/* * Copyright (c) 2009 Gregory Stoll * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * */ var thumbnailcopy = { onLoad: function() { // initialization code this.initialized = true; //this.strings = document.getElementById("thumbnailcopy-strings"); var contextMenu = document.getElementById("contentAreaContextMenu"); if (contextMenu) contextMenu.addEventListener("popupshowing", this.showHideContextStuff, false); }, showHideContextStuff: function(e) { var item = document.getElementById("thumbnailcopy-copy"); var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); var toShow = false; if (document.popupNode.localName.toUpperCase() == "IMG") { var parentNode = document.popupNode.parentNode; if (parentNode != null && parentNode.localName.toUpperCase() == "A" && (parentNode.hasAttribute("HREF") || parentNode.hasAttribute('href'))) { toShow = true; } } item.hidden = !toShow; //promptService.alert(window, "", document.popupNode.localName); }, doCopy: function() { var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); // Make sure we have a parent node and all that. var canCopy = false; if (document.popupNode.localName.toUpperCase() == "IMG") { var parentNode = document.popupNode.parentNode; if (parentNode != null && parentNode.localName.toUpperCase() == "A" && (parentNode.hasAttribute("HREF") || parentNode.hasAttribute('href'))) { canCopy = true; var imgHtml = '' + imgHtml + ''; // Copy the HTML to the clipboard. var clipboardService = Components.classes["@mozilla.org/widget/clipboardhelper;1"] .getService(Components.interfaces.nsIClipboardHelper); clipboardService.copyString(html); } } } }; window.addEventListener("load", function(e) { thumbnailcopy.onLoad(e); }, false);