Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Show entire file | Ignore 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
 *
-
 
5
 * == BEGIN LICENSE ==
4
 * 
6
 *
5
 * Licensed under the terms of the GNU Lesser General Public License:
7
 * Licensed under the terms of any of the following licenses at your
6
 * 		http://www.opensource.org/licenses/lgpl-license.php
8
 * choice:
7
 * 
9
 *
8
 * For further information visit:
10
 *  - GNU General Public License Version 2 or later (the "GPL")
9
 * 		http://www.fckeditor.net/
11
 *    http://www.gnu.org/licenses/gpl.html
10
 * 
12
 *
11
 * "Support Open Source software. What about a donation today?"
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
-
 
14
 *    http://www.gnu.org/licenses/lgpl.html
12
 * 
15
 *
13
 * File Name: fck_dialog_common.js
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
14
 * 	Useful functions used by almost all dialog window pages.
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
15
 * 
18
 *
16
 * File Authors:
19
 * == END LICENSE ==
-
 
20
 *
17
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
21
 * Useful functions used by almost all dialog window pages.
-
 
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 : '' ;
47
 
91
 
48
	var oValue ;
92
	var oValue = element.getAttribute( attName, 2 ) ;
49
	
93
 
Line 50... Line 94...
50
	if ( !( oValue = element.getAttribute( attName, 2 ) ) )
94
	if ( oValue == null )
51
		oValue = oAtt.nodeValue ;
95
		oValue = oAtt.nodeValue ;
Line 52... Line -...
52
 
-
 
53
	return ( oValue == null ? valueIfNull : oValue ) ;
96
 
54
}
97
	return ( oValue == null ? valueIfNull : oValue ) ;
55
 
98
}
56
// Functions used by text fiels to accept numbers only.
99
 
Line 57... Line -...
57
function IsDigit( e )
-
 
58
{
-
 
59
	if ( !e )
-
 
60
		e = event ;
100
function SelectField( elementId )
61
 
-
 
62
	var iCode = ( e.keyCode || e.charCode ) ;
101
{
63
	
102
	var element = GetE( elementId ) ;
64
	return (
-
 
65
			( iCode >= 48 && iCode <= 57 )		// Numbers
103
	element.focus() ;
Line -... Line 104...
-
 
104
 
-
 
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,
-
 
117
			Left		: 37,
-
 
118
			Right		: 39,
-
 
119
			'U+00007F'	: 46		// Delete
-
 
120
		} ;
-
 
121
 
-
 
122
		return function ( e )
-
 
123
			{
-
 
124
				if ( !e )
-
 
125
					e = event ;
-
 
126
 
-
 
127
				var iCode = ( e.keyCode || e.charCode ) ;
-
 
128
 
-
 
129
				if ( !iCode && e.keyIdentifier && ( e.keyIdentifier in KeyIdentifierMap ) )
-
 
130
						iCode = KeyIdentifierMap[ e.keyIdentifier ] ;
-
 
131
 
-
 
132
				return (
-
 
133
						( iCode >= 48 && iCode <= 57 )		// Numbers
-
 
134
						|| (iCode >= 35 && iCode <= 40)		// Arrows, Home, End
-
 
135
						|| iCode == 8						// Backspace
66
			|| (iCode >= 37 && iCode <= 40)		// Arrows
136
						|| iCode == 46						// Delete
67
			|| iCode == 8						// Backspace
137
						|| iCode == 9						// Tab
68
			|| iCode == 46						// Delete
138
				) ;
69
	) ;
139
			}
Line 70... Line 140...
70
}
140
	} )() ;
71
 
141
 
72
String.prototype.trim = function()
142
String.prototype.Trim = function()
73
{
143
{
Line 74... Line 144...
74
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
144
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
75
}
145
}
76
 
146
 
Line 77... Line 147...
77
String.prototype.startsWith = function( value )
147
String.prototype.StartsWith = function( value )
78
{
148
{
Line 93... Line 163...
93
}
163
}
Line 94... Line 164...
94
 
164
 
95
String.prototype.ReplaceAll = function( searchArray, replaceArray )
165
String.prototype.ReplaceAll = function( searchArray, replaceArray )
96
{
166
{
97
	var replaced = this ;
167
	var replaced = this ;
98
	
168
 
99
	for ( var i = 0 ; i < searchArray.length ; i++ )
169
	for ( var i = 0 ; i < searchArray.length ; i++ )
100
	{
170
	{
101
		replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
171
		replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
102
	}
172
	}
103
	
173
 
104
	return replaced ;
174
	return replaced ;
Line 105... Line 175...
105
}
175
}
106
 
176
 
107
function OpenFileBrowser( url, width, height )
177
function OpenFileBrowser( url, width, height )
108
{
178
{
109
	// oEditor must be defined.
179
	// oEditor must be defined.
110
	
180
 
Line 111... Line 181...
111
	var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;
181
	var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;
112
	var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
182
	var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
113
 
183
 
114
	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
184
	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
115
	sOptions += ",width=" + width ;
185
	sOptions += ",width=" + width ;
Line -... Line 186...
-
 
186
	sOptions += ",height=" + height ;
-
 
187
	sOptions += ",left=" + iLeft ;
-
 
188
	sOptions += ",top=" + iTop ;
-
 
189
 
-
 
190
	window.open( url, 'FCKBrowseWindow', sOptions ) ;
-
 
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
-
 
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
-
 
202
*/
-
 
203
function CreateNamedElement( oEditor, oOriginal, nodeName, oAttributes )
116
	sOptions += ",height=" + height ;
204
{
117
	sOptions += ",left=" + iLeft ;
205
	var oNewNode ;
118
	sOptions += ",top=" + iTop ;
206
 
119
 
207
	// IE doesn't allow easily to change properties of an existing object,
120
	// The "PreserveSessionOnFileBrowser" because the above code could be 
208
	// so remove the old and force the creation of a new one.
-
 
209
	var oldNode = null ;
121
	// blocked by popup blockers.
210
	if ( oOriginal && oEditor.FCKBrowserInfo.IsIE )
122
	if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
211
	{
-
 
212
		// Force the creation only if some of the special attributes have changed:
123
	{
213
		var bChanged = false;
-
 
214
		for( var attName in oAttributes )
124
		// The following change has been made otherwise IE will open the file 
215
			bChanged |= ( oOriginal.getAttribute( attName, 2) != oAttributes[attName] ) ;
-
 
216
 
-
 
217
		if ( bChanged )
-
 
218
		{
125
		// browser on a different server session (on some cases):
219
			oldNode = oOriginal ;
-
 
220
			oOriginal = null ;
126
		// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
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
	{
-
 
227
		oNewNode = oOriginal ;
-
 
228
	}
127
		// by Simone Chiaretta.
229
	else
-
 
230
	{
128
		var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
231
		// #676, IE doesn't play nice with the name or type attribute
129
		
232
		if ( oEditor.FCKBrowserInfo.IsIE )
130
		if ( oWindow )
233
		{
131
		{
-
 
132
			// Detect Yahoo popup blocker.
234
			var sbHTML = [] ;
133
			try
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()] )
134
			{
242
				sbHTML.push( '</' + nodeName + '>' ) ;
135
				var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
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 ) ;
136
				oWindow.opener = window ;
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
-
 
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 )
137
			}
266
			{
138
			catch(e)
267
				var range = oEditor.FCK.EditorDocument.body.createControlRange() ;
139
			{
268
				range.add( oNewNode ) ;
140
				alert( oEditor.FCKLang.BrowseServerBlocked ) ;
-
 
141
			}
-
 
142
		}
-
 
143
		else
-
 
144
			alert( oEditor.FCKLang.BrowseServerBlocked ) ;
-
 
145
    }
269
				oEditor.FCK.Selection.SelectionData = range ;
-
 
270
			}
-
 
271
		}
-
 
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
	}