Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1688 Rev 1921
Line 1... Line 1...
1
/*
1
/*
2
 * FCKeditor - The text editor for internet
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
3
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
4
 * 
4
 *
5
 * Licensed under the terms of the GNU Lesser General Public License:
5
 * == BEGIN LICENSE ==
6
 * 		http://www.opensource.org/licenses/lgpl-license.php
-
 
7
 * 
6
 *
8
 * For further information visit:
7
 * Licensed under the terms of any of the following licenses at your
9
 * 		http://www.fckeditor.net/
8
 * choice:
10
 * 
9
 *
11
 * "Support Open Source software. What about a donation today?"
10
 *  - GNU General Public License Version 2 or later (the "GPL")
-
 
11
 *    http://www.gnu.org/licenses/gpl.html
12
 * 
12
 *
-
 
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
13
 * File Name: fck_dialog_common.js
14
 *    http://www.gnu.org/licenses/lgpl.html
-
 
15
 *
14
 * 	Useful functions used by almost all dialog window pages.
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
-
 
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
-
 
18
 *
-
 
19
 * == END LICENSE ==
15
 * 
20
 *
16
 * File Authors:
21
 * Useful functions used by almost all dialog window pages.
17
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
22
 * Dialogs should link to this file as the very first script on the page.
18
 */
23
 */
Line -... Line 24...
-
 
24
 
-
 
25
// Automatically detect the correct document.domain (#123).
-
 
26
(function()
-
 
27
{
-
 
28
	var d = document.domain ;
-
 
29
 
-
 
30
	while ( true )
-
 
31
	{
-
 
32
		// Test if we can access a parent property.
-
 
33
		try
-
 
34
		{
-
 
35
			var test = window.parent.document.domain ;
-
 
36
			break ;
-
 
37
		}
-
 
38
		catch( e ) {}
-
 
39
 
-
 
40
		// Remove a domain part: www.mytest.example.com => mytest.example.com => example.com ...
-
 
41
		d = d.replace( /.*?(?:\.|$)/, '' ) ;
-
 
42
 
-
 
43
		if ( d.length == 0 )
-
 
44
			break ;		// It was not able to detect the domain.
-
 
45
 
-
 
46
		try
-
 
47
		{
-
 
48
			document.domain = d ;
-
 
49
		}
-
 
50
		catch (e)
-
 
51
		{
-
 
52
			break ;
-
 
53
		}
-
 
54
	}
-
 
55
})() ;
-
 
56
 
-
 
57
// Attention: FCKConfig must be available in the page.
-
 
58
function GetCommonDialogCss( prefix )
-
 
59
{
-
 
60
	// CSS minified by http://iceyboard.no-ip.org/projects/css_compressor (see _dev/css_compression.txt).
-
 
61
	return FCKConfig.BasePath + 'dialog/common/' + '|.ImagePreviewArea{border:#000 1px solid;overflow:auto;width:100%;height:170px;background-color:#fff}.FlashPreviewArea{border:#000 1px solid;padding:5px;overflow:auto;width:100%;height:170px;background-color:#fff}.BtnReset{float:left;background-position:center center;background-image:url(images/reset.gif);width:16px;height:16px;background-repeat:no-repeat;border:1px none;font-size:1px}.BtnLocked,.BtnUnlocked{float:left;background-position:center center;background-image:url(images/locked.gif);width:16px;height:16px;background-repeat:no-repeat;border:none 1px;font-size:1px}.BtnUnlocked{background-image:url(images/unlocked.gif)}.BtnOver{border:outset 1px;cursor:pointer;cursor:hand}' ;
-
 
62
}
19
 
63
 
20
// Gets a element by its Id. Used for shorter coding.
64
// Gets a element by its Id. Used for shorter coding.
21
function GetE( elementId )
65
function GetE( elementId )
22
{
66
{
23
	return document.getElementById( elementId )  ;
67
	return document.getElementById( elementId )  ;
Line 43... Line 87...
43
	var oAtt = element.attributes[attName] ;
87
	var oAtt = element.attributes[attName] ;
Line 44... Line 88...
44
 
88
 
45
	if ( oAtt == null || !oAtt.specified )
89
	if ( oAtt == null || !oAtt.specified )
Line 46... Line 90...
46
		return valueIfNull ? valueIfNull : '' ;
90
		return valueIfNull ? valueIfNull : '' ;
Line 47... Line 91...
47
 
91
 
48
	var oValue ;
92
	var oValue = element.getAttribute( attName, 2 ) ;
Line 49... Line 93...
49
	
93
 
50
	if ( !( oValue = element.getAttribute( attName, 2 ) ) )
94
	if ( oValue == null )
Line -... Line 95...
-
 
95
		oValue = oAtt.nodeValue ;
-
 
96
 
-
 
97
	return ( oValue == null ? valueIfNull : oValue ) ;
-
 
98
}
-
 
99
 
-
 
100
function SelectField( elementId )
-
 
101
{
-
 
102
	var element = GetE( elementId ) ;
-
 
103
	element.focus() ;
-
 
104
 
51
		oValue = oAtt.nodeValue ;
105
	// element.select may not be available for some fields (like <select>).
-
 
106
	if ( element.select )
-
 
107
		element.select() ;
-
 
108
}
-
 
109
 
-
 
110
// Functions used by text fields to accept numbers only.
-
 
111
var IsDigit = ( function()
-
 
112
	{
-
 
113
		var KeyIdentifierMap =
-
 
114
		{
-
 
115
			End			: 35,
-
 
116
			Home		: 36,
52
 
117
			Left		: 37,
53
	return ( oValue == null ? valueIfNull : oValue ) ;
118
			Right		: 39,
54
}
119
			'U+00007F'	: 46		// Delete
55
 
120
		} ;
Line 56... Line 121...
56
// Functions used by text fiels to accept numbers only.
121
 
Line -... Line 122...
-
 
122
		return function ( e )
-
 
123
			{
-
 
124
				if ( !e )
57
function IsDigit( e )
125
					e = event ;
58
{
126
 
59
	if ( !e )
127
				var iCode = ( e.keyCode || e.charCode ) ;
60
		e = event ;
128
 
61
 
129
				if ( !iCode && e.keyIdentifier && ( e.keyIdentifier in KeyIdentifierMap ) )
-
 
130
						iCode = KeyIdentifierMap[ e.keyIdentifier ] ;
62
	var iCode = ( e.keyCode || e.charCode ) ;
131
 
63
	
132
				return (
-
 
133
						( iCode >= 48 && iCode <= 57 )		// Numbers
Line 64... Line 134...
64
	return (
134
						|| (iCode >= 35 && iCode <= 40)		// Arrows, Home, End
65
			( iCode >= 48 && iCode <= 57 )		// Numbers
135
						|| iCode == 8						// Backspace
66
			|| (iCode >= 37 && iCode <= 40)		// Arrows
136
						|| iCode == 46						// Delete
67
			|| iCode == 8						// Backspace
137
						|| iCode == 9						// Tab
Line 68... Line 138...
68
			|| iCode == 46						// Delete
138
				) ;
69
	) ;
139
			}
70
}
140
	} )() ;
71
 
141
 
Line 72... Line 142...
72
String.prototype.trim = function()
142
String.prototype.Trim = function()
73
{
143
{
74
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
144
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
Line 75... Line 145...
75
}
145
}
76
 
146
 
Line 115... Line 185...
115
	sOptions += ",width=" + width ;
185
	sOptions += ",width=" + width ;
116
	sOptions += ",height=" + height ;
186
	sOptions += ",height=" + height ;
117
	sOptions += ",left=" + iLeft ;
187
	sOptions += ",left=" + iLeft ;
118
	sOptions += ",top=" + iTop ;
188
	sOptions += ",top=" + iTop ;
Line 119... Line 189...
119
 
189
 
120
	// The "PreserveSessionOnFileBrowser" because the above code could be 
-
 
121
	// blocked by popup blockers.
-
 
122
	if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
190
	window.open( url, 'FCKBrowseWindow', sOptions ) ;
123
	{
-
 
124
		// The following change has been made otherwise IE will open the file 
-
 
125
		// browser on a different server session (on some cases):
-
 
126
		// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
-
 
127
		// by Simone Chiaretta.
-
 
Line -... Line 191...
-
 
191
}
-
 
192
 
-
 
193
/**
-
 
194
 Utility function to create/update an element with a name attribute in IE, so it behaves properly when moved around
-
 
195
 It also allows to change the name or other special attributes in an existing node
-
 
196
	oEditor : instance of FCKeditor where the element will be created
-
 
197
	oOriginal : current element being edited or null if it has to be created
-
 
198
	nodeName : string with the name of the element to create
128
		var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
199
	oAttributes : Hash object with the attributes that must be set at creation time in IE
-
 
200
								Those attributes will be set also after the element has been
-
 
201
								created for any other browser to avoid redudant code
129
		
202
*/
-
 
203
function CreateNamedElement( oEditor, oOriginal, nodeName, oAttributes )
-
 
204
{
-
 
205
	var oNewNode ;
130
		if ( oWindow )
206
 
131
		{
207
	// IE doesn't allow easily to change properties of an existing object,
-
 
208
	// so remove the old and force the creation of a new one.
132
			// Detect Yahoo popup blocker.
209
	var oldNode = null ;
133
			try
210
	if ( oOriginal && oEditor.FCKBrowserInfo.IsIE )
134
			{
211
	{
-
 
212
		// Force the creation only if some of the special attributes have changed:
-
 
213
		var bChanged = false;
135
				var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
214
		for( var attName in oAttributes )
136
				oWindow.opener = window ;
215
			bChanged |= ( oOriginal.getAttribute( attName, 2) != oAttributes[attName] ) ;
137
			}
216
 
138
			catch(e)
217
		if ( bChanged )
-
 
218
		{
139
			{
219
			oldNode = oOriginal ;
140
				alert( oEditor.FCKLang.BrowseServerBlocked ) ;
220
			oOriginal = null ;
-
 
221
		}
-
 
222
	}
-
 
223
 
-
 
224
	// If the node existed (and it's not IE), then we just have to update its attributes
-
 
225
	if ( oOriginal )
-
 
226
	{
141
			}
227
		oNewNode = oOriginal ;
-
 
228
	}
-
 
229
	else
-
 
230
	{
-
 
231
		// #676, IE doesn't play nice with the name or type attribute
-
 
232
		if ( oEditor.FCKBrowserInfo.IsIE )
-
 
233
		{
-
 
234
			var sbHTML = [] ;
-
 
235
			sbHTML.push( '<' + nodeName ) ;
-
 
236
			for( var prop in oAttributes )
-
 
237
			{
-
 
238
				sbHTML.push( ' ' + prop + '="' + oAttributes[prop] + '"' ) ;
-
 
239
			}
-
 
240
			sbHTML.push( '>' ) ;
-
 
241
			if ( !oEditor.FCKListsLib.EmptyElements[nodeName.toLowerCase()] )
-
 
242
				sbHTML.push( '</' + nodeName + '>' ) ;
-
 
243
 
-
 
244
			oNewNode = oEditor.FCK.EditorDocument.createElement( sbHTML.join('') ) ;
-
 
245
			// Check if we are just changing the properties of an existing node: copy its properties
-
 
246
			if ( oldNode )
-
 
247
			{
-
 
248
				CopyAttributes( oldNode, oNewNode, oAttributes ) ;
-
 
249
				oEditor.FCKDomTools.MoveChildren( oldNode, oNewNode ) ;
-
 
250
				oldNode.parentNode.removeChild( oldNode ) ;
-
 
251
				oldNode = null ;
-
 
252
 
-
 
253
				if ( oEditor.FCK.Selection.SelectionData )
-
 
254
				{
-
 
255
					// Trick to refresh the selection object and avoid error in
-
 
256
					// fckdialog.html Selection.EnsureSelection
-
 
257
					var oSel = oEditor.FCK.EditorDocument.selection ;
-
 
258
					oEditor.FCK.Selection.SelectionData = oSel.createRange() ; // Now oSel.type will be 'None' reflecting the real situation
142
		}
259
				}
-
 
260
			}
-
 
261
			oNewNode = oEditor.FCK.InsertElement( oNewNode ) ;
-
 
262
 
-
 
263
			// FCK.Selection.SelectionData is broken by now since we've
-
 
264
			// deleted the previously selected element. So we need to reassign it.
-
 
265
			if ( oEditor.FCK.Selection.SelectionData )
-
 
266
			{
-
 
267
				var range = oEditor.FCK.EditorDocument.body.createControlRange() ;
-
 
268
				range.add( oNewNode ) ;
143
		else
269
				oEditor.FCK.Selection.SelectionData = range ;
144
			alert( oEditor.FCKLang.BrowseServerBlocked ) ;
270
			}
-
 
271
		}
145
    }
272
		else
-
 
273
		{
-
 
274
			oNewNode = oEditor.FCK.InsertElement( nodeName ) ;
-
 
275
		}
-
 
276
	}
-
 
277
 
-
 
278
	// Set the basic attributes
-
 
279
	for( var attName in oAttributes )
-
 
280
		oNewNode.setAttribute( attName, oAttributes[attName], 0 ) ;	// 0 : Case Insensitive
-
 
281
 
-
 
282
	return oNewNode ;
-
 
283
}
-
 
284
 
-
 
285
// Copy all the attributes from one node to the other, kinda like a clone
-
 
286
// But oSkipAttributes is an object with the attributes that must NOT be copied
-
 
287
function CopyAttributes( oSource, oDest, oSkipAttributes )
-
 
288
{
-
 
289
	var aAttributes = oSource.attributes ;
-
 
290
 
-
 
291
	for ( var n = 0 ; n < aAttributes.length ; n++ )
-
 
292
	{
-
 
293
		var oAttribute = aAttributes[n] ;
-
 
294
 
-
 
295
		if ( oAttribute.specified )
-
 
296
		{
-
 
297
			var sAttName = oAttribute.nodeName ;
-
 
298
			// We can set the type only once, so do it with the proper value, not copying it.
-
 
299
			if ( sAttName in oSkipAttributes )
-
 
300
				continue ;
-
 
301
 
-
 
302
			var sAttValue = oSource.getAttribute( sAttName, 2 ) ;
-
 
303
			if ( sAttValue == null )
-
 
304
				sAttValue = oAttribute.nodeValue ;
-
 
305
 
-
 
306
			oDest.setAttribute( sAttName, sAttValue, 0 ) ;	// 0 : Case Insensitive
-
 
307
		}
-
 
308
	}
146
    else
309
	// The style:
147
		window.open( url, 'FCKBrowseWindow', sOptions ) ;
310
	oDest.style.cssText = oSource.style.cssText ;