/documentation/vendor/jquery-1.6.4.js

http://github.com/jashkenas/coffee-script · JavaScript · 9046 lines · 6894 code · 1275 blank · 877 comment · 1463 complexity · c677462551f4cc0f2af192497b50f3f5 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*!
  2. * jQuery JavaScript Library v1.6.4
  3. * http://jquery.com/
  4. *
  5. * Copyright 2011, John Resig
  6. * Dual licensed under the MIT or GPL Version 2 licenses.
  7. * http://jquery.org/license
  8. *
  9. * Includes Sizzle.js
  10. * http://sizzlejs.com/
  11. * Copyright 2011, The Dojo Foundation
  12. * Released under the MIT, BSD, and GPL Licenses.
  13. *
  14. * Date: Mon Sep 12 18:54:48 2011 -0400
  15. */
  16. (function( window, undefined ) {
  17. // Use the correct document accordingly with window argument (sandbox)
  18. var document = window.document,
  19. navigator = window.navigator,
  20. location = window.location;
  21. var jQuery = (function() {
  22. // Define a local copy of jQuery
  23. var jQuery = function( selector, context ) {
  24. // The jQuery object is actually just the init constructor 'enhanced'
  25. return new jQuery.fn.init( selector, context, rootjQuery );
  26. },
  27. // Map over jQuery in case of overwrite
  28. _jQuery = window.jQuery,
  29. // Map over the $ in case of overwrite
  30. _$ = window.$,
  31. // A central reference to the root jQuery(document)
  32. rootjQuery,
  33. // A simple way to check for HTML strings or ID strings
  34. // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
  35. quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
  36. // Check if a string has a non-whitespace character in it
  37. rnotwhite = /\S/,
  38. // Used for trimming whitespace
  39. trimLeft = /^\s+/,
  40. trimRight = /\s+$/,
  41. // Check for digits
  42. rdigit = /\d/,
  43. // Match a standalone tag
  44. rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
  45. // JSON RegExp
  46. rvalidchars = /^[\],:{}\s]*$/,
  47. rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
  48. rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
  49. rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
  50. // Useragent RegExp
  51. rwebkit = /(webkit)[ \/]([\w.]+)/,
  52. ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
  53. rmsie = /(msie) ([\w.]+)/,
  54. rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
  55. // Matches dashed string for camelizing
  56. rdashAlpha = /-([a-z]|[0-9])/ig,
  57. rmsPrefix = /^-ms-/,
  58. // Used by jQuery.camelCase as callback to replace()
  59. fcamelCase = function( all, letter ) {
  60. return ( letter + "" ).toUpperCase();
  61. },
  62. // Keep a UserAgent string for use with jQuery.browser
  63. userAgent = navigator.userAgent,
  64. // For matching the engine and version of the browser
  65. browserMatch,
  66. // The deferred used on DOM ready
  67. readyList,
  68. // The ready event handler
  69. DOMContentLoaded,
  70. // Save a reference to some core methods
  71. toString = Object.prototype.toString,
  72. hasOwn = Object.prototype.hasOwnProperty,
  73. push = Array.prototype.push,
  74. slice = Array.prototype.slice,
  75. trim = String.prototype.trim,
  76. indexOf = Array.prototype.indexOf,
  77. // [[Class]] -> type pairs
  78. class2type = {};
  79. jQuery.fn = jQuery.prototype = {
  80. constructor: jQuery,
  81. init: function( selector, context, rootjQuery ) {
  82. var match, elem, ret, doc;
  83. // Handle $(""), $(null), or $(undefined)
  84. if ( !selector ) {
  85. return this;
  86. }
  87. // Handle $(DOMElement)
  88. if ( selector.nodeType ) {
  89. this.context = this[0] = selector;
  90. this.length = 1;
  91. return this;
  92. }
  93. // The body element only exists once, optimize finding it
  94. if ( selector === "body" && !context && document.body ) {
  95. this.context = document;
  96. this[0] = document.body;
  97. this.selector = selector;
  98. this.length = 1;
  99. return this;
  100. }
  101. // Handle HTML strings
  102. if ( typeof selector === "string" ) {
  103. // Are we dealing with HTML string or an ID?
  104. if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
  105. // Assume that strings that start and end with <> are HTML and skip the regex check
  106. match = [ null, selector, null ];
  107. } else {
  108. match = quickExpr.exec( selector );
  109. }
  110. // Verify a match, and that no context was specified for #id
  111. if ( match && (match[1] || !context) ) {
  112. // HANDLE: $(html) -> $(array)
  113. if ( match[1] ) {
  114. context = context instanceof jQuery ? context[0] : context;
  115. doc = (context ? context.ownerDocument || context : document);
  116. // If a single string is passed in and it's a single tag
  117. // just do a createElement and skip the rest
  118. ret = rsingleTag.exec( selector );
  119. if ( ret ) {
  120. if ( jQuery.isPlainObject( context ) ) {
  121. selector = [ document.createElement( ret[1] ) ];
  122. jQuery.fn.attr.call( selector, context, true );
  123. } else {
  124. selector = [ doc.createElement( ret[1] ) ];
  125. }
  126. } else {
  127. ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
  128. selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes;
  129. }
  130. return jQuery.merge( this, selector );
  131. // HANDLE: $("#id")
  132. } else {
  133. elem = document.getElementById( match[2] );
  134. // Check parentNode to catch when Blackberry 4.6 returns
  135. // nodes that are no longer in the document #6963
  136. if ( elem && elem.parentNode ) {
  137. // Handle the case where IE and Opera return items
  138. // by name instead of ID
  139. if ( elem.id !== match[2] ) {
  140. return rootjQuery.find( selector );
  141. }
  142. // Otherwise, we inject the element directly into the jQuery object
  143. this.length = 1;
  144. this[0] = elem;
  145. }
  146. this.context = document;
  147. this.selector = selector;
  148. return this;
  149. }
  150. // HANDLE: $(expr, $(...))
  151. } else if ( !context || context.jquery ) {
  152. return (context || rootjQuery).find( selector );
  153. // HANDLE: $(expr, context)
  154. // (which is just equivalent to: $(context).find(expr)
  155. } else {
  156. return this.constructor( context ).find( selector );
  157. }
  158. // HANDLE: $(function)
  159. // Shortcut for document ready
  160. } else if ( jQuery.isFunction( selector ) ) {
  161. return rootjQuery.ready( selector );
  162. }
  163. if (selector.selector !== undefined) {
  164. this.selector = selector.selector;
  165. this.context = selector.context;
  166. }
  167. return jQuery.makeArray( selector, this );
  168. },
  169. // Start with an empty selector
  170. selector: "",
  171. // The current version of jQuery being used
  172. jquery: "1.6.4",
  173. // The default length of a jQuery object is 0
  174. length: 0,
  175. // The number of elements contained in the matched element set
  176. size: function() {
  177. return this.length;
  178. },
  179. toArray: function() {
  180. return slice.call( this, 0 );
  181. },
  182. // Get the Nth element in the matched element set OR
  183. // Get the whole matched element set as a clean array
  184. get: function( num ) {
  185. return num == null ?
  186. // Return a 'clean' array
  187. this.toArray() :
  188. // Return just the object
  189. ( num < 0 ? this[ this.length + num ] : this[ num ] );
  190. },
  191. // Take an array of elements and push it onto the stack
  192. // (returning the new matched element set)
  193. pushStack: function( elems, name, selector ) {
  194. // Build a new jQuery matched element set
  195. var ret = this.constructor();
  196. if ( jQuery.isArray( elems ) ) {
  197. push.apply( ret, elems );
  198. } else {
  199. jQuery.merge( ret, elems );
  200. }
  201. // Add the old object onto the stack (as a reference)
  202. ret.prevObject = this;
  203. ret.context = this.context;
  204. if ( name === "find" ) {
  205. ret.selector = this.selector + (this.selector ? " " : "") + selector;
  206. } else if ( name ) {
  207. ret.selector = this.selector + "." + name + "(" + selector + ")";
  208. }
  209. // Return the newly-formed element set
  210. return ret;
  211. },
  212. // Execute a callback for every element in the matched set.
  213. // (You can seed the arguments with an array of args, but this is
  214. // only used internally.)
  215. each: function( callback, args ) {
  216. return jQuery.each( this, callback, args );
  217. },
  218. ready: function( fn ) {
  219. // Attach the listeners
  220. jQuery.bindReady();
  221. // Add the callback
  222. readyList.done( fn );
  223. return this;
  224. },
  225. eq: function( i ) {
  226. return i === -1 ?
  227. this.slice( i ) :
  228. this.slice( i, +i + 1 );
  229. },
  230. first: function() {
  231. return this.eq( 0 );
  232. },
  233. last: function() {
  234. return this.eq( -1 );
  235. },
  236. slice: function() {
  237. return this.pushStack( slice.apply( this, arguments ),
  238. "slice", slice.call(arguments).join(",") );
  239. },
  240. map: function( callback ) {
  241. return this.pushStack( jQuery.map(this, function( elem, i ) {
  242. return callback.call( elem, i, elem );
  243. }));
  244. },
  245. end: function() {
  246. return this.prevObject || this.constructor(null);
  247. },
  248. // For internal use only.
  249. // Behaves like an Array's method, not like a jQuery method.
  250. push: push,
  251. sort: [].sort,
  252. splice: [].splice
  253. };
  254. // Give the init function the jQuery prototype for later instantiation
  255. jQuery.fn.init.prototype = jQuery.fn;
  256. jQuery.extend = jQuery.fn.extend = function() {
  257. var options, name, src, copy, copyIsArray, clone,
  258. target = arguments[0] || {},
  259. i = 1,
  260. length = arguments.length,
  261. deep = false;
  262. // Handle a deep copy situation
  263. if ( typeof target === "boolean" ) {
  264. deep = target;
  265. target = arguments[1] || {};
  266. // skip the boolean and the target
  267. i = 2;
  268. }
  269. // Handle case when target is a string or something (possible in deep copy)
  270. if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
  271. target = {};
  272. }
  273. // extend jQuery itself if only one argument is passed
  274. if ( length === i ) {
  275. target = this;
  276. --i;
  277. }
  278. for ( ; i < length; i++ ) {
  279. // Only deal with non-null/undefined values
  280. if ( (options = arguments[ i ]) != null ) {
  281. // Extend the base object
  282. for ( name in options ) {
  283. src = target[ name ];
  284. copy = options[ name ];
  285. // Prevent never-ending loop
  286. if ( target === copy ) {
  287. continue;
  288. }
  289. // Recurse if we're merging plain objects or arrays
  290. if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
  291. if ( copyIsArray ) {
  292. copyIsArray = false;
  293. clone = src && jQuery.isArray(src) ? src : [];
  294. } else {
  295. clone = src && jQuery.isPlainObject(src) ? src : {};
  296. }
  297. // Never move original objects, clone them
  298. target[ name ] = jQuery.extend( deep, clone, copy );
  299. // Don't bring in undefined values
  300. } else if ( copy !== undefined ) {
  301. target[ name ] = copy;
  302. }
  303. }
  304. }
  305. }
  306. // Return the modified object
  307. return target;
  308. };
  309. jQuery.extend({
  310. noConflict: function( deep ) {
  311. if ( window.$ === jQuery ) {
  312. window.$ = _$;
  313. }
  314. if ( deep && window.jQuery === jQuery ) {
  315. window.jQuery = _jQuery;
  316. }
  317. return jQuery;
  318. },
  319. // Is the DOM ready to be used? Set to true once it occurs.
  320. isReady: false,
  321. // A counter to track how many items to wait for before
  322. // the ready event fires. See #6781
  323. readyWait: 1,
  324. // Hold (or release) the ready event
  325. holdReady: function( hold ) {
  326. if ( hold ) {
  327. jQuery.readyWait++;
  328. } else {
  329. jQuery.ready( true );
  330. }
  331. },
  332. // Handle when the DOM is ready
  333. ready: function( wait ) {
  334. // Either a released hold or an DOMready/load event and not yet ready
  335. if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
  336. // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
  337. if ( !document.body ) {
  338. return setTimeout( jQuery.ready, 1 );
  339. }
  340. // Remember that the DOM is ready
  341. jQuery.isReady = true;
  342. // If a normal DOM Ready event fired, decrement, and wait if need be
  343. if ( wait !== true && --jQuery.readyWait > 0 ) {
  344. return;
  345. }
  346. // If there are functions bound, to execute
  347. readyList.resolveWith( document, [ jQuery ] );
  348. // Trigger any bound ready events
  349. if ( jQuery.fn.trigger ) {
  350. jQuery( document ).trigger( "ready" ).unbind( "ready" );
  351. }
  352. }
  353. },
  354. bindReady: function() {
  355. if ( readyList ) {
  356. return;
  357. }
  358. readyList = jQuery._Deferred();
  359. // Catch cases where $(document).ready() is called after the
  360. // browser event has already occurred.
  361. if ( document.readyState === "complete" ) {
  362. // Handle it asynchronously to allow scripts the opportunity to delay ready
  363. return setTimeout( jQuery.ready, 1 );
  364. }
  365. // Mozilla, Opera and webkit nightlies currently support this event
  366. if ( document.addEventListener ) {
  367. // Use the handy event callback
  368. document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
  369. // A fallback to window.onload, that will always work
  370. window.addEventListener( "load", jQuery.ready, false );
  371. // If IE event model is used
  372. } else if ( document.attachEvent ) {
  373. // ensure firing before onload,
  374. // maybe late but safe also for iframes
  375. document.attachEvent( "onreadystatechange", DOMContentLoaded );
  376. // A fallback to window.onload, that will always work
  377. window.attachEvent( "onload", jQuery.ready );
  378. // If IE and not a frame
  379. // continually check to see if the document is ready
  380. var toplevel = false;
  381. try {
  382. toplevel = window.frameElement == null;
  383. } catch(e) {}
  384. if ( document.documentElement.doScroll && toplevel ) {
  385. doScrollCheck();
  386. }
  387. }
  388. },
  389. // See test/unit/core.js for details concerning isFunction.
  390. // Since version 1.3, DOM methods and functions like alert
  391. // aren't supported. They return false on IE (#2968).
  392. isFunction: function( obj ) {
  393. return jQuery.type(obj) === "function";
  394. },
  395. isArray: Array.isArray || function( obj ) {
  396. return jQuery.type(obj) === "array";
  397. },
  398. // A crude way of determining if an object is a window
  399. isWindow: function( obj ) {
  400. return obj && typeof obj === "object" && "setInterval" in obj;
  401. },
  402. isNaN: function( obj ) {
  403. return obj == null || !rdigit.test( obj ) || isNaN( obj );
  404. },
  405. type: function( obj ) {
  406. return obj == null ?
  407. String( obj ) :
  408. class2type[ toString.call(obj) ] || "object";
  409. },
  410. isPlainObject: function( obj ) {
  411. // Must be an Object.
  412. // Because of IE, we also have to check the presence of the constructor property.
  413. // Make sure that DOM nodes and window objects don't pass through, as well
  414. if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
  415. return false;
  416. }
  417. try {
  418. // Not own constructor property must be Object
  419. if ( obj.constructor &&
  420. !hasOwn.call(obj, "constructor") &&
  421. !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
  422. return false;
  423. }
  424. } catch ( e ) {
  425. // IE8,9 Will throw exceptions on certain host objects #9897
  426. return false;
  427. }
  428. // Own properties are enumerated firstly, so to speed up,
  429. // if last one is own, then all properties are own.
  430. var key;
  431. for ( key in obj ) {}
  432. return key === undefined || hasOwn.call( obj, key );
  433. },
  434. isEmptyObject: function( obj ) {
  435. for ( var name in obj ) {
  436. return false;
  437. }
  438. return true;
  439. },
  440. error: function( msg ) {
  441. throw msg;
  442. },
  443. parseJSON: function( data ) {
  444. if ( typeof data !== "string" || !data ) {
  445. return null;
  446. }
  447. // Make sure leading/trailing whitespace is removed (IE can't handle it)
  448. data = jQuery.trim( data );
  449. // Attempt to parse using the native JSON parser first
  450. if ( window.JSON && window.JSON.parse ) {
  451. return window.JSON.parse( data );
  452. }
  453. // Make sure the incoming data is actual JSON
  454. // Logic borrowed from http://json.org/json2.js
  455. if ( rvalidchars.test( data.replace( rvalidescape, "@" )
  456. .replace( rvalidtokens, "]" )
  457. .replace( rvalidbraces, "")) ) {
  458. return (new Function( "return " + data ))();
  459. }
  460. jQuery.error( "Invalid JSON: " + data );
  461. },
  462. // Cross-browser xml parsing
  463. parseXML: function( data ) {
  464. var xml, tmp;
  465. try {
  466. if ( window.DOMParser ) { // Standard
  467. tmp = new DOMParser();
  468. xml = tmp.parseFromString( data , "text/xml" );
  469. } else { // IE
  470. xml = new ActiveXObject( "Microsoft.XMLDOM" );
  471. xml.async = "false";
  472. xml.loadXML( data );
  473. }
  474. } catch( e ) {
  475. xml = undefined;
  476. }
  477. if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
  478. jQuery.error( "Invalid XML: " + data );
  479. }
  480. return xml;
  481. },
  482. noop: function() {},
  483. // Evaluates a script in a global context
  484. // Workarounds based on findings by Jim Driscoll
  485. // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
  486. globalEval: function( data ) {
  487. if ( data && rnotwhite.test( data ) ) {
  488. // We use execScript on Internet Explorer
  489. // We use an anonymous function so that context is window
  490. // rather than jQuery in Firefox
  491. ( window.execScript || function( data ) {
  492. window[ "eval" ].call( window, data );
  493. } )( data );
  494. }
  495. },
  496. // Convert dashed to camelCase; used by the css and data modules
  497. // Microsoft forgot to hump their vendor prefix (#9572)
  498. camelCase: function( string ) {
  499. return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
  500. },
  501. nodeName: function( elem, name ) {
  502. return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
  503. },
  504. // args is for internal usage only
  505. each: function( object, callback, args ) {
  506. var name, i = 0,
  507. length = object.length,
  508. isObj = length === undefined || jQuery.isFunction( object );
  509. if ( args ) {
  510. if ( isObj ) {
  511. for ( name in object ) {
  512. if ( callback.apply( object[ name ], args ) === false ) {
  513. break;
  514. }
  515. }
  516. } else {
  517. for ( ; i < length; ) {
  518. if ( callback.apply( object[ i++ ], args ) === false ) {
  519. break;
  520. }
  521. }
  522. }
  523. // A special, fast, case for the most common use of each
  524. } else {
  525. if ( isObj ) {
  526. for ( name in object ) {
  527. if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
  528. break;
  529. }
  530. }
  531. } else {
  532. for ( ; i < length; ) {
  533. if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
  534. break;
  535. }
  536. }
  537. }
  538. }
  539. return object;
  540. },
  541. // Use native String.trim function wherever possible
  542. trim: trim ?
  543. function( text ) {
  544. return text == null ?
  545. "" :
  546. trim.call( text );
  547. } :
  548. // Otherwise use our own trimming functionality
  549. function( text ) {
  550. return text == null ?
  551. "" :
  552. text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
  553. },
  554. // results is for internal usage only
  555. makeArray: function( array, results ) {
  556. var ret = results || [];
  557. if ( array != null ) {
  558. // The window, strings (and functions) also have 'length'
  559. // The extra typeof function check is to prevent crashes
  560. // in Safari 2 (See: #3039)
  561. // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
  562. var type = jQuery.type( array );
  563. if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
  564. push.call( ret, array );
  565. } else {
  566. jQuery.merge( ret, array );
  567. }
  568. }
  569. return ret;
  570. },
  571. inArray: function( elem, array ) {
  572. if ( !array ) {
  573. return -1;
  574. }
  575. if ( indexOf ) {
  576. return indexOf.call( array, elem );
  577. }
  578. for ( var i = 0, length = array.length; i < length; i++ ) {
  579. if ( array[ i ] === elem ) {
  580. return i;
  581. }
  582. }
  583. return -1;
  584. },
  585. merge: function( first, second ) {
  586. var i = first.length,
  587. j = 0;
  588. if ( typeof second.length === "number" ) {
  589. for ( var l = second.length; j < l; j++ ) {
  590. first[ i++ ] = second[ j ];
  591. }
  592. } else {
  593. while ( second[j] !== undefined ) {
  594. first[ i++ ] = second[ j++ ];
  595. }
  596. }
  597. first.length = i;
  598. return first;
  599. },
  600. grep: function( elems, callback, inv ) {
  601. var ret = [], retVal;
  602. inv = !!inv;
  603. // Go through the array, only saving the items
  604. // that pass the validator function
  605. for ( var i = 0, length = elems.length; i < length; i++ ) {
  606. retVal = !!callback( elems[ i ], i );
  607. if ( inv !== retVal ) {
  608. ret.push( elems[ i ] );
  609. }
  610. }
  611. return ret;
  612. },
  613. // arg is for internal usage only
  614. map: function( elems, callback, arg ) {
  615. var value, key, ret = [],
  616. i = 0,
  617. length = elems.length,
  618. // jquery objects are treated as arrays
  619. isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
  620. // Go through the array, translating each of the items to their
  621. if ( isArray ) {
  622. for ( ; i < length; i++ ) {
  623. value = callback( elems[ i ], i, arg );
  624. if ( value != null ) {
  625. ret[ ret.length ] = value;
  626. }
  627. }
  628. // Go through every key on the object,
  629. } else {
  630. for ( key in elems ) {
  631. value = callback( elems[ key ], key, arg );
  632. if ( value != null ) {
  633. ret[ ret.length ] = value;
  634. }
  635. }
  636. }
  637. // Flatten any nested arrays
  638. return ret.concat.apply( [], ret );
  639. },
  640. // A global GUID counter for objects
  641. guid: 1,
  642. // Bind a function to a context, optionally partially applying any
  643. // arguments.
  644. proxy: function( fn, context ) {
  645. if ( typeof context === "string" ) {
  646. var tmp = fn[ context ];
  647. context = fn;
  648. fn = tmp;
  649. }
  650. // Quick check to determine if target is callable, in the spec
  651. // this throws a TypeError, but we will just return undefined.
  652. if ( !jQuery.isFunction( fn ) ) {
  653. return undefined;
  654. }
  655. // Simulated bind
  656. var args = slice.call( arguments, 2 ),
  657. proxy = function() {
  658. return fn.apply( context, args.concat( slice.call( arguments ) ) );
  659. };
  660. // Set the guid of unique handler to the same of original handler, so it can be removed
  661. proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
  662. return proxy;
  663. },
  664. // Mutifunctional method to get and set values to a collection
  665. // The value/s can optionally be executed if it's a function
  666. access: function( elems, key, value, exec, fn, pass ) {
  667. var length = elems.length;
  668. // Setting many attributes
  669. if ( typeof key === "object" ) {
  670. for ( var k in key ) {
  671. jQuery.access( elems, k, key[k], exec, fn, value );
  672. }
  673. return elems;
  674. }
  675. // Setting one attribute
  676. if ( value !== undefined ) {
  677. // Optionally, function values get executed if exec is true
  678. exec = !pass && exec && jQuery.isFunction(value);
  679. for ( var i = 0; i < length; i++ ) {
  680. fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
  681. }
  682. return elems;
  683. }
  684. // Getting an attribute
  685. return length ? fn( elems[0], key ) : undefined;
  686. },
  687. now: function() {
  688. return (new Date()).getTime();
  689. },
  690. // Use of jQuery.browser is frowned upon.
  691. // More details: http://docs.jquery.com/Utilities/jQuery.browser
  692. uaMatch: function( ua ) {
  693. ua = ua.toLowerCase();
  694. var match = rwebkit.exec( ua ) ||
  695. ropera.exec( ua ) ||
  696. rmsie.exec( ua ) ||
  697. ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
  698. [];
  699. return { browser: match[1] || "", version: match[2] || "0" };
  700. },
  701. sub: function() {
  702. function jQuerySub( selector, context ) {
  703. return new jQuerySub.fn.init( selector, context );
  704. }
  705. jQuery.extend( true, jQuerySub, this );
  706. jQuerySub.superclass = this;
  707. jQuerySub.fn = jQuerySub.prototype = this();
  708. jQuerySub.fn.constructor = jQuerySub;
  709. jQuerySub.sub = this.sub;
  710. jQuerySub.fn.init = function init( selector, context ) {
  711. if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
  712. context = jQuerySub( context );
  713. }
  714. return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
  715. };
  716. jQuerySub.fn.init.prototype = jQuerySub.fn;
  717. var rootjQuerySub = jQuerySub(document);
  718. return jQuerySub;
  719. },
  720. browser: {}
  721. });
  722. // Populate the class2type map
  723. jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
  724. class2type[ "[object " + name + "]" ] = name.toLowerCase();
  725. });
  726. browserMatch = jQuery.uaMatch( userAgent );
  727. if ( browserMatch.browser ) {
  728. jQuery.browser[ browserMatch.browser ] = true;
  729. jQuery.browser.version = browserMatch.version;
  730. }
  731. // Deprecated, use jQuery.browser.webkit instead
  732. if ( jQuery.browser.webkit ) {
  733. jQuery.browser.safari = true;
  734. }
  735. // IE doesn't match non-breaking spaces with \s
  736. if ( rnotwhite.test( "\xA0" ) ) {
  737. trimLeft = /^[\s\xA0]+/;
  738. trimRight = /[\s\xA0]+$/;
  739. }
  740. // All jQuery objects should point back to these
  741. rootjQuery = jQuery(document);
  742. // Cleanup functions for the document ready method
  743. if ( document.addEventListener ) {
  744. DOMContentLoaded = function() {
  745. document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
  746. jQuery.ready();
  747. };
  748. } else if ( document.attachEvent ) {
  749. DOMContentLoaded = function() {
  750. // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
  751. if ( document.readyState === "complete" ) {
  752. document.detachEvent( "onreadystatechange", DOMContentLoaded );
  753. jQuery.ready();
  754. }
  755. };
  756. }
  757. // The DOM ready check for Internet Explorer
  758. function doScrollCheck() {
  759. if ( jQuery.isReady ) {
  760. return;
  761. }
  762. try {
  763. // If IE is used, use the trick by Diego Perini
  764. // http://javascript.nwbox.com/IEContentLoaded/
  765. document.documentElement.doScroll("left");
  766. } catch(e) {
  767. setTimeout( doScrollCheck, 1 );
  768. return;
  769. }
  770. // and execute any waiting functions
  771. jQuery.ready();
  772. }
  773. return jQuery;
  774. })();
  775. var // Promise methods
  776. promiseMethods = "done fail isResolved isRejected promise then always pipe".split( " " ),
  777. // Static reference to slice
  778. sliceDeferred = [].slice;
  779. jQuery.extend({
  780. // Create a simple deferred (one callbacks list)
  781. _Deferred: function() {
  782. var // callbacks list
  783. callbacks = [],
  784. // stored [ context , args ]
  785. fired,
  786. // to avoid firing when already doing so
  787. firing,
  788. // flag to know if the deferred has been cancelled
  789. cancelled,
  790. // the deferred itself
  791. deferred = {
  792. // done( f1, f2, ...)
  793. done: function() {
  794. if ( !cancelled ) {
  795. var args = arguments,
  796. i,
  797. length,
  798. elem,
  799. type,
  800. _fired;
  801. if ( fired ) {
  802. _fired = fired;
  803. fired = 0;
  804. }
  805. for ( i = 0, length = args.length; i < length; i++ ) {
  806. elem = args[ i ];
  807. type = jQuery.type( elem );
  808. if ( type === "array" ) {
  809. deferred.done.apply( deferred, elem );
  810. } else if ( type === "function" ) {
  811. callbacks.push( elem );
  812. }
  813. }
  814. if ( _fired ) {
  815. deferred.resolveWith( _fired[ 0 ], _fired[ 1 ] );
  816. }
  817. }
  818. return this;
  819. },
  820. // resolve with given context and args
  821. resolveWith: function( context, args ) {
  822. if ( !cancelled && !fired && !firing ) {
  823. // make sure args are available (#8421)
  824. args = args || [];
  825. firing = 1;
  826. try {
  827. while( callbacks[ 0 ] ) {
  828. callbacks.shift().apply( context, args );
  829. }
  830. }
  831. finally {
  832. fired = [ context, args ];
  833. firing = 0;
  834. }
  835. }
  836. return this;
  837. },
  838. // resolve with this as context and given arguments
  839. resolve: function() {
  840. deferred.resolveWith( this, arguments );
  841. return this;
  842. },
  843. // Has this deferred been resolved?
  844. isResolved: function() {
  845. return !!( firing || fired );
  846. },
  847. // Cancel
  848. cancel: function() {
  849. cancelled = 1;
  850. callbacks = [];
  851. return this;
  852. }
  853. };
  854. return deferred;
  855. },
  856. // Full fledged deferred (two callbacks list)
  857. Deferred: function( func ) {
  858. var deferred = jQuery._Deferred(),
  859. failDeferred = jQuery._Deferred(),
  860. promise;
  861. // Add errorDeferred methods, then and promise
  862. jQuery.extend( deferred, {
  863. then: function( doneCallbacks, failCallbacks ) {
  864. deferred.done( doneCallbacks ).fail( failCallbacks );
  865. return this;
  866. },
  867. always: function() {
  868. return deferred.done.apply( deferred, arguments ).fail.apply( this, arguments );
  869. },
  870. fail: failDeferred.done,
  871. rejectWith: failDeferred.resolveWith,
  872. reject: failDeferred.resolve,
  873. isRejected: failDeferred.isResolved,
  874. pipe: function( fnDone, fnFail ) {
  875. return jQuery.Deferred(function( newDefer ) {
  876. jQuery.each( {
  877. done: [ fnDone, "resolve" ],
  878. fail: [ fnFail, "reject" ]
  879. }, function( handler, data ) {
  880. var fn = data[ 0 ],
  881. action = data[ 1 ],
  882. returned;
  883. if ( jQuery.isFunction( fn ) ) {
  884. deferred[ handler ](function() {
  885. returned = fn.apply( this, arguments );
  886. if ( returned && jQuery.isFunction( returned.promise ) ) {
  887. returned.promise().then( newDefer.resolve, newDefer.reject );
  888. } else {
  889. newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
  890. }
  891. });
  892. } else {
  893. deferred[ handler ]( newDefer[ action ] );
  894. }
  895. });
  896. }).promise();
  897. },
  898. // Get a promise for this deferred
  899. // If obj is provided, the promise aspect is added to the object
  900. promise: function( obj ) {
  901. if ( obj == null ) {
  902. if ( promise ) {
  903. return promise;
  904. }
  905. promise = obj = {};
  906. }
  907. var i = promiseMethods.length;
  908. while( i-- ) {
  909. obj[ promiseMethods[i] ] = deferred[ promiseMethods[i] ];
  910. }
  911. return obj;
  912. }
  913. });
  914. // Make sure only one callback list will be used
  915. deferred.done( failDeferred.cancel ).fail( deferred.cancel );
  916. // Unexpose cancel
  917. delete deferred.cancel;
  918. // Call given func if any
  919. if ( func ) {
  920. func.call( deferred, deferred );
  921. }
  922. return deferred;
  923. },
  924. // Deferred helper
  925. when: function( firstParam ) {
  926. var args = arguments,
  927. i = 0,
  928. length = args.length,
  929. count = length,
  930. deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
  931. firstParam :
  932. jQuery.Deferred();
  933. function resolveFunc( i ) {
  934. return function( value ) {
  935. args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
  936. if ( !( --count ) ) {
  937. // Strange bug in FF4:
  938. // Values changed onto the arguments object sometimes end up as undefined values
  939. // outside the $.when method. Cloning the object into a fresh array solves the issue
  940. deferred.resolveWith( deferred, sliceDeferred.call( args, 0 ) );
  941. }
  942. };
  943. }
  944. if ( length > 1 ) {
  945. for( ; i < length; i++ ) {
  946. if ( args[ i ] && jQuery.isFunction( args[ i ].promise ) ) {
  947. args[ i ].promise().then( resolveFunc(i), deferred.reject );
  948. } else {
  949. --count;
  950. }
  951. }
  952. if ( !count ) {
  953. deferred.resolveWith( deferred, args );
  954. }
  955. } else if ( deferred !== firstParam ) {
  956. deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
  957. }
  958. return deferred.promise();
  959. }
  960. });
  961. jQuery.support = (function() {
  962. var div = document.createElement( "div" ),
  963. documentElement = document.documentElement,
  964. all,
  965. a,
  966. select,
  967. opt,
  968. input,
  969. marginDiv,
  970. support,
  971. fragment,
  972. body,
  973. testElementParent,
  974. testElement,
  975. testElementStyle,
  976. tds,
  977. events,
  978. eventName,
  979. i,
  980. isSupported;
  981. // Preliminary tests
  982. div.setAttribute("className", "t");
  983. div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
  984. all = div.getElementsByTagName( "*" );
  985. a = div.getElementsByTagName( "a" )[ 0 ];
  986. // Can't get basic test support
  987. if ( !all || !all.length || !a ) {
  988. return {};
  989. }
  990. // First batch of supports tests
  991. select = document.createElement( "select" );
  992. opt = select.appendChild( document.createElement("option") );
  993. input = div.getElementsByTagName( "input" )[ 0 ];
  994. support = {
  995. // IE strips leading whitespace when .innerHTML is used
  996. leadingWhitespace: ( div.firstChild.nodeType === 3 ),
  997. // Make sure that tbody elements aren't automatically inserted
  998. // IE will insert them into empty tables
  999. tbody: !div.getElementsByTagName( "tbody" ).length,
  1000. // Make sure that link elements get serialized correctly by innerHTML
  1001. // This requires a wrapper element in IE
  1002. htmlSerialize: !!div.getElementsByTagName( "link" ).length,
  1003. // Get the style information from getAttribute
  1004. // (IE uses .cssText instead)
  1005. style: /top/.test( a.getAttribute("style") ),
  1006. // Make sure that URLs aren't manipulated
  1007. // (IE normalizes it by default)
  1008. hrefNormalized: ( a.getAttribute( "href" ) === "/a" ),
  1009. // Make sure that element opacity exists
  1010. // (IE uses filter instead)
  1011. // Use a regex to work around a WebKit issue. See #5145
  1012. opacity: /^0.55$/.test( a.style.opacity ),
  1013. // Verify style float existence
  1014. // (IE uses styleFloat instead of cssFloat)
  1015. cssFloat: !!a.style.cssFloat,
  1016. // Make sure that if no value is specified for a checkbox
  1017. // that it defaults to "on".
  1018. // (WebKit defaults to "" instead)
  1019. checkOn: ( input.value === "on" ),
  1020. // Make sure that a selected-by-default option has a working selected property.
  1021. // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
  1022. optSelected: opt.selected,
  1023. // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
  1024. getSetAttribute: div.className !== "t",
  1025. // Will be defined later
  1026. submitBubbles: true,
  1027. changeBubbles: true,
  1028. focusinBubbles: false,
  1029. deleteExpando: true,
  1030. noCloneEvent: true,
  1031. inlineBlockNeedsLayout: false,
  1032. shrinkWrapBlocks: false,
  1033. reliableMarginRight: true
  1034. };
  1035. // Make sure checked status is properly cloned
  1036. input.checked = true;
  1037. support.noCloneChecked = input.cloneNode( true ).checked;
  1038. // Make sure that the options inside disabled selects aren't marked as disabled
  1039. // (WebKit marks them as disabled)
  1040. select.disabled = true;
  1041. support.optDisabled = !opt.disabled;
  1042. // Test to see if it's possible to delete an expando from an element
  1043. // Fails in Internet Explorer
  1044. try {
  1045. delete div.test;
  1046. } catch( e ) {
  1047. support.deleteExpando = false;
  1048. }
  1049. if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
  1050. div.attachEvent( "onclick", function() {
  1051. // Cloning a node shouldn't copy over any
  1052. // bound event handlers (IE does this)
  1053. support.noCloneEvent = false;
  1054. });
  1055. div.cloneNode( true ).fireEvent( "onclick" );
  1056. }
  1057. // Check if a radio maintains it's value
  1058. // after being appended to the DOM
  1059. input = document.createElement("input");
  1060. input.value = "t";
  1061. input.setAttribute("type", "radio");
  1062. support.radioValue = input.value === "t";
  1063. input.setAttribute("checked", "checked");
  1064. div.appendChild( input );
  1065. fragment = document.createDocumentFragment();
  1066. fragment.appendChild( div.firstChild );
  1067. // WebKit doesn't clone checked state correctly in fragments
  1068. support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
  1069. div.innerHTML = "";
  1070. // Figure out if the W3C box model works as expected
  1071. div.style.width = div.style.paddingLeft = "1px";
  1072. body = document.getElementsByTagName( "body" )[ 0 ];
  1073. // We use our own, invisible, body unless the body is already present
  1074. // in which case we use a div (#9239)
  1075. testElement = document.createElement( body ? "div" : "body" );
  1076. testElementStyle = {
  1077. visibility: "hidden",
  1078. width: 0,
  1079. height: 0,
  1080. border: 0,
  1081. margin: 0,
  1082. background: "none"
  1083. };
  1084. if ( body ) {
  1085. jQuery.extend( testElementStyle, {
  1086. position: "absolute",
  1087. left: "-1000px",
  1088. top: "-1000px"
  1089. });
  1090. }
  1091. for ( i in testElementStyle ) {
  1092. testElement.style[ i ] = testElementStyle[ i ];
  1093. }
  1094. testElement.appendChild( div );
  1095. testElementParent = body || documentElement;
  1096. testElementParent.insertBefore( testElement, testElementParent.firstChild );
  1097. // Check if a disconnected checkbox will retain its checked
  1098. // value of true after appended to the DOM (IE6/7)
  1099. support.appendChecked = input.checked;
  1100. support.boxModel = div.offsetWidth === 2;
  1101. if ( "zoom" in div.style ) {
  1102. // Check if natively block-level elements act like inline-block
  1103. // elements when setting their display to 'inline' and giving
  1104. // them layout
  1105. // (IE < 8 does this)
  1106. div.style.display = "inline";
  1107. div.style.zoom = 1;
  1108. support.inlineBlockNeedsLayout = ( div.offsetWidth === 2 );
  1109. // Check if elements with layout shrink-wrap their children
  1110. // (IE 6 does this)
  1111. div.style.display = "";
  1112. div.innerHTML = "<div style='width:4px;'></div>";
  1113. support.shrinkWrapBlocks = ( div.offsetWidth !== 2 );
  1114. }
  1115. div.innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>";
  1116. tds = div.getElementsByTagName( "td" );
  1117. // Check if table cells still have offsetWidth/Height when they are set
  1118. // to display:none and there are still other visible table cells in a
  1119. // table row; if so, offsetWidth/Height are not reliable for use when
  1120. // determining if an element has been hidden directly using
  1121. // display:none (it is still safe to use offsets if a parent element is
  1122. // hidden; don safety goggles and see bug #4512 for more information).
  1123. // (only IE 8 fails this test)
  1124. isSupported = ( tds[ 0 ].offsetHeight === 0 );
  1125. tds[ 0 ].style.display = "";
  1126. tds[ 1 ].style.display = "none";
  1127. // Check if empty table cells still have offsetWidth/Height
  1128. // (IE < 8 fail this test)
  1129. support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
  1130. div.innerHTML = "";
  1131. // Check if div with explicit width and no margin-right incorrectly
  1132. // gets computed margin-right based on width of container. For more
  1133. // info see bug #3333
  1134. // Fails in WebKit before Feb 2011 nightlies
  1135. // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
  1136. if ( document.defaultView && document.defaultView.getComputedStyle ) {
  1137. marginDiv = document.createElement( "div" );
  1138. marginDiv.style.width = "0";
  1139. marginDiv.style.marginRight = "0";
  1140. div.appendChild( marginDiv );
  1141. support.reliableMarginRight =
  1142. ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
  1143. }
  1144. // Remove the body element we added
  1145. testElement.innerHTML = "";
  1146. testElementParent.removeChild( testElement );
  1147. // Technique from Juriy Zaytsev
  1148. // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
  1149. // We only care about the case where non-standard event systems
  1150. // are used, namely in IE. Short-circuiting here helps us to
  1151. // avoid an eval call (in setAttribute) which can cause CSP
  1152. // to go haywire. See: https://developer.mozilla.org/en/Security/CSP
  1153. if ( div.attachEvent ) {
  1154. for( i in {
  1155. submit: 1,
  1156. change: 1,
  1157. focusin: 1
  1158. } ) {
  1159. eventName = "on" + i;
  1160. isSupported = ( eventName in div );
  1161. if ( !isSupported ) {
  1162. div.setAttribute( eventName, "return;" );
  1163. isSupported = ( typeof div[ eventName ] === "function" );
  1164. }
  1165. support[ i + "Bubbles" ] = isSupported;
  1166. }
  1167. }
  1168. // Null connected elements to avoid leaks in IE
  1169. testElement = fragment = select = opt = body = marginDiv = div = input = null;
  1170. return support;
  1171. })();
  1172. // Keep track of boxModel
  1173. jQuery.boxModel = jQuery.support.boxModel;
  1174. var rbrace = /^(?:\{.*\}|\[.*\])$/,
  1175. rmultiDash = /([A-Z])/g;
  1176. jQuery.extend({
  1177. cache: {},
  1178. // Please use with caution
  1179. uuid: 0,
  1180. // Unique for each copy of jQuery on the page
  1181. // Non-digits removed to match rinlinejQuery
  1182. expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
  1183. // The following elements throw uncatchable exceptions if you
  1184. // attempt to add expando properties to them.
  1185. noData: {
  1186. "embed": true,
  1187. // Ban all objects except for Flash (which handle expandos)
  1188. "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
  1189. "applet": true
  1190. },
  1191. hasData: function( elem ) {
  1192. elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
  1193. return !!elem && !isEmptyDataObject( elem );
  1194. },
  1195. data: function( elem, name, data, pvt /* Internal Use Only */ ) {
  1196. if ( !jQuery.acceptData( elem ) ) {
  1197. return;
  1198. }
  1199. var thisCache, ret,
  1200. internalKey = jQuery.expando,
  1201. getByName = typeof name === "string",
  1202. // We have to handle DOM nodes and JS objects differently because IE6-7
  1203. // can't GC object references properly across the DOM-JS boundary
  1204. isNode = elem.nodeType,
  1205. // Only DOM nodes need the global jQuery cache; JS object data is
  1206. // attached directly to the object so GC can occur automatically
  1207. cache = isNode ? jQuery.cache : elem,
  1208. // Only defining an ID for JS objects if its cache already exists allows
  1209. // the code to shortcut on the same path as a DOM node with no cache
  1210. id = isNode ? elem[ jQuery.expando ] : elem[ jQuery.expando ] && jQuery.expando;
  1211. // Avoid doing any more work than we need to when trying to get data on an
  1212. // object that has no data at all
  1213. if ( (!id || (pvt && id && (cache[ id ] && !cache[ id ][ internalKey ]))) && getByName && data === undefined ) {
  1214. return;
  1215. }
  1216. if ( !id ) {
  1217. // Only DOM nodes need a new unique ID for each element since their data
  1218. // ends up in the global cache
  1219. if ( isNode ) {
  1220. elem[ jQuery.expando ] = id = ++jQuery.uuid;
  1221. } else {
  1222. id = jQuery.expando;
  1223. }
  1224. }
  1225. if ( !cache[ id ] ) {
  1226. cache[ id ] = {};
  1227. // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
  1228. // metadata on plain JS objects when the object is serialized using
  1229. // JSON.stringify
  1230. if ( !isNode ) {
  1231. cache[ id ].toJSON = jQuery.noop;
  1232. }
  1233. }
  1234. // An object can be passed to jQuery.data instead of a key/value pair; this gets
  1235. // shallow copied over onto the existing cache
  1236. if ( typeof name === "object" || typeof name === "function" ) {
  1237. if ( pvt ) {
  1238. cache[ id ][ internalKey ] = jQuery.extend(cache[ id ][ internalKey ], name);
  1239. } else {
  1240. cache[ id ] = jQuery.extend(cache[ id ], name);
  1241. }
  1242. }
  1243. thisCache = cache[ id ];
  1244. // Internal jQuery data is stored in a separate object inside the object's data
  1245. // cache in order to avoid key collisions between internal data and user-defined
  1246. // data
  1247. if ( pvt ) {
  1248. if ( !thisCache[ internalKey ] ) {
  1249. thisCache[ internalKey ] = {};
  1250. }
  1251. thisCache = thisCache[ internalKey ];
  1252. }
  1253. if ( data !== undefined ) {
  1254. thisCache[ jQuery.camelCase( name ) ] = data;
  1255. }
  1256. // TODO: This is a hack for 1.5 ONLY. It will be removed in 1.6. Users should
  1257. // not attempt to inspect the internal events object using jQuery.data, as this
  1258. // internal data object is undocumented and subject to change.
  1259. if ( name === "events" && !thisCache[name] ) {
  1260. return thisCache[ internalKey ] && thisCache[ internalKey ].events;
  1261. }
  1262. // Check for both converted-to-camel and non-converted data property names
  1263. // If a data property was specified
  1264. if ( getByName ) {
  1265. // First Try to find as-is property data
  1266. ret = thisCache[ name ];
  1267. // Test for null|undefined property data
  1268. if ( ret == null ) {
  1269. // Try to find the camelCased property
  1270. ret = thisCache[ jQuery.camelCase( name ) ];
  1271. }
  1272. } else {
  1273. ret = thisCache;
  1274. }
  1275. return ret;
  1276. },
  1277. removeData: function( elem, name, pvt /* Internal Use Only */ ) {
  1278. if ( !jQuery.acceptData( elem ) ) {
  1279. return;
  1280. }
  1281. var thisCache,
  1282. // Reference to internal data cache key
  1283. internalKey = jQuery.expando,
  1284. isNode = elem.nodeType,
  1285. // See jQuery.data for more information
  1286. cache = isNode ? jQuery.cache : elem,
  1287. // See jQuery.data for more information
  1288. id = isNode ? elem[ jQuery.expando ] : jQuery.expando;
  1289. // If there is already no cache entry for this object, there is no
  1290. // purpose in continuing
  1291. if ( !cache[ id ] ) {
  1292. return;
  1293. }
  1294. if ( name ) {
  1295. thisCache = pvt ? cache[ id ][ internalKey ] : cache[ id ];
  1296. if ( thisCache ) {
  1297. // Support interoperable removal of hyphenated or camelcased keys
  1298. if ( !thisCache[ name ] ) {
  1299. name = jQuery.camelCase( name );
  1300. }
  1301. delete thisCache[ name ];
  1302. // If there is no data left in the cache, we want to continue
  1303. // and let the cache object itself get destroyed
  1304. if ( !isEmptyDataObject(thisCache) ) {
  1305. return;
  1306. }
  1307. }
  1308. }
  1309. // See jQuery.data for more information
  1310. if ( pvt ) {
  1311. delete cache[ id ][ internalKey ];
  1312. // Don't destroy the parent cache unless the internal data object
  1313. // had been the only thing left in it
  1314. if ( !isEmptyDataObject(cache[ id ]) ) {
  1315. return;
  1316. }
  1317. }
  1318. var internalCache = cache[ id ][ internalKey ];
  1319. // Browsers that fail expando deletion also refuse to delete expandos on
  1320. // the window, but it will allow it on all other JS objects; other browsers
  1321. // don't care
  1322. // Ensure that `cache` is not a window object #10080
  1323. if ( jQuery.support.deleteExpando || !cache.setInterval ) {
  1324. delete cache[ id ];
  1325. } else {
  1326. cache[ id ] = null;
  1327. }
  1328. // We destroyed the entire user cache at once because it's faster than
  1329. // iterating through each key, but we need to continue to persist internal
  1330. // data if it existed
  1331. if ( internalCache ) {
  1332. cache[ id ] = {};
  1333. // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
  1334. // metadata on plain JS objects when the object is serialized using
  1335. // JSON.stringify
  1336. if ( !isNode ) {
  1337. cache[ id ].toJSON = jQuery.noop;
  1338. }
  1339. cache[ id ][ internalKey ] = internalCache;
  1340. // Otherwise, we need to eliminate the expando on the node to avoid
  1341. // false lookups in the cache for entries that no longer exist
  1342. } else if ( isNode ) {
  1343. // IE does not allow us to delete expando properties from nodes,
  1344. // nor does it have a removeAttribute function on Document nodes;
  1345. // we must handle all of these cases
  1346. if ( jQuery.support.deleteExpando ) {
  1347. delete elem[ jQuery.expando ];
  1348. } else if ( elem.removeAttribute ) {
  1349. elem.removeAttribute( jQuery.expando );
  1350. } else {
  1351. elem[ jQuery.expando ] = null;
  1352. }
  1353. }
  1354. },
  1355. // For internal use only.
  1356. _data: function( elem, name, data ) {
  1357. return jQuery.data( elem, name, data, true );
  1358. },
  1359. // A method for determining if a DOM node can handle the data expando
  1360. acceptData: function( elem ) {
  1361. if ( elem.nodeName ) {
  1362. var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
  1363. if ( match ) {
  1364. return !(match === true || elem.getAttribute("classid") !== match);
  1365. }
  1366. }
  1367. return true;
  1368. }
  1369. });
  1370. jQuery.fn.extend({
  1371. data: function( key, value ) {
  1372. var data = null;
  1373. if ( typeof key === "undefined" ) {
  1374. if ( this.length ) {
  1375. data = jQuery.data( this[0] );
  1376. if ( this[0].nodeType === 1 ) {
  1377. var attr = this[0].attributes, name;
  1378. for ( var i = 0, l = attr.length; i < l; i++ ) {
  1379. name = attr[i].name;
  1380. if ( name.indexOf( "data-" ) === 0 ) {
  1381. name = jQuery.camelCase( name.substring(5) );
  1382. dataAttr( this[0], name, data[ name ] );
  1383. }
  1384. }
  1385. }
  1386. }
  1387. return data;
  1388. } else if ( typeof key === "object" ) {
  1389. return this.each(function() {
  1390. jQuery.data( this, key );
  1391. });
  1392. }
  1393. var parts = key.split(".");
  1394. parts[1] = parts[1] ? "." + parts[1] : "";
  1395. if ( value === undefined ) {
  1396. data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
  1397. // Try to fetch any internally stored data first
  1398. if ( data === undefined && this.length ) {
  1399. data = jQuery.data( this[0], key );
  1400. data = dataAttr( this[0], key, data );
  1401. }
  1402. return data === undefined && parts[1] ?
  1403. this.data( parts[0] ) :
  1404. data;
  1405. } else {
  1406. return this.each(function() {
  1407. var $this = jQuery( this ),
  1408. args = [ parts[0], value ];
  1409. $this.triggerHandler( "setData" + parts[1] + "!", args );
  1410. jQuery.data( this, key, value );
  1411. $this.triggerHandler( "changeData" + parts[1] + "!", args );
  1412. });
  1413. }
  1414. },
  1415. removeData: function( key ) {
  1416. return this.each(function() {
  1417. jQuery.removeData( this, key );
  1418. });
  1419. }
  1420. });
  1421. function dataAttr( elem, key, data ) {
  1422. // If nothing was found internally, try to fetch any
  1423. // data from the HTML5 data-* attribute
  1424. if ( data === undefined && elem.nodeType === 1 ) {
  1425. var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
  1426. data = elem.getAttribute( name );
  1427. if ( typeof data === "string" ) {
  1428. try {
  1429. data = data === "true" ? true :
  1430. data === "false" ? false :
  1431. data === "null" ? null :
  1432. !jQuery.isNaN( data ) ? parseFloat( data ) :
  1433. rbrace.test( data ) ? jQuery.parseJSON( data ) :
  1434. data;
  1435. } catch( e ) {}
  1436. // Make sure we set the data so it isn't changed later
  1437. jQuery.data( elem, key, data );
  1438. } else {
  1439. data = undefined;
  1440. }
  1441. }
  1442. return data;
  1443. }
  1444. // TODO: This is a hack for 1.5 ONLY to allow objects with a single toJSON
  1445. // property to be considered empty objects; this property always exists in
  1446. // order to make sure JSON.stringify does not expose internal metadata
  1447. function isEmptyDataObject( obj ) {
  1448. for ( var name in obj ) {
  1449. if ( name !== "toJSON" ) {
  1450. return false;
  1451. }
  1452. }
  1453. return true;
  1454. }
  1455. function handleQueueMarkDefer( elem, type, src ) {
  1456. var deferDataKey = type + "defer",
  1457. queueDataKey = type + "queue",
  1458. markDataKey = type + "mark",
  1459. defer = jQuery.data( elem, deferDataKey, undefined, true );
  1460. if ( defer &&
  1461. ( src === "queue" || !jQuery.data( elem, queueDataKey, undefined, true ) ) &&
  1462. ( src === "mark" || !jQuery.data( elem, markDataKey, undefined, true ) ) ) {
  1463. // Give room for hard-coded callbacks to fire first
  1464. // and eventually mark/queue something else on the element
  1465. setTimeout( function() {
  1466. if ( !jQuery.data( elem, queueDataKey, undefined, true ) &&
  1467. !jQuery.data( elem, markDataKey, undefined, true ) ) {
  1468. jQuery.removeData( elem, deferDataKey, true );
  1469. defer.resolve();
  1470. }
  1471. }, 0 );
  1472. }
  1473. }
  1474. jQuery.extend({
  1475. _mark: function( elem, type ) {
  1476. if ( elem ) {
  1477. type = (type || "fx") + "mark";
  1478. jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
  1479. }
  1480. },
  1481. _unmark: function( force, elem, type ) {
  1482. if ( force !== true ) {
  1483. type = elem;
  1484. elem = force;
  1485. force = false;
  1486. }
  1487. if ( elem ) {
  1488. type = type || "fx";
  1489. var key = type + "mark",
  1490. count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
  1491. if ( count ) {
  1492. jQuery.data( elem, key, count, true );
  1493. } else {
  1494. jQuery.removeData( elem, key, true );
  1495. handleQueueMarkDefer( elem, type, "mark" );
  1496. }
  1497. }
  1498. },
  1499. queue: function( elem, type, data ) {
  1500. if ( elem ) {
  1501. type = (type || "fx") + "queue";
  1502. var q = jQuery.data( elem, type, undefined, true );
  1503. // Speed up dequeue by getting out quickly if this is just a lookup
  1504. if ( data ) {
  1505. if ( !q || jQuery.isArray(data) ) {
  1506. q = jQuery.data( elem, type, jQuery.makeArray(data), true );
  1507. } else {
  1508. q.push( data );
  1509. }
  1510. }
  1511. return q || [];
  1512. }
  1513. },
  1514. dequeue: function( elem, type ) {
  1515. type = type || "fx";
  1516. var queue = jQuery.queue( elem, type ),
  1517. fn = queue.shift(),
  1518. defer;
  1519. // If the fx queue is dequeued, always remove the progress sentinel
  1520. if ( fn === "inprogress" ) {
  1521. fn = queue.shift();
  1522. }
  1523. if ( fn ) {
  1524. // Add a progress sentinel to prevent the fx queue from being
  1525. // automatically dequeued
  1526. if ( type === "fx" ) {
  1527. queue.unshift("inprogress");
  1528. }
  1529. fn.call(elem, function() {
  1530. jQuery.dequeue(elem, type);
  1531. });
  1532. }
  1533. if ( !queue.length ) {
  1534. jQuery.removeData( elem, type + "queue", true );
  1535. handleQueueMarkDefer( elem, type, "queue" );
  1536. }