This commit was manufactured by cvs2svn to create tag 'freeside_1_9_2'.
[freeside.git] / httemplate / elements / fckeditor / editor / dialog / common / fck_dialog_common.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2007 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * Useful functions used by almost all dialog window pages.\r
22  */\r
23 \r
24 var GECKO_BOGUS = '<br type="_moz">' ;\r
25 \r
26 // Gets a element by its Id. Used for shorter coding.\r
27 function GetE( elementId )\r
28 {\r
29         return document.getElementById( elementId )  ;\r
30 }\r
31 \r
32 function ShowE( element, isVisible )\r
33 {\r
34         if ( typeof( element ) == 'string' )\r
35                 element = GetE( element ) ;\r
36         element.style.display = isVisible ? '' : 'none' ;\r
37 }\r
38 \r
39 function SetAttribute( element, attName, attValue )\r
40 {\r
41         if ( attValue == null || attValue.length == 0 )\r
42                 element.removeAttribute( attName, 0 ) ;                 // 0 : Case Insensitive\r
43         else\r
44                 element.setAttribute( attName, attValue, 0 ) ;  // 0 : Case Insensitive\r
45 }\r
46 \r
47 function GetAttribute( element, attName, valueIfNull )\r
48 {\r
49         var oAtt = element.attributes[attName] ;\r
50 \r
51         if ( oAtt == null || !oAtt.specified )\r
52                 return valueIfNull ? valueIfNull : '' ;\r
53 \r
54         var oValue = element.getAttribute( attName, 2 ) ;\r
55 \r
56         if ( oValue == null )\r
57                 oValue = oAtt.nodeValue ;\r
58 \r
59         return ( oValue == null ? valueIfNull : oValue ) ;\r
60 }\r
61 \r
62 // Functions used by text fiels to accept numbers only.\r
63 function IsDigit( e )\r
64 {\r
65         if ( !e )\r
66                 e = event ;\r
67 \r
68         var iCode = ( e.keyCode || e.charCode ) ;\r
69 \r
70         return (\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
75         ) ;\r
76 }\r
77 \r
78 String.prototype.Trim = function()\r
79 {\r
80         return this.replace( /(^\s*)|(\s*$)/g, '' ) ;\r
81 }\r
82 \r
83 String.prototype.StartsWith = function( value )\r
84 {\r
85         return ( this.substr( 0, value.length ) == value ) ;\r
86 }\r
87 \r
88 String.prototype.Remove = function( start, length )\r
89 {\r
90         var s = '' ;\r
91 \r
92         if ( start > 0 )\r
93                 s = this.substring( 0, start ) ;\r
94 \r
95         if ( start + length < this.length )\r
96                 s += this.substring( start + length , this.length ) ;\r
97 \r
98         return s ;\r
99 }\r
100 \r
101 String.prototype.ReplaceAll = function( searchArray, replaceArray )\r
102 {\r
103         var replaced = this ;\r
104 \r
105         for ( var i = 0 ; i < searchArray.length ; i++ )\r
106         {\r
107                 replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;\r
108         }\r
109 \r
110         return replaced ;\r
111 }\r
112 \r
113 function OpenFileBrowser( url, width, height )\r
114 {\r
115         // oEditor must be defined.\r
116 \r
117         var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;\r
118         var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;\r
119 \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
125 \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
129         {\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
135 \r
136                 if ( oWindow )\r
137                 {\r
138                         // Detect Yahoo popup blocker.\r
139                         try\r
140                         {\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
143                         }\r
144                         catch(e)\r
145                         {\r
146                                 alert( oEditor.FCKLang.BrowseServerBlocked ) ;\r
147                         }\r
148                 }\r
149                 else\r
150                         alert( oEditor.FCKLang.BrowseServerBlocked ) ;\r
151     }\r
152     else\r
153                 window.open( url, 'FCKBrowseWindow', sOptions ) ;\r
154 }