1075 |
ddelon |
1 |
/*
|
|
|
2 |
* FCKeditor - The text editor for internet
|
|
|
3 |
* Copyright (C) 2003-2006 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_flash.js
|
|
|
14 |
* Scripts related to the Flash dialog window (see fck_flash.html).
|
|
|
15 |
*
|
|
|
16 |
* File Authors:
|
|
|
17 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
var oEditor = window.parent.InnerDialogLoaded() ;
|
|
|
21 |
var FCK = oEditor.FCK ;
|
|
|
22 |
var FCKLang = oEditor.FCKLang ;
|
|
|
23 |
var FCKConfig = oEditor.FCKConfig ;
|
|
|
24 |
|
|
|
25 |
//#### Dialog Tabs
|
|
|
26 |
|
|
|
27 |
// Set the dialog tabs.
|
|
|
28 |
window.parent.AddTab( 'Info', oEditor.FCKLang.DlgInfoTab ) ;
|
|
|
29 |
|
|
|
30 |
if ( FCKConfig.FlashUpload )
|
|
|
31 |
window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;
|
|
|
32 |
|
|
|
33 |
if ( !FCKConfig.FlashDlgHideAdvanced )
|
|
|
34 |
window.parent.AddTab( 'Advanced', oEditor.FCKLang.DlgAdvancedTag ) ;
|
|
|
35 |
|
|
|
36 |
// Function called when a dialog tag is selected.
|
|
|
37 |
function OnDialogTabChange( tabCode )
|
|
|
38 |
{
|
|
|
39 |
ShowE('divInfo' , ( tabCode == 'Info' ) ) ;
|
|
|
40 |
ShowE('divUpload' , ( tabCode == 'Upload' ) ) ;
|
|
|
41 |
ShowE('divAdvanced' , ( tabCode == 'Advanced' ) ) ;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
// Get the selected flash embed (if available).
|
|
|
45 |
var oFakeImage = FCK.Selection.GetSelectedElement() ;
|
|
|
46 |
var oEmbed ;
|
|
|
47 |
|
|
|
48 |
if ( oFakeImage )
|
|
|
49 |
{
|
|
|
50 |
if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckflash') )
|
|
|
51 |
oEmbed = FCK.GetRealElement( oFakeImage ) ;
|
|
|
52 |
else
|
|
|
53 |
oFakeImage = null ;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
window.onload = function()
|
|
|
57 |
{
|
|
|
58 |
// Translate the dialog box texts.
|
|
|
59 |
oEditor.FCKLanguageManager.TranslatePage(document) ;
|
|
|
60 |
|
|
|
61 |
// Load the selected element information (if any).
|
|
|
62 |
LoadSelection() ;
|
|
|
63 |
|
|
|
64 |
// Show/Hide the "Browse Server" button.
|
|
|
65 |
GetE('tdBrowse').style.display = FCKConfig.FlashBrowser ? '' : 'none' ;
|
|
|
66 |
|
|
|
67 |
// Set the actual uploader URL.
|
|
|
68 |
if ( FCKConfig.FlashUpload )
|
|
|
69 |
GetE('frmUpload').action = FCKConfig.FlashUploadURL ;
|
|
|
70 |
|
|
|
71 |
window.parent.SetAutoSize( true ) ;
|
|
|
72 |
|
|
|
73 |
// Activate the "OK" button.
|
|
|
74 |
window.parent.SetOkButton( true ) ;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
function LoadSelection()
|
|
|
78 |
{
|
|
|
79 |
if ( ! oEmbed ) return ;
|
|
|
80 |
|
|
|
81 |
var sUrl = GetAttribute( oEmbed, 'src', '' ) ;
|
|
|
82 |
|
|
|
83 |
GetE('txtUrl').value = GetAttribute( oEmbed, 'src', '' ) ;
|
|
|
84 |
GetE('txtWidth').value = GetAttribute( oEmbed, 'width', '' ) ;
|
|
|
85 |
GetE('txtHeight').value = GetAttribute( oEmbed, 'height', '' ) ;
|
|
|
86 |
|
|
|
87 |
// Get Advances Attributes
|
|
|
88 |
GetE('txtAttId').value = oEmbed.id ;
|
|
|
89 |
GetE('chkAutoPlay').checked = GetAttribute( oEmbed, 'play', 'true' ) == 'true' ;
|
|
|
90 |
GetE('chkLoop').checked = GetAttribute( oEmbed, 'loop', 'true' ) == 'true' ;
|
|
|
91 |
GetE('chkMenu').checked = GetAttribute( oEmbed, 'menu', 'true' ) == 'true' ;
|
|
|
92 |
GetE('cmbScale').value = GetAttribute( oEmbed, 'scale', '' ).toLowerCase() ;
|
|
|
93 |
|
|
|
94 |
GetE('txtAttTitle').value = oEmbed.title ;
|
|
|
95 |
|
|
|
96 |
if ( oEditor.FCKBrowserInfo.IsIE )
|
|
|
97 |
{
|
|
|
98 |
GetE('txtAttClasses').value = oEmbed.getAttribute('className') || '' ;
|
|
|
99 |
GetE('txtAttStyle').value = oEmbed.style.cssText ;
|
|
|
100 |
}
|
|
|
101 |
else
|
|
|
102 |
{
|
|
|
103 |
GetE('txtAttClasses').value = oEmbed.getAttribute('class',2) || '' ;
|
|
|
104 |
GetE('txtAttStyle').value = oEmbed.getAttribute('style',2) ;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
UpdatePreview() ;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
//#### The OK button was hit.
|
|
|
111 |
function Ok()
|
|
|
112 |
{
|
|
|
113 |
if ( GetE('txtUrl').value.length == 0 )
|
|
|
114 |
{
|
|
|
115 |
window.parent.SetSelectedTab( 'Info' ) ;
|
|
|
116 |
GetE('txtUrl').focus() ;
|
|
|
117 |
|
|
|
118 |
alert( oEditor.FCKLang.DlgAlertUrl ) ;
|
|
|
119 |
|
|
|
120 |
return false ;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
if ( !oEmbed )
|
|
|
124 |
{
|
|
|
125 |
oEmbed = FCK.EditorDocument.createElement( 'EMBED' ) ;
|
|
|
126 |
oFakeImage = null ;
|
|
|
127 |
}
|
|
|
128 |
UpdateEmbed( oEmbed ) ;
|
|
|
129 |
|
|
|
130 |
if ( !oFakeImage )
|
|
|
131 |
{
|
|
|
132 |
oFakeImage = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oEmbed ) ;
|
|
|
133 |
oFakeImage.setAttribute( '_fckflash', 'true', 0 ) ;
|
|
|
134 |
oFakeImage = FCK.InsertElementAndGetIt( oFakeImage ) ;
|
|
|
135 |
}
|
|
|
136 |
else
|
|
|
137 |
oEditor.FCKUndo.SaveUndoStep() ;
|
|
|
138 |
|
|
|
139 |
oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oEmbed ) ;
|
|
|
140 |
|
|
|
141 |
return true ;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
function UpdateEmbed( e )
|
|
|
145 |
{
|
|
|
146 |
SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;
|
|
|
147 |
SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;
|
|
|
148 |
|
|
|
149 |
e.src = GetE('txtUrl').value ;
|
|
|
150 |
SetAttribute( e, "width" , GetE('txtWidth').value ) ;
|
|
|
151 |
SetAttribute( e, "height", GetE('txtHeight').value ) ;
|
|
|
152 |
|
|
|
153 |
// Advances Attributes
|
|
|
154 |
|
|
|
155 |
SetAttribute( e, 'id' , GetE('txtAttId').value ) ;
|
|
|
156 |
SetAttribute( e, 'scale', GetE('cmbScale').value ) ;
|
|
|
157 |
|
|
|
158 |
SetAttribute( e, 'play', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
|
|
|
159 |
SetAttribute( e, 'loop', GetE('chkLoop').checked ? 'true' : 'false' ) ;
|
|
|
160 |
SetAttribute( e, 'menu', GetE('chkMenu').checked ? 'true' : 'false' ) ;
|
|
|
161 |
|
|
|
162 |
SetAttribute( e, 'title' , GetE('txtAttTitle').value ) ;
|
|
|
163 |
|
|
|
164 |
if ( oEditor.FCKBrowserInfo.IsIE )
|
|
|
165 |
{
|
|
|
166 |
SetAttribute( e, 'className', GetE('txtAttClasses').value ) ;
|
|
|
167 |
e.style.cssText = GetE('txtAttStyle').value ;
|
|
|
168 |
}
|
|
|
169 |
else
|
|
|
170 |
{
|
|
|
171 |
SetAttribute( e, 'class', GetE('txtAttClasses').value ) ;
|
|
|
172 |
SetAttribute( e, 'style', GetE('txtAttStyle').value ) ;
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
var ePreview ;
|
|
|
177 |
|
|
|
178 |
function SetPreviewElement( previewEl )
|
|
|
179 |
{
|
|
|
180 |
ePreview = previewEl ;
|
|
|
181 |
|
|
|
182 |
if ( GetE('txtUrl').value.length > 0 )
|
|
|
183 |
UpdatePreview() ;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
function UpdatePreview()
|
|
|
187 |
{
|
|
|
188 |
if ( !ePreview )
|
|
|
189 |
return ;
|
|
|
190 |
|
|
|
191 |
while ( ePreview.firstChild )
|
|
|
192 |
ePreview.removeChild( ePreview.firstChild ) ;
|
|
|
193 |
|
|
|
194 |
if ( GetE('txtUrl').value.length == 0 )
|
|
|
195 |
ePreview.innerHTML = ' ' ;
|
|
|
196 |
else
|
|
|
197 |
{
|
|
|
198 |
var oDoc = ePreview.ownerDocument || ePreview.document ;
|
|
|
199 |
var e = oDoc.createElement( 'EMBED' ) ;
|
|
|
200 |
|
|
|
201 |
e.src = GetE('txtUrl').value ;
|
|
|
202 |
e.type = 'application/x-shockwave-flash' ;
|
|
|
203 |
e.width = '100%' ;
|
|
|
204 |
e.height = '100%' ;
|
|
|
205 |
|
|
|
206 |
ePreview.appendChild( e ) ;
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
// <embed id="ePreview" src="fck_flash/claims.swf" width="100%" height="100%" style="visibility:hidden" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
|
|
|
211 |
|
|
|
212 |
function BrowseServer()
|
|
|
213 |
{
|
|
|
214 |
OpenFileBrowser( FCKConfig.FlashBrowserURL, FCKConfig.FlashBrowserWindowWidth, FCKConfig.FlashBrowserWindowHeight ) ;
|
|
|
215 |
}
|
|
|
216 |
|
|
|
217 |
function SetUrl( url, width, height )
|
|
|
218 |
{
|
|
|
219 |
GetE('txtUrl').value = url ;
|
|
|
220 |
|
|
|
221 |
if ( width )
|
|
|
222 |
GetE('txtWidth').value = width ;
|
|
|
223 |
|
|
|
224 |
if ( height )
|
|
|
225 |
GetE('txtHeight').value = height ;
|
|
|
226 |
|
|
|
227 |
UpdatePreview() ;
|
|
|
228 |
|
|
|
229 |
window.parent.SetSelectedTab( 'Info' ) ;
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
|
|
|
233 |
{
|
|
|
234 |
switch ( errorNumber )
|
|
|
235 |
{
|
|
|
236 |
case 0 : // No errors
|
|
|
237 |
alert( 'Your file has been successfully uploaded' ) ;
|
|
|
238 |
break ;
|
|
|
239 |
case 1 : // Custom error
|
|
|
240 |
alert( customMsg ) ;
|
|
|
241 |
return ;
|
|
|
242 |
case 101 : // Custom warning
|
|
|
243 |
alert( customMsg ) ;
|
|
|
244 |
break ;
|
|
|
245 |
case 201 :
|
|
|
246 |
alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
|
|
|
247 |
break ;
|
|
|
248 |
case 202 :
|
|
|
249 |
alert( 'Invalid file type' ) ;
|
|
|
250 |
return ;
|
|
|
251 |
case 203 :
|
|
|
252 |
alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
|
|
|
253 |
return ;
|
|
|
254 |
default :
|
|
|
255 |
alert( 'Error on file upload. Error number: ' + errorNumber ) ;
|
|
|
256 |
return ;
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
SetUrl( fileUrl ) ;
|
|
|
260 |
GetE('frmUpload').reset() ;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
var oUploadAllowedExtRegex = new RegExp( FCKConfig.FlashUploadAllowedExtensions, 'i' ) ;
|
|
|
264 |
var oUploadDeniedExtRegex = new RegExp( FCKConfig.FlashUploadDeniedExtensions, 'i' ) ;
|
|
|
265 |
|
|
|
266 |
function CheckUpload()
|
|
|
267 |
{
|
|
|
268 |
var sFile = GetE('txtUploadFile').value ;
|
|
|
269 |
|
|
|
270 |
if ( sFile.length == 0 )
|
|
|
271 |
{
|
|
|
272 |
alert( 'Please select a file to upload' ) ;
|
|
|
273 |
return false ;
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
if ( ( FCKConfig.FlashUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
|
|
|
277 |
( FCKConfig.FlashUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
|
|
|
278 |
{
|
|
|
279 |
OnUploadCompleted( 202 ) ;
|
|
|
280 |
return false ;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
return true ;
|
|
|
284 |
}
|