Skip to content

Commit bbbdd94

Browse files
committed
Fix #10814. Make support tests lazy and broken out to components.
1 parent 776012b commit bbbdd94

35 files changed

+383
-433
lines changed

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = function( grunt ) {
4242
ajax: [ "manipulation/_evalUrl" ],
4343
callbacks: [ "deferred" ],
4444
css: [ "effects", "dimensions", "offset" ],
45-
sizzle: [ "css/hidden-visible-selectors", "effects/animated-selector" ]
45+
sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
4646
}
4747
}
4848
},

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,12 @@ Some example modules that can be excluded are:
8888
- **exports/amd**: Exclude the AMD definition.
8989
- **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
9090
- **deferred**: Exclude jQuery.Deferred. This also removes jQuery.Callbacks. *Note* that modules that depend on jQuery.Deferred(AJAX, effects, core/ready) will not be removed and will still expect jQuery.Deferred to be there. Include your own jQuery.Deferred implementation or exclude those modules as well (`grunt custom:-deferred,-ajax,-effects,-core/ready`).
91-
- **support**: Excluding the support module is not recommended, but possible. It's your responsibility to either remove modules that use jQuery.support (many of them) or replace the values wherever jQuery.support is used. This is mainly only useful when building a barebones version of jQuery.
9291

9392
As a special case, you may also replace Sizzle by using a special flag `grunt custom:-sizzle`.
9493

9594
- **sizzle**: The Sizzle selector engine. When this module is excluded, it is replaced by a rudimentary selector engine based on the browser's `querySelectorAll` method that does not support jQuery selector extensions or enhanced semantics. See the selector-native.js file for details.
9695

97-
*Note*: Excluding Sizzle will also exclude all jQuery selector extensions (such as `effects/animated-selector` and `css/hidden-visible-selectors`).
96+
*Note*: Excluding Sizzle will also exclude all jQuery selector extensions (such as `effects/animatedSelector` and `css/hiddenVisibleSelectors`).
9897

9998
The build process shows a message for each dependent module it excludes or includes.
10099

src/ajax/xhr.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
define([
22
"../core",
3-
"../ajax",
4-
"../support"
5-
], function( jQuery ) {
3+
"../var/support",
4+
"../ajax"
5+
], function( jQuery, support ) {
66

77
jQuery.ajaxSettings.xhr = function() {
88
try {
@@ -33,13 +33,13 @@ if ( window.ActiveXObject ) {
3333
});
3434
}
3535

36-
jQuery.support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
37-
jQuery.support.ajax = xhrSupported = !!xhrSupported;
36+
support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
37+
support.ajax = xhrSupported = !!xhrSupported;
3838

3939
jQuery.ajaxTransport(function( options ) {
4040
var callback;
4141
// Cross domain only allowed if supported through XMLHttpRequest
42-
if ( jQuery.support.cors || xhrSupported && !options.crossDomain ) {
42+
if ( support.cors || xhrSupported && !options.crossDomain ) {
4343
return {
4444
send: function( headers, complete ) {
4545
var i, id,

src/attributes/attr.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ define([
22
"../core",
33
"../var/rnotwhite",
44
"../var/strundefined",
5-
"../selector",
6-
"../support"
7-
], function( jQuery, rnotwhite, strundefined ) {
5+
"./support",
6+
"../selector"
7+
], function( jQuery, rnotwhite, strundefined, support ) {
88

99
var nodeHook, boolHook,
1010
attrHandle = jQuery.expr.attrHandle;
@@ -93,7 +93,8 @@ jQuery.extend({
9393
attrHooks: {
9494
type: {
9595
set: function( elem, value ) {
96-
if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
96+
if ( !support.radioValue && value === "radio" &&
97+
jQuery.nodeName( elem, "input" ) ) {
9798
// Setting the type on a radio button after the value resets the value in IE6-9
9899
// Reset value to default in case type is set after value during creation
99100
var val = elem.value;

src/attributes/prop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
"../core",
3-
"../support"
4-
], function( jQuery ) {
3+
"./support"
4+
], function( jQuery, support ) {
55

66
var rfocusable = /^(?:input|select|textarea|button)$/i;
77

@@ -65,7 +65,7 @@ jQuery.extend({
6565

6666
// Support: IE9+
6767
// Selectedness for an option in an optgroup can be inaccurate
68-
if ( !jQuery.support.optSelected ) {
68+
if ( !support.optSelected ) {
6969
jQuery.propHooks.selected = {
7070
get: function( elem ) {
7171
var parent = elem.parentNode;

src/attributes/support.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
define([
2+
"../var/support"
3+
], function( support ) {
4+
5+
(function () {
6+
var input = document.createElement( "input" ),
7+
select = document.createElement( "select" ),
8+
opt = select.appendChild( document.createElement( "option" ) );
9+
10+
input.type = "checkbox";
11+
12+
// Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3
13+
// Check the default checkbox/radio value ("" on old WebKit; "on" elsewhere)
14+
support.checkOn = input.value !== "";
15+
16+
// Must access the parent to make an option select properly
17+
// Support: IE9, IE10
18+
support.optSelected = opt.selected;
19+
20+
// Make sure that the options inside disabled selects aren't marked as disabled
21+
// (WebKit marks them as disabled)
22+
select.disabled = true;
23+
support.optDisabled = !opt.disabled;
24+
25+
// Check if an input maintains its value after becoming a radio
26+
// Support: IE9, IE10
27+
input = document.createElement( "input" );
28+
input.value = "t";
29+
input.type = "radio";
30+
support.radioValue = input.value === "t";
31+
})();
32+
33+
return support;
34+
35+
});

src/attributes/val.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
define([
22
"../core",
3-
"../support"
4-
], function( jQuery ) {
3+
"./support"
4+
], function( jQuery, support ) {
55

66
var rreturn = /\r/g;
77

@@ -95,7 +95,7 @@ jQuery.extend({
9595
// IE6-9 doesn't update selected after form reset (#2551)
9696
if ( ( option.selected || i === index ) &&
9797
// Don't return options that are disabled or in a disabled optgroup
98-
( jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null ) &&
98+
( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
9999
( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
100100

101101
// Get the specific value for the option
@@ -146,7 +146,7 @@ jQuery.each([ "radio", "checkbox" ], function() {
146146
}
147147
}
148148
};
149-
if ( !jQuery.support.checkOn ) {
149+
if ( support.checkOn ) {
150150
jQuery.valHooks[ this ].get = function( elem ) {
151151
// Support: Webkit
152152
// "" is returned instead of "on" if a value isn't specified

src/core.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ define([
99
"./var/class2type",
1010
"./var/toString",
1111
"./var/hasOwn",
12-
"./var/trim"
12+
"./var/trim",
13+
"./var/support"
1314
], function( strundefined, arr, slice, concat, push, indexOf,
14-
class2type, toString, hasOwn, trim ) {
15+
class2type, toString, hasOwn, trim, support ) {
1516

1617
var
1718
// A central reference to the root jQuery(document)
@@ -702,7 +703,11 @@ jQuery.extend({
702703
length ? fn( elems[0], key ) : emptyGet;
703704
},
704705

705-
now: Date.now
706+
now: Date.now,
707+
708+
// jQuery.support is not used in Core but other projects attach their
709+
// properties to it so it needs to exist.
710+
support: support
706711
});
707712

708713
// Populate the class2type map

src/css.js

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ define([
33
"./var/pnum",
44
"./css/var/cssExpand",
55
"./css/var/isHidden",
6+
"./css/support",
67
"./css/defaultDisplay",
78
"./data/var/data_priv",
8-
"./core/swap",
9+
"./css/swap",
910
"./core/ready",
1011
"./selector", // contains
11-
"./support",
1212
// Optional
1313
"./offset"
14-
], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, data_priv ) {
14+
], function( jQuery, pnum, cssExpand, isHidden, support, defaultDisplay, data_priv ) {
1515
var curCSS,
1616
// swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
1717
// see here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
@@ -233,7 +233,7 @@ jQuery.extend({
233233

234234
// Fixes #8908, it can be done more correctly by specifying setters in cssHooks,
235235
// but it would mean to define eight (for every problematic property) identical functions
236-
if ( !jQuery.support.clearCloneStyle && value === "" && name.indexOf("background") === 0 ) {
236+
if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
237237
style[ name ] = "inherit";
238238
}
239239

@@ -382,7 +382,7 @@ function getWidthOrHeight( elem, name, extra ) {
382382
var valueIsBorderBox = true,
383383
val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
384384
styles = getStyles( elem ),
385-
isBorderBox = jQuery.support.boxSizing && jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
385+
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
386386

387387
// some non-html elements return undefined for offsetWidth, so check for null/undefined
388388
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
@@ -401,7 +401,8 @@ function getWidthOrHeight( elem, name, extra ) {
401401

402402
// we need the check for style in case a browser which returns unreliable values
403403
// for getComputedStyle silently falls back to the reliable elem.style
404-
valueIsBorderBox = isBorderBox && ( jQuery.support.boxSizingReliable || val === elem.style[ name ] );
404+
valueIsBorderBox = isBorderBox &&
405+
( support.boxSizingReliable() || val === elem.style[ name ] );
405406

406407
// Normalize "", auto, and prepare for extra
407408
val = parseFloat( val ) || 0;
@@ -440,50 +441,57 @@ jQuery.each([ "height", "width" ], function( i, name ) {
440441
elem,
441442
name,
442443
extra,
443-
jQuery.support.boxSizing && jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
444+
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
444445
styles
445446
) : 0
446447
);
447448
}
448449
};
449450
});
450451

451-
// These hooks cannot be added until DOM ready because the support test
452-
// for it is not run until after DOM ready
453-
jQuery(function() {
454-
// Support: Android 2.3
455-
if ( !jQuery.support.reliableMarginRight ) {
456-
jQuery.cssHooks.marginRight = {
457-
get: function( elem, computed ) {
458-
if ( computed ) {
459-
// Support: Android 2.3
460-
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
461-
// Work around by temporarily setting element display to inline-block
462-
return jQuery.swap( elem, { "display": "inline-block" },
463-
curCSS, [ elem, "marginRight" ] );
464-
}
465-
}
466-
};
452+
// Support: Android 2.3
453+
jQuery.cssHooks.marginRight = {
454+
get: function( elem, computed ) {
455+
if ( support.reliableMarginRight() ) {
456+
// Hook not needed, remove it.
457+
// Since there are no other hooks for marginRight, remove the whole object.
458+
delete jQuery.cssHooks.marginRight;
459+
return;
460+
}
461+
if ( computed ) {
462+
// Support: Android 2.3
463+
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
464+
// Work around by temporarily setting element display to inline-block
465+
return jQuery.swap( elem, { "display": "inline-block" },
466+
curCSS, [ elem, "marginRight" ] );
467+
}
467468
}
469+
};
468470

469-
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
470-
// getComputedStyle returns percent when specified for top/left/bottom/right
471-
// rather than make the css module depend on the offset module, we just check for it here
472-
if ( !jQuery.support.pixelPosition && jQuery.fn.position ) {
473-
jQuery.each( [ "top", "left" ], function( i, prop ) {
474-
jQuery.cssHooks[ prop ] = {
475-
get: function( elem, computed ) {
476-
if ( computed ) {
477-
computed = curCSS( elem, prop );
478-
// if curCSS returns percentage, fallback to offset
479-
return rnumnonpx.test( computed ) ?
480-
jQuery( elem ).position()[ prop ] + "px" :
481-
computed;
482-
}
471+
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
472+
// getComputedStyle returns percent when specified for top/left/bottom/right
473+
// rather than make the css module depend on the offset module, we just check for it here
474+
jQuery.each( [ "top", "left" ], function( i, prop ) {
475+
jQuery.cssHooks[ prop ] = {
476+
get: function( elem, computed ) {
477+
if ( support.pixelPosition() || !jQuery.fn.position ) {
478+
// Hook not needed, remove it.
479+
// Since there are no other hooks for prop, remove the whole object.
480+
delete jQuery.cssHooks[ prop ];
481+
return;
482+
}
483+
jQuery.cssHooks[ prop ].get = function ( i, prop ) {
484+
if ( computed ) {
485+
computed = curCSS( elem, prop );
486+
// if curCSS returns percentage, fallback to offset
487+
return rnumnonpx.test( computed ) ?
488+
jQuery( elem ).position()[ prop ] + "px" :
489+
computed;
483490
}
484491
};
485-
});
486-
}
492+
return jQuery.cssHooks[ prop ].get( i, prop );
493+
}
494+
};
487495
});
488496

489497
// These hooks are used by animate to expand properties

0 commit comments

Comments
 (0)