--- /dev/null
+/*\r
+ * @file audio plugin for CKEditor\r
+ * Copyright (C) 2011 Alfonso Martínez de Lizarrondo\r
+ *\r
+ * == BEGIN LICENSE ==\r
+ *\r
+ * Licensed under the terms of any of the following licenses at your\r
+ * choice:\r
+ *\r
+ * - GNU General Public License Version 2 or later (the "GPL")\r
+ * http://www.gnu.org/licenses/gpl.html\r
+ *\r
+ * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
+ * http://www.gnu.org/licenses/lgpl.html\r
+ *\r
+ * - Mozilla Public License Version 1.1 or later (the "MPL")\r
+ * http://www.mozilla.org/MPL/MPL-1.1.html\r
+ *\r
+ * == END LICENSE ==\r
+ *\r
+ */\r
+\r
+( function() {\r
+\r
+CKEDITOR.plugins.add( 'Audio',\r
+{\r
+ // Translations, available at the end of this file, without extra requests\r
+ lang : [ 'en', 'es' ],\r
+\r
+ getPlaceholderCss : function()\r
+ {\r
+ return 'img.cke_audio' +\r
+ '{' +\r
+ 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +\r
+ 'background-position: center center;' +\r
+ 'background-repeat: no-repeat;' +\r
+ 'background-color:gray;'+\r
+ 'border: 1px solid #a9a9a9;' +\r
+ 'width: 80px;' +\r
+ 'height: 80px;' +\r
+ '}';\r
+ },\r
+\r
+ onLoad : function()\r
+ {\r
+ // v4\r
+ if (CKEDITOR.addCss)\r
+ CKEDITOR.addCss( this.getPlaceholderCss() );\r
+\r
+ },\r
+\r
+ init : function( editor )\r
+ {\r
+ var lang = editor.lang.audio;\r
+\r
+ // Check for CKEditor 3.5\r
+ if (typeof editor.element.data == 'undefined')\r
+ {\r
+ alert('The "audio" plugin requires CKEditor 3.5 or newer');\r
+ return;\r
+ }\r
+\r
+ CKEDITOR.dialog.add( 'audio', this.path + 'dialogs/audio.js' );\r
+\r
+ editor.addCommand( 'Audio', new CKEDITOR.dialogCommand( 'audio' ) );\r
+ editor.ui.addButton( 'Audio',\r
+ {\r
+ label : lang.toolbar,\r
+ command : 'Audio',\r
+ icon : this.path + 'images/icon.png'\r
+ } );\r
+\r
+ // v3\r
+ if (editor.addCss)\r
+ editor.addCss( this.getPlaceholderCss() );\r
+\r
+\r
+ // If the "menu" plugin is loaded, register the menu items.\r
+ if ( editor.addMenuItems )\r
+ {\r
+ editor.addMenuItems(\r
+ {\r
+ audio :\r
+ {\r
+ label : lang.properties,\r
+ command : 'Audio',\r
+ group : 'flash'\r
+ }\r
+ });\r
+ }\r
+\r
+ editor.on( 'doubleclick', function( evt )\r
+ {\r
+ var element = evt.data.element;\r
+\r
+ if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'audio' )\r
+ evt.data.dialog = 'audio';\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.isReadOnly()\r
+ && element.data( 'cke-real-element-type' ) == 'audio' )\r
+ return { audio : CKEDITOR.TRISTATE_OFF };\r
+ });\r
+ }\r
+\r
+ // Add special handling for these items\r
+ CKEDITOR.dtd.$empty['cke:source']=1;\r
+ CKEDITOR.dtd.$empty['source']=1;\r
+\r
+ editor.lang.fakeobjects.audio = lang.fakeObject;\r
+\r
+\r
+ }, //Init\r
+\r
+ afterInit: function( editor )\r
+ {\r
+ var dataProcessor = editor.dataProcessor,\r
+ htmlFilter = dataProcessor && dataProcessor.htmlFilter,\r
+ dataFilter = dataProcessor && dataProcessor.dataFilter;\r
+\r
+ // dataFilter : conversion from html input to internal data\r
+ dataFilter.addRules(\r
+ {\r
+\r
+ elements : {\r
+ $ : function( realElement )\r
+ {\r
+ if ( realElement.name == 'audio' )\r
+ {\r
+ realElement.name = 'cke:audio';\r
+ for( var i=0; i < realElement.children.length; i++)\r
+ {\r
+ if ( realElement.children[ i ].name == 'source' )\r
+ realElement.children[ i ].name = 'cke:source'\r
+ }\r
+\r
+ var fakeElement = editor.createFakeParserElement( realElement, 'cke_audio', 'audio', false ),\r
+ fakeStyle = fakeElement.attributes.style || '';\r
+\r
+ var width = realElement.attributes.width,\r
+ height = realElement.attributes.height,\r
+ poster = realElement.attributes.poster;\r
+\r
+ if ( typeof width != 'undefined' )\r
+ fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength( width ) + ';';\r
+\r
+ if ( typeof height != 'undefined' )\r
+ fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + CKEDITOR.tools.cssLength( height ) + ';';\r
+\r
+ if ( poster )\r
+ fakeStyle = fakeElement.attributes.style = fakeStyle + 'background-image:url(' + poster + ');';\r
+\r
+ return fakeElement;\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+ );\r
+\r
+ } // afterInit\r
+\r
+} ); // plugins.add\r
+\r
+\r
+var en = {\r
+ toolbar : 'Audio',\r
+ dialogTitle : 'Audio properties',\r
+ fakeObject : 'Audio',\r
+ properties : 'Edit audio',\r
+ widthRequired : 'Width field cannot be empty',\r
+ heightRequired : 'Height field cannot be empty',\r
+ poster: 'Poster image',\r
+ sourceaudio: 'Source audio',\r
+ sourceType : 'Audio type',\r
+ linkTemplate : '<a href="%src%">%type%</a> ',\r
+ fallbackTemplate : 'Your browser doesn\'t support audio.<br>Please download the file: %links%'\r
+ };\r
+\r
+var es = {\r
+ toolbar : 'Audio',\r
+ dialogTitle : 'Propiedades de audio',\r
+ fakeObject : 'Audio',\r
+ properties : 'Editar el audio',\r
+ widthRequired : 'La anchura no se puede dejar en blanco',\r
+ heightRequired : 'La altura no se puede dejar en blanco',\r
+ poster: 'Imagen de presentación',\r
+ sourceaudio: 'Archivo de audio',\r
+ sourceType : 'Tipo',\r
+ linkTemplate : '<a href="%src%">%type%</a> ',\r
+ fallbackTemplate : 'Su navegador no soporta audio.<br>Por favor, descargue el fichero: %links%'\r
+ };\r
+\r
+ // v3\r
+ if (CKEDITOR.skins)\r
+ {\r
+ en = { audio : en} ;\r
+ es = { audio : es} ;\r
+ }\r
+\r
+// Translations\r
+CKEDITOR.plugins.setLang( 'audio', 'en', en );\r
+\r
+CKEDITOR.plugins.setLang( 'audio', 'es', es );\r
+\r
+})();\r