All Projects → shentao → Vue Global Events

shentao / Vue Global Events

Licence: mit
⌨️ Register global events as a component

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Vue Global Events

Nanocomponent
🚃 - create performant HTML components
Stars: ✭ 355 (-44.36%)
Mutual labels:  events
Kubernetes Event Exporter
Export Kubernetes events to multiple destinations with routing and filtering
Stars: ✭ 395 (-38.09%)
Mutual labels:  events
Cms
Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.
Stars: ✭ 498 (-21.94%)
Mutual labels:  events
Cadar
Android solution which represents month and list calendar views.
Stars: ✭ 360 (-43.57%)
Mutual labels:  events
Awesome4girls
A curated list of inclusive events/projects/initiatives for women in the tech area. 💝
Stars: ✭ 393 (-38.4%)
Mutual labels:  events
Jquery Bracket
jQuery Bracket library for organizing single and double elimination tournaments
Stars: ✭ 427 (-33.07%)
Mutual labels:  events
Pg Listen
📡 PostgreSQL LISTEN & NOTIFY for node.js that finally works.
Stars: ✭ 348 (-45.45%)
Mutual labels:  events
Twitchlib
C# Twitch Chat, Whisper, API and PubSub Library. Allows for chatting, whispering, stream event subscription and channel/account modification. Supports .NET Core 2.0
Stars: ✭ 519 (-18.65%)
Mutual labels:  events
Calendar
Календарь событий по фронтенду
Stars: ✭ 395 (-38.09%)
Mutual labels:  events
Backbone.radio
Messaging patterns for Backbone applications.
Stars: ✭ 496 (-22.26%)
Mutual labels:  events
Pretalx
Conference planning tool: CfP, scheduling, speaker management
Stars: ✭ 363 (-43.1%)
Mutual labels:  events
Laravel Relationship Events
Missing relationship events for Laravel
Stars: ✭ 383 (-39.97%)
Mutual labels:  events
All Things Cqrs
Comprehensive guide to a couple of possible ways of synchronizing two states with Spring tools. Synchronization is shown by separating command and queries in a simple CQRS application.
Stars: ✭ 474 (-25.71%)
Mutual labels:  events
Ahoy.js
Simple, powerful JavaScript analytics
Stars: ✭ 355 (-44.36%)
Mutual labels:  events
Kledex
.NET Standard framework to create simple and clean design. Advanced features for DDD, CQRS and Event Sourcing.
Stars: ✭ 502 (-21.32%)
Mutual labels:  events
Sysend.js
Send messages between open pages or tabs in same browser
Stars: ✭ 347 (-45.61%)
Mutual labels:  events
Riemann
A network event stream processing system, in Clojure.
Stars: ✭ 4,099 (+542.48%)
Mutual labels:  events
Transient
A full stack, reactive architecture for general purpose programming. Algebraic and monadically composable primitives for concurrency, parallelism, event handling, transactions, multithreading, Web, and distributed computing with complete de-inversion of control (No callbacks, no blocking, pure state)
Stars: ✭ 617 (-3.29%)
Mutual labels:  events
Lwt
OCaml promises and concurrent I/O
Stars: ✭ 505 (-20.85%)
Mutual labels:  events
Gator
Event delegation in Javascript
Stars: ✭ 485 (-23.98%)
Mutual labels:  events

vue-global-events Build Status npm package coverage

Add shortcuts by listening to events on the document, anywhere

This is the version for Vue 2, if you are looking for the Vue 3 version, take a look at the next branch

Sponsors

Bronze

Vue Mastery logo Vue Jobs logo

Installation

npm install vue-global-events

Demo

Idea

Thanks to Vue’s event modifiers, handling events is extremely easy however, you’re limited to DOM element events. We decided to change that, so now you can register global events (for example application shortcuts) just like you would listen to events on a component. No need to worry about unregistration either. You can toggle the events with a single v-if. Works with SSR too.

Usage

import GlobalEvents from 'vue-global-events'

// register globally
Vue.component('GlobalEvents', GlobalEvents)

// or locally
export default {
  components: { GlobalEvents },
  // rest of your component
}

After that you can register global events like this:

<GlobalEvents
  v-if="listenersConnected"
  @keyup.ctrl.tab="nextTab"
  @keyup.ctrl.shift.tab="previousTab"
  @keyup.space="pause"
  @contextmenu="openMenu"
/>

Props

filter

Function to prevent any event from being executed based on anything related to the event like the element that triggered it, the name, or the handler.

  • type: Function
  • default: () => true
arguments
  • event: Native Event Object
  • handler: method passed to GlobalEvents component
  • eventName: event name with key modifiers

filter should return false to prevent the execution of a handler:

<GlobalEvents
  :filter="(event, handler, eventName) => event.target.tagName !== 'INPUT'"
  @keyup.prevent.space.exact="nextTab"
/>

In the example above event would be the native keyup Event Object, handler would be the method nextTab and eventName would be the string keyup. eventName can contain key modifiers if used

target

Target element where addEventListener is called on. It's a String that refers to a global variable like document or window. This allows you to add events to the window instead of document.

  • type: String
  • default: 'document'

Warning: This prop is not reactive. It should be provided as a static value. If you need it to be reactive, add a key attribute with the same value:

<GlobalEvents :target="target" :key="target" />

Advice / Caveats

  • Always .prevent events with .ctrl and other modifiers as browsers may be using them as shortcuts.
  • Do not use shortcuts that are used by the system or that the browser does not allow you to .preventDefault(). The list includes Ctrl+Tab/Cmd+Tab, Ctrl+W/Cmd+W. You can find more information in this StackOverflow answer.
  • Prefer using actual characters to keyCodes whenever possible: @keydown.+ for detecting the plus sign. This is important because symbols and numbers on the digit row will provide different keyCodes depending on the layout used.
  • 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. 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.

Development

Run tests in watch mode:

npm run dev

Demo

Build the library with:

npm run build

And then open the index.html file

Authors

Damian Dulisz @shentao

Eduardo San Martin Morote @posva

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].