/scalate-website/src/scripts/jquery.js

http://github.com/scalate/scalate · JavaScript · 8981 lines · 7072 code · 935 blank · 974 comment · 1078 complexity · 12840be281cca027968c56e19ebdf6ec MD5 · raw file

Large files are truncated click here to view the full file

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