Giter VIP home page Giter VIP logo

delegate.js's Introduction

delegate.js

Build Status

Installation

Install with Bower:

bower install --save delegate.js

The component can be used as a Common JS module, an AMD module, or a global.

API

delegate(element)

Specify the event delegate element. Returns delegate to allow chaining.

delegate#on(type, selector, callback, [capture])

Delegate the handling of an event type to the given ancestor-element of nodes matching a given CSS selector. The callback function is invoked when an event bubbles up through any nodes that delegated their event handling to the ancestor.

The event object that is passed to the callback has a delegateTarget property that corresponds to the delegator element.

<div class="delegator"></div>
delegate(document).on('click', 'div', function (e) {
    console.log(e.delegateTarget.className);
    // => 'delegator'
});

delegate#once(type, selector, callback, [capture])

The same as .on() but the callback will be removed after it has been invoked for the first time.

delegate#off(type, callback, [capture])

Remove an event-type callback from the delegate element (event target).

delegate(document).off('click', listener);

Testing

Install Node (comes with npm) and Bower.

From the repo root, install the project's development dependencies:

npm install
bower install

Testing relies on the Karma test-runner. If you'd like to use Karma to automatically watch and re-run the test file during development, it's easiest to globally install Karma and run it from the CLI.

npm install -g karma
karma start

To run the tests in Firefox, just once, as CI would:

npm test

Browser support

  • Google Chrome (latest)
  • Opera (latest)
  • Firefox 4+
  • Safari 5+
  • Internet Explorer 9+ (IE 8 requires a DOM3 Event shim)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.