annotate jquery-2.1.4.js @ 1011:2df5ba8845b3

Merge from 156:402bb0f56dc4
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 01 Jun 2015 12:56:15 +0100
parents f427b5805b69
children
rev   line source
nicholas@926 1 /*!
nicholas@926 2 * jQuery JavaScript Library v2.1.4
nicholas@926 3 * http://jquery.com/
nicholas@926 4 *
nicholas@926 5 * Includes Sizzle.js
nicholas@926 6 * http://sizzlejs.com/
nicholas@926 7 *
nicholas@926 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nicholas@926 9 * Released under the MIT license
nicholas@926 10 * http://jquery.org/license
nicholas@926 11 *
nicholas@926 12 * Date: 2015-04-28T16:01Z
nicholas@926 13 */
nicholas@926 14
nicholas@926 15 (function( global, factory ) {
nicholas@926 16
nicholas@926 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nicholas@926 18 // For CommonJS and CommonJS-like environments where a proper `window`
nicholas@926 19 // is present, execute the factory and get jQuery.
nicholas@926 20 // For environments that do not have a `window` with a `document`
nicholas@926 21 // (such as Node.js), expose a factory as module.exports.
nicholas@926 22 // This accentuates the need for the creation of a real `window`.
nicholas@926 23 // e.g. var jQuery = require("jquery")(window);
nicholas@926 24 // See ticket #14549 for more info.
nicholas@926 25 module.exports = global.document ?
nicholas@926 26 factory( global, true ) :
nicholas@926 27 function( w ) {
nicholas@926 28 if ( !w.document ) {
nicholas@926 29 throw new Error( "jQuery requires a window with a document" );
nicholas@926 30 }
nicholas@926 31 return factory( w );
nicholas@926 32 };
nicholas@926 33 } else {
nicholas@926 34 factory( global );
nicholas@926 35 }
nicholas@926 36
nicholas@926 37 // Pass this if window is not defined yet
nicholas@926 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nicholas@926 39
nicholas@926 40 // Support: Firefox 18+
nicholas@926 41 // Can't be in strict mode, several libs including ASP.NET trace
nicholas@926 42 // the stack via arguments.caller.callee and Firefox dies if
nicholas@926 43 // you try to trace through "use strict" call chains. (#13335)
nicholas@926 44 //
nicholas@926 45
nicholas@926 46 var arr = [];
nicholas@926 47
nicholas@926 48 var slice = arr.slice;
nicholas@926 49
nicholas@926 50 var concat = arr.concat;
nicholas@926 51
nicholas@926 52 var push = arr.push;
nicholas@926 53
nicholas@926 54 var indexOf = arr.indexOf;
nicholas@926 55
nicholas@926 56 var class2type = {};
nicholas@926 57
nicholas@926 58 var toString = class2type.toString;
nicholas@926 59
nicholas@926 60 var hasOwn = class2type.hasOwnProperty;
nicholas@926 61
nicholas@926 62 var support = {};
nicholas@926 63
nicholas@926 64
nicholas@926 65
nicholas@926 66 var
nicholas@926 67 // Use the correct document accordingly with window argument (sandbox)
nicholas@926 68 document = window.document,
nicholas@926 69
nicholas@926 70 version = "2.1.4",
nicholas@926 71
nicholas@926 72 // Define a local copy of jQuery
nicholas@926 73 jQuery = function( selector, context ) {
nicholas@926 74 // The jQuery object is actually just the init constructor 'enhanced'
nicholas@926 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nicholas@926 76 return new jQuery.fn.init( selector, context );
nicholas@926 77 },
nicholas@926 78
nicholas@926 79 // Support: Android<4.1
nicholas@926 80 // Make sure we trim BOM and NBSP
nicholas@926 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nicholas@926 82
nicholas@926 83 // Matches dashed string for camelizing
nicholas@926 84 rmsPrefix = /^-ms-/,
nicholas@926 85 rdashAlpha = /-([\da-z])/gi,
nicholas@926 86
nicholas@926 87 // Used by jQuery.camelCase as callback to replace()
nicholas@926 88 fcamelCase = function( all, letter ) {
nicholas@926 89 return letter.toUpperCase();
nicholas@926 90 };
nicholas@926 91
nicholas@926 92 jQuery.fn = jQuery.prototype = {
nicholas@926 93 // The current version of jQuery being used
nicholas@926 94 jquery: version,
nicholas@926 95
nicholas@926 96 constructor: jQuery,
nicholas@926 97
nicholas@926 98 // Start with an empty selector
nicholas@926 99 selector: "",
nicholas@926 100
nicholas@926 101 // The default length of a jQuery object is 0
nicholas@926 102 length: 0,
nicholas@926 103
nicholas@926 104 toArray: function() {
nicholas@926 105 return slice.call( this );
nicholas@926 106 },
nicholas@926 107
nicholas@926 108 // Get the Nth element in the matched element set OR
nicholas@926 109 // Get the whole matched element set as a clean array
nicholas@926 110 get: function( num ) {
nicholas@926 111 return num != null ?
nicholas@926 112
nicholas@926 113 // Return just the one element from the set
nicholas@926 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nicholas@926 115
nicholas@926 116 // Return all the elements in a clean array
nicholas@926 117 slice.call( this );
nicholas@926 118 },
nicholas@926 119
nicholas@926 120 // Take an array of elements and push it onto the stack
nicholas@926 121 // (returning the new matched element set)
nicholas@926 122 pushStack: function( elems ) {
nicholas@926 123
nicholas@926 124 // Build a new jQuery matched element set
nicholas@926 125 var ret = jQuery.merge( this.constructor(), elems );
nicholas@926 126
nicholas@926 127 // Add the old object onto the stack (as a reference)
nicholas@926 128 ret.prevObject = this;
nicholas@926 129 ret.context = this.context;
nicholas@926 130
nicholas@926 131 // Return the newly-formed element set
nicholas@926 132 return ret;
nicholas@926 133 },
nicholas@926 134
nicholas@926 135 // Execute a callback for every element in the matched set.
nicholas@926 136 // (You can seed the arguments with an array of args, but this is
nicholas@926 137 // only used internally.)
nicholas@926 138 each: function( callback, args ) {
nicholas@926 139 return jQuery.each( this, callback, args );
nicholas@926 140 },
nicholas@926 141
nicholas@926 142 map: function( callback ) {
nicholas@926 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nicholas@926 144 return callback.call( elem, i, elem );
nicholas@926 145 }));
nicholas@926 146 },
nicholas@926 147
nicholas@926 148 slice: function() {
nicholas@926 149 return this.pushStack( slice.apply( this, arguments ) );
nicholas@926 150 },
nicholas@926 151
nicholas@926 152 first: function() {
nicholas@926 153 return this.eq( 0 );
nicholas@926 154 },
nicholas@926 155
nicholas@926 156 last: function() {
nicholas@926 157 return this.eq( -1 );
nicholas@926 158 },
nicholas@926 159
nicholas@926 160 eq: function( i ) {
nicholas@926 161 var len = this.length,
nicholas@926 162 j = +i + ( i < 0 ? len : 0 );
nicholas@926 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nicholas@926 164 },
nicholas@926 165
nicholas@926 166 end: function() {
nicholas@926 167 return this.prevObject || this.constructor(null);
nicholas@926 168 },
nicholas@926 169
nicholas@926 170 // For internal use only.
nicholas@926 171 // Behaves like an Array's method, not like a jQuery method.
nicholas@926 172 push: push,
nicholas@926 173 sort: arr.sort,
nicholas@926 174 splice: arr.splice
nicholas@926 175 };
nicholas@926 176
nicholas@926 177 jQuery.extend = jQuery.fn.extend = function() {
nicholas@926 178 var options, name, src, copy, copyIsArray, clone,
nicholas@926 179 target = arguments[0] || {},
nicholas@926 180 i = 1,
nicholas@926 181 length = arguments.length,
nicholas@926 182 deep = false;
nicholas@926 183
nicholas@926 184 // Handle a deep copy situation
nicholas@926 185 if ( typeof target === "boolean" ) {
nicholas@926 186 deep = target;
nicholas@926 187
nicholas@926 188 // Skip the boolean and the target
nicholas@926 189 target = arguments[ i ] || {};
nicholas@926 190 i++;
nicholas@926 191 }
nicholas@926 192
nicholas@926 193 // Handle case when target is a string or something (possible in deep copy)
nicholas@926 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nicholas@926 195 target = {};
nicholas@926 196 }
nicholas@926 197
nicholas@926 198 // Extend jQuery itself if only one argument is passed
nicholas@926 199 if ( i === length ) {
nicholas@926 200 target = this;
nicholas@926 201 i--;
nicholas@926 202 }
nicholas@926 203
nicholas@926 204 for ( ; i < length; i++ ) {
nicholas@926 205 // Only deal with non-null/undefined values
nicholas@926 206 if ( (options = arguments[ i ]) != null ) {
nicholas@926 207 // Extend the base object
nicholas@926 208 for ( name in options ) {
nicholas@926 209 src = target[ name ];
nicholas@926 210 copy = options[ name ];
nicholas@926 211
nicholas@926 212 // Prevent never-ending loop
nicholas@926 213 if ( target === copy ) {
nicholas@926 214 continue;
nicholas@926 215 }
nicholas@926 216
nicholas@926 217 // Recurse if we're merging plain objects or arrays
nicholas@926 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nicholas@926 219 if ( copyIsArray ) {
nicholas@926 220 copyIsArray = false;
nicholas@926 221 clone = src && jQuery.isArray(src) ? src : [];
nicholas@926 222
nicholas@926 223 } else {
nicholas@926 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nicholas@926 225 }
nicholas@926 226
nicholas@926 227 // Never move original objects, clone them
nicholas@926 228 target[ name ] = jQuery.extend( deep, clone, copy );
nicholas@926 229
nicholas@926 230 // Don't bring in undefined values
nicholas@926 231 } else if ( copy !== undefined ) {
nicholas@926 232 target[ name ] = copy;
nicholas@926 233 }
nicholas@926 234 }
nicholas@926 235 }
nicholas@926 236 }
nicholas@926 237
nicholas@926 238 // Return the modified object
nicholas@926 239 return target;
nicholas@926 240 };
nicholas@926 241
nicholas@926 242 jQuery.extend({
nicholas@926 243 // Unique for each copy of jQuery on the page
nicholas@926 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nicholas@926 245
nicholas@926 246 // Assume jQuery is ready without the ready module
nicholas@926 247 isReady: true,
nicholas@926 248
nicholas@926 249 error: function( msg ) {
nicholas@926 250 throw new Error( msg );
nicholas@926 251 },
nicholas@926 252
nicholas@926 253 noop: function() {},
nicholas@926 254
nicholas@926 255 isFunction: function( obj ) {
nicholas@926 256 return jQuery.type(obj) === "function";
nicholas@926 257 },
nicholas@926 258
nicholas@926 259 isArray: Array.isArray,
nicholas@926 260
nicholas@926 261 isWindow: function( obj ) {
nicholas@926 262 return obj != null && obj === obj.window;
nicholas@926 263 },
nicholas@926 264
nicholas@926 265 isNumeric: function( obj ) {
nicholas@926 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nicholas@926 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nicholas@926 268 // subtraction forces infinities to NaN
nicholas@926 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nicholas@926 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nicholas@926 271 },
nicholas@926 272
nicholas@926 273 isPlainObject: function( obj ) {
nicholas@926 274 // Not plain objects:
nicholas@926 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nicholas@926 276 // - DOM nodes
nicholas@926 277 // - window
nicholas@926 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nicholas@926 279 return false;
nicholas@926 280 }
nicholas@926 281
nicholas@926 282 if ( obj.constructor &&
nicholas@926 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nicholas@926 284 return false;
nicholas@926 285 }
nicholas@926 286
nicholas@926 287 // If the function hasn't returned already, we're confident that
nicholas@926 288 // |obj| is a plain object, created by {} or constructed with new Object
nicholas@926 289 return true;
nicholas@926 290 },
nicholas@926 291
nicholas@926 292 isEmptyObject: function( obj ) {
nicholas@926 293 var name;
nicholas@926 294 for ( name in obj ) {
nicholas@926 295 return false;
nicholas@926 296 }
nicholas@926 297 return true;
nicholas@926 298 },
nicholas@926 299
nicholas@926 300 type: function( obj ) {
nicholas@926 301 if ( obj == null ) {
nicholas@926 302 return obj + "";
nicholas@926 303 }
nicholas@926 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nicholas@926 305 return typeof obj === "object" || typeof obj === "function" ?
nicholas@926 306 class2type[ toString.call(obj) ] || "object" :
nicholas@926 307 typeof obj;
nicholas@926 308 },
nicholas@926 309
nicholas@926 310 // Evaluates a script in a global context
nicholas@926 311 globalEval: function( code ) {
nicholas@926 312 var script,
nicholas@926 313 indirect = eval;
nicholas@926 314
nicholas@926 315 code = jQuery.trim( code );
nicholas@926 316
nicholas@926 317 if ( code ) {
nicholas@926 318 // If the code includes a valid, prologue position
nicholas@926 319 // strict mode pragma, execute code by injecting a
nicholas@926 320 // script tag into the document.
nicholas@926 321 if ( code.indexOf("use strict") === 1 ) {
nicholas@926 322 script = document.createElement("script");
nicholas@926 323 script.text = code;
nicholas@926 324 document.head.appendChild( script ).parentNode.removeChild( script );
nicholas@926 325 } else {
nicholas@926 326 // Otherwise, avoid the DOM node creation, insertion
nicholas@926 327 // and removal by using an indirect global eval
nicholas@926 328 indirect( code );
nicholas@926 329 }
nicholas@926 330 }
nicholas@926 331 },
nicholas@926 332
nicholas@926 333 // Convert dashed to camelCase; used by the css and data modules
nicholas@926 334 // Support: IE9-11+
nicholas@926 335 // Microsoft forgot to hump their vendor prefix (#9572)
nicholas@926 336 camelCase: function( string ) {
nicholas@926 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nicholas@926 338 },
nicholas@926 339
nicholas@926 340 nodeName: function( elem, name ) {
nicholas@926 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nicholas@926 342 },
nicholas@926 343
nicholas@926 344 // args is for internal usage only
nicholas@926 345 each: function( obj, callback, args ) {
nicholas@926 346 var value,
nicholas@926 347 i = 0,
nicholas@926 348 length = obj.length,
nicholas@926 349 isArray = isArraylike( obj );
nicholas@926 350
nicholas@926 351 if ( args ) {
nicholas@926 352 if ( isArray ) {
nicholas@926 353 for ( ; i < length; i++ ) {
nicholas@926 354 value = callback.apply( obj[ i ], args );
nicholas@926 355
nicholas@926 356 if ( value === false ) {
nicholas@926 357 break;
nicholas@926 358 }
nicholas@926 359 }
nicholas@926 360 } else {
nicholas@926 361 for ( i in obj ) {
nicholas@926 362 value = callback.apply( obj[ i ], args );
nicholas@926 363
nicholas@926 364 if ( value === false ) {
nicholas@926 365 break;
nicholas@926 366 }
nicholas@926 367 }
nicholas@926 368 }
nicholas@926 369
nicholas@926 370 // A special, fast, case for the most common use of each
nicholas@926 371 } else {
nicholas@926 372 if ( isArray ) {
nicholas@926 373 for ( ; i < length; i++ ) {
nicholas@926 374 value = callback.call( obj[ i ], i, obj[ i ] );
nicholas@926 375
nicholas@926 376 if ( value === false ) {
nicholas@926 377 break;
nicholas@926 378 }
nicholas@926 379 }
nicholas@926 380 } else {
nicholas@926 381 for ( i in obj ) {
nicholas@926 382 value = callback.call( obj[ i ], i, obj[ i ] );
nicholas@926 383
nicholas@926 384 if ( value === false ) {
nicholas@926 385 break;
nicholas@926 386 }
nicholas@926 387 }
nicholas@926 388 }
nicholas@926 389 }
nicholas@926 390
nicholas@926 391 return obj;
nicholas@926 392 },
nicholas@926 393
nicholas@926 394 // Support: Android<4.1
nicholas@926 395 trim: function( text ) {
nicholas@926 396 return text == null ?
nicholas@926 397 "" :
nicholas@926 398 ( text + "" ).replace( rtrim, "" );
nicholas@926 399 },
nicholas@926 400
nicholas@926 401 // results is for internal usage only
nicholas@926 402 makeArray: function( arr, results ) {
nicholas@926 403 var ret = results || [];
nicholas@926 404
nicholas@926 405 if ( arr != null ) {
nicholas@926 406 if ( isArraylike( Object(arr) ) ) {
nicholas@926 407 jQuery.merge( ret,
nicholas@926 408 typeof arr === "string" ?
nicholas@926 409 [ arr ] : arr
nicholas@926 410 );
nicholas@926 411 } else {
nicholas@926 412 push.call( ret, arr );
nicholas@926 413 }
nicholas@926 414 }
nicholas@926 415
nicholas@926 416 return ret;
nicholas@926 417 },
nicholas@926 418
nicholas@926 419 inArray: function( elem, arr, i ) {
nicholas@926 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nicholas@926 421 },
nicholas@926 422
nicholas@926 423 merge: function( first, second ) {
nicholas@926 424 var len = +second.length,
nicholas@926 425 j = 0,
nicholas@926 426 i = first.length;
nicholas@926 427
nicholas@926 428 for ( ; j < len; j++ ) {
nicholas@926 429 first[ i++ ] = second[ j ];
nicholas@926 430 }
nicholas@926 431
nicholas@926 432 first.length = i;
nicholas@926 433
nicholas@926 434 return first;
nicholas@926 435 },
nicholas@926 436
nicholas@926 437 grep: function( elems, callback, invert ) {
nicholas@926 438 var callbackInverse,
nicholas@926 439 matches = [],
nicholas@926 440 i = 0,
nicholas@926 441 length = elems.length,
nicholas@926 442 callbackExpect = !invert;
nicholas@926 443
nicholas@926 444 // Go through the array, only saving the items
nicholas@926 445 // that pass the validator function
nicholas@926 446 for ( ; i < length; i++ ) {
nicholas@926 447 callbackInverse = !callback( elems[ i ], i );
nicholas@926 448 if ( callbackInverse !== callbackExpect ) {
nicholas@926 449 matches.push( elems[ i ] );
nicholas@926 450 }
nicholas@926 451 }
nicholas@926 452
nicholas@926 453 return matches;
nicholas@926 454 },
nicholas@926 455
nicholas@926 456 // arg is for internal usage only
nicholas@926 457 map: function( elems, callback, arg ) {
nicholas@926 458 var value,
nicholas@926 459 i = 0,
nicholas@926 460 length = elems.length,
nicholas@926 461 isArray = isArraylike( elems ),
nicholas@926 462 ret = [];
nicholas@926 463
nicholas@926 464 // Go through the array, translating each of the items to their new values
nicholas@926 465 if ( isArray ) {
nicholas@926 466 for ( ; i < length; i++ ) {
nicholas@926 467 value = callback( elems[ i ], i, arg );
nicholas@926 468
nicholas@926 469 if ( value != null ) {
nicholas@926 470 ret.push( value );
nicholas@926 471 }
nicholas@926 472 }
nicholas@926 473
nicholas@926 474 // Go through every key on the object,
nicholas@926 475 } else {
nicholas@926 476 for ( i in elems ) {
nicholas@926 477 value = callback( elems[ i ], i, arg );
nicholas@926 478
nicholas@926 479 if ( value != null ) {
nicholas@926 480 ret.push( value );
nicholas@926 481 }
nicholas@926 482 }
nicholas@926 483 }
nicholas@926 484
nicholas@926 485 // Flatten any nested arrays
nicholas@926 486 return concat.apply( [], ret );
nicholas@926 487 },
nicholas@926 488
nicholas@926 489 // A global GUID counter for objects
nicholas@926 490 guid: 1,
nicholas@926 491
nicholas@926 492 // Bind a function to a context, optionally partially applying any
nicholas@926 493 // arguments.
nicholas@926 494 proxy: function( fn, context ) {
nicholas@926 495 var tmp, args, proxy;
nicholas@926 496
nicholas@926 497 if ( typeof context === "string" ) {
nicholas@926 498 tmp = fn[ context ];
nicholas@926 499 context = fn;
nicholas@926 500 fn = tmp;
nicholas@926 501 }
nicholas@926 502
nicholas@926 503 // Quick check to determine if target is callable, in the spec
nicholas@926 504 // this throws a TypeError, but we will just return undefined.
nicholas@926 505 if ( !jQuery.isFunction( fn ) ) {
nicholas@926 506 return undefined;
nicholas@926 507 }
nicholas@926 508
nicholas@926 509 // Simulated bind
nicholas@926 510 args = slice.call( arguments, 2 );
nicholas@926 511 proxy = function() {
nicholas@926 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nicholas@926 513 };
nicholas@926 514
nicholas@926 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nicholas@926 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nicholas@926 517
nicholas@926 518 return proxy;
nicholas@926 519 },
nicholas@926 520
nicholas@926 521 now: Date.now,
nicholas@926 522
nicholas@926 523 // jQuery.support is not used in Core but other projects attach their
nicholas@926 524 // properties to it so it needs to exist.
nicholas@926 525 support: support
nicholas@926 526 });
nicholas@926 527
nicholas@926 528 // Populate the class2type map
nicholas@926 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nicholas@926 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nicholas@926 531 });
nicholas@926 532
nicholas@926 533 function isArraylike( obj ) {
nicholas@926 534
nicholas@926 535 // Support: iOS 8.2 (not reproducible in simulator)
nicholas@926 536 // `in` check used to prevent JIT error (gh-2145)
nicholas@926 537 // hasOwn isn't used here due to false negatives
nicholas@926 538 // regarding Nodelist length in IE
nicholas@926 539 var length = "length" in obj && obj.length,
nicholas@926 540 type = jQuery.type( obj );
nicholas@926 541
nicholas@926 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nicholas@926 543 return false;
nicholas@926 544 }
nicholas@926 545
nicholas@926 546 if ( obj.nodeType === 1 && length ) {
nicholas@926 547 return true;
nicholas@926 548 }
nicholas@926 549
nicholas@926 550 return type === "array" || length === 0 ||
nicholas@926 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nicholas@926 552 }
nicholas@926 553 var Sizzle =
nicholas@926 554 /*!
nicholas@926 555 * Sizzle CSS Selector Engine v2.2.0-pre
nicholas@926 556 * http://sizzlejs.com/
nicholas@926 557 *
nicholas@926 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nicholas@926 559 * Released under the MIT license
nicholas@926 560 * http://jquery.org/license
nicholas@926 561 *
nicholas@926 562 * Date: 2014-12-16
nicholas@926 563 */
nicholas@926 564 (function( window ) {
nicholas@926 565
nicholas@926 566 var i,
nicholas@926 567 support,
nicholas@926 568 Expr,
nicholas@926 569 getText,
nicholas@926 570 isXML,
nicholas@926 571 tokenize,
nicholas@926 572 compile,
nicholas@926 573 select,
nicholas@926 574 outermostContext,
nicholas@926 575 sortInput,
nicholas@926 576 hasDuplicate,
nicholas@926 577
nicholas@926 578 // Local document vars
nicholas@926 579 setDocument,
nicholas@926 580 document,
nicholas@926 581 docElem,
nicholas@926 582 documentIsHTML,
nicholas@926 583 rbuggyQSA,
nicholas@926 584 rbuggyMatches,
nicholas@926 585 matches,
nicholas@926 586 contains,
nicholas@926 587
nicholas@926 588 // Instance-specific data
nicholas@926 589 expando = "sizzle" + 1 * new Date(),
nicholas@926 590 preferredDoc = window.document,
nicholas@926 591 dirruns = 0,
nicholas@926 592 done = 0,
nicholas@926 593 classCache = createCache(),
nicholas@926 594 tokenCache = createCache(),
nicholas@926 595 compilerCache = createCache(),
nicholas@926 596 sortOrder = function( a, b ) {
nicholas@926 597 if ( a === b ) {
nicholas@926 598 hasDuplicate = true;
nicholas@926 599 }
nicholas@926 600 return 0;
nicholas@926 601 },
nicholas@926 602
nicholas@926 603 // General-purpose constants
nicholas@926 604 MAX_NEGATIVE = 1 << 31,
nicholas@926 605
nicholas@926 606 // Instance methods
nicholas@926 607 hasOwn = ({}).hasOwnProperty,
nicholas@926 608 arr = [],
nicholas@926 609 pop = arr.pop,
nicholas@926 610 push_native = arr.push,
nicholas@926 611 push = arr.push,
nicholas@926 612 slice = arr.slice,
nicholas@926 613 // Use a stripped-down indexOf as it's faster than native
nicholas@926 614 // http://jsperf.com/thor-indexof-vs-for/5
nicholas@926 615 indexOf = function( list, elem ) {
nicholas@926 616 var i = 0,
nicholas@926 617 len = list.length;
nicholas@926 618 for ( ; i < len; i++ ) {
nicholas@926 619 if ( list[i] === elem ) {
nicholas@926 620 return i;
nicholas@926 621 }
nicholas@926 622 }
nicholas@926 623 return -1;
nicholas@926 624 },
nicholas@926 625
nicholas@926 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nicholas@926 627
nicholas@926 628 // Regular expressions
nicholas@926 629
nicholas@926 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nicholas@926 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nicholas@926 632 // http://www.w3.org/TR/css3-syntax/#characters
nicholas@926 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nicholas@926 634
nicholas@926 635 // Loosely modeled on CSS identifier characters
nicholas@926 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nicholas@926 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nicholas@926 638 identifier = characterEncoding.replace( "w", "w#" ),
nicholas@926 639
nicholas@926 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nicholas@926 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nicholas@926 642 // Operator (capture 2)
nicholas@926 643 "*([*^$|!~]?=)" + whitespace +
nicholas@926 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nicholas@926 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nicholas@926 646 "*\\]",
nicholas@926 647
nicholas@926 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nicholas@926 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nicholas@926 650 // 1. quoted (capture 3; capture 4 or capture 5)
nicholas@926 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nicholas@926 652 // 2. simple (capture 6)
nicholas@926 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nicholas@926 654 // 3. anything else (capture 2)
nicholas@926 655 ".*" +
nicholas@926 656 ")\\)|)",
nicholas@926 657
nicholas@926 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nicholas@926 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nicholas@926 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nicholas@926 661
nicholas@926 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nicholas@926 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nicholas@926 664
nicholas@926 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nicholas@926 666
nicholas@926 667 rpseudo = new RegExp( pseudos ),
nicholas@926 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nicholas@926 669
nicholas@926 670 matchExpr = {
nicholas@926 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nicholas@926 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nicholas@926 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nicholas@926 674 "ATTR": new RegExp( "^" + attributes ),
nicholas@926 675 "PSEUDO": new RegExp( "^" + pseudos ),
nicholas@926 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nicholas@926 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nicholas@926 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nicholas@926 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nicholas@926 680 // For use in libraries implementing .is()
nicholas@926 681 // We use this for POS matching in `select`
nicholas@926 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nicholas@926 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nicholas@926 684 },
nicholas@926 685
nicholas@926 686 rinputs = /^(?:input|select|textarea|button)$/i,
nicholas@926 687 rheader = /^h\d$/i,
nicholas@926 688
nicholas@926 689 rnative = /^[^{]+\{\s*\[native \w/,
nicholas@926 690
nicholas@926 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nicholas@926 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nicholas@926 693
nicholas@926 694 rsibling = /[+~]/,
nicholas@926 695 rescape = /'|\\/g,
nicholas@926 696
nicholas@926 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nicholas@926 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nicholas@926 699 funescape = function( _, escaped, escapedWhitespace ) {
nicholas@926 700 var high = "0x" + escaped - 0x10000;
nicholas@926 701 // NaN means non-codepoint
nicholas@926 702 // Support: Firefox<24
nicholas@926 703 // Workaround erroneous numeric interpretation of +"0x"
nicholas@926 704 return high !== high || escapedWhitespace ?
nicholas@926 705 escaped :
nicholas@926 706 high < 0 ?
nicholas@926 707 // BMP codepoint
nicholas@926 708 String.fromCharCode( high + 0x10000 ) :
nicholas@926 709 // Supplemental Plane codepoint (surrogate pair)
nicholas@926 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nicholas@926 711 },
nicholas@926 712
nicholas@926 713 // Used for iframes
nicholas@926 714 // See setDocument()
nicholas@926 715 // Removing the function wrapper causes a "Permission Denied"
nicholas@926 716 // error in IE
nicholas@926 717 unloadHandler = function() {
nicholas@926 718 setDocument();
nicholas@926 719 };
nicholas@926 720
nicholas@926 721 // Optimize for push.apply( _, NodeList )
nicholas@926 722 try {
nicholas@926 723 push.apply(
nicholas@926 724 (arr = slice.call( preferredDoc.childNodes )),
nicholas@926 725 preferredDoc.childNodes
nicholas@926 726 );
nicholas@926 727 // Support: Android<4.0
nicholas@926 728 // Detect silently failing push.apply
nicholas@926 729 arr[ preferredDoc.childNodes.length ].nodeType;
nicholas@926 730 } catch ( e ) {
nicholas@926 731 push = { apply: arr.length ?
nicholas@926 732
nicholas@926 733 // Leverage slice if possible
nicholas@926 734 function( target, els ) {
nicholas@926 735 push_native.apply( target, slice.call(els) );
nicholas@926 736 } :
nicholas@926 737
nicholas@926 738 // Support: IE<9
nicholas@926 739 // Otherwise append directly
nicholas@926 740 function( target, els ) {
nicholas@926 741 var j = target.length,
nicholas@926 742 i = 0;
nicholas@926 743 // Can't trust NodeList.length
nicholas@926 744 while ( (target[j++] = els[i++]) ) {}
nicholas@926 745 target.length = j - 1;
nicholas@926 746 }
nicholas@926 747 };
nicholas@926 748 }
nicholas@926 749
nicholas@926 750 function Sizzle( selector, context, results, seed ) {
nicholas@926 751 var match, elem, m, nodeType,
nicholas@926 752 // QSA vars
nicholas@926 753 i, groups, old, nid, newContext, newSelector;
nicholas@926 754
nicholas@926 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nicholas@926 756 setDocument( context );
nicholas@926 757 }
nicholas@926 758
nicholas@926 759 context = context || document;
nicholas@926 760 results = results || [];
nicholas@926 761 nodeType = context.nodeType;
nicholas@926 762
nicholas@926 763 if ( typeof selector !== "string" || !selector ||
nicholas@926 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nicholas@926 765
nicholas@926 766 return results;
nicholas@926 767 }
nicholas@926 768
nicholas@926 769 if ( !seed && documentIsHTML ) {
nicholas@926 770
nicholas@926 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nicholas@926 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nicholas@926 773 // Speed-up: Sizzle("#ID")
nicholas@926 774 if ( (m = match[1]) ) {
nicholas@926 775 if ( nodeType === 9 ) {
nicholas@926 776 elem = context.getElementById( m );
nicholas@926 777 // Check parentNode to catch when Blackberry 4.6 returns
nicholas@926 778 // nodes that are no longer in the document (jQuery #6963)
nicholas@926 779 if ( elem && elem.parentNode ) {
nicholas@926 780 // Handle the case where IE, Opera, and Webkit return items
nicholas@926 781 // by name instead of ID
nicholas@926 782 if ( elem.id === m ) {
nicholas@926 783 results.push( elem );
nicholas@926 784 return results;
nicholas@926 785 }
nicholas@926 786 } else {
nicholas@926 787 return results;
nicholas@926 788 }
nicholas@926 789 } else {
nicholas@926 790 // Context is not a document
nicholas@926 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nicholas@926 792 contains( context, elem ) && elem.id === m ) {
nicholas@926 793 results.push( elem );
nicholas@926 794 return results;
nicholas@926 795 }
nicholas@926 796 }
nicholas@926 797
nicholas@926 798 // Speed-up: Sizzle("TAG")
nicholas@926 799 } else if ( match[2] ) {
nicholas@926 800 push.apply( results, context.getElementsByTagName( selector ) );
nicholas@926 801 return results;
nicholas@926 802
nicholas@926 803 // Speed-up: Sizzle(".CLASS")
nicholas@926 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nicholas@926 805 push.apply( results, context.getElementsByClassName( m ) );
nicholas@926 806 return results;
nicholas@926 807 }
nicholas@926 808 }
nicholas@926 809
nicholas@926 810 // QSA path
nicholas@926 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nicholas@926 812 nid = old = expando;
nicholas@926 813 newContext = context;
nicholas@926 814 newSelector = nodeType !== 1 && selector;
nicholas@926 815
nicholas@926 816 // qSA works strangely on Element-rooted queries
nicholas@926 817 // We can work around this by specifying an extra ID on the root
nicholas@926 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nicholas@926 819 // IE 8 doesn't work on object elements
nicholas@926 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nicholas@926 821 groups = tokenize( selector );
nicholas@926 822
nicholas@926 823 if ( (old = context.getAttribute("id")) ) {
nicholas@926 824 nid = old.replace( rescape, "\\$&" );
nicholas@926 825 } else {
nicholas@926 826 context.setAttribute( "id", nid );
nicholas@926 827 }
nicholas@926 828 nid = "[id='" + nid + "'] ";
nicholas@926 829
nicholas@926 830 i = groups.length;
nicholas@926 831 while ( i-- ) {
nicholas@926 832 groups[i] = nid + toSelector( groups[i] );
nicholas@926 833 }
nicholas@926 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nicholas@926 835 newSelector = groups.join(",");
nicholas@926 836 }
nicholas@926 837
nicholas@926 838 if ( newSelector ) {
nicholas@926 839 try {
nicholas@926 840 push.apply( results,
nicholas@926 841 newContext.querySelectorAll( newSelector )
nicholas@926 842 );
nicholas@926 843 return results;
nicholas@926 844 } catch(qsaError) {
nicholas@926 845 } finally {
nicholas@926 846 if ( !old ) {
nicholas@926 847 context.removeAttribute("id");
nicholas@926 848 }
nicholas@926 849 }
nicholas@926 850 }
nicholas@926 851 }
nicholas@926 852 }
nicholas@926 853
nicholas@926 854 // All others
nicholas@926 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nicholas@926 856 }
nicholas@926 857
nicholas@926 858 /**
nicholas@926 859 * Create key-value caches of limited size
nicholas@926 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nicholas@926 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nicholas@926 862 * deleting the oldest entry
nicholas@926 863 */
nicholas@926 864 function createCache() {
nicholas@926 865 var keys = [];
nicholas@926 866
nicholas@926 867 function cache( key, value ) {
nicholas@926 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nicholas@926 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nicholas@926 870 // Only keep the most recent entries
nicholas@926 871 delete cache[ keys.shift() ];
nicholas@926 872 }
nicholas@926 873 return (cache[ key + " " ] = value);
nicholas@926 874 }
nicholas@926 875 return cache;
nicholas@926 876 }
nicholas@926 877
nicholas@926 878 /**
nicholas@926 879 * Mark a function for special use by Sizzle
nicholas@926 880 * @param {Function} fn The function to mark
nicholas@926 881 */
nicholas@926 882 function markFunction( fn ) {
nicholas@926 883 fn[ expando ] = true;
nicholas@926 884 return fn;
nicholas@926 885 }
nicholas@926 886
nicholas@926 887 /**
nicholas@926 888 * Support testing using an element
nicholas@926 889 * @param {Function} fn Passed the created div and expects a boolean result
nicholas@926 890 */
nicholas@926 891 function assert( fn ) {
nicholas@926 892 var div = document.createElement("div");
nicholas@926 893
nicholas@926 894 try {
nicholas@926 895 return !!fn( div );
nicholas@926 896 } catch (e) {
nicholas@926 897 return false;
nicholas@926 898 } finally {
nicholas@926 899 // Remove from its parent by default
nicholas@926 900 if ( div.parentNode ) {
nicholas@926 901 div.parentNode.removeChild( div );
nicholas@926 902 }
nicholas@926 903 // release memory in IE
nicholas@926 904 div = null;
nicholas@926 905 }
nicholas@926 906 }
nicholas@926 907
nicholas@926 908 /**
nicholas@926 909 * Adds the same handler for all of the specified attrs
nicholas@926 910 * @param {String} attrs Pipe-separated list of attributes
nicholas@926 911 * @param {Function} handler The method that will be applied
nicholas@926 912 */
nicholas@926 913 function addHandle( attrs, handler ) {
nicholas@926 914 var arr = attrs.split("|"),
nicholas@926 915 i = attrs.length;
nicholas@926 916
nicholas@926 917 while ( i-- ) {
nicholas@926 918 Expr.attrHandle[ arr[i] ] = handler;
nicholas@926 919 }
nicholas@926 920 }
nicholas@926 921
nicholas@926 922 /**
nicholas@926 923 * Checks document order of two siblings
nicholas@926 924 * @param {Element} a
nicholas@926 925 * @param {Element} b
nicholas@926 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nicholas@926 927 */
nicholas@926 928 function siblingCheck( a, b ) {
nicholas@926 929 var cur = b && a,
nicholas@926 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nicholas@926 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nicholas@926 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nicholas@926 933
nicholas@926 934 // Use IE sourceIndex if available on both nodes
nicholas@926 935 if ( diff ) {
nicholas@926 936 return diff;
nicholas@926 937 }
nicholas@926 938
nicholas@926 939 // Check if b follows a
nicholas@926 940 if ( cur ) {
nicholas@926 941 while ( (cur = cur.nextSibling) ) {
nicholas@926 942 if ( cur === b ) {
nicholas@926 943 return -1;
nicholas@926 944 }
nicholas@926 945 }
nicholas@926 946 }
nicholas@926 947
nicholas@926 948 return a ? 1 : -1;
nicholas@926 949 }
nicholas@926 950
nicholas@926 951 /**
nicholas@926 952 * Returns a function to use in pseudos for input types
nicholas@926 953 * @param {String} type
nicholas@926 954 */
nicholas@926 955 function createInputPseudo( type ) {
nicholas@926 956 return function( elem ) {
nicholas@926 957 var name = elem.nodeName.toLowerCase();
nicholas@926 958 return name === "input" && elem.type === type;
nicholas@926 959 };
nicholas@926 960 }
nicholas@926 961
nicholas@926 962 /**
nicholas@926 963 * Returns a function to use in pseudos for buttons
nicholas@926 964 * @param {String} type
nicholas@926 965 */
nicholas@926 966 function createButtonPseudo( type ) {
nicholas@926 967 return function( elem ) {
nicholas@926 968 var name = elem.nodeName.toLowerCase();
nicholas@926 969 return (name === "input" || name === "button") && elem.type === type;
nicholas@926 970 };
nicholas@926 971 }
nicholas@926 972
nicholas@926 973 /**
nicholas@926 974 * Returns a function to use in pseudos for positionals
nicholas@926 975 * @param {Function} fn
nicholas@926 976 */
nicholas@926 977 function createPositionalPseudo( fn ) {
nicholas@926 978 return markFunction(function( argument ) {
nicholas@926 979 argument = +argument;
nicholas@926 980 return markFunction(function( seed, matches ) {
nicholas@926 981 var j,
nicholas@926 982 matchIndexes = fn( [], seed.length, argument ),
nicholas@926 983 i = matchIndexes.length;
nicholas@926 984
nicholas@926 985 // Match elements found at the specified indexes
nicholas@926 986 while ( i-- ) {
nicholas@926 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nicholas@926 988 seed[j] = !(matches[j] = seed[j]);
nicholas@926 989 }
nicholas@926 990 }
nicholas@926 991 });
nicholas@926 992 });
nicholas@926 993 }
nicholas@926 994
nicholas@926 995 /**
nicholas@926 996 * Checks a node for validity as a Sizzle context
nicholas@926 997 * @param {Element|Object=} context
nicholas@926 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nicholas@926 999 */
nicholas@926 1000 function testContext( context ) {
nicholas@926 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nicholas@926 1002 }
nicholas@926 1003
nicholas@926 1004 // Expose support vars for convenience
nicholas@926 1005 support = Sizzle.support = {};
nicholas@926 1006
nicholas@926 1007 /**
nicholas@926 1008 * Detects XML nodes
nicholas@926 1009 * @param {Element|Object} elem An element or a document
nicholas@926 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nicholas@926 1011 */
nicholas@926 1012 isXML = Sizzle.isXML = function( elem ) {
nicholas@926 1013 // documentElement is verified for cases where it doesn't yet exist
nicholas@926 1014 // (such as loading iframes in IE - #4833)
nicholas@926 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nicholas@926 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nicholas@926 1017 };
nicholas@926 1018
nicholas@926 1019 /**
nicholas@926 1020 * Sets document-related variables once based on the current document
nicholas@926 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nicholas@926 1022 * @returns {Object} Returns the current document
nicholas@926 1023 */
nicholas@926 1024 setDocument = Sizzle.setDocument = function( node ) {
nicholas@926 1025 var hasCompare, parent,
nicholas@926 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nicholas@926 1027
nicholas@926 1028 // If no document and documentElement is available, return
nicholas@926 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nicholas@926 1030 return document;
nicholas@926 1031 }
nicholas@926 1032
nicholas@926 1033 // Set our document
nicholas@926 1034 document = doc;
nicholas@926 1035 docElem = doc.documentElement;
nicholas@926 1036 parent = doc.defaultView;
nicholas@926 1037
nicholas@926 1038 // Support: IE>8
nicholas@926 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nicholas@926 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nicholas@926 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nicholas@926 1042 if ( parent && parent !== parent.top ) {
nicholas@926 1043 // IE11 does not have attachEvent, so all must suffer
nicholas@926 1044 if ( parent.addEventListener ) {
nicholas@926 1045 parent.addEventListener( "unload", unloadHandler, false );
nicholas@926 1046 } else if ( parent.attachEvent ) {
nicholas@926 1047 parent.attachEvent( "onunload", unloadHandler );
nicholas@926 1048 }
nicholas@926 1049 }
nicholas@926 1050
nicholas@926 1051 /* Support tests
nicholas@926 1052 ---------------------------------------------------------------------- */
nicholas@926 1053 documentIsHTML = !isXML( doc );
nicholas@926 1054
nicholas@926 1055 /* Attributes
nicholas@926 1056 ---------------------------------------------------------------------- */
nicholas@926 1057
nicholas@926 1058 // Support: IE<8
nicholas@926 1059 // Verify that getAttribute really returns attributes and not properties
nicholas@926 1060 // (excepting IE8 booleans)
nicholas@926 1061 support.attributes = assert(function( div ) {
nicholas@926 1062 div.className = "i";
nicholas@926 1063 return !div.getAttribute("className");
nicholas@926 1064 });
nicholas@926 1065
nicholas@926 1066 /* getElement(s)By*
nicholas@926 1067 ---------------------------------------------------------------------- */
nicholas@926 1068
nicholas@926 1069 // Check if getElementsByTagName("*") returns only elements
nicholas@926 1070 support.getElementsByTagName = assert(function( div ) {
nicholas@926 1071 div.appendChild( doc.createComment("") );
nicholas@926 1072 return !div.getElementsByTagName("*").length;
nicholas@926 1073 });
nicholas@926 1074
nicholas@926 1075 // Support: IE<9
nicholas@926 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nicholas@926 1077
nicholas@926 1078 // Support: IE<10
nicholas@926 1079 // Check if getElementById returns elements by name
nicholas@926 1080 // The broken getElementById methods don't pick up programatically-set names,
nicholas@926 1081 // so use a roundabout getElementsByName test
nicholas@926 1082 support.getById = assert(function( div ) {
nicholas@926 1083 docElem.appendChild( div ).id = expando;
nicholas@926 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nicholas@926 1085 });
nicholas@926 1086
nicholas@926 1087 // ID find and filter
nicholas@926 1088 if ( support.getById ) {
nicholas@926 1089 Expr.find["ID"] = function( id, context ) {
nicholas@926 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nicholas@926 1091 var m = context.getElementById( id );
nicholas@926 1092 // Check parentNode to catch when Blackberry 4.6 returns
nicholas@926 1093 // nodes that are no longer in the document #6963
nicholas@926 1094 return m && m.parentNode ? [ m ] : [];
nicholas@926 1095 }
nicholas@926 1096 };
nicholas@926 1097 Expr.filter["ID"] = function( id ) {
nicholas@926 1098 var attrId = id.replace( runescape, funescape );
nicholas@926 1099 return function( elem ) {
nicholas@926 1100 return elem.getAttribute("id") === attrId;
nicholas@926 1101 };
nicholas@926 1102 };
nicholas@926 1103 } else {
nicholas@926 1104 // Support: IE6/7
nicholas@926 1105 // getElementById is not reliable as a find shortcut
nicholas@926 1106 delete Expr.find["ID"];
nicholas@926 1107
nicholas@926 1108 Expr.filter["ID"] = function( id ) {
nicholas@926 1109 var attrId = id.replace( runescape, funescape );
nicholas@926 1110 return function( elem ) {
nicholas@926 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nicholas@926 1112 return node && node.value === attrId;
nicholas@926 1113 };
nicholas@926 1114 };
nicholas@926 1115 }
nicholas@926 1116
nicholas@926 1117 // Tag
nicholas@926 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nicholas@926 1119 function( tag, context ) {
nicholas@926 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nicholas@926 1121 return context.getElementsByTagName( tag );
nicholas@926 1122
nicholas@926 1123 // DocumentFragment nodes don't have gEBTN
nicholas@926 1124 } else if ( support.qsa ) {
nicholas@926 1125 return context.querySelectorAll( tag );
nicholas@926 1126 }
nicholas@926 1127 } :
nicholas@926 1128
nicholas@926 1129 function( tag, context ) {
nicholas@926 1130 var elem,
nicholas@926 1131 tmp = [],
nicholas@926 1132 i = 0,
nicholas@926 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nicholas@926 1134 results = context.getElementsByTagName( tag );
nicholas@926 1135
nicholas@926 1136 // Filter out possible comments
nicholas@926 1137 if ( tag === "*" ) {
nicholas@926 1138 while ( (elem = results[i++]) ) {
nicholas@926 1139 if ( elem.nodeType === 1 ) {
nicholas@926 1140 tmp.push( elem );
nicholas@926 1141 }
nicholas@926 1142 }
nicholas@926 1143
nicholas@926 1144 return tmp;
nicholas@926 1145 }
nicholas@926 1146 return results;
nicholas@926 1147 };
nicholas@926 1148
nicholas@926 1149 // Class
nicholas@926 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nicholas@926 1151 if ( documentIsHTML ) {
nicholas@926 1152 return context.getElementsByClassName( className );
nicholas@926 1153 }
nicholas@926 1154 };
nicholas@926 1155
nicholas@926 1156 /* QSA/matchesSelector
nicholas@926 1157 ---------------------------------------------------------------------- */
nicholas@926 1158
nicholas@926 1159 // QSA and matchesSelector support
nicholas@926 1160
nicholas@926 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nicholas@926 1162 rbuggyMatches = [];
nicholas@926 1163
nicholas@926 1164 // qSa(:focus) reports false when true (Chrome 21)
nicholas@926 1165 // We allow this because of a bug in IE8/9 that throws an error
nicholas@926 1166 // whenever `document.activeElement` is accessed on an iframe
nicholas@926 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nicholas@926 1168 // See http://bugs.jquery.com/ticket/13378
nicholas@926 1169 rbuggyQSA = [];
nicholas@926 1170
nicholas@926 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nicholas@926 1172 // Build QSA regex
nicholas@926 1173 // Regex strategy adopted from Diego Perini
nicholas@926 1174 assert(function( div ) {
nicholas@926 1175 // Select is set to empty string on purpose
nicholas@926 1176 // This is to test IE's treatment of not explicitly
nicholas@926 1177 // setting a boolean content attribute,
nicholas@926 1178 // since its presence should be enough
nicholas@926 1179 // http://bugs.jquery.com/ticket/12359
nicholas@926 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nicholas@926 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nicholas@926 1182 "<option selected=''></option></select>";
nicholas@926 1183
nicholas@926 1184 // Support: IE8, Opera 11-12.16
nicholas@926 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nicholas@926 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nicholas@926 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nicholas@926 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nicholas@926 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nicholas@926 1190 }
nicholas@926 1191
nicholas@926 1192 // Support: IE8
nicholas@926 1193 // Boolean attributes and "value" are not treated correctly
nicholas@926 1194 if ( !div.querySelectorAll("[selected]").length ) {
nicholas@926 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nicholas@926 1196 }
nicholas@926 1197
nicholas@926 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nicholas@926 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nicholas@926 1200 rbuggyQSA.push("~=");
nicholas@926 1201 }
nicholas@926 1202
nicholas@926 1203 // Webkit/Opera - :checked should return selected option elements
nicholas@926 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nicholas@926 1205 // IE8 throws error here and will not see later tests
nicholas@926 1206 if ( !div.querySelectorAll(":checked").length ) {
nicholas@926 1207 rbuggyQSA.push(":checked");
nicholas@926 1208 }
nicholas@926 1209
nicholas@926 1210 // Support: Safari 8+, iOS 8+
nicholas@926 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nicholas@926 1212 // In-page `selector#id sibing-combinator selector` fails
nicholas@926 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nicholas@926 1214 rbuggyQSA.push(".#.+[+~]");
nicholas@926 1215 }
nicholas@926 1216 });
nicholas@926 1217
nicholas@926 1218 assert(function( div ) {
nicholas@926 1219 // Support: Windows 8 Native Apps
nicholas@926 1220 // The type and name attributes are restricted during .innerHTML assignment
nicholas@926 1221 var input = doc.createElement("input");
nicholas@926 1222 input.setAttribute( "type", "hidden" );
nicholas@926 1223 div.appendChild( input ).setAttribute( "name", "D" );
nicholas@926 1224
nicholas@926 1225 // Support: IE8
nicholas@926 1226 // Enforce case-sensitivity of name attribute
nicholas@926 1227 if ( div.querySelectorAll("[name=d]").length ) {
nicholas@926 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nicholas@926 1229 }
nicholas@926 1230
nicholas@926 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nicholas@926 1232 // IE8 throws error here and will not see later tests
nicholas@926 1233 if ( !div.querySelectorAll(":enabled").length ) {
nicholas@926 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nicholas@926 1235 }
nicholas@926 1236
nicholas@926 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nicholas@926 1238 div.querySelectorAll("*,:x");
nicholas@926 1239 rbuggyQSA.push(",.*:");
nicholas@926 1240 });
nicholas@926 1241 }
nicholas@926 1242
nicholas@926 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nicholas@926 1244 docElem.webkitMatchesSelector ||
nicholas@926 1245 docElem.mozMatchesSelector ||
nicholas@926 1246 docElem.oMatchesSelector ||
nicholas@926 1247 docElem.msMatchesSelector) )) ) {
nicholas@926 1248
nicholas@926 1249 assert(function( div ) {
nicholas@926 1250 // Check to see if it's possible to do matchesSelector
nicholas@926 1251 // on a disconnected node (IE 9)
nicholas@926 1252 support.disconnectedMatch = matches.call( div, "div" );
nicholas@926 1253
nicholas@926 1254 // This should fail with an exception
nicholas@926 1255 // Gecko does not error, returns false instead
nicholas@926 1256 matches.call( div, "[s!='']:x" );
nicholas@926 1257 rbuggyMatches.push( "!=", pseudos );
nicholas@926 1258 });
nicholas@926 1259 }
nicholas@926 1260
nicholas@926 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nicholas@926 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nicholas@926 1263
nicholas@926 1264 /* Contains
nicholas@926 1265 ---------------------------------------------------------------------- */
nicholas@926 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nicholas@926 1267
nicholas@926 1268 // Element contains another
nicholas@926 1269 // Purposefully does not implement inclusive descendent
nicholas@926 1270 // As in, an element does not contain itself
nicholas@926 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nicholas@926 1272 function( a, b ) {
nicholas@926 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nicholas@926 1274 bup = b && b.parentNode;
nicholas@926 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nicholas@926 1276 adown.contains ?
nicholas@926 1277 adown.contains( bup ) :
nicholas@926 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nicholas@926 1279 ));
nicholas@926 1280 } :
nicholas@926 1281 function( a, b ) {
nicholas@926 1282 if ( b ) {
nicholas@926 1283 while ( (b = b.parentNode) ) {
nicholas@926 1284 if ( b === a ) {
nicholas@926 1285 return true;
nicholas@926 1286 }
nicholas@926 1287 }
nicholas@926 1288 }
nicholas@926 1289 return false;
nicholas@926 1290 };
nicholas@926 1291
nicholas@926 1292 /* Sorting
nicholas@926 1293 ---------------------------------------------------------------------- */
nicholas@926 1294
nicholas@926 1295 // Document order sorting
nicholas@926 1296 sortOrder = hasCompare ?
nicholas@926 1297 function( a, b ) {
nicholas@926 1298
nicholas@926 1299 // Flag for duplicate removal
nicholas@926 1300 if ( a === b ) {
nicholas@926 1301 hasDuplicate = true;
nicholas@926 1302 return 0;
nicholas@926 1303 }
nicholas@926 1304
nicholas@926 1305 // Sort on method existence if only one input has compareDocumentPosition
nicholas@926 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nicholas@926 1307 if ( compare ) {
nicholas@926 1308 return compare;
nicholas@926 1309 }
nicholas@926 1310
nicholas@926 1311 // Calculate position if both inputs belong to the same document
nicholas@926 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nicholas@926 1313 a.compareDocumentPosition( b ) :
nicholas@926 1314
nicholas@926 1315 // Otherwise we know they are disconnected
nicholas@926 1316 1;
nicholas@926 1317
nicholas@926 1318 // Disconnected nodes
nicholas@926 1319 if ( compare & 1 ||
nicholas@926 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nicholas@926 1321
nicholas@926 1322 // Choose the first element that is related to our preferred document
nicholas@926 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nicholas@926 1324 return -1;
nicholas@926 1325 }
nicholas@926 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nicholas@926 1327 return 1;
nicholas@926 1328 }
nicholas@926 1329
nicholas@926 1330 // Maintain original order
nicholas@926 1331 return sortInput ?
nicholas@926 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nicholas@926 1333 0;
nicholas@926 1334 }
nicholas@926 1335
nicholas@926 1336 return compare & 4 ? -1 : 1;
nicholas@926 1337 } :
nicholas@926 1338 function( a, b ) {
nicholas@926 1339 // Exit early if the nodes are identical
nicholas@926 1340 if ( a === b ) {
nicholas@926 1341 hasDuplicate = true;
nicholas@926 1342 return 0;
nicholas@926 1343 }
nicholas@926 1344
nicholas@926 1345 var cur,
nicholas@926 1346 i = 0,
nicholas@926 1347 aup = a.parentNode,
nicholas@926 1348 bup = b.parentNode,
nicholas@926 1349 ap = [ a ],
nicholas@926 1350 bp = [ b ];
nicholas@926 1351
nicholas@926 1352 // Parentless nodes are either documents or disconnected
nicholas@926 1353 if ( !aup || !bup ) {
nicholas@926 1354 return a === doc ? -1 :
nicholas@926 1355 b === doc ? 1 :
nicholas@926 1356 aup ? -1 :
nicholas@926 1357 bup ? 1 :
nicholas@926 1358 sortInput ?
nicholas@926 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nicholas@926 1360 0;
nicholas@926 1361
nicholas@926 1362 // If the nodes are siblings, we can do a quick check
nicholas@926 1363 } else if ( aup === bup ) {
nicholas@926 1364 return siblingCheck( a, b );
nicholas@926 1365 }
nicholas@926 1366
nicholas@926 1367 // Otherwise we need full lists of their ancestors for comparison
nicholas@926 1368 cur = a;
nicholas@926 1369 while ( (cur = cur.parentNode) ) {
nicholas@926 1370 ap.unshift( cur );
nicholas@926 1371 }
nicholas@926 1372 cur = b;
nicholas@926 1373 while ( (cur = cur.parentNode) ) {
nicholas@926 1374 bp.unshift( cur );
nicholas@926 1375 }
nicholas@926 1376
nicholas@926 1377 // Walk down the tree looking for a discrepancy
nicholas@926 1378 while ( ap[i] === bp[i] ) {
nicholas@926 1379 i++;
nicholas@926 1380 }
nicholas@926 1381
nicholas@926 1382 return i ?
nicholas@926 1383 // Do a sibling check if the nodes have a common ancestor
nicholas@926 1384 siblingCheck( ap[i], bp[i] ) :
nicholas@926 1385
nicholas@926 1386 // Otherwise nodes in our document sort first
nicholas@926 1387 ap[i] === preferredDoc ? -1 :
nicholas@926 1388 bp[i] === preferredDoc ? 1 :
nicholas@926 1389 0;
nicholas@926 1390 };
nicholas@926 1391
nicholas@926 1392 return doc;
nicholas@926 1393 };
nicholas@926 1394
nicholas@926 1395 Sizzle.matches = function( expr, elements ) {
nicholas@926 1396 return Sizzle( expr, null, null, elements );
nicholas@926 1397 };
nicholas@926 1398
nicholas@926 1399 Sizzle.matchesSelector = function( elem, expr ) {
nicholas@926 1400 // Set document vars if needed
nicholas@926 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nicholas@926 1402 setDocument( elem );
nicholas@926 1403 }
nicholas@926 1404
nicholas@926 1405 // Make sure that attribute selectors are quoted
nicholas@926 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nicholas@926 1407
nicholas@926 1408 if ( support.matchesSelector && documentIsHTML &&
nicholas@926 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nicholas@926 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nicholas@926 1411
nicholas@926 1412 try {
nicholas@926 1413 var ret = matches.call( elem, expr );
nicholas@926 1414
nicholas@926 1415 // IE 9's matchesSelector returns false on disconnected nodes
nicholas@926 1416 if ( ret || support.disconnectedMatch ||
nicholas@926 1417 // As well, disconnected nodes are said to be in a document
nicholas@926 1418 // fragment in IE 9
nicholas@926 1419 elem.document && elem.document.nodeType !== 11 ) {
nicholas@926 1420 return ret;
nicholas@926 1421 }
nicholas@926 1422 } catch (e) {}
nicholas@926 1423 }
nicholas@926 1424
nicholas@926 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nicholas@926 1426 };
nicholas@926 1427
nicholas@926 1428 Sizzle.contains = function( context, elem ) {
nicholas@926 1429 // Set document vars if needed
nicholas@926 1430 if ( ( context.ownerDocument || context ) !== document ) {
nicholas@926 1431 setDocument( context );
nicholas@926 1432 }
nicholas@926 1433 return contains( context, elem );
nicholas@926 1434 };
nicholas@926 1435
nicholas@926 1436 Sizzle.attr = function( elem, name ) {
nicholas@926 1437 // Set document vars if needed
nicholas@926 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nicholas@926 1439 setDocument( elem );
nicholas@926 1440 }
nicholas@926 1441
nicholas@926 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nicholas@926 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nicholas@926 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nicholas@926 1445 fn( elem, name, !documentIsHTML ) :
nicholas@926 1446 undefined;
nicholas@926 1447
nicholas@926 1448 return val !== undefined ?
nicholas@926 1449 val :
nicholas@926 1450 support.attributes || !documentIsHTML ?
nicholas@926 1451 elem.getAttribute( name ) :
nicholas@926 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nicholas@926 1453 val.value :
nicholas@926 1454 null;
nicholas@926 1455 };
nicholas@926 1456
nicholas@926 1457 Sizzle.error = function( msg ) {
nicholas@926 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nicholas@926 1459 };
nicholas@926 1460
nicholas@926 1461 /**
nicholas@926 1462 * Document sorting and removing duplicates
nicholas@926 1463 * @param {ArrayLike} results
nicholas@926 1464 */
nicholas@926 1465 Sizzle.uniqueSort = function( results ) {
nicholas@926 1466 var elem,
nicholas@926 1467 duplicates = [],
nicholas@926 1468 j = 0,
nicholas@926 1469 i = 0;
nicholas@926 1470
nicholas@926 1471 // Unless we *know* we can detect duplicates, assume their presence
nicholas@926 1472 hasDuplicate = !support.detectDuplicates;
nicholas@926 1473 sortInput = !support.sortStable && results.slice( 0 );
nicholas@926 1474 results.sort( sortOrder );
nicholas@926 1475
nicholas@926 1476 if ( hasDuplicate ) {
nicholas@926 1477 while ( (elem = results[i++]) ) {
nicholas@926 1478 if ( elem === results[ i ] ) {
nicholas@926 1479 j = duplicates.push( i );
nicholas@926 1480 }
nicholas@926 1481 }
nicholas@926 1482 while ( j-- ) {
nicholas@926 1483 results.splice( duplicates[ j ], 1 );
nicholas@926 1484 }
nicholas@926 1485 }
nicholas@926 1486
nicholas@926 1487 // Clear input after sorting to release objects
nicholas@926 1488 // See https://github.com/jquery/sizzle/pull/225
nicholas@926 1489 sortInput = null;
nicholas@926 1490
nicholas@926 1491 return results;
nicholas@926 1492 };
nicholas@926 1493
nicholas@926 1494 /**
nicholas@926 1495 * Utility function for retrieving the text value of an array of DOM nodes
nicholas@926 1496 * @param {Array|Element} elem
nicholas@926 1497 */
nicholas@926 1498 getText = Sizzle.getText = function( elem ) {
nicholas@926 1499 var node,
nicholas@926 1500 ret = "",
nicholas@926 1501 i = 0,
nicholas@926 1502 nodeType = elem.nodeType;
nicholas@926 1503
nicholas@926 1504 if ( !nodeType ) {
nicholas@926 1505 // If no nodeType, this is expected to be an array
nicholas@926 1506 while ( (node = elem[i++]) ) {
nicholas@926 1507 // Do not traverse comment nodes
nicholas@926 1508 ret += getText( node );
nicholas@926 1509 }
nicholas@926 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nicholas@926 1511 // Use textContent for elements
nicholas@926 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nicholas@926 1513 if ( typeof elem.textContent === "string" ) {
nicholas@926 1514 return elem.textContent;
nicholas@926 1515 } else {
nicholas@926 1516 // Traverse its children
nicholas@926 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nicholas@926 1518 ret += getText( elem );
nicholas@926 1519 }
nicholas@926 1520 }
nicholas@926 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nicholas@926 1522 return elem.nodeValue;
nicholas@926 1523 }
nicholas@926 1524 // Do not include comment or processing instruction nodes
nicholas@926 1525
nicholas@926 1526 return ret;
nicholas@926 1527 };
nicholas@926 1528
nicholas@926 1529 Expr = Sizzle.selectors = {
nicholas@926 1530
nicholas@926 1531 // Can be adjusted by the user
nicholas@926 1532 cacheLength: 50,
nicholas@926 1533
nicholas@926 1534 createPseudo: markFunction,
nicholas@926 1535
nicholas@926 1536 match: matchExpr,
nicholas@926 1537
nicholas@926 1538 attrHandle: {},
nicholas@926 1539
nicholas@926 1540 find: {},
nicholas@926 1541
nicholas@926 1542 relative: {
nicholas@926 1543 ">": { dir: "parentNode", first: true },
nicholas@926 1544 " ": { dir: "parentNode" },
nicholas@926 1545 "+": { dir: "previousSibling", first: true },
nicholas@926 1546 "~": { dir: "previousSibling" }
nicholas@926 1547 },
nicholas@926 1548
nicholas@926 1549 preFilter: {
nicholas@926 1550 "ATTR": function( match ) {
nicholas@926 1551 match[1] = match[1].replace( runescape, funescape );
nicholas@926 1552
nicholas@926 1553 // Move the given value to match[3] whether quoted or unquoted
nicholas@926 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nicholas@926 1555
nicholas@926 1556 if ( match[2] === "~=" ) {
nicholas@926 1557 match[3] = " " + match[3] + " ";
nicholas@926 1558 }
nicholas@926 1559
nicholas@926 1560 return match.slice( 0, 4 );
nicholas@926 1561 },
nicholas@926 1562
nicholas@926 1563 "CHILD": function( match ) {
nicholas@926 1564 /* matches from matchExpr["CHILD"]
nicholas@926 1565 1 type (only|nth|...)
nicholas@926 1566 2 what (child|of-type)
nicholas@926 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nicholas@926 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nicholas@926 1569 5 sign of xn-component
nicholas@926 1570 6 x of xn-component
nicholas@926 1571 7 sign of y-component
nicholas@926 1572 8 y of y-component
nicholas@926 1573 */
nicholas@926 1574 match[1] = match[1].toLowerCase();
nicholas@926 1575
nicholas@926 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nicholas@926 1577 // nth-* requires argument
nicholas@926 1578 if ( !match[3] ) {
nicholas@926 1579 Sizzle.error( match[0] );
nicholas@926 1580 }
nicholas@926 1581
nicholas@926 1582 // numeric x and y parameters for Expr.filter.CHILD
nicholas@926 1583 // remember that false/true cast respectively to 0/1
nicholas@926 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nicholas@926 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nicholas@926 1586
nicholas@926 1587 // other types prohibit arguments
nicholas@926 1588 } else if ( match[3] ) {
nicholas@926 1589 Sizzle.error( match[0] );
nicholas@926 1590 }
nicholas@926 1591
nicholas@926 1592 return match;
nicholas@926 1593 },
nicholas@926 1594
nicholas@926 1595 "PSEUDO": function( match ) {
nicholas@926 1596 var excess,
nicholas@926 1597 unquoted = !match[6] && match[2];
nicholas@926 1598
nicholas@926 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nicholas@926 1600 return null;
nicholas@926 1601 }
nicholas@926 1602
nicholas@926 1603 // Accept quoted arguments as-is
nicholas@926 1604 if ( match[3] ) {
nicholas@926 1605 match[2] = match[4] || match[5] || "";
nicholas@926 1606
nicholas@926 1607 // Strip excess characters from unquoted arguments
nicholas@926 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nicholas@926 1609 // Get excess from tokenize (recursively)
nicholas@926 1610 (excess = tokenize( unquoted, true )) &&
nicholas@926 1611 // advance to the next closing parenthesis
nicholas@926 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nicholas@926 1613
nicholas@926 1614 // excess is a negative index
nicholas@926 1615 match[0] = match[0].slice( 0, excess );
nicholas@926 1616 match[2] = unquoted.slice( 0, excess );
nicholas@926 1617 }
nicholas@926 1618
nicholas@926 1619 // Return only captures needed by the pseudo filter method (type and argument)
nicholas@926 1620 return match.slice( 0, 3 );
nicholas@926 1621 }
nicholas@926 1622 },
nicholas@926 1623
nicholas@926 1624 filter: {
nicholas@926 1625
nicholas@926 1626 "TAG": function( nodeNameSelector ) {
nicholas@926 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nicholas@926 1628 return nodeNameSelector === "*" ?
nicholas@926 1629 function() { return true; } :
nicholas@926 1630 function( elem ) {
nicholas@926 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nicholas@926 1632 };
nicholas@926 1633 },
nicholas@926 1634
nicholas@926 1635 "CLASS": function( className ) {
nicholas@926 1636 var pattern = classCache[ className + " " ];
nicholas@926 1637
nicholas@926 1638 return pattern ||
nicholas@926 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nicholas@926 1640 classCache( className, function( elem ) {
nicholas@926 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nicholas@926 1642 });
nicholas@926 1643 },
nicholas@926 1644
nicholas@926 1645 "ATTR": function( name, operator, check ) {
nicholas@926 1646 return function( elem ) {
nicholas@926 1647 var result = Sizzle.attr( elem, name );
nicholas@926 1648
nicholas@926 1649 if ( result == null ) {
nicholas@926 1650 return operator === "!=";
nicholas@926 1651 }
nicholas@926 1652 if ( !operator ) {
nicholas@926 1653 return true;
nicholas@926 1654 }
nicholas@926 1655
nicholas@926 1656 result += "";
nicholas@926 1657
nicholas@926 1658 return operator === "=" ? result === check :
nicholas@926 1659 operator === "!=" ? result !== check :
nicholas@926 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nicholas@926 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nicholas@926 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nicholas@926 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nicholas@926 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nicholas@926 1665 false;
nicholas@926 1666 };
nicholas@926 1667 },
nicholas@926 1668
nicholas@926 1669 "CHILD": function( type, what, argument, first, last ) {
nicholas@926 1670 var simple = type.slice( 0, 3 ) !== "nth",
nicholas@926 1671 forward = type.slice( -4 ) !== "last",
nicholas@926 1672 ofType = what === "of-type";
nicholas@926 1673
nicholas@926 1674 return first === 1 && last === 0 ?
nicholas@926 1675
nicholas@926 1676 // Shortcut for :nth-*(n)
nicholas@926 1677 function( elem ) {
nicholas@926 1678 return !!elem.parentNode;
nicholas@926 1679 } :
nicholas@926 1680
nicholas@926 1681 function( elem, context, xml ) {
nicholas@926 1682 var cache, outerCache, node, diff, nodeIndex, start,
nicholas@926 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nicholas@926 1684 parent = elem.parentNode,
nicholas@926 1685 name = ofType && elem.nodeName.toLowerCase(),
nicholas@926 1686 useCache = !xml && !ofType;
nicholas@926 1687
nicholas@926 1688 if ( parent ) {
nicholas@926 1689
nicholas@926 1690 // :(first|last|only)-(child|of-type)
nicholas@926 1691 if ( simple ) {
nicholas@926 1692 while ( dir ) {
nicholas@926 1693 node = elem;
nicholas@926 1694 while ( (node = node[ dir ]) ) {
nicholas@926 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nicholas@926 1696 return false;
nicholas@926 1697 }
nicholas@926 1698 }
nicholas@926 1699 // Reverse direction for :only-* (if we haven't yet done so)
nicholas@926 1700 start = dir = type === "only" && !start && "nextSibling";
nicholas@926 1701 }
nicholas@926 1702 return true;
nicholas@926 1703 }
nicholas@926 1704
nicholas@926 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nicholas@926 1706
nicholas@926 1707 // non-xml :nth-child(...) stores cache data on `parent`
nicholas@926 1708 if ( forward && useCache ) {
nicholas@926 1709 // Seek `elem` from a previously-cached index
nicholas@926 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nicholas@926 1711 cache = outerCache[ type ] || [];
nicholas@926 1712 nodeIndex = cache[0] === dirruns && cache[1];
nicholas@926 1713 diff = cache[0] === dirruns && cache[2];
nicholas@926 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nicholas@926 1715
nicholas@926 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nicholas@926 1717
nicholas@926 1718 // Fallback to seeking `elem` from the start
nicholas@926 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nicholas@926 1720
nicholas@926 1721 // When found, cache indexes on `parent` and break
nicholas@926 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nicholas@926 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nicholas@926 1724 break;
nicholas@926 1725 }
nicholas@926 1726 }
nicholas@926 1727
nicholas@926 1728 // Use previously-cached element index if available
nicholas@926 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nicholas@926 1730 diff = cache[1];
nicholas@926 1731
nicholas@926 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nicholas@926 1733 } else {
nicholas@926 1734 // Use the same loop as above to seek `elem` from the start
nicholas@926 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nicholas@926 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nicholas@926 1737
nicholas@926 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nicholas@926 1739 // Cache the index of each encountered element
nicholas@926 1740 if ( useCache ) {
nicholas@926 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nicholas@926 1742 }
nicholas@926 1743
nicholas@926 1744 if ( node === elem ) {
nicholas@926 1745 break;
nicholas@926 1746 }
nicholas@926 1747 }
nicholas@926 1748 }
nicholas@926 1749 }
nicholas@926 1750
nicholas@926 1751 // Incorporate the offset, then check against cycle size
nicholas@926 1752 diff -= last;
nicholas@926 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nicholas@926 1754 }
nicholas@926 1755 };
nicholas@926 1756 },
nicholas@926 1757
nicholas@926 1758 "PSEUDO": function( pseudo, argument ) {
nicholas@926 1759 // pseudo-class names are case-insensitive
nicholas@926 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nicholas@926 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nicholas@926 1762 // Remember that setFilters inherits from pseudos
nicholas@926 1763 var args,
nicholas@926 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nicholas@926 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nicholas@926 1766
nicholas@926 1767 // The user may use createPseudo to indicate that
nicholas@926 1768 // arguments are needed to create the filter function
nicholas@926 1769 // just as Sizzle does
nicholas@926 1770 if ( fn[ expando ] ) {
nicholas@926 1771 return fn( argument );
nicholas@926 1772 }
nicholas@926 1773
nicholas@926 1774 // But maintain support for old signatures
nicholas@926 1775 if ( fn.length > 1 ) {
nicholas@926 1776 args = [ pseudo, pseudo, "", argument ];
nicholas@926 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nicholas@926 1778 markFunction(function( seed, matches ) {
nicholas@926 1779 var idx,
nicholas@926 1780 matched = fn( seed, argument ),
nicholas@926 1781 i = matched.length;
nicholas@926 1782 while ( i-- ) {
nicholas@926 1783 idx = indexOf( seed, matched[i] );
nicholas@926 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nicholas@926 1785 }
nicholas@926 1786 }) :
nicholas@926 1787 function( elem ) {
nicholas@926 1788 return fn( elem, 0, args );
nicholas@926 1789 };
nicholas@926 1790 }
nicholas@926 1791
nicholas@926 1792 return fn;
nicholas@926 1793 }
nicholas@926 1794 },
nicholas@926 1795
nicholas@926 1796 pseudos: {
nicholas@926 1797 // Potentially complex pseudos
nicholas@926 1798 "not": markFunction(function( selector ) {
nicholas@926 1799 // Trim the selector passed to compile
nicholas@926 1800 // to avoid treating leading and trailing
nicholas@926 1801 // spaces as combinators
nicholas@926 1802 var input = [],
nicholas@926 1803 results = [],
nicholas@926 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nicholas@926 1805
nicholas@926 1806 return matcher[ expando ] ?
nicholas@926 1807 markFunction(function( seed, matches, context, xml ) {
nicholas@926 1808 var elem,
nicholas@926 1809 unmatched = matcher( seed, null, xml, [] ),
nicholas@926 1810 i = seed.length;
nicholas@926 1811
nicholas@926 1812 // Match elements unmatched by `matcher`
nicholas@926 1813 while ( i-- ) {
nicholas@926 1814 if ( (elem = unmatched[i]) ) {
nicholas@926 1815 seed[i] = !(matches[i] = elem);
nicholas@926 1816 }
nicholas@926 1817 }
nicholas@926 1818 }) :
nicholas@926 1819 function( elem, context, xml ) {
nicholas@926 1820 input[0] = elem;
nicholas@926 1821 matcher( input, null, xml, results );
nicholas@926 1822 // Don't keep the element (issue #299)
nicholas@926 1823 input[0] = null;
nicholas@926 1824 return !results.pop();
nicholas@926 1825 };
nicholas@926 1826 }),
nicholas@926 1827
nicholas@926 1828 "has": markFunction(function( selector ) {
nicholas@926 1829 return function( elem ) {
nicholas@926 1830 return Sizzle( selector, elem ).length > 0;
nicholas@926 1831 };
nicholas@926 1832 }),
nicholas@926 1833
nicholas@926 1834 "contains": markFunction(function( text ) {
nicholas@926 1835 text = text.replace( runescape, funescape );
nicholas@926 1836 return function( elem ) {
nicholas@926 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nicholas@926 1838 };
nicholas@926 1839 }),
nicholas@926 1840
nicholas@926 1841 // "Whether an element is represented by a :lang() selector
nicholas@926 1842 // is based solely on the element's language value
nicholas@926 1843 // being equal to the identifier C,
nicholas@926 1844 // or beginning with the identifier C immediately followed by "-".
nicholas@926 1845 // The matching of C against the element's language value is performed case-insensitively.
nicholas@926 1846 // The identifier C does not have to be a valid language name."
nicholas@926 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nicholas@926 1848 "lang": markFunction( function( lang ) {
nicholas@926 1849 // lang value must be a valid identifier
nicholas@926 1850 if ( !ridentifier.test(lang || "") ) {
nicholas@926 1851 Sizzle.error( "unsupported lang: " + lang );
nicholas@926 1852 }
nicholas@926 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nicholas@926 1854 return function( elem ) {
nicholas@926 1855 var elemLang;
nicholas@926 1856 do {
nicholas@926 1857 if ( (elemLang = documentIsHTML ?
nicholas@926 1858 elem.lang :
nicholas@926 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nicholas@926 1860
nicholas@926 1861 elemLang = elemLang.toLowerCase();
nicholas@926 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nicholas@926 1863 }
nicholas@926 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nicholas@926 1865 return false;
nicholas@926 1866 };
nicholas@926 1867 }),
nicholas@926 1868
nicholas@926 1869 // Miscellaneous
nicholas@926 1870 "target": function( elem ) {
nicholas@926 1871 var hash = window.location && window.location.hash;
nicholas@926 1872 return hash && hash.slice( 1 ) === elem.id;
nicholas@926 1873 },
nicholas@926 1874
nicholas@926 1875 "root": function( elem ) {
nicholas@926 1876 return elem === docElem;
nicholas@926 1877 },
nicholas@926 1878
nicholas@926 1879 "focus": function( elem ) {
nicholas@926 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nicholas@926 1881 },
nicholas@926 1882
nicholas@926 1883 // Boolean properties
nicholas@926 1884 "enabled": function( elem ) {
nicholas@926 1885 return elem.disabled === false;
nicholas@926 1886 },
nicholas@926 1887
nicholas@926 1888 "disabled": function( elem ) {
nicholas@926 1889 return elem.disabled === true;
nicholas@926 1890 },
nicholas@926 1891
nicholas@926 1892 "checked": function( elem ) {
nicholas@926 1893 // In CSS3, :checked should return both checked and selected elements
nicholas@926 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nicholas@926 1895 var nodeName = elem.nodeName.toLowerCase();
nicholas@926 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nicholas@926 1897 },
nicholas@926 1898
nicholas@926 1899 "selected": function( elem ) {
nicholas@926 1900 // Accessing this property makes selected-by-default
nicholas@926 1901 // options in Safari work properly
nicholas@926 1902 if ( elem.parentNode ) {
nicholas@926 1903 elem.parentNode.selectedIndex;
nicholas@926 1904 }
nicholas@926 1905
nicholas@926 1906 return elem.selected === true;
nicholas@926 1907 },
nicholas@926 1908
nicholas@926 1909 // Contents
nicholas@926 1910 "empty": function( elem ) {
nicholas@926 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nicholas@926 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nicholas@926 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nicholas@926 1914 // nodeType < 6 works because attributes (2) do not appear as children
nicholas@926 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nicholas@926 1916 if ( elem.nodeType < 6 ) {
nicholas@926 1917 return false;
nicholas@926 1918 }
nicholas@926 1919 }
nicholas@926 1920 return true;
nicholas@926 1921 },
nicholas@926 1922
nicholas@926 1923 "parent": function( elem ) {
nicholas@926 1924 return !Expr.pseudos["empty"]( elem );
nicholas@926 1925 },
nicholas@926 1926
nicholas@926 1927 // Element/input types
nicholas@926 1928 "header": function( elem ) {
nicholas@926 1929 return rheader.test( elem.nodeName );
nicholas@926 1930 },
nicholas@926 1931
nicholas@926 1932 "input": function( elem ) {
nicholas@926 1933 return rinputs.test( elem.nodeName );
nicholas@926 1934 },
nicholas@926 1935
nicholas@926 1936 "button": function( elem ) {
nicholas@926 1937 var name = elem.nodeName.toLowerCase();
nicholas@926 1938 return name === "input" && elem.type === "button" || name === "button";
nicholas@926 1939 },
nicholas@926 1940
nicholas@926 1941 "text": function( elem ) {
nicholas@926 1942 var attr;
nicholas@926 1943 return elem.nodeName.toLowerCase() === "input" &&
nicholas@926 1944 elem.type === "text" &&
nicholas@926 1945
nicholas@926 1946 // Support: IE<8
nicholas@926 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nicholas@926 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nicholas@926 1949 },
nicholas@926 1950
nicholas@926 1951 // Position-in-collection
nicholas@926 1952 "first": createPositionalPseudo(function() {
nicholas@926 1953 return [ 0 ];
nicholas@926 1954 }),
nicholas@926 1955
nicholas@926 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@926 1957 return [ length - 1 ];
nicholas@926 1958 }),
nicholas@926 1959
nicholas@926 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@926 1961 return [ argument < 0 ? argument + length : argument ];
nicholas@926 1962 }),
nicholas@926 1963
nicholas@926 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@926 1965 var i = 0;
nicholas@926 1966 for ( ; i < length; i += 2 ) {
nicholas@926 1967 matchIndexes.push( i );
nicholas@926 1968 }
nicholas@926 1969 return matchIndexes;
nicholas@926 1970 }),
nicholas@926 1971
nicholas@926 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@926 1973 var i = 1;
nicholas@926 1974 for ( ; i < length; i += 2 ) {
nicholas@926 1975 matchIndexes.push( i );
nicholas@926 1976 }
nicholas@926 1977 return matchIndexes;
nicholas@926 1978 }),
nicholas@926 1979
nicholas@926 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@926 1981 var i = argument < 0 ? argument + length : argument;
nicholas@926 1982 for ( ; --i >= 0; ) {
nicholas@926 1983 matchIndexes.push( i );
nicholas@926 1984 }
nicholas@926 1985 return matchIndexes;
nicholas@926 1986 }),
nicholas@926 1987
nicholas@926 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@926 1989 var i = argument < 0 ? argument + length : argument;
nicholas@926 1990 for ( ; ++i < length; ) {
nicholas@926 1991 matchIndexes.push( i );
nicholas@926 1992 }
nicholas@926 1993 return matchIndexes;
nicholas@926 1994 })
nicholas@926 1995 }
nicholas@926 1996 };
nicholas@926 1997
nicholas@926 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nicholas@926 1999
nicholas@926 2000 // Add button/input type pseudos
nicholas@926 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nicholas@926 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nicholas@926 2003 }
nicholas@926 2004 for ( i in { submit: true, reset: true } ) {
nicholas@926 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nicholas@926 2006 }
nicholas@926 2007
nicholas@926 2008 // Easy API for creating new setFilters
nicholas@926 2009 function setFilters() {}
nicholas@926 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nicholas@926 2011 Expr.setFilters = new setFilters();
nicholas@926 2012
nicholas@926 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nicholas@926 2014 var matched, match, tokens, type,
nicholas@926 2015 soFar, groups, preFilters,
nicholas@926 2016 cached = tokenCache[ selector + " " ];
nicholas@926 2017
nicholas@926 2018 if ( cached ) {
nicholas@926 2019 return parseOnly ? 0 : cached.slice( 0 );
nicholas@926 2020 }
nicholas@926 2021
nicholas@926 2022 soFar = selector;
nicholas@926 2023 groups = [];
nicholas@926 2024 preFilters = Expr.preFilter;
nicholas@926 2025
nicholas@926 2026 while ( soFar ) {
nicholas@926 2027
nicholas@926 2028 // Comma and first run
nicholas@926 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nicholas@926 2030 if ( match ) {
nicholas@926 2031 // Don't consume trailing commas as valid
nicholas@926 2032 soFar = soFar.slice( match[0].length ) || soFar;
nicholas@926 2033 }
nicholas@926 2034 groups.push( (tokens = []) );
nicholas@926 2035 }
nicholas@926 2036
nicholas@926 2037 matched = false;
nicholas@926 2038
nicholas@926 2039 // Combinators
nicholas@926 2040 if ( (match = rcombinators.exec( soFar )) ) {
nicholas@926 2041 matched = match.shift();
nicholas@926 2042 tokens.push({
nicholas@926 2043 value: matched,
nicholas@926 2044 // Cast descendant combinators to space
nicholas@926 2045 type: match[0].replace( rtrim, " " )
nicholas@926 2046 });
nicholas@926 2047 soFar = soFar.slice( matched.length );
nicholas@926 2048 }
nicholas@926 2049
nicholas@926 2050 // Filters
nicholas@926 2051 for ( type in Expr.filter ) {
nicholas@926 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nicholas@926 2053 (match = preFilters[ type ]( match ))) ) {
nicholas@926 2054 matched = match.shift();
nicholas@926 2055 tokens.push({
nicholas@926 2056 value: matched,
nicholas@926 2057 type: type,
nicholas@926 2058 matches: match
nicholas@926 2059 });
nicholas@926 2060 soFar = soFar.slice( matched.length );
nicholas@926 2061 }
nicholas@926 2062 }
nicholas@926 2063
nicholas@926 2064 if ( !matched ) {
nicholas@926 2065 break;
nicholas@926 2066 }
nicholas@926 2067 }
nicholas@926 2068
nicholas@926 2069 // Return the length of the invalid excess
nicholas@926 2070 // if we're just parsing
nicholas@926 2071 // Otherwise, throw an error or return tokens
nicholas@926 2072 return parseOnly ?
nicholas@926 2073 soFar.length :
nicholas@926 2074 soFar ?
nicholas@926 2075 Sizzle.error( selector ) :
nicholas@926 2076 // Cache the tokens
nicholas@926 2077 tokenCache( selector, groups ).slice( 0 );
nicholas@926 2078 };
nicholas@926 2079
nicholas@926 2080 function toSelector( tokens ) {
nicholas@926 2081 var i = 0,
nicholas@926 2082 len = tokens.length,
nicholas@926 2083 selector = "";
nicholas@926 2084 for ( ; i < len; i++ ) {
nicholas@926 2085 selector += tokens[i].value;
nicholas@926 2086 }
nicholas@926 2087 return selector;
nicholas@926 2088 }
nicholas@926 2089
nicholas@926 2090 function addCombinator( matcher, combinator, base ) {
nicholas@926 2091 var dir = combinator.dir,
nicholas@926 2092 checkNonElements = base && dir === "parentNode",
nicholas@926 2093 doneName = done++;
nicholas@926 2094
nicholas@926 2095 return combinator.first ?
nicholas@926 2096 // Check against closest ancestor/preceding element
nicholas@926 2097 function( elem, context, xml ) {
nicholas@926 2098 while ( (elem = elem[ dir ]) ) {
nicholas@926 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@926 2100 return matcher( elem, context, xml );
nicholas@926 2101 }
nicholas@926 2102 }
nicholas@926 2103 } :
nicholas@926 2104
nicholas@926 2105 // Check against all ancestor/preceding elements
nicholas@926 2106 function( elem, context, xml ) {
nicholas@926 2107 var oldCache, outerCache,
nicholas@926 2108 newCache = [ dirruns, doneName ];
nicholas@926 2109
nicholas@926 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nicholas@926 2111 if ( xml ) {
nicholas@926 2112 while ( (elem = elem[ dir ]) ) {
nicholas@926 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@926 2114 if ( matcher( elem, context, xml ) ) {
nicholas@926 2115 return true;
nicholas@926 2116 }
nicholas@926 2117 }
nicholas@926 2118 }
nicholas@926 2119 } else {
nicholas@926 2120 while ( (elem = elem[ dir ]) ) {
nicholas@926 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@926 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nicholas@926 2123 if ( (oldCache = outerCache[ dir ]) &&
nicholas@926 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nicholas@926 2125
nicholas@926 2126 // Assign to newCache so results back-propagate to previous elements
nicholas@926 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nicholas@926 2128 } else {
nicholas@926 2129 // Reuse newcache so results back-propagate to previous elements
nicholas@926 2130 outerCache[ dir ] = newCache;
nicholas@926 2131
nicholas@926 2132 // A match means we're done; a fail means we have to keep checking
nicholas@926 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nicholas@926 2134 return true;
nicholas@926 2135 }
nicholas@926 2136 }
nicholas@926 2137 }
nicholas@926 2138 }
nicholas@926 2139 }
nicholas@926 2140 };
nicholas@926 2141 }
nicholas@926 2142
nicholas@926 2143 function elementMatcher( matchers ) {
nicholas@926 2144 return matchers.length > 1 ?
nicholas@926 2145 function( elem, context, xml ) {
nicholas@926 2146 var i = matchers.length;
nicholas@926 2147 while ( i-- ) {
nicholas@926 2148 if ( !matchers[i]( elem, context, xml ) ) {
nicholas@926 2149 return false;
nicholas@926 2150 }
nicholas@926 2151 }
nicholas@926 2152 return true;
nicholas@926 2153 } :
nicholas@926 2154 matchers[0];
nicholas@926 2155 }
nicholas@926 2156
nicholas@926 2157 function multipleContexts( selector, contexts, results ) {
nicholas@926 2158 var i = 0,
nicholas@926 2159 len = contexts.length;
nicholas@926 2160 for ( ; i < len; i++ ) {
nicholas@926 2161 Sizzle( selector, contexts[i], results );
nicholas@926 2162 }
nicholas@926 2163 return results;
nicholas@926 2164 }
nicholas@926 2165
nicholas@926 2166 function condense( unmatched, map, filter, context, xml ) {
nicholas@926 2167 var elem,
nicholas@926 2168 newUnmatched = [],
nicholas@926 2169 i = 0,
nicholas@926 2170 len = unmatched.length,
nicholas@926 2171 mapped = map != null;
nicholas@926 2172
nicholas@926 2173 for ( ; i < len; i++ ) {
nicholas@926 2174 if ( (elem = unmatched[i]) ) {
nicholas@926 2175 if ( !filter || filter( elem, context, xml ) ) {
nicholas@926 2176 newUnmatched.push( elem );
nicholas@926 2177 if ( mapped ) {
nicholas@926 2178 map.push( i );
nicholas@926 2179 }
nicholas@926 2180 }
nicholas@926 2181 }
nicholas@926 2182 }
nicholas@926 2183
nicholas@926 2184 return newUnmatched;
nicholas@926 2185 }
nicholas@926 2186
nicholas@926 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nicholas@926 2188 if ( postFilter && !postFilter[ expando ] ) {
nicholas@926 2189 postFilter = setMatcher( postFilter );
nicholas@926 2190 }
nicholas@926 2191 if ( postFinder && !postFinder[ expando ] ) {
nicholas@926 2192 postFinder = setMatcher( postFinder, postSelector );
nicholas@926 2193 }
nicholas@926 2194 return markFunction(function( seed, results, context, xml ) {
nicholas@926 2195 var temp, i, elem,
nicholas@926 2196 preMap = [],
nicholas@926 2197 postMap = [],
nicholas@926 2198 preexisting = results.length,
nicholas@926 2199
nicholas@926 2200 // Get initial elements from seed or context
nicholas@926 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nicholas@926 2202
nicholas@926 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nicholas@926 2204 matcherIn = preFilter && ( seed || !selector ) ?
nicholas@926 2205 condense( elems, preMap, preFilter, context, xml ) :
nicholas@926 2206 elems,
nicholas@926 2207
nicholas@926 2208 matcherOut = matcher ?
nicholas@926 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nicholas@926 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nicholas@926 2211
nicholas@926 2212 // ...intermediate processing is necessary
nicholas@926 2213 [] :
nicholas@926 2214
nicholas@926 2215 // ...otherwise use results directly
nicholas@926 2216 results :
nicholas@926 2217 matcherIn;
nicholas@926 2218
nicholas@926 2219 // Find primary matches
nicholas@926 2220 if ( matcher ) {
nicholas@926 2221 matcher( matcherIn, matcherOut, context, xml );
nicholas@926 2222 }
nicholas@926 2223
nicholas@926 2224 // Apply postFilter
nicholas@926 2225 if ( postFilter ) {
nicholas@926 2226 temp = condense( matcherOut, postMap );
nicholas@926 2227 postFilter( temp, [], context, xml );
nicholas@926 2228
nicholas@926 2229 // Un-match failing elements by moving them back to matcherIn
nicholas@926 2230 i = temp.length;
nicholas@926 2231 while ( i-- ) {
nicholas@926 2232 if ( (elem = temp[i]) ) {
nicholas@926 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nicholas@926 2234 }
nicholas@926 2235 }
nicholas@926 2236 }
nicholas@926 2237
nicholas@926 2238 if ( seed ) {
nicholas@926 2239 if ( postFinder || preFilter ) {
nicholas@926 2240 if ( postFinder ) {
nicholas@926 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nicholas@926 2242 temp = [];
nicholas@926 2243 i = matcherOut.length;
nicholas@926 2244 while ( i-- ) {
nicholas@926 2245 if ( (elem = matcherOut[i]) ) {
nicholas@926 2246 // Restore matcherIn since elem is not yet a final match
nicholas@926 2247 temp.push( (matcherIn[i] = elem) );
nicholas@926 2248 }
nicholas@926 2249 }
nicholas@926 2250 postFinder( null, (matcherOut = []), temp, xml );
nicholas@926 2251 }
nicholas@926 2252
nicholas@926 2253 // Move matched elements from seed to results to keep them synchronized
nicholas@926 2254 i = matcherOut.length;
nicholas@926 2255 while ( i-- ) {
nicholas@926 2256 if ( (elem = matcherOut[i]) &&
nicholas@926 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nicholas@926 2258
nicholas@926 2259 seed[temp] = !(results[temp] = elem);
nicholas@926 2260 }
nicholas@926 2261 }
nicholas@926 2262 }
nicholas@926 2263
nicholas@926 2264 // Add elements to results, through postFinder if defined
nicholas@926 2265 } else {
nicholas@926 2266 matcherOut = condense(
nicholas@926 2267 matcherOut === results ?
nicholas@926 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nicholas@926 2269 matcherOut
nicholas@926 2270 );
nicholas@926 2271 if ( postFinder ) {
nicholas@926 2272 postFinder( null, results, matcherOut, xml );
nicholas@926 2273 } else {
nicholas@926 2274 push.apply( results, matcherOut );
nicholas@926 2275 }
nicholas@926 2276 }
nicholas@926 2277 });
nicholas@926 2278 }
nicholas@926 2279
nicholas@926 2280 function matcherFromTokens( tokens ) {
nicholas@926 2281 var checkContext, matcher, j,
nicholas@926 2282 len = tokens.length,
nicholas@926 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nicholas@926 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nicholas@926 2285 i = leadingRelative ? 1 : 0,
nicholas@926 2286
nicholas@926 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nicholas@926 2288 matchContext = addCombinator( function( elem ) {
nicholas@926 2289 return elem === checkContext;
nicholas@926 2290 }, implicitRelative, true ),
nicholas@926 2291 matchAnyContext = addCombinator( function( elem ) {
nicholas@926 2292 return indexOf( checkContext, elem ) > -1;
nicholas@926 2293 }, implicitRelative, true ),
nicholas@926 2294 matchers = [ function( elem, context, xml ) {
nicholas@926 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nicholas@926 2296 (checkContext = context).nodeType ?
nicholas@926 2297 matchContext( elem, context, xml ) :
nicholas@926 2298 matchAnyContext( elem, context, xml ) );
nicholas@926 2299 // Avoid hanging onto element (issue #299)
nicholas@926 2300 checkContext = null;
nicholas@926 2301 return ret;
nicholas@926 2302 } ];
nicholas@926 2303
nicholas@926 2304 for ( ; i < len; i++ ) {
nicholas@926 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nicholas@926 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nicholas@926 2307 } else {
nicholas@926 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nicholas@926 2309
nicholas@926 2310 // Return special upon seeing a positional matcher
nicholas@926 2311 if ( matcher[ expando ] ) {
nicholas@926 2312 // Find the next relative operator (if any) for proper handling
nicholas@926 2313 j = ++i;
nicholas@926 2314 for ( ; j < len; j++ ) {
nicholas@926 2315 if ( Expr.relative[ tokens[j].type ] ) {
nicholas@926 2316 break;
nicholas@926 2317 }
nicholas@926 2318 }
nicholas@926 2319 return setMatcher(
nicholas@926 2320 i > 1 && elementMatcher( matchers ),
nicholas@926 2321 i > 1 && toSelector(
nicholas@926 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nicholas@926 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nicholas@926 2324 ).replace( rtrim, "$1" ),
nicholas@926 2325 matcher,
nicholas@926 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nicholas@926 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nicholas@926 2328 j < len && toSelector( tokens )
nicholas@926 2329 );
nicholas@926 2330 }
nicholas@926 2331 matchers.push( matcher );
nicholas@926 2332 }
nicholas@926 2333 }
nicholas@926 2334
nicholas@926 2335 return elementMatcher( matchers );
nicholas@926 2336 }
nicholas@926 2337
nicholas@926 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nicholas@926 2339 var bySet = setMatchers.length > 0,
nicholas@926 2340 byElement = elementMatchers.length > 0,
nicholas@926 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nicholas@926 2342 var elem, j, matcher,
nicholas@926 2343 matchedCount = 0,
nicholas@926 2344 i = "0",
nicholas@926 2345 unmatched = seed && [],
nicholas@926 2346 setMatched = [],
nicholas@926 2347 contextBackup = outermostContext,
nicholas@926 2348 // We must always have either seed elements or outermost context
nicholas@926 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nicholas@926 2350 // Use integer dirruns iff this is the outermost matcher
nicholas@926 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nicholas@926 2352 len = elems.length;
nicholas@926 2353
nicholas@926 2354 if ( outermost ) {
nicholas@926 2355 outermostContext = context !== document && context;
nicholas@926 2356 }
nicholas@926 2357
nicholas@926 2358 // Add elements passing elementMatchers directly to results
nicholas@926 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nicholas@926 2360 // Support: IE<9, Safari
nicholas@926 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nicholas@926 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nicholas@926 2363 if ( byElement && elem ) {
nicholas@926 2364 j = 0;
nicholas@926 2365 while ( (matcher = elementMatchers[j++]) ) {
nicholas@926 2366 if ( matcher( elem, context, xml ) ) {
nicholas@926 2367 results.push( elem );
nicholas@926 2368 break;
nicholas@926 2369 }
nicholas@926 2370 }
nicholas@926 2371 if ( outermost ) {
nicholas@926 2372 dirruns = dirrunsUnique;
nicholas@926 2373 }
nicholas@926 2374 }
nicholas@926 2375
nicholas@926 2376 // Track unmatched elements for set filters
nicholas@926 2377 if ( bySet ) {
nicholas@926 2378 // They will have gone through all possible matchers
nicholas@926 2379 if ( (elem = !matcher && elem) ) {
nicholas@926 2380 matchedCount--;
nicholas@926 2381 }
nicholas@926 2382
nicholas@926 2383 // Lengthen the array for every element, matched or not
nicholas@926 2384 if ( seed ) {
nicholas@926 2385 unmatched.push( elem );
nicholas@926 2386 }
nicholas@926 2387 }
nicholas@926 2388 }
nicholas@926 2389
nicholas@926 2390 // Apply set filters to unmatched elements
nicholas@926 2391 matchedCount += i;
nicholas@926 2392 if ( bySet && i !== matchedCount ) {
nicholas@926 2393 j = 0;
nicholas@926 2394 while ( (matcher = setMatchers[j++]) ) {
nicholas@926 2395 matcher( unmatched, setMatched, context, xml );
nicholas@926 2396 }
nicholas@926 2397
nicholas@926 2398 if ( seed ) {
nicholas@926 2399 // Reintegrate element matches to eliminate the need for sorting
nicholas@926 2400 if ( matchedCount > 0 ) {
nicholas@926 2401 while ( i-- ) {
nicholas@926 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nicholas@926 2403 setMatched[i] = pop.call( results );
nicholas@926 2404 }
nicholas@926 2405 }
nicholas@926 2406 }
nicholas@926 2407
nicholas@926 2408 // Discard index placeholder values to get only actual matches
nicholas@926 2409 setMatched = condense( setMatched );
nicholas@926 2410 }
nicholas@926 2411
nicholas@926 2412 // Add matches to results
nicholas@926 2413 push.apply( results, setMatched );
nicholas@926 2414
nicholas@926 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nicholas@926 2416 if ( outermost && !seed && setMatched.length > 0 &&
nicholas@926 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nicholas@926 2418
nicholas@926 2419 Sizzle.uniqueSort( results );
nicholas@926 2420 }
nicholas@926 2421 }
nicholas@926 2422
nicholas@926 2423 // Override manipulation of globals by nested matchers
nicholas@926 2424 if ( outermost ) {
nicholas@926 2425 dirruns = dirrunsUnique;
nicholas@926 2426 outermostContext = contextBackup;
nicholas@926 2427 }
nicholas@926 2428
nicholas@926 2429 return unmatched;
nicholas@926 2430 };
nicholas@926 2431
nicholas@926 2432 return bySet ?
nicholas@926 2433 markFunction( superMatcher ) :
nicholas@926 2434 superMatcher;
nicholas@926 2435 }
nicholas@926 2436
nicholas@926 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nicholas@926 2438 var i,
nicholas@926 2439 setMatchers = [],
nicholas@926 2440 elementMatchers = [],
nicholas@926 2441 cached = compilerCache[ selector + " " ];
nicholas@926 2442
nicholas@926 2443 if ( !cached ) {
nicholas@926 2444 // Generate a function of recursive functions that can be used to check each element
nicholas@926 2445 if ( !match ) {
nicholas@926 2446 match = tokenize( selector );
nicholas@926 2447 }
nicholas@926 2448 i = match.length;
nicholas@926 2449 while ( i-- ) {
nicholas@926 2450 cached = matcherFromTokens( match[i] );
nicholas@926 2451 if ( cached[ expando ] ) {
nicholas@926 2452 setMatchers.push( cached );
nicholas@926 2453 } else {
nicholas@926 2454 elementMatchers.push( cached );
nicholas@926 2455 }
nicholas@926 2456 }
nicholas@926 2457
nicholas@926 2458 // Cache the compiled function
nicholas@926 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nicholas@926 2460
nicholas@926 2461 // Save selector and tokenization
nicholas@926 2462 cached.selector = selector;
nicholas@926 2463 }
nicholas@926 2464 return cached;
nicholas@926 2465 };
nicholas@926 2466
nicholas@926 2467 /**
nicholas@926 2468 * A low-level selection function that works with Sizzle's compiled
nicholas@926 2469 * selector functions
nicholas@926 2470 * @param {String|Function} selector A selector or a pre-compiled
nicholas@926 2471 * selector function built with Sizzle.compile
nicholas@926 2472 * @param {Element} context
nicholas@926 2473 * @param {Array} [results]
nicholas@926 2474 * @param {Array} [seed] A set of elements to match against
nicholas@926 2475 */
nicholas@926 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nicholas@926 2477 var i, tokens, token, type, find,
nicholas@926 2478 compiled = typeof selector === "function" && selector,
nicholas@926 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nicholas@926 2480
nicholas@926 2481 results = results || [];
nicholas@926 2482
nicholas@926 2483 // Try to minimize operations if there is no seed and only one group
nicholas@926 2484 if ( match.length === 1 ) {
nicholas@926 2485
nicholas@926 2486 // Take a shortcut and set the context if the root selector is an ID
nicholas@926 2487 tokens = match[0] = match[0].slice( 0 );
nicholas@926 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nicholas@926 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nicholas@926 2490 Expr.relative[ tokens[1].type ] ) {
nicholas@926 2491
nicholas@926 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nicholas@926 2493 if ( !context ) {
nicholas@926 2494 return results;
nicholas@926 2495
nicholas@926 2496 // Precompiled matchers will still verify ancestry, so step up a level
nicholas@926 2497 } else if ( compiled ) {
nicholas@926 2498 context = context.parentNode;
nicholas@926 2499 }
nicholas@926 2500
nicholas@926 2501 selector = selector.slice( tokens.shift().value.length );
nicholas@926 2502 }
nicholas@926 2503
nicholas@926 2504 // Fetch a seed set for right-to-left matching
nicholas@926 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nicholas@926 2506 while ( i-- ) {
nicholas@926 2507 token = tokens[i];
nicholas@926 2508
nicholas@926 2509 // Abort if we hit a combinator
nicholas@926 2510 if ( Expr.relative[ (type = token.type) ] ) {
nicholas@926 2511 break;
nicholas@926 2512 }
nicholas@926 2513 if ( (find = Expr.find[ type ]) ) {
nicholas@926 2514 // Search, expanding context for leading sibling combinators
nicholas@926 2515 if ( (seed = find(
nicholas@926 2516 token.matches[0].replace( runescape, funescape ),
nicholas@926 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nicholas@926 2518 )) ) {
nicholas@926 2519
nicholas@926 2520 // If seed is empty or no tokens remain, we can return early
nicholas@926 2521 tokens.splice( i, 1 );
nicholas@926 2522 selector = seed.length && toSelector( tokens );
nicholas@926 2523 if ( !selector ) {
nicholas@926 2524 push.apply( results, seed );
nicholas@926 2525 return results;
nicholas@926 2526 }
nicholas@926 2527
nicholas@926 2528 break;
nicholas@926 2529 }
nicholas@926 2530 }
nicholas@926 2531 }
nicholas@926 2532 }
nicholas@926 2533
nicholas@926 2534 // Compile and execute a filtering function if one is not provided
nicholas@926 2535 // Provide `match` to avoid retokenization if we modified the selector above
nicholas@926 2536 ( compiled || compile( selector, match ) )(
nicholas@926 2537 seed,
nicholas@926 2538 context,
nicholas@926 2539 !documentIsHTML,
nicholas@926 2540 results,
nicholas@926 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nicholas@926 2542 );
nicholas@926 2543 return results;
nicholas@926 2544 };
nicholas@926 2545
nicholas@926 2546 // One-time assignments
nicholas@926 2547
nicholas@926 2548 // Sort stability
nicholas@926 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nicholas@926 2550
nicholas@926 2551 // Support: Chrome 14-35+
nicholas@926 2552 // Always assume duplicates if they aren't passed to the comparison function
nicholas@926 2553 support.detectDuplicates = !!hasDuplicate;
nicholas@926 2554
nicholas@926 2555 // Initialize against the default document
nicholas@926 2556 setDocument();
nicholas@926 2557
nicholas@926 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nicholas@926 2559 // Detached nodes confoundingly follow *each other*
nicholas@926 2560 support.sortDetached = assert(function( div1 ) {
nicholas@926 2561 // Should return 1, but returns 4 (following)
nicholas@926 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nicholas@926 2563 });
nicholas@926 2564
nicholas@926 2565 // Support: IE<8
nicholas@926 2566 // Prevent attribute/property "interpolation"
nicholas@926 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nicholas@926 2568 if ( !assert(function( div ) {
nicholas@926 2569 div.innerHTML = "<a href='#'></a>";
nicholas@926 2570 return div.firstChild.getAttribute("href") === "#" ;
nicholas@926 2571 }) ) {
nicholas@926 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nicholas@926 2573 if ( !isXML ) {
nicholas@926 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nicholas@926 2575 }
nicholas@926 2576 });
nicholas@926 2577 }
nicholas@926 2578
nicholas@926 2579 // Support: IE<9
nicholas@926 2580 // Use defaultValue in place of getAttribute("value")
nicholas@926 2581 if ( !support.attributes || !assert(function( div ) {
nicholas@926 2582 div.innerHTML = "<input/>";
nicholas@926 2583 div.firstChild.setAttribute( "value", "" );
nicholas@926 2584 return div.firstChild.getAttribute( "value" ) === "";
nicholas@926 2585 }) ) {
nicholas@926 2586 addHandle( "value", function( elem, name, isXML ) {
nicholas@926 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nicholas@926 2588 return elem.defaultValue;
nicholas@926 2589 }
nicholas@926 2590 });
nicholas@926 2591 }
nicholas@926 2592
nicholas@926 2593 // Support: IE<9
nicholas@926 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nicholas@926 2595 if ( !assert(function( div ) {
nicholas@926 2596 return div.getAttribute("disabled") == null;
nicholas@926 2597 }) ) {
nicholas@926 2598 addHandle( booleans, function( elem, name, isXML ) {
nicholas@926 2599 var val;
nicholas@926 2600 if ( !isXML ) {
nicholas@926 2601 return elem[ name ] === true ? name.toLowerCase() :
nicholas@926 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nicholas@926 2603 val.value :
nicholas@926 2604 null;
nicholas@926 2605 }
nicholas@926 2606 });
nicholas@926 2607 }
nicholas@926 2608
nicholas@926 2609 return Sizzle;
nicholas@926 2610
nicholas@926 2611 })( window );
nicholas@926 2612
nicholas@926 2613
nicholas@926 2614
nicholas@926 2615 jQuery.find = Sizzle;
nicholas@926 2616 jQuery.expr = Sizzle.selectors;
nicholas@926 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nicholas@926 2618 jQuery.unique = Sizzle.uniqueSort;
nicholas@926 2619 jQuery.text = Sizzle.getText;
nicholas@926 2620 jQuery.isXMLDoc = Sizzle.isXML;
nicholas@926 2621 jQuery.contains = Sizzle.contains;
nicholas@926 2622
nicholas@926 2623
nicholas@926 2624
nicholas@926 2625 var rneedsContext = jQuery.expr.match.needsContext;
nicholas@926 2626
nicholas@926 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nicholas@926 2628
nicholas@926 2629
nicholas@926 2630
nicholas@926 2631 var risSimple = /^.[^:#\[\.,]*$/;
nicholas@926 2632
nicholas@926 2633 // Implement the identical functionality for filter and not
nicholas@926 2634 function winnow( elements, qualifier, not ) {
nicholas@926 2635 if ( jQuery.isFunction( qualifier ) ) {
nicholas@926 2636 return jQuery.grep( elements, function( elem, i ) {
nicholas@926 2637 /* jshint -W018 */
nicholas@926 2638 return !!qualifier.call( elem, i, elem ) !== not;
nicholas@926 2639 });
nicholas@926 2640
nicholas@926 2641 }
nicholas@926 2642
nicholas@926 2643 if ( qualifier.nodeType ) {
nicholas@926 2644 return jQuery.grep( elements, function( elem ) {
nicholas@926 2645 return ( elem === qualifier ) !== not;
nicholas@926 2646 });
nicholas@926 2647
nicholas@926 2648 }
nicholas@926 2649
nicholas@926 2650 if ( typeof qualifier === "string" ) {
nicholas@926 2651 if ( risSimple.test( qualifier ) ) {
nicholas@926 2652 return jQuery.filter( qualifier, elements, not );
nicholas@926 2653 }
nicholas@926 2654
nicholas@926 2655 qualifier = jQuery.filter( qualifier, elements );
nicholas@926 2656 }
nicholas@926 2657
nicholas@926 2658 return jQuery.grep( elements, function( elem ) {
nicholas@926 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nicholas@926 2660 });
nicholas@926 2661 }
nicholas@926 2662
nicholas@926 2663 jQuery.filter = function( expr, elems, not ) {
nicholas@926 2664 var elem = elems[ 0 ];
nicholas@926 2665
nicholas@926 2666 if ( not ) {
nicholas@926 2667 expr = ":not(" + expr + ")";
nicholas@926 2668 }
nicholas@926 2669
nicholas@926 2670 return elems.length === 1 && elem.nodeType === 1 ?
nicholas@926 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nicholas@926 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nicholas@926 2673 return elem.nodeType === 1;
nicholas@926 2674 }));
nicholas@926 2675 };
nicholas@926 2676
nicholas@926 2677 jQuery.fn.extend({
nicholas@926 2678 find: function( selector ) {
nicholas@926 2679 var i,
nicholas@926 2680 len = this.length,
nicholas@926 2681 ret = [],
nicholas@926 2682 self = this;
nicholas@926 2683
nicholas@926 2684 if ( typeof selector !== "string" ) {
nicholas@926 2685 return this.pushStack( jQuery( selector ).filter(function() {
nicholas@926 2686 for ( i = 0; i < len; i++ ) {
nicholas@926 2687 if ( jQuery.contains( self[ i ], this ) ) {
nicholas@926 2688 return true;
nicholas@926 2689 }
nicholas@926 2690 }
nicholas@926 2691 }) );
nicholas@926 2692 }
nicholas@926 2693
nicholas@926 2694 for ( i = 0; i < len; i++ ) {
nicholas@926 2695 jQuery.find( selector, self[ i ], ret );
nicholas@926 2696 }
nicholas@926 2697
nicholas@926 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nicholas@926 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nicholas@926 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nicholas@926 2701 return ret;
nicholas@926 2702 },
nicholas@926 2703 filter: function( selector ) {
nicholas@926 2704 return this.pushStack( winnow(this, selector || [], false) );
nicholas@926 2705 },
nicholas@926 2706 not: function( selector ) {
nicholas@926 2707 return this.pushStack( winnow(this, selector || [], true) );
nicholas@926 2708 },
nicholas@926 2709 is: function( selector ) {
nicholas@926 2710 return !!winnow(
nicholas@926 2711 this,
nicholas@926 2712
nicholas@926 2713 // If this is a positional/relative selector, check membership in the returned set
nicholas@926 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nicholas@926 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nicholas@926 2716 jQuery( selector ) :
nicholas@926 2717 selector || [],
nicholas@926 2718 false
nicholas@926 2719 ).length;
nicholas@926 2720 }
nicholas@926 2721 });
nicholas@926 2722
nicholas@926 2723
nicholas@926 2724 // Initialize a jQuery object
nicholas@926 2725
nicholas@926 2726
nicholas@926 2727 // A central reference to the root jQuery(document)
nicholas@926 2728 var rootjQuery,
nicholas@926 2729
nicholas@926 2730 // A simple way to check for HTML strings
nicholas@926 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nicholas@926 2732 // Strict HTML recognition (#11290: must start with <)
nicholas@926 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nicholas@926 2734
nicholas@926 2735 init = jQuery.fn.init = function( selector, context ) {
nicholas@926 2736 var match, elem;
nicholas@926 2737
nicholas@926 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nicholas@926 2739 if ( !selector ) {
nicholas@926 2740 return this;
nicholas@926 2741 }
nicholas@926 2742
nicholas@926 2743 // Handle HTML strings
nicholas@926 2744 if ( typeof selector === "string" ) {
nicholas@926 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nicholas@926 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nicholas@926 2747 match = [ null, selector, null ];
nicholas@926 2748
nicholas@926 2749 } else {
nicholas@926 2750 match = rquickExpr.exec( selector );
nicholas@926 2751 }
nicholas@926 2752
nicholas@926 2753 // Match html or make sure no context is specified for #id
nicholas@926 2754 if ( match && (match[1] || !context) ) {
nicholas@926 2755
nicholas@926 2756 // HANDLE: $(html) -> $(array)
nicholas@926 2757 if ( match[1] ) {
nicholas@926 2758 context = context instanceof jQuery ? context[0] : context;
nicholas@926 2759
nicholas@926 2760 // Option to run scripts is true for back-compat
nicholas@926 2761 // Intentionally let the error be thrown if parseHTML is not present
nicholas@926 2762 jQuery.merge( this, jQuery.parseHTML(
nicholas@926 2763 match[1],
nicholas@926 2764 context && context.nodeType ? context.ownerDocument || context : document,
nicholas@926 2765 true
nicholas@926 2766 ) );
nicholas@926 2767
nicholas@926 2768 // HANDLE: $(html, props)
nicholas@926 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nicholas@926 2770 for ( match in context ) {
nicholas@926 2771 // Properties of context are called as methods if possible
nicholas@926 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nicholas@926 2773 this[ match ]( context[ match ] );
nicholas@926 2774
nicholas@926 2775 // ...and otherwise set as attributes
nicholas@926 2776 } else {
nicholas@926 2777 this.attr( match, context[ match ] );
nicholas@926 2778 }
nicholas@926 2779 }
nicholas@926 2780 }
nicholas@926 2781
nicholas@926 2782 return this;
nicholas@926 2783
nicholas@926 2784 // HANDLE: $(#id)
nicholas@926 2785 } else {
nicholas@926 2786 elem = document.getElementById( match[2] );
nicholas@926 2787
nicholas@926 2788 // Support: Blackberry 4.6
nicholas@926 2789 // gEBID returns nodes no longer in the document (#6963)
nicholas@926 2790 if ( elem && elem.parentNode ) {
nicholas@926 2791 // Inject the element directly into the jQuery object
nicholas@926 2792 this.length = 1;
nicholas@926 2793 this[0] = elem;
nicholas@926 2794 }
nicholas@926 2795
nicholas@926 2796 this.context = document;
nicholas@926 2797 this.selector = selector;
nicholas@926 2798 return this;
nicholas@926 2799 }
nicholas@926 2800
nicholas@926 2801 // HANDLE: $(expr, $(...))
nicholas@926 2802 } else if ( !context || context.jquery ) {
nicholas@926 2803 return ( context || rootjQuery ).find( selector );
nicholas@926 2804
nicholas@926 2805 // HANDLE: $(expr, context)
nicholas@926 2806 // (which is just equivalent to: $(context).find(expr)
nicholas@926 2807 } else {
nicholas@926 2808 return this.constructor( context ).find( selector );
nicholas@926 2809 }
nicholas@926 2810
nicholas@926 2811 // HANDLE: $(DOMElement)
nicholas@926 2812 } else if ( selector.nodeType ) {
nicholas@926 2813 this.context = this[0] = selector;
nicholas@926 2814 this.length = 1;
nicholas@926 2815 return this;
nicholas@926 2816
nicholas@926 2817 // HANDLE: $(function)
nicholas@926 2818 // Shortcut for document ready
nicholas@926 2819 } else if ( jQuery.isFunction( selector ) ) {
nicholas@926 2820 return typeof rootjQuery.ready !== "undefined" ?
nicholas@926 2821 rootjQuery.ready( selector ) :
nicholas@926 2822 // Execute immediately if ready is not present
nicholas@926 2823 selector( jQuery );
nicholas@926 2824 }
nicholas@926 2825
nicholas@926 2826 if ( selector.selector !== undefined ) {
nicholas@926 2827 this.selector = selector.selector;
nicholas@926 2828 this.context = selector.context;
nicholas@926 2829 }
nicholas@926 2830
nicholas@926 2831 return jQuery.makeArray( selector, this );
nicholas@926 2832 };
nicholas@926 2833
nicholas@926 2834 // Give the init function the jQuery prototype for later instantiation
nicholas@926 2835 init.prototype = jQuery.fn;
nicholas@926 2836
nicholas@926 2837 // Initialize central reference
nicholas@926 2838 rootjQuery = jQuery( document );
nicholas@926 2839
nicholas@926 2840
nicholas@926 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nicholas@926 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nicholas@926 2843 guaranteedUnique = {
nicholas@926 2844 children: true,
nicholas@926 2845 contents: true,
nicholas@926 2846 next: true,
nicholas@926 2847 prev: true
nicholas@926 2848 };
nicholas@926 2849
nicholas@926 2850 jQuery.extend({
nicholas@926 2851 dir: function( elem, dir, until ) {
nicholas@926 2852 var matched = [],
nicholas@926 2853 truncate = until !== undefined;
nicholas@926 2854
nicholas@926 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nicholas@926 2856 if ( elem.nodeType === 1 ) {
nicholas@926 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nicholas@926 2858 break;
nicholas@926 2859 }
nicholas@926 2860 matched.push( elem );
nicholas@926 2861 }
nicholas@926 2862 }
nicholas@926 2863 return matched;
nicholas@926 2864 },
nicholas@926 2865
nicholas@926 2866 sibling: function( n, elem ) {
nicholas@926 2867 var matched = [];
nicholas@926 2868
nicholas@926 2869 for ( ; n; n = n.nextSibling ) {
nicholas@926 2870 if ( n.nodeType === 1 && n !== elem ) {
nicholas@926 2871 matched.push( n );
nicholas@926 2872 }
nicholas@926 2873 }
nicholas@926 2874
nicholas@926 2875 return matched;
nicholas@926 2876 }
nicholas@926 2877 });
nicholas@926 2878
nicholas@926 2879 jQuery.fn.extend({
nicholas@926 2880 has: function( target ) {
nicholas@926 2881 var targets = jQuery( target, this ),
nicholas@926 2882 l = targets.length;
nicholas@926 2883
nicholas@926 2884 return this.filter(function() {
nicholas@926 2885 var i = 0;
nicholas@926 2886 for ( ; i < l; i++ ) {
nicholas@926 2887 if ( jQuery.contains( this, targets[i] ) ) {
nicholas@926 2888 return true;
nicholas@926 2889 }
nicholas@926 2890 }
nicholas@926 2891 });
nicholas@926 2892 },
nicholas@926 2893
nicholas@926 2894 closest: function( selectors, context ) {
nicholas@926 2895 var cur,
nicholas@926 2896 i = 0,
nicholas@926 2897 l = this.length,
nicholas@926 2898 matched = [],
nicholas@926 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nicholas@926 2900 jQuery( selectors, context || this.context ) :
nicholas@926 2901 0;
nicholas@926 2902
nicholas@926 2903 for ( ; i < l; i++ ) {
nicholas@926 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nicholas@926 2905 // Always skip document fragments
nicholas@926 2906 if ( cur.nodeType < 11 && (pos ?
nicholas@926 2907 pos.index(cur) > -1 :
nicholas@926 2908
nicholas@926 2909 // Don't pass non-elements to Sizzle
nicholas@926 2910 cur.nodeType === 1 &&
nicholas@926 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nicholas@926 2912
nicholas@926 2913 matched.push( cur );
nicholas@926 2914 break;
nicholas@926 2915 }
nicholas@926 2916 }
nicholas@926 2917 }
nicholas@926 2918
nicholas@926 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nicholas@926 2920 },
nicholas@926 2921
nicholas@926 2922 // Determine the position of an element within the set
nicholas@926 2923 index: function( elem ) {
nicholas@926 2924
nicholas@926 2925 // No argument, return index in parent
nicholas@926 2926 if ( !elem ) {
nicholas@926 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nicholas@926 2928 }
nicholas@926 2929
nicholas@926 2930 // Index in selector
nicholas@926 2931 if ( typeof elem === "string" ) {
nicholas@926 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nicholas@926 2933 }
nicholas@926 2934
nicholas@926 2935 // Locate the position of the desired element
nicholas@926 2936 return indexOf.call( this,
nicholas@926 2937
nicholas@926 2938 // If it receives a jQuery object, the first element is used
nicholas@926 2939 elem.jquery ? elem[ 0 ] : elem
nicholas@926 2940 );
nicholas@926 2941 },
nicholas@926 2942
nicholas@926 2943 add: function( selector, context ) {
nicholas@926 2944 return this.pushStack(
nicholas@926 2945 jQuery.unique(
nicholas@926 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nicholas@926 2947 )
nicholas@926 2948 );
nicholas@926 2949 },
nicholas@926 2950
nicholas@926 2951 addBack: function( selector ) {
nicholas@926 2952 return this.add( selector == null ?
nicholas@926 2953 this.prevObject : this.prevObject.filter(selector)
nicholas@926 2954 );
nicholas@926 2955 }
nicholas@926 2956 });
nicholas@926 2957
nicholas@926 2958 function sibling( cur, dir ) {
nicholas@926 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nicholas@926 2960 return cur;
nicholas@926 2961 }
nicholas@926 2962
nicholas@926 2963 jQuery.each({
nicholas@926 2964 parent: function( elem ) {
nicholas@926 2965 var parent = elem.parentNode;
nicholas@926 2966 return parent && parent.nodeType !== 11 ? parent : null;
nicholas@926 2967 },
nicholas@926 2968 parents: function( elem ) {
nicholas@926 2969 return jQuery.dir( elem, "parentNode" );
nicholas@926 2970 },
nicholas@926 2971 parentsUntil: function( elem, i, until ) {
nicholas@926 2972 return jQuery.dir( elem, "parentNode", until );
nicholas@926 2973 },
nicholas@926 2974 next: function( elem ) {
nicholas@926 2975 return sibling( elem, "nextSibling" );
nicholas@926 2976 },
nicholas@926 2977 prev: function( elem ) {
nicholas@926 2978 return sibling( elem, "previousSibling" );
nicholas@926 2979 },
nicholas@926 2980 nextAll: function( elem ) {
nicholas@926 2981 return jQuery.dir( elem, "nextSibling" );
nicholas@926 2982 },
nicholas@926 2983 prevAll: function( elem ) {
nicholas@926 2984 return jQuery.dir( elem, "previousSibling" );
nicholas@926 2985 },
nicholas@926 2986 nextUntil: function( elem, i, until ) {
nicholas@926 2987 return jQuery.dir( elem, "nextSibling", until );
nicholas@926 2988 },
nicholas@926 2989 prevUntil: function( elem, i, until ) {
nicholas@926 2990 return jQuery.dir( elem, "previousSibling", until );
nicholas@926 2991 },
nicholas@926 2992 siblings: function( elem ) {
nicholas@926 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nicholas@926 2994 },
nicholas@926 2995 children: function( elem ) {
nicholas@926 2996 return jQuery.sibling( elem.firstChild );
nicholas@926 2997 },
nicholas@926 2998 contents: function( elem ) {
nicholas@926 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nicholas@926 3000 }
nicholas@926 3001 }, function( name, fn ) {
nicholas@926 3002 jQuery.fn[ name ] = function( until, selector ) {
nicholas@926 3003 var matched = jQuery.map( this, fn, until );
nicholas@926 3004
nicholas@926 3005 if ( name.slice( -5 ) !== "Until" ) {
nicholas@926 3006 selector = until;
nicholas@926 3007 }
nicholas@926 3008
nicholas@926 3009 if ( selector && typeof selector === "string" ) {
nicholas@926 3010 matched = jQuery.filter( selector, matched );
nicholas@926 3011 }
nicholas@926 3012
nicholas@926 3013 if ( this.length > 1 ) {
nicholas@926 3014 // Remove duplicates
nicholas@926 3015 if ( !guaranteedUnique[ name ] ) {
nicholas@926 3016 jQuery.unique( matched );
nicholas@926 3017 }
nicholas@926 3018
nicholas@926 3019 // Reverse order for parents* and prev-derivatives
nicholas@926 3020 if ( rparentsprev.test( name ) ) {
nicholas@926 3021 matched.reverse();
nicholas@926 3022 }
nicholas@926 3023 }
nicholas@926 3024
nicholas@926 3025 return this.pushStack( matched );
nicholas@926 3026 };
nicholas@926 3027 });
nicholas@926 3028 var rnotwhite = (/\S+/g);
nicholas@926 3029
nicholas@926 3030
nicholas@926 3031
nicholas@926 3032 // String to Object options format cache
nicholas@926 3033 var optionsCache = {};
nicholas@926 3034
nicholas@926 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nicholas@926 3036 function createOptions( options ) {
nicholas@926 3037 var object = optionsCache[ options ] = {};
nicholas@926 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nicholas@926 3039 object[ flag ] = true;
nicholas@926 3040 });
nicholas@926 3041 return object;
nicholas@926 3042 }
nicholas@926 3043
nicholas@926 3044 /*
nicholas@926 3045 * Create a callback list using the following parameters:
nicholas@926 3046 *
nicholas@926 3047 * options: an optional list of space-separated options that will change how
nicholas@926 3048 * the callback list behaves or a more traditional option object
nicholas@926 3049 *
nicholas@926 3050 * By default a callback list will act like an event callback list and can be
nicholas@926 3051 * "fired" multiple times.
nicholas@926 3052 *
nicholas@926 3053 * Possible options:
nicholas@926 3054 *
nicholas@926 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nicholas@926 3056 *
nicholas@926 3057 * memory: will keep track of previous values and will call any callback added
nicholas@926 3058 * after the list has been fired right away with the latest "memorized"
nicholas@926 3059 * values (like a Deferred)
nicholas@926 3060 *
nicholas@926 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nicholas@926 3062 *
nicholas@926 3063 * stopOnFalse: interrupt callings when a callback returns false
nicholas@926 3064 *
nicholas@926 3065 */
nicholas@926 3066 jQuery.Callbacks = function( options ) {
nicholas@926 3067
nicholas@926 3068 // Convert options from String-formatted to Object-formatted if needed
nicholas@926 3069 // (we check in cache first)
nicholas@926 3070 options = typeof options === "string" ?
nicholas@926 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nicholas@926 3072 jQuery.extend( {}, options );
nicholas@926 3073
nicholas@926 3074 var // Last fire value (for non-forgettable lists)
nicholas@926 3075 memory,
nicholas@926 3076 // Flag to know if list was already fired
nicholas@926 3077 fired,
nicholas@926 3078 // Flag to know if list is currently firing
nicholas@926 3079 firing,
nicholas@926 3080 // First callback to fire (used internally by add and fireWith)
nicholas@926 3081 firingStart,
nicholas@926 3082 // End of the loop when firing
nicholas@926 3083 firingLength,
nicholas@926 3084 // Index of currently firing callback (modified by remove if needed)
nicholas@926 3085 firingIndex,
nicholas@926 3086 // Actual callback list
nicholas@926 3087 list = [],
nicholas@926 3088 // Stack of fire calls for repeatable lists
nicholas@926 3089 stack = !options.once && [],
nicholas@926 3090 // Fire callbacks
nicholas@926 3091 fire = function( data ) {
nicholas@926 3092 memory = options.memory && data;
nicholas@926 3093 fired = true;
nicholas@926 3094 firingIndex = firingStart || 0;
nicholas@926 3095 firingStart = 0;
nicholas@926 3096 firingLength = list.length;
nicholas@926 3097 firing = true;
nicholas@926 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nicholas@926 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nicholas@926 3100 memory = false; // To prevent further calls using add
nicholas@926 3101 break;
nicholas@926 3102 }
nicholas@926 3103 }
nicholas@926 3104 firing = false;
nicholas@926 3105 if ( list ) {
nicholas@926 3106 if ( stack ) {
nicholas@926 3107 if ( stack.length ) {
nicholas@926 3108 fire( stack.shift() );
nicholas@926 3109 }
nicholas@926 3110 } else if ( memory ) {
nicholas@926 3111 list = [];
nicholas@926 3112 } else {
nicholas@926 3113 self.disable();
nicholas@926 3114 }
nicholas@926 3115 }
nicholas@926 3116 },
nicholas@926 3117 // Actual Callbacks object
nicholas@926 3118 self = {
nicholas@926 3119 // Add a callback or a collection of callbacks to the list
nicholas@926 3120 add: function() {
nicholas@926 3121 if ( list ) {
nicholas@926 3122 // First, we save the current length
nicholas@926 3123 var start = list.length;
nicholas@926 3124 (function add( args ) {
nicholas@926 3125 jQuery.each( args, function( _, arg ) {
nicholas@926 3126 var type = jQuery.type( arg );
nicholas@926 3127 if ( type === "function" ) {
nicholas@926 3128 if ( !options.unique || !self.has( arg ) ) {
nicholas@926 3129 list.push( arg );
nicholas@926 3130 }
nicholas@926 3131 } else if ( arg && arg.length && type !== "string" ) {
nicholas@926 3132 // Inspect recursively
nicholas@926 3133 add( arg );
nicholas@926 3134 }
nicholas@926 3135 });
nicholas@926 3136 })( arguments );
nicholas@926 3137 // Do we need to add the callbacks to the
nicholas@926 3138 // current firing batch?
nicholas@926 3139 if ( firing ) {
nicholas@926 3140 firingLength = list.length;
nicholas@926 3141 // With memory, if we're not firing then
nicholas@926 3142 // we should call right away
nicholas@926 3143 } else if ( memory ) {
nicholas@926 3144 firingStart = start;
nicholas@926 3145 fire( memory );
nicholas@926 3146 }
nicholas@926 3147 }
nicholas@926 3148 return this;
nicholas@926 3149 },
nicholas@926 3150 // Remove a callback from the list
nicholas@926 3151 remove: function() {
nicholas@926 3152 if ( list ) {
nicholas@926 3153 jQuery.each( arguments, function( _, arg ) {
nicholas@926 3154 var index;
nicholas@926 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nicholas@926 3156 list.splice( index, 1 );
nicholas@926 3157 // Handle firing indexes
nicholas@926 3158 if ( firing ) {
nicholas@926 3159 if ( index <= firingLength ) {
nicholas@926 3160 firingLength--;
nicholas@926 3161 }
nicholas@926 3162 if ( index <= firingIndex ) {
nicholas@926 3163 firingIndex--;
nicholas@926 3164 }
nicholas@926 3165 }
nicholas@926 3166 }
nicholas@926 3167 });
nicholas@926 3168 }
nicholas@926 3169 return this;
nicholas@926 3170 },
nicholas@926 3171 // Check if a given callback is in the list.
nicholas@926 3172 // If no argument is given, return whether or not list has callbacks attached.
nicholas@926 3173 has: function( fn ) {
nicholas@926 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nicholas@926 3175 },
nicholas@926 3176 // Remove all callbacks from the list
nicholas@926 3177 empty: function() {
nicholas@926 3178 list = [];
nicholas@926 3179 firingLength = 0;
nicholas@926 3180 return this;
nicholas@926 3181 },
nicholas@926 3182 // Have the list do nothing anymore
nicholas@926 3183 disable: function() {
nicholas@926 3184 list = stack = memory = undefined;
nicholas@926 3185 return this;
nicholas@926 3186 },
nicholas@926 3187 // Is it disabled?
nicholas@926 3188 disabled: function() {
nicholas@926 3189 return !list;
nicholas@926 3190 },
nicholas@926 3191 // Lock the list in its current state
nicholas@926 3192 lock: function() {
nicholas@926 3193 stack = undefined;
nicholas@926 3194 if ( !memory ) {
nicholas@926 3195 self.disable();
nicholas@926 3196 }
nicholas@926 3197 return this;
nicholas@926 3198 },
nicholas@926 3199 // Is it locked?
nicholas@926 3200 locked: function() {
nicholas@926 3201 return !stack;
nicholas@926 3202 },
nicholas@926 3203 // Call all callbacks with the given context and arguments
nicholas@926 3204 fireWith: function( context, args ) {
nicholas@926 3205 if ( list && ( !fired || stack ) ) {
nicholas@926 3206 args = args || [];
nicholas@926 3207 args = [ context, args.slice ? args.slice() : args ];
nicholas@926 3208 if ( firing ) {
nicholas@926 3209 stack.push( args );
nicholas@926 3210 } else {
nicholas@926 3211 fire( args );
nicholas@926 3212 }
nicholas@926 3213 }
nicholas@926 3214 return this;
nicholas@926 3215 },
nicholas@926 3216 // Call all the callbacks with the given arguments
nicholas@926 3217 fire: function() {
nicholas@926 3218 self.fireWith( this, arguments );
nicholas@926 3219 return this;
nicholas@926 3220 },
nicholas@926 3221 // To know if the callbacks have already been called at least once
nicholas@926 3222 fired: function() {
nicholas@926 3223 return !!fired;
nicholas@926 3224 }
nicholas@926 3225 };
nicholas@926 3226
nicholas@926 3227 return self;
nicholas@926 3228 };
nicholas@926 3229
nicholas@926 3230
nicholas@926 3231 jQuery.extend({
nicholas@926 3232
nicholas@926 3233 Deferred: function( func ) {
nicholas@926 3234 var tuples = [
nicholas@926 3235 // action, add listener, listener list, final state
nicholas@926 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nicholas@926 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nicholas@926 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nicholas@926 3239 ],
nicholas@926 3240 state = "pending",
nicholas@926 3241 promise = {
nicholas@926 3242 state: function() {
nicholas@926 3243 return state;
nicholas@926 3244 },
nicholas@926 3245 always: function() {
nicholas@926 3246 deferred.done( arguments ).fail( arguments );
nicholas@926 3247 return this;
nicholas@926 3248 },
nicholas@926 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nicholas@926 3250 var fns = arguments;
nicholas@926 3251 return jQuery.Deferred(function( newDefer ) {
nicholas@926 3252 jQuery.each( tuples, function( i, tuple ) {
nicholas@926 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nicholas@926 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nicholas@926 3255 deferred[ tuple[1] ](function() {
nicholas@926 3256 var returned = fn && fn.apply( this, arguments );
nicholas@926 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nicholas@926 3258 returned.promise()
nicholas@926 3259 .done( newDefer.resolve )
nicholas@926 3260 .fail( newDefer.reject )
nicholas@926 3261 .progress( newDefer.notify );
nicholas@926 3262 } else {
nicholas@926 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nicholas@926 3264 }
nicholas@926 3265 });
nicholas@926 3266 });
nicholas@926 3267 fns = null;
nicholas@926 3268 }).promise();
nicholas@926 3269 },
nicholas@926 3270 // Get a promise for this deferred
nicholas@926 3271 // If obj is provided, the promise aspect is added to the object
nicholas@926 3272 promise: function( obj ) {
nicholas@926 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nicholas@926 3274 }
nicholas@926 3275 },
nicholas@926 3276 deferred = {};
nicholas@926 3277
nicholas@926 3278 // Keep pipe for back-compat
nicholas@926 3279 promise.pipe = promise.then;
nicholas@926 3280
nicholas@926 3281 // Add list-specific methods
nicholas@926 3282 jQuery.each( tuples, function( i, tuple ) {
nicholas@926 3283 var list = tuple[ 2 ],
nicholas@926 3284 stateString = tuple[ 3 ];
nicholas@926 3285
nicholas@926 3286 // promise[ done | fail | progress ] = list.add
nicholas@926 3287 promise[ tuple[1] ] = list.add;
nicholas@926 3288
nicholas@926 3289 // Handle state
nicholas@926 3290 if ( stateString ) {
nicholas@926 3291 list.add(function() {
nicholas@926 3292 // state = [ resolved | rejected ]
nicholas@926 3293 state = stateString;
nicholas@926 3294
nicholas@926 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nicholas@926 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nicholas@926 3297 }
nicholas@926 3298
nicholas@926 3299 // deferred[ resolve | reject | notify ]
nicholas@926 3300 deferred[ tuple[0] ] = function() {
nicholas@926 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nicholas@926 3302 return this;
nicholas@926 3303 };
nicholas@926 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nicholas@926 3305 });
nicholas@926 3306
nicholas@926 3307 // Make the deferred a promise
nicholas@926 3308 promise.promise( deferred );
nicholas@926 3309
nicholas@926 3310 // Call given func if any
nicholas@926 3311 if ( func ) {
nicholas@926 3312 func.call( deferred, deferred );
nicholas@926 3313 }
nicholas@926 3314
nicholas@926 3315 // All done!
nicholas@926 3316 return deferred;
nicholas@926 3317 },
nicholas@926 3318
nicholas@926 3319 // Deferred helper
nicholas@926 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nicholas@926 3321 var i = 0,
nicholas@926 3322 resolveValues = slice.call( arguments ),
nicholas@926 3323 length = resolveValues.length,
nicholas@926 3324
nicholas@926 3325 // the count of uncompleted subordinates
nicholas@926 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nicholas@926 3327
nicholas@926 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nicholas@926 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nicholas@926 3330
nicholas@926 3331 // Update function for both resolve and progress values
nicholas@926 3332 updateFunc = function( i, contexts, values ) {
nicholas@926 3333 return function( value ) {
nicholas@926 3334 contexts[ i ] = this;
nicholas@926 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nicholas@926 3336 if ( values === progressValues ) {
nicholas@926 3337 deferred.notifyWith( contexts, values );
nicholas@926 3338 } else if ( !( --remaining ) ) {
nicholas@926 3339 deferred.resolveWith( contexts, values );
nicholas@926 3340 }
nicholas@926 3341 };
nicholas@926 3342 },
nicholas@926 3343
nicholas@926 3344 progressValues, progressContexts, resolveContexts;
nicholas@926 3345
nicholas@926 3346 // Add listeners to Deferred subordinates; treat others as resolved
nicholas@926 3347 if ( length > 1 ) {
nicholas@926 3348 progressValues = new Array( length );
nicholas@926 3349 progressContexts = new Array( length );
nicholas@926 3350 resolveContexts = new Array( length );
nicholas@926 3351 for ( ; i < length; i++ ) {
nicholas@926 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nicholas@926 3353 resolveValues[ i ].promise()
nicholas@926 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nicholas@926 3355 .fail( deferred.reject )
nicholas@926 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nicholas@926 3357 } else {
nicholas@926 3358 --remaining;
nicholas@926 3359 }
nicholas@926 3360 }
nicholas@926 3361 }
nicholas@926 3362
nicholas@926 3363 // If we're not waiting on anything, resolve the master
nicholas@926 3364 if ( !remaining ) {
nicholas@926 3365 deferred.resolveWith( resolveContexts, resolveValues );
nicholas@926 3366 }
nicholas@926 3367
nicholas@926 3368 return deferred.promise();
nicholas@926 3369 }
nicholas@926 3370 });
nicholas@926 3371
nicholas@926 3372
nicholas@926 3373 // The deferred used on DOM ready
nicholas@926 3374 var readyList;
nicholas@926 3375
nicholas@926 3376 jQuery.fn.ready = function( fn ) {
nicholas@926 3377 // Add the callback
nicholas@926 3378 jQuery.ready.promise().done( fn );
nicholas@926 3379
nicholas@926 3380 return this;
nicholas@926 3381 };
nicholas@926 3382
nicholas@926 3383 jQuery.extend({
nicholas@926 3384 // Is the DOM ready to be used? Set to true once it occurs.
nicholas@926 3385 isReady: false,
nicholas@926 3386
nicholas@926 3387 // A counter to track how many items to wait for before
nicholas@926 3388 // the ready event fires. See #6781
nicholas@926 3389 readyWait: 1,
nicholas@926 3390
nicholas@926 3391 // Hold (or release) the ready event
nicholas@926 3392 holdReady: function( hold ) {
nicholas@926 3393 if ( hold ) {
nicholas@926 3394 jQuery.readyWait++;
nicholas@926 3395 } else {
nicholas@926 3396 jQuery.ready( true );
nicholas@926 3397 }
nicholas@926 3398 },
nicholas@926 3399
nicholas@926 3400 // Handle when the DOM is ready
nicholas@926 3401 ready: function( wait ) {
nicholas@926 3402
nicholas@926 3403 // Abort if there are pending holds or we're already ready
nicholas@926 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nicholas@926 3405 return;
nicholas@926 3406 }
nicholas@926 3407
nicholas@926 3408 // Remember that the DOM is ready
nicholas@926 3409 jQuery.isReady = true;
nicholas@926 3410
nicholas@926 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nicholas@926 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nicholas@926 3413 return;
nicholas@926 3414 }
nicholas@926 3415
nicholas@926 3416 // If there are functions bound, to execute
nicholas@926 3417 readyList.resolveWith( document, [ jQuery ] );
nicholas@926 3418
nicholas@926 3419 // Trigger any bound ready events
nicholas@926 3420 if ( jQuery.fn.triggerHandler ) {
nicholas@926 3421 jQuery( document ).triggerHandler( "ready" );
nicholas@926 3422 jQuery( document ).off( "ready" );
nicholas@926 3423 }
nicholas@926 3424 }
nicholas@926 3425 });
nicholas@926 3426
nicholas@926 3427 /**
nicholas@926 3428 * The ready event handler and self cleanup method
nicholas@926 3429 */
nicholas@926 3430 function completed() {
nicholas@926 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nicholas@926 3432 window.removeEventListener( "load", completed, false );
nicholas@926 3433 jQuery.ready();
nicholas@926 3434 }
nicholas@926 3435
nicholas@926 3436 jQuery.ready.promise = function( obj ) {
nicholas@926 3437 if ( !readyList ) {
nicholas@926 3438
nicholas@926 3439 readyList = jQuery.Deferred();
nicholas@926 3440
nicholas@926 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nicholas@926 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nicholas@926 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nicholas@926 3444 if ( document.readyState === "complete" ) {
nicholas@926 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nicholas@926 3446 setTimeout( jQuery.ready );
nicholas@926 3447
nicholas@926 3448 } else {
nicholas@926 3449
nicholas@926 3450 // Use the handy event callback
nicholas@926 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nicholas@926 3452
nicholas@926 3453 // A fallback to window.onload, that will always work
nicholas@926 3454 window.addEventListener( "load", completed, false );
nicholas@926 3455 }
nicholas@926 3456 }
nicholas@926 3457 return readyList.promise( obj );
nicholas@926 3458 };
nicholas@926 3459
nicholas@926 3460 // Kick off the DOM ready check even if the user does not
nicholas@926 3461 jQuery.ready.promise();
nicholas@926 3462
nicholas@926 3463
nicholas@926 3464
nicholas@926 3465
nicholas@926 3466 // Multifunctional method to get and set values of a collection
nicholas@926 3467 // The value/s can optionally be executed if it's a function
nicholas@926 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nicholas@926 3469 var i = 0,
nicholas@926 3470 len = elems.length,
nicholas@926 3471 bulk = key == null;
nicholas@926 3472
nicholas@926 3473 // Sets many values
nicholas@926 3474 if ( jQuery.type( key ) === "object" ) {
nicholas@926 3475 chainable = true;
nicholas@926 3476 for ( i in key ) {
nicholas@926 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nicholas@926 3478 }
nicholas@926 3479
nicholas@926 3480 // Sets one value
nicholas@926 3481 } else if ( value !== undefined ) {
nicholas@926 3482 chainable = true;
nicholas@926 3483
nicholas@926 3484 if ( !jQuery.isFunction( value ) ) {
nicholas@926 3485 raw = true;
nicholas@926 3486 }
nicholas@926 3487
nicholas@926 3488 if ( bulk ) {
nicholas@926 3489 // Bulk operations run against the entire set
nicholas@926 3490 if ( raw ) {
nicholas@926 3491 fn.call( elems, value );
nicholas@926 3492 fn = null;
nicholas@926 3493
nicholas@926 3494 // ...except when executing function values
nicholas@926 3495 } else {
nicholas@926 3496 bulk = fn;
nicholas@926 3497 fn = function( elem, key, value ) {
nicholas@926 3498 return bulk.call( jQuery( elem ), value );
nicholas@926 3499 };
nicholas@926 3500 }
nicholas@926 3501 }
nicholas@926 3502
nicholas@926 3503 if ( fn ) {
nicholas@926 3504 for ( ; i < len; i++ ) {
nicholas@926 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nicholas@926 3506 }
nicholas@926 3507 }
nicholas@926 3508 }
nicholas@926 3509
nicholas@926 3510 return chainable ?
nicholas@926 3511 elems :
nicholas@926 3512
nicholas@926 3513 // Gets
nicholas@926 3514 bulk ?
nicholas@926 3515 fn.call( elems ) :
nicholas@926 3516 len ? fn( elems[0], key ) : emptyGet;
nicholas@926 3517 };
nicholas@926 3518
nicholas@926 3519
nicholas@926 3520 /**
nicholas@926 3521 * Determines whether an object can have data
nicholas@926 3522 */
nicholas@926 3523 jQuery.acceptData = function( owner ) {
nicholas@926 3524 // Accepts only:
nicholas@926 3525 // - Node
nicholas@926 3526 // - Node.ELEMENT_NODE
nicholas@926 3527 // - Node.DOCUMENT_NODE
nicholas@926 3528 // - Object
nicholas@926 3529 // - Any
nicholas@926 3530 /* jshint -W018 */
nicholas@926 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nicholas@926 3532 };
nicholas@926 3533
nicholas@926 3534
nicholas@926 3535 function Data() {
nicholas@926 3536 // Support: Android<4,
nicholas@926 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nicholas@926 3538 // return new empty object instead with no [[set]] accessor
nicholas@926 3539 Object.defineProperty( this.cache = {}, 0, {
nicholas@926 3540 get: function() {
nicholas@926 3541 return {};
nicholas@926 3542 }
nicholas@926 3543 });
nicholas@926 3544
nicholas@926 3545 this.expando = jQuery.expando + Data.uid++;
nicholas@926 3546 }
nicholas@926 3547
nicholas@926 3548 Data.uid = 1;
nicholas@926 3549 Data.accepts = jQuery.acceptData;
nicholas@926 3550
nicholas@926 3551 Data.prototype = {
nicholas@926 3552 key: function( owner ) {
nicholas@926 3553 // We can accept data for non-element nodes in modern browsers,
nicholas@926 3554 // but we should not, see #8335.
nicholas@926 3555 // Always return the key for a frozen object.
nicholas@926 3556 if ( !Data.accepts( owner ) ) {
nicholas@926 3557 return 0;
nicholas@926 3558 }
nicholas@926 3559
nicholas@926 3560 var descriptor = {},
nicholas@926 3561 // Check if the owner object already has a cache key
nicholas@926 3562 unlock = owner[ this.expando ];
nicholas@926 3563
nicholas@926 3564 // If not, create one
nicholas@926 3565 if ( !unlock ) {
nicholas@926 3566 unlock = Data.uid++;
nicholas@926 3567
nicholas@926 3568 // Secure it in a non-enumerable, non-writable property
nicholas@926 3569 try {
nicholas@926 3570 descriptor[ this.expando ] = { value: unlock };
nicholas@926 3571 Object.defineProperties( owner, descriptor );
nicholas@926 3572
nicholas@926 3573 // Support: Android<4
nicholas@926 3574 // Fallback to a less secure definition
nicholas@926 3575 } catch ( e ) {
nicholas@926 3576 descriptor[ this.expando ] = unlock;
nicholas@926 3577 jQuery.extend( owner, descriptor );
nicholas@926 3578 }
nicholas@926 3579 }
nicholas@926 3580
nicholas@926 3581 // Ensure the cache object
nicholas@926 3582 if ( !this.cache[ unlock ] ) {
nicholas@926 3583 this.cache[ unlock ] = {};
nicholas@926 3584 }
nicholas@926 3585
nicholas@926 3586 return unlock;
nicholas@926 3587 },
nicholas@926 3588 set: function( owner, data, value ) {
nicholas@926 3589 var prop,
nicholas@926 3590 // There may be an unlock assigned to this node,
nicholas@926 3591 // if there is no entry for this "owner", create one inline
nicholas@926 3592 // and set the unlock as though an owner entry had always existed
nicholas@926 3593 unlock = this.key( owner ),
nicholas@926 3594 cache = this.cache[ unlock ];
nicholas@926 3595
nicholas@926 3596 // Handle: [ owner, key, value ] args
nicholas@926 3597 if ( typeof data === "string" ) {
nicholas@926 3598 cache[ data ] = value;
nicholas@926 3599
nicholas@926 3600 // Handle: [ owner, { properties } ] args
nicholas@926 3601 } else {
nicholas@926 3602 // Fresh assignments by object are shallow copied
nicholas@926 3603 if ( jQuery.isEmptyObject( cache ) ) {
nicholas@926 3604 jQuery.extend( this.cache[ unlock ], data );
nicholas@926 3605 // Otherwise, copy the properties one-by-one to the cache object
nicholas@926 3606 } else {
nicholas@926 3607 for ( prop in data ) {
nicholas@926 3608 cache[ prop ] = data[ prop ];
nicholas@926 3609 }
nicholas@926 3610 }
nicholas@926 3611 }
nicholas@926 3612 return cache;
nicholas@926 3613 },
nicholas@926 3614 get: function( owner, key ) {
nicholas@926 3615 // Either a valid cache is found, or will be created.
nicholas@926 3616 // New caches will be created and the unlock returned,
nicholas@926 3617 // allowing direct access to the newly created
nicholas@926 3618 // empty data object. A valid owner object must be provided.
nicholas@926 3619 var cache = this.cache[ this.key( owner ) ];
nicholas@926 3620
nicholas@926 3621 return key === undefined ?
nicholas@926 3622 cache : cache[ key ];
nicholas@926 3623 },
nicholas@926 3624 access: function( owner, key, value ) {
nicholas@926 3625 var stored;
nicholas@926 3626 // In cases where either:
nicholas@926 3627 //
nicholas@926 3628 // 1. No key was specified
nicholas@926 3629 // 2. A string key was specified, but no value provided
nicholas@926 3630 //
nicholas@926 3631 // Take the "read" path and allow the get method to determine
nicholas@926 3632 // which value to return, respectively either:
nicholas@926 3633 //
nicholas@926 3634 // 1. The entire cache object
nicholas@926 3635 // 2. The data stored at the key
nicholas@926 3636 //
nicholas@926 3637 if ( key === undefined ||
nicholas@926 3638 ((key && typeof key === "string") && value === undefined) ) {
nicholas@926 3639
nicholas@926 3640 stored = this.get( owner, key );
nicholas@926 3641
nicholas@926 3642 return stored !== undefined ?
nicholas@926 3643 stored : this.get( owner, jQuery.camelCase(key) );
nicholas@926 3644 }
nicholas@926 3645
nicholas@926 3646 // [*]When the key is not a string, or both a key and value
nicholas@926 3647 // are specified, set or extend (existing objects) with either:
nicholas@926 3648 //
nicholas@926 3649 // 1. An object of properties
nicholas@926 3650 // 2. A key and value
nicholas@926 3651 //
nicholas@926 3652 this.set( owner, key, value );
nicholas@926 3653
nicholas@926 3654 // Since the "set" path can have two possible entry points
nicholas@926 3655 // return the expected data based on which path was taken[*]
nicholas@926 3656 return value !== undefined ? value : key;
nicholas@926 3657 },
nicholas@926 3658 remove: function( owner, key ) {
nicholas@926 3659 var i, name, camel,
nicholas@926 3660 unlock = this.key( owner ),
nicholas@926 3661 cache = this.cache[ unlock ];
nicholas@926 3662
nicholas@926 3663 if ( key === undefined ) {
nicholas@926 3664 this.cache[ unlock ] = {};
nicholas@926 3665
nicholas@926 3666 } else {
nicholas@926 3667 // Support array or space separated string of keys
nicholas@926 3668 if ( jQuery.isArray( key ) ) {
nicholas@926 3669 // If "name" is an array of keys...
nicholas@926 3670 // When data is initially created, via ("key", "val") signature,
nicholas@926 3671 // keys will be converted to camelCase.
nicholas@926 3672 // Since there is no way to tell _how_ a key was added, remove
nicholas@926 3673 // both plain key and camelCase key. #12786
nicholas@926 3674 // This will only penalize the array argument path.
nicholas@926 3675 name = key.concat( key.map( jQuery.camelCase ) );
nicholas@926 3676 } else {
nicholas@926 3677 camel = jQuery.camelCase( key );
nicholas@926 3678 // Try the string as a key before any manipulation
nicholas@926 3679 if ( key in cache ) {
nicholas@926 3680 name = [ key, camel ];
nicholas@926 3681 } else {
nicholas@926 3682 // If a key with the spaces exists, use it.
nicholas@926 3683 // Otherwise, create an array by matching non-whitespace
nicholas@926 3684 name = camel;
nicholas@926 3685 name = name in cache ?
nicholas@926 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nicholas@926 3687 }
nicholas@926 3688 }
nicholas@926 3689
nicholas@926 3690 i = name.length;
nicholas@926 3691 while ( i-- ) {
nicholas@926 3692 delete cache[ name[ i ] ];
nicholas@926 3693 }
nicholas@926 3694 }
nicholas@926 3695 },
nicholas@926 3696 hasData: function( owner ) {
nicholas@926 3697 return !jQuery.isEmptyObject(
nicholas@926 3698 this.cache[ owner[ this.expando ] ] || {}
nicholas@926 3699 );
nicholas@926 3700 },
nicholas@926 3701 discard: function( owner ) {
nicholas@926 3702 if ( owner[ this.expando ] ) {
nicholas@926 3703 delete this.cache[ owner[ this.expando ] ];
nicholas@926 3704 }
nicholas@926 3705 }
nicholas@926 3706 };
nicholas@926 3707 var data_priv = new Data();
nicholas@926 3708
nicholas@926 3709 var data_user = new Data();
nicholas@926 3710
nicholas@926 3711
nicholas@926 3712
nicholas@926 3713 // Implementation Summary
nicholas@926 3714 //
nicholas@926 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nicholas@926 3716 // 2. Improve the module's maintainability by reducing the storage
nicholas@926 3717 // paths to a single mechanism.
nicholas@926 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nicholas@926 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nicholas@926 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nicholas@926 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nicholas@926 3722
nicholas@926 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nicholas@926 3724 rmultiDash = /([A-Z])/g;
nicholas@926 3725
nicholas@926 3726 function dataAttr( elem, key, data ) {
nicholas@926 3727 var name;
nicholas@926 3728
nicholas@926 3729 // If nothing was found internally, try to fetch any
nicholas@926 3730 // data from the HTML5 data-* attribute
nicholas@926 3731 if ( data === undefined && elem.nodeType === 1 ) {
nicholas@926 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nicholas@926 3733 data = elem.getAttribute( name );
nicholas@926 3734
nicholas@926 3735 if ( typeof data === "string" ) {
nicholas@926 3736 try {
nicholas@926 3737 data = data === "true" ? true :
nicholas@926 3738 data === "false" ? false :
nicholas@926 3739 data === "null" ? null :
nicholas@926 3740 // Only convert to a number if it doesn't change the string
nicholas@926 3741 +data + "" === data ? +data :
nicholas@926 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nicholas@926 3743 data;
nicholas@926 3744 } catch( e ) {}
nicholas@926 3745
nicholas@926 3746 // Make sure we set the data so it isn't changed later
nicholas@926 3747 data_user.set( elem, key, data );
nicholas@926 3748 } else {
nicholas@926 3749 data = undefined;
nicholas@926 3750 }
nicholas@926 3751 }
nicholas@926 3752 return data;
nicholas@926 3753 }
nicholas@926 3754
nicholas@926 3755 jQuery.extend({
nicholas@926 3756 hasData: function( elem ) {
nicholas@926 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nicholas@926 3758 },
nicholas@926 3759
nicholas@926 3760 data: function( elem, name, data ) {
nicholas@926 3761 return data_user.access( elem, name, data );
nicholas@926 3762 },
nicholas@926 3763
nicholas@926 3764 removeData: function( elem, name ) {
nicholas@926 3765 data_user.remove( elem, name );
nicholas@926 3766 },
nicholas@926 3767
nicholas@926 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nicholas@926 3769 // with direct calls to data_priv methods, these can be deprecated.
nicholas@926 3770 _data: function( elem, name, data ) {
nicholas@926 3771 return data_priv.access( elem, name, data );
nicholas@926 3772 },
nicholas@926 3773
nicholas@926 3774 _removeData: function( elem, name ) {
nicholas@926 3775 data_priv.remove( elem, name );
nicholas@926 3776 }
nicholas@926 3777 });
nicholas@926 3778
nicholas@926 3779 jQuery.fn.extend({
nicholas@926 3780 data: function( key, value ) {
nicholas@926 3781 var i, name, data,
nicholas@926 3782 elem = this[ 0 ],
nicholas@926 3783 attrs = elem && elem.attributes;
nicholas@926 3784
nicholas@926 3785 // Gets all values
nicholas@926 3786 if ( key === undefined ) {
nicholas@926 3787 if ( this.length ) {
nicholas@926 3788 data = data_user.get( elem );
nicholas@926 3789
nicholas@926 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nicholas@926 3791 i = attrs.length;
nicholas@926 3792 while ( i-- ) {
nicholas@926 3793
nicholas@926 3794 // Support: IE11+
nicholas@926 3795 // The attrs elements can be null (#14894)
nicholas@926 3796 if ( attrs[ i ] ) {
nicholas@926 3797 name = attrs[ i ].name;
nicholas@926 3798 if ( name.indexOf( "data-" ) === 0 ) {
nicholas@926 3799 name = jQuery.camelCase( name.slice(5) );
nicholas@926 3800 dataAttr( elem, name, data[ name ] );
nicholas@926 3801 }
nicholas@926 3802 }
nicholas@926 3803 }
nicholas@926 3804 data_priv.set( elem, "hasDataAttrs", true );
nicholas@926 3805 }
nicholas@926 3806 }
nicholas@926 3807
nicholas@926 3808 return data;
nicholas@926 3809 }
nicholas@926 3810
nicholas@926 3811 // Sets multiple values
nicholas@926 3812 if ( typeof key === "object" ) {
nicholas@926 3813 return this.each(function() {
nicholas@926 3814 data_user.set( this, key );
nicholas@926 3815 });
nicholas@926 3816 }
nicholas@926 3817
nicholas@926 3818 return access( this, function( value ) {
nicholas@926 3819 var data,
nicholas@926 3820 camelKey = jQuery.camelCase( key );
nicholas@926 3821
nicholas@926 3822 // The calling jQuery object (element matches) is not empty
nicholas@926 3823 // (and therefore has an element appears at this[ 0 ]) and the
nicholas@926 3824 // `value` parameter was not undefined. An empty jQuery object
nicholas@926 3825 // will result in `undefined` for elem = this[ 0 ] which will
nicholas@926 3826 // throw an exception if an attempt to read a data cache is made.
nicholas@926 3827 if ( elem && value === undefined ) {
nicholas@926 3828 // Attempt to get data from the cache
nicholas@926 3829 // with the key as-is
nicholas@926 3830 data = data_user.get( elem, key );
nicholas@926 3831 if ( data !== undefined ) {
nicholas@926 3832 return data;
nicholas@926 3833 }
nicholas@926 3834
nicholas@926 3835 // Attempt to get data from the cache
nicholas@926 3836 // with the key camelized
nicholas@926 3837 data = data_user.get( elem, camelKey );
nicholas@926 3838 if ( data !== undefined ) {
nicholas@926 3839 return data;
nicholas@926 3840 }
nicholas@926 3841
nicholas@926 3842 // Attempt to "discover" the data in
nicholas@926 3843 // HTML5 custom data-* attrs
nicholas@926 3844 data = dataAttr( elem, camelKey, undefined );
nicholas@926 3845 if ( data !== undefined ) {
nicholas@926 3846 return data;
nicholas@926 3847 }
nicholas@926 3848
nicholas@926 3849 // We tried really hard, but the data doesn't exist.
nicholas@926 3850 return;
nicholas@926 3851 }
nicholas@926 3852
nicholas@926 3853 // Set the data...
nicholas@926 3854 this.each(function() {
nicholas@926 3855 // First, attempt to store a copy or reference of any
nicholas@926 3856 // data that might've been store with a camelCased key.
nicholas@926 3857 var data = data_user.get( this, camelKey );
nicholas@926 3858
nicholas@926 3859 // For HTML5 data-* attribute interop, we have to
nicholas@926 3860 // store property names with dashes in a camelCase form.
nicholas@926 3861 // This might not apply to all properties...*
nicholas@926 3862 data_user.set( this, camelKey, value );
nicholas@926 3863
nicholas@926 3864 // *... In the case of properties that might _actually_
nicholas@926 3865 // have dashes, we need to also store a copy of that
nicholas@926 3866 // unchanged property.
nicholas@926 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nicholas@926 3868 data_user.set( this, key, value );
nicholas@926 3869 }
nicholas@926 3870 });
nicholas@926 3871 }, null, value, arguments.length > 1, null, true );
nicholas@926 3872 },
nicholas@926 3873
nicholas@926 3874 removeData: function( key ) {
nicholas@926 3875 return this.each(function() {
nicholas@926 3876 data_user.remove( this, key );
nicholas@926 3877 });
nicholas@926 3878 }
nicholas@926 3879 });
nicholas@926 3880
nicholas@926 3881
nicholas@926 3882 jQuery.extend({
nicholas@926 3883 queue: function( elem, type, data ) {
nicholas@926 3884 var queue;
nicholas@926 3885
nicholas@926 3886 if ( elem ) {
nicholas@926 3887 type = ( type || "fx" ) + "queue";
nicholas@926 3888 queue = data_priv.get( elem, type );
nicholas@926 3889
nicholas@926 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nicholas@926 3891 if ( data ) {
nicholas@926 3892 if ( !queue || jQuery.isArray( data ) ) {
nicholas@926 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nicholas@926 3894 } else {
nicholas@926 3895 queue.push( data );
nicholas@926 3896 }
nicholas@926 3897 }
nicholas@926 3898 return queue || [];
nicholas@926 3899 }
nicholas@926 3900 },
nicholas@926 3901
nicholas@926 3902 dequeue: function( elem, type ) {
nicholas@926 3903 type = type || "fx";
nicholas@926 3904
nicholas@926 3905 var queue = jQuery.queue( elem, type ),
nicholas@926 3906 startLength = queue.length,
nicholas@926 3907 fn = queue.shift(),
nicholas@926 3908 hooks = jQuery._queueHooks( elem, type ),
nicholas@926 3909 next = function() {
nicholas@926 3910 jQuery.dequeue( elem, type );
nicholas@926 3911 };
nicholas@926 3912
nicholas@926 3913 // If the fx queue is dequeued, always remove the progress sentinel
nicholas@926 3914 if ( fn === "inprogress" ) {
nicholas@926 3915 fn = queue.shift();
nicholas@926 3916 startLength--;
nicholas@926 3917 }
nicholas@926 3918
nicholas@926 3919 if ( fn ) {
nicholas@926 3920
nicholas@926 3921 // Add a progress sentinel to prevent the fx queue from being
nicholas@926 3922 // automatically dequeued
nicholas@926 3923 if ( type === "fx" ) {
nicholas@926 3924 queue.unshift( "inprogress" );
nicholas@926 3925 }
nicholas@926 3926
nicholas@926 3927 // Clear up the last queue stop function
nicholas@926 3928 delete hooks.stop;
nicholas@926 3929 fn.call( elem, next, hooks );
nicholas@926 3930 }
nicholas@926 3931
nicholas@926 3932 if ( !startLength && hooks ) {
nicholas@926 3933 hooks.empty.fire();
nicholas@926 3934 }
nicholas@926 3935 },
nicholas@926 3936
nicholas@926 3937 // Not public - generate a queueHooks object, or return the current one
nicholas@926 3938 _queueHooks: function( elem, type ) {
nicholas@926 3939 var key = type + "queueHooks";
nicholas@926 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nicholas@926 3941 empty: jQuery.Callbacks("once memory").add(function() {
nicholas@926 3942 data_priv.remove( elem, [ type + "queue", key ] );
nicholas@926 3943 })
nicholas@926 3944 });
nicholas@926 3945 }
nicholas@926 3946 });
nicholas@926 3947
nicholas@926 3948 jQuery.fn.extend({
nicholas@926 3949 queue: function( type, data ) {
nicholas@926 3950 var setter = 2;
nicholas@926 3951
nicholas@926 3952 if ( typeof type !== "string" ) {
nicholas@926 3953 data = type;
nicholas@926 3954 type = "fx";
nicholas@926 3955 setter--;
nicholas@926 3956 }
nicholas@926 3957
nicholas@926 3958 if ( arguments.length < setter ) {
nicholas@926 3959 return jQuery.queue( this[0], type );
nicholas@926 3960 }
nicholas@926 3961
nicholas@926 3962 return data === undefined ?
nicholas@926 3963 this :
nicholas@926 3964 this.each(function() {
nicholas@926 3965 var queue = jQuery.queue( this, type, data );
nicholas@926 3966
nicholas@926 3967 // Ensure a hooks for this queue
nicholas@926 3968 jQuery._queueHooks( this, type );
nicholas@926 3969
nicholas@926 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nicholas@926 3971 jQuery.dequeue( this, type );
nicholas@926 3972 }
nicholas@926 3973 });
nicholas@926 3974 },
nicholas@926 3975 dequeue: function( type ) {
nicholas@926 3976 return this.each(function() {
nicholas@926 3977 jQuery.dequeue( this, type );
nicholas@926 3978 });
nicholas@926 3979 },
nicholas@926 3980 clearQueue: function( type ) {
nicholas@926 3981 return this.queue( type || "fx", [] );
nicholas@926 3982 },
nicholas@926 3983 // Get a promise resolved when queues of a certain type
nicholas@926 3984 // are emptied (fx is the type by default)
nicholas@926 3985 promise: function( type, obj ) {
nicholas@926 3986 var tmp,
nicholas@926 3987 count = 1,
nicholas@926 3988 defer = jQuery.Deferred(),
nicholas@926 3989 elements = this,
nicholas@926 3990 i = this.length,
nicholas@926 3991 resolve = function() {
nicholas@926 3992 if ( !( --count ) ) {
nicholas@926 3993 defer.resolveWith( elements, [ elements ] );
nicholas@926 3994 }
nicholas@926 3995 };
nicholas@926 3996
nicholas@926 3997 if ( typeof type !== "string" ) {
nicholas@926 3998 obj = type;
nicholas@926 3999 type = undefined;
nicholas@926 4000 }
nicholas@926 4001 type = type || "fx";
nicholas@926 4002
nicholas@926 4003 while ( i-- ) {
nicholas@926 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nicholas@926 4005 if ( tmp && tmp.empty ) {
nicholas@926 4006 count++;
nicholas@926 4007 tmp.empty.add( resolve );
nicholas@926 4008 }
nicholas@926 4009 }
nicholas@926 4010 resolve();
nicholas@926 4011 return defer.promise( obj );
nicholas@926 4012 }
nicholas@926 4013 });
nicholas@926 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nicholas@926 4015
nicholas@926 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nicholas@926 4017
nicholas@926 4018 var isHidden = function( elem, el ) {
nicholas@926 4019 // isHidden might be called from jQuery#filter function;
nicholas@926 4020 // in that case, element will be second argument
nicholas@926 4021 elem = el || elem;
nicholas@926 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nicholas@926 4023 };
nicholas@926 4024
nicholas@926 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nicholas@926 4026
nicholas@926 4027
nicholas@926 4028
nicholas@926 4029 (function() {
nicholas@926 4030 var fragment = document.createDocumentFragment(),
nicholas@926 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nicholas@926 4032 input = document.createElement( "input" );
nicholas@926 4033
nicholas@926 4034 // Support: Safari<=5.1
nicholas@926 4035 // Check state lost if the name is set (#11217)
nicholas@926 4036 // Support: Windows Web Apps (WWA)
nicholas@926 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nicholas@926 4038 input.setAttribute( "type", "radio" );
nicholas@926 4039 input.setAttribute( "checked", "checked" );
nicholas@926 4040 input.setAttribute( "name", "t" );
nicholas@926 4041
nicholas@926 4042 div.appendChild( input );
nicholas@926 4043
nicholas@926 4044 // Support: Safari<=5.1, Android<4.2
nicholas@926 4045 // Older WebKit doesn't clone checked state correctly in fragments
nicholas@926 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nicholas@926 4047
nicholas@926 4048 // Support: IE<=11+
nicholas@926 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nicholas@926 4050 div.innerHTML = "<textarea>x</textarea>";
nicholas@926 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nicholas@926 4052 })();
nicholas@926 4053 var strundefined = typeof undefined;
nicholas@926 4054
nicholas@926 4055
nicholas@926 4056
nicholas@926 4057 support.focusinBubbles = "onfocusin" in window;
nicholas@926 4058
nicholas@926 4059
nicholas@926 4060 var
nicholas@926 4061 rkeyEvent = /^key/,
nicholas@926 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nicholas@926 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nicholas@926 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nicholas@926 4065
nicholas@926 4066 function returnTrue() {
nicholas@926 4067 return true;
nicholas@926 4068 }
nicholas@926 4069
nicholas@926 4070 function returnFalse() {
nicholas@926 4071 return false;
nicholas@926 4072 }
nicholas@926 4073
nicholas@926 4074 function safeActiveElement() {
nicholas@926 4075 try {
nicholas@926 4076 return document.activeElement;
nicholas@926 4077 } catch ( err ) { }
nicholas@926 4078 }
nicholas@926 4079
nicholas@926 4080 /*
nicholas@926 4081 * Helper functions for managing events -- not part of the public interface.
nicholas@926 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nicholas@926 4083 */
nicholas@926 4084 jQuery.event = {
nicholas@926 4085
nicholas@926 4086 global: {},
nicholas@926 4087
nicholas@926 4088 add: function( elem, types, handler, data, selector ) {
nicholas@926 4089
nicholas@926 4090 var handleObjIn, eventHandle, tmp,
nicholas@926 4091 events, t, handleObj,
nicholas@926 4092 special, handlers, type, namespaces, origType,
nicholas@926 4093 elemData = data_priv.get( elem );
nicholas@926 4094
nicholas@926 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nicholas@926 4096 if ( !elemData ) {
nicholas@926 4097 return;
nicholas@926 4098 }
nicholas@926 4099
nicholas@926 4100 // Caller can pass in an object of custom data in lieu of the handler
nicholas@926 4101 if ( handler.handler ) {
nicholas@926 4102 handleObjIn = handler;
nicholas@926 4103 handler = handleObjIn.handler;
nicholas@926 4104 selector = handleObjIn.selector;
nicholas@926 4105 }
nicholas@926 4106
nicholas@926 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nicholas@926 4108 if ( !handler.guid ) {
nicholas@926 4109 handler.guid = jQuery.guid++;
nicholas@926 4110 }
nicholas@926 4111
nicholas@926 4112 // Init the element's event structure and main handler, if this is the first
nicholas@926 4113 if ( !(events = elemData.events) ) {
nicholas@926 4114 events = elemData.events = {};
nicholas@926 4115 }
nicholas@926 4116 if ( !(eventHandle = elemData.handle) ) {
nicholas@926 4117 eventHandle = elemData.handle = function( e ) {
nicholas@926 4118 // Discard the second event of a jQuery.event.trigger() and
nicholas@926 4119 // when an event is called after a page has unloaded
nicholas@926 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nicholas@926 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nicholas@926 4122 };
nicholas@926 4123 }
nicholas@926 4124
nicholas@926 4125 // Handle multiple events separated by a space
nicholas@926 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nicholas@926 4127 t = types.length;
nicholas@926 4128 while ( t-- ) {
nicholas@926 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nicholas@926 4130 type = origType = tmp[1];
nicholas@926 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nicholas@926 4132
nicholas@926 4133 // There *must* be a type, no attaching namespace-only handlers
nicholas@926 4134 if ( !type ) {
nicholas@926 4135 continue;
nicholas@926 4136 }
nicholas@926 4137
nicholas@926 4138 // If event changes its type, use the special event handlers for the changed type
nicholas@926 4139 special = jQuery.event.special[ type ] || {};
nicholas@926 4140
nicholas@926 4141 // If selector defined, determine special event api type, otherwise given type
nicholas@926 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nicholas@926 4143
nicholas@926 4144 // Update special based on newly reset type
nicholas@926 4145 special = jQuery.event.special[ type ] || {};
nicholas@926 4146
nicholas@926 4147 // handleObj is passed to all event handlers
nicholas@926 4148 handleObj = jQuery.extend({
nicholas@926 4149 type: type,
nicholas@926 4150 origType: origType,
nicholas@926 4151 data: data,
nicholas@926 4152 handler: handler,
nicholas@926 4153 guid: handler.guid,
nicholas@926 4154 selector: selector,
nicholas@926 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nicholas@926 4156 namespace: namespaces.join(".")
nicholas@926 4157 }, handleObjIn );
nicholas@926 4158
nicholas@926 4159 // Init the event handler queue if we're the first
nicholas@926 4160 if ( !(handlers = events[ type ]) ) {
nicholas@926 4161 handlers = events[ type ] = [];
nicholas@926 4162 handlers.delegateCount = 0;
nicholas@926 4163
nicholas@926 4164 // Only use addEventListener if the special events handler returns false
nicholas@926 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nicholas@926 4166 if ( elem.addEventListener ) {
nicholas@926 4167 elem.addEventListener( type, eventHandle, false );
nicholas@926 4168 }
nicholas@926 4169 }
nicholas@926 4170 }
nicholas@926 4171
nicholas@926 4172 if ( special.add ) {
nicholas@926 4173 special.add.call( elem, handleObj );
nicholas@926 4174
nicholas@926 4175 if ( !handleObj.handler.guid ) {
nicholas@926 4176 handleObj.handler.guid = handler.guid;
nicholas@926 4177 }
nicholas@926 4178 }
nicholas@926 4179
nicholas@926 4180 // Add to the element's handler list, delegates in front
nicholas@926 4181 if ( selector ) {
nicholas@926 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nicholas@926 4183 } else {
nicholas@926 4184 handlers.push( handleObj );
nicholas@926 4185 }
nicholas@926 4186
nicholas@926 4187 // Keep track of which events have ever been used, for event optimization
nicholas@926 4188 jQuery.event.global[ type ] = true;
nicholas@926 4189 }
nicholas@926 4190
nicholas@926 4191 },
nicholas@926 4192
nicholas@926 4193 // Detach an event or set of events from an element
nicholas@926 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nicholas@926 4195
nicholas@926 4196 var j, origCount, tmp,
nicholas@926 4197 events, t, handleObj,
nicholas@926 4198 special, handlers, type, namespaces, origType,
nicholas@926 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nicholas@926 4200
nicholas@926 4201 if ( !elemData || !(events = elemData.events) ) {
nicholas@926 4202 return;
nicholas@926 4203 }
nicholas@926 4204
nicholas@926 4205 // Once for each type.namespace in types; type may be omitted
nicholas@926 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nicholas@926 4207 t = types.length;
nicholas@926 4208 while ( t-- ) {
nicholas@926 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nicholas@926 4210 type = origType = tmp[1];
nicholas@926 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nicholas@926 4212
nicholas@926 4213 // Unbind all events (on this namespace, if provided) for the element
nicholas@926 4214 if ( !type ) {
nicholas@926 4215 for ( type in events ) {
nicholas@926 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nicholas@926 4217 }
nicholas@926 4218 continue;
nicholas@926 4219 }
nicholas@926 4220
nicholas@926 4221 special = jQuery.event.special[ type ] || {};
nicholas@926 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nicholas@926 4223 handlers = events[ type ] || [];
nicholas@926 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nicholas@926 4225
nicholas@926 4226 // Remove matching events
nicholas@926 4227 origCount = j = handlers.length;
nicholas@926 4228 while ( j-- ) {
nicholas@926 4229 handleObj = handlers[ j ];
nicholas@926 4230
nicholas@926 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nicholas@926 4232 ( !handler || handler.guid === handleObj.guid ) &&
nicholas@926 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nicholas@926 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nicholas@926 4235 handlers.splice( j, 1 );
nicholas@926 4236
nicholas@926 4237 if ( handleObj.selector ) {
nicholas@926 4238 handlers.delegateCount--;
nicholas@926 4239 }
nicholas@926 4240 if ( special.remove ) {
nicholas@926 4241 special.remove.call( elem, handleObj );
nicholas@926 4242 }
nicholas@926 4243 }
nicholas@926 4244 }
nicholas@926 4245
nicholas@926 4246 // Remove generic event handler if we removed something and no more handlers exist
nicholas@926 4247 // (avoids potential for endless recursion during removal of special event handlers)
nicholas@926 4248 if ( origCount && !handlers.length ) {
nicholas@926 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nicholas@926 4250 jQuery.removeEvent( elem, type, elemData.handle );
nicholas@926 4251 }
nicholas@926 4252
nicholas@926 4253 delete events[ type ];
nicholas@926 4254 }
nicholas@926 4255 }
nicholas@926 4256
nicholas@926 4257 // Remove the expando if it's no longer used
nicholas@926 4258 if ( jQuery.isEmptyObject( events ) ) {
nicholas@926 4259 delete elemData.handle;
nicholas@926 4260 data_priv.remove( elem, "events" );
nicholas@926 4261 }
nicholas@926 4262 },
nicholas@926 4263
nicholas@926 4264 trigger: function( event, data, elem, onlyHandlers ) {
nicholas@926 4265
nicholas@926 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nicholas@926 4267 eventPath = [ elem || document ],
nicholas@926 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nicholas@926 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nicholas@926 4270
nicholas@926 4271 cur = tmp = elem = elem || document;
nicholas@926 4272
nicholas@926 4273 // Don't do events on text and comment nodes
nicholas@926 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nicholas@926 4275 return;
nicholas@926 4276 }
nicholas@926 4277
nicholas@926 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nicholas@926 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nicholas@926 4280 return;
nicholas@926 4281 }
nicholas@926 4282
nicholas@926 4283 if ( type.indexOf(".") >= 0 ) {
nicholas@926 4284 // Namespaced trigger; create a regexp to match event type in handle()
nicholas@926 4285 namespaces = type.split(".");
nicholas@926 4286 type = namespaces.shift();
nicholas@926 4287 namespaces.sort();
nicholas@926 4288 }
nicholas@926 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nicholas@926 4290
nicholas@926 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nicholas@926 4292 event = event[ jQuery.expando ] ?
nicholas@926 4293 event :
nicholas@926 4294 new jQuery.Event( type, typeof event === "object" && event );
nicholas@926 4295
nicholas@926 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nicholas@926 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nicholas@926 4298 event.namespace = namespaces.join(".");
nicholas@926 4299 event.namespace_re = event.namespace ?
nicholas@926 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nicholas@926 4301 null;
nicholas@926 4302
nicholas@926 4303 // Clean up the event in case it is being reused
nicholas@926 4304 event.result = undefined;
nicholas@926 4305 if ( !event.target ) {
nicholas@926 4306 event.target = elem;
nicholas@926 4307 }
nicholas@926 4308
nicholas@926 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nicholas@926 4310 data = data == null ?
nicholas@926 4311 [ event ] :
nicholas@926 4312 jQuery.makeArray( data, [ event ] );
nicholas@926 4313
nicholas@926 4314 // Allow special events to draw outside the lines
nicholas@926 4315 special = jQuery.event.special[ type ] || {};
nicholas@926 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nicholas@926 4317 return;
nicholas@926 4318 }
nicholas@926 4319
nicholas@926 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nicholas@926 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nicholas@926 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nicholas@926 4323
nicholas@926 4324 bubbleType = special.delegateType || type;
nicholas@926 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nicholas@926 4326 cur = cur.parentNode;
nicholas@926 4327 }
nicholas@926 4328 for ( ; cur; cur = cur.parentNode ) {
nicholas@926 4329 eventPath.push( cur );
nicholas@926 4330 tmp = cur;
nicholas@926 4331 }
nicholas@926 4332
nicholas@926 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nicholas@926 4334 if ( tmp === (elem.ownerDocument || document) ) {
nicholas@926 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nicholas@926 4336 }
nicholas@926 4337 }
nicholas@926 4338
nicholas@926 4339 // Fire handlers on the event path
nicholas@926 4340 i = 0;
nicholas@926 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nicholas@926 4342
nicholas@926 4343 event.type = i > 1 ?
nicholas@926 4344 bubbleType :
nicholas@926 4345 special.bindType || type;
nicholas@926 4346
nicholas@926 4347 // jQuery handler
nicholas@926 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nicholas@926 4349 if ( handle ) {
nicholas@926 4350 handle.apply( cur, data );
nicholas@926 4351 }
nicholas@926 4352
nicholas@926 4353 // Native handler
nicholas@926 4354 handle = ontype && cur[ ontype ];
nicholas@926 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nicholas@926 4356 event.result = handle.apply( cur, data );
nicholas@926 4357 if ( event.result === false ) {
nicholas@926 4358 event.preventDefault();
nicholas@926 4359 }
nicholas@926 4360 }
nicholas@926 4361 }
nicholas@926 4362 event.type = type;
nicholas@926 4363
nicholas@926 4364 // If nobody prevented the default action, do it now
nicholas@926 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nicholas@926 4366
nicholas@926 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nicholas@926 4368 jQuery.acceptData( elem ) ) {
nicholas@926 4369
nicholas@926 4370 // Call a native DOM method on the target with the same name name as the event.
nicholas@926 4371 // Don't do default actions on window, that's where global variables be (#6170)
nicholas@926 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nicholas@926 4373
nicholas@926 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nicholas@926 4375 tmp = elem[ ontype ];
nicholas@926 4376
nicholas@926 4377 if ( tmp ) {
nicholas@926 4378 elem[ ontype ] = null;
nicholas@926 4379 }
nicholas@926 4380
nicholas@926 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nicholas@926 4382 jQuery.event.triggered = type;
nicholas@926 4383 elem[ type ]();
nicholas@926 4384 jQuery.event.triggered = undefined;
nicholas@926 4385
nicholas@926 4386 if ( tmp ) {
nicholas@926 4387 elem[ ontype ] = tmp;
nicholas@926 4388 }
nicholas@926 4389 }
nicholas@926 4390 }
nicholas@926 4391 }
nicholas@926 4392
nicholas@926 4393 return event.result;
nicholas@926 4394 },
nicholas@926 4395
nicholas@926 4396 dispatch: function( event ) {
nicholas@926 4397
nicholas@926 4398 // Make a writable jQuery.Event from the native event object
nicholas@926 4399 event = jQuery.event.fix( event );
nicholas@926 4400
nicholas@926 4401 var i, j, ret, matched, handleObj,
nicholas@926 4402 handlerQueue = [],
nicholas@926 4403 args = slice.call( arguments ),
nicholas@926 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nicholas@926 4405 special = jQuery.event.special[ event.type ] || {};
nicholas@926 4406
nicholas@926 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nicholas@926 4408 args[0] = event;
nicholas@926 4409 event.delegateTarget = this;
nicholas@926 4410
nicholas@926 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nicholas@926 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nicholas@926 4413 return;
nicholas@926 4414 }
nicholas@926 4415
nicholas@926 4416 // Determine handlers
nicholas@926 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nicholas@926 4418
nicholas@926 4419 // Run delegates first; they may want to stop propagation beneath us
nicholas@926 4420 i = 0;
nicholas@926 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nicholas@926 4422 event.currentTarget = matched.elem;
nicholas@926 4423
nicholas@926 4424 j = 0;
nicholas@926 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nicholas@926 4426
nicholas@926 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nicholas@926 4428 // a subset or equal to those in the bound event (both can have no namespace).
nicholas@926 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nicholas@926 4430
nicholas@926 4431 event.handleObj = handleObj;
nicholas@926 4432 event.data = handleObj.data;
nicholas@926 4433
nicholas@926 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nicholas@926 4435 .apply( matched.elem, args );
nicholas@926 4436
nicholas@926 4437 if ( ret !== undefined ) {
nicholas@926 4438 if ( (event.result = ret) === false ) {
nicholas@926 4439 event.preventDefault();
nicholas@926 4440 event.stopPropagation();
nicholas@926 4441 }
nicholas@926 4442 }
nicholas@926 4443 }
nicholas@926 4444 }
nicholas@926 4445 }
nicholas@926 4446
nicholas@926 4447 // Call the postDispatch hook for the mapped type
nicholas@926 4448 if ( special.postDispatch ) {
nicholas@926 4449 special.postDispatch.call( this, event );
nicholas@926 4450 }
nicholas@926 4451
nicholas@926 4452 return event.result;
nicholas@926 4453 },
nicholas@926 4454
nicholas@926 4455 handlers: function( event, handlers ) {
nicholas@926 4456 var i, matches, sel, handleObj,
nicholas@926 4457 handlerQueue = [],
nicholas@926 4458 delegateCount = handlers.delegateCount,
nicholas@926 4459 cur = event.target;
nicholas@926 4460
nicholas@926 4461 // Find delegate handlers
nicholas@926 4462 // Black-hole SVG <use> instance trees (#13180)
nicholas@926 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nicholas@926 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nicholas@926 4465
nicholas@926 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nicholas@926 4467
nicholas@926 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nicholas@926 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nicholas@926 4470 matches = [];
nicholas@926 4471 for ( i = 0; i < delegateCount; i++ ) {
nicholas@926 4472 handleObj = handlers[ i ];
nicholas@926 4473
nicholas@926 4474 // Don't conflict with Object.prototype properties (#13203)
nicholas@926 4475 sel = handleObj.selector + " ";
nicholas@926 4476
nicholas@926 4477 if ( matches[ sel ] === undefined ) {
nicholas@926 4478 matches[ sel ] = handleObj.needsContext ?
nicholas@926 4479 jQuery( sel, this ).index( cur ) >= 0 :
nicholas@926 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nicholas@926 4481 }
nicholas@926 4482 if ( matches[ sel ] ) {
nicholas@926 4483 matches.push( handleObj );
nicholas@926 4484 }
nicholas@926 4485 }
nicholas@926 4486 if ( matches.length ) {
nicholas@926 4487 handlerQueue.push({ elem: cur, handlers: matches });
nicholas@926 4488 }
nicholas@926 4489 }
nicholas@926 4490 }
nicholas@926 4491 }
nicholas@926 4492
nicholas@926 4493 // Add the remaining (directly-bound) handlers
nicholas@926 4494 if ( delegateCount < handlers.length ) {
nicholas@926 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nicholas@926 4496 }
nicholas@926 4497
nicholas@926 4498 return handlerQueue;
nicholas@926 4499 },
nicholas@926 4500
nicholas@926 4501 // Includes some event props shared by KeyEvent and MouseEvent
nicholas@926 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nicholas@926 4503
nicholas@926 4504 fixHooks: {},
nicholas@926 4505
nicholas@926 4506 keyHooks: {
nicholas@926 4507 props: "char charCode key keyCode".split(" "),
nicholas@926 4508 filter: function( event, original ) {
nicholas@926 4509
nicholas@926 4510 // Add which for key events
nicholas@926 4511 if ( event.which == null ) {
nicholas@926 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nicholas@926 4513 }
nicholas@926 4514
nicholas@926 4515 return event;
nicholas@926 4516 }
nicholas@926 4517 },
nicholas@926 4518
nicholas@926 4519 mouseHooks: {
nicholas@926 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nicholas@926 4521 filter: function( event, original ) {
nicholas@926 4522 var eventDoc, doc, body,
nicholas@926 4523 button = original.button;
nicholas@926 4524
nicholas@926 4525 // Calculate pageX/Y if missing and clientX/Y available
nicholas@926 4526 if ( event.pageX == null && original.clientX != null ) {
nicholas@926 4527 eventDoc = event.target.ownerDocument || document;
nicholas@926 4528 doc = eventDoc.documentElement;
nicholas@926 4529 body = eventDoc.body;
nicholas@926 4530
nicholas@926 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nicholas@926 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nicholas@926 4533 }
nicholas@926 4534
nicholas@926 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nicholas@926 4536 // Note: button is not normalized, so don't use it
nicholas@926 4537 if ( !event.which && button !== undefined ) {
nicholas@926 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nicholas@926 4539 }
nicholas@926 4540
nicholas@926 4541 return event;
nicholas@926 4542 }
nicholas@926 4543 },
nicholas@926 4544
nicholas@926 4545 fix: function( event ) {
nicholas@926 4546 if ( event[ jQuery.expando ] ) {
nicholas@926 4547 return event;
nicholas@926 4548 }
nicholas@926 4549
nicholas@926 4550 // Create a writable copy of the event object and normalize some properties
nicholas@926 4551 var i, prop, copy,
nicholas@926 4552 type = event.type,
nicholas@926 4553 originalEvent = event,
nicholas@926 4554 fixHook = this.fixHooks[ type ];
nicholas@926 4555
nicholas@926 4556 if ( !fixHook ) {
nicholas@926 4557 this.fixHooks[ type ] = fixHook =
nicholas@926 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nicholas@926 4559 rkeyEvent.test( type ) ? this.keyHooks :
nicholas@926 4560 {};
nicholas@926 4561 }
nicholas@926 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nicholas@926 4563
nicholas@926 4564 event = new jQuery.Event( originalEvent );
nicholas@926 4565
nicholas@926 4566 i = copy.length;
nicholas@926 4567 while ( i-- ) {
nicholas@926 4568 prop = copy[ i ];
nicholas@926 4569 event[ prop ] = originalEvent[ prop ];
nicholas@926 4570 }
nicholas@926 4571
nicholas@926 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nicholas@926 4573 // All events should have a target; Cordova deviceready doesn't
nicholas@926 4574 if ( !event.target ) {
nicholas@926 4575 event.target = document;
nicholas@926 4576 }
nicholas@926 4577
nicholas@926 4578 // Support: Safari 6.0+, Chrome<28
nicholas@926 4579 // Target should not be a text node (#504, #13143)
nicholas@926 4580 if ( event.target.nodeType === 3 ) {
nicholas@926 4581 event.target = event.target.parentNode;
nicholas@926 4582 }
nicholas@926 4583
nicholas@926 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nicholas@926 4585 },
nicholas@926 4586
nicholas@926 4587 special: {
nicholas@926 4588 load: {
nicholas@926 4589 // Prevent triggered image.load events from bubbling to window.load
nicholas@926 4590 noBubble: true
nicholas@926 4591 },
nicholas@926 4592 focus: {
nicholas@926 4593 // Fire native event if possible so blur/focus sequence is correct
nicholas@926 4594 trigger: function() {
nicholas@926 4595 if ( this !== safeActiveElement() && this.focus ) {
nicholas@926 4596 this.focus();
nicholas@926 4597 return false;
nicholas@926 4598 }
nicholas@926 4599 },
nicholas@926 4600 delegateType: "focusin"
nicholas@926 4601 },
nicholas@926 4602 blur: {
nicholas@926 4603 trigger: function() {
nicholas@926 4604 if ( this === safeActiveElement() && this.blur ) {
nicholas@926 4605 this.blur();
nicholas@926 4606 return false;
nicholas@926 4607 }
nicholas@926 4608 },
nicholas@926 4609 delegateType: "focusout"
nicholas@926 4610 },
nicholas@926 4611 click: {
nicholas@926 4612 // For checkbox, fire native event so checked state will be right
nicholas@926 4613 trigger: function() {
nicholas@926 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nicholas@926 4615 this.click();
nicholas@926 4616 return false;
nicholas@926 4617 }
nicholas@926 4618 },
nicholas@926 4619
nicholas@926 4620 // For cross-browser consistency, don't fire native .click() on links
nicholas@926 4621 _default: function( event ) {
nicholas@926 4622 return jQuery.nodeName( event.target, "a" );
nicholas@926 4623 }
nicholas@926 4624 },
nicholas@926 4625
nicholas@926 4626 beforeunload: {
nicholas@926 4627 postDispatch: function( event ) {
nicholas@926 4628
nicholas@926 4629 // Support: Firefox 20+
nicholas@926 4630 // Firefox doesn't alert if the returnValue field is not set.
nicholas@926 4631 if ( event.result !== undefined && event.originalEvent ) {
nicholas@926 4632 event.originalEvent.returnValue = event.result;
nicholas@926 4633 }
nicholas@926 4634 }
nicholas@926 4635 }
nicholas@926 4636 },
nicholas@926 4637
nicholas@926 4638 simulate: function( type, elem, event, bubble ) {
nicholas@926 4639 // Piggyback on a donor event to simulate a different one.
nicholas@926 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nicholas@926 4641 // simulated event prevents default then we do the same on the donor.
nicholas@926 4642 var e = jQuery.extend(
nicholas@926 4643 new jQuery.Event(),
nicholas@926 4644 event,
nicholas@926 4645 {
nicholas@926 4646 type: type,
nicholas@926 4647 isSimulated: true,
nicholas@926 4648 originalEvent: {}
nicholas@926 4649 }
nicholas@926 4650 );
nicholas@926 4651 if ( bubble ) {
nicholas@926 4652 jQuery.event.trigger( e, null, elem );
nicholas@926 4653 } else {
nicholas@926 4654 jQuery.event.dispatch.call( elem, e );
nicholas@926 4655 }
nicholas@926 4656 if ( e.isDefaultPrevented() ) {
nicholas@926 4657 event.preventDefault();
nicholas@926 4658 }
nicholas@926 4659 }
nicholas@926 4660 };
nicholas@926 4661
nicholas@926 4662 jQuery.removeEvent = function( elem, type, handle ) {
nicholas@926 4663 if ( elem.removeEventListener ) {
nicholas@926 4664 elem.removeEventListener( type, handle, false );
nicholas@926 4665 }
nicholas@926 4666 };
nicholas@926 4667
nicholas@926 4668 jQuery.Event = function( src, props ) {
nicholas@926 4669 // Allow instantiation without the 'new' keyword
nicholas@926 4670 if ( !(this instanceof jQuery.Event) ) {
nicholas@926 4671 return new jQuery.Event( src, props );
nicholas@926 4672 }
nicholas@926 4673
nicholas@926 4674 // Event object
nicholas@926 4675 if ( src && src.type ) {
nicholas@926 4676 this.originalEvent = src;
nicholas@926 4677 this.type = src.type;
nicholas@926 4678
nicholas@926 4679 // Events bubbling up the document may have been marked as prevented
nicholas@926 4680 // by a handler lower down the tree; reflect the correct value.
nicholas@926 4681 this.isDefaultPrevented = src.defaultPrevented ||
nicholas@926 4682 src.defaultPrevented === undefined &&
nicholas@926 4683 // Support: Android<4.0
nicholas@926 4684 src.returnValue === false ?
nicholas@926 4685 returnTrue :
nicholas@926 4686 returnFalse;
nicholas@926 4687
nicholas@926 4688 // Event type
nicholas@926 4689 } else {
nicholas@926 4690 this.type = src;
nicholas@926 4691 }
nicholas@926 4692
nicholas@926 4693 // Put explicitly provided properties onto the event object
nicholas@926 4694 if ( props ) {
nicholas@926 4695 jQuery.extend( this, props );
nicholas@926 4696 }
nicholas@926 4697
nicholas@926 4698 // Create a timestamp if incoming event doesn't have one
nicholas@926 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nicholas@926 4700
nicholas@926 4701 // Mark it as fixed
nicholas@926 4702 this[ jQuery.expando ] = true;
nicholas@926 4703 };
nicholas@926 4704
nicholas@926 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nicholas@926 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nicholas@926 4707 jQuery.Event.prototype = {
nicholas@926 4708 isDefaultPrevented: returnFalse,
nicholas@926 4709 isPropagationStopped: returnFalse,
nicholas@926 4710 isImmediatePropagationStopped: returnFalse,
nicholas@926 4711
nicholas@926 4712 preventDefault: function() {
nicholas@926 4713 var e = this.originalEvent;
nicholas@926 4714
nicholas@926 4715 this.isDefaultPrevented = returnTrue;
nicholas@926 4716
nicholas@926 4717 if ( e && e.preventDefault ) {
nicholas@926 4718 e.preventDefault();
nicholas@926 4719 }
nicholas@926 4720 },
nicholas@926 4721 stopPropagation: function() {
nicholas@926 4722 var e = this.originalEvent;
nicholas@926 4723
nicholas@926 4724 this.isPropagationStopped = returnTrue;
nicholas@926 4725
nicholas@926 4726 if ( e && e.stopPropagation ) {
nicholas@926 4727 e.stopPropagation();
nicholas@926 4728 }
nicholas@926 4729 },
nicholas@926 4730 stopImmediatePropagation: function() {
nicholas@926 4731 var e = this.originalEvent;
nicholas@926 4732
nicholas@926 4733 this.isImmediatePropagationStopped = returnTrue;
nicholas@926 4734
nicholas@926 4735 if ( e && e.stopImmediatePropagation ) {
nicholas@926 4736 e.stopImmediatePropagation();
nicholas@926 4737 }
nicholas@926 4738
nicholas@926 4739 this.stopPropagation();
nicholas@926 4740 }
nicholas@926 4741 };
nicholas@926 4742
nicholas@926 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nicholas@926 4744 // Support: Chrome 15+
nicholas@926 4745 jQuery.each({
nicholas@926 4746 mouseenter: "mouseover",
nicholas@926 4747 mouseleave: "mouseout",
nicholas@926 4748 pointerenter: "pointerover",
nicholas@926 4749 pointerleave: "pointerout"
nicholas@926 4750 }, function( orig, fix ) {
nicholas@926 4751 jQuery.event.special[ orig ] = {
nicholas@926 4752 delegateType: fix,
nicholas@926 4753 bindType: fix,
nicholas@926 4754
nicholas@926 4755 handle: function( event ) {
nicholas@926 4756 var ret,
nicholas@926 4757 target = this,
nicholas@926 4758 related = event.relatedTarget,
nicholas@926 4759 handleObj = event.handleObj;
nicholas@926 4760
nicholas@926 4761 // For mousenter/leave call the handler if related is outside the target.
nicholas@926 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nicholas@926 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nicholas@926 4764 event.type = handleObj.origType;
nicholas@926 4765 ret = handleObj.handler.apply( this, arguments );
nicholas@926 4766 event.type = fix;
nicholas@926 4767 }
nicholas@926 4768 return ret;
nicholas@926 4769 }
nicholas@926 4770 };
nicholas@926 4771 });
nicholas@926 4772
nicholas@926 4773 // Support: Firefox, Chrome, Safari
nicholas@926 4774 // Create "bubbling" focus and blur events
nicholas@926 4775 if ( !support.focusinBubbles ) {
nicholas@926 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nicholas@926 4777
nicholas@926 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nicholas@926 4779 var handler = function( event ) {
nicholas@926 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nicholas@926 4781 };
nicholas@926 4782
nicholas@926 4783 jQuery.event.special[ fix ] = {
nicholas@926 4784 setup: function() {
nicholas@926 4785 var doc = this.ownerDocument || this,
nicholas@926 4786 attaches = data_priv.access( doc, fix );
nicholas@926 4787
nicholas@926 4788 if ( !attaches ) {
nicholas@926 4789 doc.addEventListener( orig, handler, true );
nicholas@926 4790 }
nicholas@926 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nicholas@926 4792 },
nicholas@926 4793 teardown: function() {
nicholas@926 4794 var doc = this.ownerDocument || this,
nicholas@926 4795 attaches = data_priv.access( doc, fix ) - 1;
nicholas@926 4796
nicholas@926 4797 if ( !attaches ) {
nicholas@926 4798 doc.removeEventListener( orig, handler, true );
nicholas@926 4799 data_priv.remove( doc, fix );
nicholas@926 4800
nicholas@926 4801 } else {
nicholas@926 4802 data_priv.access( doc, fix, attaches );
nicholas@926 4803 }
nicholas@926 4804 }
nicholas@926 4805 };
nicholas@926 4806 });
nicholas@926 4807 }
nicholas@926 4808
nicholas@926 4809 jQuery.fn.extend({
nicholas@926 4810
nicholas@926 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nicholas@926 4812 var origFn, type;
nicholas@926 4813
nicholas@926 4814 // Types can be a map of types/handlers
nicholas@926 4815 if ( typeof types === "object" ) {
nicholas@926 4816 // ( types-Object, selector, data )
nicholas@926 4817 if ( typeof selector !== "string" ) {
nicholas@926 4818 // ( types-Object, data )
nicholas@926 4819 data = data || selector;
nicholas@926 4820 selector = undefined;
nicholas@926 4821 }
nicholas@926 4822 for ( type in types ) {
nicholas@926 4823 this.on( type, selector, data, types[ type ], one );
nicholas@926 4824 }
nicholas@926 4825 return this;
nicholas@926 4826 }
nicholas@926 4827
nicholas@926 4828 if ( data == null && fn == null ) {
nicholas@926 4829 // ( types, fn )
nicholas@926 4830 fn = selector;
nicholas@926 4831 data = selector = undefined;
nicholas@926 4832 } else if ( fn == null ) {
nicholas@926 4833 if ( typeof selector === "string" ) {
nicholas@926 4834 // ( types, selector, fn )
nicholas@926 4835 fn = data;
nicholas@926 4836 data = undefined;
nicholas@926 4837 } else {
nicholas@926 4838 // ( types, data, fn )
nicholas@926 4839 fn = data;
nicholas@926 4840 data = selector;
nicholas@926 4841 selector = undefined;
nicholas@926 4842 }
nicholas@926 4843 }
nicholas@926 4844 if ( fn === false ) {
nicholas@926 4845 fn = returnFalse;
nicholas@926 4846 } else if ( !fn ) {
nicholas@926 4847 return this;
nicholas@926 4848 }
nicholas@926 4849
nicholas@926 4850 if ( one === 1 ) {
nicholas@926 4851 origFn = fn;
nicholas@926 4852 fn = function( event ) {
nicholas@926 4853 // Can use an empty set, since event contains the info
nicholas@926 4854 jQuery().off( event );
nicholas@926 4855 return origFn.apply( this, arguments );
nicholas@926 4856 };
nicholas@926 4857 // Use same guid so caller can remove using origFn
nicholas@926 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nicholas@926 4859 }
nicholas@926 4860 return this.each( function() {
nicholas@926 4861 jQuery.event.add( this, types, fn, data, selector );
nicholas@926 4862 });
nicholas@926 4863 },
nicholas@926 4864 one: function( types, selector, data, fn ) {
nicholas@926 4865 return this.on( types, selector, data, fn, 1 );
nicholas@926 4866 },
nicholas@926 4867 off: function( types, selector, fn ) {
nicholas@926 4868 var handleObj, type;
nicholas@926 4869 if ( types && types.preventDefault && types.handleObj ) {
nicholas@926 4870 // ( event ) dispatched jQuery.Event
nicholas@926 4871 handleObj = types.handleObj;
nicholas@926 4872 jQuery( types.delegateTarget ).off(
nicholas@926 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nicholas@926 4874 handleObj.selector,
nicholas@926 4875 handleObj.handler
nicholas@926 4876 );
nicholas@926 4877 return this;
nicholas@926 4878 }
nicholas@926 4879 if ( typeof types === "object" ) {
nicholas@926 4880 // ( types-object [, selector] )
nicholas@926 4881 for ( type in types ) {
nicholas@926 4882 this.off( type, selector, types[ type ] );
nicholas@926 4883 }
nicholas@926 4884 return this;
nicholas@926 4885 }
nicholas@926 4886 if ( selector === false || typeof selector === "function" ) {
nicholas@926 4887 // ( types [, fn] )
nicholas@926 4888 fn = selector;
nicholas@926 4889 selector = undefined;
nicholas@926 4890 }
nicholas@926 4891 if ( fn === false ) {
nicholas@926 4892 fn = returnFalse;
nicholas@926 4893 }
nicholas@926 4894 return this.each(function() {
nicholas@926 4895 jQuery.event.remove( this, types, fn, selector );
nicholas@926 4896 });
nicholas@926 4897 },
nicholas@926 4898
nicholas@926 4899 trigger: function( type, data ) {
nicholas@926 4900 return this.each(function() {
nicholas@926 4901 jQuery.event.trigger( type, data, this );
nicholas@926 4902 });
nicholas@926 4903 },
nicholas@926 4904 triggerHandler: function( type, data ) {
nicholas@926 4905 var elem = this[0];
nicholas@926 4906 if ( elem ) {
nicholas@926 4907 return jQuery.event.trigger( type, data, elem, true );
nicholas@926 4908 }
nicholas@926 4909 }
nicholas@926 4910 });
nicholas@926 4911
nicholas@926 4912
nicholas@926 4913 var
nicholas@926 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nicholas@926 4915 rtagName = /<([\w:]+)/,
nicholas@926 4916 rhtml = /<|&#?\w+;/,
nicholas@926 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nicholas@926 4918 // checked="checked" or checked
nicholas@926 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nicholas@926 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nicholas@926 4921 rscriptTypeMasked = /^true\/(.*)/,
nicholas@926 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nicholas@926 4923
nicholas@926 4924 // We have to close these tags to support XHTML (#13200)
nicholas@926 4925 wrapMap = {
nicholas@926 4926
nicholas@926 4927 // Support: IE9
nicholas@926 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nicholas@926 4929
nicholas@926 4930 thead: [ 1, "<table>", "</table>" ],
nicholas@926 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nicholas@926 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nicholas@926 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nicholas@926 4934
nicholas@926 4935 _default: [ 0, "", "" ]
nicholas@926 4936 };
nicholas@926 4937
nicholas@926 4938 // Support: IE9
nicholas@926 4939 wrapMap.optgroup = wrapMap.option;
nicholas@926 4940
nicholas@926 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nicholas@926 4942 wrapMap.th = wrapMap.td;
nicholas@926 4943
nicholas@926 4944 // Support: 1.x compatibility
nicholas@926 4945 // Manipulating tables requires a tbody
nicholas@926 4946 function manipulationTarget( elem, content ) {
nicholas@926 4947 return jQuery.nodeName( elem, "table" ) &&
nicholas@926 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nicholas@926 4949
nicholas@926 4950 elem.getElementsByTagName("tbody")[0] ||
nicholas@926 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nicholas@926 4952 elem;
nicholas@926 4953 }
nicholas@926 4954
nicholas@926 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nicholas@926 4956 function disableScript( elem ) {
nicholas@926 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nicholas@926 4958 return elem;
nicholas@926 4959 }
nicholas@926 4960 function restoreScript( elem ) {
nicholas@926 4961 var match = rscriptTypeMasked.exec( elem.type );
nicholas@926 4962
nicholas@926 4963 if ( match ) {
nicholas@926 4964 elem.type = match[ 1 ];
nicholas@926 4965 } else {
nicholas@926 4966 elem.removeAttribute("type");
nicholas@926 4967 }
nicholas@926 4968
nicholas@926 4969 return elem;
nicholas@926 4970 }
nicholas@926 4971
nicholas@926 4972 // Mark scripts as having already been evaluated
nicholas@926 4973 function setGlobalEval( elems, refElements ) {
nicholas@926 4974 var i = 0,
nicholas@926 4975 l = elems.length;
nicholas@926 4976
nicholas@926 4977 for ( ; i < l; i++ ) {
nicholas@926 4978 data_priv.set(
nicholas@926 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nicholas@926 4980 );
nicholas@926 4981 }
nicholas@926 4982 }
nicholas@926 4983
nicholas@926 4984 function cloneCopyEvent( src, dest ) {
nicholas@926 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nicholas@926 4986
nicholas@926 4987 if ( dest.nodeType !== 1 ) {
nicholas@926 4988 return;
nicholas@926 4989 }
nicholas@926 4990
nicholas@926 4991 // 1. Copy private data: events, handlers, etc.
nicholas@926 4992 if ( data_priv.hasData( src ) ) {
nicholas@926 4993 pdataOld = data_priv.access( src );
nicholas@926 4994 pdataCur = data_priv.set( dest, pdataOld );
nicholas@926 4995 events = pdataOld.events;
nicholas@926 4996
nicholas@926 4997 if ( events ) {
nicholas@926 4998 delete pdataCur.handle;
nicholas@926 4999 pdataCur.events = {};
nicholas@926 5000
nicholas@926 5001 for ( type in events ) {
nicholas@926 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nicholas@926 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nicholas@926 5004 }
nicholas@926 5005 }
nicholas@926 5006 }
nicholas@926 5007 }
nicholas@926 5008
nicholas@926 5009 // 2. Copy user data
nicholas@926 5010 if ( data_user.hasData( src ) ) {
nicholas@926 5011 udataOld = data_user.access( src );
nicholas@926 5012 udataCur = jQuery.extend( {}, udataOld );
nicholas@926 5013
nicholas@926 5014 data_user.set( dest, udataCur );
nicholas@926 5015 }
nicholas@926 5016 }
nicholas@926 5017
nicholas@926 5018 function getAll( context, tag ) {
nicholas@926 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nicholas@926 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nicholas@926 5021 [];
nicholas@926 5022
nicholas@926 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nicholas@926 5024 jQuery.merge( [ context ], ret ) :
nicholas@926 5025 ret;
nicholas@926 5026 }
nicholas@926 5027
nicholas@926 5028 // Fix IE bugs, see support tests
nicholas@926 5029 function fixInput( src, dest ) {
nicholas@926 5030 var nodeName = dest.nodeName.toLowerCase();
nicholas@926 5031
nicholas@926 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nicholas@926 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nicholas@926 5034 dest.checked = src.checked;
nicholas@926 5035
nicholas@926 5036 // Fails to return the selected option to the default selected state when cloning options
nicholas@926 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nicholas@926 5038 dest.defaultValue = src.defaultValue;
nicholas@926 5039 }
nicholas@926 5040 }
nicholas@926 5041
nicholas@926 5042 jQuery.extend({
nicholas@926 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nicholas@926 5044 var i, l, srcElements, destElements,
nicholas@926 5045 clone = elem.cloneNode( true ),
nicholas@926 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nicholas@926 5047
nicholas@926 5048 // Fix IE cloning issues
nicholas@926 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nicholas@926 5050 !jQuery.isXMLDoc( elem ) ) {
nicholas@926 5051
nicholas@926 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nicholas@926 5053 destElements = getAll( clone );
nicholas@926 5054 srcElements = getAll( elem );
nicholas@926 5055
nicholas@926 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nicholas@926 5057 fixInput( srcElements[ i ], destElements[ i ] );
nicholas@926 5058 }
nicholas@926 5059 }
nicholas@926 5060
nicholas@926 5061 // Copy the events from the original to the clone
nicholas@926 5062 if ( dataAndEvents ) {
nicholas@926 5063 if ( deepDataAndEvents ) {
nicholas@926 5064 srcElements = srcElements || getAll( elem );
nicholas@926 5065 destElements = destElements || getAll( clone );
nicholas@926 5066
nicholas@926 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nicholas@926 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nicholas@926 5069 }
nicholas@926 5070 } else {
nicholas@926 5071 cloneCopyEvent( elem, clone );
nicholas@926 5072 }
nicholas@926 5073 }
nicholas@926 5074
nicholas@926 5075 // Preserve script evaluation history
nicholas@926 5076 destElements = getAll( clone, "script" );
nicholas@926 5077 if ( destElements.length > 0 ) {
nicholas@926 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nicholas@926 5079 }
nicholas@926 5080
nicholas@926 5081 // Return the cloned set
nicholas@926 5082 return clone;
nicholas@926 5083 },
nicholas@926 5084
nicholas@926 5085 buildFragment: function( elems, context, scripts, selection ) {
nicholas@926 5086 var elem, tmp, tag, wrap, contains, j,
nicholas@926 5087 fragment = context.createDocumentFragment(),
nicholas@926 5088 nodes = [],
nicholas@926 5089 i = 0,
nicholas@926 5090 l = elems.length;
nicholas@926 5091
nicholas@926 5092 for ( ; i < l; i++ ) {
nicholas@926 5093 elem = elems[ i ];
nicholas@926 5094
nicholas@926 5095 if ( elem || elem === 0 ) {
nicholas@926 5096
nicholas@926 5097 // Add nodes directly
nicholas@926 5098 if ( jQuery.type( elem ) === "object" ) {
nicholas@926 5099 // Support: QtWebKit, PhantomJS
nicholas@926 5100 // push.apply(_, arraylike) throws on ancient WebKit
nicholas@926 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nicholas@926 5102
nicholas@926 5103 // Convert non-html into a text node
nicholas@926 5104 } else if ( !rhtml.test( elem ) ) {
nicholas@926 5105 nodes.push( context.createTextNode( elem ) );
nicholas@926 5106
nicholas@926 5107 // Convert html into DOM nodes
nicholas@926 5108 } else {
nicholas@926 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nicholas@926 5110
nicholas@926 5111 // Deserialize a standard representation
nicholas@926 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nicholas@926 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nicholas@926 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nicholas@926 5115
nicholas@926 5116 // Descend through wrappers to the right content
nicholas@926 5117 j = wrap[ 0 ];
nicholas@926 5118 while ( j-- ) {
nicholas@926 5119 tmp = tmp.lastChild;
nicholas@926 5120 }
nicholas@926 5121
nicholas@926 5122 // Support: QtWebKit, PhantomJS
nicholas@926 5123 // push.apply(_, arraylike) throws on ancient WebKit
nicholas@926 5124 jQuery.merge( nodes, tmp.childNodes );
nicholas@926 5125
nicholas@926 5126 // Remember the top-level container
nicholas@926 5127 tmp = fragment.firstChild;
nicholas@926 5128
nicholas@926 5129 // Ensure the created nodes are orphaned (#12392)
nicholas@926 5130 tmp.textContent = "";
nicholas@926 5131 }
nicholas@926 5132 }
nicholas@926 5133 }
nicholas@926 5134
nicholas@926 5135 // Remove wrapper from fragment
nicholas@926 5136 fragment.textContent = "";
nicholas@926 5137
nicholas@926 5138 i = 0;
nicholas@926 5139 while ( (elem = nodes[ i++ ]) ) {
nicholas@926 5140
nicholas@926 5141 // #4087 - If origin and destination elements are the same, and this is
nicholas@926 5142 // that element, do not do anything
nicholas@926 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nicholas@926 5144 continue;
nicholas@926 5145 }
nicholas@926 5146
nicholas@926 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nicholas@926 5148
nicholas@926 5149 // Append to fragment
nicholas@926 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nicholas@926 5151
nicholas@926 5152 // Preserve script evaluation history
nicholas@926 5153 if ( contains ) {
nicholas@926 5154 setGlobalEval( tmp );
nicholas@926 5155 }
nicholas@926 5156
nicholas@926 5157 // Capture executables
nicholas@926 5158 if ( scripts ) {
nicholas@926 5159 j = 0;
nicholas@926 5160 while ( (elem = tmp[ j++ ]) ) {
nicholas@926 5161 if ( rscriptType.test( elem.type || "" ) ) {
nicholas@926 5162 scripts.push( elem );
nicholas@926 5163 }
nicholas@926 5164 }
nicholas@926 5165 }
nicholas@926 5166 }
nicholas@926 5167
nicholas@926 5168 return fragment;
nicholas@926 5169 },
nicholas@926 5170
nicholas@926 5171 cleanData: function( elems ) {
nicholas@926 5172 var data, elem, type, key,
nicholas@926 5173 special = jQuery.event.special,
nicholas@926 5174 i = 0;
nicholas@926 5175
nicholas@926 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nicholas@926 5177 if ( jQuery.acceptData( elem ) ) {
nicholas@926 5178 key = elem[ data_priv.expando ];
nicholas@926 5179
nicholas@926 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nicholas@926 5181 if ( data.events ) {
nicholas@926 5182 for ( type in data.events ) {
nicholas@926 5183 if ( special[ type ] ) {
nicholas@926 5184 jQuery.event.remove( elem, type );
nicholas@926 5185
nicholas@926 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nicholas@926 5187 } else {
nicholas@926 5188 jQuery.removeEvent( elem, type, data.handle );
nicholas@926 5189 }
nicholas@926 5190 }
nicholas@926 5191 }
nicholas@926 5192 if ( data_priv.cache[ key ] ) {
nicholas@926 5193 // Discard any remaining `private` data
nicholas@926 5194 delete data_priv.cache[ key ];
nicholas@926 5195 }
nicholas@926 5196 }
nicholas@926 5197 }
nicholas@926 5198 // Discard any remaining `user` data
nicholas@926 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nicholas@926 5200 }
nicholas@926 5201 }
nicholas@926 5202 });
nicholas@926 5203
nicholas@926 5204 jQuery.fn.extend({
nicholas@926 5205 text: function( value ) {
nicholas@926 5206 return access( this, function( value ) {
nicholas@926 5207 return value === undefined ?
nicholas@926 5208 jQuery.text( this ) :
nicholas@926 5209 this.empty().each(function() {
nicholas@926 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@926 5211 this.textContent = value;
nicholas@926 5212 }
nicholas@926 5213 });
nicholas@926 5214 }, null, value, arguments.length );
nicholas@926 5215 },
nicholas@926 5216
nicholas@926 5217 append: function() {
nicholas@926 5218 return this.domManip( arguments, function( elem ) {
nicholas@926 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@926 5220 var target = manipulationTarget( this, elem );
nicholas@926 5221 target.appendChild( elem );
nicholas@926 5222 }
nicholas@926 5223 });
nicholas@926 5224 },
nicholas@926 5225
nicholas@926 5226 prepend: function() {
nicholas@926 5227 return this.domManip( arguments, function( elem ) {
nicholas@926 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@926 5229 var target = manipulationTarget( this, elem );
nicholas@926 5230 target.insertBefore( elem, target.firstChild );
nicholas@926 5231 }
nicholas@926 5232 });
nicholas@926 5233 },
nicholas@926 5234
nicholas@926 5235 before: function() {
nicholas@926 5236 return this.domManip( arguments, function( elem ) {
nicholas@926 5237 if ( this.parentNode ) {
nicholas@926 5238 this.parentNode.insertBefore( elem, this );
nicholas@926 5239 }
nicholas@926 5240 });
nicholas@926 5241 },
nicholas@926 5242
nicholas@926 5243 after: function() {
nicholas@926 5244 return this.domManip( arguments, function( elem ) {
nicholas@926 5245 if ( this.parentNode ) {
nicholas@926 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nicholas@926 5247 }
nicholas@926 5248 });
nicholas@926 5249 },
nicholas@926 5250
nicholas@926 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nicholas@926 5252 var elem,
nicholas@926 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nicholas@926 5254 i = 0;
nicholas@926 5255
nicholas@926 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nicholas@926 5257 if ( !keepData && elem.nodeType === 1 ) {
nicholas@926 5258 jQuery.cleanData( getAll( elem ) );
nicholas@926 5259 }
nicholas@926 5260
nicholas@926 5261 if ( elem.parentNode ) {
nicholas@926 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nicholas@926 5263 setGlobalEval( getAll( elem, "script" ) );
nicholas@926 5264 }
nicholas@926 5265 elem.parentNode.removeChild( elem );
nicholas@926 5266 }
nicholas@926 5267 }
nicholas@926 5268
nicholas@926 5269 return this;
nicholas@926 5270 },
nicholas@926 5271
nicholas@926 5272 empty: function() {
nicholas@926 5273 var elem,
nicholas@926 5274 i = 0;
nicholas@926 5275
nicholas@926 5276 for ( ; (elem = this[i]) != null; i++ ) {
nicholas@926 5277 if ( elem.nodeType === 1 ) {
nicholas@926 5278
nicholas@926 5279 // Prevent memory leaks
nicholas@926 5280 jQuery.cleanData( getAll( elem, false ) );
nicholas@926 5281
nicholas@926 5282 // Remove any remaining nodes
nicholas@926 5283 elem.textContent = "";
nicholas@926 5284 }
nicholas@926 5285 }
nicholas@926 5286
nicholas@926 5287 return this;
nicholas@926 5288 },
nicholas@926 5289
nicholas@926 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nicholas@926 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nicholas@926 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nicholas@926 5293
nicholas@926 5294 return this.map(function() {
nicholas@926 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nicholas@926 5296 });
nicholas@926 5297 },
nicholas@926 5298
nicholas@926 5299 html: function( value ) {
nicholas@926 5300 return access( this, function( value ) {
nicholas@926 5301 var elem = this[ 0 ] || {},
nicholas@926 5302 i = 0,
nicholas@926 5303 l = this.length;
nicholas@926 5304
nicholas@926 5305 if ( value === undefined && elem.nodeType === 1 ) {
nicholas@926 5306 return elem.innerHTML;
nicholas@926 5307 }
nicholas@926 5308
nicholas@926 5309 // See if we can take a shortcut and just use innerHTML
nicholas@926 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nicholas@926 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nicholas@926 5312
nicholas@926 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nicholas@926 5314
nicholas@926 5315 try {
nicholas@926 5316 for ( ; i < l; i++ ) {
nicholas@926 5317 elem = this[ i ] || {};
nicholas@926 5318
nicholas@926 5319 // Remove element nodes and prevent memory leaks
nicholas@926 5320 if ( elem.nodeType === 1 ) {
nicholas@926 5321 jQuery.cleanData( getAll( elem, false ) );
nicholas@926 5322 elem.innerHTML = value;
nicholas@926 5323 }
nicholas@926 5324 }
nicholas@926 5325
nicholas@926 5326 elem = 0;
nicholas@926 5327
nicholas@926 5328 // If using innerHTML throws an exception, use the fallback method
nicholas@926 5329 } catch( e ) {}
nicholas@926 5330 }
nicholas@926 5331
nicholas@926 5332 if ( elem ) {
nicholas@926 5333 this.empty().append( value );
nicholas@926 5334 }
nicholas@926 5335 }, null, value, arguments.length );
nicholas@926 5336 },
nicholas@926 5337
nicholas@926 5338 replaceWith: function() {
nicholas@926 5339 var arg = arguments[ 0 ];
nicholas@926 5340
nicholas@926 5341 // Make the changes, replacing each context element with the new content
nicholas@926 5342 this.domManip( arguments, function( elem ) {
nicholas@926 5343 arg = this.parentNode;
nicholas@926 5344
nicholas@926 5345 jQuery.cleanData( getAll( this ) );
nicholas@926 5346
nicholas@926 5347 if ( arg ) {
nicholas@926 5348 arg.replaceChild( elem, this );
nicholas@926 5349 }
nicholas@926 5350 });
nicholas@926 5351
nicholas@926 5352 // Force removal if there was no new content (e.g., from empty arguments)
nicholas@926 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nicholas@926 5354 },
nicholas@926 5355
nicholas@926 5356 detach: function( selector ) {
nicholas@926 5357 return this.remove( selector, true );
nicholas@926 5358 },
nicholas@926 5359
nicholas@926 5360 domManip: function( args, callback ) {
nicholas@926 5361
nicholas@926 5362 // Flatten any nested arrays
nicholas@926 5363 args = concat.apply( [], args );
nicholas@926 5364
nicholas@926 5365 var fragment, first, scripts, hasScripts, node, doc,
nicholas@926 5366 i = 0,
nicholas@926 5367 l = this.length,
nicholas@926 5368 set = this,
nicholas@926 5369 iNoClone = l - 1,
nicholas@926 5370 value = args[ 0 ],
nicholas@926 5371 isFunction = jQuery.isFunction( value );
nicholas@926 5372
nicholas@926 5373 // We can't cloneNode fragments that contain checked, in WebKit
nicholas@926 5374 if ( isFunction ||
nicholas@926 5375 ( l > 1 && typeof value === "string" &&
nicholas@926 5376 !support.checkClone && rchecked.test( value ) ) ) {
nicholas@926 5377 return this.each(function( index ) {
nicholas@926 5378 var self = set.eq( index );
nicholas@926 5379 if ( isFunction ) {
nicholas@926 5380 args[ 0 ] = value.call( this, index, self.html() );
nicholas@926 5381 }
nicholas@926 5382 self.domManip( args, callback );
nicholas@926 5383 });
nicholas@926 5384 }
nicholas@926 5385
nicholas@926 5386 if ( l ) {
nicholas@926 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nicholas@926 5388 first = fragment.firstChild;
nicholas@926 5389
nicholas@926 5390 if ( fragment.childNodes.length === 1 ) {
nicholas@926 5391 fragment = first;
nicholas@926 5392 }
nicholas@926 5393
nicholas@926 5394 if ( first ) {
nicholas@926 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nicholas@926 5396 hasScripts = scripts.length;
nicholas@926 5397
nicholas@926 5398 // Use the original fragment for the last item instead of the first because it can end up
nicholas@926 5399 // being emptied incorrectly in certain situations (#8070).
nicholas@926 5400 for ( ; i < l; i++ ) {
nicholas@926 5401 node = fragment;
nicholas@926 5402
nicholas@926 5403 if ( i !== iNoClone ) {
nicholas@926 5404 node = jQuery.clone( node, true, true );
nicholas@926 5405
nicholas@926 5406 // Keep references to cloned scripts for later restoration
nicholas@926 5407 if ( hasScripts ) {
nicholas@926 5408 // Support: QtWebKit
nicholas@926 5409 // jQuery.merge because push.apply(_, arraylike) throws
nicholas@926 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nicholas@926 5411 }
nicholas@926 5412 }
nicholas@926 5413
nicholas@926 5414 callback.call( this[ i ], node, i );
nicholas@926 5415 }
nicholas@926 5416
nicholas@926 5417 if ( hasScripts ) {
nicholas@926 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nicholas@926 5419
nicholas@926 5420 // Reenable scripts
nicholas@926 5421 jQuery.map( scripts, restoreScript );
nicholas@926 5422
nicholas@926 5423 // Evaluate executable scripts on first document insertion
nicholas@926 5424 for ( i = 0; i < hasScripts; i++ ) {
nicholas@926 5425 node = scripts[ i ];
nicholas@926 5426 if ( rscriptType.test( node.type || "" ) &&
nicholas@926 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nicholas@926 5428
nicholas@926 5429 if ( node.src ) {
nicholas@926 5430 // Optional AJAX dependency, but won't run scripts if not present
nicholas@926 5431 if ( jQuery._evalUrl ) {
nicholas@926 5432 jQuery._evalUrl( node.src );
nicholas@926 5433 }
nicholas@926 5434 } else {
nicholas@926 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nicholas@926 5436 }
nicholas@926 5437 }
nicholas@926 5438 }
nicholas@926 5439 }
nicholas@926 5440 }
nicholas@926 5441 }
nicholas@926 5442
nicholas@926 5443 return this;
nicholas@926 5444 }
nicholas@926 5445 });
nicholas@926 5446
nicholas@926 5447 jQuery.each({
nicholas@926 5448 appendTo: "append",
nicholas@926 5449 prependTo: "prepend",
nicholas@926 5450 insertBefore: "before",
nicholas@926 5451 insertAfter: "after",
nicholas@926 5452 replaceAll: "replaceWith"
nicholas@926 5453 }, function( name, original ) {
nicholas@926 5454 jQuery.fn[ name ] = function( selector ) {
nicholas@926 5455 var elems,
nicholas@926 5456 ret = [],
nicholas@926 5457 insert = jQuery( selector ),
nicholas@926 5458 last = insert.length - 1,
nicholas@926 5459 i = 0;
nicholas@926 5460
nicholas@926 5461 for ( ; i <= last; i++ ) {
nicholas@926 5462 elems = i === last ? this : this.clone( true );
nicholas@926 5463 jQuery( insert[ i ] )[ original ]( elems );
nicholas@926 5464
nicholas@926 5465 // Support: QtWebKit
nicholas@926 5466 // .get() because push.apply(_, arraylike) throws
nicholas@926 5467 push.apply( ret, elems.get() );
nicholas@926 5468 }
nicholas@926 5469
nicholas@926 5470 return this.pushStack( ret );
nicholas@926 5471 };
nicholas@926 5472 });
nicholas@926 5473
nicholas@926 5474
nicholas@926 5475 var iframe,
nicholas@926 5476 elemdisplay = {};
nicholas@926 5477
nicholas@926 5478 /**
nicholas@926 5479 * Retrieve the actual display of a element
nicholas@926 5480 * @param {String} name nodeName of the element
nicholas@926 5481 * @param {Object} doc Document object
nicholas@926 5482 */
nicholas@926 5483 // Called only from within defaultDisplay
nicholas@926 5484 function actualDisplay( name, doc ) {
nicholas@926 5485 var style,
nicholas@926 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nicholas@926 5487
nicholas@926 5488 // getDefaultComputedStyle might be reliably used only on attached element
nicholas@926 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nicholas@926 5490
nicholas@926 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nicholas@926 5492 // since it was removed from specification and supported only in FF
nicholas@926 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nicholas@926 5494
nicholas@926 5495 // We don't have any data stored on the element,
nicholas@926 5496 // so use "detach" method as fast way to get rid of the element
nicholas@926 5497 elem.detach();
nicholas@926 5498
nicholas@926 5499 return display;
nicholas@926 5500 }
nicholas@926 5501
nicholas@926 5502 /**
nicholas@926 5503 * Try to determine the default display value of an element
nicholas@926 5504 * @param {String} nodeName
nicholas@926 5505 */
nicholas@926 5506 function defaultDisplay( nodeName ) {
nicholas@926 5507 var doc = document,
nicholas@926 5508 display = elemdisplay[ nodeName ];
nicholas@926 5509
nicholas@926 5510 if ( !display ) {
nicholas@926 5511 display = actualDisplay( nodeName, doc );
nicholas@926 5512
nicholas@926 5513 // If the simple way fails, read from inside an iframe
nicholas@926 5514 if ( display === "none" || !display ) {
nicholas@926 5515
nicholas@926 5516 // Use the already-created iframe if possible
nicholas@926 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nicholas@926 5518
nicholas@926 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nicholas@926 5520 doc = iframe[ 0 ].contentDocument;
nicholas@926 5521
nicholas@926 5522 // Support: IE
nicholas@926 5523 doc.write();
nicholas@926 5524 doc.close();
nicholas@926 5525
nicholas@926 5526 display = actualDisplay( nodeName, doc );
nicholas@926 5527 iframe.detach();
nicholas@926 5528 }
nicholas@926 5529
nicholas@926 5530 // Store the correct default display
nicholas@926 5531 elemdisplay[ nodeName ] = display;
nicholas@926 5532 }
nicholas@926 5533
nicholas@926 5534 return display;
nicholas@926 5535 }
nicholas@926 5536 var rmargin = (/^margin/);
nicholas@926 5537
nicholas@926 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nicholas@926 5539
nicholas@926 5540 var getStyles = function( elem ) {
nicholas@926 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nicholas@926 5542 // IE throws on elements created in popups
nicholas@926 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nicholas@926 5544 if ( elem.ownerDocument.defaultView.opener ) {
nicholas@926 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nicholas@926 5546 }
nicholas@926 5547
nicholas@926 5548 return window.getComputedStyle( elem, null );
nicholas@926 5549 };
nicholas@926 5550
nicholas@926 5551
nicholas@926 5552
nicholas@926 5553 function curCSS( elem, name, computed ) {
nicholas@926 5554 var width, minWidth, maxWidth, ret,
nicholas@926 5555 style = elem.style;
nicholas@926 5556
nicholas@926 5557 computed = computed || getStyles( elem );
nicholas@926 5558
nicholas@926 5559 // Support: IE9
nicholas@926 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nicholas@926 5561 if ( computed ) {
nicholas@926 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nicholas@926 5563 }
nicholas@926 5564
nicholas@926 5565 if ( computed ) {
nicholas@926 5566
nicholas@926 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nicholas@926 5568 ret = jQuery.style( elem, name );
nicholas@926 5569 }
nicholas@926 5570
nicholas@926 5571 // Support: iOS < 6
nicholas@926 5572 // A tribute to the "awesome hack by Dean Edwards"
nicholas@926 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nicholas@926 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nicholas@926 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nicholas@926 5576
nicholas@926 5577 // Remember the original values
nicholas@926 5578 width = style.width;
nicholas@926 5579 minWidth = style.minWidth;
nicholas@926 5580 maxWidth = style.maxWidth;
nicholas@926 5581
nicholas@926 5582 // Put in the new values to get a computed value out
nicholas@926 5583 style.minWidth = style.maxWidth = style.width = ret;
nicholas@926 5584 ret = computed.width;
nicholas@926 5585
nicholas@926 5586 // Revert the changed values
nicholas@926 5587 style.width = width;
nicholas@926 5588 style.minWidth = minWidth;
nicholas@926 5589 style.maxWidth = maxWidth;
nicholas@926 5590 }
nicholas@926 5591 }
nicholas@926 5592
nicholas@926 5593 return ret !== undefined ?
nicholas@926 5594 // Support: IE
nicholas@926 5595 // IE returns zIndex value as an integer.
nicholas@926 5596 ret + "" :
nicholas@926 5597 ret;
nicholas@926 5598 }
nicholas@926 5599
nicholas@926 5600
nicholas@926 5601 function addGetHookIf( conditionFn, hookFn ) {
nicholas@926 5602 // Define the hook, we'll check on the first run if it's really needed.
nicholas@926 5603 return {
nicholas@926 5604 get: function() {
nicholas@926 5605 if ( conditionFn() ) {
nicholas@926 5606 // Hook not needed (or it's not possible to use it due
nicholas@926 5607 // to missing dependency), remove it.
nicholas@926 5608 delete this.get;
nicholas@926 5609 return;
nicholas@926 5610 }
nicholas@926 5611
nicholas@926 5612 // Hook needed; redefine it so that the support test is not executed again.
nicholas@926 5613 return (this.get = hookFn).apply( this, arguments );
nicholas@926 5614 }
nicholas@926 5615 };
nicholas@926 5616 }
nicholas@926 5617
nicholas@926 5618
nicholas@926 5619 (function() {
nicholas@926 5620 var pixelPositionVal, boxSizingReliableVal,
nicholas@926 5621 docElem = document.documentElement,
nicholas@926 5622 container = document.createElement( "div" ),
nicholas@926 5623 div = document.createElement( "div" );
nicholas@926 5624
nicholas@926 5625 if ( !div.style ) {
nicholas@926 5626 return;
nicholas@926 5627 }
nicholas@926 5628
nicholas@926 5629 // Support: IE9-11+
nicholas@926 5630 // Style of cloned element affects source element cloned (#8908)
nicholas@926 5631 div.style.backgroundClip = "content-box";
nicholas@926 5632 div.cloneNode( true ).style.backgroundClip = "";
nicholas@926 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nicholas@926 5634
nicholas@926 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nicholas@926 5636 "position:absolute";
nicholas@926 5637 container.appendChild( div );
nicholas@926 5638
nicholas@926 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nicholas@926 5640 // so they're executed at the same time to save the second computation.
nicholas@926 5641 function computePixelPositionAndBoxSizingReliable() {
nicholas@926 5642 div.style.cssText =
nicholas@926 5643 // Support: Firefox<29, Android 2.3
nicholas@926 5644 // Vendor-prefix box-sizing
nicholas@926 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nicholas@926 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nicholas@926 5647 "border:1px;padding:1px;width:4px;position:absolute";
nicholas@926 5648 div.innerHTML = "";
nicholas@926 5649 docElem.appendChild( container );
nicholas@926 5650
nicholas@926 5651 var divStyle = window.getComputedStyle( div, null );
nicholas@926 5652 pixelPositionVal = divStyle.top !== "1%";
nicholas@926 5653 boxSizingReliableVal = divStyle.width === "4px";
nicholas@926 5654
nicholas@926 5655 docElem.removeChild( container );
nicholas@926 5656 }
nicholas@926 5657
nicholas@926 5658 // Support: node.js jsdom
nicholas@926 5659 // Don't assume that getComputedStyle is a property of the global object
nicholas@926 5660 if ( window.getComputedStyle ) {
nicholas@926 5661 jQuery.extend( support, {
nicholas@926 5662 pixelPosition: function() {
nicholas@926 5663
nicholas@926 5664 // This test is executed only once but we still do memoizing
nicholas@926 5665 // since we can use the boxSizingReliable pre-computing.
nicholas@926 5666 // No need to check if the test was already performed, though.
nicholas@926 5667 computePixelPositionAndBoxSizingReliable();
nicholas@926 5668 return pixelPositionVal;
nicholas@926 5669 },
nicholas@926 5670 boxSizingReliable: function() {
nicholas@926 5671 if ( boxSizingReliableVal == null ) {
nicholas@926 5672 computePixelPositionAndBoxSizingReliable();
nicholas@926 5673 }
nicholas@926 5674 return boxSizingReliableVal;
nicholas@926 5675 },
nicholas@926 5676 reliableMarginRight: function() {
nicholas@926 5677
nicholas@926 5678 // Support: Android 2.3
nicholas@926 5679 // Check if div with explicit width and no margin-right incorrectly
nicholas@926 5680 // gets computed margin-right based on width of container. (#3333)
nicholas@926 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nicholas@926 5682 // This support function is only executed once so no memoizing is needed.
nicholas@926 5683 var ret,
nicholas@926 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nicholas@926 5685
nicholas@926 5686 // Reset CSS: box-sizing; display; margin; border; padding
nicholas@926 5687 marginDiv.style.cssText = div.style.cssText =
nicholas@926 5688 // Support: Firefox<29, Android 2.3
nicholas@926 5689 // Vendor-prefix box-sizing
nicholas@926 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nicholas@926 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nicholas@926 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nicholas@926 5693 div.style.width = "1px";
nicholas@926 5694 docElem.appendChild( container );
nicholas@926 5695
nicholas@926 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nicholas@926 5697
nicholas@926 5698 docElem.removeChild( container );
nicholas@926 5699 div.removeChild( marginDiv );
nicholas@926 5700
nicholas@926 5701 return ret;
nicholas@926 5702 }
nicholas@926 5703 });
nicholas@926 5704 }
nicholas@926 5705 })();
nicholas@926 5706
nicholas@926 5707
nicholas@926 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nicholas@926 5709 jQuery.swap = function( elem, options, callback, args ) {
nicholas@926 5710 var ret, name,
nicholas@926 5711 old = {};
nicholas@926 5712
nicholas@926 5713 // Remember the old values, and insert the new ones
nicholas@926 5714 for ( name in options ) {
nicholas@926 5715 old[ name ] = elem.style[ name ];
nicholas@926 5716 elem.style[ name ] = options[ name ];
nicholas@926 5717 }
nicholas@926 5718
nicholas@926 5719 ret = callback.apply( elem, args || [] );
nicholas@926 5720
nicholas@926 5721 // Revert the old values
nicholas@926 5722 for ( name in options ) {
nicholas@926 5723 elem.style[ name ] = old[ name ];
nicholas@926 5724 }
nicholas@926 5725
nicholas@926 5726 return ret;
nicholas@926 5727 };
nicholas@926 5728
nicholas@926 5729
nicholas@926 5730 var
nicholas@926 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nicholas@926 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nicholas@926 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nicholas@926 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nicholas@926 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nicholas@926 5736
nicholas@926 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nicholas@926 5738 cssNormalTransform = {
nicholas@926 5739 letterSpacing: "0",
nicholas@926 5740 fontWeight: "400"
nicholas@926 5741 },
nicholas@926 5742
nicholas@926 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nicholas@926 5744
nicholas@926 5745 // Return a css property mapped to a potentially vendor prefixed property
nicholas@926 5746 function vendorPropName( style, name ) {
nicholas@926 5747
nicholas@926 5748 // Shortcut for names that are not vendor prefixed
nicholas@926 5749 if ( name in style ) {
nicholas@926 5750 return name;
nicholas@926 5751 }
nicholas@926 5752
nicholas@926 5753 // Check for vendor prefixed names
nicholas@926 5754 var capName = name[0].toUpperCase() + name.slice(1),
nicholas@926 5755 origName = name,
nicholas@926 5756 i = cssPrefixes.length;
nicholas@926 5757
nicholas@926 5758 while ( i-- ) {
nicholas@926 5759 name = cssPrefixes[ i ] + capName;
nicholas@926 5760 if ( name in style ) {
nicholas@926 5761 return name;
nicholas@926 5762 }
nicholas@926 5763 }
nicholas@926 5764
nicholas@926 5765 return origName;
nicholas@926 5766 }
nicholas@926 5767
nicholas@926 5768 function setPositiveNumber( elem, value, subtract ) {
nicholas@926 5769 var matches = rnumsplit.exec( value );
nicholas@926 5770 return matches ?
nicholas@926 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nicholas@926 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nicholas@926 5773 value;
nicholas@926 5774 }
nicholas@926 5775
nicholas@926 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nicholas@926 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nicholas@926 5778 // If we already have the right measurement, avoid augmentation
nicholas@926 5779 4 :
nicholas@926 5780 // Otherwise initialize for horizontal or vertical properties
nicholas@926 5781 name === "width" ? 1 : 0,
nicholas@926 5782
nicholas@926 5783 val = 0;
nicholas@926 5784
nicholas@926 5785 for ( ; i < 4; i += 2 ) {
nicholas@926 5786 // Both box models exclude margin, so add it if we want it
nicholas@926 5787 if ( extra === "margin" ) {
nicholas@926 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nicholas@926 5789 }
nicholas@926 5790
nicholas@926 5791 if ( isBorderBox ) {
nicholas@926 5792 // border-box includes padding, so remove it if we want content
nicholas@926 5793 if ( extra === "content" ) {
nicholas@926 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nicholas@926 5795 }
nicholas@926 5796
nicholas@926 5797 // At this point, extra isn't border nor margin, so remove border
nicholas@926 5798 if ( extra !== "margin" ) {
nicholas@926 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nicholas@926 5800 }
nicholas@926 5801 } else {
nicholas@926 5802 // At this point, extra isn't content, so add padding
nicholas@926 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nicholas@926 5804
nicholas@926 5805 // At this point, extra isn't content nor padding, so add border
nicholas@926 5806 if ( extra !== "padding" ) {
nicholas@926 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nicholas@926 5808 }
nicholas@926 5809 }
nicholas@926 5810 }
nicholas@926 5811
nicholas@926 5812 return val;
nicholas@926 5813 }
nicholas@926 5814
nicholas@926 5815 function getWidthOrHeight( elem, name, extra ) {
nicholas@926 5816
nicholas@926 5817 // Start with offset property, which is equivalent to the border-box value
nicholas@926 5818 var valueIsBorderBox = true,
nicholas@926 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nicholas@926 5820 styles = getStyles( elem ),
nicholas@926 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nicholas@926 5822
nicholas@926 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nicholas@926 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nicholas@926 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nicholas@926 5826 if ( val <= 0 || val == null ) {
nicholas@926 5827 // Fall back to computed then uncomputed css if necessary
nicholas@926 5828 val = curCSS( elem, name, styles );
nicholas@926 5829 if ( val < 0 || val == null ) {
nicholas@926 5830 val = elem.style[ name ];
nicholas@926 5831 }
nicholas@926 5832
nicholas@926 5833 // Computed unit is not pixels. Stop here and return.
nicholas@926 5834 if ( rnumnonpx.test(val) ) {
nicholas@926 5835 return val;
nicholas@926 5836 }
nicholas@926 5837
nicholas@926 5838 // Check for style in case a browser which returns unreliable values
nicholas@926 5839 // for getComputedStyle silently falls back to the reliable elem.style
nicholas@926 5840 valueIsBorderBox = isBorderBox &&
nicholas@926 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nicholas@926 5842
nicholas@926 5843 // Normalize "", auto, and prepare for extra
nicholas@926 5844 val = parseFloat( val ) || 0;
nicholas@926 5845 }
nicholas@926 5846
nicholas@926 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nicholas@926 5848 return ( val +
nicholas@926 5849 augmentWidthOrHeight(
nicholas@926 5850 elem,
nicholas@926 5851 name,
nicholas@926 5852 extra || ( isBorderBox ? "border" : "content" ),
nicholas@926 5853 valueIsBorderBox,
nicholas@926 5854 styles
nicholas@926 5855 )
nicholas@926 5856 ) + "px";
nicholas@926 5857 }
nicholas@926 5858
nicholas@926 5859 function showHide( elements, show ) {
nicholas@926 5860 var display, elem, hidden,
nicholas@926 5861 values = [],
nicholas@926 5862 index = 0,
nicholas@926 5863 length = elements.length;
nicholas@926 5864
nicholas@926 5865 for ( ; index < length; index++ ) {
nicholas@926 5866 elem = elements[ index ];
nicholas@926 5867 if ( !elem.style ) {
nicholas@926 5868 continue;
nicholas@926 5869 }
nicholas@926 5870
nicholas@926 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nicholas@926 5872 display = elem.style.display;
nicholas@926 5873 if ( show ) {
nicholas@926 5874 // Reset the inline display of this element to learn if it is
nicholas@926 5875 // being hidden by cascaded rules or not
nicholas@926 5876 if ( !values[ index ] && display === "none" ) {
nicholas@926 5877 elem.style.display = "";
nicholas@926 5878 }
nicholas@926 5879
nicholas@926 5880 // Set elements which have been overridden with display: none
nicholas@926 5881 // in a stylesheet to whatever the default browser style is
nicholas@926 5882 // for such an element
nicholas@926 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nicholas@926 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nicholas@926 5885 }
nicholas@926 5886 } else {
nicholas@926 5887 hidden = isHidden( elem );
nicholas@926 5888
nicholas@926 5889 if ( display !== "none" || !hidden ) {
nicholas@926 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nicholas@926 5891 }
nicholas@926 5892 }
nicholas@926 5893 }
nicholas@926 5894
nicholas@926 5895 // Set the display of most of the elements in a second loop
nicholas@926 5896 // to avoid the constant reflow
nicholas@926 5897 for ( index = 0; index < length; index++ ) {
nicholas@926 5898 elem = elements[ index ];
nicholas@926 5899 if ( !elem.style ) {
nicholas@926 5900 continue;
nicholas@926 5901 }
nicholas@926 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nicholas@926 5903 elem.style.display = show ? values[ index ] || "" : "none";
nicholas@926 5904 }
nicholas@926 5905 }
nicholas@926 5906
nicholas@926 5907 return elements;
nicholas@926 5908 }
nicholas@926 5909
nicholas@926 5910 jQuery.extend({
nicholas@926 5911
nicholas@926 5912 // Add in style property hooks for overriding the default
nicholas@926 5913 // behavior of getting and setting a style property
nicholas@926 5914 cssHooks: {
nicholas@926 5915 opacity: {
nicholas@926 5916 get: function( elem, computed ) {
nicholas@926 5917 if ( computed ) {
nicholas@926 5918
nicholas@926 5919 // We should always get a number back from opacity
nicholas@926 5920 var ret = curCSS( elem, "opacity" );
nicholas@926 5921 return ret === "" ? "1" : ret;
nicholas@926 5922 }
nicholas@926 5923 }
nicholas@926 5924 }
nicholas@926 5925 },
nicholas@926 5926
nicholas@926 5927 // Don't automatically add "px" to these possibly-unitless properties
nicholas@926 5928 cssNumber: {
nicholas@926 5929 "columnCount": true,
nicholas@926 5930 "fillOpacity": true,
nicholas@926 5931 "flexGrow": true,
nicholas@926 5932 "flexShrink": true,
nicholas@926 5933 "fontWeight": true,
nicholas@926 5934 "lineHeight": true,
nicholas@926 5935 "opacity": true,
nicholas@926 5936 "order": true,
nicholas@926 5937 "orphans": true,
nicholas@926 5938 "widows": true,
nicholas@926 5939 "zIndex": true,
nicholas@926 5940 "zoom": true
nicholas@926 5941 },
nicholas@926 5942
nicholas@926 5943 // Add in properties whose names you wish to fix before
nicholas@926 5944 // setting or getting the value
nicholas@926 5945 cssProps: {
nicholas@926 5946 "float": "cssFloat"
nicholas@926 5947 },
nicholas@926 5948
nicholas@926 5949 // Get and set the style property on a DOM Node
nicholas@926 5950 style: function( elem, name, value, extra ) {
nicholas@926 5951
nicholas@926 5952 // Don't set styles on text and comment nodes
nicholas@926 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nicholas@926 5954 return;
nicholas@926 5955 }
nicholas@926 5956
nicholas@926 5957 // Make sure that we're working with the right name
nicholas@926 5958 var ret, type, hooks,
nicholas@926 5959 origName = jQuery.camelCase( name ),
nicholas@926 5960 style = elem.style;
nicholas@926 5961
nicholas@926 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nicholas@926 5963
nicholas@926 5964 // Gets hook for the prefixed version, then unprefixed version
nicholas@926 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nicholas@926 5966
nicholas@926 5967 // Check if we're setting a value
nicholas@926 5968 if ( value !== undefined ) {
nicholas@926 5969 type = typeof value;
nicholas@926 5970
nicholas@926 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nicholas@926 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nicholas@926 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nicholas@926 5974 // Fixes bug #9237
nicholas@926 5975 type = "number";
nicholas@926 5976 }
nicholas@926 5977
nicholas@926 5978 // Make sure that null and NaN values aren't set (#7116)
nicholas@926 5979 if ( value == null || value !== value ) {
nicholas@926 5980 return;
nicholas@926 5981 }
nicholas@926 5982
nicholas@926 5983 // If a number, add 'px' to the (except for certain CSS properties)
nicholas@926 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nicholas@926 5985 value += "px";
nicholas@926 5986 }
nicholas@926 5987
nicholas@926 5988 // Support: IE9-11+
nicholas@926 5989 // background-* props affect original clone's values
nicholas@926 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nicholas@926 5991 style[ name ] = "inherit";
nicholas@926 5992 }
nicholas@926 5993
nicholas@926 5994 // If a hook was provided, use that value, otherwise just set the specified value
nicholas@926 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nicholas@926 5996 style[ name ] = value;
nicholas@926 5997 }
nicholas@926 5998
nicholas@926 5999 } else {
nicholas@926 6000 // If a hook was provided get the non-computed value from there
nicholas@926 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nicholas@926 6002 return ret;
nicholas@926 6003 }
nicholas@926 6004
nicholas@926 6005 // Otherwise just get the value from the style object
nicholas@926 6006 return style[ name ];
nicholas@926 6007 }
nicholas@926 6008 },
nicholas@926 6009
nicholas@926 6010 css: function( elem, name, extra, styles ) {
nicholas@926 6011 var val, num, hooks,
nicholas@926 6012 origName = jQuery.camelCase( name );
nicholas@926 6013
nicholas@926 6014 // Make sure that we're working with the right name
nicholas@926 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nicholas@926 6016
nicholas@926 6017 // Try prefixed name followed by the unprefixed name
nicholas@926 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nicholas@926 6019
nicholas@926 6020 // If a hook was provided get the computed value from there
nicholas@926 6021 if ( hooks && "get" in hooks ) {
nicholas@926 6022 val = hooks.get( elem, true, extra );
nicholas@926 6023 }
nicholas@926 6024
nicholas@926 6025 // Otherwise, if a way to get the computed value exists, use that
nicholas@926 6026 if ( val === undefined ) {
nicholas@926 6027 val = curCSS( elem, name, styles );
nicholas@926 6028 }
nicholas@926 6029
nicholas@926 6030 // Convert "normal" to computed value
nicholas@926 6031 if ( val === "normal" && name in cssNormalTransform ) {
nicholas@926 6032 val = cssNormalTransform[ name ];
nicholas@926 6033 }
nicholas@926 6034
nicholas@926 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nicholas@926 6036 if ( extra === "" || extra ) {
nicholas@926 6037 num = parseFloat( val );
nicholas@926 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nicholas@926 6039 }
nicholas@926 6040 return val;
nicholas@926 6041 }
nicholas@926 6042 });
nicholas@926 6043
nicholas@926 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nicholas@926 6045 jQuery.cssHooks[ name ] = {
nicholas@926 6046 get: function( elem, computed, extra ) {
nicholas@926 6047 if ( computed ) {
nicholas@926 6048
nicholas@926 6049 // Certain elements can have dimension info if we invisibly show them
nicholas@926 6050 // but it must have a current display style that would benefit
nicholas@926 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nicholas@926 6052 jQuery.swap( elem, cssShow, function() {
nicholas@926 6053 return getWidthOrHeight( elem, name, extra );
nicholas@926 6054 }) :
nicholas@926 6055 getWidthOrHeight( elem, name, extra );
nicholas@926 6056 }
nicholas@926 6057 },
nicholas@926 6058
nicholas@926 6059 set: function( elem, value, extra ) {
nicholas@926 6060 var styles = extra && getStyles( elem );
nicholas@926 6061 return setPositiveNumber( elem, value, extra ?
nicholas@926 6062 augmentWidthOrHeight(
nicholas@926 6063 elem,
nicholas@926 6064 name,
nicholas@926 6065 extra,
nicholas@926 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nicholas@926 6067 styles
nicholas@926 6068 ) : 0
nicholas@926 6069 );
nicholas@926 6070 }
nicholas@926 6071 };
nicholas@926 6072 });
nicholas@926 6073
nicholas@926 6074 // Support: Android 2.3
nicholas@926 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nicholas@926 6076 function( elem, computed ) {
nicholas@926 6077 if ( computed ) {
nicholas@926 6078 return jQuery.swap( elem, { "display": "inline-block" },
nicholas@926 6079 curCSS, [ elem, "marginRight" ] );
nicholas@926 6080 }
nicholas@926 6081 }
nicholas@926 6082 );
nicholas@926 6083
nicholas@926 6084 // These hooks are used by animate to expand properties
nicholas@926 6085 jQuery.each({
nicholas@926 6086 margin: "",
nicholas@926 6087 padding: "",
nicholas@926 6088 border: "Width"
nicholas@926 6089 }, function( prefix, suffix ) {
nicholas@926 6090 jQuery.cssHooks[ prefix + suffix ] = {
nicholas@926 6091 expand: function( value ) {
nicholas@926 6092 var i = 0,
nicholas@926 6093 expanded = {},
nicholas@926 6094
nicholas@926 6095 // Assumes a single number if not a string
nicholas@926 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nicholas@926 6097
nicholas@926 6098 for ( ; i < 4; i++ ) {
nicholas@926 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nicholas@926 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nicholas@926 6101 }
nicholas@926 6102
nicholas@926 6103 return expanded;
nicholas@926 6104 }
nicholas@926 6105 };
nicholas@926 6106
nicholas@926 6107 if ( !rmargin.test( prefix ) ) {
nicholas@926 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nicholas@926 6109 }
nicholas@926 6110 });
nicholas@926 6111
nicholas@926 6112 jQuery.fn.extend({
nicholas@926 6113 css: function( name, value ) {
nicholas@926 6114 return access( this, function( elem, name, value ) {
nicholas@926 6115 var styles, len,
nicholas@926 6116 map = {},
nicholas@926 6117 i = 0;
nicholas@926 6118
nicholas@926 6119 if ( jQuery.isArray( name ) ) {
nicholas@926 6120 styles = getStyles( elem );
nicholas@926 6121 len = name.length;
nicholas@926 6122
nicholas@926 6123 for ( ; i < len; i++ ) {
nicholas@926 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nicholas@926 6125 }
nicholas@926 6126
nicholas@926 6127 return map;
nicholas@926 6128 }
nicholas@926 6129
nicholas@926 6130 return value !== undefined ?
nicholas@926 6131 jQuery.style( elem, name, value ) :
nicholas@926 6132 jQuery.css( elem, name );
nicholas@926 6133 }, name, value, arguments.length > 1 );
nicholas@926 6134 },
nicholas@926 6135 show: function() {
nicholas@926 6136 return showHide( this, true );
nicholas@926 6137 },
nicholas@926 6138 hide: function() {
nicholas@926 6139 return showHide( this );
nicholas@926 6140 },
nicholas@926 6141 toggle: function( state ) {
nicholas@926 6142 if ( typeof state === "boolean" ) {
nicholas@926 6143 return state ? this.show() : this.hide();
nicholas@926 6144 }
nicholas@926 6145
nicholas@926 6146 return this.each(function() {
nicholas@926 6147 if ( isHidden( this ) ) {
nicholas@926 6148 jQuery( this ).show();
nicholas@926 6149 } else {
nicholas@926 6150 jQuery( this ).hide();
nicholas@926 6151 }
nicholas@926 6152 });
nicholas@926 6153 }
nicholas@926 6154 });
nicholas@926 6155
nicholas@926 6156
nicholas@926 6157 function Tween( elem, options, prop, end, easing ) {
nicholas@926 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nicholas@926 6159 }
nicholas@926 6160 jQuery.Tween = Tween;
nicholas@926 6161
nicholas@926 6162 Tween.prototype = {
nicholas@926 6163 constructor: Tween,
nicholas@926 6164 init: function( elem, options, prop, end, easing, unit ) {
nicholas@926 6165 this.elem = elem;
nicholas@926 6166 this.prop = prop;
nicholas@926 6167 this.easing = easing || "swing";
nicholas@926 6168 this.options = options;
nicholas@926 6169 this.start = this.now = this.cur();
nicholas@926 6170 this.end = end;
nicholas@926 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nicholas@926 6172 },
nicholas@926 6173 cur: function() {
nicholas@926 6174 var hooks = Tween.propHooks[ this.prop ];
nicholas@926 6175
nicholas@926 6176 return hooks && hooks.get ?
nicholas@926 6177 hooks.get( this ) :
nicholas@926 6178 Tween.propHooks._default.get( this );
nicholas@926 6179 },
nicholas@926 6180 run: function( percent ) {
nicholas@926 6181 var eased,
nicholas@926 6182 hooks = Tween.propHooks[ this.prop ];
nicholas@926 6183
nicholas@926 6184 if ( this.options.duration ) {
nicholas@926 6185 this.pos = eased = jQuery.easing[ this.easing ](
nicholas@926 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nicholas@926 6187 );
nicholas@926 6188 } else {
nicholas@926 6189 this.pos = eased = percent;
nicholas@926 6190 }
nicholas@926 6191 this.now = ( this.end - this.start ) * eased + this.start;
nicholas@926 6192
nicholas@926 6193 if ( this.options.step ) {
nicholas@926 6194 this.options.step.call( this.elem, this.now, this );
nicholas@926 6195 }
nicholas@926 6196
nicholas@926 6197 if ( hooks && hooks.set ) {
nicholas@926 6198 hooks.set( this );
nicholas@926 6199 } else {
nicholas@926 6200 Tween.propHooks._default.set( this );
nicholas@926 6201 }
nicholas@926 6202 return this;
nicholas@926 6203 }
nicholas@926 6204 };
nicholas@926 6205
nicholas@926 6206 Tween.prototype.init.prototype = Tween.prototype;
nicholas@926 6207
nicholas@926 6208 Tween.propHooks = {
nicholas@926 6209 _default: {
nicholas@926 6210 get: function( tween ) {
nicholas@926 6211 var result;
nicholas@926 6212
nicholas@926 6213 if ( tween.elem[ tween.prop ] != null &&
nicholas@926 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nicholas@926 6215 return tween.elem[ tween.prop ];
nicholas@926 6216 }
nicholas@926 6217
nicholas@926 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nicholas@926 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nicholas@926 6220 // Simple values such as "10px" are parsed to Float;
nicholas@926 6221 // complex values such as "rotate(1rad)" are returned as-is.
nicholas@926 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nicholas@926 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nicholas@926 6224 return !result || result === "auto" ? 0 : result;
nicholas@926 6225 },
nicholas@926 6226 set: function( tween ) {
nicholas@926 6227 // Use step hook for back compat.
nicholas@926 6228 // Use cssHook if its there.
nicholas@926 6229 // Use .style if available and use plain properties where available.
nicholas@926 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nicholas@926 6231 jQuery.fx.step[ tween.prop ]( tween );
nicholas@926 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nicholas@926 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nicholas@926 6234 } else {
nicholas@926 6235 tween.elem[ tween.prop ] = tween.now;
nicholas@926 6236 }
nicholas@926 6237 }
nicholas@926 6238 }
nicholas@926 6239 };
nicholas@926 6240
nicholas@926 6241 // Support: IE9
nicholas@926 6242 // Panic based approach to setting things on disconnected nodes
nicholas@926 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nicholas@926 6244 set: function( tween ) {
nicholas@926 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nicholas@926 6246 tween.elem[ tween.prop ] = tween.now;
nicholas@926 6247 }
nicholas@926 6248 }
nicholas@926 6249 };
nicholas@926 6250
nicholas@926 6251 jQuery.easing = {
nicholas@926 6252 linear: function( p ) {
nicholas@926 6253 return p;
nicholas@926 6254 },
nicholas@926 6255 swing: function( p ) {
nicholas@926 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nicholas@926 6257 }
nicholas@926 6258 };
nicholas@926 6259
nicholas@926 6260 jQuery.fx = Tween.prototype.init;
nicholas@926 6261
nicholas@926 6262 // Back Compat <1.8 extension point
nicholas@926 6263 jQuery.fx.step = {};
nicholas@926 6264
nicholas@926 6265
nicholas@926 6266
nicholas@926 6267
nicholas@926 6268 var
nicholas@926 6269 fxNow, timerId,
nicholas@926 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nicholas@926 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nicholas@926 6272 rrun = /queueHooks$/,
nicholas@926 6273 animationPrefilters = [ defaultPrefilter ],
nicholas@926 6274 tweeners = {
nicholas@926 6275 "*": [ function( prop, value ) {
nicholas@926 6276 var tween = this.createTween( prop, value ),
nicholas@926 6277 target = tween.cur(),
nicholas@926 6278 parts = rfxnum.exec( value ),
nicholas@926 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nicholas@926 6280
nicholas@926 6281 // Starting value computation is required for potential unit mismatches
nicholas@926 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nicholas@926 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nicholas@926 6284 scale = 1,
nicholas@926 6285 maxIterations = 20;
nicholas@926 6286
nicholas@926 6287 if ( start && start[ 3 ] !== unit ) {
nicholas@926 6288 // Trust units reported by jQuery.css
nicholas@926 6289 unit = unit || start[ 3 ];
nicholas@926 6290
nicholas@926 6291 // Make sure we update the tween properties later on
nicholas@926 6292 parts = parts || [];
nicholas@926 6293
nicholas@926 6294 // Iteratively approximate from a nonzero starting point
nicholas@926 6295 start = +target || 1;
nicholas@926 6296
nicholas@926 6297 do {
nicholas@926 6298 // If previous iteration zeroed out, double until we get *something*.
nicholas@926 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nicholas@926 6300 scale = scale || ".5";
nicholas@926 6301
nicholas@926 6302 // Adjust and apply
nicholas@926 6303 start = start / scale;
nicholas@926 6304 jQuery.style( tween.elem, prop, start + unit );
nicholas@926 6305
nicholas@926 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nicholas@926 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nicholas@926 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nicholas@926 6309 }
nicholas@926 6310
nicholas@926 6311 // Update tween properties
nicholas@926 6312 if ( parts ) {
nicholas@926 6313 start = tween.start = +start || +target || 0;
nicholas@926 6314 tween.unit = unit;
nicholas@926 6315 // If a +=/-= token was provided, we're doing a relative animation
nicholas@926 6316 tween.end = parts[ 1 ] ?
nicholas@926 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nicholas@926 6318 +parts[ 2 ];
nicholas@926 6319 }
nicholas@926 6320
nicholas@926 6321 return tween;
nicholas@926 6322 } ]
nicholas@926 6323 };
nicholas@926 6324
nicholas@926 6325 // Animations created synchronously will run synchronously
nicholas@926 6326 function createFxNow() {
nicholas@926 6327 setTimeout(function() {
nicholas@926 6328 fxNow = undefined;
nicholas@926 6329 });
nicholas@926 6330 return ( fxNow = jQuery.now() );
nicholas@926 6331 }
nicholas@926 6332
nicholas@926 6333 // Generate parameters to create a standard animation
nicholas@926 6334 function genFx( type, includeWidth ) {
nicholas@926 6335 var which,
nicholas@926 6336 i = 0,
nicholas@926 6337 attrs = { height: type };
nicholas@926 6338
nicholas@926 6339 // If we include width, step value is 1 to do all cssExpand values,
nicholas@926 6340 // otherwise step value is 2 to skip over Left and Right
nicholas@926 6341 includeWidth = includeWidth ? 1 : 0;
nicholas@926 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nicholas@926 6343 which = cssExpand[ i ];
nicholas@926 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nicholas@926 6345 }
nicholas@926 6346
nicholas@926 6347 if ( includeWidth ) {
nicholas@926 6348 attrs.opacity = attrs.width = type;
nicholas@926 6349 }
nicholas@926 6350
nicholas@926 6351 return attrs;
nicholas@926 6352 }
nicholas@926 6353
nicholas@926 6354 function createTween( value, prop, animation ) {
nicholas@926 6355 var tween,
nicholas@926 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nicholas@926 6357 index = 0,
nicholas@926 6358 length = collection.length;
nicholas@926 6359 for ( ; index < length; index++ ) {
nicholas@926 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nicholas@926 6361
nicholas@926 6362 // We're done with this property
nicholas@926 6363 return tween;
nicholas@926 6364 }
nicholas@926 6365 }
nicholas@926 6366 }
nicholas@926 6367
nicholas@926 6368 function defaultPrefilter( elem, props, opts ) {
nicholas@926 6369 /* jshint validthis: true */
nicholas@926 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nicholas@926 6371 anim = this,
nicholas@926 6372 orig = {},
nicholas@926 6373 style = elem.style,
nicholas@926 6374 hidden = elem.nodeType && isHidden( elem ),
nicholas@926 6375 dataShow = data_priv.get( elem, "fxshow" );
nicholas@926 6376
nicholas@926 6377 // Handle queue: false promises
nicholas@926 6378 if ( !opts.queue ) {
nicholas@926 6379 hooks = jQuery._queueHooks( elem, "fx" );
nicholas@926 6380 if ( hooks.unqueued == null ) {
nicholas@926 6381 hooks.unqueued = 0;
nicholas@926 6382 oldfire = hooks.empty.fire;
nicholas@926 6383 hooks.empty.fire = function() {
nicholas@926 6384 if ( !hooks.unqueued ) {
nicholas@926 6385 oldfire();
nicholas@926 6386 }
nicholas@926 6387 };
nicholas@926 6388 }
nicholas@926 6389 hooks.unqueued++;
nicholas@926 6390
nicholas@926 6391 anim.always(function() {
nicholas@926 6392 // Ensure the complete handler is called before this completes
nicholas@926 6393 anim.always(function() {
nicholas@926 6394 hooks.unqueued--;
nicholas@926 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nicholas@926 6396 hooks.empty.fire();
nicholas@926 6397 }
nicholas@926 6398 });
nicholas@926 6399 });
nicholas@926 6400 }
nicholas@926 6401
nicholas@926 6402 // Height/width overflow pass
nicholas@926 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nicholas@926 6404 // Make sure that nothing sneaks out
nicholas@926 6405 // Record all 3 overflow attributes because IE9-10 do not
nicholas@926 6406 // change the overflow attribute when overflowX and
nicholas@926 6407 // overflowY are set to the same value
nicholas@926 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nicholas@926 6409
nicholas@926 6410 // Set display property to inline-block for height/width
nicholas@926 6411 // animations on inline elements that are having width/height animated
nicholas@926 6412 display = jQuery.css( elem, "display" );
nicholas@926 6413
nicholas@926 6414 // Test default display if display is currently "none"
nicholas@926 6415 checkDisplay = display === "none" ?
nicholas@926 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nicholas@926 6417
nicholas@926 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nicholas@926 6419 style.display = "inline-block";
nicholas@926 6420 }
nicholas@926 6421 }
nicholas@926 6422
nicholas@926 6423 if ( opts.overflow ) {
nicholas@926 6424 style.overflow = "hidden";
nicholas@926 6425 anim.always(function() {
nicholas@926 6426 style.overflow = opts.overflow[ 0 ];
nicholas@926 6427 style.overflowX = opts.overflow[ 1 ];
nicholas@926 6428 style.overflowY = opts.overflow[ 2 ];
nicholas@926 6429 });
nicholas@926 6430 }
nicholas@926 6431
nicholas@926 6432 // show/hide pass
nicholas@926 6433 for ( prop in props ) {
nicholas@926 6434 value = props[ prop ];
nicholas@926 6435 if ( rfxtypes.exec( value ) ) {
nicholas@926 6436 delete props[ prop ];
nicholas@926 6437 toggle = toggle || value === "toggle";
nicholas@926 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nicholas@926 6439
nicholas@926 6440 // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
nicholas@926 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nicholas@926 6442 hidden = true;
nicholas@926 6443 } else {
nicholas@926 6444 continue;
nicholas@926 6445 }
nicholas@926 6446 }
nicholas@926 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nicholas@926 6448
nicholas@926 6449 // Any non-fx value stops us from restoring the original display value
nicholas@926 6450 } else {
nicholas@926 6451 display = undefined;
nicholas@926 6452 }
nicholas@926 6453 }
nicholas@926 6454
nicholas@926 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nicholas@926 6456 if ( dataShow ) {
nicholas@926 6457 if ( "hidden" in dataShow ) {
nicholas@926 6458 hidden = dataShow.hidden;
nicholas@926 6459 }
nicholas@926 6460 } else {
nicholas@926 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nicholas@926 6462 }
nicholas@926 6463
nicholas@926 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nicholas@926 6465 if ( toggle ) {
nicholas@926 6466 dataShow.hidden = !hidden;
nicholas@926 6467 }
nicholas@926 6468 if ( hidden ) {
nicholas@926 6469 jQuery( elem ).show();
nicholas@926 6470 } else {
nicholas@926 6471 anim.done(function() {
nicholas@926 6472 jQuery( elem ).hide();
nicholas@926 6473 });
nicholas@926 6474 }
nicholas@926 6475 anim.done(function() {
nicholas@926 6476 var prop;
nicholas@926 6477
nicholas@926 6478 data_priv.remove( elem, "fxshow" );
nicholas@926 6479 for ( prop in orig ) {
nicholas@926 6480 jQuery.style( elem, prop, orig[ prop ] );
nicholas@926 6481 }
nicholas@926 6482 });
nicholas@926 6483 for ( prop in orig ) {
nicholas@926 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nicholas@926 6485
nicholas@926 6486 if ( !( prop in dataShow ) ) {
nicholas@926 6487 dataShow[ prop ] = tween.start;
nicholas@926 6488 if ( hidden ) {
nicholas@926 6489 tween.end = tween.start;
nicholas@926 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nicholas@926 6491 }
nicholas@926 6492 }
nicholas@926 6493 }
nicholas@926 6494
nicholas@926 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nicholas@926 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nicholas@926 6497 style.display = display;
nicholas@926 6498 }
nicholas@926 6499 }
nicholas@926 6500
nicholas@926 6501 function propFilter( props, specialEasing ) {
nicholas@926 6502 var index, name, easing, value, hooks;
nicholas@926 6503
nicholas@926 6504 // camelCase, specialEasing and expand cssHook pass
nicholas@926 6505 for ( index in props ) {
nicholas@926 6506 name = jQuery.camelCase( index );
nicholas@926 6507 easing = specialEasing[ name ];
nicholas@926 6508 value = props[ index ];
nicholas@926 6509 if ( jQuery.isArray( value ) ) {
nicholas@926 6510 easing = value[ 1 ];
nicholas@926 6511 value = props[ index ] = value[ 0 ];
nicholas@926 6512 }
nicholas@926 6513
nicholas@926 6514 if ( index !== name ) {
nicholas@926 6515 props[ name ] = value;
nicholas@926 6516 delete props[ index ];
nicholas@926 6517 }
nicholas@926 6518
nicholas@926 6519 hooks = jQuery.cssHooks[ name ];
nicholas@926 6520 if ( hooks && "expand" in hooks ) {
nicholas@926 6521 value = hooks.expand( value );
nicholas@926 6522 delete props[ name ];
nicholas@926 6523
nicholas@926 6524 // Not quite $.extend, this won't overwrite existing keys.
nicholas@926 6525 // Reusing 'index' because we have the correct "name"
nicholas@926 6526 for ( index in value ) {
nicholas@926 6527 if ( !( index in props ) ) {
nicholas@926 6528 props[ index ] = value[ index ];
nicholas@926 6529 specialEasing[ index ] = easing;
nicholas@926 6530 }
nicholas@926 6531 }
nicholas@926 6532 } else {
nicholas@926 6533 specialEasing[ name ] = easing;
nicholas@926 6534 }
nicholas@926 6535 }
nicholas@926 6536 }
nicholas@926 6537
nicholas@926 6538 function Animation( elem, properties, options ) {
nicholas@926 6539 var result,
nicholas@926 6540 stopped,
nicholas@926 6541 index = 0,
nicholas@926 6542 length = animationPrefilters.length,
nicholas@926 6543 deferred = jQuery.Deferred().always( function() {
nicholas@926 6544 // Don't match elem in the :animated selector
nicholas@926 6545 delete tick.elem;
nicholas@926 6546 }),
nicholas@926 6547 tick = function() {
nicholas@926 6548 if ( stopped ) {
nicholas@926 6549 return false;
nicholas@926 6550 }
nicholas@926 6551 var currentTime = fxNow || createFxNow(),
nicholas@926 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nicholas@926 6553 // Support: Android 2.3
nicholas@926 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nicholas@926 6555 temp = remaining / animation.duration || 0,
nicholas@926 6556 percent = 1 - temp,
nicholas@926 6557 index = 0,
nicholas@926 6558 length = animation.tweens.length;
nicholas@926 6559
nicholas@926 6560 for ( ; index < length ; index++ ) {
nicholas@926 6561 animation.tweens[ index ].run( percent );
nicholas@926 6562 }
nicholas@926 6563
nicholas@926 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nicholas@926 6565
nicholas@926 6566 if ( percent < 1 && length ) {
nicholas@926 6567 return remaining;
nicholas@926 6568 } else {
nicholas@926 6569 deferred.resolveWith( elem, [ animation ] );
nicholas@926 6570 return false;
nicholas@926 6571 }
nicholas@926 6572 },
nicholas@926 6573 animation = deferred.promise({
nicholas@926 6574 elem: elem,
nicholas@926 6575 props: jQuery.extend( {}, properties ),
nicholas@926 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nicholas@926 6577 originalProperties: properties,
nicholas@926 6578 originalOptions: options,
nicholas@926 6579 startTime: fxNow || createFxNow(),
nicholas@926 6580 duration: options.duration,
nicholas@926 6581 tweens: [],
nicholas@926 6582 createTween: function( prop, end ) {
nicholas@926 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nicholas@926 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nicholas@926 6585 animation.tweens.push( tween );
nicholas@926 6586 return tween;
nicholas@926 6587 },
nicholas@926 6588 stop: function( gotoEnd ) {
nicholas@926 6589 var index = 0,
nicholas@926 6590 // If we are going to the end, we want to run all the tweens
nicholas@926 6591 // otherwise we skip this part
nicholas@926 6592 length = gotoEnd ? animation.tweens.length : 0;
nicholas@926 6593 if ( stopped ) {
nicholas@926 6594 return this;
nicholas@926 6595 }
nicholas@926 6596 stopped = true;
nicholas@926 6597 for ( ; index < length ; index++ ) {
nicholas@926 6598 animation.tweens[ index ].run( 1 );
nicholas@926 6599 }
nicholas@926 6600
nicholas@926 6601 // Resolve when we played the last frame; otherwise, reject
nicholas@926 6602 if ( gotoEnd ) {
nicholas@926 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nicholas@926 6604 } else {
nicholas@926 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nicholas@926 6606 }
nicholas@926 6607 return this;
nicholas@926 6608 }
nicholas@926 6609 }),
nicholas@926 6610 props = animation.props;
nicholas@926 6611
nicholas@926 6612 propFilter( props, animation.opts.specialEasing );
nicholas@926 6613
nicholas@926 6614 for ( ; index < length ; index++ ) {
nicholas@926 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nicholas@926 6616 if ( result ) {
nicholas@926 6617 return result;
nicholas@926 6618 }
nicholas@926 6619 }
nicholas@926 6620
nicholas@926 6621 jQuery.map( props, createTween, animation );
nicholas@926 6622
nicholas@926 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nicholas@926 6624 animation.opts.start.call( elem, animation );
nicholas@926 6625 }
nicholas@926 6626
nicholas@926 6627 jQuery.fx.timer(
nicholas@926 6628 jQuery.extend( tick, {
nicholas@926 6629 elem: elem,
nicholas@926 6630 anim: animation,
nicholas@926 6631 queue: animation.opts.queue
nicholas@926 6632 })
nicholas@926 6633 );
nicholas@926 6634
nicholas@926 6635 // attach callbacks from options
nicholas@926 6636 return animation.progress( animation.opts.progress )
nicholas@926 6637 .done( animation.opts.done, animation.opts.complete )
nicholas@926 6638 .fail( animation.opts.fail )
nicholas@926 6639 .always( animation.opts.always );
nicholas@926 6640 }
nicholas@926 6641
nicholas@926 6642 jQuery.Animation = jQuery.extend( Animation, {
nicholas@926 6643
nicholas@926 6644 tweener: function( props, callback ) {
nicholas@926 6645 if ( jQuery.isFunction( props ) ) {
nicholas@926 6646 callback = props;
nicholas@926 6647 props = [ "*" ];
nicholas@926 6648 } else {
nicholas@926 6649 props = props.split(" ");
nicholas@926 6650 }
nicholas@926 6651
nicholas@926 6652 var prop,
nicholas@926 6653 index = 0,
nicholas@926 6654 length = props.length;
nicholas@926 6655
nicholas@926 6656 for ( ; index < length ; index++ ) {
nicholas@926 6657 prop = props[ index ];
nicholas@926 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nicholas@926 6659 tweeners[ prop ].unshift( callback );
nicholas@926 6660 }
nicholas@926 6661 },
nicholas@926 6662
nicholas@926 6663 prefilter: function( callback, prepend ) {
nicholas@926 6664 if ( prepend ) {
nicholas@926 6665 animationPrefilters.unshift( callback );
nicholas@926 6666 } else {
nicholas@926 6667 animationPrefilters.push( callback );
nicholas@926 6668 }
nicholas@926 6669 }
nicholas@926 6670 });
nicholas@926 6671
nicholas@926 6672 jQuery.speed = function( speed, easing, fn ) {
nicholas@926 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nicholas@926 6674 complete: fn || !fn && easing ||
nicholas@926 6675 jQuery.isFunction( speed ) && speed,
nicholas@926 6676 duration: speed,
nicholas@926 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nicholas@926 6678 };
nicholas@926 6679
nicholas@926 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nicholas@926 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nicholas@926 6682
nicholas@926 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nicholas@926 6684 if ( opt.queue == null || opt.queue === true ) {
nicholas@926 6685 opt.queue = "fx";
nicholas@926 6686 }
nicholas@926 6687
nicholas@926 6688 // Queueing
nicholas@926 6689 opt.old = opt.complete;
nicholas@926 6690
nicholas@926 6691 opt.complete = function() {
nicholas@926 6692 if ( jQuery.isFunction( opt.old ) ) {
nicholas@926 6693 opt.old.call( this );
nicholas@926 6694 }
nicholas@926 6695
nicholas@926 6696 if ( opt.queue ) {
nicholas@926 6697 jQuery.dequeue( this, opt.queue );
nicholas@926 6698 }
nicholas@926 6699 };
nicholas@926 6700
nicholas@926 6701 return opt;
nicholas@926 6702 };
nicholas@926 6703
nicholas@926 6704 jQuery.fn.extend({
nicholas@926 6705 fadeTo: function( speed, to, easing, callback ) {
nicholas@926 6706
nicholas@926 6707 // Show any hidden elements after setting opacity to 0
nicholas@926 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nicholas@926 6709
nicholas@926 6710 // Animate to the value specified
nicholas@926 6711 .end().animate({ opacity: to }, speed, easing, callback );
nicholas@926 6712 },
nicholas@926 6713 animate: function( prop, speed, easing, callback ) {
nicholas@926 6714 var empty = jQuery.isEmptyObject( prop ),
nicholas@926 6715 optall = jQuery.speed( speed, easing, callback ),
nicholas@926 6716 doAnimation = function() {
nicholas@926 6717 // Operate on a copy of prop so per-property easing won't be lost
nicholas@926 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nicholas@926 6719
nicholas@926 6720 // Empty animations, or finishing resolves immediately
nicholas@926 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nicholas@926 6722 anim.stop( true );
nicholas@926 6723 }
nicholas@926 6724 };
nicholas@926 6725 doAnimation.finish = doAnimation;
nicholas@926 6726
nicholas@926 6727 return empty || optall.queue === false ?
nicholas@926 6728 this.each( doAnimation ) :
nicholas@926 6729 this.queue( optall.queue, doAnimation );
nicholas@926 6730 },
nicholas@926 6731 stop: function( type, clearQueue, gotoEnd ) {
nicholas@926 6732 var stopQueue = function( hooks ) {
nicholas@926 6733 var stop = hooks.stop;
nicholas@926 6734 delete hooks.stop;
nicholas@926 6735 stop( gotoEnd );
nicholas@926 6736 };
nicholas@926 6737
nicholas@926 6738 if ( typeof type !== "string" ) {
nicholas@926 6739 gotoEnd = clearQueue;
nicholas@926 6740 clearQueue = type;
nicholas@926 6741 type = undefined;
nicholas@926 6742 }
nicholas@926 6743 if ( clearQueue && type !== false ) {
nicholas@926 6744 this.queue( type || "fx", [] );
nicholas@926 6745 }
nicholas@926 6746
nicholas@926 6747 return this.each(function() {
nicholas@926 6748 var dequeue = true,
nicholas@926 6749 index = type != null && type + "queueHooks",
nicholas@926 6750 timers = jQuery.timers,
nicholas@926 6751 data = data_priv.get( this );
nicholas@926 6752
nicholas@926 6753 if ( index ) {
nicholas@926 6754 if ( data[ index ] && data[ index ].stop ) {
nicholas@926 6755 stopQueue( data[ index ] );
nicholas@926 6756 }
nicholas@926 6757 } else {
nicholas@926 6758 for ( index in data ) {
nicholas@926 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nicholas@926 6760 stopQueue( data[ index ] );
nicholas@926 6761 }
nicholas@926 6762 }
nicholas@926 6763 }
nicholas@926 6764
nicholas@926 6765 for ( index = timers.length; index--; ) {
nicholas@926 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nicholas@926 6767 timers[ index ].anim.stop( gotoEnd );
nicholas@926 6768 dequeue = false;
nicholas@926 6769 timers.splice( index, 1 );
nicholas@926 6770 }
nicholas@926 6771 }
nicholas@926 6772
nicholas@926 6773 // Start the next in the queue if the last step wasn't forced.
nicholas@926 6774 // Timers currently will call their complete callbacks, which
nicholas@926 6775 // will dequeue but only if they were gotoEnd.
nicholas@926 6776 if ( dequeue || !gotoEnd ) {
nicholas@926 6777 jQuery.dequeue( this, type );
nicholas@926 6778 }
nicholas@926 6779 });
nicholas@926 6780 },
nicholas@926 6781 finish: function( type ) {
nicholas@926 6782 if ( type !== false ) {
nicholas@926 6783 type = type || "fx";
nicholas@926 6784 }
nicholas@926 6785 return this.each(function() {
nicholas@926 6786 var index,
nicholas@926 6787 data = data_priv.get( this ),
nicholas@926 6788 queue = data[ type + "queue" ],
nicholas@926 6789 hooks = data[ type + "queueHooks" ],
nicholas@926 6790 timers = jQuery.timers,
nicholas@926 6791 length = queue ? queue.length : 0;
nicholas@926 6792
nicholas@926 6793 // Enable finishing flag on private data
nicholas@926 6794 data.finish = true;
nicholas@926 6795
nicholas@926 6796 // Empty the queue first
nicholas@926 6797 jQuery.queue( this, type, [] );
nicholas@926 6798
nicholas@926 6799 if ( hooks && hooks.stop ) {
nicholas@926 6800 hooks.stop.call( this, true );
nicholas@926 6801 }
nicholas@926 6802
nicholas@926 6803 // Look for any active animations, and finish them
nicholas@926 6804 for ( index = timers.length; index--; ) {
nicholas@926 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nicholas@926 6806 timers[ index ].anim.stop( true );
nicholas@926 6807 timers.splice( index, 1 );
nicholas@926 6808 }
nicholas@926 6809 }
nicholas@926 6810
nicholas@926 6811 // Look for any animations in the old queue and finish them
nicholas@926 6812 for ( index = 0; index < length; index++ ) {
nicholas@926 6813 if ( queue[ index ] && queue[ index ].finish ) {
nicholas@926 6814 queue[ index ].finish.call( this );
nicholas@926 6815 }
nicholas@926 6816 }
nicholas@926 6817
nicholas@926 6818 // Turn off finishing flag
nicholas@926 6819 delete data.finish;
nicholas@926 6820 });
nicholas@926 6821 }
nicholas@926 6822 });
nicholas@926 6823
nicholas@926 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nicholas@926 6825 var cssFn = jQuery.fn[ name ];
nicholas@926 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nicholas@926 6827 return speed == null || typeof speed === "boolean" ?
nicholas@926 6828 cssFn.apply( this, arguments ) :
nicholas@926 6829 this.animate( genFx( name, true ), speed, easing, callback );
nicholas@926 6830 };
nicholas@926 6831 });
nicholas@926 6832
nicholas@926 6833 // Generate shortcuts for custom animations
nicholas@926 6834 jQuery.each({
nicholas@926 6835 slideDown: genFx("show"),
nicholas@926 6836 slideUp: genFx("hide"),
nicholas@926 6837 slideToggle: genFx("toggle"),
nicholas@926 6838 fadeIn: { opacity: "show" },
nicholas@926 6839 fadeOut: { opacity: "hide" },
nicholas@926 6840 fadeToggle: { opacity: "toggle" }
nicholas@926 6841 }, function( name, props ) {
nicholas@926 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nicholas@926 6843 return this.animate( props, speed, easing, callback );
nicholas@926 6844 };
nicholas@926 6845 });
nicholas@926 6846
nicholas@926 6847 jQuery.timers = [];
nicholas@926 6848 jQuery.fx.tick = function() {
nicholas@926 6849 var timer,
nicholas@926 6850 i = 0,
nicholas@926 6851 timers = jQuery.timers;
nicholas@926 6852
nicholas@926 6853 fxNow = jQuery.now();
nicholas@926 6854
nicholas@926 6855 for ( ; i < timers.length; i++ ) {
nicholas@926 6856 timer = timers[ i ];
nicholas@926 6857 // Checks the timer has not already been removed
nicholas@926 6858 if ( !timer() && timers[ i ] === timer ) {
nicholas@926 6859 timers.splice( i--, 1 );
nicholas@926 6860 }
nicholas@926 6861 }
nicholas@926 6862
nicholas@926 6863 if ( !timers.length ) {
nicholas@926 6864 jQuery.fx.stop();
nicholas@926 6865 }
nicholas@926 6866 fxNow = undefined;
nicholas@926 6867 };
nicholas@926 6868
nicholas@926 6869 jQuery.fx.timer = function( timer ) {
nicholas@926 6870 jQuery.timers.push( timer );
nicholas@926 6871 if ( timer() ) {
nicholas@926 6872 jQuery.fx.start();
nicholas@926 6873 } else {
nicholas@926 6874 jQuery.timers.pop();
nicholas@926 6875 }
nicholas@926 6876 };
nicholas@926 6877
nicholas@926 6878 jQuery.fx.interval = 13;
nicholas@926 6879
nicholas@926 6880 jQuery.fx.start = function() {
nicholas@926 6881 if ( !timerId ) {
nicholas@926 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nicholas@926 6883 }
nicholas@926 6884 };
nicholas@926 6885
nicholas@926 6886 jQuery.fx.stop = function() {
nicholas@926 6887 clearInterval( timerId );
nicholas@926 6888 timerId = null;
nicholas@926 6889 };
nicholas@926 6890
nicholas@926 6891 jQuery.fx.speeds = {
nicholas@926 6892 slow: 600,
nicholas@926 6893 fast: 200,
nicholas@926 6894 // Default speed
nicholas@926 6895 _default: 400
nicholas@926 6896 };
nicholas@926 6897
nicholas@926 6898
nicholas@926 6899 // Based off of the plugin by Clint Helfers, with permission.
nicholas@926 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nicholas@926 6901 jQuery.fn.delay = function( time, type ) {
nicholas@926 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nicholas@926 6903 type = type || "fx";
nicholas@926 6904
nicholas@926 6905 return this.queue( type, function( next, hooks ) {
nicholas@926 6906 var timeout = setTimeout( next, time );
nicholas@926 6907 hooks.stop = function() {
nicholas@926 6908 clearTimeout( timeout );
nicholas@926 6909 };
nicholas@926 6910 });
nicholas@926 6911 };
nicholas@926 6912
nicholas@926 6913
nicholas@926 6914 (function() {
nicholas@926 6915 var input = document.createElement( "input" ),
nicholas@926 6916 select = document.createElement( "select" ),
nicholas@926 6917 opt = select.appendChild( document.createElement( "option" ) );
nicholas@926 6918
nicholas@926 6919 input.type = "checkbox";
nicholas@926 6920
nicholas@926 6921 // Support: iOS<=5.1, Android<=4.2+
nicholas@926 6922 // Default value for a checkbox should be "on"
nicholas@926 6923 support.checkOn = input.value !== "";
nicholas@926 6924
nicholas@926 6925 // Support: IE<=11+
nicholas@926 6926 // Must access selectedIndex to make default options select
nicholas@926 6927 support.optSelected = opt.selected;
nicholas@926 6928
nicholas@926 6929 // Support: Android<=2.3
nicholas@926 6930 // Options inside disabled selects are incorrectly marked as disabled
nicholas@926 6931 select.disabled = true;
nicholas@926 6932 support.optDisabled = !opt.disabled;
nicholas@926 6933
nicholas@926 6934 // Support: IE<=11+
nicholas@926 6935 // An input loses its value after becoming a radio
nicholas@926 6936 input = document.createElement( "input" );
nicholas@926 6937 input.value = "t";
nicholas@926 6938 input.type = "radio";
nicholas@926 6939 support.radioValue = input.value === "t";
nicholas@926 6940 })();
nicholas@926 6941
nicholas@926 6942
nicholas@926 6943 var nodeHook, boolHook,
nicholas@926 6944 attrHandle = jQuery.expr.attrHandle;
nicholas@926 6945
nicholas@926 6946 jQuery.fn.extend({
nicholas@926 6947 attr: function( name, value ) {
nicholas@926 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nicholas@926 6949 },
nicholas@926 6950
nicholas@926 6951 removeAttr: function( name ) {
nicholas@926 6952 return this.each(function() {
nicholas@926 6953 jQuery.removeAttr( this, name );
nicholas@926 6954 });
nicholas@926 6955 }
nicholas@926 6956 });
nicholas@926 6957
nicholas@926 6958 jQuery.extend({
nicholas@926 6959 attr: function( elem, name, value ) {
nicholas@926 6960 var hooks, ret,
nicholas@926 6961 nType = elem.nodeType;
nicholas@926 6962
nicholas@926 6963 // don't get/set attributes on text, comment and attribute nodes
nicholas@926 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nicholas@926 6965 return;
nicholas@926 6966 }
nicholas@926 6967
nicholas@926 6968 // Fallback to prop when attributes are not supported
nicholas@926 6969 if ( typeof elem.getAttribute === strundefined ) {
nicholas@926 6970 return jQuery.prop( elem, name, value );
nicholas@926 6971 }
nicholas@926 6972
nicholas@926 6973 // All attributes are lowercase
nicholas@926 6974 // Grab necessary hook if one is defined
nicholas@926 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nicholas@926 6976 name = name.toLowerCase();
nicholas@926 6977 hooks = jQuery.attrHooks[ name ] ||
nicholas@926 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nicholas@926 6979 }
nicholas@926 6980
nicholas@926 6981 if ( value !== undefined ) {
nicholas@926 6982
nicholas@926 6983 if ( value === null ) {
nicholas@926 6984 jQuery.removeAttr( elem, name );
nicholas@926 6985
nicholas@926 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nicholas@926 6987 return ret;
nicholas@926 6988
nicholas@926 6989 } else {
nicholas@926 6990 elem.setAttribute( name, value + "" );
nicholas@926 6991 return value;
nicholas@926 6992 }
nicholas@926 6993
nicholas@926 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nicholas@926 6995 return ret;
nicholas@926 6996
nicholas@926 6997 } else {
nicholas@926 6998 ret = jQuery.find.attr( elem, name );
nicholas@926 6999
nicholas@926 7000 // Non-existent attributes return null, we normalize to undefined
nicholas@926 7001 return ret == null ?
nicholas@926 7002 undefined :
nicholas@926 7003 ret;
nicholas@926 7004 }
nicholas@926 7005 },
nicholas@926 7006
nicholas@926 7007 removeAttr: function( elem, value ) {
nicholas@926 7008 var name, propName,
nicholas@926 7009 i = 0,
nicholas@926 7010 attrNames = value && value.match( rnotwhite );
nicholas@926 7011
nicholas@926 7012 if ( attrNames && elem.nodeType === 1 ) {
nicholas@926 7013 while ( (name = attrNames[i++]) ) {
nicholas@926 7014 propName = jQuery.propFix[ name ] || name;
nicholas@926 7015
nicholas@926 7016 // Boolean attributes get special treatment (#10870)
nicholas@926 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nicholas@926 7018 // Set corresponding property to false
nicholas@926 7019 elem[ propName ] = false;
nicholas@926 7020 }
nicholas@926 7021
nicholas@926 7022 elem.removeAttribute( name );
nicholas@926 7023 }
nicholas@926 7024 }
nicholas@926 7025 },
nicholas@926 7026
nicholas@926 7027 attrHooks: {
nicholas@926 7028 type: {
nicholas@926 7029 set: function( elem, value ) {
nicholas@926 7030 if ( !support.radioValue && value === "radio" &&
nicholas@926 7031 jQuery.nodeName( elem, "input" ) ) {
nicholas@926 7032 var val = elem.value;
nicholas@926 7033 elem.setAttribute( "type", value );
nicholas@926 7034 if ( val ) {
nicholas@926 7035 elem.value = val;
nicholas@926 7036 }
nicholas@926 7037 return value;
nicholas@926 7038 }
nicholas@926 7039 }
nicholas@926 7040 }
nicholas@926 7041 }
nicholas@926 7042 });
nicholas@926 7043
nicholas@926 7044 // Hooks for boolean attributes
nicholas@926 7045 boolHook = {
nicholas@926 7046 set: function( elem, value, name ) {
nicholas@926 7047 if ( value === false ) {
nicholas@926 7048 // Remove boolean attributes when set to false
nicholas@926 7049 jQuery.removeAttr( elem, name );
nicholas@926 7050 } else {
nicholas@926 7051 elem.setAttribute( name, name );
nicholas@926 7052 }
nicholas@926 7053 return name;
nicholas@926 7054 }
nicholas@926 7055 };
nicholas@926 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nicholas@926 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nicholas@926 7058
nicholas@926 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nicholas@926 7060 var ret, handle;
nicholas@926 7061 if ( !isXML ) {
nicholas@926 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nicholas@926 7063 handle = attrHandle[ name ];
nicholas@926 7064 attrHandle[ name ] = ret;
nicholas@926 7065 ret = getter( elem, name, isXML ) != null ?
nicholas@926 7066 name.toLowerCase() :
nicholas@926 7067 null;
nicholas@926 7068 attrHandle[ name ] = handle;
nicholas@926 7069 }
nicholas@926 7070 return ret;
nicholas@926 7071 };
nicholas@926 7072 });
nicholas@926 7073
nicholas@926 7074
nicholas@926 7075
nicholas@926 7076
nicholas@926 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nicholas@926 7078
nicholas@926 7079 jQuery.fn.extend({
nicholas@926 7080 prop: function( name, value ) {
nicholas@926 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nicholas@926 7082 },
nicholas@926 7083
nicholas@926 7084 removeProp: function( name ) {
nicholas@926 7085 return this.each(function() {
nicholas@926 7086 delete this[ jQuery.propFix[ name ] || name ];
nicholas@926 7087 });
nicholas@926 7088 }
nicholas@926 7089 });
nicholas@926 7090
nicholas@926 7091 jQuery.extend({
nicholas@926 7092 propFix: {
nicholas@926 7093 "for": "htmlFor",
nicholas@926 7094 "class": "className"
nicholas@926 7095 },
nicholas@926 7096
nicholas@926 7097 prop: function( elem, name, value ) {
nicholas@926 7098 var ret, hooks, notxml,
nicholas@926 7099 nType = elem.nodeType;
nicholas@926 7100
nicholas@926 7101 // Don't get/set properties on text, comment and attribute nodes
nicholas@926 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nicholas@926 7103 return;
nicholas@926 7104 }
nicholas@926 7105
nicholas@926 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nicholas@926 7107
nicholas@926 7108 if ( notxml ) {
nicholas@926 7109 // Fix name and attach hooks
nicholas@926 7110 name = jQuery.propFix[ name ] || name;
nicholas@926 7111 hooks = jQuery.propHooks[ name ];
nicholas@926 7112 }
nicholas@926 7113
nicholas@926 7114 if ( value !== undefined ) {
nicholas@926 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nicholas@926 7116 ret :
nicholas@926 7117 ( elem[ name ] = value );
nicholas@926 7118
nicholas@926 7119 } else {
nicholas@926 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nicholas@926 7121 ret :
nicholas@926 7122 elem[ name ];
nicholas@926 7123 }
nicholas@926 7124 },
nicholas@926 7125
nicholas@926 7126 propHooks: {
nicholas@926 7127 tabIndex: {
nicholas@926 7128 get: function( elem ) {
nicholas@926 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nicholas@926 7130 elem.tabIndex :
nicholas@926 7131 -1;
nicholas@926 7132 }
nicholas@926 7133 }
nicholas@926 7134 }
nicholas@926 7135 });
nicholas@926 7136
nicholas@926 7137 if ( !support.optSelected ) {
nicholas@926 7138 jQuery.propHooks.selected = {
nicholas@926 7139 get: function( elem ) {
nicholas@926 7140 var parent = elem.parentNode;
nicholas@926 7141 if ( parent && parent.parentNode ) {
nicholas@926 7142 parent.parentNode.selectedIndex;
nicholas@926 7143 }
nicholas@926 7144 return null;
nicholas@926 7145 }
nicholas@926 7146 };
nicholas@926 7147 }
nicholas@926 7148
nicholas@926 7149 jQuery.each([
nicholas@926 7150 "tabIndex",
nicholas@926 7151 "readOnly",
nicholas@926 7152 "maxLength",
nicholas@926 7153 "cellSpacing",
nicholas@926 7154 "cellPadding",
nicholas@926 7155 "rowSpan",
nicholas@926 7156 "colSpan",
nicholas@926 7157 "useMap",
nicholas@926 7158 "frameBorder",
nicholas@926 7159 "contentEditable"
nicholas@926 7160 ], function() {
nicholas@926 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nicholas@926 7162 });
nicholas@926 7163
nicholas@926 7164
nicholas@926 7165
nicholas@926 7166
nicholas@926 7167 var rclass = /[\t\r\n\f]/g;
nicholas@926 7168
nicholas@926 7169 jQuery.fn.extend({
nicholas@926 7170 addClass: function( value ) {
nicholas@926 7171 var classes, elem, cur, clazz, j, finalValue,
nicholas@926 7172 proceed = typeof value === "string" && value,
nicholas@926 7173 i = 0,
nicholas@926 7174 len = this.length;
nicholas@926 7175
nicholas@926 7176 if ( jQuery.isFunction( value ) ) {
nicholas@926 7177 return this.each(function( j ) {
nicholas@926 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nicholas@926 7179 });
nicholas@926 7180 }
nicholas@926 7181
nicholas@926 7182 if ( proceed ) {
nicholas@926 7183 // The disjunction here is for better compressibility (see removeClass)
nicholas@926 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nicholas@926 7185
nicholas@926 7186 for ( ; i < len; i++ ) {
nicholas@926 7187 elem = this[ i ];
nicholas@926 7188 cur = elem.nodeType === 1 && ( elem.className ?
nicholas@926 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nicholas@926 7190 " "
nicholas@926 7191 );
nicholas@926 7192
nicholas@926 7193 if ( cur ) {
nicholas@926 7194 j = 0;
nicholas@926 7195 while ( (clazz = classes[j++]) ) {
nicholas@926 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nicholas@926 7197 cur += clazz + " ";
nicholas@926 7198 }
nicholas@926 7199 }
nicholas@926 7200
nicholas@926 7201 // only assign if different to avoid unneeded rendering.
nicholas@926 7202 finalValue = jQuery.trim( cur );
nicholas@926 7203 if ( elem.className !== finalValue ) {
nicholas@926 7204 elem.className = finalValue;
nicholas@926 7205 }
nicholas@926 7206 }
nicholas@926 7207 }
nicholas@926 7208 }
nicholas@926 7209
nicholas@926 7210 return this;
nicholas@926 7211 },
nicholas@926 7212
nicholas@926 7213 removeClass: function( value ) {
nicholas@926 7214 var classes, elem, cur, clazz, j, finalValue,
nicholas@926 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nicholas@926 7216 i = 0,
nicholas@926 7217 len = this.length;
nicholas@926 7218
nicholas@926 7219 if ( jQuery.isFunction( value ) ) {
nicholas@926 7220 return this.each(function( j ) {
nicholas@926 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nicholas@926 7222 });
nicholas@926 7223 }
nicholas@926 7224 if ( proceed ) {
nicholas@926 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nicholas@926 7226
nicholas@926 7227 for ( ; i < len; i++ ) {
nicholas@926 7228 elem = this[ i ];
nicholas@926 7229 // This expression is here for better compressibility (see addClass)
nicholas@926 7230 cur = elem.nodeType === 1 && ( elem.className ?
nicholas@926 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nicholas@926 7232 ""
nicholas@926 7233 );
nicholas@926 7234
nicholas@926 7235 if ( cur ) {
nicholas@926 7236 j = 0;
nicholas@926 7237 while ( (clazz = classes[j++]) ) {
nicholas@926 7238 // Remove *all* instances
nicholas@926 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nicholas@926 7240 cur = cur.replace( " " + clazz + " ", " " );
nicholas@926 7241 }
nicholas@926 7242 }
nicholas@926 7243
nicholas@926 7244 // Only assign if different to avoid unneeded rendering.
nicholas@926 7245 finalValue = value ? jQuery.trim( cur ) : "";
nicholas@926 7246 if ( elem.className !== finalValue ) {
nicholas@926 7247 elem.className = finalValue;
nicholas@926 7248 }
nicholas@926 7249 }
nicholas@926 7250 }
nicholas@926 7251 }
nicholas@926 7252
nicholas@926 7253 return this;
nicholas@926 7254 },
nicholas@926 7255
nicholas@926 7256 toggleClass: function( value, stateVal ) {
nicholas@926 7257 var type = typeof value;
nicholas@926 7258
nicholas@926 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nicholas@926 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nicholas@926 7261 }
nicholas@926 7262
nicholas@926 7263 if ( jQuery.isFunction( value ) ) {
nicholas@926 7264 return this.each(function( i ) {
nicholas@926 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nicholas@926 7266 });
nicholas@926 7267 }
nicholas@926 7268
nicholas@926 7269 return this.each(function() {
nicholas@926 7270 if ( type === "string" ) {
nicholas@926 7271 // Toggle individual class names
nicholas@926 7272 var className,
nicholas@926 7273 i = 0,
nicholas@926 7274 self = jQuery( this ),
nicholas@926 7275 classNames = value.match( rnotwhite ) || [];
nicholas@926 7276
nicholas@926 7277 while ( (className = classNames[ i++ ]) ) {
nicholas@926 7278 // Check each className given, space separated list
nicholas@926 7279 if ( self.hasClass( className ) ) {
nicholas@926 7280 self.removeClass( className );
nicholas@926 7281 } else {
nicholas@926 7282 self.addClass( className );
nicholas@926 7283 }
nicholas@926 7284 }
nicholas@926 7285
nicholas@926 7286 // Toggle whole class name
nicholas@926 7287 } else if ( type === strundefined || type === "boolean" ) {
nicholas@926 7288 if ( this.className ) {
nicholas@926 7289 // store className if set
nicholas@926 7290 data_priv.set( this, "__className__", this.className );
nicholas@926 7291 }
nicholas@926 7292
nicholas@926 7293 // If the element has a class name or if we're passed `false`,
nicholas@926 7294 // then remove the whole classname (if there was one, the above saved it).
nicholas@926 7295 // Otherwise bring back whatever was previously saved (if anything),
nicholas@926 7296 // falling back to the empty string if nothing was stored.
nicholas@926 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nicholas@926 7298 }
nicholas@926 7299 });
nicholas@926 7300 },
nicholas@926 7301
nicholas@926 7302 hasClass: function( selector ) {
nicholas@926 7303 var className = " " + selector + " ",
nicholas@926 7304 i = 0,
nicholas@926 7305 l = this.length;
nicholas@926 7306 for ( ; i < l; i++ ) {
nicholas@926 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nicholas@926 7308 return true;
nicholas@926 7309 }
nicholas@926 7310 }
nicholas@926 7311
nicholas@926 7312 return false;
nicholas@926 7313 }
nicholas@926 7314 });
nicholas@926 7315
nicholas@926 7316
nicholas@926 7317
nicholas@926 7318
nicholas@926 7319 var rreturn = /\r/g;
nicholas@926 7320
nicholas@926 7321 jQuery.fn.extend({
nicholas@926 7322 val: function( value ) {
nicholas@926 7323 var hooks, ret, isFunction,
nicholas@926 7324 elem = this[0];
nicholas@926 7325
nicholas@926 7326 if ( !arguments.length ) {
nicholas@926 7327 if ( elem ) {
nicholas@926 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nicholas@926 7329
nicholas@926 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nicholas@926 7331 return ret;
nicholas@926 7332 }
nicholas@926 7333
nicholas@926 7334 ret = elem.value;
nicholas@926 7335
nicholas@926 7336 return typeof ret === "string" ?
nicholas@926 7337 // Handle most common string cases
nicholas@926 7338 ret.replace(rreturn, "") :
nicholas@926 7339 // Handle cases where value is null/undef or number
nicholas@926 7340 ret == null ? "" : ret;
nicholas@926 7341 }
nicholas@926 7342
nicholas@926 7343 return;
nicholas@926 7344 }
nicholas@926 7345
nicholas@926 7346 isFunction = jQuery.isFunction( value );
nicholas@926 7347
nicholas@926 7348 return this.each(function( i ) {
nicholas@926 7349 var val;
nicholas@926 7350
nicholas@926 7351 if ( this.nodeType !== 1 ) {
nicholas@926 7352 return;
nicholas@926 7353 }
nicholas@926 7354
nicholas@926 7355 if ( isFunction ) {
nicholas@926 7356 val = value.call( this, i, jQuery( this ).val() );
nicholas@926 7357 } else {
nicholas@926 7358 val = value;
nicholas@926 7359 }
nicholas@926 7360
nicholas@926 7361 // Treat null/undefined as ""; convert numbers to string
nicholas@926 7362 if ( val == null ) {
nicholas@926 7363 val = "";
nicholas@926 7364
nicholas@926 7365 } else if ( typeof val === "number" ) {
nicholas@926 7366 val += "";
nicholas@926 7367
nicholas@926 7368 } else if ( jQuery.isArray( val ) ) {
nicholas@926 7369 val = jQuery.map( val, function( value ) {
nicholas@926 7370 return value == null ? "" : value + "";
nicholas@926 7371 });
nicholas@926 7372 }
nicholas@926 7373
nicholas@926 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nicholas@926 7375
nicholas@926 7376 // If set returns undefined, fall back to normal setting
nicholas@926 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nicholas@926 7378 this.value = val;
nicholas@926 7379 }
nicholas@926 7380 });
nicholas@926 7381 }
nicholas@926 7382 });
nicholas@926 7383
nicholas@926 7384 jQuery.extend({
nicholas@926 7385 valHooks: {
nicholas@926 7386 option: {
nicholas@926 7387 get: function( elem ) {
nicholas@926 7388 var val = jQuery.find.attr( elem, "value" );
nicholas@926 7389 return val != null ?
nicholas@926 7390 val :
nicholas@926 7391 // Support: IE10-11+
nicholas@926 7392 // option.text throws exceptions (#14686, #14858)
nicholas@926 7393 jQuery.trim( jQuery.text( elem ) );
nicholas@926 7394 }
nicholas@926 7395 },
nicholas@926 7396 select: {
nicholas@926 7397 get: function( elem ) {
nicholas@926 7398 var value, option,
nicholas@926 7399 options = elem.options,
nicholas@926 7400 index = elem.selectedIndex,
nicholas@926 7401 one = elem.type === "select-one" || index < 0,
nicholas@926 7402 values = one ? null : [],
nicholas@926 7403 max = one ? index + 1 : options.length,
nicholas@926 7404 i = index < 0 ?
nicholas@926 7405 max :
nicholas@926 7406 one ? index : 0;
nicholas@926 7407
nicholas@926 7408 // Loop through all the selected options
nicholas@926 7409 for ( ; i < max; i++ ) {
nicholas@926 7410 option = options[ i ];
nicholas@926 7411
nicholas@926 7412 // IE6-9 doesn't update selected after form reset (#2551)
nicholas@926 7413 if ( ( option.selected || i === index ) &&
nicholas@926 7414 // Don't return options that are disabled or in a disabled optgroup
nicholas@926 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nicholas@926 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nicholas@926 7417
nicholas@926 7418 // Get the specific value for the option
nicholas@926 7419 value = jQuery( option ).val();
nicholas@926 7420
nicholas@926 7421 // We don't need an array for one selects
nicholas@926 7422 if ( one ) {
nicholas@926 7423 return value;
nicholas@926 7424 }
nicholas@926 7425
nicholas@926 7426 // Multi-Selects return an array
nicholas@926 7427 values.push( value );
nicholas@926 7428 }
nicholas@926 7429 }
nicholas@926 7430
nicholas@926 7431 return values;
nicholas@926 7432 },
nicholas@926 7433
nicholas@926 7434 set: function( elem, value ) {
nicholas@926 7435 var optionSet, option,
nicholas@926 7436 options = elem.options,
nicholas@926 7437 values = jQuery.makeArray( value ),
nicholas@926 7438 i = options.length;
nicholas@926 7439
nicholas@926 7440 while ( i-- ) {
nicholas@926 7441 option = options[ i ];
nicholas@926 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nicholas@926 7443 optionSet = true;
nicholas@926 7444 }
nicholas@926 7445 }
nicholas@926 7446
nicholas@926 7447 // Force browsers to behave consistently when non-matching value is set
nicholas@926 7448 if ( !optionSet ) {
nicholas@926 7449 elem.selectedIndex = -1;
nicholas@926 7450 }
nicholas@926 7451 return values;
nicholas@926 7452 }
nicholas@926 7453 }
nicholas@926 7454 }
nicholas@926 7455 });
nicholas@926 7456
nicholas@926 7457 // Radios and checkboxes getter/setter
nicholas@926 7458 jQuery.each([ "radio", "checkbox" ], function() {
nicholas@926 7459 jQuery.valHooks[ this ] = {
nicholas@926 7460 set: function( elem, value ) {
nicholas@926 7461 if ( jQuery.isArray( value ) ) {
nicholas@926 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nicholas@926 7463 }
nicholas@926 7464 }
nicholas@926 7465 };
nicholas@926 7466 if ( !support.checkOn ) {
nicholas@926 7467 jQuery.valHooks[ this ].get = function( elem ) {
nicholas@926 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nicholas@926 7469 };
nicholas@926 7470 }
nicholas@926 7471 });
nicholas@926 7472
nicholas@926 7473
nicholas@926 7474
nicholas@926 7475
nicholas@926 7476 // Return jQuery for attributes-only inclusion
nicholas@926 7477
nicholas@926 7478
nicholas@926 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nicholas@926 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nicholas@926 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nicholas@926 7482
nicholas@926 7483 // Handle event binding
nicholas@926 7484 jQuery.fn[ name ] = function( data, fn ) {
nicholas@926 7485 return arguments.length > 0 ?
nicholas@926 7486 this.on( name, null, data, fn ) :
nicholas@926 7487 this.trigger( name );
nicholas@926 7488 };
nicholas@926 7489 });
nicholas@926 7490
nicholas@926 7491 jQuery.fn.extend({
nicholas@926 7492 hover: function( fnOver, fnOut ) {
nicholas@926 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nicholas@926 7494 },
nicholas@926 7495
nicholas@926 7496 bind: function( types, data, fn ) {
nicholas@926 7497 return this.on( types, null, data, fn );
nicholas@926 7498 },
nicholas@926 7499 unbind: function( types, fn ) {
nicholas@926 7500 return this.off( types, null, fn );
nicholas@926 7501 },
nicholas@926 7502
nicholas@926 7503 delegate: function( selector, types, data, fn ) {
nicholas@926 7504 return this.on( types, selector, data, fn );
nicholas@926 7505 },
nicholas@926 7506 undelegate: function( selector, types, fn ) {
nicholas@926 7507 // ( namespace ) or ( selector, types [, fn] )
nicholas@926 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nicholas@926 7509 }
nicholas@926 7510 });
nicholas@926 7511
nicholas@926 7512
nicholas@926 7513 var nonce = jQuery.now();
nicholas@926 7514
nicholas@926 7515 var rquery = (/\?/);
nicholas@926 7516
nicholas@926 7517
nicholas@926 7518
nicholas@926 7519 // Support: Android 2.3
nicholas@926 7520 // Workaround failure to string-cast null input
nicholas@926 7521 jQuery.parseJSON = function( data ) {
nicholas@926 7522 return JSON.parse( data + "" );
nicholas@926 7523 };
nicholas@926 7524
nicholas@926 7525
nicholas@926 7526 // Cross-browser xml parsing
nicholas@926 7527 jQuery.parseXML = function( data ) {
nicholas@926 7528 var xml, tmp;
nicholas@926 7529 if ( !data || typeof data !== "string" ) {
nicholas@926 7530 return null;
nicholas@926 7531 }
nicholas@926 7532
nicholas@926 7533 // Support: IE9
nicholas@926 7534 try {
nicholas@926 7535 tmp = new DOMParser();
nicholas@926 7536 xml = tmp.parseFromString( data, "text/xml" );
nicholas@926 7537 } catch ( e ) {
nicholas@926 7538 xml = undefined;
nicholas@926 7539 }
nicholas@926 7540
nicholas@926 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nicholas@926 7542 jQuery.error( "Invalid XML: " + data );
nicholas@926 7543 }
nicholas@926 7544 return xml;
nicholas@926 7545 };
nicholas@926 7546
nicholas@926 7547
nicholas@926 7548 var
nicholas@926 7549 rhash = /#.*$/,
nicholas@926 7550 rts = /([?&])_=[^&]*/,
nicholas@926 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nicholas@926 7552 // #7653, #8125, #8152: local protocol detection
nicholas@926 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nicholas@926 7554 rnoContent = /^(?:GET|HEAD)$/,
nicholas@926 7555 rprotocol = /^\/\//,
nicholas@926 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nicholas@926 7557
nicholas@926 7558 /* Prefilters
nicholas@926 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nicholas@926 7560 * 2) These are called:
nicholas@926 7561 * - BEFORE asking for a transport
nicholas@926 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nicholas@926 7563 * 3) key is the dataType
nicholas@926 7564 * 4) the catchall symbol "*" can be used
nicholas@926 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nicholas@926 7566 */
nicholas@926 7567 prefilters = {},
nicholas@926 7568
nicholas@926 7569 /* Transports bindings
nicholas@926 7570 * 1) key is the dataType
nicholas@926 7571 * 2) the catchall symbol "*" can be used
nicholas@926 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nicholas@926 7573 */
nicholas@926 7574 transports = {},
nicholas@926 7575
nicholas@926 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nicholas@926 7577 allTypes = "*/".concat( "*" ),
nicholas@926 7578
nicholas@926 7579 // Document location
nicholas@926 7580 ajaxLocation = window.location.href,
nicholas@926 7581
nicholas@926 7582 // Segment location into parts
nicholas@926 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nicholas@926 7584
nicholas@926 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nicholas@926 7586 function addToPrefiltersOrTransports( structure ) {
nicholas@926 7587
nicholas@926 7588 // dataTypeExpression is optional and defaults to "*"
nicholas@926 7589 return function( dataTypeExpression, func ) {
nicholas@926 7590
nicholas@926 7591 if ( typeof dataTypeExpression !== "string" ) {
nicholas@926 7592 func = dataTypeExpression;
nicholas@926 7593 dataTypeExpression = "*";
nicholas@926 7594 }
nicholas@926 7595
nicholas@926 7596 var dataType,
nicholas@926 7597 i = 0,
nicholas@926 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nicholas@926 7599
nicholas@926 7600 if ( jQuery.isFunction( func ) ) {
nicholas@926 7601 // For each dataType in the dataTypeExpression
nicholas@926 7602 while ( (dataType = dataTypes[i++]) ) {
nicholas@926 7603 // Prepend if requested
nicholas@926 7604 if ( dataType[0] === "+" ) {
nicholas@926 7605 dataType = dataType.slice( 1 ) || "*";
nicholas@926 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nicholas@926 7607
nicholas@926 7608 // Otherwise append
nicholas@926 7609 } else {
nicholas@926 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nicholas@926 7611 }
nicholas@926 7612 }
nicholas@926 7613 }
nicholas@926 7614 };
nicholas@926 7615 }
nicholas@926 7616
nicholas@926 7617 // Base inspection function for prefilters and transports
nicholas@926 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nicholas@926 7619
nicholas@926 7620 var inspected = {},
nicholas@926 7621 seekingTransport = ( structure === transports );
nicholas@926 7622
nicholas@926 7623 function inspect( dataType ) {
nicholas@926 7624 var selected;
nicholas@926 7625 inspected[ dataType ] = true;
nicholas@926 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nicholas@926 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nicholas@926 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nicholas@926 7629 options.dataTypes.unshift( dataTypeOrTransport );
nicholas@926 7630 inspect( dataTypeOrTransport );
nicholas@926 7631 return false;
nicholas@926 7632 } else if ( seekingTransport ) {
nicholas@926 7633 return !( selected = dataTypeOrTransport );
nicholas@926 7634 }
nicholas@926 7635 });
nicholas@926 7636 return selected;
nicholas@926 7637 }
nicholas@926 7638
nicholas@926 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nicholas@926 7640 }
nicholas@926 7641
nicholas@926 7642 // A special extend for ajax options
nicholas@926 7643 // that takes "flat" options (not to be deep extended)
nicholas@926 7644 // Fixes #9887
nicholas@926 7645 function ajaxExtend( target, src ) {
nicholas@926 7646 var key, deep,
nicholas@926 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nicholas@926 7648
nicholas@926 7649 for ( key in src ) {
nicholas@926 7650 if ( src[ key ] !== undefined ) {
nicholas@926 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nicholas@926 7652 }
nicholas@926 7653 }
nicholas@926 7654 if ( deep ) {
nicholas@926 7655 jQuery.extend( true, target, deep );
nicholas@926 7656 }
nicholas@926 7657
nicholas@926 7658 return target;
nicholas@926 7659 }
nicholas@926 7660
nicholas@926 7661 /* Handles responses to an ajax request:
nicholas@926 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nicholas@926 7663 * - returns the corresponding response
nicholas@926 7664 */
nicholas@926 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nicholas@926 7666
nicholas@926 7667 var ct, type, finalDataType, firstDataType,
nicholas@926 7668 contents = s.contents,
nicholas@926 7669 dataTypes = s.dataTypes;
nicholas@926 7670
nicholas@926 7671 // Remove auto dataType and get content-type in the process
nicholas@926 7672 while ( dataTypes[ 0 ] === "*" ) {
nicholas@926 7673 dataTypes.shift();
nicholas@926 7674 if ( ct === undefined ) {
nicholas@926 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nicholas@926 7676 }
nicholas@926 7677 }
nicholas@926 7678
nicholas@926 7679 // Check if we're dealing with a known content-type
nicholas@926 7680 if ( ct ) {
nicholas@926 7681 for ( type in contents ) {
nicholas@926 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nicholas@926 7683 dataTypes.unshift( type );
nicholas@926 7684 break;
nicholas@926 7685 }
nicholas@926 7686 }
nicholas@926 7687 }
nicholas@926 7688
nicholas@926 7689 // Check to see if we have a response for the expected dataType
nicholas@926 7690 if ( dataTypes[ 0 ] in responses ) {
nicholas@926 7691 finalDataType = dataTypes[ 0 ];
nicholas@926 7692 } else {
nicholas@926 7693 // Try convertible dataTypes
nicholas@926 7694 for ( type in responses ) {
nicholas@926 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nicholas@926 7696 finalDataType = type;
nicholas@926 7697 break;
nicholas@926 7698 }
nicholas@926 7699 if ( !firstDataType ) {
nicholas@926 7700 firstDataType = type;
nicholas@926 7701 }
nicholas@926 7702 }
nicholas@926 7703 // Or just use first one
nicholas@926 7704 finalDataType = finalDataType || firstDataType;
nicholas@926 7705 }
nicholas@926 7706
nicholas@926 7707 // If we found a dataType
nicholas@926 7708 // We add the dataType to the list if needed
nicholas@926 7709 // and return the corresponding response
nicholas@926 7710 if ( finalDataType ) {
nicholas@926 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nicholas@926 7712 dataTypes.unshift( finalDataType );
nicholas@926 7713 }
nicholas@926 7714 return responses[ finalDataType ];
nicholas@926 7715 }
nicholas@926 7716 }
nicholas@926 7717
nicholas@926 7718 /* Chain conversions given the request and the original response
nicholas@926 7719 * Also sets the responseXXX fields on the jqXHR instance
nicholas@926 7720 */
nicholas@926 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nicholas@926 7722 var conv2, current, conv, tmp, prev,
nicholas@926 7723 converters = {},
nicholas@926 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nicholas@926 7725 dataTypes = s.dataTypes.slice();
nicholas@926 7726
nicholas@926 7727 // Create converters map with lowercased keys
nicholas@926 7728 if ( dataTypes[ 1 ] ) {
nicholas@926 7729 for ( conv in s.converters ) {
nicholas@926 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nicholas@926 7731 }
nicholas@926 7732 }
nicholas@926 7733
nicholas@926 7734 current = dataTypes.shift();
nicholas@926 7735
nicholas@926 7736 // Convert to each sequential dataType
nicholas@926 7737 while ( current ) {
nicholas@926 7738
nicholas@926 7739 if ( s.responseFields[ current ] ) {
nicholas@926 7740 jqXHR[ s.responseFields[ current ] ] = response;
nicholas@926 7741 }
nicholas@926 7742
nicholas@926 7743 // Apply the dataFilter if provided
nicholas@926 7744 if ( !prev && isSuccess && s.dataFilter ) {
nicholas@926 7745 response = s.dataFilter( response, s.dataType );
nicholas@926 7746 }
nicholas@926 7747
nicholas@926 7748 prev = current;
nicholas@926 7749 current = dataTypes.shift();
nicholas@926 7750
nicholas@926 7751 if ( current ) {
nicholas@926 7752
nicholas@926 7753 // There's only work to do if current dataType is non-auto
nicholas@926 7754 if ( current === "*" ) {
nicholas@926 7755
nicholas@926 7756 current = prev;
nicholas@926 7757
nicholas@926 7758 // Convert response if prev dataType is non-auto and differs from current
nicholas@926 7759 } else if ( prev !== "*" && prev !== current ) {
nicholas@926 7760
nicholas@926 7761 // Seek a direct converter
nicholas@926 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nicholas@926 7763
nicholas@926 7764 // If none found, seek a pair
nicholas@926 7765 if ( !conv ) {
nicholas@926 7766 for ( conv2 in converters ) {
nicholas@926 7767
nicholas@926 7768 // If conv2 outputs current
nicholas@926 7769 tmp = conv2.split( " " );
nicholas@926 7770 if ( tmp[ 1 ] === current ) {
nicholas@926 7771
nicholas@926 7772 // If prev can be converted to accepted input
nicholas@926 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nicholas@926 7774 converters[ "* " + tmp[ 0 ] ];
nicholas@926 7775 if ( conv ) {
nicholas@926 7776 // Condense equivalence converters
nicholas@926 7777 if ( conv === true ) {
nicholas@926 7778 conv = converters[ conv2 ];
nicholas@926 7779
nicholas@926 7780 // Otherwise, insert the intermediate dataType
nicholas@926 7781 } else if ( converters[ conv2 ] !== true ) {
nicholas@926 7782 current = tmp[ 0 ];
nicholas@926 7783 dataTypes.unshift( tmp[ 1 ] );
nicholas@926 7784 }
nicholas@926 7785 break;
nicholas@926 7786 }
nicholas@926 7787 }
nicholas@926 7788 }
nicholas@926 7789 }
nicholas@926 7790
nicholas@926 7791 // Apply converter (if not an equivalence)
nicholas@926 7792 if ( conv !== true ) {
nicholas@926 7793
nicholas@926 7794 // Unless errors are allowed to bubble, catch and return them
nicholas@926 7795 if ( conv && s[ "throws" ] ) {
nicholas@926 7796 response = conv( response );
nicholas@926 7797 } else {
nicholas@926 7798 try {
nicholas@926 7799 response = conv( response );
nicholas@926 7800 } catch ( e ) {
nicholas@926 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nicholas@926 7802 }
nicholas@926 7803 }
nicholas@926 7804 }
nicholas@926 7805 }
nicholas@926 7806 }
nicholas@926 7807 }
nicholas@926 7808
nicholas@926 7809 return { state: "success", data: response };
nicholas@926 7810 }
nicholas@926 7811
nicholas@926 7812 jQuery.extend({
nicholas@926 7813
nicholas@926 7814 // Counter for holding the number of active queries
nicholas@926 7815 active: 0,
nicholas@926 7816
nicholas@926 7817 // Last-Modified header cache for next request
nicholas@926 7818 lastModified: {},
nicholas@926 7819 etag: {},
nicholas@926 7820
nicholas@926 7821 ajaxSettings: {
nicholas@926 7822 url: ajaxLocation,
nicholas@926 7823 type: "GET",
nicholas@926 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nicholas@926 7825 global: true,
nicholas@926 7826 processData: true,
nicholas@926 7827 async: true,
nicholas@926 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nicholas@926 7829 /*
nicholas@926 7830 timeout: 0,
nicholas@926 7831 data: null,
nicholas@926 7832 dataType: null,
nicholas@926 7833 username: null,
nicholas@926 7834 password: null,
nicholas@926 7835 cache: null,
nicholas@926 7836 throws: false,
nicholas@926 7837 traditional: false,
nicholas@926 7838 headers: {},
nicholas@926 7839 */
nicholas@926 7840
nicholas@926 7841 accepts: {
nicholas@926 7842 "*": allTypes,
nicholas@926 7843 text: "text/plain",
nicholas@926 7844 html: "text/html",
nicholas@926 7845 xml: "application/xml, text/xml",
nicholas@926 7846 json: "application/json, text/javascript"
nicholas@926 7847 },
nicholas@926 7848
nicholas@926 7849 contents: {
nicholas@926 7850 xml: /xml/,
nicholas@926 7851 html: /html/,
nicholas@926 7852 json: /json/
nicholas@926 7853 },
nicholas@926 7854
nicholas@926 7855 responseFields: {
nicholas@926 7856 xml: "responseXML",
nicholas@926 7857 text: "responseText",
nicholas@926 7858 json: "responseJSON"
nicholas@926 7859 },
nicholas@926 7860
nicholas@926 7861 // Data converters
nicholas@926 7862 // Keys separate source (or catchall "*") and destination types with a single space
nicholas@926 7863 converters: {
nicholas@926 7864
nicholas@926 7865 // Convert anything to text
nicholas@926 7866 "* text": String,
nicholas@926 7867
nicholas@926 7868 // Text to html (true = no transformation)
nicholas@926 7869 "text html": true,
nicholas@926 7870
nicholas@926 7871 // Evaluate text as a json expression
nicholas@926 7872 "text json": jQuery.parseJSON,
nicholas@926 7873
nicholas@926 7874 // Parse text as xml
nicholas@926 7875 "text xml": jQuery.parseXML
nicholas@926 7876 },
nicholas@926 7877
nicholas@926 7878 // For options that shouldn't be deep extended:
nicholas@926 7879 // you can add your own custom options here if
nicholas@926 7880 // and when you create one that shouldn't be
nicholas@926 7881 // deep extended (see ajaxExtend)
nicholas@926 7882 flatOptions: {
nicholas@926 7883 url: true,
nicholas@926 7884 context: true
nicholas@926 7885 }
nicholas@926 7886 },
nicholas@926 7887
nicholas@926 7888 // Creates a full fledged settings object into target
nicholas@926 7889 // with both ajaxSettings and settings fields.
nicholas@926 7890 // If target is omitted, writes into ajaxSettings.
nicholas@926 7891 ajaxSetup: function( target, settings ) {
nicholas@926 7892 return settings ?
nicholas@926 7893
nicholas@926 7894 // Building a settings object
nicholas@926 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nicholas@926 7896
nicholas@926 7897 // Extending ajaxSettings
nicholas@926 7898 ajaxExtend( jQuery.ajaxSettings, target );
nicholas@926 7899 },
nicholas@926 7900
nicholas@926 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nicholas@926 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nicholas@926 7903
nicholas@926 7904 // Main method
nicholas@926 7905 ajax: function( url, options ) {
nicholas@926 7906
nicholas@926 7907 // If url is an object, simulate pre-1.5 signature
nicholas@926 7908 if ( typeof url === "object" ) {
nicholas@926 7909 options = url;
nicholas@926 7910 url = undefined;
nicholas@926 7911 }
nicholas@926 7912
nicholas@926 7913 // Force options to be an object
nicholas@926 7914 options = options || {};
nicholas@926 7915
nicholas@926 7916 var transport,
nicholas@926 7917 // URL without anti-cache param
nicholas@926 7918 cacheURL,
nicholas@926 7919 // Response headers
nicholas@926 7920 responseHeadersString,
nicholas@926 7921 responseHeaders,
nicholas@926 7922 // timeout handle
nicholas@926 7923 timeoutTimer,
nicholas@926 7924 // Cross-domain detection vars
nicholas@926 7925 parts,
nicholas@926 7926 // To know if global events are to be dispatched
nicholas@926 7927 fireGlobals,
nicholas@926 7928 // Loop variable
nicholas@926 7929 i,
nicholas@926 7930 // Create the final options object
nicholas@926 7931 s = jQuery.ajaxSetup( {}, options ),
nicholas@926 7932 // Callbacks context
nicholas@926 7933 callbackContext = s.context || s,
nicholas@926 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nicholas@926 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nicholas@926 7936 jQuery( callbackContext ) :
nicholas@926 7937 jQuery.event,
nicholas@926 7938 // Deferreds
nicholas@926 7939 deferred = jQuery.Deferred(),
nicholas@926 7940 completeDeferred = jQuery.Callbacks("once memory"),
nicholas@926 7941 // Status-dependent callbacks
nicholas@926 7942 statusCode = s.statusCode || {},
nicholas@926 7943 // Headers (they are sent all at once)
nicholas@926 7944 requestHeaders = {},
nicholas@926 7945 requestHeadersNames = {},
nicholas@926 7946 // The jqXHR state
nicholas@926 7947 state = 0,
nicholas@926 7948 // Default abort message
nicholas@926 7949 strAbort = "canceled",
nicholas@926 7950 // Fake xhr
nicholas@926 7951 jqXHR = {
nicholas@926 7952 readyState: 0,
nicholas@926 7953
nicholas@926 7954 // Builds headers hashtable if needed
nicholas@926 7955 getResponseHeader: function( key ) {
nicholas@926 7956 var match;
nicholas@926 7957 if ( state === 2 ) {
nicholas@926 7958 if ( !responseHeaders ) {
nicholas@926 7959 responseHeaders = {};
nicholas@926 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nicholas@926 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nicholas@926 7962 }
nicholas@926 7963 }
nicholas@926 7964 match = responseHeaders[ key.toLowerCase() ];
nicholas@926 7965 }
nicholas@926 7966 return match == null ? null : match;
nicholas@926 7967 },
nicholas@926 7968
nicholas@926 7969 // Raw string
nicholas@926 7970 getAllResponseHeaders: function() {
nicholas@926 7971 return state === 2 ? responseHeadersString : null;
nicholas@926 7972 },
nicholas@926 7973
nicholas@926 7974 // Caches the header
nicholas@926 7975 setRequestHeader: function( name, value ) {
nicholas@926 7976 var lname = name.toLowerCase();
nicholas@926 7977 if ( !state ) {
nicholas@926 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nicholas@926 7979 requestHeaders[ name ] = value;
nicholas@926 7980 }
nicholas@926 7981 return this;
nicholas@926 7982 },
nicholas@926 7983
nicholas@926 7984 // Overrides response content-type header
nicholas@926 7985 overrideMimeType: function( type ) {
nicholas@926 7986 if ( !state ) {
nicholas@926 7987 s.mimeType = type;
nicholas@926 7988 }
nicholas@926 7989 return this;
nicholas@926 7990 },
nicholas@926 7991
nicholas@926 7992 // Status-dependent callbacks
nicholas@926 7993 statusCode: function( map ) {
nicholas@926 7994 var code;
nicholas@926 7995 if ( map ) {
nicholas@926 7996 if ( state < 2 ) {
nicholas@926 7997 for ( code in map ) {
nicholas@926 7998 // Lazy-add the new callback in a way that preserves old ones
nicholas@926 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nicholas@926 8000 }
nicholas@926 8001 } else {
nicholas@926 8002 // Execute the appropriate callbacks
nicholas@926 8003 jqXHR.always( map[ jqXHR.status ] );
nicholas@926 8004 }
nicholas@926 8005 }
nicholas@926 8006 return this;
nicholas@926 8007 },
nicholas@926 8008
nicholas@926 8009 // Cancel the request
nicholas@926 8010 abort: function( statusText ) {
nicholas@926 8011 var finalText = statusText || strAbort;
nicholas@926 8012 if ( transport ) {
nicholas@926 8013 transport.abort( finalText );
nicholas@926 8014 }
nicholas@926 8015 done( 0, finalText );
nicholas@926 8016 return this;
nicholas@926 8017 }
nicholas@926 8018 };
nicholas@926 8019
nicholas@926 8020 // Attach deferreds
nicholas@926 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nicholas@926 8022 jqXHR.success = jqXHR.done;
nicholas@926 8023 jqXHR.error = jqXHR.fail;
nicholas@926 8024
nicholas@926 8025 // Remove hash character (#7531: and string promotion)
nicholas@926 8026 // Add protocol if not provided (prefilters might expect it)
nicholas@926 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nicholas@926 8028 // We also use the url parameter if available
nicholas@926 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nicholas@926 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nicholas@926 8031
nicholas@926 8032 // Alias method option to type as per ticket #12004
nicholas@926 8033 s.type = options.method || options.type || s.method || s.type;
nicholas@926 8034
nicholas@926 8035 // Extract dataTypes list
nicholas@926 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nicholas@926 8037
nicholas@926 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nicholas@926 8039 if ( s.crossDomain == null ) {
nicholas@926 8040 parts = rurl.exec( s.url.toLowerCase() );
nicholas@926 8041 s.crossDomain = !!( parts &&
nicholas@926 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nicholas@926 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nicholas@926 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nicholas@926 8045 );
nicholas@926 8046 }
nicholas@926 8047
nicholas@926 8048 // Convert data if not already a string
nicholas@926 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nicholas@926 8050 s.data = jQuery.param( s.data, s.traditional );
nicholas@926 8051 }
nicholas@926 8052
nicholas@926 8053 // Apply prefilters
nicholas@926 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nicholas@926 8055
nicholas@926 8056 // If request was aborted inside a prefilter, stop there
nicholas@926 8057 if ( state === 2 ) {
nicholas@926 8058 return jqXHR;
nicholas@926 8059 }
nicholas@926 8060
nicholas@926 8061 // We can fire global events as of now if asked to
nicholas@926 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nicholas@926 8063 fireGlobals = jQuery.event && s.global;
nicholas@926 8064
nicholas@926 8065 // Watch for a new set of requests
nicholas@926 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nicholas@926 8067 jQuery.event.trigger("ajaxStart");
nicholas@926 8068 }
nicholas@926 8069
nicholas@926 8070 // Uppercase the type
nicholas@926 8071 s.type = s.type.toUpperCase();
nicholas@926 8072
nicholas@926 8073 // Determine if request has content
nicholas@926 8074 s.hasContent = !rnoContent.test( s.type );
nicholas@926 8075
nicholas@926 8076 // Save the URL in case we're toying with the If-Modified-Since
nicholas@926 8077 // and/or If-None-Match header later on
nicholas@926 8078 cacheURL = s.url;
nicholas@926 8079
nicholas@926 8080 // More options handling for requests with no content
nicholas@926 8081 if ( !s.hasContent ) {
nicholas@926 8082
nicholas@926 8083 // If data is available, append data to url
nicholas@926 8084 if ( s.data ) {
nicholas@926 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nicholas@926 8086 // #9682: remove data so that it's not used in an eventual retry
nicholas@926 8087 delete s.data;
nicholas@926 8088 }
nicholas@926 8089
nicholas@926 8090 // Add anti-cache in url if needed
nicholas@926 8091 if ( s.cache === false ) {
nicholas@926 8092 s.url = rts.test( cacheURL ) ?
nicholas@926 8093
nicholas@926 8094 // If there is already a '_' parameter, set its value
nicholas@926 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nicholas@926 8096
nicholas@926 8097 // Otherwise add one to the end
nicholas@926 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nicholas@926 8099 }
nicholas@926 8100 }
nicholas@926 8101
nicholas@926 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nicholas@926 8103 if ( s.ifModified ) {
nicholas@926 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nicholas@926 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nicholas@926 8106 }
nicholas@926 8107 if ( jQuery.etag[ cacheURL ] ) {
nicholas@926 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nicholas@926 8109 }
nicholas@926 8110 }
nicholas@926 8111
nicholas@926 8112 // Set the correct header, if data is being sent
nicholas@926 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nicholas@926 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nicholas@926 8115 }
nicholas@926 8116
nicholas@926 8117 // Set the Accepts header for the server, depending on the dataType
nicholas@926 8118 jqXHR.setRequestHeader(
nicholas@926 8119 "Accept",
nicholas@926 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nicholas@926 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nicholas@926 8122 s.accepts[ "*" ]
nicholas@926 8123 );
nicholas@926 8124
nicholas@926 8125 // Check for headers option
nicholas@926 8126 for ( i in s.headers ) {
nicholas@926 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nicholas@926 8128 }
nicholas@926 8129
nicholas@926 8130 // Allow custom headers/mimetypes and early abort
nicholas@926 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nicholas@926 8132 // Abort if not done already and return
nicholas@926 8133 return jqXHR.abort();
nicholas@926 8134 }
nicholas@926 8135
nicholas@926 8136 // Aborting is no longer a cancellation
nicholas@926 8137 strAbort = "abort";
nicholas@926 8138
nicholas@926 8139 // Install callbacks on deferreds
nicholas@926 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nicholas@926 8141 jqXHR[ i ]( s[ i ] );
nicholas@926 8142 }
nicholas@926 8143
nicholas@926 8144 // Get transport
nicholas@926 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nicholas@926 8146
nicholas@926 8147 // If no transport, we auto-abort
nicholas@926 8148 if ( !transport ) {
nicholas@926 8149 done( -1, "No Transport" );
nicholas@926 8150 } else {
nicholas@926 8151 jqXHR.readyState = 1;
nicholas@926 8152
nicholas@926 8153 // Send global event
nicholas@926 8154 if ( fireGlobals ) {
nicholas@926 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nicholas@926 8156 }
nicholas@926 8157 // Timeout
nicholas@926 8158 if ( s.async && s.timeout > 0 ) {
nicholas@926 8159 timeoutTimer = setTimeout(function() {
nicholas@926 8160 jqXHR.abort("timeout");
nicholas@926 8161 }, s.timeout );
nicholas@926 8162 }
nicholas@926 8163
nicholas@926 8164 try {
nicholas@926 8165 state = 1;
nicholas@926 8166 transport.send( requestHeaders, done );
nicholas@926 8167 } catch ( e ) {
nicholas@926 8168 // Propagate exception as error if not done
nicholas@926 8169 if ( state < 2 ) {
nicholas@926 8170 done( -1, e );
nicholas@926 8171 // Simply rethrow otherwise
nicholas@926 8172 } else {
nicholas@926 8173 throw e;
nicholas@926 8174 }
nicholas@926 8175 }
nicholas@926 8176 }
nicholas@926 8177
nicholas@926 8178 // Callback for when everything is done
nicholas@926 8179 function done( status, nativeStatusText, responses, headers ) {
nicholas@926 8180 var isSuccess, success, error, response, modified,
nicholas@926 8181 statusText = nativeStatusText;
nicholas@926 8182
nicholas@926 8183 // Called once
nicholas@926 8184 if ( state === 2 ) {
nicholas@926 8185 return;
nicholas@926 8186 }
nicholas@926 8187
nicholas@926 8188 // State is "done" now
nicholas@926 8189 state = 2;
nicholas@926 8190
nicholas@926 8191 // Clear timeout if it exists
nicholas@926 8192 if ( timeoutTimer ) {
nicholas@926 8193 clearTimeout( timeoutTimer );
nicholas@926 8194 }
nicholas@926 8195
nicholas@926 8196 // Dereference transport for early garbage collection
nicholas@926 8197 // (no matter how long the jqXHR object will be used)
nicholas@926 8198 transport = undefined;
nicholas@926 8199
nicholas@926 8200 // Cache response headers
nicholas@926 8201 responseHeadersString = headers || "";
nicholas@926 8202
nicholas@926 8203 // Set readyState
nicholas@926 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nicholas@926 8205
nicholas@926 8206 // Determine if successful
nicholas@926 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nicholas@926 8208
nicholas@926 8209 // Get response data
nicholas@926 8210 if ( responses ) {
nicholas@926 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nicholas@926 8212 }
nicholas@926 8213
nicholas@926 8214 // Convert no matter what (that way responseXXX fields are always set)
nicholas@926 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nicholas@926 8216
nicholas@926 8217 // If successful, handle type chaining
nicholas@926 8218 if ( isSuccess ) {
nicholas@926 8219
nicholas@926 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nicholas@926 8221 if ( s.ifModified ) {
nicholas@926 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nicholas@926 8223 if ( modified ) {
nicholas@926 8224 jQuery.lastModified[ cacheURL ] = modified;
nicholas@926 8225 }
nicholas@926 8226 modified = jqXHR.getResponseHeader("etag");
nicholas@926 8227 if ( modified ) {
nicholas@926 8228 jQuery.etag[ cacheURL ] = modified;
nicholas@926 8229 }
nicholas@926 8230 }
nicholas@926 8231
nicholas@926 8232 // if no content
nicholas@926 8233 if ( status === 204 || s.type === "HEAD" ) {
nicholas@926 8234 statusText = "nocontent";
nicholas@926 8235
nicholas@926 8236 // if not modified
nicholas@926 8237 } else if ( status === 304 ) {
nicholas@926 8238 statusText = "notmodified";
nicholas@926 8239
nicholas@926 8240 // If we have data, let's convert it
nicholas@926 8241 } else {
nicholas@926 8242 statusText = response.state;
nicholas@926 8243 success = response.data;
nicholas@926 8244 error = response.error;
nicholas@926 8245 isSuccess = !error;
nicholas@926 8246 }
nicholas@926 8247 } else {
nicholas@926 8248 // Extract error from statusText and normalize for non-aborts
nicholas@926 8249 error = statusText;
nicholas@926 8250 if ( status || !statusText ) {
nicholas@926 8251 statusText = "error";
nicholas@926 8252 if ( status < 0 ) {
nicholas@926 8253 status = 0;
nicholas@926 8254 }
nicholas@926 8255 }
nicholas@926 8256 }
nicholas@926 8257
nicholas@926 8258 // Set data for the fake xhr object
nicholas@926 8259 jqXHR.status = status;
nicholas@926 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nicholas@926 8261
nicholas@926 8262 // Success/Error
nicholas@926 8263 if ( isSuccess ) {
nicholas@926 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nicholas@926 8265 } else {
nicholas@926 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nicholas@926 8267 }
nicholas@926 8268
nicholas@926 8269 // Status-dependent callbacks
nicholas@926 8270 jqXHR.statusCode( statusCode );
nicholas@926 8271 statusCode = undefined;
nicholas@926 8272
nicholas@926 8273 if ( fireGlobals ) {
nicholas@926 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nicholas@926 8275 [ jqXHR, s, isSuccess ? success : error ] );
nicholas@926 8276 }
nicholas@926 8277
nicholas@926 8278 // Complete
nicholas@926 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nicholas@926 8280
nicholas@926 8281 if ( fireGlobals ) {
nicholas@926 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nicholas@926 8283 // Handle the global AJAX counter
nicholas@926 8284 if ( !( --jQuery.active ) ) {
nicholas@926 8285 jQuery.event.trigger("ajaxStop");
nicholas@926 8286 }
nicholas@926 8287 }
nicholas@926 8288 }
nicholas@926 8289
nicholas@926 8290 return jqXHR;
nicholas@926 8291 },
nicholas@926 8292
nicholas@926 8293 getJSON: function( url, data, callback ) {
nicholas@926 8294 return jQuery.get( url, data, callback, "json" );
nicholas@926 8295 },
nicholas@926 8296
nicholas@926 8297 getScript: function( url, callback ) {
nicholas@926 8298 return jQuery.get( url, undefined, callback, "script" );
nicholas@926 8299 }
nicholas@926 8300 });
nicholas@926 8301
nicholas@926 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nicholas@926 8303 jQuery[ method ] = function( url, data, callback, type ) {
nicholas@926 8304 // Shift arguments if data argument was omitted
nicholas@926 8305 if ( jQuery.isFunction( data ) ) {
nicholas@926 8306 type = type || callback;
nicholas@926 8307 callback = data;
nicholas@926 8308 data = undefined;
nicholas@926 8309 }
nicholas@926 8310
nicholas@926 8311 return jQuery.ajax({
nicholas@926 8312 url: url,
nicholas@926 8313 type: method,
nicholas@926 8314 dataType: type,
nicholas@926 8315 data: data,
nicholas@926 8316 success: callback
nicholas@926 8317 });
nicholas@926 8318 };
nicholas@926 8319 });
nicholas@926 8320
nicholas@926 8321
nicholas@926 8322 jQuery._evalUrl = function( url ) {
nicholas@926 8323 return jQuery.ajax({
nicholas@926 8324 url: url,
nicholas@926 8325 type: "GET",
nicholas@926 8326 dataType: "script",
nicholas@926 8327 async: false,
nicholas@926 8328 global: false,
nicholas@926 8329 "throws": true
nicholas@926 8330 });
nicholas@926 8331 };
nicholas@926 8332
nicholas@926 8333
nicholas@926 8334 jQuery.fn.extend({
nicholas@926 8335 wrapAll: function( html ) {
nicholas@926 8336 var wrap;
nicholas@926 8337
nicholas@926 8338 if ( jQuery.isFunction( html ) ) {
nicholas@926 8339 return this.each(function( i ) {
nicholas@926 8340 jQuery( this ).wrapAll( html.call(this, i) );
nicholas@926 8341 });
nicholas@926 8342 }
nicholas@926 8343
nicholas@926 8344 if ( this[ 0 ] ) {
nicholas@926 8345
nicholas@926 8346 // The elements to wrap the target around
nicholas@926 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nicholas@926 8348
nicholas@926 8349 if ( this[ 0 ].parentNode ) {
nicholas@926 8350 wrap.insertBefore( this[ 0 ] );
nicholas@926 8351 }
nicholas@926 8352
nicholas@926 8353 wrap.map(function() {
nicholas@926 8354 var elem = this;
nicholas@926 8355
nicholas@926 8356 while ( elem.firstElementChild ) {
nicholas@926 8357 elem = elem.firstElementChild;
nicholas@926 8358 }
nicholas@926 8359
nicholas@926 8360 return elem;
nicholas@926 8361 }).append( this );
nicholas@926 8362 }
nicholas@926 8363
nicholas@926 8364 return this;
nicholas@926 8365 },
nicholas@926 8366
nicholas@926 8367 wrapInner: function( html ) {
nicholas@926 8368 if ( jQuery.isFunction( html ) ) {
nicholas@926 8369 return this.each(function( i ) {
nicholas@926 8370 jQuery( this ).wrapInner( html.call(this, i) );
nicholas@926 8371 });
nicholas@926 8372 }
nicholas@926 8373
nicholas@926 8374 return this.each(function() {
nicholas@926 8375 var self = jQuery( this ),
nicholas@926 8376 contents = self.contents();
nicholas@926 8377
nicholas@926 8378 if ( contents.length ) {
nicholas@926 8379 contents.wrapAll( html );
nicholas@926 8380
nicholas@926 8381 } else {
nicholas@926 8382 self.append( html );
nicholas@926 8383 }
nicholas@926 8384 });
nicholas@926 8385 },
nicholas@926 8386
nicholas@926 8387 wrap: function( html ) {
nicholas@926 8388 var isFunction = jQuery.isFunction( html );
nicholas@926 8389
nicholas@926 8390 return this.each(function( i ) {
nicholas@926 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nicholas@926 8392 });
nicholas@926 8393 },
nicholas@926 8394
nicholas@926 8395 unwrap: function() {
nicholas@926 8396 return this.parent().each(function() {
nicholas@926 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nicholas@926 8398 jQuery( this ).replaceWith( this.childNodes );
nicholas@926 8399 }
nicholas@926 8400 }).end();
nicholas@926 8401 }
nicholas@926 8402 });
nicholas@926 8403
nicholas@926 8404
nicholas@926 8405 jQuery.expr.filters.hidden = function( elem ) {
nicholas@926 8406 // Support: Opera <= 12.12
nicholas@926 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nicholas@926 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nicholas@926 8409 };
nicholas@926 8410 jQuery.expr.filters.visible = function( elem ) {
nicholas@926 8411 return !jQuery.expr.filters.hidden( elem );
nicholas@926 8412 };
nicholas@926 8413
nicholas@926 8414
nicholas@926 8415
nicholas@926 8416
nicholas@926 8417 var r20 = /%20/g,
nicholas@926 8418 rbracket = /\[\]$/,
nicholas@926 8419 rCRLF = /\r?\n/g,
nicholas@926 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nicholas@926 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nicholas@926 8422
nicholas@926 8423 function buildParams( prefix, obj, traditional, add ) {
nicholas@926 8424 var name;
nicholas@926 8425
nicholas@926 8426 if ( jQuery.isArray( obj ) ) {
nicholas@926 8427 // Serialize array item.
nicholas@926 8428 jQuery.each( obj, function( i, v ) {
nicholas@926 8429 if ( traditional || rbracket.test( prefix ) ) {
nicholas@926 8430 // Treat each array item as a scalar.
nicholas@926 8431 add( prefix, v );
nicholas@926 8432
nicholas@926 8433 } else {
nicholas@926 8434 // Item is non-scalar (array or object), encode its numeric index.
nicholas@926 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nicholas@926 8436 }
nicholas@926 8437 });
nicholas@926 8438
nicholas@926 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nicholas@926 8440 // Serialize object item.
nicholas@926 8441 for ( name in obj ) {
nicholas@926 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nicholas@926 8443 }
nicholas@926 8444
nicholas@926 8445 } else {
nicholas@926 8446 // Serialize scalar item.
nicholas@926 8447 add( prefix, obj );
nicholas@926 8448 }
nicholas@926 8449 }
nicholas@926 8450
nicholas@926 8451 // Serialize an array of form elements or a set of
nicholas@926 8452 // key/values into a query string
nicholas@926 8453 jQuery.param = function( a, traditional ) {
nicholas@926 8454 var prefix,
nicholas@926 8455 s = [],
nicholas@926 8456 add = function( key, value ) {
nicholas@926 8457 // If value is a function, invoke it and return its value
nicholas@926 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nicholas@926 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nicholas@926 8460 };
nicholas@926 8461
nicholas@926 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nicholas@926 8463 if ( traditional === undefined ) {
nicholas@926 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nicholas@926 8465 }
nicholas@926 8466
nicholas@926 8467 // If an array was passed in, assume that it is an array of form elements.
nicholas@926 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nicholas@926 8469 // Serialize the form elements
nicholas@926 8470 jQuery.each( a, function() {
nicholas@926 8471 add( this.name, this.value );
nicholas@926 8472 });
nicholas@926 8473
nicholas@926 8474 } else {
nicholas@926 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nicholas@926 8476 // did it), otherwise encode params recursively.
nicholas@926 8477 for ( prefix in a ) {
nicholas@926 8478 buildParams( prefix, a[ prefix ], traditional, add );
nicholas@926 8479 }
nicholas@926 8480 }
nicholas@926 8481
nicholas@926 8482 // Return the resulting serialization
nicholas@926 8483 return s.join( "&" ).replace( r20, "+" );
nicholas@926 8484 };
nicholas@926 8485
nicholas@926 8486 jQuery.fn.extend({
nicholas@926 8487 serialize: function() {
nicholas@926 8488 return jQuery.param( this.serializeArray() );
nicholas@926 8489 },
nicholas@926 8490 serializeArray: function() {
nicholas@926 8491 return this.map(function() {
nicholas@926 8492 // Can add propHook for "elements" to filter or add form elements
nicholas@926 8493 var elements = jQuery.prop( this, "elements" );
nicholas@926 8494 return elements ? jQuery.makeArray( elements ) : this;
nicholas@926 8495 })
nicholas@926 8496 .filter(function() {
nicholas@926 8497 var type = this.type;
nicholas@926 8498
nicholas@926 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nicholas@926 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nicholas@926 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nicholas@926 8502 ( this.checked || !rcheckableType.test( type ) );
nicholas@926 8503 })
nicholas@926 8504 .map(function( i, elem ) {
nicholas@926 8505 var val = jQuery( this ).val();
nicholas@926 8506
nicholas@926 8507 return val == null ?
nicholas@926 8508 null :
nicholas@926 8509 jQuery.isArray( val ) ?
nicholas@926 8510 jQuery.map( val, function( val ) {
nicholas@926 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nicholas@926 8512 }) :
nicholas@926 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nicholas@926 8514 }).get();
nicholas@926 8515 }
nicholas@926 8516 });
nicholas@926 8517
nicholas@926 8518
nicholas@926 8519 jQuery.ajaxSettings.xhr = function() {
nicholas@926 8520 try {
nicholas@926 8521 return new XMLHttpRequest();
nicholas@926 8522 } catch( e ) {}
nicholas@926 8523 };
nicholas@926 8524
nicholas@926 8525 var xhrId = 0,
nicholas@926 8526 xhrCallbacks = {},
nicholas@926 8527 xhrSuccessStatus = {
nicholas@926 8528 // file protocol always yields status code 0, assume 200
nicholas@926 8529 0: 200,
nicholas@926 8530 // Support: IE9
nicholas@926 8531 // #1450: sometimes IE returns 1223 when it should be 204
nicholas@926 8532 1223: 204
nicholas@926 8533 },
nicholas@926 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nicholas@926 8535
nicholas@926 8536 // Support: IE9
nicholas@926 8537 // Open requests must be manually aborted on unload (#5280)
nicholas@926 8538 // See https://support.microsoft.com/kb/2856746 for more info
nicholas@926 8539 if ( window.attachEvent ) {
nicholas@926 8540 window.attachEvent( "onunload", function() {
nicholas@926 8541 for ( var key in xhrCallbacks ) {
nicholas@926 8542 xhrCallbacks[ key ]();
nicholas@926 8543 }
nicholas@926 8544 });
nicholas@926 8545 }
nicholas@926 8546
nicholas@926 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nicholas@926 8548 support.ajax = xhrSupported = !!xhrSupported;
nicholas@926 8549
nicholas@926 8550 jQuery.ajaxTransport(function( options ) {
nicholas@926 8551 var callback;
nicholas@926 8552
nicholas@926 8553 // Cross domain only allowed if supported through XMLHttpRequest
nicholas@926 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nicholas@926 8555 return {
nicholas@926 8556 send: function( headers, complete ) {
nicholas@926 8557 var i,
nicholas@926 8558 xhr = options.xhr(),
nicholas@926 8559 id = ++xhrId;
nicholas@926 8560
nicholas@926 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nicholas@926 8562
nicholas@926 8563 // Apply custom fields if provided
nicholas@926 8564 if ( options.xhrFields ) {
nicholas@926 8565 for ( i in options.xhrFields ) {
nicholas@926 8566 xhr[ i ] = options.xhrFields[ i ];
nicholas@926 8567 }
nicholas@926 8568 }
nicholas@926 8569
nicholas@926 8570 // Override mime type if needed
nicholas@926 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nicholas@926 8572 xhr.overrideMimeType( options.mimeType );
nicholas@926 8573 }
nicholas@926 8574
nicholas@926 8575 // X-Requested-With header
nicholas@926 8576 // For cross-domain requests, seeing as conditions for a preflight are
nicholas@926 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nicholas@926 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nicholas@926 8579 // For same-domain requests, won't change header if already provided.
nicholas@926 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nicholas@926 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nicholas@926 8582 }
nicholas@926 8583
nicholas@926 8584 // Set headers
nicholas@926 8585 for ( i in headers ) {
nicholas@926 8586 xhr.setRequestHeader( i, headers[ i ] );
nicholas@926 8587 }
nicholas@926 8588
nicholas@926 8589 // Callback
nicholas@926 8590 callback = function( type ) {
nicholas@926 8591 return function() {
nicholas@926 8592 if ( callback ) {
nicholas@926 8593 delete xhrCallbacks[ id ];
nicholas@926 8594 callback = xhr.onload = xhr.onerror = null;
nicholas@926 8595
nicholas@926 8596 if ( type === "abort" ) {
nicholas@926 8597 xhr.abort();
nicholas@926 8598 } else if ( type === "error" ) {
nicholas@926 8599 complete(
nicholas@926 8600 // file: protocol always yields status 0; see #8605, #14207
nicholas@926 8601 xhr.status,
nicholas@926 8602 xhr.statusText
nicholas@926 8603 );
nicholas@926 8604 } else {
nicholas@926 8605 complete(
nicholas@926 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nicholas@926 8607 xhr.statusText,
nicholas@926 8608 // Support: IE9
nicholas@926 8609 // Accessing binary-data responseText throws an exception
nicholas@926 8610 // (#11426)
nicholas@926 8611 typeof xhr.responseText === "string" ? {
nicholas@926 8612 text: xhr.responseText
nicholas@926 8613 } : undefined,
nicholas@926 8614 xhr.getAllResponseHeaders()
nicholas@926 8615 );
nicholas@926 8616 }
nicholas@926 8617 }
nicholas@926 8618 };
nicholas@926 8619 };
nicholas@926 8620
nicholas@926 8621 // Listen to events
nicholas@926 8622 xhr.onload = callback();
nicholas@926 8623 xhr.onerror = callback("error");
nicholas@926 8624
nicholas@926 8625 // Create the abort callback
nicholas@926 8626 callback = xhrCallbacks[ id ] = callback("abort");
nicholas@926 8627
nicholas@926 8628 try {
nicholas@926 8629 // Do send the request (this may raise an exception)
nicholas@926 8630 xhr.send( options.hasContent && options.data || null );
nicholas@926 8631 } catch ( e ) {
nicholas@926 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nicholas@926 8633 if ( callback ) {
nicholas@926 8634 throw e;
nicholas@926 8635 }
nicholas@926 8636 }
nicholas@926 8637 },
nicholas@926 8638
nicholas@926 8639 abort: function() {
nicholas@926 8640 if ( callback ) {
nicholas@926 8641 callback();
nicholas@926 8642 }
nicholas@926 8643 }
nicholas@926 8644 };
nicholas@926 8645 }
nicholas@926 8646 });
nicholas@926 8647
nicholas@926 8648
nicholas@926 8649
nicholas@926 8650
nicholas@926 8651 // Install script dataType
nicholas@926 8652 jQuery.ajaxSetup({
nicholas@926 8653 accepts: {
nicholas@926 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nicholas@926 8655 },
nicholas@926 8656 contents: {
nicholas@926 8657 script: /(?:java|ecma)script/
nicholas@926 8658 },
nicholas@926 8659 converters: {
nicholas@926 8660 "text script": function( text ) {
nicholas@926 8661 jQuery.globalEval( text );
nicholas@926 8662 return text;
nicholas@926 8663 }
nicholas@926 8664 }
nicholas@926 8665 });
nicholas@926 8666
nicholas@926 8667 // Handle cache's special case and crossDomain
nicholas@926 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nicholas@926 8669 if ( s.cache === undefined ) {
nicholas@926 8670 s.cache = false;
nicholas@926 8671 }
nicholas@926 8672 if ( s.crossDomain ) {
nicholas@926 8673 s.type = "GET";
nicholas@926 8674 }
nicholas@926 8675 });
nicholas@926 8676
nicholas@926 8677 // Bind script tag hack transport
nicholas@926 8678 jQuery.ajaxTransport( "script", function( s ) {
nicholas@926 8679 // This transport only deals with cross domain requests
nicholas@926 8680 if ( s.crossDomain ) {
nicholas@926 8681 var script, callback;
nicholas@926 8682 return {
nicholas@926 8683 send: function( _, complete ) {
nicholas@926 8684 script = jQuery("<script>").prop({
nicholas@926 8685 async: true,
nicholas@926 8686 charset: s.scriptCharset,
nicholas@926 8687 src: s.url
nicholas@926 8688 }).on(
nicholas@926 8689 "load error",
nicholas@926 8690 callback = function( evt ) {
nicholas@926 8691 script.remove();
nicholas@926 8692 callback = null;
nicholas@926 8693 if ( evt ) {
nicholas@926 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nicholas@926 8695 }
nicholas@926 8696 }
nicholas@926 8697 );
nicholas@926 8698 document.head.appendChild( script[ 0 ] );
nicholas@926 8699 },
nicholas@926 8700 abort: function() {
nicholas@926 8701 if ( callback ) {
nicholas@926 8702 callback();
nicholas@926 8703 }
nicholas@926 8704 }
nicholas@926 8705 };
nicholas@926 8706 }
nicholas@926 8707 });
nicholas@926 8708
nicholas@926 8709
nicholas@926 8710
nicholas@926 8711
nicholas@926 8712 var oldCallbacks = [],
nicholas@926 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nicholas@926 8714
nicholas@926 8715 // Default jsonp settings
nicholas@926 8716 jQuery.ajaxSetup({
nicholas@926 8717 jsonp: "callback",
nicholas@926 8718 jsonpCallback: function() {
nicholas@926 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nicholas@926 8720 this[ callback ] = true;
nicholas@926 8721 return callback;
nicholas@926 8722 }
nicholas@926 8723 });
nicholas@926 8724
nicholas@926 8725 // Detect, normalize options and install callbacks for jsonp requests
nicholas@926 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nicholas@926 8727
nicholas@926 8728 var callbackName, overwritten, responseContainer,
nicholas@926 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nicholas@926 8730 "url" :
nicholas@926 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nicholas@926 8732 );
nicholas@926 8733
nicholas@926 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nicholas@926 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nicholas@926 8736
nicholas@926 8737 // Get callback name, remembering preexisting value associated with it
nicholas@926 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nicholas@926 8739 s.jsonpCallback() :
nicholas@926 8740 s.jsonpCallback;
nicholas@926 8741
nicholas@926 8742 // Insert callback into url or form data
nicholas@926 8743 if ( jsonProp ) {
nicholas@926 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nicholas@926 8745 } else if ( s.jsonp !== false ) {
nicholas@926 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nicholas@926 8747 }
nicholas@926 8748
nicholas@926 8749 // Use data converter to retrieve json after script execution
nicholas@926 8750 s.converters["script json"] = function() {
nicholas@926 8751 if ( !responseContainer ) {
nicholas@926 8752 jQuery.error( callbackName + " was not called" );
nicholas@926 8753 }
nicholas@926 8754 return responseContainer[ 0 ];
nicholas@926 8755 };
nicholas@926 8756
nicholas@926 8757 // force json dataType
nicholas@926 8758 s.dataTypes[ 0 ] = "json";
nicholas@926 8759
nicholas@926 8760 // Install callback
nicholas@926 8761 overwritten = window[ callbackName ];
nicholas@926 8762 window[ callbackName ] = function() {
nicholas@926 8763 responseContainer = arguments;
nicholas@926 8764 };
nicholas@926 8765
nicholas@926 8766 // Clean-up function (fires after converters)
nicholas@926 8767 jqXHR.always(function() {
nicholas@926 8768 // Restore preexisting value
nicholas@926 8769 window[ callbackName ] = overwritten;
nicholas@926 8770
nicholas@926 8771 // Save back as free
nicholas@926 8772 if ( s[ callbackName ] ) {
nicholas@926 8773 // make sure that re-using the options doesn't screw things around
nicholas@926 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nicholas@926 8775
nicholas@926 8776 // save the callback name for future use
nicholas@926 8777 oldCallbacks.push( callbackName );
nicholas@926 8778 }
nicholas@926 8779
nicholas@926 8780 // Call if it was a function and we have a response
nicholas@926 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nicholas@926 8782 overwritten( responseContainer[ 0 ] );
nicholas@926 8783 }
nicholas@926 8784
nicholas@926 8785 responseContainer = overwritten = undefined;
nicholas@926 8786 });
nicholas@926 8787
nicholas@926 8788 // Delegate to script
nicholas@926 8789 return "script";
nicholas@926 8790 }
nicholas@926 8791 });
nicholas@926 8792
nicholas@926 8793
nicholas@926 8794
nicholas@926 8795
nicholas@926 8796 // data: string of html
nicholas@926 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nicholas@926 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nicholas@926 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nicholas@926 8800 if ( !data || typeof data !== "string" ) {
nicholas@926 8801 return null;
nicholas@926 8802 }
nicholas@926 8803 if ( typeof context === "boolean" ) {
nicholas@926 8804 keepScripts = context;
nicholas@926 8805 context = false;
nicholas@926 8806 }
nicholas@926 8807 context = context || document;
nicholas@926 8808
nicholas@926 8809 var parsed = rsingleTag.exec( data ),
nicholas@926 8810 scripts = !keepScripts && [];
nicholas@926 8811
nicholas@926 8812 // Single tag
nicholas@926 8813 if ( parsed ) {
nicholas@926 8814 return [ context.createElement( parsed[1] ) ];
nicholas@926 8815 }
nicholas@926 8816
nicholas@926 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nicholas@926 8818
nicholas@926 8819 if ( scripts && scripts.length ) {
nicholas@926 8820 jQuery( scripts ).remove();
nicholas@926 8821 }
nicholas@926 8822
nicholas@926 8823 return jQuery.merge( [], parsed.childNodes );
nicholas@926 8824 };
nicholas@926 8825
nicholas@926 8826
nicholas@926 8827 // Keep a copy of the old load method
nicholas@926 8828 var _load = jQuery.fn.load;
nicholas@926 8829
nicholas@926 8830 /**
nicholas@926 8831 * Load a url into a page
nicholas@926 8832 */
nicholas@926 8833 jQuery.fn.load = function( url, params, callback ) {
nicholas@926 8834 if ( typeof url !== "string" && _load ) {
nicholas@926 8835 return _load.apply( this, arguments );
nicholas@926 8836 }
nicholas@926 8837
nicholas@926 8838 var selector, type, response,
nicholas@926 8839 self = this,
nicholas@926 8840 off = url.indexOf(" ");
nicholas@926 8841
nicholas@926 8842 if ( off >= 0 ) {
nicholas@926 8843 selector = jQuery.trim( url.slice( off ) );
nicholas@926 8844 url = url.slice( 0, off );
nicholas@926 8845 }
nicholas@926 8846
nicholas@926 8847 // If it's a function
nicholas@926 8848 if ( jQuery.isFunction( params ) ) {
nicholas@926 8849
nicholas@926 8850 // We assume that it's the callback
nicholas@926 8851 callback = params;
nicholas@926 8852 params = undefined;
nicholas@926 8853
nicholas@926 8854 // Otherwise, build a param string
nicholas@926 8855 } else if ( params && typeof params === "object" ) {
nicholas@926 8856 type = "POST";
nicholas@926 8857 }
nicholas@926 8858
nicholas@926 8859 // If we have elements to modify, make the request
nicholas@926 8860 if ( self.length > 0 ) {
nicholas@926 8861 jQuery.ajax({
nicholas@926 8862 url: url,
nicholas@926 8863
nicholas@926 8864 // if "type" variable is undefined, then "GET" method will be used
nicholas@926 8865 type: type,
nicholas@926 8866 dataType: "html",
nicholas@926 8867 data: params
nicholas@926 8868 }).done(function( responseText ) {
nicholas@926 8869
nicholas@926 8870 // Save response for use in complete callback
nicholas@926 8871 response = arguments;
nicholas@926 8872
nicholas@926 8873 self.html( selector ?
nicholas@926 8874
nicholas@926 8875 // If a selector was specified, locate the right elements in a dummy div
nicholas@926 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nicholas@926 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nicholas@926 8878
nicholas@926 8879 // Otherwise use the full result
nicholas@926 8880 responseText );
nicholas@926 8881
nicholas@926 8882 }).complete( callback && function( jqXHR, status ) {
nicholas@926 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nicholas@926 8884 });
nicholas@926 8885 }
nicholas@926 8886
nicholas@926 8887 return this;
nicholas@926 8888 };
nicholas@926 8889
nicholas@926 8890
nicholas@926 8891
nicholas@926 8892
nicholas@926 8893 // Attach a bunch of functions for handling common AJAX events
nicholas@926 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nicholas@926 8895 jQuery.fn[ type ] = function( fn ) {
nicholas@926 8896 return this.on( type, fn );
nicholas@926 8897 };
nicholas@926 8898 });
nicholas@926 8899
nicholas@926 8900
nicholas@926 8901
nicholas@926 8902
nicholas@926 8903 jQuery.expr.filters.animated = function( elem ) {
nicholas@926 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nicholas@926 8905 return elem === fn.elem;
nicholas@926 8906 }).length;
nicholas@926 8907 };
nicholas@926 8908
nicholas@926 8909
nicholas@926 8910
nicholas@926 8911
nicholas@926 8912 var docElem = window.document.documentElement;
nicholas@926 8913
nicholas@926 8914 /**
nicholas@926 8915 * Gets a window from an element
nicholas@926 8916 */
nicholas@926 8917 function getWindow( elem ) {
nicholas@926 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nicholas@926 8919 }
nicholas@926 8920
nicholas@926 8921 jQuery.offset = {
nicholas@926 8922 setOffset: function( elem, options, i ) {
nicholas@926 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nicholas@926 8924 position = jQuery.css( elem, "position" ),
nicholas@926 8925 curElem = jQuery( elem ),
nicholas@926 8926 props = {};
nicholas@926 8927
nicholas@926 8928 // Set position first, in-case top/left are set even on static elem
nicholas@926 8929 if ( position === "static" ) {
nicholas@926 8930 elem.style.position = "relative";
nicholas@926 8931 }
nicholas@926 8932
nicholas@926 8933 curOffset = curElem.offset();
nicholas@926 8934 curCSSTop = jQuery.css( elem, "top" );
nicholas@926 8935 curCSSLeft = jQuery.css( elem, "left" );
nicholas@926 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nicholas@926 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nicholas@926 8938
nicholas@926 8939 // Need to be able to calculate position if either
nicholas@926 8940 // top or left is auto and position is either absolute or fixed
nicholas@926 8941 if ( calculatePosition ) {
nicholas@926 8942 curPosition = curElem.position();
nicholas@926 8943 curTop = curPosition.top;
nicholas@926 8944 curLeft = curPosition.left;
nicholas@926 8945
nicholas@926 8946 } else {
nicholas@926 8947 curTop = parseFloat( curCSSTop ) || 0;
nicholas@926 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nicholas@926 8949 }
nicholas@926 8950
nicholas@926 8951 if ( jQuery.isFunction( options ) ) {
nicholas@926 8952 options = options.call( elem, i, curOffset );
nicholas@926 8953 }
nicholas@926 8954
nicholas@926 8955 if ( options.top != null ) {
nicholas@926 8956 props.top = ( options.top - curOffset.top ) + curTop;
nicholas@926 8957 }
nicholas@926 8958 if ( options.left != null ) {
nicholas@926 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nicholas@926 8960 }
nicholas@926 8961
nicholas@926 8962 if ( "using" in options ) {
nicholas@926 8963 options.using.call( elem, props );
nicholas@926 8964
nicholas@926 8965 } else {
nicholas@926 8966 curElem.css( props );
nicholas@926 8967 }
nicholas@926 8968 }
nicholas@926 8969 };
nicholas@926 8970
nicholas@926 8971 jQuery.fn.extend({
nicholas@926 8972 offset: function( options ) {
nicholas@926 8973 if ( arguments.length ) {
nicholas@926 8974 return options === undefined ?
nicholas@926 8975 this :
nicholas@926 8976 this.each(function( i ) {
nicholas@926 8977 jQuery.offset.setOffset( this, options, i );
nicholas@926 8978 });
nicholas@926 8979 }
nicholas@926 8980
nicholas@926 8981 var docElem, win,
nicholas@926 8982 elem = this[ 0 ],
nicholas@926 8983 box = { top: 0, left: 0 },
nicholas@926 8984 doc = elem && elem.ownerDocument;
nicholas@926 8985
nicholas@926 8986 if ( !doc ) {
nicholas@926 8987 return;
nicholas@926 8988 }
nicholas@926 8989
nicholas@926 8990 docElem = doc.documentElement;
nicholas@926 8991
nicholas@926 8992 // Make sure it's not a disconnected DOM node
nicholas@926 8993 if ( !jQuery.contains( docElem, elem ) ) {
nicholas@926 8994 return box;
nicholas@926 8995 }
nicholas@926 8996
nicholas@926 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nicholas@926 8998 // If we don't have gBCR, just use 0,0 rather than error
nicholas@926 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nicholas@926 9000 box = elem.getBoundingClientRect();
nicholas@926 9001 }
nicholas@926 9002 win = getWindow( doc );
nicholas@926 9003 return {
nicholas@926 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nicholas@926 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nicholas@926 9006 };
nicholas@926 9007 },
nicholas@926 9008
nicholas@926 9009 position: function() {
nicholas@926 9010 if ( !this[ 0 ] ) {
nicholas@926 9011 return;
nicholas@926 9012 }
nicholas@926 9013
nicholas@926 9014 var offsetParent, offset,
nicholas@926 9015 elem = this[ 0 ],
nicholas@926 9016 parentOffset = { top: 0, left: 0 };
nicholas@926 9017
nicholas@926 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nicholas@926 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nicholas@926 9020 // Assume getBoundingClientRect is there when computed position is fixed
nicholas@926 9021 offset = elem.getBoundingClientRect();
nicholas@926 9022
nicholas@926 9023 } else {
nicholas@926 9024 // Get *real* offsetParent
nicholas@926 9025 offsetParent = this.offsetParent();
nicholas@926 9026
nicholas@926 9027 // Get correct offsets
nicholas@926 9028 offset = this.offset();
nicholas@926 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nicholas@926 9030 parentOffset = offsetParent.offset();
nicholas@926 9031 }
nicholas@926 9032
nicholas@926 9033 // Add offsetParent borders
nicholas@926 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nicholas@926 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nicholas@926 9036 }
nicholas@926 9037
nicholas@926 9038 // Subtract parent offsets and element margins
nicholas@926 9039 return {
nicholas@926 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nicholas@926 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nicholas@926 9042 };
nicholas@926 9043 },
nicholas@926 9044
nicholas@926 9045 offsetParent: function() {
nicholas@926 9046 return this.map(function() {
nicholas@926 9047 var offsetParent = this.offsetParent || docElem;
nicholas@926 9048
nicholas@926 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nicholas@926 9050 offsetParent = offsetParent.offsetParent;
nicholas@926 9051 }
nicholas@926 9052
nicholas@926 9053 return offsetParent || docElem;
nicholas@926 9054 });
nicholas@926 9055 }
nicholas@926 9056 });
nicholas@926 9057
nicholas@926 9058 // Create scrollLeft and scrollTop methods
nicholas@926 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nicholas@926 9060 var top = "pageYOffset" === prop;
nicholas@926 9061
nicholas@926 9062 jQuery.fn[ method ] = function( val ) {
nicholas@926 9063 return access( this, function( elem, method, val ) {
nicholas@926 9064 var win = getWindow( elem );
nicholas@926 9065
nicholas@926 9066 if ( val === undefined ) {
nicholas@926 9067 return win ? win[ prop ] : elem[ method ];
nicholas@926 9068 }
nicholas@926 9069
nicholas@926 9070 if ( win ) {
nicholas@926 9071 win.scrollTo(
nicholas@926 9072 !top ? val : window.pageXOffset,
nicholas@926 9073 top ? val : window.pageYOffset
nicholas@926 9074 );
nicholas@926 9075
nicholas@926 9076 } else {
nicholas@926 9077 elem[ method ] = val;
nicholas@926 9078 }
nicholas@926 9079 }, method, val, arguments.length, null );
nicholas@926 9080 };
nicholas@926 9081 });
nicholas@926 9082
nicholas@926 9083 // Support: Safari<7+, Chrome<37+
nicholas@926 9084 // Add the top/left cssHooks using jQuery.fn.position
nicholas@926 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nicholas@926 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nicholas@926 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nicholas@926 9088 // rather than make the css module depend on the offset module, just check for it here
nicholas@926 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nicholas@926 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nicholas@926 9091 function( elem, computed ) {
nicholas@926 9092 if ( computed ) {
nicholas@926 9093 computed = curCSS( elem, prop );
nicholas@926 9094 // If curCSS returns percentage, fallback to offset
nicholas@926 9095 return rnumnonpx.test( computed ) ?
nicholas@926 9096 jQuery( elem ).position()[ prop ] + "px" :
nicholas@926 9097 computed;
nicholas@926 9098 }
nicholas@926 9099 }
nicholas@926 9100 );
nicholas@926 9101 });
nicholas@926 9102
nicholas@926 9103
nicholas@926 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nicholas@926 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nicholas@926 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nicholas@926 9107 // Margin is only for outerHeight, outerWidth
nicholas@926 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nicholas@926 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nicholas@926 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nicholas@926 9111
nicholas@926 9112 return access( this, function( elem, type, value ) {
nicholas@926 9113 var doc;
nicholas@926 9114
nicholas@926 9115 if ( jQuery.isWindow( elem ) ) {
nicholas@926 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nicholas@926 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nicholas@926 9118 // https://github.com/jquery/jquery/pull/764
nicholas@926 9119 return elem.document.documentElement[ "client" + name ];
nicholas@926 9120 }
nicholas@926 9121
nicholas@926 9122 // Get document width or height
nicholas@926 9123 if ( elem.nodeType === 9 ) {
nicholas@926 9124 doc = elem.documentElement;
nicholas@926 9125
nicholas@926 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nicholas@926 9127 // whichever is greatest
nicholas@926 9128 return Math.max(
nicholas@926 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nicholas@926 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nicholas@926 9131 doc[ "client" + name ]
nicholas@926 9132 );
nicholas@926 9133 }
nicholas@926 9134
nicholas@926 9135 return value === undefined ?
nicholas@926 9136 // Get width or height on the element, requesting but not forcing parseFloat
nicholas@926 9137 jQuery.css( elem, type, extra ) :
nicholas@926 9138
nicholas@926 9139 // Set width or height on the element
nicholas@926 9140 jQuery.style( elem, type, value, extra );
nicholas@926 9141 }, type, chainable ? margin : undefined, chainable, null );
nicholas@926 9142 };
nicholas@926 9143 });
nicholas@926 9144 });
nicholas@926 9145
nicholas@926 9146
nicholas@926 9147 // The number of elements contained in the matched element set
nicholas@926 9148 jQuery.fn.size = function() {
nicholas@926 9149 return this.length;
nicholas@926 9150 };
nicholas@926 9151
nicholas@926 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nicholas@926 9153
nicholas@926 9154
nicholas@926 9155
nicholas@926 9156
nicholas@926 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nicholas@926 9158 // files that may use define, but not via a proper concatenation script that
nicholas@926 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nicholas@926 9160 // way to register. Lowercase jquery is used because AMD module names are
nicholas@926 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nicholas@926 9162 // file name. Do this after creating the global so that if an AMD module wants
nicholas@926 9163 // to call noConflict to hide this version of jQuery, it will work.
nicholas@926 9164
nicholas@926 9165 // Note that for maximum portability, libraries that are not jQuery should
nicholas@926 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nicholas@926 9167 // AMD loader is present. jQuery is a special case. For more information, see
nicholas@926 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nicholas@926 9169
nicholas@926 9170 if ( typeof define === "function" && define.amd ) {
nicholas@926 9171 define( "jquery", [], function() {
nicholas@926 9172 return jQuery;
nicholas@926 9173 });
nicholas@926 9174 }
nicholas@926 9175
nicholas@926 9176
nicholas@926 9177
nicholas@926 9178
nicholas@926 9179 var
nicholas@926 9180 // Map over jQuery in case of overwrite
nicholas@926 9181 _jQuery = window.jQuery,
nicholas@926 9182
nicholas@926 9183 // Map over the $ in case of overwrite
nicholas@926 9184 _$ = window.$;
nicholas@926 9185
nicholas@926 9186 jQuery.noConflict = function( deep ) {
nicholas@926 9187 if ( window.$ === jQuery ) {
nicholas@926 9188 window.$ = _$;
nicholas@926 9189 }
nicholas@926 9190
nicholas@926 9191 if ( deep && window.jQuery === jQuery ) {
nicholas@926 9192 window.jQuery = _jQuery;
nicholas@926 9193 }
nicholas@926 9194
nicholas@926 9195 return jQuery;
nicholas@926 9196 };
nicholas@926 9197
nicholas@926 9198 // Expose jQuery and $ identifiers, even in AMD
nicholas@926 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nicholas@926 9200 // and CommonJS for browser emulators (#13566)
nicholas@926 9201 if ( typeof noGlobal === strundefined ) {
nicholas@926 9202 window.jQuery = window.$ = jQuery;
nicholas@926 9203 }
nicholas@926 9204
nicholas@926 9205
nicholas@926 9206
nicholas@926 9207
nicholas@926 9208 return jQuery;
nicholas@926 9209
nicholas@926 9210 }));