vue-global-events
Advanced tools
Comparing version 1.0.3 to 1.0.4
/** | ||
* vue-global-events v1.0.3 | ||
* (c) 2018 Damian Dulisz <damian.dulisz@gmail.com> | ||
* vue-global-events v1.0.4 | ||
* (c) 2019 Damian Dulisz <damian.dulisz@gmail.com>, Eduardo San Martin Morote <posva13@gmail.com> | ||
* @license MIT | ||
@@ -9,2 +9,9 @@ */ | ||
var _isIE; | ||
function isIE () { | ||
return _isIE == null | ||
? (_isIE = /msie|trident/.test(window.navigator.userAgent.toLowerCase())) | ||
: _isIE | ||
} | ||
var modifiersRE = /^[~!&]*/; | ||
@@ -21,2 +28,9 @@ var nonEventNameCharsRE = /\W+/; | ||
var modifiers = ref[0]; | ||
// IE only supports capture option and it has to be a boolean | ||
// https://github.com/shentao/vue-global-events/issues/14 | ||
if (isIE()) { | ||
return modifiers.indexOf('!') > -1 | ||
} | ||
return modifiers.split('').reduce(function (options, modifier) { | ||
@@ -23,0 +37,0 @@ options[names[modifier]] = true; |
/** | ||
* vue-global-events v1.0.3 | ||
* (c) 2018 Damian Dulisz <damian.dulisz@gmail.com> | ||
* vue-global-events v1.0.4 | ||
* (c) 2019 Damian Dulisz <damian.dulisz@gmail.com>, Eduardo San Martin Morote <posva13@gmail.com> | ||
* @license MIT | ||
*/ | ||
var _isIE; | ||
function isIE () { | ||
return _isIE == null | ||
? (_isIE = /msie|trident/.test(window.navigator.userAgent.toLowerCase())) | ||
: _isIE | ||
} | ||
var modifiersRE = /^[~!&]*/; | ||
@@ -18,2 +25,9 @@ var nonEventNameCharsRE = /\W+/; | ||
var modifiers = ref[0]; | ||
// IE only supports capture option and it has to be a boolean | ||
// https://github.com/shentao/vue-global-events/issues/14 | ||
if (isIE()) { | ||
return modifiers.indexOf('!') > -1 | ||
} | ||
return modifiers.split('').reduce(function (options, modifier) { | ||
@@ -20,0 +34,0 @@ options[names[modifier]] = true; |
/** | ||
* vue-global-events v1.0.3 | ||
* (c) 2018 Damian Dulisz <damian.dulisz@gmail.com> | ||
* vue-global-events v1.0.4 | ||
* (c) 2019 Damian Dulisz <damian.dulisz@gmail.com>, Eduardo San Martin Morote <posva13@gmail.com> | ||
* @license MIT | ||
@@ -13,2 +13,9 @@ */ | ||
var _isIE; | ||
function isIE () { | ||
return _isIE == null | ||
? (_isIE = /msie|trident/.test(window.navigator.userAgent.toLowerCase())) | ||
: _isIE | ||
} | ||
var modifiersRE = /^[~!&]*/; | ||
@@ -25,2 +32,9 @@ var nonEventNameCharsRE = /\W+/; | ||
var modifiers = ref[0]; | ||
// IE only supports capture option and it has to be a boolean | ||
// https://github.com/shentao/vue-global-events/issues/14 | ||
if (isIE()) { | ||
return modifiers.indexOf('!') > -1 | ||
} | ||
return modifiers.split('').reduce(function (options, modifier) { | ||
@@ -27,0 +41,0 @@ options[names[modifier]] = true; |
/** | ||
* vue-global-events v1.0.3 | ||
* (c) 2018 Damian Dulisz <damian.dulisz@gmail.com> | ||
* vue-global-events v1.0.4 | ||
* (c) 2019 Damian Dulisz <damian.dulisz@gmail.com>, Eduardo San Martin Morote <posva13@gmail.com> | ||
* @license MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueGlobalEvents=t()}(this,function(){"use strict";var e=/^[~!&]*/,t=/\W+/,n={"!":"capture","~":"once","&":"passive"};return{name:"GlobalEvents",props:{filter:{type:Function,default:function(e){return!0}}},render:function(e){return e()},mounted:function(){var r=this;this._listeners=Object.create(null),Object.keys(this.$listeners).forEach(function(i){var s=r.$listeners[i],o=function(e){r.filter(e,s,i)&&s(e)};document.addEventListener(i.replace(t,""),o,i.match(e)[0].split("").reduce(function(e,t){return e[n[t]]=!0,e},{})),r._listeners[i]=o})},beforeDestroy:function(){for(var e in this._listeners)document.removeEventListener(e.replace(t,""),this._listeners[e])}}}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueGlobalEvents=t()}(this,function(){"use strict";var e;var t=/^[~!&]*/,n=/\W+/,r={"!":"capture","~":"once","&":"passive"};function i(n){var i=n.match(t)[0];return(null==e?e=/msie|trident/.test(window.navigator.userAgent.toLowerCase()):e)?i.indexOf("!")>-1:i.split("").reduce(function(e,t){return e[r[t]]=!0,e},{})}return{name:"GlobalEvents",props:{filter:{type:Function,default:function(e){return!0}}},render:function(e){return e()},mounted:function(){var e=this;this._listeners=Object.create(null),Object.keys(this.$listeners).forEach(function(t){var r=e.$listeners[t],o=function(n){e.filter(n,r,t)&&r(n)};document.addEventListener(t.replace(n,""),o,i(t)),e._listeners[t]=o})},beforeDestroy:function(){for(var e in this._listeners)document.removeEventListener(e.replace(n,""),this._listeners[e])}}}); |
{ | ||
"name": "vue-global-events", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Component to register global events", | ||
@@ -8,3 +8,3 @@ "main": "dist/vue-global-events.cjs.js", | ||
"unpkg": "dist/vue-global-events.js", | ||
"browser": "dist/vue-global-events.js", | ||
"browser": "dist/vue-global-events.es.js", | ||
"files": [ | ||
@@ -58,11 +58,11 @@ "README.md", | ||
"devDependencies": { | ||
"babel-jest": "^21.2.0", | ||
"@vue/test-utils": "^1.0.0-beta.25", | ||
"babel-jest": "^23.6.0", | ||
"babel-preset-env": "^1.6.1", | ||
"codecov": "^3.0.0", | ||
"eslint": "^4.12.1", | ||
"eslint-config-posva": "^1.3.2", | ||
"jest": "^21.2.1", | ||
"vue": "^2.5.9", | ||
"vue-template-compiler": "^2.5.9", | ||
"vue-test-utils": "^1.0.0-beta.6" | ||
"eslint": "^5.9.0", | ||
"eslint-config-posva": "^2.0.3", | ||
"jest": "^23.6.0", | ||
"vue": "^2.5.17", | ||
"vue-template-compiler": "^2.5.17" | ||
}, | ||
@@ -69,0 +69,0 @@ "jest": { |
# vue-global-events [](https://circleci.com/gh/shentao/vue-global-events) [](https://www.npmjs.com/package/vue-global-events) [](https://codecov.io/github/shentao/vue-global-events) | ||
> Listen to events on the document anywhere | ||
> Add shortcuts by listening to events on the document, anywhere | ||
@@ -22,3 +22,3 @@ ## Installation | ||
// register globally | ||
Vue.component(GlobalEvents) | ||
Vue.component('GlobalEvents', GlobalEvents) | ||
@@ -74,2 +74,3 @@ // or locally | ||
- You can add custom keyCodes to `Vue.config.keyCodes`. This is especially useful for numbers on the digit row: add `Vue.config.keyCodes.digit1 = 49` so you can write `@keydown.digit1` because writing `@keydown.1` will trigger when `keyCode === 1`. | ||
- About using `keyup` with modifiers like `.ctrl` or `.shift`: the keyup event is triggered when a key is released and that's also when the `event.ctrlKey` is checked, which if you just released, will be false. This is because `ctrl`, `shift` and `alt` are checked differently. If you want to trigger on the `keyup` event of a modifier, you need to use its keycode ([check it here](http://keycode.info). For example, for the `ctrl` key, that would be: `@keyup.17`. You can also use the advice above this one to provide it a name like _ctrlkey_. | ||
@@ -76,0 +77,0 @@ ## Development |
@@ -0,1 +1,3 @@ | ||
import { isIE } from './utils' | ||
const modifiersRE = /^[~!&]*/ | ||
@@ -11,2 +13,9 @@ const nonEventNameCharsRE = /\W+/ | ||
const [modifiers] = eventDescriptor.match(modifiersRE) | ||
// IE only supports capture option and it has to be a boolean | ||
// https://github.com/shentao/vue-global-events/issues/14 | ||
if (isIE()) { | ||
return modifiers.indexOf('!') > -1 | ||
} | ||
return modifiers.split('').reduce((options, modifier) => { | ||
@@ -13,0 +22,0 @@ options[names[modifier]] = true |
15348
10
277
103