2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Useful functions used by almost all dialog window pages.
\r
24 var GECKO_BOGUS = '<br type="_moz">' ;
\r
26 // Gets a element by its Id. Used for shorter coding.
\r
27 function GetE( elementId )
\r
29 return document.getElementById( elementId ) ;
\r
32 function ShowE( element, isVisible )
\r
34 if ( typeof( element ) == 'string' )
\r
35 element = GetE( element ) ;
\r
36 element.style.display = isVisible ? '' : 'none' ;
\r
39 function SetAttribute( element, attName, attValue )
\r
41 if ( attValue == null || attValue.length == 0 )
\r
42 element.removeAttribute( attName, 0 ) ; // 0 : Case Insensitive
\r
44 element.setAttribute( attName, attValue, 0 ) ; // 0 : Case Insensitive
\r
47 function GetAttribute( element, attName, valueIfNull )
\r
49 var oAtt = element.attributes[attName] ;
\r
51 if ( oAtt == null || !oAtt.specified )
\r
52 return valueIfNull ? valueIfNull : '' ;
\r
54 var oValue = element.getAttribute( attName, 2 ) ;
\r
56 if ( oValue == null )
\r
57 oValue = oAtt.nodeValue ;
\r
59 return ( oValue == null ? valueIfNull : oValue ) ;
\r
62 // Functions used by text fiels to accept numbers only.
\r
63 function IsDigit( e )
\r
68 var iCode = ( e.keyCode || e.charCode ) ;
\r
71 ( iCode >= 48 && iCode <= 57 ) // Numbers
\r
72 || (iCode >= 37 && iCode <= 40) // Arrows
\r
73 || iCode == 8 // Backspace
\r
74 || iCode == 46 // Delete
\r
78 String.prototype.Trim = function()
\r
80 return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
\r
83 String.prototype.StartsWith = function( value )
\r
85 return ( this.substr( 0, value.length ) == value ) ;
\r
88 String.prototype.Remove = function( start, length )
\r
93 s = this.substring( 0, start ) ;
\r
95 if ( start + length < this.length )
\r
96 s += this.substring( start + length , this.length ) ;
\r
101 String.prototype.ReplaceAll = function( searchArray, replaceArray )
\r
103 var replaced = this ;
\r
105 for ( var i = 0 ; i < searchArray.length ; i++ )
\r
107 replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
\r
113 function OpenFileBrowser( url, width, height )
\r
115 // oEditor must be defined.
\r
117 var iLeft = ( oEditor.FCKConfig.ScreenWidth - width ) / 2 ;
\r
118 var iTop = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
\r
120 var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes" ;
\r
121 sOptions += ",width=" + width ;
\r
122 sOptions += ",height=" + height ;
\r
123 sOptions += ",left=" + iLeft ;
\r
124 sOptions += ",top=" + iTop ;
\r
126 // The "PreserveSessionOnFileBrowser" because the above code could be
\r
127 // blocked by popup blockers.
\r
128 if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
\r
130 // The following change has been made otherwise IE will open the file
\r
131 // browser on a different server session (on some cases):
\r
132 // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
\r
133 // by Simone Chiaretta.
\r
134 var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
\r
138 // Detect Yahoo popup blocker.
\r
141 var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
\r
142 oWindow.opener = window ;
\r
146 alert( oEditor.FCKLang.BrowseServerBlocked ) ;
\r
150 alert( oEditor.FCKLang.BrowseServerBlocked ) ;
\r
153 window.open( url, 'FCKBrowseWindow', sOptions ) ;
\r