Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Simplify code post browser support reduction #5296

Merged
merged 11 commits into from
Sep 19, 2023
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/css/curCSS.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ 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
Expand Down
2 changes: 1 addition & 1 deletion src/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/manipulation/domManip.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function domManip( collection, args, callback, ignored ) {

// Keep references to cloned scripts for later restoration
if ( hasScripts ) {

// TODO: check if this can be replaced with
// `push.apply( scripts, getAll( node, "script" ) )`
// but remember about gh-4320. When looking into it,
// perhaps simplify jQuery.merge itself.
jQuery.merge( scripts, getAll( node, "script" ) );
}
}
Expand Down
16 changes: 6 additions & 10 deletions test/data/testinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,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
Expand Down
130 changes: 61 additions & 69 deletions test/delegatetest.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,103 +125,95 @@ <h2>Submit Tests</h2>

<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>
Expand Down
75 changes: 0 additions & 75 deletions test/localfile.html

This file was deleted.

2 changes: 1 addition & 1 deletion test/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ QUnit.test( "jQuery.parseHTML(<a href>) - 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 );

Expand Down
2 changes: 1 addition & 1 deletion test/unit/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ QUnit.testUnlessIE( "css(--customProperty)", function( assert ) {
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 ),
expected = 20;

if ( webkitOrBlink ) {
Expand Down
24 changes: 24 additions & 0 deletions test/unit/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion test/unit/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down