2 * FCKeditor - The text editor for internet
3 * Copyright (C) 2003-2005 Frederico Caldeira Knabben
5 * Licensed under the terms of the GNU Lesser General Public License:
6 * http://www.opensource.org/licenses/lgpl-license.php
8 * For further information visit:
9 * http://www.fckeditor.net/
11 * "Support Open Source software. What about a donation today?"
13 * File Name: fck_dialog_common.js
14 * Useful functions used by almost all dialog window pages.
17 * Frederico Caldeira Knabben (fredck@fckeditor.net)
21 * Modified for Nucleus Plugin by Katsumi
22 * The license turned to GPL.
25 // Gets a element by its Id. Used for shorter coding.
26 function GetE( elementId )
28 return document.getElementById( elementId ) ;
31 function ShowE( element, isVisible )
33 if ( typeof( element ) == 'string' )
34 element = GetE( element ) ;
35 element.style.display = isVisible ? '' : 'none' ;
38 function SetAttribute( element, attName, attValue )
40 if ( attValue == null || attValue.length == 0 )
41 element.removeAttribute( attName, 0 ) ; // 0 : Case Insensitive
43 element.setAttribute( attName, attValue, 0 ) ; // 0 : Case Insensitive
46 function GetAttribute( element, attName, valueIfNull )
48 var oAtt = element.attributes[attName] ;
50 if ( oAtt == null || !oAtt.specified )
51 return valueIfNull ? valueIfNull : '' ;
55 if ( !( oValue = element.getAttribute( attName, 2 ) ) )
56 oValue = oAtt.nodeValue ;
58 return ( oValue == null ? valueIfNull : oValue ) ;
61 // Functions used by text fiels to accept numbers only.
65 var iCode = ( e.keyCode || e.charCode ) ;
69 ( iCode >= 48 && iCode <= 57 ) // Numbers
70 || (iCode >= 37 && iCode <= 40) // Arrows
71 || iCode == 8 // Backspace
72 || iCode == 46 // Delete
75 return event.returnValue ;
78 String.prototype.trim = function()
80 return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
83 String.prototype.startsWith = function( value )
85 return ( this.substr( 0, value.length ) == value ) ;
88 String.prototype.remove = function( start, length )
93 s = this.substring( 0, start ) ;
95 if ( start + length < this.length )
96 s += this.substring( start + length , this.length ) ;
101 function OpenFileBrowser( url, width, height )
103 // oEditor must be defined.
105 var iLeft = ( oEditor.FCKConfig.ScreenWidth - width ) / 2 ;
106 var iTop = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
108 var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
109 sOptions += ",width=" + width ;
110 sOptions += ",height=" + height ;
111 sOptions += ",left=" + iLeft ;
112 sOptions += ",top=" + iTop ;
113 sOptions += ",scrollbars=yes";
114 // The "PreserveSessionOnFileBrowser" because the above code could be
115 // blocked by popup blockers.
116 if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
118 // The following change has been made otherwise IE will open the file
119 // browser on a different server session (on some cases):
120 // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
121 // by Simone Chiaretta.
122 var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
124 oWindow.opener = window ;
126 alert( oEditor.FCKLang.BrowseServerBlocked ) ;
128 else { var oWindow =window.open( url, 'FCKBrowseWindow', sOptions ) ; }
130 if (FCKConfig.NucleusUseImageManager) {// Image-Manager plugin
131 SetImageManager_oWindow=oWindow;
132 SetImageManager_timer=setInterval("SetImageManager()",1);// Check the window every 1 mili second.
134 oWindow.window.opener.includeImage=function(collection,filename,type,width,height)
136 if (this.GetE('txtUrl')) this.GetE('txtUrl').value=FCKConfig.NucleusMediaDir+collection+'/'+filename;
137 if (this.GetE('txtWidth')) this.GetE('txtWidth').value=width;
138 if (this.GetE('txtHeight')) this.GetE('txtHeight').value=height;
139 //if (this.GetE('txtAttTitle')) this.GetE('txtAttTitle').value=filename;
141 oWindow.window.opener.includeOtherMedia=function(collection, filename)
143 if (this.GetE('txtUrl')) this.GetE('txtUrl').value=FCKConfig.NucleusMediaDir+collection+'/'+filename;
149 var SetImageManager_oWindow;
150 var SetImageManager_timer;
151 function SetImageManager(){
152 var oWindow=SetImageManager_oWindow;
153 if (!oWindow.window.onOK) return;
154 clearInterval(SetImageManager_timer);
155 oWindow.window.base_url=FCKConfig.NucleusMediaDir;
156 oWindow.window.__dlg_close=function(val)
160 sActualBrowser=oWindow.window.opener.sActualBrowser.toLowerCase();
164 if (val) switch (sActualBrowser){
166 if (oWindow.window.opener.GetE('txtLnkUrl')) oWindow.window.opener.GetE('txtLnkUrl').value=val['f_url'];
169 if (oWindow.window.opener.GetE('txtUrl')) oWindow.window.opener.GetE('txtUrl').value=val['f_url'];
170 if (oWindow.window.opener.GetE('txtWidth')) oWindow.window.opener.GetE('txtWidth').value=val['f_width'];
171 if (oWindow.window.opener.GetE('txtWidth')) oWindow.window.opener.GetE('txtHeight').value=val['f_height'];
172 //if (oWindow.window.opener.GetE('txtAttTitle')) oWindow.window.opener.GetE('txtAttTitle').value=filename;