JSPM

  • Created
  • Published
  • Downloads 3653
  • Score
    100M100P100Q121930F

Act on jQuery elements only once.

Package Exports

  • jquery-once

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jquery-once) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

jQuery Once

Build Status NPM version Dependency Status Development Dependency Status
Gittip donate button

Act on jQuery elements only once.

Filters out all elements that had the same filter applied on them before. It can be used to ensure that a function is only applied once to an element.

Install

NPM

  • Use: require('jquery-once')
  • Install: npm install --save jquery-once

Browserify

  • Use: require('jquery-once')
  • Install: npm install --save jquery-once
  • CDN URL: //wzrd.in/bundle/jquery-once@2.0.0-beta.2

Ender

  • Use: require('jquery-once')
  • Install: ender add jquery-once

Component

  • Use: require('jquery-once')
  • Install: component install RobLoach/jquery-once

Bower

  • Use: require('jquery-once')
  • Install: bower install jquery-once

Usage

.once(id)

Filter elements by whether they have not yet been processed.

Parameters

  • id string (optional) The data id used to determine whether the given elements have already been processed or not. Default: once

Returns

jQuery element collection of elements that have now run once by the given id.

Example

$('div.calendar').once('calendar').click(function() {
  // .once('calendar') filters out all elements which already have been
  // filtered with once('calendar'), and the elements that haven't been filtered
  // yet remain. The previous set of elements can be restored with
  // .end().
});
$('div.calendar').once().each(function() {
  // This function is only executed once for each div, even if this
  // code segment is executed repeatedly. Keyed by "once".
});

.findOnce(id)

After .once() is used and you need to retrieve all elements that have already been executed with .once(), you can use the `.findOnce() function:

Parameters

  • id string The data id used to determine whether the given elements have already been processed or not.

Returns

jQuery element collection of elements that have been run once.

Example

$('div.calendar').findOnce('calendar').each(function() {
  // This function is called for each element that was already called "once"
  // with the "calendar" ID.
});

.removeOnce(id)

A required string representing the name of the data id which should be used when filtering the elements. This only filters elements that have already been processed by the once function. The id should be the same id that was originally passed to the once() function.

Parameters

  • id string The data id used to determine whether the given elements have already been processed or not.

Returns

jQuery element collection of elements that now have their once data removed.

Example

$('div.calendar').removeOnce('calendar').each(function() {
  // This function is called for each element whose once() data is removed.
});

Development

Install dependencies through npm:

npm install

Use Mocha to test with ESLint and Mocha JSDom:

npm test

Update project documentation with Projectz:

npm run-script projectz

Build the project with:

npm run-script release

History

Discover the change history by heading on over to the HISTORY.md file.

License

Licensed under:

Copyright © Rob Loach (http://github.com/RobLoach)

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Gittip donate button

Contributors

These amazing people have contributed code to this project:

Become a contributor!