Created
August 10, 2012 20:32
-
-
Save kennyp/3317642 to your computer and use it in GitHub Desktop.
Key Sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint plusplus: true, continue: true */ | |
/*global define: false, alert: false */ | |
function trimString(str) { | |
'use strict'; | |
str = str.replace(/^\s\s*/, ''); | |
var ws = /\s/, | |
i = str.length; | |
while (ws.test(str.charAt(--i))); | |
return str.slice(0, i + 1); | |
} | |
define(['ender'], function ($) { | |
'use strict'; | |
var myKey = function (keys, scope, method) { | |
if (typeof method !== 'function') { | |
method = scope; | |
scope = 'all'; | |
} | |
keys.split(',').forEach(function (k) { | |
var series = trimString(k).split(/\s+/), nscope, i, l; | |
nscope = $.reduce($.initial(series), function (s, key) { | |
var newScope = [s, key].join('+'); | |
$.key(key, s, function () { | |
console.log('Changing Scope To: ' + newScope); | |
$.key.setScope(newScope); | |
setTimeout(function () { | |
console.log('Changing Scope Back To: ' + s); | |
$.key.setScope(s); | |
}, 500); | |
}); | |
return newScope; | |
}, scope); | |
$.key($.last(series), nscope, method); | |
}); | |
}; | |
return { | |
init: function () { | |
myKey('g o', function () { | |
console.log('You said go!'); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment