1 /* Import plugin specific language pack */
2 //tinyMCE.importPluginLanguagePack('contextmenu', 'en,zh_cn,cs,fa,fr_ca,fr,de,no');
3 if (!tinyMCE.settings['contextmenu_skip_plugin_css'])
4 tinyMCE.loadCSS(tinyMCE.baseURL + "/plugins/contextmenu/css/contextmenu.css");
6 // Global contextmenu class instance
7 var TinyMCE_contextmenu_contextMenu = null;
9 function TinyMCE_contextmenu_getInfo() {
11 longname : 'Context menus',
12 author : 'Moxiecode Systems',
13 authorurl : 'http://tinymce.moxiecode.com',
14 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_contextmenu.html',
15 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
19 function TinyMCE_contextmenu_initInstance(inst) {
20 // Is not working on MSIE 5.0
21 if (tinyMCE.isMSIE5_0)
24 // Add hide event handles
25 tinyMCE.addEvent(inst.getDoc(), "click", TinyMCE_contextmenu_hideContextMenu);
26 tinyMCE.addEvent(inst.getDoc(), "keypress", TinyMCE_contextmenu_hideContextMenu);
27 tinyMCE.addEvent(inst.getDoc(), "keydown", TinyMCE_contextmenu_hideContextMenu);
28 tinyMCE.addEvent(document, "click", TinyMCE_contextmenu_hideContextMenu);
29 tinyMCE.addEvent(document, "keypress", TinyMCE_contextmenu_hideContextMenu);
30 tinyMCE.addEvent(document, "keydown", TinyMCE_contextmenu_hideContextMenu);
32 var contextMenu = new ContextMenu({
33 commandhandler : "TinyMCE_contextmenu_commandHandler",
34 spacer_image : tinyMCE.baseURL + "/plugins/contextmenu/images/spacer.gif"
37 // Register global reference
38 TinyMCE_contextmenu_contextMenu = contextMenu;
40 // Attach contextmenu event
41 if (tinyMCE.isGecko) {
42 tinyMCE.addEvent(inst.getDoc(), "contextmenu", function(e) {TinyMCE_contextmenu_showContextMenu(tinyMCE.isMSIE ? inst.contentWindow.event : e, inst);});
44 tinyMCE.addEvent(inst.getDoc(), "contextmenu", TinyMCE_contextmenu_onContextMenu);
47 function TinyMCE_contextmenu_onContextMenu(e) {
48 var elm = tinyMCE.isMSIE ? e.srcElement : e.target;
52 if ((body = tinyMCE.getParentElement(elm, "body")) != null) {
53 for (var n in tinyMCE.instances) {
54 var inst = tinyMCE.instances[n];
56 if (body == inst.getBody()) {
62 return TinyMCE_contextmenu_showContextMenu(tinyMCE.isMSIE ? targetInst.contentWindow.event : e, targetInst);
66 function TinyMCE_contextmenu_showContextMenu(e, inst) {
67 function getAttrib(elm, name) {
68 return elm.getAttribute(name) ? elm.getAttribute(name) : "";
71 var x, y, elm, contextMenu;
72 var pos = tinyMCE.getAbsPosition(inst.iframeElement);
74 x = tinyMCE.isMSIE ? e.screenX : pos.absLeft + (e.pageX - inst.getBody().scrollLeft);
75 y = tinyMCE.isMSIE ? e.screenY : pos.absTop + (e.pageY - inst.getBody().scrollTop);
76 elm = tinyMCE.isMSIE ? e.srcElement : e.target;
77 contextMenu = TinyMCE_contextmenu_contextMenu;
78 contextMenu.inst = inst;
80 // Mozilla needs some time
81 window.setTimeout(function () {
82 var theme = tinyMCE.getParam("theme");
84 contextMenu.clearAll();
85 var sel = inst.getSelectedText().length != 0 || elm.nodeName == "IMG";
88 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_cut_desc", "Cut", "", !sel);
89 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_copy_desc", "Copy", "", !sel);
90 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_paste_desc", "Paste", "", false);
93 elm = tinyMCE.getParentElement(elm, "img,table,td");
95 switch (elm.nodeName) {
97 contextMenu.addSeparator();
100 if (tinyMCE.getAttrib(elm, 'class').indexOf('mceItemFlash') == 0)
101 contextMenu.addItem(tinyMCE.baseURL + "/plugins/flash/images/flash.gif", "$lang_flash_props", "mceFlash");
103 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/image.gif", "$lang_image_props_desc", typeof(TinyMCE_advimage_getControlHTML) != "undefined" ? "mceAdvImage" : "mceImage");
108 // Is table plugin loaded
109 if (typeof(TinyMCE_table_getControlHTML) != "undefined") {
110 var colspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "colspan");
111 var rowspan = (elm.nodeName == "TABLE") ? "" : getAttrib(elm, "rowspan");
113 colspan = colspan == "" ? "1" : colspan;
114 rowspan = rowspan == "" ? "1" : rowspan;
116 contextMenu.addSeparator();
117 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/cut.gif", "$lang_table_cut_row_desc", "mceTableCutRow");
118 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/copy.gif", "$lang_table_copy_row_desc", "mceTableCopyRow");
119 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_before_desc", "mceTablePasteRowBefore", "", inst.tableRowClipboard == null);
120 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/paste.gif", "$lang_table_paste_row_after_desc", "mceTablePasteRowAfter", "", inst.tableRowClipboard == null);
122 /* contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/left.gif", "$lang_justifyleft_desc", "JustifyLeft", "", false);
123 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/center.gif", "$lang_justifycenter_desc", "JustifyCenter", "", false);
124 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/right.gif", "$lang_justifyright_desc", "JustifyRight", "", false);
125 contextMenu.addItem(tinyMCE.baseURL + "/themes/" + theme + "/images/full.gif", "$lang_justifyfull_desc", "JustifyFull", "", false);*/
126 contextMenu.addSeparator();
127 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert");
128 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_props_desc", "mceInsertTable");
129 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_cell_props.gif", "$lang_table_cell_desc", "mceTableCellProps");
130 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete.gif", "$lang_table_del", "mceTableDelete");
131 contextMenu.addSeparator();
132 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_row_props.gif", "$lang_table_row_desc", "mceTableRowProps");
133 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_before.gif", "$lang_table_row_before_desc", "mceTableInsertRowBefore");
134 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_row_after.gif", "$lang_table_row_after_desc", "mceTableInsertRowAfter");
135 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_row.gif", "$lang_table_delete_row_desc", "mceTableDeleteRow");
136 contextMenu.addSeparator();
137 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_before.gif", "$lang_table_col_before_desc", "mceTableInsertColBefore");
138 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_insert_col_after.gif", "$lang_table_col_after_desc", "mceTableInsertColAfter");
139 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_delete_col.gif", "$lang_table_delete_col_desc", "mceTableDeleteCol");
140 contextMenu.addSeparator();
141 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_split_cells.gif", "$lang_table_split_cells_desc", "mceTableSplitCells", "", (colspan == "1" && rowspan == "1"));
142 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table_merge_cells.gif", "$lang_table_merge_cells_desc", "mceTableMergeCells", "", false);
147 // Add table specific
148 if (typeof(TinyMCE_table_getControlHTML) != "undefined") {
149 contextMenu.addSeparator();
150 contextMenu.addItem(tinyMCE.baseURL + "/plugins/table/images/table.gif", "$lang_table_desc", "mceInsertTable", "insert");
154 contextMenu.show(x, y);
157 // Cancel default handeling
158 tinyMCE.cancelEvent(e);
162 function TinyMCE_contextmenu_hideContextMenu() {
163 TinyMCE_contextmenu_contextMenu.hide();
168 function TinyMCE_contextmenu_commandHandler(command, value) {
169 TinyMCE_contextmenu_contextMenu.hide();
171 // UI must be true on these
173 if (command == "mceInsertTable" || command == "mceTableCellProps" || command == "mceTableRowProps" || command == "mceTableMergeCells")
176 if (command == "Paste")
179 TinyMCE_contextmenu_contextMenu.inst.execCommand(command, ui, value);
182 // Context menu class
184 function ContextMenu(settings) {
185 // Default value function
186 function defParam(key, def_val) {
187 settings[key] = typeof(settings[key]) != "undefined" ? settings[key] : def_val;
192 this.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
194 // Setup contextmenu div
195 this.contextMenuDiv = document.createElement("div");
196 this.contextMenuDiv.className = "contextMenu";
197 this.contextMenuDiv.setAttribute("class", "contextMenu");
198 this.contextMenuDiv.style.display = "none";
199 this.contextMenuDiv.style.position = 'absolute';
200 this.contextMenuDiv.style.zindex = 1000;
201 this.contextMenuDiv.style.left = '0px';
202 this.contextMenuDiv.style.top = '0px';
203 this.contextMenuDiv.unselectable = "on";
205 document.body.appendChild(this.contextMenuDiv);
207 // Setup default values
208 defParam("commandhandler", "");
209 defParam("spacer_image", "images/spacer.gif");
211 this.items = new Array();
212 this.settings = settings;
216 if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0) {
217 this.pop = window.createPopup();
218 doc = this.pop.document;
220 doc.write('<html><head><link href="' + tinyMCE.baseURL + '/plugins/contextmenu/css/contextmenu.css" rel="stylesheet" type="text/css" /></head><body unselectable="yes" class="contextMenuIEPopup"></body></html>');
225 ContextMenu.prototype.clearAll = function() {
227 this.contextMenuDiv.innerHTML = "";
230 ContextMenu.prototype.addSeparator = function() {
231 this.html += '<tr class="contextMenuItem"><td class="contextMenuIcon"><img src="' + this.settings['spacer_image'] + '" width="20" height="1" class="contextMenuImage" /></td><td><img class="contextMenuSeparator" width="1" height="1" src="' + this.settings['spacer_image'] + '" /></td></tr>';
234 ContextMenu.prototype.addItem = function(icon, title, command, value, disabled) {
235 if (title.charAt(0) == '$')
236 title = tinyMCE.getLang(title.substring(1));
238 var onMouseDown = '';
241 if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0)
242 onMouseDown = 'contextMenu.execCommand(\'' + command + '\', \'' + value + '\');return false;';
244 onMouseDown = this.settings['commandhandler'] + '(\'' + command + '\', \'' + value + '\');return false;';
247 icon = this.settings['spacer_image'];
250 html += '<tr class="contextMenuItem" onmousedown="' + onMouseDown + '" onmouseover="tinyMCE.switchClass(this,\'contextMenuItemOver\');" onmouseout="tinyMCE.switchClass(this,\'contextMenuItem\');">';
252 html += '<tr class="contextMenuItemDisabled">';
254 html += '<td class="contextMenuIcon"><img src="' + icon + '" width="20" height="20" class="contextMenuImage" /></td>';
255 html += '<td><div class="contextMenuText">';
260 html += '</div></td>';
267 ContextMenu.prototype.show = function(x, y) {
273 html += '<table border="0" cellpadding="0" cellspacing="0">';
277 this.contextMenuDiv.innerHTML = html;
279 if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0) {
283 this.contextMenuDiv.style.display = "block";
284 width = this.contextMenuDiv.offsetWidth;
285 height = this.contextMenuDiv.offsetHeight;
286 this.contextMenuDiv.style.display = "none";
288 // Setup popup and show
289 this.pop.document.body.innerHTML = '<div class="contextMenu">' + html + "</div>";
290 this.pop.document.tinyMCE = tinyMCE;
291 this.pop.document.contextMenu = this;
292 this.pop.show(x, y, width, height);
294 this.contextMenuDiv.style.left = x + 'px';
295 this.contextMenuDiv.style.top = y + 'px';
296 this.contextMenuDiv.style.display = "block";
300 ContextMenu.prototype.hide = function() {
301 if (tinyMCE.isMSIE && !tinyMCE.isMSIE5_0)
304 this.contextMenuDiv.style.display = "none";
307 ContextMenu.prototype.execCommand = function(command, value) {
308 eval(this.settings['commandhandler'] + "(command, value);");