ContextMenu.prototype.getContextMenu = function()

in blocks/cocoon-forms/cocoon-forms-impl/src/main/resources/org/apache/cocoon/forms/resources/htmlarea/plugins/ContextMenu/context-menu.js [38:219]


ContextMenu.prototype.getContextMenu = function(target) {
	var self = this;
	var editor = this.editor;
	var config = editor.config;
	var menu = [];
	var tbo = this.editor.plugins.TableOperations;
	if (tbo) tbo = tbo.instance;
	var i18n = ContextMenu.I18N;

	var selection = editor.hasSelectedText();
	if (selection)
		menu.push([ i18n["Cut"], function() { editor.execCommand("cut"); }, null, config.btnList["cut"][1] ],
			  [ i18n["Copy"], function() { editor.execCommand("copy"); }, null, config.btnList["copy"][1] ]);
	menu.push([ i18n["Paste"], 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 img = null;

	function tableOperation(opcode) {
		tbo.buttonPress(editor, opcode);
	};

	for (; target; target = target.parentNode) {
		var tag = target.tagName;
		if (!tag)
			continue;
		tag = tag.toLowerCase();
		switch (tag) {
		    case "img":
			img = target;
			elmenus.push(null,
				     [ i18n["Image Properties"],
				       function() {
					       editor._insertImage(img);
				       },
				       i18n["Show the image properties dialog"],
				       config.btnList["insertimage"][1] ]
				);
			break;
		    case "a":
			link = target;
			elmenus.push(null,
				     [ i18n["Modify Link"],
				       function() { editor.execCommand("createlink", true); },
				       i18n["Current URL is"] + ': ' + link.href,
				       config.btnList["createlink"][1] ],

				     [ i18n["Check Link"],
				       function() { window.open(link.href); },
				       i18n["Opens this link in a new window"] ],

				     [ i18n["Remove Link"],
				       function() {
					       if (confirm(i18n["Please confirm that you want to unlink this element."] + "\n" +
							   i18n["Link points to:"] + " " + link.href)) {
						       while (link.firstChild)
							       link.parentNode.insertBefore(link.firstChild, link);
						       link.parentNode.removeChild(link);
					       }
				       },
				       i18n["Unlink the current element"] ]
				);
			break;
		    case "td":
			td = target;
			if (!tbo) break;
			elmenus.push(null,
				     [ i18n["Cell Properties"],
				       function() { tableOperation("TO-cell-prop"); },
				       i18n["Show the Table Cell Properties dialog"],
				       config.btnList["TO-cell-prop"][1] ]
				);
			break;
		    case "tr":
			tr = target;
			if (!tbo) break;
			elmenus.push(null,
				     [ i18n["Row Properties"],
				       function() { tableOperation("TO-row-prop"); },
				       i18n["Show the Table Row Properties dialog"],
				       config.btnList["TO-row-prop"][1] ],

				     [ i18n["Insert Row Before"],
				       function() { tableOperation("TO-row-insert-above"); },
				       i18n["Insert a new row before the current one"],
				       config.btnList["TO-row-insert-above"][1] ],

				     [ i18n["Insert Row After"],
				       function() { tableOperation("TO-row-insert-under"); },
				       i18n["Insert a new row after the current one"],
				       config.btnList["TO-row-insert-under"][1] ],

				     [ i18n["Delete Row"],
				       function() { tableOperation("TO-row-delete"); },
				       i18n["Delete the current row"],
				       config.btnList["TO-row-delete"][1] ]
				);
			break;
		    case "table":
			table = target;
			if (!tbo) break;
			elmenus.push(null,
				     [ i18n["Table Properties"],
				       function() { tableOperation("TO-table-prop"); },
				       i18n["Show the Table Properties dialog"],
				       config.btnList["TO-table-prop"][1] ],

				     [ i18n["Insert Column Before"],
				       function() { tableOperation("TO-col-insert-before"); },
				       i18n["Insert a new column before the current one"],
				       config.btnList["TO-col-insert-before"][1] ],

				     [ i18n["Insert Column After"],
				       function() { tableOperation("TO-col-insert-after"); },
				       i18n["Insert a new column after the current one"],
				       config.btnList["TO-col-insert-after"][1] ],

				     [ i18n["Delete Column"],
				       function() { tableOperation("TO-col-delete"); },
				       i18n["Delete the current column"],
				       config.btnList["TO-col-delete"][1] ]
				);
			break;
		    case "body":
			elmenus.push(null,
				     [ i18n["Justify Left"],
				       function() { editor.execCommand("justifyleft"); }, null,
				       config.btnList["justifyleft"][1] ],
				     [ i18n["Justify Center"],
				       function() { editor.execCommand("justifycenter"); }, null,
				       config.btnList["justifycenter"][1] ],
				     [ i18n["Justify Right"],
				       function() { editor.execCommand("justifyright"); }, null,
				       config.btnList["justifyright"][1] ],
				     [ i18n["Justify Full"],
				       function() { editor.execCommand("justifyfull"); }, null,
				       config.btnList["justifyfull"][1] ]
				);
			break;
		}
	}

	if (selection && !link)
		menu.push(null, [ i18n["Make link"],
				  function() { editor.execCommand("createlink", true); },
				  i18n["Create a link"],
				  config.btnList["createlink"][1] ]);

	for (var i in elmenus)
		menu.push(elmenus[i]);

	menu.push(null,
		  [ i18n["Remove the"] + " <" + currentTarget.tagName + "> " + i18n["Element"],
		    function() {
			    if (confirm(i18n["Please confirm that you want to remove this element:"] + " " + currentTarget.tagName)) {
				    var el = currentTarget;
				    var p = el.parentNode;
				    p.removeChild(el);
				    if (HTMLArea.is_gecko) {
					    if (p.tagName.toLowerCase() == "td" && !p.hasChildNodes())
						    p.appendChild(editor._doc.createElement("br"));
					    editor.forceRedraw();
					    editor.focusEditor();
					    editor.updateToolbar();
					    if (table) {
						    var save_collapse = table.style.borderCollapse;
						    table.style.borderCollapse = "collapse";
						    table.style.borderCollapse = "separate";
						    table.style.borderCollapse = save_collapse;
					    }
				    }
			    }
		    },
		    i18n["Remove this node from the document"] ]);
	return menu;
};