editor_plugin.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // Find the current input format of the field we're looking at. Note that we get it in the form
  17. // "format<formatname" instead of just "<formatname>" so we use .substring() to remove the "format".
  18. if (Drupal.wysiwyg && Drupal.wysiwyg.instances[editor.id].format) {
  19. var format = Drupal.wysiwyg.instances[editor.id].format.substring(6);
  20. } else {
  21. alert(Drupal.t('Could not find the Linkit profile.'));
  22. return;
  23. }
  24. // Set profile based on the current text format of this field.
  25. Drupal.settings.linkit.currentInstance.profile = Drupal.settings.linkit.formats[format].profile;
  26. // Set the name of the source field..
  27. Drupal.settings.linkit.currentInstance.source = editor.id;
  28. // Set the source type.
  29. Drupal.settings.linkit.currentInstance.helper = 'tinymce';
  30. // Stores the current editor selection for later restoration. This can
  31. // be useful since some browsers looses it's selection if a control
  32. // element is selected/focused inside the dialogs.
  33. editor.windowManager.bookmark = editor.selection.getBookmark(1);
  34. // Create the modal.
  35. Drupal.linkit.createModal();
  36. });
  37. // Register buttons
  38. editor.addButton('linkit', {
  39. title : Drupal.t('Link to content'),
  40. cmd : 'mceLinkit',
  41. image : url + '/images/linkit.png'
  42. });
  43. // We need the real contextmenu in order to make this work.
  44. if (editor && editor.plugins.contextmenu) {
  45. // Contextmenu gets called - this is what we do.
  46. editor.plugins.contextmenu.onContextMenu.add(function(th, m, e, col) {
  47. // Only if selected node is an link do this.
  48. if (e.nodeName == 'A' || !col) {
  49. // Remove all options from standard contextmenu.
  50. m.removeAll();
  51. th._menu.add({
  52. title : Drupal.t('Link to content'),
  53. cmd : 'mceLinkit',
  54. icon : 'linkit'
  55. });
  56. //m.addSeparator();
  57. }
  58. });
  59. }
  60. },
  61. getInfo : function() {
  62. return {
  63. longname : 'Linkit',
  64. author : 'Emil Stjerneman',
  65. authorurl : 'http://www.stjerneman.com',
  66. infourl : 'http://drupal.org/project/linkit',
  67. version : tinymce.majorVersion + "." + tinymce.minorVersion
  68. };
  69. }
  70. });
  71. // Register plugin
  72. tinymce.PluginManager.add('linkit', tinymce.plugins.linkit);
  73. })(jQuery);