mirror of
https://github.com/jquery/jquery.git
synced 2026-02-02 05:15:22 -05:00
Core: Support non-browser environments
Fixes gh-2133
Fixes gh-2501
Closes gh-2504
Refs gh-1950
Refs gh-1949
Refs gh-2397
Refs gh-1537
Refs gh-2504
Refs 842958e7ae
This commit is contained in:
@@ -16,11 +16,11 @@
|
||||
// The above browsers are failing a lot of tests in the ES5
|
||||
// test suite at http://test262.ecmascript.org.
|
||||
"es3": true,
|
||||
"browser": true,
|
||||
"wsh": true,
|
||||
|
||||
"globals": {
|
||||
"window": true,
|
||||
"JSON": false,
|
||||
|
||||
"jQuery": true,
|
||||
"define": false,
|
||||
"module": false,
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/document",
|
||||
"./var/rnotwhite",
|
||||
"./ajax/var/location",
|
||||
"./ajax/var/nonce",
|
||||
"./ajax/var/rquery",
|
||||
"./core/init",
|
||||
"./ajax/parseJSON",
|
||||
"./ajax/parseXML",
|
||||
"./deferred"
|
||||
], function( jQuery, rnotwhite, nonce, rquery ) {
|
||||
], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
|
||||
|
||||
var
|
||||
rhash = /#.*$/,
|
||||
@@ -643,7 +645,7 @@ jQuery.extend({
|
||||
|
||||
// Timeout
|
||||
if ( s.async && s.timeout > 0 ) {
|
||||
timeoutTimer = setTimeout(function() {
|
||||
timeoutTimer = window.setTimeout(function() {
|
||||
jqXHR.abort("timeout");
|
||||
}, s.timeout );
|
||||
}
|
||||
@@ -677,7 +679,7 @@ jQuery.extend({
|
||||
|
||||
// Clear timeout if it exists
|
||||
if ( timeoutTimer ) {
|
||||
clearTimeout( timeoutTimer );
|
||||
window.clearTimeout( timeoutTimer );
|
||||
}
|
||||
|
||||
// Dereference transport for early garbage collection
|
||||
|
||||
@@ -10,10 +10,10 @@ jQuery.parseXML = function( data ) {
|
||||
}
|
||||
try {
|
||||
if ( window.DOMParser ) { // Standard
|
||||
tmp = new DOMParser();
|
||||
tmp = new window.DOMParser();
|
||||
xml = tmp.parseFromString( data, "text/xml" );
|
||||
} else { // IE
|
||||
xml = new ActiveXObject( "Microsoft.XMLDOM" );
|
||||
xml = new window.ActiveXObject( "Microsoft.XMLDOM" );
|
||||
xml.async = "false";
|
||||
xml.loadXML( data );
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"../ajax"
|
||||
], function( jQuery ) {
|
||||
], function( jQuery, document ) {
|
||||
|
||||
// Install script dataType
|
||||
jQuery.ajaxSetup({
|
||||
|
||||
3
src/ajax/var/location.js
Normal file
3
src/ajax/var/location.js
Normal file
@@ -0,0 +1,3 @@
|
||||
define(function() {
|
||||
return window.location;
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"../var/support",
|
||||
"../ajax"
|
||||
], function( jQuery, support ) {
|
||||
], function( jQuery, document, support ) {
|
||||
|
||||
// Create the request object
|
||||
// (This is still attached to ajaxSettings for backward compatibility)
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
define([
|
||||
"../var/document",
|
||||
"../var/support"
|
||||
], function( support ) {
|
||||
], function( document, support ) {
|
||||
|
||||
(function() {
|
||||
// Minified: var a,b,c,d,e
|
||||
var input, div, select, a, opt;
|
||||
var a,
|
||||
input = document.createElement( "input" ),
|
||||
div = document.createElement( "div" ),
|
||||
select = document.createElement( "select" ),
|
||||
opt = select.appendChild( document.createElement( "option" ) );
|
||||
|
||||
// Setup
|
||||
div = document.createElement( "div" );
|
||||
div.innerHTML = " <link/><a href='/a'>a</a><input type='checkbox'/>";
|
||||
a = div.getElementsByTagName("a")[ 0 ];
|
||||
div.innerHTML = " <link/><a href='/a'>a</a>";
|
||||
// Support: Windows Web Apps (WWA)
|
||||
// `type` must use .setAttribute for WWA (#14901)
|
||||
input.setAttribute( "type", "checkbox" );
|
||||
div.appendChild( input );
|
||||
|
||||
a = div.getElementsByTagName( "a" )[ 0 ];
|
||||
|
||||
// First batch of tests.
|
||||
select = document.createElement("select");
|
||||
opt = select.appendChild( document.createElement("option") );
|
||||
input = div.getElementsByTagName("input")[ 0 ];
|
||||
|
||||
a.style.cssText = "top:1px";
|
||||
|
||||
// Get the style information from getAttribute
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
define([
|
||||
"./var/deletedIds",
|
||||
"./var/document",
|
||||
"./var/slice",
|
||||
"./var/concat",
|
||||
"./var/push",
|
||||
@@ -8,7 +9,8 @@ define([
|
||||
"./var/toString",
|
||||
"./var/hasOwn",
|
||||
"./var/support"
|
||||
], function( deletedIds, slice, concat, push, indexOf, class2type, toString, hasOwn, support ) {
|
||||
], function( deletedIds, document, slice, concat, push, indexOf,
|
||||
class2type, toString, hasOwn, support ) {
|
||||
|
||||
var
|
||||
version = "@VERSION+compat",
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
// Initialize a jQuery object
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"./var/rsingleTag",
|
||||
"../traversing/findFilter"
|
||||
], function( jQuery, rsingleTag ) {
|
||||
], function( jQuery, document, rsingleTag ) {
|
||||
|
||||
// A central reference to the root jQuery(document)
|
||||
var rootjQuery,
|
||||
|
||||
// Use the correct document accordingly with window argument (sandbox)
|
||||
document = window.document,
|
||||
|
||||
// A simple way to check for HTML strings
|
||||
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
|
||||
// Strict HTML recognition (#11290: must start with <)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"./var/rsingleTag",
|
||||
"../manipulation/buildFragment",
|
||||
|
||||
// This is the only module that needs core/support
|
||||
"./support"
|
||||
], function( jQuery, rsingleTag, buildFragment, support ) {
|
||||
], function( jQuery, document, rsingleTag, buildFragment, support ) {
|
||||
|
||||
// data: string of html
|
||||
// context (optional): If specified, the fragment will be created in this context,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"../deferred"
|
||||
], function( jQuery ) {
|
||||
], function( jQuery, document ) {
|
||||
|
||||
// The deferred used on DOM ready
|
||||
var readyList;
|
||||
@@ -72,7 +73,7 @@ function detach() {
|
||||
function completed() {
|
||||
// readyState === "complete" is good enough for us to call the dom ready in oldIE
|
||||
if ( document.addEventListener ||
|
||||
event.type === "load" ||
|
||||
window.event.type === "load" ||
|
||||
document.readyState === "complete" ) {
|
||||
|
||||
detach();
|
||||
@@ -93,7 +94,7 @@ jQuery.ready.promise = function( obj ) {
|
||||
// http://bugs.jquery.com/ticket/12282#comment:15
|
||||
if ( document.readyState === "complete" ) {
|
||||
// Handle it asynchronously to allow scripts the opportunity to delay ready
|
||||
setTimeout( jQuery.ready );
|
||||
window.setTimeout( jQuery.ready );
|
||||
|
||||
// Standards-based browsers support DOMContentLoaded
|
||||
} else if ( document.addEventListener ) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
define([
|
||||
"../var/document",
|
||||
"../var/support"
|
||||
], function( support ) {
|
||||
], function( document, support ) {
|
||||
|
||||
// Support: Safari 8+
|
||||
// In Safari 8 documents created via document.implementation.createHTMLDocument
|
||||
|
||||
@@ -3,12 +3,13 @@ define([
|
||||
"./var/pnum",
|
||||
"./core/access",
|
||||
"./css/var/rmargin",
|
||||
"./var/document",
|
||||
"./var/rcssNum",
|
||||
"./css/var/rnumnonpx",
|
||||
"./css/var/cssExpand",
|
||||
"./css/var/isHidden",
|
||||
"./css/curCSS",
|
||||
"./css/var/swap",
|
||||
"./css/curCSS",
|
||||
"./css/adjustCSS",
|
||||
"./css/addGetHookIf",
|
||||
"./css/support",
|
||||
@@ -17,8 +18,8 @@ define([
|
||||
"./core/init",
|
||||
"./core/ready",
|
||||
"./selector" // contains
|
||||
], function( jQuery, pnum, access, rmargin, rcssNum, rnumnonpx, cssExpand, isHidden,
|
||||
curCSS, swap, adjustCSS, addGetHookIf, support, showHide ) {
|
||||
], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
|
||||
isHidden, swap, curCSS, adjustCSS, addGetHookIf, support, showHide ) {
|
||||
|
||||
var
|
||||
// BuildExclude
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
define([
|
||||
"exports",
|
||||
"../core",
|
||||
"../var/documentElement",
|
||||
"./var/rnumnonpx",
|
||||
"./var/rmargin",
|
||||
"./support",
|
||||
"../selector" // contains
|
||||
], function( exports, jQuery, rnumnonpx, rmargin, support ) {
|
||||
], function( exports, jQuery, documentElement, rnumnonpx, rmargin, support ) {
|
||||
|
||||
var getStyles, curCSS,
|
||||
rposition = /^(top|right|bottom|left)$/;
|
||||
@@ -68,7 +69,7 @@ if ( window.getComputedStyle ) {
|
||||
ret :
|
||||
ret + "";
|
||||
};
|
||||
} else if ( document.documentElement.currentStyle ) {
|
||||
} else if ( documentElement.currentStyle ) {
|
||||
getStyles = function( elem ) {
|
||||
return elem.currentStyle;
|
||||
};
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"../var/documentElement",
|
||||
"../var/support"
|
||||
], function( jQuery, support ) {
|
||||
], function( jQuery, document, documentElement, support ) {
|
||||
|
||||
(function() {
|
||||
var div, container, style, a, pixelPositionVal, boxSizingReliableVal, gBCRDimensionsVal,
|
||||
pixelMarginRightVal, reliableHiddenOffsetsVal, reliableMarginRightVal;
|
||||
|
||||
// Setup
|
||||
div = document.createElement( "div" );
|
||||
div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
|
||||
a = div.getElementsByTagName( "a" )[ 0 ];
|
||||
style = a && a.style;
|
||||
var pixelPositionVal, boxSizingReliableVal, gBCRDimensionsVal,
|
||||
pixelMarginRightVal, reliableHiddenOffsetsVal, reliableMarginRightVal,
|
||||
container = document.createElement( "div" ),
|
||||
div = document.createElement( "div" );
|
||||
|
||||
// Finish early in limited (non-browser) environments
|
||||
if ( !style ) {
|
||||
if ( !div.style ) {
|
||||
return;
|
||||
}
|
||||
|
||||
style.cssText = "float:left;opacity:.5";
|
||||
div.style.cssText = "float:left;opacity:.5";
|
||||
|
||||
// Support: IE<9
|
||||
// Make sure that element opacity exists (as opposed to filter)
|
||||
support.opacity = style.opacity === "0.5";
|
||||
support.opacity = div.style.opacity === "0.5";
|
||||
|
||||
// Verify style float existence
|
||||
// (IE uses styleFloat instead of cssFloat)
|
||||
support.cssFloat = !!style.cssFloat;
|
||||
support.cssFloat = !!div.style.cssFloat;
|
||||
|
||||
div.style.backgroundClip = "content-box";
|
||||
div.cloneNode( true ).style.backgroundClip = "";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
define([
|
||||
"../var/document",
|
||||
"../var/support"
|
||||
], function( support ) {
|
||||
], function( document, support ) {
|
||||
|
||||
(function() {
|
||||
var div = document.createElement( "div" );
|
||||
|
||||
@@ -176,7 +176,7 @@ jQuery.extend({
|
||||
if ( depth ) {
|
||||
process();
|
||||
} else {
|
||||
setTimeout( process );
|
||||
window.setTimeout( process );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
10
src/effects.js
vendored
10
src/effects.js
vendored
@@ -1,5 +1,6 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/document",
|
||||
"./var/rcssNum",
|
||||
"./var/rnotwhite",
|
||||
"./css/var/cssExpand",
|
||||
@@ -15,7 +16,8 @@ define([
|
||||
"./manipulation",
|
||||
"./css",
|
||||
"./effects/Tween"
|
||||
], function( jQuery, rcssNum, rnotwhite, cssExpand, isHidden, swap, adjustCSS, showHide ) {
|
||||
], function( jQuery, document, rcssNum, rnotwhite, cssExpand, isHidden, swap,
|
||||
adjustCSS, showHide ) {
|
||||
|
||||
var
|
||||
fxNow, timerId,
|
||||
@@ -31,7 +33,7 @@ function raf() {
|
||||
|
||||
// Animations created synchronously will run synchronously
|
||||
function createFxNow() {
|
||||
setTimeout(function() {
|
||||
window.setTimeout(function() {
|
||||
fxNow = undefined;
|
||||
});
|
||||
return ( fxNow = jQuery.now() );
|
||||
@@ -640,14 +642,14 @@ jQuery.fx.interval = 13;
|
||||
jQuery.fx.start = function() {
|
||||
timerId = window.requestAnimationFrame ?
|
||||
window.requestAnimationFrame( raf ) :
|
||||
setInterval( jQuery.fx.tick, jQuery.fx.interval );
|
||||
window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
|
||||
};
|
||||
|
||||
jQuery.fx.stop = function() {
|
||||
if ( window.cancelAnimationFrame ) {
|
||||
window.cancelAnimationFrame( timerId );
|
||||
} else {
|
||||
clearInterval( timerId );
|
||||
window.clearInterval( timerId );
|
||||
}
|
||||
|
||||
timerId = null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/document",
|
||||
"./var/rnotwhite",
|
||||
"./var/hasOwn",
|
||||
"./var/slice",
|
||||
@@ -8,7 +9,7 @@ define([
|
||||
"./core/init",
|
||||
"./data",
|
||||
"./selector"
|
||||
], function( jQuery, rnotwhite, hasOwn, slice, support ) {
|
||||
], function( jQuery, document, rnotwhite, hasOwn, slice, support ) {
|
||||
|
||||
var rformElems = /^(?:input|select|textarea)$/i,
|
||||
rkeyEvent = /^key/,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
define([
|
||||
"../var/document",
|
||||
"../var/support"
|
||||
], function( support ) {
|
||||
], function( document, support ) {
|
||||
|
||||
(function() {
|
||||
var i, eventName,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
define([
|
||||
"./core",
|
||||
"./var/document",
|
||||
"./var/concat",
|
||||
"./var/push",
|
||||
"./var/deletedIds",
|
||||
@@ -22,7 +23,7 @@ define([
|
||||
"./traversing",
|
||||
"./selector",
|
||||
"./event"
|
||||
], function( jQuery, concat, push, deletedIds, access,
|
||||
], function( jQuery, document, concat, push, deletedIds, access,
|
||||
rcheckableType, rtagName, rscriptType, rleadingWhitespace, nodeNames,
|
||||
createSafeFragment, wrapMap, getAll, setGlobalEval,
|
||||
buildFragment, support ) {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
define([
|
||||
"../core",
|
||||
"../var/document",
|
||||
"../var/support"
|
||||
], function( jQuery, support ) {
|
||||
], function( jQuery, document, support ) {
|
||||
|
||||
(function() {
|
||||
var div = document.createElement( "div" ),
|
||||
fragment = document.createDocumentFragment();
|
||||
fragment = document.createDocumentFragment(),
|
||||
input = document.createElement( "input" );
|
||||
|
||||
// Setup
|
||||
div.innerHTML = " <link/><a href='/a'></a>";
|
||||
@@ -29,7 +31,13 @@ define([
|
||||
|
||||
// #11217 - WebKit loses check when the name is after the checked attribute
|
||||
fragment.appendChild( div );
|
||||
div.innerHTML = "<input type='radio' checked='checked' name='t'/>";
|
||||
// Support: Windows Web Apps (WWA)
|
||||
// `name` and `type` must use .setAttribute for WWA (#14901)
|
||||
input.setAttribute( "type", "radio" );
|
||||
input.setAttribute( "checked", "checked" );
|
||||
input.setAttribute( "name", "t" );
|
||||
|
||||
div.appendChild( input );
|
||||
|
||||
// Support: Android<4.2
|
||||
// Older WebKit doesn't clone checked state correctly in fragments
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
define([
|
||||
"./core",
|
||||
"./core/access",
|
||||
"./var/document",
|
||||
"./var/documentElement",
|
||||
"./css/var/rnumnonpx",
|
||||
"./css/curCSS",
|
||||
"./css/addGetHookIf",
|
||||
@@ -9,7 +11,7 @@ define([
|
||||
"./core/init",
|
||||
"./css",
|
||||
"./selector" // contains
|
||||
], function( jQuery, access, rnumnonpx, curCSS, addGetHookIf, support ) {
|
||||
], function( jQuery, access, document, documentElement, rnumnonpx, curCSS, addGetHookIf, support ) {
|
||||
|
||||
// BuildExclude
|
||||
curCSS = curCSS.curCSS;
|
||||
|
||||
@@ -11,9 +11,9 @@ jQuery.fn.delay = function( time, type ) {
|
||||
type = type || "fx";
|
||||
|
||||
return this.queue( type, function( next, hooks ) {
|
||||
var timeout = setTimeout( next, time );
|
||||
var timeout = window.setTimeout( next, time );
|
||||
hooks.stop = function() {
|
||||
clearTimeout( timeout );
|
||||
window.clearTimeout( timeout );
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
3
src/var/document.js
Normal file
3
src/var/document.js
Normal file
@@ -0,0 +1,3 @@
|
||||
define(function() {
|
||||
return window.document;
|
||||
});
|
||||
5
src/var/documentElement.js
Normal file
5
src/var/documentElement.js
Normal file
@@ -0,0 +1,5 @@
|
||||
define([
|
||||
"./document"
|
||||
], function( document ) {
|
||||
return document.documentElement;
|
||||
});
|
||||
Reference in New Issue
Block a user