]> git.immae.eu Git - perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git/blob - sources/plugins/flash/dialogs/flash.js
Initial commit
[perso/Immae/Projets/packagist/connexionswing-ckeditor-component.git] / sources / plugins / flash / dialogs / flash.js
1 /**
2 * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5
6 ( function() {
7 // It is possible to set things in three different places.
8 // 1. As attributes in the object tag.
9 // 2. As param tags under the object tag.
10 // 3. As attributes in the embed tag.
11 // It is possible for a single attribute to be present in more than one place.
12 // So let's define a mapping between a sementic attribute and its syntactic
13 // equivalents.
14 // Then we'll set and retrieve attribute values according to the mapping,
15 // instead of having to check and set each syntactic attribute every time.
16 //
17 // Reference: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701
18 var ATTRTYPE_OBJECT = 1,
19 ATTRTYPE_PARAM = 2,
20 ATTRTYPE_EMBED = 4;
21
22 var attributesMap = {
23 id: [ {
24 type: ATTRTYPE_OBJECT, name: 'id'
25 } ],
26 classid: [ {
27 type: ATTRTYPE_OBJECT, name: 'classid'
28 } ],
29 codebase: [ {
30 type: ATTRTYPE_OBJECT, name: 'codebase'
31 } ],
32 pluginspage: [ {
33 type: ATTRTYPE_EMBED, name: 'pluginspage'
34 } ],
35 src: [ {
36 type: ATTRTYPE_PARAM, name: 'movie'
37 }, {
38 type: ATTRTYPE_EMBED, name: 'src'
39 }, {
40 type: ATTRTYPE_OBJECT, name: 'data'
41 } ],
42 name: [ {
43 type: ATTRTYPE_EMBED, name: 'name'
44 } ],
45 align: [ {
46 type: ATTRTYPE_OBJECT, name: 'align'
47 } ],
48 'class': [ {
49 type: ATTRTYPE_OBJECT, name: 'class'
50 }, {
51 type: ATTRTYPE_EMBED, name: 'class'
52 } ],
53 width: [ {
54 type: ATTRTYPE_OBJECT, name: 'width'
55 }, {
56 type: ATTRTYPE_EMBED, name: 'width'
57 } ],
58 height: [ {
59 type: ATTRTYPE_OBJECT, name: 'height'
60 }, {
61 type: ATTRTYPE_EMBED, name: 'height'
62 } ],
63 hSpace: [ {
64 type: ATTRTYPE_OBJECT, name: 'hSpace'
65 }, {
66 type: ATTRTYPE_EMBED, name: 'hSpace'
67 } ],
68 vSpace: [ {
69 type: ATTRTYPE_OBJECT, name: 'vSpace'
70 }, {
71 type: ATTRTYPE_EMBED, name: 'vSpace'
72 } ],
73 style: [ {
74 type: ATTRTYPE_OBJECT, name: 'style'
75 }, {
76 type: ATTRTYPE_EMBED, name: 'style'
77 } ],
78 type: [ {
79 type: ATTRTYPE_EMBED, name: 'type'
80 } ]
81 };
82
83 var names = [ 'play', 'loop', 'menu', 'quality', 'scale', 'salign', 'wmode', 'bgcolor', 'base', 'flashvars', 'allowScriptAccess', 'allowFullScreen' ];
84 for ( var i = 0; i < names.length; i++ ) {
85 attributesMap[ names[ i ] ] = [ {
86 type: ATTRTYPE_EMBED, name: names[ i ]
87 }, {
88 type: ATTRTYPE_PARAM, name: names[ i ]
89 } ];
90 }
91
92 // These attributes are "true" by default and not present in editor data (when "true").
93 // Note that, though default value of "allowFullScreen" is "true", it is not listed here.
94 // "allowFullScreen" is present in editor data regardless of the value (#7634).
95 names = [ 'play', 'loop', 'menu' ];
96 for ( i = 0; i < names.length; i++ )
97 attributesMap[ names[ i ] ][ 0 ][ 'default' ] = attributesMap[ names[ i ] ][ 1 ][ 'default' ] = true;
98
99 function loadValue( objectNode, embedNode, paramMap ) {
100 var attributes = attributesMap[ this.id ];
101 if ( !attributes )
102 return;
103
104 var isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox );
105 for ( var i = 0; i < attributes.length; i++ ) {
106 var attrDef = attributes[ i ];
107 switch ( attrDef.type ) {
108 case ATTRTYPE_OBJECT:
109 if ( !objectNode )
110 continue;
111 if ( objectNode.getAttribute( attrDef.name ) !== null ) {
112 var value = objectNode.getAttribute( attrDef.name );
113 if ( isCheckbox ) {
114 this.setValue( value.toLowerCase() == 'true' );
115 } else {
116 this.setValue( value );
117 }
118 return;
119 } else if ( isCheckbox ) {
120 this.setValue( !!attrDef['default'] );
121 }
122 break;
123 case ATTRTYPE_PARAM:
124 if ( !objectNode ) {
125 continue;
126 }
127 if ( attrDef.name in paramMap ) {
128 value = paramMap[ attrDef.name ];
129 if ( isCheckbox )
130 this.setValue( value.toLowerCase() == 'true' );
131 else
132 this.setValue( value );
133 return;
134 } else if ( isCheckbox ) {
135 this.setValue( !!attrDef[ 'default' ] );
136 }
137 break;
138 case ATTRTYPE_EMBED:
139 if ( !embedNode )
140 continue;
141 if ( embedNode.getAttribute( attrDef.name ) ) {
142 value = embedNode.getAttribute( attrDef.name );
143 if ( isCheckbox )
144 this.setValue( value.toLowerCase() == 'true' );
145 else
146 this.setValue( value );
147 return;
148 } else if ( isCheckbox ) {
149 this.setValue( !!attrDef[ 'default' ] );
150 }
151 }
152 }
153 }
154
155 function commitValue( objectNode, embedNode, paramMap ) {
156 var attributes = attributesMap[ this.id ];
157 if ( !attributes )
158 return;
159
160 var isRemove = ( this.getValue() === '' ),
161 isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox );
162
163 for ( var i = 0; i < attributes.length; i++ ) {
164 var attrDef = attributes[ i ];
165 switch ( attrDef.type ) {
166 case ATTRTYPE_OBJECT:
167 // Avoid applying the data attribute when not needed (#7733)
168 if ( !objectNode || ( attrDef.name == 'data' && embedNode && !objectNode.hasAttribute( 'data' ) ) )
169 continue;
170 var value = this.getValue();
171 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] )
172 objectNode.removeAttribute( attrDef.name );
173 else
174 objectNode.setAttribute( attrDef.name, value );
175 break;
176 case ATTRTYPE_PARAM:
177 if ( !objectNode )
178 continue;
179 value = this.getValue();
180 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] ) {
181 if ( attrDef.name in paramMap )
182 paramMap[ attrDef.name ].remove();
183 } else {
184 if ( attrDef.name in paramMap )
185 paramMap[ attrDef.name ].setAttribute( 'value', value );
186 else {
187 var param = CKEDITOR.dom.element.createFromHtml( '<cke:param></cke:param>', objectNode.getDocument() );
188 param.setAttributes( { name: attrDef.name, value: value } );
189 if ( objectNode.getChildCount() < 1 )
190 param.appendTo( objectNode );
191 else
192 param.insertBefore( objectNode.getFirst() );
193 }
194 }
195 break;
196 case ATTRTYPE_EMBED:
197 if ( !embedNode )
198 continue;
199 value = this.getValue();
200 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] )
201 embedNode.removeAttribute( attrDef.name );
202 else {
203 embedNode.setAttribute( attrDef.name, value );
204 }
205 }
206 }
207 }
208
209 CKEDITOR.dialog.add( 'flash', function( editor ) {
210 var makeObjectTag = !editor.config.flashEmbedTagOnly,
211 makeEmbedTag = editor.config.flashAddEmbedTag || editor.config.flashEmbedTagOnly;
212
213 var previewPreloader,
214 previewAreaHtml = '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) + '<br>' +
215 '<div id="cke_FlashPreviewLoader' + CKEDITOR.tools.getNextNumber() + '" style="display:none"><div class="loading">&nbsp;</div></div>' +
216 '<div id="cke_FlashPreviewBox' + CKEDITOR.tools.getNextNumber() + '" class="FlashPreviewBox"></div></div>';
217
218 return {
219 title: editor.lang.flash.title,
220 minWidth: 420,
221 minHeight: 310,
222 onShow: function() {
223 // Clear previously saved elements.
224 this.fakeImage = this.objectNode = this.embedNode = null;
225 previewPreloader = new CKEDITOR.dom.element( 'embed', editor.document );
226
227 // Try to detect any embed or object tag that has Flash parameters.
228 var fakeImage = this.getSelectedElement();
229 if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'flash' ) {
230 this.fakeImage = fakeImage;
231
232 var realElement = editor.restoreRealElement( fakeImage ),
233 objectNode = null,
234 embedNode = null,
235 paramMap = {};
236 if ( realElement.getName() == 'cke:object' ) {
237 objectNode = realElement;
238 var embedList = objectNode.getElementsByTag( 'embed', 'cke' );
239 if ( embedList.count() > 0 )
240 embedNode = embedList.getItem( 0 );
241 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
242 for ( var i = 0, length = paramList.count(); i < length; i++ ) {
243 var item = paramList.getItem( i ),
244 name = item.getAttribute( 'name' ),
245 value = item.getAttribute( 'value' );
246 paramMap[ name ] = value;
247 }
248 } else if ( realElement.getName() == 'cke:embed' ) {
249 embedNode = realElement;
250 }
251
252 this.objectNode = objectNode;
253 this.embedNode = embedNode;
254
255 this.setupContent( objectNode, embedNode, paramMap, fakeImage );
256 }
257 },
258 onOk: function() {
259 // If there's no selected object or embed, create one. Otherwise, reuse the
260 // selected object and embed nodes.
261 var objectNode = null,
262 embedNode = null,
263 paramMap = null;
264 if ( !this.fakeImage ) {
265 if ( makeObjectTag ) {
266 objectNode = CKEDITOR.dom.element.createFromHtml( '<cke:object></cke:object>', editor.document );
267 var attributes = {
268 classid: 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
269 codebase: 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'
270 };
271 objectNode.setAttributes( attributes );
272 }
273 if ( makeEmbedTag ) {
274 embedNode = CKEDITOR.dom.element.createFromHtml( '<cke:embed></cke:embed>', editor.document );
275 embedNode.setAttributes( {
276 type: 'application/x-shockwave-flash',
277 pluginspage: 'http://www.macromedia.com/go/getflashplayer'
278 } );
279 if ( objectNode )
280 embedNode.appendTo( objectNode );
281 }
282 } else {
283 objectNode = this.objectNode;
284 embedNode = this.embedNode;
285 }
286
287 // Produce the paramMap if there's an object tag.
288 if ( objectNode ) {
289 paramMap = {};
290 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
291 for ( var i = 0, length = paramList.count(); i < length; i++ )
292 paramMap[ paramList.getItem( i ).getAttribute( 'name' ) ] = paramList.getItem( i );
293 }
294
295 // A subset of the specified attributes/styles
296 // should also be applied on the fake element to
297 // have better visual effect. (#5240)
298 var extraStyles = {},
299 extraAttributes = {};
300 this.commitContent( objectNode, embedNode, paramMap, extraStyles, extraAttributes );
301
302 // Refresh the fake image.
303 var newFakeImage = editor.createFakeElement( objectNode || embedNode, 'cke_flash', 'flash', true );
304 newFakeImage.setAttributes( extraAttributes );
305 newFakeImage.setStyles( extraStyles );
306 if ( this.fakeImage ) {
307 newFakeImage.replace( this.fakeImage );
308 editor.getSelection().selectElement( newFakeImage );
309 } else {
310 editor.insertElement( newFakeImage );
311 }
312 },
313
314 onHide: function() {
315 if ( this.preview )
316 this.preview.setHtml( '' );
317 },
318
319 contents: [ {
320 id: 'info',
321 label: editor.lang.common.generalTab,
322 accessKey: 'I',
323 elements: [ {
324 type: 'vbox',
325 padding: 0,
326 children: [ {
327 type: 'hbox',
328 widths: [ '280px', '110px' ],
329 align: 'right',
330 children: [ {
331 id: 'src',
332 type: 'text',
333 label: editor.lang.common.url,
334 required: true,
335 validate: CKEDITOR.dialog.validate.notEmpty( editor.lang.flash.validateSrc ),
336 setup: loadValue,
337 commit: commitValue,
338 onLoad: function() {
339 var dialog = this.getDialog(),
340 updatePreview = function( src ) {
341 // Query the preloader to figure out the url impacted by based href.
342 previewPreloader.setAttribute( 'src', src );
343 dialog.preview.setHtml( '<embed height="100%" width="100%" src="' + CKEDITOR.tools.htmlEncode( previewPreloader.getAttribute( 'src' ) ) +
344 '" type="application/x-shockwave-flash"></embed>' );
345 };
346 // Preview element
347 dialog.preview = dialog.getContentElement( 'info', 'preview' ).getElement().getChild( 3 );
348
349 // Sync on inital value loaded.
350 this.on( 'change', function( evt ) {
351
352 if ( evt.data && evt.data.value )
353 updatePreview( evt.data.value );
354 } );
355 // Sync when input value changed.
356 this.getInputElement().on( 'change', function() {
357
358 updatePreview( this.getValue() );
359 }, this );
360 }
361 },
362 {
363 type: 'button',
364 id: 'browse',
365 filebrowser: 'info:src',
366 hidden: true,
367 // v-align with the 'src' field.
368 // TODO: We need something better than a fixed size here.
369 style: 'display:inline-block;margin-top:14px;',
370 label: editor.lang.common.browseServer
371 } ]
372 } ]
373 },
374 {
375 type: 'hbox',
376 widths: [ '25%', '25%', '25%', '25%', '25%' ],
377 children: [ {
378 type: 'text',
379 id: 'width',
380 requiredContent: 'embed[width]',
381 style: 'width:95px',
382 label: editor.lang.common.width,
383 validate: CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.width ) ),
384 setup: loadValue,
385 commit: commitValue
386 },
387 {
388 type: 'text',
389 id: 'height',
390 requiredContent: 'embed[height]',
391 style: 'width:95px',
392 label: editor.lang.common.height,
393 validate: CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.height ) ),
394 setup: loadValue,
395 commit: commitValue
396 },
397 {
398 type: 'text',
399 id: 'hSpace',
400 requiredContent: 'embed[hspace]',
401 style: 'width:95px',
402 label: editor.lang.flash.hSpace,
403 validate: CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHSpace ),
404 setup: loadValue,
405 commit: commitValue
406 },
407 {
408 type: 'text',
409 id: 'vSpace',
410 requiredContent: 'embed[vspace]',
411 style: 'width:95px',
412 label: editor.lang.flash.vSpace,
413 validate: CKEDITOR.dialog.validate.integer( editor.lang.flash.validateVSpace ),
414 setup: loadValue,
415 commit: commitValue
416 } ]
417 },
418
419 {
420 type: 'vbox',
421 children: [ {
422 type: 'html',
423 id: 'preview',
424 style: 'width:95%;',
425 html: previewAreaHtml
426 } ]
427 } ]
428 },
429 {
430 id: 'Upload',
431 hidden: true,
432 filebrowser: 'uploadButton',
433 label: editor.lang.common.upload,
434 elements: [ {
435 type: 'file',
436 id: 'upload',
437 label: editor.lang.common.upload,
438 size: 38
439 },
440 {
441 type: 'fileButton',
442 id: 'uploadButton',
443 label: editor.lang.common.uploadSubmit,
444 filebrowser: 'info:src',
445 'for': [ 'Upload', 'upload' ]
446 } ]
447 },
448 {
449 id: 'properties',
450 label: editor.lang.flash.propertiesTab,
451 elements: [ {
452 type: 'hbox',
453 widths: [ '50%', '50%' ],
454 children: [ {
455 id: 'scale',
456 type: 'select',
457 requiredContent: 'embed[scale]',
458 label: editor.lang.flash.scale,
459 'default': '',
460 style: 'width : 100%;',
461 items: [
462 [ editor.lang.common.notSet, '' ],
463 [ editor.lang.flash.scaleAll, 'showall' ],
464 [ editor.lang.flash.scaleNoBorder, 'noborder' ],
465 [ editor.lang.flash.scaleFit, 'exactfit' ]
466 ],
467 setup: loadValue,
468 commit: commitValue
469 },
470 {
471 id: 'allowScriptAccess',
472 type: 'select',
473 requiredContent: 'embed[allowscriptaccess]',
474 label: editor.lang.flash.access,
475 'default': '',
476 style: 'width : 100%;',
477 items: [
478 [ editor.lang.common.notSet, '' ],
479 [ editor.lang.flash.accessAlways, 'always' ],
480 [ editor.lang.flash.accessSameDomain, 'samedomain' ],
481 [ editor.lang.flash.accessNever, 'never' ]
482 ],
483 setup: loadValue,
484 commit: commitValue
485 } ]
486 },
487 {
488 type: 'hbox',
489 widths: [ '50%', '50%' ],
490 children: [ {
491 id: 'wmode',
492 type: 'select',
493 requiredContent: 'embed[wmode]',
494 label: editor.lang.flash.windowMode,
495 'default': '',
496 style: 'width : 100%;',
497 items: [
498 [ editor.lang.common.notSet, '' ],
499 [ editor.lang.flash.windowModeWindow, 'window' ],
500 [ editor.lang.flash.windowModeOpaque, 'opaque' ],
501 [ editor.lang.flash.windowModeTransparent, 'transparent' ]
502 ],
503 setup: loadValue,
504 commit: commitValue
505 },
506 {
507 id: 'quality',
508 type: 'select',
509 requiredContent: 'embed[quality]',
510 label: editor.lang.flash.quality,
511 'default': 'high',
512 style: 'width : 100%;',
513 items: [
514 [ editor.lang.common.notSet, '' ],
515 [ editor.lang.flash.qualityBest, 'best' ],
516 [ editor.lang.flash.qualityHigh, 'high' ],
517 [ editor.lang.flash.qualityAutoHigh, 'autohigh' ],
518 [ editor.lang.flash.qualityMedium, 'medium' ],
519 [ editor.lang.flash.qualityAutoLow, 'autolow' ],
520 [ editor.lang.flash.qualityLow, 'low' ]
521 ],
522 setup: loadValue,
523 commit: commitValue
524 } ]
525 },
526 {
527 type: 'hbox',
528 widths: [ '50%', '50%' ],
529 children: [ {
530 id: 'align',
531 type: 'select',
532 requiredContent: 'object[align]',
533 label: editor.lang.common.align,
534 'default': '',
535 style: 'width : 100%;',
536 items: [
537 [ editor.lang.common.notSet, '' ],
538 [ editor.lang.common.alignLeft, 'left' ],
539 [ editor.lang.flash.alignAbsBottom, 'absBottom' ],
540 [ editor.lang.flash.alignAbsMiddle, 'absMiddle' ],
541 [ editor.lang.flash.alignBaseline, 'baseline' ],
542 [ editor.lang.common.alignBottom, 'bottom' ],
543 [ editor.lang.common.alignMiddle, 'middle' ],
544 [ editor.lang.common.alignRight, 'right' ],
545 [ editor.lang.flash.alignTextTop, 'textTop' ],
546 [ editor.lang.common.alignTop, 'top' ]
547 ],
548 setup: loadValue,
549 commit: function( objectNode, embedNode, paramMap, extraStyles, extraAttributes ) {
550 var value = this.getValue();
551 commitValue.apply( this, arguments );
552 value && ( extraAttributes.align = value );
553 }
554 },
555 {
556 type: 'html',
557 html: '<div></div>'
558 } ]
559 },
560 {
561 type: 'fieldset',
562 label: CKEDITOR.tools.htmlEncode( editor.lang.flash.flashvars ),
563 children: [ {
564 type: 'vbox',
565 padding: 0,
566 children: [ {
567 type: 'checkbox',
568 id: 'menu',
569 label: editor.lang.flash.chkMenu,
570 'default': true,
571 setup: loadValue,
572 commit: commitValue
573 },
574 {
575 type: 'checkbox',
576 id: 'play',
577 label: editor.lang.flash.chkPlay,
578 'default': true,
579 setup: loadValue,
580 commit: commitValue
581 },
582 {
583 type: 'checkbox',
584 id: 'loop',
585 label: editor.lang.flash.chkLoop,
586 'default': true,
587 setup: loadValue,
588 commit: commitValue
589 },
590 {
591 type: 'checkbox',
592 id: 'allowFullScreen',
593 label: editor.lang.flash.chkFull,
594 'default': true,
595 setup: loadValue,
596 commit: commitValue
597 } ]
598 } ]
599 } ]
600 },
601 {
602 id: 'advanced',
603 label: editor.lang.common.advancedTab,
604 elements: [ {
605 type: 'hbox',
606 children: [ {
607 type: 'text',
608 id: 'id',
609 requiredContent: 'object[id]',
610 label: editor.lang.common.id,
611 setup: loadValue,
612 commit: commitValue
613 } ]
614 },
615 {
616 type: 'hbox',
617 widths: [ '45%', '55%' ],
618 children: [ {
619 type: 'text',
620 id: 'bgcolor',
621 requiredContent: 'embed[bgcolor]',
622 label: editor.lang.flash.bgcolor,
623 setup: loadValue,
624 commit: commitValue
625 },
626 {
627 type: 'text',
628 id: 'class',
629 requiredContent: 'embed(cke-xyz)', // Random text like 'xyz' will check if all are allowed.
630 label: editor.lang.common.cssClass,
631 setup: loadValue,
632 commit: commitValue
633 } ]
634 },
635 {
636 type: 'text',
637 id: 'style',
638 requiredContent: 'embed{cke-xyz}', // Random text like 'xyz' will check if all are allowed.
639 validate: CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),
640 label: editor.lang.common.cssStyle,
641 setup: loadValue,
642 commit: commitValue
643 } ]
644 } ]
645 };
646 } );
647 } )();