OSDN Git Service

Ver 0.5.9.2
[nucleus-jp/nucleus-plugins.git] / trunk / NP_MitasNom / mitasnom / editor / dialog / common / fck_dialog_common.js
1 /*
2  * FCKeditor - The text editor for internet
3  * Copyright (C) 2003-2005 Frederico Caldeira Knabben
4  * 
5  * Licensed under the terms of the GNU Lesser General Public License:
6  *              http://www.opensource.org/licenses/lgpl-license.php
7  * 
8  * For further information visit:
9  *              http://www.fckeditor.net/
10  * 
11  * "Support Open Source software. What about a donation today?"
12  * 
13  * File Name: fck_dialog_common.js
14  *      Useful functions used by almost all dialog window pages.
15  * 
16  * File Authors:
17  *              Frederico Caldeira Knabben (fredck@fckeditor.net)
18  */
19
20 /*
21  * Modified for Nucleus Plugin by Katsumi
22  * The license turned to GPL.
23  */
24
25 // Gets a element by its Id. Used for shorter coding.
26 function GetE( elementId )
27 {
28         return document.getElementById( elementId )  ;
29 }
30
31 function ShowE( element, isVisible )
32 {
33         if ( typeof( element ) == 'string' )
34                 element = GetE( element ) ;
35         element.style.display = isVisible ? '' : 'none' ;
36 }
37
38 function SetAttribute( element, attName, attValue )
39 {
40         if ( attValue == null || attValue.length == 0 )
41                 element.removeAttribute( attName, 0 ) ;                 // 0 : Case Insensitive
42         else
43                 element.setAttribute( attName, attValue, 0 ) ;  // 0 : Case Insensitive
44 }
45
46 function GetAttribute( element, attName, valueIfNull )
47 {
48         var oAtt = element.attributes[attName] ;
49
50         if ( oAtt == null || !oAtt.specified )
51                 return valueIfNull ? valueIfNull : '' ;
52
53         var oValue ;
54         
55         if ( !( oValue = element.getAttribute( attName, 2 ) ) )
56                 oValue = oAtt.nodeValue ;
57
58         return ( oValue == null ? valueIfNull : oValue ) ;
59 }
60
61 // Functions used by text fiels to accept numbers only.
62 function IsDigit( e )
63 {
64         e = e || event ;
65         var iCode = ( e.keyCode || e.charCode ) ;
66
67         event.returnValue =
68                 (
69                         ( iCode >= 48 && iCode <= 57 )          // Numbers
70                         || (iCode >= 37 && iCode <= 40)         // Arrows
71                         || iCode == 8                                           // Backspace
72                         || iCode == 46                                          // Delete
73                 ) ;
74
75         return event.returnValue ;
76 }
77
78 String.prototype.trim = function()
79 {
80         return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
81 }
82
83 String.prototype.startsWith = function( value )
84 {
85         return ( this.substr( 0, value.length ) == value ) ;
86 }
87
88 String.prototype.remove = function( start, length )
89 {
90         var s = '' ;
91
92         if ( start > 0 )
93                 s = this.substring( 0, start ) ;
94
95         if ( start + length < this.length )
96                 s += this.substring( start + length , this.length ) ;
97
98         return s ;
99 }
100
101 function OpenFileBrowser( url, width, height )
102 {
103         // oEditor must be defined.
104         
105         var iLeft = ( oEditor.FCKConfig.ScreenWidth  - width ) / 2 ;
106         var iTop  = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
107
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 )
117         {
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 ) ;
123                 if ( oWindow )
124                         oWindow.opener = window ;
125                 else
126                         alert( oEditor.FCKLang.BrowseServerBlocked ) ;
127         }
128         else { var oWindow =window.open( url, 'FCKBrowseWindow', sOptions ) ; }
129         if ( oWindow ) {
130                 if (FCKConfig.NucleusUseImageManager) {// Image-Manager plugin
131                         SetImageManager_oWindow=oWindow;
132                         SetImageManager_timer=setInterval("SetImageManager()",1);// Check the window every 1 mili second.
133                 } else {//media.php
134                         oWindow.window.opener.includeImage=function(collection,filename,type,width,height)
135                         {
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;
140                         };
141                         oWindow.window.opener.includeOtherMedia=function(collection, filename)
142                         {
143                                 if (this.GetE('txtUrl')) this.GetE('txtUrl').value=FCKConfig.NucleusMediaDir+collection+'/'+filename;
144                         };
145                 }
146         }
147 }
148
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)
157                 {
158                         var sActualBrowser;
159                         try {
160                                 sActualBrowser=oWindow.window.opener.sActualBrowser.toLowerCase();
161                         } catch(e) {
162                                 sActualBrowser='';
163                         }
164                         if (val) switch (sActualBrowser){
165                         case "link":
166                                 if (oWindow.window.opener.GetE('txtLnkUrl')) oWindow.window.opener.GetE('txtLnkUrl').value=val['f_url'];
167                                 break;
168                         default:
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;
173                         }
174                         oWindow.close();
175                 };
176 }