[3019] | 1 | /*
|
---|
| 2 | Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
|
---|
| 3 | For licensing, see LICENSE.html or http://ckeditor.com/license
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | (function()
|
---|
| 7 | {
|
---|
| 8 | var flashFilenameRegex = /\.swf(?:$|\?)/i,
|
---|
| 9 | numberRegex = /^\d+(?:\.\d+)?$/;
|
---|
| 10 |
|
---|
| 11 | function cssifyLength( length )
|
---|
| 12 | {
|
---|
| 13 | if ( numberRegex.test( length ) )
|
---|
| 14 | return length + 'px';
|
---|
| 15 | return length;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | function isFlashEmbed( element )
|
---|
| 19 | {
|
---|
| 20 | var attributes = element.attributes;
|
---|
| 21 |
|
---|
| 22 | return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) );
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | function createFakeElement( editor, realElement )
|
---|
| 26 | {
|
---|
| 27 | var fakeElement = editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true ),
|
---|
| 28 | fakeStyle = fakeElement.attributes.style || '';
|
---|
| 29 |
|
---|
| 30 | var width = realElement.attributes.width,
|
---|
| 31 | height = realElement.attributes.height;
|
---|
| 32 |
|
---|
| 33 | if ( typeof width != 'undefined' )
|
---|
| 34 | fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + cssifyLength( width ) + ';';
|
---|
| 35 |
|
---|
| 36 | if ( typeof height != 'undefined' )
|
---|
| 37 | fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + cssifyLength( height ) + ';';
|
---|
| 38 |
|
---|
| 39 | return fakeElement;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | CKEDITOR.plugins.add( 'flash',
|
---|
| 43 | {
|
---|
| 44 | init : function( editor )
|
---|
| 45 | {
|
---|
| 46 | editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash' ) );
|
---|
| 47 | editor.ui.addButton( 'Flash',
|
---|
| 48 | {
|
---|
| 49 | label : editor.lang.common.flash,
|
---|
| 50 | command : 'flash'
|
---|
| 51 | });
|
---|
| 52 | CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );
|
---|
| 53 |
|
---|
| 54 | editor.addCss(
|
---|
| 55 | 'img.cke_flash' +
|
---|
| 56 | '{' +
|
---|
| 57 | 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
|
---|
| 58 | 'background-position: center center;' +
|
---|
| 59 | 'background-repeat: no-repeat;' +
|
---|
| 60 | 'border: 1px solid #a9a9a9;' +
|
---|
| 61 | 'width: 80px;' +
|
---|
| 62 | 'height: 80px;' +
|
---|
| 63 | '}'
|
---|
| 64 | );
|
---|
| 65 |
|
---|
| 66 | // If the "menu" plugin is loaded, register the menu items.
|
---|
| 67 | if ( editor.addMenuItems )
|
---|
| 68 | {
|
---|
| 69 | editor.addMenuItems(
|
---|
| 70 | {
|
---|
| 71 | flash :
|
---|
| 72 | {
|
---|
| 73 | label : editor.lang.flash.properties,
|
---|
| 74 | command : 'flash',
|
---|
| 75 | group : 'flash'
|
---|
| 76 | }
|
---|
| 77 | });
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | // If the "contextmenu" plugin is loaded, register the listeners.
|
---|
| 81 | if ( editor.contextMenu )
|
---|
| 82 | {
|
---|
| 83 | editor.contextMenu.addListener( function( element, selection )
|
---|
| 84 | {
|
---|
| 85 | if ( element && element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'flash' )
|
---|
| 86 | return { flash : CKEDITOR.TRISTATE_OFF };
|
---|
| 87 | });
|
---|
| 88 | }
|
---|
| 89 | },
|
---|
| 90 |
|
---|
| 91 | afterInit : function( editor )
|
---|
| 92 | {
|
---|
| 93 | var dataProcessor = editor.dataProcessor,
|
---|
| 94 | dataFilter = dataProcessor && dataProcessor.dataFilter;
|
---|
| 95 |
|
---|
| 96 | if ( dataFilter )
|
---|
| 97 | {
|
---|
| 98 | dataFilter.addRules(
|
---|
| 99 | {
|
---|
| 100 | elements :
|
---|
| 101 | {
|
---|
| 102 | 'cke:object' : function( element )
|
---|
| 103 | {
|
---|
| 104 | var attributes = element.attributes,
|
---|
| 105 | classId = attributes.classid && String( attributes.classid ).toLowerCase();
|
---|
| 106 |
|
---|
| 107 | if ( !classId )
|
---|
| 108 | {
|
---|
| 109 | // Look for the inner <embed>
|
---|
| 110 | for ( var i = 0 ; i < element.children.length ; i++ )
|
---|
| 111 | {
|
---|
| 112 | if ( element.children[ i ].name == 'embed' )
|
---|
| 113 | {
|
---|
| 114 | if ( !isFlashEmbed( element.children[ i ] ) )
|
---|
| 115 | return null;
|
---|
| 116 |
|
---|
| 117 | return createFakeElement( editor, element );
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | return null;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | return createFakeElement( editor, element );
|
---|
| 124 | },
|
---|
| 125 |
|
---|
| 126 | 'cke:embed' : function( element )
|
---|
| 127 | {
|
---|
| 128 | if ( !isFlashEmbed( element ) )
|
---|
| 129 | return null;
|
---|
| 130 |
|
---|
| 131 | return createFakeElement( editor, element );
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | },
|
---|
| 135 | 5);
|
---|
| 136 | }
|
---|
| 137 | },
|
---|
| 138 |
|
---|
| 139 | requires : [ 'fakeobjects' ]
|
---|
| 140 | });
|
---|
| 141 | })();
|
---|
| 142 |
|
---|
| 143 | CKEDITOR.tools.extend( CKEDITOR.config,
|
---|
| 144 | {
|
---|
| 145 | /**
|
---|
| 146 | * Save as EMBED tag only. This tag is unrecommended.
|
---|
| 147 | * @type Boolean
|
---|
| 148 | * @default false
|
---|
| 149 | */
|
---|
| 150 | flashEmbedTagOnly : false,
|
---|
| 151 |
|
---|
| 152 | /**
|
---|
| 153 | * Add EMBED tag as alternative: <object><embed></embed></object>
|
---|
| 154 | * @type Boolean
|
---|
| 155 | * @default false
|
---|
| 156 | */
|
---|
| 157 | flashAddEmbedTag : true,
|
---|
| 158 |
|
---|
| 159 | /**
|
---|
| 160 | * Use embedTagOnly and addEmbedTag values on edit.
|
---|
| 161 | * @type Boolean
|
---|
| 162 | * @default false
|
---|
| 163 | */
|
---|
| 164 | flashConvertOnEdit : false
|
---|
| 165 | } );
|
---|