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