diff options
-rw-r--r-- | .editorconfig | 11 | ||||
-rw-r--r-- | .eslintrc | 11 | ||||
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | API.md | 32 | ||||
-rw-r--r-- | CHANGELOG.md | 9 | ||||
-rw-r--r-- | README.md | 21 | ||||
-rw-r--r-- | bower.json | 1 | ||||
-rw-r--r-- | example/index.html | 2 | ||||
-rw-r--r-- | jquery.once.js | 69 | ||||
-rw-r--r-- | jquery.once.min.js.map | 2 | ||||
-rw-r--r-- | once.jquery.json | 2 | ||||
-rw-r--r-- | package.json | 19 | ||||
-rw-r--r-- | test/index.js | 10 | ||||
-rw-r--r-- | test/test.js | 99 |
14 files changed, 139 insertions, 151 deletions
diff --git a/.editorconfig b/.editorconfig index 6818143..305e428 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,14 +5,7 @@ root = true [*] end_of_line = lf charset = utf-8 -trim_trailing_whitespace = false -insert_final_newline = false -indent_style = tab - -[*.json] -indent_style = space -indent_size = 2 - -[*.yml] +trim_trailing_whitespace = true +insert_final_newline = true indent_style = space indent_size = 2 diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index b8cfbc5..0000000 --- a/.eslintrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "env": { - "browser": true, - "node": true, - "amd": true, - "mocha": true - }, - "globals": { - "jQuery": true - } -} diff --git a/.travis.yml b/.travis.yml index 48648f1..ea861bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: node_js node_js: - - "0.10" - - "0.12" - iojs cache: @@ -27,26 +27,26 @@ Filter elements that have yet to be processed by the given data ID. | Param | Type | Default | Description | | --- | --- | --- | --- | -| [id] | <code>string</code> | <code>"once"</code> | The data ID used to determine whether the given elements have already been processed or not. Defaults to `"once"`. | +| [id] | <code>string</code> | <code>"once"</code> | The data ID used to determine whether the given elements have already been processed or not. Defaults to `'once'`. | **Example** ``` javascript // The following will change the color of each paragraph to red, just once -// for the "changecolor" key. +// for the 'changecolor' key. $('p').once('changecolor').css('color', 'red'); // .once() will return a set of elements that yet to have the once ID // associated with them. You can return to the original collection set by // using .end(). $('p') - .once("changecolorblue") - .css("color", "blue") + .once('changecolorblue') + .css('color', 'blue') .end() - .css("color", "red"); + .css('color', 'red'); // To execute a function on the once set, you can use jQuery's each(). -$('div.calendar').once().each(function() { - // Since there is no once ID provided here, the key will be "once". +$('div.calendar').once().each(function () { + // Since there is no once ID provided here, the key will be 'once'. }); ``` <a name="removeOnce"></a> @@ -62,16 +62,16 @@ Removes the once data from elements, based on the given ID. | Param | Type | Default | Description | | --- | --- | --- | --- | -| [id] | <code>string</code> | <code>"once"</code> | A 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. Defaults to `"once"`. | +| [id] | <code>string</code> | <code>"once"</code> | A 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. Defaults to `'once'`. | **Example** ``` javascript -// Remove once data with the "changecolor" ID. The result set is the +// Remove once data with the 'changecolor' ID. The result set is the // elements that had their once data removed. -$('p').removeOnce("changecolor").css("color", ""); +$('p').removeOnce('changecolor').css('color', ''); // Any jQuery function can be performed on the result set. -$("div.calendar").removeOnce().each(function() { +$('div.calendar').removeOnce().each(function () { // Remove the calendar behavior. }); ``` @@ -87,18 +87,18 @@ Filters elements that have already been processed once. | Param | Type | Default | Description | | --- | --- | --- | --- | -| [id] | <code>string</code> | <code>"once"</code> | A 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. Defaults to "once". | +| [id] | <code>string</code> | <code>"once"</code> | A 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. Defaults to 'once'. | **Example** ``` javascript // Find all elements that have been changecolor'ed once. -$('p').findOnce('changecolor').each(function() { +$('p').findOnce('changecolor').each(function () { // This function is called for all elements that has already once'd. }); -// Find all elements that have been acted on with the default "once" key. -$('p').findOnce().each(function() { +// Find all elements that have been acted on with the default 'once' key. +$('p').findOnce().each(function () { // This function is called for all elements that have been acted on with - // a "once" action. + // a 'once' action. }); ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b797d9..d5778f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased][unreleased] ### Changed +- Nothing so far + +## [2.1.0] - August 31, 2015 +### Changed - Switched to [Keep a CHANGELOG](http://keepachangelog.com) in CHANGELOG.md +- Moved to [JavaScript Semi-Standard Coding Style](http://npm.im/semistandard) +- Updated development dependencies ## [2.0.2] - June 5th, 2015 ### Added @@ -65,7 +71,8 @@ automatically build API documentation ### Added - Added jQuery Once -[unreleased]: https://github.com/RobLoach/jquery-once/compare/2.0.2...HEAD +[unreleased]: https://github.com/RobLoach/jquery-once/compare/2.1.0...HEAD +[2.1.0]: https://github.com/RobLoach/jquery-once/compare/2.0.2...2.1.0 [2.0.2]: https://github.com/RobLoach/jquery-once/compare/2.0.1...2.0.2 [2.0.1]: https://github.com/RobLoach/jquery-once/compare/2.0.0...2.0.1 [2.0.0]: https://github.com/RobLoach/jquery-once/compare/1.2.6...2.0.0 @@ -45,34 +45,37 @@ $('div.calendar').once().each(function() { }); ``` - ## Development -Install dependencies through [npm](http://npmjs.org): +1. Ensure you are using [io.js](http://iojs.org) >= 3.2.0: + + node --version + +2. Install dependencies through [npm](http://npmjs.org): npm install -Test with [ESLint](http://eslint.org), [Mocha](http://mochajs.org) and [Mocha -JSDom](https://github.com/rstacruz/mocha-jsdom): +3. Check coding style standard, and automated testing: npm test -Build `jquery.once.min.js` with: +4. Build `jquery.once.min.js` with: npm run build -Update API documentation with [jsdoc-to-markdown](https://github.com/75lb/jsdoc-to-markdown): +5. Update API documentation: npm run docs -Tag and publish the new versions to [npm](http://npmjs.com) with [Semantic +6. Tag and publish the new versions to [npm](http://npmjs.com) with [Semantic Versioning](http://semver.org/): - git tag 2.0.0 - git push origin 2.0.0 + git tag 2.1.0 + git push origin 2.1.0 npm publish ## Change Log + [Discover the change history by heading on over to the `CHANGELOG.md` file.](CHANGELOG.md) ## License @@ -2,7 +2,6 @@ "name": "jquery-once", "homepage": "http://github.com/robloach/jquery-once", "description": "Act on jQuery elements only once.", - "version": "2.0.2", "license": "GPL-2.0", "main": "jquery.once.js", "ignore": [ diff --git a/example/index.html b/example/index.html index a002fb4..933f5d3 100644 --- a/example/index.html +++ b/example/index.html @@ -1,7 +1,7 @@ <!DOCTYPE html> <html> <head> - <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script> + <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="../jquery.once.js"></script> </head> <body> diff --git a/jquery.once.js b/jquery.once.js index 8363e50..30573f2 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -15,35 +15,38 @@ * @see {@link http://github.com/umdjs/umd} */ (function (factory) { - "use strict"; - if (typeof exports === "object") { + 'use strict'; + + if (typeof exports === 'object') { // CommonJS - factory(require("jquery")); - } else if (typeof define === "function" && define.amd) { + factory(require('jquery')); + } else if (typeof define === 'function' && define.amd) { // AMD - define(["jquery"], factory); + /* globals define */ + define(['jquery'], factory); } else { // Global object + /* globals jQuery */ factory(jQuery); } }(function ($) { - "use strict"; + 'use strict'; /** - * Ensures that the given ID is valid, returning "once" if one is not given. + * Ensures that the given ID is valid, returning 'once' if one is not given. * * @param {string} [id=once] - * A string representing the ID to check. Defaults to `"once"`. + * A string representing the ID to check. Defaults to `'once'`. * * @returns The valid ID name. * * @throws Error when an ID is provided, but not a string. * @private */ - var checkId = function(id) { - id = id || "once"; - if (typeof id !== "string") { - throw new Error("The jQuery Once id parameter must be a string"); + var checkId = function (id) { + id = id || 'once'; + if (typeof id !== 'string') { + throw new Error('The jQuery Once id parameter must be a string'); } return id; }; @@ -53,7 +56,7 @@ * * @param {string} [id=once] * The data ID used to determine whether the given elements have already - * been processed or not. Defaults to `"once"`. + * been processed or not. Defaults to `'once'`. * * @returns jQuery collection of elements that have now run once by * the given ID. @@ -61,21 +64,21 @@ * @example * ``` javascript * // The following will change the color of each paragraph to red, just once - * // for the "changecolor" key. + * // for the 'changecolor' key. * $('p').once('changecolor').css('color', 'red'); * * // .once() will return a set of elements that yet to have the once ID * // associated with them. You can return to the original collection set by * // using .end(). * $('p') - * .once("changecolorblue") - * .css("color", "blue") + * .once('changecolorblue') + * .css('color', 'blue') * .end() - * .css("color", "red"); + * .css('color', 'red'); * * // To execute a function on the once set, you can use jQuery's each(). - * $('div.calendar').once().each(function() { - * // Since there is no once ID provided here, the key will be "once". + * $('div.calendar').once().each(function () { + * // Since there is no once ID provided here, the key will be 'once'. * }); * ``` * @@ -88,10 +91,10 @@ */ $.fn.once = function (id) { // Build the jQuery Once data name from the provided ID. - var name = "jquery-once-" + checkId(id); + var name = 'jquery-once-' + checkId(id); // Find elements that don't have the jQuery Once data applied to them yet. - return this.filter(function() { + return this.filter(function () { return $(this).data(name) !== true; }).data(name, true); }; @@ -103,19 +106,19 @@ * A 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. Defaults to `"once"`. + * originally passed to the once() function. Defaults to `'once'`. * * @returns jQuery collection of elements that were acted upon to remove their * once data. * * @example * ``` javascript - * // Remove once data with the "changecolor" ID. The result set is the + * // Remove once data with the 'changecolor' ID. The result set is the * // elements that had their once data removed. - * $('p').removeOnce("changecolor").css("color", ""); + * $('p').removeOnce('changecolor').css('color', ''); * * // Any jQuery function can be performed on the result set. - * $("div.calendar").removeOnce().each(function() { + * $('div.calendar').removeOnce().each(function () { * // Remove the calendar behavior. * }); * ``` @@ -128,7 +131,7 @@ */ $.fn.removeOnce = function (id) { // Filter through the elements to find the once'd elements. - return this.findOnce(id).removeData("jquery-once-" + checkId(id)); + return this.findOnce(id).removeData('jquery-once-' + checkId(id)); }; /** @@ -138,21 +141,21 @@ * A 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. Defaults to "once". + * was originally passed to the once() function. Defaults to 'once'. * * @returns jQuery collection of elements that have been run once. * * @example * ``` javascript * // Find all elements that have been changecolor'ed once. - * $('p').findOnce('changecolor').each(function() { + * $('p').findOnce('changecolor').each(function () { * // This function is called for all elements that has already once'd. * }); * - * // Find all elements that have been acted on with the default "once" key. - * $('p').findOnce().each(function() { + * // Find all elements that have been acted on with the default 'once' key. + * $('p').findOnce().each(function () { * // This function is called for all elements that have been acted on with - * // a "once" action. + * // a 'once' action. * }); * ``` * @@ -164,9 +167,9 @@ */ $.fn.findOnce = function (id) { // Filter the elements by which do have the data. - var name = "jquery-once-" + checkId(id); + var name = 'jquery-once-' + checkId(id); - return this.filter(function() { + return this.filter(function () { return $(this).data(name) === true; }); }; diff --git a/jquery.once.min.js.map b/jquery.once.min.js.map index c04060d..1db77fa 100644 --- a/jquery.once.min.js.map +++ b/jquery.once.min.js.map @@ -1 +1 @@ -{"version":3,"file":"jquery.once.min.js","sources":["jquery.once.js"],"names":["factory","exports","require","define","amd","jQuery","$","checkId","id","Error","fn","once","name","this","filter","data","removeOnce","findOnce","removeData"],"mappings":";;;;;;CAgBC,SAAUA,GACT,YACA,UAAWC,WAAY,SAAU,CAE/BD,EAAQE,QAAQ,eACX,UAAWC,UAAW,YAAcA,OAAOC,IAAK,CAErDD,QAAQ,UAAWH,OACd,CAELA,EAAQK,WAEV,SAAUC,GACV,YAaA,IAAIC,GAAU,SAASC,GACrBA,EAAKA,GAAM,MACX,UAAWA,KAAO,SAAU,CAC1B,KAAM,IAAIC,OAAM,iDAElB,MAAOD,GAyCTF,GAAEI,GAAGC,KAAO,SAAUH,GAEpB,GAAII,GAAO,eAAiBL,EAAQC,EAGpC,OAAOK,MAAKC,OAAO,WACjB,MAAOR,GAAEO,MAAME,KAAKH,KAAU,OAC7BG,KAAKH,EAAM,MAiChBN,GAAEI,GAAGM,WAAa,SAAUR,GAE1B,MAAOK,MAAKI,SAAST,GAAIU,WAAW,eAAiBX,EAAQC,IAkC/DF,GAAEI,GAAGO,SAAW,SAAUT,GAExB,GAAII,GAAO,eAAiBL,EAAQC,EAEpC,OAAOK,MAAKC,OAAO,WACjB,MAAOR,GAAEO,MAAME,KAAKH,KAAU"}
\ No newline at end of file +{"version":3,"file":"jquery.once.min.js","sources":["jquery.once.js"],"names":["factory","exports","require","define","amd","jQuery","$","checkId","id","Error","fn","once","name","this","filter","data","removeOnce","findOnce","removeData"],"mappings":";;;;;;CAgBC,SAAUA,GACT,YAEA,UAAWC,WAAY,SAAU,CAE/BD,EAAQE,QAAQ,eACX,UAAWC,UAAW,YAAcA,OAAOC,IAAK,CAGrDD,QAAQ,UAAWH,OACd,CAGLA,EAAQK,WAEV,SAAUC,GACV,YAaA,IAAIC,GAAU,SAAUC,GACtBA,EAAKA,GAAM,MACX,UAAWA,KAAO,SAAU,CAC1B,KAAM,IAAIC,OAAM,iDAElB,MAAOD,GAyCTF,GAAEI,GAAGC,KAAO,SAAUH,GAEpB,GAAII,GAAO,eAAiBL,EAAQC,EAGpC,OAAOK,MAAKC,OAAO,WACjB,MAAOR,GAAEO,MAAME,KAAKH,KAAU,OAC7BG,KAAKH,EAAM,MAiChBN,GAAEI,GAAGM,WAAa,SAAUR,GAE1B,MAAOK,MAAKI,SAAST,GAAIU,WAAW,eAAiBX,EAAQC,IAkC/DF,GAAEI,GAAGO,SAAW,SAAUT,GAExB,GAAII,GAAO,eAAiBL,EAAQC,EAEpC,OAAOK,MAAKC,OAAO,WACjB,MAAOR,GAAEO,MAAME,KAAKH,KAAU"}
\ No newline at end of file diff --git a/once.jquery.json b/once.jquery.json index 0df6d01..71c0f85 100644 --- a/once.jquery.json +++ b/once.jquery.json @@ -6,7 +6,7 @@ "jquery", "once" ], - "version": "2.0.2", + "version": "2.1.0", "author": { "name": "Rob Loach", "url": "http://robloach.net" diff --git a/package.json b/package.json index e9f2ec6..6b99c98 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "jquery-once", "title": "jQuery Once", "description": "Act on jQuery elements only once.", - "version": "2.0.2", + "version": "2.1.0", "keywords": [ "jquery", "jquery-plugin" @@ -36,22 +36,19 @@ "url": "http://opensource.org/licenses/MIT" } ], - "engines": { - "node": ">=0.10" - }, "dependencies": { "jquery": "*" }, "devDependencies": { - "eslint": "^0.22.1", - "jsdoc-to-markdown": "^1.0.3", - "jsdom": "~3.1.2", - "mocha": "~2.2.4", - "mocha-jsdom": "~0.4.0", - "uglify-js": "~2.4.21" + "jsdoc-to-markdown": "^1.1.1", + "jsdom": "~6.3.0", + "mocha": "~2.3.0", + "mocha-jsdom": "~1.0.0", + "semistandard": "^7.0.2", + "uglify-js": "~2.4.24" }, "scripts": { - "pretest": "eslint jquery.once.js test/test.js", + "pretest": "semistandard", "test": "mocha test/test.js", "docs": "jsdoc2md jquery.once.js > API.md", "build": "uglifyjs jquery.once.js -o jquery.once.min.js --comments --source-map jquery.once.min.js.map --mangle", diff --git a/test/index.js b/test/index.js index 2cfadb1..4ebe02c 100644 --- a/test/index.js +++ b/test/index.js @@ -3,15 +3,15 @@ */ var Mocha = require('mocha'); var path = require('path'); - + // Create our mocha instance. -var mocha = new Mocha; - +var mocha = new Mocha(); + // Add all the test files. mocha.addFile(path.join(__dirname, 'test.js')); - + // Run the tests. -mocha.run(function(failures){ +mocha.run(function (failures) { process.on('exit', function () { process.exit(failures); }); diff --git a/test/test.js b/test/test.js index e0c4711..ea3c5eb 100644 --- a/test/test.js +++ b/test/test.js @@ -1,12 +1,11 @@ -var jsdom = require("mocha-jsdom"); -var assert = require("assert"); +var jsdom = require('mocha-jsdom'); +var assert = require('assert'); /** * Automated tests for jQuery Once. */ -describe("jQuery Once", function() { - "use strict"; - +/* globals describe, it, before, beforeEach */ +describe('jQuery Once', function () { /** * The global instance of jQuery. */ @@ -20,116 +19,116 @@ describe("jQuery Once", function() { /** * Before the tests initiate, load jQuery and jQuery Once. */ - before(function() { - $ = require("jquery"); - require("../jquery.once.js"); + before(function () { + $ = require('jquery'); + require('../jquery.once.js'); }); /** * Before each test, reset the document body so that there is fresh data. */ - beforeEach(function() { + beforeEach(function () { // Build the body HTML. - document.body.innerHTML = "<p>This is the <span>Test</span>.</p>"; + document.body.innerHTML = '<p>This is the <span>Test</span>.</p>'; }); - it("should require ID to be a string", function () { + it('should require ID to be a string', function () { // Expect it to throw an error. - assert.throws(function() { - $("span").once(function () { + assert.throws(function () { + $('span').once(function () { // Nothing. }); }); }); - it("properly executes .once('test2')", function () { + it('properly executes .once("test2")', function () { // Create one once('test2') call. - $("span").once("test2").data("test2", "foo"); + $('span').once('test2').data('test2', 'foo'); // Create another once('test2') call. - $("span").once("test2").data("test2", "bar"); + $('span').once('test2').data('test2', 'bar'); // The data should result to the first once() call. - var data = $("span").data("test2"); - assert.equal(data, "foo"); + var data = $('span').data('test2'); + assert.equal(data, 'foo'); }); - it("is called only once with an ID", function() { + it('is called only once with an ID', function () { // Count the number of times once() was called. - $("span").data("count", 0); + $('span').data('count', 0); // Create the once() callback. - var callback = function() { + var callback = function () { // Increment the count variable stored in the data. - $("span").data("count", $("span").data("count") + 1); + $('span').data('count', $('span').data('count') + 1); }; // Call once() a bunch of times. for (var i = 0; i < 10; i++) { - $("span").once("count").each(callback); + $('span').once('count').each(callback); } // Verify that it was only called once. - var count = $("span").data("count"); - assert.equal(count, 1, "It was called " + count + " times."); + var count = $('span').data('count'); + assert.equal(count, 1, 'It was called ' + count + ' times.'); }); - it("is called only once without an ID", function() { + it('is called only once without an ID', function () { // Count the number of times once() was called. - $("span").data("once", 0); + $('span').data('once', 0); // Create the once() callback. - var callback = function() { - $("span").data("once", $("span").data("once") + 1); + var callback = function () { + $('span').data('once', $('span').data('once') + 1); }; // Call once() a bunch of times. for (var i = 0; i < 10; i++) { - $("span").once().each(callback); + $('span').once().each(callback); } // Verify that it was only called once. - var count = $("span").data("once"); - assert.equal(count, 1, "It was called " + count + " times."); + var count = $('span').data('once'); + assert.equal(count, 1, 'It was called ' + count + ' times.'); }); - it("retrieves empty once data correctly", function() { + it('retrieves empty once data correctly', function () { // Verify that the element starts without the class. - var hasData = $("span").data("jquery-once-test3"); - assert(!hasData, "Value not applied in the beginning."); + var hasData = $('span').data('jquery-once-test3'); + assert(!hasData, 'Value not applied in the beginning.'); // Create one once() call. - $("span").once("test3"); + $('span').once('test3'); // Verify the data is applied. - hasData = $("span").data("jquery-once-test3"); - assert(hasData, "The value is properly applied after once()."); + hasData = $('span').data('jquery-once-test3'); + assert(hasData, 'The value is properly applied after once().'); }); - it("calls removeOnce() correctly", function() { + it('calls removeOnce() correctly', function () { // Create one once() call. - $("span").once("test4"); + $('span').once('test4'); // Verify the data is applied. - var hasData = $("span").data("jquery-once-test4"); - assert(hasData, "The value is properly applied after once()."); + var hasData = $('span').data('jquery-once-test4'); + assert(hasData, 'The value is properly applied after once().'); // Remove the once property. - $("span").removeOnce("test4"); - hasData = $("span").data("jquery-once-test4"); - assert(!hasData, "The value is properly removed when called removeOnce()."); + $('span').removeOnce('test4'); + hasData = $('span').data('jquery-once-test4'); + assert(!hasData, 'The value is properly removed when called removeOnce().'); }); - it("calls findOnce() correctly", function() { + it('calls findOnce() correctly', function () { // Append an additional span to the end. - document.body.innerHTML += "<p>This is the <span>Test 2</span>.</p>"; + document.body.innerHTML += '<p>This is the <span>Test 2</span>.</p>'; // Create one once() call. - $("span").once("test5").data("foo", "bar"); + $('span').once('test5').data('foo', 'bar'); // Find the once'd elements. - $("span").findOnce("test5").each(function() { - assert.equal($(this).data("foo"), "bar", "Found correct span data."); + $('span').findOnce('test5').each(function () { + assert.equal($(this).data('foo'), 'bar', 'Found correct span data.'); }); }); |