PageRenderTime 16ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/static/scripts/tiny_mce/plugins/contextmenu/editor_plugin_src.js

http://n23.googlecode.com/
JavaScript | 97 lines | 69 code | 19 blank | 9 comment | 8 complexity | b218adc7d5f48eb4d62695929d1484d2 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. /**
  2. * $Id: editor_plugin_src.js 755 2008-03-29 19:14:42Z spocke $
  3. *
  4. * @author Moxiecode
  5. * @copyright Copyright Š 2004-2008, Moxiecode Systems AB, All rights reserved.
  6. */
  7. (function() {
  8. var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
  9. tinymce.create('tinymce.plugins.ContextMenu', {
  10. init : function(ed) {
  11. var t = this;
  12. t.editor = ed;
  13. t.onContextMenu = new tinymce.util.Dispatcher(this);
  14. ed.onContextMenu.add(function(ed, e) {
  15. if (!e.ctrlKey) {
  16. t._getMenu(ed).showMenu(e.clientX, e.clientY);
  17. Event.add(document, 'click', hide);
  18. Event.cancel(e);
  19. }
  20. });
  21. function hide() {
  22. if (t._menu) {
  23. t._menu.removeAll();
  24. t._menu.destroy();
  25. Event.remove(document, 'click', hide);
  26. }
  27. };
  28. ed.onMouseDown.add(hide);
  29. ed.onKeyDown.add(hide);
  30. },
  31. getInfo : function() {
  32. return {
  33. longname : 'Contextmenu',
  34. author : 'Moxiecode Systems AB',
  35. authorurl : 'http://tinymce.moxiecode.com',
  36. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
  37. version : tinymce.majorVersion + "." + tinymce.minorVersion
  38. };
  39. },
  40. _getMenu : function(ed) {
  41. var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2;
  42. if (m) {
  43. m.removeAll();
  44. m.destroy();
  45. }
  46. p1 = DOM.getPos(ed.getContentAreaContainer());
  47. p2 = DOM.getPos(ed.getContainer());
  48. m = ed.controlManager.createDropMenu('contextmenu', {
  49. offset_x : p1.x,
  50. offset_y : p1.y,
  51. /* vp_offset_x : p2.x,
  52. vp_offset_y : p2.y,*/
  53. constrain : 1
  54. });
  55. t._menu = m;
  56. m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
  57. m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
  58. m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
  59. if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
  60. m.addSeparator();
  61. m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
  62. m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
  63. }
  64. m.addSeparator();
  65. m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
  66. m.addSeparator();
  67. am = m.addMenu({title : 'contextmenu.align'});
  68. am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
  69. am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
  70. am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
  71. am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
  72. t.onContextMenu.dispatch(t, m, el, col);
  73. return m;
  74. }
  75. });
  76. // Register plugin
  77. tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
  78. })();