PageRenderTime 2443ms CodeModel.GetById 62ms RepoModel.GetById 24ms app.codeStats 1ms

/Visual Studio 2008/CSASPNETAjaxScriptControl/Common/jquery-1.0.js

#
JavaScript | 1814 lines | 1194 code | 362 blank | 258 comment | 462 complexity | 4180536770c22bb414601b83cf8929fa MD5 | raw file
  1. /*
  2. * jQuery - New Wave Javascript
  3. *
  4. * Copyright (c) 2006 John Resig (jquery.com)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * $Date: 2006-10-27 23:14:48 -0400 (Fri, 27 Oct 2006) $
  9. * $Rev: 509 $
  10. */
  11. // Global undefined variable
  12. window.undefined = window.undefined;
  13. function jQuery(a,c) {
  14. // Shortcut for document ready (because $(document).each() is silly)
  15. if ( a && a.constructor == Function && jQuery.fn.ready )
  16. return jQuery(document).ready(a);
  17. // Make sure that a selection was provided
  18. a = a || jQuery.context || document;
  19. // Watch for when a jQuery object is passed as the selector
  20. if ( a.jquery )
  21. return $( jQuery.merge( a, [] ) );
  22. // Watch for when a jQuery object is passed at the context
  23. if ( c && c.jquery )
  24. return $( c ).find(a);
  25. // If the context is global, return a new object
  26. if ( window == this )
  27. return new jQuery(a,c);
  28. // Handle HTML strings
  29. var m = /^[^<]*(<.+>)[^>]*$/.exec(a);
  30. if ( m ) a = jQuery.clean( [ m[1] ] );
  31. // Watch for when an array is passed in
  32. this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
  33. // Assume that it is an array of DOM Elements
  34. jQuery.merge( a, [] ) :
  35. // Find the matching elements and save them for later
  36. jQuery.find( a, c ) );
  37. // See if an extra function was provided
  38. var fn = arguments[ arguments.length - 1 ];
  39. // If so, execute it in context
  40. if ( fn && fn.constructor == Function )
  41. this.each(fn);
  42. }
  43. // Map over the $ in case of overwrite
  44. if ( $ )
  45. jQuery._$ = $;
  46. // Map the jQuery namespace to the '$' one
  47. var $ = jQuery;
  48. jQuery.fn = jQuery.prototype = {
  49. jquery: "$Rev: 509 $",
  50. size: function() {
  51. return this.length;
  52. },
  53. get: function( num ) {
  54. // Watch for when an array (of elements) is passed in
  55. if ( num && num.constructor == Array ) {
  56. // Use a tricky hack to make the jQuery object
  57. // look and feel like an array
  58. this.length = 0;
  59. [].push.apply( this, num );
  60. return this;
  61. } else
  62. return num == undefined ?
  63. // Return a 'clean' array
  64. jQuery.map( this, function(a){ return a } ) :
  65. // Return just the object
  66. this[num];
  67. },
  68. each: function( fn, args ) {
  69. return jQuery.each( this, fn, args );
  70. },
  71. index: function( obj ) {
  72. var pos = -1;
  73. this.each(function(i){
  74. if ( this == obj ) pos = i;
  75. });
  76. return pos;
  77. },
  78. attr: function( key, value, type ) {
  79. // Check to see if we're setting style values
  80. return key.constructor != String || value != undefined ?
  81. this.each(function(){
  82. // See if we're setting a hash of styles
  83. if ( value == undefined )
  84. // Set all the styles
  85. for ( var prop in key )
  86. jQuery.attr(
  87. type ? this.style : this,
  88. prop, key[prop]
  89. );
  90. // See if we're setting a single key/value style
  91. else
  92. jQuery.attr(
  93. type ? this.style : this,
  94. key, value
  95. );
  96. }) :
  97. // Look for the case where we're accessing a style value
  98. jQuery[ type || "attr" ]( this[0], key );
  99. },
  100. css: function( key, value ) {
  101. return this.attr( key, value, "curCSS" );
  102. },
  103. text: function(e) {
  104. e = e || this;
  105. var t = "";
  106. for ( var j = 0; j < e.length; j++ ) {
  107. var r = e[j].childNodes;
  108. for ( var i = 0; i < r.length; i++ )
  109. t += r[i].nodeType != 1 ?
  110. r[i].nodeValue : jQuery.fn.text([ r[i] ]);
  111. }
  112. return t;
  113. },
  114. wrap: function() {
  115. // The elements to wrap the target around
  116. var a = jQuery.clean(arguments);
  117. // Wrap each of the matched elements individually
  118. return this.each(function(){
  119. // Clone the structure that we're using to wrap
  120. var b = a[0].cloneNode(true);
  121. // Insert it before the element to be wrapped
  122. this.parentNode.insertBefore( b, this );
  123. // Find he deepest point in the wrap structure
  124. while ( b.firstChild )
  125. b = b.firstChild;
  126. // Move the matched element to within the wrap structure
  127. b.appendChild( this );
  128. });
  129. },
  130. append: function() {
  131. return this.domManip(arguments, true, 1, function(a){
  132. this.appendChild( a );
  133. });
  134. },
  135. prepend: function() {
  136. return this.domManip(arguments, true, -1, function(a){
  137. this.insertBefore( a, this.firstChild );
  138. });
  139. },
  140. before: function() {
  141. return this.domManip(arguments, false, 1, function(a){
  142. this.parentNode.insertBefore( a, this );
  143. });
  144. },
  145. after: function() {
  146. return this.domManip(arguments, false, -1, function(a){
  147. this.parentNode.insertBefore( a, this.nextSibling );
  148. });
  149. },
  150. end: function() {
  151. return this.get( this.stack.pop() );
  152. },
  153. find: function(t) {
  154. return this.pushStack( jQuery.map( this, function(a){
  155. return jQuery.find(t,a);
  156. }), arguments );
  157. },
  158. clone: function(deep) {
  159. return this.pushStack( jQuery.map( this, function(a){
  160. return a.cloneNode( deep != undefined ? deep : true );
  161. }), arguments );
  162. },
  163. filter: function(t) {
  164. return this.pushStack(
  165. t.constructor == Array &&
  166. jQuery.map(this,function(a){
  167. for ( var i = 0; i < t.length; i++ )
  168. if ( jQuery.filter(t[i],[a]).r.length )
  169. return a;
  170. }) ||
  171. t.constructor == Boolean &&
  172. ( t ? this.get() : [] ) ||
  173. t.constructor == Function &&
  174. jQuery.grep( this, t ) ||
  175. jQuery.filter(t,this).r, arguments );
  176. },
  177. not: function(t) {
  178. return this.pushStack( t.constructor == String ?
  179. jQuery.filter(t,this,false).r :
  180. jQuery.grep(this,function(a){ return a != t; }), arguments );
  181. },
  182. add: function(t) {
  183. return this.pushStack( jQuery.merge( this, t.constructor == String ?
  184. jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
  185. },
  186. is: function(expr) {
  187. return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0;
  188. },
  189. domManip: function(args, table, dir, fn){
  190. var clone = this.size() > 1;
  191. var a = jQuery.clean(args);
  192. return this.each(function(){
  193. var obj = this;
  194. if ( table && this.nodeName == "TABLE" && a[0].nodeName != "THEAD" ) {
  195. var tbody = this.getElementsByTagName("tbody");
  196. if ( !tbody.length ) {
  197. obj = document.createElement("tbody");
  198. this.appendChild( obj );
  199. } else
  200. obj = tbody[0];
  201. }
  202. for ( var i = ( dir < 0 ? a.length - 1 : 0 );
  203. i != ( dir < 0 ? dir : a.length ); i += dir ) {
  204. fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] );
  205. }
  206. });
  207. },
  208. pushStack: function(a,args) {
  209. var fn = args && args[args.length-1];
  210. if ( !fn || fn.constructor != Function ) {
  211. if ( !this.stack ) this.stack = [];
  212. this.stack.push( this.get() );
  213. this.get( a );
  214. } else {
  215. var old = this.get();
  216. this.get( a );
  217. if ( fn.constructor == Function )
  218. return this.each( fn );
  219. this.get( old );
  220. }
  221. return this;
  222. }
  223. };
  224. jQuery.extend = jQuery.fn.extend = function(obj,prop) {
  225. if ( !prop ) { prop = obj; obj = this; }
  226. for ( var i in prop ) obj[i] = prop[i];
  227. return obj;
  228. };
  229. jQuery.extend({
  230. init: function(){
  231. jQuery.initDone = true;
  232. jQuery.each( jQuery.macros.axis, function(i,n){
  233. jQuery.fn[ i ] = function(a) {
  234. var ret = jQuery.map(this,n);
  235. if ( a && a.constructor == String )
  236. ret = jQuery.filter(a,ret).r;
  237. return this.pushStack( ret, arguments );
  238. };
  239. });
  240. jQuery.each( jQuery.macros.to, function(i,n){
  241. jQuery.fn[ i ] = function(){
  242. var a = arguments;
  243. return this.each(function(){
  244. for ( var j = 0; j < a.length; j++ )
  245. $(a[j])[n]( this );
  246. });
  247. };
  248. });
  249. jQuery.each( jQuery.macros.each, function(i,n){
  250. jQuery.fn[ i ] = function() {
  251. return this.each( n, arguments );
  252. };
  253. });
  254. jQuery.each( jQuery.macros.filter, function(i,n){
  255. jQuery.fn[ n ] = function(num,fn) {
  256. return this.filter( ":" + n + "(" + num + ")", fn );
  257. };
  258. });
  259. jQuery.each( jQuery.macros.attr, function(i,n){
  260. n = n || i;
  261. jQuery.fn[ i ] = function(h) {
  262. return h == undefined ?
  263. this.length ? this[0][n] : null :
  264. this.attr( n, h );
  265. };
  266. });
  267. jQuery.each( jQuery.macros.css, function(i,n){
  268. jQuery.fn[ n ] = function(h) {
  269. return h == undefined ?
  270. ( this.length ? jQuery.css( this[0], n ) : null ) :
  271. this.css( n, h );
  272. };
  273. });
  274. },
  275. each: function( obj, fn, args ) {
  276. if ( obj.length == undefined )
  277. for ( var i in obj )
  278. fn.apply( obj[i], args || [i, obj[i]] );
  279. else
  280. for ( var i = 0; i < obj.length; i++ )
  281. fn.apply( obj[i], args || [i, obj[i]] );
  282. return obj;
  283. },
  284. className: {
  285. add: function(o,c){
  286. if (jQuery.className.has(o,c)) return;
  287. o.className += ( o.className ? " " : "" ) + c;
  288. },
  289. remove: function(o,c){
  290. o.className = !c ? "" :
  291. o.className.replace(
  292. new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), "");
  293. },
  294. has: function(e,a) {
  295. if ( e.className != undefined )
  296. e = e.className;
  297. return new RegExp("(^|\\s)" + a + "(\\s|$)").test(e);
  298. }
  299. },
  300. swap: function(e,o,f) {
  301. for ( var i in o ) {
  302. e.style["old"+i] = e.style[i];
  303. e.style[i] = o[i];
  304. }
  305. f.apply( e, [] );
  306. for ( var i in o )
  307. e.style[i] = e.style["old"+i];
  308. },
  309. css: function(e,p) {
  310. if ( p == "height" || p == "width" ) {
  311. var old = {}, oHeight, oWidth, d = ["Top","Bottom","Right","Left"];
  312. for ( var i in d ) {
  313. old["padding" + d[i]] = 0;
  314. old["border" + d[i] + "Width"] = 0;
  315. }
  316. jQuery.swap( e, old, function() {
  317. if (jQuery.css(e,"display") != "none") {
  318. oHeight = e.offsetHeight;
  319. oWidth = e.offsetWidth;
  320. } else {
  321. e = $(e.cloneNode(true)).css({
  322. visibility: "hidden", position: "absolute", display: "block"
  323. }).prependTo("body")[0];
  324. oHeight = e.clientHeight;
  325. oWidth = e.clientWidth;
  326. e.parentNode.removeChild(e);
  327. }
  328. });
  329. return p == "height" ? oHeight : oWidth;
  330. } else if ( p == "opacity" && jQuery.browser.msie )
  331. return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1;
  332. return jQuery.curCSS( e, p );
  333. },
  334. curCSS: function(elem, prop, force) {
  335. var ret;
  336. if (!force && elem.style[prop]) {
  337. ret = elem.style[prop];
  338. } else if (elem.currentStyle) {
  339. var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()});
  340. ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
  341. } else if (document.defaultView && document.defaultView.getComputedStyle) {
  342. prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase();
  343. var cur = document.defaultView.getComputedStyle(elem, null);
  344. if ( cur )
  345. ret = cur.getPropertyValue(prop);
  346. else if ( prop == 'display' )
  347. ret = 'none';
  348. else
  349. jQuery.swap(elem, { display: 'block' }, function() {
  350. ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
  351. });
  352. }
  353. return ret;
  354. },
  355. clean: function(a) {
  356. var r = [];
  357. for ( var i = 0; i < a.length; i++ ) {
  358. if ( a[i].constructor == String ) {
  359. var table = "";
  360. if ( !a[i].indexOf("<thead") || !a[i].indexOf("<tbody") ) {
  361. table = "thead";
  362. a[i] = "<table>" + a[i] + "</table>";
  363. } else if ( !a[i].indexOf("<tr") ) {
  364. table = "tr";
  365. a[i] = "<table>" + a[i] + "</table>";
  366. } else if ( !a[i].indexOf("<td") || !a[i].indexOf("<th") ) {
  367. table = "td";
  368. a[i] = "<table><tbody><tr>" + a[i] + "</tr></tbody></table>";
  369. }
  370. var div = document.createElement("div");
  371. div.innerHTML = a[i];
  372. if ( table ) {
  373. div = div.firstChild;
  374. if ( table != "thead" ) div = div.firstChild;
  375. if ( table == "td" ) div = div.firstChild;
  376. }
  377. for ( var j = 0; j < div.childNodes.length; j++ )
  378. r.push( div.childNodes[j] );
  379. } else if ( a[i].jquery || a[i].length && !a[i].nodeType )
  380. for ( var k = 0; k < a[i].length; k++ )
  381. r.push( a[i][k] );
  382. else if ( a[i] !== null )
  383. r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
  384. }
  385. return r;
  386. },
  387. expr: {
  388. "": "m[2]== '*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
  389. "#": "a.getAttribute('id')&&a.getAttribute('id')==m[2]",
  390. ":": {
  391. // Position Checks
  392. lt: "i<m[3]-0",
  393. gt: "i>m[3]-0",
  394. nth: "m[3]-0==i",
  395. eq: "m[3]-0==i",
  396. first: "i==0",
  397. last: "i==r.length-1",
  398. even: "i%2==0",
  399. odd: "i%2",
  400. // Child Checks
  401. "first-child": "jQuery.sibling(a,0).cur",
  402. "last-child": "jQuery.sibling(a,0).last",
  403. "only-child": "jQuery.sibling(a).length==1",
  404. // Parent Checks
  405. parent: "a.childNodes.length",
  406. empty: "!a.childNodes.length",
  407. // Text Check
  408. contains: "(a.innerText||a.innerHTML).indexOf(m[3])>=0",
  409. // Visibility
  410. visible: "a.type!='hidden'&&jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!='hidden'",
  411. hidden: "a.type=='hidden'||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')=='hidden'",
  412. // Form elements
  413. enabled: "!a.disabled",
  414. disabled: "a.disabled",
  415. checked: "a.checked",
  416. selected: "a.selected"
  417. },
  418. ".": "jQuery.className.has(a,m[2])",
  419. "@": {
  420. "=": "z==m[4]",
  421. "!=": "z!=m[4]",
  422. "^=": "!z.indexOf(m[4])",
  423. "$=": "z.substr(z.length - m[4].length,m[4].length)==m[4]",
  424. "*=": "z.indexOf(m[4])>=0",
  425. "": "z"
  426. },
  427. "[": "jQuery.find(m[2],a).length"
  428. },
  429. token: [
  430. "\\.\\.|/\\.\\.", "a.parentNode",
  431. ">|/", "jQuery.sibling(a.firstChild)",
  432. "\\+", "jQuery.sibling(a).next",
  433. "~", function(a){
  434. var r = [];
  435. var s = jQuery.sibling(a);
  436. if ( s.n > 0 )
  437. for ( var i = s.n; i < s.length; i++ )
  438. r.push( s[i] );
  439. return r;
  440. }
  441. ],
  442. find: function( t, context ) {
  443. // Make sure that the context is a DOM Element
  444. if ( context && context.nodeType == undefined )
  445. context = null;
  446. // Set the correct context (if none is provided)
  447. context = context || jQuery.context || document;
  448. if ( t.constructor != String ) return [t];
  449. if ( !t.indexOf("//") ) {
  450. context = context.documentElement;
  451. t = t.substr(2,t.length);
  452. } else if ( !t.indexOf("/") ) {
  453. context = context.documentElement;
  454. t = t.substr(1,t.length);
  455. // FIX Assume the root element is right :(
  456. if ( t.indexOf("/") >= 1 )
  457. t = t.substr(t.indexOf("/"),t.length);
  458. }
  459. var ret = [context];
  460. var done = [];
  461. var last = null;
  462. while ( t.length > 0 && last != t ) {
  463. var r = [];
  464. last = t;
  465. t = jQuery.trim(t).replace( /^\/\//i, "" );
  466. var foundToken = false;
  467. for ( var i = 0; i < jQuery.token.length; i += 2 ) {
  468. var re = new RegExp("^(" + jQuery.token[i] + ")");
  469. var m = re.exec(t);
  470. if ( m ) {
  471. r = ret = jQuery.map( ret, jQuery.token[i+1] );
  472. t = jQuery.trim( t.replace( re, "" ) );
  473. foundToken = true;
  474. }
  475. }
  476. if ( !foundToken ) {
  477. if ( !t.indexOf(",") || !t.indexOf("|") ) {
  478. if ( ret[0] == context ) ret.shift();
  479. done = jQuery.merge( done, ret );
  480. r = ret = [context];
  481. t = " " + t.substr(1,t.length);
  482. } else {
  483. var re2 = /^([#.]?)([a-z0-9\\*_-]*)/i;
  484. var m = re2.exec(t);
  485. if ( m[1] == "#" ) {
  486. // Ummm, should make this work in all XML docs
  487. var oid = document.getElementById(m[2]);
  488. r = ret = oid ? [oid] : [];
  489. t = t.replace( re2, "" );
  490. } else {
  491. if ( !m[2] || m[1] == "." ) m[2] = "*";
  492. for ( var i = 0; i < ret.length; i++ )
  493. r = jQuery.merge( r,
  494. m[2] == "*" ?
  495. jQuery.getAll(ret[i]) :
  496. ret[i].getElementsByTagName(m[2])
  497. );
  498. }
  499. }
  500. }
  501. if ( t ) {
  502. var val = jQuery.filter(t,r);
  503. ret = r = val.r;
  504. t = jQuery.trim(val.t);
  505. }
  506. }
  507. if ( ret && ret[0] == context ) ret.shift();
  508. done = jQuery.merge( done, ret );
  509. return done;
  510. },
  511. getAll: function(o,r) {
  512. r = r || [];
  513. var s = o.childNodes;
  514. for ( var i = 0; i < s.length; i++ )
  515. if ( s[i].nodeType == 1 ) {
  516. r.push( s[i] );
  517. jQuery.getAll( s[i], r );
  518. }
  519. return r;
  520. },
  521. attr: function(elem, name, value){
  522. var fix = {
  523. "for": "htmlFor",
  524. "class": "className",
  525. "float": "cssFloat",
  526. innerHTML: "innerHTML",
  527. className: "className"
  528. };
  529. if ( fix[name] ) {
  530. if ( value != undefined ) elem[fix[name]] = value;
  531. return elem[fix[name]];
  532. } else if ( elem.getAttribute ) {
  533. if ( value != undefined ) elem.setAttribute( name, value );
  534. return elem.getAttribute( name, 2 );
  535. } else {
  536. name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
  537. if ( value != undefined ) elem[name] = value;
  538. return elem[name];
  539. }
  540. },
  541. // The regular expressions that power the parsing engine
  542. parse: [
  543. // Match: [@value='test'], [@foo]
  544. [ "\\[ *(@)S *([!*$^=]*) *Q\\]", 1 ],
  545. // Match: [div], [div p]
  546. [ "(\\[)Q\\]", 0 ],
  547. // Match: :contains('foo')
  548. [ "(:)S\\(Q\\)", 0 ],
  549. // Match: :even, :last-chlid
  550. [ "([:.#]*)S", 0 ]
  551. ],
  552. filter: function(t,r,not) {
  553. // Figure out if we're doing regular, or inverse, filtering
  554. var g = not !== false ? jQuery.grep :
  555. function(a,f) {return jQuery.grep(a,f,true);};
  556. while ( t && /^[a-z[({<*:.#]/i.test(t) ) {
  557. var p = jQuery.parse;
  558. for ( var i = 0; i < p.length; i++ ) {
  559. var re = new RegExp( "^" + p[i][0]
  560. // Look for a string-like sequence
  561. .replace( 'S', "([a-z*_-][a-z0-9_-]*)" )
  562. // Look for something (optionally) enclosed with quotes
  563. .replace( 'Q', " *'?\"?([^'\"]*?)'?\"? *" ), "i" );
  564. var m = re.exec( t );
  565. if ( m ) {
  566. // Re-organize the match
  567. if ( p[i][1] )
  568. m = ["", m[1], m[3], m[2], m[4]];
  569. // Remove what we just matched
  570. t = t.replace( re, "" );
  571. break;
  572. }
  573. }
  574. // :not() is a special case that can be optomized by
  575. // keeping it out of the expression list
  576. if ( m[1] == ":" && m[2] == "not" )
  577. r = jQuery.filter(m[3],r,false).r;
  578. // Otherwise, find the expression to execute
  579. else {
  580. var f = jQuery.expr[m[1]];
  581. if ( f.constructor != String )
  582. f = jQuery.expr[m[1]][m[2]];
  583. // Build a custom macro to enclose it
  584. eval("f = function(a,i){" +
  585. ( m[1] == "@" ? "z=jQuery.attr(a,m[3]);" : "" ) +
  586. "return " + f + "}");
  587. // Execute it against the current filter
  588. r = g( r, f );
  589. }
  590. }
  591. // Return an array of filtered elements (r)
  592. // and the modified expression string (t)
  593. return { r: r, t: t };
  594. },
  595. trim: function(t){
  596. return t.replace(/^\s+|\s+$/g, "");
  597. },
  598. parents: function( elem ){
  599. var matched = [];
  600. var cur = elem.parentNode;
  601. while ( cur && cur != document ) {
  602. matched.push( cur );
  603. cur = cur.parentNode;
  604. }
  605. return matched;
  606. },
  607. sibling: function(elem, pos, not) {
  608. var elems = [];
  609. var siblings = elem.parentNode.childNodes;
  610. for ( var i = 0; i < siblings.length; i++ ) {
  611. if ( not === true && siblings[i] == elem ) continue;
  612. if ( siblings[i].nodeType == 1 )
  613. elems.push( siblings[i] );
  614. if ( siblings[i] == elem )
  615. elems.n = elems.length - 1;
  616. }
  617. return jQuery.extend( elems, {
  618. last: elems.n == elems.length - 1,
  619. cur: pos == "even" && elems.n % 2 == 0 || pos == "odd" && elems.n % 2 || elems[pos] == elem,
  620. prev: elems[elems.n - 1],
  621. next: elems[elems.n + 1]
  622. });
  623. },
  624. merge: function(first, second) {
  625. var result = [];
  626. // Move b over to the new array (this helps to avoid
  627. // StaticNodeList instances)
  628. for ( var k = 0; k < first.length; k++ )
  629. result[k] = first[k];
  630. // Now check for duplicates between a and b and only
  631. // add the unique items
  632. for ( var i = 0; i < second.length; i++ ) {
  633. var noCollision = true;
  634. // The collision-checking process
  635. for ( var j = 0; j < first.length; j++ )
  636. if ( second[i] == first[j] )
  637. noCollision = false;
  638. // If the item is unique, add it
  639. if ( noCollision )
  640. result.push( second[i] );
  641. }
  642. return result;
  643. },
  644. grep: function(elems, fn, inv) {
  645. // If a string is passed in for the function, make a function
  646. // for it (a handy shortcut)
  647. if ( fn.constructor == String )
  648. fn = new Function("a","i","return " + fn);
  649. var result = [];
  650. // Go through the array, only saving the items
  651. // that pass the validator function
  652. for ( var i = 0; i < elems.length; i++ )
  653. if ( !inv && fn(elems[i],i) || inv && !fn(elems[i],i) )
  654. result.push( elems[i] );
  655. return result;
  656. },
  657. map: function(elems, fn) {
  658. // If a string is passed in for the function, make a function
  659. // for it (a handy shortcut)
  660. if ( fn.constructor == String )
  661. fn = new Function("a","return " + fn);
  662. var result = [];
  663. // Go through the array, translating each of the items to their
  664. // new value (or values).
  665. for ( var i = 0; i < elems.length; i++ ) {
  666. var val = fn(elems[i],i);
  667. if ( val !== null && val != undefined ) {
  668. if ( val.constructor != Array ) val = [val];
  669. result = jQuery.merge( result, val );
  670. }
  671. }
  672. return result;
  673. },
  674. /*
  675. * A number of helper functions used for managing events.
  676. * Many of the ideas behind this code orignated from Dean Edwards' addEvent library.
  677. */
  678. event: {
  679. // Bind an event to an element
  680. // Original by Dean Edwards
  681. add: function(element, type, handler) {
  682. // For whatever reason, IE has trouble passing the window object
  683. // around, causing it to be cloned in the process
  684. if ( jQuery.browser.msie && element.setInterval != undefined )
  685. element = window;
  686. // Make sure that the function being executed has a unique ID
  687. if ( !handler.guid )
  688. handler.guid = this.guid++;
  689. // Init the element's event structure
  690. if (!element.events)
  691. element.events = {};
  692. // Get the current list of functions bound to this event
  693. var handlers = element.events[type];
  694. // If it hasn't been initialized yet
  695. if (!handlers) {
  696. // Init the event handler queue
  697. handlers = element.events[type] = {};
  698. // Remember an existing handler, if it's already there
  699. if (element["on" + type])
  700. handlers[0] = element["on" + type];
  701. }
  702. // Add the function to the element's handler list
  703. handlers[handler.guid] = handler;
  704. // And bind the global event handler to the element
  705. element["on" + type] = this.handle;
  706. // Remember the function in a global list (for triggering)
  707. if (!this.global[type])
  708. this.global[type] = [];
  709. this.global[type].push( element );
  710. },
  711. guid: 1,
  712. global: {},
  713. // Detach an event or set of events from an element
  714. remove: function(element, type, handler) {
  715. if (element.events)
  716. if (type && element.events[type])
  717. if ( handler )
  718. delete element.events[type][handler.guid];
  719. else
  720. for ( var i in element.events[type] )
  721. delete element.events[type][i];
  722. else
  723. for ( var j in element.events )
  724. this.remove( element, j );
  725. },
  726. trigger: function(type,data,element) {
  727. // Touch up the incoming data
  728. data = data || [];
  729. // Handle a global trigger
  730. if ( !element ) {
  731. var g = this.global[type];
  732. if ( g )
  733. for ( var i = 0; i < g.length; i++ )
  734. this.trigger( type, data, g[i] );
  735. // Handle triggering a single element
  736. } else if ( element["on" + type] ) {
  737. // Pass along a fake event
  738. data.unshift( this.fix({ type: type, target: element }) );
  739. // Trigger the event
  740. element["on" + type].apply( element, data );
  741. }
  742. },
  743. handle: function(event) {
  744. if ( typeof jQuery == "undefined" ) return;
  745. event = event || jQuery.event.fix( window.event );
  746. // If no correct event was found, fail
  747. if ( !event ) return;
  748. var returnValue = true;
  749. var c = this.events[event.type];
  750. for ( var j in c ) {
  751. if ( c[j].apply( this, [event] ) === false ) {
  752. event.preventDefault();
  753. event.stopPropagation();
  754. returnValue = false;
  755. }
  756. }
  757. return returnValue;
  758. },
  759. fix: function(event) {
  760. if ( event ) {
  761. event.preventDefault = function() {
  762. this.returnValue = false;
  763. };
  764. event.stopPropagation = function() {
  765. this.cancelBubble = true;
  766. };
  767. }
  768. return event;
  769. }
  770. }
  771. });
  772. new function() {
  773. var b = navigator.userAgent.toLowerCase();
  774. // Figure out what browser is being used
  775. jQuery.browser = {
  776. safari: /webkit/.test(b),
  777. opera: /opera/.test(b),
  778. msie: /msie/.test(b) && !/opera/.test(b),
  779. mozilla: /mozilla/.test(b) && !/compatible/.test(b)
  780. };
  781. // Check to see if the W3C box model is being used
  782. jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat";
  783. };
  784. jQuery.macros = {
  785. to: {
  786. appendTo: "append",
  787. prependTo: "prepend",
  788. insertBefore: "before",
  789. insertAfter: "after"
  790. },
  791. css: "width,height,top,left,position,float,overflow,color,background".split(","),
  792. filter: [ "eq", "lt", "gt", "contains" ],
  793. attr: {
  794. val: "value",
  795. html: "innerHTML",
  796. id: null,
  797. title: null,
  798. name: null,
  799. href: null,
  800. src: null,
  801. rel: null
  802. },
  803. axis: {
  804. parent: "a.parentNode",
  805. ancestors: jQuery.parents,
  806. parents: jQuery.parents,
  807. next: "jQuery.sibling(a).next",
  808. prev: "jQuery.sibling(a).prev",
  809. siblings: jQuery.sibling,
  810. children: "a.childNodes"
  811. },
  812. each: {
  813. removeAttr: function( key ) {
  814. this.removeAttribute( key );
  815. },
  816. show: function(){
  817. this.style.display = this.oldblock ? this.oldblock : "";
  818. if ( jQuery.css(this,"display") == "none" )
  819. this.style.display = "block";
  820. },
  821. hide: function(){
  822. this.oldblock = this.oldblock || jQuery.css(this,"display");
  823. if ( this.oldblock == "none" )
  824. this.oldblock = "block";
  825. this.style.display = "none";
  826. },
  827. toggle: function(){
  828. $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments );
  829. },
  830. addClass: function(c){
  831. jQuery.className.add(this,c);
  832. },
  833. removeClass: function(c){
  834. jQuery.className.remove(this,c);
  835. },
  836. toggleClass: function( c ){
  837. jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
  838. },
  839. remove: function(a){
  840. if ( !a || jQuery.filter( [this], a ).r )
  841. this.parentNode.removeChild( this );
  842. },
  843. empty: function(){
  844. while ( this.firstChild )
  845. this.removeChild( this.firstChild );
  846. },
  847. bind: function( type, fn ) {
  848. if ( fn.constructor == String )
  849. fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn);
  850. jQuery.event.add( this, type, fn );
  851. },
  852. unbind: function( type, fn ) {
  853. jQuery.event.remove( this, type, fn );
  854. },
  855. trigger: function( type, data ) {
  856. jQuery.event.trigger( type, data, this );
  857. }
  858. }
  859. };
  860. jQuery.init();jQuery.fn.extend({
  861. // We're overriding the old toggle function, so
  862. // remember it for later
  863. _toggle: jQuery.fn.toggle,
  864. toggle: function(a,b) {
  865. // If two functions are passed in, we're
  866. // toggling on a click
  867. return a && b && a.constructor == Function && b.constructor == Function ? this.click(function(e){
  868. // Figure out which function to execute
  869. this.last = this.last == a ? b : a;
  870. // Make sure that clicks stop
  871. e.preventDefault();
  872. // and execute the function
  873. return this.last.apply( this, [e] ) || false;
  874. }) :
  875. // Otherwise, execute the old toggle function
  876. this._toggle.apply( this, arguments );
  877. },
  878. hover: function(f,g) {
  879. // A private function for haandling mouse 'hovering'
  880. function handleHover(e) {
  881. // Check if mouse(over|out) are still within the same parent element
  882. var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
  883. // Traverse up the tree
  884. while ( p && p != this ) p = p.parentNode;
  885. // If we actually just moused on to a sub-element, ignore it
  886. if ( p == this ) return false;
  887. // Execute the right function
  888. return (e.type == "mouseover" ? f : g).apply(this, [e]);
  889. }
  890. // Bind the function to the two event listeners
  891. return this.mouseover(handleHover).mouseout(handleHover);
  892. },
  893. ready: function(f) {
  894. // If the DOM is already ready
  895. if ( jQuery.isReady )
  896. // Execute the function immediately
  897. f.apply( document );
  898. // Otherwise, remember the function for later
  899. else {
  900. // Add the function to the wait list
  901. jQuery.readyList.push( f );
  902. }
  903. return this;
  904. }
  905. });
  906. jQuery.extend({
  907. /*
  908. * All the code that makes DOM Ready work nicely.
  909. */
  910. isReady: false,
  911. readyList: [],
  912. // Handle when the DOM is ready
  913. ready: function() {
  914. // Make sure that the DOM is not already loaded
  915. if ( !jQuery.isReady ) {
  916. // Remember that the DOM is ready
  917. jQuery.isReady = true;
  918. // If there are functions bound, to execute
  919. if ( jQuery.readyList ) {
  920. // Execute all of them
  921. for ( var i = 0; i < jQuery.readyList.length; i++ )
  922. jQuery.readyList[i].apply( document );
  923. // Reset the list of functions
  924. jQuery.readyList = null;
  925. }
  926. }
  927. }
  928. });
  929. new function(){
  930. var e = ("blur,focus,load,resize,scroll,unload,click,dblclick," +
  931. "mousedown,mouseup,mousemove,mouseover,mouseout,change,reset,select," +
  932. "submit,keydown,keypress,keyup,error").split(",");
  933. // Go through all the event names, but make sure that
  934. // it is enclosed properly
  935. for ( var i = 0; i < e.length; i++ ) new function(){
  936. var o = e[i];
  937. // Handle event binding
  938. jQuery.fn[o] = function(f){
  939. return f ? this.bind(o, f) : this.trigger(o);
  940. };
  941. // Handle event unbinding
  942. jQuery.fn["un"+o] = function(f){ return this.unbind(o, f); };
  943. // Finally, handle events that only fire once
  944. jQuery.fn["one"+o] = function(f){
  945. // Attach the event listener
  946. return this.each(function(){
  947. var count = 0;
  948. // Add the event
  949. jQuery.event.add( this, o, function(e){
  950. // If this function has already been executed, stop
  951. if ( count++ ) return;
  952. // And execute the bound function
  953. return f.apply(this, [e]);
  954. });
  955. });
  956. };
  957. };
  958. // If Mozilla is used
  959. if ( jQuery.browser.mozilla || jQuery.browser.opera ) {
  960. // Use the handy event callback
  961. document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
  962. // If IE is used, use the excellent hack by Matthias Miller
  963. // http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
  964. } else if ( jQuery.browser.msie ) {
  965. // Only works if you document.write() it
  966. document.write("<scr" + "ipt id=__ie_init defer=true " +
  967. "src=//:><\/script>");
  968. // Use the defer script hack
  969. var script = document.getElementById("__ie_init");
  970. script.onreadystatechange = function() {
  971. if ( this.readyState == "complete" )
  972. jQuery.ready();
  973. };
  974. // Clear from memory
  975. script = null;
  976. // If Safari is used
  977. } else if ( jQuery.browser.safari ) {
  978. // Continually check to see if the document.readyState is valid
  979. jQuery.safariTimer = setInterval(function(){
  980. // loaded and complete are both valid states
  981. if ( document.readyState == "loaded" ||
  982. document.readyState == "complete" ) {
  983. // If either one are found, remove the timer
  984. clearInterval( jQuery.safariTimer );
  985. jQuery.safariTimer = null;
  986. // and execute any waiting functions
  987. jQuery.ready();
  988. }
  989. }, 10);
  990. }
  991. // A fallback to window.onload, that will always work
  992. jQuery.event.add( window, "load", jQuery.ready );
  993. };
  994. jQuery.fn.extend({
  995. // overwrite the old show method
  996. _show: jQuery.fn.show,
  997. show: function(speed,callback){
  998. return speed ? this.animate({
  999. height: "show", width: "show", opacity: "show"
  1000. }, speed, callback) : this._show();
  1001. },
  1002. // Overwrite the old hide method
  1003. _hide: jQuery.fn.hide,
  1004. hide: function(speed,callback){
  1005. return speed ? this.animate({
  1006. height: "hide", width: "hide", opacity: "hide"
  1007. }, speed, callback) : this._hide();
  1008. },
  1009. slideDown: function(speed,callback){
  1010. return this.animate({height: "show"}, speed, callback);
  1011. },
  1012. slideUp: function(speed,callback){
  1013. return this.animate({height: "hide"}, speed, callback);
  1014. },
  1015. slideToggle: function(speed,callback){
  1016. return this.each(function(){
  1017. var state = $(this).is(":hidden") ? "show" : "hide";
  1018. $(this).animate({height: state}, speed, callback);
  1019. });
  1020. },
  1021. fadeIn: function(speed,callback){
  1022. return this.animate({opacity: "show"}, speed, callback);
  1023. },
  1024. fadeOut: function(speed,callback){
  1025. return this.animate({opacity: "hide"}, speed, callback);
  1026. },
  1027. fadeTo: function(speed,to,callback){
  1028. return this.animate({opacity: to}, speed, callback);
  1029. },
  1030. animate: function(prop,speed,callback) {
  1031. return this.queue(function(){
  1032. this.curAnim = prop;
  1033. for ( var p in prop ) {
  1034. var e = new jQuery.fx( this, jQuery.speed(speed,callback), p );
  1035. if ( prop[p].constructor == Number )
  1036. e.custom( e.cur(), prop[p] );
  1037. else
  1038. e[ prop[p] ]( prop );
  1039. }
  1040. });
  1041. },
  1042. queue: function(type,fn){
  1043. if ( !fn ) {
  1044. fn = type;
  1045. type = "fx";
  1046. }
  1047. return this.each(function(){
  1048. if ( !this.queue )
  1049. this.queue = {};
  1050. if ( !this.queue[type] )
  1051. this.queue[type] = [];
  1052. this.queue[type].push( fn );
  1053. if ( this.queue[type].length == 1 )
  1054. fn.apply(this);
  1055. });
  1056. }
  1057. });
  1058. jQuery.extend({
  1059. setAuto: function(e,p) {
  1060. if ( e.notAuto ) return;
  1061. if ( p == "height" && e.scrollHeight != parseInt(jQuery.curCSS(e,p)) ) return;
  1062. if ( p == "width" && e.scrollWidth != parseInt(jQuery.curCSS(e,p)) ) return;
  1063. // Remember the original height
  1064. var a = e.style[p];
  1065. // Figure out the size of the height right now
  1066. var o = jQuery.curCSS(e,p,1);
  1067. if ( p == "height" && e.scrollHeight != o ||
  1068. p == "width" && e.scrollWidth != o ) return;
  1069. // Set the height to auto
  1070. e.style[p] = e.currentStyle ? "" : "auto";
  1071. // See what the size of "auto" is
  1072. var n = jQuery.curCSS(e,p,1);
  1073. // Revert back to the original size
  1074. if ( o != n && n != "auto" ) {
  1075. e.style[p] = a;
  1076. e.notAuto = true;
  1077. }
  1078. },
  1079. speed: function(s,o) {
  1080. o = o || {};
  1081. if ( o.constructor == Function )
  1082. o = { complete: o };
  1083. var ss = { slow: 600, fast: 200 };
  1084. o.duration = (s && s.constructor == Number ? s : ss[s]) || 400;
  1085. // Queueing
  1086. o.oldComplete = o.complete;
  1087. o.complete = function(){
  1088. jQuery.dequeue(this, "fx");
  1089. if ( o.oldComplete && o.oldComplete.constructor == Function )
  1090. o.oldComplete.apply( this );
  1091. };
  1092. return o;
  1093. },
  1094. queue: {},
  1095. dequeue: function(elem,type){
  1096. type = type || "fx";
  1097. if ( elem.queue && elem.queue[type] ) {
  1098. // Remove self
  1099. elem.queue[type].shift();
  1100. // Get next function
  1101. var f = elem.queue[type][0];
  1102. if ( f ) f.apply( elem );
  1103. }
  1104. },
  1105. /*
  1106. * I originally wrote fx() as a clone of moo.fx and in the process
  1107. * of making it small in size the code became illegible to sane
  1108. * people. You've been warned.
  1109. */
  1110. fx: function( elem, options, prop ){
  1111. var z = this;
  1112. // The users options
  1113. z.o = {
  1114. duration: options.duration || 400,
  1115. complete: options.complete,
  1116. step: options.step
  1117. };
  1118. // The element
  1119. z.el = elem;
  1120. // The styles
  1121. var y = z.el.style;
  1122. // Simple function for setting a style value
  1123. z.a = function(){
  1124. if ( options.step )
  1125. options.step.apply( elem, [ z.now ] );
  1126. if ( prop == "opacity" ) {
  1127. if (z.now == 1) z.now = 0.9999;
  1128. if (window.ActiveXObject)
  1129. y.filter = "alpha(opacity=" + z.now*100 + ")";
  1130. else
  1131. y.opacity = z.now;
  1132. // My hate for IE will never die
  1133. } else if ( parseInt(z.now) )
  1134. y[prop] = parseInt(z.now) + "px";
  1135. y.display = "block";
  1136. };
  1137. // Figure out the maximum number to run to
  1138. z.max = function(){
  1139. return parseFloat( jQuery.css(z.el,prop) );
  1140. };
  1141. // Get the current size
  1142. z.cur = function(){
  1143. var r = parseFloat( jQuery.curCSS(z.el, prop) );
  1144. return r && r > -10000 ? r : z.max();
  1145. };
  1146. // Start an animation from one number to another
  1147. z.custom = function(from,to){
  1148. z.startTime = (new Date()).getTime();
  1149. z.now = from;
  1150. z.a();
  1151. z.timer = setInterval(function(){
  1152. z.step(from, to);
  1153. }, 13);
  1154. };
  1155. // Simple 'show' function
  1156. z.show = function( p ){
  1157. if ( !z.el.orig ) z.el.orig = {};
  1158. // Remember where we started, so that we can go back to it later
  1159. z.el.orig[prop] = this.cur();
  1160. z.custom( 0, z.el.orig[prop] );
  1161. // Stupid IE, look what you made me do
  1162. if ( prop != "opacity" )
  1163. y[prop] = "1px";
  1164. };
  1165. // Simple 'hide' function
  1166. z.hide = function(){
  1167. if ( !z.el.orig ) z.el.orig = {};
  1168. // Remember where we started, so that we can go back to it later
  1169. z.el.orig[prop] = this.cur();
  1170. z.o.hide = true;
  1171. // Begin the animation
  1172. z.custom(z.el.orig[prop], 0);
  1173. };
  1174. // IE has trouble with opacity if it does not have layout
  1175. if ( jQuery.browser.msie && !z.el.currentStyle.hasLayout )
  1176. y.zoom = "1";
  1177. // Remember the overflow of the element
  1178. if ( !z.el.oldOverlay )
  1179. z.el.oldOverflow = jQuery.css( z.el, "overflow" );
  1180. // Make sure that nothing sneaks out
  1181. y.overflow = "hidden";
  1182. // Each step of an animation
  1183. z.step = function(firstNum, lastNum){
  1184. var t = (new Date()).getTime();
  1185. if (t > z.o.duration + z.startTime) {
  1186. // Stop the timer
  1187. clearInterval(z.timer);
  1188. z.timer = null;
  1189. z.now = lastNum;
  1190. z.a();
  1191. z.el.curAnim[ prop ] = true;
  1192. var done = true;
  1193. for ( var i in z.el.curAnim )
  1194. if ( z.el.curAnim[i] !== true )
  1195. done = false;
  1196. if ( done ) {
  1197. // Reset the overflow
  1198. y.overflow = z.el.oldOverflow;
  1199. // Hide the element if the "hide" operation was done
  1200. if ( z.o.hide )
  1201. y.display = 'none';
  1202. // Reset the property, if the item has been hidden
  1203. if ( z.o.hide ) {
  1204. for ( var p in z.el.curAnim ) {
  1205. y[ p ] = z.el.orig[p] + ( p == "opacity" ? "" : "px" );
  1206. // set its height and/or width to auto
  1207. if ( p == 'height' || p == 'width' )
  1208. jQuery.setAuto( z.el, p );
  1209. }
  1210. }
  1211. }
  1212. // If a callback was provided, execute it
  1213. if( done && z.o.complete && z.o.complete.constructor == Function )
  1214. // Execute the complete function
  1215. z.o.complete.apply( z.el );
  1216. } else {
  1217. // Figure out where in the animation we are and set the number
  1218. var p = (t - this.startTime) / z.o.duration;
  1219. z.now = ((-Math.cos(p*Math.PI)/2) + 0.5) * (lastNum-firstNum) + firstNum;
  1220. // Perform the next step of the animation
  1221. z.a();
  1222. }
  1223. };
  1224. }
  1225. });
  1226. // AJAX Plugin
  1227. // Docs Here:
  1228. // http://jquery.com/docs/ajax/
  1229. jQuery.fn.loadIfModified = function( url, params, callback ) {
  1230. this.load( url, params, callback, 1 );
  1231. };
  1232. jQuery.fn.load = function( url, params, callback, ifModified ) {
  1233. if ( url.constructor == Function )
  1234. return this.bind("load", url);
  1235. callback = callback || function(){};
  1236. // Default to a GET request
  1237. var type = "GET";
  1238. // If the second parameter was provided
  1239. if ( params ) {
  1240. // If it's a function
  1241. if ( params.constructor == Function ) {
  1242. // We assume that it's the callback
  1243. callback = params;
  1244. params = null;
  1245. // Otherwise, build a param string
  1246. } else {
  1247. params = jQuery.param( params );
  1248. type = "POST";
  1249. }
  1250. }
  1251. var self = this;
  1252. // Request the remote document
  1253. jQuery.ajax( type, url, params,function(res, status){
  1254. if ( status == "success" || !ifModified && status == "notmodified" ) {
  1255. // Inject the HTML into all the matched elements
  1256. self.html(res.responseText).each( callback, [res.responseText, status] );
  1257. // Execute all the scripts inside of the newly-injected HTML
  1258. $("script", self).each(function(){
  1259. if ( this.src )
  1260. $.getScript( this.src );
  1261. else
  1262. eval.call( window, this.text || this.textContent || this.innerHTML || "" );
  1263. });
  1264. } else
  1265. callback.apply( self, [res.responseText, status] );
  1266. }, ifModified);
  1267. return this;
  1268. };
  1269. // If IE is used, create a wrapper for the XMLHttpRequest object
  1270. if ( jQuery.browser.msie )
  1271. XMLHttpRequest = function(){
  1272. return new ActiveXObject(
  1273. navigator.userAgent.indexOf("MSIE 5") >= 0 ?
  1274. "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"
  1275. );
  1276. };
  1277. // Attach a bunch of functions for handling common AJAX events
  1278. new function(){
  1279. var e = "ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess".split(',');
  1280. for ( var i = 0; i < e.length; i++ ) new function(){
  1281. var o = e[i];
  1282. jQuery.fn[o] = function(f){
  1283. return this.bind(o, f);
  1284. };
  1285. };
  1286. };
  1287. jQuery.extend({
  1288. get: function( url, data, callback, type, ifModified ) {
  1289. if ( data.constructor == Function ) {
  1290. type = callback;
  1291. callback = data;
  1292. data = null;
  1293. }
  1294. if ( data ) url += "?" + jQuery.param(data);
  1295. // Build and start the HTTP Request
  1296. jQuery.ajax( "GET", url, null, function(r, status) {
  1297. if ( callback ) callback( jQuery.httpData(r,type), status );
  1298. }, ifModified);
  1299. },
  1300. getIfModified: function( url, data, callback, type ) {
  1301. jQuery.get(url, data, callback, type, 1);
  1302. },
  1303. getScript: function( url, data, callback ) {
  1304. jQuery.get(url, data, callback, "script");
  1305. },
  1306. post: function( url, data, callback, type ) {
  1307. // Build and start the HTTP Request
  1308. jQuery.ajax( "POST", url, jQuery.param(data), function(r, status) {
  1309. if ( callback ) callback( jQuery.httpData(r,type), status );
  1310. });
  1311. },
  1312. // timeout (ms)
  1313. timeout: 0,
  1314. ajaxTimeout: function(timeout) {
  1315. jQuery.timeout = timeout;
  1316. },
  1317. // Last-Modified header cache for next request
  1318. lastModified: {},
  1319. ajax: function( type, url, data, ret, ifModified ) {
  1320. // If only a single argument was passed in,
  1321. // assume that it is a object of key/value pairs
  1322. if ( !url ) {
  1323. ret = type.complete;
  1324. var success = type.success;
  1325. var error = type.error;
  1326. data = type.data;
  1327. url = type.url;
  1328. type = type.type;
  1329. }
  1330. // Watch for a new set of requests
  1331. if ( ! jQuery.active++ )
  1332. jQuery.event.trigger( "ajaxStart" );
  1333. var requestDone = false;
  1334. // Create the request object
  1335. var xml = new XMLHttpRequest();
  1336. // Open the socket
  1337. xml.open(type || "GET", url, true);
  1338. // Set the correct header, if data is being sent
  1339. if ( data )
  1340. xml.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  1341. // Set the If-Modified-Since header, if ifModified mode.
  1342. if ( ifModified )
  1343. xml.setRequestHeader("If-Modified-Since",
  1344. jQuery.lastModified[url] || "Thu, 01 Jan 1970 00:00:00 GMT" );
  1345. // Set header so calling script knows that it's an XMLHttpRequest
  1346. xml.setRequestHeader("X-Requested-With", "XMLHttpRequest");
  1347. // Make sure the browser sends the right content length
  1348. if ( xml.overrideMimeType )
  1349. xml.setRequestHeader("Connection", "close");
  1350. // Wait for a response to come back
  1351. var onreadystatechange = function(istimeout){
  1352. // The transfer is complete and the data is available, or the request timed out
  1353. if ( xml && (xml.readyState == 4 || istimeout == "timeout") ) {
  1354. requestDone = true;
  1355. var status = jQuery.httpSuccess( xml ) && istimeout != "timeout" ?
  1356. ifModified && jQuery.httpNotModified( xml, url ) ? "notmodified" : "success" : "error";
  1357. // Make sure that the request was successful or notmodified
  1358. if ( status != "error" ) {
  1359. // Cache Last-Modified header, if ifModified mode.
  1360. var modRes = xml.getResponseHeader("Last-Modified");
  1361. if ( ifModified && modRes ) jQuery.lastModified[url] = modRes;
  1362. // If a local callback was specified, fire it
  1363. if ( success ) success( xml, status );
  1364. // Fire the global callback
  1365. jQuery.event.trigger( "ajaxSuccess" );
  1366. // Otherwise, the request was not successful
  1367. } else {
  1368. // If a local callback was specified, fire it
  1369. if ( error ) error( xml, status );
  1370. // Fire the global callback
  1371. jQuery.event.trigger( "ajaxError" );
  1372. }
  1373. // The request was completed
  1374. jQuery.event.trigger( "ajaxComplete" );
  1375. // Handle the global AJAX counter
  1376. if ( ! --jQuery.active )
  1377. jQuery.event.trigger( "ajaxStop" );
  1378. // Process result
  1379. if ( ret ) ret(xml, status);
  1380. // Stop memory leaks
  1381. xml.onreadystatechange = function(){};
  1382. xml = null;
  1383. }
  1384. };
  1385. xml.onreadystatechange = onreadystatechange;
  1386. // Timeout checker
  1387. if(jQuery.timeout > 0)
  1388. setTimeout(function(){
  1389. // Check to see if the request is still happening
  1390. if (xml) {
  1391. // Cancel the request
  1392. xml.abort();
  1393. if ( !requestDone ) onreadystatechange( "timeout" );
  1394. // Clear from memory
  1395. xml = null;
  1396. }
  1397. }, jQuery.timeout);
  1398. // Send the data
  1399. xml.send(data);
  1400. },
  1401. // Counter for holding the number of active queries
  1402. active: 0,
  1403. // Determines if an XMLHttpRequest was successful or not
  1404. httpSuccess: function(r) {
  1405. try {
  1406. return !r.status && location.protocol == "file:" ||
  1407. ( r.status >= 200 && r.status < 300 ) || r.status == 304 ||
  1408. jQuery.browser.safari && r.status == undefined;
  1409. } catch(e){}
  1410. return false;
  1411. },
  1412. // Determines if an XMLHttpRequest returns NotModified
  1413. httpNotModified: function(xml, url) {
  1414. try {
  1415. var xmlRes = xml.getResponseHeader("Last-Modified");
  1416. // Firefox always returns 200. check Last-Modified date
  1417. return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
  1418. jQuery.browser.safari && xml.status == undefined;
  1419. } catch(e){}
  1420. return false;
  1421. },
  1422. // Get the data out of an XMLHttpRequest.
  1423. // Return parsed XML if content-type header is "xml" and type is "xml" or omitted,
  1424. // otherwise return plain text.
  1425. httpData: function(r,type) {
  1426. var ct = r.getResponseHeader("content-type");
  1427. var data = !type && ct && ct.indexOf("xml") >= 0;
  1428. data = type == "xml" || data ? r.responseXML : r.responseText;
  1429. // If the type is "script", eval it
  1430. if ( type == "script" ) eval.call( window, data );
  1431. return data;
  1432. },
  1433. // Serialize an array of form elements or a set of
  1434. // key/values into a query string
  1435. param: function(a) {
  1436. var s = [];
  1437. // If an array was passed in, assume that it is an array
  1438. // of form elements
  1439. if ( a.constructor == Array ) {
  1440. // Serialize the form elements
  1441. for ( var i = 0; i < a.length; i++ )
  1442. s.push( a[i].name + "=" + encodeURIComponent( a[i].value ) );
  1443. // Otherwise, assume that it's an object of key/value pairs
  1444. } else {
  1445. // Serialize the key/values
  1446. for ( var j in a )
  1447. s.push( j + "=" + encodeURIComponent( a[j] ) );
  1448. }
  1449. // Return the resulting serialization
  1450. return s.join("&");
  1451. }
  1452. });