PageRenderTime 42ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/contextmenu/editor_plugin_src.js

#
JavaScript | 160 lines | 90 code | 28 blank | 42 comment | 21 complexity | 3c35f68c340db520b8e55c90af6c12ba MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /**
  2. * editor_plugin_src.js
  3. *
  4. * Copyright 2009, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://tinymce.moxiecode.com/license
  8. * Contributing: http://tinymce.moxiecode.com/contributing
  9. */
  10. (function() {
  11. var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM;
  12. /**
  13. * This plugin a context menu to TinyMCE editor instances.
  14. *
  15. * @class tinymce.plugins.ContextMenu
  16. */
  17. tinymce.create('tinymce.plugins.ContextMenu', {
  18. /**
  19. * Initializes the plugin, this will be executed after the plugin has been created.
  20. * This call is done before the editor instance has finished it's initialization so use the onInit event
  21. * of the editor instance to intercept that event.
  22. *
  23. * @method init
  24. * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in.
  25. * @param {string} url Absolute URL to where the plugin is located.
  26. */
  27. init : function(ed) {
  28. var t = this, showMenu, contextmenuNeverUseNative, realCtrlKey;
  29. t.editor = ed;
  30. contextmenuNeverUseNative = ed.settings.contextmenu_never_use_native;
  31. /**
  32. * This event gets fired when the context menu is shown.
  33. *
  34. * @event onContextMenu
  35. * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event.
  36. * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed.
  37. */
  38. t.onContextMenu = new tinymce.util.Dispatcher(this);
  39. showMenu = ed.onContextMenu.add(function(ed, e) {
  40. // Block TinyMCE menu on ctrlKey and work around Safari issue
  41. if ((realCtrlKey !== 0 ? realCtrlKey : e.ctrlKey) && !contextmenuNeverUseNative)
  42. return;
  43. Event.cancel(e);
  44. // Select the image if it's clicked. WebKit would other wise expand the selection
  45. if (e.target.nodeName == 'IMG')
  46. ed.selection.select(e.target);
  47. t._getMenu(ed).showMenu(e.clientX || e.pageX, e.clientY || e.pageY);
  48. Event.add(ed.getDoc(), 'click', function(e) {
  49. hide(ed, e);
  50. });
  51. ed.nodeChanged();
  52. });
  53. ed.onRemove.add(function() {
  54. if (t._menu)
  55. t._menu.removeAll();
  56. });
  57. function hide(ed, e) {
  58. realCtrlKey = 0;
  59. // Since the contextmenu event moves
  60. // the selection we need to store it away
  61. if (e && e.button == 2) {
  62. realCtrlKey = e.ctrlKey;
  63. return;
  64. }
  65. if (t._menu) {
  66. t._menu.removeAll();
  67. t._menu.destroy();
  68. Event.remove(ed.getDoc(), 'click', hide);
  69. }
  70. };
  71. ed.onMouseDown.add(hide);
  72. ed.onKeyDown.add(hide);
  73. ed.onKeyDown.add(function(ed, e) {
  74. if (e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode === 121) {
  75. Event.cancel(e);
  76. showMenu(ed, e);
  77. }
  78. });
  79. },
  80. /**
  81. * Returns information about the plugin as a name/value array.
  82. * The current keys are longname, author, authorurl, infourl and version.
  83. *
  84. * @method getInfo
  85. * @return {Object} Name/value array containing information about the plugin.
  86. */
  87. getInfo : function() {
  88. return {
  89. longname : 'Contextmenu',
  90. author : 'Moxiecode Systems AB',
  91. authorurl : 'http://tinymce.moxiecode.com',
  92. infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu',
  93. version : tinymce.majorVersion + "." + tinymce.minorVersion
  94. };
  95. },
  96. _getMenu : function(ed) {
  97. var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p;
  98. if (m) {
  99. m.removeAll();
  100. m.destroy();
  101. }
  102. p = DOM.getPos(ed.getContentAreaContainer());
  103. m = ed.controlManager.createDropMenu('contextmenu', {
  104. offset_x : p.x + ed.getParam('contextmenu_offset_x', 0),
  105. offset_y : p.y + ed.getParam('contextmenu_offset_y', 0),
  106. constrain : 1,
  107. keyboard_focus: true
  108. });
  109. t._menu = m;
  110. m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col);
  111. m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col);
  112. m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'});
  113. if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) {
  114. m.addSeparator();
  115. m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true});
  116. m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'});
  117. }
  118. m.addSeparator();
  119. m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true});
  120. m.addSeparator();
  121. am = m.addMenu({title : 'contextmenu.align'});
  122. am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'});
  123. am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'});
  124. am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'});
  125. am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'});
  126. t.onContextMenu.dispatch(t, m, el, col);
  127. return m;
  128. }
  129. });
  130. // Register plugin
  131. tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu);
  132. })();