diff options
author | Kris Maglione <maglione.k@gmail.com> | 2012-12-17 19:27:53 -0800 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2012-12-17 19:27:53 -0800 |
commit | 6ee5b2ca2649bf50ac67bb493100507779ff6a23 (patch) | |
tree | 286829ba5903b79cdb011c267a25f62a6556fc3e /common | |
parent | 3f483de547a9617a6af68cb7bc9ed265ece36683 (diff) | |
download | pentadactyl-6ee5b2ca2649bf50ac67bb493100507779ff6a23.tar.gz |
Death to E4X and stuff.
Diffstat (limited to 'common')
-rw-r--r-- | common/content/dactyl.js | 19 | ||||
-rw-r--r-- | common/modules/buffer.jsm | 4 | ||||
-rw-r--r-- | common/modules/dom-e4x.jsm | 53 | ||||
-rw-r--r-- | common/modules/dom.jsm | 63 | ||||
-rw-r--r-- | common/modules/help.jsm | 4 | ||||
-rw-r--r-- | common/modules/highlight.jsm | 2 | ||||
-rw-r--r-- | common/modules/overlay.jsm | 17 | ||||
-rw-r--r-- | common/modules/styles.jsm | 6 |
8 files changed, 80 insertions, 88 deletions
diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 749da080..e3bf2495 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -4,7 +4,7 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -// "use strict"; +"use strict"; /** @scope modules */ @@ -1215,22 +1215,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { for (let [, context] in Iterator(plugins.contexts)) try { let info = contexts.getDocs(context); - if (info instanceof XML) { - if (info.*.@lang.length()) { - let lang = config.bestLocale(String(a) for each (a in info.*.@lang)); - - info.* = info.*.(function::attribute("lang").length() == 0 || @lang == lang); - - for each (let elem in info.NS::info) - for (let attr in values(["@name", "@summary", "@href"])) - if (elem[attr].length()) - info[attr] = elem[attr]; - } - body.push(["h2", { xmlns: "dactyl", tag: info.@name + '-plugin' }, - String(info.@summary)]); - body.push(info); - } - else if (DOM.isJSONXML(info)) { + if (DOM.isJSONXML(info)) { let langs = info.slice(2).filter(function (e) isArray(e) && isObject(e[1]) && e[1].lang); if (langs) { let lang = config.bestLocale(l[1].lang for each (l in langs)); diff --git a/common/modules/buffer.jsm b/common/modules/buffer.jsm index af69b694..09b7b899 100644 --- a/common/modules/buffer.jsm +++ b/common/modules/buffer.jsm @@ -875,8 +875,8 @@ var Buffer = Module("Buffer", { util.timeout(function () { indicator.remove(); }, 500); // Doesn't unattach - //doc.body.setAttributeNS(NS.uri, "activeframe", "true"); - //util.timeout(function () { doc.body.removeAttributeNS(NS.uri, "activeframe"); }, 500); + //doc.body.setAttributeNS(NS, "activeframe", "true"); + //util.timeout(function () { doc.body.removeAttributeNS(NS, "activeframe"); }, 500); }, // similar to pageInfo diff --git a/common/modules/dom-e4x.jsm b/common/modules/dom-e4x.jsm new file mode 100644 index 00000000..5a1cdfb6 --- /dev/null +++ b/common/modules/dom-e4x.jsm @@ -0,0 +1,53 @@ +// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com> +// Copyright (c) 2008-2012 Kris Maglione <maglione.k@gmail.com> +// +// This work is licensed for reuse under an MIT license. Details are +// given in the LICENSE.txt file included with this file. +/* use strict */ + +defineModule("dom", { + exports: ["fromXML"] +}); + +lazyRequire("highlight", ["highlight"]); + +var XBL = Namespace("xbl", "http://www.mozilla.org/xbl"); +var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); +var XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); +var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator"); + +function fromXML(node, doc, nodes) { + XML.ignoreWhitespace = XML.prettyPrinting = false; + if (typeof node === "string") // Sandboxes can't currently pass us XML objects. + node = XML(node); + + if (node.length() != 1) { + let domnode = doc.createDocumentFragment(); + for each (let child in node) + domnode.appendChild(fromXML(child, doc, nodes)); + return domnode; + } + + switch (node.nodeKind()) { + case "text": + return doc.createTextNode(String(node)); + case "element": + let domnode = doc.createElementNS(node.namespace(), node.localName()); + + for each (let attr in node.@*::*) + if (attr.name() != "highlight") + domnode.setAttributeNS(attr.namespace(), attr.localName(), String(attr)); + + for each (let child in node.*::*) + domnode.appendChild(fromXML(child, doc, nodes)); + if (nodes && node.@key) + nodes[node.@key] = domnode; + + if ("@highlight" in node) + highlight.highlightNode(domnode, String(node.@highlight), nodes || true); + return domnode; + default: + return null; + } +} + diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index 3dee7fee..7b74f491 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -3,7 +3,7 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; defineModule("dom", { exports: ["$", "DOM", "NS", "XBL", "XHTML", "XUL"] @@ -13,10 +13,10 @@ lazyRequire("highlight", ["highlight"]); lazyRequire("messages", ["_"]); lazyRequire("template", ["template"]); -var XBL = Namespace("xbl", "http://www.mozilla.org/xbl"); -var XHTML = Namespace("html", "http://www.w3.org/1999/xhtml"); -var XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); -var NS = Namespace("dactyl", "http://vimperator.org/namespaces/liberator"); +var XBL = "http://www.mozilla.org/xbl"; +var XHTML = "http://www.w3.org/1999/xhtml"; +var XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; +var NS = "http://vimperator.org/namespaces/liberator"; function BooleanAttribute(attr) ({ get: function (elem) elem.getAttribute(attr) == "true", @@ -116,14 +116,6 @@ var DOM = Class("DOM", { }, eachDOM: function eachDOM(val, fn, self) { - if (isString(val)) - val = XML(val); - - if (typeof val == "xml") - return this.each(function (elem, i) { - fn.call(this, DOM.fromXML(val, elem.ownerDocument), elem, i); - }, self || this); - let dom = this; function munge(val, container, idx) { if (val instanceof Ci.nsIDOMRange) @@ -1524,40 +1516,9 @@ var DOM = Class("DOM", { * stored here, keyed to the value thereof. * @returns {Node} */ - fromXML: function fromXML(node, doc, nodes) { - XML.ignoreWhitespace = XML.prettyPrinting = false; - if (typeof node === "string") // Sandboxes can't currently pass us XML objects. - node = XML(node); - - if (node.length() != 1) { - let domnode = doc.createDocumentFragment(); - for each (let child in node) - domnode.appendChild(fromXML(child, doc, nodes)); - return domnode; - } - - switch (node.nodeKind()) { - case "text": - return doc.createTextNode(String(node)); - case "element": - let domnode = doc.createElementNS(node.namespace(), node.localName()); - - for each (let attr in node.@*::*) - if (attr.name() != "highlight") - domnode.setAttributeNS(attr.namespace(), attr.localName(), String(attr)); - - for each (let child in node.*::*) - domnode.appendChild(fromXML(child, doc, nodes)); - if (nodes && node.@key) - nodes[node.@key] = domnode; - - if ("@highlight" in node) - highlight.highlightNode(domnode, String(node.@highlight), nodes || true); - return domnode; - default: - return null; - } - }, + fromXML: Class.Memoize(function () + prefs.get("javascript.options.xml.chrome") !== false + && require("dom-e4x.xml").fromXML), fromJSON: update(function fromJSON(xml, doc, nodes, namespaces) { if (!doc) @@ -1892,11 +1853,11 @@ var DOM = Class("DOM", { }, namespaces: { - xul: XUL.uri, - xhtml: XHTML.uri, - html: XHTML.uri, + xul: XUL, + xhtml: XHTML, + html: XHTML, xhtml2: "http://www.w3.org/2002/06/xhtml2", - dactyl: NS.uri + dactyl: NS }, namespaceNames: Class.Memoize(function () diff --git a/common/modules/help.jsm b/common/modules/help.jsm index 6b9e0b90..30d676cb 100644 --- a/common/modules/help.jsm +++ b/common/modules/help.jsm @@ -317,8 +317,8 @@ var Help = Module("Help", { data.push("<", node.localName); if (node instanceof Ci.nsIDOMHTMLHtmlElement) - data.push(" xmlns=" + XHTML.uri.quote(), - " xmlns:dactyl=" + NS.uri.quote()); + data.push(" xmlns=" + XHTML.quote(), + " xmlns:dactyl=" + NS.quote()); for (let { name, value } in array.iterValues(node.attributes)) { if (name == "dactyl:highlight") { diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index bda4bd78..bf242e08 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -197,7 +197,7 @@ var Highlights = Module("Highlight", { * @param {string} group */ highlightNode: function highlightNode(node, group, applyBindings) { - node.setAttributeNS(NS.uri, "highlight", group); + node.setAttributeNS(NS, "highlight", group); let groups = group.split(" "); for each (let group in groups) diff --git a/common/modules/overlay.jsm b/common/modules/overlay.jsm index 357bfeae..f8a4fb5d 100644 --- a/common/modules/overlay.jsm +++ b/common/modules/overlay.jsm @@ -2,7 +2,7 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; try { @@ -232,10 +232,7 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen function insert(key, fn) { if (obj[key]) { let iterator = Iterator(obj[key]); - if (!isObject(obj[key])) - iterator = ([elem.@id, elem.elements(), elem.@*::*.(function::name() != "id")] - for each (elem in obj[key])); - else if (isArray(obj[key])) { + if (isArray(obj[key])) { iterator = ([elem[1].id, elem.slice(2), elem[1]] for each (elem in obj[key])) } @@ -270,13 +267,9 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen } for (let attr in attrs || []) { - let ns, name, localName, val; - if (isXML(attr)) - ns = attr.namespace(), localName = attr.localName(), - name = attr.name(), val = String(attr); - else - [ns, localName] = DOM.parseNamespace(attr), - name = attr, val = attrs[attr]; + let [ns, localName] = DOM.parseNamespace(attr); + let name = attr; + let val = attrs[attr]; savedAttrs.push([elem, ns, name, getAttr(elem, ns, name), val]); if (name === "highlight") diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 071f378b..c89c2812 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -13,9 +13,9 @@ lazyRequire("contexts", ["Contexts"]); lazyRequire("template", ["template"]); function cssUri(css) "chrome-data:text/css," + encodeURI(css); -var namespace = "@namespace html " + XHTML.uri.quote() + ";\n" + - "@namespace xul " + XUL.uri.quote() + ";\n" + - "@namespace dactyl " + NS.uri.quote() + ";\n"; +var namespace = "@namespace html " + XHTML.quote() + ";\n" + + "@namespace xul " + XUL.quote() + ";\n" + + "@namespace dactyl " + NS.quote() + ";\n"; var Sheet = Struct("name", "id", "sites", "css", "hive", "agent"); Sheet.liveProperty = function (name) { |