2011-04-28 21:56:52 +00:00
[jQuery ](http://jquery.com/ ) - New Wave JavaScript
2011-01-18 00:49:24 +00:00
==================================================
2009-11-02 21:36:49 +00:00
2011-11-21 18:25:07 +00:00
Contribution Guides
--------------------------------------
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:
2011-12-11 23:20:13 +00:00
2011-11-21 18:25:07 +00:00
1. [Getting Involved ](http://docs.jquery.com/Getting_Involved )
2. [Core Style Guide ](http://docs.jquery.com/JQuery_Core_Style_Guidelines )
3. [Tips For Bug Patching ](http://docs.jquery.com/Tips_for_jQuery_Bug_Patching )
2009-11-02 21:36:49 +00:00
What you need to build your own jQuery
2011-01-18 00:49:24 +00:00
--------------------------------------
2009-11-02 21:36:49 +00:00
2012-06-04 16:48:18 +00:00
In order to build jQuery, you need to have GNU make 3.8 or later, Node.js/npm latest, and git 1.7 or later.
2011-01-18 00:49:24 +00:00
(Earlier versions might work OK, but are not tested.)
2009-11-02 21:36:49 +00:00
2011-01-18 00:49:24 +00:00
Windows users have two options:
2010-06-14 15:17:13 +00:00
2011-01-18 00:49:24 +00:00
1. Install [msysgit ](https://code.google.com/p/msysgit/ ) (Full installer for official Git),
[GNU make for Windows ](http://gnuwin32.sourceforge.net/packages/make.htm ), and a
[binary version of Node.js ](http://node-js.prcn.co.cc/ ). Make sure all three packages are installed to the same
location (by default, this is C:\Program Files\Git).
2011-01-18 03:06:57 +00:00
2. Install [Cygwin ](http://cygwin.com/ ) (make sure you install the git, make, and which packages), then either follow
the [Node.js build instructions ](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29 ) or install
2011-01-18 00:49:24 +00:00
the [binary version of Node.js ](http://node-js.prcn.co.cc/ ).
2010-06-14 15:17:13 +00:00
2011-01-18 00:49:24 +00:00
Mac OS users should install Xcode (comes on your Mac OS install DVD, or downloadable from
[Apple's Xcode site ](http://developer.apple.com/technologies/xcode.html )) and
2012-09-15 20:19:51 +00:00
[Homebrew ](http://mxcl.github.com/homebrew/ ). Once Homebrew is installed, run `brew install git` to install git,
2011-01-18 00:49:24 +00:00
and `brew install node` to install Node.js.
2010-06-14 15:17:13 +00:00
2011-01-18 00:49:24 +00:00
Linux/BSD users should use their appropriate package managers to install make, git, and node, or build from source
if you swing that way. Easy-peasy.
2009-11-02 21:36:49 +00:00
2011-01-18 00:49:24 +00:00
How to build your own jQuery
----------------------------
2009-11-02 21:36:49 +00:00
2012-06-04 16:48:18 +00:00
First, clone a copy of the main jQuery git repo by running:
2012-06-07 15:59:30 +00:00
```bash
git clone git://github.com/jquery/jquery.git
```
2012-06-04 16:48:18 +00:00
2012-08-12 09:34:21 +00:00
Enter the directory and install the Node dependencies:
2012-06-04 16:48:18 +00:00
2012-06-07 15:59:30 +00:00
```bash
cd jquery & & npm install
```
2012-06-04 16:48:18 +00:00
Make sure you have `grunt` installed by testing:
2012-06-07 15:59:30 +00:00
```bash
grunt -version
```
2012-06-04 16:48:18 +00:00
2012-06-07 02:59:44 +00:00
Then, to get a complete, minified (w/ Uglify.js), linted (w/ JSHint) version of jQuery, type the following:
2012-06-04 16:48:18 +00:00
2012-06-07 15:59:30 +00:00
```bash
grunt
```
2010-03-02 02:51:44 +00:00
2011-01-18 00:49:24 +00:00
The built version of jQuery will be put in the `dist/` subdirectory.
2009-11-02 21:36:49 +00:00
2012-06-04 16:48:18 +00:00
2012-06-07 15:24:35 +00:00
### Modules (new in 1.8)
2012-06-12 15:01:44 +00:00
Starting in jQuery 1.8, special builds can now be created that optionally exclude or include any of the following modules:
2012-06-07 15:24:35 +00:00
2012-06-12 11:13:18 +00:00
- ajax
2012-06-12 16:52:30 +00:00
- css
2012-06-07 15:24:35 +00:00
- dimensions
- effects
- offset
2012-08-12 09:34:21 +00:00
Before creating a custom build for use in production, be sure to check out the latest stable version:
```bash
git pull; git checkout $(git describe --abbrev=0 --tags)
```
Then, make sure all Node dependencies are installed and all Git submodules are checked out:
```bash
npm install & & grunt
```
2012-06-07 15:24:35 +00:00
To create a custom build, use the following special `grunt` commands:
2012-06-12 11:13:18 +00:00
Exclude **ajax** :
```bash
2012-06-12 16:52:30 +00:00
grunt custom:-ajax
```
Exclude **css** :
```bash
grunt custom:-css
2012-06-12 11:13:18 +00:00
```
2012-06-25 14:02:28 +00:00
Exclude **deprecated** :
```bash
grunt custom:-deprecated
```
2012-06-07 16:03:32 +00:00
Exclude **dimensions** :
2012-06-07 15:24:35 +00:00
2012-06-07 15:59:30 +00:00
```bash
2012-06-12 16:52:30 +00:00
grunt custom:-dimensions
2012-06-07 15:59:30 +00:00
```
2012-06-07 15:24:35 +00:00
2012-06-07 16:03:32 +00:00
Exclude **effects** :
2012-06-07 15:24:35 +00:00
2012-06-07 15:59:30 +00:00
```bash
2012-06-12 16:52:30 +00:00
grunt custom:-effects
2012-06-07 15:59:30 +00:00
```
2012-06-07 15:24:35 +00:00
2012-06-07 16:03:32 +00:00
Exclude **offset** :
2012-06-07 15:24:35 +00:00
2012-06-07 15:59:30 +00:00
```bash
2012-06-12 16:52:30 +00:00
grunt custom:-offset
2012-06-07 15:59:30 +00:00
```
2012-06-07 15:24:35 +00:00
Exclude **all** optional modules:
2012-06-07 15:59:30 +00:00
```bash
2012-07-11 13:39:18 +00:00
grunt custom:-ajax,-css,-deprecated,-dimensions,-effects,-offset
2012-06-07 15:59:30 +00:00
```
2012-06-07 15:24:35 +00:00
2012-06-12 16:52:30 +00:00
Note: dependencies will be handled internally, by the build process.
2012-06-07 15:24:35 +00:00
2012-06-04 16:48:18 +00:00
Running the Unit Tests
--------------------------------------
Start grunt to auto-build jQuery as you work:
2012-06-07 15:59:30 +00:00
```bash
cd jquery & & grunt watch
```
2012-06-04 16:48:18 +00:00
Run the unit tests with a local server that supports PHP. No database is required. Pre-configured php local servers are available for Windows and Mac. Here are some options:
- Windows: [WAMP download ](http://www.wampserver.com/en/ )
- Mac: [MAMP download ](http://www.mamp.info/en/index.html )
- Linux: [Setting up LAMP ](https://www.linux.com/learn/tutorials/288158-easy-lamp-server-installation )
- [Mongoose (most platforms) ](http://code.google.com/p/mongoose/ )
2009-11-02 21:36:49 +00:00
2010-06-14 15:17:13 +00:00
Building to a different directory
2011-01-18 00:49:24 +00:00
---------------------------------
2010-06-14 15:17:13 +00:00
2012-06-04 16:48:18 +00:00
If you want to build jQuery to a directory that is different from the default location:
2009-11-02 21:36:49 +00:00
2012-06-07 15:59:30 +00:00
```bash
grunt & & grunt dist:/path/to/special/location/
```
2012-06-04 16:48:18 +00:00
With this example, the output files would be:
```bash
2012-06-07 15:46:45 +00:00
/path/to/special/location/jquery.js
/path/to/special/location/jquery.min.js
2012-06-04 16:48:18 +00:00
```
2010-06-14 15:17:13 +00:00
2012-06-05 17:10:01 +00:00
If you want to add a permanent copy destination, create a file in `dist/` called ".destination.json". Inside the file, paste and customize the following:
```json
{
"/Absolute/path/to/other/destination": true
}
```
Additionally, both methods can be combined.
2010-06-14 15:17:13 +00:00
2012-06-05 15:59:07 +00:00
Updating Submodules
-------------------
Update the submodules to what is probably the latest upstream code.
2012-06-07 15:59:30 +00:00
```bash
grunt submodules
```
2012-06-05 15:59:07 +00:00
Note: This task will also be run any time the default `grunt` command is used.
2010-06-14 15:17:13 +00:00
2011-04-08 18:56:56 +00:00
Git for dummies
---------------
As the source code is handled by the version control system Git, it's useful to know some features used.
### Submodules ###
2011-04-11 04:24:38 +00:00
The repository uses submodules, which normally are handled directly by the Makefile, but sometimes you want to
2011-04-08 18:56:56 +00:00
be able to work with them manually.
Following are the steps to manually get the submodules:
2012-06-07 15:59:30 +00:00
```bash
git clone https://github.com/jquery/jquery.git
2012-07-11 13:42:02 +00:00
cd jquery
2012-06-07 15:59:30 +00:00
git submodule init
git submodule update
```
2011-04-08 18:56:56 +00:00
Or:
2012-06-07 15:59:30 +00:00
```bash
git clone https://github.com/jquery/jquery.git
2012-07-11 13:42:02 +00:00
cd jquery
2012-06-07 15:59:30 +00:00
git submodule update --init
```
2011-04-08 18:56:56 +00:00
Or:
2012-06-07 15:59:30 +00:00
```bash
git clone --recursive https://github.com/jquery/jquery.git
2012-07-11 13:42:02 +00:00
cd jquery
2012-06-07 15:59:30 +00:00
```
2011-04-08 18:56:56 +00:00
If you want to work inside a submodule, it is possible, but first you need to checkout a branch:
2012-06-07 15:59:30 +00:00
```bash
cd src/sizzle
git checkout master
```
2011-04-08 18:56:56 +00:00
2011-04-11 04:24:38 +00:00
After you've committed your changes to the submodule, you'll update the jquery project to point to the new commit,
2011-04-08 18:56:56 +00:00
but remember to push the submodule changes before pushing the new jquery commit:
2012-06-07 15:59:30 +00:00
```bash
cd src/sizzle
git push origin master
cd ..
git add src/sizzle
git commit
```
2011-04-08 18:56:56 +00:00
### cleaning ###
If you want to purge your working directory back to the status of upstream, following commands can be used (remember everything you've worked on is gone after these):
2012-06-07 15:59:30 +00:00
```bash
git reset --hard upstream/master
git clean -fdx
```
2011-04-08 18:56:56 +00:00
### rebasing ###
For feature/topic branches, you should always used the `--rebase` flag to `git pull` , or if you are usually handling many temporary "to be in a github pull request" branches, run following to automate this:
2012-06-07 15:59:30 +00:00
```bash
git config branch.autosetuprebase local
```
(see `man git-config` for more information)
2011-04-08 18:56:56 +00:00
### handling merge conflicts ###
If you're getting merge conflicts when merging, instead of editing the conflicted files manually, you can use the feature
`git mergetool` . Even though the default tool `xxdiff` looks awful/old, it's rather useful.
Following are some commands that can be used there:
* `Ctrl + Alt + M` - automerge as much as possible
* `b` - jump to next merge conflict
* `s` - change the order of the conflicted lines
* `u` - undo an merge
* `left mouse button` - mark a block to be the winner
* `middle mouse button` - mark a line to be the winner
* `Ctrl + S` - save
* `Ctrl + Q` - quit
2010-06-14 15:17:13 +00:00
2012-05-29 16:40:13 +00:00
[QUnit ](http://docs.jquery.com/QUnit ) Reference
-----------------
2012-05-29 17:25:02 +00:00
### Test methods ###
2012-06-07 15:59:30 +00:00
```js
expect( numAssertions );
stop();
start();
```
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
2012-05-29 17:25:02 +00:00
### Test assertions ###
2012-06-07 15:59:30 +00:00
```js
ok( value, [message] );
equal( actual, expected, [message] );
notEqual( actual, expected, [message] );
deepEqual( actual, expected, [message] );
notDeepEqual( actual, expected, [message] );
strictEqual( actual, expected, [message] );
notStrictEqual( actual, expected, [message] );
raises( block, [expected], [message] );
```
2012-05-29 16:40:13 +00:00
Test Suite Convenience Methods Reference (See [test/data/testinit.js ](https://github.com/jquery/jquery/blob/master/test/data/testinit.js ))
------------------------------
2012-05-29 17:25:02 +00:00
### Returns an array of elements with the given IDs ###
2012-06-07 15:59:30 +00:00
```js
q( ... );
```
Example:
2012-05-29 17:25:02 +00:00
2012-06-07 15:59:30 +00:00
```js
q("main", "foo", "bar");
=> [ div#main, span#foo, input#bar ]
```
2012-05-29 17:25:02 +00:00
2012-05-29 18:57:37 +00:00
### Asserts that a selection matches the given IDs ###
2012-05-29 17:25:02 +00:00
2012-06-07 15:59:30 +00:00
```js
t( testName, selector, [ "array", "of", "ids" ] );
```
Example:
```js
t("Check for something", "//[a]", ["foo", "baar"]);
```
2012-05-29 17:25:02 +00:00
### Fires a native DOM event without going through jQuery ###
2012-06-07 15:59:30 +00:00
```js
fireNative( node, eventType )
```
Example:
2012-05-29 17:25:02 +00:00
2012-06-07 15:59:30 +00:00
```js
fireNative( jQuery("#elem")[0], "click" );
```
2012-05-29 17:25:02 +00:00
### Add random number to url to stop caching ###
2012-06-07 15:59:30 +00:00
```js
url( "some/url.php" );
```
2012-05-29 17:25:02 +00:00
2012-06-07 15:59:30 +00:00
Example:
2012-05-29 17:25:02 +00:00
2012-06-07 15:59:30 +00:00
```js
url("data/test.html");
=> "data/test.html?10538358428943"
url("data/test.php?foo=bar");
=> "data/test.php?foo=bar& 10538358345554"
```
2012-05-29 17:25:02 +00:00
### Load tests in an iframe ###
Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
and fires the given callback on jQuery ready (using the jQuery loading from that page)
and passes the iFrame's jQuery to the callback.
2012-06-07 15:59:30 +00:00
```js
testIframe( fileName, testName, callback );
```
2012-05-29 17:25:02 +00:00
Callback arguments:
2012-06-07 15:59:30 +00:00
```js
callback( jQueryFromIFrame, iFrameWindow, iFrameDocument );
```
2012-05-29 17:25:02 +00:00
### Load tests in an iframe (window.iframeCallback) ###
Loads a given page constructing a url with fileName: `"./data/" + fileName + ".html"`
The given callback is fired when window.iframeCallback is called by the page
The arguments passed to the callback are the same as the
arguments passed to window.iframeCallback, whatever that may be
2012-06-07 15:59:30 +00:00
```js
testIframeWithCallback( testName, fileName, callback );
```
2012-05-29 16:40:13 +00:00
2010-06-14 15:17:13 +00:00
Questions?
----------
2009-11-02 21:36:49 +00:00
2011-01-18 00:49:24 +00:00
If you have any questions, please feel free to ask on the
[Developing jQuery Core forum ](http://forum.jquery.com/developing-jquery-core ) or in #jquery on irc.freenode.net.