X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftiny_mce%2Fplugins%2Fcontextmenu%2Feditor_plugin_src.js;h=956fbea99880c9825a5cf24e025170314615474b;hb=eb5fb3f6c3b3e1d4d3d7ebbb92b8c60d70d13254;hp=42743e46a0d7eeb566719209c2ccf16ddb810bee;hpb=26a4a07bdacdaa7013bf45cc235df207708acfde;p=citadel.git diff --git a/webcit/tiny_mce/plugins/contextmenu/editor_plugin_src.js b/webcit/tiny_mce/plugins/contextmenu/editor_plugin_src.js index 42743e46a..956fbea99 100644 --- a/webcit/tiny_mce/plugins/contextmenu/editor_plugin_src.js +++ b/webcit/tiny_mce/plugins/contextmenu/editor_plugin_src.js @@ -1,309 +1,160 @@ -/* Import plugin specific language pack */ -//tinyMCE.importPluginLanguagePack('contextmenu', 'en,zh_cn,cs,fa,fr_ca,fr,de,nb'); -if (!tinyMCE.settings['contextmenu_skip_plugin_css']) - tinyMCE.loadCSS(tinyMCE.baseURL + "/plugins/contextmenu/css/contextmenu.css"); - -// Global contextmenu class instance -var TinyMCE_contextmenu_contextMenu = null; - -function TinyMCE_contextmenu_getInfo() { - return { - longname : 'Context menus', - author : 'Moxiecode Systems', - authorurl : 'http://tinymce.moxiecode.com', - infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_contextmenu.html', - version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion - }; -}; - -function TinyMCE_contextmenu_initInstance(inst) { - // Is not working on MSIE 5.0 or Opera no contextmenu event - if (tinyMCE.isMSIE5_0 && tinyMCE.isOpera) - return; - - // Add hide event handles - tinyMCE.addEvent(inst.getDoc(), "click", TinyMCE_contextmenu_hideContextMenu); - tinyMCE.addEvent(inst.getDoc(), "keypress", TinyMCE_contextmenu_hideContextMenu); - tinyMCE.addEvent(inst.getDoc(), "keydown", TinyMCE_contextmenu_hideContextMenu); - tinyMCE.addEvent(document, "click", TinyMCE_contextmenu_hideContextMenu); - tinyMCE.addEvent(document, "keypress", TinyMCE_contextmenu_hideContextMenu); - tinyMCE.addEvent(document, "keydown", TinyMCE_contextmenu_hideContextMenu); - - var contextMenu = new ContextMenu({ - commandhandler : "TinyMCE_contextmenu_commandHandler", - spacer_image : tinyMCE.baseURL + "/plugins/contextmenu/images/spacer.gif" - }); - - // Register global reference - TinyMCE_contextmenu_contextMenu = contextMenu; - - // Attach contextmenu event - if (tinyMCE.isGecko) { - tinyMCE.addEvent(inst.getDoc(), "contextmenu", function(e) {TinyMCE_contextmenu_showContextMenu(tinyMCE.isMSIE ? inst.contentWindow.event : e, inst);}); - } else - tinyMCE.addEvent(inst.getDoc(), "contextmenu", TinyMCE_contextmenu_onContextMenu); -} - -function TinyMCE_contextmenu_onContextMenu(e) { - var elm = tinyMCE.isMSIE ? e.srcElement : e.target; - var targetInst, body; - - // Find instance - if ((body = tinyMCE.getParentElement(elm, "body")) != null) { - for (var n in tinyMCE.instances) { - var inst = tinyMCE.instances[n]; - if (!tinyMCE.isInstance(inst)) - continue; - - if (body == inst.getBody()) { - targetInst = inst; - break; +/** + * editor_plugin_src.js + * + * Copyright 2009, Moxiecode Systems AB + * Released under LGPL License. + * + * License: http://tinymce.moxiecode.com/license + * Contributing: http://tinymce.moxiecode.com/contributing + */ + +(function() { + var Event = tinymce.dom.Event, each = tinymce.each, DOM = tinymce.DOM; + + /** + * This plugin a context menu to TinyMCE editor instances. + * + * @class tinymce.plugins.ContextMenu + */ + tinymce.create('tinymce.plugins.ContextMenu', { + /** + * Initializes the plugin, this will be executed after the plugin has been created. + * This call is done before the editor instance has finished it's initialization so use the onInit event + * of the editor instance to intercept that event. + * + * @method init + * @param {tinymce.Editor} ed Editor instance that the plugin is initialized in. + * @param {string} url Absolute URL to where the plugin is located. + */ + init : function(ed) { + var t = this, showMenu, contextmenuNeverUseNative, realCtrlKey; + + t.editor = ed; + + contextmenuNeverUseNative = ed.settings.contextmenu_never_use_native; + + /** + * This event gets fired when the context menu is shown. + * + * @event onContextMenu + * @param {tinymce.plugins.ContextMenu} sender Plugin instance sending the event. + * @param {tinymce.ui.DropMenu} menu Drop down menu to fill with more items if needed. + */ + t.onContextMenu = new tinymce.util.Dispatcher(this); + + showMenu = ed.onContextMenu.add(function(ed, e) { + // Block TinyMCE menu on ctrlKey and work around Safari issue + if ((realCtrlKey !== 0 ? realCtrlKey : e.ctrlKey) && !contextmenuNeverUseNative) + return; + + Event.cancel(e); + + // Select the image if it's clicked. WebKit would other wise expand the selection + if (e.target.nodeName == 'IMG') + ed.selection.select(e.target); + + t._getMenu(ed).showMenu(e.clientX || e.pageX, e.clientY || e.pageY); + Event.add(ed.getDoc(), 'click', function(e) { + hide(ed, e); + }); + + ed.nodeChanged(); + }); + + ed.onRemove.add(function() { + if (t._menu) + t._menu.removeAll(); + }); + + function hide(ed, e) { + realCtrlKey = 0; + + // Since the contextmenu event moves + // the selection we need to store it away + if (e && e.button == 2) { + realCtrlKey = e.ctrlKey; + return; + } + + if (t._menu) { + t._menu.removeAll(); + t._menu.destroy(); + Event.remove(ed.getDoc(), 'click', hide); + } + }; + + ed.onMouseDown.add(hide); + ed.onKeyDown.add(hide); + ed.onKeyDown.add(function(ed, e) { + if (e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode === 121) { + Event.cancel(e); + showMenu(ed, e); + } + }); + }, + + /** + * Returns information about the plugin as a name/value array. + * The current keys are longname, author, authorurl, infourl and version. + * + * @method getInfo + * @return {Object} Name/value array containing information about the plugin. + */ + getInfo : function() { + return { + longname : 'Contextmenu', + author : 'Moxiecode Systems AB', + authorurl : 'http://tinymce.moxiecode.com', + infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/contextmenu', + version : tinymce.majorVersion + "." + tinymce.minorVersion + }; + }, + + _getMenu : function(ed) { + var t = this, m = t._menu, se = ed.selection, col = se.isCollapsed(), el = se.getNode() || ed.getBody(), am, p; + + if (m) { + m.removeAll(); + m.destroy(); } - } - - return TinyMCE_contextmenu_showContextMenu(tinyMCE.isMSIE ? targetInst.contentWindow.event : e, targetInst); - } -} - -function TinyMCE_contextmenu_showContextMenu(e, inst) { - function getAttrib(elm, name) { - return elm.getAttribute(name) ? elm.getAttribute(name) : ""; - } - var x, y, elm, contextMenu; - var pos = tinyMCE.getAbsPosition(inst.iframeElement); + p = DOM.getPos(ed.getContentAreaContainer()); - x = tinyMCE.isMSIE ? e.screenX : pos.absLeft + (e.pageX - inst.getBody().scrollLeft); - y = tinyMCE.isMSIE ? e.screenY : pos.absTop + (e.pageY - inst.getBody().scrollTop); - elm = tinyMCE.isMSIE ? e.srcElement : e.target; - contextMenu = TinyMCE_contextmenu_contextMenu; - contextMenu.inst = inst; + m = ed.controlManager.createDropMenu('contextmenu', { + offset_x : p.x + ed.getParam('contextmenu_offset_x', 0), + offset_y : p.y + ed.getParam('contextmenu_offset_y', 0), + constrain : 1, + keyboard_focus: true + }); - // Mozilla needs some time - window.setTimeout(function () { - var theme = tinyMCE.getParam("theme"); + t._menu = m; - contextMenu.clearAll(); - var sel = inst.getSelectedText().length != 0 || elm.nodeName == "IMG"; + m.add({title : 'advanced.cut_desc', icon : 'cut', cmd : 'Cut'}).setDisabled(col); + m.add({title : 'advanced.copy_desc', icon : 'copy', cmd : 'Copy'}).setDisabled(col); + m.add({title : 'advanced.paste_desc', icon : 'paste', cmd : 'Paste'}); - // Default items - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_cut_desc", "Cut", "", !sel); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_copy_desc", "Copy", "", !sel); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_paste_desc", "Paste", "", false); - - // Get element - elm = tinyMCE.getParentElement(elm, "img,table,td"); - if (elm) { - switch (elm.nodeName) { - case "IMG": - contextMenu.addSeparator(); - - // If flash - if (tinyMCE.getAttrib(elm, 'class').indexOf('mceItemFlash') == 0) - contextMenu.addItem(tinyMCE.baseURL + "/plugins/flash/images/flash.gif", "$lang_flash_props", "mceFlash"); - else - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/image.gif", "$lang_image_props_desc", typeof(TinyMCE_advimage_getControlHTML) != "undefined" ? "mceAdvImage" : "mceImage"); - break; - - case "TABLE": - case "TD": - // Is table plugin loaded - if (typeof(TinyMCE_table_getControlHTML) != "undefined") { - var colspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "colspan"); - var rowspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "rowspan"); - - colspan = colspan == "" ? "1" : colspan; - rowspan = rowspan == "" ? "1" : rowspan; - - contextMenu.addSeparator(); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_table_cut_row_desc", "mceTableCutRow"); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_table_copy_row_desc", "mceTableCopyRow"); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_before_desc", "mceTablePasteRowBefore", "", inst.tableRowClipboard == null); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_after_desc", "mceTablePasteRowAfter", "", inst.tableRowClipboard == null); - -/* contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyleft.gif", "$lang_justifyleft_desc", "JustifyLeft", "", false); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifycenter.gif", "$lang_justifycenter_desc", "JustifyCenter", "", false); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyright.gif", "$lang_justifyright_desc", "JustifyRight", "", false); - contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/justifyfull.gif", "$lang_justifyfull_desc", "JustifyFull", "", false);*/ - contextMenu.addSeparator(); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_props_desc", "mceInsertTable"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_cell_props.gif", "$lang_table_cell_desc", "mceTableCellProps"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete.gif", "$lang_table_del", "mceTableDelete"); - contextMenu.addSeparator(); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_row_props.gif", "$lang_table_row_desc", "mceTableRowProps"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_before.gif", "$lang_table_row_before_desc", "mceTableInsertRowBefore"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_after.gif", "$lang_table_row_after_desc", "mceTableInsertRowAfter"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_row.gif", "$lang_table_delete_row_desc", "mceTableDeleteRow"); - contextMenu.addSeparator(); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_before.gif", "$lang_table_col_before_desc", "mceTableInsertColBefore"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_after.gif", "$lang_table_col_after_desc", "mceTableInsertColAfter"); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_col.gif", "$lang_table_delete_col_desc", "mceTableDeleteCol"); - contextMenu.addSeparator(); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_split_cells.gif", "$lang_table_split_cells_desc", "mceTableSplitCells", "", (colspan == "1" && rowspan == "1")); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_merge_cells.gif", "$lang_table_merge_cells_desc", "mceTableMergeCells", "", false); - } - break; - } - } else { - // Add table specific - if (typeof(TinyMCE_table_getControlHTML) != "undefined") { - contextMenu.addSeparator(); - contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert"); + if ((el.nodeName == 'A' && !ed.dom.getAttrib(el, 'name')) || !col) { + m.addSeparator(); + m.add({title : 'advanced.link_desc', icon : 'link', cmd : ed.plugins.advlink ? 'mceAdvLink' : 'mceLink', ui : true}); + m.add({title : 'advanced.unlink_desc', icon : 'unlink', cmd : 'UnLink'}); } - } - - contextMenu.show(x, y); - }, 10); - - // Cancel default handeling - tinyMCE.cancelEvent(e); - return false; -} - -function TinyMCE_contextmenu_hideContextMenu() { - TinyMCE_contextmenu_contextMenu.hide(); -} - -function TinyMCE_contextmenu_commandHandler(command, value) { - TinyMCE_contextmenu_contextMenu.hide(); - - // UI must be true on these - var ui = false; - if (command == "mceInsertTable" || command == "mceTableCellProps" || command == "mceTableRowProps" || command == "mceTableMergeCells") - ui = true; - - if (command == "Paste") - value = null; - TinyMCE_contextmenu_contextMenu.inst.execCommand(command, ui, value); -} + m.addSeparator(); + m.add({title : 'advanced.image_desc', icon : 'image', cmd : ed.plugins.advimage ? 'mceAdvImage' : 'mceImage', ui : true}); -// Context menu class + m.addSeparator(); + am = m.addMenu({title : 'contextmenu.align'}); + am.add({title : 'contextmenu.left', icon : 'justifyleft', cmd : 'JustifyLeft'}); + am.add({title : 'contextmenu.center', icon : 'justifycenter', cmd : 'JustifyCenter'}); + am.add({title : 'contextmenu.right', icon : 'justifyright', cmd : 'JustifyRight'}); + am.add({title : 'contextmenu.full', icon : 'justifyfull', cmd : 'JustifyFull'}); -function ContextMenu(settings) { - // Default value function - function defParam(key, def_val) { - settings[key] = typeof(settings[key]) != "undefined" ? settings[key] : def_val; - } + t.onContextMenu.dispatch(t, m, el, col); - var self = this; - - this.isMSIE = (navigator.appName == "Microsoft Internet Explorer"); - - // Setup contextmenu div - this.contextMenuDiv = document.createElement("div"); - this.contextMenuDiv.className = "contextMenu"; - this.contextMenuDiv.setAttribute("class", "contextMenu"); - this.contextMenuDiv.style.display = "none"; - this.contextMenuDiv.style.position = 'absolute'; - this.contextMenuDiv.style.zindex = 1000; - this.contextMenuDiv.style.left = '0px'; - this.contextMenuDiv.style.top = '0px'; - this.contextMenuDiv.unselectable = "on"; - - document.body.appendChild(this.contextMenuDiv); - - // Setup default values - defParam("commandhandler", ""); - defParam("spacer_image", "images/spacer.gif"); - - this.items = new Array(); - this.settings = settings; - this.html = ""; - - // IE Popup - if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) { - this.pop = window.createPopup(); - doc = this.pop.document; - doc.open(); - doc.write(''); - doc.close(); - } -}; - -ContextMenu.prototype.clearAll = function() { - this.html = ""; - this.contextMenuDiv.innerHTML = ""; -}; - -ContextMenu.prototype.addSeparator = function() { - this.html += ''; -}; - -ContextMenu.prototype.addItem = function(icon, title, command, value, disabled) { - if (title.charAt(0) == '$') - title = tinyMCE.getLang(title.substring(1)); - - var onMouseDown = ''; - var html = ''; - - if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0) - onMouseDown = 'contextMenu.execCommand(\'' + command + '\', \'' + value + '\');return false;'; - else - onMouseDown = this.settings['commandhandler'] + '(\'' + command + '\', \'' + value + '\');return false;'; - - if (icon == "") - icon = this.settings['spacer_image']; - - if (!disabled) - html += ''; - else - html += ''; - - html += ''; - html += '
'; - - // Add text - html += title; - - html += '
'; - html += ''; - - // Add to main - this.html += html; -}; - -ContextMenu.prototype.show = function(x, y) { - if (this.html == "") - return; - - var html = ''; - - html += ''; - html += this.html; - html += '
'; - - this.contextMenuDiv.innerHTML = html; - - if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) { - var width, height; - - // Get dimensions - this.contextMenuDiv.style.display = "block"; - width = this.contextMenuDiv.offsetWidth; - height = this.contextMenuDiv.offsetHeight; - this.contextMenuDiv.style.display = "none"; - - // Setup popup and show - this.pop.document.body.innerHTML = '
' + html + "
"; - this.pop.document.tinyMCE = tinyMCE; - this.pop.document.contextMenu = this; - this.pop.show(x, y, width, height); - } else { - this.contextMenuDiv.style.left = x + 'px'; - this.contextMenuDiv.style.top = y + 'px'; - this.contextMenuDiv.style.display = "block"; - } -}; - -ContextMenu.prototype.hide = function() { - if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0 && !tinyMCE.isOpera) - this.pop.hide(); - else - this.contextMenuDiv.style.display = "none"; -}; + return m; + } + }); -ContextMenu.prototype.execCommand = function(command, value) { - eval(this.settings['commandhandler'] + "(command, value);"); -}; + // Register plugin + tinymce.PluginManager.add('contextmenu', tinymce.plugins.ContextMenu); +})();