2 Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
9 * It is possible to set things in three different places.
\r
10 * 1. As attributes in the object tag.
\r
11 * 2. As param tags under the object tag.
\r
12 * 3. As attributes in the embed tag.
\r
13 * It is possible for a single attribute to be present in more than one place.
\r
14 * So let's define a mapping between a sementic attribute and its syntactic
\r
16 * Then we'll set and retrieve attribute values according to the mapping,
\r
17 * instead of having to check and set each syntactic attribute every time.
\r
19 * Reference: http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701
\r
21 var ATTRTYPE_OBJECT = 1,
\r
27 id : [ { type : ATTRTYPE_OBJECT, name : 'id' } ],
\r
28 classid : [ { type : ATTRTYPE_OBJECT, name : 'classid' } ],
\r
29 codebase : [ { type : ATTRTYPE_OBJECT, name : 'codebase'} ],
\r
30 pluginspage : [ { type : ATTRTYPE_EMBED, name : 'pluginspage' } ],
\r
31 src : [ { type : ATTRTYPE_PARAM, name : 'movie' }, { type : ATTRTYPE_EMBED, name : 'src' }, { type : ATTRTYPE_OBJECT, name : 'data' } ],
\r
32 name : [ { type : ATTRTYPE_EMBED, name : 'name' } ],
\r
33 align : [ { type : ATTRTYPE_OBJECT, name : 'align' } ],
\r
34 title : [ { type : ATTRTYPE_OBJECT, name : 'title' }, { type : ATTRTYPE_EMBED, name : 'title' } ],
\r
35 'class' : [ { type : ATTRTYPE_OBJECT, name : 'class' }, { type : ATTRTYPE_EMBED, name : 'class'} ],
\r
36 width : [ { type : ATTRTYPE_OBJECT, name : 'width' }, { type : ATTRTYPE_EMBED, name : 'width' } ],
\r
37 height : [ { type : ATTRTYPE_OBJECT, name : 'height' }, { type : ATTRTYPE_EMBED, name : 'height' } ],
\r
38 hSpace : [ { type : ATTRTYPE_OBJECT, name : 'hSpace' }, { type : ATTRTYPE_EMBED, name : 'hSpace' } ],
\r
39 vSpace : [ { type : ATTRTYPE_OBJECT, name : 'vSpace' }, { type : ATTRTYPE_EMBED, name : 'vSpace' } ],
\r
40 style : [ { type : ATTRTYPE_OBJECT, name : 'style' }, { type : ATTRTYPE_EMBED, name : 'style' } ],
\r
41 type : [ { type : ATTRTYPE_EMBED, name : 'type' } ]
\r
44 var names = [ 'play', 'loop', 'menu', 'quality', 'scale', 'salign', 'wmode', 'bgcolor', 'base', 'flashvars', 'allowScriptAccess',
\r
45 'allowFullScreen' ];
\r
46 for ( var i = 0 ; i < names.length ; i++ )
\r
47 attributesMap[ names[i] ] = [ { type : ATTRTYPE_EMBED, name : names[i] }, { type : ATTRTYPE_PARAM, name : names[i] } ];
\r
48 names = [ 'allowFullScreen', 'play', 'loop', 'menu' ];
\r
49 for ( i = 0 ; i < names.length ; i++ )
\r
50 attributesMap[ names[i] ][0]['default'] = attributesMap[ names[i] ][1]['default'] = true;
\r
52 var defaultToPixel = CKEDITOR.tools.cssLength;
\r
54 function loadValue( objectNode, embedNode, paramMap )
\r
56 var attributes = attributesMap[ this.id ];
\r
60 var isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox );
\r
61 for ( var i = 0 ; i < attributes.length ; i++ )
\r
63 var attrDef = attributes[ i ];
\r
64 switch ( attrDef.type )
\r
66 case ATTRTYPE_OBJECT:
\r
69 if ( objectNode.getAttribute( attrDef.name ) !== null )
\r
71 var value = objectNode.getAttribute( attrDef.name );
\r
73 this.setValue( value.toLowerCase() == 'true' );
\r
75 this.setValue( value );
\r
78 else if ( isCheckbox )
\r
79 this.setValue( !!attrDef[ 'default' ] );
\r
81 case ATTRTYPE_PARAM:
\r
84 if ( attrDef.name in paramMap )
\r
86 value = paramMap[ attrDef.name ];
\r
88 this.setValue( value.toLowerCase() == 'true' );
\r
90 this.setValue( value );
\r
93 else if ( isCheckbox )
\r
94 this.setValue( !!attrDef[ 'default' ] );
\r
96 case ATTRTYPE_EMBED:
\r
99 if ( embedNode.getAttribute( attrDef.name ) )
\r
101 value = embedNode.getAttribute( attrDef.name );
\r
103 this.setValue( value.toLowerCase() == 'true' );
\r
105 this.setValue( value );
\r
108 else if ( isCheckbox )
\r
109 this.setValue( !!attrDef[ 'default' ] );
\r
114 function commitValue( objectNode, embedNode, paramMap )
\r
116 var attributes = attributesMap[ this.id ];
\r
120 var isRemove = ( this.getValue() === '' ),
\r
121 isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox );
\r
123 for ( var i = 0 ; i < attributes.length ; i++ )
\r
125 var attrDef = attributes[i];
\r
126 switch ( attrDef.type )
\r
128 case ATTRTYPE_OBJECT:
\r
129 // Avoid applying the data attribute when not needed (#7733)
\r
130 if ( !objectNode || ( attrDef.name == 'data' && embedNode && !objectNode.hasAttribute( 'data' ) ) )
\r
132 var value = this.getValue();
\r
133 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] )
\r
134 objectNode.removeAttribute( attrDef.name );
\r
136 objectNode.setAttribute( attrDef.name, value );
\r
138 case ATTRTYPE_PARAM:
\r
141 value = this.getValue();
\r
142 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] )
\r
144 if ( attrDef.name in paramMap )
\r
145 paramMap[ attrDef.name ].remove();
\r
149 if ( attrDef.name in paramMap )
\r
150 paramMap[ attrDef.name ].setAttribute( 'value', value );
\r
153 var param = CKEDITOR.dom.element.createFromHtml( '<cke:param></cke:param>', objectNode.getDocument() );
\r
154 param.setAttributes( { name : attrDef.name, value : value } );
\r
155 if ( objectNode.getChildCount() < 1 )
\r
156 param.appendTo( objectNode );
\r
158 param.insertBefore( objectNode.getFirst() );
\r
162 case ATTRTYPE_EMBED:
\r
165 value = this.getValue();
\r
166 if ( isRemove || isCheckbox && value === attrDef[ 'default' ])
\r
167 embedNode.removeAttribute( attrDef.name );
\r
169 embedNode.setAttribute( attrDef.name, value );
\r
174 CKEDITOR.dialog.add( 'flash', function( editor )
\r
176 var makeObjectTag = !editor.config.flashEmbedTagOnly,
\r
177 makeEmbedTag = editor.config.flashAddEmbedTag || editor.config.flashEmbedTagOnly;
\r
179 var previewPreloader,
\r
180 previewAreaHtml = '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) +'<br>' +
\r
181 '<div id="cke_FlashPreviewLoader' + CKEDITOR.tools.getNextNumber() + '" style="display:none"><div class="loading"> </div></div>' +
\r
182 '<div id="cke_FlashPreviewBox' + CKEDITOR.tools.getNextNumber() + '" class="FlashPreviewBox"></div></div>';
\r
185 title : editor.lang.flash.title,
\r
188 onShow : function()
\r
190 // Clear previously saved elements.
\r
191 this.fakeImage = this.objectNode = this.embedNode = null;
\r
192 previewPreloader = new CKEDITOR.dom.element( 'embed', editor.document );
\r
194 // Try to detect any embed or object tag that has Flash parameters.
\r
195 var fakeImage = this.getSelectedElement();
\r
196 if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'flash' )
\r
198 this.fakeImage = fakeImage;
\r
200 var realElement = editor.restoreRealElement( fakeImage ),
\r
201 objectNode = null, embedNode = null, paramMap = {};
\r
202 if ( realElement.getName() == 'cke:object' )
\r
204 objectNode = realElement;
\r
205 var embedList = objectNode.getElementsByTag( 'embed', 'cke' );
\r
206 if ( embedList.count() > 0 )
\r
207 embedNode = embedList.getItem( 0 );
\r
208 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
\r
209 for ( var i = 0, length = paramList.count() ; i < length ; i++ )
\r
211 var item = paramList.getItem( i ),
\r
212 name = item.getAttribute( 'name' ),
\r
213 value = item.getAttribute( 'value' );
\r
214 paramMap[ name ] = value;
\r
217 else if ( realElement.getName() == 'cke:embed' )
\r
218 embedNode = realElement;
\r
220 this.objectNode = objectNode;
\r
221 this.embedNode = embedNode;
\r
223 this.setupContent( objectNode, embedNode, paramMap, fakeImage );
\r
228 // If there's no selected object or embed, create one. Otherwise, reuse the
\r
229 // selected object and embed nodes.
\r
230 var objectNode = null,
\r
233 if ( !this.fakeImage )
\r
235 if ( makeObjectTag )
\r
237 objectNode = CKEDITOR.dom.element.createFromHtml( '<cke:object></cke:object>', editor.document );
\r
239 classid : 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
\r
240 codebase : 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'
\r
242 objectNode.setAttributes( attributes );
\r
244 if ( makeEmbedTag )
\r
246 embedNode = CKEDITOR.dom.element.createFromHtml( '<cke:embed></cke:embed>', editor.document );
\r
247 embedNode.setAttributes(
\r
249 type : 'application/x-shockwave-flash',
\r
250 pluginspage : 'http://www.macromedia.com/go/getflashplayer'
\r
253 embedNode.appendTo( objectNode );
\r
258 objectNode = this.objectNode;
\r
259 embedNode = this.embedNode;
\r
262 // Produce the paramMap if there's an object tag.
\r
266 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
\r
267 for ( var i = 0, length = paramList.count() ; i < length ; i++ )
\r
268 paramMap[ paramList.getItem( i ).getAttribute( 'name' ) ] = paramList.getItem( i );
\r
271 // A subset of the specified attributes/styles
\r
272 // should also be applied on the fake element to
\r
273 // have better visual effect. (#5240)
\r
274 var extraStyles = {}, extraAttributes = {};
\r
275 this.commitContent( objectNode, embedNode, paramMap, extraStyles, extraAttributes );
\r
277 // Refresh the fake image.
\r
278 var newFakeImage = editor.createFakeElement( objectNode || embedNode, 'cke_flash', 'flash', true );
\r
279 newFakeImage.setAttributes( extraAttributes );
\r
280 newFakeImage.setStyles( extraStyles );
\r
281 if ( this.fakeImage )
\r
283 newFakeImage.replace( this.fakeImage );
\r
284 editor.getSelection().selectElement( newFakeImage );
\r
287 editor.insertElement( newFakeImage );
\r
290 onHide : function()
\r
292 if ( this.preview )
\r
293 this.preview.setHtml('');
\r
299 label : editor.lang.common.generalTab,
\r
310 widths : [ '280px', '110px' ],
\r
317 label : editor.lang.common.url,
\r
319 validate : CKEDITOR.dialog.validate.notEmpty( editor.lang.flash.validateSrc ),
\r
321 commit : commitValue,
\r
322 onLoad : function()
\r
324 var dialog = this.getDialog(),
\r
325 updatePreview = function( src ){
\r
326 // Query the preloader to figure out the url impacted by based href.
\r
327 previewPreloader.setAttribute( 'src', src );
\r
328 dialog.preview.setHtml( '<embed height="100%" width="100%" src="'
\r
329 + CKEDITOR.tools.htmlEncode( previewPreloader.getAttribute( 'src' ) )
\r
330 + '" type="application/x-shockwave-flash"></embed>' );
\r
333 dialog.preview = dialog.getContentElement( 'info', 'preview' ).getElement().getChild( 3 );
\r
335 // Sync on inital value loaded.
\r
336 this.on( 'change', function( evt ){
\r
338 if ( evt.data && evt.data.value )
\r
339 updatePreview( evt.data.value );
\r
341 // Sync when input value changed.
\r
342 this.getInputElement().on( 'change', function( evt ){
\r
344 updatePreview( this.getValue() );
\r
351 filebrowser : 'info:src',
\r
353 // v-align with the 'src' field.
\r
354 // TODO: We need something better than a fixed size here.
\r
355 style : 'display:inline-block;margin-top:10px;',
\r
356 label : editor.lang.common.browseServer
\r
364 widths : [ '25%', '25%', '25%', '25%', '25%' ],
\r
370 style : 'width:95px',
\r
371 label : editor.lang.common.width,
\r
372 validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.width ) ),
\r
374 commit : commitValue
\r
379 style : 'width:95px',
\r
380 label : editor.lang.common.height,
\r
381 validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength.replace( '%1', editor.lang.common.height ) ),
\r
383 commit : commitValue
\r
388 style : 'width:95px',
\r
389 label : editor.lang.flash.hSpace,
\r
390 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHSpace ),
\r
392 commit : commitValue
\r
397 style : 'width:95px',
\r
398 label : editor.lang.flash.vSpace,
\r
399 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateVSpace ),
\r
401 commit : commitValue
\r
413 style : 'width:95%;',
\r
414 html : previewAreaHtml
\r
423 filebrowser : 'uploadButton',
\r
424 label : editor.lang.common.upload,
\r
430 label : editor.lang.common.upload,
\r
434 type : 'fileButton',
\r
435 id : 'uploadButton',
\r
436 label : editor.lang.common.uploadSubmit,
\r
437 filebrowser : 'info:src',
\r
438 'for' : [ 'Upload', 'upload' ]
\r
444 label : editor.lang.flash.propertiesTab,
\r
449 widths : [ '50%', '50%' ],
\r
455 label : editor.lang.flash.scale,
\r
457 style : 'width : 100%;',
\r
460 [ editor.lang.common.notSet , ''],
\r
461 [ editor.lang.flash.scaleAll, 'showall' ],
\r
462 [ editor.lang.flash.scaleNoBorder, 'noborder' ],
\r
463 [ editor.lang.flash.scaleFit, 'exactfit' ]
\r
466 commit : commitValue
\r
469 id : 'allowScriptAccess',
\r
471 label : editor.lang.flash.access,
\r
473 style : 'width : 100%;',
\r
476 [ editor.lang.common.notSet , ''],
\r
477 [ editor.lang.flash.accessAlways, 'always' ],
\r
478 [ editor.lang.flash.accessSameDomain, 'samedomain' ],
\r
479 [ editor.lang.flash.accessNever, 'never' ]
\r
482 commit : commitValue
\r
488 widths : [ '50%', '50%' ],
\r
494 label : editor.lang.flash.windowMode,
\r
496 style : 'width : 100%;',
\r
499 [ editor.lang.common.notSet , '' ],
\r
500 [ editor.lang.flash.windowModeWindow, 'window' ],
\r
501 [ editor.lang.flash.windowModeOpaque, 'opaque' ],
\r
502 [ editor.lang.flash.windowModeTransparent, 'transparent' ]
\r
505 commit : commitValue
\r
510 label : editor.lang.flash.quality,
\r
511 'default' : 'high',
\r
512 style : 'width : 100%;',
\r
515 [ editor.lang.common.notSet , '' ],
\r
516 [ editor.lang.flash.qualityBest, 'best' ],
\r
517 [ editor.lang.flash.qualityHigh, 'high' ],
\r
518 [ editor.lang.flash.qualityAutoHigh, 'autohigh' ],
\r
519 [ editor.lang.flash.qualityMedium, 'medium' ],
\r
520 [ editor.lang.flash.qualityAutoLow, 'autolow' ],
\r
521 [ editor.lang.flash.qualityLow, 'low' ]
\r
524 commit : commitValue
\r
530 widths : [ '50%', '50%' ],
\r
536 label : editor.lang.common.align,
\r
538 style : 'width : 100%;',
\r
541 [ editor.lang.common.notSet , ''],
\r
542 [ editor.lang.common.alignLeft , 'left'],
\r
543 [ editor.lang.flash.alignAbsBottom , 'absBottom'],
\r
544 [ editor.lang.flash.alignAbsMiddle , 'absMiddle'],
\r
545 [ editor.lang.flash.alignBaseline , 'baseline'],
\r
546 [ editor.lang.common.alignBottom , 'bottom'],
\r
547 [ editor.lang.common.alignMiddle , 'middle'],
\r
548 [ editor.lang.common.alignRight , 'right'],
\r
549 [ editor.lang.flash.alignTextTop , 'textTop'],
\r
550 [ editor.lang.common.alignTop , 'top']
\r
553 commit : function( objectNode, embedNode, paramMap, extraStyles, extraAttributes )
\r
555 var value = this.getValue();
\r
556 commitValue.apply( this, arguments );
\r
557 value && ( extraAttributes.align = value );
\r
562 html : '<div></div>'
\r
568 label : CKEDITOR.tools.htmlEncode( editor.lang.flash.flashvars ),
\r
579 label : editor.lang.flash.chkMenu,
\r
582 commit : commitValue
\r
587 label : editor.lang.flash.chkPlay,
\r
590 commit : commitValue
\r
595 label : editor.lang.flash.chkLoop,
\r
598 commit : commitValue
\r
602 id : 'allowFullScreen',
\r
603 label : editor.lang.flash.chkFull,
\r
606 commit : commitValue
\r
616 label : editor.lang.common.advancedTab,
\r
621 widths : [ '45%', '55%' ],
\r
627 label : editor.lang.common.id,
\r
629 commit : commitValue
\r
634 label : editor.lang.common.advisoryTitle,
\r
636 commit : commitValue
\r
642 widths : [ '45%', '55%' ],
\r
648 label : editor.lang.flash.bgcolor,
\r
650 commit : commitValue
\r
655 label : editor.lang.common.cssClass,
\r
657 commit : commitValue
\r
664 validate : CKEDITOR.dialog.validate.inlineStyle( editor.lang.common.invalidInlineStyle ),
\r
665 label : editor.lang.common.cssStyle,
\r
667 commit : commitValue
\r