diff options
author | Rob Loach <robloach@gmail.com> | 2014-11-03 00:42:50 -0800 |
---|---|---|
committer | Rob Loach <robloach@gmail.com> | 2014-11-03 00:42:50 -0800 |
commit | 43af89bfb0d71acf447ab3c21b552facb461da6a (patch) | |
tree | 638a10e1ecaeb9d143a861255a5667c4b9d95da7 | |
parent | ad87ba262b4ae6b64e31b10ef9bced5168d8e467 (diff) | |
parent | 2dde6eb29fa82af61ddba108da42c79cab60f100 (diff) | |
download | jquery-once-43af89bfb0d71acf447ab3c21b552facb461da6a.zip jquery-once-43af89bfb0d71acf447ab3c21b552facb461da6a.tar.gz jquery-once-43af89bfb0d71acf447ab3c21b552facb461da6a.tar.bz2 |
Update CoffeeScript source
-rw-r--r-- | .jshintrc | 63 | ||||
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | Gruntfile.js | 65 | ||||
-rw-r--r-- | HISTORY.md | 15 | ||||
-rw-r--r-- | README.md | 20 | ||||
-rw-r--r-- | bower.json | 6 | ||||
-rw-r--r-- | component.json | 2 | ||||
-rw-r--r-- | composer.json | 45 | ||||
-rw-r--r-- | example/index.html | 34 | ||||
-rw-r--r-- | jquery.once.js | 5 | ||||
-rw-r--r-- | jquery.once.js.map | 2 | ||||
-rw-r--r-- | jquery.once.litcoffee | 14 | ||||
-rw-r--r-- | jquery.once.min.js | 6 | ||||
-rw-r--r-- | once.jquery.json | 52 | ||||
-rw-r--r-- | package.json | 14 | ||||
-rw-r--r-- | test/index.html | 6 | ||||
-rw-r--r-- | test/test.js | 26 |
17 files changed, 149 insertions, 227 deletions
diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 643c399..0000000 --- a/.jshintrc +++ /dev/null @@ -1,63 +0,0 @@ -{ - // enforcing options - "bitwise": true, - "camelcase": true, - "curly": false, // we like one liners - "eqeqeq": true, - "es3": true, - "forin": true, - "freeze": true, - "immed": true, - "indent": 1, // we use tabs - "latedef": true, - "newcap": true, - "noarg": true, - "noempty": true, - "nonbsp": true, - "nonew": true, - "plusplus": false, // we are good at js - "quotmark": false, // we like flexibility - "undef": true, - "unused": true, - "strict": true, - "trailing": true, - "maxparams": false, // no - "maxdepth": false, // no - "maxstatements": false, // no - "maxcomplexity": false, // no - "maxlen": false, // no - - // relaxing options - "asi": true, // we use asi - "boss": true, // we understand assignments - "debug": false, - "eqnull": true, // we know how to do null/undefined checks - "esnext": false, - "evil": false, - "expr": false, - "funcscope": false, - "gcl": true, - "globalstrict": false, - "iterator": false, - "lastsemic": false, - "laxbreak": false, - "laxcomma": false, - "loopfunc": false, - "moz": false, - "multistr": false, - "notypeof": false, - "proto": false, - "scripturl": false, - "smarttabs": false, // default; spaces should only be mixed with tabs after words - "shadow": false, - "sub": false, - "supernew": false, - "noyield": false, - - // environments - "browser": true, - "node": true, - - // legacy - "onevar": false -} diff --git a/.travis.yml b/.travis.yml index efd3a59..f136c55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ language: node_js # ensure dev dependencies are installed (handled via npm install) # ensure test dependencies are installed (handled via cake install) install: - - npm install grunt-cli -g - npm install script: "npm test" node_js: diff --git a/Gruntfile.js b/Gruntfile.js index 5a17749..86df8fb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,6 @@ /*jshint node:true*/ module.exports = function(grunt) { - "use strict"; grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { @@ -15,72 +14,26 @@ module.exports = function(grunt) { }, all: { files: { - 'jquery.once.min.js': ['jquery.once.js'] + 'jquery.once.min.js': [ + 'jquery.once.js' + ] } } }, qunit: { - files: ['test/index.html'] - }, - jshint: { - options: { - curly: true, - eqeqeq: true, - immed: true, - latedef: true, - newcap: true, - noarg: true, - sub: true, - undef: true, - eqnull: true, - browser: true, - globals: { - jQuery: true, - $: true, - console: true, - require: true, - define: true - } - }, files: [ + 'test/index.html' + ] + }, + eslint: { + target: [ 'jquery.once.js' - ], - test: { - options: { - globals: { - jQuery: true, - $: true, - QUnit: true, - module: true, - test: true, - start: true, - stop: true, - expect: true, - ok: true, - equal: true, - deepEqual: true, - strictEqual: true - } - }, - files: { - src: [ - 'test/test.js' - ] - } - }, - grunt: { - files: { - src: [ - 'Gruntfile.js' - ] - } - } + ] } }); grunt.loadNpmTasks('grunt-contrib-qunit'); grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-coffee'); grunt.registerTask('default', ['qunit']); grunt.registerTask('release', ['default', 'uglify']); @@ -1,5 +1,20 @@ # History +## v2.0.0-alpha.10 November 2, 2014 +- Switch to [CoffeeScript](http://coffeescript.org) + +## v2.0.0-alpha.9 October 16, 2014 +- `id` parameter of `.once()` now a required parameter + - From [@theodoreb](http://github.com/theodoreb) + +## v2.0.0-alpha.8 October 9, 2014 +- Update documentation +- Fix whitespace +- Switch from JSHint to ESLint + +## v2.0.0-alpha.7 October 8, 2014 +- Removed unneeded cache variable + ## v2.0.0-alpha.6 October 5, 2014 - Removed function callback in order to promote jQuery chaining standards @@ -35,7 +35,7 @@ Act on jQuery elements only once. ### [Browserify](http://browserify.org/) - Use: `require('jquery-once')` - Install: `npm install --save jquery-once` -- CDN URL: `//wzrd.in/bundle/jquery-once@2.0.0-alpha.6` +- CDN URL: `//wzrd.in/bundle/jquery-once@2.0.0-alpha.9` ### [Ender](http://ender.jit.su/) - Use: `require('jquery-once')` @@ -54,7 +54,7 @@ Act on jQuery elements only once. ## Usage -[See the `jquery.once.litcoffee` for documentation.](jquery.once.litcoffee) +[See `jquery.once.litcoffee` for documentation.](jquery.once.litcoffee) ## Development @@ -62,21 +62,13 @@ Install dependencies through [npm](http://npmjs.org): npm install -Use [Grunt](http://gruntjs.com) to run [qunit](http://qunitjs.com) tests: +Run the following command to run tests: - grunt jshint qunit + npm run-script test -Build the project with [Grunt](http://gruntjs.com): +Build the project with: - grunt release - -Update project documentation with [Projectz](https://github.com/bevry/projectz): - - npm run-script projectz - -Generate code documentation with [JSDoc](http://usejsdoc.org): - - npm run-script jsdoc + npm run-script release <!-- HISTORY/ --> @@ -1,8 +1,8 @@ { "name": "jquery-once", "homepage": "http://github.com/robloach/jquery-once", - "description": "jQuery Once Plugin", - "version": "2.0.0-alpha.6", + "description": "jQuery Once", + "version": "2.0.0-alpha.9", "main": "jquery.once.js", "ignore": [ "*.json", @@ -20,9 +20,9 @@ }, "devDependencies": { "grunt": "~0.4.5", - "grunt-contrib-jshint": "~0.10.0", "grunt-contrib-qunit": "~0.5.2", "grunt-contrib-uglify": "~0.6.0", + "grunt-eslint": "~1.1.0", "projectz": "~0.3.15" } }
\ No newline at end of file diff --git a/component.json b/component.json index 35ffb81..e952219 100644 --- a/component.json +++ b/component.json @@ -4,7 +4,7 @@ "homepage": "http://github.com/robloach/jquery-once", "description": "Act on jQuery elements only once.", "license": "GPL-2.0", - "version": "2.0.0-alpha.6", + "version": "2.0.0-alpha.9", "keywords": [ "jquery" ], diff --git a/composer.json b/composer.json index c5c7ab3..32cea87 100644 --- a/composer.json +++ b/composer.json @@ -1,25 +1,26 @@ { - "name": "robloach/jquery-once", - "description": "Act on jQuery elements only once.", - "type": "component", - "license": [ - "MIT", - "GPL-2.0" - ], - "require": { - "components/jquery": ">=2.1.1" - }, - "extra": { - "component": { - "scripts": [ - "jquery.once.js" - ], - "files": [ - "jquery.once.min.js" - ], - "shim": { - "deps": ["jquery"] - } - } + "name": "robloach/jquery-once", + "description": "Act on jQuery elements only once.", + "type": "component", + "license": [ + "MIT", + "GPL-2.0" + ], + "require": { + "components/jquery": ">=2.1.1" + }, + "extra": { + "component": { + "scripts": [ + "jquery.once.js" + ], + "files": [ + "jquery.once.min.js", + "jquery.once.js.map" + ], + "shim": { + "deps": ["jquery"] + } } + } } diff --git a/example/index.html b/example/index.html index 6f9cfe9..7a2c13b 100644 --- a/example/index.html +++ b/example/index.html @@ -1,18 +1,24 @@ <!DOCTYPE html> <html> - <head> - <script src="../node_modules/jquery/dist/jquery.js"></script> - <script src="../jquery.once.js"></script> - </head> - <body> - <h1>jQuery Once</h1> - <p>This is some text, which should stay green.</p> - <script> - // Change the color of the text to green. - $('p').once('changecolor').css('color', 'green'); + <head> + <script src="../node_modules/jquery/dist/jquery.js"></script> + <script src="../jquery.once.js"></script> + </head> + <body> + <h1>jQuery Once</h1> + <p>This is some text, which should stay green.</p> + <script> + // Change the color of the text to green. + $('p').once('changecolor').css('color', 'green'); - // Attempt to change the color again. - $('p').once('changecolor').css('color', 'red'); - </script> - </body> + // Attempt to change the color again. + $('p').once('changecolor').css('color', 'red'); + + // Now change the background color. + $('p').once('changebackground').css('background-color', 'black'); + + // Change it again. + $('p').once('changebackground').css('background-color', 'yellow'); + </script> + </body> </html> diff --git a/jquery.once.js b/jquery.once.js index 5deed57..a547c1a 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -13,7 +13,10 @@ uuid = 0; $.fn.once = function(id) { var name; - name = "jquery-once-" + (id || ++uuid); + if (!id) { + throw new Error("An ID is required when calling jQuery.once()"); + } + name = "jquery-once-" + id; return this.filter(function() { return $(this).data(name) !== true; }).data(name, true); diff --git a/jquery.once.js.map b/jquery.once.js.map index 31f3ae9..c8046f5 100644 --- a/jquery.once.js.map +++ b/jquery.once.js.map @@ -6,5 +6,5 @@ "jquery.once.litcoffee" ], "names": [], - "mappings": ";AAaI;AAAA,EAAA,CAAC,SAAC,OAAD,GAAA;AACC,IAAA,IAAG,MAAA,CAAA,OAAA,KAAkB,QAArB;AACE,MAAA,OAAA,CAAQ,OAAA,CAAQ,QAAR,CAAR,CAAA,CADF;KAAA,MAEK,IAAG,MAAA,CAAA,MAAA,KAAiB,UAAjB,IAAgC,MAAM,CAAC,GAA1C;AACH,MAAA,MAAA,CAAO,CAAC,QAAD,CAAP,EAAmB,OAAnB,CAAA,CADG;KAAA,MAAA;AAGH,MAAA,OAAA,CAAQ,MAAR,CAAA,CAHG;KAHN;EAAA,CAAD,CAAA,CAQE,SAAC,CAAD,GAAA;AACA,QAAA,IAAA;AAAA,IAAA,IAAA,GAAO,CAAP,CAAA;AAAA,IA4BA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E,SAAC,CAAD,GAAA;AACA,QAAA,IAAA;AAAA,IAAA,IAAA,GAAO,CAAP,CAAA;AAAA,IA0BA,CAAC,CAAC,EAAE,CAAC,IAAL,GAAY,SAAC,EAAD,GAAA;AAEV,UAAA,IAAA;AAAA,MAAA,IAAmE,CAAA,EAAnE;AAAA,cAAU,IAAA,KAAA,CAAM,8CAAN,CAAV,CAAA;OAAA;AAAA,MAGA,IAAA,GAAO,cAAA,GAAiB,EAHxB,CAAA;aAMA,IAAC,CAAA,MAAD,CAAQ,SAAA,GAAA;eACN,CAAA,CAAE,IAAF,CAAO,CAAC,IAAR,CAAa,IAAb,CAAA,KAAwB,KADlB;MAAA,CAAR,CAEA,CAAC,IAFD,CAEM,IAFN,EAEY,IAFZ,EARU;IAAA,CA1BZ,CAAA;AAAA,IAkEA,CAAC,CAAC,EAAE,CAAC,UAAL,GAAkB,SAAC,EAAD,GAAA;aAEhB,IAAC,CAAA,QAAD,CAAU,EAAV,CAAa,CAAC,UAAd,CAAyB,cAAA,GAAiB,EAA1C,EAFgB;IAAA,CAlElB,CAAA;AAAA,IAiGA,CAAC,CAAC,EAAE,CAAC,QAAL,GAAgB,SAAC,EAAD,GAAA;AAEd,UAAA,IAAA;AAAA,MAAA,IAAA,GAAO,cAAA,GAAiB,EAAxB,CAAA;aACA,IAAC,CAAA,MAAD,CAAQ,SAAA,GAAA;eACN,CAAA,CAAE,IAAF,CAAO,CAAC,IAAR,CAAa,IAAb,CAAA,KAAsB,KADhB;MAAA,CAAR,EAHc;IAAA,CAjGhB,CADA;EAAA,CARF,CAAA,CAAA;AAAA" }
\ No newline at end of file diff --git a/jquery.once.litcoffee b/jquery.once.litcoffee index 369b392..445e22a 100644 --- a/jquery.once.litcoffee +++ b/jquery.once.litcoffee @@ -29,10 +29,8 @@ Filter elements by whether they have not yet been processed. #### Parameters -* `id` *(string)* The optional data id used to determine whether the given - elements have already been processed or not. When id is not provided, it - becomes a unique identifier, depicted as a number. The element's data id will - then be represented in the form of `jquery-once-#`. +* `id` The data id used to determine whether the given elements have already +been processed or not. #### Returns @@ -49,9 +47,11 @@ $('p').once('changecolor').css('color', 'green'); #### Source $.fn.once = (id) -> - # Build the name for the data identifier. Generate a new unique id if - # the id parameter is not provided. - name = "jquery-once-" + (id or ++uuid) + # The id parameter is required. + throw new Error("An ID is required when calling jQuery.once()") if not id + + # Build the name for the data identifier. + name = "jquery-once-" + id # Filter the elements by which do not have the data yet. @filter -> diff --git a/jquery.once.min.js b/jquery.once.min.js index 5c222a8..45302c6 100644 --- a/jquery.once.min.js +++ b/jquery.once.min.js @@ -1,4 +1,4 @@ -/*! jQuery Once - v2.0.0-alpha.6 - 10/7/2014 - https://github.com/RobLoach/jquery-once - * (c) 2014 Rob Loach (http://github.com/robloach) +/*! jQuery Once - v2.0.0-alpha.9 - 10/16/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";var b={},c=0;a.fn.once=function(d){"string"!=typeof d&&(d in b||(b[d]=++c),d=b[d]);var e="jquery-once-"+d;return this.filter(function(){return a(this).data(e)!==!0}).data(e,!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)throw new Error("An ID is required when calling jQuery.once()");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 diff --git a/once.jquery.json b/once.jquery.json index d8323ae..d562ac2 100644 --- a/once.jquery.json +++ b/once.jquery.json @@ -1,30 +1,30 @@ { - "name": "once", - "title": "jQuery Once", - "description": "Act on jQuery elements only once.", - "keywords": [ - "jquery", - "once" - ], - "version": "2.0.0-alpha.6", - "author": { - "name": "Rob Loach", - "url": "http://robloach.net" + "name": "once", + "title": "jQuery Once", + "description": "Act on jQuery elements only once.", + "keywords": [ + "jquery", + "once" + ], + "version": "2.0.0-alpha.9", + "author": { + "name": "Rob Loach", + "url": "http://robloach.net" + }, + "licenses": [ + { + "type": "GPL-2.0", + "url": "http://opensource.org/licenses/gpl-2.0.php" }, - "licenses": [ - { - "type": "GPL-2.0", - "url": "http://opensource.org/licenses/gpl-2.0.php" - }, - { - "type": "MIT", - "url": "http://opensource.org/licenses/MIT" - } - ], - "bugs": "https://github.com/RobLoach/jquery-once/issues", - "homepage": "https://github.com/RobLoach/jquery-once", - "download": "https://github.com/RobLoach/jquery-once/archive/master.zip", - "dependencies": { - "jquery": "~2.1.1" + { + "type": "MIT", + "url": "http://opensource.org/licenses/MIT" } + ], + "bugs": "https://github.com/RobLoach/jquery-once/issues", + "homepage": "https://github.com/RobLoach/jquery-once", + "download": "https://github.com/RobLoach/jquery-once/archive/master.zip", + "dependencies": { + "jquery": "~2.1.1" + } } diff --git a/package.json b/package.json index b43b57d..b617297 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.0-alpha.6", + "version": "2.0.0-alpha.9", "keywords": [ "jquery" ], @@ -52,15 +52,17 @@ "coffee-script": "~1.8.0", "coffeelint": "~1.6.1", "grunt": "~0.4.5", - "grunt-contrib-coffee": "~0.12.0", "grunt-contrib-qunit": "~0.5.2", "grunt-contrib-uglify": "~0.6.0", - "projectz": "~0.3.15" + "projectz": "~0.3.15", + "qunitjs": "~1.15.0" }, "scripts": { "compile": "./node_modules/.bin/coffee -m -c *.litcoffee", - "test": "./node_modules/.bin/coffeelint *.litcoffee && grunt qunit", - "projectz": "node_modules/.bin/projectz compile", - "release": "npm run-script compile && grunt release" + "coffeelint": "./node_modules/.bin/coffeelint *.litcoffee", + "test": "npm run-script coffeelint && npm run-script compile && npm run-script qunit", + "qunit": "grunt qunit", + "projectz": "./node_modules/.bin/projectz compile", + "release": "npm run-script compile && grunt release && npm run-script projectz" } } 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> diff --git a/test/test.js b/test/test.js index 88d59e7..44ab452 100644 --- a/test/test.js +++ b/test/test.js @@ -1,12 +1,26 @@ -test("Properly executed", function() { - // Create one once() call. - $('#test1 span').once().data('test1', 'foobar'); +test("ID required", function() { + expect(1); + try { + $("#test1 span").once(); + } + catch (e) { + ok(e, "Error is triggered when ID is missing."); + } +}); + +test(".once('test1-2') properly executed", function() { + // Create one once('test1-2') call. + $('#test1 span').once('test1-2').data('test1-2', 'foo'); + + // Create another once('test1-2') call. + $('#test1 span').once('test1-2').data('test1-2', 'bar'); - var data = $('#test1 span').data('test1'); - ok(data === "foobar"); + // The data should result to the first once() call. + var data = $('#test1 span').data('test1-2'); + ok(data === "foo"); }); -test("Called only once", function() { +test("Called only once, counted", function() { // Count the number of times once() was called. $('#test2 span').data('count', 0); |