dom/tests/mochitest/ajax/jquery/dist/jquery.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial