From c73815baa87ae92d7b31ec53daa6f15fc9f01a36 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 27 Jul 2011 05:27:27 -0400 Subject: [PATCH] Minor cleanup. --- common/content/dactyl.js | 2 +- common/content/events.js | 32 ++++++++++++++++++++------------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 56fd7a1f..f30f36ab 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1124,7 +1124,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { let loadplugins = options.get("loadplugins"); if (args) - loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) } + loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) }; dir.readDirectory(true).forEach(function (file) { if (file.isFile() && loadplugins.getKey(file.path) diff --git a/common/content/events.js b/common/content/events.js index bcad0c8a..8d19a0d1 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -732,8 +732,7 @@ var Events = Module("events", { * @param {Object} opts The pseudo-event. @optional */ create: function (doc, type, opts) { - opts = opts || {}; - var DEFAULTS = { + const DEFAULTS = { HTML: { type: type, bubbles: true, cancelable: false }, @@ -756,22 +755,31 @@ var Events = Module("events", { relatedTarget: null } }; - const TYPES = { - change: "", "dactyl-input": "", input: "", submit: "", - click: "Mouse", mousedown: "Mouse", mouseup: "Mouse", - mouseover: "Mouse", mouseout: "Mouse", - keypress: "Key", keyup: "Key", keydown: "Key" - }; - var t = TYPES[type]; + + opts = opts || {}; + + var t = this._create_types[type]; var evt = doc.createEvent((t || "HTML") + "Events"); let defaults = DEFAULTS[t || "HTML"]; - evt["init" + t + "Event"].apply(evt, Object.keys(defaults) - .map(function (k) k in opts ? opts[k] - : defaults[k])); + + let args = Object.keys(defaults) + .map(function (k) k in opts ? opts[k] : defaults[k]); + + evt["init" + t + "Event"].apply(evt, args); return evt; }, + _create_types: Class.memoize(function () iter( + { + Mouse: "click mousedown mouseout mouseover mouseup", + Key: "keydown keypress keyup", + "": "change dactyl-input input submit" + } + ).map(function ([k, v]) v.split(" ").map(function (v) [v, k])) + .flatten() + .toObject()), + /** * Converts a user-input string of keys into a canonical * representation.