plugin.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: 80px;' +
  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_video', 'audio', false),
  107. fakeStyle = fakeElement.attributes.style || '';
  108. var width = realElement.attributes.width,
  109. height = realElement.attributes.height;
  110. if (typeof width != 'undefined') {
  111. fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength(width) + ';';
  112. }
  113. if (typeof height != 'undefined') {
  114. fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + CKEDITOR.tools.cssLength(height) + ';';
  115. }
  116. return fakeElement;
  117. }
  118. }
  119. }
  120. });
  121. } // afterInit
  122. }); // plugins.add
  123. var en = {
  124. toolbar: 'Audio',
  125. dialogTitle: 'Audio properties',
  126. fakeObject: 'Audio',
  127. properties: 'Edit audio',
  128. widthRequired: 'Width field cannot be empty',
  129. heightRequired: 'Height field cannot be empty',
  130. sourceAudio: 'Source audio',
  131. sourceType: 'Audio type',
  132. linkTemplate: '<a href="%src%">%type%</a> ',
  133. fallbackTemplate: 'Your browser doesn\'t support audio.<br>Please download the file: %links%',
  134. autoPlay: 'Auto play'
  135. };
  136. var es = {
  137. toolbar: 'Audio',
  138. dialogTitle: 'Propiedades de audio',
  139. fakeObject: 'Audio',
  140. properties: 'Editar el audio',
  141. widthRequired: 'La anchura no se puede dejar en blanco',
  142. heightRequired: 'La altura no se puede dejar en blanco',
  143. sourceAudio: 'Archivo de audio',
  144. sourceType: 'Tipo',
  145. linkTemplate: '<a href="%src%">%type%</a> ',
  146. fallbackTemplate: 'Su navegador no soporta AUDIO.<br>Por favor, descargue el fichero: %links%',
  147. autoPlay: 'Reproducir automáticamente'
  148. };
  149. // v3
  150. if (CKEDITOR.skins) {
  151. en = {audio: en};
  152. es = {audio: es};
  153. }
  154. // Translations
  155. CKEDITOR.plugins.setLang('audio', 'en', en);
  156. CKEDITOR.plugins.setLang('audio', 'es', es);
  157. })();