annotate core/assets/vendor/jquery/jquery.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 /*!
Chris@0 2 * jQuery JavaScript Library v3.2.1
Chris@0 3 * https://jquery.com/
Chris@0 4 *
Chris@0 5 * Includes Sizzle.js
Chris@0 6 * https://sizzlejs.com/
Chris@0 7 *
Chris@0 8 * Copyright JS Foundation and other contributors
Chris@0 9 * Released under the MIT license
Chris@0 10 * https://jquery.org/license
Chris@0 11 *
Chris@0 12 * Date: 2017-03-20T18:59Z
Chris@0 13 */
Chris@0 14 ( function( global, factory ) {
Chris@0 15
Chris@0 16 "use strict";
Chris@0 17
Chris@0 18 if ( typeof module === "object" && typeof module.exports === "object" ) {
Chris@0 19
Chris@0 20 // For CommonJS and CommonJS-like environments where a proper `window`
Chris@0 21 // is present, execute the factory and get jQuery.
Chris@0 22 // For environments that do not have a `window` with a `document`
Chris@0 23 // (such as Node.js), expose a factory as module.exports.
Chris@0 24 // This accentuates the need for the creation of a real `window`.
Chris@0 25 // e.g. var jQuery = require("jquery")(window);
Chris@0 26 // See ticket #14549 for more info.
Chris@0 27 module.exports = global.document ?
Chris@0 28 factory( global, true ) :
Chris@0 29 function( w ) {
Chris@0 30 if ( !w.document ) {
Chris@0 31 throw new Error( "jQuery requires a window with a document" );
Chris@0 32 }
Chris@0 33 return factory( w );
Chris@0 34 };
Chris@0 35 } else {
Chris@0 36 factory( global );
Chris@0 37 }
Chris@0 38
Chris@0 39 // Pass this if window is not defined yet
Chris@0 40 } )( typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
Chris@0 41
Chris@0 42 // Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1
Chris@0 43 // throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode
Chris@0 44 // arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common
Chris@0 45 // enough that all such attempts are guarded in a try block.
Chris@0 46 "use strict";
Chris@0 47
Chris@0 48 var arr = [];
Chris@0 49
Chris@0 50 var document = window.document;
Chris@0 51
Chris@0 52 var getProto = Object.getPrototypeOf;
Chris@0 53
Chris@0 54 var slice = arr.slice;
Chris@0 55
Chris@0 56 var concat = arr.concat;
Chris@0 57
Chris@0 58 var push = arr.push;
Chris@0 59
Chris@0 60 var indexOf = arr.indexOf;
Chris@0 61
Chris@0 62 var class2type = {};
Chris@0 63
Chris@0 64 var toString = class2type.toString;
Chris@0 65
Chris@0 66 var hasOwn = class2type.hasOwnProperty;
Chris@0 67
Chris@0 68 var fnToString = hasOwn.toString;
Chris@0 69
Chris@0 70 var ObjectFunctionString = fnToString.call( Object );
Chris@0 71
Chris@0 72 var support = {};
Chris@0 73
Chris@0 74
Chris@0 75
Chris@0 76 function DOMEval( code, doc ) {
Chris@0 77 doc = doc || document;
Chris@0 78
Chris@0 79 var script = doc.createElement( "script" );
Chris@0 80
Chris@0 81 script.text = code;
Chris@0 82 doc.head.appendChild( script ).parentNode.removeChild( script );
Chris@0 83 }
Chris@0 84 /* global Symbol */
Chris@0 85 // Defining this global in .eslintrc.json would create a danger of using the global
Chris@0 86 // unguarded in another place, it seems safer to define global only for this module
Chris@0 87
Chris@0 88
Chris@0 89
Chris@0 90 var
Chris@0 91 version = "3.2.1",
Chris@0 92
Chris@0 93 // Define a local copy of jQuery
Chris@0 94 jQuery = function( selector, context ) {
Chris@0 95
Chris@0 96 // The jQuery object is actually just the init constructor 'enhanced'
Chris@0 97 // Need init if jQuery is called (just allow error to be thrown if not included)
Chris@0 98 return new jQuery.fn.init( selector, context );
Chris@0 99 },
Chris@0 100
Chris@0 101 // Support: Android <=4.0 only
Chris@0 102 // Make sure we trim BOM and NBSP
Chris@0 103 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
Chris@0 104
Chris@0 105 // Matches dashed string for camelizing
Chris@0 106 rmsPrefix = /^-ms-/,
Chris@0 107 rdashAlpha = /-([a-z])/g,
Chris@0 108
Chris@0 109 // Used by jQuery.camelCase as callback to replace()
Chris@0 110 fcamelCase = function( all, letter ) {
Chris@0 111 return letter.toUpperCase();
Chris@0 112 };
Chris@0 113
Chris@0 114 jQuery.fn = jQuery.prototype = {
Chris@0 115
Chris@0 116 // The current version of jQuery being used
Chris@0 117 jquery: version,
Chris@0 118
Chris@0 119 constructor: jQuery,
Chris@0 120
Chris@0 121 // The default length of a jQuery object is 0
Chris@0 122 length: 0,
Chris@0 123
Chris@0 124 toArray: function() {
Chris@0 125 return slice.call( this );
Chris@0 126 },
Chris@0 127
Chris@0 128 // Get the Nth element in the matched element set OR
Chris@0 129 // Get the whole matched element set as a clean array
Chris@0 130 get: function( num ) {
Chris@0 131
Chris@0 132 // Return all the elements in a clean array
Chris@0 133 if ( num == null ) {
Chris@0 134 return slice.call( this );
Chris@0 135 }
Chris@0 136
Chris@0 137 // Return just the one element from the set
Chris@0 138 return num < 0 ? this[ num + this.length ] : this[ num ];
Chris@0 139 },
Chris@0 140
Chris@0 141 // Take an array of elements and push it onto the stack
Chris@0 142 // (returning the new matched element set)
Chris@0 143 pushStack: function( elems ) {
Chris@0 144
Chris@0 145 // Build a new jQuery matched element set
Chris@0 146 var ret = jQuery.merge( this.constructor(), elems );
Chris@0 147
Chris@0 148 // Add the old object onto the stack (as a reference)
Chris@0 149 ret.prevObject = this;
Chris@0 150
Chris@0 151 // Return the newly-formed element set
Chris@0 152 return ret;
Chris@0 153 },
Chris@0 154
Chris@0 155 // Execute a callback for every element in the matched set.
Chris@0 156 each: function( callback ) {
Chris@0 157 return jQuery.each( this, callback );
Chris@0 158 },
Chris@0 159
Chris@0 160 map: function( callback ) {
Chris@0 161 return this.pushStack( jQuery.map( this, function( elem, i ) {
Chris@0 162 return callback.call( elem, i, elem );
Chris@0 163 } ) );
Chris@0 164 },
Chris@0 165
Chris@0 166 slice: function() {
Chris@0 167 return this.pushStack( slice.apply( this, arguments ) );
Chris@0 168 },
Chris@0 169
Chris@0 170 first: function() {
Chris@0 171 return this.eq( 0 );
Chris@0 172 },
Chris@0 173
Chris@0 174 last: function() {
Chris@0 175 return this.eq( -1 );
Chris@0 176 },
Chris@0 177
Chris@0 178 eq: function( i ) {
Chris@0 179 var len = this.length,
Chris@0 180 j = +i + ( i < 0 ? len : 0 );
Chris@0 181 return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );
Chris@0 182 },
Chris@0 183
Chris@0 184 end: function() {
Chris@0 185 return this.prevObject || this.constructor();
Chris@0 186 },
Chris@0 187
Chris@0 188 // For internal use only.
Chris@0 189 // Behaves like an Array's method, not like a jQuery method.
Chris@0 190 push: push,
Chris@0 191 sort: arr.sort,
Chris@0 192 splice: arr.splice
Chris@0 193 };
Chris@0 194
Chris@0 195 jQuery.extend = jQuery.fn.extend = function() {
Chris@0 196 var options, name, src, copy, copyIsArray, clone,
Chris@0 197 target = arguments[ 0 ] || {},
Chris@0 198 i = 1,
Chris@0 199 length = arguments.length,
Chris@0 200 deep = false;
Chris@0 201
Chris@0 202 // Handle a deep copy situation
Chris@0 203 if ( typeof target === "boolean" ) {
Chris@0 204 deep = target;
Chris@0 205
Chris@0 206 // Skip the boolean and the target
Chris@0 207 target = arguments[ i ] || {};
Chris@0 208 i++;
Chris@0 209 }
Chris@0 210
Chris@0 211 // Handle case when target is a string or something (possible in deep copy)
Chris@0 212 if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
Chris@0 213 target = {};
Chris@0 214 }
Chris@0 215
Chris@0 216 // Extend jQuery itself if only one argument is passed
Chris@0 217 if ( i === length ) {
Chris@0 218 target = this;
Chris@0 219 i--;
Chris@0 220 }
Chris@0 221
Chris@0 222 for ( ; i < length; i++ ) {
Chris@0 223
Chris@0 224 // Only deal with non-null/undefined values
Chris@0 225 if ( ( options = arguments[ i ] ) != null ) {
Chris@0 226
Chris@0 227 // Extend the base object
Chris@0 228 for ( name in options ) {
Chris@0 229 src = target[ name ];
Chris@0 230 copy = options[ name ];
Chris@0 231
Chris@0 232 // Prevent never-ending loop
Chris@0 233 if ( target === copy ) {
Chris@0 234 continue;
Chris@0 235 }
Chris@0 236
Chris@0 237 // Recurse if we're merging plain objects or arrays
Chris@0 238 if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
Chris@0 239 ( copyIsArray = Array.isArray( copy ) ) ) ) {
Chris@0 240
Chris@0 241 if ( copyIsArray ) {
Chris@0 242 copyIsArray = false;
Chris@0 243 clone = src && Array.isArray( src ) ? src : [];
Chris@0 244
Chris@0 245 } else {
Chris@0 246 clone = src && jQuery.isPlainObject( src ) ? src : {};
Chris@0 247 }
Chris@0 248
Chris@0 249 // Never move original objects, clone them
Chris@0 250 target[ name ] = jQuery.extend( deep, clone, copy );
Chris@0 251
Chris@0 252 // Don't bring in undefined values
Chris@0 253 } else if ( copy !== undefined ) {
Chris@0 254 target[ name ] = copy;
Chris@0 255 }
Chris@0 256 }
Chris@0 257 }
Chris@0 258 }
Chris@0 259
Chris@0 260 // Return the modified object
Chris@0 261 return target;
Chris@0 262 };
Chris@0 263
Chris@0 264 jQuery.extend( {
Chris@0 265
Chris@0 266 // Unique for each copy of jQuery on the page
Chris@0 267 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
Chris@0 268
Chris@0 269 // Assume jQuery is ready without the ready module
Chris@0 270 isReady: true,
Chris@0 271
Chris@0 272 error: function( msg ) {
Chris@0 273 throw new Error( msg );
Chris@0 274 },
Chris@0 275
Chris@0 276 noop: function() {},
Chris@0 277
Chris@0 278 isFunction: function( obj ) {
Chris@0 279 return jQuery.type( obj ) === "function";
Chris@0 280 },
Chris@0 281
Chris@0 282 isWindow: function( obj ) {
Chris@0 283 return obj != null && obj === obj.window;
Chris@0 284 },
Chris@0 285
Chris@0 286 isNumeric: function( obj ) {
Chris@0 287
Chris@0 288 // As of jQuery 3.0, isNumeric is limited to
Chris@0 289 // strings and numbers (primitives or objects)
Chris@0 290 // that can be coerced to finite numbers (gh-2662)
Chris@0 291 var type = jQuery.type( obj );
Chris@0 292 return ( type === "number" || type === "string" ) &&
Chris@0 293
Chris@0 294 // parseFloat NaNs numeric-cast false positives ("")
Chris@0 295 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
Chris@0 296 // subtraction forces infinities to NaN
Chris@0 297 !isNaN( obj - parseFloat( obj ) );
Chris@0 298 },
Chris@0 299
Chris@0 300 isPlainObject: function( obj ) {
Chris@0 301 var proto, Ctor;
Chris@0 302
Chris@0 303 // Detect obvious negatives
Chris@0 304 // Use toString instead of jQuery.type to catch host objects
Chris@0 305 if ( !obj || toString.call( obj ) !== "[object Object]" ) {
Chris@0 306 return false;
Chris@0 307 }
Chris@0 308
Chris@0 309 proto = getProto( obj );
Chris@0 310
Chris@0 311 // Objects with no prototype (e.g., `Object.create( null )`) are plain
Chris@0 312 if ( !proto ) {
Chris@0 313 return true;
Chris@0 314 }
Chris@0 315
Chris@0 316 // Objects with prototype are plain iff they were constructed by a global Object function
Chris@0 317 Ctor = hasOwn.call( proto, "constructor" ) && proto.constructor;
Chris@0 318 return typeof Ctor === "function" && fnToString.call( Ctor ) === ObjectFunctionString;
Chris@0 319 },
Chris@0 320
Chris@0 321 isEmptyObject: function( obj ) {
Chris@0 322
Chris@0 323 /* eslint-disable no-unused-vars */
Chris@0 324 // See https://github.com/eslint/eslint/issues/6125
Chris@0 325 var name;
Chris@0 326
Chris@0 327 for ( name in obj ) {
Chris@0 328 return false;
Chris@0 329 }
Chris@0 330 return true;
Chris@0 331 },
Chris@0 332
Chris@0 333 type: function( obj ) {
Chris@0 334 if ( obj == null ) {
Chris@0 335 return obj + "";
Chris@0 336 }
Chris@0 337
Chris@0 338 // Support: Android <=2.3 only (functionish RegExp)
Chris@0 339 return typeof obj === "object" || typeof obj === "function" ?
Chris@0 340 class2type[ toString.call( obj ) ] || "object" :
Chris@0 341 typeof obj;
Chris@0 342 },
Chris@0 343
Chris@0 344 // Evaluates a script in a global context
Chris@0 345 globalEval: function( code ) {
Chris@0 346 DOMEval( code );
Chris@0 347 },
Chris@0 348
Chris@0 349 // Convert dashed to camelCase; used by the css and data modules
Chris@0 350 // Support: IE <=9 - 11, Edge 12 - 13
Chris@0 351 // Microsoft forgot to hump their vendor prefix (#9572)
Chris@0 352 camelCase: function( string ) {
Chris@0 353 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
Chris@0 354 },
Chris@0 355
Chris@0 356 each: function( obj, callback ) {
Chris@0 357 var length, i = 0;
Chris@0 358
Chris@0 359 if ( isArrayLike( obj ) ) {
Chris@0 360 length = obj.length;
Chris@0 361 for ( ; i < length; i++ ) {
Chris@0 362 if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
Chris@0 363 break;
Chris@0 364 }
Chris@0 365 }
Chris@0 366 } else {
Chris@0 367 for ( i in obj ) {
Chris@0 368 if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
Chris@0 369 break;
Chris@0 370 }
Chris@0 371 }
Chris@0 372 }
Chris@0 373
Chris@0 374 return obj;
Chris@0 375 },
Chris@0 376
Chris@0 377 // Support: Android <=4.0 only
Chris@0 378 trim: function( text ) {
Chris@0 379 return text == null ?
Chris@0 380 "" :
Chris@0 381 ( text + "" ).replace( rtrim, "" );
Chris@0 382 },
Chris@0 383
Chris@0 384 // results is for internal usage only
Chris@0 385 makeArray: function( arr, results ) {
Chris@0 386 var ret = results || [];
Chris@0 387
Chris@0 388 if ( arr != null ) {
Chris@0 389 if ( isArrayLike( Object( arr ) ) ) {
Chris@0 390 jQuery.merge( ret,
Chris@0 391 typeof arr === "string" ?
Chris@0 392 [ arr ] : arr
Chris@0 393 );
Chris@0 394 } else {
Chris@0 395 push.call( ret, arr );
Chris@0 396 }
Chris@0 397 }
Chris@0 398
Chris@0 399 return ret;
Chris@0 400 },
Chris@0 401
Chris@0 402 inArray: function( elem, arr, i ) {
Chris@0 403 return arr == null ? -1 : indexOf.call( arr, elem, i );
Chris@0 404 },
Chris@0 405
Chris@0 406 // Support: Android <=4.0 only, PhantomJS 1 only
Chris@0 407 // push.apply(_, arraylike) throws on ancient WebKit
Chris@0 408 merge: function( first, second ) {
Chris@0 409 var len = +second.length,
Chris@0 410 j = 0,
Chris@0 411 i = first.length;
Chris@0 412
Chris@0 413 for ( ; j < len; j++ ) {
Chris@0 414 first[ i++ ] = second[ j ];
Chris@0 415 }
Chris@0 416
Chris@0 417 first.length = i;
Chris@0 418
Chris@0 419 return first;
Chris@0 420 },
Chris@0 421
Chris@0 422 grep: function( elems, callback, invert ) {
Chris@0 423 var callbackInverse,
Chris@0 424 matches = [],
Chris@0 425 i = 0,
Chris@0 426 length = elems.length,
Chris@0 427 callbackExpect = !invert;
Chris@0 428
Chris@0 429 // Go through the array, only saving the items
Chris@0 430 // that pass the validator function
Chris@0 431 for ( ; i < length; i++ ) {
Chris@0 432 callbackInverse = !callback( elems[ i ], i );
Chris@0 433 if ( callbackInverse !== callbackExpect ) {
Chris@0 434 matches.push( elems[ i ] );
Chris@0 435 }
Chris@0 436 }
Chris@0 437
Chris@0 438 return matches;
Chris@0 439 },
Chris@0 440
Chris@0 441 // arg is for internal usage only
Chris@0 442 map: function( elems, callback, arg ) {
Chris@0 443 var length, value,
Chris@0 444 i = 0,
Chris@0 445 ret = [];
Chris@0 446
Chris@0 447 // Go through the array, translating each of the items to their new values
Chris@0 448 if ( isArrayLike( elems ) ) {
Chris@0 449 length = elems.length;
Chris@0 450 for ( ; i < length; i++ ) {
Chris@0 451 value = callback( elems[ i ], i, arg );
Chris@0 452
Chris@0 453 if ( value != null ) {
Chris@0 454 ret.push( value );
Chris@0 455 }
Chris@0 456 }
Chris@0 457
Chris@0 458 // Go through every key on the object,
Chris@0 459 } else {
Chris@0 460 for ( i in elems ) {
Chris@0 461 value = callback( elems[ i ], i, arg );
Chris@0 462
Chris@0 463 if ( value != null ) {
Chris@0 464 ret.push( value );
Chris@0 465 }
Chris@0 466 }
Chris@0 467 }
Chris@0 468
Chris@0 469 // Flatten any nested arrays
Chris@0 470 return concat.apply( [], ret );
Chris@0 471 },
Chris@0 472
Chris@0 473 // A global GUID counter for objects
Chris@0 474 guid: 1,
Chris@0 475
Chris@0 476 // Bind a function to a context, optionally partially applying any
Chris@0 477 // arguments.
Chris@0 478 proxy: function( fn, context ) {
Chris@0 479 var tmp, args, proxy;
Chris@0 480
Chris@0 481 if ( typeof context === "string" ) {
Chris@0 482 tmp = fn[ context ];
Chris@0 483 context = fn;
Chris@0 484 fn = tmp;
Chris@0 485 }
Chris@0 486
Chris@0 487 // Quick check to determine if target is callable, in the spec
Chris@0 488 // this throws a TypeError, but we will just return undefined.
Chris@0 489 if ( !jQuery.isFunction( fn ) ) {
Chris@0 490 return undefined;
Chris@0 491 }
Chris@0 492
Chris@0 493 // Simulated bind
Chris@0 494 args = slice.call( arguments, 2 );
Chris@0 495 proxy = function() {
Chris@0 496 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
Chris@0 497 };
Chris@0 498
Chris@0 499 // Set the guid of unique handler to the same of original handler, so it can be removed
Chris@0 500 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
Chris@0 501
Chris@0 502 return proxy;
Chris@0 503 },
Chris@0 504
Chris@0 505 now: Date.now,
Chris@0 506
Chris@0 507 // jQuery.support is not used in Core but other projects attach their
Chris@0 508 // properties to it so it needs to exist.
Chris@0 509 support: support
Chris@0 510 } );
Chris@0 511
Chris@0 512 if ( typeof Symbol === "function" ) {
Chris@0 513 jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
Chris@0 514 }
Chris@0 515
Chris@0 516 // Populate the class2type map
Chris@0 517 jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
Chris@0 518 function( i, name ) {
Chris@0 519 class2type[ "[object " + name + "]" ] = name.toLowerCase();
Chris@0 520 } );
Chris@0 521
Chris@0 522 function isArrayLike( obj ) {
Chris@0 523
Chris@0 524 // Support: real iOS 8.2 only (not reproducible in simulator)
Chris@0 525 // `in` check used to prevent JIT error (gh-2145)
Chris@0 526 // hasOwn isn't used here due to false negatives
Chris@0 527 // regarding Nodelist length in IE
Chris@0 528 var length = !!obj && "length" in obj && obj.length,
Chris@0 529 type = jQuery.type( obj );
Chris@0 530
Chris@0 531 if ( type === "function" || jQuery.isWindow( obj ) ) {
Chris@0 532 return false;
Chris@0 533 }
Chris@0 534
Chris@0 535 return type === "array" || length === 0 ||
Chris@0 536 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
Chris@0 537 }
Chris@0 538 var Sizzle =
Chris@0 539 /*!
Chris@0 540 * Sizzle CSS Selector Engine v2.3.3
Chris@0 541 * https://sizzlejs.com/
Chris@0 542 *
Chris@0 543 * Copyright jQuery Foundation and other contributors
Chris@0 544 * Released under the MIT license
Chris@0 545 * http://jquery.org/license
Chris@0 546 *
Chris@0 547 * Date: 2016-08-08
Chris@0 548 */
Chris@0 549 (function( window ) {
Chris@0 550
Chris@0 551 var i,
Chris@0 552 support,
Chris@0 553 Expr,
Chris@0 554 getText,
Chris@0 555 isXML,
Chris@0 556 tokenize,
Chris@0 557 compile,
Chris@0 558 select,
Chris@0 559 outermostContext,
Chris@0 560 sortInput,
Chris@0 561 hasDuplicate,
Chris@0 562
Chris@0 563 // Local document vars
Chris@0 564 setDocument,
Chris@0 565 document,
Chris@0 566 docElem,
Chris@0 567 documentIsHTML,
Chris@0 568 rbuggyQSA,
Chris@0 569 rbuggyMatches,
Chris@0 570 matches,
Chris@0 571 contains,
Chris@0 572
Chris@0 573 // Instance-specific data
Chris@0 574 expando = "sizzle" + 1 * new Date(),
Chris@0 575 preferredDoc = window.document,
Chris@0 576 dirruns = 0,
Chris@0 577 done = 0,
Chris@0 578 classCache = createCache(),
Chris@0 579 tokenCache = createCache(),
Chris@0 580 compilerCache = createCache(),
Chris@0 581 sortOrder = function( a, b ) {
Chris@0 582 if ( a === b ) {
Chris@0 583 hasDuplicate = true;
Chris@0 584 }
Chris@0 585 return 0;
Chris@0 586 },
Chris@0 587
Chris@0 588 // Instance methods
Chris@0 589 hasOwn = ({}).hasOwnProperty,
Chris@0 590 arr = [],
Chris@0 591 pop = arr.pop,
Chris@0 592 push_native = arr.push,
Chris@0 593 push = arr.push,
Chris@0 594 slice = arr.slice,
Chris@0 595 // Use a stripped-down indexOf as it's faster than native
Chris@0 596 // https://jsperf.com/thor-indexof-vs-for/5
Chris@0 597 indexOf = function( list, elem ) {
Chris@0 598 var i = 0,
Chris@0 599 len = list.length;
Chris@0 600 for ( ; i < len; i++ ) {
Chris@0 601 if ( list[i] === elem ) {
Chris@0 602 return i;
Chris@0 603 }
Chris@0 604 }
Chris@0 605 return -1;
Chris@0 606 },
Chris@0 607
Chris@0 608 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
Chris@0 609
Chris@0 610 // Regular expressions
Chris@0 611
Chris@0 612 // http://www.w3.org/TR/css3-selectors/#whitespace
Chris@0 613 whitespace = "[\\x20\\t\\r\\n\\f]",
Chris@0 614
Chris@0 615 // http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
Chris@0 616 identifier = "(?:\\\\.|[\\w-]|[^\0-\\xa0])+",
Chris@0 617
Chris@0 618 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
Chris@0 619 attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace +
Chris@0 620 // Operator (capture 2)
Chris@0 621 "*([*^$|!~]?=)" + whitespace +
Chris@0 622 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
Chris@0 623 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
Chris@0 624 "*\\]",
Chris@0 625
Chris@0 626 pseudos = ":(" + identifier + ")(?:\\((" +
Chris@0 627 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
Chris@0 628 // 1. quoted (capture 3; capture 4 or capture 5)
Chris@0 629 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
Chris@0 630 // 2. simple (capture 6)
Chris@0 631 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
Chris@0 632 // 3. anything else (capture 2)
Chris@0 633 ".*" +
Chris@0 634 ")\\)|)",
Chris@0 635
Chris@0 636 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
Chris@0 637 rwhitespace = new RegExp( whitespace + "+", "g" ),
Chris@0 638 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
Chris@0 639
Chris@0 640 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
Chris@0 641 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
Chris@0 642
Chris@0 643 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
Chris@0 644
Chris@0 645 rpseudo = new RegExp( pseudos ),
Chris@0 646 ridentifier = new RegExp( "^" + identifier + "$" ),
Chris@0 647
Chris@0 648 matchExpr = {
Chris@0 649 "ID": new RegExp( "^#(" + identifier + ")" ),
Chris@0 650 "CLASS": new RegExp( "^\\.(" + identifier + ")" ),
Chris@0 651 "TAG": new RegExp( "^(" + identifier + "|[*])" ),
Chris@0 652 "ATTR": new RegExp( "^" + attributes ),
Chris@0 653 "PSEUDO": new RegExp( "^" + pseudos ),
Chris@0 654 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
Chris@0 655 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
Chris@0 656 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
Chris@0 657 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
Chris@0 658 // For use in libraries implementing .is()
Chris@0 659 // We use this for POS matching in `select`
Chris@0 660 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
Chris@0 661 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
Chris@0 662 },
Chris@0 663
Chris@0 664 rinputs = /^(?:input|select|textarea|button)$/i,
Chris@0 665 rheader = /^h\d$/i,
Chris@0 666
Chris@0 667 rnative = /^[^{]+\{\s*\[native \w/,
Chris@0 668
Chris@0 669 // Easily-parseable/retrievable ID or TAG or CLASS selectors
Chris@0 670 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
Chris@0 671
Chris@0 672 rsibling = /[+~]/,
Chris@0 673
Chris@0 674 // CSS escapes
Chris@0 675 // http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
Chris@0 676 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
Chris@0 677 funescape = function( _, escaped, escapedWhitespace ) {
Chris@0 678 var high = "0x" + escaped - 0x10000;
Chris@0 679 // NaN means non-codepoint
Chris@0 680 // Support: Firefox<24
Chris@0 681 // Workaround erroneous numeric interpretation of +"0x"
Chris@0 682 return high !== high || escapedWhitespace ?
Chris@0 683 escaped :
Chris@0 684 high < 0 ?
Chris@0 685 // BMP codepoint
Chris@0 686 String.fromCharCode( high + 0x10000 ) :
Chris@0 687 // Supplemental Plane codepoint (surrogate pair)
Chris@0 688 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
Chris@0 689 },
Chris@0 690
Chris@0 691 // CSS string/identifier serialization
Chris@0 692 // https://drafts.csswg.org/cssom/#common-serializing-idioms
Chris@0 693 rcssescape = /([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,
Chris@0 694 fcssescape = function( ch, asCodePoint ) {
Chris@0 695 if ( asCodePoint ) {
Chris@0 696
Chris@0 697 // U+0000 NULL becomes U+FFFD REPLACEMENT CHARACTER
Chris@0 698 if ( ch === "\0" ) {
Chris@0 699 return "\uFFFD";
Chris@0 700 }
Chris@0 701
Chris@0 702 // Control characters and (dependent upon position) numbers get escaped as code points
Chris@0 703 return ch.slice( 0, -1 ) + "\\" + ch.charCodeAt( ch.length - 1 ).toString( 16 ) + " ";
Chris@0 704 }
Chris@0 705
Chris@0 706 // Other potentially-special ASCII characters get backslash-escaped
Chris@0 707 return "\\" + ch;
Chris@0 708 },
Chris@0 709
Chris@0 710 // Used for iframes
Chris@0 711 // See setDocument()
Chris@0 712 // Removing the function wrapper causes a "Permission Denied"
Chris@0 713 // error in IE
Chris@0 714 unloadHandler = function() {
Chris@0 715 setDocument();
Chris@0 716 },
Chris@0 717
Chris@0 718 disabledAncestor = addCombinator(
Chris@0 719 function( elem ) {
Chris@0 720 return elem.disabled === true && ("form" in elem || "label" in elem);
Chris@0 721 },
Chris@0 722 { dir: "parentNode", next: "legend" }
Chris@0 723 );
Chris@0 724
Chris@0 725 // Optimize for push.apply( _, NodeList )
Chris@0 726 try {
Chris@0 727 push.apply(
Chris@0 728 (arr = slice.call( preferredDoc.childNodes )),
Chris@0 729 preferredDoc.childNodes
Chris@0 730 );
Chris@0 731 // Support: Android<4.0
Chris@0 732 // Detect silently failing push.apply
Chris@0 733 arr[ preferredDoc.childNodes.length ].nodeType;
Chris@0 734 } catch ( e ) {
Chris@0 735 push = { apply: arr.length ?
Chris@0 736
Chris@0 737 // Leverage slice if possible
Chris@0 738 function( target, els ) {
Chris@0 739 push_native.apply( target, slice.call(els) );
Chris@0 740 } :
Chris@0 741
Chris@0 742 // Support: IE<9
Chris@0 743 // Otherwise append directly
Chris@0 744 function( target, els ) {
Chris@0 745 var j = target.length,
Chris@0 746 i = 0;
Chris@0 747 // Can't trust NodeList.length
Chris@0 748 while ( (target[j++] = els[i++]) ) {}
Chris@0 749 target.length = j - 1;
Chris@0 750 }
Chris@0 751 };
Chris@0 752 }
Chris@0 753
Chris@0 754 function Sizzle( selector, context, results, seed ) {
Chris@0 755 var m, i, elem, nid, match, groups, newSelector,
Chris@0 756 newContext = context && context.ownerDocument,
Chris@0 757
Chris@0 758 // nodeType defaults to 9, since context defaults to document
Chris@0 759 nodeType = context ? context.nodeType : 9;
Chris@0 760
Chris@0 761 results = results || [];
Chris@0 762
Chris@0 763 // Return early from calls with invalid selector or context
Chris@0 764 if ( typeof selector !== "string" || !selector ||
Chris@0 765 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
Chris@0 766
Chris@0 767 return results;
Chris@0 768 }
Chris@0 769
Chris@0 770 // Try to shortcut find operations (as opposed to filters) in HTML documents
Chris@0 771 if ( !seed ) {
Chris@0 772
Chris@0 773 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
Chris@0 774 setDocument( context );
Chris@0 775 }
Chris@0 776 context = context || document;
Chris@0 777
Chris@0 778 if ( documentIsHTML ) {
Chris@0 779
Chris@0 780 // If the selector is sufficiently simple, try using a "get*By*" DOM method
Chris@0 781 // (excepting DocumentFragment context, where the methods don't exist)
Chris@0 782 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
Chris@0 783
Chris@0 784 // ID selector
Chris@0 785 if ( (m = match[1]) ) {
Chris@0 786
Chris@0 787 // Document context
Chris@0 788 if ( nodeType === 9 ) {
Chris@0 789 if ( (elem = context.getElementById( m )) ) {
Chris@0 790
Chris@0 791 // Support: IE, Opera, Webkit
Chris@0 792 // TODO: identify versions
Chris@0 793 // getElementById can match elements by name instead of ID
Chris@0 794 if ( elem.id === m ) {
Chris@0 795 results.push( elem );
Chris@0 796 return results;
Chris@0 797 }
Chris@0 798 } else {
Chris@0 799 return results;
Chris@0 800 }
Chris@0 801
Chris@0 802 // Element context
Chris@0 803 } else {
Chris@0 804
Chris@0 805 // Support: IE, Opera, Webkit
Chris@0 806 // TODO: identify versions
Chris@0 807 // getElementById can match elements by name instead of ID
Chris@0 808 if ( newContext && (elem = newContext.getElementById( m )) &&
Chris@0 809 contains( context, elem ) &&
Chris@0 810 elem.id === m ) {
Chris@0 811
Chris@0 812 results.push( elem );
Chris@0 813 return results;
Chris@0 814 }
Chris@0 815 }
Chris@0 816
Chris@0 817 // Type selector
Chris@0 818 } else if ( match[2] ) {
Chris@0 819 push.apply( results, context.getElementsByTagName( selector ) );
Chris@0 820 return results;
Chris@0 821
Chris@0 822 // Class selector
Chris@0 823 } else if ( (m = match[3]) && support.getElementsByClassName &&
Chris@0 824 context.getElementsByClassName ) {
Chris@0 825
Chris@0 826 push.apply( results, context.getElementsByClassName( m ) );
Chris@0 827 return results;
Chris@0 828 }
Chris@0 829 }
Chris@0 830
Chris@0 831 // Take advantage of querySelectorAll
Chris@0 832 if ( support.qsa &&
Chris@0 833 !compilerCache[ selector + " " ] &&
Chris@0 834 (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
Chris@0 835
Chris@0 836 if ( nodeType !== 1 ) {
Chris@0 837 newContext = context;
Chris@0 838 newSelector = selector;
Chris@0 839
Chris@0 840 // qSA looks outside Element context, which is not what we want
Chris@0 841 // Thanks to Andrew Dupont for this workaround technique
Chris@0 842 // Support: IE <=8
Chris@0 843 // Exclude object elements
Chris@0 844 } else if ( context.nodeName.toLowerCase() !== "object" ) {
Chris@0 845
Chris@0 846 // Capture the context ID, setting it first if necessary
Chris@0 847 if ( (nid = context.getAttribute( "id" )) ) {
Chris@0 848 nid = nid.replace( rcssescape, fcssescape );
Chris@0 849 } else {
Chris@0 850 context.setAttribute( "id", (nid = expando) );
Chris@0 851 }
Chris@0 852
Chris@0 853 // Prefix every selector in the list
Chris@0 854 groups = tokenize( selector );
Chris@0 855 i = groups.length;
Chris@0 856 while ( i-- ) {
Chris@0 857 groups[i] = "#" + nid + " " + toSelector( groups[i] );
Chris@0 858 }
Chris@0 859 newSelector = groups.join( "," );
Chris@0 860
Chris@0 861 // Expand context for sibling selectors
Chris@0 862 newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||
Chris@0 863 context;
Chris@0 864 }
Chris@0 865
Chris@0 866 if ( newSelector ) {
Chris@0 867 try {
Chris@0 868 push.apply( results,
Chris@0 869 newContext.querySelectorAll( newSelector )
Chris@0 870 );
Chris@0 871 return results;
Chris@0 872 } catch ( qsaError ) {
Chris@0 873 } finally {
Chris@0 874 if ( nid === expando ) {
Chris@0 875 context.removeAttribute( "id" );
Chris@0 876 }
Chris@0 877 }
Chris@0 878 }
Chris@0 879 }
Chris@0 880 }
Chris@0 881 }
Chris@0 882
Chris@0 883 // All others
Chris@0 884 return select( selector.replace( rtrim, "$1" ), context, results, seed );
Chris@0 885 }
Chris@0 886
Chris@0 887 /**
Chris@0 888 * Create key-value caches of limited size
Chris@0 889 * @returns {function(string, object)} Returns the Object data after storing it on itself with
Chris@0 890 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
Chris@0 891 * deleting the oldest entry
Chris@0 892 */
Chris@0 893 function createCache() {
Chris@0 894 var keys = [];
Chris@0 895
Chris@0 896 function cache( key, value ) {
Chris@0 897 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
Chris@0 898 if ( keys.push( key + " " ) > Expr.cacheLength ) {
Chris@0 899 // Only keep the most recent entries
Chris@0 900 delete cache[ keys.shift() ];
Chris@0 901 }
Chris@0 902 return (cache[ key + " " ] = value);
Chris@0 903 }
Chris@0 904 return cache;
Chris@0 905 }
Chris@0 906
Chris@0 907 /**
Chris@0 908 * Mark a function for special use by Sizzle
Chris@0 909 * @param {Function} fn The function to mark
Chris@0 910 */
Chris@0 911 function markFunction( fn ) {
Chris@0 912 fn[ expando ] = true;
Chris@0 913 return fn;
Chris@0 914 }
Chris@0 915
Chris@0 916 /**
Chris@0 917 * Support testing using an element
Chris@0 918 * @param {Function} fn Passed the created element and returns a boolean result
Chris@0 919 */
Chris@0 920 function assert( fn ) {
Chris@0 921 var el = document.createElement("fieldset");
Chris@0 922
Chris@0 923 try {
Chris@0 924 return !!fn( el );
Chris@0 925 } catch (e) {
Chris@0 926 return false;
Chris@0 927 } finally {
Chris@0 928 // Remove from its parent by default
Chris@0 929 if ( el.parentNode ) {
Chris@0 930 el.parentNode.removeChild( el );
Chris@0 931 }
Chris@0 932 // release memory in IE
Chris@0 933 el = null;
Chris@0 934 }
Chris@0 935 }
Chris@0 936
Chris@0 937 /**
Chris@0 938 * Adds the same handler for all of the specified attrs
Chris@0 939 * @param {String} attrs Pipe-separated list of attributes
Chris@0 940 * @param {Function} handler The method that will be applied
Chris@0 941 */
Chris@0 942 function addHandle( attrs, handler ) {
Chris@0 943 var arr = attrs.split("|"),
Chris@0 944 i = arr.length;
Chris@0 945
Chris@0 946 while ( i-- ) {
Chris@0 947 Expr.attrHandle[ arr[i] ] = handler;
Chris@0 948 }
Chris@0 949 }
Chris@0 950
Chris@0 951 /**
Chris@0 952 * Checks document order of two siblings
Chris@0 953 * @param {Element} a
Chris@0 954 * @param {Element} b
Chris@0 955 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
Chris@0 956 */
Chris@0 957 function siblingCheck( a, b ) {
Chris@0 958 var cur = b && a,
Chris@0 959 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
Chris@0 960 a.sourceIndex - b.sourceIndex;
Chris@0 961
Chris@0 962 // Use IE sourceIndex if available on both nodes
Chris@0 963 if ( diff ) {
Chris@0 964 return diff;
Chris@0 965 }
Chris@0 966
Chris@0 967 // Check if b follows a
Chris@0 968 if ( cur ) {
Chris@0 969 while ( (cur = cur.nextSibling) ) {
Chris@0 970 if ( cur === b ) {
Chris@0 971 return -1;
Chris@0 972 }
Chris@0 973 }
Chris@0 974 }
Chris@0 975
Chris@0 976 return a ? 1 : -1;
Chris@0 977 }
Chris@0 978
Chris@0 979 /**
Chris@0 980 * Returns a function to use in pseudos for input types
Chris@0 981 * @param {String} type
Chris@0 982 */
Chris@0 983 function createInputPseudo( type ) {
Chris@0 984 return function( elem ) {
Chris@0 985 var name = elem.nodeName.toLowerCase();
Chris@0 986 return name === "input" && elem.type === type;
Chris@0 987 };
Chris@0 988 }
Chris@0 989
Chris@0 990 /**
Chris@0 991 * Returns a function to use in pseudos for buttons
Chris@0 992 * @param {String} type
Chris@0 993 */
Chris@0 994 function createButtonPseudo( type ) {
Chris@0 995 return function( elem ) {
Chris@0 996 var name = elem.nodeName.toLowerCase();
Chris@0 997 return (name === "input" || name === "button") && elem.type === type;
Chris@0 998 };
Chris@0 999 }
Chris@0 1000
Chris@0 1001 /**
Chris@0 1002 * Returns a function to use in pseudos for :enabled/:disabled
Chris@0 1003 * @param {Boolean} disabled true for :disabled; false for :enabled
Chris@0 1004 */
Chris@0 1005 function createDisabledPseudo( disabled ) {
Chris@0 1006
Chris@0 1007 // Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable
Chris@0 1008 return function( elem ) {
Chris@0 1009
Chris@0 1010 // Only certain elements can match :enabled or :disabled
Chris@0 1011 // https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled
Chris@0 1012 // https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled
Chris@0 1013 if ( "form" in elem ) {
Chris@0 1014
Chris@0 1015 // Check for inherited disabledness on relevant non-disabled elements:
Chris@0 1016 // * listed form-associated elements in a disabled fieldset
Chris@0 1017 // https://html.spec.whatwg.org/multipage/forms.html#category-listed
Chris@0 1018 // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled
Chris@0 1019 // * option elements in a disabled optgroup
Chris@0 1020 // https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled
Chris@0 1021 // All such elements have a "form" property.
Chris@0 1022 if ( elem.parentNode && elem.disabled === false ) {
Chris@0 1023
Chris@0 1024 // Option elements defer to a parent optgroup if present
Chris@0 1025 if ( "label" in elem ) {
Chris@0 1026 if ( "label" in elem.parentNode ) {
Chris@0 1027 return elem.parentNode.disabled === disabled;
Chris@0 1028 } else {
Chris@0 1029 return elem.disabled === disabled;
Chris@0 1030 }
Chris@0 1031 }
Chris@0 1032
Chris@0 1033 // Support: IE 6 - 11
Chris@0 1034 // Use the isDisabled shortcut property to check for disabled fieldset ancestors
Chris@0 1035 return elem.isDisabled === disabled ||
Chris@0 1036
Chris@0 1037 // Where there is no isDisabled, check manually
Chris@0 1038 /* jshint -W018 */
Chris@0 1039 elem.isDisabled !== !disabled &&
Chris@0 1040 disabledAncestor( elem ) === disabled;
Chris@0 1041 }
Chris@0 1042
Chris@0 1043 return elem.disabled === disabled;
Chris@0 1044
Chris@0 1045 // Try to winnow out elements that can't be disabled before trusting the disabled property.
Chris@0 1046 // Some victims get caught in our net (label, legend, menu, track), but it shouldn't
Chris@0 1047 // even exist on them, let alone have a boolean value.
Chris@0 1048 } else if ( "label" in elem ) {
Chris@0 1049 return elem.disabled === disabled;
Chris@0 1050 }
Chris@0 1051
Chris@0 1052 // Remaining elements are neither :enabled nor :disabled
Chris@0 1053 return false;
Chris@0 1054 };
Chris@0 1055 }
Chris@0 1056
Chris@0 1057 /**
Chris@0 1058 * Returns a function to use in pseudos for positionals
Chris@0 1059 * @param {Function} fn
Chris@0 1060 */
Chris@0 1061 function createPositionalPseudo( fn ) {
Chris@0 1062 return markFunction(function( argument ) {
Chris@0 1063 argument = +argument;
Chris@0 1064 return markFunction(function( seed, matches ) {
Chris@0 1065 var j,
Chris@0 1066 matchIndexes = fn( [], seed.length, argument ),
Chris@0 1067 i = matchIndexes.length;
Chris@0 1068
Chris@0 1069 // Match elements found at the specified indexes
Chris@0 1070 while ( i-- ) {
Chris@0 1071 if ( seed[ (j = matchIndexes[i]) ] ) {
Chris@0 1072 seed[j] = !(matches[j] = seed[j]);
Chris@0 1073 }
Chris@0 1074 }
Chris@0 1075 });
Chris@0 1076 });
Chris@0 1077 }
Chris@0 1078
Chris@0 1079 /**
Chris@0 1080 * Checks a node for validity as a Sizzle context
Chris@0 1081 * @param {Element|Object=} context
Chris@0 1082 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
Chris@0 1083 */
Chris@0 1084 function testContext( context ) {
Chris@0 1085 return context && typeof context.getElementsByTagName !== "undefined" && context;
Chris@0 1086 }
Chris@0 1087
Chris@0 1088 // Expose support vars for convenience
Chris@0 1089 support = Sizzle.support = {};
Chris@0 1090
Chris@0 1091 /**
Chris@0 1092 * Detects XML nodes
Chris@0 1093 * @param {Element|Object} elem An element or a document
Chris@0 1094 * @returns {Boolean} True iff elem is a non-HTML XML node
Chris@0 1095 */
Chris@0 1096 isXML = Sizzle.isXML = function( elem ) {
Chris@0 1097 // documentElement is verified for cases where it doesn't yet exist
Chris@0 1098 // (such as loading iframes in IE - #4833)
Chris@0 1099 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
Chris@0 1100 return documentElement ? documentElement.nodeName !== "HTML" : false;
Chris@0 1101 };
Chris@0 1102
Chris@0 1103 /**
Chris@0 1104 * Sets document-related variables once based on the current document
Chris@0 1105 * @param {Element|Object} [doc] An element or document object to use to set the document
Chris@0 1106 * @returns {Object} Returns the current document
Chris@0 1107 */
Chris@0 1108 setDocument = Sizzle.setDocument = function( node ) {
Chris@0 1109 var hasCompare, subWindow,
Chris@0 1110 doc = node ? node.ownerDocument || node : preferredDoc;
Chris@0 1111
Chris@0 1112 // Return early if doc is invalid or already selected
Chris@0 1113 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
Chris@0 1114 return document;
Chris@0 1115 }
Chris@0 1116
Chris@0 1117 // Update global variables
Chris@0 1118 document = doc;
Chris@0 1119 docElem = document.documentElement;
Chris@0 1120 documentIsHTML = !isXML( document );
Chris@0 1121
Chris@0 1122 // Support: IE 9-11, Edge
Chris@0 1123 // Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936)
Chris@0 1124 if ( preferredDoc !== document &&
Chris@0 1125 (subWindow = document.defaultView) && subWindow.top !== subWindow ) {
Chris@0 1126
Chris@0 1127 // Support: IE 11, Edge
Chris@0 1128 if ( subWindow.addEventListener ) {
Chris@0 1129 subWindow.addEventListener( "unload", unloadHandler, false );
Chris@0 1130
Chris@0 1131 // Support: IE 9 - 10 only
Chris@0 1132 } else if ( subWindow.attachEvent ) {
Chris@0 1133 subWindow.attachEvent( "onunload", unloadHandler );
Chris@0 1134 }
Chris@0 1135 }
Chris@0 1136
Chris@0 1137 /* Attributes
Chris@0 1138 ---------------------------------------------------------------------- */
Chris@0 1139
Chris@0 1140 // Support: IE<8
Chris@0 1141 // Verify that getAttribute really returns attributes and not properties
Chris@0 1142 // (excepting IE8 booleans)
Chris@0 1143 support.attributes = assert(function( el ) {
Chris@0 1144 el.className = "i";
Chris@0 1145 return !el.getAttribute("className");
Chris@0 1146 });
Chris@0 1147
Chris@0 1148 /* getElement(s)By*
Chris@0 1149 ---------------------------------------------------------------------- */
Chris@0 1150
Chris@0 1151 // Check if getElementsByTagName("*") returns only elements
Chris@0 1152 support.getElementsByTagName = assert(function( el ) {
Chris@0 1153 el.appendChild( document.createComment("") );
Chris@0 1154 return !el.getElementsByTagName("*").length;
Chris@0 1155 });
Chris@0 1156
Chris@0 1157 // Support: IE<9
Chris@0 1158 support.getElementsByClassName = rnative.test( document.getElementsByClassName );
Chris@0 1159
Chris@0 1160 // Support: IE<10
Chris@0 1161 // Check if getElementById returns elements by name
Chris@0 1162 // The broken getElementById methods don't pick up programmatically-set names,
Chris@0 1163 // so use a roundabout getElementsByName test
Chris@0 1164 support.getById = assert(function( el ) {
Chris@0 1165 docElem.appendChild( el ).id = expando;
Chris@0 1166 return !document.getElementsByName || !document.getElementsByName( expando ).length;
Chris@0 1167 });
Chris@0 1168
Chris@0 1169 // ID filter and find
Chris@0 1170 if ( support.getById ) {
Chris@0 1171 Expr.filter["ID"] = function( id ) {
Chris@0 1172 var attrId = id.replace( runescape, funescape );
Chris@0 1173 return function( elem ) {
Chris@0 1174 return elem.getAttribute("id") === attrId;
Chris@0 1175 };
Chris@0 1176 };
Chris@0 1177 Expr.find["ID"] = function( id, context ) {
Chris@0 1178 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
Chris@0 1179 var elem = context.getElementById( id );
Chris@0 1180 return elem ? [ elem ] : [];
Chris@0 1181 }
Chris@0 1182 };
Chris@0 1183 } else {
Chris@0 1184 Expr.filter["ID"] = function( id ) {
Chris@0 1185 var attrId = id.replace( runescape, funescape );
Chris@0 1186 return function( elem ) {
Chris@0 1187 var node = typeof elem.getAttributeNode !== "undefined" &&
Chris@0 1188 elem.getAttributeNode("id");
Chris@0 1189 return node && node.value === attrId;
Chris@0 1190 };
Chris@0 1191 };
Chris@0 1192
Chris@0 1193 // Support: IE 6 - 7 only
Chris@0 1194 // getElementById is not reliable as a find shortcut
Chris@0 1195 Expr.find["ID"] = function( id, context ) {
Chris@0 1196 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
Chris@0 1197 var node, i, elems,
Chris@0 1198 elem = context.getElementById( id );
Chris@0 1199
Chris@0 1200 if ( elem ) {
Chris@0 1201
Chris@0 1202 // Verify the id attribute
Chris@0 1203 node = elem.getAttributeNode("id");
Chris@0 1204 if ( node && node.value === id ) {
Chris@0 1205 return [ elem ];
Chris@0 1206 }
Chris@0 1207
Chris@0 1208 // Fall back on getElementsByName
Chris@0 1209 elems = context.getElementsByName( id );
Chris@0 1210 i = 0;
Chris@0 1211 while ( (elem = elems[i++]) ) {
Chris@0 1212 node = elem.getAttributeNode("id");
Chris@0 1213 if ( node && node.value === id ) {
Chris@0 1214 return [ elem ];
Chris@0 1215 }
Chris@0 1216 }
Chris@0 1217 }
Chris@0 1218
Chris@0 1219 return [];
Chris@0 1220 }
Chris@0 1221 };
Chris@0 1222 }
Chris@0 1223
Chris@0 1224 // Tag
Chris@0 1225 Expr.find["TAG"] = support.getElementsByTagName ?
Chris@0 1226 function( tag, context ) {
Chris@0 1227 if ( typeof context.getElementsByTagName !== "undefined" ) {
Chris@0 1228 return context.getElementsByTagName( tag );
Chris@0 1229
Chris@0 1230 // DocumentFragment nodes don't have gEBTN
Chris@0 1231 } else if ( support.qsa ) {
Chris@0 1232 return context.querySelectorAll( tag );
Chris@0 1233 }
Chris@0 1234 } :
Chris@0 1235
Chris@0 1236 function( tag, context ) {
Chris@0 1237 var elem,
Chris@0 1238 tmp = [],
Chris@0 1239 i = 0,
Chris@0 1240 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
Chris@0 1241 results = context.getElementsByTagName( tag );
Chris@0 1242
Chris@0 1243 // Filter out possible comments
Chris@0 1244 if ( tag === "*" ) {
Chris@0 1245 while ( (elem = results[i++]) ) {
Chris@0 1246 if ( elem.nodeType === 1 ) {
Chris@0 1247 tmp.push( elem );
Chris@0 1248 }
Chris@0 1249 }
Chris@0 1250
Chris@0 1251 return tmp;
Chris@0 1252 }
Chris@0 1253 return results;
Chris@0 1254 };
Chris@0 1255
Chris@0 1256 // Class
Chris@0 1257 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
Chris@0 1258 if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) {
Chris@0 1259 return context.getElementsByClassName( className );
Chris@0 1260 }
Chris@0 1261 };
Chris@0 1262
Chris@0 1263 /* QSA/matchesSelector
Chris@0 1264 ---------------------------------------------------------------------- */
Chris@0 1265
Chris@0 1266 // QSA and matchesSelector support
Chris@0 1267
Chris@0 1268 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
Chris@0 1269 rbuggyMatches = [];
Chris@0 1270
Chris@0 1271 // qSa(:focus) reports false when true (Chrome 21)
Chris@0 1272 // We allow this because of a bug in IE8/9 that throws an error
Chris@0 1273 // whenever `document.activeElement` is accessed on an iframe
Chris@0 1274 // So, we allow :focus to pass through QSA all the time to avoid the IE error
Chris@0 1275 // See https://bugs.jquery.com/ticket/13378
Chris@0 1276 rbuggyQSA = [];
Chris@0 1277
Chris@0 1278 if ( (support.qsa = rnative.test( document.querySelectorAll )) ) {
Chris@0 1279 // Build QSA regex
Chris@0 1280 // Regex strategy adopted from Diego Perini
Chris@0 1281 assert(function( el ) {
Chris@0 1282 // Select is set to empty string on purpose
Chris@0 1283 // This is to test IE's treatment of not explicitly
Chris@0 1284 // setting a boolean content attribute,
Chris@0 1285 // since its presence should be enough
Chris@0 1286 // https://bugs.jquery.com/ticket/12359
Chris@0 1287 docElem.appendChild( el ).innerHTML = "<a id='" + expando + "'></a>" +
Chris@0 1288 "<select id='" + expando + "-\r\\' msallowcapture=''>" +
Chris@0 1289 "<option selected=''></option></select>";
Chris@0 1290
Chris@0 1291 // Support: IE8, Opera 11-12.16
Chris@0 1292 // Nothing should be selected when empty strings follow ^= or $= or *=
Chris@0 1293 // The test attribute must be unknown in Opera but "safe" for WinRT
Chris@0 1294 // https://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
Chris@0 1295 if ( el.querySelectorAll("[msallowcapture^='']").length ) {
Chris@0 1296 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
Chris@0 1297 }
Chris@0 1298
Chris@0 1299 // Support: IE8
Chris@0 1300 // Boolean attributes and "value" are not treated correctly
Chris@0 1301 if ( !el.querySelectorAll("[selected]").length ) {
Chris@0 1302 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
Chris@0 1303 }
Chris@0 1304
Chris@0 1305 // Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+
Chris@0 1306 if ( !el.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
Chris@0 1307 rbuggyQSA.push("~=");
Chris@0 1308 }
Chris@0 1309
Chris@0 1310 // Webkit/Opera - :checked should return selected option elements
Chris@0 1311 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
Chris@0 1312 // IE8 throws error here and will not see later tests
Chris@0 1313 if ( !el.querySelectorAll(":checked").length ) {
Chris@0 1314 rbuggyQSA.push(":checked");
Chris@0 1315 }
Chris@0 1316
Chris@0 1317 // Support: Safari 8+, iOS 8+
Chris@0 1318 // https://bugs.webkit.org/show_bug.cgi?id=136851
Chris@0 1319 // In-page `selector#id sibling-combinator selector` fails
Chris@0 1320 if ( !el.querySelectorAll( "a#" + expando + "+*" ).length ) {
Chris@0 1321 rbuggyQSA.push(".#.+[+~]");
Chris@0 1322 }
Chris@0 1323 });
Chris@0 1324
Chris@0 1325 assert(function( el ) {
Chris@0 1326 el.innerHTML = "<a href='' disabled='disabled'></a>" +
Chris@0 1327 "<select disabled='disabled'><option/></select>";
Chris@0 1328
Chris@0 1329 // Support: Windows 8 Native Apps
Chris@0 1330 // The type and name attributes are restricted during .innerHTML assignment
Chris@0 1331 var input = document.createElement("input");
Chris@0 1332 input.setAttribute( "type", "hidden" );
Chris@0 1333 el.appendChild( input ).setAttribute( "name", "D" );
Chris@0 1334
Chris@0 1335 // Support: IE8
Chris@0 1336 // Enforce case-sensitivity of name attribute
Chris@0 1337 if ( el.querySelectorAll("[name=d]").length ) {
Chris@0 1338 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
Chris@0 1339 }
Chris@0 1340
Chris@0 1341 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
Chris@0 1342 // IE8 throws error here and will not see later tests
Chris@0 1343 if ( el.querySelectorAll(":enabled").length !== 2 ) {
Chris@0 1344 rbuggyQSA.push( ":enabled", ":disabled" );
Chris@0 1345 }
Chris@0 1346
Chris@0 1347 // Support: IE9-11+
Chris@0 1348 // IE's :disabled selector does not pick up the children of disabled fieldsets
Chris@0 1349 docElem.appendChild( el ).disabled = true;
Chris@0 1350 if ( el.querySelectorAll(":disabled").length !== 2 ) {
Chris@0 1351 rbuggyQSA.push( ":enabled", ":disabled" );
Chris@0 1352 }
Chris@0 1353
Chris@0 1354 // Opera 10-11 does not throw on post-comma invalid pseudos
Chris@0 1355 el.querySelectorAll("*,:x");
Chris@0 1356 rbuggyQSA.push(",.*:");
Chris@0 1357 });
Chris@0 1358 }
Chris@0 1359
Chris@0 1360 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
Chris@0 1361 docElem.webkitMatchesSelector ||
Chris@0 1362 docElem.mozMatchesSelector ||
Chris@0 1363 docElem.oMatchesSelector ||
Chris@0 1364 docElem.msMatchesSelector) )) ) {
Chris@0 1365
Chris@0 1366 assert(function( el ) {
Chris@0 1367 // Check to see if it's possible to do matchesSelector
Chris@0 1368 // on a disconnected node (IE 9)
Chris@0 1369 support.disconnectedMatch = matches.call( el, "*" );
Chris@0 1370
Chris@0 1371 // This should fail with an exception
Chris@0 1372 // Gecko does not error, returns false instead
Chris@0 1373 matches.call( el, "[s!='']:x" );
Chris@0 1374 rbuggyMatches.push( "!=", pseudos );
Chris@0 1375 });
Chris@0 1376 }
Chris@0 1377
Chris@0 1378 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
Chris@0 1379 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
Chris@0 1380
Chris@0 1381 /* Contains
Chris@0 1382 ---------------------------------------------------------------------- */
Chris@0 1383 hasCompare = rnative.test( docElem.compareDocumentPosition );
Chris@0 1384
Chris@0 1385 // Element contains another
Chris@0 1386 // Purposefully self-exclusive
Chris@0 1387 // As in, an element does not contain itself
Chris@0 1388 contains = hasCompare || rnative.test( docElem.contains ) ?
Chris@0 1389 function( a, b ) {
Chris@0 1390 var adown = a.nodeType === 9 ? a.documentElement : a,
Chris@0 1391 bup = b && b.parentNode;
Chris@0 1392 return a === bup || !!( bup && bup.nodeType === 1 && (
Chris@0 1393 adown.contains ?
Chris@0 1394 adown.contains( bup ) :
Chris@0 1395 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
Chris@0 1396 ));
Chris@0 1397 } :
Chris@0 1398 function( a, b ) {
Chris@0 1399 if ( b ) {
Chris@0 1400 while ( (b = b.parentNode) ) {
Chris@0 1401 if ( b === a ) {
Chris@0 1402 return true;
Chris@0 1403 }
Chris@0 1404 }
Chris@0 1405 }
Chris@0 1406 return false;
Chris@0 1407 };
Chris@0 1408
Chris@0 1409 /* Sorting
Chris@0 1410 ---------------------------------------------------------------------- */
Chris@0 1411
Chris@0 1412 // Document order sorting
Chris@0 1413 sortOrder = hasCompare ?
Chris@0 1414 function( a, b ) {
Chris@0 1415
Chris@0 1416 // Flag for duplicate removal
Chris@0 1417 if ( a === b ) {
Chris@0 1418 hasDuplicate = true;
Chris@0 1419 return 0;
Chris@0 1420 }
Chris@0 1421
Chris@0 1422 // Sort on method existence if only one input has compareDocumentPosition
Chris@0 1423 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
Chris@0 1424 if ( compare ) {
Chris@0 1425 return compare;
Chris@0 1426 }
Chris@0 1427
Chris@0 1428 // Calculate position if both inputs belong to the same document
Chris@0 1429 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
Chris@0 1430 a.compareDocumentPosition( b ) :
Chris@0 1431
Chris@0 1432 // Otherwise we know they are disconnected
Chris@0 1433 1;
Chris@0 1434
Chris@0 1435 // Disconnected nodes
Chris@0 1436 if ( compare & 1 ||
Chris@0 1437 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
Chris@0 1438
Chris@0 1439 // Choose the first element that is related to our preferred document
Chris@0 1440 if ( a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
Chris@0 1441 return -1;
Chris@0 1442 }
Chris@0 1443 if ( b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
Chris@0 1444 return 1;
Chris@0 1445 }
Chris@0 1446
Chris@0 1447 // Maintain original order
Chris@0 1448 return sortInput ?
Chris@0 1449 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
Chris@0 1450 0;
Chris@0 1451 }
Chris@0 1452
Chris@0 1453 return compare & 4 ? -1 : 1;
Chris@0 1454 } :
Chris@0 1455 function( a, b ) {
Chris@0 1456 // Exit early if the nodes are identical
Chris@0 1457 if ( a === b ) {
Chris@0 1458 hasDuplicate = true;
Chris@0 1459 return 0;
Chris@0 1460 }
Chris@0 1461
Chris@0 1462 var cur,
Chris@0 1463 i = 0,
Chris@0 1464 aup = a.parentNode,
Chris@0 1465 bup = b.parentNode,
Chris@0 1466 ap = [ a ],
Chris@0 1467 bp = [ b ];
Chris@0 1468
Chris@0 1469 // Parentless nodes are either documents or disconnected
Chris@0 1470 if ( !aup || !bup ) {
Chris@0 1471 return a === document ? -1 :
Chris@0 1472 b === document ? 1 :
Chris@0 1473 aup ? -1 :
Chris@0 1474 bup ? 1 :
Chris@0 1475 sortInput ?
Chris@0 1476 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
Chris@0 1477 0;
Chris@0 1478
Chris@0 1479 // If the nodes are siblings, we can do a quick check
Chris@0 1480 } else if ( aup === bup ) {
Chris@0 1481 return siblingCheck( a, b );
Chris@0 1482 }
Chris@0 1483
Chris@0 1484 // Otherwise we need full lists of their ancestors for comparison
Chris@0 1485 cur = a;
Chris@0 1486 while ( (cur = cur.parentNode) ) {
Chris@0 1487 ap.unshift( cur );
Chris@0 1488 }
Chris@0 1489 cur = b;
Chris@0 1490 while ( (cur = cur.parentNode) ) {
Chris@0 1491 bp.unshift( cur );
Chris@0 1492 }
Chris@0 1493
Chris@0 1494 // Walk down the tree looking for a discrepancy
Chris@0 1495 while ( ap[i] === bp[i] ) {
Chris@0 1496 i++;
Chris@0 1497 }
Chris@0 1498
Chris@0 1499 return i ?
Chris@0 1500 // Do a sibling check if the nodes have a common ancestor
Chris@0 1501 siblingCheck( ap[i], bp[i] ) :
Chris@0 1502
Chris@0 1503 // Otherwise nodes in our document sort first
Chris@0 1504 ap[i] === preferredDoc ? -1 :
Chris@0 1505 bp[i] === preferredDoc ? 1 :
Chris@0 1506 0;
Chris@0 1507 };
Chris@0 1508
Chris@0 1509 return document;
Chris@0 1510 };
Chris@0 1511
Chris@0 1512 Sizzle.matches = function( expr, elements ) {
Chris@0 1513 return Sizzle( expr, null, null, elements );
Chris@0 1514 };
Chris@0 1515
Chris@0 1516 Sizzle.matchesSelector = function( elem, expr ) {
Chris@0 1517 // Set document vars if needed
Chris@0 1518 if ( ( elem.ownerDocument || elem ) !== document ) {
Chris@0 1519 setDocument( elem );
Chris@0 1520 }
Chris@0 1521
Chris@0 1522 // Make sure that attribute selectors are quoted
Chris@0 1523 expr = expr.replace( rattributeQuotes, "='$1']" );
Chris@0 1524
Chris@0 1525 if ( support.matchesSelector && documentIsHTML &&
Chris@0 1526 !compilerCache[ expr + " " ] &&
Chris@0 1527 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
Chris@0 1528 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
Chris@0 1529
Chris@0 1530 try {
Chris@0 1531 var ret = matches.call( elem, expr );
Chris@0 1532
Chris@0 1533 // IE 9's matchesSelector returns false on disconnected nodes
Chris@0 1534 if ( ret || support.disconnectedMatch ||
Chris@0 1535 // As well, disconnected nodes are said to be in a document
Chris@0 1536 // fragment in IE 9
Chris@0 1537 elem.document && elem.document.nodeType !== 11 ) {
Chris@0 1538 return ret;
Chris@0 1539 }
Chris@0 1540 } catch (e) {}
Chris@0 1541 }
Chris@0 1542
Chris@0 1543 return Sizzle( expr, document, null, [ elem ] ).length > 0;
Chris@0 1544 };
Chris@0 1545
Chris@0 1546 Sizzle.contains = function( context, elem ) {
Chris@0 1547 // Set document vars if needed
Chris@0 1548 if ( ( context.ownerDocument || context ) !== document ) {
Chris@0 1549 setDocument( context );
Chris@0 1550 }
Chris@0 1551 return contains( context, elem );
Chris@0 1552 };
Chris@0 1553
Chris@0 1554 Sizzle.attr = function( elem, name ) {
Chris@0 1555 // Set document vars if needed
Chris@0 1556 if ( ( elem.ownerDocument || elem ) !== document ) {
Chris@0 1557 setDocument( elem );
Chris@0 1558 }
Chris@0 1559
Chris@0 1560 var fn = Expr.attrHandle[ name.toLowerCase() ],
Chris@0 1561 // Don't get fooled by Object.prototype properties (jQuery #13807)
Chris@0 1562 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
Chris@0 1563 fn( elem, name, !documentIsHTML ) :
Chris@0 1564 undefined;
Chris@0 1565
Chris@0 1566 return val !== undefined ?
Chris@0 1567 val :
Chris@0 1568 support.attributes || !documentIsHTML ?
Chris@0 1569 elem.getAttribute( name ) :
Chris@0 1570 (val = elem.getAttributeNode(name)) && val.specified ?
Chris@0 1571 val.value :
Chris@0 1572 null;
Chris@0 1573 };
Chris@0 1574
Chris@0 1575 Sizzle.escape = function( sel ) {
Chris@0 1576 return (sel + "").replace( rcssescape, fcssescape );
Chris@0 1577 };
Chris@0 1578
Chris@0 1579 Sizzle.error = function( msg ) {
Chris@0 1580 throw new Error( "Syntax error, unrecognized expression: " + msg );
Chris@0 1581 };
Chris@0 1582
Chris@0 1583 /**
Chris@0 1584 * Document sorting and removing duplicates
Chris@0 1585 * @param {ArrayLike} results
Chris@0 1586 */
Chris@0 1587 Sizzle.uniqueSort = function( results ) {
Chris@0 1588 var elem,
Chris@0 1589 duplicates = [],
Chris@0 1590 j = 0,
Chris@0 1591 i = 0;
Chris@0 1592
Chris@0 1593 // Unless we *know* we can detect duplicates, assume their presence
Chris@0 1594 hasDuplicate = !support.detectDuplicates;
Chris@0 1595 sortInput = !support.sortStable && results.slice( 0 );
Chris@0 1596 results.sort( sortOrder );
Chris@0 1597
Chris@0 1598 if ( hasDuplicate ) {
Chris@0 1599 while ( (elem = results[i++]) ) {
Chris@0 1600 if ( elem === results[ i ] ) {
Chris@0 1601 j = duplicates.push( i );
Chris@0 1602 }
Chris@0 1603 }
Chris@0 1604 while ( j-- ) {
Chris@0 1605 results.splice( duplicates[ j ], 1 );
Chris@0 1606 }
Chris@0 1607 }
Chris@0 1608
Chris@0 1609 // Clear input after sorting to release objects
Chris@0 1610 // See https://github.com/jquery/sizzle/pull/225
Chris@0 1611 sortInput = null;
Chris@0 1612
Chris@0 1613 return results;
Chris@0 1614 };
Chris@0 1615
Chris@0 1616 /**
Chris@0 1617 * Utility function for retrieving the text value of an array of DOM nodes
Chris@0 1618 * @param {Array|Element} elem
Chris@0 1619 */
Chris@0 1620 getText = Sizzle.getText = function( elem ) {
Chris@0 1621 var node,
Chris@0 1622 ret = "",
Chris@0 1623 i = 0,
Chris@0 1624 nodeType = elem.nodeType;
Chris@0 1625
Chris@0 1626 if ( !nodeType ) {
Chris@0 1627 // If no nodeType, this is expected to be an array
Chris@0 1628 while ( (node = elem[i++]) ) {
Chris@0 1629 // Do not traverse comment nodes
Chris@0 1630 ret += getText( node );
Chris@0 1631 }
Chris@0 1632 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
Chris@0 1633 // Use textContent for elements
Chris@0 1634 // innerText usage removed for consistency of new lines (jQuery #11153)
Chris@0 1635 if ( typeof elem.textContent === "string" ) {
Chris@0 1636 return elem.textContent;
Chris@0 1637 } else {
Chris@0 1638 // Traverse its children
Chris@0 1639 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
Chris@0 1640 ret += getText( elem );
Chris@0 1641 }
Chris@0 1642 }
Chris@0 1643 } else if ( nodeType === 3 || nodeType === 4 ) {
Chris@0 1644 return elem.nodeValue;
Chris@0 1645 }
Chris@0 1646 // Do not include comment or processing instruction nodes
Chris@0 1647
Chris@0 1648 return ret;
Chris@0 1649 };
Chris@0 1650
Chris@0 1651 Expr = Sizzle.selectors = {
Chris@0 1652
Chris@0 1653 // Can be adjusted by the user
Chris@0 1654 cacheLength: 50,
Chris@0 1655
Chris@0 1656 createPseudo: markFunction,
Chris@0 1657
Chris@0 1658 match: matchExpr,
Chris@0 1659
Chris@0 1660 attrHandle: {},
Chris@0 1661
Chris@0 1662 find: {},
Chris@0 1663
Chris@0 1664 relative: {
Chris@0 1665 ">": { dir: "parentNode", first: true },
Chris@0 1666 " ": { dir: "parentNode" },
Chris@0 1667 "+": { dir: "previousSibling", first: true },
Chris@0 1668 "~": { dir: "previousSibling" }
Chris@0 1669 },
Chris@0 1670
Chris@0 1671 preFilter: {
Chris@0 1672 "ATTR": function( match ) {
Chris@0 1673 match[1] = match[1].replace( runescape, funescape );
Chris@0 1674
Chris@0 1675 // Move the given value to match[3] whether quoted or unquoted
Chris@0 1676 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
Chris@0 1677
Chris@0 1678 if ( match[2] === "~=" ) {
Chris@0 1679 match[3] = " " + match[3] + " ";
Chris@0 1680 }
Chris@0 1681
Chris@0 1682 return match.slice( 0, 4 );
Chris@0 1683 },
Chris@0 1684
Chris@0 1685 "CHILD": function( match ) {
Chris@0 1686 /* matches from matchExpr["CHILD"]
Chris@0 1687 1 type (only|nth|...)
Chris@0 1688 2 what (child|of-type)
Chris@0 1689 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
Chris@0 1690 4 xn-component of xn+y argument ([+-]?\d*n|)
Chris@0 1691 5 sign of xn-component
Chris@0 1692 6 x of xn-component
Chris@0 1693 7 sign of y-component
Chris@0 1694 8 y of y-component
Chris@0 1695 */
Chris@0 1696 match[1] = match[1].toLowerCase();
Chris@0 1697
Chris@0 1698 if ( match[1].slice( 0, 3 ) === "nth" ) {
Chris@0 1699 // nth-* requires argument
Chris@0 1700 if ( !match[3] ) {
Chris@0 1701 Sizzle.error( match[0] );
Chris@0 1702 }
Chris@0 1703
Chris@0 1704 // numeric x and y parameters for Expr.filter.CHILD
Chris@0 1705 // remember that false/true cast respectively to 0/1
Chris@0 1706 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
Chris@0 1707 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
Chris@0 1708
Chris@0 1709 // other types prohibit arguments
Chris@0 1710 } else if ( match[3] ) {
Chris@0 1711 Sizzle.error( match[0] );
Chris@0 1712 }
Chris@0 1713
Chris@0 1714 return match;
Chris@0 1715 },
Chris@0 1716
Chris@0 1717 "PSEUDO": function( match ) {
Chris@0 1718 var excess,
Chris@0 1719 unquoted = !match[6] && match[2];
Chris@0 1720
Chris@0 1721 if ( matchExpr["CHILD"].test( match[0] ) ) {
Chris@0 1722 return null;
Chris@0 1723 }
Chris@0 1724
Chris@0 1725 // Accept quoted arguments as-is
Chris@0 1726 if ( match[3] ) {
Chris@0 1727 match[2] = match[4] || match[5] || "";
Chris@0 1728
Chris@0 1729 // Strip excess characters from unquoted arguments
Chris@0 1730 } else if ( unquoted && rpseudo.test( unquoted ) &&
Chris@0 1731 // Get excess from tokenize (recursively)
Chris@0 1732 (excess = tokenize( unquoted, true )) &&
Chris@0 1733 // advance to the next closing parenthesis
Chris@0 1734 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
Chris@0 1735
Chris@0 1736 // excess is a negative index
Chris@0 1737 match[0] = match[0].slice( 0, excess );
Chris@0 1738 match[2] = unquoted.slice( 0, excess );
Chris@0 1739 }
Chris@0 1740
Chris@0 1741 // Return only captures needed by the pseudo filter method (type and argument)
Chris@0 1742 return match.slice( 0, 3 );
Chris@0 1743 }
Chris@0 1744 },
Chris@0 1745
Chris@0 1746 filter: {
Chris@0 1747
Chris@0 1748 "TAG": function( nodeNameSelector ) {
Chris@0 1749 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
Chris@0 1750 return nodeNameSelector === "*" ?
Chris@0 1751 function() { return true; } :
Chris@0 1752 function( elem ) {
Chris@0 1753 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
Chris@0 1754 };
Chris@0 1755 },
Chris@0 1756
Chris@0 1757 "CLASS": function( className ) {
Chris@0 1758 var pattern = classCache[ className + " " ];
Chris@0 1759
Chris@0 1760 return pattern ||
Chris@0 1761 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
Chris@0 1762 classCache( className, function( elem ) {
Chris@0 1763 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
Chris@0 1764 });
Chris@0 1765 },
Chris@0 1766
Chris@0 1767 "ATTR": function( name, operator, check ) {
Chris@0 1768 return function( elem ) {
Chris@0 1769 var result = Sizzle.attr( elem, name );
Chris@0 1770
Chris@0 1771 if ( result == null ) {
Chris@0 1772 return operator === "!=";
Chris@0 1773 }
Chris@0 1774 if ( !operator ) {
Chris@0 1775 return true;
Chris@0 1776 }
Chris@0 1777
Chris@0 1778 result += "";
Chris@0 1779
Chris@0 1780 return operator === "=" ? result === check :
Chris@0 1781 operator === "!=" ? result !== check :
Chris@0 1782 operator === "^=" ? check && result.indexOf( check ) === 0 :
Chris@0 1783 operator === "*=" ? check && result.indexOf( check ) > -1 :
Chris@0 1784 operator === "$=" ? check && result.slice( -check.length ) === check :
Chris@0 1785 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
Chris@0 1786 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
Chris@0 1787 false;
Chris@0 1788 };
Chris@0 1789 },
Chris@0 1790
Chris@0 1791 "CHILD": function( type, what, argument, first, last ) {
Chris@0 1792 var simple = type.slice( 0, 3 ) !== "nth",
Chris@0 1793 forward = type.slice( -4 ) !== "last",
Chris@0 1794 ofType = what === "of-type";
Chris@0 1795
Chris@0 1796 return first === 1 && last === 0 ?
Chris@0 1797
Chris@0 1798 // Shortcut for :nth-*(n)
Chris@0 1799 function( elem ) {
Chris@0 1800 return !!elem.parentNode;
Chris@0 1801 } :
Chris@0 1802
Chris@0 1803 function( elem, context, xml ) {
Chris@0 1804 var cache, uniqueCache, outerCache, node, nodeIndex, start,
Chris@0 1805 dir = simple !== forward ? "nextSibling" : "previousSibling",
Chris@0 1806 parent = elem.parentNode,
Chris@0 1807 name = ofType && elem.nodeName.toLowerCase(),
Chris@0 1808 useCache = !xml && !ofType,
Chris@0 1809 diff = false;
Chris@0 1810
Chris@0 1811 if ( parent ) {
Chris@0 1812
Chris@0 1813 // :(first|last|only)-(child|of-type)
Chris@0 1814 if ( simple ) {
Chris@0 1815 while ( dir ) {
Chris@0 1816 node = elem;
Chris@0 1817 while ( (node = node[ dir ]) ) {
Chris@0 1818 if ( ofType ?
Chris@0 1819 node.nodeName.toLowerCase() === name :
Chris@0 1820 node.nodeType === 1 ) {
Chris@0 1821
Chris@0 1822 return false;
Chris@0 1823 }
Chris@0 1824 }
Chris@0 1825 // Reverse direction for :only-* (if we haven't yet done so)
Chris@0 1826 start = dir = type === "only" && !start && "nextSibling";
Chris@0 1827 }
Chris@0 1828 return true;
Chris@0 1829 }
Chris@0 1830
Chris@0 1831 start = [ forward ? parent.firstChild : parent.lastChild ];
Chris@0 1832
Chris@0 1833 // non-xml :nth-child(...) stores cache data on `parent`
Chris@0 1834 if ( forward && useCache ) {
Chris@0 1835
Chris@0 1836 // Seek `elem` from a previously-cached index
Chris@0 1837
Chris@0 1838 // ...in a gzip-friendly way
Chris@0 1839 node = parent;
Chris@0 1840 outerCache = node[ expando ] || (node[ expando ] = {});
Chris@0 1841
Chris@0 1842 // Support: IE <9 only
Chris@0 1843 // Defend against cloned attroperties (jQuery gh-1709)
Chris@0 1844 uniqueCache = outerCache[ node.uniqueID ] ||
Chris@0 1845 (outerCache[ node.uniqueID ] = {});
Chris@0 1846
Chris@0 1847 cache = uniqueCache[ type ] || [];
Chris@0 1848 nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
Chris@0 1849 diff = nodeIndex && cache[ 2 ];
Chris@0 1850 node = nodeIndex && parent.childNodes[ nodeIndex ];
Chris@0 1851
Chris@0 1852 while ( (node = ++nodeIndex && node && node[ dir ] ||
Chris@0 1853
Chris@0 1854 // Fallback to seeking `elem` from the start
Chris@0 1855 (diff = nodeIndex = 0) || start.pop()) ) {
Chris@0 1856
Chris@0 1857 // When found, cache indexes on `parent` and break
Chris@0 1858 if ( node.nodeType === 1 && ++diff && node === elem ) {
Chris@0 1859 uniqueCache[ type ] = [ dirruns, nodeIndex, diff ];
Chris@0 1860 break;
Chris@0 1861 }
Chris@0 1862 }
Chris@0 1863
Chris@0 1864 } else {
Chris@0 1865 // Use previously-cached element index if available
Chris@0 1866 if ( useCache ) {
Chris@0 1867 // ...in a gzip-friendly way
Chris@0 1868 node = elem;
Chris@0 1869 outerCache = node[ expando ] || (node[ expando ] = {});
Chris@0 1870
Chris@0 1871 // Support: IE <9 only
Chris@0 1872 // Defend against cloned attroperties (jQuery gh-1709)
Chris@0 1873 uniqueCache = outerCache[ node.uniqueID ] ||
Chris@0 1874 (outerCache[ node.uniqueID ] = {});
Chris@0 1875
Chris@0 1876 cache = uniqueCache[ type ] || [];
Chris@0 1877 nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
Chris@0 1878 diff = nodeIndex;
Chris@0 1879 }
Chris@0 1880
Chris@0 1881 // xml :nth-child(...)
Chris@0 1882 // or :nth-last-child(...) or :nth(-last)?-of-type(...)
Chris@0 1883 if ( diff === false ) {
Chris@0 1884 // Use the same loop as above to seek `elem` from the start
Chris@0 1885 while ( (node = ++nodeIndex && node && node[ dir ] ||
Chris@0 1886 (diff = nodeIndex = 0) || start.pop()) ) {
Chris@0 1887
Chris@0 1888 if ( ( ofType ?
Chris@0 1889 node.nodeName.toLowerCase() === name :
Chris@0 1890 node.nodeType === 1 ) &&
Chris@0 1891 ++diff ) {
Chris@0 1892
Chris@0 1893 // Cache the index of each encountered element
Chris@0 1894 if ( useCache ) {
Chris@0 1895 outerCache = node[ expando ] || (node[ expando ] = {});
Chris@0 1896
Chris@0 1897 // Support: IE <9 only
Chris@0 1898 // Defend against cloned attroperties (jQuery gh-1709)
Chris@0 1899 uniqueCache = outerCache[ node.uniqueID ] ||
Chris@0 1900 (outerCache[ node.uniqueID ] = {});
Chris@0 1901
Chris@0 1902 uniqueCache[ type ] = [ dirruns, diff ];
Chris@0 1903 }
Chris@0 1904
Chris@0 1905 if ( node === elem ) {
Chris@0 1906 break;
Chris@0 1907 }
Chris@0 1908 }
Chris@0 1909 }
Chris@0 1910 }
Chris@0 1911 }
Chris@0 1912
Chris@0 1913 // Incorporate the offset, then check against cycle size
Chris@0 1914 diff -= last;
Chris@0 1915 return diff === first || ( diff % first === 0 && diff / first >= 0 );
Chris@0 1916 }
Chris@0 1917 };
Chris@0 1918 },
Chris@0 1919
Chris@0 1920 "PSEUDO": function( pseudo, argument ) {
Chris@0 1921 // pseudo-class names are case-insensitive
Chris@0 1922 // http://www.w3.org/TR/selectors/#pseudo-classes
Chris@0 1923 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
Chris@0 1924 // Remember that setFilters inherits from pseudos
Chris@0 1925 var args,
Chris@0 1926 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
Chris@0 1927 Sizzle.error( "unsupported pseudo: " + pseudo );
Chris@0 1928
Chris@0 1929 // The user may use createPseudo to indicate that
Chris@0 1930 // arguments are needed to create the filter function
Chris@0 1931 // just as Sizzle does
Chris@0 1932 if ( fn[ expando ] ) {
Chris@0 1933 return fn( argument );
Chris@0 1934 }
Chris@0 1935
Chris@0 1936 // But maintain support for old signatures
Chris@0 1937 if ( fn.length > 1 ) {
Chris@0 1938 args = [ pseudo, pseudo, "", argument ];
Chris@0 1939 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
Chris@0 1940 markFunction(function( seed, matches ) {
Chris@0 1941 var idx,
Chris@0 1942 matched = fn( seed, argument ),
Chris@0 1943 i = matched.length;
Chris@0 1944 while ( i-- ) {
Chris@0 1945 idx = indexOf( seed, matched[i] );
Chris@0 1946 seed[ idx ] = !( matches[ idx ] = matched[i] );
Chris@0 1947 }
Chris@0 1948 }) :
Chris@0 1949 function( elem ) {
Chris@0 1950 return fn( elem, 0, args );
Chris@0 1951 };
Chris@0 1952 }
Chris@0 1953
Chris@0 1954 return fn;
Chris@0 1955 }
Chris@0 1956 },
Chris@0 1957
Chris@0 1958 pseudos: {
Chris@0 1959 // Potentially complex pseudos
Chris@0 1960 "not": markFunction(function( selector ) {
Chris@0 1961 // Trim the selector passed to compile
Chris@0 1962 // to avoid treating leading and trailing
Chris@0 1963 // spaces as combinators
Chris@0 1964 var input = [],
Chris@0 1965 results = [],
Chris@0 1966 matcher = compile( selector.replace( rtrim, "$1" ) );
Chris@0 1967
Chris@0 1968 return matcher[ expando ] ?
Chris@0 1969 markFunction(function( seed, matches, context, xml ) {
Chris@0 1970 var elem,
Chris@0 1971 unmatched = matcher( seed, null, xml, [] ),
Chris@0 1972 i = seed.length;
Chris@0 1973
Chris@0 1974 // Match elements unmatched by `matcher`
Chris@0 1975 while ( i-- ) {
Chris@0 1976 if ( (elem = unmatched[i]) ) {
Chris@0 1977 seed[i] = !(matches[i] = elem);
Chris@0 1978 }
Chris@0 1979 }
Chris@0 1980 }) :
Chris@0 1981 function( elem, context, xml ) {
Chris@0 1982 input[0] = elem;
Chris@0 1983 matcher( input, null, xml, results );
Chris@0 1984 // Don't keep the element (issue #299)
Chris@0 1985 input[0] = null;
Chris@0 1986 return !results.pop();
Chris@0 1987 };
Chris@0 1988 }),
Chris@0 1989
Chris@0 1990 "has": markFunction(function( selector ) {
Chris@0 1991 return function( elem ) {
Chris@0 1992 return Sizzle( selector, elem ).length > 0;
Chris@0 1993 };
Chris@0 1994 }),
Chris@0 1995
Chris@0 1996 "contains": markFunction(function( text ) {
Chris@0 1997 text = text.replace( runescape, funescape );
Chris@0 1998 return function( elem ) {
Chris@0 1999 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
Chris@0 2000 };
Chris@0 2001 }),
Chris@0 2002
Chris@0 2003 // "Whether an element is represented by a :lang() selector
Chris@0 2004 // is based solely on the element's language value
Chris@0 2005 // being equal to the identifier C,
Chris@0 2006 // or beginning with the identifier C immediately followed by "-".
Chris@0 2007 // The matching of C against the element's language value is performed case-insensitively.
Chris@0 2008 // The identifier C does not have to be a valid language name."
Chris@0 2009 // http://www.w3.org/TR/selectors/#lang-pseudo
Chris@0 2010 "lang": markFunction( function( lang ) {
Chris@0 2011 // lang value must be a valid identifier
Chris@0 2012 if ( !ridentifier.test(lang || "") ) {
Chris@0 2013 Sizzle.error( "unsupported lang: " + lang );
Chris@0 2014 }
Chris@0 2015 lang = lang.replace( runescape, funescape ).toLowerCase();
Chris@0 2016 return function( elem ) {
Chris@0 2017 var elemLang;
Chris@0 2018 do {
Chris@0 2019 if ( (elemLang = documentIsHTML ?
Chris@0 2020 elem.lang :
Chris@0 2021 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
Chris@0 2022
Chris@0 2023 elemLang = elemLang.toLowerCase();
Chris@0 2024 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
Chris@0 2025 }
Chris@0 2026 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
Chris@0 2027 return false;
Chris@0 2028 };
Chris@0 2029 }),
Chris@0 2030
Chris@0 2031 // Miscellaneous
Chris@0 2032 "target": function( elem ) {
Chris@0 2033 var hash = window.location && window.location.hash;
Chris@0 2034 return hash && hash.slice( 1 ) === elem.id;
Chris@0 2035 },
Chris@0 2036
Chris@0 2037 "root": function( elem ) {
Chris@0 2038 return elem === docElem;
Chris@0 2039 },
Chris@0 2040
Chris@0 2041 "focus": function( elem ) {
Chris@0 2042 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
Chris@0 2043 },
Chris@0 2044
Chris@0 2045 // Boolean properties
Chris@0 2046 "enabled": createDisabledPseudo( false ),
Chris@0 2047 "disabled": createDisabledPseudo( true ),
Chris@0 2048
Chris@0 2049 "checked": function( elem ) {
Chris@0 2050 // In CSS3, :checked should return both checked and selected elements
Chris@0 2051 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
Chris@0 2052 var nodeName = elem.nodeName.toLowerCase();
Chris@0 2053 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
Chris@0 2054 },
Chris@0 2055
Chris@0 2056 "selected": function( elem ) {
Chris@0 2057 // Accessing this property makes selected-by-default
Chris@0 2058 // options in Safari work properly
Chris@0 2059 if ( elem.parentNode ) {
Chris@0 2060 elem.parentNode.selectedIndex;
Chris@0 2061 }
Chris@0 2062
Chris@0 2063 return elem.selected === true;
Chris@0 2064 },
Chris@0 2065
Chris@0 2066 // Contents
Chris@0 2067 "empty": function( elem ) {
Chris@0 2068 // http://www.w3.org/TR/selectors/#empty-pseudo
Chris@0 2069 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
Chris@0 2070 // but not by others (comment: 8; processing instruction: 7; etc.)
Chris@0 2071 // nodeType < 6 works because attributes (2) do not appear as children
Chris@0 2072 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
Chris@0 2073 if ( elem.nodeType < 6 ) {
Chris@0 2074 return false;
Chris@0 2075 }
Chris@0 2076 }
Chris@0 2077 return true;
Chris@0 2078 },
Chris@0 2079
Chris@0 2080 "parent": function( elem ) {
Chris@0 2081 return !Expr.pseudos["empty"]( elem );
Chris@0 2082 },
Chris@0 2083
Chris@0 2084 // Element/input types
Chris@0 2085 "header": function( elem ) {
Chris@0 2086 return rheader.test( elem.nodeName );
Chris@0 2087 },
Chris@0 2088
Chris@0 2089 "input": function( elem ) {
Chris@0 2090 return rinputs.test( elem.nodeName );
Chris@0 2091 },
Chris@0 2092
Chris@0 2093 "button": function( elem ) {
Chris@0 2094 var name = elem.nodeName.toLowerCase();
Chris@0 2095 return name === "input" && elem.type === "button" || name === "button";
Chris@0 2096 },
Chris@0 2097
Chris@0 2098 "text": function( elem ) {
Chris@0 2099 var attr;
Chris@0 2100 return elem.nodeName.toLowerCase() === "input" &&
Chris@0 2101 elem.type === "text" &&
Chris@0 2102
Chris@0 2103 // Support: IE<8
Chris@0 2104 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
Chris@0 2105 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
Chris@0 2106 },
Chris@0 2107
Chris@0 2108 // Position-in-collection
Chris@0 2109 "first": createPositionalPseudo(function() {
Chris@0 2110 return [ 0 ];
Chris@0 2111 }),
Chris@0 2112
Chris@0 2113 "last": createPositionalPseudo(function( matchIndexes, length ) {
Chris@0 2114 return [ length - 1 ];
Chris@0 2115 }),
Chris@0 2116
Chris@0 2117 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
Chris@0 2118 return [ argument < 0 ? argument + length : argument ];
Chris@0 2119 }),
Chris@0 2120
Chris@0 2121 "even": createPositionalPseudo(function( matchIndexes, length ) {
Chris@0 2122 var i = 0;
Chris@0 2123 for ( ; i < length; i += 2 ) {
Chris@0 2124 matchIndexes.push( i );
Chris@0 2125 }
Chris@0 2126 return matchIndexes;
Chris@0 2127 }),
Chris@0 2128
Chris@0 2129 "odd": createPositionalPseudo(function( matchIndexes, length ) {
Chris@0 2130 var i = 1;
Chris@0 2131 for ( ; i < length; i += 2 ) {
Chris@0 2132 matchIndexes.push( i );
Chris@0 2133 }
Chris@0 2134 return matchIndexes;
Chris@0 2135 }),
Chris@0 2136
Chris@0 2137 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
Chris@0 2138 var i = argument < 0 ? argument + length : argument;
Chris@0 2139 for ( ; --i >= 0; ) {
Chris@0 2140 matchIndexes.push( i );
Chris@0 2141 }
Chris@0 2142 return matchIndexes;
Chris@0 2143 }),
Chris@0 2144
Chris@0 2145 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
Chris@0 2146 var i = argument < 0 ? argument + length : argument;
Chris@0 2147 for ( ; ++i < length; ) {
Chris@0 2148 matchIndexes.push( i );
Chris@0 2149 }
Chris@0 2150 return matchIndexes;
Chris@0 2151 })
Chris@0 2152 }
Chris@0 2153 };
Chris@0 2154
Chris@0 2155 Expr.pseudos["nth"] = Expr.pseudos["eq"];
Chris@0 2156
Chris@0 2157 // Add button/input type pseudos
Chris@0 2158 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
Chris@0 2159 Expr.pseudos[ i ] = createInputPseudo( i );
Chris@0 2160 }
Chris@0 2161 for ( i in { submit: true, reset: true } ) {
Chris@0 2162 Expr.pseudos[ i ] = createButtonPseudo( i );
Chris@0 2163 }
Chris@0 2164
Chris@0 2165 // Easy API for creating new setFilters
Chris@0 2166 function setFilters() {}
Chris@0 2167 setFilters.prototype = Expr.filters = Expr.pseudos;
Chris@0 2168 Expr.setFilters = new setFilters();
Chris@0 2169
Chris@0 2170 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
Chris@0 2171 var matched, match, tokens, type,
Chris@0 2172 soFar, groups, preFilters,
Chris@0 2173 cached = tokenCache[ selector + " " ];
Chris@0 2174
Chris@0 2175 if ( cached ) {
Chris@0 2176 return parseOnly ? 0 : cached.slice( 0 );
Chris@0 2177 }
Chris@0 2178
Chris@0 2179 soFar = selector;
Chris@0 2180 groups = [];
Chris@0 2181 preFilters = Expr.preFilter;
Chris@0 2182
Chris@0 2183 while ( soFar ) {
Chris@0 2184
Chris@0 2185 // Comma and first run
Chris@0 2186 if ( !matched || (match = rcomma.exec( soFar )) ) {
Chris@0 2187 if ( match ) {
Chris@0 2188 // Don't consume trailing commas as valid
Chris@0 2189 soFar = soFar.slice( match[0].length ) || soFar;
Chris@0 2190 }
Chris@0 2191 groups.push( (tokens = []) );
Chris@0 2192 }
Chris@0 2193
Chris@0 2194 matched = false;
Chris@0 2195
Chris@0 2196 // Combinators
Chris@0 2197 if ( (match = rcombinators.exec( soFar )) ) {
Chris@0 2198 matched = match.shift();
Chris@0 2199 tokens.push({
Chris@0 2200 value: matched,
Chris@0 2201 // Cast descendant combinators to space
Chris@0 2202 type: match[0].replace( rtrim, " " )
Chris@0 2203 });
Chris@0 2204 soFar = soFar.slice( matched.length );
Chris@0 2205 }
Chris@0 2206
Chris@0 2207 // Filters
Chris@0 2208 for ( type in Expr.filter ) {
Chris@0 2209 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
Chris@0 2210 (match = preFilters[ type ]( match ))) ) {
Chris@0 2211 matched = match.shift();
Chris@0 2212 tokens.push({
Chris@0 2213 value: matched,
Chris@0 2214 type: type,
Chris@0 2215 matches: match
Chris@0 2216 });
Chris@0 2217 soFar = soFar.slice( matched.length );
Chris@0 2218 }
Chris@0 2219 }
Chris@0 2220
Chris@0 2221 if ( !matched ) {
Chris@0 2222 break;
Chris@0 2223 }
Chris@0 2224 }
Chris@0 2225
Chris@0 2226 // Return the length of the invalid excess
Chris@0 2227 // if we're just parsing
Chris@0 2228 // Otherwise, throw an error or return tokens
Chris@0 2229 return parseOnly ?
Chris@0 2230 soFar.length :
Chris@0 2231 soFar ?
Chris@0 2232 Sizzle.error( selector ) :
Chris@0 2233 // Cache the tokens
Chris@0 2234 tokenCache( selector, groups ).slice( 0 );
Chris@0 2235 };
Chris@0 2236
Chris@0 2237 function toSelector( tokens ) {
Chris@0 2238 var i = 0,
Chris@0 2239 len = tokens.length,
Chris@0 2240 selector = "";
Chris@0 2241 for ( ; i < len; i++ ) {
Chris@0 2242 selector += tokens[i].value;
Chris@0 2243 }
Chris@0 2244 return selector;
Chris@0 2245 }
Chris@0 2246
Chris@0 2247 function addCombinator( matcher, combinator, base ) {
Chris@0 2248 var dir = combinator.dir,
Chris@0 2249 skip = combinator.next,
Chris@0 2250 key = skip || dir,
Chris@0 2251 checkNonElements = base && key === "parentNode",
Chris@0 2252 doneName = done++;
Chris@0 2253
Chris@0 2254 return combinator.first ?
Chris@0 2255 // Check against closest ancestor/preceding element
Chris@0 2256 function( elem, context, xml ) {
Chris@0 2257 while ( (elem = elem[ dir ]) ) {
Chris@0 2258 if ( elem.nodeType === 1 || checkNonElements ) {
Chris@0 2259 return matcher( elem, context, xml );
Chris@0 2260 }
Chris@0 2261 }
Chris@0 2262 return false;
Chris@0 2263 } :
Chris@0 2264
Chris@0 2265 // Check against all ancestor/preceding elements
Chris@0 2266 function( elem, context, xml ) {
Chris@0 2267 var oldCache, uniqueCache, outerCache,
Chris@0 2268 newCache = [ dirruns, doneName ];
Chris@0 2269
Chris@0 2270 // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
Chris@0 2271 if ( xml ) {
Chris@0 2272 while ( (elem = elem[ dir ]) ) {
Chris@0 2273 if ( elem.nodeType === 1 || checkNonElements ) {
Chris@0 2274 if ( matcher( elem, context, xml ) ) {
Chris@0 2275 return true;
Chris@0 2276 }
Chris@0 2277 }
Chris@0 2278 }
Chris@0 2279 } else {
Chris@0 2280 while ( (elem = elem[ dir ]) ) {
Chris@0 2281 if ( elem.nodeType === 1 || checkNonElements ) {
Chris@0 2282 outerCache = elem[ expando ] || (elem[ expando ] = {});
Chris@0 2283
Chris@0 2284 // Support: IE <9 only
Chris@0 2285 // Defend against cloned attroperties (jQuery gh-1709)
Chris@0 2286 uniqueCache = outerCache[ elem.uniqueID ] || (outerCache[ elem.uniqueID ] = {});
Chris@0 2287
Chris@0 2288 if ( skip && skip === elem.nodeName.toLowerCase() ) {
Chris@0 2289 elem = elem[ dir ] || elem;
Chris@0 2290 } else if ( (oldCache = uniqueCache[ key ]) &&
Chris@0 2291 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
Chris@0 2292
Chris@0 2293 // Assign to newCache so results back-propagate to previous elements
Chris@0 2294 return (newCache[ 2 ] = oldCache[ 2 ]);
Chris@0 2295 } else {
Chris@0 2296 // Reuse newcache so results back-propagate to previous elements
Chris@0 2297 uniqueCache[ key ] = newCache;
Chris@0 2298
Chris@0 2299 // A match means we're done; a fail means we have to keep checking
Chris@0 2300 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
Chris@0 2301 return true;
Chris@0 2302 }
Chris@0 2303 }
Chris@0 2304 }
Chris@0 2305 }
Chris@0 2306 }
Chris@0 2307 return false;
Chris@0 2308 };
Chris@0 2309 }
Chris@0 2310
Chris@0 2311 function elementMatcher( matchers ) {
Chris@0 2312 return matchers.length > 1 ?
Chris@0 2313 function( elem, context, xml ) {
Chris@0 2314 var i = matchers.length;
Chris@0 2315 while ( i-- ) {
Chris@0 2316 if ( !matchers[i]( elem, context, xml ) ) {
Chris@0 2317 return false;
Chris@0 2318 }
Chris@0 2319 }
Chris@0 2320 return true;
Chris@0 2321 } :
Chris@0 2322 matchers[0];
Chris@0 2323 }
Chris@0 2324
Chris@0 2325 function multipleContexts( selector, contexts, results ) {
Chris@0 2326 var i = 0,
Chris@0 2327 len = contexts.length;
Chris@0 2328 for ( ; i < len; i++ ) {
Chris@0 2329 Sizzle( selector, contexts[i], results );
Chris@0 2330 }
Chris@0 2331 return results;
Chris@0 2332 }
Chris@0 2333
Chris@0 2334 function condense( unmatched, map, filter, context, xml ) {
Chris@0 2335 var elem,
Chris@0 2336 newUnmatched = [],
Chris@0 2337 i = 0,
Chris@0 2338 len = unmatched.length,
Chris@0 2339 mapped = map != null;
Chris@0 2340
Chris@0 2341 for ( ; i < len; i++ ) {
Chris@0 2342 if ( (elem = unmatched[i]) ) {
Chris@0 2343 if ( !filter || filter( elem, context, xml ) ) {
Chris@0 2344 newUnmatched.push( elem );
Chris@0 2345 if ( mapped ) {
Chris@0 2346 map.push( i );
Chris@0 2347 }
Chris@0 2348 }
Chris@0 2349 }
Chris@0 2350 }
Chris@0 2351
Chris@0 2352 return newUnmatched;
Chris@0 2353 }
Chris@0 2354
Chris@0 2355 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
Chris@0 2356 if ( postFilter && !postFilter[ expando ] ) {
Chris@0 2357 postFilter = setMatcher( postFilter );
Chris@0 2358 }
Chris@0 2359 if ( postFinder && !postFinder[ expando ] ) {
Chris@0 2360 postFinder = setMatcher( postFinder, postSelector );
Chris@0 2361 }
Chris@0 2362 return markFunction(function( seed, results, context, xml ) {
Chris@0 2363 var temp, i, elem,
Chris@0 2364 preMap = [],
Chris@0 2365 postMap = [],
Chris@0 2366 preexisting = results.length,
Chris@0 2367
Chris@0 2368 // Get initial elements from seed or context
Chris@0 2369 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
Chris@0 2370
Chris@0 2371 // Prefilter to get matcher input, preserving a map for seed-results synchronization
Chris@0 2372 matcherIn = preFilter && ( seed || !selector ) ?
Chris@0 2373 condense( elems, preMap, preFilter, context, xml ) :
Chris@0 2374 elems,
Chris@0 2375
Chris@0 2376 matcherOut = matcher ?
Chris@0 2377 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
Chris@0 2378 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
Chris@0 2379
Chris@0 2380 // ...intermediate processing is necessary
Chris@0 2381 [] :
Chris@0 2382
Chris@0 2383 // ...otherwise use results directly
Chris@0 2384 results :
Chris@0 2385 matcherIn;
Chris@0 2386
Chris@0 2387 // Find primary matches
Chris@0 2388 if ( matcher ) {
Chris@0 2389 matcher( matcherIn, matcherOut, context, xml );
Chris@0 2390 }
Chris@0 2391
Chris@0 2392 // Apply postFilter
Chris@0 2393 if ( postFilter ) {
Chris@0 2394 temp = condense( matcherOut, postMap );
Chris@0 2395 postFilter( temp, [], context, xml );
Chris@0 2396
Chris@0 2397 // Un-match failing elements by moving them back to matcherIn
Chris@0 2398 i = temp.length;
Chris@0 2399 while ( i-- ) {
Chris@0 2400 if ( (elem = temp[i]) ) {
Chris@0 2401 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
Chris@0 2402 }
Chris@0 2403 }
Chris@0 2404 }
Chris@0 2405
Chris@0 2406 if ( seed ) {
Chris@0 2407 if ( postFinder || preFilter ) {
Chris@0 2408 if ( postFinder ) {
Chris@0 2409 // Get the final matcherOut by condensing this intermediate into postFinder contexts
Chris@0 2410 temp = [];
Chris@0 2411 i = matcherOut.length;
Chris@0 2412 while ( i-- ) {
Chris@0 2413 if ( (elem = matcherOut[i]) ) {
Chris@0 2414 // Restore matcherIn since elem is not yet a final match
Chris@0 2415 temp.push( (matcherIn[i] = elem) );
Chris@0 2416 }
Chris@0 2417 }
Chris@0 2418 postFinder( null, (matcherOut = []), temp, xml );
Chris@0 2419 }
Chris@0 2420
Chris@0 2421 // Move matched elements from seed to results to keep them synchronized
Chris@0 2422 i = matcherOut.length;
Chris@0 2423 while ( i-- ) {
Chris@0 2424 if ( (elem = matcherOut[i]) &&
Chris@0 2425 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
Chris@0 2426
Chris@0 2427 seed[temp] = !(results[temp] = elem);
Chris@0 2428 }
Chris@0 2429 }
Chris@0 2430 }
Chris@0 2431
Chris@0 2432 // Add elements to results, through postFinder if defined
Chris@0 2433 } else {
Chris@0 2434 matcherOut = condense(
Chris@0 2435 matcherOut === results ?
Chris@0 2436 matcherOut.splice( preexisting, matcherOut.length ) :
Chris@0 2437 matcherOut
Chris@0 2438 );
Chris@0 2439 if ( postFinder ) {
Chris@0 2440 postFinder( null, results, matcherOut, xml );
Chris@0 2441 } else {
Chris@0 2442 push.apply( results, matcherOut );
Chris@0 2443 }
Chris@0 2444 }
Chris@0 2445 });
Chris@0 2446 }
Chris@0 2447
Chris@0 2448 function matcherFromTokens( tokens ) {
Chris@0 2449 var checkContext, matcher, j,
Chris@0 2450 len = tokens.length,
Chris@0 2451 leadingRelative = Expr.relative[ tokens[0].type ],
Chris@0 2452 implicitRelative = leadingRelative || Expr.relative[" "],
Chris@0 2453 i = leadingRelative ? 1 : 0,
Chris@0 2454
Chris@0 2455 // The foundational matcher ensures that elements are reachable from top-level context(s)
Chris@0 2456 matchContext = addCombinator( function( elem ) {
Chris@0 2457 return elem === checkContext;
Chris@0 2458 }, implicitRelative, true ),
Chris@0 2459 matchAnyContext = addCombinator( function( elem ) {
Chris@0 2460 return indexOf( checkContext, elem ) > -1;
Chris@0 2461 }, implicitRelative, true ),
Chris@0 2462 matchers = [ function( elem, context, xml ) {
Chris@0 2463 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
Chris@0 2464 (checkContext = context).nodeType ?
Chris@0 2465 matchContext( elem, context, xml ) :
Chris@0 2466 matchAnyContext( elem, context, xml ) );
Chris@0 2467 // Avoid hanging onto element (issue #299)
Chris@0 2468 checkContext = null;
Chris@0 2469 return ret;
Chris@0 2470 } ];
Chris@0 2471
Chris@0 2472 for ( ; i < len; i++ ) {
Chris@0 2473 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
Chris@0 2474 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
Chris@0 2475 } else {
Chris@0 2476 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
Chris@0 2477
Chris@0 2478 // Return special upon seeing a positional matcher
Chris@0 2479 if ( matcher[ expando ] ) {
Chris@0 2480 // Find the next relative operator (if any) for proper handling
Chris@0 2481 j = ++i;
Chris@0 2482 for ( ; j < len; j++ ) {
Chris@0 2483 if ( Expr.relative[ tokens[j].type ] ) {
Chris@0 2484 break;
Chris@0 2485 }
Chris@0 2486 }
Chris@0 2487 return setMatcher(
Chris@0 2488 i > 1 && elementMatcher( matchers ),
Chris@0 2489 i > 1 && toSelector(
Chris@0 2490 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
Chris@0 2491 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
Chris@0 2492 ).replace( rtrim, "$1" ),
Chris@0 2493 matcher,
Chris@0 2494 i < j && matcherFromTokens( tokens.slice( i, j ) ),
Chris@0 2495 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
Chris@0 2496 j < len && toSelector( tokens )
Chris@0 2497 );
Chris@0 2498 }
Chris@0 2499 matchers.push( matcher );
Chris@0 2500 }
Chris@0 2501 }
Chris@0 2502
Chris@0 2503 return elementMatcher( matchers );
Chris@0 2504 }
Chris@0 2505
Chris@0 2506 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
Chris@0 2507 var bySet = setMatchers.length > 0,
Chris@0 2508 byElement = elementMatchers.length > 0,
Chris@0 2509 superMatcher = function( seed, context, xml, results, outermost ) {
Chris@0 2510 var elem, j, matcher,
Chris@0 2511 matchedCount = 0,
Chris@0 2512 i = "0",
Chris@0 2513 unmatched = seed && [],
Chris@0 2514 setMatched = [],
Chris@0 2515 contextBackup = outermostContext,
Chris@0 2516 // We must always have either seed elements or outermost context
Chris@0 2517 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
Chris@0 2518 // Use integer dirruns iff this is the outermost matcher
Chris@0 2519 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
Chris@0 2520 len = elems.length;
Chris@0 2521
Chris@0 2522 if ( outermost ) {
Chris@0 2523 outermostContext = context === document || context || outermost;
Chris@0 2524 }
Chris@0 2525
Chris@0 2526 // Add elements passing elementMatchers directly to results
Chris@0 2527 // Support: IE<9, Safari
Chris@0 2528 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
Chris@0 2529 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
Chris@0 2530 if ( byElement && elem ) {
Chris@0 2531 j = 0;
Chris@0 2532 if ( !context && elem.ownerDocument !== document ) {
Chris@0 2533 setDocument( elem );
Chris@0 2534 xml = !documentIsHTML;
Chris@0 2535 }
Chris@0 2536 while ( (matcher = elementMatchers[j++]) ) {
Chris@0 2537 if ( matcher( elem, context || document, xml) ) {
Chris@0 2538 results.push( elem );
Chris@0 2539 break;
Chris@0 2540 }
Chris@0 2541 }
Chris@0 2542 if ( outermost ) {
Chris@0 2543 dirruns = dirrunsUnique;
Chris@0 2544 }
Chris@0 2545 }
Chris@0 2546
Chris@0 2547 // Track unmatched elements for set filters
Chris@0 2548 if ( bySet ) {
Chris@0 2549 // They will have gone through all possible matchers
Chris@0 2550 if ( (elem = !matcher && elem) ) {
Chris@0 2551 matchedCount--;
Chris@0 2552 }
Chris@0 2553
Chris@0 2554 // Lengthen the array for every element, matched or not
Chris@0 2555 if ( seed ) {
Chris@0 2556 unmatched.push( elem );
Chris@0 2557 }
Chris@0 2558 }
Chris@0 2559 }
Chris@0 2560
Chris@0 2561 // `i` is now the count of elements visited above, and adding it to `matchedCount`
Chris@0 2562 // makes the latter nonnegative.
Chris@0 2563 matchedCount += i;
Chris@0 2564
Chris@0 2565 // Apply set filters to unmatched elements
Chris@0 2566 // NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`
Chris@0 2567 // equals `i`), unless we didn't visit _any_ elements in the above loop because we have
Chris@0 2568 // no element matchers and no seed.
Chris@0 2569 // Incrementing an initially-string "0" `i` allows `i` to remain a string only in that
Chris@0 2570 // case, which will result in a "00" `matchedCount` that differs from `i` but is also
Chris@0 2571 // numerically zero.
Chris@0 2572 if ( bySet && i !== matchedCount ) {
Chris@0 2573 j = 0;
Chris@0 2574 while ( (matcher = setMatchers[j++]) ) {
Chris@0 2575 matcher( unmatched, setMatched, context, xml );
Chris@0 2576 }
Chris@0 2577
Chris@0 2578 if ( seed ) {
Chris@0 2579 // Reintegrate element matches to eliminate the need for sorting
Chris@0 2580 if ( matchedCount > 0 ) {
Chris@0 2581 while ( i-- ) {
Chris@0 2582 if ( !(unmatched[i] || setMatched[i]) ) {
Chris@0 2583 setMatched[i] = pop.call( results );
Chris@0 2584 }
Chris@0 2585 }
Chris@0 2586 }
Chris@0 2587
Chris@0 2588 // Discard index placeholder values to get only actual matches
Chris@0 2589 setMatched = condense( setMatched );
Chris@0 2590 }
Chris@0 2591
Chris@0 2592 // Add matches to results
Chris@0 2593 push.apply( results, setMatched );
Chris@0 2594
Chris@0 2595 // Seedless set matches succeeding multiple successful matchers stipulate sorting
Chris@0 2596 if ( outermost && !seed && setMatched.length > 0 &&
Chris@0 2597 ( matchedCount + setMatchers.length ) > 1 ) {
Chris@0 2598
Chris@0 2599 Sizzle.uniqueSort( results );
Chris@0 2600 }
Chris@0 2601 }
Chris@0 2602
Chris@0 2603 // Override manipulation of globals by nested matchers
Chris@0 2604 if ( outermost ) {
Chris@0 2605 dirruns = dirrunsUnique;
Chris@0 2606 outermostContext = contextBackup;
Chris@0 2607 }
Chris@0 2608
Chris@0 2609 return unmatched;
Chris@0 2610 };
Chris@0 2611
Chris@0 2612 return bySet ?
Chris@0 2613 markFunction( superMatcher ) :
Chris@0 2614 superMatcher;
Chris@0 2615 }
Chris@0 2616
Chris@0 2617 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
Chris@0 2618 var i,
Chris@0 2619 setMatchers = [],
Chris@0 2620 elementMatchers = [],
Chris@0 2621 cached = compilerCache[ selector + " " ];
Chris@0 2622
Chris@0 2623 if ( !cached ) {
Chris@0 2624 // Generate a function of recursive functions that can be used to check each element
Chris@0 2625 if ( !match ) {
Chris@0 2626 match = tokenize( selector );
Chris@0 2627 }
Chris@0 2628 i = match.length;
Chris@0 2629 while ( i-- ) {
Chris@0 2630 cached = matcherFromTokens( match[i] );
Chris@0 2631 if ( cached[ expando ] ) {
Chris@0 2632 setMatchers.push( cached );
Chris@0 2633 } else {
Chris@0 2634 elementMatchers.push( cached );
Chris@0 2635 }
Chris@0 2636 }
Chris@0 2637
Chris@0 2638 // Cache the compiled function
Chris@0 2639 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
Chris@0 2640
Chris@0 2641 // Save selector and tokenization
Chris@0 2642 cached.selector = selector;
Chris@0 2643 }
Chris@0 2644 return cached;
Chris@0 2645 };
Chris@0 2646
Chris@0 2647 /**
Chris@0 2648 * A low-level selection function that works with Sizzle's compiled
Chris@0 2649 * selector functions
Chris@0 2650 * @param {String|Function} selector A selector or a pre-compiled
Chris@0 2651 * selector function built with Sizzle.compile
Chris@0 2652 * @param {Element} context
Chris@0 2653 * @param {Array} [results]
Chris@0 2654 * @param {Array} [seed] A set of elements to match against
Chris@0 2655 */
Chris@0 2656 select = Sizzle.select = function( selector, context, results, seed ) {
Chris@0 2657 var i, tokens, token, type, find,
Chris@0 2658 compiled = typeof selector === "function" && selector,
Chris@0 2659 match = !seed && tokenize( (selector = compiled.selector || selector) );
Chris@0 2660
Chris@0 2661 results = results || [];
Chris@0 2662
Chris@0 2663 // Try to minimize operations if there is only one selector in the list and no seed
Chris@0 2664 // (the latter of which guarantees us context)
Chris@0 2665 if ( match.length === 1 ) {
Chris@0 2666
Chris@0 2667 // Reduce context if the leading compound selector is an ID
Chris@0 2668 tokens = match[0] = match[0].slice( 0 );
Chris@0 2669 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
Chris@0 2670 context.nodeType === 9 && documentIsHTML && Expr.relative[ tokens[1].type ] ) {
Chris@0 2671
Chris@0 2672 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
Chris@0 2673 if ( !context ) {
Chris@0 2674 return results;
Chris@0 2675
Chris@0 2676 // Precompiled matchers will still verify ancestry, so step up a level
Chris@0 2677 } else if ( compiled ) {
Chris@0 2678 context = context.parentNode;
Chris@0 2679 }
Chris@0 2680
Chris@0 2681 selector = selector.slice( tokens.shift().value.length );
Chris@0 2682 }
Chris@0 2683
Chris@0 2684 // Fetch a seed set for right-to-left matching
Chris@0 2685 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
Chris@0 2686 while ( i-- ) {
Chris@0 2687 token = tokens[i];
Chris@0 2688
Chris@0 2689 // Abort if we hit a combinator
Chris@0 2690 if ( Expr.relative[ (type = token.type) ] ) {
Chris@0 2691 break;
Chris@0 2692 }
Chris@0 2693 if ( (find = Expr.find[ type ]) ) {
Chris@0 2694 // Search, expanding context for leading sibling combinators
Chris@0 2695 if ( (seed = find(
Chris@0 2696 token.matches[0].replace( runescape, funescape ),
Chris@0 2697 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
Chris@0 2698 )) ) {
Chris@0 2699
Chris@0 2700 // If seed is empty or no tokens remain, we can return early
Chris@0 2701 tokens.splice( i, 1 );
Chris@0 2702 selector = seed.length && toSelector( tokens );
Chris@0 2703 if ( !selector ) {
Chris@0 2704 push.apply( results, seed );
Chris@0 2705 return results;
Chris@0 2706 }
Chris@0 2707
Chris@0 2708 break;
Chris@0 2709 }
Chris@0 2710 }
Chris@0 2711 }
Chris@0 2712 }
Chris@0 2713
Chris@0 2714 // Compile and execute a filtering function if one is not provided
Chris@0 2715 // Provide `match` to avoid retokenization if we modified the selector above
Chris@0 2716 ( compiled || compile( selector, match ) )(
Chris@0 2717 seed,
Chris@0 2718 context,
Chris@0 2719 !documentIsHTML,
Chris@0 2720 results,
Chris@0 2721 !context || rsibling.test( selector ) && testContext( context.parentNode ) || context
Chris@0 2722 );
Chris@0 2723 return results;
Chris@0 2724 };
Chris@0 2725
Chris@0 2726 // One-time assignments
Chris@0 2727
Chris@0 2728 // Sort stability
Chris@0 2729 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
Chris@0 2730
Chris@0 2731 // Support: Chrome 14-35+
Chris@0 2732 // Always assume duplicates if they aren't passed to the comparison function
Chris@0 2733 support.detectDuplicates = !!hasDuplicate;
Chris@0 2734
Chris@0 2735 // Initialize against the default document
Chris@0 2736 setDocument();
Chris@0 2737
Chris@0 2738 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
Chris@0 2739 // Detached nodes confoundingly follow *each other*
Chris@0 2740 support.sortDetached = assert(function( el ) {
Chris@0 2741 // Should return 1, but returns 4 (following)
Chris@0 2742 return el.compareDocumentPosition( document.createElement("fieldset") ) & 1;
Chris@0 2743 });
Chris@0 2744
Chris@0 2745 // Support: IE<8
Chris@0 2746 // Prevent attribute/property "interpolation"
Chris@0 2747 // https://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
Chris@0 2748 if ( !assert(function( el ) {
Chris@0 2749 el.innerHTML = "<a href='#'></a>";
Chris@0 2750 return el.firstChild.getAttribute("href") === "#" ;
Chris@0 2751 }) ) {
Chris@0 2752 addHandle( "type|href|height|width", function( elem, name, isXML ) {
Chris@0 2753 if ( !isXML ) {
Chris@0 2754 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
Chris@0 2755 }
Chris@0 2756 });
Chris@0 2757 }
Chris@0 2758
Chris@0 2759 // Support: IE<9
Chris@0 2760 // Use defaultValue in place of getAttribute("value")
Chris@0 2761 if ( !support.attributes || !assert(function( el ) {
Chris@0 2762 el.innerHTML = "<input/>";
Chris@0 2763 el.firstChild.setAttribute( "value", "" );
Chris@0 2764 return el.firstChild.getAttribute( "value" ) === "";
Chris@0 2765 }) ) {
Chris@0 2766 addHandle( "value", function( elem, name, isXML ) {
Chris@0 2767 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
Chris@0 2768 return elem.defaultValue;
Chris@0 2769 }
Chris@0 2770 });
Chris@0 2771 }
Chris@0 2772
Chris@0 2773 // Support: IE<9
Chris@0 2774 // Use getAttributeNode to fetch booleans when getAttribute lies
Chris@0 2775 if ( !assert(function( el ) {
Chris@0 2776 return el.getAttribute("disabled") == null;
Chris@0 2777 }) ) {
Chris@0 2778 addHandle( booleans, function( elem, name, isXML ) {
Chris@0 2779 var val;
Chris@0 2780 if ( !isXML ) {
Chris@0 2781 return elem[ name ] === true ? name.toLowerCase() :
Chris@0 2782 (val = elem.getAttributeNode( name )) && val.specified ?
Chris@0 2783 val.value :
Chris@0 2784 null;
Chris@0 2785 }
Chris@0 2786 });
Chris@0 2787 }
Chris@0 2788
Chris@0 2789 return Sizzle;
Chris@0 2790
Chris@0 2791 })( window );
Chris@0 2792
Chris@0 2793
Chris@0 2794
Chris@0 2795 jQuery.find = Sizzle;
Chris@0 2796 jQuery.expr = Sizzle.selectors;
Chris@0 2797
Chris@0 2798 // Deprecated
Chris@0 2799 jQuery.expr[ ":" ] = jQuery.expr.pseudos;
Chris@0 2800 jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort;
Chris@0 2801 jQuery.text = Sizzle.getText;
Chris@0 2802 jQuery.isXMLDoc = Sizzle.isXML;
Chris@0 2803 jQuery.contains = Sizzle.contains;
Chris@0 2804 jQuery.escapeSelector = Sizzle.escape;
Chris@0 2805
Chris@0 2806
Chris@0 2807
Chris@0 2808
Chris@0 2809 var dir = function( elem, dir, until ) {
Chris@0 2810 var matched = [],
Chris@0 2811 truncate = until !== undefined;
Chris@0 2812
Chris@0 2813 while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
Chris@0 2814 if ( elem.nodeType === 1 ) {
Chris@0 2815 if ( truncate && jQuery( elem ).is( until ) ) {
Chris@0 2816 break;
Chris@0 2817 }
Chris@0 2818 matched.push( elem );
Chris@0 2819 }
Chris@0 2820 }
Chris@0 2821 return matched;
Chris@0 2822 };
Chris@0 2823
Chris@0 2824
Chris@0 2825 var siblings = function( n, elem ) {
Chris@0 2826 var matched = [];
Chris@0 2827
Chris@0 2828 for ( ; n; n = n.nextSibling ) {
Chris@0 2829 if ( n.nodeType === 1 && n !== elem ) {
Chris@0 2830 matched.push( n );
Chris@0 2831 }
Chris@0 2832 }
Chris@0 2833
Chris@0 2834 return matched;
Chris@0 2835 };
Chris@0 2836
Chris@0 2837
Chris@0 2838 var rneedsContext = jQuery.expr.match.needsContext;
Chris@0 2839
Chris@0 2840
Chris@0 2841
Chris@0 2842 function nodeName( elem, name ) {
Chris@0 2843
Chris@0 2844 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
Chris@0 2845
Chris@0 2846 };
Chris@0 2847 var rsingleTag = ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i );
Chris@0 2848
Chris@0 2849
Chris@0 2850
Chris@0 2851 var risSimple = /^.[^:#\[\.,]*$/;
Chris@0 2852
Chris@0 2853 // Implement the identical functionality for filter and not
Chris@0 2854 function winnow( elements, qualifier, not ) {
Chris@0 2855 if ( jQuery.isFunction( qualifier ) ) {
Chris@0 2856 return jQuery.grep( elements, function( elem, i ) {
Chris@0 2857 return !!qualifier.call( elem, i, elem ) !== not;
Chris@0 2858 } );
Chris@0 2859 }
Chris@0 2860
Chris@0 2861 // Single element
Chris@0 2862 if ( qualifier.nodeType ) {
Chris@0 2863 return jQuery.grep( elements, function( elem ) {
Chris@0 2864 return ( elem === qualifier ) !== not;
Chris@0 2865 } );
Chris@0 2866 }
Chris@0 2867
Chris@0 2868 // Arraylike of elements (jQuery, arguments, Array)
Chris@0 2869 if ( typeof qualifier !== "string" ) {
Chris@0 2870 return jQuery.grep( elements, function( elem ) {
Chris@0 2871 return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
Chris@0 2872 } );
Chris@0 2873 }
Chris@0 2874
Chris@0 2875 // Simple selector that can be filtered directly, removing non-Elements
Chris@0 2876 if ( risSimple.test( qualifier ) ) {
Chris@0 2877 return jQuery.filter( qualifier, elements, not );
Chris@0 2878 }
Chris@0 2879
Chris@0 2880 // Complex selector, compare the two sets, removing non-Elements
Chris@0 2881 qualifier = jQuery.filter( qualifier, elements );
Chris@0 2882 return jQuery.grep( elements, function( elem ) {
Chris@0 2883 return ( indexOf.call( qualifier, elem ) > -1 ) !== not && elem.nodeType === 1;
Chris@0 2884 } );
Chris@0 2885 }
Chris@0 2886
Chris@0 2887 jQuery.filter = function( expr, elems, not ) {
Chris@0 2888 var elem = elems[ 0 ];
Chris@0 2889
Chris@0 2890 if ( not ) {
Chris@0 2891 expr = ":not(" + expr + ")";
Chris@0 2892 }
Chris@0 2893
Chris@0 2894 if ( elems.length === 1 && elem.nodeType === 1 ) {
Chris@0 2895 return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [];
Chris@0 2896 }
Chris@0 2897
Chris@0 2898 return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
Chris@0 2899 return elem.nodeType === 1;
Chris@0 2900 } ) );
Chris@0 2901 };
Chris@0 2902
Chris@0 2903 jQuery.fn.extend( {
Chris@0 2904 find: function( selector ) {
Chris@0 2905 var i, ret,
Chris@0 2906 len = this.length,
Chris@0 2907 self = this;
Chris@0 2908
Chris@0 2909 if ( typeof selector !== "string" ) {
Chris@0 2910 return this.pushStack( jQuery( selector ).filter( function() {
Chris@0 2911 for ( i = 0; i < len; i++ ) {
Chris@0 2912 if ( jQuery.contains( self[ i ], this ) ) {
Chris@0 2913 return true;
Chris@0 2914 }
Chris@0 2915 }
Chris@0 2916 } ) );
Chris@0 2917 }
Chris@0 2918
Chris@0 2919 ret = this.pushStack( [] );
Chris@0 2920
Chris@0 2921 for ( i = 0; i < len; i++ ) {
Chris@0 2922 jQuery.find( selector, self[ i ], ret );
Chris@0 2923 }
Chris@0 2924
Chris@0 2925 return len > 1 ? jQuery.uniqueSort( ret ) : ret;
Chris@0 2926 },
Chris@0 2927 filter: function( selector ) {
Chris@0 2928 return this.pushStack( winnow( this, selector || [], false ) );
Chris@0 2929 },
Chris@0 2930 not: function( selector ) {
Chris@0 2931 return this.pushStack( winnow( this, selector || [], true ) );
Chris@0 2932 },
Chris@0 2933 is: function( selector ) {
Chris@0 2934 return !!winnow(
Chris@0 2935 this,
Chris@0 2936
Chris@0 2937 // If this is a positional/relative selector, check membership in the returned set
Chris@0 2938 // so $("p:first").is("p:last") won't return true for a doc with two "p".
Chris@0 2939 typeof selector === "string" && rneedsContext.test( selector ) ?
Chris@0 2940 jQuery( selector ) :
Chris@0 2941 selector || [],
Chris@0 2942 false
Chris@0 2943 ).length;
Chris@0 2944 }
Chris@0 2945 } );
Chris@0 2946
Chris@0 2947
Chris@0 2948 // Initialize a jQuery object
Chris@0 2949
Chris@0 2950
Chris@0 2951 // A central reference to the root jQuery(document)
Chris@0 2952 var rootjQuery,
Chris@0 2953
Chris@0 2954 // A simple way to check for HTML strings
Chris@0 2955 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
Chris@0 2956 // Strict HTML recognition (#11290: must start with <)
Chris@0 2957 // Shortcut simple #id case for speed
Chris@0 2958 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
Chris@0 2959
Chris@0 2960 init = jQuery.fn.init = function( selector, context, root ) {
Chris@0 2961 var match, elem;
Chris@0 2962
Chris@0 2963 // HANDLE: $(""), $(null), $(undefined), $(false)
Chris@0 2964 if ( !selector ) {
Chris@0 2965 return this;
Chris@0 2966 }
Chris@0 2967
Chris@0 2968 // Method init() accepts an alternate rootjQuery
Chris@0 2969 // so migrate can support jQuery.sub (gh-2101)
Chris@0 2970 root = root || rootjQuery;
Chris@0 2971
Chris@0 2972 // Handle HTML strings
Chris@0 2973 if ( typeof selector === "string" ) {
Chris@0 2974 if ( selector[ 0 ] === "<" &&
Chris@0 2975 selector[ selector.length - 1 ] === ">" &&
Chris@0 2976 selector.length >= 3 ) {
Chris@0 2977
Chris@0 2978 // Assume that strings that start and end with <> are HTML and skip the regex check
Chris@0 2979 match = [ null, selector, null ];
Chris@0 2980
Chris@0 2981 } else {
Chris@0 2982 match = rquickExpr.exec( selector );
Chris@0 2983 }
Chris@0 2984
Chris@0 2985 // Match html or make sure no context is specified for #id
Chris@0 2986 if ( match && ( match[ 1 ] || !context ) ) {
Chris@0 2987
Chris@0 2988 // HANDLE: $(html) -> $(array)
Chris@0 2989 if ( match[ 1 ] ) {
Chris@0 2990 context = context instanceof jQuery ? context[ 0 ] : context;
Chris@0 2991
Chris@0 2992 // Option to run scripts is true for back-compat
Chris@0 2993 // Intentionally let the error be thrown if parseHTML is not present
Chris@0 2994 jQuery.merge( this, jQuery.parseHTML(
Chris@0 2995 match[ 1 ],
Chris@0 2996 context && context.nodeType ? context.ownerDocument || context : document,
Chris@0 2997 true
Chris@0 2998 ) );
Chris@0 2999
Chris@0 3000 // HANDLE: $(html, props)
Chris@0 3001 if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
Chris@0 3002 for ( match in context ) {
Chris@0 3003
Chris@0 3004 // Properties of context are called as methods if possible
Chris@0 3005 if ( jQuery.isFunction( this[ match ] ) ) {
Chris@0 3006 this[ match ]( context[ match ] );
Chris@0 3007
Chris@0 3008 // ...and otherwise set as attributes
Chris@0 3009 } else {
Chris@0 3010 this.attr( match, context[ match ] );
Chris@0 3011 }
Chris@0 3012 }
Chris@0 3013 }
Chris@0 3014
Chris@0 3015 return this;
Chris@0 3016
Chris@0 3017 // HANDLE: $(#id)
Chris@0 3018 } else {
Chris@0 3019 elem = document.getElementById( match[ 2 ] );
Chris@0 3020
Chris@0 3021 if ( elem ) {
Chris@0 3022
Chris@0 3023 // Inject the element directly into the jQuery object
Chris@0 3024 this[ 0 ] = elem;
Chris@0 3025 this.length = 1;
Chris@0 3026 }
Chris@0 3027 return this;
Chris@0 3028 }
Chris@0 3029
Chris@0 3030 // HANDLE: $(expr, $(...))
Chris@0 3031 } else if ( !context || context.jquery ) {
Chris@0 3032 return ( context || root ).find( selector );
Chris@0 3033
Chris@0 3034 // HANDLE: $(expr, context)
Chris@0 3035 // (which is just equivalent to: $(context).find(expr)
Chris@0 3036 } else {
Chris@0 3037 return this.constructor( context ).find( selector );
Chris@0 3038 }
Chris@0 3039
Chris@0 3040 // HANDLE: $(DOMElement)
Chris@0 3041 } else if ( selector.nodeType ) {
Chris@0 3042 this[ 0 ] = selector;
Chris@0 3043 this.length = 1;
Chris@0 3044 return this;
Chris@0 3045
Chris@0 3046 // HANDLE: $(function)
Chris@0 3047 // Shortcut for document ready
Chris@0 3048 } else if ( jQuery.isFunction( selector ) ) {
Chris@0 3049 return root.ready !== undefined ?
Chris@0 3050 root.ready( selector ) :
Chris@0 3051
Chris@0 3052 // Execute immediately if ready is not present
Chris@0 3053 selector( jQuery );
Chris@0 3054 }
Chris@0 3055
Chris@0 3056 return jQuery.makeArray( selector, this );
Chris@0 3057 };
Chris@0 3058
Chris@0 3059 // Give the init function the jQuery prototype for later instantiation
Chris@0 3060 init.prototype = jQuery.fn;
Chris@0 3061
Chris@0 3062 // Initialize central reference
Chris@0 3063 rootjQuery = jQuery( document );
Chris@0 3064
Chris@0 3065
Chris@0 3066 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
Chris@0 3067
Chris@0 3068 // Methods guaranteed to produce a unique set when starting from a unique set
Chris@0 3069 guaranteedUnique = {
Chris@0 3070 children: true,
Chris@0 3071 contents: true,
Chris@0 3072 next: true,
Chris@0 3073 prev: true
Chris@0 3074 };
Chris@0 3075
Chris@0 3076 jQuery.fn.extend( {
Chris@0 3077 has: function( target ) {
Chris@0 3078 var targets = jQuery( target, this ),
Chris@0 3079 l = targets.length;
Chris@0 3080
Chris@0 3081 return this.filter( function() {
Chris@0 3082 var i = 0;
Chris@0 3083 for ( ; i < l; i++ ) {
Chris@0 3084 if ( jQuery.contains( this, targets[ i ] ) ) {
Chris@0 3085 return true;
Chris@0 3086 }
Chris@0 3087 }
Chris@0 3088 } );
Chris@0 3089 },
Chris@0 3090
Chris@0 3091 closest: function( selectors, context ) {
Chris@0 3092 var cur,
Chris@0 3093 i = 0,
Chris@0 3094 l = this.length,
Chris@0 3095 matched = [],
Chris@0 3096 targets = typeof selectors !== "string" && jQuery( selectors );
Chris@0 3097
Chris@0 3098 // Positional selectors never match, since there's no _selection_ context
Chris@0 3099 if ( !rneedsContext.test( selectors ) ) {
Chris@0 3100 for ( ; i < l; i++ ) {
Chris@0 3101 for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
Chris@0 3102
Chris@0 3103 // Always skip document fragments
Chris@0 3104 if ( cur.nodeType < 11 && ( targets ?
Chris@0 3105 targets.index( cur ) > -1 :
Chris@0 3106
Chris@0 3107 // Don't pass non-elements to Sizzle
Chris@0 3108 cur.nodeType === 1 &&
Chris@0 3109 jQuery.find.matchesSelector( cur, selectors ) ) ) {
Chris@0 3110
Chris@0 3111 matched.push( cur );
Chris@0 3112 break;
Chris@0 3113 }
Chris@0 3114 }
Chris@0 3115 }
Chris@0 3116 }
Chris@0 3117
Chris@0 3118 return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
Chris@0 3119 },
Chris@0 3120
Chris@0 3121 // Determine the position of an element within the set
Chris@0 3122 index: function( elem ) {
Chris@0 3123
Chris@0 3124 // No argument, return index in parent
Chris@0 3125 if ( !elem ) {
Chris@0 3126 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
Chris@0 3127 }
Chris@0 3128
Chris@0 3129 // Index in selector
Chris@0 3130 if ( typeof elem === "string" ) {
Chris@0 3131 return indexOf.call( jQuery( elem ), this[ 0 ] );
Chris@0 3132 }
Chris@0 3133
Chris@0 3134 // Locate the position of the desired element
Chris@0 3135 return indexOf.call( this,
Chris@0 3136
Chris@0 3137 // If it receives a jQuery object, the first element is used
Chris@0 3138 elem.jquery ? elem[ 0 ] : elem
Chris@0 3139 );
Chris@0 3140 },
Chris@0 3141
Chris@0 3142 add: function( selector, context ) {
Chris@0 3143 return this.pushStack(
Chris@0 3144 jQuery.uniqueSort(
Chris@0 3145 jQuery.merge( this.get(), jQuery( selector, context ) )
Chris@0 3146 )
Chris@0 3147 );
Chris@0 3148 },
Chris@0 3149
Chris@0 3150 addBack: function( selector ) {
Chris@0 3151 return this.add( selector == null ?
Chris@0 3152 this.prevObject : this.prevObject.filter( selector )
Chris@0 3153 );
Chris@0 3154 }
Chris@0 3155 } );
Chris@0 3156
Chris@0 3157 function sibling( cur, dir ) {
Chris@0 3158 while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
Chris@0 3159 return cur;
Chris@0 3160 }
Chris@0 3161
Chris@0 3162 jQuery.each( {
Chris@0 3163 parent: function( elem ) {
Chris@0 3164 var parent = elem.parentNode;
Chris@0 3165 return parent && parent.nodeType !== 11 ? parent : null;
Chris@0 3166 },
Chris@0 3167 parents: function( elem ) {
Chris@0 3168 return dir( elem, "parentNode" );
Chris@0 3169 },
Chris@0 3170 parentsUntil: function( elem, i, until ) {
Chris@0 3171 return dir( elem, "parentNode", until );
Chris@0 3172 },
Chris@0 3173 next: function( elem ) {
Chris@0 3174 return sibling( elem, "nextSibling" );
Chris@0 3175 },
Chris@0 3176 prev: function( elem ) {
Chris@0 3177 return sibling( elem, "previousSibling" );
Chris@0 3178 },
Chris@0 3179 nextAll: function( elem ) {
Chris@0 3180 return dir( elem, "nextSibling" );
Chris@0 3181 },
Chris@0 3182 prevAll: function( elem ) {
Chris@0 3183 return dir( elem, "previousSibling" );
Chris@0 3184 },
Chris@0 3185 nextUntil: function( elem, i, until ) {
Chris@0 3186 return dir( elem, "nextSibling", until );
Chris@0 3187 },
Chris@0 3188 prevUntil: function( elem, i, until ) {
Chris@0 3189 return dir( elem, "previousSibling", until );
Chris@0 3190 },
Chris@0 3191 siblings: function( elem ) {
Chris@0 3192 return siblings( ( elem.parentNode || {} ).firstChild, elem );
Chris@0 3193 },
Chris@0 3194 children: function( elem ) {
Chris@0 3195 return siblings( elem.firstChild );
Chris@0 3196 },
Chris@0 3197 contents: function( elem ) {
Chris@0 3198 if ( nodeName( elem, "iframe" ) ) {
Chris@0 3199 return elem.contentDocument;
Chris@0 3200 }
Chris@0 3201
Chris@0 3202 // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
Chris@0 3203 // Treat the template element as a regular one in browsers that
Chris@0 3204 // don't support it.
Chris@0 3205 if ( nodeName( elem, "template" ) ) {
Chris@0 3206 elem = elem.content || elem;
Chris@0 3207 }
Chris@0 3208
Chris@0 3209 return jQuery.merge( [], elem.childNodes );
Chris@0 3210 }
Chris@0 3211 }, function( name, fn ) {
Chris@0 3212 jQuery.fn[ name ] = function( until, selector ) {
Chris@0 3213 var matched = jQuery.map( this, fn, until );
Chris@0 3214
Chris@0 3215 if ( name.slice( -5 ) !== "Until" ) {
Chris@0 3216 selector = until;
Chris@0 3217 }
Chris@0 3218
Chris@0 3219 if ( selector && typeof selector === "string" ) {
Chris@0 3220 matched = jQuery.filter( selector, matched );
Chris@0 3221 }
Chris@0 3222
Chris@0 3223 if ( this.length > 1 ) {
Chris@0 3224
Chris@0 3225 // Remove duplicates
Chris@0 3226 if ( !guaranteedUnique[ name ] ) {
Chris@0 3227 jQuery.uniqueSort( matched );
Chris@0 3228 }
Chris@0 3229
Chris@0 3230 // Reverse order for parents* and prev-derivatives
Chris@0 3231 if ( rparentsprev.test( name ) ) {
Chris@0 3232 matched.reverse();
Chris@0 3233 }
Chris@0 3234 }
Chris@0 3235
Chris@0 3236 return this.pushStack( matched );
Chris@0 3237 };
Chris@0 3238 } );
Chris@0 3239 var rnothtmlwhite = ( /[^\x20\t\r\n\f]+/g );
Chris@0 3240
Chris@0 3241
Chris@0 3242
Chris@0 3243 // Convert String-formatted options into Object-formatted ones
Chris@0 3244 function createOptions( options ) {
Chris@0 3245 var object = {};
Chris@0 3246 jQuery.each( options.match( rnothtmlwhite ) || [], function( _, flag ) {
Chris@0 3247 object[ flag ] = true;
Chris@0 3248 } );
Chris@0 3249 return object;
Chris@0 3250 }
Chris@0 3251
Chris@0 3252 /*
Chris@0 3253 * Create a callback list using the following parameters:
Chris@0 3254 *
Chris@0 3255 * options: an optional list of space-separated options that will change how
Chris@0 3256 * the callback list behaves or a more traditional option object
Chris@0 3257 *
Chris@0 3258 * By default a callback list will act like an event callback list and can be
Chris@0 3259 * "fired" multiple times.
Chris@0 3260 *
Chris@0 3261 * Possible options:
Chris@0 3262 *
Chris@0 3263 * once: will ensure the callback list can only be fired once (like a Deferred)
Chris@0 3264 *
Chris@0 3265 * memory: will keep track of previous values and will call any callback added
Chris@0 3266 * after the list has been fired right away with the latest "memorized"
Chris@0 3267 * values (like a Deferred)
Chris@0 3268 *
Chris@0 3269 * unique: will ensure a callback can only be added once (no duplicate in the list)
Chris@0 3270 *
Chris@0 3271 * stopOnFalse: interrupt callings when a callback returns false
Chris@0 3272 *
Chris@0 3273 */
Chris@0 3274 jQuery.Callbacks = function( options ) {
Chris@0 3275
Chris@0 3276 // Convert options from String-formatted to Object-formatted if needed
Chris@0 3277 // (we check in cache first)
Chris@0 3278 options = typeof options === "string" ?
Chris@0 3279 createOptions( options ) :
Chris@0 3280 jQuery.extend( {}, options );
Chris@0 3281
Chris@0 3282 var // Flag to know if list is currently firing
Chris@0 3283 firing,
Chris@0 3284
Chris@0 3285 // Last fire value for non-forgettable lists
Chris@0 3286 memory,
Chris@0 3287
Chris@0 3288 // Flag to know if list was already fired
Chris@0 3289 fired,
Chris@0 3290
Chris@0 3291 // Flag to prevent firing
Chris@0 3292 locked,
Chris@0 3293
Chris@0 3294 // Actual callback list
Chris@0 3295 list = [],
Chris@0 3296
Chris@0 3297 // Queue of execution data for repeatable lists
Chris@0 3298 queue = [],
Chris@0 3299
Chris@0 3300 // Index of currently firing callback (modified by add/remove as needed)
Chris@0 3301 firingIndex = -1,
Chris@0 3302
Chris@0 3303 // Fire callbacks
Chris@0 3304 fire = function() {
Chris@0 3305
Chris@0 3306 // Enforce single-firing
Chris@0 3307 locked = locked || options.once;
Chris@0 3308
Chris@0 3309 // Execute callbacks for all pending executions,
Chris@0 3310 // respecting firingIndex overrides and runtime changes
Chris@0 3311 fired = firing = true;
Chris@0 3312 for ( ; queue.length; firingIndex = -1 ) {
Chris@0 3313 memory = queue.shift();
Chris@0 3314 while ( ++firingIndex < list.length ) {
Chris@0 3315
Chris@0 3316 // Run callback and check for early termination
Chris@0 3317 if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false &&
Chris@0 3318 options.stopOnFalse ) {
Chris@0 3319
Chris@0 3320 // Jump to end and forget the data so .add doesn't re-fire
Chris@0 3321 firingIndex = list.length;
Chris@0 3322 memory = false;
Chris@0 3323 }
Chris@0 3324 }
Chris@0 3325 }
Chris@0 3326
Chris@0 3327 // Forget the data if we're done with it
Chris@0 3328 if ( !options.memory ) {
Chris@0 3329 memory = false;
Chris@0 3330 }
Chris@0 3331
Chris@0 3332 firing = false;
Chris@0 3333
Chris@0 3334 // Clean up if we're done firing for good
Chris@0 3335 if ( locked ) {
Chris@0 3336
Chris@0 3337 // Keep an empty list if we have data for future add calls
Chris@0 3338 if ( memory ) {
Chris@0 3339 list = [];
Chris@0 3340
Chris@0 3341 // Otherwise, this object is spent
Chris@0 3342 } else {
Chris@0 3343 list = "";
Chris@0 3344 }
Chris@0 3345 }
Chris@0 3346 },
Chris@0 3347
Chris@0 3348 // Actual Callbacks object
Chris@0 3349 self = {
Chris@0 3350
Chris@0 3351 // Add a callback or a collection of callbacks to the list
Chris@0 3352 add: function() {
Chris@0 3353 if ( list ) {
Chris@0 3354
Chris@0 3355 // If we have memory from a past run, we should fire after adding
Chris@0 3356 if ( memory && !firing ) {
Chris@0 3357 firingIndex = list.length - 1;
Chris@0 3358 queue.push( memory );
Chris@0 3359 }
Chris@0 3360
Chris@0 3361 ( function add( args ) {
Chris@0 3362 jQuery.each( args, function( _, arg ) {
Chris@0 3363 if ( jQuery.isFunction( arg ) ) {
Chris@0 3364 if ( !options.unique || !self.has( arg ) ) {
Chris@0 3365 list.push( arg );
Chris@0 3366 }
Chris@0 3367 } else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) {
Chris@0 3368
Chris@0 3369 // Inspect recursively
Chris@0 3370 add( arg );
Chris@0 3371 }
Chris@0 3372 } );
Chris@0 3373 } )( arguments );
Chris@0 3374
Chris@0 3375 if ( memory && !firing ) {
Chris@0 3376 fire();
Chris@0 3377 }
Chris@0 3378 }
Chris@0 3379 return this;
Chris@0 3380 },
Chris@0 3381
Chris@0 3382 // Remove a callback from the list
Chris@0 3383 remove: function() {
Chris@0 3384 jQuery.each( arguments, function( _, arg ) {
Chris@0 3385 var index;
Chris@0 3386 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
Chris@0 3387 list.splice( index, 1 );
Chris@0 3388
Chris@0 3389 // Handle firing indexes
Chris@0 3390 if ( index <= firingIndex ) {
Chris@0 3391 firingIndex--;
Chris@0 3392 }
Chris@0 3393 }
Chris@0 3394 } );
Chris@0 3395 return this;
Chris@0 3396 },
Chris@0 3397
Chris@0 3398 // Check if a given callback is in the list.
Chris@0 3399 // If no argument is given, return whether or not list has callbacks attached.
Chris@0 3400 has: function( fn ) {
Chris@0 3401 return fn ?
Chris@0 3402 jQuery.inArray( fn, list ) > -1 :
Chris@0 3403 list.length > 0;
Chris@0 3404 },
Chris@0 3405
Chris@0 3406 // Remove all callbacks from the list
Chris@0 3407 empty: function() {
Chris@0 3408 if ( list ) {
Chris@0 3409 list = [];
Chris@0 3410 }
Chris@0 3411 return this;
Chris@0 3412 },
Chris@0 3413
Chris@0 3414 // Disable .fire and .add
Chris@0 3415 // Abort any current/pending executions
Chris@0 3416 // Clear all callbacks and values
Chris@0 3417 disable: function() {
Chris@0 3418 locked = queue = [];
Chris@0 3419 list = memory = "";
Chris@0 3420 return this;
Chris@0 3421 },
Chris@0 3422 disabled: function() {
Chris@0 3423 return !list;
Chris@0 3424 },
Chris@0 3425
Chris@0 3426 // Disable .fire
Chris@0 3427 // Also disable .add unless we have memory (since it would have no effect)
Chris@0 3428 // Abort any pending executions
Chris@0 3429 lock: function() {
Chris@0 3430 locked = queue = [];
Chris@0 3431 if ( !memory && !firing ) {
Chris@0 3432 list = memory = "";
Chris@0 3433 }
Chris@0 3434 return this;
Chris@0 3435 },
Chris@0 3436 locked: function() {
Chris@0 3437 return !!locked;
Chris@0 3438 },
Chris@0 3439
Chris@0 3440 // Call all callbacks with the given context and arguments
Chris@0 3441 fireWith: function( context, args ) {
Chris@0 3442 if ( !locked ) {
Chris@0 3443 args = args || [];
Chris@0 3444 args = [ context, args.slice ? args.slice() : args ];
Chris@0 3445 queue.push( args );
Chris@0 3446 if ( !firing ) {
Chris@0 3447 fire();
Chris@0 3448 }
Chris@0 3449 }
Chris@0 3450 return this;
Chris@0 3451 },
Chris@0 3452
Chris@0 3453 // Call all the callbacks with the given arguments
Chris@0 3454 fire: function() {
Chris@0 3455 self.fireWith( this, arguments );
Chris@0 3456 return this;
Chris@0 3457 },
Chris@0 3458
Chris@0 3459 // To know if the callbacks have already been called at least once
Chris@0 3460 fired: function() {
Chris@0 3461 return !!fired;
Chris@0 3462 }
Chris@0 3463 };
Chris@0 3464
Chris@0 3465 return self;
Chris@0 3466 };
Chris@0 3467
Chris@0 3468
Chris@0 3469 function Identity( v ) {
Chris@0 3470 return v;
Chris@0 3471 }
Chris@0 3472 function Thrower( ex ) {
Chris@0 3473 throw ex;
Chris@0 3474 }
Chris@0 3475
Chris@0 3476 function adoptValue( value, resolve, reject, noValue ) {
Chris@0 3477 var method;
Chris@0 3478
Chris@0 3479 try {
Chris@0 3480
Chris@0 3481 // Check for promise aspect first to privilege synchronous behavior
Chris@0 3482 if ( value && jQuery.isFunction( ( method = value.promise ) ) ) {
Chris@0 3483 method.call( value ).done( resolve ).fail( reject );
Chris@0 3484
Chris@0 3485 // Other thenables
Chris@0 3486 } else if ( value && jQuery.isFunction( ( method = value.then ) ) ) {
Chris@0 3487 method.call( value, resolve, reject );
Chris@0 3488
Chris@0 3489 // Other non-thenables
Chris@0 3490 } else {
Chris@0 3491
Chris@0 3492 // Control `resolve` arguments by letting Array#slice cast boolean `noValue` to integer:
Chris@0 3493 // * false: [ value ].slice( 0 ) => resolve( value )
Chris@0 3494 // * true: [ value ].slice( 1 ) => resolve()
Chris@0 3495 resolve.apply( undefined, [ value ].slice( noValue ) );
Chris@0 3496 }
Chris@0 3497
Chris@0 3498 // For Promises/A+, convert exceptions into rejections
Chris@0 3499 // Since jQuery.when doesn't unwrap thenables, we can skip the extra checks appearing in
Chris@0 3500 // Deferred#then to conditionally suppress rejection.
Chris@0 3501 } catch ( value ) {
Chris@0 3502
Chris@0 3503 // Support: Android 4.0 only
Chris@0 3504 // Strict mode functions invoked without .call/.apply get global-object context
Chris@0 3505 reject.apply( undefined, [ value ] );
Chris@0 3506 }
Chris@0 3507 }
Chris@0 3508
Chris@0 3509 jQuery.extend( {
Chris@0 3510
Chris@0 3511 Deferred: function( func ) {
Chris@0 3512 var tuples = [
Chris@0 3513
Chris@0 3514 // action, add listener, callbacks,
Chris@0 3515 // ... .then handlers, argument index, [final state]
Chris@0 3516 [ "notify", "progress", jQuery.Callbacks( "memory" ),
Chris@0 3517 jQuery.Callbacks( "memory" ), 2 ],
Chris@0 3518 [ "resolve", "done", jQuery.Callbacks( "once memory" ),
Chris@0 3519 jQuery.Callbacks( "once memory" ), 0, "resolved" ],
Chris@0 3520 [ "reject", "fail", jQuery.Callbacks( "once memory" ),
Chris@0 3521 jQuery.Callbacks( "once memory" ), 1, "rejected" ]
Chris@0 3522 ],
Chris@0 3523 state = "pending",
Chris@0 3524 promise = {
Chris@0 3525 state: function() {
Chris@0 3526 return state;
Chris@0 3527 },
Chris@0 3528 always: function() {
Chris@0 3529 deferred.done( arguments ).fail( arguments );
Chris@0 3530 return this;
Chris@0 3531 },
Chris@0 3532 "catch": function( fn ) {
Chris@0 3533 return promise.then( null, fn );
Chris@0 3534 },
Chris@0 3535
Chris@0 3536 // Keep pipe for back-compat
Chris@0 3537 pipe: function( /* fnDone, fnFail, fnProgress */ ) {
Chris@0 3538 var fns = arguments;
Chris@0 3539
Chris@0 3540 return jQuery.Deferred( function( newDefer ) {
Chris@0 3541 jQuery.each( tuples, function( i, tuple ) {
Chris@0 3542
Chris@0 3543 // Map tuples (progress, done, fail) to arguments (done, fail, progress)
Chris@0 3544 var fn = jQuery.isFunction( fns[ tuple[ 4 ] ] ) && fns[ tuple[ 4 ] ];
Chris@0 3545
Chris@0 3546 // deferred.progress(function() { bind to newDefer or newDefer.notify })
Chris@0 3547 // deferred.done(function() { bind to newDefer or newDefer.resolve })
Chris@0 3548 // deferred.fail(function() { bind to newDefer or newDefer.reject })
Chris@0 3549 deferred[ tuple[ 1 ] ]( function() {
Chris@0 3550 var returned = fn && fn.apply( this, arguments );
Chris@0 3551 if ( returned && jQuery.isFunction( returned.promise ) ) {
Chris@0 3552 returned.promise()
Chris@0 3553 .progress( newDefer.notify )
Chris@0 3554 .done( newDefer.resolve )
Chris@0 3555 .fail( newDefer.reject );
Chris@0 3556 } else {
Chris@0 3557 newDefer[ tuple[ 0 ] + "With" ](
Chris@0 3558 this,
Chris@0 3559 fn ? [ returned ] : arguments
Chris@0 3560 );
Chris@0 3561 }
Chris@0 3562 } );
Chris@0 3563 } );
Chris@0 3564 fns = null;
Chris@0 3565 } ).promise();
Chris@0 3566 },
Chris@0 3567 then: function( onFulfilled, onRejected, onProgress ) {
Chris@0 3568 var maxDepth = 0;
Chris@0 3569 function resolve( depth, deferred, handler, special ) {
Chris@0 3570 return function() {
Chris@0 3571 var that = this,
Chris@0 3572 args = arguments,
Chris@0 3573 mightThrow = function() {
Chris@0 3574 var returned, then;
Chris@0 3575
Chris@0 3576 // Support: Promises/A+ section 2.3.3.3.3
Chris@0 3577 // https://promisesaplus.com/#point-59
Chris@0 3578 // Ignore double-resolution attempts
Chris@0 3579 if ( depth < maxDepth ) {
Chris@0 3580 return;
Chris@0 3581 }
Chris@0 3582
Chris@0 3583 returned = handler.apply( that, args );
Chris@0 3584
Chris@0 3585 // Support: Promises/A+ section 2.3.1
Chris@0 3586 // https://promisesaplus.com/#point-48
Chris@0 3587 if ( returned === deferred.promise() ) {
Chris@0 3588 throw new TypeError( "Thenable self-resolution" );
Chris@0 3589 }
Chris@0 3590
Chris@0 3591 // Support: Promises/A+ sections 2.3.3.1, 3.5
Chris@0 3592 // https://promisesaplus.com/#point-54
Chris@0 3593 // https://promisesaplus.com/#point-75
Chris@0 3594 // Retrieve `then` only once
Chris@0 3595 then = returned &&
Chris@0 3596
Chris@0 3597 // Support: Promises/A+ section 2.3.4
Chris@0 3598 // https://promisesaplus.com/#point-64
Chris@0 3599 // Only check objects and functions for thenability
Chris@0 3600 ( typeof returned === "object" ||
Chris@0 3601 typeof returned === "function" ) &&
Chris@0 3602 returned.then;
Chris@0 3603
Chris@0 3604 // Handle a returned thenable
Chris@0 3605 if ( jQuery.isFunction( then ) ) {
Chris@0 3606
Chris@0 3607 // Special processors (notify) just wait for resolution
Chris@0 3608 if ( special ) {
Chris@0 3609 then.call(
Chris@0 3610 returned,
Chris@0 3611 resolve( maxDepth, deferred, Identity, special ),
Chris@0 3612 resolve( maxDepth, deferred, Thrower, special )
Chris@0 3613 );
Chris@0 3614
Chris@0 3615 // Normal processors (resolve) also hook into progress
Chris@0 3616 } else {
Chris@0 3617
Chris@0 3618 // ...and disregard older resolution values
Chris@0 3619 maxDepth++;
Chris@0 3620
Chris@0 3621 then.call(
Chris@0 3622 returned,
Chris@0 3623 resolve( maxDepth, deferred, Identity, special ),
Chris@0 3624 resolve( maxDepth, deferred, Thrower, special ),
Chris@0 3625 resolve( maxDepth, deferred, Identity,
Chris@0 3626 deferred.notifyWith )
Chris@0 3627 );
Chris@0 3628 }
Chris@0 3629
Chris@0 3630 // Handle all other returned values
Chris@0 3631 } else {
Chris@0 3632
Chris@0 3633 // Only substitute handlers pass on context
Chris@0 3634 // and multiple values (non-spec behavior)
Chris@0 3635 if ( handler !== Identity ) {
Chris@0 3636 that = undefined;
Chris@0 3637 args = [ returned ];
Chris@0 3638 }
Chris@0 3639
Chris@0 3640 // Process the value(s)
Chris@0 3641 // Default process is resolve
Chris@0 3642 ( special || deferred.resolveWith )( that, args );
Chris@0 3643 }
Chris@0 3644 },
Chris@0 3645
Chris@0 3646 // Only normal processors (resolve) catch and reject exceptions
Chris@0 3647 process = special ?
Chris@0 3648 mightThrow :
Chris@0 3649 function() {
Chris@0 3650 try {
Chris@0 3651 mightThrow();
Chris@0 3652 } catch ( e ) {
Chris@0 3653
Chris@0 3654 if ( jQuery.Deferred.exceptionHook ) {
Chris@0 3655 jQuery.Deferred.exceptionHook( e,
Chris@0 3656 process.stackTrace );
Chris@0 3657 }
Chris@0 3658
Chris@0 3659 // Support: Promises/A+ section 2.3.3.3.4.1
Chris@0 3660 // https://promisesaplus.com/#point-61
Chris@0 3661 // Ignore post-resolution exceptions
Chris@0 3662 if ( depth + 1 >= maxDepth ) {
Chris@0 3663
Chris@0 3664 // Only substitute handlers pass on context
Chris@0 3665 // and multiple values (non-spec behavior)
Chris@0 3666 if ( handler !== Thrower ) {
Chris@0 3667 that = undefined;
Chris@0 3668 args = [ e ];
Chris@0 3669 }
Chris@0 3670
Chris@0 3671 deferred.rejectWith( that, args );
Chris@0 3672 }
Chris@0 3673 }
Chris@0 3674 };
Chris@0 3675
Chris@0 3676 // Support: Promises/A+ section 2.3.3.3.1
Chris@0 3677 // https://promisesaplus.com/#point-57
Chris@0 3678 // Re-resolve promises immediately to dodge false rejection from
Chris@0 3679 // subsequent errors
Chris@0 3680 if ( depth ) {
Chris@0 3681 process();
Chris@0 3682 } else {
Chris@0 3683
Chris@0 3684 // Call an optional hook to record the stack, in case of exception
Chris@0 3685 // since it's otherwise lost when execution goes async
Chris@0 3686 if ( jQuery.Deferred.getStackHook ) {
Chris@0 3687 process.stackTrace = jQuery.Deferred.getStackHook();
Chris@0 3688 }
Chris@0 3689 window.setTimeout( process );
Chris@0 3690 }
Chris@0 3691 };
Chris@0 3692 }
Chris@0 3693
Chris@0 3694 return jQuery.Deferred( function( newDefer ) {
Chris@0 3695
Chris@0 3696 // progress_handlers.add( ... )
Chris@0 3697 tuples[ 0 ][ 3 ].add(
Chris@0 3698 resolve(
Chris@0 3699 0,
Chris@0 3700 newDefer,
Chris@0 3701 jQuery.isFunction( onProgress ) ?
Chris@0 3702 onProgress :
Chris@0 3703 Identity,
Chris@0 3704 newDefer.notifyWith
Chris@0 3705 )
Chris@0 3706 );
Chris@0 3707
Chris@0 3708 // fulfilled_handlers.add( ... )
Chris@0 3709 tuples[ 1 ][ 3 ].add(
Chris@0 3710 resolve(
Chris@0 3711 0,
Chris@0 3712 newDefer,
Chris@0 3713 jQuery.isFunction( onFulfilled ) ?
Chris@0 3714 onFulfilled :
Chris@0 3715 Identity
Chris@0 3716 )
Chris@0 3717 );
Chris@0 3718
Chris@0 3719 // rejected_handlers.add( ... )
Chris@0 3720 tuples[ 2 ][ 3 ].add(
Chris@0 3721 resolve(
Chris@0 3722 0,
Chris@0 3723 newDefer,
Chris@0 3724 jQuery.isFunction( onRejected ) ?
Chris@0 3725 onRejected :
Chris@0 3726 Thrower
Chris@0 3727 )
Chris@0 3728 );
Chris@0 3729 } ).promise();
Chris@0 3730 },
Chris@0 3731
Chris@0 3732 // Get a promise for this deferred
Chris@0 3733 // If obj is provided, the promise aspect is added to the object
Chris@0 3734 promise: function( obj ) {
Chris@0 3735 return obj != null ? jQuery.extend( obj, promise ) : promise;
Chris@0 3736 }
Chris@0 3737 },
Chris@0 3738 deferred = {};
Chris@0 3739
Chris@0 3740 // Add list-specific methods
Chris@0 3741 jQuery.each( tuples, function( i, tuple ) {
Chris@0 3742 var list = tuple[ 2 ],
Chris@0 3743 stateString = tuple[ 5 ];
Chris@0 3744
Chris@0 3745 // promise.progress = list.add
Chris@0 3746 // promise.done = list.add
Chris@0 3747 // promise.fail = list.add
Chris@0 3748 promise[ tuple[ 1 ] ] = list.add;
Chris@0 3749
Chris@0 3750 // Handle state
Chris@0 3751 if ( stateString ) {
Chris@0 3752 list.add(
Chris@0 3753 function() {
Chris@0 3754
Chris@0 3755 // state = "resolved" (i.e., fulfilled)
Chris@0 3756 // state = "rejected"
Chris@0 3757 state = stateString;
Chris@0 3758 },
Chris@0 3759
Chris@0 3760 // rejected_callbacks.disable
Chris@0 3761 // fulfilled_callbacks.disable
Chris@0 3762 tuples[ 3 - i ][ 2 ].disable,
Chris@0 3763
Chris@0 3764 // progress_callbacks.lock
Chris@0 3765 tuples[ 0 ][ 2 ].lock
Chris@0 3766 );
Chris@0 3767 }
Chris@0 3768
Chris@0 3769 // progress_handlers.fire
Chris@0 3770 // fulfilled_handlers.fire
Chris@0 3771 // rejected_handlers.fire
Chris@0 3772 list.add( tuple[ 3 ].fire );
Chris@0 3773
Chris@0 3774 // deferred.notify = function() { deferred.notifyWith(...) }
Chris@0 3775 // deferred.resolve = function() { deferred.resolveWith(...) }
Chris@0 3776 // deferred.reject = function() { deferred.rejectWith(...) }
Chris@0 3777 deferred[ tuple[ 0 ] ] = function() {
Chris@0 3778 deferred[ tuple[ 0 ] + "With" ]( this === deferred ? undefined : this, arguments );
Chris@0 3779 return this;
Chris@0 3780 };
Chris@0 3781
Chris@0 3782 // deferred.notifyWith = list.fireWith
Chris@0 3783 // deferred.resolveWith = list.fireWith
Chris@0 3784 // deferred.rejectWith = list.fireWith
Chris@0 3785 deferred[ tuple[ 0 ] + "With" ] = list.fireWith;
Chris@0 3786 } );
Chris@0 3787
Chris@0 3788 // Make the deferred a promise
Chris@0 3789 promise.promise( deferred );
Chris@0 3790
Chris@0 3791 // Call given func if any
Chris@0 3792 if ( func ) {
Chris@0 3793 func.call( deferred, deferred );
Chris@0 3794 }
Chris@0 3795
Chris@0 3796 // All done!
Chris@0 3797 return deferred;
Chris@0 3798 },
Chris@0 3799
Chris@0 3800 // Deferred helper
Chris@0 3801 when: function( singleValue ) {
Chris@0 3802 var
Chris@0 3803
Chris@0 3804 // count of uncompleted subordinates
Chris@0 3805 remaining = arguments.length,
Chris@0 3806
Chris@0 3807 // count of unprocessed arguments
Chris@0 3808 i = remaining,
Chris@0 3809
Chris@0 3810 // subordinate fulfillment data
Chris@0 3811 resolveContexts = Array( i ),
Chris@0 3812 resolveValues = slice.call( arguments ),
Chris@0 3813
Chris@0 3814 // the master Deferred
Chris@0 3815 master = jQuery.Deferred(),
Chris@0 3816
Chris@0 3817 // subordinate callback factory
Chris@0 3818 updateFunc = function( i ) {
Chris@0 3819 return function( value ) {
Chris@0 3820 resolveContexts[ i ] = this;
Chris@0 3821 resolveValues[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
Chris@0 3822 if ( !( --remaining ) ) {
Chris@0 3823 master.resolveWith( resolveContexts, resolveValues );
Chris@0 3824 }
Chris@0 3825 };
Chris@0 3826 };
Chris@0 3827
Chris@0 3828 // Single- and empty arguments are adopted like Promise.resolve
Chris@0 3829 if ( remaining <= 1 ) {
Chris@0 3830 adoptValue( singleValue, master.done( updateFunc( i ) ).resolve, master.reject,
Chris@0 3831 !remaining );
Chris@0 3832
Chris@0 3833 // Use .then() to unwrap secondary thenables (cf. gh-3000)
Chris@0 3834 if ( master.state() === "pending" ||
Chris@0 3835 jQuery.isFunction( resolveValues[ i ] && resolveValues[ i ].then ) ) {
Chris@0 3836
Chris@0 3837 return master.then();
Chris@0 3838 }
Chris@0 3839 }
Chris@0 3840
Chris@0 3841 // Multiple arguments are aggregated like Promise.all array elements
Chris@0 3842 while ( i-- ) {
Chris@0 3843 adoptValue( resolveValues[ i ], updateFunc( i ), master.reject );
Chris@0 3844 }
Chris@0 3845
Chris@0 3846 return master.promise();
Chris@0 3847 }
Chris@0 3848 } );
Chris@0 3849
Chris@0 3850
Chris@0 3851 // These usually indicate a programmer mistake during development,
Chris@0 3852 // warn about them ASAP rather than swallowing them by default.
Chris@0 3853 var rerrorNames = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
Chris@0 3854
Chris@0 3855 jQuery.Deferred.exceptionHook = function( error, stack ) {
Chris@0 3856
Chris@0 3857 // Support: IE 8 - 9 only
Chris@0 3858 // Console exists when dev tools are open, which can happen at any time
Chris@0 3859 if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {
Chris@0 3860 window.console.warn( "jQuery.Deferred exception: " + error.message, error.stack, stack );
Chris@0 3861 }
Chris@0 3862 };
Chris@0 3863
Chris@0 3864
Chris@0 3865
Chris@0 3866
Chris@0 3867 jQuery.readyException = function( error ) {
Chris@0 3868 window.setTimeout( function() {
Chris@0 3869 throw error;
Chris@0 3870 } );
Chris@0 3871 };
Chris@0 3872
Chris@0 3873
Chris@0 3874
Chris@0 3875
Chris@0 3876 // The deferred used on DOM ready
Chris@0 3877 var readyList = jQuery.Deferred();
Chris@0 3878
Chris@0 3879 jQuery.fn.ready = function( fn ) {
Chris@0 3880
Chris@0 3881 readyList
Chris@0 3882 .then( fn )
Chris@0 3883
Chris@0 3884 // Wrap jQuery.readyException in a function so that the lookup
Chris@0 3885 // happens at the time of error handling instead of callback
Chris@0 3886 // registration.
Chris@0 3887 .catch( function( error ) {
Chris@0 3888 jQuery.readyException( error );
Chris@0 3889 } );
Chris@0 3890
Chris@0 3891 return this;
Chris@0 3892 };
Chris@0 3893
Chris@0 3894 jQuery.extend( {
Chris@0 3895
Chris@0 3896 // Is the DOM ready to be used? Set to true once it occurs.
Chris@0 3897 isReady: false,
Chris@0 3898
Chris@0 3899 // A counter to track how many items to wait for before
Chris@0 3900 // the ready event fires. See #6781
Chris@0 3901 readyWait: 1,
Chris@0 3902
Chris@0 3903 // Handle when the DOM is ready
Chris@0 3904 ready: function( wait ) {
Chris@0 3905
Chris@0 3906 // Abort if there are pending holds or we're already ready
Chris@0 3907 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
Chris@0 3908 return;
Chris@0 3909 }
Chris@0 3910
Chris@0 3911 // Remember that the DOM is ready
Chris@0 3912 jQuery.isReady = true;
Chris@0 3913
Chris@0 3914 // If a normal DOM Ready event fired, decrement, and wait if need be
Chris@0 3915 if ( wait !== true && --jQuery.readyWait > 0 ) {
Chris@0 3916 return;
Chris@0 3917 }
Chris@0 3918
Chris@0 3919 // If there are functions bound, to execute
Chris@0 3920 readyList.resolveWith( document, [ jQuery ] );
Chris@0 3921 }
Chris@0 3922 } );
Chris@0 3923
Chris@0 3924 jQuery.ready.then = readyList.then;
Chris@0 3925
Chris@0 3926 // The ready event handler and self cleanup method
Chris@0 3927 function completed() {
Chris@0 3928 document.removeEventListener( "DOMContentLoaded", completed );
Chris@0 3929 window.removeEventListener( "load", completed );
Chris@0 3930 jQuery.ready();
Chris@0 3931 }
Chris@0 3932
Chris@0 3933 // Catch cases where $(document).ready() is called
Chris@0 3934 // after the browser event has already occurred.
Chris@0 3935 // Support: IE <=9 - 10 only
Chris@0 3936 // Older IE sometimes signals "interactive" too soon
Chris@0 3937 if ( document.readyState === "complete" ||
Chris@0 3938 ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
Chris@0 3939
Chris@0 3940 // Handle it asynchronously to allow scripts the opportunity to delay ready
Chris@0 3941 window.setTimeout( jQuery.ready );
Chris@0 3942
Chris@0 3943 } else {
Chris@0 3944
Chris@0 3945 // Use the handy event callback
Chris@0 3946 document.addEventListener( "DOMContentLoaded", completed );
Chris@0 3947
Chris@0 3948 // A fallback to window.onload, that will always work
Chris@0 3949 window.addEventListener( "load", completed );
Chris@0 3950 }
Chris@0 3951
Chris@0 3952
Chris@0 3953
Chris@0 3954
Chris@0 3955 // Multifunctional method to get and set values of a collection
Chris@0 3956 // The value/s can optionally be executed if it's a function
Chris@0 3957 var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
Chris@0 3958 var i = 0,
Chris@0 3959 len = elems.length,
Chris@0 3960 bulk = key == null;
Chris@0 3961
Chris@0 3962 // Sets many values
Chris@0 3963 if ( jQuery.type( key ) === "object" ) {
Chris@0 3964 chainable = true;
Chris@0 3965 for ( i in key ) {
Chris@0 3966 access( elems, fn, i, key[ i ], true, emptyGet, raw );
Chris@0 3967 }
Chris@0 3968
Chris@0 3969 // Sets one value
Chris@0 3970 } else if ( value !== undefined ) {
Chris@0 3971 chainable = true;
Chris@0 3972
Chris@0 3973 if ( !jQuery.isFunction( value ) ) {
Chris@0 3974 raw = true;
Chris@0 3975 }
Chris@0 3976
Chris@0 3977 if ( bulk ) {
Chris@0 3978
Chris@0 3979 // Bulk operations run against the entire set
Chris@0 3980 if ( raw ) {
Chris@0 3981 fn.call( elems, value );
Chris@0 3982 fn = null;
Chris@0 3983
Chris@0 3984 // ...except when executing function values
Chris@0 3985 } else {
Chris@0 3986 bulk = fn;
Chris@0 3987 fn = function( elem, key, value ) {
Chris@0 3988 return bulk.call( jQuery( elem ), value );
Chris@0 3989 };
Chris@0 3990 }
Chris@0 3991 }
Chris@0 3992
Chris@0 3993 if ( fn ) {
Chris@0 3994 for ( ; i < len; i++ ) {
Chris@0 3995 fn(
Chris@0 3996 elems[ i ], key, raw ?
Chris@0 3997 value :
Chris@0 3998 value.call( elems[ i ], i, fn( elems[ i ], key ) )
Chris@0 3999 );
Chris@0 4000 }
Chris@0 4001 }
Chris@0 4002 }
Chris@0 4003
Chris@0 4004 if ( chainable ) {
Chris@0 4005 return elems;
Chris@0 4006 }
Chris@0 4007
Chris@0 4008 // Gets
Chris@0 4009 if ( bulk ) {
Chris@0 4010 return fn.call( elems );
Chris@0 4011 }
Chris@0 4012
Chris@0 4013 return len ? fn( elems[ 0 ], key ) : emptyGet;
Chris@0 4014 };
Chris@0 4015 var acceptData = function( owner ) {
Chris@0 4016
Chris@0 4017 // Accepts only:
Chris@0 4018 // - Node
Chris@0 4019 // - Node.ELEMENT_NODE
Chris@0 4020 // - Node.DOCUMENT_NODE
Chris@0 4021 // - Object
Chris@0 4022 // - Any
Chris@0 4023 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
Chris@0 4024 };
Chris@0 4025
Chris@0 4026
Chris@0 4027
Chris@0 4028
Chris@0 4029 function Data() {
Chris@0 4030 this.expando = jQuery.expando + Data.uid++;
Chris@0 4031 }
Chris@0 4032
Chris@0 4033 Data.uid = 1;
Chris@0 4034
Chris@0 4035 Data.prototype = {
Chris@0 4036
Chris@0 4037 cache: function( owner ) {
Chris@0 4038
Chris@0 4039 // Check if the owner object already has a cache
Chris@0 4040 var value = owner[ this.expando ];
Chris@0 4041
Chris@0 4042 // If not, create one
Chris@0 4043 if ( !value ) {
Chris@0 4044 value = {};
Chris@0 4045
Chris@0 4046 // We can accept data for non-element nodes in modern browsers,
Chris@0 4047 // but we should not, see #8335.
Chris@0 4048 // Always return an empty object.
Chris@0 4049 if ( acceptData( owner ) ) {
Chris@0 4050
Chris@0 4051 // If it is a node unlikely to be stringify-ed or looped over
Chris@0 4052 // use plain assignment
Chris@0 4053 if ( owner.nodeType ) {
Chris@0 4054 owner[ this.expando ] = value;
Chris@0 4055
Chris@0 4056 // Otherwise secure it in a non-enumerable property
Chris@0 4057 // configurable must be true to allow the property to be
Chris@0 4058 // deleted when data is removed
Chris@0 4059 } else {
Chris@0 4060 Object.defineProperty( owner, this.expando, {
Chris@0 4061 value: value,
Chris@0 4062 configurable: true
Chris@0 4063 } );
Chris@0 4064 }
Chris@0 4065 }
Chris@0 4066 }
Chris@0 4067
Chris@0 4068 return value;
Chris@0 4069 },
Chris@0 4070 set: function( owner, data, value ) {
Chris@0 4071 var prop,
Chris@0 4072 cache = this.cache( owner );
Chris@0 4073
Chris@0 4074 // Handle: [ owner, key, value ] args
Chris@0 4075 // Always use camelCase key (gh-2257)
Chris@0 4076 if ( typeof data === "string" ) {
Chris@0 4077 cache[ jQuery.camelCase( data ) ] = value;
Chris@0 4078
Chris@0 4079 // Handle: [ owner, { properties } ] args
Chris@0 4080 } else {
Chris@0 4081
Chris@0 4082 // Copy the properties one-by-one to the cache object
Chris@0 4083 for ( prop in data ) {
Chris@0 4084 cache[ jQuery.camelCase( prop ) ] = data[ prop ];
Chris@0 4085 }
Chris@0 4086 }
Chris@0 4087 return cache;
Chris@0 4088 },
Chris@0 4089 get: function( owner, key ) {
Chris@0 4090 return key === undefined ?
Chris@0 4091 this.cache( owner ) :
Chris@0 4092
Chris@0 4093 // Always use camelCase key (gh-2257)
Chris@0 4094 owner[ this.expando ] && owner[ this.expando ][ jQuery.camelCase( key ) ];
Chris@0 4095 },
Chris@0 4096 access: function( owner, key, value ) {
Chris@0 4097
Chris@0 4098 // In cases where either:
Chris@0 4099 //
Chris@0 4100 // 1. No key was specified
Chris@0 4101 // 2. A string key was specified, but no value provided
Chris@0 4102 //
Chris@0 4103 // Take the "read" path and allow the get method to determine
Chris@0 4104 // which value to return, respectively either:
Chris@0 4105 //
Chris@0 4106 // 1. The entire cache object
Chris@0 4107 // 2. The data stored at the key
Chris@0 4108 //
Chris@0 4109 if ( key === undefined ||
Chris@0 4110 ( ( key && typeof key === "string" ) && value === undefined ) ) {
Chris@0 4111
Chris@0 4112 return this.get( owner, key );
Chris@0 4113 }
Chris@0 4114
Chris@0 4115 // When the key is not a string, or both a key and value
Chris@0 4116 // are specified, set or extend (existing objects) with either:
Chris@0 4117 //
Chris@0 4118 // 1. An object of properties
Chris@0 4119 // 2. A key and value
Chris@0 4120 //
Chris@0 4121 this.set( owner, key, value );
Chris@0 4122
Chris@0 4123 // Since the "set" path can have two possible entry points
Chris@0 4124 // return the expected data based on which path was taken[*]
Chris@0 4125 return value !== undefined ? value : key;
Chris@0 4126 },
Chris@0 4127 remove: function( owner, key ) {
Chris@0 4128 var i,
Chris@0 4129 cache = owner[ this.expando ];
Chris@0 4130
Chris@0 4131 if ( cache === undefined ) {
Chris@0 4132 return;
Chris@0 4133 }
Chris@0 4134
Chris@0 4135 if ( key !== undefined ) {
Chris@0 4136
Chris@0 4137 // Support array or space separated string of keys
Chris@0 4138 if ( Array.isArray( key ) ) {
Chris@0 4139
Chris@0 4140 // If key is an array of keys...
Chris@0 4141 // We always set camelCase keys, so remove that.
Chris@0 4142 key = key.map( jQuery.camelCase );
Chris@0 4143 } else {
Chris@0 4144 key = jQuery.camelCase( key );
Chris@0 4145
Chris@0 4146 // If a key with the spaces exists, use it.
Chris@0 4147 // Otherwise, create an array by matching non-whitespace
Chris@0 4148 key = key in cache ?
Chris@0 4149 [ key ] :
Chris@0 4150 ( key.match( rnothtmlwhite ) || [] );
Chris@0 4151 }
Chris@0 4152
Chris@0 4153 i = key.length;
Chris@0 4154
Chris@0 4155 while ( i-- ) {
Chris@0 4156 delete cache[ key[ i ] ];
Chris@0 4157 }
Chris@0 4158 }
Chris@0 4159
Chris@0 4160 // Remove the expando if there's no more data
Chris@0 4161 if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
Chris@0 4162
Chris@0 4163 // Support: Chrome <=35 - 45
Chris@0 4164 // Webkit & Blink performance suffers when deleting properties
Chris@0 4165 // from DOM nodes, so set to undefined instead
Chris@0 4166 // https://bugs.chromium.org/p/chromium/issues/detail?id=378607 (bug restricted)
Chris@0 4167 if ( owner.nodeType ) {
Chris@0 4168 owner[ this.expando ] = undefined;
Chris@0 4169 } else {
Chris@0 4170 delete owner[ this.expando ];
Chris@0 4171 }
Chris@0 4172 }
Chris@0 4173 },
Chris@0 4174 hasData: function( owner ) {
Chris@0 4175 var cache = owner[ this.expando ];
Chris@0 4176 return cache !== undefined && !jQuery.isEmptyObject( cache );
Chris@0 4177 }
Chris@0 4178 };
Chris@0 4179 var dataPriv = new Data();
Chris@0 4180
Chris@0 4181 var dataUser = new Data();
Chris@0 4182
Chris@0 4183
Chris@0 4184
Chris@0 4185 // Implementation Summary
Chris@0 4186 //
Chris@0 4187 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
Chris@0 4188 // 2. Improve the module's maintainability by reducing the storage
Chris@0 4189 // paths to a single mechanism.
Chris@0 4190 // 3. Use the same single mechanism to support "private" and "user" data.
Chris@0 4191 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
Chris@0 4192 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
Chris@0 4193 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
Chris@0 4194
Chris@0 4195 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
Chris@0 4196 rmultiDash = /[A-Z]/g;
Chris@0 4197
Chris@0 4198 function getData( data ) {
Chris@0 4199 if ( data === "true" ) {
Chris@0 4200 return true;
Chris@0 4201 }
Chris@0 4202
Chris@0 4203 if ( data === "false" ) {
Chris@0 4204 return false;
Chris@0 4205 }
Chris@0 4206
Chris@0 4207 if ( data === "null" ) {
Chris@0 4208 return null;
Chris@0 4209 }
Chris@0 4210
Chris@0 4211 // Only convert to a number if it doesn't change the string
Chris@0 4212 if ( data === +data + "" ) {
Chris@0 4213 return +data;
Chris@0 4214 }
Chris@0 4215
Chris@0 4216 if ( rbrace.test( data ) ) {
Chris@0 4217 return JSON.parse( data );
Chris@0 4218 }
Chris@0 4219
Chris@0 4220 return data;
Chris@0 4221 }
Chris@0 4222
Chris@0 4223 function dataAttr( elem, key, data ) {
Chris@0 4224 var name;
Chris@0 4225
Chris@0 4226 // If nothing was found internally, try to fetch any
Chris@0 4227 // data from the HTML5 data-* attribute
Chris@0 4228 if ( data === undefined && elem.nodeType === 1 ) {
Chris@0 4229 name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase();
Chris@0 4230 data = elem.getAttribute( name );
Chris@0 4231
Chris@0 4232 if ( typeof data === "string" ) {
Chris@0 4233 try {
Chris@0 4234 data = getData( data );
Chris@0 4235 } catch ( e ) {}
Chris@0 4236
Chris@0 4237 // Make sure we set the data so it isn't changed later
Chris@0 4238 dataUser.set( elem, key, data );
Chris@0 4239 } else {
Chris@0 4240 data = undefined;
Chris@0 4241 }
Chris@0 4242 }
Chris@0 4243 return data;
Chris@0 4244 }
Chris@0 4245
Chris@0 4246 jQuery.extend( {
Chris@0 4247 hasData: function( elem ) {
Chris@0 4248 return dataUser.hasData( elem ) || dataPriv.hasData( elem );
Chris@0 4249 },
Chris@0 4250
Chris@0 4251 data: function( elem, name, data ) {
Chris@0 4252 return dataUser.access( elem, name, data );
Chris@0 4253 },
Chris@0 4254
Chris@0 4255 removeData: function( elem, name ) {
Chris@0 4256 dataUser.remove( elem, name );
Chris@0 4257 },
Chris@0 4258
Chris@0 4259 // TODO: Now that all calls to _data and _removeData have been replaced
Chris@0 4260 // with direct calls to dataPriv methods, these can be deprecated.
Chris@0 4261 _data: function( elem, name, data ) {
Chris@0 4262 return dataPriv.access( elem, name, data );
Chris@0 4263 },
Chris@0 4264
Chris@0 4265 _removeData: function( elem, name ) {
Chris@0 4266 dataPriv.remove( elem, name );
Chris@0 4267 }
Chris@0 4268 } );
Chris@0 4269
Chris@0 4270 jQuery.fn.extend( {
Chris@0 4271 data: function( key, value ) {
Chris@0 4272 var i, name, data,
Chris@0 4273 elem = this[ 0 ],
Chris@0 4274 attrs = elem && elem.attributes;
Chris@0 4275
Chris@0 4276 // Gets all values
Chris@0 4277 if ( key === undefined ) {
Chris@0 4278 if ( this.length ) {
Chris@0 4279 data = dataUser.get( elem );
Chris@0 4280
Chris@0 4281 if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) {
Chris@0 4282 i = attrs.length;
Chris@0 4283 while ( i-- ) {
Chris@0 4284
Chris@0 4285 // Support: IE 11 only
Chris@0 4286 // The attrs elements can be null (#14894)
Chris@0 4287 if ( attrs[ i ] ) {
Chris@0 4288 name = attrs[ i ].name;
Chris@0 4289 if ( name.indexOf( "data-" ) === 0 ) {
Chris@0 4290 name = jQuery.camelCase( name.slice( 5 ) );
Chris@0 4291 dataAttr( elem, name, data[ name ] );
Chris@0 4292 }
Chris@0 4293 }
Chris@0 4294 }
Chris@0 4295 dataPriv.set( elem, "hasDataAttrs", true );
Chris@0 4296 }
Chris@0 4297 }
Chris@0 4298
Chris@0 4299 return data;
Chris@0 4300 }
Chris@0 4301
Chris@0 4302 // Sets multiple values
Chris@0 4303 if ( typeof key === "object" ) {
Chris@0 4304 return this.each( function() {
Chris@0 4305 dataUser.set( this, key );
Chris@0 4306 } );
Chris@0 4307 }
Chris@0 4308
Chris@0 4309 return access( this, function( value ) {
Chris@0 4310 var data;
Chris@0 4311
Chris@0 4312 // The calling jQuery object (element matches) is not empty
Chris@0 4313 // (and therefore has an element appears at this[ 0 ]) and the
Chris@0 4314 // `value` parameter was not undefined. An empty jQuery object
Chris@0 4315 // will result in `undefined` for elem = this[ 0 ] which will
Chris@0 4316 // throw an exception if an attempt to read a data cache is made.
Chris@0 4317 if ( elem && value === undefined ) {
Chris@0 4318
Chris@0 4319 // Attempt to get data from the cache
Chris@0 4320 // The key will always be camelCased in Data
Chris@0 4321 data = dataUser.get( elem, key );
Chris@0 4322 if ( data !== undefined ) {
Chris@0 4323 return data;
Chris@0 4324 }
Chris@0 4325
Chris@0 4326 // Attempt to "discover" the data in
Chris@0 4327 // HTML5 custom data-* attrs
Chris@0 4328 data = dataAttr( elem, key );
Chris@0 4329 if ( data !== undefined ) {
Chris@0 4330 return data;
Chris@0 4331 }
Chris@0 4332
Chris@0 4333 // We tried really hard, but the data doesn't exist.
Chris@0 4334 return;
Chris@0 4335 }
Chris@0 4336
Chris@0 4337 // Set the data...
Chris@0 4338 this.each( function() {
Chris@0 4339
Chris@0 4340 // We always store the camelCased key
Chris@0 4341 dataUser.set( this, key, value );
Chris@0 4342 } );
Chris@0 4343 }, null, value, arguments.length > 1, null, true );
Chris@0 4344 },
Chris@0 4345
Chris@0 4346 removeData: function( key ) {
Chris@0 4347 return this.each( function() {
Chris@0 4348 dataUser.remove( this, key );
Chris@0 4349 } );
Chris@0 4350 }
Chris@0 4351 } );
Chris@0 4352
Chris@0 4353
Chris@0 4354 jQuery.extend( {
Chris@0 4355 queue: function( elem, type, data ) {
Chris@0 4356 var queue;
Chris@0 4357
Chris@0 4358 if ( elem ) {
Chris@0 4359 type = ( type || "fx" ) + "queue";
Chris@0 4360 queue = dataPriv.get( elem, type );
Chris@0 4361
Chris@0 4362 // Speed up dequeue by getting out quickly if this is just a lookup
Chris@0 4363 if ( data ) {
Chris@0 4364 if ( !queue || Array.isArray( data ) ) {
Chris@0 4365 queue = dataPriv.access( elem, type, jQuery.makeArray( data ) );
Chris@0 4366 } else {
Chris@0 4367 queue.push( data );
Chris@0 4368 }
Chris@0 4369 }
Chris@0 4370 return queue || [];
Chris@0 4371 }
Chris@0 4372 },
Chris@0 4373
Chris@0 4374 dequeue: function( elem, type ) {
Chris@0 4375 type = type || "fx";
Chris@0 4376
Chris@0 4377 var queue = jQuery.queue( elem, type ),
Chris@0 4378 startLength = queue.length,
Chris@0 4379 fn = queue.shift(),
Chris@0 4380 hooks = jQuery._queueHooks( elem, type ),
Chris@0 4381 next = function() {
Chris@0 4382 jQuery.dequeue( elem, type );
Chris@0 4383 };
Chris@0 4384
Chris@0 4385 // If the fx queue is dequeued, always remove the progress sentinel
Chris@0 4386 if ( fn === "inprogress" ) {
Chris@0 4387 fn = queue.shift();
Chris@0 4388 startLength--;
Chris@0 4389 }
Chris@0 4390
Chris@0 4391 if ( fn ) {
Chris@0 4392
Chris@0 4393 // Add a progress sentinel to prevent the fx queue from being
Chris@0 4394 // automatically dequeued
Chris@0 4395 if ( type === "fx" ) {
Chris@0 4396 queue.unshift( "inprogress" );
Chris@0 4397 }
Chris@0 4398
Chris@0 4399 // Clear up the last queue stop function
Chris@0 4400 delete hooks.stop;
Chris@0 4401 fn.call( elem, next, hooks );
Chris@0 4402 }
Chris@0 4403
Chris@0 4404 if ( !startLength && hooks ) {
Chris@0 4405 hooks.empty.fire();
Chris@0 4406 }
Chris@0 4407 },
Chris@0 4408
Chris@0 4409 // Not public - generate a queueHooks object, or return the current one
Chris@0 4410 _queueHooks: function( elem, type ) {
Chris@0 4411 var key = type + "queueHooks";
Chris@0 4412 return dataPriv.get( elem, key ) || dataPriv.access( elem, key, {
Chris@0 4413 empty: jQuery.Callbacks( "once memory" ).add( function() {
Chris@0 4414 dataPriv.remove( elem, [ type + "queue", key ] );
Chris@0 4415 } )
Chris@0 4416 } );
Chris@0 4417 }
Chris@0 4418 } );
Chris@0 4419
Chris@0 4420 jQuery.fn.extend( {
Chris@0 4421 queue: function( type, data ) {
Chris@0 4422 var setter = 2;
Chris@0 4423
Chris@0 4424 if ( typeof type !== "string" ) {
Chris@0 4425 data = type;
Chris@0 4426 type = "fx";
Chris@0 4427 setter--;
Chris@0 4428 }
Chris@0 4429
Chris@0 4430 if ( arguments.length < setter ) {
Chris@0 4431 return jQuery.queue( this[ 0 ], type );
Chris@0 4432 }
Chris@0 4433
Chris@0 4434 return data === undefined ?
Chris@0 4435 this :
Chris@0 4436 this.each( function() {
Chris@0 4437 var queue = jQuery.queue( this, type, data );
Chris@0 4438
Chris@0 4439 // Ensure a hooks for this queue
Chris@0 4440 jQuery._queueHooks( this, type );
Chris@0 4441
Chris@0 4442 if ( type === "fx" && queue[ 0 ] !== "inprogress" ) {
Chris@0 4443 jQuery.dequeue( this, type );
Chris@0 4444 }
Chris@0 4445 } );
Chris@0 4446 },
Chris@0 4447 dequeue: function( type ) {
Chris@0 4448 return this.each( function() {
Chris@0 4449 jQuery.dequeue( this, type );
Chris@0 4450 } );
Chris@0 4451 },
Chris@0 4452 clearQueue: function( type ) {
Chris@0 4453 return this.queue( type || "fx", [] );
Chris@0 4454 },
Chris@0 4455
Chris@0 4456 // Get a promise resolved when queues of a certain type
Chris@0 4457 // are emptied (fx is the type by default)
Chris@0 4458 promise: function( type, obj ) {
Chris@0 4459 var tmp,
Chris@0 4460 count = 1,
Chris@0 4461 defer = jQuery.Deferred(),
Chris@0 4462 elements = this,
Chris@0 4463 i = this.length,
Chris@0 4464 resolve = function() {
Chris@0 4465 if ( !( --count ) ) {
Chris@0 4466 defer.resolveWith( elements, [ elements ] );
Chris@0 4467 }
Chris@0 4468 };
Chris@0 4469
Chris@0 4470 if ( typeof type !== "string" ) {
Chris@0 4471 obj = type;
Chris@0 4472 type = undefined;
Chris@0 4473 }
Chris@0 4474 type = type || "fx";
Chris@0 4475
Chris@0 4476 while ( i-- ) {
Chris@0 4477 tmp = dataPriv.get( elements[ i ], type + "queueHooks" );
Chris@0 4478 if ( tmp && tmp.empty ) {
Chris@0 4479 count++;
Chris@0 4480 tmp.empty.add( resolve );
Chris@0 4481 }
Chris@0 4482 }
Chris@0 4483 resolve();
Chris@0 4484 return defer.promise( obj );
Chris@0 4485 }
Chris@0 4486 } );
Chris@0 4487 var pnum = ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source;
Chris@0 4488
Chris@0 4489 var rcssNum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" );
Chris@0 4490
Chris@0 4491
Chris@0 4492 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
Chris@0 4493
Chris@0 4494 var isHiddenWithinTree = function( elem, el ) {
Chris@0 4495
Chris@0 4496 // isHiddenWithinTree might be called from jQuery#filter function;
Chris@0 4497 // in that case, element will be second argument
Chris@0 4498 elem = el || elem;
Chris@0 4499
Chris@0 4500 // Inline style trumps all
Chris@0 4501 return elem.style.display === "none" ||
Chris@0 4502 elem.style.display === "" &&
Chris@0 4503
Chris@0 4504 // Otherwise, check computed style
Chris@0 4505 // Support: Firefox <=43 - 45
Chris@0 4506 // Disconnected elements can have computed display: none, so first confirm that elem is
Chris@0 4507 // in the document.
Chris@0 4508 jQuery.contains( elem.ownerDocument, elem ) &&
Chris@0 4509
Chris@0 4510 jQuery.css( elem, "display" ) === "none";
Chris@0 4511 };
Chris@0 4512
Chris@0 4513 var swap = function( elem, options, callback, args ) {
Chris@0 4514 var ret, name,
Chris@0 4515 old = {};
Chris@0 4516
Chris@0 4517 // Remember the old values, and insert the new ones
Chris@0 4518 for ( name in options ) {
Chris@0 4519 old[ name ] = elem.style[ name ];
Chris@0 4520 elem.style[ name ] = options[ name ];
Chris@0 4521 }
Chris@0 4522
Chris@0 4523 ret = callback.apply( elem, args || [] );
Chris@0 4524
Chris@0 4525 // Revert the old values
Chris@0 4526 for ( name in options ) {
Chris@0 4527 elem.style[ name ] = old[ name ];
Chris@0 4528 }
Chris@0 4529
Chris@0 4530 return ret;
Chris@0 4531 };
Chris@0 4532
Chris@0 4533
Chris@0 4534
Chris@0 4535
Chris@0 4536 function adjustCSS( elem, prop, valueParts, tween ) {
Chris@0 4537 var adjusted,
Chris@0 4538 scale = 1,
Chris@0 4539 maxIterations = 20,
Chris@0 4540 currentValue = tween ?
Chris@0 4541 function() {
Chris@0 4542 return tween.cur();
Chris@0 4543 } :
Chris@0 4544 function() {
Chris@0 4545 return jQuery.css( elem, prop, "" );
Chris@0 4546 },
Chris@0 4547 initial = currentValue(),
Chris@0 4548 unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
Chris@0 4549
Chris@0 4550 // Starting value computation is required for potential unit mismatches
Chris@0 4551 initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
Chris@0 4552 rcssNum.exec( jQuery.css( elem, prop ) );
Chris@0 4553
Chris@0 4554 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
Chris@0 4555
Chris@0 4556 // Trust units reported by jQuery.css
Chris@0 4557 unit = unit || initialInUnit[ 3 ];
Chris@0 4558
Chris@0 4559 // Make sure we update the tween properties later on
Chris@0 4560 valueParts = valueParts || [];
Chris@0 4561
Chris@0 4562 // Iteratively approximate from a nonzero starting point
Chris@0 4563 initialInUnit = +initial || 1;
Chris@0 4564
Chris@0 4565 do {
Chris@0 4566
Chris@0 4567 // If previous iteration zeroed out, double until we get *something*.
Chris@0 4568 // Use string for doubling so we don't accidentally see scale as unchanged below
Chris@0 4569 scale = scale || ".5";
Chris@0 4570
Chris@0 4571 // Adjust and apply
Chris@0 4572 initialInUnit = initialInUnit / scale;
Chris@0 4573 jQuery.style( elem, prop, initialInUnit + unit );
Chris@0 4574
Chris@0 4575 // Update scale, tolerating zero or NaN from tween.cur()
Chris@0 4576 // Break the loop if scale is unchanged or perfect, or if we've just had enough.
Chris@0 4577 } while (
Chris@0 4578 scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations
Chris@0 4579 );
Chris@0 4580 }
Chris@0 4581
Chris@0 4582 if ( valueParts ) {
Chris@0 4583 initialInUnit = +initialInUnit || +initial || 0;
Chris@0 4584
Chris@0 4585 // Apply relative offset (+=/-=) if specified
Chris@0 4586 adjusted = valueParts[ 1 ] ?
Chris@0 4587 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
Chris@0 4588 +valueParts[ 2 ];
Chris@0 4589 if ( tween ) {
Chris@0 4590 tween.unit = unit;
Chris@0 4591 tween.start = initialInUnit;
Chris@0 4592 tween.end = adjusted;
Chris@0 4593 }
Chris@0 4594 }
Chris@0 4595 return adjusted;
Chris@0 4596 }
Chris@0 4597
Chris@0 4598
Chris@0 4599 var defaultDisplayMap = {};
Chris@0 4600
Chris@0 4601 function getDefaultDisplay( elem ) {
Chris@0 4602 var temp,
Chris@0 4603 doc = elem.ownerDocument,
Chris@0 4604 nodeName = elem.nodeName,
Chris@0 4605 display = defaultDisplayMap[ nodeName ];
Chris@0 4606
Chris@0 4607 if ( display ) {
Chris@0 4608 return display;
Chris@0 4609 }
Chris@0 4610
Chris@0 4611 temp = doc.body.appendChild( doc.createElement( nodeName ) );
Chris@0 4612 display = jQuery.css( temp, "display" );
Chris@0 4613
Chris@0 4614 temp.parentNode.removeChild( temp );
Chris@0 4615
Chris@0 4616 if ( display === "none" ) {
Chris@0 4617 display = "block";
Chris@0 4618 }
Chris@0 4619 defaultDisplayMap[ nodeName ] = display;
Chris@0 4620
Chris@0 4621 return display;
Chris@0 4622 }
Chris@0 4623
Chris@0 4624 function showHide( elements, show ) {
Chris@0 4625 var display, elem,
Chris@0 4626 values = [],
Chris@0 4627 index = 0,
Chris@0 4628 length = elements.length;
Chris@0 4629
Chris@0 4630 // Determine new display value for elements that need to change
Chris@0 4631 for ( ; index < length; index++ ) {
Chris@0 4632 elem = elements[ index ];
Chris@0 4633 if ( !elem.style ) {
Chris@0 4634 continue;
Chris@0 4635 }
Chris@0 4636
Chris@0 4637 display = elem.style.display;
Chris@0 4638 if ( show ) {
Chris@0 4639
Chris@0 4640 // Since we force visibility upon cascade-hidden elements, an immediate (and slow)
Chris@0 4641 // check is required in this first loop unless we have a nonempty display value (either
Chris@0 4642 // inline or about-to-be-restored)
Chris@0 4643 if ( display === "none" ) {
Chris@0 4644 values[ index ] = dataPriv.get( elem, "display" ) || null;
Chris@0 4645 if ( !values[ index ] ) {
Chris@0 4646 elem.style.display = "";
Chris@0 4647 }
Chris@0 4648 }
Chris@0 4649 if ( elem.style.display === "" && isHiddenWithinTree( elem ) ) {
Chris@0 4650 values[ index ] = getDefaultDisplay( elem );
Chris@0 4651 }
Chris@0 4652 } else {
Chris@0 4653 if ( display !== "none" ) {
Chris@0 4654 values[ index ] = "none";
Chris@0 4655
Chris@0 4656 // Remember what we're overwriting
Chris@0 4657 dataPriv.set( elem, "display", display );
Chris@0 4658 }
Chris@0 4659 }
Chris@0 4660 }
Chris@0 4661
Chris@0 4662 // Set the display of the elements in a second loop to avoid constant reflow
Chris@0 4663 for ( index = 0; index < length; index++ ) {
Chris@0 4664 if ( values[ index ] != null ) {
Chris@0 4665 elements[ index ].style.display = values[ index ];
Chris@0 4666 }
Chris@0 4667 }
Chris@0 4668
Chris@0 4669 return elements;
Chris@0 4670 }
Chris@0 4671
Chris@0 4672 jQuery.fn.extend( {
Chris@0 4673 show: function() {
Chris@0 4674 return showHide( this, true );
Chris@0 4675 },
Chris@0 4676 hide: function() {
Chris@0 4677 return showHide( this );
Chris@0 4678 },
Chris@0 4679 toggle: function( state ) {
Chris@0 4680 if ( typeof state === "boolean" ) {
Chris@0 4681 return state ? this.show() : this.hide();
Chris@0 4682 }
Chris@0 4683
Chris@0 4684 return this.each( function() {
Chris@0 4685 if ( isHiddenWithinTree( this ) ) {
Chris@0 4686 jQuery( this ).show();
Chris@0 4687 } else {
Chris@0 4688 jQuery( this ).hide();
Chris@0 4689 }
Chris@0 4690 } );
Chris@0 4691 }
Chris@0 4692 } );
Chris@0 4693 var rcheckableType = ( /^(?:checkbox|radio)$/i );
Chris@0 4694
Chris@0 4695 var rtagName = ( /<([a-z][^\/\0>\x20\t\r\n\f]+)/i );
Chris@0 4696
Chris@0 4697 var rscriptType = ( /^$|\/(?:java|ecma)script/i );
Chris@0 4698
Chris@0 4699
Chris@0 4700
Chris@0 4701 // We have to close these tags to support XHTML (#13200)
Chris@0 4702 var wrapMap = {
Chris@0 4703
Chris@0 4704 // Support: IE <=9 only
Chris@0 4705 option: [ 1, "<select multiple='multiple'>", "</select>" ],
Chris@0 4706
Chris@0 4707 // XHTML parsers do not magically insert elements in the
Chris@0 4708 // same way that tag soup parsers do. So we cannot shorten
Chris@0 4709 // this by omitting <tbody> or other required elements.
Chris@0 4710 thead: [ 1, "<table>", "</table>" ],
Chris@0 4711 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
Chris@0 4712 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
Chris@0 4713 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
Chris@0 4714
Chris@0 4715 _default: [ 0, "", "" ]
Chris@0 4716 };
Chris@0 4717
Chris@0 4718 // Support: IE <=9 only
Chris@0 4719 wrapMap.optgroup = wrapMap.option;
Chris@0 4720
Chris@0 4721 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
Chris@0 4722 wrapMap.th = wrapMap.td;
Chris@0 4723
Chris@0 4724
Chris@0 4725 function getAll( context, tag ) {
Chris@0 4726
Chris@0 4727 // Support: IE <=9 - 11 only
Chris@0 4728 // Use typeof to avoid zero-argument method invocation on host objects (#15151)
Chris@0 4729 var ret;
Chris@0 4730
Chris@0 4731 if ( typeof context.getElementsByTagName !== "undefined" ) {
Chris@0 4732 ret = context.getElementsByTagName( tag || "*" );
Chris@0 4733
Chris@0 4734 } else if ( typeof context.querySelectorAll !== "undefined" ) {
Chris@0 4735 ret = context.querySelectorAll( tag || "*" );
Chris@0 4736
Chris@0 4737 } else {
Chris@0 4738 ret = [];
Chris@0 4739 }
Chris@0 4740
Chris@0 4741 if ( tag === undefined || tag && nodeName( context, tag ) ) {
Chris@0 4742 return jQuery.merge( [ context ], ret );
Chris@0 4743 }
Chris@0 4744
Chris@0 4745 return ret;
Chris@0 4746 }
Chris@0 4747
Chris@0 4748
Chris@0 4749 // Mark scripts as having already been evaluated
Chris@0 4750 function setGlobalEval( elems, refElements ) {
Chris@0 4751 var i = 0,
Chris@0 4752 l = elems.length;
Chris@0 4753
Chris@0 4754 for ( ; i < l; i++ ) {
Chris@0 4755 dataPriv.set(
Chris@0 4756 elems[ i ],
Chris@0 4757 "globalEval",
Chris@0 4758 !refElements || dataPriv.get( refElements[ i ], "globalEval" )
Chris@0 4759 );
Chris@0 4760 }
Chris@0 4761 }
Chris@0 4762
Chris@0 4763
Chris@0 4764 var rhtml = /<|&#?\w+;/;
Chris@0 4765
Chris@0 4766 function buildFragment( elems, context, scripts, selection, ignored ) {
Chris@0 4767 var elem, tmp, tag, wrap, contains, j,
Chris@0 4768 fragment = context.createDocumentFragment(),
Chris@0 4769 nodes = [],
Chris@0 4770 i = 0,
Chris@0 4771 l = elems.length;
Chris@0 4772
Chris@0 4773 for ( ; i < l; i++ ) {
Chris@0 4774 elem = elems[ i ];
Chris@0 4775
Chris@0 4776 if ( elem || elem === 0 ) {
Chris@0 4777
Chris@0 4778 // Add nodes directly
Chris@0 4779 if ( jQuery.type( elem ) === "object" ) {
Chris@0 4780
Chris@0 4781 // Support: Android <=4.0 only, PhantomJS 1 only
Chris@0 4782 // push.apply(_, arraylike) throws on ancient WebKit
Chris@0 4783 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
Chris@0 4784
Chris@0 4785 // Convert non-html into a text node
Chris@0 4786 } else if ( !rhtml.test( elem ) ) {
Chris@0 4787 nodes.push( context.createTextNode( elem ) );
Chris@0 4788
Chris@0 4789 // Convert html into DOM nodes
Chris@0 4790 } else {
Chris@0 4791 tmp = tmp || fragment.appendChild( context.createElement( "div" ) );
Chris@0 4792
Chris@0 4793 // Deserialize a standard representation
Chris@0 4794 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
Chris@0 4795 wrap = wrapMap[ tag ] || wrapMap._default;
Chris@0 4796 tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ];
Chris@0 4797
Chris@0 4798 // Descend through wrappers to the right content
Chris@0 4799 j = wrap[ 0 ];
Chris@0 4800 while ( j-- ) {
Chris@0 4801 tmp = tmp.lastChild;
Chris@0 4802 }
Chris@0 4803
Chris@0 4804 // Support: Android <=4.0 only, PhantomJS 1 only
Chris@0 4805 // push.apply(_, arraylike) throws on ancient WebKit
Chris@0 4806 jQuery.merge( nodes, tmp.childNodes );
Chris@0 4807
Chris@0 4808 // Remember the top-level container
Chris@0 4809 tmp = fragment.firstChild;
Chris@0 4810
Chris@0 4811 // Ensure the created nodes are orphaned (#12392)
Chris@0 4812 tmp.textContent = "";
Chris@0 4813 }
Chris@0 4814 }
Chris@0 4815 }
Chris@0 4816
Chris@0 4817 // Remove wrapper from fragment
Chris@0 4818 fragment.textContent = "";
Chris@0 4819
Chris@0 4820 i = 0;
Chris@0 4821 while ( ( elem = nodes[ i++ ] ) ) {
Chris@0 4822
Chris@0 4823 // Skip elements already in the context collection (trac-4087)
Chris@0 4824 if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
Chris@0 4825 if ( ignored ) {
Chris@0 4826 ignored.push( elem );
Chris@0 4827 }
Chris@0 4828 continue;
Chris@0 4829 }
Chris@0 4830
Chris@0 4831 contains = jQuery.contains( elem.ownerDocument, elem );
Chris@0 4832
Chris@0 4833 // Append to fragment
Chris@0 4834 tmp = getAll( fragment.appendChild( elem ), "script" );
Chris@0 4835
Chris@0 4836 // Preserve script evaluation history
Chris@0 4837 if ( contains ) {
Chris@0 4838 setGlobalEval( tmp );
Chris@0 4839 }
Chris@0 4840
Chris@0 4841 // Capture executables
Chris@0 4842 if ( scripts ) {
Chris@0 4843 j = 0;
Chris@0 4844 while ( ( elem = tmp[ j++ ] ) ) {
Chris@0 4845 if ( rscriptType.test( elem.type || "" ) ) {
Chris@0 4846 scripts.push( elem );
Chris@0 4847 }
Chris@0 4848 }
Chris@0 4849 }
Chris@0 4850 }
Chris@0 4851
Chris@0 4852 return fragment;
Chris@0 4853 }
Chris@0 4854
Chris@0 4855
Chris@0 4856 ( function() {
Chris@0 4857 var fragment = document.createDocumentFragment(),
Chris@0 4858 div = fragment.appendChild( document.createElement( "div" ) ),
Chris@0 4859 input = document.createElement( "input" );
Chris@0 4860
Chris@0 4861 // Support: Android 4.0 - 4.3 only
Chris@0 4862 // Check state lost if the name is set (#11217)
Chris@0 4863 // Support: Windows Web Apps (WWA)
Chris@0 4864 // `name` and `type` must use .setAttribute for WWA (#14901)
Chris@0 4865 input.setAttribute( "type", "radio" );
Chris@0 4866 input.setAttribute( "checked", "checked" );
Chris@0 4867 input.setAttribute( "name", "t" );
Chris@0 4868
Chris@0 4869 div.appendChild( input );
Chris@0 4870
Chris@0 4871 // Support: Android <=4.1 only
Chris@0 4872 // Older WebKit doesn't clone checked state correctly in fragments
Chris@0 4873 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
Chris@0 4874
Chris@0 4875 // Support: IE <=11 only
Chris@0 4876 // Make sure textarea (and checkbox) defaultValue is properly cloned
Chris@0 4877 div.innerHTML = "<textarea>x</textarea>";
Chris@0 4878 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
Chris@0 4879 } )();
Chris@0 4880 var documentElement = document.documentElement;
Chris@0 4881
Chris@0 4882
Chris@0 4883
Chris@0 4884 var
Chris@0 4885 rkeyEvent = /^key/,
Chris@0 4886 rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/,
Chris@0 4887 rtypenamespace = /^([^.]*)(?:\.(.+)|)/;
Chris@0 4888
Chris@0 4889 function returnTrue() {
Chris@0 4890 return true;
Chris@0 4891 }
Chris@0 4892
Chris@0 4893 function returnFalse() {
Chris@0 4894 return false;
Chris@0 4895 }
Chris@0 4896
Chris@0 4897 // Support: IE <=9 only
Chris@0 4898 // See #13393 for more info
Chris@0 4899 function safeActiveElement() {
Chris@0 4900 try {
Chris@0 4901 return document.activeElement;
Chris@0 4902 } catch ( err ) { }
Chris@0 4903 }
Chris@0 4904
Chris@0 4905 function on( elem, types, selector, data, fn, one ) {
Chris@0 4906 var origFn, type;
Chris@0 4907
Chris@0 4908 // Types can be a map of types/handlers
Chris@0 4909 if ( typeof types === "object" ) {
Chris@0 4910
Chris@0 4911 // ( types-Object, selector, data )
Chris@0 4912 if ( typeof selector !== "string" ) {
Chris@0 4913
Chris@0 4914 // ( types-Object, data )
Chris@0 4915 data = data || selector;
Chris@0 4916 selector = undefined;
Chris@0 4917 }
Chris@0 4918 for ( type in types ) {
Chris@0 4919 on( elem, type, selector, data, types[ type ], one );
Chris@0 4920 }
Chris@0 4921 return elem;
Chris@0 4922 }
Chris@0 4923
Chris@0 4924 if ( data == null && fn == null ) {
Chris@0 4925
Chris@0 4926 // ( types, fn )
Chris@0 4927 fn = selector;
Chris@0 4928 data = selector = undefined;
Chris@0 4929 } else if ( fn == null ) {
Chris@0 4930 if ( typeof selector === "string" ) {
Chris@0 4931
Chris@0 4932 // ( types, selector, fn )
Chris@0 4933 fn = data;
Chris@0 4934 data = undefined;
Chris@0 4935 } else {
Chris@0 4936
Chris@0 4937 // ( types, data, fn )
Chris@0 4938 fn = data;
Chris@0 4939 data = selector;
Chris@0 4940 selector = undefined;
Chris@0 4941 }
Chris@0 4942 }
Chris@0 4943 if ( fn === false ) {
Chris@0 4944 fn = returnFalse;
Chris@0 4945 } else if ( !fn ) {
Chris@0 4946 return elem;
Chris@0 4947 }
Chris@0 4948
Chris@0 4949 if ( one === 1 ) {
Chris@0 4950 origFn = fn;
Chris@0 4951 fn = function( event ) {
Chris@0 4952
Chris@0 4953 // Can use an empty set, since event contains the info
Chris@0 4954 jQuery().off( event );
Chris@0 4955 return origFn.apply( this, arguments );
Chris@0 4956 };
Chris@0 4957
Chris@0 4958 // Use same guid so caller can remove using origFn
Chris@0 4959 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
Chris@0 4960 }
Chris@0 4961 return elem.each( function() {
Chris@0 4962 jQuery.event.add( this, types, fn, data, selector );
Chris@0 4963 } );
Chris@0 4964 }
Chris@0 4965
Chris@0 4966 /*
Chris@0 4967 * Helper functions for managing events -- not part of the public interface.
Chris@0 4968 * Props to Dean Edwards' addEvent library for many of the ideas.
Chris@0 4969 */
Chris@0 4970 jQuery.event = {
Chris@0 4971
Chris@0 4972 global: {},
Chris@0 4973
Chris@0 4974 add: function( elem, types, handler, data, selector ) {
Chris@0 4975
Chris@0 4976 var handleObjIn, eventHandle, tmp,
Chris@0 4977 events, t, handleObj,
Chris@0 4978 special, handlers, type, namespaces, origType,
Chris@0 4979 elemData = dataPriv.get( elem );
Chris@0 4980
Chris@0 4981 // Don't attach events to noData or text/comment nodes (but allow plain objects)
Chris@0 4982 if ( !elemData ) {
Chris@0 4983 return;
Chris@0 4984 }
Chris@0 4985
Chris@0 4986 // Caller can pass in an object of custom data in lieu of the handler
Chris@0 4987 if ( handler.handler ) {
Chris@0 4988 handleObjIn = handler;
Chris@0 4989 handler = handleObjIn.handler;
Chris@0 4990 selector = handleObjIn.selector;
Chris@0 4991 }
Chris@0 4992
Chris@0 4993 // Ensure that invalid selectors throw exceptions at attach time
Chris@0 4994 // Evaluate against documentElement in case elem is a non-element node (e.g., document)
Chris@0 4995 if ( selector ) {
Chris@0 4996 jQuery.find.matchesSelector( documentElement, selector );
Chris@0 4997 }
Chris@0 4998
Chris@0 4999 // Make sure that the handler has a unique ID, used to find/remove it later
Chris@0 5000 if ( !handler.guid ) {
Chris@0 5001 handler.guid = jQuery.guid++;
Chris@0 5002 }
Chris@0 5003
Chris@0 5004 // Init the element's event structure and main handler, if this is the first
Chris@0 5005 if ( !( events = elemData.events ) ) {
Chris@0 5006 events = elemData.events = {};
Chris@0 5007 }
Chris@0 5008 if ( !( eventHandle = elemData.handle ) ) {
Chris@0 5009 eventHandle = elemData.handle = function( e ) {
Chris@0 5010
Chris@0 5011 // Discard the second event of a jQuery.event.trigger() and
Chris@0 5012 // when an event is called after a page has unloaded
Chris@0 5013 return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
Chris@0 5014 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
Chris@0 5015 };
Chris@0 5016 }
Chris@0 5017
Chris@0 5018 // Handle multiple events separated by a space
Chris@0 5019 types = ( types || "" ).match( rnothtmlwhite ) || [ "" ];
Chris@0 5020 t = types.length;
Chris@0 5021 while ( t-- ) {
Chris@0 5022 tmp = rtypenamespace.exec( types[ t ] ) || [];
Chris@0 5023 type = origType = tmp[ 1 ];
Chris@0 5024 namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
Chris@0 5025
Chris@0 5026 // There *must* be a type, no attaching namespace-only handlers
Chris@0 5027 if ( !type ) {
Chris@0 5028 continue;
Chris@0 5029 }
Chris@0 5030
Chris@0 5031 // If event changes its type, use the special event handlers for the changed type
Chris@0 5032 special = jQuery.event.special[ type ] || {};
Chris@0 5033
Chris@0 5034 // If selector defined, determine special event api type, otherwise given type
Chris@0 5035 type = ( selector ? special.delegateType : special.bindType ) || type;
Chris@0 5036
Chris@0 5037 // Update special based on newly reset type
Chris@0 5038 special = jQuery.event.special[ type ] || {};
Chris@0 5039
Chris@0 5040 // handleObj is passed to all event handlers
Chris@0 5041 handleObj = jQuery.extend( {
Chris@0 5042 type: type,
Chris@0 5043 origType: origType,
Chris@0 5044 data: data,
Chris@0 5045 handler: handler,
Chris@0 5046 guid: handler.guid,
Chris@0 5047 selector: selector,
Chris@0 5048 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
Chris@0 5049 namespace: namespaces.join( "." )
Chris@0 5050 }, handleObjIn );
Chris@0 5051
Chris@0 5052 // Init the event handler queue if we're the first
Chris@0 5053 if ( !( handlers = events[ type ] ) ) {
Chris@0 5054 handlers = events[ type ] = [];
Chris@0 5055 handlers.delegateCount = 0;
Chris@0 5056
Chris@0 5057 // Only use addEventListener if the special events handler returns false
Chris@0 5058 if ( !special.setup ||
Chris@0 5059 special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
Chris@0 5060
Chris@0 5061 if ( elem.addEventListener ) {
Chris@0 5062 elem.addEventListener( type, eventHandle );
Chris@0 5063 }
Chris@0 5064 }
Chris@0 5065 }
Chris@0 5066
Chris@0 5067 if ( special.add ) {
Chris@0 5068 special.add.call( elem, handleObj );
Chris@0 5069
Chris@0 5070 if ( !handleObj.handler.guid ) {
Chris@0 5071 handleObj.handler.guid = handler.guid;
Chris@0 5072 }
Chris@0 5073 }
Chris@0 5074
Chris@0 5075 // Add to the element's handler list, delegates in front
Chris@0 5076 if ( selector ) {
Chris@0 5077 handlers.splice( handlers.delegateCount++, 0, handleObj );
Chris@0 5078 } else {
Chris@0 5079 handlers.push( handleObj );
Chris@0 5080 }
Chris@0 5081
Chris@0 5082 // Keep track of which events have ever been used, for event optimization
Chris@0 5083 jQuery.event.global[ type ] = true;
Chris@0 5084 }
Chris@0 5085
Chris@0 5086 },
Chris@0 5087
Chris@0 5088 // Detach an event or set of events from an element
Chris@0 5089 remove: function( elem, types, handler, selector, mappedTypes ) {
Chris@0 5090
Chris@0 5091 var j, origCount, tmp,
Chris@0 5092 events, t, handleObj,
Chris@0 5093 special, handlers, type, namespaces, origType,
Chris@0 5094 elemData = dataPriv.hasData( elem ) && dataPriv.get( elem );
Chris@0 5095
Chris@0 5096 if ( !elemData || !( events = elemData.events ) ) {
Chris@0 5097 return;
Chris@0 5098 }
Chris@0 5099
Chris@0 5100 // Once for each type.namespace in types; type may be omitted
Chris@0 5101 types = ( types || "" ).match( rnothtmlwhite ) || [ "" ];
Chris@0 5102 t = types.length;
Chris@0 5103 while ( t-- ) {
Chris@0 5104 tmp = rtypenamespace.exec( types[ t ] ) || [];
Chris@0 5105 type = origType = tmp[ 1 ];
Chris@0 5106 namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
Chris@0 5107
Chris@0 5108 // Unbind all events (on this namespace, if provided) for the element
Chris@0 5109 if ( !type ) {
Chris@0 5110 for ( type in events ) {
Chris@0 5111 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
Chris@0 5112 }
Chris@0 5113 continue;
Chris@0 5114 }
Chris@0 5115
Chris@0 5116 special = jQuery.event.special[ type ] || {};
Chris@0 5117 type = ( selector ? special.delegateType : special.bindType ) || type;
Chris@0 5118 handlers = events[ type ] || [];
Chris@0 5119 tmp = tmp[ 2 ] &&
Chris@0 5120 new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" );
Chris@0 5121
Chris@0 5122 // Remove matching events
Chris@0 5123 origCount = j = handlers.length;
Chris@0 5124 while ( j-- ) {
Chris@0 5125 handleObj = handlers[ j ];
Chris@0 5126
Chris@0 5127 if ( ( mappedTypes || origType === handleObj.origType ) &&
Chris@0 5128 ( !handler || handler.guid === handleObj.guid ) &&
Chris@0 5129 ( !tmp || tmp.test( handleObj.namespace ) ) &&
Chris@0 5130 ( !selector || selector === handleObj.selector ||
Chris@0 5131 selector === "**" && handleObj.selector ) ) {
Chris@0 5132 handlers.splice( j, 1 );
Chris@0 5133
Chris@0 5134 if ( handleObj.selector ) {
Chris@0 5135 handlers.delegateCount--;
Chris@0 5136 }
Chris@0 5137 if ( special.remove ) {
Chris@0 5138 special.remove.call( elem, handleObj );
Chris@0 5139 }
Chris@0 5140 }
Chris@0 5141 }
Chris@0 5142
Chris@0 5143 // Remove generic event handler if we removed something and no more handlers exist
Chris@0 5144 // (avoids potential for endless recursion during removal of special event handlers)
Chris@0 5145 if ( origCount && !handlers.length ) {
Chris@0 5146 if ( !special.teardown ||
Chris@0 5147 special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
Chris@0 5148
Chris@0 5149 jQuery.removeEvent( elem, type, elemData.handle );
Chris@0 5150 }
Chris@0 5151
Chris@0 5152 delete events[ type ];
Chris@0 5153 }
Chris@0 5154 }
Chris@0 5155
Chris@0 5156 // Remove data and the expando if it's no longer used
Chris@0 5157 if ( jQuery.isEmptyObject( events ) ) {
Chris@0 5158 dataPriv.remove( elem, "handle events" );
Chris@0 5159 }
Chris@0 5160 },
Chris@0 5161
Chris@0 5162 dispatch: function( nativeEvent ) {
Chris@0 5163
Chris@0 5164 // Make a writable jQuery.Event from the native event object
Chris@0 5165 var event = jQuery.event.fix( nativeEvent );
Chris@0 5166
Chris@0 5167 var i, j, ret, matched, handleObj, handlerQueue,
Chris@0 5168 args = new Array( arguments.length ),
Chris@0 5169 handlers = ( dataPriv.get( this, "events" ) || {} )[ event.type ] || [],
Chris@0 5170 special = jQuery.event.special[ event.type ] || {};
Chris@0 5171
Chris@0 5172 // Use the fix-ed jQuery.Event rather than the (read-only) native event
Chris@0 5173 args[ 0 ] = event;
Chris@0 5174
Chris@0 5175 for ( i = 1; i < arguments.length; i++ ) {
Chris@0 5176 args[ i ] = arguments[ i ];
Chris@0 5177 }
Chris@0 5178
Chris@0 5179 event.delegateTarget = this;
Chris@0 5180
Chris@0 5181 // Call the preDispatch hook for the mapped type, and let it bail if desired
Chris@0 5182 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
Chris@0 5183 return;
Chris@0 5184 }
Chris@0 5185
Chris@0 5186 // Determine handlers
Chris@0 5187 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
Chris@0 5188
Chris@0 5189 // Run delegates first; they may want to stop propagation beneath us
Chris@0 5190 i = 0;
Chris@0 5191 while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) {
Chris@0 5192 event.currentTarget = matched.elem;
Chris@0 5193
Chris@0 5194 j = 0;
Chris@0 5195 while ( ( handleObj = matched.handlers[ j++ ] ) &&
Chris@0 5196 !event.isImmediatePropagationStopped() ) {
Chris@0 5197
Chris@0 5198 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
Chris@0 5199 // a subset or equal to those in the bound event (both can have no namespace).
Chris@0 5200 if ( !event.rnamespace || event.rnamespace.test( handleObj.namespace ) ) {
Chris@0 5201
Chris@0 5202 event.handleObj = handleObj;
Chris@0 5203 event.data = handleObj.data;
Chris@0 5204
Chris@0 5205 ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||
Chris@0 5206 handleObj.handler ).apply( matched.elem, args );
Chris@0 5207
Chris@0 5208 if ( ret !== undefined ) {
Chris@0 5209 if ( ( event.result = ret ) === false ) {
Chris@0 5210 event.preventDefault();
Chris@0 5211 event.stopPropagation();
Chris@0 5212 }
Chris@0 5213 }
Chris@0 5214 }
Chris@0 5215 }
Chris@0 5216 }
Chris@0 5217
Chris@0 5218 // Call the postDispatch hook for the mapped type
Chris@0 5219 if ( special.postDispatch ) {
Chris@0 5220 special.postDispatch.call( this, event );
Chris@0 5221 }
Chris@0 5222
Chris@0 5223 return event.result;
Chris@0 5224 },
Chris@0 5225
Chris@0 5226 handlers: function( event, handlers ) {
Chris@0 5227 var i, handleObj, sel, matchedHandlers, matchedSelectors,
Chris@0 5228 handlerQueue = [],
Chris@0 5229 delegateCount = handlers.delegateCount,
Chris@0 5230 cur = event.target;
Chris@0 5231
Chris@0 5232 // Find delegate handlers
Chris@0 5233 if ( delegateCount &&
Chris@0 5234
Chris@0 5235 // Support: IE <=9
Chris@0 5236 // Black-hole SVG <use> instance trees (trac-13180)
Chris@0 5237 cur.nodeType &&
Chris@0 5238
Chris@0 5239 // Support: Firefox <=42
Chris@0 5240 // Suppress spec-violating clicks indicating a non-primary pointer button (trac-3861)
Chris@0 5241 // https://www.w3.org/TR/DOM-Level-3-Events/#event-type-click
Chris@0 5242 // Support: IE 11 only
Chris@0 5243 // ...but not arrow key "clicks" of radio inputs, which can have `button` -1 (gh-2343)
Chris@0 5244 !( event.type === "click" && event.button >= 1 ) ) {
Chris@0 5245
Chris@0 5246 for ( ; cur !== this; cur = cur.parentNode || this ) {
Chris@0 5247
Chris@0 5248 // Don't check non-elements (#13208)
Chris@0 5249 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
Chris@0 5250 if ( cur.nodeType === 1 && !( event.type === "click" && cur.disabled === true ) ) {
Chris@0 5251 matchedHandlers = [];
Chris@0 5252 matchedSelectors = {};
Chris@0 5253 for ( i = 0; i < delegateCount; i++ ) {
Chris@0 5254 handleObj = handlers[ i ];
Chris@0 5255
Chris@0 5256 // Don't conflict with Object.prototype properties (#13203)
Chris@0 5257 sel = handleObj.selector + " ";
Chris@0 5258
Chris@0 5259 if ( matchedSelectors[ sel ] === undefined ) {
Chris@0 5260 matchedSelectors[ sel ] = handleObj.needsContext ?
Chris@0 5261 jQuery( sel, this ).index( cur ) > -1 :
Chris@0 5262 jQuery.find( sel, this, null, [ cur ] ).length;
Chris@0 5263 }
Chris@0 5264 if ( matchedSelectors[ sel ] ) {
Chris@0 5265 matchedHandlers.push( handleObj );
Chris@0 5266 }
Chris@0 5267 }
Chris@0 5268 if ( matchedHandlers.length ) {
Chris@0 5269 handlerQueue.push( { elem: cur, handlers: matchedHandlers } );
Chris@0 5270 }
Chris@0 5271 }
Chris@0 5272 }
Chris@0 5273 }
Chris@0 5274
Chris@0 5275 // Add the remaining (directly-bound) handlers
Chris@0 5276 cur = this;
Chris@0 5277 if ( delegateCount < handlers.length ) {
Chris@0 5278 handlerQueue.push( { elem: cur, handlers: handlers.slice( delegateCount ) } );
Chris@0 5279 }
Chris@0 5280
Chris@0 5281 return handlerQueue;
Chris@0 5282 },
Chris@0 5283
Chris@0 5284 addProp: function( name, hook ) {
Chris@0 5285 Object.defineProperty( jQuery.Event.prototype, name, {
Chris@0 5286 enumerable: true,
Chris@0 5287 configurable: true,
Chris@0 5288
Chris@0 5289 get: jQuery.isFunction( hook ) ?
Chris@0 5290 function() {
Chris@0 5291 if ( this.originalEvent ) {
Chris@0 5292 return hook( this.originalEvent );
Chris@0 5293 }
Chris@0 5294 } :
Chris@0 5295 function() {
Chris@0 5296 if ( this.originalEvent ) {
Chris@0 5297 return this.originalEvent[ name ];
Chris@0 5298 }
Chris@0 5299 },
Chris@0 5300
Chris@0 5301 set: function( value ) {
Chris@0 5302 Object.defineProperty( this, name, {
Chris@0 5303 enumerable: true,
Chris@0 5304 configurable: true,
Chris@0 5305 writable: true,
Chris@0 5306 value: value
Chris@0 5307 } );
Chris@0 5308 }
Chris@0 5309 } );
Chris@0 5310 },
Chris@0 5311
Chris@0 5312 fix: function( originalEvent ) {
Chris@0 5313 return originalEvent[ jQuery.expando ] ?
Chris@0 5314 originalEvent :
Chris@0 5315 new jQuery.Event( originalEvent );
Chris@0 5316 },
Chris@0 5317
Chris@0 5318 special: {
Chris@0 5319 load: {
Chris@0 5320
Chris@0 5321 // Prevent triggered image.load events from bubbling to window.load
Chris@0 5322 noBubble: true
Chris@0 5323 },
Chris@0 5324 focus: {
Chris@0 5325
Chris@0 5326 // Fire native event if possible so blur/focus sequence is correct
Chris@0 5327 trigger: function() {
Chris@0 5328 if ( this !== safeActiveElement() && this.focus ) {
Chris@0 5329 this.focus();
Chris@0 5330 return false;
Chris@0 5331 }
Chris@0 5332 },
Chris@0 5333 delegateType: "focusin"
Chris@0 5334 },
Chris@0 5335 blur: {
Chris@0 5336 trigger: function() {
Chris@0 5337 if ( this === safeActiveElement() && this.blur ) {
Chris@0 5338 this.blur();
Chris@0 5339 return false;
Chris@0 5340 }
Chris@0 5341 },
Chris@0 5342 delegateType: "focusout"
Chris@0 5343 },
Chris@0 5344 click: {
Chris@0 5345
Chris@0 5346 // For checkbox, fire native event so checked state will be right
Chris@0 5347 trigger: function() {
Chris@0 5348 if ( this.type === "checkbox" && this.click && nodeName( this, "input" ) ) {
Chris@0 5349 this.click();
Chris@0 5350 return false;
Chris@0 5351 }
Chris@0 5352 },
Chris@0 5353
Chris@0 5354 // For cross-browser consistency, don't fire native .click() on links
Chris@0 5355 _default: function( event ) {
Chris@0 5356 return nodeName( event.target, "a" );
Chris@0 5357 }
Chris@0 5358 },
Chris@0 5359
Chris@0 5360 beforeunload: {
Chris@0 5361 postDispatch: function( event ) {
Chris@0 5362
Chris@0 5363 // Support: Firefox 20+
Chris@0 5364 // Firefox doesn't alert if the returnValue field is not set.
Chris@0 5365 if ( event.result !== undefined && event.originalEvent ) {
Chris@0 5366 event.originalEvent.returnValue = event.result;
Chris@0 5367 }
Chris@0 5368 }
Chris@0 5369 }
Chris@0 5370 }
Chris@0 5371 };
Chris@0 5372
Chris@0 5373 jQuery.removeEvent = function( elem, type, handle ) {
Chris@0 5374
Chris@0 5375 // This "if" is needed for plain objects
Chris@0 5376 if ( elem.removeEventListener ) {
Chris@0 5377 elem.removeEventListener( type, handle );
Chris@0 5378 }
Chris@0 5379 };
Chris@0 5380
Chris@0 5381 jQuery.Event = function( src, props ) {
Chris@0 5382
Chris@0 5383 // Allow instantiation without the 'new' keyword
Chris@0 5384 if ( !( this instanceof jQuery.Event ) ) {
Chris@0 5385 return new jQuery.Event( src, props );
Chris@0 5386 }
Chris@0 5387
Chris@0 5388 // Event object
Chris@0 5389 if ( src && src.type ) {
Chris@0 5390 this.originalEvent = src;
Chris@0 5391 this.type = src.type;
Chris@0 5392
Chris@0 5393 // Events bubbling up the document may have been marked as prevented
Chris@0 5394 // by a handler lower down the tree; reflect the correct value.
Chris@0 5395 this.isDefaultPrevented = src.defaultPrevented ||
Chris@0 5396 src.defaultPrevented === undefined &&
Chris@0 5397
Chris@0 5398 // Support: Android <=2.3 only
Chris@0 5399 src.returnValue === false ?
Chris@0 5400 returnTrue :
Chris@0 5401 returnFalse;
Chris@0 5402
Chris@0 5403 // Create target properties
Chris@0 5404 // Support: Safari <=6 - 7 only
Chris@0 5405 // Target should not be a text node (#504, #13143)
Chris@0 5406 this.target = ( src.target && src.target.nodeType === 3 ) ?
Chris@0 5407 src.target.parentNode :
Chris@0 5408 src.target;
Chris@0 5409
Chris@0 5410 this.currentTarget = src.currentTarget;
Chris@0 5411 this.relatedTarget = src.relatedTarget;
Chris@0 5412
Chris@0 5413 // Event type
Chris@0 5414 } else {
Chris@0 5415 this.type = src;
Chris@0 5416 }
Chris@0 5417
Chris@0 5418 // Put explicitly provided properties onto the event object
Chris@0 5419 if ( props ) {
Chris@0 5420 jQuery.extend( this, props );
Chris@0 5421 }
Chris@0 5422
Chris@0 5423 // Create a timestamp if incoming event doesn't have one
Chris@0 5424 this.timeStamp = src && src.timeStamp || jQuery.now();
Chris@0 5425
Chris@0 5426 // Mark it as fixed
Chris@0 5427 this[ jQuery.expando ] = true;
Chris@0 5428 };
Chris@0 5429
Chris@0 5430 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
Chris@0 5431 // https://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
Chris@0 5432 jQuery.Event.prototype = {
Chris@0 5433 constructor: jQuery.Event,
Chris@0 5434 isDefaultPrevented: returnFalse,
Chris@0 5435 isPropagationStopped: returnFalse,
Chris@0 5436 isImmediatePropagationStopped: returnFalse,
Chris@0 5437 isSimulated: false,
Chris@0 5438
Chris@0 5439 preventDefault: function() {
Chris@0 5440 var e = this.originalEvent;
Chris@0 5441
Chris@0 5442 this.isDefaultPrevented = returnTrue;
Chris@0 5443
Chris@0 5444 if ( e && !this.isSimulated ) {
Chris@0 5445 e.preventDefault();
Chris@0 5446 }
Chris@0 5447 },
Chris@0 5448 stopPropagation: function() {
Chris@0 5449 var e = this.originalEvent;
Chris@0 5450
Chris@0 5451 this.isPropagationStopped = returnTrue;
Chris@0 5452
Chris@0 5453 if ( e && !this.isSimulated ) {
Chris@0 5454 e.stopPropagation();
Chris@0 5455 }
Chris@0 5456 },
Chris@0 5457 stopImmediatePropagation: function() {
Chris@0 5458 var e = this.originalEvent;
Chris@0 5459
Chris@0 5460 this.isImmediatePropagationStopped = returnTrue;
Chris@0 5461
Chris@0 5462 if ( e && !this.isSimulated ) {
Chris@0 5463 e.stopImmediatePropagation();
Chris@0 5464 }
Chris@0 5465
Chris@0 5466 this.stopPropagation();
Chris@0 5467 }
Chris@0 5468 };
Chris@0 5469
Chris@0 5470 // Includes all common event props including KeyEvent and MouseEvent specific props
Chris@0 5471 jQuery.each( {
Chris@0 5472 altKey: true,
Chris@0 5473 bubbles: true,
Chris@0 5474 cancelable: true,
Chris@0 5475 changedTouches: true,
Chris@0 5476 ctrlKey: true,
Chris@0 5477 detail: true,
Chris@0 5478 eventPhase: true,
Chris@0 5479 metaKey: true,
Chris@0 5480 pageX: true,
Chris@0 5481 pageY: true,
Chris@0 5482 shiftKey: true,
Chris@0 5483 view: true,
Chris@0 5484 "char": true,
Chris@0 5485 charCode: true,
Chris@0 5486 key: true,
Chris@0 5487 keyCode: true,
Chris@0 5488 button: true,
Chris@0 5489 buttons: true,
Chris@0 5490 clientX: true,
Chris@0 5491 clientY: true,
Chris@0 5492 offsetX: true,
Chris@0 5493 offsetY: true,
Chris@0 5494 pointerId: true,
Chris@0 5495 pointerType: true,
Chris@0 5496 screenX: true,
Chris@0 5497 screenY: true,
Chris@0 5498 targetTouches: true,
Chris@0 5499 toElement: true,
Chris@0 5500 touches: true,
Chris@0 5501
Chris@0 5502 which: function( event ) {
Chris@0 5503 var button = event.button;
Chris@0 5504
Chris@0 5505 // Add which for key events
Chris@0 5506 if ( event.which == null && rkeyEvent.test( event.type ) ) {
Chris@0 5507 return event.charCode != null ? event.charCode : event.keyCode;
Chris@0 5508 }
Chris@0 5509
Chris@0 5510 // Add which for click: 1 === left; 2 === middle; 3 === right
Chris@0 5511 if ( !event.which && button !== undefined && rmouseEvent.test( event.type ) ) {
Chris@0 5512 if ( button & 1 ) {
Chris@0 5513 return 1;
Chris@0 5514 }
Chris@0 5515
Chris@0 5516 if ( button & 2 ) {
Chris@0 5517 return 3;
Chris@0 5518 }
Chris@0 5519
Chris@0 5520 if ( button & 4 ) {
Chris@0 5521 return 2;
Chris@0 5522 }
Chris@0 5523
Chris@0 5524 return 0;
Chris@0 5525 }
Chris@0 5526
Chris@0 5527 return event.which;
Chris@0 5528 }
Chris@0 5529 }, jQuery.event.addProp );
Chris@0 5530
Chris@0 5531 // Create mouseenter/leave events using mouseover/out and event-time checks
Chris@0 5532 // so that event delegation works in jQuery.
Chris@0 5533 // Do the same for pointerenter/pointerleave and pointerover/pointerout
Chris@0 5534 //
Chris@0 5535 // Support: Safari 7 only
Chris@0 5536 // Safari sends mouseenter too often; see:
Chris@0 5537 // https://bugs.chromium.org/p/chromium/issues/detail?id=470258
Chris@0 5538 // for the description of the bug (it existed in older Chrome versions as well).
Chris@0 5539 jQuery.each( {
Chris@0 5540 mouseenter: "mouseover",
Chris@0 5541 mouseleave: "mouseout",
Chris@0 5542 pointerenter: "pointerover",
Chris@0 5543 pointerleave: "pointerout"
Chris@0 5544 }, function( orig, fix ) {
Chris@0 5545 jQuery.event.special[ orig ] = {
Chris@0 5546 delegateType: fix,
Chris@0 5547 bindType: fix,
Chris@0 5548
Chris@0 5549 handle: function( event ) {
Chris@0 5550 var ret,
Chris@0 5551 target = this,
Chris@0 5552 related = event.relatedTarget,
Chris@0 5553 handleObj = event.handleObj;
Chris@0 5554
Chris@0 5555 // For mouseenter/leave call the handler if related is outside the target.
Chris@0 5556 // NB: No relatedTarget if the mouse left/entered the browser window
Chris@0 5557 if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) {
Chris@0 5558 event.type = handleObj.origType;
Chris@0 5559 ret = handleObj.handler.apply( this, arguments );
Chris@0 5560 event.type = fix;
Chris@0 5561 }
Chris@0 5562 return ret;
Chris@0 5563 }
Chris@0 5564 };
Chris@0 5565 } );
Chris@0 5566
Chris@0 5567 jQuery.fn.extend( {
Chris@0 5568
Chris@0 5569 on: function( types, selector, data, fn ) {
Chris@0 5570 return on( this, types, selector, data, fn );
Chris@0 5571 },
Chris@0 5572 one: function( types, selector, data, fn ) {
Chris@0 5573 return on( this, types, selector, data, fn, 1 );
Chris@0 5574 },
Chris@0 5575 off: function( types, selector, fn ) {
Chris@0 5576 var handleObj, type;
Chris@0 5577 if ( types && types.preventDefault && types.handleObj ) {
Chris@0 5578
Chris@0 5579 // ( event ) dispatched jQuery.Event
Chris@0 5580 handleObj = types.handleObj;
Chris@0 5581 jQuery( types.delegateTarget ).off(
Chris@0 5582 handleObj.namespace ?
Chris@0 5583 handleObj.origType + "." + handleObj.namespace :
Chris@0 5584 handleObj.origType,
Chris@0 5585 handleObj.selector,
Chris@0 5586 handleObj.handler
Chris@0 5587 );
Chris@0 5588 return this;
Chris@0 5589 }
Chris@0 5590 if ( typeof types === "object" ) {
Chris@0 5591
Chris@0 5592 // ( types-object [, selector] )
Chris@0 5593 for ( type in types ) {
Chris@0 5594 this.off( type, selector, types[ type ] );
Chris@0 5595 }
Chris@0 5596 return this;
Chris@0 5597 }
Chris@0 5598 if ( selector === false || typeof selector === "function" ) {
Chris@0 5599
Chris@0 5600 // ( types [, fn] )
Chris@0 5601 fn = selector;
Chris@0 5602 selector = undefined;
Chris@0 5603 }
Chris@0 5604 if ( fn === false ) {
Chris@0 5605 fn = returnFalse;
Chris@0 5606 }
Chris@0 5607 return this.each( function() {
Chris@0 5608 jQuery.event.remove( this, types, fn, selector );
Chris@0 5609 } );
Chris@0 5610 }
Chris@0 5611 } );
Chris@0 5612
Chris@0 5613
Chris@0 5614 var
Chris@0 5615
Chris@0 5616 /* eslint-disable max-len */
Chris@0 5617
Chris@0 5618 // See https://github.com/eslint/eslint/issues/3229
Chris@0 5619 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi,
Chris@0 5620
Chris@0 5621 /* eslint-enable */
Chris@0 5622
Chris@0 5623 // Support: IE <=10 - 11, Edge 12 - 13
Chris@0 5624 // In IE/Edge using regex groups here causes severe slowdowns.
Chris@0 5625 // See https://connect.microsoft.com/IE/feedback/details/1736512/
Chris@0 5626 rnoInnerhtml = /<script|<style|<link/i,
Chris@0 5627
Chris@0 5628 // checked="checked" or checked
Chris@0 5629 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
Chris@0 5630 rscriptTypeMasked = /^true\/(.*)/,
Chris@0 5631 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
Chris@0 5632
Chris@0 5633 // Prefer a tbody over its parent table for containing new rows
Chris@0 5634 function manipulationTarget( elem, content ) {
Chris@0 5635 if ( nodeName( elem, "table" ) &&
Chris@0 5636 nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ) {
Chris@0 5637
Chris@0 5638 return jQuery( ">tbody", elem )[ 0 ] || elem;
Chris@0 5639 }
Chris@0 5640
Chris@0 5641 return elem;
Chris@0 5642 }
Chris@0 5643
Chris@0 5644 // Replace/restore the type attribute of script elements for safe DOM manipulation
Chris@0 5645 function disableScript( elem ) {
Chris@0 5646 elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type;
Chris@0 5647 return elem;
Chris@0 5648 }
Chris@0 5649 function restoreScript( elem ) {
Chris@0 5650 var match = rscriptTypeMasked.exec( elem.type );
Chris@0 5651
Chris@0 5652 if ( match ) {
Chris@0 5653 elem.type = match[ 1 ];
Chris@0 5654 } else {
Chris@0 5655 elem.removeAttribute( "type" );
Chris@0 5656 }
Chris@0 5657
Chris@0 5658 return elem;
Chris@0 5659 }
Chris@0 5660
Chris@0 5661 function cloneCopyEvent( src, dest ) {
Chris@0 5662 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
Chris@0 5663
Chris@0 5664 if ( dest.nodeType !== 1 ) {
Chris@0 5665 return;
Chris@0 5666 }
Chris@0 5667
Chris@0 5668 // 1. Copy private data: events, handlers, etc.
Chris@0 5669 if ( dataPriv.hasData( src ) ) {
Chris@0 5670 pdataOld = dataPriv.access( src );
Chris@0 5671 pdataCur = dataPriv.set( dest, pdataOld );
Chris@0 5672 events = pdataOld.events;
Chris@0 5673
Chris@0 5674 if ( events ) {
Chris@0 5675 delete pdataCur.handle;
Chris@0 5676 pdataCur.events = {};
Chris@0 5677
Chris@0 5678 for ( type in events ) {
Chris@0 5679 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
Chris@0 5680 jQuery.event.add( dest, type, events[ type ][ i ] );
Chris@0 5681 }
Chris@0 5682 }
Chris@0 5683 }
Chris@0 5684 }
Chris@0 5685
Chris@0 5686 // 2. Copy user data
Chris@0 5687 if ( dataUser.hasData( src ) ) {
Chris@0 5688 udataOld = dataUser.access( src );
Chris@0 5689 udataCur = jQuery.extend( {}, udataOld );
Chris@0 5690
Chris@0 5691 dataUser.set( dest, udataCur );
Chris@0 5692 }
Chris@0 5693 }
Chris@0 5694
Chris@0 5695 // Fix IE bugs, see support tests
Chris@0 5696 function fixInput( src, dest ) {
Chris@0 5697 var nodeName = dest.nodeName.toLowerCase();
Chris@0 5698
Chris@0 5699 // Fails to persist the checked state of a cloned checkbox or radio button.
Chris@0 5700 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
Chris@0 5701 dest.checked = src.checked;
Chris@0 5702
Chris@0 5703 // Fails to return the selected option to the default selected state when cloning options
Chris@0 5704 } else if ( nodeName === "input" || nodeName === "textarea" ) {
Chris@0 5705 dest.defaultValue = src.defaultValue;
Chris@0 5706 }
Chris@0 5707 }
Chris@0 5708
Chris@0 5709 function domManip( collection, args, callback, ignored ) {
Chris@0 5710
Chris@0 5711 // Flatten any nested arrays
Chris@0 5712 args = concat.apply( [], args );
Chris@0 5713
Chris@0 5714 var fragment, first, scripts, hasScripts, node, doc,
Chris@0 5715 i = 0,
Chris@0 5716 l = collection.length,
Chris@0 5717 iNoClone = l - 1,
Chris@0 5718 value = args[ 0 ],
Chris@0 5719 isFunction = jQuery.isFunction( value );
Chris@0 5720
Chris@0 5721 // We can't cloneNode fragments that contain checked, in WebKit
Chris@0 5722 if ( isFunction ||
Chris@0 5723 ( l > 1 && typeof value === "string" &&
Chris@0 5724 !support.checkClone && rchecked.test( value ) ) ) {
Chris@0 5725 return collection.each( function( index ) {
Chris@0 5726 var self = collection.eq( index );
Chris@0 5727 if ( isFunction ) {
Chris@0 5728 args[ 0 ] = value.call( this, index, self.html() );
Chris@0 5729 }
Chris@0 5730 domManip( self, args, callback, ignored );
Chris@0 5731 } );
Chris@0 5732 }
Chris@0 5733
Chris@0 5734 if ( l ) {
Chris@0 5735 fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
Chris@0 5736 first = fragment.firstChild;
Chris@0 5737
Chris@0 5738 if ( fragment.childNodes.length === 1 ) {
Chris@0 5739 fragment = first;
Chris@0 5740 }
Chris@0 5741
Chris@0 5742 // Require either new content or an interest in ignored elements to invoke the callback
Chris@0 5743 if ( first || ignored ) {
Chris@0 5744 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
Chris@0 5745 hasScripts = scripts.length;
Chris@0 5746
Chris@0 5747 // Use the original fragment for the last item
Chris@0 5748 // instead of the first because it can end up
Chris@0 5749 // being emptied incorrectly in certain situations (#8070).
Chris@0 5750 for ( ; i < l; i++ ) {
Chris@0 5751 node = fragment;
Chris@0 5752
Chris@0 5753 if ( i !== iNoClone ) {
Chris@0 5754 node = jQuery.clone( node, true, true );
Chris@0 5755
Chris@0 5756 // Keep references to cloned scripts for later restoration
Chris@0 5757 if ( hasScripts ) {
Chris@0 5758
Chris@0 5759 // Support: Android <=4.0 only, PhantomJS 1 only
Chris@0 5760 // push.apply(_, arraylike) throws on ancient WebKit
Chris@0 5761 jQuery.merge( scripts, getAll( node, "script" ) );
Chris@0 5762 }
Chris@0 5763 }
Chris@0 5764
Chris@0 5765 callback.call( collection[ i ], node, i );
Chris@0 5766 }
Chris@0 5767
Chris@0 5768 if ( hasScripts ) {
Chris@0 5769 doc = scripts[ scripts.length - 1 ].ownerDocument;
Chris@0 5770
Chris@0 5771 // Reenable scripts
Chris@0 5772 jQuery.map( scripts, restoreScript );
Chris@0 5773
Chris@0 5774 // Evaluate executable scripts on first document insertion
Chris@0 5775 for ( i = 0; i < hasScripts; i++ ) {
Chris@0 5776 node = scripts[ i ];
Chris@0 5777 if ( rscriptType.test( node.type || "" ) &&
Chris@0 5778 !dataPriv.access( node, "globalEval" ) &&
Chris@0 5779 jQuery.contains( doc, node ) ) {
Chris@0 5780
Chris@0 5781 if ( node.src ) {
Chris@0 5782
Chris@0 5783 // Optional AJAX dependency, but won't run scripts if not present
Chris@0 5784 if ( jQuery._evalUrl ) {
Chris@0 5785 jQuery._evalUrl( node.src );
Chris@0 5786 }
Chris@0 5787 } else {
Chris@0 5788 DOMEval( node.textContent.replace( rcleanScript, "" ), doc );
Chris@0 5789 }
Chris@0 5790 }
Chris@0 5791 }
Chris@0 5792 }
Chris@0 5793 }
Chris@0 5794 }
Chris@0 5795
Chris@0 5796 return collection;
Chris@0 5797 }
Chris@0 5798
Chris@0 5799 function remove( elem, selector, keepData ) {
Chris@0 5800 var node,
Chris@0 5801 nodes = selector ? jQuery.filter( selector, elem ) : elem,
Chris@0 5802 i = 0;
Chris@0 5803
Chris@0 5804 for ( ; ( node = nodes[ i ] ) != null; i++ ) {
Chris@0 5805 if ( !keepData && node.nodeType === 1 ) {
Chris@0 5806 jQuery.cleanData( getAll( node ) );
Chris@0 5807 }
Chris@0 5808
Chris@0 5809 if ( node.parentNode ) {
Chris@0 5810 if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
Chris@0 5811 setGlobalEval( getAll( node, "script" ) );
Chris@0 5812 }
Chris@0 5813 node.parentNode.removeChild( node );
Chris@0 5814 }
Chris@0 5815 }
Chris@0 5816
Chris@0 5817 return elem;
Chris@0 5818 }
Chris@0 5819
Chris@0 5820 jQuery.extend( {
Chris@0 5821 htmlPrefilter: function( html ) {
Chris@0 5822 return html.replace( rxhtmlTag, "<$1></$2>" );
Chris@0 5823 },
Chris@0 5824
Chris@0 5825 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
Chris@0 5826 var i, l, srcElements, destElements,
Chris@0 5827 clone = elem.cloneNode( true ),
Chris@0 5828 inPage = jQuery.contains( elem.ownerDocument, elem );
Chris@0 5829
Chris@0 5830 // Fix IE cloning issues
Chris@0 5831 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
Chris@0 5832 !jQuery.isXMLDoc( elem ) ) {
Chris@0 5833
Chris@0 5834 // We eschew Sizzle here for performance reasons: https://jsperf.com/getall-vs-sizzle/2
Chris@0 5835 destElements = getAll( clone );
Chris@0 5836 srcElements = getAll( elem );
Chris@0 5837
Chris@0 5838 for ( i = 0, l = srcElements.length; i < l; i++ ) {
Chris@0 5839 fixInput( srcElements[ i ], destElements[ i ] );
Chris@0 5840 }
Chris@0 5841 }
Chris@0 5842
Chris@0 5843 // Copy the events from the original to the clone
Chris@0 5844 if ( dataAndEvents ) {
Chris@0 5845 if ( deepDataAndEvents ) {
Chris@0 5846 srcElements = srcElements || getAll( elem );
Chris@0 5847 destElements = destElements || getAll( clone );
Chris@0 5848
Chris@0 5849 for ( i = 0, l = srcElements.length; i < l; i++ ) {
Chris@0 5850 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
Chris@0 5851 }
Chris@0 5852 } else {
Chris@0 5853 cloneCopyEvent( elem, clone );
Chris@0 5854 }
Chris@0 5855 }
Chris@0 5856
Chris@0 5857 // Preserve script evaluation history
Chris@0 5858 destElements = getAll( clone, "script" );
Chris@0 5859 if ( destElements.length > 0 ) {
Chris@0 5860 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
Chris@0 5861 }
Chris@0 5862
Chris@0 5863 // Return the cloned set
Chris@0 5864 return clone;
Chris@0 5865 },
Chris@0 5866
Chris@0 5867 cleanData: function( elems ) {
Chris@0 5868 var data, elem, type,
Chris@0 5869 special = jQuery.event.special,
Chris@0 5870 i = 0;
Chris@0 5871
Chris@0 5872 for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
Chris@0 5873 if ( acceptData( elem ) ) {
Chris@0 5874 if ( ( data = elem[ dataPriv.expando ] ) ) {
Chris@0 5875 if ( data.events ) {
Chris@0 5876 for ( type in data.events ) {
Chris@0 5877 if ( special[ type ] ) {
Chris@0 5878 jQuery.event.remove( elem, type );
Chris@0 5879
Chris@0 5880 // This is a shortcut to avoid jQuery.event.remove's overhead
Chris@0 5881 } else {
Chris@0 5882 jQuery.removeEvent( elem, type, data.handle );
Chris@0 5883 }
Chris@0 5884 }
Chris@0 5885 }
Chris@0 5886
Chris@0 5887 // Support: Chrome <=35 - 45+
Chris@0 5888 // Assign undefined instead of using delete, see Data#remove
Chris@0 5889 elem[ dataPriv.expando ] = undefined;
Chris@0 5890 }
Chris@0 5891 if ( elem[ dataUser.expando ] ) {
Chris@0 5892
Chris@0 5893 // Support: Chrome <=35 - 45+
Chris@0 5894 // Assign undefined instead of using delete, see Data#remove
Chris@0 5895 elem[ dataUser.expando ] = undefined;
Chris@0 5896 }
Chris@0 5897 }
Chris@0 5898 }
Chris@0 5899 }
Chris@0 5900 } );
Chris@0 5901
Chris@0 5902 jQuery.fn.extend( {
Chris@0 5903 detach: function( selector ) {
Chris@0 5904 return remove( this, selector, true );
Chris@0 5905 },
Chris@0 5906
Chris@0 5907 remove: function( selector ) {
Chris@0 5908 return remove( this, selector );
Chris@0 5909 },
Chris@0 5910
Chris@0 5911 text: function( value ) {
Chris@0 5912 return access( this, function( value ) {
Chris@0 5913 return value === undefined ?
Chris@0 5914 jQuery.text( this ) :
Chris@0 5915 this.empty().each( function() {
Chris@0 5916 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
Chris@0 5917 this.textContent = value;
Chris@0 5918 }
Chris@0 5919 } );
Chris@0 5920 }, null, value, arguments.length );
Chris@0 5921 },
Chris@0 5922
Chris@0 5923 append: function() {
Chris@0 5924 return domManip( this, arguments, function( elem ) {
Chris@0 5925 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
Chris@0 5926 var target = manipulationTarget( this, elem );
Chris@0 5927 target.appendChild( elem );
Chris@0 5928 }
Chris@0 5929 } );
Chris@0 5930 },
Chris@0 5931
Chris@0 5932 prepend: function() {
Chris@0 5933 return domManip( this, arguments, function( elem ) {
Chris@0 5934 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
Chris@0 5935 var target = manipulationTarget( this, elem );
Chris@0 5936 target.insertBefore( elem, target.firstChild );
Chris@0 5937 }
Chris@0 5938 } );
Chris@0 5939 },
Chris@0 5940
Chris@0 5941 before: function() {
Chris@0 5942 return domManip( this, arguments, function( elem ) {
Chris@0 5943 if ( this.parentNode ) {
Chris@0 5944 this.parentNode.insertBefore( elem, this );
Chris@0 5945 }
Chris@0 5946 } );
Chris@0 5947 },
Chris@0 5948
Chris@0 5949 after: function() {
Chris@0 5950 return domManip( this, arguments, function( elem ) {
Chris@0 5951 if ( this.parentNode ) {
Chris@0 5952 this.parentNode.insertBefore( elem, this.nextSibling );
Chris@0 5953 }
Chris@0 5954 } );
Chris@0 5955 },
Chris@0 5956
Chris@0 5957 empty: function() {
Chris@0 5958 var elem,
Chris@0 5959 i = 0;
Chris@0 5960
Chris@0 5961 for ( ; ( elem = this[ i ] ) != null; i++ ) {
Chris@0 5962 if ( elem.nodeType === 1 ) {
Chris@0 5963
Chris@0 5964 // Prevent memory leaks
Chris@0 5965 jQuery.cleanData( getAll( elem, false ) );
Chris@0 5966
Chris@0 5967 // Remove any remaining nodes
Chris@0 5968 elem.textContent = "";
Chris@0 5969 }
Chris@0 5970 }
Chris@0 5971
Chris@0 5972 return this;
Chris@0 5973 },
Chris@0 5974
Chris@0 5975 clone: function( dataAndEvents, deepDataAndEvents ) {
Chris@0 5976 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
Chris@0 5977 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
Chris@0 5978
Chris@0 5979 return this.map( function() {
Chris@0 5980 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
Chris@0 5981 } );
Chris@0 5982 },
Chris@0 5983
Chris@0 5984 html: function( value ) {
Chris@0 5985 return access( this, function( value ) {
Chris@0 5986 var elem = this[ 0 ] || {},
Chris@0 5987 i = 0,
Chris@0 5988 l = this.length;
Chris@0 5989
Chris@0 5990 if ( value === undefined && elem.nodeType === 1 ) {
Chris@0 5991 return elem.innerHTML;
Chris@0 5992 }
Chris@0 5993
Chris@0 5994 // See if we can take a shortcut and just use innerHTML
Chris@0 5995 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
Chris@0 5996 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
Chris@0 5997
Chris@0 5998 value = jQuery.htmlPrefilter( value );
Chris@0 5999
Chris@0 6000 try {
Chris@0 6001 for ( ; i < l; i++ ) {
Chris@0 6002 elem = this[ i ] || {};
Chris@0 6003
Chris@0 6004 // Remove element nodes and prevent memory leaks
Chris@0 6005 if ( elem.nodeType === 1 ) {
Chris@0 6006 jQuery.cleanData( getAll( elem, false ) );
Chris@0 6007 elem.innerHTML = value;
Chris@0 6008 }
Chris@0 6009 }
Chris@0 6010
Chris@0 6011 elem = 0;
Chris@0 6012
Chris@0 6013 // If using innerHTML throws an exception, use the fallback method
Chris@0 6014 } catch ( e ) {}
Chris@0 6015 }
Chris@0 6016
Chris@0 6017 if ( elem ) {
Chris@0 6018 this.empty().append( value );
Chris@0 6019 }
Chris@0 6020 }, null, value, arguments.length );
Chris@0 6021 },
Chris@0 6022
Chris@0 6023 replaceWith: function() {
Chris@0 6024 var ignored = [];
Chris@0 6025
Chris@0 6026 // Make the changes, replacing each non-ignored context element with the new content
Chris@0 6027 return domManip( this, arguments, function( elem ) {
Chris@0 6028 var parent = this.parentNode;
Chris@0 6029
Chris@0 6030 if ( jQuery.inArray( this, ignored ) < 0 ) {
Chris@0 6031 jQuery.cleanData( getAll( this ) );
Chris@0 6032 if ( parent ) {
Chris@0 6033 parent.replaceChild( elem, this );
Chris@0 6034 }
Chris@0 6035 }
Chris@0 6036
Chris@0 6037 // Force callback invocation
Chris@0 6038 }, ignored );
Chris@0 6039 }
Chris@0 6040 } );
Chris@0 6041
Chris@0 6042 jQuery.each( {
Chris@0 6043 appendTo: "append",
Chris@0 6044 prependTo: "prepend",
Chris@0 6045 insertBefore: "before",
Chris@0 6046 insertAfter: "after",
Chris@0 6047 replaceAll: "replaceWith"
Chris@0 6048 }, function( name, original ) {
Chris@0 6049 jQuery.fn[ name ] = function( selector ) {
Chris@0 6050 var elems,
Chris@0 6051 ret = [],
Chris@0 6052 insert = jQuery( selector ),
Chris@0 6053 last = insert.length - 1,
Chris@0 6054 i = 0;
Chris@0 6055
Chris@0 6056 for ( ; i <= last; i++ ) {
Chris@0 6057 elems = i === last ? this : this.clone( true );
Chris@0 6058 jQuery( insert[ i ] )[ original ]( elems );
Chris@0 6059
Chris@0 6060 // Support: Android <=4.0 only, PhantomJS 1 only
Chris@0 6061 // .get() because push.apply(_, arraylike) throws on ancient WebKit
Chris@0 6062 push.apply( ret, elems.get() );
Chris@0 6063 }
Chris@0 6064
Chris@0 6065 return this.pushStack( ret );
Chris@0 6066 };
Chris@0 6067 } );
Chris@0 6068 var rmargin = ( /^margin/ );
Chris@0 6069
Chris@0 6070 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
Chris@0 6071
Chris@0 6072 var getStyles = function( elem ) {
Chris@0 6073
Chris@0 6074 // Support: IE <=11 only, Firefox <=30 (#15098, #14150)
Chris@0 6075 // IE throws on elements created in popups
Chris@0 6076 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
Chris@0 6077 var view = elem.ownerDocument.defaultView;
Chris@0 6078
Chris@0 6079 if ( !view || !view.opener ) {
Chris@0 6080 view = window;
Chris@0 6081 }
Chris@0 6082
Chris@0 6083 return view.getComputedStyle( elem );
Chris@0 6084 };
Chris@0 6085
Chris@0 6086
Chris@0 6087
Chris@0 6088 ( function() {
Chris@0 6089
Chris@0 6090 // Executing both pixelPosition & boxSizingReliable tests require only one layout
Chris@0 6091 // so they're executed at the same time to save the second computation.
Chris@0 6092 function computeStyleTests() {
Chris@0 6093
Chris@0 6094 // This is a singleton, we need to execute it only once
Chris@0 6095 if ( !div ) {
Chris@0 6096 return;
Chris@0 6097 }
Chris@0 6098
Chris@0 6099 div.style.cssText =
Chris@0 6100 "box-sizing:border-box;" +
Chris@0 6101 "position:relative;display:block;" +
Chris@0 6102 "margin:auto;border:1px;padding:1px;" +
Chris@0 6103 "top:1%;width:50%";
Chris@0 6104 div.innerHTML = "";
Chris@0 6105 documentElement.appendChild( container );
Chris@0 6106
Chris@0 6107 var divStyle = window.getComputedStyle( div );
Chris@0 6108 pixelPositionVal = divStyle.top !== "1%";
Chris@0 6109
Chris@0 6110 // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44
Chris@0 6111 reliableMarginLeftVal = divStyle.marginLeft === "2px";
Chris@0 6112 boxSizingReliableVal = divStyle.width === "4px";
Chris@0 6113
Chris@0 6114 // Support: Android 4.0 - 4.3 only
Chris@0 6115 // Some styles come back with percentage values, even though they shouldn't
Chris@0 6116 div.style.marginRight = "50%";
Chris@0 6117 pixelMarginRightVal = divStyle.marginRight === "4px";
Chris@0 6118
Chris@0 6119 documentElement.removeChild( container );
Chris@0 6120
Chris@0 6121 // Nullify the div so it wouldn't be stored in the memory and
Chris@0 6122 // it will also be a sign that checks already performed
Chris@0 6123 div = null;
Chris@0 6124 }
Chris@0 6125
Chris@0 6126 var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal, reliableMarginLeftVal,
Chris@0 6127 container = document.createElement( "div" ),
Chris@0 6128 div = document.createElement( "div" );
Chris@0 6129
Chris@0 6130 // Finish early in limited (non-browser) environments
Chris@0 6131 if ( !div.style ) {
Chris@0 6132 return;
Chris@0 6133 }
Chris@0 6134
Chris@0 6135 // Support: IE <=9 - 11 only
Chris@0 6136 // Style of cloned element affects source element cloned (#8908)
Chris@0 6137 div.style.backgroundClip = "content-box";
Chris@0 6138 div.cloneNode( true ).style.backgroundClip = "";
Chris@0 6139 support.clearCloneStyle = div.style.backgroundClip === "content-box";
Chris@0 6140
Chris@0 6141 container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
Chris@0 6142 "padding:0;margin-top:1px;position:absolute";
Chris@0 6143 container.appendChild( div );
Chris@0 6144
Chris@0 6145 jQuery.extend( support, {
Chris@0 6146 pixelPosition: function() {
Chris@0 6147 computeStyleTests();
Chris@0 6148 return pixelPositionVal;
Chris@0 6149 },
Chris@0 6150 boxSizingReliable: function() {
Chris@0 6151 computeStyleTests();
Chris@0 6152 return boxSizingReliableVal;
Chris@0 6153 },
Chris@0 6154 pixelMarginRight: function() {
Chris@0 6155 computeStyleTests();
Chris@0 6156 return pixelMarginRightVal;
Chris@0 6157 },
Chris@0 6158 reliableMarginLeft: function() {
Chris@0 6159 computeStyleTests();
Chris@0 6160 return reliableMarginLeftVal;
Chris@0 6161 }
Chris@0 6162 } );
Chris@0 6163 } )();
Chris@0 6164
Chris@0 6165
Chris@0 6166 function curCSS( elem, name, computed ) {
Chris@0 6167 var width, minWidth, maxWidth, ret,
Chris@0 6168
Chris@0 6169 // Support: Firefox 51+
Chris@0 6170 // Retrieving style before computed somehow
Chris@0 6171 // fixes an issue with getting wrong values
Chris@0 6172 // on detached elements
Chris@0 6173 style = elem.style;
Chris@0 6174
Chris@0 6175 computed = computed || getStyles( elem );
Chris@0 6176
Chris@0 6177 // getPropertyValue is needed for:
Chris@0 6178 // .css('filter') (IE 9 only, #12537)
Chris@0 6179 // .css('--customProperty) (#3144)
Chris@0 6180 if ( computed ) {
Chris@0 6181 ret = computed.getPropertyValue( name ) || computed[ name ];
Chris@0 6182
Chris@0 6183 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
Chris@0 6184 ret = jQuery.style( elem, name );
Chris@0 6185 }
Chris@0 6186
Chris@0 6187 // A tribute to the "awesome hack by Dean Edwards"
Chris@0 6188 // Android Browser returns percentage for some values,
Chris@0 6189 // but width seems to be reliably pixels.
Chris@0 6190 // This is against the CSSOM draft spec:
Chris@0 6191 // https://drafts.csswg.org/cssom/#resolved-values
Chris@0 6192 if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
Chris@0 6193
Chris@0 6194 // Remember the original values
Chris@0 6195 width = style.width;
Chris@0 6196 minWidth = style.minWidth;
Chris@0 6197 maxWidth = style.maxWidth;
Chris@0 6198
Chris@0 6199 // Put in the new values to get a computed value out
Chris@0 6200 style.minWidth = style.maxWidth = style.width = ret;
Chris@0 6201 ret = computed.width;
Chris@0 6202
Chris@0 6203 // Revert the changed values
Chris@0 6204 style.width = width;
Chris@0 6205 style.minWidth = minWidth;
Chris@0 6206 style.maxWidth = maxWidth;
Chris@0 6207 }
Chris@0 6208 }
Chris@0 6209
Chris@0 6210 return ret !== undefined ?
Chris@0 6211
Chris@0 6212 // Support: IE <=9 - 11 only
Chris@0 6213 // IE returns zIndex value as an integer.
Chris@0 6214 ret + "" :
Chris@0 6215 ret;
Chris@0 6216 }
Chris@0 6217
Chris@0 6218
Chris@0 6219 function addGetHookIf( conditionFn, hookFn ) {
Chris@0 6220
Chris@0 6221 // Define the hook, we'll check on the first run if it's really needed.
Chris@0 6222 return {
Chris@0 6223 get: function() {
Chris@0 6224 if ( conditionFn() ) {
Chris@0 6225
Chris@0 6226 // Hook not needed (or it's not possible to use it due
Chris@0 6227 // to missing dependency), remove it.
Chris@0 6228 delete this.get;
Chris@0 6229 return;
Chris@0 6230 }
Chris@0 6231
Chris@0 6232 // Hook needed; redefine it so that the support test is not executed again.
Chris@0 6233 return ( this.get = hookFn ).apply( this, arguments );
Chris@0 6234 }
Chris@0 6235 };
Chris@0 6236 }
Chris@0 6237
Chris@0 6238
Chris@0 6239 var
Chris@0 6240
Chris@0 6241 // Swappable if display is none or starts with table
Chris@0 6242 // except "table", "table-cell", or "table-caption"
Chris@0 6243 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
Chris@0 6244 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
Chris@0 6245 rcustomProp = /^--/,
Chris@0 6246 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
Chris@0 6247 cssNormalTransform = {
Chris@0 6248 letterSpacing: "0",
Chris@0 6249 fontWeight: "400"
Chris@0 6250 },
Chris@0 6251
Chris@0 6252 cssPrefixes = [ "Webkit", "Moz", "ms" ],
Chris@0 6253 emptyStyle = document.createElement( "div" ).style;
Chris@0 6254
Chris@0 6255 // Return a css property mapped to a potentially vendor prefixed property
Chris@0 6256 function vendorPropName( name ) {
Chris@0 6257
Chris@0 6258 // Shortcut for names that are not vendor prefixed
Chris@0 6259 if ( name in emptyStyle ) {
Chris@0 6260 return name;
Chris@0 6261 }
Chris@0 6262
Chris@0 6263 // Check for vendor prefixed names
Chris@0 6264 var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
Chris@0 6265 i = cssPrefixes.length;
Chris@0 6266
Chris@0 6267 while ( i-- ) {
Chris@0 6268 name = cssPrefixes[ i ] + capName;
Chris@0 6269 if ( name in emptyStyle ) {
Chris@0 6270 return name;
Chris@0 6271 }
Chris@0 6272 }
Chris@0 6273 }
Chris@0 6274
Chris@0 6275 // Return a property mapped along what jQuery.cssProps suggests or to
Chris@0 6276 // a vendor prefixed property.
Chris@0 6277 function finalPropName( name ) {
Chris@0 6278 var ret = jQuery.cssProps[ name ];
Chris@0 6279 if ( !ret ) {
Chris@0 6280 ret = jQuery.cssProps[ name ] = vendorPropName( name ) || name;
Chris@0 6281 }
Chris@0 6282 return ret;
Chris@0 6283 }
Chris@0 6284
Chris@0 6285 function setPositiveNumber( elem, value, subtract ) {
Chris@0 6286
Chris@0 6287 // Any relative (+/-) values have already been
Chris@0 6288 // normalized at this point
Chris@0 6289 var matches = rcssNum.exec( value );
Chris@0 6290 return matches ?
Chris@0 6291
Chris@0 6292 // Guard against undefined "subtract", e.g., when used as in cssHooks
Chris@0 6293 Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
Chris@0 6294 value;
Chris@0 6295 }
Chris@0 6296
Chris@0 6297 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
Chris@0 6298 var i,
Chris@0 6299 val = 0;
Chris@0 6300
Chris@0 6301 // If we already have the right measurement, avoid augmentation
Chris@0 6302 if ( extra === ( isBorderBox ? "border" : "content" ) ) {
Chris@0 6303 i = 4;
Chris@0 6304
Chris@0 6305 // Otherwise initialize for horizontal or vertical properties
Chris@0 6306 } else {
Chris@0 6307 i = name === "width" ? 1 : 0;
Chris@0 6308 }
Chris@0 6309
Chris@0 6310 for ( ; i < 4; i += 2 ) {
Chris@0 6311
Chris@0 6312 // Both box models exclude margin, so add it if we want it
Chris@0 6313 if ( extra === "margin" ) {
Chris@0 6314 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
Chris@0 6315 }
Chris@0 6316
Chris@0 6317 if ( isBorderBox ) {
Chris@0 6318
Chris@0 6319 // border-box includes padding, so remove it if we want content
Chris@0 6320 if ( extra === "content" ) {
Chris@0 6321 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
Chris@0 6322 }
Chris@0 6323
Chris@0 6324 // At this point, extra isn't border nor margin, so remove border
Chris@0 6325 if ( extra !== "margin" ) {
Chris@0 6326 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
Chris@0 6327 }
Chris@0 6328 } else {
Chris@0 6329
Chris@0 6330 // At this point, extra isn't content, so add padding
Chris@0 6331 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
Chris@0 6332
Chris@0 6333 // At this point, extra isn't content nor padding, so add border
Chris@0 6334 if ( extra !== "padding" ) {
Chris@0 6335 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
Chris@0 6336 }
Chris@0 6337 }
Chris@0 6338 }
Chris@0 6339
Chris@0 6340 return val;
Chris@0 6341 }
Chris@0 6342
Chris@0 6343 function getWidthOrHeight( elem, name, extra ) {
Chris@0 6344
Chris@0 6345 // Start with computed style
Chris@0 6346 var valueIsBorderBox,
Chris@0 6347 styles = getStyles( elem ),
Chris@0 6348 val = curCSS( elem, name, styles ),
Chris@0 6349 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
Chris@0 6350
Chris@0 6351 // Computed unit is not pixels. Stop here and return.
Chris@0 6352 if ( rnumnonpx.test( val ) ) {
Chris@0 6353 return val;
Chris@0 6354 }
Chris@0 6355
Chris@0 6356 // Check for style in case a browser which returns unreliable values
Chris@0 6357 // for getComputedStyle silently falls back to the reliable elem.style
Chris@0 6358 valueIsBorderBox = isBorderBox &&
Chris@0 6359 ( support.boxSizingReliable() || val === elem.style[ name ] );
Chris@0 6360
Chris@0 6361 // Fall back to offsetWidth/Height when value is "auto"
Chris@0 6362 // This happens for inline elements with no explicit setting (gh-3571)
Chris@0 6363 if ( val === "auto" ) {
Chris@0 6364 val = elem[ "offset" + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
Chris@0 6365 }
Chris@0 6366
Chris@0 6367 // Normalize "", auto, and prepare for extra
Chris@0 6368 val = parseFloat( val ) || 0;
Chris@0 6369
Chris@0 6370 // Use the active box-sizing model to add/subtract irrelevant styles
Chris@0 6371 return ( val +
Chris@0 6372 augmentWidthOrHeight(
Chris@0 6373 elem,
Chris@0 6374 name,
Chris@0 6375 extra || ( isBorderBox ? "border" : "content" ),
Chris@0 6376 valueIsBorderBox,
Chris@0 6377 styles
Chris@0 6378 )
Chris@0 6379 ) + "px";
Chris@0 6380 }
Chris@0 6381
Chris@0 6382 jQuery.extend( {
Chris@0 6383
Chris@0 6384 // Add in style property hooks for overriding the default
Chris@0 6385 // behavior of getting and setting a style property
Chris@0 6386 cssHooks: {
Chris@0 6387 opacity: {
Chris@0 6388 get: function( elem, computed ) {
Chris@0 6389 if ( computed ) {
Chris@0 6390
Chris@0 6391 // We should always get a number back from opacity
Chris@0 6392 var ret = curCSS( elem, "opacity" );
Chris@0 6393 return ret === "" ? "1" : ret;
Chris@0 6394 }
Chris@0 6395 }
Chris@0 6396 }
Chris@0 6397 },
Chris@0 6398
Chris@0 6399 // Don't automatically add "px" to these possibly-unitless properties
Chris@0 6400 cssNumber: {
Chris@0 6401 "animationIterationCount": true,
Chris@0 6402 "columnCount": true,
Chris@0 6403 "fillOpacity": true,
Chris@0 6404 "flexGrow": true,
Chris@0 6405 "flexShrink": true,
Chris@0 6406 "fontWeight": true,
Chris@0 6407 "lineHeight": true,
Chris@0 6408 "opacity": true,
Chris@0 6409 "order": true,
Chris@0 6410 "orphans": true,
Chris@0 6411 "widows": true,
Chris@0 6412 "zIndex": true,
Chris@0 6413 "zoom": true
Chris@0 6414 },
Chris@0 6415
Chris@0 6416 // Add in properties whose names you wish to fix before
Chris@0 6417 // setting or getting the value
Chris@0 6418 cssProps: {
Chris@0 6419 "float": "cssFloat"
Chris@0 6420 },
Chris@0 6421
Chris@0 6422 // Get and set the style property on a DOM Node
Chris@0 6423 style: function( elem, name, value, extra ) {
Chris@0 6424
Chris@0 6425 // Don't set styles on text and comment nodes
Chris@0 6426 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
Chris@0 6427 return;
Chris@0 6428 }
Chris@0 6429
Chris@0 6430 // Make sure that we're working with the right name
Chris@0 6431 var ret, type, hooks,
Chris@0 6432 origName = jQuery.camelCase( name ),
Chris@0 6433 isCustomProp = rcustomProp.test( name ),
Chris@0 6434 style = elem.style;
Chris@0 6435
Chris@0 6436 // Make sure that we're working with the right name. We don't
Chris@0 6437 // want to query the value if it is a CSS custom property
Chris@0 6438 // since they are user-defined.
Chris@0 6439 if ( !isCustomProp ) {
Chris@0 6440 name = finalPropName( origName );
Chris@0 6441 }
Chris@0 6442
Chris@0 6443 // Gets hook for the prefixed version, then unprefixed version
Chris@0 6444 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
Chris@0 6445
Chris@0 6446 // Check if we're setting a value
Chris@0 6447 if ( value !== undefined ) {
Chris@0 6448 type = typeof value;
Chris@0 6449
Chris@0 6450 // Convert "+=" or "-=" to relative numbers (#7345)
Chris@0 6451 if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
Chris@0 6452 value = adjustCSS( elem, name, ret );
Chris@0 6453
Chris@0 6454 // Fixes bug #9237
Chris@0 6455 type = "number";
Chris@0 6456 }
Chris@0 6457
Chris@0 6458 // Make sure that null and NaN values aren't set (#7116)
Chris@0 6459 if ( value == null || value !== value ) {
Chris@0 6460 return;
Chris@0 6461 }
Chris@0 6462
Chris@0 6463 // If a number was passed in, add the unit (except for certain CSS properties)
Chris@0 6464 if ( type === "number" ) {
Chris@0 6465 value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
Chris@0 6466 }
Chris@0 6467
Chris@0 6468 // background-* props affect original clone's values
Chris@0 6469 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
Chris@0 6470 style[ name ] = "inherit";
Chris@0 6471 }
Chris@0 6472
Chris@0 6473 // If a hook was provided, use that value, otherwise just set the specified value
Chris@0 6474 if ( !hooks || !( "set" in hooks ) ||
Chris@0 6475 ( value = hooks.set( elem, value, extra ) ) !== undefined ) {
Chris@0 6476
Chris@0 6477 if ( isCustomProp ) {
Chris@0 6478 style.setProperty( name, value );
Chris@0 6479 } else {
Chris@0 6480 style[ name ] = value;
Chris@0 6481 }
Chris@0 6482 }
Chris@0 6483
Chris@0 6484 } else {
Chris@0 6485
Chris@0 6486 // If a hook was provided get the non-computed value from there
Chris@0 6487 if ( hooks && "get" in hooks &&
Chris@0 6488 ( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
Chris@0 6489
Chris@0 6490 return ret;
Chris@0 6491 }
Chris@0 6492
Chris@0 6493 // Otherwise just get the value from the style object
Chris@0 6494 return style[ name ];
Chris@0 6495 }
Chris@0 6496 },
Chris@0 6497
Chris@0 6498 css: function( elem, name, extra, styles ) {
Chris@0 6499 var val, num, hooks,
Chris@0 6500 origName = jQuery.camelCase( name ),
Chris@0 6501 isCustomProp = rcustomProp.test( name );
Chris@0 6502
Chris@0 6503 // Make sure that we're working with the right name. We don't
Chris@0 6504 // want to modify the value if it is a CSS custom property
Chris@0 6505 // since they are user-defined.
Chris@0 6506 if ( !isCustomProp ) {
Chris@0 6507 name = finalPropName( origName );
Chris@0 6508 }
Chris@0 6509
Chris@0 6510 // Try prefixed name followed by the unprefixed name
Chris@0 6511 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
Chris@0 6512
Chris@0 6513 // If a hook was provided get the computed value from there
Chris@0 6514 if ( hooks && "get" in hooks ) {
Chris@0 6515 val = hooks.get( elem, true, extra );
Chris@0 6516 }
Chris@0 6517
Chris@0 6518 // Otherwise, if a way to get the computed value exists, use that
Chris@0 6519 if ( val === undefined ) {
Chris@0 6520 val = curCSS( elem, name, styles );
Chris@0 6521 }
Chris@0 6522
Chris@0 6523 // Convert "normal" to computed value
Chris@0 6524 if ( val === "normal" && name in cssNormalTransform ) {
Chris@0 6525 val = cssNormalTransform[ name ];
Chris@0 6526 }
Chris@0 6527
Chris@0 6528 // Make numeric if forced or a qualifier was provided and val looks numeric
Chris@0 6529 if ( extra === "" || extra ) {
Chris@0 6530 num = parseFloat( val );
Chris@0 6531 return extra === true || isFinite( num ) ? num || 0 : val;
Chris@0 6532 }
Chris@0 6533
Chris@0 6534 return val;
Chris@0 6535 }
Chris@0 6536 } );
Chris@0 6537
Chris@0 6538 jQuery.each( [ "height", "width" ], function( i, name ) {
Chris@0 6539 jQuery.cssHooks[ name ] = {
Chris@0 6540 get: function( elem, computed, extra ) {
Chris@0 6541 if ( computed ) {
Chris@0 6542
Chris@0 6543 // Certain elements can have dimension info if we invisibly show them
Chris@0 6544 // but it must have a current display style that would benefit
Chris@0 6545 return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
Chris@0 6546
Chris@0 6547 // Support: Safari 8+
Chris@0 6548 // Table columns in Safari have non-zero offsetWidth & zero
Chris@0 6549 // getBoundingClientRect().width unless display is changed.
Chris@0 6550 // Support: IE <=11 only
Chris@0 6551 // Running getBoundingClientRect on a disconnected node
Chris@0 6552 // in IE throws an error.
Chris@0 6553 ( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
Chris@0 6554 swap( elem, cssShow, function() {
Chris@0 6555 return getWidthOrHeight( elem, name, extra );
Chris@0 6556 } ) :
Chris@0 6557 getWidthOrHeight( elem, name, extra );
Chris@0 6558 }
Chris@0 6559 },
Chris@0 6560
Chris@0 6561 set: function( elem, value, extra ) {
Chris@0 6562 var matches,
Chris@0 6563 styles = extra && getStyles( elem ),
Chris@0 6564 subtract = extra && augmentWidthOrHeight(
Chris@0 6565 elem,
Chris@0 6566 name,
Chris@0 6567 extra,
Chris@0 6568 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
Chris@0 6569 styles
Chris@0 6570 );
Chris@0 6571
Chris@0 6572 // Convert to pixels if value adjustment is needed
Chris@0 6573 if ( subtract && ( matches = rcssNum.exec( value ) ) &&
Chris@0 6574 ( matches[ 3 ] || "px" ) !== "px" ) {
Chris@0 6575
Chris@0 6576 elem.style[ name ] = value;
Chris@0 6577 value = jQuery.css( elem, name );
Chris@0 6578 }
Chris@0 6579
Chris@0 6580 return setPositiveNumber( elem, value, subtract );
Chris@0 6581 }
Chris@0 6582 };
Chris@0 6583 } );
Chris@0 6584
Chris@0 6585 jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
Chris@0 6586 function( elem, computed ) {
Chris@0 6587 if ( computed ) {
Chris@0 6588 return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
Chris@0 6589 elem.getBoundingClientRect().left -
Chris@0 6590 swap( elem, { marginLeft: 0 }, function() {
Chris@0 6591 return elem.getBoundingClientRect().left;
Chris@0 6592 } )
Chris@0 6593 ) + "px";
Chris@0 6594 }
Chris@0 6595 }
Chris@0 6596 );
Chris@0 6597
Chris@0 6598 // These hooks are used by animate to expand properties
Chris@0 6599 jQuery.each( {
Chris@0 6600 margin: "",
Chris@0 6601 padding: "",
Chris@0 6602 border: "Width"
Chris@0 6603 }, function( prefix, suffix ) {
Chris@0 6604 jQuery.cssHooks[ prefix + suffix ] = {
Chris@0 6605 expand: function( value ) {
Chris@0 6606 var i = 0,
Chris@0 6607 expanded = {},
Chris@0 6608
Chris@0 6609 // Assumes a single number if not a string
Chris@0 6610 parts = typeof value === "string" ? value.split( " " ) : [ value ];
Chris@0 6611
Chris@0 6612 for ( ; i < 4; i++ ) {
Chris@0 6613 expanded[ prefix + cssExpand[ i ] + suffix ] =
Chris@0 6614 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
Chris@0 6615 }
Chris@0 6616
Chris@0 6617 return expanded;
Chris@0 6618 }
Chris@0 6619 };
Chris@0 6620
Chris@0 6621 if ( !rmargin.test( prefix ) ) {
Chris@0 6622 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
Chris@0 6623 }
Chris@0 6624 } );
Chris@0 6625
Chris@0 6626 jQuery.fn.extend( {
Chris@0 6627 css: function( name, value ) {
Chris@0 6628 return access( this, function( elem, name, value ) {
Chris@0 6629 var styles, len,
Chris@0 6630 map = {},
Chris@0 6631 i = 0;
Chris@0 6632
Chris@0 6633 if ( Array.isArray( name ) ) {
Chris@0 6634 styles = getStyles( elem );
Chris@0 6635 len = name.length;
Chris@0 6636
Chris@0 6637 for ( ; i < len; i++ ) {
Chris@0 6638 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
Chris@0 6639 }
Chris@0 6640
Chris@0 6641 return map;
Chris@0 6642 }
Chris@0 6643
Chris@0 6644 return value !== undefined ?
Chris@0 6645 jQuery.style( elem, name, value ) :
Chris@0 6646 jQuery.css( elem, name );
Chris@0 6647 }, name, value, arguments.length > 1 );
Chris@0 6648 }
Chris@0 6649 } );
Chris@0 6650
Chris@0 6651
Chris@0 6652 function Tween( elem, options, prop, end, easing ) {
Chris@0 6653 return new Tween.prototype.init( elem, options, prop, end, easing );
Chris@0 6654 }
Chris@0 6655 jQuery.Tween = Tween;
Chris@0 6656
Chris@0 6657 Tween.prototype = {
Chris@0 6658 constructor: Tween,
Chris@0 6659 init: function( elem, options, prop, end, easing, unit ) {
Chris@0 6660 this.elem = elem;
Chris@0 6661 this.prop = prop;
Chris@0 6662 this.easing = easing || jQuery.easing._default;
Chris@0 6663 this.options = options;
Chris@0 6664 this.start = this.now = this.cur();
Chris@0 6665 this.end = end;
Chris@0 6666 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
Chris@0 6667 },
Chris@0 6668 cur: function() {
Chris@0 6669 var hooks = Tween.propHooks[ this.prop ];
Chris@0 6670
Chris@0 6671 return hooks && hooks.get ?
Chris@0 6672 hooks.get( this ) :
Chris@0 6673 Tween.propHooks._default.get( this );
Chris@0 6674 },
Chris@0 6675 run: function( percent ) {
Chris@0 6676 var eased,
Chris@0 6677 hooks = Tween.propHooks[ this.prop ];
Chris@0 6678
Chris@0 6679 if ( this.options.duration ) {
Chris@0 6680 this.pos = eased = jQuery.easing[ this.easing ](
Chris@0 6681 percent, this.options.duration * percent, 0, 1, this.options.duration
Chris@0 6682 );
Chris@0 6683 } else {
Chris@0 6684 this.pos = eased = percent;
Chris@0 6685 }
Chris@0 6686 this.now = ( this.end - this.start ) * eased + this.start;
Chris@0 6687
Chris@0 6688 if ( this.options.step ) {
Chris@0 6689 this.options.step.call( this.elem, this.now, this );
Chris@0 6690 }
Chris@0 6691
Chris@0 6692 if ( hooks && hooks.set ) {
Chris@0 6693 hooks.set( this );
Chris@0 6694 } else {
Chris@0 6695 Tween.propHooks._default.set( this );
Chris@0 6696 }
Chris@0 6697 return this;
Chris@0 6698 }
Chris@0 6699 };
Chris@0 6700
Chris@0 6701 Tween.prototype.init.prototype = Tween.prototype;
Chris@0 6702
Chris@0 6703 Tween.propHooks = {
Chris@0 6704 _default: {
Chris@0 6705 get: function( tween ) {
Chris@0 6706 var result;
Chris@0 6707
Chris@0 6708 // Use a property on the element directly when it is not a DOM element,
Chris@0 6709 // or when there is no matching style property that exists.
Chris@0 6710 if ( tween.elem.nodeType !== 1 ||
Chris@0 6711 tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) {
Chris@0 6712 return tween.elem[ tween.prop ];
Chris@0 6713 }
Chris@0 6714
Chris@0 6715 // Passing an empty string as a 3rd parameter to .css will automatically
Chris@0 6716 // attempt a parseFloat and fallback to a string if the parse fails.
Chris@0 6717 // Simple values such as "10px" are parsed to Float;
Chris@0 6718 // complex values such as "rotate(1rad)" are returned as-is.
Chris@0 6719 result = jQuery.css( tween.elem, tween.prop, "" );
Chris@0 6720
Chris@0 6721 // Empty strings, null, undefined and "auto" are converted to 0.
Chris@0 6722 return !result || result === "auto" ? 0 : result;
Chris@0 6723 },
Chris@0 6724 set: function( tween ) {
Chris@0 6725
Chris@0 6726 // Use step hook for back compat.
Chris@0 6727 // Use cssHook if its there.
Chris@0 6728 // Use .style if available and use plain properties where available.
Chris@0 6729 if ( jQuery.fx.step[ tween.prop ] ) {
Chris@0 6730 jQuery.fx.step[ tween.prop ]( tween );
Chris@0 6731 } else if ( tween.elem.nodeType === 1 &&
Chris@0 6732 ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null ||
Chris@0 6733 jQuery.cssHooks[ tween.prop ] ) ) {
Chris@0 6734 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
Chris@0 6735 } else {
Chris@0 6736 tween.elem[ tween.prop ] = tween.now;
Chris@0 6737 }
Chris@0 6738 }
Chris@0 6739 }
Chris@0 6740 };
Chris@0 6741
Chris@0 6742 // Support: IE <=9 only
Chris@0 6743 // Panic based approach to setting things on disconnected nodes
Chris@0 6744 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
Chris@0 6745 set: function( tween ) {
Chris@0 6746 if ( tween.elem.nodeType && tween.elem.parentNode ) {
Chris@0 6747 tween.elem[ tween.prop ] = tween.now;
Chris@0 6748 }
Chris@0 6749 }
Chris@0 6750 };
Chris@0 6751
Chris@0 6752 jQuery.easing = {
Chris@0 6753 linear: function( p ) {
Chris@0 6754 return p;
Chris@0 6755 },
Chris@0 6756 swing: function( p ) {
Chris@0 6757 return 0.5 - Math.cos( p * Math.PI ) / 2;
Chris@0 6758 },
Chris@0 6759 _default: "swing"
Chris@0 6760 };
Chris@0 6761
Chris@0 6762 jQuery.fx = Tween.prototype.init;
Chris@0 6763
Chris@0 6764 // Back compat <1.8 extension point
Chris@0 6765 jQuery.fx.step = {};
Chris@0 6766
Chris@0 6767
Chris@0 6768
Chris@0 6769
Chris@0 6770 var
Chris@0 6771 fxNow, inProgress,
Chris@0 6772 rfxtypes = /^(?:toggle|show|hide)$/,
Chris@0 6773 rrun = /queueHooks$/;
Chris@0 6774
Chris@0 6775 function schedule() {
Chris@0 6776 if ( inProgress ) {
Chris@0 6777 if ( document.hidden === false && window.requestAnimationFrame ) {
Chris@0 6778 window.requestAnimationFrame( schedule );
Chris@0 6779 } else {
Chris@0 6780 window.setTimeout( schedule, jQuery.fx.interval );
Chris@0 6781 }
Chris@0 6782
Chris@0 6783 jQuery.fx.tick();
Chris@0 6784 }
Chris@0 6785 }
Chris@0 6786
Chris@0 6787 // Animations created synchronously will run synchronously
Chris@0 6788 function createFxNow() {
Chris@0 6789 window.setTimeout( function() {
Chris@0 6790 fxNow = undefined;
Chris@0 6791 } );
Chris@0 6792 return ( fxNow = jQuery.now() );
Chris@0 6793 }
Chris@0 6794
Chris@0 6795 // Generate parameters to create a standard animation
Chris@0 6796 function genFx( type, includeWidth ) {
Chris@0 6797 var which,
Chris@0 6798 i = 0,
Chris@0 6799 attrs = { height: type };
Chris@0 6800
Chris@0 6801 // If we include width, step value is 1 to do all cssExpand values,
Chris@0 6802 // otherwise step value is 2 to skip over Left and Right
Chris@0 6803 includeWidth = includeWidth ? 1 : 0;
Chris@0 6804 for ( ; i < 4; i += 2 - includeWidth ) {
Chris@0 6805 which = cssExpand[ i ];
Chris@0 6806 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
Chris@0 6807 }
Chris@0 6808
Chris@0 6809 if ( includeWidth ) {
Chris@0 6810 attrs.opacity = attrs.width = type;
Chris@0 6811 }
Chris@0 6812
Chris@0 6813 return attrs;
Chris@0 6814 }
Chris@0 6815
Chris@0 6816 function createTween( value, prop, animation ) {
Chris@0 6817 var tween,
Chris@0 6818 collection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ "*" ] ),
Chris@0 6819 index = 0,
Chris@0 6820 length = collection.length;
Chris@0 6821 for ( ; index < length; index++ ) {
Chris@0 6822 if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) {
Chris@0 6823
Chris@0 6824 // We're done with this property
Chris@0 6825 return tween;
Chris@0 6826 }
Chris@0 6827 }
Chris@0 6828 }
Chris@0 6829
Chris@0 6830 function defaultPrefilter( elem, props, opts ) {
Chris@0 6831 var prop, value, toggle, hooks, oldfire, propTween, restoreDisplay, display,
Chris@0 6832 isBox = "width" in props || "height" in props,
Chris@0 6833 anim = this,
Chris@0 6834 orig = {},
Chris@0 6835 style = elem.style,
Chris@0 6836 hidden = elem.nodeType && isHiddenWithinTree( elem ),
Chris@0 6837 dataShow = dataPriv.get( elem, "fxshow" );
Chris@0 6838
Chris@0 6839 // Queue-skipping animations hijack the fx hooks
Chris@0 6840 if ( !opts.queue ) {
Chris@0 6841 hooks = jQuery._queueHooks( elem, "fx" );
Chris@0 6842 if ( hooks.unqueued == null ) {
Chris@0 6843 hooks.unqueued = 0;
Chris@0 6844 oldfire = hooks.empty.fire;
Chris@0 6845 hooks.empty.fire = function() {
Chris@0 6846 if ( !hooks.unqueued ) {
Chris@0 6847 oldfire();
Chris@0 6848 }
Chris@0 6849 };
Chris@0 6850 }
Chris@0 6851 hooks.unqueued++;
Chris@0 6852
Chris@0 6853 anim.always( function() {
Chris@0 6854
Chris@0 6855 // Ensure the complete handler is called before this completes
Chris@0 6856 anim.always( function() {
Chris@0 6857 hooks.unqueued--;
Chris@0 6858 if ( !jQuery.queue( elem, "fx" ).length ) {
Chris@0 6859 hooks.empty.fire();
Chris@0 6860 }
Chris@0 6861 } );
Chris@0 6862 } );
Chris@0 6863 }
Chris@0 6864
Chris@0 6865 // Detect show/hide animations
Chris@0 6866 for ( prop in props ) {
Chris@0 6867 value = props[ prop ];
Chris@0 6868 if ( rfxtypes.test( value ) ) {
Chris@0 6869 delete props[ prop ];
Chris@0 6870 toggle = toggle || value === "toggle";
Chris@0 6871 if ( value === ( hidden ? "hide" : "show" ) ) {
Chris@0 6872
Chris@0 6873 // Pretend to be hidden if this is a "show" and
Chris@0 6874 // there is still data from a stopped show/hide
Chris@0 6875 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
Chris@0 6876 hidden = true;
Chris@0 6877
Chris@0 6878 // Ignore all other no-op show/hide data
Chris@0 6879 } else {
Chris@0 6880 continue;
Chris@0 6881 }
Chris@0 6882 }
Chris@0 6883 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
Chris@0 6884 }
Chris@0 6885 }
Chris@0 6886
Chris@0 6887 // Bail out if this is a no-op like .hide().hide()
Chris@0 6888 propTween = !jQuery.isEmptyObject( props );
Chris@0 6889 if ( !propTween && jQuery.isEmptyObject( orig ) ) {
Chris@0 6890 return;
Chris@0 6891 }
Chris@0 6892
Chris@0 6893 // Restrict "overflow" and "display" styles during box animations
Chris@0 6894 if ( isBox && elem.nodeType === 1 ) {
Chris@0 6895
Chris@0 6896 // Support: IE <=9 - 11, Edge 12 - 13
Chris@0 6897 // Record all 3 overflow attributes because IE does not infer the shorthand
Chris@0 6898 // from identically-valued overflowX and overflowY
Chris@0 6899 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
Chris@0 6900
Chris@0 6901 // Identify a display type, preferring old show/hide data over the CSS cascade
Chris@0 6902 restoreDisplay = dataShow && dataShow.display;
Chris@0 6903 if ( restoreDisplay == null ) {
Chris@0 6904 restoreDisplay = dataPriv.get( elem, "display" );
Chris@0 6905 }
Chris@0 6906 display = jQuery.css( elem, "display" );
Chris@0 6907 if ( display === "none" ) {
Chris@0 6908 if ( restoreDisplay ) {
Chris@0 6909 display = restoreDisplay;
Chris@0 6910 } else {
Chris@0 6911
Chris@0 6912 // Get nonempty value(s) by temporarily forcing visibility
Chris@0 6913 showHide( [ elem ], true );
Chris@0 6914 restoreDisplay = elem.style.display || restoreDisplay;
Chris@0 6915 display = jQuery.css( elem, "display" );
Chris@0 6916 showHide( [ elem ] );
Chris@0 6917 }
Chris@0 6918 }
Chris@0 6919
Chris@0 6920 // Animate inline elements as inline-block
Chris@0 6921 if ( display === "inline" || display === "inline-block" && restoreDisplay != null ) {
Chris@0 6922 if ( jQuery.css( elem, "float" ) === "none" ) {
Chris@0 6923
Chris@0 6924 // Restore the original display value at the end of pure show/hide animations
Chris@0 6925 if ( !propTween ) {
Chris@0 6926 anim.done( function() {
Chris@0 6927 style.display = restoreDisplay;
Chris@0 6928 } );
Chris@0 6929 if ( restoreDisplay == null ) {
Chris@0 6930 display = style.display;
Chris@0 6931 restoreDisplay = display === "none" ? "" : display;
Chris@0 6932 }
Chris@0 6933 }
Chris@0 6934 style.display = "inline-block";
Chris@0 6935 }
Chris@0 6936 }
Chris@0 6937 }
Chris@0 6938
Chris@0 6939 if ( opts.overflow ) {
Chris@0 6940 style.overflow = "hidden";
Chris@0 6941 anim.always( function() {
Chris@0 6942 style.overflow = opts.overflow[ 0 ];
Chris@0 6943 style.overflowX = opts.overflow[ 1 ];
Chris@0 6944 style.overflowY = opts.overflow[ 2 ];
Chris@0 6945 } );
Chris@0 6946 }
Chris@0 6947
Chris@0 6948 // Implement show/hide animations
Chris@0 6949 propTween = false;
Chris@0 6950 for ( prop in orig ) {
Chris@0 6951
Chris@0 6952 // General show/hide setup for this element animation
Chris@0 6953 if ( !propTween ) {
Chris@0 6954 if ( dataShow ) {
Chris@0 6955 if ( "hidden" in dataShow ) {
Chris@0 6956 hidden = dataShow.hidden;
Chris@0 6957 }
Chris@0 6958 } else {
Chris@0 6959 dataShow = dataPriv.access( elem, "fxshow", { display: restoreDisplay } );
Chris@0 6960 }
Chris@0 6961
Chris@0 6962 // Store hidden/visible for toggle so `.stop().toggle()` "reverses"
Chris@0 6963 if ( toggle ) {
Chris@0 6964 dataShow.hidden = !hidden;
Chris@0 6965 }
Chris@0 6966
Chris@0 6967 // Show elements before animating them
Chris@0 6968 if ( hidden ) {
Chris@0 6969 showHide( [ elem ], true );
Chris@0 6970 }
Chris@0 6971
Chris@0 6972 /* eslint-disable no-loop-func */
Chris@0 6973
Chris@0 6974 anim.done( function() {
Chris@0 6975
Chris@0 6976 /* eslint-enable no-loop-func */
Chris@0 6977
Chris@0 6978 // The final step of a "hide" animation is actually hiding the element
Chris@0 6979 if ( !hidden ) {
Chris@0 6980 showHide( [ elem ] );
Chris@0 6981 }
Chris@0 6982 dataPriv.remove( elem, "fxshow" );
Chris@0 6983 for ( prop in orig ) {
Chris@0 6984 jQuery.style( elem, prop, orig[ prop ] );
Chris@0 6985 }
Chris@0 6986 } );
Chris@0 6987 }
Chris@0 6988
Chris@0 6989 // Per-property setup
Chris@0 6990 propTween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
Chris@0 6991 if ( !( prop in dataShow ) ) {
Chris@0 6992 dataShow[ prop ] = propTween.start;
Chris@0 6993 if ( hidden ) {
Chris@0 6994 propTween.end = propTween.start;
Chris@0 6995 propTween.start = 0;
Chris@0 6996 }
Chris@0 6997 }
Chris@0 6998 }
Chris@0 6999 }
Chris@0 7000
Chris@0 7001 function propFilter( props, specialEasing ) {
Chris@0 7002 var index, name, easing, value, hooks;
Chris@0 7003
Chris@0 7004 // camelCase, specialEasing and expand cssHook pass
Chris@0 7005 for ( index in props ) {
Chris@0 7006 name = jQuery.camelCase( index );
Chris@0 7007 easing = specialEasing[ name ];
Chris@0 7008 value = props[ index ];
Chris@0 7009 if ( Array.isArray( value ) ) {
Chris@0 7010 easing = value[ 1 ];
Chris@0 7011 value = props[ index ] = value[ 0 ];
Chris@0 7012 }
Chris@0 7013
Chris@0 7014 if ( index !== name ) {
Chris@0 7015 props[ name ] = value;
Chris@0 7016 delete props[ index ];
Chris@0 7017 }
Chris@0 7018
Chris@0 7019 hooks = jQuery.cssHooks[ name ];
Chris@0 7020 if ( hooks && "expand" in hooks ) {
Chris@0 7021 value = hooks.expand( value );
Chris@0 7022 delete props[ name ];
Chris@0 7023
Chris@0 7024 // Not quite $.extend, this won't overwrite existing keys.
Chris@0 7025 // Reusing 'index' because we have the correct "name"
Chris@0 7026 for ( index in value ) {
Chris@0 7027 if ( !( index in props ) ) {
Chris@0 7028 props[ index ] = value[ index ];
Chris@0 7029 specialEasing[ index ] = easing;
Chris@0 7030 }
Chris@0 7031 }
Chris@0 7032 } else {
Chris@0 7033 specialEasing[ name ] = easing;
Chris@0 7034 }
Chris@0 7035 }
Chris@0 7036 }
Chris@0 7037
Chris@0 7038 function Animation( elem, properties, options ) {
Chris@0 7039 var result,
Chris@0 7040 stopped,
Chris@0 7041 index = 0,
Chris@0 7042 length = Animation.prefilters.length,
Chris@0 7043 deferred = jQuery.Deferred().always( function() {
Chris@0 7044
Chris@0 7045 // Don't match elem in the :animated selector
Chris@0 7046 delete tick.elem;
Chris@0 7047 } ),
Chris@0 7048 tick = function() {
Chris@0 7049 if ( stopped ) {
Chris@0 7050 return false;
Chris@0 7051 }
Chris@0 7052 var currentTime = fxNow || createFxNow(),
Chris@0 7053 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
Chris@0 7054
Chris@0 7055 // Support: Android 2.3 only
Chris@0 7056 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
Chris@0 7057 temp = remaining / animation.duration || 0,
Chris@0 7058 percent = 1 - temp,
Chris@0 7059 index = 0,
Chris@0 7060 length = animation.tweens.length;
Chris@0 7061
Chris@0 7062 for ( ; index < length; index++ ) {
Chris@0 7063 animation.tweens[ index ].run( percent );
Chris@0 7064 }
Chris@0 7065
Chris@0 7066 deferred.notifyWith( elem, [ animation, percent, remaining ] );
Chris@0 7067
Chris@0 7068 // If there's more to do, yield
Chris@0 7069 if ( percent < 1 && length ) {
Chris@0 7070 return remaining;
Chris@0 7071 }
Chris@0 7072
Chris@0 7073 // If this was an empty animation, synthesize a final progress notification
Chris@0 7074 if ( !length ) {
Chris@0 7075 deferred.notifyWith( elem, [ animation, 1, 0 ] );
Chris@0 7076 }
Chris@0 7077
Chris@0 7078 // Resolve the animation and report its conclusion
Chris@0 7079 deferred.resolveWith( elem, [ animation ] );
Chris@0 7080 return false;
Chris@0 7081 },
Chris@0 7082 animation = deferred.promise( {
Chris@0 7083 elem: elem,
Chris@0 7084 props: jQuery.extend( {}, properties ),
Chris@0 7085 opts: jQuery.extend( true, {
Chris@0 7086 specialEasing: {},
Chris@0 7087 easing: jQuery.easing._default
Chris@0 7088 }, options ),
Chris@0 7089 originalProperties: properties,
Chris@0 7090 originalOptions: options,
Chris@0 7091 startTime: fxNow || createFxNow(),
Chris@0 7092 duration: options.duration,
Chris@0 7093 tweens: [],
Chris@0 7094 createTween: function( prop, end ) {
Chris@0 7095 var tween = jQuery.Tween( elem, animation.opts, prop, end,
Chris@0 7096 animation.opts.specialEasing[ prop ] || animation.opts.easing );
Chris@0 7097 animation.tweens.push( tween );
Chris@0 7098 return tween;
Chris@0 7099 },
Chris@0 7100 stop: function( gotoEnd ) {
Chris@0 7101 var index = 0,
Chris@0 7102
Chris@0 7103 // If we are going to the end, we want to run all the tweens
Chris@0 7104 // otherwise we skip this part
Chris@0 7105 length = gotoEnd ? animation.tweens.length : 0;
Chris@0 7106 if ( stopped ) {
Chris@0 7107 return this;
Chris@0 7108 }
Chris@0 7109 stopped = true;
Chris@0 7110 for ( ; index < length; index++ ) {
Chris@0 7111 animation.tweens[ index ].run( 1 );
Chris@0 7112 }
Chris@0 7113
Chris@0 7114 // Resolve when we played the last frame; otherwise, reject
Chris@0 7115 if ( gotoEnd ) {
Chris@0 7116 deferred.notifyWith( elem, [ animation, 1, 0 ] );
Chris@0 7117 deferred.resolveWith( elem, [ animation, gotoEnd ] );
Chris@0 7118 } else {
Chris@0 7119 deferred.rejectWith( elem, [ animation, gotoEnd ] );
Chris@0 7120 }
Chris@0 7121 return this;
Chris@0 7122 }
Chris@0 7123 } ),
Chris@0 7124 props = animation.props;
Chris@0 7125
Chris@0 7126 propFilter( props, animation.opts.specialEasing );
Chris@0 7127
Chris@0 7128 for ( ; index < length; index++ ) {
Chris@0 7129 result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
Chris@0 7130 if ( result ) {
Chris@0 7131 if ( jQuery.isFunction( result.stop ) ) {
Chris@0 7132 jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
Chris@0 7133 jQuery.proxy( result.stop, result );
Chris@0 7134 }
Chris@0 7135 return result;
Chris@0 7136 }
Chris@0 7137 }
Chris@0 7138
Chris@0 7139 jQuery.map( props, createTween, animation );
Chris@0 7140
Chris@0 7141 if ( jQuery.isFunction( animation.opts.start ) ) {
Chris@0 7142 animation.opts.start.call( elem, animation );
Chris@0 7143 }
Chris@0 7144
Chris@0 7145 // Attach callbacks from options
Chris@0 7146 animation
Chris@0 7147 .progress( animation.opts.progress )
Chris@0 7148 .done( animation.opts.done, animation.opts.complete )
Chris@0 7149 .fail( animation.opts.fail )
Chris@0 7150 .always( animation.opts.always );
Chris@0 7151
Chris@0 7152 jQuery.fx.timer(
Chris@0 7153 jQuery.extend( tick, {
Chris@0 7154 elem: elem,
Chris@0 7155 anim: animation,
Chris@0 7156 queue: animation.opts.queue
Chris@0 7157 } )
Chris@0 7158 );
Chris@0 7159
Chris@0 7160 return animation;
Chris@0 7161 }
Chris@0 7162
Chris@0 7163 jQuery.Animation = jQuery.extend( Animation, {
Chris@0 7164
Chris@0 7165 tweeners: {
Chris@0 7166 "*": [ function( prop, value ) {
Chris@0 7167 var tween = this.createTween( prop, value );
Chris@0 7168 adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );
Chris@0 7169 return tween;
Chris@0 7170 } ]
Chris@0 7171 },
Chris@0 7172
Chris@0 7173 tweener: function( props, callback ) {
Chris@0 7174 if ( jQuery.isFunction( props ) ) {
Chris@0 7175 callback = props;
Chris@0 7176 props = [ "*" ];
Chris@0 7177 } else {
Chris@0 7178 props = props.match( rnothtmlwhite );
Chris@0 7179 }
Chris@0 7180
Chris@0 7181 var prop,
Chris@0 7182 index = 0,
Chris@0 7183 length = props.length;
Chris@0 7184
Chris@0 7185 for ( ; index < length; index++ ) {
Chris@0 7186 prop = props[ index ];
Chris@0 7187 Animation.tweeners[ prop ] = Animation.tweeners[ prop ] || [];
Chris@0 7188 Animation.tweeners[ prop ].unshift( callback );
Chris@0 7189 }
Chris@0 7190 },
Chris@0 7191
Chris@0 7192 prefilters: [ defaultPrefilter ],
Chris@0 7193
Chris@0 7194 prefilter: function( callback, prepend ) {
Chris@0 7195 if ( prepend ) {
Chris@0 7196 Animation.prefilters.unshift( callback );
Chris@0 7197 } else {
Chris@0 7198 Animation.prefilters.push( callback );
Chris@0 7199 }
Chris@0 7200 }
Chris@0 7201 } );
Chris@0 7202
Chris@0 7203 jQuery.speed = function( speed, easing, fn ) {
Chris@0 7204 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
Chris@0 7205 complete: fn || !fn && easing ||
Chris@0 7206 jQuery.isFunction( speed ) && speed,
Chris@0 7207 duration: speed,
Chris@0 7208 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
Chris@0 7209 };
Chris@0 7210
Chris@0 7211 // Go to the end state if fx are off
Chris@0 7212 if ( jQuery.fx.off ) {
Chris@0 7213 opt.duration = 0;
Chris@0 7214
Chris@0 7215 } else {
Chris@0 7216 if ( typeof opt.duration !== "number" ) {
Chris@0 7217 if ( opt.duration in jQuery.fx.speeds ) {
Chris@0 7218 opt.duration = jQuery.fx.speeds[ opt.duration ];
Chris@0 7219
Chris@0 7220 } else {
Chris@0 7221 opt.duration = jQuery.fx.speeds._default;
Chris@0 7222 }
Chris@0 7223 }
Chris@0 7224 }
Chris@0 7225
Chris@0 7226 // Normalize opt.queue - true/undefined/null -> "fx"
Chris@0 7227 if ( opt.queue == null || opt.queue === true ) {
Chris@0 7228 opt.queue = "fx";
Chris@0 7229 }
Chris@0 7230
Chris@0 7231 // Queueing
Chris@0 7232 opt.old = opt.complete;
Chris@0 7233
Chris@0 7234 opt.complete = function() {
Chris@0 7235 if ( jQuery.isFunction( opt.old ) ) {
Chris@0 7236 opt.old.call( this );
Chris@0 7237 }
Chris@0 7238
Chris@0 7239 if ( opt.queue ) {
Chris@0 7240 jQuery.dequeue( this, opt.queue );
Chris@0 7241 }
Chris@0 7242 };
Chris@0 7243
Chris@0 7244 return opt;
Chris@0 7245 };
Chris@0 7246
Chris@0 7247 jQuery.fn.extend( {
Chris@0 7248 fadeTo: function( speed, to, easing, callback ) {
Chris@0 7249
Chris@0 7250 // Show any hidden elements after setting opacity to 0
Chris@0 7251 return this.filter( isHiddenWithinTree ).css( "opacity", 0 ).show()
Chris@0 7252
Chris@0 7253 // Animate to the value specified
Chris@0 7254 .end().animate( { opacity: to }, speed, easing, callback );
Chris@0 7255 },
Chris@0 7256 animate: function( prop, speed, easing, callback ) {
Chris@0 7257 var empty = jQuery.isEmptyObject( prop ),
Chris@0 7258 optall = jQuery.speed( speed, easing, callback ),
Chris@0 7259 doAnimation = function() {
Chris@0 7260
Chris@0 7261 // Operate on a copy of prop so per-property easing won't be lost
Chris@0 7262 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
Chris@0 7263
Chris@0 7264 // Empty animations, or finishing resolves immediately
Chris@0 7265 if ( empty || dataPriv.get( this, "finish" ) ) {
Chris@0 7266 anim.stop( true );
Chris@0 7267 }
Chris@0 7268 };
Chris@0 7269 doAnimation.finish = doAnimation;
Chris@0 7270
Chris@0 7271 return empty || optall.queue === false ?
Chris@0 7272 this.each( doAnimation ) :
Chris@0 7273 this.queue( optall.queue, doAnimation );
Chris@0 7274 },
Chris@0 7275 stop: function( type, clearQueue, gotoEnd ) {
Chris@0 7276 var stopQueue = function( hooks ) {
Chris@0 7277 var stop = hooks.stop;
Chris@0 7278 delete hooks.stop;
Chris@0 7279 stop( gotoEnd );
Chris@0 7280 };
Chris@0 7281
Chris@0 7282 if ( typeof type !== "string" ) {
Chris@0 7283 gotoEnd = clearQueue;
Chris@0 7284 clearQueue = type;
Chris@0 7285 type = undefined;
Chris@0 7286 }
Chris@0 7287 if ( clearQueue && type !== false ) {
Chris@0 7288 this.queue( type || "fx", [] );
Chris@0 7289 }
Chris@0 7290
Chris@0 7291 return this.each( function() {
Chris@0 7292 var dequeue = true,
Chris@0 7293 index = type != null && type + "queueHooks",
Chris@0 7294 timers = jQuery.timers,
Chris@0 7295 data = dataPriv.get( this );
Chris@0 7296
Chris@0 7297 if ( index ) {
Chris@0 7298 if ( data[ index ] && data[ index ].stop ) {
Chris@0 7299 stopQueue( data[ index ] );
Chris@0 7300 }
Chris@0 7301 } else {
Chris@0 7302 for ( index in data ) {
Chris@0 7303 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
Chris@0 7304 stopQueue( data[ index ] );
Chris@0 7305 }
Chris@0 7306 }
Chris@0 7307 }
Chris@0 7308
Chris@0 7309 for ( index = timers.length; index--; ) {
Chris@0 7310 if ( timers[ index ].elem === this &&
Chris@0 7311 ( type == null || timers[ index ].queue === type ) ) {
Chris@0 7312
Chris@0 7313 timers[ index ].anim.stop( gotoEnd );
Chris@0 7314 dequeue = false;
Chris@0 7315 timers.splice( index, 1 );
Chris@0 7316 }
Chris@0 7317 }
Chris@0 7318
Chris@0 7319 // Start the next in the queue if the last step wasn't forced.
Chris@0 7320 // Timers currently will call their complete callbacks, which
Chris@0 7321 // will dequeue but only if they were gotoEnd.
Chris@0 7322 if ( dequeue || !gotoEnd ) {
Chris@0 7323 jQuery.dequeue( this, type );
Chris@0 7324 }
Chris@0 7325 } );
Chris@0 7326 },
Chris@0 7327 finish: function( type ) {
Chris@0 7328 if ( type !== false ) {
Chris@0 7329 type = type || "fx";
Chris@0 7330 }
Chris@0 7331 return this.each( function() {
Chris@0 7332 var index,
Chris@0 7333 data = dataPriv.get( this ),
Chris@0 7334 queue = data[ type + "queue" ],
Chris@0 7335 hooks = data[ type + "queueHooks" ],
Chris@0 7336 timers = jQuery.timers,
Chris@0 7337 length = queue ? queue.length : 0;
Chris@0 7338
Chris@0 7339 // Enable finishing flag on private data
Chris@0 7340 data.finish = true;
Chris@0 7341
Chris@0 7342 // Empty the queue first
Chris@0 7343 jQuery.queue( this, type, [] );
Chris@0 7344
Chris@0 7345 if ( hooks && hooks.stop ) {
Chris@0 7346 hooks.stop.call( this, true );
Chris@0 7347 }
Chris@0 7348
Chris@0 7349 // Look for any active animations, and finish them
Chris@0 7350 for ( index = timers.length; index--; ) {
Chris@0 7351 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
Chris@0 7352 timers[ index ].anim.stop( true );
Chris@0 7353 timers.splice( index, 1 );
Chris@0 7354 }
Chris@0 7355 }
Chris@0 7356
Chris@0 7357 // Look for any animations in the old queue and finish them
Chris@0 7358 for ( index = 0; index < length; index++ ) {
Chris@0 7359 if ( queue[ index ] && queue[ index ].finish ) {
Chris@0 7360 queue[ index ].finish.call( this );
Chris@0 7361 }
Chris@0 7362 }
Chris@0 7363
Chris@0 7364 // Turn off finishing flag
Chris@0 7365 delete data.finish;
Chris@0 7366 } );
Chris@0 7367 }
Chris@0 7368 } );
Chris@0 7369
Chris@0 7370 jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) {
Chris@0 7371 var cssFn = jQuery.fn[ name ];
Chris@0 7372 jQuery.fn[ name ] = function( speed, easing, callback ) {
Chris@0 7373 return speed == null || typeof speed === "boolean" ?
Chris@0 7374 cssFn.apply( this, arguments ) :
Chris@0 7375 this.animate( genFx( name, true ), speed, easing, callback );
Chris@0 7376 };
Chris@0 7377 } );
Chris@0 7378
Chris@0 7379 // Generate shortcuts for custom animations
Chris@0 7380 jQuery.each( {
Chris@0 7381 slideDown: genFx( "show" ),
Chris@0 7382 slideUp: genFx( "hide" ),
Chris@0 7383 slideToggle: genFx( "toggle" ),
Chris@0 7384 fadeIn: { opacity: "show" },
Chris@0 7385 fadeOut: { opacity: "hide" },
Chris@0 7386 fadeToggle: { opacity: "toggle" }
Chris@0 7387 }, function( name, props ) {
Chris@0 7388 jQuery.fn[ name ] = function( speed, easing, callback ) {
Chris@0 7389 return this.animate( props, speed, easing, callback );
Chris@0 7390 };
Chris@0 7391 } );
Chris@0 7392
Chris@0 7393 jQuery.timers = [];
Chris@0 7394 jQuery.fx.tick = function() {
Chris@0 7395 var timer,
Chris@0 7396 i = 0,
Chris@0 7397 timers = jQuery.timers;
Chris@0 7398
Chris@0 7399 fxNow = jQuery.now();
Chris@0 7400
Chris@0 7401 for ( ; i < timers.length; i++ ) {
Chris@0 7402 timer = timers[ i ];
Chris@0 7403
Chris@0 7404 // Run the timer and safely remove it when done (allowing for external removal)
Chris@0 7405 if ( !timer() && timers[ i ] === timer ) {
Chris@0 7406 timers.splice( i--, 1 );
Chris@0 7407 }
Chris@0 7408 }
Chris@0 7409
Chris@0 7410 if ( !timers.length ) {
Chris@0 7411 jQuery.fx.stop();
Chris@0 7412 }
Chris@0 7413 fxNow = undefined;
Chris@0 7414 };
Chris@0 7415
Chris@0 7416 jQuery.fx.timer = function( timer ) {
Chris@0 7417 jQuery.timers.push( timer );
Chris@0 7418 jQuery.fx.start();
Chris@0 7419 };
Chris@0 7420
Chris@0 7421 jQuery.fx.interval = 13;
Chris@0 7422 jQuery.fx.start = function() {
Chris@0 7423 if ( inProgress ) {
Chris@0 7424 return;
Chris@0 7425 }
Chris@0 7426
Chris@0 7427 inProgress = true;
Chris@0 7428 schedule();
Chris@0 7429 };
Chris@0 7430
Chris@0 7431 jQuery.fx.stop = function() {
Chris@0 7432 inProgress = null;
Chris@0 7433 };
Chris@0 7434
Chris@0 7435 jQuery.fx.speeds = {
Chris@0 7436 slow: 600,
Chris@0 7437 fast: 200,
Chris@0 7438
Chris@0 7439 // Default speed
Chris@0 7440 _default: 400
Chris@0 7441 };
Chris@0 7442
Chris@0 7443
Chris@0 7444 // Based off of the plugin by Clint Helfers, with permission.
Chris@0 7445 // https://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/
Chris@0 7446 jQuery.fn.delay = function( time, type ) {
Chris@0 7447 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
Chris@0 7448 type = type || "fx";
Chris@0 7449
Chris@0 7450 return this.queue( type, function( next, hooks ) {
Chris@0 7451 var timeout = window.setTimeout( next, time );
Chris@0 7452 hooks.stop = function() {
Chris@0 7453 window.clearTimeout( timeout );
Chris@0 7454 };
Chris@0 7455 } );
Chris@0 7456 };
Chris@0 7457
Chris@0 7458
Chris@0 7459 ( function() {
Chris@0 7460 var input = document.createElement( "input" ),
Chris@0 7461 select = document.createElement( "select" ),
Chris@0 7462 opt = select.appendChild( document.createElement( "option" ) );
Chris@0 7463
Chris@0 7464 input.type = "checkbox";
Chris@0 7465
Chris@0 7466 // Support: Android <=4.3 only
Chris@0 7467 // Default value for a checkbox should be "on"
Chris@0 7468 support.checkOn = input.value !== "";
Chris@0 7469
Chris@0 7470 // Support: IE <=11 only
Chris@0 7471 // Must access selectedIndex to make default options select
Chris@0 7472 support.optSelected = opt.selected;
Chris@0 7473
Chris@0 7474 // Support: IE <=11 only
Chris@0 7475 // An input loses its value after becoming a radio
Chris@0 7476 input = document.createElement( "input" );
Chris@0 7477 input.value = "t";
Chris@0 7478 input.type = "radio";
Chris@0 7479 support.radioValue = input.value === "t";
Chris@0 7480 } )();
Chris@0 7481
Chris@0 7482
Chris@0 7483 var boolHook,
Chris@0 7484 attrHandle = jQuery.expr.attrHandle;
Chris@0 7485
Chris@0 7486 jQuery.fn.extend( {
Chris@0 7487 attr: function( name, value ) {
Chris@0 7488 return access( this, jQuery.attr, name, value, arguments.length > 1 );
Chris@0 7489 },
Chris@0 7490
Chris@0 7491 removeAttr: function( name ) {
Chris@0 7492 return this.each( function() {
Chris@0 7493 jQuery.removeAttr( this, name );
Chris@0 7494 } );
Chris@0 7495 }
Chris@0 7496 } );
Chris@0 7497
Chris@0 7498 jQuery.extend( {
Chris@0 7499 attr: function( elem, name, value ) {
Chris@0 7500 var ret, hooks,
Chris@0 7501 nType = elem.nodeType;
Chris@0 7502
Chris@0 7503 // Don't get/set attributes on text, comment and attribute nodes
Chris@0 7504 if ( nType === 3 || nType === 8 || nType === 2 ) {
Chris@0 7505 return;
Chris@0 7506 }
Chris@0 7507
Chris@0 7508 // Fallback to prop when attributes are not supported
Chris@0 7509 if ( typeof elem.getAttribute === "undefined" ) {
Chris@0 7510 return jQuery.prop( elem, name, value );
Chris@0 7511 }
Chris@0 7512
Chris@0 7513 // Attribute hooks are determined by the lowercase version
Chris@0 7514 // Grab necessary hook if one is defined
Chris@0 7515 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
Chris@0 7516 hooks = jQuery.attrHooks[ name.toLowerCase() ] ||
Chris@0 7517 ( jQuery.expr.match.bool.test( name ) ? boolHook : undefined );
Chris@0 7518 }
Chris@0 7519
Chris@0 7520 if ( value !== undefined ) {
Chris@0 7521 if ( value === null ) {
Chris@0 7522 jQuery.removeAttr( elem, name );
Chris@0 7523 return;
Chris@0 7524 }
Chris@0 7525
Chris@0 7526 if ( hooks && "set" in hooks &&
Chris@0 7527 ( ret = hooks.set( elem, value, name ) ) !== undefined ) {
Chris@0 7528 return ret;
Chris@0 7529 }
Chris@0 7530
Chris@0 7531 elem.setAttribute( name, value + "" );
Chris@0 7532 return value;
Chris@0 7533 }
Chris@0 7534
Chris@0 7535 if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
Chris@0 7536 return ret;
Chris@0 7537 }
Chris@0 7538
Chris@0 7539 ret = jQuery.find.attr( elem, name );
Chris@0 7540
Chris@0 7541 // Non-existent attributes return null, we normalize to undefined
Chris@0 7542 return ret == null ? undefined : ret;
Chris@0 7543 },
Chris@0 7544
Chris@0 7545 attrHooks: {
Chris@0 7546 type: {
Chris@0 7547 set: function( elem, value ) {
Chris@0 7548 if ( !support.radioValue && value === "radio" &&
Chris@0 7549 nodeName( elem, "input" ) ) {
Chris@0 7550 var val = elem.value;
Chris@0 7551 elem.setAttribute( "type", value );
Chris@0 7552 if ( val ) {
Chris@0 7553 elem.value = val;
Chris@0 7554 }
Chris@0 7555 return value;
Chris@0 7556 }
Chris@0 7557 }
Chris@0 7558 }
Chris@0 7559 },
Chris@0 7560
Chris@0 7561 removeAttr: function( elem, value ) {
Chris@0 7562 var name,
Chris@0 7563 i = 0,
Chris@0 7564
Chris@0 7565 // Attribute names can contain non-HTML whitespace characters
Chris@0 7566 // https://html.spec.whatwg.org/multipage/syntax.html#attributes-2
Chris@0 7567 attrNames = value && value.match( rnothtmlwhite );
Chris@0 7568
Chris@0 7569 if ( attrNames && elem.nodeType === 1 ) {
Chris@0 7570 while ( ( name = attrNames[ i++ ] ) ) {
Chris@0 7571 elem.removeAttribute( name );
Chris@0 7572 }
Chris@0 7573 }
Chris@0 7574 }
Chris@0 7575 } );
Chris@0 7576
Chris@0 7577 // Hooks for boolean attributes
Chris@0 7578 boolHook = {
Chris@0 7579 set: function( elem, value, name ) {
Chris@0 7580 if ( value === false ) {
Chris@0 7581
Chris@0 7582 // Remove boolean attributes when set to false
Chris@0 7583 jQuery.removeAttr( elem, name );
Chris@0 7584 } else {
Chris@0 7585 elem.setAttribute( name, name );
Chris@0 7586 }
Chris@0 7587 return name;
Chris@0 7588 }
Chris@0 7589 };
Chris@0 7590
Chris@0 7591 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
Chris@0 7592 var getter = attrHandle[ name ] || jQuery.find.attr;
Chris@0 7593
Chris@0 7594 attrHandle[ name ] = function( elem, name, isXML ) {
Chris@0 7595 var ret, handle,
Chris@0 7596 lowercaseName = name.toLowerCase();
Chris@0 7597
Chris@0 7598 if ( !isXML ) {
Chris@0 7599
Chris@0 7600 // Avoid an infinite loop by temporarily removing this function from the getter
Chris@0 7601 handle = attrHandle[ lowercaseName ];
Chris@0 7602 attrHandle[ lowercaseName ] = ret;
Chris@0 7603 ret = getter( elem, name, isXML ) != null ?
Chris@0 7604 lowercaseName :
Chris@0 7605 null;
Chris@0 7606 attrHandle[ lowercaseName ] = handle;
Chris@0 7607 }
Chris@0 7608 return ret;
Chris@0 7609 };
Chris@0 7610 } );
Chris@0 7611
Chris@0 7612
Chris@0 7613
Chris@0 7614
Chris@0 7615 var rfocusable = /^(?:input|select|textarea|button)$/i,
Chris@0 7616 rclickable = /^(?:a|area)$/i;
Chris@0 7617
Chris@0 7618 jQuery.fn.extend( {
Chris@0 7619 prop: function( name, value ) {
Chris@0 7620 return access( this, jQuery.prop, name, value, arguments.length > 1 );
Chris@0 7621 },
Chris@0 7622
Chris@0 7623 removeProp: function( name ) {
Chris@0 7624 return this.each( function() {
Chris@0 7625 delete this[ jQuery.propFix[ name ] || name ];
Chris@0 7626 } );
Chris@0 7627 }
Chris@0 7628 } );
Chris@0 7629
Chris@0 7630 jQuery.extend( {
Chris@0 7631 prop: function( elem, name, value ) {
Chris@0 7632 var ret, hooks,
Chris@0 7633 nType = elem.nodeType;
Chris@0 7634
Chris@0 7635 // Don't get/set properties on text, comment and attribute nodes
Chris@0 7636 if ( nType === 3 || nType === 8 || nType === 2 ) {
Chris@0 7637 return;
Chris@0 7638 }
Chris@0 7639
Chris@0 7640 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
Chris@0 7641
Chris@0 7642 // Fix name and attach hooks
Chris@0 7643 name = jQuery.propFix[ name ] || name;
Chris@0 7644 hooks = jQuery.propHooks[ name ];
Chris@0 7645 }
Chris@0 7646
Chris@0 7647 if ( value !== undefined ) {
Chris@0 7648 if ( hooks && "set" in hooks &&
Chris@0 7649 ( ret = hooks.set( elem, value, name ) ) !== undefined ) {
Chris@0 7650 return ret;
Chris@0 7651 }
Chris@0 7652
Chris@0 7653 return ( elem[ name ] = value );
Chris@0 7654 }
Chris@0 7655
Chris@0 7656 if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
Chris@0 7657 return ret;
Chris@0 7658 }
Chris@0 7659
Chris@0 7660 return elem[ name ];
Chris@0 7661 },
Chris@0 7662
Chris@0 7663 propHooks: {
Chris@0 7664 tabIndex: {
Chris@0 7665 get: function( elem ) {
Chris@0 7666
Chris@0 7667 // Support: IE <=9 - 11 only
Chris@0 7668 // elem.tabIndex doesn't always return the
Chris@0 7669 // correct value when it hasn't been explicitly set
Chris@0 7670 // https://web.archive.org/web/20141116233347/http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
Chris@0 7671 // Use proper attribute retrieval(#12072)
Chris@0 7672 var tabindex = jQuery.find.attr( elem, "tabindex" );
Chris@0 7673
Chris@0 7674 if ( tabindex ) {
Chris@0 7675 return parseInt( tabindex, 10 );
Chris@0 7676 }
Chris@0 7677
Chris@0 7678 if (
Chris@0 7679 rfocusable.test( elem.nodeName ) ||
Chris@0 7680 rclickable.test( elem.nodeName ) &&
Chris@0 7681 elem.href
Chris@0 7682 ) {
Chris@0 7683 return 0;
Chris@0 7684 }
Chris@0 7685
Chris@0 7686 return -1;
Chris@0 7687 }
Chris@0 7688 }
Chris@0 7689 },
Chris@0 7690
Chris@0 7691 propFix: {
Chris@0 7692 "for": "htmlFor",
Chris@0 7693 "class": "className"
Chris@0 7694 }
Chris@0 7695 } );
Chris@0 7696
Chris@0 7697 // Support: IE <=11 only
Chris@0 7698 // Accessing the selectedIndex property
Chris@0 7699 // forces the browser to respect setting selected
Chris@0 7700 // on the option
Chris@0 7701 // The getter ensures a default option is selected
Chris@0 7702 // when in an optgroup
Chris@0 7703 // eslint rule "no-unused-expressions" is disabled for this code
Chris@0 7704 // since it considers such accessions noop
Chris@0 7705 if ( !support.optSelected ) {
Chris@0 7706 jQuery.propHooks.selected = {
Chris@0 7707 get: function( elem ) {
Chris@0 7708
Chris@0 7709 /* eslint no-unused-expressions: "off" */
Chris@0 7710
Chris@0 7711 var parent = elem.parentNode;
Chris@0 7712 if ( parent && parent.parentNode ) {
Chris@0 7713 parent.parentNode.selectedIndex;
Chris@0 7714 }
Chris@0 7715 return null;
Chris@0 7716 },
Chris@0 7717 set: function( elem ) {
Chris@0 7718
Chris@0 7719 /* eslint no-unused-expressions: "off" */
Chris@0 7720
Chris@0 7721 var parent = elem.parentNode;
Chris@0 7722 if ( parent ) {
Chris@0 7723 parent.selectedIndex;
Chris@0 7724
Chris@0 7725 if ( parent.parentNode ) {
Chris@0 7726 parent.parentNode.selectedIndex;
Chris@0 7727 }
Chris@0 7728 }
Chris@0 7729 }
Chris@0 7730 };
Chris@0 7731 }
Chris@0 7732
Chris@0 7733 jQuery.each( [
Chris@0 7734 "tabIndex",
Chris@0 7735 "readOnly",
Chris@0 7736 "maxLength",
Chris@0 7737 "cellSpacing",
Chris@0 7738 "cellPadding",
Chris@0 7739 "rowSpan",
Chris@0 7740 "colSpan",
Chris@0 7741 "useMap",
Chris@0 7742 "frameBorder",
Chris@0 7743 "contentEditable"
Chris@0 7744 ], function() {
Chris@0 7745 jQuery.propFix[ this.toLowerCase() ] = this;
Chris@0 7746 } );
Chris@0 7747
Chris@0 7748
Chris@0 7749
Chris@0 7750
Chris@0 7751 // Strip and collapse whitespace according to HTML spec
Chris@0 7752 // https://html.spec.whatwg.org/multipage/infrastructure.html#strip-and-collapse-whitespace
Chris@0 7753 function stripAndCollapse( value ) {
Chris@0 7754 var tokens = value.match( rnothtmlwhite ) || [];
Chris@0 7755 return tokens.join( " " );
Chris@0 7756 }
Chris@0 7757
Chris@0 7758
Chris@0 7759 function getClass( elem ) {
Chris@0 7760 return elem.getAttribute && elem.getAttribute( "class" ) || "";
Chris@0 7761 }
Chris@0 7762
Chris@0 7763 jQuery.fn.extend( {
Chris@0 7764 addClass: function( value ) {
Chris@0 7765 var classes, elem, cur, curValue, clazz, j, finalValue,
Chris@0 7766 i = 0;
Chris@0 7767
Chris@0 7768 if ( jQuery.isFunction( value ) ) {
Chris@0 7769 return this.each( function( j ) {
Chris@0 7770 jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
Chris@0 7771 } );
Chris@0 7772 }
Chris@0 7773
Chris@0 7774 if ( typeof value === "string" && value ) {
Chris@0 7775 classes = value.match( rnothtmlwhite ) || [];
Chris@0 7776
Chris@0 7777 while ( ( elem = this[ i++ ] ) ) {
Chris@0 7778 curValue = getClass( elem );
Chris@0 7779 cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " );
Chris@0 7780
Chris@0 7781 if ( cur ) {
Chris@0 7782 j = 0;
Chris@0 7783 while ( ( clazz = classes[ j++ ] ) ) {
Chris@0 7784 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
Chris@0 7785 cur += clazz + " ";
Chris@0 7786 }
Chris@0 7787 }
Chris@0 7788
Chris@0 7789 // Only assign if different to avoid unneeded rendering.
Chris@0 7790 finalValue = stripAndCollapse( cur );
Chris@0 7791 if ( curValue !== finalValue ) {
Chris@0 7792 elem.setAttribute( "class", finalValue );
Chris@0 7793 }
Chris@0 7794 }
Chris@0 7795 }
Chris@0 7796 }
Chris@0 7797
Chris@0 7798 return this;
Chris@0 7799 },
Chris@0 7800
Chris@0 7801 removeClass: function( value ) {
Chris@0 7802 var classes, elem, cur, curValue, clazz, j, finalValue,
Chris@0 7803 i = 0;
Chris@0 7804
Chris@0 7805 if ( jQuery.isFunction( value ) ) {
Chris@0 7806 return this.each( function( j ) {
Chris@0 7807 jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
Chris@0 7808 } );
Chris@0 7809 }
Chris@0 7810
Chris@0 7811 if ( !arguments.length ) {
Chris@0 7812 return this.attr( "class", "" );
Chris@0 7813 }
Chris@0 7814
Chris@0 7815 if ( typeof value === "string" && value ) {
Chris@0 7816 classes = value.match( rnothtmlwhite ) || [];
Chris@0 7817
Chris@0 7818 while ( ( elem = this[ i++ ] ) ) {
Chris@0 7819 curValue = getClass( elem );
Chris@0 7820
Chris@0 7821 // This expression is here for better compressibility (see addClass)
Chris@0 7822 cur = elem.nodeType === 1 && ( " " + stripAndCollapse( curValue ) + " " );
Chris@0 7823
Chris@0 7824 if ( cur ) {
Chris@0 7825 j = 0;
Chris@0 7826 while ( ( clazz = classes[ j++ ] ) ) {
Chris@0 7827
Chris@0 7828 // Remove *all* instances
Chris@0 7829 while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
Chris@0 7830 cur = cur.replace( " " + clazz + " ", " " );
Chris@0 7831 }
Chris@0 7832 }
Chris@0 7833
Chris@0 7834 // Only assign if different to avoid unneeded rendering.
Chris@0 7835 finalValue = stripAndCollapse( cur );
Chris@0 7836 if ( curValue !== finalValue ) {
Chris@0 7837 elem.setAttribute( "class", finalValue );
Chris@0 7838 }
Chris@0 7839 }
Chris@0 7840 }
Chris@0 7841 }
Chris@0 7842
Chris@0 7843 return this;
Chris@0 7844 },
Chris@0 7845
Chris@0 7846 toggleClass: function( value, stateVal ) {
Chris@0 7847 var type = typeof value;
Chris@0 7848
Chris@0 7849 if ( typeof stateVal === "boolean" && type === "string" ) {
Chris@0 7850 return stateVal ? this.addClass( value ) : this.removeClass( value );
Chris@0 7851 }
Chris@0 7852
Chris@0 7853 if ( jQuery.isFunction( value ) ) {
Chris@0 7854 return this.each( function( i ) {
Chris@0 7855 jQuery( this ).toggleClass(
Chris@0 7856 value.call( this, i, getClass( this ), stateVal ),
Chris@0 7857 stateVal
Chris@0 7858 );
Chris@0 7859 } );
Chris@0 7860 }
Chris@0 7861
Chris@0 7862 return this.each( function() {
Chris@0 7863 var className, i, self, classNames;
Chris@0 7864
Chris@0 7865 if ( type === "string" ) {
Chris@0 7866
Chris@0 7867 // Toggle individual class names
Chris@0 7868 i = 0;
Chris@0 7869 self = jQuery( this );
Chris@0 7870 classNames = value.match( rnothtmlwhite ) || [];
Chris@0 7871
Chris@0 7872 while ( ( className = classNames[ i++ ] ) ) {
Chris@0 7873
Chris@0 7874 // Check each className given, space separated list
Chris@0 7875 if ( self.hasClass( className ) ) {
Chris@0 7876 self.removeClass( className );
Chris@0 7877 } else {
Chris@0 7878 self.addClass( className );
Chris@0 7879 }
Chris@0 7880 }
Chris@0 7881
Chris@0 7882 // Toggle whole class name
Chris@0 7883 } else if ( value === undefined || type === "boolean" ) {
Chris@0 7884 className = getClass( this );
Chris@0 7885 if ( className ) {
Chris@0 7886
Chris@0 7887 // Store className if set
Chris@0 7888 dataPriv.set( this, "__className__", className );
Chris@0 7889 }
Chris@0 7890
Chris@0 7891 // If the element has a class name or if we're passed `false`,
Chris@0 7892 // then remove the whole classname (if there was one, the above saved it).
Chris@0 7893 // Otherwise bring back whatever was previously saved (if anything),
Chris@0 7894 // falling back to the empty string if nothing was stored.
Chris@0 7895 if ( this.setAttribute ) {
Chris@0 7896 this.setAttribute( "class",
Chris@0 7897 className || value === false ?
Chris@0 7898 "" :
Chris@0 7899 dataPriv.get( this, "__className__" ) || ""
Chris@0 7900 );
Chris@0 7901 }
Chris@0 7902 }
Chris@0 7903 } );
Chris@0 7904 },
Chris@0 7905
Chris@0 7906 hasClass: function( selector ) {
Chris@0 7907 var className, elem,
Chris@0 7908 i = 0;
Chris@0 7909
Chris@0 7910 className = " " + selector + " ";
Chris@0 7911 while ( ( elem = this[ i++ ] ) ) {
Chris@0 7912 if ( elem.nodeType === 1 &&
Chris@0 7913 ( " " + stripAndCollapse( getClass( elem ) ) + " " ).indexOf( className ) > -1 ) {
Chris@0 7914 return true;
Chris@0 7915 }
Chris@0 7916 }
Chris@0 7917
Chris@0 7918 return false;
Chris@0 7919 }
Chris@0 7920 } );
Chris@0 7921
Chris@0 7922
Chris@0 7923
Chris@0 7924
Chris@0 7925 var rreturn = /\r/g;
Chris@0 7926
Chris@0 7927 jQuery.fn.extend( {
Chris@0 7928 val: function( value ) {
Chris@0 7929 var hooks, ret, isFunction,
Chris@0 7930 elem = this[ 0 ];
Chris@0 7931
Chris@0 7932 if ( !arguments.length ) {
Chris@0 7933 if ( elem ) {
Chris@0 7934 hooks = jQuery.valHooks[ elem.type ] ||
Chris@0 7935 jQuery.valHooks[ elem.nodeName.toLowerCase() ];
Chris@0 7936
Chris@0 7937 if ( hooks &&
Chris@0 7938 "get" in hooks &&
Chris@0 7939 ( ret = hooks.get( elem, "value" ) ) !== undefined
Chris@0 7940 ) {
Chris@0 7941 return ret;
Chris@0 7942 }
Chris@0 7943
Chris@0 7944 ret = elem.value;
Chris@0 7945
Chris@0 7946 // Handle most common string cases
Chris@0 7947 if ( typeof ret === "string" ) {
Chris@0 7948 return ret.replace( rreturn, "" );
Chris@0 7949 }
Chris@0 7950
Chris@0 7951 // Handle cases where value is null/undef or number
Chris@0 7952 return ret == null ? "" : ret;
Chris@0 7953 }
Chris@0 7954
Chris@0 7955 return;
Chris@0 7956 }
Chris@0 7957
Chris@0 7958 isFunction = jQuery.isFunction( value );
Chris@0 7959
Chris@0 7960 return this.each( function( i ) {
Chris@0 7961 var val;
Chris@0 7962
Chris@0 7963 if ( this.nodeType !== 1 ) {
Chris@0 7964 return;
Chris@0 7965 }
Chris@0 7966
Chris@0 7967 if ( isFunction ) {
Chris@0 7968 val = value.call( this, i, jQuery( this ).val() );
Chris@0 7969 } else {
Chris@0 7970 val = value;
Chris@0 7971 }
Chris@0 7972
Chris@0 7973 // Treat null/undefined as ""; convert numbers to string
Chris@0 7974 if ( val == null ) {
Chris@0 7975 val = "";
Chris@0 7976
Chris@0 7977 } else if ( typeof val === "number" ) {
Chris@0 7978 val += "";
Chris@0 7979
Chris@0 7980 } else if ( Array.isArray( val ) ) {
Chris@0 7981 val = jQuery.map( val, function( value ) {
Chris@0 7982 return value == null ? "" : value + "";
Chris@0 7983 } );
Chris@0 7984 }
Chris@0 7985
Chris@0 7986 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
Chris@0 7987
Chris@0 7988 // If set returns undefined, fall back to normal setting
Chris@0 7989 if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
Chris@0 7990 this.value = val;
Chris@0 7991 }
Chris@0 7992 } );
Chris@0 7993 }
Chris@0 7994 } );
Chris@0 7995
Chris@0 7996 jQuery.extend( {
Chris@0 7997 valHooks: {
Chris@0 7998 option: {
Chris@0 7999 get: function( elem ) {
Chris@0 8000
Chris@0 8001 var val = jQuery.find.attr( elem, "value" );
Chris@0 8002 return val != null ?
Chris@0 8003 val :
Chris@0 8004
Chris@0 8005 // Support: IE <=10 - 11 only
Chris@0 8006 // option.text throws exceptions (#14686, #14858)
Chris@0 8007 // Strip and collapse whitespace
Chris@0 8008 // https://html.spec.whatwg.org/#strip-and-collapse-whitespace
Chris@0 8009 stripAndCollapse( jQuery.text( elem ) );
Chris@0 8010 }
Chris@0 8011 },
Chris@0 8012 select: {
Chris@0 8013 get: function( elem ) {
Chris@0 8014 var value, option, i,
Chris@0 8015 options = elem.options,
Chris@0 8016 index = elem.selectedIndex,
Chris@0 8017 one = elem.type === "select-one",
Chris@0 8018 values = one ? null : [],
Chris@0 8019 max = one ? index + 1 : options.length;
Chris@0 8020
Chris@0 8021 if ( index < 0 ) {
Chris@0 8022 i = max;
Chris@0 8023
Chris@0 8024 } else {
Chris@0 8025 i = one ? index : 0;
Chris@0 8026 }
Chris@0 8027
Chris@0 8028 // Loop through all the selected options
Chris@0 8029 for ( ; i < max; i++ ) {
Chris@0 8030 option = options[ i ];
Chris@0 8031
Chris@0 8032 // Support: IE <=9 only
Chris@0 8033 // IE8-9 doesn't update selected after form reset (#2551)
Chris@0 8034 if ( ( option.selected || i === index ) &&
Chris@0 8035
Chris@0 8036 // Don't return options that are disabled or in a disabled optgroup
Chris@0 8037 !option.disabled &&
Chris@0 8038 ( !option.parentNode.disabled ||
Chris@0 8039 !nodeName( option.parentNode, "optgroup" ) ) ) {
Chris@0 8040
Chris@0 8041 // Get the specific value for the option
Chris@0 8042 value = jQuery( option ).val();
Chris@0 8043
Chris@0 8044 // We don't need an array for one selects
Chris@0 8045 if ( one ) {
Chris@0 8046 return value;
Chris@0 8047 }
Chris@0 8048
Chris@0 8049 // Multi-Selects return an array
Chris@0 8050 values.push( value );
Chris@0 8051 }
Chris@0 8052 }
Chris@0 8053
Chris@0 8054 return values;
Chris@0 8055 },
Chris@0 8056
Chris@0 8057 set: function( elem, value ) {
Chris@0 8058 var optionSet, option,
Chris@0 8059 options = elem.options,
Chris@0 8060 values = jQuery.makeArray( value ),
Chris@0 8061 i = options.length;
Chris@0 8062
Chris@0 8063 while ( i-- ) {
Chris@0 8064 option = options[ i ];
Chris@0 8065
Chris@0 8066 /* eslint-disable no-cond-assign */
Chris@0 8067
Chris@0 8068 if ( option.selected =
Chris@0 8069 jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
Chris@0 8070 ) {
Chris@0 8071 optionSet = true;
Chris@0 8072 }
Chris@0 8073
Chris@0 8074 /* eslint-enable no-cond-assign */
Chris@0 8075 }
Chris@0 8076
Chris@0 8077 // Force browsers to behave consistently when non-matching value is set
Chris@0 8078 if ( !optionSet ) {
Chris@0 8079 elem.selectedIndex = -1;
Chris@0 8080 }
Chris@0 8081 return values;
Chris@0 8082 }
Chris@0 8083 }
Chris@0 8084 }
Chris@0 8085 } );
Chris@0 8086
Chris@0 8087 // Radios and checkboxes getter/setter
Chris@0 8088 jQuery.each( [ "radio", "checkbox" ], function() {
Chris@0 8089 jQuery.valHooks[ this ] = {
Chris@0 8090 set: function( elem, value ) {
Chris@0 8091 if ( Array.isArray( value ) ) {
Chris@0 8092 return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
Chris@0 8093 }
Chris@0 8094 }
Chris@0 8095 };
Chris@0 8096 if ( !support.checkOn ) {
Chris@0 8097 jQuery.valHooks[ this ].get = function( elem ) {
Chris@0 8098 return elem.getAttribute( "value" ) === null ? "on" : elem.value;
Chris@0 8099 };
Chris@0 8100 }
Chris@0 8101 } );
Chris@0 8102
Chris@0 8103
Chris@0 8104
Chris@0 8105
Chris@0 8106 // Return jQuery for attributes-only inclusion
Chris@0 8107
Chris@0 8108
Chris@0 8109 var rfocusMorph = /^(?:focusinfocus|focusoutblur)$/;
Chris@0 8110
Chris@0 8111 jQuery.extend( jQuery.event, {
Chris@0 8112
Chris@0 8113 trigger: function( event, data, elem, onlyHandlers ) {
Chris@0 8114
Chris@0 8115 var i, cur, tmp, bubbleType, ontype, handle, special,
Chris@0 8116 eventPath = [ elem || document ],
Chris@0 8117 type = hasOwn.call( event, "type" ) ? event.type : event,
Chris@0 8118 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : [];
Chris@0 8119
Chris@0 8120 cur = tmp = elem = elem || document;
Chris@0 8121
Chris@0 8122 // Don't do events on text and comment nodes
Chris@0 8123 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
Chris@0 8124 return;
Chris@0 8125 }
Chris@0 8126
Chris@0 8127 // focus/blur morphs to focusin/out; ensure we're not firing them right now
Chris@0 8128 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
Chris@0 8129 return;
Chris@0 8130 }
Chris@0 8131
Chris@0 8132 if ( type.indexOf( "." ) > -1 ) {
Chris@0 8133
Chris@0 8134 // Namespaced trigger; create a regexp to match event type in handle()
Chris@0 8135 namespaces = type.split( "." );
Chris@0 8136 type = namespaces.shift();
Chris@0 8137 namespaces.sort();
Chris@0 8138 }
Chris@0 8139 ontype = type.indexOf( ":" ) < 0 && "on" + type;
Chris@0 8140
Chris@0 8141 // Caller can pass in a jQuery.Event object, Object, or just an event type string
Chris@0 8142 event = event[ jQuery.expando ] ?
Chris@0 8143 event :
Chris@0 8144 new jQuery.Event( type, typeof event === "object" && event );
Chris@0 8145
Chris@0 8146 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
Chris@0 8147 event.isTrigger = onlyHandlers ? 2 : 3;
Chris@0 8148 event.namespace = namespaces.join( "." );
Chris@0 8149 event.rnamespace = event.namespace ?
Chris@0 8150 new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) :
Chris@0 8151 null;
Chris@0 8152
Chris@0 8153 // Clean up the event in case it is being reused
Chris@0 8154 event.result = undefined;
Chris@0 8155 if ( !event.target ) {
Chris@0 8156 event.target = elem;
Chris@0 8157 }
Chris@0 8158
Chris@0 8159 // Clone any incoming data and prepend the event, creating the handler arg list
Chris@0 8160 data = data == null ?
Chris@0 8161 [ event ] :
Chris@0 8162 jQuery.makeArray( data, [ event ] );
Chris@0 8163
Chris@0 8164 // Allow special events to draw outside the lines
Chris@0 8165 special = jQuery.event.special[ type ] || {};
Chris@0 8166 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
Chris@0 8167 return;
Chris@0 8168 }
Chris@0 8169
Chris@0 8170 // Determine event propagation path in advance, per W3C events spec (#9951)
Chris@0 8171 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
Chris@0 8172 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
Chris@0 8173
Chris@0 8174 bubbleType = special.delegateType || type;
Chris@0 8175 if ( !rfocusMorph.test( bubbleType + type ) ) {
Chris@0 8176 cur = cur.parentNode;
Chris@0 8177 }
Chris@0 8178 for ( ; cur; cur = cur.parentNode ) {
Chris@0 8179 eventPath.push( cur );
Chris@0 8180 tmp = cur;
Chris@0 8181 }
Chris@0 8182
Chris@0 8183 // Only add window if we got to document (e.g., not plain obj or detached DOM)
Chris@0 8184 if ( tmp === ( elem.ownerDocument || document ) ) {
Chris@0 8185 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
Chris@0 8186 }
Chris@0 8187 }
Chris@0 8188
Chris@0 8189 // Fire handlers on the event path
Chris@0 8190 i = 0;
Chris@0 8191 while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) {
Chris@0 8192
Chris@0 8193 event.type = i > 1 ?
Chris@0 8194 bubbleType :
Chris@0 8195 special.bindType || type;
Chris@0 8196
Chris@0 8197 // jQuery handler
Chris@0 8198 handle = ( dataPriv.get( cur, "events" ) || {} )[ event.type ] &&
Chris@0 8199 dataPriv.get( cur, "handle" );
Chris@0 8200 if ( handle ) {
Chris@0 8201 handle.apply( cur, data );
Chris@0 8202 }
Chris@0 8203
Chris@0 8204 // Native handler
Chris@0 8205 handle = ontype && cur[ ontype ];
Chris@0 8206 if ( handle && handle.apply && acceptData( cur ) ) {
Chris@0 8207 event.result = handle.apply( cur, data );
Chris@0 8208 if ( event.result === false ) {
Chris@0 8209 event.preventDefault();
Chris@0 8210 }
Chris@0 8211 }
Chris@0 8212 }
Chris@0 8213 event.type = type;
Chris@0 8214
Chris@0 8215 // If nobody prevented the default action, do it now
Chris@0 8216 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
Chris@0 8217
Chris@0 8218 if ( ( !special._default ||
Chris@0 8219 special._default.apply( eventPath.pop(), data ) === false ) &&
Chris@0 8220 acceptData( elem ) ) {
Chris@0 8221
Chris@0 8222 // Call a native DOM method on the target with the same name as the event.
Chris@0 8223 // Don't do default actions on window, that's where global variables be (#6170)
Chris@0 8224 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
Chris@0 8225
Chris@0 8226 // Don't re-trigger an onFOO event when we call its FOO() method
Chris@0 8227 tmp = elem[ ontype ];
Chris@0 8228
Chris@0 8229 if ( tmp ) {
Chris@0 8230 elem[ ontype ] = null;
Chris@0 8231 }
Chris@0 8232
Chris@0 8233 // Prevent re-triggering of the same event, since we already bubbled it above
Chris@0 8234 jQuery.event.triggered = type;
Chris@0 8235 elem[ type ]();
Chris@0 8236 jQuery.event.triggered = undefined;
Chris@0 8237
Chris@0 8238 if ( tmp ) {
Chris@0 8239 elem[ ontype ] = tmp;
Chris@0 8240 }
Chris@0 8241 }
Chris@0 8242 }
Chris@0 8243 }
Chris@0 8244
Chris@0 8245 return event.result;
Chris@0 8246 },
Chris@0 8247
Chris@0 8248 // Piggyback on a donor event to simulate a different one
Chris@0 8249 // Used only for `focus(in | out)` events
Chris@0 8250 simulate: function( type, elem, event ) {
Chris@0 8251 var e = jQuery.extend(
Chris@0 8252 new jQuery.Event(),
Chris@0 8253 event,
Chris@0 8254 {
Chris@0 8255 type: type,
Chris@0 8256 isSimulated: true
Chris@0 8257 }
Chris@0 8258 );
Chris@0 8259
Chris@0 8260 jQuery.event.trigger( e, null, elem );
Chris@0 8261 }
Chris@0 8262
Chris@0 8263 } );
Chris@0 8264
Chris@0 8265 jQuery.fn.extend( {
Chris@0 8266
Chris@0 8267 trigger: function( type, data ) {
Chris@0 8268 return this.each( function() {
Chris@0 8269 jQuery.event.trigger( type, data, this );
Chris@0 8270 } );
Chris@0 8271 },
Chris@0 8272 triggerHandler: function( type, data ) {
Chris@0 8273 var elem = this[ 0 ];
Chris@0 8274 if ( elem ) {
Chris@0 8275 return jQuery.event.trigger( type, data, elem, true );
Chris@0 8276 }
Chris@0 8277 }
Chris@0 8278 } );
Chris@0 8279
Chris@0 8280
Chris@0 8281 jQuery.each( ( "blur focus focusin focusout resize scroll click dblclick " +
Chris@0 8282 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
Chris@0 8283 "change select submit keydown keypress keyup contextmenu" ).split( " " ),
Chris@0 8284 function( i, name ) {
Chris@0 8285
Chris@0 8286 // Handle event binding
Chris@0 8287 jQuery.fn[ name ] = function( data, fn ) {
Chris@0 8288 return arguments.length > 0 ?
Chris@0 8289 this.on( name, null, data, fn ) :
Chris@0 8290 this.trigger( name );
Chris@0 8291 };
Chris@0 8292 } );
Chris@0 8293
Chris@0 8294 jQuery.fn.extend( {
Chris@0 8295 hover: function( fnOver, fnOut ) {
Chris@0 8296 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
Chris@0 8297 }
Chris@0 8298 } );
Chris@0 8299
Chris@0 8300
Chris@0 8301
Chris@0 8302
Chris@0 8303 support.focusin = "onfocusin" in window;
Chris@0 8304
Chris@0 8305
Chris@0 8306 // Support: Firefox <=44
Chris@0 8307 // Firefox doesn't have focus(in | out) events
Chris@0 8308 // Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787
Chris@0 8309 //
Chris@0 8310 // Support: Chrome <=48 - 49, Safari <=9.0 - 9.1
Chris@0 8311 // focus(in | out) events fire after focus & blur events,
Chris@0 8312 // which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order
Chris@0 8313 // Related ticket - https://bugs.chromium.org/p/chromium/issues/detail?id=449857
Chris@0 8314 if ( !support.focusin ) {
Chris@0 8315 jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) {
Chris@0 8316
Chris@0 8317 // Attach a single capturing handler on the document while someone wants focusin/focusout
Chris@0 8318 var handler = function( event ) {
Chris@0 8319 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) );
Chris@0 8320 };
Chris@0 8321
Chris@0 8322 jQuery.event.special[ fix ] = {
Chris@0 8323 setup: function() {
Chris@0 8324 var doc = this.ownerDocument || this,
Chris@0 8325 attaches = dataPriv.access( doc, fix );
Chris@0 8326
Chris@0 8327 if ( !attaches ) {
Chris@0 8328 doc.addEventListener( orig, handler, true );
Chris@0 8329 }
Chris@0 8330 dataPriv.access( doc, fix, ( attaches || 0 ) + 1 );
Chris@0 8331 },
Chris@0 8332 teardown: function() {
Chris@0 8333 var doc = this.ownerDocument || this,
Chris@0 8334 attaches = dataPriv.access( doc, fix ) - 1;
Chris@0 8335
Chris@0 8336 if ( !attaches ) {
Chris@0 8337 doc.removeEventListener( orig, handler, true );
Chris@0 8338 dataPriv.remove( doc, fix );
Chris@0 8339
Chris@0 8340 } else {
Chris@0 8341 dataPriv.access( doc, fix, attaches );
Chris@0 8342 }
Chris@0 8343 }
Chris@0 8344 };
Chris@0 8345 } );
Chris@0 8346 }
Chris@0 8347 var location = window.location;
Chris@0 8348
Chris@0 8349 var nonce = jQuery.now();
Chris@0 8350
Chris@0 8351 var rquery = ( /\?/ );
Chris@0 8352
Chris@0 8353
Chris@0 8354
Chris@0 8355 // Cross-browser xml parsing
Chris@0 8356 jQuery.parseXML = function( data ) {
Chris@0 8357 var xml;
Chris@0 8358 if ( !data || typeof data !== "string" ) {
Chris@0 8359 return null;
Chris@0 8360 }
Chris@0 8361
Chris@0 8362 // Support: IE 9 - 11 only
Chris@0 8363 // IE throws on parseFromString with invalid input.
Chris@0 8364 try {
Chris@0 8365 xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" );
Chris@0 8366 } catch ( e ) {
Chris@0 8367 xml = undefined;
Chris@0 8368 }
Chris@0 8369
Chris@0 8370 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
Chris@0 8371 jQuery.error( "Invalid XML: " + data );
Chris@0 8372 }
Chris@0 8373 return xml;
Chris@0 8374 };
Chris@0 8375
Chris@0 8376
Chris@0 8377 var
Chris@0 8378 rbracket = /\[\]$/,
Chris@0 8379 rCRLF = /\r?\n/g,
Chris@0 8380 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
Chris@0 8381 rsubmittable = /^(?:input|select|textarea|keygen)/i;
Chris@0 8382
Chris@0 8383 function buildParams( prefix, obj, traditional, add ) {
Chris@0 8384 var name;
Chris@0 8385
Chris@0 8386 if ( Array.isArray( obj ) ) {
Chris@0 8387
Chris@0 8388 // Serialize array item.
Chris@0 8389 jQuery.each( obj, function( i, v ) {
Chris@0 8390 if ( traditional || rbracket.test( prefix ) ) {
Chris@0 8391
Chris@0 8392 // Treat each array item as a scalar.
Chris@0 8393 add( prefix, v );
Chris@0 8394
Chris@0 8395 } else {
Chris@0 8396
Chris@0 8397 // Item is non-scalar (array or object), encode its numeric index.
Chris@0 8398 buildParams(
Chris@0 8399 prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
Chris@0 8400 v,
Chris@0 8401 traditional,
Chris@0 8402 add
Chris@0 8403 );
Chris@0 8404 }
Chris@0 8405 } );
Chris@0 8406
Chris@0 8407 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
Chris@0 8408
Chris@0 8409 // Serialize object item.
Chris@0 8410 for ( name in obj ) {
Chris@0 8411 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
Chris@0 8412 }
Chris@0 8413
Chris@0 8414 } else {
Chris@0 8415
Chris@0 8416 // Serialize scalar item.
Chris@0 8417 add( prefix, obj );
Chris@0 8418 }
Chris@0 8419 }
Chris@0 8420
Chris@0 8421 // Serialize an array of form elements or a set of
Chris@0 8422 // key/values into a query string
Chris@0 8423 jQuery.param = function( a, traditional ) {
Chris@0 8424 var prefix,
Chris@0 8425 s = [],
Chris@0 8426 add = function( key, valueOrFunction ) {
Chris@0 8427
Chris@0 8428 // If value is a function, invoke it and use its return value
Chris@0 8429 var value = jQuery.isFunction( valueOrFunction ) ?
Chris@0 8430 valueOrFunction() :
Chris@0 8431 valueOrFunction;
Chris@0 8432
Chris@0 8433 s[ s.length ] = encodeURIComponent( key ) + "=" +
Chris@0 8434 encodeURIComponent( value == null ? "" : value );
Chris@0 8435 };
Chris@0 8436
Chris@0 8437 // If an array was passed in, assume that it is an array of form elements.
Chris@0 8438 if ( Array.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
Chris@0 8439
Chris@0 8440 // Serialize the form elements
Chris@0 8441 jQuery.each( a, function() {
Chris@0 8442 add( this.name, this.value );
Chris@0 8443 } );
Chris@0 8444
Chris@0 8445 } else {
Chris@0 8446
Chris@0 8447 // If traditional, encode the "old" way (the way 1.3.2 or older
Chris@0 8448 // did it), otherwise encode params recursively.
Chris@0 8449 for ( prefix in a ) {
Chris@0 8450 buildParams( prefix, a[ prefix ], traditional, add );
Chris@0 8451 }
Chris@0 8452 }
Chris@0 8453
Chris@0 8454 // Return the resulting serialization
Chris@0 8455 return s.join( "&" );
Chris@0 8456 };
Chris@0 8457
Chris@0 8458 jQuery.fn.extend( {
Chris@0 8459 serialize: function() {
Chris@0 8460 return jQuery.param( this.serializeArray() );
Chris@0 8461 },
Chris@0 8462 serializeArray: function() {
Chris@0 8463 return this.map( function() {
Chris@0 8464
Chris@0 8465 // Can add propHook for "elements" to filter or add form elements
Chris@0 8466 var elements = jQuery.prop( this, "elements" );
Chris@0 8467 return elements ? jQuery.makeArray( elements ) : this;
Chris@0 8468 } )
Chris@0 8469 .filter( function() {
Chris@0 8470 var type = this.type;
Chris@0 8471
Chris@0 8472 // Use .is( ":disabled" ) so that fieldset[disabled] works
Chris@0 8473 return this.name && !jQuery( this ).is( ":disabled" ) &&
Chris@0 8474 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
Chris@0 8475 ( this.checked || !rcheckableType.test( type ) );
Chris@0 8476 } )
Chris@0 8477 .map( function( i, elem ) {
Chris@0 8478 var val = jQuery( this ).val();
Chris@0 8479
Chris@0 8480 if ( val == null ) {
Chris@0 8481 return null;
Chris@0 8482 }
Chris@0 8483
Chris@0 8484 if ( Array.isArray( val ) ) {
Chris@0 8485 return jQuery.map( val, function( val ) {
Chris@0 8486 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
Chris@0 8487 } );
Chris@0 8488 }
Chris@0 8489
Chris@0 8490 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
Chris@0 8491 } ).get();
Chris@0 8492 }
Chris@0 8493 } );
Chris@0 8494
Chris@0 8495
Chris@0 8496 var
Chris@0 8497 r20 = /%20/g,
Chris@0 8498 rhash = /#.*$/,
Chris@0 8499 rantiCache = /([?&])_=[^&]*/,
Chris@0 8500 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
Chris@0 8501
Chris@0 8502 // #7653, #8125, #8152: local protocol detection
Chris@0 8503 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
Chris@0 8504 rnoContent = /^(?:GET|HEAD)$/,
Chris@0 8505 rprotocol = /^\/\//,
Chris@0 8506
Chris@0 8507 /* Prefilters
Chris@0 8508 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
Chris@0 8509 * 2) These are called:
Chris@0 8510 * - BEFORE asking for a transport
Chris@0 8511 * - AFTER param serialization (s.data is a string if s.processData is true)
Chris@0 8512 * 3) key is the dataType
Chris@0 8513 * 4) the catchall symbol "*" can be used
Chris@0 8514 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
Chris@0 8515 */
Chris@0 8516 prefilters = {},
Chris@0 8517
Chris@0 8518 /* Transports bindings
Chris@0 8519 * 1) key is the dataType
Chris@0 8520 * 2) the catchall symbol "*" can be used
Chris@0 8521 * 3) selection will start with transport dataType and THEN go to "*" if needed
Chris@0 8522 */
Chris@0 8523 transports = {},
Chris@0 8524
Chris@0 8525 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
Chris@0 8526 allTypes = "*/".concat( "*" ),
Chris@0 8527
Chris@0 8528 // Anchor tag for parsing the document origin
Chris@0 8529 originAnchor = document.createElement( "a" );
Chris@0 8530 originAnchor.href = location.href;
Chris@0 8531
Chris@0 8532 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
Chris@0 8533 function addToPrefiltersOrTransports( structure ) {
Chris@0 8534
Chris@0 8535 // dataTypeExpression is optional and defaults to "*"
Chris@0 8536 return function( dataTypeExpression, func ) {
Chris@0 8537
Chris@0 8538 if ( typeof dataTypeExpression !== "string" ) {
Chris@0 8539 func = dataTypeExpression;
Chris@0 8540 dataTypeExpression = "*";
Chris@0 8541 }
Chris@0 8542
Chris@0 8543 var dataType,
Chris@0 8544 i = 0,
Chris@0 8545 dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];
Chris@0 8546
Chris@0 8547 if ( jQuery.isFunction( func ) ) {
Chris@0 8548
Chris@0 8549 // For each dataType in the dataTypeExpression
Chris@0 8550 while ( ( dataType = dataTypes[ i++ ] ) ) {
Chris@0 8551
Chris@0 8552 // Prepend if requested
Chris@0 8553 if ( dataType[ 0 ] === "+" ) {
Chris@0 8554 dataType = dataType.slice( 1 ) || "*";
Chris@0 8555 ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
Chris@0 8556
Chris@0 8557 // Otherwise append
Chris@0 8558 } else {
Chris@0 8559 ( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
Chris@0 8560 }
Chris@0 8561 }
Chris@0 8562 }
Chris@0 8563 };
Chris@0 8564 }
Chris@0 8565
Chris@0 8566 // Base inspection function for prefilters and transports
Chris@0 8567 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
Chris@0 8568
Chris@0 8569 var inspected = {},
Chris@0 8570 seekingTransport = ( structure === transports );
Chris@0 8571
Chris@0 8572 function inspect( dataType ) {
Chris@0 8573 var selected;
Chris@0 8574 inspected[ dataType ] = true;
Chris@0 8575 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
Chris@0 8576 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
Chris@0 8577 if ( typeof dataTypeOrTransport === "string" &&
Chris@0 8578 !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
Chris@0 8579
Chris@0 8580 options.dataTypes.unshift( dataTypeOrTransport );
Chris@0 8581 inspect( dataTypeOrTransport );
Chris@0 8582 return false;
Chris@0 8583 } else if ( seekingTransport ) {
Chris@0 8584 return !( selected = dataTypeOrTransport );
Chris@0 8585 }
Chris@0 8586 } );
Chris@0 8587 return selected;
Chris@0 8588 }
Chris@0 8589
Chris@0 8590 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
Chris@0 8591 }
Chris@0 8592
Chris@0 8593 // A special extend for ajax options
Chris@0 8594 // that takes "flat" options (not to be deep extended)
Chris@0 8595 // Fixes #9887
Chris@0 8596 function ajaxExtend( target, src ) {
Chris@0 8597 var key, deep,
Chris@0 8598 flatOptions = jQuery.ajaxSettings.flatOptions || {};
Chris@0 8599
Chris@0 8600 for ( key in src ) {
Chris@0 8601 if ( src[ key ] !== undefined ) {
Chris@0 8602 ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
Chris@0 8603 }
Chris@0 8604 }
Chris@0 8605 if ( deep ) {
Chris@0 8606 jQuery.extend( true, target, deep );
Chris@0 8607 }
Chris@0 8608
Chris@0 8609 return target;
Chris@0 8610 }
Chris@0 8611
Chris@0 8612 /* Handles responses to an ajax request:
Chris@0 8613 * - finds the right dataType (mediates between content-type and expected dataType)
Chris@0 8614 * - returns the corresponding response
Chris@0 8615 */
Chris@0 8616 function ajaxHandleResponses( s, jqXHR, responses ) {
Chris@0 8617
Chris@0 8618 var ct, type, finalDataType, firstDataType,
Chris@0 8619 contents = s.contents,
Chris@0 8620 dataTypes = s.dataTypes;
Chris@0 8621
Chris@0 8622 // Remove auto dataType and get content-type in the process
Chris@0 8623 while ( dataTypes[ 0 ] === "*" ) {
Chris@0 8624 dataTypes.shift();
Chris@0 8625 if ( ct === undefined ) {
Chris@0 8626 ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
Chris@0 8627 }
Chris@0 8628 }
Chris@0 8629
Chris@0 8630 // Check if we're dealing with a known content-type
Chris@0 8631 if ( ct ) {
Chris@0 8632 for ( type in contents ) {
Chris@0 8633 if ( contents[ type ] && contents[ type ].test( ct ) ) {
Chris@0 8634 dataTypes.unshift( type );
Chris@0 8635 break;
Chris@0 8636 }
Chris@0 8637 }
Chris@0 8638 }
Chris@0 8639
Chris@0 8640 // Check to see if we have a response for the expected dataType
Chris@0 8641 if ( dataTypes[ 0 ] in responses ) {
Chris@0 8642 finalDataType = dataTypes[ 0 ];
Chris@0 8643 } else {
Chris@0 8644
Chris@0 8645 // Try convertible dataTypes
Chris@0 8646 for ( type in responses ) {
Chris@0 8647 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
Chris@0 8648 finalDataType = type;
Chris@0 8649 break;
Chris@0 8650 }
Chris@0 8651 if ( !firstDataType ) {
Chris@0 8652 firstDataType = type;
Chris@0 8653 }
Chris@0 8654 }
Chris@0 8655
Chris@0 8656 // Or just use first one
Chris@0 8657 finalDataType = finalDataType || firstDataType;
Chris@0 8658 }
Chris@0 8659
Chris@0 8660 // If we found a dataType
Chris@0 8661 // We add the dataType to the list if needed
Chris@0 8662 // and return the corresponding response
Chris@0 8663 if ( finalDataType ) {
Chris@0 8664 if ( finalDataType !== dataTypes[ 0 ] ) {
Chris@0 8665 dataTypes.unshift( finalDataType );
Chris@0 8666 }
Chris@0 8667 return responses[ finalDataType ];
Chris@0 8668 }
Chris@0 8669 }
Chris@0 8670
Chris@0 8671 /* Chain conversions given the request and the original response
Chris@0 8672 * Also sets the responseXXX fields on the jqXHR instance
Chris@0 8673 */
Chris@0 8674 function ajaxConvert( s, response, jqXHR, isSuccess ) {
Chris@0 8675 var conv2, current, conv, tmp, prev,
Chris@0 8676 converters = {},
Chris@0 8677
Chris@0 8678 // Work with a copy of dataTypes in case we need to modify it for conversion
Chris@0 8679 dataTypes = s.dataTypes.slice();
Chris@0 8680
Chris@0 8681 // Create converters map with lowercased keys
Chris@0 8682 if ( dataTypes[ 1 ] ) {
Chris@0 8683 for ( conv in s.converters ) {
Chris@0 8684 converters[ conv.toLowerCase() ] = s.converters[ conv ];
Chris@0 8685 }
Chris@0 8686 }
Chris@0 8687
Chris@0 8688 current = dataTypes.shift();
Chris@0 8689
Chris@0 8690 // Convert to each sequential dataType
Chris@0 8691 while ( current ) {
Chris@0 8692
Chris@0 8693 if ( s.responseFields[ current ] ) {
Chris@0 8694 jqXHR[ s.responseFields[ current ] ] = response;
Chris@0 8695 }
Chris@0 8696
Chris@0 8697 // Apply the dataFilter if provided
Chris@0 8698 if ( !prev && isSuccess && s.dataFilter ) {
Chris@0 8699 response = s.dataFilter( response, s.dataType );
Chris@0 8700 }
Chris@0 8701
Chris@0 8702 prev = current;
Chris@0 8703 current = dataTypes.shift();
Chris@0 8704
Chris@0 8705 if ( current ) {
Chris@0 8706
Chris@0 8707 // There's only work to do if current dataType is non-auto
Chris@0 8708 if ( current === "*" ) {
Chris@0 8709
Chris@0 8710 current = prev;
Chris@0 8711
Chris@0 8712 // Convert response if prev dataType is non-auto and differs from current
Chris@0 8713 } else if ( prev !== "*" && prev !== current ) {
Chris@0 8714
Chris@0 8715 // Seek a direct converter
Chris@0 8716 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
Chris@0 8717
Chris@0 8718 // If none found, seek a pair
Chris@0 8719 if ( !conv ) {
Chris@0 8720 for ( conv2 in converters ) {
Chris@0 8721
Chris@0 8722 // If conv2 outputs current
Chris@0 8723 tmp = conv2.split( " " );
Chris@0 8724 if ( tmp[ 1 ] === current ) {
Chris@0 8725
Chris@0 8726 // If prev can be converted to accepted input
Chris@0 8727 conv = converters[ prev + " " + tmp[ 0 ] ] ||
Chris@0 8728 converters[ "* " + tmp[ 0 ] ];
Chris@0 8729 if ( conv ) {
Chris@0 8730
Chris@0 8731 // Condense equivalence converters
Chris@0 8732 if ( conv === true ) {
Chris@0 8733 conv = converters[ conv2 ];
Chris@0 8734
Chris@0 8735 // Otherwise, insert the intermediate dataType
Chris@0 8736 } else if ( converters[ conv2 ] !== true ) {
Chris@0 8737 current = tmp[ 0 ];
Chris@0 8738 dataTypes.unshift( tmp[ 1 ] );
Chris@0 8739 }
Chris@0 8740 break;
Chris@0 8741 }
Chris@0 8742 }
Chris@0 8743 }
Chris@0 8744 }
Chris@0 8745
Chris@0 8746 // Apply converter (if not an equivalence)
Chris@0 8747 if ( conv !== true ) {
Chris@0 8748
Chris@0 8749 // Unless errors are allowed to bubble, catch and return them
Chris@0 8750 if ( conv && s.throws ) {
Chris@0 8751 response = conv( response );
Chris@0 8752 } else {
Chris@0 8753 try {
Chris@0 8754 response = conv( response );
Chris@0 8755 } catch ( e ) {
Chris@0 8756 return {
Chris@0 8757 state: "parsererror",
Chris@0 8758 error: conv ? e : "No conversion from " + prev + " to " + current
Chris@0 8759 };
Chris@0 8760 }
Chris@0 8761 }
Chris@0 8762 }
Chris@0 8763 }
Chris@0 8764 }
Chris@0 8765 }
Chris@0 8766
Chris@0 8767 return { state: "success", data: response };
Chris@0 8768 }
Chris@0 8769
Chris@0 8770 jQuery.extend( {
Chris@0 8771
Chris@0 8772 // Counter for holding the number of active queries
Chris@0 8773 active: 0,
Chris@0 8774
Chris@0 8775 // Last-Modified header cache for next request
Chris@0 8776 lastModified: {},
Chris@0 8777 etag: {},
Chris@0 8778
Chris@0 8779 ajaxSettings: {
Chris@0 8780 url: location.href,
Chris@0 8781 type: "GET",
Chris@0 8782 isLocal: rlocalProtocol.test( location.protocol ),
Chris@0 8783 global: true,
Chris@0 8784 processData: true,
Chris@0 8785 async: true,
Chris@0 8786 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
Chris@0 8787
Chris@0 8788 /*
Chris@0 8789 timeout: 0,
Chris@0 8790 data: null,
Chris@0 8791 dataType: null,
Chris@0 8792 username: null,
Chris@0 8793 password: null,
Chris@0 8794 cache: null,
Chris@0 8795 throws: false,
Chris@0 8796 traditional: false,
Chris@0 8797 headers: {},
Chris@0 8798 */
Chris@0 8799
Chris@0 8800 accepts: {
Chris@0 8801 "*": allTypes,
Chris@0 8802 text: "text/plain",
Chris@0 8803 html: "text/html",
Chris@0 8804 xml: "application/xml, text/xml",
Chris@0 8805 json: "application/json, text/javascript"
Chris@0 8806 },
Chris@0 8807
Chris@0 8808 contents: {
Chris@0 8809 xml: /\bxml\b/,
Chris@0 8810 html: /\bhtml/,
Chris@0 8811 json: /\bjson\b/
Chris@0 8812 },
Chris@0 8813
Chris@0 8814 responseFields: {
Chris@0 8815 xml: "responseXML",
Chris@0 8816 text: "responseText",
Chris@0 8817 json: "responseJSON"
Chris@0 8818 },
Chris@0 8819
Chris@0 8820 // Data converters
Chris@0 8821 // Keys separate source (or catchall "*") and destination types with a single space
Chris@0 8822 converters: {
Chris@0 8823
Chris@0 8824 // Convert anything to text
Chris@0 8825 "* text": String,
Chris@0 8826
Chris@0 8827 // Text to html (true = no transformation)
Chris@0 8828 "text html": true,
Chris@0 8829
Chris@0 8830 // Evaluate text as a json expression
Chris@0 8831 "text json": JSON.parse,
Chris@0 8832
Chris@0 8833 // Parse text as xml
Chris@0 8834 "text xml": jQuery.parseXML
Chris@0 8835 },
Chris@0 8836
Chris@0 8837 // For options that shouldn't be deep extended:
Chris@0 8838 // you can add your own custom options here if
Chris@0 8839 // and when you create one that shouldn't be
Chris@0 8840 // deep extended (see ajaxExtend)
Chris@0 8841 flatOptions: {
Chris@0 8842 url: true,
Chris@0 8843 context: true
Chris@0 8844 }
Chris@0 8845 },
Chris@0 8846
Chris@0 8847 // Creates a full fledged settings object into target
Chris@0 8848 // with both ajaxSettings and settings fields.
Chris@0 8849 // If target is omitted, writes into ajaxSettings.
Chris@0 8850 ajaxSetup: function( target, settings ) {
Chris@0 8851 return settings ?
Chris@0 8852
Chris@0 8853 // Building a settings object
Chris@0 8854 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
Chris@0 8855
Chris@0 8856 // Extending ajaxSettings
Chris@0 8857 ajaxExtend( jQuery.ajaxSettings, target );
Chris@0 8858 },
Chris@0 8859
Chris@0 8860 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
Chris@0 8861 ajaxTransport: addToPrefiltersOrTransports( transports ),
Chris@0 8862
Chris@0 8863 // Main method
Chris@0 8864 ajax: function( url, options ) {
Chris@0 8865
Chris@0 8866 // If url is an object, simulate pre-1.5 signature
Chris@0 8867 if ( typeof url === "object" ) {
Chris@0 8868 options = url;
Chris@0 8869 url = undefined;
Chris@0 8870 }
Chris@0 8871
Chris@0 8872 // Force options to be an object
Chris@0 8873 options = options || {};
Chris@0 8874
Chris@0 8875 var transport,
Chris@0 8876
Chris@0 8877 // URL without anti-cache param
Chris@0 8878 cacheURL,
Chris@0 8879
Chris@0 8880 // Response headers
Chris@0 8881 responseHeadersString,
Chris@0 8882 responseHeaders,
Chris@0 8883
Chris@0 8884 // timeout handle
Chris@0 8885 timeoutTimer,
Chris@0 8886
Chris@0 8887 // Url cleanup var
Chris@0 8888 urlAnchor,
Chris@0 8889
Chris@0 8890 // Request state (becomes false upon send and true upon completion)
Chris@0 8891 completed,
Chris@0 8892
Chris@0 8893 // To know if global events are to be dispatched
Chris@0 8894 fireGlobals,
Chris@0 8895
Chris@0 8896 // Loop variable
Chris@0 8897 i,
Chris@0 8898
Chris@0 8899 // uncached part of the url
Chris@0 8900 uncached,
Chris@0 8901
Chris@0 8902 // Create the final options object
Chris@0 8903 s = jQuery.ajaxSetup( {}, options ),
Chris@0 8904
Chris@0 8905 // Callbacks context
Chris@0 8906 callbackContext = s.context || s,
Chris@0 8907
Chris@0 8908 // Context for global events is callbackContext if it is a DOM node or jQuery collection
Chris@0 8909 globalEventContext = s.context &&
Chris@0 8910 ( callbackContext.nodeType || callbackContext.jquery ) ?
Chris@0 8911 jQuery( callbackContext ) :
Chris@0 8912 jQuery.event,
Chris@0 8913
Chris@0 8914 // Deferreds
Chris@0 8915 deferred = jQuery.Deferred(),
Chris@0 8916 completeDeferred = jQuery.Callbacks( "once memory" ),
Chris@0 8917
Chris@0 8918 // Status-dependent callbacks
Chris@0 8919 statusCode = s.statusCode || {},
Chris@0 8920
Chris@0 8921 // Headers (they are sent all at once)
Chris@0 8922 requestHeaders = {},
Chris@0 8923 requestHeadersNames = {},
Chris@0 8924
Chris@0 8925 // Default abort message
Chris@0 8926 strAbort = "canceled",
Chris@0 8927
Chris@0 8928 // Fake xhr
Chris@0 8929 jqXHR = {
Chris@0 8930 readyState: 0,
Chris@0 8931
Chris@0 8932 // Builds headers hashtable if needed
Chris@0 8933 getResponseHeader: function( key ) {
Chris@0 8934 var match;
Chris@0 8935 if ( completed ) {
Chris@0 8936 if ( !responseHeaders ) {
Chris@0 8937 responseHeaders = {};
Chris@0 8938 while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
Chris@0 8939 responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
Chris@0 8940 }
Chris@0 8941 }
Chris@0 8942 match = responseHeaders[ key.toLowerCase() ];
Chris@0 8943 }
Chris@0 8944 return match == null ? null : match;
Chris@0 8945 },
Chris@0 8946
Chris@0 8947 // Raw string
Chris@0 8948 getAllResponseHeaders: function() {
Chris@0 8949 return completed ? responseHeadersString : null;
Chris@0 8950 },
Chris@0 8951
Chris@0 8952 // Caches the header
Chris@0 8953 setRequestHeader: function( name, value ) {
Chris@0 8954 if ( completed == null ) {
Chris@0 8955 name = requestHeadersNames[ name.toLowerCase() ] =
Chris@0 8956 requestHeadersNames[ name.toLowerCase() ] || name;
Chris@0 8957 requestHeaders[ name ] = value;
Chris@0 8958 }
Chris@0 8959 return this;
Chris@0 8960 },
Chris@0 8961
Chris@0 8962 // Overrides response content-type header
Chris@0 8963 overrideMimeType: function( type ) {
Chris@0 8964 if ( completed == null ) {
Chris@0 8965 s.mimeType = type;
Chris@0 8966 }
Chris@0 8967 return this;
Chris@0 8968 },
Chris@0 8969
Chris@0 8970 // Status-dependent callbacks
Chris@0 8971 statusCode: function( map ) {
Chris@0 8972 var code;
Chris@0 8973 if ( map ) {
Chris@0 8974 if ( completed ) {
Chris@0 8975
Chris@0 8976 // Execute the appropriate callbacks
Chris@0 8977 jqXHR.always( map[ jqXHR.status ] );
Chris@0 8978 } else {
Chris@0 8979
Chris@0 8980 // Lazy-add the new callbacks in a way that preserves old ones
Chris@0 8981 for ( code in map ) {
Chris@0 8982 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
Chris@0 8983 }
Chris@0 8984 }
Chris@0 8985 }
Chris@0 8986 return this;
Chris@0 8987 },
Chris@0 8988
Chris@0 8989 // Cancel the request
Chris@0 8990 abort: function( statusText ) {
Chris@0 8991 var finalText = statusText || strAbort;
Chris@0 8992 if ( transport ) {
Chris@0 8993 transport.abort( finalText );
Chris@0 8994 }
Chris@0 8995 done( 0, finalText );
Chris@0 8996 return this;
Chris@0 8997 }
Chris@0 8998 };
Chris@0 8999
Chris@0 9000 // Attach deferreds
Chris@0 9001 deferred.promise( jqXHR );
Chris@0 9002
Chris@0 9003 // Add protocol if not provided (prefilters might expect it)
Chris@0 9004 // Handle falsy url in the settings object (#10093: consistency with old signature)
Chris@0 9005 // We also use the url parameter if available
Chris@0 9006 s.url = ( ( url || s.url || location.href ) + "" )
Chris@0 9007 .replace( rprotocol, location.protocol + "//" );
Chris@0 9008
Chris@0 9009 // Alias method option to type as per ticket #12004
Chris@0 9010 s.type = options.method || options.type || s.method || s.type;
Chris@0 9011
Chris@0 9012 // Extract dataTypes list
Chris@0 9013 s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ];
Chris@0 9014
Chris@0 9015 // A cross-domain request is in order when the origin doesn't match the current origin.
Chris@0 9016 if ( s.crossDomain == null ) {
Chris@0 9017 urlAnchor = document.createElement( "a" );
Chris@0 9018
Chris@0 9019 // Support: IE <=8 - 11, Edge 12 - 13
Chris@0 9020 // IE throws exception on accessing the href property if url is malformed,
Chris@0 9021 // e.g. http://example.com:80x/
Chris@0 9022 try {
Chris@0 9023 urlAnchor.href = s.url;
Chris@0 9024
Chris@0 9025 // Support: IE <=8 - 11 only
Chris@0 9026 // Anchor's host property isn't correctly set when s.url is relative
Chris@0 9027 urlAnchor.href = urlAnchor.href;
Chris@0 9028 s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
Chris@0 9029 urlAnchor.protocol + "//" + urlAnchor.host;
Chris@0 9030 } catch ( e ) {
Chris@0 9031
Chris@0 9032 // If there is an error parsing the URL, assume it is crossDomain,
Chris@0 9033 // it can be rejected by the transport if it is invalid
Chris@0 9034 s.crossDomain = true;
Chris@0 9035 }
Chris@0 9036 }
Chris@0 9037
Chris@0 9038 // Convert data if not already a string
Chris@0 9039 if ( s.data && s.processData && typeof s.data !== "string" ) {
Chris@0 9040 s.data = jQuery.param( s.data, s.traditional );
Chris@0 9041 }
Chris@0 9042
Chris@0 9043 // Apply prefilters
Chris@0 9044 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
Chris@0 9045
Chris@0 9046 // If request was aborted inside a prefilter, stop there
Chris@0 9047 if ( completed ) {
Chris@0 9048 return jqXHR;
Chris@0 9049 }
Chris@0 9050
Chris@0 9051 // We can fire global events as of now if asked to
Chris@0 9052 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
Chris@0 9053 fireGlobals = jQuery.event && s.global;
Chris@0 9054
Chris@0 9055 // Watch for a new set of requests
Chris@0 9056 if ( fireGlobals && jQuery.active++ === 0 ) {
Chris@0 9057 jQuery.event.trigger( "ajaxStart" );
Chris@0 9058 }
Chris@0 9059
Chris@0 9060 // Uppercase the type
Chris@0 9061 s.type = s.type.toUpperCase();
Chris@0 9062
Chris@0 9063 // Determine if request has content
Chris@0 9064 s.hasContent = !rnoContent.test( s.type );
Chris@0 9065
Chris@0 9066 // Save the URL in case we're toying with the If-Modified-Since
Chris@0 9067 // and/or If-None-Match header later on
Chris@0 9068 // Remove hash to simplify url manipulation
Chris@0 9069 cacheURL = s.url.replace( rhash, "" );
Chris@0 9070
Chris@0 9071 // More options handling for requests with no content
Chris@0 9072 if ( !s.hasContent ) {
Chris@0 9073
Chris@0 9074 // Remember the hash so we can put it back
Chris@0 9075 uncached = s.url.slice( cacheURL.length );
Chris@0 9076
Chris@0 9077 // If data is available, append data to url
Chris@0 9078 if ( s.data ) {
Chris@0 9079 cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;
Chris@0 9080
Chris@0 9081 // #9682: remove data so that it's not used in an eventual retry
Chris@0 9082 delete s.data;
Chris@0 9083 }
Chris@0 9084
Chris@0 9085 // Add or update anti-cache param if needed
Chris@0 9086 if ( s.cache === false ) {
Chris@0 9087 cacheURL = cacheURL.replace( rantiCache, "$1" );
Chris@0 9088 uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce++ ) + uncached;
Chris@0 9089 }
Chris@0 9090
Chris@0 9091 // Put hash and anti-cache on the URL that will be requested (gh-1732)
Chris@0 9092 s.url = cacheURL + uncached;
Chris@0 9093
Chris@0 9094 // Change '%20' to '+' if this is encoded form body content (gh-2658)
Chris@0 9095 } else if ( s.data && s.processData &&
Chris@0 9096 ( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) {
Chris@0 9097 s.data = s.data.replace( r20, "+" );
Chris@0 9098 }
Chris@0 9099
Chris@0 9100 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
Chris@0 9101 if ( s.ifModified ) {
Chris@0 9102 if ( jQuery.lastModified[ cacheURL ] ) {
Chris@0 9103 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
Chris@0 9104 }
Chris@0 9105 if ( jQuery.etag[ cacheURL ] ) {
Chris@0 9106 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
Chris@0 9107 }
Chris@0 9108 }
Chris@0 9109
Chris@0 9110 // Set the correct header, if data is being sent
Chris@0 9111 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
Chris@0 9112 jqXHR.setRequestHeader( "Content-Type", s.contentType );
Chris@0 9113 }
Chris@0 9114
Chris@0 9115 // Set the Accepts header for the server, depending on the dataType
Chris@0 9116 jqXHR.setRequestHeader(
Chris@0 9117 "Accept",
Chris@0 9118 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
Chris@0 9119 s.accepts[ s.dataTypes[ 0 ] ] +
Chris@0 9120 ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
Chris@0 9121 s.accepts[ "*" ]
Chris@0 9122 );
Chris@0 9123
Chris@0 9124 // Check for headers option
Chris@0 9125 for ( i in s.headers ) {
Chris@0 9126 jqXHR.setRequestHeader( i, s.headers[ i ] );
Chris@0 9127 }
Chris@0 9128
Chris@0 9129 // Allow custom headers/mimetypes and early abort
Chris@0 9130 if ( s.beforeSend &&
Chris@0 9131 ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) {
Chris@0 9132
Chris@0 9133 // Abort if not done already and return
Chris@0 9134 return jqXHR.abort();
Chris@0 9135 }
Chris@0 9136
Chris@0 9137 // Aborting is no longer a cancellation
Chris@0 9138 strAbort = "abort";
Chris@0 9139
Chris@0 9140 // Install callbacks on deferreds
Chris@0 9141 completeDeferred.add( s.complete );
Chris@0 9142 jqXHR.done( s.success );
Chris@0 9143 jqXHR.fail( s.error );
Chris@0 9144
Chris@0 9145 // Get transport
Chris@0 9146 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
Chris@0 9147
Chris@0 9148 // If no transport, we auto-abort
Chris@0 9149 if ( !transport ) {
Chris@0 9150 done( -1, "No Transport" );
Chris@0 9151 } else {
Chris@0 9152 jqXHR.readyState = 1;
Chris@0 9153
Chris@0 9154 // Send global event
Chris@0 9155 if ( fireGlobals ) {
Chris@0 9156 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
Chris@0 9157 }
Chris@0 9158
Chris@0 9159 // If request was aborted inside ajaxSend, stop there
Chris@0 9160 if ( completed ) {
Chris@0 9161 return jqXHR;
Chris@0 9162 }
Chris@0 9163
Chris@0 9164 // Timeout
Chris@0 9165 if ( s.async && s.timeout > 0 ) {
Chris@0 9166 timeoutTimer = window.setTimeout( function() {
Chris@0 9167 jqXHR.abort( "timeout" );
Chris@0 9168 }, s.timeout );
Chris@0 9169 }
Chris@0 9170
Chris@0 9171 try {
Chris@0 9172 completed = false;
Chris@0 9173 transport.send( requestHeaders, done );
Chris@0 9174 } catch ( e ) {
Chris@0 9175
Chris@0 9176 // Rethrow post-completion exceptions
Chris@0 9177 if ( completed ) {
Chris@0 9178 throw e;
Chris@0 9179 }
Chris@0 9180
Chris@0 9181 // Propagate others as results
Chris@0 9182 done( -1, e );
Chris@0 9183 }
Chris@0 9184 }
Chris@0 9185
Chris@0 9186 // Callback for when everything is done
Chris@0 9187 function done( status, nativeStatusText, responses, headers ) {
Chris@0 9188 var isSuccess, success, error, response, modified,
Chris@0 9189 statusText = nativeStatusText;
Chris@0 9190
Chris@0 9191 // Ignore repeat invocations
Chris@0 9192 if ( completed ) {
Chris@0 9193 return;
Chris@0 9194 }
Chris@0 9195
Chris@0 9196 completed = true;
Chris@0 9197
Chris@0 9198 // Clear timeout if it exists
Chris@0 9199 if ( timeoutTimer ) {
Chris@0 9200 window.clearTimeout( timeoutTimer );
Chris@0 9201 }
Chris@0 9202
Chris@0 9203 // Dereference transport for early garbage collection
Chris@0 9204 // (no matter how long the jqXHR object will be used)
Chris@0 9205 transport = undefined;
Chris@0 9206
Chris@0 9207 // Cache response headers
Chris@0 9208 responseHeadersString = headers || "";
Chris@0 9209
Chris@0 9210 // Set readyState
Chris@0 9211 jqXHR.readyState = status > 0 ? 4 : 0;
Chris@0 9212
Chris@0 9213 // Determine if successful
Chris@0 9214 isSuccess = status >= 200 && status < 300 || status === 304;
Chris@0 9215
Chris@0 9216 // Get response data
Chris@0 9217 if ( responses ) {
Chris@0 9218 response = ajaxHandleResponses( s, jqXHR, responses );
Chris@0 9219 }
Chris@0 9220
Chris@0 9221 // Convert no matter what (that way responseXXX fields are always set)
Chris@0 9222 response = ajaxConvert( s, response, jqXHR, isSuccess );
Chris@0 9223
Chris@0 9224 // If successful, handle type chaining
Chris@0 9225 if ( isSuccess ) {
Chris@0 9226
Chris@0 9227 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
Chris@0 9228 if ( s.ifModified ) {
Chris@0 9229 modified = jqXHR.getResponseHeader( "Last-Modified" );
Chris@0 9230 if ( modified ) {
Chris@0 9231 jQuery.lastModified[ cacheURL ] = modified;
Chris@0 9232 }
Chris@0 9233 modified = jqXHR.getResponseHeader( "etag" );
Chris@0 9234 if ( modified ) {
Chris@0 9235 jQuery.etag[ cacheURL ] = modified;
Chris@0 9236 }
Chris@0 9237 }
Chris@0 9238
Chris@0 9239 // if no content
Chris@0 9240 if ( status === 204 || s.type === "HEAD" ) {
Chris@0 9241 statusText = "nocontent";
Chris@0 9242
Chris@0 9243 // if not modified
Chris@0 9244 } else if ( status === 304 ) {
Chris@0 9245 statusText = "notmodified";
Chris@0 9246
Chris@0 9247 // If we have data, let's convert it
Chris@0 9248 } else {
Chris@0 9249 statusText = response.state;
Chris@0 9250 success = response.data;
Chris@0 9251 error = response.error;
Chris@0 9252 isSuccess = !error;
Chris@0 9253 }
Chris@0 9254 } else {
Chris@0 9255
Chris@0 9256 // Extract error from statusText and normalize for non-aborts
Chris@0 9257 error = statusText;
Chris@0 9258 if ( status || !statusText ) {
Chris@0 9259 statusText = "error";
Chris@0 9260 if ( status < 0 ) {
Chris@0 9261 status = 0;
Chris@0 9262 }
Chris@0 9263 }
Chris@0 9264 }
Chris@0 9265
Chris@0 9266 // Set data for the fake xhr object
Chris@0 9267 jqXHR.status = status;
Chris@0 9268 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
Chris@0 9269
Chris@0 9270 // Success/Error
Chris@0 9271 if ( isSuccess ) {
Chris@0 9272 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
Chris@0 9273 } else {
Chris@0 9274 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
Chris@0 9275 }
Chris@0 9276
Chris@0 9277 // Status-dependent callbacks
Chris@0 9278 jqXHR.statusCode( statusCode );
Chris@0 9279 statusCode = undefined;
Chris@0 9280
Chris@0 9281 if ( fireGlobals ) {
Chris@0 9282 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
Chris@0 9283 [ jqXHR, s, isSuccess ? success : error ] );
Chris@0 9284 }
Chris@0 9285
Chris@0 9286 // Complete
Chris@0 9287 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
Chris@0 9288
Chris@0 9289 if ( fireGlobals ) {
Chris@0 9290 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
Chris@0 9291
Chris@0 9292 // Handle the global AJAX counter
Chris@0 9293 if ( !( --jQuery.active ) ) {
Chris@0 9294 jQuery.event.trigger( "ajaxStop" );
Chris@0 9295 }
Chris@0 9296 }
Chris@0 9297 }
Chris@0 9298
Chris@0 9299 return jqXHR;
Chris@0 9300 },
Chris@0 9301
Chris@0 9302 getJSON: function( url, data, callback ) {
Chris@0 9303 return jQuery.get( url, data, callback, "json" );
Chris@0 9304 },
Chris@0 9305
Chris@0 9306 getScript: function( url, callback ) {
Chris@0 9307 return jQuery.get( url, undefined, callback, "script" );
Chris@0 9308 }
Chris@0 9309 } );
Chris@0 9310
Chris@0 9311 jQuery.each( [ "get", "post" ], function( i, method ) {
Chris@0 9312 jQuery[ method ] = function( url, data, callback, type ) {
Chris@0 9313
Chris@0 9314 // Shift arguments if data argument was omitted
Chris@0 9315 if ( jQuery.isFunction( data ) ) {
Chris@0 9316 type = type || callback;
Chris@0 9317 callback = data;
Chris@0 9318 data = undefined;
Chris@0 9319 }
Chris@0 9320
Chris@0 9321 // The url can be an options object (which then must have .url)
Chris@0 9322 return jQuery.ajax( jQuery.extend( {
Chris@0 9323 url: url,
Chris@0 9324 type: method,
Chris@0 9325 dataType: type,
Chris@0 9326 data: data,
Chris@0 9327 success: callback
Chris@0 9328 }, jQuery.isPlainObject( url ) && url ) );
Chris@0 9329 };
Chris@0 9330 } );
Chris@0 9331
Chris@0 9332
Chris@0 9333 jQuery._evalUrl = function( url ) {
Chris@0 9334 return jQuery.ajax( {
Chris@0 9335 url: url,
Chris@0 9336
Chris@0 9337 // Make this explicit, since user can override this through ajaxSetup (#11264)
Chris@0 9338 type: "GET",
Chris@0 9339 dataType: "script",
Chris@0 9340 cache: true,
Chris@0 9341 async: false,
Chris@0 9342 global: false,
Chris@0 9343 "throws": true
Chris@0 9344 } );
Chris@0 9345 };
Chris@0 9346
Chris@0 9347
Chris@0 9348 jQuery.fn.extend( {
Chris@0 9349 wrapAll: function( html ) {
Chris@0 9350 var wrap;
Chris@0 9351
Chris@0 9352 if ( this[ 0 ] ) {
Chris@0 9353 if ( jQuery.isFunction( html ) ) {
Chris@0 9354 html = html.call( this[ 0 ] );
Chris@0 9355 }
Chris@0 9356
Chris@0 9357 // The elements to wrap the target around
Chris@0 9358 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
Chris@0 9359
Chris@0 9360 if ( this[ 0 ].parentNode ) {
Chris@0 9361 wrap.insertBefore( this[ 0 ] );
Chris@0 9362 }
Chris@0 9363
Chris@0 9364 wrap.map( function() {
Chris@0 9365 var elem = this;
Chris@0 9366
Chris@0 9367 while ( elem.firstElementChild ) {
Chris@0 9368 elem = elem.firstElementChild;
Chris@0 9369 }
Chris@0 9370
Chris@0 9371 return elem;
Chris@0 9372 } ).append( this );
Chris@0 9373 }
Chris@0 9374
Chris@0 9375 return this;
Chris@0 9376 },
Chris@0 9377
Chris@0 9378 wrapInner: function( html ) {
Chris@0 9379 if ( jQuery.isFunction( html ) ) {
Chris@0 9380 return this.each( function( i ) {
Chris@0 9381 jQuery( this ).wrapInner( html.call( this, i ) );
Chris@0 9382 } );
Chris@0 9383 }
Chris@0 9384
Chris@0 9385 return this.each( function() {
Chris@0 9386 var self = jQuery( this ),
Chris@0 9387 contents = self.contents();
Chris@0 9388
Chris@0 9389 if ( contents.length ) {
Chris@0 9390 contents.wrapAll( html );
Chris@0 9391
Chris@0 9392 } else {
Chris@0 9393 self.append( html );
Chris@0 9394 }
Chris@0 9395 } );
Chris@0 9396 },
Chris@0 9397
Chris@0 9398 wrap: function( html ) {
Chris@0 9399 var isFunction = jQuery.isFunction( html );
Chris@0 9400
Chris@0 9401 return this.each( function( i ) {
Chris@0 9402 jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
Chris@0 9403 } );
Chris@0 9404 },
Chris@0 9405
Chris@0 9406 unwrap: function( selector ) {
Chris@0 9407 this.parent( selector ).not( "body" ).each( function() {
Chris@0 9408 jQuery( this ).replaceWith( this.childNodes );
Chris@0 9409 } );
Chris@0 9410 return this;
Chris@0 9411 }
Chris@0 9412 } );
Chris@0 9413
Chris@0 9414
Chris@0 9415 jQuery.expr.pseudos.hidden = function( elem ) {
Chris@0 9416 return !jQuery.expr.pseudos.visible( elem );
Chris@0 9417 };
Chris@0 9418 jQuery.expr.pseudos.visible = function( elem ) {
Chris@0 9419 return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );
Chris@0 9420 };
Chris@0 9421
Chris@0 9422
Chris@0 9423
Chris@0 9424
Chris@0 9425 jQuery.ajaxSettings.xhr = function() {
Chris@0 9426 try {
Chris@0 9427 return new window.XMLHttpRequest();
Chris@0 9428 } catch ( e ) {}
Chris@0 9429 };
Chris@0 9430
Chris@0 9431 var xhrSuccessStatus = {
Chris@0 9432
Chris@0 9433 // File protocol always yields status code 0, assume 200
Chris@0 9434 0: 200,
Chris@0 9435
Chris@0 9436 // Support: IE <=9 only
Chris@0 9437 // #1450: sometimes IE returns 1223 when it should be 204
Chris@0 9438 1223: 204
Chris@0 9439 },
Chris@0 9440 xhrSupported = jQuery.ajaxSettings.xhr();
Chris@0 9441
Chris@0 9442 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
Chris@0 9443 support.ajax = xhrSupported = !!xhrSupported;
Chris@0 9444
Chris@0 9445 jQuery.ajaxTransport( function( options ) {
Chris@0 9446 var callback, errorCallback;
Chris@0 9447
Chris@0 9448 // Cross domain only allowed if supported through XMLHttpRequest
Chris@0 9449 if ( support.cors || xhrSupported && !options.crossDomain ) {
Chris@0 9450 return {
Chris@0 9451 send: function( headers, complete ) {
Chris@0 9452 var i,
Chris@0 9453 xhr = options.xhr();
Chris@0 9454
Chris@0 9455 xhr.open(
Chris@0 9456 options.type,
Chris@0 9457 options.url,
Chris@0 9458 options.async,
Chris@0 9459 options.username,
Chris@0 9460 options.password
Chris@0 9461 );
Chris@0 9462
Chris@0 9463 // Apply custom fields if provided
Chris@0 9464 if ( options.xhrFields ) {
Chris@0 9465 for ( i in options.xhrFields ) {
Chris@0 9466 xhr[ i ] = options.xhrFields[ i ];
Chris@0 9467 }
Chris@0 9468 }
Chris@0 9469
Chris@0 9470 // Override mime type if needed
Chris@0 9471 if ( options.mimeType && xhr.overrideMimeType ) {
Chris@0 9472 xhr.overrideMimeType( options.mimeType );
Chris@0 9473 }
Chris@0 9474
Chris@0 9475 // X-Requested-With header
Chris@0 9476 // For cross-domain requests, seeing as conditions for a preflight are
Chris@0 9477 // akin to a jigsaw puzzle, we simply never set it to be sure.
Chris@0 9478 // (it can always be set on a per-request basis or even using ajaxSetup)
Chris@0 9479 // For same-domain requests, won't change header if already provided.
Chris@0 9480 if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) {
Chris@0 9481 headers[ "X-Requested-With" ] = "XMLHttpRequest";
Chris@0 9482 }
Chris@0 9483
Chris@0 9484 // Set headers
Chris@0 9485 for ( i in headers ) {
Chris@0 9486 xhr.setRequestHeader( i, headers[ i ] );
Chris@0 9487 }
Chris@0 9488
Chris@0 9489 // Callback
Chris@0 9490 callback = function( type ) {
Chris@0 9491 return function() {
Chris@0 9492 if ( callback ) {
Chris@0 9493 callback = errorCallback = xhr.onload =
Chris@0 9494 xhr.onerror = xhr.onabort = xhr.onreadystatechange = null;
Chris@0 9495
Chris@0 9496 if ( type === "abort" ) {
Chris@0 9497 xhr.abort();
Chris@0 9498 } else if ( type === "error" ) {
Chris@0 9499
Chris@0 9500 // Support: IE <=9 only
Chris@0 9501 // On a manual native abort, IE9 throws
Chris@0 9502 // errors on any property access that is not readyState
Chris@0 9503 if ( typeof xhr.status !== "number" ) {
Chris@0 9504 complete( 0, "error" );
Chris@0 9505 } else {
Chris@0 9506 complete(
Chris@0 9507
Chris@0 9508 // File: protocol always yields status 0; see #8605, #14207
Chris@0 9509 xhr.status,
Chris@0 9510 xhr.statusText
Chris@0 9511 );
Chris@0 9512 }
Chris@0 9513 } else {
Chris@0 9514 complete(
Chris@0 9515 xhrSuccessStatus[ xhr.status ] || xhr.status,
Chris@0 9516 xhr.statusText,
Chris@0 9517
Chris@0 9518 // Support: IE <=9 only
Chris@0 9519 // IE9 has no XHR2 but throws on binary (trac-11426)
Chris@0 9520 // For XHR2 non-text, let the caller handle it (gh-2498)
Chris@0 9521 ( xhr.responseType || "text" ) !== "text" ||
Chris@0 9522 typeof xhr.responseText !== "string" ?
Chris@0 9523 { binary: xhr.response } :
Chris@0 9524 { text: xhr.responseText },
Chris@0 9525 xhr.getAllResponseHeaders()
Chris@0 9526 );
Chris@0 9527 }
Chris@0 9528 }
Chris@0 9529 };
Chris@0 9530 };
Chris@0 9531
Chris@0 9532 // Listen to events
Chris@0 9533 xhr.onload = callback();
Chris@0 9534 errorCallback = xhr.onerror = callback( "error" );
Chris@0 9535
Chris@0 9536 // Support: IE 9 only
Chris@0 9537 // Use onreadystatechange to replace onabort
Chris@0 9538 // to handle uncaught aborts
Chris@0 9539 if ( xhr.onabort !== undefined ) {
Chris@0 9540 xhr.onabort = errorCallback;
Chris@0 9541 } else {
Chris@0 9542 xhr.onreadystatechange = function() {
Chris@0 9543
Chris@0 9544 // Check readyState before timeout as it changes
Chris@0 9545 if ( xhr.readyState === 4 ) {
Chris@0 9546
Chris@0 9547 // Allow onerror to be called first,
Chris@0 9548 // but that will not handle a native abort
Chris@0 9549 // Also, save errorCallback to a variable
Chris@0 9550 // as xhr.onerror cannot be accessed
Chris@0 9551 window.setTimeout( function() {
Chris@0 9552 if ( callback ) {
Chris@0 9553 errorCallback();
Chris@0 9554 }
Chris@0 9555 } );
Chris@0 9556 }
Chris@0 9557 };
Chris@0 9558 }
Chris@0 9559
Chris@0 9560 // Create the abort callback
Chris@0 9561 callback = callback( "abort" );
Chris@0 9562
Chris@0 9563 try {
Chris@0 9564
Chris@0 9565 // Do send the request (this may raise an exception)
Chris@0 9566 xhr.send( options.hasContent && options.data || null );
Chris@0 9567 } catch ( e ) {
Chris@0 9568
Chris@0 9569 // #14683: Only rethrow if this hasn't been notified as an error yet
Chris@0 9570 if ( callback ) {
Chris@0 9571 throw e;
Chris@0 9572 }
Chris@0 9573 }
Chris@0 9574 },
Chris@0 9575
Chris@0 9576 abort: function() {
Chris@0 9577 if ( callback ) {
Chris@0 9578 callback();
Chris@0 9579 }
Chris@0 9580 }
Chris@0 9581 };
Chris@0 9582 }
Chris@0 9583 } );
Chris@0 9584
Chris@0 9585
Chris@0 9586
Chris@0 9587
Chris@0 9588 // Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432)
Chris@0 9589 jQuery.ajaxPrefilter( function( s ) {
Chris@0 9590 if ( s.crossDomain ) {
Chris@0 9591 s.contents.script = false;
Chris@0 9592 }
Chris@0 9593 } );
Chris@0 9594
Chris@0 9595 // Install script dataType
Chris@0 9596 jQuery.ajaxSetup( {
Chris@0 9597 accepts: {
Chris@0 9598 script: "text/javascript, application/javascript, " +
Chris@0 9599 "application/ecmascript, application/x-ecmascript"
Chris@0 9600 },
Chris@0 9601 contents: {
Chris@0 9602 script: /\b(?:java|ecma)script\b/
Chris@0 9603 },
Chris@0 9604 converters: {
Chris@0 9605 "text script": function( text ) {
Chris@0 9606 jQuery.globalEval( text );
Chris@0 9607 return text;
Chris@0 9608 }
Chris@0 9609 }
Chris@0 9610 } );
Chris@0 9611
Chris@0 9612 // Handle cache's special case and crossDomain
Chris@0 9613 jQuery.ajaxPrefilter( "script", function( s ) {
Chris@0 9614 if ( s.cache === undefined ) {
Chris@0 9615 s.cache = false;
Chris@0 9616 }
Chris@0 9617 if ( s.crossDomain ) {
Chris@0 9618 s.type = "GET";
Chris@0 9619 }
Chris@0 9620 } );
Chris@0 9621
Chris@0 9622 // Bind script tag hack transport
Chris@0 9623 jQuery.ajaxTransport( "script", function( s ) {
Chris@0 9624
Chris@0 9625 // This transport only deals with cross domain requests
Chris@0 9626 if ( s.crossDomain ) {
Chris@0 9627 var script, callback;
Chris@0 9628 return {
Chris@0 9629 send: function( _, complete ) {
Chris@0 9630 script = jQuery( "<script>" ).prop( {
Chris@0 9631 charset: s.scriptCharset,
Chris@0 9632 src: s.url
Chris@0 9633 } ).on(
Chris@0 9634 "load error",
Chris@0 9635 callback = function( evt ) {
Chris@0 9636 script.remove();
Chris@0 9637 callback = null;
Chris@0 9638 if ( evt ) {
Chris@0 9639 complete( evt.type === "error" ? 404 : 200, evt.type );
Chris@0 9640 }
Chris@0 9641 }
Chris@0 9642 );
Chris@0 9643
Chris@0 9644 // Use native DOM manipulation to avoid our domManip AJAX trickery
Chris@0 9645 document.head.appendChild( script[ 0 ] );
Chris@0 9646 },
Chris@0 9647 abort: function() {
Chris@0 9648 if ( callback ) {
Chris@0 9649 callback();
Chris@0 9650 }
Chris@0 9651 }
Chris@0 9652 };
Chris@0 9653 }
Chris@0 9654 } );
Chris@0 9655
Chris@0 9656
Chris@0 9657
Chris@0 9658
Chris@0 9659 var oldCallbacks = [],
Chris@0 9660 rjsonp = /(=)\?(?=&|$)|\?\?/;
Chris@0 9661
Chris@0 9662 // Default jsonp settings
Chris@0 9663 jQuery.ajaxSetup( {
Chris@0 9664 jsonp: "callback",
Chris@0 9665 jsonpCallback: function() {
Chris@0 9666 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
Chris@0 9667 this[ callback ] = true;
Chris@0 9668 return callback;
Chris@0 9669 }
Chris@0 9670 } );
Chris@0 9671
Chris@0 9672 // Detect, normalize options and install callbacks for jsonp requests
Chris@0 9673 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
Chris@0 9674
Chris@0 9675 var callbackName, overwritten, responseContainer,
Chris@0 9676 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
Chris@0 9677 "url" :
Chris@0 9678 typeof s.data === "string" &&
Chris@0 9679 ( s.contentType || "" )
Chris@0 9680 .indexOf( "application/x-www-form-urlencoded" ) === 0 &&
Chris@0 9681 rjsonp.test( s.data ) && "data"
Chris@0 9682 );
Chris@0 9683
Chris@0 9684 // Handle iff the expected data type is "jsonp" or we have a parameter to set
Chris@0 9685 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
Chris@0 9686
Chris@0 9687 // Get callback name, remembering preexisting value associated with it
Chris@0 9688 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
Chris@0 9689 s.jsonpCallback() :
Chris@0 9690 s.jsonpCallback;
Chris@0 9691
Chris@0 9692 // Insert callback into url or form data
Chris@0 9693 if ( jsonProp ) {
Chris@0 9694 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
Chris@0 9695 } else if ( s.jsonp !== false ) {
Chris@0 9696 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
Chris@0 9697 }
Chris@0 9698
Chris@0 9699 // Use data converter to retrieve json after script execution
Chris@0 9700 s.converters[ "script json" ] = function() {
Chris@0 9701 if ( !responseContainer ) {
Chris@0 9702 jQuery.error( callbackName + " was not called" );
Chris@0 9703 }
Chris@0 9704 return responseContainer[ 0 ];
Chris@0 9705 };
Chris@0 9706
Chris@0 9707 // Force json dataType
Chris@0 9708 s.dataTypes[ 0 ] = "json";
Chris@0 9709
Chris@0 9710 // Install callback
Chris@0 9711 overwritten = window[ callbackName ];
Chris@0 9712 window[ callbackName ] = function() {
Chris@0 9713 responseContainer = arguments;
Chris@0 9714 };
Chris@0 9715
Chris@0 9716 // Clean-up function (fires after converters)
Chris@0 9717 jqXHR.always( function() {
Chris@0 9718
Chris@0 9719 // If previous value didn't exist - remove it
Chris@0 9720 if ( overwritten === undefined ) {
Chris@0 9721 jQuery( window ).removeProp( callbackName );
Chris@0 9722
Chris@0 9723 // Otherwise restore preexisting value
Chris@0 9724 } else {
Chris@0 9725 window[ callbackName ] = overwritten;
Chris@0 9726 }
Chris@0 9727
Chris@0 9728 // Save back as free
Chris@0 9729 if ( s[ callbackName ] ) {
Chris@0 9730
Chris@0 9731 // Make sure that re-using the options doesn't screw things around
Chris@0 9732 s.jsonpCallback = originalSettings.jsonpCallback;
Chris@0 9733
Chris@0 9734 // Save the callback name for future use
Chris@0 9735 oldCallbacks.push( callbackName );
Chris@0 9736 }
Chris@0 9737
Chris@0 9738 // Call if it was a function and we have a response
Chris@0 9739 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
Chris@0 9740 overwritten( responseContainer[ 0 ] );
Chris@0 9741 }
Chris@0 9742
Chris@0 9743 responseContainer = overwritten = undefined;
Chris@0 9744 } );
Chris@0 9745
Chris@0 9746 // Delegate to script
Chris@0 9747 return "script";
Chris@0 9748 }
Chris@0 9749 } );
Chris@0 9750
Chris@0 9751
Chris@0 9752
Chris@0 9753
Chris@0 9754 // Support: Safari 8 only
Chris@0 9755 // In Safari 8 documents created via document.implementation.createHTMLDocument
Chris@0 9756 // collapse sibling forms: the second one becomes a child of the first one.
Chris@0 9757 // Because of that, this security measure has to be disabled in Safari 8.
Chris@0 9758 // https://bugs.webkit.org/show_bug.cgi?id=137337
Chris@0 9759 support.createHTMLDocument = ( function() {
Chris@0 9760 var body = document.implementation.createHTMLDocument( "" ).body;
Chris@0 9761 body.innerHTML = "<form></form><form></form>";
Chris@0 9762 return body.childNodes.length === 2;
Chris@0 9763 } )();
Chris@0 9764
Chris@0 9765
Chris@0 9766 // Argument "data" should be string of html
Chris@0 9767 // context (optional): If specified, the fragment will be created in this context,
Chris@0 9768 // defaults to document
Chris@0 9769 // keepScripts (optional): If true, will include scripts passed in the html string
Chris@0 9770 jQuery.parseHTML = function( data, context, keepScripts ) {
Chris@0 9771 if ( typeof data !== "string" ) {
Chris@0 9772 return [];
Chris@0 9773 }
Chris@0 9774 if ( typeof context === "boolean" ) {
Chris@0 9775 keepScripts = context;
Chris@0 9776 context = false;
Chris@0 9777 }
Chris@0 9778
Chris@0 9779 var base, parsed, scripts;
Chris@0 9780
Chris@0 9781 if ( !context ) {
Chris@0 9782
Chris@0 9783 // Stop scripts or inline event handlers from being executed immediately
Chris@0 9784 // by using document.implementation
Chris@0 9785 if ( support.createHTMLDocument ) {
Chris@0 9786 context = document.implementation.createHTMLDocument( "" );
Chris@0 9787
Chris@0 9788 // Set the base href for the created document
Chris@0 9789 // so any parsed elements with URLs
Chris@0 9790 // are based on the document's URL (gh-2965)
Chris@0 9791 base = context.createElement( "base" );
Chris@0 9792 base.href = document.location.href;
Chris@0 9793 context.head.appendChild( base );
Chris@0 9794 } else {
Chris@0 9795 context = document;
Chris@0 9796 }
Chris@0 9797 }
Chris@0 9798
Chris@0 9799 parsed = rsingleTag.exec( data );
Chris@0 9800 scripts = !keepScripts && [];
Chris@0 9801
Chris@0 9802 // Single tag
Chris@0 9803 if ( parsed ) {
Chris@0 9804 return [ context.createElement( parsed[ 1 ] ) ];
Chris@0 9805 }
Chris@0 9806
Chris@0 9807 parsed = buildFragment( [ data ], context, scripts );
Chris@0 9808
Chris@0 9809 if ( scripts && scripts.length ) {
Chris@0 9810 jQuery( scripts ).remove();
Chris@0 9811 }
Chris@0 9812
Chris@0 9813 return jQuery.merge( [], parsed.childNodes );
Chris@0 9814 };
Chris@0 9815
Chris@0 9816
Chris@0 9817 /**
Chris@0 9818 * Load a url into a page
Chris@0 9819 */
Chris@0 9820 jQuery.fn.load = function( url, params, callback ) {
Chris@0 9821 var selector, type, response,
Chris@0 9822 self = this,
Chris@0 9823 off = url.indexOf( " " );
Chris@0 9824
Chris@0 9825 if ( off > -1 ) {
Chris@0 9826 selector = stripAndCollapse( url.slice( off ) );
Chris@0 9827 url = url.slice( 0, off );
Chris@0 9828 }
Chris@0 9829
Chris@0 9830 // If it's a function
Chris@0 9831 if ( jQuery.isFunction( params ) ) {
Chris@0 9832
Chris@0 9833 // We assume that it's the callback
Chris@0 9834 callback = params;
Chris@0 9835 params = undefined;
Chris@0 9836
Chris@0 9837 // Otherwise, build a param string
Chris@0 9838 } else if ( params && typeof params === "object" ) {
Chris@0 9839 type = "POST";
Chris@0 9840 }
Chris@0 9841
Chris@0 9842 // If we have elements to modify, make the request
Chris@0 9843 if ( self.length > 0 ) {
Chris@0 9844 jQuery.ajax( {
Chris@0 9845 url: url,
Chris@0 9846
Chris@0 9847 // If "type" variable is undefined, then "GET" method will be used.
Chris@0 9848 // Make value of this field explicit since
Chris@0 9849 // user can override it through ajaxSetup method
Chris@0 9850 type: type || "GET",
Chris@0 9851 dataType: "html",
Chris@0 9852 data: params
Chris@0 9853 } ).done( function( responseText ) {
Chris@0 9854
Chris@0 9855 // Save response for use in complete callback
Chris@0 9856 response = arguments;
Chris@0 9857
Chris@0 9858 self.html( selector ?
Chris@0 9859
Chris@0 9860 // If a selector was specified, locate the right elements in a dummy div
Chris@0 9861 // Exclude scripts to avoid IE 'Permission Denied' errors
Chris@0 9862 jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
Chris@0 9863
Chris@0 9864 // Otherwise use the full result
Chris@0 9865 responseText );
Chris@0 9866
Chris@0 9867 // If the request succeeds, this function gets "data", "status", "jqXHR"
Chris@0 9868 // but they are ignored because response was set above.
Chris@0 9869 // If it fails, this function gets "jqXHR", "status", "error"
Chris@0 9870 } ).always( callback && function( jqXHR, status ) {
Chris@0 9871 self.each( function() {
Chris@0 9872 callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
Chris@0 9873 } );
Chris@0 9874 } );
Chris@0 9875 }
Chris@0 9876
Chris@0 9877 return this;
Chris@0 9878 };
Chris@0 9879
Chris@0 9880
Chris@0 9881
Chris@0 9882
Chris@0 9883 // Attach a bunch of functions for handling common AJAX events
Chris@0 9884 jQuery.each( [
Chris@0 9885 "ajaxStart",
Chris@0 9886 "ajaxStop",
Chris@0 9887 "ajaxComplete",
Chris@0 9888 "ajaxError",
Chris@0 9889 "ajaxSuccess",
Chris@0 9890 "ajaxSend"
Chris@0 9891 ], function( i, type ) {
Chris@0 9892 jQuery.fn[ type ] = function( fn ) {
Chris@0 9893 return this.on( type, fn );
Chris@0 9894 };
Chris@0 9895 } );
Chris@0 9896
Chris@0 9897
Chris@0 9898
Chris@0 9899
Chris@0 9900 jQuery.expr.pseudos.animated = function( elem ) {
Chris@0 9901 return jQuery.grep( jQuery.timers, function( fn ) {
Chris@0 9902 return elem === fn.elem;
Chris@0 9903 } ).length;
Chris@0 9904 };
Chris@0 9905
Chris@0 9906
Chris@0 9907
Chris@0 9908
Chris@0 9909 jQuery.offset = {
Chris@0 9910 setOffset: function( elem, options, i ) {
Chris@0 9911 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
Chris@0 9912 position = jQuery.css( elem, "position" ),
Chris@0 9913 curElem = jQuery( elem ),
Chris@0 9914 props = {};
Chris@0 9915
Chris@0 9916 // Set position first, in-case top/left are set even on static elem
Chris@0 9917 if ( position === "static" ) {
Chris@0 9918 elem.style.position = "relative";
Chris@0 9919 }
Chris@0 9920
Chris@0 9921 curOffset = curElem.offset();
Chris@0 9922 curCSSTop = jQuery.css( elem, "top" );
Chris@0 9923 curCSSLeft = jQuery.css( elem, "left" );
Chris@0 9924 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
Chris@0 9925 ( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1;
Chris@0 9926
Chris@0 9927 // Need to be able to calculate position if either
Chris@0 9928 // top or left is auto and position is either absolute or fixed
Chris@0 9929 if ( calculatePosition ) {
Chris@0 9930 curPosition = curElem.position();
Chris@0 9931 curTop = curPosition.top;
Chris@0 9932 curLeft = curPosition.left;
Chris@0 9933
Chris@0 9934 } else {
Chris@0 9935 curTop = parseFloat( curCSSTop ) || 0;
Chris@0 9936 curLeft = parseFloat( curCSSLeft ) || 0;
Chris@0 9937 }
Chris@0 9938
Chris@0 9939 if ( jQuery.isFunction( options ) ) {
Chris@0 9940
Chris@0 9941 // Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
Chris@0 9942 options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
Chris@0 9943 }
Chris@0 9944
Chris@0 9945 if ( options.top != null ) {
Chris@0 9946 props.top = ( options.top - curOffset.top ) + curTop;
Chris@0 9947 }
Chris@0 9948 if ( options.left != null ) {
Chris@0 9949 props.left = ( options.left - curOffset.left ) + curLeft;
Chris@0 9950 }
Chris@0 9951
Chris@0 9952 if ( "using" in options ) {
Chris@0 9953 options.using.call( elem, props );
Chris@0 9954
Chris@0 9955 } else {
Chris@0 9956 curElem.css( props );
Chris@0 9957 }
Chris@0 9958 }
Chris@0 9959 };
Chris@0 9960
Chris@0 9961 jQuery.fn.extend( {
Chris@0 9962 offset: function( options ) {
Chris@0 9963
Chris@0 9964 // Preserve chaining for setter
Chris@0 9965 if ( arguments.length ) {
Chris@0 9966 return options === undefined ?
Chris@0 9967 this :
Chris@0 9968 this.each( function( i ) {
Chris@0 9969 jQuery.offset.setOffset( this, options, i );
Chris@0 9970 } );
Chris@0 9971 }
Chris@0 9972
Chris@0 9973 var doc, docElem, rect, win,
Chris@0 9974 elem = this[ 0 ];
Chris@0 9975
Chris@0 9976 if ( !elem ) {
Chris@0 9977 return;
Chris@0 9978 }
Chris@0 9979
Chris@0 9980 // Return zeros for disconnected and hidden (display: none) elements (gh-2310)
Chris@0 9981 // Support: IE <=11 only
Chris@0 9982 // Running getBoundingClientRect on a
Chris@0 9983 // disconnected node in IE throws an error
Chris@0 9984 if ( !elem.getClientRects().length ) {
Chris@0 9985 return { top: 0, left: 0 };
Chris@0 9986 }
Chris@0 9987
Chris@0 9988 rect = elem.getBoundingClientRect();
Chris@0 9989
Chris@0 9990 doc = elem.ownerDocument;
Chris@0 9991 docElem = doc.documentElement;
Chris@0 9992 win = doc.defaultView;
Chris@0 9993
Chris@0 9994 return {
Chris@0 9995 top: rect.top + win.pageYOffset - docElem.clientTop,
Chris@0 9996 left: rect.left + win.pageXOffset - docElem.clientLeft
Chris@0 9997 };
Chris@0 9998 },
Chris@0 9999
Chris@0 10000 position: function() {
Chris@0 10001 if ( !this[ 0 ] ) {
Chris@0 10002 return;
Chris@0 10003 }
Chris@0 10004
Chris@0 10005 var offsetParent, offset,
Chris@0 10006 elem = this[ 0 ],
Chris@0 10007 parentOffset = { top: 0, left: 0 };
Chris@0 10008
Chris@0 10009 // Fixed elements are offset from window (parentOffset = {top:0, left: 0},
Chris@0 10010 // because it is its only offset parent
Chris@0 10011 if ( jQuery.css( elem, "position" ) === "fixed" ) {
Chris@0 10012
Chris@0 10013 // Assume getBoundingClientRect is there when computed position is fixed
Chris@0 10014 offset = elem.getBoundingClientRect();
Chris@0 10015
Chris@0 10016 } else {
Chris@0 10017
Chris@0 10018 // Get *real* offsetParent
Chris@0 10019 offsetParent = this.offsetParent();
Chris@0 10020
Chris@0 10021 // Get correct offsets
Chris@0 10022 offset = this.offset();
Chris@0 10023 if ( !nodeName( offsetParent[ 0 ], "html" ) ) {
Chris@0 10024 parentOffset = offsetParent.offset();
Chris@0 10025 }
Chris@0 10026
Chris@0 10027 // Add offsetParent borders
Chris@0 10028 parentOffset = {
Chris@0 10029 top: parentOffset.top + jQuery.css( offsetParent[ 0 ], "borderTopWidth", true ),
Chris@0 10030 left: parentOffset.left + jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true )
Chris@0 10031 };
Chris@0 10032 }
Chris@0 10033
Chris@0 10034 // Subtract parent offsets and element margins
Chris@0 10035 return {
Chris@0 10036 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
Chris@0 10037 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
Chris@0 10038 };
Chris@0 10039 },
Chris@0 10040
Chris@0 10041 // This method will return documentElement in the following cases:
Chris@0 10042 // 1) For the element inside the iframe without offsetParent, this method will return
Chris@0 10043 // documentElement of the parent window
Chris@0 10044 // 2) For the hidden or detached element
Chris@0 10045 // 3) For body or html element, i.e. in case of the html node - it will return itself
Chris@0 10046 //
Chris@0 10047 // but those exceptions were never presented as a real life use-cases
Chris@0 10048 // and might be considered as more preferable results.
Chris@0 10049 //
Chris@0 10050 // This logic, however, is not guaranteed and can change at any point in the future
Chris@0 10051 offsetParent: function() {
Chris@0 10052 return this.map( function() {
Chris@0 10053 var offsetParent = this.offsetParent;
Chris@0 10054
Chris@0 10055 while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) {
Chris@0 10056 offsetParent = offsetParent.offsetParent;
Chris@0 10057 }
Chris@0 10058
Chris@0 10059 return offsetParent || documentElement;
Chris@0 10060 } );
Chris@0 10061 }
Chris@0 10062 } );
Chris@0 10063
Chris@0 10064 // Create scrollLeft and scrollTop methods
Chris@0 10065 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
Chris@0 10066 var top = "pageYOffset" === prop;
Chris@0 10067
Chris@0 10068 jQuery.fn[ method ] = function( val ) {
Chris@0 10069 return access( this, function( elem, method, val ) {
Chris@0 10070
Chris@0 10071 // Coalesce documents and windows
Chris@0 10072 var win;
Chris@0 10073 if ( jQuery.isWindow( elem ) ) {
Chris@0 10074 win = elem;
Chris@0 10075 } else if ( elem.nodeType === 9 ) {
Chris@0 10076 win = elem.defaultView;
Chris@0 10077 }
Chris@0 10078
Chris@0 10079 if ( val === undefined ) {
Chris@0 10080 return win ? win[ prop ] : elem[ method ];
Chris@0 10081 }
Chris@0 10082
Chris@0 10083 if ( win ) {
Chris@0 10084 win.scrollTo(
Chris@0 10085 !top ? val : win.pageXOffset,
Chris@0 10086 top ? val : win.pageYOffset
Chris@0 10087 );
Chris@0 10088
Chris@0 10089 } else {
Chris@0 10090 elem[ method ] = val;
Chris@0 10091 }
Chris@0 10092 }, method, val, arguments.length );
Chris@0 10093 };
Chris@0 10094 } );
Chris@0 10095
Chris@0 10096 // Support: Safari <=7 - 9.1, Chrome <=37 - 49
Chris@0 10097 // Add the top/left cssHooks using jQuery.fn.position
Chris@0 10098 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
Chris@0 10099 // Blink bug: https://bugs.chromium.org/p/chromium/issues/detail?id=589347
Chris@0 10100 // getComputedStyle returns percent when specified for top/left/bottom/right;
Chris@0 10101 // rather than make the css module depend on the offset module, just check for it here
Chris@0 10102 jQuery.each( [ "top", "left" ], function( i, prop ) {
Chris@0 10103 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
Chris@0 10104 function( elem, computed ) {
Chris@0 10105 if ( computed ) {
Chris@0 10106 computed = curCSS( elem, prop );
Chris@0 10107
Chris@0 10108 // If curCSS returns percentage, fallback to offset
Chris@0 10109 return rnumnonpx.test( computed ) ?
Chris@0 10110 jQuery( elem ).position()[ prop ] + "px" :
Chris@0 10111 computed;
Chris@0 10112 }
Chris@0 10113 }
Chris@0 10114 );
Chris@0 10115 } );
Chris@0 10116
Chris@0 10117
Chris@0 10118 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
Chris@0 10119 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
Chris@0 10120 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name },
Chris@0 10121 function( defaultExtra, funcName ) {
Chris@0 10122
Chris@0 10123 // Margin is only for outerHeight, outerWidth
Chris@0 10124 jQuery.fn[ funcName ] = function( margin, value ) {
Chris@0 10125 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
Chris@0 10126 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
Chris@0 10127
Chris@0 10128 return access( this, function( elem, type, value ) {
Chris@0 10129 var doc;
Chris@0 10130
Chris@0 10131 if ( jQuery.isWindow( elem ) ) {
Chris@0 10132
Chris@0 10133 // $( window ).outerWidth/Height return w/h including scrollbars (gh-1729)
Chris@0 10134 return funcName.indexOf( "outer" ) === 0 ?
Chris@0 10135 elem[ "inner" + name ] :
Chris@0 10136 elem.document.documentElement[ "client" + name ];
Chris@0 10137 }
Chris@0 10138
Chris@0 10139 // Get document width or height
Chris@0 10140 if ( elem.nodeType === 9 ) {
Chris@0 10141 doc = elem.documentElement;
Chris@0 10142
Chris@0 10143 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
Chris@0 10144 // whichever is greatest
Chris@0 10145 return Math.max(
Chris@0 10146 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
Chris@0 10147 elem.body[ "offset" + name ], doc[ "offset" + name ],
Chris@0 10148 doc[ "client" + name ]
Chris@0 10149 );
Chris@0 10150 }
Chris@0 10151
Chris@0 10152 return value === undefined ?
Chris@0 10153
Chris@0 10154 // Get width or height on the element, requesting but not forcing parseFloat
Chris@0 10155 jQuery.css( elem, type, extra ) :
Chris@0 10156
Chris@0 10157 // Set width or height on the element
Chris@0 10158 jQuery.style( elem, type, value, extra );
Chris@0 10159 }, type, chainable ? margin : undefined, chainable );
Chris@0 10160 };
Chris@0 10161 } );
Chris@0 10162 } );
Chris@0 10163
Chris@0 10164
Chris@0 10165 jQuery.fn.extend( {
Chris@0 10166
Chris@0 10167 bind: function( types, data, fn ) {
Chris@0 10168 return this.on( types, null, data, fn );
Chris@0 10169 },
Chris@0 10170 unbind: function( types, fn ) {
Chris@0 10171 return this.off( types, null, fn );
Chris@0 10172 },
Chris@0 10173
Chris@0 10174 delegate: function( selector, types, data, fn ) {
Chris@0 10175 return this.on( types, selector, data, fn );
Chris@0 10176 },
Chris@0 10177 undelegate: function( selector, types, fn ) {
Chris@0 10178
Chris@0 10179 // ( namespace ) or ( selector, types [, fn] )
Chris@0 10180 return arguments.length === 1 ?
Chris@0 10181 this.off( selector, "**" ) :
Chris@0 10182 this.off( types, selector || "**", fn );
Chris@0 10183 }
Chris@0 10184 } );
Chris@0 10185
Chris@0 10186 jQuery.holdReady = function( hold ) {
Chris@0 10187 if ( hold ) {
Chris@0 10188 jQuery.readyWait++;
Chris@0 10189 } else {
Chris@0 10190 jQuery.ready( true );
Chris@0 10191 }
Chris@0 10192 };
Chris@0 10193 jQuery.isArray = Array.isArray;
Chris@0 10194 jQuery.parseJSON = JSON.parse;
Chris@0 10195 jQuery.nodeName = nodeName;
Chris@0 10196
Chris@0 10197
Chris@0 10198
Chris@0 10199
Chris@0 10200 // Register as a named AMD module, since jQuery can be concatenated with other
Chris@0 10201 // files that may use define, but not via a proper concatenation script that
Chris@0 10202 // understands anonymous AMD modules. A named AMD is safest and most robust
Chris@0 10203 // way to register. Lowercase jquery is used because AMD module names are
Chris@0 10204 // derived from file names, and jQuery is normally delivered in a lowercase
Chris@0 10205 // file name. Do this after creating the global so that if an AMD module wants
Chris@0 10206 // to call noConflict to hide this version of jQuery, it will work.
Chris@0 10207
Chris@0 10208 // Note that for maximum portability, libraries that are not jQuery should
Chris@0 10209 // declare themselves as anonymous modules, and avoid setting a global if an
Chris@0 10210 // AMD loader is present. jQuery is a special case. For more information, see
Chris@0 10211 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
Chris@0 10212
Chris@0 10213 if ( typeof define === "function" && define.amd ) {
Chris@0 10214 define( "jquery", [], function() {
Chris@0 10215 return jQuery;
Chris@0 10216 } );
Chris@0 10217 }
Chris@0 10218
Chris@0 10219
Chris@0 10220
Chris@0 10221
Chris@0 10222 var
Chris@0 10223
Chris@0 10224 // Map over jQuery in case of overwrite
Chris@0 10225 _jQuery = window.jQuery,
Chris@0 10226
Chris@0 10227 // Map over the $ in case of overwrite
Chris@0 10228 _$ = window.$;
Chris@0 10229
Chris@0 10230 jQuery.noConflict = function( deep ) {
Chris@0 10231 if ( window.$ === jQuery ) {
Chris@0 10232 window.$ = _$;
Chris@0 10233 }
Chris@0 10234
Chris@0 10235 if ( deep && window.jQuery === jQuery ) {
Chris@0 10236 window.jQuery = _jQuery;
Chris@0 10237 }
Chris@0 10238
Chris@0 10239 return jQuery;
Chris@0 10240 };
Chris@0 10241
Chris@0 10242 // Expose jQuery and $ identifiers, even in AMD
Chris@0 10243 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
Chris@0 10244 // and CommonJS for browser emulators (#13566)
Chris@0 10245 if ( !noGlobal ) {
Chris@0 10246 window.jQuery = window.$ = jQuery;
Chris@0 10247 }
Chris@0 10248
Chris@0 10249
Chris@0 10250
Chris@0 10251
Chris@0 10252 return jQuery;
Chris@0 10253 } );