From 6fe88690a336a883ea310da76762e5a456dc487a 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: * 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 (cherry picked from commit 93ca49e6d1ac23fee33b3bc3b7f4d93dd1a25cb7) --- README.md | 2 +- src/css/curCSS.js | 4 ++ src/effects.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 +- 10 files changed, 100 insertions(+), 159 deletions(-) delete mode 100644 test/localfile.html diff --git a/README.md b/README.md index 5464d6e30..ef97bc8b2 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 cde40b6d4..ce8395162 100644 --- a/src/css/curCSS.js +++ b/src/css/curCSS.js @@ -29,6 +29,10 @@ function curCSS( elem, name, computed ) { // .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 d0feb01d4..240cf225d 100644 --- a/src/effects.js +++ b/src/effects.js @@ -459,7 +459,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 || isFunction( speed ) && speed, duration: speed, easing: fn && easing || easing && !isFunction( easing ) && easing diff --git a/test/data/testinit.js b/test/data/testinit.js index dbc30a0a1..0ec324c15 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -177,16 +177,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 { 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 - - - - - -

jQuery Local File Test

-

- Introduction -

- -

- Results -

- -

- Logs: -

- - - diff --git a/test/unit/core.js b/test/unit/core.js index e96f5f0ba..8b0cca9f7 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1389,7 +1389,7 @@ QUnit.test( "jQuery.parseHTML() - gh-2965", function( assert ) { } ); if ( jQuery.support.createHTMLDocument ) { - 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 845a03b77..7dadb2db3 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -1848,7 +1848,7 @@ QUnit.test( "Do not throw on frame elements from css method (trac-15098)", funct 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 ) && !/edge\//i.test( navigator.userAgent ), expected = 20; diff --git a/test/unit/dimensions.js b/test/unit/dimensions.js index dc7e719fb..2cb3a5e7e 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