keypress-tool
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -13,7 +13,2 @@ 'use strict'; | ||
/** | ||
* Get the bucket for this specific key combination | ||
*/ | ||
exports['default'] = KeyPress; | ||
var _capitalize = require('string-tool'); | ||
@@ -77,45 +72,42 @@ | ||
// Install the event handler | ||
if (isBrowser) { | ||
addEventListener('keydown', function (ev) { | ||
var hash = ev.keyCode + '-' + (ev.ctrlKey ? '1' : '0') + (ev.metaKey ? '1' : '0') + (ev.shiftKey ? '1' : '0') + (ev.altKey ? '1' : '0'); | ||
var bucket = buckets[hash]; | ||
if (bucket === undefined || bucket.length === 0) { | ||
return; | ||
function handleKey(ev) { | ||
var hash = ev.keyCode + '-' + (ev.ctrlKey ? '1' : '0') + (ev.metaKey ? '1' : '0') + (ev.shiftKey ? '1' : '0') + (ev.altKey ? '1' : '0'); | ||
var bucket = buckets[hash]; | ||
if (bucket === undefined || bucket.length === 0) { | ||
return; | ||
} | ||
bucket = bucket.filter(function (lnr) { | ||
return lnr.inputEl || !_isInputElement.isInputElement(ev.target); | ||
}); | ||
if (bucket.length === 0) { | ||
return; | ||
} | ||
if (!bucket.executeDefault) { | ||
ev.stopPropagation(); | ||
ev.preventDefault(); | ||
} | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = bucket[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var lnr = _step.value; | ||
lnr.call(this, ev); | ||
} | ||
bucket = bucket.filter(function (lnr) { | ||
return lnr.inputEl || !_isInputElement.isInputElement(ev.target); | ||
}); | ||
if (bucket.length === 0) { | ||
return; | ||
} | ||
if (!bucket.executeDefault) { | ||
ev.stopPropagation(); | ||
ev.preventDefault(); | ||
} | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
for (var _iterator = bucket[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var lnr = _step.value; | ||
lnr.call(this, ev); | ||
if (!_iteratorNormalCompletion && _iterator['return']) { | ||
_iterator['return'](); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator['return']) { | ||
_iterator['return'](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
@@ -144,12 +136,2 @@ | ||
_createClass(ListenerBucket, [{ | ||
key: 'toString', | ||
value: function toString() { | ||
var m = this.modifiers; | ||
if (isMac) { | ||
return (m.has('ctrl') ? '⌃' : '') + (m.has('alt') ? '⌥' : '') + (m.has('shift') ? '⇧' : '') + (m.has('meta') ? '⌘' : '') + this.keyName; | ||
} else { | ||
return (m.has('meta') ? 'Win+' : '') + (m.has('ctrl') ? 'Ctrl+' : '') + (m.has('alt') ? 'Alt+' : '') + (m.has('shift') ? 'Shift+' : '') + this.keyName; | ||
} | ||
} | ||
}, { | ||
key: 'addListener', | ||
@@ -174,2 +156,12 @@ value: function addListener(callback) { | ||
} | ||
}, { | ||
key: 'toString', | ||
value: function toString() { | ||
var m = this.modifiers; | ||
if (isMac) { | ||
return (m.has('ctrl') ? '⌃' : '') + (m.has('alt') ? '⌥' : '') + (m.has('shift') ? '⇧' : '') + (m.has('meta') ? '⌘' : '') + this.keyName; | ||
} else { | ||
return (m.has('meta') ? 'Win+' : '') + (m.has('ctrl') ? 'Ctrl+' : '') + (m.has('alt') ? 'Alt+' : '') + (m.has('shift') ? 'Shift+' : '') + this.keyName; | ||
} | ||
} | ||
}]); | ||
@@ -196,2 +188,6 @@ | ||
} | ||
/** | ||
* Get the bucket for this specific key combination | ||
*/ | ||
function KeyPress(char) { | ||
@@ -225,2 +221,14 @@ var options = arguments[1] === undefined ? [] : arguments[1]; | ||
KeyPress.enable = function () { | ||
isBrowser && addEventListener('keydown', handleKey); | ||
}; | ||
KeyPress.disable = function () { | ||
isBrowser && removeEventListener('keydown', handleKey); | ||
}; | ||
// Install the event handler | ||
KeyPress.enable(); | ||
exports['default'] = KeyPress; | ||
module.exports = exports['default']; |
@@ -58,23 +58,20 @@ import { capitalize } from 'string-tool'; | ||
// Install the event handler | ||
if (isBrowser) { | ||
addEventListener('keydown', function(ev) { | ||
var hash = ev.keyCode + '-' + (ev.ctrlKey ? '1' : '0') + (ev.metaKey ? '1' : '0') | ||
+ (ev.shiftKey ? '1' : '0') + (ev.altKey ? '1' : '0'); | ||
var bucket = buckets[hash]; | ||
if (bucket === undefined || bucket.length === 0) { | ||
return; | ||
} | ||
bucket = bucket.filter(lnr => lnr.inputEl || !isInputElement(ev.target)); | ||
if (bucket.length === 0) { | ||
return; | ||
} | ||
if (!bucket.executeDefault) { | ||
ev.stopPropagation(); | ||
ev.preventDefault(); | ||
} | ||
for (var lnr of bucket) { | ||
lnr.call(this, ev); | ||
} | ||
}); | ||
function handleKey(ev) { | ||
var hash = ev.keyCode + '-' + (ev.ctrlKey ? '1' : '0') + (ev.metaKey ? '1' : '0') | ||
+ (ev.shiftKey ? '1' : '0') + (ev.altKey ? '1' : '0'); | ||
var bucket = buckets[hash]; | ||
if (bucket === undefined || bucket.length === 0) { | ||
return; | ||
} | ||
bucket = bucket.filter(lnr => lnr.inputEl || !isInputElement(ev.target)); | ||
if (bucket.length === 0) { | ||
return; | ||
} | ||
if (!bucket.executeDefault) { | ||
ev.stopPropagation(); | ||
ev.preventDefault(); | ||
} | ||
for (var lnr of bucket) { | ||
lnr.call(this, ev); | ||
} | ||
} | ||
@@ -94,2 +91,14 @@ | ||
addListener(callback, inputEl = false) { | ||
if (!isBrowser) { return; } | ||
// Just tack an attribute on the function. Why not? | ||
callback.inputEl = inputEl; | ||
this.push(callback); | ||
} | ||
removeListener(callback) { | ||
if (!isBrowser) { return; } | ||
// TODO: remove from array | ||
} | ||
toString() { | ||
@@ -108,14 +117,2 @@ var m = this.modifiers; | ||
addListener(callback, inputEl = false) { | ||
if (!isBrowser) { return; } | ||
// Just tack an attribute on the function. Why not? | ||
callback.inputEl = inputEl; | ||
this.push(callback); | ||
} | ||
removeListener(callback) { | ||
if (!isBrowser) { return; } | ||
// TODO: remove from array | ||
} | ||
} | ||
@@ -143,3 +140,3 @@ | ||
*/ | ||
export default function KeyPress(char, options = []) { | ||
function KeyPress(char, options = []) { | ||
// TODO: What if the options are capitalized? | ||
@@ -169,2 +166,15 @@ var m = new Set(options); | ||
} | ||
} | ||
} | ||
KeyPress.enable = function() { | ||
isBrowser && addEventListener('keydown', handleKey); | ||
} | ||
KeyPress.disable = function() { | ||
isBrowser && removeEventListener('keydown', handleKey); | ||
} | ||
// Install the event handler | ||
KeyPress.enable(); | ||
export default KeyPress; |
{ | ||
"name": "keypress-tool", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Create custom keyboard shortcuts in the browser", | ||
@@ -5,0 +5,0 @@ "keywords": [ "keyboard", "shortcut", "browser" ], |
@@ -1,6 +0,4 @@ | ||
# keypress-tool | ||
# keypress-tool [![Build Status](https://travis-ci.org/JannesMeyer/keypress-tool.svg?branch=master)](https://travis-ci.org/JannesMeyer/keypress-tool) [![Dependencies](https://david-dm.org/JannesMeyer/keypress-tool.svg)](https://david-dm.org/JannesMeyer/keypress-tool) [![Development Dependencies](https://david-dm.org/JannesMeyer/keypress-tool/dev-status.svg)](https://david-dm.org/JannesMeyer/keypress-tool#info=devDependencies) | ||
[![Build Status](https://travis-ci.org/JannesMeyer/keypress-tool.svg?branch=master)](https://travis-ci.org/JannesMeyer/keypress-tool) | ||
[![Dependencies](https://david-dm.org/JannesMeyer/keypress-tool.svg)](https://david-dm.org/JannesMeyer/keypress-tool) | ||
[![Development Dependencies](https://david-dm.org/JannesMeyer/keypress-tool/dev-status.svg)](https://david-dm.org/JannesMeyer/keypress-tool#info=devDependencies) | ||
[![NPM](https://nodei.co/npm/keypress-tool.png)](https://www.npmjs.com/package/keypress-tool) | ||
@@ -7,0 +5,0 @@ **Import the module** (ES6 syntax) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13645
391
0
30