Skip to content

Commit

Permalink
2.3.0
Browse files Browse the repository at this point in the history
- Switched from `var` to `let` and `const` for variable scope
- Removed `use strict` directives
  • Loading branch information
RobLoach authored Jan 4, 2024
1 parent abad155 commit c9a250a
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 52 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-3.4.1.js"></script>
<script src="http://code.jquery.com/jquery-3.7.1.js"></script>
<script src="../jquery.once.js"></script>
</head>
<body>
Expand Down
8 changes: 4 additions & 4 deletions jquery.once.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,7 +8,7 @@

///<reference types="jquery" />

interface JQuery{
interface JQuery {

/**
* Filter elements that have yet to be processed by the given data ID.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -113,7 +113,7 @@ interface JQuery{
* @global
* @public
*/
findOnce(id:string): JQuery;
findOnce(id: string): JQuery;
}


6 changes: 3 additions & 3 deletions jquery.once.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions jquery.once.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jquery.once.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"main": "jquery.once.js",
"contributors": [
"JohnAlbin (https://github.com/JohnAlbin)",
"Rob Loach <[email protected]> (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",
Expand Down Expand Up @@ -64,5 +65,10 @@
"jquery.once.min.js",
"jquery.once.min.js.map"
]
},
"xo": {
"rules": {
"unicorn/prefer-module": 0
}
}
}
21 changes: 0 additions & 21 deletions test/index.js

This file was deleted.

28 changes: 14 additions & 14 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@ 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');
});

/**
* 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 = '<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', () => {
// 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');

Expand All @@ -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);
};
Expand All @@ -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);
};

Expand All @@ -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.');
Expand All @@ -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');

Expand All @@ -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 += '<p>This is the <span>Test 2</span>.</p>';

Expand Down

0 comments on commit c9a250a

Please sign in to comment.