bgneal@45: /** bgneal@183: * editor_plugin_src.js bgneal@45: * bgneal@183: * Copyright 2009, Moxiecode Systems AB bgneal@183: * Released under LGPL License. bgneal@183: * bgneal@183: * License: http://tinymce.moxiecode.com/license bgneal@183: * Contributing: http://tinymce.moxiecode.com/contributing bgneal@45: */ bgneal@45: bgneal@45: (function() { bgneal@45: var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM; bgneal@45: bgneal@183: /** bgneal@183: * This plugin a context menu to TinyMCE editor instances. bgneal@183: * bgneal@183: * @class tinymce.plugins.ContextMenu bgneal@183: */ bgneal@45: tinymce.create('tinymce.plugins.ContextMenu', { bgneal@183: /** bgneal@183: * Initializes the plugin, this will be executed after the plugin has been created. bgneal@183: * This call is done before the editor instance has finished it's initialization so use the onInit event bgneal@183: * of the editor instance to intercept that event. bgneal@183: * bgneal@183: * @method init bgneal@183: * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. bgneal@183: * @param {string} url Absolute URL to where the plugin is located. bgneal@183: */ bgneal@45: init : function(ed) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.editor = ed; bgneal@183: bgneal@183: /** bgneal@183: * This event gets fired when the context menu is shown. bgneal@183: * bgneal@183: * @event onContextMenu bgneal@183: * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event. bgneal@183: * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed. bgneal@183: */ bgneal@45: t.onContextMenu = new tinymce.util.Dispatcher(this); bgneal@45: bgneal@45: ed.onContextMenu.add(function(ed, e) { bgneal@45: if (!e.ctrlKey) { bgneal@45: t._getMenu(ed).showMenu(e.clientX, e.clientY); bgneal@45: Event.add(ed.getDoc(), 'click', hide); bgneal@45: Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: function hide() { bgneal@45: if (t._menu) { bgneal@45: t._menu.removeAll(); bgneal@45: t._menu.destroy(); bgneal@45: Event.remove(ed.getDoc(), 'click', hide); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: ed.onMouseDown.add(hide); bgneal@45: ed.onKeyDown.add(hide); bgneal@45: }, bgneal@45: bgneal@183: /** bgneal@183: * Returns information about the plugin as a name/value array. bgneal@183: * The current keys are longname, author, authorurl, infourl and version. bgneal@183: * bgneal@183: * @method getInfo bgneal@183: * @return {Object} Name/value array containing information about the plugin. bgneal@183: */ bgneal@45: getInfo : function() { bgneal@45: return { bgneal@45: longname : 'Contextmenu', bgneal@45: author : 'Moxiecode Systems AB', bgneal@45: authorurl : 'http://tinymce.moxiecode.com', bgneal@45: infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu', bgneal@45: version : tinymce.majorVersion + "." + tinymce.minorVersion bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: _getMenu : function(ed) { bgneal@45: var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p1, p2; bgneal@45: bgneal@45: if (m) { bgneal@45: m.removeAll(); bgneal@45: m.destroy(); bgneal@45: } bgneal@45: bgneal@45: p1 = DOM.getPos(ed.getContentAreaContainer()); bgneal@45: p2 = DOM.getPos(ed.getContainer()); bgneal@45: bgneal@45: m = ed.controlManager.createDropMenu('contextmenu', { bgneal@45: offset_x : p1.x + ed.getParam('contextmenu_offset_x', 0), bgneal@45: offset_y : p1.y + ed.getParam('contextmenu_offset_y', 0), bgneal@45: constrain : 1 bgneal@45: }); bgneal@45: bgneal@45: t._menu = m; bgneal@45: bgneal@45: m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col); bgneal@45: m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col); bgneal@45: m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'}); bgneal@45: bgneal@45: if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) { bgneal@45: m.addSeparator(); bgneal@45: m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true}); bgneal@45: m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'}); bgneal@45: } bgneal@45: bgneal@45: m.addSeparator(); bgneal@45: m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); bgneal@45: bgneal@45: m.addSeparator(); bgneal@45: am = m.addMenu({title : 'contextmenu.align'}); bgneal@45: am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'}); bgneal@45: am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'}); bgneal@45: am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'}); bgneal@45: am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'}); bgneal@45: bgneal@45: t.onContextMenu.dispatch(t, m, el, col); bgneal@45: bgneal@45: return m; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Register plugin bgneal@45: tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu); bgneal@45: })();