plugin.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // Add Command
  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 fucntion, this will be used in the popup.
  22. editor._.video_filterFnNum = CKEDITOR.tools.addFunction(insert, editor);
  23. }
  24. });
  25. function insert(params, editor) {
  26. var selection = editor.getSelection(),
  27. ranges = selection.getRanges(),
  28. range,
  29. textNode;
  30. editor.fire('saveSnapshot');
  31. var str = '[video:' + params.file_url;
  32. if (params.width) {
  33. str += ' width:' + params.width;
  34. }
  35. if (params.height) {
  36. str += ' height:' + params.height;
  37. }
  38. if (params.align) {
  39. str += ' align:' + params.align;
  40. }
  41. if (params.autoplay) {
  42. str += ' autoplay:' + params.autoplay;
  43. }
  44. str += ']';
  45. for (var i = 0, len = ranges.length; i < len; i++) {
  46. range = ranges[i];
  47. range.deleteContents();
  48. textNode = CKEDITOR.dom.element.createFromHtml(str);
  49. range.insertNode(textNode);
  50. }
  51. range.moveToPosition(textNode, CKEDITOR.POSITION_AFTER_END);
  52. range.select();
  53. editor.fire('saveSnapshot');
  54. }
  55. })(jQuery);