From 6ed8bad74dd1e67651a5284c0abf462090980c18 Mon Sep 17 00:00:00 2001 From: Tore Birkeland Date: Sun, 13 Sep 2015 21:05:47 +0200 Subject: [PATCH] Now reads key property from the keyboard event if keyCode is missing. Fixes an issue with simulating events in PhantomJS --- keypress-2.1.3.min.js | 53 ++++---- keypress.coffee | 4 +- keypress.js | 309 +++++++++++++++++++++--------------------- 3 files changed, 180 insertions(+), 186 deletions(-) diff --git a/keypress-2.1.3.min.js b/keypress-2.1.3.min.js index 66697ef..be2f631 100644 --- a/keypress-2.1.3.min.js +++ b/keypress-2.1.3.min.js @@ -1,33 +1,28 @@ -/* - Keypress version 2.1.3 (c) 2014 David Mauro. - Licensed under the Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0 -*/ -(function(){var m,v,y,z,A,r,w,B,F,C,G,H,q,s,p,o,t,D,I,E={}.hasOwnProperty,j=[].indexOf||function(a){for(var c=0,b=this.length;cj.call(a,"cmd")?!1:!0};g.prototype._prevent_default=function(a,c){if((c||this.should_suppress_event_defaults)&&!this.should_force_event_defaults)if(a.preventDefault?a.preventDefault():a.returnValue=!1,a.stopPropagation)return a.stopPropagation()}; -g.prototype._get_active_combos=function(a){var c,b;c=[];b=w(this._keys_down,function(b){return b!==a});b.push(a);this._match_combo_arrays(b,function(a){return function(b){if(a._cmd_bug_check(b.keys))return c.push(b)}}(this));this._fuzzy_match_combo_arrays(b,function(a){return function(b){if(!(0<=j.call(c,b))&&!b.is_solitary&&a._cmd_bug_check(b.keys))return c.push(b)}}(this));return c};g.prototype._get_potential_combos=function(a){var c,b,d,e,f;b=[];f=this._registered_combos;d=0;for(e=f.length;dk;e=0<=k?++i:--i)if((c=this._active_combos[e])&&c.is_exclusive&&a.is_exclusive){c=c.keys;if(!h){g=0;for(n=c.length;gj.call(a.keys,b)){h=!1;break}}if(f&&!h){l=a.keys;g=0;for(n= -l.length;gj.call(c,b)){f=!0;break}}h&&(d?(c=this._active_combos.splice(e,1)[0],null!=c&&c.reset()):(c=this._active_combos.splice(e,1,a)[0],null!=c&&c.reset(),d=!0),f=!1)}}f&&this._active_combos.unshift(a);return h||f};g.prototype._remove_from_active_combos=function(a){var c,b,d,e;b=d=0;for(e=this._active_combos.length;0<=e?de;b=0<=e?++d:--d)if(c=this._active_combos[b],c===a){a=this._active_combos.splice(b,1)[0];a.reset();break}};g.prototype._get_possible_sequences=function(){var a, -c,b,d,e,f,h,i,g,n,k,l;d=[];n=this._registered_combos;f=0;for(g=n.length;f=k;c=1<=k?++h:--h)if(e=this._sequence.slice(-c),a.is_sequence){if(0>j.call(a.keys,"shift")&&(e=w(e,function(a){return"shift"!==a}),!e.length))continue;c=i=0;for(l=e.length;0<=l?il;c=0<=l?++i:--i)if(a.keys[c]===e[c])b=!0;else{b=!1;break}b&&d.push(a)}}return d};g.prototype._add_key_to_sequence=function(a,c){var b,d,e,f;this._sequence.push(a);d=this._get_possible_sequences(); -if(d.length){e=0;for(f=d.length;e=l;b=1<=l?++i:--i)if(f=w(this._sequence, -function(a){return 0<=j.call(c.keys,"shift")?!0:"shift"!==a}).slice(-b),c.keys.length===f.length){b=g=0;for(u=f.length;0<=u?gu;b=0<=u?++g:--g)if(e=f[b],!(0>j.call(c.keys,"shift")&&"shift"===e)&&!("shift"===a&&0>j.call(c.keys,"shift")))if(c.keys[b]===e)d=!0;else{d=!1;break}}if(d){debugger;c.is_exclusive&&(this._sequence=[]);return c}}return!1};g.prototype._receive_input=function(a,c){var b;if(this._prevent_capture)this._keys_down.length&&(this._keys_down=[]);else if(b=z(a.keyCode),(c||this._keys_down.length|| -!("alt"===b||b===o))&&b)return c?this._key_down(b,a):this._key_up(b,a)};g.prototype._fire=function(a,c,b,d){"function"===typeof c["on_"+a]&&this._prevent_default(b,!0!==c["on_"+a].call(c["this"],b,c.count,d));"release"===a&&(c.count=0);if("keyup"===a)return c.keyup_fired=!0};g.prototype._match_combo_arrays=function(a,c){var b,d,e,f;f=this._registered_combos;d=0;for(e=f.length;df;b=0<=f?++d:--d)this._keys_down[b]===e&&this._keys_down.splice(b,1)}d=this._get_active_combos(a);e=this._get_potential_combos(a);f=0;for(h=d.length;fj.call(this._keys_down,a)&&this._keys_down.push(a)}; -g.prototype._handle_combo_down=function(a,c,b,d){var e,f,h,g,m;if(0>j.call(a.keys,b))return!1;this._prevent_default(d,a&&a.prevent_default);e=!1;if(0<=j.call(this._keys_down,b)&&(e=!0,!a.allows_key_repeat()))return!1;h=this._add_to_active_combos(a,b);b=a.keyup_fired=!1;if(a.is_exclusive){g=0;for(m=c.length;ga.keys.length){b=!0;break}}if(!b&&(a.is_counting&&"function"===typeof a.on_keydown&&(a.count+=1),h))return this._fire("keydown",a,d,e)};g.prototype._key_up= -function(a,c){var b,d,e,f,h,g;b=a;(e=A(a,c))&&(a=e);e=s[b];c.shiftKey?e&&0<=j.call(this._keys_down,e)||(a=b):b&&0<=j.call(this._keys_down,b)||(a=e);(f=this._get_sequence(a))&&this._fire("keyup",f,c);if(0>j.call(this._keys_down,a))return!1;f=h=0;for(g=this._keys_down.length;0<=g?hg;f=0<=g?++h:--h)if((d=this._keys_down[f])===a||d===e||d===b){this._keys_down.splice(f,1);break}d=this._active_combos.length;e=[];g=this._active_combos;f=0;for(h=g.length;fi.call(a,"cmd")?!1:!0};g.prototype._prevent_default=function(a,c){if((c||this.should_suppress_event_defaults)&&!this.should_force_event_defaults)if(a.preventDefault?a.preventDefault():a.returnValue=!1,a.stopPropagation)return a.stopPropagation()}; +g.prototype._get_active_combos=function(a){var c,b;c=[];b=v(this._keys_down,function(b){return b!==a});b.push(a);this._match_combo_arrays(b,function(a){return function(b){if(a._cmd_bug_check(b.keys))return c.push(b)}}(this));this._fuzzy_match_combo_arrays(b,function(a){return function(b){if(!(0<=i.call(c,b))&&!b.is_solitary&&a._cmd_bug_check(b.keys))return c.push(b)}}(this));return c};g.prototype._get_potential_combos=function(a){var c,b,d,e,f;e=[];f=this._registered_combos;b=0;for(d=f.length;bg;e=0<=g?++f:--f)if((c=this._active_combos[e])&&c.is_exclusive&&a.is_exclusive){c=c.keys;if(!l){j=0;for(h=c.length;ji.call(a.keys,b)){l=!1;break}}if(k&&!l){n=a.keys;j=0;for(h= +n.length;ji.call(c,b)){k=!0;break}}l&&(d?(c=this._active_combos.splice(e,1)[0],null!=c&&c.reset()):(c=this._active_combos.splice(e,1,a)[0],null!=c&&c.reset(),d=!0),k=!1)}}k&&this._active_combos.unshift(a);return l||k};g.prototype._remove_from_active_combos=function(a){var c,b,d,e;b=d=0;for(e=this._active_combos.length;0<=e?de;b=0<=e?++d:--d)if(c=this._active_combos[b],c===a){a=this._active_combos.splice(b,1)[0];a.reset();break}};g.prototype._get_possible_sequences=function(){var a, +c,b,d,e,f,h,j,g,n,k,l;h=[];g=this._registered_combos;b=0;for(d=g.length;b=n;c=1<=n?++e:--e)if(l=this._sequence.slice(-c),a.is_sequence){if(0>i.call(a.keys,"shift")&&(l=v(l,function(a){return"shift"!==a}),!l.length))continue;c=j=0;for(k=l.length;0<=k?jk;c=0<=k?++j:--j)if(a.keys[c]===l[c])f=!0;else{f=!1;break}f&&h.push(a)}}return h};g.prototype._add_key_to_sequence=function(a,c){var b,d,e,f;this._sequence.push(a);f=this._get_possible_sequences(); +if(f.length){d=0;for(e=f.length;d=n;b=1<=n?++f:--f)if(m=v(this._sequence, +function(a){return 0<=i.call(c.keys,"shift")?!0:"shift"!==a}).slice(-b),c.keys.length===m.length){b=g=0;for(k=m.length;0<=k?gk;b=0<=k?++g:--g)if(l=m[b],!(0>i.call(c.keys,"shift")&&"shift"===l)&&!("shift"===a&&0>i.call(c.keys,"shift")))if(c.keys[b]===l)h=!0;else{h=!1;break}}if(h)return c.is_exclusive&&(this._sequence=[]),c}return!1};g.prototype._receive_input=function(a,c){var b;if(this._prevent_capture)this._keys_down.length&&(this._keys_down=[]);else if(b=y(a.keyCode||a.key),(c||this._keys_down.length|| +!("alt"===b||b===o))&&b)return c?this._key_down(b,a):this._key_up(b,a)};g.prototype._fire=function(a,c,b,d){"function"===typeof c["on_"+a]&&this._prevent_default(b,!0!==c["on_"+a].call(c["this"],b,c.count,d));"release"===a&&(c.count=0);if("keyup"===a)return c.keyup_fired=!0};g.prototype._match_combo_arrays=function(a,c){var b,d,e,f;e=this._registered_combos;b=0;for(d=e.length;be;b=0<=e?++d:--d)this._keys_down[b]===h&&this._keys_down.splice(b,1)}d=this._get_active_combos(a);h=this._get_potential_combos(a);f=0;for(e=d.length;fi.call(this._keys_down,a)&&this._keys_down.push(a)}; +g.prototype._handle_combo_down=function(a,c,b,d){var e,f,h,g,m;if(0>i.call(a.keys,b))return!1;this._prevent_default(d,a&&a.prevent_default);e=!1;if(0<=i.call(this._keys_down,b)&&(e=!0,!a.allows_key_repeat()))return!1;m=this._add_to_active_combos(a,b);b=a.keyup_fired=!1;if(a.is_exclusive){f=0;for(h=c.length;fa.keys.length){b=!0;break}}if(!b&&(a.is_counting&&"function"===typeof a.on_keydown&&(a.count+=1),m))return this._fire("keydown",a,d,e)};g.prototype._key_up= +function(a,c){var b,d,e,f,h,g;d=a;(b=z(a,c))&&(a=b);b=s[d];c.shiftKey?b&&0<=i.call(this._keys_down,b)||(a=d):d&&0<=i.call(this._keys_down,d)||(a=b);(f=this._get_sequence(a))&&this._fire("keyup",f,c);if(0>i.call(this._keys_down,a))return!1;f=h=0;for(g=this._keys_down.length;0<=g?hg;f=0<=g?++h:--h)if((e=this._keys_down[f])===a||e===b||e===d){this._keys_down.splice(f,1);break}d=this._active_combos.length;e=[];g=this._active_combos;h=0;for(f=g.length;hd;b=0<=d?++c:--c)if(a===i._registered_combos[b]){i._registered_combos.splice(b, -1);break}else e.push(void 0);return e};if(a instanceof x)return b(a);"string"===typeof a&&(a=a.split(" "));f=this._registered_combos;g=[];d=0;for(e=f.length;de;b=0<=e?++d:--d)if(a[b]!==c[b])return!1;return!0};F=function(a,c){var b,d,e;d=0;for(e=a.length;dj.call(c,b))return!1;return!0};B=Array.prototype.indexOf||function(a,c){var b,d,e;b=d=0;for(e=a.length;0<=e?d<=e:d>=e;b=0<=e?++d:--d)if(a[b]===c)return b;return-1};C=function(a,c){var b,d,e,f;e=d=0;for(f=a.length;e=d)d=b;else return!1;return!0}; -p=function(){if(m.debug)return console.log.apply(console,arguments)};G=function(a){var c,b,d;c=!1;for(d in q)if(b=q[d],a===b){c=!0;break}if(!c)for(d in s)if(b=s[d],a===b){c=!0;break}return c};I=function(a){var c,b,d,e,f,g,i;f=!0;a.keys.length||p("You're trying to bind a combo with no keys:",a);b=g=0;for(i=a.keys.length;0<=i?gi;b=0<=i?++g:--g)d=a.keys[b],(c=H[d])&&(d=a.keys[b]=c),"meta"===d&&a.keys.splice(b,1,o),"cmd"===d&&p('Warning: use the "meta" key rather than "cmd" for Windows compatibility'); -i=a.keys;c=0;for(g=i.length;c",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(","0":")"};q={"0":"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift", +(a.keys=a.keys.split(" "));b=this._defaults;for(c in b)D.call(b,c)&&(d=b[c],void 0===a[c]&&(a[c]=d));a=new w(a);if(H(a))return this._registered_combos.push(a),a};g.prototype.register_many=function(a){var c,b,d,e;e=[];b=0;for(d=a.length;bd;b=0<=d?++c:--c)if(a===i._registered_combos[b]){i._registered_combos.splice(b, +1);break}else e.push(void 0);return e};if(a instanceof w)return g(a);"string"===typeof a&&(a=a.split(" "));e=this._registered_combos;f=[];b=0;for(d=e.length;be;b=0<=e?++d:--d)if(a[b]!==c[b])return!1;return!0};E=function(a,c){var b,d,e;d=0;for(e=a.length;di.call(c,b))return!1;return!0};A=Array.prototype.indexOf||function(a,c){var b,d,e;b=d=0;for(e=a.length;0<=e?d<=e:d>=e;b=0<=e?++d:--d)if(a[b]===c)return b;return-1};B=function(a,c){var b,d,e,f;d=f=0;for(e=a.length;d=f)f=b;else return!1;return!0}; +p=function(){if(m.debug)return console.log.apply(console,arguments)};F=function(a){var c,b,d;b=!1;for(c in q)if(d=q[c],a===d){b=!0;break}if(!b)for(c in s)if(d=s[c],a===d){b=!0;break}return b};H=function(a){var c,b,d,e,f,g,j;j=!0;a.keys.length||p("You're trying to bind a combo with no keys:",a);b=e=0;for(f=a.keys.length;0<=f?ef;b=0<=f?++e:--e)d=a.keys[b],(c=G[d])&&(d=a.keys[b]=c),"meta"===d&&a.keys.splice(b,1,o),"cmd"===d&&p('Warning: use the "meta" key rather than "cmd" for Windows compatibility'); +f=a.keys;e=0;for(c=f.length;e",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(","0":")"};q={"0":"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift", 17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"cmd",92:"cmd",93:"cmd",96:"num_0",97:"num_1",98:"num_2",99:"num_3", 100:"num_4",101:"num_5",102:"num_6",103:"num_7",104:"num_8",105:"num_9",106:"num_multiply",107:"num_add",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",124:"print",144:"num",145:"scroll",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",225:"alt",57392:"ctrl",63289:"num",59:";",61:"=",173:"-"};m._keycode_dictionary= -q;m._is_array_in_array_sorted=C;-1!==navigator.userAgent.indexOf("Mac OS X")&&(o="cmd");-1!==navigator.userAgent.indexOf("Opera")&&(q["17"]="cmd");"function"===typeof define&&define.amd?define([],function(){return m}):"undefined"!==typeof exports&&null!==exports?exports.keypress=m:window.keypress=m}).call(this); +q;m._is_array_in_array_sorted=B;-1!==navigator.userAgent.indexOf("Mac OS X")&&(o="cmd");-1!==navigator.userAgent.indexOf("Opera")&&(q["17"]="cmd");"function"===typeof define&&define.amd?define([],function(){return m}):"undefined"!==typeof exports&&null!==exports?exports.keypress=m:window.keypress=m}).call(this); diff --git a/keypress.coffee b/keypress.coffee index c6287f0..c58f820 100644 --- a/keypress.coffee +++ b/keypress.coffee @@ -146,7 +146,7 @@ class keypress.Listener _bug_catcher: (e) -> # This seems to be Mac specific weirdness, so we'll target "cmd" as metaKey # Force a keyup for non-modifier keys when command is held because they don't fire - if _metakey is "cmd" and "cmd" in @_keys_down and _convert_key_to_readable(e.keyCode) not in ["cmd", "shift", "alt", "caps", "tab"] + if _metakey is "cmd" and "cmd" in @_keys_down and _convert_key_to_readable(e.keyCode || e.key) not in ["cmd", "shift", "alt", "caps", "tab"] @_receive_input e, false # Note: we're currently ignoring the fact that this doesn't catch the bug that a keyup # will not fire if you keydown a combo, then press and hold cmd, then keyup the combo. @@ -336,7 +336,7 @@ class keypress.Listener if @_prevent_capture @_keys_down = [] if @_keys_down.length return - key = _convert_key_to_readable e.keyCode + key = _convert_key_to_readable (e.keyCode || e.key) # Catch tabbing out of a non-capturing state if !is_keydown and !@_keys_down.length and key in ["alt", _metakey] return diff --git a/keypress.js b/keypress.js index 4d08671..94c47f1 100644 --- a/keypress.js +++ b/keypress.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.8.0 +// Generated by CoffeeScript 1.10.0 /* Copyright 2014 David Mauro @@ -40,9 +40,9 @@ Combo options available and their defaults: */ (function() { - var Combo, keypress, _change_keycodes_by_browser, _compare_arrays, _compare_arrays_sorted, _convert_key_to_readable, _convert_to_shifted_key, _decide_meta_key, _factory_defaults, _filter_array, _index_of_in_array, _is_array_in_array, _is_array_in_array_sorted, _key_is_valid, _keycode_alternate_names, _keycode_dictionary, _keycode_shifted_keys, _log_error, _metakey, _modifier_event_mapping, _modifier_keys, _validate_combo, - __hasProp = {}.hasOwnProperty, - __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; + var Combo, _change_keycodes_by_browser, _compare_arrays, _compare_arrays_sorted, _convert_key_to_readable, _convert_to_shifted_key, _decide_meta_key, _factory_defaults, _filter_array, _index_of_in_array, _is_array_in_array, _is_array_in_array_sorted, _key_is_valid, _keycode_alternate_names, _keycode_dictionary, _keycode_shifted_keys, _log_error, _metakey, _modifier_event_mapping, _modifier_keys, _validate_combo, keypress, + hasProp = {}.hasOwnProperty, + indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; _factory_defaults = { is_unordered: false, @@ -65,7 +65,7 @@ Combo options available and their defaults: function Combo(dictionary) { var property, value; for (property in dictionary) { - if (!__hasProp.call(dictionary, property)) continue; + if (!hasProp.call(dictionary, property)) continue; value = dictionary[property]; if (value !== false) { this[property] = value; @@ -108,7 +108,7 @@ Combo options available and their defaults: this._prevent_capture = false; this._defaults = defaults || {}; for (property in _factory_defaults) { - if (!__hasProp.call(_factory_defaults, property)) continue; + if (!hasProp.call(_factory_defaults, property)) continue; value = _factory_defaults[property]; this._defaults[property] = this._defaults[property] || value; } @@ -136,10 +136,10 @@ Combo options available and their defaults: })(this)); this.blur_event = attach_handler(window, "blur", (function(_this) { return function() { - var key, _i, _len, _ref; - _ref = _this._keys_down; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - key = _ref[_i]; + var key, l, len, ref; + ref = _this._keys_down; + for (l = 0, len = ref.length; l < len; l++) { + key = ref[l]; _this._key_up(key, {}); } return _this._keys_down = []; @@ -162,14 +162,14 @@ Combo options available and their defaults: }; Listener.prototype._bug_catcher = function(e) { - var _ref; - if (_metakey === "cmd" && __indexOf.call(this._keys_down, "cmd") >= 0 && ((_ref = _convert_key_to_readable(e.keyCode)) !== "cmd" && _ref !== "shift" && _ref !== "alt" && _ref !== "caps" && _ref !== "tab")) { + var ref; + if (_metakey === "cmd" && indexOf.call(this._keys_down, "cmd") >= 0 && ((ref = _convert_key_to_readable(e.keyCode || e.key)) !== "cmd" && ref !== "shift" && ref !== "alt" && ref !== "caps" && ref !== "tab")) { return this._receive_input(e, false); } }; Listener.prototype._cmd_bug_check = function(combo_keys) { - if (_metakey === "cmd" && __indexOf.call(this._keys_down, "cmd") >= 0 && __indexOf.call(combo_keys, "cmd") < 0) { + if (_metakey === "cmd" && indexOf.call(this._keys_down, "cmd") >= 0 && indexOf.call(combo_keys, "cmd") < 0) { return false; } return true; @@ -204,7 +204,7 @@ Combo options available and their defaults: })(this)); this._fuzzy_match_combo_arrays(keys_down, (function(_this) { return function(match) { - if (__indexOf.call(active_combos, match) >= 0) { + if (indexOf.call(active_combos, match) >= 0) { return; } if (!(match.is_solitary || !_this._cmd_bug_check(match.keys))) { @@ -216,15 +216,15 @@ Combo options available and their defaults: }; Listener.prototype._get_potential_combos = function(key) { - var combo, potentials, _i, _len, _ref; + var combo, l, len, potentials, ref; potentials = []; - _ref = this._registered_combos; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - combo = _ref[_i]; + ref = this._registered_combos; + for (l = 0, len = ref.length; l < len; l++) { + combo = ref[l]; if (combo.is_sequence) { continue; } - if (__indexOf.call(combo.keys, key) >= 0 && this._cmd_bug_check(combo.keys)) { + if (indexOf.call(combo.keys, key) >= 0 && this._cmd_bug_check(combo.keys)) { potentials.push(combo); } } @@ -232,35 +232,35 @@ Combo options available and their defaults: }; Listener.prototype._add_to_active_combos = function(combo) { - var active_combo, active_key, active_keys, already_replaced, combo_key, i, should_prepend, should_replace, _i, _j, _k, _len, _len1, _ref, _ref1; + var active_combo, active_key, active_keys, already_replaced, combo_key, i, l, len, len1, m, n, ref, ref1, should_prepend, should_replace; should_replace = false; should_prepend = true; already_replaced = false; - if (__indexOf.call(this._active_combos, combo) >= 0) { + if (indexOf.call(this._active_combos, combo) >= 0) { return true; } else if (this._active_combos.length) { - for (i = _i = 0, _ref = this._active_combos.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + for (i = l = 0, ref = this._active_combos.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { active_combo = this._active_combos[i]; if (!(active_combo && active_combo.is_exclusive && combo.is_exclusive)) { continue; } active_keys = active_combo.keys; if (!should_replace) { - for (_j = 0, _len = active_keys.length; _j < _len; _j++) { - active_key = active_keys[_j]; + for (m = 0, len = active_keys.length; m < len; m++) { + active_key = active_keys[m]; should_replace = true; - if (__indexOf.call(combo.keys, active_key) < 0) { + if (indexOf.call(combo.keys, active_key) < 0) { should_replace = false; break; } } } if (should_prepend && !should_replace) { - _ref1 = combo.keys; - for (_k = 0, _len1 = _ref1.length; _k < _len1; _k++) { - combo_key = _ref1[_k]; + ref1 = combo.keys; + for (n = 0, len1 = ref1.length; n < len1; n++) { + combo_key = ref1[n]; should_prepend = false; - if (__indexOf.call(active_keys, combo_key) < 0) { + if (indexOf.call(active_keys, combo_key) < 0) { should_prepend = true; break; } @@ -290,8 +290,8 @@ Combo options available and their defaults: }; Listener.prototype._remove_from_active_combos = function(combo) { - var active_combo, i, _i, _ref; - for (i = _i = 0, _ref = this._active_combos.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + var active_combo, i, l, ref; + for (i = l = 0, ref = this._active_combos.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { active_combo = this._active_combos[i]; if (active_combo === combo) { combo = this._active_combos.splice(i, 1)[0]; @@ -302,17 +302,17 @@ Combo options available and their defaults: }; Listener.prototype._get_possible_sequences = function() { - var combo, i, j, match, matches, sequence, _i, _j, _k, _len, _ref, _ref1, _ref2; + var combo, i, j, l, len, m, match, matches, n, ref, ref1, ref2, sequence; matches = []; - _ref = this._registered_combos; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - combo = _ref[_i]; - for (j = _j = 1, _ref1 = this._sequence.length; 1 <= _ref1 ? _j <= _ref1 : _j >= _ref1; j = 1 <= _ref1 ? ++_j : --_j) { + ref = this._registered_combos; + for (l = 0, len = ref.length; l < len; l++) { + combo = ref[l]; + for (j = m = 1, ref1 = this._sequence.length; 1 <= ref1 ? m <= ref1 : m >= ref1; j = 1 <= ref1 ? ++m : --m) { sequence = this._sequence.slice(-j); if (!combo.is_sequence) { continue; } - if (__indexOf.call(combo.keys, "shift") < 0) { + if (indexOf.call(combo.keys, "shift") < 0) { sequence = _filter_array(sequence, function(key) { return key !== "shift"; }); @@ -320,7 +320,7 @@ Combo options available and their defaults: continue; } } - for (i = _k = 0, _ref2 = sequence.length; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; i = 0 <= _ref2 ? ++_k : --_k) { + for (i = n = 0, ref2 = sequence.length; 0 <= ref2 ? n < ref2 : n > ref2; i = 0 <= ref2 ? ++n : --n) { if (combo.keys[i] === sequence[i]) { match = true; } else { @@ -337,12 +337,12 @@ Combo options available and their defaults: }; Listener.prototype._add_key_to_sequence = function(key, e) { - var combo, sequence_combos, _i, _len; + var combo, l, len, sequence_combos; this._sequence.push(key); sequence_combos = this._get_possible_sequences(); if (sequence_combos.length) { - for (_i = 0, _len = sequence_combos.length; _i < _len; _i++) { - combo = sequence_combos[_i]; + for (l = 0, len = sequence_combos.length; l < len; l++) { + combo = sequence_combos[l]; this._prevent_default(e, combo.prevent_default); } if (this._sequence_timer) { @@ -359,16 +359,16 @@ Combo options available and their defaults: }; Listener.prototype._get_sequence = function(key) { - var combo, i, j, match, seq_key, sequence, _i, _j, _k, _len, _ref, _ref1, _ref2; - _ref = this._registered_combos; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - combo = _ref[_i]; + var combo, i, j, l, len, m, match, n, ref, ref1, ref2, seq_key, sequence; + ref = this._registered_combos; + for (l = 0, len = ref.length; l < len; l++) { + combo = ref[l]; if (!combo.is_sequence) { continue; } - for (j = _j = 1, _ref1 = this._sequence.length; 1 <= _ref1 ? _j <= _ref1 : _j >= _ref1; j = 1 <= _ref1 ? ++_j : --_j) { + for (j = m = 1, ref1 = this._sequence.length; 1 <= ref1 ? m <= ref1 : m >= ref1; j = 1 <= ref1 ? ++m : --m) { sequence = (_filter_array(this._sequence, function(seq_key) { - if (__indexOf.call(combo.keys, "shift") >= 0) { + if (indexOf.call(combo.keys, "shift") >= 0) { return true; } return seq_key !== "shift"; @@ -376,14 +376,14 @@ Combo options available and their defaults: if (combo.keys.length !== sequence.length) { continue; } - for (i = _k = 0, _ref2 = sequence.length; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; i = 0 <= _ref2 ? ++_k : --_k) { + for (i = n = 0, ref2 = sequence.length; 0 <= ref2 ? n < ref2 : n > ref2; i = 0 <= ref2 ? ++n : --n) { seq_key = sequence[i]; - if (__indexOf.call(combo.keys, "shift") < 0) { + if (indexOf.call(combo.keys, "shift") < 0) { if (seq_key === "shift") { continue; } } - if (key === "shift" && __indexOf.call(combo.keys, "shift") < 0) { + if (key === "shift" && indexOf.call(combo.keys, "shift") < 0) { continue; } if (combo.keys[i] === seq_key) { @@ -395,7 +395,6 @@ Combo options available and their defaults: } } if (match) { - debugger; if (combo.is_exclusive) { this._sequence = []; } @@ -413,7 +412,7 @@ Combo options available and their defaults: } return; } - key = _convert_key_to_readable(e.keyCode); + key = _convert_key_to_readable(e.keyCode || e.key); if (!is_keydown && !this._keys_down.length && (key === "alt" || key === _metakey)) { return; } @@ -440,10 +439,10 @@ Combo options available and their defaults: }; Listener.prototype._match_combo_arrays = function(potential_match, match_handler) { - var source_combo, _i, _len, _ref; - _ref = this._registered_combos; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - source_combo = _ref[_i]; + var l, len, ref, source_combo; + ref = this._registered_combos; + for (l = 0, len = ref.length; l < len; l++) { + source_combo = ref[l]; if ((!source_combo.is_unordered && _compare_arrays_sorted(potential_match, source_combo.keys)) || (source_combo.is_unordered && _compare_arrays(potential_match, source_combo.keys))) { match_handler(source_combo); } @@ -451,10 +450,10 @@ Combo options available and their defaults: }; Listener.prototype._fuzzy_match_combo_arrays = function(potential_match, match_handler) { - var source_combo, _i, _len, _ref; - _ref = this._registered_combos; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - source_combo = _ref[_i]; + var l, len, ref, source_combo; + ref = this._registered_combos; + for (l = 0, len = ref.length; l < len; l++) { + source_combo = ref[l]; if ((!source_combo.is_unordered && _is_array_in_array_sorted(source_combo.keys, potential_match)) || (source_combo.is_unordered && _is_array_in_array(source_combo.keys, potential_match))) { match_handler(source_combo); } @@ -462,11 +461,11 @@ Combo options available and their defaults: }; Listener.prototype._keys_remain = function(combo) { - var key, keys_remain, _i, _len, _ref; - _ref = combo.keys; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - key = _ref[_i]; - if (__indexOf.call(this._keys_down, key) >= 0) { + var key, keys_remain, l, len, ref; + ref = combo.keys; + for (l = 0, len = ref.length; l < len; l++) { + key = ref[l]; + if (indexOf.call(this._keys_down, key) >= 0) { keys_remain = true; break; } @@ -475,7 +474,7 @@ Combo options available and their defaults: }; Listener.prototype._key_down = function(key, e) { - var combo, combos, event_mod, i, mod, potential, potential_combos, sequence_combo, shifted_key, _i, _j, _k, _len, _len1, _ref; + var combo, combos, event_mod, i, l, len, len1, m, mod, n, potential, potential_combos, ref, sequence_combo, shifted_key; shifted_key = _convert_to_shifted_key(key, e); if (shifted_key) { key = shifted_key; @@ -490,7 +489,7 @@ Combo options available and their defaults: if (!e[event_mod]) { continue; } - if (mod === key || __indexOf.call(this._keys_down, mod) >= 0) { + if (mod === key || indexOf.call(this._keys_down, mod) >= 0) { continue; } this._keys_down.push(mod); @@ -500,11 +499,11 @@ Combo options available and their defaults: if (mod === key) { continue; } - if (__indexOf.call(this._keys_down, mod) >= 0 && !e[event_mod]) { + if (indexOf.call(this._keys_down, mod) >= 0 && !e[event_mod]) { if (mod === "cmd" && _metakey !== "cmd") { continue; } - for (i = _i = 0, _ref = this._keys_down.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + for (i = l = 0, ref = this._keys_down.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { if (this._keys_down[i] === mod) { this._keys_down.splice(i, 1); } @@ -513,29 +512,29 @@ Combo options available and their defaults: } combos = this._get_active_combos(key); potential_combos = this._get_potential_combos(key); - for (_j = 0, _len = combos.length; _j < _len; _j++) { - combo = combos[_j]; + for (m = 0, len = combos.length; m < len; m++) { + combo = combos[m]; this._handle_combo_down(combo, potential_combos, key, e); } if (potential_combos.length) { - for (_k = 0, _len1 = potential_combos.length; _k < _len1; _k++) { - potential = potential_combos[_k]; + for (n = 0, len1 = potential_combos.length; n < len1; n++) { + potential = potential_combos[n]; this._prevent_default(e, potential.prevent_default); } } - if (__indexOf.call(this._keys_down, key) < 0) { + if (indexOf.call(this._keys_down, key) < 0) { this._keys_down.push(key); } }; Listener.prototype._handle_combo_down = function(combo, potential_combos, key, e) { - var is_autorepeat, is_other_exclusive, potential_combo, result, _i, _len; - if (__indexOf.call(combo.keys, key) < 0) { + var is_autorepeat, is_other_exclusive, l, len, potential_combo, result; + if (indexOf.call(combo.keys, key) < 0) { return false; } this._prevent_default(e, combo && combo.prevent_default); is_autorepeat = false; - if (__indexOf.call(this._keys_down, key) >= 0) { + if (indexOf.call(this._keys_down, key) >= 0) { is_autorepeat = true; if (!combo.allows_key_repeat()) { return false; @@ -545,8 +544,8 @@ Combo options available and their defaults: combo.keyup_fired = false; is_other_exclusive = false; if (combo.is_exclusive) { - for (_i = 0, _len = potential_combos.length; _i < _len; _i++) { - potential_combo = potential_combos[_i]; + for (l = 0, len = potential_combos.length; l < len; l++) { + potential_combo = potential_combos[l]; if (potential_combo.is_exclusive && potential_combo.keys.length > combo.keys.length) { is_other_exclusive = true; break; @@ -564,7 +563,7 @@ Combo options available and their defaults: }; Listener.prototype._key_up = function(key, e) { - var active_combo, active_combos_length, combo, combos, i, sequence_combo, shifted_key, unshifted_key, _i, _j, _k, _l, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3; + var active_combo, active_combos_length, combo, combos, i, l, len, len1, len2, m, n, o, ref, ref1, ref2, ref3, sequence_combo, shifted_key, unshifted_key; unshifted_key = key; shifted_key = _convert_to_shifted_key(key, e); if (shifted_key) { @@ -572,11 +571,11 @@ Combo options available and their defaults: } shifted_key = _keycode_shifted_keys[unshifted_key]; if (e.shiftKey) { - if (!(shifted_key && __indexOf.call(this._keys_down, shifted_key) >= 0)) { + if (!(shifted_key && indexOf.call(this._keys_down, shifted_key) >= 0)) { key = unshifted_key; } } else { - if (!(unshifted_key && __indexOf.call(this._keys_down, unshifted_key) >= 0)) { + if (!(unshifted_key && indexOf.call(this._keys_down, unshifted_key) >= 0)) { key = shifted_key; } } @@ -584,33 +583,33 @@ Combo options available and their defaults: if (sequence_combo) { this._fire("keyup", sequence_combo, e); } - if (__indexOf.call(this._keys_down, key) < 0) { + if (indexOf.call(this._keys_down, key) < 0) { return false; } - for (i = _i = 0, _ref = this._keys_down.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - if ((_ref1 = this._keys_down[i]) === key || _ref1 === shifted_key || _ref1 === unshifted_key) { + for (i = l = 0, ref = this._keys_down.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { + if ((ref1 = this._keys_down[i]) === key || ref1 === shifted_key || ref1 === unshifted_key) { this._keys_down.splice(i, 1); break; } } active_combos_length = this._active_combos.length; combos = []; - _ref2 = this._active_combos; - for (_j = 0, _len = _ref2.length; _j < _len; _j++) { - active_combo = _ref2[_j]; - if (__indexOf.call(active_combo.keys, key) >= 0) { + ref2 = this._active_combos; + for (m = 0, len = ref2.length; m < len; m++) { + active_combo = ref2[m]; + if (indexOf.call(active_combo.keys, key) >= 0) { combos.push(active_combo); } } - for (_k = 0, _len1 = combos.length; _k < _len1; _k++) { - combo = combos[_k]; + for (n = 0, len1 = combos.length; n < len1; n++) { + combo = combos[n]; this._handle_combo_up(combo, e, key); } if (active_combos_length > 1) { - _ref3 = this._active_combos; - for (_l = 0, _len2 = _ref3.length; _l < _len2; _l++) { - active_combo = _ref3[_l]; - if (active_combo === void 0 || __indexOf.call(combos, active_combo) >= 0) { + ref3 = this._active_combos; + for (o = 0, len2 = ref3.length; o < len2; o++) { + active_combo = ref3[o]; + if (active_combo === void 0 || indexOf.call(combos, active_combo) >= 0) { continue; } if (!this._keys_remain(active_combo)) { @@ -666,14 +665,14 @@ Combo options available and their defaults: }; Listener.prototype.register_combo = function(combo_dictionary) { - var combo, property, value, _ref; + var combo, property, ref, value; if (typeof combo_dictionary["keys"] === "string") { combo_dictionary["keys"] = combo_dictionary["keys"].split(" "); } - _ref = this._defaults; - for (property in _ref) { - if (!__hasProp.call(_ref, property)) continue; - value = _ref[property]; + ref = this._defaults; + for (property in ref) { + if (!hasProp.call(ref, property)) continue; + value = ref[property]; if (combo_dictionary[property] === void 0) { combo_dictionary[property] = value; } @@ -686,33 +685,33 @@ Combo options available and their defaults: }; Listener.prototype.register_many = function(combo_array) { - var combo, _i, _len, _results; - _results = []; - for (_i = 0, _len = combo_array.length; _i < _len; _i++) { - combo = combo_array[_i]; - _results.push(this.register_combo(combo)); + var combo, l, len, results; + results = []; + for (l = 0, len = combo_array.length; l < len; l++) { + combo = combo_array[l]; + results.push(this.register_combo(combo)); } - return _results; + return results; }; Listener.prototype.unregister_combo = function(keys_or_combo) { - var combo, unregister_combo, _i, _len, _ref, _results; + var combo, l, len, ref, results, unregister_combo; if (!keys_or_combo) { return false; } unregister_combo = (function(_this) { return function(combo) { - var i, _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = _this._registered_combos.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + var i, l, ref, results; + results = []; + for (i = l = 0, ref = _this._registered_combos.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { if (combo === _this._registered_combos[i]) { _this._registered_combos.splice(i, 1); break; } else { - _results.push(void 0); + results.push(void 0); } } - return _results; + return results; }; })(this); if (keys_or_combo instanceof Combo) { @@ -721,31 +720,31 @@ Combo options available and their defaults: if (typeof keys_or_combo === "string") { keys_or_combo = keys_or_combo.split(" "); } - _ref = this._registered_combos; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - combo = _ref[_i]; + ref = this._registered_combos; + results = []; + for (l = 0, len = ref.length; l < len; l++) { + combo = ref[l]; if (combo == null) { continue; } if ((combo.is_unordered && _compare_arrays(keys_or_combo, combo.keys)) || (!combo.is_unordered && _compare_arrays_sorted(keys_or_combo, combo.keys))) { - _results.push(unregister_combo(combo)); + results.push(unregister_combo(combo)); } else { - _results.push(void 0); + results.push(void 0); } } - return _results; + return results; } }; Listener.prototype.unregister_many = function(combo_array) { - var combo, _i, _len, _results; - _results = []; - for (_i = 0, _len = combo_array.length; _i < _len; _i++) { - combo = combo_array[_i]; - _results.push(this.unregister_combo(combo)); + var combo, l, len, results; + results = []; + for (l = 0, len = combo_array.length; l < len; l++) { + combo = combo_array[l]; + results.push(this.unregister_combo(combo)); } - return _results; + return results; }; Listener.prototype.get_registered_combos = function() { @@ -794,27 +793,27 @@ Combo options available and their defaults: return array.filter(callback); } else { return (function() { - var _i, _len, _results; - _results = []; - for (_i = 0, _len = array.length; _i < _len; _i++) { - element = array[_i]; + var l, len, results; + results = []; + for (l = 0, len = array.length; l < len; l++) { + element = array[l]; if (callback(element)) { - _results.push(element); + results.push(element); } } - return _results; + return results; })(); } }; _compare_arrays = function(a1, a2) { - var item, _i, _len; + var item, l, len; if (a1.length !== a2.length) { return false; } - for (_i = 0, _len = a1.length; _i < _len; _i++) { - item = a1[_i]; - if (__indexOf.call(a2, item) >= 0) { + for (l = 0, len = a1.length; l < len; l++) { + item = a1[l]; + if (indexOf.call(a2, item) >= 0) { continue; } return false; @@ -823,11 +822,11 @@ Combo options available and their defaults: }; _compare_arrays_sorted = function(a1, a2) { - var i, _i, _ref; + var i, l, ref; if (a1.length !== a2.length) { return false; } - for (i = _i = 0, _ref = a1.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + for (i = l = 0, ref = a1.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { if (a1[i] !== a2[i]) { return false; } @@ -836,10 +835,10 @@ Combo options available and their defaults: }; _is_array_in_array = function(a1, a2) { - var item, _i, _len; - for (_i = 0, _len = a1.length; _i < _len; _i++) { - item = a1[_i]; - if (__indexOf.call(a2, item) < 0) { + var item, l, len; + for (l = 0, len = a1.length; l < len; l++) { + item = a1[l]; + if (indexOf.call(a2, item) < 0) { return false; } } @@ -847,8 +846,8 @@ Combo options available and their defaults: }; _index_of_in_array = Array.prototype.indexOf || function(a, item) { - var i, _i, _ref; - for (i = _i = 0, _ref = a.length; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { + var i, l, ref; + for (i = l = 0, ref = a.length; 0 <= ref ? l <= ref : l >= ref; i = 0 <= ref ? ++l : --l) { if (a[i] === item) { return i; } @@ -857,10 +856,10 @@ Combo options available and their defaults: }; _is_array_in_array_sorted = function(a1, a2) { - var index, item, prev, _i, _len; + var index, item, l, len, prev; prev = 0; - for (_i = 0, _len = a1.length; _i < _len; _i++) { - item = a1[_i]; + for (l = 0, len = a1.length; l < len; l++) { + item = a1[l]; index = _index_of_in_array.call(a2, item); if (index >= prev) { prev = index; @@ -878,7 +877,7 @@ Combo options available and their defaults: }; _key_is_valid = function(key) { - var valid, valid_key, _; + var _, valid, valid_key; valid = false; for (_ in _keycode_dictionary) { valid_key = _keycode_dictionary[_]; @@ -900,12 +899,12 @@ Combo options available and their defaults: }; _validate_combo = function(combo) { - var alt_name, i, key, mod_key, non_modifier_keys, property, validated, value, _i, _j, _k, _len, _len1, _ref, _ref1; + var alt_name, i, key, l, len, len1, m, mod_key, n, non_modifier_keys, property, ref, ref1, validated, value; validated = true; if (!combo.keys.length) { _log_error("You're trying to bind a combo with no keys:", combo); } - for (i = _i = 0, _ref = combo.keys.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + for (i = l = 0, ref = combo.keys.length; 0 <= ref ? l < ref : l > ref; i = 0 <= ref ? ++l : --l) { key = combo.keys[i]; alt_name = _keycode_alternate_names[key]; if (alt_name) { @@ -918,18 +917,18 @@ Combo options available and their defaults: _log_error("Warning: use the \"meta\" key rather than \"cmd\" for Windows compatibility"); } } - _ref1 = combo.keys; - for (_j = 0, _len = _ref1.length; _j < _len; _j++) { - key = _ref1[_j]; + ref1 = combo.keys; + for (m = 0, len = ref1.length; m < len; m++) { + key = ref1[m]; if (!_key_is_valid(key)) { _log_error("Do not recognize the key \"" + key + "\""); validated = false; } } - if (__indexOf.call(combo.keys, "meta") >= 0 || __indexOf.call(combo.keys, "cmd") >= 0) { + if (indexOf.call(combo.keys, "meta") >= 0 || indexOf.call(combo.keys, "cmd") >= 0) { non_modifier_keys = combo.keys.slice(); - for (_k = 0, _len1 = _modifier_keys.length; _k < _len1; _k++) { - mod_key = _modifier_keys[_k]; + for (n = 0, len1 = _modifier_keys.length; n < len1; n++) { + mod_key = _modifier_keys[n]; if ((i = _index_of_in_array.call(non_modifier_keys, mod_key)) > -1) { non_modifier_keys.splice(i, 1); }