📄 advanced-context-menu.js
字号:
// Context Menu Plugin for HippoCMS
HTMLArea.loadStyle("menu.css", "AdvancedContextMenu");
function AdvancedContextMenu(editor) {
this.editor = editor;
}
AdvancedContextMenu._pluginInfo = {
name : "AdvancedContextMenu",
version : "1.0",
developer : "Jeroen Reijn",
developer_url : "http://www.hippo.nl/",
license : "Apache 2.0 License"
};
AdvancedContextMenu.prototype.onGenerate = function() {
var self = this;
var doc = this.editordoc = this.editor._iframe.contentWindow.document;
HTMLArea._addEvents(doc, ["contextmenu"],
function (event) {
return self.popupMenu(HTMLArea.is_ie ? self.editor._iframe.contentWindow.event : event);
});
this.currentMenu = null;
};
AdvancedContextMenu.prototype.getContextMenu = function(target) {
var self = this;
var editor = this.editor;
var config = editor.config;
var menu = [];
var tbo = this.editor.plugins.AdvancedTableOperations;
if (tbo) tbo = tbo.instance;
var selection = editor.hasSelectedText();
if (selection)
menu.push([ HTMLArea._lc("Cut", "AdvancedContextMenu"), function() { editor.execCommand("cut"); }, null, config.btnList["cut"][1] ],
[ HTMLArea._lc("Copy", "AdvancedContextMenu"), function() { editor.execCommand("copy"); }, null, config.btnList["copy"][1] ]);
menu.push([ HTMLArea._lc("Paste", "AdvancedContextMenu"), function() { editor.execCommand("paste"); }, null, config.btnList["paste"][1] ]);
var currentTarget = target;
var elmenus = [];
var link = null;
var table = null;
var tr = null;
var td = null;
var th = null;
var img = null;
function tableOperation(opcode) {
tbo.buttonPress(editor, opcode);
}
function insertPara(after) {
var el = currentTarget;
var par = el.parentNode;
var p = editor._doc.createElement("p");
p.appendChild(editor._doc.createElement("br"));
par.insertBefore(p, after ? el.nextSibling : el);
var sel = editor._getSelection();
var range = editor._createRange(sel);
if (!HTMLArea.is_ie) {
sel.removeAllRanges();
range.selectNodeContents(p);
range.collapse(true);
sel.addRange(range);
} else {
range.moveToElementText(p);
range.collapse(true);
range.select();
}
}
for (; target; target = target.parentNode) {
var tag = target.tagName;
if (!tag)
continue;
tag = tag.toLowerCase();
switch (tag) {
case "img":
img = target;
elmenus.push(null,
[ HTMLArea._lc("_Image Properties...", "AdvancedContextMenu"),
function() {
editor._insertImage(img);
},
HTMLArea._lc("Show the image properties dialog", "AdvancedContextMenu"),
config.btnList["insertimage"][1] ]
);
break;
case "a":
link = target;
elmenus.push(null,
[ HTMLArea._lc("_Modify Link...", "AdvancedContextMenu"),
function() { editor.config.btnList['createlink'][3](editor); },
HTMLArea._lc("Current URL is", "AdvancedContextMenu") + ': ' + link.href,
config.btnList["createlink"][1] ],
[ HTMLArea._lc("Chec_k Link...", "AdvancedContextMenu"),
function() { window.open(link.href); },
HTMLArea._lc("Opens this link in a new window", "AdvancedContextMenu") ],
[ HTMLArea._lc("_Remove Link...", "ContextMenu"),
function() {
if (confirm(HTMLArea._lc("Please confirm that you want to unlink this element.", "AdvancedContextMenu") + "\n" +
HTMLArea._lc("Link points to:", "AdvancedContextMenu") + " " + link.href)) {
while (link.firstChild)
link.parentNode.insertBefore(link.firstChild, link);
link.parentNode.removeChild(link);
}
},
HTMLArea._lc("Unlink the current element", "AdvancedContextMenu") ]
);
break;
case "td":
td = target;
if (!tbo) break;
elmenus.push(null,
[ HTMLArea._lc("C_ell Properties...", "AdvancedContextMenu"),
function() { tableOperation("TO-cell-prop"); },
HTMLArea._lc("Show the Table Cell Properties dialog", "AdvancedContextMenu"),
config.btnList["TO-cell-prop"][1] ]
);
break;
case "th":
th = target;
if (!tbo) break;
elmenus.push(null,
[ HTMLArea._lc("C_ell Properties...", "AdvancedContextMenu"),
function() { tableOperation("TO-cell-prop"); },
HTMLArea._lc("Show the Table Cell Properties dialog", "AdvancedContextMenu"),
config.btnList["TO-cell-prop"][1] ]
);
break;
case "tr":
tr = target;
if (!tbo) break;
elmenus.push(null,
[ HTMLArea._lc("Ro_w Properties...", "AdvancedContextMenu"),
function() { tableOperation("TO-row-prop"); },
HTMLArea._lc("Show the Table Row Properties dialog", "AdvancedContextMenu"),
config.btnList["TO-row-prop"][1] ],
[ HTMLArea._lc("I_nsert Row Before", "AdvancedContextMenu"),
function() { tableOperation("TO-row-insert-above"); },
HTMLArea._lc("Insert a new row before the current one", "AdvancedContextMenu"),
config.btnList["TO-row-insert-above"][1] ],
[ HTMLArea._lc("In_sert Row After", "AdvancedContextMenu"),
function() { tableOperation("TO-row-insert-under"); },
HTMLArea._lc("Insert a new row after the current one", "AdvancedContextMenu"),
config.btnList["TO-row-insert-under"][1] ],
[ HTMLArea._lc("_Delete Row", "AdvancedContextMenu"),
function() { tableOperation("TO-row-delete"); },
HTMLArea._lc("Delete the current row", "AdvancedContextMenu"),
config.btnList["TO-row-delete"][1] ]
);
break;
case "table":
table = target;
if (!tbo) break;
elmenus.push(null,
[ HTMLArea._lc("_Table Properties...", "AdvancedContextMenu"),
function() { tableOperation("TO-table-prop"); },
HTMLArea._lc("Show the Table Properties dialog", "AdvancedContextMenu"),
config.btnList["TO-table-prop"][1] ],
[ HTMLArea._lc("Insert _Column Before", "AdvancedContextMenu"),
function() { tableOperation("TO-col-insert-before"); },
HTMLArea._lc("Insert a new column before the current one", "AdvancedContextMenu"),
config.btnList["TO-col-insert-before"][1] ],
[ HTMLArea._lc("Insert C_olumn After", "AdvancedContextMenu"),
function() { tableOperation("TO-col-insert-after"); },
HTMLArea._lc("Insert a new column after the current one", "AdvancedContextMenu"),
config.btnList["TO-col-insert-after"][1] ],
[ HTMLArea._lc("De_lete Column", "AdvancedContextMenu"),
function() { tableOperation("TO-col-delete"); },
HTMLArea._lc("Delete the current column", "AdvancedContextMenu"),
config.btnList["TO-col-delete"][1] ]
);
break;
case "body":
elmenus.push(null,
[ HTMLArea._lc("Justify Left", "AdvancedContextMenu"),
function() { editor.execCommand("justifyleft"); }, null,
config.btnList["justifyleft"][1] ],
[ HTMLArea._lc("Justify Center", "AdvancedContextMenu"),
function() { editor.execCommand("justifycenter"); }, null,
config.btnList["justifycenter"][1] ],
[ HTMLArea._lc("Justify Right", "AdvancedContextMenu"),
function() { editor.execCommand("justifyright"); }, null,
config.btnList["justifyright"][1] ],
[ HTMLArea._lc("Justify Full", "AdvancedContextMenu"),
function() { editor.execCommand("justifyfull"); }, null,
config.btnList["justifyfull"][1] ]
);
break;
}
}
if (selection && !link)
menu.push(null, [ HTMLArea._lc("Make lin_k...", "AdvancedContextMenu"),
function() { editor.config.btnList['createlink'][3](editor); },
HTMLArea._lc("Create a link", "AdvancedContextMenu"),
config.btnList["createlink"][1] ]);
for (var i = 0; i < elmenus.length; ++i)
menu.push(elmenus[i]);
if (!/html|body/i.test(currentTarget.tagName))
menu.push(null,
[ HTMLArea._lc({string: "Remove the $elem Element...", replace: {elem: "<" + currentTarget.tagName + ">"}}, "AdvancedContextMenu"),
function() {
if (confirm(HTMLArea._lc("Please confirm that you want to remove this element:", "AdvancedContextMenu") + " " +
currentTarget.tagName)) {
var el = currentTarget;
var p = el.parentNode;
p.removeChild(el);
if (HTMLArea.is_gecko) {
if (p.tagName.toLowerCase() == "td" && !p.hasChildNodes())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -