plugin.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * @file Video 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( 'video',
  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_video' +
  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.video;
  49. // Check for CKEditor 3.5
  50. if (typeof editor.element.data == 'undefined')
  51. {
  52. alert('The "video" plugin requires CKEditor 3.5 or newer');
  53. return;
  54. }
  55. CKEDITOR.dialog.add( 'video', this.path + 'dialogs/video.js' );
  56. editor.addCommand( 'Video', new CKEDITOR.dialogCommand( 'video' ) );
  57. editor.ui.addButton( 'Video',
  58. {
  59. label : lang.toolbar,
  60. command : 'Video',
  61. icon : this.path + 'images/icon.png'
  62. } );
  63. // v3
  64. if (editor.addCss)
  65. editor.addCss( this.getPlaceholderCss() );
  66. // If the "menu" plugin is loaded, register the menu items.
  67. if ( editor.addMenuItems )
  68. {
  69. editor.addMenuItems(
  70. {
  71. video :
  72. {
  73. label : lang.properties,
  74. command : 'Video',
  75. group : 'flash'
  76. }
  77. });
  78. }
  79. editor.on( 'doubleclick', function( evt )
  80. {
  81. var element = evt.data.element;
  82. if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'video' )
  83. evt.data.dialog = 'video';
  84. });
  85. // If the "contextmenu" plugin is loaded, register the listeners.
  86. if ( editor.contextMenu )
  87. {
  88. editor.contextMenu.addListener( function( element, selection )
  89. {
  90. if ( element && element.is( 'img' ) && !element.isReadOnly()
  91. && element.data( 'cke-real-element-type' ) == 'video' )
  92. return { video : CKEDITOR.TRISTATE_OFF };
  93. });
  94. }
  95. // Add special handling for these items
  96. CKEDITOR.dtd.$empty['cke:source']=1;
  97. CKEDITOR.dtd.$empty['source']=1;
  98. editor.lang.fakeobjects.video = lang.fakeObject;
  99. }, //Init
  100. afterInit: function( editor )
  101. {
  102. var dataProcessor = editor.dataProcessor,
  103. htmlFilter = dataProcessor && dataProcessor.htmlFilter,
  104. dataFilter = dataProcessor && dataProcessor.dataFilter;
  105. // dataFilter : conversion from html input to internal data
  106. dataFilter.addRules(
  107. {
  108. elements : {
  109. $ : function( realElement )
  110. {
  111. if ( realElement.name == 'video' )
  112. {
  113. realElement.name = 'cke:video';
  114. for( var i=0; i < realElement.children.length; i++)
  115. {
  116. if ( realElement.children[ i ].name == 'source' )
  117. realElement.children[ i ].name = 'cke:source'
  118. }
  119. var fakeElement = editor.createFakeParserElement( realElement, 'cke_video', 'video', false ),
  120. fakeStyle = fakeElement.attributes.style || '';
  121. var width = realElement.attributes.width,
  122. height = realElement.attributes.height,
  123. poster = realElement.attributes.poster;
  124. if ( typeof width != 'undefined' )
  125. fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + CKEDITOR.tools.cssLength( width ) + ';';
  126. if ( typeof height != 'undefined' )
  127. fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + CKEDITOR.tools.cssLength( height ) + ';';
  128. if ( poster )
  129. fakeStyle = fakeElement.attributes.style = fakeStyle + 'background-image:url(' + poster + ');';
  130. return fakeElement;
  131. }
  132. }
  133. }
  134. }
  135. );
  136. } // afterInit
  137. } ); // plugins.add
  138. var en = {
  139. toolbar : 'Video',
  140. dialogTitle : 'Video properties',
  141. fakeObject : 'Video',
  142. properties : 'Edit video',
  143. widthRequired : 'Width field cannot be empty',
  144. heightRequired : 'Height field cannot be empty',
  145. poster: 'Poster image',
  146. sourceVideo: 'Source video',
  147. sourceType : 'Video type',
  148. linkTemplate : '<a href="%src%">%type%</a> ',
  149. fallbackTemplate : 'Your browser doesn\'t support video.<br>Please download the file: %links%'
  150. };
  151. var es = {
  152. toolbar : 'Video',
  153. dialogTitle : 'Propiedades de video',
  154. fakeObject : 'Video',
  155. properties : 'Editar el video',
  156. widthRequired : 'La anchura no se puede dejar en blanco',
  157. heightRequired : 'La altura no se puede dejar en blanco',
  158. poster: 'Imagen de presentación',
  159. sourceVideo: 'Archivo de video',
  160. sourceType : 'Tipo',
  161. linkTemplate : '<a href="%src%">%type%</a> ',
  162. fallbackTemplate : 'Su navegador no soporta VIDEO.<br>Por favor, descargue el fichero: %links%'
  163. };
  164. // v3
  165. if (CKEDITOR.skins)
  166. {
  167. en = { video : en} ;
  168. es = { video : es} ;
  169. }
  170. // Translations
  171. CKEDITOR.plugins.setLang( 'video', 'en', en );
  172. CKEDITOR.plugins.setLang( 'video', 'es', es );
  173. })();