plugin.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * @file audio plugin for CKEditor
  3. * Copyright (C) 2011 Alfonso Martínez de Lizarrondo
  4. *
  5. * == BEGIN LICENSE ==
  6. *
  7. * Licensed under the terms of any of the following licenses at your
  8. * choice:
  9. *
  10. * - GNU General Public License Version 2 or later (the "GPL")
  11. * http://www.gnu.org/licenses/gpl.html
  12. *
  13. * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14. * http://www.gnu.org/licenses/lgpl.html
  15. *
  16. * - Mozilla Public License Version 1.1 or later (the "MPL")
  17. * http://www.mozilla.org/MPL/MPL-1.1.html
  18. *
  19. * == END LICENSE ==
  20. *
  21. */
  22. ( function() {
  23. CKEDITOR.plugins.add( 'audio',
  24. {
  25. // Translations, available at the end of this file, without extra requests
  26. lang : [ 'en', 'es' ],
  27. getPlaceholderCss : function()
  28. {
  29. return 'img.cke_audio' +
  30. '{' +
  31. 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
  32. 'background-position: center center;' +
  33. 'background-repeat: no-repeat;' +
  34. 'background-color:gray;'+
  35. 'border: 1px solid #a9a9a9;' +
  36. 'width: 80px;' +
  37. 'height: 80px;' +
  38. '}';
  39. },
  40. onLoad : function()
  41. {
  42. // v4
  43. if (CKEDITOR.addCss)
  44. CKEDITOR.addCss( this.getPlaceholderCss() );
  45. },
  46. init : function( editor )
  47. {
  48. var lang = editor.lang.audio;
  49. // Check for CKEditor 3.5
  50. if (typeof editor.element.data == 'undefined')
  51. {
  52. alert('The "audio" plugin requires CKEditor 3.5 or newer');
  53. return;
  54. }
  55. CKEDITOR.dialog.add( 'audio', this.path + 'dialogs/audio.js' );
  56. editor.addCommand( 'audio', new CKEDITOR.dialogCommand( 'audio' ) );
  57. editor.ui.addButton( 'audio',
  58. {
  59. label : 'Вставить аудио',
  60. command : 'audio',
  61. icon : this.path + 'images/icon.png',
  62. toolbar: 'insert,4'
  63. } );
  64. // v3
  65. if (editor.addCss)
  66. editor.addCss( this.getPlaceholderCss() );
  67. // If the "menu" plugin is loaded, register the menu items.
  68. if ( editor.addMenuItems )
  69. {
  70. editor.addMenuItems(
  71. {
  72. audio :
  73. {
  74. label : lang.properties,
  75. command : 'audio',
  76. group : 'flash'
  77. }
  78. });
  79. }
  80. editor.on( 'doubleclick', function( evt )
  81. {
  82. var element = evt.data.element;
  83. if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'audio' )
  84. evt.data.dialog = 'audio';
  85. });
  86. // If the "contextmenu" plugin is loaded, register the listeners.
  87. if ( editor.contextMenu )
  88. {
  89. editor.contextMenu.addListener( function( element, selection )
  90. {
  91. if ( element && element.is( 'img' ) && !element.isReadOnly()
  92. && element.data( 'cke-real-element-type' ) == 'audio' )
  93. return { audio : CKEDITOR.TRISTATE_OFF };
  94. });
  95. }
  96. // Add special handling for these items
  97. CKEDITOR.dtd.$empty['cke:source']=1;
  98. CKEDITOR.dtd.$empty['source']=1;
  99. editor.lang.fakeobjects.audio = lang.fakeObject;
  100. }, //Init
  101. afterInit: function( editor )
  102. {
  103. var dataProcessor = editor.dataProcessor,
  104. htmlFilter = dataProcessor && dataProcessor.htmlFilter,
  105. dataFilter = dataProcessor && dataProcessor.dataFilter;
  106. // dataFilter : conversion from html input to internal data
  107. dataFilter.addRules(
  108. {
  109. elements : {
  110. $ : function( realElement )
  111. {
  112. if ( realElement.name == 'audio' )
  113. {
  114. realElement.name = 'cke:audio';
  115. for( var i=0; i < realElement.children.length; i++)
  116. {
  117. if ( realElement.children[ i ].name == 'source' )
  118. realElement.children[ i ].name = 'cke:source'
  119. }
  120. var fakeElement = editor.createFakeParserElement( realElement, 'cke_audio', 'audio', false ),
  121. fakeStyle = fakeElement.attributes.style || '';
  122. var width = realElement.attributes.width,
  123. height = realElement.attributes.height,
  124. poster = realElement.attributes.poster;
  125. if ( typeof width != 'undefined' )
  126. fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength( width ) + ';';
  127. if ( typeof height != 'undefined' )
  128. fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + CKEDITOR.tools.cssLength( height ) + ';';
  129. if ( poster )
  130. fakeStyle = fakeElement.attributes.style = fakeStyle + 'background-image:url(' + poster + ');';
  131. return fakeElement;
  132. }
  133. }
  134. }
  135. }
  136. );
  137. } // afterInit
  138. } ); // plugins.add
  139. var en = {
  140. toolbar : 'Audio',
  141. dialogTitle : 'Audio properties',
  142. fakeObject : 'Audio',
  143. properties : 'Edit audio',
  144. widthRequired : 'Width field cannot be empty',
  145. heightRequired : 'Height field cannot be empty',
  146. poster: 'Poster image',
  147. sourceaudio: 'Source audio',
  148. sourceType : 'Audio type',
  149. linkTemplate : '<a href="%src%">%type%</a> ',
  150. fallbackTemplate : 'Your browser doesn\'t support audio.<br>Please download the file: %links%'
  151. };
  152. var es = {
  153. toolbar : 'Audio',
  154. dialogTitle : 'Propiedades de audio',
  155. fakeObject : 'Audio',
  156. properties : 'Editar el audio',
  157. widthRequired : 'La anchura no se puede dejar en blanco',
  158. heightRequired : 'La altura no se puede dejar en blanco',
  159. poster: 'Imagen de presentación',
  160. sourceaudio: 'Archivo de audio',
  161. sourceType : 'Tipo',
  162. linkTemplate : '<a href="%src%">%type%</a> ',
  163. fallbackTemplate : 'Su navegador no soporta audio.<br>Por favor, descargue el fichero: %links%'
  164. };
  165. // v3
  166. if (CKEDITOR.skins)
  167. {
  168. en = { audio : en} ;
  169. es = { audio : es} ;
  170. }
  171. // Translations
  172. CKEDITOR.plugins.setLang( 'audio', 'en', en );
  173. CKEDITOR.plugins.setLang( 'audio', 'es', es );
  174. })();