2
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
* Copyright (C) 2003-2007 Frederico Caldeira Knabben
7
* Licensed under the terms of any of the following licenses at your
10
* - GNU General Public License Version 2 or later (the "GPL")
11
* http://www.gnu.org/licenses/gpl.html
13
* - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
* http://www.gnu.org/licenses/lgpl.html
16
* - Mozilla Public License Version 1.1 or later (the "MPL")
17
* http://www.mozilla.org/MPL/MPL-1.1.html
21
* Useful functions used by almost all dialog window pages.
24
// Gets a element by its Id. Used for shorter coding.
25
function GetE( elementId )
27
return document.getElementById( elementId ) ;
30
function ShowE( element, isVisible )
32
if ( typeof( element ) == 'string' )
33
element = GetE( element ) ;
34
element.style.display = isVisible ? '' : 'none' ;
37
function SetAttribute( element, attName, attValue )
39
if ( attValue == null || attValue.length == 0 )
40
element.removeAttribute( attName, 0 ) ; // 0 : Case Insensitive
42
element.setAttribute( attName, attValue, 0 ) ; // 0 : Case Insensitive
45
function GetAttribute( element, attName, valueIfNull )
47
var oAtt = element.attributes[attName] ;
49
if ( oAtt == null || !oAtt.specified )
50
return valueIfNull ? valueIfNull : '' ;
52
var oValue = element.getAttribute( attName, 2 ) ;
55
oValue = oAtt.nodeValue ;
57
return ( oValue == null ? valueIfNull : oValue ) ;
60
var KeyIdentifierMap =
66
'U+00007F' : 46 // Delete
69
// Functions used by text fields to accept numbers only.
75
var iCode = ( e.keyCode || e.charCode ) ;
77
if ( !iCode && e.keyIdentifier && ( e.keyIdentifier in KeyIdentifierMap ) )
78
iCode = KeyIdentifierMap[ e.keyIdentifier ] ;
81
( iCode >= 48 && iCode <= 57 ) // Numbers
82
|| (iCode >= 35 && iCode <= 40) // Arrows, Home, End
83
|| iCode == 8 // Backspace
84
|| iCode == 46 // Delete
89
String.prototype.Trim = function()
91
return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
94
String.prototype.StartsWith = function( value )
96
return ( this.substr( 0, value.length ) == value ) ;
99
String.prototype.Remove = function( start, length )
104
s = this.substring( 0, start ) ;
106
if ( start + length < this.length )
107
s += this.substring( start + length , this.length ) ;
112
String.prototype.ReplaceAll = function( searchArray, replaceArray )
114
var replaced = this ;
116
for ( var i = 0 ; i < searchArray.length ; i++ )
118
replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
124
function OpenFileBrowser( url, width, height )
126
// oEditor must be defined.
128
var iLeft = ( oEditor.FCKConfig.ScreenWidth - width ) / 2 ;
129
var iTop = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
131
var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
132
sOptions += ",width=" + width ;
133
sOptions += ",height=" + height ;
134
sOptions += ",left=" + iLeft ;
135
sOptions += ",top=" + iTop ;
137
// The "PreserveSessionOnFileBrowser" because the above code could be
138
// blocked by popup blockers.
139
if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
141
// The following change has been made otherwise IE will open the file
142
// browser on a different server session (on some cases):
143
// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
144
// by Simone Chiaretta.
145
var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
149
// Detect Yahoo popup blocker.
152
var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
153
oWindow.opener = window ;
157
alert( oEditor.FCKLang.BrowseServerBlocked ) ;
161
alert( oEditor.FCKLang.BrowseServerBlocked ) ;
164
window.open( url, 'FCKBrowseWindow', sOptions ) ;