From 3e0dbe73c6b051bfbf6a0636178b2ebadcb8db63 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Fri, 3 Jan 2014 13:22:47 -0700 Subject: [PATCH] Built --- genie.min.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genie.min.js b/genie.min.js index de41cc6..1671eb9 100644 --- a/genie.min.js +++ b/genie.min.js @@ -1,8 +1,8 @@ /** * genie - v0.3.0 @license - * (c) 2014-01-01 - Kent C. Dodds + * (c) 2014-01-03 - Kent C. Dodds * A JavaScript library committed to improving user experience by empowering users to interact with web apps using the keyboard (better than cryptic shortcuts). * Freely distributed under the MIT license * https://github.com/kentcdodds/genie */ -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(b):a.genie=b()}(this,function(){"use strict";function a(c){if(N(c)){var e=[];return K(c,function(b){e.push(a(b))}),e}var f=c.id||"g-"+ib++,g={id:f,context:b(c.context),data:c.data||{},magicWords:C(c.magicWords),action:d(c.action)};return g.data.timesMade={total:0,magicWords:{}},hb[f]=g,hb[f]}function b(a){var b=a||kb;return b=O(b)||N(b)?{any:C(b)}:c(a)}function c(a){function b(b){a[b]&&(a[b]=C(a[b]))}return b("all"),b("any"),b("none"),a}function d(a){return O(a)&&(a={destination:a}),P(a)?function(){a.openNewTab?window.open(a.destination,"_blank"):window.location.href=a.destination}:a}function e(a){P(a)&&a.id&&(a=a.id);var b=hb[a];return delete hb[a],K(jb,function(b,c){-1!==b.indexOf(a)&&jb[c].splice(b.indexOf(a),1),jb[c].length||delete jb[c]}),b}function f(a,b,c){var d=h(a,b,c);return K(d,function(a,b){d[b]=e(a)}),d}function g(a){a=a||kb;var b=[];return K(hb,function(c){(v(a)||v(c.context)||x(c,a))&&b.push(c)}),b}function h(a,b,c){var d=[];return b=b||"any",K(hb,function(e){var f=i(e,c);!J(f)&&("all"===b&&H(f,a)||"none"===b&&G(f,a)||"any"===b&&F(f,a))&&d.push(e)}),d}function i(a,b){var c=[];return b=b||["all","any","none"],b=C(b),K(b,function(b){a.context[b]&&(c=c.concat(a.context[b]))}),c}function j(a){if(N(a)){var b=[];return K(a,function(a){b.push(hb[a])}),b}return hb[a]}function k(){var a=U();return U({wishes:{},noWishMerge:!0,previousId:0,enteredMagicWords:{},context:kb,previousContext:kb,enabled:!0}),a}function l(a){a=a||"";var b=jb[a]||[],c=m(b,a);b=b.concat(c);var d=[];return K(b,function(a){var b=hb[a];b&&w(b)&&d.push(b)}),d}function m(a,b){var c=[],d=[];K(hb,function(d,e){if(!I(a,e)&&w(d)){var f=n(d.magicWords,b);f!==rb.noMatch&&(c[f]=c[f]||[],c[f].push(e))}});for(var e=c.length;e>0;e--){var f=c[e-1];f&&(d=d.concat(f))}return d}function n(a,b){var c=rb.noMatch;return K(a,function(a){var d=o(a,b);return d>c&&(c=d),c!==rb.equals}),c}function o(a,b){return a=(""+a).toLowerCase(),b=(""+b).toLowerCase(),b.length>a.length?rb.noMatch:a===b?rb.equals:0===a.indexOf(b)?rb.startsWith:-1!==a.indexOf(" "+b)?rb.wordStartsWith:-1!==a.indexOf(b)?rb.contains:1===b.length?rb.noMatch:-1!==p(a).indexOf(b)?rb.acronym:q(a,b)}function p(a){var b="",c=a.split(" ");return K(c,function(a){var c=a.split("-");K(c,function(a){b+=a.substr(0,1)})}),b}function q(a,b){function c(a,b){for(var c=!1,e=d;e0&&(c=d[0])}return c}function t(a){return!R([a,hb[a.id]])&&!T(a.action)&&w(a)}function u(a,b){a.action(a,b);var c=a.data.timesMade;c.total++,c.magicWords[b]=c.magicWords[b]||0,c.magicWords[b]++}function v(a){return P(a)||(a=C(a)),N(a)&&1===a.length?a[0]===kb[0]:a.any&&1===a.any.length?a.any[0]===kb[0]:!1}function w(a){return v(lb)||v(a.context)||a.context===lb||x(a,lb)}function x(a,b){var c,d=a.context.any||[],e=a.context.all||[],f=a.context.none||[],g=J(d)||F(b,d),h=b.length>=e.length&&H(b,e),i=G(b,f);return c=g&&h&&i}function y(a,b){jb[b]=jb[b]||[];var c=a.id,d=jb[b],e=d.indexOf(c);0!==e&&z(c,d,e)}function z(a,b,c){if(-1!==c&&b.splice(c,1),1!==c&&b.length>0){var d=b[0];b[0]=a,a=d}b.unshift(a)}function A(a){var b={add:[],remove:[]};return K(mb,function(c){var d=!1,e=c.contexts,f=c.regexes,g=c.paths;K(f,function(c){c.lastIndex=0;var f=c.exec(a);if(f&&f.length>0){var g=[];K(e,function(a){var b=a.replace(qb,function(a,b){return f[b]});g.push(b)}),b.add=b.add.concat(g),d=!0}return!d}),d||(K(g,function(c){return a===c&&(b.add=b.add.concat(e),d=!0),!d}),d||(b.remove=b.remove.concat(e)))}),b}function B(){var a=[];return K(mb,function(b){var c=b.contexts;K(c,function(b){if(qb.test(b)){var c=b.replace(qb,".+?");K(lb,function(b){new RegExp(c).test(b)&&a.push(b)})}})}),a}function C(a){return a?N(a)?a:[a]:[]}function D(a,b){b=C(b);for(var c=0;c-1}function J(a){return T(a)?!0:N(a)?0===a.length:Q(a)?!1:!1}function K(a,b){Q(a)&&(a=C(a)),N(a)?L(a,b):M(a,b)}function L(a,b){for(var c,d=0;df?xb.push(e):xb[f]=e,e}function b(a){var b=a.id||"g-"+yb++,d={id:b,context:c(a.context),data:a.data||{},magicWords:M(a.magicWords),action:e(a.action)};return d.data.timesMade={total:0,magicWords:{}},d}function c(a){var b=a||Ab;return b=ab(b)||_(b)?{any:M(b)}:d(a)}function d(a){function b(b){a[b]&&(a[b]=M(a[b]))}return b("all"),b("any"),b("none"),a}function e(a){return ab(a)&&(a={destination:a}),bb(a)?function(){a.openNewTab?window.open(a.destination,"_blank"):window.location.href=a.destination}:a}function f(a){var b=xb.indexOf(a);return b||U(xb,function(c,d){return a===c.id||a.id===c.id?(b=d,a=c,!1):void 0}),xb.splice(b,1),g(a.id),a}function g(a){function b(c,d,e){U(c,function(d,e){if("wishes"===e){var f=d.indexOf(a);-1!==f&&d.splice(f,1),d.length||delete c[e]}else b(d,c,e)});var f=s(c,"wishes").length>0;!f&&d&&e&&delete d[e]}b(zb)}function h(a,b,c){var d=j(a,b,c);return U(d,function(a,b){d[b]=f(a)}),d}function i(a){a=a||Ab;var b=[];return U(xb,function(c){(E(a)||E(c.context)||G(c,a))&&b.push(c)}),b}function j(a,b,c){var d=[];return b=b||"any",U(xb,function(e){var f=k(e,c);!T(f)&&("all"===b&&R(f,a)||"none"===b&&Q(f,a)||"any"===b&&P(f,a))&&d.push(e)}),d}function k(a,b){var c=[];return b=b||["all","any","none"],b=M(b),U(b,function(b){a.context[b]&&(c=c.concat(a.context[b]))}),c}function l(a){if(_(a)){var b=[];return U(m(a),function(a){b.push(xb[a])}),b}var c=m(a);return c>-1?xb[c]:null}function m(a){var b=-1;if(_(a)){var c=[];return U(a,function(a){c.push(m(a))}),c}return U(xb,function(c,d){return c.id===a?(b=d,!1):void 0}),b}function n(){var a=gb();return gb({wishes:[],noWishMerge:!0,previousId:0,enteredMagicWords:{},context:Ab,previousContext:Ab,enabled:!0}),a}function o(a){a=(fb(a)?"":""+a).toLowerCase();var b=p(a),c=l(b),d=q(c),e=t(xb,b,a),f=l(e);return d.concat(f)}function p(a){var b=r(zb,a.split(""));return b?s(b,"wishes",!0):[]}function q(a){var b=[];return U(a,function(a){a&&F(a)&&b.push(a)}),b}function r(a,b){var c=a;b=M(b);var d=U(b,function(a){return c.hasOwnProperty(a)?(c=c[a],!0):!1});return d?c:null}function s(a,b,c){function d(a){U(a,function(a,f){if(f===b){var g=M(a);U(g,function(a){c&&S(e,a)||e.push(a)})}else e=e.concat(d(a))})}var e=[];return d(a),e}function t(a,b,c){var d=[],e=[];return U(a,function(a){if(F(a)){var e=u(a.magicWords,c);y(a,e,d,b)}},!0),U(d,function(a){a&&U(a,function(a){a&&(e=e.concat(a))})},!0),e}function u(a,b){var c={matchType:Ib.noMatch,magicWordIndex:-1};return U(a,function(a,d){var e=v(a,b);return e>c.matchType&&(c.matchType=e,c.magicWordIndex=d),c.matchType!==Ib.equals}),c}function v(a,b){return a=(""+a).toLowerCase(),b.length>a.length?Ib.noMatch:a===b?Ib.equals:0===a.indexOf(b)?Ib.startsWith:-1!==a.indexOf(" "+b)?Ib.wordStartsWith:-1!==a.indexOf(b)?Ib.contains:1===b.length?Ib.noMatch:-1!==w(a).indexOf(b)?Ib.acronym:x(a,b)}function w(a){var b="",c=a.split(" ");return U(c,function(a){var c=a.split("-");U(c,function(a){b+=a.substr(0,1)})}),b}function x(a,b){function c(a,b){for(var c=!1,e=d;e0&&(c=d[0])}return c}function C(a){return a&&!fb(a.action)&&F(a)}function D(a,b){a.action(a,b);var c=a.data.timesMade;c.total++,c.magicWords[b]=c.magicWords[b]||0,c.magicWords[b]++}function E(a){return bb(a)||(a=M(a)),_(a)&&1===a.length?a[0]===Ab[0]:a.any&&1===a.any.length?a.any[0]===Ab[0]:!1}function F(a){return E(Cb)||E(a.context)||a.context===Cb||G(a,Cb)}function G(a,b){var c,d=a.context.any||[],e=a.context.all||[],f=a.context.none||[],g=T(d)||P(b,d),h=b.length>=e.length&&R(b,e),i=Q(b,f);return c=g&&h&&i}function H(a,b){var c=I(zb,b);c.wishes=c.wishes||[];var d=c.wishes.indexOf(a.id);0!==d&&J(a.id,c.wishes,d)}function I(a,b){var c=b.substring(0,1),d=b.substring(1),e=a[c]=a[c]||{};return d?I(e,d):e}function J(a,b,c){if(-1!==c&&b.splice(c,1),1!==c&&b.length>0){var d=b[0];b[0]=a,a=d}b.unshift(a)}function K(a){var b={add:[],remove:[]};return U(Db,function(c){var d=!1,e=c.contexts,f=c.regexes,g=c.paths;U(f,function(c){c.lastIndex=0;var f=c.exec(a);if(f&&f.length>0){var g=[];U(e,function(a){var b=a.replace(Hb,function(a,b){return f[b]});g.push(b)}),b.add=b.add.concat(g),d=!0}return!d}),d||(U(g,function(c){return a===c&&(b.add=b.add.concat(e),d=!0),!d}),d||(b.remove=b.remove.concat(e)))}),b}function L(){var a=[];return U(Db,function(b){var c=b.contexts;U(c,function(b){if(Hb.test(b)){var c=b.replace(Hb,".+?");U(Cb,function(b){new RegExp(c).test(b)&&a.push(b)})}})}),a}function M(a){return a?_(a)?a:[a]:[]}function N(a,b){b=M(b),U(b,function(b){a.indexOf(b)<0&&a.push(b)})}function O(a,b){b=M(b);for(var c=0;c-1}function T(a){return fb(a)?!0:_(a)?0===a.length:cb(a)?!1:!1}function U(a,b,c){return cb(a)&&(a=M(a)),_(a)?V(a,b,c):Y(a,b)}function V(a,b,c){return Z(c)?W(a,b):X(a,b)}function W(a,b){for(var c=!0,d=a.length-1;d>=0&&(c=b(a[d],d,a),!$(c));d--);return c}function X(a,b){for(var c=!0,d=0;d