Skip to content

Instantly share code, notes, and snippets.

@kennyp
Created August 10, 2012 20:32
Show Gist options
  • Save kennyp/3317642 to your computer and use it in GitHub Desktop.
Save kennyp/3317642 to your computer and use it in GitHub Desktop.
Key Sequences
/*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