├── .npmrc ├── test ├── data │ ├── support │ │ ├── csp.log │ │ ├── csp.js │ │ ├── getComputedSupport.js │ │ └── bodyBackground.html │ ├── badcall.js │ ├── badjson.js │ ├── json_obj.js │ ├── module.js │ ├── 1x1.jpg │ ├── inner_module.js │ ├── nomodule.js │ ├── inner_nomodule.js │ ├── name.html │ ├── iframe.html │ ├── test2.html │ ├── csp-nonce-globaleval.js │ ├── csp-nonce-external.js │ ├── frame.html │ ├── cleanScript.html │ ├── 1x1.svg │ ├── test3.html │ ├── csp-nonce.js │ ├── test.include.html │ ├── iframeTest.js │ ├── core │ │ ├── jquery-iterability-transpiled-es6.js │ │ ├── jquery-iterability-transpiled.html │ │ ├── onready.html │ │ ├── aliased.html │ │ └── dynamic_ready.html │ ├── text.txt │ ├── dashboard.xml │ ├── manipulation │ │ ├── scripts-context.html │ │ └── iframe-denied.html │ ├── csp.include.html │ ├── csp-nonce.html │ ├── event │ │ ├── focusElem.html │ │ ├── onbeforeunload.html │ │ ├── triggerunload.html │ │ ├── focusinCrossFrame.html │ │ ├── promiseReady.html │ │ ├── interactiveReady.html │ │ └── syncReady.html │ ├── css │ │ ├── cssWidthBeforeDocReady.html │ │ └── cssWidthBrowserZoom.html │ ├── csp-nonce-external.html │ ├── data │ │ └── dataAttrs.html │ ├── csp-nonce-globaleval.html │ ├── dimensions │ │ └── documentLarge.html │ ├── selector │ │ ├── mixed_sort.html │ │ ├── cache.html │ │ └── html5_selector.html │ ├── ajax │ │ ├── unreleasedXHR.html │ │ └── onunload.html │ ├── with_fries.xml │ ├── offset │ │ ├── body.html │ │ ├── fixed.html │ │ ├── table.html │ │ ├── static.html │ │ ├── scroll.html │ │ ├── relative.html │ │ ├── absolute.html │ │ └── boxes.html │ ├── testinit-jsdom.js │ ├── readywait.html │ └── testsuite.css ├── promises_aplus_adapters │ ├── .eslintrc.json │ ├── deferred.js │ └── when.js ├── xhtml.php ├── node_smoke_tests │ ├── .eslintrc.json │ ├── iterable_with_native_symbol.js │ ├── document_missing.js │ ├── lib │ │ ├── ensure_jquery.js │ │ ├── ensure_global_not_created.js │ │ └── ensure_iterability_es6.js │ ├── document_passed.js │ └── document_present_originally.js ├── unit │ ├── exports.js │ └── support.js ├── integration │ ├── data │ │ ├── gh-1764-fullscreen-iframe.css │ │ ├── gh-1764-fullscreen-iframe.html │ │ └── gh-1764-fullscreen.js │ ├── gh-1764-fullscreen.html │ └── gh-2343-ie-radio-click.html ├── karma.context.html ├── karma.debug.html ├── .eslintrc.json ├── index.html ├── networkerror.html ├── localfile.html ├── jquery.js └── hovertest.html ├── src ├── var │ ├── arr.js │ ├── trim.js │ ├── document.js │ ├── getProto.js │ ├── rcheckableType.js │ ├── class2type.js │ ├── pop.js │ ├── push.js │ ├── slice.js │ ├── sort.js │ ├── indexOf.js │ ├── pnum.js │ ├── fnToString.js │ ├── isIE.js │ ├── support.js │ ├── toString.js │ ├── documentElement.js │ ├── hasOwn.js │ ├── isWindow.js │ ├── ObjectFunctionString.js │ ├── rcssNum.js │ ├── rnothtmlwhite.js │ └── flat.js ├── ajax │ ├── var │ │ ├── rquery.js │ │ ├── location.js │ │ └── nonce.js │ ├── parseXML.js │ ├── script.js │ ├── load.js │ ├── jsonp.js │ └── xhr.js ├── core │ ├── var │ │ ├── rhtml.js │ │ └── rsingleTag.js │ ├── nodeName.js │ ├── readyException.js │ ├── toType.js │ ├── stripAndCollapse.js │ ├── camelCase.js │ ├── isAttached.js │ ├── DOMEval.js │ ├── access.js │ ├── parseHTML.js │ ├── ready.js │ ├── ready-no-deferred.js │ └── init.js ├── css │ ├── var │ │ ├── cssExpand.js │ │ ├── rnumnonpx.js │ │ ├── swap.js │ │ ├── getStyles.js │ │ └── isHiddenWithinTree.js │ ├── hiddenVisibleSelectors.js │ ├── cssCamelCase.js │ ├── curCSS.js │ ├── finalPropName.js │ ├── support.js │ ├── isAutoPx.js │ ├── adjustCSS.js │ └── showHide.js ├── data │ ├── var │ │ ├── dataPriv.js │ │ ├── dataUser.js │ │ └── acceptData.js │ └── Data.js ├── manipulation │ ├── var │ │ ├── rscriptType.js │ │ └── rtagName.js │ ├── setGlobalEval.js │ ├── getAll.js │ ├── _evalUrl.js │ ├── wrapMap.js │ └── buildFragment.js ├── selector │ ├── var │ │ └── whitespace.js │ ├── support.js │ ├── contains.js │ ├── escapeSelector.js │ ├── rbuggyQSA.js │ └── uniqueSort.js ├── traversing │ ├── var │ │ ├── rneedsContext.js │ │ ├── siblings.js │ │ └── dir.js │ └── findFilter.js ├── attributes.js ├── effects │ ├── animatedSelector.js │ └── Tween.js ├── event │ ├── ajax.js │ └── alias.js ├── deferred │ └── exceptionHook.js ├── queue │ └── delay.js ├── exports │ ├── global.js │ └── amd.js ├── .eslintrc.json ├── jquery.js ├── wrapper.js ├── wrap.js ├── dimensions.js ├── deprecated.js ├── attributes │ ├── attr.js │ ├── prop.js │ ├── val.js │ └── classes.js ├── queue.js ├── serialize.js └── data.js ├── .gitattributes ├── .npmignore ├── CODE_OF_CONDUCT.md ├── .eslintrc.json ├── .eslintrc-node.json ├── .editorconfig ├── .eslintignore ├── .gitignore ├── dist └── .eslintrc.json ├── .github ├── lock.yml ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── .eslintrc-browser.json ├── .travis.yml ├── LICENSE.txt └── package.json /.npmrc: -------------------------------------------------------------------------------- 1 | save-exact=true 2 | -------------------------------------------------------------------------------- /test/data/support/csp.log: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/var/arr.js: -------------------------------------------------------------------------------- 1 | export default []; 2 | -------------------------------------------------------------------------------- /test/data/badcall.js: -------------------------------------------------------------------------------- 1 | undefined(); 2 | -------------------------------------------------------------------------------- /src/var/trim.js: -------------------------------------------------------------------------------- 1 | export default "".trim; 2 | -------------------------------------------------------------------------------- /test/data/badjson.js: -------------------------------------------------------------------------------- 1 | {bad: toTheBone} 2 | -------------------------------------------------------------------------------- /src/ajax/var/rquery.js: -------------------------------------------------------------------------------- 1 | export default ( /\?/ ); 2 | -------------------------------------------------------------------------------- /src/core/var/rhtml.js: -------------------------------------------------------------------------------- 1 | export default ( /HTML$/i ); 2 | -------------------------------------------------------------------------------- /src/var/document.js: -------------------------------------------------------------------------------- 1 | export default window.document; 2 | -------------------------------------------------------------------------------- /src/ajax/var/location.js: -------------------------------------------------------------------------------- 1 | export default window.location; 2 | -------------------------------------------------------------------------------- /src/ajax/var/nonce.js: -------------------------------------------------------------------------------- 1 | export default { guid: Date.now() }; 2 | -------------------------------------------------------------------------------- /src/var/getProto.js: -------------------------------------------------------------------------------- 1 | export default Object.getPrototypeOf; 2 | -------------------------------------------------------------------------------- /test/data/json_obj.js: -------------------------------------------------------------------------------- 1 | { "data": {"lang": "en", "length": 25} } 2 | -------------------------------------------------------------------------------- /src/var/rcheckableType.js: -------------------------------------------------------------------------------- 1 | export default ( /^(?:checkbox|radio)$/i ); 2 | -------------------------------------------------------------------------------- /src/var/class2type.js: -------------------------------------------------------------------------------- 1 | // [[Class]] -> type pairs 2 | export default {}; 3 | -------------------------------------------------------------------------------- /test/data/module.js: -------------------------------------------------------------------------------- 1 | QUnit.assert.ok( true, "evaluated: module with src" ); 2 | -------------------------------------------------------------------------------- /src/css/var/cssExpand.js: -------------------------------------------------------------------------------- 1 | export default [ "Top", "Right", "Bottom", "Left" ]; 2 | -------------------------------------------------------------------------------- /src/var/pop.js: -------------------------------------------------------------------------------- 1 | import arr from "./arr.js"; 2 | 3 | export default arr.pop; 4 | -------------------------------------------------------------------------------- /src/var/push.js: -------------------------------------------------------------------------------- 1 | import arr from "./arr.js"; 2 | 3 | export default arr.push; 4 | -------------------------------------------------------------------------------- /src/var/slice.js: -------------------------------------------------------------------------------- 1 | import arr from "./arr.js"; 2 | 3 | export default arr.slice; 4 | -------------------------------------------------------------------------------- /src/var/sort.js: -------------------------------------------------------------------------------- 1 | import arr from "./arr.js"; 2 | 3 | export default arr.sort; 4 | -------------------------------------------------------------------------------- /src/var/indexOf.js: -------------------------------------------------------------------------------- 1 | import arr from "./arr.js"; 2 | 3 | export default arr.indexOf; 4 | -------------------------------------------------------------------------------- /src/var/pnum.js: -------------------------------------------------------------------------------- 1 | export default ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source; 2 | -------------------------------------------------------------------------------- /test/data/1x1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tkh44/jquery/master/test/data/1x1.jpg -------------------------------------------------------------------------------- /test/data/inner_module.js: -------------------------------------------------------------------------------- 1 | QUnit.assert.ok( true, "evaluated: inner module with src" ); 2 | -------------------------------------------------------------------------------- /src/data/var/dataPriv.js: -------------------------------------------------------------------------------- 1 | import Data from "../Data.js"; 2 | 3 | export default new Data(); 4 | -------------------------------------------------------------------------------- /src/data/var/dataUser.js: -------------------------------------------------------------------------------- 1 | import Data from "../Data.js"; 2 | 3 | export default new Data(); 4 | -------------------------------------------------------------------------------- /src/manipulation/var/rscriptType.js: -------------------------------------------------------------------------------- 1 | export default ( /^$|^module$|\/(?:java|ecma)script/i ); 2 | -------------------------------------------------------------------------------- /test/data/nomodule.js: -------------------------------------------------------------------------------- 1 | QUnit.assert.ok( QUnit.isIE, "evaluated: nomodule script with src" ); 2 | -------------------------------------------------------------------------------- /src/var/fnToString.js: -------------------------------------------------------------------------------- 1 | import hasOwn from "./hasOwn.js"; 2 | 3 | export default hasOwn.toString; 4 | -------------------------------------------------------------------------------- /src/var/isIE.js: -------------------------------------------------------------------------------- 1 | import document from "./document.js"; 2 | 3 | export default document.documentMode; 4 | -------------------------------------------------------------------------------- /src/var/support.js: -------------------------------------------------------------------------------- 1 | // All support tests are defined in their respective modules. 2 | export default {}; 3 | -------------------------------------------------------------------------------- /test/data/inner_nomodule.js: -------------------------------------------------------------------------------- 1 | QUnit.assert.ok( QUnit.isIE, "evaluated: inner nomodule script with src" ); 2 | -------------------------------------------------------------------------------- /src/var/toString.js: -------------------------------------------------------------------------------- 1 | import class2type from "./class2type.js"; 2 | 3 | export default class2type.toString; 4 | -------------------------------------------------------------------------------- /src/var/documentElement.js: -------------------------------------------------------------------------------- 1 | import document from "./document.js"; 2 | 3 | export default document.documentElement; 4 | -------------------------------------------------------------------------------- /src/var/hasOwn.js: -------------------------------------------------------------------------------- 1 | import class2type from "./class2type.js"; 2 | 3 | export default class2type.hasOwnProperty; 4 | -------------------------------------------------------------------------------- /test/data/name.html: -------------------------------------------------------------------------------- 1 | ERROR 2 | -------------------------------------------------------------------------------- /src/var/isWindow.js: -------------------------------------------------------------------------------- 1 | export default function isWindow( obj ) { 2 | return obj != null && obj === obj.window; 3 | }; 4 | -------------------------------------------------------------------------------- /test/data/support/csp.js: -------------------------------------------------------------------------------- 1 | jQuery( function() { 2 | startIframeTest( getComputedSupport( jQuery.support ) ); 3 | } ); 4 | -------------------------------------------------------------------------------- /test/promises_aplus_adapters/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "../../.eslintrc-node.json" 5 | } 6 | -------------------------------------------------------------------------------- /src/selector/var/whitespace.js: -------------------------------------------------------------------------------- 1 | // https://www.w3.org/TR/css3-selectors/#whitespace 2 | export default "[\\x20\\t\\r\\n\\f]"; 3 | -------------------------------------------------------------------------------- /src/var/ObjectFunctionString.js: -------------------------------------------------------------------------------- 1 | import fnToString from "./fnToString.js"; 2 | 3 | export default fnToString.call( Object ); 4 | -------------------------------------------------------------------------------- /src/css/var/rnumnonpx.js: -------------------------------------------------------------------------------- 1 | import pnum from "../../var/pnum.js"; 2 | 3 | export default new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" ); 4 | -------------------------------------------------------------------------------- /src/var/rcssNum.js: -------------------------------------------------------------------------------- 1 | import pnum from "../var/pnum.js"; 2 | 3 | export default new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ); 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # JS files must always use LF for tools to work 5 | *.js eol=lf 6 | -------------------------------------------------------------------------------- /test/data/iframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | iframe 4 | 5 | 6 |
span text
7 | 8 | 9 | -------------------------------------------------------------------------------- /src/traversing/var/rneedsContext.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../../core.js"; 2 | 3 | import "../../selector.js"; 4 | 5 | export default jQuery.expr.match.needsContext; 6 | -------------------------------------------------------------------------------- /test/xhtml.php: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /test/data/test2.html: -------------------------------------------------------------------------------- 1 | 6 | -------------------------------------------------------------------------------- /test/data/csp-nonce-globaleval.js: -------------------------------------------------------------------------------- 1 | /* global startIframeTest */ 2 | 3 | jQuery( function() { 4 | $.globalEval( "startIframeTest()", { nonce: "jquery+hardcoded+nonce" } ); 5 | } ); 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .eslintignore 2 | .eslintrc.json 3 | 4 | /.editorconfig 5 | /.gitattributes 6 | /.mailmap 7 | /.travis.yml 8 | 9 | /build 10 | /speed 11 | /test 12 | /Gruntfile.js 13 | -------------------------------------------------------------------------------- /src/core/nodeName.js: -------------------------------------------------------------------------------- 1 | function nodeName( elem, name ) { 2 | 3 | return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); 4 | 5 | }; 6 | 7 | export default nodeName; 8 | -------------------------------------------------------------------------------- /src/core/readyException.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | jQuery.readyException = function( error ) { 4 | window.setTimeout( function() { 5 | throw error; 6 | } ); 7 | }; 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | jQuery is a [JS Foundation](https://js.foundation/) project and subscribes to its code of conduct. 2 | 3 | It is available at https://js.foundation/community/code-of-conduct. 4 | -------------------------------------------------------------------------------- /test/data/csp-nonce-external.js: -------------------------------------------------------------------------------- 1 | /* global startIframeTest */ 2 | 3 | jQuery( function() { 4 | $( "body" ).append( "" ); 5 | } ); 6 | -------------------------------------------------------------------------------- /src/var/rnothtmlwhite.js: -------------------------------------------------------------------------------- 1 | // Only count HTML whitespace 2 | // Other whitespace should count in values 3 | // https://infra.spec.whatwg.org/#ascii-whitespace 4 | export default ( /[^\x20\t\r\n\f]+/g ); 5 | -------------------------------------------------------------------------------- /test/data/frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | frame 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/node_smoke_tests/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "../../.eslintrc-node.json", 5 | 6 | "parserOptions": { 7 | "ecmaVersion": 6 8 | }, 9 | 10 | "env": { 11 | "es6": true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/core/var/rsingleTag.js: -------------------------------------------------------------------------------- 1 | // rsingleTag matches a string consisting of a single HTML element with no attributes 2 | // and captures the element's name 3 | export default ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i ); 4 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "./.eslintrc-node.json", 5 | 6 | "overrides": [ 7 | { 8 | "files": "rollup.config.js", 9 | "parserOptions": { 10 | "sourceType": "module" 11 | } 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /test/data/cleanScript.html: -------------------------------------------------------------------------------- 1 | 6 | 11 | -------------------------------------------------------------------------------- /test/unit/exports.js: -------------------------------------------------------------------------------- 1 | QUnit.module( "exports", { afterEach: moduleTeardown } ); 2 | 3 | QUnit.test( "amdModule", function( assert ) { 4 | assert.expect( 1 ); 5 | 6 | assert.equal( jQuery, amdDefined, "Make sure defined module matches jQuery" ); 7 | } ); 8 | -------------------------------------------------------------------------------- /test/data/1x1.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | -------------------------------------------------------------------------------- /test/node_smoke_tests/iterable_with_native_symbol.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | if ( typeof Symbol === "undefined" ) { 4 | console.log( "Symbols not supported, skipping the test..." ); 5 | process.exit(); 6 | } 7 | 8 | require( "./lib/ensure_iterability_es6" )(); 9 | -------------------------------------------------------------------------------- /src/traversing/var/siblings.js: -------------------------------------------------------------------------------- 1 | export default function( n, elem ) { 2 | var matched = []; 3 | 4 | for ( ; n; n = n.nextSibling ) { 5 | if ( n.nodeType === 1 && n !== elem ) { 6 | matched.push( n ); 7 | } 8 | } 9 | 10 | return matched; 11 | }; 12 | -------------------------------------------------------------------------------- /test/data/test3.html: -------------------------------------------------------------------------------- 1 |
This is a user
2 |
This is a user
3 |
This is a teacher
4 |
This is a superuser
5 |
This is a superuser with non-HTML whitespace
6 | -------------------------------------------------------------------------------- /.eslintrc-node.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "jquery", 5 | 6 | "parserOptions": { 7 | "ecmaVersion": 2018 8 | }, 9 | 10 | "env": { 11 | "es6": true, 12 | "node": true 13 | }, 14 | 15 | "rules": { 16 | "strict": ["error", "global"] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/attributes.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | 3 | import "./attributes/attr.js"; 4 | import "./attributes/prop.js"; 5 | import "./attributes/classes.js"; 6 | import "./attributes/val.js"; 7 | 8 | // Return jQuery for attributes-only inclusion 9 | export default jQuery; 10 | -------------------------------------------------------------------------------- /test/data/csp-nonce.js: -------------------------------------------------------------------------------- 1 | /* global startIframeTest */ 2 | 3 | jQuery( function() { 4 | var script = document.createElement( "script" ); 5 | script.setAttribute( "nonce", "jquery+hardcoded+nonce" ); 6 | script.innerHTML = "startIframeTest()"; 7 | $( document.head ).append( script ); 8 | } ); 9 | -------------------------------------------------------------------------------- /test/data/test.include.html: -------------------------------------------------------------------------------- 1 | html text
2 | 6 | 7 | blabla 8 | -------------------------------------------------------------------------------- /test/data/iframeTest.js: -------------------------------------------------------------------------------- 1 | window.startIframeTest = function() { 2 | var args = Array.prototype.slice.call( arguments ); 3 | 4 | // Note: jQuery may be undefined if page did not load it 5 | args.unshift( window.jQuery, window, document ); 6 | window.parent.iframeCallback.apply( null, args ); 7 | }; 8 | -------------------------------------------------------------------------------- /src/effects/animatedSelector.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | import "../selector.js"; 4 | import "../effects.js"; 5 | 6 | jQuery.expr.pseudos.animated = function( elem ) { 7 | return jQuery.grep( jQuery.timers, function( fn ) { 8 | return elem === fn.elem; 9 | } ).length; 10 | }; 11 | -------------------------------------------------------------------------------- /src/manipulation/var/rtagName.js: -------------------------------------------------------------------------------- 1 | // rtagName captures the name from the first start tag in a string of HTML 2 | // https://html.spec.whatwg.org/multipage/syntax.html#tag-open-state 3 | // https://html.spec.whatwg.org/multipage/syntax.html#tag-name-state 4 | export default ( /<([a-z][^\/\0>\x20\t\r\n\f]*)/i ); 5 | -------------------------------------------------------------------------------- /src/var/flat.js: -------------------------------------------------------------------------------- 1 | import arr from "./arr.js"; 2 | 3 | // Support: IE 11+, Edge 18+ 4 | // Provide fallback for browsers without Array#flat. 5 | export default arr.flat ? function( array ) { 6 | return arr.flat.call( array ); 7 | } : function( array ) { 8 | return arr.concat.apply( [], array ); 9 | }; 10 | -------------------------------------------------------------------------------- /test/integration/data/gh-1764-fullscreen-iframe.css: -------------------------------------------------------------------------------- 1 | .result { 2 | font-size: 24px; 3 | margin: 0.5em 0; 4 | width: 700px; 5 | height: 56px; 6 | } 7 | 8 | .error { 9 | background-color: red; 10 | } 11 | 12 | .warn { 13 | background-color: yellow; 14 | } 15 | 16 | .success { 17 | background-color: lightgreen; 18 | } 19 | -------------------------------------------------------------------------------- /test/data/core/jquery-iterability-transpiled-es6.js: -------------------------------------------------------------------------------- 1 | /* global startIframeTest */ 2 | 3 | jQuery( function() { 4 | "use strict"; 5 | 6 | var elem = jQuery( "
" ); 7 | var result = ""; 8 | var i; 9 | for ( i of elem ) { 10 | result += i.nodeName; 11 | } 12 | 13 | startIframeTest( result ); 14 | } ); 15 | -------------------------------------------------------------------------------- /src/selector/support.js: -------------------------------------------------------------------------------- 1 | import document from "../var/document.js"; 2 | import support from "../var/support.js"; 3 | 4 | // Support: IE 9 - 11+, Edge 12 - 18+ 5 | // IE/Edge don't support the :scope pseudo-class. 6 | try { 7 | document.querySelectorAll( ":scope" ); 8 | support.scope = true; 9 | } catch ( e ) {} 10 | 11 | export default support; 12 | -------------------------------------------------------------------------------- /test/data/support/getComputedSupport.js: -------------------------------------------------------------------------------- 1 | function getComputedSupport( support ) { 2 | var prop, 3 | result = {}; 4 | 5 | for ( prop in support ) { 6 | if ( typeof support[ prop ] === "function" ) { 7 | result[ prop ] = support[ prop ](); 8 | } else { 9 | result[ prop ] = support[ prop ]; 10 | } 11 | } 12 | 13 | return result; 14 | } 15 | -------------------------------------------------------------------------------- /test/data/text.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet 2 | consectetuer adipiscing elit 3 | Sed lorem leo 4 | lorem leo consectetuer adipiscing elit 5 | Sed lorem leo 6 | rhoncus sit amet 7 | elementum at 8 | bibendum at, eros 9 | Cras at mi et tortor egestas vestibulum 10 | sed Cras at mi vestibulum 11 | Phasellus sed felis sit amet 12 | orci dapibus semper. 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | indent_style = tab 8 | end_of_line = lf 9 | charset = utf-8 10 | trim_trailing_whitespace = true 11 | insert_final_newline = true 12 | 13 | [package.json] 14 | indent_style = space 15 | indent_size = 2 16 | 17 | -------------------------------------------------------------------------------- /src/core/toType.js: -------------------------------------------------------------------------------- 1 | import class2type from "../var/class2type.js"; 2 | import toString from "../var/toString.js"; 3 | 4 | function toType( obj ) { 5 | if ( obj == null ) { 6 | return obj + ""; 7 | } 8 | 9 | return typeof obj === "object" ? 10 | class2type[ toString.call( obj ) ] || "object" : 11 | typeof obj; 12 | } 13 | 14 | export default toType; 15 | -------------------------------------------------------------------------------- /src/css/hiddenVisibleSelectors.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | import "../selector.js"; 4 | 5 | jQuery.expr.pseudos.hidden = function( elem ) { 6 | return !jQuery.expr.pseudos.visible( elem ); 7 | }; 8 | jQuery.expr.pseudos.visible = function( elem ) { 9 | return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length ); 10 | }; 11 | -------------------------------------------------------------------------------- /src/data/var/acceptData.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Determines whether an object can have data 3 | */ 4 | export default function( owner ) { 5 | 6 | // Accepts only: 7 | // - Node 8 | // - Node.ELEMENT_NODE 9 | // - Node.DOCUMENT_NODE 10 | // - Object 11 | // - Any 12 | return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType ); 13 | }; 14 | -------------------------------------------------------------------------------- /test/data/dashboard.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/data/manipulation/scripts-context.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | body 6 | 7 | 8 |
9 | 10 | 11 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | external 2 | node_modules 3 | *.min.js 4 | dist/** 5 | !dist/jquery.js 6 | test/data/jquery-1.9.1.js 7 | test/data/badcall.js 8 | test/data/badjson.js 9 | test/data/json_obj.js 10 | test/data/readywaitasset.js 11 | test/data/readywaitloader.js 12 | test/data/support/csp.js 13 | test/data/support/getComputedSupport.js 14 | test/data/core/jquery-iterability-transpiled.js 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .settings 3 | *~ 4 | *.diff 5 | *.patch 6 | /*.html 7 | .DS_Store 8 | .bower.json 9 | .sizecache.json 10 | yarn.lock 11 | package-lock.json 12 | 13 | npm-debug.log* 14 | 15 | # Ignore everything in dist folder except for eslint config 16 | /dist/* 17 | !/dist/.eslintrc.json 18 | 19 | /node_modules 20 | 21 | /test/data/core/jquery-iterability-transpiled.js 22 | -------------------------------------------------------------------------------- /src/core/stripAndCollapse.js: -------------------------------------------------------------------------------- 1 | import rnothtmlwhite from "../var/rnothtmlwhite.js"; 2 | 3 | // Strip and collapse whitespace according to HTML spec 4 | // https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace 5 | function stripAndCollapse( value ) { 6 | var tokens = value.match( rnothtmlwhite ) || []; 7 | return tokens.join( " " ); 8 | } 9 | 10 | export default stripAndCollapse; 11 | -------------------------------------------------------------------------------- /dist/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "../.eslintrc-browser.json", 5 | 6 | "parserOptions": { 7 | "ecmaVersion": 5, 8 | "sourceType": "script" 9 | }, 10 | 11 | "rules": { 12 | // That is okay for the built version 13 | "no-multiple-empty-lines": "off" 14 | }, 15 | 16 | "globals": { 17 | "define": false, 18 | "module": true, 19 | "Symbol": false 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/core/camelCase.js: -------------------------------------------------------------------------------- 1 | // Matches dashed string for camelizing 2 | var rdashAlpha = /-([a-z])/g; 3 | 4 | // Used by camelCase as callback to replace() 5 | function fcamelCase( _all, letter ) { 6 | return letter.toUpperCase(); 7 | } 8 | 9 | // Convert dashed to camelCase 10 | function camelCase( string ) { 11 | return string.replace( rdashAlpha, fcamelCase ); 12 | } 13 | 14 | export default camelCase; 15 | -------------------------------------------------------------------------------- /test/node_smoke_tests/document_missing.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require( "assert" ); 4 | const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ); 5 | const jQueryFactory = require( "../../dist/jquery.js" ); 6 | 7 | assert.throws( () => { 8 | jQueryFactory( {} ); 9 | }, /jQuery requires a window with a document/ ); 10 | 11 | ensureGlobalNotCreated( module.exports ); 12 | -------------------------------------------------------------------------------- /test/node_smoke_tests/lib/ensure_jquery.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require( "assert" ); 4 | 5 | // Check if the object we got is the jQuery object by invoking a basic API. 6 | const ensureJQuery = ( jQuery ) => { 7 | assert( /^jQuery/.test( jQuery.expando ), 8 | "jQuery.expando was not detected, the jQuery bootstrap process has failed" ); 9 | }; 10 | 11 | module.exports = ensureJQuery; 12 | -------------------------------------------------------------------------------- /src/event/ajax.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | import "../event.js"; 4 | 5 | // Attach a bunch of functions for handling common AJAX events 6 | jQuery.each( [ 7 | "ajaxStart", 8 | "ajaxStop", 9 | "ajaxComplete", 10 | "ajaxError", 11 | "ajaxSuccess", 12 | "ajaxSend" 13 | ], function( _i, type ) { 14 | jQuery.fn[ type ] = function( fn ) { 15 | return this.on( type, fn ); 16 | }; 17 | } ); 18 | -------------------------------------------------------------------------------- /src/traversing/var/dir.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../../core.js"; 2 | 3 | export default function( elem, dir, until ) { 4 | var matched = [], 5 | truncate = until !== undefined; 6 | 7 | while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) { 8 | if ( elem.nodeType === 1 ) { 9 | if ( truncate && jQuery( elem ).is( until ) ) { 10 | break; 11 | } 12 | matched.push( elem ); 13 | } 14 | } 15 | return matched; 16 | }; 17 | -------------------------------------------------------------------------------- /test/data/csp.include.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSP Test Page 6 | 7 | 8 | 9 | 10 | 11 | 12 |

CSP Test Page

13 | 14 | 15 | -------------------------------------------------------------------------------- /test/node_smoke_tests/document_passed.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const { JSDOM } = require( "jsdom" ); 4 | 5 | const { window } = new JSDOM( "" ); 6 | 7 | const ensureJQuery = require( "./lib/ensure_jquery" ); 8 | const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ); 9 | const jQuery = require( "../../dist/jquery.js" )( window ); 10 | 11 | ensureJQuery( jQuery ); 12 | ensureGlobalNotCreated( module.exports ); 13 | -------------------------------------------------------------------------------- /test/promises_aplus_adapters/deferred.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 | const deferred = jQuery.Deferred(); 11 | 12 | return { 13 | promise: deferred.promise(), 14 | resolve: deferred.resolve.bind( deferred ), 15 | reject: deferred.reject.bind( deferred ) 16 | }; 17 | }; 18 | -------------------------------------------------------------------------------- /src/manipulation/setGlobalEval.js: -------------------------------------------------------------------------------- 1 | import dataPriv from "../data/var/dataPriv.js"; 2 | 3 | // Mark scripts as having already been evaluated 4 | function setGlobalEval( elems, refElements ) { 5 | var i = 0, 6 | l = elems.length; 7 | 8 | for ( ; i < l; i++ ) { 9 | dataPriv.set( 10 | elems[ i ], 11 | "globalEval", 12 | !refElements || dataPriv.get( refElements[ i ], "globalEval" ) 13 | ); 14 | } 15 | } 16 | 17 | export default setGlobalEval; 18 | -------------------------------------------------------------------------------- /test/data/csp-nonce.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSP nonce Test Page 6 | 7 | 8 | 9 | 10 | 11 |

CSP nonce Test Page

12 | 13 | 14 | -------------------------------------------------------------------------------- /test/data/event/focusElem.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | .focus() (activeElement access #13393) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/css/cssCamelCase.js: -------------------------------------------------------------------------------- 1 | import camelCase from "../core/camelCase.js"; 2 | 3 | // Matches dashed string for camelizing 4 | var rmsPrefix = /^-ms-/; 5 | 6 | // Convert dashed to camelCase, handle vendor prefixes. 7 | // Used by the css & effects modules. 8 | // Support: IE <=9 - 11+, Edge 12 - 18+ 9 | // Microsoft forgot to hump their vendor prefix (#9572) 10 | function cssCamelCase( string ) { 11 | return camelCase( string.replace( rmsPrefix, "ms-" ) ); 12 | } 13 | 14 | export default cssCamelCase; 15 | -------------------------------------------------------------------------------- /test/data/css/cssWidthBeforeDocReady.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | 14 | 15 |
16 | 17 | 18 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /.github/lock.yml: -------------------------------------------------------------------------------- 1 | # Configuration for lock-threads - https://github.com/dessant/lock-threads 2 | 3 | # Number of days of inactivity before a closed issue or pull request is locked 4 | daysUntilLock: 180 5 | 6 | # Issues and pull requests with these labels will not be locked. Set to `[]` to disable 7 | exemptLabels: [] 8 | 9 | # Label to add before locking, such as `outdated`. Set to `false` to disable 10 | lockLabel: false 11 | 12 | # Comment to post before locking. Set to `false` to disable 13 | lockComment: false 14 | -------------------------------------------------------------------------------- /test/node_smoke_tests/document_present_originally.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const { JSDOM } = require( "jsdom" ); 4 | 5 | const { window } = new JSDOM( "" ); 6 | 7 | // Pretend the window is a global. 8 | global.window = window; 9 | 10 | const ensureJQuery = require( "./lib/ensure_jquery" ); 11 | const ensureGlobalNotCreated = require( "./lib/ensure_global_not_created" ); 12 | const jQuery = require( "../../dist/jquery.js" ); 13 | 14 | ensureJQuery( jQuery ); 15 | ensureGlobalNotCreated( module.exports, window ); 16 | -------------------------------------------------------------------------------- /src/selector/contains.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | // Note: an element does not contain itself 4 | jQuery.contains = function( a, b ) { 5 | var adown = a.nodeType === 9 ? a.documentElement : a, 6 | bup = b && b.parentNode; 7 | 8 | return a === bup || !!( bup && bup.nodeType === 1 && ( 9 | 10 | // Support: IE 9 - 11+ 11 | // IE doesn't have `contains` on SVG. 12 | adown.contains ? 13 | adown.contains( bup ) : 14 | a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 15 | ) ); 16 | }; 17 | -------------------------------------------------------------------------------- /test/data/csp-nonce-external.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSP nonce via jQuery.globalEval Test Page 6 | 7 | 8 | 9 | 10 | 11 |

CSP nonce for external script Test Page

12 | 13 | 14 | -------------------------------------------------------------------------------- /test/data/data/dataAttrs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IE11 onpageshow strangeness (#14894) 6 | 7 | 8 | 13 | 14 | 15 | Test for #14894 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/data/csp-nonce-globaleval.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSP nonce via jQuery.globalEval Test Page 6 | 7 | 8 | 9 | 10 | 11 |

CSP nonce via jQuery.globalEval Test Page

12 | 13 | 14 | -------------------------------------------------------------------------------- /test/data/event/onbeforeunload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 20 | 21 | -------------------------------------------------------------------------------- /src/css/var/swap.js: -------------------------------------------------------------------------------- 1 | // A method for quickly swapping in/out CSS properties to get correct calculations. 2 | export default function( elem, options, callback ) { 3 | var ret, name, 4 | old = {}; 5 | 6 | // Remember the old values, and insert the new ones 7 | for ( name in options ) { 8 | old[ name ] = elem.style[ name ]; 9 | elem.style[ name ] = options[ name ]; 10 | } 11 | 12 | ret = callback.call( elem ); 13 | 14 | // Revert the old values 15 | for ( name in options ) { 16 | elem.style[ name ] = old[ name ]; 17 | } 18 | 19 | return ret; 20 | }; 21 | -------------------------------------------------------------------------------- /test/data/core/jquery-iterability-transpiled.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery objects transpiled iterability test page 6 | 7 | 8 | 9 | 10 | 11 | 12 |

jQuery objects transpiled iterability test page

13 | 14 | 15 | -------------------------------------------------------------------------------- /test/data/event/triggerunload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.eslintrc-browser.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "jquery", 5 | 6 | "parserOptions": { 7 | "ecmaVersion": 5 8 | }, 9 | 10 | // The browser env is not enabled on purpose so that code takes 11 | // all browser-only globals from window instead of assuming 12 | // they're available as globals. This makes it possible to use 13 | // jQuery with tools like jsdom which provide a custom window 14 | // implementation. 15 | "env": {}, 16 | 17 | "globals": { 18 | "window": true 19 | }, 20 | 21 | "rules": { 22 | "strict": ["error", "function"] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/deferred/exceptionHook.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | import "../deferred.js"; 4 | 5 | // These usually indicate a programmer mistake during development, 6 | // warn about them ASAP rather than swallowing them by default. 7 | var rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/; 8 | 9 | jQuery.Deferred.exceptionHook = function( error, stack ) { 10 | 11 | if ( error && rerrorNames.test( error.name ) ) { 12 | window.console.warn( 13 | "jQuery.Deferred exception: " + error.message, 14 | error.stack, 15 | stack 16 | ); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /test/data/event/focusinCrossFrame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | focusin event cross-frame (#14180) 6 | 7 | 8 | 9 | 10 | 11 | 12 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/css/var/getStyles.js: -------------------------------------------------------------------------------- 1 | export default function( elem ) { 2 | 3 | // Support: IE <=11+ (trac-14150) 4 | // In IE popup's `window` is the opener window which makes `window.getComputedStyle( elem )` 5 | // break. Using `elem.ownerDocument.defaultView` avoids the issue. 6 | var view = elem.ownerDocument.defaultView; 7 | 8 | // `document.implementation.createHTMLDocument( "" )` has a `null` `defaultView` 9 | // property; check `defaultView` truthiness to fallback to window in such a case. 10 | if ( !view ) { 11 | view = window; 12 | } 13 | 14 | return view.getComputedStyle( elem ); 15 | }; 16 | -------------------------------------------------------------------------------- /test/node_smoke_tests/lib/ensure_global_not_created.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const assert = require( "assert" ); 4 | 5 | // Ensure the jQuery property on global/window/module.exports/etc. was not 6 | // created in a CommonJS environment. 7 | // `global` is always checked in addition to passed parameters. 8 | const ensureGlobalNotCreated = ( ...args ) => { 9 | [ ...args, global ].forEach( function( object ) { 10 | assert.strictEqual( object.jQuery, undefined, 11 | "A jQuery global was created in a CommonJS environment." ); 12 | } ); 13 | }; 14 | 15 | module.exports = ensureGlobalNotCreated; 16 | -------------------------------------------------------------------------------- /test/data/event/promiseReady.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test case for jQuery ticket #11470 6 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/ajax/parseXML.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | // Cross-browser xml parsing 4 | jQuery.parseXML = function( data ) { 5 | var xml; 6 | if ( !data || typeof data !== "string" ) { 7 | return null; 8 | } 9 | 10 | // Support: IE 9 - 11+ 11 | // IE throws on parseFromString with invalid input. 12 | try { 13 | xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" ); 14 | } catch ( e ) { 15 | xml = undefined; 16 | } 17 | 18 | if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) { 19 | jQuery.error( "Invalid XML: " + data ); 20 | } 21 | return xml; 22 | }; 23 | 24 | export default jQuery.parseXML; 25 | -------------------------------------------------------------------------------- /test/data/dimensions/documentLarge.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 12 | 13 | 14 |
15 | 16 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /test/data/core/onready.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | alias-masked DOM properties (#14074) 6 | 10 | 11 | 12 | 13 | 14 |
15 | 16 |
17 | 24 | 25 | -------------------------------------------------------------------------------- /test/data/core/aliased.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | alias-masked DOM properties (#14074) 6 | 12 | 13 | 14 | 15 | 16 |
17 | 18 |
19 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /test/data/css/cssWidthBrowserZoom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 18 | 19 | 20 |
21 | 22 | 23 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/queue/delay.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | import "../queue.js"; 4 | import "../effects.js"; // Delay is optional because of this dependency 5 | 6 | // Based off of the plugin by Clint Helfers, with permission. 7 | // https://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/ 8 | jQuery.fn.delay = function( time, type ) { 9 | time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time; 10 | type = type || "fx"; 11 | 12 | return this.queue( type, function( next, hooks ) { 13 | var timeout = window.setTimeout( next, time ); 14 | hooks.stop = function() { 15 | window.clearTimeout( timeout ); 16 | }; 17 | } ); 18 | }; 19 | -------------------------------------------------------------------------------- /test/data/selector/mixed_sort.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery selector - cross-window uniqueSort 6 | 7 | 8 | 9 | 10 | 11 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/core/isAttached.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import documentElement from "../var/documentElement.js"; 3 | 4 | import "../selector/contains.js"; // jQuery.contains 5 | 6 | var isAttached = function( elem ) { 7 | return jQuery.contains( elem.ownerDocument, elem ); 8 | }, 9 | composed = { composed: true }; 10 | 11 | // Support: IE 9 - 11+, Edge 12 - 18+ 12 | // Check attachment across shadow DOM boundaries when possible (gh-3504) 13 | if ( documentElement.getRootNode ) { 14 | isAttached = function( elem ) { 15 | return jQuery.contains( elem.ownerDocument, elem ) || 16 | elem.getRootNode( composed ) === elem.ownerDocument; 17 | }; 18 | } 19 | 20 | export default isAttached; 21 | -------------------------------------------------------------------------------- /test/integration/data/gh-1764-fullscreen-iframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Test for gh-1764 - test iframe 7 | 8 | 9 | 10 | 11 |
12 |
13 | 14 |
15 | 16 | 17 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - "8" 5 | - "10" 6 | - "12" 7 | - "13" 8 | env: 9 | - NPM_SCRIPT=test:browserless 10 | matrix: 11 | include: 12 | # Run browser tests only on one Node.js version to save time. 13 | - node_js: "12" 14 | env: 15 | - NPM_SCRIPT="test:browser" 16 | - BROWSERS="ChromeHeadless,FirefoxHeadless" 17 | addons: 18 | chrome: stable 19 | firefox: latest 20 | # Run tests on Firefox ESR as well. 21 | - node_js: "12" 22 | env: 23 | - NPM_SCRIPT="test:browser" 24 | - BROWSERS="FirefoxHeadless" 25 | addons: 26 | firefox: latest-esr 27 | script: 28 | - npm run $NPM_SCRIPT 29 | -------------------------------------------------------------------------------- /test/data/selector/cache.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery selector - cache 6 | 7 | 8 | 9 | 15 | 16 | 17 | 18 |
19 | Worlds collide 20 |
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, "
", "
" ], 10 | col: [ 2, "", "
" ], 11 | tr: [ 2, "", "
" ], 12 | td: [ 3, "", "
" ], 13 | 14 | _default: [ 0, "", "" ] 15 | }; 16 | 17 | wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; 18 | wrapMap.th = wrapMap.td; 19 | 20 | export default wrapMap; 21 | -------------------------------------------------------------------------------- /test/data/ajax/onunload.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | onunload ajax requests (#14379) 6 | 7 | 8 | 9 | 10 | 11 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/data/with_fries.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 1 14 | 15 | 16 | 17 | 18 | foo 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/selector/escapeSelector.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | // CSS string/identifier serialization 4 | // https://drafts.csswg.org/cssom/#common-serializing-idioms 5 | var rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\x80-\uFFFF\w-]/g; 6 | 7 | function fcssescape( ch, asCodePoint ) { 8 | if ( asCodePoint ) { 9 | 10 | // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER 11 | if ( ch === "\0" ) { 12 | return "\uFFFD"; 13 | } 14 | 15 | // Control characters and (dependent upon position) numbers get escaped as code points 16 | return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " "; 17 | } 18 | 19 | // Other potentially-special ASCII characters get backslash-escaped 20 | return "\\" + ch; 21 | } 22 | 23 | jQuery.escapeSelector = function( sel ) { 24 | return ( sel + "" ).replace( rcssescape, fcssescape ); 25 | }; 26 | -------------------------------------------------------------------------------- /test/data/event/interactiveReady.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test case for gh-2100 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 21 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /test/data/event/syncReady.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test case for jQuery ticket #10067 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 21 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /test/data/support/bodyBackground.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 17 | 18 | 19 |
20 | 21 | 22 | 23 |
24 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "../.eslintrc-browser.json", 5 | 6 | "parserOptions": { 7 | "ecmaVersion": 2015, 8 | "sourceType": "module" 9 | }, 10 | 11 | "overrides": [ 12 | { 13 | "files": "wrapper.js", 14 | "parserOptions": { 15 | "ecmaVersion": 5, 16 | "sourceType": "script" 17 | }, 18 | "rules": { 19 | "no-unused-vars": "off" 20 | }, 21 | "globals": { 22 | "jQuery": false, 23 | "module": true 24 | } 25 | }, 26 | 27 | { 28 | "files": "exports/amd.js", 29 | "globals": { 30 | "define": false 31 | } 32 | }, 33 | 34 | { 35 | "files": "core.js", 36 | "globals": { 37 | 38 | // Defining Symbol globally would create a danger of using 39 | // it unguarded in another place, it seems safer to define 40 | // it only for this module. 41 | "Symbol": false 42 | } 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | ### Description ### 21 | 22 | 23 | ### Link to test case ### 24 | 25 | -------------------------------------------------------------------------------- /src/css/finalPropName.js: -------------------------------------------------------------------------------- 1 | import document from "../var/document.js"; 2 | 3 | var cssPrefixes = [ "Webkit", "Moz", "ms" ], 4 | emptyStyle = document.createElement( "div" ).style, 5 | vendorProps = {}; 6 | 7 | // Return a vendor-prefixed property or undefined 8 | function vendorPropName( name ) { 9 | 10 | // Check for vendor prefixed names 11 | var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), 12 | i = cssPrefixes.length; 13 | 14 | while ( i-- ) { 15 | name = cssPrefixes[ i ] + capName; 16 | if ( name in emptyStyle ) { 17 | return name; 18 | } 19 | } 20 | } 21 | 22 | // Return a potentially-mapped vendor prefixed property 23 | function finalPropName( name ) { 24 | var final = vendorProps[ name ]; 25 | 26 | if ( final ) { 27 | return final; 28 | } 29 | if ( name in emptyStyle ) { 30 | return name; 31 | } 32 | return vendorProps[ name ] = vendorPropName( name ) || name; 33 | } 34 | 35 | export default finalPropName; 36 | -------------------------------------------------------------------------------- /test/integration/gh-1764-fullscreen.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Test for gh-1764 7 | 8 | 20 | 21 | 22 | 23 |
24 |
25 | 26 |
27 | 28 | 29 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /test/data/core/dynamic_ready.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /test/integration/gh-2343-ie-radio-click.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Test for gh-2343 (IE11) 7 | 8 | 15 | 16 | 17 | 18 | 19 |

Test for gh-2343 (IE11)

20 |

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 |
26 | 0 27 | 1 28 | 2 29 |
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 |

Click the white box to move the marker to it.

35 | 36 | 37 | -------------------------------------------------------------------------------- /test/data/offset/table.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | table 7 | 13 | 14 | 15 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
th-1th-2th-3
td-1td-2td-3
42 |
43 |

Click the white box to move the marker to it.

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 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |

Click the white box to move the marker to it.

42 | 43 | 44 | -------------------------------------------------------------------------------- /test/data/offset/relative.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | relative 7 | 14 | 15 | 16 | 27 | 28 | 29 |
30 |
31 |
32 |

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.

33 | 34 | 35 | -------------------------------------------------------------------------------- /src/css/isAutoPx.js: -------------------------------------------------------------------------------- 1 | var ralphaStart = /^[a-z]/, 2 | 3 | // The regex visualized: 4 | // 5 | // /----------\ 6 | // | | /-------\ 7 | // | / Top \ | | | 8 | // /--- Border ---+-| Right |-+---+- Width -+---\ 9 | // | | Bottom | | 10 | // | \ Left / | 11 | // | | 12 | // | /----------\ | 13 | // | /-------------\ | | |- END 14 | // | | | | / Top \ | | 15 | // | | / Margin \ | | | Right | | | 16 | // |---------+-| |-+---+-| Bottom |-+----| 17 | // | \ Padding / \ Left / | 18 | // BEGIN -| | 19 | // | /---------\ | 20 | // | | | | 21 | // | | / Min \ | / Width \ | 22 | // \--------------+-| |-+---| |---/ 23 | // \ Max / \ Height / 24 | rautoPx = /^(?:Border(?:Top|Right|Bottom|Left)?(?:Width|)|(?:Margin|Padding)?(?:Top|Right|Bottom|Left)?|(?:Min|Max)?(?:Width|Height))$/; 25 | 26 | function isAutoPx( prop ) { 27 | 28 | // The first test is used to ensure that: 29 | // 1. The prop starts with a lowercase letter (as we uppercase it for the second regex). 30 | // 2. The prop is not empty. 31 | return ralphaStart.test( prop ) && 32 | rautoPx.test( prop[ 0 ].toUpperCase() + prop.slice( 1 ) ); 33 | }; 34 | 35 | export default isAutoPx; 36 | -------------------------------------------------------------------------------- /src/wrap.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | 3 | import "./core/init.js"; 4 | import "./manipulation.js"; // clone 5 | import "./traversing.js"; // parent, contents 6 | 7 | jQuery.fn.extend( { 8 | wrapAll: function( html ) { 9 | var wrap; 10 | 11 | if ( this[ 0 ] ) { 12 | if ( typeof html === "function" ) { 13 | html = html.call( this[ 0 ] ); 14 | } 15 | 16 | // The elements to wrap the target around 17 | wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true ); 18 | 19 | if ( this[ 0 ].parentNode ) { 20 | wrap.insertBefore( this[ 0 ] ); 21 | } 22 | 23 | wrap.map( function() { 24 | var elem = this; 25 | 26 | while ( elem.firstElementChild ) { 27 | elem = elem.firstElementChild; 28 | } 29 | 30 | return elem; 31 | } ).append( this ); 32 | } 33 | 34 | return this; 35 | }, 36 | 37 | wrapInner: function( html ) { 38 | if ( typeof html === "function" ) { 39 | return this.each( function( i ) { 40 | jQuery( this ).wrapInner( html.call( this, i ) ); 41 | } ); 42 | } 43 | 44 | return this.each( function() { 45 | var self = jQuery( this ), 46 | contents = self.contents(); 47 | 48 | if ( contents.length ) { 49 | contents.wrapAll( html ); 50 | 51 | } else { 52 | self.append( html ); 53 | } 54 | } ); 55 | }, 56 | 57 | wrap: function( html ) { 58 | var htmlIsFunction = typeof html === "function"; 59 | 60 | return this.each( function( i ) { 61 | jQuery( this ).wrapAll( htmlIsFunction ? html.call( this, i ) : html ); 62 | } ); 63 | }, 64 | 65 | unwrap: function( selector ) { 66 | this.parent( selector ).not( "body" ).each( function() { 67 | jQuery( this ).replaceWith( this.childNodes ); 68 | } ); 69 | return this; 70 | } 71 | } ); 72 | 73 | export default jQuery; 74 | -------------------------------------------------------------------------------- /test/karma.debug.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %X_UA_COMPATIBLE% 5 | DEBUG 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 28 | %SCRIPTS% 29 | 30 | 31 | 32 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /test/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "extends": "../.eslintrc-browser.json", 5 | 6 | "env": { 7 | 8 | // In source the browser env is not enabled but unit tests rely on them 9 | // too much and we don't run them in non-browser environments anyway. 10 | "browser": true 11 | }, 12 | 13 | "globals": { 14 | "require": false, 15 | "Promise": false, 16 | "Symbol": false, 17 | "QUnit": false, 18 | "ajaxTest": false, 19 | "testIframe": false, 20 | "createDashboardXML": false, 21 | "createWithFriesXML": false, 22 | "createXMLFragment": false, 23 | "moduleTeardown": false, 24 | "url": false, 25 | "q": false, 26 | "jQuery": true, 27 | "sinon": true, 28 | "amdDefined": true, 29 | "fireNative": true, 30 | "Globals": true, 31 | "hasPHP": true, 32 | "isLocal": true, 33 | "supportjQuery": true, 34 | "originaljQuery": true, 35 | "$": true, 36 | "original$": true, 37 | "baseURL": true, 38 | "externalHost": true 39 | }, 40 | 41 | "rules": { 42 | // See https://github.com/eslint/eslint/issues/2342 43 | "no-unused-vars": "off", 44 | 45 | // Too many errors 46 | "max-len": "off", 47 | "brace-style": "off", 48 | "key-spacing": "off", 49 | "camelcase": "off", 50 | "strict": "off", 51 | 52 | // Not really too many - waiting for autofix features for these rules 53 | "lines-around-comment": "off", 54 | "dot-notation": "off" 55 | }, 56 | 57 | "overrides": [ 58 | { 59 | "files": [ 60 | "data/core/jquery-iterability-transpiled-es6.js", 61 | "data/testinit-jsdom.js" 62 | ], 63 | "parserOptions": { 64 | "ecmaVersion": 2015 65 | } 66 | }, 67 | 68 | { 69 | "files": [ 70 | "jquery.js", 71 | "data/testinit.js" 72 | ], 73 | "parserOptions": { 74 | "ecmaVersion": 2020 75 | } 76 | } 77 | ] 78 | } 79 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery Test Suite 6 | 7 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 36 | 37 | 38 | 39 |
40 | 41 | 42 | 43 | 44 |
45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/ajax/script.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import document from "../var/document.js"; 3 | 4 | import "../ajax.js"; 5 | 6 | // Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432) 7 | jQuery.ajaxPrefilter( function( s ) { 8 | if ( s.crossDomain ) { 9 | s.contents.script = false; 10 | } 11 | } ); 12 | 13 | // Install script dataType 14 | jQuery.ajaxSetup( { 15 | accepts: { 16 | script: "text/javascript, application/javascript, " + 17 | "application/ecmascript, application/x-ecmascript" 18 | }, 19 | contents: { 20 | script: /\b(?:java|ecma)script\b/ 21 | }, 22 | converters: { 23 | "text script": function( text ) { 24 | jQuery.globalEval( text ); 25 | return text; 26 | } 27 | } 28 | } ); 29 | 30 | // Handle cache's special case and crossDomain 31 | jQuery.ajaxPrefilter( "script", function( s ) { 32 | if ( s.cache === undefined ) { 33 | s.cache = false; 34 | } 35 | if ( s.crossDomain ) { 36 | s.type = "GET"; 37 | } 38 | } ); 39 | 40 | // Bind script tag hack transport 41 | jQuery.ajaxTransport( "script", function( s ) { 42 | 43 | // This transport only deals with cross domain or forced-by-attrs requests 44 | if ( s.crossDomain || s.scriptAttrs ) { 45 | var script, callback; 46 | return { 47 | send: function( _, complete ) { 48 | script = jQuery( " 19 | 36 | 37 | 38 |

39 | jQuery Network Error Test for Firefox 40 |

41 |
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 |
  1. 52 | make sure you accessed this page through a web server, 53 |
  2. 54 |
  3. 55 | stop the web server, 56 |
  4. 57 |
  5. 58 | open the console, 59 |
  6. 60 |
  7. 61 | click this 62 | 63 | , 64 |
  8. 65 |
  9. 66 | wait for both requests to fail. 67 |
  10. 68 |
69 |
70 | Test passes if you get two log lines: 71 | 79 |
80 |
81 | Test fails if the browser notifies an exception. 82 |
83 | 84 | 85 | -------------------------------------------------------------------------------- /src/dimensions.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | import access from "./core/access.js"; 3 | import isWindow from "./var/isWindow.js"; 4 | 5 | import "./css.js"; 6 | 7 | // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods 8 | jQuery.each( { Height: "height", Width: "width" }, function( name, type ) { 9 | jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, 10 | function( defaultExtra, funcName ) { 11 | 12 | // Margin is only for outerHeight, outerWidth 13 | jQuery.fn[ funcName ] = function( margin, value ) { 14 | var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ), 15 | extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" ); 16 | 17 | return access( this, function( elem, type, value ) { 18 | var doc; 19 | 20 | if ( isWindow( elem ) ) { 21 | 22 | // $( window ).outerWidth/Height return w/h including scrollbars (gh-1729) 23 | return funcName.indexOf( "outer" ) === 0 ? 24 | elem[ "inner" + name ] : 25 | elem.document.documentElement[ "client" + name ]; 26 | } 27 | 28 | // Get document width or height 29 | if ( elem.nodeType === 9 ) { 30 | doc = elem.documentElement; 31 | 32 | // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height], 33 | // whichever is greatest 34 | return Math.max( 35 | elem.body[ "scroll" + name ], doc[ "scroll" + name ], 36 | elem.body[ "offset" + name ], doc[ "offset" + name ], 37 | doc[ "client" + name ] 38 | ); 39 | } 40 | 41 | return value === undefined ? 42 | 43 | // Get width or height on the element, requesting but not forcing parseFloat 44 | jQuery.css( elem, type, extra ) : 45 | 46 | // Set width or height on the element 47 | jQuery.style( elem, type, value, extra ); 48 | }, type, chainable ? margin : undefined, chainable ); 49 | }; 50 | } ); 51 | } ); 52 | 53 | export default jQuery; 54 | -------------------------------------------------------------------------------- /src/deprecated.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | import slice from "./var/slice.js"; 3 | import trim from "./var/trim.js"; 4 | 5 | import "./event/alias.js"; 6 | 7 | jQuery.fn.extend( { 8 | 9 | bind: function( types, data, fn ) { 10 | return this.on( types, null, data, fn ); 11 | }, 12 | unbind: function( types, fn ) { 13 | return this.off( types, null, fn ); 14 | }, 15 | 16 | delegate: function( selector, types, data, fn ) { 17 | return this.on( types, selector, data, fn ); 18 | }, 19 | undelegate: function( selector, types, fn ) { 20 | 21 | // ( namespace ) or ( selector, types [, fn] ) 22 | return arguments.length === 1 ? 23 | this.off( selector, "**" ) : 24 | this.off( types, selector || "**", fn ); 25 | } 26 | } ); 27 | 28 | // Bind a function to a context, optionally partially applying any 29 | // arguments. 30 | // jQuery.proxy is deprecated to promote standards (specifically Function#bind) 31 | // However, it is not slated for removal any time soon 32 | jQuery.proxy = function( fn, context ) { 33 | var tmp, args, proxy; 34 | 35 | if ( typeof context === "string" ) { 36 | tmp = fn[ context ]; 37 | context = fn; 38 | fn = tmp; 39 | } 40 | 41 | // Quick check to determine if target is callable, in the spec 42 | // this throws a TypeError, but we will just return undefined. 43 | if ( typeof fn !== "function" ) { 44 | return undefined; 45 | } 46 | 47 | // Simulated bind 48 | args = slice.call( arguments, 2 ); 49 | proxy = function() { 50 | return fn.apply( context || this, args.concat( slice.call( arguments ) ) ); 51 | }; 52 | 53 | // Set the guid of unique handler to the same of original handler, so it can be removed 54 | proxy.guid = fn.guid = fn.guid || jQuery.guid++; 55 | 56 | return proxy; 57 | }; 58 | 59 | jQuery.holdReady = function( hold ) { 60 | if ( hold ) { 61 | jQuery.readyWait++; 62 | } else { 63 | jQuery.ready( true ); 64 | } 65 | }; 66 | 67 | jQuery.trim = function( text ) { 68 | return text == null ? "" : trim.call( text ); 69 | }; 70 | -------------------------------------------------------------------------------- /test/data/offset/absolute.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | absolute 7 | 18 | 19 | 20 | 31 | 32 | 33 |
absolute-1 34 |
absolute-1-1 35 |
absolute-1-1-1
36 |
37 |
38 |
absolute-2
39 |
Has absolute position but no values set for the location ('auto').
40 |
41 |

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 | 43 | 44 | -------------------------------------------------------------------------------- /test/data/readywait.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | jQuery.holdReady Test 11 | 12 | 17 | 18 | 19 | 20 | 22 | 23 | 40 | 41 | 42 |

43 | jQuery.holdReady Test 44 |

45 |

46 | This is a test page for jQuery.readyWait and jQuery.holdReady, 47 | see 48 | #6781 49 | and 50 | #8803. 51 |

52 |

53 | Test for jQuery.holdReady, which can be used 54 | by plugins and other scripts to indicate something 55 | important to the page is still loading and needs 56 | to block the DOM ready callbacks that are registered 57 | with jQuery. 58 |

59 |

60 | Script loaders are the most likely kind of script 61 | to use jQuery.holdReady, but it could be used by 62 | other things like a script that loads a CSS file 63 | and wants to pause the DOM ready callbacks. 64 |

65 |

66 | Expected Result: The text 67 | It Worked! 68 | appears below after about 2 seconds. 69 |

70 |

71 | If there is an error in the console, 72 | or the text does not show up, then the test failed. 73 |

74 |
75 | 76 | 77 | -------------------------------------------------------------------------------- /src/ajax/load.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import stripAndCollapse from "../core/stripAndCollapse.js"; 3 | 4 | import "../core/parseHTML.js"; 5 | import "../ajax.js"; 6 | import "../traversing.js"; 7 | import "../manipulation.js"; 8 | import "../selector.js"; 9 | 10 | /** 11 | * Load a url into a page 12 | */ 13 | jQuery.fn.load = function( url, params, callback ) { 14 | var selector, type, response, 15 | self = this, 16 | off = url.indexOf( " " ); 17 | 18 | if ( off > -1 ) { 19 | selector = stripAndCollapse( url.slice( off ) ); 20 | url = url.slice( 0, off ); 21 | } 22 | 23 | // If it's a function 24 | if ( typeof params === "function" ) { 25 | 26 | // We assume that it's the callback 27 | callback = params; 28 | params = undefined; 29 | 30 | // Otherwise, build a param string 31 | } else if ( params && typeof params === "object" ) { 32 | type = "POST"; 33 | } 34 | 35 | // If we have elements to modify, make the request 36 | if ( self.length > 0 ) { 37 | jQuery.ajax( { 38 | url: url, 39 | 40 | // If "type" variable is undefined, then "GET" method will be used. 41 | // Make value of this field explicit since 42 | // user can override it through ajaxSetup method 43 | type: type || "GET", 44 | dataType: "html", 45 | data: params 46 | } ).done( function( responseText ) { 47 | 48 | // Save response for use in complete callback 49 | response = arguments; 50 | 51 | self.html( selector ? 52 | 53 | // If a selector was specified, locate the right elements in a dummy div 54 | // Exclude scripts to avoid IE 'Permission Denied' errors 55 | jQuery( "
" ).append( jQuery.parseHTML( responseText ) ).find( selector ) : 56 | 57 | // Otherwise use the full result 58 | responseText ); 59 | 60 | // If the request succeeds, this function gets "data", "status", "jqXHR" 61 | // but they are ignored because response was set above. 62 | // If it fails, this function gets "jqXHR", "status", "error" 63 | } ).always( callback && function( jqXHR, status ) { 64 | self.each( function() { 65 | callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] ); 66 | } ); 67 | } ); 68 | } 69 | 70 | return this; 71 | }; 72 | -------------------------------------------------------------------------------- /test/localfile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery Local File Test 6 | 7 | 8 | 12 | 13 | 14 |

jQuery Local File Test

15 |

16 | Introduction 17 |

18 | 29 |

30 | Results 31 |

32 | 44 |

45 | Logs: 46 |

47 | 49 | 75 | 76 | -------------------------------------------------------------------------------- /src/core/ready.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import document from "../var/document.js"; 3 | 4 | import "../core/readyException.js"; 5 | import "../deferred.js"; 6 | 7 | // The deferred used on DOM ready 8 | var readyList = jQuery.Deferred(); 9 | 10 | jQuery.fn.ready = function( fn ) { 11 | 12 | readyList 13 | .then( fn ) 14 | 15 | // Wrap jQuery.readyException in a function so that the lookup 16 | // happens at the time of error handling instead of callback 17 | // registration. 18 | .catch( function( error ) { 19 | jQuery.readyException( error ); 20 | } ); 21 | 22 | return this; 23 | }; 24 | 25 | jQuery.extend( { 26 | 27 | // Is the DOM ready to be used? Set to true once it occurs. 28 | isReady: false, 29 | 30 | // A counter to track how many items to wait for before 31 | // the ready event fires. See #6781 32 | readyWait: 1, 33 | 34 | // Handle when the DOM is ready 35 | ready: function( wait ) { 36 | 37 | // Abort if there are pending holds or we're already ready 38 | if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { 39 | return; 40 | } 41 | 42 | // Remember that the DOM is ready 43 | jQuery.isReady = true; 44 | 45 | // If a normal DOM Ready event fired, decrement, and wait if need be 46 | if ( wait !== true && --jQuery.readyWait > 0 ) { 47 | return; 48 | } 49 | 50 | // If there are functions bound, to execute 51 | readyList.resolveWith( document, [ jQuery ] ); 52 | } 53 | } ); 54 | 55 | jQuery.ready.then = readyList.then; 56 | 57 | // The ready event handler and self cleanup method 58 | function completed() { 59 | document.removeEventListener( "DOMContentLoaded", completed ); 60 | window.removeEventListener( "load", completed ); 61 | jQuery.ready(); 62 | } 63 | 64 | // Catch cases where $(document).ready() is called 65 | // after the browser event has already occurred. 66 | if ( document.readyState !== "loading" ) { 67 | 68 | // Handle it asynchronously to allow scripts the opportunity to delay ready 69 | window.setTimeout( jQuery.ready ); 70 | 71 | } else { 72 | 73 | // Use the handy event callback 74 | document.addEventListener( "DOMContentLoaded", completed ); 75 | 76 | // A fallback to window.onload, that will always work 77 | window.addEventListener( "load", completed ); 78 | } 79 | -------------------------------------------------------------------------------- /src/css/adjustCSS.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import isAutoPx from "./isAutoPx.js"; 3 | import rcssNum from "../var/rcssNum.js"; 4 | 5 | function adjustCSS( elem, prop, valueParts, tween ) { 6 | var adjusted, scale, 7 | maxIterations = 20, 8 | currentValue = tween ? 9 | function() { 10 | return tween.cur(); 11 | } : 12 | function() { 13 | return jQuery.css( elem, prop, "" ); 14 | }, 15 | initial = currentValue(), 16 | unit = valueParts && valueParts[ 3 ] || ( isAutoPx( prop ) ? "px" : "" ), 17 | 18 | // Starting value computation is required for potential unit mismatches 19 | initialInUnit = elem.nodeType && 20 | ( !isAutoPx( prop ) || unit !== "px" && +initial ) && 21 | rcssNum.exec( jQuery.css( elem, prop ) ); 22 | 23 | if ( initialInUnit && initialInUnit[ 3 ] !== unit ) { 24 | 25 | // Support: Firefox <=54 - 66+ 26 | // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144) 27 | initial = initial / 2; 28 | 29 | // Trust units reported by jQuery.css 30 | unit = unit || initialInUnit[ 3 ]; 31 | 32 | // Iteratively approximate from a nonzero starting point 33 | initialInUnit = +initial || 1; 34 | 35 | while ( maxIterations-- ) { 36 | 37 | // Evaluate and update our best guess (doubling guesses that zero out). 38 | // Finish if the scale equals or crosses 1 (making the old*new product non-positive). 39 | jQuery.style( elem, prop, initialInUnit + unit ); 40 | if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) { 41 | maxIterations = 0; 42 | } 43 | initialInUnit = initialInUnit / scale; 44 | 45 | } 46 | 47 | initialInUnit = initialInUnit * 2; 48 | jQuery.style( elem, prop, initialInUnit + unit ); 49 | 50 | // Make sure we update the tween properties later on 51 | valueParts = valueParts || []; 52 | } 53 | 54 | if ( valueParts ) { 55 | initialInUnit = +initialInUnit || +initial || 0; 56 | 57 | // Apply relative offset (+=/-=) if specified 58 | adjusted = valueParts[ 1 ] ? 59 | initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] : 60 | +valueParts[ 2 ]; 61 | if ( tween ) { 62 | tween.unit = unit; 63 | tween.start = initialInUnit; 64 | tween.end = adjusted; 65 | } 66 | } 67 | return adjusted; 68 | } 69 | 70 | export default adjustCSS; 71 | -------------------------------------------------------------------------------- /test/jquery.js: -------------------------------------------------------------------------------- 1 | // Use the right jQuery source on the test page (and iframes) 2 | ( function() { 3 | /* global loadTests: false */ 4 | 5 | var dynamicImportSource, 6 | FILEPATH = "/test/jquery.js", 7 | activeScript = [].slice.call( document.getElementsByTagName( "script" ), -1 )[ 0 ], 8 | parentUrl = activeScript && activeScript.src ? 9 | activeScript.src.replace( /[?#].*/, "" ) + FILEPATH.replace( /[^/]+/g, ".." ) + "/" : 10 | "../", 11 | QUnit = window.QUnit || parent.QUnit, 12 | require = window.require || parent.require, 13 | 14 | // Default to unminified jQuery for directly-opened iframes 15 | urlParams = QUnit ? 16 | QUnit.urlParams : 17 | { dev: true }, 18 | src = urlParams.dev ? 19 | "dist/jquery.js" : 20 | "dist/jquery.min.js"; 21 | 22 | // Define configuration parameters controlling how jQuery is loaded 23 | if ( QUnit ) { 24 | 25 | // ES modules loading is asynchronous and incompatible with synchronous 26 | // test loading in Karma. 27 | if ( !window.__karma__ ) { 28 | QUnit.config.urlConfig.push( { 29 | id: "esmodules", 30 | label: "Load as modules", 31 | tooltip: "Load a relevant jQuery module file (and its dependencies)" 32 | } ); 33 | } 34 | 35 | QUnit.config.urlConfig.push( { 36 | id: "dev", 37 | label: "Load unminified", 38 | tooltip: "Load the development (unminified) jQuery file" 39 | } ); 40 | } 41 | 42 | // Honor AMD loading on the main window (detected by seeing QUnit on it). 43 | // This doesn't apply to iframes because they synchronously expect jQuery to be there. 44 | if ( urlParams.esmodules && window.QUnit ) { 45 | 46 | // Support: IE 11+, Edge 12 - 18+ 47 | // IE/Edge don't support the dynamic import syntax so they'd crash 48 | // with a SyntaxError here. 49 | dynamicImportSource = "" + 50 | "import( `${ parentUrl }src/jquery.js` ).then( ( { default: jQuery } ) => {\n" + 51 | " window.jQuery = jQuery;\n" + 52 | " if ( typeof loadTests === \"function\" ) {\n" + 53 | " // Include tests if specified\n" + 54 | " loadTests();\n" + 55 | " }\n" + 56 | "} );"; 57 | 58 | eval( dynamicImportSource ); 59 | 60 | // Otherwise, load synchronously 61 | } else { 62 | document.write( " 8 | 9 | 12 | 13 | 21 | 22 | 23 | 25 | 26 |
28 | 29 |
33 | 39 | 41 |
42 | 43 | 44 | 46 |
47 | 48 | 51 | 52 | 54 | 55 |
    57 | 58 |
    60 | 61 |
    63 | 64 | 75 | 76 | 78 | 79 | 84 | 85 | 86 | 89 | 90 | 91 | 95 | 96 | 102 | 103 |
    105 |
    Term
    This is the first definition in compact format.
    106 |
    Term
    This is the second definition in compact format.
    107 |
    108 | 109 | 111 | 112 | Scrolling text (non-standard) 115 | 116 | 117 | -------------------------------------------------------------------------------- /src/traversing/findFilter.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import indexOf from "../var/indexOf.js"; 3 | import rneedsContext from "./var/rneedsContext.js"; 4 | 5 | import "../selector.js"; 6 | 7 | // Implement the identical functionality for filter and not 8 | function winnow( elements, qualifier, not ) { 9 | if ( typeof qualifier === "function" ) { 10 | return jQuery.grep( elements, function( elem, i ) { 11 | return !!qualifier.call( elem, i, elem ) !== not; 12 | } ); 13 | } 14 | 15 | // Single element 16 | if ( qualifier.nodeType ) { 17 | return jQuery.grep( elements, function( elem ) { 18 | return ( elem === qualifier ) !== not; 19 | } ); 20 | } 21 | 22 | // Arraylike of elements (jQuery, arguments, Array) 23 | if ( typeof qualifier !== "string" ) { 24 | return jQuery.grep( elements, function( elem ) { 25 | return ( indexOf.call( qualifier, elem ) > -1 ) !== not; 26 | } ); 27 | } 28 | 29 | // Filtered directly for both simple and complex selectors 30 | return jQuery.filter( qualifier, elements, not ); 31 | } 32 | 33 | jQuery.filter = function( expr, elems, not ) { 34 | var elem = elems[ 0 ]; 35 | 36 | if ( not ) { 37 | expr = ":not(" + expr + ")"; 38 | } 39 | 40 | if ( elems.length === 1 && elem.nodeType === 1 ) { 41 | return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : []; 42 | } 43 | 44 | return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { 45 | return elem.nodeType === 1; 46 | } ) ); 47 | }; 48 | 49 | jQuery.fn.extend( { 50 | find: function( selector ) { 51 | var i, ret, 52 | len = this.length, 53 | self = this; 54 | 55 | if ( typeof selector !== "string" ) { 56 | return this.pushStack( jQuery( selector ).filter( function() { 57 | for ( i = 0; i < len; i++ ) { 58 | if ( jQuery.contains( self[ i ], this ) ) { 59 | return true; 60 | } 61 | } 62 | } ) ); 63 | } 64 | 65 | ret = this.pushStack( [] ); 66 | 67 | for ( i = 0; i < len; i++ ) { 68 | jQuery.find( selector, self[ i ], ret ); 69 | } 70 | 71 | return len > 1 ? jQuery.uniqueSort( ret ) : ret; 72 | }, 73 | filter: function( selector ) { 74 | return this.pushStack( winnow( this, selector || [], false ) ); 75 | }, 76 | not: function( selector ) { 77 | return this.pushStack( winnow( this, selector || [], true ) ); 78 | }, 79 | is: function( selector ) { 80 | return !!winnow( 81 | this, 82 | 83 | // If this is a positional/relative selector, check membership in the returned set 84 | // so $("p:first").is("p:last") won't return true for a doc with two "p". 85 | typeof selector === "string" && rneedsContext.test( selector ) ? 86 | jQuery( selector ) : 87 | selector || [], 88 | false 89 | ).length; 90 | } 91 | } ); 92 | -------------------------------------------------------------------------------- /src/manipulation/buildFragment.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import toType from "../core/toType.js"; 3 | import isAttached from "../core/isAttached.js"; 4 | import rtagName from "./var/rtagName.js"; 5 | import rscriptType from "./var/rscriptType.js"; 6 | import wrapMap from "./wrapMap.js"; 7 | import getAll from "./getAll.js"; 8 | import setGlobalEval from "./setGlobalEval.js"; 9 | 10 | var rhtml = /<|&#?\w+;/; 11 | 12 | function buildFragment( elems, context, scripts, selection, ignored ) { 13 | var elem, tmp, tag, wrap, attached, j, 14 | fragment = context.createDocumentFragment(), 15 | nodes = [], 16 | i = 0, 17 | l = elems.length; 18 | 19 | for ( ; i < l; i++ ) { 20 | elem = elems[ i ]; 21 | 22 | if ( elem || elem === 0 ) { 23 | 24 | // Add nodes directly 25 | if ( toType( elem ) === "object" ) { 26 | jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem ); 27 | 28 | // Convert non-html into a text node 29 | } else if ( !rhtml.test( elem ) ) { 30 | nodes.push( context.createTextNode( elem ) ); 31 | 32 | // Convert html into DOM nodes 33 | } else { 34 | tmp = tmp || fragment.appendChild( context.createElement( "div" ) ); 35 | 36 | // Deserialize a standard representation 37 | tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase(); 38 | wrap = wrapMap[ tag ] || wrapMap._default; 39 | tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ]; 40 | 41 | // Descend through wrappers to the right content 42 | j = wrap[ 0 ]; 43 | while ( j-- ) { 44 | tmp = tmp.lastChild; 45 | } 46 | 47 | jQuery.merge( nodes, tmp.childNodes ); 48 | 49 | // Remember the top-level container 50 | tmp = fragment.firstChild; 51 | 52 | // Ensure the created nodes are orphaned (#12392) 53 | tmp.textContent = ""; 54 | } 55 | } 56 | } 57 | 58 | // Remove wrapper from fragment 59 | fragment.textContent = ""; 60 | 61 | i = 0; 62 | while ( ( elem = nodes[ i++ ] ) ) { 63 | 64 | // Skip elements already in the context collection (trac-4087) 65 | if ( selection && jQuery.inArray( elem, selection ) > -1 ) { 66 | if ( ignored ) { 67 | ignored.push( elem ); 68 | } 69 | continue; 70 | } 71 | 72 | attached = isAttached( elem ); 73 | 74 | // Append to fragment 75 | tmp = getAll( fragment.appendChild( elem ), "script" ); 76 | 77 | // Preserve script evaluation history 78 | if ( attached ) { 79 | setGlobalEval( tmp ); 80 | } 81 | 82 | // Capture executables 83 | if ( scripts ) { 84 | j = 0; 85 | while ( ( elem = tmp[ j++ ] ) ) { 86 | if ( rscriptType.test( elem.type || "" ) ) { 87 | scripts.push( elem ); 88 | } 89 | } 90 | } 91 | } 92 | 93 | return fragment; 94 | } 95 | 96 | export default buildFragment; 97 | -------------------------------------------------------------------------------- /src/css/showHide.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import dataPriv from "../data/var/dataPriv.js"; 3 | import isHiddenWithinTree from "../css/var/isHiddenWithinTree.js"; 4 | 5 | var defaultDisplayMap = {}; 6 | 7 | function getDefaultDisplay( elem ) { 8 | var temp, 9 | doc = elem.ownerDocument, 10 | nodeName = elem.nodeName, 11 | display = defaultDisplayMap[ nodeName ]; 12 | 13 | if ( display ) { 14 | return display; 15 | } 16 | 17 | temp = doc.body.appendChild( doc.createElement( nodeName ) ); 18 | display = jQuery.css( temp, "display" ); 19 | 20 | temp.parentNode.removeChild( temp ); 21 | 22 | if ( display === "none" ) { 23 | display = "block"; 24 | } 25 | defaultDisplayMap[ nodeName ] = display; 26 | 27 | return display; 28 | } 29 | 30 | function showHide( elements, show ) { 31 | var display, elem, 32 | values = [], 33 | index = 0, 34 | length = elements.length; 35 | 36 | // Determine new display value for elements that need to change 37 | for ( ; index < length; index++ ) { 38 | elem = elements[ index ]; 39 | if ( !elem.style ) { 40 | continue; 41 | } 42 | 43 | display = elem.style.display; 44 | if ( show ) { 45 | 46 | // Since we force visibility upon cascade-hidden elements, an immediate (and slow) 47 | // check is required in this first loop unless we have a nonempty display value (either 48 | // inline or about-to-be-restored) 49 | if ( display === "none" ) { 50 | values[ index ] = dataPriv.get( elem, "display" ) || null; 51 | if ( !values[ index ] ) { 52 | elem.style.display = ""; 53 | } 54 | } 55 | if ( elem.style.display === "" && isHiddenWithinTree( elem ) ) { 56 | values[ index ] = getDefaultDisplay( elem ); 57 | } 58 | } else { 59 | if ( display !== "none" ) { 60 | values[ index ] = "none"; 61 | 62 | // Remember what we're overwriting 63 | dataPriv.set( elem, "display", display ); 64 | } 65 | } 66 | } 67 | 68 | // Set the display of the elements in a second loop to avoid constant reflow 69 | for ( index = 0; index < length; index++ ) { 70 | if ( values[ index ] != null ) { 71 | elements[ index ].style.display = values[ index ]; 72 | } 73 | } 74 | 75 | return elements; 76 | } 77 | 78 | jQuery.fn.extend( { 79 | show: function() { 80 | return showHide( this, true ); 81 | }, 82 | hide: function() { 83 | return showHide( this ); 84 | }, 85 | toggle: function( state ) { 86 | if ( typeof state === "boolean" ) { 87 | return state ? this.show() : this.hide(); 88 | } 89 | 90 | return this.each( function() { 91 | if ( isHiddenWithinTree( this ) ) { 92 | jQuery( this ).show(); 93 | } else { 94 | jQuery( this ).hide(); 95 | } 96 | } ); 97 | } 98 | } ); 99 | 100 | export default showHide; 101 | -------------------------------------------------------------------------------- /test/data/testsuite.css: -------------------------------------------------------------------------------- 1 | ol#empty { 2 | opacity: 0; 3 | } 4 | 5 | div#fx-tests h4 { 6 | background: red; 7 | } 8 | 9 | div#fx-tests h4.pass { 10 | background: green; 11 | } 12 | 13 | div#fx-tests div.box { 14 | background: red; 15 | overflow: hidden; 16 | border: 2px solid #000; 17 | } 18 | 19 | div#fx-tests div.overflow { 20 | overflow: visible; 21 | } 22 | 23 | div.autoheight { 24 | height: auto; 25 | } 26 | 27 | div.autowidth { 28 | width: auto; 29 | } 30 | 31 | div.autoopacity { 32 | opacity: 1; 33 | } 34 | 35 | div.largewidth { 36 | width: 100px; 37 | } 38 | 39 | div.largeheight { 40 | height: 100px; 41 | } 42 | 43 | div.medwidth { 44 | width: 50px; 45 | } 46 | 47 | div.medheight { 48 | height: 50px; 49 | } 50 | 51 | div.medopacity { 52 | opacity: 0.5; 53 | } 54 | 55 | div.nowidth { 56 | width: 0; 57 | } 58 | 59 | div.noheight { 60 | height: 0; 61 | } 62 | 63 | div.noopacity { 64 | opacity: 0; 65 | } 66 | 67 | div#fx-tests div.widewidth { 68 | background-repeat: repeat-x; 69 | } 70 | 71 | div#fx-tests div.wideheight { 72 | background-repeat: repeat-y; 73 | } 74 | 75 | div#fx-tests div.widewidth.wideheight { 76 | background-repeat: repeat; 77 | } 78 | 79 | div#fx-tests div.noback { 80 | background-image: none; 81 | } 82 | 83 | .chain-test, 84 | .chain-test div { 85 | width: 100px; 86 | height: 20px; 87 | position: relative; 88 | float: left; 89 | } 90 | .chain-test div { 91 | position: absolute; 92 | top: 0; 93 | left: 0; 94 | } 95 | 96 | .chain-test { 97 | background: red; 98 | } 99 | .chain-test div { 100 | background: green; 101 | } 102 | 103 | .chain-test-out { 104 | background: green; 105 | } 106 | .chain-test-out div { 107 | background: red; 108 | display: none; 109 | } 110 | 111 | #nothiddendiv { font-size: 16px; } 112 | #nothiddendivchild.em { font-size: 2em; } 113 | #nothiddendivchild.prct { font-size: 150%; } 114 | 115 | /* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ 116 | body, div { background: url(https://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } 117 | 118 | /* #10501 */ 119 | section { background:#f0f; display:block; } 120 | 121 | /* #11971 */ 122 | #foo { background: url(1x1.jpg) right bottom no-repeat; } 123 | 124 | /* #14824 */ 125 | #span-14824 { display: block; } 126 | 127 | #display { display: list-item !important; } 128 | 129 | .block { display: block; } 130 | .inline { display: inline; } 131 | .list-item { display: list-item; } 132 | .hidden, .none { display: none; } 133 | 134 | #div-gh-2836 { 135 | position: relative; 136 | overflow: auto; 137 | height: 100px; 138 | } 139 | #div-gh-2836 div { 140 | position: relative; 141 | height: 100%; 142 | padding: 0; 143 | margin: 0; 144 | } 145 | 146 | .border-box, .border-box * { 147 | box-sizing: border-box; 148 | } 149 | -------------------------------------------------------------------------------- /src/ajax/jsonp.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import nonce from "./var/nonce.js"; 3 | import rquery from "./var/rquery.js"; 4 | 5 | import "../ajax.js"; 6 | 7 | var oldCallbacks = [], 8 | rjsonp = /(=)\?(?=&|$)|\?\?/; 9 | 10 | // Default jsonp settings 11 | jQuery.ajaxSetup( { 12 | jsonp: "callback", 13 | jsonpCallback: function() { 14 | var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce.guid++ ) ); 15 | this[ callback ] = true; 16 | return callback; 17 | } 18 | } ); 19 | 20 | // Detect, normalize options and install callbacks for jsonp requests 21 | jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) { 22 | 23 | var callbackName, overwritten, responseContainer, 24 | jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ? 25 | "url" : 26 | typeof s.data === "string" && 27 | ( s.contentType || "" ) 28 | .indexOf( "application/x-www-form-urlencoded" ) === 0 && 29 | rjsonp.test( s.data ) && "data" 30 | ); 31 | 32 | // Handle iff the expected data type is "jsonp" or we have a parameter to set 33 | if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) { 34 | 35 | // Get callback name, remembering preexisting value associated with it 36 | callbackName = s.jsonpCallback = typeof s.jsonpCallback === "function" ? 37 | s.jsonpCallback() : 38 | s.jsonpCallback; 39 | 40 | // Insert callback into url or form data 41 | if ( jsonProp ) { 42 | s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName ); 43 | } else if ( s.jsonp !== false ) { 44 | s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName; 45 | } 46 | 47 | // Use data converter to retrieve json after script execution 48 | s.converters[ "script json" ] = function() { 49 | if ( !responseContainer ) { 50 | jQuery.error( callbackName + " was not called" ); 51 | } 52 | return responseContainer[ 0 ]; 53 | }; 54 | 55 | // Force json dataType 56 | s.dataTypes[ 0 ] = "json"; 57 | 58 | // Install callback 59 | overwritten = window[ callbackName ]; 60 | window[ callbackName ] = function() { 61 | responseContainer = arguments; 62 | }; 63 | 64 | // Clean-up function (fires after converters) 65 | jqXHR.always( function() { 66 | 67 | // If previous value didn't exist - remove it 68 | if ( overwritten === undefined ) { 69 | jQuery( window ).removeProp( callbackName ); 70 | 71 | // Otherwise restore preexisting value 72 | } else { 73 | window[ callbackName ] = overwritten; 74 | } 75 | 76 | // Save back as free 77 | if ( s[ callbackName ] ) { 78 | 79 | // Make sure that re-using the options doesn't screw things around 80 | s.jsonpCallback = originalSettings.jsonpCallback; 81 | 82 | // Save the callback name for future use 83 | oldCallbacks.push( callbackName ); 84 | } 85 | 86 | // Call if it was a function and we have a response 87 | if ( responseContainer && typeof overwritten === "function" ) { 88 | overwritten( responseContainer[ 0 ] ); 89 | } 90 | 91 | responseContainer = overwritten = undefined; 92 | } ); 93 | 94 | // Delegate to script 95 | return "script"; 96 | } 97 | } ); 98 | -------------------------------------------------------------------------------- /src/ajax/xhr.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | 3 | import "../ajax.js"; 4 | 5 | jQuery.ajaxSettings.xhr = function() { 6 | return new window.XMLHttpRequest(); 7 | }; 8 | 9 | var xhrSuccessStatus = { 10 | 11 | // File protocol always yields status code 0, assume 200 12 | 0: 200 13 | }; 14 | 15 | jQuery.ajaxTransport( function( options ) { 16 | var callback; 17 | 18 | // Cross domain only allowed if supported through XMLHttpRequest 19 | return { 20 | send: function( headers, complete ) { 21 | var i, 22 | xhr = options.xhr(); 23 | 24 | xhr.open( 25 | options.type, 26 | options.url, 27 | options.async, 28 | options.username, 29 | options.password 30 | ); 31 | 32 | // Apply custom fields if provided 33 | if ( options.xhrFields ) { 34 | for ( i in options.xhrFields ) { 35 | xhr[ i ] = options.xhrFields[ i ]; 36 | } 37 | } 38 | 39 | // Override mime type if needed 40 | if ( options.mimeType && xhr.overrideMimeType ) { 41 | xhr.overrideMimeType( options.mimeType ); 42 | } 43 | 44 | // X-Requested-With header 45 | // For cross-domain requests, seeing as conditions for a preflight are 46 | // akin to a jigsaw puzzle, we simply never set it to be sure. 47 | // (it can always be set on a per-request basis or even using ajaxSetup) 48 | // For same-domain requests, won't change header if already provided. 49 | if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) { 50 | headers[ "X-Requested-With" ] = "XMLHttpRequest"; 51 | } 52 | 53 | // Set headers 54 | for ( i in headers ) { 55 | xhr.setRequestHeader( i, headers[ i ] ); 56 | } 57 | 58 | // Callback 59 | callback = function( type ) { 60 | return function() { 61 | if ( callback ) { 62 | callback = xhr.onload = xhr.onerror = xhr.onabort = xhr.ontimeout = null; 63 | 64 | if ( type === "abort" ) { 65 | xhr.abort(); 66 | } else if ( type === "error" ) { 67 | complete( 68 | 69 | // File: protocol always yields status 0; see #8605, #14207 70 | xhr.status, 71 | xhr.statusText 72 | ); 73 | } else { 74 | complete( 75 | xhrSuccessStatus[ xhr.status ] || xhr.status, 76 | xhr.statusText, 77 | 78 | // For XHR2 non-text, let the caller handle it (gh-2498) 79 | ( xhr.responseType || "text" ) === "text" ? 80 | { text: xhr.responseText } : 81 | { binary: xhr.response }, 82 | xhr.getAllResponseHeaders() 83 | ); 84 | } 85 | } 86 | }; 87 | }; 88 | 89 | // Listen to events 90 | xhr.onload = callback(); 91 | xhr.onabort = xhr.onerror = xhr.ontimeout = callback( "error" ); 92 | 93 | // Create the abort callback 94 | callback = callback( "abort" ); 95 | 96 | try { 97 | 98 | // Do send the request (this may raise an exception) 99 | xhr.send( options.hasContent && options.data || null ); 100 | } catch ( e ) { 101 | 102 | // #14683: Only rethrow if this hasn't been notified as an error yet 103 | if ( callback ) { 104 | throw e; 105 | } 106 | } 107 | }, 108 | 109 | abort: function() { 110 | if ( callback ) { 111 | callback(); 112 | } 113 | } 114 | }; 115 | } ); 116 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jquery", 3 | "title": "jQuery", 4 | "description": "JavaScript library for DOM operations", 5 | "version": "4.0.0-pre", 6 | "main": "dist/jquery.js", 7 | "homepage": "https://jquery.com", 8 | "author": { 9 | "name": "JS Foundation and other contributors", 10 | "url": "https://github.com/jquery/jquery/blob/master/AUTHORS.txt" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/jquery/jquery.git" 15 | }, 16 | "keywords": [ 17 | "jquery", 18 | "javascript", 19 | "browser", 20 | "library" 21 | ], 22 | "bugs": { 23 | "url": "https://github.com/jquery/jquery/issues" 24 | }, 25 | "license": "MIT", 26 | "dependencies": {}, 27 | "devDependencies": { 28 | "@babel/core": "7.4.3", 29 | "@babel/plugin-transform-for-of": "7.4.3", 30 | "commitplease": "3.2.0", 31 | "core-js-bundle": "3.0.0", 32 | "eslint-config-jquery": "2.0.0", 33 | "grunt": "1.0.4", 34 | "grunt-babel": "8.0.0", 35 | "grunt-cli": "1.3.2", 36 | "grunt-compare-size": "0.4.2", 37 | "grunt-contrib-uglify": "3.4.0", 38 | "grunt-contrib-watch": "1.1.0", 39 | "grunt-eslint": "22.0.0", 40 | "grunt-git-authors": "3.2.0", 41 | "grunt-jsonlint": "1.1.0", 42 | "grunt-karma": "3.0.1", 43 | "grunt-newer": "1.3.0", 44 | "gzip-js": "0.3.2", 45 | "husky": "1.3.1", 46 | "insight": "0.10.1", 47 | "jsdom": "14.0.0", 48 | "karma": "4.0.1", 49 | "karma-browserstack-launcher": "1.5.1", 50 | "karma-chrome-launcher": "2.2.0", 51 | "karma-firefox-launcher": "1.1.0", 52 | "karma-ie-launcher": "1.0.0", 53 | "karma-jsdom-launcher": "7.1.0", 54 | "karma-qunit": "3.0.0", 55 | "load-grunt-tasks": "4.0.0", 56 | "native-promise-only": "0.8.1", 57 | "promises-aplus-tests": "2.1.2", 58 | "q": "1.5.1", 59 | "qunit": "2.9.2", 60 | "raw-body": "2.3.3", 61 | "requirejs": "2.3.6", 62 | "rollup": "1.25.2", 63 | "rollup-plugin-hypothetical": "2.1.0", 64 | "sinon": "7.3.1", 65 | "strip-json-comments": "2.0.1", 66 | "testswarm": "1.1.0", 67 | "uglify-js": "3.4.7" 68 | }, 69 | "scripts": { 70 | "build": "npm install && grunt", 71 | "start": "grunt watch", 72 | "test:browserless": "grunt && grunt test:slow", 73 | "test:browser": "grunt && grunt karma:main", 74 | "test": "grunt && grunt test:slow && grunt karma:main", 75 | "jenkins": "npm run test:browserless" 76 | }, 77 | "commitplease": { 78 | "nohook": true, 79 | "components": [ 80 | "Docs", 81 | "Tests", 82 | "Build", 83 | "Support", 84 | "Release", 85 | "Core", 86 | "Ajax", 87 | "Attributes", 88 | "Callbacks", 89 | "CSS", 90 | "Data", 91 | "Deferred", 92 | "Deprecated", 93 | "Dimensions", 94 | "Effects", 95 | "Event", 96 | "Manipulation", 97 | "Offset", 98 | "Queue", 99 | "Selector", 100 | "Serialize", 101 | "Traversing", 102 | "Wrap" 103 | ], 104 | "markerPattern": "^((clos|fix|resolv)(e[sd]|ing))|^(refs?)", 105 | "ticketPattern": "^((Closes|Fixes) ([a-zA-Z]{2,}-)[0-9]+)|^(Refs? [^#])" 106 | }, 107 | "husky": { 108 | "hooks": { 109 | "commit-msg": "node node_modules/commitplease", 110 | "pre-commit": "grunt lint:newer qunit_fixture" 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /test/data/offset/boxes.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | Nonempty margin/border/padding/position 8 | 69 | 70 | 71 | 77 | 78 | 79 |
    80 |
    relative > relative
    82 |
    relative > absolute
    84 |
    85 |
    86 |
    absolute > relative
    88 |
    absolute > absolute
    90 |
    91 |
    92 |
    fixed > relative
    94 |
    fixed > absolute
    96 |
    97 |

    position:absolute with no top/left values

    98 | 99 | 100 | -------------------------------------------------------------------------------- /src/effects/Tween.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import isAutoPx from "../css/isAutoPx.js"; 3 | import finalPropName from "../css/finalPropName.js"; 4 | 5 | import "../css.js"; 6 | 7 | function Tween( elem, options, prop, end, easing ) { 8 | return new Tween.prototype.init( elem, options, prop, end, easing ); 9 | } 10 | jQuery.Tween = Tween; 11 | 12 | Tween.prototype = { 13 | constructor: Tween, 14 | init: function( elem, options, prop, end, easing, unit ) { 15 | this.elem = elem; 16 | this.prop = prop; 17 | this.easing = easing || jQuery.easing._default; 18 | this.options = options; 19 | this.start = this.now = this.cur(); 20 | this.end = end; 21 | this.unit = unit || ( isAutoPx( prop ) ? "px" : "" ); 22 | }, 23 | cur: function() { 24 | var hooks = Tween.propHooks[ this.prop ]; 25 | 26 | return hooks && hooks.get ? 27 | hooks.get( this ) : 28 | Tween.propHooks._default.get( this ); 29 | }, 30 | run: function( percent ) { 31 | var eased, 32 | hooks = Tween.propHooks[ this.prop ]; 33 | 34 | if ( this.options.duration ) { 35 | this.pos = eased = jQuery.easing[ this.easing ]( 36 | percent, this.options.duration * percent, 0, 1, this.options.duration 37 | ); 38 | } else { 39 | this.pos = eased = percent; 40 | } 41 | this.now = ( this.end - this.start ) * eased + this.start; 42 | 43 | if ( this.options.step ) { 44 | this.options.step.call( this.elem, this.now, this ); 45 | } 46 | 47 | if ( hooks && hooks.set ) { 48 | hooks.set( this ); 49 | } else { 50 | Tween.propHooks._default.set( this ); 51 | } 52 | return this; 53 | } 54 | }; 55 | 56 | Tween.prototype.init.prototype = Tween.prototype; 57 | 58 | Tween.propHooks = { 59 | _default: { 60 | get: function( tween ) { 61 | var result; 62 | 63 | // Use a property on the element directly when it is not a DOM element, 64 | // or when there is no matching style property that exists. 65 | if ( tween.elem.nodeType !== 1 || 66 | tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) { 67 | return tween.elem[ tween.prop ]; 68 | } 69 | 70 | // Passing an empty string as a 3rd parameter to .css will automatically 71 | // attempt a parseFloat and fallback to a string if the parse fails. 72 | // Simple values such as "10px" are parsed to Float; 73 | // complex values such as "rotate(1rad)" are returned as-is. 74 | result = jQuery.css( tween.elem, tween.prop, "" ); 75 | 76 | // Empty strings, null, undefined and "auto" are converted to 0. 77 | return !result || result === "auto" ? 0 : result; 78 | }, 79 | set: function( tween ) { 80 | 81 | // Use step hook for back compat. 82 | // Use cssHook if its there. 83 | // Use .style if available and use plain properties where available. 84 | if ( jQuery.fx.step[ tween.prop ] ) { 85 | jQuery.fx.step[ tween.prop ]( tween ); 86 | } else if ( tween.elem.nodeType === 1 && ( 87 | jQuery.cssHooks[ tween.prop ] || 88 | tween.elem.style[ finalPropName( tween.prop ) ] != null ) ) { 89 | jQuery.style( tween.elem, tween.prop, tween.now + tween.unit ); 90 | } else { 91 | tween.elem[ tween.prop ] = tween.now; 92 | } 93 | } 94 | } 95 | }; 96 | 97 | jQuery.easing = { 98 | linear: function( p ) { 99 | return p; 100 | }, 101 | swing: function( p ) { 102 | return 0.5 - Math.cos( p * Math.PI ) / 2; 103 | }, 104 | _default: "swing" 105 | }; 106 | 107 | jQuery.fx = Tween.prototype.init; 108 | 109 | // Back compat <1.8 extension point 110 | jQuery.fx.step = {}; 111 | -------------------------------------------------------------------------------- /test/integration/data/gh-1764-fullscreen.js: -------------------------------------------------------------------------------- 1 | /* exported bootstrapFrom */ 2 | 3 | // `mode` may be "iframe" or not specified. 4 | function bootstrapFrom( mainSelector, mode ) { 5 | if ( mode === "iframe" && window.parent === window ) { 6 | jQuery( mainSelector + " .result" ) 7 | .attr( "class", "result warn" ) 8 | .text( "This test should be run in an iframe. Open ../gh-1764-fullscreen.html." ); 9 | jQuery( mainSelector + " .toggle-fullscreen" ).remove(); 10 | return; 11 | } 12 | 13 | var fullscreenSupported = document.exitFullscreen || 14 | document.exitFullscreen || 15 | document.msExitFullscreen || 16 | document.mozCancelFullScreen || 17 | document.webkitExitFullscreen; 18 | 19 | function isFullscreen() { 20 | return !!( document.fullscreenElement || 21 | document.mozFullScreenElement || 22 | document.webkitFullscreenElement || 23 | document.msFullscreenElement ); 24 | } 25 | 26 | function requestFullscreen( element ) { 27 | if ( !isFullscreen() ) { 28 | if ( element.requestFullscreen ) { 29 | element.requestFullscreen(); 30 | } else if ( element.msRequestFullscreen ) { 31 | element.msRequestFullscreen(); 32 | } else if ( element.mozRequestFullScreen ) { 33 | element.mozRequestFullScreen(); 34 | } else if ( element.webkitRequestFullscreen ) { 35 | element.webkitRequestFullscreen(); 36 | } 37 | } 38 | } 39 | 40 | function exitFullscreen() { 41 | if ( document.exitFullscreen ) { 42 | document.exitFullscreen(); 43 | } else if ( document.msExitFullscreen ) { 44 | document.msExitFullscreen(); 45 | } else if ( document.mozCancelFullScreen ) { 46 | document.mozCancelFullScreen(); 47 | } else if ( document.webkitExitFullscreen ) { 48 | document.webkitExitFullscreen(); 49 | } 50 | } 51 | 52 | function runTest() { 53 | var dimensions; 54 | if ( !fullscreenSupported ) { 55 | jQuery( mainSelector + " .result" ) 56 | .attr( "class", "result success" ) 57 | .text( "Fullscreen mode is not supported in this browser. Test not run." ); 58 | } else if ( !isFullscreen() ) { 59 | jQuery( mainSelector + " .result" ) 60 | .attr( "class", "result warn" ) 61 | .text( "Enable fullscreen mode to fire the test." ); 62 | } else { 63 | dimensions = jQuery( mainSelector + " .result" ).css( [ "width", "height" ] ); 64 | dimensions.width = parseFloat( dimensions.width ).toFixed( 3 ); 65 | dimensions.height = parseFloat( dimensions.height ).toFixed( 3 ); 66 | if ( dimensions.width === "700.000" && dimensions.height === "56.000" ) { 67 | jQuery( mainSelector + " .result" ) 68 | .attr( "class", "result success" ) 69 | .text( "Dimensions in fullscreen mode are computed correctly." ); 70 | } else { 71 | jQuery( mainSelector + " .result" ) 72 | .attr( "class", "result error" ) 73 | .html( "Incorrect dimensions; " + 74 | "expected: { width: '700.000', height: '56.000' };
    " + 75 | "got: { width: '" + dimensions.width + "', height: '" + 76 | dimensions.height + "' }." ); 77 | } 78 | } 79 | } 80 | 81 | function toggleFullscreen() { 82 | if ( isFullscreen() ) { 83 | exitFullscreen(); 84 | } else { 85 | requestFullscreen( jQuery( mainSelector + " .container" )[ 0 ] ); 86 | } 87 | } 88 | 89 | $( mainSelector + " .toggle-fullscreen" ).on( "click", toggleFullscreen ); 90 | 91 | $( document ).on( [ 92 | "webkitfullscreenchange", 93 | "mozfullscreenchange", 94 | "fullscreenchange", 95 | "MSFullscreenChange" 96 | ].join( " " ), runTest ); 97 | 98 | runTest(); 99 | } 100 | -------------------------------------------------------------------------------- /src/attributes/attr.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import access from "../core/access.js"; 3 | import nodeName from "../core/nodeName.js"; 4 | import rnothtmlwhite from "../var/rnothtmlwhite.js"; 5 | import isIE from "../var/isIE.js"; 6 | 7 | import "../selector.js"; 8 | 9 | jQuery.fn.extend( { 10 | attr: function( name, value ) { 11 | return access( this, jQuery.attr, name, value, arguments.length > 1 ); 12 | }, 13 | 14 | removeAttr: function( name ) { 15 | return this.each( function() { 16 | jQuery.removeAttr( this, name ); 17 | } ); 18 | } 19 | } ); 20 | 21 | jQuery.extend( { 22 | attr: function( elem, name, value ) { 23 | var ret, hooks, 24 | nType = elem.nodeType; 25 | 26 | // Don't get/set attributes on text, comment and attribute nodes 27 | if ( nType === 3 || nType === 8 || nType === 2 ) { 28 | return; 29 | } 30 | 31 | // Fallback to prop when attributes are not supported 32 | if ( typeof elem.getAttribute === "undefined" ) { 33 | return jQuery.prop( elem, name, value ); 34 | } 35 | 36 | // Attribute hooks are determined by the lowercase version 37 | // Grab necessary hook if one is defined 38 | if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { 39 | hooks = jQuery.attrHooks[ name.toLowerCase() ]; 40 | } 41 | 42 | if ( value !== undefined ) { 43 | if ( value === null ) { 44 | jQuery.removeAttr( elem, name ); 45 | return; 46 | } 47 | 48 | if ( hooks && "set" in hooks && 49 | ( ret = hooks.set( elem, value, name ) ) !== undefined ) { 50 | return ret; 51 | } 52 | 53 | elem.setAttribute( name, value + "" ); 54 | return value; 55 | } 56 | 57 | if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { 58 | return ret; 59 | } 60 | 61 | ret = elem.getAttribute( name ); 62 | 63 | // Non-existent attributes return null, we normalize to undefined 64 | return ret == null ? undefined : ret; 65 | }, 66 | 67 | attrHooks: { 68 | type: { 69 | set: function( elem, value ) { 70 | 71 | // Support: IE <=11+ 72 | // An input loses its value after becoming a radio 73 | if ( isIE && value === "radio" && nodeName( elem, "input" ) ) { 74 | var val = elem.value; 75 | elem.setAttribute( "type", value ); 76 | if ( val ) { 77 | elem.value = val; 78 | } 79 | return value; 80 | } 81 | } 82 | } 83 | }, 84 | 85 | removeAttr: function( elem, value ) { 86 | var name, 87 | i = 0, 88 | 89 | // Attribute names can contain non-HTML whitespace characters 90 | // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 91 | attrNames = value && value.match( rnothtmlwhite ); 92 | 93 | if ( attrNames && elem.nodeType === 1 ) { 94 | while ( ( name = attrNames[ i++ ] ) ) { 95 | elem.removeAttribute( name ); 96 | } 97 | } 98 | } 99 | } ); 100 | 101 | jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( _i, name ) { 102 | jQuery.attrHooks[ name ] = { 103 | get: function( elem ) { 104 | var ret, 105 | isXML = jQuery.isXMLDoc( elem ), 106 | lowercaseName = name.toLowerCase(); 107 | 108 | if ( !isXML ) { 109 | ret = elem.getAttribute( name ) != null ? 110 | lowercaseName : 111 | null; 112 | } 113 | return ret; 114 | }, 115 | 116 | set: function( elem, value, name ) { 117 | if ( value === false ) { 118 | 119 | // Remove boolean attributes when set to false 120 | jQuery.removeAttr( elem, name ); 121 | } else { 122 | elem.setAttribute( name, name ); 123 | } 124 | return name; 125 | } 126 | }; 127 | } ); 128 | -------------------------------------------------------------------------------- /src/attributes/prop.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import access from "../core/access.js"; 3 | import isIE from "../var/isIE.js"; 4 | 5 | import "../selector.js"; 6 | 7 | var rfocusable = /^(?:input|select|textarea|button)$/i, 8 | rclickable = /^(?:a|area)$/i; 9 | 10 | jQuery.fn.extend( { 11 | prop: function( name, value ) { 12 | return access( this, jQuery.prop, name, value, arguments.length > 1 ); 13 | }, 14 | 15 | removeProp: function( name ) { 16 | return this.each( function() { 17 | delete this[ jQuery.propFix[ name ] || name ]; 18 | } ); 19 | } 20 | } ); 21 | 22 | jQuery.extend( { 23 | prop: function( elem, name, value ) { 24 | var ret, hooks, 25 | nType = elem.nodeType; 26 | 27 | // Don't get/set properties on text, comment and attribute nodes 28 | if ( nType === 3 || nType === 8 || nType === 2 ) { 29 | return; 30 | } 31 | 32 | if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) { 33 | 34 | // Fix name and attach hooks 35 | name = jQuery.propFix[ name ] || name; 36 | hooks = jQuery.propHooks[ name ]; 37 | } 38 | 39 | if ( value !== undefined ) { 40 | if ( hooks && "set" in hooks && 41 | ( ret = hooks.set( elem, value, name ) ) !== undefined ) { 42 | return ret; 43 | } 44 | 45 | return ( elem[ name ] = value ); 46 | } 47 | 48 | if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) { 49 | return ret; 50 | } 51 | 52 | return elem[ name ]; 53 | }, 54 | 55 | propHooks: { 56 | tabIndex: { 57 | get: function( elem ) { 58 | 59 | // Support: IE <=9 - 11+ 60 | // elem.tabIndex doesn't always return the 61 | // correct value when it hasn't been explicitly set 62 | // https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/ 63 | // Use proper attribute retrieval(#12072) 64 | var tabindex = elem.getAttribute( "tabindex" ); 65 | 66 | if ( tabindex ) { 67 | return parseInt( tabindex, 10 ); 68 | } 69 | 70 | if ( 71 | rfocusable.test( elem.nodeName ) || 72 | rclickable.test( elem.nodeName ) && 73 | elem.href 74 | ) { 75 | return 0; 76 | } 77 | 78 | return -1; 79 | } 80 | } 81 | }, 82 | 83 | propFix: { 84 | "for": "htmlFor", 85 | "class": "className" 86 | } 87 | } ); 88 | 89 | // Support: IE <=11+ 90 | // Accessing the selectedIndex property forces the browser to respect 91 | // setting selected on the option. The getter ensures a default option 92 | // is selected when in an optgroup. ESLint rule "no-unused-expressions" 93 | // is disabled for this code since it considers such accessions noop. 94 | if ( isIE ) { 95 | jQuery.propHooks.selected = { 96 | get: function( elem ) { 97 | 98 | var parent = elem.parentNode; 99 | if ( parent && parent.parentNode ) { 100 | // eslint-disable-next-line no-unused-expressions 101 | parent.parentNode.selectedIndex; 102 | } 103 | return null; 104 | }, 105 | set: function( elem ) { 106 | 107 | 108 | var parent = elem.parentNode; 109 | if ( parent ) { 110 | // eslint-disable-next-line no-unused-expressions 111 | parent.selectedIndex; 112 | 113 | if ( parent.parentNode ) { 114 | // eslint-disable-next-line no-unused-expressions 115 | parent.parentNode.selectedIndex; 116 | } 117 | } 118 | } 119 | }; 120 | } 121 | 122 | jQuery.each( [ 123 | "tabIndex", 124 | "readOnly", 125 | "maxLength", 126 | "cellSpacing", 127 | "cellPadding", 128 | "rowSpan", 129 | "colSpan", 130 | "useMap", 131 | "frameBorder", 132 | "contentEditable" 133 | ], function() { 134 | jQuery.propFix[ this.toLowerCase() ] = this; 135 | } ); 136 | -------------------------------------------------------------------------------- /src/queue.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | import dataPriv from "./data/var/dataPriv.js"; 3 | 4 | import "./deferred.js"; 5 | import "./callbacks.js"; 6 | 7 | jQuery.extend( { 8 | queue: function( elem, type, data ) { 9 | var queue; 10 | 11 | if ( elem ) { 12 | type = ( type || "fx" ) + "queue"; 13 | queue = dataPriv.get( elem, type ); 14 | 15 | // Speed up dequeue by getting out quickly if this is just a lookup 16 | if ( data ) { 17 | if ( !queue || Array.isArray( data ) ) { 18 | queue = dataPriv.access( elem, type, jQuery.makeArray( data ) ); 19 | } else { 20 | queue.push( data ); 21 | } 22 | } 23 | return queue || []; 24 | } 25 | }, 26 | 27 | dequeue: function( elem, type ) { 28 | type = type || "fx"; 29 | 30 | var queue = jQuery.queue( elem, type ), 31 | startLength = queue.length, 32 | fn = queue.shift(), 33 | hooks = jQuery._queueHooks( elem, type ), 34 | next = function() { 35 | jQuery.dequeue( elem, type ); 36 | }; 37 | 38 | // If the fx queue is dequeued, always remove the progress sentinel 39 | if ( fn === "inprogress" ) { 40 | fn = queue.shift(); 41 | startLength--; 42 | } 43 | 44 | if ( fn ) { 45 | 46 | // Add a progress sentinel to prevent the fx queue from being 47 | // automatically dequeued 48 | if ( type === "fx" ) { 49 | queue.unshift( "inprogress" ); 50 | } 51 | 52 | // Clear up the last queue stop function 53 | delete hooks.stop; 54 | fn.call( elem, next, hooks ); 55 | } 56 | 57 | if ( !startLength && hooks ) { 58 | hooks.empty.fire(); 59 | } 60 | }, 61 | 62 | // Not public - generate a queueHooks object, or return the current one 63 | _queueHooks: function( elem, type ) { 64 | var key = type + "queueHooks"; 65 | return dataPriv.get( elem, key ) || dataPriv.access( elem, key, { 66 | empty: jQuery.Callbacks( "once memory" ).add( function() { 67 | dataPriv.remove( elem, [ type + "queue", key ] ); 68 | } ) 69 | } ); 70 | } 71 | } ); 72 | 73 | jQuery.fn.extend( { 74 | queue: function( type, data ) { 75 | var setter = 2; 76 | 77 | if ( typeof type !== "string" ) { 78 | data = type; 79 | type = "fx"; 80 | setter--; 81 | } 82 | 83 | if ( arguments.length < setter ) { 84 | return jQuery.queue( this[ 0 ], type ); 85 | } 86 | 87 | return data === undefined ? 88 | this : 89 | this.each( function() { 90 | var queue = jQuery.queue( this, type, data ); 91 | 92 | // Ensure a hooks for this queue 93 | jQuery._queueHooks( this, type ); 94 | 95 | if ( type === "fx" && queue[ 0 ] !== "inprogress" ) { 96 | jQuery.dequeue( this, type ); 97 | } 98 | } ); 99 | }, 100 | dequeue: function( type ) { 101 | return this.each( function() { 102 | jQuery.dequeue( this, type ); 103 | } ); 104 | }, 105 | clearQueue: function( type ) { 106 | return this.queue( type || "fx", [] ); 107 | }, 108 | 109 | // Get a promise resolved when queues of a certain type 110 | // are emptied (fx is the type by default) 111 | promise: function( type, obj ) { 112 | var tmp, 113 | count = 1, 114 | defer = jQuery.Deferred(), 115 | elements = this, 116 | i = this.length, 117 | resolve = function() { 118 | if ( !( --count ) ) { 119 | defer.resolveWith( elements, [ elements ] ); 120 | } 121 | }; 122 | 123 | if ( typeof type !== "string" ) { 124 | obj = type; 125 | type = undefined; 126 | } 127 | type = type || "fx"; 128 | 129 | while ( i-- ) { 130 | tmp = dataPriv.get( elements[ i ], type + "queueHooks" ); 131 | if ( tmp && tmp.empty ) { 132 | count++; 133 | tmp.empty.add( resolve ); 134 | } 135 | } 136 | resolve(); 137 | return defer.promise( obj ); 138 | } 139 | } ); 140 | 141 | export default jQuery; 142 | -------------------------------------------------------------------------------- /src/serialize.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | import toType from "./core/toType.js"; 3 | import rcheckableType from "./var/rcheckableType.js"; 4 | 5 | import "./core/init.js"; 6 | import "./traversing.js"; // filter 7 | import "./attributes/prop.js"; 8 | 9 | var 10 | rbracket = /\[\]$/, 11 | rCRLF = /\r?\n/g, 12 | rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i, 13 | rsubmittable = /^(?:input|select|textarea|keygen)/i; 14 | 15 | function buildParams( prefix, obj, traditional, add ) { 16 | var name; 17 | 18 | if ( Array.isArray( obj ) ) { 19 | 20 | // Serialize array item. 21 | jQuery.each( obj, function( i, v ) { 22 | if ( traditional || rbracket.test( prefix ) ) { 23 | 24 | // Treat each array item as a scalar. 25 | add( prefix, v ); 26 | 27 | } else { 28 | 29 | // Item is non-scalar (array or object), encode its numeric index. 30 | buildParams( 31 | prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]", 32 | v, 33 | traditional, 34 | add 35 | ); 36 | } 37 | } ); 38 | 39 | } else if ( !traditional && toType( obj ) === "object" ) { 40 | 41 | // Serialize object item. 42 | for ( name in obj ) { 43 | buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add ); 44 | } 45 | 46 | } else { 47 | 48 | // Serialize scalar item. 49 | add( prefix, obj ); 50 | } 51 | } 52 | 53 | // Serialize an array of form elements or a set of 54 | // key/values into a query string 55 | jQuery.param = function( a, traditional ) { 56 | var prefix, 57 | s = [], 58 | add = function( key, valueOrFunction ) { 59 | 60 | // If value is a function, invoke it and use its return value 61 | var value = typeof valueOrFunction === "function" ? 62 | valueOrFunction() : 63 | valueOrFunction; 64 | 65 | s[ s.length ] = encodeURIComponent( key ) + "=" + 66 | encodeURIComponent( value == null ? "" : value ); 67 | }; 68 | 69 | if ( a == null ) { 70 | return ""; 71 | } 72 | 73 | // If an array was passed in, assume that it is an array of form elements. 74 | if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) { 75 | 76 | // Serialize the form elements 77 | jQuery.each( a, function() { 78 | add( this.name, this.value ); 79 | } ); 80 | 81 | } else { 82 | 83 | // If traditional, encode the "old" way (the way 1.3.2 or older 84 | // did it), otherwise encode params recursively. 85 | for ( prefix in a ) { 86 | buildParams( prefix, a[ prefix ], traditional, add ); 87 | } 88 | } 89 | 90 | // Return the resulting serialization 91 | return s.join( "&" ); 92 | }; 93 | 94 | jQuery.fn.extend( { 95 | serialize: function() { 96 | return jQuery.param( this.serializeArray() ); 97 | }, 98 | serializeArray: function() { 99 | return this.map( function() { 100 | 101 | // Can add propHook for "elements" to filter or add form elements 102 | var elements = jQuery.prop( this, "elements" ); 103 | return elements ? jQuery.makeArray( elements ) : this; 104 | } ) 105 | .filter( function() { 106 | var type = this.type; 107 | 108 | // Use .is( ":disabled" ) so that fieldset[disabled] works 109 | return this.name && !jQuery( this ).is( ":disabled" ) && 110 | rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) && 111 | ( this.checked || !rcheckableType.test( type ) ); 112 | } ) 113 | .map( function( _i, elem ) { 114 | var val = jQuery( this ).val(); 115 | 116 | if ( val == null ) { 117 | return null; 118 | } 119 | 120 | if ( Array.isArray( val ) ) { 121 | return jQuery.map( val, function( val ) { 122 | return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; 123 | } ); 124 | } 125 | 126 | return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) }; 127 | } ).get(); 128 | } 129 | } ); 130 | 131 | export default jQuery; 132 | -------------------------------------------------------------------------------- /src/core/init.js: -------------------------------------------------------------------------------- 1 | // Initialize a jQuery object 2 | import jQuery from "../core.js"; 3 | import document from "../var/document.js"; 4 | import rsingleTag from "./var/rsingleTag.js"; 5 | 6 | import "../traversing/findFilter.js"; 7 | 8 | // A central reference to the root jQuery(document) 9 | var rootjQuery, 10 | 11 | // A simple way to check for HTML strings 12 | // Prioritize #id over to avoid XSS via location.hash (#9521) 13 | // Strict HTML recognition (#11290: must start with <) 14 | // Shortcut simple #id case for speed 15 | rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/, 16 | 17 | init = jQuery.fn.init = function( selector, context, root ) { 18 | var match, elem; 19 | 20 | // HANDLE: $(""), $(null), $(undefined), $(false) 21 | if ( !selector ) { 22 | return this; 23 | } 24 | 25 | // Method init() accepts an alternate rootjQuery 26 | // so migrate can support jQuery.sub (gh-2101) 27 | root = root || rootjQuery; 28 | 29 | // Handle HTML strings 30 | if ( typeof selector === "string" ) { 31 | if ( selector[ 0 ] === "<" && 32 | selector[ selector.length - 1 ] === ">" && 33 | selector.length >= 3 ) { 34 | 35 | // Assume that strings that start and end with <> are HTML and skip the regex check 36 | match = [ null, selector, null ]; 37 | 38 | } else { 39 | match = rquickExpr.exec( selector ); 40 | } 41 | 42 | // Match html or make sure no context is specified for #id 43 | if ( match && ( match[ 1 ] || !context ) ) { 44 | 45 | // HANDLE: $(html) -> $(array) 46 | if ( match[ 1 ] ) { 47 | context = context instanceof jQuery ? context[ 0 ] : context; 48 | 49 | // Option to run scripts is true for back-compat 50 | // Intentionally let the error be thrown if parseHTML is not present 51 | jQuery.merge( this, jQuery.parseHTML( 52 | match[ 1 ], 53 | context && context.nodeType ? context.ownerDocument || context : document, 54 | true 55 | ) ); 56 | 57 | // HANDLE: $(html, props) 58 | if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) { 59 | for ( match in context ) { 60 | 61 | // Properties of context are called as methods if possible 62 | if ( typeof this[ match ] === "function" ) { 63 | this[ match ]( context[ match ] ); 64 | 65 | // ...and otherwise set as attributes 66 | } else { 67 | this.attr( match, context[ match ] ); 68 | } 69 | } 70 | } 71 | 72 | return this; 73 | 74 | // HANDLE: $(#id) 75 | } else { 76 | elem = document.getElementById( match[ 2 ] ); 77 | 78 | if ( elem ) { 79 | 80 | // Inject the element directly into the jQuery object 81 | this[ 0 ] = elem; 82 | this.length = 1; 83 | } 84 | return this; 85 | } 86 | 87 | // HANDLE: $(expr, $(...)) 88 | } else if ( !context || context.jquery ) { 89 | return ( context || root ).find( selector ); 90 | 91 | // HANDLE: $(expr, context) 92 | // (which is just equivalent to: $(context).find(expr) 93 | } else { 94 | return this.constructor( context ).find( selector ); 95 | } 96 | 97 | // HANDLE: $(DOMElement) 98 | } else if ( selector.nodeType ) { 99 | this[ 0 ] = selector; 100 | this.length = 1; 101 | return this; 102 | 103 | // HANDLE: $(function) 104 | // Shortcut for document ready 105 | } else if ( typeof selector === "function" ) { 106 | return root.ready !== undefined ? 107 | root.ready( selector ) : 108 | 109 | // Execute immediately if ready is not present 110 | selector( jQuery ); 111 | } 112 | 113 | return jQuery.makeArray( selector, this ); 114 | }; 115 | 116 | // Give the init function the jQuery prototype for later instantiation 117 | init.prototype = jQuery.fn; 118 | 119 | // Initialize central reference 120 | rootjQuery = jQuery( document ); 121 | 122 | export default init; 123 | -------------------------------------------------------------------------------- /src/attributes/val.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import stripAndCollapse from "../core/stripAndCollapse.js"; 3 | import nodeName from "../core/nodeName.js"; 4 | 5 | import "../core/init.js"; 6 | 7 | var rreturn = /\r/g; 8 | 9 | jQuery.fn.extend( { 10 | val: function( value ) { 11 | var hooks, ret, valueIsFunction, 12 | elem = this[ 0 ]; 13 | 14 | if ( !arguments.length ) { 15 | if ( elem ) { 16 | hooks = jQuery.valHooks[ elem.type ] || 17 | jQuery.valHooks[ elem.nodeName.toLowerCase() ]; 18 | 19 | if ( hooks && 20 | "get" in hooks && 21 | ( ret = hooks.get( elem, "value" ) ) !== undefined 22 | ) { 23 | return ret; 24 | } 25 | 26 | ret = elem.value; 27 | 28 | // Handle most common string cases 29 | if ( typeof ret === "string" ) { 30 | return ret.replace( rreturn, "" ); 31 | } 32 | 33 | // Handle cases where value is null/undef or number 34 | return ret == null ? "" : ret; 35 | } 36 | 37 | return; 38 | } 39 | 40 | valueIsFunction = typeof value === "function"; 41 | 42 | return this.each( function( i ) { 43 | var val; 44 | 45 | if ( this.nodeType !== 1 ) { 46 | return; 47 | } 48 | 49 | if ( valueIsFunction ) { 50 | val = value.call( this, i, jQuery( this ).val() ); 51 | } else { 52 | val = value; 53 | } 54 | 55 | // Treat null/undefined as ""; convert numbers to string 56 | if ( val == null ) { 57 | val = ""; 58 | 59 | } else if ( typeof val === "number" ) { 60 | val += ""; 61 | 62 | } else if ( Array.isArray( val ) ) { 63 | val = jQuery.map( val, function( value ) { 64 | return value == null ? "" : value + ""; 65 | } ); 66 | } 67 | 68 | hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ]; 69 | 70 | // If set returns undefined, fall back to normal setting 71 | if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) { 72 | this.value = val; 73 | } 74 | } ); 75 | } 76 | } ); 77 | 78 | jQuery.extend( { 79 | valHooks: { 80 | option: { 81 | get: function( elem ) { 82 | 83 | var val = elem.getAttribute( "value" ); 84 | return val != null ? 85 | val : 86 | 87 | // Support: IE <=10 - 11+ 88 | // option.text throws exceptions (#14686, #14858) 89 | // Strip and collapse whitespace 90 | // https://html.spec.whatwg.org/#strip-and-collapse-whitespace 91 | stripAndCollapse( jQuery.text( elem ) ); 92 | } 93 | }, 94 | select: { 95 | get: function( elem ) { 96 | var value, option, i, 97 | options = elem.options, 98 | index = elem.selectedIndex, 99 | one = elem.type === "select-one", 100 | values = one ? null : [], 101 | max = one ? index + 1 : options.length; 102 | 103 | if ( index < 0 ) { 104 | i = max; 105 | 106 | } else { 107 | i = one ? index : 0; 108 | } 109 | 110 | // Loop through all the selected options 111 | for ( ; i < max; i++ ) { 112 | option = options[ i ]; 113 | 114 | if ( option.selected && 115 | 116 | // Don't return options that are disabled or in a disabled optgroup 117 | !option.disabled && 118 | ( !option.parentNode.disabled || 119 | !nodeName( option.parentNode, "optgroup" ) ) ) { 120 | 121 | // Get the specific value for the option 122 | value = jQuery( option ).val(); 123 | 124 | // We don't need an array for one selects 125 | if ( one ) { 126 | return value; 127 | } 128 | 129 | // Multi-Selects return an array 130 | values.push( value ); 131 | } 132 | } 133 | 134 | return values; 135 | }, 136 | 137 | set: function( elem, value ) { 138 | var optionSet, option, 139 | options = elem.options, 140 | values = jQuery.makeArray( value ), 141 | i = options.length; 142 | 143 | while ( i-- ) { 144 | option = options[ i ]; 145 | 146 | if ( ( option.selected = 147 | jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1 148 | ) ) { 149 | optionSet = true; 150 | } 151 | } 152 | 153 | // Force browsers to behave consistently when non-matching value is set 154 | if ( !optionSet ) { 155 | elem.selectedIndex = -1; 156 | } 157 | return values; 158 | } 159 | } 160 | } 161 | } ); 162 | 163 | // Radios and checkboxes getter/setter 164 | jQuery.each( [ "radio", "checkbox" ], function() { 165 | jQuery.valHooks[ this ] = { 166 | set: function( elem, value ) { 167 | if ( Array.isArray( value ) ) { 168 | return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 ); 169 | } 170 | } 171 | }; 172 | } ); 173 | -------------------------------------------------------------------------------- /src/data/Data.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import camelCase from "../core/camelCase.js"; 3 | import rnothtmlwhite from "../var/rnothtmlwhite.js"; 4 | import acceptData from "./var/acceptData.js"; 5 | 6 | function Data() { 7 | this.expando = jQuery.expando + Data.uid++; 8 | } 9 | 10 | Data.uid = 1; 11 | 12 | Data.prototype = { 13 | 14 | cache: function( owner ) { 15 | 16 | // Check if the owner object already has a cache 17 | var value = owner[ this.expando ]; 18 | 19 | // If not, create one 20 | if ( !value ) { 21 | value = {}; 22 | 23 | // We can accept data for non-element nodes in modern browsers, 24 | // but we should not, see #8335. 25 | // Always return an empty object. 26 | if ( acceptData( owner ) ) { 27 | 28 | // If it is a node unlikely to be stringify-ed or looped over 29 | // use plain assignment 30 | if ( owner.nodeType ) { 31 | owner[ this.expando ] = value; 32 | 33 | // Otherwise secure it in a non-enumerable property 34 | // configurable must be true to allow the property to be 35 | // deleted when data is removed 36 | } else { 37 | Object.defineProperty( owner, this.expando, { 38 | value: value, 39 | configurable: true 40 | } ); 41 | } 42 | } 43 | } 44 | 45 | return value; 46 | }, 47 | set: function( owner, data, value ) { 48 | var prop, 49 | cache = this.cache( owner ); 50 | 51 | // Handle: [ owner, key, value ] args 52 | // Always use camelCase key (gh-2257) 53 | if ( typeof data === "string" ) { 54 | cache[ camelCase( data ) ] = value; 55 | 56 | // Handle: [ owner, { properties } ] args 57 | } else { 58 | 59 | // Copy the properties one-by-one to the cache object 60 | for ( prop in data ) { 61 | cache[ camelCase( prop ) ] = data[ prop ]; 62 | } 63 | } 64 | return cache; 65 | }, 66 | get: function( owner, key ) { 67 | return key === undefined ? 68 | this.cache( owner ) : 69 | 70 | // Always use camelCase key (gh-2257) 71 | owner[ this.expando ] && owner[ this.expando ][ camelCase( key ) ]; 72 | }, 73 | access: function( owner, key, value ) { 74 | 75 | // In cases where either: 76 | // 77 | // 1. No key was specified 78 | // 2. A string key was specified, but no value provided 79 | // 80 | // Take the "read" path and allow the get method to determine 81 | // which value to return, respectively either: 82 | // 83 | // 1. The entire cache object 84 | // 2. The data stored at the key 85 | // 86 | if ( key === undefined || 87 | ( ( key && typeof key === "string" ) && value === undefined ) ) { 88 | 89 | return this.get( owner, key ); 90 | } 91 | 92 | // When the key is not a string, or both a key and value 93 | // are specified, set or extend (existing objects) with either: 94 | // 95 | // 1. An object of properties 96 | // 2. A key and value 97 | // 98 | this.set( owner, key, value ); 99 | 100 | // Since the "set" path can have two possible entry points 101 | // return the expected data based on which path was taken[*] 102 | return value !== undefined ? value : key; 103 | }, 104 | remove: function( owner, key ) { 105 | var i, 106 | cache = owner[ this.expando ]; 107 | 108 | if ( cache === undefined ) { 109 | return; 110 | } 111 | 112 | if ( key !== undefined ) { 113 | 114 | // Support array or space separated string of keys 115 | if ( Array.isArray( key ) ) { 116 | 117 | // If key is an array of keys... 118 | // We always set camelCase keys, so remove that. 119 | key = key.map( camelCase ); 120 | } else { 121 | key = camelCase( key ); 122 | 123 | // If a key with the spaces exists, use it. 124 | // Otherwise, create an array by matching non-whitespace 125 | key = key in cache ? 126 | [ key ] : 127 | ( key.match( rnothtmlwhite ) || [] ); 128 | } 129 | 130 | i = key.length; 131 | 132 | while ( i-- ) { 133 | delete cache[ key[ i ] ]; 134 | } 135 | } 136 | 137 | // Remove the expando if there's no more data 138 | if ( key === undefined || jQuery.isEmptyObject( cache ) ) { 139 | 140 | // Support: Chrome <=35 - 45+ 141 | // Webkit & Blink performance suffers when deleting properties 142 | // from DOM nodes, so set to undefined instead 143 | // https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted) 144 | if ( owner.nodeType ) { 145 | owner[ this.expando ] = undefined; 146 | } else { 147 | delete owner[ this.expando ]; 148 | } 149 | } 150 | }, 151 | hasData: function( owner ) { 152 | var cache = owner[ this.expando ]; 153 | return cache !== undefined && !jQuery.isEmptyObject( cache ); 154 | } 155 | }; 156 | 157 | export default Data; 158 | -------------------------------------------------------------------------------- /test/hovertest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hover tests 4 | 5 | 32 | 33 | 34 |

    Hover (mouse{over,out,enter,leave}) Tests

    35 |

    Be sure to try moving the mouse out of the browser via the left side on each test.

    36 |
    37 | 38 |
    39 |
    40 | 41 | .hover() in/out: 0 / 0 42 |
    43 |
    44 | Mouse over here should NOT trigger the counter. 45 |
    46 |
    47 |
    48 |
    49 | 50 | Live enter/leave: 0 / 0 51 |
    52 |
    53 | Mouse over here should NOT trigger the counter. 54 |
    55 |
    56 |
    57 |
    58 | 59 | Delegated enter/leave: 0 / 0 60 |
    61 |
    62 | Mouse over here should NOT trigger the counter. 63 |
    64 |
    65 | 66 |
    67 |
    68 | 69 | Bind over/out: 0 / 0 70 |
    71 |
    72 | Mouse over here SHOULD trigger the counter. 73 |
    74 |
    75 |
    76 |
    77 | 78 | Live over/out: 0 / 0 79 |
    80 |
    81 | Mouse over here SHOULD trigger the counter. 82 |
    83 |
    84 |
    85 |
    86 | 87 | Delegated over/out: 0 / 0 88 |
    89 |
    90 | Mouse over here SHOULD trigger the counter. 91 |
    92 |
    93 | 94 |
    95 | 96 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /src/data.js: -------------------------------------------------------------------------------- 1 | import jQuery from "./core.js"; 2 | import access from "./core/access.js"; 3 | import camelCase from "./core/camelCase.js"; 4 | import dataPriv from "./data/var/dataPriv.js"; 5 | import dataUser from "./data/var/dataUser.js"; 6 | 7 | // Implementation Summary 8 | // 9 | // 1. Enforce API surface and semantic compatibility with 1.9.x branch 10 | // 2. Improve the module's maintainability by reducing the storage 11 | // paths to a single mechanism. 12 | // 3. Use the same single mechanism to support "private" and "user" data. 13 | // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData) 14 | // 5. Avoid exposing implementation details on user objects (eg. expando properties) 15 | // 6. Provide a clear path for implementation upgrade to WeakMap in 2014 16 | 17 | var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/, 18 | rmultiDash = /[A-Z]/g; 19 | 20 | function getData( data ) { 21 | if ( data === "true" ) { 22 | return true; 23 | } 24 | 25 | if ( data === "false" ) { 26 | return false; 27 | } 28 | 29 | if ( data === "null" ) { 30 | return null; 31 | } 32 | 33 | // Only convert to a number if it doesn't change the string 34 | if ( data === +data + "" ) { 35 | return +data; 36 | } 37 | 38 | if ( rbrace.test( data ) ) { 39 | return JSON.parse( data ); 40 | } 41 | 42 | return data; 43 | } 44 | 45 | function dataAttr( elem, key, data ) { 46 | var name; 47 | 48 | // If nothing was found internally, try to fetch any 49 | // data from the HTML5 data-* attribute 50 | if ( data === undefined && elem.nodeType === 1 ) { 51 | name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase(); 52 | data = elem.getAttribute( name ); 53 | 54 | if ( typeof data === "string" ) { 55 | try { 56 | data = getData( data ); 57 | } catch ( e ) {} 58 | 59 | // Make sure we set the data so it isn't changed later 60 | dataUser.set( elem, key, data ); 61 | } else { 62 | data = undefined; 63 | } 64 | } 65 | return data; 66 | } 67 | 68 | jQuery.extend( { 69 | hasData: function( elem ) { 70 | return dataUser.hasData( elem ) || dataPriv.hasData( elem ); 71 | }, 72 | 73 | data: function( elem, name, data ) { 74 | return dataUser.access( elem, name, data ); 75 | }, 76 | 77 | removeData: function( elem, name ) { 78 | dataUser.remove( elem, name ); 79 | }, 80 | 81 | // TODO: Now that all calls to _data and _removeData have been replaced 82 | // with direct calls to dataPriv methods, these can be deprecated. 83 | _data: function( elem, name, data ) { 84 | return dataPriv.access( elem, name, data ); 85 | }, 86 | 87 | _removeData: function( elem, name ) { 88 | dataPriv.remove( elem, name ); 89 | } 90 | } ); 91 | 92 | jQuery.fn.extend( { 93 | data: function( key, value ) { 94 | var i, name, data, 95 | elem = this[ 0 ], 96 | attrs = elem && elem.attributes; 97 | 98 | // Gets all values 99 | if ( key === undefined ) { 100 | if ( this.length ) { 101 | data = dataUser.get( elem ); 102 | 103 | if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) { 104 | i = attrs.length; 105 | while ( i-- ) { 106 | 107 | // Support: IE 11+ 108 | // The attrs elements can be null (#14894) 109 | if ( attrs[ i ] ) { 110 | name = attrs[ i ].name; 111 | if ( name.indexOf( "data-" ) === 0 ) { 112 | name = camelCase( name.slice( 5 ) ); 113 | dataAttr( elem, name, data[ name ] ); 114 | } 115 | } 116 | } 117 | dataPriv.set( elem, "hasDataAttrs", true ); 118 | } 119 | } 120 | 121 | return data; 122 | } 123 | 124 | // Sets multiple values 125 | if ( typeof key === "object" ) { 126 | return this.each( function() { 127 | dataUser.set( this, key ); 128 | } ); 129 | } 130 | 131 | return access( this, function( value ) { 132 | var data; 133 | 134 | // The calling jQuery object (element matches) is not empty 135 | // (and therefore has an element appears at this[ 0 ]) and the 136 | // `value` parameter was not undefined. An empty jQuery object 137 | // will result in `undefined` for elem = this[ 0 ] which will 138 | // throw an exception if an attempt to read a data cache is made. 139 | if ( elem && value === undefined ) { 140 | 141 | // Attempt to get data from the cache 142 | // The key will always be camelCased in Data 143 | data = dataUser.get( elem, key ); 144 | if ( data !== undefined ) { 145 | return data; 146 | } 147 | 148 | // Attempt to "discover" the data in 149 | // HTML5 custom data-* attrs 150 | data = dataAttr( elem, key ); 151 | if ( data !== undefined ) { 152 | return data; 153 | } 154 | 155 | // We tried really hard, but the data doesn't exist. 156 | return; 157 | } 158 | 159 | // Set the data... 160 | this.each( function() { 161 | 162 | // We always store the camelCased key 163 | dataUser.set( this, key, value ); 164 | } ); 165 | }, null, value, arguments.length > 1, null, true ); 166 | }, 167 | 168 | removeData: function( key ) { 169 | return this.each( function() { 170 | dataUser.remove( this, key ); 171 | } ); 172 | } 173 | } ); 174 | 175 | export default jQuery; 176 | -------------------------------------------------------------------------------- /test/unit/support.js: -------------------------------------------------------------------------------- 1 | QUnit.module( "support", { afterEach: moduleTeardown } ); 2 | 3 | var computedSupport = getComputedSupport( jQuery.support ); 4 | 5 | function getComputedSupport( support ) { 6 | var prop, 7 | result = {}; 8 | 9 | for ( prop in support ) { 10 | if ( typeof support[ prop ] === "function" ) { 11 | result[ prop ] = support[ prop ](); 12 | } else { 13 | result[ prop ] = support[ prop ]; 14 | } 15 | } 16 | 17 | return result; 18 | } 19 | 20 | if ( jQuery.css ) { 21 | testIframe( 22 | "body background is not lost if set prior to loading jQuery (#9239)", 23 | "support/bodyBackground.html", 24 | function( assert, jQuery, window, document, color, support ) { 25 | assert.expect( 2 ); 26 | var okValue = { 27 | "#000000": true, 28 | "rgb(0, 0, 0)": true 29 | }; 30 | assert.ok( okValue[ color ], "color was not reset (" + color + ")" ); 31 | 32 | assert.deepEqual( jQuery.extend( {}, support ), computedSupport, 33 | "Same support properties" ); 34 | } 35 | ); 36 | } 37 | 38 | // This test checks CSP only for browsers with "Content-Security-Policy" header support 39 | // i.e. no IE 40 | testIframe( 41 | "Check CSP (https://developer.mozilla.org/en-US/docs/Security/CSP) restrictions", 42 | "mock.php?action=cspFrame", 43 | function( assert, jQuery, window, document, support ) { 44 | var done = assert.async(); 45 | 46 | assert.expect( 2 ); 47 | assert.deepEqual( jQuery.extend( {}, support ), computedSupport, 48 | "No violations of CSP polices" ); 49 | 50 | supportjQuery.get( baseURL + "support/csp.log" ).done( function( data ) { 51 | assert.equal( data, "", "No log request should be sent" ); 52 | supportjQuery.get( baseURL + "mock.php?action=cspClean" ).done( done ); 53 | } ); 54 | } 55 | ); 56 | 57 | ( function() { 58 | var expected, 59 | userAgent = window.navigator.userAgent, 60 | expectedMap = { 61 | edge: { 62 | reliableTrDimensions: false, 63 | scope: undefined 64 | }, 65 | ie_11: { 66 | reliableTrDimensions: false, 67 | scope: undefined 68 | }, 69 | chrome: { 70 | reliableTrDimensions: true, 71 | scope: true 72 | }, 73 | safari: { 74 | reliableTrDimensions: true, 75 | scope: true 76 | }, 77 | firefox: { 78 | reliableTrDimensions: true, 79 | scope: true 80 | }, 81 | ios: { 82 | reliableTrDimensions: true, 83 | scope: true 84 | } 85 | }; 86 | 87 | if ( /edge\//i.test( userAgent ) ) { 88 | expected = expectedMap.edge; 89 | } else if ( document.documentMode ) { 90 | expected = expectedMap.ie_11; 91 | } else if ( /chrome/i.test( userAgent ) ) { 92 | 93 | // Catches Chrome on Android & Opera as well. 94 | expected = expectedMap.chrome; 95 | } else if ( /\b\d+(\.\d+)+ safari/i.test( userAgent ) ) { 96 | expected = expectedMap.safari; 97 | } else if ( /firefox/i.test( userAgent ) ) { 98 | expected = expectedMap.firefox; 99 | } else if ( /(?:iphone|ipad);.*(?:iphone)? os \d+_/i.test( userAgent ) ) { 100 | expected = expectedMap.ios; 101 | } 102 | 103 | QUnit.test( "Verify that support tests resolve as expected per browser", function( assert ) { 104 | if ( !expected ) { 105 | assert.expect( 1 ); 106 | assert.ok( false, "Known client: " + userAgent ); 107 | } 108 | 109 | var i, prop, 110 | j = 0; 111 | 112 | for ( prop in computedSupport ) { 113 | j++; 114 | } 115 | 116 | // Add an assertion per undefined support prop as it may 117 | // not even exist on computedSupport but we still want to run 118 | // the check. 119 | for ( prop in expected ) { 120 | if ( expected[ prop ] === undefined ) { 121 | j++; 122 | } 123 | } 124 | 125 | assert.expect( j ); 126 | 127 | for ( i in expected ) { 128 | assert.equal( computedSupport[ i ], expected[ i ], 129 | "jQuery.support['" + i + "']: " + computedSupport[ i ] + 130 | ", expected['" + i + "']: " + expected[ i ] ); 131 | } 132 | } ); 133 | 134 | QUnit.test( "Verify support tests are failing in one of tested browsers", 135 | function( assert ) { 136 | 137 | var prop, browserKey, supportTestName, 138 | i = 0, 139 | supportProps = {}, 140 | failingSupportProps = {}; 141 | 142 | for ( prop in computedSupport ) { 143 | i++; 144 | } 145 | 146 | // Add an assertion per undefined support prop as it may 147 | // not even exist on computedSupport but we still want to run 148 | // the check. 149 | for ( prop in expected ) { 150 | if ( expected[ prop ] === undefined ) { 151 | i++; 152 | } 153 | } 154 | 155 | assert.expect( i ); 156 | 157 | // Record all support props and the failing ones and ensure every test 158 | // is failing at least once. 159 | for ( browserKey in expectedMap ) { 160 | for ( supportTestName in expectedMap[ browserKey ] ) { 161 | supportProps[ supportTestName ] = true; 162 | if ( !expectedMap[ browserKey ][ supportTestName ] ) { 163 | failingSupportProps[ supportTestName ] = true; 164 | } 165 | } 166 | } 167 | 168 | for ( supportTestName in supportProps ) { 169 | assert.ok( failingSupportProps[ supportTestName ], 170 | "jQuery.support['" + supportTestName + 171 | "'] is expected to fail at least in one browser" ); 172 | } 173 | } ); 174 | 175 | } )(); 176 | -------------------------------------------------------------------------------- /src/attributes/classes.js: -------------------------------------------------------------------------------- 1 | import jQuery from "../core.js"; 2 | import stripAndCollapse from "../core/stripAndCollapse.js"; 3 | import rnothtmlwhite from "../var/rnothtmlwhite.js"; 4 | import dataPriv from "../data/var/dataPriv.js"; 5 | 6 | import "../core/init.js"; 7 | 8 | function getClass( elem ) { 9 | return elem.getAttribute && elem.getAttribute( "class" ) || ""; 10 | } 11 | 12 | function classesToArray( value ) { 13 | if ( Array.isArray( value ) ) { 14 | return value; 15 | } 16 | if ( typeof value === "string" ) { 17 | return value.match( rnothtmlwhite ) || []; 18 | } 19 | return []; 20 | } 21 | 22 | jQuery.fn.extend( { 23 | addClass: function( value ) { 24 | var classes, elem, cur, curValue, clazz, j, finalValue, 25 | i = 0; 26 | 27 | if ( typeof value === "function" ) { 28 | return this.each( function( j ) { 29 | jQuery( this ).addClass( value.call( this, j, getClass( this ) ) ); 30 | } ); 31 | } 32 | 33 | classes = classesToArray( value ); 34 | 35 | if ( classes.length ) { 36 | while ( ( elem = this[ i++ ] ) ) { 37 | curValue = getClass( elem ); 38 | cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); 39 | 40 | if ( cur ) { 41 | j = 0; 42 | while ( ( clazz = classes[ j++ ] ) ) { 43 | if ( cur.indexOf( " " + clazz + " " ) < 0 ) { 44 | cur += clazz + " "; 45 | } 46 | } 47 | 48 | // Only assign if different to avoid unneeded rendering. 49 | finalValue = stripAndCollapse( cur ); 50 | if ( curValue !== finalValue ) { 51 | elem.setAttribute( "class", finalValue ); 52 | } 53 | } 54 | } 55 | } 56 | 57 | return this; 58 | }, 59 | 60 | removeClass: function( value ) { 61 | var classes, elem, cur, curValue, clazz, j, finalValue, 62 | i = 0; 63 | 64 | if ( typeof value === "function" ) { 65 | return this.each( function( j ) { 66 | jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) ); 67 | } ); 68 | } 69 | 70 | if ( !arguments.length ) { 71 | return this.attr( "class", "" ); 72 | } 73 | 74 | classes = classesToArray( value ); 75 | 76 | if ( classes.length ) { 77 | while ( ( elem = this[ i++ ] ) ) { 78 | curValue = getClass( elem ); 79 | 80 | // This expression is here for better compressibility (see addClass) 81 | cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " ); 82 | 83 | if ( cur ) { 84 | j = 0; 85 | while ( ( clazz = classes[ j++ ] ) ) { 86 | 87 | // Remove *all* instances 88 | while ( cur.indexOf( " " + clazz + " " ) > -1 ) { 89 | cur = cur.replace( " " + clazz + " ", " " ); 90 | } 91 | } 92 | 93 | // Only assign if different to avoid unneeded rendering. 94 | finalValue = stripAndCollapse( cur ); 95 | if ( curValue !== finalValue ) { 96 | elem.setAttribute( "class", finalValue ); 97 | } 98 | } 99 | } 100 | } 101 | 102 | return this; 103 | }, 104 | 105 | toggleClass: function( value, stateVal ) { 106 | var type = typeof value, 107 | isValidValue = type === "string" || Array.isArray( value ); 108 | 109 | if ( typeof stateVal === "boolean" && isValidValue ) { 110 | return stateVal ? this.addClass( value ) : this.removeClass( value ); 111 | } 112 | 113 | if ( typeof value === "function" ) { 114 | return this.each( function( i ) { 115 | jQuery( this ).toggleClass( 116 | value.call( this, i, getClass( this ), stateVal ), 117 | stateVal 118 | ); 119 | } ); 120 | } 121 | 122 | return this.each( function() { 123 | var className, i, self, classNames; 124 | 125 | if ( isValidValue ) { 126 | 127 | // Toggle individual class names 128 | i = 0; 129 | self = jQuery( this ); 130 | classNames = classesToArray( value ); 131 | 132 | while ( ( className = classNames[ i++ ] ) ) { 133 | 134 | // Check each className given, space separated list 135 | if ( self.hasClass( className ) ) { 136 | self.removeClass( className ); 137 | } else { 138 | self.addClass( className ); 139 | } 140 | } 141 | 142 | // Toggle whole class name 143 | } else if ( value === undefined || type === "boolean" ) { 144 | className = getClass( this ); 145 | if ( className ) { 146 | 147 | // Store className if set 148 | dataPriv.set( this, "__className__", className ); 149 | } 150 | 151 | // If the element has a class name or if we're passed `false`, 152 | // then remove the whole classname (if there was one, the above saved it). 153 | // Otherwise bring back whatever was previously saved (if anything), 154 | // falling back to the empty string if nothing was stored. 155 | if ( this.setAttribute ) { 156 | this.setAttribute( "class", 157 | className || value === false ? 158 | "" : 159 | dataPriv.get( this, "__className__" ) || "" 160 | ); 161 | } 162 | } 163 | } ); 164 | }, 165 | 166 | hasClass: function( selector ) { 167 | var className, elem, 168 | i = 0; 169 | 170 | className = " " + selector + " "; 171 | while ( ( elem = this[ i++ ] ) ) { 172 | if ( elem.nodeType === 1 && 173 | ( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) { 174 | return true; 175 | } 176 | } 177 | 178 | return false; 179 | } 180 | } ); 181 | --------------------------------------------------------------------------------