21 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/test/node_smoke_tests/lib/ensure_iterability_es6.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | const assert = require( "assert" );
4 |
5 | const ensureIterability = () => {
6 | const { JSDOM } = require( "jsdom" );
7 |
8 | const { window } = new JSDOM( "" );
9 |
10 | let i;
11 | const ensureJQuery = require( "./ensure_jquery" );
12 | const jQuery = require( "../../../dist/jquery.js" )( window );
13 | const elem = jQuery( "" );
14 | let result = "";
15 |
16 | ensureJQuery( jQuery );
17 |
18 | for ( i of elem ) {
19 | result += i.nodeName;
20 | }
21 |
22 | assert.strictEqual( result, "DIVSPANA", "for-of works on jQuery objects" );
23 | };
24 |
25 | module.exports = ensureIterability;
26 |
--------------------------------------------------------------------------------
/src/exports/global.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 |
3 | var
4 |
5 | // Map over jQuery in case of overwrite
6 | _jQuery = window.jQuery,
7 |
8 | // Map over the $ in case of overwrite
9 | _$ = window.$;
10 |
11 | jQuery.noConflict = function( deep ) {
12 | if ( window.$ === jQuery ) {
13 | window.$ = _$;
14 | }
15 |
16 | if ( deep && window.jQuery === jQuery ) {
17 | window.jQuery = _jQuery;
18 | }
19 |
20 | return jQuery;
21 | };
22 |
23 | // Expose jQuery and $ identifiers, even in AMD
24 | // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
25 | // and CommonJS for browser emulators (#13566)
26 | if ( typeof noGlobal === "undefined" ) {
27 | window.jQuery = window.$ = jQuery;
28 | }
29 |
--------------------------------------------------------------------------------
/src/css/curCSS.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 | import isAttached from "../core/isAttached.js";
3 | import getStyles from "./var/getStyles.js";
4 |
5 | function curCSS( elem, name, computed ) {
6 | var ret;
7 |
8 | computed = computed || getStyles( elem );
9 |
10 | // getPropertyValue is needed for `.css('--customProperty')` (gh-3144)
11 | if ( computed ) {
12 | ret = computed.getPropertyValue( name ) || computed[ name ];
13 |
14 | if ( ret === "" && !isAttached( elem ) ) {
15 | ret = jQuery.style( elem, name );
16 | }
17 | }
18 |
19 | return ret !== undefined ?
20 |
21 | // Support: IE <=9 - 11+
22 | // IE returns zIndex value as an integer.
23 | ret + "" :
24 | ret;
25 | }
26 |
27 | export default curCSS;
28 |
--------------------------------------------------------------------------------
/src/event/alias.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 |
3 | import "../event.js";
4 | import "./trigger.js";
5 |
6 | jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
7 | "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
8 | "change select submit keydown keypress keyup contextmenu" ).split( " " ),
9 | function( _i, name ) {
10 |
11 | // Handle event binding
12 | jQuery.fn[ name ] = function( data, fn ) {
13 | return arguments.length > 0 ?
14 | this.on( name, null, data, fn ) :
15 | this.trigger( name );
16 | };
17 | } );
18 |
19 | jQuery.fn.extend( {
20 | hover: function( fnOver, fnOut ) {
21 | return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
22 | }
23 | } );
24 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### Summary ###
2 |
6 |
7 |
8 | ### Checklist ###
9 |
12 |
13 | * [ ] All authors have signed the CLA at https://cla.js.foundation/jquery/jquery
14 | * [ ] New tests have been added to show the fix or feature works
15 | * [ ] Grunt build and unit tests pass locally with these changes
16 | * [ ] If needed, a docs issue/PR was created at https://github.com/jquery/api.jquery.com
17 |
18 |
21 |
--------------------------------------------------------------------------------
/src/manipulation/getAll.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 | import nodeName from "../core/nodeName.js";
3 |
4 | function getAll( context, tag ) {
5 |
6 | // Support: IE <=9 - 11+
7 | // Use typeof to avoid zero-argument method invocation on host objects (#15151)
8 | var ret;
9 |
10 | if ( typeof context.getElementsByTagName !== "undefined" ) {
11 | ret = context.getElementsByTagName( tag || "*" );
12 |
13 | } else if ( typeof context.querySelectorAll !== "undefined" ) {
14 | ret = context.querySelectorAll( tag || "*" );
15 |
16 | } else {
17 | ret = [];
18 | }
19 |
20 | if ( tag === undefined || tag && nodeName( context, tag ) ) {
21 | return jQuery.merge( [ context ], ret );
22 | }
23 |
24 | return ret;
25 | }
26 |
27 | export default getAll;
28 |
--------------------------------------------------------------------------------
/src/manipulation/_evalUrl.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../ajax.js";
2 |
3 | jQuery._evalUrl = function( url, options ) {
4 | return jQuery.ajax( {
5 | url: url,
6 |
7 | // Make this explicit, since user can override this through ajaxSetup (#11264)
8 | type: "GET",
9 | dataType: "script",
10 | cache: true,
11 | async: false,
12 | global: false,
13 |
14 | // Only evaluate the response if it is successful (gh-4126)
15 | // dataFilter is not invoked for failure responses, so using it instead
16 | // of the default converter is kludgy but it works.
17 | converters: {
18 | "text script": function() {}
19 | },
20 | dataFilter: function( response ) {
21 | jQuery.globalEval( response, options );
22 | }
23 | } );
24 | };
25 |
26 | export default jQuery._evalUrl;
27 |
--------------------------------------------------------------------------------
/test/data/ajax/unreleasedXHR.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Attempt to block tests because of dangling XHR requests (IE)
6 |
7 |
8 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/manipulation/wrapMap.js:
--------------------------------------------------------------------------------
1 | // We have to close these tags to support XHTML (#13200)
2 | var wrapMap = {
3 |
4 | // Table parts need to be wrapped with `
` or they're
5 | // stripped to their contents when put in a div.
6 | // XHTML parsers do not magically insert elements in the
7 | // same way that tag soup parsers do, so we cannot shorten
8 | // this by omitting or other required elements.
9 | thead: [ 1, "
21 | Instructions: In IE11, click on or focus the first radio button.
22 | Then use the left/right arrow keys to select the other radios.
23 | You should see events logged in the results below.
24 |
25 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/jquery.js:
--------------------------------------------------------------------------------
1 | import jQuery from "./core.js";
2 |
3 | import "./selector.js";
4 | import "./traversing.js";
5 | import "./callbacks.js";
6 | import "./deferred.js";
7 | import "./deferred/exceptionHook.js";
8 | import "./core/ready.js";
9 | import "./data.js";
10 | import "./queue.js";
11 | import "./queue/delay.js";
12 | import "./attributes.js";
13 | import "./event.js";
14 | import "./manipulation.js";
15 | import "./manipulation/_evalUrl.js";
16 | import "./wrap.js";
17 | import "./css.js";
18 | import "./css/hiddenVisibleSelectors.js";
19 | import "./serialize.js";
20 | import "./ajax.js";
21 | import "./ajax/xhr.js";
22 | import "./ajax/script.js";
23 | import "./ajax/jsonp.js";
24 | import "./core/parseHTML.js";
25 | import "./ajax/load.js";
26 | import "./event/ajax.js";
27 | import "./effects.js";
28 | import "./effects/animatedSelector.js";
29 | import "./offset.js";
30 | import "./dimensions.js";
31 | import "./deprecated.js";
32 | import "./exports/amd.js";
33 | import "./exports/global.js";
34 |
35 | export default jQuery;
36 |
--------------------------------------------------------------------------------
/test/data/offset/body.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | body
7 |
12 |
13 |
14 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/css/var/isHiddenWithinTree.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../../core.js";
2 |
3 | // isHiddenWithinTree reports if an element has a non-"none" display style (inline and/or
4 | // through the CSS cascade), which is useful in deciding whether or not to make it visible.
5 | // It differs from the :hidden selector (jQuery.expr.pseudos.hidden) in two important ways:
6 | // * A hidden ancestor does not force an element to be classified as hidden.
7 | // * Being disconnected from the document does not force an element to be classified as hidden.
8 | // These differences improve the behavior of .toggle() et al. when applied to elements that are
9 | // detached or contained within hidden ancestors (gh-2404, gh-2863).
10 | export default function( elem, el ) {
11 |
12 | // isHiddenWithinTree might be called from jQuery#filter function;
13 | // in that case, element will be second argument
14 | elem = el || elem;
15 |
16 | // Inline style trumps all
17 | return elem.style.display === "none" ||
18 | elem.style.display === "" &&
19 | jQuery.css( elem, "display" ) === "none";
20 | };
21 |
--------------------------------------------------------------------------------
/src/exports/amd.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 |
3 | // Register as a named AMD module, since jQuery can be concatenated with other
4 | // files that may use define, but not via a proper concatenation script that
5 | // understands anonymous AMD modules. A named AMD is safest and most robust
6 | // way to register. Lowercase jquery is used because AMD module names are
7 | // derived from file names, and jQuery is normally delivered in a lowercase
8 | // file name. Do this after creating the global so that if an AMD module wants
9 | // to call noConflict to hide this version of jQuery, it will work.
10 |
11 | // Note that for maximum portability, libraries that are not jQuery should
12 | // declare themselves as anonymous modules, and avoid setting a global if an
13 | // AMD loader is present. jQuery is a special case. For more information, see
14 | // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
15 |
16 | if ( typeof define === "function" && define.amd ) {
17 | define( "jquery", [], function() {
18 | return jQuery;
19 | } );
20 | }
21 |
--------------------------------------------------------------------------------
/test/data/manipulation/iframe-denied.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | body
6 |
7 |
8 |
9 |
10 |
11 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/css/support.js:
--------------------------------------------------------------------------------
1 | import document from "../var/document.js";
2 | import documentElement from "../var/documentElement.js";
3 | import support from "../var/support.js";
4 |
5 | var reliableTrDimensionsVal;
6 |
7 | // Support: IE 11+, Edge 15 - 18+
8 | // IE/Edge misreport `getComputedStyle` of table rows with width/height
9 | // set in CSS while `offset*` properties report correct values.
10 | support.reliableTrDimensions = function() {
11 | var table, tr, trChild;
12 | if ( reliableTrDimensionsVal == null ) {
13 | table = document.createElement( "table" );
14 | tr = document.createElement( "tr" );
15 | trChild = document.createElement( "div" );
16 |
17 | table.style.cssText = "position:absolute;left:-11111px";
18 | tr.style.height = "1px";
19 | trChild.style.height = "9px";
20 |
21 | documentElement
22 | .appendChild( table )
23 | .appendChild( tr )
24 | .appendChild( trChild );
25 |
26 | var trStyle = window.getComputedStyle( tr );
27 | reliableTrDimensionsVal = parseInt( trStyle.height ) > 3;
28 |
29 | documentElement.removeChild( table );
30 | }
31 | return reliableTrDimensionsVal;
32 | };
33 |
34 | export default support;
35 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright JS Foundation and other contributors, https://js.foundation/
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/test/promises_aplus_adapters/when.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | const { JSDOM } = require( "jsdom" );
4 |
5 | const { window } = new JSDOM( "" );
6 |
7 | const jQuery = require( "../../" )( window );
8 |
9 | module.exports.deferred = () => {
10 | let adopted, promised;
11 |
12 | return {
13 | resolve: function() {
14 | if ( !adopted ) {
15 | adopted = jQuery.when.apply( jQuery, arguments );
16 | if ( promised ) {
17 | adopted.then( promised.resolve, promised.reject );
18 | }
19 | }
20 | return adopted;
21 | },
22 | reject: function( value ) {
23 | if ( !adopted ) {
24 | adopted = jQuery.when( jQuery.Deferred().reject( value ) );
25 | if ( promised ) {
26 | adopted.then( promised.resolve, promised.reject );
27 | }
28 | }
29 | return adopted;
30 | },
31 |
32 | // A manually-constructed thenable that works even if calls precede resolve/reject
33 | promise: {
34 | then: function() {
35 | if ( !adopted ) {
36 | if ( !promised ) {
37 | promised = jQuery.Deferred();
38 | }
39 | return promised.then.apply( promised, arguments );
40 | }
41 | return adopted.then.apply( adopted, arguments );
42 | }
43 | }
44 | };
45 | };
46 |
--------------------------------------------------------------------------------
/src/core/DOMEval.js:
--------------------------------------------------------------------------------
1 | import document from "../var/document.js";
2 |
3 | var preservedScriptAttributes = {
4 | type: true,
5 | src: true,
6 | nonce: true,
7 | noModule: true
8 | };
9 |
10 | function DOMEval( code, node, doc ) {
11 | doc = doc || document;
12 |
13 | var i, val,
14 | script = doc.createElement( "script" );
15 |
16 | script.text = code;
17 | if ( node ) {
18 | for ( i in preservedScriptAttributes ) {
19 |
20 | // Support: Firefox <=64 - 66+, Edge <=18+
21 | // Some browsers don't support the "nonce" property on scripts.
22 | // On the other hand, just using `getAttribute` is not enough as
23 | // the `nonce` attribute is reset to an empty string whenever it
24 | // becomes browsing-context connected.
25 | // See https://github.com/whatwg/html/issues/2369
26 | // See https://html.spec.whatwg.org/#nonce-attributes
27 | // The `node.getAttribute` check was added for the sake of
28 | // `jQuery.globalEval` so that it can fake a nonce-containing node
29 | // via an object.
30 | val = node[ i ] || node.getAttribute && node.getAttribute( i );
31 | if ( val ) {
32 | script.setAttribute( i, val );
33 | }
34 | }
35 | }
36 | doc.head.appendChild( script ).parentNode.removeChild( script );
37 | }
38 |
39 | export default DOMEval;
40 |
--------------------------------------------------------------------------------
/src/wrapper.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * jQuery JavaScript Library v@VERSION
3 | * https://jquery.com/
4 | *
5 | * Copyright JS Foundation and other contributors
6 | * Released under the MIT license
7 | * https://jquery.org/license
8 | *
9 | * Date: @DATE
10 | */
11 | ( function( global, factory ) {
12 |
13 | "use strict";
14 |
15 | if ( typeof module === "object" && typeof module.exports === "object" ) {
16 |
17 | // For CommonJS and CommonJS-like environments where a proper `window`
18 | // is present, execute the factory and get jQuery.
19 | // For environments that do not have a `window` with a `document`
20 | // (such as Node.js), expose a factory as module.exports.
21 | // This accentuates the need for the creation of a real `window`.
22 | // e.g. var jQuery = require("jquery")(window);
23 | // See ticket #14549 for more info.
24 | module.exports = global.document ?
25 | factory( global, true ) :
26 | function( w ) {
27 | if ( !w.document ) {
28 | throw new Error( "jQuery requires a window with a document" );
29 | }
30 | return factory( w );
31 | };
32 | } else {
33 | factory( global );
34 | }
35 |
36 | // Pass this if window is not defined yet
37 | } )( typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
38 |
39 | "use strict";
40 |
41 | // @CODE
42 | // build.js inserts compiled jQuery here
43 |
44 | return jQuery;
45 | } );
46 |
--------------------------------------------------------------------------------
/src/selector/rbuggyQSA.js:
--------------------------------------------------------------------------------
1 | import document from "../var/document.js";
2 | import isIE from "../var/isIE.js";
3 | import whitespace from "./var/whitespace.js";
4 |
5 | var rbuggyQSA = [],
6 | testEl = document.createElement( "div" ),
7 | input = document.createElement( "input" );
8 |
9 | testEl.innerHTML = "";
10 |
11 | // Support: Chrome 38 - 77 only
12 | // Chrome considers anchor elements with href to match ":enabled"
13 | // See https://bugs.chromium.org/p/chromium/issues/detail?id=993387
14 | if ( testEl.querySelectorAll( ":enabled" ).length ) {
15 | rbuggyQSA.push( ":enabled" );
16 | }
17 |
18 | // Support: IE 9 - 11+
19 | // IE's :disabled selector does not pick up the children of disabled fieldsets
20 | if ( isIE ) {
21 | rbuggyQSA.push( ":enabled", ":disabled" );
22 | }
23 |
24 | // Support: IE 11+, Edge 15 - 18+
25 | // IE 11/Edge don't find elements on a `[name='']` query in some cases.
26 | // Adding a temporary attribute to the document before the selection works
27 | // around the issue.
28 | // Interestingly, IE 10 & older don't seem to have the issue.
29 | input.setAttribute( "name", "" );
30 | testEl.appendChild( input );
31 | if ( !testEl.querySelectorAll( "[name='']" ).length ) {
32 | rbuggyQSA.push( "\\[" + whitespace + "*name" + whitespace + "*=" +
33 | whitespace + "*(?:''|\"\")" );
34 | }
35 |
36 | rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) );
37 |
38 | export default rbuggyQSA;
39 |
--------------------------------------------------------------------------------
/test/data/offset/fixed.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | fixed
7 |
15 |
16 |
17 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/core/access.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 | import toType from "../core/toType.js";
3 |
4 | // Multifunctional method to get and set values of a collection
5 | // The value/s can optionally be executed if it's a function
6 | var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
7 | var i = 0,
8 | len = elems.length,
9 | bulk = key == null;
10 |
11 | // Sets many values
12 | if ( toType( key ) === "object" ) {
13 | chainable = true;
14 | for ( i in key ) {
15 | access( elems, fn, i, key[ i ], true, emptyGet, raw );
16 | }
17 |
18 | // Sets one value
19 | } else if ( value !== undefined ) {
20 | chainable = true;
21 |
22 | if ( typeof value !== "function" ) {
23 | raw = true;
24 | }
25 |
26 | if ( bulk ) {
27 |
28 | // Bulk operations run against the entire set
29 | if ( raw ) {
30 | fn.call( elems, value );
31 | fn = null;
32 |
33 | // ...except when executing function values
34 | } else {
35 | bulk = fn;
36 | fn = function( elem, _key, value ) {
37 | return bulk.call( jQuery( elem ), value );
38 | };
39 | }
40 | }
41 |
42 | if ( fn ) {
43 | for ( ; i < len; i++ ) {
44 | fn(
45 | elems[ i ], key, raw ?
46 | value :
47 | value.call( elems[ i ], i, fn( elems[ i ], key ) )
48 | );
49 | }
50 | }
51 | }
52 |
53 | if ( chainable ) {
54 | return elems;
55 | }
56 |
57 | // Gets
58 | if ( bulk ) {
59 | return fn.call( elems );
60 | }
61 |
62 | return len ? fn( elems[ 0 ], key ) : emptyGet;
63 | };
64 |
65 | export default access;
66 |
--------------------------------------------------------------------------------
/test/data/testinit-jsdom.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | // Support: jsdom 13.2+
4 | // jsdom implements a throwing `window.scrollTo`.
5 | QUnit.config.scrolltop = false;
6 |
7 | QUnit.isIE = false;
8 | QUnit.testUnlessIE = QUnit.test;
9 |
10 | const FILEPATH = "/test/data/testinit-jsdom.js";
11 | const activeScript = document.currentScript;
12 | const parentUrl = activeScript && activeScript.src ?
13 | activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" :
14 | "../";
15 | const supportjQuery = this.jQuery;
16 |
17 | // baseURL is intentionally set to "data/" instead of "".
18 | // This is not just for convenience (since most files are in data/)
19 | // but also to ensure that urls without prefix fail.
20 | // Otherwise it's easy to write tests that pass on test/index.html
21 | // but fail in Karma runner (where the baseURL is different).
22 | const baseURL = parentUrl + "test/data/";
23 |
24 | // Setup global variables before loading jQuery for testing .noConflict()
25 | supportjQuery.noConflict( true );
26 | window.originaljQuery = this.jQuery = undefined;
27 | window.original$ = this.$ = "replaced";
28 |
29 | /**
30 | * Add random number to url to stop caching
31 | *
32 | * Also prefixes with baseURL automatically.
33 | *
34 | * @example url("index.html")
35 | * @result "data/index.html?10538358428943"
36 | *
37 | * @example url("mock.php?foo=bar")
38 | * @result "data/mock.php?foo=bar&10538358345554"
39 | */
40 | function url( value ) {
41 | return baseURL + value + ( /\?/.test( value ) ? "&" : "?" ) +
42 | new Date().getTime() + "" + parseInt( Math.random() * 100000, 10 );
43 | }
44 |
--------------------------------------------------------------------------------
/test/data/offset/static.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | static
7 |
13 |
14 |
15 |
26 |
27 |
28 |
29 |
30 |
31 |
Click the white box to move the marker to it. Clicking the box also changes the position to absolute (if not already) and sets the position according to the position method.
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/core/parseHTML.js:
--------------------------------------------------------------------------------
1 | import jQuery from "../core.js";
2 | import document from "../var/document.js";
3 | import rsingleTag from "./var/rsingleTag.js";
4 | import buildFragment from "../manipulation/buildFragment.js";
5 |
6 | // Argument "data" should be string of html
7 | // context (optional): If specified, the fragment will be created in this context,
8 | // defaults to document
9 | // keepScripts (optional): If true, will include scripts passed in the html string
10 | jQuery.parseHTML = function( data, context, keepScripts ) {
11 | if ( typeof data !== "string" ) {
12 | return [];
13 | }
14 | if ( typeof context === "boolean" ) {
15 | keepScripts = context;
16 | context = false;
17 | }
18 |
19 | var base, parsed, scripts;
20 |
21 | if ( !context ) {
22 |
23 | // Stop scripts or inline event handlers from being executed immediately
24 | // by using document.implementation
25 | context = document.implementation.createHTMLDocument( "" );
26 |
27 | // Set the base href for the created document
28 | // so any parsed elements with URLs
29 | // are based on the document's URL (gh-2965)
30 | base = context.createElement( "base" );
31 | base.href = document.location.href;
32 | context.head.appendChild( base );
33 | }
34 |
35 | parsed = rsingleTag.exec( data );
36 | scripts = !keepScripts && [];
37 |
38 | // Single tag
39 | if ( parsed ) {
40 | return [ context.createElement( parsed[ 1 ] ) ];
41 | }
42 |
43 | parsed = buildFragment( [ data ], context, scripts );
44 |
45 | if ( scripts && scripts.length ) {
46 | jQuery( scripts ).remove();
47 | }
48 |
49 | return jQuery.merge( [], parsed.childNodes );
50 | };
51 |
--------------------------------------------------------------------------------
/test/karma.context.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CONTEXT
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
26 | %SCRIPTS%
27 |
28 |
29 |
30 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/test/data/offset/scroll.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 | scroll
7 |
17 |
18 |
19 |
31 |
32 |
33 |
Click the white box to move the marker to it. Clicking the box also changes the position to absolute (if not already) and sets the position according to the position method.
42 | This is a test page for
43 |
44 | #8135
45 |
46 | which was reported in Firefox when accessing properties
47 | of an XMLHttpRequest object after a network error occurred.
48 |
49 |
Take the following steps:
50 |
51 |
52 | make sure you accessed this page through a web server,
53 |
54 |
55 | stop the web server,
56 |
57 |
58 | open the console,
59 |
60 |
61 | click this
62 |
63 | ,
64 |
65 |
66 | wait for both requests to fail.
67 |
68 |
69 |
70 | Test passes if you get two log lines:
71 |
72 |
73 | the first starting with "abort",
74 |
75 |
76 | the second starting with "complete",
77 |
78 |
79 |
80 |
81 | Test fails if the browser notifies an exception.
82 |