]> source.dussan.org Git - jquery.git/commitdiff
Core: Simplify code post browser support reduction
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Tue, 19 Sep 2023 22:54:40 +0000 (00:54 +0200)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Tue, 19 Sep 2023 22:59:32 +0000 (00:59 +0200)
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
src/css/curCSS.js
src/effects.js
test/data/testinit.js
test/delegatetest.html
test/localfile.html [deleted file]
test/unit/core.js
test/unit/css.js
test/unit/dimensions.js
test/unit/wrap.js

index 5464d6e30b0b086cdcba3b7b8654c8dd83be1651..ef97bc8b2e0859fbe4945215d9fe66e1816d1405 100644 (file)
--- 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
 
index cde40b6d469dec49fa1c0a5c2b048feb52f281ac..ce83951624e3c6bf9329e2b654942cc479479a51 100644 (file)
@@ -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
index d0feb01d45854bdae476bb866bed3c1ff0f61dc0..240cf225dec573b424558a431b3c6dff54fcff5d 100644 (file)
@@ -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
index dbc30a0a18e8227b5287c2a4ba1f8108922b293e..0ec324c15b3bd8067fd0713341204fab10f518cc 100644 (file)
@@ -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
index d3225196ee82ee1b2e77c3c9eb3b3cb5e16ada0e..53efe54ce524bd112e6e9f48f0be8039112a51fe 100644 (file)
@@ -125,103 +125,95 @@ th, td {
 
 <script type='text/javascript'>
 
-$("#fileversion").text($.fn.jquery);
+$( "#fileversion" ).text( $.fn.jquery );
 
 // Try an auto-submit, it should only fire once
-$(function(){
+$( function() {
        var triggered = false;
-       $("#autosub input").trigger("keypress");
-       $("body").on("submit", "#autosub", function( e ){
+       $( "#autosub input" ).trigger( "keypress" );
+       $( "body" ).on( "submit", "#autosub", function( e ) {
                e.preventDefault();
                e.stopPropagation();
                if ( triggered ) {
-                       alert("autosubmit FAIL");
+                       alert( "autosubmit FAIL" );
                }
                triggered = true;
-       });
-       $("#autosub").submit().remove();
-});
+       } );
+       $( "#autosub" ).submit().remove();
+} );
 
 // Events we want to track in row-order
-var events = "bind-change live-change onX-change bind-propertychange live-beforeactivate live-focusin bind-focus live-beforedeactivate live-focusout bind-blur live-click live-keydown".split(" "),
+var events = "bind-change live-change onX-change bind-propertychange live-beforeactivate live-focusin bind-focus live-beforedeactivate live-focusout bind-blur live-click live-keydown".split( " " ),
        counter = 0;
-       blinker = function(event){
-               if ( !counter ) {
-                       $("#changes tbody td").text("");
-               }
-               var $el = event.data,
-                       prev = $el.text();
-               prev = prev? prev +" | " : "";
-               return $el
-                       .text(prev + ++counter+" " + (this.value.replace(/^on$/,"") || this.id || this.checked || ""))
-                       .css("backgroundColor","#0f0")
-                       .delay(800)
-                       .queue(function(next){
-                               $el.css("backgroundColor","#afa");
-                               --counter;
-                               next();
-                       });
-       };
+blinker = function( event ) {
+       if ( !counter ) {
+               $( "#changes tbody td" ).text( "" );
+       }
+       var $el = event.data,
+               prev = $el.text();
+       prev = prev ? prev + " | " : "";
+       return $el
+               .text( prev + ++counter + " " + ( this.value.replace( /^on$/, "" ) || this.id || this.checked || "" ) )
+               .css( "backgroundColor", "#0f0" )
+               .delay( 800 )
+               .queue( function( next ) {
+                       $el.css( "backgroundColor", "#afa" );
+                       --counter;
+                       next();
+               );
+};
 
-for ( var i=0; i < events.length; i++ ) {
-       var m = events[i].split("-"),
-               api = m[0],
-               type = m[1],
-               $row = $("<tr><th>"+type+" "+api+"</th></tr>");
+for ( var i = 0; i < events.length; i++ ) {
+       var m = events[ i ].split( "-" ),
+               api = m[ 0 ],
+               type = m[ 1 ],
+               $row = $( "<tr><th>" + type + " " + api + "</th></tr>" );
 
-       $("#changes thead td").each(function(){
-               var id = "#"+this.id,
-                       $cell = $("<td></td>");
+       $( "#changes thead td" ).each( function() {
+               var id = "#" + this.id,
+                       $cell = $( "<td></td>" );
                if ( api == "onX" ) {
-                       $(this).find("input, button, select, textarea").each(function(){
-                               this["on"+type] = function(e){ e = $.event.fix(e||event); e.data = $cell; blinker.call(this, e); };
-                       });
+                       $( this ).find( "input, button, select, textarea" ).each( function() {
+                               this[ "on" + type ] = function( e ) {
+ e = $.event.fix( e || event ); e.data = $cell; blinker.call( this, e );
+};
+                       } );
                } else if ( api == "bind" ) {
-                       $(this).find("input, button, select, textarea").bind(type, $cell, blinker);
+                       $( this ).find( "input, button, select, textarea" ).bind( type, $cell, blinker );
                } else {
-                       $(id+" input,"+id+" button,"+id+" select,"+id+" textarea").live(type, $cell, blinker);
+                       $( id + " input," + id + " button," + id + " select," + id + " textarea" ).live( type, $cell, blinker );
                }
-               $row.append($cell);
-       });
-       $("#changes tbody").append($row);
-}
-
-// Ensure that cloned elements get the delegated event magic; this is
-// implementation-specific knowledge but otherwise impossible to test.
-// The beforeactivate event attaches a direct-bound change event.
-// (Only care about the live change for this third select element.)
-var sel1 = $("#select-one select:first-child");
-if ( typeof(sel1[0].fireEvent) !== "undefined" ) {
-       sel1.trigger( "beforeactivate" ).clone().appendTo("#select-one");
-       //alert($("#select-one select").map(function(){ return this._change_attached || "undef"; }).get().join("|"));
+               $row.append( $cell );
+       } );
+       $( "#changes tbody" ).append( $row );
 }
 
-jQuery.fn.blink = function(){
+jQuery.fn.blink = function() {
        return this
-               .css("backgroundColor","green")
-               .text( (parseInt(this.text(), 10) || 0) + 1 )
-               .delay(700).queue(function(next){
-                       jQuery(this).css("backgroundColor","#afa");
+               .css( "backgroundColor", "green" )
+               .text( ( parseInt( this.text(), 10 ) || 0 ) + 1 )
+               .delay( 700 ).queue( function( next ) {
+                       jQuery( this ).css( "backgroundColor", "#afa" );
                        next();
-               });
+               } );
 };
 
 jQuery.fn.addSubmitTest = function( id, prevent ) {
-       return this.live("submit", function(e){
+       return this.live( "submit", function( e ) {
                if ( prevent ) {
-                               e.preventDefault();
+                       e.preventDefault();
                }
-               jQuery(id).blink();
-       });
+               jQuery( id ).blink();
+       } );
 };
 
-$("#text_submit").addSubmitTest("#textSubmit", true);
-$("#password_submit").addSubmitTest("#passwordSubmit", true);
-$("#submit_submit").addSubmitTest("#submitSubmit", true);
-$("#prog_submit").addSubmitTest("#submitSubmit", true);
-$(document).bind("submit", function(){
-       jQuery("#boundSubmit").blink();
-});
+$( "#text_submit" ).addSubmitTest( "#textSubmit", true );
+$( "#password_submit" ).addSubmitTest( "#passwordSubmit", true );
+$( "#submit_submit" ).addSubmitTest( "#submitSubmit", true );
+$( "#prog_submit" ).addSubmitTest( "#submitSubmit", true );
+$( document ).bind( "submit", function() {
+       jQuery( "#boundSubmit" ).blink();
+} );
 
 </script>
 </body>
diff --git a/test/localfile.html b/test/localfile.html
deleted file mode 100644 (file)
index 5a79bfe..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
-<head>
-       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-       <title>jQuery Local File Test</title>
-       <!-- Includes -->
-       <script src="jquery.js"></script>
-       <style>
-               .error { color: red; }
-               .success { color: green; }
-       </style>
-</head>
-<body>
-       <h1>jQuery Local File Test</h1>
-       <h2>
-               Introduction
-       </h2>
-       <ul>
-               <li>
-                       Access this file using the "file:" protocol,
-               </li>
-               <li>
-                       two green "OK" strings must appear below,
-               </li>
-               <li>
-                       Empty local files will issue errors, it's a known limitation.
-               </li>
-       </ul>
-       <h2>
-               Results
-       </h2>
-       <ul>
-               <li>
-                       Success:
-                       <span id="success">
-                       </span>
-               </li>
-               <li>
-                       Error:
-                       <span id="error">
-                       </span>
-               </li>
-       </ul>
-       <h2>
-               Logs:
-       </h2>
-       <ul id="log">
-       </ul>
-       <script>
-               var logUL = jQuery( "#log" );
-               function doLog( message, args ) {
-                       jQuery( "<li></li>" ).appendTo( logUL ).text( message + ': "' + Array.prototype.join.call( args, '" - "' ) + '"' );
-               }
-               jQuery.ajax( "./data/badjson.js" , {
-                       context: jQuery( "#success" ),
-                       dataType: "text"
-               }).success(function( data, _, xhr ) {
-                       doLog( "Success (" + xhr.status + ")" , arguments );
-                       this.addClass( data ? "success" : "error" ).text( "OK" );
-               }).error(function( xhr ) {
-                       doLog( "Success (" + xhr.status + ")" , arguments );
-                       this.addClass( "error" ).text( "FAIL" );
-               });
-               jQuery.ajax( "./data/doesnotexist.ext" , {
-                       context: jQuery( "#error" ),
-                       dataType: "text"
-               }).error(function( xhr ) {
-                       doLog( "Error (" + xhr.status + ")" , arguments );
-                       this.addClass( "success" ).text( "OK" );
-               }).success(function( data, _, xhr ) {
-                       doLog( "Error (" + xhr.status + ")" , arguments );
-                       this.addClass( "error" ).text( "FAIL" );
-               });
-       </script>
-</body>
index e96f5f0baf5bf1158fad36589ce5bc627268ce01..8b0cca9f790ea2d641479e85e5545ab6e48b42b7 100644 (file)
@@ -1389,7 +1389,7 @@ QUnit.test( "jQuery.parseHTML(<a href>) - 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 );
 
index 845a03b77fd0bd94a1b1e80ee4bd0bf181d5ad19..7dadb2db313ab8a789921e6262af3a77446e6677 100644 (file)
@@ -1848,7 +1848,7 @@ QUnit.test( "Do not throw on frame elements from css method (trac-15098)", funct
                var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
                        $elem = jQuery( "<div>" ).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;
 
index dc7e719fbf7dd7031230809cd4b37d9d62a03575..2cb3a5e7ef203d31f652210429a66cc5ea622960 100644 (file)
@@ -284,6 +284,30 @@ QUnit.test( "outerHeight()", function( assert ) {
        div.remove();
 } );
 
+QUnit.test( "fractional getters", function( assert ) {
+       assert.expect( 8 );
+
+       var elem = jQuery( "<div>" ).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 );
 
index 24136ac0ecb20459cdf035ec1419ff6f3965da08..31f9cd3006ace68d3256dd39d539b4d7c392a2e8 100644 (file)
@@ -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( "<div class='red'><span></span></div>" ) ).text();