diff options
-rw-r--r-- | .travis.yml | 7 | ||||
-rw-r--r-- | Gruntfile.js | 88 | ||||
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | bower.json | 2 | ||||
-rw-r--r-- | component.json | 2 | ||||
-rw-r--r-- | composer.json | 1 | ||||
-rw-r--r-- | example/index.html | 2 | ||||
-rw-r--r-- | jquery.once.js | 2 | ||||
-rw-r--r-- | jquery.once.min.js | 4 | ||||
-rw-r--r-- | once.jquery.json | 2 | ||||
-rw-r--r-- | package.json | 13 | ||||
-rw-r--r-- | test/index.html | 30 | ||||
-rw-r--r-- | test/test.js | 45 |
13 files changed, 202 insertions, 7 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d63b2ee --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - 0.11 + - 0.10 +install: + - npm install grunt-cli -g + - npm install diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..740293f --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,88 @@ +/*jshint node:true*/ + +module.exports = function(grunt) { + "use strict"; + 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'] + }, + 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: [ + '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-jshint'); + grunt.loadNpmTasks('grunt-contrib-qunit'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + + grunt.registerTask('default', ['jshint', 'qunit']); + grunt.registerTask('release', ['default', 'uglify']); + +}; @@ -31,6 +31,17 @@ $('div.calendar').once(function() { }); ``` +Development +----------- + +Leverage [npm](http://npmjs.org), [grunt](http://gruntjs.com), and [qunit](http://qunitjs.com): + +``` bash +$ npm install +$ npm test +$ grunt release +``` + License ------- @@ -1,7 +1,7 @@ { "name": "jquery-once", "description": "jQuery Once Plugin", - "version": "1.2.1", + "version": "1.2.3", "keywords": [ "jquery" ], diff --git a/component.json b/component.json index ba3319d..149182e 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "jquery-once", "description": "jQuery Once Plugin", - "version": "1.2.1", + "version": "1.2.3", "keywords": [ "jquery" ], diff --git a/composer.json b/composer.json index 0172176..bc1b32d 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ }, "extra": { "component": { + "main": "jquery.once.js", "scripts": [ "jquery.once.js" ], diff --git a/example/index.html b/example/index.html index 0afff9b..fa009dc 100644 --- a/example/index.html +++ b/example/index.html @@ -2,7 +2,7 @@ <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> - <script src="../jquery.once.js"></script> + <script src="../jquery.once.min.js"></script> </head> <body> <h1>jQuery Once</h1> diff --git a/jquery.once.js b/jquery.once.js index f1ad1ba..5363945 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -1,5 +1,5 @@ /** - * jQuery Once Plugin v1.2.2 + * jQuery Once Plugin 1.2.3 * http://plugins.jquery.com/once/ * * Dual licensed under the MIT and GPL licenses: diff --git a/jquery.once.min.js b/jquery.once.min.js new file mode 100644 index 0000000..47276e1 --- /dev/null +++ b/jquery.once.min.js @@ -0,0 +1,4 @@ +/*! jquery-once - v1.2.3 - 6/13/2013 - http://github.com/robloach/jquery-once + * (c) 2013 Rob Loach (http://robloach.net) + * Licensed GPL-2.0, MIT */ +(function(e){"use strict";"object"==typeof exports?e(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)})(function(e){"use strict";var n={},t=0;e.fn.once=function(r,i){"string"!=typeof r&&(r in n||(n[r]=++t),i||(i=r),r="jquery-once-"+n[r]);var o=r+"-processed",s=this.not("."+o).addClass(o);return e.isFunction(i)?s.each(i):s},e.fn.removeOnce=function(n,t){var r=n+"-processed",i=this.filter("."+r).removeClass(r);return e.isFunction(t)?i.each(t):i}});
\ No newline at end of file diff --git a/once.jquery.json b/once.jquery.json index a28c74f..961f715 100644 --- a/once.jquery.json +++ b/once.jquery.json @@ -6,7 +6,7 @@ "jquery", "once" ], - "version": "1.2.1", + "version": "1.2.3", "author": { "name": "Konstantin Kafer", "url": "http://kkaefer.com" diff --git a/package.json b/package.json index 4895b9c..396374e 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "jquery-once", "description": "jQuery Once Plugin.", - "version": "1.2.1", + "version": "1.2.3", "keywords": [ "jquery" ], "homepage": "http://github.com/robloach/jquery-once", - "author": "Konstantin Kafer", + "author": "Rob Loach (http://robloach.net)", "repository": { "type": "git", "url": "https://github.com/RobLoach/jquery-once.git" @@ -23,5 +23,14 @@ ], "dependencies": { "jquery": "~1.8.0" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-contrib-qunit": "~0.2.1", + "grunt-contrib-jshint": "~0.4.3", + "grunt-contrib-uglify": "~0.1.1" + }, + "scripts": { + "test": "grunt jshint qunit" } } diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..adc06ba --- /dev/null +++ b/test/index.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<head> + <title>jQuery Once - Test Suite</title> + <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.11.0.css"> +</head> +<body id="body"> + <div id="qunit"></div> + <div id="qunit-fixture"> + + <div id="test1"> + <p>This is <span>Test 1</span>.</p> + </div> + + <div id="test2"> + <p>This is <span>Test 2</span>.</p> + </div> + + <div id="test3"> + <p>This is <span>Test 3</span>.</p> + </div> + + </div> + + <script src="http://code.jquery.com/jquery-1.10.0.js"></script> + <script src="http://code.jquery.com/qunit/qunit-1.11.0.js"></script> + <script src="../jquery.once.js"></script> + <script src="test.js"></script> +</body> +</html> diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..533c532 --- /dev/null +++ b/test/test.js @@ -0,0 +1,45 @@ +test("Properly executed", function() { + // Create one once() call. + $('#test1 span').once(function() { + $(this).data('test1', 'foobar'); + }); + + var data = $('#test1 span').data('test1'); + ok(data === "foobar"); +}); + +test("Called only once", function() { + // Count the number of times once() was called. + $('#test2 span').data('count', 0); + + // Create the once() callback. + var callback = function() { + var count = $('#test2 span').data('count'); + count++; + $('#test2 span').data('count', count); + }; + + // Call once() a bunch of times. + for (var i = 0; i < 10; i++) { + $('#test2 span').once('count', callback); + } + + // Verify that it was only called once. + var count = $('#test2 span').data('count'); + ok(count === 1); +}); + +test("Apply the class correctly", function() { + // Verify that the element starts without the class. + var hasClass = $('#test3 span').hasClass('test3-processed'); + ok(!hasClass, 'Processed class not applied in the beginning.'); + + // Create one once() call. + $('#test3 span').once('test3', function() { + // Do nothing. + }); + + // Verify the class is applied. + hasClass = $('#test3 span').hasClass('test3-processed'); + ok(hasClass, 'The processed class is properly applied after once().'); +}); |