Compare commits

...

498 Commits

Author SHA1 Message Date
Denis Knauf bb7d98f018 input type=datetime-local support for ajax. 2011-07-07 12:13:10 +02:00
jaubourg e6f8951983 Fixes #9632. Adds res:// protocol to the list of local protocols. 2011-07-01 02:18:05 +02:00
jaubourg e83fcdcb02 Fixes #9682. Removes data from the options for request with no content so that it is not used again in case of a retry. Unit test added. 2011-07-01 02:11:26 +02:00
jaubourg 139135a98a Fixes #9446. Context is properly propagated using pipe. If context was the original deferred, then context is updated to next deferred in the chain. Unit tests added. 2011-07-01 01:51:50 +02:00
jaubourg 5b92a5f5ec Replaces typo (status instead of state) as observed in #9585. 2011-07-01 00:16:34 +02:00
John Resig e2ab2ba1d5 Updating the source version to 1.6.3pre 2011-06-30 14:17:44 -04:00
John Resig aa6f8c8cd3 Tagging the 1.6.2 release. 2011-06-30 14:16:56 -04:00
timmywil ab1504f14f Set timerId to true instead of a number so that intervals set to 1 are not accidentally cleared when stopped. Fixes #9678.
- Adding a working test case would not be possible in this case, but all tests pass.
2011-06-28 11:46:03 -04:00
timmywil 96501d38a9 Allow similarly named classes (regression from 9499) and switch class retrieval to property when passing class to value functions. Fixes #9617. 2011-06-19 18:58:47 -04:00
Mike Sherov 124817e668 Landing pull request 413. Move border/padding checks to after width validation to avoid unnecessary fallbacks. Fixes #9598.
More Details:
 - https://github.com/jquery/jquery/pull/413
 - http://bugs.jquery.com/ticket/9300
 - http://bugs.jquery.com/ticket/9441
 - http://bugs.jquery.com/ticket/9598
2011-06-17 17:33:29 -04:00
John Resig d59b0f3e27 Re-updating QUnit, oops. 2011-06-14 15:06:28 -07:00
John Resig d269e426e0 Updating version in release notes script. 2011-06-14 15:05:27 -07:00
John Resig 138d5b7b81 Updating the source version to 1.6.2pre 2011-06-14 14:55:14 -07:00
John Resig d443e533aa Tagging the 1.6.2rc1 release. 2011-06-14 14:54:23 -07:00
Schalk Neethling 8a532d1575 Landing pull request 378. Comment typo in core.js.
More Details:
 - https://github.com/jquery/jquery/pull/378
2011-06-14 16:01:50 -04:00
rwldrn 5eef5917fd Landing pull request 409. Adds fillOpacity to internal cssNumber. Fixes #9548.
More Details:
 - https://github.com/jquery/jquery/pull/409
 - http://bugs.jquery.com/ticket/9548
2011-06-14 15:59:22 -04:00
Greg Hazel 13ceb0f56b Landing pull request 410. Moves jQuery attachment comment to outro.
More Details:
 - https://github.com/jquery/jquery/pull/410
2011-06-14 15:51:03 -04:00
rwldrn 6926247bf4 Landing pull request 397. withinElement rewrite in event. Fixes #6234, #9357, #9447.
More Details:
 - https://github.com/jquery/jquery/pull/397
 - http://bugs.jquery.com/ticket/6234
 - http://bugs.jquery.com/ticket/9357
 - http://bugs.jquery.com/ticket/9447
2011-06-14 15:38:46 -04:00
timmywil 641ad80211 Attribute hooks do not need to be attached in XML docs. Fixes #9568. 2011-06-13 10:02:13 -04:00
timmywil 39a2f29c29 Revert "Add catch block to try/finally in deferred. Fixes #9033. Test case needed." Line of exception was lost when debugging.
This reverts commit 0a80be67f4.
2011-06-08 10:55:52 -04:00
timmywil db437be6e3 Check classes passed for duplicates. Fixes #9499. 2011-06-07 21:00:44 -04:00
timmywil 0a80be67f4 Add catch block to try/finally in deferred. Fixes #9033. Test case needed. 2011-06-07 20:55:17 -04:00
timmywil d66c3b6d84 Remove fellback in width/height cssHook 2011-06-07 00:04:17 -04:00
rwldrn 6490c10c75 Landing pull request 401. Nulling all elements created in support.js; Fixes #9471.
More Details:
 - https://github.com/jquery/jquery/pull/401
 - http://bugs.jquery.com/ticket/9471
2011-06-06 23:54:17 -04:00
timmywil 75203de743 Optimize width/height retrieval (moved logic to getWH, removed adjustWH). Supplements #9441, #9300. 2011-06-06 23:35:16 -04:00
Mike Sherov 80ad14bd14 Add margin after checking width. Add tests. Fixes #9441. Fixes #9300. 2011-06-06 23:13:37 -04:00
rwldrn 0742056645 Landing pull request 403. Check for both camelized and hyphenated data property names; Fixes #9301.
More Details:
 - https://github.com/jquery/jquery/pull/403
 - http://bugs.jquery.com/ticket/9301
2011-06-06 20:18:36 -04:00
rwldrn c3c001cf5b Landing pull request 404. Removes unused hasOwn var declaration. Fixes #9510.
More Details:
 - https://github.com/jquery/jquery/pull/404
 - http://bugs.jquery.com/ticket/9510
2011-06-06 20:16:14 -04:00
timmywil 71d2e657d0 Update QUnit. 2011-06-06 20:15:16 -04:00
timmywil 1d202c6afc Move the value attrHook to the main attrHooks object to save bytes 2011-05-26 16:51:41 -04:00
timmywil 9d4033d629 Add test for appending an xml element to another. Supplements #9370. 2011-05-25 20:48:59 -04:00
timmywil bdce86dc2e Move window/document test to dimensions for consistency 2011-05-25 19:59:29 -04:00
timmywil edb2286544 Return null for outer/inner width/height calls on window/document. Fixes #7557. 2011-05-25 19:49:50 -04:00
timmywil 1d1cb582c0 elem.getElementsByTagName calls the function in IE6/7. Fixes #9370. 2011-05-25 19:35:52 -04:00
Scott Hughes 287156197f Landing pull request 389. Null elements in clone to avoid memory leak in IE. Fixes #9341.
More Details:
 - https://github.com/jquery/jquery/pull/389
 - http://bugs.jquery.com/ticket/9341
2011-05-25 15:18:13 -04:00
rwldrn 408c98fb4b Landing pull request 383. Relocating jQuery.camelCase to core; Fixes #9368.
More Details:
 - https://github.com/jquery/jquery/pull/383
 - http://bugs.jquery.com/ticket/9368
2011-05-25 15:10:49 -04:00
timmywil b8fc9d14a1 detachEvent is unnecessary since we're nulling div. Fixes #8873. 2011-05-25 15:08:37 -04:00
timmywil 657b197c19 Null created elements in support to avoid leaks in IE. Tested IE6-8. Leaks are contained to the byte. Fixes #9294. 2011-05-25 14:30:46 -04:00
timmywil a5396bde70 Attach background data to divs as well 2011-05-25 14:01:33 -04:00
timmywil e5457a5a1f Remove unnecessary background setting in support now that we have the div reversion. Test added. 2011-05-25 13:58:05 -04:00
Mathias Bynens b43910a496 Landing pull request 352. Slightly improved defaultDisplay() and Throbber of Doom. Fixes #8994.
More Details:
 - https://github.com/jquery/jquery/pull/352
 - http://bugs.jquery.com/ticket/8994
2011-05-20 11:22:52 -04:00
rwldrn f82b9dddc4 Landing pull request 382. Adds support for number values (meter,progress); Fixes #9319.
More Details:
 - https://github.com/jquery/jquery/pull/382
 - http://bugs.jquery.com/ticket/9319
2011-05-20 11:03:33 -04:00
timmywil a1545b5079 Unnecessary var removed. 2011-05-18 11:59:21 -04:00
timmywil 25118e22a2 Handle unset value attributes consistently depending on property existence. Supplements #9328. 2011-05-18 11:46:22 -04:00
timmywil ba90af0dc5 Make the value hook less obtrusive for elements which do not inherently have a value property. Fixes #9328. 2011-05-18 11:29:25 -04:00
timmywil 7d3ba9f89e Switched title attribute to getAttributeNode for IE6/7. Fixes #9329. 2011-05-18 11:05:20 -04:00
Rick Waldron c17f589ec9 Landing pull request 377. Check custom data != null(undefined), allows zero; Fixes #9285.
More Details:
 - https://github.com/jquery/jquery/pull/377
 - http://bugs.jquery.com/ticket/9285
2011-05-16 10:38:36 -04:00
timmywil a5cf257a8a Use getAttributeNode for ^on attributes in IE6/7 to avoid anonymous function wrapper. Fixes #9298. 2011-05-16 10:17:50 -04:00
timmywil 6171e0a923 Retrieve the class attribute on a form in IE6/7. Fixes 9286. 2011-05-14 12:07:40 -04:00
timmywil cf702496ee Removing unnecessary argument type check for boolean hook 2011-05-13 13:47:44 -04:00
timmywil bc82ff0ff9 Make sure setting boolean attributes to the same name sets the property to a boolean type 2011-05-13 13:39:38 -04:00
timmywil 6f676e692d Use prop to retrieve boolean properties (so the selected hook will be used) 2011-05-13 13:33:43 -04:00
Rick Waldron ec829431fe Landing pull request 365. jQuery.buildFragment, ensure doc is a document; Fixes #8950.
More Details:
 - https://github.com/jquery/jquery/pull/365
 - http://bugs.jquery.com/ticket/8950
2011-05-13 12:26:17 -04:00
timmywil a5b7c0fa33 Style edits for pull request 375 2011-05-13 12:14:31 -04:00
avaly cbbd7d28e1 Landing pull request 375. Added test case to support #9237 Fixes #9237.
More Details:
 - https://github.com/jquery/jquery/pull/375
 - http://bugs.jquery.com/ticket/9237
2011-05-13 12:09:49 -04:00
timmywil 3486365062 Animation callbacks keep their place in the queue stack. Fixes #9220. 2011-05-13 11:56:55 -04:00
jaubourg 0f81cf8991 Adds iframe code for #9239. 2011-05-13 17:50:57 +02:00
jaubourg ceba855c01 Fixes #9239. If the body is already present in the DOM, use a div within it to perform boxModel-related support tests. Unit test added. 2011-05-13 17:43:53 +02:00
John Resig b60c8560ce Updating the source version to 1.6.2pre 2011-05-12 15:04:51 -04:00
John Resig 9fd37b2c8a Tagging the 1.6.1 release. 2011-05-12 15:04:36 -04:00
timmywil 01c5b7f7f5 JR don't want my QUnit. 2011-05-11 12:02:41 -04:00
John Resig f794f48f02 Adding in test case to support #9211. 2011-05-11 11:43:37 -04:00
jaubourg 391398cf23 Fixes #9221. Wraps openings of html comments and CDATA blocks found at the beginning of inserted script elements into a javascript block comment so that the new implementation of globalEval will not throw an exception in IE (execScript being less lenient than eval). Unit tests added. 2011-05-11 14:13:07 +02:00
timmywil 3a1c27b508 Revert "Updating QUnit." This commit actually reverted QUnit.
This reverts commit f9cccd05b6.
2011-05-10 13:58:50 -04:00
John Resig 68d980bbb4 Updating the source version to 1.6.1pre 2011-05-10 13:50:49 -04:00
John Resig 344af56868 Tagging the 1.6.1rc1 release. 2011-05-10 13:50:35 -04:00
John Resig f9cccd05b6 Updating QUnit. 2011-05-10 13:50:21 -04:00
John Resig 2812a87da7 Updating Sizzle. 2011-05-10 13:37:05 -04:00
John Resig c42360b5be More formatting tweaking. 2011-05-10 12:57:55 -04:00
John Resig d2fea6123f Merge branch 'master' of github.com:jquery/jquery 2011-05-10 12:54:41 -04:00
John Resig c8374fafe5 Update sizzle. 2011-05-10 12:54:29 -04:00
timmywil d75c61a5bd Update QUnit 2011-05-10 12:46:55 -04:00
John Resig 1ec003f10c Fix tabs in delegate test. 2011-05-10 12:43:34 -04:00
John Resig a5e407cafb Make sure that data properties with hyphens are always accessed/set using camelCase. Fixes #9124. 2011-05-10 11:56:42 -04:00
John Resig 419b5e5e2a Make sure that mouseenter/mouseleave fire on the correct element when doing delegation. Fixes #9069. 2011-05-10 11:49:32 -04:00
louisremi 521ae562da Landing pull request 374. .animate() Callbacks should fire in correct order (unit test included). Fixes #9100.
More Details:
 - https://github.com/jquery/jquery/pull/374
 - https://github.com/jquery/jquery/issues/9100
2011-05-10 11:22:12 -04:00
Sahab Yazdani 304dd618b7 Landing pull request 370. Fixes #8763.
More Details:
 - https://github.com/jquery/jquery/pull/370
 - https://github.com/jquery/jquery/issues/8763
2011-05-10 11:20:22 -04:00
jaubourg 38de389a8e Adds unit/support.js to unit tests. Still have to test for #8763 has to be done in its own file however, since Firefox refuses to notify global errors in the iframe (attachEvent, window.onerror and script.onerror all fail). 2011-05-10 12:24:36 +02:00
louisremi 966c2fe46a oops console 2011-05-10 12:18:40 +02:00
timmywil 4526c8b0a0 Add fallback to prop for the window and document. Switch value to use the property instead of the attribute for back compat. 2011-05-10 00:28:02 -04:00
louisremi f34a90b3f7 oops unit test 2011-05-09 17:46:00 +02:00
louisremi 076c347605 .animate() Callbacks should fire in correct order (fix #9100 + unit test) 2011-05-09 17:35:51 +02:00
jaubourg 8c13cfa805 Fixes #9104. Returning null or undefined in a pipe callback shouldn't end up throwing an exception. Silly, silly, me. 2011-05-09 10:01:20 +02:00
jaubourg efd0fce7a1 Fixes #9109. When jQuery is loaded in the body, then the fake body element used in support has to be inserted before the document's body for boxModel to be properly detected (got the hint by looking at the code in jQuery mobile). Test page added so that we can keep checking this. 2011-05-09 09:48:23 +02:00
timmywil 18b1cf2942 Remove value check from formHook; other elements can use value hook 2011-05-07 22:01:10 -04:00
timmywil 90f37aaf7a Call extend on prop to avoid changing original properties so that per-property easing is not lost in multiple animations with the same props 2011-05-07 21:26:02 -04:00
timmywil 8bb6e95b66 Set val before hide/show check and fix easing setting; also update attributes test for autofocus
- The object passed should not change so it can be used in future animates, updated src and tests accordingly.
2011-05-07 20:46:38 -04:00
Daniel Pihlstrom 3d1c27d52e Fix per-property easing. Fixes #9067 2011-05-07 19:28:07 -04:00
gnarf 31268449b9 Landing pull request 372. Test for numeric properties was using wrong variable. Fixes #9074.
More Details:
 - https://github.com/jquery/jquery/pull/372
2011-05-07 19:18:52 -04:00
timmywil c085563270 Reduce the boolean list only to those that have corresponding IDLs that don't require being added to propFix; only set the IDL if it exists
- See http://jsfiddle.net/timmywil/u5NLn/ for how boolean attributes are handled in every browser.
2011-05-07 14:49:04 -04:00
timmywil 09c0cf995b Global found in valHook for select(get) 2011-05-07 11:48:42 -04:00
timmywil c864455ccf Global found in dataAttr function 2011-05-06 14:54:47 -04:00
timmywil c72b0f3256 Check empty string instead of specified as specified is inconsistent on the name attribute. Fixes #9148. 2011-05-06 13:49:20 -04:00
timmywil f7f8450041 tmp was global in the new fn.promise. Fixes #9147. 2011-05-06 12:10:16 -04:00
timmywil a257e07ae4 Reduce boolean attribute list to only content attributes
- Removed IDL-only boolean attributes as well as officially deprecated attributes that we've not supported before
2011-05-06 10:53:05 -04:00
timmywil f30cd4155e Update boolean attribute list to contain all boolean attributes listed in w3c 2011-05-05 14:37:59 -04:00
timmywil cccf9ad91d Add support for the contenteditable attribute 2011-05-05 12:52:04 -04:00
timmywil 5097e6d1c6 Construct boolHook and rboolean regex to deal with boolean attributes. Fixes #9129. Fixes #9123.
- Construct regex for all attributes which are boolean attributes by specification.

  + This allows us to do what users expect with enumerated attributes and allows us to no longer complicate the issue.

  + People are just too confused with passing "true" instead of true when they should, so we won't have to worry about that anymore.

- Modularize code for dealing with boolean attributes into a separate hook to keep attr short and fast.
2011-05-05 12:17:08 -04:00
timmywil 5195335cf4 Set the property corresponding to a boolean attribute when setting to true. Fixes #9103.
- Once boolean properties had been modified natively, setting the attribute no longer set the current value
2011-05-04 15:53:00 -04:00
timmywil 3ed4b22073 Run property names through propFix in removeProp 2011-05-04 11:40:46 -04:00
timmywil 480b88ca37 Set corresponding property to false when removing boolean attributes. Fixes #9094 2011-05-04 11:29:38 -04:00
timmywil 97144424cc Update boolean check to avoid crashes, add all name fixes to propFix (properties are case-sensitive in all browsers), add tests for prop 2011-05-04 00:31:01 -04:00
John Resig a9d9f8c542 If no hook is provided, and a boolean property exists, use that to return an attribute-style value for boolean attributes. Fixes #9079. 2011-05-03 21:44:42 -04:00
John Resig bfad45fe45 Fix problem with appending multiple string arguments in IE 6. Fixes #9072. 2011-05-03 15:02:26 -04:00
John Resig 3cdffce19f Updating release note script. 2011-05-03 15:01:29 -04:00
timmywil 4ac2fdda2c Fix setting value attributes on option elements. Fixes #9071. 2011-05-03 14:48:36 -04:00
timmywil 6d2fd57f45 Fix QUnit Header links 2011-05-02 18:14:12 -04:00
timmywil ea24cd106b Avoid changing html in two places; add minified jQuery as an option to the main test page 2011-05-02 17:53:55 -04:00
timmywil 3dbd7b54de Add a test page for running the test suite against a fully built and compressed jQuery. Fixes #7650. 2011-05-02 16:56:39 -04:00
John Resig 89fd9dffad Less aggressive semicolon insertion for the minified file. 2011-05-02 16:36:16 -04:00
John Resig f8a112f08e Ensure that an endline is in place at the end of the minified jQuery file. 2011-05-02 16:32:02 -04:00
John Resig f4b5d3fc51 Update the UglifyJS code. 2011-05-02 16:25:36 -04:00
John Resig c0d993903b Fix bug with handling minor releases after major releases in the build script. 2011-05-02 16:25:20 -04:00
John Resig 53f275034a Updating the source version to 1.6.1pre 2011-05-02 13:50:33 -04:00
John Resig eae7c4111c Tagging the 1.6 release. 2011-05-02 13:50:00 -04:00
John Resig ca338dc749 Check for #8984 wasn't strong enough, enhanced. 2011-05-02 13:31:23 -04:00
John Resig 6c449fd5df Make sure that empty nodelists continue to map properly. Fixes #8993. 2011-05-02 13:25:53 -04:00
John Resig 86aa764f0b Change check for skipping the initial quickExpr RegExp check. Fixes #8984. 2011-05-02 13:14:13 -04:00
timmywil f1392d8208 Set background to none on our mock body and remove its contents to avoid a crash in IE when removing it. Fixes #9028. 2011-05-02 11:57:01 -04:00
timmywil 24a8ffb3ea Test for a colon in attribute names for IE6/7. Fixes #1591. 2011-05-01 17:09:50 -04:00
Rick Waldron 0c2d1aee54 jQuery.buildFragment, ensure doc is a document; Includes comments; Adds unit test. Fixes #8950 2011-04-30 10:42:36 -04:00
Dave Methvin e2bace8fa1 Merged pull request #361 from rwldrn/9008a.
Restored /g flag to rspaces; Adds unit tests; Supplements #9008
2011-04-29 07:36:31 -07:00
Rick Waldron bf678fd9d6 Restores var names to satisfy the crock-machine. Supplements #9008 2011-04-28 22:26:34 -04:00
Rick Waldron ca367674c1 Restored /g flag to rspaces; Adds unit tests; Supplements #9008 2011-04-28 21:15:45 -04:00
Dave Methvin e5f4ec846c Merged pull request #360 from xavierm02/patch-3.
Javascript -> JavaScript
2011-04-28 16:18:05 -07:00
MONTILLET Xavier ebf2faca1e Javascript -> JavaScript except if it was intentional to avoid letting newbies think it's Java. 2011-04-28 14:56:52 -07:00
timmywil b8a9c2ba34 Syntax in testrunner 2011-04-28 16:31:51 -04:00
rwldrn 57f56be04f Make cached rspaces regex definitions consistent. Fixes #9008 2011-04-28 16:06:13 -04:00
rwldrn 632cd6c4ba Landing pull request 357. Update unit tests for widows & orphans. Supplements #8971 Fixes #8971.
More Details:
 - https://github.com/jquery/jquery/pull/357
 - http://bugs.jquery.com/ticket/8971
2011-04-28 15:56:02 -04:00
Rick Waldron ebac797ac2 Landing pull request 354. Adds QUnit Aliases to testrunner.js. Fixes #8991.
More Details:
 - https://github.com/jquery/jquery/pull/354
 - http://bugs.jquery.com/ticket/8991
2011-04-28 15:28:01 -04:00
timmywil c0450f3c2a Correct the attachment of the p tag in the widows/orphans tests. Fixes test suite in IE8 2011-04-27 16:33:12 -04:00
John Resig b5772da087 Add a simple script for generating the release notes of a pre-release. 2011-04-27 00:56:08 -04:00
John Resig a8988e3cd1 Adding a Node-based release management script for pushing new releases to the CDN. 2011-04-26 16:23:09 -04:00
John Resig fd11df1ec4 Updating the source version to 1.6pre 2011-04-26 16:22:07 -04:00
John Resig 455edf197a Tagging the 1.6rc1 release. 2011-04-26 16:21:45 -04:00
Julian Aubourg 742e15c638 Merged pull request #348 from rwldrn/8978.
jQuery.support core style guide correction. Fixes #8978
2011-04-26 07:08:14 -07:00
Rick Waldron 08f52d69bd jQuery.support core style guide correction. Fixes #8978 2011-04-26 09:45:27 -04:00
timmywil fb65ba418a Merged pull request #345 from rwldrn/8971.
No need to test for widows & orphans values in IE6-8. Fixes #8971
2011-04-25 12:53:43 -07:00
rwldrn 86d5d3e809 No need to test for widows & orphans values in IE6-8. Fixes #8971 2011-04-25 13:13:57 -04:00
timmywil 5165033883 Add tests data- and aria- attributes and the autofocus boolean attribute and some style updates in jQuery.attr 2011-04-25 12:41:12 -04:00
aFarkas 83e9ce95d7 handle data- and aria- special 2011-04-25 12:41:12 -04:00
aFarkas 9559b1a294 dealing with boolean content attribute 2011-04-25 12:41:12 -04:00
Jordan Boesch 02ad0aa3b6 Landing pull request 344. using jQuery.nodeName where applicable.
More Details:
 - https://github.com/jquery/jquery/pull/344
2011-04-23 17:58:56 -04:00
timmywil 15ccae91db Switch the form nodeName check in attr to use jQuery.nodeName for consistency 2011-04-23 13:56:51 -04:00
John Resig 9b00827ac9 Disabling .add(form.elements) unit test. 2011-04-22 00:51:23 -04:00
timmywil bc7bb0df28 Merge branch 'master' of github.com:jquery/jquery 2011-04-22 00:28:11 -04:00
timmywil 2942be780f Combine the support tests for radioValue and appendChecked 2011-04-22 00:27:52 -04:00
Rick Waldron 3d9445e3fc Landing pull request 340. Adds widows, orphans to cssNumber hash; includes tests. Fixes #8936.
More Details:
 - https://github.com/jquery/jquery/pull/340
 - http://bugs.jquery.com/ticket/8936
2011-04-22 00:02:08 -04:00
Dave Methvin 16312c6b06 Merge branch 'master' of github.com:jquery/jquery into fix-8790a-quicker-trigger 2011-04-21 22:15:21 -04:00
timmywil d274b7b9f7 Landing pull request 332. Appending disconnected radio or checkbox inputs and keeping checked setting Fixes #8060, #8500.
More Details:
 - https://github.com/jquery/jquery/pull/332
 - http://bugs.jquery.com/ticket/8060
 - http://bugs.jquery.com/ticket/8500
2011-04-21 21:51:23 -04:00
timmywil 3ac9eb7ce3 Landing pull request [337](https://github.com/jquery/jquery/pull/337). Value of radio inputs resets when type is set after the value in all IEs. Fixes #8570 ([bug](http://bugs.jquery.com/ticket/8570)). 2011-04-21 21:33:09 -04:00
timmywil dbe966aa57 Update Sizzle and QUnit 2011-04-21 13:03:19 -04:00
jaubourg a28eadff48 Makes sure no unload handler is bound when not in IE. Also simplifies the whole "on unload abort" code. Also avoids the declaration of yet another variables in the jQuery main closure for the temporary XHR used to assess support properties. 2011-04-21 18:43:40 +02:00
jeresig 60cfab3d19 Updating Sizzle and QUnit. 2011-04-20 19:08:29 -04:00
timmywil 103d325887 Follow w3c standard for setting the common boolean attributes to the same name(selected, checked, readOnly, and disabled) 2011-04-19 17:48:07 -04:00
timmywil 8d2d94cfba Fix test suite fails for hiding text nodes in F4 and IE9. Update for #6135. 2011-04-19 13:45:01 -04:00
timmywil 825d3d96ce Only use getAttributeNode on buttons when setting value 2011-04-19 13:17:38 -04:00
jaubourg 3a3842c669 (Re) Fixes #8884 in a way that keeps the format of the headers map sent to transports natural. 2011-04-19 00:29:20 -07:00
Rick Waldron 8d3754751d DRY out #6514 2011-04-17 15:29:49 -07:00
timmywil fb5ef2c4ec Merge branch 'master' of github.com:jquery/jquery 2011-04-17 18:18:40 -04:00
timmywil 34d80709ce Fix value attribute and val for value on button elements. Fixes #1954 2011-04-17 18:17:31 -04:00
John Resig 15da298f72 Remove unnecessary usage of Function.prototype.bind (#7783) but maintain API. Also fix bug with proxy failing when a name is provided. Fixes #8893. 2011-04-17 18:17:31 -04:00
John Resig 2a71493447 Updating UglifyJS. 2011-04-17 18:17:31 -04:00
Brian Brennan 3cb9c1835c Fix live mouseenter and mouseleave binding so they can be activated by triggers. Fixes #6514. 2011-04-17 18:17:31 -04:00
John Resig f408aa4314 Remove unnecessary usage of Function.prototype.bind (#7783) but maintain API. Also fix bug with proxy failing when a name is provided. Fixes #8893. 2011-04-17 14:11:40 -07:00
John Resig 2786a11053 Updating UglifyJS. 2011-04-17 13:28:36 -07:00
John Resig 7a8fac57eb Merge branch 'master' of github.com:jquery/jquery 2011-04-17 11:58:58 -07:00
Brian Brennan d46042e050 Fix live mouseenter and mouseleave binding so they can be activated by triggers. Fixes #6514. 2011-04-17 11:58:20 -07:00
timmywil 230a50ff1c Update Sizzle - qunit-fixture changes 2011-04-17 14:25:16 -04:00
timmywil 3aa46725ed Merge branch 'qunit_fixture' 2011-04-17 14:12:31 -04:00
timmywil 68cc3ad730 Update QUnit, fix visibility of #dl and pass JSLint in effects.js 2011-04-17 14:12:05 -04:00
John Resig 21c0be8496 Make sure that hide or show don't fail when operating on non-Element nodes. Fixes #6135. 2011-04-17 11:07:42 -07:00
John Resig 728a70c036 Make sure that forms and selects are added to a jQuery set correctly. Fixes #6912. 2011-04-17 10:51:24 -07:00
Gilmore Davidson a9b81d759a Added check for live mouseenter/mouseleave events if bound to nested elements with the same selector. Fixes #5884. 2011-04-17 10:34:38 -07:00
John Resig adef5c3550 Make sure that there isn't an error if no event object exists. Fixes #8755. 2011-04-17 10:21:46 -07:00
timmywil ecf6a3c383 Switch QUnit div from depreceted #main to #qunit-fixture 2011-04-17 02:43:57 -04:00
Dave Methvin 235080e125 Follow-up to #8790. Delay the creation of a jQuery.Event until we know it will need to be triggered. 2011-04-16 20:48:27 -04:00
John Resig 5d70c6d797 Add in unit tests for #6993. 2011-04-16 17:39:30 -07:00
John Resig 6e3b596514 Allow function to be passed in as a data object to bind and one. Fixes #6993. 2011-04-16 17:37:35 -07:00
John Resig 94ee3e9743 Cache references to navigator and location. Fixes #6690. 2011-04-16 14:18:56 -07:00
John Resig 5b197b6c5f Merge branch 'cellpadding_support' of https://github.com/timmywil/jquery into timmywil-cellpadding_support 2011-04-16 09:17:34 -07:00
John Resig 8312e2d852 Merge branch 'effectsCleanup' of https://github.com/louisremi/jquery into louisremi-effectsCleanup 2011-04-16 09:16:45 -07:00
John Resig ce7b311b92 Backing out fix for #6481. 2011-04-16 09:12:53 -07:00
jaubourg a519129e99 Removes now unnecessary regexp and companion function. Fixes some spacing issues. Shortens field names. 2011-04-15 14:16:43 -07:00
Sam Bisbee 4d3cb7d7ee Fixing code styling typo. 2011-04-15 16:45:45 -04:00
Sam Bisbee a9a79ccc6e Continuing to map request headers using their name in uppercase for the index, but we now map to an object with an unmodified name and value: { name: "", value: "" }. This prevents overwriting of the user's supplied headers, which many applications parse with case sensitivity, because we no longer use the modified, uppercase index when building the request. 2011-04-15 16:36:43 -04:00
Jordan Boesch 35d9425969 removing regex 2011-04-15 08:53:37 -06:00
louisremi bcc8187b05 undefined should be as good as null here 2011-04-15 16:33:21 +02:00
Jordan Boesch c4d0cccecf revert to old code, bug is invalid 2011-04-15 07:48:50 -06:00
louisremi 7bc8227d29 typo 2011-04-15 15:30:19 +02:00
louisremi 7666c3ef9a remove more useless code. feels good. 2011-04-15 15:18:21 +02:00
louisremi eccf15be6c - merge master
- move private functions at the bottom
- remove duplicate code
- move more var at the top of their scope
- rewrite a loop to be more efficient
2011-04-15 14:44:55 +02:00
timmywil b6d21592cb Add support for setting the cellPadding attribute in IE6/7 2011-04-14 23:11:49 -04:00
jeresig 8e1467f97e Updating the source version to 1.6pre. 2011-04-14 16:29:22 -04:00
jeresig 19ceebd0f4 Tagging the 1.6b1 release. 2011-04-14 16:29:14 -04:00
timmywil d4b31a15ff Adds box-sizing check for IE9 inputs and buttons 2011-04-14 16:26:20 -04:00
jeresig 1dda994c46 Merge branch '8099' of https://github.com/rwldrn/jquery. Fixes #8099.
Conflicts:
	test/data/testsuite.css
2011-04-14 15:57:47 -04:00
jeresig 84712bd624 Fix formatting of pull 325. Fixes #4146. 2011-04-14 15:49:15 -04:00
jeresig cdb02d09f1 Merge branch 'bug_4146_v2' of https://github.com/jboesch/jquery into jboesch-bug_4146_v2 2011-04-14 15:44:58 -04:00
louisremi 7dc7070426 reduce function calls
simplify easing resolution code
+ some code cleanup
2011-04-14 15:21:08 +02:00
louisremi 8806435a77 Merge branch 'master' of http://github.com/jquery/jquery into effectsCleanup 2011-04-14 11:46:29 +02:00
timmywil 38d6d9f6e0 Adjust the unit tests in traversing - is(jQuery) to avoid long-running script alerts 2011-04-14 00:46:10 -04:00
Jordan Boesch e64d3d4e57 fixing bug 4146 - round 2! 2011-04-13 22:30:30 -06:00
timmywil ca5bc202ac IE9's support for SVG elements unfortunately does not extend to clearAttributes. Checks for its presence before proceeding. 2011-04-13 23:45:58 -04:00
timmywil 149a040794 Fix test suite fail in IE6/7 on event:undelegate - was failing an if where it shouldn't 2011-04-13 23:14:14 -04:00
jeresig 72ddc8c645 Merge branch 'master' of github.com:jquery/jquery 2011-04-13 16:42:20 -04:00
jeresig 42e20269ec Updating Sizzle. 2011-04-13 16:41:55 -04:00
rwldrn a76decc476 Ticket #8099 Performance tweaking, credits 2011-04-13 15:43:15 -04:00
rwldrn 59240d31c0 Ticket #8099 Updates per review 2011-04-13 13:58:17 -04:00
rwldrn 4fde550cb6 Ticket #8099 Conditional iframe approache, caches both iframe and iframedoc for reuse 2011-04-13 13:43:52 -04:00
jaubourg 4ad9b44dea Ensures callback placeholders are tested for and eventually replaced in data only when contentType is application/x-www-form-urlencoded and data is a string. Removes json to jsonp promotion when jsonp or jsonpCallback options are present. Uses new Deferred.always method to bind cleanUp function. 2011-04-13 19:27:19 +02:00
jaubourg 4344d08417 Fixes #8635 again (fix was lost in rewrite). Also removes unnecessary "manual" garbage collection. 2011-04-13 18:35:38 +02:00
Dave Methvin f7f4ef91cf Merge branch 'fix_suite_fails' of https://github.com/timmywil/jquery into timmywil-fix_suite_fails 2011-04-12 19:42:35 -04:00
Dave Methvin 0032e30f75 Merge branch 'jslint_function_in_loop' of https://github.com/timmywil/jquery into timmywil-jslint_function_in_loop 2011-04-12 19:39:53 -04:00
timmywil 69866fd2e5 VML.type test was causing multiple test suite fails, fix attributes.js fail in IE6 where the val(String/Number) tests were interfering with the val(Function) tests 2011-04-12 19:32:18 -04:00
Dave Methvin bebd8bc01e Followup to #8753. Modify new Event constructor signature to jQuery.event(type, props), which can be exploited by jQuery.event.trigger as well. 2011-04-12 19:29:09 -04:00
rwldrn 81de96af74 Fixes #8099 using iframe to capture an element's real default display; suggested by lrbabe/louisremi 2011-04-12 18:57:14 -04:00
Dave Methvin 6d49e84daf Merge branch 'fix-8790-quick-trigger'
Conflicts:
	src/event.js
2011-04-12 18:46:21 -04:00
Dave Methvin 9e71ad1b12 Explicitly set event.type in case we chopped out a namespace or exclusive flag. 2011-04-12 18:32:23 -04:00
timmywil 73f9ab6705 JSLint failed due to function created within for loop 2011-04-12 18:30:21 -04:00
Dave Methvin 352715bd08 Use explicit "new jQuery.Event" to avoid double-function-call overhead. 2011-04-12 17:46:15 -04:00
John Firebaugh 0d8b247cab Accessing the 'type' property on VML elements fails on IE. Fixes #7071. 2011-04-12 16:48:22 -04:00
John Resig 3418f32387 Merge branch 'master' of https://github.com/rjgotten/jquery into rjgotten-master. Also added in unit tests covering the case. Fixes #6180.
Conflicts:
	src/manipulation.js
2011-04-12 16:39:30 -04:00
John Resig 122514a8da Merge branch 'master' of https://github.com/jclain/jquery into jclain-master 2011-04-12 16:26:41 -04:00
John Resig f1d75edec7 Merge branch 'bug_7931' of https://github.com/Xavi-/jquery into Xavi--bug_7931
Conflicts:
	src/offset.js
2011-04-12 16:13:56 -04:00
John Resig 978c065555 Merge branch 'Sub_Naming' of https://github.com/timmywil/jquery into timmywil-Sub_Naming
Conflicts:
	src/core.js
	src/css.js
	src/event.js
2011-04-12 16:05:40 -04:00
John Resig e7787cd098 More formatting tweaks. 2011-04-12 15:54:30 -04:00
John Resig 34adda3c88 Fixing some minor formatting problems. 2011-04-12 14:58:55 -04:00
John Resig b05d631b30 Merge branch 'fix-8790-quick-trigger' of https://github.com/dmethvin/jquery into dmethvin-fix-8790-quick-trigger 2011-04-12 14:57:30 -04:00
rwldrn 885b64d4e6 Fixes #8099 using iframe to capture an element's real default display; suggested by lrbabe/louisremi 2011-04-12 13:50:15 -04:00
rwldrn 7164615f67 Ticket 8099, Reattempt with iframe 2011-04-12 11:48:07 -04:00
louisremi f19a74f10b revert last commit 2011-04-12 13:12:58 +02:00
louisremi 01a2b51b26 switch double quotes with single quotes 2011-04-12 13:07:38 +02:00
louisremi 02e0047e92 resolve more conflicts 2011-04-12 11:39:21 +02:00
louisremi a5604aedb7 merge with master and resolve more conflicts 2011-04-12 11:29:25 +02:00
louisremi 8547b34f92 resolve conflict 2011-04-12 11:18:44 +02:00
louisremi f42010b657 third batch 2011-04-12 10:47:46 +02:00
jeresig 312df0441b Revert "QUnit test for overriding important css declarations, references #4427"
This reverts commit 1299e89dcd.

Conflicts:

	test/unit/css.js
2011-04-12 00:54:12 -04:00
jeresig 0ff4c69929 Some minor code cleanup. 2011-04-12 00:38:48 -04:00
jeresig db80ad94d5 Merge branch 'fix_8402' of https://github.com/lrbabe/jquery into lrbabe-fix_8402 2011-04-12 00:37:51 -04:00
jeresig 430d9e0b06 Merge branch 'fix_8403' of https://github.com/lrbabe/jquery into lrbabe-fix_8403 2011-04-12 00:35:51 -04:00
jeresig 7bfb6a7dd3 Removing un-needed frameElement check as discussed in #8018. Fixes #8108. 2011-04-12 00:29:52 -04:00
jeresig 0d755dff13 Merge branch 'master' of https://github.com/inukshuk/jquery into inukshuk-master
Conflicts:
	test/unit/offset.js
2011-04-12 00:25:36 -04:00
jeresig ea6987e078 Merge branch 'master' of https://github.com/azatoth/jquery 2011-04-12 00:18:12 -04:00
Azatoth 1299e89dcd QUnit test for overriding important css declarations, references #4427 2011-04-12 00:17:07 -04:00
jeresig 31b3c44db3 Merge branch 'bug_4366' of https://github.com/jboesch/jquery into jboesch-bug_4366 2011-04-12 00:12:27 -04:00
jeresig 2d27ac4d29 Merge branch 'master' of https://github.com/robmorgan/jquery into robmorgan-master 2011-04-12 00:09:46 -04:00
jeresig 0fa0f4cf02 Merge branch 'attr_remove_list_check' of https://github.com/timmywil/jquery into timmywil-attr_remove_list_check 2011-04-12 00:05:21 -04:00
timmywil 98da6b13bc Fixes unit/css.js test fail in Safari 5. support.js test was passing erroneously due to the body to which the div was attached having a width of 0 2011-04-11 23:59:12 -04:00
timmywil cb659c6054 retrieving list with getAttribute is fine, no need to add list here anymore 2011-04-11 19:30:20 -04:00
jaubourg 2b70893928 Bug fixes in queue.js: type in dequeue could be undefined which lead to a wrong data key, which would then have undesirable data left dangling on elements. Also adds missing semicolon in effects unit. 2011-04-12 01:09:35 +02:00
jaubourg f6f1cc77f4 Merge branch 'master' of github.com:jquery/jquery 2011-04-12 00:27:51 +02:00
louisremi 11adde5127 second batch 2011-04-11 22:33:29 +02:00
jeresig e9905b15d4 Merge branch '2773_firefox_opera_fix' of https://github.com/timmywil/jquery into timmywil-2773_firefox_opera_fix 2011-04-11 16:00:34 -04:00
louisremi 581fa82420 double quotes, again 2011-04-11 21:44:29 +02:00
louisremi cccd092fe0 first batch 2011-04-11 21:43:43 +02:00
louisremi 930731ba0f Double quote is the new simple quote 2011-04-11 21:33:15 +02:00
louisremi d710442201 the expected number of assertions shouldn't contain a condition 2011-04-11 21:14:41 +02:00
louisremi 6ddc3816dd limit this test to browsers not supporting opacity 2011-04-11 21:05:15 +02:00
louisremi 272b8d69dc replace cssPropsAware branch 2011-04-11 20:33:52 +02:00
Dave Methvin 7fa6de0ec1 Merge branch 'master' of github.com:jquery/jquery into fix-8790-quick-trigger 2011-04-11 13:25:57 -04:00
Dave Methvin a5071d49ba Shave some time off array setup in trigger/handle 2011-04-11 13:19:00 -04:00
louisremi 780b7983d0 Group all local functions at the top of the file and add comments 2011-04-11 19:01:04 +02:00
timmywil a564a0b1ec Run order problem when running full test suite in Opera 11, removed failing test as it passed by itself and there are others just like it 2011-04-11 12:24:31 -04:00
jeresig 094c48e0c5 Merge branch '8777' of https://github.com/rwldrn/jquery into rwldrn-8777
Conflicts:
	src/event.js
2011-04-11 12:13:04 -04:00
timmywil eb857e2b71 Fix unit tests in firefox 4 and opera 11, passing null or undefined to indexOf was throwing an error in those browsers 2011-04-11 11:54:55 -04:00
Dave Methvin 7957516671 Merge branch 'master' of github.com:jquery/jquery into fix-8790-quick-trigger
Conflicts:
	src/event.js
2011-04-11 11:44:26 -04:00
Rick Waldon 868e1e28ce Ticket #8753 Always set event type explicitly 2011-04-11 11:32:23 -04:00
Dave Methvin 1cca0817a0 Merge branch 'master' of github.com:jquery/jquery into fix-8790-quick-trigger 2011-04-11 11:25:27 -04:00
jeresig 6591f6dd9d Fix broken merge. 2011-04-11 11:22:52 -04:00
Dave Methvin 530c915553 Move initialization of event until we determine if anyone wants it. 2011-04-11 11:15:00 -04:00
jaubourg 4c3aba9a15 Merge branch 'master' of github.com:jquery/jquery 2011-04-11 13:41:17 +02:00
jaubourg 3411d47a6a Adds _mark and _unmark as a mean to keep track of ongoing non-queued animations in fn.promise. 2011-04-11 13:40:14 +02:00
Rob Morgan 91d0398813 Adding a full-stop 2011-04-11 12:32:45 +08:00
Rob Morgan 467747d55f Fixing typos in the README.md file 2011-04-11 12:24:38 +08:00
Dave Methvin bb52010442 Merge branch 'master' of github.com:jquery/jquery into fix-8790-quick-trigger 2011-04-10 17:40:31 -04:00
jeresig 56ffad2dad Merge branch '8101_lrbabe_requestAnimationFrame' of https://github.com/timmywil/jquery into timmywil-8101_lrbabe_requestAnimationFrame
Conflicts:
	src/effects.js
2011-04-10 17:27:34 -04:00
timmywil 791402b453 Separate raf function definition from passing it to requestAnimationFrame 2011-04-10 17:17:34 -04:00
jeresig 92dfb53314 Merge branch 'attrhooks.1.6v2' of https://github.com/timmywil/jquery 2011-04-10 17:11:35 -04:00
timmywil 215c507f79 Added back support.js test for getSetAttribute and removed some duplicate code that crept into attributes.js 2011-04-10 17:08:18 -04:00
jeresig f89edbc6e4 Merge branch 'modest_val_proposal' of https://github.com/timmywil/jquery into timmywil-modest_val_proposal
Conflicts:
	src/attributes.js
2011-04-10 16:56:56 -04:00
jeresig 14ecd9a992 Merge branch 'proxy-native-bind' of https://github.com/gf3/jquery into gf3-proxy-native-bind 2011-04-10 16:51:22 -04:00
jeresig 909a6ff60a Merge branch 'bug_7369' of https://github.com/timmywil/jquery into timmywil-bug_7369 2011-04-10 16:48:02 -04:00
jeresig 247363b9a7 Merge branch 'map-object.1.6' of https://github.com/danheberden/jquery into danheberden-map-object.1.6 2011-04-10 16:46:14 -04:00
jeresig 523db95de2 Merge branch '2773_find_closest' of https://github.com/timmywil/jquery into timmywil-2773_find_closest
Conflicts:
	test/unit/traversing.js
2011-04-10 16:37:09 -04:00
jeresig 52f31054fd Fix formatting. 2011-04-10 16:32:40 -04:00
jeresig b8fd1f03a6 Merge branch 'bug_2773' of https://github.com/timmywil/jquery into timmywil-bug_2773 2011-04-10 16:31:10 -04:00
jeresig 83dc078055 Bringing in the latest Sizzle code. 2011-04-10 16:28:44 -04:00
jeresig 2c74ee46ee Merge branch 'eventprops.1.6final' of https://github.com/rwldrn/jquery into rwldrn-eventprops.1.6final
Conflicts:
	test/unit/event.js
2011-04-10 16:28:15 -04:00
timmywil c10a76ec71 Merge branch 'master' into attrhooks.1.6v2 2011-04-10 16:26:39 -04:00
jeresig 7fb95ebe8f Merge branch 'attrhooks.1.6'
Conflicts:
	src/core.js
	src/support.js
2011-04-10 15:49:17 -04:00
jeresig b92d2f0bc9 Merge branch 'attrhooks.1.6v2' of https://github.com/timmywil/jquery into timmywil-attrhooks.1.6v2
Conflicts:
	src/attributes.js
2011-04-10 15:41:51 -04:00
timmywil da89d8768c Had some stale code in test/unit/attributes.js 2011-04-10 15:40:49 -04:00
jeresig 9ed5c774e4 Pulling in latest Sizzle. 2011-04-10 15:38:54 -04:00
Dave Methvin a019fc9ff3 Merge branch 'git_for_dummies' of https://github.com/azatoth/jquery into land-git-readme 2011-04-10 15:26:30 -04:00
Alexis Abril 8c318bf414 Fixes #7328. When getting data- attributes, after-cap any embedded dashes per the W3C HTML5 spec. 2011-04-10 15:17:00 -04:00
Rick Waldron 8c40c00fac Fixes #8814. Clean up inArray. 2011-04-10 14:31:31 -04:00
timmywil 3a1b4661f5 #8150 - When removing the width and height attributes in IE6/7, setting to "" actually sets to 0 instead of auto
- Having fixed this automatically with the use of removeAttribute in browsers that support it, this will fix it for IE6/7 as well.

- This has no effect on width/height styles set elsewhere( test added to removeAttr )

- With this addition, I need to call attr in removeAttr for IE6/7, which means boolean calls like .attr("checked", "") will no longer remove the attribute, which I think is fine.  .attr("checked", false) will still remove.  If I had left it, it would have gone in an infinite loop since setting to empty string is the only way to remove it in these browsers.

- The hrefNormalized hooks were returning null if they weren't present.  Added the null check to the getter.

- Now that the style support fails in IE8 as well due to uppercasing everything, no need to have style included with the hrefNormalized hooks
2011-04-09 17:25:06 -04:00
timmywil 17afd80d48 IE8 testing for lowercasing the css properties on retrieving style; had assumed the style support check failed in IE8, which it now does 2011-04-09 15:56:35 -04:00
Carl Fürstenberg 5dde3eb441 Git for dummies
Per request, here is an simple git for dummies quick sheet, with some
useful commands.
2011-04-08 22:09:53 +02:00
jaubourg f182b7b921 Adds a default falsy value for focusinBubbles + minor style consistency regarding test expression in support map initialization. 2011-04-08 18:24:25 +02:00
jaubourg 2594a935de Applies exception in Style Guidelines regarding objects and functions when they are the last argument of a function call. 2011-04-08 17:41:14 +02:00
jaubourg 7a1c6beab0 Renames chain as pipe. 2011-04-08 17:35:08 +02:00
Dave Methvin 98d83ef85f Fixes #8722. Remove try/catch used by #3533 to fix the IE Table Colon Blow bug, and instead check for colon in the event name. Thanks to daguej for scoping this out -- a colonoscopy you might say. 2011-04-07 22:52:15 -04:00
Dave Methvin c470db6950 Merge branch 'master' of github.com:jquery/jquery 2011-04-07 11:30:26 -04:00
Dave Methvin 14193e449e Create jQuery.holdReady(true/false) method to encapsulate jQuery.readyWait++ / jQuery.ready(true) logic. Fix problem where jQuery.ready may trigger twice, causing the (unsupported) document.onready to run twice. Fixes #8803 . 2011-04-07 11:26:42 -04:00
jaubourg 6832595ccd Merge branch 'master' of github.com:jquery/jquery
Conflicts:
	src/support.js
2011-04-07 06:56:19 +02:00
jaubourg c1dcad6942 Rewrite of the support module. We use a temporary body element in order not to have to wait for the document to be ready for boxModel-related support tests. 2011-04-07 06:51:37 +02:00
jaubourg f3c6077da0 Rewrite of globalEval. Uses window.execScript or window.eval with a trick to ensure proper context. Unit tests added. 2011-04-07 06:47:15 +02:00
jaubourg 4552d135f4 Adds fn.promise as a mean to observe the completion of animations on a set of elements. Only queued animations are handled for now, non-queued animations support coming soon. Effects unit tests updated to test the feature (needs more testing though). 2011-04-07 06:00:52 +02:00
jaubourg bb99899ca0 Adds always and chain methods to deferreds. 2011-04-07 05:49:32 +02:00
Dave Methvin 2f11ba7c98 Allow specific custom events to exit trigger early if there are no handlers bound for that type. 2011-04-06 23:41:47 -04:00
jaubourg 75a4bc4a4e Makes sure each animation tick has the same timestamp for all animations in the batch. 2011-04-07 05:07:20 +02:00
Dave Methvin bbd9c776ea Fix #8732. Change feature detect for focusin event support, so IE9 won't have duplicate events. 2011-04-06 23:06:52 -04:00
Dave Methvin b7dd8404c5 Fixes #8712. Bubble custom events to the window when they are triggered. Ride that, Cowboy! 2011-04-06 22:11:58 -04:00
Dave Methvin 879be3d812 Fix some spacing and comment issues that crept in with the rebase. 2011-04-06 11:34:41 -04:00
Dave Methvin 29386db319 Sadly, we still have to bubble the event so inline handlers will work. 2011-04-06 10:57:09 -04:00
Dave Methvin 246757bacd Only bubble a triggered event if we have attached a jQuery handler, but check the current element for an inline handler regardless. Make some other size optimizations as well. 2011-04-06 10:57:07 -04:00
Dave Methvin bfa32317d2 Switch from recursion to iteration for event triggering. Move event-name namespace processing out of event handler, since it has to always go through trigger. 2011-04-06 10:50:31 -04:00
carpie e0856738e6 Skip id regex check when large html strings are passed to the jQuery constructor (#7990). 2011-04-05 23:18:35 -04:00
Dave Methvin ceaf093942 Merge branch 'cssrelative.1.6' of https://github.com/danheberden/jquery into danheberden-cssrelative.1.6 2011-04-05 22:40:59 -04:00
timmywil d47c0ae422 Performance testing: localize val to each block and only set val to value when not a function 2011-04-05 22:40:12 -04:00
Dave Methvin 0fbadbcced Merge branch 'domready' of https://github.com/cowboy/jquery 2011-04-05 22:24:40 -04:00
Dave Methvin 1e85027dee Merge branch '4321' of https://github.com/rwldrn/jquery into rwldrn-4321 2011-04-05 22:04:05 -04:00
Dave Methvin c1316a4cb1 Shorten up the code and do event cleanup on test cases. 2011-04-05 21:59:09 -04:00
Dave Methvin b5c7c507c1 Merge branch 'ticket_7883' of https://github.com/rwldrn/jquery into rwldrn-ticket_7883 2011-04-05 21:42:58 -04:00
rwldrn 4b0c26f0af Ticket #8777 undelegate by namespace 2011-04-05 18:55:07 -04:00
rwldrn 92a4d59c32 Remove this.type assignment 2011-04-05 16:32:42 -04:00
timmywil 9db18ddd84 Per rwaldron's request, added oRequestAnimationFrame as a possibility 2011-04-05 16:28:25 -04:00
rwldrn b1b2e83394 Move this.type setting to after prop set; avoid setting twice 2011-04-05 16:20:55 -04:00
rwldrn 23a411b6bc Ticket #8753 Allow special properties to explicitly defined on jQuery.Event objects 2011-04-05 15:55:40 -04:00
Dan Heberden c0389e3e37 Add missing var declaration for 2011-04-05 08:33:14 -07:00
Dan Heberden 3609bed9e7 Remove extra else in parseJSON 2011-04-05 07:20:58 -07:00
Dan Heberden a7e7dbd978 Bug 7587; Enhancement/1.6 Feature: Bypass regexp filter on $.parseJSON and use native thrown exceptions if window.JSON.parse is available 2011-04-05 01:43:14 -07:00
Dan Heberden c72371f714 Improve speed of $.map with object support (-5% previous speed) and improve .length detection 2011-04-04 23:59:54 -07:00
Dan Heberden 44a3b5839e Improve relative string performance in .css and some code cleanup 2011-04-04 16:48:24 -07:00
timmywil fe3203bb5b Some adjustments and style edits on lrbabe's pull for requestAnimationFrame
- Moved support.js check to effects.js.  This is just an assignment to the function if it exists.  Removed string concatenations.

  + Still need to do the checks on window, but after that, window is no longer needed.

- Switched ternary to an if statmenet

- assigned timerId to a number rather than the function. I did perf tests to check which is faster.
2011-04-04 19:25:12 -04:00
louisremi 5b0369366a shorten requestAnimationFrame test 2011-04-04 15:47:19 -04:00
louisremi c95ab2a39c first tick should not occur immediatly; no tick should happen after a stop()
+ comments
2011-04-04 15:46:37 -04:00
louisremi 15e34d1f07 reduce impact of requestAnimationFrame on incompatible browsers by minimizing number of lookups 2011-04-04 15:46:37 -04:00
louisremi 03e6f7235b there was no way to 'manually' stop an animation 2011-04-04 15:46:37 -04:00
louisremi 6de29b24b1 timerId has to be set to true, to avoid starting multiple animation queues 2011-04-04 15:46:37 -04:00
louisremi 933ea8c5fa 'this' is the window 2011-04-04 15:46:37 -04:00
louisremi 9dc6397187 omitting 'window.' was causing undefined errors 2011-04-04 15:46:37 -04:00
louisremi f7ccec1b70 use requestAnimationFrame instead of setInterval for animations, when available. 2011-04-04 15:46:37 -04:00
timmywil 94fff6ff62 Remove the unused radiocheck regex 2011-04-04 14:22:58 -04:00
Dan Heberden 123dd72e80 Bug 7345; Add support for explicit/relative string values in .css - modified from original pull req by brandonaron #78 2011-04-04 11:21:15 -07:00
jaubourg 2ed81b44be Fixes #8744. Makes sure script transport abort method actually removes the script tag even if readyState exists. 2011-04-04 17:41:30 +02:00
timmywil 6f79bee3e3 Normalize css property names to lowercase for comparisons on a .attr('style') call since IE uppercases everything 2011-04-03 19:13:41 -04:00
timmywil ad2b3bc9f9 Found a problem removing the style attribute in IE
- Style is now a special case in IE6/7 to set cssText.  My goal is to avoid calling attr again for the performance benefit, and at this point it would also cause an infinite loop for the boolean attributes hooks such as selected & checked.  Nevertheless, style seems to be the only one requiring a special call.
2011-04-03 19:13:41 -04:00
timmywil 2a8a2b6148 Move the if statement in jQuery.fn.removeAttr to jQuery.removeAttr
- Extra testing on removeAttr and IE form weirdness( all good )
2011-04-03 19:13:41 -04:00
timmywil ff75767558 Minor adjustments and cleanup, including normalizing the value to a string when setting( list of changes below )
- Normalize set value to string to synchronize return type cross-browser

- Add style attrHook to propHooks to support style getting in all browsers for both attr and prop

- Extend the selected propHook instead of overriding a possible set function

- Remove selected propHook TODO since there is no selected content attribute and it should return null
2011-04-03 19:13:41 -04:00
timmywil 8cbf551a48 #5413 - Much shorter solution for getting width/height in ie6
- #8255 Added support for the list attribute in browsers that support it (it is automatically readonly, but can be set if using getAttribute( name, 2)
2011-04-03 19:13:41 -04:00
timmywil 5fc2281fcc - Added a hook to swap display none for width and height in browsers that do not sufficiently support get/setAttribute 2011-04-03 19:13:41 -04:00
timmywil 1e9b3ef3d8 Move the check for the name attribute out of attr and down to the formHook definition 2011-04-03 19:13:41 -04:00
timmywil fa4373c11b Add style attribute support tests to $.attr 2011-04-03 19:13:41 -04:00
timmywil a4d44979c6 Shorten the logic for hooks, ternary was unnecessary 2011-04-03 19:13:41 -04:00
timmywil 217a7abc43 Add name to prop hooks as well 2011-04-03 19:13:41 -04:00
timmywil 11c97bb066 Add attribute name to paramaters for hooks 2011-04-03 19:13:40 -04:00
timmywil 03da4c7ca7 Style formatting 2011-04-03 19:13:40 -04:00
timmywil 448111cbd4 No longer need to check for objects or string of null with the special form treatment and updates to removeAttr 2011-04-03 19:13:40 -04:00
timmywil 5caf7d8376 Clean up 2011-04-03 19:13:40 -04:00
timmywil 56014a1a00 Shorten even further 2011-04-03 19:13:40 -04:00
timmywil 479b28fb6a Modularize special form code for IE6/7 and clean up attr again 2011-04-03 19:13:40 -04:00
timmywil e0900a686d Fix issue where non-existant attributes on forms in IE6/7 were throwing errors 2011-04-03 19:13:40 -04:00
timmywil 3892df207d Add test for bug #3116 2011-04-03 19:13:40 -04:00
timmywil 47c80c2050 Add test for bug#3685, remove added html and add dynamicly to avoid global test suite errors 2011-04-03 19:13:40 -04:00
timmywil 9e05a0a37f Fix #6562, tighten up the special code for form objects, add name attrHook for IE6/7, and don't check for undefined with getting hook'd attr 2011-04-03 19:13:40 -04:00
timmywil 102053abd8 Fix #7472 and added test for #3113
- Forms with an input that has either name="action" or name="some-other-attr-on-the-form" caused problems in IE6/7.  This is fixed.

- Changed check in $.attr for ret === null to typeof ret === "object" to catch any inputs that are accidentally retrieved in IE6/7, since attributes cannot be set to objects and typeof null === "object"
2011-04-03 19:13:39 -04:00
timmywil 11cfdb2394 Non-existent attribute for jQuery.attr no longer needs to check for "undefined"
- Remove an unnecessary var

- Use variable in removeAttr for better minification
2011-04-03 19:13:39 -04:00
timmywil dfeeb872d6 Performance enhancement switching nodeType to a var 2011-04-03 19:13:39 -04:00
timmywil d28922bc03 Pass jslint, 2 missing semicolons 2011-04-03 19:13:39 -04:00
timmywil 2580420b7e Test description 2011-04-03 19:13:39 -04:00
timmywil 5ac6ca3fa5 Restored 6 tests that I had commented to come back to later to split up between prop and attr. All tests still pass in all browsers.
- I should make it clear that I have not removed any tests, but only moved some attr tests to prop where I thought it was appropriate.
2011-04-03 19:13:39 -04:00
timmywil dbe3b7a9d0 Style edits according to comments from John and rwaldron. 2011-04-03 19:13:39 -04:00
timmywil f578e0f997 Don't use extend when setting the action attrHook for IE6/7 2011-04-03 19:13:39 -04:00
timmywil 77c559c3cb No, don't return this. 2011-04-03 19:13:39 -04:00
timmywil b85d2cd8a5 Simplify jQuery.removeAttr and return this 2011-04-03 19:13:39 -04:00
timmywil 9f88fa9165 Full test suite now passes in all browsers! There are probably some tweaks we can make to shorten and simplify.
- removeAttr now only uses setAttribute if camelCase setAttribute is not supported

  + Might want to rename jQuery.support.getSetAttribute

- tabIndex is a special case now for hooks where undefined should be returned.

  + Should we be checking if hooks returns undefined?  undefined might be the desired return value in future hooks.
    As of now, tabIndex is the only one that needs it, but the test suite will still pass if we don't check if hooks are undefined.
2011-04-03 19:13:39 -04:00
timmywil 8cd30c62d8 Continuing IE7 testing, conditional attr fixes and hooks with feature testing. Will figure out a way to shorten after the test suite passes. 2011-04-03 19:13:39 -04:00
timmywil ebb8e8e300 Fix feature test, accidentally got rid of closure end 2011-04-03 19:13:39 -04:00
timmywil 00abeaee17 Didn't actually need the hooks anymore 2011-04-03 19:13:38 -04:00
timmywil 4baa213d88 First proposed solution for IE6/7 get/setAttribute quirks. Needs more testing, but solves some issues 2011-04-03 19:13:38 -04:00
timmywil 607210e010 Speed up hasAttr a little 2011-04-03 19:13:38 -04:00
timmywil 5eecb13fa3 Now passes in IE8, changed around $.hasAttr and switched the attrHook for selected to be a propHook 2011-04-03 19:13:38 -04:00
timmywil de79e8c7e0 Make the new attr/prop changes pass the test suite (in Webkit). There are still errors in IE.
+ Added hooks for selected, checked, readonly, disabled to removeAttr if set to falsey

+ Removed all attrs from attrFix, these aren't needed for setAttribute

+ If prop is used for class, do we want a propFix for class?

  - We could just assume the user should know to use className with prop.  I've done the latter for now.

+ Created tests for $.fn.prop and $.fn.removeProp

  - Actually all I did was change broken attr tests to prop where it made sense.
2011-04-03 19:13:38 -04:00
jeresig ab4e300919 Very crude first pass at splitting apart the attr/prop logic. Also adding in attrHooks/propHooks. All of it is completely untested. 2011-04-03 19:13:38 -04:00
timmywil 64a0005a3b A more modest valHooks proposal
- The main difference is that this does not allow arbitrarily adding hooks to any collection of elements.

- Modularizes val into a set of easily maintainable and conditional hooks.

- valHooks is placed at jQuery.valHooks

  + This could technically be extended, but I do not see it being used except in very rare cases since you can only apply valHooks to nodeNames and input types, and not a collection of elements as before. We could theoretically privatize valHooks taking it off of jQuery and only use it internally for our own convenience, but again, I do not believe this patch carries with it the dangers of the first proposal.

- Slightly improved performance of val on radios and checkboxes for browsers that support checkOn, given the conditional attachment of its hook.
2011-04-02 17:05:04 -04:00
John Resig fcc112f406 Updating the source version to 1.6pre. 2011-03-31 15:28:33 -04:00
John Resig a507f719ab Tagging the 1.5.2 release. 2011-03-31 15:28:23 -04:00
Ben Alman de0c25bef4 Updated DOM ready unit tests. 2011-03-31 13:36:16 -04:00
Ben Alman 368bfc0fe0 DOM Ready unit tests (but not the supporting fixed code). 2011-03-31 11:37:48 -04:00
Dave Methvin ff06d411d2 Merge branch 'bug_8316' of https://github.com/timmywil/jquery into timmywil-bug_8316 2011-03-31 10:25:59 -04:00
Dave Methvin 459bd7f89d Followup commit for #7340 test case; make sure second test fires properly on IE by focusing to another element rather than blurring off the first. 2011-03-31 09:10:30 -04:00
timmywil f9cc5597a4 Fix test cases for bug #8316 fix.
- Removed special page, just needed another test in the fixed offset tests

- Checks it's position related to scrolling
2011-03-31 02:55:16 -04:00
timmywil a807451a23 Fixes #7369 - Using an attribute selector for a non-existent attribute raised an exception on disconnected nodes 2011-03-30 23:39:19 -04:00
timmywil 1a16776730 Remove test for bug #7369 to move the fix to a separate branch for a sooner pull 2011-03-30 23:23:38 -04:00
Dave Methvin 6c28a394c2 Remove crossDomain:null comment, it's not needed since undefined==null below. 2011-03-30 21:59:38 -04:00
timmywil 6da3885cc3 Merge branch 'master' of git://github.com/jquery/jquery into 2773_find_closest 2011-03-30 21:52:09 -04:00
Dave Methvin adbe5e95f3 Merge branch 'crossDomain' of https://github.com/JessThrysoee/jquery into JessThrysoee-crossDomain 2011-03-30 21:52:04 -04:00
Dave Methvin ad4152709c Fixes #8203. Remove some misguided nulling of elements done in the name of IE memory cleanup. Based on a patch by davidmurdoch in pull 226. 2011-03-30 21:21:49 -04:00
John Resig 8cdafe7704 Merge branch 'makefile_fixes' of https://github.com/azatoth/jquery into azatoth-makefile_fixes 2011-03-30 15:23:31 -04:00
John Resig b89b66657c Merge branch 'fix_8346' of https://github.com/lrbabe/jquery into lrbabe-fix_8346 2011-03-30 14:54:52 -04:00
Jordan Boesch 926884bf1f Bug 4366; removing extra space 2011-03-30 11:26:20 -06:00
Jordan Boesch 3296116041 Bug 4366; fixing $.each(document.styleSheets) from throwing errors in IE 2011-03-30 11:17:48 -06:00
jaubourg f2ce87df8e Fixes #8692. Strange FF4 bug: values changed onto the arguments object sometimes end up as undefined values outside the $.when method. Cloning the object into a fresh array solves the issue. 2011-03-30 18:54:32 +02:00
John Resig 2555a5a232 Update the Sizzle location to point to the newly-moved repo. 2011-03-28 13:10:12 -04:00
rwldrn ef0157d191 Bug #8635 Firefox uncaught exception 2011-03-28 12:31:03 -04:00
timmywil e93ca40aa7 Bug #7369: Check non-existent attribute as well to be sure 2011-03-25 23:52:36 -04:00
timmywil e6da0fa6a9 Bug #7369: Add test for disconnected node in closest when passing attribute selector; this was recently fixed in 1.5.2rc 2011-03-25 23:46:29 -04:00
jeresig ee81d4da92 Merge branch 'bug-3333' of https://github.com/rdworth/jquery 2011-03-24 22:10:38 -04:00
jeresig 23e8cc5608 Updating the source version to 1.5.2pre. 2011-03-24 20:12:40 -04:00
jeresig 2d80710ab0 Tagging the 1.5.2rc1 release. 2011-03-24 20:12:31 -04:00
jeresig d86c48679a Land new sizzle commit. 2011-03-24 20:08:40 -04:00
Richard Worth 735a949a06 Further fix for #3333, refactored marginRight css hook to use jQuery.swap and computed. Thanks timmywil 2011-03-24 19:55:55 -04:00
jeresig 7b985c4ca0 Oops, that test file for bug #8316 was needed - was also missing an include and was causing errors. 2011-03-24 19:52:45 -04:00
jeresig 5ee4eefb9e Updating Sizzle submodule to bring in the latest commit. 2011-03-24 19:40:09 -04:00
jeresig 53697d10ef Fix missing semicolon. 2011-03-24 19:36:38 -04:00
Michael Murray e8f4629b92 Offset setter for fixed position elements in Webkit. Fixes #8316. 2011-03-24 19:02:38 -04:00
jeresig 1912ded3ee Merge branch 'bug-3333' of https://github.com/rdworth/jquery into rdworth-bug-3333 2011-03-24 18:58:20 -04:00
Richard Worth c3c507e900 Added css hook to work around bug in WebKit computed margin-right. Fixes #3333 - .css("marginRight") is incorrect in WebKit 2011-03-24 15:41:46 -04:00
timmywil 85232c97bf Traversing unit tests: added tests for passing invalid arguments to $.fn.not (should have no effect on existing object rather than return an empty object as filter does) 2011-03-23 16:04:12 -04:00
timmywil d2eafa0bb8 Merge branch 'master' of git://github.com/jquery/jquery into bug_2773 2011-03-23 15:59:33 -04:00
timmywil b8013581ce Closest unit tests: add one for passing a jQuery collection with multiple elements 2011-03-23 15:56:05 -04:00
Carl Fürstenberg 50e8837207 Makefile: pull_submodules cleaning
Empirical testing confirms that pulling the url again is enough
2011-03-22 23:18:15 +01:00
Carl Fürstenberg 07392bb090 Merge branch 'master' into makefile_fixes 2011-03-22 21:55:49 +01:00
timmywil e09d8898d8 Add node and jQuery object support to $.fn.closest 2011-03-21 20:59:20 -04:00
Dan Heberden 00dd6013b6 Clean up tab spacing 2011-03-21 12:24:53 -07:00
Dan Heberden d832f4f71e jQuery.map to iterate over objects with a .length property 2011-03-21 12:12:31 -07:00
Dan Heberden e38f074d14 jQuery.map to conform with style guidelines - improved size/DRY code 2011-03-21 08:39:53 -07:00
Dan Heberden 2407690ef9 Fixes 2616; Pull in #252 by jboesch: jQuery.map with object support 2011-03-21 08:10:27 -07:00
Dan Heberden f0e7d28e83 Merge branch 'bug_2616' of https://github.com/jboesch/jquery into map-object.1.6
* 'bug_2616' of https://github.com/jboesch/jquery:
  Bug 2616; Adding object support to jQuery.map
2011-03-21 08:04:35 -07:00
jeresig 7705c35b14 Merge branch 'fix-8456-lost-mouseenter' of https://github.com/dmethvin/jquery into dmethvin-fix-8456-lost-mouseenter 2011-03-21 10:53:57 -04:00
jeresig 5c79f82ec2 Merge branch 'fix-7340-focusin-focusout-bubble' of https://github.com/dmethvin/jquery into dmethvin-fix-7340-focusin-focusout-bubble 2011-03-21 10:53:18 -04:00
Carl Fürstenberg 8a1156da9b merge doesn't work when init
sadly the merge strategy doesn't work when doing an initial clone,
circumvent that
2011-03-18 17:59:16 +01:00
Carl Fürstenberg e2dd8916ee Adding core target
Adding core target to do jquery, minimization and lint
2011-03-18 17:59:09 +01:00
Carl Fürstenberg b4acb7ae81 updating phony rules 2011-03-17 20:23:20 +01:00
Carl Fürstenberg 4f9e78616e Change makefile order to only update submodules on 'all' target
insterad of always update the submodules, now only "make all" will run
that, thus an "make jquery" will not update them
2011-03-17 20:21:32 +01:00
Carl Fürstenberg 22738e0e4b Remove jq target
remove obsolete jq target
2011-03-17 20:20:02 +01:00
Carl Fürstenberg a2faed347d Merge when updating submodules on make
When  running make, the submodule update will remove all local changes.
Adding flag --rebase or --merge does solve the issue. rebase will
probably make it cleaner, but it might stop on conflict, thus --merge
will result in fewer (probably none).
2011-03-17 19:50:53 +01:00
timmywil eb1497c1fb Merge branch 'master' of git://github.com/jquery/jquery into 2773_find_closest 2011-03-16 14:44:31 -04:00
timmywil 929792834f Organizing vars 2011-03-16 14:41:26 -04:00
timmywil 7a69e34a5c 2773: first pass adding node/jQuery object support to jQuery.fn.find; unit tests added 2011-03-16 01:16:32 -04:00
Carl Fürstenberg 51abb3dc07 Changing dependice order for minify to prevent reminify
unless jquery.js has been updated, no minification should occur

closes: #8519
2011-03-16 01:44:05 +01:00
John Resig 0cf336d2c9 Merge branch 'bug_6158' of https://github.com/jboesch/jquery into jboesch-bug_6158 2011-03-15 17:06:24 -04:00
Carl Fürstenberg bd4468886d adding pull command 2011-03-15 21:42:58 +01:00
Carl Fürstenberg cd2ca7b591 pull submodules make command
Adding an helper funciton to pull the latest from all registered
submodules
2011-03-15 21:25:51 +01:00
Carl Fürstenberg 150d3decb5 Introduce submodules, closes #8536
Instead of the manual clone of sizzle and qunit, use git submodules
instead. this will ensure that all future releases can be recreated by
checking out an tag.
2011-03-15 20:16:09 +01:00
jaubourg 714ae379db Fixes #8509. Makes URL regexp less overzealous and ensures it recognizes URL schemes which do not contain a conformant hierarchical structure ( as per section 2.1.2 of http://www.ietf.org/rfc/rfc2718.txt ). Also adds about: and adobe air's app: and app-storage: to the list of local protocols and provides a failover in case document.location is illformed. Unit test added. 2011-03-15 19:20:03 +01:00
Jordan Boesch 124acbfbc5 removing parens 2011-03-14 14:17:02 -06:00
timmywil 8246347b71 Starting with adding the test 2011-03-13 21:12:10 -04:00
JessThrysoee 11c26b3cc9 no need to specifically initialize crossDomain to null 2011-03-11 17:46:59 +01:00
JessThrysoee 515c56f9c6 Make it possible to force the Ajax crossDomain option to false. 2011-03-11 00:17:38 +01:00
Dave Methvin 2ac4067a63 Fixes #8456. Make sure parent is not null before crawling into its lap, so mouseenter is triggered on a mouseover event. 2011-03-09 22:38:26 -05:00
louisremi c6b891fb1c Adding unit tests for #8403 2011-03-07 14:43:08 +01:00
jeresig d4e4414451 Very crude first pass at splitting apart the attr/prop logic. Also adding in attrHooks/propHooks. All of it is completely untested. 2011-03-06 22:47:40 -05:00
jaubourg 6c124d3dd4 Fixes #8423. Never set X-Requested-With header automagically for cross-domain requests. 2011-03-07 00:42:09 +01:00
Jordan Boesch dd100bf5ac bug 6158; fixing replaceWith from throwing errors on non existant elements; fixing semicolon 2011-03-05 09:59:25 -06:00
Jordan Boesch c9ef09c800 bug 6158; fixing replaceWith from throwing errors on non existant elements 2011-03-05 09:46:12 -06:00
Jordan Boesch 5c2d70979c bug 6158; fixing replaceWith from throwing errors on empty elements 2011-03-05 09:30:29 -06:00
Dave Methvin 55ec6a71d2 Fixes #7340. Use a single capturing handler to simulate bubbling focusin/focusout event on non-IE browsers. Allow native DOM methods to fire events other than the currently active one back into jQuery. 2011-03-04 21:16:40 -05:00
jaubourg 2d0bc7ce72 Moves Deferred-related code into a separate module. Context handling has been simplified in _Deferred.resolve and jQuery.when has been refactored for clarity (and minor optimization). 2011-03-03 19:38:06 +01:00
jaubourg c1279895f3 Fix for #8421. Makes sure resolveWith can be called with only one parameter. 2011-03-03 15:16:47 +01:00
louisremi 025f2c63e4 fixing both #8403 and #8401: jQuery \"bulldozes\" other IE filters when setting opacity 2011-03-01 00:54:15 +01:00
Jordan Boesch c8a887af06 Bug 2616; Adding object support to jQuery.map 2011-02-27 12:47:35 -06:00
timmywil 9e5ec378e3 Merge branch 'master' of git://github.com/jquery/jquery into bug_2773 2011-02-26 18:53:25 -05:00
gnarf 71bd828d9f Grouped up the test 2011-02-24 13:21:05 -06:00
gnarf 14e9da51f9 A quick change to detect AIR urls 2011-02-24 13:10:33 -06:00
jaubourg 58faec7cb7 Removes unnecessary parenthesis from regular expression. 2011-02-24 06:37:37 +01:00
jaubourg 5d9db486c7 Revert "Fixes #8353. Adds a catch block in resolveWith so that the finally block gets executed in IE7 and IE6."
This reverts commit cacea6f7e7.
2011-02-24 00:32:30 +01:00
jeresig 83d1a1fd56 Updating the source version to 1.5.2pre. 2011-02-23 13:55:45 -05:00
louisremi e27fcf42ce comments for workarounds are always welcome. 2011-02-23 15:55:13 +01:00
louisremi c5264ce196 fix the regular expression that turns camel-case properties to lower-case ones for IE9. Fixes #8346 2011-02-23 15:53:29 +01:00
Timmy Willison 82626799ca Changed $.sub internals to match sub naming, added some more spacing in some areas for readability 2011-02-06 19:34:57 -05:00
Timmy Willison ed48787ec5 Fix bug #2773, jQuery.fn.is to accept JQuery and node objects, and a small fix for winnow getting an undefined selector 2011-01-24 16:18:19 -05:00
Gianni Chiappetta 574ae3b1be added: Backcompatibility with old proxy syntax. 2011-01-21 10:33:50 -05:00
Gianni Chiappetta a03f040dbf Merge branch 'master' into proxy-native-bind
* master: (194 commits)
  Revert "Make sure that focusin/focusout bubbles in non-IE browsers." This was causing problems with the focusin event, see: #7340.
  Replaces "text in-between" technique with a full-fledged one-level transitive search for converters (unit tests added). Also cleans up auto dataType determination and adds converter checks in order to guess the best dataType possible.
  Moves determineResponse logic into main ajax callback. Puts responseXXX fields definitions into ajaxSettings.
  Removes misleading comment.
  Bring jQuery('#id') and jQuery('body') logic back into core (while leaving it in Sizzle at the same time). Was causing too much of a performance hit to leave it all to Sizzle.
  Renames Deferred's fire and fireReject methods as resolveWith and rejectWith respectively.
  Fix typo in regex tweak from previous commit.
  Renames determineDataType as determineResponse. Makes it more generic as a first step into integrating the logic into the main ajax done callback. Also fixes some comments in ajax/xhr.js.
  Move jQuery(...) selector speed-up logic into Sizzle(...) qSA handling. Additionally add in a new catch for Sizzle('.class') (avoid using qSA and use getElementsByClassName instead, where applicable).
  Revises the way arguments are handled in ajax.
  Makes sure statusCode callbacks are ordered in the same way success and error callbacks are. Unit tests added.
  Cleans up and simplifies code shared by ajaxPrefilter and ajaxTransport. Removes chainability of ajaxSetup, ajaxPrefilter and ajaxTransport. Also makes sure context is handled properly by ajaxSetup (unit test added).
  Rework unit tests to check actual result elements.
  Moves active counter test after all other ajax tests where it should be.
  Revised the Nokia support fallback. It turns out that Nokia supports the documentElement property but does not define document.compatMode. Adding this third fallback allows Nokia to run jQuery error-free and return proper values for window width and height.
  Moves things around to make jsLint happier.
  Fixes crossDomain test so that it assumes port to be 80 for http and 443 for https when it is not provided.
  Moves determineDataType into ajaxSettings so that it is accessible to transports without the need for a second argument and so that we can now pass the original options to the transport instead. Also ensures the original options are actually propagated to prefilters (they were not).
  Re-adds hastily removed variable and simplifies statusCode based callbacks handling.
  Use undefined instead of 0 to deference transport for clarity.
  ...

Conflicts:
	src/event.js
2011-01-21 09:58:55 -05:00
Xavi 135a384cf3 Bug 7931; cleaned up white space in accordance to style guide 2011-01-18 12:40:07 -05:00
Xavi 0942b3b3f5 Merge branch 'master' of git://github.com/jquery/jquery into bug_7931 2011-01-18 12:06:05 -05:00
Sylvester Keil 75655e5758 Use parseFloat instead of parseInt to read CSS values.
This fixes #7730 and #7885.
2011-01-15 13:56:20 +01:00
Xavi b78e3fc39f Bug 7931; Inverted logic in scrollTop/Left (i.e. made 2011-01-09 20:51:20 -05:00
Xavi bed64e65cc Bug 7931; Added unit tests for scrollTop/Left. 2011-01-09 20:39:23 -05:00
Xavi 8d28f41f66 Bug 7931; Replaced with and 2011-01-09 20:34:15 -05:00
Xavi 628bacc3ce Bug 7931; Added missing semicolon and replaced '!=' with '!==' to allow null through 2011-01-09 20:16:18 -05:00
Xavi d03d2e9f26 Bug 7931; Fixed bug that caused scrollTop and scrollLeft setters to return null when called on an empty jquery object 2011-01-09 19:11:05 -05:00
rwldrn 5f52e61d74 4321 jQuery('#') returns empty jquery object 2011-01-01 17:18:47 -05:00
rwldrn 037d6bd5c3 4321 returns empty jquery object 2011-01-01 17:13:04 -05:00
rwldrn 612a908514 #7883 .delegate and .live should accept false as the fn arg, like bind 2011-01-01 13:49:59 -05:00
Gianni Chiappetta ade531cfaa Noted which browsers don't support Function#bind. 2010-12-18 19:26:36 -05:00
Gianni Chiappetta 6bc9fc7c10 Perf. improvement based on fearphage's suggestion (direct vs call vs apply). 2010-12-18 19:17:37 -05:00
Gianni Chiappetta 1ebb5ab3e1 Added list of browsers that currently support Function#bind. 2010-12-16 16:04:23 -05:00
Gianni Chiappetta 5b1b57850c Add a quick test to $.support for native bind.
As per the suggestion by ajpiano: 9f8cd6c499 (commitcomment-218658)
2010-12-15 18:31:10 -05:00
Gianni Chiappetta 9f8cd6c499 Fixing $.proxy to work like (and use) Function.prototype.bind (ticket #7783)
http://bugs.jquery.com/ticket/7783
2010-12-14 21:53:04 -05:00
Jephte CLAIN 596f9a1f21 Merge branch 'master' of https://github.com/jclain/jquery 2010-11-22 08:31:17 +04:00
Jephte CLAIN dd79199a08 fix to follow current source style 2010-11-22 08:30:17 +04:00
Jephte CLAIN 1ac7b459a4 respect source guidelines 2010-11-22 08:12:12 +04:00
Jephte CLAIN 689d63f487 Return control of $ and jQuery only if it is really necessary. This make
jQuery.noConflict() callable anytime.
2010-10-19 09:32:13 +04:00
rjgotten df7dfc2404 Check against the type attribute of script elements retrieved through getElementsByTagName() so that only those elements of type "text/javascript" are handled by 'clean'.
Fixes #6180: jQuery.clean should not touch script tags that are not of type text/javascript
2010-10-17 08:30:05 -07:00
68 changed files with 6220 additions and 3281 deletions

2
.gitignore vendored
View File

@ -4,7 +4,5 @@ dist
*~
*.diff
*.patch
test/qunit
src/sizzle
/*.html
.DS_Store

6
.gitmodules vendored Normal file
View File

@ -0,0 +1,6 @@
[submodule "src/sizzle"]
path = src/sizzle
url = git://github.com/jquery/sizzle.git
[submodule "test/qunit"]
path = test/qunit
url = git://github.com/jquery/qunit.git

View File

@ -1,5 +1,3 @@
V ?= 0
SRC_DIR = src
TEST_DIR = test
BUILD_DIR = build
@ -12,6 +10,7 @@ COMPILER = ${JS_ENGINE} ${BUILD_DIR}/uglify.js --unsafe
POST_COMPILER = ${JS_ENGINE} ${BUILD_DIR}/post-compile.js
BASE_FILES = ${SRC_DIR}/core.js\
${SRC_DIR}/deferred.js\
${SRC_DIR}/support.js\
${SRC_DIR}/data.js\
${SRC_DIR}/queue.js\
@ -37,48 +36,21 @@ JQ = ${DIST_DIR}/jquery.js
JQ_MIN = ${DIST_DIR}/jquery.min.js
SIZZLE_DIR = ${SRC_DIR}/sizzle
QUNIT_DIR = ${TEST_DIR}/qunit
JQ_VER = $(shell cat version.txt)
VER = sed "s/@VERSION/${JQ_VER}/"
DATE=$(shell git log -1 --pretty=format:%ad)
all: jquery min lint
all: update_submodules core
core: jquery min lint
@@echo "jQuery build complete."
${DIST_DIR}:
@@mkdir -p ${DIST_DIR}
ifeq ($(strip $(V)),0)
verbose = --quiet
else ifeq ($(strip $(V)),1)
verbose =
else
verbose = --verbose
endif
define clone_or_pull
-@@if test ! -d $(strip ${1})/.git; then \
echo "Cloning $(strip ${1})..."; \
git clone $(strip ${verbose}) --depth=1 $(strip ${2}) $(strip ${1}); \
else \
echo "Pulling $(strip ${1})..."; \
git --git-dir=$(strip ${1})/.git pull $(strip ${verbose}) origin master; \
fi
endef
${QUNIT_DIR}:
$(call clone_or_pull, ${QUNIT_DIR}, git://github.com/jquery/qunit.git)
${SIZZLE_DIR}:
$(call clone_or_pull, ${SIZZLE_DIR}, git://github.com/jeresig/sizzle.git)
init: ${QUNIT_DIR} ${SIZZLE_DIR}
jquery: init ${JQ}
jq: init ${JQ}
jquery: ${JQ}
${JQ}: ${MODULES} | ${DIST_DIR}
@@echo "Building" ${JQ}
@ -101,9 +73,9 @@ lint: jquery
echo "You must have NodeJS installed in order to test jQuery against JSLint."; \
fi
min: ${JQ_MIN}
min: jquery ${JQ_MIN}
${JQ_MIN}: jquery
${JQ_MIN}: ${JQ}
@@if test ! -z ${JS_ENGINE}; then \
echo "Minifying jQuery" ${JQ_MIN}; \
${COMPILER} ${JQ} > ${JQ_MIN}.tmp; \
@ -121,7 +93,28 @@ clean:
@@echo "Removing built copy of Sizzle"
@@rm -f src/selector.js
@@echo "Removing cloned directories"
distclean: clean
@@echo "Removing submodules"
@@rm -rf test/qunit src/sizzle
.PHONY: all jquery lint min init jq clean
# change pointers for submodules and update them to what is specified in jQuery
# --merge doesn't work when doing an initial clone, thus test if we have non-existing
# submodules, then do an real update
update_submodules:
@@if [ -d .git ]; then \
if git submodule status | grep -q -E '^-'; then \
git submodule update --init --recursive; \
else \
git submodule update --init --recursive --merge; \
fi; \
fi;
# update the submodules to the latest at the most logical branch
pull_submodules:
@@git submodule foreach "git pull \$$(git config remote.origin.url)"
@@git submodule summary
pull: pull_submodules
@@git pull ${REMOTE} ${BRANCH}
.PHONY: all jquery lint min clean distclean update_submodules pull_submodules pull core

View File

@ -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?
----------

View File

@ -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

View File

@ -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
View 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
View 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
View 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 );
}

View File

@ -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);

View File

@ -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 = /(?:^file|^widget|\-extension):$/,
rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,
rnoContent = /^(?:GET|HEAD)$/,
rprotocol = /^\/\//,
rquery = /\?/,
@ -15,11 +15,7 @@ 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+))?/,
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
// Keep a copy of the old load method
_load = jQuery.fn.load,
@ -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
@ -61,7 +57,7 @@ try {
}
// Segment location into parts
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() );
ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
function addToPrefiltersOrTransports( structure ) {
@ -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({
@ -319,7 +315,6 @@ jQuery.extend({
cache: null,
traditional: false,
headers: {},
crossDomain: null,
*/
accepts: {
@ -394,6 +389,7 @@ jQuery.extend({
ifModifiedKey,
// Headers (they are sent all at once)
requestHeaders = {},
requestHeadersNames = {},
// Response headers
responseHeadersString,
responseHeaders,
@ -417,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;
},
@ -604,7 +602,7 @@ jQuery.extend({
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
// Determine if a cross-domain request is in order
if ( !s.crossDomain ) {
if ( s.crossDomain == null ) {
parts = rurl.exec( s.url.toLowerCase() );
s.crossDomain = !!( parts &&
( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
@ -646,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
@ -665,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 ) {
@ -726,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 {
@ -758,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
@ -774,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 ) ) {
@ -794,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 {

View File

@ -1,7 +1,7 @@
(function( jQuery ) {
var jsc = jQuery.now(),
jsre = /(\=)\?(&|$)|()\?\?()/i;
jsre = /(\=)\?(&|$)|\?\?/i;
// Default jsonp settings
jQuery.ajaxSetup({
@ -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 );

View File

@ -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 );

View File

@ -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 ) {
@ -92,11 +83,12 @@ if ( jQuery.support.ajax ) {
xhr.overrideMimeType( s.mimeType );
}
// Requested-With header
// Not set for crossDomain requests with no content
// (see why at http://trac.dojotoolkit.org/ticket/9486)
// Won't change header if already provided
if ( !( s.crossDomain && !s.hasContent ) && !headers["X-Requested-With"] ) {
// X-Requested-With header
// For cross-domain requests, seeing as conditions for a preflight are
// akin to a jigsaw puzzle, we simply never set it to be sure.
// (it can always be set on a per-request basis or even using ajaxSetup)
// For same-domain requests, won't change header if already provided.
if ( !s.crossDomain && !headers["X-Requested-With"] ) {
headers[ "X-Requested-With" ] = "XMLHttpRequest";
}
@ -135,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
@ -196,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;
}
},

View File

@ -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 );

View File

@ -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,21 +44,23 @@ 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,
// For matching the engine and version of the browser
browserMatch,
// Has the ready events already been bound?
readyBound = false,
// The deferred used on DOM ready
readyList,
// Promise methods
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
// The ready event handler
DOMContentLoaded,
@ -94,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;
}
@ -102,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) ) {
@ -359,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;
}
@ -375,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 );
@ -408,11 +422,11 @@ jQuery.extend({
},
bindReady: function() {
if ( readyBound ) {
if ( readyList ) {
return;
}
readyBound = true;
readyList = jQuery._Deferred();
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
@ -433,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 );
@ -521,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
@ -561,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();
},
@ -590,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 ) {
@ -616,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;
}
}
}
}
@ -648,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 );
@ -661,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++ ) {
@ -712,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;
}
}
}
@ -731,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;
@ -792,171 +824,6 @@ jQuery.extend({
return (new Date()).getTime();
},
// Create a simple deferred (one callbacks list)
_Deferred: function() {
var // callbacks list
callbacks = [],
// stored [ context , args ]
fired,
// to avoid firing when already doing so
firing,
// flag to know if the deferred has been cancelled
cancelled,
// the deferred itself
deferred = {
// done( f1, f2, ...)
done: function() {
if ( !cancelled ) {
var args = arguments,
i,
length,
elem,
type,
_fired;
if ( fired ) {
_fired = fired;
fired = 0;
}
for ( i = 0, length = args.length; i < length; i++ ) {
elem = args[ i ];
type = jQuery.type( elem );
if ( type === "array" ) {
deferred.done.apply( deferred, elem );
} else if ( type === "function" ) {
callbacks.push( elem );
}
}
if ( _fired ) {
deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
}
}
return this;
},
// resolve with given context and args
resolveWith: function( context, args ) {
if ( !cancelled && !fired && !firing ) {
firing = 1;
try {
while( callbacks[ 0 ] ) {
callbacks.shift().apply( context, args );
}
}
// We have to add a catch block for
// IE prior to 8 or else the finally
// block will never get executed
catch (e) {
throw e;
}
finally {
fired = [ context, args ];
firing = 0;
}
}
return this;
},
// resolve with this as context and given arguments
resolve: function() {
deferred.resolveWith( jQuery.isFunction( this.promise ) ? this.promise() : this, arguments );
return this;
},
// Has this deferred been resolved?
isResolved: function() {
return !!( firing || fired );
},
// Cancel
cancel: function() {
cancelled = 1;
callbacks = [];
return this;
}
};
return deferred;
},
// Full fledged deferred (two callbacks list)
Deferred: function( func ) {
var deferred = jQuery._Deferred(),
failDeferred = jQuery._Deferred(),
promise;
// Add errorDeferred methods, then and promise
jQuery.extend( deferred, {
then: function( doneCallbacks, failCallbacks ) {
deferred.done( doneCallbacks ).fail( failCallbacks );
return this;
},
fail: failDeferred.done,
rejectWith: failDeferred.resolveWith,
reject: failDeferred.resolve,
isRejected: failDeferred.isResolved,
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
if ( obj == null ) {
if ( promise ) {
return promise;
}
promise = obj = {};
}
var i = promiseMethods.length;
while( i-- ) {
obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
}
return obj;
}
} );
// Make sure only one callback list will be used
deferred.done( failDeferred.cancel ).fail( deferred.cancel );
// Unexpose cancel
delete deferred.cancel;
// Call given func if any
if ( func ) {
func.call( deferred, deferred );
}
return deferred;
},
// Deferred helper
when: function( object ) {
var lastIndex = arguments.length,
deferred = lastIndex <= 1 && object && jQuery.isFunction( object.promise ) ?
object :
jQuery.Deferred(),
promise = deferred.promise();
if ( lastIndex > 1 ) {
var array = slice.call( arguments, 0 ),
count = lastIndex,
iCallback = function( index ) {
return function( value ) {
array[ index ] = arguments.length > 1 ? slice.call( arguments, 0 ) : value;
if ( !( --count ) ) {
deferred.resolveWith( promise, array );
}
};
};
while( ( lastIndex-- ) ) {
object = array[ lastIndex ];
if ( object && jQuery.isFunction( object.promise ) ) {
object.promise().then( iCallback(lastIndex), deferred.reject );
} else {
--count;
}
}
if ( !count ) {
deferred.resolveWith( promise, array );
}
} else if ( deferred !== object ) {
deferred.resolve( object );
}
return promise;
},
// Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser
uaMatch: function( ua ) {
@ -972,32 +839,29 @@ 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: {}
});
// Create readyList deferred
readyList = jQuery._Deferred();
// Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
@ -1014,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]+/;
@ -1065,7 +923,6 @@ function doScrollCheck() {
jQuery.ready();
}
// Expose jQuery to the global object
return jQuery;
})();

View File

@ -2,10 +2,12 @@
var ralpha = /alpha\([^)]*\)/i,
ropacity = /opacity=([^)]*)/,
rdashAlpha = /-([a-z])/ig,
rupper = /([A-Z])/g,
// 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" ],
@ -13,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
@ -52,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
@ -74,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";
}
@ -112,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 ) {
@ -124,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 );
}
},
@ -144,10 +160,6 @@ jQuery.extend({
for ( name in options ) {
elem.style[ name ] = old[ name ];
}
},
camelCase: function( string ) {
return string.replace( rdashAlpha, fcamelCase );
}
});
@ -161,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";
@ -215,33 +204,56 @@ 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;
}
};
}
jQuery(function() {
// This hook cannot be added until DOM ready because the support test
// for it is not run until after DOM ready
if ( !jQuery.support.reliableMarginRight ) {
jQuery.cssHooks.marginRight = {
get: function( elem, computed ) {
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
// Work around by temporarily setting element display to inline-block
var ret;
jQuery.swap( elem, { "display": "inline-block" }, function() {
if ( computed ) {
ret = curCSS( elem, "margin-right", "marginRight" );
} else {
ret = elem.style.marginRight;
}
});
return ret;
}
};
}
});
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();
@ -298,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 ) {

View File

@ -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 {

199
src/deferred.js Normal file
View File

@ -0,0 +1,199 @@
(function( jQuery ) {
var // Promise methods
promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
// Static reference to slice
sliceDeferred = [].slice;
jQuery.extend({
// Create a simple deferred (one callbacks list)
_Deferred: function() {
var // callbacks list
callbacks = [],
// stored [ context , args ]
fired,
// to avoid firing when already doing so
firing,
// flag to know if the deferred has been cancelled
cancelled,
// the deferred itself
deferred = {
// done( f1, f2, ...)
done: function() {
if ( !cancelled ) {
var args = arguments,
i,
length,
elem,
type,
_fired;
if ( fired ) {
_fired = fired;
fired = 0;
}
for ( i = 0, length = args.length; i < length; i++ ) {
elem = args[ i ];
type = jQuery.type( elem );
if ( type === "array" ) {
deferred.done.apply( deferred, elem );
} else if ( type === "function" ) {
callbacks.push( elem );
}
}
if ( _fired ) {
deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
}
}
return this;
},
// resolve with given context and args
resolveWith: function( context, args ) {
if ( !cancelled && !fired && !firing ) {
// make sure args are available (#8421)
args = args || [];
firing = 1;
try {
while( callbacks[ 0 ] ) {
callbacks.shift().apply( context, args );
}
}
finally {
fired = [ context, args ];
firing = 0;
}
}
return this;
},
// resolve with this as context and given arguments
resolve: function() {
deferred.resolveWith( this, arguments );
return this;
},
// Has this deferred been resolved?
isResolved: function() {
return !!( firing || fired );
},
// Cancel
cancel: function() {
cancelled = 1;
callbacks = [];
return this;
}
};
return deferred;
},
// Full fledged deferred (two callbacks list)
Deferred: function( func ) {
var deferred = jQuery._Deferred(),
failDeferred = jQuery._Deferred(),
promise;
// Add errorDeferred methods, then and promise
jQuery.extend( deferred, {
then: function( doneCallbacks, failCallbacks ) {
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 ) {
if ( obj == null ) {
if ( promise ) {
return promise;
}
promise = obj = {};
}
var i = promiseMethods.length;
while( i-- ) {
obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
}
return obj;
}
});
// Make sure only one callback list will be used
deferred.done( failDeferred.cancel ).fail( deferred.cancel );
// Unexpose cancel
delete deferred.cancel;
// Call given func if any
if ( func ) {
func.call( deferred, deferred );
}
return deferred;
},
// Deferred helper
when: function( firstParam ) {
var args = arguments,
i = 0,
length = args.length,
count = length,
deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
firstParam :
jQuery.Deferred();
function resolveFunc( i ) {
return function( value ) {
args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
if ( !( --count ) ) {
// Strange bug in FF4:
// Values changed onto the arguments object sometimes end up as undefined values
// outside the $.when method. Cloning the object into a fresh array solves the issue
deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) );
}
};
}
if ( length > 1 ) {
for( ; i < length; i++ ) {
if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) {
args[ i ].promise().then( resolveFunc(i), deferred.reject );
} else {
--count;
}
}
if ( !count ) {
deferred.resolveWith( deferred, args );
}
} else if ( deferred !== firstParam ) {
deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
}
return deferred.promise();
}
});
})( jQuery );

View File

@ -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
View File

@ -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;
}

View File

@ -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 ) {
@ -70,10 +59,10 @@ jQuery.event = {
}
if ( !eventHandle ) {
elemData.handle = eventHandle = function() {
// 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 ?
elemData.handle = eventHandle = function( e ) {
// 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 = true;
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 = false;
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 !== 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,27 +858,43 @@ 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() {
this.addEventListener( orig, handler, true );
if ( attaches++ === 0 ) {
document.addEventListener( orig, handler, true );
}
},
teardown: function() {
this.removeEventListener( orig, handler, true );
if ( --attaches === 0 ) {
document.removeEventListener( orig, handler, true );
}
}
};
function handler( e ) {
e = jQuery.event.fix( e );
function handler( donor ) {
// Donor event is always a native one; fix it and switch its type.
// Let focusin/out handler cancel the donor focus/blur event.
var e = jQuery.event.fix( donor );
e.type = fix;
return jQuery.event.handle.call( this, e );
e.originalEvent = {};
jQuery.event.trigger( e, null, e.target );
if ( e.isDefaultPrevented() ) {
donor.preventDefault();
}
}
});
}
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 ) {
@ -895,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 );
@ -941,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 );
@ -956,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 ) {
@ -1013,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;
}
@ -1036,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;
@ -1107,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 ) {
@ -1145,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 " +
@ -1170,3 +1195,4 @@ jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblcl
});
})( jQuery );

View File

@ -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;

View File

@ -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;
@ -261,7 +263,9 @@ jQuery.fn.extend({
}
});
} else {
return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
return this.length ?
this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
this;
}
},
@ -375,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
@ -428,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
@ -439,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;
}
}
@ -492,7 +514,7 @@ jQuery.each({
function getAll( elem ) {
if ( "getElementsByTagName" in elem ) {
return elem.getElementsByTagName( "*" );
} else if ( "querySelectorAll" in elem ) {
return elem.querySelectorAll( "*" );
@ -501,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),
@ -545,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'
@ -556,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" ) {
@ -568,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 ) {
@ -626,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] );
}
@ -694,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 ) {
@ -702,4 +762,4 @@ function evalScript( i, elem ) {
}
}
})( jQuery );
})( jQuery );

View File

@ -37,8 +37,8 @@ if ( "getBoundingClientRect" in document.documentElement ) {
win = getWindow(doc),
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,
scrollTop = (win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop ),
scrollLeft = (win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft),
scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
top = box.top + scrollTop - clientTop,
left = box.left + scrollLeft - clientLeft;
@ -151,7 +151,6 @@ jQuery.offset = {
this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop);
body.removeChild( container );
body = container = innerDiv = checkDiv = table = td = null;
jQuery.offset.initialize = jQuery.noop;
},
@ -181,17 +180,19 @@ jQuery.offset = {
curOffset = curElem.offset(),
curCSSTop = jQuery.css( elem, "top" ),
curCSSLeft = jQuery.css( elem, "left" ),
calculatePosition = (position === "absolute" && 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 absolute
// 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 );
}
@ -260,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
@ -291,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;
}
});
};
});

View File

@ -1,2 +1,3 @@
// Expose jQuery to the global object
window.jQuery = window.$ = jQuery;
})(window);

View File

@ -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
src/sizzle Submodule

@ -0,0 +1 @@
Subproject commit 3ba396e439a07c2a2facafbe07cdaa1b80a24c00

View File

@ -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,174 +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();
try {
script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
} catch(e) {}
root.insertBefore( script, root.firstChild );
// 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)
if ( window[ id ] ) {
_scriptEval = true;
delete window[ id ];
} else {
_scriptEval = false;
}
root.removeChild( script );
// release memory in IE
root = script = id = null;
}
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";
body.removeChild( div ).style.display = "none";
div = tds = null;
});
// Check if empty table cells still have offsetWidth/Height
// (IE < 8 fail this test)
support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
div.innerHTML = "";
// 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";
}
el = null;
// Null connected elements to avoid leaks in IE
testElement = fragment = select = opt = body = marginDiv = div = input = null;
return isSupported;
};
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 );

View File

@ -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 );

View File

@ -6,6 +6,7 @@
<title>CSP Test Page</title>
<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>

View File

@ -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>

View File

@ -16,6 +16,7 @@
#positionTest { position: absolute; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>

View File

@ -9,6 +9,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>

View File

@ -13,6 +13,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>
@ -34,6 +35,7 @@
<body>
<div id="fixed-1" class="fixed"></div>
<div id="fixed-2" class="fixed"></div>
<div id="fixed-no-top-left" class="fixed"></div>
<div id="forceScroll"></div>
<div id="marker"></div>
<p class="instructions">Click the white box to move the marker to it.</p>

View File

@ -11,6 +11,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>

View File

@ -14,6 +14,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>

View File

@ -11,6 +11,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>

View File

@ -11,6 +11,7 @@
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
</style>
<script src="../../../src/core.js"></script>
<script src="../../../src/deferred.js"></script>
<script src="../../../src/support.js"></script>
<script src="../../../src/sizzle/sizzle.js"></script>
<script src="../../../src/sizzle-jquery.js"></script>

View File

@ -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);
}
}

View 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>

View 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>

View 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>

View File

@ -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;
})();

View File

@ -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; }

View 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"));
}
})();

View File

@ -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>

View File

@ -9,6 +9,7 @@
<script src="data/testinit.js"></script>
<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>
@ -27,10 +28,14 @@
<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>
<script src="unit/attributes.js"></script>
@ -46,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>
@ -56,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>,
@ -201,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>

View File

@ -5,6 +5,7 @@
<title>jQuery Local File Test</title>
<!-- Includes -->
<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>

View File

@ -16,6 +16,7 @@
div { margin-top: 10px; }
</style>
<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>

1
test/qunit Submodule

@ -0,0 +1 @@
Subproject commit d4f23f8a882d13b71768503e2db9fa33ef169ba0

View File

@ -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; }
@ -15,6 +15,7 @@
#expectedOutput { background-color: green }
</style>
<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>
@ -51,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
@ -67,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>

View File

@ -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" );
});
@ -492,7 +507,7 @@ test(".ajax() - hash", function() {
test("jQuery ajax - cross-domain detection", function() {
expect( 4 );
expect( 6 );
var loc = document.location,
otherPort = loc.port === 666 ? 667 : 666,
@ -509,7 +524,16 @@ test("jQuery ajax - cross-domain detection", function() {
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + '//somewebsitethatdoesnotexist-656329477541.com:' + ( loc.port || 80 ),
url: "app:/path",
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Adobe AIR app:/ URL detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
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;
@ -525,6 +549,15 @@ test("jQuery ajax - cross-domain detection", function() {
}
});
jQuery.ajax({
dataType: "jsonp",
url: "about:blank",
beforeSend: function( _ , s ) {
ok( s.crossDomain , "Test about:blank is detected as cross-domain" );
return false;
}
});
jQuery.ajax({
dataType: "jsonp",
url: loc.protocol + "//" + loc.host,
@ -541,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" );
@ -565,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" );
@ -610,7 +643,7 @@ test("Ajax events with context", function() {
};
}
jQuery('#foo').add(context)
jQuery("#foo").add(context)
.ajaxSend(event)
.ajaxComplete(event)
.ajaxError(event)
@ -632,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"),
@ -716,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" );
@ -750,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();
}
});
@ -765,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) {
@ -786,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"),
@ -794,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();
}
});
@ -873,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();
};
@ -884,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);
}
});
@ -895,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" );
@ -938,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&regularThing=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?" };
@ -956,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" );
@ -974,7 +1002,7 @@ test("jQuery.param()", function() {
params = {someName: [1, 2, 3], regularThing: "blah" };
equals( jQuery.param(params), "someName=1&someName=2&someName=3&regularThing=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"]};
@ -995,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" );
});
@ -1026,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();
});
@ -1083,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;
});
@ -1102,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();
});
@ -1124,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();
});
});
@ -1141,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);
});
});
@ -1158,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();
});
@ -1182,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();
});
});
@ -1194,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();
});
});
@ -1208,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
});
@ -1220,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();
});
});
@ -1235,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);
});
@ -1582,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();
}
});
@ -1618,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();
}
});
@ -1642,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();
}
});
@ -1656,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();
});
});
@ -1669,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();
});
@ -1702,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();
});
});
@ -1713,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 );
@ -1742,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();
});
@ -1768,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",
@ -1801,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();
}
});
@ -1821,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();
}
});
@ -1835,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();
}
});
@ -1847,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();
}
});
@ -2009,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(); }
@ -2029,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(); }
@ -2241,4 +2269,4 @@ test("jQuery.ajax - active counter", function() {
}
//}
//}

File diff suppressed because it is too large Load Diff

View File

@ -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}");
@ -914,221 +984,6 @@ test("jQuery.parseJSON", function(){
}
});
test("jQuery._Deferred()", function() {
expect( 10 );
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();
}
test = "";
deferred = jQuery._Deferred().done( function() {
test += "A";
}, function() {
test += "B";
} ).resolve();
strictEqual( test , "AB" , "Test multiple done parameters" );
test = "";
deferred.done( function() {
deferred.done( function() {
test += "C";
} );
test += "A";
}, function() {
test += "B";
} );
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" );
});
});
test("jQuery.Deferred()", function() {
expect( 10 );
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" );
});
jQuery.Deferred().resolve().then( function() {
ok( true , "Success on resolve" );
}, function() {
ok( false , "Error on resolve" );
});
jQuery.Deferred().reject().then( function() {
ok( false , "Success on reject" );
}, function() {
ok( true , "Error on reject" );
});
( 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" );
});
test("jQuery.when()", function() {
expect( 23 );
// Some other objects
jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
"a number other than zero": 1,
"true": true,
"false": false,
"null": null,
"undefined": undefined,
"a plain object": {}
} , function( message , value ) {
ok( jQuery.isFunction( jQuery.when( value ).then( function( resolveValue ) {
strictEqual( resolveValue , value , "Test the promise was resolved with " + message );
} ).promise ) , "Test " + message + " triggers the creation of a new Promise" );
} );
ok( jQuery.isFunction( jQuery.when().then( 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" );
var cache, i;
for( i = 1 ; i < 4 ; i++ ) {
jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
}) ).then( function( value ) {
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
}, function() {
ok( false , "Fail called" );
});
}
});
test("jQuery.when() - joined", function() {
expect(8);
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 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" );
});
});
test("jQuery.sub() - Static Methods", function(){
expect(18);
var Subclass = jQuery.sub();
@ -1136,46 +991,46 @@ 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);
}
});
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(){
@ -1186,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];
@ -1217,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"
);
});
@ -1249,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 );
});
});

View File

@ -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 () {
@ -333,3 +418,70 @@ test("internal ref to elem.runtimeStyle (bug #7608)", function () {
ok( result, "elem.runtimeStyle does not throw exception" );
});
test("marginRight computed style (bug #3333)", function() {
expect(1);
var $div = jQuery("#foo");
$div.css({
width: "1px",
marginRight: 0
});
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'");
});
});

View File

@ -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");
});
});

383
test/unit/deferred.js Normal file
View File

@ -0,0 +1,383 @@
module("deferred", { teardown: moduleTeardown });
jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
function createDeferred() {
return withNew ? new jQuery._Deferred() : jQuery._Deferred();
}
test("jQuery._Deferred" + withNew, function() {
expect( 11 );
var deferred,
object,
test;
deferred = createDeferred();
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 = 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() {
deferred.done( function() {
test += "C";
} );
test += "A";
}, function() {
test += "B";
} );
strictEqual( test , "ABC" , "Test done callbacks order" );
deferred = createDeferred();
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" );
} );
jQuery.Deferred().reject().pipe( null, jQuery.noop ).fail(function( value ) {
strictEqual( value, undefined, "pipe fail callback can return undefined/null" );
});
});
test( "jQuery.Deferred.pipe - deferred (done)", function() {
expect(3);
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;
});
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" );
});
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 );
// Some other objects
jQuery.each( {
"an empty string": "",
"a non-empty string": "some string",
"zero": 0,
"a number other than zero": 1,
"true": true,
"false": false,
"null": null,
"undefined": undefined,
"a plain object": {}
} , function( message , value ) {
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" );
} );
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" );
var cache, i;
for( i = 1 ; i < 4 ; i++ ) {
jQuery.when( cache || jQuery.Deferred( function() {
this.resolve( i );
}) ).done(function( value ) {
strictEqual( value , 1 , "Function executed" + ( i > 1 ? " only once" : "" ) );
cache = value;
});
}
});
test("jQuery.when - joined", function() {
expect(25);
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
};
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 );
});

View File

@ -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
View File

@ -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();
}
});
});

View File

@ -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();
@ -683,12 +766,63 @@ test("hover()", function() {
equals( times, 4, "hover handlers fired" );
});
test("mouseover triggers mouseenter", function() {
expect(1);
var count = 0,
elem = jQuery("<a />");
elem.mouseenter(function () {
count++;
});
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;
@ -702,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" );
@ -758,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" );
@ -779,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"]);
@ -794,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;
}
@ -802,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;
}
@ -840,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" );
@ -861,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();
@ -883,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");
@ -903,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();
@ -938,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)" );
@ -982,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
@ -1098,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
@ -1111,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
@ -1193,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();
@ -1210,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." );
@ -1234,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;
@ -1625,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
@ -1724,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();
@ -1741,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." );
@ -1762,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;
@ -1942,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() {
@ -1966,15 +2168,124 @@ test("window resize", function() {
ok( !jQuery._data(window, "__events__"), "Make sure all the events are gone." );
});
/*
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("focusin bubbles", function() {
expect(5);
var input = jQuery( "<input type='text' />" ).prependTo( "body" ),
order = 0;
jQuery( "body" ).bind( "focusin.focusinBubblesTest", function(){
equals( 1, order++, "focusin on the body second" );
});
input.bind( "focusin.focusinBubblesTest", function(){
equals( 0, order++, "focusin on the element first" );
});
// 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" );
input.remove();
jQuery( "body" ).unbind( "focusin.focusinBubblesTest" );
});
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) {
@ -1983,3 +2294,4 @@ test("event properties", function() {
}).click();
});
*/

File diff suppressed because it is too large Load Diff

View File

@ -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 });
@ -265,13 +265,13 @@ testoffset("static", function( jQuery ) {
});
testoffset("fixed", function( jQuery ) {
expect(28);
expect(30);
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,47 +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");
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" );
}
});
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";
@ -379,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() {
@ -422,6 +441,32 @@ test("offsetParent", function(){
equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." );
});
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() {
@ -445,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, visiblity: '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;
}

View File

@ -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
View 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" );
});

View File

@ -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() {

View File

@ -1 +1 @@
1.5.1
1.6.3pre