JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / flash / plugin.js
diff --git a/_source/plugins/flash/plugin.js b/_source/plugins/flash/plugin.js
new file mode 100644 (file)
index 0000000..29117ba
--- /dev/null
@@ -0,0 +1,165 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+(function()\r
+{\r
+       var flashFilenameRegex = /\.swf(?:$|\?)/i,\r
+               numberRegex = /^\d+(?:\.\d+)?$/;\r
+\r
+       function cssifyLength( length )\r
+       {\r
+               if ( numberRegex.test( length ) )\r
+                       return length + 'px';\r
+               return length;\r
+       }\r
+\r
+       function isFlashEmbed( element )\r
+       {\r
+               var attributes = element.attributes;\r
+\r
+               return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) );\r
+       }\r
+\r
+       function createFakeElement( editor, realElement )\r
+       {\r
+               var fakeElement = editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true ),\r
+                       fakeStyle = fakeElement.attributes.style || '';\r
+\r
+               var width = realElement.attributes.width,\r
+                       height = realElement.attributes.height;\r
+\r
+               if ( typeof width != 'undefined' )\r
+                       fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + cssifyLength( width ) + ';';\r
+\r
+               if ( typeof height != 'undefined' )\r
+                       fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + cssifyLength( height ) + ';';\r
+\r
+               return fakeElement;\r
+       }\r
+\r
+       CKEDITOR.plugins.add( 'flash',\r
+       {\r
+               init : function( editor )\r
+               {\r
+                       editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash' ) );\r
+                       editor.ui.addButton( 'Flash',\r
+                               {\r
+                                       label : editor.lang.common.flash,\r
+                                       command : 'flash'\r
+                               });\r
+                       CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );\r
+\r
+                       editor.addCss(\r
+                               'img.cke_flash' +\r
+                               '{' +\r
+                                       'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +\r
+                                       'background-position: center center;' +\r
+                                       'background-repeat: no-repeat;' +\r
+                                       'border: 1px solid #a9a9a9;' +\r
+                                       'width: 80px;' +\r
+                                       'height: 80px;' +\r
+                               '}'\r
+                               );\r
+\r
+                       // If the "menu" plugin is loaded, register the menu items.\r
+                       if ( editor.addMenuItems )\r
+                       {\r
+                               editor.addMenuItems(\r
+                                       {\r
+                                               flash :\r
+                                               {\r
+                                                       label : editor.lang.flash.properties,\r
+                                                       command : 'flash',\r
+                                                       group : 'flash'\r
+                                               }\r
+                                       });\r
+                       }\r
+\r
+                       // If the "contextmenu" plugin is loaded, register the listeners.\r
+                       if ( editor.contextMenu )\r
+                       {\r
+                               editor.contextMenu.addListener( function( element, selection )\r
+                                       {\r
+                                               if ( element && element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'flash' )\r
+                                                       return { flash : CKEDITOR.TRISTATE_OFF };\r
+                                       });\r
+                       }\r
+               },\r
+\r
+               afterInit : function( editor )\r
+               {\r
+                       var dataProcessor = editor.dataProcessor,\r
+                               dataFilter = dataProcessor && dataProcessor.dataFilter;\r
+\r
+                       if ( dataFilter )\r
+                       {\r
+                               dataFilter.addRules(\r
+                                       {\r
+                                               elements :\r
+                                               {\r
+                                                       'cke:object' : function( element )\r
+                                                       {\r
+                                                               var attributes = element.attributes,\r
+                                                                       classId = attributes.classid && String( attributes.classid ).toLowerCase();\r
+\r
+                                                               if ( !classId )\r
+                                                               {\r
+                                                                       // Look for the inner <embed>\r
+                                                                       for ( var i = 0 ; i < element.children.length ; i++ )\r
+                                                                       {\r
+                                                                               if ( element.children[ i ].name == 'embed' )\r
+                                                                               {\r
+                                                                                       if ( !isFlashEmbed( element.children[ i ] ) )\r
+                                                                                               return null;\r
+\r
+                                                                                       return createFakeElement( editor, element );\r
+                                                                               }\r
+                                                                       }\r
+                                                                       return null;\r
+                                                               }\r
+\r
+                                                               return createFakeElement( editor, element );\r
+                                                       },\r
+\r
+                                                       'cke:embed' : function( element )\r
+                                                       {\r
+                                                               if ( !isFlashEmbed( element ) )\r
+                                                                       return null;\r
+\r
+                                                               return createFakeElement( editor, element );\r
+                                                       }\r
+                                               }\r
+                                       },\r
+                                       5);\r
+                       }\r
+               },\r
+\r
+               requires : [ 'fakeobjects' ]\r
+       });\r
+})();\r
+\r
+CKEDITOR.tools.extend( CKEDITOR.config,\r
+{\r
+       /**\r
+        * Save as EMBED tag only. This tag is unrecommended.\r
+        * @type Boolean\r
+        * @default false\r
+        */\r
+       flashEmbedTagOnly : false,\r
+\r
+       /**\r
+        * Add EMBED tag as alternative: &lt;object&gt&lt;embed&gt&lt;/embed&gt&lt;/object&gt\r
+        * @type Boolean\r
+        * @default false\r
+        */\r
+       flashAddEmbedTag : true,\r
+\r
+       /**\r
+        * Use embedTagOnly and addEmbedTag values on edit.\r
+        * @type Boolean\r
+        * @default false\r
+        */\r
+       flashConvertOnEdit : false\r
+} );\r