plugin.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * @file Plugin for inserting video tags with video_filter
  3. */
  4. (function ($) {
  5. CKEDITOR.plugins.add('video_filter', {
  6. requires : [],
  7. init: function(editor) {
  8. // Add Button
  9. editor.ui.addButton('video_filter', {
  10. label: 'Video filter',
  11. command: 'video_filter',
  12. icon: this.path + 'video_filter.png'
  13. });
  14. if(typeof window.showModalDialog !== 'undefined') {
  15. editor.addCommand('video_filter', {
  16. exec : function () {
  17. var path = (Drupal.settings.video_filter.url.wysiwyg_ckeditor) ? Drupal.settings.video_filter.url.wysiwyg_ckeditor : Drupal.settings.video_filter.url.ckeditor
  18. var media = window.showModalDialog(path, { 'opener' : window, 'editorname' : editor.name }, "dialogWidth:580px; dialogHeight:480px; center:yes; resizable:yes; help:no;");
  19. }
  20. });
  21. // Register an extra function, this will be used in the popup.
  22. editor._.video_filterFnNum = CKEDITOR.tools.addFunction(insert, editor);
  23. }
  24. else {
  25. editor.addCommand('video_filter', new CKEDITOR.dialogCommand('video_filterDialog'));
  26. }
  27. }
  28. });
  29. CKEDITOR.dialog.add('video_filterDialog', function( editor ) {
  30. var instructions_path = Drupal.settings.video_filter.instructions_url;
  31. return {
  32. title : 'Add Video',
  33. minWidth : 600,
  34. minHeight : 180,
  35. contents : [{
  36. id : 'general',
  37. label : 'Settings',
  38. elements : [
  39. {
  40. type : 'text',
  41. id : 'file_url',
  42. label : 'URL',
  43. validate : CKEDITOR.dialog.validate.notEmpty( 'The link must have a URL.' ),
  44. required : true,
  45. commit : function( data )
  46. {
  47. data.file_url = this.getValue();
  48. }
  49. },
  50. {
  51. type : 'text',
  52. id : 'width',
  53. label : 'Width',
  54. commit : function( data )
  55. {
  56. data.width = this.getValue();
  57. }
  58. },
  59. {
  60. type : 'text',
  61. id : 'height',
  62. label : 'Height',
  63. commit : function( data )
  64. {
  65. data.height = this.getValue();
  66. }
  67. },
  68. {
  69. type : 'select',
  70. id : 'align',
  71. label : 'Align',
  72. 'default': 'none',
  73. items: [
  74. ['None', ''],
  75. ['Left', 'left'],
  76. ['Right', 'right'],
  77. ['Center', 'center']
  78. ],
  79. commit : function( data )
  80. {
  81. data.align = this.getValue();
  82. }
  83. },
  84. {
  85. type : 'checkbox',
  86. id : 'autoplay',
  87. label : 'Autoplay',
  88. 'default': '',
  89. commit : function( data )
  90. {
  91. data.autoplay = this.getValue() ? 1 : 0;
  92. }
  93. },
  94. {
  95. type: 'html',
  96. html: '<iframe src="' + instructions_path + '" style="width:100%; height: 200px;"></iframe>',
  97. },
  98. ]
  99. }],
  100. onOk : function()
  101. {
  102. var dialog = this,
  103. data = {},
  104. link = editor.document.createElement( 'p' );
  105. this.commitContent( data );
  106. var str = '[video:' + data.file_url;
  107. if (data.width) {
  108. str += ' width:' + data.width;
  109. }
  110. if (data.height) {
  111. str += ' height:' + data.height;
  112. }
  113. if (data.align) {
  114. str += ' align:' + data.align;
  115. }
  116. if (data.autoplay) {
  117. str += ' autoplay:' + data.autoplay;
  118. }
  119. str += ']';
  120. link.setHtml( str );
  121. editor.insertElement( link );
  122. }
  123. };
  124. });
  125. function insert(params, editor) {
  126. var selection = editor.getSelection(),
  127. ranges = selection.getRanges(),
  128. range,
  129. textNode;
  130. editor.fire('saveSnapshot');
  131. var str = '[video:' + params.file_url;
  132. if (params.width) {
  133. str += ' width:' + params.width;
  134. }
  135. if (params.height) {
  136. str += ' height:' + params.height;
  137. }
  138. if (params.align) {
  139. str += ' align:' + params.align;
  140. }
  141. if (params.autoplay) {
  142. str += ' autoplay:' + params.autoplay;
  143. }
  144. else {
  145. str += ' autoplay:' + '0';
  146. }
  147. str += ']';
  148. for (var i = 0, len = ranges.length; i < len; i++) {
  149. range = ranges[i];
  150. range.deleteContents();
  151. textNode = CKEDITOR.dom.element.createFromHtml(str);
  152. range.insertNode(textNode);
  153. }
  154. range.moveToPosition(textNode, CKEDITOR.POSITION_AFTER_END);
  155. range.select();
  156. editor.fire('saveSnapshot');
  157. }
  158. })(jQuery);