plugin.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * @file Audio plugin for CKEditor - fork from the Video plugin for CKEditor
  3. * Copyright (C) 2014 BeezNest Latino S.A.C
  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. // Translations, available at the end of this file, without extra requests
  25. lang: ['en', 'es'],
  26. getPlaceholderCss: function() {
  27. return 'img.cke_audio' +
  28. '{' +
  29. 'background-image: url(' + CKEDITOR.getUrl(this.path + 'images/placeholder.png') + ');' +
  30. 'background-position: center center;' +
  31. 'background-repeat: no-repeat;' +
  32. 'background-color:gray;' +
  33. 'border: 1px solid #a9a9a9;' +
  34. 'width: 80px;' +
  35. 'height: 40px;' +
  36. '}';
  37. },
  38. onLoad: function() {
  39. // v4
  40. if (CKEDITOR.addCss)
  41. CKEDITOR.addCss(this.getPlaceholderCss());
  42. },
  43. init: function(editor) {
  44. var lang = editor.lang.audio;
  45. // Check for CKEditor 3.5
  46. if (typeof editor.element.data == 'undefined') {
  47. alert('The "audio" plugin requires CKEditor 3.5 or newer');
  48. return;
  49. }
  50. CKEDITOR.dialog.add('audio', this.path + 'dialogs/audio.js');
  51. editor.addCommand('Audio', new CKEDITOR.dialogCommand('audio'));
  52. editor.ui.addButton('Audio', {
  53. label: lang.toolbar,
  54. command: 'Audio',
  55. icon: this.path + 'images/icon.png'
  56. });
  57. // v3
  58. if (editor.addCss) {
  59. editor.addCss(this.getPlaceholderCss());
  60. }
  61. // If the "menu" plugin is loaded, register the menu items.
  62. if (editor.addMenuItems) {
  63. editor.addMenuItems({
  64. audio: {
  65. label: lang.properties,
  66. command: 'Audio',
  67. group: 'flash'
  68. }
  69. });
  70. }
  71. editor.on('doubleclick', function(evt) {
  72. var element = evt.data.element;
  73. if (element.is('img') && element.data('cke-real-element-type') == 'audio') {
  74. evt.data.dialog = 'audio';
  75. }
  76. });
  77. // If the "contextmenu" plugin is loaded, register the listeners.
  78. if (editor.contextMenu) {
  79. editor.contextMenu.addListener(function(element, selection) {
  80. if (element && element.is('img') && !element.isReadOnly()
  81. && element.data('cke-real-element-type') == 'audio') {
  82. return {audio: CKEDITOR.TRISTATE_OFF};
  83. }
  84. });
  85. }
  86. // Add special handling for these items
  87. CKEDITOR.dtd.$empty['cke:source'] = 1;
  88. CKEDITOR.dtd.$empty['source'] = 1;
  89. editor.lang.fakeobjects.audio = lang.fakeObject;
  90. }, //Init
  91. afterInit: function(editor) {
  92. var dataProcessor = editor.dataProcessor,
  93. htmlFilter = dataProcessor && dataProcessor.htmlFilter,
  94. dataFilter = dataProcessor && dataProcessor.dataFilter;
  95. // dataFilter : conversion from html input to internal data
  96. dataFilter.addRules({
  97. elements: {
  98. $: function(realElement) {
  99. if (realElement.name == 'audio') {
  100. realElement.name = 'cke:audio';
  101. for (var i = 0; i < realElement.children.length; i++) {
  102. if (realElement.children[ i ].name == 'source') {
  103. realElement.children[ i ].name = 'cke:source';
  104. }
  105. }
  106. var fakeElement = editor.createFakeParserElement(realElement, 'cke_audio', 'audio', false),
  107. fakeStyle = fakeElement.attributes.style || '';
  108. var width = realElement.attributes.width;
  109. if (typeof width != 'undefined') {
  110. fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength(width) + ';';
  111. }
  112. return fakeElement;
  113. }
  114. }
  115. }
  116. });
  117. } // afterInit
  118. }); // plugins.add
  119. var en = {
  120. toolbar: 'Audio',
  121. dialogTitle: 'Audio properties',
  122. fakeObject: 'Audio',
  123. properties: 'Edit audio',
  124. widthRequired: 'Width field cannot be empty',
  125. heightRequired: 'Height field cannot be empty',
  126. sourceAudio: 'Source audio',
  127. sourceType: 'Audio type',
  128. linkTemplate: '<a href="%src%">%type%</a> ',
  129. fallbackTemplate: 'Your browser doesn\'t support audio.<br>Please download the file: %links%',
  130. autoPlay: 'Auto play'
  131. };
  132. var es = {
  133. toolbar: 'Audio',
  134. dialogTitle: 'Propiedades de audio',
  135. fakeObject: 'Audio',
  136. properties: 'Editar el audio',
  137. widthRequired: 'La anchura no se puede dejar en blanco',
  138. heightRequired: 'La altura no se puede dejar en blanco',
  139. sourceAudio: 'Archivo de audio',
  140. sourceType: 'Tipo',
  141. linkTemplate: '<a href="%src%">%type%</a> ',
  142. fallbackTemplate: 'Su navegador no soporta AUDIO.<br>Por favor, descargue el fichero: %links%',
  143. autoPlay: 'Reproducir automáticamente'
  144. };
  145. var fr = {
  146. toolbar: 'Audio',
  147. dialogTitle: 'Propriétés de l\'audio',
  148. fakeObject: 'Audio',
  149. properties: 'Editer l\'audio',
  150. widthRequired: 'La largeur ne peut être vide',
  151. heightRequired: 'La hauteur ne peut être vide',
  152. sourceAudio: 'Fichier audio',
  153. sourceType: 'Type',
  154. linkTemplate: '<a href="%src%">%type%</a> ',
  155. fallbackTemplate: 'Votre navigateur ne supporte pas l\'AUDIO.<br>Veuillez télécharger le fichier: %links%',
  156. autoPlay: 'Lecture automatique'
  157. };
  158. // v3
  159. if (CKEDITOR.skins) {
  160. en = {audio: en};
  161. es = {audio: es};
  162. }
  163. // Translations
  164. CKEDITOR.plugins.setLang('audio', 'en', en);
  165. CKEDITOR.plugins.setLang('audio', 'es', es);
  166. })();