diff options
author | Rob Loach <robloach@gmail.com> | 2014-12-19 00:49:38 -0500 |
---|---|---|
committer | Rob Loach <robloach@gmail.com> | 2014-12-19 00:49:38 -0500 |
commit | 8177ff4cfce95d85158911006ba8e91a8468f6ae (patch) | |
tree | b6915100762faf811e3c248ba43fe1d75b6b43c1 | |
parent | 6a2ab3c7f9d58f2d47398ac29af06dec14c4612e (diff) | |
parent | 041b74c37e5480c9273d0228e635ca34a9b7fa6d (diff) | |
download | jquery-once-8177ff4cfce95d85158911006ba8e91a8468f6ae.zip jquery-once-8177ff4cfce95d85158911006ba8e91a8468f6ae.tar.gz jquery-once-8177ff4cfce95d85158911006ba8e91a8468f6ae.tar.bz2 |
Merge pull request #24 from RobLoach/fix/grunt
Reduce dependency on Grunt
-rw-r--r-- | Gruntfile.js | 27 | ||||
-rw-r--r-- | README.md | 61 | ||||
-rw-r--r-- | bower.json | 11 | ||||
-rw-r--r-- | composer.json | 5 | ||||
-rw-r--r-- | jquery.once.js | 12 | ||||
-rw-r--r-- | jquery.once.min.js | 2 | ||||
-rw-r--r-- | jquery.once.min.js.map | 1 | ||||
-rw-r--r-- | once.jquery.json | 2 | ||||
-rw-r--r-- | package.json | 14 | ||||
-rw-r--r-- | test/index.html | 6 |
10 files changed, 72 insertions, 69 deletions
diff --git a/Gruntfile.js b/Gruntfile.js index 3c7201b..af1d6f7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,40 +3,15 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - uglify: { - options: { - preserveComments: false, - banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + - '<%= grunt.template.today("m/d/yyyy") %>' + - '<%= pkg.homepage ? " - " + pkg.homepage + "\\n" : "" %>' + - ' * (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>\n' + - ' * Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n' - }, - all: { - files: { - 'jquery.once.min.js': [ - 'jquery.once.js' - ] - } - } - }, qunit: { files: [ 'test/index.html' ] - }, - eslint: { - target: [ - 'jquery.once.js' - ] } }); grunt.loadNpmTasks('grunt-contrib-qunit'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-eslint'); - grunt.registerTask('default', ['eslint', 'qunit']); - grunt.registerTask('release', ['default', 'uglify']); + grunt.registerTask('default', ['qunit']); }; @@ -58,29 +58,51 @@ be used to ensure that a function is only applied once to an element. ## Usage -### `.once()` +### `.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 + ``` javascript -$('div.calendar').once('calendar').each(function() { - // This function is only executed once for each div, even if this - // code segment is executed repeatedly. -}); $('div.calendar').once('calendar').click(function() { // .once('calendar') filters out all elements which already have been - // filtered with once(), and the elements that haven't been filtered + // 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()` +### `.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 + ``` javascript $('div.calendar').findOnce('calendar').each(function() { // This function is called for each element that was already called "once" @@ -88,10 +110,23 @@ $('div.calendar').findOnce('calendar').each(function() { }); ``` -### `.removeOnce()` +### `.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 -It is possible to remove the `.once()` data, and iterate through each element -whose once state is removed: +* `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 ``` javascript $('div.calendar').removeOnce('calendar').each(function() { @@ -110,9 +145,9 @@ Use [Grunt](http://gruntjs.com) to run [qunit](http://qunitjs.com) tests: grunt jshint qunit -Build the project with [Grunt](http://gruntjs.com): +Build the project with: - grunt release + npm run-script release Update project documentation with [Projectz](https://github.com/bevry/projectz): @@ -172,5 +207,3 @@ These amazing people have contributed code to this project: [Become a contributor!](https://github.com/RobLoach/jquery-once/blob/master/CONTRIBUTING.md#files) <!-- /BACKERS --> - - @@ -16,13 +16,6 @@ "jquery" ], "dependencies": { - "jquery": "~2.1.1" - }, - "devDependencies": { - "grunt": "~0.4.5", - "grunt-contrib-qunit": "~0.5.2", - "grunt-contrib-uglify": "~0.6.0", - "grunt-eslint": "~1.1.0", - "projectz": "~0.3.15" + "jquery": "*" } -}
\ No newline at end of file +} diff --git a/composer.json b/composer.json index 7737817..5407622 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "GPL-2.0" ], "require": { - "components/jquery": ">=2.1.1" + "components/jquery": "*" }, "extra": { "component": { @@ -15,7 +15,8 @@ "jquery.once.js" ], "files": [ - "jquery.once.min.js" + "jquery.once.min.js", + "jquery.once.min.js.map" ], "shim": { "deps": ["jquery"] diff --git a/jquery.once.js b/jquery.once.js index 87741f9..a13b9f8 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -1,10 +1,8 @@ /*! - * jQuery Once 2.0.0-alpha.9 - * http://github.com/robloach/jquery-once - * - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html + * jQuery Once v2.0.0-alpha.9 - http://github.com/robloach/jquery-once + * @license MIT, GPL-2.0 + * http://opensource.org/licenses/MIT + * http://opensource.org/licenses/GPL-2.0 */ /** @@ -55,7 +53,7 @@ $.fn.once = function (id) { id = id || "once"; if (typeof id !== "string") { - throw new Error("jQuery.once() parameter MUST be a string"); + throw new Error("jQuery.once() parameter must be a string"); } // Build the name for the data identifier. Generate a new unique id if the // id parameter is not provided. diff --git a/jquery.once.min.js b/jquery.once.min.js index ff683be..06c9519 100644 --- a/jquery.once.min.js +++ b/jquery.once.min.js @@ -1,4 +1,4 @@ /*! jQuery Once - v2.0.0-alpha.9 - 12/15/2014 - https://github.com/RobLoach/jquery-once * (c) 2014 Rob Loach (http://github.com/RobLoach) * Licensed GPL-2.0, MIT */ -!function(a){"use strict";"object"==typeof exports?a(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";a.fn.once=function(b){if(b=b||"once","string"!=typeof b)throw new Error("jQuery.once() parameter MUST be a string");var c="jquery-once-"+b;return this.filter(function(){return a(this).data(c)!==!0}).data(c,!0)},a.fn.removeOnce=function(a){return this.findOnce(a).removeData("jquery-once-"+a)},a.fn.findOnce=function(b){var c="jquery-once-"+b;return this.filter(function(){return a(this).data(c)===!0})}});
\ No newline at end of file +!function(a){"use strict";"object"==typeof exports?a(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"use strict";a.fn.once=function(b){if(b=b||"once","string"!=typeof b)throw new Error("jQuery.once() parameter MUST be a string");var c="jquery-once-"+b;return this.filter(function(){return a(this).data(c)!==!0}).data(c,!0)},a.fn.removeOnce=function(a){return this.findOnce(a).removeData("jquery-once-"+a)},a.fn.findOnce=function(b){var c="jquery-once-"+b;return this.filter(function(){return a(this).data(c)===!0})}}); diff --git a/jquery.once.min.js.map b/jquery.once.min.js.map new file mode 100644 index 0000000..937c2d2 --- /dev/null +++ b/jquery.once.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"jquery.once.min.js","sources":["jquery.once.js"],"names":["factory","exports","require","define","amd","jQuery","$","fn","once","id","Error","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,YAuBAA,GAAEC,GAAGC,KAAO,SAAUC,GACpB,IAAKA,EAAI,CACP,KAAM,IAAIC,OAAM,gDAIlB,GAAIC,GAAO,eAAiBF,CAG5B,OAAOG,MAAKC,OAAO,WACjB,MAAOP,GAAEM,MAAME,KAAKH,KAAU,OAC7BG,KAAKH,EAAM,MA2BhBL,GAAEC,GAAGQ,WAAa,SAAUN,GAE1B,MAAOG,MAAKI,SAASP,GAAIQ,WAAW,eAAiBR,GA0BvDH,GAAEC,GAAGS,SAAW,SAAUP,GAExB,GAAIE,GAAO,eAAiBF,CAE5B,OAAOG,MAAKC,OAAO,WACjB,MAAOP,GAAEM,MAAME,KAAKH,KAAU"}
\ No newline at end of file diff --git a/once.jquery.json b/once.jquery.json index d562ac2..c011458 100644 --- a/once.jquery.json +++ b/once.jquery.json @@ -25,6 +25,6 @@ "homepage": "https://github.com/RobLoach/jquery-once", "download": "https://github.com/RobLoach/jquery-once/archive/master.zip", "dependencies": { - "jquery": "~2.1.1" + "jquery": "*" } } diff --git a/package.json b/package.json index 4597862..f15dcb4 100644 --- a/package.json +++ b/package.json @@ -47,19 +47,21 @@ "node": ">=0.10" }, "dependencies": { - "jquery": "~2.1.1" + "jquery": "*" }, "devDependencies": { + "eslint": "~0.9.2", "grunt": "~0.4.5", "grunt-contrib-qunit": "~0.5.2", - "grunt-contrib-uglify": "~0.6.0", - "grunt-eslint": "~1.1.0", - "projectz": "~0.3.15" + "projectz": "~0.3.15", + "uglify-js": "~2.4.15", + "qunitjs": "~1.16.0" }, "scripts": { + "pretest": "./node_modules/.bin/eslint jquery.once.js", "test": "grunt", - "projectz": "node_modules/.bin/projectz compile", - "release": "grunt release", + "projectz": "./node_modules/.bin/projectz compile", + "release": "./node_modules/.bin/uglifyjs jquery.once.js -o jquery.once.min.js --comments --source-map jquery.once.min.js.map --mangle", "jsdoc": "jsdoc jquery.once.js README.md" } } diff --git a/test/index.html b/test/index.html index 038db22..6a0293f 100644 --- a/test/index.html +++ b/test/index.html @@ -2,7 +2,7 @@ <html> <head> <title>jQuery Once - Test Suite</title> - <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css"> + <link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css"> </head> <body id="body"> <div id="qunit"></div> @@ -31,8 +31,8 @@ </div> - <script src="http://code.jquery.com/jquery-2.1.1.js"></script> - <script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script> + <script src="../node_modules/jquery/dist/jquery.js"></script> + <script src="../node_modules/qunitjs/qunit/qunit.js"></script> <script src="../jquery.once.js"></script> <script src="test.js"></script> </body> |