UNPKG

jquery-next-id

Version:

jQuery collection plugin that will assign the next ID in sequence if an ID property does not already exist.

92 lines (68 loc) 2.59 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Source: jquery.nextid.js</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Source: jquery.nextid.js</h1> <section> <article> <pre class="prettyprint source linenums"><code>/** * @file jQuery collection plugin that will assign the next id in sequence if an id property does not already exist. * @author Ian McBurnie &lt;ianmcburnie@hotmail.com> * @version 1.0.1 * @requires jquery */ (function($, window, document, undefined) { // eslint-disable-line no-unused-vars var _nextInSequenceMap = {}; /** * jQuery collection plugin that will assign the next id in sequence if an id property does not already exist. * * @method "jQuery.fn.nextId" * @param {string} prefix The id will be prefixed with this value (default: nid) * @return {jQuery} chainable jQuery class */ $.fn.nextId = function nextId(prefix) { prefix = prefix || $.fn.nextId.defaults.prefix; // initialise prefix in sequence map if necessary _nextInSequenceMap[prefix] = _nextInSequenceMap[prefix] || 0; return this.filter(function onFilter() { return !this.id; }).each(function onEach() { $(this).prop('id', prefix + $.fn.nextId.defaults.separator + _nextInSequenceMap[prefix]++); }); }; }(jQuery, window, document)); $.fn.nextId.defaults = { prefix: 'nid', separator: '-' }; /** * The jQuery plugin namespace. * @external "jQuery.fn" * @see {@link http://learn.jquery.com/plugins/|jQuery Plugins} */ </code></pre> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Externals</h3><ul><li><a href="external-_jQuery.fn_.html">jQuery.fn</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%2522jQuery.fn.nextId%2522">"jQuery.fn.nextId"</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Tue Oct 17 2017 13:49:59 GMT-0700 (PDT) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>