npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastbinder

v0.3.12

Published

Fast and worry-free dynamic event binding

Downloads

1,091

Readme

Fastbinder

Build Status

Fast, simple, leak-free event binding for your views.

Add and remove thousands of DOM elements dynamically without worrying about any additional event binding/unbinding. The only bound elements are window and document.body.

The following attributes are supported:

  • data-on-blur
  • data-on-click
  • data-on-change
  • data-on-focus
  • data-on-hover
  • data-on-keydown
  • data-on-keyup
  • data-on-mousedown
  • data-on-mouseup
  • data-on-scroll
  • data-on-submit

Install

bower install fastbinder
npm install fastbinder

Usage

// Initialize
jQuery.fastbinder();

// Initialize with options
jQuery.fastbinder({ hoverDelay: 250 });

// Set options later on:
jQuery.fastbinder.setOptions({ forceExternalLinks: false });

// Tear down:
jQuery.fastbinder.destroy();

// Example handler function:
MyLibrary.myKeyupHandler = function (e) {
  // The jQuery event object is passed in:
  window.console.log(e, e.which);

  // `this` is bound to the DOMElement:
  var val = $(this).val();
  window.console.log(val);
};
<!-- Change Handler -->
<input type="text" data-on-change="MyLibrary.myChangeHandler" />

<!-- Click Handler -->
<a href="#" data-on-click="MyLibrary.myClickHandler">Execute myFunction on click</a>

<!-- Hover Handler -->
<div data-on-hover="MyLibrary.myHoverHandler"></a>

<!-- Scroll Handler -->
<div data-on-scroll="MyLibrary.myScrollHandler"></a>

<!-- Form submit handler -->
<form data-on-submit="MyLibrary.mySubmitHandler">
  <input type="text" data-on-keyup="MyLibrary.myKeyupHandler" />
  <input type="submit" />
</form>

Setting a Controller Scope

By using the data-controller attribute on either a parent element or the element itself, you can namespace a template block to a particular controller. For example, changing this input would execute the MyLibrary.myController.change function:

<div data-controller="MyLibrary.myController">
  <input type="text" data-on-change="change" />
</div>

You can also define an implied controller prefix:

$.fastbinder({
  controllerPrefix: 'App.Controller.',
});
<div data-controller="Things">
  <button data-on-click="clickHandler">Will execute App.Controller.Things.clickHandler</button>
</div>

Controller scopes can be nested, or overridden using a fully-qualified function name:

<div data-controller="Cars">
  <button data-on-click="clickHandler">Will execute Cars.clickHandler</button>
  <div data-controller="Boats">
    <button data-on-click="clickHandler">Will execute Boats.clickHandler</button>
    <button data-on-click="Planes.clickHandler">Will execute Planes.clickHandler</button>
  </div>
</div>

Adding and Extending Bindings

For example, to add support for touch events:

jQuery.fastbinder.on({ name: 'touchstart', attribute: 'on-touchstart' });
jQuery.fastbinder.on({ name: 'touchend', attribute: 'on-touchend' });

Or to support both mouse and touch events with a single attribute:

jQuery.fastbinder.on({ name: 'mousedown touchstart', attribute: 'on-mousedown' });
jQuery.fastbinder.on({ name: 'mouseup touchend', attribute: 'on-mouseup' });

Running the Tests

First, install bower and npm dependencies:

npm install
bower install
npm test