1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-04 16:04:11 +01:00

More minorish changes.

This commit is contained in:
Kris Maglione
2011-09-03 09:21:57 -04:00
parent 91cbb9dacb
commit 3764176940

View File

@@ -48,6 +48,8 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
this.timeout(this.initialize); this.timeout(this.initialize);
}, },
id: Class.Memoize(function () config.addon.id),
initialize: function () { initialize: function () {
this.overlayWindow(config.overlayChrome, function _overlay(window) ({ this.overlayWindow(config.overlayChrome, function _overlay(window) ({
init: function onInit(document) { init: function onInit(document) {
@@ -318,17 +320,16 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
cleanup: function cleanup() { cleanup: function cleanup() {
for (let doc in util.iterDocuments()) { for (let doc in util.iterDocuments()) {
for (let elem in values(doc.dactylOverlayElements || [])) for (let elem in values(this.getData(doc, "overlayElements")))
if (elem.parentNode) if (elem.parentNode)
elem.parentNode.removeChild(elem); elem.parentNode.removeChild(elem);
for (let [elem, ns, name, orig, value] in values(doc.dactylOverlayAttributes || [])) for (let [elem, ns, name, orig, value] in values(this.getData(doc, "overlayAttributes")))
if (getAttr(elem, ns, name) === value) if (getAttr(elem, ns, name) === value)
setAttr(elem, ns, name, orig); setAttr(elem, ns, name, orig);
delete doc.dactylOverlayElements; delete doc[this.id];
delete doc.dactylOverlayAttributes; delete doc.defaultView[this.id];
delete doc.dactylOverlays;
} }
}, },
@@ -350,6 +351,27 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
} }
}, },
getData: function getData(obj, key, constructor) {
let { id } = this;
if (!(id in obj))
obj[id] = {};
if (!(key in obj[id]))
obj[id][key] = (constructor || Array)();
return obj[id][key];
},
setData: function setData(obj, key, val) {
let { id } = this;
if (!(id in obj))
obj[id] = {};
return obj[id][key] = val;
},
overlayWindow: function (url, fn) { overlayWindow: function (url, fn) {
if (url instanceof Ci.nsIDOMWindow) if (url instanceof Ci.nsIDOMWindow)
overlay._loadOverlay(url, fn); overlay._loadOverlay(url, fn);
@@ -374,23 +396,20 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
}, },
_loadOverlays: function _loadOverlays(window) { _loadOverlays: function _loadOverlays(window) {
if (!window.dactylOverlays) let overlays = this.getData(window, "overlays");
window.dactylOverlays = [];
for each (let obj in overlay.overlays[window.document.documentURI] || []) { for each (let obj in overlay.overlays[window.document.documentURI] || []) {
if (~window.dactylOverlays.indexOf(obj)) if (~overlays.indexOf(obj))
continue; continue;
window.dactylOverlays.push(obj); overlays.push(obj);
this._loadOverlay(window, obj(window)); this._loadOverlay(window, obj(window));
} }
}, },
_loadOverlay: function _loadOverlay(window, obj) { _loadOverlay: function _loadOverlay(window, obj) {
let doc = window.document; let doc = window.document;
if (!doc.dactylOverlayElements) { let elems = this.getData(doc, "overlayElements");
doc.dactylOverlayElements = []; let attrs = this.getData(doc, "overlayAttributes");
doc.dactylOverlayAttributes = [];
}
function insert(key, fn) { function insert(key, fn) {
if (obj[key]) { if (obj[key]) {
@@ -402,15 +421,15 @@ var Overlay = Module("Overlay", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReferen
if (elem = doc.getElementById(elem)) { if (elem = doc.getElementById(elem)) {
let node = util.xmlToDom(xml, doc, obj.objects); let node = util.xmlToDom(xml, doc, obj.objects);
if (!(node instanceof Ci.nsIDOMDocumentFragment)) if (!(node instanceof Ci.nsIDOMDocumentFragment))
doc.dactylOverlayElements.push(node); elems.push(node);
else else
for (let n in array.iterValues(node.childNodes)) for (let n in array.iterValues(node.childNodes))
doc.dactylOverlayElements.push(n); elems.push(n);
fn(elem, node); fn(elem, node);
for each (let attr in attr || []) { for each (let attr in attr || []) {
let ns = attr.namespace(), name = attr.localName(); let ns = attr.namespace(), name = attr.localName();
doc.dactylOverlayAttributes.push([elem, ns, name, getAttr(elem, ns, name), String(attr)]); attrs.push([elem, ns, name, getAttr(elem, ns, name), String(attr)]);
if (attr.name() != "highlight") if (attr.name() != "highlight")
elem.setAttributeNS(ns, name, String(attr)); elem.setAttributeNS(ns, name, String(attr));
else else