plugin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright (c) 2003-2012, 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. if (CKEDITOR.env.ie) {
  29. data.content = selection.getNative().createRange().text;
  30. }
  31. else {
  32. data.content = selection.getNative().toString();
  33. }
  34. }
  35. else if (data.node) {
  36. // content is supposed to contain the "outerHTML".
  37. data.content = data.node.parentNode.innerHTML;
  38. }
  39. }
  40. Drupal.settings.ckeditor.plugins['media'].invoke(data, Drupal.settings.ckeditor.plugins['media'], editor.name);
  41. }
  42. };
  43. editor.addCommand( 'media', pluginCommand );
  44. editor.ui.addButton( 'Media',
  45. {
  46. label: 'Add media',
  47. command: 'media',
  48. icon: this.path + 'images/icon.gif'
  49. });
  50. }
  51. });
  52. } )();