editor_plugin.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @file
  3. * Plugin for inserting links with Linkit.
  4. */
  5. (function ($) {
  6. tinymce.create('tinymce.plugins.linkit', {
  7. init : function(editor, url) {
  8. // Register commands
  9. editor.addCommand('mceLinkit', function() {
  10. if (typeof Drupal.settings.linkit === 'undefined') {
  11. alert(Drupal.t('Could not find the Linkit profile.'));
  12. return ;
  13. }
  14. // Set the editor object.
  15. Drupal.settings.linkit.currentInstance.editor = editor;
  16. // Set profile.
  17. Drupal.settings.linkit.currentInstance.profile = Drupal.settings.linkit.fields[editor.id].profile;
  18. // Set the name of the source field..
  19. Drupal.settings.linkit.currentInstance.source = editor.id;
  20. // Set the source type.
  21. Drupal.settings.linkit.currentInstance.helper = 'tinymce';
  22. // Stores the current editor selection for later restoration. This can
  23. // be useful since some browsers looses it's selection if a control
  24. // element is selected/focused inside the dialogs.
  25. editor.windowManager.bookmark = editor.selection.getBookmark(1);
  26. // Create the modal.
  27. Drupal.linkit.createModal();
  28. });
  29. // Register buttons
  30. editor.addButton('linkit', {
  31. title : Drupal.t('Link to content'),
  32. cmd : 'mceLinkit',
  33. image : url + '/images/linkit.png'
  34. });
  35. // We need the real contextmenu in order to make this work.
  36. if (editor && editor.plugins.contextmenu) {
  37. // Contextmenu gets called - this is what we do.
  38. editor.plugins.contextmenu.onContextMenu.add(function(th, m, e, col) {
  39. // Only if selected node is an link do this.
  40. if (e.nodeName == 'A' || !col) {
  41. // Remove all options from standard contextmenu.
  42. m.removeAll();
  43. th._menu.add({
  44. title : Drupal.t('Link to content'),
  45. cmd : 'mceLinkit',
  46. icon : 'linkit'
  47. });
  48. //m.addSeparator();
  49. }
  50. });
  51. }
  52. },
  53. getInfo : function() {
  54. return {
  55. longname : 'Linkit',
  56. author : 'Emil Stjerneman',
  57. authorurl : 'http://www.stjerneman.com',
  58. infourl : 'http://drupal.org/project/linkit',
  59. version : tinymce.majorVersion + "." + tinymce.minorVersion
  60. };
  61. }
  62. });
  63. // Register plugin
  64. tinymce.PluginManager.add('linkit', tinymce.plugins.linkit);
  65. })(jQuery);