3.6.4
[jquery.git] / README.md
blobc05254e30eef6d18662c0d137d12fc9a80f0313c
1 [jQuery](https://jquery.com/) — New Wave JavaScript
2 ==================================================
4 [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjquery%2Fjquery.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjquery%2Fjquery?ref=badge_shield)
6 [![Gitter](https://badges.gitter.im/jquery/jquery.svg)](https://gitter.im/jquery/jquery?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8 Contribution Guides
9 --------------------------------------
11 In the spirit of open source software development, jQuery always encourages community code contribution. To help you get started and before you jump into writing code, be sure to read these important contribution guidelines thoroughly:
13 1. [Getting Involved](https://contribute.jquery.org/)
14 2. [Core Style Guide](https://contribute.jquery.org/style-guide/js/)
15 3. [Writing Code for jQuery Foundation Projects](https://contribute.jquery.org/code/)
17 ### References to issues/PRs
19 GitHub issues/PRs are usually referenced via `gh-NUMBER`, where `NUMBER` is the numerical ID of the issue/PR. You can find such an issue/PR under `https://github.com/jquery/jquery/issues/NUMBER`.
21 jQuery has used a different bug tracker - based on Trac - in the past, available under [bugs.jquery.com](https://bugs.jquery.com/). It is being kept in read only mode so that referring to past discussions is possible. When jQuery source references one of those issues, it uses the pattern `trac-NUMBER`, where `NUMBER` is the numerical ID of the issue. You can find such an issue under `https://bugs.jquery.com/ticket/NUMBER`.
24 Environments in which to use jQuery
25 --------------------------------------
27 - [Browser support](https://jquery.com/browser-support/)
28 - jQuery also supports Node, browser extensions, and other non-browser environments.
31 What you need to build your own jQuery
32 --------------------------------------
34 To build jQuery, you need to have the latest Node.js/npm and git 1.7 or later. Earlier versions might work, but are not supported.
36 For Windows, you have to download and install [git](https://git-scm.com/downloads) and [Node.js](https://nodejs.org/en/download/).
38 OS X users should install [Homebrew](https://brew.sh/). Once Homebrew is installed, run `brew install git` to install git,
39 and `brew install node` to install Node.js.
41 Linux/BSD users should use their appropriate package managers to install git and Node.js, or build from source
42 if you swing that way. Easy-peasy.
45 How to build your own jQuery
46 ----------------------------
48 Clone a copy of the main jQuery git repo by running:
50 ```bash
51 git clone git://github.com/jquery/jquery.git
52 ```
54 Enter the jquery directory and run the build script:
55 ```bash
56 cd jquery && npm run build
57 ```
58 The built version of jQuery will be put in the `dist/` subdirectory, along with the minified copy and associated map file.
60 If you want to create custom build or help with jQuery development, it would be better to install [grunt command line interface](https://github.com/gruntjs/grunt-cli) as a global package:
62 ```
63 npm install -g grunt-cli
64 ```
65 Make sure you have `grunt` installed by testing:
66 ```
67 grunt -V
68 ```
70 Now by running the `grunt` command, in the jquery directory, you can build a full version of jQuery, just like with an `npm run build` command:
71 ```
72 grunt
73 ```
75 There are many other tasks available for jQuery Core:
76 ```
77 grunt -help
78 ```
80 ### Modules
82 Special builds can be created that exclude subsets of jQuery functionality.
83 This allows for smaller custom builds when the builder is certain that those parts of jQuery are not being used.
84 For example, an app that only used JSONP for `$.ajax()` and did not need to calculate offsets or positions of elements could exclude the offset and ajax/xhr modules.
86 Any module may be excluded except for `core`, and `selector`. To exclude a module, pass its path relative to the `src` folder (without the `.js` extension).
88 Some example modules that can be excluded are:
90 - **ajax**: All AJAX functionality: `$.ajax()`, `$.get()`, `$.post()`, `$.ajaxSetup()`, `.load()`, transports, and ajax event shorthands such as `.ajaxStart()`.
91 - **ajax/xhr**: The XMLHTTPRequest AJAX transport only.
92 - **ajax/script**: The `<script>` AJAX transport only; used to retrieve scripts.
93 - **ajax/jsonp**: The JSONP AJAX transport only; depends on the ajax/script transport.
94 - **css**: The `.css()` method. Also removes **all** modules depending on css (including **effects**, **dimensions**, and **offset**).
95 - **css/showHide**:  Non-animated `.show()`, `.hide()` and `.toggle()`; can be excluded if you use classes or explicit `.css()` calls to set the `display` property. Also removes the **effects** module.
96 - **deprecated**: Methods documented as deprecated but not yet removed.
97 - **dimensions**: The `.width()` and `.height()` methods, including `inner-` and `outer-` variations.
98 - **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
99 - **event**: The `.on()` and `.off()` methods and all event functionality.
100 - **event/focusin**: Cross-browser support for the focusin and focusout events.
101 - **event/trigger**: The `.trigger()` and `.triggerHandler()` methods.
102 - **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
103 - **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
104 - **core/ready**: Exclude the ready module if you place your scripts at the end of the body. Any ready callbacks bound with `jQuery()` will simply be called immediately. However, `jQuery(document).ready()` will not be a function and `.on("ready", ...)` or similar will not be triggered.
105 - **deferred**: Exclude jQuery.Deferred. This also removes jQuery.Callbacks. *Note* that modules that depend on jQuery.Deferred(AJAX, effects, core/ready) will not be removed and will still expect jQuery.Deferred to be there. Include your own jQuery.Deferred implementation or exclude those modules as well (`grunt custom:-deferred,-ajax,-effects,-core/ready`).
106 - **exports/global**: Exclude the attachment of global jQuery variables ($ and jQuery) to the window.
107 - **exports/amd**: Exclude the AMD definition.
109 As a special case, you may also replace Sizzle by using a special flag `grunt custom:-sizzle`.
111 - **sizzle**: The Sizzle selector engine. When this module is excluded, it is replaced by a rudimentary selector engine based on the browser's `querySelectorAll` method that does not support jQuery selector extensions or enhanced semantics. See the [selector-native.js](https://github.com/jquery/jquery/blob/main/src/selector-native.js) file for details.
113 *Note*: Excluding Sizzle will also exclude all jQuery selector extensions (such as `effects/animatedSelector` and `css/hiddenVisibleSelectors`).
115 The build process shows a message for each dependent module it excludes or includes.
117 ##### AMD name
119 As an option, you can set the module name for jQuery's AMD definition. By default, it is set to "jquery", which plays nicely with plugins and third-party libraries, but there may be cases where you'd like to change this. Simply set the `"amd"` option:
121 ```bash
122 grunt custom --amd="custom-name"
125 Or, to define anonymously, set the name to an empty string.
127 ```bash
128 grunt custom --amd=""
131 #### Custom Build Examples
133 To create a custom build, first check out the version:
135 ```bash
136 git pull; git checkout VERSION
139 Where VERSION is the version you want to customize. Then, make sure all Node dependencies are installed:
141 ```bash
142 npm install
145 Create the custom build using the `grunt custom` option, listing the modules to be excluded.
147 Exclude all **ajax** functionality:
149 ```bash
150 grunt custom:-ajax
153 Excluding **css** removes modules depending on CSS: **effects**, **offset**, **dimensions**.
155 ```bash
156 grunt custom:-css
159 Exclude a bunch of modules:
161 ```bash
162 grunt custom:-ajax/jsonp,-css,-deprecated,-dimensions,-effects,-offset,-wrap
165 There is also a special alias to generate a build with the same configuration as the official jQuery Slim build is generated:
166 ```bash
167 grunt custom:slim
170 For questions or requests regarding custom builds, please start a thread on the [Developing jQuery Core](https://forum.jquery.com/developing-jquery-core) section of the forum. Due to the combinatorics and custom nature of these builds, they are not regularly tested in jQuery's unit test process. The non-Sizzle selector engine currently does not pass unit tests because it is missing too much essential functionality.
172 Running the Unit Tests
173 --------------------------------------
175 Make sure you have the necessary dependencies:
177 ```bash
178 npm install
181 Start `grunt watch` or `npm start` to auto-build jQuery as you work:
183 ```bash
184 grunt watch
188 Run the unit tests with a local server that supports PHP. Ensure that you run the site from the root directory, not the "test" directory. No database is required. Pre-configured php local servers are available for Windows and Mac. Here are some options:
190 - Windows: [WAMP download](http://www.wampserver.com/en/)
191 - Mac: [MAMP download](https://www.mamp.info/en/downloads/)
192 - Linux: [Setting up LAMP](https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation)
193 - [Mongoose (most platforms)](https://code.google.com/p/mongoose/)
198 Building to a different directory
199 ---------------------------------
201 To copy the built jQuery files from `/dist` to another directory:
203 ```bash
204 grunt && grunt dist:/path/to/special/location/
206 With this example, the output files would be:
208 ```bash
209 /path/to/special/location/jquery.js
210 /path/to/special/location/jquery.min.js
213 To add a permanent copy destination, create a file in `dist/` called ".destination.json". Inside the file, paste and customize the following:
215 ```json
218   "/Absolute/path/to/other/destination": true
222 Additionally, both methods can be combined.
226 Essential Git
227 -------------
229 As the source code is handled by the Git version control system, it's useful to know some features used.
231 ### Cleaning ###
233 If you want to purge your working directory back to the status of upstream, the following commands can be used (remember everything you've worked on is gone after these):
235 ```bash
236 git reset --hard upstream/main
237 git clean -fdx
240 ### Rebasing ###
242 For feature/topic branches, you should always use the `--rebase` flag to `git pull`, or if you are usually handling many temporary "to be in a github pull request" branches, run the following to automate this:
244 ```bash
245 git config branch.autosetuprebase local
247 (see `man git-config` for more information)
249 ### Handling merge conflicts ###
251 If you're getting merge conflicts when merging, instead of editing the conflicted files manually, you can use the feature
252 `git mergetool`. Even though the default tool `xxdiff` looks awful/old, it's rather useful.
254 The following are some commands that can be used there:
256 * `Ctrl + Alt + M` - automerge as much as possible
257 * `b` - jump to next merge conflict
258 * `s` - change the order of the conflicted lines
259 * `u` - undo a merge
260 * `left mouse button` - mark a block to be the winner
261 * `middle mouse button` - mark a line to be the winner
262 * `Ctrl + S` - save
263 * `Ctrl + Q` - quit
265 [QUnit](https://api.qunitjs.com) Reference
266 -----------------
268 ### Test methods ###
270 ```js
271 expect( numAssertions );
272 stop();
273 start();
277 *Note*: QUnit's eventual addition of an argument to stop/start is ignored in this test suite so that start and stop can be passed as callbacks without worrying about their parameters.
279 ### Test assertions ###
282 ```js
283 ok( value, [message] );
284 equal( actual, expected, [message] );
285 notEqual( actual, expected, [message] );
286 deepEqual( actual, expected, [message] );
287 notDeepEqual( actual, expected, [message] );
288 strictEqual( actual, expected, [message] );
289 notStrictEqual( actual, expected, [message] );
290 throws( block, [expected], [message] );
294 Test Suite Convenience Methods Reference (See [test/data/testinit.js](https://github.com/jquery/jquery/blob/main/test/data/testinit.js))
295 ------------------------------
297 ### Returns an array of elements with the given IDs ###
299 ```js
300 q( ... );
303 Example:
305 ```js
306 q("main", "foo", "bar");
308 => [ div#main, span#foo, input#bar ]
311 ### Asserts that a selection matches the given IDs ###
313 ```js
314 t( testName, selector, [ "array", "of", "ids" ] );
317 Example:
319 ```js
320 t("Check for something", "//[a]", ["foo", "bar"]);
325 ### Fires a native DOM event without going through jQuery ###
327 ```js
328 fireNative( node, eventType )
331 Example:
333 ```js
334 fireNative( jQuery("#elem")[0], "click" );
337 ### Add random number to url to stop caching ###
339 ```js
340 url( "some/url" );
343 Example:
345 ```js
346 url("index.html");
348 => "data/index.html?10538358428943"
351 url("mock.php?foo=bar");
353 => "data/mock.php?foo=bar&10538358345554"
357 ### Run tests in an iframe ###
359 Some tests may require a document other than the standard test fixture, and
360 these can be run in a separate iframe. The actual test code and assertions
361 remain in jQuery's main test files; only the minimal test fixture markup
362 and setup code should be placed in the iframe file.
364 ```js
365 testIframe( testName, fileName,
366   function testCallback(
367       assert, jQuery, window, document,
368           [ additional args ] ) {
369         ...
370   } );
373 This loads a page, constructing a url with fileName `"./data/" + fileName`.
374 The iframed page determines when the callback occurs in the test by
375 including the "/test/data/iframeTest.js" script and calling
376 `startIframeTest( [ additional args ] )` when appropriate. Often this
377 will be after either document ready or `window.onload` fires.
379 The `testCallback` receives the QUnit `assert` object created by `testIframe`
380 for this test, followed by the global `jQuery`, `window`, and `document` from
381 the iframe. If the iframe code passes any arguments to `startIframeTest`,
382 they follow the `document` argument.
385 Questions?
386 ----------
388 If you have any questions, please feel free to ask on the
389 [Developing jQuery Core forum](https://forum.jquery.com/developing-jquery-core) or in #jquery on irc.freenode.net.