From 93ca49e6d1ac23fee33b3bc3b7f4d93dd1a25cb7 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?=
Date: Wed, 20 Sep 2023 00:54:40 +0200
Subject: [PATCH] Core: Simplify code post browser support reduction
Summary of the changes:
* Core: Simplify code post browser support reduction
* Tests: Remove legacy jQuery.cache & oldIE leftovers
* Tests: Reformat JavaScript in delegatetest.html
* Docs: "jQuery Foundation Projects" -> "jQuery Projects"
* Tests: Drop an unused localfile.html file (modern browsers don't support
the `file:` protocol this way, there's no point in keeping the file around)
* Effects: Remove a redundant `!fn` check (`fn || !fn && easing` is equivalent
to `fn || easing`; simplify the code)
* CSS: Explain the fallback to direct object access in curCSS better
* Tests: Deduplicate `jQuery.parseHTML` test titles
* Dimensions: Add a test for fractional values
* Tests: Fix a buggy WebKit regex
Closes gh-5296
---
README.md | 2 +-
src/css/curCSS.js | 4 ++
src/effects.js | 2 +-
src/manipulation.js | 2 +-
test/data/testinit.js | 16 ++---
test/delegatetest.html | 130 +++++++++++++++++++---------------------
test/localfile.html | 75 -----------------------
test/unit/core.js | 2 +-
test/unit/css.js | 2 +-
test/unit/dimensions.js | 24 ++++++++
test/unit/wrap.js | 2 +-
11 files changed, 101 insertions(+), 160 deletions(-)
delete mode 100644 test/localfile.html
diff --git a/README.md b/README.md
index a18b15f72..7a3e0fa62 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ In the spirit of open source software development, jQuery always encourages comm
1. [Getting Involved](https://contribute.jquery.org/)
2. [Core Style Guide](https://contribute.jquery.org/style-guide/js/)
-3. [Writing Code for jQuery Foundation Projects](https://contribute.jquery.org/code/)
+3. [Writing Code for jQuery Projects](https://contribute.jquery.org/code/)
### References to issues/PRs
diff --git a/src/css/curCSS.js b/src/css/curCSS.js
index 06394f315..16104d893 100644
--- a/src/css/curCSS.js
+++ b/src/css/curCSS.js
@@ -13,6 +13,10 @@ export function curCSS( elem, name, computed ) {
// getPropertyValue is needed for `.css('--customProperty')` (gh-3144)
if ( computed ) {
+ // A fallback to direct property access is needed as `computed`, being
+ // the output of `getComputedStyle`, contains camelCased keys and
+ // `getPropertyValue` requires kebab-case ones.
+ //
// Support: IE <=9 - 11+
// IE only supports `"float"` in `getPropertyValue`; in computed styles
// it's only available as `"cssFloat"`. We no longer modify properties
diff --git a/src/effects.js b/src/effects.js
index 99dbad7bc..3c1bd33fd 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -446,7 +446,7 @@ jQuery.Animation = jQuery.extend( Animation, {
jQuery.speed = function( speed, easing, fn ) {
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
- complete: fn || !fn && easing ||
+ complete: fn || easing ||
typeof speed === "function" && speed,
duration: speed,
easing: fn && easing || easing && typeof easing !== "function" && easing
diff --git a/src/manipulation.js b/src/manipulation.js
index 0a7209412..f8834e57b 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -334,7 +334,7 @@ jQuery.each( {
for ( ; i <= last; i++ ) {
elems = i === last ? this : this.clone( true );
jQuery( insert[ i ] )[ original ]( elems );
- push.apply( ret, elems.get() );
+ push.apply( ret, elems );
}
return this.pushStack( ret );
diff --git a/test/data/testinit.js b/test/data/testinit.js
index baf758205..aafe2902c 100644
--- a/test/data/testinit.js
+++ b/test/data/testinit.js
@@ -144,16 +144,12 @@ this.createXMLFragment = function() {
return frag;
};
-window.fireNative = document.createEvent ?
- function( node, type ) {
- var event = document.createEvent( "HTMLEvents" );
-
- event.initEvent( type, true, true );
- node.dispatchEvent( event );
- } :
- function( node, type ) {
- node.fireEvent( "on" + type, document.createEventObject() );
- };
+window.fireNative = function( node, type ) {
+ var event = document.createEvent( "HTMLEvents" );
+
+ event.initEvent( type, true, true );
+ node.dispatchEvent( event );
+};
/**
* Add random number to url to stop caching
diff --git a/test/delegatetest.html b/test/delegatetest.html
index d3225196e..53efe54ce 100644
--- a/test/delegatetest.html
+++ b/test/delegatetest.html
@@ -125,103 +125,95 @@ th, td {
- jQuery Local File Test
-
- Introduction
-
-
- -
- Access this file using the "file:" protocol,
-
- -
- two green "OK" strings must appear below,
-
- -
- Empty local files will issue errors, it's a known limitation.
-
-
-
- Results
-
-
- -
- Success:
-
-
-
- -
- Error:
-
-
-
-
-
- Logs:
-
-
-
-
diff --git a/test/localfile.html b/test/localfile.html
deleted file mode 100644
index 5a79bfec1..000000000
--- a/test/localfile.html
+++ /dev/null
@@ -1,75 +0,0 @@
-
-
-
-
-
jQuery Local File Test
-
-
-
-
-
diff --git a/test/unit/core.js b/test/unit/core.js
index 294664d5c..666f0e820 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1403,7 +1403,7 @@ QUnit.test( "jQuery.parseHTML() - gh-2965", function( assert ) {
assert.ok( /\/example\.html$/.test( href ), "href is not lost after parsing anchor" );
} );
-QUnit.test( "jQuery.parseHTML", function( assert ) {
+QUnit.test( "jQuery.parseHTML error handling", function( assert ) {
var done = assert.async();
assert.expect( 1 );
diff --git a/test/unit/css.js b/test/unit/css.js
index 31d043544..146dcd9da 100644
--- a/test/unit/css.js
+++ b/test/unit/css.js
@@ -1757,7 +1757,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
var div = jQuery( "" ).appendTo( "#qunit-fixture" ),
$elem = jQuery( "
" ).addClass( "test__customProperties" )
.appendTo( "#qunit-fixture" ),
- webkitOrBlink = /\webkit\b/i.test( navigator.userAgent ),
+ webkitOrBlink = /webkit\b/i.test( navigator.userAgent ),
expected = 20;
if ( webkitOrBlink ) {
diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js
index 85a69cdb7..6b0c9c798 100644
--- a/test/unit/dimensions.js
+++ b/test/unit/dimensions.js
@@ -284,6 +284,30 @@ QUnit.test( "outerHeight()", function( assert ) {
div.remove();
} );
+QUnit.test( "fractional getters", function( assert ) {
+ assert.expect( 8 );
+
+ var elem = jQuery( "
" ).css( {
+ width: "10.5px",
+ height: "20.5px",
+ border: "10px solid white",
+ padding: "2px",
+ margin: "3px"
+ } );
+
+ elem.appendTo( "#qunit-fixture" );
+
+ assert.strictEqual( elem.width(), 10.5, "width supports fractions" );
+ assert.strictEqual( elem.innerWidth(), 14.5, "innerWidth supports fractions" );
+ assert.strictEqual( elem.outerWidth(), 34.5, "outerWidth supports fractions" );
+ assert.strictEqual( elem.outerWidth( true ), 40.5, "outerWidth( true ) supports fractions" );
+
+ assert.strictEqual( elem.height(), 20.5, "height supports fractions" );
+ assert.strictEqual( elem.innerHeight(), 24.5, "innerHeight supports fractions" );
+ assert.strictEqual( elem.outerHeight(), 44.5, "outerHeight supports fractions" );
+ assert.strictEqual( elem.outerHeight( true ), 50.5, "outerHeight( true ) supports fractions" );
+} );
+
QUnit.test( "child of a hidden elem (or unconnected node) has accurate inner/outer/Width()/Height() see trac-9441 trac-9300", function( assert ) {
assert.expect( 16 );
diff --git a/test/unit/wrap.js b/test/unit/wrap.js
index 24136ac0e..31f9cd300 100644
--- a/test/unit/wrap.js
+++ b/test/unit/wrap.js
@@ -23,7 +23,7 @@ function testWrap( val, assert ) {
assert.expect( 18 );
- var defaultText, result, j, i, cacheLength;
+ var defaultText, result, j;
defaultText = "Try them out:";
result = jQuery( "#first" ).wrap( val( "
" ) ).text();
--
2.39.5