2 Copyright (c) 2003-2011, 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 function loadValue( objectNode, embedNode, paramMap )
\r
54 var attributes = attributesMap[ this.id ];
\r
58 var isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox );
\r
59 for ( var i = 0 ; i < attributes.length ; i++ )
\r
61 var attrDef = attributes[ i ];
\r
62 switch ( attrDef.type )
\r
64 case ATTRTYPE_OBJECT:
\r
67 if ( objectNode.getAttribute( attrDef.name ) !== null )
\r
69 var value = objectNode.getAttribute( attrDef.name );
\r
71 this.setValue( value.toLowerCase() == 'true' );
\r
73 this.setValue( value );
\r
76 else if ( isCheckbox )
\r
77 this.setValue( !!attrDef[ 'default' ] );
\r
79 case ATTRTYPE_PARAM:
\r
82 if ( attrDef.name in paramMap )
\r
84 value = paramMap[ attrDef.name ];
\r
86 this.setValue( value.toLowerCase() == 'true' );
\r
88 this.setValue( value );
\r
91 else if ( isCheckbox )
\r
92 this.setValue( !!attrDef[ 'default' ] );
\r
94 case ATTRTYPE_EMBED:
\r
97 if ( embedNode.getAttribute( attrDef.name ) )
\r
99 value = embedNode.getAttribute( attrDef.name );
\r
101 this.setValue( value.toLowerCase() == 'true' );
\r
103 this.setValue( value );
\r
106 else if ( isCheckbox )
\r
107 this.setValue( !!attrDef[ 'default' ] );
\r
112 function commitValue( objectNode, embedNode, paramMap )
\r
114 var attributes = attributesMap[ this.id ];
\r
118 var isRemove = ( this.getValue() === '' ),
\r
119 isCheckbox = ( this instanceof CKEDITOR.ui.dialog.checkbox );
\r
121 for ( var i = 0 ; i < attributes.length ; i++ )
\r
123 var attrDef = attributes[i];
\r
124 switch ( attrDef.type )
\r
126 case ATTRTYPE_OBJECT:
\r
129 var value = this.getValue();
\r
130 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] )
\r
131 objectNode.removeAttribute( attrDef.name );
\r
133 objectNode.setAttribute( attrDef.name, value );
\r
135 case ATTRTYPE_PARAM:
\r
138 value = this.getValue();
\r
139 if ( isRemove || isCheckbox && value === attrDef[ 'default' ] )
\r
141 if ( attrDef.name in paramMap )
\r
142 paramMap[ attrDef.name ].remove();
\r
146 if ( attrDef.name in paramMap )
\r
147 paramMap[ attrDef.name ].setAttribute( 'value', value );
\r
150 var param = CKEDITOR.dom.element.createFromHtml( '<cke:param></cke:param>', objectNode.getDocument() );
\r
151 param.setAttributes( { name : attrDef.name, value : value } );
\r
152 if ( objectNode.getChildCount() < 1 )
\r
153 param.appendTo( objectNode );
\r
155 param.insertBefore( objectNode.getFirst() );
\r
159 case ATTRTYPE_EMBED:
\r
162 value = this.getValue();
\r
163 if ( isRemove || isCheckbox && value === attrDef[ 'default' ])
\r
164 embedNode.removeAttribute( attrDef.name );
\r
166 embedNode.setAttribute( attrDef.name, value );
\r
171 CKEDITOR.dialog.add( 'flash', function( editor )
\r
173 var makeObjectTag = !editor.config.flashEmbedTagOnly,
\r
174 makeEmbedTag = editor.config.flashAddEmbedTag || editor.config.flashEmbedTagOnly;
\r
176 var previewPreloader,
\r
177 previewAreaHtml = '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.common.preview ) +'<br>' +
\r
178 '<div id="cke_FlashPreviewLoader' + CKEDITOR.tools.getNextNumber() + '" style="display:none"><div class="loading"> </div></div>' +
\r
179 '<div id="cke_FlashPreviewBox' + CKEDITOR.tools.getNextNumber() + '" class="FlashPreviewBox"></div></div>';
\r
182 title : editor.lang.flash.title,
\r
185 onShow : function()
\r
187 // Clear previously saved elements.
\r
188 this.fakeImage = this.objectNode = this.embedNode = null;
\r
189 previewPreloader = new CKEDITOR.dom.element( 'embed', editor.document );
\r
191 // Try to detect any embed or object tag that has Flash parameters.
\r
192 var fakeImage = this.getSelectedElement();
\r
193 if ( fakeImage && fakeImage.data( 'cke-real-element-type' ) && fakeImage.data( 'cke-real-element-type' ) == 'flash' )
\r
195 this.fakeImage = fakeImage;
\r
197 var realElement = editor.restoreRealElement( fakeImage ),
\r
198 objectNode = null, embedNode = null, paramMap = {};
\r
199 if ( realElement.getName() == 'cke:object' )
\r
201 objectNode = realElement;
\r
202 var embedList = objectNode.getElementsByTag( 'embed', 'cke' );
\r
203 if ( embedList.count() > 0 )
\r
204 embedNode = embedList.getItem( 0 );
\r
205 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
\r
206 for ( var i = 0, length = paramList.count() ; i < length ; i++ )
\r
208 var item = paramList.getItem( i ),
\r
209 name = item.getAttribute( 'name' ),
\r
210 value = item.getAttribute( 'value' );
\r
211 paramMap[ name ] = value;
\r
214 else if ( realElement.getName() == 'cke:embed' )
\r
215 embedNode = realElement;
\r
217 this.objectNode = objectNode;
\r
218 this.embedNode = embedNode;
\r
220 this.setupContent( objectNode, embedNode, paramMap, fakeImage );
\r
225 // If there's no selected object or embed, create one. Otherwise, reuse the
\r
226 // selected object and embed nodes.
\r
227 var objectNode = null,
\r
230 if ( !this.fakeImage )
\r
232 if ( makeObjectTag )
\r
234 objectNode = CKEDITOR.dom.element.createFromHtml( '<cke:object></cke:object>', editor.document );
\r
236 classid : 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
\r
237 codebase : 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'
\r
239 objectNode.setAttributes( attributes );
\r
241 if ( makeEmbedTag )
\r
243 embedNode = CKEDITOR.dom.element.createFromHtml( '<cke:embed></cke:embed>', editor.document );
\r
244 embedNode.setAttributes(
\r
246 type : 'application/x-shockwave-flash',
\r
247 pluginspage : 'http://www.macromedia.com/go/getflashplayer'
\r
250 embedNode.appendTo( objectNode );
\r
255 objectNode = this.objectNode;
\r
256 embedNode = this.embedNode;
\r
259 // Produce the paramMap if there's an object tag.
\r
263 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
\r
264 for ( var i = 0, length = paramList.count() ; i < length ; i++ )
\r
265 paramMap[ paramList.getItem( i ).getAttribute( 'name' ) ] = paramList.getItem( i );
\r
268 // A subset of the specified attributes/styles
\r
269 // should also be applied on the fake element to
\r
270 // have better visual effect. (#5240)
\r
271 var extraStyles = {}, extraAttributes = {};
\r
272 this.commitContent( objectNode, embedNode, paramMap, extraStyles, extraAttributes );
\r
274 // Refresh the fake image.
\r
275 var newFakeImage = editor.createFakeElement( objectNode || embedNode, 'cke_flash', 'flash', true );
\r
276 newFakeImage.setAttributes( extraAttributes );
\r
277 newFakeImage.setStyles( extraStyles );
\r
278 if ( this.fakeImage )
\r
280 newFakeImage.replace( this.fakeImage );
\r
281 editor.getSelection().selectElement( newFakeImage );
\r
284 editor.insertElement( newFakeImage );
\r
287 onHide : function()
\r
289 if ( this.preview )
\r
290 this.preview.setHtml('');
\r
296 label : editor.lang.common.generalTab,
\r
307 widths : [ '280px', '110px' ],
\r
314 label : editor.lang.common.url,
\r
316 validate : CKEDITOR.dialog.validate.notEmpty( editor.lang.flash.validateSrc ),
\r
318 commit : commitValue,
\r
319 onLoad : function()
\r
321 var dialog = this.getDialog(),
\r
322 updatePreview = function( src ){
\r
323 // Query the preloader to figure out the url impacted by based href.
\r
324 previewPreloader.setAttribute( 'src', src );
\r
325 dialog.preview.setHtml( '<embed height="100%" width="100%" src="'
\r
326 + CKEDITOR.tools.htmlEncode( previewPreloader.getAttribute( 'src' ) )
\r
327 + '" type="application/x-shockwave-flash"></embed>' );
\r
330 dialog.preview = dialog.getContentElement( 'info', 'preview' ).getElement().getChild( 3 );
\r
332 // Sync on inital value loaded.
\r
333 this.on( 'change', function( evt ){
\r
335 if ( evt.data && evt.data.value )
\r
336 updatePreview( evt.data.value );
\r
338 // Sync when input value changed.
\r
339 this.getInputElement().on( 'change', function( evt ){
\r
341 updatePreview( this.getValue() );
\r
348 filebrowser : 'info:src',
\r
350 // v-align with the 'src' field.
\r
351 // TODO: We need something better than a fixed size here.
\r
352 style : 'display:inline-block;margin-top:10px;',
\r
353 label : editor.lang.common.browseServer
\r
361 widths : [ '25%', '25%', '25%', '25%', '25%' ],
\r
367 style : 'width:95px',
\r
368 label : editor.lang.common.width,
\r
369 validate : CKEDITOR.dialog.validate.integer( editor.lang.common.invalidWidth ),
\r
370 setup : function( objectNode, embedNode, paramMap, fakeImage )
\r
372 loadValue.apply( this, arguments );
\r
375 var fakeImageWidth = parseInt( fakeImage.$.style.width, 10 );
\r
376 if ( !isNaN( fakeImageWidth ) )
\r
377 this.setValue( fakeImageWidth );
\r
380 commit : function( objectNode, embedNode, paramMap, extraStyles )
\r
382 commitValue.apply( this, arguments );
\r
383 if ( this.getValue() )
\r
384 extraStyles.width = this.getValue() + 'px';
\r
390 style : 'width:95px',
\r
391 label : editor.lang.common.height,
\r
392 validate : CKEDITOR.dialog.validate.integer( editor.lang.common.invalidHeight ),
\r
393 setup : function( objectNode, embedNode, paramMap, fakeImage )
\r
395 loadValue.apply( this, arguments );
\r
398 var fakeImageHeight = parseInt( fakeImage.$.style.height, 10 );
\r
399 if ( !isNaN( fakeImageHeight ) )
\r
400 this.setValue( fakeImageHeight );
\r
403 commit : function( objectNode, embedNode, paramMap, extraStyles )
\r
405 commitValue.apply( this, arguments );
\r
406 if ( this.getValue() )
\r
407 extraStyles.height = this.getValue() + 'px';
\r
413 style : 'width:95px',
\r
414 label : editor.lang.flash.hSpace,
\r
415 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHSpace ),
\r
417 commit : commitValue
\r
422 style : 'width:95px',
\r
423 label : editor.lang.flash.vSpace,
\r
424 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateVSpace ),
\r
426 commit : commitValue
\r
438 style : 'width:95%;',
\r
439 html : previewAreaHtml
\r
448 filebrowser : 'uploadButton',
\r
449 label : editor.lang.common.upload,
\r
455 label : editor.lang.common.upload,
\r
459 type : 'fileButton',
\r
460 id : 'uploadButton',
\r
461 label : editor.lang.common.uploadSubmit,
\r
462 filebrowser : 'info:src',
\r
463 'for' : [ 'Upload', 'upload' ]
\r
469 label : editor.lang.flash.propertiesTab,
\r
474 widths : [ '50%', '50%' ],
\r
480 label : editor.lang.flash.scale,
\r
482 style : 'width : 100%;',
\r
485 [ editor.lang.common.notSet , ''],
\r
486 [ editor.lang.flash.scaleAll, 'showall' ],
\r
487 [ editor.lang.flash.scaleNoBorder, 'noborder' ],
\r
488 [ editor.lang.flash.scaleFit, 'exactfit' ]
\r
491 commit : commitValue
\r
494 id : 'allowScriptAccess',
\r
496 label : editor.lang.flash.access,
\r
498 style : 'width : 100%;',
\r
501 [ editor.lang.common.notSet , ''],
\r
502 [ editor.lang.flash.accessAlways, 'always' ],
\r
503 [ editor.lang.flash.accessSameDomain, 'samedomain' ],
\r
504 [ editor.lang.flash.accessNever, 'never' ]
\r
507 commit : commitValue
\r
513 widths : [ '50%', '50%' ],
\r
519 label : editor.lang.flash.windowMode,
\r
521 style : 'width : 100%;',
\r
524 [ editor.lang.common.notSet , '' ],
\r
525 [ editor.lang.flash.windowModeWindow, 'window' ],
\r
526 [ editor.lang.flash.windowModeOpaque, 'opaque' ],
\r
527 [ editor.lang.flash.windowModeTransparent, 'transparent' ]
\r
530 commit : commitValue
\r
535 label : editor.lang.flash.quality,
\r
536 'default' : 'high',
\r
537 style : 'width : 100%;',
\r
540 [ editor.lang.common.notSet , '' ],
\r
541 [ editor.lang.flash.qualityBest, 'best' ],
\r
542 [ editor.lang.flash.qualityHigh, 'high' ],
\r
543 [ editor.lang.flash.qualityAutoHigh, 'autohigh' ],
\r
544 [ editor.lang.flash.qualityMedium, 'medium' ],
\r
545 [ editor.lang.flash.qualityAutoLow, 'autolow' ],
\r
546 [ editor.lang.flash.qualityLow, 'low' ]
\r
549 commit : commitValue
\r
555 widths : [ '50%', '50%' ],
\r
561 label : editor.lang.common.align,
\r
563 style : 'width : 100%;',
\r
566 [ editor.lang.common.notSet , ''],
\r
567 [ editor.lang.common.alignLeft , 'left'],
\r
568 [ editor.lang.flash.alignAbsBottom , 'absBottom'],
\r
569 [ editor.lang.flash.alignAbsMiddle , 'absMiddle'],
\r
570 [ editor.lang.flash.alignBaseline , 'baseline'],
\r
571 [ editor.lang.common.alignBottom , 'bottom'],
\r
572 [ editor.lang.common.alignMiddle , 'middle'],
\r
573 [ editor.lang.common.alignRight , 'right'],
\r
574 [ editor.lang.flash.alignTextTop , 'textTop'],
\r
575 [ editor.lang.common.alignTop , 'top']
\r
578 commit : function( objectNode, embedNode, paramMap, extraStyles, extraAttributes )
\r
580 var value = this.getValue();
\r
581 commitValue.apply( this, arguments );
\r
582 value && ( extraAttributes.align = value );
\r
587 html : '<div></div>'
\r
593 label : CKEDITOR.tools.htmlEncode( editor.lang.flash.flashvars ),
\r
604 label : editor.lang.flash.chkMenu,
\r
607 commit : commitValue
\r
612 label : editor.lang.flash.chkPlay,
\r
615 commit : commitValue
\r
620 label : editor.lang.flash.chkLoop,
\r
623 commit : commitValue
\r
627 id : 'allowFullScreen',
\r
628 label : editor.lang.flash.chkFull,
\r
631 commit : commitValue
\r
641 label : editor.lang.common.advancedTab,
\r
646 widths : [ '45%', '55%' ],
\r
652 label : editor.lang.common.id,
\r
654 commit : commitValue
\r
659 label : editor.lang.common.advisoryTitle,
\r
661 commit : commitValue
\r
667 widths : [ '45%', '55%' ],
\r
673 label : editor.lang.flash.bgcolor,
\r
675 commit : commitValue
\r
680 label : editor.lang.common.cssClass,
\r
682 commit : commitValue
\r
689 label : editor.lang.common.cssStyle,
\r
691 commit : commitValue
\r