Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hotkeys-js

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hotkeys-js - npm Package Compare versions

Comparing version 2.0.4 to 2.0.5

2

dist/hotkeys.min.js
/*! hotkeys-js v2.0.4 | MIT (c) 2017 kenny wang <wowohoo@qq.com> | https://github.com/jaywcjlove/hotkeys.git */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).hotkeys=e()}}(function(){function n(e){return h[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)}function t(e){g=e||"all"}function o(){return g||"all"}function r(e,n,t){e.addEventListener?e.addEventListener(n,t,!1):e.attachEvent&&e.attachEvent("on"+n,function(){t(window.event)})}function i(e){var n,t=e.keyCode||e.which||e.charCode,r=x["*"];if(-1===y.indexOf(t)&&y.push(t),93!==t&&224!==t||(t=91),t in m){m[t]=!0;for(var i in v)v[i]===t&&(d[i]=!0);if(!r)return}for(var a in m)m[a]=e[w[a]];if(d.filter.call(this,e)){if(n=o(),r)for(l=0;l<r.length;l++)r[l].scope===n&&f(e,r[l],n);if(t in x)for(var l=0;l<x[t].length;l++)f(e,x[t][l],n)}}function f(e,n,t){var o;if(n.scope===t||"all"===n.scope){o=n.mods.length>0;for(var r in m)(!m[r]&&n.mods.indexOf(+r)>-1||m[r]&&-1===n.mods.indexOf(+r))&&(o=!1);(0!==n.mods.length||m[16]||m[18]||m[17]||m[91])&&!o&&"*"!==n.shortcut||!1===n.method(e,n)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function a(e,n){for(var t=e.length>=n.length?e:n,o=e.length>=n.length?n:e,r=0;r<t.length;r++)if(-1===o.indexOf(t[r]))return!1;return!0}function l(e){for(var n=e.slice(0,e.length-1),t=0;t<n.length;t++)n[t]=v[n[t].toLowerCase()];return n}function c(e){e||(e="");var n,t;for(t=(n=(e=e.replace(/\s/g,"")).split(",")).lastIndexOf("");t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function s(n){var t=n.keyCode||e.which||e.charCode,o=y.indexOf(t);if(o>=0&&y.splice(o,1),93!==t&&224!==t||(t=91),t in m){m[t]=!1;for(var r in v)v[r]===t&&(d[r]=!1)}}function d(e,t,o){var r=c(e),i=[],f=0;for(void 0===o&&(o=t,t="all");f<r.length;f++)i=[],(e=r[f].split("+")).length>1&&(i=l(e)),(e="*"===(e=e[e.length-1])?"*":n(e))in x||(x[e]=[]),x[e].push({shortcut:r[f],scope:t,method:o,key:r[f],mods:i})}Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;n<this.length;n++)if(this[n]===e)return n;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(e){for(var n=this.length-1;n>=0;n--)if(this[n]===e)return n;return-1});for(var u,p=navigator.userAgent.toLowerCase().indexOf("firefox")>0,h={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,home:36,end:35,pageup:33,pagedown:34,"⇪":20,capslock:20,",":188,".":190,"/":191,"`":192,"-":p?173:189,"=":p?61:187,";":p?59:186,"'":222,"[":219,"]":221,"\\":220},g="all",v={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":p?224:91,cmd:p?224:91,command:p?224:91},y=[],w={16:"shiftKey",18:"altKey",17:"ctrlKey"},m={16:!1,18:!1,17:!1},x={},O=1;O<20;O++)h["f"+O]=111+O;w[p?224:91]="metaKey",m[p?224:91]=!1,r(document,"keydown",function(e){i(e)}),r(document,"keyup",function(e){s(e)}),u={setScope:t,getScope:o,deleteScope:function(e,n){var r,i,f;e||(e=o());for(r in x)for(i=x[r],f=0;f<i.length;)i[f].scope===e?i.splice(f,1):f++;o()===e&&t(n||"all")},getPressedKeyCodes:function(){return y.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=n(e)),-1!==y.indexOf(e)},filter:function(e){var n=(e.target||e.srcElement).tagName;return!("INPUT"===n||"SELECT"===n||"TEXTAREA"===n)},unbind:function(e,t){for(var r,i,f=c(e),s=[],d=0;d<f.length;d++){if((r=f[d].split("+")).length>1&&(s=l(r)),e=r[r.length-1],e="*"===e?"*":n(e),t||(t=o()),!x[e])return;for(var u=0;u<x[e].length;u++)(i=x[e][u]).scope===t&&a(i.mods,s)&&(x[e][u]={})}}};for(var k in u)d[k]=u[k];var C=window.hotkeys;return d.noConflict=function(e){return e&&window.hotkeys===d&&(window.hotkeys=C),d},window.hotkeys=d,d});
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).hotkeys=e()}}(function(){function n(e){return h[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)}function t(e){g=e||"all"}function o(){return g||"all"}function r(e,n,t){e.addEventListener?e.addEventListener(n,t,!1):e.attachEvent&&e.attachEvent("on"+n,function(){t(window.event)})}function i(e){var n,t=e.keyCode||e.which||e.charCode,r=x["*"];if(-1===y.indexOf(t)&&y.push(t),93!==t&&224!==t||(t=91),t in m){m[t]=!0;for(var i in v)v[i]===t&&(d[i]=!0);if(!r)return}for(var a in m)m[a]=e[w[a]];if(d.filter.call(this,e)){if(n=o(),r)for(l=0;l<r.length;l++)r[l].scope===n&&f(e,r[l],n);if(t in x)for(var l=0;l<x[t].length;l++)f(e,x[t][l],n)}}function f(e,n,t){var o;if(n.scope===t||"all"===n.scope){o=n.mods.length>0;for(var r in m)(!m[r]&&n.mods.indexOf(+r)>-1||m[r]&&-1===n.mods.indexOf(+r))&&(o=!1);(0!==n.mods.length||m[16]||m[18]||m[17]||m[91])&&!o&&"*"!==n.shortcut||!1===n.method(e,n)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function a(e,n){for(var t=e.length>=n.length?e:n,o=e.length>=n.length?n:e,r=0;r<t.length;r++)if(-1===o.indexOf(t[r]))return!1;return!0}function l(e){for(var n=e.slice(0,e.length-1),t=0;t<n.length;t++)n[t]=v[n[t].toLowerCase()];return n}function c(e){e||(e="");var n,t;for(t=(n=(e=e.replace(/\s/g,"")).split(",")).lastIndexOf("");t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function s(n){var t=n.keyCode||e.which||e.charCode,o=y.indexOf(t);if(o>=0&&y.splice(o,1),93!==t&&224!==t||(t=91),t in m){m[t]=!1;for(var r in v)v[r]===t&&(d[r]=!1)}}function d(e,t,o){var r=c(e),i=[],f=0;for(void 0===o&&(o=t,t="all");f<r.length;f++)i=[],(e=r[f].split("+")).length>1&&(i=l(e)),(e="*"===(e=e[e.length-1])?"*":n(e))in x||(x[e]=[]),x[e].push({shortcut:r[f],scope:t,method:o,key:r[f],mods:i})}Array.prototype.indexOf||(Array.prototype.indexOf=function(e){for(var n=0;n<this.length;n++)if(this[n]===e)return n;return-1}),Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(e){for(var n=this.length-1;n>=0;n--)if(this[n]===e)return n;return-1});for(var u,p="undefined"!=typeof navigator&&navigator.userAgent.toLowerCase().indexOf("firefox")>0,h={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,home:36,end:35,pageup:33,pagedown:34,"⇪":20,capslock:20,",":188,".":190,"/":191,"`":192,"-":p?173:189,"=":p?61:187,";":p?59:186,"'":222,"[":219,"]":221,"\\":220},g="all",v={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":p?224:91,cmd:p?224:91,command:p?224:91},y=[],w={16:"shiftKey",18:"altKey",17:"ctrlKey"},m={16:!1,18:!1,17:!1},x={},O=1;O<20;O++)h["f"+O]=111+O;w[p?224:91]="metaKey",m[p?224:91]=!1,r(document,"keydown",function(e){i(e)}),r(document,"keyup",function(e){s(e)}),u={setScope:t,getScope:o,deleteScope:function(e,n){var r,i,f;e||(e=o());for(r in x)for(i=x[r],f=0;f<i.length;)i[f].scope===e?i.splice(f,1):f++;o()===e&&t(n||"all")},getPressedKeyCodes:function(){return y.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=n(e)),-1!==y.indexOf(e)},filter:function(e){var n=(e.target||e.srcElement).tagName;return!("INPUT"===n||"SELECT"===n||"TEXTAREA"===n)},unbind:function(e,t){for(var r,i,f=c(e),s=[],d=0;d<f.length;d++){if((r=f[d].split("+")).length>1&&(s=l(r)),e=r[r.length-1],e="*"===e?"*":n(e),t||(t=o()),!x[e])return;for(var u=0;u<x[e].length;u++)(i=x[e][u]).scope===t&&a(i.mods,s)&&(x[e][u]={})}}};for(var k in u)d[k]=u[k];var C=window.hotkeys;return d.noConflict=function(e){return e&&window.hotkeys===d&&(window.hotkeys=C),d},window.hotkeys=d,d});
{
"name": "hotkeys-js",
"version": "2.0.4",
"version": "2.0.5",
"description": "A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.",

@@ -5,0 +5,0 @@ "author": "kenny wang <wowohoo@qq.com>",

@@ -107,9 +107,17 @@ # 设置快捷键

// 定义a快捷键
hotkeys('f5', function(event,handler){
//event.srcElement: input
//event.target: input
// 阻止Widnows系统下的默认刷新事件
event.preventDefault()
alert('你按下了 F5 键!')
});
// 定义a快捷键
hotkeys('a', function(event,handler){
//event.srcElement: input
//event.target: input
if(event.target === "input"){
alert('你在输入框中按下了 a!')
}
alert('你按下了 a!')
//event.srcElement: input
//event.target: input
if(event.target === "input"){
alert('你在输入框中按下了 a!')
}
alert('你按下了 a!')
});

@@ -119,9 +127,9 @@

hotkeys('ctrl+a,ctrl+b,r,f', function(event,handler){
switch(handler.key){
case "ctrl+a":alert('你按下了ctrl+a!');break;
case "ctrl+b":alert('你按下了ctrl+b!');break;
case "r":alert('你按下了r!');break;
case "f":alert('你按下了f!');break;
}
//handler.scope 范围
switch(handler.key){
case "ctrl+a":alert('你按下了ctrl+a!');break;
case "ctrl+b":alert('你按下了ctrl+b!');break;
case "r":alert('你按下了r!');break;
case "f":alert('你按下了f!');break;
}
//handler.scope 范围
});

@@ -137,7 +145,7 @@

hotkeys('*','wcj', function(e){
console.log('干点活儿',e);
console.log("key.getScope()::",hotkeys.getScope());
if(hotkeys.shift) console.log('大哥你摁下了 shift 键!');
if(hotkeys.ctrl) console.log('大哥你摁下了 ctrl 键!');
if(hotkeys.alt) console.log('大哥你摁下了 alt 键!');
console.log('干点活儿',e);
console.log("key.getScope()::",hotkeys.getScope());
if(hotkeys.shift) console.log('大哥你摁下了 shift 键!');
if(hotkeys.ctrl) console.log('大哥你摁下了 ctrl 键!');
if(hotkeys.alt) console.log('大哥你摁下了 alt 键!');
});

@@ -164,6 +172,6 @@ ```

hotkeys('shift+a,alt+d, w', function(e){
console.log('干点活儿',e);
if(hotkeys.shift) console.log('大哥你摁下了 shift 键!');
if(hotkeys.ctrl) console.log('大哥你摁下了 ctrl 键!');
if(hotkeys.alt) console.log('大哥你摁下了 alt 键!');
console.log('干点活儿',e);
if(hotkeys.shift) console.log('大哥你摁下了 shift 键!');
if(hotkeys.ctrl) console.log('大哥你摁下了 ctrl 键!');
if(hotkeys.alt) console.log('大哥你摁下了 alt 键!');
});

@@ -179,7 +187,7 @@ ```

hotkeys('ctrl+o, ctrl+alt+enter', 'scope1', function(){
console.log('你好看');
console.log('你好看');
});
hotkeys('ctrl+o, enter', 'scope2', function(){
console.log('你好丑陋啊!');
console.log('你好丑陋啊!');
});

@@ -226,5 +234,5 @@

hotkeys('a', function(){
console.log(hotkeys.isPressed("a")); //=> true
console.log(hotkeys.isPressed("A")); //=> true
console.log(hotkeys.isPressed(65)); //=> true
console.log(hotkeys.isPressed("a")); //=> true
console.log(hotkeys.isPressed("A")); //=> true
console.log(hotkeys.isPressed(65)); //=> true
});

@@ -239,3 +247,3 @@ ```

hotkeys('command+ctrl+shift+a,f', function(){
console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] 或者 [70]
console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] 或者 [70]
})

@@ -256,7 +264,7 @@ ```

hotkeys.filter = function(event) {
var tagName = (event.target || event.srcElement).tagName;
return !(tagName.isContentEditable ||
tagName == 'INPUT' ||
tagName == 'SELECT' ||
tagName == 'TEXTAREA');
var tagName = (event.target || event.srcElement).tagName;
return !(tagName.isContentEditable ||
tagName == 'INPUT' ||
tagName == 'SELECT' ||
tagName == 'TEXTAREA');
}

@@ -266,5 +274,5 @@

hotkeys.filter = function(event){
var tagName = (event.target || event.srcElement).tagName;
hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
var tagName = (event.target || event.srcElement).tagName;
hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
}

@@ -278,3 +286,3 @@ ```

k('a', function() {
console.log("这里可以干一些事儿")
console.log("这里可以干一些事儿")
});

@@ -281,0 +289,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc