From c9a250a1789a6932b44c08758f5166e98ddcecce Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 4 Jan 2024 17:12:20 -0500 Subject: [PATCH] 2.3.0 - Switched from `var` to `let` and `const` for variable scope - Removed `use strict` directives --- CHANGELOG.md | 7 ++++--- LICENSE.md | 2 +- example/index.html | 2 +- jquery.once.d.ts | 8 ++++---- jquery.once.js | 6 +++--- jquery.once.min.js | 4 ++-- jquery.once.min.js.map | 2 +- package.json | 10 ++++++++-- test/index.js | 21 --------------------- test/test.js | 28 ++++++++++++++-------------- 10 files changed, 38 insertions(+), 52 deletions(-) delete mode 100644 test/index.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 381cc4c..3f7bbaf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,13 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [2.3.0] - Unreleased +## [2.3.0] - January 4th, 2024 ### Changed +- Switched from `var` to `let` and `const` for variable scope +- Removed `use strict` directives - Updated developer dependencies +- Minor updates to developer documentation - Switched to GitHub Actions for testing -- Removed `use strict` directives -- Switched from `var` to `let` and `const` for variable scope ## [2.2.3] - May 14th, 2019 ### Fixed diff --git a/LICENSE.md b/LICENSE.md index 96a3d50..1201b6c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # License -Copyright © 2016-2020 [Rob Loach](http://github.com/RobLoach) +Copyright © 2016-2024 [Rob Loach](http://github.com/RobLoach) ## GPL-2.0 diff --git a/example/index.html b/example/index.html index 9d5bba6..4853e0c 100644 --- a/example/index.html +++ b/example/index.html @@ -1,7 +1,7 @@ - + diff --git a/jquery.once.d.ts b/jquery.once.d.ts index 57190da..597be42 100644 --- a/jquery.once.d.ts +++ b/jquery.once.d.ts @@ -1,5 +1,5 @@ /*! - * jQuery Once v2.2.3 Typescript Definition - http://github.com/robloach/jquery-once + * jQuery Once v2.3.0 Typescript Definition - http://github.com/robloach/jquery-once * @license MIT, GPL-2.0 * http://opensource.org/licenses/MIT * http://opensource.org/licenses/GPL-2.0 @@ -8,7 +8,7 @@ /// -interface JQuery{ +interface JQuery { /** * Filter elements that have yet to be processed by the given data ID. @@ -48,7 +48,7 @@ interface JQuery{ * @global * @public */ - once(id?:string): JQuery; + once(id?: string): JQuery; /** * Removes the once data from elements, based on the given ID. @@ -113,7 +113,7 @@ interface JQuery{ * @global * @public */ - findOnce(id:string): JQuery; + findOnce(id: string): JQuery; } diff --git a/jquery.once.js b/jquery.once.js index 1a63fc0..6b34b4e 100644 --- a/jquery.once.js +++ b/jquery.once.js @@ -1,12 +1,12 @@ /*! - * jQuery Once v2.2.3 - http://github.com/robloach/jquery-once + * jQuery Once v2.3.0 - http://github.com/robloach/jquery-once * @license MIT, GPL-2.0 * http://opensource.org/licenses/MIT * http://opensource.org/licenses/GPL-2.0 */ /** - * Universal Module Definition + * jQuery Once: Universal Module Definition * * jQuery Once has a dependency on jQuery, so we wrap the code with a UMD * pattern in order to allow loading jQuery and jQuery Once through a module @@ -34,7 +34,7 @@ * @param {string} [id=once] * A string representing the ID to check. Defaults to `'once'`. * - * @returns {number} The valid ID name. + * @returns {string} The valid ID name. * * @throws TypeError when an ID is provided, but not a string. * @private diff --git a/jquery.once.min.js b/jquery.once.min.js index 47a8780..33a2a3f 100644 --- a/jquery.once.min.js +++ b/jquery.once.min.js @@ -1,8 +1,8 @@ /*! - * jQuery Once v2.2.3 - http://github.com/robloach/jquery-once + * jQuery Once v2.3.0 - http://github.com/robloach/jquery-once * @license MIT, GPL-2.0 * http://opensource.org/licenses/MIT * http://opensource.org/licenses/GPL-2.0 */ -(function(e){"use strict";if(typeof exports==="object"&&typeof exports.nodeName!=="string"){e(require("jquery"))}else if(typeof define==="function"&&define.amd){define(["jquery"],e)}else{e(jQuery)}})(function(t){"use strict";var r=function(e){e=e||"once";if(typeof e!=="string"){throw new TypeError("The jQuery Once id parameter must be a string")}return e};t.fn.once=function(e){var n="jquery-once-"+r(e);return this.filter(function(){return t(this).data(n)!==true}).data(n,true)};t.fn.removeOnce=function(e){return this.findOnce(e).removeData("jquery-once-"+r(e))};t.fn.findOnce=function(e){var n="jquery-once-"+r(e);return this.filter(function(){return t(this).data(n)===true})}}); +(function(e){if(typeof exports==="object"&&typeof exports.nodeName!=="string"){e(require("jquery"))}else if(typeof define==="function"&&define.amd){define(["jquery"],e)}else{e(jQuery)}})(t=>{const r=function(e="once"){if(typeof e!=="string"){throw new TypeError("The jQuery Once id parameter must be a string")}return e};t.fn.once=function(e){const n="jquery-once-"+r(e);return this.filter(function(){return t(this).data(n)!==true}).data(n,true)};t.fn.removeOnce=function(e){return this.findOnce(e).removeData("jquery-once-"+r(e))};t.fn.findOnce=function(e){const n="jquery-once-"+r(e);return this.filter(function(){return t(this).data(n)===true})}}); //# sourceMappingURL=jquery.once.min.js.map \ No newline at end of file diff --git a/jquery.once.min.js.map b/jquery.once.min.js.map index a42313c..b53c225 100644 --- a/jquery.once.min.js.map +++ b/jquery.once.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["jquery.once.js"],"names":["factory","exports","nodeName","require","define","amd","jQuery","$","checkId","id","TypeError","fn","once","name","this","filter","data","removeOnce","findOnce","removeData"],"mappings":";;;;;;CAgBA,SAAWA,GACT,aAEA,UAAWC,UAAY,iBAAmBA,QAAQC,WAAa,SAAU,CAEvEF,EAAQG,QAAQ,gBACX,UAAWC,SAAW,YAAcA,OAAOC,IAAK,CAGrDD,OAAO,CAAC,UAAWJ,OACd,CAGLA,EAAQM,UAbZ,CAeG,SAAUC,GACX,aAaA,IAAIC,EAAU,SAAUC,GACtBA,EAAKA,GAAM,OACX,UAAWA,IAAO,SAAU,CAC1B,MAAM,IAAIC,UAAU,iDAGtB,OAAOD,GAyCTF,EAAEI,GAAGC,KAAO,SAAUH,GAEpB,IAAII,EAAO,eAAiBL,EAAQC,GAGpC,OAAOK,KAAKC,OAAO,WACjB,OAAOR,EAAEO,MAAME,KAAKH,KAAU,OAC7BG,KAAKH,EAAM,OAiChBN,EAAEI,GAAGM,WAAa,SAAUR,GAE1B,OAAOK,KAAKI,SAAST,GAAIU,WAAW,eAAiBX,EAAQC,KAkC/DF,EAAEI,GAAGO,SAAW,SAAUT,GAExB,IAAII,EAAO,eAAiBL,EAAQC,GAEpC,OAAOK,KAAKC,OAAO,WACjB,OAAOR,EAAEO,MAAME,KAAKH,KAAU","file":"jquery.once.min.js"} \ No newline at end of file +{"version":3,"file":"jquery.once.min.js","sources":["jquery.once.js"],"names":["factory","exports","nodeName","require","define","amd","jQuery","$","checkId","id","TypeError","fn","once","name","this","filter","data","removeOnce","findOnce","removeData"],"mappings":";;;;;;CAgBA,SAAWA,GACT,GAAI,OAAOC,UAAY,UAAY,OAAOA,QAAQC,WAAa,SAAU,CAEvEF,EAAQG,QAAQ,QAAQ,CAAC,CAC3B,MAAO,GAAI,OAAOC,SAAW,YAAcA,OAAOC,IAAK,CAGrDD,OAAO,CAAC,UAAWJ,CAAO,CAC5B,KAAO,CAGLA,EAAQM,MAAM,CAChB,CACD,GAAEC,IAYD,MAAMC,EAAU,SAAUC,EAAK,QAC7B,GAAI,OAAOA,IAAO,SAAU,CAC1B,MAAM,IAAIC,UAAU,+CAA+C,CACrE,CAEA,OAAOD,CACT,EAwCAF,EAAEI,GAAGC,KAAO,SAAUH,GAEpB,MAAMI,EAAO,eAAiBL,EAAQC,CAAE,EAGxC,OAAOK,KAAKC,OAAO,WACjB,OAAOR,EAAEO,IAAI,EAAEE,KAAKH,CAAI,IAAM,IAChC,CAAC,EAAEG,KAAKH,EAAM,IAAI,CACpB,EAgCAN,EAAEI,GAAGM,WAAa,SAAUR,GAE1B,OAAOK,KAAKI,SAAST,CAAE,EAAEU,WAAW,eAAiBX,EAAQC,CAAE,CAAC,CAClE,EAiCAF,EAAEI,GAAGO,SAAW,SAAUT,GAExB,MAAMI,EAAO,eAAiBL,EAAQC,CAAE,EAExC,OAAOK,KAAKC,OAAO,WACjB,OAAOR,EAAEO,IAAI,EAAEE,KAAKH,CAAI,IAAM,IAChC,CAAC,CACH,CACF,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 6e73e76..a615b09 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "main": "jquery.once.js", "contributors": [ "JohnAlbin (https://github.com/JohnAlbin)", - "Rob Loach (https://github.com/RobLoach)", - "theodoreb (https://github.com/theodoreb)" + "Rob Loach (https://github.com/RobLoach)", + "theodoreb (https://github.com/theodoreb)", + "Olavo Rocha Neto (https://github.com/olavorn)" ], "repository": { "type": "git", @@ -64,5 +65,10 @@ "jquery.once.min.js", "jquery.once.min.js.map" ] + }, + "xo": { + "rules": { + "unicorn/prefer-module": 0 + } } } diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 7c3b1ca..0000000 --- a/test/index.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Mocha test runner. - */ -const path = require('path'); -const Mocha = require('mocha'); -const process = require('process'); - -// Create our mocha instance. -const mocha = new Mocha(); - -// Add all the test files. -mocha.addFile(path.join(__dirname, 'test.js')); - -// Run the tests. -mocha.run(function (failures) { - process.on('exit', function () { - if (failures) { - throw new Error(failures); - } - }); -}); diff --git a/test/test.js b/test/test.js index 049b26d..8bcd142 100644 --- a/test/test.js +++ b/test/test.js @@ -15,13 +15,13 @@ describe('jQuery Once', () => { * Turn the Mocha test environment into a DOM environment with JSDom. */ jsdom({ - url: 'http://localhost' + url: 'http://localhost', }); /** * Before the tests initiate, load jQuery and jQuery Once. */ - before(function () { + before(() => { $ = require('jquery'); $.once = require('../jquery.once.js'); }); @@ -29,22 +29,22 @@ describe('jQuery Once', () => { /** * Before each test, reset the document body so that there is fresh data. */ - beforeEach(function () { + beforeEach(() => { // Build the body HTML. /* globals document */ document.body.innerHTML = '

This is the Test.

'; }); - it('should require ID to be a string', function () { + it('should require ID to be a string', () => { // Expect it to throw an error. - assert.throws(function () { - $('span').once(function () { + assert.throws(() => { + $('span').once(() => { // Nothing. }); }); }); - it('properly executes .once("test2")', function () { + it('properly executes .once("test2")', () => { // Create one once('test2') call. $('span').once('test2').data('test2', 'foo'); @@ -56,12 +56,12 @@ describe('jQuery Once', () => { assert.strictEqual(data, 'foo'); }); - it('is called only once with an ID', function () { + it('is called only once with an ID', () => { // Count the number of times once() was called. $('span').data('count', 0); // Create the once() callback. - const callback = function () { + const callback = () => { // Increment the count variable stored in the data. $('span').data('count', $('span').data('count') + 1); }; @@ -76,12 +76,12 @@ describe('jQuery Once', () => { assert.strictEqual(count, 1, 'It was called ' + count + ' times.'); }); - it('is called only once without an ID', function () { + it('is called only once without an ID', () => { // Count the number of times once() was called. $('span').data('once', 0); // Create the once() callback. - const callback = function () { + const callback = () => { $('span').data('once', $('span').data('once') + 1); }; @@ -95,7 +95,7 @@ describe('jQuery Once', () => { assert.strictEqual(count, 1, 'It was called ' + count + ' times.'); }); - it('retrieves empty once data correctly', function () { + it('retrieves empty once data correctly', () => { // Verify that the element starts without the class. let hasData = $('span').data('jquery-once-test3'); assert(!hasData, 'Value not applied in the beginning.'); @@ -108,7 +108,7 @@ describe('jQuery Once', () => { assert(hasData, 'The value is properly applied after once().'); }); - it('calls removeOnce() correctly', function () { + it('calls removeOnce() correctly', () => { // Create one once() call. $('span').once('test4'); @@ -122,7 +122,7 @@ describe('jQuery Once', () => { assert(!hasData, 'The value is properly removed when called removeOnce().'); }); - it('calls findOnce() correctly', function () { + it('calls findOnce() correctly', () => { // Append an additional span to the end. document.body.innerHTML += '

This is the Test 2.

';