combokeys-capture
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -69,3 +69,2 @@ /* eslint-env node, browser */ | ||
module.exports.prototype.bindMultiple = require("./prototype/bindMultiple"); | ||
module.exports.prototype.unbind = require("./prototype/unbind"); | ||
module.exports.prototype.trigger = require("./prototype/trigger"); | ||
@@ -72,0 +71,0 @@ module.exports.prototype.reset = require("./prototype/reset.js"); |
@@ -15,3 +15,3 @@ /* eslint-env node, browser */ | ||
* @param {string=} action - "keypress", "keydown", or "keyup" | ||
* @returns void | ||
* @returns {Function} unbind function | ||
*/ | ||
@@ -22,4 +22,3 @@ module.exports = function(keys, callback, action) { | ||
keys = keys instanceof Array ? keys : [keys]; | ||
self.bindMultiple(keys, callback, action); | ||
return self; | ||
return self.bindMultiple(keys, callback, action); | ||
}; |
@@ -15,5 +15,12 @@ /* eslint-env node, browser */ | ||
var unbinders = []; | ||
for (var j = 0; j < combinations.length; ++j) { | ||
self.bindSingle(combinations[j], callback, action); | ||
unbinders.push(self.bindSingle(combinations[j], callback, action)); | ||
} | ||
return function(){ | ||
for(var ii=0; ii<unbinders.length; ii++){ | ||
unbinders[ii](); | ||
} | ||
}; | ||
}; |
@@ -73,7 +73,15 @@ /* eslint-env node, browser */ | ||
// ones are better suited to the key provided | ||
var unbinders = []; | ||
for (var j = 0; j < keys.length; ++j) { | ||
var isFinal = j + 1 === keys.length; | ||
var wrappedCallback = isFinal ? callbackAndReset : increaseSequence(action || self.getKeyInfo(keys[j + 1]).action); | ||
self.bindSingle(keys[j], wrappedCallback, action, combo, j); | ||
unbinders.push(self.bindSingle(keys[j], wrappedCallback, action, combo, j)); | ||
} | ||
return function(){ | ||
for( var ii=0; ii<unbinders.length; ii++){ | ||
unbinders[ii](); | ||
} | ||
}; | ||
}; |
@@ -17,5 +17,2 @@ /* eslint-env node, browser */ | ||
// store a direct mapped reference for use with Combokeys.trigger | ||
self.directMap[combination + ":" + action] = callback; | ||
// make sure multiple spaces in a row become a single space | ||
@@ -30,4 +27,3 @@ combination = combination.replace(/\s+/g, " "); | ||
if (sequence.length > 1) { | ||
self.bindSequence(combination, sequence, callback, action); | ||
return; | ||
return self.bindSequence(combination, sequence, callback, action); | ||
} | ||
@@ -37,9 +33,6 @@ | ||
// make sure to initialize array if this is the first time | ||
// make sure to initialize arrays if this is the first time | ||
// a callback is added for this key | ||
self.callbacks[info.key] = self.callbacks[info.key] || []; | ||
self.callbacks[info.key] = self.callbacks[info.key] || {sequences: [], singles: []}; | ||
// remove an existing match if there is one | ||
self.getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level); | ||
// add this call back to the array | ||
@@ -51,3 +44,5 @@ // if it is a sequence put it at the beginning | ||
// the sequence ones to come first | ||
self.callbacks[info.key][sequenceName ? "unshift" : "push"]({ | ||
var callbacksArray = self.callbacks[info.key][sequenceName ? 'sequences' : 'singles']; | ||
var callbackDefinition = { | ||
callback: callback, | ||
@@ -59,3 +54,11 @@ modifiers: info.modifiers, | ||
combo: combination | ||
}); | ||
}; | ||
callbacksArray.push(callbackDefinition); | ||
return function(){ | ||
index = callbacksArray.indexOf(callbackDefinition); | ||
callbacksArray.splice(index, 1); | ||
}; | ||
}; |
@@ -38,5 +38,11 @@ /* eslint-env node, browser */ | ||
// and see if any of them match | ||
for (j = 0; j < self.callbacks[character].length; ++j) { | ||
callback = self.callbacks[character][j]; | ||
var callbacks = self.callbacks[character].sequences.reverse().concat(self.callbacks[character].singles.reverse()); | ||
//stupid reverse function mutates array | ||
self.callbacks[character].sequences.reverse(); | ||
self.callbacks[character].singles.reverse(); | ||
for (j = 0; j < callbacks.length; ++j) { | ||
callback = callbacks[j]; | ||
// if a sequence name is not specified, but this is a sequence at | ||
@@ -63,14 +69,2 @@ // the wrong level then move onto the next match | ||
if ((action === "keypress" && !e.metaKey && !e.ctrlKey) || modifiersMatch(modifiers, callback.modifiers)) { | ||
// when you bind a combination or sequence a second time it | ||
// should overwrite the first one. if a sequenceName or | ||
// combination is specified in this call it does just that | ||
// | ||
// @todo make deleting its own method? | ||
var deleteCombo = !sequenceName && callback.combo === combination; | ||
var deleteSequence = sequenceName && callback.seq === sequenceName && callback.level === level; | ||
if (deleteCombo || deleteSequence) { | ||
self.callbacks[character].splice(j, 1); | ||
} | ||
matches.push(callback); | ||
@@ -77,0 +71,0 @@ } |
@@ -11,6 +11,3 @@ /* eslint-env node, browser */ | ||
module.exports = function(keys, action) { | ||
if (directMap[keys + ":" + action]) { | ||
directMap[keys + ":" + action]({}, keys); | ||
} | ||
return this; | ||
}; |
110
package.json
{ | ||
"name": "combokeys-capture", | ||
"version": "2.3.0", | ||
"description": "JavaScript library for handling keyboard shortcuts in the browser", | ||
"main": "index.js", | ||
"homepage": "https://github.com/omarstreak/combokeys", | ||
"implements": ["CommonJS/Modules/1.0"], | ||
"scripts": { | ||
"build": "mkdir -p dist ; ./node_modules/.bin/browserify index.js -o dist/combokeys.js --standalone Combokeys", | ||
"test": "./node_modules/zuul/bin/zuul --phantom -- test/test.combokeys.js test/plugins/test.*.js" | ||
"name": "combokeys-capture", | ||
"version": "2.4.0", | ||
"description": "JavaScript library for handling keyboard shortcuts in the browser", | ||
"main": "index.js", | ||
"homepage": "https://github.com/omarstreak/combokeys", | ||
"implements": [ | ||
"CommonJS/Modules/1.0" | ||
], | ||
"scripts": { | ||
"build": "mkdir -p dist ; ./node_modules/.bin/browserify index.js -o dist/combokeys.js --standalone Combokeys", | ||
"test": "./node_modules/zuul/bin/zuul --phantom -- test/test.combokeys.js test/plugins/test.*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/omarstreak/combokeys.git" | ||
}, | ||
"keywords": [ | ||
"keyboard", | ||
"shortcuts", | ||
"events", | ||
"browser" | ||
], | ||
"maintainers": [ | ||
{ | ||
"name": "Shahar Or", | ||
"email": "mightyiampresence@gmail.com", | ||
"web": "https://github.com/mightyiam" | ||
} | ||
], | ||
"contributors": [ | ||
{ | ||
"name": "Shahar Or", | ||
"email": "mightyiampresence@gmail.com", | ||
"web": "https://github.com/mightyiam" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/omarstreak/combokeys.git" | ||
}, | ||
"keywords": [ | ||
"keyboard", | ||
"shortcuts", | ||
"events", | ||
"browser" | ||
], | ||
"maintainers": [{ | ||
"name": "Shahar Or", | ||
"email": "mightyiampresence@gmail.com", | ||
"web": "https://github.com/mightyiam" | ||
}], | ||
"contributors": [ | ||
{ | ||
"name": "Shahar Or", | ||
"email": "mightyiampresence@gmail.com", | ||
"web": "https://github.com/mightyiam" | ||
}, | ||
{ | ||
"name": "Craig Campbell", | ||
"web": "http://craig.is" | ||
} | ||
], | ||
"bugs": "https://github.com/omarstreak/combokeys/issues", | ||
"licenses": [{ | ||
"type": "Apache 2.0", | ||
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt" | ||
}], | ||
"devDependencies": { | ||
"browserify": "~7.0.3", | ||
"chai": "^1.10.0", | ||
"es5-shim": "^4.0.3", | ||
"grunt": "~0.4.1", | ||
"grunt-complexity": "~0.1.2", | ||
"grunt-eslint": "^2.0.0", | ||
"load-grunt-tasks": "^1.0.0", | ||
"mocha": "^2.0.1", | ||
"phantomjs": "^1.9.12", | ||
"sinon": "^1.12.1", | ||
"zuul": "^1.13.1" | ||
{ | ||
"name": "Craig Campbell", | ||
"web": "http://craig.is" | ||
} | ||
], | ||
"bugs": "https://github.com/omarstreak/combokeys/issues", | ||
"licenses": [ | ||
{ | ||
"type": "Apache 2.0", | ||
"url": "https://www.apache.org/licenses/LICENSE-2.0.txt" | ||
} | ||
], | ||
"devDependencies": { | ||
"browserify": "~7.0.3", | ||
"chai": "^1.10.0", | ||
"es5-shim": "^4.0.3", | ||
"grunt": "~0.4.1", | ||
"grunt-complexity": "~0.1.2", | ||
"grunt-eslint": "^2.0.0", | ||
"load-grunt-tasks": "^1.0.0", | ||
"mocha": "^2.0.1", | ||
"phantomjs": "^1.9.12", | ||
"sinon": "^1.12.1", | ||
"zuul": "^1.13.1" | ||
} | ||
} |
94755
55
2068