All Projects → ealush → Vent

ealush / Vent

jQuery inspired DOM events library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vent

Domtastic
Small, fast, and modular DOM and event library for modern browsers.
Stars: ✭ 763 (+2443.33%)
Mutual labels:  events, jquery, dom
Vscode Powertools
A swiss army knife with lots of tools, extensions and (scriptable) enhancements for Visual Studio Code.
Stars: ✭ 150 (+400%)
Mutual labels:  events, jquery
Phantomas
Headless Chromium-based web performance metrics collector and monitoring tool
Stars: ✭ 2,191 (+7203.33%)
Mutual labels:  jquery, dom
preact-delegate
Preact delegate DOM events
Stars: ✭ 17 (-43.33%)
Mutual labels:  events, dom
Dna.js
🧬 An uncomplicated user interface library for building data-driven semantic templates
Stars: ✭ 114 (+280%)
Mutual labels:  jquery, dom
Femtojs
femtoJS - Really small JavaScript (ES6) library for DOM manipulation.
Stars: ✭ 122 (+306.67%)
Mutual labels:  jquery, dom
ngx-event-modifiers
Event Modifiers for Angular Applications https://netbasal.com/implementing-event-modifiers-in-angular-87e1a07969ce
Stars: ✭ 14 (-53.33%)
Mutual labels:  events, dom
Bliss
Blissful JavaScript
Stars: ✭ 2,352 (+7740%)
Mutual labels:  events, dom
Js Tracker
A chrome extension tracks front-end JavaScript that uses DOM / jQuery APIs to manipulate html dom elements (e.g., change style, attach event listener) at runtime.
Stars: ✭ 387 (+1190%)
Mutual labels:  jquery, dom
Shoestring
A lightweight, simple DOM utility made to run on a tight budget.
Stars: ✭ 447 (+1390%)
Mutual labels:  jquery, dom
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+81953.33%)
Mutual labels:  jquery, dom
Domquery
PHP library for easy 'jQuery like' DOM traversing and manipulation.
Stars: ✭ 84 (+180%)
Mutual labels:  jquery, dom
Nito
A jQuery library for building user interfaces
Stars: ✭ 56 (+86.67%)
Mutual labels:  jquery, dom
Jquery Xpath
jQuery XPath plugin (with full XPath 2.0 language support)
Stars: ✭ 173 (+476.67%)
Mutual labels:  jquery, dom
Nanocomponent
🚃 - create performant HTML components
Stars: ✭ 355 (+1083.33%)
Mutual labels:  events, dom
Cash
An absurdly small jQuery alternative for modern browsers.
Stars: ✭ 5,714 (+18946.67%)
Mutual labels:  jquery, dom
Arrive
Watch for DOM elements creation and removal
Stars: ✭ 703 (+2243.33%)
Mutual labels:  jquery, dom
Rest Api Examples
Test and Prototype with Fake Online REST/OAuth 2 APIs Examples
Stars: ✭ 13 (-56.67%)
Mutual labels:  jquery
Sticky Nav
A jQuery plugin make the navbar sticky, smart anchor link highlighting, smooth scrolling. Simple and powerful.
Stars: ✭ 21 (-30%)
Mutual labels:  jquery
Esp8266 Wifi Relay
simple sketch of using ESP8266WebServer to switch relays on GPIO pins. It serves a simple website with toggle buttons for each relay
Stars: ✭ 13 (-56.67%)
Mutual labels:  jquery

Vent

img logo

Extremely lightweight (1.5Kb) jQuery inspired events library for the browser.

vent('a:first-child').on('click', (e) => {
    // do something
});
vent('a').add('button').off('click');

vent(window).trigger('scroll');

Installation

You can either include vent's source as a script tag on your page, or:

npm i --save vent-dom

Or:

<script src="http://cdn.jsdelivr.net/npm/[email protected]/lib/vent.min.js"></script>

A note on ES5 support

This library by default does not support ES5 syntax, but it does produce an es5 bundle for those who still need es5 support. To use it, either require, or use itas a script tag.

<script src="http://cdn.jsdelivr.net/npm/[email protected]/lib/vent.min.es5.js"></script>

Or:

require('vent-dom/lib/vent.min.es5.js');

Getting the $

By default vent does not assign itself to $, in many cases you may already have jQuery on your page - sometimes simply because a 3rd party brought it in, and I don't want to cause any collisions. To use vent with $, simply add this to your code (after embedding vent, of course):

window.$ = vent;

$('button').trigger('click');

If you want to stay pretty safe and still use a shorthand, v works well too:

window.v = vent;

v(window).on('scroll', () => {
    console.log('Weeeeeee!')
});

Mission

Even today, when jQuery is mostly unneeded due to the facts that most browsers are more or less standard compliant, jQuery’s api for dealing with DOM events is hands down the best.

It offers easy event delegation, removing listeners is as simple as .off, it handles custom events and more. The only problem with jQuery is that it is huge (over 200kb), and mostly unneeded. Vent tries to provide all that goodness with just 1.5Kb.

Welcome Vent.

Vent was written with jQuery in mind. It doesn’t support all of jQuery’s goodness, but it does maintain all the best parts.

What Vent isn't?

  • Vent is NOT jQuery. It is not a 100% jQuery compliant, but it does cover 95% of the use-cases handled by jQuery.
  • Vent is not backwards compatible. It works across all evergreen browsers (Chrome, FF, Safari, Edge..). If for some reason you want your stuff to work on ie10 and below, please, use jQuery.
  • Vent is not a DOM manipulation library.

Vent's API

  • vent(selector): Most basic usage. Add elements to the set of elements.
vent(window)
vent('a')
vent('body')
vent(document.body)
  • .on(events, handler): Registers a single or multiple events on the matched selectors. It also handles delegations via selectors passed as the second argument.
// regular usage
vent('li').on('click', (e) => {
    console.log('clicked!');
});

// multiple event matching
vent('li').on('click mouseenter', (e) => {
    console.log(e.type);
});

// event delegation
vent('ul').on('click', 'li:first-child', (e) => {
    console.log('clicked!');
});

// custom event matching
vent('li').on('sample-event', (e) => {
    console.log('custom event');
});
  • .off(events): Unregisters events handlers bound using .on. When no events passed
  • .off(events, handler): Unregisters events handlers bound using .on. When no events passed
vent('a').off('click'); // unregisters all click events bound using 'on()'
vent('a').off('click mouseenter'); // unregisters all click and mouseenter events bound using 'on()'
vent('a').off(); // unregisters all events bound using 'on()'
vent('a').off('click', myHandler); // unregisters all events that were created with a specific handler function.
  • .once(events, delegatedTarget, handler): exactly like .on, but gets triggered only once. Does not respect .off!
vent('a').once('click', () => {
    console.log('this will only happen once');
});
  • .trigger(event, { data, options }): Triggers an event. Accepts data and custom options. By default triggered events get bubbles: true (can be overridden with custom options). Note: if the triggered event is a function on the element (such as click, focus, etc...), the function itself will be called along with dispatching an event.

Custom data will appear under detail property of the event.

// regular use
vent('a').trigger('click'); // will click the element
vent('a').trigger('mouseenter'); // will dispatch `mouseenter` event.

// with data
vent('a').trigger('click', {data: 'custom data'}); // will dispatch `click` with custom data (not call the function)

vent('a').trigger('sample', {options: {bubbles: false}});
  • .add(selector): extends Vent set with more elements
const v = vent('a');
v.add(window);
v.add('li');

v.on('scroll') // will be triggered for `a`, `window`, `li`.

Icon made by hirschwolf from www.flaticon.com.

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].