-// Copyright (c) 2009-2013 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2009-2014 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.
target = null;
this.setData(doc, "listeners", listeners.filter(function (args) {
- if (target == null || args[0].get() == target && args[1] == event && args[2].wrapped == callback && args[3] == capture) {
- args[0].get().removeEventListener.apply(args[0].get(), args.slice(1));
+ let elem = args[0].get();
+ if (target == null || elem == target && args[1] == event && args[2].wrapped == callback && args[3] == capture) {
+ elem.removeEventListener.apply(elem, args.slice(1));
return false;
}
- return !args[0].get();
+ return elem;
}));
},
cleanup: function cleanup(reason) {
for (let doc in util.iterDocuments()) {
+ for (let callback in values(this.getData(doc, "cleanup")))
+ util.trapErrors(callback, doc, reason);
+
for (let elem in values(this.getData(doc, "overlayElements")))
if (elem.parentNode)
elem.parentNode.removeChild(elem);
if (getAttr(elem, ns, name) === value)
setAttr(elem, ns, name, orig);
- for (let callback in values(this.getData(doc, "cleanup")))
- util.trapErrors(callback, doc, reason);
-
this.unlisten(doc, true);
delete doc[this.id];
setData: function setData(obj, key, val) {
let data = this.getData(obj);
+ if (val !== undefined)
+ return data[key] = val;
- return data[key] = val;
+ delete data[key];
},
overlayWindow: function overlayWindow(url, fn) {
_loadOverlays: function _loadOverlays(window) {
let overlays = this.getData(window, "overlays");
- for each (let obj in overlay.overlays[window.document.documentURI] || []) {
+ for (let obj of overlay.overlays[window.document.documentURI] || []) {
if (~overlays.indexOf(obj))
continue;
overlays.push(obj);
if (elem = doc.getElementById(String(elem))) {
// Urgh. Hack.
let namespaces;
- if (attrs && !isXML(attrs))
+ if (attrs)
namespaces = iter([k.slice(6), DOM.fromJSON.namespaces[v] || v]
for ([k, v] in Iterator(attrs))
if (/^xmlns(?:$|:)/.test(k))).toObject();
- let node;
- if (isXML(xml))
- node = DOM.fromXML(xml, doc, obj.objects);
- else
- node = DOM.fromJSON(xml, doc, obj.objects, namespaces);
+ let node = DOM.fromJSON(xml, doc, obj.objects, namespaces);
if (!(node instanceof Ci.nsIDOMDocumentFragment))
savedElems.push(node);
fn(elem, node);
- if (isXML(attrs))
- // Evilness and such.
- let (oldAttrs = attrs) {
- attrs = (attr for each (attr in oldAttrs));
- }
-
for (let attr in attrs || []) {
let [ns, localName] = DOM.parseNamespace(attr);
let name = attr;
overrides = update(Object.create(original), overrides);
Object.getOwnPropertyNames(overrides).forEach(function (k) {
- let orig, desc = Object.getOwnPropertyDescriptor(overrides, k);
+ let desc = Object.getOwnPropertyDescriptor(overrides, k);
+
if (desc.value instanceof Class.Property)
desc = desc.value.init(k) || desc.value;
if (k in object) {
- for (let obj = object; obj && !orig; obj = Object.getPrototypeOf(obj))
- if (orig = Object.getOwnPropertyDescriptor(obj, k))
+ for (let obj = object; obj && !orig; obj = Object.getPrototypeOf(obj)) {
+ var orig = Object.getOwnPropertyDescriptor(obj, k);
+ if (orig)
Object.defineProperty(original, k, orig);
+ }
- if (!orig)
- if (orig = Object.getPropertyDescriptor(object, k))
+ if (!orig) {
+ orig = Object.getPropertyDescriptor(object, k);
+ if (orig)
Object.defineProperty(original, k, orig);
+ }
}
// Guard against horrible add-ons that use eval-based monkey
delete desc.writable;
desc.get = function get() value;
desc.set = function set(val) {
- if (!callable(val) || Function.prototype.toString(val).indexOf(sentinel) < 0)
+ if (!callable(val) || !Function.prototype.toString(val).contains(sentinel))
Class.replaceProperty(this, k, val);
else {
let package_ = util.newURI(Components.stack.caller.filename).host;
}, this);
return function unwrap() {
- for each (let k in Object.getOwnPropertyNames(original))
+ for (let k of Object.getOwnPropertyNames(original))
if (Object.getOwnPropertyDescriptor(object, k).configurable)
Object.defineProperty(object, k, Object.getOwnPropertyDescriptor(original, k));
else {
get activeModules() this.activeWindow && this.activeWindow.dactyl.modules,
- get modules() this.windows.map(w => w.dactyl.modules),
+ get modules() [w.dactyl.modules for (w of this.windows)],
/**
* The most recently active dactyl window.
*/
- get activeWindow() this.windows[0],
+ get activeWindow() {
+ let win = this._activeWindow && this._activeWindow.get();
+ return this.windows.has(win) && win;
+ },
- set activeWindow(win) this.windows = [win].concat(this.windows.filter(w => w != win)),
+ set activeWindow(win) this._activeWindow = util.weakReference(win),
/**
* A list of extant dactyl windows.
*/
- windows: Class.Memoize(() => [])
+ windows: Class.Memoize(() => RealSet())
});
endModule();