PageRenderTime 50ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 1ms

/media/js/jquery.js

http://trespams.googlecode.com/
JavaScript | 3408 lines | 2771 code | 294 blank | 343 comment | 385 complexity | 032eb9d1100e96e9c9fbf3ad6a390bfd MD5 | raw file
  1. (function(){
  2. /*
  3. * jQuery 1.2.3b - New Wave Javascript
  4. *
  5. * Copyright (c) 2008 John Resig (jquery.com)
  6. * Dual licensed under the MIT (MIT-LICENSE.txt)
  7. * and GPL (GPL-LICENSE.txt) licenses.
  8. *
  9. * $Date: 2008-02-03 19:43:04 +0100 (So, 03 Feb 2008) $
  10. * $Rev: 4611 $
  11. */
  12. // Map over jQuery in case of overwrite
  13. if ( window.jQuery )
  14. var _jQuery = window.jQuery;
  15. var jQuery = window.jQuery = function( selector, context ) {
  16. // The jQuery object is actually just the init constructor 'enhanced'
  17. return new jQuery.prototype.init( selector, context );
  18. };
  19. // Map over the $ in case of overwrite
  20. if ( window.$ )
  21. var _$ = window.$;
  22. // Map the jQuery namespace to the '$' one
  23. window.$ = jQuery;
  24. // A simple way to check for HTML strings or ID strings
  25. // (both of which we optimize for)
  26. var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
  27. // Is it a simple selector
  28. var isSimple = /^.[^:#\[\.]*$/;
  29. jQuery.fn = jQuery.prototype = {
  30. init: function( selector, context ) {
  31. // Make sure that a selection was provided
  32. selector = selector || document;
  33. // Handle $(DOMElement)
  34. if ( selector.nodeType ) {
  35. this[0] = selector;
  36. this.length = 1;
  37. return this;
  38. // Handle HTML strings
  39. } else if ( typeof selector == "string" ) {
  40. // Are we dealing with HTML string or an ID?
  41. var match = quickExpr.exec( selector );
  42. // Verify a match, and that no context was specified for #id
  43. if ( match && (match[1] || !context) ) {
  44. // HANDLE: $(html) -> $(array)
  45. if ( match[1] )
  46. selector = jQuery.clean( [ match[1] ], context );
  47. // HANDLE: $("#id")
  48. else {
  49. var elem = document.getElementById( match[3] );
  50. // Make sure an element was located
  51. if ( elem )
  52. // Handle the case where IE and Opera return items
  53. // by name instead of ID
  54. if ( elem.id != match[3] )
  55. return jQuery().find( selector );
  56. // Otherwise, we inject the element directly into the jQuery object
  57. else {
  58. this[0] = elem;
  59. this.length = 1;
  60. return this;
  61. }
  62. else
  63. selector = [];
  64. }
  65. // HANDLE: $(expr, [context])
  66. // (which is just equivalent to: $(content).find(expr)
  67. } else
  68. return new jQuery( context ).find( selector );
  69. // HANDLE: $(function)
  70. // Shortcut for document ready
  71. } else if ( jQuery.isFunction( selector ) )
  72. return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
  73. return this.setArray(
  74. // HANDLE: $(array)
  75. selector.constructor == Array && selector ||
  76. // HANDLE: $(arraylike)
  77. // Watch for when an array-like object, contains DOM nodes, is passed in as the selector
  78. (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||
  79. // HANDLE: $(*)
  80. [ selector ] );
  81. },
  82. // The current version of jQuery being used
  83. jquery: "1.2.3b",
  84. // The number of elements contained in the matched element set
  85. size: function() {
  86. return this.length;
  87. },
  88. // The number of elements contained in the matched element set
  89. length: 0,
  90. // Get the Nth element in the matched element set OR
  91. // Get the whole matched element set as a clean array
  92. get: function( num ) {
  93. return num == undefined ?
  94. // Return a 'clean' array
  95. jQuery.makeArray( this ) :
  96. // Return just the object
  97. this[ num ];
  98. },
  99. // Take an array of elements and push it onto the stack
  100. // (returning the new matched element set)
  101. pushStack: function( elems ) {
  102. // Build a new jQuery matched element set
  103. var ret = jQuery( elems );
  104. // Add the old object onto the stack (as a reference)
  105. ret.prevObject = this;
  106. // Return the newly-formed element set
  107. return ret;
  108. },
  109. // Force the current matched set of elements to become
  110. // the specified array of elements (destroying the stack in the process)
  111. // You should use pushStack() in order to do this, but maintain the stack
  112. setArray: function( elems ) {
  113. // Resetting the length to 0, then using the native Array push
  114. // is a super-fast way to populate an object with array-like properties
  115. this.length = 0;
  116. Array.prototype.push.apply( this, elems );
  117. return this;
  118. },
  119. // Execute a callback for every element in the matched set.
  120. // (You can seed the arguments with an array of args, but this is
  121. // only used internally.)
  122. each: function( callback, args ) {
  123. return jQuery.each( this, callback, args );
  124. },
  125. // Determine the position of an element within
  126. // the matched set of elements
  127. index: function( elem ) {
  128. var ret = -1;
  129. // Locate the position of the desired element
  130. this.each(function(i){
  131. if ( this == elem )
  132. ret = i;
  133. });
  134. return ret;
  135. },
  136. attr: function( name, value, type ) {
  137. var options = name;
  138. // Look for the case where we're accessing a style value
  139. if ( name.constructor == String )
  140. if ( value == undefined )
  141. return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
  142. else {
  143. options = {};
  144. options[ name ] = value;
  145. }
  146. // Check to see if we're setting style values
  147. return this.each(function(i){
  148. // Set all the styles
  149. for ( name in options )
  150. jQuery.attr(
  151. type ?
  152. this.style :
  153. this,
  154. name, jQuery.prop( this, options[ name ], type, i, name )
  155. );
  156. });
  157. },
  158. css: function( key, value ) {
  159. // ignore negative width and height values
  160. if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
  161. value = undefined;
  162. return this.attr( key, value, "curCSS" );
  163. },
  164. text: function( text ) {
  165. if ( typeof text != "object" && text != null )
  166. return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
  167. var ret = "";
  168. jQuery.each( text || this, function(){
  169. jQuery.each( this.childNodes, function(){
  170. if ( this.nodeType != 8 )
  171. ret += this.nodeType != 1 ?
  172. this.nodeValue :
  173. jQuery.fn.text( [ this ] );
  174. });
  175. });
  176. return ret;
  177. },
  178. wrapAll: function( html ) {
  179. if ( this[0] )
  180. // The elements to wrap the target around
  181. jQuery( html, this[0].ownerDocument )
  182. .clone()
  183. .insertBefore( this[0] )
  184. .map(function(){
  185. var elem = this;
  186. while ( elem.firstChild )
  187. elem = elem.firstChild;
  188. return elem;
  189. })
  190. .append(this);
  191. return this;
  192. },
  193. wrapInner: function( html ) {
  194. return this.each(function(){
  195. jQuery( this ).contents().wrapAll( html );
  196. });
  197. },
  198. wrap: function( html ) {
  199. return this.each(function(){
  200. jQuery( this ).wrapAll( html );
  201. });
  202. },
  203. append: function() {
  204. return this.domManip(arguments, true, false, function(elem){
  205. if (this.nodeType == 1)
  206. this.appendChild( elem );
  207. });
  208. },
  209. prepend: function() {
  210. return this.domManip(arguments, true, true, function(elem){
  211. if (this.nodeType == 1)
  212. this.insertBefore( elem, this.firstChild );
  213. });
  214. },
  215. before: function() {
  216. return this.domManip(arguments, false, false, function(elem){
  217. this.parentNode.insertBefore( elem, this );
  218. });
  219. },
  220. after: function() {
  221. return this.domManip(arguments, false, true, function(elem){
  222. this.parentNode.insertBefore( elem, this.nextSibling );
  223. });
  224. },
  225. end: function() {
  226. return this.prevObject || jQuery( [] );
  227. },
  228. find: function( selector ) {
  229. var elems = jQuery.map(this, function(elem){
  230. return jQuery.find( selector, elem );
  231. });
  232. return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?
  233. jQuery.unique( elems ) :
  234. elems );
  235. },
  236. clone: function( events ) {
  237. // Do the clone
  238. var ret = this.map(function(){
  239. if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) {
  240. // IE copies events bound via attachEvent when
  241. // using cloneNode. Calling detachEvent on the
  242. // clone will also remove the events from the orignal
  243. // In order to get around this, we use innerHTML.
  244. // Unfortunately, this means some modifications to
  245. // attributes in IE that are actually only stored
  246. // as properties will not be copied (such as the
  247. // the name attribute on an input).
  248. var clone = this.cloneNode(true),
  249. container = document.createElement("div");
  250. container.appendChild(clone);
  251. return jQuery.clean([container.innerHTML])[0];
  252. } else
  253. return this.cloneNode(true);
  254. });
  255. // Need to set the expando to null on the cloned set if it exists
  256. // removeData doesn't work here, IE removes it from the original as well
  257. // this is primarily for IE but the data expando shouldn't be copied over in any browser
  258. var clone = ret.find("*").andSelf().each(function(){
  259. if ( this[ expando ] != undefined )
  260. this[ expando ] = null;
  261. });
  262. // Copy the events from the original to the clone
  263. if ( events === true )
  264. this.find("*").andSelf().each(function(i){
  265. if (this.nodeType == 3)
  266. return;
  267. var events = jQuery.data( this, "events" );
  268. for ( var type in events )
  269. for ( var handler in events[ type ] )
  270. jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );
  271. });
  272. // Return the cloned set
  273. return ret;
  274. },
  275. filter: function( selector ) {
  276. return this.pushStack(
  277. jQuery.isFunction( selector ) &&
  278. jQuery.grep(this, function(elem, i){
  279. return selector.call( elem, i );
  280. }) ||
  281. jQuery.multiFilter( selector, this ) );
  282. },
  283. not: function( selector ) {
  284. if ( selector.constructor == String )
  285. // test special case where just one selector is passed in
  286. if ( isSimple.test( selector ) )
  287. return this.pushStack( jQuery.multiFilter( selector, this, true ) );
  288. else
  289. selector = jQuery.multiFilter( selector, this );
  290. var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
  291. return this.filter(function() {
  292. return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
  293. });
  294. },
  295. add: function( selector ) {
  296. return !selector ? this : this.pushStack( jQuery.merge(
  297. this.get(),
  298. selector.constructor == String ?
  299. jQuery( selector ).get() :
  300. selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?
  301. selector : [selector] ) );
  302. },
  303. is: function( selector ) {
  304. return selector ?
  305. jQuery.multiFilter( selector, this ).length > 0 :
  306. false;
  307. },
  308. hasClass: function( selector ) {
  309. return this.is( "." + selector );
  310. },
  311. val: function( value ) {
  312. if ( value == undefined ) {
  313. if ( this.length ) {
  314. var elem = this[0];
  315. // We need to handle select boxes special
  316. if ( jQuery.nodeName( elem, "select" ) ) {
  317. var index = elem.selectedIndex,
  318. values = [],
  319. options = elem.options,
  320. one = elem.type == "select-one";
  321. // Nothing was selected
  322. if ( index < 0 )
  323. return null;
  324. // Loop through all the selected options
  325. for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
  326. var option = options[ i ];
  327. if ( option.selected ) {
  328. // Get the specifc value for the option
  329. value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;
  330. // We don't need an array for one selects
  331. if ( one )
  332. return value;
  333. // Multi-Selects return an array
  334. values.push( value );
  335. }
  336. }
  337. return values;
  338. // Everything else, we just grab the value
  339. } else
  340. return (this[0].value || "").replace(/\r/g, "");
  341. }
  342. return undefined;
  343. }
  344. return this.each(function(){
  345. if ( this.nodeType != 1 )
  346. return;
  347. if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )
  348. this.checked = (jQuery.inArray(this.value, value) >= 0 ||
  349. jQuery.inArray(this.name, value) >= 0);
  350. else if ( jQuery.nodeName( this, "select" ) ) {
  351. var values = value.constructor == Array ?
  352. value :
  353. [ value ];
  354. jQuery( "option", this ).each(function(){
  355. this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
  356. jQuery.inArray( this.text, values ) >= 0);
  357. });
  358. if ( !values.length )
  359. this.selectedIndex = -1;
  360. } else
  361. this.value = value;
  362. });
  363. },
  364. html: function( value ) {
  365. return value == undefined ?
  366. (this.length ?
  367. this[0].innerHTML :
  368. null) :
  369. this.empty().append( value );
  370. },
  371. replaceWith: function( value ) {
  372. return this.after( value ).remove();
  373. },
  374. eq: function( i ) {
  375. return this.slice( i, i + 1 );
  376. },
  377. slice: function() {
  378. return this.pushStack( Array.prototype.slice.apply( this, arguments ) );
  379. },
  380. map: function( callback ) {
  381. return this.pushStack( jQuery.map(this, function(elem, i){
  382. return callback.call( elem, i, elem );
  383. }));
  384. },
  385. andSelf: function() {
  386. return this.add( this.prevObject );
  387. },
  388. data: function( key, value ){
  389. var parts = key.split(".");
  390. parts[1] = parts[1] ? "." + parts[1] : "";
  391. if ( value == null ) {
  392. var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
  393. if ( data == undefined && this.length )
  394. data = jQuery.data( this[0], key );
  395. return data == null && parts[1] ?
  396. this.data( parts[0] ) :
  397. data;
  398. } else
  399. return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
  400. jQuery.data( this, key, value );
  401. });
  402. },
  403. removeData: function( key ){
  404. return this.each(function(){
  405. jQuery.removeData( this, key );
  406. });
  407. },
  408. domManip: function( args, table, reverse, callback ) {
  409. var clone = this.length > 1, elems;
  410. return this.each(function(){
  411. if ( !elems ) {
  412. elems = jQuery.clean( args, this.ownerDocument );
  413. if ( reverse )
  414. elems.reverse();
  415. }
  416. var obj = this;
  417. if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
  418. obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
  419. var scripts = jQuery( [] );
  420. jQuery.each(elems, function(){
  421. var elem = clone ?
  422. jQuery( this ).clone( true )[0] :
  423. this;
  424. // execute all scripts after the elements have been injected
  425. if ( jQuery.nodeName( elem, "script" ) ) {
  426. scripts = scripts.add( elem );
  427. } else {
  428. // Remove any inner scripts for later evaluation
  429. if ( elem.nodeType == 1 )
  430. scripts = scripts.add( jQuery( "script", elem ).remove() );
  431. // Inject the elements into the document
  432. callback.call( obj, elem );
  433. }
  434. });
  435. scripts.each( evalScript );
  436. });
  437. }
  438. };
  439. // Give the init function the jQuery prototype for later instantiation
  440. jQuery.prototype.init.prototype = jQuery.prototype;
  441. function evalScript( i, elem ) {
  442. if ( elem.src )
  443. jQuery.ajax({
  444. url: elem.src,
  445. async: false,
  446. dataType: "script"
  447. });
  448. else
  449. jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
  450. if ( elem.parentNode )
  451. elem.parentNode.removeChild( elem );
  452. }
  453. jQuery.extend = jQuery.fn.extend = function() {
  454. // copy reference to target object
  455. var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
  456. // Handle a deep copy situation
  457. if ( target.constructor == Boolean ) {
  458. deep = target;
  459. target = arguments[1] || {};
  460. // skip the boolean and the target
  461. i = 2;
  462. }
  463. // Handle case when target is a string or something (possible in deep copy)
  464. if ( typeof target != "object" && typeof target != "function" )
  465. target = {};
  466. // extend jQuery itself if only one argument is passed
  467. if ( length == 1 ) {
  468. target = this;
  469. i = 0;
  470. }
  471. for ( ; i < length; i++ )
  472. // Only deal with non-null/undefined values
  473. if ( (options = arguments[ i ]) != null )
  474. // Extend the base object
  475. for ( var name in options ) {
  476. // Prevent never-ending loop
  477. if ( target === options[ name ] )
  478. continue;
  479. // Recurse if we're merging object values
  480. if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )
  481. target[ name ] = jQuery.extend( target[ name ], options[ name ] );
  482. // Don't bring in undefined values
  483. else if ( options[ name ] != undefined )
  484. target[ name ] = options[ name ];
  485. }
  486. // Return the modified object
  487. return target;
  488. };
  489. var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};
  490. // exclude the following css properties to add px
  491. var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
  492. jQuery.extend({
  493. noConflict: function( deep ) {
  494. window.$ = _$;
  495. if ( deep )
  496. window.jQuery = _jQuery;
  497. return jQuery;
  498. },
  499. // See test/unit/core.js for details concerning this function.
  500. isFunction: function( fn ) {
  501. return !!fn && typeof fn != "string" && !fn.nodeName &&
  502. fn.constructor != Array && /function/i.test( fn + "" );
  503. },
  504. // check if an element is in a (or is an) XML document
  505. isXMLDoc: function( elem ) {
  506. return elem.documentElement && !elem.body ||
  507. elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;
  508. },
  509. // Evalulates a script in a global context
  510. globalEval: function( data ) {
  511. data = jQuery.trim( data );
  512. if ( data ) {
  513. // Inspired by code by Andrea Giammarchi
  514. // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
  515. var head = document.getElementsByTagName("head")[0] || document.documentElement,
  516. script = document.createElement("script");
  517. script.type = "text/javascript";
  518. if ( jQuery.browser.msie )
  519. script.text = data;
  520. else
  521. script.appendChild( document.createTextNode( data ) );
  522. head.appendChild( script );
  523. head.removeChild( script );
  524. }
  525. },
  526. nodeName: function( elem, name ) {
  527. return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
  528. },
  529. cache: {},
  530. data: function( elem, name, data ) {
  531. elem = elem == window ?
  532. windowData :
  533. elem;
  534. var id = elem[ expando ];
  535. // Compute a unique ID for the element
  536. if ( !id )
  537. id = elem[ expando ] = ++uuid;
  538. // Only generate the data cache if we're
  539. // trying to access or manipulate it
  540. if ( name && !jQuery.cache[ id ] )
  541. jQuery.cache[ id ] = {};
  542. // Prevent overriding the named cache with undefined values
  543. if ( data != undefined )
  544. jQuery.cache[ id ][ name ] = data;
  545. // Return the named cache data, or the ID for the element
  546. return name ?
  547. jQuery.cache[ id ][ name ] :
  548. id;
  549. },
  550. removeData: function( elem, name ) {
  551. elem = elem == window ?
  552. windowData :
  553. elem;
  554. var id = elem[ expando ];
  555. // If we want to remove a specific section of the element's data
  556. if ( name ) {
  557. if ( jQuery.cache[ id ] ) {
  558. // Remove the section of cache data
  559. delete jQuery.cache[ id ][ name ];
  560. // If we've removed all the data, remove the element's cache
  561. name = "";
  562. for ( name in jQuery.cache[ id ] )
  563. break;
  564. if ( !name )
  565. jQuery.removeData( elem );
  566. }
  567. // Otherwise, we want to remove all of the element's data
  568. } else {
  569. // Clean up the element expando
  570. try {
  571. delete elem[ expando ];
  572. } catch(e){
  573. // IE has trouble directly removing the expando
  574. // but it's ok with using removeAttribute
  575. if ( elem.removeAttribute )
  576. elem.removeAttribute( expando );
  577. }
  578. // Completely remove the data cache
  579. delete jQuery.cache[ id ];
  580. }
  581. },
  582. // args is for internal usage only
  583. each: function( object, callback, args ) {
  584. if ( args ) {
  585. if ( object.length == undefined ) {
  586. for ( var name in object )
  587. if ( callback.apply( object[ name ], args ) === false )
  588. break;
  589. } else
  590. for ( var i = 0, length = object.length; i < length; i++ )
  591. if ( callback.apply( object[ i ], args ) === false )
  592. break;
  593. // A special, fast, case for the most common use of each
  594. } else {
  595. if ( object.length == undefined ) {
  596. for ( var name in object )
  597. if ( callback.call( object[ name ], name, object[ name ] ) === false )
  598. break;
  599. } else
  600. for ( var i = 0, length = object.length, value = object[0];
  601. i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
  602. }
  603. return object;
  604. },
  605. prop: function( elem, value, type, i, name ) {
  606. // Handle executable functions
  607. if ( jQuery.isFunction( value ) )
  608. value = value.call( elem, i );
  609. // Handle passing in a number to a CSS property
  610. return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?
  611. value + "px" :
  612. value;
  613. },
  614. className: {
  615. // internal only, use addClass("class")
  616. add: function( elem, classNames ) {
  617. jQuery.each((classNames || "").split(/\s+/), function(i, className){
  618. if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
  619. elem.className += (elem.className ? " " : "") + className;
  620. });
  621. },
  622. // internal only, use removeClass("class")
  623. remove: function( elem, classNames ) {
  624. if (elem.nodeType == 1)
  625. elem.className = classNames != undefined ?
  626. jQuery.grep(elem.className.split(/\s+/), function(className){
  627. return !jQuery.className.has( classNames, className );
  628. }).join(" ") :
  629. "";
  630. },
  631. // internal only, use is(".class")
  632. has: function( elem, className ) {
  633. return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
  634. }
  635. },
  636. // A method for quickly swapping in/out CSS properties to get correct calculations
  637. swap: function( elem, options, callback ) {
  638. var old = {};
  639. // Remember the old values, and insert the new ones
  640. for ( var name in options ) {
  641. old[ name ] = elem.style[ name ];
  642. elem.style[ name ] = options[ name ];
  643. }
  644. callback.call( elem );
  645. // Revert the old values
  646. for ( var name in options )
  647. elem.style[ name ] = old[ name ];
  648. },
  649. css: function( elem, name, force ) {
  650. if ( name == "width" || name == "height" ) {
  651. var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
  652. function getWH() {
  653. val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
  654. var padding = 0, border = 0;
  655. jQuery.each( which, function() {
  656. padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
  657. border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
  658. });
  659. val -= Math.round(padding + border);
  660. }
  661. if ( jQuery(elem).is(":visible") )
  662. getWH();
  663. else
  664. jQuery.swap( elem, props, getWH );
  665. return Math.max(0, val);
  666. }
  667. return jQuery.curCSS( elem, name, force );
  668. },
  669. curCSS: function( elem, name, force ) {
  670. var ret;
  671. // A helper method for determining if an element's values are broken
  672. function color( elem ) {
  673. if ( !jQuery.browser.safari )
  674. return false;
  675. var ret = document.defaultView.getComputedStyle( elem, null );
  676. return !ret || ret.getPropertyValue("color") == "";
  677. }
  678. // We need to handle opacity special in IE
  679. if ( name == "opacity" && jQuery.browser.msie ) {
  680. ret = jQuery.attr( elem.style, "opacity" );
  681. return ret == "" ?
  682. "1" :
  683. ret;
  684. }
  685. // Opera sometimes will give the wrong display answer, this fixes it, see #2037
  686. if ( jQuery.browser.opera && name == "display" ) {
  687. var save = elem.style.display;
  688. elem.style.display = "block";
  689. elem.style.display = save;
  690. }
  691. // Make sure we're using the right name for getting the float value
  692. if ( name.match( /float/i ) )
  693. name = styleFloat;
  694. if ( !force && elem.style && elem.style[ name ] )
  695. ret = elem.style[ name ];
  696. else if ( document.defaultView && document.defaultView.getComputedStyle ) {
  697. // Only "float" is needed here
  698. if ( name.match( /float/i ) )
  699. name = "float";
  700. name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
  701. var getComputedStyle = document.defaultView.getComputedStyle( elem, null );
  702. if ( getComputedStyle && !color( elem ) )
  703. ret = getComputedStyle.getPropertyValue( name );
  704. // If the element isn't reporting its values properly in Safari
  705. // then some display: none elements are involved
  706. else {
  707. var swap = [], stack = [];
  708. // Locate all of the parent display: none elements
  709. for ( var a = elem; a && color(a); a = a.parentNode )
  710. stack.unshift(a);
  711. // Go through and make them visible, but in reverse
  712. // (It would be better if we knew the exact display type that they had)
  713. for ( var i = 0; i < stack.length; i++ )
  714. if ( color( stack[ i ] ) ) {
  715. swap[ i ] = stack[ i ].style.display;
  716. stack[ i ].style.display = "block";
  717. }
  718. // Since we flip the display style, we have to handle that
  719. // one special, otherwise get the value
  720. ret = name == "display" && swap[ stack.length - 1 ] != null ?
  721. "none" :
  722. ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";
  723. // Finally, revert the display styles back
  724. for ( var i = 0; i < swap.length; i++ )
  725. if ( swap[ i ] != null )
  726. stack[ i ].style.display = swap[ i ];
  727. }
  728. // We should always get a number back from opacity
  729. if ( name == "opacity" && ret == "" )
  730. ret = "1";
  731. } else if ( elem.currentStyle ) {
  732. var camelCase = name.replace(/\-(\w)/g, function(all, letter){
  733. return letter.toUpperCase();
  734. });
  735. ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
  736. // From the awesome hack by Dean Edwards
  737. // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
  738. // If we're not dealing with a regular pixel number
  739. // but a number that has a weird ending, we need to convert it to pixels
  740. if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
  741. // Remember the original values
  742. var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;
  743. // Put in the new values to get a computed value out
  744. elem.runtimeStyle.left = elem.currentStyle.left;
  745. elem.style.left = ret || 0;
  746. ret = elem.style.pixelLeft + "px";
  747. // Revert the changed values
  748. elem.style.left = style;
  749. elem.runtimeStyle.left = runtimeStyle;
  750. }
  751. }
  752. return ret;
  753. },
  754. clean: function( elems, context ) {
  755. var ret = [];
  756. context = context || document;
  757. // !context.createElement fails in IE with an error but returns typeof 'object'
  758. if (typeof context.createElement == 'undefined')
  759. context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
  760. jQuery.each(elems, function(i, elem){
  761. if ( !elem )
  762. return;
  763. if ( elem.constructor == Number )
  764. elem = elem.toString();
  765. // Convert html string into DOM nodes
  766. if ( typeof elem == "string" ) {
  767. // Fix "XHTML"-style tags in all browsers
  768. elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
  769. return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
  770. all :
  771. front + "></" + tag + ">";
  772. });
  773. // Trim whitespace, otherwise indexOf won't work as expected
  774. var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
  775. var wrap =
  776. // option or optgroup
  777. !tags.indexOf("<opt") &&
  778. [ 1, "<select multiple='multiple'>", "</select>" ] ||
  779. !tags.indexOf("<leg") &&
  780. [ 1, "<fieldset>", "</fieldset>" ] ||
  781. tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
  782. [ 1, "<table>", "</table>" ] ||
  783. !tags.indexOf("<tr") &&
  784. [ 2, "<table><tbody>", "</tbody></table>" ] ||
  785. // <thead> matched above
  786. (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
  787. [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
  788. !tags.indexOf("<col") &&
  789. [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
  790. // IE can't serialize <link> and <script> tags normally
  791. jQuery.browser.msie &&
  792. [ 1, "div<div>", "</div>" ] ||
  793. [ 0, "", "" ];
  794. // Go to html and back, then peel off extra wrappers
  795. div.innerHTML = wrap[1] + elem + wrap[2];
  796. // Move to the right depth
  797. while ( wrap[0]-- )
  798. div = div.lastChild;
  799. // Remove IE's autoinserted <tbody> from table fragments
  800. if ( jQuery.browser.msie ) {
  801. // String was a <table>, *may* have spurious <tbody>
  802. var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?
  803. div.firstChild && div.firstChild.childNodes :
  804. // String was a bare <thead> or <tfoot>
  805. wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?
  806. div.childNodes :
  807. [];
  808. for ( var j = tbody.length - 1; j >= 0 ; --j )
  809. if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
  810. tbody[ j ].parentNode.removeChild( tbody[ j ] );
  811. // IE completely kills leading whitespace when innerHTML is used
  812. if ( /^\s/.test( elem ) )
  813. div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
  814. }
  815. elem = jQuery.makeArray( div.childNodes );
  816. }
  817. if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )
  818. return;
  819. if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )
  820. ret.push( elem );
  821. else
  822. ret = jQuery.merge( ret, elem );
  823. });
  824. return ret;
  825. },
  826. attr: function( elem, name, value ) {
  827. // don't set attributes on text and comment nodes
  828. if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
  829. return undefined;
  830. var fix = jQuery.isXMLDoc( elem ) ?
  831. {} :
  832. jQuery.props;
  833. // Safari mis-reports the default selected property of a hidden option
  834. // Accessing the parent's selectedIndex property fixes it
  835. if ( name == "selected" && jQuery.browser.safari )
  836. elem.parentNode.selectedIndex;
  837. // Certain attributes only work when accessed via the old DOM 0 way
  838. if ( fix[ name ] ) {
  839. if ( value != undefined )
  840. elem[ fix[ name ] ] = value;
  841. return elem[ fix[ name ] ];
  842. } else if ( jQuery.browser.msie && name == "style" )
  843. return jQuery.attr( elem.style, "cssText", value );
  844. else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )
  845. return elem.getAttributeNode( name ).nodeValue;
  846. // IE elem.getAttribute passes even for style
  847. else if ( elem.tagName ) {
  848. if ( value != undefined ) {
  849. // We can't allow the type property to be changed (since it causes problems in IE)
  850. if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
  851. throw "type property can't be changed";
  852. // convert the value to a string (all browsers do this but IE) see #1070
  853. elem.setAttribute( name, "" + value );
  854. }
  855. if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) )
  856. return elem.getAttribute( name, 2 );
  857. return elem.getAttribute( name );
  858. // elem is actually elem.style ... set the style
  859. } else {
  860. // IE actually uses filters for opacity
  861. if ( name == "opacity" && jQuery.browser.msie ) {
  862. if ( value != undefined ) {
  863. // IE has trouble with opacity if it does not have layout
  864. // Force it by setting the zoom level
  865. elem.zoom = 1;
  866. // Set the alpha filter to set the opacity
  867. elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
  868. (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
  869. }
  870. return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
  871. (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :
  872. "";
  873. }
  874. name = name.replace(/-([a-z])/ig, function(all, letter){
  875. return letter.toUpperCase();
  876. });
  877. if ( value != undefined )
  878. elem[ name ] = value;
  879. return elem[ name ];
  880. }
  881. },
  882. trim: function( text ) {
  883. return (text || "").replace( /^\s+|\s+$/g, "" );
  884. },
  885. makeArray: function( array ) {
  886. var ret = [];
  887. // Need to use typeof to fight Safari childNodes crashes
  888. if ( typeof array != "array" )
  889. for ( var i = 0, length = array.length; i < length; i++ )
  890. ret.push( array[ i ] );
  891. else
  892. ret = array.slice( 0 );
  893. return ret;
  894. },
  895. inArray: function( elem, array ) {
  896. for ( var i = 0, length = array.length; i < length; i++ )
  897. if ( array[ i ] == elem )
  898. return i;
  899. return -1;
  900. },
  901. merge: function( first, second ) {
  902. // We have to loop this way because IE & Opera overwrite the length
  903. // expando of getElementsByTagName
  904. // Also, we need to make sure that the correct elements are being returned
  905. // (IE returns comment nodes in a '*' query)
  906. if ( jQuery.browser.msie ) {
  907. for ( var i = 0; second[ i ]; i++ )
  908. if ( second[ i ].nodeType != 8 )
  909. first.push( second[ i ] );
  910. } else
  911. for ( var i = 0; second[ i ]; i++ )
  912. first.push( second[ i ] );
  913. return first;
  914. },
  915. unique: function( array ) {
  916. var ret = [], done = {};
  917. try {
  918. for ( var i = 0, length = array.length; i < length; i++ ) {
  919. var id = jQuery.data( array[ i ] );
  920. if ( !done[ id ] ) {
  921. done[ id ] = true;
  922. ret.push( array[ i ] );
  923. }
  924. }
  925. } catch( e ) {
  926. ret = array;
  927. }
  928. return ret;
  929. },
  930. grep: function( elems, callback, inv ) {
  931. var ret = [];
  932. // Go through the array, only saving the items
  933. // that pass the validator function
  934. for ( var i = 0, length = elems.length; i < length; i++ )
  935. if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )
  936. ret.push( elems[ i ] );
  937. return ret;
  938. },
  939. map: function( elems, callback ) {
  940. var ret = [];
  941. // Go through the array, translating each of the items to their
  942. // new value (or values).
  943. for ( var i = 0, length = elems.length; i < length; i++ ) {
  944. var value = callback( elems[ i ], i );
  945. if ( value !== null && value != undefined ) {
  946. if ( value.constructor != Array )
  947. value = [ value ];
  948. ret = ret.concat( value );
  949. }
  950. }
  951. return ret;
  952. }
  953. });
  954. var userAgent = navigator.userAgent.toLowerCase();
  955. // Figure out what browser is being used
  956. jQuery.browser = {
  957. version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
  958. safari: /webkit/.test( userAgent ),
  959. opera: /opera/.test( userAgent ),
  960. msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
  961. mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  962. };
  963. var styleFloat = jQuery.browser.msie ?
  964. "styleFloat" :
  965. "cssFloat";
  966. jQuery.extend({
  967. // Check to see if the W3C box model is being used
  968. boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",
  969. props: {
  970. "for": "htmlFor",
  971. "class": "className",
  972. "float": styleFloat,
  973. cssFloat: styleFloat,
  974. styleFloat: styleFloat,
  975. innerHTML: "innerHTML",
  976. className: "className",
  977. value: "value",
  978. disabled: "disabled",
  979. checked: "checked",
  980. readonly: "readOnly",
  981. selected: "selected",
  982. maxlength: "maxLength",
  983. selectedIndex: "selectedIndex",
  984. defaultValue: "defaultValue",
  985. tagName: "tagName",
  986. nodeName: "nodeName"
  987. }
  988. });
  989. jQuery.each({
  990. parent: function(elem){return elem.parentNode;},
  991. parents: function(elem){return jQuery.dir(elem,"parentNode");},
  992. next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
  993. prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
  994. nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
  995. prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
  996. siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
  997. children: function(elem){return jQuery.sibling(elem.firstChild);},
  998. contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
  999. }, function(name, fn){
  1000. jQuery.fn[ name ] = function( selector ) {
  1001. var ret = jQuery.map( this, fn );
  1002. if ( selector && typeof selector == "string" )
  1003. ret = jQuery.multiFilter( selector, ret );
  1004. return this.pushStack( jQuery.unique( ret ) );
  1005. };
  1006. });
  1007. jQuery.each({
  1008. appendTo: "append",
  1009. prependTo: "prepend",
  1010. insertBefore: "before",
  1011. insertAfter: "after",
  1012. replaceAll: "replaceWith"
  1013. }, function(name, original){
  1014. jQuery.fn[ name ] = function() {
  1015. var args = arguments;
  1016. return this.each(function(){
  1017. for ( var i = 0, length = args.length; i < length; i++ )
  1018. jQuery( args[ i ] )[ original ]( this );
  1019. });
  1020. };
  1021. });
  1022. jQuery.each({
  1023. removeAttr: function( name ) {
  1024. jQuery.attr( this, name, "" );
  1025. if (this.nodeType == 1)
  1026. this.removeAttribute( name );
  1027. },
  1028. addClass: function( classNames ) {
  1029. jQuery.className.add( this, classNames );
  1030. },
  1031. removeClass: function( classNames ) {
  1032. jQuery.className.remove( this, classNames );
  1033. },
  1034. toggleClass: function( classNames ) {
  1035. jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
  1036. },
  1037. remove: function( selector ) {
  1038. if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {
  1039. // Prevent memory leaks
  1040. jQuery( "*", this ).add(this).each(function(){
  1041. jQuery.event.remove(this);
  1042. jQuery.removeData(this);
  1043. });
  1044. if (this.parentNode)
  1045. this.parentNode.removeChild( this );
  1046. }
  1047. },
  1048. empty: function() {
  1049. // Remove element nodes and prevent memory leaks
  1050. jQuery( ">*", this ).remove();
  1051. // Remove any remaining nodes
  1052. while ( this.firstChild )
  1053. this.removeChild( this.firstChild );
  1054. }
  1055. }, function(name, fn){
  1056. jQuery.fn[ name ] = function(){
  1057. return this.each( fn, arguments );
  1058. };
  1059. });
  1060. jQuery.each([ "Height", "Width" ], function(i, name){
  1061. var type = name.toLowerCase();
  1062. jQuery.fn[ type ] = function( size ) {
  1063. // Get window width or height
  1064. return this[0] == window ?
  1065. // Opera reports document.body.client[Width/Height] properly in both quirks and standards
  1066. jQuery.browser.opera && document.body[ "client" + name ] ||
  1067. // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)
  1068. jQuery.browser.safari && window[ "inner" + name ] ||
  1069. // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode
  1070. document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :
  1071. // Get document width or height
  1072. this[0] == document ?
  1073. // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
  1074. Math.max(
  1075. Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]),
  1076. Math.max(document.body["offset" + name], document.documentElement["offset" + name])
  1077. ) :
  1078. // Get or set width or height on the element
  1079. size == undefined ?
  1080. // Get width or height on the element
  1081. (this.length ? jQuery.css( this[0], type ) : null) :
  1082. // Set the width or height on the element (default to pixels if value is unitless)
  1083. this.css( type, size.constructor == String ? size : size + "px" );
  1084. };
  1085. });
  1086. var chars = jQuery.browser.safari && parseInt(jQuery.browser.version) < 417 ?
  1087. "(?:[\\w*_-]|\\\\.)" :
  1088. "(?:[\\w\u0128-\uFFFF*_-]|\\\\.)",
  1089. quickChild = new RegExp("^>\\s*(" + chars + "+)"),
  1090. quickID = new RegExp("^(" + chars + "+)(#)(" + chars + "+)"),
  1091. quickClass = new RegExp("^([#.]?)(" + chars + "*)");
  1092. jQuery.extend({
  1093. expr: {
  1094. "": function(a,i,m){return m[2]=="*"||jQuery.nodeName(a,m[2]);},
  1095. "#": function(a,i,m){return a.getAttribute("id")==m[2];},
  1096. ":": {
  1097. // Position Checks
  1098. lt: function(a,i,m){return i<m[3]-0;},
  1099. gt: function(a,i,m){return i>m[3]-0;},
  1100. nth: function(a,i,m){return m[3]-0==i;},
  1101. eq: function(a,i,m){return m[3]-0==i;},
  1102. first: function(a,i){return i==0;},
  1103. last: function(a,i,m,r){return i==r.length-1;},
  1104. even: function(a,i){return i%2==0;},
  1105. odd: function(a,i){return i%2;},
  1106. // Child Checks
  1107. "first-child": function(a){return a.parentNode.getElementsByTagName("*")[0]==a;},
  1108. "last-child": function(a){return jQuery.nth(a.parentNode.lastChild,1,"previousSibling")==a;},
  1109. "only-child": function(a){return !jQuery.nth(a.parentNode.lastChild,2,"previousSibling");},
  1110. // Parent Checks
  1111. parent: function(a){return a.firstChild;},
  1112. empty: function(a){return !a.firstChild;},
  1113. // Text Check
  1114. contains: function(a,i,m){return (a.textContent||a.innerText||jQuery(a).text()||"").indexOf(m[3])>=0;},
  1115. // Visibility
  1116. visible: function(a){return "hidden"!=a.type&&jQuery.css(a,"display")!="none"&&jQuery.css(a,"visibility")!="hidden";},
  1117. hidden: function(a){return "hidden"==a.type||jQuery.css(a,"display")=="none"||jQuery.css(a,"visibility")=="hidden";},
  1118. // Form attributes
  1119. enabled: function(a){return !a.disabled;},
  1120. disabled: function(a){return a.disabled;},
  1121. checked: function(a){return a.checked;},
  1122. selected: function(a){return a.selected||jQuery.attr(a,"selected");},
  1123. // Form elements
  1124. text: function(a){return "text"==a.type;},
  1125. radio: function(a){return "radio"==a.type;},
  1126. checkbox: function(a){return "checkbox"==a.type;},
  1127. file: function(a){return "file"==a.type;},
  1128. password: function(a){return "password"==a.type;},
  1129. submit: function(a){return "submit"==a.type;},
  1130. image: function(a){return "image"==a.type;},
  1131. reset: function(a){return "reset"==a.type;},
  1132. button: function(a){return "button"==a.type||jQuery.nodeName(a,"button");},
  1133. input: function(a){return /input|select|textarea|button/i.test(a.nodeName);},
  1134. // :has()
  1135. has: function(a,i,m){return jQuery.find(m[3],a).length;},
  1136. // :header
  1137. header: function(a){return /h\d/i.test(a.nodeName);},
  1138. // :animated
  1139. animated: function(a){return jQuery.grep(jQuery.timers,function(fn){return a==fn.elem;}).length;}
  1140. }
  1141. },
  1142. // The regular expressions that power the parsing engine
  1143. parse: [
  1144. // Match: [@value='test'], [@foo]
  1145. /^(\[) *@?([\w-]+) *([!*$^~=]*) *('?"?)(.*?)\4 *\]/,
  1146. // Match: :contains('foo')
  1147. /^(:)([\w-]+)\("?'?(.*?(\(.*?\))?[^(]*?)"?'?\)/,
  1148. // Match: :even, :last-chlid, #id, .class
  1149. new RegExp("^([:.#]*)(" + chars + "+)")
  1150. ],
  1151. multiFilter: function( expr, elems, not ) {
  1152. var old, cur = [];
  1153. while ( expr && expr != old ) {
  1154. old = expr;
  1155. var f = jQuery.filter( expr, elems, not );
  1156. expr = f.t.replace(/^\s*,\s*/, "" );
  1157. cur = not ? elems = f.r : jQuery.merge( cur, f.r );
  1158. }
  1159. return cur;
  1160. },
  1161. find: function( t, context ) {
  1162. // Quickly handle non-string expressions
  1163. if ( typeof t != "string" )
  1164. return [ t ];
  1165. // check to make sure context is a DOM element or a document
  1166. if ( context && context.nodeType != 1 && context.nodeType != 9)
  1167. return [ ];
  1168. // Set the correct context (if none is provided)
  1169. context = context || document;
  1170. // Initialize the search
  1171. var ret = [context], done = [], last, nodeName;
  1172. // Continue while a selector expression exists, and while
  1173. // we're no longer looping upon ourselves
  1174. while ( t && last != t ) {
  1175. var r = [];
  1176. last = t;
  1177. t = jQuery.trim(t);
  1178. var foundToken = false;
  1179. // An attempt at speeding up child selectors that
  1180. // point to a specific element tag
  1181. var re = quickChild;
  1182. var m = re.exec(t);
  1183. if ( m ) {
  1184. nodeName = m[1].toUpperCase();
  1185. // Perform our own iteration and filter
  1186. for ( var i = 0; ret[i]; i++ )
  1187. for ( var c = ret[i].firstChild; c; c = c.nextSibling )
  1188. if ( c.nodeType == 1 && (nodeName == "*" || c.nodeName.toUpperCase() == nodeName) )
  1189. r.push( c );
  1190. ret = r;
  1191. t = t.replace( re, "" );
  1192. if ( t.indexOf(" ") == 0 ) continue;
  1193. foundToken = true;
  1194. } else {
  1195. re = /^([>+~])\s*(\w*)/i;
  1196. if ( (m = re.exec(t)) != null ) {
  1197. r = [];
  1198. var merge = {};
  1199. nodeName = m[2].toUpperCase();
  1200. m = m[1];
  1201. for ( var j = 0, rl = ret.length; j < rl; j++ ) {
  1202. var n = m == "~" || m == "+" ? ret[j].nextSibling : ret[j].firstChild;
  1203. for ( ; n; n = n.nextSibling )
  1204. if ( n.nodeType == 1 ) {
  1205. var id = jQuery.data(n);
  1206. if ( m == "~" && merge[id] ) break;
  1207. if (!nodeName || n.nodeName.toUpperCase() == nodeName ) {
  1208. if ( m == "~" ) merge[id] = true;
  1209. r.push( n );
  1210. }
  1211. if ( m == "+" ) break;
  1212. }
  1213. }
  1214. ret = r;
  1215. // And remove the token
  1216. t = jQuery.trim( t.replace( re, "" ) );
  1217. foundToken = true;
  1218. }
  1219. }
  1220. // See if there's still an expression, and that we haven't already
  1221. // matched a token
  1222. if ( t && !foundToken ) {
  1223. // Handle multiple expressions
  1224. if ( !t.indexOf(",") ) {
  1225. // Clean the result set
  1226. if ( context == ret[0] ) ret.shift();
  1227. // Merge the result sets
  1228. done = jQuery.merge( done, ret );
  1229. // Reset the context
  1230. r = ret = [context];
  1231. // Touch up the selector string
  1232. t = " " + t.substr(1,t.length);
  1233. } else {
  1234. // Optimize for the case nodeName#idName
  1235. var re2 = quickID;
  1236. var m = re2.exec(t);
  1237. // Re-organize the results, so that they're consistent
  1238. if ( m ) {
  1239. m = [ 0, m[2], m[3], m[1] ];
  1240. } else {
  1241. // Otherwise, do a traditional filter check for
  1242. // ID, class, and element selectors
  1243. re2 = quickClass;
  1244. m = re2.exec(t);
  1245. }
  1246. m[2] = m[2].replace(/\\/g, "");
  1247. var elem = ret[ret.length-1];
  1248. // Try to do a global search by ID, where we can
  1249. if ( m[1] == "#" && elem && elem.getElementById && !jQuery.isXMLDoc(elem) ) {
  1250. // Optimization for HTML document case
  1251. var oid = elem.getElementById(m[2]);
  1252. // Do a quick check for the existence of the actual ID attribute
  1253. // to avoid selecting by the name attribute in IE
  1254. // also check to insure id is a string to avoid selecting an element with the name of 'id' inside a form
  1255. if ( (jQuery.browser.msie||jQuery.browser.opera) && oid && typeof oid.id == "string" && oid.id != m[2] )
  1256. oid = jQuery('[@id="'+m[2]+'"]', elem)[0];
  1257. // Do a quick check for node name (where applicable) so
  1258. // that div#foo searches will be really fast
  1259. ret = r = oid && (!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];
  1260. } else {
  1261. // We need to find all descendant elements
  1262. for ( var i = 0; ret[i]; i++ ) {
  1263. // Grab the tag name being searched for
  1264. var tag = m[1] == "#" && m[3] ? m[3] : m[1] != "" || m[0] == "" ? "*" : m[2];
  1265. // Handle IE7 being really dumb about <object>s
  1266. if ( tag == "*" && ret[i].nodeName.toLowerCase() == "object" )
  1267. tag = "param";
  1268. r = jQuery.merge( r, ret[i].getElementsByTagName( tag ));
  1269. }
  1270. // It's faster to filter by class and be done with it
  1271. if ( m[1] == "." )
  1272. r = jQuery.classFilter( r, m[2] );
  1273. // Same with ID filtering
  1274. if ( m[1] == "#" ) {
  1275. var tmp = [];
  1276. // Try to find the element with the ID
  1277. for ( var i = 0; r[i]; i++ )
  1278. if ( r[i].getAttribute("id") == m[2] ) {
  1279. tmp = [ r[i] ];
  1280. break;
  1281. }
  1282. r = tmp;
  1283. }
  1284. ret = r;
  1285. }
  1286. t = t.replace( re2, "" );
  1287. }
  1288. }
  1289. // If a selector string still exists
  1290. if ( t ) {
  1291. // Attempt to filter it
  1292. var val = jQuery.filter(t,r);
  1293. ret = r = val.r;
  1294. t = jQuery.trim(val.t);
  1295. }
  1296. }
  1297. // An error occurred with the selector;
  1298. // just return an empty set instead
  1299. if ( t )
  1300. ret = [];
  1301. // Remove the root context
  1302. if ( ret && context == ret[0] )
  1303. ret.shift();
  1304. // And combine the results
  1305. done = jQuery.merge( done, ret );
  1306. return done;
  1307. },
  1308. classFilter: function(r,m,not){
  1309. m = " " + m + " ";
  1310. var tmp = [];
  1311. for ( var i = 0; r[i]; i++ ) {
  1312. var pass = (" " + r[i].className + " ").indexOf( m ) >= 0;
  1313. if ( !not && pass || not && !pass )
  1314. tmp.push( r[i] );
  1315. }
  1316. return tmp;
  1317. },
  1318. filter: function(t,r,not) {
  1319. var last;
  1320. // Look for common filter expressions
  1321. while ( t && t != last ) {
  1322. last = t;
  1323. var p = jQuery.parse, m;
  1324. for ( var i = 0; p[i]; i++ ) {
  1325. m = p[i].exec( t );
  1326. if ( m ) {
  1327. // Remove what we just matched
  1328. t = t.substring( m[0].length );
  1329. m[2] = m[2].replace(/\\/g, "");
  1330. break;
  1331. }
  1332. }
  1333. if ( !m )
  1334. break;
  1335. // :not() is a special case that can be optimized by
  1336. // keeping it out of the expression list
  1337. if ( m[1] == ":" && m[2] == "not" )
  1338. // optimize if only one selector found (most common case)
  1339. r = isSimple.test( m[3] ) ?
  1340. jQuery.filter(m[3], r, true).r :
  1341. jQuery( r ).not( m[3] );
  1342. // We can get a big speed boost by filtering by class here
  1343. else if ( m[1] == "." )
  1344. r = jQuery.classFilter(r, m[2], not);
  1345. else if ( m[1] == "[" ) {
  1346. var tmp = [], type = m[3];
  1347. for ( var i = 0, rl = r.length; i < rl; i++ ) {
  1348. var a = r[i], z = a[ jQuery.props[m[2]] || m[2] ];
  1349. if ( z == null || /href|src|selected/.test(m[2]) )
  1350. z = jQuery.attr(a,m[2]) || '';
  1351. if ( (type == "" && !!z ||
  1352. type == "=" && z == m[5] ||
  1353. type == "!=" && z != m[5] ||
  1354. type == "^=" && z && !z.indexOf(m[5]) ||
  1355. type == "$=" && z.substr(z.length - m[5].length) == m[5] ||
  1356. (type == "*=" || type == "~=") && z.indexOf(m[5]) >= 0) ^ not )
  1357. tmp.push( a );
  1358. }
  1359. r = tmp;
  1360. // We can get a speed boost by handling nth-child here
  1361. } else if ( m[1] == ":" && m[2] == "nth-child" ) {
  1362. var merge = {}, tmp = [],
  1363. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  1364. test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  1365. m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
  1366. !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
  1367. // calculate the numbers (first)n+(last) including if they are negative
  1368. first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
  1369. // loop through all the elements left in the jQuery object
  1370. for ( var i = 0, rl = r.length; i < rl; i++ ) {
  1371. var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
  1372. if ( !merge[id] ) {
  1373. var c = 1;
  1374. for ( var n = parentNode.firstChild; n; n = n.nextSibling )
  1375. if ( n.nodeType == 1 )
  1376. n.nodeIndex = c++;
  1377. merge[id] = true;
  1378. }
  1379. var add = false;
  1380. if ( first == 0 ) {
  1381. if ( node.nodeIndex == last )
  1382. add = true;
  1383. } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
  1384. add = true;
  1385. if ( add ^ not )
  1386. tmp.push( node );
  1387. }
  1388. r = tmp;
  1389. // Otherwise, find the expression to execute
  1390. } else {
  1391. var fn = jQuery.expr[ m[1] ];
  1392. if ( typeof fn == "object" )
  1393. fn = fn[ m[2] ];
  1394. if ( typeof fn == "string" )
  1395. fn = eval("false||function(a,i){return " + fn + ";}");
  1396. // Execute it against the current filter
  1397. r = jQuery.grep( r, function(elem, i){
  1398. return fn(elem, i, m, r);
  1399. }, not );
  1400. }
  1401. }
  1402. // Return an array of filtered elements (r)
  1403. // and the modified expression string (t)
  1404. return { r: r, t: t };
  1405. },
  1406. dir: function( elem, dir ){
  1407. var matched = [];
  1408. var cur = elem[dir];
  1409. while ( cur && cur != document ) {
  1410. if ( cur.nodeType == 1 )
  1411. matched.push( cur );
  1412. cur = cur[dir];
  1413. }
  1414. return matched;
  1415. },
  1416. nth: function(cur,result,dir,elem){
  1417. result = result || 1;
  1418. var num = 0;
  1419. for ( ; cur; cur = cur[dir] )
  1420. if ( cur.nodeType == 1 && ++num == result )
  1421. break;
  1422. return cur;
  1423. },
  1424. sibling: function( n, elem ) {
  1425. var r = [];
  1426. for ( ; n; n = n.nextSibling ) {
  1427. if ( n.nodeType == 1 && (!elem || n != elem) )
  1428. r.push( n );
  1429. }
  1430. return r;
  1431. }
  1432. });
  1433. /*
  1434. * A number of helper functions used for managing events.
  1435. * Many of the ideas behind this code orignated from
  1436. * Dean Edwards' addEvent library.
  1437. */
  1438. jQuery.event = {
  1439. // Bind an event to an element
  1440. // Original by Dean Edwards
  1441. add: function(elem, types, handler, data) {
  1442. if ( elem.nodeType == 3 || elem.nodeType == 8 )
  1443. return;
  1444. // For whatever reason, IE has trouble passing the window object
  1445. // around, causing it to be cloned in the process
  1446. if ( jQuery.browser.msie && elem.setInterval != undefined )
  1447. elem = window;
  1448. // Make sure that the function being executed has a unique ID
  1449. if ( !handler.guid )
  1450. handler.guid = this.guid++;
  1451. // if data is passed, bind to handler
  1452. if( data != undefined ) {
  1453. // Create temporary function pointer to original handler
  1454. var fn = handler;
  1455. // Create unique handler function, wrapped around original handler
  1456. handler = function() {
  1457. // Pass arguments and context to original handler
  1458. return fn.apply(this, arguments);
  1459. };
  1460. // Store data in unique handler
  1461. handler.data = data;
  1462. // Set the guid of unique handler to the same of original handler, so it can be removed
  1463. handler.guid = fn.guid;
  1464. }
  1465. // Init the element's event structure
  1466. var events = jQuery.data(elem, "events") || jQuery.data(elem, "events", {}),
  1467. handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
  1468. // returned undefined or false
  1469. var val;
  1470. // Handle the second event of a trigger and when
  1471. // an event is called after a page has unloaded
  1472. if ( typeof jQuery == "undefined" || jQuery.event.triggered )
  1473. return val;
  1474. val = jQuery.event.handle.apply(arguments.callee.elem, arguments);
  1475. return val;
  1476. });
  1477. // Add elem as a property of the handle function
  1478. // This is to prevent a memory leak with non-native
  1479. // event in IE.
  1480. handle.elem = elem;
  1481. // Handle multiple events seperated by a space
  1482. // jQuery(...).bind("mouseover mouseout", fn);
  1483. jQuery.each(types.split(/\s+/), function(index, type) {
  1484. // Namespaced event handlers
  1485. var parts = type.split(".");
  1486. type = parts[0];
  1487. handler.type = parts[1];
  1488. // Get the current list of functions bound to this event
  1489. var handlers = events[type];
  1490. // Init the event handler queue
  1491. if (!handlers) {
  1492. handlers = events[type] = {};
  1493. // Check for a special event handler
  1494. // Only use addEventListener/attachEvent if the special
  1495. // events handler returns false
  1496. if ( !jQuery.event.special[type] || jQuery.event.special[type].setup.call(elem) === false ) {
  1497. // Bind the global event handler to the element
  1498. if (elem.addEventListener)
  1499. elem.addEventListener(type, handle, false);
  1500. else if (elem.attachEvent)
  1501. elem.attachEvent("on" + type, handle);
  1502. }
  1503. }
  1504. // Add the function to the element's handler list
  1505. handlers[handler.guid] = handler;
  1506. // Keep track of which events have been used, for global triggering
  1507. jQuery.event.global[type] = true;
  1508. });
  1509. // Nullify elem to prevent memory leaks in IE
  1510. elem = null;
  1511. },
  1512. guid: 1,
  1513. global: {},
  1514. // Detach an event or set of events from an element
  1515. remove: function(elem, types, handler) {
  1516. // don't do events on text and comment nodes
  1517. if ( elem.nodeType == 3 || elem.nodeType == 8 )
  1518. return;
  1519. var events = jQuery.data(elem, "events"), ret, index;
  1520. if ( events ) {
  1521. // Unbind all events for the element
  1522. if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
  1523. for ( var type in events )
  1524. this.remove( elem, type + (types || "") );
  1525. else {
  1526. // types is actually an event object here
  1527. if ( types.type ) {
  1528. handler = types.handler;
  1529. types = types.type;
  1530. }
  1531. // Handle multiple events seperated by a space
  1532. // jQuery(...).unbind("mouseover mouseout", fn);
  1533. jQuery.each(types.split(/\s+/), function(index, type){
  1534. // Namespaced event handlers
  1535. var parts = type.split(".");
  1536. type = parts[0];
  1537. if ( events[type] ) {
  1538. // remove the given handler for the given type
  1539. if ( handler )
  1540. delete events[type][handler.guid];
  1541. // remove all handlers for the given type
  1542. else
  1543. for ( handler in events[type] )
  1544. // Handle the removal of namespaced events
  1545. if ( !parts[1] || events[type][handler].type == parts[1] )
  1546. delete events[type][handler];
  1547. // remove generic event handler if no more handlers exist
  1548. for ( ret in events[type] ) break;
  1549. if ( !ret ) {
  1550. if ( !jQuery.event.special[type] || jQuery.event.special[type].teardown.call(elem) === false ) {
  1551. if (elem.removeEventListener)
  1552. elem.removeEventListener(type, jQuery.data(elem, "handle"), false);
  1553. else if (elem.detachEvent)
  1554. elem.detachEvent("on" + type, jQuery.data(elem, "handle"));
  1555. }
  1556. ret = null;
  1557. delete events[type];
  1558. }
  1559. }
  1560. });
  1561. }
  1562. // Remove the expando if it's no longer used
  1563. for ( ret in events ) break;
  1564. if ( !ret ) {
  1565. var handle = jQuery.data( elem, "handle" );
  1566. if ( handle ) handle.elem = null;
  1567. jQuery.removeData( elem, "events" );
  1568. jQuery.removeData( elem, "handle" );
  1569. }
  1570. }
  1571. },
  1572. trigger: function(type, data, elem, donative, extra) {
  1573. // Clone the incoming data, if any
  1574. data = jQuery.makeArray(data || []);
  1575. if ( type.indexOf("!") >= 0 ) {
  1576. type = type.slice(0, -1);
  1577. var exclusive = true;
  1578. }
  1579. // Handle a global trigger
  1580. if ( !elem ) {
  1581. // Only trigger if we've ever bound an event for it
  1582. if ( this.global[type] )
  1583. jQuery("*").add([window, document]).trigger(type, data);
  1584. // Handle triggering a single element
  1585. } else {
  1586. // don't do events on text and comment nodes
  1587. if ( elem.nodeType == 3 || elem.nodeType == 8 )
  1588. return undefined;
  1589. var val, ret, fn = jQuery.isFunction( elem[ type ] || null ),
  1590. // Check to see if we need to provide a fake event, or not
  1591. event = !data[0] || !data[0].preventDefault;
  1592. // Pass along a fake event
  1593. if ( event )
  1594. data.unshift( this.fix({ type: type, target: elem }) );
  1595. // Enforce the right trigger type
  1596. data[0].type = type;
  1597. if ( exclusive )
  1598. data[0].exclusive = true;
  1599. // Trigger the event
  1600. if ( jQuery.isFunction( jQuery.data(elem, "handle") ) )
  1601. val = jQuery.data(elem, "handle").apply( elem, data );
  1602. // Handle triggering native .onfoo handlers
  1603. if ( !fn && elem["on"+type] && elem["on"+type].apply( elem, data ) === false )
  1604. val = false;
  1605. // Extra functions don't get the custom event object
  1606. if ( event )
  1607. data.shift();
  1608. // Handle triggering of extra function
  1609. if ( extra && jQuery.isFunction( extra ) ) {
  1610. // call the extra function and tack the current return value on the end for possible inspection
  1611. ret = extra.apply( elem, val == null ? data : data.concat( val ) );
  1612. // if anything is returned, give it precedence and have it overwrite the previous value
  1613. if (ret !== undefined)
  1614. val = ret;
  1615. }
  1616. // Trigger the native events (except for clicks on links)
  1617. if ( fn && donative !== false && val !== false && !(jQuery.nodeName(elem, 'a') && type == "click") ) {
  1618. this.triggered = true;
  1619. try {
  1620. elem[ type ]();
  1621. // prevent IE from throwing an error for some hidden elements
  1622. } catch (e) {}
  1623. }
  1624. this.triggered = false;
  1625. }
  1626. return val;
  1627. },
  1628. handle: function(event) {
  1629. // returned undefined or false
  1630. var val;
  1631. // Empty object is for triggered events with no data
  1632. event = jQuery.event.fix( event || window.event || {} );
  1633. // Namespaced event handlers
  1634. var parts = event.type.split(".");
  1635. event.type = parts[0];
  1636. var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );
  1637. args.unshift( event );
  1638. for ( var j in handlers ) {
  1639. var handler = handlers[j];
  1640. // Pass in a reference to the handler function itself
  1641. // So that we can later remove it
  1642. args[0].handler = handler;
  1643. args[0].data = handler.data;
  1644. // Filter the functions by class
  1645. if ( !parts[1] && !event.exclusive || handler.type == parts[1] ) {
  1646. var ret = handler.apply( this, args );
  1647. if ( val !== false )
  1648. val = ret;
  1649. if ( ret === false ) {
  1650. event.preventDefault();
  1651. event.stopPropagation();
  1652. }
  1653. }
  1654. }
  1655. // Clean up added properties in IE to prevent memory leak
  1656. if (jQuery.browser.msie)
  1657. event.target = event.preventDefault = event.stopPropagation =
  1658. event.handler = event.data = null;
  1659. return val;
  1660. },
  1661. fix: function(event) {
  1662. // store a copy of the original event object
  1663. // and clone to set read-only properties
  1664. var originalEvent = event;
  1665. event = jQuery.extend({}, originalEvent);
  1666. // add preventDefault and stopPropagation since
  1667. // they will not work on the clone
  1668. event.preventDefault = function() {
  1669. // if preventDefault exists run it on the original event
  1670. if (originalEvent.preventDefault)
  1671. originalEvent.preventDefault();
  1672. // otherwise set the returnValue property of the original event to false (IE)
  1673. originalEvent.returnValue = false;
  1674. };
  1675. event.stopPropagation = function() {
  1676. // if stopPropagation exists run it on the original event
  1677. if (originalEvent.stopPropagation)
  1678. originalEvent.stopPropagation();
  1679. // otherwise set the cancelBubble property of the original event to true (IE)
  1680. originalEvent.cancelBubble = true;
  1681. };
  1682. // Fix target property, if necessary
  1683. if ( !event.target )
  1684. event.target = event.srcElement || document; // Fixes #1925 where srcElement might not be defined either
  1685. // check if target is a textnode (safari)
  1686. if ( event.target.nodeType == 3 )
  1687. event.target = originalEvent.target.parentNode;
  1688. // Add relatedTarget, if necessary
  1689. if ( !event.relatedTarget && event.fromElement )
  1690. event.relatedTarget = event.fromElement == event.target ? event.toElement : event.fromElement;
  1691. // Calculate pageX/Y if missing and clientX/Y available
  1692. if ( event.pageX == null && event.clientX != null ) {
  1693. var doc = document.documentElement, body = document.body;
  1694. event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0);
  1695. event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0);
  1696. }
  1697. // Add which for key events
  1698. if ( !event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode) )
  1699. event.which = event.charCode || event.keyCode;
  1700. // Add metaKey to non-Mac browsers (use ctrl for PC's and Meta for Macs)
  1701. if ( !event.metaKey && event.ctrlKey )
  1702. event.metaKey = event.ctrlKey;
  1703. // Add which for click: 1 == left; 2 == middle; 3 == right
  1704. // Note: button is not normalized, so don't use it
  1705. if ( !event.which && event.button )
  1706. event.which = (event.button & 1 ? 1 : ( event.button & 2 ? 3 : ( event.button & 4 ? 2 : 0 ) ));
  1707. return event;
  1708. },
  1709. special: {
  1710. ready: {
  1711. setup: function() {
  1712. // Make sure the ready event is setup
  1713. bindReady();
  1714. return;
  1715. },
  1716. teardown: function() { return; }
  1717. },
  1718. mouseenter: {
  1719. setup: function() {
  1720. if ( jQuery.browser.msie ) return false;
  1721. jQuery(this).bind("mouseover", jQuery.event.special.mouseenter.handler);
  1722. return true;
  1723. },
  1724. teardown: function() {
  1725. if ( jQuery.browser.msie ) return false;
  1726. jQuery(this).unbind("mouseover", jQuery.event.special.mouseenter.handler);
  1727. return true;
  1728. },
  1729. handler: function(event) {
  1730. // If we actually just moused on to a sub-element, ignore it
  1731. if ( withinElement(event, this) ) return true;
  1732. // Execute the right handlers by setting the event type to mouseenter
  1733. arguments[0].type = "mouseenter";
  1734. return jQuery.event.handle.apply(this, arguments);
  1735. }
  1736. },
  1737. mouseleave: {
  1738. setup: function() {
  1739. if ( jQuery.browser.msie ) return false;
  1740. jQuery(this).bind("mouseout", jQuery.event.special.mouseleave.handler);
  1741. return true;
  1742. },
  1743. teardown: function() {
  1744. if ( jQuery.browser.msie ) return false;
  1745. jQuery(this).unbind("mouseout", jQuery.event.special.mouseleave.handler);
  1746. return true;
  1747. },
  1748. handler: function(event) {
  1749. // If we actually just moused on to a sub-element, ignore it
  1750. if ( withinElement(event, this) ) return true;
  1751. // Execute the right handlers by setting the event type to mouseleave
  1752. arguments[0].type = "mouseleave";
  1753. return jQuery.event.handle.apply(this, arguments);
  1754. }
  1755. }
  1756. }
  1757. };
  1758. jQuery.fn.extend({
  1759. bind: function( type, data, fn ) {
  1760. return type == "unload" ? this.one(type, data, fn) : this.each(function(){
  1761. jQuery.event.add( this, type, fn || data, fn && data );
  1762. });
  1763. },
  1764. one: function( type, data, fn ) {
  1765. return this.each(function(){
  1766. jQuery.event.add( this, type, function(event) {
  1767. jQuery(this).unbind(event);
  1768. return (fn || data).apply( this, arguments);
  1769. }, fn && data);
  1770. });
  1771. },
  1772. unbind: function( type, fn ) {
  1773. return this.each(function(){
  1774. jQuery.event.remove( this, type, fn );
  1775. });
  1776. },
  1777. trigger: function( type, data, fn ) {
  1778. return this.each(function(){
  1779. jQuery.event.trigger( type, data, this, true, fn );
  1780. });
  1781. },
  1782. triggerHandler: function( type, data, fn ) {
  1783. if ( this[0] )
  1784. return jQuery.event.trigger( type, data, this[0], false, fn );
  1785. return undefined;
  1786. },
  1787. toggle: function() {
  1788. // Save reference to arguments for access in closure
  1789. var args = arguments;
  1790. return this.click(function(event) {
  1791. // Figure out which function to execute
  1792. this.lastToggle = 0 == this.lastToggle ? 1 : 0;
  1793. // Make sure that clicks stop
  1794. event.preventDefault();
  1795. // and execute the function
  1796. return args[this.lastToggle].apply( this, arguments ) || false;
  1797. });
  1798. },
  1799. hover: function(fnOver, fnOut) {
  1800. return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
  1801. },
  1802. ready: function(fn) {
  1803. // Attach the listeners
  1804. bindReady();
  1805. // If the DOM is already ready
  1806. if ( jQuery.isReady )
  1807. // Execute the function immediately
  1808. fn.call( document, jQuery );
  1809. // Otherwise, remember the function for later
  1810. else
  1811. // Add the function to the wait list
  1812. jQuery.readyList.push( function() { return fn.call(this, jQuery); } );
  1813. return this;
  1814. }
  1815. });
  1816. jQuery.extend({
  1817. isReady: false,
  1818. readyList: [],
  1819. // Handle when the DOM is ready
  1820. ready: function() {
  1821. // Make sure that the DOM is not already loaded
  1822. if ( !jQuery.isReady ) {
  1823. // Remember that the DOM is ready
  1824. jQuery.isReady = true;
  1825. // If there are functions bound, to execute
  1826. if ( jQuery.readyList ) {
  1827. // Execute all of them
  1828. jQuery.each( jQuery.readyList, function(){
  1829. this.apply( document );
  1830. });
  1831. // Reset the list of functions
  1832. jQuery.readyList = null;
  1833. }
  1834. // Trigger any bound ready events
  1835. jQuery(document).triggerHandler("ready");
  1836. }
  1837. }
  1838. });
  1839. var readyBound = false;
  1840. function bindReady(){
  1841. if ( readyBound ) return;
  1842. readyBound = true;
  1843. // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
  1844. if ( document.addEventListener && !jQuery.browser.opera)
  1845. // Use the handy event callback
  1846. document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
  1847. // If IE is used and is not in a frame
  1848. // Continually check to see if the document is ready
  1849. if ( jQuery.browser.msie && window == top ) (function(){
  1850. if (jQuery.isReady) return;
  1851. try {
  1852. // If IE is used, use the trick by Diego Perini
  1853. // http://javascript.nwbox.com/IEContentLoaded/
  1854. document.documentElement.doScroll("left");
  1855. } catch( error ) {
  1856. setTimeout( arguments.callee, 0 );
  1857. return;
  1858. }
  1859. // and execute any waiting functions
  1860. jQuery.ready();
  1861. })();
  1862. if ( jQuery.browser.opera )
  1863. document.addEventListener( "DOMContentLoaded", function () {
  1864. if (jQuery.isReady) return;
  1865. for (var i = 0; i < document.styleSheets.length; i++)
  1866. if (document.styleSheets[i].disabled) {
  1867. setTimeout( arguments.callee, 0 );
  1868. return;
  1869. }
  1870. // and execute any waiting functions
  1871. jQuery.ready();
  1872. }, false);
  1873. if ( jQuery.browser.safari ) {
  1874. var numStyles;
  1875. (function(){
  1876. if (jQuery.isReady) return;
  1877. if ( document.readyState != "loaded" && document.readyState != "complete" ) {
  1878. setTimeout( arguments.callee, 0 );
  1879. return;
  1880. }
  1881. if ( numStyles === undefined )
  1882. numStyles = jQuery("style, link[rel=stylesheet]").length;
  1883. if ( document.styleSheets.length != numStyles ) {
  1884. setTimeout( arguments.callee, 0 );
  1885. return;
  1886. }
  1887. // and execute any waiting functions
  1888. jQuery.ready();
  1889. })();
  1890. }
  1891. // A fallback to window.onload, that will always work
  1892. jQuery.event.add( window, "load", jQuery.ready );
  1893. }
  1894. jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
  1895. "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
  1896. "submit,keydown,keypress,keyup,error").split(","), function(i, name){
  1897. // Handle event binding
  1898. jQuery.fn[name] = function(fn){
  1899. return fn ? this.bind(name, fn) : this.trigger(name);
  1900. };
  1901. });
  1902. // Checks if an event happened on an element within another element
  1903. // Used in jQuery.event.special.mouseenter and mouseleave handlers
  1904. var withinElement = function(event, elem) {
  1905. // Check if mouse(over|out) are still within the same parent element
  1906. var parent = event.relatedTarget;
  1907. // Traverse up the tree
  1908. while ( parent && parent != elem ) try { parent = parent.parentNode; } catch(error) { parent = elem; }
  1909. // Return true if we actually just moused on to a sub-element
  1910. return parent == elem;
  1911. };
  1912. // Prevent memory leaks in IE
  1913. // And prevent errors on refresh with events like mouseover in other browsers
  1914. // Window isn't included so as not to unbind existing unload events
  1915. jQuery(window).bind("unload", function() {
  1916. jQuery("*").add(document).unbind();
  1917. });
  1918. jQuery.fn.extend({
  1919. load: function( url, params, callback ) {
  1920. if ( jQuery.isFunction( url ) )
  1921. return this.bind("load", url);
  1922. var off = url.indexOf(" ");
  1923. if ( off >= 0 ) {
  1924. var selector = url.slice(off, url.length);
  1925. url = url.slice(0, off);
  1926. }
  1927. callback = callback || function(){};
  1928. // Default to a GET request
  1929. var type = "GET";
  1930. // If the second parameter was provided
  1931. if ( params )
  1932. // If it's a function
  1933. if ( jQuery.isFunction( params ) ) {
  1934. // We assume that it's the callback
  1935. callback = params;
  1936. params = null;
  1937. // Otherwise, build a param string
  1938. } else {
  1939. params = jQuery.param( params );
  1940. type = "POST";
  1941. }
  1942. var self = this;
  1943. // Request the remote document
  1944. jQuery.ajax({
  1945. url: url,
  1946. type: type,
  1947. dataType: "html",
  1948. data: params,
  1949. complete: function(res, status){
  1950. // If successful, inject the HTML into all the matched elements
  1951. if ( status == "success" || status == "notmodified" )
  1952. // See if a selector was specified
  1953. self.html( selector ?
  1954. // Create a dummy div to hold the results
  1955. jQuery("<div/>")
  1956. // inject the contents of the document in, removing the scripts
  1957. // to avoid any 'Permission Denied' errors in IE
  1958. .append(res.responseText.replace(/<script(.|\s)*?\/script>/g, ""))
  1959. // Locate the specified elements
  1960. .find(selector) :
  1961. // If not, just inject the full result
  1962. res.responseText );
  1963. self.each( callback, [res.responseText, status, res] );
  1964. }
  1965. });
  1966. return this;
  1967. },
  1968. serialize: function() {
  1969. return jQuery.param(this.serializeArray());
  1970. },
  1971. serializeArray: function() {
  1972. return this.map(function(){
  1973. return jQuery.nodeName(this, "form") ?
  1974. jQuery.makeArray(this.elements) : this;
  1975. })
  1976. .filter(function(){
  1977. return this.name && !this.disabled &&
  1978. (this.checked || /select|textarea/i.test(this.nodeName) ||
  1979. /text|hidden|password/i.test(this.type));
  1980. })
  1981. .map(function(i, elem){
  1982. var val = jQuery(this).val();
  1983. return val == null ? null :
  1984. val.constructor == Array ?
  1985. jQuery.map( val, function(val, i){
  1986. return {name: elem.name, value: val};
  1987. }) :
  1988. {name: elem.name, value: val};
  1989. }).get();
  1990. }
  1991. });
  1992. // Attach a bunch of functions for handling common AJAX events
  1993. jQuery.each( "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","), function(i,o){
  1994. jQuery.fn[o] = function(f){
  1995. return this.bind(o, f);
  1996. };
  1997. });
  1998. var jsc = (new Date).getTime();
  1999. jQuery.extend({
  2000. get: function( url, data, callback, type ) {
  2001. // shift arguments if data argument was ommited
  2002. if ( jQuery.isFunction( data ) ) {
  2003. callback = data;
  2004. data = null;
  2005. }
  2006. return jQuery.ajax({
  2007. type: "GET",
  2008. url: url,
  2009. data: data,
  2010. success: callback,
  2011. dataType: type
  2012. });
  2013. },
  2014. getScript: function( url, callback ) {
  2015. return jQuery.get(url, null, callback, "script");
  2016. },
  2017. getJSON: function( url, data, callback ) {
  2018. return jQuery.get(url, data, callback, "json");
  2019. },
  2020. post: function( url, data, callback, type ) {
  2021. if ( jQuery.isFunction( data ) ) {
  2022. callback = data;
  2023. data = {};
  2024. }
  2025. return jQuery.ajax({
  2026. type: "POST",
  2027. url: url,
  2028. data: data,
  2029. success: callback,
  2030. dataType: type
  2031. });
  2032. },
  2033. ajaxSetup: function( settings ) {
  2034. jQuery.extend( jQuery.ajaxSettings, settings );
  2035. },
  2036. ajaxSettings: {
  2037. global: true,
  2038. type: "GET",
  2039. timeout: 0,
  2040. contentType: "application/x-www-form-urlencoded",
  2041. processData: true,
  2042. async: true,
  2043. data: null,
  2044. username: null,
  2045. password: null,
  2046. accepts: {
  2047. xml: "application/xml, text/xml",
  2048. html: "text/html",
  2049. script: "text/javascript, application/javascript",
  2050. json: "application/json, text/javascript",
  2051. text: "text/plain",
  2052. _default: "*/*"
  2053. }
  2054. },
  2055. // Last-Modified header cache for next request
  2056. lastModified: {},
  2057. ajax: function( s ) {
  2058. var jsonp, jsre = /=\?(&|$)/g, status, data;
  2059. // Extend the settings, but re-extend 's' so that it can be
  2060. // checked again later (in the test suite, specifically)
  2061. s = jQuery.extend(true, s, jQuery.extend(true, {}, jQuery.ajaxSettings, s));
  2062. // convert data if not already a string
  2063. if ( s.data && s.processData && typeof s.data != "string" )
  2064. s.data = jQuery.param(s.data);
  2065. // Handle JSONP Parameter Callbacks
  2066. if ( s.dataType == "jsonp" ) {
  2067. if ( s.type.toLowerCase() == "get" ) {
  2068. if ( !s.url.match(jsre) )
  2069. s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?";
  2070. } else if ( !s.data || !s.data.match(jsre) )
  2071. s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?";
  2072. s.dataType = "json";
  2073. }
  2074. // Build temporary JSONP function
  2075. if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) {
  2076. jsonp = "jsonp" + jsc++;
  2077. // Replace the =? sequence both in the query string and the data
  2078. if ( s.data )
  2079. s.data = (s.data + "").replace(jsre, "=" + jsonp + "$1");
  2080. s.url = s.url.replace(jsre, "=" + jsonp + "$1");
  2081. // We need to make sure
  2082. // that a JSONP style response is executed properly
  2083. s.dataType = "script";
  2084. // Handle JSONP-style loading
  2085. window[ jsonp ] = function(tmp){
  2086. data = tmp;
  2087. success();
  2088. complete();
  2089. // Garbage collect
  2090. window[ jsonp ] = undefined;
  2091. try{ delete window[ jsonp ]; } catch(e){}
  2092. if ( head )
  2093. head.removeChild( script );
  2094. };
  2095. }
  2096. if ( s.dataType == "script" && s.cache == null )
  2097. s.cache = false;
  2098. if ( s.cache === false && s.type.toLowerCase() == "get" ) {
  2099. var ts = (new Date()).getTime();
  2100. // try replacing _= if it is there
  2101. var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
  2102. // if nothing was replaced, add timestamp to the end
  2103. s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : "");
  2104. }
  2105. // If data is available, append data to url for get requests
  2106. if ( s.data && s.type.toLowerCase() == "get" ) {
  2107. s.url += (s.url.match(/\?/) ? "&" : "?") + s.data;
  2108. // IE likes to send both get and post data, prevent this
  2109. s.data = null;
  2110. }
  2111. // Watch for a new set of requests
  2112. if ( s.global && ! jQuery.active++ )
  2113. jQuery.event.trigger( "ajaxStart" );
  2114. // If we're requesting a remote document
  2115. // and trying to load JSON or Script with a GET
  2116. if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && s.dataType == "script" && s.type.toLowerCase() == "get" ) {
  2117. var head = document.getElementsByTagName("head")[0];
  2118. var script = document.createElement("script");
  2119. script.src = s.url;
  2120. if (s.scriptCharset)
  2121. script.charset = s.scriptCharset;
  2122. // Handle Script loading
  2123. if ( !jsonp ) {
  2124. var done = false;
  2125. // Attach handlers for all browsers
  2126. script.onload = script.onreadystatechange = function(){
  2127. if ( !done && (!this.readyState ||
  2128. this.readyState == "loaded" || this.readyState == "complete") ) {
  2129. done = true;
  2130. success();
  2131. complete();
  2132. head.removeChild( script );
  2133. }
  2134. };
  2135. }
  2136. head.appendChild(script);
  2137. // We handle everything using the script element injection
  2138. return undefined;
  2139. }
  2140. var requestDone = false;
  2141. // Create the request object; Microsoft failed to properly
  2142. // implement the XMLHttpRequest in IE7, so we use the ActiveXObject when it is available
  2143. var xml = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  2144. // Open the socket
  2145. xml.open(s.type, s.url, s.async, s.username, s.password);
  2146. // Need an extra try/catch for cross domain requests in Firefox 3
  2147. try {
  2148. // Set the correct header, if data is being sent
  2149. if ( s.data )
  2150. xml.setRequestHeader("Content-Type", s.contentType);
  2151. // Set the If-Modified-Since header, if ifModified mode.
  2152. if ( s.ifModified )
  2153. xml.setRequestHeader("If-Modified-Since",
  2154. jQuery.lastModified[s.url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
  2155. // Set header so the called script knows that it's an XMLHttpRequest
  2156. xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  2157. // Set the Accepts header for the server, depending on the dataType
  2158. xml.setRequestHeader("Accept", s.dataType && s.accepts[ s.dataType ] ?
  2159. s.accepts[ s.dataType ] + ", */*" :
  2160. s.accepts._default );
  2161. } catch(e){}
  2162. // Allow custom headers/mimetypes
  2163. if ( s.beforeSend )
  2164. s.beforeSend(xml);
  2165. if ( s.global )
  2166. jQuery.event.trigger("ajaxSend", [xml, s]);
  2167. // Wait for a response to come back
  2168. var onreadystatechange = function(isTimeout){
  2169. // The transfer is complete and the data is available, or the request timed out
  2170. if ( !requestDone && xml && (xml.readyState == 4 || isTimeout == "timeout") ) {
  2171. requestDone = true;
  2172. // clear poll interval
  2173. if (ival) {
  2174. clearInterval(ival);
  2175. ival = null;
  2176. }
  2177. status = isTimeout == "timeout" && "timeout" ||
  2178. !jQuery.httpSuccess( xml ) && "error" ||
  2179. s.ifModified && jQuery.httpNotModified( xml, s.url ) && "notmodified" ||
  2180. "success";
  2181. if ( status == "success" ) {
  2182. // Watch for, and catch, XML document parse errors
  2183. try {
  2184. // process the data (runs the xml through httpData regardless of callback)
  2185. data = jQuery.httpData( xml, s.dataType );
  2186. } catch(e) {
  2187. status = "parsererror";
  2188. }
  2189. }
  2190. // Make sure that the request was successful or notmodified
  2191. if ( status == "success" ) {
  2192. // Cache Last-Modified header, if ifModified mode.
  2193. var modRes;
  2194. try {
  2195. modRes = xml.getResponseHeader("Last-Modified");
  2196. } catch(e) {} // swallow exception thrown by FF if header is not available
  2197. if ( s.ifModified && modRes )
  2198. jQuery.lastModified[s.url] = modRes;
  2199. // JSONP handles its own success callback
  2200. if ( !jsonp )
  2201. success();
  2202. } else
  2203. jQuery.handleError(s, xml, status);
  2204. // Fire the complete handlers
  2205. complete();
  2206. // Stop memory leaks
  2207. if ( s.async )
  2208. xml = null;
  2209. }
  2210. };
  2211. if ( s.async ) {
  2212. // don't attach the handler to the request, just poll it instead
  2213. var ival = setInterval(onreadystatechange, 13);
  2214. // Timeout checker
  2215. if ( s.timeout > 0 )
  2216. setTimeout(function(){
  2217. // Check to see if the request is still happening
  2218. if ( xml ) {
  2219. // Cancel the request
  2220. xml.abort();
  2221. if( !requestDone )
  2222. onreadystatechange( "timeout" );
  2223. }
  2224. }, s.timeout);
  2225. }
  2226. // Send the data
  2227. try {
  2228. xml.send(s.data);
  2229. } catch(e) {
  2230. jQuery.handleError(s, xml, null, e);
  2231. }
  2232. // firefox 1.5 doesn't fire statechange for sync requests
  2233. if ( !s.async )
  2234. onreadystatechange();
  2235. function success(){
  2236. // If a local callback was specified, fire it and pass it the data
  2237. if ( s.success )
  2238. s.success( data, status );
  2239. // Fire the global callback
  2240. if ( s.global )
  2241. jQuery.event.trigger( "ajaxSuccess", [xml, s] );
  2242. }
  2243. function complete(){
  2244. // Process result
  2245. if ( s.complete )
  2246. s.complete(xml, status);
  2247. // The request was completed
  2248. if ( s.global )
  2249. jQuery.event.trigger( "ajaxComplete", [xml, s] );
  2250. // Handle the global AJAX counter
  2251. if ( s.global && ! --jQuery.active )
  2252. jQuery.event.trigger( "ajaxStop" );
  2253. }
  2254. // return XMLHttpRequest to allow aborting the request etc.
  2255. return xml;
  2256. },
  2257. handleError: function( s, xml, status, e ) {
  2258. // If a local callback was specified, fire it
  2259. if ( s.error ) s.error( xml, status, e );
  2260. // Fire the global callback
  2261. if ( s.global )
  2262. jQuery.event.trigger( "ajaxError", [xml, s, e] );
  2263. },
  2264. // Counter for holding the number of active queries
  2265. active: 0,
  2266. // Determines if an XMLHttpRequest was successful or not
  2267. httpSuccess: function( r ) {
  2268. try {
  2269. // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
  2270. return !r.status && location.protocol == "file:" ||
  2271. ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 ||
  2272. jQuery.browser.safari && r.status == undefined;
  2273. } catch(e){}
  2274. return false;
  2275. },
  2276. // Determines if an XMLHttpRequest returns NotModified
  2277. httpNotModified: function( xml, url ) {
  2278. try {
  2279. var xmlRes = xml.getResponseHeader("Last-Modified");
  2280. // Firefox always returns 200. check Last-Modified date
  2281. return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
  2282. jQuery.browser.safari && xml.status == undefined;
  2283. } catch(e){}
  2284. return false;
  2285. },
  2286. httpData: function( r, type ) {
  2287. var ct = r.getResponseHeader("content-type");
  2288. var xml = type == "xml" || !type && ct && ct.indexOf("xml") >= 0;
  2289. var data = xml ? r.responseXML : r.responseText;
  2290. if ( xml && data.documentElement.tagName == "parsererror" )
  2291. throw "parsererror";
  2292. // If the type is "script", eval it in global context
  2293. if ( type == "script" )
  2294. jQuery.globalEval( data );
  2295. // Get the JavaScript object, if JSON is used.
  2296. if ( type == "json" )
  2297. data = eval("(" + data + ")");
  2298. return data;
  2299. },
  2300. // Serialize an array of form elements or a set of
  2301. // key/values into a query string
  2302. param: function( a ) {
  2303. var s = [];
  2304. // If an array was passed in, assume that it is an array
  2305. // of form elements
  2306. if ( a.constructor == Array || a.jquery )
  2307. // Serialize the form elements
  2308. jQuery.each( a, function(){
  2309. s.push( encodeURIComponent(this.name) + "=" + encodeURIComponent( this.value ) );
  2310. });
  2311. // Otherwise, assume that it's an object of key/value pairs
  2312. else
  2313. // Serialize the key/values
  2314. for ( var j in a )
  2315. // If the value is an array then the key names need to be repeated
  2316. if ( a[j] && a[j].constructor == Array )
  2317. jQuery.each( a[j], function(){
  2318. s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
  2319. });
  2320. else
  2321. s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
  2322. // Return the resulting serialization
  2323. return s.join("&").replace(/%20/g, "+");
  2324. }
  2325. });
  2326. jQuery.fn.extend({
  2327. show: function(speed,callback){
  2328. return speed ?
  2329. this.animate({
  2330. height: "show", width: "show", opacity: "show"
  2331. }, speed, callback) :
  2332. this.filter(":hidden").each(function(){
  2333. this.style.display = this.oldblock || "";
  2334. if ( jQuery.css(this,"display") == "none" ) {
  2335. var elem = jQuery("<" + this.tagName + " />").appendTo("body");
  2336. this.style.display = elem.css("display");
  2337. // handle an edge condition where css is - div { display:none; } or similar
  2338. if (this.style.display == "none")
  2339. this.style.display = "block";
  2340. elem.remove();
  2341. }
  2342. }).end();
  2343. },
  2344. hide: function(speed,callback){
  2345. return speed ?
  2346. this.animate({
  2347. height: "hide", width: "hide", opacity: "hide"
  2348. }, speed, callback) :
  2349. this.filter(":visible").each(function(){
  2350. this.oldblock = this.oldblock || jQuery.css(this,"display");
  2351. this.style.display = "none";
  2352. }).end();
  2353. },
  2354. // Save the old toggle function
  2355. _toggle: jQuery.fn.toggle,
  2356. toggle: function( fn, fn2 ){
  2357. return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
  2358. this._toggle( fn, fn2 ) :
  2359. fn ?
  2360. this.animate({
  2361. height: "toggle", width: "toggle", opacity: "toggle"
  2362. }, fn, fn2) :
  2363. this.each(function(){
  2364. jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
  2365. });
  2366. },
  2367. slideDown: function(speed,callback){
  2368. return this.animate({height: "show"}, speed, callback);
  2369. },
  2370. slideUp: function(speed,callback){
  2371. return this.animate({height: "hide"}, speed, callback);
  2372. },
  2373. slideToggle: function(speed, callback){
  2374. return this.animate({height: "toggle"}, speed, callback);
  2375. },
  2376. fadeIn: function(speed, callback){
  2377. return this.animate({opacity: "show"}, speed, callback);
  2378. },
  2379. fadeOut: function(speed, callback){
  2380. return this.animate({opacity: "hide"}, speed, callback);
  2381. },
  2382. fadeTo: function(speed,to,callback){
  2383. return this.animate({opacity: to}, speed, callback);
  2384. },
  2385. animate: function( prop, speed, easing, callback ) {
  2386. var optall = jQuery.speed(speed, easing, callback);
  2387. return this[ optall.queue === false ? "each" : "queue" ](function(){
  2388. if ( this.nodeType != 1)
  2389. return false;
  2390. var opt = jQuery.extend({}, optall);
  2391. var hidden = jQuery(this).is(":hidden"), self = this;
  2392. for ( var p in prop ) {
  2393. if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
  2394. return jQuery.isFunction(opt.complete) && opt.complete.apply(this);
  2395. if ( p == "height" || p == "width" ) {
  2396. // Store display property
  2397. opt.display = jQuery.css(this, "display");
  2398. // Make sure that nothing sneaks out
  2399. opt.overflow = this.style.overflow;
  2400. }
  2401. }
  2402. if ( opt.overflow != null )
  2403. this.style.overflow = "hidden";
  2404. opt.curAnim = jQuery.extend({}, prop);
  2405. jQuery.each( prop, function(name, val){
  2406. var e = new jQuery.fx( self, opt, name );
  2407. if ( /toggle|show|hide/.test(val) )
  2408. e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
  2409. else {
  2410. var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
  2411. start = e.cur(true) || 0;
  2412. if ( parts ) {
  2413. var end = parseFloat(parts[2]),
  2414. unit = parts[3] || "px";
  2415. // We need to compute starting value
  2416. if ( unit != "px" ) {
  2417. self.style[ name ] = (end || 1) + unit;
  2418. start = ((end || 1) / e.cur(true)) * start;
  2419. self.style[ name ] = start + unit;
  2420. }
  2421. // If a +=/-= token was provided, we're doing a relative animation
  2422. if ( parts[1] )
  2423. end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
  2424. e.custom( start, end, unit );
  2425. } else
  2426. e.custom( start, val, "" );
  2427. }
  2428. });
  2429. // For JS strict compliance
  2430. return true;
  2431. });
  2432. },
  2433. queue: function(type, fn){
  2434. if ( jQuery.isFunction(type) || ( type && type.constructor == Array )) {
  2435. fn = type;
  2436. type = "fx";
  2437. }
  2438. if ( !type || (typeof type == "string" && !fn) )
  2439. return queue( this[0], type );
  2440. return this.each(function(){
  2441. if ( fn.constructor == Array )
  2442. queue(this, type, fn);
  2443. else {
  2444. queue(this, type).push( fn );
  2445. if ( queue(this, type).length == 1 )
  2446. fn.apply(this);
  2447. }
  2448. });
  2449. },
  2450. stop: function(clearQueue, gotoEnd){
  2451. var timers = jQuery.timers;
  2452. if (clearQueue)
  2453. this.queue([]);
  2454. this.each(function(){
  2455. // go in reverse order so anything added to the queue during the loop is ignored
  2456. for ( var i = timers.length - 1; i >= 0; i-- )
  2457. if ( timers[i].elem == this ) {
  2458. if (gotoEnd)
  2459. // force the next step to be the last
  2460. timers[i](true);
  2461. timers.splice(i, 1);
  2462. }
  2463. });
  2464. // start the next in the queue if the last step wasn't forced
  2465. if (!gotoEnd)
  2466. this.dequeue();
  2467. return this;
  2468. }
  2469. });
  2470. var queue = function( elem, type, array ) {
  2471. if ( !elem )
  2472. return undefined;
  2473. type = type || "fx";
  2474. var q = jQuery.data( elem, type + "queue" );
  2475. if ( !q || array )
  2476. q = jQuery.data( elem, type + "queue",
  2477. array ? jQuery.makeArray(array) : [] );
  2478. return q;
  2479. };
  2480. jQuery.fn.dequeue = function(type){
  2481. type = type || "fx";
  2482. return this.each(function(){
  2483. var q = queue(this, type);
  2484. q.shift();
  2485. if ( q.length )
  2486. q[0].apply( this );
  2487. });
  2488. };
  2489. jQuery.extend({
  2490. speed: function(speed, easing, fn) {
  2491. var opt = speed && speed.constructor == Object ? speed : {
  2492. complete: fn || !fn && easing ||
  2493. jQuery.isFunction( speed ) && speed,
  2494. duration: speed,
  2495. easing: fn && easing || easing && easing.constructor != Function && easing
  2496. };
  2497. opt.duration = (opt.duration && opt.duration.constructor == Number ?
  2498. opt.duration :
  2499. { slow: 600, fast: 200 }[opt.duration]) || 400;
  2500. // Queueing
  2501. opt.old = opt.complete;
  2502. opt.complete = function(){
  2503. if ( opt.queue !== false )
  2504. jQuery(this).dequeue();
  2505. if ( jQuery.isFunction( opt.old ) )
  2506. opt.old.apply( this );
  2507. };
  2508. return opt;
  2509. },
  2510. easing: {
  2511. linear: function( p, n, firstNum, diff ) {
  2512. return firstNum + diff * p;
  2513. },
  2514. swing: function( p, n, firstNum, diff ) {
  2515. return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
  2516. }
  2517. },
  2518. timers: [],
  2519. timerId: null,
  2520. fx: function( elem, options, prop ){
  2521. this.options = options;
  2522. this.elem = elem;
  2523. this.prop = prop;
  2524. if ( !options.orig )
  2525. options.orig = {};
  2526. }
  2527. });
  2528. jQuery.fx.prototype = {
  2529. // Simple function for setting a style value
  2530. update: function(){
  2531. if ( this.options.step )
  2532. this.options.step.apply( this.elem, [ this.now, this ] );
  2533. (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
  2534. // Set display property to block for height/width animations
  2535. if ( this.prop == "height" || this.prop == "width" )
  2536. this.elem.style.display = "block";
  2537. },
  2538. // Get the current size
  2539. cur: function(force){
  2540. if ( this.elem[this.prop] != null && this.elem.style[this.prop] == null )
  2541. return this.elem[ this.prop ];
  2542. var r = parseFloat(jQuery.css(this.elem, this.prop, force));
  2543. return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
  2544. },
  2545. // Start an animation from one number to another
  2546. custom: function(from, to, unit){
  2547. this.startTime = (new Date()).getTime();
  2548. this.start = from;
  2549. this.end = to;
  2550. this.unit = unit || this.unit || "px";
  2551. this.now = this.start;
  2552. this.pos = this.state = 0;
  2553. this.update();
  2554. var self = this;
  2555. function t(gotoEnd){
  2556. return self.step(gotoEnd);
  2557. }
  2558. t.elem = this.elem;
  2559. jQuery.timers.push(t);
  2560. if ( jQuery.timerId == null ) {
  2561. jQuery.timerId = setInterval(function(){
  2562. var timers = jQuery.timers;
  2563. for ( var i = 0; i < timers.length; i++ )
  2564. if ( !timers[i]() )
  2565. timers.splice(i--, 1);
  2566. if ( !timers.length ) {
  2567. clearInterval( jQuery.timerId );
  2568. jQuery.timerId = null;
  2569. }
  2570. }, 13);
  2571. }
  2572. },
  2573. // Simple 'show' function
  2574. show: function(){
  2575. // Remember where we started, so that we can go back to it later
  2576. this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
  2577. this.options.show = true;
  2578. // Begin the animation
  2579. this.custom(0, this.cur());
  2580. // Make sure that we start at a small width/height to avoid any
  2581. // flash of content
  2582. if ( this.prop == "width" || this.prop == "height" )
  2583. this.elem.style[this.prop] = "1px";
  2584. // Start by showing the element
  2585. jQuery(this.elem).show();
  2586. },
  2587. // Simple 'hide' function
  2588. hide: function(){
  2589. // Remember where we started, so that we can go back to it later
  2590. this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
  2591. this.options.hide = true;
  2592. // Begin the animation
  2593. this.custom(this.cur(), 0);
  2594. },
  2595. // Each step of an animation
  2596. step: function(gotoEnd){
  2597. var t = (new Date()).getTime();
  2598. if ( gotoEnd || t > this.options.duration + this.startTime ) {
  2599. this.now = this.end;
  2600. this.pos = this.state = 1;
  2601. this.update();
  2602. this.options.curAnim[ this.prop ] = true;
  2603. var done = true;
  2604. for ( var i in this.options.curAnim )
  2605. if ( this.options.curAnim[i] !== true )
  2606. done = false;
  2607. if ( done ) {
  2608. if ( this.options.display != null ) {
  2609. // Reset the overflow
  2610. this.elem.style.overflow = this.options.overflow;
  2611. // Reset the display
  2612. this.elem.style.display = this.options.display;
  2613. if ( jQuery.css(this.elem, "display") == "none" )
  2614. this.elem.style.display = "block";
  2615. }
  2616. // Hide the element if the "hide" operation was done
  2617. if ( this.options.hide )
  2618. this.elem.style.display = "none";
  2619. // Reset the properties, if the item has been hidden or shown
  2620. if ( this.options.hide || this.options.show )
  2621. for ( var p in this.options.curAnim )
  2622. jQuery.attr(this.elem.style, p, this.options.orig[p]);
  2623. }
  2624. // If a callback was provided, execute it
  2625. if ( done && jQuery.isFunction( this.options.complete ) )
  2626. // Execute the complete function
  2627. this.options.complete.apply( this.elem );
  2628. return false;
  2629. } else {
  2630. var n = t - this.startTime;
  2631. this.state = n / this.options.duration;
  2632. // Perform the easing function, defaults to swing
  2633. this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
  2634. this.now = this.start + ((this.end - this.start) * this.pos);
  2635. // Perform the next step of the animation
  2636. this.update();
  2637. }
  2638. return true;
  2639. }
  2640. };
  2641. jQuery.fx.step = {
  2642. scrollLeft: function(fx){
  2643. fx.elem.scrollLeft = fx.now;
  2644. },
  2645. scrollTop: function(fx){
  2646. fx.elem.scrollTop = fx.now;
  2647. },
  2648. opacity: function(fx){
  2649. jQuery.attr(fx.elem.style, "opacity", fx.now);
  2650. },
  2651. _default: function(fx){
  2652. fx.elem.style[ fx.prop ] = fx.now + fx.unit;
  2653. }
  2654. };
  2655. // The Offset Method
  2656. // Originally By Brandon Aaron, part of the Dimension Plugin
  2657. // http://jquery.com/plugins/project/dimensions
  2658. jQuery.fn.offset = function() {
  2659. var left = 0, top = 0, elem = this[0], results;
  2660. if ( elem ) with ( jQuery.browser ) {
  2661. var parent = elem.parentNode,
  2662. offsetChild = elem,
  2663. offsetParent = elem.offsetParent,
  2664. doc = elem.ownerDocument,
  2665. safari2 = safari && parseInt(version) < 522,
  2666. fixed = jQuery.css(elem, "position") == "fixed";
  2667. // Use getBoundingClientRect if available
  2668. if ( elem.getBoundingClientRect ) {
  2669. var box = elem.getBoundingClientRect();
  2670. // Add the document scroll offsets
  2671. add(box.left + Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
  2672. box.top + Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
  2673. // IE adds the HTML element's border, by default it is medium which is 2px
  2674. // IE 6 and 7 quirks mode the border width is overwritable by the following css html { border: 0; }
  2675. // IE 7 standards mode, the border is always 2px
  2676. // This border/offset is typically represented by the clientLeft and clientTop properties
  2677. // However, in IE6 and 7 quirks mode the clientLeft and clientTop properties are not updated when overwriting it via CSS
  2678. // Therefore this method will be off by 2px in IE while in quirksmode
  2679. add( -doc.documentElement.clientLeft, -doc.documentElement.clientTop );
  2680. // Otherwise loop through the offsetParents and parentNodes
  2681. } else {
  2682. // Initial element offsets
  2683. add( elem.offsetLeft, elem.offsetTop );
  2684. // Get parent offsets
  2685. while ( offsetParent ) {
  2686. // Add offsetParent offsets
  2687. add( offsetParent.offsetLeft, offsetParent.offsetTop );
  2688. // Mozilla and Safari > 2 does not include the border on offset parents
  2689. // However Mozilla adds the border for table or table cells
  2690. if ( mozilla && !/^t(able|d|h)$/i.test(offsetParent.tagName) || safari && !safari2 )
  2691. border( offsetParent );
  2692. // Add the document scroll offsets if position is fixed on any offsetParent
  2693. if ( !fixed && jQuery.css(offsetParent, "position") == "fixed" )
  2694. fixed = true;
  2695. // Set offsetChild to previous offsetParent unless it is the body element
  2696. offsetChild = /^body$/i.test(offsetParent.tagName) ? offsetChild : offsetParent;
  2697. // Get next offsetParent
  2698. offsetParent = offsetParent.offsetParent;
  2699. }
  2700. // Get parent scroll offsets
  2701. while ( parent && parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
  2702. // Remove parent scroll UNLESS that parent is inline or a table to work around Opera inline/table scrollLeft/Top bug
  2703. if ( !/^inline|table.*$/i.test(jQuery.css(parent, "display")) )
  2704. // Subtract parent scroll offsets
  2705. add( -parent.scrollLeft, -parent.scrollTop );
  2706. // Mozilla does not add the border for a parent that has overflow != visible
  2707. if ( mozilla && jQuery.css(parent, "overflow") != "visible" )
  2708. border( parent );
  2709. // Get next parent
  2710. parent = parent.parentNode;
  2711. }
  2712. // Safari <= 2 doubles body offsets with a fixed position element/offsetParent or absolutely positioned offsetChild
  2713. // Mozilla doubles body offsets with a non-absolutely positioned offsetChild
  2714. if ( (safari2 && (fixed || jQuery.css(offsetChild, "position") == "absolute")) ||
  2715. (mozilla && jQuery.css(offsetChild, "position") != "absolute") )
  2716. add( -doc.body.offsetLeft, -doc.body.offsetTop );
  2717. // Add the document scroll offsets if position is fixed
  2718. if ( fixed )
  2719. add(Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft),
  2720. Math.max(doc.documentElement.scrollTop, doc.body.scrollTop));
  2721. }
  2722. // Return an object with top and left properties
  2723. results = { top: top, left: left };
  2724. }
  2725. function border(elem) {
  2726. add( jQuery.curCSS(elem, "borderLeftWidth", true), jQuery.curCSS(elem, "borderTopWidth", true) );
  2727. }
  2728. function add(l, t) {
  2729. left += parseInt(l) || 0;
  2730. top += parseInt(t) || 0;
  2731. }
  2732. return results;
  2733. };
  2734. })();