Compare commits
442 commits
Author | SHA1 | Date | |
---|---|---|---|
bb7d98f018 | |||
e6f8951983 | |||
e83fcdcb02 | |||
139135a98a | |||
5b92a5f5ec | |||
e2ab2ba1d5 | |||
aa6f8c8cd3 | |||
ab1504f14f | |||
96501d38a9 | |||
124817e668 | |||
d59b0f3e27 | |||
d269e426e0 | |||
138d5b7b81 | |||
d443e533aa | |||
8a532d1575 | |||
5eef5917fd | |||
13ceb0f56b | |||
6926247bf4 | |||
641ad80211 | |||
39a2f29c29 | |||
db437be6e3 | |||
0a80be67f4 | |||
d66c3b6d84 | |||
6490c10c75 | |||
75203de743 | |||
80ad14bd14 | |||
0742056645 | |||
c3c001cf5b | |||
71d2e657d0 | |||
1d202c6afc | |||
9d4033d629 | |||
bdce86dc2e | |||
edb2286544 | |||
1d1cb582c0 | |||
287156197f | |||
408c98fb4b | |||
b8fc9d14a1 | |||
657b197c19 | |||
a5396bde70 | |||
e5457a5a1f | |||
b43910a496 | |||
f82b9dddc4 | |||
a1545b5079 | |||
25118e22a2 | |||
ba90af0dc5 | |||
7d3ba9f89e | |||
c17f589ec9 | |||
a5cf257a8a | |||
6171e0a923 | |||
cf702496ee | |||
bc82ff0ff9 | |||
6f676e692d | |||
ec829431fe | |||
a5b7c0fa33 | |||
cbbd7d28e1 | |||
3486365062 | |||
0f81cf8991 | |||
ceba855c01 | |||
b60c8560ce | |||
9fd37b2c8a | |||
01c5b7f7f5 | |||
f794f48f02 | |||
391398cf23 | |||
3a1c27b508 | |||
68d980bbb4 | |||
344af56868 | |||
f9cccd05b6 | |||
2812a87da7 | |||
c42360b5be | |||
d2fea6123f | |||
c8374fafe5 | |||
d75c61a5bd | |||
1ec003f10c | |||
a5e407cafb | |||
419b5e5e2a | |||
521ae562da | |||
304dd618b7 | |||
38de389a8e | |||
966c2fe46a | |||
4526c8b0a0 | |||
f34a90b3f7 | |||
076c347605 | |||
8c13cfa805 | |||
efd0fce7a1 | |||
18b1cf2942 | |||
90f37aaf7a | |||
8bb6e95b66 | |||
3d1c27d52e | |||
31268449b9 | |||
c085563270 | |||
09c0cf995b | |||
c864455ccf | |||
c72b0f3256 | |||
f7f8450041 | |||
a257e07ae4 | |||
f30cd4155e | |||
cccf9ad91d | |||
5097e6d1c6 | |||
5195335cf4 | |||
3ed4b22073 | |||
480b88ca37 | |||
97144424cc | |||
a9d9f8c542 | |||
bfad45fe45 | |||
3cdffce19f | |||
4ac2fdda2c | |||
6d2fd57f45 | |||
ea24cd106b | |||
3dbd7b54de | |||
89fd9dffad | |||
f8a112f08e | |||
f4b5d3fc51 | |||
c0d993903b | |||
53f275034a | |||
eae7c4111c | |||
ca338dc749 | |||
6c449fd5df | |||
86aa764f0b | |||
f1392d8208 | |||
24a8ffb3ea | |||
0c2d1aee54 | |||
e2bace8fa1 | |||
bf678fd9d6 | |||
ca367674c1 | |||
e5f4ec846c | |||
ebf2faca1e | |||
b8a9c2ba34 | |||
57f56be04f | |||
632cd6c4ba | |||
ebac797ac2 | |||
c0450f3c2a | |||
b5772da087 | |||
a8988e3cd1 | |||
fd11df1ec4 | |||
455edf197a | |||
742e15c638 | |||
08f52d69bd | |||
fb65ba418a | |||
86d5d3e809 | |||
5165033883 | |||
83e9ce95d7 | |||
9559b1a294 | |||
02ad0aa3b6 | |||
15ccae91db | |||
9b00827ac9 | |||
bc7bb0df28 | |||
2942be780f | |||
3d9445e3fc | |||
16312c6b06 | |||
d274b7b9f7 | |||
3ac9eb7ce3 | |||
dbe966aa57 | |||
a28eadff48 | |||
60cfab3d19 | |||
103d325887 | |||
8d2d94cfba | |||
825d3d96ce | |||
3a3842c669 | |||
8d3754751d | |||
fb5ef2c4ec | |||
34d80709ce | |||
15da298f72 | |||
2a71493447 | |||
3cb9c1835c | |||
f408aa4314 | |||
2786a11053 | |||
7a8fac57eb | |||
d46042e050 | |||
230a50ff1c | |||
3aa46725ed | |||
68cc3ad730 | |||
21c0be8496 | |||
728a70c036 | |||
a9b81d759a | |||
adef5c3550 | |||
ecf6a3c383 | |||
235080e125 | |||
5d70c6d797 | |||
6e3b596514 | |||
94ee3e9743 | |||
5b197b6c5f | |||
8312e2d852 | |||
ce7b311b92 | |||
a519129e99 | |||
4d3cb7d7ee | |||
a9a79ccc6e | |||
35d9425969 | |||
bcc8187b05 | |||
c4d0cccecf | |||
7bc8227d29 | |||
7666c3ef9a | |||
eccf15be6c | |||
b6d21592cb | |||
8e1467f97e | |||
19ceebd0f4 | |||
d4b31a15ff | |||
1dda994c46 | |||
84712bd624 | |||
cdb02d09f1 | |||
7dc7070426 | |||
8806435a77 | |||
38d6d9f6e0 | |||
e64d3d4e57 | |||
ca5bc202ac | |||
149a040794 | |||
72ddc8c645 | |||
42e20269ec | |||
a76decc476 | |||
59240d31c0 | |||
4fde550cb6 | |||
4ad9b44dea | |||
4344d08417 | |||
f7f4ef91cf | |||
0032e30f75 | |||
69866fd2e5 | |||
bebd8bc01e | |||
81de96af74 | |||
6d49e84daf | |||
9e71ad1b12 | |||
73f9ab6705 | |||
352715bd08 | |||
0d8b247cab | |||
3418f32387 | |||
122514a8da | |||
f1d75edec7 | |||
978c065555 | |||
e7787cd098 | |||
34adda3c88 | |||
b05d631b30 | |||
885b64d4e6 | |||
7164615f67 | |||
f19a74f10b | |||
01a2b51b26 | |||
02e0047e92 | |||
a5604aedb7 | |||
8547b34f92 | |||
f42010b657 | |||
312df0441b | |||
0ff4c69929 | |||
db80ad94d5 | |||
430d9e0b06 | |||
7bfb6a7dd3 | |||
0d755dff13 | |||
ea6987e078 | |||
1299e89dcd | |||
31b3c44db3 | |||
2d27ac4d29 | |||
0fa0f4cf02 | |||
98da6b13bc | |||
cb659c6054 | |||
2b70893928 | |||
f6f1cc77f4 | |||
11adde5127 | |||
e9905b15d4 | |||
581fa82420 | |||
cccd092fe0 | |||
930731ba0f | |||
d710442201 | |||
6ddc3816dd | |||
272b8d69dc | |||
7fa6de0ec1 | |||
a5071d49ba | |||
780b7983d0 | |||
a564a0b1ec | |||
094c48e0c5 | |||
eb857e2b71 | |||
7957516671 | |||
868e1e28ce | |||
1cca0817a0 | |||
6591f6dd9d | |||
530c915553 | |||
4c3aba9a15 | |||
3411d47a6a | |||
91d0398813 | |||
467747d55f | |||
bb52010442 | |||
56ffad2dad | |||
791402b453 | |||
92dfb53314 | |||
215c507f79 | |||
f89edbc6e4 | |||
14ecd9a992 | |||
909a6ff60a | |||
247363b9a7 | |||
523db95de2 | |||
52f31054fd | |||
b8fd1f03a6 | |||
83dc078055 | |||
2c74ee46ee | |||
c10a76ec71 | |||
7fb95ebe8f | |||
b92d2f0bc9 | |||
da89d8768c | |||
9ed5c774e4 | |||
a019fc9ff3 | |||
8c318bf414 | |||
8c40c00fac | |||
3a1b4661f5 | |||
17afd80d48 | |||
5dde3eb441 | |||
f182b7b921 | |||
2594a935de | |||
7a1c6beab0 | |||
98d83ef85f | |||
c470db6950 | |||
14193e449e | |||
6832595ccd | |||
c1dcad6942 | |||
f3c6077da0 | |||
4552d135f4 | |||
bb99899ca0 | |||
2f11ba7c98 | |||
75a4bc4a4e | |||
bbd9c776ea | |||
b7dd8404c5 | |||
879be3d812 | |||
29386db319 | |||
246757bacd | |||
bfa32317d2 | |||
e0856738e6 | |||
ceaf093942 | |||
d47c0ae422 | |||
0fbadbcced | |||
1e85027dee | |||
c1316a4cb1 | |||
b5c7c507c1 | |||
4b0c26f0af | |||
92a4d59c32 | |||
9db18ddd84 | |||
b1b2e83394 | |||
23a411b6bc | |||
c0389e3e37 | |||
3609bed9e7 | |||
a7e7dbd978 | |||
c72371f714 | |||
44a3b5839e | |||
fe3203bb5b | |||
5b0369366a | |||
c95ab2a39c | |||
15e34d1f07 | |||
03e6f7235b | |||
6de29b24b1 | |||
933ea8c5fa | |||
9dc6397187 | |||
f7ccec1b70 | |||
94fff6ff62 | |||
123dd72e80 | |||
2ed81b44be | |||
6f79bee3e3 | |||
ad2b3bc9f9 | |||
2a8a2b6148 | |||
ff75767558 | |||
8cbf551a48 | |||
5fc2281fcc | |||
1e9b3ef3d8 | |||
fa4373c11b | |||
a4d44979c6 | |||
217a7abc43 | |||
11c97bb066 | |||
03da4c7ca7 | |||
448111cbd4 | |||
5caf7d8376 | |||
56014a1a00 | |||
479b28fb6a | |||
e0900a686d | |||
3892df207d | |||
47c80c2050 | |||
9e05a0a37f | |||
102053abd8 | |||
11cfdb2394 | |||
dfeeb872d6 | |||
d28922bc03 | |||
2580420b7e | |||
5ac6ca3fa5 | |||
dbe3b7a9d0 | |||
f578e0f997 | |||
77c559c3cb | |||
b85d2cd8a5 | |||
9f88fa9165 | |||
8cd30c62d8 | |||
ebb8e8e300 | |||
00abeaee17 | |||
4baa213d88 | |||
607210e010 | |||
5eecb13fa3 | |||
de79e8c7e0 | |||
ab4e300919 | |||
64a0005a3b | |||
fcc112f406 | |||
de0c25bef4 | |||
368bfc0fe0 | |||
a807451a23 | |||
1a16776730 | |||
6da3885cc3 | |||
926884bf1f | |||
3296116041 | |||
e93ca40aa7 | |||
e6da0fa6a9 | |||
85232c97bf | |||
d2eafa0bb8 | |||
b8013581ce | |||
50e8837207 | |||
e09d8898d8 | |||
00dd6013b6 | |||
d832f4f71e | |||
e38f074d14 | |||
2407690ef9 | |||
f0e7d28e83 | |||
eb1497c1fb | |||
929792834f | |||
7a69e34a5c | |||
8246347b71 | |||
c6b891fb1c | |||
d4e4414451 | |||
025f2c63e4 | |||
c8a887af06 | |||
9e5ec378e3 | |||
82626799ca | |||
ed48787ec5 | |||
574ae3b1be | |||
a03f040dbf | |||
135a384cf3 | |||
0942b3b3f5 | |||
75655e5758 | |||
b78e3fc39f | |||
bed64e65cc | |||
8d28f41f66 | |||
628bacc3ce | |||
d03d2e9f26 | |||
5f52e61d74 | |||
037d6bd5c3 | |||
612a908514 | |||
ade531cfaa | |||
6bc9fc7c10 | |||
1ebb5ab3e1 | |||
5b1b57850c | |||
9f8cd6c499 | |||
596f9a1f21 | |||
dd79199a08 | |||
1ac7b459a4 | |||
689d63f487 | |||
df7dfc2404 |
2
Makefile
2
Makefile
|
@ -111,7 +111,7 @@ update_submodules:
|
|||
|
||||
# update the submodules to the latest at the most logical branch
|
||||
pull_submodules:
|
||||
@@git submodule foreach "git pull origin \$$(git branch --no-color --contains \$$(git rev-parse HEAD) | grep -v \( | head -1)"
|
||||
@@git submodule foreach "git pull \$$(git config remote.origin.url)"
|
||||
@@git submodule summary
|
||||
|
||||
pull: pull_submodules
|
||||
|
|
85
README.md
85
README.md
|
@ -1,4 +1,4 @@
|
|||
[jQuery](http://jquery.com/) - New Wave Javascript
|
||||
[jQuery](http://jquery.com/) - New Wave JavaScript
|
||||
==================================================
|
||||
|
||||
What you need to build your own jQuery
|
||||
|
@ -56,6 +56,89 @@ Sometimes, the various git repositories get into an inconsistent state where bui
|
|||
(usually this results in the jquery.js or jquery.min.js being 0 bytes). If this happens, run `make clean`, then
|
||||
run `make` again.
|
||||
|
||||
Git for dummies
|
||||
---------------
|
||||
|
||||
As the source code is handled by the version control system Git, it's useful to know some features used.
|
||||
|
||||
### Submodules ###
|
||||
|
||||
The repository uses submodules, which normally are handled directly by the Makefile, but sometimes you want to
|
||||
be able to work with them manually.
|
||||
|
||||
Following are the steps to manually get the submodules:
|
||||
|
||||
1. `git clone https://github.com/jquery/jquery.git`
|
||||
2. `git submodule init`
|
||||
3. `git submodule update`
|
||||
|
||||
Or:
|
||||
|
||||
1. `git clone https://github.com/jquery/jquery.git`
|
||||
2. `git submodule update --init`
|
||||
|
||||
Or:
|
||||
|
||||
1. `git clone --recursive https://github.com/jquery/jquery.git`
|
||||
|
||||
If you want to work inside a submodule, it is possible, but first you need to checkout a branch:
|
||||
|
||||
1. `cd src/sizzle`
|
||||
2. `git checkout master`
|
||||
|
||||
After you've committed your changes to the submodule, you'll update the jquery project to point to the new commit,
|
||||
but remember to push the submodule changes before pushing the new jquery commit:
|
||||
|
||||
1. `cd src/sizzle`
|
||||
2. `git push origin master`
|
||||
3. `cd ..`
|
||||
4. `git add src/sizzle`
|
||||
5. `git commit`
|
||||
|
||||
The makefile has some targets to simplify submodule handling:
|
||||
|
||||
#### `make update_submodules` ####
|
||||
|
||||
checks out the commit pointed to by jquery, but merges your local changes, if any. This target is executed
|
||||
when you are doing a normal `make`.
|
||||
|
||||
#### `make pull_submodules` ####
|
||||
|
||||
updates the content of the submodules to what is probably the latest upstream code.
|
||||
|
||||
#### `make pull` ####
|
||||
|
||||
make a `make pull_submodules` and after that a `git pull`. if you have no remote tracking in your master branch, you can
|
||||
execute this command as `make pull REMOTE=origin BRANCH=master` instead.
|
||||
|
||||
### 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):
|
||||
|
||||
1. `git reset --hard upstream/master`
|
||||
2. `git clean -fdx`
|
||||
|
||||
### 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:
|
||||
|
||||
* `git config branch.autosetuprebase local` (see `man git-config` for more information)
|
||||
|
||||
### 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
|
||||
|
||||
Questions?
|
||||
----------
|
||||
|
|
|
@ -182,8 +182,6 @@ var OPERATORS = array_to_hash([
|
|||
">>=",
|
||||
"<<=",
|
||||
">>>=",
|
||||
"~=",
|
||||
"%=",
|
||||
"|=",
|
||||
"^=",
|
||||
"&=",
|
||||
|
@ -191,7 +189,7 @@ var OPERATORS = array_to_hash([
|
|||
"||"
|
||||
]);
|
||||
|
||||
var WHITESPACE_CHARS = array_to_hash(characters(" \n\r\t"));
|
||||
var WHITESPACE_CHARS = array_to_hash(characters(" \n\r\t\u200b"));
|
||||
|
||||
var PUNC_BEFORE_EXPRESSION = array_to_hash(characters("[{}(,.;:"));
|
||||
|
||||
|
@ -201,20 +199,47 @@ var REGEXP_MODIFIERS = array_to_hash(characters("gmsiy"));
|
|||
|
||||
/* -----[ Tokenizer ]----- */
|
||||
|
||||
function is_alphanumeric_char(ch) {
|
||||
ch = ch.charCodeAt(0);
|
||||
return (ch >= 48 && ch <= 57) ||
|
||||
(ch >= 65 && ch <= 90) ||
|
||||
(ch >= 97 && ch <= 122);
|
||||
// regexps adapted from http://xregexp.com/plugins/#unicode
|
||||
var UNICODE = {
|
||||
letter: new RegExp("[\\u0041-\\u005A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u0523\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0621-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971\\u0972\\u097B-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D28\\u0D2A-\\u0D39\\u0D3D\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8B\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10D0-\\u10FA\\u10FC\\u1100-\\u1159\\u115F-\\u11A2\\u11A8-\\u11F9\\u1200-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u1676\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19A9\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u2094\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183\\u2184\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2C6F\\u2C71-\\u2C7D\\u2C80-\\u2CE4\\u2D00-\\u2D25\\u2D30-\\u2D65\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005\\u3006\\u3031-\\u3035\\u303B\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31B7\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FC3\\uA000-\\uA48C\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA65F\\uA662-\\uA66E\\uA67F-\\uA697\\uA717-\\uA71F\\uA722-\\uA788\\uA78B\\uA78C\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA90A-\\uA925\\uA930-\\uA946\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAC00\\uD7A3\\uF900-\\uFA2D\\uFA30-\\uFA6A\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),
|
||||
non_spacing_mark: new RegExp("[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065E\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0900-\\u0902\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0955\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F90-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFD-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26]"),
|
||||
space_combining_mark: new RegExp("[\\u0903\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"),
|
||||
connector_punctuation: new RegExp("[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]")
|
||||
};
|
||||
|
||||
function is_identifier_char(ch) {
|
||||
return is_alphanumeric_char(ch) || ch == "$" || ch == "_";
|
||||
function is_letter(ch) {
|
||||
return UNICODE.letter.test(ch);
|
||||
};
|
||||
|
||||
function is_digit(ch) {
|
||||
ch = ch.charCodeAt(0);
|
||||
return ch >= 48 && ch <= 57;
|
||||
return ch >= 48 && ch <= 57; //XXX: find out if "UnicodeDigit" means something else than 0..9
|
||||
};
|
||||
|
||||
function is_alphanumeric_char(ch) {
|
||||
return is_digit(ch) || is_letter(ch);
|
||||
};
|
||||
|
||||
function is_unicode_combining_mark(ch) {
|
||||
return UNICODE.non_spacing_mark.test(ch) || UNICODE.space_combining_mark.test(ch);
|
||||
};
|
||||
|
||||
function is_unicode_connector_punctuation(ch) {
|
||||
return UNICODE.connector_punctuation.test(ch);
|
||||
};
|
||||
|
||||
function is_identifier_start(ch) {
|
||||
return ch == "$" || ch == "_" || is_letter(ch);
|
||||
};
|
||||
|
||||
function is_identifier_char(ch) {
|
||||
return is_identifier_start(ch)
|
||||
|| is_unicode_combining_mark(ch)
|
||||
|| is_digit(ch)
|
||||
|| is_unicode_connector_punctuation(ch)
|
||||
|| ch == "\u200c" // zero-width non-joiner <ZWNJ>
|
||||
|| ch == "\u200d" // zero-width joiner <ZWJ> (in my ECMA-262 PDF, this is also 200c)
|
||||
;
|
||||
};
|
||||
|
||||
function parse_js_number(num) {
|
||||
|
@ -253,18 +278,19 @@ function is_token(token, type, val) {
|
|||
|
||||
var EX_EOF = {};
|
||||
|
||||
function tokenizer($TEXT, skip_comments) {
|
||||
function tokenizer($TEXT) {
|
||||
|
||||
var S = {
|
||||
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
|
||||
pos : 0,
|
||||
tokpos : 0,
|
||||
line : 0,
|
||||
tokline : 0,
|
||||
col : 0,
|
||||
tokcol : 0,
|
||||
newline_before : false,
|
||||
regex_allowed : false
|
||||
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, ''),
|
||||
pos : 0,
|
||||
tokpos : 0,
|
||||
line : 0,
|
||||
tokline : 0,
|
||||
col : 0,
|
||||
tokcol : 0,
|
||||
newline_before : false,
|
||||
regex_allowed : false,
|
||||
comments_before : []
|
||||
};
|
||||
|
||||
function peek() { return S.text.charAt(S.pos); };
|
||||
|
@ -299,7 +325,7 @@ function tokenizer($TEXT, skip_comments) {
|
|||
S.tokpos = S.pos;
|
||||
};
|
||||
|
||||
function token(type, value) {
|
||||
function token(type, value, is_comment) {
|
||||
S.regex_allowed = ((type == "operator" && !HOP(UNARY_POSTFIX, value)) ||
|
||||
(type == "keyword" && HOP(KEYWORDS_BEFORE_EXPRESSION, value)) ||
|
||||
(type == "punc" && HOP(PUNC_BEFORE_EXPRESSION, value)));
|
||||
|
@ -311,6 +337,10 @@ function tokenizer($TEXT, skip_comments) {
|
|||
pos : S.tokpos,
|
||||
nlb : S.newline_before
|
||||
};
|
||||
if (!is_comment) {
|
||||
ret.comments_before = S.comments_before;
|
||||
S.comments_before = [];
|
||||
}
|
||||
S.newline_before = false;
|
||||
return ret;
|
||||
};
|
||||
|
@ -351,7 +381,7 @@ function tokenizer($TEXT, skip_comments) {
|
|||
if (ch == "+") return after_e;
|
||||
after_e = false;
|
||||
if (ch == ".") {
|
||||
if (!has_dot)
|
||||
if (!has_dot && !has_x)
|
||||
return has_dot = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -417,7 +447,7 @@ function tokenizer($TEXT, skip_comments) {
|
|||
ret = S.text.substring(S.pos, i);
|
||||
S.pos = i;
|
||||
}
|
||||
return token("comment1", ret);
|
||||
return token("comment1", ret, true);
|
||||
};
|
||||
|
||||
function read_multiline_comment() {
|
||||
|
@ -425,14 +455,41 @@ function tokenizer($TEXT, skip_comments) {
|
|||
return with_eof_error("Unterminated multiline comment", function(){
|
||||
var i = find("*/", true),
|
||||
text = S.text.substring(S.pos, i),
|
||||
tok = token("comment2", text);
|
||||
tok = token("comment2", text, true);
|
||||
S.pos = i + 2;
|
||||
S.line += text.split("\n").length - 1;
|
||||
S.newline_before = text.indexOf("\n") >= 0;
|
||||
|
||||
// https://github.com/mishoo/UglifyJS/issues/#issue/100
|
||||
if (/^@cc_on/i.test(text)) {
|
||||
warn("WARNING: at line " + S.line);
|
||||
warn("*** Found \"conditional comment\": " + text);
|
||||
warn("*** UglifyJS DISCARDS ALL COMMENTS. This means your code might no longer work properly in Internet Explorer.");
|
||||
}
|
||||
|
||||
return tok;
|
||||
});
|
||||
};
|
||||
|
||||
function read_name() {
|
||||
var backslash = false, name = "", ch;
|
||||
while ((ch = peek()) != null) {
|
||||
if (!backslash) {
|
||||
if (ch == "\\") backslash = true, next();
|
||||
else if (is_identifier_char(ch)) name += next();
|
||||
else break;
|
||||
}
|
||||
else {
|
||||
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
||||
ch = read_escaped_char();
|
||||
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
||||
name += ch;
|
||||
backslash = false;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
function read_regexp() {
|
||||
return with_eof_error("Unterminated regular expression", function(){
|
||||
var prev_backslash = false, regexp = "", ch, in_class = false;
|
||||
|
@ -452,15 +509,14 @@ function tokenizer($TEXT, skip_comments) {
|
|||
} else {
|
||||
regexp += ch;
|
||||
}
|
||||
var mods = read_while(function(ch){
|
||||
return HOP(REGEXP_MODIFIERS, ch);
|
||||
});
|
||||
var mods = read_name();
|
||||
return token("regexp", [ regexp, mods ]);
|
||||
});
|
||||
};
|
||||
|
||||
function read_operator(prefix) {
|
||||
function grow(op) {
|
||||
if (!peek()) return op;
|
||||
var bigger = op + peek();
|
||||
if (HOP(OPERATORS, bigger)) {
|
||||
next();
|
||||
|
@ -472,19 +528,18 @@ function tokenizer($TEXT, skip_comments) {
|
|||
return token("operator", grow(prefix || next()));
|
||||
};
|
||||
|
||||
var handle_slash = skip_comments ? function() {
|
||||
function handle_slash() {
|
||||
next();
|
||||
var regex_allowed = S.regex_allowed;
|
||||
switch (peek()) {
|
||||
case "/": read_line_comment(); S.regex_allowed = regex_allowed; return next_token();
|
||||
case "*": read_multiline_comment(); S.regex_allowed = regex_allowed; return next_token();
|
||||
}
|
||||
return S.regex_allowed ? read_regexp() : read_operator("/");
|
||||
} : function() {
|
||||
next();
|
||||
switch (peek()) {
|
||||
case "/": return read_line_comment();
|
||||
case "*": return read_multiline_comment();
|
||||
case "/":
|
||||
S.comments_before.push(read_line_comment());
|
||||
S.regex_allowed = regex_allowed;
|
||||
return next_token();
|
||||
case "*":
|
||||
S.comments_before.push(read_multiline_comment());
|
||||
S.regex_allowed = regex_allowed;
|
||||
return next_token();
|
||||
}
|
||||
return S.regex_allowed ? read_regexp() : read_operator("/");
|
||||
};
|
||||
|
@ -497,7 +552,7 @@ function tokenizer($TEXT, skip_comments) {
|
|||
};
|
||||
|
||||
function read_word() {
|
||||
var word = read_while(is_identifier_char);
|
||||
var word = read_name();
|
||||
return !HOP(KEYWORDS, word)
|
||||
? token("name", word)
|
||||
: HOP(OPERATORS, word)
|
||||
|
@ -529,7 +584,7 @@ function tokenizer($TEXT, skip_comments) {
|
|||
if (ch == ".") return handle_dot();
|
||||
if (ch == "/") return handle_slash();
|
||||
if (HOP(OPERATOR_CHARS, ch)) return read_operator();
|
||||
if (is_identifier_char(ch)) return read_word();
|
||||
if (ch == "\\" || is_identifier_start(ch)) return read_word();
|
||||
parse_error("Unexpected character '" + ch + "'");
|
||||
};
|
||||
|
||||
|
@ -565,7 +620,7 @@ var ASSIGNMENT = (function(a, ret, i){
|
|||
}
|
||||
return ret;
|
||||
})(
|
||||
["+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "~=", "%=", "|=", "^=", "&="],
|
||||
["+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&="],
|
||||
{ "=": true },
|
||||
0
|
||||
);
|
||||
|
@ -608,16 +663,16 @@ function NodeWithToken(str, start, end) {
|
|||
|
||||
NodeWithToken.prototype.toString = function() { return this.name; };
|
||||
|
||||
function parse($TEXT, strict_mode, embed_tokens) {
|
||||
function parse($TEXT, exigent_mode, embed_tokens) {
|
||||
|
||||
var S = {
|
||||
input: tokenizer($TEXT, true),
|
||||
token: null,
|
||||
prev: null,
|
||||
peeked: null,
|
||||
in_function: 0,
|
||||
in_loop: 0,
|
||||
labels: []
|
||||
input : typeof $TEXT == "string" ? tokenizer($TEXT, true) : $TEXT,
|
||||
token : null,
|
||||
prev : null,
|
||||
peeked : null,
|
||||
in_function : 0,
|
||||
in_loop : 0,
|
||||
labels : []
|
||||
};
|
||||
|
||||
S.token = next();
|
||||
|
@ -671,7 +726,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
function expect(punc) { return expect_token("punc", punc); };
|
||||
|
||||
function can_insert_semicolon() {
|
||||
return !strict_mode && (
|
||||
return !exigent_mode && (
|
||||
S.token.nlb || is("eof") || is("punc", "}")
|
||||
);
|
||||
};
|
||||
|
@ -693,17 +748,20 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
};
|
||||
|
||||
function add_tokens(str, start, end) {
|
||||
return new NodeWithToken(str, start, end);
|
||||
return str instanceof NodeWithToken ? str : new NodeWithToken(str, start, end);
|
||||
};
|
||||
|
||||
var statement = embed_tokens ? function() {
|
||||
var start = S.token;
|
||||
var stmt = $statement();
|
||||
stmt[0] = add_tokens(stmt[0], start, prev());
|
||||
return stmt;
|
||||
} : $statement;
|
||||
function maybe_embed_tokens(parser) {
|
||||
if (embed_tokens) return function() {
|
||||
var start = S.token;
|
||||
var ast = parser.apply(this, arguments);
|
||||
ast[0] = add_tokens(ast[0], start, prev());
|
||||
return ast;
|
||||
};
|
||||
else return parser;
|
||||
};
|
||||
|
||||
function $statement() {
|
||||
var statement = maybe_embed_tokens(function() {
|
||||
if (is("operator", "/")) {
|
||||
S.peeked = null;
|
||||
S.token = S.input(true); // force regexp
|
||||
|
@ -797,12 +855,12 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
unexpected();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function labeled_statement(label) {
|
||||
S.labels.push(label);
|
||||
var start = S.token, stat = statement();
|
||||
if (strict_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0]))
|
||||
if (exigent_mode && !HOP(STATEMENTS_WITH_LABELS, stat[0]))
|
||||
unexpected(start);
|
||||
S.labels.pop();
|
||||
return as("label", label, stat);
|
||||
|
@ -827,29 +885,35 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
|
||||
function for_() {
|
||||
expect("(");
|
||||
var has_var = is("keyword", "var");
|
||||
if (has_var)
|
||||
next();
|
||||
if (is("name") && is_token(peek(), "operator", "in")) {
|
||||
// for (i in foo)
|
||||
var name = S.token.value;
|
||||
next(); next();
|
||||
var obj = expression();
|
||||
expect(")");
|
||||
return as("for-in", has_var, name, obj, in_loop(statement));
|
||||
} else {
|
||||
// classic for
|
||||
var init = is("punc", ";") ? null : has_var ? var_() : expression();
|
||||
expect(";");
|
||||
var test = is("punc", ";") ? null : expression();
|
||||
expect(";");
|
||||
var step = is("punc", ")") ? null : expression();
|
||||
expect(")");
|
||||
return as("for", init, test, step, in_loop(statement));
|
||||
var init = null;
|
||||
if (!is("punc", ";")) {
|
||||
init = is("keyword", "var")
|
||||
? (next(), var_(true))
|
||||
: expression(true, true);
|
||||
if (is("operator", "in"))
|
||||
return for_in(init);
|
||||
}
|
||||
return regular_for(init);
|
||||
};
|
||||
|
||||
function function_(in_statement) {
|
||||
function regular_for(init) {
|
||||
expect(";");
|
||||
var test = is("punc", ";") ? null : expression();
|
||||
expect(";");
|
||||
var step = is("punc", ")") ? null : expression();
|
||||
expect(")");
|
||||
return as("for", init, test, step, in_loop(statement));
|
||||
};
|
||||
|
||||
function for_in(init) {
|
||||
var lhs = init[0] == "var" ? as("name", init[1][0]) : init;
|
||||
next();
|
||||
var obj = expression();
|
||||
expect(")");
|
||||
return as("for-in", init, lhs, obj, in_loop(statement));
|
||||
};
|
||||
|
||||
var function_ = maybe_embed_tokens(function(in_statement) {
|
||||
var name = is("name") ? prog1(S.token.value, next) : null;
|
||||
if (in_statement && !name)
|
||||
unexpected();
|
||||
|
@ -877,7 +941,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
S.in_loop = loop;
|
||||
return a;
|
||||
})());
|
||||
};
|
||||
});
|
||||
|
||||
function if_() {
|
||||
var cond = parenthesised(), body = statement(), belse;
|
||||
|
@ -946,7 +1010,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
return as("try", body, bcatch, bfinally);
|
||||
};
|
||||
|
||||
function vardefs() {
|
||||
function vardefs(no_in) {
|
||||
var a = [];
|
||||
for (;;) {
|
||||
if (!is("name"))
|
||||
|
@ -955,7 +1019,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
next();
|
||||
if (is("operator", "=")) {
|
||||
next();
|
||||
a.push([ name, expression(false) ]);
|
||||
a.push([ name, expression(false, no_in) ]);
|
||||
} else {
|
||||
a.push([ name ]);
|
||||
}
|
||||
|
@ -966,8 +1030,8 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
return a;
|
||||
};
|
||||
|
||||
function var_() {
|
||||
return as("var", vardefs());
|
||||
function var_(no_in) {
|
||||
return as("var", vardefs(no_in));
|
||||
};
|
||||
|
||||
function const_() {
|
||||
|
@ -985,7 +1049,7 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
return subscripts(as("new", newexp, args), true);
|
||||
};
|
||||
|
||||
function expr_atom(allow_calls) {
|
||||
var expr_atom = maybe_embed_tokens(function(allow_calls) {
|
||||
if (is("operator", "new")) {
|
||||
next();
|
||||
return new_();
|
||||
|
@ -1020,29 +1084,32 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
return subscripts(prog1(atom, next), allow_calls);
|
||||
}
|
||||
unexpected();
|
||||
};
|
||||
});
|
||||
|
||||
function expr_list(closing, allow_trailing_comma) {
|
||||
function expr_list(closing, allow_trailing_comma, allow_empty) {
|
||||
var first = true, a = [];
|
||||
while (!is("punc", closing)) {
|
||||
if (first) first = false; else expect(",");
|
||||
if (allow_trailing_comma && is("punc", closing))
|
||||
break;
|
||||
a.push(expression(false));
|
||||
if (allow_trailing_comma && is("punc", closing)) break;
|
||||
if (is("punc", ",") && allow_empty) {
|
||||
a.push([ "atom", "undefined" ]);
|
||||
} else {
|
||||
a.push(expression(false));
|
||||
}
|
||||
}
|
||||
next();
|
||||
return a;
|
||||
};
|
||||
|
||||
function array_() {
|
||||
return as("array", expr_list("]", !strict_mode));
|
||||
return as("array", expr_list("]", !exigent_mode, true));
|
||||
};
|
||||
|
||||
function object_() {
|
||||
var first = true, a = [];
|
||||
while (!is("punc", "}")) {
|
||||
if (first) first = false; else expect(",");
|
||||
if (!strict_mode && is("punc", "}"))
|
||||
if (!exigent_mode && is("punc", "}"))
|
||||
// allow trailing comma
|
||||
break;
|
||||
var type = S.token.type;
|
||||
|
@ -1105,64 +1172,68 @@ function parse($TEXT, strict_mode, embed_tokens) {
|
|||
return as(tag, op, expr);
|
||||
};
|
||||
|
||||
function expr_op(left, min_prec) {
|
||||
function expr_op(left, min_prec, no_in) {
|
||||
var op = is("operator") ? S.token.value : null;
|
||||
if (op && op == "in" && no_in) op = null;
|
||||
var prec = op != null ? PRECEDENCE[op] : null;
|
||||
if (prec != null && prec > min_prec) {
|
||||
next();
|
||||
var right = expr_op(expr_atom(true), prec);
|
||||
return expr_op(as("binary", op, left, right), min_prec);
|
||||
var right = expr_op(expr_atom(true), prec, no_in);
|
||||
return expr_op(as("binary", op, left, right), min_prec, no_in);
|
||||
}
|
||||
return left;
|
||||
};
|
||||
|
||||
function expr_ops() {
|
||||
return expr_op(expr_atom(true), 0);
|
||||
function expr_ops(no_in) {
|
||||
return expr_op(expr_atom(true), 0, no_in);
|
||||
};
|
||||
|
||||
function maybe_conditional() {
|
||||
var expr = expr_ops();
|
||||
function maybe_conditional(no_in) {
|
||||
var expr = expr_ops(no_in);
|
||||
if (is("operator", "?")) {
|
||||
next();
|
||||
var yes = expression(false);
|
||||
expect(":");
|
||||
return as("conditional", expr, yes, expression(false));
|
||||
return as("conditional", expr, yes, expression(false, no_in));
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
|
||||
function is_assignable(expr) {
|
||||
if (!exigent_mode) return true;
|
||||
switch (expr[0]) {
|
||||
case "dot":
|
||||
case "sub":
|
||||
case "new":
|
||||
case "call":
|
||||
return true;
|
||||
case "name":
|
||||
return expr[1] != "this";
|
||||
}
|
||||
};
|
||||
|
||||
function maybe_assign() {
|
||||
var left = maybe_conditional(), val = S.token.value;
|
||||
function maybe_assign(no_in) {
|
||||
var left = maybe_conditional(no_in), val = S.token.value;
|
||||
if (is("operator") && HOP(ASSIGNMENT, val)) {
|
||||
if (is_assignable(left)) {
|
||||
next();
|
||||
return as("assign", ASSIGNMENT[val], left, maybe_assign());
|
||||
return as("assign", ASSIGNMENT[val], left, maybe_assign(no_in));
|
||||
}
|
||||
croak("Invalid assignment");
|
||||
}
|
||||
return left;
|
||||
};
|
||||
|
||||
function expression(commas) {
|
||||
var expression = maybe_embed_tokens(function(commas, no_in) {
|
||||
if (arguments.length == 0)
|
||||
commas = true;
|
||||
var expr = maybe_assign();
|
||||
var expr = maybe_assign(no_in);
|
||||
if (commas && is("punc", ",")) {
|
||||
next();
|
||||
return as("seq", expr, expression());
|
||||
return as("seq", expr, expression(true, no_in));
|
||||
}
|
||||
return expr;
|
||||
};
|
||||
});
|
||||
|
||||
function in_loop(cont) {
|
||||
try {
|
||||
|
@ -1222,6 +1293,8 @@ function HOP(obj, prop) {
|
|||
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||
};
|
||||
|
||||
var warn = function() {};
|
||||
|
||||
/* -----[ Exports ]----- */
|
||||
|
||||
exports.tokenizer = tokenizer;
|
||||
|
@ -1237,3 +1310,6 @@ exports.KEYWORDS = KEYWORDS;
|
|||
exports.ATOMIC_START_TOKEN = ATOMIC_START_TOKEN;
|
||||
exports.OPERATORS = OPERATORS;
|
||||
exports.is_alphanumeric_char = is_alphanumeric_char;
|
||||
exports.set_logger = function(logger) {
|
||||
warn = logger;
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,4 +4,4 @@ var print = require("sys").print,
|
|||
src = require("fs").readFileSync(process.argv[2], "utf8");
|
||||
|
||||
// Previously done in sed but reimplemented here due to portability issues
|
||||
print(src.replace(/^(\s*\*\/)(.+)/m, "$1\n$2;"));
|
||||
print( src.replace( /^(\s*\*\/)(.+)/m, "$1\n$2" ) + ";" );
|
||||
|
|
54
build/release-notes.js
Normal file
54
build/release-notes.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env node
|
||||
/*
|
||||
* jQuery Release Note Generator
|
||||
*/
|
||||
|
||||
var fs = require("fs"),
|
||||
http = require("http"),
|
||||
tmpl = require("mustache"),
|
||||
extract = /<a href="\/ticket\/(\d+)" title="View ticket">(.*?)<[^"]+"component">\s*(\S+)/g;
|
||||
|
||||
var opts = {
|
||||
version: "1.6.2 RC 1",
|
||||
short_version: "1.6.2rc1",
|
||||
final_version: "1.6.2",
|
||||
categories: []
|
||||
};
|
||||
|
||||
http.request({
|
||||
host: "bugs.jquery.com",
|
||||
port: 80,
|
||||
method: "GET",
|
||||
path: "/query?status=closed&resolution=fixed&component=!web&order=component&milestone=" + opts.final_version
|
||||
}, function (res) {
|
||||
var data = [];
|
||||
|
||||
res.on( "data", function( chunk ) {
|
||||
data.push( chunk );
|
||||
});
|
||||
|
||||
res.on( "end", function() {
|
||||
var match,
|
||||
file = data.join(""),
|
||||
cur;
|
||||
|
||||
while ( (match = extract.exec( file )) ) {
|
||||
if ( "#" + match[1] !== match[2] ) {
|
||||
var cat = match[3];
|
||||
|
||||
if ( !cur || cur.name !== cat ) {
|
||||
cur = { name: match[3], niceName: match[3].replace(/^./, function(a){ return a.toUpperCase(); }), bugs: [] };
|
||||
opts.categories.push( cur );
|
||||
}
|
||||
|
||||
cur.bugs.push({ ticket: match[1], title: match[2] });
|
||||
}
|
||||
}
|
||||
|
||||
buildNotes();
|
||||
});
|
||||
}).end();
|
||||
|
||||
function buildNotes() {
|
||||
console.log( tmpl.to_html( fs.readFileSync("release-notes.txt", "utf8"), opts ) );
|
||||
}
|
27
build/release-notes.txt
Normal file
27
build/release-notes.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
<h2>jQuery {{version}} Released</h2>
|
||||
|
||||
<p>This is a preview release of jQuery. We're releasing it so that everyone can start testing the code in their applications, making sure that there are no major problems.</p>
|
||||
|
||||
<p>You can get the code from the jQuery CDN:</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="http://code.jquery.com/jquery-{{short_version}}.js">http://code.jquery.com/jquery-{{short_version}}.js</a></li>
|
||||
</ul>
|
||||
|
||||
<p>You can help us by dropping that code into your existing application and letting us know that if anything no longer works. Please <a href="http://bugs.jquery.com/">file a bug</a> and be sure to mention that you're testing against jQuery {{version}}.</p>
|
||||
|
||||
<p>We want to encourage everyone from the community to try and <a href="http://docs.jquery.com/Getting_Involved">get involved</a> in contributing back to jQuery core. We've set up a <a href="http://docs.jquery.com/Getting_Involved">full page</a> of information dedicated towards becoming more involved with the team. The team is here and ready to help you help us!</p>
|
||||
|
||||
<h2>jQuery {{version}} Change Log</h2>
|
||||
|
||||
<p>The current change log of the {{version}} release.</p>
|
||||
|
||||
{{#categories}}
|
||||
<h3>{{niceName}}</h3>
|
||||
|
||||
<ul>
|
||||
{{#bugs}}
|
||||
<li><a href="http://bugs.jquery.com/ticket/{{ticket}}">#{{ticket}}</a>: {{title}}</li>
|
||||
{{/bugs}}
|
||||
</ul>
|
||||
{{/categories}}
|
169
build/release.js
Normal file
169
build/release.js
Normal file
|
@ -0,0 +1,169 @@
|
|||
#!/usr/bin/env node
|
||||
/*
|
||||
* jQuery Release Management
|
||||
*/
|
||||
|
||||
var fs = require("fs"),
|
||||
child = require("child_process"),
|
||||
debug = false;
|
||||
|
||||
var scpURL = "jqadmin@code.origin.jquery.com:/var/www/html/code.jquery.com/",
|
||||
cdnURL = "http://code.origin.jquery.com/",
|
||||
|
||||
version = /^[\d.]+(?:(?:a|b|rc)\d+|pre)?$/,
|
||||
versionFile = "version.txt",
|
||||
|
||||
file = "dist/jquery.js",
|
||||
minFile = "dist/jquery.min.js",
|
||||
|
||||
files = {
|
||||
"jquery-VER.js": file,
|
||||
"jquery-VER.min.js": minFile
|
||||
},
|
||||
|
||||
finalFiles = {
|
||||
"jquery.js": file,
|
||||
"jquery-latest.js": file,
|
||||
"jquery.min.js": minFile,
|
||||
"jquery-latest.min.js": minFile
|
||||
};
|
||||
|
||||
exec( "git pull && git status", function( error, stdout, stderr ) {
|
||||
if ( /Changes to be committed/i.test( stdout ) ) {
|
||||
exit( "Please commit changed files before attemping to push a release." );
|
||||
|
||||
} else if ( /Changes not staged for commit/i.test( stdout ) ) {
|
||||
exit( "Please stash files before attempting to push a release." );
|
||||
|
||||
} else {
|
||||
setVersion();
|
||||
}
|
||||
});
|
||||
|
||||
function setVersion() {
|
||||
var oldVersion = fs.readFileSync( versionFile, "utf8" );
|
||||
|
||||
prompt( "New Version (was " + oldVersion + "): ", function( data ) {
|
||||
if ( data && version.test( data ) ) {
|
||||
fs.writeFileSync( versionFile, data );
|
||||
|
||||
exec( "git commit -a -m 'Tagging the " + data + " release.' && git push && " +
|
||||
"git tag " + data + " && git push origin " + data, function() {
|
||||
make( data );
|
||||
});
|
||||
|
||||
} else {
|
||||
console.error( "Malformed version number, please try again." );
|
||||
setVersion();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function make( newVersion ) {
|
||||
exec( "make clean && make", function( error, stdout, stderr ) {
|
||||
// TODO: Verify JSLint
|
||||
|
||||
Object.keys( files ).forEach(function( oldName ) {
|
||||
var value = files[ oldName ], name = oldName.replace( /VER/g, newVersion );
|
||||
|
||||
copy( value, name );
|
||||
|
||||
delete files[ oldName ];
|
||||
files[ name ] = value;
|
||||
});
|
||||
|
||||
exec( "scp " + Object.keys( files ).join( " " ) + " " + scpURL, function() {
|
||||
setNextVersion( newVersion );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function setNextVersion( newVersion ) {
|
||||
var isFinal = false;
|
||||
|
||||
if ( /(?:a|b|rc)\d+$/.test( newVersion ) ) {
|
||||
newVersion = newVersion.replace( /(?:a|b|rc)\d+$/, "pre" );
|
||||
|
||||
} else if ( /^\d+\.\d+\.?(\d*)$/.test( newVersion ) ) {
|
||||
newVersion = newVersion.replace( /^(\d+\.\d+\.?)(\d*)$/, function( all, pre, num ) {
|
||||
return pre + (pre.charAt( pre.length - 1 ) !== "." ? "." : "") + (num ? parseFloat( num ) + 1 : 1) + "pre";
|
||||
});
|
||||
|
||||
isFinal = true;
|
||||
}
|
||||
|
||||
prompt( "Next Version [" + newVersion + "]: ", function( data ) {
|
||||
if ( !data ) {
|
||||
data = newVersion;
|
||||
}
|
||||
|
||||
if ( version.test( data ) ) {
|
||||
fs.writeFileSync( versionFile, data );
|
||||
|
||||
exec( "git commit -a -m 'Updating the source version to " + data + "' && git push", function() {
|
||||
if ( isFinal ) {
|
||||
makeFinal( newVersion );
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
console.error( "Malformed version number, please try again." );
|
||||
setNextVersion( newVersion );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function makeFinal( newVersion ) {
|
||||
var all = Object.keys( finalFiles );
|
||||
|
||||
// Copy all the files
|
||||
all.forEach(function( name ) {
|
||||
copy( finalFiles[ name ], name );
|
||||
});
|
||||
|
||||
// Upload files to CDN
|
||||
exec( "scp " + all.join( " " ) + " " + scpURL, function() {
|
||||
exec( "curl '" + cdnURL + "{" + all.join( "," ) + "}?reload'", function() {
|
||||
console.log( "Done." );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function copy( oldFile, newFile ) {
|
||||
if ( debug ) {
|
||||
console.log( "Copying " + oldFile + " to " + newFile );
|
||||
|
||||
} else {
|
||||
fs.writeFileSync( newFile, fs.readFileSync( oldFile, "utf8" ) );
|
||||
}
|
||||
}
|
||||
|
||||
function prompt( msg, callback ) {
|
||||
process.stdout.write( msg );
|
||||
|
||||
process.stdin.resume();
|
||||
process.stdin.setEncoding( "utf8" );
|
||||
|
||||
process.stdin.once( "data", function( chunk ) {
|
||||
process.stdin.pause();
|
||||
callback( chunk.replace( /\n*$/g, "" ) );
|
||||
});
|
||||
}
|
||||
|
||||
function exec( cmd, fn ) {
|
||||
if ( debug ) {
|
||||
console.log( cmd );
|
||||
fn();
|
||||
|
||||
} else {
|
||||
child.exec( cmd, fn );
|
||||
}
|
||||
}
|
||||
|
||||
function exit( msg ) {
|
||||
if ( msg ) {
|
||||
console.error( "\nError: " + msg );
|
||||
}
|
||||
|
||||
process.exit( 1 );
|
||||
}
|
176
build/uglify.js
176
build/uglify.js
|
@ -1,14 +1,10 @@
|
|||
#! /usr/bin/env node
|
||||
// -*- js2 -*-
|
||||
// -*- js -*-
|
||||
|
||||
global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
|
||||
var fs = require("fs"),
|
||||
jsp = require("./lib/parse-js"),
|
||||
pro = require("./lib/process");
|
||||
|
||||
pro.set_logger(function(msg){
|
||||
sys.debug(msg);
|
||||
});
|
||||
var fs = require("fs");
|
||||
var jsp = require("./lib/parse-js"),
|
||||
pro = require("./lib/process");
|
||||
|
||||
var options = {
|
||||
ast: false,
|
||||
|
@ -17,13 +13,16 @@ var options = {
|
|||
squeeze: true,
|
||||
make_seqs: true,
|
||||
dead_code: true,
|
||||
beautify: false,
|
||||
verbose: false,
|
||||
show_copyright: true,
|
||||
out_same_file: false,
|
||||
extra: false,
|
||||
unsafe: false, // XXX: extra & unsafe? but maybe we don't want both, so....
|
||||
beautify_options: {
|
||||
max_line_length: 32 * 1024,
|
||||
unsafe: false,
|
||||
reserved_names: null,
|
||||
defines: { },
|
||||
codegen_options: {
|
||||
ascii_only: false,
|
||||
beautify: false,
|
||||
indent_level: 4,
|
||||
indent_start: 0,
|
||||
quote_keys: false,
|
||||
|
@ -40,15 +39,15 @@ out: while (args.length > 0) {
|
|||
switch (v) {
|
||||
case "-b":
|
||||
case "--beautify":
|
||||
options.beautify = true;
|
||||
options.codegen_options.beautify = true;
|
||||
break;
|
||||
case "-i":
|
||||
case "--indent":
|
||||
options.beautify_options.indent_level = args.shift();
|
||||
options.codegen_options.indent_level = args.shift();
|
||||
break;
|
||||
case "-q":
|
||||
case "--quote-keys":
|
||||
options.beautify_options.quote_keys = true;
|
||||
options.codegen_options.quote_keys = true;
|
||||
break;
|
||||
case "-mt":
|
||||
case "--mangle-toplevel":
|
||||
|
@ -86,23 +85,109 @@ out: while (args.length > 0) {
|
|||
case "--ast":
|
||||
options.ast = true;
|
||||
break;
|
||||
case "--extra":
|
||||
options.extra = true;
|
||||
break;
|
||||
case "--unsafe":
|
||||
options.unsafe = true;
|
||||
break;
|
||||
case "--max-line-len":
|
||||
options.max_line_length = parseInt(args.shift(), 10);
|
||||
break;
|
||||
case "--reserved-names":
|
||||
options.reserved_names = args.shift().split(",");
|
||||
break;
|
||||
case "-d":
|
||||
case "--define":
|
||||
var defarg = args.shift();
|
||||
try {
|
||||
var defsym = function(sym) {
|
||||
// KEYWORDS_ATOM doesn't include NaN or Infinity - should we check
|
||||
// for them too ?? We don't check reserved words and the like as the
|
||||
// define values are only substituted AFTER parsing
|
||||
if (jsp.KEYWORDS_ATOM.hasOwnProperty(sym)) {
|
||||
throw "Don't define values for inbuilt constant '"+sym+"'";
|
||||
}
|
||||
return sym;
|
||||
},
|
||||
defval = function(v) {
|
||||
if (v.match(/^"(.*)"$/) || v.match(/^'(.*)'$/)) {
|
||||
return [ "string", RegExp.$1 ];
|
||||
}
|
||||
else if (!isNaN(parseFloat(v))) {
|
||||
return [ "num", parseFloat(v) ];
|
||||
}
|
||||
else if (v.match(/^[a-z\$_][a-z\$_0-9]*$/i)) {
|
||||
return [ "name", v ];
|
||||
}
|
||||
else if (!v.match(/"/)) {
|
||||
return [ "string", v ];
|
||||
}
|
||||
else if (!v.match(/'/)) {
|
||||
return [ "string", v ];
|
||||
}
|
||||
throw "Can't understand the specified value: "+v;
|
||||
};
|
||||
if (defarg.match(/^([a-z_\$][a-z_\$0-9]*)(=(.*))?$/i)) {
|
||||
var sym = defsym(RegExp.$1),
|
||||
val = RegExp.$2 ? defval(RegExp.$2.substr(1)) : [ 'name', 'true' ];
|
||||
options.defines[sym] = val;
|
||||
}
|
||||
else {
|
||||
throw "The --define option expects SYMBOL[=value]";
|
||||
}
|
||||
} catch(ex) {
|
||||
sys.print("ERROR: In option --define "+defarg+"\n"+ex+"\n");
|
||||
process.exit(1);
|
||||
}
|
||||
break;
|
||||
case "--define-from-module":
|
||||
var defmodarg = args.shift(),
|
||||
defmodule = require(defmodarg),
|
||||
sym,
|
||||
val;
|
||||
for (sym in defmodule) {
|
||||
if (defmodule.hasOwnProperty(sym)) {
|
||||
options.defines[sym] = function(val) {
|
||||
if (typeof val == "string")
|
||||
return [ "string", val ];
|
||||
if (typeof val == "number")
|
||||
return [ "num", val ];
|
||||
if (val === true)
|
||||
return [ 'name', 'true' ];
|
||||
if (val === false)
|
||||
return [ 'name', 'false' ];
|
||||
if (val === null)
|
||||
return [ 'name', 'null' ];
|
||||
if (val === undefined)
|
||||
return [ 'name', 'undefined' ];
|
||||
sys.print("ERROR: In option --define-from-module "+defmodarg+"\n");
|
||||
sys.print("ERROR: Unknown object type for: "+sym+"="+val+"\n");
|
||||
process.exit(1);
|
||||
return null;
|
||||
}(defmodule[sym]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "--ascii":
|
||||
options.codegen_options.ascii_only = true;
|
||||
break;
|
||||
default:
|
||||
filename = v;
|
||||
break out;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.verbose) {
|
||||
pro.set_logger(function(msg){
|
||||
sys.debug(msg);
|
||||
});
|
||||
}
|
||||
|
||||
jsp.set_logger(function(msg){
|
||||
sys.debug(msg);
|
||||
});
|
||||
|
||||
if (filename) {
|
||||
fs.readFile(filename, "utf8", function(err, text){
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
if (err) throw err;
|
||||
output(squeeze_it(text));
|
||||
});
|
||||
} else {
|
||||
|
@ -131,7 +216,9 @@ function output(text) {
|
|||
});
|
||||
}
|
||||
out.write(text);
|
||||
out.end();
|
||||
if (options.output !== true) {
|
||||
out.end();
|
||||
}
|
||||
};
|
||||
|
||||
// --------- main ends here.
|
||||
|
@ -152,36 +239,35 @@ function show_copyright(comments) {
|
|||
function squeeze_it(code) {
|
||||
var result = "";
|
||||
if (options.show_copyright) {
|
||||
var initial_comments = [];
|
||||
// keep first comment
|
||||
var tok = jsp.tokenizer(code, false), c;
|
||||
var tok = jsp.tokenizer(code), c;
|
||||
c = tok();
|
||||
var prev = null;
|
||||
while (/^comment/.test(c.type) && (!prev || prev == c.type)) {
|
||||
initial_comments.push(c);
|
||||
prev = c.type;
|
||||
c = tok();
|
||||
}
|
||||
result += show_copyright(initial_comments);
|
||||
result += show_copyright(c.comments_before);
|
||||
}
|
||||
try {
|
||||
var ast = time_it("parse", function(){ return jsp.parse(code); });
|
||||
if (options.mangle)
|
||||
ast = time_it("mangle", function(){ return pro.ast_mangle(ast, options.mangle_toplevel); });
|
||||
if (options.squeeze)
|
||||
ast = time_it("squeeze", function(){
|
||||
ast = pro.ast_squeeze(ast, {
|
||||
make_seqs : options.make_seqs,
|
||||
dead_code : options.dead_code,
|
||||
extra : options.extra
|
||||
});
|
||||
if (options.unsafe)
|
||||
ast = pro.ast_squeeze_more(ast);
|
||||
return ast;
|
||||
if (options.mangle) ast = time_it("mangle", function(){
|
||||
return pro.ast_mangle(ast, {
|
||||
toplevel: options.mangle_toplevel,
|
||||
defines: options.defines,
|
||||
except: options.reserved_names
|
||||
});
|
||||
});
|
||||
if (options.squeeze) ast = time_it("squeeze", function(){
|
||||
ast = pro.ast_squeeze(ast, {
|
||||
make_seqs : options.make_seqs,
|
||||
dead_code : options.dead_code,
|
||||
keep_comps : !options.unsafe
|
||||
});
|
||||
if (options.unsafe)
|
||||
ast = pro.ast_squeeze_more(ast);
|
||||
return ast;
|
||||
});
|
||||
if (options.ast)
|
||||
return sys.inspect(ast, null, null);
|
||||
result += time_it("generate", function(){ return pro.gen_code(ast, options.beautify && options.beautify_options) });
|
||||
result += time_it("generate", function(){ return pro.gen_code(ast, options.codegen_options) });
|
||||
if (!options.codegen_options.beautify && options.max_line_length) {
|
||||
result = time_it("split", function(){ return pro.split_lines(result, options.max_line_length) });
|
||||
}
|
||||
return result;
|
||||
} catch(ex) {
|
||||
sys.debug(ex.stack);
|
||||
|
|
57
src/ajax.js
57
src/ajax.js
|
@ -5,9 +5,9 @@ var r20 = /%20/g,
|
|||
rCRLF = /\r?\n/g,
|
||||
rhash = /#.*$/,
|
||||
rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
|
||||
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
||||
rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
|
||||
// #7653, #8125, #8152: local protocol detection
|
||||
rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|widget):$/,
|
||||
rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,
|
||||
rnoContent = /^(?:GET|HEAD)$/,
|
||||
rprotocol = /^\/\//,
|
||||
rquery = /\?/,
|
||||
|
@ -15,10 +15,6 @@ var r20 = /%20/g,
|
|||
rselectTextarea = /^(?:select|textarea)/i,
|
||||
rspacesAjax = /\s+/,
|
||||
rts = /([?&])_=[^&]*/,
|
||||
rucHeaders = /(^|\-)([a-z])/g,
|
||||
rucHeadersFunc = function( _, $1, $2 ) {
|
||||
return $1 + $2.toUpperCase();
|
||||
},
|
||||
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
|
||||
|
||||
// Keep a copy of the old load method
|
||||
|
@ -49,9 +45,9 @@ var r20 = /%20/g,
|
|||
ajaxLocParts;
|
||||
|
||||
// #8138, IE may throw an exception when accessing
|
||||
// a field from document.location if document.domain has been set
|
||||
// a field from window.location if document.domain has been set
|
||||
try {
|
||||
ajaxLocation = document.location.href;
|
||||
ajaxLocation = location.href;
|
||||
} catch( e ) {
|
||||
// Use the href attribute of an A element
|
||||
// since IE will modify it given document.location
|
||||
|
@ -99,7 +95,7 @@ function addToPrefiltersOrTransports( structure ) {
|
|||
};
|
||||
}
|
||||
|
||||
//Base inspection function for prefilters and transports
|
||||
// Base inspection function for prefilters and transports
|
||||
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
|
||||
dataType /* internal */, inspected /* internal */ ) {
|
||||
|
||||
|
@ -248,7 +244,7 @@ jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".sp
|
|||
jQuery.fn[ o ] = function( f ){
|
||||
return this.bind( o, f );
|
||||
};
|
||||
} );
|
||||
});
|
||||
|
||||
jQuery.each( [ "get", "post" ], function( i, method ) {
|
||||
jQuery[ method ] = function( url, data, callback, type ) {
|
||||
|
@ -267,7 +263,7 @@ jQuery.each( [ "get", "post" ], function( i, method ) {
|
|||
dataType: type
|
||||
});
|
||||
};
|
||||
} );
|
||||
});
|
||||
|
||||
jQuery.extend({
|
||||
|
||||
|
@ -393,6 +389,7 @@ jQuery.extend({
|
|||
ifModifiedKey,
|
||||
// Headers (they are sent all at once)
|
||||
requestHeaders = {},
|
||||
requestHeadersNames = {},
|
||||
// Response headers
|
||||
responseHeadersString,
|
||||
responseHeaders,
|
||||
|
@ -416,7 +413,9 @@ jQuery.extend({
|
|||
// Caches the header
|
||||
setRequestHeader: function( name, value ) {
|
||||
if ( !state ) {
|
||||
requestHeaders[ name.toLowerCase().replace( rucHeaders, rucHeadersFunc ) ] = value;
|
||||
var lname = name.toLowerCase();
|
||||
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
|
||||
requestHeaders[ name ] = value;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
@ -645,6 +644,8 @@ jQuery.extend({
|
|||
// If data is available, append data to url
|
||||
if ( s.data ) {
|
||||
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
|
||||
// #9682: remove data so that it's not used in an eventual retry
|
||||
delete s.data;
|
||||
}
|
||||
|
||||
// Get ifModifiedKey before adding the anti-cache parameter
|
||||
|
@ -664,24 +665,27 @@ jQuery.extend({
|
|||
|
||||
// Set the correct header, if data is being sent
|
||||
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
||||
requestHeaders[ "Content-Type" ] = s.contentType;
|
||||
jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
||||
}
|
||||
|
||||
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
||||
if ( s.ifModified ) {
|
||||
ifModifiedKey = ifModifiedKey || s.url;
|
||||
if ( jQuery.lastModified[ ifModifiedKey ] ) {
|
||||
requestHeaders[ "If-Modified-Since" ] = jQuery.lastModified[ ifModifiedKey ];
|
||||
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
|
||||
}
|
||||
if ( jQuery.etag[ ifModifiedKey ] ) {
|
||||
requestHeaders[ "If-None-Match" ] = jQuery.etag[ ifModifiedKey ];
|
||||
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
|
||||
}
|
||||
}
|
||||
|
||||
// Set the Accepts header for the server, depending on the dataType
|
||||
requestHeaders.Accept = s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
||||
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
||||
s.accepts[ "*" ];
|
||||
jqXHR.setRequestHeader(
|
||||
"Accept",
|
||||
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
|
||||
s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", */*; q=0.01" : "" ) :
|
||||
s.accepts[ "*" ]
|
||||
);
|
||||
|
||||
// Check for headers option
|
||||
for ( i in s.headers ) {
|
||||
|
@ -725,7 +729,7 @@ jQuery.extend({
|
|||
transport.send( requestHeaders, done );
|
||||
} catch (e) {
|
||||
// Propagate exception as error if not done
|
||||
if ( status < 2 ) {
|
||||
if ( state < 2 ) {
|
||||
done( -1, e );
|
||||
// Simply rethrow otherwise
|
||||
} else {
|
||||
|
@ -757,7 +761,7 @@ jQuery.extend({
|
|||
// Serialize the form elements
|
||||
jQuery.each( a, function() {
|
||||
add( this.name, this.value );
|
||||
} );
|
||||
});
|
||||
|
||||
} else {
|
||||
// If traditional, encode the "old" way (the way 1.3.2 or older
|
||||
|
@ -773,7 +777,7 @@ jQuery.extend({
|
|||
});
|
||||
|
||||
function buildParams( prefix, obj, traditional, add ) {
|
||||
if ( jQuery.isArray( obj ) && obj.length ) {
|
||||
if ( jQuery.isArray( obj ) ) {
|
||||
// Serialize array item.
|
||||
jQuery.each( obj, function( i, v ) {
|
||||
if ( traditional || rbracket.test( prefix ) ) {
|
||||
|
@ -793,16 +797,9 @@ function buildParams( prefix, obj, traditional, add ) {
|
|||
});
|
||||
|
||||
} else if ( !traditional && obj != null && typeof obj === "object" ) {
|
||||
// If we see an array here, it is empty and should be treated as an empty
|
||||
// object
|
||||
if ( jQuery.isArray( obj ) || jQuery.isEmptyObject( obj ) ) {
|
||||
add( prefix, "" );
|
||||
|
||||
// Serialize object item.
|
||||
} else {
|
||||
for ( var name in obj ) {
|
||||
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
||||
}
|
||||
for ( var name in obj ) {
|
||||
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -14,13 +14,12 @@ jQuery.ajaxSetup({
|
|||
// Detect, normalize options and install callbacks for jsonp requests
|
||||
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
||||
|
||||
var dataIsString = ( typeof s.data === "string" );
|
||||
var inspectData = s.contentType === "application/x-www-form-urlencoded" &&
|
||||
( typeof s.data === "string" );
|
||||
|
||||
if ( s.dataTypes[ 0 ] === "jsonp" ||
|
||||
originalSettings.jsonpCallback ||
|
||||
originalSettings.jsonp != null ||
|
||||
s.jsonp !== false && ( jsre.test( s.url ) ||
|
||||
dataIsString && jsre.test( s.data ) ) ) {
|
||||
inspectData && jsre.test( s.data ) ) ) {
|
||||
|
||||
var responseContainer,
|
||||
jsonpCallback = s.jsonpCallback =
|
||||
|
@ -28,20 +27,12 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|||
previous = window[ jsonpCallback ],
|
||||
url = s.url,
|
||||
data = s.data,
|
||||
replace = "$1" + jsonpCallback + "$2",
|
||||
cleanUp = function() {
|
||||
// Set callback back to previous value
|
||||
window[ jsonpCallback ] = previous;
|
||||
// Call if it was a function and we have a response
|
||||
if ( responseContainer && jQuery.isFunction( previous ) ) {
|
||||
window[ jsonpCallback ]( responseContainer[ 0 ] );
|
||||
}
|
||||
};
|
||||
replace = "$1" + jsonpCallback + "$2";
|
||||
|
||||
if ( s.jsonp !== false ) {
|
||||
url = url.replace( jsre, replace );
|
||||
if ( s.url === url ) {
|
||||
if ( dataIsString ) {
|
||||
if ( inspectData ) {
|
||||
data = data.replace( jsre, replace );
|
||||
}
|
||||
if ( s.data === data ) {
|
||||
|
@ -59,8 +50,15 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|||
responseContainer = [ response ];
|
||||
};
|
||||
|
||||
// Install cleanUp function
|
||||
jqXHR.then( cleanUp, cleanUp );
|
||||
// Clean-up function
|
||||
jqXHR.always(function() {
|
||||
// Set callback back to previous value
|
||||
window[ jsonpCallback ] = previous;
|
||||
// Call if it was a function and we have a response
|
||||
if ( responseContainer && jQuery.isFunction( previous ) ) {
|
||||
window[ jsonpCallback ]( responseContainer[ 0 ] );
|
||||
}
|
||||
});
|
||||
|
||||
// Use data converter to retrieve json after script execution
|
||||
s.converters["script json"] = function() {
|
||||
|
@ -76,6 +74,6 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|||
// Delegate to script
|
||||
return "script";
|
||||
}
|
||||
} );
|
||||
});
|
||||
|
||||
})( jQuery );
|
||||
|
|
|
@ -25,7 +25,7 @@ jQuery.ajaxPrefilter( "script", function( s ) {
|
|||
s.type = "GET";
|
||||
s.global = false;
|
||||
}
|
||||
} );
|
||||
});
|
||||
|
||||
// Bind script tag hack transport
|
||||
jQuery.ajaxTransport( "script", function(s) {
|
||||
|
@ -53,7 +53,7 @@ jQuery.ajaxTransport( "script", function(s) {
|
|||
// Attach handlers for all browsers
|
||||
script.onload = script.onreadystatechange = function( _, isAbort ) {
|
||||
|
||||
if ( !script.readyState || /loaded|complete/.test( script.readyState ) ) {
|
||||
if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
|
||||
|
||||
// Handle memory leak in IE
|
||||
script.onload = script.onreadystatechange = null;
|
||||
|
@ -84,6 +84,6 @@ jQuery.ajaxTransport( "script", function(s) {
|
|||
}
|
||||
};
|
||||
}
|
||||
} );
|
||||
});
|
||||
|
||||
})( jQuery );
|
||||
|
|
|
@ -1,21 +1,14 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var // #5280: next active xhr id and list of active xhrs' callbacks
|
||||
xhrId = jQuery.now(),
|
||||
xhrCallbacks,
|
||||
|
||||
// XHR used to determine supports properties
|
||||
testXHR;
|
||||
|
||||
// #5280: Internet Explorer will keep connections alive if we don't abort on unload
|
||||
function xhrOnUnloadAbort() {
|
||||
jQuery( window ).unload(function() {
|
||||
var // #5280: Internet Explorer will keep connections alive if we don't abort on unload
|
||||
xhrOnUnloadAbort = window.ActiveXObject ? function() {
|
||||
// Abort all pending requests
|
||||
for ( var key in xhrCallbacks ) {
|
||||
xhrCallbacks[ key ]( 0, 1 );
|
||||
}
|
||||
});
|
||||
}
|
||||
} : false,
|
||||
xhrId = 0,
|
||||
xhrCallbacks;
|
||||
|
||||
// Functions to create xhrs
|
||||
function createStandardXHR() {
|
||||
|
@ -45,15 +38,13 @@ jQuery.ajaxSettings.xhr = window.ActiveXObject ?
|
|||
// For all other browsers, use the standard XMLHttpRequest object
|
||||
createStandardXHR;
|
||||
|
||||
// Test if we can create an xhr object
|
||||
testXHR = jQuery.ajaxSettings.xhr();
|
||||
jQuery.support.ajax = !!testXHR;
|
||||
|
||||
// Does this browser support crossDomain XHR requests
|
||||
jQuery.support.cors = testXHR && ( "withCredentials" in testXHR );
|
||||
|
||||
// No need for the temporary xhr anymore
|
||||
testXHR = undefined;
|
||||
// Determine support properties
|
||||
(function( xhr ) {
|
||||
jQuery.extend( jQuery.support, {
|
||||
ajax: !!xhr,
|
||||
cors: !!xhr && ( "withCredentials" in xhr )
|
||||
});
|
||||
})( jQuery.ajaxSettings.xhr() );
|
||||
|
||||
// Create transport if the browser can provide an xhr
|
||||
if ( jQuery.support.ajax ) {
|
||||
|
@ -136,7 +127,9 @@ if ( jQuery.support.ajax ) {
|
|||
// Do not keep as active anymore
|
||||
if ( handle ) {
|
||||
xhr.onreadystatechange = jQuery.noop;
|
||||
delete xhrCallbacks[ handle ];
|
||||
if ( xhrOnUnloadAbort ) {
|
||||
delete xhrCallbacks[ handle ];
|
||||
}
|
||||
}
|
||||
|
||||
// If it's an abort
|
||||
|
@ -197,15 +190,18 @@ if ( jQuery.support.ajax ) {
|
|||
if ( !s.async || xhr.readyState === 4 ) {
|
||||
callback();
|
||||
} else {
|
||||
// Create the active xhrs callbacks list if needed
|
||||
// and attach the unload handler
|
||||
if ( !xhrCallbacks ) {
|
||||
xhrCallbacks = {};
|
||||
xhrOnUnloadAbort();
|
||||
handle = ++xhrId;
|
||||
if ( xhrOnUnloadAbort ) {
|
||||
// Create the active xhrs callbacks list if needed
|
||||
// and attach the unload handler
|
||||
if ( !xhrCallbacks ) {
|
||||
xhrCallbacks = {};
|
||||
jQuery( window ).unload( xhrOnUnloadAbort );
|
||||
}
|
||||
// Add to list of active xhrs callbacks
|
||||
xhrCallbacks[ handle ] = callback;
|
||||
}
|
||||
// Add to list of active xhrs callbacks
|
||||
handle = xhrId++;
|
||||
xhr.onreadystatechange = xhrCallbacks[ handle ] = callback;
|
||||
xhr.onreadystatechange = callback;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -1,66 +1,67 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var rclass = /[\n\t\r]/g,
|
||||
rspaces = /\s+/,
|
||||
rspace = /\s+/,
|
||||
rreturn = /\r/g,
|
||||
rspecialurl = /^(?:href|src|style)$/,
|
||||
rtype = /^(?:button|input)$/i,
|
||||
rfocusable = /^(?:button|input|object|select|textarea)$/i,
|
||||
rclickable = /^a(?:rea)?$/i,
|
||||
rradiocheck = /^(?:radio|checkbox)$/i;
|
||||
|
||||
jQuery.props = {
|
||||
"for": "htmlFor",
|
||||
"class": "className",
|
||||
readonly: "readOnly",
|
||||
maxlength: "maxLength",
|
||||
cellspacing: "cellSpacing",
|
||||
rowspan: "rowSpan",
|
||||
colspan: "colSpan",
|
||||
tabindex: "tabIndex",
|
||||
usemap: "useMap",
|
||||
frameborder: "frameBorder"
|
||||
};
|
||||
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
|
||||
rinvalidChar = /\:|^on/,
|
||||
formHook, boolHook;
|
||||
|
||||
jQuery.fn.extend({
|
||||
attr: function( name, value ) {
|
||||
return jQuery.access( this, name, value, true, jQuery.attr );
|
||||
},
|
||||
|
||||
removeAttr: function( name, fn ) {
|
||||
return this.each(function(){
|
||||
jQuery.attr( this, name, "" );
|
||||
if ( this.nodeType === 1 ) {
|
||||
this.removeAttribute( name );
|
||||
}
|
||||
removeAttr: function( name ) {
|
||||
return this.each(function() {
|
||||
jQuery.removeAttr( this, name );
|
||||
});
|
||||
},
|
||||
|
||||
prop: function( name, value ) {
|
||||
return jQuery.access( this, name, value, true, jQuery.prop );
|
||||
},
|
||||
|
||||
removeProp: function( name ) {
|
||||
name = jQuery.propFix[ name ] || name;
|
||||
return this.each(function() {
|
||||
// try/catch handles cases where IE balks (such as removing a property on window)
|
||||
try {
|
||||
this[ name ] = undefined;
|
||||
delete this[ name ];
|
||||
} catch( e ) {}
|
||||
});
|
||||
},
|
||||
|
||||
addClass: function( value ) {
|
||||
if ( jQuery.isFunction(value) ) {
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
self.addClass( value.call(this, i, self.attr("class")) );
|
||||
var classNames, i, l, elem,
|
||||
setClass, c, cl;
|
||||
|
||||
if ( jQuery.isFunction( value ) ) {
|
||||
return this.each(function( j ) {
|
||||
jQuery( this ).addClass( value.call(this, j, this.className) );
|
||||
});
|
||||
}
|
||||
|
||||
if ( value && typeof value === "string" ) {
|
||||
var classNames = (value || "").split( rspaces );
|
||||
classNames = value.split( rspace );
|
||||
|
||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||
var elem = this[i];
|
||||
for ( i = 0, l = this.length; i < l; i++ ) {
|
||||
elem = this[ i ];
|
||||
|
||||
if ( elem.nodeType === 1 ) {
|
||||
if ( !elem.className ) {
|
||||
if ( !elem.className && classNames.length === 1 ) {
|
||||
elem.className = value;
|
||||
|
||||
} else {
|
||||
var className = " " + elem.className + " ",
|
||||
setClass = elem.className;
|
||||
setClass = " " + elem.className + " ";
|
||||
|
||||
for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
|
||||
if ( className.indexOf( " " + classNames[c] + " " ) < 0 ) {
|
||||
setClass += " " + classNames[c];
|
||||
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
|
||||
if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
|
||||
setClass += classNames[ c ] + " ";
|
||||
}
|
||||
}
|
||||
elem.className = jQuery.trim( setClass );
|
||||
|
@ -73,24 +74,25 @@ jQuery.fn.extend({
|
|||
},
|
||||
|
||||
removeClass: function( value ) {
|
||||
if ( jQuery.isFunction(value) ) {
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
self.removeClass( value.call(this, i, self.attr("class")) );
|
||||
var classNames, i, l, elem, className, c, cl;
|
||||
|
||||
if ( jQuery.isFunction( value ) ) {
|
||||
return this.each(function( j ) {
|
||||
jQuery( this ).removeClass( value.call(this, j, this.className) );
|
||||
});
|
||||
}
|
||||
|
||||
if ( (value && typeof value === "string") || value === undefined ) {
|
||||
var classNames = (value || "").split( rspaces );
|
||||
classNames = (value || "").split( rspace );
|
||||
|
||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||
var elem = this[i];
|
||||
for ( i = 0, l = this.length; i < l; i++ ) {
|
||||
elem = this[ i ];
|
||||
|
||||
if ( elem.nodeType === 1 && elem.className ) {
|
||||
if ( value ) {
|
||||
var className = (" " + elem.className + " ").replace(rclass, " ");
|
||||
for ( var c = 0, cl = classNames.length; c < cl; c++ ) {
|
||||
className = className.replace(" " + classNames[c] + " ", " ");
|
||||
className = (" " + elem.className + " ").replace( rclass, " " );
|
||||
for ( c = 0, cl = classNames.length; c < cl; c++ ) {
|
||||
className = className.replace(" " + classNames[ c ] + " ", " ");
|
||||
}
|
||||
elem.className = jQuery.trim( className );
|
||||
|
||||
|
@ -109,9 +111,8 @@ jQuery.fn.extend({
|
|||
isBool = typeof stateVal === "boolean";
|
||||
|
||||
if ( jQuery.isFunction( value ) ) {
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this);
|
||||
self.toggleClass( value.call(this, i, self.attr("class"), stateVal), stateVal );
|
||||
return this.each(function( i ) {
|
||||
jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -122,7 +123,7 @@ jQuery.fn.extend({
|
|||
i = 0,
|
||||
self = jQuery( this ),
|
||||
state = stateVal,
|
||||
classNames = value.split( rspaces );
|
||||
classNames = value.split( rspace );
|
||||
|
||||
while ( (className = classNames[ i++ ]) ) {
|
||||
// check each className given, space seperated list
|
||||
|
@ -154,82 +155,42 @@ jQuery.fn.extend({
|
|||
},
|
||||
|
||||
val: function( value ) {
|
||||
var hooks, ret,
|
||||
elem = this[0];
|
||||
|
||||
if ( !arguments.length ) {
|
||||
var elem = this[0];
|
||||
|
||||
if ( elem ) {
|
||||
if ( jQuery.nodeName( elem, "option" ) ) {
|
||||
// attributes.value is undefined in Blackberry 4.7 but
|
||||
// uses .value. See #6932
|
||||
var val = elem.attributes.value;
|
||||
return !val || val.specified ? elem.value : elem.text;
|
||||
hooks = jQuery.valHooks[ elem.nodeName.toLowerCase() ] || jQuery.valHooks[ elem.type ];
|
||||
|
||||
if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// We need to handle select boxes special
|
||||
if ( jQuery.nodeName( elem, "select" ) ) {
|
||||
var index = elem.selectedIndex,
|
||||
values = [],
|
||||
options = elem.options,
|
||||
one = elem.type === "select-one";
|
||||
|
||||
// Nothing was selected
|
||||
if ( index < 0 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Loop through all the selected options
|
||||
for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
|
||||
var option = options[ i ];
|
||||
|
||||
// Don't return options that are disabled or in a disabled optgroup
|
||||
if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
|
||||
(!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
|
||||
|
||||
// Get the specific value for the option
|
||||
value = jQuery(option).val();
|
||||
|
||||
// We don't need an array for one selects
|
||||
if ( one ) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Multi-Selects return an array
|
||||
values.push( value );
|
||||
}
|
||||
}
|
||||
|
||||
// Fixes Bug #2551 -- select.val() broken in IE after form.reset()
|
||||
if ( one && !values.length && options.length ) {
|
||||
return jQuery( options[ index ] ).val();
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
// Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
|
||||
if ( rradiocheck.test( elem.type ) && !jQuery.support.checkOn ) {
|
||||
return elem.getAttribute("value") === null ? "on" : elem.value;
|
||||
}
|
||||
|
||||
// Everything else, we just grab the value
|
||||
return (elem.value || "").replace(rreturn, "");
|
||||
ret = elem.value;
|
||||
|
||||
return typeof ret === "string" ?
|
||||
// handle most common string cases
|
||||
ret.replace(rreturn, "") :
|
||||
// handle cases where value is null/undef or number
|
||||
ret == null ? "" : ret;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var isFunction = jQuery.isFunction(value);
|
||||
var isFunction = jQuery.isFunction( value );
|
||||
|
||||
return this.each(function(i) {
|
||||
var self = jQuery(this), val = value;
|
||||
return this.each(function( i ) {
|
||||
var self = jQuery(this), val;
|
||||
|
||||
if ( this.nodeType !== 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isFunction ) {
|
||||
val = value.call(this, i, self.val());
|
||||
val = value.call( this, i, self.val() );
|
||||
} else {
|
||||
val = value;
|
||||
}
|
||||
|
||||
// Treat null/undefined as ""; convert numbers to string
|
||||
|
@ -237,27 +198,16 @@ jQuery.fn.extend({
|
|||
val = "";
|
||||
} else if ( typeof val === "number" ) {
|
||||
val += "";
|
||||
} else if ( jQuery.isArray(val) ) {
|
||||
val = jQuery.map(val, function (value) {
|
||||
} else if ( jQuery.isArray( val ) ) {
|
||||
val = jQuery.map(val, function ( value ) {
|
||||
return value == null ? "" : value + "";
|
||||
});
|
||||
}
|
||||
|
||||
if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) {
|
||||
this.checked = jQuery.inArray( self.val(), val ) >= 0;
|
||||
hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ];
|
||||
|
||||
} else if ( jQuery.nodeName( this, "select" ) ) {
|
||||
var values = jQuery.makeArray(val);
|
||||
|
||||
jQuery( "option", this ).each(function() {
|
||||
this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
|
||||
});
|
||||
|
||||
if ( !values.length ) {
|
||||
this.selectedIndex = -1;
|
||||
}
|
||||
|
||||
} else {
|
||||
// If set returns undefined, fall back to normal setting
|
||||
if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
|
||||
this.value = val;
|
||||
}
|
||||
});
|
||||
|
@ -265,6 +215,72 @@ jQuery.fn.extend({
|
|||
});
|
||||
|
||||
jQuery.extend({
|
||||
valHooks: {
|
||||
option: {
|
||||
get: function( elem ) {
|
||||
// attributes.value is undefined in Blackberry 4.7 but
|
||||
// uses .value. See #6932
|
||||
var val = elem.attributes.value;
|
||||
return !val || val.specified ? elem.value : elem.text;
|
||||
}
|
||||
},
|
||||
select: {
|
||||
get: function( elem ) {
|
||||
var value,
|
||||
index = elem.selectedIndex,
|
||||
values = [],
|
||||
options = elem.options,
|
||||
one = elem.type === "select-one";
|
||||
|
||||
// Nothing was selected
|
||||
if ( index < 0 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Loop through all the selected options
|
||||
for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
|
||||
var option = options[ i ];
|
||||
|
||||
// Don't return options that are disabled or in a disabled optgroup
|
||||
if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
|
||||
(!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
|
||||
|
||||
// Get the specific value for the option
|
||||
value = jQuery( option ).val();
|
||||
|
||||
// We don't need an array for one selects
|
||||
if ( one ) {
|
||||
return value;
|
||||
}
|
||||
|
||||
// Multi-Selects return an array
|
||||
values.push( value );
|
||||
}
|
||||
}
|
||||
|
||||
// Fixes Bug #2551 -- select.val() broken in IE after form.reset()
|
||||
if ( one && !values.length && options.length ) {
|
||||
return jQuery( options[ index ] ).val();
|
||||
}
|
||||
|
||||
return values;
|
||||
},
|
||||
|
||||
set: function( elem, value ) {
|
||||
var values = jQuery.makeArray( value );
|
||||
|
||||
jQuery(elem).find("option").each(function() {
|
||||
this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
|
||||
});
|
||||
|
||||
if ( !values.length ) {
|
||||
elem.selectedIndex = -1;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
attrFn: {
|
||||
val: true,
|
||||
css: true,
|
||||
|
@ -275,115 +291,340 @@ jQuery.extend({
|
|||
height: true,
|
||||
offset: true
|
||||
},
|
||||
|
||||
|
||||
attrFix: {
|
||||
// Always normalize to ensure hook usage
|
||||
tabindex: "tabIndex"
|
||||
},
|
||||
|
||||
attr: function( elem, name, value, pass ) {
|
||||
var nType = elem.nodeType;
|
||||
|
||||
// don't get/set attributes on text, comment and attribute nodes
|
||||
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || elem.nodeType === 2 ) {
|
||||
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if ( pass && name in jQuery.attrFn ) {
|
||||
return jQuery(elem)[name](value);
|
||||
return jQuery( elem )[ name ]( value );
|
||||
}
|
||||
|
||||
var notxml = elem.nodeType !== 1 || !jQuery.isXMLDoc( elem ),
|
||||
// Whether we are setting (or getting)
|
||||
set = value !== undefined;
|
||||
// Fallback to prop when attributes are not supported
|
||||
if ( !("getAttribute" in elem) ) {
|
||||
return jQuery.prop( elem, name, value );
|
||||
}
|
||||
|
||||
// Try to normalize/fix the name
|
||||
name = notxml && jQuery.props[ name ] || name;
|
||||
var ret, hooks,
|
||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||
|
||||
// Only do all the following if this is a node (faster for style)
|
||||
if ( elem.nodeType === 1 ) {
|
||||
// These attributes require special treatment
|
||||
var special = rspecialurl.test( name );
|
||||
// Normalize the name if needed
|
||||
if ( notxml ) {
|
||||
name = jQuery.attrFix[ name ] || name;
|
||||
|
||||
// Safari mis-reports the default selected property of an option
|
||||
// Accessing the parent's selectedIndex property fixes it
|
||||
if ( name === "selected" && !jQuery.support.optSelected ) {
|
||||
var parent = elem.parentNode;
|
||||
if ( parent ) {
|
||||
parent.selectedIndex;
|
||||
hooks = jQuery.attrHooks[ name ];
|
||||
|
||||
// Make sure that it also works with optgroups, see #5701
|
||||
if ( parent.parentNode ) {
|
||||
parent.parentNode.selectedIndex;
|
||||
}
|
||||
if ( !hooks ) {
|
||||
// Use boolHook for boolean attributes
|
||||
if ( rboolean.test( name ) ) {
|
||||
|
||||
hooks = boolHook;
|
||||
|
||||
// Use formHook for forms and if the name contains certain characters
|
||||
} else if ( formHook && name !== "className" &&
|
||||
(jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ) {
|
||||
|
||||
hooks = formHook;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If applicable, access the attribute via the DOM 0 way
|
||||
// 'in' checks fail in Blackberry 4.7 #6931
|
||||
if ( (name in elem || elem[ name ] !== undefined) && notxml && !special ) {
|
||||
if ( set ) {
|
||||
// We can't allow the type property to be changed (since it causes problems in IE)
|
||||
if ( name === "type" && rtype.test( elem.nodeName ) && elem.parentNode ) {
|
||||
jQuery.error( "type property can't be changed" );
|
||||
}
|
||||
if ( value !== undefined ) {
|
||||
|
||||
if ( value === null ) {
|
||||
if ( elem.nodeType === 1 ) {
|
||||
elem.removeAttribute( name );
|
||||
}
|
||||
|
||||
} else {
|
||||
elem[ name ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// browsers index elements by id/name on forms, give priority to attributes.
|
||||
if ( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) ) {
|
||||
return elem.getAttributeNode( name ).nodeValue;
|
||||
}
|
||||
|
||||
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
|
||||
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
||||
if ( name === "tabIndex" ) {
|
||||
var attributeNode = elem.getAttributeNode( "tabIndex" );
|
||||
|
||||
return attributeNode && attributeNode.specified ?
|
||||
attributeNode.value :
|
||||
rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
|
||||
0 :
|
||||
undefined;
|
||||
}
|
||||
|
||||
return elem[ name ];
|
||||
}
|
||||
|
||||
if ( !jQuery.support.style && notxml && name === "style" ) {
|
||||
if ( set ) {
|
||||
elem.style.cssText = "" + value;
|
||||
}
|
||||
|
||||
return elem.style.cssText;
|
||||
}
|
||||
|
||||
if ( set ) {
|
||||
// convert the value to a string (all browsers do this but IE) see #1070
|
||||
elem.setAttribute( name, "" + value );
|
||||
}
|
||||
|
||||
// Ensure that missing attributes return undefined
|
||||
// Blackberry 4.7 returns "" from getAttribute #6938
|
||||
if ( !elem.attributes[ name ] && (elem.hasAttribute && !elem.hasAttribute( name )) ) {
|
||||
if ( value === null ) {
|
||||
jQuery.removeAttr( elem, name );
|
||||
return undefined;
|
||||
|
||||
} else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
elem.setAttribute( name, "" + value );
|
||||
return value;
|
||||
}
|
||||
|
||||
var attr = !jQuery.support.hrefNormalized && notxml && special ?
|
||||
// Some attributes require a special call on IE
|
||||
elem.getAttribute( name, 2 ) :
|
||||
elem.getAttribute( name );
|
||||
} else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
|
||||
ret = elem.getAttribute( name );
|
||||
|
||||
// Non-existent attributes return null, we normalize to undefined
|
||||
return attr === null ? undefined : attr;
|
||||
return ret === null ?
|
||||
undefined :
|
||||
ret;
|
||||
}
|
||||
// Handle everything which isn't a DOM element node
|
||||
if ( set ) {
|
||||
elem[ name ] = value;
|
||||
},
|
||||
|
||||
removeAttr: function( elem, name ) {
|
||||
var propName;
|
||||
if ( elem.nodeType === 1 ) {
|
||||
name = jQuery.attrFix[ name ] || name;
|
||||
|
||||
if ( jQuery.support.getSetAttribute ) {
|
||||
// Use removeAttribute in browsers that support it
|
||||
elem.removeAttribute( name );
|
||||
} else {
|
||||
jQuery.attr( elem, name, "" );
|
||||
elem.removeAttributeNode( elem.getAttributeNode( name ) );
|
||||
}
|
||||
|
||||
// Set corresponding property to false for boolean attributes
|
||||
if ( rboolean.test( name ) && (propName = jQuery.propFix[ name ] || name) in elem ) {
|
||||
elem[ propName ] = false;
|
||||
}
|
||||
}
|
||||
return elem[ name ];
|
||||
},
|
||||
|
||||
attrHooks: {
|
||||
type: {
|
||||
set: function( elem, value ) {
|
||||
// We can't allow the type property to be changed (since it causes problems in IE)
|
||||
if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
|
||||
jQuery.error( "type property can't be changed" );
|
||||
} else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
|
||||
// Setting the type on a radio button after the value resets the value in IE6-9
|
||||
// Reset value to it's default in case type is set after value
|
||||
// This is for element creation
|
||||
var val = elem.value;
|
||||
elem.setAttribute( "type", value );
|
||||
if ( val ) {
|
||||
elem.value = val;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
},
|
||||
tabIndex: {
|
||||
get: function( elem ) {
|
||||
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
|
||||
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
||||
var attributeNode = elem.getAttributeNode("tabIndex");
|
||||
|
||||
return attributeNode && attributeNode.specified ?
|
||||
parseInt( attributeNode.value, 10 ) :
|
||||
rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
|
||||
0 :
|
||||
undefined;
|
||||
}
|
||||
},
|
||||
// Use the value property for back compat
|
||||
// Use the formHook for button elements in IE6/7 (#1954)
|
||||
value: {
|
||||
get: function( elem, name ) {
|
||||
if ( formHook && jQuery.nodeName( elem, "button" ) ) {
|
||||
return formHook.get( elem, name );
|
||||
}
|
||||
return name in elem ?
|
||||
elem.value :
|
||||
null;
|
||||
},
|
||||
set: function( elem, value, name ) {
|
||||
if ( formHook && jQuery.nodeName( elem, "button" ) ) {
|
||||
return formHook.set( elem, value, name );
|
||||
}
|
||||
// Does not return so that setAttribute is also used
|
||||
elem.value = value;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
propFix: {
|
||||
tabindex: "tabIndex",
|
||||
readonly: "readOnly",
|
||||
"for": "htmlFor",
|
||||
"class": "className",
|
||||
maxlength: "maxLength",
|
||||
cellspacing: "cellSpacing",
|
||||
cellpadding: "cellPadding",
|
||||
rowspan: "rowSpan",
|
||||
colspan: "colSpan",
|
||||
usemap: "useMap",
|
||||
frameborder: "frameBorder",
|
||||
contenteditable: "contentEditable"
|
||||
},
|
||||
|
||||
prop: function( elem, name, value ) {
|
||||
var nType = elem.nodeType;
|
||||
|
||||
// don't get/set properties on text, comment and attribute nodes
|
||||
if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var ret, hooks,
|
||||
notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
|
||||
|
||||
if ( notxml ) {
|
||||
// Fix name and attach hooks
|
||||
name = jQuery.propFix[ name ] || name;
|
||||
hooks = jQuery.propHooks[ name ];
|
||||
}
|
||||
|
||||
if ( value !== undefined ) {
|
||||
if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
return (elem[ name ] = value);
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== undefined ) {
|
||||
return ret;
|
||||
|
||||
} else {
|
||||
return elem[ name ];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
propHooks: {}
|
||||
});
|
||||
|
||||
// Hook for boolean attributes
|
||||
boolHook = {
|
||||
get: function( elem, name ) {
|
||||
// Align boolean attributes with corresponding properties
|
||||
return jQuery.prop( elem, name ) ?
|
||||
name.toLowerCase() :
|
||||
undefined;
|
||||
},
|
||||
set: function( elem, value, name ) {
|
||||
var propName;
|
||||
if ( value === false ) {
|
||||
// Remove boolean attributes when set to false
|
||||
jQuery.removeAttr( elem, name );
|
||||
} else {
|
||||
// value is true since we know at this point it's type boolean and not false
|
||||
// Set boolean attributes to the same name and set the DOM property
|
||||
propName = jQuery.propFix[ name ] || name;
|
||||
if ( propName in elem ) {
|
||||
// Only set the IDL specifically if it already exists on the element
|
||||
elem[ propName ] = true;
|
||||
}
|
||||
|
||||
elem.setAttribute( name, name.toLowerCase() );
|
||||
}
|
||||
return name;
|
||||
}
|
||||
};
|
||||
|
||||
// IE6/7 do not support getting/setting some attributes with get/setAttribute
|
||||
if ( !jQuery.support.getSetAttribute ) {
|
||||
|
||||
// propFix is more comprehensive and contains all fixes
|
||||
jQuery.attrFix = jQuery.propFix;
|
||||
|
||||
// Use this for any attribute on a form in IE6/7
|
||||
formHook = jQuery.attrHooks.name = jQuery.attrHooks.title = jQuery.valHooks.button = {
|
||||
get: function( elem, name ) {
|
||||
var ret;
|
||||
ret = elem.getAttributeNode( name );
|
||||
// Return undefined if nodeValue is empty string
|
||||
return ret && ret.nodeValue !== "" ?
|
||||
ret.nodeValue :
|
||||
undefined;
|
||||
},
|
||||
set: function( elem, value, name ) {
|
||||
// Check form objects in IE (multiple bugs related)
|
||||
// Only use nodeValue if the attribute node exists on the form
|
||||
var ret = elem.getAttributeNode( name );
|
||||
if ( ret ) {
|
||||
ret.nodeValue = value;
|
||||
return value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Set width and height to auto instead of 0 on empty string( Bug #8150 )
|
||||
// This is for removals
|
||||
jQuery.each([ "width", "height" ], function( i, name ) {
|
||||
jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
|
||||
set: function( elem, value ) {
|
||||
if ( value === "" ) {
|
||||
elem.setAttribute( name, "auto" );
|
||||
return value;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Some attributes require a special call on IE
|
||||
if ( !jQuery.support.hrefNormalized ) {
|
||||
jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
|
||||
jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
|
||||
get: function( elem ) {
|
||||
var ret = elem.getAttribute( name, 2 );
|
||||
return ret === null ? undefined : ret;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ( !jQuery.support.style ) {
|
||||
jQuery.attrHooks.style = {
|
||||
get: function( elem ) {
|
||||
// Return undefined in the case of empty string
|
||||
// Normalize to lowercase since IE uppercases css property names
|
||||
return elem.style.cssText.toLowerCase() || undefined;
|
||||
},
|
||||
set: function( elem, value ) {
|
||||
return (elem.style.cssText = "" + value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Safari mis-reports the default selected property of an option
|
||||
// Accessing the parent's selectedIndex property fixes it
|
||||
if ( !jQuery.support.optSelected ) {
|
||||
jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
|
||||
get: function( elem ) {
|
||||
var parent = elem.parentNode;
|
||||
|
||||
if ( parent ) {
|
||||
parent.selectedIndex;
|
||||
|
||||
// Make sure that it also works with optgroups, see #5701
|
||||
if ( parent.parentNode ) {
|
||||
parent.parentNode.selectedIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Radios and checkboxes getter/setter
|
||||
if ( !jQuery.support.checkOn ) {
|
||||
jQuery.each([ "radio", "checkbox" ], function() {
|
||||
jQuery.valHooks[ this ] = {
|
||||
get: function( elem ) {
|
||||
// Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
|
||||
return elem.getAttribute("value") === null ? "on" : elem.value;
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
jQuery.each([ "radio", "checkbox" ], function() {
|
||||
jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], {
|
||||
set: function( elem, value ) {
|
||||
if ( jQuery.isArray( value ) ) {
|
||||
return (elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})( jQuery );
|
||||
|
|
213
src/core.js
213
src/core.js
|
@ -17,7 +17,7 @@ var jQuery = function( selector, context ) {
|
|||
|
||||
// A simple way to check for HTML strings or ID strings
|
||||
// (both of which we optimize for)
|
||||
quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
|
||||
quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
|
||||
|
||||
// Check if a string has a non-whitespace character in it
|
||||
rnotwhite = /\S/,
|
||||
|
@ -44,6 +44,14 @@ var jQuery = function( selector, context ) {
|
|||
rmsie = /(msie) ([\w.]+)/,
|
||||
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
|
||||
|
||||
// Matches dashed string for camelizing
|
||||
rdashAlpha = /-([a-z])/ig,
|
||||
|
||||
// Used by jQuery.camelCase as callback to replace()
|
||||
fcamelCase = function( all, letter ) {
|
||||
return letter.toUpperCase();
|
||||
},
|
||||
|
||||
// Keep a UserAgent string for use with jQuery.browser
|
||||
userAgent = navigator.userAgent,
|
||||
|
||||
|
@ -88,7 +96,7 @@ jQuery.fn = jQuery.prototype = {
|
|||
if ( selector === "body" && !context && document.body ) {
|
||||
this.context = document;
|
||||
this[0] = document.body;
|
||||
this.selector = "body";
|
||||
this.selector = selector;
|
||||
this.length = 1;
|
||||
return this;
|
||||
}
|
||||
|
@ -96,7 +104,13 @@ jQuery.fn = jQuery.prototype = {
|
|||
// Handle HTML strings
|
||||
if ( typeof selector === "string" ) {
|
||||
// Are we dealing with HTML string or an ID?
|
||||
match = quickExpr.exec( selector );
|
||||
if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
|
||||
// Assume that strings that start and end with <> are HTML and skip the regex check
|
||||
match = [ null, selector, null ];
|
||||
|
||||
} else {
|
||||
match = quickExpr.exec( selector );
|
||||
}
|
||||
|
||||
// Verify a match, and that no context was specified for #id
|
||||
if ( match && (match[1] || !context) ) {
|
||||
|
@ -353,9 +367,11 @@ jQuery.extend = jQuery.fn.extend = function() {
|
|||
|
||||
jQuery.extend({
|
||||
noConflict: function( deep ) {
|
||||
window.$ = _$;
|
||||
if ( window.$ === jQuery ) {
|
||||
window.$ = _$;
|
||||
}
|
||||
|
||||
if ( deep ) {
|
||||
if ( deep && window.jQuery === jQuery ) {
|
||||
window.jQuery = _jQuery;
|
||||
}
|
||||
|
||||
|
@ -369,15 +385,19 @@ jQuery.extend({
|
|||
// the ready event fires. See #6781
|
||||
readyWait: 1,
|
||||
|
||||
// Hold (or release) the ready event
|
||||
holdReady: function( hold ) {
|
||||
if ( hold ) {
|
||||
jQuery.readyWait++;
|
||||
} else {
|
||||
jQuery.ready( true );
|
||||
}
|
||||
},
|
||||
|
||||
// Handle when the DOM is ready
|
||||
ready: function( wait ) {
|
||||
// A third-party is pushing the ready event forwards
|
||||
if ( wait === true ) {
|
||||
jQuery.readyWait--;
|
||||
}
|
||||
|
||||
// Make sure that the DOM is not already loaded
|
||||
if ( !jQuery.readyWait || (wait !== true && !jQuery.isReady) ) {
|
||||
// Either a released hold or an DOMready/load event and not yet ready
|
||||
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
|
||||
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
|
||||
if ( !document.body ) {
|
||||
return setTimeout( jQuery.ready, 1 );
|
||||
|
@ -427,7 +447,7 @@ jQuery.extend({
|
|||
} else if ( document.attachEvent ) {
|
||||
// ensure firing before onload,
|
||||
// maybe late but safe also for iframes
|
||||
document.attachEvent("onreadystatechange", DOMContentLoaded);
|
||||
document.attachEvent( "onreadystatechange", DOMContentLoaded );
|
||||
|
||||
// A fallback to window.onload, that will always work
|
||||
window.attachEvent( "onload", jQuery.ready );
|
||||
|
@ -515,20 +535,21 @@ jQuery.extend({
|
|||
// Make sure leading/trailing whitespace is removed (IE can't handle it)
|
||||
data = jQuery.trim( data );
|
||||
|
||||
// Attempt to parse using the native JSON parser first
|
||||
if ( window.JSON && window.JSON.parse ) {
|
||||
return window.JSON.parse( data );
|
||||
}
|
||||
|
||||
// Make sure the incoming data is actual JSON
|
||||
// Logic borrowed from http://json.org/json2.js
|
||||
if ( rvalidchars.test(data.replace(rvalidescape, "@")
|
||||
.replace(rvalidtokens, "]")
|
||||
.replace(rvalidbraces, "")) ) {
|
||||
if ( rvalidchars.test( data.replace( rvalidescape, "@" )
|
||||
.replace( rvalidtokens, "]" )
|
||||
.replace( rvalidbraces, "")) ) {
|
||||
|
||||
// Try to use the native JSON parser first
|
||||
return window.JSON && window.JSON.parse ?
|
||||
window.JSON.parse( data ) :
|
||||
(new Function("return " + data))();
|
||||
return (new Function( "return " + data ))();
|
||||
|
||||
} else {
|
||||
jQuery.error( "Invalid JSON: " + data );
|
||||
}
|
||||
jQuery.error( "Invalid JSON: " + data );
|
||||
},
|
||||
|
||||
// Cross-browser xml parsing
|
||||
|
@ -555,27 +576,26 @@ jQuery.extend({
|
|||
|
||||
noop: function() {},
|
||||
|
||||
// Evalulates a script in a global context
|
||||
// Evaluates a script in a global context
|
||||
// Workarounds based on findings by Jim Driscoll
|
||||
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
|
||||
globalEval: function( data ) {
|
||||
if ( data && rnotwhite.test(data) ) {
|
||||
// Inspired by code by Andrea Giammarchi
|
||||
// http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
|
||||
var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
|
||||
script = document.createElement( "script" );
|
||||
|
||||
if ( jQuery.support.scriptEval() ) {
|
||||
script.appendChild( document.createTextNode( data ) );
|
||||
} else {
|
||||
script.text = data;
|
||||
}
|
||||
|
||||
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
|
||||
// This arises when a base node is used (#2709).
|
||||
head.insertBefore( script, head.firstChild );
|
||||
head.removeChild( script );
|
||||
if ( data && rnotwhite.test( data ) ) {
|
||||
// We use execScript on Internet Explorer
|
||||
// We use an anonymous function so that context is window
|
||||
// rather than jQuery in Firefox
|
||||
( window.execScript || function( data ) {
|
||||
window[ "eval" ].call( window, data );
|
||||
} )( data );
|
||||
}
|
||||
},
|
||||
|
||||
// Converts a dashed string to camelCased string;
|
||||
// Used by both the css and data modules
|
||||
camelCase: function( string ) {
|
||||
return string.replace( rdashAlpha, fcamelCase );
|
||||
},
|
||||
|
||||
nodeName: function( elem, name ) {
|
||||
return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
|
||||
},
|
||||
|
@ -584,7 +604,7 @@ jQuery.extend({
|
|||
each: function( object, callback, args ) {
|
||||
var name, i = 0,
|
||||
length = object.length,
|
||||
isObj = length === undefined || jQuery.isFunction(object);
|
||||
isObj = length === undefined || jQuery.isFunction( object );
|
||||
|
||||
if ( args ) {
|
||||
if ( isObj ) {
|
||||
|
@ -610,8 +630,11 @@ jQuery.extend({
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for ( var value = object[0];
|
||||
i < length && callback.call( value, i, value ) !== false; value = object[++i] ) {}
|
||||
for ( ; i < length; ) {
|
||||
if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -642,7 +665,7 @@ jQuery.extend({
|
|||
// The extra typeof function check is to prevent crashes
|
||||
// in Safari 2 (See: #3039)
|
||||
// Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
|
||||
var type = jQuery.type(array);
|
||||
var type = jQuery.type( array );
|
||||
|
||||
if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
|
||||
push.call( ret, array );
|
||||
|
@ -655,8 +678,9 @@ jQuery.extend({
|
|||
},
|
||||
|
||||
inArray: function( elem, array ) {
|
||||
if ( array.indexOf ) {
|
||||
return array.indexOf( elem );
|
||||
|
||||
if ( indexOf ) {
|
||||
return indexOf.call( array, elem );
|
||||
}
|
||||
|
||||
for ( var i = 0, length = array.length; i < length; i++ ) {
|
||||
|
@ -706,15 +730,30 @@ jQuery.extend({
|
|||
|
||||
// arg is for internal usage only
|
||||
map: function( elems, callback, arg ) {
|
||||
var ret = [], value;
|
||||
var value, key, ret = [],
|
||||
i = 0,
|
||||
length = elems.length,
|
||||
// jquery objects are treated as arrays
|
||||
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
|
||||
|
||||
// Go through the array, translating each of the items to their
|
||||
// new value (or values).
|
||||
for ( var i = 0, length = elems.length; i < length; i++ ) {
|
||||
value = callback( elems[ i ], i, arg );
|
||||
if ( isArray ) {
|
||||
for ( ; i < length; i++ ) {
|
||||
value = callback( elems[ i ], i, arg );
|
||||
|
||||
if ( value != null ) {
|
||||
ret[ ret.length ] = value;
|
||||
if ( value != null ) {
|
||||
ret[ ret.length ] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Go through every key on the object,
|
||||
} else {
|
||||
for ( key in elems ) {
|
||||
value = callback( elems[ key ], key, arg );
|
||||
|
||||
if ( value != null ) {
|
||||
ret[ ret.length ] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -725,36 +764,35 @@ jQuery.extend({
|
|||
// A global GUID counter for objects
|
||||
guid: 1,
|
||||
|
||||
proxy: function( fn, proxy, thisObject ) {
|
||||
if ( arguments.length === 2 ) {
|
||||
if ( typeof proxy === "string" ) {
|
||||
thisObject = fn;
|
||||
fn = thisObject[ proxy ];
|
||||
proxy = undefined;
|
||||
|
||||
} else if ( proxy && !jQuery.isFunction( proxy ) ) {
|
||||
thisObject = proxy;
|
||||
proxy = undefined;
|
||||
}
|
||||
// Bind a function to a context, optionally partially applying any
|
||||
// arguments.
|
||||
proxy: function( fn, context ) {
|
||||
if ( typeof context === "string" ) {
|
||||
var tmp = fn[ context ];
|
||||
context = fn;
|
||||
fn = tmp;
|
||||
}
|
||||
|
||||
if ( !proxy && fn ) {
|
||||
// Quick check to determine if target is callable, in the spec
|
||||
// this throws a TypeError, but we will just return undefined.
|
||||
if ( !jQuery.isFunction( fn ) ) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Simulated bind
|
||||
var args = slice.call( arguments, 2 ),
|
||||
proxy = function() {
|
||||
return fn.apply( thisObject || this, arguments );
|
||||
return fn.apply( context, args.concat( slice.call( arguments ) ) );
|
||||
};
|
||||
}
|
||||
|
||||
// Set the guid of unique handler to the same of original handler, so it can be removed
|
||||
if ( fn ) {
|
||||
proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
|
||||
}
|
||||
proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
|
||||
|
||||
// So proxy can be declared as an argument
|
||||
return proxy;
|
||||
},
|
||||
|
||||
// Mutifunctional method to get and set values to a collection
|
||||
// The value/s can be optionally by executed if its a function
|
||||
// The value/s can optionally be executed if it's a function
|
||||
access: function( elems, key, value, exec, fn, pass ) {
|
||||
var length = elems.length;
|
||||
|
||||
|
@ -801,24 +839,24 @@ jQuery.extend({
|
|||
},
|
||||
|
||||
sub: function() {
|
||||
function jQuerySubclass( selector, context ) {
|
||||
return new jQuerySubclass.fn.init( selector, context );
|
||||
function jQuerySub( selector, context ) {
|
||||
return new jQuerySub.fn.init( selector, context );
|
||||
}
|
||||
jQuery.extend( true, jQuerySubclass, this );
|
||||
jQuerySubclass.superclass = this;
|
||||
jQuerySubclass.fn = jQuerySubclass.prototype = this();
|
||||
jQuerySubclass.fn.constructor = jQuerySubclass;
|
||||
jQuerySubclass.subclass = this.subclass;
|
||||
jQuerySubclass.fn.init = function init( selector, context ) {
|
||||
if ( context && context instanceof jQuery && !(context instanceof jQuerySubclass) ) {
|
||||
context = jQuerySubclass(context);
|
||||
jQuery.extend( true, jQuerySub, this );
|
||||
jQuerySub.superclass = this;
|
||||
jQuerySub.fn = jQuerySub.prototype = this();
|
||||
jQuerySub.fn.constructor = jQuerySub;
|
||||
jQuerySub.sub = this.sub;
|
||||
jQuerySub.fn.init = function init( selector, context ) {
|
||||
if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
|
||||
context = jQuerySub( context );
|
||||
}
|
||||
|
||||
return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass );
|
||||
return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
|
||||
};
|
||||
jQuerySubclass.fn.init.prototype = jQuerySubclass.fn;
|
||||
var rootjQuerySubclass = jQuerySubclass(document);
|
||||
return jQuerySubclass;
|
||||
jQuerySub.fn.init.prototype = jQuerySub.fn;
|
||||
var rootjQuerySub = jQuerySub(document);
|
||||
return jQuerySub;
|
||||
},
|
||||
|
||||
browser: {}
|
||||
|
@ -840,12 +878,6 @@ if ( jQuery.browser.webkit ) {
|
|||
jQuery.browser.safari = true;
|
||||
}
|
||||
|
||||
if ( indexOf ) {
|
||||
jQuery.inArray = function( elem, array ) {
|
||||
return indexOf.call( array, elem );
|
||||
};
|
||||
}
|
||||
|
||||
// IE doesn't match non-breaking spaces with \s
|
||||
if ( rnotwhite.test( "\xA0" ) ) {
|
||||
trimLeft = /^[\s\xA0]+/;
|
||||
|
@ -891,7 +923,6 @@ function doScrollCheck() {
|
|||
jQuery.ready();
|
||||
}
|
||||
|
||||
// Expose jQuery to the global object
|
||||
return jQuery;
|
||||
|
||||
})();
|
||||
|
|
156
src/css.js
156
src/css.js
|
@ -2,11 +2,12 @@
|
|||
|
||||
var ralpha = /alpha\([^)]*\)/i,
|
||||
ropacity = /opacity=([^)]*)/,
|
||||
rdashAlpha = /-([a-z])/ig,
|
||||
// fixed for IE9, see #8346
|
||||
rupper = /([A-Z]|^ms)/g,
|
||||
rnumpx = /^-?\d+(?:px)?$/i,
|
||||
rnum = /^-?\d/,
|
||||
rrelNum = /^[+\-]=/,
|
||||
rrelNumFilter = /[^+\-\.\de]+/g,
|
||||
|
||||
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
||||
cssWidth = [ "Left", "Right" ],
|
||||
|
@ -14,11 +15,7 @@ var ralpha = /alpha\([^)]*\)/i,
|
|||
curCSS,
|
||||
|
||||
getComputedStyle,
|
||||
currentStyle,
|
||||
|
||||
fcamelCase = function( all, letter ) {
|
||||
return letter.toUpperCase();
|
||||
};
|
||||
currentStyle;
|
||||
|
||||
jQuery.fn.css = function( name, value ) {
|
||||
// Setting 'undefined' is a no-op
|
||||
|
@ -53,11 +50,14 @@ jQuery.extend({
|
|||
|
||||
// Exclude the following css properties to add px
|
||||
cssNumber: {
|
||||
"zIndex": true,
|
||||
"fillOpacity": true,
|
||||
"fontWeight": true,
|
||||
"lineHeight": true,
|
||||
"opacity": true,
|
||||
"zoom": true,
|
||||
"lineHeight": true
|
||||
"orphans": true,
|
||||
"widows": true,
|
||||
"zIndex": true,
|
||||
"zoom": true
|
||||
},
|
||||
|
||||
// Add in properties whose names you wish to fix before
|
||||
|
@ -75,20 +75,29 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
// Make sure that we're working with the right name
|
||||
var ret, origName = jQuery.camelCase( name ),
|
||||
var ret, type, origName = jQuery.camelCase( name ),
|
||||
style = elem.style, hooks = jQuery.cssHooks[ origName ];
|
||||
|
||||
name = jQuery.cssProps[ origName ] || origName;
|
||||
|
||||
// Check if we're setting a value
|
||||
if ( value !== undefined ) {
|
||||
type = typeof value;
|
||||
|
||||
// Make sure that NaN and null values aren't set. See: #7116
|
||||
if ( typeof value === "number" && isNaN( value ) || value == null ) {
|
||||
if ( type === "number" && isNaN( value ) || value == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// convert relative number strings (+= or -=) to relative numbers. #7345
|
||||
if ( type === "string" && rrelNum.test( value ) ) {
|
||||
value = +value.replace( rrelNumFilter, "" ) + parseFloat( jQuery.css( elem, name ) );
|
||||
// Fixes bug #9237
|
||||
type = "number";
|
||||
}
|
||||
|
||||
// If a number was passed in, add 'px' to the (except for certain CSS properties)
|
||||
if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
|
||||
if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
|
||||
value += "px";
|
||||
}
|
||||
|
||||
|
@ -113,11 +122,17 @@ jQuery.extend({
|
|||
},
|
||||
|
||||
css: function( elem, name, extra ) {
|
||||
// Make sure that we're working with the right name
|
||||
var ret, origName = jQuery.camelCase( name ),
|
||||
hooks = jQuery.cssHooks[ origName ];
|
||||
var ret, hooks;
|
||||
|
||||
name = jQuery.cssProps[ origName ] || origName;
|
||||
// Make sure that we're working with the right name
|
||||
name = jQuery.camelCase( name );
|
||||
hooks = jQuery.cssHooks[ name ];
|
||||
name = jQuery.cssProps[ name ] || name;
|
||||
|
||||
// cssFloat needs a special treatment
|
||||
if ( name === "cssFloat" ) {
|
||||
name = "float";
|
||||
}
|
||||
|
||||
// If a hook was provided get the computed value from there
|
||||
if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
|
||||
|
@ -125,7 +140,7 @@ jQuery.extend({
|
|||
|
||||
// Otherwise, if a way to get the computed value exists, use that
|
||||
} else if ( curCSS ) {
|
||||
return curCSS( elem, name, origName );
|
||||
return curCSS( elem, name );
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -145,10 +160,6 @@ jQuery.extend({
|
|||
for ( name in options ) {
|
||||
elem.style[ name ] = old[ name ];
|
||||
}
|
||||
},
|
||||
|
||||
camelCase: function( string ) {
|
||||
return string.replace( rdashAlpha, fcamelCase );
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -162,44 +173,21 @@ jQuery.each(["height", "width"], function( i, name ) {
|
|||
|
||||
if ( computed ) {
|
||||
if ( elem.offsetWidth !== 0 ) {
|
||||
val = getWH( elem, name, extra );
|
||||
|
||||
return getWH( elem, name, extra );
|
||||
} else {
|
||||
jQuery.swap( elem, cssShow, function() {
|
||||
val = getWH( elem, name, extra );
|
||||
});
|
||||
}
|
||||
|
||||
if ( val <= 0 ) {
|
||||
val = curCSS( elem, name, name );
|
||||
|
||||
if ( val === "0px" && currentStyle ) {
|
||||
val = currentStyle( elem, name, name );
|
||||
}
|
||||
|
||||
if ( val != null ) {
|
||||
// Should return "auto" instead of 0, use 0 for
|
||||
// temporary backwards-compat
|
||||
return val === "" || val === "auto" ? "0px" : val;
|
||||
}
|
||||
}
|
||||
|
||||
if ( val < 0 || val == null ) {
|
||||
val = elem.style[ name ];
|
||||
|
||||
// Should return "auto" instead of 0, use 0 for
|
||||
// temporary backwards-compat
|
||||
return val === "" || val === "auto" ? "0px" : val;
|
||||
}
|
||||
|
||||
return typeof val === "string" ? val : val + "px";
|
||||
return val;
|
||||
}
|
||||
},
|
||||
|
||||
set: function( elem, value ) {
|
||||
if ( rnumpx.test( value ) ) {
|
||||
// ignore negative width and height values #1599
|
||||
value = parseFloat(value);
|
||||
value = parseFloat( value );
|
||||
|
||||
if ( value >= 0 ) {
|
||||
return value + "px";
|
||||
|
@ -216,27 +204,28 @@ if ( !jQuery.support.opacity ) {
|
|||
jQuery.cssHooks.opacity = {
|
||||
get: function( elem, computed ) {
|
||||
// IE uses filters for opacity
|
||||
return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
|
||||
(parseFloat(RegExp.$1) / 100) + "" :
|
||||
return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
|
||||
( parseFloat( RegExp.$1 ) / 100 ) + "" :
|
||||
computed ? "1" : "";
|
||||
},
|
||||
|
||||
set: function( elem, value ) {
|
||||
var style = elem.style;
|
||||
var style = elem.style,
|
||||
currentStyle = elem.currentStyle;
|
||||
|
||||
// IE has trouble with opacity if it does not have layout
|
||||
// Force it by setting the zoom level
|
||||
style.zoom = 1;
|
||||
|
||||
// Set the alpha filter to set the opacity
|
||||
var opacity = jQuery.isNaN(value) ?
|
||||
var opacity = jQuery.isNaN( value ) ?
|
||||
"" :
|
||||
"alpha(opacity=" + value * 100 + ")",
|
||||
filter = style.filter || "";
|
||||
filter = currentStyle && currentStyle.filter || style.filter || "";
|
||||
|
||||
style.filter = ralpha.test(filter) ?
|
||||
filter.replace(ralpha, opacity) :
|
||||
style.filter + ' ' + opacity;
|
||||
style.filter = ralpha.test( filter ) ?
|
||||
filter.replace( ralpha, opacity ) :
|
||||
filter + " " + opacity;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -264,7 +253,7 @@ jQuery(function() {
|
|||
});
|
||||
|
||||
if ( document.defaultView && document.defaultView.getComputedStyle ) {
|
||||
getComputedStyle = function( elem, newName, name ) {
|
||||
getComputedStyle = function( elem, name ) {
|
||||
var ret, defaultView, computedStyle;
|
||||
|
||||
name = name.replace( rupper, "-$1" ).toLowerCase();
|
||||
|
@ -321,27 +310,50 @@ if ( document.documentElement.currentStyle ) {
|
|||
curCSS = getComputedStyle || currentStyle;
|
||||
|
||||
function getWH( elem, name, extra ) {
|
||||
var which = name === "width" ? cssWidth : cssHeight,
|
||||
val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
|
||||
|
||||
if ( extra === "border" ) {
|
||||
return val;
|
||||
// Start with offset property
|
||||
var val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
|
||||
which = name === "width" ? cssWidth : cssHeight;
|
||||
|
||||
if ( val > 0 ) {
|
||||
if ( extra !== "border" ) {
|
||||
jQuery.each( which, function() {
|
||||
if ( !extra ) {
|
||||
val -= parseFloat( jQuery.css( elem, "padding" + this ) ) || 0;
|
||||
}
|
||||
if ( extra === "margin" ) {
|
||||
val += parseFloat( jQuery.css( elem, extra + this ) ) || 0;
|
||||
} else {
|
||||
val -= parseFloat( jQuery.css( elem, "border" + this + "Width" ) ) || 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return val + "px";
|
||||
}
|
||||
|
||||
jQuery.each( which, function() {
|
||||
if ( !extra ) {
|
||||
val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
|
||||
}
|
||||
// Fall back to computed then uncomputed css if necessary
|
||||
val = curCSS( elem, name, name );
|
||||
if ( val < 0 || val == null ) {
|
||||
val = elem.style[ name ] || 0;
|
||||
}
|
||||
// Normalize "", auto, and prepare for extra
|
||||
val = parseFloat( val ) || 0;
|
||||
|
||||
if ( extra === "margin" ) {
|
||||
val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
|
||||
// Add padding, border, margin
|
||||
if ( extra ) {
|
||||
jQuery.each( which, function() {
|
||||
val += parseFloat( jQuery.css( elem, "padding" + this ) ) || 0;
|
||||
if ( extra !== "padding" ) {
|
||||
val += parseFloat( jQuery.css( elem, "border" + this + "Width" ) ) || 0;
|
||||
}
|
||||
if ( extra === "margin" ) {
|
||||
val += parseFloat( jQuery.css( elem, extra + this ) ) || 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else {
|
||||
val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
|
||||
}
|
||||
});
|
||||
|
||||
return val;
|
||||
return val + "px";
|
||||
}
|
||||
|
||||
if ( jQuery.expr && jQuery.expr.filters ) {
|
||||
|
|
19
src/data.js
19
src/data.js
|
@ -1,6 +1,7 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var rbrace = /^(?:\{.*\}|\[.*\])$/;
|
||||
var rbrace = /^(?:\{.*\}|\[.*\])$/,
|
||||
rmultiDash = /([a-z])([A-Z])/g;
|
||||
|
||||
jQuery.extend({
|
||||
cache: {},
|
||||
|
@ -97,7 +98,7 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
if ( data !== undefined ) {
|
||||
thisCache[ name ] = data;
|
||||
thisCache[ jQuery.camelCase( name ) ] = data;
|
||||
}
|
||||
|
||||
// TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
|
||||
|
@ -107,7 +108,10 @@ jQuery.extend({
|
|||
return thisCache[ internalKey ] && thisCache[ internalKey ].events;
|
||||
}
|
||||
|
||||
return getByName ? thisCache[ name ] : thisCache;
|
||||
return getByName ?
|
||||
// Check for both converted-to-camel and non-converted data property names
|
||||
thisCache[ jQuery.camelCase( name ) ] || thisCache[ name ] :
|
||||
thisCache;
|
||||
},
|
||||
|
||||
removeData: function( elem, name, pvt /* Internal Use Only */ ) {
|
||||
|
@ -223,12 +227,13 @@ jQuery.fn.extend({
|
|||
data = jQuery.data( this[0] );
|
||||
|
||||
if ( this[0].nodeType === 1 ) {
|
||||
var attr = this[0].attributes, name;
|
||||
var attr = this[0].attributes, name;
|
||||
for ( var i = 0, l = attr.length; i < l; i++ ) {
|
||||
name = attr[i].name;
|
||||
|
||||
if ( name.indexOf( "data-" ) === 0 ) {
|
||||
name = name.substr( 5 );
|
||||
name = jQuery.camelCase( name.substring(5) );
|
||||
|
||||
dataAttr( this[0], name, data[ name ] );
|
||||
}
|
||||
}
|
||||
|
@ -282,7 +287,9 @@ function dataAttr( elem, key, data ) {
|
|||
// If nothing was found internally, try to fetch any
|
||||
// data from the HTML5 data-* attribute
|
||||
if ( data === undefined && elem.nodeType === 1 ) {
|
||||
data = elem.getAttribute( "data-" + key );
|
||||
var name = "data-" + key.replace( rmultiDash, "$1-$2" ).toLowerCase();
|
||||
|
||||
data = elem.getAttribute( name );
|
||||
|
||||
if ( typeof data === "string" ) {
|
||||
try {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var // Promise methods
|
||||
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
|
||||
promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
|
||||
// Static reference to slice
|
||||
sliceDeferred = [].slice;
|
||||
|
||||
|
@ -100,10 +100,37 @@ jQuery.extend({
|
|||
deferred.done( doneCallbacks ).fail( failCallbacks );
|
||||
return this;
|
||||
},
|
||||
always: function() {
|
||||
return deferred.done.apply( deferred, arguments ).fail.apply( this, arguments );
|
||||
},
|
||||
fail: failDeferred.done,
|
||||
rejectWith: failDeferred.resolveWith,
|
||||
reject: failDeferred.resolve,
|
||||
isRejected: failDeferred.isResolved,
|
||||
pipe: function( fnDone, fnFail ) {
|
||||
return jQuery.Deferred(function( newDefer ) {
|
||||
jQuery.each( {
|
||||
done: [ fnDone, "resolve" ],
|
||||
fail: [ fnFail, "reject" ]
|
||||
}, function( handler, data ) {
|
||||
var fn = data[ 0 ],
|
||||
action = data[ 1 ],
|
||||
returned;
|
||||
if ( jQuery.isFunction( fn ) ) {
|
||||
deferred[ handler ](function() {
|
||||
returned = fn.apply( this, arguments );
|
||||
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
||||
returned.promise().then( newDefer.resolve, newDefer.reject );
|
||||
} else {
|
||||
newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
|
||||
}
|
||||
});
|
||||
} else {
|
||||
deferred[ handler ]( newDefer[ action ] );
|
||||
}
|
||||
});
|
||||
}).promise();
|
||||
},
|
||||
// Get a promise for this deferred
|
||||
// If obj is provided, the promise aspect is added to the object
|
||||
promise: function( obj ) {
|
||||
|
@ -119,7 +146,7 @@ jQuery.extend({
|
|||
}
|
||||
return obj;
|
||||
}
|
||||
} );
|
||||
});
|
||||
// Make sure only one callback list will be used
|
||||
deferred.done( failDeferred.cancel ).fail( deferred.cancel );
|
||||
// Unexpose cancel
|
||||
|
@ -169,4 +196,4 @@ jQuery.extend({
|
|||
}
|
||||
});
|
||||
|
||||
})( jQuery );
|
||||
})( jQuery );
|
|
@ -1,21 +1,23 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
// Create innerHeight, innerWidth, outerHeight and outerWidth methods
|
||||
// Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
|
||||
jQuery.each([ "Height", "Width" ], function( i, name ) {
|
||||
|
||||
var type = name.toLowerCase();
|
||||
|
||||
// innerHeight and innerWidth
|
||||
jQuery.fn["inner" + name] = function() {
|
||||
return this[0] ?
|
||||
parseFloat( jQuery.css( this[0], type, "padding" ) ) :
|
||||
jQuery.fn[ "inner" + name ] = function() {
|
||||
var elem = this[0];
|
||||
return elem && elem.style ?
|
||||
parseFloat( jQuery.css( elem, type, "padding" ) ) :
|
||||
null;
|
||||
};
|
||||
|
||||
// outerHeight and outerWidth
|
||||
jQuery.fn["outer" + name] = function( margin ) {
|
||||
return this[0] ?
|
||||
parseFloat( jQuery.css( this[0], type, margin ? "margin" : "border" ) ) :
|
||||
jQuery.fn[ "outer" + name ] = function( margin ) {
|
||||
var elem = this[0];
|
||||
return elem && elem.style ?
|
||||
parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
|
||||
null;
|
||||
};
|
||||
|
||||
|
|
271
src/effects.js
vendored
271
src/effects.js
vendored
|
@ -1,6 +1,7 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
var elemdisplay = {},
|
||||
iframe, iframeDoc,
|
||||
rfxtypes = /^(?:toggle|show|hide)$/,
|
||||
rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
|
||||
timerId,
|
||||
|
@ -11,7 +12,11 @@ var elemdisplay = {},
|
|||
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
|
||||
// opacity animations
|
||||
[ "opacity" ]
|
||||
];
|
||||
],
|
||||
fxNow,
|
||||
requestAnimationFrame = window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame;
|
||||
|
||||
jQuery.fn.extend({
|
||||
show: function( speed, easing, callback ) {
|
||||
|
@ -23,19 +28,22 @@ jQuery.fn.extend({
|
|||
} else {
|
||||
for ( var i = 0, j = this.length; i < j; i++ ) {
|
||||
elem = this[i];
|
||||
display = elem.style.display;
|
||||
|
||||
// Reset the inline display of this element to learn if it is
|
||||
// being hidden by cascaded rules or not
|
||||
if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
|
||||
display = elem.style.display = "";
|
||||
}
|
||||
if ( elem.style ) {
|
||||
display = elem.style.display;
|
||||
|
||||
// Set elements which have been overridden with display: none
|
||||
// in a stylesheet to whatever the default browser style is
|
||||
// for such an element
|
||||
if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
|
||||
jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
|
||||
// Reset the inline display of this element to learn if it is
|
||||
// being hidden by cascaded rules or not
|
||||
if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
|
||||
display = elem.style.display = "";
|
||||
}
|
||||
|
||||
// Set elements which have been overridden with display: none
|
||||
// in a stylesheet to whatever the default browser style is
|
||||
// for such an element
|
||||
if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
|
||||
jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,10 +51,13 @@ jQuery.fn.extend({
|
|||
// to avoid the constant reflow
|
||||
for ( i = 0; i < j; i++ ) {
|
||||
elem = this[i];
|
||||
display = elem.style.display;
|
||||
|
||||
if ( display === "" || display === "none" ) {
|
||||
elem.style.display = jQuery._data(elem, "olddisplay") || "";
|
||||
if ( elem.style ) {
|
||||
display = elem.style.display;
|
||||
|
||||
if ( display === "" || display === "none" ) {
|
||||
elem.style.display = jQuery._data(elem, "olddisplay") || "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,17 +71,21 @@ jQuery.fn.extend({
|
|||
|
||||
} else {
|
||||
for ( var i = 0, j = this.length; i < j; i++ ) {
|
||||
var display = jQuery.css( this[i], "display" );
|
||||
if ( this[i].style ) {
|
||||
var display = jQuery.css( this[i], "display" );
|
||||
|
||||
if ( display !== "none" && !jQuery._data( this[i], "olddisplay" ) ) {
|
||||
jQuery._data( this[i], "olddisplay", display );
|
||||
if ( display !== "none" && !jQuery._data( this[i], "olddisplay" ) ) {
|
||||
jQuery._data( this[i], "olddisplay", display );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the display of the elements in a second loop
|
||||
// to avoid the constant reflow
|
||||
for ( i = 0; i < j; i++ ) {
|
||||
this[i].style.display = "none";
|
||||
if ( this[i].style ) {
|
||||
this[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -108,32 +123,54 @@ jQuery.fn.extend({
|
|||
var optall = jQuery.speed(speed, easing, callback);
|
||||
|
||||
if ( jQuery.isEmptyObject( prop ) ) {
|
||||
return this.each( optall.complete );
|
||||
return this.each( optall.complete, [ false ] );
|
||||
}
|
||||
|
||||
// Do not change referenced properties as per-property easing will be lost
|
||||
prop = jQuery.extend( {}, prop );
|
||||
|
||||
return this[ optall.queue === false ? "each" : "queue" ](function() {
|
||||
// XXX 'this' does not always have a nodeName when running the
|
||||
// test suite
|
||||
|
||||
var opt = jQuery.extend({}, optall), p,
|
||||
if ( optall.queue === false ) {
|
||||
jQuery._mark( this );
|
||||
}
|
||||
|
||||
var opt = jQuery.extend( {}, optall ),
|
||||
isElement = this.nodeType === 1,
|
||||
hidden = isElement && jQuery(this).is(":hidden"),
|
||||
self = this;
|
||||
name, val, p,
|
||||
display, e,
|
||||
parts, start, end, unit;
|
||||
|
||||
// will store per property easing and be used to determine when an animation is complete
|
||||
opt.animatedProperties = {};
|
||||
|
||||
for ( p in prop ) {
|
||||
var name = jQuery.camelCase( p );
|
||||
|
||||
// property name normalization
|
||||
name = jQuery.camelCase( p );
|
||||
if ( p !== name ) {
|
||||
prop[ name ] = prop[ p ];
|
||||
delete prop[ p ];
|
||||
p = name;
|
||||
}
|
||||
|
||||
if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
|
||||
return opt.complete.call(this);
|
||||
val = prop[ name ];
|
||||
|
||||
// easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
|
||||
if ( jQuery.isArray( val ) ) {
|
||||
opt.animatedProperties[ name ] = val[ 1 ];
|
||||
val = prop[ name ] = val[ 0 ];
|
||||
} else {
|
||||
opt.animatedProperties[ name ] = opt.specialEasing && opt.specialEasing[ name ] || opt.easing || 'swing';
|
||||
}
|
||||
|
||||
if ( isElement && ( p === "height" || p === "width" ) ) {
|
||||
if ( val === "hide" && hidden || val === "show" && !hidden ) {
|
||||
return opt.complete.call( this );
|
||||
}
|
||||
|
||||
if ( isElement && ( name === "height" || name === "width" ) ) {
|
||||
// Make sure that nothing sneaks out
|
||||
// Record all 3 overflow attributes because IE does not
|
||||
// change the overflow attribute when overflowX and
|
||||
|
@ -149,7 +186,7 @@ jQuery.fn.extend({
|
|||
this.style.display = "inline-block";
|
||||
|
||||
} else {
|
||||
var display = defaultDisplay(this.nodeName);
|
||||
display = defaultDisplay( this.nodeName );
|
||||
|
||||
// inline-level elements accept inline-block;
|
||||
// block-level elements need to be inline with layout
|
||||
|
@ -163,44 +200,37 @@ jQuery.fn.extend({
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( jQuery.isArray( prop[p] ) ) {
|
||||
// Create (if needed) and add to specialEasing
|
||||
(opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
|
||||
prop[p] = prop[p][0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( opt.overflow != null ) {
|
||||
this.style.overflow = "hidden";
|
||||
}
|
||||
|
||||
opt.curAnim = jQuery.extend({}, prop);
|
||||
|
||||
jQuery.each( prop, function( name, val ) {
|
||||
var e = new jQuery.fx( self, opt, name );
|
||||
for ( p in prop ) {
|
||||
e = new jQuery.fx( this, opt, p );
|
||||
val = prop[ p ];
|
||||
|
||||
if ( rfxtypes.test(val) ) {
|
||||
e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
|
||||
e[ val === "toggle" ? hidden ? "show" : "hide" : val ]();
|
||||
|
||||
} else {
|
||||
var parts = rfxnum.exec(val),
|
||||
start = e.cur();
|
||||
parts = rfxnum.exec( val );
|
||||
start = e.cur();
|
||||
|
||||
if ( parts ) {
|
||||
var end = parseFloat( parts[2] ),
|
||||
unit = parts[3] || ( jQuery.cssNumber[ name ] ? "" : "px" );
|
||||
end = parseFloat( parts[2] );
|
||||
unit = parts[3] || ( jQuery.cssNumber[ p ] ? "" : "px" );
|
||||
|
||||
// We need to compute starting value
|
||||
if ( unit !== "px" ) {
|
||||
jQuery.style( self, name, (end || 1) + unit);
|
||||
jQuery.style( this, p, (end || 1) + unit);
|
||||
start = ((end || 1) / e.cur()) * start;
|
||||
jQuery.style( self, name, start + unit);
|
||||
jQuery.style( this, p, start + unit);
|
||||
}
|
||||
|
||||
// If a +=/-= token was provided, we're doing a relative animation
|
||||
if ( parts[1] ) {
|
||||
end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
|
||||
end = ( (parts[ 1 ] === "-=" ? -1 : 1) * end ) + start;
|
||||
}
|
||||
|
||||
e.custom( start, end, unit );
|
||||
|
@ -209,7 +239,7 @@ jQuery.fn.extend({
|
|||
e.custom( start, val, "" );
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// For JS strict compliance
|
||||
return true;
|
||||
|
@ -217,15 +247,18 @@ jQuery.fn.extend({
|
|||
},
|
||||
|
||||
stop: function( clearQueue, gotoEnd ) {
|
||||
var timers = jQuery.timers;
|
||||
|
||||
if ( clearQueue ) {
|
||||
this.queue([]);
|
||||
}
|
||||
|
||||
this.each(function() {
|
||||
// go in reverse order so anything added to the queue during the loop is ignored
|
||||
for ( var i = timers.length - 1; i >= 0; i-- ) {
|
||||
var timers = jQuery.timers,
|
||||
i = timers.length;
|
||||
// clear marker counters if we know they won't be
|
||||
if ( !gotoEnd ) {
|
||||
jQuery._unmark( true, this );
|
||||
}
|
||||
while ( i-- ) {
|
||||
if ( timers[i].elem === this ) {
|
||||
if (gotoEnd) {
|
||||
// force the next step to be the last
|
||||
|
@ -247,6 +280,17 @@ jQuery.fn.extend({
|
|||
|
||||
});
|
||||
|
||||
// Animations created synchronously will run synchronously
|
||||
function createFxNow() {
|
||||
setTimeout( clearFxNow, 0 );
|
||||
return ( fxNow = jQuery.now() );
|
||||
}
|
||||
|
||||
function clearFxNow() {
|
||||
fxNow = undefined;
|
||||
}
|
||||
|
||||
// Generate parameters to create a standard animation
|
||||
function genFx( type, num ) {
|
||||
var obj = {};
|
||||
|
||||
|
@ -285,13 +329,16 @@ jQuery.extend({
|
|||
|
||||
// Queueing
|
||||
opt.old = opt.complete;
|
||||
opt.complete = function() {
|
||||
if ( opt.queue !== false ) {
|
||||
jQuery(this).dequeue();
|
||||
}
|
||||
opt.complete = function( noUnmark ) {
|
||||
if ( jQuery.isFunction( opt.old ) ) {
|
||||
opt.old.call( this );
|
||||
}
|
||||
|
||||
if ( opt.queue !== false ) {
|
||||
jQuery.dequeue( this );
|
||||
} else if ( noUnmark !== false ) {
|
||||
jQuery._unmark( this );
|
||||
}
|
||||
};
|
||||
|
||||
return opt;
|
||||
|
@ -313,9 +360,7 @@ jQuery.extend({
|
|||
this.elem = elem;
|
||||
this.prop = prop;
|
||||
|
||||
if ( !options.orig ) {
|
||||
options.orig = {};
|
||||
}
|
||||
options.orig = options.orig || {};
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -347,9 +392,10 @@ jQuery.fx.prototype = {
|
|||
// Start an animation from one number to another
|
||||
custom: function( from, to, unit ) {
|
||||
var self = this,
|
||||
fx = jQuery.fx;
|
||||
fx = jQuery.fx,
|
||||
raf;
|
||||
|
||||
this.startTime = jQuery.now();
|
||||
this.startTime = fxNow || createFxNow();
|
||||
this.start = from;
|
||||
this.end = to;
|
||||
this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
|
||||
|
@ -363,7 +409,20 @@ jQuery.fx.prototype = {
|
|||
t.elem = this.elem;
|
||||
|
||||
if ( t() && jQuery.timers.push(t) && !timerId ) {
|
||||
timerId = setInterval(fx.tick, fx.interval);
|
||||
// Use requestAnimationFrame instead of setInterval if available
|
||||
if ( requestAnimationFrame ) {
|
||||
timerId = true;
|
||||
raf = function() {
|
||||
// When timerId gets set to null at any point, this stops
|
||||
if ( timerId ) {
|
||||
requestAnimationFrame( raf );
|
||||
fx.tick();
|
||||
}
|
||||
};
|
||||
requestAnimationFrame( raf );
|
||||
} else {
|
||||
timerId = setInterval( fx.tick, fx.interval );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -394,60 +453,64 @@ jQuery.fx.prototype = {
|
|||
|
||||
// Each step of an animation
|
||||
step: function( gotoEnd ) {
|
||||
var t = jQuery.now(), done = true;
|
||||
var t = fxNow || createFxNow(),
|
||||
done = true,
|
||||
elem = this.elem,
|
||||
options = this.options,
|
||||
i, n;
|
||||
|
||||
if ( gotoEnd || t >= this.options.duration + this.startTime ) {
|
||||
if ( gotoEnd || t >= options.duration + this.startTime ) {
|
||||
this.now = this.end;
|
||||
this.pos = this.state = 1;
|
||||
this.update();
|
||||
|
||||
this.options.curAnim[ this.prop ] = true;
|
||||
options.animatedProperties[ this.prop ] = true;
|
||||
|
||||
for ( var i in this.options.curAnim ) {
|
||||
if ( this.options.curAnim[i] !== true ) {
|
||||
for ( i in options.animatedProperties ) {
|
||||
if ( options.animatedProperties[i] !== true ) {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( done ) {
|
||||
// Reset the overflow
|
||||
if ( this.options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
|
||||
var elem = this.elem,
|
||||
options = this.options;
|
||||
if ( options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
|
||||
|
||||
jQuery.each( [ "", "X", "Y" ], function (index, value) {
|
||||
elem.style[ "overflow" + value ] = options.overflow[index];
|
||||
} );
|
||||
});
|
||||
}
|
||||
|
||||
// Hide the element if the "hide" operation was done
|
||||
if ( this.options.hide ) {
|
||||
jQuery(this.elem).hide();
|
||||
if ( options.hide ) {
|
||||
jQuery(elem).hide();
|
||||
}
|
||||
|
||||
// Reset the properties, if the item has been hidden or shown
|
||||
if ( this.options.hide || this.options.show ) {
|
||||
for ( var p in this.options.curAnim ) {
|
||||
jQuery.style( this.elem, p, this.options.orig[p] );
|
||||
if ( options.hide || options.show ) {
|
||||
for ( var p in options.animatedProperties ) {
|
||||
jQuery.style( elem, p, options.orig[p] );
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the complete function
|
||||
this.options.complete.call( this.elem );
|
||||
options.complete.call( elem );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
} else {
|
||||
var n = t - this.startTime;
|
||||
this.state = n / this.options.duration;
|
||||
|
||||
// Perform the easing function, defaults to swing
|
||||
var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
|
||||
var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
|
||||
this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
|
||||
this.now = this.start + ((this.end - this.start) * this.pos);
|
||||
// classical easing cannot be used with an Infinity duration
|
||||
if ( options.duration == Infinity ) {
|
||||
this.now = t;
|
||||
} else {
|
||||
n = t - this.startTime;
|
||||
this.state = n / options.duration;
|
||||
|
||||
// Perform the easing function, defaults to swing
|
||||
this.pos = jQuery.easing[ options.animatedProperties[ this.prop ] ]( this.state, n, 0, 1, options.duration );
|
||||
this.now = this.start + ((this.end - this.start) * this.pos);
|
||||
}
|
||||
// Perform the next step of the animation
|
||||
this.update();
|
||||
}
|
||||
|
@ -458,9 +521,7 @@ jQuery.fx.prototype = {
|
|||
|
||||
jQuery.extend( jQuery.fx, {
|
||||
tick: function() {
|
||||
var timers = jQuery.timers;
|
||||
|
||||
for ( var i = 0; i < timers.length; i++ ) {
|
||||
for ( var timers = jQuery.timers, i = 0 ; i < timers.length ; ++i ) {
|
||||
if ( !timers[i]() ) {
|
||||
timers.splice(i--, 1);
|
||||
}
|
||||
|
@ -508,17 +569,47 @@ if ( jQuery.expr && jQuery.expr.filters ) {
|
|||
};
|
||||
}
|
||||
|
||||
// Try to restore the default display value of an element
|
||||
function defaultDisplay( nodeName ) {
|
||||
|
||||
if ( !elemdisplay[ nodeName ] ) {
|
||||
var elem = jQuery("<" + nodeName + ">").appendTo("body"),
|
||||
display = elem.css("display");
|
||||
|
||||
var body = document.body,
|
||||
elem = jQuery( "<" + nodeName + ">" ).appendTo( body ),
|
||||
display = elem.css( "display" );
|
||||
|
||||
elem.remove();
|
||||
|
||||
// If the simple way fails,
|
||||
// get element's real default display by attaching it to a temp iframe
|
||||
if ( display === "none" || display === "" ) {
|
||||
display = "block";
|
||||
// No iframe to use yet, so create it
|
||||
if ( !iframe ) {
|
||||
iframe = document.createElement( "iframe" );
|
||||
iframe.frameBorder = iframe.width = iframe.height = 0;
|
||||
}
|
||||
|
||||
body.appendChild( iframe );
|
||||
|
||||
// Create a cacheable copy of the iframe document on first call.
|
||||
// IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML
|
||||
// document to it; WebKit & Firefox won't allow reusing the iframe document.
|
||||
if ( !iframeDoc || !iframe.createElement ) {
|
||||
iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
|
||||
iframeDoc.write( ( document.compatMode === "CSS1Compat" ? "<!doctype html>" : "" ) + "<html><body>" );
|
||||
iframeDoc.close();
|
||||
}
|
||||
|
||||
elem = iframeDoc.createElement( nodeName );
|
||||
|
||||
iframeDoc.body.appendChild( elem );
|
||||
|
||||
display = jQuery.css( elem, "display" );
|
||||
|
||||
body.removeChild( iframe );
|
||||
}
|
||||
|
||||
// Store the correct default display
|
||||
elemdisplay[ nodeName ] = display;
|
||||
}
|
||||
|
||||
|
|
428
src/event.js
428
src/event.js
|
@ -3,7 +3,7 @@
|
|||
var rnamespaces = /\.(.*)$/,
|
||||
rformElems = /^(?:textarea|input|select)$/i,
|
||||
rperiod = /\./g,
|
||||
rspace = / /g,
|
||||
rspaces = / /g,
|
||||
rescape = /[^\w\s.|`]/g,
|
||||
fcleanup = function( nm ) {
|
||||
return nm.replace(rescape, "\\$&");
|
||||
|
@ -23,17 +23,6 @@ jQuery.event = {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO :: Use a try/catch until it's safe to pull this out (likely 1.6)
|
||||
// Minor release fix for bug #8018
|
||||
try {
|
||||
// For whatever reason, IE has trouble passing the window object
|
||||
// around, causing it to be cloned in the process
|
||||
if ( jQuery.isWindow( elem ) && ( elem !== window && !elem.frameElement ) ) {
|
||||
elem = window;
|
||||
}
|
||||
}
|
||||
catch ( e ) {}
|
||||
|
||||
if ( handler === false ) {
|
||||
handler = returnFalse;
|
||||
} else if ( !handler ) {
|
||||
|
@ -71,9 +60,9 @@ jQuery.event = {
|
|||
|
||||
if ( !eventHandle ) {
|
||||
elemData.handle = eventHandle = function( e ) {
|
||||
// Handle the second event of a trigger and when
|
||||
// an event is called after a page has unloaded
|
||||
return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
|
||||
// Discard the second event of a jQuery.event.trigger() and
|
||||
// when an event is called after a page has unloaded
|
||||
return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
|
||||
jQuery.event.handle.apply( eventHandle.elem, arguments ) :
|
||||
undefined;
|
||||
};
|
||||
|
@ -143,7 +132,7 @@ jQuery.event = {
|
|||
// Add the function to the element's handler list
|
||||
handlers.push( handleObj );
|
||||
|
||||
// Keep track of which events have been used, for global triggering
|
||||
// Keep track of which events have been used, for event optimization
|
||||
jQuery.event.global[ type ] = true;
|
||||
}
|
||||
|
||||
|
@ -276,182 +265,185 @@ jQuery.event = {
|
|||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Events that are safe to short-circuit if no handlers are attached.
|
||||
// Native DOM events should not be added, they may have inline handlers.
|
||||
customEvent: {
|
||||
"getData": true,
|
||||
"setData": true,
|
||||
"changeData": true
|
||||
},
|
||||
|
||||
// bubbling is internal
|
||||
trigger: function( event, data, elem /*, bubbling */ ) {
|
||||
trigger: function( event, data, elem, onlyHandlers ) {
|
||||
// Event object or event type
|
||||
var type = event.type || event,
|
||||
bubbling = arguments[3];
|
||||
namespaces = [],
|
||||
exclusive;
|
||||
|
||||
if ( !bubbling ) {
|
||||
event = typeof event === "object" ?
|
||||
// jQuery.Event object
|
||||
event[ jQuery.expando ] ? event :
|
||||
// Object literal
|
||||
jQuery.extend( jQuery.Event(type), event ) :
|
||||
// Just the event type (string)
|
||||
jQuery.Event(type);
|
||||
|
||||
if ( type.indexOf("!") >= 0 ) {
|
||||
event.type = type = type.slice(0, -1);
|
||||
event.exclusive = true;
|
||||
}
|
||||
|
||||
// Handle a global trigger
|
||||
if ( !elem ) {
|
||||
// Don't bubble custom events when global (to avoid too much overhead)
|
||||
event.stopPropagation();
|
||||
|
||||
// Only trigger if we've ever bound an event for it
|
||||
if ( jQuery.event.global[ type ] ) {
|
||||
// XXX This code smells terrible. event.js should not be directly
|
||||
// inspecting the data cache
|
||||
jQuery.each( jQuery.cache, function() {
|
||||
// internalKey variable is just used to make it easier to find
|
||||
// and potentially change this stuff later; currently it just
|
||||
// points to jQuery.expando
|
||||
var internalKey = jQuery.expando,
|
||||
internalCache = this[ internalKey ];
|
||||
if ( internalCache && internalCache.events && internalCache.events[ type ] ) {
|
||||
jQuery.event.trigger( event, data, internalCache.handle.elem );
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Handle triggering a single element
|
||||
|
||||
// don't do events on text and comment nodes
|
||||
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Clean up in case it is reused
|
||||
event.result = undefined;
|
||||
event.target = elem;
|
||||
|
||||
// Clone the incoming data, if any
|
||||
data = jQuery.makeArray( data );
|
||||
data.unshift( event );
|
||||
if ( type.indexOf("!") >= 0 ) {
|
||||
// Exclusive events trigger only for the exact event (no namespaces)
|
||||
type = type.slice(0, -1);
|
||||
exclusive = true;
|
||||
}
|
||||
|
||||
event.currentTarget = elem;
|
||||
|
||||
// Trigger the event, it is assumed that "handle" is a function
|
||||
var handle = jQuery._data( elem, "handle" );
|
||||
|
||||
if ( handle ) {
|
||||
handle.apply( elem, data );
|
||||
if ( type.indexOf(".") >= 0 ) {
|
||||
// Namespaced trigger; create a regexp to match event type in handle()
|
||||
namespaces = type.split(".");
|
||||
type = namespaces.shift();
|
||||
namespaces.sort();
|
||||
}
|
||||
|
||||
var parent = elem.parentNode || elem.ownerDocument;
|
||||
if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) {
|
||||
// No jQuery handlers for this event type, and it can't have inline handlers
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger an inline bound script
|
||||
try {
|
||||
if ( !(elem && elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()]) ) {
|
||||
if ( elem[ "on" + type ] && elem[ "on" + type ].apply( elem, data ) === false ) {
|
||||
event.result = false;
|
||||
event.preventDefault();
|
||||
// Caller can pass in an Event, Object, or just an event type string
|
||||
event = typeof event === "object" ?
|
||||
// jQuery.Event object
|
||||
event[ jQuery.expando ] ? event :
|
||||
// Object literal
|
||||
new jQuery.Event( type, event ) :
|
||||
// Just the event type (string)
|
||||
new jQuery.Event( type );
|
||||
|
||||
event.type = type;
|
||||
event.exclusive = exclusive;
|
||||
event.namespace = namespaces.join(".");
|
||||
event.namespace_re = new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)");
|
||||
|
||||
// triggerHandler() and global events don't bubble or run the default action
|
||||
if ( onlyHandlers || !elem ) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
// Handle a global trigger
|
||||
if ( !elem ) {
|
||||
// TODO: Stop taunting the data cache; remove global events and always attach to document
|
||||
jQuery.each( jQuery.cache, function() {
|
||||
// internalKey variable is just used to make it easier to find
|
||||
// and potentially change this stuff later; currently it just
|
||||
// points to jQuery.expando
|
||||
var internalKey = jQuery.expando,
|
||||
internalCache = this[ internalKey ];
|
||||
if ( internalCache && internalCache.events && internalCache.events[ type ] ) {
|
||||
jQuery.event.trigger( event, data, internalCache.handle.elem );
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't do events on text and comment nodes
|
||||
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up the event in case it is being reused
|
||||
event.result = undefined;
|
||||
event.target = elem;
|
||||
|
||||
// Clone any incoming data and prepend the event, creating the handler arg list
|
||||
data = data != null ? jQuery.makeArray( data ) : [];
|
||||
data.unshift( event );
|
||||
|
||||
var cur = elem,
|
||||
// IE doesn't like method names with a colon (#3533, #8272)
|
||||
ontype = type.indexOf(":") < 0 ? "on" + type : "";
|
||||
|
||||
// Fire event on the current element, then bubble up the DOM tree
|
||||
do {
|
||||
var handle = jQuery._data( cur, "handle" );
|
||||
|
||||
event.currentTarget = cur;
|
||||
if ( handle ) {
|
||||
handle.apply( cur, data );
|
||||
}
|
||||
|
||||
// prevent IE from throwing an error for some elements with some event types, see #3533
|
||||
} catch (inlineError) {}
|
||||
// Trigger an inline bound script
|
||||
if ( ontype && jQuery.acceptData( cur ) && cur[ ontype ] && cur[ ontype ].apply( cur, data ) === false ) {
|
||||
event.result = false;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if ( !event.isPropagationStopped() && parent ) {
|
||||
jQuery.event.trigger( event, data, parent, true );
|
||||
// Bubble up to document, then to window
|
||||
cur = cur.parentNode || cur.ownerDocument || cur === event.target.ownerDocument && window;
|
||||
} while ( cur && !event.isPropagationStopped() );
|
||||
|
||||
} else if ( !event.isDefaultPrevented() ) {
|
||||
// If nobody prevented the default action, do it now
|
||||
if ( !event.isDefaultPrevented() ) {
|
||||
var old,
|
||||
target = event.target,
|
||||
targetType = type.replace( rnamespaces, "" ),
|
||||
isClick = jQuery.nodeName( target, "a" ) && targetType === "click",
|
||||
special = jQuery.event.special[ targetType ] || {};
|
||||
special = jQuery.event.special[ type ] || {};
|
||||
|
||||
if ( (!special._default || special._default.call( elem, event ) === false) &&
|
||||
!isClick && !(target && target.nodeName && jQuery.noData[target.nodeName.toLowerCase()]) ) {
|
||||
if ( (!special._default || special._default.call( elem.ownerDocument, event ) === false) &&
|
||||
!(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
|
||||
|
||||
// Call a native DOM method on the target with the same name name as the event.
|
||||
// Can't use an .isFunction)() check here because IE6/7 fails that test.
|
||||
// IE<9 dies on focus to hidden element (#1486), may want to revisit a try/catch.
|
||||
try {
|
||||
if ( target[ targetType ] ) {
|
||||
// Make sure that we don't accidentally re-trigger the onFOO events
|
||||
old = target[ "on" + targetType ];
|
||||
if ( ontype && elem[ type ] ) {
|
||||
// Don't re-trigger an onFOO event when we call its FOO() method
|
||||
old = elem[ ontype ];
|
||||
|
||||
if ( old ) {
|
||||
target[ "on" + targetType ] = null;
|
||||
elem[ ontype ] = null;
|
||||
}
|
||||
|
||||
jQuery.event.triggered = event.type;
|
||||
target[ targetType ]();
|
||||
jQuery.event.triggered = type;
|
||||
elem[ type ]();
|
||||
}
|
||||
|
||||
// prevent IE from throwing an error for some elements with some event types, see #3533
|
||||
} catch (triggerError) {}
|
||||
} catch ( ieError ) {}
|
||||
|
||||
if ( old ) {
|
||||
target[ "on" + targetType ] = old;
|
||||
elem[ ontype ] = old;
|
||||
}
|
||||
|
||||
jQuery.event.triggered = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return event.result;
|
||||
},
|
||||
|
||||
handle: function( event ) {
|
||||
var all, handlers, namespaces, namespace_re, events,
|
||||
namespace_sort = [],
|
||||
args = jQuery.makeArray( arguments );
|
||||
event = jQuery.event.fix( event || window.event );
|
||||
// Snapshot the handlers list since a called handler may add/remove events.
|
||||
var handlers = ((jQuery._data( this, "events" ) || {})[ event.type ] || []).slice(0),
|
||||
run_all = !event.exclusive && !event.namespace,
|
||||
args = Array.prototype.slice.call( arguments, 0 );
|
||||
|
||||
event = args[0] = jQuery.event.fix( event || window.event );
|
||||
// Use the fix-ed Event rather than the (read-only) native event
|
||||
args[0] = event;
|
||||
event.currentTarget = this;
|
||||
|
||||
// Namespaced event handlers
|
||||
all = event.type.indexOf(".") < 0 && !event.exclusive;
|
||||
for ( var j = 0, l = handlers.length; j < l; j++ ) {
|
||||
var handleObj = handlers[ j ];
|
||||
|
||||
if ( !all ) {
|
||||
namespaces = event.type.split(".");
|
||||
event.type = namespaces.shift();
|
||||
namespace_sort = namespaces.slice(0).sort();
|
||||
namespace_re = new RegExp("(^|\\.)" + namespace_sort.join("\\.(?:.*\\.)?") + "(\\.|$)");
|
||||
}
|
||||
// Triggered event must 1) be non-exclusive and have no namespace, or
|
||||
// 2) have namespace(s) a subset or equal to those in the bound event.
|
||||
if ( run_all || event.namespace_re.test( handleObj.namespace ) ) {
|
||||
// Pass in a reference to the handler function itself
|
||||
// So that we can later remove it
|
||||
event.handler = handleObj.handler;
|
||||
event.data = handleObj.data;
|
||||
event.handleObj = handleObj;
|
||||
|
||||
event.namespace = event.namespace || namespace_sort.join(".");
|
||||
var ret = handleObj.handler.apply( this, args );
|
||||
|
||||
events = jQuery._data(this, "events");
|
||||
|
||||
handlers = (events || {})[ event.type ];
|
||||
|
||||
if ( events && handlers ) {
|
||||
// Clone the handlers to prevent manipulation
|
||||
handlers = handlers.slice(0);
|
||||
|
||||
for ( var j = 0, l = handlers.length; j < l; j++ ) {
|
||||
var handleObj = handlers[ j ];
|
||||
|
||||
// Filter the functions by class
|
||||
if ( all || namespace_re.test( handleObj.namespace ) ) {
|
||||
// Pass in a reference to the handler function itself
|
||||
// So that we can later remove it
|
||||
event.handler = handleObj.handler;
|
||||
event.data = handleObj.data;
|
||||
event.handleObj = handleObj;
|
||||
|
||||
var ret = handleObj.handler.apply( this, args );
|
||||
|
||||
if ( ret !== undefined ) {
|
||||
event.result = ret;
|
||||
if ( ret === false ) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
if ( ret !== undefined ) {
|
||||
event.result = ret;
|
||||
if ( ret === false ) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
if ( event.isImmediatePropagationStopped() ) {
|
||||
break;
|
||||
}
|
||||
if ( event.isImmediatePropagationStopped() ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return event.result;
|
||||
},
|
||||
|
||||
|
@ -490,8 +482,9 @@ jQuery.event = {
|
|||
|
||||
// Calculate pageX/Y if missing and clientX/Y available
|
||||
if ( event.pageX == null && event.clientX != null ) {
|
||||
var doc = document.documentElement,
|
||||
body = document.body;
|
||||
var eventDocument = event.target.ownerDocument || document,
|
||||
doc = eventDocument.documentElement,
|
||||
body = eventDocument.body;
|
||||
|
||||
event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
|
||||
event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
|
||||
|
@ -570,10 +563,10 @@ jQuery.removeEvent = document.removeEventListener ?
|
|||
}
|
||||
};
|
||||
|
||||
jQuery.Event = function( src ) {
|
||||
jQuery.Event = function( src, props ) {
|
||||
// Allow instantiation without the 'new' keyword
|
||||
if ( !this.preventDefault ) {
|
||||
return new jQuery.Event( src );
|
||||
return new jQuery.Event( src, props );
|
||||
}
|
||||
|
||||
// Event object
|
||||
|
@ -591,6 +584,11 @@ jQuery.Event = function( src ) {
|
|||
this.type = src;
|
||||
}
|
||||
|
||||
// Put explicitly provided properties onto the event object
|
||||
if ( props ) {
|
||||
jQuery.extend( this, props );
|
||||
}
|
||||
|
||||
// timeStamp is buggy for some events on Firefox(#3843)
|
||||
// So we won't rely on the native value
|
||||
this.timeStamp = jQuery.now();
|
||||
|
@ -652,33 +650,27 @@ jQuery.Event.prototype = {
|
|||
// Checks if an event happened on an element within another element
|
||||
// Used in jQuery.event.special.mouseenter and mouseleave handlers
|
||||
var withinElement = function( event ) {
|
||||
|
||||
// Check if mouse(over|out) are still within the same parent element
|
||||
var parent = event.relatedTarget;
|
||||
var related = event.relatedTarget,
|
||||
inside = false,
|
||||
eventType = event.type;
|
||||
|
||||
// Firefox sometimes assigns relatedTarget a XUL element
|
||||
// which we cannot access the parentNode property of
|
||||
try {
|
||||
event.type = event.data;
|
||||
|
||||
// Chrome does something similar, the parentNode property
|
||||
// can be accessed but is null.
|
||||
if ( parent && parent !== document && !parent.parentNode ) {
|
||||
return;
|
||||
}
|
||||
// Traverse up the tree
|
||||
while ( parent && parent !== this ) {
|
||||
parent = parent.parentNode;
|
||||
if ( related !== this ) {
|
||||
|
||||
if ( related ) {
|
||||
inside = jQuery.contains( this, related );
|
||||
}
|
||||
|
||||
if ( parent !== this ) {
|
||||
// set the correct event type
|
||||
event.type = event.data;
|
||||
if ( !inside ) {
|
||||
|
||||
// handle event if we actually just moused on to a non sub-element
|
||||
jQuery.event.handle.apply( this, arguments );
|
||||
}
|
||||
|
||||
// assuming we've left the element since we most likely mousedover a xul element
|
||||
} catch(e) { }
|
||||
event.type = eventType;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// In case of event delegation, we only need to rename the event.type,
|
||||
|
@ -708,7 +700,7 @@ if ( !jQuery.support.submitBubbles ) {
|
|||
|
||||
jQuery.event.special.submit = {
|
||||
setup: function( data, namespaces ) {
|
||||
if ( this.nodeName && this.nodeName.toLowerCase() !== "form" ) {
|
||||
if ( !jQuery.nodeName( this, "form" ) ) {
|
||||
jQuery.event.add(this, "click.specialSubmit", function( e ) {
|
||||
var elem = e.target,
|
||||
type = elem.type;
|
||||
|
@ -757,7 +749,7 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
}).join("-") :
|
||||
"";
|
||||
|
||||
} else if ( elem.nodeName.toLowerCase() === "select" ) {
|
||||
} else if ( jQuery.nodeName( elem, "select" ) ) {
|
||||
val = elem.selectedIndex;
|
||||
}
|
||||
|
||||
|
@ -797,9 +789,9 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
beforedeactivate: testChange,
|
||||
|
||||
click: function( e ) {
|
||||
var elem = e.target, type = elem.type;
|
||||
var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : "";
|
||||
|
||||
if ( type === "radio" || type === "checkbox" || elem.nodeName.toLowerCase() === "select" ) {
|
||||
if ( type === "radio" || type === "checkbox" || jQuery.nodeName( elem, "select" ) ) {
|
||||
testChange.call( this, e );
|
||||
}
|
||||
},
|
||||
|
@ -807,9 +799,9 @@ if ( !jQuery.support.changeBubbles ) {
|
|||
// Change has to be called before submit
|
||||
// Keydown will be called before keypress, which is used in submit-event delegation
|
||||
keydown: function( e ) {
|
||||
var elem = e.target, type = elem.type;
|
||||
var elem = e.target, type = jQuery.nodeName( elem, "input" ) ? elem.type : "";
|
||||
|
||||
if ( (e.keyCode === 13 && elem.nodeName.toLowerCase() !== "textarea") ||
|
||||
if ( (e.keyCode === 13 && !jQuery.nodeName( elem, "textarea" ) ) ||
|
||||
(e.keyCode === 32 && (type === "checkbox" || type === "radio")) ||
|
||||
type === "select-multiple" ) {
|
||||
testChange.call( this, e );
|
||||
|
@ -866,12 +858,12 @@ function trigger( type, elem, args ) {
|
|||
}
|
||||
|
||||
// Create "bubbling" focus and blur events
|
||||
if ( document.addEventListener ) {
|
||||
if ( !jQuery.support.focusinBubbles ) {
|
||||
jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
|
||||
|
||||
|
||||
// Attach a single capturing handler while someone wants focusin/focusout
|
||||
var attaches = 0;
|
||||
|
||||
|
||||
jQuery.event.special[ fix ] = {
|
||||
setup: function() {
|
||||
if ( attaches++ === 0 ) {
|
||||
|
@ -901,6 +893,8 @@ if ( document.addEventListener ) {
|
|||
|
||||
jQuery.each(["bind", "one"], function( i, name ) {
|
||||
jQuery.fn[ name ] = function( type, data, fn ) {
|
||||
var handler;
|
||||
|
||||
// Handle object literals
|
||||
if ( typeof type === "object" ) {
|
||||
for ( var key in type ) {
|
||||
|
@ -909,15 +903,20 @@ jQuery.each(["bind", "one"], function( i, name ) {
|
|||
return this;
|
||||
}
|
||||
|
||||
if ( jQuery.isFunction( data ) || data === false ) {
|
||||
if ( arguments.length === 2 || data === false ) {
|
||||
fn = data;
|
||||
data = undefined;
|
||||
}
|
||||
|
||||
var handler = name === "one" ? jQuery.proxy( fn, function( event ) {
|
||||
jQuery( this ).unbind( event, handler );
|
||||
return fn.apply( this, arguments );
|
||||
}) : fn;
|
||||
if ( name === "one" ) {
|
||||
handler = function( event ) {
|
||||
jQuery( this ).unbind( event, handler );
|
||||
return fn.apply( this, arguments );
|
||||
};
|
||||
handler.guid = fn.guid || jQuery.guid++;
|
||||
} else {
|
||||
handler = fn;
|
||||
}
|
||||
|
||||
if ( type === "unload" && name !== "one" ) {
|
||||
this.one( type, data, fn );
|
||||
|
@ -955,7 +954,7 @@ jQuery.fn.extend({
|
|||
|
||||
undelegate: function( selector, types, fn ) {
|
||||
if ( arguments.length === 0 ) {
|
||||
return this.unbind( "live" );
|
||||
return this.unbind( "live" );
|
||||
|
||||
} else {
|
||||
return this.die( types, null, fn, selector );
|
||||
|
@ -970,35 +969,34 @@ jQuery.fn.extend({
|
|||
|
||||
triggerHandler: function( type, data ) {
|
||||
if ( this[0] ) {
|
||||
var event = jQuery.Event( type );
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
jQuery.event.trigger( event, data, this[0] );
|
||||
return event.result;
|
||||
return jQuery.event.trigger( type, data, this[0], true );
|
||||
}
|
||||
},
|
||||
|
||||
toggle: function( fn ) {
|
||||
// Save reference to arguments for access in closure
|
||||
var args = arguments,
|
||||
i = 1;
|
||||
guid = fn.guid || jQuery.guid++,
|
||||
i = 0,
|
||||
toggler = function( event ) {
|
||||
// Figure out which function to execute
|
||||
var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i;
|
||||
jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 );
|
||||
|
||||
// Make sure that clicks stop
|
||||
event.preventDefault();
|
||||
|
||||
// and execute the function
|
||||
return args[ lastToggle ].apply( this, arguments ) || false;
|
||||
};
|
||||
|
||||
// link all the functions, so any of them can unbind this click handler
|
||||
toggler.guid = guid;
|
||||
while ( i < args.length ) {
|
||||
jQuery.proxy( fn, args[ i++ ] );
|
||||
args[ i++ ].guid = guid;
|
||||
}
|
||||
|
||||
return this.click( jQuery.proxy( fn, function( event ) {
|
||||
// Figure out which function to execute
|
||||
var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
|
||||
jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
|
||||
|
||||
// Make sure that clicks stop
|
||||
event.preventDefault();
|
||||
|
||||
// and execute the function
|
||||
return args[ lastToggle ].apply( this, arguments ) || false;
|
||||
}));
|
||||
return this.click( toggler );
|
||||
},
|
||||
|
||||
hover: function( fnOver, fnOut ) {
|
||||
|
@ -1027,8 +1025,16 @@ jQuery.each(["live", "die"], function( i, name ) {
|
|||
return this;
|
||||
}
|
||||
|
||||
if ( jQuery.isFunction( data ) ) {
|
||||
fn = data;
|
||||
if ( name === "die" && !types &&
|
||||
origSelector && origSelector.charAt(0) === "." ) {
|
||||
|
||||
context.unbind( origSelector );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
if ( data === false || jQuery.isFunction( data ) ) {
|
||||
fn = data || returnFalse;
|
||||
data = undefined;
|
||||
}
|
||||
|
||||
|
@ -1050,7 +1056,7 @@ jQuery.each(["live", "die"], function( i, name ) {
|
|||
|
||||
preType = type;
|
||||
|
||||
if ( type === "focus" || type === "blur" ) {
|
||||
if ( liveMap[ type ] ) {
|
||||
types.push( liveMap[ type ] + namespaces );
|
||||
type = type + namespaces;
|
||||
|
||||
|
@ -1121,6 +1127,11 @@ function liveHandler( event ) {
|
|||
if ( handleObj.preType === "mouseenter" || handleObj.preType === "mouseleave" ) {
|
||||
event.type = handleObj.preType;
|
||||
related = jQuery( event.relatedTarget ).closest( handleObj.selector )[0];
|
||||
|
||||
// Make sure not to accidentally match a child element with the same selector
|
||||
if ( related && jQuery.contains( elem, related ) ) {
|
||||
related = elem;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !related || related !== elem ) {
|
||||
|
@ -1159,7 +1170,7 @@ function liveHandler( event ) {
|
|||
}
|
||||
|
||||
function liveConvert( type, selector ) {
|
||||
return (type && type !== "*" ? type + "." : "") + selector.replace(rperiod, "`").replace(rspace, "&");
|
||||
return (type && type !== "*" ? type + "." : "") + selector.replace(rperiod, "`").replace(rspaces, "&");
|
||||
}
|
||||
|
||||
jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
|
||||
|
@ -1184,3 +1195,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
|
|||
});
|
||||
|
||||
})( jQuery );
|
||||
|
||||
|
|
|
@ -16,4 +16,6 @@
|
|||
(function( window, undefined ) {
|
||||
|
||||
// Use the correct document accordingly with window argument (sandbox)
|
||||
var document = window.document;
|
||||
var document = window.document,
|
||||
navigator = window.navigator,
|
||||
location = window.location;
|
||||
|
|
|
@ -9,6 +9,8 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
|
|||
rnocache = /<(?:script|object|embed|option|style)/i,
|
||||
// checked="checked" or checked
|
||||
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
|
||||
rscriptType = /\/(java|ecma)script/i,
|
||||
rcleanScript = /^\s*<!(?:\[CDATA\[|\-\-)/,
|
||||
wrapMap = {
|
||||
option: [ 1, "<select multiple='multiple'>", "</select>" ],
|
||||
legend: [ 1, "<fieldset>", "</fieldset>" ],
|
||||
|
@ -69,7 +71,7 @@ jQuery.fn.extend({
|
|||
}
|
||||
|
||||
return elem;
|
||||
}).append(this);
|
||||
}).append( this );
|
||||
}
|
||||
|
||||
return this;
|
||||
|
@ -377,21 +379,27 @@ function cloneCopyEvent( src, dest ) {
|
|||
}
|
||||
}
|
||||
|
||||
function cloneFixAttributes(src, dest) {
|
||||
function cloneFixAttributes( src, dest ) {
|
||||
var nodeName;
|
||||
|
||||
// We do not need to do anything for non-Elements
|
||||
if ( dest.nodeType !== 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var nodeName = dest.nodeName.toLowerCase();
|
||||
|
||||
// clearAttributes removes the attributes, which we don't want,
|
||||
// but also removes the attachEvent events, which we *do* want
|
||||
dest.clearAttributes();
|
||||
if ( dest.clearAttributes ) {
|
||||
dest.clearAttributes();
|
||||
}
|
||||
|
||||
// mergeAttributes, in contrast, only merges back on the
|
||||
// original attributes, not the events
|
||||
dest.mergeAttributes(src);
|
||||
if ( dest.mergeAttributes ) {
|
||||
dest.mergeAttributes( src );
|
||||
}
|
||||
|
||||
nodeName = dest.nodeName.toLowerCase();
|
||||
|
||||
// IE6-8 fail to clone children inside object elements that use
|
||||
// the proprietary classid attribute value (rather than the type
|
||||
|
@ -430,8 +438,21 @@ function cloneFixAttributes(src, dest) {
|
|||
}
|
||||
|
||||
jQuery.buildFragment = function( args, nodes, scripts ) {
|
||||
var fragment, cacheable, cacheresults,
|
||||
doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
|
||||
var fragment, cacheable, cacheresults, doc;
|
||||
|
||||
// nodes may contain either an explicit document object,
|
||||
// a jQuery collection or context object.
|
||||
// If nodes[0] contains a valid object to assign to doc
|
||||
if ( nodes && nodes[0] ) {
|
||||
doc = nodes[0].ownerDocument || nodes[0];
|
||||
}
|
||||
|
||||
// Ensure that an attr object doesn't incorrectly stand in as a document object
|
||||
// Chrome and Firefox seem to allow this to occur and will throw exception
|
||||
// Fixes #8950
|
||||
if ( !doc.createDocumentFragment ) {
|
||||
doc = document;
|
||||
}
|
||||
|
||||
// Only cache "small" (1/2 KB) HTML strings that are associated with the main document
|
||||
// Cloning options loses the selected state, so don't cache them
|
||||
|
@ -441,11 +462,10 @@ jQuery.buildFragment = function( args, nodes, scripts ) {
|
|||
args[0].charAt(0) === "<" && !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
|
||||
|
||||
cacheable = true;
|
||||
|
||||
cacheresults = jQuery.fragments[ args[0] ];
|
||||
if ( cacheresults ) {
|
||||
if ( cacheresults !== 1 ) {
|
||||
fragment = cacheresults;
|
||||
}
|
||||
if ( cacheresults && cacheresults !== 1 ) {
|
||||
fragment = cacheresults;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -494,7 +514,7 @@ jQuery.each({
|
|||
function getAll( elem ) {
|
||||
if ( "getElementsByTagName" in elem ) {
|
||||
return elem.getElementsByTagName( "*" );
|
||||
|
||||
|
||||
} else if ( "querySelectorAll" in elem ) {
|
||||
return elem.querySelectorAll( "*" );
|
||||
|
||||
|
@ -503,6 +523,21 @@ function getAll( elem ) {
|
|||
}
|
||||
}
|
||||
|
||||
// Used in clean, fixes the defaultChecked property
|
||||
function fixDefaultChecked( elem ) {
|
||||
if ( elem.type === "checkbox" || elem.type === "radio" ) {
|
||||
elem.defaultChecked = elem.checked;
|
||||
}
|
||||
}
|
||||
// Finds all inputs and passes them to fixDefaultChecked
|
||||
function findInputs( elem ) {
|
||||
if ( jQuery.nodeName( elem, "input" ) ) {
|
||||
fixDefaultChecked( elem );
|
||||
} else if ( "getElementsByTagName" in elem ) {
|
||||
jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
|
||||
}
|
||||
}
|
||||
|
||||
jQuery.extend({
|
||||
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
|
||||
var clone = elem.cloneNode(true),
|
||||
|
@ -547,10 +582,15 @@ jQuery.extend({
|
|||
}
|
||||
}
|
||||
|
||||
srcElements = destElements = null;
|
||||
|
||||
// Return the cloned set
|
||||
return clone;
|
||||
},
|
||||
},
|
||||
|
||||
clean: function( elems, context, fragment, scripts ) {
|
||||
var checkScriptType;
|
||||
|
||||
context = context || document;
|
||||
|
||||
// !context.createElement fails in IE with an error but returns typeof 'object'
|
||||
|
@ -558,7 +598,7 @@ jQuery.extend({
|
|||
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
|
||||
}
|
||||
|
||||
var ret = [];
|
||||
var ret = [], j;
|
||||
|
||||
for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
|
||||
if ( typeof elem === "number" ) {
|
||||
|
@ -570,54 +610,67 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
// Convert html string into DOM nodes
|
||||
if ( typeof elem === "string" && !rhtml.test( elem ) ) {
|
||||
elem = context.createTextNode( elem );
|
||||
if ( typeof elem === "string" ) {
|
||||
if ( !rhtml.test( elem ) ) {
|
||||
elem = context.createTextNode( elem );
|
||||
} else {
|
||||
// Fix "XHTML"-style tags in all browsers
|
||||
elem = elem.replace(rxhtmlTag, "<$1></$2>");
|
||||
|
||||
} else if ( typeof elem === "string" ) {
|
||||
// Fix "XHTML"-style tags in all browsers
|
||||
elem = elem.replace(rxhtmlTag, "<$1></$2>");
|
||||
// Trim whitespace, otherwise indexOf won't work as expected
|
||||
var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
|
||||
wrap = wrapMap[ tag ] || wrapMap._default,
|
||||
depth = wrap[0],
|
||||
div = context.createElement("div");
|
||||
|
||||
// Trim whitespace, otherwise indexOf won't work as expected
|
||||
var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
|
||||
wrap = wrapMap[ tag ] || wrapMap._default,
|
||||
depth = wrap[0],
|
||||
div = context.createElement("div");
|
||||
// Go to html and back, then peel off extra wrappers
|
||||
div.innerHTML = wrap[1] + elem + wrap[2];
|
||||
|
||||
// Go to html and back, then peel off extra wrappers
|
||||
div.innerHTML = wrap[1] + elem + wrap[2];
|
||||
// Move to the right depth
|
||||
while ( depth-- ) {
|
||||
div = div.lastChild;
|
||||
}
|
||||
|
||||
// Move to the right depth
|
||||
while ( depth-- ) {
|
||||
div = div.lastChild;
|
||||
}
|
||||
// Remove IE's autoinserted <tbody> from table fragments
|
||||
if ( !jQuery.support.tbody ) {
|
||||
|
||||
// Remove IE's autoinserted <tbody> from table fragments
|
||||
if ( !jQuery.support.tbody ) {
|
||||
// String was a <table>, *may* have spurious <tbody>
|
||||
var hasBody = rtbody.test(elem),
|
||||
tbody = tag === "table" && !hasBody ?
|
||||
div.firstChild && div.firstChild.childNodes :
|
||||
|
||||
// String was a <table>, *may* have spurious <tbody>
|
||||
var hasBody = rtbody.test(elem),
|
||||
tbody = tag === "table" && !hasBody ?
|
||||
div.firstChild && div.firstChild.childNodes :
|
||||
// String was a bare <thead> or <tfoot>
|
||||
wrap[1] === "<table>" && !hasBody ?
|
||||
div.childNodes :
|
||||
[];
|
||||
|
||||
// String was a bare <thead> or <tfoot>
|
||||
wrap[1] === "<table>" && !hasBody ?
|
||||
div.childNodes :
|
||||
[];
|
||||
|
||||
for ( var j = tbody.length - 1; j >= 0 ; --j ) {
|
||||
if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
|
||||
tbody[ j ].parentNode.removeChild( tbody[ j ] );
|
||||
for ( j = tbody.length - 1; j >= 0 ; --j ) {
|
||||
if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
|
||||
tbody[ j ].parentNode.removeChild( tbody[ j ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// IE completely kills leading whitespace when innerHTML is used
|
||||
if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
|
||||
div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
|
||||
}
|
||||
|
||||
// IE completely kills leading whitespace when innerHTML is used
|
||||
if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
|
||||
div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
|
||||
elem = div.childNodes;
|
||||
}
|
||||
}
|
||||
|
||||
elem = div.childNodes;
|
||||
// Resets defaultChecked for any radios and checkboxes
|
||||
// about to be appended to the DOM in IE 6/7 (#8060)
|
||||
var len;
|
||||
if ( !jQuery.support.appendChecked ) {
|
||||
if ( elem[0] && typeof (len = elem.length) === "number" ) {
|
||||
for ( j = 0; j < len; j++ ) {
|
||||
findInputs( elem[j] );
|
||||
}
|
||||
} else {
|
||||
findInputs( elem );
|
||||
}
|
||||
}
|
||||
|
||||
if ( elem.nodeType ) {
|
||||
|
@ -628,13 +681,18 @@ jQuery.extend({
|
|||
}
|
||||
|
||||
if ( fragment ) {
|
||||
checkScriptType = function( elem ) {
|
||||
return !elem.type || rscriptType.test( elem.type );
|
||||
};
|
||||
for ( i = 0; ret[i]; i++ ) {
|
||||
if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
|
||||
scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
|
||||
|
||||
} else {
|
||||
if ( ret[i].nodeType === 1 ) {
|
||||
ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
|
||||
var jsTags = jQuery.grep( ret[i].getElementsByTagName( "script" ), checkScriptType );
|
||||
|
||||
ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
|
||||
}
|
||||
fragment.appendChild( ret[i] );
|
||||
}
|
||||
|
@ -696,7 +754,7 @@ function evalScript( i, elem ) {
|
|||
dataType: "script"
|
||||
});
|
||||
} else {
|
||||
jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
|
||||
jQuery.globalEval( ( elem.text || elem.textContent || elem.innerHTML || "" ).replace( rcleanScript, "/*$0*/" ) );
|
||||
}
|
||||
|
||||
if ( elem.parentNode ) {
|
||||
|
@ -704,4 +762,4 @@ function evalScript( i, elem ) {
|
|||
}
|
||||
}
|
||||
|
||||
})( jQuery );
|
||||
})( jQuery );
|
|
@ -180,17 +180,19 @@ jQuery.offset = {
|
|||
curOffset = curElem.offset(),
|
||||
curCSSTop = jQuery.css( elem, "top" ),
|
||||
curCSSLeft = jQuery.css( elem, "left" ),
|
||||
calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray('auto', [curCSSTop, curCSSLeft]) > -1,
|
||||
calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
|
||||
props = {}, curPosition = {}, curTop, curLeft;
|
||||
|
||||
// need to be able to calculate position if either top or left is auto and position is either absolute or fixed
|
||||
if ( calculatePosition ) {
|
||||
curPosition = curElem.position();
|
||||
curTop = curPosition.top;
|
||||
curLeft = curPosition.left;
|
||||
} else {
|
||||
curTop = parseFloat( curCSSTop ) || 0;
|
||||
curLeft = parseFloat( curCSSLeft ) || 0;
|
||||
}
|
||||
|
||||
curTop = calculatePosition ? curPosition.top : parseInt( curCSSTop, 10 ) || 0;
|
||||
curLeft = calculatePosition ? curPosition.left : parseInt( curCSSLeft, 10 ) || 0;
|
||||
|
||||
if ( jQuery.isFunction( options ) ) {
|
||||
options = options.call( elem, i, curOffset );
|
||||
}
|
||||
|
@ -259,29 +261,16 @@ jQuery.fn.extend({
|
|||
jQuery.each( ["Left", "Top"], function( i, name ) {
|
||||
var method = "scroll" + name;
|
||||
|
||||
jQuery.fn[ method ] = function(val) {
|
||||
var elem = this[0], win;
|
||||
jQuery.fn[ method ] = function( val ) {
|
||||
var elem, win;
|
||||
|
||||
if ( !elem ) {
|
||||
return null;
|
||||
}
|
||||
if ( val === undefined ) {
|
||||
elem = this[ 0 ];
|
||||
|
||||
if ( val !== undefined ) {
|
||||
// Set the scroll offset
|
||||
return this.each(function() {
|
||||
win = getWindow( this );
|
||||
if ( !elem ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( win ) {
|
||||
win.scrollTo(
|
||||
!i ? val : jQuery(win).scrollLeft(),
|
||||
i ? val : jQuery(win).scrollTop()
|
||||
);
|
||||
|
||||
} else {
|
||||
this[ method ] = val;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
win = getWindow( elem );
|
||||
|
||||
// Return the scroll offset
|
||||
|
@ -290,6 +279,21 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
|
|||
win.document.body[ method ] :
|
||||
elem[ method ];
|
||||
}
|
||||
|
||||
// Set the scroll offset
|
||||
return this.each(function() {
|
||||
win = getWindow( this );
|
||||
|
||||
if ( win ) {
|
||||
win.scrollTo(
|
||||
!i ? val : jQuery( win ).scrollLeft(),
|
||||
i ? val : jQuery( win ).scrollTop()
|
||||
);
|
||||
|
||||
} else {
|
||||
this[ method ] = val;
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
// Expose jQuery to the global object
|
||||
window.jQuery = window.$ = jQuery;
|
||||
})(window);
|
||||
|
|
113
src/queue.js
113
src/queue.js
|
@ -1,34 +1,75 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
function handleQueueMarkDefer( elem, type, src ) {
|
||||
var deferDataKey = type + "defer",
|
||||
queueDataKey = type + "queue",
|
||||
markDataKey = type + "mark",
|
||||
defer = jQuery.data( elem, deferDataKey, undefined, true );
|
||||
if ( defer &&
|
||||
( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
|
||||
( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
|
||||
// Give room for hard-coded callbacks to fire first
|
||||
// and eventually mark/queue something else on the element
|
||||
setTimeout( function() {
|
||||
if ( !jQuery.data( elem, queueDataKey, undefined, true ) &&
|
||||
!jQuery.data( elem, markDataKey, undefined, true ) ) {
|
||||
jQuery.removeData( elem, deferDataKey, true );
|
||||
defer.resolve();
|
||||
}
|
||||
}, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
jQuery.extend({
|
||||
queue: function( elem, type, data ) {
|
||||
if ( !elem ) {
|
||||
return;
|
||||
|
||||
_mark: function( elem, type ) {
|
||||
if ( elem ) {
|
||||
type = (type || "fx") + "mark";
|
||||
jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
|
||||
}
|
||||
},
|
||||
|
||||
type = (type || "fx") + "queue";
|
||||
var q = jQuery._data( elem, type );
|
||||
_unmark: function( force, elem, type ) {
|
||||
if ( force !== true ) {
|
||||
type = elem;
|
||||
elem = force;
|
||||
force = false;
|
||||
}
|
||||
if ( elem ) {
|
||||
type = type || "fx";
|
||||
var key = type + "mark",
|
||||
count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
|
||||
if ( count ) {
|
||||
jQuery.data( elem, key, count, true );
|
||||
} else {
|
||||
jQuery.removeData( elem, key, true );
|
||||
handleQueueMarkDefer( elem, type, "mark" );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Speed up dequeue by getting out quickly if this is just a lookup
|
||||
if ( !data ) {
|
||||
queue: function( elem, type, data ) {
|
||||
if ( elem ) {
|
||||
type = (type || "fx") + "queue";
|
||||
var q = jQuery.data( elem, type, undefined, true );
|
||||
// Speed up dequeue by getting out quickly if this is just a lookup
|
||||
if ( data ) {
|
||||
if ( !q || jQuery.isArray(data) ) {
|
||||
q = jQuery.data( elem, type, jQuery.makeArray(data), true );
|
||||
} else {
|
||||
q.push( data );
|
||||
}
|
||||
}
|
||||
return q || [];
|
||||
}
|
||||
|
||||
if ( !q || jQuery.isArray(data) ) {
|
||||
q = jQuery._data( elem, type, jQuery.makeArray(data) );
|
||||
|
||||
} else {
|
||||
q.push( data );
|
||||
}
|
||||
|
||||
return q;
|
||||
},
|
||||
|
||||
dequeue: function( elem, type ) {
|
||||
type = type || "fx";
|
||||
|
||||
var queue = jQuery.queue( elem, type ),
|
||||
fn = queue.shift();
|
||||
fn = queue.shift(),
|
||||
defer;
|
||||
|
||||
// If the fx queue is dequeued, always remove the progress sentinel
|
||||
if ( fn === "inprogress" ) {
|
||||
|
@ -49,6 +90,7 @@ jQuery.extend({
|
|||
|
||||
if ( !queue.length ) {
|
||||
jQuery.removeData( elem, type + "queue", true );
|
||||
handleQueueMarkDefer( elem, type, "queue" );
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -63,7 +105,7 @@ jQuery.fn.extend({
|
|||
if ( data === undefined ) {
|
||||
return jQuery.queue( this[0], type );
|
||||
}
|
||||
return this.each(function( i ) {
|
||||
return this.each(function() {
|
||||
var queue = jQuery.queue( this, type, data );
|
||||
|
||||
if ( type === "fx" && queue[0] !== "inprogress" ) {
|
||||
|
@ -76,7 +118,6 @@ jQuery.fn.extend({
|
|||
jQuery.dequeue( this, type );
|
||||
});
|
||||
},
|
||||
|
||||
// Based off of the plugin by Clint Helfers, with permission.
|
||||
// http://blindsignals.com/index.php/2009/07/jquery-delay/
|
||||
delay: function( time, type ) {
|
||||
|
@ -90,9 +131,41 @@ jQuery.fn.extend({
|
|||
}, time );
|
||||
});
|
||||
},
|
||||
|
||||
clearQueue: function( type ) {
|
||||
return this.queue( type || "fx", [] );
|
||||
},
|
||||
// Get a promise resolved when queues of a certain type
|
||||
// are emptied (fx is the type by default)
|
||||
promise: function( type, object ) {
|
||||
if ( typeof type !== "string" ) {
|
||||
object = type;
|
||||
type = undefined;
|
||||
}
|
||||
type = type || "fx";
|
||||
var defer = jQuery.Deferred(),
|
||||
elements = this,
|
||||
i = elements.length,
|
||||
count = 1,
|
||||
deferDataKey = type + "defer",
|
||||
queueDataKey = type + "queue",
|
||||
markDataKey = type + "mark",
|
||||
tmp;
|
||||
function resolve() {
|
||||
if ( !( --count ) ) {
|
||||
defer.resolveWith( elements, [ elements ] );
|
||||
}
|
||||
}
|
||||
while( i-- ) {
|
||||
if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
|
||||
( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
|
||||
jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
|
||||
jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
|
||||
count++;
|
||||
tmp.done( resolve );
|
||||
}
|
||||
}
|
||||
resolve();
|
||||
return defer.promise();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit f12b9309269ba7e705a99efe099f86ed1fe98d58
|
||||
Subproject commit 3ba396e439a07c2a2facafbe07cdaa1b80a24c00
|
311
src/support.js
311
src/support.js
|
@ -1,44 +1,63 @@
|
|||
(function( jQuery ) {
|
||||
|
||||
(function() {
|
||||
jQuery.support = (function() {
|
||||
|
||||
jQuery.support = {};
|
||||
var div = document.createElement( "div" ),
|
||||
documentElement = document.documentElement,
|
||||
all,
|
||||
a,
|
||||
select,
|
||||
opt,
|
||||
input,
|
||||
marginDiv,
|
||||
support,
|
||||
fragment,
|
||||
body,
|
||||
testElementParent,
|
||||
testElement,
|
||||
testElementStyle,
|
||||
tds,
|
||||
events,
|
||||
eventName,
|
||||
i,
|
||||
isSupported;
|
||||
|
||||
var div = document.createElement("div");
|
||||
// Preliminary tests
|
||||
div.setAttribute("className", "t");
|
||||
div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
|
||||
|
||||
div.style.display = "none";
|
||||
div.innerHTML = " <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
|
||||
|
||||
var all = div.getElementsByTagName("*"),
|
||||
a = div.getElementsByTagName("a")[0],
|
||||
select = document.createElement("select"),
|
||||
opt = select.appendChild( document.createElement("option") ),
|
||||
input = div.getElementsByTagName("input")[0];
|
||||
all = div.getElementsByTagName( "*" );
|
||||
a = div.getElementsByTagName( "a" )[ 0 ];
|
||||
|
||||
// Can't get basic test support
|
||||
if ( !all || !all.length || !a ) {
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
jQuery.support = {
|
||||
// First batch of supports tests
|
||||
select = document.createElement( "select" );
|
||||
opt = select.appendChild( document.createElement("option") );
|
||||
input = div.getElementsByTagName( "input" )[ 0 ];
|
||||
|
||||
support = {
|
||||
// IE strips leading whitespace when .innerHTML is used
|
||||
leadingWhitespace: div.firstChild.nodeType === 3,
|
||||
leadingWhitespace: ( div.firstChild.nodeType === 3 ),
|
||||
|
||||
// Make sure that tbody elements aren't automatically inserted
|
||||
// IE will insert them into empty tables
|
||||
tbody: !div.getElementsByTagName("tbody").length,
|
||||
tbody: !div.getElementsByTagName( "tbody" ).length,
|
||||
|
||||
// Make sure that link elements get serialized correctly by innerHTML
|
||||
// This requires a wrapper element in IE
|
||||
htmlSerialize: !!div.getElementsByTagName("link").length,
|
||||
htmlSerialize: !!div.getElementsByTagName( "link" ).length,
|
||||
|
||||
// Get the style information from getAttribute
|
||||
// (IE uses .cssText insted)
|
||||
style: /red/.test( a.getAttribute("style") ),
|
||||
// (IE uses .cssText instead)
|
||||
style: /top/.test( a.getAttribute("style") ),
|
||||
|
||||
// Make sure that URLs aren't manipulated
|
||||
// (IE normalizes it by default)
|
||||
hrefNormalized: a.getAttribute("href") === "/a",
|
||||
hrefNormalized: ( a.getAttribute( "href" ) === "/a" ),
|
||||
|
||||
// Make sure that element opacity exists
|
||||
// (IE uses filter instead)
|
||||
|
@ -52,182 +71,186 @@
|
|||
// Make sure that if no value is specified for a checkbox
|
||||
// that it defaults to "on".
|
||||
// (WebKit defaults to "" instead)
|
||||
checkOn: input.value === "on",
|
||||
checkOn: ( input.value === "on" ),
|
||||
|
||||
// Make sure that a selected-by-default option has a working selected property.
|
||||
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
|
||||
optSelected: opt.selected,
|
||||
|
||||
// Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
|
||||
getSetAttribute: div.className !== "t",
|
||||
|
||||
// Will be defined later
|
||||
submitBubbles: true,
|
||||
changeBubbles: true,
|
||||
focusinBubbles: false,
|
||||
deleteExpando: true,
|
||||
optDisabled: false,
|
||||
checkClone: false,
|
||||
noCloneEvent: true,
|
||||
noCloneChecked: true,
|
||||
boxModel: null,
|
||||
inlineBlockNeedsLayout: false,
|
||||
shrinkWrapBlocks: false,
|
||||
reliableHiddenOffsets: true,
|
||||
reliableMarginRight: true
|
||||
};
|
||||
|
||||
// Make sure checked status is properly cloned
|
||||
input.checked = true;
|
||||
jQuery.support.noCloneChecked = input.cloneNode( true ).checked;
|
||||
support.noCloneChecked = input.cloneNode( true ).checked;
|
||||
|
||||
// Make sure that the options inside disabled selects aren't marked as disabled
|
||||
// (WebKit marks them as diabled)
|
||||
// (WebKit marks them as disabled)
|
||||
select.disabled = true;
|
||||
jQuery.support.optDisabled = !opt.disabled;
|
||||
|
||||
var _scriptEval = null;
|
||||
jQuery.support.scriptEval = function() {
|
||||
if ( _scriptEval === null ) {
|
||||
var root = document.documentElement,
|
||||
script = document.createElement("script"),
|
||||
id = "script" + jQuery.now();
|
||||
|
||||
// Make sure that the execution of code works by injecting a script
|
||||
// tag with appendChild/createTextNode
|
||||
// (IE doesn't support this, fails, and uses .text instead)
|
||||
try {
|
||||
script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
|
||||
} catch(e) {}
|
||||
|
||||
root.insertBefore( script, root.firstChild );
|
||||
|
||||
if ( window[ id ] ) {
|
||||
_scriptEval = true;
|
||||
delete window[ id ];
|
||||
} else {
|
||||
_scriptEval = false;
|
||||
}
|
||||
|
||||
root.removeChild( script );
|
||||
}
|
||||
|
||||
return _scriptEval;
|
||||
};
|
||||
support.optDisabled = !opt.disabled;
|
||||
|
||||
// Test to see if it's possible to delete an expando from an element
|
||||
// Fails in Internet Explorer
|
||||
try {
|
||||
delete div.test;
|
||||
|
||||
} catch(e) {
|
||||
jQuery.support.deleteExpando = false;
|
||||
} catch( e ) {
|
||||
support.deleteExpando = false;
|
||||
}
|
||||
|
||||
if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
|
||||
div.attachEvent("onclick", function click() {
|
||||
div.attachEvent( "onclick", function() {
|
||||
// Cloning a node shouldn't copy over any
|
||||
// bound event handlers (IE does this)
|
||||
jQuery.support.noCloneEvent = false;
|
||||
div.detachEvent("onclick", click);
|
||||
support.noCloneEvent = false;
|
||||
});
|
||||
div.cloneNode(true).fireEvent("onclick");
|
||||
div.cloneNode( true ).fireEvent( "onclick" );
|
||||
}
|
||||
|
||||
div = document.createElement("div");
|
||||
div.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>";
|
||||
// Check if a radio maintains it's value
|
||||
// after being appended to the DOM
|
||||
input = document.createElement("input");
|
||||
input.value = "t";
|
||||
input.setAttribute("type", "radio");
|
||||
support.radioValue = input.value === "t";
|
||||
|
||||
var fragment = document.createDocumentFragment();
|
||||
input.setAttribute("checked", "checked");
|
||||
div.appendChild( input );
|
||||
fragment = document.createDocumentFragment();
|
||||
fragment.appendChild( div.firstChild );
|
||||
|
||||
// WebKit doesn't clone checked state correctly in fragments
|
||||
jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked;
|
||||
support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
|
||||
|
||||
div.innerHTML = "";
|
||||
|
||||
// Figure out if the W3C box model works as expected
|
||||
// document.body must exist before we can do this
|
||||
jQuery(function() {
|
||||
var div = document.createElement("div"),
|
||||
body = document.getElementsByTagName("body")[0];
|
||||
div.style.width = div.style.paddingLeft = "1px";
|
||||
|
||||
// Frameset documents with no body should not run this code
|
||||
if ( !body ) {
|
||||
return;
|
||||
}
|
||||
body = document.getElementsByTagName( "body" )[ 0 ];
|
||||
// We use our own, invisible, body unless the body is already present
|
||||
// in which case we use a div (#9239)
|
||||
testElement = document.createElement( body ? "div" : "body" );
|
||||
testElementStyle = {
|
||||
visibility: "hidden",
|
||||
width: 0,
|
||||
height: 0,
|
||||
border: 0,
|
||||
margin: 0
|
||||
};
|
||||
if ( body ) {
|
||||
jQuery.extend( testElementStyle, {
|
||||
position: "absolute",
|
||||
left: -1000,
|
||||
top: -1000
|
||||
});
|
||||
}
|
||||
for ( i in testElementStyle ) {
|
||||
testElement.style[ i ] = testElementStyle[ i ];
|
||||
}
|
||||
testElement.appendChild( div );
|
||||
testElementParent = body || documentElement;
|
||||
testElementParent.insertBefore( testElement, testElementParent.firstChild );
|
||||
|
||||
div.style.width = div.style.paddingLeft = "1px";
|
||||
body.appendChild( div );
|
||||
jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
|
||||
// Check if a disconnected checkbox will retain its checked
|
||||
// value of true after appended to the DOM (IE6/7)
|
||||
support.appendChecked = input.checked;
|
||||
|
||||
if ( "zoom" in div.style ) {
|
||||
// Check if natively block-level elements act like inline-block
|
||||
// elements when setting their display to 'inline' and giving
|
||||
// them layout
|
||||
// (IE < 8 does this)
|
||||
div.style.display = "inline";
|
||||
div.style.zoom = 1;
|
||||
jQuery.support.inlineBlockNeedsLayout = div.offsetWidth === 2;
|
||||
support.boxModel = div.offsetWidth === 2;
|
||||
|
||||
// Check if elements with layout shrink-wrap their children
|
||||
// (IE 6 does this)
|
||||
div.style.display = "";
|
||||
div.innerHTML = "<div style='width:4px;'></div>";
|
||||
jQuery.support.shrinkWrapBlocks = div.offsetWidth !== 2;
|
||||
}
|
||||
if ( "zoom" in div.style ) {
|
||||
// Check if natively block-level elements act like inline-block
|
||||
// elements when setting their display to 'inline' and giving
|
||||
// them layout
|
||||
// (IE < 8 does this)
|
||||
div.style.display = "inline";
|
||||
div.style.zoom = 1;
|
||||
support.inlineBlockNeedsLayout = ( div.offsetWidth === 2 );
|
||||
|
||||
div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
|
||||
var tds = div.getElementsByTagName("td");
|
||||
// Check if elements with layout shrink-wrap their children
|
||||
// (IE 6 does this)
|
||||
div.style.display = "";
|
||||
div.innerHTML = "<div style='width:4px;'></div>";
|
||||
support.shrinkWrapBlocks = ( div.offsetWidth !== 2 );
|
||||
}
|
||||
|
||||
// Check if table cells still have offsetWidth/Height when they are set
|
||||
// to display:none and there are still other visible table cells in a
|
||||
// table row; if so, offsetWidth/Height are not reliable for use when
|
||||
// determining if an element has been hidden directly using
|
||||
// display:none (it is still safe to use offsets if a parent element is
|
||||
// hidden; don safety goggles and see bug #4512 for more information).
|
||||
// (only IE 8 fails this test)
|
||||
jQuery.support.reliableHiddenOffsets = tds[0].offsetHeight === 0;
|
||||
div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
|
||||
tds = div.getElementsByTagName( "td" );
|
||||
|
||||
tds[0].style.display = "";
|
||||
tds[1].style.display = "none";
|
||||
// Check if table cells still have offsetWidth/Height when they are set
|
||||
// to display:none and there are still other visible table cells in a
|
||||
// table row; if so, offsetWidth/Height are not reliable for use when
|
||||
// determining if an element has been hidden directly using
|
||||
// display:none (it is still safe to use offsets if a parent element is
|
||||
// hidden; don safety goggles and see bug #4512 for more information).
|
||||
// (only IE 8 fails this test)
|
||||
isSupported = ( tds[ 0 ].offsetHeight === 0 );
|
||||
|
||||
// Check if empty table cells still have offsetWidth/Height
|
||||
// (IE < 8 fail this test)
|
||||
jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0;
|
||||
div.innerHTML = "";
|
||||
tds[ 0 ].style.display = "";
|
||||
tds[ 1 ].style.display = "none";
|
||||
|
||||
// Check if div with explicit width and no margin-right incorrectly
|
||||
// gets computed margin-right based on width of container. For more
|
||||
// info see bug #3333
|
||||
// Fails in WebKit before Feb 2011 nightlies
|
||||
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
||||
if ( document.defaultView && document.defaultView.getComputedStyle ) {
|
||||
div.style.width = "1px";
|
||||
div.style.marginRight = "0";
|
||||
jQuery.support.reliableMarginRight = ( parseInt(document.defaultView.getComputedStyle(div, null).marginRight, 10) || 0 ) === 0;
|
||||
}
|
||||
// Check if empty table cells still have offsetWidth/Height
|
||||
// (IE < 8 fail this test)
|
||||
support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
|
||||
div.innerHTML = "";
|
||||
|
||||
body.removeChild( div ).style.display = "none";
|
||||
div = tds = null;
|
||||
});
|
||||
// Check if div with explicit width and no margin-right incorrectly
|
||||
// gets computed margin-right based on width of container. For more
|
||||
// info see bug #3333
|
||||
// Fails in WebKit before Feb 2011 nightlies
|
||||
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
||||
if ( document.defaultView && document.defaultView.getComputedStyle ) {
|
||||
marginDiv = document.createElement( "div" );
|
||||
marginDiv.style.width = "0";
|
||||
marginDiv.style.marginRight = "0";
|
||||
div.appendChild( marginDiv );
|
||||
support.reliableMarginRight =
|
||||
( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
|
||||
}
|
||||
|
||||
// Remove the body element we added
|
||||
testElement.innerHTML = "";
|
||||
testElementParent.removeChild( testElement );
|
||||
|
||||
// Technique from Juriy Zaytsev
|
||||
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
||||
var eventSupported = function( eventName ) {
|
||||
var el = document.createElement("div");
|
||||
eventName = "on" + eventName;
|
||||
|
||||
// We only care about the case where non-standard event systems
|
||||
// are used, namely in IE. Short-circuiting here helps us to
|
||||
// avoid an eval call (in setAttribute) which can cause CSP
|
||||
// to go haywire. See: https://developer.mozilla.org/en/Security/CSP
|
||||
if ( !el.attachEvent ) {
|
||||
return true;
|
||||
// We only care about the case where non-standard event systems
|
||||
// are used, namely in IE. Short-circuiting here helps us to
|
||||
// avoid an eval call (in setAttribute) which can cause CSP
|
||||
// to go haywire. See: https://developer.mozilla.org/en/Security/CSP
|
||||
if ( div.attachEvent ) {
|
||||
for( i in {
|
||||
submit: 1,
|
||||
change: 1,
|
||||
focusin: 1
|
||||
} ) {
|
||||
eventName = "on" + i;
|
||||
isSupported = ( eventName in div );
|
||||
if ( !isSupported ) {
|
||||
div.setAttribute( eventName, "return;" );
|
||||
isSupported = ( typeof div[ eventName ] === "function" );
|
||||
}
|
||||
support[ i + "Bubbles" ] = isSupported;
|
||||
}
|
||||
}
|
||||
|
||||
var isSupported = (eventName in el);
|
||||
if ( !isSupported ) {
|
||||
el.setAttribute(eventName, "return;");
|
||||
isSupported = typeof el[eventName] === "function";
|
||||
}
|
||||
return isSupported;
|
||||
};
|
||||
// Null connected elements to avoid leaks in IE
|
||||
testElement = fragment = select = opt = body = marginDiv = div = input = null;
|
||||
|
||||
jQuery.support.submitBubbles = eventSupported("submit");
|
||||
jQuery.support.changeBubbles = eventSupported("change");
|
||||
|
||||
// release memory in IE
|
||||
div = all = a = null;
|
||||
return support;
|
||||
})();
|
||||
|
||||
// Keep track of boxModel
|
||||
jQuery.boxModel = jQuery.support.boxModel;
|
||||
|
||||
})( jQuery );
|
||||
|
|
|
@ -17,17 +17,30 @@ var runtil = /Until$/,
|
|||
|
||||
jQuery.fn.extend({
|
||||
find: function( selector ) {
|
||||
var ret = this.pushStack( "", "find", selector ),
|
||||
length = 0;
|
||||
var self = this,
|
||||
i, l;
|
||||
|
||||
for ( var i = 0, l = this.length; i < l; i++ ) {
|
||||
if ( typeof selector !== "string" ) {
|
||||
return jQuery( selector ).filter(function() {
|
||||
for ( i = 0, l = self.length; i < l; i++ ) {
|
||||
if ( jQuery.contains( self[ i ], this ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var ret = this.pushStack( "", "find", selector ),
|
||||
length, n, r;
|
||||
|
||||
for ( i = 0, l = this.length; i < l; i++ ) {
|
||||
length = ret.length;
|
||||
jQuery.find( selector, this[i], ret );
|
||||
|
||||
if ( i > 0 ) {
|
||||
// Make sure that the results are unique
|
||||
for ( var n = length; n < ret.length; n++ ) {
|
||||
for ( var r = 0; r < length; r++ ) {
|
||||
for ( n = length; n < ret.length; n++ ) {
|
||||
for ( r = 0; r < length; r++ ) {
|
||||
if ( ret[r] === ret[n] ) {
|
||||
ret.splice(n--, 1);
|
||||
break;
|
||||
|
@ -60,12 +73,15 @@ jQuery.fn.extend({
|
|||
},
|
||||
|
||||
is: function( selector ) {
|
||||
return !!selector && jQuery.filter( selector, this ).length > 0;
|
||||
return !!selector && ( typeof selector === "string" ?
|
||||
jQuery.filter( selector, this ).length > 0 :
|
||||
this.filter( selector ).length > 0 );
|
||||
},
|
||||
|
||||
closest: function( selectors, context ) {
|
||||
var ret = [], i, l, cur = this[0];
|
||||
|
||||
|
||||
// Array
|
||||
if ( jQuery.isArray( selectors ) ) {
|
||||
var match, selector,
|
||||
matches = {},
|
||||
|
@ -75,8 +91,8 @@ jQuery.fn.extend({
|
|||
for ( i = 0, l = selectors.length; i < l; i++ ) {
|
||||
selector = selectors[i];
|
||||
|
||||
if ( !matches[selector] ) {
|
||||
matches[selector] = jQuery.expr.match.POS.test( selector ) ?
|
||||
if ( !matches[ selector ] ) {
|
||||
matches[ selector ] = POS.test( selector ) ?
|
||||
jQuery( selector, context || this.context ) :
|
||||
selector;
|
||||
}
|
||||
|
@ -84,9 +100,9 @@ jQuery.fn.extend({
|
|||
|
||||
while ( cur && cur.ownerDocument && cur !== context ) {
|
||||
for ( selector in matches ) {
|
||||
match = matches[selector];
|
||||
match = matches[ selector ];
|
||||
|
||||
if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
|
||||
if ( match.jquery ? match.index( cur ) > -1 : jQuery( cur ).is( match ) ) {
|
||||
ret.push({ selector: selector, elem: cur, level: level });
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +115,10 @@ jQuery.fn.extend({
|
|||
return ret;
|
||||
}
|
||||
|
||||
var pos = POS.test( selectors ) ?
|
||||
jQuery( selectors, context || this.context ) : null;
|
||||
// String
|
||||
var pos = POS.test( selectors ) || typeof selectors !== "string" ?
|
||||
jQuery( selectors, context || this.context ) :
|
||||
0;
|
||||
|
||||
for ( i = 0, l = this.length; i < l; i++ ) {
|
||||
cur = this[i];
|
||||
|
@ -112,14 +130,14 @@ jQuery.fn.extend({
|
|||
|
||||
} else {
|
||||
cur = cur.parentNode;
|
||||
if ( !cur || !cur.ownerDocument || cur === context ) {
|
||||
if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ret = ret.length > 1 ? jQuery.unique(ret) : ret;
|
||||
ret = ret.length > 1 ? jQuery.unique( ret ) : ret;
|
||||
|
||||
return this.pushStack( ret, "closest", selectors );
|
||||
},
|
||||
|
@ -142,7 +160,7 @@ jQuery.fn.extend({
|
|||
add: function( selector, context ) {
|
||||
var set = typeof selector === "string" ?
|
||||
jQuery( selector, context ) :
|
||||
jQuery.makeArray( selector ),
|
||||
jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
|
||||
all = jQuery.merge( this.get(), set );
|
||||
|
||||
return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
|
||||
|
@ -280,6 +298,11 @@ jQuery.extend({
|
|||
|
||||
// Implement the identical functionality for filter and not
|
||||
function winnow( elements, qualifier, keep ) {
|
||||
|
||||
// Can't pass null or undefined to indexOf in Firefox 4
|
||||
// Set to 0 to skip string check
|
||||
qualifier = qualifier || 0;
|
||||
|
||||
if ( jQuery.isFunction( qualifier ) ) {
|
||||
return jQuery.grep(elements, function( elem, i ) {
|
||||
var retVal = !!qualifier.call( elem, i, elem );
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<dashboard>
|
||||
<locations class="foo">
|
||||
<location for="bar">
|
||||
<location for="bar" checked="different">
|
||||
<infowindowtab>
|
||||
<tab title="Location"><![CDATA[blabla]]></tab>
|
||||
<tab title="Users"><![CDATA[blublu]]></tab>
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
// Simple script loader that uses jQuery.readyWait
|
||||
// Simple script loader that uses jQuery.readyWait via jQuery.holdReady()
|
||||
|
||||
//Hold on jQuery!
|
||||
jQuery.readyWait++;
|
||||
jQuery.holdReady(true);
|
||||
|
||||
var readyRegExp = /^(complete|loaded)$/;
|
||||
|
||||
function assetLoaded( evt ){
|
||||
var node = evt.currentTarget || evt.srcElement;
|
||||
if ( evt.type === "load" || readyRegExp.test(node.readyState) ) {
|
||||
jQuery.ready(true);
|
||||
jQuery.holdReady(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
37
test/data/support/bodyBackground.html
Normal file
37
test/data/support/bodyBackground.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<style>
|
||||
body {
|
||||
background: #000000;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<script src="../../../src/core.js"></script>
|
||||
<script src="../../../src/deferred.js"></script>
|
||||
<script src="../../../src/support.js"></script>
|
||||
<script src="../../../src/data.js"></script>
|
||||
<script src="../../../src/queue.js"></script>
|
||||
<script src="../../../src/attributes.js"></script>
|
||||
<script src="../../../src/event.js"></script>
|
||||
<script src="../../../src/sizzle/sizzle.js"></script>
|
||||
<script src="../../../src/sizzle-jquery.js"></script>
|
||||
<script src="../../../src/traversing.js"></script>
|
||||
<script src="../../../src/manipulation.js"></script>
|
||||
<script src="../../../src/css.js"></script>
|
||||
<script src="../../../src/ajax.js"></script>
|
||||
<script src="../../../src/ajax/jsonp.js"></script>
|
||||
<script src="../../../src/ajax/script.js"></script>
|
||||
<script src="../../../src/ajax/xhr.js"></script>
|
||||
<script src="../../../src/effects.js"></script>
|
||||
<script src="../../../src/offset.js"></script>
|
||||
<script src="../../../src/dimensions.js"></script>
|
||||
</div>
|
||||
<script>
|
||||
window.top.supportCallback( jQuery( "body" ).css( "backgroundColor" ), jQuery.support );
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
27
test/data/support/boxModelIE.html
Normal file
27
test/data/support/boxModelIE.html
Normal file
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<body>
|
||||
<script src="../../../src/core.js"></script>
|
||||
<script src="../../../src/deferred.js"></script>
|
||||
<script src="../../../src/support.js"></script>
|
||||
<script src="../../../src/data.js"></script>
|
||||
<script src="../../../src/queue.js"></script>
|
||||
<script src="../../../src/attributes.js"></script>
|
||||
<script src="../../../src/event.js"></script>
|
||||
<script src="../../../src/sizzle/sizzle.js"></script>
|
||||
<script src="../../../src/sizzle-jquery.js"></script>
|
||||
<script src="../../../src/traversing.js"></script>
|
||||
<script src="../../../src/manipulation.js"></script>
|
||||
<script src="../../../src/css.js"></script>
|
||||
<script src="../../../src/ajax.js"></script>
|
||||
<script src="../../../src/ajax/jsonp.js"></script>
|
||||
<script src="../../../src/ajax/script.js"></script>
|
||||
<script src="../../../src/ajax/xhr.js"></script>
|
||||
<script src="../../../src/effects.js"></script>
|
||||
<script src="../../../src/offset.js"></script>
|
||||
<script src="../../../src/dimensions.js"></script>
|
||||
<script>
|
||||
window.top.supportCallback( document.compatMode, jQuery.support.boxModel );
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
25
test/data/support/hiddenIFrameFF.html
Normal file
25
test/data/support/hiddenIFrameFF.html
Normal file
|
@ -0,0 +1,25 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="../../../src/core.js"></script>
|
||||
<script src="../../../src/deferred.js"></script>
|
||||
<script src="../../../src/support.js"></script>
|
||||
<script src="../../../src/data.js"></script>
|
||||
<script src="../../../src/queue.js"></script>
|
||||
<script src="../../../src/attributes.js"></script>
|
||||
<script src="../../../src/event.js"></script>
|
||||
<script src="../../../src/sizzle/sizzle.js"></script>
|
||||
<script src="../../../src/sizzle-jquery.js"></script>
|
||||
<script src="../../../src/traversing.js"></script>
|
||||
<script src="../../../src/manipulation.js"></script>
|
||||
<script src="../../../src/css.js"></script>
|
||||
<script src="../../../src/ajax.js"></script>
|
||||
<script src="../../../src/ajax/jsonp.js"></script>
|
||||
<script src="../../../src/ajax/script.js"></script>
|
||||
<script src="../../../src/ajax/xhr.js"></script>
|
||||
<script src="../../../src/effects.js"></script>
|
||||
<script src="../../../src/offset.js"></script>
|
||||
<script src="../../../src/dimensions.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
|
@ -2,8 +2,9 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's.
|
|||
|
||||
// jQuery-specific QUnit.reset
|
||||
(function() {
|
||||
var reset = QUnit.reset;
|
||||
var ajaxSettings = jQuery.ajaxSettings
|
||||
var reset = QUnit.reset,
|
||||
ajaxSettings = jQuery.ajaxSettings;
|
||||
|
||||
QUnit.reset = function() {
|
||||
reset.apply(this, arguments);
|
||||
jQuery.event.global = {};
|
||||
|
@ -24,3 +25,9 @@ jQuery.noConflict(); // Allow the test to run with other libs or jQuery's.
|
|||
|
||||
document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>");
|
||||
})();
|
||||
|
||||
// QUnit Aliases
|
||||
(function() {
|
||||
window.equals = window.equal;
|
||||
window.same = window.deepEqual;
|
||||
})();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* for testing opacity set in styles in IE */
|
||||
ol#empty { opacity: 0; filter:Alpha(opacity=0); }
|
||||
ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); }
|
||||
|
||||
div#fx-tests h4 {
|
||||
background: red;
|
||||
|
@ -109,3 +109,15 @@ div#show-tests * { display: none; }
|
|||
#nothiddendiv { font-size: 16px; }
|
||||
#nothiddendivchild.em { font-size: 2em; }
|
||||
#nothiddendivchild.prct { font-size: 150%; }
|
||||
|
||||
/* For testing type on vml in IE #7071 */
|
||||
v\:oval { behavior:url(#default#VML); display:inline-block; }
|
||||
|
||||
/* 8099 changes to default styles are read correctly */
|
||||
tt { display: none; }
|
||||
sup { display: none; }
|
||||
dfn { display: none; }
|
||||
|
||||
/* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */
|
||||
body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; }
|
||||
|
||||
|
|
8
test/data/versioncheck.js
Normal file
8
test/data/versioncheck.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Run minified source from dist (do make first)
|
||||
// Should be loaded before QUnit but after src
|
||||
(function() {
|
||||
if ( /jquery\=min/.test( window.location.search ) ) {
|
||||
jQuery.noConflict( true );
|
||||
document.write(unescape("%3Cscript%20src%3D%27../dist/jquery.min.js%27%3E%3C/script%3E"));
|
||||
}
|
||||
})();
|
|
@ -183,10 +183,20 @@
|
|||
<td id='boundSubmit' class="red">DOCUMENT</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h1>Mouseleave Tests</h1>
|
||||
|
||||
<div class="out" style="margin:20px; border:1px solid #000; background: red;">
|
||||
<p>Count mouse leave event</p>
|
||||
<div class="in" style="background: green; margin: 10px auto; width: 50%;">
|
||||
<p>mouse over here should not trigger the counter.</p>
|
||||
</div>
|
||||
<p>0</p>
|
||||
</div>
|
||||
|
||||
<ul id="log"></ul>
|
||||
|
||||
<script type='text/javascript'>
|
||||
<script type='text/javascript'>
|
||||
jQuery.fn.addChangeClickTest = function( id, prevent ) {
|
||||
this.bind("focusin", function(){
|
||||
jQuery(id + "focus").blink();
|
||||
|
@ -270,6 +280,10 @@
|
|||
jQuery("#boundSubmit").blink();
|
||||
});
|
||||
|
||||
</script>
|
||||
var n = 0;
|
||||
$("div.out").live("mouseleave", function() {
|
||||
$("p:last", this).text(++n);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -28,10 +28,13 @@
|
|||
<script src="../src/offset.js"></script>
|
||||
<script src="../src/dimensions.js"></script>
|
||||
|
||||
<script src="data/versioncheck.js"></script>
|
||||
|
||||
<script src="qunit/qunit/qunit.js"></script>
|
||||
<script src="data/testrunner.js"></script>
|
||||
|
||||
<script src="unit/core.js"></script>
|
||||
<script src="unit/support.js"></script>
|
||||
<script src="unit/deferred.js"></script>
|
||||
<script src="unit/data.js"></script>
|
||||
<script src="unit/queue.js"></script>
|
||||
|
@ -48,7 +51,9 @@
|
|||
</head>
|
||||
|
||||
<body id="body">
|
||||
<h1 id="qunit-header">jQuery Test Suite</h1>
|
||||
<h1 id="qunit-header"><a href="/jquery/test/index.html">jQuery Test Suite</a>
|
||||
<a href="?jquery=min">(minified)</a>
|
||||
</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
|
@ -58,10 +63,10 @@
|
|||
<div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv">
|
||||
<div id="nothiddendivchild"></div>
|
||||
</div>
|
||||
<!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
|
||||
<!-- this iframe is outside the #qunit-fixture so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
|
||||
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
|
||||
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;">
|
||||
<div id="main">
|
||||
<dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px">
|
||||
<div id="qunit-fixture">
|
||||
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
|
||||
<p id="ap">
|
||||
Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
|
||||
|
@ -203,6 +208,10 @@ Z</textarea>
|
|||
<select name="D4" disabled="disabled">
|
||||
<option selected="selected" value="NO">NO</option>
|
||||
</select>
|
||||
<input id="list-test" type="text" />
|
||||
<datalist id="datalist">
|
||||
<option value="option"></option>
|
||||
</datalist>
|
||||
</form>
|
||||
<div id="moretests">
|
||||
<form>
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d404faf8f587fcbe6b8907943022e6318dd51e0c
|
||||
Subproject commit d4f23f8a882d13b71768503e2db9fa33ef169ba0
|
|
@ -1,13 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Test for jQuery.readyWait. Needs to be a
|
||||
Test for jQuery.holdReady. Needs to be a
|
||||
standalone test since it deals with DOM
|
||||
ready.
|
||||
-->
|
||||
<head>
|
||||
<title>
|
||||
jQuery.readyWait Test
|
||||
jQuery.holdReady Test
|
||||
</title>
|
||||
<style>
|
||||
div { margin-top: 10px; }
|
||||
|
@ -52,15 +52,17 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
jQuery.readyWait Test
|
||||
jQuery.holdReady Test
|
||||
</h1>
|
||||
<p>
|
||||
This is a test page for jQuery.readyWait, that was
|
||||
added due to this ticket
|
||||
<a href="http://bugs.jquery.com/ticket/6781">#6781</a>.
|
||||
This is a test page for jQuery.readyWait and jQuery.holdReady,
|
||||
see
|
||||
<a href="http://bugs.jquery.com/ticket/6781">#6781</a>
|
||||
and
|
||||
<a href="http://bugs.jquery.com/ticket/8803">#8803</a>.
|
||||
</p>
|
||||
<p>
|
||||
Test for jQuery.readyWait, which can be used
|
||||
Test for jQuery.holdReady, which can be used
|
||||
by plugins and other scripts to indicate something
|
||||
important to the page is still loading and needs
|
||||
to block the DOM ready callbacks that are registered
|
||||
|
@ -68,7 +70,7 @@
|
|||
</p>
|
||||
<p>
|
||||
Script loaders are the most likely kind of script
|
||||
to use jQuery.readyWait, but it could be used by
|
||||
to use jQuery.holdReady, but it could be used by
|
||||
other things like a script that loads a CSS file
|
||||
and wants to pause the DOM ready callbacks.
|
||||
</p>
|
||||
|
|
|
@ -14,7 +14,7 @@ test("jQuery.ajax() - success callbacks", function() {
|
|||
|
||||
stop();
|
||||
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -46,7 +46,7 @@ test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
|
|||
stop();
|
||||
|
||||
setTimeout(function(){
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -78,7 +78,7 @@ test("jQuery.ajax() - success callbacks (late binding)", function() {
|
|||
stop();
|
||||
|
||||
setTimeout(function(){
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -111,7 +111,7 @@ test("jQuery.ajax() - success callbacks (oncomplete binding)", function() {
|
|||
stop();
|
||||
|
||||
setTimeout(function(){
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -147,7 +147,7 @@ test("jQuery.ajax() - success callbacks (very late binding)", function() {
|
|||
stop();
|
||||
|
||||
setTimeout(function(){
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -214,7 +214,7 @@ test("jQuery.ajax() - error callbacks", function() {
|
|||
expect( 8 );
|
||||
stop();
|
||||
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -247,10 +247,10 @@ test( "jQuery.ajax - multiple method signatures introduced in 1.5 ( #8107)", fun
|
|||
stop();
|
||||
|
||||
jQuery.when(
|
||||
jQuery.ajax().success(function() { ok( true, 'With no arguments' ); }),
|
||||
jQuery.ajax('data/name.html').success(function() { ok( true, 'With only string URL argument' ); }),
|
||||
jQuery.ajax('data/name.html', {} ).success(function() { ok( true, 'With string URL param and map' ); }),
|
||||
jQuery.ajax({ url: 'data/name.html'} ).success(function() { ok( true, 'With only map' ); })
|
||||
jQuery.ajax().success(function() { ok( true, "With no arguments" ); }),
|
||||
jQuery.ajax("data/name.html").success(function() { ok( true, "With only string URL argument" ); }),
|
||||
jQuery.ajax("data/name.html", {} ).success(function() { ok( true, "With string URL param and map" ); }),
|
||||
jQuery.ajax({ url: "data/name.html"} ).success(function() { ok( true, "With only map" ); })
|
||||
).then( start, start );
|
||||
|
||||
});
|
||||
|
@ -321,25 +321,40 @@ test("jQuery.ajax() - responseText on error", function() {
|
|||
|
||||
test(".ajax() - retry with jQuery.ajax( this )", function() {
|
||||
|
||||
expect( 1 );
|
||||
expect( 2 );
|
||||
|
||||
stop();
|
||||
|
||||
var firstTime = 1;
|
||||
var firstTime = true,
|
||||
previousUrl;
|
||||
|
||||
jQuery.ajax({
|
||||
url: url("data/errorWithText.php"),
|
||||
error: function() {
|
||||
if ( firstTime ) {
|
||||
firstTime = 0;
|
||||
firstTime = false;
|
||||
jQuery.ajax( this );
|
||||
} else {
|
||||
ok( true , "Test retrying with jQuery.ajax(this) works" );
|
||||
start();
|
||||
jQuery.ajax({
|
||||
url: url("data/errorWithText.php"),
|
||||
data: { x: 1 },
|
||||
beforeSend: function() {
|
||||
if ( !previousUrl ) {
|
||||
previousUrl = this.url;
|
||||
} else {
|
||||
strictEqual( this.url , previousUrl, "url parameters are not re-appended" );
|
||||
start();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
jQuery.ajax( this );
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test(".ajax() - headers" , function() {
|
||||
|
@ -348,7 +363,7 @@ test(".ajax() - headers" , function() {
|
|||
|
||||
stop();
|
||||
|
||||
jQuery('#foo').ajaxSend(function( evt, xhr ) {
|
||||
jQuery("#foo").ajaxSend(function( evt, xhr ) {
|
||||
xhr.setRequestHeader( "ajax-send", "test" );
|
||||
});
|
||||
|
||||
|
@ -509,7 +524,7 @@ test("jQuery ajax - cross-domain detection", function() {
|
|||
|
||||
jQuery.ajax({
|
||||
dataType: "jsonp",
|
||||
url: 'app:/path',
|
||||
url: "app:/path",
|
||||
beforeSend: function( _ , s ) {
|
||||
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
|
||||
return false;
|
||||
|
@ -518,7 +533,7 @@ test("jQuery ajax - cross-domain detection", function() {
|
|||
|
||||
jQuery.ajax({
|
||||
dataType: "jsonp",
|
||||
url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
|
||||
url: loc.protocol + "//somewebsitethatdoesnotexist-656329477541.com:" + ( loc.port || 80 ),
|
||||
beforeSend: function( _ , s ) {
|
||||
ok( s.crossDomain , "Test different hostnames are detected as cross-domain" );
|
||||
return false;
|
||||
|
@ -559,7 +574,7 @@ test(".load() - 404 error callbacks", function() {
|
|||
expect( 6 );
|
||||
stop();
|
||||
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -583,7 +598,7 @@ test("jQuery.ajax() - abort", function() {
|
|||
expect( 8 );
|
||||
stop();
|
||||
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( true, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( true, "ajaxStop" );
|
||||
|
@ -628,7 +643,7 @@ test("Ajax events with context", function() {
|
|||
};
|
||||
}
|
||||
|
||||
jQuery('#foo').add(context)
|
||||
jQuery("#foo").add(context)
|
||||
.ajaxSend(event)
|
||||
.ajaxComplete(event)
|
||||
.ajaxError(event)
|
||||
|
@ -650,7 +665,7 @@ test("Ajax events with context", function() {
|
|||
complete: function(){
|
||||
callback("complete").call(this);
|
||||
|
||||
jQuery('#foo').add(context).unbind();
|
||||
jQuery("#foo").add(context).unbind();
|
||||
|
||||
jQuery.ajax({
|
||||
url: url("data/404.html"),
|
||||
|
@ -734,7 +749,7 @@ test("jQuery.ajax() - disabled globals", function() {
|
|||
expect( 3 );
|
||||
stop();
|
||||
|
||||
jQuery('#foo').ajaxStart(function(){
|
||||
jQuery("#foo").ajaxStart(function(){
|
||||
ok( false, "ajaxStart" );
|
||||
}).ajaxStop(function(){
|
||||
ok( false, "ajaxStop" );
|
||||
|
@ -768,9 +783,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun
|
|||
url: url("data/with_fries.xml"),
|
||||
dataType: "xml",
|
||||
success: function(resp) {
|
||||
equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
|
||||
equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
|
||||
equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
|
||||
equals( jQuery("properties", resp).length, 1, "properties in responseXML" );
|
||||
equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" );
|
||||
equals( jQuery("thing", resp).length, 2, "things in responseXML" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -783,9 +798,9 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements (over
|
|||
url: url("data/with_fries_over_jsonp.php"),
|
||||
dataType: "jsonp xml",
|
||||
success: function(resp) {
|
||||
equals( jQuery("properties", resp).length, 1, 'properties in responseXML' );
|
||||
equals( jQuery("jsconf", resp).length, 1, 'jsconf in responseXML' );
|
||||
equals( jQuery("thing", resp).length, 2, 'things in responseXML' );
|
||||
equals( jQuery("properties", resp).length, 1, "properties in responseXML" );
|
||||
equals( jQuery("jsconf", resp).length, 1, "jsconf in responseXML" );
|
||||
equals( jQuery("thing", resp).length, 2, "things in responseXML" );
|
||||
start();
|
||||
},
|
||||
error: function(_1,_2,error) {
|
||||
|
@ -804,7 +819,7 @@ test("jQuery.ajax - HEAD requests", function() {
|
|||
type: "HEAD",
|
||||
success: function(data, status, xhr){
|
||||
var h = xhr.getAllResponseHeaders();
|
||||
ok( /Date/i.test(h), 'No Date in HEAD response' );
|
||||
ok( /Date/i.test(h), "No Date in HEAD response" );
|
||||
|
||||
jQuery.ajax({
|
||||
url: url("data/name.html"),
|
||||
|
@ -812,7 +827,7 @@ test("jQuery.ajax - HEAD requests", function() {
|
|||
type: "HEAD",
|
||||
success: function(data, status, xhr){
|
||||
var h = xhr.getAllResponseHeaders();
|
||||
ok( /Date/i.test(h), 'No Date in HEAD response with data' );
|
||||
ok( /Date/i.test(h), "No Date in HEAD response with data" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -891,8 +906,8 @@ test("jQuery.ajax - dataType html", function() {
|
|||
stop();
|
||||
|
||||
var verifyEvaluation = function() {
|
||||
equals( testFoo, "foo", 'Check if script was evaluated for datatype html' );
|
||||
equals( foobar, "bar", 'Check if script src was evaluated for datatype html' );
|
||||
equals( testFoo, "foo", "Check if script was evaluated for datatype html" );
|
||||
equals( foobar, "bar", "Check if script src was evaluated for datatype html" );
|
||||
|
||||
start();
|
||||
};
|
||||
|
@ -902,7 +917,7 @@ test("jQuery.ajax - dataType html", function() {
|
|||
url: url("data/test.html"),
|
||||
success: function(data) {
|
||||
jQuery("#ap").html(data);
|
||||
ok( data.match(/^html text/), 'Check content for datatype html' );
|
||||
ok( data.match(/^html text/), "Check content for datatype html" );
|
||||
setTimeout(verifyEvaluation, 600);
|
||||
}
|
||||
});
|
||||
|
@ -913,40 +928,40 @@ test("serialize()", function() {
|
|||
|
||||
// Add html5 elements only for serialize because selector can't yet find them on non-html5 browsers
|
||||
jQuery("#search").after(
|
||||
'<input type="email" id="html5email" name="email" value="dave@jquery.com" />'+
|
||||
'<input type="number" id="html5number" name="number" value="43" />'
|
||||
"<input type='email' id='html5email' name='email' value='dave@jquery.com' />"+
|
||||
"<input type='number' id='html5number' name='number' value='43' />"
|
||||
);
|
||||
|
||||
equals( jQuery('#form').serialize(),
|
||||
equals( jQuery("#form").serialize(),
|
||||
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
|
||||
'Check form serialization as query string');
|
||||
"Check form serialization as query string");
|
||||
|
||||
equals( jQuery('#form :input').serialize(),
|
||||
equals( jQuery("#form :input").serialize(),
|
||||
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3",
|
||||
'Check input serialization as query string');
|
||||
"Check input serialization as query string");
|
||||
|
||||
equals( jQuery('#testForm').serialize(),
|
||||
'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
|
||||
'Check form serialization as query string');
|
||||
equals( jQuery("#testForm").serialize(),
|
||||
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
|
||||
"Check form serialization as query string");
|
||||
|
||||
equals( jQuery('#testForm :input').serialize(),
|
||||
'T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=',
|
||||
'Check input serialization as query string');
|
||||
equals( jQuery("#testForm :input").serialize(),
|
||||
"T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
|
||||
"Check input serialization as query string");
|
||||
|
||||
equals( jQuery('#form, #testForm').serialize(),
|
||||
equals( jQuery("#form, #testForm").serialize(),
|
||||
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&select5=3&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
|
||||
'Multiple form serialization as query string');
|
||||
"Multiple form serialization as query string");
|
||||
|
||||
/* Temporarily disabled. Opera 10 has problems with form serialization.
|
||||
equals( jQuery('#form, #testForm :input').serialize(),
|
||||
equals( jQuery("#form, #testForm :input").serialize(),
|
||||
"action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&search=search&email=dave%40jquery.com&number=43&select1=&select2=3&select3=1&select3=2&T3=%3F%0D%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=",
|
||||
'Mixed form/input serialization as query string');
|
||||
"Mixed form/input serialization as query string");
|
||||
*/
|
||||
jQuery("#html5email, #html5number").remove();
|
||||
});
|
||||
|
||||
test("jQuery.param()", function() {
|
||||
expect(24);
|
||||
expect(21);
|
||||
|
||||
equals( !jQuery.ajaxSettings.traditional, true, "traditional flag, falsy by default" );
|
||||
|
||||
|
@ -956,13 +971,13 @@ test("jQuery.param()", function() {
|
|||
params = {someName: [1, 2, 3], regularThing: "blah" };
|
||||
equals( jQuery.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3®ularThing=blah", "with array" );
|
||||
|
||||
params = {foo: ['a', 'b', 'c']};
|
||||
params = {foo: ["a", "b", "c"]};
|
||||
equals( jQuery.param(params), "foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c", "with array of strings" );
|
||||
|
||||
params = {foo: ["baz", 42, "All your base are belong to us"] };
|
||||
equals( jQuery.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" );
|
||||
|
||||
params = {foo: { bar: 'baz', beep: 42, quux: 'All your base are belong to us' } };
|
||||
params = {foo: { bar: "baz", beep: 42, quux: "All your base are belong to us" } };
|
||||
equals( jQuery.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" );
|
||||
|
||||
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
|
||||
|
@ -974,12 +989,7 @@ test("jQuery.param()", function() {
|
|||
params = { a:[1,2], b:{ c:3, d:[4,5], e:{ x:[6], y:7, z:[8,9] }, f:true, g:false, h:undefined }, i:[10,11], j:true, k:false, l:[undefined,0], m:"cowboy hat?" };
|
||||
equals( jQuery.param(params,true), "a=1&a=2&b=%5Bobject+Object%5D&i=10&i=11&j=true&k=false&l=undefined&l=0&m=cowboy+hat%3F", "huge structure, forced traditional" );
|
||||
|
||||
equals( decodeURIComponent( jQuery.param({ a: [1,2,3], 'b[]': [4,5,6], 'c[d]': [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
|
||||
|
||||
// Make sure empty arrays and objects are handled #6481
|
||||
equals( jQuery.param({"foo": {"bar": []} }), "foo%5Bbar%5D=", "Empty array param" );
|
||||
equals( jQuery.param({"foo": {"bar": [], foo: 1} }), "foo%5Bbar%5D=&foo%5Bfoo%5D=1", "Empty array param" );
|
||||
equals( jQuery.param({"foo": {"bar": {}} }), "foo%5Bbar%5D=", "Empty object param" );
|
||||
equals( decodeURIComponent( jQuery.param({ a: [1,2,3], "b[]": [4,5,6], "c[d]": [7,8,9], e: { f: [10], g: [11,12], h: 13 } }) ), "a[]=1&a[]=2&a[]=3&b[]=4&b[]=5&b[]=6&c[d][]=7&c[d][]=8&c[d][]=9&e[f][]=10&e[g][]=11&e[g][]=12&e[h]=13", "Make sure params are not double-encoded." );
|
||||
|
||||
// #7945
|
||||
equals( jQuery.param({"jquery": "1.4.2"}), "jquery=1.4.2", "Check that object with a jQuery property get serialized correctly" );
|
||||
|
@ -992,7 +1002,7 @@ test("jQuery.param()", function() {
|
|||
params = {someName: [1, 2, 3], regularThing: "blah" };
|
||||
equals( jQuery.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" );
|
||||
|
||||
params = {foo: ['a', 'b', 'c']};
|
||||
params = {foo: ["a", "b", "c"]};
|
||||
equals( jQuery.param(params), "foo=a&foo=b&foo=c", "with array of strings" );
|
||||
|
||||
params = {"foo[]":["baz", 42, "All your base are belong to us"]};
|
||||
|
@ -1013,7 +1023,7 @@ test("jQuery.param()", function() {
|
|||
params = { param1: null };
|
||||
equals( jQuery.param(params,false), "param1=null", "Make sure that null params aren't traversed." );
|
||||
|
||||
params = {'test': {'length': 3, 'foo': 'bar'} };
|
||||
params = {"test": {"length": 3, "foo": "bar"} };
|
||||
equals( jQuery.param( params, false ), "test%5Blength%5D=3&test%5Bfoo%5D=bar", "Sub-object with a length property" );
|
||||
});
|
||||
|
||||
|
@ -1044,10 +1054,10 @@ test("pass-through request object", function() {
|
|||
errorCount++;
|
||||
errorEx += ": " + xml.status;
|
||||
});
|
||||
jQuery("#foo").one('ajaxStop', function () {
|
||||
jQuery("#foo").one("ajaxStop", function () {
|
||||
equals(successCount, 5, "Check all ajax calls successful");
|
||||
equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")");
|
||||
jQuery("#foo").unbind('ajaxError');
|
||||
jQuery("#foo").unbind("ajaxError");
|
||||
|
||||
start();
|
||||
});
|
||||
|
@ -1101,17 +1111,17 @@ test("global ajaxSettings", function() {
|
|||
var orig = { url: "data/with_fries.xml" };
|
||||
var t;
|
||||
|
||||
jQuery.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} });
|
||||
jQuery.ajaxSetup({ data: {foo: "bar", bar: "BAR"} });
|
||||
|
||||
t = jQuery.extend({}, orig);
|
||||
t.data = {};
|
||||
jQuery.ajax(t);
|
||||
ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" );
|
||||
ok( t.url.indexOf("foo") > -1 && t.url.indexOf("bar") > -1, "Check extending {}" );
|
||||
|
||||
t = jQuery.extend({}, orig);
|
||||
t.data = { zoo: 'a', ping: 'b' };
|
||||
t.data = { zoo: "a", ping: "b" };
|
||||
jQuery.ajax(t);
|
||||
ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" );
|
||||
ok( t.url.indexOf("ping") > -1 && t.url.indexOf("zoo") > -1 && t.url.indexOf("foo") > -1 && t.url.indexOf("bar") > -1, "Check extending { zoo: "a", ping: "b" }" );
|
||||
|
||||
jQuery.ajaxSettings = tmp;
|
||||
});
|
||||
|
@ -1120,13 +1130,13 @@ test("global ajaxSettings", function() {
|
|||
test("load(String)", function() {
|
||||
expect(1);
|
||||
stop(); // check if load can be called with only url
|
||||
jQuery('#first').load("data/name.html", start);
|
||||
jQuery("#first").load("data/name.html", start);
|
||||
});
|
||||
|
||||
test("load('url selector')", function() {
|
||||
expect(1);
|
||||
stop(); // check if load can be called with only url
|
||||
jQuery('#first').load("data/test3.html div.user", function(){
|
||||
jQuery("#first").load("data/test3.html div.user", function(){
|
||||
equals( jQuery(this).children("div").length, 2, "Verify that specific elements were injected" );
|
||||
start();
|
||||
});
|
||||
|
@ -1142,14 +1152,14 @@ test("load(String, Function) with ajaxSetup on dataType json, see #2046", functi
|
|||
jQuery.ajaxSetup({ dataType: "" });
|
||||
start();
|
||||
});
|
||||
jQuery('#first').load("data/test3.html");
|
||||
jQuery("#first").load("data/test3.html");
|
||||
});
|
||||
|
||||
test("load(String, Function) - simple: inject text into DOM", function() {
|
||||
expect(2);
|
||||
stop();
|
||||
jQuery('#first').load(url("data/name.html"), function() {
|
||||
ok( /^ERROR/.test(jQuery('#first').text()), 'Check if content was injected into the DOM' );
|
||||
jQuery("#first").load(url("data/name.html"), function() {
|
||||
ok( /^ERROR/.test(jQuery("#first").text()), "Check if content was injected into the DOM" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -1159,15 +1169,15 @@ test("load(String, Function) - check scripts", function() {
|
|||
stop();
|
||||
|
||||
var verifyEvaluation = function() {
|
||||
equals( foobar, "bar", 'Check if script src was evaluated after load' );
|
||||
equals( jQuery('#ap').html(), 'bar', 'Check if script evaluation has modified DOM');
|
||||
equals( foobar, "bar", "Check if script src was evaluated after load" );
|
||||
equals( jQuery("#ap").html(), "bar", "Check if script evaluation has modified DOM");
|
||||
|
||||
start();
|
||||
};
|
||||
jQuery('#first').load(url('data/test.html'), function() {
|
||||
ok( jQuery('#first').html().match(/^html text/), 'Check content after loading html' );
|
||||
equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
|
||||
equals( testFoo, "foo", 'Check if script was evaluated after load' );
|
||||
jQuery("#first").load(url("data/test.html"), function() {
|
||||
ok( jQuery("#first").html().match(/^html text/), "Check content after loading html" );
|
||||
equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
|
||||
equals( testFoo, "foo", "Check if script was evaluated after load" );
|
||||
setTimeout(verifyEvaluation, 600);
|
||||
});
|
||||
});
|
||||
|
@ -1176,9 +1186,9 @@ test("load(String, Function) - check file with only a script tag", function() {
|
|||
expect(3);
|
||||
stop();
|
||||
|
||||
jQuery('#first').load(url('data/test2.html'), function() {
|
||||
equals( jQuery('#foo').html(), 'foo', 'Check if script evaluation has modified DOM');
|
||||
equals( testFoo, "foo", 'Check if script was evaluated after load' );
|
||||
jQuery("#first").load(url("data/test2.html"), function() {
|
||||
equals( jQuery("#foo").html(), "foo", "Check if script evaluation has modified DOM");
|
||||
equals( testFoo, "foo", "Check if script was evaluated after load" );
|
||||
|
||||
start();
|
||||
});
|
||||
|
@ -1200,10 +1210,10 @@ test("load(String, Object, Function)", function() {
|
|||
expect(2);
|
||||
stop();
|
||||
|
||||
jQuery('<div />').load(url('data/params_html.php'), { foo:3, bar:'ok' }, function() {
|
||||
var $post = jQuery(this).find('#post');
|
||||
equals( $post.find('#foo').text(), '3', 'Check if a hash of data is passed correctly');
|
||||
equals( $post.find('#bar').text(), 'ok', 'Check if a hash of data is passed correctly');
|
||||
jQuery("<div />").load(url("data/params_html.php"), { foo: 3, bar: "ok" }, function() {
|
||||
var $post = jQuery(this).find("#post");
|
||||
equals( $post.find("#foo").text(), "3", "Check if a hash of data is passed correctly");
|
||||
equals( $post.find("#bar").text(), "ok", "Check if a hash of data is passed correctly");
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -1212,10 +1222,10 @@ test("load(String, String, Function)", function() {
|
|||
expect(2);
|
||||
stop();
|
||||
|
||||
jQuery('<div />').load(url('data/params_html.php'), 'foo=3&bar=ok', function() {
|
||||
var $get = jQuery(this).find('#get');
|
||||
equals( $get.find('#foo').text(), '3', 'Check if a string of data is passed correctly');
|
||||
equals( $get.find('#bar').text(), 'ok', 'Check if a of data is passed correctly');
|
||||
jQuery("<div />").load(url("data/params_html.php"), "foo=3&bar=ok", function() {
|
||||
var $get = jQuery(this).find("#get");
|
||||
equals( $get.find("#foo").text(), "3", "Check if a string of data is passed correctly");
|
||||
equals( $get.find("#bar").text(), "ok", "Check if a of data is passed correctly");
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -1226,8 +1236,8 @@ test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
|
|||
jQuery.ajaxSetup({
|
||||
data: "helloworld"
|
||||
});
|
||||
jQuery.get(url('data/echoQuery.php'), function(data) {
|
||||
ok( /helloworld$/.test( data ), 'Data from ajaxSettings was used');
|
||||
jQuery.get(url("data/echoQuery.php"), function(data) {
|
||||
ok( /helloworld$/.test( data ), "Data from ajaxSettings was used");
|
||||
jQuery.ajaxSetup({
|
||||
data: null
|
||||
});
|
||||
|
@ -1238,13 +1248,13 @@ test("jQuery.get(String, Function) - data in ajaxSettings (#8277)", function() {
|
|||
test("jQuery.get(String, Hash, Function) - parse xml and use text() on nodes", function() {
|
||||
expect(2);
|
||||
stop();
|
||||
jQuery.get(url('data/dashboard.xml'), function(xml) {
|
||||
jQuery.get(url("data/dashboard.xml"), function(xml) {
|
||||
var content = [];
|
||||
jQuery('tab', xml).each(function() {
|
||||
jQuery("tab", xml).each(function() {
|
||||
content.push(jQuery(this).text());
|
||||
});
|
||||
equals( content[0], 'blabla', 'Check first tab');
|
||||
equals( content[1], 'blublu', 'Check second tab');
|
||||
equals( content[0], "blabla", "Check first tab");
|
||||
equals( content[1], "blublu", "Check second tab");
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -1253,7 +1263,7 @@ test("jQuery.getScript(String, Function) - with callback", function() {
|
|||
expect(3);
|
||||
stop();
|
||||
jQuery.getScript(url("data/test.js"), function( data, _, jqXHR ) {
|
||||
equals( foobar, "bar", 'Check if script was evaluated' );
|
||||
equals( foobar, "bar", "Check if script was evaluated" );
|
||||
strictEqual( data, jqXHR.responseText, "Same-domain script requests returns the source of the script (#8082)" );
|
||||
setTimeout(start, 100);
|
||||
});
|
||||
|
@ -1600,7 +1610,7 @@ test("jQuery.ajax() - malformed JSON", function() {
|
|||
},
|
||||
error: function(xhr, msg, detailedMsg) {
|
||||
equals( "parsererror", msg, "A parse error occurred." );
|
||||
ok( /^Invalid JSON/.test(detailedMsg), "Detailed parsererror message provided" );
|
||||
ok( /^(Invalid|SyntaxError|exception)/i.test(detailedMsg), "Detailed parsererror message provided" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -1636,10 +1646,10 @@ test("jQuery.ajax() - json by content-type", function() {
|
|||
data: { header: "json", json: "array" },
|
||||
success: function( json ) {
|
||||
ok( json.length >= 2, "Check length");
|
||||
equals( json[0].name, 'John', 'Check JSON: first, name' );
|
||||
equals( json[0].age, 21, 'Check JSON: first, age' );
|
||||
equals( json[1].name, 'Peter', 'Check JSON: second, name' );
|
||||
equals( json[1].age, 25, 'Check JSON: second, age' );
|
||||
equals( json[0].name, "John", "Check JSON: first, name" );
|
||||
equals( json[0].age, 21, "Check JSON: first, age" );
|
||||
equals( json[1].name, "Peter", "Check JSON: second, name" );
|
||||
equals( json[1].age, 25, "Check JSON: second, age" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -1660,10 +1670,10 @@ test("jQuery.ajax() - json by content-type disabled with options", function() {
|
|||
equals( typeof text , "string" , "json wasn't auto-determined" );
|
||||
var json = jQuery.parseJSON( text );
|
||||
ok( json.length >= 2, "Check length");
|
||||
equals( json[0].name, 'John', 'Check JSON: first, name' );
|
||||
equals( json[0].age, 21, 'Check JSON: first, age' );
|
||||
equals( json[1].name, 'Peter', 'Check JSON: second, name' );
|
||||
equals( json[1].age, 25, 'Check JSON: second, age' );
|
||||
equals( json[0].name, "John", "Check JSON: first, name" );
|
||||
equals( json[0].age, 21, "Check JSON: first, age" );
|
||||
equals( json[1].name, "Peter", "Check JSON: second, name" );
|
||||
equals( json[1].age, 25, "Check JSON: second, age" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -1674,10 +1684,10 @@ test("jQuery.getJSON(String, Hash, Function) - JSON array", function() {
|
|||
stop();
|
||||
jQuery.getJSON(url("data/json.php"), {json: "array"}, function(json) {
|
||||
ok( json.length >= 2, "Check length");
|
||||
equals( json[0].name, 'John', 'Check JSON: first, name' );
|
||||
equals( json[0].age, 21, 'Check JSON: first, age' );
|
||||
equals( json[1].name, 'Peter', 'Check JSON: second, name' );
|
||||
equals( json[1].age, 25, 'Check JSON: second, age' );
|
||||
equals( json[0].name, "John", "Check JSON: first, name" );
|
||||
equals( json[0].age, 21, "Check JSON: first, age" );
|
||||
equals( json[1].name, "Peter", "Check JSON: second, name" );
|
||||
equals( json[1].age, 25, "Check JSON: second, age" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -1687,8 +1697,8 @@ test("jQuery.getJSON(String, Function) - JSON object", function() {
|
|||
stop();
|
||||
jQuery.getJSON(url("data/json.php"), function(json) {
|
||||
if (json && json.data) {
|
||||
equals( json.data.lang, 'en', 'Check JSON: lang' );
|
||||
equals( json.data.length, 25, 'Check JSON: length' );
|
||||
equals( json.data.lang, "en", "Check JSON: lang" );
|
||||
equals( json.data.length, 25, "Check JSON: length" );
|
||||
}
|
||||
start();
|
||||
});
|
||||
|
@ -1720,8 +1730,8 @@ test("jQuery.getJSON(String, Function) - JSON object with absolute url to local
|
|||
|
||||
stop();
|
||||
jQuery.getJSON(url(base + "data/json.php"), function(json) {
|
||||
equals( json.data.lang, 'en', 'Check JSON: lang' );
|
||||
equals( json.data.length, 25, 'Check JSON: length' );
|
||||
equals( json.data.lang, "en", "Check JSON: lang" );
|
||||
equals( json.data.length, 25, "Check JSON: length" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -1731,23 +1741,23 @@ test("jQuery.post - data", 3, function() {
|
|||
|
||||
jQuery.when(
|
||||
jQuery.post( url( "data/name.php" ), { xml: "5-2", length: 3 }, function( xml ) {
|
||||
jQuery( 'math', xml ).each( function() {
|
||||
equals( jQuery( 'calculation', this ).text(), '5-2', 'Check for XML' );
|
||||
equals( jQuery( 'result', this ).text(), '3', 'Check for XML' );
|
||||
jQuery( "math", xml ).each( function() {
|
||||
equals( jQuery( "calculation", this ).text(), "5-2", "Check for XML" );
|
||||
equals( jQuery( "result", this ).text(), "3", "Check for XML" );
|
||||
});
|
||||
}),
|
||||
|
||||
jQuery.ajax({
|
||||
url: url('data/echoData.php'),
|
||||
url: url("data/echoData.php"),
|
||||
type: "POST",
|
||||
data: {
|
||||
'test': {
|
||||
'length': 7,
|
||||
'foo': 'bar'
|
||||
"test": {
|
||||
"length": 7,
|
||||
"foo": "bar"
|
||||
}
|
||||
},
|
||||
success: function( data ) {
|
||||
strictEqual( data, 'test%5Blength%5D=7&test%5Bfoo%5D=bar', 'Check if a sub-object with a length param is serialized correctly');
|
||||
strictEqual( data, "test%5Blength%5D=7&test%5Bfoo%5D=bar", "Check if a sub-object with a length param is serialized correctly");
|
||||
}
|
||||
})
|
||||
).then( start, start );
|
||||
|
@ -1760,17 +1770,17 @@ test("jQuery.post(String, Hash, Function) - simple with xml", function() {
|
|||
var done = 0;
|
||||
|
||||
jQuery.post(url("data/name.php"), {xml: "5-2"}, function(xml){
|
||||
jQuery('math', xml).each(function() {
|
||||
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
|
||||
equals( jQuery('result', this).text(), '3', 'Check for XML' );
|
||||
jQuery("math", xml).each(function() {
|
||||
equals( jQuery("calculation", this).text(), "5-2", "Check for XML" );
|
||||
equals( jQuery("result", this).text(), "3", "Check for XML" );
|
||||
});
|
||||
if ( ++done === 2 ) start();
|
||||
});
|
||||
|
||||
jQuery.post(url("data/name.php?xml=5-2"), {}, function(xml){
|
||||
jQuery('math', xml).each(function() {
|
||||
equals( jQuery('calculation', this).text(), '5-2', 'Check for XML' );
|
||||
equals( jQuery('result', this).text(), '3', 'Check for XML' );
|
||||
jQuery("math", xml).each(function() {
|
||||
equals( jQuery("calculation", this).text(), "5-2", "Check for XML" );
|
||||
equals( jQuery("result", this).text(), "3", "Check for XML" );
|
||||
});
|
||||
if ( ++done === 2 ) start();
|
||||
});
|
||||
|
@ -1786,18 +1796,18 @@ test("jQuery.ajaxSetup({timeout: Number}) - with global timeout", function() {
|
|||
var pass = function() {
|
||||
passed++;
|
||||
if ( passed == 2 ) {
|
||||
ok( true, 'Check local and global callbacks after timeout' );
|
||||
jQuery('#main').unbind("ajaxError");
|
||||
ok( true, "Check local and global callbacks after timeout" );
|
||||
jQuery("#qunit-fixture").unbind("ajaxError");
|
||||
start();
|
||||
}
|
||||
};
|
||||
|
||||
var fail = function(a,b,c) {
|
||||
ok( false, 'Check for timeout failed ' + a + ' ' + b );
|
||||
ok( false, "Check for timeout failed " + a + " " + b );
|
||||
start();
|
||||
};
|
||||
|
||||
jQuery('#main').ajaxError(pass);
|
||||
jQuery("#qunit-fixture").ajaxError(pass);
|
||||
|
||||
jQuery.ajax({
|
||||
type: "GET",
|
||||
|
@ -1819,11 +1829,11 @@ test("jQuery.ajaxSetup({timeout: Number}) with localtimeout", function() {
|
|||
timeout: 15000,
|
||||
url: url("data/name.php?wait=1"),
|
||||
error: function() {
|
||||
ok( false, 'Check for local timeout failed' );
|
||||
ok( false, "Check for local timeout failed" );
|
||||
start();
|
||||
},
|
||||
success: function() {
|
||||
ok( true, 'Check for local timeout' );
|
||||
ok( true, "Check for local timeout" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -1839,7 +1849,7 @@ test("jQuery.ajax - simple get", function() {
|
|||
type: "GET",
|
||||
url: url("data/name.php?name=foo"),
|
||||
success: function(msg){
|
||||
equals( msg, 'bar', 'Check for GET' );
|
||||
equals( msg, "bar", "Check for GET" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -1853,7 +1863,7 @@ test("jQuery.ajax - simple post", function() {
|
|||
url: url("data/name.php"),
|
||||
data: "name=peter",
|
||||
success: function(msg){
|
||||
equals( msg, 'pan', 'Check for POST' );
|
||||
equals( msg, "pan", "Check for POST" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -1865,7 +1875,7 @@ test("ajaxSetup()", function() {
|
|||
jQuery.ajaxSetup({
|
||||
url: url("data/name.php?name=foo"),
|
||||
success: function(msg){
|
||||
equals( msg, 'bar', 'Check for GET' );
|
||||
equals( msg, "bar", "Check for GET" );
|
||||
start();
|
||||
}
|
||||
});
|
||||
|
@ -2027,14 +2037,14 @@ test("jQuery ajax - failing cross-domain", function() {
|
|||
var i = 2;
|
||||
|
||||
jQuery.ajax({
|
||||
url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
|
||||
url: "http://somewebsitethatdoesnotexist-67864863574657654.com",
|
||||
success: function(){ ok( false , "success" ); },
|
||||
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
|
||||
complete: function() { if ( ! --i ) start(); }
|
||||
});
|
||||
|
||||
jQuery.ajax({
|
||||
url: 'http://www.google.com',
|
||||
url: "http://www.google.com",
|
||||
success: function(){ ok( false , "success" ); },
|
||||
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
|
||||
complete: function() { if ( ! --i ) start(); }
|
||||
|
@ -2047,7 +2057,7 @@ test("jQuery ajax - atom+xml", function() {
|
|||
stop();
|
||||
|
||||
jQuery.ajax({
|
||||
url: url( 'data/atom+xml.php' ),
|
||||
url: url( "data/atom+xml.php" ),
|
||||
success: function(){ ok( true , "success" ); },
|
||||
error: function(){ ok( false , "error" ); },
|
||||
complete: function() { start(); }
|
||||
|
@ -2259,4 +2269,4 @@ test("jQuery.ajax - active counter", function() {
|
|||
|
||||
}
|
||||
|
||||
//}
|
||||
//}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,7 @@ test("Basic requirements", function() {
|
|||
});
|
||||
|
||||
test("jQuery()", function() {
|
||||
expect(24);
|
||||
expect(29);
|
||||
|
||||
// Basic constructor's behavior
|
||||
|
||||
|
@ -20,6 +20,7 @@ test("jQuery()", function() {
|
|||
equals( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
|
||||
equals( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
|
||||
equals( jQuery("").length, 0, "jQuery('') === jQuery([])" );
|
||||
equals( jQuery("#").length, 0, "jQuery('#') === jQuery([])" );
|
||||
|
||||
var obj = jQuery("div");
|
||||
equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
|
||||
|
@ -28,7 +29,7 @@ test("jQuery()", function() {
|
|||
equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" );
|
||||
|
||||
|
||||
var main = jQuery("#main");
|
||||
var main = jQuery("#qunit-fixture");
|
||||
same( jQuery("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
|
||||
|
||||
/*
|
||||
|
@ -61,7 +62,7 @@ test("jQuery()", function() {
|
|||
|
||||
equals( jQuery([1,2,3]).get(1), 2, "Test passing an array to the factory" );
|
||||
|
||||
equals( jQuery(document.body).get(0), jQuery('body').get(0), "Test passing an html node to the factory" );
|
||||
equals( jQuery(document.body).get(0), jQuery("body").get(0), "Test passing an html node to the factory" );
|
||||
|
||||
var exec = false;
|
||||
|
||||
|
@ -74,13 +75,13 @@ test("jQuery()", function() {
|
|||
id: "test3"
|
||||
});
|
||||
|
||||
equals( elem[0].style.width, '10px', 'jQuery() quick setter width');
|
||||
equals( elem[0].style.paddingLeft, '1px', 'jQuery quick setter css');
|
||||
equals( elem[0].style.paddingRight, '1px', 'jQuery quick setter css');
|
||||
equals( elem[0].childNodes.length, 1, 'jQuery quick setter text');
|
||||
equals( elem[0].firstChild.nodeValue, "test", 'jQuery quick setter text');
|
||||
equals( elem[0].className, "test2", 'jQuery() quick setter class');
|
||||
equals( elem[0].id, "test3", 'jQuery() quick setter id');
|
||||
equals( elem[0].style.width, "10px", "jQuery() quick setter width");
|
||||
equals( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
|
||||
equals( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
|
||||
equals( elem[0].childNodes.length, 1, "jQuery quick setter text");
|
||||
equals( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
|
||||
equals( elem[0].className, "test2", "jQuery() quick setter class");
|
||||
equals( elem[0].id, "test3", "jQuery() quick setter id");
|
||||
|
||||
exec = true;
|
||||
elem.click();
|
||||
|
@ -95,6 +96,17 @@ test("jQuery()", function() {
|
|||
|
||||
// manually clean up detached elements
|
||||
elem.remove();
|
||||
|
||||
equals( jQuery(" <div/> ").length, 1, "Make sure whitespace is trimmed." );
|
||||
equals( jQuery(" a<div/>b ").length, 1, "Make sure whitespace and other characters are trimmed." );
|
||||
|
||||
var long = "";
|
||||
for ( var i = 0; i < 128; i++ ) {
|
||||
long += "12345678";
|
||||
}
|
||||
|
||||
equals( jQuery(" <div>" + long + "</div> ").length, 1, "Make sure whitespace is trimmed on long strings." );
|
||||
equals( jQuery(" a<div>" + long + "</div>b ").length, 1, "Make sure whitespace and other characters are trimmed on long strings." );
|
||||
});
|
||||
|
||||
test("selector state", function() {
|
||||
|
@ -114,54 +126,54 @@ test("selector state", function() {
|
|||
equals( test.selector, "", "Body Selector" );
|
||||
equals( test.context, document.body, "Body Context" );
|
||||
|
||||
test = jQuery("#main");
|
||||
equals( test.selector, "#main", "#main Selector" );
|
||||
equals( test.context, document, "#main Context" );
|
||||
test = jQuery("#qunit-fixture");
|
||||
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
||||
equals( test.context, document, "#qunit-fixture Context" );
|
||||
|
||||
test = jQuery("#notfoundnono");
|
||||
equals( test.selector, "#notfoundnono", "#notfoundnono Selector" );
|
||||
equals( test.context, document, "#notfoundnono Context" );
|
||||
|
||||
test = jQuery("#main", document);
|
||||
equals( test.selector, "#main", "#main Selector" );
|
||||
equals( test.context, document, "#main Context" );
|
||||
test = jQuery("#qunit-fixture", document);
|
||||
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
||||
equals( test.context, document, "#qunit-fixture Context" );
|
||||
|
||||
test = jQuery("#main", document.body);
|
||||
equals( test.selector, "#main", "#main Selector" );
|
||||
equals( test.context, document.body, "#main Context" );
|
||||
test = jQuery("#qunit-fixture", document.body);
|
||||
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
||||
equals( test.context, document.body, "#qunit-fixture Context" );
|
||||
|
||||
// Test cloning
|
||||
test = jQuery(test);
|
||||
equals( test.selector, "#main", "#main Selector" );
|
||||
equals( test.context, document.body, "#main Context" );
|
||||
equals( test.selector, "#qunit-fixture", "#qunit-fixture Selector" );
|
||||
equals( test.context, document.body, "#qunit-fixture Context" );
|
||||
|
||||
test = jQuery(document.body).find("#main");
|
||||
equals( test.selector, "#main", "#main find Selector" );
|
||||
equals( test.context, document.body, "#main find Context" );
|
||||
test = jQuery(document.body).find("#qunit-fixture");
|
||||
equals( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" );
|
||||
equals( test.context, document.body, "#qunit-fixture find Context" );
|
||||
|
||||
test = jQuery("#main").filter("div");
|
||||
equals( test.selector, "#main.filter(div)", "#main filter Selector" );
|
||||
equals( test.context, document, "#main filter Context" );
|
||||
test = jQuery("#qunit-fixture").filter("div");
|
||||
equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter Selector" );
|
||||
equals( test.context, document, "#qunit-fixture filter Context" );
|
||||
|
||||
test = jQuery("#main").not("div");
|
||||
equals( test.selector, "#main.not(div)", "#main not Selector" );
|
||||
equals( test.context, document, "#main not Context" );
|
||||
test = jQuery("#qunit-fixture").not("div");
|
||||
equals( test.selector, "#qunit-fixture.not(div)", "#qunit-fixture not Selector" );
|
||||
equals( test.context, document, "#qunit-fixture not Context" );
|
||||
|
||||
test = jQuery("#main").filter("div").not("div");
|
||||
equals( test.selector, "#main.filter(div).not(div)", "#main filter, not Selector" );
|
||||
equals( test.context, document, "#main filter, not Context" );
|
||||
test = jQuery("#qunit-fixture").filter("div").not("div");
|
||||
equals( test.selector, "#qunit-fixture.filter(div).not(div)", "#qunit-fixture filter, not Selector" );
|
||||
equals( test.context, document, "#qunit-fixture filter, not Context" );
|
||||
|
||||
test = jQuery("#main").filter("div").not("div").end();
|
||||
equals( test.selector, "#main.filter(div)", "#main filter, not, end Selector" );
|
||||
equals( test.context, document, "#main filter, not, end Context" );
|
||||
test = jQuery("#qunit-fixture").filter("div").not("div").end();
|
||||
equals( test.selector, "#qunit-fixture.filter(div)", "#qunit-fixture filter, not, end Selector" );
|
||||
equals( test.context, document, "#qunit-fixture filter, not, end Context" );
|
||||
|
||||
test = jQuery("#main").parent("body");
|
||||
equals( test.selector, "#main.parent(body)", "#main parent Selector" );
|
||||
equals( test.context, document, "#main parent Context" );
|
||||
test = jQuery("#qunit-fixture").parent("body");
|
||||
equals( test.selector, "#qunit-fixture.parent(body)", "#qunit-fixture parent Selector" );
|
||||
equals( test.context, document, "#qunit-fixture parent Context" );
|
||||
|
||||
test = jQuery("#main").eq(0);
|
||||
equals( test.selector, "#main.slice(0,1)", "#main eq Selector" );
|
||||
equals( test.context, document, "#main eq Context" );
|
||||
test = jQuery("#qunit-fixture").eq(0);
|
||||
equals( test.selector, "#qunit-fixture.slice(0,1)", "#qunit-fixture eq Selector" );
|
||||
equals( test.context, document, "#qunit-fixture eq Context" );
|
||||
|
||||
var d = "<div />";
|
||||
equals(
|
||||
|
@ -171,6 +183,26 @@ test("selector state", function() {
|
|||
);
|
||||
});
|
||||
|
||||
test( "globalEval", function() {
|
||||
|
||||
expect( 3 );
|
||||
|
||||
jQuery.globalEval( "var globalEvalTest = true;" );
|
||||
ok( window.globalEvalTest, "Test variable declarations are global" );
|
||||
|
||||
window.globalEvalTest = false;
|
||||
|
||||
jQuery.globalEval( "globalEvalTest = true;" );
|
||||
ok( window.globalEvalTest, "Test variable assignments are global" );
|
||||
|
||||
window.globalEvalTest = false;
|
||||
|
||||
jQuery.globalEval( "this.globalEvalTest = true;" );
|
||||
ok( window.globalEvalTest, "Test context (this) is the window object" );
|
||||
|
||||
window.globalEvalTest = undefined;
|
||||
});
|
||||
|
||||
if ( !isLocal ) {
|
||||
test("browser", function() {
|
||||
stop();
|
||||
|
@ -207,7 +239,7 @@ test("noConflict", function() {
|
|||
equals( jQuery.noConflict(true), $$, "noConflict returned the jQuery object" );
|
||||
equals( jQuery, originaljQuery, "Make sure jQuery was reverted." );
|
||||
equals( $, original$, "Make sure $ was reverted." );
|
||||
ok( $$("#main").html("test"), "Make sure that jQuery still works." );
|
||||
ok( $$("#qunit-fixture").html("test"), "Make sure that jQuery still works." );
|
||||
|
||||
jQuery = $$;
|
||||
});
|
||||
|
@ -439,7 +471,7 @@ if ( !isLocal ) {
|
|||
test("isXMLDoc - XML", function() {
|
||||
expect(3);
|
||||
stop();
|
||||
jQuery.get('data/dashboard.xml', function(xml) {
|
||||
jQuery.get("data/dashboard.xml", function(xml) {
|
||||
ok( jQuery.isXMLDoc( xml ), "XML document" );
|
||||
ok( jQuery.isXMLDoc( xml.documentElement ), "XML documentElement" );
|
||||
ok( jQuery.isXMLDoc( jQuery("tab", xml)[0] ), "XML Tab Element" );
|
||||
|
@ -468,7 +500,7 @@ test("isWindow", function() {
|
|||
});
|
||||
|
||||
test("jQuery('html')", function() {
|
||||
expect(15);
|
||||
expect(18);
|
||||
|
||||
QUnit.reset();
|
||||
jQuery.foo = false;
|
||||
|
@ -500,6 +532,19 @@ test("jQuery('html')", function() {
|
|||
|
||||
ok( jQuery("<div></div>")[0], "Create a div with closing tag." );
|
||||
ok( jQuery("<table></table>")[0], "Create a table with closing tag." );
|
||||
|
||||
// Test very large html string #7990
|
||||
var i;
|
||||
var li = "<li>very large html string</li>";
|
||||
var html = ["<ul>"];
|
||||
for ( i = 0; i < 50000; i += 1 ) {
|
||||
html.push(li);
|
||||
}
|
||||
html.push("</ul>");
|
||||
html = jQuery(html.join(""))[0];
|
||||
equals( html.nodeName.toUpperCase(), "UL");
|
||||
equals( html.firstChild.nodeName.toUpperCase(), "LI");
|
||||
equals( html.childNodes.length, 50000 );
|
||||
});
|
||||
|
||||
test("jQuery('html', context)", function() {
|
||||
|
@ -514,7 +559,7 @@ if ( !isLocal ) {
|
|||
test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
|
||||
expect(2);
|
||||
stop();
|
||||
jQuery.get('data/dashboard.xml', function(xml) {
|
||||
jQuery.get("data/dashboard.xml", function(xml) {
|
||||
// tests for #1419 where IE was a problem
|
||||
var tab = jQuery("tab", xml).eq(0);
|
||||
equals( tab.text(), "blabla", "Verify initial text correct" );
|
||||
|
@ -527,39 +572,39 @@ test("jQuery(selector, xml).text(str) - Loaded via XML document", function() {
|
|||
|
||||
test("end()", function() {
|
||||
expect(3);
|
||||
equals( 'Yahoo', jQuery('#yahoo').parent().end().text(), 'Check for end' );
|
||||
ok( jQuery('#yahoo').end(), 'Check for end with nothing to end' );
|
||||
equals( "Yahoo", jQuery("#yahoo").parent().end().text(), "Check for end" );
|
||||
ok( jQuery("#yahoo").end(), "Check for end with nothing to end" );
|
||||
|
||||
var x = jQuery('#yahoo');
|
||||
var x = jQuery("#yahoo");
|
||||
x.parent();
|
||||
equals( 'Yahoo', jQuery('#yahoo').text(), 'Check for non-destructive behaviour' );
|
||||
equals( "Yahoo", jQuery("#yahoo").text(), "Check for non-destructive behaviour" );
|
||||
});
|
||||
|
||||
test("length", function() {
|
||||
expect(1);
|
||||
equals( jQuery("#main p").length, 6, "Get Number of Elements Found" );
|
||||
equals( jQuery("#qunit-fixture p").length, 6, "Get Number of Elements Found" );
|
||||
});
|
||||
|
||||
test("size()", function() {
|
||||
expect(1);
|
||||
equals( jQuery("#main p").size(), 6, "Get Number of Elements Found" );
|
||||
equals( jQuery("#qunit-fixture p").size(), 6, "Get Number of Elements Found" );
|
||||
});
|
||||
|
||||
test("get()", function() {
|
||||
expect(1);
|
||||
same( jQuery("#main p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
|
||||
same( jQuery("#qunit-fixture p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
|
||||
});
|
||||
|
||||
test("toArray()", function() {
|
||||
expect(1);
|
||||
same( jQuery("#main p").toArray(),
|
||||
same( jQuery("#qunit-fixture p").toArray(),
|
||||
q("firstp","ap","sndp","en","sap","first"),
|
||||
"Convert jQuery object to an Array" )
|
||||
})
|
||||
|
||||
test("get(Number)", function() {
|
||||
expect(2);
|
||||
equals( jQuery("#main p").get(0), document.getElementById("firstp"), "Get A Single Element" );
|
||||
equals( jQuery("#qunit-fixture p").get(0), document.getElementById("firstp"), "Get A Single Element" );
|
||||
strictEqual( jQuery("#firstp").get(1), undefined, "Try get with index larger elements count" );
|
||||
});
|
||||
|
||||
|
@ -572,7 +617,7 @@ test("get(-Number)",function() {
|
|||
test("each(Function)", function() {
|
||||
expect(1);
|
||||
var div = jQuery("div");
|
||||
div.each(function(){this.foo = 'zoo';});
|
||||
div.each(function(){this.foo = "zoo";});
|
||||
var pass = true;
|
||||
for ( var i = 0; i < div.size(); i++ ) {
|
||||
if ( div.get(i).foo != "zoo" ) pass = false;
|
||||
|
@ -591,7 +636,7 @@ test("slice()", function() {
|
|||
same( $links.slice(-1).get(), q("mark"), "slice(-1)" );
|
||||
|
||||
same( $links.eq(1).get(), q("groups"), "eq(1)" );
|
||||
same( $links.eq('2').get(), q("anchor1"), "eq('2')" );
|
||||
same( $links.eq("2").get(), q("anchor1"), "eq('2')" );
|
||||
same( $links.eq(-1).get(), q("mark"), "eq(-1)" );
|
||||
});
|
||||
|
||||
|
@ -608,7 +653,7 @@ test("first()/last()", function() {
|
|||
});
|
||||
|
||||
test("map()", function() {
|
||||
expect(2);//expect(6);
|
||||
expect(8);
|
||||
|
||||
same(
|
||||
jQuery("#ap").map(function(){
|
||||
|
@ -626,32 +671,38 @@ test("map()", function() {
|
|||
"Single Map"
|
||||
);
|
||||
|
||||
return;//these haven't been accepted yet
|
||||
|
||||
//for #2616
|
||||
var keys = jQuery.map( {a:1,b:2}, function( v, k ){
|
||||
return k;
|
||||
}, [ ] );
|
||||
|
||||
});
|
||||
equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
|
||||
|
||||
var values = jQuery.map( {a:1,b:2}, function( v, k ){
|
||||
return v;
|
||||
}, [ ] );
|
||||
|
||||
});
|
||||
equals( values.join(""), "12", "Map the values from a hash to an array" );
|
||||
|
||||
// object with length prop
|
||||
var values = jQuery.map( {a:1,b:2, length:3}, function( v, k ){
|
||||
return v;
|
||||
});
|
||||
equals( values.join(""), "123", "Map the values from a hash with a length property to an array" );
|
||||
|
||||
var scripts = document.getElementsByTagName("script");
|
||||
var mapped = jQuery.map( scripts, function( v, k ){
|
||||
return v;
|
||||
}, {length:0} );
|
||||
|
||||
});
|
||||
equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
|
||||
|
||||
var nonsense = document.getElementsByTagName("asdf");
|
||||
var mapped = jQuery.map( nonsense, function( v, k ){
|
||||
return v;
|
||||
});
|
||||
equals( mapped.length, nonsense.length, "Map an empty array(-like) to a hash" );
|
||||
|
||||
var flat = jQuery.map( Array(4), function( v, k ){
|
||||
return k % 2 ? k : [k,k,k];//try mixing array and regular returns
|
||||
});
|
||||
|
||||
equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
|
||||
});
|
||||
|
||||
|
@ -758,7 +809,7 @@ test("jQuery.extend(Object, Object)", function() {
|
|||
ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
|
||||
|
||||
var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
|
||||
ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
|
||||
ok( typeof ret.foo !== "undefined", "Make sure a null value doesn't crash with deep extend, for #1908" );
|
||||
|
||||
var obj = { foo:null };
|
||||
jQuery.extend(true, obj, { foo:"notnull" } );
|
||||
|
@ -784,7 +835,7 @@ test("jQuery.extend(Object, Object)", function() {
|
|||
});
|
||||
|
||||
test("jQuery.each(Object,Function)", function() {
|
||||
expect(13);
|
||||
expect(14);
|
||||
jQuery.each( [0,1,2], function(i, n){
|
||||
equals( i, n, "Check array iteration" );
|
||||
});
|
||||
|
@ -811,17 +862,24 @@ test("jQuery.each(Object,Function)", function() {
|
|||
equals( total, 3, "Looping over an object, with break" );
|
||||
|
||||
var f = function(){};
|
||||
f.foo = 'bar';
|
||||
f.foo = "bar";
|
||||
jQuery.each(f, function(i){
|
||||
f[i] = 'baz';
|
||||
f[i] = "baz";
|
||||
});
|
||||
equals( "baz", f.foo, "Loop over a function" );
|
||||
|
||||
var stylesheet_count = 0;
|
||||
jQuery.each(document.styleSheets, function(i){
|
||||
stylesheet_count++;
|
||||
});
|
||||
equals(stylesheet_count, 2, "should not throw an error in IE while looping over document.styleSheets and return proper amount");
|
||||
|
||||
});
|
||||
|
||||
test("jQuery.makeArray", function(){
|
||||
expect(17);
|
||||
|
||||
equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
|
||||
equals( jQuery.makeArray(jQuery("html>*"))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
|
||||
|
||||
equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
|
||||
|
||||
|
@ -851,11 +909,11 @@ test("jQuery.makeArray", function(){
|
|||
|
||||
equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
|
||||
|
||||
ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );
|
||||
ok( jQuery.makeArray(document.getElementById("form")).length >= 13, "Pass makeArray a form (treat as elements)" );
|
||||
|
||||
// For #5610
|
||||
same( jQuery.makeArray({'length': '0'}), [], "Make sure object is coerced properly.");
|
||||
same( jQuery.makeArray({'length': '5'}), [], "Make sure object is coerced properly.");
|
||||
same( jQuery.makeArray({length: "0"}), [], "Make sure object is coerced properly.");
|
||||
same( jQuery.makeArray({length: "5"}), [], "Make sure object is coerced properly.");
|
||||
});
|
||||
|
||||
test("jQuery.isEmptyObject", function(){
|
||||
|
@ -869,7 +927,7 @@ test("jQuery.isEmptyObject", function(){
|
|||
});
|
||||
|
||||
test("jQuery.proxy", function(){
|
||||
expect(4);
|
||||
expect(7);
|
||||
|
||||
var test = function(){ equals( this, thisObject, "Make sure that scope is set properly." ); };
|
||||
var thisObject = { foo: "bar", method: test };
|
||||
|
@ -880,11 +938,23 @@ test("jQuery.proxy", function(){
|
|||
// Basic scoping
|
||||
jQuery.proxy( test, thisObject )();
|
||||
|
||||
// Another take on it
|
||||
jQuery.proxy( thisObject, "method" )();
|
||||
|
||||
// Make sure it doesn't freak out
|
||||
equals( jQuery.proxy( null, thisObject ), undefined, "Make sure no function was returned." );
|
||||
|
||||
// Use the string shortcut
|
||||
jQuery.proxy( thisObject, "method" )();
|
||||
// Partial application
|
||||
var test2 = function( a ){ equals( a, "pre-applied", "Ensure arguments can be pre-applied." ); };
|
||||
jQuery.proxy( test2, null, "pre-applied" )();
|
||||
|
||||
// Partial application w/ normal arguments
|
||||
var test3 = function( a, b ){ equals( b, "normal", "Ensure arguments can be pre-applied and passed as usual." ); };
|
||||
jQuery.proxy( test3, null, "pre-applied" )( "normal" );
|
||||
|
||||
// Test old syntax
|
||||
var test4 = { meth: function( a ){ equals( a, "boom", "Ensure old syntax works." ); } };
|
||||
jQuery.proxy( test4, "meth" )( "boom" );
|
||||
});
|
||||
|
||||
test("jQuery.parseJSON", function(){
|
||||
|
@ -895,9 +965,9 @@ test("jQuery.parseJSON", function(){
|
|||
equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." );
|
||||
|
||||
same( jQuery.parseJSON("{}"), {}, "Plain object parsing." );
|
||||
same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." );
|
||||
same( jQuery.parseJSON("{\"test\":1}"), {"test":1}, "Plain object parsing." );
|
||||
|
||||
same( jQuery.parseJSON('\n{"test":1}'), {"test":1}, "Make sure leading whitespaces are handled." );
|
||||
same( jQuery.parseJSON("\n{\"test\":1}"), {"test":1}, "Make sure leading whitespaces are handled." );
|
||||
|
||||
try {
|
||||
jQuery.parseJSON("{a:1}");
|
||||
|
@ -921,7 +991,7 @@ test("jQuery.sub() - Static Methods", function(){
|
|||
topLevelMethod: function() {return this.debug;},
|
||||
debug: false,
|
||||
config: {
|
||||
locale: 'en_US'
|
||||
locale: "en_US"
|
||||
},
|
||||
setup: function(config) {
|
||||
this.extend(true, this.config, config);
|
||||
|
@ -930,37 +1000,37 @@ test("jQuery.sub() - Static Methods", function(){
|
|||
Subclass.fn.extend({subClassMethod: function() { return this;}});
|
||||
|
||||
//Test Simple Subclass
|
||||
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
|
||||
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
|
||||
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
|
||||
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
|
||||
ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true");
|
||||
ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!");
|
||||
same(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly");
|
||||
equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods");
|
||||
|
||||
//Create a SubSubclass
|
||||
var SubSubclass = Subclass.sub();
|
||||
|
||||
//Make Sure the SubSubclass inherited properly
|
||||
ok(SubSubclass.topLevelMethod() === false, 'SubSubclass.topLevelMethod thought debug was true');
|
||||
ok(SubSubclass.config.locale == 'en_US', SubSubclass.config.locale + ' is wrong!');
|
||||
same(SubSubclass.config.test, undefined, 'SubSubclass.config.test is set incorrectly');
|
||||
equal(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
|
||||
ok(SubSubclass.topLevelMethod() === false, "SubSubclass.topLevelMethod thought debug was true");
|
||||
ok(SubSubclass.config.locale == "en_US", SubSubclass.config.locale + " is wrong!");
|
||||
same(SubSubclass.config.test, undefined, "SubSubclass.config.test is set incorrectly");
|
||||
equal(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods");
|
||||
|
||||
//Modify The Subclass and test the Modifications
|
||||
SubSubclass.fn.extend({subSubClassMethod: function() { return this;}});
|
||||
SubSubclass.setup({locale: 'es_MX', test: 'worked'});
|
||||
SubSubclass.setup({locale: "es_MX", test: "worked"});
|
||||
SubSubclass.debug = true;
|
||||
SubSubclass.ajax = function() {return false;};
|
||||
ok(SubSubclass.topLevelMethod(), 'SubSubclass.topLevelMethod thought debug was false');
|
||||
same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, 'Methods Differ!');
|
||||
ok(SubSubclass.config.locale == 'es_MX', SubSubclass.config.locale + ' is wrong!');
|
||||
ok(SubSubclass.config.test == 'worked', 'SubSubclass.config.test is set incorrectly');
|
||||
notEqual(jQuery.ajax, SubSubclass.ajax, 'The subsubclass failed to get all top level methods');
|
||||
ok(SubSubclass.topLevelMethod(), "SubSubclass.topLevelMethod thought debug was false");
|
||||
same(SubSubclass(document).subClassMethod, Subclass.fn.subClassMethod, "Methods Differ!");
|
||||
ok(SubSubclass.config.locale == "es_MX", SubSubclass.config.locale + " is wrong!");
|
||||
ok(SubSubclass.config.test == "worked", "SubSubclass.config.test is set incorrectly");
|
||||
notEqual(jQuery.ajax, SubSubclass.ajax, "The subsubclass failed to get all top level methods");
|
||||
|
||||
//This shows that the modifications to the SubSubClass did not bubble back up to it's superclass
|
||||
ok(Subclass.topLevelMethod() === false, 'Subclass.topLevelMethod thought debug was true');
|
||||
ok(Subclass.config.locale == 'en_US', Subclass.config.locale + ' is wrong!');
|
||||
same(Subclass.config.test, undefined, 'Subclass.config.test is set incorrectly');
|
||||
same(Subclass(document).subSubClassMethod, undefined, 'subSubClassMethod set incorrectly');
|
||||
equal(jQuery.ajax, Subclass.ajax, 'The subclass failed to get all top level methods');
|
||||
ok(Subclass.topLevelMethod() === false, "Subclass.topLevelMethod thought debug was true");
|
||||
ok(Subclass.config.locale == "en_US", Subclass.config.locale + " is wrong!");
|
||||
same(Subclass.config.test, undefined, "Subclass.config.test is set incorrectly");
|
||||
same(Subclass(document).subSubClassMethod, undefined, "subSubClassMethod set incorrectly");
|
||||
equal(jQuery.ajax, Subclass.ajax, "The subclass failed to get all top level methods");
|
||||
});
|
||||
|
||||
test("jQuery.sub() - .fn Methods", function(){
|
||||
|
@ -971,25 +1041,25 @@ test("jQuery.sub() - .fn Methods", function(){
|
|||
jQueryDocument = jQuery(document),
|
||||
selectors, contexts, methods, method, arg, description;
|
||||
|
||||
jQueryDocument.toString = function(){ return 'jQueryDocument'; };
|
||||
jQueryDocument.toString = function(){ return "jQueryDocument"; };
|
||||
|
||||
Subclass.fn.subclassMethod = function(){};
|
||||
SubclassSubclass.fn.subclassSubclassMethod = function(){};
|
||||
|
||||
selectors = [
|
||||
'body',
|
||||
'html, body',
|
||||
'<div></div>'
|
||||
"body",
|
||||
"html, body",
|
||||
"<div></div>"
|
||||
];
|
||||
|
||||
methods = [ // all methods that return a new jQuery instance
|
||||
['eq', 1],
|
||||
['add', document],
|
||||
['end'],
|
||||
['has'],
|
||||
['closest', 'div'],
|
||||
['filter', document],
|
||||
['find', 'div']
|
||||
["eq", 1],
|
||||
["add", document],
|
||||
["end"],
|
||||
["has"],
|
||||
["closest", "div"],
|
||||
["filter", document],
|
||||
["find", "div"]
|
||||
];
|
||||
|
||||
contexts = [undefined, document, jQueryDocument];
|
||||
|
@ -1002,31 +1072,31 @@ test("jQuery.sub() - .fn Methods", function(){
|
|||
|
||||
jQuery.each(contexts, function(i, context){
|
||||
|
||||
description = '("'+selector+'", '+context+').'+method+'('+(arg||'')+')';
|
||||
description = "(\""+selector+"\", "+context+")."+method+"("+(arg||"")+")";
|
||||
|
||||
same(
|
||||
jQuery(selector, context)[method](arg).subclassMethod, undefined,
|
||||
'jQuery'+description+' doesnt have Subclass methods'
|
||||
"jQuery"+description+" doesn't have Subclass methods"
|
||||
);
|
||||
same(
|
||||
jQuery(selector, context)[method](arg).subclassSubclassMethod, undefined,
|
||||
'jQuery'+description+' doesnt have SubclassSubclass methods'
|
||||
"jQuery"+description+" doesn't have SubclassSubclass methods"
|
||||
);
|
||||
same(
|
||||
Subclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod,
|
||||
'Subclass'+description+' has Subclass methods'
|
||||
"Subclass"+description+" has Subclass methods"
|
||||
);
|
||||
same(
|
||||
Subclass(selector, context)[method](arg).subclassSubclassMethod, undefined,
|
||||
'Subclass'+description+' doesnt have SubclassSubclass methods'
|
||||
"Subclass"+description+" doesn't have SubclassSubclass methods"
|
||||
);
|
||||
same(
|
||||
SubclassSubclass(selector, context)[method](arg).subclassMethod, Subclass.fn.subclassMethod,
|
||||
'SubclassSubclass'+description+' has Subclass methods'
|
||||
"SubclassSubclass"+description+" has Subclass methods"
|
||||
);
|
||||
same(
|
||||
SubclassSubclass(selector, context)[method](arg).subclassSubclassMethod, SubclassSubclass.fn.subclassSubclassMethod,
|
||||
'SubclassSubclass'+description+' has SubclassSubclass methods'
|
||||
"SubclassSubclass"+description+" has SubclassSubclass methods"
|
||||
);
|
||||
|
||||
});
|
||||
|
@ -1034,3 +1104,17 @@ test("jQuery.sub() - .fn Methods", function(){
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
test("jQuery.camelCase()", function() {
|
||||
|
||||
var tests = {
|
||||
"foo-bar": "fooBar",
|
||||
"foo-bar-baz": "fooBarBaz"
|
||||
};
|
||||
|
||||
expect(2);
|
||||
|
||||
jQuery.each( tests, function( key, val ) {
|
||||
equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val );
|
||||
});
|
||||
});
|
||||
|
|
258
test/unit/css.js
258
test/unit/css.js
|
@ -1,15 +1,15 @@
|
|||
module("css", { teardown: moduleTeardown });
|
||||
|
||||
test("css(String|Hash)", function() {
|
||||
expect(41);
|
||||
expect( 42 );
|
||||
|
||||
equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"');
|
||||
equals( jQuery("#qunit-fixture").css("display"), "block", "Check for css property \"display\"");
|
||||
|
||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
||||
jQuery('#nothiddendiv').css({display: 'none'});
|
||||
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
||||
jQuery('#nothiddendiv').css({display: 'block'});
|
||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
||||
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
|
||||
jQuery("#nothiddendiv").css({display: "none"});
|
||||
ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
|
||||
jQuery("#nothiddendiv").css({display: "block"});
|
||||
ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
|
||||
|
||||
var div = jQuery( "<div>" );
|
||||
|
||||
|
@ -32,34 +32,37 @@ test("css(String|Hash)", function() {
|
|||
div2.remove();
|
||||
|
||||
// handle negative numbers by ignoring #1599, #4216
|
||||
jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });
|
||||
jQuery("#nothiddendiv").css( {width: 1, height: 1} );
|
||||
|
||||
var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
|
||||
jQuery('#nothiddendiv').css({ width: -1, height: -1 });
|
||||
equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
|
||||
equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
|
||||
var width = parseFloat(jQuery("#nothiddendiv").css("width")), height = parseFloat(jQuery("#nothiddendiv").css("height"));
|
||||
jQuery("#nothiddendiv").css({ width: -1, height: -1 });
|
||||
equals( parseFloat(jQuery("#nothiddendiv").css("width")), width, "Test negative width ignored")
|
||||
equals( parseFloat(jQuery("#nothiddendiv").css("height")), height, "Test negative height ignored")
|
||||
|
||||
equals( jQuery('<div style="display: none;">').css('display'), 'none', 'Styles on disconnected nodes');
|
||||
equals( jQuery("<div style='display: none;'>").css("display"), "none", "Styles on disconnected nodes");
|
||||
|
||||
jQuery('#floatTest').css({'float': 'right'});
|
||||
equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
|
||||
jQuery('#floatTest').css({'font-size': '30px'});
|
||||
equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
|
||||
jQuery("#floatTest").css({"float": "right"});
|
||||
equals( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right");
|
||||
jQuery("#floatTest").css({"font-size": "30px"});
|
||||
equals( jQuery("#floatTest").css("font-size"), "30px", "Modified CSS font-size: Assert font-size is 30px");
|
||||
jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
|
||||
jQuery("#foo").css({opacity: n});
|
||||
|
||||
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
||||
jQuery('#foo').css({opacity: n});
|
||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
||||
jQuery('#foo').css({opacity: parseFloat(n)});
|
||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
||||
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
||||
jQuery("#foo").css({opacity: parseFloat(n)});
|
||||
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
||||
});
|
||||
jQuery('#foo').css({opacity: ''});
|
||||
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
||||
jQuery("#foo").css({opacity: ""});
|
||||
equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
|
||||
|
||||
equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" );
|
||||
jQuery('#empty').css({ opacity: '1' });
|
||||
equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
|
||||
equals( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
|
||||
jQuery("#empty").css({ opacity: "1" });
|
||||
equals( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
|
||||
jQuery.support.opacity ?
|
||||
ok(true, "Requires the same number of tests"):
|
||||
ok( ~jQuery("#empty")[0].currentStyle.filter.indexOf("gradient"), "Assert setting opacity doesn't overwrite other filters of the stylesheet in IE" );
|
||||
|
||||
var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild');
|
||||
var div = jQuery("#nothiddendiv"), child = jQuery("#nothiddendivchild");
|
||||
|
||||
equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
|
||||
equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
|
||||
|
@ -105,31 +108,113 @@ test("css(String|Hash)", function() {
|
|||
equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
|
||||
});
|
||||
|
||||
test("css() explicit and relative values", function() {
|
||||
expect(27);
|
||||
var $elem = jQuery("#nothiddendiv");
|
||||
|
||||
$elem.css({ width: 1, height: 1, paddingLeft: "1px", opacity: 1 });
|
||||
equals( $elem.width(), 1, "Initial css set or width/height works (hash)" );
|
||||
equals( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" );
|
||||
equals( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" );
|
||||
|
||||
$elem.css({ width: "+=9" });
|
||||
equals( $elem.width(), 10, "'+=9' on width (hash)" );
|
||||
|
||||
$elem.css({ width: "-=9" });
|
||||
equals( $elem.width(), 1, "'-=9' on width (hash)" );
|
||||
|
||||
$elem.css({ width: "+=9px" });
|
||||
equals( $elem.width(), 10, "'+=9px' on width (hash)" );
|
||||
|
||||
$elem.css({ width: "-=9px" });
|
||||
equals( $elem.width(), 1, "'-=9px' on width (hash)" );
|
||||
|
||||
$elem.css( "width", "+=9" );
|
||||
equals( $elem.width(), 10, "'+=9' on width (params)" );
|
||||
|
||||
$elem.css( "width", "-=9" ) ;
|
||||
equals( $elem.width(), 1, "'-=9' on width (params)" );
|
||||
|
||||
$elem.css( "width", "+=9px" );
|
||||
equals( $elem.width(), 10, "'+=9px' on width (params)" );
|
||||
|
||||
$elem.css( "width", "-=9px" );
|
||||
equals( $elem.width(), 1, "'-=9px' on width (params)" );
|
||||
|
||||
$elem.css({ paddingLeft: "+=4" });
|
||||
equals( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );
|
||||
|
||||
$elem.css({ paddingLeft: "-=4" });
|
||||
equals( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" );
|
||||
|
||||
$elem.css({ paddingLeft: "+=4px" });
|
||||
equals( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" );
|
||||
|
||||
$elem.css({ paddingLeft: "-=4px" });
|
||||
equals( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" );
|
||||
|
||||
$elem.css({ "padding-left": "+=4" });
|
||||
equals( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" );
|
||||
|
||||
$elem.css({ "padding-left": "-=4" });
|
||||
equals( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" );
|
||||
|
||||
$elem.css({ "padding-left": "+=4px" });
|
||||
equals( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" );
|
||||
|
||||
$elem.css({ "padding-left": "-=4px" });
|
||||
equals( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" );
|
||||
|
||||
$elem.css( "paddingLeft", "+=4" );
|
||||
equals( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" );
|
||||
|
||||
$elem.css( "paddingLeft", "-=4" );
|
||||
equals( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" );
|
||||
|
||||
$elem.css( "padding-left", "+=4px" );
|
||||
equals( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" );
|
||||
|
||||
$elem.css( "padding-left", "-=4px" );
|
||||
equals( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" );
|
||||
|
||||
$elem.css({ opacity: "-=0.5" });
|
||||
equals( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" );
|
||||
|
||||
$elem.css({ opacity: "+=0.5" });
|
||||
equals( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" );
|
||||
|
||||
$elem.css( "opacity", "-=0.5" );
|
||||
equals( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" );
|
||||
|
||||
$elem.css( "opacity", "+=0.5" );
|
||||
equals( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" );
|
||||
});
|
||||
|
||||
test("css(String, Object)", function() {
|
||||
expect(22);
|
||||
|
||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
|
||||
jQuery('#nothiddendiv').css("display", 'none');
|
||||
ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
|
||||
jQuery('#nothiddendiv').css("display", 'block');
|
||||
ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
|
||||
ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
|
||||
jQuery("#nothiddendiv").css("display", "none");
|
||||
ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
|
||||
jQuery("#nothiddendiv").css("display", "block");
|
||||
ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
|
||||
|
||||
jQuery("#nothiddendiv").css("top", "-1em");
|
||||
ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
|
||||
|
||||
jQuery('#floatTest').css('float', 'left');
|
||||
equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
|
||||
jQuery('#floatTest').css('font-size', '20px');
|
||||
equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
|
||||
jQuery("#floatTest").css("float", "left");
|
||||
equals( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
|
||||
jQuery("#floatTest").css("font-size", "20px");
|
||||
equals( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
|
||||
|
||||
jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
|
||||
jQuery('#foo').css('opacity', n);
|
||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
||||
jQuery('#foo').css('opacity', parseFloat(n));
|
||||
equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
||||
jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
|
||||
jQuery("#foo").css("opacity", n);
|
||||
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
|
||||
jQuery("#foo").css("opacity", parseFloat(n));
|
||||
equals( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
|
||||
});
|
||||
jQuery('#foo').css('opacity', '');
|
||||
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
|
||||
jQuery("#foo").css("opacity", "");
|
||||
equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
|
||||
|
||||
// using contents will get comments regular, text, and comment nodes
|
||||
var j = jQuery("#nonnodes").contents();
|
||||
|
@ -149,7 +234,7 @@ test("css(String, Object)", function() {
|
|||
// Test for Bug #5509
|
||||
var success = true;
|
||||
try {
|
||||
jQuery('#foo').css("backgroundColor", "rgba(0, 0, 0, 0.1)");
|
||||
jQuery("#foo").css("backgroundColor", "rgba(0, 0, 0, 0.1)");
|
||||
}
|
||||
catch (e) {
|
||||
success = false;
|
||||
|
@ -160,19 +245,19 @@ test("css(String, Object)", function() {
|
|||
if ( !jQuery.support.opacity ) {
|
||||
test("css(String, Object) for MSIE", function() {
|
||||
// for #1438, IE throws JS error when filter exists but doesn't have opacity in it
|
||||
jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
|
||||
equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
|
||||
jQuery("#foo").css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
|
||||
equals( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when a different filter is set in IE, #1438" );
|
||||
|
||||
var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
|
||||
var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
|
||||
var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
|
||||
jQuery('#foo').css("filter", filterVal);
|
||||
equals( jQuery('#foo').css("filter"), filterVal, "css('filter', val) works" );
|
||||
jQuery('#foo').css("opacity", 1);
|
||||
equals( jQuery('#foo').css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
|
||||
equals( jQuery('#foo').css("opacity"), 1, "Setting opacity in IE with other filters works" );
|
||||
jQuery('#foo').css("filter", filterVal3).css("opacity", 1);
|
||||
ok( jQuery('#foo').css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" );
|
||||
jQuery("#foo").css("filter", filterVal);
|
||||
equals( jQuery("#foo").css("filter"), filterVal, "css('filter', val) works" );
|
||||
jQuery("#foo").css("opacity", 1);
|
||||
equals( jQuery("#foo").css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
|
||||
equals( jQuery("#foo").css("opacity"), 1, "Setting opacity in IE with other filters works" );
|
||||
jQuery("#foo").css("filter", filterVal3).css("opacity", 1);
|
||||
ok( jQuery("#foo").css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" );
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -311,14 +396,14 @@ test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", funct
|
|||
test(":visible selector works properly on table elements (bug #4512)", function () {
|
||||
expect(1);
|
||||
|
||||
jQuery('#table').html('<tr><td style="display:none">cell</td><td>cell</td></tr>');
|
||||
equals(jQuery('#table td:visible').length, 1, "hidden cell is not perceived as visible");
|
||||
jQuery("#table").html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
|
||||
equals(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible");
|
||||
});
|
||||
|
||||
test(":visible selector works properly on children with a hidden parent (bug #4512)", function () {
|
||||
expect(1);
|
||||
jQuery('#table').css('display', 'none').html('<tr><td>cell</td><td>cell</td></tr>');
|
||||
equals(jQuery('#table td:visible').length, 0, "hidden cell children not perceived as visible");
|
||||
jQuery("#table").css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");
|
||||
equals(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible");
|
||||
});
|
||||
|
||||
test("internal ref to elem.runtimeStyle (bug #7608)", function () {
|
||||
|
@ -343,5 +428,60 @@ test("marginRight computed style (bug #3333)", function() {
|
|||
marginRight: 0
|
||||
});
|
||||
|
||||
equals($div.css("marginRight"), "0px");
|
||||
equals($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
|
||||
});
|
||||
|
||||
test("jQuery.cssProps behavior, (bug #8402)", function() {
|
||||
var div = jQuery( "<div>" ).appendTo(document.body).css({
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 10
|
||||
});
|
||||
jQuery.cssProps.top = "left";
|
||||
equal( div.css("top"), "10px", "the fixed property is used when accessing the computed style");
|
||||
div.css("top", "100px");
|
||||
equal( div[0].style.left, "100px", "the fixed property is used when setting the style");
|
||||
// cleanup jQuery.cssProps
|
||||
jQuery.cssProps.top = undefined;
|
||||
});
|
||||
|
||||
test("widows & orphans #8936", function () {
|
||||
|
||||
var $p = jQuery("<p>").appendTo("#qunit-fixture");
|
||||
|
||||
if ( "widows" in $p[0].style ) {
|
||||
expect(4);
|
||||
$p.css({
|
||||
widows: 0,
|
||||
orphans: 0
|
||||
});
|
||||
|
||||
equal( $p.css("widows") || jQuery.style( $p[0], "widows" ), 0, "widows correctly start with value 0");
|
||||
equal( $p.css("orphans") || jQuery.style( $p[0], "orphans" ), 0, "orphans correctly start with value 0");
|
||||
|
||||
$p.css({
|
||||
widows: 3,
|
||||
orphans: 3
|
||||
});
|
||||
|
||||
equal( $p.css("widows") || jQuery.style( $p[0], "widows" ), 3, "widows correctly set to 3");
|
||||
equal( $p.css("orphans") || jQuery.style( $p[0], "orphans" ), 3, "orphans correctly set to 3");
|
||||
} else {
|
||||
|
||||
expect(1);
|
||||
ok( true, "jQuery does not attempt to test for style props that definitely don't exist in older versions of IE");
|
||||
}
|
||||
|
||||
|
||||
$p.remove();
|
||||
});
|
||||
|
||||
test("Do not append px to 'fill-opacity' #9548", 1, function() {
|
||||
|
||||
var $div = jQuery("<div>").appendTo("#qunit-fixture");
|
||||
|
||||
$div.css("fill-opacity", 0).animate({ "fill-opacity": 1.0 }, 0, function () {
|
||||
equal( jQuery(this).css("fill-opacity"), 1, "Do not append px to 'fill-opacity'");
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -283,11 +283,11 @@ test(".data(String) and .data(String, Object)", function() {
|
|||
|
||||
// #3748
|
||||
var $elem = jQuery({exists:true});
|
||||
equals( $elem.data('nothing'), undefined, "Non-existent data returns undefined");
|
||||
equals( $elem.data('null',null).data('null'), null, "null's are preserved");
|
||||
equals( $elem.data('emptyString','').data('emptyString'), '', "Empty strings are preserved");
|
||||
equals( $elem.data('false',false).data('false'), false, "false's are preserved");
|
||||
equals( $elem.data('exists'), undefined, "Existing data is not returned" );
|
||||
equals( $elem.data("nothing"), undefined, "Non-existent data returns undefined");
|
||||
equals( $elem.data("null", null).data("null"), null, "null's are preserved");
|
||||
equals( $elem.data("emptyString", "").data("emptyString"), "", "Empty strings are preserved");
|
||||
equals( $elem.data("false", false).data("false"), false, "false's are preserved");
|
||||
equals( $elem.data("exists"), undefined, "Existing data is not returned" );
|
||||
|
||||
// Clean up
|
||||
$elem.removeData();
|
||||
|
@ -316,7 +316,7 @@ test("data-* attributes", function() {
|
|||
|
||||
div.remove();
|
||||
|
||||
child.appendTo('#main');
|
||||
child.appendTo("#qunit-fixture");
|
||||
equals( child.data("myobj"), "old data", "Value accessed from data-* attribute");
|
||||
|
||||
child.data("myobj", "replaced");
|
||||
|
@ -365,19 +365,19 @@ test("data-* attributes", function() {
|
|||
.attr("data-null", "null")
|
||||
.attr("data-string", "test");
|
||||
|
||||
strictEqual( child.data('true'), true, "Primitive true read from attribute");
|
||||
strictEqual( child.data('false'), false, "Primitive false read from attribute");
|
||||
strictEqual( child.data('five'), 5, "Primitive number read from attribute");
|
||||
strictEqual( child.data('point'), 5.5, "Primitive number read from attribute");
|
||||
strictEqual( child.data('pointe'), 5500, "Primitive number read from attribute");
|
||||
strictEqual( child.data('pointbad'), "5..5", "Bad number read from attribute");
|
||||
strictEqual( child.data('pointbad2'), "-.", "Bad number read from attribute");
|
||||
strictEqual( child.data('badjson'), "{123}", "Bad number read from attribute");
|
||||
strictEqual( child.data('badjson2'), "[abc]", "Bad number read from attribute");
|
||||
strictEqual( child.data('empty'), "", "Empty string read from attribute");
|
||||
strictEqual( child.data('space'), " ", "Empty string read from attribute");
|
||||
strictEqual( child.data('null'), null, "Primitive null read from attribute");
|
||||
strictEqual( child.data('string'), "test", "Typical string read from attribute");
|
||||
strictEqual( child.data("true"), true, "Primitive true read from attribute");
|
||||
strictEqual( child.data("false"), false, "Primitive false read from attribute");
|
||||
strictEqual( child.data("five"), 5, "Primitive number read from attribute");
|
||||
strictEqual( child.data("point"), 5.5, "Primitive number read from attribute");
|
||||
strictEqual( child.data("pointe"), 5500, "Primitive number read from attribute");
|
||||
strictEqual( child.data("pointbad"), "5..5", "Bad number read from attribute");
|
||||
strictEqual( child.data("pointbad2"), "-.", "Bad number read from attribute");
|
||||
strictEqual( child.data("badjson"), "{123}", "Bad number read from attribute");
|
||||
strictEqual( child.data("badjson2"), "[abc]", "Bad number read from attribute");
|
||||
strictEqual( child.data("empty"), "", "Empty string read from attribute");
|
||||
strictEqual( child.data("space"), " ", "Empty string read from attribute");
|
||||
strictEqual( child.data("null"), null, "Primitive null read from attribute");
|
||||
strictEqual( child.data("string"), "test", "Typical string read from attribute");
|
||||
|
||||
child.remove();
|
||||
|
||||
|
@ -401,12 +401,12 @@ test("data-* attributes", function() {
|
|||
same(jQuery(elem).data("stuff"), [2,8], "Check stuff property");
|
||||
break;
|
||||
default:
|
||||
ok(false, ["Assertion failed on index ", index, ", with data ", data].join(''));
|
||||
ok(false, ["Assertion failed on index ", index, ", with data ", data].join(""));
|
||||
}
|
||||
}
|
||||
|
||||
var metadata = '<ol><li class="test test2" data-foo="bar" data-bar="baz" data-arr="[1,2]">Some stuff</li><li class="test test2" data-test="bar" data-bar="baz">Some stuff</li><li class="test test2" data-zoooo="bar" data-bar=\'{"test":"baz"}\'>Some stuff</li><li class="test test2" data-number=true data-stuff="[2,8]">Some stuff</li></ol>',
|
||||
elem = jQuery(metadata).appendTo('#main');
|
||||
var metadata = "<ol><li class='test test2' data-foo='bar' data-bar='baz' data-arr='[1,2]'>Some stuff</li><li class='test test2' data-test='bar' data-bar='baz'>Some stuff</li><li class='test test2' data-zoooo='bar' data-bar='{\"test\":\"baz\"}'>Some stuff</li><li class='test test2' data-number=true data-stuff='[2,8]'>Some stuff</li></ol>",
|
||||
elem = jQuery(metadata).appendTo("#qunit-fixture");
|
||||
|
||||
elem.find("li").each(testData);
|
||||
elem.remove();
|
||||
|
@ -483,6 +483,45 @@ if (window.JSON && window.JSON.stringify) {
|
|||
var obj = { foo: "bar" };
|
||||
jQuery.data(obj, "hidden", true);
|
||||
|
||||
equals( JSON.stringify(obj), '{"foo":"bar"}', "Expando is hidden from JSON.stringify" );
|
||||
equals( JSON.stringify(obj), "{\"foo\":\"bar\"}", "Expando is hidden from JSON.stringify" );
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
test("jQuery.data should follow html5 specification regarding camel casing", function() {
|
||||
expect(8);
|
||||
|
||||
var div = jQuery("<div id='myObject' data-foo='a' data-foo-bar='b' data-foo-bar-baz='c'></div>")
|
||||
.prependTo("body");
|
||||
|
||||
equals(div.data().foo, "a", "Verify single word data-* key");
|
||||
equals(div.data().fooBar, "b", "Verify multiple word data-* key");
|
||||
equals(div.data().fooBarBaz, "c", "Verify multiple word data-* key");
|
||||
|
||||
equals(div.data("foo"), "a", "Verify single word data-* key");
|
||||
equals(div.data("fooBar"), "b", "Verify multiple word data-* key");
|
||||
equals(div.data("fooBarBaz"), "c", "Verify multiple word data-* key");
|
||||
|
||||
div.data("foo-bar", "d");
|
||||
|
||||
equals(div.data("fooBar"), "d", "Verify updated data-* key");
|
||||
equals(div.data("foo-bar"), "d", "Verify updated data-* key");
|
||||
|
||||
div.remove();
|
||||
});
|
||||
|
||||
test("jQuery.data should not miss data with preset hyphenated property names", function() {
|
||||
|
||||
expect(2);
|
||||
|
||||
var div = jQuery("<div/>", { id: "hyphened" }).appendTo("#qunit-fixture"),
|
||||
test = {
|
||||
"camelBar": "camelBar",
|
||||
"hyphen-foo": "hyphen-foo"
|
||||
};
|
||||
|
||||
div.data( test );
|
||||
|
||||
jQuery.each( test , function(i, k) {
|
||||
equal( div.data(k), k, "data with property '"+k+"' was correctly found");
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,153 +1,308 @@
|
|||
module("deferred", { teardown: moduleTeardown });
|
||||
|
||||
test("jQuery._Deferred()", function() {
|
||||
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
|
||||
|
||||
expect( 11 );
|
||||
|
||||
var deferred,
|
||||
object,
|
||||
test;
|
||||
|
||||
deferred = jQuery._Deferred();
|
||||
|
||||
test = false;
|
||||
|
||||
deferred.done( function( value ) {
|
||||
equals( value , "value" , "Test pre-resolve callback" );
|
||||
test = true;
|
||||
} );
|
||||
|
||||
deferred.resolve( "value" );
|
||||
|
||||
ok( test , "Test pre-resolve callbacks called right away" );
|
||||
|
||||
test = false;
|
||||
|
||||
deferred.done( function( value ) {
|
||||
equals( value , "value" , "Test post-resolve callback" );
|
||||
test = true;
|
||||
} );
|
||||
|
||||
ok( test , "Test post-resolve callbacks called right away" );
|
||||
|
||||
deferred.cancel();
|
||||
|
||||
test = true;
|
||||
|
||||
deferred.done( function() {
|
||||
ok( false , "Cancel was ignored" );
|
||||
test = false;
|
||||
} );
|
||||
|
||||
ok( test , "Test cancel" );
|
||||
|
||||
deferred = jQuery._Deferred().resolve();
|
||||
|
||||
try {
|
||||
deferred.done( function() {
|
||||
throw "Error";
|
||||
} , function() {
|
||||
ok( true , "Test deferred do not cancel on exception" );
|
||||
} );
|
||||
} catch( e ) {
|
||||
strictEqual( e , "Error" , "Test deferred propagates exceptions");
|
||||
deferred.done();
|
||||
function createDeferred() {
|
||||
return withNew ? new jQuery._Deferred() : jQuery._Deferred();
|
||||
}
|
||||
|
||||
test = "";
|
||||
deferred = jQuery._Deferred().done( function() {
|
||||
test("jQuery._Deferred" + withNew, function() {
|
||||
|
||||
test += "A";
|
||||
expect( 11 );
|
||||
|
||||
}, function() {
|
||||
var deferred,
|
||||
object,
|
||||
test;
|
||||
|
||||
test += "B";
|
||||
deferred = createDeferred();
|
||||
|
||||
} ).resolve();
|
||||
test = false;
|
||||
|
||||
strictEqual( test , "AB" , "Test multiple done parameters" );
|
||||
deferred.done( function( value ) {
|
||||
equals( value , "value" , "Test pre-resolve callback" );
|
||||
test = true;
|
||||
} );
|
||||
|
||||
test = "";
|
||||
deferred.resolve( "value" );
|
||||
|
||||
deferred.done( function() {
|
||||
ok( test , "Test pre-resolve callbacks called right away" );
|
||||
|
||||
test = false;
|
||||
|
||||
deferred.done( function( value ) {
|
||||
equals( value , "value" , "Test post-resolve callback" );
|
||||
test = true;
|
||||
} );
|
||||
|
||||
ok( test , "Test post-resolve callbacks called right away" );
|
||||
|
||||
deferred.cancel();
|
||||
|
||||
test = true;
|
||||
|
||||
deferred.done( function() {
|
||||
ok( false , "Cancel was ignored" );
|
||||
test = false;
|
||||
} );
|
||||
|
||||
ok( test , "Test cancel" );
|
||||
|
||||
deferred = createDeferred().resolve();
|
||||
|
||||
try {
|
||||
deferred.done( function() {
|
||||
throw "Error";
|
||||
} , function() {
|
||||
ok( true , "Test deferred do not cancel on exception" );
|
||||
} );
|
||||
} catch( e ) {
|
||||
strictEqual( e , "Error" , "Test deferred propagates exceptions");
|
||||
deferred.done();
|
||||
}
|
||||
|
||||
test = "";
|
||||
deferred = createDeferred().done( function() {
|
||||
|
||||
test += "A";
|
||||
|
||||
}, function() {
|
||||
|
||||
test += "B";
|
||||
|
||||
} ).resolve();
|
||||
|
||||
strictEqual( test , "AB" , "Test multiple done parameters" );
|
||||
|
||||
test = "";
|
||||
|
||||
deferred.done( function() {
|
||||
|
||||
test += "C";
|
||||
deferred.done( function() {
|
||||
|
||||
test += "C";
|
||||
|
||||
} );
|
||||
|
||||
test += "A";
|
||||
|
||||
}, function() {
|
||||
|
||||
test += "B";
|
||||
} );
|
||||
|
||||
test += "A";
|
||||
strictEqual( test , "ABC" , "Test done callbacks order" );
|
||||
|
||||
}, function() {
|
||||
deferred = createDeferred();
|
||||
|
||||
test += "B";
|
||||
deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
|
||||
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
|
||||
});
|
||||
|
||||
// #8421
|
||||
deferred = createDeferred();
|
||||
deferred.resolveWith().done(function() {
|
||||
ok( true, "Test resolveWith can be called with no argument" );
|
||||
});
|
||||
});
|
||||
} );
|
||||
|
||||
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
|
||||
|
||||
function createDeferred( fn ) {
|
||||
return withNew ? new jQuery.Deferred( fn ) : jQuery.Deferred( fn );
|
||||
}
|
||||
|
||||
test("jQuery.Deferred" + withNew, function() {
|
||||
|
||||
expect( 8 );
|
||||
|
||||
createDeferred().resolve().then( function() {
|
||||
ok( true , "Success on resolve" );
|
||||
ok( this.isResolved(), "Deferred is resolved" );
|
||||
}, function() {
|
||||
ok( false , "Error on resolve" );
|
||||
}).always( function() {
|
||||
ok( true , "Always callback on resolve" );
|
||||
});
|
||||
|
||||
createDeferred().reject().then( function() {
|
||||
ok( false , "Success on reject" );
|
||||
}, function() {
|
||||
ok( true , "Error on reject" );
|
||||
ok( this.isRejected(), "Deferred is rejected" );
|
||||
}).always( function() {
|
||||
ok( true , "Always callback on reject" );
|
||||
});
|
||||
|
||||
createDeferred( function( defer ) {
|
||||
ok( this === defer , "Defer passed as this & first argument" );
|
||||
this.resolve( "done" );
|
||||
}).then( function( value ) {
|
||||
strictEqual( value , "done" , "Passed function executed" );
|
||||
});
|
||||
});
|
||||
} );
|
||||
|
||||
test( "jQuery.Deferred.pipe - filtering (done)", function() {
|
||||
|
||||
expect(4);
|
||||
|
||||
var defer = jQuery.Deferred(),
|
||||
piped = defer.pipe(function( a, b ) {
|
||||
return a * b;
|
||||
}),
|
||||
value1,
|
||||
value2,
|
||||
value3;
|
||||
|
||||
piped.done(function( result ) {
|
||||
value3 = result;
|
||||
});
|
||||
|
||||
defer.done(function( a, b ) {
|
||||
value1 = a;
|
||||
value2 = b;
|
||||
});
|
||||
|
||||
defer.resolve( 2, 3 );
|
||||
|
||||
strictEqual( value1, 2, "first resolve value ok" );
|
||||
strictEqual( value2, 3, "second resolve value ok" );
|
||||
strictEqual( value3, 6, "result of filter ok" );
|
||||
|
||||
jQuery.Deferred().reject().pipe(function() {
|
||||
ok( false, "pipe should not be called on reject" );
|
||||
});
|
||||
|
||||
jQuery.Deferred().resolve().pipe( jQuery.noop ).done(function( value ) {
|
||||
strictEqual( value, undefined, "pipe done callback can return undefined/null" );
|
||||
});
|
||||
});
|
||||
|
||||
test( "jQuery.Deferred.pipe - filtering (fail)", function() {
|
||||
|
||||
expect(4);
|
||||
|
||||
var defer = jQuery.Deferred(),
|
||||
piped = defer.pipe( null, function( a, b ) {
|
||||
return a * b;
|
||||
} ),
|
||||
value1,
|
||||
value2,
|
||||
value3;
|
||||
|
||||
piped.fail(function( result ) {
|
||||
value3 = result;
|
||||
});
|
||||
|
||||
defer.fail(function( a, b ) {
|
||||
value1 = a;
|
||||
value2 = b;
|
||||
});
|
||||
|
||||
defer.reject( 2, 3 );
|
||||
|
||||
strictEqual( value1, 2, "first reject value ok" );
|
||||
strictEqual( value2, 3, "second reject value ok" );
|
||||
strictEqual( value3, 6, "result of filter ok" );
|
||||
|
||||
jQuery.Deferred().resolve().pipe( null, function() {
|
||||
ok( false, "pipe should not be called on resolve" );
|
||||
} );
|
||||
|
||||
strictEqual( test , "ABC" , "Test done callbacks order" );
|
||||
|
||||
deferred = jQuery._Deferred();
|
||||
|
||||
deferred.resolveWith( jQuery , [ document ] ).done( function( doc ) {
|
||||
ok( this === jQuery && arguments.length === 1 && doc === document , "Test fire context & args" );
|
||||
});
|
||||
|
||||
// #8421
|
||||
deferred = jQuery._Deferred();
|
||||
deferred.resolveWith().done(function() {
|
||||
ok( true, "Test resolveWith can be called with no argument" );
|
||||
jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) {
|
||||
strictEqual( value, undefined, "pipe fail callback can return undefined/null" );
|
||||
});
|
||||
});
|
||||
|
||||
test("jQuery.Deferred()", function() {
|
||||
test( "jQuery.Deferred.pipe - deferred (done)", function() {
|
||||
|
||||
expect( 10 );
|
||||
expect(3);
|
||||
|
||||
jQuery.Deferred( function( defer ) {
|
||||
strictEqual( this , defer , "Defer passed as this & first argument" );
|
||||
this.resolve( "done" );
|
||||
}).then( function( value ) {
|
||||
strictEqual( value , "done" , "Passed function executed" );
|
||||
var defer = jQuery.Deferred(),
|
||||
piped = defer.pipe(function( a, b ) {
|
||||
return jQuery.Deferred(function( defer ) {
|
||||
defer.reject( a * b );
|
||||
});
|
||||
}),
|
||||
value1,
|
||||
value2,
|
||||
value3;
|
||||
|
||||
piped.fail(function( result ) {
|
||||
value3 = result;
|
||||
});
|
||||
|
||||
jQuery.Deferred().resolve().then( function() {
|
||||
ok( true , "Success on resolve" );
|
||||
}, function() {
|
||||
ok( false , "Error on resolve" );
|
||||
defer.done(function( a, b ) {
|
||||
value1 = a;
|
||||
value2 = b;
|
||||
});
|
||||
|
||||
jQuery.Deferred().reject().then( function() {
|
||||
ok( false , "Success on reject" );
|
||||
}, function() {
|
||||
ok( true , "Error on reject" );
|
||||
});
|
||||
defer.resolve( 2, 3 );
|
||||
|
||||
( new jQuery.Deferred( function( defer ) {
|
||||
strictEqual( this , defer , "Defer passed as this & first argument (new)" );
|
||||
this.resolve( "done" );
|
||||
}) ).then( function( value ) {
|
||||
strictEqual( value , "done" , "Passed function executed (new)" );
|
||||
});
|
||||
|
||||
( new jQuery.Deferred() ).resolve().then( function() {
|
||||
ok( true , "Success on resolve (new)" );
|
||||
}, function() {
|
||||
ok( false , "Error on resolve (new)" );
|
||||
});
|
||||
|
||||
( new jQuery.Deferred() ).reject().then( function() {
|
||||
ok( false , "Success on reject (new)" );
|
||||
}, function() {
|
||||
ok( true , "Error on reject (new)" );
|
||||
});
|
||||
|
||||
var tmp = jQuery.Deferred();
|
||||
|
||||
strictEqual( tmp.promise() , tmp.promise() , "Test deferred always return same promise" );
|
||||
strictEqual( tmp.promise() , tmp.promise().promise() , "Test deferred's promise always return same promise as deferred" );
|
||||
strictEqual( value1, 2, "first resolve value ok" );
|
||||
strictEqual( value2, 3, "second resolve value ok" );
|
||||
strictEqual( value3, 6, "result of filter ok" );
|
||||
});
|
||||
|
||||
test("jQuery.when()", function() {
|
||||
test( "jQuery.Deferred.pipe - deferred (fail)", function() {
|
||||
|
||||
expect(3);
|
||||
|
||||
var defer = jQuery.Deferred(),
|
||||
piped = defer.pipe( null, function( a, b ) {
|
||||
return jQuery.Deferred(function( defer ) {
|
||||
defer.resolve( a * b );
|
||||
});
|
||||
} ),
|
||||
value1,
|
||||
value2,
|
||||
value3;
|
||||
|
||||
piped.done(function( result ) {
|
||||
value3 = result;
|
||||
});
|
||||
|
||||
defer.fail(function( a, b ) {
|
||||
value1 = a;
|
||||
value2 = b;
|
||||
});
|
||||
|
||||
defer.reject( 2, 3 );
|
||||
|
||||
strictEqual( value1, 2, "first reject value ok" );
|
||||
strictEqual( value2, 3, "second reject value ok" );
|
||||
strictEqual( value3, 6, "result of filter ok" );
|
||||
});
|
||||
|
||||
test( "jQuery.Deferred.pipe - context", function() {
|
||||
|
||||
expect(4);
|
||||
|
||||
var context = {};
|
||||
|
||||
jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) {
|
||||
return value * 3;
|
||||
}).done(function( value ) {
|
||||
strictEqual( this, context, "custom context correctly propagated" );
|
||||
strictEqual( value, 6, "proper value received" );
|
||||
});
|
||||
|
||||
var defer = jQuery.Deferred(),
|
||||
piped = defer.pipe(function( value ) {
|
||||
return value * 3;
|
||||
});
|
||||
|
||||
defer.resolve( 2 );
|
||||
|
||||
piped.done(function( value ) {
|
||||
strictEqual( this.promise(), piped, "default context gets updated to latest defer in the chain" );
|
||||
strictEqual( value, 6, "proper value received" );
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test( "jQuery.when" , function() {
|
||||
|
||||
expect( 23 );
|
||||
|
||||
|
@ -166,57 +321,63 @@ test("jQuery.when()", function() {
|
|||
|
||||
} , function( message , value ) {
|
||||
|
||||
ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
|
||||
ok( jQuery.isFunction( jQuery.when( value ).done(function( resolveValue ) {
|
||||
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
|
||||
} ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
|
||||
}).promise ) , "Test " + message + " triggers the creation of a new Promise" );
|
||||
|
||||
} );
|
||||
|
||||
ok( jQuery.isFunction( jQuery.when().then( function( resolveValue ) {
|
||||
ok( jQuery.isFunction( jQuery.when().done(function( resolveValue ) {
|
||||
strictEqual( resolveValue , undefined , "Test the promise was resolved with no parameter" );
|
||||
} ).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
|
||||
}).promise ) , "Test calling when with no parameter triggers the creation of a new Promise" );
|
||||
|
||||
var cache, i;
|
||||
|
||||
for( i = 1 ; i < 4 ; i++ ) {
|
||||
jQuery.when( cache || jQuery.Deferred( function() {
|
||||
this.resolve( i );
|
||||
}) ).then( function( value ) {
|
||||
}) ).done(function( value ) {
|
||||
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
|
||||
cache = value;
|
||||
}, function() {
|
||||
ok( false , "Fail called" );
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("jQuery.when() - joined", function() {
|
||||
test("jQuery.when - joined", function() {
|
||||
|
||||
expect(8);
|
||||
expect(25);
|
||||
|
||||
jQuery.when( 1, 2, 3 ).done( function( a, b, c ) {
|
||||
strictEqual( a , 1 , "Test first param is first resolved value - non-observables" );
|
||||
strictEqual( b , 2 , "Test second param is second resolved value - non-observables" );
|
||||
strictEqual( c , 3 , "Test third param is third resolved value - non-observables" );
|
||||
}).fail( function() {
|
||||
ok( false , "Test the created deferred was resolved - non-observables");
|
||||
});
|
||||
var deferreds = {
|
||||
value: 1,
|
||||
success: jQuery.Deferred().resolve( 1 ),
|
||||
error: jQuery.Deferred().reject( 0 ),
|
||||
futureSuccess: jQuery.Deferred(),
|
||||
futureError: jQuery.Deferred()
|
||||
},
|
||||
willSucceed = {
|
||||
value: true,
|
||||
success: true,
|
||||
error: false,
|
||||
futureSuccess: true,
|
||||
futureError: false
|
||||
};
|
||||
|
||||
var successDeferred = jQuery.Deferred().resolve( 1 , 2 , 3 ),
|
||||
errorDeferred = jQuery.Deferred().reject( "error" , "errorParam" );
|
||||
|
||||
jQuery.when( 1 , successDeferred , 3 ).done( function( a, b, c ) {
|
||||
strictEqual( a , 1 , "Test first param is first resolved value - resolved observable" );
|
||||
same( b , [ 1 , 2 , 3 ] , "Test second param is second resolved value - resolved observable" );
|
||||
strictEqual( c , 3 , "Test third param is third resolved value - resolved observable" );
|
||||
}).fail( function() {
|
||||
ok( false , "Test the created deferred was resolved - resolved observable");
|
||||
});
|
||||
|
||||
jQuery.when( 1 , errorDeferred , 3 ).done( function() {
|
||||
ok( false , "Test the created deferred was rejected - rejected observable");
|
||||
}).fail( function( error , errorParam ) {
|
||||
strictEqual( error , "error" , "Test first param is first rejected value - rejected observable" );
|
||||
strictEqual( errorParam , "errorParam" , "Test second param is second rejected value - rejected observable" );
|
||||
});
|
||||
jQuery.each( deferreds, function( id1, defer1 ) {
|
||||
jQuery.each( deferreds, function( id2, defer2 ) {
|
||||
var shouldResolve = willSucceed[ id1 ] && willSucceed[ id2 ],
|
||||
expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ],
|
||||
code = id1 + "/" + id2;
|
||||
jQuery.when( defer1, defer2 ).done(function( a, b ) {
|
||||
if ( shouldResolve ) {
|
||||
same( [ a, b ], expected, code + " => resolve" );
|
||||
}
|
||||
}).fail(function( a, b ) {
|
||||
if ( !shouldResolve ) {
|
||||
same( [ a, b ], expected, code + " => resolve" );
|
||||
}
|
||||
});
|
||||
} );
|
||||
} );
|
||||
deferreds.futureSuccess.resolve( 1 );
|
||||
deferreds.futureError.reject( 0 );
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ function testWidth( val ) {
|
|||
equals( blah.width( val(10) ), blah, "Make sure that setting a width on an empty set returns the set." );
|
||||
equals( blah.width(), null, "Make sure 'null' is returned on an empty set");
|
||||
|
||||
jQuery.removeData($div[0], 'olddisplay', true);
|
||||
jQuery.removeData($div[0], "olddisplay", true);
|
||||
}
|
||||
|
||||
test("width()", function() {
|
||||
|
@ -83,7 +83,7 @@ function testHeight( val ) {
|
|||
equals( blah.height( val(10) ), blah, "Make sure that setting a height on an empty set returns the set." );
|
||||
equals( blah.height(), null, "Make sure 'null' is returned on an empty set");
|
||||
|
||||
jQuery.removeData($div[0], 'olddisplay', true);
|
||||
jQuery.removeData($div[0], "olddisplay", true);
|
||||
}
|
||||
|
||||
test("height()", function() {
|
||||
|
@ -107,7 +107,13 @@ test("height() with function args", function() {
|
|||
});
|
||||
|
||||
test("innerWidth()", function() {
|
||||
expect(4);
|
||||
expect(8);
|
||||
|
||||
equals(jQuery(window).innerWidth(), null, "Test on window without margin option");
|
||||
equals(jQuery(window).innerWidth(true), null, "Test on window with margin option");
|
||||
|
||||
equals(jQuery(document).innerWidth(), null, "Test on document without margin option");
|
||||
equals(jQuery(document).innerWidth(true), null, "Test on document with margin option");
|
||||
|
||||
var $div = jQuery("#nothiddendiv");
|
||||
// set styles
|
||||
|
@ -132,11 +138,17 @@ test("innerWidth()", function() {
|
|||
equals( div.innerWidth(), 0, "Make sure that disconnected nodes are handled." );
|
||||
|
||||
div.remove();
|
||||
jQuery.removeData($div[0], 'olddisplay', true);
|
||||
jQuery.removeData($div[0], "olddisplay", true);
|
||||
});
|
||||
|
||||
test("innerHeight()", function() {
|
||||
expect(4);
|
||||
expect(8);
|
||||
|
||||
equals(jQuery(window).innerHeight(), null, "Test on window without margin option");
|
||||
equals(jQuery(window).innerHeight(true), null, "Test on window with margin option");
|
||||
|
||||
equals(jQuery(document).innerHeight(), null, "Test on document without margin option");
|
||||
equals(jQuery(document).innerHeight(true), null, "Test on document with margin option");
|
||||
|
||||
var $div = jQuery("#nothiddendiv");
|
||||
// set styles
|
||||
|
@ -161,11 +173,16 @@ test("innerHeight()", function() {
|
|||
equals( div.innerHeight(), 0, "Make sure that disconnected nodes are handled." );
|
||||
|
||||
div.remove();
|
||||
jQuery.removeData($div[0], 'olddisplay', true);
|
||||
jQuery.removeData($div[0], "olddisplay", true);
|
||||
});
|
||||
|
||||
test("outerWidth()", function() {
|
||||
expect(7);
|
||||
expect(11);
|
||||
|
||||
equal( jQuery( window ).outerWidth(), null, "Test on window without margin option" );
|
||||
equal( jQuery( window ).outerWidth( true ), null, "Test on window with margin option" );
|
||||
equal( jQuery( document ).outerWidth(), null, "Test on document without margin option" );
|
||||
equal( jQuery( document ).outerWidth( true ), null, "Test on document with margin option" );
|
||||
|
||||
var $div = jQuery("#nothiddendiv");
|
||||
$div.css("width", 30);
|
||||
|
@ -191,11 +208,41 @@ test("outerWidth()", function() {
|
|||
equals( div.outerWidth(), 0, "Make sure that disconnected nodes are handled." );
|
||||
|
||||
div.remove();
|
||||
jQuery.removeData($div[0], 'olddisplay', true);
|
||||
jQuery.removeData($div[0], "olddisplay", true);
|
||||
});
|
||||
|
||||
test("child of a hidden elem has accurate inner/outer/Width()/Height() see #9441 #9300", function() {
|
||||
expect(8);
|
||||
|
||||
// setup html
|
||||
var $divNormal = jQuery("<div>").css({ width: "100px", height: "100px", border: "10px solid white", padding: "2px", margin: "3px" }),
|
||||
$divChild = $divNormal.clone(),
|
||||
$divHiddenParent = jQuery("<div>").css( "display", "none" ).append( $divChild ).appendTo("body");
|
||||
$divNormal.appendTo("body");
|
||||
|
||||
// tests that child div of a hidden div works the same as a normal div
|
||||
equals( $divChild.width(), $divNormal.width(), "child of a hidden element width() is wrong see #9441" );
|
||||
equals( $divChild.innerWidth(), $divNormal.innerWidth(), "child of a hidden element innerWidth() is wrong see #9441" );
|
||||
equals( $divChild.outerWidth(), $divNormal.outerWidth(), "child of a hidden element outerWidth() is wrong see #9441" );
|
||||
equals( $divChild.outerWidth(true), $divNormal.outerWidth( true ), "child of a hidden element outerWidth( true ) is wrong see #9300" );
|
||||
|
||||
equals( $divChild.height(), $divNormal.height(), "child of a hidden element height() is wrong see #9441" );
|
||||
equals( $divChild.innerHeight(), $divNormal.innerHeight(), "child of a hidden element innerHeight() is wrong see #9441" );
|
||||
equals( $divChild.outerHeight(), $divNormal.outerHeight(), "child of a hidden element outerHeight() is wrong see #9441" );
|
||||
equals( $divChild.outerHeight(true), $divNormal.outerHeight( true ), "child of a hidden element outerHeight( true ) is wrong see #9300" );
|
||||
|
||||
// teardown html
|
||||
$divHiddenParent.remove();
|
||||
$divNormal.remove();
|
||||
});
|
||||
|
||||
test("outerHeight()", function() {
|
||||
expect(7);
|
||||
expect(11);
|
||||
|
||||
equal( jQuery( window ).outerHeight(), null, "Test on window without margin option" );
|
||||
equal( jQuery( window ).outerHeight( true ), null, "Test on window with margin option" );
|
||||
equal( jQuery( document ).outerHeight(), null, "Test on document without margin option" );
|
||||
equal( jQuery( document ).outerHeight( true ), null, "Test on document with margin option" );
|
||||
|
||||
var $div = jQuery("#nothiddendiv");
|
||||
$div.css("height", 30);
|
||||
|
@ -220,5 +267,5 @@ test("outerHeight()", function() {
|
|||
equals( div.outerHeight(), 0, "Make sure that disconnected nodes are handled." );
|
||||
|
||||
div.remove();
|
||||
jQuery.removeData($div[0], 'olddisplay', true);
|
||||
jQuery.removeData($div[0], "olddisplay", true);
|
||||
});
|
||||
|
|
257
test/unit/effects.js
vendored
257
test/unit/effects.js
vendored
|
@ -2,7 +2,7 @@ module("effects", { teardown: moduleTeardown });
|
|||
|
||||
test("sanity check", function() {
|
||||
expect(1);
|
||||
ok( jQuery("#dl:visible, #main:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
|
||||
ok( jQuery("#dl:visible, #qunit-fixture:visible, #foo:visible").length === 3, "QUnit state is correct for testing effects" );
|
||||
});
|
||||
|
||||
test("show()", function() {
|
||||
|
@ -14,7 +14,7 @@ test("show()", function() {
|
|||
|
||||
equals( hiddendiv.css("display"), "block", "Make sure a pre-hidden div is visible." );
|
||||
|
||||
var div = jQuery("<div>").hide().appendTo("#main").show();
|
||||
var div = jQuery("<div>").hide().appendTo("#qunit-fixture").show();
|
||||
|
||||
equal( div.css("display"), "block", "Make sure pre-hidden divs show" );
|
||||
|
||||
|
@ -32,7 +32,8 @@ test("show()", function() {
|
|||
|
||||
hiddendiv.css("display","");
|
||||
|
||||
var pass = true, div = jQuery("#main div");
|
||||
var pass = true;
|
||||
div = jQuery("#qunit-fixture div");
|
||||
div.show().each(function(){
|
||||
if ( this.style.display == "none" ) pass = false;
|
||||
});
|
||||
|
@ -62,7 +63,7 @@ test("show()", function() {
|
|||
});
|
||||
|
||||
// #show-tests * is set display: none in CSS
|
||||
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id="test-table"></table>');
|
||||
jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
|
||||
|
||||
var old = jQuery("#test-table").show().css("display") !== "table";
|
||||
jQuery("#test-table").remove();
|
||||
|
@ -88,6 +89,10 @@ test("show()", function() {
|
|||
var elem = jQuery(selector, "#show-tests").show();
|
||||
equals( elem.css("display"), expected, "Show using correct display type for " + selector );
|
||||
});
|
||||
|
||||
// Make sure that showing or hiding a text node doesn't cause an error
|
||||
jQuery("<div>test</div> text <span>test</span>").show().remove();
|
||||
jQuery("<div>test</div> text <span>test</span>").hide().remove();
|
||||
});
|
||||
|
||||
test("show(Number) - other displays", function() {
|
||||
|
@ -96,7 +101,7 @@ test("show(Number) - other displays", function() {
|
|||
stop();
|
||||
|
||||
// #show-tests * is set display: none in CSS
|
||||
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id="test-table"></table>');
|
||||
jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
|
||||
|
||||
var old = jQuery("#test-table").show().css("display") !== "table",
|
||||
num = 0;
|
||||
|
@ -138,11 +143,11 @@ test("Persist correct display value", function() {
|
|||
stop();
|
||||
|
||||
// #show-tests * is set display: none in CSS
|
||||
jQuery("#main").append('<div id="show-tests"><span style="position:absolute;">foo</span></div>');
|
||||
jQuery("#qunit-fixture").append("<div id='show-tests'><span style='position:absolute;'>foo</span></div>");
|
||||
|
||||
var $span = jQuery("#show-tests span"),
|
||||
displayNone = $span.css("display"),
|
||||
display = '', num = 0;
|
||||
display = "", num = 0;
|
||||
|
||||
$span.show();
|
||||
|
||||
|
@ -162,13 +167,35 @@ test("Persist correct display value", function() {
|
|||
});
|
||||
});
|
||||
|
||||
test("show() resolves correct default display #8099", function() {
|
||||
expect(7);
|
||||
var tt8099 = jQuery("<tt/>").appendTo("body"),
|
||||
dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
|
||||
|
||||
equals( tt8099.css("display"), "none", "default display override for all tt" );
|
||||
equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
|
||||
|
||||
equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
|
||||
|
||||
equals( tt8099.hide().css("display"), "none", "default display override for all tt" );
|
||||
equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
|
||||
|
||||
equals( dfn8099.css("display"), "none", "default display override for all dfn" );
|
||||
equals( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
|
||||
|
||||
tt8099.remove();
|
||||
dfn8099.remove();
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("animate(Hash, Object, Function)", function() {
|
||||
expect(1);
|
||||
stop();
|
||||
var hash = {opacity: 'show'};
|
||||
var hash = {opacity: "show"};
|
||||
var hashCopy = jQuery.extend({}, hash);
|
||||
jQuery('#foo').animate(hash, 0, function() {
|
||||
equals( hash.opacity, hashCopy.opacity, 'Check if animate changed the hash parameter' );
|
||||
jQuery("#foo").animate(hash, 0, function() {
|
||||
equals( hash.opacity, hashCopy.opacity, "Check if animate changed the hash parameter" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
@ -193,7 +220,7 @@ test("animate block as inline width/height", function() {
|
|||
if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
|
||||
stop();
|
||||
|
||||
jQuery("#foo").css({ display: "inline", width: '', height: '' }).animate({ width: 42, height: 42 }, 100, function() {
|
||||
jQuery("#foo").css({ display: "inline", width: "", height: "" }).animate({ width: 42, height: 42 }, 100, function() {
|
||||
equals( jQuery(this).css("display"), jQuery.support.inlineBlockNeedsLayout ? "inline" : "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
|
||||
equals( this.offsetWidth, 42, "width was animated" );
|
||||
equals( this.offsetHeight, 42, "height was animated" );
|
||||
|
@ -218,9 +245,9 @@ test("animate native inline width/height", function() {
|
|||
|
||||
if ( jQuery.support.inlineBlockNeedsLayout || expected === "inline-block" ) {
|
||||
stop();
|
||||
jQuery("#foo").css({ display: "", width: '', height: '' })
|
||||
.append('<span>text</span>')
|
||||
.children('span')
|
||||
jQuery("#foo").css({ display: "", width: "", height: "" })
|
||||
.append("<span>text</span>")
|
||||
.children("span")
|
||||
.animate({ width: 42, height: 42 }, 100, function() {
|
||||
equals( jQuery(this).css("display"), "inline-block", "inline-block was set on non-floated inline element when animating width/height" );
|
||||
equals( this.offsetWidth, 42, "width was animated" );
|
||||
|
@ -317,13 +344,13 @@ test("animate option (queue === false)", function () {
|
|||
var order = [];
|
||||
|
||||
var $foo = jQuery("#foo");
|
||||
$foo.animate({width:'100px'}, 3000, function () {
|
||||
$foo.animate({width:"100px"}, 3000, function () {
|
||||
// should finish after unqueued animation so second
|
||||
order.push(2);
|
||||
same( order, [ 1, 2 ], "Animations finished in the correct order" );
|
||||
start();
|
||||
});
|
||||
$foo.animate({fontSize:'2em'}, {queue:false, duration:10, complete:function () {
|
||||
$foo.animate({fontSize:"2em"}, {queue:false, duration:10, complete:function () {
|
||||
// short duration and out of queue so should finish first
|
||||
order.push(1);
|
||||
}});
|
||||
|
@ -433,7 +460,7 @@ test("stop()", function() {
|
|||
var w = 0;
|
||||
$foo.hide().width(200).width();
|
||||
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
setTimeout(function(){
|
||||
var nw = $foo.width();
|
||||
notEqual( nw, w, "An animation occurred " + nw + "px " + w + "px");
|
||||
|
@ -458,9 +485,9 @@ test("stop() - several in queue", function() {
|
|||
var w = 0;
|
||||
$foo.hide().width(200).width();
|
||||
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width:'hide' }, 1000);
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
$foo.animate({ width: "hide" }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
setTimeout(function(){
|
||||
equals( $foo.queue().length, 3, "All 3 still in the queue" );
|
||||
var nw = $foo.width();
|
||||
|
@ -483,9 +510,9 @@ test("stop(clearQueue)", function() {
|
|||
var w = 0;
|
||||
$foo.hide().width(200).width();
|
||||
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width:'hide' }, 1000);
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
$foo.animate({ width: "hide" }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
setTimeout(function(){
|
||||
var nw = $foo.width();
|
||||
ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
|
||||
|
@ -510,10 +537,10 @@ test("stop(clearQueue, gotoEnd)", function() {
|
|||
var w = 0;
|
||||
$foo.hide().width(200).width();
|
||||
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width:'hide' }, 1000);
|
||||
$foo.animate({ width:'show' }, 1000);
|
||||
$foo.animate({ width:'hide' }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
$foo.animate({ width: "hide" }, 1000);
|
||||
$foo.animate({ width: "show" }, 1000);
|
||||
$foo.animate({ width: "hide" }, 1000);
|
||||
setTimeout(function(){
|
||||
var nw = $foo.width();
|
||||
ok( nw != w, "An animation occurred " + nw + "px " + w + "px");
|
||||
|
@ -556,10 +583,10 @@ jQuery.checkOverflowDisplay = function(){
|
|||
equals(jQuery.css( this, "display" ), "inline", "Display shouldn't be tampered with.");
|
||||
|
||||
start();
|
||||
}
|
||||
};
|
||||
|
||||
test( "jQuery.fx.prototype.cur()", 6, function() {
|
||||
var div = jQuery( "<div></div>" ).appendTo( "#main" ).css({
|
||||
var div = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" ).css({
|
||||
color: "#ABC",
|
||||
border: "5px solid black",
|
||||
left: "auto",
|
||||
|
@ -668,8 +695,8 @@ jQuery.each( {
|
|||
jQuery(elem).css(prop,prop == "opacity" ? 0 : "0px");
|
||||
return 0;
|
||||
}
|
||||
}, function(fn, f){
|
||||
jQuery.each( {
|
||||
}, function( fn, f ) {
|
||||
jQuery.each({
|
||||
"show": function(elem,prop){
|
||||
jQuery(elem).hide().addClass("wide"+prop);
|
||||
return "show";
|
||||
|
@ -717,59 +744,64 @@ jQuery.each( {
|
|||
|
||||
var anim = { width: t_w, height: t_h, opacity: t_o };
|
||||
|
||||
elem.animate(anim, 50, function(){
|
||||
elem.animate(anim, 50);
|
||||
|
||||
jQuery.when( elem ).done(function( elem ){
|
||||
|
||||
elem = elem[ 0 ];
|
||||
|
||||
if ( t_w == "show" )
|
||||
equals( this.style.display, "block", "Showing, display should block: " + this.style.display);
|
||||
equals( elem.style.display, "block", "Showing, display should block: " + elem.style.display);
|
||||
|
||||
if ( t_w == "hide"||t_w == "show" )
|
||||
ok(f_w === "" ? this.style.width === f_w : this.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + this.style.width);
|
||||
ok(f_w === "" ? elem.style.width === f_w : elem.style.width.indexOf(f_w) === 0, "Width must be reset to " + f_w + ": " + elem.style.width);
|
||||
|
||||
if ( t_h == "hide"||t_h == "show" )
|
||||
ok(f_h === "" ? this.style.height === f_h : this.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + this.style.height);
|
||||
ok(f_h === "" ? elem.style.height === f_h : elem.style.height.indexOf(f_h) === 0, "Height must be reset to " + f_h + ": " + elem.style.height);
|
||||
|
||||
var cur_o = jQuery.style(this, "opacity");
|
||||
var cur_o = jQuery.style(elem, "opacity");
|
||||
|
||||
if ( t_o == "hide" || t_o == "show" )
|
||||
equals(cur_o, f_o, "Opacity must be reset to " + f_o + ": " + cur_o);
|
||||
|
||||
if ( t_w == "hide" )
|
||||
equals(this.style.display, "none", "Hiding, display should be none: " + this.style.display);
|
||||
equals(elem.style.display, "none", "Hiding, display should be none: " + elem.style.display);
|
||||
|
||||
if ( t_o.constructor == Number ) {
|
||||
equals(cur_o, t_o, "Final opacity should be " + t_o + ": " + cur_o);
|
||||
|
||||
ok(jQuery.css(this, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
|
||||
ok(jQuery.css(elem, "opacity") != "" || cur_o == t_o, "Opacity should be explicitly set to " + t_o + ", is instead: " + cur_o);
|
||||
}
|
||||
|
||||
if ( t_w.constructor == Number ) {
|
||||
equals(this.style.width, t_w + "px", "Final width should be " + t_w + ": " + this.style.width);
|
||||
equals(elem.style.width, t_w + "px", "Final width should be " + t_w + ": " + elem.style.width);
|
||||
|
||||
var cur_w = jQuery.css(this,"width");
|
||||
var cur_w = jQuery.css(elem,"width");
|
||||
|
||||
ok(this.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
|
||||
ok(elem.style.width != "" || cur_w == t_w, "Width should be explicitly set to " + t_w + ", is instead: " + cur_w);
|
||||
}
|
||||
|
||||
if ( t_h.constructor == Number ) {
|
||||
equals(this.style.height, t_h + "px", "Final height should be " + t_h + ": " + this.style.height);
|
||||
equals(elem.style.height, t_h + "px", "Final height should be " + t_h + ": " + elem.style.height);
|
||||
|
||||
var cur_h = jQuery.css(this,"height");
|
||||
var cur_h = jQuery.css(elem,"height");
|
||||
|
||||
ok(this.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
|
||||
ok(elem.style.height != "" || cur_h == t_h, "Height should be explicitly set to " + t_h + ", is instead: " + cur_w);
|
||||
}
|
||||
|
||||
if ( t_h == "show" ) {
|
||||
var old_h = jQuery.css(this, "height");
|
||||
jQuery(this).append("<br/>Some more text<br/>and some more...");
|
||||
var old_h = jQuery.css(elem, "height");
|
||||
jQuery(elem).append("<br/>Some more text<br/>and some more...");
|
||||
|
||||
if ( /Auto/.test( fn ) ) {
|
||||
notEqual(jQuery.css(this, "height"), old_h, "Make sure height is auto.");
|
||||
notEqual(jQuery.css(elem, "height"), old_h, "Make sure height is auto.");
|
||||
} else {
|
||||
equals(jQuery.css(this, "height"), old_h, "Make sure height is not auto.");
|
||||
equals(jQuery.css(elem, "height"), old_h, "Make sure height is not auto.");
|
||||
}
|
||||
}
|
||||
|
||||
// manually remove generated element
|
||||
jQuery(this).remove();
|
||||
jQuery(elem).remove();
|
||||
|
||||
start();
|
||||
});
|
||||
|
@ -778,7 +810,7 @@ jQuery.each( {
|
|||
});
|
||||
|
||||
jQuery.fn.saveState = function(hiddenOverflow){
|
||||
var check = ['opacity','height','width','display','overflow'];
|
||||
var check = ["opacity", "height", "width", "display", "overflow"];
|
||||
expect(check.length);
|
||||
|
||||
stop();
|
||||
|
@ -799,64 +831,64 @@ jQuery.checkState = function(){
|
|||
});
|
||||
|
||||
// manually clean data on modified element
|
||||
jQuery.removeData(this, 'olddisplay', true);
|
||||
jQuery.removeData(this, "olddisplay", true);
|
||||
|
||||
start();
|
||||
}
|
||||
};
|
||||
|
||||
// Chaining Tests
|
||||
test("Chain fadeOut fadeIn", function() {
|
||||
jQuery('#fadein div').saveState().fadeOut('fast').fadeIn('fast',jQuery.checkState);
|
||||
jQuery("#fadein div").saveState().fadeOut("fast").fadeIn("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain fadeIn fadeOut", function() {
|
||||
jQuery('#fadeout div').saveState().fadeIn('fast').fadeOut('fast',jQuery.checkState);
|
||||
jQuery("#fadeout div").saveState().fadeIn("fast").fadeOut("fast",jQuery.checkState);
|
||||
});
|
||||
|
||||
test("Chain hide show", function() {
|
||||
jQuery('#show div').saveState(jQuery.support.shrinkWrapBlocks).hide('fast').show('fast',jQuery.checkState);
|
||||
jQuery("#show div").saveState(jQuery.support.shrinkWrapBlocks).hide("fast").show("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain show hide", function() {
|
||||
jQuery('#hide div').saveState(jQuery.support.shrinkWrapBlocks).show('fast').hide('fast',jQuery.checkState);
|
||||
jQuery("#hide div").saveState(jQuery.support.shrinkWrapBlocks).show("fast").hide("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain show hide with easing and callback", function() {
|
||||
jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
|
||||
jQuery("#hide div").saveState().show("fast").hide("fast","linear",jQuery.checkState);
|
||||
});
|
||||
|
||||
test("Chain toggle in", function() {
|
||||
jQuery('#togglein div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
|
||||
jQuery("#togglein div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain toggle out", function() {
|
||||
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast',jQuery.checkState);
|
||||
jQuery("#toggleout div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain toggle out with easing and callback", function() {
|
||||
jQuery('#toggleout div').saveState(jQuery.support.shrinkWrapBlocks).toggle('fast').toggle('fast','linear',jQuery.checkState);
|
||||
jQuery("#toggleout div").saveState(jQuery.support.shrinkWrapBlocks).toggle("fast").toggle("fast","linear",jQuery.checkState);
|
||||
});
|
||||
test("Chain slideDown slideUp", function() {
|
||||
jQuery('#slidedown div').saveState(jQuery.support.shrinkWrapBlocks).slideDown('fast').slideUp('fast',jQuery.checkState);
|
||||
jQuery("#slidedown div").saveState(jQuery.support.shrinkWrapBlocks).slideDown("fast").slideUp("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain slideUp slideDown", function() {
|
||||
jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast',jQuery.checkState);
|
||||
jQuery("#slideup div").saveState(jQuery.support.shrinkWrapBlocks).slideUp("fast").slideDown("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain slideUp slideDown with easing and callback", function() {
|
||||
jQuery('#slideup div').saveState(jQuery.support.shrinkWrapBlocks).slideUp('fast').slideDown('fast','linear',jQuery.checkState);
|
||||
jQuery("#slideup div").saveState(jQuery.support.shrinkWrapBlocks).slideUp("fast").slideDown("fast","linear",jQuery.checkState);
|
||||
});
|
||||
|
||||
test("Chain slideToggle in", function() {
|
||||
jQuery('#slidetogglein div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
|
||||
jQuery("#slidetogglein div").saveState(jQuery.support.shrinkWrapBlocks).slideToggle("fast").slideToggle("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain slideToggle out", function() {
|
||||
jQuery('#slidetoggleout div').saveState(jQuery.support.shrinkWrapBlocks).slideToggle('fast').slideToggle('fast',jQuery.checkState);
|
||||
jQuery("#slidetoggleout div").saveState(jQuery.support.shrinkWrapBlocks).slideToggle("fast").slideToggle("fast",jQuery.checkState);
|
||||
});
|
||||
|
||||
test("Chain fadeToggle in", function() {
|
||||
jQuery('#fadetogglein div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
|
||||
jQuery("#fadetogglein div").saveState().fadeToggle("fast").fadeToggle("fast",jQuery.checkState);
|
||||
});
|
||||
test("Chain fadeToggle out", function() {
|
||||
jQuery('#fadetoggleout div').saveState().fadeToggle('fast').fadeToggle('fast',jQuery.checkState);
|
||||
jQuery("#fadetoggleout div").saveState().fadeToggle("fast").fadeToggle("fast",jQuery.checkState);
|
||||
});
|
||||
|
||||
test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
|
||||
jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
|
||||
jQuery("#fadeto div").saveState().fadeTo("fast",0.5).fadeTo("fast",1.0,"linear",jQuery.checkState);
|
||||
});
|
||||
|
||||
jQuery.makeTest = function( text ){
|
||||
|
@ -870,7 +902,7 @@ jQuery.makeTest = function( text ){
|
|||
.after( elem );
|
||||
|
||||
return elem;
|
||||
}
|
||||
};
|
||||
|
||||
jQuery.makeTest.id = 1;
|
||||
|
||||
|
@ -891,34 +923,42 @@ test("jQuery.show('fast') doesn't clear radio buttons (bug #1095)", function ()
|
|||
|
||||
test("animate with per-property easing", function(){
|
||||
|
||||
expect(3);
|
||||
expect(5);
|
||||
stop();
|
||||
|
||||
var _test1_called = false;
|
||||
var _test2_called = false;
|
||||
var _default_test_called = false;
|
||||
var data = { a:0, b:0, c:0 },
|
||||
_test1_called = false,
|
||||
_test2_called = false,
|
||||
_default_test_called = false,
|
||||
props = {
|
||||
a: [ 100, "_test1" ],
|
||||
b: [ 100, "_test2" ],
|
||||
c: 100
|
||||
};
|
||||
|
||||
jQuery.easing['_test1'] = function() {
|
||||
jQuery.easing["_test1"] = function(p) {
|
||||
_test1_called = true;
|
||||
return p;
|
||||
};
|
||||
|
||||
jQuery.easing['_test2'] = function() {
|
||||
jQuery.easing["_test2"] = function(p) {
|
||||
_test2_called = true;
|
||||
return p;
|
||||
};
|
||||
|
||||
jQuery.easing['_default_test'] = function() {
|
||||
jQuery.easing["_default_test"] = function(p) {
|
||||
_default_test_called = true;
|
||||
return p;
|
||||
};
|
||||
|
||||
jQuery({a:0,b:0,c:0}).animate({
|
||||
a: [100, '_test1'],
|
||||
b: [100, '_test2'],
|
||||
c: 100
|
||||
}, 400, '_default_test', function(){
|
||||
jQuery(data).animate( props, 400, "_default_test", function(){
|
||||
start();
|
||||
ok(_test1_called, "Easing function (1) called");
|
||||
ok(_test2_called, "Easing function (2) called");
|
||||
ok(_default_test_called, "Easing function (_default) called");
|
||||
|
||||
ok( _test1_called, "Easing function (_test1) called" );
|
||||
ok( _test2_called, "Easing function (_test2) called" );
|
||||
ok( _default_test_called, "Easing function (_default) called" );
|
||||
equal( props.a[ 1 ], "_test1", "animate does not change original props (per-property easing would be lost)");
|
||||
equal( props.b[ 1 ], "_test2", "animate does not change original props (per-property easing would be lost)");
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -927,7 +967,7 @@ test("hide hidden elements (bug #7141)", function() {
|
|||
expect(3);
|
||||
QUnit.reset();
|
||||
|
||||
var div = jQuery("<div style='display:none'></div>").appendTo("#main");
|
||||
var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
|
||||
equals( div.css("display"), "none", "Element is hidden by default" );
|
||||
div.hide();
|
||||
ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
|
||||
|
@ -942,7 +982,7 @@ test("hide hidden elements, with animation (bug #7141)", function() {
|
|||
QUnit.reset();
|
||||
stop();
|
||||
|
||||
var div = jQuery("<div style='display:none'></div>").appendTo("#main");
|
||||
var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
|
||||
equals( div.css("display"), "none", "Element is hidden by default" );
|
||||
div.hide(1, function () {
|
||||
ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
|
||||
|
@ -955,10 +995,53 @@ test("hide hidden elements, with animation (bug #7141)", function() {
|
|||
|
||||
test("animate unit-less properties (#4966)", 2, function() {
|
||||
stop();
|
||||
var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#main" );
|
||||
var div = jQuery( "<div style='z-index: 0; position: absolute;'></div>" ).appendTo( "#qunit-fixture" );
|
||||
equal( div.css( "z-index" ), "0", "z-index is 0" );
|
||||
div.animate({ zIndex: 2 }, function() {
|
||||
equal( div.css( "z-index" ), "2", "z-index is 2" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test( "animate properties missing px w/ opacity as last (#9074)", 2, function() {
|
||||
expect( 6 );
|
||||
stop();
|
||||
var div = jQuery( "<div style='position: absolute; margin-left: 0; left: 0px;'></div>" )
|
||||
.appendTo( "#qunit-fixture" );
|
||||
function cssInt( prop ) {
|
||||
return parseInt( div.css( prop ), 10 );
|
||||
}
|
||||
equal( cssInt( "marginLeft" ), 0, "Margin left is 0" );
|
||||
equal( cssInt( "left" ), 0, "Left is 0" );
|
||||
div.animate({
|
||||
left: 200,
|
||||
marginLeft: 200,
|
||||
opacity: 0
|
||||
}, 1000);
|
||||
setTimeout(function() {
|
||||
var ml = cssInt( "marginLeft" ),
|
||||
l = cssInt( "left" );
|
||||
notEqual( ml, 0, "Margin left is not 0 after partial animate" );
|
||||
notEqual( ml, 200, "Margin left is not 200 after partial animate" );
|
||||
notEqual( l, 0, "Left is not 0 after partial animate" );
|
||||
notEqual( l, 200, "Left is not 200 after partial animate" );
|
||||
div.stop().remove();
|
||||
start();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
test("callbacks should fire in correct order (#9100)", function() {
|
||||
stop();
|
||||
var a = 1,
|
||||
cb = 0,
|
||||
$lis = jQuery("<p data-operation='*2'></p><p data-operation='^2'></p>").appendTo("#qunit-fixture")
|
||||
// The test will always pass if no properties are animated or if the duration is 0
|
||||
.animate({fontSize: 12}, 13, function() {
|
||||
a *= jQuery(this).data("operation") === "*2" ? 2 : a;
|
||||
cb++;
|
||||
if ( cb === 2 ) {
|
||||
equal( a, 4, "test value has been *2 and _then_ ^2");
|
||||
start();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,8 +14,28 @@ test("null or undefined handler", function() {
|
|||
} catch (e) {}
|
||||
});
|
||||
|
||||
test("bind(), with data", function() {
|
||||
test("bind(),live(),delegate() with non-null,defined data", function() {
|
||||
|
||||
expect(3);
|
||||
|
||||
var handler = function( event, data ) {
|
||||
equal( data, 0, "non-null, defined data (zero) is correctly passed" );
|
||||
};
|
||||
|
||||
jQuery("#foo").bind("foo", handler);
|
||||
jQuery("#foo").live("foo", handler);
|
||||
jQuery("div").delegate("#foo", "foo", handler);
|
||||
|
||||
jQuery("#foo").trigger("foo", 0);
|
||||
|
||||
jQuery("#foo").unbind("foo", handler);
|
||||
jQuery("#foo").die("foo", handler);
|
||||
jQuery("div").undelegate("#foo", "foo");
|
||||
|
||||
});
|
||||
|
||||
test("bind(), with data", function() {
|
||||
expect(4);
|
||||
var handler = function(event) {
|
||||
ok( event.data, "bind() with data, check passed data exists" );
|
||||
equals( event.data.foo, "bar", "bind() with data, Check value of passed data" );
|
||||
|
@ -23,6 +43,12 @@ test("bind(), with data", function() {
|
|||
jQuery("#firstp").bind("click", {foo: "bar"}, handler).click().unbind("click", handler);
|
||||
|
||||
ok( !jQuery._data(jQuery("#firstp")[0], "events"), "Event handler unbound when using data." );
|
||||
|
||||
var test = function(){};
|
||||
var handler2 = function(event) {
|
||||
equals( event.data, test, "bind() with function data, Check value of passed data" );
|
||||
};
|
||||
jQuery("#firstp").bind("click", test, handler2).click().unbind("click", handler2);
|
||||
});
|
||||
|
||||
test("click(), with data", function() {
|
||||
|
@ -62,6 +88,22 @@ test("bind(), multiple events at once", function() {
|
|||
equals( mouseoverCounter, 1, "bind() with multiple events at once" );
|
||||
});
|
||||
|
||||
test("bind(), five events at once", function() {
|
||||
expect(1);
|
||||
|
||||
var count = 0,
|
||||
handler = function(event) {
|
||||
count++;
|
||||
};
|
||||
|
||||
jQuery("#firstp").bind("click mouseover foo bar baz", handler)
|
||||
.trigger("click").trigger("mouseover")
|
||||
.trigger("foo").trigger("bar")
|
||||
.trigger("baz");
|
||||
|
||||
equals( count, 5, "bind() five events at once" );
|
||||
});
|
||||
|
||||
test("bind(), multiple events at once and namespaces", function() {
|
||||
expect(7);
|
||||
|
||||
|
@ -163,7 +205,7 @@ test("bind(), namespace with special add", function() {
|
|||
});
|
||||
|
||||
// Should trigger 2
|
||||
div.appendTo("#main").remove();
|
||||
div.appendTo("#qunit-fixture").remove();
|
||||
|
||||
delete jQuery.event.special.test;
|
||||
});
|
||||
|
@ -301,11 +343,11 @@ test("live/delegate immediate propagation", function() {
|
|||
test("bind/delegate bubbling, isDefaultPrevented", function() {
|
||||
expect(2);
|
||||
var $anchor2 = jQuery( "#anchor2" ),
|
||||
$main = jQuery( "#main" ),
|
||||
$main = jQuery( "#qunit-fixture" ),
|
||||
fakeClick = function($jq) {
|
||||
// Use a native click so we don't get jQuery simulated bubbling
|
||||
if ( document.createEvent ) {
|
||||
var e = document.createEvent( 'MouseEvents' );
|
||||
var e = document.createEvent( "MouseEvents" );
|
||||
e.initEvent( "click", true, true );
|
||||
$jq[0].dispatchEvent(e);
|
||||
}
|
||||
|
@ -347,7 +389,7 @@ test("bind(), iframes", function() {
|
|||
|
||||
jQuery("div", doc).bind("click", function() {
|
||||
ok( true, "Binding to element inside iframe" );
|
||||
}).click().unbind('click');
|
||||
}).click().unbind("click");
|
||||
});
|
||||
|
||||
test("bind(), trigger change on select", function() {
|
||||
|
@ -357,8 +399,8 @@ test("bind(), trigger change on select", function() {
|
|||
equals( event.data, counter++, "Event.data is not a global event object" );
|
||||
};
|
||||
jQuery("#form select").each(function(i){
|
||||
jQuery(this).bind('change', i, selectOnChange);
|
||||
}).trigger('change');
|
||||
jQuery(this).bind("change", i, selectOnChange);
|
||||
}).trigger("change");
|
||||
});
|
||||
|
||||
test("bind(), namespaced events, cloned events", 18, function() {
|
||||
|
@ -409,7 +451,7 @@ test("bind(), namespaced events, cloned events", 18, function() {
|
|||
}).trigger("tester");
|
||||
|
||||
// Make sure events stick with appendTo'd elements (which are cloned) #2027
|
||||
jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("#main");
|
||||
jQuery("<a href='#fail' class='test'>test</a>").click(function(){ return false; }).appendTo("#qunit-fixture");
|
||||
ok( jQuery("a.test:first").triggerHandler("click") === false, "Handler is bound to appendTo'd elements" );
|
||||
});
|
||||
|
||||
|
@ -532,7 +574,7 @@ test("bind(name, false), unbind(name, false)", function() {
|
|||
expect(3);
|
||||
|
||||
var main = 0;
|
||||
jQuery("#main").bind("click", function(e){ main++; });
|
||||
jQuery("#qunit-fixture").bind("click", function(e){ main++; });
|
||||
jQuery("#ap").trigger("click");
|
||||
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||
|
||||
|
@ -547,7 +589,48 @@ test("bind(name, false), unbind(name, false)", function() {
|
|||
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||
|
||||
// manually clean up events from elements outside the fixture
|
||||
jQuery("#main").unbind("click");
|
||||
jQuery("#qunit-fixture").unbind("click");
|
||||
});
|
||||
|
||||
test("live(name, false), die(name, false)", function() {
|
||||
expect(3);
|
||||
|
||||
var main = 0;
|
||||
jQuery("#qunit-fixture").live("click", function(e){ main++; });
|
||||
jQuery("#ap").trigger("click");
|
||||
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||
|
||||
main = 0;
|
||||
jQuery("#ap").live("click", false);
|
||||
jQuery("#ap").trigger("click");
|
||||
equals( main, 0, "Verify that no bubble happened." );
|
||||
|
||||
main = 0;
|
||||
jQuery("#ap").die("click", false);
|
||||
jQuery("#ap").trigger("click");
|
||||
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||
jQuery("#qunit-fixture").die("click");
|
||||
});
|
||||
|
||||
test("delegate(selector, name, false), undelegate(selector, name, false)", function() {
|
||||
expect(3);
|
||||
|
||||
var main = 0;
|
||||
|
||||
jQuery("#qunit-fixture").delegate("#ap", "click", function(e){ main++; });
|
||||
jQuery("#ap").trigger("click");
|
||||
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||
|
||||
main = 0;
|
||||
jQuery("#ap").delegate("#groups", "click", false);
|
||||
jQuery("#groups").trigger("click");
|
||||
equals( main, 0, "Verify that no bubble happened." );
|
||||
|
||||
main = 0;
|
||||
jQuery("#ap").undelegate("#groups", "click", false);
|
||||
jQuery("#groups").trigger("click");
|
||||
equals( main, 1, "Verify that the trigger happened correctly." );
|
||||
jQuery("#qunit-fixture").undelegate("#ap", "click");
|
||||
});
|
||||
|
||||
test("bind()/trigger()/unbind() on plain object", function() {
|
||||
|
@ -605,23 +688,23 @@ test("unbind(type)", function() {
|
|||
}
|
||||
|
||||
message = "unbind passing function";
|
||||
$elem.bind('error1', error).unbind('error1',error).triggerHandler('error1');
|
||||
$elem.bind("error1", error).unbind("error1", error).triggerHandler("error1");
|
||||
|
||||
message = "unbind all from event";
|
||||
$elem.bind('error1', error).unbind('error1').triggerHandler('error1');
|
||||
$elem.bind("error1", error).unbind("error1").triggerHandler("error1");
|
||||
|
||||
message = "unbind all";
|
||||
$elem.bind('error1', error).unbind().triggerHandler('error1');
|
||||
$elem.bind("error1", error).unbind().triggerHandler("error1");
|
||||
|
||||
message = "unbind many with function";
|
||||
$elem.bind('error1 error2',error)
|
||||
.unbind('error1 error2', error )
|
||||
.trigger('error1').triggerHandler('error2');
|
||||
$elem.bind("error1 error2",error)
|
||||
.unbind("error1 error2", error )
|
||||
.trigger("error1").triggerHandler("error2");
|
||||
|
||||
message = "unbind many"; // #3538
|
||||
$elem.bind('error1 error2',error)
|
||||
.unbind('error1 error2')
|
||||
.trigger('error1').triggerHandler('error2');
|
||||
$elem.bind("error1 error2", error)
|
||||
.unbind("error1 error2")
|
||||
.trigger("error1").triggerHandler("error2");
|
||||
|
||||
message = "unbind without a type or handler";
|
||||
$elem.bind("error1 error2.test",error)
|
||||
|
@ -637,28 +720,28 @@ test("unbind(eventObject)", function() {
|
|||
|
||||
function assert( expected ){
|
||||
num = 0;
|
||||
$elem.trigger('foo').triggerHandler('bar');
|
||||
$elem.trigger("foo").triggerHandler("bar");
|
||||
equals( num, expected, "Check the right handlers are triggered" );
|
||||
}
|
||||
|
||||
$elem
|
||||
// This handler shouldn't be unbound
|
||||
.bind('foo', function(){
|
||||
.bind("foo", function(){
|
||||
num += 1;
|
||||
})
|
||||
.bind('foo', function(e){
|
||||
.bind("foo", function(e){
|
||||
$elem.unbind( e )
|
||||
num += 2;
|
||||
})
|
||||
// Neither this one
|
||||
.bind('bar', function(){
|
||||
.bind("bar", function(){
|
||||
num += 4;
|
||||
});
|
||||
|
||||
assert( 7 );
|
||||
assert( 5 );
|
||||
|
||||
$elem.unbind('bar');
|
||||
$elem.unbind("bar");
|
||||
assert( 1 );
|
||||
|
||||
$elem.unbind();
|
||||
|
@ -685,24 +768,61 @@ test("hover()", function() {
|
|||
|
||||
test("mouseover triggers mouseenter", function() {
|
||||
expect(1);
|
||||
|
||||
|
||||
var count = 0,
|
||||
elem = jQuery("<a />");
|
||||
elem.mouseenter(function () {
|
||||
count++;
|
||||
});
|
||||
elem.trigger('mouseover');
|
||||
elem.trigger("mouseover");
|
||||
equals(count, 1, "make sure mouseover triggers a mouseenter" );
|
||||
|
||||
|
||||
elem.remove();
|
||||
});
|
||||
|
||||
test("withinElement implemented with jQuery.contains()", function() {
|
||||
|
||||
expect(1);
|
||||
|
||||
jQuery("#qunit-fixture").append('<div id="jc-outer"><div id="jc-inner"></div></div>');
|
||||
|
||||
jQuery("#jc-outer").bind("mouseenter mouseleave", function( event ) {
|
||||
|
||||
equal( this.id, "jc-outer", this.id + " " + event.type );
|
||||
|
||||
}).trigger("mouseenter");
|
||||
|
||||
jQuery("#jc-inner").trigger("mousenter");
|
||||
|
||||
jQuery("#jc-outer").unbind("mouseenter mouseleave").remove();
|
||||
jQuery("#jc-inner").remove();
|
||||
|
||||
});
|
||||
|
||||
test("mouseenter, mouseleave don't catch exceptions", function() {
|
||||
expect(2);
|
||||
|
||||
var elem = jQuery("#firstp").hover(function() { throw "an Exception"; });
|
||||
|
||||
try {
|
||||
elem.mouseenter();
|
||||
} catch (e) {
|
||||
equals( e, "an Exception", "mouseenter doesn't catch exceptions" );
|
||||
}
|
||||
|
||||
try {
|
||||
elem.mouseleave();
|
||||
} catch (e) {
|
||||
equals( e, "an Exception", "mouseleave doesn't catch exceptions" );
|
||||
}
|
||||
});
|
||||
|
||||
test("trigger() shortcuts", function() {
|
||||
expect(6);
|
||||
|
||||
var elem = jQuery('<li><a href="#">Change location</a></li>').prependTo('#firstUL');
|
||||
elem.find('a').bind('click', function() {
|
||||
var close = jQuery('spanx', this); // same with jQuery(this).find('span');
|
||||
var elem = jQuery("<li><a href='#'>Change location</a></li>").prependTo("#firstUL");
|
||||
elem.find("a").bind("click", function() {
|
||||
var close = jQuery("spanx", this); // same with jQuery(this).find("span");
|
||||
equals( close.length, 0, "Context element does not exist, length must be zero" );
|
||||
ok( !close[0], "Context element does not exist, direct access to element must return undefined" );
|
||||
return false;
|
||||
|
@ -716,48 +836,57 @@ test("trigger() shortcuts", function() {
|
|||
}).click();
|
||||
|
||||
var counter = 0;
|
||||
jQuery('#firstp')[0].onclick = function(event) {
|
||||
jQuery("#firstp")[0].onclick = function(event) {
|
||||
counter++;
|
||||
};
|
||||
jQuery('#firstp').click();
|
||||
jQuery("#firstp").click();
|
||||
equals( counter, 1, "Check that click, triggers onclick event handler also" );
|
||||
|
||||
var clickCounter = 0;
|
||||
jQuery('#simon1')[0].onclick = function(event) {
|
||||
jQuery("#simon1")[0].onclick = function(event) {
|
||||
clickCounter++;
|
||||
};
|
||||
jQuery('#simon1').click();
|
||||
jQuery("#simon1").click();
|
||||
equals( clickCounter, 1, "Check that click, triggers onclick event handler on an a tag also" );
|
||||
|
||||
elem = jQuery('<img />').load(function(){
|
||||
elem = jQuery("<img />").load(function(){
|
||||
ok( true, "Trigger the load event, using the shortcut .load() (#2819)");
|
||||
}).load();
|
||||
|
||||
// manually clean up detached elements
|
||||
elem.remove();
|
||||
|
||||
// test that special handlers do not blow up with VML elements (#7071)
|
||||
jQuery('<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v" />').appendTo('head');
|
||||
jQuery('<v:oval id="oval" style="width:100pt;height:75pt;" fillcolor="red"> </v:oval>').appendTo('#form');
|
||||
jQuery("#oval").click().keydown();
|
||||
});
|
||||
|
||||
test("trigger() bubbling", function() {
|
||||
expect(14);
|
||||
expect(17);
|
||||
|
||||
var doc = 0, html = 0, body = 0, main = 0, ap = 0;
|
||||
var win = 0, doc = 0, html = 0, body = 0, main = 0, ap = 0;
|
||||
|
||||
jQuery(window).bind("click", function(e){ win++; });
|
||||
jQuery(document).bind("click", function(e){ if ( e.target !== document) { doc++; } });
|
||||
jQuery("html").bind("click", function(e){ html++; });
|
||||
jQuery("body").bind("click", function(e){ body++; });
|
||||
jQuery("#main").bind("click", function(e){ main++; });
|
||||
jQuery("#qunit-fixture").bind("click", function(e){ main++; });
|
||||
jQuery("#ap").bind("click", function(){ ap++; return false; });
|
||||
|
||||
jQuery("html").trigger("click");
|
||||
equals( win, 1, "HTML bubble" );
|
||||
equals( doc, 1, "HTML bubble" );
|
||||
equals( html, 1, "HTML bubble" );
|
||||
|
||||
jQuery("body").trigger("click");
|
||||
equals( win, 2, "Body bubble" );
|
||||
equals( doc, 2, "Body bubble" );
|
||||
equals( html, 2, "Body bubble" );
|
||||
equals( body, 1, "Body bubble" );
|
||||
|
||||
jQuery("#main").trigger("click");
|
||||
jQuery("#qunit-fixture").trigger("click");
|
||||
equals( win, 3, "Main bubble" );
|
||||
equals( doc, 3, "Main bubble" );
|
||||
equals( html, 3, "Main bubble" );
|
||||
equals( body, 2, "Main bubble" );
|
||||
|
@ -772,11 +901,11 @@ test("trigger() bubbling", function() {
|
|||
|
||||
// manually clean up events from elements outside the fixture
|
||||
jQuery(document).unbind("click");
|
||||
jQuery("html, body, #main").unbind("click");
|
||||
jQuery("html, body, #qunit-fixture").unbind("click");
|
||||
});
|
||||
|
||||
test("trigger(type, [data], [fn])", function() {
|
||||
expect(14);
|
||||
expect(16);
|
||||
|
||||
var handler = function(event, a, b, c) {
|
||||
equals( event.type, "click", "check passed data" );
|
||||
|
@ -793,7 +922,24 @@ test("trigger(type, [data], [fn])", function() {
|
|||
ok( true, "Native call was triggered" );
|
||||
};
|
||||
|
||||
// Triggers handlrs and native
|
||||
|
||||
$elem.live('mouseenter', function(){
|
||||
ok( true, 'Trigger mouseenter bound by live' );
|
||||
});
|
||||
|
||||
$elem.live('mouseleave', function(){
|
||||
ok( true, 'Trigger mouseleave bound by live' );
|
||||
});
|
||||
|
||||
$elem.trigger('mouseenter');
|
||||
|
||||
$elem.trigger('mouseleave');
|
||||
|
||||
$elem.die('mouseenter');
|
||||
|
||||
$elem.die('mouseleave');
|
||||
|
||||
// Triggers handlrs and native
|
||||
// Trigger 5
|
||||
$elem.bind("click", handler).trigger("click", [1, "2", "abc"]);
|
||||
|
||||
|
@ -808,7 +954,7 @@ test("trigger(type, [data], [fn])", function() {
|
|||
|
||||
var pass = true;
|
||||
try {
|
||||
jQuery('#form input:first').hide().trigger('focus');
|
||||
jQuery("#form input:first").hide().trigger("focus");
|
||||
} catch(e) {
|
||||
pass = false;
|
||||
}
|
||||
|
@ -816,7 +962,7 @@ test("trigger(type, [data], [fn])", function() {
|
|||
|
||||
pass = true;
|
||||
try {
|
||||
jQuery('#main table:first').bind('test:test', function(){}).trigger('test:test');
|
||||
jQuery("#qunit-fixture table:first").bind("test:test", function(){}).trigger("test:test");
|
||||
} catch (e) {
|
||||
pass = false;
|
||||
}
|
||||
|
@ -854,8 +1000,8 @@ test("jQuery.Event.currentTarget", function(){
|
|||
test("trigger(eventObject, [data], [fn])", function() {
|
||||
expect(25);
|
||||
|
||||
var $parent = jQuery('<div id="par" />').hide().appendTo('body'),
|
||||
$child = jQuery('<p id="child">foo</p>').appendTo( $parent );
|
||||
var $parent = jQuery("<div id='par' />").hide().appendTo("body"),
|
||||
$child = jQuery("<p id='child'>foo</p>").appendTo( $parent );
|
||||
|
||||
var event = jQuery.Event("noNew");
|
||||
ok( event != window, "Instantiate jQuery.Event without the 'new' keyword" );
|
||||
|
@ -875,21 +1021,21 @@ test("trigger(eventObject, [data], [fn])", function() {
|
|||
equals( event.isPropagationStopped(), true, "Verify isPropagationStopped" );
|
||||
equals( event.isImmediatePropagationStopped(), true, "Verify isPropagationStopped" );
|
||||
|
||||
$parent.bind('foo',function(e){
|
||||
$parent.bind("foo",function(e){
|
||||
// Tries bubbling
|
||||
equals( e.type, 'foo', 'Verify event type when passed passing an event object' );
|
||||
equals( e.target.id, 'child', 'Verify event.target when passed passing an event object' );
|
||||
equals( e.currentTarget.id, 'par', 'Verify event.target when passed passing an event object' );
|
||||
equals( e.secret, 'boo!', 'Verify event object\'s custom attribute when passed passing an event object' );
|
||||
equals( e.type, "foo", "Verify event type when passed passing an event object" );
|
||||
equals( e.target.id, "child", "Verify event.target when passed passing an event object" );
|
||||
equals( e.currentTarget.id, "par", "Verify event.target when passed passing an event object" );
|
||||
equals( e.secret, "boo!", "Verify event object's custom attribute when passed passing an event object" );
|
||||
});
|
||||
|
||||
// test with an event object
|
||||
event = new jQuery.Event("foo");
|
||||
event.secret = 'boo!';
|
||||
event.secret = "boo!";
|
||||
$child.trigger(event);
|
||||
|
||||
// test with a literal object
|
||||
$child.trigger({type:'foo', secret:'boo!'});
|
||||
$child.trigger({type: "foo", secret: "boo!"});
|
||||
|
||||
$parent.unbind();
|
||||
|
||||
|
@ -897,9 +1043,9 @@ test("trigger(eventObject, [data], [fn])", function() {
|
|||
ok( false, "This assertion shouldn't be reached");
|
||||
}
|
||||
|
||||
$parent.bind('foo', error );
|
||||
$parent.bind("foo", error );
|
||||
|
||||
$child.bind('foo',function(e, a, b, c ){
|
||||
$child.bind("foo",function(e, a, b, c ){
|
||||
equals( arguments.length, 4, "Check arguments length");
|
||||
equals( a, 1, "Check first custom argument");
|
||||
equals( b, 2, "Check second custom argument");
|
||||
|
@ -917,29 +1063,50 @@ test("trigger(eventObject, [data], [fn])", function() {
|
|||
|
||||
// We should add this back in when we want to test the order
|
||||
// in which event handlers are iterated.
|
||||
//$child.bind('foo', error );
|
||||
//$child.bind("foo", error );
|
||||
|
||||
event = new jQuery.Event("foo");
|
||||
$child.trigger( event, [1,2,3] ).unbind();
|
||||
equals( event.result, "result", "Check event.result attribute");
|
||||
|
||||
// Will error if it bubbles
|
||||
$child.triggerHandler('foo');
|
||||
$child.triggerHandler("foo");
|
||||
|
||||
$child.unbind();
|
||||
$parent.unbind().remove();
|
||||
});
|
||||
|
||||
test("jQuery.Event( type, props )", function() {
|
||||
|
||||
expect(4);
|
||||
|
||||
var event = jQuery.Event( "keydown", { keyCode: 64 }),
|
||||
handler = function( event ) {
|
||||
ok( "keyCode" in event, "Special property 'keyCode' exists" );
|
||||
equal( event.keyCode, 64, "event.keyCode has explicit value '64'" );
|
||||
};
|
||||
|
||||
// Supports jQuery.Event implementation
|
||||
equal( event.type, "keydown", "Verify type" );
|
||||
|
||||
ok( "keyCode" in event, "Special 'keyCode' property exists" );
|
||||
|
||||
jQuery("body").bind( "keydown", handler ).trigger( event );
|
||||
|
||||
jQuery("body").unbind( "keydown" );
|
||||
|
||||
});
|
||||
|
||||
test("jQuery.Event.currentTarget", function(){
|
||||
expect(1);
|
||||
|
||||
var counter = 0,
|
||||
$elem = jQuery('<button>a</button>').click(function(e){
|
||||
$elem = jQuery("<button>a</button>").click(function(e){
|
||||
equals( e.currentTarget, this, "Check currentTarget on "+(counter++?"native":"fake") +" event" );
|
||||
});
|
||||
|
||||
// Fake event
|
||||
$elem.trigger('click');
|
||||
$elem.trigger("click");
|
||||
|
||||
// Cleanup
|
||||
$elem.unbind();
|
||||
|
@ -952,7 +1119,7 @@ test("toggle(Function, Function, ...)", function() {
|
|||
fn1 = function(e) { count++; },
|
||||
fn2 = function(e) { count--; },
|
||||
preventDefault = function(e) { e.preventDefault() },
|
||||
link = jQuery('#mark');
|
||||
link = jQuery("#mark");
|
||||
link.click(preventDefault).click().toggle(fn1, fn2).click().click().click().click().click();
|
||||
equals( count, 1, "Check for toggle(fn, fn)" );
|
||||
|
||||
|
@ -996,8 +1163,8 @@ test("toggle(Function, Function, ...)", function() {
|
|||
$div.click();
|
||||
equals( turn, 2, "Trying toggle with 3 functions, attempt 5 yields 2");
|
||||
|
||||
$div.unbind('click',fns[0]);
|
||||
var data = jQuery._data( $div[0], 'events' );
|
||||
$div.unbind("click",fns[0]);
|
||||
var data = jQuery._data( $div[0], "events" );
|
||||
ok( !data, "Unbinding one function from toggle unbinds them all");
|
||||
|
||||
// manually clean up detached elements
|
||||
|
@ -1112,12 +1279,12 @@ test(".live()/.die()", function() {
|
|||
jQuery("div").die("submit");
|
||||
|
||||
// Test binding with a different context
|
||||
var clicked = 0, container = jQuery('#main')[0];
|
||||
var clicked = 0, container = jQuery("#qunit-fixture")[0];
|
||||
jQuery("#foo", container).live("click", function(e){ clicked++; });
|
||||
jQuery("div").trigger('click');
|
||||
jQuery("#foo").trigger('click');
|
||||
jQuery("#main").trigger('click');
|
||||
jQuery("body").trigger('click');
|
||||
jQuery("div").trigger("click");
|
||||
jQuery("#foo").trigger("click");
|
||||
jQuery("#qunit-fixture").trigger("click");
|
||||
jQuery("body").trigger("click");
|
||||
equals( clicked, 2, "live with a context" );
|
||||
|
||||
// Make sure the event is actually stored on the context
|
||||
|
@ -1125,7 +1292,7 @@ test(".live()/.die()", function() {
|
|||
|
||||
// Test unbinding with a different context
|
||||
jQuery("#foo", container).die("click");
|
||||
jQuery("#foo").trigger('click');
|
||||
jQuery("#foo").trigger("click");
|
||||
equals( clicked, 2, "die with a context");
|
||||
|
||||
// Test binding with event data
|
||||
|
@ -1207,9 +1374,9 @@ test(".live()/.die()", function() {
|
|||
|
||||
// Make sure we don't loose the target by DOM modifications
|
||||
// after the bubble already reached the liveHandler
|
||||
var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
|
||||
var livec = 0, elemDiv = jQuery("#nothiddendivchild").html("<span></span>").get(0);
|
||||
|
||||
jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(''); });
|
||||
jQuery("#nothiddendivchild").live("click", function(e){ jQuery("#nothiddendivchild").html(""); });
|
||||
jQuery("#nothiddendivchild").live("click", function(e){ if(e.target) {livec++;} });
|
||||
|
||||
jQuery("#nothiddendiv span").click();
|
||||
|
@ -1224,20 +1391,20 @@ test(".live()/.die()", function() {
|
|||
var lived = 0, livee = 0;
|
||||
|
||||
// bind one pair in one order
|
||||
jQuery('span#liveSpan1 a').live('click', function(){ lived++; return false; });
|
||||
jQuery('span#liveSpan1').live('click', function(){ livee++; });
|
||||
jQuery("span#liveSpan1 a").live("click", function(){ lived++; return false; });
|
||||
jQuery("span#liveSpan1").live("click", function(){ livee++; });
|
||||
|
||||
jQuery('span#liveSpan1 a').click();
|
||||
jQuery("span#liveSpan1 a").click();
|
||||
equals( lived, 1, "Verify that only one first handler occurred." );
|
||||
equals( livee, 0, "Verify that second handler doesn't." );
|
||||
|
||||
// and one pair in inverse
|
||||
jQuery('span#liveSpan2').live('click', function(){ livee++; });
|
||||
jQuery('span#liveSpan2 a').live('click', function(){ lived++; return false; });
|
||||
jQuery("span#liveSpan2").live("click", function(){ livee++; });
|
||||
jQuery("span#liveSpan2 a").live("click", function(){ lived++; return false; });
|
||||
|
||||
lived = 0;
|
||||
livee = 0;
|
||||
jQuery('span#liveSpan2 a').click();
|
||||
jQuery("span#liveSpan2 a").click();
|
||||
equals( lived, 1, "Verify that only one first handler occurred." );
|
||||
equals( livee, 0, "Verify that second handler doesn't." );
|
||||
|
||||
|
@ -1248,15 +1415,15 @@ test(".live()/.die()", function() {
|
|||
jQuery("span#liveSpan2").die("click");
|
||||
|
||||
// Test this, target and currentTarget are correct
|
||||
jQuery('span#liveSpan1').live('click', function(e){
|
||||
equals( this.id, 'liveSpan1', 'Check the this within a live handler' );
|
||||
equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a live handler' );
|
||||
equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a live handler' );
|
||||
jQuery("span#liveSpan1").live("click", function(e){
|
||||
equals( this.id, "liveSpan1", "Check the this within a live handler" );
|
||||
equals( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a live handler" );
|
||||
equals( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a live handler" );
|
||||
});
|
||||
|
||||
jQuery('span#liveSpan1 a').click();
|
||||
jQuery("span#liveSpan1 a").click();
|
||||
|
||||
jQuery('span#liveSpan1').die('click');
|
||||
jQuery("span#liveSpan1").die("click");
|
||||
|
||||
// Work with deep selectors
|
||||
livee = 0;
|
||||
|
@ -1639,20 +1806,20 @@ test(".delegate()/.undelegate()", function() {
|
|||
jQuery("#body").undelegate("div", "submit");
|
||||
|
||||
// Test binding with a different context
|
||||
var clicked = 0, container = jQuery('#main')[0];
|
||||
jQuery("#main").delegate("#foo", "click", function(e){ clicked++; });
|
||||
jQuery("div").trigger('click');
|
||||
jQuery("#foo").trigger('click');
|
||||
jQuery("#main").trigger('click');
|
||||
jQuery("body").trigger('click');
|
||||
var clicked = 0, container = jQuery("#qunit-fixture")[0];
|
||||
jQuery("#qunit-fixture").delegate("#foo", "click", function(e){ clicked++; });
|
||||
jQuery("div").trigger("click");
|
||||
jQuery("#foo").trigger("click");
|
||||
jQuery("#qunit-fixture").trigger("click");
|
||||
jQuery("body").trigger("click");
|
||||
equals( clicked, 2, "delegate with a context" );
|
||||
|
||||
// Make sure the event is actually stored on the context
|
||||
ok( jQuery._data(container, "events").live, "delegate with a context" );
|
||||
|
||||
// Test unbinding with a different context
|
||||
jQuery("#main").undelegate("#foo", "click");
|
||||
jQuery("#foo").trigger('click');
|
||||
jQuery("#qunit-fixture").undelegate("#foo", "click");
|
||||
jQuery("#foo").trigger("click");
|
||||
equals( clicked, 2, "undelegate with a context");
|
||||
|
||||
// Test binding with event data
|
||||
|
@ -1738,9 +1905,9 @@ test(".delegate()/.undelegate()", function() {
|
|||
|
||||
// Make sure we don't loose the target by DOM modifications
|
||||
// after the bubble already reached the liveHandler
|
||||
var livec = 0, elemDiv = jQuery("#nothiddendivchild").html('<span></span>').get(0);
|
||||
var livec = 0, elemDiv = jQuery("#nothiddendivchild").html("<span></span>").get(0);
|
||||
|
||||
jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(''); });
|
||||
jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ jQuery("#nothiddendivchild").html(""); });
|
||||
jQuery("#body").delegate("#nothiddendivchild", "click", function(e){ if(e.target) {livec++;} });
|
||||
|
||||
jQuery("#nothiddendiv span").click();
|
||||
|
@ -1755,20 +1922,20 @@ test(".delegate()/.undelegate()", function() {
|
|||
var lived = 0, livee = 0;
|
||||
|
||||
// bind one pair in one order
|
||||
jQuery("#body").delegate('span#liveSpan1 a', 'click', function(){ lived++; return false; });
|
||||
jQuery("#body").delegate('span#liveSpan1', 'click', function(){ livee++; });
|
||||
jQuery("#body").delegate("span#liveSpan1 a", "click", function(){ lived++; return false; });
|
||||
jQuery("#body").delegate("span#liveSpan1", "click", function(){ livee++; });
|
||||
|
||||
jQuery('span#liveSpan1 a').click();
|
||||
jQuery("span#liveSpan1 a").click();
|
||||
equals( lived, 1, "Verify that only one first handler occurred." );
|
||||
equals( livee, 0, "Verify that second handler doesn't." );
|
||||
|
||||
// and one pair in inverse
|
||||
jQuery("#body").delegate('span#liveSpan2', 'click', function(){ livee++; });
|
||||
jQuery("#body").delegate('span#liveSpan2 a', 'click', function(){ lived++; return false; });
|
||||
jQuery("#body").delegate("span#liveSpan2", "click", function(){ livee++; });
|
||||
jQuery("#body").delegate("span#liveSpan2 a", "click", function(){ lived++; return false; });
|
||||
|
||||
lived = 0;
|
||||
livee = 0;
|
||||
jQuery('span#liveSpan2 a').click();
|
||||
jQuery("span#liveSpan2 a").click();
|
||||
equals( lived, 1, "Verify that only one first handler occurred." );
|
||||
equals( livee, 0, "Verify that second handler doesn't." );
|
||||
|
||||
|
@ -1776,15 +1943,15 @@ test(".delegate()/.undelegate()", function() {
|
|||
jQuery("#body").undelegate("click");
|
||||
|
||||
// Test this, target and currentTarget are correct
|
||||
jQuery("#body").delegate('span#liveSpan1', 'click', function(e){
|
||||
equals( this.id, 'liveSpan1', 'Check the this within a delegate handler' );
|
||||
equals( e.currentTarget.id, 'liveSpan1', 'Check the event.currentTarget within a delegate handler' );
|
||||
equals( e.target.nodeName.toUpperCase(), 'A', 'Check the event.target within a delegate handler' );
|
||||
jQuery("#body").delegate("span#liveSpan1", "click", function(e){
|
||||
equals( this.id, "liveSpan1", "Check the this within a delegate handler" );
|
||||
equals( e.currentTarget.id, "liveSpan1", "Check the event.currentTarget within a delegate handler" );
|
||||
equals( e.target.nodeName.toUpperCase(), "A", "Check the event.target within a delegate handler" );
|
||||
});
|
||||
|
||||
jQuery('span#liveSpan1 a').click();
|
||||
jQuery("span#liveSpan1 a").click();
|
||||
|
||||
jQuery("#body").undelegate('span#liveSpan1', 'click');
|
||||
jQuery("#body").undelegate("span#liveSpan1", "click");
|
||||
|
||||
// Work with deep selectors
|
||||
livee = 0;
|
||||
|
@ -1956,16 +2123,37 @@ test("delegate with submit", function() {
|
|||
jQuery(document).undelegate();
|
||||
});
|
||||
|
||||
test("undelegate() with only namespaces", function() {
|
||||
expect(2);
|
||||
|
||||
var $delegate = jQuery("#liveHandlerOrder"),
|
||||
count = 0;
|
||||
|
||||
$delegate.delegate("a", "click.ns", function(e) {
|
||||
count++;
|
||||
});
|
||||
|
||||
jQuery("a", $delegate).eq(0).trigger("click.ns");
|
||||
|
||||
equals( count, 1, "delegated click.ns");
|
||||
|
||||
$delegate.undelegate(".ns");
|
||||
|
||||
jQuery("a", $delegate).eq(1).trigger("click.ns");
|
||||
|
||||
equals( count, 1, "no more .ns after undelegate");
|
||||
});
|
||||
|
||||
test("Non DOM element events", function() {
|
||||
expect(1);
|
||||
|
||||
var o = {};
|
||||
|
||||
jQuery(o).bind('nonelementobj', function(e) {
|
||||
jQuery(o).bind("nonelementobj", function(e) {
|
||||
ok( true, "Event on non-DOM object triggered" );
|
||||
});
|
||||
|
||||
jQuery(o).trigger('nonelementobj');
|
||||
jQuery(o).trigger("nonelementobj");
|
||||
});
|
||||
|
||||
test("window resize", function() {
|
||||
|
@ -1982,8 +2170,8 @@ test("window resize", function() {
|
|||
|
||||
test("focusin bubbles", function() {
|
||||
expect(5);
|
||||
|
||||
var input = jQuery( '<input type="text" />' ).prependTo( "body" ),
|
||||
|
||||
var input = jQuery( "<input type='text' />" ).prependTo( "body" ),
|
||||
order = 0;
|
||||
|
||||
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
|
||||
|
@ -1996,12 +2184,12 @@ test("focusin bubbles", function() {
|
|||
|
||||
// DOM focus method
|
||||
input[0].focus();
|
||||
|
||||
|
||||
// To make the next focus test work, we need to take focus off the input.
|
||||
// This will fire another focusin event, so set order to reflect that.
|
||||
order = 1;
|
||||
jQuery("#text1")[0].focus();
|
||||
|
||||
|
||||
// jQuery trigger, which calls DOM focus
|
||||
order = 0;
|
||||
input.trigger( "focus" );
|
||||
|
@ -2010,15 +2198,94 @@ test("focusin bubbles", function() {
|
|||
jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
|
||||
});
|
||||
|
||||
/*
|
||||
test("jQuery(function($) {})", function() {
|
||||
stop();
|
||||
jQuery(function($) {
|
||||
equals(jQuery, $, "ready doesn't provide an event object, instead it provides a reference to the jQuery function, see http://docs.jquery.com/Events/ready#fn");
|
||||
start();
|
||||
});
|
||||
test("custom events with colons (#3533, #8272)", function() {
|
||||
expect(1);
|
||||
|
||||
var tab = jQuery("<table><tr><td>trigger</td></tr></table>").appendTo("body");
|
||||
try {
|
||||
tab.trigger("back:forth");
|
||||
ok( true, "colon events don't throw" );
|
||||
} catch ( e ) {
|
||||
ok( false, "colon events die" );
|
||||
};
|
||||
tab.remove();
|
||||
|
||||
});
|
||||
|
||||
(function(){
|
||||
// This code must be run before DOM ready!
|
||||
var notYetReady, noEarlyExecution,
|
||||
order = [],
|
||||
args = {};
|
||||
|
||||
notYetReady = !jQuery.isReady;
|
||||
|
||||
test("jQuery.isReady", function() {
|
||||
expect(2);
|
||||
|
||||
equals(notYetReady, true, "jQuery.isReady should not be true before DOM ready");
|
||||
equals(jQuery.isReady, true, "jQuery.isReady should be true once DOM is ready");
|
||||
});
|
||||
|
||||
// Create an event handler.
|
||||
function makeHandler( testId ) {
|
||||
// When returned function is executed, push testId onto `order` array
|
||||
// to ensure execution order. Also, store event handler arg to ensure
|
||||
// the correct arg is being passed into the event handler.
|
||||
return function( arg ) {
|
||||
order.push(testId);
|
||||
args[testId] = arg;
|
||||
};
|
||||
}
|
||||
|
||||
// Bind to the ready event in every possible way.
|
||||
jQuery(makeHandler("a"));
|
||||
jQuery(document).ready(makeHandler("b"));
|
||||
jQuery(document).bind("ready.readytest", makeHandler("c"));
|
||||
|
||||
// Do it twice, just to be sure.
|
||||
jQuery(makeHandler("d"));
|
||||
jQuery(document).ready(makeHandler("e"));
|
||||
jQuery(document).bind("ready.readytest", makeHandler("f"));
|
||||
|
||||
noEarlyExecution = order.length == 0;
|
||||
|
||||
// This assumes that QUnit tests are run on DOM ready!
|
||||
test("jQuery ready", function() {
|
||||
expect(10);
|
||||
|
||||
ok(noEarlyExecution, "Handlers bound to DOM ready should not execute before DOM ready");
|
||||
|
||||
// Ensure execution order.
|
||||
same(order, ["a", "b", "d", "e", "c", "f"], "Bound DOM ready handlers should execute in bind-order, but those bound with jQuery(document).bind( 'ready', fn ) will always execute last");
|
||||
|
||||
// Ensure handler argument is correct.
|
||||
equals(args.a, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
|
||||
equals(args.b, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
|
||||
ok(args.c instanceof jQuery.Event, "Argument passed to fn in jQuery(document).bind( 'ready', fn ) should be an event object");
|
||||
|
||||
order = [];
|
||||
|
||||
// Now that the ready event has fired, again bind to the ready event
|
||||
// in every possible way. These event handlers should execute immediately.
|
||||
jQuery(makeHandler("g"));
|
||||
equals(order.pop(), "g", "Event handler should execute immediately");
|
||||
equals(args.g, jQuery, "Argument passed to fn in jQuery( fn ) should be jQuery");
|
||||
|
||||
jQuery(document).ready(makeHandler("h"));
|
||||
equals(order.pop(), "h", "Event handler should execute immediately");
|
||||
equals(args.h, jQuery, "Argument passed to fn in jQuery(document).ready( fn ) should be jQuery");
|
||||
|
||||
jQuery(document).bind("ready.readytest", makeHandler("never"));
|
||||
equals(order.length, 0, "Event handler should never execute since DOM ready has already passed");
|
||||
|
||||
// Cleanup.
|
||||
jQuery(document).unbind("ready.readytest");
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
/*
|
||||
test("event properties", function() {
|
||||
stop();
|
||||
jQuery("#simon1").click(function(event) {
|
||||
|
@ -2027,3 +2294,4 @@ test("event properties", function() {
|
|||
}).click();
|
||||
});
|
||||
*/
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -20,7 +20,7 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
|
|||
// this insures that the results will be wrong
|
||||
// if the offset method is using the scroll offset
|
||||
// of the parent window
|
||||
var forceScroll = jQuery('<div>', { width: 2000, height: 2000 }).appendTo('body');
|
||||
var forceScroll = jQuery("<div>", { width: 2000, height: 2000 }).appendTo("body");
|
||||
window.scrollTo(200, 200);
|
||||
|
||||
if ( document.documentElement.scrollTop || document.body.scrollTop ) {
|
||||
|
@ -31,7 +31,7 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
|
|||
|
||||
// get offset
|
||||
tests = [
|
||||
{ id: '#absolute-1', top: 1, left: 1 }
|
||||
{ id: "#absolute-1", top: 1, left: 1 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
|
||||
|
@ -41,7 +41,7 @@ testoffset("absolute"/* in iframe */, function($, iframe) {
|
|||
|
||||
// get position
|
||||
tests = [
|
||||
{ id: '#absolute-1', top: 0, left: 0 }
|
||||
{ id: "#absolute-1", top: 0, left: 0 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
|
||||
|
@ -56,10 +56,10 @@ testoffset("absolute", function( jQuery ) {
|
|||
|
||||
// get offset tests
|
||||
var tests = [
|
||||
{ id: '#absolute-1', top: 1, left: 1 },
|
||||
{ id: '#absolute-1-1', top: 5, left: 5 },
|
||||
{ id: '#absolute-1-1-1', top: 9, left: 9 },
|
||||
{ id: '#absolute-2', top: 20, left: 20 }
|
||||
{ id: "#absolute-1", top: 1, left: 1 },
|
||||
{ id: "#absolute-1-1", top: 5, left: 5 },
|
||||
{ id: "#absolute-1-1-1", top: 9, left: 9 },
|
||||
{ id: "#absolute-2", top: 20, left: 20 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
|
||||
|
@ -69,10 +69,10 @@ testoffset("absolute", function( jQuery ) {
|
|||
|
||||
// get position
|
||||
tests = [
|
||||
{ id: '#absolute-1', top: 0, left: 0 },
|
||||
{ id: '#absolute-1-1', top: 1, left: 1 },
|
||||
{ id: '#absolute-1-1-1', top: 1, left: 1 },
|
||||
{ id: '#absolute-2', top: 19, left: 19 }
|
||||
{ id: "#absolute-1", top: 0, left: 0 },
|
||||
{ id: "#absolute-1-1", top: 1, left: 1 },
|
||||
{ id: "#absolute-1-1-1", top: 1, left: 1 },
|
||||
{ id: "#absolute-2", top: 19, left: 19 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
|
||||
|
@ -80,29 +80,29 @@ testoffset("absolute", function( jQuery ) {
|
|||
});
|
||||
|
||||
// test #5781
|
||||
var offset = jQuery( '#positionTest' ).offset({ top: 10, left: 10 }).offset();
|
||||
var offset = jQuery( "#positionTest" ).offset({ top: 10, left: 10 }).offset();
|
||||
equals( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." )
|
||||
equals( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." )
|
||||
|
||||
|
||||
// set offset
|
||||
tests = [
|
||||
{ id: '#absolute-2', top: 30, left: 30 },
|
||||
{ id: '#absolute-2', top: 10, left: 10 },
|
||||
{ id: '#absolute-2', top: -1, left: -1 },
|
||||
{ id: '#absolute-2', top: 19, left: 19 },
|
||||
{ id: '#absolute-1-1-1', top: 15, left: 15 },
|
||||
{ id: '#absolute-1-1-1', top: 5, left: 5 },
|
||||
{ id: '#absolute-1-1-1', top: -1, left: -1 },
|
||||
{ id: '#absolute-1-1-1', top: 9, left: 9 },
|
||||
{ id: '#absolute-1-1', top: 10, left: 10 },
|
||||
{ id: '#absolute-1-1', top: 0, left: 0 },
|
||||
{ id: '#absolute-1-1', top: -1, left: -1 },
|
||||
{ id: '#absolute-1-1', top: 5, left: 5 },
|
||||
{ id: '#absolute-1', top: 2, left: 2 },
|
||||
{ id: '#absolute-1', top: 0, left: 0 },
|
||||
{ id: '#absolute-1', top: -1, left: -1 },
|
||||
{ id: '#absolute-1', top: 1, left: 1 }
|
||||
{ id: "#absolute-2", top: 30, left: 30 },
|
||||
{ id: "#absolute-2", top: 10, left: 10 },
|
||||
{ id: "#absolute-2", top: -1, left: -1 },
|
||||
{ id: "#absolute-2", top: 19, left: 19 },
|
||||
{ id: "#absolute-1-1-1", top: 15, left: 15 },
|
||||
{ id: "#absolute-1-1-1", top: 5, left: 5 },
|
||||
{ id: "#absolute-1-1-1", top: -1, left: -1 },
|
||||
{ id: "#absolute-1-1-1", top: 9, left: 9 },
|
||||
{ id: "#absolute-1-1", top: 10, left: 10 },
|
||||
{ id: "#absolute-1-1", top: 0, left: 0 },
|
||||
{ id: "#absolute-1-1", top: -1, left: -1 },
|
||||
{ id: "#absolute-1-1", top: 5, left: 5 },
|
||||
{ id: "#absolute-1", top: 2, left: 2 },
|
||||
{ id: "#absolute-1", top: 0, left: 0 },
|
||||
{ id: "#absolute-1", top: -1, left: -1 },
|
||||
{ id: "#absolute-1", top: 1, left: 1 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
jQuery( this.id ).offset({ top: this.top, left: this.left });
|
||||
|
@ -144,9 +144,9 @@ testoffset("relative", function( jQuery ) {
|
|||
|
||||
// get offset
|
||||
var tests = [
|
||||
{ id: '#relative-1', top: ie ? 6 : 7, left: 7 },
|
||||
{ id: '#relative-1-1', top: ie ? 13 : 15, left: 15 },
|
||||
{ id: '#relative-2', top: ie ? 141 : 142, left: 27 }
|
||||
{ id: "#relative-1", top: ie ? 6 : 7, left: 7 },
|
||||
{ id: "#relative-1-1", top: ie ? 13 : 15, left: 15 },
|
||||
{ id: "#relative-2", top: ie ? 141 : 142, left: 27 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
|
||||
|
@ -156,9 +156,9 @@ testoffset("relative", function( jQuery ) {
|
|||
|
||||
// get position
|
||||
tests = [
|
||||
{ id: '#relative-1', top: ie ? 5 : 6, left: 6 },
|
||||
{ id: '#relative-1-1', top: ie ? 4 : 5, left: 5 },
|
||||
{ id: '#relative-2', top: ie ? 140 : 141, left: 26 }
|
||||
{ id: "#relative-1", top: ie ? 5 : 6, left: 6 },
|
||||
{ id: "#relative-1-1", top: ie ? 4 : 5, left: 5 },
|
||||
{ id: "#relative-2", top: ie ? 140 : 141, left: 26 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
|
||||
|
@ -168,18 +168,18 @@ testoffset("relative", function( jQuery ) {
|
|||
|
||||
// set offset
|
||||
tests = [
|
||||
{ id: '#relative-2', top: 200, left: 50 },
|
||||
{ id: '#relative-2', top: 100, left: 10 },
|
||||
{ id: '#relative-2', top: -5, left: -5 },
|
||||
{ id: '#relative-2', top: 142, left: 27 },
|
||||
{ id: '#relative-1-1', top: 100, left: 100 },
|
||||
{ id: '#relative-1-1', top: 5, left: 5 },
|
||||
{ id: '#relative-1-1', top: -1, left: -1 },
|
||||
{ id: '#relative-1-1', top: 15, left: 15 },
|
||||
{ id: '#relative-1', top: 100, left: 100 },
|
||||
{ id: '#relative-1', top: 0, left: 0 },
|
||||
{ id: '#relative-1', top: -1, left: -1 },
|
||||
{ id: '#relative-1', top: 7, left: 7 }
|
||||
{ id: "#relative-2", top: 200, left: 50 },
|
||||
{ id: "#relative-2", top: 100, left: 10 },
|
||||
{ id: "#relative-2", top: -5, left: -5 },
|
||||
{ id: "#relative-2", top: 142, left: 27 },
|
||||
{ id: "#relative-1-1", top: 100, left: 100 },
|
||||
{ id: "#relative-1-1", top: 5, left: 5 },
|
||||
{ id: "#relative-1-1", top: -1, left: -1 },
|
||||
{ id: "#relative-1-1", top: 15, left: 15 },
|
||||
{ id: "#relative-1", top: 100, left: 100 },
|
||||
{ id: "#relative-1", top: 0, left: 0 },
|
||||
{ id: "#relative-1", top: -1, left: -1 },
|
||||
{ id: "#relative-1", top: 7, left: 7 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
jQuery( this.id ).offset({ top: this.top, left: this.left });
|
||||
|
@ -205,10 +205,10 @@ testoffset("static", function( jQuery ) {
|
|||
|
||||
// get offset
|
||||
var tests = [
|
||||
{ id: '#static-1', top: ie ? 6 : 7, left: 7 },
|
||||
{ id: '#static-1-1', top: ie ? 13 : 15, left: 15 },
|
||||
{ id: '#static-1-1-1', top: ie ? 20 : 23, left: 23 },
|
||||
{ id: '#static-2', top: ie ? 121 : 122, left: 7 }
|
||||
{ id: "#static-1", top: ie ? 6 : 7, left: 7 },
|
||||
{ id: "#static-1-1", top: ie ? 13 : 15, left: 15 },
|
||||
{ id: "#static-1-1-1", top: ie ? 20 : 23, left: 23 },
|
||||
{ id: "#static-2", top: ie ? 121 : 122, left: 7 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
|
||||
|
@ -218,10 +218,10 @@ testoffset("static", function( jQuery ) {
|
|||
|
||||
// get position
|
||||
tests = [
|
||||
{ id: '#static-1', top: ie ? 5 : 6, left: 6 },
|
||||
{ id: '#static-1-1', top: ie ? 12 : 14, left: 14 },
|
||||
{ id: '#static-1-1-1', top: ie ? 19 : 22, left: 22 },
|
||||
{ id: '#static-2', top: ie ? 120 : 121, left: 6 }
|
||||
{ id: "#static-1", top: ie ? 5 : 6, left: 6 },
|
||||
{ id: "#static-1-1", top: ie ? 12 : 14, left: 14 },
|
||||
{ id: "#static-1-1-1", top: ie ? 19 : 22, left: 22 },
|
||||
{ id: "#static-2", top: ie ? 120 : 121, left: 6 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.top + "').position().top" );
|
||||
|
@ -231,22 +231,22 @@ testoffset("static", function( jQuery ) {
|
|||
|
||||
// set offset
|
||||
tests = [
|
||||
{ id: '#static-2', top: 200, left: 200 },
|
||||
{ id: '#static-2', top: 100, left: 100 },
|
||||
{ id: '#static-2', top: -2, left: -2 },
|
||||
{ id: '#static-2', top: 121, left: 6 },
|
||||
{ id: '#static-1-1-1', top: 50, left: 50 },
|
||||
{ id: '#static-1-1-1', top: 10, left: 10 },
|
||||
{ id: '#static-1-1-1', top: -1, left: -1 },
|
||||
{ id: '#static-1-1-1', top: 22, left: 22 },
|
||||
{ id: '#static-1-1', top: 25, left: 25 },
|
||||
{ id: '#static-1-1', top: 10, left: 10 },
|
||||
{ id: '#static-1-1', top: -3, left: -3 },
|
||||
{ id: '#static-1-1', top: 14, left: 14 },
|
||||
{ id: '#static-1', top: 30, left: 30 },
|
||||
{ id: '#static-1', top: 2, left: 2 },
|
||||
{ id: '#static-1', top: -2, left: -2 },
|
||||
{ id: '#static-1', top: 7, left: 7 }
|
||||
{ id: "#static-2", top: 200, left: 200 },
|
||||
{ id: "#static-2", top: 100, left: 100 },
|
||||
{ id: "#static-2", top: -2, left: -2 },
|
||||
{ id: "#static-2", top: 121, left: 6 },
|
||||
{ id: "#static-1-1-1", top: 50, left: 50 },
|
||||
{ id: "#static-1-1-1", top: 10, left: 10 },
|
||||
{ id: "#static-1-1-1", top: -1, left: -1 },
|
||||
{ id: "#static-1-1-1", top: 22, left: 22 },
|
||||
{ id: "#static-1-1", top: 25, left: 25 },
|
||||
{ id: "#static-1-1", top: 10, left: 10 },
|
||||
{ id: "#static-1-1", top: -3, left: -3 },
|
||||
{ id: "#static-1-1", top: 14, left: 14 },
|
||||
{ id: "#static-1", top: 30, left: 30 },
|
||||
{ id: "#static-1", top: 2, left: 2 },
|
||||
{ id: "#static-1", top: -2, left: -2 },
|
||||
{ id: "#static-1", top: 7, left: 7 }
|
||||
];
|
||||
jQuery.each( tests, function() {
|
||||
jQuery( this.id ).offset({ top: this.top, left: this.left });
|
||||
|
@ -270,8 +270,8 @@ testoffset("fixed", function( jQuery ) {
|
|||
jQuery.offset.initialize();
|
||||
|
||||
var tests = [
|
||||
{ id: '#fixed-1', top: 1001, left: 1001 },
|
||||
{ id: '#fixed-2', top: 1021, left: 1021 }
|
||||
{ id: "#fixed-1", top: 1001, left: 1001 },
|
||||
{ id: "#fixed-2", top: 1021, left: 1021 }
|
||||
];
|
||||
|
||||
jQuery.each( tests, function() {
|
||||
|
@ -284,18 +284,18 @@ testoffset("fixed", function( jQuery ) {
|
|||
equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
|
||||
} else {
|
||||
// need to have same number of assertions
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
}
|
||||
});
|
||||
|
||||
tests = [
|
||||
{ id: '#fixed-1', top: 100, left: 100 },
|
||||
{ id: '#fixed-1', top: 0, left: 0 },
|
||||
{ id: '#fixed-1', top: -4, left: -4 },
|
||||
{ id: '#fixed-2', top: 200, left: 200 },
|
||||
{ id: '#fixed-2', top: 0, left: 0 },
|
||||
{ id: '#fixed-2', top: -5, left: -5 }
|
||||
{ id: "#fixed-1", top: 100, left: 100 },
|
||||
{ id: "#fixed-1", top: 0, left: 0 },
|
||||
{ id: "#fixed-1", top: -4, left: -4 },
|
||||
{ id: "#fixed-2", top: 200, left: 200 },
|
||||
{ id: "#fixed-2", top: 0, left: 0 },
|
||||
{ id: "#fixed-2", top: -5, left: -5 }
|
||||
];
|
||||
|
||||
jQuery.each( tests, function() {
|
||||
|
@ -314,58 +314,58 @@ testoffset("fixed", function( jQuery ) {
|
|||
equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
|
||||
} else {
|
||||
// need to have same number of assertions
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
}
|
||||
});
|
||||
|
||||
// Bug 8316
|
||||
var $noTopLeft = jQuery('#fixed-no-top-left');
|
||||
var $noTopLeft = jQuery("#fixed-no-top-left");
|
||||
if ( jQuery.offset.supportsFixedPosition ) {
|
||||
equals( $noTopLeft.offset().top, 1007, "Check offset top for fixed element with no top set" );
|
||||
equals( $noTopLeft.offset().left, 1007, "Check offset left for fixed element with no left set" );
|
||||
} else {
|
||||
// need to have same number of assertions
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, 'Fixed position is not supported' );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
ok( true, "Fixed position is not supported" );
|
||||
}
|
||||
});
|
||||
|
||||
testoffset("table", function( jQuery ) {
|
||||
expect(4);
|
||||
|
||||
equals( jQuery('#table-1').offset().top, 6, "jQuery('#table-1').offset().top" );
|
||||
equals( jQuery('#table-1').offset().left, 6, "jQuery('#table-1').offset().left" );
|
||||
equals( jQuery("#table-1").offset().top, 6, "jQuery('#table-1').offset().top" );
|
||||
equals( jQuery("#table-1").offset().left, 6, "jQuery('#table-1').offset().left" );
|
||||
|
||||
equals( jQuery('#th-1').offset().top, 10, "jQuery('#th-1').offset().top" );
|
||||
equals( jQuery('#th-1').offset().left, 10, "jQuery('#th-1').offset().left" );
|
||||
equals( jQuery("#th-1").offset().top, 10, "jQuery('#th-1').offset().top" );
|
||||
equals( jQuery("#th-1").offset().left, 10, "jQuery('#th-1').offset().left" );
|
||||
});
|
||||
|
||||
testoffset("scroll", function( jQuery, win ) {
|
||||
expect(16);
|
||||
expect(22);
|
||||
|
||||
var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8;
|
||||
|
||||
// IE is collapsing the top margin of 1px
|
||||
equals( jQuery('#scroll-1').offset().top, ie ? 6 : 7, "jQuery('#scroll-1').offset().top" );
|
||||
equals( jQuery('#scroll-1').offset().left, 7, "jQuery('#scroll-1').offset().left" );
|
||||
equals( jQuery("#scroll-1").offset().top, ie ? 6 : 7, "jQuery('#scroll-1').offset().top" );
|
||||
equals( jQuery("#scroll-1").offset().left, 7, "jQuery('#scroll-1').offset().left" );
|
||||
|
||||
// IE is collapsing the top margin of 1px
|
||||
equals( jQuery('#scroll-1-1').offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" );
|
||||
equals( jQuery('#scroll-1-1').offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
|
||||
equals( jQuery("#scroll-1-1").offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" );
|
||||
equals( jQuery("#scroll-1-1").offset().left, 11, "jQuery('#scroll-1-1').offset().left" );
|
||||
|
||||
|
||||
// scroll offset tests .scrollTop/Left
|
||||
equals( jQuery('#scroll-1').scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
|
||||
equals( jQuery('#scroll-1').scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
|
||||
equals( jQuery("#scroll-1").scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" );
|
||||
equals( jQuery("#scroll-1").scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" );
|
||||
|
||||
equals( jQuery('#scroll-1-1').scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
|
||||
equals( jQuery('#scroll-1-1').scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
|
||||
equals( jQuery("#scroll-1-1").scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" );
|
||||
equals( jQuery("#scroll-1-1").scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" );
|
||||
|
||||
// equals( jQuery('body').scrollTop(), 0, "jQuery('body').scrollTop()" );
|
||||
// equals( jQuery('body').scrollLeft(), 0, "jQuery('body').scrollTop()" );
|
||||
// equals( jQuery("body").scrollTop(), 0, "jQuery("body").scrollTop()" );
|
||||
// equals( jQuery("body").scrollLeft(), 0, "jQuery("body").scrollTop()" );
|
||||
|
||||
win.name = "test";
|
||||
|
||||
|
@ -390,13 +390,21 @@ testoffset("scroll", function( jQuery, win ) {
|
|||
equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
|
||||
equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
|
||||
equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
|
||||
|
||||
// Tests scrollTop/Left with empty jquery objects
|
||||
notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
|
||||
notEqual( jQuery().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
|
||||
notEqual( jQuery().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
|
||||
notEqual( jQuery().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
|
||||
strictEqual( jQuery().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
|
||||
strictEqual( jQuery().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
|
||||
});
|
||||
|
||||
testoffset("body", function( jQuery ) {
|
||||
expect(2);
|
||||
|
||||
equals( jQuery('body').offset().top, 1, "jQuery('#body').offset().top" );
|
||||
equals( jQuery('body').offset().left, 1, "jQuery('#body').offset().left" );
|
||||
equals( jQuery("body").offset().top, 1, "jQuery('#body').offset().top" );
|
||||
equals( jQuery("body").offset().left, 1, "jQuery('#body').offset().left" );
|
||||
});
|
||||
|
||||
test("Chaining offset(coords) returns jQuery object", function() {
|
||||
|
@ -433,7 +441,33 @@ test("offsetParent", function(){
|
|||
equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
|
||||
});
|
||||
|
||||
function testoffset( name, fn ) {
|
||||
test("fractions (see #7730 and #7885)", function() {
|
||||
expect(2);
|
||||
|
||||
jQuery('body').append('<div id="fractions"/>');
|
||||
|
||||
var expected = { top: 1000, left: 1000 };
|
||||
var div = jQuery('#fractions');
|
||||
|
||||
div.css({
|
||||
position: 'absolute',
|
||||
left: '1000.7432222px',
|
||||
top: '1000.532325px',
|
||||
width: 100,
|
||||
height: 100
|
||||
});
|
||||
|
||||
div.offset(expected);
|
||||
|
||||
var result = div.offset();
|
||||
|
||||
equals( result.top, expected.top, "Check top" );
|
||||
equals( result.left, expected.left, "Check left" );
|
||||
|
||||
div.remove();
|
||||
});
|
||||
|
||||
function testoffset(name, fn) {
|
||||
|
||||
test(name, function() {
|
||||
// pause execution for now
|
||||
|
@ -456,10 +490,10 @@ function testoffset( name, fn ) {
|
|||
});
|
||||
|
||||
function loadFixture() {
|
||||
var src = './data/offset/' + name + '.html?' + parseInt( Math.random()*1000, 10 ),
|
||||
iframe = jQuery('<iframe />').css({
|
||||
width: 500, height: 500, position: 'absolute', top: -600, left: -600, visibility: 'hidden'
|
||||
}).appendTo('body')[0];
|
||||
var src = "./data/offset/" + name + ".html?" + parseInt( Math.random()*1000, 10 ),
|
||||
iframe = jQuery("<iframe />").css({
|
||||
width: 500, height: 500, position: "absolute", top: -600, left: -600, visibility: "hidden"
|
||||
}).appendTo("body")[0];
|
||||
iframe.contentWindow.location = src;
|
||||
return iframe;
|
||||
}
|
||||
|
|
|
@ -1,38 +1,50 @@
|
|||
module("queue", { teardown: moduleTeardown });
|
||||
|
||||
test("queue() with other types",function() {
|
||||
expect(9);
|
||||
expect(11);
|
||||
var counter = 0;
|
||||
|
||||
var $div = jQuery({});
|
||||
stop();
|
||||
|
||||
var $div = jQuery({}),
|
||||
defer;
|
||||
|
||||
$div.promise("foo").done(function() {
|
||||
equals( counter, 0, "Deferred for collection with no queue is automatically resolved" );
|
||||
});
|
||||
|
||||
$div
|
||||
.queue('foo',function(){
|
||||
.queue("foo",function(){
|
||||
equals( ++counter, 1, "Dequeuing" );
|
||||
jQuery.dequeue(this,'foo');
|
||||
jQuery.dequeue(this,"foo");
|
||||
})
|
||||
.queue('foo',function(){
|
||||
.queue("foo",function(){
|
||||
equals( ++counter, 2, "Dequeuing" );
|
||||
jQuery(this).dequeue('foo');
|
||||
jQuery(this).dequeue("foo");
|
||||
})
|
||||
.queue('foo',function(){
|
||||
.queue("foo",function(){
|
||||
equals( ++counter, 3, "Dequeuing" );
|
||||
})
|
||||
.queue('foo',function(){
|
||||
.queue("foo",function(){
|
||||
equals( ++counter, 4, "Dequeuing" );
|
||||
});
|
||||
|
||||
equals( $div.queue('foo').length, 4, "Testing queue length" );
|
||||
defer = $div.promise("foo").done(function() {
|
||||
equals( counter, 4, "Testing previous call to dequeue in deferred" );
|
||||
start();
|
||||
});
|
||||
|
||||
$div.dequeue('foo');
|
||||
equals( $div.queue("foo").length, 4, "Testing queue length" );
|
||||
|
||||
$div.dequeue("foo");
|
||||
|
||||
equals( counter, 3, "Testing previous call to dequeue" );
|
||||
equals( $div.queue('foo').length, 1, "Testing queue length" );
|
||||
equals( $div.queue("foo").length, 1, "Testing queue length" );
|
||||
|
||||
$div.dequeue('foo');
|
||||
$div.dequeue("foo");
|
||||
|
||||
equals( counter, 4, "Testing previous call to dequeue" );
|
||||
equals( $div.queue('foo').length, 0, "Testing queue length" );
|
||||
equals( $div.queue("foo").length, 0, "Testing queue length" );
|
||||
});
|
||||
|
||||
test("queue(name) passes in the next item in the queue as a parameter", function() {
|
||||
|
@ -74,7 +86,7 @@ test("queue(name) passes in the next item in the queue as a parameter", function
|
|||
});
|
||||
|
||||
test("queue() passes in the next item in the queue as a parameter to fx queues", function() {
|
||||
expect(2);
|
||||
expect(3);
|
||||
stop();
|
||||
|
||||
var div = jQuery({});
|
||||
|
@ -87,11 +99,39 @@ test("queue() passes in the next item in the queue as a parameter to fx queues",
|
|||
}).queue(function(next) {
|
||||
equals(++counter, 2, "Next was called");
|
||||
next();
|
||||
start();
|
||||
}).queue("bar", function() {
|
||||
equals(++counter, 3, "Other queues are not triggered by next()")
|
||||
});
|
||||
|
||||
jQuery.when( div.promise("fx"), div ).done(function() {
|
||||
equals(counter, 2, "Deferreds resolved");
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test("callbacks keep their place in the queue", function() {
|
||||
expect(5);
|
||||
stop();
|
||||
var div = jQuery("<div>"),
|
||||
counter = 0;
|
||||
|
||||
div.queue(function( next ) {
|
||||
equal( ++counter, 1, "Queue/callback order: first called" );
|
||||
setTimeout( next, 200 );
|
||||
}).show(100, function() {
|
||||
equal( ++counter, 2, "Queue/callback order: second called" );
|
||||
jQuery(this).hide(100, function() {
|
||||
equal( ++counter, 4, "Queue/callback order: fourth called" );
|
||||
});
|
||||
}).queue(function( next ) {
|
||||
equal( ++counter, 3, "Queue/callback order: third called" );
|
||||
next();
|
||||
});
|
||||
|
||||
div.promise("fx").done(function() {
|
||||
equals(counter, 4, "Deferreds resolved");
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test("delay()", function() {
|
||||
|
@ -110,7 +150,9 @@ test("delay()", function() {
|
|||
});
|
||||
|
||||
test("clearQueue(name) clears the queue", function() {
|
||||
expect(1);
|
||||
expect(2);
|
||||
|
||||
stop()
|
||||
|
||||
var div = jQuery({});
|
||||
var counter = 0;
|
||||
|
@ -123,6 +165,11 @@ test("clearQueue(name) clears the queue", function() {
|
|||
counter++;
|
||||
});
|
||||
|
||||
div.promise("foo").done(function() {
|
||||
ok( true, "dequeue resolves the deferred" );
|
||||
start();
|
||||
});
|
||||
|
||||
div.dequeue("foo");
|
||||
|
||||
equals(counter, 1, "the queue was cleared");
|
||||
|
@ -146,3 +193,81 @@ test("clearQueue() clears the fx queue", function() {
|
|||
|
||||
div.removeData();
|
||||
});
|
||||
|
||||
test("_mark() and _unmark()", function() {
|
||||
expect(1);
|
||||
|
||||
var div = {},
|
||||
$div = jQuery( div );
|
||||
|
||||
stop();
|
||||
|
||||
jQuery._mark( div, "foo" );
|
||||
jQuery._mark( div, "foo" );
|
||||
jQuery._unmark( div, "foo" );
|
||||
jQuery._unmark( div, "foo" );
|
||||
|
||||
$div.promise( "foo" ).done(function() {
|
||||
ok( true, "No more marks" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test("_mark() and _unmark() default to 'fx'", function() {
|
||||
expect(1);
|
||||
|
||||
var div = {},
|
||||
$div = jQuery( div );
|
||||
|
||||
stop();
|
||||
|
||||
jQuery._mark( div );
|
||||
jQuery._mark( div );
|
||||
jQuery._unmark( div, "fx" );
|
||||
jQuery._unmark( div );
|
||||
|
||||
$div.promise().done(function() {
|
||||
ok( true, "No more marks" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test("promise()", function() {
|
||||
expect(1);
|
||||
|
||||
stop();
|
||||
|
||||
var objects = [];
|
||||
|
||||
jQuery.each( [{}, {}], function( i, div ) {
|
||||
var $div = jQuery( div );
|
||||
$div.queue(function( next ) {
|
||||
setTimeout( function() {
|
||||
if ( i ) {
|
||||
next();
|
||||
setTimeout( function() {
|
||||
jQuery._unmark( div );
|
||||
}, 20 );
|
||||
} else {
|
||||
jQuery._unmark( div );
|
||||
setTimeout( function() {
|
||||
next();
|
||||
}, 20 );
|
||||
}
|
||||
}, 50 );
|
||||
}).queue(function( next ) {
|
||||
next();
|
||||
});
|
||||
jQuery._mark( div );
|
||||
objects.push( $div );
|
||||
});
|
||||
|
||||
jQuery.when.apply( jQuery, objects ).done(function() {
|
||||
ok( true, "Deferred resolved" );
|
||||
start();
|
||||
});
|
||||
|
||||
jQuery.each( objects, function() {
|
||||
this.dequeue();
|
||||
});
|
||||
});
|
55
test/unit/support.js
Normal file
55
test/unit/support.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
module("support", { teardown: moduleTeardown });
|
||||
|
||||
function supportIFrameTest( title, url, noDisplay, func ) {
|
||||
|
||||
if ( noDisplay !== true ) {
|
||||
func = noDisplay;
|
||||
noDisplay = false;
|
||||
}
|
||||
|
||||
test( title, function() {
|
||||
var iframe;
|
||||
|
||||
stop();
|
||||
window.supportCallback = function() {
|
||||
var self = this,
|
||||
args = arguments;
|
||||
setTimeout( function() {
|
||||
window.supportCallback = undefined;
|
||||
iframe.remove();
|
||||
func.apply( self, args );
|
||||
start();
|
||||
}, 0 );
|
||||
};
|
||||
iframe = jQuery( "<div/>" ).css( "display", noDisplay ? "none" : "block" ).append(
|
||||
jQuery( "<iframe/>" ).attr( "src", "data/support/" + url + ".html" )
|
||||
).appendTo( "body" );
|
||||
});
|
||||
}
|
||||
|
||||
supportIFrameTest( "proper boxModel in compatMode CSS1Compat (IE6 and IE7)", "boxModelIE", function( compatMode, boxModel ) {
|
||||
ok( compatMode !== "CSS1Compat" || boxModel, "boxModel properly detected" );
|
||||
});
|
||||
|
||||
supportIFrameTest( "body background is not lost if set prior to loading jQuery (#9238)", "bodyBackground", function( color, support ) {
|
||||
expect( 2 );
|
||||
var okValue = {
|
||||
"#000000": true,
|
||||
"rgb(0, 0, 0)": true
|
||||
};
|
||||
ok( okValue[ color ], "color was not reset (" + color + ")" );
|
||||
var i, passed = true;
|
||||
for ( i in jQuery.support ) {
|
||||
if ( jQuery.support[ i ] !== support[ i ] ) {
|
||||
passed = false;
|
||||
strictEquals( jQuery.support[ i ], support[ i ], "Support property " + i + " is different" );
|
||||
}
|
||||
}
|
||||
for ( i in support ) {
|
||||
if ( !( i in jQuery.support ) ) {
|
||||
ok = false;
|
||||
strictEquals( src[ i ], dest[ i ], "Unexpected property: " + i );
|
||||
}
|
||||
}
|
||||
ok( passed, "Same support properties" );
|
||||
});
|
|
@ -2,47 +2,100 @@ module("traversing", { teardown: moduleTeardown });
|
|||
|
||||
test("find(String)", function() {
|
||||
expect(5);
|
||||
equals( 'Yahoo', jQuery('#foo').find('.blogTest').text(), 'Check for find' );
|
||||
equals( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" );
|
||||
|
||||
// using contents will get comments regular, text, and comment nodes
|
||||
var j = jQuery("#nonnodes").contents();
|
||||
equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
|
||||
|
||||
same( jQuery("#main").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
|
||||
same( jQuery("#main").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" );
|
||||
same( jQuery("#main").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" );
|
||||
same( jQuery("#qunit-fixture").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" );
|
||||
same( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" );
|
||||
same( jQuery("#qunit-fixture").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" );
|
||||
});
|
||||
|
||||
test("is(String)", function() {
|
||||
expect(26);
|
||||
ok( jQuery('#form').is('form'), 'Check for element: A form must be a form' );
|
||||
ok( !jQuery('#form').is('div'), 'Check for element: A form is not a div' );
|
||||
ok( jQuery('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
|
||||
ok( !jQuery('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
|
||||
ok( jQuery('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
|
||||
ok( !jQuery('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
|
||||
ok( jQuery('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
|
||||
ok( !jQuery('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
|
||||
ok( jQuery('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
|
||||
ok( !jQuery('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
|
||||
ok( jQuery('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
|
||||
ok( !jQuery('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
|
||||
ok( jQuery('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
|
||||
ok( !jQuery('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
|
||||
ok( jQuery('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
|
||||
ok( !jQuery('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
|
||||
ok( jQuery('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
|
||||
ok( !jQuery('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
|
||||
ok( !jQuery('#foo').is(0), 'Expected false for an invalid expression - 0' );
|
||||
ok( !jQuery('#foo').is(null), 'Expected false for an invalid expression - null' );
|
||||
ok( !jQuery('#foo').is(''), 'Expected false for an invalid expression - ""' );
|
||||
ok( !jQuery('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
|
||||
test("find(node|jQuery object)", function() {
|
||||
expect( 11 );
|
||||
|
||||
var $foo = jQuery("#foo"),
|
||||
$blog = jQuery(".blogTest"),
|
||||
$first = jQuery("#first"),
|
||||
$two = $blog.add( $first ),
|
||||
$fooTwo = $foo.add( $blog );
|
||||
|
||||
equals( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
|
||||
equals( $foo.find( $blog[0] ).text(), "Yahoo", "Find with blog node" );
|
||||
equals( $foo.find( $first ).length, 0, "#first is not in #foo" );
|
||||
equals( $foo.find( $first[0]).length, 0, "#first not in #foo (node)" );
|
||||
ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" );
|
||||
ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
|
||||
ok( $fooTwo.find( $blog[0] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
|
||||
|
||||
equals( $two.find( $foo ).length, 0, "Foo is not in two elements" );
|
||||
equals( $two.find( $foo[0] ).length, 0, "Foo is not in two elements(node)" );
|
||||
equals( $two.find( $first ).length, 0, "first is in the collection and not within two" );
|
||||
equals( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" );
|
||||
|
||||
});
|
||||
|
||||
test("is(String|undefined)", function() {
|
||||
expect(27);
|
||||
ok( jQuery("#form").is("form"), "Check for element: A form must be a form" );
|
||||
ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" );
|
||||
ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" );
|
||||
ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" );
|
||||
ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" );
|
||||
ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
|
||||
ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" );
|
||||
ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
|
||||
ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" );
|
||||
ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
|
||||
ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" );
|
||||
ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
|
||||
ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" );
|
||||
ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" );
|
||||
ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" );
|
||||
ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" );
|
||||
ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
|
||||
ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
|
||||
|
||||
ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" );
|
||||
ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" );
|
||||
ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" );
|
||||
ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" );
|
||||
ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" );
|
||||
|
||||
// test is() with comma-seperated expressions
|
||||
ok( jQuery('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
|
||||
ok( jQuery('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
|
||||
ok( jQuery('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
|
||||
ok( jQuery('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
|
||||
ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
|
||||
ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
|
||||
ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
|
||||
ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" );
|
||||
});
|
||||
|
||||
test("is(jQuery)", function() {
|
||||
expect(21);
|
||||
ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" );
|
||||
ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" );
|
||||
ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" );
|
||||
ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" );
|
||||
ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
|
||||
ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
|
||||
ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" );
|
||||
ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
|
||||
ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" );
|
||||
ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
|
||||
ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" );
|
||||
ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" );
|
||||
ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" );
|
||||
ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" );
|
||||
ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" );
|
||||
|
||||
// Some raw elements
|
||||
ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" );
|
||||
ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" );
|
||||
ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" );
|
||||
ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" );
|
||||
ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
|
||||
ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
|
||||
});
|
||||
|
||||
test("index()", function() {
|
||||
|
@ -55,15 +108,15 @@ test("index(Object|String|undefined)", function() {
|
|||
expect(16);
|
||||
|
||||
var elements = jQuery([window, document]),
|
||||
inputElements = jQuery('#radio1,#radio2,#check1,#check2');
|
||||
inputElements = jQuery("#radio1,#radio2,#check1,#check2");
|
||||
|
||||
// Passing a node
|
||||
equals( elements.index(window), 0, "Check for index of elements" );
|
||||
equals( elements.index(document), 1, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" );
|
||||
equals( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" );
|
||||
equals( inputElements.index(window), -1, "Check for not found index" );
|
||||
equals( inputElements.index(document), -1, "Check for not found index" );
|
||||
|
||||
|
@ -75,18 +128,23 @@ test("index(Object|String|undefined)", function() {
|
|||
|
||||
// Passing a selector or nothing
|
||||
// enabled since [6330]
|
||||
equals( jQuery('#text2').index(), 2, "Check for index amongst siblings" );
|
||||
equals( jQuery('#form').children().eq(4).index(), 4, "Check for index amongst siblings" );
|
||||
equals( jQuery('#radio2').index('#form :radio') , 1, "Check for index within a selector" );
|
||||
equals( jQuery('#form :radio').index( jQuery('#radio2') ), 1, "Check for index within a selector" );
|
||||
equals( jQuery('#radio2').index('#form :text') , -1, "Check for index not found within a selector" );
|
||||
equals( jQuery("#text2").index(), 2, "Check for index amongst siblings" );
|
||||
equals( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" );
|
||||
equals( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" );
|
||||
equals( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" );
|
||||
equals( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" );
|
||||
});
|
||||
|
||||
test("filter(Selector)", function() {
|
||||
expect(5);
|
||||
test("filter(Selector|undefined)", function() {
|
||||
expect(9);
|
||||
same( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
|
||||
same( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
|
||||
same( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
|
||||
|
||||
same( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object");
|
||||
same( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
|
||||
same( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object");
|
||||
same( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object");
|
||||
|
||||
// using contents will get comments regular, text, and comment nodes
|
||||
var j = jQuery("#nonnodes").contents();
|
||||
|
@ -97,9 +155,9 @@ test("filter(Selector)", function() {
|
|||
test("filter(Function)", function() {
|
||||
expect(2);
|
||||
|
||||
same( jQuery("#main p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
|
||||
same( jQuery("#qunit-fixture p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
|
||||
|
||||
same( jQuery("#main p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" );
|
||||
same( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" );
|
||||
});
|
||||
|
||||
test("filter(Element)", function() {
|
||||
|
@ -124,11 +182,11 @@ test("filter(jQuery)", function() {
|
|||
})
|
||||
|
||||
test("closest()", function() {
|
||||
expect(11);
|
||||
expect(13);
|
||||
same( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
|
||||
same( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
|
||||
same( jQuery("body").closest("div").get(), [], "closest(div)" );
|
||||
same( jQuery("#main").closest("span,#html").get(), q("html"), "closest(span,#html)" );
|
||||
same( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" );
|
||||
|
||||
same( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" );
|
||||
same( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
|
||||
|
@ -140,10 +198,14 @@ test("closest()", function() {
|
|||
same( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
|
||||
|
||||
//Test that .closest() returns unique'd set
|
||||
equals( jQuery('#main p').closest('#main').length, 1, "Closest should return a unique set" );
|
||||
equals( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" );
|
||||
|
||||
// Test on disconnected node
|
||||
equals( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
|
||||
|
||||
// Bug #7369
|
||||
equals( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" );
|
||||
equals( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" );
|
||||
});
|
||||
|
||||
test("closest(Array)", function() {
|
||||
|
@ -151,23 +213,45 @@ test("closest(Array)", function() {
|
|||
same( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" );
|
||||
same( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" );
|
||||
same( jQuery("body").closest(["div"]), [], "closest([div])" );
|
||||
same( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("main"), "level": 4 }], "closest([div])" );
|
||||
same( jQuery("#main").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" );
|
||||
same( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("qunit-fixture"), "level": 4 }], "closest([div])" );
|
||||
same( jQuery("#qunit-fixture").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" );
|
||||
|
||||
same( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
|
||||
same( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" );
|
||||
});
|
||||
|
||||
test("not(Selector)", function() {
|
||||
expect(7);
|
||||
equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
|
||||
test("closest(jQuery)", function() {
|
||||
expect(8);
|
||||
var $child = jQuery("#nothiddendivchild"),
|
||||
$parent = jQuery("#nothiddendiv"),
|
||||
$main = jQuery("#qunit-fixture"),
|
||||
$body = jQuery("body");
|
||||
ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" );
|
||||
ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
|
||||
ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" );
|
||||
ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" );
|
||||
equals( $child.closest( document.createElement("div") ).length, 0, "created element is not related" );
|
||||
equals( $child.closest( $main ).length, 0, "Main not a parent of child" );
|
||||
equals( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" );
|
||||
ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." );
|
||||
});
|
||||
|
||||
test("not(Selector|undefined)", function() {
|
||||
expect(11);
|
||||
equals( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" );
|
||||
same( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
|
||||
same( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
|
||||
same( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')");
|
||||
|
||||
same( jQuery('#ap *').not('code').get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
|
||||
same( jQuery('#ap *').not('code, #mark').get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
|
||||
same( jQuery('#ap *').not('#mark, code').get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
|
||||
same( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
|
||||
same( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
|
||||
same( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
|
||||
|
||||
var all = jQuery("p").get();
|
||||
same( jQuery("p").not(null).get(), all, "not(null) should have no effect");
|
||||
same( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect");
|
||||
same( jQuery("p").not(0).get(), all, "not(0) should have no effect");
|
||||
same( jQuery("p").not("").get(), all, "not('') should have no effect");
|
||||
});
|
||||
|
||||
test("not(Element)", function() {
|
||||
|
@ -178,13 +262,13 @@ test("not(Element)", function() {
|
|||
});
|
||||
|
||||
test("not(Function)", function() {
|
||||
same( jQuery("#main p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" );
|
||||
same( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" );
|
||||
});
|
||||
|
||||
test("not(Array)", function() {
|
||||
expect(2);
|
||||
|
||||
equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
|
||||
equals( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
|
||||
equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
|
||||
});
|
||||
|
||||
|
@ -197,37 +281,37 @@ test("not(jQuery)", function() {
|
|||
test("has(Element)", function() {
|
||||
expect(2);
|
||||
|
||||
var obj = jQuery("#main").has(jQuery("#sndp")[0]);
|
||||
same( obj.get(), q("main"), "Keeps elements that have the element as a descendant" );
|
||||
var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
|
||||
same( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
|
||||
|
||||
var multipleParent = jQuery("#main, #header").has(jQuery("#sndp")[0]);
|
||||
same( obj.get(), q("main"), "Does not include elements that do not have the element as a descendant" );
|
||||
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
|
||||
same( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
|
||||
});
|
||||
|
||||
test("has(Selector)", function() {
|
||||
expect(3);
|
||||
|
||||
var obj = jQuery("#main").has("#sndp");
|
||||
same( obj.get(), q("main"), "Keeps elements that have any element matching the selector as a descendant" );
|
||||
var obj = jQuery("#qunit-fixture").has("#sndp");
|
||||
same( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
|
||||
|
||||
var multipleParent = jQuery("#main, #header").has("#sndp");
|
||||
same( obj.get(), q("main"), "Does not include elements that do not have the element as a descendant" );
|
||||
var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
|
||||
same( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
|
||||
|
||||
var multipleHas = jQuery("#main").has("#sndp, #first");
|
||||
same( multipleHas.get(), q("main"), "Only adds elements once" );
|
||||
var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
|
||||
same( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
|
||||
});
|
||||
|
||||
test("has(Arrayish)", function() {
|
||||
expect(3);
|
||||
|
||||
var simple = jQuery("#main").has(jQuery("#sndp"));
|
||||
same( simple.get(), q("main"), "Keeps elements that have any element in the jQuery list as a descendant" );
|
||||
var simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
|
||||
same( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
|
||||
|
||||
var multipleParent = jQuery("#main, #header").has(jQuery("#sndp"));
|
||||
same( multipleParent.get(), q("main"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
|
||||
var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
|
||||
same( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
|
||||
|
||||
var multipleHas = jQuery("#main").has(jQuery("#sndp, #first"));
|
||||
same( simple.get(), q("main"), "Only adds elements once" );
|
||||
var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
|
||||
same( simple.get(), q("qunit-fixture"), "Only adds elements once" );
|
||||
});
|
||||
|
||||
test("andSelf()", function() {
|
||||
|
@ -235,7 +319,7 @@ test("andSelf()", function() {
|
|||
same( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
|
||||
same( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
|
||||
same( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
|
||||
same( jQuery("#groups").parents("p, div").andSelf().get(), q("main", "ap", "groups"), "Check for parents and self" );
|
||||
same( jQuery("#groups").parents("p, div").andSelf().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
|
||||
});
|
||||
|
||||
test("siblings([String])", function() {
|
||||
|
@ -268,9 +352,9 @@ test("parents([String])", function() {
|
|||
expect(5);
|
||||
equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
|
||||
equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
|
||||
equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
|
||||
same( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
|
||||
same( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
|
||||
equals( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" );
|
||||
same( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" );
|
||||
same( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" );
|
||||
});
|
||||
|
||||
test("parentsUntil([String])", function() {
|
||||
|
@ -280,10 +364,10 @@ test("parentsUntil([String])", function() {
|
|||
|
||||
same( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
|
||||
same( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
|
||||
same( jQuery("#groups").parentsUntil("#html").get(), parents.not(':last').get(), "Simple parentsUntil check" );
|
||||
same( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" );
|
||||
equals( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
|
||||
same( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
|
||||
same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#main").get(), "Filtered parentsUntil check" );
|
||||
same( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" );
|
||||
same( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
|
||||
equals( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" );
|
||||
same( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );
|
||||
|
@ -308,29 +392,29 @@ test("prev([String])", function() {
|
|||
test("nextAll([String])", function() {
|
||||
expect(4);
|
||||
|
||||
var elems = jQuery('#form').children();
|
||||
var elems = jQuery("#form").children();
|
||||
|
||||
same( jQuery("#label-for").nextAll().get(), elems.not(':first').get(), "Simple nextAll check" );
|
||||
same( jQuery("#label-for").nextAll('input').get(), elems.not(':first').filter('input').get(), "Filtered nextAll check" );
|
||||
same( jQuery("#label-for").nextAll('input,select').get(), elems.not(':first').filter('input,select').get(), "Multiple-filtered nextAll check" );
|
||||
same( jQuery("#label-for, #hidden1").nextAll('input,select').get(), elems.not(':first').filter('input,select').get(), "Multi-source, multiple-filtered nextAll check" );
|
||||
same( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" );
|
||||
same( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" );
|
||||
same( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" );
|
||||
same( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" );
|
||||
});
|
||||
|
||||
test("prevAll([String])", function() {
|
||||
expect(4);
|
||||
|
||||
var elems = jQuery( jQuery('#form').children().slice(0, 12).get().reverse() );
|
||||
var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() );
|
||||
|
||||
same( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
|
||||
same( jQuery("#area1").prevAll('input').get(), elems.filter('input').get(), "Filtered prevAll check" );
|
||||
same( jQuery("#area1").prevAll('input,select').get(), elems.filter('input,select').get(), "Multiple-filtered prevAll check" );
|
||||
same( jQuery("#area1, #hidden1").prevAll('input,select').get(), elems.filter('input,select').get(), "Multi-source, multiple-filtered prevAll check" );
|
||||
same( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" );
|
||||
same( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" );
|
||||
same( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" );
|
||||
});
|
||||
|
||||
test("nextUntil([String])", function() {
|
||||
expect(11);
|
||||
|
||||
var elems = jQuery('#form').children().slice( 2, 12 );
|
||||
var elems = jQuery("#form").children().slice( 2, 12 );
|
||||
|
||||
same( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
|
||||
same( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
|
||||
|
@ -353,14 +437,14 @@ test("prevUntil([String])", function() {
|
|||
|
||||
same( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
|
||||
same( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
|
||||
same( jQuery("#area1").prevUntil("label").get(), elems.not(':last').get(), "Simple prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" );
|
||||
equals( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label", "input").get(), elems.not(':last').not("button").get(), "Filtered prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label", "button").get(), elems.not(':last').not("input").get(), "Filtered prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(':last').get(), "Multiple-filtered prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" );
|
||||
same( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" );
|
||||
equals( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" );
|
||||
same( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(':last').get(), "Multi-source, multiple-filtered prevUntil check" );
|
||||
same( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" );
|
||||
});
|
||||
|
||||
test("contents()", function() {
|
||||
|
@ -399,7 +483,12 @@ test("add(String|Element|Array|undefined)", function() {
|
|||
expect(16);
|
||||
same( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
|
||||
same( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
|
||||
ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
|
||||
|
||||
// We no longer support .add(form.elements), unfortunately.
|
||||
// There is no way, in browsers, to reliably determine the difference
|
||||
// between form.elements and form - and doing .add(form) and having it
|
||||
// add the form elements is way to unexpected, so this gets the boot.
|
||||
// ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
|
||||
|
||||
// For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
|
||||
// use jQuery([]).add(form.elements) instead.
|
||||
|
@ -435,7 +524,8 @@ test("add(String|Element|Array|undefined)", function() {
|
|||
var notDefined;
|
||||
equals( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
|
||||
|
||||
ok( jQuery([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" );
|
||||
equals( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
|
||||
equals( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" );
|
||||
});
|
||||
|
||||
test("add(String, Context)", function() {
|
||||
|
|
|
@ -1 +1 @@
|
|||
1.5.2
|
||||
1.6.3pre
|
Loading…
Reference in a new issue