annotate node_modules/jQuery/lib/node-jquery.js @ 101:52e44ee1c791 tip master

enabled all scores in autostart script
author Rob Canning <rc@kiben.net>
date Tue, 21 Apr 2015 16:20:57 +0100
parents cd921abc8887
children
rev   line source
rob@77 1 (function () {
rob@77 2 function create(window) {
rob@77 3
rob@77 4 if(window == null ) {
rob@77 5 window = require('jsdom').jsdom().createWindow();
rob@77 6 // assume window is a jsdom instance...
rob@77 7 // jsdom includes an incomplete version of XMLHttpRequest
rob@77 8 window.XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
rob@77 9 // trick jQuery into thinking CORS is supported (should be in node-XMLHttpRequest)
rob@77 10 window.XMLHttpRequest.prototype.withCredentials = false;
rob@77 11
rob@77 12 if(window.location == null) {
rob@77 13 window.location = require('location');
rob@77 14 }
rob@77 15
rob@77 16 if(window.navigator == null) {
rob@77 17 window.navigator = require('navigator');
rob@77 18 }
rob@77 19 }
rob@77 20
rob@77 21
rob@77 22 var location = window.location,
rob@77 23 navigator = window.navigator,
rob@77 24 XMLHttpRequest = window.XMLHttpRequest;
rob@77 25
rob@77 26 /*!
rob@77 27 * jQuery JavaScript Library v1.7.2
rob@77 28 * http://jquery.com/
rob@77 29 *
rob@77 30 * Copyright 2011, John Resig
rob@77 31 * Dual licensed under the MIT or GPL Version 2 licenses.
rob@77 32 * http://jquery.org/license
rob@77 33 *
rob@77 34 * Includes Sizzle.js
rob@77 35 * http://sizzlejs.com/
rob@77 36 * Copyright 2011, The Dojo Foundation
rob@77 37 * Released under the MIT, BSD, and GPL Licenses.
rob@77 38 *
rob@77 39 * Date: Wed Mar 21 12:46:34 2012 -0700
rob@77 40 */
rob@77 41 (function( window, undefined ) {
rob@77 42
rob@77 43 // Use the correct document accordingly with window argument (sandbox)
rob@77 44 var document = window.document,
rob@77 45 navigator = window.navigator,
rob@77 46 location = window.location;
rob@77 47 var jQuery = (function() {
rob@77 48
rob@77 49 // Define a local copy of jQuery
rob@77 50 var jQuery = function( selector, context ) {
rob@77 51 // The jQuery object is actually just the init constructor 'enhanced'
rob@77 52 return new jQuery.fn.init( selector, context, rootjQuery );
rob@77 53 },
rob@77 54
rob@77 55 // Map over jQuery in case of overwrite
rob@77 56 _jQuery = window.jQuery,
rob@77 57
rob@77 58 // Map over the $ in case of overwrite
rob@77 59 _$ = window.$,
rob@77 60
rob@77 61 // A central reference to the root jQuery(document)
rob@77 62 rootjQuery,
rob@77 63
rob@77 64 // A simple way to check for HTML strings or ID strings
rob@77 65 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
rob@77 66 quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
rob@77 67
rob@77 68 // Check if a string has a non-whitespace character in it
rob@77 69 rnotwhite = /\S/,
rob@77 70
rob@77 71 // Used for trimming whitespace
rob@77 72 trimLeft = /^\s+/,
rob@77 73 trimRight = /\s+$/,
rob@77 74
rob@77 75 // Match a standalone tag
rob@77 76 rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
rob@77 77
rob@77 78 // JSON RegExp
rob@77 79 rvalidchars = /^[\],:{}\s]*$/,
rob@77 80 rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
rob@77 81 rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
rob@77 82 rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
rob@77 83
rob@77 84 // Useragent RegExp
rob@77 85 rwebkit = /(webkit)[ \/]([\w.]+)/,
rob@77 86 ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
rob@77 87 rmsie = /(msie) ([\w.]+)/,
rob@77 88 rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
rob@77 89
rob@77 90 // Matches dashed string for camelizing
rob@77 91 rdashAlpha = /-([a-z]|[0-9])/ig,
rob@77 92 rmsPrefix = /^-ms-/,
rob@77 93
rob@77 94 // Used by jQuery.camelCase as callback to replace()
rob@77 95 fcamelCase = function( all, letter ) {
rob@77 96 return ( letter + "" ).toUpperCase();
rob@77 97 },
rob@77 98
rob@77 99 // Keep a UserAgent string for use with jQuery.browser
rob@77 100 userAgent = navigator.userAgent,
rob@77 101
rob@77 102 // For matching the engine and version of the browser
rob@77 103 browserMatch,
rob@77 104
rob@77 105 // The deferred used on DOM ready
rob@77 106 readyList,
rob@77 107
rob@77 108 // The ready event handler
rob@77 109 DOMContentLoaded,
rob@77 110
rob@77 111 // Save a reference to some core methods
rob@77 112 toString = Object.prototype.toString,
rob@77 113 hasOwn = Object.prototype.hasOwnProperty,
rob@77 114 push = Array.prototype.push,
rob@77 115 slice = Array.prototype.slice,
rob@77 116 trim = String.prototype.trim,
rob@77 117 indexOf = Array.prototype.indexOf,
rob@77 118
rob@77 119 // [[Class]] -> type pairs
rob@77 120 class2type = {};
rob@77 121
rob@77 122 jQuery.fn = jQuery.prototype = {
rob@77 123 constructor: jQuery,
rob@77 124 init: function( selector, context, rootjQuery ) {
rob@77 125 var match, elem, ret, doc;
rob@77 126
rob@77 127 // Handle $(""), $(null), or $(undefined)
rob@77 128 if ( !selector ) {
rob@77 129 return this;
rob@77 130 }
rob@77 131
rob@77 132 // Handle $(DOMElement)
rob@77 133 if ( selector.nodeType ) {
rob@77 134 this.context = this[0] = selector;
rob@77 135 this.length = 1;
rob@77 136 return this;
rob@77 137 }
rob@77 138
rob@77 139 // The body element only exists once, optimize finding it
rob@77 140 if ( selector === "body" && !context && document.body ) {
rob@77 141 this.context = document;
rob@77 142 this[0] = document.body;
rob@77 143 this.selector = selector;
rob@77 144 this.length = 1;
rob@77 145 return this;
rob@77 146 }
rob@77 147
rob@77 148 // Handle HTML strings
rob@77 149 if ( typeof selector === "string" ) {
rob@77 150 // Are we dealing with HTML string or an ID?
rob@77 151 if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
rob@77 152 // Assume that strings that start and end with <> are HTML and skip the regex check
rob@77 153 match = [ null, selector, null ];
rob@77 154
rob@77 155 } else {
rob@77 156 match = quickExpr.exec( selector );
rob@77 157 }
rob@77 158
rob@77 159 // Verify a match, and that no context was specified for #id
rob@77 160 if ( match && (match[1] || !context) ) {
rob@77 161
rob@77 162 // HANDLE: $(html) -> $(array)
rob@77 163 if ( match[1] ) {
rob@77 164 context = context instanceof jQuery ? context[0] : context;
rob@77 165 doc = ( context ? context.ownerDocument || context : document );
rob@77 166
rob@77 167 // If a single string is passed in and it's a single tag
rob@77 168 // just do a createElement and skip the rest
rob@77 169 ret = rsingleTag.exec( selector );
rob@77 170
rob@77 171 if ( ret ) {
rob@77 172 if ( jQuery.isPlainObject( context ) ) {
rob@77 173 selector = [ document.createElement( ret[1] ) ];
rob@77 174 jQuery.fn.attr.call( selector, context, true );
rob@77 175
rob@77 176 } else {
rob@77 177 selector = [ doc.createElement( ret[1] ) ];
rob@77 178 }
rob@77 179
rob@77 180 } else {
rob@77 181 ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
rob@77 182 selector = ( ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment ).childNodes;
rob@77 183 }
rob@77 184
rob@77 185 return jQuery.merge( this, selector );
rob@77 186
rob@77 187 // HANDLE: $("#id")
rob@77 188 } else {
rob@77 189 elem = document.getElementById( match[2] );
rob@77 190
rob@77 191 // Check parentNode to catch when Blackberry 4.6 returns
rob@77 192 // nodes that are no longer in the document #6963
rob@77 193 if ( elem && elem.parentNode ) {
rob@77 194 // Handle the case where IE and Opera return items
rob@77 195 // by name instead of ID
rob@77 196 if ( elem.id !== match[2] ) {
rob@77 197 return rootjQuery.find( selector );
rob@77 198 }
rob@77 199
rob@77 200 // Otherwise, we inject the element directly into the jQuery object
rob@77 201 this.length = 1;
rob@77 202 this[0] = elem;
rob@77 203 }
rob@77 204
rob@77 205 this.context = document;
rob@77 206 this.selector = selector;
rob@77 207 return this;
rob@77 208 }
rob@77 209
rob@77 210 // HANDLE: $(expr, $(...))
rob@77 211 } else if ( !context || context.jquery ) {
rob@77 212 return ( context || rootjQuery ).find( selector );
rob@77 213
rob@77 214 // HANDLE: $(expr, context)
rob@77 215 // (which is just equivalent to: $(context).find(expr)
rob@77 216 } else {
rob@77 217 return this.constructor( context ).find( selector );
rob@77 218 }
rob@77 219
rob@77 220 // HANDLE: $(function)
rob@77 221 // Shortcut for document ready
rob@77 222 } else if ( jQuery.isFunction( selector ) ) {
rob@77 223 return rootjQuery.ready( selector );
rob@77 224 }
rob@77 225
rob@77 226 if ( selector.selector !== undefined ) {
rob@77 227 this.selector = selector.selector;
rob@77 228 this.context = selector.context;
rob@77 229 }
rob@77 230
rob@77 231 return jQuery.makeArray( selector, this );
rob@77 232 },
rob@77 233
rob@77 234 // Start with an empty selector
rob@77 235 selector: "",
rob@77 236
rob@77 237 // The current version of jQuery being used
rob@77 238 jquery: "1.7.2",
rob@77 239
rob@77 240 // The default length of a jQuery object is 0
rob@77 241 length: 0,
rob@77 242
rob@77 243 // The number of elements contained in the matched element set
rob@77 244 size: function() {
rob@77 245 return this.length;
rob@77 246 },
rob@77 247
rob@77 248 toArray: function() {
rob@77 249 return slice.call( this, 0 );
rob@77 250 },
rob@77 251
rob@77 252 // Get the Nth element in the matched element set OR
rob@77 253 // Get the whole matched element set as a clean array
rob@77 254 get: function( num ) {
rob@77 255 return num == null ?
rob@77 256
rob@77 257 // Return a 'clean' array
rob@77 258 this.toArray() :
rob@77 259
rob@77 260 // Return just the object
rob@77 261 ( num < 0 ? this[ this.length + num ] : this[ num ] );
rob@77 262 },
rob@77 263
rob@77 264 // Take an array of elements and push it onto the stack
rob@77 265 // (returning the new matched element set)
rob@77 266 pushStack: function( elems, name, selector ) {
rob@77 267 // Build a new jQuery matched element set
rob@77 268 var ret = this.constructor();
rob@77 269
rob@77 270 if ( jQuery.isArray( elems ) ) {
rob@77 271 push.apply( ret, elems );
rob@77 272
rob@77 273 } else {
rob@77 274 jQuery.merge( ret, elems );
rob@77 275 }
rob@77 276
rob@77 277 // Add the old object onto the stack (as a reference)
rob@77 278 ret.prevObject = this;
rob@77 279
rob@77 280 ret.context = this.context;
rob@77 281
rob@77 282 if ( name === "find" ) {
rob@77 283 ret.selector = this.selector + ( this.selector ? " " : "" ) + selector;
rob@77 284 } else if ( name ) {
rob@77 285 ret.selector = this.selector + "." + name + "(" + selector + ")";
rob@77 286 }
rob@77 287
rob@77 288 // Return the newly-formed element set
rob@77 289 return ret;
rob@77 290 },
rob@77 291
rob@77 292 // Execute a callback for every element in the matched set.
rob@77 293 // (You can seed the arguments with an array of args, but this is
rob@77 294 // only used internally.)
rob@77 295 each: function( callback, args ) {
rob@77 296 return jQuery.each( this, callback, args );
rob@77 297 },
rob@77 298
rob@77 299 ready: function( fn ) {
rob@77 300 // Attach the listeners
rob@77 301 jQuery.bindReady();
rob@77 302
rob@77 303 // Add the callback
rob@77 304 readyList.add( fn );
rob@77 305
rob@77 306 return this;
rob@77 307 },
rob@77 308
rob@77 309 eq: function( i ) {
rob@77 310 i = +i;
rob@77 311 return i === -1 ?
rob@77 312 this.slice( i ) :
rob@77 313 this.slice( i, i + 1 );
rob@77 314 },
rob@77 315
rob@77 316 first: function() {
rob@77 317 return this.eq( 0 );
rob@77 318 },
rob@77 319
rob@77 320 last: function() {
rob@77 321 return this.eq( -1 );
rob@77 322 },
rob@77 323
rob@77 324 slice: function() {
rob@77 325 return this.pushStack( slice.apply( this, arguments ),
rob@77 326 "slice", slice.call(arguments).join(",") );
rob@77 327 },
rob@77 328
rob@77 329 map: function( callback ) {
rob@77 330 return this.pushStack( jQuery.map(this, function( elem, i ) {
rob@77 331 return callback.call( elem, i, elem );
rob@77 332 }));
rob@77 333 },
rob@77 334
rob@77 335 end: function() {
rob@77 336 return this.prevObject || this.constructor(null);
rob@77 337 },
rob@77 338
rob@77 339 // For internal use only.
rob@77 340 // Behaves like an Array's method, not like a jQuery method.
rob@77 341 push: push,
rob@77 342 sort: [].sort,
rob@77 343 splice: [].splice
rob@77 344 };
rob@77 345
rob@77 346 // Give the init function the jQuery prototype for later instantiation
rob@77 347 jQuery.fn.init.prototype = jQuery.fn;
rob@77 348
rob@77 349 jQuery.extend = jQuery.fn.extend = function() {
rob@77 350 var options, name, src, copy, copyIsArray, clone,
rob@77 351 target = arguments[0] || {},
rob@77 352 i = 1,
rob@77 353 length = arguments.length,
rob@77 354 deep = false;
rob@77 355
rob@77 356 // Handle a deep copy situation
rob@77 357 if ( typeof target === "boolean" ) {
rob@77 358 deep = target;
rob@77 359 target = arguments[1] || {};
rob@77 360 // skip the boolean and the target
rob@77 361 i = 2;
rob@77 362 }
rob@77 363
rob@77 364 // Handle case when target is a string or something (possible in deep copy)
rob@77 365 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
rob@77 366 target = {};
rob@77 367 }
rob@77 368
rob@77 369 // extend jQuery itself if only one argument is passed
rob@77 370 if ( length === i ) {
rob@77 371 target = this;
rob@77 372 --i;
rob@77 373 }
rob@77 374
rob@77 375 for ( ; i < length; i++ ) {
rob@77 376 // Only deal with non-null/undefined values
rob@77 377 if ( (options = arguments[ i ]) != null ) {
rob@77 378 // Extend the base object
rob@77 379 for ( name in options ) {
rob@77 380 src = target[ name ];
rob@77 381 copy = options[ name ];
rob@77 382
rob@77 383 // Prevent never-ending loop
rob@77 384 if ( target === copy ) {
rob@77 385 continue;
rob@77 386 }
rob@77 387
rob@77 388 // Recurse if we're merging plain objects or arrays
rob@77 389 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
rob@77 390 if ( copyIsArray ) {
rob@77 391 copyIsArray = false;
rob@77 392 clone = src && jQuery.isArray(src) ? src : [];
rob@77 393
rob@77 394 } else {
rob@77 395 clone = src && jQuery.isPlainObject(src) ? src : {};
rob@77 396 }
rob@77 397
rob@77 398 // Never move original objects, clone them
rob@77 399 target[ name ] = jQuery.extend( deep, clone, copy );
rob@77 400
rob@77 401 // Don't bring in undefined values
rob@77 402 } else if ( copy !== undefined ) {
rob@77 403 target[ name ] = copy;
rob@77 404 }
rob@77 405 }
rob@77 406 }
rob@77 407 }
rob@77 408
rob@77 409 // Return the modified object
rob@77 410 return target;
rob@77 411 };
rob@77 412
rob@77 413 jQuery.extend({
rob@77 414 noConflict: function( deep ) {
rob@77 415 if ( window.$ === jQuery ) {
rob@77 416 window.$ = _$;
rob@77 417 }
rob@77 418
rob@77 419 if ( deep && window.jQuery === jQuery ) {
rob@77 420 window.jQuery = _jQuery;
rob@77 421 }
rob@77 422
rob@77 423 return jQuery;
rob@77 424 },
rob@77 425
rob@77 426 // Is the DOM ready to be used? Set to true once it occurs.
rob@77 427 isReady: false,
rob@77 428
rob@77 429 // A counter to track how many items to wait for before
rob@77 430 // the ready event fires. See #6781
rob@77 431 readyWait: 1,
rob@77 432
rob@77 433 // Hold (or release) the ready event
rob@77 434 holdReady: function( hold ) {
rob@77 435 if ( hold ) {
rob@77 436 jQuery.readyWait++;
rob@77 437 } else {
rob@77 438 jQuery.ready( true );
rob@77 439 }
rob@77 440 },
rob@77 441
rob@77 442 // Handle when the DOM is ready
rob@77 443 ready: function( wait ) {
rob@77 444 // Either a released hold or an DOMready/load event and not yet ready
rob@77 445 if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
rob@77 446 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
rob@77 447 if ( !document.body ) {
rob@77 448 return setTimeout( jQuery.ready, 1 );
rob@77 449 }
rob@77 450
rob@77 451 // Remember that the DOM is ready
rob@77 452 jQuery.isReady = true;
rob@77 453
rob@77 454 // If a normal DOM Ready event fired, decrement, and wait if need be
rob@77 455 if ( wait !== true && --jQuery.readyWait > 0 ) {
rob@77 456 return;
rob@77 457 }
rob@77 458
rob@77 459 // If there are functions bound, to execute
rob@77 460 readyList.fireWith( document, [ jQuery ] );
rob@77 461
rob@77 462 // Trigger any bound ready events
rob@77 463 if ( jQuery.fn.trigger ) {
rob@77 464 jQuery( document ).trigger( "ready" ).off( "ready" );
rob@77 465 }
rob@77 466 }
rob@77 467 },
rob@77 468
rob@77 469 bindReady: function() {
rob@77 470 if ( readyList ) {
rob@77 471 return;
rob@77 472 }
rob@77 473
rob@77 474 readyList = jQuery.Callbacks( "once memory" );
rob@77 475
rob@77 476 // Catch cases where $(document).ready() is called after the
rob@77 477 // browser event has already occurred.
rob@77 478 if ( document.readyState === "complete" ) {
rob@77 479 // Handle it asynchronously to allow scripts the opportunity to delay ready
rob@77 480 return setTimeout( jQuery.ready, 1 );
rob@77 481 }
rob@77 482
rob@77 483 // Mozilla, Opera and webkit nightlies currently support this event
rob@77 484 if ( document.addEventListener ) {
rob@77 485 // Use the handy event callback
rob@77 486 document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
rob@77 487
rob@77 488 // A fallback to window.onload, that will always work
rob@77 489 window.addEventListener( "load", jQuery.ready, false );
rob@77 490
rob@77 491 // If IE event model is used
rob@77 492 } else if ( document.attachEvent ) {
rob@77 493 // ensure firing before onload,
rob@77 494 // maybe late but safe also for iframes
rob@77 495 document.attachEvent( "onreadystatechange", DOMContentLoaded );
rob@77 496
rob@77 497 // A fallback to window.onload, that will always work
rob@77 498 window.attachEvent( "onload", jQuery.ready );
rob@77 499
rob@77 500 // If IE and not a frame
rob@77 501 // continually check to see if the document is ready
rob@77 502 var toplevel = false;
rob@77 503
rob@77 504 try {
rob@77 505 toplevel = window.frameElement == null;
rob@77 506 } catch(e) {}
rob@77 507
rob@77 508 if ( document.documentElement.doScroll && toplevel ) {
rob@77 509 doScrollCheck();
rob@77 510 }
rob@77 511 }
rob@77 512 },
rob@77 513
rob@77 514 // See test/unit/core.js for details concerning isFunction.
rob@77 515 // Since version 1.3, DOM methods and functions like alert
rob@77 516 // aren't supported. They return false on IE (#2968).
rob@77 517 isFunction: function( obj ) {
rob@77 518 return jQuery.type(obj) === "function";
rob@77 519 },
rob@77 520
rob@77 521 isArray: Array.isArray || function( obj ) {
rob@77 522 return jQuery.type(obj) === "array";
rob@77 523 },
rob@77 524
rob@77 525 isWindow: function( obj ) {
rob@77 526 return obj != null && obj == obj.window;
rob@77 527 },
rob@77 528
rob@77 529 isNumeric: function( obj ) {
rob@77 530 return !isNaN( parseFloat(obj) ) && isFinite( obj );
rob@77 531 },
rob@77 532
rob@77 533 type: function( obj ) {
rob@77 534 return obj == null ?
rob@77 535 String( obj ) :
rob@77 536 class2type[ toString.call(obj) ] || "object";
rob@77 537 },
rob@77 538
rob@77 539 isPlainObject: function( obj ) {
rob@77 540 // Must be an Object.
rob@77 541 // Because of IE, we also have to check the presence of the constructor property.
rob@77 542 // Make sure that DOM nodes and window objects don't pass through, as well
rob@77 543 if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
rob@77 544 return false;
rob@77 545 }
rob@77 546
rob@77 547 try {
rob@77 548 // Not own constructor property must be Object
rob@77 549 if ( obj.constructor &&
rob@77 550 !hasOwn.call(obj, "constructor") &&
rob@77 551 !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
rob@77 552 return false;
rob@77 553 }
rob@77 554 } catch ( e ) {
rob@77 555 // IE8,9 Will throw exceptions on certain host objects #9897
rob@77 556 return false;
rob@77 557 }
rob@77 558
rob@77 559 // Own properties are enumerated firstly, so to speed up,
rob@77 560 // if last one is own, then all properties are own.
rob@77 561
rob@77 562 var key;
rob@77 563 for ( key in obj ) {}
rob@77 564
rob@77 565 return key === undefined || hasOwn.call( obj, key );
rob@77 566 },
rob@77 567
rob@77 568 isEmptyObject: function( obj ) {
rob@77 569 for ( var name in obj ) {
rob@77 570 return false;
rob@77 571 }
rob@77 572 return true;
rob@77 573 },
rob@77 574
rob@77 575 error: function( msg ) {
rob@77 576 throw new Error( msg );
rob@77 577 },
rob@77 578
rob@77 579 parseJSON: function( data ) {
rob@77 580 if ( typeof data !== "string" || !data ) {
rob@77 581 return null;
rob@77 582 }
rob@77 583
rob@77 584 // Make sure leading/trailing whitespace is removed (IE can't handle it)
rob@77 585 data = jQuery.trim( data );
rob@77 586
rob@77 587 // Attempt to parse using the native JSON parser first
rob@77 588 if ( window.JSON && window.JSON.parse ) {
rob@77 589 return window.JSON.parse( data );
rob@77 590 }
rob@77 591
rob@77 592 // Make sure the incoming data is actual JSON
rob@77 593 // Logic borrowed from http://json.org/json2.js
rob@77 594 if ( rvalidchars.test( data.replace( rvalidescape, "@" )
rob@77 595 .replace( rvalidtokens, "]" )
rob@77 596 .replace( rvalidbraces, "")) ) {
rob@77 597
rob@77 598 return ( new Function( "return " + data ) )();
rob@77 599
rob@77 600 }
rob@77 601 jQuery.error( "Invalid JSON: " + data );
rob@77 602 },
rob@77 603
rob@77 604 // Cross-browser xml parsing
rob@77 605 parseXML: function( data ) {
rob@77 606 if ( typeof data !== "string" || !data ) {
rob@77 607 return null;
rob@77 608 }
rob@77 609 var xml, tmp;
rob@77 610 try {
rob@77 611 if ( window.DOMParser ) { // Standard
rob@77 612 tmp = new DOMParser();
rob@77 613 xml = tmp.parseFromString( data , "text/xml" );
rob@77 614 } else { // IE
rob@77 615 xml = new ActiveXObject( "Microsoft.XMLDOM" );
rob@77 616 xml.async = "false";
rob@77 617 xml.loadXML( data );
rob@77 618 }
rob@77 619 } catch( e ) {
rob@77 620 xml = undefined;
rob@77 621 }
rob@77 622 if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
rob@77 623 jQuery.error( "Invalid XML: " + data );
rob@77 624 }
rob@77 625 return xml;
rob@77 626 },
rob@77 627
rob@77 628 noop: function() {},
rob@77 629
rob@77 630 // Evaluates a script in a global context
rob@77 631 // Workarounds based on findings by Jim Driscoll
rob@77 632 // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
rob@77 633 globalEval: function( data ) {
rob@77 634 if ( data && rnotwhite.test( data ) ) {
rob@77 635 // We use execScript on Internet Explorer
rob@77 636 // We use an anonymous function so that context is window
rob@77 637 // rather than jQuery in Firefox
rob@77 638 ( window.execScript || function( data ) {
rob@77 639 window[ "eval" ].call( window, data );
rob@77 640 } )( data );
rob@77 641 }
rob@77 642 },
rob@77 643
rob@77 644 // Convert dashed to camelCase; used by the css and data modules
rob@77 645 // Microsoft forgot to hump their vendor prefix (#9572)
rob@77 646 camelCase: function( string ) {
rob@77 647 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
rob@77 648 },
rob@77 649
rob@77 650 nodeName: function( elem, name ) {
rob@77 651 return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
rob@77 652 },
rob@77 653
rob@77 654 // args is for internal usage only
rob@77 655 each: function( object, callback, args ) {
rob@77 656 var name, i = 0,
rob@77 657 length = object.length,
rob@77 658 isObj = length === undefined || jQuery.isFunction( object );
rob@77 659
rob@77 660 if ( args ) {
rob@77 661 if ( isObj ) {
rob@77 662 for ( name in object ) {
rob@77 663 if ( callback.apply( object[ name ], args ) === false ) {
rob@77 664 break;
rob@77 665 }
rob@77 666 }
rob@77 667 } else {
rob@77 668 for ( ; i < length; ) {
rob@77 669 if ( callback.apply( object[ i++ ], args ) === false ) {
rob@77 670 break;
rob@77 671 }
rob@77 672 }
rob@77 673 }
rob@77 674
rob@77 675 // A special, fast, case for the most common use of each
rob@77 676 } else {
rob@77 677 if ( isObj ) {
rob@77 678 for ( name in object ) {
rob@77 679 if ( callback.call( object[ name ], name, object[ name ] ) === false ) {
rob@77 680 break;
rob@77 681 }
rob@77 682 }
rob@77 683 } else {
rob@77 684 for ( ; i < length; ) {
rob@77 685 if ( callback.call( object[ i ], i, object[ i++ ] ) === false ) {
rob@77 686 break;
rob@77 687 }
rob@77 688 }
rob@77 689 }
rob@77 690 }
rob@77 691
rob@77 692 return object;
rob@77 693 },
rob@77 694
rob@77 695 // Use native String.trim function wherever possible
rob@77 696 trim: trim ?
rob@77 697 function( text ) {
rob@77 698 return text == null ?
rob@77 699 "" :
rob@77 700 trim.call( text );
rob@77 701 } :
rob@77 702
rob@77 703 // Otherwise use our own trimming functionality
rob@77 704 function( text ) {
rob@77 705 return text == null ?
rob@77 706 "" :
rob@77 707 text.toString().replace( trimLeft, "" ).replace( trimRight, "" );
rob@77 708 },
rob@77 709
rob@77 710 // results is for internal usage only
rob@77 711 makeArray: function( array, results ) {
rob@77 712 var ret = results || [];
rob@77 713
rob@77 714 if ( array != null ) {
rob@77 715 // The window, strings (and functions) also have 'length'
rob@77 716 // Tweaked logic slightly to handle Blackberry 4.7 RegExp issues #6930
rob@77 717 var type = jQuery.type( array );
rob@77 718
rob@77 719 if ( array.length == null || type === "string" || type === "function" || type === "regexp" || jQuery.isWindow( array ) ) {
rob@77 720 push.call( ret, array );
rob@77 721 } else {
rob@77 722 jQuery.merge( ret, array );
rob@77 723 }
rob@77 724 }
rob@77 725
rob@77 726 return ret;
rob@77 727 },
rob@77 728
rob@77 729 inArray: function( elem, array, i ) {
rob@77 730 var len;
rob@77 731
rob@77 732 if ( array ) {
rob@77 733 if ( indexOf ) {
rob@77 734 return indexOf.call( array, elem, i );
rob@77 735 }
rob@77 736
rob@77 737 len = array.length;
rob@77 738 i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
rob@77 739
rob@77 740 for ( ; i < len; i++ ) {
rob@77 741 // Skip accessing in sparse arrays
rob@77 742 if ( i in array && array[ i ] === elem ) {
rob@77 743 return i;
rob@77 744 }
rob@77 745 }
rob@77 746 }
rob@77 747
rob@77 748 return -1;
rob@77 749 },
rob@77 750
rob@77 751 merge: function( first, second ) {
rob@77 752 var i = first.length,
rob@77 753 j = 0;
rob@77 754
rob@77 755 if ( typeof second.length === "number" ) {
rob@77 756 for ( var l = second.length; j < l; j++ ) {
rob@77 757 first[ i++ ] = second[ j ];
rob@77 758 }
rob@77 759
rob@77 760 } else {
rob@77 761 while ( second[j] !== undefined ) {
rob@77 762 first[ i++ ] = second[ j++ ];
rob@77 763 }
rob@77 764 }
rob@77 765
rob@77 766 first.length = i;
rob@77 767
rob@77 768 return first;
rob@77 769 },
rob@77 770
rob@77 771 grep: function( elems, callback, inv ) {
rob@77 772 var ret = [], retVal;
rob@77 773 inv = !!inv;
rob@77 774
rob@77 775 // Go through the array, only saving the items
rob@77 776 // that pass the validator function
rob@77 777 for ( var i = 0, length = elems.length; i < length; i++ ) {
rob@77 778 retVal = !!callback( elems[ i ], i );
rob@77 779 if ( inv !== retVal ) {
rob@77 780 ret.push( elems[ i ] );
rob@77 781 }
rob@77 782 }
rob@77 783
rob@77 784 return ret;
rob@77 785 },
rob@77 786
rob@77 787 // arg is for internal usage only
rob@77 788 map: function( elems, callback, arg ) {
rob@77 789 var value, key, ret = [],
rob@77 790 i = 0,
rob@77 791 length = elems.length,
rob@77 792 // jquery objects are treated as arrays
rob@77 793 isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) ) ;
rob@77 794
rob@77 795 // Go through the array, translating each of the items to their
rob@77 796 if ( isArray ) {
rob@77 797 for ( ; i < length; i++ ) {
rob@77 798 value = callback( elems[ i ], i, arg );
rob@77 799
rob@77 800 if ( value != null ) {
rob@77 801 ret[ ret.length ] = value;
rob@77 802 }
rob@77 803 }
rob@77 804
rob@77 805 // Go through every key on the object,
rob@77 806 } else {
rob@77 807 for ( key in elems ) {
rob@77 808 value = callback( elems[ key ], key, arg );
rob@77 809
rob@77 810 if ( value != null ) {
rob@77 811 ret[ ret.length ] = value;
rob@77 812 }
rob@77 813 }
rob@77 814 }
rob@77 815
rob@77 816 // Flatten any nested arrays
rob@77 817 return ret.concat.apply( [], ret );
rob@77 818 },
rob@77 819
rob@77 820 // A global GUID counter for objects
rob@77 821 guid: 1,
rob@77 822
rob@77 823 // Bind a function to a context, optionally partially applying any
rob@77 824 // arguments.
rob@77 825 proxy: function( fn, context ) {
rob@77 826 if ( typeof context === "string" ) {
rob@77 827 var tmp = fn[ context ];
rob@77 828 context = fn;
rob@77 829 fn = tmp;
rob@77 830 }
rob@77 831
rob@77 832 // Quick check to determine if target is callable, in the spec
rob@77 833 // this throws a TypeError, but we will just return undefined.
rob@77 834 if ( !jQuery.isFunction( fn ) ) {
rob@77 835 return undefined;
rob@77 836 }
rob@77 837
rob@77 838 // Simulated bind
rob@77 839 var args = slice.call( arguments, 2 ),
rob@77 840 proxy = function() {
rob@77 841 return fn.apply( context, args.concat( slice.call( arguments ) ) );
rob@77 842 };
rob@77 843
rob@77 844 // Set the guid of unique handler to the same of original handler, so it can be removed
rob@77 845 proxy.guid = fn.guid = fn.guid || proxy.guid || jQuery.guid++;
rob@77 846
rob@77 847 return proxy;
rob@77 848 },
rob@77 849
rob@77 850 // Mutifunctional method to get and set values to a collection
rob@77 851 // The value/s can optionally be executed if it's a function
rob@77 852 access: function( elems, fn, key, value, chainable, emptyGet, pass ) {
rob@77 853 var exec,
rob@77 854 bulk = key == null,
rob@77 855 i = 0,
rob@77 856 length = elems.length;
rob@77 857
rob@77 858 // Sets many values
rob@77 859 if ( key && typeof key === "object" ) {
rob@77 860 for ( i in key ) {
rob@77 861 jQuery.access( elems, fn, i, key[i], 1, emptyGet, value );
rob@77 862 }
rob@77 863 chainable = 1;
rob@77 864
rob@77 865 // Sets one value
rob@77 866 } else if ( value !== undefined ) {
rob@77 867 // Optionally, function values get executed if exec is true
rob@77 868 exec = pass === undefined && jQuery.isFunction( value );
rob@77 869
rob@77 870 if ( bulk ) {
rob@77 871 // Bulk operations only iterate when executing function values
rob@77 872 if ( exec ) {
rob@77 873 exec = fn;
rob@77 874 fn = function( elem, key, value ) {
rob@77 875 return exec.call( jQuery( elem ), value );
rob@77 876 };
rob@77 877
rob@77 878 // Otherwise they run against the entire set
rob@77 879 } else {
rob@77 880 fn.call( elems, value );
rob@77 881 fn = null;
rob@77 882 }
rob@77 883 }
rob@77 884
rob@77 885 if ( fn ) {
rob@77 886 for (; i < length; i++ ) {
rob@77 887 fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
rob@77 888 }
rob@77 889 }
rob@77 890
rob@77 891 chainable = 1;
rob@77 892 }
rob@77 893
rob@77 894 return chainable ?
rob@77 895 elems :
rob@77 896
rob@77 897 // Gets
rob@77 898 bulk ?
rob@77 899 fn.call( elems ) :
rob@77 900 length ? fn( elems[0], key ) : emptyGet;
rob@77 901 },
rob@77 902
rob@77 903 now: function() {
rob@77 904 return ( new Date() ).getTime();
rob@77 905 },
rob@77 906
rob@77 907 // Use of jQuery.browser is frowned upon.
rob@77 908 // More details: http://docs.jquery.com/Utilities/jQuery.browser
rob@77 909 uaMatch: function( ua ) {
rob@77 910 ua = ua.toLowerCase();
rob@77 911
rob@77 912 var match = rwebkit.exec( ua ) ||
rob@77 913 ropera.exec( ua ) ||
rob@77 914 rmsie.exec( ua ) ||
rob@77 915 ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) ||
rob@77 916 [];
rob@77 917
rob@77 918 return { browser: match[1] || "", version: match[2] || "0" };
rob@77 919 },
rob@77 920
rob@77 921 sub: function() {
rob@77 922 function jQuerySub( selector, context ) {
rob@77 923 return new jQuerySub.fn.init( selector, context );
rob@77 924 }
rob@77 925 jQuery.extend( true, jQuerySub, this );
rob@77 926 jQuerySub.superclass = this;
rob@77 927 jQuerySub.fn = jQuerySub.prototype = this();
rob@77 928 jQuerySub.fn.constructor = jQuerySub;
rob@77 929 jQuerySub.sub = this.sub;
rob@77 930 jQuerySub.fn.init = function init( selector, context ) {
rob@77 931 if ( context && context instanceof jQuery && !(context instanceof jQuerySub) ) {
rob@77 932 context = jQuerySub( context );
rob@77 933 }
rob@77 934
rob@77 935 return jQuery.fn.init.call( this, selector, context, rootjQuerySub );
rob@77 936 };
rob@77 937 jQuerySub.fn.init.prototype = jQuerySub.fn;
rob@77 938 var rootjQuerySub = jQuerySub(document);
rob@77 939 return jQuerySub;
rob@77 940 },
rob@77 941
rob@77 942 browser: {}
rob@77 943 });
rob@77 944
rob@77 945 // Populate the class2type map
rob@77 946 jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
rob@77 947 class2type[ "[object " + name + "]" ] = name.toLowerCase();
rob@77 948 });
rob@77 949
rob@77 950 browserMatch = jQuery.uaMatch( userAgent );
rob@77 951 if ( browserMatch.browser ) {
rob@77 952 jQuery.browser[ browserMatch.browser ] = true;
rob@77 953 jQuery.browser.version = browserMatch.version;
rob@77 954 }
rob@77 955
rob@77 956 // Deprecated, use jQuery.browser.webkit instead
rob@77 957 if ( jQuery.browser.webkit ) {
rob@77 958 jQuery.browser.safari = true;
rob@77 959 }
rob@77 960
rob@77 961 // IE doesn't match non-breaking spaces with \s
rob@77 962 if ( rnotwhite.test( "\xA0" ) ) {
rob@77 963 trimLeft = /^[\s\xA0]+/;
rob@77 964 trimRight = /[\s\xA0]+$/;
rob@77 965 }
rob@77 966
rob@77 967 // All jQuery objects should point back to these
rob@77 968 rootjQuery = jQuery(document);
rob@77 969
rob@77 970 // Cleanup functions for the document ready method
rob@77 971 if ( document.addEventListener ) {
rob@77 972 DOMContentLoaded = function() {
rob@77 973 document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
rob@77 974 jQuery.ready();
rob@77 975 };
rob@77 976
rob@77 977 } else if ( document.attachEvent ) {
rob@77 978 DOMContentLoaded = function() {
rob@77 979 // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
rob@77 980 if ( document.readyState === "complete" ) {
rob@77 981 document.detachEvent( "onreadystatechange", DOMContentLoaded );
rob@77 982 jQuery.ready();
rob@77 983 }
rob@77 984 };
rob@77 985 }
rob@77 986
rob@77 987 // The DOM ready check for Internet Explorer
rob@77 988 function doScrollCheck() {
rob@77 989 if ( jQuery.isReady ) {
rob@77 990 return;
rob@77 991 }
rob@77 992
rob@77 993 try {
rob@77 994 // If IE is used, use the trick by Diego Perini
rob@77 995 // http://javascript.nwbox.com/IEContentLoaded/
rob@77 996 document.documentElement.doScroll("left");
rob@77 997 } catch(e) {
rob@77 998 setTimeout( doScrollCheck, 1 );
rob@77 999 return;
rob@77 1000 }
rob@77 1001
rob@77 1002 // and execute any waiting functions
rob@77 1003 jQuery.ready();
rob@77 1004 }
rob@77 1005
rob@77 1006 return jQuery;
rob@77 1007
rob@77 1008 })();
rob@77 1009
rob@77 1010
rob@77 1011 // String to Object flags format cache
rob@77 1012 var flagsCache = {};
rob@77 1013
rob@77 1014 // Convert String-formatted flags into Object-formatted ones and store in cache
rob@77 1015 function createFlags( flags ) {
rob@77 1016 var object = flagsCache[ flags ] = {},
rob@77 1017 i, length;
rob@77 1018 flags = flags.split( /\s+/ );
rob@77 1019 for ( i = 0, length = flags.length; i < length; i++ ) {
rob@77 1020 object[ flags[i] ] = true;
rob@77 1021 }
rob@77 1022 return object;
rob@77 1023 }
rob@77 1024
rob@77 1025 /*
rob@77 1026 * Create a callback list using the following parameters:
rob@77 1027 *
rob@77 1028 * flags: an optional list of space-separated flags that will change how
rob@77 1029 * the callback list behaves
rob@77 1030 *
rob@77 1031 * By default a callback list will act like an event callback list and can be
rob@77 1032 * "fired" multiple times.
rob@77 1033 *
rob@77 1034 * Possible flags:
rob@77 1035 *
rob@77 1036 * once: will ensure the callback list can only be fired once (like a Deferred)
rob@77 1037 *
rob@77 1038 * memory: will keep track of previous values and will call any callback added
rob@77 1039 * after the list has been fired right away with the latest "memorized"
rob@77 1040 * values (like a Deferred)
rob@77 1041 *
rob@77 1042 * unique: will ensure a callback can only be added once (no duplicate in the list)
rob@77 1043 *
rob@77 1044 * stopOnFalse: interrupt callings when a callback returns false
rob@77 1045 *
rob@77 1046 */
rob@77 1047 jQuery.Callbacks = function( flags ) {
rob@77 1048
rob@77 1049 // Convert flags from String-formatted to Object-formatted
rob@77 1050 // (we check in cache first)
rob@77 1051 flags = flags ? ( flagsCache[ flags ] || createFlags( flags ) ) : {};
rob@77 1052
rob@77 1053 var // Actual callback list
rob@77 1054 list = [],
rob@77 1055 // Stack of fire calls for repeatable lists
rob@77 1056 stack = [],
rob@77 1057 // Last fire value (for non-forgettable lists)
rob@77 1058 memory,
rob@77 1059 // Flag to know if list was already fired
rob@77 1060 fired,
rob@77 1061 // Flag to know if list is currently firing
rob@77 1062 firing,
rob@77 1063 // First callback to fire (used internally by add and fireWith)
rob@77 1064 firingStart,
rob@77 1065 // End of the loop when firing
rob@77 1066 firingLength,
rob@77 1067 // Index of currently firing callback (modified by remove if needed)
rob@77 1068 firingIndex,
rob@77 1069 // Add one or several callbacks to the list
rob@77 1070 add = function( args ) {
rob@77 1071 var i,
rob@77 1072 length,
rob@77 1073 elem,
rob@77 1074 type,
rob@77 1075 actual;
rob@77 1076 for ( i = 0, length = args.length; i < length; i++ ) {
rob@77 1077 elem = args[ i ];
rob@77 1078 type = jQuery.type( elem );
rob@77 1079 if ( type === "array" ) {
rob@77 1080 // Inspect recursively
rob@77 1081 add( elem );
rob@77 1082 } else if ( type === "function" ) {
rob@77 1083 // Add if not in unique mode and callback is not in
rob@77 1084 if ( !flags.unique || !self.has( elem ) ) {
rob@77 1085 list.push( elem );
rob@77 1086 }
rob@77 1087 }
rob@77 1088 }
rob@77 1089 },
rob@77 1090 // Fire callbacks
rob@77 1091 fire = function( context, args ) {
rob@77 1092 args = args || [];
rob@77 1093 memory = !flags.memory || [ context, args ];
rob@77 1094 fired = true;
rob@77 1095 firing = true;
rob@77 1096 firingIndex = firingStart || 0;
rob@77 1097 firingStart = 0;
rob@77 1098 firingLength = list.length;
rob@77 1099 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
rob@77 1100 if ( list[ firingIndex ].apply( context, args ) === false && flags.stopOnFalse ) {
rob@77 1101 memory = true; // Mark as halted
rob@77 1102 break;
rob@77 1103 }
rob@77 1104 }
rob@77 1105 firing = false;
rob@77 1106 if ( list ) {
rob@77 1107 if ( !flags.once ) {
rob@77 1108 if ( stack && stack.length ) {
rob@77 1109 memory = stack.shift();
rob@77 1110 self.fireWith( memory[ 0 ], memory[ 1 ] );
rob@77 1111 }
rob@77 1112 } else if ( memory === true ) {
rob@77 1113 self.disable();
rob@77 1114 } else {
rob@77 1115 list = [];
rob@77 1116 }
rob@77 1117 }
rob@77 1118 },
rob@77 1119 // Actual Callbacks object
rob@77 1120 self = {
rob@77 1121 // Add a callback or a collection of callbacks to the list
rob@77 1122 add: function() {
rob@77 1123 if ( list ) {
rob@77 1124 var length = list.length;
rob@77 1125 add( arguments );
rob@77 1126 // Do we need to add the callbacks to the
rob@77 1127 // current firing batch?
rob@77 1128 if ( firing ) {
rob@77 1129 firingLength = list.length;
rob@77 1130 // With memory, if we're not firing then
rob@77 1131 // we should call right away, unless previous
rob@77 1132 // firing was halted (stopOnFalse)
rob@77 1133 } else if ( memory && memory !== true ) {
rob@77 1134 firingStart = length;
rob@77 1135 fire( memory[ 0 ], memory[ 1 ] );
rob@77 1136 }
rob@77 1137 }
rob@77 1138 return this;
rob@77 1139 },
rob@77 1140 // Remove a callback from the list
rob@77 1141 remove: function() {
rob@77 1142 if ( list ) {
rob@77 1143 var args = arguments,
rob@77 1144 argIndex = 0,
rob@77 1145 argLength = args.length;
rob@77 1146 for ( ; argIndex < argLength ; argIndex++ ) {
rob@77 1147 for ( var i = 0; i < list.length; i++ ) {
rob@77 1148 if ( args[ argIndex ] === list[ i ] ) {
rob@77 1149 // Handle firingIndex and firingLength
rob@77 1150 if ( firing ) {
rob@77 1151 if ( i <= firingLength ) {
rob@77 1152 firingLength--;
rob@77 1153 if ( i <= firingIndex ) {
rob@77 1154 firingIndex--;
rob@77 1155 }
rob@77 1156 }
rob@77 1157 }
rob@77 1158 // Remove the element
rob@77 1159 list.splice( i--, 1 );
rob@77 1160 // If we have some unicity property then
rob@77 1161 // we only need to do this once
rob@77 1162 if ( flags.unique ) {
rob@77 1163 break;
rob@77 1164 }
rob@77 1165 }
rob@77 1166 }
rob@77 1167 }
rob@77 1168 }
rob@77 1169 return this;
rob@77 1170 },
rob@77 1171 // Control if a given callback is in the list
rob@77 1172 has: function( fn ) {
rob@77 1173 if ( list ) {
rob@77 1174 var i = 0,
rob@77 1175 length = list.length;
rob@77 1176 for ( ; i < length; i++ ) {
rob@77 1177 if ( fn === list[ i ] ) {
rob@77 1178 return true;
rob@77 1179 }
rob@77 1180 }
rob@77 1181 }
rob@77 1182 return false;
rob@77 1183 },
rob@77 1184 // Remove all callbacks from the list
rob@77 1185 empty: function() {
rob@77 1186 list = [];
rob@77 1187 return this;
rob@77 1188 },
rob@77 1189 // Have the list do nothing anymore
rob@77 1190 disable: function() {
rob@77 1191 list = stack = memory = undefined;
rob@77 1192 return this;
rob@77 1193 },
rob@77 1194 // Is it disabled?
rob@77 1195 disabled: function() {
rob@77 1196 return !list;
rob@77 1197 },
rob@77 1198 // Lock the list in its current state
rob@77 1199 lock: function() {
rob@77 1200 stack = undefined;
rob@77 1201 if ( !memory || memory === true ) {
rob@77 1202 self.disable();
rob@77 1203 }
rob@77 1204 return this;
rob@77 1205 },
rob@77 1206 // Is it locked?
rob@77 1207 locked: function() {
rob@77 1208 return !stack;
rob@77 1209 },
rob@77 1210 // Call all callbacks with the given context and arguments
rob@77 1211 fireWith: function( context, args ) {
rob@77 1212 if ( stack ) {
rob@77 1213 if ( firing ) {
rob@77 1214 if ( !flags.once ) {
rob@77 1215 stack.push( [ context, args ] );
rob@77 1216 }
rob@77 1217 } else if ( !( flags.once && memory ) ) {
rob@77 1218 fire( context, args );
rob@77 1219 }
rob@77 1220 }
rob@77 1221 return this;
rob@77 1222 },
rob@77 1223 // Call all the callbacks with the given arguments
rob@77 1224 fire: function() {
rob@77 1225 self.fireWith( this, arguments );
rob@77 1226 return this;
rob@77 1227 },
rob@77 1228 // To know if the callbacks have already been called at least once
rob@77 1229 fired: function() {
rob@77 1230 return !!fired;
rob@77 1231 }
rob@77 1232 };
rob@77 1233
rob@77 1234 return self;
rob@77 1235 };
rob@77 1236
rob@77 1237
rob@77 1238
rob@77 1239
rob@77 1240 var // Static reference to slice
rob@77 1241 sliceDeferred = [].slice;
rob@77 1242
rob@77 1243 jQuery.extend({
rob@77 1244
rob@77 1245 Deferred: function( func ) {
rob@77 1246 var doneList = jQuery.Callbacks( "once memory" ),
rob@77 1247 failList = jQuery.Callbacks( "once memory" ),
rob@77 1248 progressList = jQuery.Callbacks( "memory" ),
rob@77 1249 state = "pending",
rob@77 1250 lists = {
rob@77 1251 resolve: doneList,
rob@77 1252 reject: failList,
rob@77 1253 notify: progressList
rob@77 1254 },
rob@77 1255 promise = {
rob@77 1256 done: doneList.add,
rob@77 1257 fail: failList.add,
rob@77 1258 progress: progressList.add,
rob@77 1259
rob@77 1260 state: function() {
rob@77 1261 return state;
rob@77 1262 },
rob@77 1263
rob@77 1264 // Deprecated
rob@77 1265 isResolved: doneList.fired,
rob@77 1266 isRejected: failList.fired,
rob@77 1267
rob@77 1268 then: function( doneCallbacks, failCallbacks, progressCallbacks ) {
rob@77 1269 deferred.done( doneCallbacks ).fail( failCallbacks ).progress( progressCallbacks );
rob@77 1270 return this;
rob@77 1271 },
rob@77 1272 always: function() {
rob@77 1273 deferred.done.apply( deferred, arguments ).fail.apply( deferred, arguments );
rob@77 1274 return this;
rob@77 1275 },
rob@77 1276 pipe: function( fnDone, fnFail, fnProgress ) {
rob@77 1277 return jQuery.Deferred(function( newDefer ) {
rob@77 1278 jQuery.each( {
rob@77 1279 done: [ fnDone, "resolve" ],
rob@77 1280 fail: [ fnFail, "reject" ],
rob@77 1281 progress: [ fnProgress, "notify" ]
rob@77 1282 }, function( handler, data ) {
rob@77 1283 var fn = data[ 0 ],
rob@77 1284 action = data[ 1 ],
rob@77 1285 returned;
rob@77 1286 if ( jQuery.isFunction( fn ) ) {
rob@77 1287 deferred[ handler ](function() {
rob@77 1288 returned = fn.apply( this, arguments );
rob@77 1289 if ( returned && jQuery.isFunction( returned.promise ) ) {
rob@77 1290 returned.promise().then( newDefer.resolve, newDefer.reject, newDefer.notify );
rob@77 1291 } else {
rob@77 1292 newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
rob@77 1293 }
rob@77 1294 });
rob@77 1295 } else {
rob@77 1296 deferred[ handler ]( newDefer[ action ] );
rob@77 1297 }
rob@77 1298 });
rob@77 1299 }).promise();
rob@77 1300 },
rob@77 1301 // Get a promise for this deferred
rob@77 1302 // If obj is provided, the promise aspect is added to the object
rob@77 1303 promise: function( obj ) {
rob@77 1304 if ( obj == null ) {
rob@77 1305 obj = promise;
rob@77 1306 } else {
rob@77 1307 for ( var key in promise ) {
rob@77 1308 obj[ key ] = promise[ key ];
rob@77 1309 }
rob@77 1310 }
rob@77 1311 return obj;
rob@77 1312 }
rob@77 1313 },
rob@77 1314 deferred = promise.promise({}),
rob@77 1315 key;
rob@77 1316
rob@77 1317 for ( key in lists ) {
rob@77 1318 deferred[ key ] = lists[ key ].fire;
rob@77 1319 deferred[ key + "With" ] = lists[ key ].fireWith;
rob@77 1320 }
rob@77 1321
rob@77 1322 // Handle state
rob@77 1323 deferred.done( function() {
rob@77 1324 state = "resolved";
rob@77 1325 }, failList.disable, progressList.lock ).fail( function() {
rob@77 1326 state = "rejected";
rob@77 1327 }, doneList.disable, progressList.lock );
rob@77 1328
rob@77 1329 // Call given func if any
rob@77 1330 if ( func ) {
rob@77 1331 func.call( deferred, deferred );
rob@77 1332 }
rob@77 1333
rob@77 1334 // All done!
rob@77 1335 return deferred;
rob@77 1336 },
rob@77 1337
rob@77 1338 // Deferred helper
rob@77 1339 when: function( firstParam ) {
rob@77 1340 var args = sliceDeferred.call( arguments, 0 ),
rob@77 1341 i = 0,
rob@77 1342 length = args.length,
rob@77 1343 pValues = new Array( length ),
rob@77 1344 count = length,
rob@77 1345 pCount = length,
rob@77 1346 deferred = length <= 1 && firstParam && jQuery.isFunction( firstParam.promise ) ?
rob@77 1347 firstParam :
rob@77 1348 jQuery.Deferred(),
rob@77 1349 promise = deferred.promise();
rob@77 1350 function resolveFunc( i ) {
rob@77 1351 return function( value ) {
rob@77 1352 args[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
rob@77 1353 if ( !( --count ) ) {
rob@77 1354 deferred.resolveWith( deferred, args );
rob@77 1355 }
rob@77 1356 };
rob@77 1357 }
rob@77 1358 function progressFunc( i ) {
rob@77 1359 return function( value ) {
rob@77 1360 pValues[ i ] = arguments.length > 1 ? sliceDeferred.call( arguments, 0 ) : value;
rob@77 1361 deferred.notifyWith( promise, pValues );
rob@77 1362 };
rob@77 1363 }
rob@77 1364 if ( length > 1 ) {
rob@77 1365 for ( ; i < length; i++ ) {
rob@77 1366 if ( args[ i ] && args[ i ].promise && jQuery.isFunction( args[ i ].promise ) ) {
rob@77 1367 args[ i ].promise().then( resolveFunc(i), deferred.reject, progressFunc(i) );
rob@77 1368 } else {
rob@77 1369 --count;
rob@77 1370 }
rob@77 1371 }
rob@77 1372 if ( !count ) {
rob@77 1373 deferred.resolveWith( deferred, args );
rob@77 1374 }
rob@77 1375 } else if ( deferred !== firstParam ) {
rob@77 1376 deferred.resolveWith( deferred, length ? [ firstParam ] : [] );
rob@77 1377 }
rob@77 1378 return promise;
rob@77 1379 }
rob@77 1380 });
rob@77 1381
rob@77 1382
rob@77 1383
rob@77 1384
rob@77 1385 jQuery.support = (function() {
rob@77 1386
rob@77 1387 var support,
rob@77 1388 all,
rob@77 1389 a,
rob@77 1390 select,
rob@77 1391 opt,
rob@77 1392 input,
rob@77 1393 fragment,
rob@77 1394 tds,
rob@77 1395 events,
rob@77 1396 eventName,
rob@77 1397 i,
rob@77 1398 isSupported,
rob@77 1399 div = document.createElement( "div" ),
rob@77 1400 documentElement = document.documentElement;
rob@77 1401
rob@77 1402 // Preliminary tests
rob@77 1403 div.setAttribute("className", "t");
rob@77 1404 div.innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
rob@77 1405
rob@77 1406 all = div.getElementsByTagName( "*" );
rob@77 1407 a = div.getElementsByTagName( "a" )[ 0 ];
rob@77 1408
rob@77 1409 // Can't get basic test support
rob@77 1410 if ( !all || !all.length || !a ) {
rob@77 1411 return {};
rob@77 1412 }
rob@77 1413
rob@77 1414 // First batch of supports tests
rob@77 1415 select = document.createElement( "select" );
rob@77 1416 opt = select.appendChild( document.createElement("option") );
rob@77 1417 input = div.getElementsByTagName( "input" )[ 0 ];
rob@77 1418
rob@77 1419 support = {
rob@77 1420 // IE strips leading whitespace when .innerHTML is used
rob@77 1421 leadingWhitespace: ( div.firstChild.nodeType === 3 ),
rob@77 1422
rob@77 1423 // Make sure that tbody elements aren't automatically inserted
rob@77 1424 // IE will insert them into empty tables
rob@77 1425 tbody: !div.getElementsByTagName("tbody").length,
rob@77 1426
rob@77 1427 // Make sure that link elements get serialized correctly by innerHTML
rob@77 1428 // This requires a wrapper element in IE
rob@77 1429 htmlSerialize: !!div.getElementsByTagName("link").length,
rob@77 1430
rob@77 1431 // Get the style information from getAttribute
rob@77 1432 // (IE uses .cssText instead)
rob@77 1433 style: /top/.test( a.getAttribute("style") ),
rob@77 1434
rob@77 1435 // Make sure that URLs aren't manipulated
rob@77 1436 // (IE normalizes it by default)
rob@77 1437 hrefNormalized: ( a.getAttribute("href") === "/a" ),
rob@77 1438
rob@77 1439 // Make sure that element opacity exists
rob@77 1440 // (IE uses filter instead)
rob@77 1441 // Use a regex to work around a WebKit issue. See #5145
rob@77 1442 opacity: /^0.55/.test( a.style.opacity ),
rob@77 1443
rob@77 1444 // Verify style float existence
rob@77 1445 // (IE uses styleFloat instead of cssFloat)
rob@77 1446 cssFloat: !!a.style.cssFloat,
rob@77 1447
rob@77 1448 // Make sure that if no value is specified for a checkbox
rob@77 1449 // that it defaults to "on".
rob@77 1450 // (WebKit defaults to "" instead)
rob@77 1451 checkOn: ( input.value === "on" ),
rob@77 1452
rob@77 1453 // Make sure that a selected-by-default option has a working selected property.
rob@77 1454 // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
rob@77 1455 optSelected: opt.selected,
rob@77 1456
rob@77 1457 // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
rob@77 1458 getSetAttribute: div.className !== "t",
rob@77 1459
rob@77 1460 // Tests for enctype support on a form(#6743)
rob@77 1461 enctype: !!document.createElement("form").enctype,
rob@77 1462
rob@77 1463 // Makes sure cloning an html5 element does not cause problems
rob@77 1464 // Where outerHTML is undefined, this still works
rob@77 1465 html5Clone: document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>",
rob@77 1466
rob@77 1467 // Will be defined later
rob@77 1468 submitBubbles: true,
rob@77 1469 changeBubbles: true,
rob@77 1470 focusinBubbles: false,
rob@77 1471 deleteExpando: true,
rob@77 1472 noCloneEvent: true,
rob@77 1473 inlineBlockNeedsLayout: false,
rob@77 1474 shrinkWrapBlocks: false,
rob@77 1475 reliableMarginRight: true,
rob@77 1476 pixelMargin: true
rob@77 1477 };
rob@77 1478
rob@77 1479 // jQuery.boxModel DEPRECATED in 1.3, use jQuery.support.boxModel instead
rob@77 1480 jQuery.boxModel = support.boxModel = (document.compatMode === "CSS1Compat");
rob@77 1481
rob@77 1482 // Make sure checked status is properly cloned
rob@77 1483 input.checked = true;
rob@77 1484 support.noCloneChecked = input.cloneNode( true ).checked;
rob@77 1485
rob@77 1486 // Make sure that the options inside disabled selects aren't marked as disabled
rob@77 1487 // (WebKit marks them as disabled)
rob@77 1488 select.disabled = true;
rob@77 1489 support.optDisabled = !opt.disabled;
rob@77 1490
rob@77 1491 // Test to see if it's possible to delete an expando from an element
rob@77 1492 // Fails in Internet Explorer
rob@77 1493 try {
rob@77 1494 delete div.test;
rob@77 1495 } catch( e ) {
rob@77 1496 support.deleteExpando = false;
rob@77 1497 }
rob@77 1498
rob@77 1499 if ( !div.addEventListener && div.attachEvent && div.fireEvent ) {
rob@77 1500 div.attachEvent( "onclick", function() {
rob@77 1501 // Cloning a node shouldn't copy over any
rob@77 1502 // bound event handlers (IE does this)
rob@77 1503 support.noCloneEvent = false;
rob@77 1504 });
rob@77 1505 div.cloneNode( true ).fireEvent( "onclick" );
rob@77 1506 }
rob@77 1507
rob@77 1508 // Check if a radio maintains its value
rob@77 1509 // after being appended to the DOM
rob@77 1510 input = document.createElement("input");
rob@77 1511 input.value = "t";
rob@77 1512 input.setAttribute("type", "radio");
rob@77 1513 support.radioValue = input.value === "t";
rob@77 1514
rob@77 1515 input.setAttribute("checked", "checked");
rob@77 1516
rob@77 1517 // #11217 - WebKit loses check when the name is after the checked attribute
rob@77 1518 input.setAttribute( "name", "t" );
rob@77 1519
rob@77 1520 div.appendChild( input );
rob@77 1521 fragment = document.createDocumentFragment();
rob@77 1522 fragment.appendChild( div.lastChild );
rob@77 1523
rob@77 1524 // WebKit doesn't clone checked state correctly in fragments
rob@77 1525 support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
rob@77 1526
rob@77 1527 // Check if a disconnected checkbox will retain its checked
rob@77 1528 // value of true after appended to the DOM (IE6/7)
rob@77 1529 support.appendChecked = input.checked;
rob@77 1530
rob@77 1531 fragment.removeChild( input );
rob@77 1532 fragment.appendChild( div );
rob@77 1533
rob@77 1534 // Technique from Juriy Zaytsev
rob@77 1535 // http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
rob@77 1536 // We only care about the case where non-standard event systems
rob@77 1537 // are used, namely in IE. Short-circuiting here helps us to
rob@77 1538 // avoid an eval call (in setAttribute) which can cause CSP
rob@77 1539 // to go haywire. See: https://developer.mozilla.org/en/Security/CSP
rob@77 1540 if ( div.attachEvent ) {
rob@77 1541 for ( i in {
rob@77 1542 submit: 1,
rob@77 1543 change: 1,
rob@77 1544 focusin: 1
rob@77 1545 }) {
rob@77 1546 eventName = "on" + i;
rob@77 1547 isSupported = ( eventName in div );
rob@77 1548 if ( !isSupported ) {
rob@77 1549 div.setAttribute( eventName, "return;" );
rob@77 1550 isSupported = ( typeof div[ eventName ] === "function" );
rob@77 1551 }
rob@77 1552 support[ i + "Bubbles" ] = isSupported;
rob@77 1553 }
rob@77 1554 }
rob@77 1555
rob@77 1556 fragment.removeChild( div );
rob@77 1557
rob@77 1558 // Null elements to avoid leaks in IE
rob@77 1559 fragment = select = opt = div = input = null;
rob@77 1560
rob@77 1561 // Run tests that need a body at doc ready
rob@77 1562 jQuery(function() {
rob@77 1563 var container, outer, inner, table, td, offsetSupport,
rob@77 1564 marginDiv, conMarginTop, style, html, positionTopLeftWidthHeight,
rob@77 1565 paddingMarginBorderVisibility, paddingMarginBorder,
rob@77 1566 body = document.getElementsByTagName("body")[0];
rob@77 1567
rob@77 1568 if ( !body ) {
rob@77 1569 // Return for frameset docs that don't have a body
rob@77 1570 return;
rob@77 1571 }
rob@77 1572
rob@77 1573 conMarginTop = 1;
rob@77 1574 paddingMarginBorder = "padding:0;margin:0;border:";
rob@77 1575 positionTopLeftWidthHeight = "position:absolute;top:0;left:0;width:1px;height:1px;";
rob@77 1576 paddingMarginBorderVisibility = paddingMarginBorder + "0;visibility:hidden;";
rob@77 1577 style = "style='" + positionTopLeftWidthHeight + paddingMarginBorder + "5px solid #000;";
rob@77 1578 html = "<div " + style + "display:block;'><div style='" + paddingMarginBorder + "0;display:block;overflow:hidden;'></div></div>" +
rob@77 1579 "<table " + style + "' cellpadding='0' cellspacing='0'>" +
rob@77 1580 "<tr><td></td></tr></table>";
rob@77 1581
rob@77 1582 container = document.createElement("div");
rob@77 1583 container.style.cssText = paddingMarginBorderVisibility + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px";
rob@77 1584 body.insertBefore( container, body.firstChild );
rob@77 1585
rob@77 1586 // Construct the test element
rob@77 1587 div = document.createElement("div");
rob@77 1588 container.appendChild( div );
rob@77 1589
rob@77 1590 // Check if table cells still have offsetWidth/Height when they are set
rob@77 1591 // to display:none and there are still other visible table cells in a
rob@77 1592 // table row; if so, offsetWidth/Height are not reliable for use when
rob@77 1593 // determining if an element has been hidden directly using
rob@77 1594 // display:none (it is still safe to use offsets if a parent element is
rob@77 1595 // hidden; don safety goggles and see bug #4512 for more information).
rob@77 1596 // (only IE 8 fails this test)
rob@77 1597 div.innerHTML = "<table><tr><td style='" + paddingMarginBorder + "0;display:none'></td><td>t</td></tr></table>";
rob@77 1598 tds = div.getElementsByTagName( "td" );
rob@77 1599 isSupported = ( tds[ 0 ].offsetHeight === 0 );
rob@77 1600
rob@77 1601 tds[ 0 ].style.display = "";
rob@77 1602 tds[ 1 ].style.display = "none";
rob@77 1603
rob@77 1604 // Check if empty table cells still have offsetWidth/Height
rob@77 1605 // (IE <= 8 fail this test)
rob@77 1606 support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
rob@77 1607
rob@77 1608 // Check if div with explicit width and no margin-right incorrectly
rob@77 1609 // gets computed margin-right based on width of container. For more
rob@77 1610 // info see bug #3333
rob@77 1611 // Fails in WebKit before Feb 2011 nightlies
rob@77 1612 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
rob@77 1613 if ( window.getComputedStyle ) {
rob@77 1614 div.innerHTML = "";
rob@77 1615 marginDiv = document.createElement( "div" );
rob@77 1616 marginDiv.style.width = "0";
rob@77 1617 marginDiv.style.marginRight = "0";
rob@77 1618 div.style.width = "2px";
rob@77 1619 div.appendChild( marginDiv );
rob@77 1620 support.reliableMarginRight =
rob@77 1621 ( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
rob@77 1622 }
rob@77 1623
rob@77 1624 if ( typeof div.style.zoom !== "undefined" ) {
rob@77 1625 // Check if natively block-level elements act like inline-block
rob@77 1626 // elements when setting their display to 'inline' and giving
rob@77 1627 // them layout
rob@77 1628 // (IE < 8 does this)
rob@77 1629 div.innerHTML = "";
rob@77 1630 div.style.width = div.style.padding = "1px";
rob@77 1631 div.style.border = 0;
rob@77 1632 div.style.overflow = "hidden";
rob@77 1633 div.style.display = "inline";
rob@77 1634 div.style.zoom = 1;
rob@77 1635 support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 );
rob@77 1636
rob@77 1637 // Check if elements with layout shrink-wrap their children
rob@77 1638 // (IE 6 does this)
rob@77 1639 div.style.display = "block";
rob@77 1640 div.style.overflow = "visible";
rob@77 1641 div.innerHTML = "<div style='width:5px;'></div>";
rob@77 1642 support.shrinkWrapBlocks = ( div.offsetWidth !== 3 );
rob@77 1643 }
rob@77 1644
rob@77 1645 div.style.cssText = positionTopLeftWidthHeight + paddingMarginBorderVisibility;
rob@77 1646 div.innerHTML = html;
rob@77 1647
rob@77 1648 outer = div.firstChild;
rob@77 1649 inner = outer.firstChild;
rob@77 1650 td = outer.nextSibling.firstChild.firstChild;
rob@77 1651
rob@77 1652 offsetSupport = {
rob@77 1653 doesNotAddBorder: ( inner.offsetTop !== 5 ),
rob@77 1654 doesAddBorderForTableAndCells: ( td.offsetTop === 5 )
rob@77 1655 };
rob@77 1656
rob@77 1657 inner.style.position = "fixed";
rob@77 1658 inner.style.top = "20px";
rob@77 1659
rob@77 1660 // safari subtracts parent border width here which is 5px
rob@77 1661 offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 );
rob@77 1662 inner.style.position = inner.style.top = "";
rob@77 1663
rob@77 1664 outer.style.overflow = "hidden";
rob@77 1665 outer.style.position = "relative";
rob@77 1666
rob@77 1667 offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 );
rob@77 1668 offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== conMarginTop );
rob@77 1669
rob@77 1670 if ( window.getComputedStyle ) {
rob@77 1671 div.style.marginTop = "1%";
rob@77 1672 support.pixelMargin = ( window.getComputedStyle( div, null ) || { marginTop: 0 } ).marginTop !== "1%";
rob@77 1673 }
rob@77 1674
rob@77 1675 if ( typeof container.style.zoom !== "undefined" ) {
rob@77 1676 container.style.zoom = 1;
rob@77 1677 }
rob@77 1678
rob@77 1679 body.removeChild( container );
rob@77 1680 marginDiv = div = container = null;
rob@77 1681
rob@77 1682 jQuery.extend( support, offsetSupport );
rob@77 1683 });
rob@77 1684
rob@77 1685 return support;
rob@77 1686 })();
rob@77 1687
rob@77 1688
rob@77 1689
rob@77 1690
rob@77 1691 var rbrace = /^(?:\{.*\}|\[.*\])$/,
rob@77 1692 rmultiDash = /([A-Z])/g;
rob@77 1693
rob@77 1694 jQuery.extend({
rob@77 1695 cache: {},
rob@77 1696
rob@77 1697 // Please use with caution
rob@77 1698 uuid: 0,
rob@77 1699
rob@77 1700 // Unique for each copy of jQuery on the page
rob@77 1701 // Non-digits removed to match rinlinejQuery
rob@77 1702 expando: "jQuery" + ( jQuery.fn.jquery + Math.random() ).replace( /\D/g, "" ),
rob@77 1703
rob@77 1704 // The following elements throw uncatchable exceptions if you
rob@77 1705 // attempt to add expando properties to them.
rob@77 1706 noData: {
rob@77 1707 "embed": true,
rob@77 1708 // Ban all objects except for Flash (which handle expandos)
rob@77 1709 "object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
rob@77 1710 "applet": true
rob@77 1711 },
rob@77 1712
rob@77 1713 hasData: function( elem ) {
rob@77 1714 elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ];
rob@77 1715 return !!elem && !isEmptyDataObject( elem );
rob@77 1716 },
rob@77 1717
rob@77 1718 data: function( elem, name, data, pvt /* Internal Use Only */ ) {
rob@77 1719 if ( !jQuery.acceptData( elem ) ) {
rob@77 1720 return;
rob@77 1721 }
rob@77 1722
rob@77 1723 var privateCache, thisCache, ret,
rob@77 1724 internalKey = jQuery.expando,
rob@77 1725 getByName = typeof name === "string",
rob@77 1726
rob@77 1727 // We have to handle DOM nodes and JS objects differently because IE6-7
rob@77 1728 // can't GC object references properly across the DOM-JS boundary
rob@77 1729 isNode = elem.nodeType,
rob@77 1730
rob@77 1731 // Only DOM nodes need the global jQuery cache; JS object data is
rob@77 1732 // attached directly to the object so GC can occur automatically
rob@77 1733 cache = isNode ? jQuery.cache : elem,
rob@77 1734
rob@77 1735 // Only defining an ID for JS objects if its cache already exists allows
rob@77 1736 // the code to shortcut on the same path as a DOM node with no cache
rob@77 1737 id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey,
rob@77 1738 isEvents = name === "events";
rob@77 1739
rob@77 1740 // Avoid doing any more work than we need to when trying to get data on an
rob@77 1741 // object that has no data at all
rob@77 1742 if ( (!id || !cache[id] || (!isEvents && !pvt && !cache[id].data)) && getByName && data === undefined ) {
rob@77 1743 return;
rob@77 1744 }
rob@77 1745
rob@77 1746 if ( !id ) {
rob@77 1747 // Only DOM nodes need a new unique ID for each element since their data
rob@77 1748 // ends up in the global cache
rob@77 1749 if ( isNode ) {
rob@77 1750 elem[ internalKey ] = id = ++jQuery.uuid;
rob@77 1751 } else {
rob@77 1752 id = internalKey;
rob@77 1753 }
rob@77 1754 }
rob@77 1755
rob@77 1756 if ( !cache[ id ] ) {
rob@77 1757 cache[ id ] = {};
rob@77 1758
rob@77 1759 // Avoids exposing jQuery metadata on plain JS objects when the object
rob@77 1760 // is serialized using JSON.stringify
rob@77 1761 if ( !isNode ) {
rob@77 1762 cache[ id ].toJSON = jQuery.noop;
rob@77 1763 }
rob@77 1764 }
rob@77 1765
rob@77 1766 // An object can be passed to jQuery.data instead of a key/value pair; this gets
rob@77 1767 // shallow copied over onto the existing cache
rob@77 1768 if ( typeof name === "object" || typeof name === "function" ) {
rob@77 1769 if ( pvt ) {
rob@77 1770 cache[ id ] = jQuery.extend( cache[ id ], name );
rob@77 1771 } else {
rob@77 1772 cache[ id ].data = jQuery.extend( cache[ id ].data, name );
rob@77 1773 }
rob@77 1774 }
rob@77 1775
rob@77 1776 privateCache = thisCache = cache[ id ];
rob@77 1777
rob@77 1778 // jQuery data() is stored in a separate object inside the object's internal data
rob@77 1779 // cache in order to avoid key collisions between internal data and user-defined
rob@77 1780 // data.
rob@77 1781 if ( !pvt ) {
rob@77 1782 if ( !thisCache.data ) {
rob@77 1783 thisCache.data = {};
rob@77 1784 }
rob@77 1785
rob@77 1786 thisCache = thisCache.data;
rob@77 1787 }
rob@77 1788
rob@77 1789 if ( data !== undefined ) {
rob@77 1790 thisCache[ jQuery.camelCase( name ) ] = data;
rob@77 1791 }
rob@77 1792
rob@77 1793 // Users should not attempt to inspect the internal events object using jQuery.data,
rob@77 1794 // it is undocumented and subject to change. But does anyone listen? No.
rob@77 1795 if ( isEvents && !thisCache[ name ] ) {
rob@77 1796 return privateCache.events;
rob@77 1797 }
rob@77 1798
rob@77 1799 // Check for both converted-to-camel and non-converted data property names
rob@77 1800 // If a data property was specified
rob@77 1801 if ( getByName ) {
rob@77 1802
rob@77 1803 // First Try to find as-is property data
rob@77 1804 ret = thisCache[ name ];
rob@77 1805
rob@77 1806 // Test for null|undefined property data
rob@77 1807 if ( ret == null ) {
rob@77 1808
rob@77 1809 // Try to find the camelCased property
rob@77 1810 ret = thisCache[ jQuery.camelCase( name ) ];
rob@77 1811 }
rob@77 1812 } else {
rob@77 1813 ret = thisCache;
rob@77 1814 }
rob@77 1815
rob@77 1816 return ret;
rob@77 1817 },
rob@77 1818
rob@77 1819 removeData: function( elem, name, pvt /* Internal Use Only */ ) {
rob@77 1820 if ( !jQuery.acceptData( elem ) ) {
rob@77 1821 return;
rob@77 1822 }
rob@77 1823
rob@77 1824 var thisCache, i, l,
rob@77 1825
rob@77 1826 // Reference to internal data cache key
rob@77 1827 internalKey = jQuery.expando,
rob@77 1828
rob@77 1829 isNode = elem.nodeType,
rob@77 1830
rob@77 1831 // See jQuery.data for more information
rob@77 1832 cache = isNode ? jQuery.cache : elem,
rob@77 1833
rob@77 1834 // See jQuery.data for more information
rob@77 1835 id = isNode ? elem[ internalKey ] : internalKey;
rob@77 1836
rob@77 1837 // If there is already no cache entry for this object, there is no
rob@77 1838 // purpose in continuing
rob@77 1839 if ( !cache[ id ] ) {
rob@77 1840 return;
rob@77 1841 }
rob@77 1842
rob@77 1843 if ( name ) {
rob@77 1844
rob@77 1845 thisCache = pvt ? cache[ id ] : cache[ id ].data;
rob@77 1846
rob@77 1847 if ( thisCache ) {
rob@77 1848
rob@77 1849 // Support array or space separated string names for data keys
rob@77 1850 if ( !jQuery.isArray( name ) ) {
rob@77 1851
rob@77 1852 // try the string as a key before any manipulation
rob@77 1853 if ( name in thisCache ) {
rob@77 1854 name = [ name ];
rob@77 1855 } else {
rob@77 1856
rob@77 1857 // split the camel cased version by spaces unless a key with the spaces exists
rob@77 1858 name = jQuery.camelCase( name );
rob@77 1859 if ( name in thisCache ) {
rob@77 1860 name = [ name ];
rob@77 1861 } else {
rob@77 1862 name = name.split( " " );
rob@77 1863 }
rob@77 1864 }
rob@77 1865 }
rob@77 1866
rob@77 1867 for ( i = 0, l = name.length; i < l; i++ ) {
rob@77 1868 delete thisCache[ name[i] ];
rob@77 1869 }
rob@77 1870
rob@77 1871 // If there is no data left in the cache, we want to continue
rob@77 1872 // and let the cache object itself get destroyed
rob@77 1873 if ( !( pvt ? isEmptyDataObject : jQuery.isEmptyObject )( thisCache ) ) {
rob@77 1874 return;
rob@77 1875 }
rob@77 1876 }
rob@77 1877 }
rob@77 1878
rob@77 1879 // See jQuery.data for more information
rob@77 1880 if ( !pvt ) {
rob@77 1881 delete cache[ id ].data;
rob@77 1882
rob@77 1883 // Don't destroy the parent cache unless the internal data object
rob@77 1884 // had been the only thing left in it
rob@77 1885 if ( !isEmptyDataObject(cache[ id ]) ) {
rob@77 1886 return;
rob@77 1887 }
rob@77 1888 }
rob@77 1889
rob@77 1890 // Browsers that fail expando deletion also refuse to delete expandos on
rob@77 1891 // the window, but it will allow it on all other JS objects; other browsers
rob@77 1892 // don't care
rob@77 1893 // Ensure that `cache` is not a window object #10080
rob@77 1894 if ( jQuery.support.deleteExpando || !cache.setInterval ) {
rob@77 1895 delete cache[ id ];
rob@77 1896 } else {
rob@77 1897 cache[ id ] = null;
rob@77 1898 }
rob@77 1899
rob@77 1900 // We destroyed the cache and need to eliminate the expando on the node to avoid
rob@77 1901 // false lookups in the cache for entries that no longer exist
rob@77 1902 if ( isNode ) {
rob@77 1903 // IE does not allow us to delete expando properties from nodes,
rob@77 1904 // nor does it have a removeAttribute function on Document nodes;
rob@77 1905 // we must handle all of these cases
rob@77 1906 if ( jQuery.support.deleteExpando ) {
rob@77 1907 delete elem[ internalKey ];
rob@77 1908 } else if ( elem.removeAttribute ) {
rob@77 1909 elem.removeAttribute( internalKey );
rob@77 1910 } else {
rob@77 1911 elem[ internalKey ] = null;
rob@77 1912 }
rob@77 1913 }
rob@77 1914 },
rob@77 1915
rob@77 1916 // For internal use only.
rob@77 1917 _data: function( elem, name, data ) {
rob@77 1918 return jQuery.data( elem, name, data, true );
rob@77 1919 },
rob@77 1920
rob@77 1921 // A method for determining if a DOM node can handle the data expando
rob@77 1922 acceptData: function( elem ) {
rob@77 1923 if ( elem.nodeName ) {
rob@77 1924 var match = jQuery.noData[ elem.nodeName.toLowerCase() ];
rob@77 1925
rob@77 1926 if ( match ) {
rob@77 1927 return !(match === true || elem.getAttribute("classid") !== match);
rob@77 1928 }
rob@77 1929 }
rob@77 1930
rob@77 1931 return true;
rob@77 1932 }
rob@77 1933 });
rob@77 1934
rob@77 1935 jQuery.fn.extend({
rob@77 1936 data: function( key, value ) {
rob@77 1937 var parts, part, attr, name, l,
rob@77 1938 elem = this[0],
rob@77 1939 i = 0,
rob@77 1940 data = null;
rob@77 1941
rob@77 1942 // Gets all values
rob@77 1943 if ( key === undefined ) {
rob@77 1944 if ( this.length ) {
rob@77 1945 data = jQuery.data( elem );
rob@77 1946
rob@77 1947 if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) {
rob@77 1948 attr = elem.attributes;
rob@77 1949 for ( l = attr.length; i < l; i++ ) {
rob@77 1950 name = attr[i].name;
rob@77 1951
rob@77 1952 if ( name.indexOf( "data-" ) === 0 ) {
rob@77 1953 name = jQuery.camelCase( name.substring(5) );
rob@77 1954
rob@77 1955 dataAttr( elem, name, data[ name ] );
rob@77 1956 }
rob@77 1957 }
rob@77 1958 jQuery._data( elem, "parsedAttrs", true );
rob@77 1959 }
rob@77 1960 }
rob@77 1961
rob@77 1962 return data;
rob@77 1963 }
rob@77 1964
rob@77 1965 // Sets multiple values
rob@77 1966 if ( typeof key === "object" ) {
rob@77 1967 return this.each(function() {
rob@77 1968 jQuery.data( this, key );
rob@77 1969 });
rob@77 1970 }
rob@77 1971
rob@77 1972 parts = key.split( ".", 2 );
rob@77 1973 parts[1] = parts[1] ? "." + parts[1] : "";
rob@77 1974 part = parts[1] + "!";
rob@77 1975
rob@77 1976 return jQuery.access( this, function( value ) {
rob@77 1977
rob@77 1978 if ( value === undefined ) {
rob@77 1979 data = this.triggerHandler( "getData" + part, [ parts[0] ] );
rob@77 1980
rob@77 1981 // Try to fetch any internally stored data first
rob@77 1982 if ( data === undefined && elem ) {
rob@77 1983 data = jQuery.data( elem, key );
rob@77 1984 data = dataAttr( elem, key, data );
rob@77 1985 }
rob@77 1986
rob@77 1987 return data === undefined && parts[1] ?
rob@77 1988 this.data( parts[0] ) :
rob@77 1989 data;
rob@77 1990 }
rob@77 1991
rob@77 1992 parts[1] = value;
rob@77 1993 this.each(function() {
rob@77 1994 var self = jQuery( this );
rob@77 1995
rob@77 1996 self.triggerHandler( "setData" + part, parts );
rob@77 1997 jQuery.data( this, key, value );
rob@77 1998 self.triggerHandler( "changeData" + part, parts );
rob@77 1999 });
rob@77 2000 }, null, value, arguments.length > 1, null, false );
rob@77 2001 },
rob@77 2002
rob@77 2003 removeData: function( key ) {
rob@77 2004 return this.each(function() {
rob@77 2005 jQuery.removeData( this, key );
rob@77 2006 });
rob@77 2007 }
rob@77 2008 });
rob@77 2009
rob@77 2010 function dataAttr( elem, key, data ) {
rob@77 2011 // If nothing was found internally, try to fetch any
rob@77 2012 // data from the HTML5 data-* attribute
rob@77 2013 if ( data === undefined && elem.nodeType === 1 ) {
rob@77 2014
rob@77 2015 var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
rob@77 2016
rob@77 2017 data = elem.getAttribute( name );
rob@77 2018
rob@77 2019 if ( typeof data === "string" ) {
rob@77 2020 try {
rob@77 2021 data = data === "true" ? true :
rob@77 2022 data === "false" ? false :
rob@77 2023 data === "null" ? null :
rob@77 2024 jQuery.isNumeric( data ) ? +data :
rob@77 2025 rbrace.test( data ) ? jQuery.parseJSON( data ) :
rob@77 2026 data;
rob@77 2027 } catch( e ) {}
rob@77 2028
rob@77 2029 // Make sure we set the data so it isn't changed later
rob@77 2030 jQuery.data( elem, key, data );
rob@77 2031
rob@77 2032 } else {
rob@77 2033 data = undefined;
rob@77 2034 }
rob@77 2035 }
rob@77 2036
rob@77 2037 return data;
rob@77 2038 }
rob@77 2039
rob@77 2040 // checks a cache object for emptiness
rob@77 2041 function isEmptyDataObject( obj ) {
rob@77 2042 for ( var name in obj ) {
rob@77 2043
rob@77 2044 // if the public data object is empty, the private is still empty
rob@77 2045 if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) {
rob@77 2046 continue;
rob@77 2047 }
rob@77 2048 if ( name !== "toJSON" ) {
rob@77 2049 return false;
rob@77 2050 }
rob@77 2051 }
rob@77 2052
rob@77 2053 return true;
rob@77 2054 }
rob@77 2055
rob@77 2056
rob@77 2057
rob@77 2058
rob@77 2059 function handleQueueMarkDefer( elem, type, src ) {
rob@77 2060 var deferDataKey = type + "defer",
rob@77 2061 queueDataKey = type + "queue",
rob@77 2062 markDataKey = type + "mark",
rob@77 2063 defer = jQuery._data( elem, deferDataKey );
rob@77 2064 if ( defer &&
rob@77 2065 ( src === "queue" || !jQuery._data(elem, queueDataKey) ) &&
rob@77 2066 ( src === "mark" || !jQuery._data(elem, markDataKey) ) ) {
rob@77 2067 // Give room for hard-coded callbacks to fire first
rob@77 2068 // and eventually mark/queue something else on the element
rob@77 2069 setTimeout( function() {
rob@77 2070 if ( !jQuery._data( elem, queueDataKey ) &&
rob@77 2071 !jQuery._data( elem, markDataKey ) ) {
rob@77 2072 jQuery.removeData( elem, deferDataKey, true );
rob@77 2073 defer.fire();
rob@77 2074 }
rob@77 2075 }, 0 );
rob@77 2076 }
rob@77 2077 }
rob@77 2078
rob@77 2079 jQuery.extend({
rob@77 2080
rob@77 2081 _mark: function( elem, type ) {
rob@77 2082 if ( elem ) {
rob@77 2083 type = ( type || "fx" ) + "mark";
rob@77 2084 jQuery._data( elem, type, (jQuery._data( elem, type ) || 0) + 1 );
rob@77 2085 }
rob@77 2086 },
rob@77 2087
rob@77 2088 _unmark: function( force, elem, type ) {
rob@77 2089 if ( force !== true ) {
rob@77 2090 type = elem;
rob@77 2091 elem = force;
rob@77 2092 force = false;
rob@77 2093 }
rob@77 2094 if ( elem ) {
rob@77 2095 type = type || "fx";
rob@77 2096 var key = type + "mark",
rob@77 2097 count = force ? 0 : ( (jQuery._data( elem, key ) || 1) - 1 );
rob@77 2098 if ( count ) {
rob@77 2099 jQuery._data( elem, key, count );
rob@77 2100 } else {
rob@77 2101 jQuery.removeData( elem, key, true );
rob@77 2102 handleQueueMarkDefer( elem, type, "mark" );
rob@77 2103 }
rob@77 2104 }
rob@77 2105 },
rob@77 2106
rob@77 2107 queue: function( elem, type, data ) {
rob@77 2108 var q;
rob@77 2109 if ( elem ) {
rob@77 2110 type = ( type || "fx" ) + "queue";
rob@77 2111 q = jQuery._data( elem, type );
rob@77 2112
rob@77 2113 // Speed up dequeue by getting out quickly if this is just a lookup
rob@77 2114 if ( data ) {
rob@77 2115 if ( !q || jQuery.isArray(data) ) {
rob@77 2116 q = jQuery._data( elem, type, jQuery.makeArray(data) );
rob@77 2117 } else {
rob@77 2118 q.push( data );
rob@77 2119 }
rob@77 2120 }
rob@77 2121 return q || [];
rob@77 2122 }
rob@77 2123 },
rob@77 2124
rob@77 2125 dequeue: function( elem, type ) {
rob@77 2126 type = type || "fx";
rob@77 2127
rob@77 2128 var queue = jQuery.queue( elem, type ),
rob@77 2129 fn = queue.shift(),
rob@77 2130 hooks = {};
rob@77 2131
rob@77 2132 // If the fx queue is dequeued, always remove the progress sentinel
rob@77 2133 if ( fn === "inprogress" ) {
rob@77 2134 fn = queue.shift();
rob@77 2135 }
rob@77 2136
rob@77 2137 if ( fn ) {
rob@77 2138 // Add a progress sentinel to prevent the fx queue from being
rob@77 2139 // automatically dequeued
rob@77 2140 if ( type === "fx" ) {
rob@77 2141 queue.unshift( "inprogress" );
rob@77 2142 }
rob@77 2143
rob@77 2144 jQuery._data( elem, type + ".run", hooks );
rob@77 2145 fn.call( elem, function() {
rob@77 2146 jQuery.dequeue( elem, type );
rob@77 2147 }, hooks );
rob@77 2148 }
rob@77 2149
rob@77 2150 if ( !queue.length ) {
rob@77 2151 jQuery.removeData( elem, type + "queue " + type + ".run", true );
rob@77 2152 handleQueueMarkDefer( elem, type, "queue" );
rob@77 2153 }
rob@77 2154 }
rob@77 2155 });
rob@77 2156
rob@77 2157 jQuery.fn.extend({
rob@77 2158 queue: function( type, data ) {
rob@77 2159 var setter = 2;
rob@77 2160
rob@77 2161 if ( typeof type !== "string" ) {
rob@77 2162 data = type;
rob@77 2163 type = "fx";
rob@77 2164 setter--;
rob@77 2165 }
rob@77 2166
rob@77 2167 if ( arguments.length < setter ) {
rob@77 2168 return jQuery.queue( this[0], type );
rob@77 2169 }
rob@77 2170
rob@77 2171 return data === undefined ?
rob@77 2172 this :
rob@77 2173 this.each(function() {
rob@77 2174 var queue = jQuery.queue( this, type, data );
rob@77 2175
rob@77 2176 if ( type === "fx" && queue[0] !== "inprogress" ) {
rob@77 2177 jQuery.dequeue( this, type );
rob@77 2178 }
rob@77 2179 });
rob@77 2180 },
rob@77 2181 dequeue: function( type ) {
rob@77 2182 return this.each(function() {
rob@77 2183 jQuery.dequeue( this, type );
rob@77 2184 });
rob@77 2185 },
rob@77 2186 // Based off of the plugin by Clint Helfers, with permission.
rob@77 2187 // http://blindsignals.com/index.php/2009/07/jquery-delay/
rob@77 2188 delay: function( time, type ) {
rob@77 2189 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
rob@77 2190 type = type || "fx";
rob@77 2191
rob@77 2192 return this.queue( type, function( next, hooks ) {
rob@77 2193 var timeout = setTimeout( next, time );
rob@77 2194 hooks.stop = function() {
rob@77 2195 clearTimeout( timeout );
rob@77 2196 };
rob@77 2197 });
rob@77 2198 },
rob@77 2199 clearQueue: function( type ) {
rob@77 2200 return this.queue( type || "fx", [] );
rob@77 2201 },
rob@77 2202 // Get a promise resolved when queues of a certain type
rob@77 2203 // are emptied (fx is the type by default)
rob@77 2204 promise: function( type, object ) {
rob@77 2205 if ( typeof type !== "string" ) {
rob@77 2206 object = type;
rob@77 2207 type = undefined;
rob@77 2208 }
rob@77 2209 type = type || "fx";
rob@77 2210 var defer = jQuery.Deferred(),
rob@77 2211 elements = this,
rob@77 2212 i = elements.length,
rob@77 2213 count = 1,
rob@77 2214 deferDataKey = type + "defer",
rob@77 2215 queueDataKey = type + "queue",
rob@77 2216 markDataKey = type + "mark",
rob@77 2217 tmp;
rob@77 2218 function resolve() {
rob@77 2219 if ( !( --count ) ) {
rob@77 2220 defer.resolveWith( elements, [ elements ] );
rob@77 2221 }
rob@77 2222 }
rob@77 2223 while( i-- ) {
rob@77 2224 if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
rob@77 2225 ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
rob@77 2226 jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
rob@77 2227 jQuery.data( elements[ i ], deferDataKey, jQuery.Callbacks( "once memory" ), true ) )) {
rob@77 2228 count++;
rob@77 2229 tmp.add( resolve );
rob@77 2230 }
rob@77 2231 }
rob@77 2232 resolve();
rob@77 2233 return defer.promise( object );
rob@77 2234 }
rob@77 2235 });
rob@77 2236
rob@77 2237
rob@77 2238
rob@77 2239
rob@77 2240 var rclass = /[\n\t\r]/g,
rob@77 2241 rspace = /\s+/,
rob@77 2242 rreturn = /\r/g,
rob@77 2243 rtype = /^(?:button|input)$/i,
rob@77 2244 rfocusable = /^(?:button|input|object|select|textarea)$/i,
rob@77 2245 rclickable = /^a(?:rea)?$/i,
rob@77 2246 rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
rob@77 2247 getSetAttribute = jQuery.support.getSetAttribute,
rob@77 2248 nodeHook, boolHook, fixSpecified;
rob@77 2249
rob@77 2250 jQuery.fn.extend({
rob@77 2251 attr: function( name, value ) {
rob@77 2252 return jQuery.access( this, jQuery.attr, name, value, arguments.length > 1 );
rob@77 2253 },
rob@77 2254
rob@77 2255 removeAttr: function( name ) {
rob@77 2256 return this.each(function() {
rob@77 2257 jQuery.removeAttr( this, name );
rob@77 2258 });
rob@77 2259 },
rob@77 2260
rob@77 2261 prop: function( name, value ) {
rob@77 2262 return jQuery.access( this, jQuery.prop, name, value, arguments.length > 1 );
rob@77 2263 },
rob@77 2264
rob@77 2265 removeProp: function( name ) {
rob@77 2266 name = jQuery.propFix[ name ] || name;
rob@77 2267 return this.each(function() {
rob@77 2268 // try/catch handles cases where IE balks (such as removing a property on window)
rob@77 2269 try {
rob@77 2270 this[ name ] = undefined;
rob@77 2271 delete this[ name ];
rob@77 2272 } catch( e ) {}
rob@77 2273 });
rob@77 2274 },
rob@77 2275
rob@77 2276 addClass: function( value ) {
rob@77 2277 var classNames, i, l, elem,
rob@77 2278 setClass, c, cl;
rob@77 2279
rob@77 2280 if ( jQuery.isFunction( value ) ) {
rob@77 2281 return this.each(function( j ) {
rob@77 2282 jQuery( this ).addClass( value.call(this, j, this.className) );
rob@77 2283 });
rob@77 2284 }
rob@77 2285
rob@77 2286 if ( value && typeof value === "string" ) {
rob@77 2287 classNames = value.split( rspace );
rob@77 2288
rob@77 2289 for ( i = 0, l = this.length; i < l; i++ ) {
rob@77 2290 elem = this[ i ];
rob@77 2291
rob@77 2292 if ( elem.nodeType === 1 ) {
rob@77 2293 if ( !elem.className && classNames.length === 1 ) {
rob@77 2294 elem.className = value;
rob@77 2295
rob@77 2296 } else {
rob@77 2297 setClass = " " + elem.className + " ";
rob@77 2298
rob@77 2299 for ( c = 0, cl = classNames.length; c < cl; c++ ) {
rob@77 2300 if ( !~setClass.indexOf( " " + classNames[ c ] + " " ) ) {
rob@77 2301 setClass += classNames[ c ] + " ";
rob@77 2302 }
rob@77 2303 }
rob@77 2304 elem.className = jQuery.trim( setClass );
rob@77 2305 }
rob@77 2306 }
rob@77 2307 }
rob@77 2308 }
rob@77 2309
rob@77 2310 return this;
rob@77 2311 },
rob@77 2312
rob@77 2313 removeClass: function( value ) {
rob@77 2314 var classNames, i, l, elem, className, c, cl;
rob@77 2315
rob@77 2316 if ( jQuery.isFunction( value ) ) {
rob@77 2317 return this.each(function( j ) {
rob@77 2318 jQuery( this ).removeClass( value.call(this, j, this.className) );
rob@77 2319 });
rob@77 2320 }
rob@77 2321
rob@77 2322 if ( (value && typeof value === "string") || value === undefined ) {
rob@77 2323 classNames = ( value || "" ).split( rspace );
rob@77 2324
rob@77 2325 for ( i = 0, l = this.length; i < l; i++ ) {
rob@77 2326 elem = this[ i ];
rob@77 2327
rob@77 2328 if ( elem.nodeType === 1 && elem.className ) {
rob@77 2329 if ( value ) {
rob@77 2330 className = (" " + elem.className + " ").replace( rclass, " " );
rob@77 2331 for ( c = 0, cl = classNames.length; c < cl; c++ ) {
rob@77 2332 className = className.replace(" " + classNames[ c ] + " ", " ");
rob@77 2333 }
rob@77 2334 elem.className = jQuery.trim( className );
rob@77 2335
rob@77 2336 } else {
rob@77 2337 elem.className = "";
rob@77 2338 }
rob@77 2339 }
rob@77 2340 }
rob@77 2341 }
rob@77 2342
rob@77 2343 return this;
rob@77 2344 },
rob@77 2345
rob@77 2346 toggleClass: function( value, stateVal ) {
rob@77 2347 var type = typeof value,
rob@77 2348 isBool = typeof stateVal === "boolean";
rob@77 2349
rob@77 2350 if ( jQuery.isFunction( value ) ) {
rob@77 2351 return this.each(function( i ) {
rob@77 2352 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
rob@77 2353 });
rob@77 2354 }
rob@77 2355
rob@77 2356 return this.each(function() {
rob@77 2357 if ( type === "string" ) {
rob@77 2358 // toggle individual class names
rob@77 2359 var className,
rob@77 2360 i = 0,
rob@77 2361 self = jQuery( this ),
rob@77 2362 state = stateVal,
rob@77 2363 classNames = value.split( rspace );
rob@77 2364
rob@77 2365 while ( (className = classNames[ i++ ]) ) {
rob@77 2366 // check each className given, space seperated list
rob@77 2367 state = isBool ? state : !self.hasClass( className );
rob@77 2368 self[ state ? "addClass" : "removeClass" ]( className );
rob@77 2369 }
rob@77 2370
rob@77 2371 } else if ( type === "undefined" || type === "boolean" ) {
rob@77 2372 if ( this.className ) {
rob@77 2373 // store className if set
rob@77 2374 jQuery._data( this, "__className__", this.className );
rob@77 2375 }
rob@77 2376
rob@77 2377 // toggle whole className
rob@77 2378 this.className = this.className || value === false ? "" : jQuery._data( this, "__className__" ) || "";
rob@77 2379 }
rob@77 2380 });
rob@77 2381 },
rob@77 2382
rob@77 2383 hasClass: function( selector ) {
rob@77 2384 var className = " " + selector + " ",
rob@77 2385 i = 0,
rob@77 2386 l = this.length;
rob@77 2387 for ( ; i < l; i++ ) {
rob@77 2388 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
rob@77 2389 return true;
rob@77 2390 }
rob@77 2391 }
rob@77 2392
rob@77 2393 return false;
rob@77 2394 },
rob@77 2395
rob@77 2396 val: function( value ) {
rob@77 2397 var hooks, ret, isFunction,
rob@77 2398 elem = this[0];
rob@77 2399
rob@77 2400 if ( !arguments.length ) {
rob@77 2401 if ( elem ) {
rob@77 2402 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
rob@77 2403
rob@77 2404 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
rob@77 2405 return ret;
rob@77 2406 }
rob@77 2407
rob@77 2408 ret = elem.value;
rob@77 2409
rob@77 2410 return typeof ret === "string" ?
rob@77 2411 // handle most common string cases
rob@77 2412 ret.replace(rreturn, "") :
rob@77 2413 // handle cases where value is null/undef or number
rob@77 2414 ret == null ? "" : ret;
rob@77 2415 }
rob@77 2416
rob@77 2417 return;
rob@77 2418 }
rob@77 2419
rob@77 2420 isFunction = jQuery.isFunction( value );
rob@77 2421
rob@77 2422 return this.each(function( i ) {
rob@77 2423 var self = jQuery(this), val;
rob@77 2424
rob@77 2425 if ( this.nodeType !== 1 ) {
rob@77 2426 return;
rob@77 2427 }
rob@77 2428
rob@77 2429 if ( isFunction ) {
rob@77 2430 val = value.call( this, i, self.val() );
rob@77 2431 } else {
rob@77 2432 val = value;
rob@77 2433 }
rob@77 2434
rob@77 2435 // Treat null/undefined as ""; convert numbers to string
rob@77 2436 if ( val == null ) {
rob@77 2437 val = "";
rob@77 2438 } else if ( typeof val === "number" ) {
rob@77 2439 val += "";
rob@77 2440 } else if ( jQuery.isArray( val ) ) {
rob@77 2441 val = jQuery.map(val, function ( value ) {
rob@77 2442 return value == null ? "" : value + "";
rob@77 2443 });
rob@77 2444 }
rob@77 2445
rob@77 2446 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
rob@77 2447
rob@77 2448 // If set returns undefined, fall back to normal setting
rob@77 2449 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
rob@77 2450 this.value = val;
rob@77 2451 }
rob@77 2452 });
rob@77 2453 }
rob@77 2454 });
rob@77 2455
rob@77 2456 jQuery.extend({
rob@77 2457 valHooks: {
rob@77 2458 option: {
rob@77 2459 get: function( elem ) {
rob@77 2460 // attributes.value is undefined in Blackberry 4.7 but
rob@77 2461 // uses .value. See #6932
rob@77 2462 var val = elem.attributes.value;
rob@77 2463 return !val || val.specified ? elem.value : elem.text;
rob@77 2464 }
rob@77 2465 },
rob@77 2466 select: {
rob@77 2467 get: function( elem ) {
rob@77 2468 var value, i, max, option,
rob@77 2469 index = elem.selectedIndex,
rob@77 2470 values = [],
rob@77 2471 options = elem.options,
rob@77 2472 one = elem.type === "select-one";
rob@77 2473
rob@77 2474 // Nothing was selected
rob@77 2475 if ( index < 0 ) {
rob@77 2476 return null;
rob@77 2477 }
rob@77 2478
rob@77 2479 // Loop through all the selected options
rob@77 2480 i = one ? index : 0;
rob@77 2481 max = one ? index + 1 : options.length;
rob@77 2482 for ( ; i < max; i++ ) {
rob@77 2483 option = options[ i ];
rob@77 2484
rob@77 2485 // Don't return options that are disabled or in a disabled optgroup
rob@77 2486 if ( option.selected && (jQuery.support.optDisabled ? !option.disabled : option.getAttribute("disabled") === null) &&
rob@77 2487 (!option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" )) ) {
rob@77 2488
rob@77 2489 // Get the specific value for the option
rob@77 2490 value = jQuery( option ).val();
rob@77 2491
rob@77 2492 // We don't need an array for one selects
rob@77 2493 if ( one ) {
rob@77 2494 return value;
rob@77 2495 }
rob@77 2496
rob@77 2497 // Multi-Selects return an array
rob@77 2498 values.push( value );
rob@77 2499 }
rob@77 2500 }
rob@77 2501
rob@77 2502 // Fixes Bug #2551 -- select.val() broken in IE after form.reset()
rob@77 2503 if ( one && !values.length && options.length ) {
rob@77 2504 return jQuery( options[ index ] ).val();
rob@77 2505 }
rob@77 2506
rob@77 2507 return values;
rob@77 2508 },
rob@77 2509
rob@77 2510 set: function( elem, value ) {
rob@77 2511 var values = jQuery.makeArray( value );
rob@77 2512
rob@77 2513 jQuery(elem).find("option").each(function() {
rob@77 2514 this.selected = jQuery.inArray( jQuery(this).val(), values ) >= 0;
rob@77 2515 });
rob@77 2516
rob@77 2517 if ( !values.length ) {
rob@77 2518 elem.selectedIndex = -1;
rob@77 2519 }
rob@77 2520 return values;
rob@77 2521 }
rob@77 2522 }
rob@77 2523 },
rob@77 2524
rob@77 2525 attrFn: {
rob@77 2526 val: true,
rob@77 2527 css: true,
rob@77 2528 html: true,
rob@77 2529 text: true,
rob@77 2530 data: true,
rob@77 2531 width: true,
rob@77 2532 height: true,
rob@77 2533 offset: true
rob@77 2534 },
rob@77 2535
rob@77 2536 attr: function( elem, name, value, pass ) {
rob@77 2537 var ret, hooks, notxml,
rob@77 2538 nType = elem.nodeType;
rob@77 2539
rob@77 2540 // don't get/set attributes on text, comment and attribute nodes
rob@77 2541 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
rob@77 2542 return;
rob@77 2543 }
rob@77 2544
rob@77 2545 if ( pass && name in jQuery.attrFn ) {
rob@77 2546 return jQuery( elem )[ name ]( value );
rob@77 2547 }
rob@77 2548
rob@77 2549 // Fallback to prop when attributes are not supported
rob@77 2550 if ( typeof elem.getAttribute === "undefined" ) {
rob@77 2551 return jQuery.prop( elem, name, value );
rob@77 2552 }
rob@77 2553
rob@77 2554 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
rob@77 2555
rob@77 2556 // All attributes are lowercase
rob@77 2557 // Grab necessary hook if one is defined
rob@77 2558 if ( notxml ) {
rob@77 2559 name = name.toLowerCase();
rob@77 2560 hooks = jQuery.attrHooks[ name ] || ( rboolean.test( name ) ? boolHook : nodeHook );
rob@77 2561 }
rob@77 2562
rob@77 2563 if ( value !== undefined ) {
rob@77 2564
rob@77 2565 if ( value === null ) {
rob@77 2566 jQuery.removeAttr( elem, name );
rob@77 2567 return;
rob@77 2568
rob@77 2569 } else if ( hooks && "set" in hooks && notxml && (ret = hooks.set( elem, value, name )) !== undefined ) {
rob@77 2570 return ret;
rob@77 2571
rob@77 2572 } else {
rob@77 2573 elem.setAttribute( name, "" + value );
rob@77 2574 return value;
rob@77 2575 }
rob@77 2576
rob@77 2577 } else if ( hooks && "get" in hooks && notxml && (ret = hooks.get( elem, name )) !== null ) {
rob@77 2578 return ret;
rob@77 2579
rob@77 2580 } else {
rob@77 2581
rob@77 2582 ret = elem.getAttribute( name );
rob@77 2583
rob@77 2584 // Non-existent attributes return null, we normalize to undefined
rob@77 2585 return ret === null ?
rob@77 2586 undefined :
rob@77 2587 ret;
rob@77 2588 }
rob@77 2589 },
rob@77 2590
rob@77 2591 removeAttr: function( elem, value ) {
rob@77 2592 var propName, attrNames, name, l, isBool,
rob@77 2593 i = 0;
rob@77 2594
rob@77 2595 if ( value && elem.nodeType === 1 ) {
rob@77 2596 attrNames = value.toLowerCase().split( rspace );
rob@77 2597 l = attrNames.length;
rob@77 2598
rob@77 2599 for ( ; i < l; i++ ) {
rob@77 2600 name = attrNames[ i ];
rob@77 2601
rob@77 2602 if ( name ) {
rob@77 2603 propName = jQuery.propFix[ name ] || name;
rob@77 2604 isBool = rboolean.test( name );
rob@77 2605
rob@77 2606 // See #9699 for explanation of this approach (setting first, then removal)
rob@77 2607 // Do not do this for boolean attributes (see #10870)
rob@77 2608 if ( !isBool ) {
rob@77 2609 jQuery.attr( elem, name, "" );
rob@77 2610 }
rob@77 2611 elem.removeAttribute( getSetAttribute ? name : propName );
rob@77 2612
rob@77 2613 // Set corresponding property to false for boolean attributes
rob@77 2614 if ( isBool && propName in elem ) {
rob@77 2615 elem[ propName ] = false;
rob@77 2616 }
rob@77 2617 }
rob@77 2618 }
rob@77 2619 }
rob@77 2620 },
rob@77 2621
rob@77 2622 attrHooks: {
rob@77 2623 type: {
rob@77 2624 set: function( elem, value ) {
rob@77 2625 // We can't allow the type property to be changed (since it causes problems in IE)
rob@77 2626 if ( rtype.test( elem.nodeName ) && elem.parentNode ) {
rob@77 2627 jQuery.error( "type property can't be changed" );
rob@77 2628 } else if ( !jQuery.support.radioValue && value === "radio" && jQuery.nodeName(elem, "input") ) {
rob@77 2629 // Setting the type on a radio button after the value resets the value in IE6-9
rob@77 2630 // Reset value to it's default in case type is set after value
rob@77 2631 // This is for element creation
rob@77 2632 var val = elem.value;
rob@77 2633 elem.setAttribute( "type", value );
rob@77 2634 if ( val ) {
rob@77 2635 elem.value = val;
rob@77 2636 }
rob@77 2637 return value;
rob@77 2638 }
rob@77 2639 }
rob@77 2640 },
rob@77 2641 // Use the value property for back compat
rob@77 2642 // Use the nodeHook for button elements in IE6/7 (#1954)
rob@77 2643 value: {
rob@77 2644 get: function( elem, name ) {
rob@77 2645 if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
rob@77 2646 return nodeHook.get( elem, name );
rob@77 2647 }
rob@77 2648 return name in elem ?
rob@77 2649 elem.value :
rob@77 2650 null;
rob@77 2651 },
rob@77 2652 set: function( elem, value, name ) {
rob@77 2653 if ( nodeHook && jQuery.nodeName( elem, "button" ) ) {
rob@77 2654 return nodeHook.set( elem, value, name );
rob@77 2655 }
rob@77 2656 // Does not return so that setAttribute is also used
rob@77 2657 elem.value = value;
rob@77 2658 }
rob@77 2659 }
rob@77 2660 },
rob@77 2661
rob@77 2662 propFix: {
rob@77 2663 tabindex: "tabIndex",
rob@77 2664 readonly: "readOnly",
rob@77 2665 "for": "htmlFor",
rob@77 2666 "class": "className",
rob@77 2667 maxlength: "maxLength",
rob@77 2668 cellspacing: "cellSpacing",
rob@77 2669 cellpadding: "cellPadding",
rob@77 2670 rowspan: "rowSpan",
rob@77 2671 colspan: "colSpan",
rob@77 2672 usemap: "useMap",
rob@77 2673 frameborder: "frameBorder",
rob@77 2674 contenteditable: "contentEditable"
rob@77 2675 },
rob@77 2676
rob@77 2677 prop: function( elem, name, value ) {
rob@77 2678 var ret, hooks, notxml,
rob@77 2679 nType = elem.nodeType;
rob@77 2680
rob@77 2681 // don't get/set properties on text, comment and attribute nodes
rob@77 2682 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
rob@77 2683 return;
rob@77 2684 }
rob@77 2685
rob@77 2686 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
rob@77 2687
rob@77 2688 if ( notxml ) {
rob@77 2689 // Fix name and attach hooks
rob@77 2690 name = jQuery.propFix[ name ] || name;
rob@77 2691 hooks = jQuery.propHooks[ name ];
rob@77 2692 }
rob@77 2693
rob@77 2694 if ( value !== undefined ) {
rob@77 2695 if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
rob@77 2696 return ret;
rob@77 2697
rob@77 2698 } else {
rob@77 2699 return ( elem[ name ] = value );
rob@77 2700 }
rob@77 2701
rob@77 2702 } else {
rob@77 2703 if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
rob@77 2704 return ret;
rob@77 2705
rob@77 2706 } else {
rob@77 2707 return elem[ name ];
rob@77 2708 }
rob@77 2709 }
rob@77 2710 },
rob@77 2711
rob@77 2712 propHooks: {
rob@77 2713 tabIndex: {
rob@77 2714 get: function( elem ) {
rob@77 2715 // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
rob@77 2716 // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
rob@77 2717 var attributeNode = elem.getAttributeNode("tabindex");
rob@77 2718
rob@77 2719 return attributeNode && attributeNode.specified ?
rob@77 2720 parseInt( attributeNode.value, 10 ) :
rob@77 2721 rfocusable.test( elem.nodeName ) || rclickable.test( elem.nodeName ) && elem.href ?
rob@77 2722 0 :
rob@77 2723 undefined;
rob@77 2724 }
rob@77 2725 }
rob@77 2726 }
rob@77 2727 });
rob@77 2728
rob@77 2729 // Add the tabIndex propHook to attrHooks for back-compat (different case is intentional)
rob@77 2730 jQuery.attrHooks.tabindex = jQuery.propHooks.tabIndex;
rob@77 2731
rob@77 2732 // Hook for boolean attributes
rob@77 2733 boolHook = {
rob@77 2734 get: function( elem, name ) {
rob@77 2735 // Align boolean attributes with corresponding properties
rob@77 2736 // Fall back to attribute presence where some booleans are not supported
rob@77 2737 var attrNode,
rob@77 2738 property = jQuery.prop( elem, name );
rob@77 2739 return property === true || typeof property !== "boolean" && ( attrNode = elem.getAttributeNode(name) ) && attrNode.nodeValue !== false ?
rob@77 2740 name.toLowerCase() :
rob@77 2741 undefined;
rob@77 2742 },
rob@77 2743 set: function( elem, value, name ) {
rob@77 2744 var propName;
rob@77 2745 if ( value === false ) {
rob@77 2746 // Remove boolean attributes when set to false
rob@77 2747 jQuery.removeAttr( elem, name );
rob@77 2748 } else {
rob@77 2749 // value is true since we know at this point it's type boolean and not false
rob@77 2750 // Set boolean attributes to the same name and set the DOM property
rob@77 2751 propName = jQuery.propFix[ name ] || name;
rob@77 2752 if ( propName in elem ) {
rob@77 2753 // Only set the IDL specifically if it already exists on the element
rob@77 2754 elem[ propName ] = true;
rob@77 2755 }
rob@77 2756
rob@77 2757 elem.setAttribute( name, name.toLowerCase() );
rob@77 2758 }
rob@77 2759 return name;
rob@77 2760 }
rob@77 2761 };
rob@77 2762
rob@77 2763 // IE6/7 do not support getting/setting some attributes with get/setAttribute
rob@77 2764 if ( !getSetAttribute ) {
rob@77 2765
rob@77 2766 fixSpecified = {
rob@77 2767 name: true,
rob@77 2768 id: true,
rob@77 2769 coords: true
rob@77 2770 };
rob@77 2771
rob@77 2772 // Use this for any attribute in IE6/7
rob@77 2773 // This fixes almost every IE6/7 issue
rob@77 2774 nodeHook = jQuery.valHooks.button = {
rob@77 2775 get: function( elem, name ) {
rob@77 2776 var ret;
rob@77 2777 ret = elem.getAttributeNode( name );
rob@77 2778 return ret && ( fixSpecified[ name ] ? ret.nodeValue !== "" : ret.specified ) ?
rob@77 2779 ret.nodeValue :
rob@77 2780 undefined;
rob@77 2781 },
rob@77 2782 set: function( elem, value, name ) {
rob@77 2783 // Set the existing or create a new attribute node
rob@77 2784 var ret = elem.getAttributeNode( name );
rob@77 2785 if ( !ret ) {
rob@77 2786 ret = document.createAttribute( name );
rob@77 2787 elem.setAttributeNode( ret );
rob@77 2788 }
rob@77 2789 return ( ret.nodeValue = value + "" );
rob@77 2790 }
rob@77 2791 };
rob@77 2792
rob@77 2793 // Apply the nodeHook to tabindex
rob@77 2794 jQuery.attrHooks.tabindex.set = nodeHook.set;
rob@77 2795
rob@77 2796 // Set width and height to auto instead of 0 on empty string( Bug #8150 )
rob@77 2797 // This is for removals
rob@77 2798 jQuery.each([ "width", "height" ], function( i, name ) {
rob@77 2799 jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
rob@77 2800 set: function( elem, value ) {
rob@77 2801 if ( value === "" ) {
rob@77 2802 elem.setAttribute( name, "auto" );
rob@77 2803 return value;
rob@77 2804 }
rob@77 2805 }
rob@77 2806 });
rob@77 2807 });
rob@77 2808
rob@77 2809 // Set contenteditable to false on removals(#10429)
rob@77 2810 // Setting to empty string throws an error as an invalid value
rob@77 2811 jQuery.attrHooks.contenteditable = {
rob@77 2812 get: nodeHook.get,
rob@77 2813 set: function( elem, value, name ) {
rob@77 2814 if ( value === "" ) {
rob@77 2815 value = "false";
rob@77 2816 }
rob@77 2817 nodeHook.set( elem, value, name );
rob@77 2818 }
rob@77 2819 };
rob@77 2820 }
rob@77 2821
rob@77 2822
rob@77 2823 // Some attributes require a special call on IE
rob@77 2824 if ( !jQuery.support.hrefNormalized ) {
rob@77 2825 jQuery.each([ "href", "src", "width", "height" ], function( i, name ) {
rob@77 2826 jQuery.attrHooks[ name ] = jQuery.extend( jQuery.attrHooks[ name ], {
rob@77 2827 get: function( elem ) {
rob@77 2828 var ret = elem.getAttribute( name, 2 );
rob@77 2829 return ret === null ? undefined : ret;
rob@77 2830 }
rob@77 2831 });
rob@77 2832 });
rob@77 2833 }
rob@77 2834
rob@77 2835 if ( !jQuery.support.style ) {
rob@77 2836 jQuery.attrHooks.style = {
rob@77 2837 get: function( elem ) {
rob@77 2838 // Return undefined in the case of empty string
rob@77 2839 // Normalize to lowercase since IE uppercases css property names
rob@77 2840 return elem.style.cssText.toLowerCase() || undefined;
rob@77 2841 },
rob@77 2842 set: function( elem, value ) {
rob@77 2843 return ( elem.style.cssText = "" + value );
rob@77 2844 }
rob@77 2845 };
rob@77 2846 }
rob@77 2847
rob@77 2848 // Safari mis-reports the default selected property of an option
rob@77 2849 // Accessing the parent's selectedIndex property fixes it
rob@77 2850 if ( !jQuery.support.optSelected ) {
rob@77 2851 jQuery.propHooks.selected = jQuery.extend( jQuery.propHooks.selected, {
rob@77 2852 get: function( elem ) {
rob@77 2853 var parent = elem.parentNode;
rob@77 2854
rob@77 2855 if ( parent ) {
rob@77 2856 parent.selectedIndex;
rob@77 2857
rob@77 2858 // Make sure that it also works with optgroups, see #5701
rob@77 2859 if ( parent.parentNode ) {
rob@77 2860 parent.parentNode.selectedIndex;
rob@77 2861 }
rob@77 2862 }
rob@77 2863 return null;
rob@77 2864 }
rob@77 2865 });
rob@77 2866 }
rob@77 2867
rob@77 2868 // IE6/7 call enctype encoding
rob@77 2869 if ( !jQuery.support.enctype ) {
rob@77 2870 jQuery.propFix.enctype = "encoding";
rob@77 2871 }
rob@77 2872
rob@77 2873 // Radios and checkboxes getter/setter
rob@77 2874 if ( !jQuery.support.checkOn ) {
rob@77 2875 jQuery.each([ "radio", "checkbox" ], function() {
rob@77 2876 jQuery.valHooks[ this ] = {
rob@77 2877 get: function( elem ) {
rob@77 2878 // Handle the case where in Webkit "" is returned instead of "on" if a value isn't specified
rob@77 2879 return elem.getAttribute("value") === null ? "on" : elem.value;
rob@77 2880 }
rob@77 2881 };
rob@77 2882 });
rob@77 2883 }
rob@77 2884 jQuery.each([ "radio", "checkbox" ], function() {
rob@77 2885 jQuery.valHooks[ this ] = jQuery.extend( jQuery.valHooks[ this ], {
rob@77 2886 set: function( elem, value ) {
rob@77 2887 if ( jQuery.isArray( value ) ) {
rob@77 2888 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
rob@77 2889 }
rob@77 2890 }
rob@77 2891 });
rob@77 2892 });
rob@77 2893
rob@77 2894
rob@77 2895
rob@77 2896
rob@77 2897 var rformElems = /^(?:textarea|input|select)$/i,
rob@77 2898 rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/,
rob@77 2899 rhoverHack = /(?:^|\s)hover(\.\S+)?\b/,
rob@77 2900 rkeyEvent = /^key/,
rob@77 2901 rmouseEvent = /^(?:mouse|contextmenu)|click/,
rob@77 2902 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
rob@77 2903 rquickIs = /^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,
rob@77 2904 quickParse = function( selector ) {
rob@77 2905 var quick = rquickIs.exec( selector );
rob@77 2906 if ( quick ) {
rob@77 2907 // 0 1 2 3
rob@77 2908 // [ _, tag, id, class ]
rob@77 2909 quick[1] = ( quick[1] || "" ).toLowerCase();
rob@77 2910 quick[3] = quick[3] && new RegExp( "(?:^|\\s)" + quick[3] + "(?:\\s|$)" );
rob@77 2911 }
rob@77 2912 return quick;
rob@77 2913 },
rob@77 2914 quickIs = function( elem, m ) {
rob@77 2915 var attrs = elem.attributes || {};
rob@77 2916 return (
rob@77 2917 (!m[1] || elem.nodeName.toLowerCase() === m[1]) &&
rob@77 2918 (!m[2] || (attrs.id || {}).value === m[2]) &&
rob@77 2919 (!m[3] || m[3].test( (attrs[ "class" ] || {}).value ))
rob@77 2920 );
rob@77 2921 },
rob@77 2922 hoverHack = function( events ) {
rob@77 2923 return jQuery.event.special.hover ? events : events.replace( rhoverHack, "mouseenter$1 mouseleave$1" );
rob@77 2924 };
rob@77 2925
rob@77 2926 /*
rob@77 2927 * Helper functions for managing events -- not part of the public interface.
rob@77 2928 * Props to Dean Edwards' addEvent library for many of the ideas.
rob@77 2929 */
rob@77 2930 jQuery.event = {
rob@77 2931
rob@77 2932 add: function( elem, types, handler, data, selector ) {
rob@77 2933
rob@77 2934 var elemData, eventHandle, events,
rob@77 2935 t, tns, type, namespaces, handleObj,
rob@77 2936 handleObjIn, quick, handlers, special;
rob@77 2937
rob@77 2938 // Don't attach events to noData or text/comment nodes (allow plain objects tho)
rob@77 2939 if ( elem.nodeType === 3 || elem.nodeType === 8 || !types || !handler || !(elemData = jQuery._data( elem )) ) {
rob@77 2940 return;
rob@77 2941 }
rob@77 2942
rob@77 2943 // Caller can pass in an object of custom data in lieu of the handler
rob@77 2944 if ( handler.handler ) {
rob@77 2945 handleObjIn = handler;
rob@77 2946 handler = handleObjIn.handler;
rob@77 2947 selector = handleObjIn.selector;
rob@77 2948 }
rob@77 2949
rob@77 2950 // Make sure that the handler has a unique ID, used to find/remove it later
rob@77 2951 if ( !handler.guid ) {
rob@77 2952 handler.guid = jQuery.guid++;
rob@77 2953 }
rob@77 2954
rob@77 2955 // Init the element's event structure and main handler, if this is the first
rob@77 2956 events = elemData.events;
rob@77 2957 if ( !events ) {
rob@77 2958 elemData.events = events = {};
rob@77 2959 }
rob@77 2960 eventHandle = elemData.handle;
rob@77 2961 if ( !eventHandle ) {
rob@77 2962 elemData.handle = eventHandle = function( e ) {
rob@77 2963 // Discard the second event of a jQuery.event.trigger() and
rob@77 2964 // when an event is called after a page has unloaded
rob@77 2965 return typeof jQuery !== "undefined" && (!e || jQuery.event.triggered !== e.type) ?
rob@77 2966 jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
rob@77 2967 undefined;
rob@77 2968 };
rob@77 2969 // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
rob@77 2970 eventHandle.elem = elem;
rob@77 2971 }
rob@77 2972
rob@77 2973 // Handle multiple events separated by a space
rob@77 2974 // jQuery(...).bind("mouseover mouseout", fn);
rob@77 2975 types = jQuery.trim( hoverHack(types) ).split( " " );
rob@77 2976 for ( t = 0; t < types.length; t++ ) {
rob@77 2977
rob@77 2978 tns = rtypenamespace.exec( types[t] ) || [];
rob@77 2979 type = tns[1];
rob@77 2980 namespaces = ( tns[2] || "" ).split( "." ).sort();
rob@77 2981
rob@77 2982 // If event changes its type, use the special event handlers for the changed type
rob@77 2983 special = jQuery.event.special[ type ] || {};
rob@77 2984
rob@77 2985 // If selector defined, determine special event api type, otherwise given type
rob@77 2986 type = ( selector ? special.delegateType : special.bindType ) || type;
rob@77 2987
rob@77 2988 // Update special based on newly reset type
rob@77 2989 special = jQuery.event.special[ type ] || {};
rob@77 2990
rob@77 2991 // handleObj is passed to all event handlers
rob@77 2992 handleObj = jQuery.extend({
rob@77 2993 type: type,
rob@77 2994 origType: tns[1],
rob@77 2995 data: data,
rob@77 2996 handler: handler,
rob@77 2997 guid: handler.guid,
rob@77 2998 selector: selector,
rob@77 2999 quick: selector && quickParse( selector ),
rob@77 3000 namespace: namespaces.join(".")
rob@77 3001 }, handleObjIn );
rob@77 3002
rob@77 3003 // Init the event handler queue if we're the first
rob@77 3004 handlers = events[ type ];
rob@77 3005 if ( !handlers ) {
rob@77 3006 handlers = events[ type ] = [];
rob@77 3007 handlers.delegateCount = 0;
rob@77 3008
rob@77 3009 // Only use addEventListener/attachEvent if the special events handler returns false
rob@77 3010 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
rob@77 3011 // Bind the global event handler to the element
rob@77 3012 if ( elem.addEventListener ) {
rob@77 3013 elem.addEventListener( type, eventHandle, false );
rob@77 3014
rob@77 3015 } else if ( elem.attachEvent ) {
rob@77 3016 elem.attachEvent( "on" + type, eventHandle );
rob@77 3017 }
rob@77 3018 }
rob@77 3019 }
rob@77 3020
rob@77 3021 if ( special.add ) {
rob@77 3022 special.add.call( elem, handleObj );
rob@77 3023
rob@77 3024 if ( !handleObj.handler.guid ) {
rob@77 3025 handleObj.handler.guid = handler.guid;
rob@77 3026 }
rob@77 3027 }
rob@77 3028
rob@77 3029 // Add to the element's handler list, delegates in front
rob@77 3030 if ( selector ) {
rob@77 3031 handlers.splice( handlers.delegateCount++, 0, handleObj );
rob@77 3032 } else {
rob@77 3033 handlers.push( handleObj );
rob@77 3034 }
rob@77 3035
rob@77 3036 // Keep track of which events have ever been used, for event optimization
rob@77 3037 jQuery.event.global[ type ] = true;
rob@77 3038 }
rob@77 3039
rob@77 3040 // Nullify elem to prevent memory leaks in IE
rob@77 3041 elem = null;
rob@77 3042 },
rob@77 3043
rob@77 3044 global: {},
rob@77 3045
rob@77 3046 // Detach an event or set of events from an element
rob@77 3047 remove: function( elem, types, handler, selector, mappedTypes ) {
rob@77 3048
rob@77 3049 var elemData = jQuery.hasData( elem ) && jQuery._data( elem ),
rob@77 3050 t, tns, type, origType, namespaces, origCount,
rob@77 3051 j, events, special, handle, eventType, handleObj;
rob@77 3052
rob@77 3053 if ( !elemData || !(events = elemData.events) ) {
rob@77 3054 return;
rob@77 3055 }
rob@77 3056
rob@77 3057 // Once for each type.namespace in types; type may be omitted
rob@77 3058 types = jQuery.trim( hoverHack( types || "" ) ).split(" ");
rob@77 3059 for ( t = 0; t < types.length; t++ ) {
rob@77 3060 tns = rtypenamespace.exec( types[t] ) || [];
rob@77 3061 type = origType = tns[1];
rob@77 3062 namespaces = tns[2];
rob@77 3063
rob@77 3064 // Unbind all events (on this namespace, if provided) for the element
rob@77 3065 if ( !type ) {
rob@77 3066 for ( type in events ) {
rob@77 3067 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
rob@77 3068 }
rob@77 3069 continue;
rob@77 3070 }
rob@77 3071
rob@77 3072 special = jQuery.event.special[ type ] || {};
rob@77 3073 type = ( selector? special.delegateType : special.bindType ) || type;
rob@77 3074 eventType = events[ type ] || [];
rob@77 3075 origCount = eventType.length;
rob@77 3076 namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
rob@77 3077
rob@77 3078 // Remove matching events
rob@77 3079 for ( j = 0; j < eventType.length; j++ ) {
rob@77 3080 handleObj = eventType[ j ];
rob@77 3081
rob@77 3082 if ( ( mappedTypes || origType === handleObj.origType ) &&
rob@77 3083 ( !handler || handler.guid === handleObj.guid ) &&
rob@77 3084 ( !namespaces || namespaces.test( handleObj.namespace ) ) &&
rob@77 3085 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
rob@77 3086 eventType.splice( j--, 1 );
rob@77 3087
rob@77 3088 if ( handleObj.selector ) {
rob@77 3089 eventType.delegateCount--;
rob@77 3090 }
rob@77 3091 if ( special.remove ) {
rob@77 3092 special.remove.call( elem, handleObj );
rob@77 3093 }
rob@77 3094 }
rob@77 3095 }
rob@77 3096
rob@77 3097 // Remove generic event handler if we removed something and no more handlers exist
rob@77 3098 // (avoids potential for endless recursion during removal of special event handlers)
rob@77 3099 if ( eventType.length === 0 && origCount !== eventType.length ) {
rob@77 3100 if ( !special.teardown || special.teardown.call( elem, namespaces ) === false ) {
rob@77 3101 jQuery.removeEvent( elem, type, elemData.handle );
rob@77 3102 }
rob@77 3103
rob@77 3104 delete events[ type ];
rob@77 3105 }
rob@77 3106 }
rob@77 3107
rob@77 3108 // Remove the expando if it's no longer used
rob@77 3109 if ( jQuery.isEmptyObject( events ) ) {
rob@77 3110 handle = elemData.handle;
rob@77 3111 if ( handle ) {
rob@77 3112 handle.elem = null;
rob@77 3113 }
rob@77 3114
rob@77 3115 // removeData also checks for emptiness and clears the expando if empty
rob@77 3116 // so use it instead of delete
rob@77 3117 jQuery.removeData( elem, [ "events", "handle" ], true );
rob@77 3118 }
rob@77 3119 },
rob@77 3120
rob@77 3121 // Events that are safe to short-circuit if no handlers are attached.
rob@77 3122 // Native DOM events should not be added, they may have inline handlers.
rob@77 3123 customEvent: {
rob@77 3124 "getData": true,
rob@77 3125 "setData": true,
rob@77 3126 "changeData": true
rob@77 3127 },
rob@77 3128
rob@77 3129 trigger: function( event, data, elem, onlyHandlers ) {
rob@77 3130 // Don't do events on text and comment nodes
rob@77 3131 if ( elem && (elem.nodeType === 3 || elem.nodeType === 8) ) {
rob@77 3132 return;
rob@77 3133 }
rob@77 3134
rob@77 3135 // Event object or event type
rob@77 3136 var type = event.type || event,
rob@77 3137 namespaces = [],
rob@77 3138 cache, exclusive, i, cur, old, ontype, special, handle, eventPath, bubbleType;
rob@77 3139
rob@77 3140 // focus/blur morphs to focusin/out; ensure we're not firing them right now
rob@77 3141 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
rob@77 3142 return;
rob@77 3143 }
rob@77 3144
rob@77 3145 if ( type.indexOf( "!" ) >= 0 ) {
rob@77 3146 // Exclusive events trigger only for the exact event (no namespaces)
rob@77 3147 type = type.slice(0, -1);
rob@77 3148 exclusive = true;
rob@77 3149 }
rob@77 3150
rob@77 3151 if ( type.indexOf( "." ) >= 0 ) {
rob@77 3152 // Namespaced trigger; create a regexp to match event type in handle()
rob@77 3153 namespaces = type.split(".");
rob@77 3154 type = namespaces.shift();
rob@77 3155 namespaces.sort();
rob@77 3156 }
rob@77 3157
rob@77 3158 if ( (!elem || jQuery.event.customEvent[ type ]) && !jQuery.event.global[ type ] ) {
rob@77 3159 // No jQuery handlers for this event type, and it can't have inline handlers
rob@77 3160 return;
rob@77 3161 }
rob@77 3162
rob@77 3163 // Caller can pass in an Event, Object, or just an event type string
rob@77 3164 event = typeof event === "object" ?
rob@77 3165 // jQuery.Event object
rob@77 3166 event[ jQuery.expando ] ? event :
rob@77 3167 // Object literal
rob@77 3168 new jQuery.Event( type, event ) :
rob@77 3169 // Just the event type (string)
rob@77 3170 new jQuery.Event( type );
rob@77 3171
rob@77 3172 event.type = type;
rob@77 3173 event.isTrigger = true;
rob@77 3174 event.exclusive = exclusive;
rob@77 3175 event.namespace = namespaces.join( "." );
rob@77 3176 event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
rob@77 3177 ontype = type.indexOf( ":" ) < 0 ? "on" + type : "";
rob@77 3178
rob@77 3179 // Handle a global trigger
rob@77 3180 if ( !elem ) {
rob@77 3181
rob@77 3182 // TODO: Stop taunting the data cache; remove global events and always attach to document
rob@77 3183 cache = jQuery.cache;
rob@77 3184 for ( i in cache ) {
rob@77 3185 if ( cache[ i ].events && cache[ i ].events[ type ] ) {
rob@77 3186 jQuery.event.trigger( event, data, cache[ i ].handle.elem, true );
rob@77 3187 }
rob@77 3188 }
rob@77 3189 return;
rob@77 3190 }
rob@77 3191
rob@77 3192 // Clean up the event in case it is being reused
rob@77 3193 event.result = undefined;
rob@77 3194 if ( !event.target ) {
rob@77 3195 event.target = elem;
rob@77 3196 }
rob@77 3197
rob@77 3198 // Clone any incoming data and prepend the event, creating the handler arg list
rob@77 3199 data = data != null ? jQuery.makeArray( data ) : [];
rob@77 3200 data.unshift( event );
rob@77 3201
rob@77 3202 // Allow special events to draw outside the lines
rob@77 3203 special = jQuery.event.special[ type ] || {};
rob@77 3204 if ( special.trigger && special.trigger.apply( elem, data ) === false ) {
rob@77 3205 return;
rob@77 3206 }
rob@77 3207
rob@77 3208 // Determine event propagation path in advance, per W3C events spec (#9951)
rob@77 3209 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
rob@77 3210 eventPath = [[ elem, special.bindType || type ]];
rob@77 3211 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
rob@77 3212
rob@77 3213 bubbleType = special.delegateType || type;
rob@77 3214 cur = rfocusMorph.test( bubbleType + type ) ? elem : elem.parentNode;
rob@77 3215 old = null;
rob@77 3216 for ( ; cur; cur = cur.parentNode ) {
rob@77 3217 eventPath.push([ cur, bubbleType ]);
rob@77 3218 old = cur;
rob@77 3219 }
rob@77 3220
rob@77 3221 // Only add window if we got to document (e.g., not plain obj or detached DOM)
rob@77 3222 if ( old && old === elem.ownerDocument ) {
rob@77 3223 eventPath.push([ old.defaultView || old.parentWindow || window, bubbleType ]);
rob@77 3224 }
rob@77 3225 }
rob@77 3226
rob@77 3227 // Fire handlers on the event path
rob@77 3228 for ( i = 0; i < eventPath.length && !event.isPropagationStopped(); i++ ) {
rob@77 3229
rob@77 3230 cur = eventPath[i][0];
rob@77 3231 event.type = eventPath[i][1];
rob@77 3232
rob@77 3233 handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
rob@77 3234 if ( handle ) {
rob@77 3235 handle.apply( cur, data );
rob@77 3236 }
rob@77 3237 // Note that this is a bare JS function and not a jQuery handler
rob@77 3238 handle = ontype && cur[ ontype ];
rob@77 3239 if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) {
rob@77 3240 event.preventDefault();
rob@77 3241 }
rob@77 3242 }
rob@77 3243 event.type = type;
rob@77 3244
rob@77 3245 // If nobody prevented the default action, do it now
rob@77 3246 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
rob@77 3247
rob@77 3248 if ( (!special._default || special._default.apply( elem.ownerDocument, data ) === false) &&
rob@77 3249 !(type === "click" && jQuery.nodeName( elem, "a" )) && jQuery.acceptData( elem ) ) {
rob@77 3250
rob@77 3251 // Call a native DOM method on the target with the same name name as the event.
rob@77 3252 // Can't use an .isFunction() check here because IE6/7 fails that test.
rob@77 3253 // Don't do default actions on window, that's where global variables be (#6170)
rob@77 3254 // IE<9 dies on focus/blur to hidden element (#1486)
rob@77 3255 if ( ontype && elem[ type ] && ((type !== "focus" && type !== "blur") || event.target.offsetWidth !== 0) && !jQuery.isWindow( elem ) ) {
rob@77 3256
rob@77 3257 // Don't re-trigger an onFOO event when we call its FOO() method
rob@77 3258 old = elem[ ontype ];
rob@77 3259
rob@77 3260 if ( old ) {
rob@77 3261 elem[ ontype ] = null;
rob@77 3262 }
rob@77 3263
rob@77 3264 // Prevent re-triggering of the same event, since we already bubbled it above
rob@77 3265 jQuery.event.triggered = type;
rob@77 3266 elem[ type ]();
rob@77 3267 jQuery.event.triggered = undefined;
rob@77 3268
rob@77 3269 if ( old ) {
rob@77 3270 elem[ ontype ] = old;
rob@77 3271 }
rob@77 3272 }
rob@77 3273 }
rob@77 3274 }
rob@77 3275
rob@77 3276 return event.result;
rob@77 3277 },
rob@77 3278
rob@77 3279 dispatch: function( event ) {
rob@77 3280
rob@77 3281 // Make a writable jQuery.Event from the native event object
rob@77 3282 event = jQuery.event.fix( event || window.event );
rob@77 3283
rob@77 3284 var handlers = ( (jQuery._data( this, "events" ) || {} )[ event.type ] || []),
rob@77 3285 delegateCount = handlers.delegateCount,
rob@77 3286 args = [].slice.call( arguments, 0 ),
rob@77 3287 run_all = !event.exclusive && !event.namespace,
rob@77 3288 special = jQuery.event.special[ event.type ] || {},
rob@77 3289 handlerQueue = [],
rob@77 3290 i, j, cur, jqcur, ret, selMatch, matched, matches, handleObj, sel, related;
rob@77 3291
rob@77 3292 // Use the fix-ed jQuery.Event rather than the (read-only) native event
rob@77 3293 args[0] = event;
rob@77 3294 event.delegateTarget = this;
rob@77 3295
rob@77 3296 // Call the preDispatch hook for the mapped type, and let it bail if desired
rob@77 3297 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
rob@77 3298 return;
rob@77 3299 }
rob@77 3300
rob@77 3301 // Determine handlers that should run if there are delegated events
rob@77 3302 // Avoid non-left-click bubbling in Firefox (#3861)
rob@77 3303 if ( delegateCount && !(event.button && event.type === "click") ) {
rob@77 3304
rob@77 3305 // Pregenerate a single jQuery object for reuse with .is()
rob@77 3306 jqcur = jQuery(this);
rob@77 3307 jqcur.context = this.ownerDocument || this;
rob@77 3308
rob@77 3309 for ( cur = event.target; cur != this; cur = cur.parentNode || this ) {
rob@77 3310
rob@77 3311 // Don't process events on disabled elements (#6911, #8165)
rob@77 3312 if ( cur.disabled !== true ) {
rob@77 3313 selMatch = {};
rob@77 3314 matches = [];
rob@77 3315 jqcur[0] = cur;
rob@77 3316 for ( i = 0; i < delegateCount; i++ ) {
rob@77 3317 handleObj = handlers[ i ];
rob@77 3318 sel = handleObj.selector;
rob@77 3319
rob@77 3320 if ( selMatch[ sel ] === undefined ) {
rob@77 3321 selMatch[ sel ] = (
rob@77 3322 handleObj.quick ? quickIs( cur, handleObj.quick ) : jqcur.is( sel )
rob@77 3323 );
rob@77 3324 }
rob@77 3325 if ( selMatch[ sel ] ) {
rob@77 3326 matches.push( handleObj );
rob@77 3327 }
rob@77 3328 }
rob@77 3329 if ( matches.length ) {
rob@77 3330 handlerQueue.push({ elem: cur, matches: matches });
rob@77 3331 }
rob@77 3332 }
rob@77 3333 }
rob@77 3334 }
rob@77 3335
rob@77 3336 // Add the remaining (directly-bound) handlers
rob@77 3337 if ( handlers.length > delegateCount ) {
rob@77 3338 handlerQueue.push({ elem: this, matches: handlers.slice( delegateCount ) });
rob@77 3339 }
rob@77 3340
rob@77 3341 // Run delegates first; they may want to stop propagation beneath us
rob@77 3342 for ( i = 0; i < handlerQueue.length && !event.isPropagationStopped(); i++ ) {
rob@77 3343 matched = handlerQueue[ i ];
rob@77 3344 event.currentTarget = matched.elem;
rob@77 3345
rob@77 3346 for ( j = 0; j < matched.matches.length && !event.isImmediatePropagationStopped(); j++ ) {
rob@77 3347 handleObj = matched.matches[ j ];
rob@77 3348
rob@77 3349 // Triggered event must either 1) be non-exclusive and have no namespace, or
rob@77 3350 // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace).
rob@77 3351 if ( run_all || (!event.namespace && !handleObj.namespace) || event.namespace_re && event.namespace_re.test( handleObj.namespace ) ) {
rob@77 3352
rob@77 3353 event.data = handleObj.data;
rob@77 3354 event.handleObj = handleObj;
rob@77 3355
rob@77 3356 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
rob@77 3357 .apply( matched.elem, args );
rob@77 3358
rob@77 3359 if ( ret !== undefined ) {
rob@77 3360 event.result = ret;
rob@77 3361 if ( ret === false ) {
rob@77 3362 event.preventDefault();
rob@77 3363 event.stopPropagation();
rob@77 3364 }
rob@77 3365 }
rob@77 3366 }
rob@77 3367 }
rob@77 3368 }
rob@77 3369
rob@77 3370 // Call the postDispatch hook for the mapped type
rob@77 3371 if ( special.postDispatch ) {
rob@77 3372 special.postDispatch.call( this, event );
rob@77 3373 }
rob@77 3374
rob@77 3375 return event.result;
rob@77 3376 },
rob@77 3377
rob@77 3378 // Includes some event props shared by KeyEvent and MouseEvent
rob@77 3379 // *** attrChange attrName relatedNode srcElement are not normalized, non-W3C, deprecated, will be removed in 1.8 ***
rob@77 3380 props: "attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
rob@77 3381
rob@77 3382 fixHooks: {},
rob@77 3383
rob@77 3384 keyHooks: {
rob@77 3385 props: "char charCode key keyCode".split(" "),
rob@77 3386 filter: function( event, original ) {
rob@77 3387
rob@77 3388 // Add which for key events
rob@77 3389 if ( event.which == null ) {
rob@77 3390 event.which = original.charCode != null ? original.charCode : original.keyCode;
rob@77 3391 }
rob@77 3392
rob@77 3393 return event;
rob@77 3394 }
rob@77 3395 },
rob@77 3396
rob@77 3397 mouseHooks: {
rob@77 3398 props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
rob@77 3399 filter: function( event, original ) {
rob@77 3400 var eventDoc, doc, body,
rob@77 3401 button = original.button,
rob@77 3402 fromElement = original.fromElement;
rob@77 3403
rob@77 3404 // Calculate pageX/Y if missing and clientX/Y available
rob@77 3405 if ( event.pageX == null && original.clientX != null ) {
rob@77 3406 eventDoc = event.target.ownerDocument || document;
rob@77 3407 doc = eventDoc.documentElement;
rob@77 3408 body = eventDoc.body;
rob@77 3409
rob@77 3410 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
rob@77 3411 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
rob@77 3412 }
rob@77 3413
rob@77 3414 // Add relatedTarget, if necessary
rob@77 3415 if ( !event.relatedTarget && fromElement ) {
rob@77 3416 event.relatedTarget = fromElement === event.target ? original.toElement : fromElement;
rob@77 3417 }
rob@77 3418
rob@77 3419 // Add which for click: 1 === left; 2 === middle; 3 === right
rob@77 3420 // Note: button is not normalized, so don't use it
rob@77 3421 if ( !event.which && button !== undefined ) {
rob@77 3422 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
rob@77 3423 }
rob@77 3424
rob@77 3425 return event;
rob@77 3426 }
rob@77 3427 },
rob@77 3428
rob@77 3429 fix: function( event ) {
rob@77 3430 if ( event[ jQuery.expando ] ) {
rob@77 3431 return event;
rob@77 3432 }
rob@77 3433
rob@77 3434 // Create a writable copy of the event object and normalize some properties
rob@77 3435 var i, prop,
rob@77 3436 originalEvent = event,
rob@77 3437 fixHook = jQuery.event.fixHooks[ event.type ] || {},
rob@77 3438 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
rob@77 3439
rob@77 3440 event = jQuery.Event( originalEvent );
rob@77 3441
rob@77 3442 for ( i = copy.length; i; ) {
rob@77 3443 prop = copy[ --i ];
rob@77 3444 event[ prop ] = originalEvent[ prop ];
rob@77 3445 }
rob@77 3446
rob@77 3447 // Fix target property, if necessary (#1925, IE 6/7/8 & Safari2)
rob@77 3448 if ( !event.target ) {
rob@77 3449 event.target = originalEvent.srcElement || document;
rob@77 3450 }
rob@77 3451
rob@77 3452 // Target should not be a text node (#504, Safari)
rob@77 3453 if ( event.target.nodeType === 3 ) {
rob@77 3454 event.target = event.target.parentNode;
rob@77 3455 }
rob@77 3456
rob@77 3457 // For mouse/key events; add metaKey if it's not there (#3368, IE6/7/8)
rob@77 3458 if ( event.metaKey === undefined ) {
rob@77 3459 event.metaKey = event.ctrlKey;
rob@77 3460 }
rob@77 3461
rob@77 3462 return fixHook.filter? fixHook.filter( event, originalEvent ) : event;
rob@77 3463 },
rob@77 3464
rob@77 3465 special: {
rob@77 3466 ready: {
rob@77 3467 // Make sure the ready event is setup
rob@77 3468 setup: jQuery.bindReady
rob@77 3469 },
rob@77 3470
rob@77 3471 load: {
rob@77 3472 // Prevent triggered image.load events from bubbling to window.load
rob@77 3473 noBubble: true
rob@77 3474 },
rob@77 3475
rob@77 3476 focus: {
rob@77 3477 delegateType: "focusin"
rob@77 3478 },
rob@77 3479 blur: {
rob@77 3480 delegateType: "focusout"
rob@77 3481 },
rob@77 3482
rob@77 3483 beforeunload: {
rob@77 3484 setup: function( data, namespaces, eventHandle ) {
rob@77 3485 // We only want to do this special case on windows
rob@77 3486 if ( jQuery.isWindow( this ) ) {
rob@77 3487 this.onbeforeunload = eventHandle;
rob@77 3488 }
rob@77 3489 },
rob@77 3490
rob@77 3491 teardown: function( namespaces, eventHandle ) {
rob@77 3492 if ( this.onbeforeunload === eventHandle ) {
rob@77 3493 this.onbeforeunload = null;
rob@77 3494 }
rob@77 3495 }
rob@77 3496 }
rob@77 3497 },
rob@77 3498
rob@77 3499 simulate: function( type, elem, event, bubble ) {
rob@77 3500 // Piggyback on a donor event to simulate a different one.
rob@77 3501 // Fake originalEvent to avoid donor's stopPropagation, but if the
rob@77 3502 // simulated event prevents default then we do the same on the donor.
rob@77 3503 var e = jQuery.extend(
rob@77 3504 new jQuery.Event(),
rob@77 3505 event,
rob@77 3506 { type: type,
rob@77 3507 isSimulated: true,
rob@77 3508 originalEvent: {}
rob@77 3509 }
rob@77 3510 );
rob@77 3511 if ( bubble ) {
rob@77 3512 jQuery.event.trigger( e, null, elem );
rob@77 3513 } else {
rob@77 3514 jQuery.event.dispatch.call( elem, e );
rob@77 3515 }
rob@77 3516 if ( e.isDefaultPrevented() ) {
rob@77 3517 event.preventDefault();
rob@77 3518 }
rob@77 3519 }
rob@77 3520 };
rob@77 3521
rob@77 3522 // Some plugins are using, but it's undocumented/deprecated and will be removed.
rob@77 3523 // The 1.7 special event interface should provide all the hooks needed now.
rob@77 3524 jQuery.event.handle = jQuery.event.dispatch;
rob@77 3525
rob@77 3526 jQuery.removeEvent = document.removeEventListener ?
rob@77 3527 function( elem, type, handle ) {
rob@77 3528 if ( elem.removeEventListener ) {
rob@77 3529 elem.removeEventListener( type, handle, false );
rob@77 3530 }
rob@77 3531 } :
rob@77 3532 function( elem, type, handle ) {
rob@77 3533 if ( elem.detachEvent ) {
rob@77 3534 elem.detachEvent( "on" + type, handle );
rob@77 3535 }
rob@77 3536 };
rob@77 3537
rob@77 3538 jQuery.Event = function( src, props ) {
rob@77 3539 // Allow instantiation without the 'new' keyword
rob@77 3540 if ( !(this instanceof jQuery.Event) ) {
rob@77 3541 return new jQuery.Event( src, props );
rob@77 3542 }
rob@77 3543
rob@77 3544 // Event object
rob@77 3545 if ( src && src.type ) {
rob@77 3546 this.originalEvent = src;
rob@77 3547 this.type = src.type;
rob@77 3548
rob@77 3549 // Events bubbling up the document may have been marked as prevented
rob@77 3550 // by a handler lower down the tree; reflect the correct value.
rob@77 3551 this.isDefaultPrevented = ( src.defaultPrevented || src.returnValue === false ||
rob@77 3552 src.getPreventDefault && src.getPreventDefault() ) ? returnTrue : returnFalse;
rob@77 3553
rob@77 3554 // Event type
rob@77 3555 } else {
rob@77 3556 this.type = src;
rob@77 3557 }
rob@77 3558
rob@77 3559 // Put explicitly provided properties onto the event object
rob@77 3560 if ( props ) {
rob@77 3561 jQuery.extend( this, props );
rob@77 3562 }
rob@77 3563
rob@77 3564 // Create a timestamp if incoming event doesn't have one
rob@77 3565 this.timeStamp = src && src.timeStamp || jQuery.now();
rob@77 3566
rob@77 3567 // Mark it as fixed
rob@77 3568 this[ jQuery.expando ] = true;
rob@77 3569 };
rob@77 3570
rob@77 3571 function returnFalse() {
rob@77 3572 return false;
rob@77 3573 }
rob@77 3574 function returnTrue() {
rob@77 3575 return true;
rob@77 3576 }
rob@77 3577
rob@77 3578 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
rob@77 3579 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
rob@77 3580 jQuery.Event.prototype = {
rob@77 3581 preventDefault: function() {
rob@77 3582 this.isDefaultPrevented = returnTrue;
rob@77 3583
rob@77 3584 var e = this.originalEvent;
rob@77 3585 if ( !e ) {
rob@77 3586 return;
rob@77 3587 }
rob@77 3588
rob@77 3589 // if preventDefault exists run it on the original event
rob@77 3590 if ( e.preventDefault ) {
rob@77 3591 e.preventDefault();
rob@77 3592
rob@77 3593 // otherwise set the returnValue property of the original event to false (IE)
rob@77 3594 } else {
rob@77 3595 e.returnValue = false;
rob@77 3596 }
rob@77 3597 },
rob@77 3598 stopPropagation: function() {
rob@77 3599 this.isPropagationStopped = returnTrue;
rob@77 3600
rob@77 3601 var e = this.originalEvent;
rob@77 3602 if ( !e ) {
rob@77 3603 return;
rob@77 3604 }
rob@77 3605 // if stopPropagation exists run it on the original event
rob@77 3606 if ( e.stopPropagation ) {
rob@77 3607 e.stopPropagation();
rob@77 3608 }
rob@77 3609 // otherwise set the cancelBubble property of the original event to true (IE)
rob@77 3610 e.cancelBubble = true;
rob@77 3611 },
rob@77 3612 stopImmediatePropagation: function() {
rob@77 3613 this.isImmediatePropagationStopped = returnTrue;
rob@77 3614 this.stopPropagation();
rob@77 3615 },
rob@77 3616 isDefaultPrevented: returnFalse,
rob@77 3617 isPropagationStopped: returnFalse,
rob@77 3618 isImmediatePropagationStopped: returnFalse
rob@77 3619 };
rob@77 3620
rob@77 3621 // Create mouseenter/leave events using mouseover/out and event-time checks
rob@77 3622 jQuery.each({
rob@77 3623 mouseenter: "mouseover",
rob@77 3624 mouseleave: "mouseout"
rob@77 3625 }, function( orig, fix ) {
rob@77 3626 jQuery.event.special[ orig ] = {
rob@77 3627 delegateType: fix,
rob@77 3628 bindType: fix,
rob@77 3629
rob@77 3630 handle: function( event ) {
rob@77 3631 var target = this,
rob@77 3632 related = event.relatedTarget,
rob@77 3633 handleObj = event.handleObj,
rob@77 3634 selector = handleObj.selector,
rob@77 3635 ret;
rob@77 3636
rob@77 3637 // For mousenter/leave call the handler if related is outside the target.
rob@77 3638 // NB: No relatedTarget if the mouse left/entered the browser window
rob@77 3639 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
rob@77 3640 event.type = handleObj.origType;
rob@77 3641 ret = handleObj.handler.apply( this, arguments );
rob@77 3642 event.type = fix;
rob@77 3643 }
rob@77 3644 return ret;
rob@77 3645 }
rob@77 3646 };
rob@77 3647 });
rob@77 3648
rob@77 3649 // IE submit delegation
rob@77 3650 if ( !jQuery.support.submitBubbles ) {
rob@77 3651
rob@77 3652 jQuery.event.special.submit = {
rob@77 3653 setup: function() {
rob@77 3654 // Only need this for delegated form submit events
rob@77 3655 if ( jQuery.nodeName( this, "form" ) ) {
rob@77 3656 return false;
rob@77 3657 }
rob@77 3658
rob@77 3659 // Lazy-add a submit handler when a descendant form may potentially be submitted
rob@77 3660 jQuery.event.add( this, "click._submit keypress._submit", function( e ) {
rob@77 3661 // Node name check avoids a VML-related crash in IE (#9807)
rob@77 3662 var elem = e.target,
rob@77 3663 form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined;
rob@77 3664 if ( form && !form._submit_attached ) {
rob@77 3665 jQuery.event.add( form, "submit._submit", function( event ) {
rob@77 3666 event._submit_bubble = true;
rob@77 3667 });
rob@77 3668 form._submit_attached = true;
rob@77 3669 }
rob@77 3670 });
rob@77 3671 // return undefined since we don't need an event listener
rob@77 3672 },
rob@77 3673
rob@77 3674 postDispatch: function( event ) {
rob@77 3675 // If form was submitted by the user, bubble the event up the tree
rob@77 3676 if ( event._submit_bubble ) {
rob@77 3677 delete event._submit_bubble;
rob@77 3678 if ( this.parentNode && !event.isTrigger ) {
rob@77 3679 jQuery.event.simulate( "submit", this.parentNode, event, true );
rob@77 3680 }
rob@77 3681 }
rob@77 3682 },
rob@77 3683
rob@77 3684 teardown: function() {
rob@77 3685 // Only need this for delegated form submit events
rob@77 3686 if ( jQuery.nodeName( this, "form" ) ) {
rob@77 3687 return false;
rob@77 3688 }
rob@77 3689
rob@77 3690 // Remove delegated handlers; cleanData eventually reaps submit handlers attached above
rob@77 3691 jQuery.event.remove( this, "._submit" );
rob@77 3692 }
rob@77 3693 };
rob@77 3694 }
rob@77 3695
rob@77 3696 // IE change delegation and checkbox/radio fix
rob@77 3697 if ( !jQuery.support.changeBubbles ) {
rob@77 3698
rob@77 3699 jQuery.event.special.change = {
rob@77 3700
rob@77 3701 setup: function() {
rob@77 3702
rob@77 3703 if ( rformElems.test( this.nodeName ) ) {
rob@77 3704 // IE doesn't fire change on a check/radio until blur; trigger it on click
rob@77 3705 // after a propertychange. Eat the blur-change in special.change.handle.
rob@77 3706 // This still fires onchange a second time for check/radio after blur.
rob@77 3707 if ( this.type === "checkbox" || this.type === "radio" ) {
rob@77 3708 jQuery.event.add( this, "propertychange._change", function( event ) {
rob@77 3709 if ( event.originalEvent.propertyName === "checked" ) {
rob@77 3710 this._just_changed = true;
rob@77 3711 }
rob@77 3712 });
rob@77 3713 jQuery.event.add( this, "click._change", function( event ) {
rob@77 3714 if ( this._just_changed && !event.isTrigger ) {
rob@77 3715 this._just_changed = false;
rob@77 3716 jQuery.event.simulate( "change", this, event, true );
rob@77 3717 }
rob@77 3718 });
rob@77 3719 }
rob@77 3720 return false;
rob@77 3721 }
rob@77 3722 // Delegated event; lazy-add a change handler on descendant inputs
rob@77 3723 jQuery.event.add( this, "beforeactivate._change", function( e ) {
rob@77 3724 var elem = e.target;
rob@77 3725
rob@77 3726 if ( rformElems.test( elem.nodeName ) && !elem._change_attached ) {
rob@77 3727 jQuery.event.add( elem, "change._change", function( event ) {
rob@77 3728 if ( this.parentNode && !event.isSimulated && !event.isTrigger ) {
rob@77 3729 jQuery.event.simulate( "change", this.parentNode, event, true );
rob@77 3730 }
rob@77 3731 });
rob@77 3732 elem._change_attached = true;
rob@77 3733 }
rob@77 3734 });
rob@77 3735 },
rob@77 3736
rob@77 3737 handle: function( event ) {
rob@77 3738 var elem = event.target;
rob@77 3739
rob@77 3740 // Swallow native change events from checkbox/radio, we already triggered them above
rob@77 3741 if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) {
rob@77 3742 return event.handleObj.handler.apply( this, arguments );
rob@77 3743 }
rob@77 3744 },
rob@77 3745
rob@77 3746 teardown: function() {
rob@77 3747 jQuery.event.remove( this, "._change" );
rob@77 3748
rob@77 3749 return rformElems.test( this.nodeName );
rob@77 3750 }
rob@77 3751 };
rob@77 3752 }
rob@77 3753
rob@77 3754 // Create "bubbling" focus and blur events
rob@77 3755 if ( !jQuery.support.focusinBubbles ) {
rob@77 3756 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
rob@77 3757
rob@77 3758 // Attach a single capturing handler while someone wants focusin/focusout
rob@77 3759 var attaches = 0,
rob@77 3760 handler = function( event ) {
rob@77 3761 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
rob@77 3762 };
rob@77 3763
rob@77 3764 jQuery.event.special[ fix ] = {
rob@77 3765 setup: function() {
rob@77 3766 if ( attaches++ === 0 ) {
rob@77 3767 document.addEventListener( orig, handler, true );
rob@77 3768 }
rob@77 3769 },
rob@77 3770 teardown: function() {
rob@77 3771 if ( --attaches === 0 ) {
rob@77 3772 document.removeEventListener( orig, handler, true );
rob@77 3773 }
rob@77 3774 }
rob@77 3775 };
rob@77 3776 });
rob@77 3777 }
rob@77 3778
rob@77 3779 jQuery.fn.extend({
rob@77 3780
rob@77 3781 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
rob@77 3782 var origFn, type;
rob@77 3783
rob@77 3784 // Types can be a map of types/handlers
rob@77 3785 if ( typeof types === "object" ) {
rob@77 3786 // ( types-Object, selector, data )
rob@77 3787 if ( typeof selector !== "string" ) { // && selector != null
rob@77 3788 // ( types-Object, data )
rob@77 3789 data = data || selector;
rob@77 3790 selector = undefined;
rob@77 3791 }
rob@77 3792 for ( type in types ) {
rob@77 3793 this.on( type, selector, data, types[ type ], one );
rob@77 3794 }
rob@77 3795 return this;
rob@77 3796 }
rob@77 3797
rob@77 3798 if ( data == null && fn == null ) {
rob@77 3799 // ( types, fn )
rob@77 3800 fn = selector;
rob@77 3801 data = selector = undefined;
rob@77 3802 } else if ( fn == null ) {
rob@77 3803 if ( typeof selector === "string" ) {
rob@77 3804 // ( types, selector, fn )
rob@77 3805 fn = data;
rob@77 3806 data = undefined;
rob@77 3807 } else {
rob@77 3808 // ( types, data, fn )
rob@77 3809 fn = data;
rob@77 3810 data = selector;
rob@77 3811 selector = undefined;
rob@77 3812 }
rob@77 3813 }
rob@77 3814 if ( fn === false ) {
rob@77 3815 fn = returnFalse;
rob@77 3816 } else if ( !fn ) {
rob@77 3817 return this;
rob@77 3818 }
rob@77 3819
rob@77 3820 if ( one === 1 ) {
rob@77 3821 origFn = fn;
rob@77 3822 fn = function( event ) {
rob@77 3823 // Can use an empty set, since event contains the info
rob@77 3824 jQuery().off( event );
rob@77 3825 return origFn.apply( this, arguments );
rob@77 3826 };
rob@77 3827 // Use same guid so caller can remove using origFn
rob@77 3828 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
rob@77 3829 }
rob@77 3830 return this.each( function() {
rob@77 3831 jQuery.event.add( this, types, fn, data, selector );
rob@77 3832 });
rob@77 3833 },
rob@77 3834 one: function( types, selector, data, fn ) {
rob@77 3835 return this.on( types, selector, data, fn, 1 );
rob@77 3836 },
rob@77 3837 off: function( types, selector, fn ) {
rob@77 3838 if ( types && types.preventDefault && types.handleObj ) {
rob@77 3839 // ( event ) dispatched jQuery.Event
rob@77 3840 var handleObj = types.handleObj;
rob@77 3841 jQuery( types.delegateTarget ).off(
rob@77 3842 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
rob@77 3843 handleObj.selector,
rob@77 3844 handleObj.handler
rob@77 3845 );
rob@77 3846 return this;
rob@77 3847 }
rob@77 3848 if ( typeof types === "object" ) {
rob@77 3849 // ( types-object [, selector] )
rob@77 3850 for ( var type in types ) {
rob@77 3851 this.off( type, selector, types[ type ] );
rob@77 3852 }
rob@77 3853 return this;
rob@77 3854 }
rob@77 3855 if ( selector === false || typeof selector === "function" ) {
rob@77 3856 // ( types [, fn] )
rob@77 3857 fn = selector;
rob@77 3858 selector = undefined;
rob@77 3859 }
rob@77 3860 if ( fn === false ) {
rob@77 3861 fn = returnFalse;
rob@77 3862 }
rob@77 3863 return this.each(function() {
rob@77 3864 jQuery.event.remove( this, types, fn, selector );
rob@77 3865 });
rob@77 3866 },
rob@77 3867
rob@77 3868 bind: function( types, data, fn ) {
rob@77 3869 return this.on( types, null, data, fn );
rob@77 3870 },
rob@77 3871 unbind: function( types, fn ) {
rob@77 3872 return this.off( types, null, fn );
rob@77 3873 },
rob@77 3874
rob@77 3875 live: function( types, data, fn ) {
rob@77 3876 jQuery( this.context ).on( types, this.selector, data, fn );
rob@77 3877 return this;
rob@77 3878 },
rob@77 3879 die: function( types, fn ) {
rob@77 3880 jQuery( this.context ).off( types, this.selector || "**", fn );
rob@77 3881 return this;
rob@77 3882 },
rob@77 3883
rob@77 3884 delegate: function( selector, types, data, fn ) {
rob@77 3885 return this.on( types, selector, data, fn );
rob@77 3886 },
rob@77 3887 undelegate: function( selector, types, fn ) {
rob@77 3888 // ( namespace ) or ( selector, types [, fn] )
rob@77 3889 return arguments.length == 1? this.off( selector, "**" ) : this.off( types, selector, fn );
rob@77 3890 },
rob@77 3891
rob@77 3892 trigger: function( type, data ) {
rob@77 3893 return this.each(function() {
rob@77 3894 jQuery.event.trigger( type, data, this );
rob@77 3895 });
rob@77 3896 },
rob@77 3897 triggerHandler: function( type, data ) {
rob@77 3898 if ( this[0] ) {
rob@77 3899 return jQuery.event.trigger( type, data, this[0], true );
rob@77 3900 }
rob@77 3901 },
rob@77 3902
rob@77 3903 toggle: function( fn ) {
rob@77 3904 // Save reference to arguments for access in closure
rob@77 3905 var args = arguments,
rob@77 3906 guid = fn.guid || jQuery.guid++,
rob@77 3907 i = 0,
rob@77 3908 toggler = function( event ) {
rob@77 3909 // Figure out which function to execute
rob@77 3910 var lastToggle = ( jQuery._data( this, "lastToggle" + fn.guid ) || 0 ) % i;
rob@77 3911 jQuery._data( this, "lastToggle" + fn.guid, lastToggle + 1 );
rob@77 3912
rob@77 3913 // Make sure that clicks stop
rob@77 3914 event.preventDefault();
rob@77 3915
rob@77 3916 // and execute the function
rob@77 3917 return args[ lastToggle ].apply( this, arguments ) || false;
rob@77 3918 };
rob@77 3919
rob@77 3920 // link all the functions, so any of them can unbind this click handler
rob@77 3921 toggler.guid = guid;
rob@77 3922 while ( i < args.length ) {
rob@77 3923 args[ i++ ].guid = guid;
rob@77 3924 }
rob@77 3925
rob@77 3926 return this.click( toggler );
rob@77 3927 },
rob@77 3928
rob@77 3929 hover: function( fnOver, fnOut ) {
rob@77 3930 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
rob@77 3931 }
rob@77 3932 });
rob@77 3933
rob@77 3934 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
rob@77 3935 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
rob@77 3936 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
rob@77 3937
rob@77 3938 // Handle event binding
rob@77 3939 jQuery.fn[ name ] = function( data, fn ) {
rob@77 3940 if ( fn == null ) {
rob@77 3941 fn = data;
rob@77 3942 data = null;
rob@77 3943 }
rob@77 3944
rob@77 3945 return arguments.length > 0 ?
rob@77 3946 this.on( name, null, data, fn ) :
rob@77 3947 this.trigger( name );
rob@77 3948 };
rob@77 3949
rob@77 3950 if ( jQuery.attrFn ) {
rob@77 3951 jQuery.attrFn[ name ] = true;
rob@77 3952 }
rob@77 3953
rob@77 3954 if ( rkeyEvent.test( name ) ) {
rob@77 3955 jQuery.event.fixHooks[ name ] = jQuery.event.keyHooks;
rob@77 3956 }
rob@77 3957
rob@77 3958 if ( rmouseEvent.test( name ) ) {
rob@77 3959 jQuery.event.fixHooks[ name ] = jQuery.event.mouseHooks;
rob@77 3960 }
rob@77 3961 });
rob@77 3962
rob@77 3963
rob@77 3964
rob@77 3965 /*!
rob@77 3966 * Sizzle CSS Selector Engine
rob@77 3967 * Copyright 2011, The Dojo Foundation
rob@77 3968 * Released under the MIT, BSD, and GPL Licenses.
rob@77 3969 * More information: http://sizzlejs.com/
rob@77 3970 */
rob@77 3971 (function(){
rob@77 3972
rob@77 3973 var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
rob@77 3974 expando = "sizcache" + (Math.random() + '').replace('.', ''),
rob@77 3975 done = 0,
rob@77 3976 toString = Object.prototype.toString,
rob@77 3977 hasDuplicate = false,
rob@77 3978 baseHasDuplicate = true,
rob@77 3979 rBackslash = /\\/g,
rob@77 3980 rReturn = /\r\n/g,
rob@77 3981 rNonWord = /\W/;
rob@77 3982
rob@77 3983 // Here we check if the JavaScript engine is using some sort of
rob@77 3984 // optimization where it does not always call our comparision
rob@77 3985 // function. If that is the case, discard the hasDuplicate value.
rob@77 3986 // Thus far that includes Google Chrome.
rob@77 3987 [0, 0].sort(function() {
rob@77 3988 baseHasDuplicate = false;
rob@77 3989 return 0;
rob@77 3990 });
rob@77 3991
rob@77 3992 var Sizzle = function( selector, context, results, seed ) {
rob@77 3993 results = results || [];
rob@77 3994 context = context || document;
rob@77 3995
rob@77 3996 var origContext = context;
rob@77 3997
rob@77 3998 if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
rob@77 3999 return [];
rob@77 4000 }
rob@77 4001
rob@77 4002 if ( !selector || typeof selector !== "string" ) {
rob@77 4003 return results;
rob@77 4004 }
rob@77 4005
rob@77 4006 var m, set, checkSet, extra, ret, cur, pop, i,
rob@77 4007 prune = true,
rob@77 4008 contextXML = Sizzle.isXML( context ),
rob@77 4009 parts = [],
rob@77 4010 soFar = selector;
rob@77 4011
rob@77 4012 // Reset the position of the chunker regexp (start from head)
rob@77 4013 do {
rob@77 4014 chunker.exec( "" );
rob@77 4015 m = chunker.exec( soFar );
rob@77 4016
rob@77 4017 if ( m ) {
rob@77 4018 soFar = m[3];
rob@77 4019
rob@77 4020 parts.push( m[1] );
rob@77 4021
rob@77 4022 if ( m[2] ) {
rob@77 4023 extra = m[3];
rob@77 4024 break;
rob@77 4025 }
rob@77 4026 }
rob@77 4027 } while ( m );
rob@77 4028
rob@77 4029 if ( parts.length > 1 && origPOS.exec( selector ) ) {
rob@77 4030
rob@77 4031 if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
rob@77 4032 set = posProcess( parts[0] + parts[1], context, seed );
rob@77 4033
rob@77 4034 } else {
rob@77 4035 set = Expr.relative[ parts[0] ] ?
rob@77 4036 [ context ] :
rob@77 4037 Sizzle( parts.shift(), context );
rob@77 4038
rob@77 4039 while ( parts.length ) {
rob@77 4040 selector = parts.shift();
rob@77 4041
rob@77 4042 if ( Expr.relative[ selector ] ) {
rob@77 4043 selector += parts.shift();
rob@77 4044 }
rob@77 4045
rob@77 4046 set = posProcess( selector, set, seed );
rob@77 4047 }
rob@77 4048 }
rob@77 4049
rob@77 4050 } else {
rob@77 4051 // Take a shortcut and set the context if the root selector is an ID
rob@77 4052 // (but not if it'll be faster if the inner selector is an ID)
rob@77 4053 if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
rob@77 4054 Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
rob@77 4055
rob@77 4056 ret = Sizzle.find( parts.shift(), context, contextXML );
rob@77 4057 context = ret.expr ?
rob@77 4058 Sizzle.filter( ret.expr, ret.set )[0] :
rob@77 4059 ret.set[0];
rob@77 4060 }
rob@77 4061
rob@77 4062 if ( context ) {
rob@77 4063 ret = seed ?
rob@77 4064 { expr: parts.pop(), set: makeArray(seed) } :
rob@77 4065 Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
rob@77 4066
rob@77 4067 set = ret.expr ?
rob@77 4068 Sizzle.filter( ret.expr, ret.set ) :
rob@77 4069 ret.set;
rob@77 4070
rob@77 4071 if ( parts.length > 0 ) {
rob@77 4072 checkSet = makeArray( set );
rob@77 4073
rob@77 4074 } else {
rob@77 4075 prune = false;
rob@77 4076 }
rob@77 4077
rob@77 4078 while ( parts.length ) {
rob@77 4079 cur = parts.pop();
rob@77 4080 pop = cur;
rob@77 4081
rob@77 4082 if ( !Expr.relative[ cur ] ) {
rob@77 4083 cur = "";
rob@77 4084 } else {
rob@77 4085 pop = parts.pop();
rob@77 4086 }
rob@77 4087
rob@77 4088 if ( pop == null ) {
rob@77 4089 pop = context;
rob@77 4090 }
rob@77 4091
rob@77 4092 Expr.relative[ cur ]( checkSet, pop, contextXML );
rob@77 4093 }
rob@77 4094
rob@77 4095 } else {
rob@77 4096 checkSet = parts = [];
rob@77 4097 }
rob@77 4098 }
rob@77 4099
rob@77 4100 if ( !checkSet ) {
rob@77 4101 checkSet = set;
rob@77 4102 }
rob@77 4103
rob@77 4104 if ( !checkSet ) {
rob@77 4105 Sizzle.error( cur || selector );
rob@77 4106 }
rob@77 4107
rob@77 4108 if ( toString.call(checkSet) === "[object Array]" ) {
rob@77 4109 if ( !prune ) {
rob@77 4110 results.push.apply( results, checkSet );
rob@77 4111
rob@77 4112 } else if ( context && context.nodeType === 1 ) {
rob@77 4113 for ( i = 0; checkSet[i] != null; i++ ) {
rob@77 4114 if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
rob@77 4115 results.push( set[i] );
rob@77 4116 }
rob@77 4117 }
rob@77 4118
rob@77 4119 } else {
rob@77 4120 for ( i = 0; checkSet[i] != null; i++ ) {
rob@77 4121 if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
rob@77 4122 results.push( set[i] );
rob@77 4123 }
rob@77 4124 }
rob@77 4125 }
rob@77 4126
rob@77 4127 } else {
rob@77 4128 makeArray( checkSet, results );
rob@77 4129 }
rob@77 4130
rob@77 4131 if ( extra ) {
rob@77 4132 Sizzle( extra, origContext, results, seed );
rob@77 4133 Sizzle.uniqueSort( results );
rob@77 4134 }
rob@77 4135
rob@77 4136 return results;
rob@77 4137 };
rob@77 4138
rob@77 4139 Sizzle.uniqueSort = function( results ) {
rob@77 4140 if ( sortOrder ) {
rob@77 4141 hasDuplicate = baseHasDuplicate;
rob@77 4142 results.sort( sortOrder );
rob@77 4143
rob@77 4144 if ( hasDuplicate ) {
rob@77 4145 for ( var i = 1; i < results.length; i++ ) {
rob@77 4146 if ( results[i] === results[ i - 1 ] ) {
rob@77 4147 results.splice( i--, 1 );
rob@77 4148 }
rob@77 4149 }
rob@77 4150 }
rob@77 4151 }
rob@77 4152
rob@77 4153 return results;
rob@77 4154 };
rob@77 4155
rob@77 4156 Sizzle.matches = function( expr, set ) {
rob@77 4157 return Sizzle( expr, null, null, set );
rob@77 4158 };
rob@77 4159
rob@77 4160 Sizzle.matchesSelector = function( node, expr ) {
rob@77 4161 return Sizzle( expr, null, null, [node] ).length > 0;
rob@77 4162 };
rob@77 4163
rob@77 4164 Sizzle.find = function( expr, context, isXML ) {
rob@77 4165 var set, i, len, match, type, left;
rob@77 4166
rob@77 4167 if ( !expr ) {
rob@77 4168 return [];
rob@77 4169 }
rob@77 4170
rob@77 4171 for ( i = 0, len = Expr.order.length; i < len; i++ ) {
rob@77 4172 type = Expr.order[i];
rob@77 4173
rob@77 4174 if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
rob@77 4175 left = match[1];
rob@77 4176 match.splice( 1, 1 );
rob@77 4177
rob@77 4178 if ( left.substr( left.length - 1 ) !== "\\" ) {
rob@77 4179 match[1] = (match[1] || "").replace( rBackslash, "" );
rob@77 4180 set = Expr.find[ type ]( match, context, isXML );
rob@77 4181
rob@77 4182 if ( set != null ) {
rob@77 4183 expr = expr.replace( Expr.match[ type ], "" );
rob@77 4184 break;
rob@77 4185 }
rob@77 4186 }
rob@77 4187 }
rob@77 4188 }
rob@77 4189
rob@77 4190 if ( !set ) {
rob@77 4191 set = typeof context.getElementsByTagName !== "undefined" ?
rob@77 4192 context.getElementsByTagName( "*" ) :
rob@77 4193 [];
rob@77 4194 }
rob@77 4195
rob@77 4196 return { set: set, expr: expr };
rob@77 4197 };
rob@77 4198
rob@77 4199 Sizzle.filter = function( expr, set, inplace, not ) {
rob@77 4200 var match, anyFound,
rob@77 4201 type, found, item, filter, left,
rob@77 4202 i, pass,
rob@77 4203 old = expr,
rob@77 4204 result = [],
rob@77 4205 curLoop = set,
rob@77 4206 isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
rob@77 4207
rob@77 4208 while ( expr && set.length ) {
rob@77 4209 for ( type in Expr.filter ) {
rob@77 4210 if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
rob@77 4211 filter = Expr.filter[ type ];
rob@77 4212 left = match[1];
rob@77 4213
rob@77 4214 anyFound = false;
rob@77 4215
rob@77 4216 match.splice(1,1);
rob@77 4217
rob@77 4218 if ( left.substr( left.length - 1 ) === "\\" ) {
rob@77 4219 continue;
rob@77 4220 }
rob@77 4221
rob@77 4222 if ( curLoop === result ) {
rob@77 4223 result = [];
rob@77 4224 }
rob@77 4225
rob@77 4226 if ( Expr.preFilter[ type ] ) {
rob@77 4227 match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
rob@77 4228
rob@77 4229 if ( !match ) {
rob@77 4230 anyFound = found = true;
rob@77 4231
rob@77 4232 } else if ( match === true ) {
rob@77 4233 continue;
rob@77 4234 }
rob@77 4235 }
rob@77 4236
rob@77 4237 if ( match ) {
rob@77 4238 for ( i = 0; (item = curLoop[i]) != null; i++ ) {
rob@77 4239 if ( item ) {
rob@77 4240 found = filter( item, match, i, curLoop );
rob@77 4241 pass = not ^ found;
rob@77 4242
rob@77 4243 if ( inplace && found != null ) {
rob@77 4244 if ( pass ) {
rob@77 4245 anyFound = true;
rob@77 4246
rob@77 4247 } else {
rob@77 4248 curLoop[i] = false;
rob@77 4249 }
rob@77 4250
rob@77 4251 } else if ( pass ) {
rob@77 4252 result.push( item );
rob@77 4253 anyFound = true;
rob@77 4254 }
rob@77 4255 }
rob@77 4256 }
rob@77 4257 }
rob@77 4258
rob@77 4259 if ( found !== undefined ) {
rob@77 4260 if ( !inplace ) {
rob@77 4261 curLoop = result;
rob@77 4262 }
rob@77 4263
rob@77 4264 expr = expr.replace( Expr.match[ type ], "" );
rob@77 4265
rob@77 4266 if ( !anyFound ) {
rob@77 4267 return [];
rob@77 4268 }
rob@77 4269
rob@77 4270 break;
rob@77 4271 }
rob@77 4272 }
rob@77 4273 }
rob@77 4274
rob@77 4275 // Improper expression
rob@77 4276 if ( expr === old ) {
rob@77 4277 if ( anyFound == null ) {
rob@77 4278 Sizzle.error( expr );
rob@77 4279
rob@77 4280 } else {
rob@77 4281 break;
rob@77 4282 }
rob@77 4283 }
rob@77 4284
rob@77 4285 old = expr;
rob@77 4286 }
rob@77 4287
rob@77 4288 return curLoop;
rob@77 4289 };
rob@77 4290
rob@77 4291 Sizzle.error = function( msg ) {
rob@77 4292 throw new Error( "Syntax error, unrecognized expression: " + msg );
rob@77 4293 };
rob@77 4294
rob@77 4295 /**
rob@77 4296 * Utility function for retreiving the text value of an array of DOM nodes
rob@77 4297 * @param {Array|Element} elem
rob@77 4298 */
rob@77 4299 var getText = Sizzle.getText = function( elem ) {
rob@77 4300 var i, node,
rob@77 4301 nodeType = elem.nodeType,
rob@77 4302 ret = "";
rob@77 4303
rob@77 4304 if ( nodeType ) {
rob@77 4305 if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
rob@77 4306 // Use textContent || innerText for elements
rob@77 4307 if ( typeof elem.textContent === 'string' ) {
rob@77 4308 return elem.textContent;
rob@77 4309 } else if ( typeof elem.innerText === 'string' ) {
rob@77 4310 // Replace IE's carriage returns
rob@77 4311 return elem.innerText.replace( rReturn, '' );
rob@77 4312 } else {
rob@77 4313 // Traverse it's children
rob@77 4314 for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
rob@77 4315 ret += getText( elem );
rob@77 4316 }
rob@77 4317 }
rob@77 4318 } else if ( nodeType === 3 || nodeType === 4 ) {
rob@77 4319 return elem.nodeValue;
rob@77 4320 }
rob@77 4321 } else {
rob@77 4322
rob@77 4323 // If no nodeType, this is expected to be an array
rob@77 4324 for ( i = 0; (node = elem[i]); i++ ) {
rob@77 4325 // Do not traverse comment nodes
rob@77 4326 if ( node.nodeType !== 8 ) {
rob@77 4327 ret += getText( node );
rob@77 4328 }
rob@77 4329 }
rob@77 4330 }
rob@77 4331 return ret;
rob@77 4332 };
rob@77 4333
rob@77 4334 var Expr = Sizzle.selectors = {
rob@77 4335 order: [ "ID", "NAME", "TAG" ],
rob@77 4336
rob@77 4337 match: {
rob@77 4338 ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
rob@77 4339 CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
rob@77 4340 NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
rob@77 4341 ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
rob@77 4342 TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
rob@77 4343 CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
rob@77 4344 POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
rob@77 4345 PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
rob@77 4346 },
rob@77 4347
rob@77 4348 leftMatch: {},
rob@77 4349
rob@77 4350 attrMap: {
rob@77 4351 "class": "className",
rob@77 4352 "for": "htmlFor"
rob@77 4353 },
rob@77 4354
rob@77 4355 attrHandle: {
rob@77 4356 href: function( elem ) {
rob@77 4357 return elem.getAttribute( "href" );
rob@77 4358 },
rob@77 4359 type: function( elem ) {
rob@77 4360 return elem.getAttribute( "type" );
rob@77 4361 }
rob@77 4362 },
rob@77 4363
rob@77 4364 relative: {
rob@77 4365 "+": function(checkSet, part){
rob@77 4366 var isPartStr = typeof part === "string",
rob@77 4367 isTag = isPartStr && !rNonWord.test( part ),
rob@77 4368 isPartStrNotTag = isPartStr && !isTag;
rob@77 4369
rob@77 4370 if ( isTag ) {
rob@77 4371 part = part.toLowerCase();
rob@77 4372 }
rob@77 4373
rob@77 4374 for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
rob@77 4375 if ( (elem = checkSet[i]) ) {
rob@77 4376 while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
rob@77 4377
rob@77 4378 checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
rob@77 4379 elem || false :
rob@77 4380 elem === part;
rob@77 4381 }
rob@77 4382 }
rob@77 4383
rob@77 4384 if ( isPartStrNotTag ) {
rob@77 4385 Sizzle.filter( part, checkSet, true );
rob@77 4386 }
rob@77 4387 },
rob@77 4388
rob@77 4389 ">": function( checkSet, part ) {
rob@77 4390 var elem,
rob@77 4391 isPartStr = typeof part === "string",
rob@77 4392 i = 0,
rob@77 4393 l = checkSet.length;
rob@77 4394
rob@77 4395 if ( isPartStr && !rNonWord.test( part ) ) {
rob@77 4396 part = part.toLowerCase();
rob@77 4397
rob@77 4398 for ( ; i < l; i++ ) {
rob@77 4399 elem = checkSet[i];
rob@77 4400
rob@77 4401 if ( elem ) {
rob@77 4402 var parent = elem.parentNode;
rob@77 4403 checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
rob@77 4404 }
rob@77 4405 }
rob@77 4406
rob@77 4407 } else {
rob@77 4408 for ( ; i < l; i++ ) {
rob@77 4409 elem = checkSet[i];
rob@77 4410
rob@77 4411 if ( elem ) {
rob@77 4412 checkSet[i] = isPartStr ?
rob@77 4413 elem.parentNode :
rob@77 4414 elem.parentNode === part;
rob@77 4415 }
rob@77 4416 }
rob@77 4417
rob@77 4418 if ( isPartStr ) {
rob@77 4419 Sizzle.filter( part, checkSet, true );
rob@77 4420 }
rob@77 4421 }
rob@77 4422 },
rob@77 4423
rob@77 4424 "": function(checkSet, part, isXML){
rob@77 4425 var nodeCheck,
rob@77 4426 doneName = done++,
rob@77 4427 checkFn = dirCheck;
rob@77 4428
rob@77 4429 if ( typeof part === "string" && !rNonWord.test( part ) ) {
rob@77 4430 part = part.toLowerCase();
rob@77 4431 nodeCheck = part;
rob@77 4432 checkFn = dirNodeCheck;
rob@77 4433 }
rob@77 4434
rob@77 4435 checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
rob@77 4436 },
rob@77 4437
rob@77 4438 "~": function( checkSet, part, isXML ) {
rob@77 4439 var nodeCheck,
rob@77 4440 doneName = done++,
rob@77 4441 checkFn = dirCheck;
rob@77 4442
rob@77 4443 if ( typeof part === "string" && !rNonWord.test( part ) ) {
rob@77 4444 part = part.toLowerCase();
rob@77 4445 nodeCheck = part;
rob@77 4446 checkFn = dirNodeCheck;
rob@77 4447 }
rob@77 4448
rob@77 4449 checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
rob@77 4450 }
rob@77 4451 },
rob@77 4452
rob@77 4453 find: {
rob@77 4454 ID: function( match, context, isXML ) {
rob@77 4455 if ( typeof context.getElementById !== "undefined" && !isXML ) {
rob@77 4456 var m = context.getElementById(match[1]);
rob@77 4457 // Check parentNode to catch when Blackberry 4.6 returns
rob@77 4458 // nodes that are no longer in the document #6963
rob@77 4459 return m && m.parentNode ? [m] : [];
rob@77 4460 }
rob@77 4461 },
rob@77 4462
rob@77 4463 NAME: function( match, context ) {
rob@77 4464 if ( typeof context.getElementsByName !== "undefined" ) {
rob@77 4465 var ret = [],
rob@77 4466 results = context.getElementsByName( match[1] );
rob@77 4467
rob@77 4468 for ( var i = 0, l = results.length; i < l; i++ ) {
rob@77 4469 if ( results[i].getAttribute("name") === match[1] ) {
rob@77 4470 ret.push( results[i] );
rob@77 4471 }
rob@77 4472 }
rob@77 4473
rob@77 4474 return ret.length === 0 ? null : ret;
rob@77 4475 }
rob@77 4476 },
rob@77 4477
rob@77 4478 TAG: function( match, context ) {
rob@77 4479 if ( typeof context.getElementsByTagName !== "undefined" ) {
rob@77 4480 return context.getElementsByTagName( match[1] );
rob@77 4481 }
rob@77 4482 }
rob@77 4483 },
rob@77 4484 preFilter: {
rob@77 4485 CLASS: function( match, curLoop, inplace, result, not, isXML ) {
rob@77 4486 match = " " + match[1].replace( rBackslash, "" ) + " ";
rob@77 4487
rob@77 4488 if ( isXML ) {
rob@77 4489 return match;
rob@77 4490 }
rob@77 4491
rob@77 4492 for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
rob@77 4493 if ( elem ) {
rob@77 4494 if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
rob@77 4495 if ( !inplace ) {
rob@77 4496 result.push( elem );
rob@77 4497 }
rob@77 4498
rob@77 4499 } else if ( inplace ) {
rob@77 4500 curLoop[i] = false;
rob@77 4501 }
rob@77 4502 }
rob@77 4503 }
rob@77 4504
rob@77 4505 return false;
rob@77 4506 },
rob@77 4507
rob@77 4508 ID: function( match ) {
rob@77 4509 return match[1].replace( rBackslash, "" );
rob@77 4510 },
rob@77 4511
rob@77 4512 TAG: function( match, curLoop ) {
rob@77 4513 return match[1].replace( rBackslash, "" ).toLowerCase();
rob@77 4514 },
rob@77 4515
rob@77 4516 CHILD: function( match ) {
rob@77 4517 if ( match[1] === "nth" ) {
rob@77 4518 if ( !match[2] ) {
rob@77 4519 Sizzle.error( match[0] );
rob@77 4520 }
rob@77 4521
rob@77 4522 match[2] = match[2].replace(/^\+|\s*/g, '');
rob@77 4523
rob@77 4524 // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
rob@77 4525 var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
rob@77 4526 match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
rob@77 4527 !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
rob@77 4528
rob@77 4529 // calculate the numbers (first)n+(last) including if they are negative
rob@77 4530 match[2] = (test[1] + (test[2] || 1)) - 0;
rob@77 4531 match[3] = test[3] - 0;
rob@77 4532 }
rob@77 4533 else if ( match[2] ) {
rob@77 4534 Sizzle.error( match[0] );
rob@77 4535 }
rob@77 4536
rob@77 4537 // TODO: Move to normal caching system
rob@77 4538 match[0] = done++;
rob@77 4539
rob@77 4540 return match;
rob@77 4541 },
rob@77 4542
rob@77 4543 ATTR: function( match, curLoop, inplace, result, not, isXML ) {
rob@77 4544 var name = match[1] = match[1].replace( rBackslash, "" );
rob@77 4545
rob@77 4546 if ( !isXML && Expr.attrMap[name] ) {
rob@77 4547 match[1] = Expr.attrMap[name];
rob@77 4548 }
rob@77 4549
rob@77 4550 // Handle if an un-quoted value was used
rob@77 4551 match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
rob@77 4552
rob@77 4553 if ( match[2] === "~=" ) {
rob@77 4554 match[4] = " " + match[4] + " ";
rob@77 4555 }
rob@77 4556
rob@77 4557 return match;
rob@77 4558 },
rob@77 4559
rob@77 4560 PSEUDO: function( match, curLoop, inplace, result, not ) {
rob@77 4561 if ( match[1] === "not" ) {
rob@77 4562 // If we're dealing with a complex expression, or a simple one
rob@77 4563 if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
rob@77 4564 match[3] = Sizzle(match[3], null, null, curLoop);
rob@77 4565
rob@77 4566 } else {
rob@77 4567 var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
rob@77 4568
rob@77 4569 if ( !inplace ) {
rob@77 4570 result.push.apply( result, ret );
rob@77 4571 }
rob@77 4572
rob@77 4573 return false;
rob@77 4574 }
rob@77 4575
rob@77 4576 } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
rob@77 4577 return true;
rob@77 4578 }
rob@77 4579
rob@77 4580 return match;
rob@77 4581 },
rob@77 4582
rob@77 4583 POS: function( match ) {
rob@77 4584 match.unshift( true );
rob@77 4585
rob@77 4586 return match;
rob@77 4587 }
rob@77 4588 },
rob@77 4589
rob@77 4590 filters: {
rob@77 4591 enabled: function( elem ) {
rob@77 4592 return elem.disabled === false && elem.type !== "hidden";
rob@77 4593 },
rob@77 4594
rob@77 4595 disabled: function( elem ) {
rob@77 4596 return elem.disabled === true;
rob@77 4597 },
rob@77 4598
rob@77 4599 checked: function( elem ) {
rob@77 4600 return elem.checked === true;
rob@77 4601 },
rob@77 4602
rob@77 4603 selected: function( elem ) {
rob@77 4604 // Accessing this property makes selected-by-default
rob@77 4605 // options in Safari work properly
rob@77 4606 if ( elem.parentNode ) {
rob@77 4607 elem.parentNode.selectedIndex;
rob@77 4608 }
rob@77 4609
rob@77 4610 return elem.selected === true;
rob@77 4611 },
rob@77 4612
rob@77 4613 parent: function( elem ) {
rob@77 4614 return !!elem.firstChild;
rob@77 4615 },
rob@77 4616
rob@77 4617 empty: function( elem ) {
rob@77 4618 return !elem.firstChild;
rob@77 4619 },
rob@77 4620
rob@77 4621 has: function( elem, i, match ) {
rob@77 4622 return !!Sizzle( match[3], elem ).length;
rob@77 4623 },
rob@77 4624
rob@77 4625 header: function( elem ) {
rob@77 4626 return (/h\d/i).test( elem.nodeName );
rob@77 4627 },
rob@77 4628
rob@77 4629 text: function( elem ) {
rob@77 4630 var attr = elem.getAttribute( "type" ), type = elem.type;
rob@77 4631 // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
rob@77 4632 // use getAttribute instead to test this case
rob@77 4633 return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
rob@77 4634 },
rob@77 4635
rob@77 4636 radio: function( elem ) {
rob@77 4637 return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
rob@77 4638 },
rob@77 4639
rob@77 4640 checkbox: function( elem ) {
rob@77 4641 return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
rob@77 4642 },
rob@77 4643
rob@77 4644 file: function( elem ) {
rob@77 4645 return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
rob@77 4646 },
rob@77 4647
rob@77 4648 password: function( elem ) {
rob@77 4649 return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
rob@77 4650 },
rob@77 4651
rob@77 4652 submit: function( elem ) {
rob@77 4653 var name = elem.nodeName.toLowerCase();
rob@77 4654 return (name === "input" || name === "button") && "submit" === elem.type;
rob@77 4655 },
rob@77 4656
rob@77 4657 image: function( elem ) {
rob@77 4658 return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
rob@77 4659 },
rob@77 4660
rob@77 4661 reset: function( elem ) {
rob@77 4662 var name = elem.nodeName.toLowerCase();
rob@77 4663 return (name === "input" || name === "button") && "reset" === elem.type;
rob@77 4664 },
rob@77 4665
rob@77 4666 button: function( elem ) {
rob@77 4667 var name = elem.nodeName.toLowerCase();
rob@77 4668 return name === "input" && "button" === elem.type || name === "button";
rob@77 4669 },
rob@77 4670
rob@77 4671 input: function( elem ) {
rob@77 4672 return (/input|select|textarea|button/i).test( elem.nodeName );
rob@77 4673 },
rob@77 4674
rob@77 4675 focus: function( elem ) {
rob@77 4676 return elem === elem.ownerDocument.activeElement;
rob@77 4677 }
rob@77 4678 },
rob@77 4679 setFilters: {
rob@77 4680 first: function( elem, i ) {
rob@77 4681 return i === 0;
rob@77 4682 },
rob@77 4683
rob@77 4684 last: function( elem, i, match, array ) {
rob@77 4685 return i === array.length - 1;
rob@77 4686 },
rob@77 4687
rob@77 4688 even: function( elem, i ) {
rob@77 4689 return i % 2 === 0;
rob@77 4690 },
rob@77 4691
rob@77 4692 odd: function( elem, i ) {
rob@77 4693 return i % 2 === 1;
rob@77 4694 },
rob@77 4695
rob@77 4696 lt: function( elem, i, match ) {
rob@77 4697 return i < match[3] - 0;
rob@77 4698 },
rob@77 4699
rob@77 4700 gt: function( elem, i, match ) {
rob@77 4701 return i > match[3] - 0;
rob@77 4702 },
rob@77 4703
rob@77 4704 nth: function( elem, i, match ) {
rob@77 4705 return match[3] - 0 === i;
rob@77 4706 },
rob@77 4707
rob@77 4708 eq: function( elem, i, match ) {
rob@77 4709 return match[3] - 0 === i;
rob@77 4710 }
rob@77 4711 },
rob@77 4712 filter: {
rob@77 4713 PSEUDO: function( elem, match, i, array ) {
rob@77 4714 var name = match[1],
rob@77 4715 filter = Expr.filters[ name ];
rob@77 4716
rob@77 4717 if ( filter ) {
rob@77 4718 return filter( elem, i, match, array );
rob@77 4719
rob@77 4720 } else if ( name === "contains" ) {
rob@77 4721 return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;
rob@77 4722
rob@77 4723 } else if ( name === "not" ) {
rob@77 4724 var not = match[3];
rob@77 4725
rob@77 4726 for ( var j = 0, l = not.length; j < l; j++ ) {
rob@77 4727 if ( not[j] === elem ) {
rob@77 4728 return false;
rob@77 4729 }
rob@77 4730 }
rob@77 4731
rob@77 4732 return true;
rob@77 4733
rob@77 4734 } else {
rob@77 4735 Sizzle.error( name );
rob@77 4736 }
rob@77 4737 },
rob@77 4738
rob@77 4739 CHILD: function( elem, match ) {
rob@77 4740 var first, last,
rob@77 4741 doneName, parent, cache,
rob@77 4742 count, diff,
rob@77 4743 type = match[1],
rob@77 4744 node = elem;
rob@77 4745
rob@77 4746 switch ( type ) {
rob@77 4747 case "only":
rob@77 4748 case "first":
rob@77 4749 while ( (node = node.previousSibling) ) {
rob@77 4750 if ( node.nodeType === 1 ) {
rob@77 4751 return false;
rob@77 4752 }
rob@77 4753 }
rob@77 4754
rob@77 4755 if ( type === "first" ) {
rob@77 4756 return true;
rob@77 4757 }
rob@77 4758
rob@77 4759 node = elem;
rob@77 4760
rob@77 4761 /* falls through */
rob@77 4762 case "last":
rob@77 4763 while ( (node = node.nextSibling) ) {
rob@77 4764 if ( node.nodeType === 1 ) {
rob@77 4765 return false;
rob@77 4766 }
rob@77 4767 }
rob@77 4768
rob@77 4769 return true;
rob@77 4770
rob@77 4771 case "nth":
rob@77 4772 first = match[2];
rob@77 4773 last = match[3];
rob@77 4774
rob@77 4775 if ( first === 1 && last === 0 ) {
rob@77 4776 return true;
rob@77 4777 }
rob@77 4778
rob@77 4779 doneName = match[0];
rob@77 4780 parent = elem.parentNode;
rob@77 4781
rob@77 4782 if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
rob@77 4783 count = 0;
rob@77 4784
rob@77 4785 for ( node = parent.firstChild; node; node = node.nextSibling ) {
rob@77 4786 if ( node.nodeType === 1 ) {
rob@77 4787 node.nodeIndex = ++count;
rob@77 4788 }
rob@77 4789 }
rob@77 4790
rob@77 4791 parent[ expando ] = doneName;
rob@77 4792 }
rob@77 4793
rob@77 4794 diff = elem.nodeIndex - last;
rob@77 4795
rob@77 4796 if ( first === 0 ) {
rob@77 4797 return diff === 0;
rob@77 4798
rob@77 4799 } else {
rob@77 4800 return ( diff % first === 0 && diff / first >= 0 );
rob@77 4801 }
rob@77 4802 }
rob@77 4803 },
rob@77 4804
rob@77 4805 ID: function( elem, match ) {
rob@77 4806 return elem.nodeType === 1 && elem.getAttribute("id") === match;
rob@77 4807 },
rob@77 4808
rob@77 4809 TAG: function( elem, match ) {
rob@77 4810 return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
rob@77 4811 },
rob@77 4812
rob@77 4813 CLASS: function( elem, match ) {
rob@77 4814 return (" " + (elem.className || elem.getAttribute("class")) + " ")
rob@77 4815 .indexOf( match ) > -1;
rob@77 4816 },
rob@77 4817
rob@77 4818 ATTR: function( elem, match ) {
rob@77 4819 var name = match[1],
rob@77 4820 result = Sizzle.attr ?
rob@77 4821 Sizzle.attr( elem, name ) :
rob@77 4822 Expr.attrHandle[ name ] ?
rob@77 4823 Expr.attrHandle[ name ]( elem ) :
rob@77 4824 elem[ name ] != null ?
rob@77 4825 elem[ name ] :
rob@77 4826 elem.getAttribute( name ),
rob@77 4827 value = result + "",
rob@77 4828 type = match[2],
rob@77 4829 check = match[4];
rob@77 4830
rob@77 4831 return result == null ?
rob@77 4832 type === "!=" :
rob@77 4833 !type && Sizzle.attr ?
rob@77 4834 result != null :
rob@77 4835 type === "=" ?
rob@77 4836 value === check :
rob@77 4837 type === "*=" ?
rob@77 4838 value.indexOf(check) >= 0 :
rob@77 4839 type === "~=" ?
rob@77 4840 (" " + value + " ").indexOf(check) >= 0 :
rob@77 4841 !check ?
rob@77 4842 value && result !== false :
rob@77 4843 type === "!=" ?
rob@77 4844 value !== check :
rob@77 4845 type === "^=" ?
rob@77 4846 value.indexOf(check) === 0 :
rob@77 4847 type === "$=" ?
rob@77 4848 value.substr(value.length - check.length) === check :
rob@77 4849 type === "|=" ?
rob@77 4850 value === check || value.substr(0, check.length + 1) === check + "-" :
rob@77 4851 false;
rob@77 4852 },
rob@77 4853
rob@77 4854 POS: function( elem, match, i, array ) {
rob@77 4855 var name = match[2],
rob@77 4856 filter = Expr.setFilters[ name ];
rob@77 4857
rob@77 4858 if ( filter ) {
rob@77 4859 return filter( elem, i, match, array );
rob@77 4860 }
rob@77 4861 }
rob@77 4862 }
rob@77 4863 };
rob@77 4864
rob@77 4865 var origPOS = Expr.match.POS,
rob@77 4866 fescape = function(all, num){
rob@77 4867 return "\\" + (num - 0 + 1);
rob@77 4868 };
rob@77 4869
rob@77 4870 for ( var type in Expr.match ) {
rob@77 4871 Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
rob@77 4872 Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
rob@77 4873 }
rob@77 4874 // Expose origPOS
rob@77 4875 // "global" as in regardless of relation to brackets/parens
rob@77 4876 Expr.match.globalPOS = origPOS;
rob@77 4877
rob@77 4878 var makeArray = function( array, results ) {
rob@77 4879 array = Array.prototype.slice.call( array, 0 );
rob@77 4880
rob@77 4881 if ( results ) {
rob@77 4882 results.push.apply( results, array );
rob@77 4883 return results;
rob@77 4884 }
rob@77 4885
rob@77 4886 return array;
rob@77 4887 };
rob@77 4888
rob@77 4889 // Perform a simple check to determine if the browser is capable of
rob@77 4890 // converting a NodeList to an array using builtin methods.
rob@77 4891 // Also verifies that the returned array holds DOM nodes
rob@77 4892 // (which is not the case in the Blackberry browser)
rob@77 4893 try {
rob@77 4894 Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
rob@77 4895
rob@77 4896 // Provide a fallback method if it does not work
rob@77 4897 } catch( e ) {
rob@77 4898 makeArray = function( array, results ) {
rob@77 4899 var i = 0,
rob@77 4900 ret = results || [];
rob@77 4901
rob@77 4902 if ( toString.call(array) === "[object Array]" ) {
rob@77 4903 Array.prototype.push.apply( ret, array );
rob@77 4904
rob@77 4905 } else {
rob@77 4906 if ( typeof array.length === "number" ) {
rob@77 4907 for ( var l = array.length; i < l; i++ ) {
rob@77 4908 ret.push( array[i] );
rob@77 4909 }
rob@77 4910
rob@77 4911 } else {
rob@77 4912 for ( ; array[i]; i++ ) {
rob@77 4913 ret.push( array[i] );
rob@77 4914 }
rob@77 4915 }
rob@77 4916 }
rob@77 4917
rob@77 4918 return ret;
rob@77 4919 };
rob@77 4920 }
rob@77 4921
rob@77 4922 var sortOrder, siblingCheck;
rob@77 4923
rob@77 4924 if ( document.documentElement.compareDocumentPosition ) {
rob@77 4925 sortOrder = function( a, b ) {
rob@77 4926 if ( a === b ) {
rob@77 4927 hasDuplicate = true;
rob@77 4928 return 0;
rob@77 4929 }
rob@77 4930
rob@77 4931 if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
rob@77 4932 return a.compareDocumentPosition ? -1 : 1;
rob@77 4933 }
rob@77 4934
rob@77 4935 return a.compareDocumentPosition(b) & 4 ? -1 : 1;
rob@77 4936 };
rob@77 4937
rob@77 4938 } else {
rob@77 4939 sortOrder = function( a, b ) {
rob@77 4940 // The nodes are identical, we can exit early
rob@77 4941 if ( a === b ) {
rob@77 4942 hasDuplicate = true;
rob@77 4943 return 0;
rob@77 4944
rob@77 4945 // Fallback to using sourceIndex (in IE) if it's available on both nodes
rob@77 4946 } else if ( a.sourceIndex && b.sourceIndex ) {
rob@77 4947 return a.sourceIndex - b.sourceIndex;
rob@77 4948 }
rob@77 4949
rob@77 4950 var al, bl,
rob@77 4951 ap = [],
rob@77 4952 bp = [],
rob@77 4953 aup = a.parentNode,
rob@77 4954 bup = b.parentNode,
rob@77 4955 cur = aup;
rob@77 4956
rob@77 4957 // If the nodes are siblings (or identical) we can do a quick check
rob@77 4958 if ( aup === bup ) {
rob@77 4959 return siblingCheck( a, b );
rob@77 4960
rob@77 4961 // If no parents were found then the nodes are disconnected
rob@77 4962 } else if ( !aup ) {
rob@77 4963 return -1;
rob@77 4964
rob@77 4965 } else if ( !bup ) {
rob@77 4966 return 1;
rob@77 4967 }
rob@77 4968
rob@77 4969 // Otherwise they're somewhere else in the tree so we need
rob@77 4970 // to build up a full list of the parentNodes for comparison
rob@77 4971 while ( cur ) {
rob@77 4972 ap.unshift( cur );
rob@77 4973 cur = cur.parentNode;
rob@77 4974 }
rob@77 4975
rob@77 4976 cur = bup;
rob@77 4977
rob@77 4978 while ( cur ) {
rob@77 4979 bp.unshift( cur );
rob@77 4980 cur = cur.parentNode;
rob@77 4981 }
rob@77 4982
rob@77 4983 al = ap.length;
rob@77 4984 bl = bp.length;
rob@77 4985
rob@77 4986 // Start walking down the tree looking for a discrepancy
rob@77 4987 for ( var i = 0; i < al && i < bl; i++ ) {
rob@77 4988 if ( ap[i] !== bp[i] ) {
rob@77 4989 return siblingCheck( ap[i], bp[i] );
rob@77 4990 }
rob@77 4991 }
rob@77 4992
rob@77 4993 // We ended someplace up the tree so do a sibling check
rob@77 4994 return i === al ?
rob@77 4995 siblingCheck( a, bp[i], -1 ) :
rob@77 4996 siblingCheck( ap[i], b, 1 );
rob@77 4997 };
rob@77 4998
rob@77 4999 siblingCheck = function( a, b, ret ) {
rob@77 5000 if ( a === b ) {
rob@77 5001 return ret;
rob@77 5002 }
rob@77 5003
rob@77 5004 var cur = a.nextSibling;
rob@77 5005
rob@77 5006 while ( cur ) {
rob@77 5007 if ( cur === b ) {
rob@77 5008 return -1;
rob@77 5009 }
rob@77 5010
rob@77 5011 cur = cur.nextSibling;
rob@77 5012 }
rob@77 5013
rob@77 5014 return 1;
rob@77 5015 };
rob@77 5016 }
rob@77 5017
rob@77 5018 // Check to see if the browser returns elements by name when
rob@77 5019 // querying by getElementById (and provide a workaround)
rob@77 5020 (function(){
rob@77 5021 // We're going to inject a fake input element with a specified name
rob@77 5022 var form = document.createElement("div"),
rob@77 5023 id = "script" + (new Date()).getTime(),
rob@77 5024 root = document.documentElement;
rob@77 5025
rob@77 5026 form.innerHTML = "<a name='" + id + "'/>";
rob@77 5027
rob@77 5028 // Inject it into the root element, check its status, and remove it quickly
rob@77 5029 root.insertBefore( form, root.firstChild );
rob@77 5030
rob@77 5031 // The workaround has to do additional checks after a getElementById
rob@77 5032 // Which slows things down for other browsers (hence the branching)
rob@77 5033 if ( document.getElementById( id ) ) {
rob@77 5034 Expr.find.ID = function( match, context, isXML ) {
rob@77 5035 if ( typeof context.getElementById !== "undefined" && !isXML ) {
rob@77 5036 var m = context.getElementById(match[1]);
rob@77 5037
rob@77 5038 return m ?
rob@77 5039 m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
rob@77 5040 [m] :
rob@77 5041 undefined :
rob@77 5042 [];
rob@77 5043 }
rob@77 5044 };
rob@77 5045
rob@77 5046 Expr.filter.ID = function( elem, match ) {
rob@77 5047 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
rob@77 5048
rob@77 5049 return elem.nodeType === 1 && node && node.nodeValue === match;
rob@77 5050 };
rob@77 5051 }
rob@77 5052
rob@77 5053 root.removeChild( form );
rob@77 5054
rob@77 5055 // release memory in IE
rob@77 5056 root = form = null;
rob@77 5057 })();
rob@77 5058
rob@77 5059 (function(){
rob@77 5060 // Check to see if the browser returns only elements
rob@77 5061 // when doing getElementsByTagName("*")
rob@77 5062
rob@77 5063 // Create a fake element
rob@77 5064 var div = document.createElement("div");
rob@77 5065 div.appendChild( document.createComment("") );
rob@77 5066
rob@77 5067 // Make sure no comments are found
rob@77 5068 if ( div.getElementsByTagName("*").length > 0 ) {
rob@77 5069 Expr.find.TAG = function( match, context ) {
rob@77 5070 var results = context.getElementsByTagName( match[1] );
rob@77 5071
rob@77 5072 // Filter out possible comments
rob@77 5073 if ( match[1] === "*" ) {
rob@77 5074 var tmp = [];
rob@77 5075
rob@77 5076 for ( var i = 0; results[i]; i++ ) {
rob@77 5077 if ( results[i].nodeType === 1 ) {
rob@77 5078 tmp.push( results[i] );
rob@77 5079 }
rob@77 5080 }
rob@77 5081
rob@77 5082 results = tmp;
rob@77 5083 }
rob@77 5084
rob@77 5085 return results;
rob@77 5086 };
rob@77 5087 }
rob@77 5088
rob@77 5089 // Check to see if an attribute returns normalized href attributes
rob@77 5090 div.innerHTML = "<a href='#'></a>";
rob@77 5091
rob@77 5092 if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
rob@77 5093 div.firstChild.getAttribute("href") !== "#" ) {
rob@77 5094
rob@77 5095 Expr.attrHandle.href = function( elem ) {
rob@77 5096 return elem.getAttribute( "href", 2 );
rob@77 5097 };
rob@77 5098 }
rob@77 5099
rob@77 5100 // release memory in IE
rob@77 5101 div = null;
rob@77 5102 })();
rob@77 5103
rob@77 5104 if ( document.querySelectorAll ) {
rob@77 5105 (function(){
rob@77 5106 var oldSizzle = Sizzle,
rob@77 5107 div = document.createElement("div"),
rob@77 5108 id = "__sizzle__";
rob@77 5109
rob@77 5110 div.innerHTML = "<p class='TEST'></p>";
rob@77 5111
rob@77 5112 // Safari can't handle uppercase or unicode characters when
rob@77 5113 // in quirks mode.
rob@77 5114 if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
rob@77 5115 return;
rob@77 5116 }
rob@77 5117
rob@77 5118 Sizzle = function( query, context, extra, seed ) {
rob@77 5119 context = context || document;
rob@77 5120
rob@77 5121 // Only use querySelectorAll on non-XML documents
rob@77 5122 // (ID selectors don't work in non-HTML documents)
rob@77 5123 if ( !seed && !Sizzle.isXML(context) ) {
rob@77 5124 // See if we find a selector to speed up
rob@77 5125 var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
rob@77 5126
rob@77 5127 if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
rob@77 5128 // Speed-up: Sizzle("TAG")
rob@77 5129 if ( match[1] ) {
rob@77 5130 return makeArray( context.getElementsByTagName( query ), extra );
rob@77 5131
rob@77 5132 // Speed-up: Sizzle(".CLASS")
rob@77 5133 } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
rob@77 5134 return makeArray( context.getElementsByClassName( match[2] ), extra );
rob@77 5135 }
rob@77 5136 }
rob@77 5137
rob@77 5138 if ( context.nodeType === 9 ) {
rob@77 5139 // Speed-up: Sizzle("body")
rob@77 5140 // The body element only exists once, optimize finding it
rob@77 5141 if ( query === "body" && context.body ) {
rob@77 5142 return makeArray( [ context.body ], extra );
rob@77 5143
rob@77 5144 // Speed-up: Sizzle("#ID")
rob@77 5145 } else if ( match && match[3] ) {
rob@77 5146 var elem = context.getElementById( match[3] );
rob@77 5147
rob@77 5148 // Check parentNode to catch when Blackberry 4.6 returns
rob@77 5149 // nodes that are no longer in the document #6963
rob@77 5150 if ( elem && elem.parentNode ) {
rob@77 5151 // Handle the case where IE and Opera return items
rob@77 5152 // by name instead of ID
rob@77 5153 if ( elem.id === match[3] ) {
rob@77 5154 return makeArray( [ elem ], extra );
rob@77 5155 }
rob@77 5156
rob@77 5157 } else {
rob@77 5158 return makeArray( [], extra );
rob@77 5159 }
rob@77 5160 }
rob@77 5161
rob@77 5162 try {
rob@77 5163 return makeArray( context.querySelectorAll(query), extra );
rob@77 5164 } catch(qsaError) {}
rob@77 5165
rob@77 5166 // qSA works strangely on Element-rooted queries
rob@77 5167 // We can work around this by specifying an extra ID on the root
rob@77 5168 // and working up from there (Thanks to Andrew Dupont for the technique)
rob@77 5169 // IE 8 doesn't work on object elements
rob@77 5170 } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
rob@77 5171 var oldContext = context,
rob@77 5172 old = context.getAttribute( "id" ),
rob@77 5173 nid = old || id,
rob@77 5174 hasParent = context.parentNode,
rob@77 5175 relativeHierarchySelector = /^\s*[+~]/.test( query );
rob@77 5176
rob@77 5177 if ( !old ) {
rob@77 5178 context.setAttribute( "id", nid );
rob@77 5179 } else {
rob@77 5180 nid = nid.replace( /'/g, "\\//JQUERY_SOURCE" );
rob@77 5181 }
rob@77 5182 if ( relativeHierarchySelector && hasParent ) {
rob@77 5183 context = context.parentNode;
rob@77 5184 }
rob@77 5185
rob@77 5186 try {
rob@77 5187 if ( !relativeHierarchySelector || hasParent ) {
rob@77 5188 return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
rob@77 5189 }
rob@77 5190
rob@77 5191 } catch(pseudoError) {
rob@77 5192 } finally {
rob@77 5193 if ( !old ) {
rob@77 5194 oldContext.removeAttribute( "id" );
rob@77 5195 }
rob@77 5196 }
rob@77 5197 }
rob@77 5198 }
rob@77 5199
rob@77 5200 return oldSizzle(query, context, extra, seed);
rob@77 5201 };
rob@77 5202
rob@77 5203 for ( var prop in oldSizzle ) {
rob@77 5204 Sizzle[ prop ] = oldSizzle[ prop ];
rob@77 5205 }
rob@77 5206
rob@77 5207 // release memory in IE
rob@77 5208 div = null;
rob@77 5209 })();
rob@77 5210 }
rob@77 5211
rob@77 5212 (function(){
rob@77 5213 var html = document.documentElement,
rob@77 5214 matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
rob@77 5215
rob@77 5216 if ( matches ) {
rob@77 5217 // Check to see if it's possible to do matchesSelector
rob@77 5218 // on a disconnected node (IE 9 fails this)
rob@77 5219 var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
rob@77 5220 pseudoWorks = false;
rob@77 5221
rob@77 5222 try {
rob@77 5223 // This should fail with an exception
rob@77 5224 // Gecko does not error, returns false instead
rob@77 5225 matches.call( document.documentElement, "[test!='']:sizzle" );
rob@77 5226
rob@77 5227 } catch( pseudoError ) {
rob@77 5228 pseudoWorks = true;
rob@77 5229 }
rob@77 5230
rob@77 5231 Sizzle.matchesSelector = function( node, expr ) {
rob@77 5232 // Make sure that attribute selectors are quoted
rob@77 5233 expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
rob@77 5234
rob@77 5235 if ( !Sizzle.isXML( node ) ) {
rob@77 5236 try {
rob@77 5237 if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
rob@77 5238 var ret = matches.call( node, expr );
rob@77 5239
rob@77 5240 // IE 9's matchesSelector returns false on disconnected nodes
rob@77 5241 if ( ret || !disconnectedMatch ||
rob@77 5242 // As well, disconnected nodes are said to be in a document
rob@77 5243 // fragment in IE 9, so check for that
rob@77 5244 node.document && node.document.nodeType !== 11 ) {
rob@77 5245 return ret;
rob@77 5246 }
rob@77 5247 }
rob@77 5248 } catch(e) {}
rob@77 5249 }
rob@77 5250
rob@77 5251 return Sizzle(expr, null, null, [node]).length > 0;
rob@77 5252 };
rob@77 5253 }
rob@77 5254 })();
rob@77 5255
rob@77 5256 (function(){
rob@77 5257 var div = document.createElement("div");
rob@77 5258
rob@77 5259 div.innerHTML = "<div class='test e'></div><div class='test'></div>";
rob@77 5260
rob@77 5261 // Opera can't find a second classname (in 9.6)
rob@77 5262 // Also, make sure that getElementsByClassName actually exists
rob@77 5263 if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
rob@77 5264 return;
rob@77 5265 }
rob@77 5266
rob@77 5267 // Safari caches class attributes, doesn't catch changes (in 3.2)
rob@77 5268 div.lastChild.className = "e";
rob@77 5269
rob@77 5270 if ( div.getElementsByClassName("e").length === 1 ) {
rob@77 5271 return;
rob@77 5272 }
rob@77 5273
rob@77 5274 Expr.order.splice(1, 0, "CLASS");
rob@77 5275 Expr.find.CLASS = function( match, context, isXML ) {
rob@77 5276 if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
rob@77 5277 return context.getElementsByClassName(match[1]);
rob@77 5278 }
rob@77 5279 };
rob@77 5280
rob@77 5281 // release memory in IE
rob@77 5282 div = null;
rob@77 5283 })();
rob@77 5284
rob@77 5285 function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
rob@77 5286 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
rob@77 5287 var elem = checkSet[i];
rob@77 5288
rob@77 5289 if ( elem ) {
rob@77 5290 var match = false;
rob@77 5291
rob@77 5292 elem = elem[dir];
rob@77 5293
rob@77 5294 while ( elem ) {
rob@77 5295 if ( elem[ expando ] === doneName ) {
rob@77 5296 match = checkSet[elem.sizset];
rob@77 5297 break;
rob@77 5298 }
rob@77 5299
rob@77 5300 if ( elem.nodeType === 1 && !isXML ){
rob@77 5301 elem[ expando ] = doneName;
rob@77 5302 elem.sizset = i;
rob@77 5303 }
rob@77 5304
rob@77 5305 if ( elem.nodeName.toLowerCase() === cur ) {
rob@77 5306 match = elem;
rob@77 5307 break;
rob@77 5308 }
rob@77 5309
rob@77 5310 elem = elem[dir];
rob@77 5311 }
rob@77 5312
rob@77 5313 checkSet[i] = match;
rob@77 5314 }
rob@77 5315 }
rob@77 5316 }
rob@77 5317
rob@77 5318 function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
rob@77 5319 for ( var i = 0, l = checkSet.length; i < l; i++ ) {
rob@77 5320 var elem = checkSet[i];
rob@77 5321
rob@77 5322 if ( elem ) {
rob@77 5323 var match = false;
rob@77 5324
rob@77 5325 elem = elem[dir];
rob@77 5326
rob@77 5327 while ( elem ) {
rob@77 5328 if ( elem[ expando ] === doneName ) {
rob@77 5329 match = checkSet[elem.sizset];
rob@77 5330 break;
rob@77 5331 }
rob@77 5332
rob@77 5333 if ( elem.nodeType === 1 ) {
rob@77 5334 if ( !isXML ) {
rob@77 5335 elem[ expando ] = doneName;
rob@77 5336 elem.sizset = i;
rob@77 5337 }
rob@77 5338
rob@77 5339 if ( typeof cur !== "string" ) {
rob@77 5340 if ( elem === cur ) {
rob@77 5341 match = true;
rob@77 5342 break;
rob@77 5343 }
rob@77 5344
rob@77 5345 } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
rob@77 5346 match = elem;
rob@77 5347 break;
rob@77 5348 }
rob@77 5349 }
rob@77 5350
rob@77 5351 elem = elem[dir];
rob@77 5352 }
rob@77 5353
rob@77 5354 checkSet[i] = match;
rob@77 5355 }
rob@77 5356 }
rob@77 5357 }
rob@77 5358
rob@77 5359 if ( document.documentElement.contains ) {
rob@77 5360 Sizzle.contains = function( a, b ) {
rob@77 5361 return a !== b && (a.contains ? a.contains(b) : true);
rob@77 5362 };
rob@77 5363
rob@77 5364 } else if ( document.documentElement.compareDocumentPosition ) {
rob@77 5365 Sizzle.contains = function( a, b ) {
rob@77 5366 return !!(a.compareDocumentPosition(b) & 16);
rob@77 5367 };
rob@77 5368
rob@77 5369 } else {
rob@77 5370 Sizzle.contains = function() {
rob@77 5371 return false;
rob@77 5372 };
rob@77 5373 }
rob@77 5374
rob@77 5375 Sizzle.isXML = function( elem ) {
rob@77 5376 // documentElement is verified for cases where it doesn't yet exist
rob@77 5377 // (such as loading iframes in IE - #4833)
rob@77 5378 var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
rob@77 5379
rob@77 5380 return documentElement ? documentElement.nodeName !== "HTML" : false;
rob@77 5381 };
rob@77 5382
rob@77 5383 var posProcess = function( selector, context, seed ) {
rob@77 5384 var match,
rob@77 5385 tmpSet = [],
rob@77 5386 later = "",
rob@77 5387 root = context.nodeType ? [context] : context;
rob@77 5388
rob@77 5389 // Position selectors must be done after the filter
rob@77 5390 // And so must :not(positional) so we move all PSEUDOs to the end
rob@77 5391 while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
rob@77 5392 later += match[0];
rob@77 5393 selector = selector.replace( Expr.match.PSEUDO, "" );
rob@77 5394 }
rob@77 5395
rob@77 5396 selector = Expr.relative[selector] ? selector + "*" : selector;
rob@77 5397
rob@77 5398 for ( var i = 0, l = root.length; i < l; i++ ) {
rob@77 5399 Sizzle( selector, root[i], tmpSet, seed );
rob@77 5400 }
rob@77 5401
rob@77 5402 return Sizzle.filter( later, tmpSet );
rob@77 5403 };
rob@77 5404
rob@77 5405 // EXPOSE
rob@77 5406 // Override sizzle attribute retrieval
rob@77 5407 Sizzle.attr = jQuery.attr;
rob@77 5408 Sizzle.selectors.attrMap = {};
rob@77 5409 jQuery.find = Sizzle;
rob@77 5410 jQuery.expr = Sizzle.selectors;
rob@77 5411 jQuery.expr[":"] = jQuery.expr.filters;
rob@77 5412 jQuery.unique = Sizzle.uniqueSort;
rob@77 5413 jQuery.text = Sizzle.getText;
rob@77 5414 jQuery.isXMLDoc = Sizzle.isXML;
rob@77 5415 jQuery.contains = Sizzle.contains;
rob@77 5416
rob@77 5417
rob@77 5418 })();
rob@77 5419
rob@77 5420
rob@77 5421 var runtil = /Until$/,
rob@77 5422 rparentsprev = /^(?:parents|prevUntil|prevAll)/,
rob@77 5423 // Note: This RegExp should be improved, or likely pulled from Sizzle
rob@77 5424 rmultiselector = /,/,
rob@77 5425 isSimple = /^.[^:#\[\.,]*$/,
rob@77 5426 slice = Array.prototype.slice,
rob@77 5427 POS = jQuery.expr.match.globalPOS,
rob@77 5428 // methods guaranteed to produce a unique set when starting from a unique set
rob@77 5429 guaranteedUnique = {
rob@77 5430 children: true,
rob@77 5431 contents: true,
rob@77 5432 next: true,
rob@77 5433 prev: true
rob@77 5434 };
rob@77 5435
rob@77 5436 jQuery.fn.extend({
rob@77 5437 find: function( selector ) {
rob@77 5438 var self = this,
rob@77 5439 i, l;
rob@77 5440
rob@77 5441 if ( typeof selector !== "string" ) {
rob@77 5442 return jQuery( selector ).filter(function() {
rob@77 5443 for ( i = 0, l = self.length; i < l; i++ ) {
rob@77 5444 if ( jQuery.contains( self[ i ], this ) ) {
rob@77 5445 return true;
rob@77 5446 }
rob@77 5447 }
rob@77 5448 });
rob@77 5449 }
rob@77 5450
rob@77 5451 var ret = this.pushStack( "", "find", selector ),
rob@77 5452 length, n, r;
rob@77 5453
rob@77 5454 for ( i = 0, l = this.length; i < l; i++ ) {
rob@77 5455 length = ret.length;
rob@77 5456 jQuery.find( selector, this[i], ret );
rob@77 5457
rob@77 5458 if ( i > 0 ) {
rob@77 5459 // Make sure that the results are unique
rob@77 5460 for ( n = length; n < ret.length; n++ ) {
rob@77 5461 for ( r = 0; r < length; r++ ) {
rob@77 5462 if ( ret[r] === ret[n] ) {
rob@77 5463 ret.splice(n--, 1);
rob@77 5464 break;
rob@77 5465 }
rob@77 5466 }
rob@77 5467 }
rob@77 5468 }
rob@77 5469 }
rob@77 5470
rob@77 5471 return ret;
rob@77 5472 },
rob@77 5473
rob@77 5474 has: function( target ) {
rob@77 5475 var targets = jQuery( target );
rob@77 5476 return this.filter(function() {
rob@77 5477 for ( var i = 0, l = targets.length; i < l; i++ ) {
rob@77 5478 if ( jQuery.contains( this, targets[i] ) ) {
rob@77 5479 return true;
rob@77 5480 }
rob@77 5481 }
rob@77 5482 });
rob@77 5483 },
rob@77 5484
rob@77 5485 not: function( selector ) {
rob@77 5486 return this.pushStack( winnow(this, selector, false), "not", selector);
rob@77 5487 },
rob@77 5488
rob@77 5489 filter: function( selector ) {
rob@77 5490 return this.pushStack( winnow(this, selector, true), "filter", selector );
rob@77 5491 },
rob@77 5492
rob@77 5493 is: function( selector ) {
rob@77 5494 return !!selector && (
rob@77 5495 typeof selector === "string" ?
rob@77 5496 // If this is a positional selector, check membership in the returned set
rob@77 5497 // so $("p:first").is("p:last") won't return true for a doc with two "p".
rob@77 5498 POS.test( selector ) ?
rob@77 5499 jQuery( selector, this.context ).index( this[0] ) >= 0 :
rob@77 5500 jQuery.filter( selector, this ).length > 0 :
rob@77 5501 this.filter( selector ).length > 0 );
rob@77 5502 },
rob@77 5503
rob@77 5504 closest: function( selectors, context ) {
rob@77 5505 var ret = [], i, l, cur = this[0];
rob@77 5506
rob@77 5507 // Array (deprecated as of jQuery 1.7)
rob@77 5508 if ( jQuery.isArray( selectors ) ) {
rob@77 5509 var level = 1;
rob@77 5510
rob@77 5511 while ( cur && cur.ownerDocument && cur !== context ) {
rob@77 5512 for ( i = 0; i < selectors.length; i++ ) {
rob@77 5513
rob@77 5514 if ( jQuery( cur ).is( selectors[ i ] ) ) {
rob@77 5515 ret.push({ selector: selectors[ i ], elem: cur, level: level });
rob@77 5516 }
rob@77 5517 }
rob@77 5518
rob@77 5519 cur = cur.parentNode;
rob@77 5520 level++;
rob@77 5521 }
rob@77 5522
rob@77 5523 return ret;
rob@77 5524 }
rob@77 5525
rob@77 5526 // String
rob@77 5527 var pos = POS.test( selectors ) || typeof selectors !== "string" ?
rob@77 5528 jQuery( selectors, context || this.context ) :
rob@77 5529 0;
rob@77 5530
rob@77 5531 for ( i = 0, l = this.length; i < l; i++ ) {
rob@77 5532 cur = this[i];
rob@77 5533
rob@77 5534 while ( cur ) {
rob@77 5535 if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) {
rob@77 5536 ret.push( cur );
rob@77 5537 break;
rob@77 5538
rob@77 5539 } else {
rob@77 5540 cur = cur.parentNode;
rob@77 5541 if ( !cur || !cur.ownerDocument || cur === context || cur.nodeType === 11 ) {
rob@77 5542 break;
rob@77 5543 }
rob@77 5544 }
rob@77 5545 }
rob@77 5546 }
rob@77 5547
rob@77 5548 ret = ret.length > 1 ? jQuery.unique( ret ) : ret;
rob@77 5549
rob@77 5550 return this.pushStack( ret, "closest", selectors );
rob@77 5551 },
rob@77 5552
rob@77 5553 // Determine the position of an element within
rob@77 5554 // the matched set of elements
rob@77 5555 index: function( elem ) {
rob@77 5556
rob@77 5557 // No argument, return index in parent
rob@77 5558 if ( !elem ) {
rob@77 5559 return ( this[0] && this[0].parentNode ) ? this.prevAll().length : -1;
rob@77 5560 }
rob@77 5561
rob@77 5562 // index in selector
rob@77 5563 if ( typeof elem === "string" ) {
rob@77 5564 return jQuery.inArray( this[0], jQuery( elem ) );
rob@77 5565 }
rob@77 5566
rob@77 5567 // Locate the position of the desired element
rob@77 5568 return jQuery.inArray(
rob@77 5569 // If it receives a jQuery object, the first element is used
rob@77 5570 elem.jquery ? elem[0] : elem, this );
rob@77 5571 },
rob@77 5572
rob@77 5573 add: function( selector, context ) {
rob@77 5574 var set = typeof selector === "string" ?
rob@77 5575 jQuery( selector, context ) :
rob@77 5576 jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
rob@77 5577 all = jQuery.merge( this.get(), set );
rob@77 5578
rob@77 5579 return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
rob@77 5580 all :
rob@77 5581 jQuery.unique( all ) );
rob@77 5582 },
rob@77 5583
rob@77 5584 andSelf: function() {
rob@77 5585 return this.add( this.prevObject );
rob@77 5586 }
rob@77 5587 });
rob@77 5588
rob@77 5589 // A painfully simple check to see if an element is disconnected
rob@77 5590 // from a document (should be improved, where feasible).
rob@77 5591 function isDisconnected( node ) {
rob@77 5592 return !node || !node.parentNode || node.parentNode.nodeType === 11;
rob@77 5593 }
rob@77 5594
rob@77 5595 jQuery.each({
rob@77 5596 parent: function( elem ) {
rob@77 5597 var parent = elem.parentNode;
rob@77 5598 return parent && parent.nodeType !== 11 ? parent : null;
rob@77 5599 },
rob@77 5600 parents: function( elem ) {
rob@77 5601 return jQuery.dir( elem, "parentNode" );
rob@77 5602 },
rob@77 5603 parentsUntil: function( elem, i, until ) {
rob@77 5604 return jQuery.dir( elem, "parentNode", until );
rob@77 5605 },
rob@77 5606 next: function( elem ) {
rob@77 5607 return jQuery.nth( elem, 2, "nextSibling" );
rob@77 5608 },
rob@77 5609 prev: function( elem ) {
rob@77 5610 return jQuery.nth( elem, 2, "previousSibling" );
rob@77 5611 },
rob@77 5612 nextAll: function( elem ) {
rob@77 5613 return jQuery.dir( elem, "nextSibling" );
rob@77 5614 },
rob@77 5615 prevAll: function( elem ) {
rob@77 5616 return jQuery.dir( elem, "previousSibling" );
rob@77 5617 },
rob@77 5618 nextUntil: function( elem, i, until ) {
rob@77 5619 return jQuery.dir( elem, "nextSibling", until );
rob@77 5620 },
rob@77 5621 prevUntil: function( elem, i, until ) {
rob@77 5622 return jQuery.dir( elem, "previousSibling", until );
rob@77 5623 },
rob@77 5624 siblings: function( elem ) {
rob@77 5625 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
rob@77 5626 },
rob@77 5627 children: function( elem ) {
rob@77 5628 return jQuery.sibling( elem.firstChild );
rob@77 5629 },
rob@77 5630 contents: function( elem ) {
rob@77 5631 return jQuery.nodeName( elem, "iframe" ) ?
rob@77 5632 elem.contentDocument || elem.contentWindow.document :
rob@77 5633 jQuery.makeArray( elem.childNodes );
rob@77 5634 }
rob@77 5635 }, function( name, fn ) {
rob@77 5636 jQuery.fn[ name ] = function( until, selector ) {
rob@77 5637 var ret = jQuery.map( this, fn, until );
rob@77 5638
rob@77 5639 if ( !runtil.test( name ) ) {
rob@77 5640 selector = until;
rob@77 5641 }
rob@77 5642
rob@77 5643 if ( selector && typeof selector === "string" ) {
rob@77 5644 ret = jQuery.filter( selector, ret );
rob@77 5645 }
rob@77 5646
rob@77 5647 ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret;
rob@77 5648
rob@77 5649 if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
rob@77 5650 ret = ret.reverse();
rob@77 5651 }
rob@77 5652
rob@77 5653 return this.pushStack( ret, name, slice.call( arguments ).join(",") );
rob@77 5654 };
rob@77 5655 });
rob@77 5656
rob@77 5657 jQuery.extend({
rob@77 5658 filter: function( expr, elems, not ) {
rob@77 5659 if ( not ) {
rob@77 5660 expr = ":not(" + expr + ")";
rob@77 5661 }
rob@77 5662
rob@77 5663 return elems.length === 1 ?
rob@77 5664 jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] :
rob@77 5665 jQuery.find.matches(expr, elems);
rob@77 5666 },
rob@77 5667
rob@77 5668 dir: function( elem, dir, until ) {
rob@77 5669 var matched = [],
rob@77 5670 cur = elem[ dir ];
rob@77 5671
rob@77 5672 while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
rob@77 5673 if ( cur.nodeType === 1 ) {
rob@77 5674 matched.push( cur );
rob@77 5675 }
rob@77 5676 cur = cur[dir];
rob@77 5677 }
rob@77 5678 return matched;
rob@77 5679 },
rob@77 5680
rob@77 5681 nth: function( cur, result, dir, elem ) {
rob@77 5682 result = result || 1;
rob@77 5683 var num = 0;
rob@77 5684
rob@77 5685 for ( ; cur; cur = cur[dir] ) {
rob@77 5686 if ( cur.nodeType === 1 && ++num === result ) {
rob@77 5687 break;
rob@77 5688 }
rob@77 5689 }
rob@77 5690
rob@77 5691 return cur;
rob@77 5692 },
rob@77 5693
rob@77 5694 sibling: function( n, elem ) {
rob@77 5695 var r = [];
rob@77 5696
rob@77 5697 for ( ; n; n = n.nextSibling ) {
rob@77 5698 if ( n.nodeType === 1 && n !== elem ) {
rob@77 5699 r.push( n );
rob@77 5700 }
rob@77 5701 }
rob@77 5702
rob@77 5703 return r;
rob@77 5704 }
rob@77 5705 });
rob@77 5706
rob@77 5707 // Implement the identical functionality for filter and not
rob@77 5708 function winnow( elements, qualifier, keep ) {
rob@77 5709
rob@77 5710 // Can't pass null or undefined to indexOf in Firefox 4
rob@77 5711 // Set to 0 to skip string check
rob@77 5712 qualifier = qualifier || 0;
rob@77 5713
rob@77 5714 if ( jQuery.isFunction( qualifier ) ) {
rob@77 5715 return jQuery.grep(elements, function( elem, i ) {
rob@77 5716 var retVal = !!qualifier.call( elem, i, elem );
rob@77 5717 return retVal === keep;
rob@77 5718 });
rob@77 5719
rob@77 5720 } else if ( qualifier.nodeType ) {
rob@77 5721 return jQuery.grep(elements, function( elem, i ) {
rob@77 5722 return ( elem === qualifier ) === keep;
rob@77 5723 });
rob@77 5724
rob@77 5725 } else if ( typeof qualifier === "string" ) {
rob@77 5726 var filtered = jQuery.grep(elements, function( elem ) {
rob@77 5727 return elem.nodeType === 1;
rob@77 5728 });
rob@77 5729
rob@77 5730 if ( isSimple.test( qualifier ) ) {
rob@77 5731 return jQuery.filter(qualifier, filtered, !keep);
rob@77 5732 } else {
rob@77 5733 qualifier = jQuery.filter( qualifier, filtered );
rob@77 5734 }
rob@77 5735 }
rob@77 5736
rob@77 5737 return jQuery.grep(elements, function( elem, i ) {
rob@77 5738 return ( jQuery.inArray( elem, qualifier ) >= 0 ) === keep;
rob@77 5739 });
rob@77 5740 }
rob@77 5741
rob@77 5742
rob@77 5743
rob@77 5744
rob@77 5745 function createSafeFragment( document ) {
rob@77 5746 var list = nodeNames.split( "|" ),
rob@77 5747 safeFrag = document.createDocumentFragment();
rob@77 5748
rob@77 5749 if ( safeFrag.createElement ) {
rob@77 5750 while ( list.length ) {
rob@77 5751 safeFrag.createElement(
rob@77 5752 list.pop()
rob@77 5753 );
rob@77 5754 }
rob@77 5755 }
rob@77 5756 return safeFrag;
rob@77 5757 }
rob@77 5758
rob@77 5759 var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
rob@77 5760 "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
rob@77 5761 rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
rob@77 5762 rleadingWhitespace = /^\s+/,
rob@77 5763 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
rob@77 5764 rtagName = /<([\w:]+)/,
rob@77 5765 rtbody = /<tbody/i,
rob@77 5766 rhtml = /<|&#?\w+;/,
rob@77 5767 rnoInnerhtml = /<(?:script|style)/i,
rob@77 5768 rnocache = /<(?:script|object|embed|option|style)/i,
rob@77 5769 rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"),
rob@77 5770 // checked="checked" or checked
rob@77 5771 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
rob@77 5772 rscriptType = /\/(java|ecma)script/i,
rob@77 5773 rcleanScript = /^\s*<!(?:\[CDATA\[|\-\-)/,
rob@77 5774 wrapMap = {
rob@77 5775 option: [ 1, "<select multiple='multiple'>", "</select>" ],
rob@77 5776 legend: [ 1, "<fieldset>", "</fieldset>" ],
rob@77 5777 thead: [ 1, "<table>", "</table>" ],
rob@77 5778 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
rob@77 5779 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
rob@77 5780 col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
rob@77 5781 area: [ 1, "<map>", "</map>" ],
rob@77 5782 _default: [ 0, "", "" ]
rob@77 5783 },
rob@77 5784 safeFragment = createSafeFragment( document );
rob@77 5785
rob@77 5786 wrapMap.optgroup = wrapMap.option;
rob@77 5787 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
rob@77 5788 wrapMap.th = wrapMap.td;
rob@77 5789
rob@77 5790 // IE can't serialize <link> and <script> tags normally
rob@77 5791 if ( !jQuery.support.htmlSerialize ) {
rob@77 5792 wrapMap._default = [ 1, "div<div>", "</div>" ];
rob@77 5793 }
rob@77 5794
rob@77 5795 jQuery.fn.extend({
rob@77 5796 text: function( value ) {
rob@77 5797 return jQuery.access( this, function( value ) {
rob@77 5798 return value === undefined ?
rob@77 5799 jQuery.text( this ) :
rob@77 5800 this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) );
rob@77 5801 }, null, value, arguments.length );
rob@77 5802 },
rob@77 5803
rob@77 5804 wrapAll: function( html ) {
rob@77 5805 if ( jQuery.isFunction( html ) ) {
rob@77 5806 return this.each(function(i) {
rob@77 5807 jQuery(this).wrapAll( html.call(this, i) );
rob@77 5808 });
rob@77 5809 }
rob@77 5810
rob@77 5811 if ( this[0] ) {
rob@77 5812 // The elements to wrap the target around
rob@77 5813 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
rob@77 5814
rob@77 5815 if ( this[0].parentNode ) {
rob@77 5816 wrap.insertBefore( this[0] );
rob@77 5817 }
rob@77 5818
rob@77 5819 wrap.map(function() {
rob@77 5820 var elem = this;
rob@77 5821
rob@77 5822 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
rob@77 5823 elem = elem.firstChild;
rob@77 5824 }
rob@77 5825
rob@77 5826 return elem;
rob@77 5827 }).append( this );
rob@77 5828 }
rob@77 5829
rob@77 5830 return this;
rob@77 5831 },
rob@77 5832
rob@77 5833 wrapInner: function( html ) {
rob@77 5834 if ( jQuery.isFunction( html ) ) {
rob@77 5835 return this.each(function(i) {
rob@77 5836 jQuery(this).wrapInner( html.call(this, i) );
rob@77 5837 });
rob@77 5838 }
rob@77 5839
rob@77 5840 return this.each(function() {
rob@77 5841 var self = jQuery( this ),
rob@77 5842 contents = self.contents();
rob@77 5843
rob@77 5844 if ( contents.length ) {
rob@77 5845 contents.wrapAll( html );
rob@77 5846
rob@77 5847 } else {
rob@77 5848 self.append( html );
rob@77 5849 }
rob@77 5850 });
rob@77 5851 },
rob@77 5852
rob@77 5853 wrap: function( html ) {
rob@77 5854 var isFunction = jQuery.isFunction( html );
rob@77 5855
rob@77 5856 return this.each(function(i) {
rob@77 5857 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
rob@77 5858 });
rob@77 5859 },
rob@77 5860
rob@77 5861 unwrap: function() {
rob@77 5862 return this.parent().each(function() {
rob@77 5863 if ( !jQuery.nodeName( this, "body" ) ) {
rob@77 5864 jQuery( this ).replaceWith( this.childNodes );
rob@77 5865 }
rob@77 5866 }).end();
rob@77 5867 },
rob@77 5868
rob@77 5869 append: function() {
rob@77 5870 return this.domManip(arguments, true, function( elem ) {
rob@77 5871 if ( this.nodeType === 1 ) {
rob@77 5872 this.appendChild( elem );
rob@77 5873 }
rob@77 5874 });
rob@77 5875 },
rob@77 5876
rob@77 5877 prepend: function() {
rob@77 5878 return this.domManip(arguments, true, function( elem ) {
rob@77 5879 if ( this.nodeType === 1 ) {
rob@77 5880 this.insertBefore( elem, this.firstChild );
rob@77 5881 }
rob@77 5882 });
rob@77 5883 },
rob@77 5884
rob@77 5885 before: function() {
rob@77 5886 if ( this[0] && this[0].parentNode ) {
rob@77 5887 return this.domManip(arguments, false, function( elem ) {
rob@77 5888 this.parentNode.insertBefore( elem, this );
rob@77 5889 });
rob@77 5890 } else if ( arguments.length ) {
rob@77 5891 var set = jQuery.clean( arguments );
rob@77 5892 set.push.apply( set, this.toArray() );
rob@77 5893 return this.pushStack( set, "before", arguments );
rob@77 5894 }
rob@77 5895 },
rob@77 5896
rob@77 5897 after: function() {
rob@77 5898 if ( this[0] && this[0].parentNode ) {
rob@77 5899 return this.domManip(arguments, false, function( elem ) {
rob@77 5900 this.parentNode.insertBefore( elem, this.nextSibling );
rob@77 5901 });
rob@77 5902 } else if ( arguments.length ) {
rob@77 5903 var set = this.pushStack( this, "after", arguments );
rob@77 5904 set.push.apply( set, jQuery.clean(arguments) );
rob@77 5905 return set;
rob@77 5906 }
rob@77 5907 },
rob@77 5908
rob@77 5909 // keepData is for internal use only--do not document
rob@77 5910 remove: function( selector, keepData ) {
rob@77 5911 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
rob@77 5912 if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
rob@77 5913 if ( !keepData && elem.nodeType === 1 ) {
rob@77 5914 jQuery.cleanData( elem.getElementsByTagName("*") );
rob@77 5915 jQuery.cleanData( [ elem ] );
rob@77 5916 }
rob@77 5917
rob@77 5918 if ( elem.parentNode ) {
rob@77 5919 elem.parentNode.removeChild( elem );
rob@77 5920 }
rob@77 5921 }
rob@77 5922 }
rob@77 5923
rob@77 5924 return this;
rob@77 5925 },
rob@77 5926
rob@77 5927 empty: function() {
rob@77 5928 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
rob@77 5929 // Remove element nodes and prevent memory leaks
rob@77 5930 if ( elem.nodeType === 1 ) {
rob@77 5931 jQuery.cleanData( elem.getElementsByTagName("*") );
rob@77 5932 }
rob@77 5933
rob@77 5934 // Remove any remaining nodes
rob@77 5935 while ( elem.firstChild ) {
rob@77 5936 elem.removeChild( elem.firstChild );
rob@77 5937 }
rob@77 5938 }
rob@77 5939
rob@77 5940 return this;
rob@77 5941 },
rob@77 5942
rob@77 5943 clone: function( dataAndEvents, deepDataAndEvents ) {
rob@77 5944 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
rob@77 5945 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
rob@77 5946
rob@77 5947 return this.map( function () {
rob@77 5948 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
rob@77 5949 });
rob@77 5950 },
rob@77 5951
rob@77 5952 html: function( value ) {
rob@77 5953 return jQuery.access( this, function( value ) {
rob@77 5954 var elem = this[0] || {},
rob@77 5955 i = 0,
rob@77 5956 l = this.length;
rob@77 5957
rob@77 5958 if ( value === undefined ) {
rob@77 5959 return elem.nodeType === 1 ?
rob@77 5960 elem.innerHTML.replace( rinlinejQuery, "" ) :
rob@77 5961 null;
rob@77 5962 }
rob@77 5963
rob@77 5964
rob@77 5965 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
rob@77 5966 ( jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value ) ) &&
rob@77 5967 !wrapMap[ ( rtagName.exec( value ) || ["", ""] )[1].toLowerCase() ] ) {
rob@77 5968
rob@77 5969 value = value.replace( rxhtmlTag, "<$1></$2>" );
rob@77 5970
rob@77 5971 try {
rob@77 5972 for (; i < l; i++ ) {
rob@77 5973 // Remove element nodes and prevent memory leaks
rob@77 5974 elem = this[i] || {};
rob@77 5975 if ( elem.nodeType === 1 ) {
rob@77 5976 jQuery.cleanData( elem.getElementsByTagName( "*" ) );
rob@77 5977 elem.innerHTML = value;
rob@77 5978 }
rob@77 5979 }
rob@77 5980
rob@77 5981 elem = 0;
rob@77 5982
rob@77 5983 // If using innerHTML throws an exception, use the fallback method
rob@77 5984 } catch(e) {}
rob@77 5985 }
rob@77 5986
rob@77 5987 if ( elem ) {
rob@77 5988 this.empty().append( value );
rob@77 5989 }
rob@77 5990 }, null, value, arguments.length );
rob@77 5991 },
rob@77 5992
rob@77 5993 replaceWith: function( value ) {
rob@77 5994 if ( this[0] && this[0].parentNode ) {
rob@77 5995 // Make sure that the elements are removed from the DOM before they are inserted
rob@77 5996 // this can help fix replacing a parent with child elements
rob@77 5997 if ( jQuery.isFunction( value ) ) {
rob@77 5998 return this.each(function(i) {
rob@77 5999 var self = jQuery(this), old = self.html();
rob@77 6000 self.replaceWith( value.call( this, i, old ) );
rob@77 6001 });
rob@77 6002 }
rob@77 6003
rob@77 6004 if ( typeof value !== "string" ) {
rob@77 6005 value = jQuery( value ).detach();
rob@77 6006 }
rob@77 6007
rob@77 6008 return this.each(function() {
rob@77 6009 var next = this.nextSibling,
rob@77 6010 parent = this.parentNode;
rob@77 6011
rob@77 6012 jQuery( this ).remove();
rob@77 6013
rob@77 6014 if ( next ) {
rob@77 6015 jQuery(next).before( value );
rob@77 6016 } else {
rob@77 6017 jQuery(parent).append( value );
rob@77 6018 }
rob@77 6019 });
rob@77 6020 } else {
rob@77 6021 return this.length ?
rob@77 6022 this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value ) :
rob@77 6023 this;
rob@77 6024 }
rob@77 6025 },
rob@77 6026
rob@77 6027 detach: function( selector ) {
rob@77 6028 return this.remove( selector, true );
rob@77 6029 },
rob@77 6030
rob@77 6031 domManip: function( args, table, callback ) {
rob@77 6032 var results, first, fragment, parent,
rob@77 6033 value = args[0],
rob@77 6034 scripts = [];
rob@77 6035
rob@77 6036 // We can't cloneNode fragments that contain checked, in WebKit
rob@77 6037 if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
rob@77 6038 return this.each(function() {
rob@77 6039 jQuery(this).domManip( args, table, callback, true );
rob@77 6040 });
rob@77 6041 }
rob@77 6042
rob@77 6043 if ( jQuery.isFunction(value) ) {
rob@77 6044 return this.each(function(i) {
rob@77 6045 var self = jQuery(this);
rob@77 6046 args[0] = value.call(this, i, table ? self.html() : undefined);
rob@77 6047 self.domManip( args, table, callback );
rob@77 6048 });
rob@77 6049 }
rob@77 6050
rob@77 6051 if ( this[0] ) {
rob@77 6052 parent = value && value.parentNode;
rob@77 6053
rob@77 6054 // If we're in a fragment, just use that instead of building a new one
rob@77 6055 if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
rob@77 6056 results = { fragment: parent };
rob@77 6057
rob@77 6058 } else {
rob@77 6059 results = jQuery.buildFragment( args, this, scripts );
rob@77 6060 }
rob@77 6061
rob@77 6062 fragment = results.fragment;
rob@77 6063
rob@77 6064 if ( fragment.childNodes.length === 1 ) {
rob@77 6065 first = fragment = fragment.firstChild;
rob@77 6066 } else {
rob@77 6067 first = fragment.firstChild;
rob@77 6068 }
rob@77 6069
rob@77 6070 if ( first ) {
rob@77 6071 table = table && jQuery.nodeName( first, "tr" );
rob@77 6072
rob@77 6073 for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) {
rob@77 6074 callback.call(
rob@77 6075 table ?
rob@77 6076 root(this[i], first) :
rob@77 6077 this[i],
rob@77 6078 // Make sure that we do not leak memory by inadvertently discarding
rob@77 6079 // the original fragment (which might have attached data) instead of
rob@77 6080 // using it; in addition, use the original fragment object for the last
rob@77 6081 // item instead of first because it can end up being emptied incorrectly
rob@77 6082 // in certain situations (Bug #8070).
rob@77 6083 // Fragments from the fragment cache must always be cloned and never used
rob@77 6084 // in place.
rob@77 6085 results.cacheable || ( l > 1 && i < lastIndex ) ?
rob@77 6086 jQuery.clone( fragment, true, true ) :
rob@77 6087 fragment
rob@77 6088 );
rob@77 6089 }
rob@77 6090 }
rob@77 6091
rob@77 6092 if ( scripts.length ) {
rob@77 6093 jQuery.each( scripts, function( i, elem ) {
rob@77 6094 if ( elem.src ) {
rob@77 6095 jQuery.ajax({
rob@77 6096 type: "GET",
rob@77 6097 global: false,
rob@77 6098 url: elem.src,
rob@77 6099 async: false,
rob@77 6100 dataType: "script"
rob@77 6101 });
rob@77 6102 } else {
rob@77 6103 jQuery.globalEval( ( elem.text || elem.textContent || elem.innerHTML || "" ).replace( rcleanScript, "/*$0*/" ) );
rob@77 6104 }
rob@77 6105
rob@77 6106 if ( elem.parentNode ) {
rob@77 6107 elem.parentNode.removeChild( elem );
rob@77 6108 }
rob@77 6109 });
rob@77 6110 }
rob@77 6111 }
rob@77 6112
rob@77 6113 return this;
rob@77 6114 }
rob@77 6115 });
rob@77 6116
rob@77 6117 function root( elem, cur ) {
rob@77 6118 return jQuery.nodeName(elem, "table") ?
rob@77 6119 (elem.getElementsByTagName("tbody")[0] ||
rob@77 6120 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
rob@77 6121 elem;
rob@77 6122 }
rob@77 6123
rob@77 6124 function cloneCopyEvent( src, dest ) {
rob@77 6125
rob@77 6126 if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
rob@77 6127 return;
rob@77 6128 }
rob@77 6129
rob@77 6130 var type, i, l,
rob@77 6131 oldData = jQuery._data( src ),
rob@77 6132 curData = jQuery._data( dest, oldData ),
rob@77 6133 events = oldData.events;
rob@77 6134
rob@77 6135 if ( events ) {
rob@77 6136 delete curData.handle;
rob@77 6137 curData.events = {};
rob@77 6138
rob@77 6139 for ( type in events ) {
rob@77 6140 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
rob@77 6141 jQuery.event.add( dest, type, events[ type ][ i ] );
rob@77 6142 }
rob@77 6143 }
rob@77 6144 }
rob@77 6145
rob@77 6146 // make the cloned public data object a copy from the original
rob@77 6147 if ( curData.data ) {
rob@77 6148 curData.data = jQuery.extend( {}, curData.data );
rob@77 6149 }
rob@77 6150 }
rob@77 6151
rob@77 6152 function cloneFixAttributes( src, dest ) {
rob@77 6153 var nodeName;
rob@77 6154
rob@77 6155 // We do not need to do anything for non-Elements
rob@77 6156 if ( dest.nodeType !== 1 ) {
rob@77 6157 return;
rob@77 6158 }
rob@77 6159
rob@77 6160 // clearAttributes removes the attributes, which we don't want,
rob@77 6161 // but also removes the attachEvent events, which we *do* want
rob@77 6162 if ( dest.clearAttributes ) {
rob@77 6163 dest.clearAttributes();
rob@77 6164 }
rob@77 6165
rob@77 6166 // mergeAttributes, in contrast, only merges back on the
rob@77 6167 // original attributes, not the events
rob@77 6168 if ( dest.mergeAttributes ) {
rob@77 6169 dest.mergeAttributes( src );
rob@77 6170 }
rob@77 6171
rob@77 6172 nodeName = dest.nodeName.toLowerCase();
rob@77 6173
rob@77 6174 // IE6-8 fail to clone children inside object elements that use
rob@77 6175 // the proprietary classid attribute value (rather than the type
rob@77 6176 // attribute) to identify the type of content to display
rob@77 6177 if ( nodeName === "object" ) {
rob@77 6178 dest.outerHTML = src.outerHTML;
rob@77 6179
rob@77 6180 } else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
rob@77 6181 // IE6-8 fails to persist the checked state of a cloned checkbox
rob@77 6182 // or radio button. Worse, IE6-7 fail to give the cloned element
rob@77 6183 // a checked appearance if the defaultChecked value isn't also set
rob@77 6184 if ( src.checked ) {
rob@77 6185 dest.defaultChecked = dest.checked = src.checked;
rob@77 6186 }
rob@77 6187
rob@77 6188 // IE6-7 get confused and end up setting the value of a cloned
rob@77 6189 // checkbox/radio button to an empty string instead of "on"
rob@77 6190 if ( dest.value !== src.value ) {
rob@77 6191 dest.value = src.value;
rob@77 6192 }
rob@77 6193
rob@77 6194 // IE6-8 fails to return the selected option to the default selected
rob@77 6195 // state when cloning options
rob@77 6196 } else if ( nodeName === "option" ) {
rob@77 6197 dest.selected = src.defaultSelected;
rob@77 6198
rob@77 6199 // IE6-8 fails to set the defaultValue to the correct value when
rob@77 6200 // cloning other types of input fields
rob@77 6201 } else if ( nodeName === "input" || nodeName === "textarea" ) {
rob@77 6202 dest.defaultValue = src.defaultValue;
rob@77 6203
rob@77 6204 // IE blanks contents when cloning scripts
rob@77 6205 } else if ( nodeName === "script" && dest.text !== src.text ) {
rob@77 6206 dest.text = src.text;
rob@77 6207 }
rob@77 6208
rob@77 6209 // Event data gets referenced instead of copied if the expando
rob@77 6210 // gets copied too
rob@77 6211 dest.removeAttribute( jQuery.expando );
rob@77 6212
rob@77 6213 // Clear flags for bubbling special change/submit events, they must
rob@77 6214 // be reattached when the newly cloned events are first activated
rob@77 6215 dest.removeAttribute( "_submit_attached" );
rob@77 6216 dest.removeAttribute( "_change_attached" );
rob@77 6217 }
rob@77 6218
rob@77 6219 jQuery.buildFragment = function( args, nodes, scripts ) {
rob@77 6220 var fragment, cacheable, cacheresults, doc,
rob@77 6221 first = args[ 0 ];
rob@77 6222
rob@77 6223 // nodes may contain either an explicit document object,
rob@77 6224 // a jQuery collection or context object.
rob@77 6225 // If nodes[0] contains a valid object to assign to doc
rob@77 6226 if ( nodes && nodes[0] ) {
rob@77 6227 doc = nodes[0].ownerDocument || nodes[0];
rob@77 6228 }
rob@77 6229
rob@77 6230 // Ensure that an attr object doesn't incorrectly stand in as a document object
rob@77 6231 // Chrome and Firefox seem to allow this to occur and will throw exception
rob@77 6232 // Fixes #8950
rob@77 6233 if ( !doc.createDocumentFragment ) {
rob@77 6234 doc = document;
rob@77 6235 }
rob@77 6236
rob@77 6237 // Only cache "small" (1/2 KB) HTML strings that are associated with the main document
rob@77 6238 // Cloning options loses the selected state, so don't cache them
rob@77 6239 // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
rob@77 6240 // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
rob@77 6241 // Lastly, IE6,7,8 will not correctly reuse cached fragments that were created from unknown elems #10501
rob@77 6242 if ( args.length === 1 && typeof first === "string" && first.length < 512 && doc === document &&
rob@77 6243 first.charAt(0) === "<" && !rnocache.test( first ) &&
rob@77 6244 (jQuery.support.checkClone || !rchecked.test( first )) &&
rob@77 6245 (jQuery.support.html5Clone || !rnoshimcache.test( first )) ) {
rob@77 6246
rob@77 6247 cacheable = true;
rob@77 6248
rob@77 6249 cacheresults = jQuery.fragments[ first ];
rob@77 6250 if ( cacheresults && cacheresults !== 1 ) {
rob@77 6251 fragment = cacheresults;
rob@77 6252 }
rob@77 6253 }
rob@77 6254
rob@77 6255 if ( !fragment ) {
rob@77 6256 fragment = doc.createDocumentFragment();
rob@77 6257 jQuery.clean( args, doc, fragment, scripts );
rob@77 6258 }
rob@77 6259
rob@77 6260 if ( cacheable ) {
rob@77 6261 jQuery.fragments[ first ] = cacheresults ? fragment : 1;
rob@77 6262 }
rob@77 6263
rob@77 6264 return { fragment: fragment, cacheable: cacheable };
rob@77 6265 };
rob@77 6266
rob@77 6267 jQuery.fragments = {};
rob@77 6268
rob@77 6269 jQuery.each({
rob@77 6270 appendTo: "append",
rob@77 6271 prependTo: "prepend",
rob@77 6272 insertBefore: "before",
rob@77 6273 insertAfter: "after",
rob@77 6274 replaceAll: "replaceWith"
rob@77 6275 }, function( name, original ) {
rob@77 6276 jQuery.fn[ name ] = function( selector ) {
rob@77 6277 var ret = [],
rob@77 6278 insert = jQuery( selector ),
rob@77 6279 parent = this.length === 1 && this[0].parentNode;
rob@77 6280
rob@77 6281 if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
rob@77 6282 insert[ original ]( this[0] );
rob@77 6283 return this;
rob@77 6284
rob@77 6285 } else {
rob@77 6286 for ( var i = 0, l = insert.length; i < l; i++ ) {
rob@77 6287 var elems = ( i > 0 ? this.clone(true) : this ).get();
rob@77 6288 jQuery( insert[i] )[ original ]( elems );
rob@77 6289 ret = ret.concat( elems );
rob@77 6290 }
rob@77 6291
rob@77 6292 return this.pushStack( ret, name, insert.selector );
rob@77 6293 }
rob@77 6294 };
rob@77 6295 });
rob@77 6296
rob@77 6297 function getAll( elem ) {
rob@77 6298 if ( typeof elem.getElementsByTagName !== "undefined" ) {
rob@77 6299 return elem.getElementsByTagName( "*" );
rob@77 6300
rob@77 6301 } else if ( typeof elem.querySelectorAll !== "undefined" ) {
rob@77 6302 return elem.querySelectorAll( "*" );
rob@77 6303
rob@77 6304 } else {
rob@77 6305 return [];
rob@77 6306 }
rob@77 6307 }
rob@77 6308
rob@77 6309 // Used in clean, fixes the defaultChecked property
rob@77 6310 function fixDefaultChecked( elem ) {
rob@77 6311 if ( elem.type === "checkbox" || elem.type === "radio" ) {
rob@77 6312 elem.defaultChecked = elem.checked;
rob@77 6313 }
rob@77 6314 }
rob@77 6315 // Finds all inputs and passes them to fixDefaultChecked
rob@77 6316 function findInputs( elem ) {
rob@77 6317 var nodeName = ( elem.nodeName || "" ).toLowerCase();
rob@77 6318 if ( nodeName === "input" ) {
rob@77 6319 fixDefaultChecked( elem );
rob@77 6320 // Skip scripts, get other children
rob@77 6321 } else if ( nodeName !== "script" && typeof elem.getElementsByTagName !== "undefined" ) {
rob@77 6322 jQuery.grep( elem.getElementsByTagName("input"), fixDefaultChecked );
rob@77 6323 }
rob@77 6324 }
rob@77 6325
rob@77 6326 // Derived From: http://www.iecss.com/shimprove/javascript/shimprove.1-0-1.js
rob@77 6327 function shimCloneNode( elem ) {
rob@77 6328 var div = document.createElement( "div" );
rob@77 6329 safeFragment.appendChild( div );
rob@77 6330
rob@77 6331 div.innerHTML = elem.outerHTML;
rob@77 6332 return div.firstChild;
rob@77 6333 }
rob@77 6334
rob@77 6335 jQuery.extend({
rob@77 6336 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
rob@77 6337 var srcElements,
rob@77 6338 destElements,
rob@77 6339 i,
rob@77 6340 // IE<=8 does not properly clone detached, unknown element nodes
rob@77 6341 clone = jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ?
rob@77 6342 elem.cloneNode( true ) :
rob@77 6343 shimCloneNode( elem );
rob@77 6344
rob@77 6345 if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) &&
rob@77 6346 (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
rob@77 6347 // IE copies events bound via attachEvent when using cloneNode.
rob@77 6348 // Calling detachEvent on the clone will also remove the events
rob@77 6349 // from the original. In order to get around this, we use some
rob@77 6350 // proprietary methods to clear the events. Thanks to MooTools
rob@77 6351 // guys for this hotness.
rob@77 6352
rob@77 6353 cloneFixAttributes( elem, clone );
rob@77 6354
rob@77 6355 // Using Sizzle here is crazy slow, so we use getElementsByTagName instead
rob@77 6356 srcElements = getAll( elem );
rob@77 6357 destElements = getAll( clone );
rob@77 6358
rob@77 6359 // Weird iteration because IE will replace the length property
rob@77 6360 // with an element if you are cloning the body and one of the
rob@77 6361 // elements on the page has a name or id of "length"
rob@77 6362 for ( i = 0; srcElements[i]; ++i ) {
rob@77 6363 // Ensure that the destination node is not null; Fixes #9587
rob@77 6364 if ( destElements[i] ) {
rob@77 6365 cloneFixAttributes( srcElements[i], destElements[i] );
rob@77 6366 }
rob@77 6367 }
rob@77 6368 }
rob@77 6369
rob@77 6370 // Copy the events from the original to the clone
rob@77 6371 if ( dataAndEvents ) {
rob@77 6372 cloneCopyEvent( elem, clone );
rob@77 6373
rob@77 6374 if ( deepDataAndEvents ) {
rob@77 6375 srcElements = getAll( elem );
rob@77 6376 destElements = getAll( clone );
rob@77 6377
rob@77 6378 for ( i = 0; srcElements[i]; ++i ) {
rob@77 6379 cloneCopyEvent( srcElements[i], destElements[i] );
rob@77 6380 }
rob@77 6381 }
rob@77 6382 }
rob@77 6383
rob@77 6384 srcElements = destElements = null;
rob@77 6385
rob@77 6386 // Return the cloned set
rob@77 6387 return clone;
rob@77 6388 },
rob@77 6389
rob@77 6390 clean: function( elems, context, fragment, scripts ) {
rob@77 6391 var checkScriptType, script, j,
rob@77 6392 ret = [];
rob@77 6393
rob@77 6394 context = context || document;
rob@77 6395
rob@77 6396 // !context.createElement fails in IE with an error but returns typeof 'object'
rob@77 6397 if ( typeof context.createElement === "undefined" ) {
rob@77 6398 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
rob@77 6399 }
rob@77 6400
rob@77 6401 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
rob@77 6402 if ( typeof elem === "number" ) {
rob@77 6403 elem += "";
rob@77 6404 }
rob@77 6405
rob@77 6406 if ( !elem ) {
rob@77 6407 continue;
rob@77 6408 }
rob@77 6409
rob@77 6410 // Convert html string into DOM nodes
rob@77 6411 if ( typeof elem === "string" ) {
rob@77 6412 if ( !rhtml.test( elem ) ) {
rob@77 6413 elem = context.createTextNode( elem );
rob@77 6414 } else {
rob@77 6415 // Fix "XHTML"-style tags in all browsers
rob@77 6416 elem = elem.replace(rxhtmlTag, "<$1></$2>");
rob@77 6417
rob@77 6418 // Trim whitespace, otherwise indexOf won't work as expected
rob@77 6419 var tag = ( rtagName.exec( elem ) || ["", ""] )[1].toLowerCase(),
rob@77 6420 wrap = wrapMap[ tag ] || wrapMap._default,
rob@77 6421 depth = wrap[0],
rob@77 6422 div = context.createElement("div"),
rob@77 6423 safeChildNodes = safeFragment.childNodes,
rob@77 6424 remove;
rob@77 6425
rob@77 6426 // Append wrapper element to unknown element safe doc fragment
rob@77 6427 if ( context === document ) {
rob@77 6428 // Use the fragment we've already created for this document
rob@77 6429 safeFragment.appendChild( div );
rob@77 6430 } else {
rob@77 6431 // Use a fragment created with the owner document
rob@77 6432 createSafeFragment( context ).appendChild( div );
rob@77 6433 }
rob@77 6434
rob@77 6435 // Go to html and back, then peel off extra wrappers
rob@77 6436 div.innerHTML = wrap[1] + elem + wrap[2];
rob@77 6437
rob@77 6438 // Move to the right depth
rob@77 6439 while ( depth-- ) {
rob@77 6440 div = div.lastChild;
rob@77 6441 }
rob@77 6442
rob@77 6443 // Remove IE's autoinserted <tbody> from table fragments
rob@77 6444 if ( !jQuery.support.tbody ) {
rob@77 6445
rob@77 6446 // String was a <table>, *may* have spurious <tbody>
rob@77 6447 var hasBody = rtbody.test(elem),
rob@77 6448 tbody = tag === "table" && !hasBody ?
rob@77 6449 div.firstChild && div.firstChild.childNodes :
rob@77 6450
rob@77 6451 // String was a bare <thead> or <tfoot>
rob@77 6452 wrap[1] === "<table>" && !hasBody ?
rob@77 6453 div.childNodes :
rob@77 6454 [];
rob@77 6455
rob@77 6456 for ( j = tbody.length - 1; j >= 0 ; --j ) {
rob@77 6457 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
rob@77 6458 tbody[ j ].parentNode.removeChild( tbody[ j ] );
rob@77 6459 }
rob@77 6460 }
rob@77 6461 }
rob@77 6462
rob@77 6463 // IE completely kills leading whitespace when innerHTML is used
rob@77 6464 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
rob@77 6465 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
rob@77 6466 }
rob@77 6467
rob@77 6468 elem = div.childNodes;
rob@77 6469
rob@77 6470 // Clear elements from DocumentFragment (safeFragment or otherwise)
rob@77 6471 // to avoid hoarding elements. Fixes #11356
rob@77 6472 if ( div ) {
rob@77 6473 div.parentNode.removeChild( div );
rob@77 6474
rob@77 6475 // Guard against -1 index exceptions in FF3.6
rob@77 6476 if ( safeChildNodes.length > 0 ) {
rob@77 6477 remove = safeChildNodes[ safeChildNodes.length - 1 ];
rob@77 6478
rob@77 6479 if ( remove && remove.parentNode ) {
rob@77 6480 remove.parentNode.removeChild( remove );
rob@77 6481 }
rob@77 6482 }
rob@77 6483 }
rob@77 6484 }
rob@77 6485 }
rob@77 6486
rob@77 6487 // Resets defaultChecked for any radios and checkboxes
rob@77 6488 // about to be appended to the DOM in IE 6/7 (#8060)
rob@77 6489 var len;
rob@77 6490 if ( !jQuery.support.appendChecked ) {
rob@77 6491 if ( elem[0] && typeof (len = elem.length) === "number" ) {
rob@77 6492 for ( j = 0; j < len; j++ ) {
rob@77 6493 findInputs( elem[j] );
rob@77 6494 }
rob@77 6495 } else {
rob@77 6496 findInputs( elem );
rob@77 6497 }
rob@77 6498 }
rob@77 6499
rob@77 6500 if ( elem.nodeType ) {
rob@77 6501 ret.push( elem );
rob@77 6502 } else {
rob@77 6503 ret = jQuery.merge( ret, elem );
rob@77 6504 }
rob@77 6505 }
rob@77 6506
rob@77 6507 if ( fragment ) {
rob@77 6508 checkScriptType = function( elem ) {
rob@77 6509 return !elem.type || rscriptType.test( elem.type );
rob@77 6510 };
rob@77 6511 for ( i = 0; ret[i]; i++ ) {
rob@77 6512 script = ret[i];
rob@77 6513 if ( scripts && jQuery.nodeName( script, "script" ) && (!script.type || rscriptType.test( script.type )) ) {
rob@77 6514 scripts.push( script.parentNode ? script.parentNode.removeChild( script ) : script );
rob@77 6515
rob@77 6516 } else {
rob@77 6517 if ( script.nodeType === 1 ) {
rob@77 6518 var jsTags = jQuery.grep( script.getElementsByTagName( "script" ), checkScriptType );
rob@77 6519
rob@77 6520 ret.splice.apply( ret, [i + 1, 0].concat( jsTags ) );
rob@77 6521 }
rob@77 6522 fragment.appendChild( script );
rob@77 6523 }
rob@77 6524 }
rob@77 6525 }
rob@77 6526
rob@77 6527 return ret;
rob@77 6528 },
rob@77 6529
rob@77 6530 cleanData: function( elems ) {
rob@77 6531 var data, id,
rob@77 6532 cache = jQuery.cache,
rob@77 6533 special = jQuery.event.special,
rob@77 6534 deleteExpando = jQuery.support.deleteExpando;
rob@77 6535
rob@77 6536 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
rob@77 6537 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
rob@77 6538 continue;
rob@77 6539 }
rob@77 6540
rob@77 6541 id = elem[ jQuery.expando ];
rob@77 6542
rob@77 6543 if ( id ) {
rob@77 6544 data = cache[ id ];
rob@77 6545
rob@77 6546 if ( data && data.events ) {
rob@77 6547 for ( var type in data.events ) {
rob@77 6548 if ( special[ type ] ) {
rob@77 6549 jQuery.event.remove( elem, type );
rob@77 6550
rob@77 6551 // This is a shortcut to avoid jQuery.event.remove's overhead
rob@77 6552 } else {
rob@77 6553 jQuery.removeEvent( elem, type, data.handle );
rob@77 6554 }
rob@77 6555 }
rob@77 6556
rob@77 6557 // Null the DOM reference to avoid IE6/7/8 leak (#7054)
rob@77 6558 if ( data.handle ) {
rob@77 6559 data.handle.elem = null;
rob@77 6560 }
rob@77 6561 }
rob@77 6562
rob@77 6563 if ( deleteExpando ) {
rob@77 6564 delete elem[ jQuery.expando ];
rob@77 6565
rob@77 6566 } else if ( elem.removeAttribute ) {
rob@77 6567 elem.removeAttribute( jQuery.expando );
rob@77 6568 }
rob@77 6569
rob@77 6570 delete cache[ id ];
rob@77 6571 }
rob@77 6572 }
rob@77 6573 }
rob@77 6574 });
rob@77 6575
rob@77 6576
rob@77 6577
rob@77 6578
rob@77 6579 var ralpha = /alpha\([^)]*\)/i,
rob@77 6580 ropacity = /opacity=([^)]*)/,
rob@77 6581 // fixed for IE9, see #8346
rob@77 6582 rupper = /([A-Z]|^ms)/g,
rob@77 6583 rnum = /^[\-+]?(?:\d*\.)?\d+$/i,
rob@77 6584 rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
rob@77 6585 rrelNum = /^([\-+])=([\-+.\de]+)/,
rob@77 6586 rmargin = /^margin/,
rob@77 6587
rob@77 6588 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
rob@77 6589
rob@77 6590 // order is important!
rob@77 6591 cssExpand = [ "Top", "Right", "Bottom", "Left" ],
rob@77 6592
rob@77 6593 curCSS,
rob@77 6594
rob@77 6595 getComputedStyle,
rob@77 6596 currentStyle;
rob@77 6597
rob@77 6598 jQuery.fn.css = function( name, value ) {
rob@77 6599 return jQuery.access( this, function( elem, name, value ) {
rob@77 6600 return value !== undefined ?
rob@77 6601 jQuery.style( elem, name, value ) :
rob@77 6602 jQuery.css( elem, name );
rob@77 6603 }, name, value, arguments.length > 1 );
rob@77 6604 };
rob@77 6605
rob@77 6606 jQuery.extend({
rob@77 6607 // Add in style property hooks for overriding the default
rob@77 6608 // behavior of getting and setting a style property
rob@77 6609 cssHooks: {
rob@77 6610 opacity: {
rob@77 6611 get: function( elem, computed ) {
rob@77 6612 if ( computed ) {
rob@77 6613 // We should always get a number back from opacity
rob@77 6614 var ret = curCSS( elem, "opacity" );
rob@77 6615 return ret === "" ? "1" : ret;
rob@77 6616
rob@77 6617 } else {
rob@77 6618 return elem.style.opacity;
rob@77 6619 }
rob@77 6620 }
rob@77 6621 }
rob@77 6622 },
rob@77 6623
rob@77 6624 // Exclude the following css properties to add px
rob@77 6625 cssNumber: {
rob@77 6626 "fillOpacity": true,
rob@77 6627 "fontWeight": true,
rob@77 6628 "lineHeight": true,
rob@77 6629 "opacity": true,
rob@77 6630 "orphans": true,
rob@77 6631 "widows": true,
rob@77 6632 "zIndex": true,
rob@77 6633 "zoom": true
rob@77 6634 },
rob@77 6635
rob@77 6636 // Add in properties whose names you wish to fix before
rob@77 6637 // setting or getting the value
rob@77 6638 cssProps: {
rob@77 6639 // normalize float css property
rob@77 6640 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
rob@77 6641 },
rob@77 6642
rob@77 6643 // Get and set the style property on a DOM Node
rob@77 6644 style: function( elem, name, value, extra ) {
rob@77 6645 // Don't set styles on text and comment nodes
rob@77 6646 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
rob@77 6647 return;
rob@77 6648 }
rob@77 6649
rob@77 6650 // Make sure that we're working with the right name
rob@77 6651 var ret, type, origName = jQuery.camelCase( name ),
rob@77 6652 style = elem.style, hooks = jQuery.cssHooks[ origName ];
rob@77 6653
rob@77 6654 name = jQuery.cssProps[ origName ] || origName;
rob@77 6655
rob@77 6656 // Check if we're setting a value
rob@77 6657 if ( value !== undefined ) {
rob@77 6658 type = typeof value;
rob@77 6659
rob@77 6660 // convert relative number strings (+= or -=) to relative numbers. #7345
rob@77 6661 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
rob@77 6662 value = ( +( ret[1] + 1) * +ret[2] ) + parseFloat( jQuery.css( elem, name ) );
rob@77 6663 // Fixes bug #9237
rob@77 6664 type = "number";
rob@77 6665 }
rob@77 6666
rob@77 6667 // Make sure that NaN and null values aren't set. See: #7116
rob@77 6668 if ( value == null || type === "number" && isNaN( value ) ) {
rob@77 6669 return;
rob@77 6670 }
rob@77 6671
rob@77 6672 // If a number was passed in, add 'px' to the (except for certain CSS properties)
rob@77 6673 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
rob@77 6674 value += "px";
rob@77 6675 }
rob@77 6676
rob@77 6677 // If a hook was provided, use that value, otherwise just set the specified value
rob@77 6678 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
rob@77 6679 // Wrapped to prevent IE from throwing errors when 'invalid' values are provided
rob@77 6680 // Fixes bug #5509
rob@77 6681 try {
rob@77 6682 style[ name ] = value;
rob@77 6683 } catch(e) {}
rob@77 6684 }
rob@77 6685
rob@77 6686 } else {
rob@77 6687 // If a hook was provided get the non-computed value from there
rob@77 6688 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
rob@77 6689 return ret;
rob@77 6690 }
rob@77 6691
rob@77 6692 // Otherwise just get the value from the style object
rob@77 6693 return style[ name ];
rob@77 6694 }
rob@77 6695 },
rob@77 6696
rob@77 6697 css: function( elem, name, extra ) {
rob@77 6698 var ret, hooks;
rob@77 6699
rob@77 6700 // Make sure that we're working with the right name
rob@77 6701 name = jQuery.camelCase( name );
rob@77 6702 hooks = jQuery.cssHooks[ name ];
rob@77 6703 name = jQuery.cssProps[ name ] || name;
rob@77 6704
rob@77 6705 // cssFloat needs a special treatment
rob@77 6706 if ( name === "cssFloat" ) {
rob@77 6707 name = "float";
rob@77 6708 }
rob@77 6709
rob@77 6710 // If a hook was provided get the computed value from there
rob@77 6711 if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
rob@77 6712 return ret;
rob@77 6713
rob@77 6714 // Otherwise, if a way to get the computed value exists, use that
rob@77 6715 } else if ( curCSS ) {
rob@77 6716 return curCSS( elem, name );
rob@77 6717 }
rob@77 6718 },
rob@77 6719
rob@77 6720 // A method for quickly swapping in/out CSS properties to get correct calculations
rob@77 6721 swap: function( elem, options, callback ) {
rob@77 6722 var old = {},
rob@77 6723 ret, name;
rob@77 6724
rob@77 6725 // Remember the old values, and insert the new ones
rob@77 6726 for ( name in options ) {
rob@77 6727 old[ name ] = elem.style[ name ];
rob@77 6728 elem.style[ name ] = options[ name ];
rob@77 6729 }
rob@77 6730
rob@77 6731 ret = callback.call( elem );
rob@77 6732
rob@77 6733 // Revert the old values
rob@77 6734 for ( name in options ) {
rob@77 6735 elem.style[ name ] = old[ name ];
rob@77 6736 }
rob@77 6737
rob@77 6738 return ret;
rob@77 6739 }
rob@77 6740 });
rob@77 6741
rob@77 6742 // DEPRECATED in 1.3, Use jQuery.css() instead
rob@77 6743 jQuery.curCSS = jQuery.css;
rob@77 6744
rob@77 6745 if ( document.defaultView && document.defaultView.getComputedStyle ) {
rob@77 6746 getComputedStyle = function( elem, name ) {
rob@77 6747 var ret, defaultView, computedStyle, width,
rob@77 6748 style = elem.style;
rob@77 6749
rob@77 6750 name = name.replace( rupper, "-$1" ).toLowerCase();
rob@77 6751
rob@77 6752 if ( (defaultView = elem.ownerDocument.defaultView) &&
rob@77 6753 (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
rob@77 6754
rob@77 6755 ret = computedStyle.getPropertyValue( name );
rob@77 6756 if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
rob@77 6757 ret = jQuery.style( elem, name );
rob@77 6758 }
rob@77 6759 }
rob@77 6760
rob@77 6761 // A tribute to the "awesome hack by Dean Edwards"
rob@77 6762 // WebKit uses "computed value (percentage if specified)" instead of "used value" for margins
rob@77 6763 // which is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
rob@77 6764 if ( !jQuery.support.pixelMargin && computedStyle && rmargin.test( name ) && rnumnonpx.test( ret ) ) {
rob@77 6765 width = style.width;
rob@77 6766 style.width = ret;
rob@77 6767 ret = computedStyle.width;
rob@77 6768 style.width = width;
rob@77 6769 }
rob@77 6770
rob@77 6771 return ret;
rob@77 6772 };
rob@77 6773 }
rob@77 6774
rob@77 6775 if ( document.documentElement.currentStyle ) {
rob@77 6776 currentStyle = function( elem, name ) {
rob@77 6777 var left, rsLeft, uncomputed,
rob@77 6778 ret = elem.currentStyle && elem.currentStyle[ name ],
rob@77 6779 style = elem.style;
rob@77 6780
rob@77 6781 // Avoid setting ret to empty string here
rob@77 6782 // so we don't default to auto
rob@77 6783 if ( ret == null && style && (uncomputed = style[ name ]) ) {
rob@77 6784 ret = uncomputed;
rob@77 6785 }
rob@77 6786
rob@77 6787 // From the awesome hack by Dean Edwards
rob@77 6788 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
rob@77 6789
rob@77 6790 // If we're not dealing with a regular pixel number
rob@77 6791 // but a number that has a weird ending, we need to convert it to pixels
rob@77 6792 if ( rnumnonpx.test( ret ) ) {
rob@77 6793
rob@77 6794 // Remember the original values
rob@77 6795 left = style.left;
rob@77 6796 rsLeft = elem.runtimeStyle && elem.runtimeStyle.left;
rob@77 6797
rob@77 6798 // Put in the new values to get a computed value out
rob@77 6799 if ( rsLeft ) {
rob@77 6800 elem.runtimeStyle.left = elem.currentStyle.left;
rob@77 6801 }
rob@77 6802 style.left = name === "fontSize" ? "1em" : ret;
rob@77 6803 ret = style.pixelLeft + "px";
rob@77 6804
rob@77 6805 // Revert the changed values
rob@77 6806 style.left = left;
rob@77 6807 if ( rsLeft ) {
rob@77 6808 elem.runtimeStyle.left = rsLeft;
rob@77 6809 }
rob@77 6810 }
rob@77 6811
rob@77 6812 return ret === "" ? "auto" : ret;
rob@77 6813 };
rob@77 6814 }
rob@77 6815
rob@77 6816 curCSS = getComputedStyle || currentStyle;
rob@77 6817
rob@77 6818 function getWidthOrHeight( elem, name, extra ) {
rob@77 6819
rob@77 6820 // Start with offset property
rob@77 6821 var val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
rob@77 6822 i = name === "width" ? 1 : 0,
rob@77 6823 len = 4;
rob@77 6824
rob@77 6825 if ( val > 0 ) {
rob@77 6826 if ( extra !== "border" ) {
rob@77 6827 for ( ; i < len; i += 2 ) {
rob@77 6828 if ( !extra ) {
rob@77 6829 val -= parseFloat( jQuery.css( elem, "padding" + cssExpand[ i ] ) ) || 0;
rob@77 6830 }
rob@77 6831 if ( extra === "margin" ) {
rob@77 6832 val += parseFloat( jQuery.css( elem, extra + cssExpand[ i ] ) ) || 0;
rob@77 6833 } else {
rob@77 6834 val -= parseFloat( jQuery.css( elem, "border" + cssExpand[ i ] + "Width" ) ) || 0;
rob@77 6835 }
rob@77 6836 }
rob@77 6837 }
rob@77 6838
rob@77 6839 return val + "px";
rob@77 6840 }
rob@77 6841
rob@77 6842 // Fall back to computed then uncomputed css if necessary
rob@77 6843 val = curCSS( elem, name );
rob@77 6844 if ( val < 0 || val == null ) {
rob@77 6845 val = elem.style[ name ];
rob@77 6846 }
rob@77 6847
rob@77 6848 // Computed unit is not pixels. Stop here and return.
rob@77 6849 if ( rnumnonpx.test(val) ) {
rob@77 6850 return val;
rob@77 6851 }
rob@77 6852
rob@77 6853 // Normalize "", auto, and prepare for extra
rob@77 6854 val = parseFloat( val ) || 0;
rob@77 6855
rob@77 6856 // Add padding, border, margin
rob@77 6857 if ( extra ) {
rob@77 6858 for ( ; i < len; i += 2 ) {
rob@77 6859 val += parseFloat( jQuery.css( elem, "padding" + cssExpand[ i ] ) ) || 0;
rob@77 6860 if ( extra !== "padding" ) {
rob@77 6861 val += parseFloat( jQuery.css( elem, "border" + cssExpand[ i ] + "Width" ) ) || 0;
rob@77 6862 }
rob@77 6863 if ( extra === "margin" ) {
rob@77 6864 val += parseFloat( jQuery.css( elem, extra + cssExpand[ i ]) ) || 0;
rob@77 6865 }
rob@77 6866 }
rob@77 6867 }
rob@77 6868
rob@77 6869 return val + "px";
rob@77 6870 }
rob@77 6871
rob@77 6872 jQuery.each([ "height", "width" ], function( i, name ) {
rob@77 6873 jQuery.cssHooks[ name ] = {
rob@77 6874 get: function( elem, computed, extra ) {
rob@77 6875 if ( computed ) {
rob@77 6876 if ( elem.offsetWidth !== 0 ) {
rob@77 6877 return getWidthOrHeight( elem, name, extra );
rob@77 6878 } else {
rob@77 6879 return jQuery.swap( elem, cssShow, function() {
rob@77 6880 return getWidthOrHeight( elem, name, extra );
rob@77 6881 });
rob@77 6882 }
rob@77 6883 }
rob@77 6884 },
rob@77 6885
rob@77 6886 set: function( elem, value ) {
rob@77 6887 return rnum.test( value ) ?
rob@77 6888 value + "px" :
rob@77 6889 value;
rob@77 6890 }
rob@77 6891 };
rob@77 6892 });
rob@77 6893
rob@77 6894 if ( !jQuery.support.opacity ) {
rob@77 6895 jQuery.cssHooks.opacity = {
rob@77 6896 get: function( elem, computed ) {
rob@77 6897 // IE uses filters for opacity
rob@77 6898 return ropacity.test( (computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "" ) ?
rob@77 6899 ( parseFloat( RegExp.$1 ) / 100 ) + "" :
rob@77 6900 computed ? "1" : "";
rob@77 6901 },
rob@77 6902
rob@77 6903 set: function( elem, value ) {
rob@77 6904 var style = elem.style,
rob@77 6905 currentStyle = elem.currentStyle,
rob@77 6906 opacity = jQuery.isNumeric( value ) ? "alpha(opacity=" + value * 100 + ")" : "",
rob@77 6907 filter = currentStyle && currentStyle.filter || style.filter || "";
rob@77 6908
rob@77 6909 // IE has trouble with opacity if it does not have layout
rob@77 6910 // Force it by setting the zoom level
rob@77 6911 style.zoom = 1;
rob@77 6912
rob@77 6913 // if setting opacity to 1, and no other filters exist - attempt to remove filter attribute #6652
rob@77 6914 if ( value >= 1 && jQuery.trim( filter.replace( ralpha, "" ) ) === "" ) {
rob@77 6915
rob@77 6916 // Setting style.filter to null, "" & " " still leave "filter:" in the cssText
rob@77 6917 // if "filter:" is present at all, clearType is disabled, we want to avoid this
rob@77 6918 // style.removeAttribute is IE Only, but so apparently is this code path...
rob@77 6919 style.removeAttribute( "filter" );
rob@77 6920
rob@77 6921 // if there there is no filter style applied in a css rule, we are done
rob@77 6922 if ( currentStyle && !currentStyle.filter ) {
rob@77 6923 return;
rob@77 6924 }
rob@77 6925 }
rob@77 6926
rob@77 6927 // otherwise, set new filter values
rob@77 6928 style.filter = ralpha.test( filter ) ?
rob@77 6929 filter.replace( ralpha, opacity ) :
rob@77 6930 filter + " " + opacity;
rob@77 6931 }
rob@77 6932 };
rob@77 6933 }
rob@77 6934
rob@77 6935 jQuery(function() {
rob@77 6936 // This hook cannot be added until DOM ready because the support test
rob@77 6937 // for it is not run until after DOM ready
rob@77 6938 if ( !jQuery.support.reliableMarginRight ) {
rob@77 6939 jQuery.cssHooks.marginRight = {
rob@77 6940 get: function( elem, computed ) {
rob@77 6941 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
rob@77 6942 // Work around by temporarily setting element display to inline-block
rob@77 6943 return jQuery.swap( elem, { "display": "inline-block" }, function() {
rob@77 6944 if ( computed ) {
rob@77 6945 return curCSS( elem, "margin-right" );
rob@77 6946 } else {
rob@77 6947 return elem.style.marginRight;
rob@77 6948 }
rob@77 6949 });
rob@77 6950 }
rob@77 6951 };
rob@77 6952 }
rob@77 6953 });
rob@77 6954
rob@77 6955 if ( jQuery.expr && jQuery.expr.filters ) {
rob@77 6956 jQuery.expr.filters.hidden = function( elem ) {
rob@77 6957 var width = elem.offsetWidth,
rob@77 6958 height = elem.offsetHeight;
rob@77 6959
rob@77 6960 return ( width === 0 && height === 0 ) || (!jQuery.support.reliableHiddenOffsets && ((elem.style && elem.style.display) || jQuery.css( elem, "display" )) === "none");
rob@77 6961 };
rob@77 6962
rob@77 6963 jQuery.expr.filters.visible = function( elem ) {
rob@77 6964 return !jQuery.expr.filters.hidden( elem );
rob@77 6965 };
rob@77 6966 }
rob@77 6967
rob@77 6968 // These hooks are used by animate to expand properties
rob@77 6969 jQuery.each({
rob@77 6970 margin: "",
rob@77 6971 padding: "",
rob@77 6972 border: "Width"
rob@77 6973 }, function( prefix, suffix ) {
rob@77 6974
rob@77 6975 jQuery.cssHooks[ prefix + suffix ] = {
rob@77 6976 expand: function( value ) {
rob@77 6977 var i,
rob@77 6978
rob@77 6979 // assumes a single number if not a string
rob@77 6980 parts = typeof value === "string" ? value.split(" ") : [ value ],
rob@77 6981 expanded = {};
rob@77 6982
rob@77 6983 for ( i = 0; i < 4; i++ ) {
rob@77 6984 expanded[ prefix + cssExpand[ i ] + suffix ] =
rob@77 6985 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
rob@77 6986 }
rob@77 6987
rob@77 6988 return expanded;
rob@77 6989 }
rob@77 6990 };
rob@77 6991 });
rob@77 6992
rob@77 6993
rob@77 6994
rob@77 6995
rob@77 6996 var r20 = /%20/g,
rob@77 6997 rbracket = /\[\]$/,
rob@77 6998 rCRLF = /\r?\n/g,
rob@77 6999 rhash = /#.*$/,
rob@77 7000 rheaders = /^(.*?):[ \t]*([^\r\n]*)\r?$/mg, // IE leaves an \r character at EOL
rob@77 7001 rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
rob@77 7002 // #7653, #8125, #8152: local protocol detection
rob@77 7003 rlocalProtocol = /^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,
rob@77 7004 rnoContent = /^(?:GET|HEAD)$/,
rob@77 7005 rprotocol = /^\/\//,
rob@77 7006 rquery = /\?/,
rob@77 7007 rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
rob@77 7008 rselectTextarea = /^(?:select|textarea)/i,
rob@77 7009 rspacesAjax = /\s+/,
rob@77 7010 rts = /([?&])_=[^&]*/,
rob@77 7011 rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
rob@77 7012
rob@77 7013 // Keep a copy of the old load method
rob@77 7014 _load = jQuery.fn.load,
rob@77 7015
rob@77 7016 /* Prefilters
rob@77 7017 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
rob@77 7018 * 2) These are called:
rob@77 7019 * - BEFORE asking for a transport
rob@77 7020 * - AFTER param serialization (s.data is a string if s.processData is true)
rob@77 7021 * 3) key is the dataType
rob@77 7022 * 4) the catchall symbol "*" can be used
rob@77 7023 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
rob@77 7024 */
rob@77 7025 prefilters = {},
rob@77 7026
rob@77 7027 /* Transports bindings
rob@77 7028 * 1) key is the dataType
rob@77 7029 * 2) the catchall symbol "*" can be used
rob@77 7030 * 3) selection will start with transport dataType and THEN go to "*" if needed
rob@77 7031 */
rob@77 7032 transports = {},
rob@77 7033
rob@77 7034 // Document location
rob@77 7035 ajaxLocation,
rob@77 7036
rob@77 7037 // Document location segments
rob@77 7038 ajaxLocParts,
rob@77 7039
rob@77 7040 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
rob@77 7041 allTypes = ["*/"] + ["*"];
rob@77 7042
rob@77 7043 // #8138, IE may throw an exception when accessing
rob@77 7044 // a field from window.location if document.domain has been set
rob@77 7045 try {
rob@77 7046 ajaxLocation = location.href;
rob@77 7047 } catch( e ) {
rob@77 7048 // Use the href attribute of an A element
rob@77 7049 // since IE will modify it given document.location
rob@77 7050 ajaxLocation = document.createElement( "a" );
rob@77 7051 ajaxLocation.href = "";
rob@77 7052 ajaxLocation = ajaxLocation.href;
rob@77 7053 }
rob@77 7054
rob@77 7055 // Segment location into parts
rob@77 7056 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
rob@77 7057
rob@77 7058 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
rob@77 7059 function addToPrefiltersOrTransports( structure ) {
rob@77 7060
rob@77 7061 // dataTypeExpression is optional and defaults to "*"
rob@77 7062 return function( dataTypeExpression, func ) {
rob@77 7063
rob@77 7064 if ( typeof dataTypeExpression !== "string" ) {
rob@77 7065 func = dataTypeExpression;
rob@77 7066 dataTypeExpression = "*";
rob@77 7067 }
rob@77 7068
rob@77 7069 if ( jQuery.isFunction( func ) ) {
rob@77 7070 var dataTypes = dataTypeExpression.toLowerCase().split( rspacesAjax ),
rob@77 7071 i = 0,
rob@77 7072 length = dataTypes.length,
rob@77 7073 dataType,
rob@77 7074 list,
rob@77 7075 placeBefore;
rob@77 7076
rob@77 7077 // For each dataType in the dataTypeExpression
rob@77 7078 for ( ; i < length; i++ ) {
rob@77 7079 dataType = dataTypes[ i ];
rob@77 7080 // We control if we're asked to add before
rob@77 7081 // any existing element
rob@77 7082 placeBefore = /^\+/.test( dataType );
rob@77 7083 if ( placeBefore ) {
rob@77 7084 dataType = dataType.substr( 1 ) || "*";
rob@77 7085 }
rob@77 7086 list = structure[ dataType ] = structure[ dataType ] || [];
rob@77 7087 // then we add to the structure accordingly
rob@77 7088 list[ placeBefore ? "unshift" : "push" ]( func );
rob@77 7089 }
rob@77 7090 }
rob@77 7091 };
rob@77 7092 }
rob@77 7093
rob@77 7094 // Base inspection function for prefilters and transports
rob@77 7095 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR,
rob@77 7096 dataType /* internal */, inspected /* internal */ ) {
rob@77 7097
rob@77 7098 dataType = dataType || options.dataTypes[ 0 ];
rob@77 7099 inspected = inspected || {};
rob@77 7100
rob@77 7101 inspected[ dataType ] = true;
rob@77 7102
rob@77 7103 var list = structure[ dataType ],
rob@77 7104 i = 0,
rob@77 7105 length = list ? list.length : 0,
rob@77 7106 executeOnly = ( structure === prefilters ),
rob@77 7107 selection;
rob@77 7108
rob@77 7109 for ( ; i < length && ( executeOnly || !selection ); i++ ) {
rob@77 7110 selection = list[ i ]( options, originalOptions, jqXHR );
rob@77 7111 // If we got redirected to another dataType
rob@77 7112 // we try there if executing only and not done already
rob@77 7113 if ( typeof selection === "string" ) {
rob@77 7114 if ( !executeOnly || inspected[ selection ] ) {
rob@77 7115 selection = undefined;
rob@77 7116 } else {
rob@77 7117 options.dataTypes.unshift( selection );
rob@77 7118 selection = inspectPrefiltersOrTransports(
rob@77 7119 structure, options, originalOptions, jqXHR, selection, inspected );
rob@77 7120 }
rob@77 7121 }
rob@77 7122 }
rob@77 7123 // If we're only executing or nothing was selected
rob@77 7124 // we try the catchall dataType if not done already
rob@77 7125 if ( ( executeOnly || !selection ) && !inspected[ "*" ] ) {
rob@77 7126 selection = inspectPrefiltersOrTransports(
rob@77 7127 structure, options, originalOptions, jqXHR, "*", inspected );
rob@77 7128 }
rob@77 7129 // unnecessary when only executing (prefilters)
rob@77 7130 // but it'll be ignored by the caller in that case
rob@77 7131 return selection;
rob@77 7132 }
rob@77 7133
rob@77 7134 // A special extend for ajax options
rob@77 7135 // that takes "flat" options (not to be deep extended)
rob@77 7136 // Fixes #9887
rob@77 7137 function ajaxExtend( target, src ) {
rob@77 7138 var key, deep,
rob@77 7139 flatOptions = jQuery.ajaxSettings.flatOptions || {};
rob@77 7140 for ( key in src ) {
rob@77 7141 if ( src[ key ] !== undefined ) {
rob@77 7142 ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
rob@77 7143 }
rob@77 7144 }
rob@77 7145 if ( deep ) {
rob@77 7146 jQuery.extend( true, target, deep );
rob@77 7147 }
rob@77 7148 }
rob@77 7149
rob@77 7150 jQuery.fn.extend({
rob@77 7151 load: function( url, params, callback ) {
rob@77 7152 if ( typeof url !== "string" && _load ) {
rob@77 7153 return _load.apply( this, arguments );
rob@77 7154
rob@77 7155 // Don't do a request if no elements are being requested
rob@77 7156 } else if ( !this.length ) {
rob@77 7157 return this;
rob@77 7158 }
rob@77 7159
rob@77 7160 var off = url.indexOf( " " );
rob@77 7161 if ( off >= 0 ) {
rob@77 7162 var selector = url.slice( off, url.length );
rob@77 7163 url = url.slice( 0, off );
rob@77 7164 }
rob@77 7165
rob@77 7166 // Default to a GET request
rob@77 7167 var type = "GET";
rob@77 7168
rob@77 7169 // If the second parameter was provided
rob@77 7170 if ( params ) {
rob@77 7171 // If it's a function
rob@77 7172 if ( jQuery.isFunction( params ) ) {
rob@77 7173 // We assume that it's the callback
rob@77 7174 callback = params;
rob@77 7175 params = undefined;
rob@77 7176
rob@77 7177 // Otherwise, build a param string
rob@77 7178 } else if ( typeof params === "object" ) {
rob@77 7179 params = jQuery.param( params, jQuery.ajaxSettings.traditional );
rob@77 7180 type = "POST";
rob@77 7181 }
rob@77 7182 }
rob@77 7183
rob@77 7184 var self = this;
rob@77 7185
rob@77 7186 // Request the remote document
rob@77 7187 jQuery.ajax({
rob@77 7188 url: url,
rob@77 7189 type: type,
rob@77 7190 dataType: "html",
rob@77 7191 data: params,
rob@77 7192 // Complete callback (responseText is used internally)
rob@77 7193 complete: function( jqXHR, status, responseText ) {
rob@77 7194 // Store the response as specified by the jqXHR object
rob@77 7195 responseText = jqXHR.responseText;
rob@77 7196 // If successful, inject the HTML into all the matched elements
rob@77 7197 if ( jqXHR.isResolved() ) {
rob@77 7198 // #4825: Get the actual response in case
rob@77 7199 // a dataFilter is present in ajaxSettings
rob@77 7200 jqXHR.done(function( r ) {
rob@77 7201 responseText = r;
rob@77 7202 });
rob@77 7203 // See if a selector was specified
rob@77 7204 self.html( selector ?
rob@77 7205 // Create a dummy div to hold the results
rob@77 7206 jQuery("<div>")
rob@77 7207 // inject the contents of the document in, removing the scripts
rob@77 7208 // to avoid any 'Permission Denied' errors in IE
rob@77 7209 .append(responseText.replace(rscript, ""))
rob@77 7210
rob@77 7211 // Locate the specified elements
rob@77 7212 .find(selector) :
rob@77 7213
rob@77 7214 // If not, just inject the full result
rob@77 7215 responseText );
rob@77 7216 }
rob@77 7217
rob@77 7218 if ( callback ) {
rob@77 7219 self.each( callback, [ responseText, status, jqXHR ] );
rob@77 7220 }
rob@77 7221 }
rob@77 7222 });
rob@77 7223
rob@77 7224 return this;
rob@77 7225 },
rob@77 7226
rob@77 7227 serialize: function() {
rob@77 7228 return jQuery.param( this.serializeArray() );
rob@77 7229 },
rob@77 7230
rob@77 7231 serializeArray: function() {
rob@77 7232 return this.map(function(){
rob@77 7233 return this.elements ? jQuery.makeArray( this.elements ) : this;
rob@77 7234 })
rob@77 7235 .filter(function(){
rob@77 7236 return this.name && !this.disabled &&
rob@77 7237 ( this.checked || rselectTextarea.test( this.nodeName ) ||
rob@77 7238 rinput.test( this.type ) );
rob@77 7239 })
rob@77 7240 .map(function( i, elem ){
rob@77 7241 var val = jQuery( this ).val();
rob@77 7242
rob@77 7243 return val == null ?
rob@77 7244 null :
rob@77 7245 jQuery.isArray( val ) ?
rob@77 7246 jQuery.map( val, function( val, i ){
rob@77 7247 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
rob@77 7248 }) :
rob@77 7249 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
rob@77 7250 }).get();
rob@77 7251 }
rob@77 7252 });
rob@77 7253
rob@77 7254 // Attach a bunch of functions for handling common AJAX events
rob@77 7255 jQuery.each( "ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split( " " ), function( i, o ){
rob@77 7256 jQuery.fn[ o ] = function( f ){
rob@77 7257 return this.on( o, f );
rob@77 7258 };
rob@77 7259 });
rob@77 7260
rob@77 7261 jQuery.each( [ "get", "post" ], function( i, method ) {
rob@77 7262 jQuery[ method ] = function( url, data, callback, type ) {
rob@77 7263 // shift arguments if data argument was omitted
rob@77 7264 if ( jQuery.isFunction( data ) ) {
rob@77 7265 type = type || callback;
rob@77 7266 callback = data;
rob@77 7267 data = undefined;
rob@77 7268 }
rob@77 7269
rob@77 7270 return jQuery.ajax({
rob@77 7271 type: method,
rob@77 7272 url: url,
rob@77 7273 data: data,
rob@77 7274 success: callback,
rob@77 7275 dataType: type
rob@77 7276 });
rob@77 7277 };
rob@77 7278 });
rob@77 7279
rob@77 7280 jQuery.extend({
rob@77 7281
rob@77 7282 getScript: function( url, callback ) {
rob@77 7283 return jQuery.get( url, undefined, callback, "script" );
rob@77 7284 },
rob@77 7285
rob@77 7286 getJSON: function( url, data, callback ) {
rob@77 7287 return jQuery.get( url, data, callback, "json" );
rob@77 7288 },
rob@77 7289
rob@77 7290 // Creates a full fledged settings object into target
rob@77 7291 // with both ajaxSettings and settings fields.
rob@77 7292 // If target is omitted, writes into ajaxSettings.
rob@77 7293 ajaxSetup: function( target, settings ) {
rob@77 7294 if ( settings ) {
rob@77 7295 // Building a settings object
rob@77 7296 ajaxExtend( target, jQuery.ajaxSettings );
rob@77 7297 } else {
rob@77 7298 // Extending ajaxSettings
rob@77 7299 settings = target;
rob@77 7300 target = jQuery.ajaxSettings;
rob@77 7301 }
rob@77 7302 ajaxExtend( target, settings );
rob@77 7303 return target;
rob@77 7304 },
rob@77 7305
rob@77 7306 ajaxSettings: {
rob@77 7307 url: ajaxLocation,
rob@77 7308 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
rob@77 7309 global: true,
rob@77 7310 type: "GET",
rob@77 7311 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
rob@77 7312 processData: true,
rob@77 7313 async: true,
rob@77 7314 /*
rob@77 7315 timeout: 0,
rob@77 7316 data: null,
rob@77 7317 dataType: null,
rob@77 7318 username: null,
rob@77 7319 password: null,
rob@77 7320 cache: null,
rob@77 7321 traditional: false,
rob@77 7322 headers: {},
rob@77 7323 */
rob@77 7324
rob@77 7325 accepts: {
rob@77 7326 xml: "application/xml, text/xml",
rob@77 7327 html: "text/html",
rob@77 7328 text: "text/plain",
rob@77 7329 json: "application/json, text/javascript",
rob@77 7330 "*": allTypes
rob@77 7331 },
rob@77 7332
rob@77 7333 contents: {
rob@77 7334 xml: /xml/,
rob@77 7335 html: /html/,
rob@77 7336 json: /json/
rob@77 7337 },
rob@77 7338
rob@77 7339 responseFields: {
rob@77 7340 xml: "responseXML",
rob@77 7341 text: "responseText"
rob@77 7342 },
rob@77 7343
rob@77 7344 // List of data converters
rob@77 7345 // 1) key format is "source_type destination_type" (a single space in-between)
rob@77 7346 // 2) the catchall symbol "*" can be used for source_type
rob@77 7347 converters: {
rob@77 7348
rob@77 7349 // Convert anything to text
rob@77 7350 "* text": window.String,
rob@77 7351
rob@77 7352 // Text to html (true = no transformation)
rob@77 7353 "text html": true,
rob@77 7354
rob@77 7355 // Evaluate text as a json expression
rob@77 7356 "text json": jQuery.parseJSON,
rob@77 7357
rob@77 7358 // Parse text as xml
rob@77 7359 "text xml": jQuery.parseXML
rob@77 7360 },
rob@77 7361
rob@77 7362 // For options that shouldn't be deep extended:
rob@77 7363 // you can add your own custom options here if
rob@77 7364 // and when you create one that shouldn't be
rob@77 7365 // deep extended (see ajaxExtend)
rob@77 7366 flatOptions: {
rob@77 7367 context: true,
rob@77 7368 url: true
rob@77 7369 }
rob@77 7370 },
rob@77 7371
rob@77 7372 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
rob@77 7373 ajaxTransport: addToPrefiltersOrTransports( transports ),
rob@77 7374
rob@77 7375 // Main method
rob@77 7376 ajax: function( url, options ) {
rob@77 7377
rob@77 7378 // If url is an object, simulate pre-1.5 signature
rob@77 7379 if ( typeof url === "object" ) {
rob@77 7380 options = url;
rob@77 7381 url = undefined;
rob@77 7382 }
rob@77 7383
rob@77 7384 // Force options to be an object
rob@77 7385 options = options || {};
rob@77 7386
rob@77 7387 var // Create the final options object
rob@77 7388 s = jQuery.ajaxSetup( {}, options ),
rob@77 7389 // Callbacks context
rob@77 7390 callbackContext = s.context || s,
rob@77 7391 // Context for global events
rob@77 7392 // It's the callbackContext if one was provided in the options
rob@77 7393 // and if it's a DOM node or a jQuery collection
rob@77 7394 globalEventContext = callbackContext !== s &&
rob@77 7395 ( callbackContext.nodeType || callbackContext instanceof jQuery ) ?
rob@77 7396 jQuery( callbackContext ) : jQuery.event,
rob@77 7397 // Deferreds
rob@77 7398 deferred = jQuery.Deferred(),
rob@77 7399 completeDeferred = jQuery.Callbacks( "once memory" ),
rob@77 7400 // Status-dependent callbacks
rob@77 7401 statusCode = s.statusCode || {},
rob@77 7402 // ifModified key
rob@77 7403 ifModifiedKey,
rob@77 7404 // Headers (they are sent all at once)
rob@77 7405 requestHeaders = {},
rob@77 7406 requestHeadersNames = {},
rob@77 7407 // Response headers
rob@77 7408 responseHeadersString,
rob@77 7409 responseHeaders,
rob@77 7410 // transport
rob@77 7411 transport,
rob@77 7412 // timeout handle
rob@77 7413 timeoutTimer,
rob@77 7414 // Cross-domain detection vars
rob@77 7415 parts,
rob@77 7416 // The jqXHR state
rob@77 7417 state = 0,
rob@77 7418 // To know if global events are to be dispatched
rob@77 7419 fireGlobals,
rob@77 7420 // Loop variable
rob@77 7421 i,
rob@77 7422 // Fake xhr
rob@77 7423 jqXHR = {
rob@77 7424
rob@77 7425 readyState: 0,
rob@77 7426
rob@77 7427 // Caches the header
rob@77 7428 setRequestHeader: function( name, value ) {
rob@77 7429 if ( !state ) {
rob@77 7430 var lname = name.toLowerCase();
rob@77 7431 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
rob@77 7432 requestHeaders[ name ] = value;
rob@77 7433 }
rob@77 7434 return this;
rob@77 7435 },
rob@77 7436
rob@77 7437 // Raw string
rob@77 7438 getAllResponseHeaders: function() {
rob@77 7439 return state === 2 ? responseHeadersString : null;
rob@77 7440 },
rob@77 7441
rob@77 7442 // Builds headers hashtable if needed
rob@77 7443 getResponseHeader: function( key ) {
rob@77 7444 var match;
rob@77 7445 if ( state === 2 ) {
rob@77 7446 if ( !responseHeaders ) {
rob@77 7447 responseHeaders = {};
rob@77 7448 while( ( match = rheaders.exec( responseHeadersString ) ) ) {
rob@77 7449 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
rob@77 7450 }
rob@77 7451 }
rob@77 7452 match = responseHeaders[ key.toLowerCase() ];
rob@77 7453 }
rob@77 7454 return match === undefined ? null : match;
rob@77 7455 },
rob@77 7456
rob@77 7457 // Overrides response content-type header
rob@77 7458 overrideMimeType: function( type ) {
rob@77 7459 if ( !state ) {
rob@77 7460 s.mimeType = type;
rob@77 7461 }
rob@77 7462 return this;
rob@77 7463 },
rob@77 7464
rob@77 7465 // Cancel the request
rob@77 7466 abort: function( statusText ) {
rob@77 7467 statusText = statusText || "abort";
rob@77 7468 if ( transport ) {
rob@77 7469 transport.abort( statusText );
rob@77 7470 }
rob@77 7471 done( 0, statusText );
rob@77 7472 return this;
rob@77 7473 }
rob@77 7474 };
rob@77 7475
rob@77 7476 // Callback for when everything is done
rob@77 7477 // It is defined here because jslint complains if it is declared
rob@77 7478 // at the end of the function (which would be more logical and readable)
rob@77 7479 function done( status, nativeStatusText, responses, headers ) {
rob@77 7480
rob@77 7481 // Called once
rob@77 7482 if ( state === 2 ) {
rob@77 7483 return;
rob@77 7484 }
rob@77 7485
rob@77 7486 // State is "done" now
rob@77 7487 state = 2;
rob@77 7488
rob@77 7489 // Clear timeout if it exists
rob@77 7490 if ( timeoutTimer ) {
rob@77 7491 clearTimeout( timeoutTimer );
rob@77 7492 }
rob@77 7493
rob@77 7494 // Dereference transport for early garbage collection
rob@77 7495 // (no matter how long the jqXHR object will be used)
rob@77 7496 transport = undefined;
rob@77 7497
rob@77 7498 // Cache response headers
rob@77 7499 responseHeadersString = headers || "";
rob@77 7500
rob@77 7501 // Set readyState
rob@77 7502 jqXHR.readyState = status > 0 ? 4 : 0;
rob@77 7503
rob@77 7504 var isSuccess,
rob@77 7505 success,
rob@77 7506 error,
rob@77 7507 statusText = nativeStatusText,
rob@77 7508 response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
rob@77 7509 lastModified,
rob@77 7510 etag;
rob@77 7511
rob@77 7512 // If successful, handle type chaining
rob@77 7513 if ( status >= 200 && status < 300 || status === 304 ) {
rob@77 7514
rob@77 7515 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
rob@77 7516 if ( s.ifModified ) {
rob@77 7517
rob@77 7518 if ( ( lastModified = jqXHR.getResponseHeader( "Last-Modified" ) ) ) {
rob@77 7519 jQuery.lastModified[ ifModifiedKey ] = lastModified;
rob@77 7520 }
rob@77 7521 if ( ( etag = jqXHR.getResponseHeader( "Etag" ) ) ) {
rob@77 7522 jQuery.etag[ ifModifiedKey ] = etag;
rob@77 7523 }
rob@77 7524 }
rob@77 7525
rob@77 7526 // If not modified
rob@77 7527 if ( status === 304 ) {
rob@77 7528
rob@77 7529 statusText = "notmodified";
rob@77 7530 isSuccess = true;
rob@77 7531
rob@77 7532 // If we have data
rob@77 7533 } else {
rob@77 7534
rob@77 7535 try {
rob@77 7536 success = ajaxConvert( s, response );
rob@77 7537 statusText = "success";
rob@77 7538 isSuccess = true;
rob@77 7539 } catch(e) {
rob@77 7540 // We have a parsererror
rob@77 7541 statusText = "parsererror";
rob@77 7542 error = e;
rob@77 7543 }
rob@77 7544 }
rob@77 7545 } else {
rob@77 7546 // We extract error from statusText
rob@77 7547 // then normalize statusText and status for non-aborts
rob@77 7548 error = statusText;
rob@77 7549 if ( !statusText || status ) {
rob@77 7550 statusText = "error";
rob@77 7551 if ( status < 0 ) {
rob@77 7552 status = 0;
rob@77 7553 }
rob@77 7554 }
rob@77 7555 }
rob@77 7556
rob@77 7557 // Set data for the fake xhr object
rob@77 7558 jqXHR.status = status;
rob@77 7559 jqXHR.statusText = "" + ( nativeStatusText || statusText );
rob@77 7560
rob@77 7561 // Success/Error
rob@77 7562 if ( isSuccess ) {
rob@77 7563 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
rob@77 7564 } else {
rob@77 7565 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
rob@77 7566 }
rob@77 7567
rob@77 7568 // Status-dependent callbacks
rob@77 7569 jqXHR.statusCode( statusCode );
rob@77 7570 statusCode = undefined;
rob@77 7571
rob@77 7572 if ( fireGlobals ) {
rob@77 7573 globalEventContext.trigger( "ajax" + ( isSuccess ? "Success" : "Error" ),
rob@77 7574 [ jqXHR, s, isSuccess ? success : error ] );
rob@77 7575 }
rob@77 7576
rob@77 7577 // Complete
rob@77 7578 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
rob@77 7579
rob@77 7580 if ( fireGlobals ) {
rob@77 7581 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
rob@77 7582 // Handle the global AJAX counter
rob@77 7583 if ( !( --jQuery.active ) ) {
rob@77 7584 jQuery.event.trigger( "ajaxStop" );
rob@77 7585 }
rob@77 7586 }
rob@77 7587 }
rob@77 7588
rob@77 7589 // Attach deferreds
rob@77 7590 deferred.promise( jqXHR );
rob@77 7591 jqXHR.success = jqXHR.done;
rob@77 7592 jqXHR.error = jqXHR.fail;
rob@77 7593 jqXHR.complete = completeDeferred.add;
rob@77 7594
rob@77 7595 // Status-dependent callbacks
rob@77 7596 jqXHR.statusCode = function( map ) {
rob@77 7597 if ( map ) {
rob@77 7598 var tmp;
rob@77 7599 if ( state < 2 ) {
rob@77 7600 for ( tmp in map ) {
rob@77 7601 statusCode[ tmp ] = [ statusCode[tmp], map[tmp] ];
rob@77 7602 }
rob@77 7603 } else {
rob@77 7604 tmp = map[ jqXHR.status ];
rob@77 7605 jqXHR.then( tmp, tmp );
rob@77 7606 }
rob@77 7607 }
rob@77 7608 return this;
rob@77 7609 };
rob@77 7610
rob@77 7611 // Remove hash character (#7531: and string promotion)
rob@77 7612 // Add protocol if not provided (#5866: IE7 issue with protocol-less urls)
rob@77 7613 // We also use the url parameter if available
rob@77 7614 s.url = ( ( url || s.url ) + "" ).replace( rhash, "" ).replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
rob@77 7615
rob@77 7616 // Extract dataTypes list
rob@77 7617 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().split( rspacesAjax );
rob@77 7618
rob@77 7619 // Determine if a cross-domain request is in order
rob@77 7620 if ( s.crossDomain == null ) {
rob@77 7621 parts = rurl.exec( s.url.toLowerCase() );
rob@77 7622 s.crossDomain = !!( parts &&
rob@77 7623 ( parts[ 1 ] != ajaxLocParts[ 1 ] || parts[ 2 ] != ajaxLocParts[ 2 ] ||
rob@77 7624 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? 80 : 443 ) ) !=
rob@77 7625 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? 80 : 443 ) ) )
rob@77 7626 );
rob@77 7627 }
rob@77 7628
rob@77 7629 // Convert data if not already a string
rob@77 7630 if ( s.data && s.processData && typeof s.data !== "string" ) {
rob@77 7631 s.data = jQuery.param( s.data, s.traditional );
rob@77 7632 }
rob@77 7633
rob@77 7634 // Apply prefilters
rob@77 7635 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
rob@77 7636
rob@77 7637 // If request was aborted inside a prefilter, stop there
rob@77 7638 if ( state === 2 ) {
rob@77 7639 return false;
rob@77 7640 }
rob@77 7641
rob@77 7642 // We can fire global events as of now if asked to
rob@77 7643 fireGlobals = s.global;
rob@77 7644
rob@77 7645 // Uppercase the type
rob@77 7646 s.type = s.type.toUpperCase();
rob@77 7647
rob@77 7648 // Determine if request has content
rob@77 7649 s.hasContent = !rnoContent.test( s.type );
rob@77 7650
rob@77 7651 // Watch for a new set of requests
rob@77 7652 if ( fireGlobals && jQuery.active++ === 0 ) {
rob@77 7653 jQuery.event.trigger( "ajaxStart" );
rob@77 7654 }
rob@77 7655
rob@77 7656 // More options handling for requests with no content
rob@77 7657 if ( !s.hasContent ) {
rob@77 7658
rob@77 7659 // If data is available, append data to url
rob@77 7660 if ( s.data ) {
rob@77 7661 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.data;
rob@77 7662 // #9682: remove data so that it's not used in an eventual retry
rob@77 7663 delete s.data;
rob@77 7664 }
rob@77 7665
rob@77 7666 // Get ifModifiedKey before adding the anti-cache parameter
rob@77 7667 ifModifiedKey = s.url;
rob@77 7668
rob@77 7669 // Add anti-cache in url if needed
rob@77 7670 if ( s.cache === false ) {
rob@77 7671
rob@77 7672 var ts = jQuery.now(),
rob@77 7673 // try replacing _= if it is there
rob@77 7674 ret = s.url.replace( rts, "$1_=" + ts );
rob@77 7675
rob@77 7676 // if nothing was replaced, add timestamp to the end
rob@77 7677 s.url = ret + ( ( ret === s.url ) ? ( rquery.test( s.url ) ? "&" : "?" ) + "_=" + ts : "" );
rob@77 7678 }
rob@77 7679 }
rob@77 7680
rob@77 7681 // Set the correct header, if data is being sent
rob@77 7682 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
rob@77 7683 jqXHR.setRequestHeader( "Content-Type", s.contentType );
rob@77 7684 }
rob@77 7685
rob@77 7686 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
rob@77 7687 if ( s.ifModified ) {
rob@77 7688 ifModifiedKey = ifModifiedKey || s.url;
rob@77 7689 if ( jQuery.lastModified[ ifModifiedKey ] ) {
rob@77 7690 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ ifModifiedKey ] );
rob@77 7691 }
rob@77 7692 if ( jQuery.etag[ ifModifiedKey ] ) {
rob@77 7693 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ ifModifiedKey ] );
rob@77 7694 }
rob@77 7695 }
rob@77 7696
rob@77 7697 // Set the Accepts header for the server, depending on the dataType
rob@77 7698 jqXHR.setRequestHeader(
rob@77 7699 "Accept",
rob@77 7700 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
rob@77 7701 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
rob@77 7702 s.accepts[ "*" ]
rob@77 7703 );
rob@77 7704
rob@77 7705 // Check for headers option
rob@77 7706 for ( i in s.headers ) {
rob@77 7707 jqXHR.setRequestHeader( i, s.headers[ i ] );
rob@77 7708 }
rob@77 7709
rob@77 7710 // Allow custom headers/mimetypes and early abort
rob@77 7711 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
rob@77 7712 // Abort if not done already
rob@77 7713 jqXHR.abort();
rob@77 7714 return false;
rob@77 7715
rob@77 7716 }
rob@77 7717
rob@77 7718 // Install callbacks on deferreds
rob@77 7719 for ( i in { success: 1, error: 1, complete: 1 } ) {
rob@77 7720 jqXHR[ i ]( s[ i ] );
rob@77 7721 }
rob@77 7722
rob@77 7723 // Get transport
rob@77 7724 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
rob@77 7725
rob@77 7726 // If no transport, we auto-abort
rob@77 7727 if ( !transport ) {
rob@77 7728 done( -1, "No Transport" );
rob@77 7729 } else {
rob@77 7730 jqXHR.readyState = 1;
rob@77 7731 // Send global event
rob@77 7732 if ( fireGlobals ) {
rob@77 7733 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
rob@77 7734 }
rob@77 7735 // Timeout
rob@77 7736 if ( s.async && s.timeout > 0 ) {
rob@77 7737 timeoutTimer = setTimeout( function(){
rob@77 7738 jqXHR.abort( "timeout" );
rob@77 7739 }, s.timeout );
rob@77 7740 }
rob@77 7741
rob@77 7742 try {
rob@77 7743 state = 1;
rob@77 7744 transport.send( requestHeaders, done );
rob@77 7745 } catch (e) {
rob@77 7746 // Propagate exception as error if not done
rob@77 7747 if ( state < 2 ) {
rob@77 7748 done( -1, e );
rob@77 7749 // Simply rethrow otherwise
rob@77 7750 } else {
rob@77 7751 throw e;
rob@77 7752 }
rob@77 7753 }
rob@77 7754 }
rob@77 7755
rob@77 7756 return jqXHR;
rob@77 7757 },
rob@77 7758
rob@77 7759 // Serialize an array of form elements or a set of
rob@77 7760 // key/values into a query string
rob@77 7761 param: function( a, traditional ) {
rob@77 7762 var s = [],
rob@77 7763 add = function( key, value ) {
rob@77 7764 // If value is a function, invoke it and return its value
rob@77 7765 value = jQuery.isFunction( value ) ? value() : value;
rob@77 7766 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
rob@77 7767 };
rob@77 7768
rob@77 7769 // Set traditional to true for jQuery <= 1.3.2 behavior.
rob@77 7770 if ( traditional === undefined ) {
rob@77 7771 traditional = jQuery.ajaxSettings.traditional;
rob@77 7772 }
rob@77 7773
rob@77 7774 // If an array was passed in, assume that it is an array of form elements.
rob@77 7775 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
rob@77 7776 // Serialize the form elements
rob@77 7777 jQuery.each( a, function() {
rob@77 7778 add( this.name, this.value );
rob@77 7779 });
rob@77 7780
rob@77 7781 } else {
rob@77 7782 // If traditional, encode the "old" way (the way 1.3.2 or older
rob@77 7783 // did it), otherwise encode params recursively.
rob@77 7784 for ( var prefix in a ) {
rob@77 7785 buildParams( prefix, a[ prefix ], traditional, add );
rob@77 7786 }
rob@77 7787 }
rob@77 7788
rob@77 7789 // Return the resulting serialization
rob@77 7790 return s.join( "&" ).replace( r20, "+" );
rob@77 7791 }
rob@77 7792 });
rob@77 7793
rob@77 7794 function buildParams( prefix, obj, traditional, add ) {
rob@77 7795 if ( jQuery.isArray( obj ) ) {
rob@77 7796 // Serialize array item.
rob@77 7797 jQuery.each( obj, function( i, v ) {
rob@77 7798 if ( traditional || rbracket.test( prefix ) ) {
rob@77 7799 // Treat each array item as a scalar.
rob@77 7800 add( prefix, v );
rob@77 7801
rob@77 7802 } else {
rob@77 7803 // If array item is non-scalar (array or object), encode its
rob@77 7804 // numeric index to resolve deserialization ambiguity issues.
rob@77 7805 // Note that rack (as of 1.0.0) can't currently deserialize
rob@77 7806 // nested arrays properly, and attempting to do so may cause
rob@77 7807 // a server error. Possible fixes are to modify rack's
rob@77 7808 // deserialization algorithm or to provide an option or flag
rob@77 7809 // to force array serialization to be shallow.
rob@77 7810 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
rob@77 7811 }
rob@77 7812 });
rob@77 7813
rob@77 7814 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
rob@77 7815 // Serialize object item.
rob@77 7816 for ( var name in obj ) {
rob@77 7817 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
rob@77 7818 }
rob@77 7819
rob@77 7820 } else {
rob@77 7821 // Serialize scalar item.
rob@77 7822 add( prefix, obj );
rob@77 7823 }
rob@77 7824 }
rob@77 7825
rob@77 7826 // This is still on the jQuery object... for now
rob@77 7827 // Want to move this to jQuery.ajax some day
rob@77 7828 jQuery.extend({
rob@77 7829
rob@77 7830 // Counter for holding the number of active queries
rob@77 7831 active: 0,
rob@77 7832
rob@77 7833 // Last-Modified header cache for next request
rob@77 7834 lastModified: {},
rob@77 7835 etag: {}
rob@77 7836
rob@77 7837 });
rob@77 7838
rob@77 7839 /* Handles responses to an ajax request:
rob@77 7840 * - sets all responseXXX fields accordingly
rob@77 7841 * - finds the right dataType (mediates between content-type and expected dataType)
rob@77 7842 * - returns the corresponding response
rob@77 7843 */
rob@77 7844 function ajaxHandleResponses( s, jqXHR, responses ) {
rob@77 7845
rob@77 7846 var contents = s.contents,
rob@77 7847 dataTypes = s.dataTypes,
rob@77 7848 responseFields = s.responseFields,
rob@77 7849 ct,
rob@77 7850 type,
rob@77 7851 finalDataType,
rob@77 7852 firstDataType;
rob@77 7853
rob@77 7854 // Fill responseXXX fields
rob@77 7855 for ( type in responseFields ) {
rob@77 7856 if ( type in responses ) {
rob@77 7857 jqXHR[ responseFields[type] ] = responses[ type ];
rob@77 7858 }
rob@77 7859 }
rob@77 7860
rob@77 7861 // Remove auto dataType and get content-type in the process
rob@77 7862 while( dataTypes[ 0 ] === "*" ) {
rob@77 7863 dataTypes.shift();
rob@77 7864 if ( ct === undefined ) {
rob@77 7865 ct = s.mimeType || jqXHR.getResponseHeader( "content-type" );
rob@77 7866 }
rob@77 7867 }
rob@77 7868
rob@77 7869 // Check if we're dealing with a known content-type
rob@77 7870 if ( ct ) {
rob@77 7871 for ( type in contents ) {
rob@77 7872 if ( contents[ type ] && contents[ type ].test( ct ) ) {
rob@77 7873 dataTypes.unshift( type );
rob@77 7874 break;
rob@77 7875 }
rob@77 7876 }
rob@77 7877 }
rob@77 7878
rob@77 7879 // Check to see if we have a response for the expected dataType
rob@77 7880 if ( dataTypes[ 0 ] in responses ) {
rob@77 7881 finalDataType = dataTypes[ 0 ];
rob@77 7882 } else {
rob@77 7883 // Try convertible dataTypes
rob@77 7884 for ( type in responses ) {
rob@77 7885 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
rob@77 7886 finalDataType = type;
rob@77 7887 break;
rob@77 7888 }
rob@77 7889 if ( !firstDataType ) {
rob@77 7890 firstDataType = type;
rob@77 7891 }
rob@77 7892 }
rob@77 7893 // Or just use first one
rob@77 7894 finalDataType = finalDataType || firstDataType;
rob@77 7895 }
rob@77 7896
rob@77 7897 // If we found a dataType
rob@77 7898 // We add the dataType to the list if needed
rob@77 7899 // and return the corresponding response
rob@77 7900 if ( finalDataType ) {
rob@77 7901 if ( finalDataType !== dataTypes[ 0 ] ) {
rob@77 7902 dataTypes.unshift( finalDataType );
rob@77 7903 }
rob@77 7904 return responses[ finalDataType ];
rob@77 7905 }
rob@77 7906 }
rob@77 7907
rob@77 7908 // Chain conversions given the request and the original response
rob@77 7909 function ajaxConvert( s, response ) {
rob@77 7910
rob@77 7911 // Apply the dataFilter if provided
rob@77 7912 if ( s.dataFilter ) {
rob@77 7913 response = s.dataFilter( response, s.dataType );
rob@77 7914 }
rob@77 7915
rob@77 7916 var dataTypes = s.dataTypes,
rob@77 7917 converters = {},
rob@77 7918 i,
rob@77 7919 key,
rob@77 7920 length = dataTypes.length,
rob@77 7921 tmp,
rob@77 7922 // Current and previous dataTypes
rob@77 7923 current = dataTypes[ 0 ],
rob@77 7924 prev,
rob@77 7925 // Conversion expression
rob@77 7926 conversion,
rob@77 7927 // Conversion function
rob@77 7928 conv,
rob@77 7929 // Conversion functions (transitive conversion)
rob@77 7930 conv1,
rob@77 7931 conv2;
rob@77 7932
rob@77 7933 // For each dataType in the chain
rob@77 7934 for ( i = 1; i < length; i++ ) {
rob@77 7935
rob@77 7936 // Create converters map
rob@77 7937 // with lowercased keys
rob@77 7938 if ( i === 1 ) {
rob@77 7939 for ( key in s.converters ) {
rob@77 7940 if ( typeof key === "string" ) {
rob@77 7941 converters[ key.toLowerCase() ] = s.converters[ key ];
rob@77 7942 }
rob@77 7943 }
rob@77 7944 }
rob@77 7945
rob@77 7946 // Get the dataTypes
rob@77 7947 prev = current;
rob@77 7948 current = dataTypes[ i ];
rob@77 7949
rob@77 7950 // If current is auto dataType, update it to prev
rob@77 7951 if ( current === "*" ) {
rob@77 7952 current = prev;
rob@77 7953 // If no auto and dataTypes are actually different
rob@77 7954 } else if ( prev !== "*" && prev !== current ) {
rob@77 7955
rob@77 7956 // Get the converter
rob@77 7957 conversion = prev + " " + current;
rob@77 7958 conv = converters[ conversion ] || converters[ "* " + current ];
rob@77 7959
rob@77 7960 // If there is no direct converter, search transitively
rob@77 7961 if ( !conv ) {
rob@77 7962 conv2 = undefined;
rob@77 7963 for ( conv1 in converters ) {
rob@77 7964 tmp = conv1.split( " " );
rob@77 7965 if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
rob@77 7966 conv2 = converters[ tmp[1] + " " + current ];
rob@77 7967 if ( conv2 ) {
rob@77 7968 conv1 = converters[ conv1 ];
rob@77 7969 if ( conv1 === true ) {
rob@77 7970 conv = conv2;
rob@77 7971 } else if ( conv2 === true ) {
rob@77 7972 conv = conv1;
rob@77 7973 }
rob@77 7974 break;
rob@77 7975 }
rob@77 7976 }
rob@77 7977 }
rob@77 7978 }
rob@77 7979 // If we found no converter, dispatch an error
rob@77 7980 if ( !( conv || conv2 ) ) {
rob@77 7981 jQuery.error( "No conversion from " + conversion.replace(" "," to ") );
rob@77 7982 }
rob@77 7983 // If found converter is not an equivalence
rob@77 7984 if ( conv !== true ) {
rob@77 7985 // Convert with 1 or 2 converters accordingly
rob@77 7986 response = conv ? conv( response ) : conv2( conv1(response) );
rob@77 7987 }
rob@77 7988 }
rob@77 7989 }
rob@77 7990 return response;
rob@77 7991 }
rob@77 7992
rob@77 7993
rob@77 7994
rob@77 7995
rob@77 7996 var jsc = jQuery.now(),
rob@77 7997 jsre = /(\=)\?(&|$)|\?\?/i;
rob@77 7998
rob@77 7999 // Default jsonp settings
rob@77 8000 jQuery.ajaxSetup({
rob@77 8001 jsonp: "callback",
rob@77 8002 jsonpCallback: function() {
rob@77 8003 return jQuery.expando + "_" + ( jsc++ );
rob@77 8004 }
rob@77 8005 });
rob@77 8006
rob@77 8007 // Detect, normalize options and install callbacks for jsonp requests
rob@77 8008 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
rob@77 8009
rob@77 8010 var inspectData = ( typeof s.data === "string" ) && /^application\/x\-www\-form\-urlencoded/.test( s.contentType );
rob@77 8011
rob@77 8012 if ( s.dataTypes[ 0 ] === "jsonp" ||
rob@77 8013 s.jsonp !== false && ( jsre.test( s.url ) ||
rob@77 8014 inspectData && jsre.test( s.data ) ) ) {
rob@77 8015
rob@77 8016 var responseContainer,
rob@77 8017 jsonpCallback = s.jsonpCallback =
rob@77 8018 jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
rob@77 8019 previous = window[ jsonpCallback ],
rob@77 8020 url = s.url,
rob@77 8021 data = s.data,
rob@77 8022 replace = "$1" + jsonpCallback + "$2";
rob@77 8023
rob@77 8024 if ( s.jsonp !== false ) {
rob@77 8025 url = url.replace( jsre, replace );
rob@77 8026 if ( s.url === url ) {
rob@77 8027 if ( inspectData ) {
rob@77 8028 data = data.replace( jsre, replace );
rob@77 8029 }
rob@77 8030 if ( s.data === data ) {
rob@77 8031 // Add callback manually
rob@77 8032 url += (/\?/.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
rob@77 8033 }
rob@77 8034 }
rob@77 8035 }
rob@77 8036
rob@77 8037 s.url = url;
rob@77 8038 s.data = data;
rob@77 8039
rob@77 8040 // Install callback
rob@77 8041 window[ jsonpCallback ] = function( response ) {
rob@77 8042 responseContainer = [ response ];
rob@77 8043 };
rob@77 8044
rob@77 8045 // Clean-up function
rob@77 8046 jqXHR.always(function() {
rob@77 8047 // Set callback back to previous value
rob@77 8048 window[ jsonpCallback ] = previous;
rob@77 8049 // Call if it was a function and we have a response
rob@77 8050 if ( responseContainer && jQuery.isFunction( previous ) ) {
rob@77 8051 window[ jsonpCallback ]( responseContainer[ 0 ] );
rob@77 8052 }
rob@77 8053 });
rob@77 8054
rob@77 8055 // Use data converter to retrieve json after script execution
rob@77 8056 s.converters["script json"] = function() {
rob@77 8057 if ( !responseContainer ) {
rob@77 8058 jQuery.error( jsonpCallback + " was not called" );
rob@77 8059 }
rob@77 8060 return responseContainer[ 0 ];
rob@77 8061 };
rob@77 8062
rob@77 8063 // force json dataType
rob@77 8064 s.dataTypes[ 0 ] = "json";
rob@77 8065
rob@77 8066 // Delegate to script
rob@77 8067 return "script";
rob@77 8068 }
rob@77 8069 });
rob@77 8070
rob@77 8071
rob@77 8072
rob@77 8073
rob@77 8074 // Install script dataType
rob@77 8075 jQuery.ajaxSetup({
rob@77 8076 accepts: {
rob@77 8077 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
rob@77 8078 },
rob@77 8079 contents: {
rob@77 8080 script: /javascript|ecmascript/
rob@77 8081 },
rob@77 8082 converters: {
rob@77 8083 "text script": function( text ) {
rob@77 8084 jQuery.globalEval( text );
rob@77 8085 return text;
rob@77 8086 }
rob@77 8087 }
rob@77 8088 });
rob@77 8089
rob@77 8090 // Handle cache's special case and global
rob@77 8091 jQuery.ajaxPrefilter( "script", function( s ) {
rob@77 8092 if ( s.cache === undefined ) {
rob@77 8093 s.cache = false;
rob@77 8094 }
rob@77 8095 if ( s.crossDomain ) {
rob@77 8096 s.type = "GET";
rob@77 8097 s.global = false;
rob@77 8098 }
rob@77 8099 });
rob@77 8100
rob@77 8101 // Bind script tag hack transport
rob@77 8102 jQuery.ajaxTransport( "script", function(s) {
rob@77 8103
rob@77 8104 // This transport only deals with cross domain requests
rob@77 8105 if ( s.crossDomain ) {
rob@77 8106
rob@77 8107 var script,
rob@77 8108 head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement;
rob@77 8109
rob@77 8110 return {
rob@77 8111
rob@77 8112 send: function( _, callback ) {
rob@77 8113
rob@77 8114 script = document.createElement( "script" );
rob@77 8115
rob@77 8116 script.async = "async";
rob@77 8117
rob@77 8118 if ( s.scriptCharset ) {
rob@77 8119 script.charset = s.scriptCharset;
rob@77 8120 }
rob@77 8121
rob@77 8122 script.src = s.url;
rob@77 8123
rob@77 8124 // Attach handlers for all browsers
rob@77 8125 script.onload = script.onreadystatechange = function( _, isAbort ) {
rob@77 8126
rob@77 8127 if ( isAbort || !script.readyState || /loaded|complete/.test( script.readyState ) ) {
rob@77 8128
rob@77 8129 // Handle memory leak in IE
rob@77 8130 script.onload = script.onreadystatechange = null;
rob@77 8131
rob@77 8132 // Remove the script
rob@77 8133 if ( head && script.parentNode ) {
rob@77 8134 head.removeChild( script );
rob@77 8135 }
rob@77 8136
rob@77 8137 // Dereference the script
rob@77 8138 script = undefined;
rob@77 8139
rob@77 8140 // Callback if not abort
rob@77 8141 if ( !isAbort ) {
rob@77 8142 callback( 200, "success" );
rob@77 8143 }
rob@77 8144 }
rob@77 8145 };
rob@77 8146 // Use insertBefore instead of appendChild to circumvent an IE6 bug.
rob@77 8147 // This arises when a base node is used (#2709 and #4378).
rob@77 8148 head.insertBefore( script, head.firstChild );
rob@77 8149 },
rob@77 8150
rob@77 8151 abort: function() {
rob@77 8152 if ( script ) {
rob@77 8153 script.onload( 0, 1 );
rob@77 8154 }
rob@77 8155 }
rob@77 8156 };
rob@77 8157 }
rob@77 8158 });
rob@77 8159
rob@77 8160
rob@77 8161
rob@77 8162
rob@77 8163 var // #5280: Internet Explorer will keep connections alive if we don't abort on unload
rob@77 8164 xhrOnUnloadAbort = window.ActiveXObject ? function() {
rob@77 8165 // Abort all pending requests
rob@77 8166 for ( var key in xhrCallbacks ) {
rob@77 8167 xhrCallbacks[ key ]( 0, 1 );
rob@77 8168 }
rob@77 8169 } : false,
rob@77 8170 xhrId = 0,
rob@77 8171 xhrCallbacks;
rob@77 8172
rob@77 8173 // Functions to create xhrs
rob@77 8174 function createStandardXHR() {
rob@77 8175 try {
rob@77 8176 return new window.XMLHttpRequest();
rob@77 8177 } catch( e ) {}
rob@77 8178 }
rob@77 8179
rob@77 8180 function createActiveXHR() {
rob@77 8181 try {
rob@77 8182 return new window.ActiveXObject( "Microsoft.XMLHTTP" );
rob@77 8183 } catch( e ) {}
rob@77 8184 }
rob@77 8185
rob@77 8186 // Create the request object
rob@77 8187 // (This is still attached to ajaxSettings for backward compatibility)
rob@77 8188 jQuery.ajaxSettings.xhr = window.ActiveXObject ?
rob@77 8189 /* Microsoft failed to properly
rob@77 8190 * implement the XMLHttpRequest in IE7 (can't request local files),
rob@77 8191 * so we use the ActiveXObject when it is available
rob@77 8192 * Additionally XMLHttpRequest can be disabled in IE7/IE8 so
rob@77 8193 * we need a fallback.
rob@77 8194 */
rob@77 8195 function() {
rob@77 8196 return !this.isLocal && createStandardXHR() || createActiveXHR();
rob@77 8197 } :
rob@77 8198 // For all other browsers, use the standard XMLHttpRequest object
rob@77 8199 createStandardXHR;
rob@77 8200
rob@77 8201 // Determine support properties
rob@77 8202 (function( xhr ) {
rob@77 8203 jQuery.extend( jQuery.support, {
rob@77 8204 ajax: !!xhr,
rob@77 8205 cors: !!xhr && ( "withCredentials" in xhr )
rob@77 8206 });
rob@77 8207 })( jQuery.ajaxSettings.xhr() );
rob@77 8208
rob@77 8209 // Create transport if the browser can provide an xhr
rob@77 8210 if ( jQuery.support.ajax ) {
rob@77 8211
rob@77 8212 jQuery.ajaxTransport(function( s ) {
rob@77 8213 // Cross domain only allowed if supported through XMLHttpRequest
rob@77 8214 if ( !s.crossDomain || jQuery.support.cors ) {
rob@77 8215
rob@77 8216 var callback;
rob@77 8217
rob@77 8218 return {
rob@77 8219 send: function( headers, complete ) {
rob@77 8220
rob@77 8221 // Get a new xhr
rob@77 8222 var xhr = s.xhr(),
rob@77 8223 handle,
rob@77 8224 i;
rob@77 8225
rob@77 8226 // Open the socket
rob@77 8227 // Passing null username, generates a login popup on Opera (#2865)
rob@77 8228 if ( s.username ) {
rob@77 8229 xhr.open( s.type, s.url, s.async, s.username, s.password );
rob@77 8230 } else {
rob@77 8231 xhr.open( s.type, s.url, s.async );
rob@77 8232 }
rob@77 8233
rob@77 8234 // Apply custom fields if provided
rob@77 8235 if ( s.xhrFields ) {
rob@77 8236 for ( i in s.xhrFields ) {
rob@77 8237 xhr[ i ] = s.xhrFields[ i ];
rob@77 8238 }
rob@77 8239 }
rob@77 8240
rob@77 8241 // Override mime type if needed
rob@77 8242 if ( s.mimeType && xhr.overrideMimeType ) {
rob@77 8243 xhr.overrideMimeType( s.mimeType );
rob@77 8244 }
rob@77 8245
rob@77 8246 // X-Requested-With header
rob@77 8247 // For cross-domain requests, seeing as conditions for a preflight are
rob@77 8248 // akin to a jigsaw puzzle, we simply never set it to be sure.
rob@77 8249 // (it can always be set on a per-request basis or even using ajaxSetup)
rob@77 8250 // For same-domain requests, won't change header if already provided.
rob@77 8251 if ( !s.crossDomain && !headers["X-Requested-With"] ) {
rob@77 8252 headers[ "X-Requested-With" ] = "XMLHttpRequest";
rob@77 8253 }
rob@77 8254
rob@77 8255 // Need an extra try/catch for cross domain requests in Firefox 3
rob@77 8256 try {
rob@77 8257 for ( i in headers ) {
rob@77 8258 xhr.setRequestHeader( i, headers[ i ] );
rob@77 8259 }
rob@77 8260 } catch( _ ) {}
rob@77 8261
rob@77 8262 // Do send the request
rob@77 8263 // This may raise an exception which is actually
rob@77 8264 // handled in jQuery.ajax (so no try/catch here)
rob@77 8265 xhr.send( ( s.hasContent && s.data ) || null );
rob@77 8266
rob@77 8267 // Listener
rob@77 8268 callback = function( _, isAbort ) {
rob@77 8269
rob@77 8270 var status,
rob@77 8271 statusText,
rob@77 8272 responseHeaders,
rob@77 8273 responses,
rob@77 8274 xml;
rob@77 8275
rob@77 8276 // Firefox throws exceptions when accessing properties
rob@77 8277 // of an xhr when a network error occured
rob@77 8278 // http://helpful.knobs-dials.com/index.php/Component_returned_failure_code:_0x80040111_(NS_ERROR_NOT_AVAILABLE)
rob@77 8279 try {
rob@77 8280
rob@77 8281 // Was never called and is aborted or complete
rob@77 8282 if ( callback && ( isAbort || xhr.readyState === 4 ) ) {
rob@77 8283
rob@77 8284 // Only called once
rob@77 8285 callback = undefined;
rob@77 8286
rob@77 8287 // Do not keep as active anymore
rob@77 8288 if ( handle ) {
rob@77 8289 xhr.onreadystatechange = jQuery.noop;
rob@77 8290 if ( xhrOnUnloadAbort ) {
rob@77 8291 delete xhrCallbacks[ handle ];
rob@77 8292 }
rob@77 8293 }
rob@77 8294
rob@77 8295 // If it's an abort
rob@77 8296 if ( isAbort ) {
rob@77 8297 // Abort it manually if needed
rob@77 8298 if ( xhr.readyState !== 4 ) {
rob@77 8299 xhr.abort();
rob@77 8300 }
rob@77 8301 } else {
rob@77 8302 status = xhr.status;
rob@77 8303 responseHeaders = xhr.getAllResponseHeaders();
rob@77 8304 responses = {};
rob@77 8305 xml = xhr.responseXML;
rob@77 8306
rob@77 8307 // Construct response list
rob@77 8308 if ( xml && xml.documentElement /* #4958 */ ) {
rob@77 8309 responses.xml = xml;
rob@77 8310 }
rob@77 8311
rob@77 8312 // When requesting binary data, IE6-9 will throw an exception
rob@77 8313 // on any attempt to access responseText (#11426)
rob@77 8314 try {
rob@77 8315 responses.text = xhr.responseText;
rob@77 8316 } catch( _ ) {
rob@77 8317 }
rob@77 8318
rob@77 8319 // Firefox throws an exception when accessing
rob@77 8320 // statusText for faulty cross-domain requests
rob@77 8321 try {
rob@77 8322 statusText = xhr.statusText;
rob@77 8323 } catch( e ) {
rob@77 8324 // We normalize with Webkit giving an empty statusText
rob@77 8325 statusText = "";
rob@77 8326 }
rob@77 8327
rob@77 8328 // Filter status for non standard behaviors
rob@77 8329
rob@77 8330 // If the request is local and we have data: assume a success
rob@77 8331 // (success with no data won't get notified, that's the best we
rob@77 8332 // can do given current implementations)
rob@77 8333 if ( !status && s.isLocal && !s.crossDomain ) {
rob@77 8334 status = responses.text ? 200 : 404;
rob@77 8335 // IE - #1450: sometimes returns 1223 when it should be 204
rob@77 8336 } else if ( status === 1223 ) {
rob@77 8337 status = 204;
rob@77 8338 }
rob@77 8339 }
rob@77 8340 }
rob@77 8341 } catch( firefoxAccessException ) {
rob@77 8342 if ( !isAbort ) {
rob@77 8343 complete( -1, firefoxAccessException );
rob@77 8344 }
rob@77 8345 }
rob@77 8346
rob@77 8347 // Call complete if needed
rob@77 8348 if ( responses ) {
rob@77 8349 complete( status, statusText, responses, responseHeaders );
rob@77 8350 }
rob@77 8351 };
rob@77 8352
rob@77 8353 // if we're in sync mode or it's in cache
rob@77 8354 // and has been retrieved directly (IE6 & IE7)
rob@77 8355 // we need to manually fire the callback
rob@77 8356 if ( !s.async || xhr.readyState === 4 ) {
rob@77 8357 callback();
rob@77 8358 } else {
rob@77 8359 handle = ++xhrId;
rob@77 8360 if ( xhrOnUnloadAbort ) {
rob@77 8361 // Create the active xhrs callbacks list if needed
rob@77 8362 // and attach the unload handler
rob@77 8363 if ( !xhrCallbacks ) {
rob@77 8364 xhrCallbacks = {};
rob@77 8365 jQuery( window ).unload( xhrOnUnloadAbort );
rob@77 8366 }
rob@77 8367 // Add to list of active xhrs callbacks
rob@77 8368 xhrCallbacks[ handle ] = callback;
rob@77 8369 }
rob@77 8370 xhr.onreadystatechange = callback;
rob@77 8371 }
rob@77 8372 },
rob@77 8373
rob@77 8374 abort: function() {
rob@77 8375 if ( callback ) {
rob@77 8376 callback(0,1);
rob@77 8377 }
rob@77 8378 }
rob@77 8379 };
rob@77 8380 }
rob@77 8381 });
rob@77 8382 }
rob@77 8383
rob@77 8384
rob@77 8385
rob@77 8386
rob@77 8387 var elemdisplay = {},
rob@77 8388 iframe, iframeDoc,
rob@77 8389 rfxtypes = /^(?:toggle|show|hide)$/,
rob@77 8390 rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
rob@77 8391 timerId,
rob@77 8392 fxAttrs = [
rob@77 8393 // height animations
rob@77 8394 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
rob@77 8395 // width animations
rob@77 8396 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
rob@77 8397 // opacity animations
rob@77 8398 [ "opacity" ]
rob@77 8399 ],
rob@77 8400 fxNow;
rob@77 8401
rob@77 8402 jQuery.fn.extend({
rob@77 8403 show: function( speed, easing, callback ) {
rob@77 8404 var elem, display;
rob@77 8405
rob@77 8406 if ( speed || speed === 0 ) {
rob@77 8407 return this.animate( genFx("show", 3), speed, easing, callback );
rob@77 8408
rob@77 8409 } else {
rob@77 8410 for ( var i = 0, j = this.length; i < j; i++ ) {
rob@77 8411 elem = this[ i ];
rob@77 8412
rob@77 8413 if ( elem.style ) {
rob@77 8414 display = elem.style.display;
rob@77 8415
rob@77 8416 // Reset the inline display of this element to learn if it is
rob@77 8417 // being hidden by cascaded rules or not
rob@77 8418 if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
rob@77 8419 display = elem.style.display = "";
rob@77 8420 }
rob@77 8421
rob@77 8422 // Set elements which have been overridden with display: none
rob@77 8423 // in a stylesheet to whatever the default browser style is
rob@77 8424 // for such an element
rob@77 8425 if ( (display === "" && jQuery.css(elem, "display") === "none") ||
rob@77 8426 !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
rob@77 8427 jQuery._data( elem, "olddisplay", defaultDisplay(elem.nodeName) );
rob@77 8428 }
rob@77 8429 }
rob@77 8430 }
rob@77 8431
rob@77 8432 // Set the display of most of the elements in a second loop
rob@77 8433 // to avoid the constant reflow
rob@77 8434 for ( i = 0; i < j; i++ ) {
rob@77 8435 elem = this[ i ];
rob@77 8436
rob@77 8437 if ( elem.style ) {
rob@77 8438 display = elem.style.display;
rob@77 8439
rob@77 8440 if ( display === "" || display === "none" ) {
rob@77 8441 elem.style.display = jQuery._data( elem, "olddisplay" ) || "";
rob@77 8442 }
rob@77 8443 }
rob@77 8444 }
rob@77 8445
rob@77 8446 return this;
rob@77 8447 }
rob@77 8448 },
rob@77 8449
rob@77 8450 hide: function( speed, easing, callback ) {
rob@77 8451 if ( speed || speed === 0 ) {
rob@77 8452 return this.animate( genFx("hide", 3), speed, easing, callback);
rob@77 8453
rob@77 8454 } else {
rob@77 8455 var elem, display,
rob@77 8456 i = 0,
rob@77 8457 j = this.length;
rob@77 8458
rob@77 8459 for ( ; i < j; i++ ) {
rob@77 8460 elem = this[i];
rob@77 8461 if ( elem.style ) {
rob@77 8462 display = jQuery.css( elem, "display" );
rob@77 8463
rob@77 8464 if ( display !== "none" && !jQuery._data( elem, "olddisplay" ) ) {
rob@77 8465 jQuery._data( elem, "olddisplay", display );
rob@77 8466 }
rob@77 8467 }
rob@77 8468 }
rob@77 8469
rob@77 8470 // Set the display of the elements in a second loop
rob@77 8471 // to avoid the constant reflow
rob@77 8472 for ( i = 0; i < j; i++ ) {
rob@77 8473 if ( this[i].style ) {
rob@77 8474 this[i].style.display = "none";
rob@77 8475 }
rob@77 8476 }
rob@77 8477
rob@77 8478 return this;
rob@77 8479 }
rob@77 8480 },
rob@77 8481
rob@77 8482 // Save the old toggle function
rob@77 8483 _toggle: jQuery.fn.toggle,
rob@77 8484
rob@77 8485 toggle: function( fn, fn2, callback ) {
rob@77 8486 var bool = typeof fn === "boolean";
rob@77 8487
rob@77 8488 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
rob@77 8489 this._toggle.apply( this, arguments );
rob@77 8490
rob@77 8491 } else if ( fn == null || bool ) {
rob@77 8492 this.each(function() {
rob@77 8493 var state = bool ? fn : jQuery(this).is(":hidden");
rob@77 8494 jQuery(this)[ state ? "show" : "hide" ]();
rob@77 8495 });
rob@77 8496
rob@77 8497 } else {
rob@77 8498 this.animate(genFx("toggle", 3), fn, fn2, callback);
rob@77 8499 }
rob@77 8500
rob@77 8501 return this;
rob@77 8502 },
rob@77 8503
rob@77 8504 fadeTo: function( speed, to, easing, callback ) {
rob@77 8505 return this.filter(":hidden").css("opacity", 0).show().end()
rob@77 8506 .animate({opacity: to}, speed, easing, callback);
rob@77 8507 },
rob@77 8508
rob@77 8509 animate: function( prop, speed, easing, callback ) {
rob@77 8510 var optall = jQuery.speed( speed, easing, callback );
rob@77 8511
rob@77 8512 if ( jQuery.isEmptyObject( prop ) ) {
rob@77 8513 return this.each( optall.complete, [ false ] );
rob@77 8514 }
rob@77 8515
rob@77 8516 // Do not change referenced properties as per-property easing will be lost
rob@77 8517 prop = jQuery.extend( {}, prop );
rob@77 8518
rob@77 8519 function doAnimation() {
rob@77 8520 // XXX 'this' does not always have a nodeName when running the
rob@77 8521 // test suite
rob@77 8522
rob@77 8523 if ( optall.queue === false ) {
rob@77 8524 jQuery._mark( this );
rob@77 8525 }
rob@77 8526
rob@77 8527 var opt = jQuery.extend( {}, optall ),
rob@77 8528 isElement = this.nodeType === 1,
rob@77 8529 hidden = isElement && jQuery(this).is(":hidden"),
rob@77 8530 name, val, p, e, hooks, replace,
rob@77 8531 parts, start, end, unit,
rob@77 8532 method;
rob@77 8533
rob@77 8534 // will store per property easing and be used to determine when an animation is complete
rob@77 8535 opt.animatedProperties = {};
rob@77 8536
rob@77 8537 // first pass over propertys to expand / normalize
rob@77 8538 for ( p in prop ) {
rob@77 8539 name = jQuery.camelCase( p );
rob@77 8540 if ( p !== name ) {
rob@77 8541 prop[ name ] = prop[ p ];
rob@77 8542 delete prop[ p ];
rob@77 8543 }
rob@77 8544
rob@77 8545 if ( ( hooks = jQuery.cssHooks[ name ] ) && "expand" in hooks ) {
rob@77 8546 replace = hooks.expand( prop[ name ] );
rob@77 8547 delete prop[ name ];
rob@77 8548
rob@77 8549 // not quite $.extend, this wont overwrite keys already present.
rob@77 8550 // also - reusing 'p' from above because we have the correct "name"
rob@77 8551 for ( p in replace ) {
rob@77 8552 if ( ! ( p in prop ) ) {
rob@77 8553 prop[ p ] = replace[ p ];
rob@77 8554 }
rob@77 8555 }
rob@77 8556 }
rob@77 8557 }
rob@77 8558
rob@77 8559 for ( name in prop ) {
rob@77 8560 val = prop[ name ];
rob@77 8561 // easing resolution: per property > opt.specialEasing > opt.easing > 'swing' (default)
rob@77 8562 if ( jQuery.isArray( val ) ) {
rob@77 8563 opt.animatedProperties[ name ] = val[ 1 ];
rob@77 8564 val = prop[ name ] = val[ 0 ];
rob@77 8565 } else {
rob@77 8566 opt.animatedProperties[ name ] = opt.specialEasing && opt.specialEasing[ name ] || opt.easing || 'swing';
rob@77 8567 }
rob@77 8568
rob@77 8569 if ( val === "hide" && hidden || val === "show" && !hidden ) {
rob@77 8570 return opt.complete.call( this );
rob@77 8571 }
rob@77 8572
rob@77 8573 if ( isElement && ( name === "height" || name === "width" ) ) {
rob@77 8574 // Make sure that nothing sneaks out
rob@77 8575 // Record all 3 overflow attributes because IE does not
rob@77 8576 // change the overflow attribute when overflowX and
rob@77 8577 // overflowY are set to the same value
rob@77 8578 opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
rob@77 8579
rob@77 8580 // Set display property to inline-block for height/width
rob@77 8581 // animations on inline elements that are having width/height animated
rob@77 8582 if ( jQuery.css( this, "display" ) === "inline" &&
rob@77 8583 jQuery.css( this, "float" ) === "none" ) {
rob@77 8584
rob@77 8585 // inline-level elements accept inline-block;
rob@77 8586 // block-level elements need to be inline with layout
rob@77 8587 if ( !jQuery.support.inlineBlockNeedsLayout || defaultDisplay( this.nodeName ) === "inline" ) {
rob@77 8588 this.style.display = "inline-block";
rob@77 8589
rob@77 8590 } else {
rob@77 8591 this.style.zoom = 1;
rob@77 8592 }
rob@77 8593 }
rob@77 8594 }
rob@77 8595 }
rob@77 8596
rob@77 8597 if ( opt.overflow != null ) {
rob@77 8598 this.style.overflow = "hidden";
rob@77 8599 }
rob@77 8600
rob@77 8601 for ( p in prop ) {
rob@77 8602 e = new jQuery.fx( this, opt, p );
rob@77 8603 val = prop[ p ];
rob@77 8604
rob@77 8605 if ( rfxtypes.test( val ) ) {
rob@77 8606
rob@77 8607 // Tracks whether to show or hide based on private
rob@77 8608 // data attached to the element
rob@77 8609 method = jQuery._data( this, "toggle" + p ) || ( val === "toggle" ? hidden ? "show" : "hide" : 0 );
rob@77 8610 if ( method ) {
rob@77 8611 jQuery._data( this, "toggle" + p, method === "show" ? "hide" : "show" );
rob@77 8612 e[ method ]();
rob@77 8613 } else {
rob@77 8614 e[ val ]();
rob@77 8615 }
rob@77 8616
rob@77 8617 } else {
rob@77 8618 parts = rfxnum.exec( val );
rob@77 8619 start = e.cur();
rob@77 8620
rob@77 8621 if ( parts ) {
rob@77 8622 end = parseFloat( parts[2] );
rob@77 8623 unit = parts[3] || ( jQuery.cssNumber[ p ] ? "" : "px" );
rob@77 8624
rob@77 8625 // We need to compute starting value
rob@77 8626 if ( unit !== "px" ) {
rob@77 8627 jQuery.style( this, p, (end || 1) + unit);
rob@77 8628 start = ( (end || 1) / e.cur() ) * start;
rob@77 8629 jQuery.style( this, p, start + unit);
rob@77 8630 }
rob@77 8631
rob@77 8632 // If a +=/-= token was provided, we're doing a relative animation
rob@77 8633 if ( parts[1] ) {
rob@77 8634 end = ( (parts[ 1 ] === "-=" ? -1 : 1) * end ) + start;
rob@77 8635 }
rob@77 8636
rob@77 8637 e.custom( start, end, unit );
rob@77 8638
rob@77 8639 } else {
rob@77 8640 e.custom( start, val, "" );
rob@77 8641 }
rob@77 8642 }
rob@77 8643 }
rob@77 8644
rob@77 8645 // For JS strict compliance
rob@77 8646 return true;
rob@77 8647 }
rob@77 8648
rob@77 8649 return optall.queue === false ?
rob@77 8650 this.each( doAnimation ) :
rob@77 8651 this.queue( optall.queue, doAnimation );
rob@77 8652 },
rob@77 8653
rob@77 8654 stop: function( type, clearQueue, gotoEnd ) {
rob@77 8655 if ( typeof type !== "string" ) {
rob@77 8656 gotoEnd = clearQueue;
rob@77 8657 clearQueue = type;
rob@77 8658 type = undefined;
rob@77 8659 }
rob@77 8660 if ( clearQueue && type !== false ) {
rob@77 8661 this.queue( type || "fx", [] );
rob@77 8662 }
rob@77 8663
rob@77 8664 return this.each(function() {
rob@77 8665 var index,
rob@77 8666 hadTimers = false,
rob@77 8667 timers = jQuery.timers,
rob@77 8668 data = jQuery._data( this );
rob@77 8669
rob@77 8670 // clear marker counters if we know they won't be
rob@77 8671 if ( !gotoEnd ) {
rob@77 8672 jQuery._unmark( true, this );
rob@77 8673 }
rob@77 8674
rob@77 8675 function stopQueue( elem, data, index ) {
rob@77 8676 var hooks = data[ index ];
rob@77 8677 jQuery.removeData( elem, index, true );
rob@77 8678 hooks.stop( gotoEnd );
rob@77 8679 }
rob@77 8680
rob@77 8681 if ( type == null ) {
rob@77 8682 for ( index in data ) {
rob@77 8683 if ( data[ index ] && data[ index ].stop && index.indexOf(".run") === index.length - 4 ) {
rob@77 8684 stopQueue( this, data, index );
rob@77 8685 }
rob@77 8686 }
rob@77 8687 } else if ( data[ index = type + ".run" ] && data[ index ].stop ){
rob@77 8688 stopQueue( this, data, index );
rob@77 8689 }
rob@77 8690
rob@77 8691 for ( index = timers.length; index--; ) {
rob@77 8692 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
rob@77 8693 if ( gotoEnd ) {
rob@77 8694
rob@77 8695 // force the next step to be the last
rob@77 8696 timers[ index ]( true );
rob@77 8697 } else {
rob@77 8698 timers[ index ].saveState();
rob@77 8699 }
rob@77 8700 hadTimers = true;
rob@77 8701 timers.splice( index, 1 );
rob@77 8702 }
rob@77 8703 }
rob@77 8704
rob@77 8705 // start the next in the queue if the last step wasn't forced
rob@77 8706 // timers currently will call their complete callbacks, which will dequeue
rob@77 8707 // but only if they were gotoEnd
rob@77 8708 if ( !( gotoEnd && hadTimers ) ) {
rob@77 8709 jQuery.dequeue( this, type );
rob@77 8710 }
rob@77 8711 });
rob@77 8712 }
rob@77 8713
rob@77 8714 });
rob@77 8715
rob@77 8716 // Animations created synchronously will run synchronously
rob@77 8717 function createFxNow() {
rob@77 8718 setTimeout( clearFxNow, 0 );
rob@77 8719 return ( fxNow = jQuery.now() );
rob@77 8720 }
rob@77 8721
rob@77 8722 function clearFxNow() {
rob@77 8723 fxNow = undefined;
rob@77 8724 }
rob@77 8725
rob@77 8726 // Generate parameters to create a standard animation
rob@77 8727 function genFx( type, num ) {
rob@77 8728 var obj = {};
rob@77 8729
rob@77 8730 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice( 0, num )), function() {
rob@77 8731 obj[ this ] = type;
rob@77 8732 });
rob@77 8733
rob@77 8734 return obj;
rob@77 8735 }
rob@77 8736
rob@77 8737 // Generate shortcuts for custom animations
rob@77 8738 jQuery.each({
rob@77 8739 slideDown: genFx( "show", 1 ),
rob@77 8740 slideUp: genFx( "hide", 1 ),
rob@77 8741 slideToggle: genFx( "toggle", 1 ),
rob@77 8742 fadeIn: { opacity: "show" },
rob@77 8743 fadeOut: { opacity: "hide" },
rob@77 8744 fadeToggle: { opacity: "toggle" }
rob@77 8745 }, function( name, props ) {
rob@77 8746 jQuery.fn[ name ] = function( speed, easing, callback ) {
rob@77 8747 return this.animate( props, speed, easing, callback );
rob@77 8748 };
rob@77 8749 });
rob@77 8750
rob@77 8751 jQuery.extend({
rob@77 8752 speed: function( speed, easing, fn ) {
rob@77 8753 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
rob@77 8754 complete: fn || !fn && easing ||
rob@77 8755 jQuery.isFunction( speed ) && speed,
rob@77 8756 duration: speed,
rob@77 8757 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
rob@77 8758 };
rob@77 8759
rob@77 8760 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
rob@77 8761 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
rob@77 8762
rob@77 8763 // normalize opt.queue - true/undefined/null -> "fx"
rob@77 8764 if ( opt.queue == null || opt.queue === true ) {
rob@77 8765 opt.queue = "fx";
rob@77 8766 }
rob@77 8767
rob@77 8768 // Queueing
rob@77 8769 opt.old = opt.complete;
rob@77 8770
rob@77 8771 opt.complete = function( noUnmark ) {
rob@77 8772 if ( jQuery.isFunction( opt.old ) ) {
rob@77 8773 opt.old.call( this );
rob@77 8774 }
rob@77 8775
rob@77 8776 if ( opt.queue ) {
rob@77 8777 jQuery.dequeue( this, opt.queue );
rob@77 8778 } else if ( noUnmark !== false ) {
rob@77 8779 jQuery._unmark( this );
rob@77 8780 }
rob@77 8781 };
rob@77 8782
rob@77 8783 return opt;
rob@77 8784 },
rob@77 8785
rob@77 8786 easing: {
rob@77 8787 linear: function( p ) {
rob@77 8788 return p;
rob@77 8789 },
rob@77 8790 swing: function( p ) {
rob@77 8791 return ( -Math.cos( p*Math.PI ) / 2 ) + 0.5;
rob@77 8792 }
rob@77 8793 },
rob@77 8794
rob@77 8795 timers: [],
rob@77 8796
rob@77 8797 fx: function( elem, options, prop ) {
rob@77 8798 this.options = options;
rob@77 8799 this.elem = elem;
rob@77 8800 this.prop = prop;
rob@77 8801
rob@77 8802 options.orig = options.orig || {};
rob@77 8803 }
rob@77 8804
rob@77 8805 });
rob@77 8806
rob@77 8807 jQuery.fx.prototype = {
rob@77 8808 // Simple function for setting a style value
rob@77 8809 update: function() {
rob@77 8810 if ( this.options.step ) {
rob@77 8811 this.options.step.call( this.elem, this.now, this );
rob@77 8812 }
rob@77 8813
rob@77 8814 ( jQuery.fx.step[ this.prop ] || jQuery.fx.step._default )( this );
rob@77 8815 },
rob@77 8816
rob@77 8817 // Get the current size
rob@77 8818 cur: function() {
rob@77 8819 if ( this.elem[ this.prop ] != null && (!this.elem.style || this.elem.style[ this.prop ] == null) ) {
rob@77 8820 return this.elem[ this.prop ];
rob@77 8821 }
rob@77 8822
rob@77 8823 var parsed,
rob@77 8824 r = jQuery.css( this.elem, this.prop );
rob@77 8825 // Empty strings, null, undefined and "auto" are converted to 0,
rob@77 8826 // complex values such as "rotate(1rad)" are returned as is,
rob@77 8827 // simple values such as "10px" are parsed to Float.
rob@77 8828 return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
rob@77 8829 },
rob@77 8830
rob@77 8831 // Start an animation from one number to another
rob@77 8832 custom: function( from, to, unit ) {
rob@77 8833 var self = this,
rob@77 8834 fx = jQuery.fx;
rob@77 8835
rob@77 8836 this.startTime = fxNow || createFxNow();
rob@77 8837 this.end = to;
rob@77 8838 this.now = this.start = from;
rob@77 8839 this.pos = this.state = 0;
rob@77 8840 this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
rob@77 8841
rob@77 8842 function t( gotoEnd ) {
rob@77 8843 return self.step( gotoEnd );
rob@77 8844 }
rob@77 8845
rob@77 8846 t.queue = this.options.queue;
rob@77 8847 t.elem = this.elem;
rob@77 8848 t.saveState = function() {
rob@77 8849 if ( jQuery._data( self.elem, "fxshow" + self.prop ) === undefined ) {
rob@77 8850 if ( self.options.hide ) {
rob@77 8851 jQuery._data( self.elem, "fxshow" + self.prop, self.start );
rob@77 8852 } else if ( self.options.show ) {
rob@77 8853 jQuery._data( self.elem, "fxshow" + self.prop, self.end );
rob@77 8854 }
rob@77 8855 }
rob@77 8856 };
rob@77 8857
rob@77 8858 if ( t() && jQuery.timers.push(t) && !timerId ) {
rob@77 8859 timerId = setInterval( fx.tick, fx.interval );
rob@77 8860 }
rob@77 8861 },
rob@77 8862
rob@77 8863 // Simple 'show' function
rob@77 8864 show: function() {
rob@77 8865 var dataShow = jQuery._data( this.elem, "fxshow" + this.prop );
rob@77 8866
rob@77 8867 // Remember where we started, so that we can go back to it later
rob@77 8868 this.options.orig[ this.prop ] = dataShow || jQuery.style( this.elem, this.prop );
rob@77 8869 this.options.show = true;
rob@77 8870
rob@77 8871 // Begin the animation
rob@77 8872 // Make sure that we start at a small width/height to avoid any flash of content
rob@77 8873 if ( dataShow !== undefined ) {
rob@77 8874 // This show is picking up where a previous hide or show left off
rob@77 8875 this.custom( this.cur(), dataShow );
rob@77 8876 } else {
rob@77 8877 this.custom( this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur() );
rob@77 8878 }
rob@77 8879
rob@77 8880 // Start by showing the element
rob@77 8881 jQuery( this.elem ).show();
rob@77 8882 },
rob@77 8883
rob@77 8884 // Simple 'hide' function
rob@77 8885 hide: function() {
rob@77 8886 // Remember where we started, so that we can go back to it later
rob@77 8887 this.options.orig[ this.prop ] = jQuery._data( this.elem, "fxshow" + this.prop ) || jQuery.style( this.elem, this.prop );
rob@77 8888 this.options.hide = true;
rob@77 8889
rob@77 8890 // Begin the animation
rob@77 8891 this.custom( this.cur(), 0 );
rob@77 8892 },
rob@77 8893
rob@77 8894 // Each step of an animation
rob@77 8895 step: function( gotoEnd ) {
rob@77 8896 var p, n, complete,
rob@77 8897 t = fxNow || createFxNow(),
rob@77 8898 done = true,
rob@77 8899 elem = this.elem,
rob@77 8900 options = this.options;
rob@77 8901
rob@77 8902 if ( gotoEnd || t >= options.duration + this.startTime ) {
rob@77 8903 this.now = this.end;
rob@77 8904 this.pos = this.state = 1;
rob@77 8905 this.update();
rob@77 8906
rob@77 8907 options.animatedProperties[ this.prop ] = true;
rob@77 8908
rob@77 8909 for ( p in options.animatedProperties ) {
rob@77 8910 if ( options.animatedProperties[ p ] !== true ) {
rob@77 8911 done = false;
rob@77 8912 }
rob@77 8913 }
rob@77 8914
rob@77 8915 if ( done ) {
rob@77 8916 // Reset the overflow
rob@77 8917 if ( options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
rob@77 8918
rob@77 8919 jQuery.each( [ "", "X", "Y" ], function( index, value ) {
rob@77 8920 elem.style[ "overflow" + value ] = options.overflow[ index ];
rob@77 8921 });
rob@77 8922 }
rob@77 8923
rob@77 8924 // Hide the element if the "hide" operation was done
rob@77 8925 if ( options.hide ) {
rob@77 8926 jQuery( elem ).hide();
rob@77 8927 }
rob@77 8928
rob@77 8929 // Reset the properties, if the item has been hidden or shown
rob@77 8930 if ( options.hide || options.show ) {
rob@77 8931 for ( p in options.animatedProperties ) {
rob@77 8932 jQuery.style( elem, p, options.orig[ p ] );
rob@77 8933 jQuery.removeData( elem, "fxshow" + p, true );
rob@77 8934 // Toggle data is no longer needed
rob@77 8935 jQuery.removeData( elem, "toggle" + p, true );
rob@77 8936 }
rob@77 8937 }
rob@77 8938
rob@77 8939 // Execute the complete function
rob@77 8940 // in the event that the complete function throws an exception
rob@77 8941 // we must ensure it won't be called twice. #5684
rob@77 8942
rob@77 8943 complete = options.complete;
rob@77 8944 if ( complete ) {
rob@77 8945
rob@77 8946 options.complete = false;
rob@77 8947 complete.call( elem );
rob@77 8948 }
rob@77 8949 }
rob@77 8950
rob@77 8951 return false;
rob@77 8952
rob@77 8953 } else {
rob@77 8954 // classical easing cannot be used with an Infinity duration
rob@77 8955 if ( options.duration == Infinity ) {
rob@77 8956 this.now = t;
rob@77 8957 } else {
rob@77 8958 n = t - this.startTime;
rob@77 8959 this.state = n / options.duration;
rob@77 8960
rob@77 8961 // Perform the easing function, defaults to swing
rob@77 8962 this.pos = jQuery.easing[ options.animatedProperties[this.prop] ]( this.state, n, 0, 1, options.duration );
rob@77 8963 this.now = this.start + ( (this.end - this.start) * this.pos );
rob@77 8964 }
rob@77 8965 // Perform the next step of the animation
rob@77 8966 this.update();
rob@77 8967 }
rob@77 8968
rob@77 8969 return true;
rob@77 8970 }
rob@77 8971 };
rob@77 8972
rob@77 8973 jQuery.extend( jQuery.fx, {
rob@77 8974 tick: function() {
rob@77 8975 var timer,
rob@77 8976 timers = jQuery.timers,
rob@77 8977 i = 0;
rob@77 8978
rob@77 8979 for ( ; i < timers.length; i++ ) {
rob@77 8980 timer = timers[ i ];
rob@77 8981 // Checks the timer has not already been removed
rob@77 8982 if ( !timer() && timers[ i ] === timer ) {
rob@77 8983 timers.splice( i--, 1 );
rob@77 8984 }
rob@77 8985 }
rob@77 8986
rob@77 8987 if ( !timers.length ) {
rob@77 8988 jQuery.fx.stop();
rob@77 8989 }
rob@77 8990 },
rob@77 8991
rob@77 8992 interval: 13,
rob@77 8993
rob@77 8994 stop: function() {
rob@77 8995 clearInterval( timerId );
rob@77 8996 timerId = null;
rob@77 8997 },
rob@77 8998
rob@77 8999 speeds: {
rob@77 9000 slow: 600,
rob@77 9001 fast: 200,
rob@77 9002 // Default speed
rob@77 9003 _default: 400
rob@77 9004 },
rob@77 9005
rob@77 9006 step: {
rob@77 9007 opacity: function( fx ) {
rob@77 9008 jQuery.style( fx.elem, "opacity", fx.now );
rob@77 9009 },
rob@77 9010
rob@77 9011 _default: function( fx ) {
rob@77 9012 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
rob@77 9013 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
rob@77 9014 } else {
rob@77 9015 fx.elem[ fx.prop ] = fx.now;
rob@77 9016 }
rob@77 9017 }
rob@77 9018 }
rob@77 9019 });
rob@77 9020
rob@77 9021 // Ensure props that can't be negative don't go there on undershoot easing
rob@77 9022 jQuery.each( fxAttrs.concat.apply( [], fxAttrs ), function( i, prop ) {
rob@77 9023 // exclude marginTop, marginLeft, marginBottom and marginRight from this list
rob@77 9024 if ( prop.indexOf( "margin" ) ) {
rob@77 9025 jQuery.fx.step[ prop ] = function( fx ) {
rob@77 9026 jQuery.style( fx.elem, prop, Math.max(0, fx.now) + fx.unit );
rob@77 9027 };
rob@77 9028 }
rob@77 9029 });
rob@77 9030
rob@77 9031 if ( jQuery.expr && jQuery.expr.filters ) {
rob@77 9032 jQuery.expr.filters.animated = function( elem ) {
rob@77 9033 return jQuery.grep(jQuery.timers, function( fn ) {
rob@77 9034 return elem === fn.elem;
rob@77 9035 }).length;
rob@77 9036 };
rob@77 9037 }
rob@77 9038
rob@77 9039 // Try to restore the default display value of an element
rob@77 9040 function defaultDisplay( nodeName ) {
rob@77 9041
rob@77 9042 if ( !elemdisplay[ nodeName ] ) {
rob@77 9043
rob@77 9044 var body = document.body,
rob@77 9045 elem = jQuery( "<" + nodeName + ">" ).appendTo( body ),
rob@77 9046 display = elem.css( "display" );
rob@77 9047 elem.remove();
rob@77 9048
rob@77 9049 // If the simple way fails,
rob@77 9050 // get element's real default display by attaching it to a temp iframe
rob@77 9051 if ( display === "none" || display === "" ) {
rob@77 9052 // No iframe to use yet, so create it
rob@77 9053 if ( !iframe ) {
rob@77 9054 iframe = document.createElement( "iframe" );
rob@77 9055 iframe.frameBorder = iframe.width = iframe.height = 0;
rob@77 9056 }
rob@77 9057
rob@77 9058 body.appendChild( iframe );
rob@77 9059
rob@77 9060 // Create a cacheable copy of the iframe document on first call.
rob@77 9061 // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake HTML
rob@77 9062 // document to it; WebKit & Firefox won't allow reusing the iframe document.
rob@77 9063 if ( !iframeDoc || !iframe.createElement ) {
rob@77 9064 iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
rob@77 9065 iframeDoc.write( ( jQuery.support.boxModel ? "<!doctype html>" : "" ) + "<html><body>" );
rob@77 9066 iframeDoc.close();
rob@77 9067 }
rob@77 9068
rob@77 9069 elem = iframeDoc.createElement( nodeName );
rob@77 9070
rob@77 9071 iframeDoc.body.appendChild( elem );
rob@77 9072
rob@77 9073 display = jQuery.css( elem, "display" );
rob@77 9074 body.removeChild( iframe );
rob@77 9075 }
rob@77 9076
rob@77 9077 // Store the correct default display
rob@77 9078 elemdisplay[ nodeName ] = display;
rob@77 9079 }
rob@77 9080
rob@77 9081 return elemdisplay[ nodeName ];
rob@77 9082 }
rob@77 9083
rob@77 9084
rob@77 9085
rob@77 9086
rob@77 9087 var getOffset,
rob@77 9088 rtable = /^t(?:able|d|h)$/i,
rob@77 9089 rroot = /^(?:body|html)$/i;
rob@77 9090
rob@77 9091 if ( "getBoundingClientRect" in document.documentElement ) {
rob@77 9092 getOffset = function( elem, doc, docElem, box ) {
rob@77 9093 try {
rob@77 9094 box = elem.getBoundingClientRect();
rob@77 9095 } catch(e) {}
rob@77 9096
rob@77 9097 // Make sure we're not dealing with a disconnected DOM node
rob@77 9098 if ( !box || !jQuery.contains( docElem, elem ) ) {
rob@77 9099 return box ? { top: box.top, left: box.left } : { top: 0, left: 0 };
rob@77 9100 }
rob@77 9101
rob@77 9102 var body = doc.body,
rob@77 9103 win = getWindow( doc ),
rob@77 9104 clientTop = docElem.clientTop || body.clientTop || 0,
rob@77 9105 clientLeft = docElem.clientLeft || body.clientLeft || 0,
rob@77 9106 scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
rob@77 9107 scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
rob@77 9108 top = box.top + scrollTop - clientTop,
rob@77 9109 left = box.left + scrollLeft - clientLeft;
rob@77 9110
rob@77 9111 return { top: top, left: left };
rob@77 9112 };
rob@77 9113
rob@77 9114 } else {
rob@77 9115 getOffset = function( elem, doc, docElem ) {
rob@77 9116 var computedStyle,
rob@77 9117 offsetParent = elem.offsetParent,
rob@77 9118 prevOffsetParent = elem,
rob@77 9119 body = doc.body,
rob@77 9120 defaultView = doc.defaultView,
rob@77 9121 prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle,
rob@77 9122 top = elem.offsetTop,
rob@77 9123 left = elem.offsetLeft;
rob@77 9124
rob@77 9125 while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
rob@77 9126 if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
rob@77 9127 break;
rob@77 9128 }
rob@77 9129
rob@77 9130 computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
rob@77 9131 top -= elem.scrollTop;
rob@77 9132 left -= elem.scrollLeft;
rob@77 9133
rob@77 9134 if ( elem === offsetParent ) {
rob@77 9135 top += elem.offsetTop;
rob@77 9136 left += elem.offsetLeft;
rob@77 9137
rob@77 9138 if ( jQuery.support.doesNotAddBorder && !(jQuery.support.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) {
rob@77 9139 top += parseFloat( computedStyle.borderTopWidth ) || 0;
rob@77 9140 left += parseFloat( computedStyle.borderLeftWidth ) || 0;
rob@77 9141 }
rob@77 9142
rob@77 9143 prevOffsetParent = offsetParent;
rob@77 9144 offsetParent = elem.offsetParent;
rob@77 9145 }
rob@77 9146
rob@77 9147 if ( jQuery.support.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
rob@77 9148 top += parseFloat( computedStyle.borderTopWidth ) || 0;
rob@77 9149 left += parseFloat( computedStyle.borderLeftWidth ) || 0;
rob@77 9150 }
rob@77 9151
rob@77 9152 prevComputedStyle = computedStyle;
rob@77 9153 }
rob@77 9154
rob@77 9155 if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
rob@77 9156 top += body.offsetTop;
rob@77 9157 left += body.offsetLeft;
rob@77 9158 }
rob@77 9159
rob@77 9160 if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) {
rob@77 9161 top += Math.max( docElem.scrollTop, body.scrollTop );
rob@77 9162 left += Math.max( docElem.scrollLeft, body.scrollLeft );
rob@77 9163 }
rob@77 9164
rob@77 9165 return { top: top, left: left };
rob@77 9166 };
rob@77 9167 }
rob@77 9168
rob@77 9169 jQuery.fn.offset = function( options ) {
rob@77 9170 if ( arguments.length ) {
rob@77 9171 return options === undefined ?
rob@77 9172 this :
rob@77 9173 this.each(function( i ) {
rob@77 9174 jQuery.offset.setOffset( this, options, i );
rob@77 9175 });
rob@77 9176 }
rob@77 9177
rob@77 9178 var elem = this[0],
rob@77 9179 doc = elem && elem.ownerDocument;
rob@77 9180
rob@77 9181 if ( !doc ) {
rob@77 9182 return null;
rob@77 9183 }
rob@77 9184
rob@77 9185 if ( elem === doc.body ) {
rob@77 9186 return jQuery.offset.bodyOffset( elem );
rob@77 9187 }
rob@77 9188
rob@77 9189 return getOffset( elem, doc, doc.documentElement );
rob@77 9190 };
rob@77 9191
rob@77 9192 jQuery.offset = {
rob@77 9193
rob@77 9194 bodyOffset: function( body ) {
rob@77 9195 var top = body.offsetTop,
rob@77 9196 left = body.offsetLeft;
rob@77 9197
rob@77 9198 if ( jQuery.support.doesNotIncludeMarginInBodyOffset ) {
rob@77 9199 top += parseFloat( jQuery.css(body, "marginTop") ) || 0;
rob@77 9200 left += parseFloat( jQuery.css(body, "marginLeft") ) || 0;
rob@77 9201 }
rob@77 9202
rob@77 9203 return { top: top, left: left };
rob@77 9204 },
rob@77 9205
rob@77 9206 setOffset: function( elem, options, i ) {
rob@77 9207 var position = jQuery.css( elem, "position" );
rob@77 9208
rob@77 9209 // set position first, in-case top/left are set even on static elem
rob@77 9210 if ( position === "static" ) {
rob@77 9211 elem.style.position = "relative";
rob@77 9212 }
rob@77 9213
rob@77 9214 var curElem = jQuery( elem ),
rob@77 9215 curOffset = curElem.offset(),
rob@77 9216 curCSSTop = jQuery.css( elem, "top" ),
rob@77 9217 curCSSLeft = jQuery.css( elem, "left" ),
rob@77 9218 calculatePosition = ( position === "absolute" || position === "fixed" ) && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
rob@77 9219 props = {}, curPosition = {}, curTop, curLeft;
rob@77 9220
rob@77 9221 // need to be able to calculate position if either top or left is auto and position is either absolute or fixed
rob@77 9222 if ( calculatePosition ) {
rob@77 9223 curPosition = curElem.position();
rob@77 9224 curTop = curPosition.top;
rob@77 9225 curLeft = curPosition.left;
rob@77 9226 } else {
rob@77 9227 curTop = parseFloat( curCSSTop ) || 0;
rob@77 9228 curLeft = parseFloat( curCSSLeft ) || 0;
rob@77 9229 }
rob@77 9230
rob@77 9231 if ( jQuery.isFunction( options ) ) {
rob@77 9232 options = options.call( elem, i, curOffset );
rob@77 9233 }
rob@77 9234
rob@77 9235 if ( options.top != null ) {
rob@77 9236 props.top = ( options.top - curOffset.top ) + curTop;
rob@77 9237 }
rob@77 9238 if ( options.left != null ) {
rob@77 9239 props.left = ( options.left - curOffset.left ) + curLeft;
rob@77 9240 }
rob@77 9241
rob@77 9242 if ( "using" in options ) {
rob@77 9243 options.using.call( elem, props );
rob@77 9244 } else {
rob@77 9245 curElem.css( props );
rob@77 9246 }
rob@77 9247 }
rob@77 9248 };
rob@77 9249
rob@77 9250
rob@77 9251 jQuery.fn.extend({
rob@77 9252
rob@77 9253 position: function() {
rob@77 9254 if ( !this[0] ) {
rob@77 9255 return null;
rob@77 9256 }
rob@77 9257
rob@77 9258 var elem = this[0],
rob@77 9259
rob@77 9260 // Get *real* offsetParent
rob@77 9261 offsetParent = this.offsetParent(),
rob@77 9262
rob@77 9263 // Get correct offsets
rob@77 9264 offset = this.offset(),
rob@77 9265 parentOffset = rroot.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset();
rob@77 9266
rob@77 9267 // Subtract element margins
rob@77 9268 // note: when an element has margin: auto the offsetLeft and marginLeft
rob@77 9269 // are the same in Safari causing offset.left to incorrectly be 0
rob@77 9270 offset.top -= parseFloat( jQuery.css(elem, "marginTop") ) || 0;
rob@77 9271 offset.left -= parseFloat( jQuery.css(elem, "marginLeft") ) || 0;
rob@77 9272
rob@77 9273 // Add offsetParent borders
rob@77 9274 parentOffset.top += parseFloat( jQuery.css(offsetParent[0], "borderTopWidth") ) || 0;
rob@77 9275 parentOffset.left += parseFloat( jQuery.css(offsetParent[0], "borderLeftWidth") ) || 0;
rob@77 9276
rob@77 9277 // Subtract the two offsets
rob@77 9278 return {
rob@77 9279 top: offset.top - parentOffset.top,
rob@77 9280 left: offset.left - parentOffset.left
rob@77 9281 };
rob@77 9282 },
rob@77 9283
rob@77 9284 offsetParent: function() {
rob@77 9285 return this.map(function() {
rob@77 9286 var offsetParent = this.offsetParent || document.body;
rob@77 9287 while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) {
rob@77 9288 offsetParent = offsetParent.offsetParent;
rob@77 9289 }
rob@77 9290 return offsetParent;
rob@77 9291 });
rob@77 9292 }
rob@77 9293 });
rob@77 9294
rob@77 9295
rob@77 9296 // Create scrollLeft and scrollTop methods
rob@77 9297 jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) {
rob@77 9298 var top = /Y/.test( prop );
rob@77 9299
rob@77 9300 jQuery.fn[ method ] = function( val ) {
rob@77 9301 return jQuery.access( this, function( elem, method, val ) {
rob@77 9302 var win = getWindow( elem );
rob@77 9303
rob@77 9304 if ( val === undefined ) {
rob@77 9305 return win ? (prop in win) ? win[ prop ] :
rob@77 9306 jQuery.support.boxModel && win.document.documentElement[ method ] ||
rob@77 9307 win.document.body[ method ] :
rob@77 9308 elem[ method ];
rob@77 9309 }
rob@77 9310
rob@77 9311 if ( win ) {
rob@77 9312 win.scrollTo(
rob@77 9313 !top ? val : jQuery( win ).scrollLeft(),
rob@77 9314 top ? val : jQuery( win ).scrollTop()
rob@77 9315 );
rob@77 9316
rob@77 9317 } else {
rob@77 9318 elem[ method ] = val;
rob@77 9319 }
rob@77 9320 }, method, val, arguments.length, null );
rob@77 9321 };
rob@77 9322 });
rob@77 9323
rob@77 9324 function getWindow( elem ) {
rob@77 9325 return jQuery.isWindow( elem ) ?
rob@77 9326 elem :
rob@77 9327 elem.nodeType === 9 ?
rob@77 9328 elem.defaultView || elem.parentWindow :
rob@77 9329 false;
rob@77 9330 }
rob@77 9331
rob@77 9332
rob@77 9333
rob@77 9334
rob@77 9335 // Create width, height, innerHeight, innerWidth, outerHeight and outerWidth methods
rob@77 9336 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
rob@77 9337 var clientProp = "client" + name,
rob@77 9338 scrollProp = "scroll" + name,
rob@77 9339 offsetProp = "offset" + name;
rob@77 9340
rob@77 9341 // innerHeight and innerWidth
rob@77 9342 jQuery.fn[ "inner" + name ] = function() {
rob@77 9343 var elem = this[0];
rob@77 9344 return elem ?
rob@77 9345 elem.style ?
rob@77 9346 parseFloat( jQuery.css( elem, type, "padding" ) ) :
rob@77 9347 this[ type ]() :
rob@77 9348 null;
rob@77 9349 };
rob@77 9350
rob@77 9351 // outerHeight and outerWidth
rob@77 9352 jQuery.fn[ "outer" + name ] = function( margin ) {
rob@77 9353 var elem = this[0];
rob@77 9354 return elem ?
rob@77 9355 elem.style ?
rob@77 9356 parseFloat( jQuery.css( elem, type, margin ? "margin" : "border" ) ) :
rob@77 9357 this[ type ]() :
rob@77 9358 null;
rob@77 9359 };
rob@77 9360
rob@77 9361 jQuery.fn[ type ] = function( value ) {
rob@77 9362 return jQuery.access( this, function( elem, type, value ) {
rob@77 9363 var doc, docElemProp, orig, ret;
rob@77 9364
rob@77 9365 if ( jQuery.isWindow( elem ) ) {
rob@77 9366 // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
rob@77 9367 doc = elem.document;
rob@77 9368 docElemProp = doc.documentElement[ clientProp ];
rob@77 9369 return jQuery.support.boxModel && docElemProp ||
rob@77 9370 doc.body && doc.body[ clientProp ] || docElemProp;
rob@77 9371 }
rob@77 9372
rob@77 9373 // Get document width or height
rob@77 9374 if ( elem.nodeType === 9 ) {
rob@77 9375 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater
rob@77 9376 doc = elem.documentElement;
rob@77 9377
rob@77 9378 // when a window > document, IE6 reports a offset[Width/Height] > client[Width/Height]
rob@77 9379 // so we can't use max, as it'll choose the incorrect offset[Width/Height]
rob@77 9380 // instead we use the correct client[Width/Height]
rob@77 9381 // support:IE6
rob@77 9382 if ( doc[ clientProp ] >= doc[ scrollProp ] ) {
rob@77 9383 return doc[ clientProp ];
rob@77 9384 }
rob@77 9385
rob@77 9386 return Math.max(
rob@77 9387 elem.body[ scrollProp ], doc[ scrollProp ],
rob@77 9388 elem.body[ offsetProp ], doc[ offsetProp ]
rob@77 9389 );
rob@77 9390 }
rob@77 9391
rob@77 9392 // Get width or height on the element
rob@77 9393 if ( value === undefined ) {
rob@77 9394 orig = jQuery.css( elem, type );
rob@77 9395 ret = parseFloat( orig );
rob@77 9396 return jQuery.isNumeric( ret ) ? ret : orig;
rob@77 9397 }
rob@77 9398
rob@77 9399 // Set the width or height on the element
rob@77 9400 jQuery( elem ).css( type, value );
rob@77 9401 }, type, value, arguments.length, null );
rob@77 9402 };
rob@77 9403 });
rob@77 9404
rob@77 9405
rob@77 9406
rob@77 9407
rob@77 9408 // Expose jQuery to the global object
rob@77 9409 window.jQuery = window.$ = jQuery;
rob@77 9410
rob@77 9411 // Expose jQuery as an AMD module, but only for AMD loaders that
rob@77 9412 // understand the issues with loading multiple versions of jQuery
rob@77 9413 // in a page that all might call define(). The loader will indicate
rob@77 9414 // they have special allowances for multiple jQuery versions by
rob@77 9415 // specifying define.amd.jQuery = true. Register as a named module,
rob@77 9416 // since jQuery can be concatenated with other files that may use define,
rob@77 9417 // but not use a proper concatenation script that understands anonymous
rob@77 9418 // AMD modules. A named AMD is safest and most robust way to register.
rob@77 9419 // Lowercase jquery is used because AMD module names are derived from
rob@77 9420 // file names, and jQuery is normally delivered in a lowercase file name.
rob@77 9421 // Do this after creating the global so that if an AMD module wants to call
rob@77 9422 // noConflict to hide this version of jQuery, it will work.
rob@77 9423 if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
rob@77 9424 define( "jquery", [], function () { return jQuery; } );
rob@77 9425 }
rob@77 9426
rob@77 9427
rob@77 9428
rob@77 9429 })( window );
rob@77 9430
rob@77 9431
rob@77 9432 window.jQuery.noConflict();
rob@77 9433 return window.jQuery;
rob@77 9434 }
rob@77 9435 module.exports = create('undefined' === typeof window ? undefined : window);
rob@77 9436 module.exports.create = create;
rob@77 9437 }());