plugin.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.html or http://ckeditor.com/license
  4. */
  5. /**
  6. * @file Plugin for inserting images from Drupal media module
  7. */
  8. ( function() {
  9. CKEDITOR.plugins.add( 'media',
  10. {
  11. // Wrap Drupal plugin in a proxy plugin.
  12. init: function(editor)
  13. {
  14. var pluginCommand = {
  15. exec: function (editor) {
  16. var data = {
  17. format: 'html',
  18. node: null,
  19. content: ''
  20. };
  21. var selection = editor.getSelection();
  22. if (selection) {
  23. data.node = selection.getSelectedElement();
  24. if (data.node) {
  25. data.node = data.node.$;
  26. }
  27. if (selection.getType() == CKEDITOR.SELECTION_TEXT) {
  28. data.content = selection.getSelectedText();
  29. }
  30. else if (data.node) {
  31. // content is supposed to contain the "outerHTML".
  32. data.content = data.node.parentNode.innerHTML;
  33. }
  34. }
  35. Drupal.settings.ckeditor.plugins['media'].invoke(data, Drupal.settings.ckeditor.plugins['media'], editor.name);
  36. }
  37. };
  38. editor.addCommand( 'media', pluginCommand );
  39. editor.ui.addButton( 'Media',
  40. {
  41. label: 'Add media',
  42. command: 'media',
  43. icon: this.path + 'images/icon.gif'
  44. });
  45. }
  46. });
  47. } )();