/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const MathMLNS = "http://www.w3.org/1998/Math/MathML";
const XLinkNS = "http://www.w3.org/1999/xlink";
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const XMLNS = "http://www.w3.org/XML/1998/namespace";
const XHTMLNS = "http://www.w3.org/1999/xhtml";
var gMetadataBundle;
var gLangBundle;
var gRegionBundle;
var nodeView;
var htmlMode = false;
var onLink = false;
var onImage = false;
var onInsDel = false;
var onQuote = false;
var onMisc = false;
var onTable = false;
var onTitle = false;
var onLang = false;
function onLoad()
{
gMetadataBundle = document.getElementById("bundle_metadata");
gLangBundle = document.getElementById("bundle_languages");
gRegionBundle = document.getElementById("bundle_regions");
showMetadataFor(window.arguments[0]);
nodeView = window.arguments[0].ownerDocument.defaultView;
}
function showMetadataFor(elem)
{
// skip past non-element nodes
while (elem && elem.nodeType != Node.ELEMENT_NODE)
elem = elem.parentNode;
if (!elem) {
alert(gMetadataBundle.getString("unableToShowProps"));
window.close();
}
if (elem.ownerDocument.getElementsByName && !elem.ownerDocument.namespaceURI)
htmlMode = true;
// htmllocalname is "" if it's not an html tag, or the name of the tag if it is.
var htmllocalname = "";
if (isHTMLElement(elem,"")) {
htmllocalname = elem.localName.toLowerCase();
}
// We only look for images once
checkForImage(elem, htmllocalname);
// Walk up the tree, looking for elements of interest.
// Each of them could be at a different level in the tree, so they each
// need their own boolean to tell us to stop looking.
while (elem && elem.nodeType == Node.ELEMENT_NODE) {
htmllocalname = "";
if (isHTMLElement(elem,"")) {
htmllocalname = elem.localName.toLowerCase();
}
if (!onLink) checkForLink(elem, htmllocalname);
if (!onInsDel) checkForInsDel(elem, htmllocalname);
if (!onQuote) checkForQuote(elem, htmllocalname);
if (!onTable) checkForTable(elem, htmllocalname);
if (!onTitle) checkForTitle(elem, htmllocalname);
if (!onLang) checkForLang(elem, htmllocalname);
elem = elem.parentNode;
}
// Decide which sections to show
var onMisc = onTable || onTitle || onLang;
if (!onMisc) hideNode("misc-sec");
if (!onLink) hideNode("link-sec");
if (!onImage) hideNode("image-sec");
if (!onInsDel) hideNode("insdel-sec");
if (!onQuote) hideNode("quote-sec");
// Fix the Misc section visibilities
if (onMisc) {
if (!onTable) hideNode("misc-tblsummary");
if (!onLang) hideNode("misc-lang");
if (!onTitle) hideNode("misc-title");
}
// Get rid of the "No properties" message. This is a backstop -
// it should really never show, as long as nsContextMenu.js's
// checking doesn't get broken.
if (onLink || onImage || onInsDel || onQuote || onMisc)
hideNode("no-properties")
}
var cacheListener = {
onCacheEntryAvailable: function onCacheEntryAvailable(descriptor) {
if (descriptor) {
var kbSize = descriptor.dataSize / 1024;
kbSize = Math.round(kbSize * 100) / 100;
setInfo("image-filesize", gMetadataBundle.getFormattedString("imageSize",
[formatNumber(kbSize),
formatNumber(descriptor.dataSize)]));
} else {
setInfo("image-filesize", gMetadataBundle.getString("imageSizeUnknown"));
}
},
onCacheEntryCheck: function onCacheEntryCheck() {
return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
}
};
function checkForImage(elem, htmllocalname)
{
var img;
var imgType; // "img" =
// "object" =