// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k@gmail.com>
+// Copyright (c) 2008-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.
if (val == null)
;
- else if (typeof val == "xml" && context instanceof Ci.nsIDOMDocument)
- this[length++] = DOM.fromXML(val, context, this.nodes);
else if (DOM.isJSONXML(val)) {
if (context instanceof Ci.nsIDOMDocument)
this[length++] = DOM.fromJSON(val, context, this.nodes);
let charset = doc.characterSet;
let converter = services.CharsetConv(charset);
- for each (let cs in form.acceptCharset.split(/\s*,\s*|\s+/)) {
+ for (let cs of form.acceptCharset.split(/\s*,\s*|\s+/)) {
let c = services.CharsetConv(cs);
if (c) {
converter = services.CharsetConv(cs);
if (callable(v))
v = v.call(this, elem, i);
- if (Set.has(hooks, k) && hooks[k].set)
+ if (hasOwnProperty(hooks, k) && hooks[k].set)
hooks[k].set.call(this, elem, v, k);
else if (v == null)
elem.removeAttributeNS(ns, k);
if (!this.length)
return null;
- if (Set.has(hooks, key) && hooks[key].get)
+ if (hasOwnProperty(hooks, key) && hooks[key].get)
return hooks[key].get.call(this, this[0], key);
if (!this[0].hasAttributeNS(ns, key))
keyTable: Class.Memoize(function (prop) this.init()[prop]),
key_code: Class.Memoize(function (prop) this.init()[prop]),
key_key: Class.Memoize(function (prop) this.init()[prop]),
- pseudoKeys: Set(["count", "leader", "nop", "pass"]),
+ pseudoKeys: RealSet(["count", "leader", "nop", "pass"]),
/**
* Converts a user-input string of keys into a canonical
* @returns {string} Canonical form.
*/
canonicalKeys: function canonicalKeys(keys, unknownOk=true) {
- return this.parse(keys, unknownOk).map(this.closure.stringify).join("");
+ return this.parse(keys, unknownOk).map(this.bound.stringify).join("");
},
iterKeys: function iterKeys(keys) iter(function () {
}
else {
let [match, modifier, keyname] = evt_str.match(/^<((?:[*12CASM⌘]-)*)(.+?)>$/i) || [false, '', ''];
- modifier = Set(modifier.toUpperCase());
+ modifier = RealSet(modifier.toUpperCase());
keyname = keyname.toLowerCase();
evt_obj.dactylKeyname = keyname;
if (/^u[0-9a-f]+$/.test(keyname))
keyname = String.fromCharCode(parseInt(keyname.substr(1), 16));
if (keyname && (unknownOk || keyname.length == 1 || /mouse$/.test(keyname) ||
- this.key_code[keyname] || Set.has(this.pseudoKeys, keyname))) {
- evt_obj.globKey ="*" in modifier;
- evt_obj.ctrlKey ="C" in modifier;
- evt_obj.altKey ="A" in modifier;
- evt_obj.shiftKey ="S" in modifier;
- evt_obj.metaKey ="M" in modifier || "⌘" in modifier;
+ this.key_code[keyname] || this.pseudoKeys.has(keyname))) {
+ evt_obj.globKey = modifier.has("*");
+ evt_obj.ctrlKey = modifier.has("C");
+ evt_obj.altKey = modifier.has("A");
+ evt_obj.shiftKey = modifier.has("S");
+ evt_obj.metaKey = modifier.has("M") || modifier.has("⌘");
evt_obj.dactylShift = evt_obj.shiftKey;
if (keyname.length == 1) { // normal characters
evt_obj.charCode = keyname.charCodeAt(0);
evt_obj.keyCode = this.key_code[keyname.toLowerCase()];
}
- else if (Set.has(this.pseudoKeys, keyname)) {
+ else if (this.pseudoKeys.has(keyname)) {
evt_obj.dactylString = "<" + this.key_key[keyname] + ">";
}
else if (/mouse$/.test(keyname)) { // mouse events
- evt_obj.type = (/2-/.test(modifier) ? "dblclick" : "click");
+ evt_obj.type = (modifier.has("2") ? "dblclick" : "click");
evt_obj.button = ["leftmouse", "middlemouse", "rightmouse"].indexOf(keyname);
delete evt_obj.keyCode;
delete evt_obj.charCode;
* @param {Node} target The DOM node to which to dispatch the event.
* @param {Event} event The event to dispatch.
*/
- dispatch: Class.Memoize(function ()
- config.haveGecko("2b")
- ? function dispatch(target, event, extra) {
- try {
- this.feedingEvent = extra;
-
- if (target instanceof Ci.nsIDOMElement)
- // This causes a crash on Gecko<2.0, it seems.
- return (target.ownerDocument || target.document || target).defaultView
- .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils)
- .dispatchDOMEventViaPresShell(target, event, true);
- else {
- target.dispatchEvent(event);
- return !event.defaultPrevented;
- }
- }
- catch (e) {
- util.reportError(e);
- }
- finally {
- this.feedingEvent = null;
- }
+ dispatch: function dispatch(target, event, extra) {
+ try {
+ this.feedingEvent = extra;
+
+ if (target instanceof Ci.nsIDOMElement)
+ return (target.ownerDocument || target.document || target).defaultView
+ .QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils)
+ .dispatchDOMEventViaPresShell(target, event, true);
+ else {
+ target.dispatchEvent(event);
+ return !event.defaultPrevented;
}
- : function dispatch(target, event, extra) {
- try {
- this.feedingEvent = extra;
- target.dispatchEvent(update(event, extra));
- }
- finally {
- this.feedingEvent = null;
- }
- })
+ }
+ catch (e) {
+ util.reportError(e);
+ }
+ finally {
+ this.feedingEvent = null;
+ }
+ }
}),
createContents: Class.Memoize(() => services.has("dactyl") && services.dactyl.createContents
* The set of input element type attribute values that mark the element as
* an editable field.
*/
- editableInputs: Set(["date", "datetime", "datetime-local", "email", "file",
- "month", "number", "password", "range", "search",
- "tel", "text", "time", "url", "week"]),
+ editableInputs: RealSet(["date", "datetime", "datetime-local", "email", "file",
+ "month", "number", "password", "range", "search",
+ "tel", "text", "time", "url", "week"]),
/**
* Converts a given DOM Node, Range, or Selection to a string. If
* @returns {boolean} True when the patterns are all valid.
*/
validateMatcher: function validateMatcher(list) {
- return this.testValues(list, DOM.closure.testMatcher);
+ return this.testValues(list, DOM.bound.testMatcher);
},
testMatcher: function testMatcher(value) {
return str.replace(regexp, m => map[m]);
},
- /**
- * Converts an E4X XML literal to a DOM node. Any attribute named
- * highlight is present, it is transformed into dactyl:highlight,
- * and the named highlight groups are guaranteed to be loaded.
- *
- * @param {Node} node
- * @param {Document} doc
- * @param {Object} nodes If present, nodes with the "key" attribute are
- * stored here, keyed to the value thereof.
- * @returns {Node}
- */
- fromXML: deprecated("DOM.fromJSON", { get: function fromXML()
- prefs.get("javascript.options.xml.chrome") !== false
- && require("dom-e4x").fromXML }),
-
fromJSON: update(function fromJSON(xml, doc, nodes, namespaces) {
if (!doc)
doc = document;
if (isinstance(args, ["String", "Number", "Boolean", _]))
return doc.createTextNode(args);
- if (isXML(args))
- return DOM.fromXML(args, doc, nodes);
if (isObject(args) && "toDOM" in args)
return args.toDOM(doc, namespaces, nodes);
if (args instanceof Ci.nsIDOMNode)
toPrettyXML: function toPrettyXML(xml, asXML, indent, namespaces) {
const INDENT = indent || " ";
- const EMPTY = Set("area base basefont br col frame hr img input isindex link meta param"
+ const EMPTY = RealSet("area base basefont br col frame hr img input isindex link meta param"
.split(" "));
function namespaced(namespaces, namespace, localName) {
return indent +
DOM.escapeHTML(String(args), true);
- if (isXML(args))
- return indent +
- args.toXMLString()
- .replace(/^/m, indent);
-
if (isObject(args) && "toDOM" in args)
return indent +
services.XMLSerializer()
let res = [indent, "<", name];
for (let [key, val] in Iterator(attr)) {
- if (Set.has(skipAttr, key))
+ if (hasOwnProperty(skipAttr, key))
continue;
let vals = parseNamespace(key);
'="', DOM.escapeHTML(val), '"');
}
- if ((vals[0] || namespaces[""]) == String(XHTML) && Set.has(EMPTY, vals[1])
+ if ((vals[0] || namespaces[""]) == String(XHTML) && EMPTY.has(vals[1])
|| asXML && !args.length)
res.push("/>");
else {
Object.keys(DOM.Event.types).forEach(function (event) {
let name = event.replace(/-(.)/g, (m, m1) => m1.toUpperCase());
- if (!Set.has(DOM.prototype, name))
+ if (!hasOwnProperty(DOM.prototype, name))
DOM.prototype[name] =
function _event(arg, extra) {
return this[callable(arg) ? "listen" : "dispatch"](event, arg, extra);