2 Copyright (c) 2003-2009, 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' } ],
\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 previewAreaHtml = '<div>' + CKEDITOR.tools.htmlEncode( editor.lang.image.preview ) +'<br>' +
\r
177 '<div id="FlashPreviewLoader" style="display:none"><div class="loading"> </div></div>' +
\r
178 '<div id="FlashPreviewBox"></div></div>';
\r
181 title : editor.lang.flash.title,
\r
184 onShow : function()
\r
186 // Clear previously saved elements.
\r
187 this.fakeImage = this.objectNode = this.embedNode = null;
\r
189 // Try to detect any embed or object tag that has Flash parameters.
\r
190 var fakeImage = this.getSelectedElement();
\r
191 if ( fakeImage && fakeImage.getAttribute( '_cke_real_element_type' ) && fakeImage.getAttribute( '_cke_real_element_type' ) == 'flash' )
\r
193 this.fakeImage = fakeImage;
\r
195 var realElement = editor.restoreRealElement( fakeImage ),
\r
196 objectNode = null, embedNode = null, paramMap = {};
\r
197 if ( realElement.getName() == 'cke:object' )
\r
199 objectNode = realElement;
\r
200 var embedList = objectNode.getElementsByTag( 'embed', 'cke' );
\r
201 if ( embedList.count() > 0 )
\r
202 embedNode = embedList.getItem( 0 );
\r
203 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
\r
204 for ( var i = 0, length = paramList.count() ; i < length ; i++ )
\r
206 var item = paramList.getItem( i ),
\r
207 name = item.getAttribute( 'name' ),
\r
208 value = item.getAttribute( 'value' );
\r
209 paramMap[ name ] = value;
\r
212 else if ( realElement.getName() == 'cke:embed' )
\r
213 embedNode = realElement;
\r
215 this.objectNode = objectNode;
\r
216 this.embedNode = embedNode;
\r
218 this.setupContent( objectNode, embedNode, paramMap, fakeImage );
\r
223 // If there's no selected object or embed, create one. Otherwise, reuse the
\r
224 // selected object and embed nodes.
\r
225 var objectNode = null,
\r
228 if ( !this.fakeImage )
\r
230 if ( makeObjectTag )
\r
232 objectNode = CKEDITOR.dom.element.createFromHtml( '<cke:object></cke:object>', editor.document );
\r
234 classid : 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
\r
235 codebase : 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0'
\r
237 objectNode.setAttributes( attributes );
\r
239 if ( makeEmbedTag )
\r
241 embedNode = CKEDITOR.dom.element.createFromHtml( '<cke:embed></cke:embed>', editor.document );
\r
242 embedNode.setAttributes(
\r
244 type : 'application/x-shockwave-flash',
\r
245 pluginspage : 'http://www.macromedia.com/go/getflashplayer'
\r
248 embedNode.appendTo( objectNode );
\r
253 objectNode = this.objectNode;
\r
254 embedNode = this.embedNode;
\r
257 // Produce the paramMap if there's an object tag.
\r
261 var paramList = objectNode.getElementsByTag( 'param', 'cke' );
\r
262 for ( var i = 0, length = paramList.count() ; i < length ; i++ )
\r
263 paramMap[ paramList.getItem( i ).getAttribute( 'name' ) ] = paramList.getItem( i );
\r
266 // Apply or remove flash parameters.
\r
267 var extraStyles = {};
\r
268 this.commitContent( objectNode, embedNode, paramMap, extraStyles );
\r
270 // Refresh the fake image.
\r
271 var newFakeImage = editor.createFakeElement( objectNode || embedNode, 'cke_flash', 'flash', true );
\r
272 newFakeImage.setStyles( extraStyles );
\r
273 if ( this.fakeImage )
\r
275 newFakeImage.replace( this.fakeImage );
\r
276 editor.getSelection().selectElement( newFakeImage );
\r
279 editor.insertElement( newFakeImage );
\r
282 onHide : function()
\r
284 if ( this.preview )
\r
285 this.preview.setHtml('');
\r
291 label : editor.lang.common.generalTab,
\r
302 html : '<span>' + CKEDITOR.tools.htmlEncode( editor.lang.image.url ) + '</span>'
\r
306 widths : [ '280px', '110px' ],
\r
314 validate : CKEDITOR.dialog.validate.notEmpty( editor.lang.flash.validateSrc ),
\r
316 commit : commitValue,
\r
317 onLoad : function()
\r
319 var dialog = this.getDialog(),
\r
320 updatePreview = function( src ){
\r
322 dialog.preview.setHtml( '<embed height="100%" width="100%" src="'
\r
323 + CKEDITOR.tools.htmlEncode( src )
\r
324 + '" type="application/x-shockwave-flash"></embed>' );
\r
327 dialog.preview = dialog.getContentElement( 'info', 'preview' ).getElement().getChild( 3 );
\r
329 // Sync on inital value loaded.
\r
330 this.on( 'change', function( evt ){
\r
332 if ( evt.data && evt.data.value )
\r
333 updatePreview( evt.data.value );
\r
335 // Sync when input value changed.
\r
336 this.getInputElement().on( 'change', function( evt ){
\r
338 updatePreview( this.getValue() );
\r
345 filebrowser : 'info:src',
\r
348 label : editor.lang.common.browseServer
\r
356 widths : [ '25%', '25%', '25%', '25%', '25%' ],
\r
362 style : 'width:95px',
\r
363 label : editor.lang.flash.width,
\r
364 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateWidth ),
\r
365 setup : function( objectNode, embedNode, paramMap, fakeImage )
\r
367 loadValue.apply( this, arguments );
\r
370 var fakeImageWidth = parseInt( fakeImage.$.style.width, 10 );
\r
371 if ( !isNaN( fakeImageWidth ) )
\r
372 this.setValue( fakeImageWidth );
\r
375 commit : function( objectNode, embedNode, paramMap, extraStyles )
\r
377 commitValue.apply( this, arguments );
\r
378 if ( this.getValue() )
\r
379 extraStyles.width = this.getValue() + 'px';
\r
385 style : 'width:95px',
\r
386 label : editor.lang.flash.height,
\r
387 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHeight ),
\r
388 setup : function( objectNode, embedNode, paramMap, fakeImage )
\r
390 loadValue.apply( this, arguments );
\r
393 var fakeImageHeight = parseInt( fakeImage.$.style.height, 10 );
\r
394 if ( !isNaN( fakeImageHeight ) )
\r
395 this.setValue( fakeImageHeight );
\r
398 commit : function( objectNode, embedNode, paramMap, extraStyles )
\r
400 commitValue.apply( this, arguments );
\r
401 if ( this.getValue() )
\r
402 extraStyles.height = this.getValue() + 'px';
\r
408 style : 'width:95px',
\r
409 label : editor.lang.flash.hSpace,
\r
410 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateHSpace ),
\r
412 commit : commitValue
\r
417 style : 'width:95px',
\r
418 label : editor.lang.flash.vSpace,
\r
419 validate : CKEDITOR.dialog.validate.integer( editor.lang.flash.validateVSpace ),
\r
421 commit : commitValue
\r
433 style : 'width:95%;',
\r
434 html : previewAreaHtml
\r
443 filebrowser : 'uploadButton',
\r
444 label : editor.lang.common.upload,
\r
450 label : editor.lang.common.upload,
\r
454 type : 'fileButton',
\r
455 id : 'uploadButton',
\r
456 label : editor.lang.common.uploadSubmit,
\r
457 filebrowser : 'info:src',
\r
458 'for' : [ 'Upload', 'upload' ]
\r
464 label : editor.lang.flash.propertiesTab,
\r
469 widths : [ '50%', '50%' ],
\r
475 label : editor.lang.flash.scale,
\r
477 style : 'width : 100%;',
\r
480 [ editor.lang.common.notSet , ''],
\r
481 [ editor.lang.flash.scaleAll, 'showall' ],
\r
482 [ editor.lang.flash.scaleNoBorder, 'noborder' ],
\r
483 [ editor.lang.flash.scaleFit, 'exactfit' ]
\r
486 commit : commitValue
\r
489 id : 'allowScriptAccess',
\r
491 label : editor.lang.flash.access,
\r
493 style : 'width : 100%;',
\r
496 [ editor.lang.common.notSet , ''],
\r
497 [ editor.lang.flash.accessAlways, 'always' ],
\r
498 [ editor.lang.flash.accessSameDomain, 'samedomain' ],
\r
499 [ editor.lang.flash.accessNever, 'never' ]
\r
502 commit : commitValue
\r
508 widths : [ '50%', '50%' ],
\r
514 label : editor.lang.flash.windowMode,
\r
516 style : 'width : 100%;',
\r
519 [ editor.lang.common.notSet , '' ],
\r
520 [ editor.lang.flash.windowModeWindow, 'window' ],
\r
521 [ editor.lang.flash.windowModeOpaque, 'opaque' ],
\r
522 [ editor.lang.flash.windowModeTransparent, 'transparent' ]
\r
525 commit : commitValue
\r
530 label : editor.lang.flash.quality,
\r
531 'default' : 'high',
\r
532 style : 'width : 100%;',
\r
535 [ editor.lang.common.notSet , '' ],
\r
536 [ editor.lang.flash.qualityBest, 'best' ],
\r
537 [ editor.lang.flash.qualityHigh, 'high' ],
\r
538 [ editor.lang.flash.qualityAutoHigh, 'autohigh' ],
\r
539 [ editor.lang.flash.qualityMedium, 'medium' ],
\r
540 [ editor.lang.flash.qualityAutoLow, 'autolow' ],
\r
541 [ editor.lang.flash.qualityLow, 'low' ]
\r
544 commit : commitValue
\r
550 widths : [ '50%', '50%' ],
\r
556 label : editor.lang.flash.align,
\r
558 style : 'width : 100%;',
\r
561 [ editor.lang.common.notSet , ''],
\r
562 [ editor.lang.image.alignLeft , 'left'],
\r
563 [ editor.lang.image.alignAbsBottom , 'absBottom'],
\r
564 [ editor.lang.image.alignAbsMiddle , 'absMiddle'],
\r
565 [ editor.lang.image.alignBaseline , 'baseline'],
\r
566 [ editor.lang.image.alignBottom , 'bottom'],
\r
567 [ editor.lang.image.alignMiddle , 'middle'],
\r
568 [ editor.lang.image.alignRight , 'right'],
\r
569 [ editor.lang.image.alignTextTop , 'textTop'],
\r
570 [ editor.lang.image.alignTop , 'top']
\r
573 commit : commitValue
\r
577 html : '<div></div>'
\r
588 html : CKEDITOR.tools.htmlEncode( editor.lang.flash.flashvars )
\r
593 label : editor.lang.flash.chkMenu,
\r
596 commit : commitValue
\r
601 label : editor.lang.flash.chkPlay,
\r
604 commit : commitValue
\r
609 label : editor.lang.flash.chkLoop,
\r
612 commit : commitValue
\r
616 id : 'allowFullScreen',
\r
617 label : editor.lang.flash.chkFull,
\r
620 commit : commitValue
\r
628 label : editor.lang.common.advancedTab,
\r
633 widths : [ '45%', '55%' ],
\r
639 label : editor.lang.common.id,
\r
641 commit : commitValue
\r
646 label : editor.lang.common.advisoryTitle,
\r
648 commit : commitValue
\r
654 widths : [ '45%', '55%' ],
\r
660 label : editor.lang.flash.bgcolor,
\r
662 commit : commitValue
\r
667 label : editor.lang.common.cssClass,
\r
669 commit : commitValue
\r
676 label : editor.lang.common.cssStyle,
\r
678 commit : commitValue
\r