annotate jquery-2.1.4.js @ 536:efac13499354 Dev_main

Merge into dev_main
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 22 Feb 2016 12:19:43 +0000
parents e4436132dbd9
children
rev   line source
nicholas@103 1 /*!
nicholas@103 2 * jQuery JavaScript Library v2.1.4
nicholas@103 3 * http://jquery.com/
nicholas@103 4 *
nicholas@103 5 * Includes Sizzle.js
nicholas@103 6 * http://sizzlejs.com/
nicholas@103 7 *
nicholas@103 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nicholas@103 9 * Released under the MIT license
nicholas@103 10 * http://jquery.org/license
nicholas@103 11 *
nicholas@103 12 * Date: 2015-04-28T16:01Z
nicholas@103 13 */
nicholas@103 14
nicholas@103 15 (function( global, factory ) {
nicholas@103 16
nicholas@103 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nicholas@103 18 // For CommonJS and CommonJS-like environments where a proper `window`
nicholas@103 19 // is present, execute the factory and get jQuery.
nicholas@103 20 // For environments that do not have a `window` with a `document`
nicholas@103 21 // (such as Node.js), expose a factory as module.exports.
nicholas@103 22 // This accentuates the need for the creation of a real `window`.
nicholas@103 23 // e.g. var jQuery = require("jquery")(window);
nicholas@103 24 // See ticket #14549 for more info.
nicholas@103 25 module.exports = global.document ?
nicholas@103 26 factory( global, true ) :
nicholas@103 27 function( w ) {
nicholas@103 28 if ( !w.document ) {
nicholas@103 29 throw new Error( "jQuery requires a window with a document" );
nicholas@103 30 }
nicholas@103 31 return factory( w );
nicholas@103 32 };
nicholas@103 33 } else {
nicholas@103 34 factory( global );
nicholas@103 35 }
nicholas@103 36
nicholas@103 37 // Pass this if window is not defined yet
nicholas@103 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nicholas@103 39
nicholas@103 40 // Support: Firefox 18+
nicholas@103 41 // Can't be in strict mode, several libs including ASP.NET trace
nicholas@103 42 // the stack via arguments.caller.callee and Firefox dies if
nicholas@103 43 // you try to trace through "use strict" call chains. (#13335)
nicholas@103 44 //
nicholas@103 45
nicholas@103 46 var arr = [];
nicholas@103 47
nicholas@103 48 var slice = arr.slice;
nicholas@103 49
nicholas@103 50 var concat = arr.concat;
nicholas@103 51
nicholas@103 52 var push = arr.push;
nicholas@103 53
nicholas@103 54 var indexOf = arr.indexOf;
nicholas@103 55
nicholas@103 56 var class2type = {};
nicholas@103 57
nicholas@103 58 var toString = class2type.toString;
nicholas@103 59
nicholas@103 60 var hasOwn = class2type.hasOwnProperty;
nicholas@103 61
nicholas@103 62 var support = {};
nicholas@103 63
nicholas@103 64
nicholas@103 65
nicholas@103 66 var
nicholas@103 67 // Use the correct document accordingly with window argument (sandbox)
nicholas@103 68 document = window.document,
nicholas@103 69
nicholas@103 70 version = "2.1.4",
nicholas@103 71
nicholas@103 72 // Define a local copy of jQuery
nicholas@103 73 jQuery = function( selector, context ) {
nicholas@103 74 // The jQuery object is actually just the init constructor 'enhanced'
nicholas@103 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nicholas@103 76 return new jQuery.fn.init( selector, context );
nicholas@103 77 },
nicholas@103 78
nicholas@103 79 // Support: Android<4.1
nicholas@103 80 // Make sure we trim BOM and NBSP
nicholas@103 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nicholas@103 82
nicholas@103 83 // Matches dashed string for camelizing
nicholas@103 84 rmsPrefix = /^-ms-/,
nicholas@103 85 rdashAlpha = /-([\da-z])/gi,
nicholas@103 86
nicholas@103 87 // Used by jQuery.camelCase as callback to replace()
nicholas@103 88 fcamelCase = function( all, letter ) {
nicholas@103 89 return letter.toUpperCase();
nicholas@103 90 };
nicholas@103 91
nicholas@103 92 jQuery.fn = jQuery.prototype = {
nicholas@103 93 // The current version of jQuery being used
nicholas@103 94 jquery: version,
nicholas@103 95
nicholas@103 96 constructor: jQuery,
nicholas@103 97
nicholas@103 98 // Start with an empty selector
nicholas@103 99 selector: "",
nicholas@103 100
nicholas@103 101 // The default length of a jQuery object is 0
nicholas@103 102 length: 0,
nicholas@103 103
nicholas@103 104 toArray: function() {
nicholas@103 105 return slice.call( this );
nicholas@103 106 },
nicholas@103 107
nicholas@103 108 // Get the Nth element in the matched element set OR
nicholas@103 109 // Get the whole matched element set as a clean array
nicholas@103 110 get: function( num ) {
nicholas@103 111 return num != null ?
nicholas@103 112
nicholas@103 113 // Return just the one element from the set
nicholas@103 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nicholas@103 115
nicholas@103 116 // Return all the elements in a clean array
nicholas@103 117 slice.call( this );
nicholas@103 118 },
nicholas@103 119
nicholas@103 120 // Take an array of elements and push it onto the stack
nicholas@103 121 // (returning the new matched element set)
nicholas@103 122 pushStack: function( elems ) {
nicholas@103 123
nicholas@103 124 // Build a new jQuery matched element set
nicholas@103 125 var ret = jQuery.merge( this.constructor(), elems );
nicholas@103 126
nicholas@103 127 // Add the old object onto the stack (as a reference)
nicholas@103 128 ret.prevObject = this;
nicholas@103 129 ret.context = this.context;
nicholas@103 130
nicholas@103 131 // Return the newly-formed element set
nicholas@103 132 return ret;
nicholas@103 133 },
nicholas@103 134
nicholas@103 135 // Execute a callback for every element in the matched set.
nicholas@103 136 // (You can seed the arguments with an array of args, but this is
nicholas@103 137 // only used internally.)
nicholas@103 138 each: function( callback, args ) {
nicholas@103 139 return jQuery.each( this, callback, args );
nicholas@103 140 },
nicholas@103 141
nicholas@103 142 map: function( callback ) {
nicholas@103 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nicholas@103 144 return callback.call( elem, i, elem );
nicholas@103 145 }));
nicholas@103 146 },
nicholas@103 147
nicholas@103 148 slice: function() {
nicholas@103 149 return this.pushStack( slice.apply( this, arguments ) );
nicholas@103 150 },
nicholas@103 151
nicholas@103 152 first: function() {
nicholas@103 153 return this.eq( 0 );
nicholas@103 154 },
nicholas@103 155
nicholas@103 156 last: function() {
nicholas@103 157 return this.eq( -1 );
nicholas@103 158 },
nicholas@103 159
nicholas@103 160 eq: function( i ) {
nicholas@103 161 var len = this.length,
nicholas@103 162 j = +i + ( i < 0 ? len : 0 );
nicholas@103 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nicholas@103 164 },
nicholas@103 165
nicholas@103 166 end: function() {
nicholas@103 167 return this.prevObject || this.constructor(null);
nicholas@103 168 },
nicholas@103 169
nicholas@103 170 // For internal use only.
nicholas@103 171 // Behaves like an Array's method, not like a jQuery method.
nicholas@103 172 push: push,
nicholas@103 173 sort: arr.sort,
nicholas@103 174 splice: arr.splice
nicholas@103 175 };
nicholas@103 176
nicholas@103 177 jQuery.extend = jQuery.fn.extend = function() {
nicholas@103 178 var options, name, src, copy, copyIsArray, clone,
nicholas@103 179 target = arguments[0] || {},
nicholas@103 180 i = 1,
nicholas@103 181 length = arguments.length,
nicholas@103 182 deep = false;
nicholas@103 183
nicholas@103 184 // Handle a deep copy situation
nicholas@103 185 if ( typeof target === "boolean" ) {
nicholas@103 186 deep = target;
nicholas@103 187
nicholas@103 188 // Skip the boolean and the target
nicholas@103 189 target = arguments[ i ] || {};
nicholas@103 190 i++;
nicholas@103 191 }
nicholas@103 192
nicholas@103 193 // Handle case when target is a string or something (possible in deep copy)
nicholas@103 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nicholas@103 195 target = {};
nicholas@103 196 }
nicholas@103 197
nicholas@103 198 // Extend jQuery itself if only one argument is passed
nicholas@103 199 if ( i === length ) {
nicholas@103 200 target = this;
nicholas@103 201 i--;
nicholas@103 202 }
nicholas@103 203
nicholas@103 204 for ( ; i < length; i++ ) {
nicholas@103 205 // Only deal with non-null/undefined values
nicholas@103 206 if ( (options = arguments[ i ]) != null ) {
nicholas@103 207 // Extend the base object
nicholas@103 208 for ( name in options ) {
nicholas@103 209 src = target[ name ];
nicholas@103 210 copy = options[ name ];
nicholas@103 211
nicholas@103 212 // Prevent never-ending loop
nicholas@103 213 if ( target === copy ) {
nicholas@103 214 continue;
nicholas@103 215 }
nicholas@103 216
nicholas@103 217 // Recurse if we're merging plain objects or arrays
nicholas@103 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nicholas@103 219 if ( copyIsArray ) {
nicholas@103 220 copyIsArray = false;
nicholas@103 221 clone = src && jQuery.isArray(src) ? src : [];
nicholas@103 222
nicholas@103 223 } else {
nicholas@103 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nicholas@103 225 }
nicholas@103 226
nicholas@103 227 // Never move original objects, clone them
nicholas@103 228 target[ name ] = jQuery.extend( deep, clone, copy );
nicholas@103 229
nicholas@103 230 // Don't bring in undefined values
nicholas@103 231 } else if ( copy !== undefined ) {
nicholas@103 232 target[ name ] = copy;
nicholas@103 233 }
nicholas@103 234 }
nicholas@103 235 }
nicholas@103 236 }
nicholas@103 237
nicholas@103 238 // Return the modified object
nicholas@103 239 return target;
nicholas@103 240 };
nicholas@103 241
nicholas@103 242 jQuery.extend({
nicholas@103 243 // Unique for each copy of jQuery on the page
nicholas@103 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nicholas@103 245
nicholas@103 246 // Assume jQuery is ready without the ready module
nicholas@103 247 isReady: true,
nicholas@103 248
nicholas@103 249 error: function( msg ) {
nicholas@103 250 throw new Error( msg );
nicholas@103 251 },
nicholas@103 252
nicholas@103 253 noop: function() {},
nicholas@103 254
nicholas@103 255 isFunction: function( obj ) {
nicholas@103 256 return jQuery.type(obj) === "function";
nicholas@103 257 },
nicholas@103 258
nicholas@103 259 isArray: Array.isArray,
nicholas@103 260
nicholas@103 261 isWindow: function( obj ) {
nicholas@103 262 return obj != null && obj === obj.window;
nicholas@103 263 },
nicholas@103 264
nicholas@103 265 isNumeric: function( obj ) {
nicholas@103 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nicholas@103 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nicholas@103 268 // subtraction forces infinities to NaN
nicholas@103 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nicholas@103 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nicholas@103 271 },
nicholas@103 272
nicholas@103 273 isPlainObject: function( obj ) {
nicholas@103 274 // Not plain objects:
nicholas@103 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nicholas@103 276 // - DOM nodes
nicholas@103 277 // - window
nicholas@103 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nicholas@103 279 return false;
nicholas@103 280 }
nicholas@103 281
nicholas@103 282 if ( obj.constructor &&
nicholas@103 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nicholas@103 284 return false;
nicholas@103 285 }
nicholas@103 286
nicholas@103 287 // If the function hasn't returned already, we're confident that
nicholas@103 288 // |obj| is a plain object, created by {} or constructed with new Object
nicholas@103 289 return true;
nicholas@103 290 },
nicholas@103 291
nicholas@103 292 isEmptyObject: function( obj ) {
nicholas@103 293 var name;
nicholas@103 294 for ( name in obj ) {
nicholas@103 295 return false;
nicholas@103 296 }
nicholas@103 297 return true;
nicholas@103 298 },
nicholas@103 299
nicholas@103 300 type: function( obj ) {
nicholas@103 301 if ( obj == null ) {
nicholas@103 302 return obj + "";
nicholas@103 303 }
nicholas@103 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nicholas@103 305 return typeof obj === "object" || typeof obj === "function" ?
nicholas@103 306 class2type[ toString.call(obj) ] || "object" :
nicholas@103 307 typeof obj;
nicholas@103 308 },
nicholas@103 309
nicholas@103 310 // Evaluates a script in a global context
nicholas@103 311 globalEval: function( code ) {
nicholas@103 312 var script,
nicholas@103 313 indirect = eval;
nicholas@103 314
nicholas@103 315 code = jQuery.trim( code );
nicholas@103 316
nicholas@103 317 if ( code ) {
nicholas@103 318 // If the code includes a valid, prologue position
nicholas@103 319 // strict mode pragma, execute code by injecting a
nicholas@103 320 // script tag into the document.
nicholas@103 321 if ( code.indexOf("use strict") === 1 ) {
nicholas@103 322 script = document.createElement("script");
nicholas@103 323 script.text = code;
nicholas@103 324 document.head.appendChild( script ).parentNode.removeChild( script );
nicholas@103 325 } else {
nicholas@103 326 // Otherwise, avoid the DOM node creation, insertion
nicholas@103 327 // and removal by using an indirect global eval
nicholas@103 328 indirect( code );
nicholas@103 329 }
nicholas@103 330 }
nicholas@103 331 },
nicholas@103 332
nicholas@103 333 // Convert dashed to camelCase; used by the css and data modules
nicholas@103 334 // Support: IE9-11+
nicholas@103 335 // Microsoft forgot to hump their vendor prefix (#9572)
nicholas@103 336 camelCase: function( string ) {
nicholas@103 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nicholas@103 338 },
nicholas@103 339
nicholas@103 340 nodeName: function( elem, name ) {
nicholas@103 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nicholas@103 342 },
nicholas@103 343
nicholas@103 344 // args is for internal usage only
nicholas@103 345 each: function( obj, callback, args ) {
nicholas@103 346 var value,
nicholas@103 347 i = 0,
nicholas@103 348 length = obj.length,
nicholas@103 349 isArray = isArraylike( obj );
nicholas@103 350
nicholas@103 351 if ( args ) {
nicholas@103 352 if ( isArray ) {
nicholas@103 353 for ( ; i < length; i++ ) {
nicholas@103 354 value = callback.apply( obj[ i ], args );
nicholas@103 355
nicholas@103 356 if ( value === false ) {
nicholas@103 357 break;
nicholas@103 358 }
nicholas@103 359 }
nicholas@103 360 } else {
nicholas@103 361 for ( i in obj ) {
nicholas@103 362 value = callback.apply( obj[ i ], args );
nicholas@103 363
nicholas@103 364 if ( value === false ) {
nicholas@103 365 break;
nicholas@103 366 }
nicholas@103 367 }
nicholas@103 368 }
nicholas@103 369
nicholas@103 370 // A special, fast, case for the most common use of each
nicholas@103 371 } else {
nicholas@103 372 if ( isArray ) {
nicholas@103 373 for ( ; i < length; i++ ) {
nicholas@103 374 value = callback.call( obj[ i ], i, obj[ i ] );
nicholas@103 375
nicholas@103 376 if ( value === false ) {
nicholas@103 377 break;
nicholas@103 378 }
nicholas@103 379 }
nicholas@103 380 } else {
nicholas@103 381 for ( i in obj ) {
nicholas@103 382 value = callback.call( obj[ i ], i, obj[ i ] );
nicholas@103 383
nicholas@103 384 if ( value === false ) {
nicholas@103 385 break;
nicholas@103 386 }
nicholas@103 387 }
nicholas@103 388 }
nicholas@103 389 }
nicholas@103 390
nicholas@103 391 return obj;
nicholas@103 392 },
nicholas@103 393
nicholas@103 394 // Support: Android<4.1
nicholas@103 395 trim: function( text ) {
nicholas@103 396 return text == null ?
nicholas@103 397 "" :
nicholas@103 398 ( text + "" ).replace( rtrim, "" );
nicholas@103 399 },
nicholas@103 400
nicholas@103 401 // results is for internal usage only
nicholas@103 402 makeArray: function( arr, results ) {
nicholas@103 403 var ret = results || [];
nicholas@103 404
nicholas@103 405 if ( arr != null ) {
nicholas@103 406 if ( isArraylike( Object(arr) ) ) {
nicholas@103 407 jQuery.merge( ret,
nicholas@103 408 typeof arr === "string" ?
nicholas@103 409 [ arr ] : arr
nicholas@103 410 );
nicholas@103 411 } else {
nicholas@103 412 push.call( ret, arr );
nicholas@103 413 }
nicholas@103 414 }
nicholas@103 415
nicholas@103 416 return ret;
nicholas@103 417 },
nicholas@103 418
nicholas@103 419 inArray: function( elem, arr, i ) {
nicholas@103 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nicholas@103 421 },
nicholas@103 422
nicholas@103 423 merge: function( first, second ) {
nicholas@103 424 var len = +second.length,
nicholas@103 425 j = 0,
nicholas@103 426 i = first.length;
nicholas@103 427
nicholas@103 428 for ( ; j < len; j++ ) {
nicholas@103 429 first[ i++ ] = second[ j ];
nicholas@103 430 }
nicholas@103 431
nicholas@103 432 first.length = i;
nicholas@103 433
nicholas@103 434 return first;
nicholas@103 435 },
nicholas@103 436
nicholas@103 437 grep: function( elems, callback, invert ) {
nicholas@103 438 var callbackInverse,
nicholas@103 439 matches = [],
nicholas@103 440 i = 0,
nicholas@103 441 length = elems.length,
nicholas@103 442 callbackExpect = !invert;
nicholas@103 443
nicholas@103 444 // Go through the array, only saving the items
nicholas@103 445 // that pass the validator function
nicholas@103 446 for ( ; i < length; i++ ) {
nicholas@103 447 callbackInverse = !callback( elems[ i ], i );
nicholas@103 448 if ( callbackInverse !== callbackExpect ) {
nicholas@103 449 matches.push( elems[ i ] );
nicholas@103 450 }
nicholas@103 451 }
nicholas@103 452
nicholas@103 453 return matches;
nicholas@103 454 },
nicholas@103 455
nicholas@103 456 // arg is for internal usage only
nicholas@103 457 map: function( elems, callback, arg ) {
nicholas@103 458 var value,
nicholas@103 459 i = 0,
nicholas@103 460 length = elems.length,
nicholas@103 461 isArray = isArraylike( elems ),
nicholas@103 462 ret = [];
nicholas@103 463
nicholas@103 464 // Go through the array, translating each of the items to their new values
nicholas@103 465 if ( isArray ) {
nicholas@103 466 for ( ; i < length; i++ ) {
nicholas@103 467 value = callback( elems[ i ], i, arg );
nicholas@103 468
nicholas@103 469 if ( value != null ) {
nicholas@103 470 ret.push( value );
nicholas@103 471 }
nicholas@103 472 }
nicholas@103 473
nicholas@103 474 // Go through every key on the object,
nicholas@103 475 } else {
nicholas@103 476 for ( i in elems ) {
nicholas@103 477 value = callback( elems[ i ], i, arg );
nicholas@103 478
nicholas@103 479 if ( value != null ) {
nicholas@103 480 ret.push( value );
nicholas@103 481 }
nicholas@103 482 }
nicholas@103 483 }
nicholas@103 484
nicholas@103 485 // Flatten any nested arrays
nicholas@103 486 return concat.apply( [], ret );
nicholas@103 487 },
nicholas@103 488
nicholas@103 489 // A global GUID counter for objects
nicholas@103 490 guid: 1,
nicholas@103 491
nicholas@103 492 // Bind a function to a context, optionally partially applying any
nicholas@103 493 // arguments.
nicholas@103 494 proxy: function( fn, context ) {
nicholas@103 495 var tmp, args, proxy;
nicholas@103 496
nicholas@103 497 if ( typeof context === "string" ) {
nicholas@103 498 tmp = fn[ context ];
nicholas@103 499 context = fn;
nicholas@103 500 fn = tmp;
nicholas@103 501 }
nicholas@103 502
nicholas@103 503 // Quick check to determine if target is callable, in the spec
nicholas@103 504 // this throws a TypeError, but we will just return undefined.
nicholas@103 505 if ( !jQuery.isFunction( fn ) ) {
nicholas@103 506 return undefined;
nicholas@103 507 }
nicholas@103 508
nicholas@103 509 // Simulated bind
nicholas@103 510 args = slice.call( arguments, 2 );
nicholas@103 511 proxy = function() {
nicholas@103 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nicholas@103 513 };
nicholas@103 514
nicholas@103 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nicholas@103 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nicholas@103 517
nicholas@103 518 return proxy;
nicholas@103 519 },
nicholas@103 520
nicholas@103 521 now: Date.now,
nicholas@103 522
nicholas@103 523 // jQuery.support is not used in Core but other projects attach their
nicholas@103 524 // properties to it so it needs to exist.
nicholas@103 525 support: support
nicholas@103 526 });
nicholas@103 527
nicholas@103 528 // Populate the class2type map
nicholas@103 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nicholas@103 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nicholas@103 531 });
nicholas@103 532
nicholas@103 533 function isArraylike( obj ) {
nicholas@103 534
nicholas@103 535 // Support: iOS 8.2 (not reproducible in simulator)
nicholas@103 536 // `in` check used to prevent JIT error (gh-2145)
nicholas@103 537 // hasOwn isn't used here due to false negatives
nicholas@103 538 // regarding Nodelist length in IE
nicholas@103 539 var length = "length" in obj && obj.length,
nicholas@103 540 type = jQuery.type( obj );
nicholas@103 541
nicholas@103 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nicholas@103 543 return false;
nicholas@103 544 }
nicholas@103 545
nicholas@103 546 if ( obj.nodeType === 1 && length ) {
nicholas@103 547 return true;
nicholas@103 548 }
nicholas@103 549
nicholas@103 550 return type === "array" || length === 0 ||
nicholas@103 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nicholas@103 552 }
nicholas@103 553 var Sizzle =
nicholas@103 554 /*!
nicholas@103 555 * Sizzle CSS Selector Engine v2.2.0-pre
nicholas@103 556 * http://sizzlejs.com/
nicholas@103 557 *
nicholas@103 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nicholas@103 559 * Released under the MIT license
nicholas@103 560 * http://jquery.org/license
nicholas@103 561 *
nicholas@103 562 * Date: 2014-12-16
nicholas@103 563 */
nicholas@103 564 (function( window ) {
nicholas@103 565
nicholas@103 566 var i,
nicholas@103 567 support,
nicholas@103 568 Expr,
nicholas@103 569 getText,
nicholas@103 570 isXML,
nicholas@103 571 tokenize,
nicholas@103 572 compile,
nicholas@103 573 select,
nicholas@103 574 outermostContext,
nicholas@103 575 sortInput,
nicholas@103 576 hasDuplicate,
nicholas@103 577
nicholas@103 578 // Local document vars
nicholas@103 579 setDocument,
nicholas@103 580 document,
nicholas@103 581 docElem,
nicholas@103 582 documentIsHTML,
nicholas@103 583 rbuggyQSA,
nicholas@103 584 rbuggyMatches,
nicholas@103 585 matches,
nicholas@103 586 contains,
nicholas@103 587
nicholas@103 588 // Instance-specific data
nicholas@103 589 expando = "sizzle" + 1 * new Date(),
nicholas@103 590 preferredDoc = window.document,
nicholas@103 591 dirruns = 0,
nicholas@103 592 done = 0,
nicholas@103 593 classCache = createCache(),
nicholas@103 594 tokenCache = createCache(),
nicholas@103 595 compilerCache = createCache(),
nicholas@103 596 sortOrder = function( a, b ) {
nicholas@103 597 if ( a === b ) {
nicholas@103 598 hasDuplicate = true;
nicholas@103 599 }
nicholas@103 600 return 0;
nicholas@103 601 },
nicholas@103 602
nicholas@103 603 // General-purpose constants
nicholas@103 604 MAX_NEGATIVE = 1 << 31,
nicholas@103 605
nicholas@103 606 // Instance methods
nicholas@103 607 hasOwn = ({}).hasOwnProperty,
nicholas@103 608 arr = [],
nicholas@103 609 pop = arr.pop,
nicholas@103 610 push_native = arr.push,
nicholas@103 611 push = arr.push,
nicholas@103 612 slice = arr.slice,
nicholas@103 613 // Use a stripped-down indexOf as it's faster than native
nicholas@103 614 // http://jsperf.com/thor-indexof-vs-for/5
nicholas@103 615 indexOf = function( list, elem ) {
nicholas@103 616 var i = 0,
nicholas@103 617 len = list.length;
nicholas@103 618 for ( ; i < len; i++ ) {
nicholas@103 619 if ( list[i] === elem ) {
nicholas@103 620 return i;
nicholas@103 621 }
nicholas@103 622 }
nicholas@103 623 return -1;
nicholas@103 624 },
nicholas@103 625
nicholas@103 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nicholas@103 627
nicholas@103 628 // Regular expressions
nicholas@103 629
nicholas@103 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nicholas@103 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nicholas@103 632 // http://www.w3.org/TR/css3-syntax/#characters
nicholas@103 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nicholas@103 634
nicholas@103 635 // Loosely modeled on CSS identifier characters
nicholas@103 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nicholas@103 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nicholas@103 638 identifier = characterEncoding.replace( "w", "w#" ),
nicholas@103 639
nicholas@103 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nicholas@103 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nicholas@103 642 // Operator (capture 2)
nicholas@103 643 "*([*^$|!~]?=)" + whitespace +
nicholas@103 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nicholas@103 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nicholas@103 646 "*\\]",
nicholas@103 647
nicholas@103 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nicholas@103 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nicholas@103 650 // 1. quoted (capture 3; capture 4 or capture 5)
nicholas@103 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nicholas@103 652 // 2. simple (capture 6)
nicholas@103 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nicholas@103 654 // 3. anything else (capture 2)
nicholas@103 655 ".*" +
nicholas@103 656 ")\\)|)",
nicholas@103 657
nicholas@103 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nicholas@103 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nicholas@103 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nicholas@103 661
nicholas@103 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nicholas@103 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nicholas@103 664
nicholas@103 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nicholas@103 666
nicholas@103 667 rpseudo = new RegExp( pseudos ),
nicholas@103 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nicholas@103 669
nicholas@103 670 matchExpr = {
nicholas@103 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nicholas@103 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nicholas@103 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nicholas@103 674 "ATTR": new RegExp( "^" + attributes ),
nicholas@103 675 "PSEUDO": new RegExp( "^" + pseudos ),
nicholas@103 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nicholas@103 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nicholas@103 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nicholas@103 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nicholas@103 680 // For use in libraries implementing .is()
nicholas@103 681 // We use this for POS matching in `select`
nicholas@103 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nicholas@103 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nicholas@103 684 },
nicholas@103 685
nicholas@103 686 rinputs = /^(?:input|select|textarea|button)$/i,
nicholas@103 687 rheader = /^h\d$/i,
nicholas@103 688
nicholas@103 689 rnative = /^[^{]+\{\s*\[native \w/,
nicholas@103 690
nicholas@103 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nicholas@103 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nicholas@103 693
nicholas@103 694 rsibling = /[+~]/,
nicholas@103 695 rescape = /'|\\/g,
nicholas@103 696
nicholas@103 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nicholas@103 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nicholas@103 699 funescape = function( _, escaped, escapedWhitespace ) {
nicholas@103 700 var high = "0x" + escaped - 0x10000;
nicholas@103 701 // NaN means non-codepoint
nicholas@103 702 // Support: Firefox<24
nicholas@103 703 // Workaround erroneous numeric interpretation of +"0x"
nicholas@103 704 return high !== high || escapedWhitespace ?
nicholas@103 705 escaped :
nicholas@103 706 high < 0 ?
nicholas@103 707 // BMP codepoint
nicholas@103 708 String.fromCharCode( high + 0x10000 ) :
nicholas@103 709 // Supplemental Plane codepoint (surrogate pair)
nicholas@103 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nicholas@103 711 },
nicholas@103 712
nicholas@103 713 // Used for iframes
nicholas@103 714 // See setDocument()
nicholas@103 715 // Removing the function wrapper causes a "Permission Denied"
nicholas@103 716 // error in IE
nicholas@103 717 unloadHandler = function() {
nicholas@103 718 setDocument();
nicholas@103 719 };
nicholas@103 720
nicholas@103 721 // Optimize for push.apply( _, NodeList )
nicholas@103 722 try {
nicholas@103 723 push.apply(
nicholas@103 724 (arr = slice.call( preferredDoc.childNodes )),
nicholas@103 725 preferredDoc.childNodes
nicholas@103 726 );
nicholas@103 727 // Support: Android<4.0
nicholas@103 728 // Detect silently failing push.apply
nicholas@103 729 arr[ preferredDoc.childNodes.length ].nodeType;
nicholas@103 730 } catch ( e ) {
nicholas@103 731 push = { apply: arr.length ?
nicholas@103 732
nicholas@103 733 // Leverage slice if possible
nicholas@103 734 function( target, els ) {
nicholas@103 735 push_native.apply( target, slice.call(els) );
nicholas@103 736 } :
nicholas@103 737
nicholas@103 738 // Support: IE<9
nicholas@103 739 // Otherwise append directly
nicholas@103 740 function( target, els ) {
nicholas@103 741 var j = target.length,
nicholas@103 742 i = 0;
nicholas@103 743 // Can't trust NodeList.length
nicholas@103 744 while ( (target[j++] = els[i++]) ) {}
nicholas@103 745 target.length = j - 1;
nicholas@103 746 }
nicholas@103 747 };
nicholas@103 748 }
nicholas@103 749
nicholas@103 750 function Sizzle( selector, context, results, seed ) {
nicholas@103 751 var match, elem, m, nodeType,
nicholas@103 752 // QSA vars
nicholas@103 753 i, groups, old, nid, newContext, newSelector;
nicholas@103 754
nicholas@103 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nicholas@103 756 setDocument( context );
nicholas@103 757 }
nicholas@103 758
nicholas@103 759 context = context || document;
nicholas@103 760 results = results || [];
nicholas@103 761 nodeType = context.nodeType;
nicholas@103 762
nicholas@103 763 if ( typeof selector !== "string" || !selector ||
nicholas@103 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nicholas@103 765
nicholas@103 766 return results;
nicholas@103 767 }
nicholas@103 768
nicholas@103 769 if ( !seed && documentIsHTML ) {
nicholas@103 770
nicholas@103 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nicholas@103 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nicholas@103 773 // Speed-up: Sizzle("#ID")
nicholas@103 774 if ( (m = match[1]) ) {
nicholas@103 775 if ( nodeType === 9 ) {
nicholas@103 776 elem = context.getElementById( m );
nicholas@103 777 // Check parentNode to catch when Blackberry 4.6 returns
nicholas@103 778 // nodes that are no longer in the document (jQuery #6963)
nicholas@103 779 if ( elem && elem.parentNode ) {
nicholas@103 780 // Handle the case where IE, Opera, and Webkit return items
nicholas@103 781 // by name instead of ID
nicholas@103 782 if ( elem.id === m ) {
nicholas@103 783 results.push( elem );
nicholas@103 784 return results;
nicholas@103 785 }
nicholas@103 786 } else {
nicholas@103 787 return results;
nicholas@103 788 }
nicholas@103 789 } else {
nicholas@103 790 // Context is not a document
nicholas@103 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nicholas@103 792 contains( context, elem ) && elem.id === m ) {
nicholas@103 793 results.push( elem );
nicholas@103 794 return results;
nicholas@103 795 }
nicholas@103 796 }
nicholas@103 797
nicholas@103 798 // Speed-up: Sizzle("TAG")
nicholas@103 799 } else if ( match[2] ) {
nicholas@103 800 push.apply( results, context.getElementsByTagName( selector ) );
nicholas@103 801 return results;
nicholas@103 802
nicholas@103 803 // Speed-up: Sizzle(".CLASS")
nicholas@103 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nicholas@103 805 push.apply( results, context.getElementsByClassName( m ) );
nicholas@103 806 return results;
nicholas@103 807 }
nicholas@103 808 }
nicholas@103 809
nicholas@103 810 // QSA path
nicholas@103 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nicholas@103 812 nid = old = expando;
nicholas@103 813 newContext = context;
nicholas@103 814 newSelector = nodeType !== 1 && selector;
nicholas@103 815
nicholas@103 816 // qSA works strangely on Element-rooted queries
nicholas@103 817 // We can work around this by specifying an extra ID on the root
nicholas@103 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nicholas@103 819 // IE 8 doesn't work on object elements
nicholas@103 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nicholas@103 821 groups = tokenize( selector );
nicholas@103 822
nicholas@103 823 if ( (old = context.getAttribute("id")) ) {
nicholas@103 824 nid = old.replace( rescape, "\\$&" );
nicholas@103 825 } else {
nicholas@103 826 context.setAttribute( "id", nid );
nicholas@103 827 }
nicholas@103 828 nid = "[id='" + nid + "'] ";
nicholas@103 829
nicholas@103 830 i = groups.length;
nicholas@103 831 while ( i-- ) {
nicholas@103 832 groups[i] = nid + toSelector( groups[i] );
nicholas@103 833 }
nicholas@103 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nicholas@103 835 newSelector = groups.join(",");
nicholas@103 836 }
nicholas@103 837
nicholas@103 838 if ( newSelector ) {
nicholas@103 839 try {
nicholas@103 840 push.apply( results,
nicholas@103 841 newContext.querySelectorAll( newSelector )
nicholas@103 842 );
nicholas@103 843 return results;
nicholas@103 844 } catch(qsaError) {
nicholas@103 845 } finally {
nicholas@103 846 if ( !old ) {
nicholas@103 847 context.removeAttribute("id");
nicholas@103 848 }
nicholas@103 849 }
nicholas@103 850 }
nicholas@103 851 }
nicholas@103 852 }
nicholas@103 853
nicholas@103 854 // All others
nicholas@103 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nicholas@103 856 }
nicholas@103 857
nicholas@103 858 /**
nicholas@103 859 * Create key-value caches of limited size
nicholas@103 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nicholas@103 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nicholas@103 862 * deleting the oldest entry
nicholas@103 863 */
nicholas@103 864 function createCache() {
nicholas@103 865 var keys = [];
nicholas@103 866
nicholas@103 867 function cache( key, value ) {
nicholas@103 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nicholas@103 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nicholas@103 870 // Only keep the most recent entries
nicholas@103 871 delete cache[ keys.shift() ];
nicholas@103 872 }
nicholas@103 873 return (cache[ key + " " ] = value);
nicholas@103 874 }
nicholas@103 875 return cache;
nicholas@103 876 }
nicholas@103 877
nicholas@103 878 /**
nicholas@103 879 * Mark a function for special use by Sizzle
nicholas@103 880 * @param {Function} fn The function to mark
nicholas@103 881 */
nicholas@103 882 function markFunction( fn ) {
nicholas@103 883 fn[ expando ] = true;
nicholas@103 884 return fn;
nicholas@103 885 }
nicholas@103 886
nicholas@103 887 /**
nicholas@103 888 * Support testing using an element
nicholas@103 889 * @param {Function} fn Passed the created div and expects a boolean result
nicholas@103 890 */
nicholas@103 891 function assert( fn ) {
nicholas@103 892 var div = document.createElement("div");
nicholas@103 893
nicholas@103 894 try {
nicholas@103 895 return !!fn( div );
nicholas@103 896 } catch (e) {
nicholas@103 897 return false;
nicholas@103 898 } finally {
nicholas@103 899 // Remove from its parent by default
nicholas@103 900 if ( div.parentNode ) {
nicholas@103 901 div.parentNode.removeChild( div );
nicholas@103 902 }
nicholas@103 903 // release memory in IE
nicholas@103 904 div = null;
nicholas@103 905 }
nicholas@103 906 }
nicholas@103 907
nicholas@103 908 /**
nicholas@103 909 * Adds the same handler for all of the specified attrs
nicholas@103 910 * @param {String} attrs Pipe-separated list of attributes
nicholas@103 911 * @param {Function} handler The method that will be applied
nicholas@103 912 */
nicholas@103 913 function addHandle( attrs, handler ) {
nicholas@103 914 var arr = attrs.split("|"),
nicholas@103 915 i = attrs.length;
nicholas@103 916
nicholas@103 917 while ( i-- ) {
nicholas@103 918 Expr.attrHandle[ arr[i] ] = handler;
nicholas@103 919 }
nicholas@103 920 }
nicholas@103 921
nicholas@103 922 /**
nicholas@103 923 * Checks document order of two siblings
nicholas@103 924 * @param {Element} a
nicholas@103 925 * @param {Element} b
nicholas@103 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nicholas@103 927 */
nicholas@103 928 function siblingCheck( a, b ) {
nicholas@103 929 var cur = b && a,
nicholas@103 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nicholas@103 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nicholas@103 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nicholas@103 933
nicholas@103 934 // Use IE sourceIndex if available on both nodes
nicholas@103 935 if ( diff ) {
nicholas@103 936 return diff;
nicholas@103 937 }
nicholas@103 938
nicholas@103 939 // Check if b follows a
nicholas@103 940 if ( cur ) {
nicholas@103 941 while ( (cur = cur.nextSibling) ) {
nicholas@103 942 if ( cur === b ) {
nicholas@103 943 return -1;
nicholas@103 944 }
nicholas@103 945 }
nicholas@103 946 }
nicholas@103 947
nicholas@103 948 return a ? 1 : -1;
nicholas@103 949 }
nicholas@103 950
nicholas@103 951 /**
nicholas@103 952 * Returns a function to use in pseudos for input types
nicholas@103 953 * @param {String} type
nicholas@103 954 */
nicholas@103 955 function createInputPseudo( type ) {
nicholas@103 956 return function( elem ) {
nicholas@103 957 var name = elem.nodeName.toLowerCase();
nicholas@103 958 return name === "input" && elem.type === type;
nicholas@103 959 };
nicholas@103 960 }
nicholas@103 961
nicholas@103 962 /**
nicholas@103 963 * Returns a function to use in pseudos for buttons
nicholas@103 964 * @param {String} type
nicholas@103 965 */
nicholas@103 966 function createButtonPseudo( type ) {
nicholas@103 967 return function( elem ) {
nicholas@103 968 var name = elem.nodeName.toLowerCase();
nicholas@103 969 return (name === "input" || name === "button") && elem.type === type;
nicholas@103 970 };
nicholas@103 971 }
nicholas@103 972
nicholas@103 973 /**
nicholas@103 974 * Returns a function to use in pseudos for positionals
nicholas@103 975 * @param {Function} fn
nicholas@103 976 */
nicholas@103 977 function createPositionalPseudo( fn ) {
nicholas@103 978 return markFunction(function( argument ) {
nicholas@103 979 argument = +argument;
nicholas@103 980 return markFunction(function( seed, matches ) {
nicholas@103 981 var j,
nicholas@103 982 matchIndexes = fn( [], seed.length, argument ),
nicholas@103 983 i = matchIndexes.length;
nicholas@103 984
nicholas@103 985 // Match elements found at the specified indexes
nicholas@103 986 while ( i-- ) {
nicholas@103 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nicholas@103 988 seed[j] = !(matches[j] = seed[j]);
nicholas@103 989 }
nicholas@103 990 }
nicholas@103 991 });
nicholas@103 992 });
nicholas@103 993 }
nicholas@103 994
nicholas@103 995 /**
nicholas@103 996 * Checks a node for validity as a Sizzle context
nicholas@103 997 * @param {Element|Object=} context
nicholas@103 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nicholas@103 999 */
nicholas@103 1000 function testContext( context ) {
nicholas@103 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nicholas@103 1002 }
nicholas@103 1003
nicholas@103 1004 // Expose support vars for convenience
nicholas@103 1005 support = Sizzle.support = {};
nicholas@103 1006
nicholas@103 1007 /**
nicholas@103 1008 * Detects XML nodes
nicholas@103 1009 * @param {Element|Object} elem An element or a document
nicholas@103 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nicholas@103 1011 */
nicholas@103 1012 isXML = Sizzle.isXML = function( elem ) {
nicholas@103 1013 // documentElement is verified for cases where it doesn't yet exist
nicholas@103 1014 // (such as loading iframes in IE - #4833)
nicholas@103 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nicholas@103 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nicholas@103 1017 };
nicholas@103 1018
nicholas@103 1019 /**
nicholas@103 1020 * Sets document-related variables once based on the current document
nicholas@103 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nicholas@103 1022 * @returns {Object} Returns the current document
nicholas@103 1023 */
nicholas@103 1024 setDocument = Sizzle.setDocument = function( node ) {
nicholas@103 1025 var hasCompare, parent,
nicholas@103 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nicholas@103 1027
nicholas@103 1028 // If no document and documentElement is available, return
nicholas@103 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nicholas@103 1030 return document;
nicholas@103 1031 }
nicholas@103 1032
nicholas@103 1033 // Set our document
nicholas@103 1034 document = doc;
nicholas@103 1035 docElem = doc.documentElement;
nicholas@103 1036 parent = doc.defaultView;
nicholas@103 1037
nicholas@103 1038 // Support: IE>8
nicholas@103 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nicholas@103 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nicholas@103 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nicholas@103 1042 if ( parent && parent !== parent.top ) {
nicholas@103 1043 // IE11 does not have attachEvent, so all must suffer
nicholas@103 1044 if ( parent.addEventListener ) {
nicholas@103 1045 parent.addEventListener( "unload", unloadHandler, false );
nicholas@103 1046 } else if ( parent.attachEvent ) {
nicholas@103 1047 parent.attachEvent( "onunload", unloadHandler );
nicholas@103 1048 }
nicholas@103 1049 }
nicholas@103 1050
nicholas@103 1051 /* Support tests
nicholas@103 1052 ---------------------------------------------------------------------- */
nicholas@103 1053 documentIsHTML = !isXML( doc );
nicholas@103 1054
nicholas@103 1055 /* Attributes
nicholas@103 1056 ---------------------------------------------------------------------- */
nicholas@103 1057
nicholas@103 1058 // Support: IE<8
nicholas@103 1059 // Verify that getAttribute really returns attributes and not properties
nicholas@103 1060 // (excepting IE8 booleans)
nicholas@103 1061 support.attributes = assert(function( div ) {
nicholas@103 1062 div.className = "i";
nicholas@103 1063 return !div.getAttribute("className");
nicholas@103 1064 });
nicholas@103 1065
nicholas@103 1066 /* getElement(s)By*
nicholas@103 1067 ---------------------------------------------------------------------- */
nicholas@103 1068
nicholas@103 1069 // Check if getElementsByTagName("*") returns only elements
nicholas@103 1070 support.getElementsByTagName = assert(function( div ) {
nicholas@103 1071 div.appendChild( doc.createComment("") );
nicholas@103 1072 return !div.getElementsByTagName("*").length;
nicholas@103 1073 });
nicholas@103 1074
nicholas@103 1075 // Support: IE<9
nicholas@103 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nicholas@103 1077
nicholas@103 1078 // Support: IE<10
nicholas@103 1079 // Check if getElementById returns elements by name
nicholas@103 1080 // The broken getElementById methods don't pick up programatically-set names,
nicholas@103 1081 // so use a roundabout getElementsByName test
nicholas@103 1082 support.getById = assert(function( div ) {
nicholas@103 1083 docElem.appendChild( div ).id = expando;
nicholas@103 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nicholas@103 1085 });
nicholas@103 1086
nicholas@103 1087 // ID find and filter
nicholas@103 1088 if ( support.getById ) {
nicholas@103 1089 Expr.find["ID"] = function( id, context ) {
nicholas@103 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nicholas@103 1091 var m = context.getElementById( id );
nicholas@103 1092 // Check parentNode to catch when Blackberry 4.6 returns
nicholas@103 1093 // nodes that are no longer in the document #6963
nicholas@103 1094 return m && m.parentNode ? [ m ] : [];
nicholas@103 1095 }
nicholas@103 1096 };
nicholas@103 1097 Expr.filter["ID"] = function( id ) {
nicholas@103 1098 var attrId = id.replace( runescape, funescape );
nicholas@103 1099 return function( elem ) {
nicholas@103 1100 return elem.getAttribute("id") === attrId;
nicholas@103 1101 };
nicholas@103 1102 };
nicholas@103 1103 } else {
nicholas@103 1104 // Support: IE6/7
nicholas@103 1105 // getElementById is not reliable as a find shortcut
nicholas@103 1106 delete Expr.find["ID"];
nicholas@103 1107
nicholas@103 1108 Expr.filter["ID"] = function( id ) {
nicholas@103 1109 var attrId = id.replace( runescape, funescape );
nicholas@103 1110 return function( elem ) {
nicholas@103 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nicholas@103 1112 return node && node.value === attrId;
nicholas@103 1113 };
nicholas@103 1114 };
nicholas@103 1115 }
nicholas@103 1116
nicholas@103 1117 // Tag
nicholas@103 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nicholas@103 1119 function( tag, context ) {
nicholas@103 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nicholas@103 1121 return context.getElementsByTagName( tag );
nicholas@103 1122
nicholas@103 1123 // DocumentFragment nodes don't have gEBTN
nicholas@103 1124 } else if ( support.qsa ) {
nicholas@103 1125 return context.querySelectorAll( tag );
nicholas@103 1126 }
nicholas@103 1127 } :
nicholas@103 1128
nicholas@103 1129 function( tag, context ) {
nicholas@103 1130 var elem,
nicholas@103 1131 tmp = [],
nicholas@103 1132 i = 0,
nicholas@103 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nicholas@103 1134 results = context.getElementsByTagName( tag );
nicholas@103 1135
nicholas@103 1136 // Filter out possible comments
nicholas@103 1137 if ( tag === "*" ) {
nicholas@103 1138 while ( (elem = results[i++]) ) {
nicholas@103 1139 if ( elem.nodeType === 1 ) {
nicholas@103 1140 tmp.push( elem );
nicholas@103 1141 }
nicholas@103 1142 }
nicholas@103 1143
nicholas@103 1144 return tmp;
nicholas@103 1145 }
nicholas@103 1146 return results;
nicholas@103 1147 };
nicholas@103 1148
nicholas@103 1149 // Class
nicholas@103 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nicholas@103 1151 if ( documentIsHTML ) {
nicholas@103 1152 return context.getElementsByClassName( className );
nicholas@103 1153 }
nicholas@103 1154 };
nicholas@103 1155
nicholas@103 1156 /* QSA/matchesSelector
nicholas@103 1157 ---------------------------------------------------------------------- */
nicholas@103 1158
nicholas@103 1159 // QSA and matchesSelector support
nicholas@103 1160
nicholas@103 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nicholas@103 1162 rbuggyMatches = [];
nicholas@103 1163
nicholas@103 1164 // qSa(:focus) reports false when true (Chrome 21)
nicholas@103 1165 // We allow this because of a bug in IE8/9 that throws an error
nicholas@103 1166 // whenever `document.activeElement` is accessed on an iframe
nicholas@103 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nicholas@103 1168 // See http://bugs.jquery.com/ticket/13378
nicholas@103 1169 rbuggyQSA = [];
nicholas@103 1170
nicholas@103 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nicholas@103 1172 // Build QSA regex
nicholas@103 1173 // Regex strategy adopted from Diego Perini
nicholas@103 1174 assert(function( div ) {
nicholas@103 1175 // Select is set to empty string on purpose
nicholas@103 1176 // This is to test IE's treatment of not explicitly
nicholas@103 1177 // setting a boolean content attribute,
nicholas@103 1178 // since its presence should be enough
nicholas@103 1179 // http://bugs.jquery.com/ticket/12359
nicholas@103 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nicholas@103 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nicholas@103 1182 "<option selected=''></option></select>";
nicholas@103 1183
nicholas@103 1184 // Support: IE8, Opera 11-12.16
nicholas@103 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nicholas@103 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nicholas@103 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nicholas@103 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nicholas@103 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nicholas@103 1190 }
nicholas@103 1191
nicholas@103 1192 // Support: IE8
nicholas@103 1193 // Boolean attributes and "value" are not treated correctly
nicholas@103 1194 if ( !div.querySelectorAll("[selected]").length ) {
nicholas@103 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nicholas@103 1196 }
nicholas@103 1197
nicholas@103 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nicholas@103 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nicholas@103 1200 rbuggyQSA.push("~=");
nicholas@103 1201 }
nicholas@103 1202
nicholas@103 1203 // Webkit/Opera - :checked should return selected option elements
nicholas@103 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nicholas@103 1205 // IE8 throws error here and will not see later tests
nicholas@103 1206 if ( !div.querySelectorAll(":checked").length ) {
nicholas@103 1207 rbuggyQSA.push(":checked");
nicholas@103 1208 }
nicholas@103 1209
nicholas@103 1210 // Support: Safari 8+, iOS 8+
nicholas@103 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nicholas@103 1212 // In-page `selector#id sibing-combinator selector` fails
nicholas@103 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nicholas@103 1214 rbuggyQSA.push(".#.+[+~]");
nicholas@103 1215 }
nicholas@103 1216 });
nicholas@103 1217
nicholas@103 1218 assert(function( div ) {
nicholas@103 1219 // Support: Windows 8 Native Apps
nicholas@103 1220 // The type and name attributes are restricted during .innerHTML assignment
nicholas@103 1221 var input = doc.createElement("input");
nicholas@103 1222 input.setAttribute( "type", "hidden" );
nicholas@103 1223 div.appendChild( input ).setAttribute( "name", "D" );
nicholas@103 1224
nicholas@103 1225 // Support: IE8
nicholas@103 1226 // Enforce case-sensitivity of name attribute
nicholas@103 1227 if ( div.querySelectorAll("[name=d]").length ) {
nicholas@103 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nicholas@103 1229 }
nicholas@103 1230
nicholas@103 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nicholas@103 1232 // IE8 throws error here and will not see later tests
nicholas@103 1233 if ( !div.querySelectorAll(":enabled").length ) {
nicholas@103 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nicholas@103 1235 }
nicholas@103 1236
nicholas@103 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nicholas@103 1238 div.querySelectorAll("*,:x");
nicholas@103 1239 rbuggyQSA.push(",.*:");
nicholas@103 1240 });
nicholas@103 1241 }
nicholas@103 1242
nicholas@103 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nicholas@103 1244 docElem.webkitMatchesSelector ||
nicholas@103 1245 docElem.mozMatchesSelector ||
nicholas@103 1246 docElem.oMatchesSelector ||
nicholas@103 1247 docElem.msMatchesSelector) )) ) {
nicholas@103 1248
nicholas@103 1249 assert(function( div ) {
nicholas@103 1250 // Check to see if it's possible to do matchesSelector
nicholas@103 1251 // on a disconnected node (IE 9)
nicholas@103 1252 support.disconnectedMatch = matches.call( div, "div" );
nicholas@103 1253
nicholas@103 1254 // This should fail with an exception
nicholas@103 1255 // Gecko does not error, returns false instead
nicholas@103 1256 matches.call( div, "[s!='']:x" );
nicholas@103 1257 rbuggyMatches.push( "!=", pseudos );
nicholas@103 1258 });
nicholas@103 1259 }
nicholas@103 1260
nicholas@103 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nicholas@103 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nicholas@103 1263
nicholas@103 1264 /* Contains
nicholas@103 1265 ---------------------------------------------------------------------- */
nicholas@103 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nicholas@103 1267
nicholas@103 1268 // Element contains another
nicholas@103 1269 // Purposefully does not implement inclusive descendent
nicholas@103 1270 // As in, an element does not contain itself
nicholas@103 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nicholas@103 1272 function( a, b ) {
nicholas@103 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nicholas@103 1274 bup = b && b.parentNode;
nicholas@103 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nicholas@103 1276 adown.contains ?
nicholas@103 1277 adown.contains( bup ) :
nicholas@103 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nicholas@103 1279 ));
nicholas@103 1280 } :
nicholas@103 1281 function( a, b ) {
nicholas@103 1282 if ( b ) {
nicholas@103 1283 while ( (b = b.parentNode) ) {
nicholas@103 1284 if ( b === a ) {
nicholas@103 1285 return true;
nicholas@103 1286 }
nicholas@103 1287 }
nicholas@103 1288 }
nicholas@103 1289 return false;
nicholas@103 1290 };
nicholas@103 1291
nicholas@103 1292 /* Sorting
nicholas@103 1293 ---------------------------------------------------------------------- */
nicholas@103 1294
nicholas@103 1295 // Document order sorting
nicholas@103 1296 sortOrder = hasCompare ?
nicholas@103 1297 function( a, b ) {
nicholas@103 1298
nicholas@103 1299 // Flag for duplicate removal
nicholas@103 1300 if ( a === b ) {
nicholas@103 1301 hasDuplicate = true;
nicholas@103 1302 return 0;
nicholas@103 1303 }
nicholas@103 1304
nicholas@103 1305 // Sort on method existence if only one input has compareDocumentPosition
nicholas@103 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nicholas@103 1307 if ( compare ) {
nicholas@103 1308 return compare;
nicholas@103 1309 }
nicholas@103 1310
nicholas@103 1311 // Calculate position if both inputs belong to the same document
nicholas@103 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nicholas@103 1313 a.compareDocumentPosition( b ) :
nicholas@103 1314
nicholas@103 1315 // Otherwise we know they are disconnected
nicholas@103 1316 1;
nicholas@103 1317
nicholas@103 1318 // Disconnected nodes
nicholas@103 1319 if ( compare & 1 ||
nicholas@103 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nicholas@103 1321
nicholas@103 1322 // Choose the first element that is related to our preferred document
nicholas@103 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nicholas@103 1324 return -1;
nicholas@103 1325 }
nicholas@103 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nicholas@103 1327 return 1;
nicholas@103 1328 }
nicholas@103 1329
nicholas@103 1330 // Maintain original order
nicholas@103 1331 return sortInput ?
nicholas@103 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nicholas@103 1333 0;
nicholas@103 1334 }
nicholas@103 1335
nicholas@103 1336 return compare & 4 ? -1 : 1;
nicholas@103 1337 } :
nicholas@103 1338 function( a, b ) {
nicholas@103 1339 // Exit early if the nodes are identical
nicholas@103 1340 if ( a === b ) {
nicholas@103 1341 hasDuplicate = true;
nicholas@103 1342 return 0;
nicholas@103 1343 }
nicholas@103 1344
nicholas@103 1345 var cur,
nicholas@103 1346 i = 0,
nicholas@103 1347 aup = a.parentNode,
nicholas@103 1348 bup = b.parentNode,
nicholas@103 1349 ap = [ a ],
nicholas@103 1350 bp = [ b ];
nicholas@103 1351
nicholas@103 1352 // Parentless nodes are either documents or disconnected
nicholas@103 1353 if ( !aup || !bup ) {
nicholas@103 1354 return a === doc ? -1 :
nicholas@103 1355 b === doc ? 1 :
nicholas@103 1356 aup ? -1 :
nicholas@103 1357 bup ? 1 :
nicholas@103 1358 sortInput ?
nicholas@103 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nicholas@103 1360 0;
nicholas@103 1361
nicholas@103 1362 // If the nodes are siblings, we can do a quick check
nicholas@103 1363 } else if ( aup === bup ) {
nicholas@103 1364 return siblingCheck( a, b );
nicholas@103 1365 }
nicholas@103 1366
nicholas@103 1367 // Otherwise we need full lists of their ancestors for comparison
nicholas@103 1368 cur = a;
nicholas@103 1369 while ( (cur = cur.parentNode) ) {
nicholas@103 1370 ap.unshift( cur );
nicholas@103 1371 }
nicholas@103 1372 cur = b;
nicholas@103 1373 while ( (cur = cur.parentNode) ) {
nicholas@103 1374 bp.unshift( cur );
nicholas@103 1375 }
nicholas@103 1376
nicholas@103 1377 // Walk down the tree looking for a discrepancy
nicholas@103 1378 while ( ap[i] === bp[i] ) {
nicholas@103 1379 i++;
nicholas@103 1380 }
nicholas@103 1381
nicholas@103 1382 return i ?
nicholas@103 1383 // Do a sibling check if the nodes have a common ancestor
nicholas@103 1384 siblingCheck( ap[i], bp[i] ) :
nicholas@103 1385
nicholas@103 1386 // Otherwise nodes in our document sort first
nicholas@103 1387 ap[i] === preferredDoc ? -1 :
nicholas@103 1388 bp[i] === preferredDoc ? 1 :
nicholas@103 1389 0;
nicholas@103 1390 };
nicholas@103 1391
nicholas@103 1392 return doc;
nicholas@103 1393 };
nicholas@103 1394
nicholas@103 1395 Sizzle.matches = function( expr, elements ) {
nicholas@103 1396 return Sizzle( expr, null, null, elements );
nicholas@103 1397 };
nicholas@103 1398
nicholas@103 1399 Sizzle.matchesSelector = function( elem, expr ) {
nicholas@103 1400 // Set document vars if needed
nicholas@103 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nicholas@103 1402 setDocument( elem );
nicholas@103 1403 }
nicholas@103 1404
nicholas@103 1405 // Make sure that attribute selectors are quoted
nicholas@103 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nicholas@103 1407
nicholas@103 1408 if ( support.matchesSelector && documentIsHTML &&
nicholas@103 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nicholas@103 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nicholas@103 1411
nicholas@103 1412 try {
nicholas@103 1413 var ret = matches.call( elem, expr );
nicholas@103 1414
nicholas@103 1415 // IE 9's matchesSelector returns false on disconnected nodes
nicholas@103 1416 if ( ret || support.disconnectedMatch ||
nicholas@103 1417 // As well, disconnected nodes are said to be in a document
nicholas@103 1418 // fragment in IE 9
nicholas@103 1419 elem.document && elem.document.nodeType !== 11 ) {
nicholas@103 1420 return ret;
nicholas@103 1421 }
nicholas@103 1422 } catch (e) {}
nicholas@103 1423 }
nicholas@103 1424
nicholas@103 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nicholas@103 1426 };
nicholas@103 1427
nicholas@103 1428 Sizzle.contains = function( context, elem ) {
nicholas@103 1429 // Set document vars if needed
nicholas@103 1430 if ( ( context.ownerDocument || context ) !== document ) {
nicholas@103 1431 setDocument( context );
nicholas@103 1432 }
nicholas@103 1433 return contains( context, elem );
nicholas@103 1434 };
nicholas@103 1435
nicholas@103 1436 Sizzle.attr = function( elem, name ) {
nicholas@103 1437 // Set document vars if needed
nicholas@103 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nicholas@103 1439 setDocument( elem );
nicholas@103 1440 }
nicholas@103 1441
nicholas@103 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nicholas@103 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nicholas@103 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nicholas@103 1445 fn( elem, name, !documentIsHTML ) :
nicholas@103 1446 undefined;
nicholas@103 1447
nicholas@103 1448 return val !== undefined ?
nicholas@103 1449 val :
nicholas@103 1450 support.attributes || !documentIsHTML ?
nicholas@103 1451 elem.getAttribute( name ) :
nicholas@103 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nicholas@103 1453 val.value :
nicholas@103 1454 null;
nicholas@103 1455 };
nicholas@103 1456
nicholas@103 1457 Sizzle.error = function( msg ) {
nicholas@103 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nicholas@103 1459 };
nicholas@103 1460
nicholas@103 1461 /**
nicholas@103 1462 * Document sorting and removing duplicates
nicholas@103 1463 * @param {ArrayLike} results
nicholas@103 1464 */
nicholas@103 1465 Sizzle.uniqueSort = function( results ) {
nicholas@103 1466 var elem,
nicholas@103 1467 duplicates = [],
nicholas@103 1468 j = 0,
nicholas@103 1469 i = 0;
nicholas@103 1470
nicholas@103 1471 // Unless we *know* we can detect duplicates, assume their presence
nicholas@103 1472 hasDuplicate = !support.detectDuplicates;
nicholas@103 1473 sortInput = !support.sortStable && results.slice( 0 );
nicholas@103 1474 results.sort( sortOrder );
nicholas@103 1475
nicholas@103 1476 if ( hasDuplicate ) {
nicholas@103 1477 while ( (elem = results[i++]) ) {
nicholas@103 1478 if ( elem === results[ i ] ) {
nicholas@103 1479 j = duplicates.push( i );
nicholas@103 1480 }
nicholas@103 1481 }
nicholas@103 1482 while ( j-- ) {
nicholas@103 1483 results.splice( duplicates[ j ], 1 );
nicholas@103 1484 }
nicholas@103 1485 }
nicholas@103 1486
nicholas@103 1487 // Clear input after sorting to release objects
nicholas@103 1488 // See https://github.com/jquery/sizzle/pull/225
nicholas@103 1489 sortInput = null;
nicholas@103 1490
nicholas@103 1491 return results;
nicholas@103 1492 };
nicholas@103 1493
nicholas@103 1494 /**
nicholas@103 1495 * Utility function for retrieving the text value of an array of DOM nodes
nicholas@103 1496 * @param {Array|Element} elem
nicholas@103 1497 */
nicholas@103 1498 getText = Sizzle.getText = function( elem ) {
nicholas@103 1499 var node,
nicholas@103 1500 ret = "",
nicholas@103 1501 i = 0,
nicholas@103 1502 nodeType = elem.nodeType;
nicholas@103 1503
nicholas@103 1504 if ( !nodeType ) {
nicholas@103 1505 // If no nodeType, this is expected to be an array
nicholas@103 1506 while ( (node = elem[i++]) ) {
nicholas@103 1507 // Do not traverse comment nodes
nicholas@103 1508 ret += getText( node );
nicholas@103 1509 }
nicholas@103 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nicholas@103 1511 // Use textContent for elements
nicholas@103 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nicholas@103 1513 if ( typeof elem.textContent === "string" ) {
nicholas@103 1514 return elem.textContent;
nicholas@103 1515 } else {
nicholas@103 1516 // Traverse its children
nicholas@103 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nicholas@103 1518 ret += getText( elem );
nicholas@103 1519 }
nicholas@103 1520 }
nicholas@103 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nicholas@103 1522 return elem.nodeValue;
nicholas@103 1523 }
nicholas@103 1524 // Do not include comment or processing instruction nodes
nicholas@103 1525
nicholas@103 1526 return ret;
nicholas@103 1527 };
nicholas@103 1528
nicholas@103 1529 Expr = Sizzle.selectors = {
nicholas@103 1530
nicholas@103 1531 // Can be adjusted by the user
nicholas@103 1532 cacheLength: 50,
nicholas@103 1533
nicholas@103 1534 createPseudo: markFunction,
nicholas@103 1535
nicholas@103 1536 match: matchExpr,
nicholas@103 1537
nicholas@103 1538 attrHandle: {},
nicholas@103 1539
nicholas@103 1540 find: {},
nicholas@103 1541
nicholas@103 1542 relative: {
nicholas@103 1543 ">": { dir: "parentNode", first: true },
nicholas@103 1544 " ": { dir: "parentNode" },
nicholas@103 1545 "+": { dir: "previousSibling", first: true },
nicholas@103 1546 "~": { dir: "previousSibling" }
nicholas@103 1547 },
nicholas@103 1548
nicholas@103 1549 preFilter: {
nicholas@103 1550 "ATTR": function( match ) {
nicholas@103 1551 match[1] = match[1].replace( runescape, funescape );
nicholas@103 1552
nicholas@103 1553 // Move the given value to match[3] whether quoted or unquoted
nicholas@103 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nicholas@103 1555
nicholas@103 1556 if ( match[2] === "~=" ) {
nicholas@103 1557 match[3] = " " + match[3] + " ";
nicholas@103 1558 }
nicholas@103 1559
nicholas@103 1560 return match.slice( 0, 4 );
nicholas@103 1561 },
nicholas@103 1562
nicholas@103 1563 "CHILD": function( match ) {
nicholas@103 1564 /* matches from matchExpr["CHILD"]
nicholas@103 1565 1 type (only|nth|...)
nicholas@103 1566 2 what (child|of-type)
nicholas@103 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nicholas@103 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nicholas@103 1569 5 sign of xn-component
nicholas@103 1570 6 x of xn-component
nicholas@103 1571 7 sign of y-component
nicholas@103 1572 8 y of y-component
nicholas@103 1573 */
nicholas@103 1574 match[1] = match[1].toLowerCase();
nicholas@103 1575
nicholas@103 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nicholas@103 1577 // nth-* requires argument
nicholas@103 1578 if ( !match[3] ) {
nicholas@103 1579 Sizzle.error( match[0] );
nicholas@103 1580 }
nicholas@103 1581
nicholas@103 1582 // numeric x and y parameters for Expr.filter.CHILD
nicholas@103 1583 // remember that false/true cast respectively to 0/1
nicholas@103 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nicholas@103 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nicholas@103 1586
nicholas@103 1587 // other types prohibit arguments
nicholas@103 1588 } else if ( match[3] ) {
nicholas@103 1589 Sizzle.error( match[0] );
nicholas@103 1590 }
nicholas@103 1591
nicholas@103 1592 return match;
nicholas@103 1593 },
nicholas@103 1594
nicholas@103 1595 "PSEUDO": function( match ) {
nicholas@103 1596 var excess,
nicholas@103 1597 unquoted = !match[6] && match[2];
nicholas@103 1598
nicholas@103 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nicholas@103 1600 return null;
nicholas@103 1601 }
nicholas@103 1602
nicholas@103 1603 // Accept quoted arguments as-is
nicholas@103 1604 if ( match[3] ) {
nicholas@103 1605 match[2] = match[4] || match[5] || "";
nicholas@103 1606
nicholas@103 1607 // Strip excess characters from unquoted arguments
nicholas@103 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nicholas@103 1609 // Get excess from tokenize (recursively)
nicholas@103 1610 (excess = tokenize( unquoted, true )) &&
nicholas@103 1611 // advance to the next closing parenthesis
nicholas@103 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nicholas@103 1613
nicholas@103 1614 // excess is a negative index
nicholas@103 1615 match[0] = match[0].slice( 0, excess );
nicholas@103 1616 match[2] = unquoted.slice( 0, excess );
nicholas@103 1617 }
nicholas@103 1618
nicholas@103 1619 // Return only captures needed by the pseudo filter method (type and argument)
nicholas@103 1620 return match.slice( 0, 3 );
nicholas@103 1621 }
nicholas@103 1622 },
nicholas@103 1623
nicholas@103 1624 filter: {
nicholas@103 1625
nicholas@103 1626 "TAG": function( nodeNameSelector ) {
nicholas@103 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nicholas@103 1628 return nodeNameSelector === "*" ?
nicholas@103 1629 function() { return true; } :
nicholas@103 1630 function( elem ) {
nicholas@103 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nicholas@103 1632 };
nicholas@103 1633 },
nicholas@103 1634
nicholas@103 1635 "CLASS": function( className ) {
nicholas@103 1636 var pattern = classCache[ className + " " ];
nicholas@103 1637
nicholas@103 1638 return pattern ||
nicholas@103 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nicholas@103 1640 classCache( className, function( elem ) {
nicholas@103 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nicholas@103 1642 });
nicholas@103 1643 },
nicholas@103 1644
nicholas@103 1645 "ATTR": function( name, operator, check ) {
nicholas@103 1646 return function( elem ) {
nicholas@103 1647 var result = Sizzle.attr( elem, name );
nicholas@103 1648
nicholas@103 1649 if ( result == null ) {
nicholas@103 1650 return operator === "!=";
nicholas@103 1651 }
nicholas@103 1652 if ( !operator ) {
nicholas@103 1653 return true;
nicholas@103 1654 }
nicholas@103 1655
nicholas@103 1656 result += "";
nicholas@103 1657
nicholas@103 1658 return operator === "=" ? result === check :
nicholas@103 1659 operator === "!=" ? result !== check :
nicholas@103 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nicholas@103 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nicholas@103 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nicholas@103 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nicholas@103 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nicholas@103 1665 false;
nicholas@103 1666 };
nicholas@103 1667 },
nicholas@103 1668
nicholas@103 1669 "CHILD": function( type, what, argument, first, last ) {
nicholas@103 1670 var simple = type.slice( 0, 3 ) !== "nth",
nicholas@103 1671 forward = type.slice( -4 ) !== "last",
nicholas@103 1672 ofType = what === "of-type";
nicholas@103 1673
nicholas@103 1674 return first === 1 && last === 0 ?
nicholas@103 1675
nicholas@103 1676 // Shortcut for :nth-*(n)
nicholas@103 1677 function( elem ) {
nicholas@103 1678 return !!elem.parentNode;
nicholas@103 1679 } :
nicholas@103 1680
nicholas@103 1681 function( elem, context, xml ) {
nicholas@103 1682 var cache, outerCache, node, diff, nodeIndex, start,
nicholas@103 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nicholas@103 1684 parent = elem.parentNode,
nicholas@103 1685 name = ofType && elem.nodeName.toLowerCase(),
nicholas@103 1686 useCache = !xml && !ofType;
nicholas@103 1687
nicholas@103 1688 if ( parent ) {
nicholas@103 1689
nicholas@103 1690 // :(first|last|only)-(child|of-type)
nicholas@103 1691 if ( simple ) {
nicholas@103 1692 while ( dir ) {
nicholas@103 1693 node = elem;
nicholas@103 1694 while ( (node = node[ dir ]) ) {
nicholas@103 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nicholas@103 1696 return false;
nicholas@103 1697 }
nicholas@103 1698 }
nicholas@103 1699 // Reverse direction for :only-* (if we haven't yet done so)
nicholas@103 1700 start = dir = type === "only" && !start && "nextSibling";
nicholas@103 1701 }
nicholas@103 1702 return true;
nicholas@103 1703 }
nicholas@103 1704
nicholas@103 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nicholas@103 1706
nicholas@103 1707 // non-xml :nth-child(...) stores cache data on `parent`
nicholas@103 1708 if ( forward && useCache ) {
nicholas@103 1709 // Seek `elem` from a previously-cached index
nicholas@103 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nicholas@103 1711 cache = outerCache[ type ] || [];
nicholas@103 1712 nodeIndex = cache[0] === dirruns && cache[1];
nicholas@103 1713 diff = cache[0] === dirruns && cache[2];
nicholas@103 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nicholas@103 1715
nicholas@103 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nicholas@103 1717
nicholas@103 1718 // Fallback to seeking `elem` from the start
nicholas@103 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nicholas@103 1720
nicholas@103 1721 // When found, cache indexes on `parent` and break
nicholas@103 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nicholas@103 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nicholas@103 1724 break;
nicholas@103 1725 }
nicholas@103 1726 }
nicholas@103 1727
nicholas@103 1728 // Use previously-cached element index if available
nicholas@103 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nicholas@103 1730 diff = cache[1];
nicholas@103 1731
nicholas@103 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nicholas@103 1733 } else {
nicholas@103 1734 // Use the same loop as above to seek `elem` from the start
nicholas@103 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nicholas@103 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nicholas@103 1737
nicholas@103 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nicholas@103 1739 // Cache the index of each encountered element
nicholas@103 1740 if ( useCache ) {
nicholas@103 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nicholas@103 1742 }
nicholas@103 1743
nicholas@103 1744 if ( node === elem ) {
nicholas@103 1745 break;
nicholas@103 1746 }
nicholas@103 1747 }
nicholas@103 1748 }
nicholas@103 1749 }
nicholas@103 1750
nicholas@103 1751 // Incorporate the offset, then check against cycle size
nicholas@103 1752 diff -= last;
nicholas@103 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nicholas@103 1754 }
nicholas@103 1755 };
nicholas@103 1756 },
nicholas@103 1757
nicholas@103 1758 "PSEUDO": function( pseudo, argument ) {
nicholas@103 1759 // pseudo-class names are case-insensitive
nicholas@103 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nicholas@103 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nicholas@103 1762 // Remember that setFilters inherits from pseudos
nicholas@103 1763 var args,
nicholas@103 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nicholas@103 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nicholas@103 1766
nicholas@103 1767 // The user may use createPseudo to indicate that
nicholas@103 1768 // arguments are needed to create the filter function
nicholas@103 1769 // just as Sizzle does
nicholas@103 1770 if ( fn[ expando ] ) {
nicholas@103 1771 return fn( argument );
nicholas@103 1772 }
nicholas@103 1773
nicholas@103 1774 // But maintain support for old signatures
nicholas@103 1775 if ( fn.length > 1 ) {
nicholas@103 1776 args = [ pseudo, pseudo, "", argument ];
nicholas@103 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nicholas@103 1778 markFunction(function( seed, matches ) {
nicholas@103 1779 var idx,
nicholas@103 1780 matched = fn( seed, argument ),
nicholas@103 1781 i = matched.length;
nicholas@103 1782 while ( i-- ) {
nicholas@103 1783 idx = indexOf( seed, matched[i] );
nicholas@103 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nicholas@103 1785 }
nicholas@103 1786 }) :
nicholas@103 1787 function( elem ) {
nicholas@103 1788 return fn( elem, 0, args );
nicholas@103 1789 };
nicholas@103 1790 }
nicholas@103 1791
nicholas@103 1792 return fn;
nicholas@103 1793 }
nicholas@103 1794 },
nicholas@103 1795
nicholas@103 1796 pseudos: {
nicholas@103 1797 // Potentially complex pseudos
nicholas@103 1798 "not": markFunction(function( selector ) {
nicholas@103 1799 // Trim the selector passed to compile
nicholas@103 1800 // to avoid treating leading and trailing
nicholas@103 1801 // spaces as combinators
nicholas@103 1802 var input = [],
nicholas@103 1803 results = [],
nicholas@103 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nicholas@103 1805
nicholas@103 1806 return matcher[ expando ] ?
nicholas@103 1807 markFunction(function( seed, matches, context, xml ) {
nicholas@103 1808 var elem,
nicholas@103 1809 unmatched = matcher( seed, null, xml, [] ),
nicholas@103 1810 i = seed.length;
nicholas@103 1811
nicholas@103 1812 // Match elements unmatched by `matcher`
nicholas@103 1813 while ( i-- ) {
nicholas@103 1814 if ( (elem = unmatched[i]) ) {
nicholas@103 1815 seed[i] = !(matches[i] = elem);
nicholas@103 1816 }
nicholas@103 1817 }
nicholas@103 1818 }) :
nicholas@103 1819 function( elem, context, xml ) {
nicholas@103 1820 input[0] = elem;
nicholas@103 1821 matcher( input, null, xml, results );
nicholas@103 1822 // Don't keep the element (issue #299)
nicholas@103 1823 input[0] = null;
nicholas@103 1824 return !results.pop();
nicholas@103 1825 };
nicholas@103 1826 }),
nicholas@103 1827
nicholas@103 1828 "has": markFunction(function( selector ) {
nicholas@103 1829 return function( elem ) {
nicholas@103 1830 return Sizzle( selector, elem ).length > 0;
nicholas@103 1831 };
nicholas@103 1832 }),
nicholas@103 1833
nicholas@103 1834 "contains": markFunction(function( text ) {
nicholas@103 1835 text = text.replace( runescape, funescape );
nicholas@103 1836 return function( elem ) {
nicholas@103 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nicholas@103 1838 };
nicholas@103 1839 }),
nicholas@103 1840
nicholas@103 1841 // "Whether an element is represented by a :lang() selector
nicholas@103 1842 // is based solely on the element's language value
nicholas@103 1843 // being equal to the identifier C,
nicholas@103 1844 // or beginning with the identifier C immediately followed by "-".
nicholas@103 1845 // The matching of C against the element's language value is performed case-insensitively.
nicholas@103 1846 // The identifier C does not have to be a valid language name."
nicholas@103 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nicholas@103 1848 "lang": markFunction( function( lang ) {
nicholas@103 1849 // lang value must be a valid identifier
nicholas@103 1850 if ( !ridentifier.test(lang || "") ) {
nicholas@103 1851 Sizzle.error( "unsupported lang: " + lang );
nicholas@103 1852 }
nicholas@103 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nicholas@103 1854 return function( elem ) {
nicholas@103 1855 var elemLang;
nicholas@103 1856 do {
nicholas@103 1857 if ( (elemLang = documentIsHTML ?
nicholas@103 1858 elem.lang :
nicholas@103 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nicholas@103 1860
nicholas@103 1861 elemLang = elemLang.toLowerCase();
nicholas@103 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nicholas@103 1863 }
nicholas@103 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nicholas@103 1865 return false;
nicholas@103 1866 };
nicholas@103 1867 }),
nicholas@103 1868
nicholas@103 1869 // Miscellaneous
nicholas@103 1870 "target": function( elem ) {
nicholas@103 1871 var hash = window.location && window.location.hash;
nicholas@103 1872 return hash && hash.slice( 1 ) === elem.id;
nicholas@103 1873 },
nicholas@103 1874
nicholas@103 1875 "root": function( elem ) {
nicholas@103 1876 return elem === docElem;
nicholas@103 1877 },
nicholas@103 1878
nicholas@103 1879 "focus": function( elem ) {
nicholas@103 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nicholas@103 1881 },
nicholas@103 1882
nicholas@103 1883 // Boolean properties
nicholas@103 1884 "enabled": function( elem ) {
nicholas@103 1885 return elem.disabled === false;
nicholas@103 1886 },
nicholas@103 1887
nicholas@103 1888 "disabled": function( elem ) {
nicholas@103 1889 return elem.disabled === true;
nicholas@103 1890 },
nicholas@103 1891
nicholas@103 1892 "checked": function( elem ) {
nicholas@103 1893 // In CSS3, :checked should return both checked and selected elements
nicholas@103 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nicholas@103 1895 var nodeName = elem.nodeName.toLowerCase();
nicholas@103 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nicholas@103 1897 },
nicholas@103 1898
nicholas@103 1899 "selected": function( elem ) {
nicholas@103 1900 // Accessing this property makes selected-by-default
nicholas@103 1901 // options in Safari work properly
nicholas@103 1902 if ( elem.parentNode ) {
nicholas@103 1903 elem.parentNode.selectedIndex;
nicholas@103 1904 }
nicholas@103 1905
nicholas@103 1906 return elem.selected === true;
nicholas@103 1907 },
nicholas@103 1908
nicholas@103 1909 // Contents
nicholas@103 1910 "empty": function( elem ) {
nicholas@103 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nicholas@103 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nicholas@103 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nicholas@103 1914 // nodeType < 6 works because attributes (2) do not appear as children
nicholas@103 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nicholas@103 1916 if ( elem.nodeType < 6 ) {
nicholas@103 1917 return false;
nicholas@103 1918 }
nicholas@103 1919 }
nicholas@103 1920 return true;
nicholas@103 1921 },
nicholas@103 1922
nicholas@103 1923 "parent": function( elem ) {
nicholas@103 1924 return !Expr.pseudos["empty"]( elem );
nicholas@103 1925 },
nicholas@103 1926
nicholas@103 1927 // Element/input types
nicholas@103 1928 "header": function( elem ) {
nicholas@103 1929 return rheader.test( elem.nodeName );
nicholas@103 1930 },
nicholas@103 1931
nicholas@103 1932 "input": function( elem ) {
nicholas@103 1933 return rinputs.test( elem.nodeName );
nicholas@103 1934 },
nicholas@103 1935
nicholas@103 1936 "button": function( elem ) {
nicholas@103 1937 var name = elem.nodeName.toLowerCase();
nicholas@103 1938 return name === "input" && elem.type === "button" || name === "button";
nicholas@103 1939 },
nicholas@103 1940
nicholas@103 1941 "text": function( elem ) {
nicholas@103 1942 var attr;
nicholas@103 1943 return elem.nodeName.toLowerCase() === "input" &&
nicholas@103 1944 elem.type === "text" &&
nicholas@103 1945
nicholas@103 1946 // Support: IE<8
nicholas@103 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nicholas@103 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nicholas@103 1949 },
nicholas@103 1950
nicholas@103 1951 // Position-in-collection
nicholas@103 1952 "first": createPositionalPseudo(function() {
nicholas@103 1953 return [ 0 ];
nicholas@103 1954 }),
nicholas@103 1955
nicholas@103 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@103 1957 return [ length - 1 ];
nicholas@103 1958 }),
nicholas@103 1959
nicholas@103 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@103 1961 return [ argument < 0 ? argument + length : argument ];
nicholas@103 1962 }),
nicholas@103 1963
nicholas@103 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@103 1965 var i = 0;
nicholas@103 1966 for ( ; i < length; i += 2 ) {
nicholas@103 1967 matchIndexes.push( i );
nicholas@103 1968 }
nicholas@103 1969 return matchIndexes;
nicholas@103 1970 }),
nicholas@103 1971
nicholas@103 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@103 1973 var i = 1;
nicholas@103 1974 for ( ; i < length; i += 2 ) {
nicholas@103 1975 matchIndexes.push( i );
nicholas@103 1976 }
nicholas@103 1977 return matchIndexes;
nicholas@103 1978 }),
nicholas@103 1979
nicholas@103 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@103 1981 var i = argument < 0 ? argument + length : argument;
nicholas@103 1982 for ( ; --i >= 0; ) {
nicholas@103 1983 matchIndexes.push( i );
nicholas@103 1984 }
nicholas@103 1985 return matchIndexes;
nicholas@103 1986 }),
nicholas@103 1987
nicholas@103 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@103 1989 var i = argument < 0 ? argument + length : argument;
nicholas@103 1990 for ( ; ++i < length; ) {
nicholas@103 1991 matchIndexes.push( i );
nicholas@103 1992 }
nicholas@103 1993 return matchIndexes;
nicholas@103 1994 })
nicholas@103 1995 }
nicholas@103 1996 };
nicholas@103 1997
nicholas@103 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nicholas@103 1999
nicholas@103 2000 // Add button/input type pseudos
nicholas@103 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nicholas@103 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nicholas@103 2003 }
nicholas@103 2004 for ( i in { submit: true, reset: true } ) {
nicholas@103 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nicholas@103 2006 }
nicholas@103 2007
nicholas@103 2008 // Easy API for creating new setFilters
nicholas@103 2009 function setFilters() {}
nicholas@103 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nicholas@103 2011 Expr.setFilters = new setFilters();
nicholas@103 2012
nicholas@103 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nicholas@103 2014 var matched, match, tokens, type,
nicholas@103 2015 soFar, groups, preFilters,
nicholas@103 2016 cached = tokenCache[ selector + " " ];
nicholas@103 2017
nicholas@103 2018 if ( cached ) {
nicholas@103 2019 return parseOnly ? 0 : cached.slice( 0 );
nicholas@103 2020 }
nicholas@103 2021
nicholas@103 2022 soFar = selector;
nicholas@103 2023 groups = [];
nicholas@103 2024 preFilters = Expr.preFilter;
nicholas@103 2025
nicholas@103 2026 while ( soFar ) {
nicholas@103 2027
nicholas@103 2028 // Comma and first run
nicholas@103 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nicholas@103 2030 if ( match ) {
nicholas@103 2031 // Don't consume trailing commas as valid
nicholas@103 2032 soFar = soFar.slice( match[0].length ) || soFar;
nicholas@103 2033 }
nicholas@103 2034 groups.push( (tokens = []) );
nicholas@103 2035 }
nicholas@103 2036
nicholas@103 2037 matched = false;
nicholas@103 2038
nicholas@103 2039 // Combinators
nicholas@103 2040 if ( (match = rcombinators.exec( soFar )) ) {
nicholas@103 2041 matched = match.shift();
nicholas@103 2042 tokens.push({
nicholas@103 2043 value: matched,
nicholas@103 2044 // Cast descendant combinators to space
nicholas@103 2045 type: match[0].replace( rtrim, " " )
nicholas@103 2046 });
nicholas@103 2047 soFar = soFar.slice( matched.length );
nicholas@103 2048 }
nicholas@103 2049
nicholas@103 2050 // Filters
nicholas@103 2051 for ( type in Expr.filter ) {
nicholas@103 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nicholas@103 2053 (match = preFilters[ type ]( match ))) ) {
nicholas@103 2054 matched = match.shift();
nicholas@103 2055 tokens.push({
nicholas@103 2056 value: matched,
nicholas@103 2057 type: type,
nicholas@103 2058 matches: match
nicholas@103 2059 });
nicholas@103 2060 soFar = soFar.slice( matched.length );
nicholas@103 2061 }
nicholas@103 2062 }
nicholas@103 2063
nicholas@103 2064 if ( !matched ) {
nicholas@103 2065 break;
nicholas@103 2066 }
nicholas@103 2067 }
nicholas@103 2068
nicholas@103 2069 // Return the length of the invalid excess
nicholas@103 2070 // if we're just parsing
nicholas@103 2071 // Otherwise, throw an error or return tokens
nicholas@103 2072 return parseOnly ?
nicholas@103 2073 soFar.length :
nicholas@103 2074 soFar ?
nicholas@103 2075 Sizzle.error( selector ) :
nicholas@103 2076 // Cache the tokens
nicholas@103 2077 tokenCache( selector, groups ).slice( 0 );
nicholas@103 2078 };
nicholas@103 2079
nicholas@103 2080 function toSelector( tokens ) {
nicholas@103 2081 var i = 0,
nicholas@103 2082 len = tokens.length,
nicholas@103 2083 selector = "";
nicholas@103 2084 for ( ; i < len; i++ ) {
nicholas@103 2085 selector += tokens[i].value;
nicholas@103 2086 }
nicholas@103 2087 return selector;
nicholas@103 2088 }
nicholas@103 2089
nicholas@103 2090 function addCombinator( matcher, combinator, base ) {
nicholas@103 2091 var dir = combinator.dir,
nicholas@103 2092 checkNonElements = base && dir === "parentNode",
nicholas@103 2093 doneName = done++;
nicholas@103 2094
nicholas@103 2095 return combinator.first ?
nicholas@103 2096 // Check against closest ancestor/preceding element
nicholas@103 2097 function( elem, context, xml ) {
nicholas@103 2098 while ( (elem = elem[ dir ]) ) {
nicholas@103 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@103 2100 return matcher( elem, context, xml );
nicholas@103 2101 }
nicholas@103 2102 }
nicholas@103 2103 } :
nicholas@103 2104
nicholas@103 2105 // Check against all ancestor/preceding elements
nicholas@103 2106 function( elem, context, xml ) {
nicholas@103 2107 var oldCache, outerCache,
nicholas@103 2108 newCache = [ dirruns, doneName ];
nicholas@103 2109
nicholas@103 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nicholas@103 2111 if ( xml ) {
nicholas@103 2112 while ( (elem = elem[ dir ]) ) {
nicholas@103 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@103 2114 if ( matcher( elem, context, xml ) ) {
nicholas@103 2115 return true;
nicholas@103 2116 }
nicholas@103 2117 }
nicholas@103 2118 }
nicholas@103 2119 } else {
nicholas@103 2120 while ( (elem = elem[ dir ]) ) {
nicholas@103 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@103 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nicholas@103 2123 if ( (oldCache = outerCache[ dir ]) &&
nicholas@103 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nicholas@103 2125
nicholas@103 2126 // Assign to newCache so results back-propagate to previous elements
nicholas@103 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nicholas@103 2128 } else {
nicholas@103 2129 // Reuse newcache so results back-propagate to previous elements
nicholas@103 2130 outerCache[ dir ] = newCache;
nicholas@103 2131
nicholas@103 2132 // A match means we're done; a fail means we have to keep checking
nicholas@103 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nicholas@103 2134 return true;
nicholas@103 2135 }
nicholas@103 2136 }
nicholas@103 2137 }
nicholas@103 2138 }
nicholas@103 2139 }
nicholas@103 2140 };
nicholas@103 2141 }
nicholas@103 2142
nicholas@103 2143 function elementMatcher( matchers ) {
nicholas@103 2144 return matchers.length > 1 ?
nicholas@103 2145 function( elem, context, xml ) {
nicholas@103 2146 var i = matchers.length;
nicholas@103 2147 while ( i-- ) {
nicholas@103 2148 if ( !matchers[i]( elem, context, xml ) ) {
nicholas@103 2149 return false;
nicholas@103 2150 }
nicholas@103 2151 }
nicholas@103 2152 return true;
nicholas@103 2153 } :
nicholas@103 2154 matchers[0];
nicholas@103 2155 }
nicholas@103 2156
nicholas@103 2157 function multipleContexts( selector, contexts, results ) {
nicholas@103 2158 var i = 0,
nicholas@103 2159 len = contexts.length;
nicholas@103 2160 for ( ; i < len; i++ ) {
nicholas@103 2161 Sizzle( selector, contexts[i], results );
nicholas@103 2162 }
nicholas@103 2163 return results;
nicholas@103 2164 }
nicholas@103 2165
nicholas@103 2166 function condense( unmatched, map, filter, context, xml ) {
nicholas@103 2167 var elem,
nicholas@103 2168 newUnmatched = [],
nicholas@103 2169 i = 0,
nicholas@103 2170 len = unmatched.length,
nicholas@103 2171 mapped = map != null;
nicholas@103 2172
nicholas@103 2173 for ( ; i < len; i++ ) {
nicholas@103 2174 if ( (elem = unmatched[i]) ) {
nicholas@103 2175 if ( !filter || filter( elem, context, xml ) ) {
nicholas@103 2176 newUnmatched.push( elem );
nicholas@103 2177 if ( mapped ) {
nicholas@103 2178 map.push( i );
nicholas@103 2179 }
nicholas@103 2180 }
nicholas@103 2181 }
nicholas@103 2182 }
nicholas@103 2183
nicholas@103 2184 return newUnmatched;
nicholas@103 2185 }
nicholas@103 2186
nicholas@103 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nicholas@103 2188 if ( postFilter && !postFilter[ expando ] ) {
nicholas@103 2189 postFilter = setMatcher( postFilter );
nicholas@103 2190 }
nicholas@103 2191 if ( postFinder && !postFinder[ expando ] ) {
nicholas@103 2192 postFinder = setMatcher( postFinder, postSelector );
nicholas@103 2193 }
nicholas@103 2194 return markFunction(function( seed, results, context, xml ) {
nicholas@103 2195 var temp, i, elem,
nicholas@103 2196 preMap = [],
nicholas@103 2197 postMap = [],
nicholas@103 2198 preexisting = results.length,
nicholas@103 2199
nicholas@103 2200 // Get initial elements from seed or context
nicholas@103 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nicholas@103 2202
nicholas@103 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nicholas@103 2204 matcherIn = preFilter && ( seed || !selector ) ?
nicholas@103 2205 condense( elems, preMap, preFilter, context, xml ) :
nicholas@103 2206 elems,
nicholas@103 2207
nicholas@103 2208 matcherOut = matcher ?
nicholas@103 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nicholas@103 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nicholas@103 2211
nicholas@103 2212 // ...intermediate processing is necessary
nicholas@103 2213 [] :
nicholas@103 2214
nicholas@103 2215 // ...otherwise use results directly
nicholas@103 2216 results :
nicholas@103 2217 matcherIn;
nicholas@103 2218
nicholas@103 2219 // Find primary matches
nicholas@103 2220 if ( matcher ) {
nicholas@103 2221 matcher( matcherIn, matcherOut, context, xml );
nicholas@103 2222 }
nicholas@103 2223
nicholas@103 2224 // Apply postFilter
nicholas@103 2225 if ( postFilter ) {
nicholas@103 2226 temp = condense( matcherOut, postMap );
nicholas@103 2227 postFilter( temp, [], context, xml );
nicholas@103 2228
nicholas@103 2229 // Un-match failing elements by moving them back to matcherIn
nicholas@103 2230 i = temp.length;
nicholas@103 2231 while ( i-- ) {
nicholas@103 2232 if ( (elem = temp[i]) ) {
nicholas@103 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nicholas@103 2234 }
nicholas@103 2235 }
nicholas@103 2236 }
nicholas@103 2237
nicholas@103 2238 if ( seed ) {
nicholas@103 2239 if ( postFinder || preFilter ) {
nicholas@103 2240 if ( postFinder ) {
nicholas@103 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nicholas@103 2242 temp = [];
nicholas@103 2243 i = matcherOut.length;
nicholas@103 2244 while ( i-- ) {
nicholas@103 2245 if ( (elem = matcherOut[i]) ) {
nicholas@103 2246 // Restore matcherIn since elem is not yet a final match
nicholas@103 2247 temp.push( (matcherIn[i] = elem) );
nicholas@103 2248 }
nicholas@103 2249 }
nicholas@103 2250 postFinder( null, (matcherOut = []), temp, xml );
nicholas@103 2251 }
nicholas@103 2252
nicholas@103 2253 // Move matched elements from seed to results to keep them synchronized
nicholas@103 2254 i = matcherOut.length;
nicholas@103 2255 while ( i-- ) {
nicholas@103 2256 if ( (elem = matcherOut[i]) &&
nicholas@103 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nicholas@103 2258
nicholas@103 2259 seed[temp] = !(results[temp] = elem);
nicholas@103 2260 }
nicholas@103 2261 }
nicholas@103 2262 }
nicholas@103 2263
nicholas@103 2264 // Add elements to results, through postFinder if defined
nicholas@103 2265 } else {
nicholas@103 2266 matcherOut = condense(
nicholas@103 2267 matcherOut === results ?
nicholas@103 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nicholas@103 2269 matcherOut
nicholas@103 2270 );
nicholas@103 2271 if ( postFinder ) {
nicholas@103 2272 postFinder( null, results, matcherOut, xml );
nicholas@103 2273 } else {
nicholas@103 2274 push.apply( results, matcherOut );
nicholas@103 2275 }
nicholas@103 2276 }
nicholas@103 2277 });
nicholas@103 2278 }
nicholas@103 2279
nicholas@103 2280 function matcherFromTokens( tokens ) {
nicholas@103 2281 var checkContext, matcher, j,
nicholas@103 2282 len = tokens.length,
nicholas@103 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nicholas@103 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nicholas@103 2285 i = leadingRelative ? 1 : 0,
nicholas@103 2286
nicholas@103 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nicholas@103 2288 matchContext = addCombinator( function( elem ) {
nicholas@103 2289 return elem === checkContext;
nicholas@103 2290 }, implicitRelative, true ),
nicholas@103 2291 matchAnyContext = addCombinator( function( elem ) {
nicholas@103 2292 return indexOf( checkContext, elem ) > -1;
nicholas@103 2293 }, implicitRelative, true ),
nicholas@103 2294 matchers = [ function( elem, context, xml ) {
nicholas@103 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nicholas@103 2296 (checkContext = context).nodeType ?
nicholas@103 2297 matchContext( elem, context, xml ) :
nicholas@103 2298 matchAnyContext( elem, context, xml ) );
nicholas@103 2299 // Avoid hanging onto element (issue #299)
nicholas@103 2300 checkContext = null;
nicholas@103 2301 return ret;
nicholas@103 2302 } ];
nicholas@103 2303
nicholas@103 2304 for ( ; i < len; i++ ) {
nicholas@103 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nicholas@103 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nicholas@103 2307 } else {
nicholas@103 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nicholas@103 2309
nicholas@103 2310 // Return special upon seeing a positional matcher
nicholas@103 2311 if ( matcher[ expando ] ) {
nicholas@103 2312 // Find the next relative operator (if any) for proper handling
nicholas@103 2313 j = ++i;
nicholas@103 2314 for ( ; j < len; j++ ) {
nicholas@103 2315 if ( Expr.relative[ tokens[j].type ] ) {
nicholas@103 2316 break;
nicholas@103 2317 }
nicholas@103 2318 }
nicholas@103 2319 return setMatcher(
nicholas@103 2320 i > 1 && elementMatcher( matchers ),
nicholas@103 2321 i > 1 && toSelector(
nicholas@103 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nicholas@103 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nicholas@103 2324 ).replace( rtrim, "$1" ),
nicholas@103 2325 matcher,
nicholas@103 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nicholas@103 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nicholas@103 2328 j < len && toSelector( tokens )
nicholas@103 2329 );
nicholas@103 2330 }
nicholas@103 2331 matchers.push( matcher );
nicholas@103 2332 }
nicholas@103 2333 }
nicholas@103 2334
nicholas@103 2335 return elementMatcher( matchers );
nicholas@103 2336 }
nicholas@103 2337
nicholas@103 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nicholas@103 2339 var bySet = setMatchers.length > 0,
nicholas@103 2340 byElement = elementMatchers.length > 0,
nicholas@103 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nicholas@103 2342 var elem, j, matcher,
nicholas@103 2343 matchedCount = 0,
nicholas@103 2344 i = "0",
nicholas@103 2345 unmatched = seed && [],
nicholas@103 2346 setMatched = [],
nicholas@103 2347 contextBackup = outermostContext,
nicholas@103 2348 // We must always have either seed elements or outermost context
nicholas@103 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nicholas@103 2350 // Use integer dirruns iff this is the outermost matcher
nicholas@103 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nicholas@103 2352 len = elems.length;
nicholas@103 2353
nicholas@103 2354 if ( outermost ) {
nicholas@103 2355 outermostContext = context !== document && context;
nicholas@103 2356 }
nicholas@103 2357
nicholas@103 2358 // Add elements passing elementMatchers directly to results
nicholas@103 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nicholas@103 2360 // Support: IE<9, Safari
nicholas@103 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nicholas@103 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nicholas@103 2363 if ( byElement && elem ) {
nicholas@103 2364 j = 0;
nicholas@103 2365 while ( (matcher = elementMatchers[j++]) ) {
nicholas@103 2366 if ( matcher( elem, context, xml ) ) {
nicholas@103 2367 results.push( elem );
nicholas@103 2368 break;
nicholas@103 2369 }
nicholas@103 2370 }
nicholas@103 2371 if ( outermost ) {
nicholas@103 2372 dirruns = dirrunsUnique;
nicholas@103 2373 }
nicholas@103 2374 }
nicholas@103 2375
nicholas@103 2376 // Track unmatched elements for set filters
nicholas@103 2377 if ( bySet ) {
nicholas@103 2378 // They will have gone through all possible matchers
nicholas@103 2379 if ( (elem = !matcher && elem) ) {
nicholas@103 2380 matchedCount--;
nicholas@103 2381 }
nicholas@103 2382
nicholas@103 2383 // Lengthen the array for every element, matched or not
nicholas@103 2384 if ( seed ) {
nicholas@103 2385 unmatched.push( elem );
nicholas@103 2386 }
nicholas@103 2387 }
nicholas@103 2388 }
nicholas@103 2389
nicholas@103 2390 // Apply set filters to unmatched elements
nicholas@103 2391 matchedCount += i;
nicholas@103 2392 if ( bySet && i !== matchedCount ) {
nicholas@103 2393 j = 0;
nicholas@103 2394 while ( (matcher = setMatchers[j++]) ) {
nicholas@103 2395 matcher( unmatched, setMatched, context, xml );
nicholas@103 2396 }
nicholas@103 2397
nicholas@103 2398 if ( seed ) {
nicholas@103 2399 // Reintegrate element matches to eliminate the need for sorting
nicholas@103 2400 if ( matchedCount > 0 ) {
nicholas@103 2401 while ( i-- ) {
nicholas@103 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nicholas@103 2403 setMatched[i] = pop.call( results );
nicholas@103 2404 }
nicholas@103 2405 }
nicholas@103 2406 }
nicholas@103 2407
nicholas@103 2408 // Discard index placeholder values to get only actual matches
nicholas@103 2409 setMatched = condense( setMatched );
nicholas@103 2410 }
nicholas@103 2411
nicholas@103 2412 // Add matches to results
nicholas@103 2413 push.apply( results, setMatched );
nicholas@103 2414
nicholas@103 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nicholas@103 2416 if ( outermost && !seed && setMatched.length > 0 &&
nicholas@103 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nicholas@103 2418
nicholas@103 2419 Sizzle.uniqueSort( results );
nicholas@103 2420 }
nicholas@103 2421 }
nicholas@103 2422
nicholas@103 2423 // Override manipulation of globals by nested matchers
nicholas@103 2424 if ( outermost ) {
nicholas@103 2425 dirruns = dirrunsUnique;
nicholas@103 2426 outermostContext = contextBackup;
nicholas@103 2427 }
nicholas@103 2428
nicholas@103 2429 return unmatched;
nicholas@103 2430 };
nicholas@103 2431
nicholas@103 2432 return bySet ?
nicholas@103 2433 markFunction( superMatcher ) :
nicholas@103 2434 superMatcher;
nicholas@103 2435 }
nicholas@103 2436
nicholas@103 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nicholas@103 2438 var i,
nicholas@103 2439 setMatchers = [],
nicholas@103 2440 elementMatchers = [],
nicholas@103 2441 cached = compilerCache[ selector + " " ];
nicholas@103 2442
nicholas@103 2443 if ( !cached ) {
nicholas@103 2444 // Generate a function of recursive functions that can be used to check each element
nicholas@103 2445 if ( !match ) {
nicholas@103 2446 match = tokenize( selector );
nicholas@103 2447 }
nicholas@103 2448 i = match.length;
nicholas@103 2449 while ( i-- ) {
nicholas@103 2450 cached = matcherFromTokens( match[i] );
nicholas@103 2451 if ( cached[ expando ] ) {
nicholas@103 2452 setMatchers.push( cached );
nicholas@103 2453 } else {
nicholas@103 2454 elementMatchers.push( cached );
nicholas@103 2455 }
nicholas@103 2456 }
nicholas@103 2457
nicholas@103 2458 // Cache the compiled function
nicholas@103 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nicholas@103 2460
nicholas@103 2461 // Save selector and tokenization
nicholas@103 2462 cached.selector = selector;
nicholas@103 2463 }
nicholas@103 2464 return cached;
nicholas@103 2465 };
nicholas@103 2466
nicholas@103 2467 /**
nicholas@103 2468 * A low-level selection function that works with Sizzle's compiled
nicholas@103 2469 * selector functions
nicholas@103 2470 * @param {String|Function} selector A selector or a pre-compiled
nicholas@103 2471 * selector function built with Sizzle.compile
nicholas@103 2472 * @param {Element} context
nicholas@103 2473 * @param {Array} [results]
nicholas@103 2474 * @param {Array} [seed] A set of elements to match against
nicholas@103 2475 */
nicholas@103 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nicholas@103 2477 var i, tokens, token, type, find,
nicholas@103 2478 compiled = typeof selector === "function" && selector,
nicholas@103 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nicholas@103 2480
nicholas@103 2481 results = results || [];
nicholas@103 2482
nicholas@103 2483 // Try to minimize operations if there is no seed and only one group
nicholas@103 2484 if ( match.length === 1 ) {
nicholas@103 2485
nicholas@103 2486 // Take a shortcut and set the context if the root selector is an ID
nicholas@103 2487 tokens = match[0] = match[0].slice( 0 );
nicholas@103 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nicholas@103 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nicholas@103 2490 Expr.relative[ tokens[1].type ] ) {
nicholas@103 2491
nicholas@103 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nicholas@103 2493 if ( !context ) {
nicholas@103 2494 return results;
nicholas@103 2495
nicholas@103 2496 // Precompiled matchers will still verify ancestry, so step up a level
nicholas@103 2497 } else if ( compiled ) {
nicholas@103 2498 context = context.parentNode;
nicholas@103 2499 }
nicholas@103 2500
nicholas@103 2501 selector = selector.slice( tokens.shift().value.length );
nicholas@103 2502 }
nicholas@103 2503
nicholas@103 2504 // Fetch a seed set for right-to-left matching
nicholas@103 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nicholas@103 2506 while ( i-- ) {
nicholas@103 2507 token = tokens[i];
nicholas@103 2508
nicholas@103 2509 // Abort if we hit a combinator
nicholas@103 2510 if ( Expr.relative[ (type = token.type) ] ) {
nicholas@103 2511 break;
nicholas@103 2512 }
nicholas@103 2513 if ( (find = Expr.find[ type ]) ) {
nicholas@103 2514 // Search, expanding context for leading sibling combinators
nicholas@103 2515 if ( (seed = find(
nicholas@103 2516 token.matches[0].replace( runescape, funescape ),
nicholas@103 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nicholas@103 2518 )) ) {
nicholas@103 2519
nicholas@103 2520 // If seed is empty or no tokens remain, we can return early
nicholas@103 2521 tokens.splice( i, 1 );
nicholas@103 2522 selector = seed.length && toSelector( tokens );
nicholas@103 2523 if ( !selector ) {
nicholas@103 2524 push.apply( results, seed );
nicholas@103 2525 return results;
nicholas@103 2526 }
nicholas@103 2527
nicholas@103 2528 break;
nicholas@103 2529 }
nicholas@103 2530 }
nicholas@103 2531 }
nicholas@103 2532 }
nicholas@103 2533
nicholas@103 2534 // Compile and execute a filtering function if one is not provided
nicholas@103 2535 // Provide `match` to avoid retokenization if we modified the selector above
nicholas@103 2536 ( compiled || compile( selector, match ) )(
nicholas@103 2537 seed,
nicholas@103 2538 context,
nicholas@103 2539 !documentIsHTML,
nicholas@103 2540 results,
nicholas@103 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nicholas@103 2542 );
nicholas@103 2543 return results;
nicholas@103 2544 };
nicholas@103 2545
nicholas@103 2546 // One-time assignments
nicholas@103 2547
nicholas@103 2548 // Sort stability
nicholas@103 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nicholas@103 2550
nicholas@103 2551 // Support: Chrome 14-35+
nicholas@103 2552 // Always assume duplicates if they aren't passed to the comparison function
nicholas@103 2553 support.detectDuplicates = !!hasDuplicate;
nicholas@103 2554
nicholas@103 2555 // Initialize against the default document
nicholas@103 2556 setDocument();
nicholas@103 2557
nicholas@103 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nicholas@103 2559 // Detached nodes confoundingly follow *each other*
nicholas@103 2560 support.sortDetached = assert(function( div1 ) {
nicholas@103 2561 // Should return 1, but returns 4 (following)
nicholas@103 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nicholas@103 2563 });
nicholas@103 2564
nicholas@103 2565 // Support: IE<8
nicholas@103 2566 // Prevent attribute/property "interpolation"
nicholas@103 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nicholas@103 2568 if ( !assert(function( div ) {
nicholas@103 2569 div.innerHTML = "<a href='#'></a>";
nicholas@103 2570 return div.firstChild.getAttribute("href") === "#" ;
nicholas@103 2571 }) ) {
nicholas@103 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nicholas@103 2573 if ( !isXML ) {
nicholas@103 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nicholas@103 2575 }
nicholas@103 2576 });
nicholas@103 2577 }
nicholas@103 2578
nicholas@103 2579 // Support: IE<9
nicholas@103 2580 // Use defaultValue in place of getAttribute("value")
nicholas@103 2581 if ( !support.attributes || !assert(function( div ) {
nicholas@103 2582 div.innerHTML = "<input/>";
nicholas@103 2583 div.firstChild.setAttribute( "value", "" );
nicholas@103 2584 return div.firstChild.getAttribute( "value" ) === "";
nicholas@103 2585 }) ) {
nicholas@103 2586 addHandle( "value", function( elem, name, isXML ) {
nicholas@103 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nicholas@103 2588 return elem.defaultValue;
nicholas@103 2589 }
nicholas@103 2590 });
nicholas@103 2591 }
nicholas@103 2592
nicholas@103 2593 // Support: IE<9
nicholas@103 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nicholas@103 2595 if ( !assert(function( div ) {
nicholas@103 2596 return div.getAttribute("disabled") == null;
nicholas@103 2597 }) ) {
nicholas@103 2598 addHandle( booleans, function( elem, name, isXML ) {
nicholas@103 2599 var val;
nicholas@103 2600 if ( !isXML ) {
nicholas@103 2601 return elem[ name ] === true ? name.toLowerCase() :
nicholas@103 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nicholas@103 2603 val.value :
nicholas@103 2604 null;
nicholas@103 2605 }
nicholas@103 2606 });
nicholas@103 2607 }
nicholas@103 2608
nicholas@103 2609 return Sizzle;
nicholas@103 2610
nicholas@103 2611 })( window );
nicholas@103 2612
nicholas@103 2613
nicholas@103 2614
nicholas@103 2615 jQuery.find = Sizzle;
nicholas@103 2616 jQuery.expr = Sizzle.selectors;
nicholas@103 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nicholas@103 2618 jQuery.unique = Sizzle.uniqueSort;
nicholas@103 2619 jQuery.text = Sizzle.getText;
nicholas@103 2620 jQuery.isXMLDoc = Sizzle.isXML;
nicholas@103 2621 jQuery.contains = Sizzle.contains;
nicholas@103 2622
nicholas@103 2623
nicholas@103 2624
nicholas@103 2625 var rneedsContext = jQuery.expr.match.needsContext;
nicholas@103 2626
nicholas@103 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nicholas@103 2628
nicholas@103 2629
nicholas@103 2630
nicholas@103 2631 var risSimple = /^.[^:#\[\.,]*$/;
nicholas@103 2632
nicholas@103 2633 // Implement the identical functionality for filter and not
nicholas@103 2634 function winnow( elements, qualifier, not ) {
nicholas@103 2635 if ( jQuery.isFunction( qualifier ) ) {
nicholas@103 2636 return jQuery.grep( elements, function( elem, i ) {
nicholas@103 2637 /* jshint -W018 */
nicholas@103 2638 return !!qualifier.call( elem, i, elem ) !== not;
nicholas@103 2639 });
nicholas@103 2640
nicholas@103 2641 }
nicholas@103 2642
nicholas@103 2643 if ( qualifier.nodeType ) {
nicholas@103 2644 return jQuery.grep( elements, function( elem ) {
nicholas@103 2645 return ( elem === qualifier ) !== not;
nicholas@103 2646 });
nicholas@103 2647
nicholas@103 2648 }
nicholas@103 2649
nicholas@103 2650 if ( typeof qualifier === "string" ) {
nicholas@103 2651 if ( risSimple.test( qualifier ) ) {
nicholas@103 2652 return jQuery.filter( qualifier, elements, not );
nicholas@103 2653 }
nicholas@103 2654
nicholas@103 2655 qualifier = jQuery.filter( qualifier, elements );
nicholas@103 2656 }
nicholas@103 2657
nicholas@103 2658 return jQuery.grep( elements, function( elem ) {
nicholas@103 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nicholas@103 2660 });
nicholas@103 2661 }
nicholas@103 2662
nicholas@103 2663 jQuery.filter = function( expr, elems, not ) {
nicholas@103 2664 var elem = elems[ 0 ];
nicholas@103 2665
nicholas@103 2666 if ( not ) {
nicholas@103 2667 expr = ":not(" + expr + ")";
nicholas@103 2668 }
nicholas@103 2669
nicholas@103 2670 return elems.length === 1 && elem.nodeType === 1 ?
nicholas@103 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nicholas@103 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nicholas@103 2673 return elem.nodeType === 1;
nicholas@103 2674 }));
nicholas@103 2675 };
nicholas@103 2676
nicholas@103 2677 jQuery.fn.extend({
nicholas@103 2678 find: function( selector ) {
nicholas@103 2679 var i,
nicholas@103 2680 len = this.length,
nicholas@103 2681 ret = [],
nicholas@103 2682 self = this;
nicholas@103 2683
nicholas@103 2684 if ( typeof selector !== "string" ) {
nicholas@103 2685 return this.pushStack( jQuery( selector ).filter(function() {
nicholas@103 2686 for ( i = 0; i < len; i++ ) {
nicholas@103 2687 if ( jQuery.contains( self[ i ], this ) ) {
nicholas@103 2688 return true;
nicholas@103 2689 }
nicholas@103 2690 }
nicholas@103 2691 }) );
nicholas@103 2692 }
nicholas@103 2693
nicholas@103 2694 for ( i = 0; i < len; i++ ) {
nicholas@103 2695 jQuery.find( selector, self[ i ], ret );
nicholas@103 2696 }
nicholas@103 2697
nicholas@103 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nicholas@103 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nicholas@103 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nicholas@103 2701 return ret;
nicholas@103 2702 },
nicholas@103 2703 filter: function( selector ) {
nicholas@103 2704 return this.pushStack( winnow(this, selector || [], false) );
nicholas@103 2705 },
nicholas@103 2706 not: function( selector ) {
nicholas@103 2707 return this.pushStack( winnow(this, selector || [], true) );
nicholas@103 2708 },
nicholas@103 2709 is: function( selector ) {
nicholas@103 2710 return !!winnow(
nicholas@103 2711 this,
nicholas@103 2712
nicholas@103 2713 // If this is a positional/relative selector, check membership in the returned set
nicholas@103 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nicholas@103 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nicholas@103 2716 jQuery( selector ) :
nicholas@103 2717 selector || [],
nicholas@103 2718 false
nicholas@103 2719 ).length;
nicholas@103 2720 }
nicholas@103 2721 });
nicholas@103 2722
nicholas@103 2723
nicholas@103 2724 // Initialize a jQuery object
nicholas@103 2725
nicholas@103 2726
nicholas@103 2727 // A central reference to the root jQuery(document)
nicholas@103 2728 var rootjQuery,
nicholas@103 2729
nicholas@103 2730 // A simple way to check for HTML strings
nicholas@103 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nicholas@103 2732 // Strict HTML recognition (#11290: must start with <)
nicholas@103 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nicholas@103 2734
nicholas@103 2735 init = jQuery.fn.init = function( selector, context ) {
nicholas@103 2736 var match, elem;
nicholas@103 2737
nicholas@103 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nicholas@103 2739 if ( !selector ) {
nicholas@103 2740 return this;
nicholas@103 2741 }
nicholas@103 2742
nicholas@103 2743 // Handle HTML strings
nicholas@103 2744 if ( typeof selector === "string" ) {
nicholas@103 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nicholas@103 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nicholas@103 2747 match = [ null, selector, null ];
nicholas@103 2748
nicholas@103 2749 } else {
nicholas@103 2750 match = rquickExpr.exec( selector );
nicholas@103 2751 }
nicholas@103 2752
nicholas@103 2753 // Match html or make sure no context is specified for #id
nicholas@103 2754 if ( match && (match[1] || !context) ) {
nicholas@103 2755
nicholas@103 2756 // HANDLE: $(html) -> $(array)
nicholas@103 2757 if ( match[1] ) {
nicholas@103 2758 context = context instanceof jQuery ? context[0] : context;
nicholas@103 2759
nicholas@103 2760 // Option to run scripts is true for back-compat
nicholas@103 2761 // Intentionally let the error be thrown if parseHTML is not present
nicholas@103 2762 jQuery.merge( this, jQuery.parseHTML(
nicholas@103 2763 match[1],
nicholas@103 2764 context && context.nodeType ? context.ownerDocument || context : document,
nicholas@103 2765 true
nicholas@103 2766 ) );
nicholas@103 2767
nicholas@103 2768 // HANDLE: $(html, props)
nicholas@103 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nicholas@103 2770 for ( match in context ) {
nicholas@103 2771 // Properties of context are called as methods if possible
nicholas@103 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nicholas@103 2773 this[ match ]( context[ match ] );
nicholas@103 2774
nicholas@103 2775 // ...and otherwise set as attributes
nicholas@103 2776 } else {
nicholas@103 2777 this.attr( match, context[ match ] );
nicholas@103 2778 }
nicholas@103 2779 }
nicholas@103 2780 }
nicholas@103 2781
nicholas@103 2782 return this;
nicholas@103 2783
nicholas@103 2784 // HANDLE: $(#id)
nicholas@103 2785 } else {
nicholas@103 2786 elem = document.getElementById( match[2] );
nicholas@103 2787
nicholas@103 2788 // Support: Blackberry 4.6
nicholas@103 2789 // gEBID returns nodes no longer in the document (#6963)
nicholas@103 2790 if ( elem && elem.parentNode ) {
nicholas@103 2791 // Inject the element directly into the jQuery object
nicholas@103 2792 this.length = 1;
nicholas@103 2793 this[0] = elem;
nicholas@103 2794 }
nicholas@103 2795
nicholas@103 2796 this.context = document;
nicholas@103 2797 this.selector = selector;
nicholas@103 2798 return this;
nicholas@103 2799 }
nicholas@103 2800
nicholas@103 2801 // HANDLE: $(expr, $(...))
nicholas@103 2802 } else if ( !context || context.jquery ) {
nicholas@103 2803 return ( context || rootjQuery ).find( selector );
nicholas@103 2804
nicholas@103 2805 // HANDLE: $(expr, context)
nicholas@103 2806 // (which is just equivalent to: $(context).find(expr)
nicholas@103 2807 } else {
nicholas@103 2808 return this.constructor( context ).find( selector );
nicholas@103 2809 }
nicholas@103 2810
nicholas@103 2811 // HANDLE: $(DOMElement)
nicholas@103 2812 } else if ( selector.nodeType ) {
nicholas@103 2813 this.context = this[0] = selector;
nicholas@103 2814 this.length = 1;
nicholas@103 2815 return this;
nicholas@103 2816
nicholas@103 2817 // HANDLE: $(function)
nicholas@103 2818 // Shortcut for document ready
nicholas@103 2819 } else if ( jQuery.isFunction( selector ) ) {
nicholas@103 2820 return typeof rootjQuery.ready !== "undefined" ?
nicholas@103 2821 rootjQuery.ready( selector ) :
nicholas@103 2822 // Execute immediately if ready is not present
nicholas@103 2823 selector( jQuery );
nicholas@103 2824 }
nicholas@103 2825
nicholas@103 2826 if ( selector.selector !== undefined ) {
nicholas@103 2827 this.selector = selector.selector;
nicholas@103 2828 this.context = selector.context;
nicholas@103 2829 }
nicholas@103 2830
nicholas@103 2831 return jQuery.makeArray( selector, this );
nicholas@103 2832 };
nicholas@103 2833
nicholas@103 2834 // Give the init function the jQuery prototype for later instantiation
nicholas@103 2835 init.prototype = jQuery.fn;
nicholas@103 2836
nicholas@103 2837 // Initialize central reference
nicholas@103 2838 rootjQuery = jQuery( document );
nicholas@103 2839
nicholas@103 2840
nicholas@103 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nicholas@103 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nicholas@103 2843 guaranteedUnique = {
nicholas@103 2844 children: true,
nicholas@103 2845 contents: true,
nicholas@103 2846 next: true,
nicholas@103 2847 prev: true
nicholas@103 2848 };
nicholas@103 2849
nicholas@103 2850 jQuery.extend({
nicholas@103 2851 dir: function( elem, dir, until ) {
nicholas@103 2852 var matched = [],
nicholas@103 2853 truncate = until !== undefined;
nicholas@103 2854
nicholas@103 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nicholas@103 2856 if ( elem.nodeType === 1 ) {
nicholas@103 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nicholas@103 2858 break;
nicholas@103 2859 }
nicholas@103 2860 matched.push( elem );
nicholas@103 2861 }
nicholas@103 2862 }
nicholas@103 2863 return matched;
nicholas@103 2864 },
nicholas@103 2865
nicholas@103 2866 sibling: function( n, elem ) {
nicholas@103 2867 var matched = [];
nicholas@103 2868
nicholas@103 2869 for ( ; n; n = n.nextSibling ) {
nicholas@103 2870 if ( n.nodeType === 1 && n !== elem ) {
nicholas@103 2871 matched.push( n );
nicholas@103 2872 }
nicholas@103 2873 }
nicholas@103 2874
nicholas@103 2875 return matched;
nicholas@103 2876 }
nicholas@103 2877 });
nicholas@103 2878
nicholas@103 2879 jQuery.fn.extend({
nicholas@103 2880 has: function( target ) {
nicholas@103 2881 var targets = jQuery( target, this ),
nicholas@103 2882 l = targets.length;
nicholas@103 2883
nicholas@103 2884 return this.filter(function() {
nicholas@103 2885 var i = 0;
nicholas@103 2886 for ( ; i < l; i++ ) {
nicholas@103 2887 if ( jQuery.contains( this, targets[i] ) ) {
nicholas@103 2888 return true;
nicholas@103 2889 }
nicholas@103 2890 }
nicholas@103 2891 });
nicholas@103 2892 },
nicholas@103 2893
nicholas@103 2894 closest: function( selectors, context ) {
nicholas@103 2895 var cur,
nicholas@103 2896 i = 0,
nicholas@103 2897 l = this.length,
nicholas@103 2898 matched = [],
nicholas@103 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nicholas@103 2900 jQuery( selectors, context || this.context ) :
nicholas@103 2901 0;
nicholas@103 2902
nicholas@103 2903 for ( ; i < l; i++ ) {
nicholas@103 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nicholas@103 2905 // Always skip document fragments
nicholas@103 2906 if ( cur.nodeType < 11 && (pos ?
nicholas@103 2907 pos.index(cur) > -1 :
nicholas@103 2908
nicholas@103 2909 // Don't pass non-elements to Sizzle
nicholas@103 2910 cur.nodeType === 1 &&
nicholas@103 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nicholas@103 2912
nicholas@103 2913 matched.push( cur );
nicholas@103 2914 break;
nicholas@103 2915 }
nicholas@103 2916 }
nicholas@103 2917 }
nicholas@103 2918
nicholas@103 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nicholas@103 2920 },
nicholas@103 2921
nicholas@103 2922 // Determine the position of an element within the set
nicholas@103 2923 index: function( elem ) {
nicholas@103 2924
nicholas@103 2925 // No argument, return index in parent
nicholas@103 2926 if ( !elem ) {
nicholas@103 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nicholas@103 2928 }
nicholas@103 2929
nicholas@103 2930 // Index in selector
nicholas@103 2931 if ( typeof elem === "string" ) {
nicholas@103 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nicholas@103 2933 }
nicholas@103 2934
nicholas@103 2935 // Locate the position of the desired element
nicholas@103 2936 return indexOf.call( this,
nicholas@103 2937
nicholas@103 2938 // If it receives a jQuery object, the first element is used
nicholas@103 2939 elem.jquery ? elem[ 0 ] : elem
nicholas@103 2940 );
nicholas@103 2941 },
nicholas@103 2942
nicholas@103 2943 add: function( selector, context ) {
nicholas@103 2944 return this.pushStack(
nicholas@103 2945 jQuery.unique(
nicholas@103 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nicholas@103 2947 )
nicholas@103 2948 );
nicholas@103 2949 },
nicholas@103 2950
nicholas@103 2951 addBack: function( selector ) {
nicholas@103 2952 return this.add( selector == null ?
nicholas@103 2953 this.prevObject : this.prevObject.filter(selector)
nicholas@103 2954 );
nicholas@103 2955 }
nicholas@103 2956 });
nicholas@103 2957
nicholas@103 2958 function sibling( cur, dir ) {
nicholas@103 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nicholas@103 2960 return cur;
nicholas@103 2961 }
nicholas@103 2962
nicholas@103 2963 jQuery.each({
nicholas@103 2964 parent: function( elem ) {
nicholas@103 2965 var parent = elem.parentNode;
nicholas@103 2966 return parent && parent.nodeType !== 11 ? parent : null;
nicholas@103 2967 },
nicholas@103 2968 parents: function( elem ) {
nicholas@103 2969 return jQuery.dir( elem, "parentNode" );
nicholas@103 2970 },
nicholas@103 2971 parentsUntil: function( elem, i, until ) {
nicholas@103 2972 return jQuery.dir( elem, "parentNode", until );
nicholas@103 2973 },
nicholas@103 2974 next: function( elem ) {
nicholas@103 2975 return sibling( elem, "nextSibling" );
nicholas@103 2976 },
nicholas@103 2977 prev: function( elem ) {
nicholas@103 2978 return sibling( elem, "previousSibling" );
nicholas@103 2979 },
nicholas@103 2980 nextAll: function( elem ) {
nicholas@103 2981 return jQuery.dir( elem, "nextSibling" );
nicholas@103 2982 },
nicholas@103 2983 prevAll: function( elem ) {
nicholas@103 2984 return jQuery.dir( elem, "previousSibling" );
nicholas@103 2985 },
nicholas@103 2986 nextUntil: function( elem, i, until ) {
nicholas@103 2987 return jQuery.dir( elem, "nextSibling", until );
nicholas@103 2988 },
nicholas@103 2989 prevUntil: function( elem, i, until ) {
nicholas@103 2990 return jQuery.dir( elem, "previousSibling", until );
nicholas@103 2991 },
nicholas@103 2992 siblings: function( elem ) {
nicholas@103 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nicholas@103 2994 },
nicholas@103 2995 children: function( elem ) {
nicholas@103 2996 return jQuery.sibling( elem.firstChild );
nicholas@103 2997 },
nicholas@103 2998 contents: function( elem ) {
nicholas@103 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nicholas@103 3000 }
nicholas@103 3001 }, function( name, fn ) {
nicholas@103 3002 jQuery.fn[ name ] = function( until, selector ) {
nicholas@103 3003 var matched = jQuery.map( this, fn, until );
nicholas@103 3004
nicholas@103 3005 if ( name.slice( -5 ) !== "Until" ) {
nicholas@103 3006 selector = until;
nicholas@103 3007 }
nicholas@103 3008
nicholas@103 3009 if ( selector && typeof selector === "string" ) {
nicholas@103 3010 matched = jQuery.filter( selector, matched );
nicholas@103 3011 }
nicholas@103 3012
nicholas@103 3013 if ( this.length > 1 ) {
nicholas@103 3014 // Remove duplicates
nicholas@103 3015 if ( !guaranteedUnique[ name ] ) {
nicholas@103 3016 jQuery.unique( matched );
nicholas@103 3017 }
nicholas@103 3018
nicholas@103 3019 // Reverse order for parents* and prev-derivatives
nicholas@103 3020 if ( rparentsprev.test( name ) ) {
nicholas@103 3021 matched.reverse();
nicholas@103 3022 }
nicholas@103 3023 }
nicholas@103 3024
nicholas@103 3025 return this.pushStack( matched );
nicholas@103 3026 };
nicholas@103 3027 });
nicholas@103 3028 var rnotwhite = (/\S+/g);
nicholas@103 3029
nicholas@103 3030
nicholas@103 3031
nicholas@103 3032 // String to Object options format cache
nicholas@103 3033 var optionsCache = {};
nicholas@103 3034
nicholas@103 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nicholas@103 3036 function createOptions( options ) {
nicholas@103 3037 var object = optionsCache[ options ] = {};
nicholas@103 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nicholas@103 3039 object[ flag ] = true;
nicholas@103 3040 });
nicholas@103 3041 return object;
nicholas@103 3042 }
nicholas@103 3043
nicholas@103 3044 /*
nicholas@103 3045 * Create a callback list using the following parameters:
nicholas@103 3046 *
nicholas@103 3047 * options: an optional list of space-separated options that will change how
nicholas@103 3048 * the callback list behaves or a more traditional option object
nicholas@103 3049 *
nicholas@103 3050 * By default a callback list will act like an event callback list and can be
nicholas@103 3051 * "fired" multiple times.
nicholas@103 3052 *
nicholas@103 3053 * Possible options:
nicholas@103 3054 *
nicholas@103 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nicholas@103 3056 *
nicholas@103 3057 * memory: will keep track of previous values and will call any callback added
nicholas@103 3058 * after the list has been fired right away with the latest "memorized"
nicholas@103 3059 * values (like a Deferred)
nicholas@103 3060 *
nicholas@103 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nicholas@103 3062 *
nicholas@103 3063 * stopOnFalse: interrupt callings when a callback returns false
nicholas@103 3064 *
nicholas@103 3065 */
nicholas@103 3066 jQuery.Callbacks = function( options ) {
nicholas@103 3067
nicholas@103 3068 // Convert options from String-formatted to Object-formatted if needed
nicholas@103 3069 // (we check in cache first)
nicholas@103 3070 options = typeof options === "string" ?
nicholas@103 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nicholas@103 3072 jQuery.extend( {}, options );
nicholas@103 3073
nicholas@103 3074 var // Last fire value (for non-forgettable lists)
nicholas@103 3075 memory,
nicholas@103 3076 // Flag to know if list was already fired
nicholas@103 3077 fired,
nicholas@103 3078 // Flag to know if list is currently firing
nicholas@103 3079 firing,
nicholas@103 3080 // First callback to fire (used internally by add and fireWith)
nicholas@103 3081 firingStart,
nicholas@103 3082 // End of the loop when firing
nicholas@103 3083 firingLength,
nicholas@103 3084 // Index of currently firing callback (modified by remove if needed)
nicholas@103 3085 firingIndex,
nicholas@103 3086 // Actual callback list
nicholas@103 3087 list = [],
nicholas@103 3088 // Stack of fire calls for repeatable lists
nicholas@103 3089 stack = !options.once && [],
nicholas@103 3090 // Fire callbacks
nicholas@103 3091 fire = function( data ) {
nicholas@103 3092 memory = options.memory && data;
nicholas@103 3093 fired = true;
nicholas@103 3094 firingIndex = firingStart || 0;
nicholas@103 3095 firingStart = 0;
nicholas@103 3096 firingLength = list.length;
nicholas@103 3097 firing = true;
nicholas@103 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nicholas@103 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nicholas@103 3100 memory = false; // To prevent further calls using add
nicholas@103 3101 break;
nicholas@103 3102 }
nicholas@103 3103 }
nicholas@103 3104 firing = false;
nicholas@103 3105 if ( list ) {
nicholas@103 3106 if ( stack ) {
nicholas@103 3107 if ( stack.length ) {
nicholas@103 3108 fire( stack.shift() );
nicholas@103 3109 }
nicholas@103 3110 } else if ( memory ) {
nicholas@103 3111 list = [];
nicholas@103 3112 } else {
nicholas@103 3113 self.disable();
nicholas@103 3114 }
nicholas@103 3115 }
nicholas@103 3116 },
nicholas@103 3117 // Actual Callbacks object
nicholas@103 3118 self = {
nicholas@103 3119 // Add a callback or a collection of callbacks to the list
nicholas@103 3120 add: function() {
nicholas@103 3121 if ( list ) {
nicholas@103 3122 // First, we save the current length
nicholas@103 3123 var start = list.length;
nicholas@103 3124 (function add( args ) {
nicholas@103 3125 jQuery.each( args, function( _, arg ) {
nicholas@103 3126 var type = jQuery.type( arg );
nicholas@103 3127 if ( type === "function" ) {
nicholas@103 3128 if ( !options.unique || !self.has( arg ) ) {
nicholas@103 3129 list.push( arg );
nicholas@103 3130 }
nicholas@103 3131 } else if ( arg && arg.length && type !== "string" ) {
nicholas@103 3132 // Inspect recursively
nicholas@103 3133 add( arg );
nicholas@103 3134 }
nicholas@103 3135 });
nicholas@103 3136 })( arguments );
nicholas@103 3137 // Do we need to add the callbacks to the
nicholas@103 3138 // current firing batch?
nicholas@103 3139 if ( firing ) {
nicholas@103 3140 firingLength = list.length;
nicholas@103 3141 // With memory, if we're not firing then
nicholas@103 3142 // we should call right away
nicholas@103 3143 } else if ( memory ) {
nicholas@103 3144 firingStart = start;
nicholas@103 3145 fire( memory );
nicholas@103 3146 }
nicholas@103 3147 }
nicholas@103 3148 return this;
nicholas@103 3149 },
nicholas@103 3150 // Remove a callback from the list
nicholas@103 3151 remove: function() {
nicholas@103 3152 if ( list ) {
nicholas@103 3153 jQuery.each( arguments, function( _, arg ) {
nicholas@103 3154 var index;
nicholas@103 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nicholas@103 3156 list.splice( index, 1 );
nicholas@103 3157 // Handle firing indexes
nicholas@103 3158 if ( firing ) {
nicholas@103 3159 if ( index <= firingLength ) {
nicholas@103 3160 firingLength--;
nicholas@103 3161 }
nicholas@103 3162 if ( index <= firingIndex ) {
nicholas@103 3163 firingIndex--;
nicholas@103 3164 }
nicholas@103 3165 }
nicholas@103 3166 }
nicholas@103 3167 });
nicholas@103 3168 }
nicholas@103 3169 return this;
nicholas@103 3170 },
nicholas@103 3171 // Check if a given callback is in the list.
nicholas@103 3172 // If no argument is given, return whether or not list has callbacks attached.
nicholas@103 3173 has: function( fn ) {
nicholas@103 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nicholas@103 3175 },
nicholas@103 3176 // Remove all callbacks from the list
nicholas@103 3177 empty: function() {
nicholas@103 3178 list = [];
nicholas@103 3179 firingLength = 0;
nicholas@103 3180 return this;
nicholas@103 3181 },
nicholas@103 3182 // Have the list do nothing anymore
nicholas@103 3183 disable: function() {
nicholas@103 3184 list = stack = memory = undefined;
nicholas@103 3185 return this;
nicholas@103 3186 },
nicholas@103 3187 // Is it disabled?
nicholas@103 3188 disabled: function() {
nicholas@103 3189 return !list;
nicholas@103 3190 },
nicholas@103 3191 // Lock the list in its current state
nicholas@103 3192 lock: function() {
nicholas@103 3193 stack = undefined;
nicholas@103 3194 if ( !memory ) {
nicholas@103 3195 self.disable();
nicholas@103 3196 }
nicholas@103 3197 return this;
nicholas@103 3198 },
nicholas@103 3199 // Is it locked?
nicholas@103 3200 locked: function() {
nicholas@103 3201 return !stack;
nicholas@103 3202 },
nicholas@103 3203 // Call all callbacks with the given context and arguments
nicholas@103 3204 fireWith: function( context, args ) {
nicholas@103 3205 if ( list && ( !fired || stack ) ) {
nicholas@103 3206 args = args || [];
nicholas@103 3207 args = [ context, args.slice ? args.slice() : args ];
nicholas@103 3208 if ( firing ) {
nicholas@103 3209 stack.push( args );
nicholas@103 3210 } else {
nicholas@103 3211 fire( args );
nicholas@103 3212 }
nicholas@103 3213 }
nicholas@103 3214 return this;
nicholas@103 3215 },
nicholas@103 3216 // Call all the callbacks with the given arguments
nicholas@103 3217 fire: function() {
nicholas@103 3218 self.fireWith( this, arguments );
nicholas@103 3219 return this;
nicholas@103 3220 },
nicholas@103 3221 // To know if the callbacks have already been called at least once
nicholas@103 3222 fired: function() {
nicholas@103 3223 return !!fired;
nicholas@103 3224 }
nicholas@103 3225 };
nicholas@103 3226
nicholas@103 3227 return self;
nicholas@103 3228 };
nicholas@103 3229
nicholas@103 3230
nicholas@103 3231 jQuery.extend({
nicholas@103 3232
nicholas@103 3233 Deferred: function( func ) {
nicholas@103 3234 var tuples = [
nicholas@103 3235 // action, add listener, listener list, final state
nicholas@103 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nicholas@103 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nicholas@103 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nicholas@103 3239 ],
nicholas@103 3240 state = "pending",
nicholas@103 3241 promise = {
nicholas@103 3242 state: function() {
nicholas@103 3243 return state;
nicholas@103 3244 },
nicholas@103 3245 always: function() {
nicholas@103 3246 deferred.done( arguments ).fail( arguments );
nicholas@103 3247 return this;
nicholas@103 3248 },
nicholas@103 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nicholas@103 3250 var fns = arguments;
nicholas@103 3251 return jQuery.Deferred(function( newDefer ) {
nicholas@103 3252 jQuery.each( tuples, function( i, tuple ) {
nicholas@103 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nicholas@103 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nicholas@103 3255 deferred[ tuple[1] ](function() {
nicholas@103 3256 var returned = fn && fn.apply( this, arguments );
nicholas@103 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nicholas@103 3258 returned.promise()
nicholas@103 3259 .done( newDefer.resolve )
nicholas@103 3260 .fail( newDefer.reject )
nicholas@103 3261 .progress( newDefer.notify );
nicholas@103 3262 } else {
nicholas@103 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nicholas@103 3264 }
nicholas@103 3265 });
nicholas@103 3266 });
nicholas@103 3267 fns = null;
nicholas@103 3268 }).promise();
nicholas@103 3269 },
nicholas@103 3270 // Get a promise for this deferred
nicholas@103 3271 // If obj is provided, the promise aspect is added to the object
nicholas@103 3272 promise: function( obj ) {
nicholas@103 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nicholas@103 3274 }
nicholas@103 3275 },
nicholas@103 3276 deferred = {};
nicholas@103 3277
nicholas@103 3278 // Keep pipe for back-compat
nicholas@103 3279 promise.pipe = promise.then;
nicholas@103 3280
nicholas@103 3281 // Add list-specific methods
nicholas@103 3282 jQuery.each( tuples, function( i, tuple ) {
nicholas@103 3283 var list = tuple[ 2 ],
nicholas@103 3284 stateString = tuple[ 3 ];
nicholas@103 3285
nicholas@103 3286 // promise[ done | fail | progress ] = list.add
nicholas@103 3287 promise[ tuple[1] ] = list.add;
nicholas@103 3288
nicholas@103 3289 // Handle state
nicholas@103 3290 if ( stateString ) {
nicholas@103 3291 list.add(function() {
nicholas@103 3292 // state = [ resolved | rejected ]
nicholas@103 3293 state = stateString;
nicholas@103 3294
nicholas@103 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nicholas@103 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nicholas@103 3297 }
nicholas@103 3298
nicholas@103 3299 // deferred[ resolve | reject | notify ]
nicholas@103 3300 deferred[ tuple[0] ] = function() {
nicholas@103 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nicholas@103 3302 return this;
nicholas@103 3303 };
nicholas@103 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nicholas@103 3305 });
nicholas@103 3306
nicholas@103 3307 // Make the deferred a promise
nicholas@103 3308 promise.promise( deferred );
nicholas@103 3309
nicholas@103 3310 // Call given func if any
nicholas@103 3311 if ( func ) {
nicholas@103 3312 func.call( deferred, deferred );
nicholas@103 3313 }
nicholas@103 3314
nicholas@103 3315 // All done!
nicholas@103 3316 return deferred;
nicholas@103 3317 },
nicholas@103 3318
nicholas@103 3319 // Deferred helper
nicholas@103 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nicholas@103 3321 var i = 0,
nicholas@103 3322 resolveValues = slice.call( arguments ),
nicholas@103 3323 length = resolveValues.length,
nicholas@103 3324
nicholas@103 3325 // the count of uncompleted subordinates
nicholas@103 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nicholas@103 3327
nicholas@103 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nicholas@103 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nicholas@103 3330
nicholas@103 3331 // Update function for both resolve and progress values
nicholas@103 3332 updateFunc = function( i, contexts, values ) {
nicholas@103 3333 return function( value ) {
nicholas@103 3334 contexts[ i ] = this;
nicholas@103 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nicholas@103 3336 if ( values === progressValues ) {
nicholas@103 3337 deferred.notifyWith( contexts, values );
nicholas@103 3338 } else if ( !( --remaining ) ) {
nicholas@103 3339 deferred.resolveWith( contexts, values );
nicholas@103 3340 }
nicholas@103 3341 };
nicholas@103 3342 },
nicholas@103 3343
nicholas@103 3344 progressValues, progressContexts, resolveContexts;
nicholas@103 3345
nicholas@103 3346 // Add listeners to Deferred subordinates; treat others as resolved
nicholas@103 3347 if ( length > 1 ) {
nicholas@103 3348 progressValues = new Array( length );
nicholas@103 3349 progressContexts = new Array( length );
nicholas@103 3350 resolveContexts = new Array( length );
nicholas@103 3351 for ( ; i < length; i++ ) {
nicholas@103 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nicholas@103 3353 resolveValues[ i ].promise()
nicholas@103 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nicholas@103 3355 .fail( deferred.reject )
nicholas@103 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nicholas@103 3357 } else {
nicholas@103 3358 --remaining;
nicholas@103 3359 }
nicholas@103 3360 }
nicholas@103 3361 }
nicholas@103 3362
nicholas@103 3363 // If we're not waiting on anything, resolve the master
nicholas@103 3364 if ( !remaining ) {
nicholas@103 3365 deferred.resolveWith( resolveContexts, resolveValues );
nicholas@103 3366 }
nicholas@103 3367
nicholas@103 3368 return deferred.promise();
nicholas@103 3369 }
nicholas@103 3370 });
nicholas@103 3371
nicholas@103 3372
nicholas@103 3373 // The deferred used on DOM ready
nicholas@103 3374 var readyList;
nicholas@103 3375
nicholas@103 3376 jQuery.fn.ready = function( fn ) {
nicholas@103 3377 // Add the callback
nicholas@103 3378 jQuery.ready.promise().done( fn );
nicholas@103 3379
nicholas@103 3380 return this;
nicholas@103 3381 };
nicholas@103 3382
nicholas@103 3383 jQuery.extend({
nicholas@103 3384 // Is the DOM ready to be used? Set to true once it occurs.
nicholas@103 3385 isReady: false,
nicholas@103 3386
nicholas@103 3387 // A counter to track how many items to wait for before
nicholas@103 3388 // the ready event fires. See #6781
nicholas@103 3389 readyWait: 1,
nicholas@103 3390
nicholas@103 3391 // Hold (or release) the ready event
nicholas@103 3392 holdReady: function( hold ) {
nicholas@103 3393 if ( hold ) {
nicholas@103 3394 jQuery.readyWait++;
nicholas@103 3395 } else {
nicholas@103 3396 jQuery.ready( true );
nicholas@103 3397 }
nicholas@103 3398 },
nicholas@103 3399
nicholas@103 3400 // Handle when the DOM is ready
nicholas@103 3401 ready: function( wait ) {
nicholas@103 3402
nicholas@103 3403 // Abort if there are pending holds or we're already ready
nicholas@103 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nicholas@103 3405 return;
nicholas@103 3406 }
nicholas@103 3407
nicholas@103 3408 // Remember that the DOM is ready
nicholas@103 3409 jQuery.isReady = true;
nicholas@103 3410
nicholas@103 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nicholas@103 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nicholas@103 3413 return;
nicholas@103 3414 }
nicholas@103 3415
nicholas@103 3416 // If there are functions bound, to execute
nicholas@103 3417 readyList.resolveWith( document, [ jQuery ] );
nicholas@103 3418
nicholas@103 3419 // Trigger any bound ready events
nicholas@103 3420 if ( jQuery.fn.triggerHandler ) {
nicholas@103 3421 jQuery( document ).triggerHandler( "ready" );
nicholas@103 3422 jQuery( document ).off( "ready" );
nicholas@103 3423 }
nicholas@103 3424 }
nicholas@103 3425 });
nicholas@103 3426
nicholas@103 3427 /**
nicholas@103 3428 * The ready event handler and self cleanup method
nicholas@103 3429 */
nicholas@103 3430 function completed() {
nicholas@103 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nicholas@103 3432 window.removeEventListener( "load", completed, false );
nicholas@103 3433 jQuery.ready();
nicholas@103 3434 }
nicholas@103 3435
nicholas@103 3436 jQuery.ready.promise = function( obj ) {
nicholas@103 3437 if ( !readyList ) {
nicholas@103 3438
nicholas@103 3439 readyList = jQuery.Deferred();
nicholas@103 3440
nicholas@103 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nicholas@103 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nicholas@103 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nicholas@103 3444 if ( document.readyState === "complete" ) {
nicholas@103 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nicholas@103 3446 setTimeout( jQuery.ready );
nicholas@103 3447
nicholas@103 3448 } else {
nicholas@103 3449
nicholas@103 3450 // Use the handy event callback
nicholas@103 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nicholas@103 3452
nicholas@103 3453 // A fallback to window.onload, that will always work
nicholas@103 3454 window.addEventListener( "load", completed, false );
nicholas@103 3455 }
nicholas@103 3456 }
nicholas@103 3457 return readyList.promise( obj );
nicholas@103 3458 };
nicholas@103 3459
nicholas@103 3460 // Kick off the DOM ready check even if the user does not
nicholas@103 3461 jQuery.ready.promise();
nicholas@103 3462
nicholas@103 3463
nicholas@103 3464
nicholas@103 3465
nicholas@103 3466 // Multifunctional method to get and set values of a collection
nicholas@103 3467 // The value/s can optionally be executed if it's a function
nicholas@103 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nicholas@103 3469 var i = 0,
nicholas@103 3470 len = elems.length,
nicholas@103 3471 bulk = key == null;
nicholas@103 3472
nicholas@103 3473 // Sets many values
nicholas@103 3474 if ( jQuery.type( key ) === "object" ) {
nicholas@103 3475 chainable = true;
nicholas@103 3476 for ( i in key ) {
nicholas@103 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nicholas@103 3478 }
nicholas@103 3479
nicholas@103 3480 // Sets one value
nicholas@103 3481 } else if ( value !== undefined ) {
nicholas@103 3482 chainable = true;
nicholas@103 3483
nicholas@103 3484 if ( !jQuery.isFunction( value ) ) {
nicholas@103 3485 raw = true;
nicholas@103 3486 }
nicholas@103 3487
nicholas@103 3488 if ( bulk ) {
nicholas@103 3489 // Bulk operations run against the entire set
nicholas@103 3490 if ( raw ) {
nicholas@103 3491 fn.call( elems, value );
nicholas@103 3492 fn = null;
nicholas@103 3493
nicholas@103 3494 // ...except when executing function values
nicholas@103 3495 } else {
nicholas@103 3496 bulk = fn;
nicholas@103 3497 fn = function( elem, key, value ) {
nicholas@103 3498 return bulk.call( jQuery( elem ), value );
nicholas@103 3499 };
nicholas@103 3500 }
nicholas@103 3501 }
nicholas@103 3502
nicholas@103 3503 if ( fn ) {
nicholas@103 3504 for ( ; i < len; i++ ) {
nicholas@103 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nicholas@103 3506 }
nicholas@103 3507 }
nicholas@103 3508 }
nicholas@103 3509
nicholas@103 3510 return chainable ?
nicholas@103 3511 elems :
nicholas@103 3512
nicholas@103 3513 // Gets
nicholas@103 3514 bulk ?
nicholas@103 3515 fn.call( elems ) :
nicholas@103 3516 len ? fn( elems[0], key ) : emptyGet;
nicholas@103 3517 };
nicholas@103 3518
nicholas@103 3519
nicholas@103 3520 /**
nicholas@103 3521 * Determines whether an object can have data
nicholas@103 3522 */
nicholas@103 3523 jQuery.acceptData = function( owner ) {
nicholas@103 3524 // Accepts only:
nicholas@103 3525 // - Node
nicholas@103 3526 // - Node.ELEMENT_NODE
nicholas@103 3527 // - Node.DOCUMENT_NODE
nicholas@103 3528 // - Object
nicholas@103 3529 // - Any
nicholas@103 3530 /* jshint -W018 */
nicholas@103 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nicholas@103 3532 };
nicholas@103 3533
nicholas@103 3534
nicholas@103 3535 function Data() {
nicholas@103 3536 // Support: Android<4,
nicholas@103 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nicholas@103 3538 // return new empty object instead with no [[set]] accessor
nicholas@103 3539 Object.defineProperty( this.cache = {}, 0, {
nicholas@103 3540 get: function() {
nicholas@103 3541 return {};
nicholas@103 3542 }
nicholas@103 3543 });
nicholas@103 3544
nicholas@103 3545 this.expando = jQuery.expando + Data.uid++;
nicholas@103 3546 }
nicholas@103 3547
nicholas@103 3548 Data.uid = 1;
nicholas@103 3549 Data.accepts = jQuery.acceptData;
nicholas@103 3550
nicholas@103 3551 Data.prototype = {
nicholas@103 3552 key: function( owner ) {
nicholas@103 3553 // We can accept data for non-element nodes in modern browsers,
nicholas@103 3554 // but we should not, see #8335.
nicholas@103 3555 // Always return the key for a frozen object.
nicholas@103 3556 if ( !Data.accepts( owner ) ) {
nicholas@103 3557 return 0;
nicholas@103 3558 }
nicholas@103 3559
nicholas@103 3560 var descriptor = {},
nicholas@103 3561 // Check if the owner object already has a cache key
nicholas@103 3562 unlock = owner[ this.expando ];
nicholas@103 3563
nicholas@103 3564 // If not, create one
nicholas@103 3565 if ( !unlock ) {
nicholas@103 3566 unlock = Data.uid++;
nicholas@103 3567
nicholas@103 3568 // Secure it in a non-enumerable, non-writable property
nicholas@103 3569 try {
nicholas@103 3570 descriptor[ this.expando ] = { value: unlock };
nicholas@103 3571 Object.defineProperties( owner, descriptor );
nicholas@103 3572
nicholas@103 3573 // Support: Android<4
nicholas@103 3574 // Fallback to a less secure definition
nicholas@103 3575 } catch ( e ) {
nicholas@103 3576 descriptor[ this.expando ] = unlock;
nicholas@103 3577 jQuery.extend( owner, descriptor );
nicholas@103 3578 }
nicholas@103 3579 }
nicholas@103 3580
nicholas@103 3581 // Ensure the cache object
nicholas@103 3582 if ( !this.cache[ unlock ] ) {
nicholas@103 3583 this.cache[ unlock ] = {};
nicholas@103 3584 }
nicholas@103 3585
nicholas@103 3586 return unlock;
nicholas@103 3587 },
nicholas@103 3588 set: function( owner, data, value ) {
nicholas@103 3589 var prop,
nicholas@103 3590 // There may be an unlock assigned to this node,
nicholas@103 3591 // if there is no entry for this "owner", create one inline
nicholas@103 3592 // and set the unlock as though an owner entry had always existed
nicholas@103 3593 unlock = this.key( owner ),
nicholas@103 3594 cache = this.cache[ unlock ];
nicholas@103 3595
nicholas@103 3596 // Handle: [ owner, key, value ] args
nicholas@103 3597 if ( typeof data === "string" ) {
nicholas@103 3598 cache[ data ] = value;
nicholas@103 3599
nicholas@103 3600 // Handle: [ owner, { properties } ] args
nicholas@103 3601 } else {
nicholas@103 3602 // Fresh assignments by object are shallow copied
nicholas@103 3603 if ( jQuery.isEmptyObject( cache ) ) {
nicholas@103 3604 jQuery.extend( this.cache[ unlock ], data );
nicholas@103 3605 // Otherwise, copy the properties one-by-one to the cache object
nicholas@103 3606 } else {
nicholas@103 3607 for ( prop in data ) {
nicholas@103 3608 cache[ prop ] = data[ prop ];
nicholas@103 3609 }
nicholas@103 3610 }
nicholas@103 3611 }
nicholas@103 3612 return cache;
nicholas@103 3613 },
nicholas@103 3614 get: function( owner, key ) {
nicholas@103 3615 // Either a valid cache is found, or will be created.
nicholas@103 3616 // New caches will be created and the unlock returned,
nicholas@103 3617 // allowing direct access to the newly created
nicholas@103 3618 // empty data object. A valid owner object must be provided.
nicholas@103 3619 var cache = this.cache[ this.key( owner ) ];
nicholas@103 3620
nicholas@103 3621 return key === undefined ?
nicholas@103 3622 cache : cache[ key ];
nicholas@103 3623 },
nicholas@103 3624 access: function( owner, key, value ) {
nicholas@103 3625 var stored;
nicholas@103 3626 // In cases where either:
nicholas@103 3627 //
nicholas@103 3628 // 1. No key was specified
nicholas@103 3629 // 2. A string key was specified, but no value provided
nicholas@103 3630 //
nicholas@103 3631 // Take the "read" path and allow the get method to determine
nicholas@103 3632 // which value to return, respectively either:
nicholas@103 3633 //
nicholas@103 3634 // 1. The entire cache object
nicholas@103 3635 // 2. The data stored at the key
nicholas@103 3636 //
nicholas@103 3637 if ( key === undefined ||
nicholas@103 3638 ((key && typeof key === "string") && value === undefined) ) {
nicholas@103 3639
nicholas@103 3640 stored = this.get( owner, key );
nicholas@103 3641
nicholas@103 3642 return stored !== undefined ?
nicholas@103 3643 stored : this.get( owner, jQuery.camelCase(key) );
nicholas@103 3644 }
nicholas@103 3645
nicholas@103 3646 // [*]When the key is not a string, or both a key and value
nicholas@103 3647 // are specified, set or extend (existing objects) with either:
nicholas@103 3648 //
nicholas@103 3649 // 1. An object of properties
nicholas@103 3650 // 2. A key and value
nicholas@103 3651 //
nicholas@103 3652 this.set( owner, key, value );
nicholas@103 3653
nicholas@103 3654 // Since the "set" path can have two possible entry points
nicholas@103 3655 // return the expected data based on which path was taken[*]
nicholas@103 3656 return value !== undefined ? value : key;
nicholas@103 3657 },
nicholas@103 3658 remove: function( owner, key ) {
nicholas@103 3659 var i, name, camel,
nicholas@103 3660 unlock = this.key( owner ),
nicholas@103 3661 cache = this.cache[ unlock ];
nicholas@103 3662
nicholas@103 3663 if ( key === undefined ) {
nicholas@103 3664 this.cache[ unlock ] = {};
nicholas@103 3665
nicholas@103 3666 } else {
nicholas@103 3667 // Support array or space separated string of keys
nicholas@103 3668 if ( jQuery.isArray( key ) ) {
nicholas@103 3669 // If "name" is an array of keys...
nicholas@103 3670 // When data is initially created, via ("key", "val") signature,
nicholas@103 3671 // keys will be converted to camelCase.
nicholas@103 3672 // Since there is no way to tell _how_ a key was added, remove
nicholas@103 3673 // both plain key and camelCase key. #12786
nicholas@103 3674 // This will only penalize the array argument path.
nicholas@103 3675 name = key.concat( key.map( jQuery.camelCase ) );
nicholas@103 3676 } else {
nicholas@103 3677 camel = jQuery.camelCase( key );
nicholas@103 3678 // Try the string as a key before any manipulation
nicholas@103 3679 if ( key in cache ) {
nicholas@103 3680 name = [ key, camel ];
nicholas@103 3681 } else {
nicholas@103 3682 // If a key with the spaces exists, use it.
nicholas@103 3683 // Otherwise, create an array by matching non-whitespace
nicholas@103 3684 name = camel;
nicholas@103 3685 name = name in cache ?
nicholas@103 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nicholas@103 3687 }
nicholas@103 3688 }
nicholas@103 3689
nicholas@103 3690 i = name.length;
nicholas@103 3691 while ( i-- ) {
nicholas@103 3692 delete cache[ name[ i ] ];
nicholas@103 3693 }
nicholas@103 3694 }
nicholas@103 3695 },
nicholas@103 3696 hasData: function( owner ) {
nicholas@103 3697 return !jQuery.isEmptyObject(
nicholas@103 3698 this.cache[ owner[ this.expando ] ] || {}
nicholas@103 3699 );
nicholas@103 3700 },
nicholas@103 3701 discard: function( owner ) {
nicholas@103 3702 if ( owner[ this.expando ] ) {
nicholas@103 3703 delete this.cache[ owner[ this.expando ] ];
nicholas@103 3704 }
nicholas@103 3705 }
nicholas@103 3706 };
nicholas@103 3707 var data_priv = new Data();
nicholas@103 3708
nicholas@103 3709 var data_user = new Data();
nicholas@103 3710
nicholas@103 3711
nicholas@103 3712
nicholas@103 3713 // Implementation Summary
nicholas@103 3714 //
nicholas@103 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nicholas@103 3716 // 2. Improve the module's maintainability by reducing the storage
nicholas@103 3717 // paths to a single mechanism.
nicholas@103 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nicholas@103 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nicholas@103 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nicholas@103 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nicholas@103 3722
nicholas@103 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nicholas@103 3724 rmultiDash = /([A-Z])/g;
nicholas@103 3725
nicholas@103 3726 function dataAttr( elem, key, data ) {
nicholas@103 3727 var name;
nicholas@103 3728
nicholas@103 3729 // If nothing was found internally, try to fetch any
nicholas@103 3730 // data from the HTML5 data-* attribute
nicholas@103 3731 if ( data === undefined && elem.nodeType === 1 ) {
nicholas@103 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nicholas@103 3733 data = elem.getAttribute( name );
nicholas@103 3734
nicholas@103 3735 if ( typeof data === "string" ) {
nicholas@103 3736 try {
nicholas@103 3737 data = data === "true" ? true :
nicholas@103 3738 data === "false" ? false :
nicholas@103 3739 data === "null" ? null :
nicholas@103 3740 // Only convert to a number if it doesn't change the string
nicholas@103 3741 +data + "" === data ? +data :
nicholas@103 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nicholas@103 3743 data;
nicholas@103 3744 } catch( e ) {}
nicholas@103 3745
nicholas@103 3746 // Make sure we set the data so it isn't changed later
nicholas@103 3747 data_user.set( elem, key, data );
nicholas@103 3748 } else {
nicholas@103 3749 data = undefined;
nicholas@103 3750 }
nicholas@103 3751 }
nicholas@103 3752 return data;
nicholas@103 3753 }
nicholas@103 3754
nicholas@103 3755 jQuery.extend({
nicholas@103 3756 hasData: function( elem ) {
nicholas@103 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nicholas@103 3758 },
nicholas@103 3759
nicholas@103 3760 data: function( elem, name, data ) {
nicholas@103 3761 return data_user.access( elem, name, data );
nicholas@103 3762 },
nicholas@103 3763
nicholas@103 3764 removeData: function( elem, name ) {
nicholas@103 3765 data_user.remove( elem, name );
nicholas@103 3766 },
nicholas@103 3767
nicholas@103 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nicholas@103 3769 // with direct calls to data_priv methods, these can be deprecated.
nicholas@103 3770 _data: function( elem, name, data ) {
nicholas@103 3771 return data_priv.access( elem, name, data );
nicholas@103 3772 },
nicholas@103 3773
nicholas@103 3774 _removeData: function( elem, name ) {
nicholas@103 3775 data_priv.remove( elem, name );
nicholas@103 3776 }
nicholas@103 3777 });
nicholas@103 3778
nicholas@103 3779 jQuery.fn.extend({
nicholas@103 3780 data: function( key, value ) {
nicholas@103 3781 var i, name, data,
nicholas@103 3782 elem = this[ 0 ],
nicholas@103 3783 attrs = elem && elem.attributes;
nicholas@103 3784
nicholas@103 3785 // Gets all values
nicholas@103 3786 if ( key === undefined ) {
nicholas@103 3787 if ( this.length ) {
nicholas@103 3788 data = data_user.get( elem );
nicholas@103 3789
nicholas@103 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nicholas@103 3791 i = attrs.length;
nicholas@103 3792 while ( i-- ) {
nicholas@103 3793
nicholas@103 3794 // Support: IE11+
nicholas@103 3795 // The attrs elements can be null (#14894)
nicholas@103 3796 if ( attrs[ i ] ) {
nicholas@103 3797 name = attrs[ i ].name;
nicholas@103 3798 if ( name.indexOf( "data-" ) === 0 ) {
nicholas@103 3799 name = jQuery.camelCase( name.slice(5) );
nicholas@103 3800 dataAttr( elem, name, data[ name ] );
nicholas@103 3801 }
nicholas@103 3802 }
nicholas@103 3803 }
nicholas@103 3804 data_priv.set( elem, "hasDataAttrs", true );
nicholas@103 3805 }
nicholas@103 3806 }
nicholas@103 3807
nicholas@103 3808 return data;
nicholas@103 3809 }
nicholas@103 3810
nicholas@103 3811 // Sets multiple values
nicholas@103 3812 if ( typeof key === "object" ) {
nicholas@103 3813 return this.each(function() {
nicholas@103 3814 data_user.set( this, key );
nicholas@103 3815 });
nicholas@103 3816 }
nicholas@103 3817
nicholas@103 3818 return access( this, function( value ) {
nicholas@103 3819 var data,
nicholas@103 3820 camelKey = jQuery.camelCase( key );
nicholas@103 3821
nicholas@103 3822 // The calling jQuery object (element matches) is not empty
nicholas@103 3823 // (and therefore has an element appears at this[ 0 ]) and the
nicholas@103 3824 // `value` parameter was not undefined. An empty jQuery object
nicholas@103 3825 // will result in `undefined` for elem = this[ 0 ] which will
nicholas@103 3826 // throw an exception if an attempt to read a data cache is made.
nicholas@103 3827 if ( elem && value === undefined ) {
nicholas@103 3828 // Attempt to get data from the cache
nicholas@103 3829 // with the key as-is
nicholas@103 3830 data = data_user.get( elem, key );
nicholas@103 3831 if ( data !== undefined ) {
nicholas@103 3832 return data;
nicholas@103 3833 }
nicholas@103 3834
nicholas@103 3835 // Attempt to get data from the cache
nicholas@103 3836 // with the key camelized
nicholas@103 3837 data = data_user.get( elem, camelKey );
nicholas@103 3838 if ( data !== undefined ) {
nicholas@103 3839 return data;
nicholas@103 3840 }
nicholas@103 3841
nicholas@103 3842 // Attempt to "discover" the data in
nicholas@103 3843 // HTML5 custom data-* attrs
nicholas@103 3844 data = dataAttr( elem, camelKey, undefined );
nicholas@103 3845 if ( data !== undefined ) {
nicholas@103 3846 return data;
nicholas@103 3847 }
nicholas@103 3848
nicholas@103 3849 // We tried really hard, but the data doesn't exist.
nicholas@103 3850 return;
nicholas@103 3851 }
nicholas@103 3852
nicholas@103 3853 // Set the data...
nicholas@103 3854 this.each(function() {
nicholas@103 3855 // First, attempt to store a copy or reference of any
nicholas@103 3856 // data that might've been store with a camelCased key.
nicholas@103 3857 var data = data_user.get( this, camelKey );
nicholas@103 3858
nicholas@103 3859 // For HTML5 data-* attribute interop, we have to
nicholas@103 3860 // store property names with dashes in a camelCase form.
nicholas@103 3861 // This might not apply to all properties...*
nicholas@103 3862 data_user.set( this, camelKey, value );
nicholas@103 3863
nicholas@103 3864 // *... In the case of properties that might _actually_
nicholas@103 3865 // have dashes, we need to also store a copy of that
nicholas@103 3866 // unchanged property.
nicholas@103 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nicholas@103 3868 data_user.set( this, key, value );
nicholas@103 3869 }
nicholas@103 3870 });
nicholas@103 3871 }, null, value, arguments.length > 1, null, true );
nicholas@103 3872 },
nicholas@103 3873
nicholas@103 3874 removeData: function( key ) {
nicholas@103 3875 return this.each(function() {
nicholas@103 3876 data_user.remove( this, key );
nicholas@103 3877 });
nicholas@103 3878 }
nicholas@103 3879 });
nicholas@103 3880
nicholas@103 3881
nicholas@103 3882 jQuery.extend({
nicholas@103 3883 queue: function( elem, type, data ) {
nicholas@103 3884 var queue;
nicholas@103 3885
nicholas@103 3886 if ( elem ) {
nicholas@103 3887 type = ( type || "fx" ) + "queue";
nicholas@103 3888 queue = data_priv.get( elem, type );
nicholas@103 3889
nicholas@103 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nicholas@103 3891 if ( data ) {
nicholas@103 3892 if ( !queue || jQuery.isArray( data ) ) {
nicholas@103 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nicholas@103 3894 } else {
nicholas@103 3895 queue.push( data );
nicholas@103 3896 }
nicholas@103 3897 }
nicholas@103 3898 return queue || [];
nicholas@103 3899 }
nicholas@103 3900 },
nicholas@103 3901
nicholas@103 3902 dequeue: function( elem, type ) {
nicholas@103 3903 type = type || "fx";
nicholas@103 3904
nicholas@103 3905 var queue = jQuery.queue( elem, type ),
nicholas@103 3906 startLength = queue.length,
nicholas@103 3907 fn = queue.shift(),
nicholas@103 3908 hooks = jQuery._queueHooks( elem, type ),
nicholas@103 3909 next = function() {
nicholas@103 3910 jQuery.dequeue( elem, type );
nicholas@103 3911 };
nicholas@103 3912
nicholas@103 3913 // If the fx queue is dequeued, always remove the progress sentinel
nicholas@103 3914 if ( fn === "inprogress" ) {
nicholas@103 3915 fn = queue.shift();
nicholas@103 3916 startLength--;
nicholas@103 3917 }
nicholas@103 3918
nicholas@103 3919 if ( fn ) {
nicholas@103 3920
nicholas@103 3921 // Add a progress sentinel to prevent the fx queue from being
nicholas@103 3922 // automatically dequeued
nicholas@103 3923 if ( type === "fx" ) {
nicholas@103 3924 queue.unshift( "inprogress" );
nicholas@103 3925 }
nicholas@103 3926
nicholas@103 3927 // Clear up the last queue stop function
nicholas@103 3928 delete hooks.stop;
nicholas@103 3929 fn.call( elem, next, hooks );
nicholas@103 3930 }
nicholas@103 3931
nicholas@103 3932 if ( !startLength && hooks ) {
nicholas@103 3933 hooks.empty.fire();
nicholas@103 3934 }
nicholas@103 3935 },
nicholas@103 3936
nicholas@103 3937 // Not public - generate a queueHooks object, or return the current one
nicholas@103 3938 _queueHooks: function( elem, type ) {
nicholas@103 3939 var key = type + "queueHooks";
nicholas@103 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nicholas@103 3941 empty: jQuery.Callbacks("once memory").add(function() {
nicholas@103 3942 data_priv.remove( elem, [ type + "queue", key ] );
nicholas@103 3943 })
nicholas@103 3944 });
nicholas@103 3945 }
nicholas@103 3946 });
nicholas@103 3947
nicholas@103 3948 jQuery.fn.extend({
nicholas@103 3949 queue: function( type, data ) {
nicholas@103 3950 var setter = 2;
nicholas@103 3951
nicholas@103 3952 if ( typeof type !== "string" ) {
nicholas@103 3953 data = type;
nicholas@103 3954 type = "fx";
nicholas@103 3955 setter--;
nicholas@103 3956 }
nicholas@103 3957
nicholas@103 3958 if ( arguments.length < setter ) {
nicholas@103 3959 return jQuery.queue( this[0], type );
nicholas@103 3960 }
nicholas@103 3961
nicholas@103 3962 return data === undefined ?
nicholas@103 3963 this :
nicholas@103 3964 this.each(function() {
nicholas@103 3965 var queue = jQuery.queue( this, type, data );
nicholas@103 3966
nicholas@103 3967 // Ensure a hooks for this queue
nicholas@103 3968 jQuery._queueHooks( this, type );
nicholas@103 3969
nicholas@103 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nicholas@103 3971 jQuery.dequeue( this, type );
nicholas@103 3972 }
nicholas@103 3973 });
nicholas@103 3974 },
nicholas@103 3975 dequeue: function( type ) {
nicholas@103 3976 return this.each(function() {
nicholas@103 3977 jQuery.dequeue( this, type );
nicholas@103 3978 });
nicholas@103 3979 },
nicholas@103 3980 clearQueue: function( type ) {
nicholas@103 3981 return this.queue( type || "fx", [] );
nicholas@103 3982 },
nicholas@103 3983 // Get a promise resolved when queues of a certain type
nicholas@103 3984 // are emptied (fx is the type by default)
nicholas@103 3985 promise: function( type, obj ) {
nicholas@103 3986 var tmp,
nicholas@103 3987 count = 1,
nicholas@103 3988 defer = jQuery.Deferred(),
nicholas@103 3989 elements = this,
nicholas@103 3990 i = this.length,
nicholas@103 3991 resolve = function() {
nicholas@103 3992 if ( !( --count ) ) {
nicholas@103 3993 defer.resolveWith( elements, [ elements ] );
nicholas@103 3994 }
nicholas@103 3995 };
nicholas@103 3996
nicholas@103 3997 if ( typeof type !== "string" ) {
nicholas@103 3998 obj = type;
nicholas@103 3999 type = undefined;
nicholas@103 4000 }
nicholas@103 4001 type = type || "fx";
nicholas@103 4002
nicholas@103 4003 while ( i-- ) {
nicholas@103 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nicholas@103 4005 if ( tmp && tmp.empty ) {
nicholas@103 4006 count++;
nicholas@103 4007 tmp.empty.add( resolve );
nicholas@103 4008 }
nicholas@103 4009 }
nicholas@103 4010 resolve();
nicholas@103 4011 return defer.promise( obj );
nicholas@103 4012 }
nicholas@103 4013 });
nicholas@103 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nicholas@103 4015
nicholas@103 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nicholas@103 4017
nicholas@103 4018 var isHidden = function( elem, el ) {
nicholas@103 4019 // isHidden might be called from jQuery#filter function;
nicholas@103 4020 // in that case, element will be second argument
nicholas@103 4021 elem = el || elem;
nicholas@103 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nicholas@103 4023 };
nicholas@103 4024
nicholas@103 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nicholas@103 4026
nicholas@103 4027
nicholas@103 4028
nicholas@103 4029 (function() {
nicholas@103 4030 var fragment = document.createDocumentFragment(),
nicholas@103 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nicholas@103 4032 input = document.createElement( "input" );
nicholas@103 4033
nicholas@103 4034 // Support: Safari<=5.1
nicholas@103 4035 // Check state lost if the name is set (#11217)
nicholas@103 4036 // Support: Windows Web Apps (WWA)
nicholas@103 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nicholas@103 4038 input.setAttribute( "type", "radio" );
nicholas@103 4039 input.setAttribute( "checked", "checked" );
nicholas@103 4040 input.setAttribute( "name", "t" );
nicholas@103 4041
nicholas@103 4042 div.appendChild( input );
nicholas@103 4043
nicholas@103 4044 // Support: Safari<=5.1, Android<4.2
nicholas@103 4045 // Older WebKit doesn't clone checked state correctly in fragments
nicholas@103 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nicholas@103 4047
nicholas@103 4048 // Support: IE<=11+
nicholas@103 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nicholas@103 4050 div.innerHTML = "<textarea>x</textarea>";
nicholas@103 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nicholas@103 4052 })();
nicholas@103 4053 var strundefined = typeof undefined;
nicholas@103 4054
nicholas@103 4055
nicholas@103 4056
nicholas@103 4057 support.focusinBubbles = "onfocusin" in window;
nicholas@103 4058
nicholas@103 4059
nicholas@103 4060 var
nicholas@103 4061 rkeyEvent = /^key/,
nicholas@103 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nicholas@103 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nicholas@103 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nicholas@103 4065
nicholas@103 4066 function returnTrue() {
nicholas@103 4067 return true;
nicholas@103 4068 }
nicholas@103 4069
nicholas@103 4070 function returnFalse() {
nicholas@103 4071 return false;
nicholas@103 4072 }
nicholas@103 4073
nicholas@103 4074 function safeActiveElement() {
nicholas@103 4075 try {
nicholas@103 4076 return document.activeElement;
nicholas@103 4077 } catch ( err ) { }
nicholas@103 4078 }
nicholas@103 4079
nicholas@103 4080 /*
nicholas@103 4081 * Helper functions for managing events -- not part of the public interface.
nicholas@103 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nicholas@103 4083 */
nicholas@103 4084 jQuery.event = {
nicholas@103 4085
nicholas@103 4086 global: {},
nicholas@103 4087
nicholas@103 4088 add: function( elem, types, handler, data, selector ) {
nicholas@103 4089
nicholas@103 4090 var handleObjIn, eventHandle, tmp,
nicholas@103 4091 events, t, handleObj,
nicholas@103 4092 special, handlers, type, namespaces, origType,
nicholas@103 4093 elemData = data_priv.get( elem );
nicholas@103 4094
nicholas@103 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nicholas@103 4096 if ( !elemData ) {
nicholas@103 4097 return;
nicholas@103 4098 }
nicholas@103 4099
nicholas@103 4100 // Caller can pass in an object of custom data in lieu of the handler
nicholas@103 4101 if ( handler.handler ) {
nicholas@103 4102 handleObjIn = handler;
nicholas@103 4103 handler = handleObjIn.handler;
nicholas@103 4104 selector = handleObjIn.selector;
nicholas@103 4105 }
nicholas@103 4106
nicholas@103 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nicholas@103 4108 if ( !handler.guid ) {
nicholas@103 4109 handler.guid = jQuery.guid++;
nicholas@103 4110 }
nicholas@103 4111
nicholas@103 4112 // Init the element's event structure and main handler, if this is the first
nicholas@103 4113 if ( !(events = elemData.events) ) {
nicholas@103 4114 events = elemData.events = {};
nicholas@103 4115 }
nicholas@103 4116 if ( !(eventHandle = elemData.handle) ) {
nicholas@103 4117 eventHandle = elemData.handle = function( e ) {
nicholas@103 4118 // Discard the second event of a jQuery.event.trigger() and
nicholas@103 4119 // when an event is called after a page has unloaded
nicholas@103 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nicholas@103 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nicholas@103 4122 };
nicholas@103 4123 }
nicholas@103 4124
nicholas@103 4125 // Handle multiple events separated by a space
nicholas@103 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nicholas@103 4127 t = types.length;
nicholas@103 4128 while ( t-- ) {
nicholas@103 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nicholas@103 4130 type = origType = tmp[1];
nicholas@103 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nicholas@103 4132
nicholas@103 4133 // There *must* be a type, no attaching namespace-only handlers
nicholas@103 4134 if ( !type ) {
nicholas@103 4135 continue;
nicholas@103 4136 }
nicholas@103 4137
nicholas@103 4138 // If event changes its type, use the special event handlers for the changed type
nicholas@103 4139 special = jQuery.event.special[ type ] || {};
nicholas@103 4140
nicholas@103 4141 // If selector defined, determine special event api type, otherwise given type
nicholas@103 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nicholas@103 4143
nicholas@103 4144 // Update special based on newly reset type
nicholas@103 4145 special = jQuery.event.special[ type ] || {};
nicholas@103 4146
nicholas@103 4147 // handleObj is passed to all event handlers
nicholas@103 4148 handleObj = jQuery.extend({
nicholas@103 4149 type: type,
nicholas@103 4150 origType: origType,
nicholas@103 4151 data: data,
nicholas@103 4152 handler: handler,
nicholas@103 4153 guid: handler.guid,
nicholas@103 4154 selector: selector,
nicholas@103 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nicholas@103 4156 namespace: namespaces.join(".")
nicholas@103 4157 }, handleObjIn );
nicholas@103 4158
nicholas@103 4159 // Init the event handler queue if we're the first
nicholas@103 4160 if ( !(handlers = events[ type ]) ) {
nicholas@103 4161 handlers = events[ type ] = [];
nicholas@103 4162 handlers.delegateCount = 0;
nicholas@103 4163
nicholas@103 4164 // Only use addEventListener if the special events handler returns false
nicholas@103 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nicholas@103 4166 if ( elem.addEventListener ) {
nicholas@103 4167 elem.addEventListener( type, eventHandle, false );
nicholas@103 4168 }
nicholas@103 4169 }
nicholas@103 4170 }
nicholas@103 4171
nicholas@103 4172 if ( special.add ) {
nicholas@103 4173 special.add.call( elem, handleObj );
nicholas@103 4174
nicholas@103 4175 if ( !handleObj.handler.guid ) {
nicholas@103 4176 handleObj.handler.guid = handler.guid;
nicholas@103 4177 }
nicholas@103 4178 }
nicholas@103 4179
nicholas@103 4180 // Add to the element's handler list, delegates in front
nicholas@103 4181 if ( selector ) {
nicholas@103 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nicholas@103 4183 } else {
nicholas@103 4184 handlers.push( handleObj );
nicholas@103 4185 }
nicholas@103 4186
nicholas@103 4187 // Keep track of which events have ever been used, for event optimization
nicholas@103 4188 jQuery.event.global[ type ] = true;
nicholas@103 4189 }
nicholas@103 4190
nicholas@103 4191 },
nicholas@103 4192
nicholas@103 4193 // Detach an event or set of events from an element
nicholas@103 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nicholas@103 4195
nicholas@103 4196 var j, origCount, tmp,
nicholas@103 4197 events, t, handleObj,
nicholas@103 4198 special, handlers, type, namespaces, origType,
nicholas@103 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nicholas@103 4200
nicholas@103 4201 if ( !elemData || !(events = elemData.events) ) {
nicholas@103 4202 return;
nicholas@103 4203 }
nicholas@103 4204
nicholas@103 4205 // Once for each type.namespace in types; type may be omitted
nicholas@103 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nicholas@103 4207 t = types.length;
nicholas@103 4208 while ( t-- ) {
nicholas@103 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nicholas@103 4210 type = origType = tmp[1];
nicholas@103 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nicholas@103 4212
nicholas@103 4213 // Unbind all events (on this namespace, if provided) for the element
nicholas@103 4214 if ( !type ) {
nicholas@103 4215 for ( type in events ) {
nicholas@103 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nicholas@103 4217 }
nicholas@103 4218 continue;
nicholas@103 4219 }
nicholas@103 4220
nicholas@103 4221 special = jQuery.event.special[ type ] || {};
nicholas@103 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nicholas@103 4223 handlers = events[ type ] || [];
nicholas@103 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nicholas@103 4225
nicholas@103 4226 // Remove matching events
nicholas@103 4227 origCount = j = handlers.length;
nicholas@103 4228 while ( j-- ) {
nicholas@103 4229 handleObj = handlers[ j ];
nicholas@103 4230
nicholas@103 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nicholas@103 4232 ( !handler || handler.guid === handleObj.guid ) &&
nicholas@103 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nicholas@103 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nicholas@103 4235 handlers.splice( j, 1 );
nicholas@103 4236
nicholas@103 4237 if ( handleObj.selector ) {
nicholas@103 4238 handlers.delegateCount--;
nicholas@103 4239 }
nicholas@103 4240 if ( special.remove ) {
nicholas@103 4241 special.remove.call( elem, handleObj );
nicholas@103 4242 }
nicholas@103 4243 }
nicholas@103 4244 }
nicholas@103 4245
nicholas@103 4246 // Remove generic event handler if we removed something and no more handlers exist
nicholas@103 4247 // (avoids potential for endless recursion during removal of special event handlers)
nicholas@103 4248 if ( origCount && !handlers.length ) {
nicholas@103 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nicholas@103 4250 jQuery.removeEvent( elem, type, elemData.handle );
nicholas@103 4251 }
nicholas@103 4252
nicholas@103 4253 delete events[ type ];
nicholas@103 4254 }
nicholas@103 4255 }
nicholas@103 4256
nicholas@103 4257 // Remove the expando if it's no longer used
nicholas@103 4258 if ( jQuery.isEmptyObject( events ) ) {
nicholas@103 4259 delete elemData.handle;
nicholas@103 4260 data_priv.remove( elem, "events" );
nicholas@103 4261 }
nicholas@103 4262 },
nicholas@103 4263
nicholas@103 4264 trigger: function( event, data, elem, onlyHandlers ) {
nicholas@103 4265
nicholas@103 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nicholas@103 4267 eventPath = [ elem || document ],
nicholas@103 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nicholas@103 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nicholas@103 4270
nicholas@103 4271 cur = tmp = elem = elem || document;
nicholas@103 4272
nicholas@103 4273 // Don't do events on text and comment nodes
nicholas@103 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nicholas@103 4275 return;
nicholas@103 4276 }
nicholas@103 4277
nicholas@103 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nicholas@103 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nicholas@103 4280 return;
nicholas@103 4281 }
nicholas@103 4282
nicholas@103 4283 if ( type.indexOf(".") >= 0 ) {
nicholas@103 4284 // Namespaced trigger; create a regexp to match event type in handle()
nicholas@103 4285 namespaces = type.split(".");
nicholas@103 4286 type = namespaces.shift();
nicholas@103 4287 namespaces.sort();
nicholas@103 4288 }
nicholas@103 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nicholas@103 4290
nicholas@103 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nicholas@103 4292 event = event[ jQuery.expando ] ?
nicholas@103 4293 event :
nicholas@103 4294 new jQuery.Event( type, typeof event === "object" && event );
nicholas@103 4295
nicholas@103 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nicholas@103 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nicholas@103 4298 event.namespace = namespaces.join(".");
nicholas@103 4299 event.namespace_re = event.namespace ?
nicholas@103 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nicholas@103 4301 null;
nicholas@103 4302
nicholas@103 4303 // Clean up the event in case it is being reused
nicholas@103 4304 event.result = undefined;
nicholas@103 4305 if ( !event.target ) {
nicholas@103 4306 event.target = elem;
nicholas@103 4307 }
nicholas@103 4308
nicholas@103 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nicholas@103 4310 data = data == null ?
nicholas@103 4311 [ event ] :
nicholas@103 4312 jQuery.makeArray( data, [ event ] );
nicholas@103 4313
nicholas@103 4314 // Allow special events to draw outside the lines
nicholas@103 4315 special = jQuery.event.special[ type ] || {};
nicholas@103 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nicholas@103 4317 return;
nicholas@103 4318 }
nicholas@103 4319
nicholas@103 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nicholas@103 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nicholas@103 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nicholas@103 4323
nicholas@103 4324 bubbleType = special.delegateType || type;
nicholas@103 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nicholas@103 4326 cur = cur.parentNode;
nicholas@103 4327 }
nicholas@103 4328 for ( ; cur; cur = cur.parentNode ) {
nicholas@103 4329 eventPath.push( cur );
nicholas@103 4330 tmp = cur;
nicholas@103 4331 }
nicholas@103 4332
nicholas@103 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nicholas@103 4334 if ( tmp === (elem.ownerDocument || document) ) {
nicholas@103 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nicholas@103 4336 }
nicholas@103 4337 }
nicholas@103 4338
nicholas@103 4339 // Fire handlers on the event path
nicholas@103 4340 i = 0;
nicholas@103 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nicholas@103 4342
nicholas@103 4343 event.type = i > 1 ?
nicholas@103 4344 bubbleType :
nicholas@103 4345 special.bindType || type;
nicholas@103 4346
nicholas@103 4347 // jQuery handler
nicholas@103 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nicholas@103 4349 if ( handle ) {
nicholas@103 4350 handle.apply( cur, data );
nicholas@103 4351 }
nicholas@103 4352
nicholas@103 4353 // Native handler
nicholas@103 4354 handle = ontype && cur[ ontype ];
nicholas@103 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nicholas@103 4356 event.result = handle.apply( cur, data );
nicholas@103 4357 if ( event.result === false ) {
nicholas@103 4358 event.preventDefault();
nicholas@103 4359 }
nicholas@103 4360 }
nicholas@103 4361 }
nicholas@103 4362 event.type = type;
nicholas@103 4363
nicholas@103 4364 // If nobody prevented the default action, do it now
nicholas@103 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nicholas@103 4366
nicholas@103 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nicholas@103 4368 jQuery.acceptData( elem ) ) {
nicholas@103 4369
nicholas@103 4370 // Call a native DOM method on the target with the same name name as the event.
nicholas@103 4371 // Don't do default actions on window, that's where global variables be (#6170)
nicholas@103 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nicholas@103 4373
nicholas@103 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nicholas@103 4375 tmp = elem[ ontype ];
nicholas@103 4376
nicholas@103 4377 if ( tmp ) {
nicholas@103 4378 elem[ ontype ] = null;
nicholas@103 4379 }
nicholas@103 4380
nicholas@103 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nicholas@103 4382 jQuery.event.triggered = type;
nicholas@103 4383 elem[ type ]();
nicholas@103 4384 jQuery.event.triggered = undefined;
nicholas@103 4385
nicholas@103 4386 if ( tmp ) {
nicholas@103 4387 elem[ ontype ] = tmp;
nicholas@103 4388 }
nicholas@103 4389 }
nicholas@103 4390 }
nicholas@103 4391 }
nicholas@103 4392
nicholas@103 4393 return event.result;
nicholas@103 4394 },
nicholas@103 4395
nicholas@103 4396 dispatch: function( event ) {
nicholas@103 4397
nicholas@103 4398 // Make a writable jQuery.Event from the native event object
nicholas@103 4399 event = jQuery.event.fix( event );
nicholas@103 4400
nicholas@103 4401 var i, j, ret, matched, handleObj,
nicholas@103 4402 handlerQueue = [],
nicholas@103 4403 args = slice.call( arguments ),
nicholas@103 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nicholas@103 4405 special = jQuery.event.special[ event.type ] || {};
nicholas@103 4406
nicholas@103 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nicholas@103 4408 args[0] = event;
nicholas@103 4409 event.delegateTarget = this;
nicholas@103 4410
nicholas@103 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nicholas@103 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nicholas@103 4413 return;
nicholas@103 4414 }
nicholas@103 4415
nicholas@103 4416 // Determine handlers
nicholas@103 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nicholas@103 4418
nicholas@103 4419 // Run delegates first; they may want to stop propagation beneath us
nicholas@103 4420 i = 0;
nicholas@103 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nicholas@103 4422 event.currentTarget = matched.elem;
nicholas@103 4423
nicholas@103 4424 j = 0;
nicholas@103 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nicholas@103 4426
nicholas@103 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nicholas@103 4428 // a subset or equal to those in the bound event (both can have no namespace).
nicholas@103 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nicholas@103 4430
nicholas@103 4431 event.handleObj = handleObj;
nicholas@103 4432 event.data = handleObj.data;
nicholas@103 4433
nicholas@103 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nicholas@103 4435 .apply( matched.elem, args );
nicholas@103 4436
nicholas@103 4437 if ( ret !== undefined ) {
nicholas@103 4438 if ( (event.result = ret) === false ) {
nicholas@103 4439 event.preventDefault();
nicholas@103 4440 event.stopPropagation();
nicholas@103 4441 }
nicholas@103 4442 }
nicholas@103 4443 }
nicholas@103 4444 }
nicholas@103 4445 }
nicholas@103 4446
nicholas@103 4447 // Call the postDispatch hook for the mapped type
nicholas@103 4448 if ( special.postDispatch ) {
nicholas@103 4449 special.postDispatch.call( this, event );
nicholas@103 4450 }
nicholas@103 4451
nicholas@103 4452 return event.result;
nicholas@103 4453 },
nicholas@103 4454
nicholas@103 4455 handlers: function( event, handlers ) {
nicholas@103 4456 var i, matches, sel, handleObj,
nicholas@103 4457 handlerQueue = [],
nicholas@103 4458 delegateCount = handlers.delegateCount,
nicholas@103 4459 cur = event.target;
nicholas@103 4460
nicholas@103 4461 // Find delegate handlers
nicholas@103 4462 // Black-hole SVG <use> instance trees (#13180)
nicholas@103 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nicholas@103 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nicholas@103 4465
nicholas@103 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nicholas@103 4467
nicholas@103 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nicholas@103 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nicholas@103 4470 matches = [];
nicholas@103 4471 for ( i = 0; i < delegateCount; i++ ) {
nicholas@103 4472 handleObj = handlers[ i ];
nicholas@103 4473
nicholas@103 4474 // Don't conflict with Object.prototype properties (#13203)
nicholas@103 4475 sel = handleObj.selector + " ";
nicholas@103 4476
nicholas@103 4477 if ( matches[ sel ] === undefined ) {
nicholas@103 4478 matches[ sel ] = handleObj.needsContext ?
nicholas@103 4479 jQuery( sel, this ).index( cur ) >= 0 :
nicholas@103 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nicholas@103 4481 }
nicholas@103 4482 if ( matches[ sel ] ) {
nicholas@103 4483 matches.push( handleObj );
nicholas@103 4484 }
nicholas@103 4485 }
nicholas@103 4486 if ( matches.length ) {
nicholas@103 4487 handlerQueue.push({ elem: cur, handlers: matches });
nicholas@103 4488 }
nicholas@103 4489 }
nicholas@103 4490 }
nicholas@103 4491 }
nicholas@103 4492
nicholas@103 4493 // Add the remaining (directly-bound) handlers
nicholas@103 4494 if ( delegateCount < handlers.length ) {
nicholas@103 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nicholas@103 4496 }
nicholas@103 4497
nicholas@103 4498 return handlerQueue;
nicholas@103 4499 },
nicholas@103 4500
nicholas@103 4501 // Includes some event props shared by KeyEvent and MouseEvent
nicholas@103 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nicholas@103 4503
nicholas@103 4504 fixHooks: {},
nicholas@103 4505
nicholas@103 4506 keyHooks: {
nicholas@103 4507 props: "char charCode key keyCode".split(" "),
nicholas@103 4508 filter: function( event, original ) {
nicholas@103 4509
nicholas@103 4510 // Add which for key events
nicholas@103 4511 if ( event.which == null ) {
nicholas@103 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nicholas@103 4513 }
nicholas@103 4514
nicholas@103 4515 return event;
nicholas@103 4516 }
nicholas@103 4517 },
nicholas@103 4518
nicholas@103 4519 mouseHooks: {
nicholas@103 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nicholas@103 4521 filter: function( event, original ) {
nicholas@103 4522 var eventDoc, doc, body,
nicholas@103 4523 button = original.button;
nicholas@103 4524
nicholas@103 4525 // Calculate pageX/Y if missing and clientX/Y available
nicholas@103 4526 if ( event.pageX == null && original.clientX != null ) {
nicholas@103 4527 eventDoc = event.target.ownerDocument || document;
nicholas@103 4528 doc = eventDoc.documentElement;
nicholas@103 4529 body = eventDoc.body;
nicholas@103 4530
nicholas@103 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nicholas@103 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nicholas@103 4533 }
nicholas@103 4534
nicholas@103 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nicholas@103 4536 // Note: button is not normalized, so don't use it
nicholas@103 4537 if ( !event.which && button !== undefined ) {
nicholas@103 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nicholas@103 4539 }
nicholas@103 4540
nicholas@103 4541 return event;
nicholas@103 4542 }
nicholas@103 4543 },
nicholas@103 4544
nicholas@103 4545 fix: function( event ) {
nicholas@103 4546 if ( event[ jQuery.expando ] ) {
nicholas@103 4547 return event;
nicholas@103 4548 }
nicholas@103 4549
nicholas@103 4550 // Create a writable copy of the event object and normalize some properties
nicholas@103 4551 var i, prop, copy,
nicholas@103 4552 type = event.type,
nicholas@103 4553 originalEvent = event,
nicholas@103 4554 fixHook = this.fixHooks[ type ];
nicholas@103 4555
nicholas@103 4556 if ( !fixHook ) {
nicholas@103 4557 this.fixHooks[ type ] = fixHook =
nicholas@103 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nicholas@103 4559 rkeyEvent.test( type ) ? this.keyHooks :
nicholas@103 4560 {};
nicholas@103 4561 }
nicholas@103 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nicholas@103 4563
nicholas@103 4564 event = new jQuery.Event( originalEvent );
nicholas@103 4565
nicholas@103 4566 i = copy.length;
nicholas@103 4567 while ( i-- ) {
nicholas@103 4568 prop = copy[ i ];
nicholas@103 4569 event[ prop ] = originalEvent[ prop ];
nicholas@103 4570 }
nicholas@103 4571
nicholas@103 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nicholas@103 4573 // All events should have a target; Cordova deviceready doesn't
nicholas@103 4574 if ( !event.target ) {
nicholas@103 4575 event.target = document;
nicholas@103 4576 }
nicholas@103 4577
nicholas@103 4578 // Support: Safari 6.0+, Chrome<28
nicholas@103 4579 // Target should not be a text node (#504, #13143)
nicholas@103 4580 if ( event.target.nodeType === 3 ) {
nicholas@103 4581 event.target = event.target.parentNode;
nicholas@103 4582 }
nicholas@103 4583
nicholas@103 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nicholas@103 4585 },
nicholas@103 4586
nicholas@103 4587 special: {
nicholas@103 4588 load: {
nicholas@103 4589 // Prevent triggered image.load events from bubbling to window.load
nicholas@103 4590 noBubble: true
nicholas@103 4591 },
nicholas@103 4592 focus: {
nicholas@103 4593 // Fire native event if possible so blur/focus sequence is correct
nicholas@103 4594 trigger: function() {
nicholas@103 4595 if ( this !== safeActiveElement() && this.focus ) {
nicholas@103 4596 this.focus();
nicholas@103 4597 return false;
nicholas@103 4598 }
nicholas@103 4599 },
nicholas@103 4600 delegateType: "focusin"
nicholas@103 4601 },
nicholas@103 4602 blur: {
nicholas@103 4603 trigger: function() {
nicholas@103 4604 if ( this === safeActiveElement() && this.blur ) {
nicholas@103 4605 this.blur();
nicholas@103 4606 return false;
nicholas@103 4607 }
nicholas@103 4608 },
nicholas@103 4609 delegateType: "focusout"
nicholas@103 4610 },
nicholas@103 4611 click: {
nicholas@103 4612 // For checkbox, fire native event so checked state will be right
nicholas@103 4613 trigger: function() {
nicholas@103 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nicholas@103 4615 this.click();
nicholas@103 4616 return false;
nicholas@103 4617 }
nicholas@103 4618 },
nicholas@103 4619
nicholas@103 4620 // For cross-browser consistency, don't fire native .click() on links
nicholas@103 4621 _default: function( event ) {
nicholas@103 4622 return jQuery.nodeName( event.target, "a" );
nicholas@103 4623 }
nicholas@103 4624 },
nicholas@103 4625
nicholas@103 4626 beforeunload: {
nicholas@103 4627 postDispatch: function( event ) {
nicholas@103 4628
nicholas@103 4629 // Support: Firefox 20+
nicholas@103 4630 // Firefox doesn't alert if the returnValue field is not set.
nicholas@103 4631 if ( event.result !== undefined && event.originalEvent ) {
nicholas@103 4632 event.originalEvent.returnValue = event.result;
nicholas@103 4633 }
nicholas@103 4634 }
nicholas@103 4635 }
nicholas@103 4636 },
nicholas@103 4637
nicholas@103 4638 simulate: function( type, elem, event, bubble ) {
nicholas@103 4639 // Piggyback on a donor event to simulate a different one.
nicholas@103 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nicholas@103 4641 // simulated event prevents default then we do the same on the donor.
nicholas@103 4642 var e = jQuery.extend(
nicholas@103 4643 new jQuery.Event(),
nicholas@103 4644 event,
nicholas@103 4645 {
nicholas@103 4646 type: type,
nicholas@103 4647 isSimulated: true,
nicholas@103 4648 originalEvent: {}
nicholas@103 4649 }
nicholas@103 4650 );
nicholas@103 4651 if ( bubble ) {
nicholas@103 4652 jQuery.event.trigger( e, null, elem );
nicholas@103 4653 } else {
nicholas@103 4654 jQuery.event.dispatch.call( elem, e );
nicholas@103 4655 }
nicholas@103 4656 if ( e.isDefaultPrevented() ) {
nicholas@103 4657 event.preventDefault();
nicholas@103 4658 }
nicholas@103 4659 }
nicholas@103 4660 };
nicholas@103 4661
nicholas@103 4662 jQuery.removeEvent = function( elem, type, handle ) {
nicholas@103 4663 if ( elem.removeEventListener ) {
nicholas@103 4664 elem.removeEventListener( type, handle, false );
nicholas@103 4665 }
nicholas@103 4666 };
nicholas@103 4667
nicholas@103 4668 jQuery.Event = function( src, props ) {
nicholas@103 4669 // Allow instantiation without the 'new' keyword
nicholas@103 4670 if ( !(this instanceof jQuery.Event) ) {
nicholas@103 4671 return new jQuery.Event( src, props );
nicholas@103 4672 }
nicholas@103 4673
nicholas@103 4674 // Event object
nicholas@103 4675 if ( src && src.type ) {
nicholas@103 4676 this.originalEvent = src;
nicholas@103 4677 this.type = src.type;
nicholas@103 4678
nicholas@103 4679 // Events bubbling up the document may have been marked as prevented
nicholas@103 4680 // by a handler lower down the tree; reflect the correct value.
nicholas@103 4681 this.isDefaultPrevented = src.defaultPrevented ||
nicholas@103 4682 src.defaultPrevented === undefined &&
nicholas@103 4683 // Support: Android<4.0
nicholas@103 4684 src.returnValue === false ?
nicholas@103 4685 returnTrue :
nicholas@103 4686 returnFalse;
nicholas@103 4687
nicholas@103 4688 // Event type
nicholas@103 4689 } else {
nicholas@103 4690 this.type = src;
nicholas@103 4691 }
nicholas@103 4692
nicholas@103 4693 // Put explicitly provided properties onto the event object
nicholas@103 4694 if ( props ) {
nicholas@103 4695 jQuery.extend( this, props );
nicholas@103 4696 }
nicholas@103 4697
nicholas@103 4698 // Create a timestamp if incoming event doesn't have one
nicholas@103 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nicholas@103 4700
nicholas@103 4701 // Mark it as fixed
nicholas@103 4702 this[ jQuery.expando ] = true;
nicholas@103 4703 };
nicholas@103 4704
nicholas@103 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nicholas@103 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nicholas@103 4707 jQuery.Event.prototype = {
nicholas@103 4708 isDefaultPrevented: returnFalse,
nicholas@103 4709 isPropagationStopped: returnFalse,
nicholas@103 4710 isImmediatePropagationStopped: returnFalse,
nicholas@103 4711
nicholas@103 4712 preventDefault: function() {
nicholas@103 4713 var e = this.originalEvent;
nicholas@103 4714
nicholas@103 4715 this.isDefaultPrevented = returnTrue;
nicholas@103 4716
nicholas@103 4717 if ( e && e.preventDefault ) {
nicholas@103 4718 e.preventDefault();
nicholas@103 4719 }
nicholas@103 4720 },
nicholas@103 4721 stopPropagation: function() {
nicholas@103 4722 var e = this.originalEvent;
nicholas@103 4723
nicholas@103 4724 this.isPropagationStopped = returnTrue;
nicholas@103 4725
nicholas@103 4726 if ( e && e.stopPropagation ) {
nicholas@103 4727 e.stopPropagation();
nicholas@103 4728 }
nicholas@103 4729 },
nicholas@103 4730 stopImmediatePropagation: function() {
nicholas@103 4731 var e = this.originalEvent;
nicholas@103 4732
nicholas@103 4733 this.isImmediatePropagationStopped = returnTrue;
nicholas@103 4734
nicholas@103 4735 if ( e && e.stopImmediatePropagation ) {
nicholas@103 4736 e.stopImmediatePropagation();
nicholas@103 4737 }
nicholas@103 4738
nicholas@103 4739 this.stopPropagation();
nicholas@103 4740 }
nicholas@103 4741 };
nicholas@103 4742
nicholas@103 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nicholas@103 4744 // Support: Chrome 15+
nicholas@103 4745 jQuery.each({
nicholas@103 4746 mouseenter: "mouseover",
nicholas@103 4747 mouseleave: "mouseout",
nicholas@103 4748 pointerenter: "pointerover",
nicholas@103 4749 pointerleave: "pointerout"
nicholas@103 4750 }, function( orig, fix ) {
nicholas@103 4751 jQuery.event.special[ orig ] = {
nicholas@103 4752 delegateType: fix,
nicholas@103 4753 bindType: fix,
nicholas@103 4754
nicholas@103 4755 handle: function( event ) {
nicholas@103 4756 var ret,
nicholas@103 4757 target = this,
nicholas@103 4758 related = event.relatedTarget,
nicholas@103 4759 handleObj = event.handleObj;
nicholas@103 4760
nicholas@103 4761 // For mousenter/leave call the handler if related is outside the target.
nicholas@103 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nicholas@103 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nicholas@103 4764 event.type = handleObj.origType;
nicholas@103 4765 ret = handleObj.handler.apply( this, arguments );
nicholas@103 4766 event.type = fix;
nicholas@103 4767 }
nicholas@103 4768 return ret;
nicholas@103 4769 }
nicholas@103 4770 };
nicholas@103 4771 });
nicholas@103 4772
nicholas@103 4773 // Support: Firefox, Chrome, Safari
nicholas@103 4774 // Create "bubbling" focus and blur events
nicholas@103 4775 if ( !support.focusinBubbles ) {
nicholas@103 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nicholas@103 4777
nicholas@103 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nicholas@103 4779 var handler = function( event ) {
nicholas@103 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nicholas@103 4781 };
nicholas@103 4782
nicholas@103 4783 jQuery.event.special[ fix ] = {
nicholas@103 4784 setup: function() {
nicholas@103 4785 var doc = this.ownerDocument || this,
nicholas@103 4786 attaches = data_priv.access( doc, fix );
nicholas@103 4787
nicholas@103 4788 if ( !attaches ) {
nicholas@103 4789 doc.addEventListener( orig, handler, true );
nicholas@103 4790 }
nicholas@103 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nicholas@103 4792 },
nicholas@103 4793 teardown: function() {
nicholas@103 4794 var doc = this.ownerDocument || this,
nicholas@103 4795 attaches = data_priv.access( doc, fix ) - 1;
nicholas@103 4796
nicholas@103 4797 if ( !attaches ) {
nicholas@103 4798 doc.removeEventListener( orig, handler, true );
nicholas@103 4799 data_priv.remove( doc, fix );
nicholas@103 4800
nicholas@103 4801 } else {
nicholas@103 4802 data_priv.access( doc, fix, attaches );
nicholas@103 4803 }
nicholas@103 4804 }
nicholas@103 4805 };
nicholas@103 4806 });
nicholas@103 4807 }
nicholas@103 4808
nicholas@103 4809 jQuery.fn.extend({
nicholas@103 4810
nicholas@103 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nicholas@103 4812 var origFn, type;
nicholas@103 4813
nicholas@103 4814 // Types can be a map of types/handlers
nicholas@103 4815 if ( typeof types === "object" ) {
nicholas@103 4816 // ( types-Object, selector, data )
nicholas@103 4817 if ( typeof selector !== "string" ) {
nicholas@103 4818 // ( types-Object, data )
nicholas@103 4819 data = data || selector;
nicholas@103 4820 selector = undefined;
nicholas@103 4821 }
nicholas@103 4822 for ( type in types ) {
nicholas@103 4823 this.on( type, selector, data, types[ type ], one );
nicholas@103 4824 }
nicholas@103 4825 return this;
nicholas@103 4826 }
nicholas@103 4827
nicholas@103 4828 if ( data == null && fn == null ) {
nicholas@103 4829 // ( types, fn )
nicholas@103 4830 fn = selector;
nicholas@103 4831 data = selector = undefined;
nicholas@103 4832 } else if ( fn == null ) {
nicholas@103 4833 if ( typeof selector === "string" ) {
nicholas@103 4834 // ( types, selector, fn )
nicholas@103 4835 fn = data;
nicholas@103 4836 data = undefined;
nicholas@103 4837 } else {
nicholas@103 4838 // ( types, data, fn )
nicholas@103 4839 fn = data;
nicholas@103 4840 data = selector;
nicholas@103 4841 selector = undefined;
nicholas@103 4842 }
nicholas@103 4843 }
nicholas@103 4844 if ( fn === false ) {
nicholas@103 4845 fn = returnFalse;
nicholas@103 4846 } else if ( !fn ) {
nicholas@103 4847 return this;
nicholas@103 4848 }
nicholas@103 4849
nicholas@103 4850 if ( one === 1 ) {
nicholas@103 4851 origFn = fn;
nicholas@103 4852 fn = function( event ) {
nicholas@103 4853 // Can use an empty set, since event contains the info
nicholas@103 4854 jQuery().off( event );
nicholas@103 4855 return origFn.apply( this, arguments );
nicholas@103 4856 };
nicholas@103 4857 // Use same guid so caller can remove using origFn
nicholas@103 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nicholas@103 4859 }
nicholas@103 4860 return this.each( function() {
nicholas@103 4861 jQuery.event.add( this, types, fn, data, selector );
nicholas@103 4862 });
nicholas@103 4863 },
nicholas@103 4864 one: function( types, selector, data, fn ) {
nicholas@103 4865 return this.on( types, selector, data, fn, 1 );
nicholas@103 4866 },
nicholas@103 4867 off: function( types, selector, fn ) {
nicholas@103 4868 var handleObj, type;
nicholas@103 4869 if ( types && types.preventDefault && types.handleObj ) {
nicholas@103 4870 // ( event ) dispatched jQuery.Event
nicholas@103 4871 handleObj = types.handleObj;
nicholas@103 4872 jQuery( types.delegateTarget ).off(
nicholas@103 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nicholas@103 4874 handleObj.selector,
nicholas@103 4875 handleObj.handler
nicholas@103 4876 );
nicholas@103 4877 return this;
nicholas@103 4878 }
nicholas@103 4879 if ( typeof types === "object" ) {
nicholas@103 4880 // ( types-object [, selector] )
nicholas@103 4881 for ( type in types ) {
nicholas@103 4882 this.off( type, selector, types[ type ] );
nicholas@103 4883 }
nicholas@103 4884 return this;
nicholas@103 4885 }
nicholas@103 4886 if ( selector === false || typeof selector === "function" ) {
nicholas@103 4887 // ( types [, fn] )
nicholas@103 4888 fn = selector;
nicholas@103 4889 selector = undefined;
nicholas@103 4890 }
nicholas@103 4891 if ( fn === false ) {
nicholas@103 4892 fn = returnFalse;
nicholas@103 4893 }
nicholas@103 4894 return this.each(function() {
nicholas@103 4895 jQuery.event.remove( this, types, fn, selector );
nicholas@103 4896 });
nicholas@103 4897 },
nicholas@103 4898
nicholas@103 4899 trigger: function( type, data ) {
nicholas@103 4900 return this.each(function() {
nicholas@103 4901 jQuery.event.trigger( type, data, this );
nicholas@103 4902 });
nicholas@103 4903 },
nicholas@103 4904 triggerHandler: function( type, data ) {
nicholas@103 4905 var elem = this[0];
nicholas@103 4906 if ( elem ) {
nicholas@103 4907 return jQuery.event.trigger( type, data, elem, true );
nicholas@103 4908 }
nicholas@103 4909 }
nicholas@103 4910 });
nicholas@103 4911
nicholas@103 4912
nicholas@103 4913 var
nicholas@103 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nicholas@103 4915 rtagName = /<([\w:]+)/,
nicholas@103 4916 rhtml = /<|&#?\w+;/,
nicholas@103 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nicholas@103 4918 // checked="checked" or checked
nicholas@103 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nicholas@103 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nicholas@103 4921 rscriptTypeMasked = /^true\/(.*)/,
nicholas@103 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nicholas@103 4923
nicholas@103 4924 // We have to close these tags to support XHTML (#13200)
nicholas@103 4925 wrapMap = {
nicholas@103 4926
nicholas@103 4927 // Support: IE9
nicholas@103 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nicholas@103 4929
nicholas@103 4930 thead: [ 1, "<table>", "</table>" ],
nicholas@103 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nicholas@103 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nicholas@103 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nicholas@103 4934
nicholas@103 4935 _default: [ 0, "", "" ]
nicholas@103 4936 };
nicholas@103 4937
nicholas@103 4938 // Support: IE9
nicholas@103 4939 wrapMap.optgroup = wrapMap.option;
nicholas@103 4940
nicholas@103 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nicholas@103 4942 wrapMap.th = wrapMap.td;
nicholas@103 4943
nicholas@103 4944 // Support: 1.x compatibility
nicholas@103 4945 // Manipulating tables requires a tbody
nicholas@103 4946 function manipulationTarget( elem, content ) {
nicholas@103 4947 return jQuery.nodeName( elem, "table" ) &&
nicholas@103 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nicholas@103 4949
nicholas@103 4950 elem.getElementsByTagName("tbody")[0] ||
nicholas@103 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nicholas@103 4952 elem;
nicholas@103 4953 }
nicholas@103 4954
nicholas@103 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nicholas@103 4956 function disableScript( elem ) {
nicholas@103 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nicholas@103 4958 return elem;
nicholas@103 4959 }
nicholas@103 4960 function restoreScript( elem ) {
nicholas@103 4961 var match = rscriptTypeMasked.exec( elem.type );
nicholas@103 4962
nicholas@103 4963 if ( match ) {
nicholas@103 4964 elem.type = match[ 1 ];
nicholas@103 4965 } else {
nicholas@103 4966 elem.removeAttribute("type");
nicholas@103 4967 }
nicholas@103 4968
nicholas@103 4969 return elem;
nicholas@103 4970 }
nicholas@103 4971
nicholas@103 4972 // Mark scripts as having already been evaluated
nicholas@103 4973 function setGlobalEval( elems, refElements ) {
nicholas@103 4974 var i = 0,
nicholas@103 4975 l = elems.length;
nicholas@103 4976
nicholas@103 4977 for ( ; i < l; i++ ) {
nicholas@103 4978 data_priv.set(
nicholas@103 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nicholas@103 4980 );
nicholas@103 4981 }
nicholas@103 4982 }
nicholas@103 4983
nicholas@103 4984 function cloneCopyEvent( src, dest ) {
nicholas@103 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nicholas@103 4986
nicholas@103 4987 if ( dest.nodeType !== 1 ) {
nicholas@103 4988 return;
nicholas@103 4989 }
nicholas@103 4990
nicholas@103 4991 // 1. Copy private data: events, handlers, etc.
nicholas@103 4992 if ( data_priv.hasData( src ) ) {
nicholas@103 4993 pdataOld = data_priv.access( src );
nicholas@103 4994 pdataCur = data_priv.set( dest, pdataOld );
nicholas@103 4995 events = pdataOld.events;
nicholas@103 4996
nicholas@103 4997 if ( events ) {
nicholas@103 4998 delete pdataCur.handle;
nicholas@103 4999 pdataCur.events = {};
nicholas@103 5000
nicholas@103 5001 for ( type in events ) {
nicholas@103 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nicholas@103 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nicholas@103 5004 }
nicholas@103 5005 }
nicholas@103 5006 }
nicholas@103 5007 }
nicholas@103 5008
nicholas@103 5009 // 2. Copy user data
nicholas@103 5010 if ( data_user.hasData( src ) ) {
nicholas@103 5011 udataOld = data_user.access( src );
nicholas@103 5012 udataCur = jQuery.extend( {}, udataOld );
nicholas@103 5013
nicholas@103 5014 data_user.set( dest, udataCur );
nicholas@103 5015 }
nicholas@103 5016 }
nicholas@103 5017
nicholas@103 5018 function getAll( context, tag ) {
nicholas@103 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nicholas@103 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nicholas@103 5021 [];
nicholas@103 5022
nicholas@103 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nicholas@103 5024 jQuery.merge( [ context ], ret ) :
nicholas@103 5025 ret;
nicholas@103 5026 }
nicholas@103 5027
nicholas@103 5028 // Fix IE bugs, see support tests
nicholas@103 5029 function fixInput( src, dest ) {
nicholas@103 5030 var nodeName = dest.nodeName.toLowerCase();
nicholas@103 5031
nicholas@103 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nicholas@103 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nicholas@103 5034 dest.checked = src.checked;
nicholas@103 5035
nicholas@103 5036 // Fails to return the selected option to the default selected state when cloning options
nicholas@103 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nicholas@103 5038 dest.defaultValue = src.defaultValue;
nicholas@103 5039 }
nicholas@103 5040 }
nicholas@103 5041
nicholas@103 5042 jQuery.extend({
nicholas@103 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nicholas@103 5044 var i, l, srcElements, destElements,
nicholas@103 5045 clone = elem.cloneNode( true ),
nicholas@103 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nicholas@103 5047
nicholas@103 5048 // Fix IE cloning issues
nicholas@103 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nicholas@103 5050 !jQuery.isXMLDoc( elem ) ) {
nicholas@103 5051
nicholas@103 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nicholas@103 5053 destElements = getAll( clone );
nicholas@103 5054 srcElements = getAll( elem );
nicholas@103 5055
nicholas@103 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nicholas@103 5057 fixInput( srcElements[ i ], destElements[ i ] );
nicholas@103 5058 }
nicholas@103 5059 }
nicholas@103 5060
nicholas@103 5061 // Copy the events from the original to the clone
nicholas@103 5062 if ( dataAndEvents ) {
nicholas@103 5063 if ( deepDataAndEvents ) {
nicholas@103 5064 srcElements = srcElements || getAll( elem );
nicholas@103 5065 destElements = destElements || getAll( clone );
nicholas@103 5066
nicholas@103 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nicholas@103 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nicholas@103 5069 }
nicholas@103 5070 } else {
nicholas@103 5071 cloneCopyEvent( elem, clone );
nicholas@103 5072 }
nicholas@103 5073 }
nicholas@103 5074
nicholas@103 5075 // Preserve script evaluation history
nicholas@103 5076 destElements = getAll( clone, "script" );
nicholas@103 5077 if ( destElements.length > 0 ) {
nicholas@103 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nicholas@103 5079 }
nicholas@103 5080
nicholas@103 5081 // Return the cloned set
nicholas@103 5082 return clone;
nicholas@103 5083 },
nicholas@103 5084
nicholas@103 5085 buildFragment: function( elems, context, scripts, selection ) {
nicholas@103 5086 var elem, tmp, tag, wrap, contains, j,
nicholas@103 5087 fragment = context.createDocumentFragment(),
nicholas@103 5088 nodes = [],
nicholas@103 5089 i = 0,
nicholas@103 5090 l = elems.length;
nicholas@103 5091
nicholas@103 5092 for ( ; i < l; i++ ) {
nicholas@103 5093 elem = elems[ i ];
nicholas@103 5094
nicholas@103 5095 if ( elem || elem === 0 ) {
nicholas@103 5096
nicholas@103 5097 // Add nodes directly
nicholas@103 5098 if ( jQuery.type( elem ) === "object" ) {
nicholas@103 5099 // Support: QtWebKit, PhantomJS
nicholas@103 5100 // push.apply(_, arraylike) throws on ancient WebKit
nicholas@103 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nicholas@103 5102
nicholas@103 5103 // Convert non-html into a text node
nicholas@103 5104 } else if ( !rhtml.test( elem ) ) {
nicholas@103 5105 nodes.push( context.createTextNode( elem ) );
nicholas@103 5106
nicholas@103 5107 // Convert html into DOM nodes
nicholas@103 5108 } else {
nicholas@103 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nicholas@103 5110
nicholas@103 5111 // Deserialize a standard representation
nicholas@103 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nicholas@103 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nicholas@103 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nicholas@103 5115
nicholas@103 5116 // Descend through wrappers to the right content
nicholas@103 5117 j = wrap[ 0 ];
nicholas@103 5118 while ( j-- ) {
nicholas@103 5119 tmp = tmp.lastChild;
nicholas@103 5120 }
nicholas@103 5121
nicholas@103 5122 // Support: QtWebKit, PhantomJS
nicholas@103 5123 // push.apply(_, arraylike) throws on ancient WebKit
nicholas@103 5124 jQuery.merge( nodes, tmp.childNodes );
nicholas@103 5125
nicholas@103 5126 // Remember the top-level container
nicholas@103 5127 tmp = fragment.firstChild;
nicholas@103 5128
nicholas@103 5129 // Ensure the created nodes are orphaned (#12392)
nicholas@103 5130 tmp.textContent = "";
nicholas@103 5131 }
nicholas@103 5132 }
nicholas@103 5133 }
nicholas@103 5134
nicholas@103 5135 // Remove wrapper from fragment
nicholas@103 5136 fragment.textContent = "";
nicholas@103 5137
nicholas@103 5138 i = 0;
nicholas@103 5139 while ( (elem = nodes[ i++ ]) ) {
nicholas@103 5140
nicholas@103 5141 // #4087 - If origin and destination elements are the same, and this is
nicholas@103 5142 // that element, do not do anything
nicholas@103 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nicholas@103 5144 continue;
nicholas@103 5145 }
nicholas@103 5146
nicholas@103 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nicholas@103 5148
nicholas@103 5149 // Append to fragment
nicholas@103 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nicholas@103 5151
nicholas@103 5152 // Preserve script evaluation history
nicholas@103 5153 if ( contains ) {
nicholas@103 5154 setGlobalEval( tmp );
nicholas@103 5155 }
nicholas@103 5156
nicholas@103 5157 // Capture executables
nicholas@103 5158 if ( scripts ) {
nicholas@103 5159 j = 0;
nicholas@103 5160 while ( (elem = tmp[ j++ ]) ) {
nicholas@103 5161 if ( rscriptType.test( elem.type || "" ) ) {
nicholas@103 5162 scripts.push( elem );
nicholas@103 5163 }
nicholas@103 5164 }
nicholas@103 5165 }
nicholas@103 5166 }
nicholas@103 5167
nicholas@103 5168 return fragment;
nicholas@103 5169 },
nicholas@103 5170
nicholas@103 5171 cleanData: function( elems ) {
nicholas@103 5172 var data, elem, type, key,
nicholas@103 5173 special = jQuery.event.special,
nicholas@103 5174 i = 0;
nicholas@103 5175
nicholas@103 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nicholas@103 5177 if ( jQuery.acceptData( elem ) ) {
nicholas@103 5178 key = elem[ data_priv.expando ];
nicholas@103 5179
nicholas@103 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nicholas@103 5181 if ( data.events ) {
nicholas@103 5182 for ( type in data.events ) {
nicholas@103 5183 if ( special[ type ] ) {
nicholas@103 5184 jQuery.event.remove( elem, type );
nicholas@103 5185
nicholas@103 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nicholas@103 5187 } else {
nicholas@103 5188 jQuery.removeEvent( elem, type, data.handle );
nicholas@103 5189 }
nicholas@103 5190 }
nicholas@103 5191 }
nicholas@103 5192 if ( data_priv.cache[ key ] ) {
nicholas@103 5193 // Discard any remaining `private` data
nicholas@103 5194 delete data_priv.cache[ key ];
nicholas@103 5195 }
nicholas@103 5196 }
nicholas@103 5197 }
nicholas@103 5198 // Discard any remaining `user` data
nicholas@103 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nicholas@103 5200 }
nicholas@103 5201 }
nicholas@103 5202 });
nicholas@103 5203
nicholas@103 5204 jQuery.fn.extend({
nicholas@103 5205 text: function( value ) {
nicholas@103 5206 return access( this, function( value ) {
nicholas@103 5207 return value === undefined ?
nicholas@103 5208 jQuery.text( this ) :
nicholas@103 5209 this.empty().each(function() {
nicholas@103 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@103 5211 this.textContent = value;
nicholas@103 5212 }
nicholas@103 5213 });
nicholas@103 5214 }, null, value, arguments.length );
nicholas@103 5215 },
nicholas@103 5216
nicholas@103 5217 append: function() {
nicholas@103 5218 return this.domManip( arguments, function( elem ) {
nicholas@103 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@103 5220 var target = manipulationTarget( this, elem );
nicholas@103 5221 target.appendChild( elem );
nicholas@103 5222 }
nicholas@103 5223 });
nicholas@103 5224 },
nicholas@103 5225
nicholas@103 5226 prepend: function() {
nicholas@103 5227 return this.domManip( arguments, function( elem ) {
nicholas@103 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@103 5229 var target = manipulationTarget( this, elem );
nicholas@103 5230 target.insertBefore( elem, target.firstChild );
nicholas@103 5231 }
nicholas@103 5232 });
nicholas@103 5233 },
nicholas@103 5234
nicholas@103 5235 before: function() {
nicholas@103 5236 return this.domManip( arguments, function( elem ) {
nicholas@103 5237 if ( this.parentNode ) {
nicholas@103 5238 this.parentNode.insertBefore( elem, this );
nicholas@103 5239 }
nicholas@103 5240 });
nicholas@103 5241 },
nicholas@103 5242
nicholas@103 5243 after: function() {
nicholas@103 5244 return this.domManip( arguments, function( elem ) {
nicholas@103 5245 if ( this.parentNode ) {
nicholas@103 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nicholas@103 5247 }
nicholas@103 5248 });
nicholas@103 5249 },
nicholas@103 5250
nicholas@103 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nicholas@103 5252 var elem,
nicholas@103 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nicholas@103 5254 i = 0;
nicholas@103 5255
nicholas@103 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nicholas@103 5257 if ( !keepData && elem.nodeType === 1 ) {
nicholas@103 5258 jQuery.cleanData( getAll( elem ) );
nicholas@103 5259 }
nicholas@103 5260
nicholas@103 5261 if ( elem.parentNode ) {
nicholas@103 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nicholas@103 5263 setGlobalEval( getAll( elem, "script" ) );
nicholas@103 5264 }
nicholas@103 5265 elem.parentNode.removeChild( elem );
nicholas@103 5266 }
nicholas@103 5267 }
nicholas@103 5268
nicholas@103 5269 return this;
nicholas@103 5270 },
nicholas@103 5271
nicholas@103 5272 empty: function() {
nicholas@103 5273 var elem,
nicholas@103 5274 i = 0;
nicholas@103 5275
nicholas@103 5276 for ( ; (elem = this[i]) != null; i++ ) {
nicholas@103 5277 if ( elem.nodeType === 1 ) {
nicholas@103 5278
nicholas@103 5279 // Prevent memory leaks
nicholas@103 5280 jQuery.cleanData( getAll( elem, false ) );
nicholas@103 5281
nicholas@103 5282 // Remove any remaining nodes
nicholas@103 5283 elem.textContent = "";
nicholas@103 5284 }
nicholas@103 5285 }
nicholas@103 5286
nicholas@103 5287 return this;
nicholas@103 5288 },
nicholas@103 5289
nicholas@103 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nicholas@103 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nicholas@103 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nicholas@103 5293
nicholas@103 5294 return this.map(function() {
nicholas@103 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nicholas@103 5296 });
nicholas@103 5297 },
nicholas@103 5298
nicholas@103 5299 html: function( value ) {
nicholas@103 5300 return access( this, function( value ) {
nicholas@103 5301 var elem = this[ 0 ] || {},
nicholas@103 5302 i = 0,
nicholas@103 5303 l = this.length;
nicholas@103 5304
nicholas@103 5305 if ( value === undefined && elem.nodeType === 1 ) {
nicholas@103 5306 return elem.innerHTML;
nicholas@103 5307 }
nicholas@103 5308
nicholas@103 5309 // See if we can take a shortcut and just use innerHTML
nicholas@103 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nicholas@103 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nicholas@103 5312
nicholas@103 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nicholas@103 5314
nicholas@103 5315 try {
nicholas@103 5316 for ( ; i < l; i++ ) {
nicholas@103 5317 elem = this[ i ] || {};
nicholas@103 5318
nicholas@103 5319 // Remove element nodes and prevent memory leaks
nicholas@103 5320 if ( elem.nodeType === 1 ) {
nicholas@103 5321 jQuery.cleanData( getAll( elem, false ) );
nicholas@103 5322 elem.innerHTML = value;
nicholas@103 5323 }
nicholas@103 5324 }
nicholas@103 5325
nicholas@103 5326 elem = 0;
nicholas@103 5327
nicholas@103 5328 // If using innerHTML throws an exception, use the fallback method
nicholas@103 5329 } catch( e ) {}
nicholas@103 5330 }
nicholas@103 5331
nicholas@103 5332 if ( elem ) {
nicholas@103 5333 this.empty().append( value );
nicholas@103 5334 }
nicholas@103 5335 }, null, value, arguments.length );
nicholas@103 5336 },
nicholas@103 5337
nicholas@103 5338 replaceWith: function() {
nicholas@103 5339 var arg = arguments[ 0 ];
nicholas@103 5340
nicholas@103 5341 // Make the changes, replacing each context element with the new content
nicholas@103 5342 this.domManip( arguments, function( elem ) {
nicholas@103 5343 arg = this.parentNode;
nicholas@103 5344
nicholas@103 5345 jQuery.cleanData( getAll( this ) );
nicholas@103 5346
nicholas@103 5347 if ( arg ) {
nicholas@103 5348 arg.replaceChild( elem, this );
nicholas@103 5349 }
nicholas@103 5350 });
nicholas@103 5351
nicholas@103 5352 // Force removal if there was no new content (e.g., from empty arguments)
nicholas@103 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nicholas@103 5354 },
nicholas@103 5355
nicholas@103 5356 detach: function( selector ) {
nicholas@103 5357 return this.remove( selector, true );
nicholas@103 5358 },
nicholas@103 5359
nicholas@103 5360 domManip: function( args, callback ) {
nicholas@103 5361
nicholas@103 5362 // Flatten any nested arrays
nicholas@103 5363 args = concat.apply( [], args );
nicholas@103 5364
nicholas@103 5365 var fragment, first, scripts, hasScripts, node, doc,
nicholas@103 5366 i = 0,
nicholas@103 5367 l = this.length,
nicholas@103 5368 set = this,
nicholas@103 5369 iNoClone = l - 1,
nicholas@103 5370 value = args[ 0 ],
nicholas@103 5371 isFunction = jQuery.isFunction( value );
nicholas@103 5372
nicholas@103 5373 // We can't cloneNode fragments that contain checked, in WebKit
nicholas@103 5374 if ( isFunction ||
nicholas@103 5375 ( l > 1 && typeof value === "string" &&
nicholas@103 5376 !support.checkClone && rchecked.test( value ) ) ) {
nicholas@103 5377 return this.each(function( index ) {
nicholas@103 5378 var self = set.eq( index );
nicholas@103 5379 if ( isFunction ) {
nicholas@103 5380 args[ 0 ] = value.call( this, index, self.html() );
nicholas@103 5381 }
nicholas@103 5382 self.domManip( args, callback );
nicholas@103 5383 });
nicholas@103 5384 }
nicholas@103 5385
nicholas@103 5386 if ( l ) {
nicholas@103 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nicholas@103 5388 first = fragment.firstChild;
nicholas@103 5389
nicholas@103 5390 if ( fragment.childNodes.length === 1 ) {
nicholas@103 5391 fragment = first;
nicholas@103 5392 }
nicholas@103 5393
nicholas@103 5394 if ( first ) {
nicholas@103 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nicholas@103 5396 hasScripts = scripts.length;
nicholas@103 5397
nicholas@103 5398 // Use the original fragment for the last item instead of the first because it can end up
nicholas@103 5399 // being emptied incorrectly in certain situations (#8070).
nicholas@103 5400 for ( ; i < l; i++ ) {
nicholas@103 5401 node = fragment;
nicholas@103 5402
nicholas@103 5403 if ( i !== iNoClone ) {
nicholas@103 5404 node = jQuery.clone( node, true, true );
nicholas@103 5405
nicholas@103 5406 // Keep references to cloned scripts for later restoration
nicholas@103 5407 if ( hasScripts ) {
nicholas@103 5408 // Support: QtWebKit
nicholas@103 5409 // jQuery.merge because push.apply(_, arraylike) throws
nicholas@103 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nicholas@103 5411 }
nicholas@103 5412 }
nicholas@103 5413
nicholas@103 5414 callback.call( this[ i ], node, i );
nicholas@103 5415 }
nicholas@103 5416
nicholas@103 5417 if ( hasScripts ) {
nicholas@103 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nicholas@103 5419
nicholas@103 5420 // Reenable scripts
nicholas@103 5421 jQuery.map( scripts, restoreScript );
nicholas@103 5422
nicholas@103 5423 // Evaluate executable scripts on first document insertion
nicholas@103 5424 for ( i = 0; i < hasScripts; i++ ) {
nicholas@103 5425 node = scripts[ i ];
nicholas@103 5426 if ( rscriptType.test( node.type || "" ) &&
nicholas@103 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nicholas@103 5428
nicholas@103 5429 if ( node.src ) {
nicholas@103 5430 // Optional AJAX dependency, but won't run scripts if not present
nicholas@103 5431 if ( jQuery._evalUrl ) {
nicholas@103 5432 jQuery._evalUrl( node.src );
nicholas@103 5433 }
nicholas@103 5434 } else {
nicholas@103 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nicholas@103 5436 }
nicholas@103 5437 }
nicholas@103 5438 }
nicholas@103 5439 }
nicholas@103 5440 }
nicholas@103 5441 }
nicholas@103 5442
nicholas@103 5443 return this;
nicholas@103 5444 }
nicholas@103 5445 });
nicholas@103 5446
nicholas@103 5447 jQuery.each({
nicholas@103 5448 appendTo: "append",
nicholas@103 5449 prependTo: "prepend",
nicholas@103 5450 insertBefore: "before",
nicholas@103 5451 insertAfter: "after",
nicholas@103 5452 replaceAll: "replaceWith"
nicholas@103 5453 }, function( name, original ) {
nicholas@103 5454 jQuery.fn[ name ] = function( selector ) {
nicholas@103 5455 var elems,
nicholas@103 5456 ret = [],
nicholas@103 5457 insert = jQuery( selector ),
nicholas@103 5458 last = insert.length - 1,
nicholas@103 5459 i = 0;
nicholas@103 5460
nicholas@103 5461 for ( ; i <= last; i++ ) {
nicholas@103 5462 elems = i === last ? this : this.clone( true );
nicholas@103 5463 jQuery( insert[ i ] )[ original ]( elems );
nicholas@103 5464
nicholas@103 5465 // Support: QtWebKit
nicholas@103 5466 // .get() because push.apply(_, arraylike) throws
nicholas@103 5467 push.apply( ret, elems.get() );
nicholas@103 5468 }
nicholas@103 5469
nicholas@103 5470 return this.pushStack( ret );
nicholas@103 5471 };
nicholas@103 5472 });
nicholas@103 5473
nicholas@103 5474
nicholas@103 5475 var iframe,
nicholas@103 5476 elemdisplay = {};
nicholas@103 5477
nicholas@103 5478 /**
nicholas@103 5479 * Retrieve the actual display of a element
nicholas@103 5480 * @param {String} name nodeName of the element
nicholas@103 5481 * @param {Object} doc Document object
nicholas@103 5482 */
nicholas@103 5483 // Called only from within defaultDisplay
nicholas@103 5484 function actualDisplay( name, doc ) {
nicholas@103 5485 var style,
nicholas@103 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nicholas@103 5487
nicholas@103 5488 // getDefaultComputedStyle might be reliably used only on attached element
nicholas@103 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nicholas@103 5490
nicholas@103 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nicholas@103 5492 // since it was removed from specification and supported only in FF
nicholas@103 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nicholas@103 5494
nicholas@103 5495 // We don't have any data stored on the element,
nicholas@103 5496 // so use "detach" method as fast way to get rid of the element
nicholas@103 5497 elem.detach();
nicholas@103 5498
nicholas@103 5499 return display;
nicholas@103 5500 }
nicholas@103 5501
nicholas@103 5502 /**
nicholas@103 5503 * Try to determine the default display value of an element
nicholas@103 5504 * @param {String} nodeName
nicholas@103 5505 */
nicholas@103 5506 function defaultDisplay( nodeName ) {
nicholas@103 5507 var doc = document,
nicholas@103 5508 display = elemdisplay[ nodeName ];
nicholas@103 5509
nicholas@103 5510 if ( !display ) {
nicholas@103 5511 display = actualDisplay( nodeName, doc );
nicholas@103 5512
nicholas@103 5513 // If the simple way fails, read from inside an iframe
nicholas@103 5514 if ( display === "none" || !display ) {
nicholas@103 5515
nicholas@103 5516 // Use the already-created iframe if possible
nicholas@103 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nicholas@103 5518
nicholas@103 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nicholas@103 5520 doc = iframe[ 0 ].contentDocument;
nicholas@103 5521
nicholas@103 5522 // Support: IE
nicholas@103 5523 doc.write();
nicholas@103 5524 doc.close();
nicholas@103 5525
nicholas@103 5526 display = actualDisplay( nodeName, doc );
nicholas@103 5527 iframe.detach();
nicholas@103 5528 }
nicholas@103 5529
nicholas@103 5530 // Store the correct default display
nicholas@103 5531 elemdisplay[ nodeName ] = display;
nicholas@103 5532 }
nicholas@103 5533
nicholas@103 5534 return display;
nicholas@103 5535 }
nicholas@103 5536 var rmargin = (/^margin/);
nicholas@103 5537
nicholas@103 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nicholas@103 5539
nicholas@103 5540 var getStyles = function( elem ) {
nicholas@103 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nicholas@103 5542 // IE throws on elements created in popups
nicholas@103 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nicholas@103 5544 if ( elem.ownerDocument.defaultView.opener ) {
nicholas@103 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nicholas@103 5546 }
nicholas@103 5547
nicholas@103 5548 return window.getComputedStyle( elem, null );
nicholas@103 5549 };
nicholas@103 5550
nicholas@103 5551
nicholas@103 5552
nicholas@103 5553 function curCSS( elem, name, computed ) {
nicholas@103 5554 var width, minWidth, maxWidth, ret,
nicholas@103 5555 style = elem.style;
nicholas@103 5556
nicholas@103 5557 computed = computed || getStyles( elem );
nicholas@103 5558
nicholas@103 5559 // Support: IE9
nicholas@103 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nicholas@103 5561 if ( computed ) {
nicholas@103 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nicholas@103 5563 }
nicholas@103 5564
nicholas@103 5565 if ( computed ) {
nicholas@103 5566
nicholas@103 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nicholas@103 5568 ret = jQuery.style( elem, name );
nicholas@103 5569 }
nicholas@103 5570
nicholas@103 5571 // Support: iOS < 6
nicholas@103 5572 // A tribute to the "awesome hack by Dean Edwards"
nicholas@103 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nicholas@103 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nicholas@103 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nicholas@103 5576
nicholas@103 5577 // Remember the original values
nicholas@103 5578 width = style.width;
nicholas@103 5579 minWidth = style.minWidth;
nicholas@103 5580 maxWidth = style.maxWidth;
nicholas@103 5581
nicholas@103 5582 // Put in the new values to get a computed value out
nicholas@103 5583 style.minWidth = style.maxWidth = style.width = ret;
nicholas@103 5584 ret = computed.width;
nicholas@103 5585
nicholas@103 5586 // Revert the changed values
nicholas@103 5587 style.width = width;
nicholas@103 5588 style.minWidth = minWidth;
nicholas@103 5589 style.maxWidth = maxWidth;
nicholas@103 5590 }
nicholas@103 5591 }
nicholas@103 5592
nicholas@103 5593 return ret !== undefined ?
nicholas@103 5594 // Support: IE
nicholas@103 5595 // IE returns zIndex value as an integer.
nicholas@103 5596 ret + "" :
nicholas@103 5597 ret;
nicholas@103 5598 }
nicholas@103 5599
nicholas@103 5600
nicholas@103 5601 function addGetHookIf( conditionFn, hookFn ) {
nicholas@103 5602 // Define the hook, we'll check on the first run if it's really needed.
nicholas@103 5603 return {
nicholas@103 5604 get: function() {
nicholas@103 5605 if ( conditionFn() ) {
nicholas@103 5606 // Hook not needed (or it's not possible to use it due
nicholas@103 5607 // to missing dependency), remove it.
nicholas@103 5608 delete this.get;
nicholas@103 5609 return;
nicholas@103 5610 }
nicholas@103 5611
nicholas@103 5612 // Hook needed; redefine it so that the support test is not executed again.
nicholas@103 5613 return (this.get = hookFn).apply( this, arguments );
nicholas@103 5614 }
nicholas@103 5615 };
nicholas@103 5616 }
nicholas@103 5617
nicholas@103 5618
nicholas@103 5619 (function() {
nicholas@103 5620 var pixelPositionVal, boxSizingReliableVal,
nicholas@103 5621 docElem = document.documentElement,
nicholas@103 5622 container = document.createElement( "div" ),
nicholas@103 5623 div = document.createElement( "div" );
nicholas@103 5624
nicholas@103 5625 if ( !div.style ) {
nicholas@103 5626 return;
nicholas@103 5627 }
nicholas@103 5628
nicholas@103 5629 // Support: IE9-11+
nicholas@103 5630 // Style of cloned element affects source element cloned (#8908)
nicholas@103 5631 div.style.backgroundClip = "content-box";
nicholas@103 5632 div.cloneNode( true ).style.backgroundClip = "";
nicholas@103 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nicholas@103 5634
nicholas@103 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nicholas@103 5636 "position:absolute";
nicholas@103 5637 container.appendChild( div );
nicholas@103 5638
nicholas@103 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nicholas@103 5640 // so they're executed at the same time to save the second computation.
nicholas@103 5641 function computePixelPositionAndBoxSizingReliable() {
nicholas@103 5642 div.style.cssText =
nicholas@103 5643 // Support: Firefox<29, Android 2.3
nicholas@103 5644 // Vendor-prefix box-sizing
nicholas@103 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nicholas@103 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nicholas@103 5647 "border:1px;padding:1px;width:4px;position:absolute";
nicholas@103 5648 div.innerHTML = "";
nicholas@103 5649 docElem.appendChild( container );
nicholas@103 5650
nicholas@103 5651 var divStyle = window.getComputedStyle( div, null );
nicholas@103 5652 pixelPositionVal = divStyle.top !== "1%";
nicholas@103 5653 boxSizingReliableVal = divStyle.width === "4px";
nicholas@103 5654
nicholas@103 5655 docElem.removeChild( container );
nicholas@103 5656 }
nicholas@103 5657
nicholas@103 5658 // Support: node.js jsdom
nicholas@103 5659 // Don't assume that getComputedStyle is a property of the global object
nicholas@103 5660 if ( window.getComputedStyle ) {
nicholas@103 5661 jQuery.extend( support, {
nicholas@103 5662 pixelPosition: function() {
nicholas@103 5663
nicholas@103 5664 // This test is executed only once but we still do memoizing
nicholas@103 5665 // since we can use the boxSizingReliable pre-computing.
nicholas@103 5666 // No need to check if the test was already performed, though.
nicholas@103 5667 computePixelPositionAndBoxSizingReliable();
nicholas@103 5668 return pixelPositionVal;
nicholas@103 5669 },
nicholas@103 5670 boxSizingReliable: function() {
nicholas@103 5671 if ( boxSizingReliableVal == null ) {
nicholas@103 5672 computePixelPositionAndBoxSizingReliable();
nicholas@103 5673 }
nicholas@103 5674 return boxSizingReliableVal;
nicholas@103 5675 },
nicholas@103 5676 reliableMarginRight: function() {
nicholas@103 5677
nicholas@103 5678 // Support: Android 2.3
nicholas@103 5679 // Check if div with explicit width and no margin-right incorrectly
nicholas@103 5680 // gets computed margin-right based on width of container. (#3333)
nicholas@103 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nicholas@103 5682 // This support function is only executed once so no memoizing is needed.
nicholas@103 5683 var ret,
nicholas@103 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nicholas@103 5685
nicholas@103 5686 // Reset CSS: box-sizing; display; margin; border; padding
nicholas@103 5687 marginDiv.style.cssText = div.style.cssText =
nicholas@103 5688 // Support: Firefox<29, Android 2.3
nicholas@103 5689 // Vendor-prefix box-sizing
nicholas@103 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nicholas@103 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nicholas@103 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nicholas@103 5693 div.style.width = "1px";
nicholas@103 5694 docElem.appendChild( container );
nicholas@103 5695
nicholas@103 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nicholas@103 5697
nicholas@103 5698 docElem.removeChild( container );
nicholas@103 5699 div.removeChild( marginDiv );
nicholas@103 5700
nicholas@103 5701 return ret;
nicholas@103 5702 }
nicholas@103 5703 });
nicholas@103 5704 }
nicholas@103 5705 })();
nicholas@103 5706
nicholas@103 5707
nicholas@103 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nicholas@103 5709 jQuery.swap = function( elem, options, callback, args ) {
nicholas@103 5710 var ret, name,
nicholas@103 5711 old = {};
nicholas@103 5712
nicholas@103 5713 // Remember the old values, and insert the new ones
nicholas@103 5714 for ( name in options ) {
nicholas@103 5715 old[ name ] = elem.style[ name ];
nicholas@103 5716 elem.style[ name ] = options[ name ];
nicholas@103 5717 }
nicholas@103 5718
nicholas@103 5719 ret = callback.apply( elem, args || [] );
nicholas@103 5720
nicholas@103 5721 // Revert the old values
nicholas@103 5722 for ( name in options ) {
nicholas@103 5723 elem.style[ name ] = old[ name ];
nicholas@103 5724 }
nicholas@103 5725
nicholas@103 5726 return ret;
nicholas@103 5727 };
nicholas@103 5728
nicholas@103 5729
nicholas@103 5730 var
nicholas@103 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nicholas@103 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nicholas@103 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nicholas@103 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nicholas@103 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nicholas@103 5736
nicholas@103 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nicholas@103 5738 cssNormalTransform = {
nicholas@103 5739 letterSpacing: "0",
nicholas@103 5740 fontWeight: "400"
nicholas@103 5741 },
nicholas@103 5742
nicholas@103 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nicholas@103 5744
nicholas@103 5745 // Return a css property mapped to a potentially vendor prefixed property
nicholas@103 5746 function vendorPropName( style, name ) {
nicholas@103 5747
nicholas@103 5748 // Shortcut for names that are not vendor prefixed
nicholas@103 5749 if ( name in style ) {
nicholas@103 5750 return name;
nicholas@103 5751 }
nicholas@103 5752
nicholas@103 5753 // Check for vendor prefixed names
nicholas@103 5754 var capName = name[0].toUpperCase() + name.slice(1),
nicholas@103 5755 origName = name,
nicholas@103 5756 i = cssPrefixes.length;
nicholas@103 5757
nicholas@103 5758 while ( i-- ) {
nicholas@103 5759 name = cssPrefixes[ i ] + capName;
nicholas@103 5760 if ( name in style ) {
nicholas@103 5761 return name;
nicholas@103 5762 }
nicholas@103 5763 }
nicholas@103 5764
nicholas@103 5765 return origName;
nicholas@103 5766 }
nicholas@103 5767
nicholas@103 5768 function setPositiveNumber( elem, value, subtract ) {
nicholas@103 5769 var matches = rnumsplit.exec( value );
nicholas@103 5770 return matches ?
nicholas@103 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nicholas@103 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nicholas@103 5773 value;
nicholas@103 5774 }
nicholas@103 5775
nicholas@103 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nicholas@103 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nicholas@103 5778 // If we already have the right measurement, avoid augmentation
nicholas@103 5779 4 :
nicholas@103 5780 // Otherwise initialize for horizontal or vertical properties
nicholas@103 5781 name === "width" ? 1 : 0,
nicholas@103 5782
nicholas@103 5783 val = 0;
nicholas@103 5784
nicholas@103 5785 for ( ; i < 4; i += 2 ) {
nicholas@103 5786 // Both box models exclude margin, so add it if we want it
nicholas@103 5787 if ( extra === "margin" ) {
nicholas@103 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nicholas@103 5789 }
nicholas@103 5790
nicholas@103 5791 if ( isBorderBox ) {
nicholas@103 5792 // border-box includes padding, so remove it if we want content
nicholas@103 5793 if ( extra === "content" ) {
nicholas@103 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nicholas@103 5795 }
nicholas@103 5796
nicholas@103 5797 // At this point, extra isn't border nor margin, so remove border
nicholas@103 5798 if ( extra !== "margin" ) {
nicholas@103 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nicholas@103 5800 }
nicholas@103 5801 } else {
nicholas@103 5802 // At this point, extra isn't content, so add padding
nicholas@103 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nicholas@103 5804
nicholas@103 5805 // At this point, extra isn't content nor padding, so add border
nicholas@103 5806 if ( extra !== "padding" ) {
nicholas@103 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nicholas@103 5808 }
nicholas@103 5809 }
nicholas@103 5810 }
nicholas@103 5811
nicholas@103 5812 return val;
nicholas@103 5813 }
nicholas@103 5814
nicholas@103 5815 function getWidthOrHeight( elem, name, extra ) {
nicholas@103 5816
nicholas@103 5817 // Start with offset property, which is equivalent to the border-box value
nicholas@103 5818 var valueIsBorderBox = true,
nicholas@103 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nicholas@103 5820 styles = getStyles( elem ),
nicholas@103 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nicholas@103 5822
nicholas@103 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nicholas@103 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nicholas@103 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nicholas@103 5826 if ( val <= 0 || val == null ) {
nicholas@103 5827 // Fall back to computed then uncomputed css if necessary
nicholas@103 5828 val = curCSS( elem, name, styles );
nicholas@103 5829 if ( val < 0 || val == null ) {
nicholas@103 5830 val = elem.style[ name ];
nicholas@103 5831 }
nicholas@103 5832
nicholas@103 5833 // Computed unit is not pixels. Stop here and return.
nicholas@103 5834 if ( rnumnonpx.test(val) ) {
nicholas@103 5835 return val;
nicholas@103 5836 }
nicholas@103 5837
nicholas@103 5838 // Check for style in case a browser which returns unreliable values
nicholas@103 5839 // for getComputedStyle silently falls back to the reliable elem.style
nicholas@103 5840 valueIsBorderBox = isBorderBox &&
nicholas@103 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nicholas@103 5842
nicholas@103 5843 // Normalize "", auto, and prepare for extra
nicholas@103 5844 val = parseFloat( val ) || 0;
nicholas@103 5845 }
nicholas@103 5846
nicholas@103 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nicholas@103 5848 return ( val +
nicholas@103 5849 augmentWidthOrHeight(
nicholas@103 5850 elem,
nicholas@103 5851 name,
nicholas@103 5852 extra || ( isBorderBox ? "border" : "content" ),
nicholas@103 5853 valueIsBorderBox,
nicholas@103 5854 styles
nicholas@103 5855 )
nicholas@103 5856 ) + "px";
nicholas@103 5857 }
nicholas@103 5858
nicholas@103 5859 function showHide( elements, show ) {
nicholas@103 5860 var display, elem, hidden,
nicholas@103 5861 values = [],
nicholas@103 5862 index = 0,
nicholas@103 5863 length = elements.length;
nicholas@103 5864
nicholas@103 5865 for ( ; index < length; index++ ) {
nicholas@103 5866 elem = elements[ index ];
nicholas@103 5867 if ( !elem.style ) {
nicholas@103 5868 continue;
nicholas@103 5869 }
nicholas@103 5870
nicholas@103 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nicholas@103 5872 display = elem.style.display;
nicholas@103 5873 if ( show ) {
nicholas@103 5874 // Reset the inline display of this element to learn if it is
nicholas@103 5875 // being hidden by cascaded rules or not
nicholas@103 5876 if ( !values[ index ] && display === "none" ) {
nicholas@103 5877 elem.style.display = "";
nicholas@103 5878 }
nicholas@103 5879
nicholas@103 5880 // Set elements which have been overridden with display: none
nicholas@103 5881 // in a stylesheet to whatever the default browser style is
nicholas@103 5882 // for such an element
nicholas@103 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nicholas@103 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nicholas@103 5885 }
nicholas@103 5886 } else {
nicholas@103 5887 hidden = isHidden( elem );
nicholas@103 5888
nicholas@103 5889 if ( display !== "none" || !hidden ) {
nicholas@103 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nicholas@103 5891 }
nicholas@103 5892 }
nicholas@103 5893 }
nicholas@103 5894
nicholas@103 5895 // Set the display of most of the elements in a second loop
nicholas@103 5896 // to avoid the constant reflow
nicholas@103 5897 for ( index = 0; index < length; index++ ) {
nicholas@103 5898 elem = elements[ index ];
nicholas@103 5899 if ( !elem.style ) {
nicholas@103 5900 continue;
nicholas@103 5901 }
nicholas@103 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nicholas@103 5903 elem.style.display = show ? values[ index ] || "" : "none";
nicholas@103 5904 }
nicholas@103 5905 }
nicholas@103 5906
nicholas@103 5907 return elements;
nicholas@103 5908 }
nicholas@103 5909
nicholas@103 5910 jQuery.extend({
nicholas@103 5911
nicholas@103 5912 // Add in style property hooks for overriding the default
nicholas@103 5913 // behavior of getting and setting a style property
nicholas@103 5914 cssHooks: {
nicholas@103 5915 opacity: {
nicholas@103 5916 get: function( elem, computed ) {
nicholas@103 5917 if ( computed ) {
nicholas@103 5918
nicholas@103 5919 // We should always get a number back from opacity
nicholas@103 5920 var ret = curCSS( elem, "opacity" );
nicholas@103 5921 return ret === "" ? "1" : ret;
nicholas@103 5922 }
nicholas@103 5923 }
nicholas@103 5924 }
nicholas@103 5925 },
nicholas@103 5926
nicholas@103 5927 // Don't automatically add "px" to these possibly-unitless properties
nicholas@103 5928 cssNumber: {
nicholas@103 5929 "columnCount": true,
nicholas@103 5930 "fillOpacity": true,
nicholas@103 5931 "flexGrow": true,
nicholas@103 5932 "flexShrink": true,
nicholas@103 5933 "fontWeight": true,
nicholas@103 5934 "lineHeight": true,
nicholas@103 5935 "opacity": true,
nicholas@103 5936 "order": true,
nicholas@103 5937 "orphans": true,
nicholas@103 5938 "widows": true,
nicholas@103 5939 "zIndex": true,
nicholas@103 5940 "zoom": true
nicholas@103 5941 },
nicholas@103 5942
nicholas@103 5943 // Add in properties whose names you wish to fix before
nicholas@103 5944 // setting or getting the value
nicholas@103 5945 cssProps: {
nicholas@103 5946 "float": "cssFloat"
nicholas@103 5947 },
nicholas@103 5948
nicholas@103 5949 // Get and set the style property on a DOM Node
nicholas@103 5950 style: function( elem, name, value, extra ) {
nicholas@103 5951
nicholas@103 5952 // Don't set styles on text and comment nodes
nicholas@103 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nicholas@103 5954 return;
nicholas@103 5955 }
nicholas@103 5956
nicholas@103 5957 // Make sure that we're working with the right name
nicholas@103 5958 var ret, type, hooks,
nicholas@103 5959 origName = jQuery.camelCase( name ),
nicholas@103 5960 style = elem.style;
nicholas@103 5961
nicholas@103 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nicholas@103 5963
nicholas@103 5964 // Gets hook for the prefixed version, then unprefixed version
nicholas@103 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nicholas@103 5966
nicholas@103 5967 // Check if we're setting a value
nicholas@103 5968 if ( value !== undefined ) {
nicholas@103 5969 type = typeof value;
nicholas@103 5970
nicholas@103 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nicholas@103 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nicholas@103 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nicholas@103 5974 // Fixes bug #9237
nicholas@103 5975 type = "number";
nicholas@103 5976 }
nicholas@103 5977
nicholas@103 5978 // Make sure that null and NaN values aren't set (#7116)
nicholas@103 5979 if ( value == null || value !== value ) {
nicholas@103 5980 return;
nicholas@103 5981 }
nicholas@103 5982
nicholas@103 5983 // If a number, add 'px' to the (except for certain CSS properties)
nicholas@103 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nicholas@103 5985 value += "px";
nicholas@103 5986 }
nicholas@103 5987
nicholas@103 5988 // Support: IE9-11+
nicholas@103 5989 // background-* props affect original clone's values
nicholas@103 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nicholas@103 5991 style[ name ] = "inherit";
nicholas@103 5992 }
nicholas@103 5993
nicholas@103 5994 // If a hook was provided, use that value, otherwise just set the specified value
nicholas@103 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nicholas@103 5996 style[ name ] = value;
nicholas@103 5997 }
nicholas@103 5998
nicholas@103 5999 } else {
nicholas@103 6000 // If a hook was provided get the non-computed value from there
nicholas@103 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nicholas@103 6002 return ret;
nicholas@103 6003 }
nicholas@103 6004
nicholas@103 6005 // Otherwise just get the value from the style object
nicholas@103 6006 return style[ name ];
nicholas@103 6007 }
nicholas@103 6008 },
nicholas@103 6009
nicholas@103 6010 css: function( elem, name, extra, styles ) {
nicholas@103 6011 var val, num, hooks,
nicholas@103 6012 origName = jQuery.camelCase( name );
nicholas@103 6013
nicholas@103 6014 // Make sure that we're working with the right name
nicholas@103 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nicholas@103 6016
nicholas@103 6017 // Try prefixed name followed by the unprefixed name
nicholas@103 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nicholas@103 6019
nicholas@103 6020 // If a hook was provided get the computed value from there
nicholas@103 6021 if ( hooks && "get" in hooks ) {
nicholas@103 6022 val = hooks.get( elem, true, extra );
nicholas@103 6023 }
nicholas@103 6024
nicholas@103 6025 // Otherwise, if a way to get the computed value exists, use that
nicholas@103 6026 if ( val === undefined ) {
nicholas@103 6027 val = curCSS( elem, name, styles );
nicholas@103 6028 }
nicholas@103 6029
nicholas@103 6030 // Convert "normal" to computed value
nicholas@103 6031 if ( val === "normal" && name in cssNormalTransform ) {
nicholas@103 6032 val = cssNormalTransform[ name ];
nicholas@103 6033 }
nicholas@103 6034
nicholas@103 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nicholas@103 6036 if ( extra === "" || extra ) {
nicholas@103 6037 num = parseFloat( val );
nicholas@103 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nicholas@103 6039 }
nicholas@103 6040 return val;
nicholas@103 6041 }
nicholas@103 6042 });
nicholas@103 6043
nicholas@103 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nicholas@103 6045 jQuery.cssHooks[ name ] = {
nicholas@103 6046 get: function( elem, computed, extra ) {
nicholas@103 6047 if ( computed ) {
nicholas@103 6048
nicholas@103 6049 // Certain elements can have dimension info if we invisibly show them
nicholas@103 6050 // but it must have a current display style that would benefit
nicholas@103 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nicholas@103 6052 jQuery.swap( elem, cssShow, function() {
nicholas@103 6053 return getWidthOrHeight( elem, name, extra );
nicholas@103 6054 }) :
nicholas@103 6055 getWidthOrHeight( elem, name, extra );
nicholas@103 6056 }
nicholas@103 6057 },
nicholas@103 6058
nicholas@103 6059 set: function( elem, value, extra ) {
nicholas@103 6060 var styles = extra && getStyles( elem );
nicholas@103 6061 return setPositiveNumber( elem, value, extra ?
nicholas@103 6062 augmentWidthOrHeight(
nicholas@103 6063 elem,
nicholas@103 6064 name,
nicholas@103 6065 extra,
nicholas@103 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nicholas@103 6067 styles
nicholas@103 6068 ) : 0
nicholas@103 6069 );
nicholas@103 6070 }
nicholas@103 6071 };
nicholas@103 6072 });
nicholas@103 6073
nicholas@103 6074 // Support: Android 2.3
nicholas@103 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nicholas@103 6076 function( elem, computed ) {
nicholas@103 6077 if ( computed ) {
nicholas@103 6078 return jQuery.swap( elem, { "display": "inline-block" },
nicholas@103 6079 curCSS, [ elem, "marginRight" ] );
nicholas@103 6080 }
nicholas@103 6081 }
nicholas@103 6082 );
nicholas@103 6083
nicholas@103 6084 // These hooks are used by animate to expand properties
nicholas@103 6085 jQuery.each({
nicholas@103 6086 margin: "",
nicholas@103 6087 padding: "",
nicholas@103 6088 border: "Width"
nicholas@103 6089 }, function( prefix, suffix ) {
nicholas@103 6090 jQuery.cssHooks[ prefix + suffix ] = {
nicholas@103 6091 expand: function( value ) {
nicholas@103 6092 var i = 0,
nicholas@103 6093 expanded = {},
nicholas@103 6094
nicholas@103 6095 // Assumes a single number if not a string
nicholas@103 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nicholas@103 6097
nicholas@103 6098 for ( ; i < 4; i++ ) {
nicholas@103 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nicholas@103 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nicholas@103 6101 }
nicholas@103 6102
nicholas@103 6103 return expanded;
nicholas@103 6104 }
nicholas@103 6105 };
nicholas@103 6106
nicholas@103 6107 if ( !rmargin.test( prefix ) ) {
nicholas@103 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nicholas@103 6109 }
nicholas@103 6110 });
nicholas@103 6111
nicholas@103 6112 jQuery.fn.extend({
nicholas@103 6113 css: function( name, value ) {
nicholas@103 6114 return access( this, function( elem, name, value ) {
nicholas@103 6115 var styles, len,
nicholas@103 6116 map = {},
nicholas@103 6117 i = 0;
nicholas@103 6118
nicholas@103 6119 if ( jQuery.isArray( name ) ) {
nicholas@103 6120 styles = getStyles( elem );
nicholas@103 6121 len = name.length;
nicholas@103 6122
nicholas@103 6123 for ( ; i < len; i++ ) {
nicholas@103 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nicholas@103 6125 }
nicholas@103 6126
nicholas@103 6127 return map;
nicholas@103 6128 }
nicholas@103 6129
nicholas@103 6130 return value !== undefined ?
nicholas@103 6131 jQuery.style( elem, name, value ) :
nicholas@103 6132 jQuery.css( elem, name );
nicholas@103 6133 }, name, value, arguments.length > 1 );
nicholas@103 6134 },
nicholas@103 6135 show: function() {
nicholas@103 6136 return showHide( this, true );
nicholas@103 6137 },
nicholas@103 6138 hide: function() {
nicholas@103 6139 return showHide( this );
nicholas@103 6140 },
nicholas@103 6141 toggle: function( state ) {
nicholas@103 6142 if ( typeof state === "boolean" ) {
nicholas@103 6143 return state ? this.show() : this.hide();
nicholas@103 6144 }
nicholas@103 6145
nicholas@103 6146 return this.each(function() {
nicholas@103 6147 if ( isHidden( this ) ) {
nicholas@103 6148 jQuery( this ).show();
nicholas@103 6149 } else {
nicholas@103 6150 jQuery( this ).hide();
nicholas@103 6151 }
nicholas@103 6152 });
nicholas@103 6153 }
nicholas@103 6154 });
nicholas@103 6155
nicholas@103 6156
nicholas@103 6157 function Tween( elem, options, prop, end, easing ) {
nicholas@103 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nicholas@103 6159 }
nicholas@103 6160 jQuery.Tween = Tween;
nicholas@103 6161
nicholas@103 6162 Tween.prototype = {
nicholas@103 6163 constructor: Tween,
nicholas@103 6164 init: function( elem, options, prop, end, easing, unit ) {
nicholas@103 6165 this.elem = elem;
nicholas@103 6166 this.prop = prop;
nicholas@103 6167 this.easing = easing || "swing";
nicholas@103 6168 this.options = options;
nicholas@103 6169 this.start = this.now = this.cur();
nicholas@103 6170 this.end = end;
nicholas@103 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nicholas@103 6172 },
nicholas@103 6173 cur: function() {
nicholas@103 6174 var hooks = Tween.propHooks[ this.prop ];
nicholas@103 6175
nicholas@103 6176 return hooks && hooks.get ?
nicholas@103 6177 hooks.get( this ) :
nicholas@103 6178 Tween.propHooks._default.get( this );
nicholas@103 6179 },
nicholas@103 6180 run: function( percent ) {
nicholas@103 6181 var eased,
nicholas@103 6182 hooks = Tween.propHooks[ this.prop ];
nicholas@103 6183
nicholas@103 6184 if ( this.options.duration ) {
nicholas@103 6185 this.pos = eased = jQuery.easing[ this.easing ](
nicholas@103 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nicholas@103 6187 );
nicholas@103 6188 } else {
nicholas@103 6189 this.pos = eased = percent;
nicholas@103 6190 }
nicholas@103 6191 this.now = ( this.end - this.start ) * eased + this.start;
nicholas@103 6192
nicholas@103 6193 if ( this.options.step ) {
nicholas@103 6194 this.options.step.call( this.elem, this.now, this );
nicholas@103 6195 }
nicholas@103 6196
nicholas@103 6197 if ( hooks && hooks.set ) {
nicholas@103 6198 hooks.set( this );
nicholas@103 6199 } else {
nicholas@103 6200 Tween.propHooks._default.set( this );
nicholas@103 6201 }
nicholas@103 6202 return this;
nicholas@103 6203 }
nicholas@103 6204 };
nicholas@103 6205
nicholas@103 6206 Tween.prototype.init.prototype = Tween.prototype;
nicholas@103 6207
nicholas@103 6208 Tween.propHooks = {
nicholas@103 6209 _default: {
nicholas@103 6210 get: function( tween ) {
nicholas@103 6211 var result;
nicholas@103 6212
nicholas@103 6213 if ( tween.elem[ tween.prop ] != null &&
nicholas@103 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nicholas@103 6215 return tween.elem[ tween.prop ];
nicholas@103 6216 }
nicholas@103 6217
nicholas@103 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nicholas@103 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nicholas@103 6220 // Simple values such as "10px" are parsed to Float;
nicholas@103 6221 // complex values such as "rotate(1rad)" are returned as-is.
nicholas@103 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nicholas@103 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nicholas@103 6224 return !result || result === "auto" ? 0 : result;
nicholas@103 6225 },
nicholas@103 6226 set: function( tween ) {
nicholas@103 6227 // Use step hook for back compat.
nicholas@103 6228 // Use cssHook if its there.
nicholas@103 6229 // Use .style if available and use plain properties where available.
nicholas@103 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nicholas@103 6231 jQuery.fx.step[ tween.prop ]( tween );
nicholas@103 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nicholas@103 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nicholas@103 6234 } else {
nicholas@103 6235 tween.elem[ tween.prop ] = tween.now;
nicholas@103 6236 }
nicholas@103 6237 }
nicholas@103 6238 }
nicholas@103 6239 };
nicholas@103 6240
nicholas@103 6241 // Support: IE9
nicholas@103 6242 // Panic based approach to setting things on disconnected nodes
nicholas@103 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nicholas@103 6244 set: function( tween ) {
nicholas@103 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nicholas@103 6246 tween.elem[ tween.prop ] = tween.now;
nicholas@103 6247 }
nicholas@103 6248 }
nicholas@103 6249 };
nicholas@103 6250
nicholas@103 6251 jQuery.easing = {
nicholas@103 6252 linear: function( p ) {
nicholas@103 6253 return p;
nicholas@103 6254 },
nicholas@103 6255 swing: function( p ) {
nicholas@103 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nicholas@103 6257 }
nicholas@103 6258 };
nicholas@103 6259
nicholas@103 6260 jQuery.fx = Tween.prototype.init;
nicholas@103 6261
nicholas@103 6262 // Back Compat <1.8 extension point
nicholas@103 6263 jQuery.fx.step = {};
nicholas@103 6264
nicholas@103 6265
nicholas@103 6266
nicholas@103 6267
nicholas@103 6268 var
nicholas@103 6269 fxNow, timerId,
nicholas@103 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nicholas@103 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nicholas@103 6272 rrun = /queueHooks$/,
nicholas@103 6273 animationPrefilters = [ defaultPrefilter ],
nicholas@103 6274 tweeners = {
nicholas@103 6275 "*": [ function( prop, value ) {
nicholas@103 6276 var tween = this.createTween( prop, value ),
nicholas@103 6277 target = tween.cur(),
nicholas@103 6278 parts = rfxnum.exec( value ),
nicholas@103 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nicholas@103 6280
nicholas@103 6281 // Starting value computation is required for potential unit mismatches
nicholas@103 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nicholas@103 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nicholas@103 6284 scale = 1,
nicholas@103 6285 maxIterations = 20;
nicholas@103 6286
nicholas@103 6287 if ( start && start[ 3 ] !== unit ) {
nicholas@103 6288 // Trust units reported by jQuery.css
nicholas@103 6289 unit = unit || start[ 3 ];
nicholas@103 6290
nicholas@103 6291 // Make sure we update the tween properties later on
nicholas@103 6292 parts = parts || [];
nicholas@103 6293
nicholas@103 6294 // Iteratively approximate from a nonzero starting point
nicholas@103 6295 start = +target || 1;
nicholas@103 6296
nicholas@103 6297 do {
nicholas@103 6298 // If previous iteration zeroed out, double until we get *something*.
nicholas@103 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nicholas@103 6300 scale = scale || ".5";
nicholas@103 6301
nicholas@103 6302 // Adjust and apply
nicholas@103 6303 start = start / scale;
nicholas@103 6304 jQuery.style( tween.elem, prop, start + unit );
nicholas@103 6305
nicholas@103 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nicholas@103 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nicholas@103 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nicholas@103 6309 }
nicholas@103 6310
nicholas@103 6311 // Update tween properties
nicholas@103 6312 if ( parts ) {
nicholas@103 6313 start = tween.start = +start || +target || 0;
nicholas@103 6314 tween.unit = unit;
nicholas@103 6315 // If a +=/-= token was provided, we're doing a relative animation
nicholas@103 6316 tween.end = parts[ 1 ] ?
nicholas@103 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nicholas@103 6318 +parts[ 2 ];
nicholas@103 6319 }
nicholas@103 6320
nicholas@103 6321 return tween;
nicholas@103 6322 } ]
nicholas@103 6323 };
nicholas@103 6324
nicholas@103 6325 // Animations created synchronously will run synchronously
nicholas@103 6326 function createFxNow() {
nicholas@103 6327 setTimeout(function() {
nicholas@103 6328 fxNow = undefined;
nicholas@103 6329 });
nicholas@103 6330 return ( fxNow = jQuery.now() );
nicholas@103 6331 }
nicholas@103 6332
nicholas@103 6333 // Generate parameters to create a standard animation
nicholas@103 6334 function genFx( type, includeWidth ) {
nicholas@103 6335 var which,
nicholas@103 6336 i = 0,
nicholas@103 6337 attrs = { height: type };
nicholas@103 6338
nicholas@103 6339 // If we include width, step value is 1 to do all cssExpand values,
nicholas@103 6340 // otherwise step value is 2 to skip over Left and Right
nicholas@103 6341 includeWidth = includeWidth ? 1 : 0;
nicholas@103 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nicholas@103 6343 which = cssExpand[ i ];
nicholas@103 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nicholas@103 6345 }
nicholas@103 6346
nicholas@103 6347 if ( includeWidth ) {
nicholas@103 6348 attrs.opacity = attrs.width = type;
nicholas@103 6349 }
nicholas@103 6350
nicholas@103 6351 return attrs;
nicholas@103 6352 }
nicholas@103 6353
nicholas@103 6354 function createTween( value, prop, animation ) {
nicholas@103 6355 var tween,
nicholas@103 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nicholas@103 6357 index = 0,
nicholas@103 6358 length = collection.length;
nicholas@103 6359 for ( ; index < length; index++ ) {
nicholas@103 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nicholas@103 6361
nicholas@103 6362 // We're done with this property
nicholas@103 6363 return tween;
nicholas@103 6364 }
nicholas@103 6365 }
nicholas@103 6366 }
nicholas@103 6367
nicholas@103 6368 function defaultPrefilter( elem, props, opts ) {
nicholas@103 6369 /* jshint validthis: true */
nicholas@103 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nicholas@103 6371 anim = this,
nicholas@103 6372 orig = {},
nicholas@103 6373 style = elem.style,
nicholas@103 6374 hidden = elem.nodeType && isHidden( elem ),
nicholas@103 6375 dataShow = data_priv.get( elem, "fxshow" );
nicholas@103 6376
nicholas@103 6377 // Handle queue: false promises
nicholas@103 6378 if ( !opts.queue ) {
nicholas@103 6379 hooks = jQuery._queueHooks( elem, "fx" );
nicholas@103 6380 if ( hooks.unqueued == null ) {
nicholas@103 6381 hooks.unqueued = 0;
nicholas@103 6382 oldfire = hooks.empty.fire;
nicholas@103 6383 hooks.empty.fire = function() {
nicholas@103 6384 if ( !hooks.unqueued ) {
nicholas@103 6385 oldfire();
nicholas@103 6386 }
nicholas@103 6387 };
nicholas@103 6388 }
nicholas@103 6389 hooks.unqueued++;
nicholas@103 6390
nicholas@103 6391 anim.always(function() {
nicholas@103 6392 // Ensure the complete handler is called before this completes
nicholas@103 6393 anim.always(function() {
nicholas@103 6394 hooks.unqueued--;
nicholas@103 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nicholas@103 6396 hooks.empty.fire();
nicholas@103 6397 }
nicholas@103 6398 });
nicholas@103 6399 });
nicholas@103 6400 }
nicholas@103 6401
nicholas@103 6402 // Height/width overflow pass
nicholas@103 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nicholas@103 6404 // Make sure that nothing sneaks out
nicholas@103 6405 // Record all 3 overflow attributes because IE9-10 do not
nicholas@103 6406 // change the overflow attribute when overflowX and
nicholas@103 6407 // overflowY are set to the same value
nicholas@103 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nicholas@103 6409
nicholas@103 6410 // Set display property to inline-block for height/width
nicholas@103 6411 // animations on inline elements that are having width/height animated
nicholas@103 6412 display = jQuery.css( elem, "display" );
nicholas@103 6413
nicholas@103 6414 // Test default display if display is currently "none"
nicholas@103 6415 checkDisplay = display === "none" ?
nicholas@103 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nicholas@103 6417
nicholas@103 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nicholas@103 6419 style.display = "inline-block";
nicholas@103 6420 }
nicholas@103 6421 }
nicholas@103 6422
nicholas@103 6423 if ( opts.overflow ) {
nicholas@103 6424 style.overflow = "hidden";
nicholas@103 6425 anim.always(function() {
nicholas@103 6426 style.overflow = opts.overflow[ 0 ];
nicholas@103 6427 style.overflowX = opts.overflow[ 1 ];
nicholas@103 6428 style.overflowY = opts.overflow[ 2 ];
nicholas@103 6429 });
nicholas@103 6430 }
nicholas@103 6431
nicholas@103 6432 // show/hide pass
nicholas@103 6433 for ( prop in props ) {
nicholas@103 6434 value = props[ prop ];
nicholas@103 6435 if ( rfxtypes.exec( value ) ) {
nicholas@103 6436 delete props[ prop ];
nicholas@103 6437 toggle = toggle || value === "toggle";
nicholas@103 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nicholas@103 6439
nicholas@103 6440 // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden
nicholas@103 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nicholas@103 6442 hidden = true;
nicholas@103 6443 } else {
nicholas@103 6444 continue;
nicholas@103 6445 }
nicholas@103 6446 }
nicholas@103 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nicholas@103 6448
nicholas@103 6449 // Any non-fx value stops us from restoring the original display value
nicholas@103 6450 } else {
nicholas@103 6451 display = undefined;
nicholas@103 6452 }
nicholas@103 6453 }
nicholas@103 6454
nicholas@103 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nicholas@103 6456 if ( dataShow ) {
nicholas@103 6457 if ( "hidden" in dataShow ) {
nicholas@103 6458 hidden = dataShow.hidden;
nicholas@103 6459 }
nicholas@103 6460 } else {
nicholas@103 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nicholas@103 6462 }
nicholas@103 6463
nicholas@103 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nicholas@103 6465 if ( toggle ) {
nicholas@103 6466 dataShow.hidden = !hidden;
nicholas@103 6467 }
nicholas@103 6468 if ( hidden ) {
nicholas@103 6469 jQuery( elem ).show();
nicholas@103 6470 } else {
nicholas@103 6471 anim.done(function() {
nicholas@103 6472 jQuery( elem ).hide();
nicholas@103 6473 });
nicholas@103 6474 }
nicholas@103 6475 anim.done(function() {
nicholas@103 6476 var prop;
nicholas@103 6477
nicholas@103 6478 data_priv.remove( elem, "fxshow" );
nicholas@103 6479 for ( prop in orig ) {
nicholas@103 6480 jQuery.style( elem, prop, orig[ prop ] );
nicholas@103 6481 }
nicholas@103 6482 });
nicholas@103 6483 for ( prop in orig ) {
nicholas@103 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nicholas@103 6485
nicholas@103 6486 if ( !( prop in dataShow ) ) {
nicholas@103 6487 dataShow[ prop ] = tween.start;
nicholas@103 6488 if ( hidden ) {
nicholas@103 6489 tween.end = tween.start;
nicholas@103 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nicholas@103 6491 }
nicholas@103 6492 }
nicholas@103 6493 }
nicholas@103 6494
nicholas@103 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nicholas@103 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nicholas@103 6497 style.display = display;
nicholas@103 6498 }
nicholas@103 6499 }
nicholas@103 6500
nicholas@103 6501 function propFilter( props, specialEasing ) {
nicholas@103 6502 var index, name, easing, value, hooks;
nicholas@103 6503
nicholas@103 6504 // camelCase, specialEasing and expand cssHook pass
nicholas@103 6505 for ( index in props ) {
nicholas@103 6506 name = jQuery.camelCase( index );
nicholas@103 6507 easing = specialEasing[ name ];
nicholas@103 6508 value = props[ index ];
nicholas@103 6509 if ( jQuery.isArray( value ) ) {
nicholas@103 6510 easing = value[ 1 ];
nicholas@103 6511 value = props[ index ] = value[ 0 ];
nicholas@103 6512 }
nicholas@103 6513
nicholas@103 6514 if ( index !== name ) {
nicholas@103 6515 props[ name ] = value;
nicholas@103 6516 delete props[ index ];
nicholas@103 6517 }
nicholas@103 6518
nicholas@103 6519 hooks = jQuery.cssHooks[ name ];
nicholas@103 6520 if ( hooks && "expand" in hooks ) {
nicholas@103 6521 value = hooks.expand( value );
nicholas@103 6522 delete props[ name ];
nicholas@103 6523
nicholas@103 6524 // Not quite $.extend, this won't overwrite existing keys.
nicholas@103 6525 // Reusing 'index' because we have the correct "name"
nicholas@103 6526 for ( index in value ) {
nicholas@103 6527 if ( !( index in props ) ) {
nicholas@103 6528 props[ index ] = value[ index ];
nicholas@103 6529 specialEasing[ index ] = easing;
nicholas@103 6530 }
nicholas@103 6531 }
nicholas@103 6532 } else {
nicholas@103 6533 specialEasing[ name ] = easing;
nicholas@103 6534 }
nicholas@103 6535 }
nicholas@103 6536 }
nicholas@103 6537
nicholas@103 6538 function Animation( elem, properties, options ) {
nicholas@103 6539 var result,
nicholas@103 6540 stopped,
nicholas@103 6541 index = 0,
nicholas@103 6542 length = animationPrefilters.length,
nicholas@103 6543 deferred = jQuery.Deferred().always( function() {
nicholas@103 6544 // Don't match elem in the :animated selector
nicholas@103 6545 delete tick.elem;
nicholas@103 6546 }),
nicholas@103 6547 tick = function() {
nicholas@103 6548 if ( stopped ) {
nicholas@103 6549 return false;
nicholas@103 6550 }
nicholas@103 6551 var currentTime = fxNow || createFxNow(),
nicholas@103 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nicholas@103 6553 // Support: Android 2.3
nicholas@103 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nicholas@103 6555 temp = remaining / animation.duration || 0,
nicholas@103 6556 percent = 1 - temp,
nicholas@103 6557 index = 0,
nicholas@103 6558 length = animation.tweens.length;
nicholas@103 6559
nicholas@103 6560 for ( ; index < length ; index++ ) {
nicholas@103 6561 animation.tweens[ index ].run( percent );
nicholas@103 6562 }
nicholas@103 6563
nicholas@103 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nicholas@103 6565
nicholas@103 6566 if ( percent < 1 && length ) {
nicholas@103 6567 return remaining;
nicholas@103 6568 } else {
nicholas@103 6569 deferred.resolveWith( elem, [ animation ] );
nicholas@103 6570 return false;
nicholas@103 6571 }
nicholas@103 6572 },
nicholas@103 6573 animation = deferred.promise({
nicholas@103 6574 elem: elem,
nicholas@103 6575 props: jQuery.extend( {}, properties ),
nicholas@103 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nicholas@103 6577 originalProperties: properties,
nicholas@103 6578 originalOptions: options,
nicholas@103 6579 startTime: fxNow || createFxNow(),
nicholas@103 6580 duration: options.duration,
nicholas@103 6581 tweens: [],
nicholas@103 6582 createTween: function( prop, end ) {
nicholas@103 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nicholas@103 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nicholas@103 6585 animation.tweens.push( tween );
nicholas@103 6586 return tween;
nicholas@103 6587 },
nicholas@103 6588 stop: function( gotoEnd ) {
nicholas@103 6589 var index = 0,
nicholas@103 6590 // If we are going to the end, we want to run all the tweens
nicholas@103 6591 // otherwise we skip this part
nicholas@103 6592 length = gotoEnd ? animation.tweens.length : 0;
nicholas@103 6593 if ( stopped ) {
nicholas@103 6594 return this;
nicholas@103 6595 }
nicholas@103 6596 stopped = true;
nicholas@103 6597 for ( ; index < length ; index++ ) {
nicholas@103 6598 animation.tweens[ index ].run( 1 );
nicholas@103 6599 }
nicholas@103 6600
nicholas@103 6601 // Resolve when we played the last frame; otherwise, reject
nicholas@103 6602 if ( gotoEnd ) {
nicholas@103 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nicholas@103 6604 } else {
nicholas@103 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nicholas@103 6606 }
nicholas@103 6607 return this;
nicholas@103 6608 }
nicholas@103 6609 }),
nicholas@103 6610 props = animation.props;
nicholas@103 6611
nicholas@103 6612 propFilter( props, animation.opts.specialEasing );
nicholas@103 6613
nicholas@103 6614 for ( ; index < length ; index++ ) {
nicholas@103 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nicholas@103 6616 if ( result ) {
nicholas@103 6617 return result;
nicholas@103 6618 }
nicholas@103 6619 }
nicholas@103 6620
nicholas@103 6621 jQuery.map( props, createTween, animation );
nicholas@103 6622
nicholas@103 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nicholas@103 6624 animation.opts.start.call( elem, animation );
nicholas@103 6625 }
nicholas@103 6626
nicholas@103 6627 jQuery.fx.timer(
nicholas@103 6628 jQuery.extend( tick, {
nicholas@103 6629 elem: elem,
nicholas@103 6630 anim: animation,
nicholas@103 6631 queue: animation.opts.queue
nicholas@103 6632 })
nicholas@103 6633 );
nicholas@103 6634
nicholas@103 6635 // attach callbacks from options
nicholas@103 6636 return animation.progress( animation.opts.progress )
nicholas@103 6637 .done( animation.opts.done, animation.opts.complete )
nicholas@103 6638 .fail( animation.opts.fail )
nicholas@103 6639 .always( animation.opts.always );
nicholas@103 6640 }
nicholas@103 6641
nicholas@103 6642 jQuery.Animation = jQuery.extend( Animation, {
nicholas@103 6643
nicholas@103 6644 tweener: function( props, callback ) {
nicholas@103 6645 if ( jQuery.isFunction( props ) ) {
nicholas@103 6646 callback = props;
nicholas@103 6647 props = [ "*" ];
nicholas@103 6648 } else {
nicholas@103 6649 props = props.split(" ");
nicholas@103 6650 }
nicholas@103 6651
nicholas@103 6652 var prop,
nicholas@103 6653 index = 0,
nicholas@103 6654 length = props.length;
nicholas@103 6655
nicholas@103 6656 for ( ; index < length ; index++ ) {
nicholas@103 6657 prop = props[ index ];
nicholas@103 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nicholas@103 6659 tweeners[ prop ].unshift( callback );
nicholas@103 6660 }
nicholas@103 6661 },
nicholas@103 6662
nicholas@103 6663 prefilter: function( callback, prepend ) {
nicholas@103 6664 if ( prepend ) {
nicholas@103 6665 animationPrefilters.unshift( callback );
nicholas@103 6666 } else {
nicholas@103 6667 animationPrefilters.push( callback );
nicholas@103 6668 }
nicholas@103 6669 }
nicholas@103 6670 });
nicholas@103 6671
nicholas@103 6672 jQuery.speed = function( speed, easing, fn ) {
nicholas@103 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nicholas@103 6674 complete: fn || !fn && easing ||
nicholas@103 6675 jQuery.isFunction( speed ) && speed,
nicholas@103 6676 duration: speed,
nicholas@103 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nicholas@103 6678 };
nicholas@103 6679
nicholas@103 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nicholas@103 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nicholas@103 6682
nicholas@103 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nicholas@103 6684 if ( opt.queue == null || opt.queue === true ) {
nicholas@103 6685 opt.queue = "fx";
nicholas@103 6686 }
nicholas@103 6687
nicholas@103 6688 // Queueing
nicholas@103 6689 opt.old = opt.complete;
nicholas@103 6690
nicholas@103 6691 opt.complete = function() {
nicholas@103 6692 if ( jQuery.isFunction( opt.old ) ) {
nicholas@103 6693 opt.old.call( this );
nicholas@103 6694 }
nicholas@103 6695
nicholas@103 6696 if ( opt.queue ) {
nicholas@103 6697 jQuery.dequeue( this, opt.queue );
nicholas@103 6698 }
nicholas@103 6699 };
nicholas@103 6700
nicholas@103 6701 return opt;
nicholas@103 6702 };
nicholas@103 6703
nicholas@103 6704 jQuery.fn.extend({
nicholas@103 6705 fadeTo: function( speed, to, easing, callback ) {
nicholas@103 6706
nicholas@103 6707 // Show any hidden elements after setting opacity to 0
nicholas@103 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nicholas@103 6709
nicholas@103 6710 // Animate to the value specified
nicholas@103 6711 .end().animate({ opacity: to }, speed, easing, callback );
nicholas@103 6712 },
nicholas@103 6713 animate: function( prop, speed, easing, callback ) {
nicholas@103 6714 var empty = jQuery.isEmptyObject( prop ),
nicholas@103 6715 optall = jQuery.speed( speed, easing, callback ),
nicholas@103 6716 doAnimation = function() {
nicholas@103 6717 // Operate on a copy of prop so per-property easing won't be lost
nicholas@103 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nicholas@103 6719
nicholas@103 6720 // Empty animations, or finishing resolves immediately
nicholas@103 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nicholas@103 6722 anim.stop( true );
nicholas@103 6723 }
nicholas@103 6724 };
nicholas@103 6725 doAnimation.finish = doAnimation;
nicholas@103 6726
nicholas@103 6727 return empty || optall.queue === false ?
nicholas@103 6728 this.each( doAnimation ) :
nicholas@103 6729 this.queue( optall.queue, doAnimation );
nicholas@103 6730 },
nicholas@103 6731 stop: function( type, clearQueue, gotoEnd ) {
nicholas@103 6732 var stopQueue = function( hooks ) {
nicholas@103 6733 var stop = hooks.stop;
nicholas@103 6734 delete hooks.stop;
nicholas@103 6735 stop( gotoEnd );
nicholas@103 6736 };
nicholas@103 6737
nicholas@103 6738 if ( typeof type !== "string" ) {
nicholas@103 6739 gotoEnd = clearQueue;
nicholas@103 6740 clearQueue = type;
nicholas@103 6741 type = undefined;
nicholas@103 6742 }
nicholas@103 6743 if ( clearQueue && type !== false ) {
nicholas@103 6744 this.queue( type || "fx", [] );
nicholas@103 6745 }
nicholas@103 6746
nicholas@103 6747 return this.each(function() {
nicholas@103 6748 var dequeue = true,
nicholas@103 6749 index = type != null && type + "queueHooks",
nicholas@103 6750 timers = jQuery.timers,
nicholas@103 6751 data = data_priv.get( this );
nicholas@103 6752
nicholas@103 6753 if ( index ) {
nicholas@103 6754 if ( data[ index ] && data[ index ].stop ) {
nicholas@103 6755 stopQueue( data[ index ] );
nicholas@103 6756 }
nicholas@103 6757 } else {
nicholas@103 6758 for ( index in data ) {
nicholas@103 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nicholas@103 6760 stopQueue( data[ index ] );
nicholas@103 6761 }
nicholas@103 6762 }
nicholas@103 6763 }
nicholas@103 6764
nicholas@103 6765 for ( index = timers.length; index--; ) {
nicholas@103 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nicholas@103 6767 timers[ index ].anim.stop( gotoEnd );
nicholas@103 6768 dequeue = false;
nicholas@103 6769 timers.splice( index, 1 );
nicholas@103 6770 }
nicholas@103 6771 }
nicholas@103 6772
nicholas@103 6773 // Start the next in the queue if the last step wasn't forced.
nicholas@103 6774 // Timers currently will call their complete callbacks, which
nicholas@103 6775 // will dequeue but only if they were gotoEnd.
nicholas@103 6776 if ( dequeue || !gotoEnd ) {
nicholas@103 6777 jQuery.dequeue( this, type );
nicholas@103 6778 }
nicholas@103 6779 });
nicholas@103 6780 },
nicholas@103 6781 finish: function( type ) {
nicholas@103 6782 if ( type !== false ) {
nicholas@103 6783 type = type || "fx";
nicholas@103 6784 }
nicholas@103 6785 return this.each(function() {
nicholas@103 6786 var index,
nicholas@103 6787 data = data_priv.get( this ),
nicholas@103 6788 queue = data[ type + "queue" ],
nicholas@103 6789 hooks = data[ type + "queueHooks" ],
nicholas@103 6790 timers = jQuery.timers,
nicholas@103 6791 length = queue ? queue.length : 0;
nicholas@103 6792
nicholas@103 6793 // Enable finishing flag on private data
nicholas@103 6794 data.finish = true;
nicholas@103 6795
nicholas@103 6796 // Empty the queue first
nicholas@103 6797 jQuery.queue( this, type, [] );
nicholas@103 6798
nicholas@103 6799 if ( hooks && hooks.stop ) {
nicholas@103 6800 hooks.stop.call( this, true );
nicholas@103 6801 }
nicholas@103 6802
nicholas@103 6803 // Look for any active animations, and finish them
nicholas@103 6804 for ( index = timers.length; index--; ) {
nicholas@103 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nicholas@103 6806 timers[ index ].anim.stop( true );
nicholas@103 6807 timers.splice( index, 1 );
nicholas@103 6808 }
nicholas@103 6809 }
nicholas@103 6810
nicholas@103 6811 // Look for any animations in the old queue and finish them
nicholas@103 6812 for ( index = 0; index < length; index++ ) {
nicholas@103 6813 if ( queue[ index ] && queue[ index ].finish ) {
nicholas@103 6814 queue[ index ].finish.call( this );
nicholas@103 6815 }
nicholas@103 6816 }
nicholas@103 6817
nicholas@103 6818 // Turn off finishing flag
nicholas@103 6819 delete data.finish;
nicholas@103 6820 });
nicholas@103 6821 }
nicholas@103 6822 });
nicholas@103 6823
nicholas@103 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nicholas@103 6825 var cssFn = jQuery.fn[ name ];
nicholas@103 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nicholas@103 6827 return speed == null || typeof speed === "boolean" ?
nicholas@103 6828 cssFn.apply( this, arguments ) :
nicholas@103 6829 this.animate( genFx( name, true ), speed, easing, callback );
nicholas@103 6830 };
nicholas@103 6831 });
nicholas@103 6832
nicholas@103 6833 // Generate shortcuts for custom animations
nicholas@103 6834 jQuery.each({
nicholas@103 6835 slideDown: genFx("show"),
nicholas@103 6836 slideUp: genFx("hide"),
nicholas@103 6837 slideToggle: genFx("toggle"),
nicholas@103 6838 fadeIn: { opacity: "show" },
nicholas@103 6839 fadeOut: { opacity: "hide" },
nicholas@103 6840 fadeToggle: { opacity: "toggle" }
nicholas@103 6841 }, function( name, props ) {
nicholas@103 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nicholas@103 6843 return this.animate( props, speed, easing, callback );
nicholas@103 6844 };
nicholas@103 6845 });
nicholas@103 6846
nicholas@103 6847 jQuery.timers = [];
nicholas@103 6848 jQuery.fx.tick = function() {
nicholas@103 6849 var timer,
nicholas@103 6850 i = 0,
nicholas@103 6851 timers = jQuery.timers;
nicholas@103 6852
nicholas@103 6853 fxNow = jQuery.now();
nicholas@103 6854
nicholas@103 6855 for ( ; i < timers.length; i++ ) {
nicholas@103 6856 timer = timers[ i ];
nicholas@103 6857 // Checks the timer has not already been removed
nicholas@103 6858 if ( !timer() && timers[ i ] === timer ) {
nicholas@103 6859 timers.splice( i--, 1 );
nicholas@103 6860 }
nicholas@103 6861 }
nicholas@103 6862
nicholas@103 6863 if ( !timers.length ) {
nicholas@103 6864 jQuery.fx.stop();
nicholas@103 6865 }
nicholas@103 6866 fxNow = undefined;
nicholas@103 6867 };
nicholas@103 6868
nicholas@103 6869 jQuery.fx.timer = function( timer ) {
nicholas@103 6870 jQuery.timers.push( timer );
nicholas@103 6871 if ( timer() ) {
nicholas@103 6872 jQuery.fx.start();
nicholas@103 6873 } else {
nicholas@103 6874 jQuery.timers.pop();
nicholas@103 6875 }
nicholas@103 6876 };
nicholas@103 6877
nicholas@103 6878 jQuery.fx.interval = 13;
nicholas@103 6879
nicholas@103 6880 jQuery.fx.start = function() {
nicholas@103 6881 if ( !timerId ) {
nicholas@103 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nicholas@103 6883 }
nicholas@103 6884 };
nicholas@103 6885
nicholas@103 6886 jQuery.fx.stop = function() {
nicholas@103 6887 clearInterval( timerId );
nicholas@103 6888 timerId = null;
nicholas@103 6889 };
nicholas@103 6890
nicholas@103 6891 jQuery.fx.speeds = {
nicholas@103 6892 slow: 600,
nicholas@103 6893 fast: 200,
nicholas@103 6894 // Default speed
nicholas@103 6895 _default: 400
nicholas@103 6896 };
nicholas@103 6897
nicholas@103 6898
nicholas@103 6899 // Based off of the plugin by Clint Helfers, with permission.
nicholas@103 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nicholas@103 6901 jQuery.fn.delay = function( time, type ) {
nicholas@103 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nicholas@103 6903 type = type || "fx";
nicholas@103 6904
nicholas@103 6905 return this.queue( type, function( next, hooks ) {
nicholas@103 6906 var timeout = setTimeout( next, time );
nicholas@103 6907 hooks.stop = function() {
nicholas@103 6908 clearTimeout( timeout );
nicholas@103 6909 };
nicholas@103 6910 });
nicholas@103 6911 };
nicholas@103 6912
nicholas@103 6913
nicholas@103 6914 (function() {
nicholas@103 6915 var input = document.createElement( "input" ),
nicholas@103 6916 select = document.createElement( "select" ),
nicholas@103 6917 opt = select.appendChild( document.createElement( "option" ) );
nicholas@103 6918
nicholas@103 6919 input.type = "checkbox";
nicholas@103 6920
nicholas@103 6921 // Support: iOS<=5.1, Android<=4.2+
nicholas@103 6922 // Default value for a checkbox should be "on"
nicholas@103 6923 support.checkOn = input.value !== "";
nicholas@103 6924
nicholas@103 6925 // Support: IE<=11+
nicholas@103 6926 // Must access selectedIndex to make default options select
nicholas@103 6927 support.optSelected = opt.selected;
nicholas@103 6928
nicholas@103 6929 // Support: Android<=2.3
nicholas@103 6930 // Options inside disabled selects are incorrectly marked as disabled
nicholas@103 6931 select.disabled = true;
nicholas@103 6932 support.optDisabled = !opt.disabled;
nicholas@103 6933
nicholas@103 6934 // Support: IE<=11+
nicholas@103 6935 // An input loses its value after becoming a radio
nicholas@103 6936 input = document.createElement( "input" );
nicholas@103 6937 input.value = "t";
nicholas@103 6938 input.type = "radio";
nicholas@103 6939 support.radioValue = input.value === "t";
nicholas@103 6940 })();
nicholas@103 6941
nicholas@103 6942
nicholas@103 6943 var nodeHook, boolHook,
nicholas@103 6944 attrHandle = jQuery.expr.attrHandle;
nicholas@103 6945
nicholas@103 6946 jQuery.fn.extend({
nicholas@103 6947 attr: function( name, value ) {
nicholas@103 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nicholas@103 6949 },
nicholas@103 6950
nicholas@103 6951 removeAttr: function( name ) {
nicholas@103 6952 return this.each(function() {
nicholas@103 6953 jQuery.removeAttr( this, name );
nicholas@103 6954 });
nicholas@103 6955 }
nicholas@103 6956 });
nicholas@103 6957
nicholas@103 6958 jQuery.extend({
nicholas@103 6959 attr: function( elem, name, value ) {
nicholas@103 6960 var hooks, ret,
nicholas@103 6961 nType = elem.nodeType;
nicholas@103 6962
nicholas@103 6963 // don't get/set attributes on text, comment and attribute nodes
nicholas@103 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nicholas@103 6965 return;
nicholas@103 6966 }
nicholas@103 6967
nicholas@103 6968 // Fallback to prop when attributes are not supported
nicholas@103 6969 if ( typeof elem.getAttribute === strundefined ) {
nicholas@103 6970 return jQuery.prop( elem, name, value );
nicholas@103 6971 }
nicholas@103 6972
nicholas@103 6973 // All attributes are lowercase
nicholas@103 6974 // Grab necessary hook if one is defined
nicholas@103 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nicholas@103 6976 name = name.toLowerCase();
nicholas@103 6977 hooks = jQuery.attrHooks[ name ] ||
nicholas@103 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nicholas@103 6979 }
nicholas@103 6980
nicholas@103 6981 if ( value !== undefined ) {
nicholas@103 6982
nicholas@103 6983 if ( value === null ) {
nicholas@103 6984 jQuery.removeAttr( elem, name );
nicholas@103 6985
nicholas@103 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nicholas@103 6987 return ret;
nicholas@103 6988
nicholas@103 6989 } else {
nicholas@103 6990 elem.setAttribute( name, value + "" );
nicholas@103 6991 return value;
nicholas@103 6992 }
nicholas@103 6993
nicholas@103 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nicholas@103 6995 return ret;
nicholas@103 6996
nicholas@103 6997 } else {
nicholas@103 6998 ret = jQuery.find.attr( elem, name );
nicholas@103 6999
nicholas@103 7000 // Non-existent attributes return null, we normalize to undefined
nicholas@103 7001 return ret == null ?
nicholas@103 7002 undefined :
nicholas@103 7003 ret;
nicholas@103 7004 }
nicholas@103 7005 },
nicholas@103 7006
nicholas@103 7007 removeAttr: function( elem, value ) {
nicholas@103 7008 var name, propName,
nicholas@103 7009 i = 0,
nicholas@103 7010 attrNames = value && value.match( rnotwhite );
nicholas@103 7011
nicholas@103 7012 if ( attrNames && elem.nodeType === 1 ) {
nicholas@103 7013 while ( (name = attrNames[i++]) ) {
nicholas@103 7014 propName = jQuery.propFix[ name ] || name;
nicholas@103 7015
nicholas@103 7016 // Boolean attributes get special treatment (#10870)
nicholas@103 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nicholas@103 7018 // Set corresponding property to false
nicholas@103 7019 elem[ propName ] = false;
nicholas@103 7020 }
nicholas@103 7021
nicholas@103 7022 elem.removeAttribute( name );
nicholas@103 7023 }
nicholas@103 7024 }
nicholas@103 7025 },
nicholas@103 7026
nicholas@103 7027 attrHooks: {
nicholas@103 7028 type: {
nicholas@103 7029 set: function( elem, value ) {
nicholas@103 7030 if ( !support.radioValue && value === "radio" &&
nicholas@103 7031 jQuery.nodeName( elem, "input" ) ) {
nicholas@103 7032 var val = elem.value;
nicholas@103 7033 elem.setAttribute( "type", value );
nicholas@103 7034 if ( val ) {
nicholas@103 7035 elem.value = val;
nicholas@103 7036 }
nicholas@103 7037 return value;
nicholas@103 7038 }
nicholas@103 7039 }
nicholas@103 7040 }
nicholas@103 7041 }
nicholas@103 7042 });
nicholas@103 7043
nicholas@103 7044 // Hooks for boolean attributes
nicholas@103 7045 boolHook = {
nicholas@103 7046 set: function( elem, value, name ) {
nicholas@103 7047 if ( value === false ) {
nicholas@103 7048 // Remove boolean attributes when set to false
nicholas@103 7049 jQuery.removeAttr( elem, name );
nicholas@103 7050 } else {
nicholas@103 7051 elem.setAttribute( name, name );
nicholas@103 7052 }
nicholas@103 7053 return name;
nicholas@103 7054 }
nicholas@103 7055 };
nicholas@103 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nicholas@103 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nicholas@103 7058
nicholas@103 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nicholas@103 7060 var ret, handle;
nicholas@103 7061 if ( !isXML ) {
nicholas@103 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nicholas@103 7063 handle = attrHandle[ name ];
nicholas@103 7064 attrHandle[ name ] = ret;
nicholas@103 7065 ret = getter( elem, name, isXML ) != null ?
nicholas@103 7066 name.toLowerCase() :
nicholas@103 7067 null;
nicholas@103 7068 attrHandle[ name ] = handle;
nicholas@103 7069 }
nicholas@103 7070 return ret;
nicholas@103 7071 };
nicholas@103 7072 });
nicholas@103 7073
nicholas@103 7074
nicholas@103 7075
nicholas@103 7076
nicholas@103 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nicholas@103 7078
nicholas@103 7079 jQuery.fn.extend({
nicholas@103 7080 prop: function( name, value ) {
nicholas@103 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nicholas@103 7082 },
nicholas@103 7083
nicholas@103 7084 removeProp: function( name ) {
nicholas@103 7085 return this.each(function() {
nicholas@103 7086 delete this[ jQuery.propFix[ name ] || name ];
nicholas@103 7087 });
nicholas@103 7088 }
nicholas@103 7089 });
nicholas@103 7090
nicholas@103 7091 jQuery.extend({
nicholas@103 7092 propFix: {
nicholas@103 7093 "for": "htmlFor",
nicholas@103 7094 "class": "className"
nicholas@103 7095 },
nicholas@103 7096
nicholas@103 7097 prop: function( elem, name, value ) {
nicholas@103 7098 var ret, hooks, notxml,
nicholas@103 7099 nType = elem.nodeType;
nicholas@103 7100
nicholas@103 7101 // Don't get/set properties on text, comment and attribute nodes
nicholas@103 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nicholas@103 7103 return;
nicholas@103 7104 }
nicholas@103 7105
nicholas@103 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nicholas@103 7107
nicholas@103 7108 if ( notxml ) {
nicholas@103 7109 // Fix name and attach hooks
nicholas@103 7110 name = jQuery.propFix[ name ] || name;
nicholas@103 7111 hooks = jQuery.propHooks[ name ];
nicholas@103 7112 }
nicholas@103 7113
nicholas@103 7114 if ( value !== undefined ) {
nicholas@103 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nicholas@103 7116 ret :
nicholas@103 7117 ( elem[ name ] = value );
nicholas@103 7118
nicholas@103 7119 } else {
nicholas@103 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nicholas@103 7121 ret :
nicholas@103 7122 elem[ name ];
nicholas@103 7123 }
nicholas@103 7124 },
nicholas@103 7125
nicholas@103 7126 propHooks: {
nicholas@103 7127 tabIndex: {
nicholas@103 7128 get: function( elem ) {
nicholas@103 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nicholas@103 7130 elem.tabIndex :
nicholas@103 7131 -1;
nicholas@103 7132 }
nicholas@103 7133 }
nicholas@103 7134 }
nicholas@103 7135 });
nicholas@103 7136
nicholas@103 7137 if ( !support.optSelected ) {
nicholas@103 7138 jQuery.propHooks.selected = {
nicholas@103 7139 get: function( elem ) {
nicholas@103 7140 var parent = elem.parentNode;
nicholas@103 7141 if ( parent && parent.parentNode ) {
nicholas@103 7142 parent.parentNode.selectedIndex;
nicholas@103 7143 }
nicholas@103 7144 return null;
nicholas@103 7145 }
nicholas@103 7146 };
nicholas@103 7147 }
nicholas@103 7148
nicholas@103 7149 jQuery.each([
nicholas@103 7150 "tabIndex",
nicholas@103 7151 "readOnly",
nicholas@103 7152 "maxLength",
nicholas@103 7153 "cellSpacing",
nicholas@103 7154 "cellPadding",
nicholas@103 7155 "rowSpan",
nicholas@103 7156 "colSpan",
nicholas@103 7157 "useMap",
nicholas@103 7158 "frameBorder",
nicholas@103 7159 "contentEditable"
nicholas@103 7160 ], function() {
nicholas@103 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nicholas@103 7162 });
nicholas@103 7163
nicholas@103 7164
nicholas@103 7165
nicholas@103 7166
nicholas@103 7167 var rclass = /[\t\r\n\f]/g;
nicholas@103 7168
nicholas@103 7169 jQuery.fn.extend({
nicholas@103 7170 addClass: function( value ) {
nicholas@103 7171 var classes, elem, cur, clazz, j, finalValue,
nicholas@103 7172 proceed = typeof value === "string" && value,
nicholas@103 7173 i = 0,
nicholas@103 7174 len = this.length;
nicholas@103 7175
nicholas@103 7176 if ( jQuery.isFunction( value ) ) {
nicholas@103 7177 return this.each(function( j ) {
nicholas@103 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nicholas@103 7179 });
nicholas@103 7180 }
nicholas@103 7181
nicholas@103 7182 if ( proceed ) {
nicholas@103 7183 // The disjunction here is for better compressibility (see removeClass)
nicholas@103 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nicholas@103 7185
nicholas@103 7186 for ( ; i < len; i++ ) {
nicholas@103 7187 elem = this[ i ];
nicholas@103 7188 cur = elem.nodeType === 1 && ( elem.className ?
nicholas@103 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nicholas@103 7190 " "
nicholas@103 7191 );
nicholas@103 7192
nicholas@103 7193 if ( cur ) {
nicholas@103 7194 j = 0;
nicholas@103 7195 while ( (clazz = classes[j++]) ) {
nicholas@103 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nicholas@103 7197 cur += clazz + " ";
nicholas@103 7198 }
nicholas@103 7199 }
nicholas@103 7200
nicholas@103 7201 // only assign if different to avoid unneeded rendering.
nicholas@103 7202 finalValue = jQuery.trim( cur );
nicholas@103 7203 if ( elem.className !== finalValue ) {
nicholas@103 7204 elem.className = finalValue;
nicholas@103 7205 }
nicholas@103 7206 }
nicholas@103 7207 }
nicholas@103 7208 }
nicholas@103 7209
nicholas@103 7210 return this;
nicholas@103 7211 },
nicholas@103 7212
nicholas@103 7213 removeClass: function( value ) {
nicholas@103 7214 var classes, elem, cur, clazz, j, finalValue,
nicholas@103 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nicholas@103 7216 i = 0,
nicholas@103 7217 len = this.length;
nicholas@103 7218
nicholas@103 7219 if ( jQuery.isFunction( value ) ) {
nicholas@103 7220 return this.each(function( j ) {
nicholas@103 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nicholas@103 7222 });
nicholas@103 7223 }
nicholas@103 7224 if ( proceed ) {
nicholas@103 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nicholas@103 7226
nicholas@103 7227 for ( ; i < len; i++ ) {
nicholas@103 7228 elem = this[ i ];
nicholas@103 7229 // This expression is here for better compressibility (see addClass)
nicholas@103 7230 cur = elem.nodeType === 1 && ( elem.className ?
nicholas@103 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nicholas@103 7232 ""
nicholas@103 7233 );
nicholas@103 7234
nicholas@103 7235 if ( cur ) {
nicholas@103 7236 j = 0;
nicholas@103 7237 while ( (clazz = classes[j++]) ) {
nicholas@103 7238 // Remove *all* instances
nicholas@103 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nicholas@103 7240 cur = cur.replace( " " + clazz + " ", " " );
nicholas@103 7241 }
nicholas@103 7242 }
nicholas@103 7243
nicholas@103 7244 // Only assign if different to avoid unneeded rendering.
nicholas@103 7245 finalValue = value ? jQuery.trim( cur ) : "";
nicholas@103 7246 if ( elem.className !== finalValue ) {
nicholas@103 7247 elem.className = finalValue;
nicholas@103 7248 }
nicholas@103 7249 }
nicholas@103 7250 }
nicholas@103 7251 }
nicholas@103 7252
nicholas@103 7253 return this;
nicholas@103 7254 },
nicholas@103 7255
nicholas@103 7256 toggleClass: function( value, stateVal ) {
nicholas@103 7257 var type = typeof value;
nicholas@103 7258
nicholas@103 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nicholas@103 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nicholas@103 7261 }
nicholas@103 7262
nicholas@103 7263 if ( jQuery.isFunction( value ) ) {
nicholas@103 7264 return this.each(function( i ) {
nicholas@103 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nicholas@103 7266 });
nicholas@103 7267 }
nicholas@103 7268
nicholas@103 7269 return this.each(function() {
nicholas@103 7270 if ( type === "string" ) {
nicholas@103 7271 // Toggle individual class names
nicholas@103 7272 var className,
nicholas@103 7273 i = 0,
nicholas@103 7274 self = jQuery( this ),
nicholas@103 7275 classNames = value.match( rnotwhite ) || [];
nicholas@103 7276
nicholas@103 7277 while ( (className = classNames[ i++ ]) ) {
nicholas@103 7278 // Check each className given, space separated list
nicholas@103 7279 if ( self.hasClass( className ) ) {
nicholas@103 7280 self.removeClass( className );
nicholas@103 7281 } else {
nicholas@103 7282 self.addClass( className );
nicholas@103 7283 }
nicholas@103 7284 }
nicholas@103 7285
nicholas@103 7286 // Toggle whole class name
nicholas@103 7287 } else if ( type === strundefined || type === "boolean" ) {
nicholas@103 7288 if ( this.className ) {
nicholas@103 7289 // store className if set
nicholas@103 7290 data_priv.set( this, "__className__", this.className );
nicholas@103 7291 }
nicholas@103 7292
nicholas@103 7293 // If the element has a class name or if we're passed `false`,
nicholas@103 7294 // then remove the whole classname (if there was one, the above saved it).
nicholas@103 7295 // Otherwise bring back whatever was previously saved (if anything),
nicholas@103 7296 // falling back to the empty string if nothing was stored.
nicholas@103 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nicholas@103 7298 }
nicholas@103 7299 });
nicholas@103 7300 },
nicholas@103 7301
nicholas@103 7302 hasClass: function( selector ) {
nicholas@103 7303 var className = " " + selector + " ",
nicholas@103 7304 i = 0,
nicholas@103 7305 l = this.length;
nicholas@103 7306 for ( ; i < l; i++ ) {
nicholas@103 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nicholas@103 7308 return true;
nicholas@103 7309 }
nicholas@103 7310 }
nicholas@103 7311
nicholas@103 7312 return false;
nicholas@103 7313 }
nicholas@103 7314 });
nicholas@103 7315
nicholas@103 7316
nicholas@103 7317
nicholas@103 7318
nicholas@103 7319 var rreturn = /\r/g;
nicholas@103 7320
nicholas@103 7321 jQuery.fn.extend({
nicholas@103 7322 val: function( value ) {
nicholas@103 7323 var hooks, ret, isFunction,
nicholas@103 7324 elem = this[0];
nicholas@103 7325
nicholas@103 7326 if ( !arguments.length ) {
nicholas@103 7327 if ( elem ) {
nicholas@103 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nicholas@103 7329
nicholas@103 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nicholas@103 7331 return ret;
nicholas@103 7332 }
nicholas@103 7333
nicholas@103 7334 ret = elem.value;
nicholas@103 7335
nicholas@103 7336 return typeof ret === "string" ?
nicholas@103 7337 // Handle most common string cases
nicholas@103 7338 ret.replace(rreturn, "") :
nicholas@103 7339 // Handle cases where value is null/undef or number
nicholas@103 7340 ret == null ? "" : ret;
nicholas@103 7341 }
nicholas@103 7342
nicholas@103 7343 return;
nicholas@103 7344 }
nicholas@103 7345
nicholas@103 7346 isFunction = jQuery.isFunction( value );
nicholas@103 7347
nicholas@103 7348 return this.each(function( i ) {
nicholas@103 7349 var val;
nicholas@103 7350
nicholas@103 7351 if ( this.nodeType !== 1 ) {
nicholas@103 7352 return;
nicholas@103 7353 }
nicholas@103 7354
nicholas@103 7355 if ( isFunction ) {
nicholas@103 7356 val = value.call( this, i, jQuery( this ).val() );
nicholas@103 7357 } else {
nicholas@103 7358 val = value;
nicholas@103 7359 }
nicholas@103 7360
nicholas@103 7361 // Treat null/undefined as ""; convert numbers to string
nicholas@103 7362 if ( val == null ) {
nicholas@103 7363 val = "";
nicholas@103 7364
nicholas@103 7365 } else if ( typeof val === "number" ) {
nicholas@103 7366 val += "";
nicholas@103 7367
nicholas@103 7368 } else if ( jQuery.isArray( val ) ) {
nicholas@103 7369 val = jQuery.map( val, function( value ) {
nicholas@103 7370 return value == null ? "" : value + "";
nicholas@103 7371 });
nicholas@103 7372 }
nicholas@103 7373
nicholas@103 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nicholas@103 7375
nicholas@103 7376 // If set returns undefined, fall back to normal setting
nicholas@103 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nicholas@103 7378 this.value = val;
nicholas@103 7379 }
nicholas@103 7380 });
nicholas@103 7381 }
nicholas@103 7382 });
nicholas@103 7383
nicholas@103 7384 jQuery.extend({
nicholas@103 7385 valHooks: {
nicholas@103 7386 option: {
nicholas@103 7387 get: function( elem ) {
nicholas@103 7388 var val = jQuery.find.attr( elem, "value" );
nicholas@103 7389 return val != null ?
nicholas@103 7390 val :
nicholas@103 7391 // Support: IE10-11+
nicholas@103 7392 // option.text throws exceptions (#14686, #14858)
nicholas@103 7393 jQuery.trim( jQuery.text( elem ) );
nicholas@103 7394 }
nicholas@103 7395 },
nicholas@103 7396 select: {
nicholas@103 7397 get: function( elem ) {
nicholas@103 7398 var value, option,
nicholas@103 7399 options = elem.options,
nicholas@103 7400 index = elem.selectedIndex,
nicholas@103 7401 one = elem.type === "select-one" || index < 0,
nicholas@103 7402 values = one ? null : [],
nicholas@103 7403 max = one ? index + 1 : options.length,
nicholas@103 7404 i = index < 0 ?
nicholas@103 7405 max :
nicholas@103 7406 one ? index : 0;
nicholas@103 7407
nicholas@103 7408 // Loop through all the selected options
nicholas@103 7409 for ( ; i < max; i++ ) {
nicholas@103 7410 option = options[ i ];
nicholas@103 7411
nicholas@103 7412 // IE6-9 doesn't update selected after form reset (#2551)
nicholas@103 7413 if ( ( option.selected || i === index ) &&
nicholas@103 7414 // Don't return options that are disabled or in a disabled optgroup
nicholas@103 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nicholas@103 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nicholas@103 7417
nicholas@103 7418 // Get the specific value for the option
nicholas@103 7419 value = jQuery( option ).val();
nicholas@103 7420
nicholas@103 7421 // We don't need an array for one selects
nicholas@103 7422 if ( one ) {
nicholas@103 7423 return value;
nicholas@103 7424 }
nicholas@103 7425
nicholas@103 7426 // Multi-Selects return an array
nicholas@103 7427 values.push( value );
nicholas@103 7428 }
nicholas@103 7429 }
nicholas@103 7430
nicholas@103 7431 return values;
nicholas@103 7432 },
nicholas@103 7433
nicholas@103 7434 set: function( elem, value ) {
nicholas@103 7435 var optionSet, option,
nicholas@103 7436 options = elem.options,
nicholas@103 7437 values = jQuery.makeArray( value ),
nicholas@103 7438 i = options.length;
nicholas@103 7439
nicholas@103 7440 while ( i-- ) {
nicholas@103 7441 option = options[ i ];
nicholas@103 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nicholas@103 7443 optionSet = true;
nicholas@103 7444 }
nicholas@103 7445 }
nicholas@103 7446
nicholas@103 7447 // Force browsers to behave consistently when non-matching value is set
nicholas@103 7448 if ( !optionSet ) {
nicholas@103 7449 elem.selectedIndex = -1;
nicholas@103 7450 }
nicholas@103 7451 return values;
nicholas@103 7452 }
nicholas@103 7453 }
nicholas@103 7454 }
nicholas@103 7455 });
nicholas@103 7456
nicholas@103 7457 // Radios and checkboxes getter/setter
nicholas@103 7458 jQuery.each([ "radio", "checkbox" ], function() {
nicholas@103 7459 jQuery.valHooks[ this ] = {
nicholas@103 7460 set: function( elem, value ) {
nicholas@103 7461 if ( jQuery.isArray( value ) ) {
nicholas@103 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nicholas@103 7463 }
nicholas@103 7464 }
nicholas@103 7465 };
nicholas@103 7466 if ( !support.checkOn ) {
nicholas@103 7467 jQuery.valHooks[ this ].get = function( elem ) {
nicholas@103 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nicholas@103 7469 };
nicholas@103 7470 }
nicholas@103 7471 });
nicholas@103 7472
nicholas@103 7473
nicholas@103 7474
nicholas@103 7475
nicholas@103 7476 // Return jQuery for attributes-only inclusion
nicholas@103 7477
nicholas@103 7478
nicholas@103 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nicholas@103 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nicholas@103 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nicholas@103 7482
nicholas@103 7483 // Handle event binding
nicholas@103 7484 jQuery.fn[ name ] = function( data, fn ) {
nicholas@103 7485 return arguments.length > 0 ?
nicholas@103 7486 this.on( name, null, data, fn ) :
nicholas@103 7487 this.trigger( name );
nicholas@103 7488 };
nicholas@103 7489 });
nicholas@103 7490
nicholas@103 7491 jQuery.fn.extend({
nicholas@103 7492 hover: function( fnOver, fnOut ) {
nicholas@103 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nicholas@103 7494 },
nicholas@103 7495
nicholas@103 7496 bind: function( types, data, fn ) {
nicholas@103 7497 return this.on( types, null, data, fn );
nicholas@103 7498 },
nicholas@103 7499 unbind: function( types, fn ) {
nicholas@103 7500 return this.off( types, null, fn );
nicholas@103 7501 },
nicholas@103 7502
nicholas@103 7503 delegate: function( selector, types, data, fn ) {
nicholas@103 7504 return this.on( types, selector, data, fn );
nicholas@103 7505 },
nicholas@103 7506 undelegate: function( selector, types, fn ) {
nicholas@103 7507 // ( namespace ) or ( selector, types [, fn] )
nicholas@103 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nicholas@103 7509 }
nicholas@103 7510 });
nicholas@103 7511
nicholas@103 7512
nicholas@103 7513 var nonce = jQuery.now();
nicholas@103 7514
nicholas@103 7515 var rquery = (/\?/);
nicholas@103 7516
nicholas@103 7517
nicholas@103 7518
nicholas@103 7519 // Support: Android 2.3
nicholas@103 7520 // Workaround failure to string-cast null input
nicholas@103 7521 jQuery.parseJSON = function( data ) {
nicholas@103 7522 return JSON.parse( data + "" );
nicholas@103 7523 };
nicholas@103 7524
nicholas@103 7525
nicholas@103 7526 // Cross-browser xml parsing
nicholas@103 7527 jQuery.parseXML = function( data ) {
nicholas@103 7528 var xml, tmp;
nicholas@103 7529 if ( !data || typeof data !== "string" ) {
nicholas@103 7530 return null;
nicholas@103 7531 }
nicholas@103 7532
nicholas@103 7533 // Support: IE9
nicholas@103 7534 try {
nicholas@103 7535 tmp = new DOMParser();
nicholas@103 7536 xml = tmp.parseFromString( data, "text/xml" );
nicholas@103 7537 } catch ( e ) {
nicholas@103 7538 xml = undefined;
nicholas@103 7539 }
nicholas@103 7540
nicholas@103 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nicholas@103 7542 jQuery.error( "Invalid XML: " + data );
nicholas@103 7543 }
nicholas@103 7544 return xml;
nicholas@103 7545 };
nicholas@103 7546
nicholas@103 7547
nicholas@103 7548 var
nicholas@103 7549 rhash = /#.*$/,
nicholas@103 7550 rts = /([?&])_=[^&]*/,
nicholas@103 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nicholas@103 7552 // #7653, #8125, #8152: local protocol detection
nicholas@103 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nicholas@103 7554 rnoContent = /^(?:GET|HEAD)$/,
nicholas@103 7555 rprotocol = /^\/\//,
nicholas@103 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nicholas@103 7557
nicholas@103 7558 /* Prefilters
nicholas@103 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nicholas@103 7560 * 2) These are called:
nicholas@103 7561 * - BEFORE asking for a transport
nicholas@103 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nicholas@103 7563 * 3) key is the dataType
nicholas@103 7564 * 4) the catchall symbol "*" can be used
nicholas@103 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nicholas@103 7566 */
nicholas@103 7567 prefilters = {},
nicholas@103 7568
nicholas@103 7569 /* Transports bindings
nicholas@103 7570 * 1) key is the dataType
nicholas@103 7571 * 2) the catchall symbol "*" can be used
nicholas@103 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nicholas@103 7573 */
nicholas@103 7574 transports = {},
nicholas@103 7575
nicholas@103 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nicholas@103 7577 allTypes = "*/".concat( "*" ),
nicholas@103 7578
nicholas@103 7579 // Document location
nicholas@103 7580 ajaxLocation = window.location.href,
nicholas@103 7581
nicholas@103 7582 // Segment location into parts
nicholas@103 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nicholas@103 7584
nicholas@103 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nicholas@103 7586 function addToPrefiltersOrTransports( structure ) {
nicholas@103 7587
nicholas@103 7588 // dataTypeExpression is optional and defaults to "*"
nicholas@103 7589 return function( dataTypeExpression, func ) {
nicholas@103 7590
nicholas@103 7591 if ( typeof dataTypeExpression !== "string" ) {
nicholas@103 7592 func = dataTypeExpression;
nicholas@103 7593 dataTypeExpression = "*";
nicholas@103 7594 }
nicholas@103 7595
nicholas@103 7596 var dataType,
nicholas@103 7597 i = 0,
nicholas@103 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nicholas@103 7599
nicholas@103 7600 if ( jQuery.isFunction( func ) ) {
nicholas@103 7601 // For each dataType in the dataTypeExpression
nicholas@103 7602 while ( (dataType = dataTypes[i++]) ) {
nicholas@103 7603 // Prepend if requested
nicholas@103 7604 if ( dataType[0] === "+" ) {
nicholas@103 7605 dataType = dataType.slice( 1 ) || "*";
nicholas@103 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nicholas@103 7607
nicholas@103 7608 // Otherwise append
nicholas@103 7609 } else {
nicholas@103 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nicholas@103 7611 }
nicholas@103 7612 }
nicholas@103 7613 }
nicholas@103 7614 };
nicholas@103 7615 }
nicholas@103 7616
nicholas@103 7617 // Base inspection function for prefilters and transports
nicholas@103 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nicholas@103 7619
nicholas@103 7620 var inspected = {},
nicholas@103 7621 seekingTransport = ( structure === transports );
nicholas@103 7622
nicholas@103 7623 function inspect( dataType ) {
nicholas@103 7624 var selected;
nicholas@103 7625 inspected[ dataType ] = true;
nicholas@103 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nicholas@103 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nicholas@103 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nicholas@103 7629 options.dataTypes.unshift( dataTypeOrTransport );
nicholas@103 7630 inspect( dataTypeOrTransport );
nicholas@103 7631 return false;
nicholas@103 7632 } else if ( seekingTransport ) {
nicholas@103 7633 return !( selected = dataTypeOrTransport );
nicholas@103 7634 }
nicholas@103 7635 });
nicholas@103 7636 return selected;
nicholas@103 7637 }
nicholas@103 7638
nicholas@103 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nicholas@103 7640 }
nicholas@103 7641
nicholas@103 7642 // A special extend for ajax options
nicholas@103 7643 // that takes "flat" options (not to be deep extended)
nicholas@103 7644 // Fixes #9887
nicholas@103 7645 function ajaxExtend( target, src ) {
nicholas@103 7646 var key, deep,
nicholas@103 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nicholas@103 7648
nicholas@103 7649 for ( key in src ) {
nicholas@103 7650 if ( src[ key ] !== undefined ) {
nicholas@103 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nicholas@103 7652 }
nicholas@103 7653 }
nicholas@103 7654 if ( deep ) {
nicholas@103 7655 jQuery.extend( true, target, deep );
nicholas@103 7656 }
nicholas@103 7657
nicholas@103 7658 return target;
nicholas@103 7659 }
nicholas@103 7660
nicholas@103 7661 /* Handles responses to an ajax request:
nicholas@103 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nicholas@103 7663 * - returns the corresponding response
nicholas@103 7664 */
nicholas@103 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nicholas@103 7666
nicholas@103 7667 var ct, type, finalDataType, firstDataType,
nicholas@103 7668 contents = s.contents,
nicholas@103 7669 dataTypes = s.dataTypes;
nicholas@103 7670
nicholas@103 7671 // Remove auto dataType and get content-type in the process
nicholas@103 7672 while ( dataTypes[ 0 ] === "*" ) {
nicholas@103 7673 dataTypes.shift();
nicholas@103 7674 if ( ct === undefined ) {
nicholas@103 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nicholas@103 7676 }
nicholas@103 7677 }
nicholas@103 7678
nicholas@103 7679 // Check if we're dealing with a known content-type
nicholas@103 7680 if ( ct ) {
nicholas@103 7681 for ( type in contents ) {
nicholas@103 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nicholas@103 7683 dataTypes.unshift( type );
nicholas@103 7684 break;
nicholas@103 7685 }
nicholas@103 7686 }
nicholas@103 7687 }
nicholas@103 7688
nicholas@103 7689 // Check to see if we have a response for the expected dataType
nicholas@103 7690 if ( dataTypes[ 0 ] in responses ) {
nicholas@103 7691 finalDataType = dataTypes[ 0 ];
nicholas@103 7692 } else {
nicholas@103 7693 // Try convertible dataTypes
nicholas@103 7694 for ( type in responses ) {
nicholas@103 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nicholas@103 7696 finalDataType = type;
nicholas@103 7697 break;
nicholas@103 7698 }
nicholas@103 7699 if ( !firstDataType ) {
nicholas@103 7700 firstDataType = type;
nicholas@103 7701 }
nicholas@103 7702 }
nicholas@103 7703 // Or just use first one
nicholas@103 7704 finalDataType = finalDataType || firstDataType;
nicholas@103 7705 }
nicholas@103 7706
nicholas@103 7707 // If we found a dataType
nicholas@103 7708 // We add the dataType to the list if needed
nicholas@103 7709 // and return the corresponding response
nicholas@103 7710 if ( finalDataType ) {
nicholas@103 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nicholas@103 7712 dataTypes.unshift( finalDataType );
nicholas@103 7713 }
nicholas@103 7714 return responses[ finalDataType ];
nicholas@103 7715 }
nicholas@103 7716 }
nicholas@103 7717
nicholas@103 7718 /* Chain conversions given the request and the original response
nicholas@103 7719 * Also sets the responseXXX fields on the jqXHR instance
nicholas@103 7720 */
nicholas@103 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nicholas@103 7722 var conv2, current, conv, tmp, prev,
nicholas@103 7723 converters = {},
nicholas@103 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nicholas@103 7725 dataTypes = s.dataTypes.slice();
nicholas@103 7726
nicholas@103 7727 // Create converters map with lowercased keys
nicholas@103 7728 if ( dataTypes[ 1 ] ) {
nicholas@103 7729 for ( conv in s.converters ) {
nicholas@103 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nicholas@103 7731 }
nicholas@103 7732 }
nicholas@103 7733
nicholas@103 7734 current = dataTypes.shift();
nicholas@103 7735
nicholas@103 7736 // Convert to each sequential dataType
nicholas@103 7737 while ( current ) {
nicholas@103 7738
nicholas@103 7739 if ( s.responseFields[ current ] ) {
nicholas@103 7740 jqXHR[ s.responseFields[ current ] ] = response;
nicholas@103 7741 }
nicholas@103 7742
nicholas@103 7743 // Apply the dataFilter if provided
nicholas@103 7744 if ( !prev && isSuccess && s.dataFilter ) {
nicholas@103 7745 response = s.dataFilter( response, s.dataType );
nicholas@103 7746 }
nicholas@103 7747
nicholas@103 7748 prev = current;
nicholas@103 7749 current = dataTypes.shift();
nicholas@103 7750
nicholas@103 7751 if ( current ) {
nicholas@103 7752
nicholas@103 7753 // There's only work to do if current dataType is non-auto
nicholas@103 7754 if ( current === "*" ) {
nicholas@103 7755
nicholas@103 7756 current = prev;
nicholas@103 7757
nicholas@103 7758 // Convert response if prev dataType is non-auto and differs from current
nicholas@103 7759 } else if ( prev !== "*" && prev !== current ) {
nicholas@103 7760
nicholas@103 7761 // Seek a direct converter
nicholas@103 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nicholas@103 7763
nicholas@103 7764 // If none found, seek a pair
nicholas@103 7765 if ( !conv ) {
nicholas@103 7766 for ( conv2 in converters ) {
nicholas@103 7767
nicholas@103 7768 // If conv2 outputs current
nicholas@103 7769 tmp = conv2.split( " " );
nicholas@103 7770 if ( tmp[ 1 ] === current ) {
nicholas@103 7771
nicholas@103 7772 // If prev can be converted to accepted input
nicholas@103 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nicholas@103 7774 converters[ "* " + tmp[ 0 ] ];
nicholas@103 7775 if ( conv ) {
nicholas@103 7776 // Condense equivalence converters
nicholas@103 7777 if ( conv === true ) {
nicholas@103 7778 conv = converters[ conv2 ];
nicholas@103 7779
nicholas@103 7780 // Otherwise, insert the intermediate dataType
nicholas@103 7781 } else if ( converters[ conv2 ] !== true ) {
nicholas@103 7782 current = tmp[ 0 ];
nicholas@103 7783 dataTypes.unshift( tmp[ 1 ] );
nicholas@103 7784 }
nicholas@103 7785 break;
nicholas@103 7786 }
nicholas@103 7787 }
nicholas@103 7788 }
nicholas@103 7789 }
nicholas@103 7790
nicholas@103 7791 // Apply converter (if not an equivalence)
nicholas@103 7792 if ( conv !== true ) {
nicholas@103 7793
nicholas@103 7794 // Unless errors are allowed to bubble, catch and return them
nicholas@103 7795 if ( conv && s[ "throws" ] ) {
nicholas@103 7796 response = conv( response );
nicholas@103 7797 } else {
nicholas@103 7798 try {
nicholas@103 7799 response = conv( response );
nicholas@103 7800 } catch ( e ) {
nicholas@103 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nicholas@103 7802 }
nicholas@103 7803 }
nicholas@103 7804 }
nicholas@103 7805 }
nicholas@103 7806 }
nicholas@103 7807 }
nicholas@103 7808
nicholas@103 7809 return { state: "success", data: response };
nicholas@103 7810 }
nicholas@103 7811
nicholas@103 7812 jQuery.extend({
nicholas@103 7813
nicholas@103 7814 // Counter for holding the number of active queries
nicholas@103 7815 active: 0,
nicholas@103 7816
nicholas@103 7817 // Last-Modified header cache for next request
nicholas@103 7818 lastModified: {},
nicholas@103 7819 etag: {},
nicholas@103 7820
nicholas@103 7821 ajaxSettings: {
nicholas@103 7822 url: ajaxLocation,
nicholas@103 7823 type: "GET",
nicholas@103 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nicholas@103 7825 global: true,
nicholas@103 7826 processData: true,
nicholas@103 7827 async: true,
nicholas@103 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nicholas@103 7829 /*
nicholas@103 7830 timeout: 0,
nicholas@103 7831 data: null,
nicholas@103 7832 dataType: null,
nicholas@103 7833 username: null,
nicholas@103 7834 password: null,
nicholas@103 7835 cache: null,
nicholas@103 7836 throws: false,
nicholas@103 7837 traditional: false,
nicholas@103 7838 headers: {},
nicholas@103 7839 */
nicholas@103 7840
nicholas@103 7841 accepts: {
nicholas@103 7842 "*": allTypes,
nicholas@103 7843 text: "text/plain",
nicholas@103 7844 html: "text/html",
nicholas@103 7845 xml: "application/xml, text/xml",
nicholas@103 7846 json: "application/json, text/javascript"
nicholas@103 7847 },
nicholas@103 7848
nicholas@103 7849 contents: {
nicholas@103 7850 xml: /xml/,
nicholas@103 7851 html: /html/,
nicholas@103 7852 json: /json/
nicholas@103 7853 },
nicholas@103 7854
nicholas@103 7855 responseFields: {
nicholas@103 7856 xml: "responseXML",
nicholas@103 7857 text: "responseText",
nicholas@103 7858 json: "responseJSON"
nicholas@103 7859 },
nicholas@103 7860
nicholas@103 7861 // Data converters
nicholas@103 7862 // Keys separate source (or catchall "*") and destination types with a single space
nicholas@103 7863 converters: {
nicholas@103 7864
nicholas@103 7865 // Convert anything to text
nicholas@103 7866 "* text": String,
nicholas@103 7867
nicholas@103 7868 // Text to html (true = no transformation)
nicholas@103 7869 "text html": true,
nicholas@103 7870
nicholas@103 7871 // Evaluate text as a json expression
nicholas@103 7872 "text json": jQuery.parseJSON,
nicholas@103 7873
nicholas@103 7874 // Parse text as xml
nicholas@103 7875 "text xml": jQuery.parseXML
nicholas@103 7876 },
nicholas@103 7877
nicholas@103 7878 // For options that shouldn't be deep extended:
nicholas@103 7879 // you can add your own custom options here if
nicholas@103 7880 // and when you create one that shouldn't be
nicholas@103 7881 // deep extended (see ajaxExtend)
nicholas@103 7882 flatOptions: {
nicholas@103 7883 url: true,
nicholas@103 7884 context: true
nicholas@103 7885 }
nicholas@103 7886 },
nicholas@103 7887
nicholas@103 7888 // Creates a full fledged settings object into target
nicholas@103 7889 // with both ajaxSettings and settings fields.
nicholas@103 7890 // If target is omitted, writes into ajaxSettings.
nicholas@103 7891 ajaxSetup: function( target, settings ) {
nicholas@103 7892 return settings ?
nicholas@103 7893
nicholas@103 7894 // Building a settings object
nicholas@103 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nicholas@103 7896
nicholas@103 7897 // Extending ajaxSettings
nicholas@103 7898 ajaxExtend( jQuery.ajaxSettings, target );
nicholas@103 7899 },
nicholas@103 7900
nicholas@103 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nicholas@103 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nicholas@103 7903
nicholas@103 7904 // Main method
nicholas@103 7905 ajax: function( url, options ) {
nicholas@103 7906
nicholas@103 7907 // If url is an object, simulate pre-1.5 signature
nicholas@103 7908 if ( typeof url === "object" ) {
nicholas@103 7909 options = url;
nicholas@103 7910 url = undefined;
nicholas@103 7911 }
nicholas@103 7912
nicholas@103 7913 // Force options to be an object
nicholas@103 7914 options = options || {};
nicholas@103 7915
nicholas@103 7916 var transport,
nicholas@103 7917 // URL without anti-cache param
nicholas@103 7918 cacheURL,
nicholas@103 7919 // Response headers
nicholas@103 7920 responseHeadersString,
nicholas@103 7921 responseHeaders,
nicholas@103 7922 // timeout handle
nicholas@103 7923 timeoutTimer,
nicholas@103 7924 // Cross-domain detection vars
nicholas@103 7925 parts,
nicholas@103 7926 // To know if global events are to be dispatched
nicholas@103 7927 fireGlobals,
nicholas@103 7928 // Loop variable
nicholas@103 7929 i,
nicholas@103 7930 // Create the final options object
nicholas@103 7931 s = jQuery.ajaxSetup( {}, options ),
nicholas@103 7932 // Callbacks context
nicholas@103 7933 callbackContext = s.context || s,
nicholas@103 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nicholas@103 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nicholas@103 7936 jQuery( callbackContext ) :
nicholas@103 7937 jQuery.event,
nicholas@103 7938 // Deferreds
nicholas@103 7939 deferred = jQuery.Deferred(),
nicholas@103 7940 completeDeferred = jQuery.Callbacks("once memory"),
nicholas@103 7941 // Status-dependent callbacks
nicholas@103 7942 statusCode = s.statusCode || {},
nicholas@103 7943 // Headers (they are sent all at once)
nicholas@103 7944 requestHeaders = {},
nicholas@103 7945 requestHeadersNames = {},
nicholas@103 7946 // The jqXHR state
nicholas@103 7947 state = 0,
nicholas@103 7948 // Default abort message
nicholas@103 7949 strAbort = "canceled",
nicholas@103 7950 // Fake xhr
nicholas@103 7951 jqXHR = {
nicholas@103 7952 readyState: 0,
nicholas@103 7953
nicholas@103 7954 // Builds headers hashtable if needed
nicholas@103 7955 getResponseHeader: function( key ) {
nicholas@103 7956 var match;
nicholas@103 7957 if ( state === 2 ) {
nicholas@103 7958 if ( !responseHeaders ) {
nicholas@103 7959 responseHeaders = {};
nicholas@103 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nicholas@103 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nicholas@103 7962 }
nicholas@103 7963 }
nicholas@103 7964 match = responseHeaders[ key.toLowerCase() ];
nicholas@103 7965 }
nicholas@103 7966 return match == null ? null : match;
nicholas@103 7967 },
nicholas@103 7968
nicholas@103 7969 // Raw string
nicholas@103 7970 getAllResponseHeaders: function() {
nicholas@103 7971 return state === 2 ? responseHeadersString : null;
nicholas@103 7972 },
nicholas@103 7973
nicholas@103 7974 // Caches the header
nicholas@103 7975 setRequestHeader: function( name, value ) {
nicholas@103 7976 var lname = name.toLowerCase();
nicholas@103 7977 if ( !state ) {
nicholas@103 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nicholas@103 7979 requestHeaders[ name ] = value;
nicholas@103 7980 }
nicholas@103 7981 return this;
nicholas@103 7982 },
nicholas@103 7983
nicholas@103 7984 // Overrides response content-type header
nicholas@103 7985 overrideMimeType: function( type ) {
nicholas@103 7986 if ( !state ) {
nicholas@103 7987 s.mimeType = type;
nicholas@103 7988 }
nicholas@103 7989 return this;
nicholas@103 7990 },
nicholas@103 7991
nicholas@103 7992 // Status-dependent callbacks
nicholas@103 7993 statusCode: function( map ) {
nicholas@103 7994 var code;
nicholas@103 7995 if ( map ) {
nicholas@103 7996 if ( state < 2 ) {
nicholas@103 7997 for ( code in map ) {
nicholas@103 7998 // Lazy-add the new callback in a way that preserves old ones
nicholas@103 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nicholas@103 8000 }
nicholas@103 8001 } else {
nicholas@103 8002 // Execute the appropriate callbacks
nicholas@103 8003 jqXHR.always( map[ jqXHR.status ] );
nicholas@103 8004 }
nicholas@103 8005 }
nicholas@103 8006 return this;
nicholas@103 8007 },
nicholas@103 8008
nicholas@103 8009 // Cancel the request
nicholas@103 8010 abort: function( statusText ) {
nicholas@103 8011 var finalText = statusText || strAbort;
nicholas@103 8012 if ( transport ) {
nicholas@103 8013 transport.abort( finalText );
nicholas@103 8014 }
nicholas@103 8015 done( 0, finalText );
nicholas@103 8016 return this;
nicholas@103 8017 }
nicholas@103 8018 };
nicholas@103 8019
nicholas@103 8020 // Attach deferreds
nicholas@103 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nicholas@103 8022 jqXHR.success = jqXHR.done;
nicholas@103 8023 jqXHR.error = jqXHR.fail;
nicholas@103 8024
nicholas@103 8025 // Remove hash character (#7531: and string promotion)
nicholas@103 8026 // Add protocol if not provided (prefilters might expect it)
nicholas@103 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nicholas@103 8028 // We also use the url parameter if available
nicholas@103 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nicholas@103 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nicholas@103 8031
nicholas@103 8032 // Alias method option to type as per ticket #12004
nicholas@103 8033 s.type = options.method || options.type || s.method || s.type;
nicholas@103 8034
nicholas@103 8035 // Extract dataTypes list
nicholas@103 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nicholas@103 8037
nicholas@103 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nicholas@103 8039 if ( s.crossDomain == null ) {
nicholas@103 8040 parts = rurl.exec( s.url.toLowerCase() );
nicholas@103 8041 s.crossDomain = !!( parts &&
nicholas@103 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nicholas@103 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nicholas@103 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nicholas@103 8045 );
nicholas@103 8046 }
nicholas@103 8047
nicholas@103 8048 // Convert data if not already a string
nicholas@103 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nicholas@103 8050 s.data = jQuery.param( s.data, s.traditional );
nicholas@103 8051 }
nicholas@103 8052
nicholas@103 8053 // Apply prefilters
nicholas@103 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nicholas@103 8055
nicholas@103 8056 // If request was aborted inside a prefilter, stop there
nicholas@103 8057 if ( state === 2 ) {
nicholas@103 8058 return jqXHR;
nicholas@103 8059 }
nicholas@103 8060
nicholas@103 8061 // We can fire global events as of now if asked to
nicholas@103 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nicholas@103 8063 fireGlobals = jQuery.event && s.global;
nicholas@103 8064
nicholas@103 8065 // Watch for a new set of requests
nicholas@103 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nicholas@103 8067 jQuery.event.trigger("ajaxStart");
nicholas@103 8068 }
nicholas@103 8069
nicholas@103 8070 // Uppercase the type
nicholas@103 8071 s.type = s.type.toUpperCase();
nicholas@103 8072
nicholas@103 8073 // Determine if request has content
nicholas@103 8074 s.hasContent = !rnoContent.test( s.type );
nicholas@103 8075
nicholas@103 8076 // Save the URL in case we're toying with the If-Modified-Since
nicholas@103 8077 // and/or If-None-Match header later on
nicholas@103 8078 cacheURL = s.url;
nicholas@103 8079
nicholas@103 8080 // More options handling for requests with no content
nicholas@103 8081 if ( !s.hasContent ) {
nicholas@103 8082
nicholas@103 8083 // If data is available, append data to url
nicholas@103 8084 if ( s.data ) {
nicholas@103 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nicholas@103 8086 // #9682: remove data so that it's not used in an eventual retry
nicholas@103 8087 delete s.data;
nicholas@103 8088 }
nicholas@103 8089
nicholas@103 8090 // Add anti-cache in url if needed
nicholas@103 8091 if ( s.cache === false ) {
nicholas@103 8092 s.url = rts.test( cacheURL ) ?
nicholas@103 8093
nicholas@103 8094 // If there is already a '_' parameter, set its value
nicholas@103 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nicholas@103 8096
nicholas@103 8097 // Otherwise add one to the end
nicholas@103 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nicholas@103 8099 }
nicholas@103 8100 }
nicholas@103 8101
nicholas@103 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nicholas@103 8103 if ( s.ifModified ) {
nicholas@103 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nicholas@103 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nicholas@103 8106 }
nicholas@103 8107 if ( jQuery.etag[ cacheURL ] ) {
nicholas@103 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nicholas@103 8109 }
nicholas@103 8110 }
nicholas@103 8111
nicholas@103 8112 // Set the correct header, if data is being sent
nicholas@103 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nicholas@103 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nicholas@103 8115 }
nicholas@103 8116
nicholas@103 8117 // Set the Accepts header for the server, depending on the dataType
nicholas@103 8118 jqXHR.setRequestHeader(
nicholas@103 8119 "Accept",
nicholas@103 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nicholas@103 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nicholas@103 8122 s.accepts[ "*" ]
nicholas@103 8123 );
nicholas@103 8124
nicholas@103 8125 // Check for headers option
nicholas@103 8126 for ( i in s.headers ) {
nicholas@103 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nicholas@103 8128 }
nicholas@103 8129
nicholas@103 8130 // Allow custom headers/mimetypes and early abort
nicholas@103 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nicholas@103 8132 // Abort if not done already and return
nicholas@103 8133 return jqXHR.abort();
nicholas@103 8134 }
nicholas@103 8135
nicholas@103 8136 // Aborting is no longer a cancellation
nicholas@103 8137 strAbort = "abort";
nicholas@103 8138
nicholas@103 8139 // Install callbacks on deferreds
nicholas@103 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nicholas@103 8141 jqXHR[ i ]( s[ i ] );
nicholas@103 8142 }
nicholas@103 8143
nicholas@103 8144 // Get transport
nicholas@103 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nicholas@103 8146
nicholas@103 8147 // If no transport, we auto-abort
nicholas@103 8148 if ( !transport ) {
nicholas@103 8149 done( -1, "No Transport" );
nicholas@103 8150 } else {
nicholas@103 8151 jqXHR.readyState = 1;
nicholas@103 8152
nicholas@103 8153 // Send global event
nicholas@103 8154 if ( fireGlobals ) {
nicholas@103 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nicholas@103 8156 }
nicholas@103 8157 // Timeout
nicholas@103 8158 if ( s.async && s.timeout > 0 ) {
nicholas@103 8159 timeoutTimer = setTimeout(function() {
nicholas@103 8160 jqXHR.abort("timeout");
nicholas@103 8161 }, s.timeout );
nicholas@103 8162 }
nicholas@103 8163
nicholas@103 8164 try {
nicholas@103 8165 state = 1;
nicholas@103 8166 transport.send( requestHeaders, done );
nicholas@103 8167 } catch ( e ) {
nicholas@103 8168 // Propagate exception as error if not done
nicholas@103 8169 if ( state < 2 ) {
nicholas@103 8170 done( -1, e );
nicholas@103 8171 // Simply rethrow otherwise
nicholas@103 8172 } else {
nicholas@103 8173 throw e;
nicholas@103 8174 }
nicholas@103 8175 }
nicholas@103 8176 }
nicholas@103 8177
nicholas@103 8178 // Callback for when everything is done
nicholas@103 8179 function done( status, nativeStatusText, responses, headers ) {
nicholas@103 8180 var isSuccess, success, error, response, modified,
nicholas@103 8181 statusText = nativeStatusText;
nicholas@103 8182
nicholas@103 8183 // Called once
nicholas@103 8184 if ( state === 2 ) {
nicholas@103 8185 return;
nicholas@103 8186 }
nicholas@103 8187
nicholas@103 8188 // State is "done" now
nicholas@103 8189 state = 2;
nicholas@103 8190
nicholas@103 8191 // Clear timeout if it exists
nicholas@103 8192 if ( timeoutTimer ) {
nicholas@103 8193 clearTimeout( timeoutTimer );
nicholas@103 8194 }
nicholas@103 8195
nicholas@103 8196 // Dereference transport for early garbage collection
nicholas@103 8197 // (no matter how long the jqXHR object will be used)
nicholas@103 8198 transport = undefined;
nicholas@103 8199
nicholas@103 8200 // Cache response headers
nicholas@103 8201 responseHeadersString = headers || "";
nicholas@103 8202
nicholas@103 8203 // Set readyState
nicholas@103 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nicholas@103 8205
nicholas@103 8206 // Determine if successful
nicholas@103 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nicholas@103 8208
nicholas@103 8209 // Get response data
nicholas@103 8210 if ( responses ) {
nicholas@103 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nicholas@103 8212 }
nicholas@103 8213
nicholas@103 8214 // Convert no matter what (that way responseXXX fields are always set)
nicholas@103 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nicholas@103 8216
nicholas@103 8217 // If successful, handle type chaining
nicholas@103 8218 if ( isSuccess ) {
nicholas@103 8219
nicholas@103 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nicholas@103 8221 if ( s.ifModified ) {
nicholas@103 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nicholas@103 8223 if ( modified ) {
nicholas@103 8224 jQuery.lastModified[ cacheURL ] = modified;
nicholas@103 8225 }
nicholas@103 8226 modified = jqXHR.getResponseHeader("etag");
nicholas@103 8227 if ( modified ) {
nicholas@103 8228 jQuery.etag[ cacheURL ] = modified;
nicholas@103 8229 }
nicholas@103 8230 }
nicholas@103 8231
nicholas@103 8232 // if no content
nicholas@103 8233 if ( status === 204 || s.type === "HEAD" ) {
nicholas@103 8234 statusText = "nocontent";
nicholas@103 8235
nicholas@103 8236 // if not modified
nicholas@103 8237 } else if ( status === 304 ) {
nicholas@103 8238 statusText = "notmodified";
nicholas@103 8239
nicholas@103 8240 // If we have data, let's convert it
nicholas@103 8241 } else {
nicholas@103 8242 statusText = response.state;
nicholas@103 8243 success = response.data;
nicholas@103 8244 error = response.error;
nicholas@103 8245 isSuccess = !error;
nicholas@103 8246 }
nicholas@103 8247 } else {
nicholas@103 8248 // Extract error from statusText and normalize for non-aborts
nicholas@103 8249 error = statusText;
nicholas@103 8250 if ( status || !statusText ) {
nicholas@103 8251 statusText = "error";
nicholas@103 8252 if ( status < 0 ) {
nicholas@103 8253 status = 0;
nicholas@103 8254 }
nicholas@103 8255 }
nicholas@103 8256 }
nicholas@103 8257
nicholas@103 8258 // Set data for the fake xhr object
nicholas@103 8259 jqXHR.status = status;
nicholas@103 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nicholas@103 8261
nicholas@103 8262 // Success/Error
nicholas@103 8263 if ( isSuccess ) {
nicholas@103 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nicholas@103 8265 } else {
nicholas@103 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nicholas@103 8267 }
nicholas@103 8268
nicholas@103 8269 // Status-dependent callbacks
nicholas@103 8270 jqXHR.statusCode( statusCode );
nicholas@103 8271 statusCode = undefined;
nicholas@103 8272
nicholas@103 8273 if ( fireGlobals ) {
nicholas@103 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nicholas@103 8275 [ jqXHR, s, isSuccess ? success : error ] );
nicholas@103 8276 }
nicholas@103 8277
nicholas@103 8278 // Complete
nicholas@103 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nicholas@103 8280
nicholas@103 8281 if ( fireGlobals ) {
nicholas@103 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nicholas@103 8283 // Handle the global AJAX counter
nicholas@103 8284 if ( !( --jQuery.active ) ) {
nicholas@103 8285 jQuery.event.trigger("ajaxStop");
nicholas@103 8286 }
nicholas@103 8287 }
nicholas@103 8288 }
nicholas@103 8289
nicholas@103 8290 return jqXHR;
nicholas@103 8291 },
nicholas@103 8292
nicholas@103 8293 getJSON: function( url, data, callback ) {
nicholas@103 8294 return jQuery.get( url, data, callback, "json" );
nicholas@103 8295 },
nicholas@103 8296
nicholas@103 8297 getScript: function( url, callback ) {
nicholas@103 8298 return jQuery.get( url, undefined, callback, "script" );
nicholas@103 8299 }
nicholas@103 8300 });
nicholas@103 8301
nicholas@103 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nicholas@103 8303 jQuery[ method ] = function( url, data, callback, type ) {
nicholas@103 8304 // Shift arguments if data argument was omitted
nicholas@103 8305 if ( jQuery.isFunction( data ) ) {
nicholas@103 8306 type = type || callback;
nicholas@103 8307 callback = data;
nicholas@103 8308 data = undefined;
nicholas@103 8309 }
nicholas@103 8310
nicholas@103 8311 return jQuery.ajax({
nicholas@103 8312 url: url,
nicholas@103 8313 type: method,
nicholas@103 8314 dataType: type,
nicholas@103 8315 data: data,
nicholas@103 8316 success: callback
nicholas@103 8317 });
nicholas@103 8318 };
nicholas@103 8319 });
nicholas@103 8320
nicholas@103 8321
nicholas@103 8322 jQuery._evalUrl = function( url ) {
nicholas@103 8323 return jQuery.ajax({
nicholas@103 8324 url: url,
nicholas@103 8325 type: "GET",
nicholas@103 8326 dataType: "script",
nicholas@103 8327 async: false,
nicholas@103 8328 global: false,
nicholas@103 8329 "throws": true
nicholas@103 8330 });
nicholas@103 8331 };
nicholas@103 8332
nicholas@103 8333
nicholas@103 8334 jQuery.fn.extend({
nicholas@103 8335 wrapAll: function( html ) {
nicholas@103 8336 var wrap;
nicholas@103 8337
nicholas@103 8338 if ( jQuery.isFunction( html ) ) {
nicholas@103 8339 return this.each(function( i ) {
nicholas@103 8340 jQuery( this ).wrapAll( html.call(this, i) );
nicholas@103 8341 });
nicholas@103 8342 }
nicholas@103 8343
nicholas@103 8344 if ( this[ 0 ] ) {
nicholas@103 8345
nicholas@103 8346 // The elements to wrap the target around
nicholas@103 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nicholas@103 8348
nicholas@103 8349 if ( this[ 0 ].parentNode ) {
nicholas@103 8350 wrap.insertBefore( this[ 0 ] );
nicholas@103 8351 }
nicholas@103 8352
nicholas@103 8353 wrap.map(function() {
nicholas@103 8354 var elem = this;
nicholas@103 8355
nicholas@103 8356 while ( elem.firstElementChild ) {
nicholas@103 8357 elem = elem.firstElementChild;
nicholas@103 8358 }
nicholas@103 8359
nicholas@103 8360 return elem;
nicholas@103 8361 }).append( this );
nicholas@103 8362 }
nicholas@103 8363
nicholas@103 8364 return this;
nicholas@103 8365 },
nicholas@103 8366
nicholas@103 8367 wrapInner: function( html ) {
nicholas@103 8368 if ( jQuery.isFunction( html ) ) {
nicholas@103 8369 return this.each(function( i ) {
nicholas@103 8370 jQuery( this ).wrapInner( html.call(this, i) );
nicholas@103 8371 });
nicholas@103 8372 }
nicholas@103 8373
nicholas@103 8374 return this.each(function() {
nicholas@103 8375 var self = jQuery( this ),
nicholas@103 8376 contents = self.contents();
nicholas@103 8377
nicholas@103 8378 if ( contents.length ) {
nicholas@103 8379 contents.wrapAll( html );
nicholas@103 8380
nicholas@103 8381 } else {
nicholas@103 8382 self.append( html );
nicholas@103 8383 }
nicholas@103 8384 });
nicholas@103 8385 },
nicholas@103 8386
nicholas@103 8387 wrap: function( html ) {
nicholas@103 8388 var isFunction = jQuery.isFunction( html );
nicholas@103 8389
nicholas@103 8390 return this.each(function( i ) {
nicholas@103 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nicholas@103 8392 });
nicholas@103 8393 },
nicholas@103 8394
nicholas@103 8395 unwrap: function() {
nicholas@103 8396 return this.parent().each(function() {
nicholas@103 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nicholas@103 8398 jQuery( this ).replaceWith( this.childNodes );
nicholas@103 8399 }
nicholas@103 8400 }).end();
nicholas@103 8401 }
nicholas@103 8402 });
nicholas@103 8403
nicholas@103 8404
nicholas@103 8405 jQuery.expr.filters.hidden = function( elem ) {
nicholas@103 8406 // Support: Opera <= 12.12
nicholas@103 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nicholas@103 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nicholas@103 8409 };
nicholas@103 8410 jQuery.expr.filters.visible = function( elem ) {
nicholas@103 8411 return !jQuery.expr.filters.hidden( elem );
nicholas@103 8412 };
nicholas@103 8413
nicholas@103 8414
nicholas@103 8415
nicholas@103 8416
nicholas@103 8417 var r20 = /%20/g,
nicholas@103 8418 rbracket = /\[\]$/,
nicholas@103 8419 rCRLF = /\r?\n/g,
nicholas@103 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nicholas@103 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nicholas@103 8422
nicholas@103 8423 function buildParams( prefix, obj, traditional, add ) {
nicholas@103 8424 var name;
nicholas@103 8425
nicholas@103 8426 if ( jQuery.isArray( obj ) ) {
nicholas@103 8427 // Serialize array item.
nicholas@103 8428 jQuery.each( obj, function( i, v ) {
nicholas@103 8429 if ( traditional || rbracket.test( prefix ) ) {
nicholas@103 8430 // Treat each array item as a scalar.
nicholas@103 8431 add( prefix, v );
nicholas@103 8432
nicholas@103 8433 } else {
nicholas@103 8434 // Item is non-scalar (array or object), encode its numeric index.
nicholas@103 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nicholas@103 8436 }
nicholas@103 8437 });
nicholas@103 8438
nicholas@103 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nicholas@103 8440 // Serialize object item.
nicholas@103 8441 for ( name in obj ) {
nicholas@103 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nicholas@103 8443 }
nicholas@103 8444
nicholas@103 8445 } else {
nicholas@103 8446 // Serialize scalar item.
nicholas@103 8447 add( prefix, obj );
nicholas@103 8448 }
nicholas@103 8449 }
nicholas@103 8450
nicholas@103 8451 // Serialize an array of form elements or a set of
nicholas@103 8452 // key/values into a query string
nicholas@103 8453 jQuery.param = function( a, traditional ) {
nicholas@103 8454 var prefix,
nicholas@103 8455 s = [],
nicholas@103 8456 add = function( key, value ) {
nicholas@103 8457 // If value is a function, invoke it and return its value
nicholas@103 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nicholas@103 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nicholas@103 8460 };
nicholas@103 8461
nicholas@103 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nicholas@103 8463 if ( traditional === undefined ) {
nicholas@103 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nicholas@103 8465 }
nicholas@103 8466
nicholas@103 8467 // If an array was passed in, assume that it is an array of form elements.
nicholas@103 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nicholas@103 8469 // Serialize the form elements
nicholas@103 8470 jQuery.each( a, function() {
nicholas@103 8471 add( this.name, this.value );
nicholas@103 8472 });
nicholas@103 8473
nicholas@103 8474 } else {
nicholas@103 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nicholas@103 8476 // did it), otherwise encode params recursively.
nicholas@103 8477 for ( prefix in a ) {
nicholas@103 8478 buildParams( prefix, a[ prefix ], traditional, add );
nicholas@103 8479 }
nicholas@103 8480 }
nicholas@103 8481
nicholas@103 8482 // Return the resulting serialization
nicholas@103 8483 return s.join( "&" ).replace( r20, "+" );
nicholas@103 8484 };
nicholas@103 8485
nicholas@103 8486 jQuery.fn.extend({
nicholas@103 8487 serialize: function() {
nicholas@103 8488 return jQuery.param( this.serializeArray() );
nicholas@103 8489 },
nicholas@103 8490 serializeArray: function() {
nicholas@103 8491 return this.map(function() {
nicholas@103 8492 // Can add propHook for "elements" to filter or add form elements
nicholas@103 8493 var elements = jQuery.prop( this, "elements" );
nicholas@103 8494 return elements ? jQuery.makeArray( elements ) : this;
nicholas@103 8495 })
nicholas@103 8496 .filter(function() {
nicholas@103 8497 var type = this.type;
nicholas@103 8498
nicholas@103 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nicholas@103 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nicholas@103 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nicholas@103 8502 ( this.checked || !rcheckableType.test( type ) );
nicholas@103 8503 })
nicholas@103 8504 .map(function( i, elem ) {
nicholas@103 8505 var val = jQuery( this ).val();
nicholas@103 8506
nicholas@103 8507 return val == null ?
nicholas@103 8508 null :
nicholas@103 8509 jQuery.isArray( val ) ?
nicholas@103 8510 jQuery.map( val, function( val ) {
nicholas@103 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nicholas@103 8512 }) :
nicholas@103 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nicholas@103 8514 }).get();
nicholas@103 8515 }
nicholas@103 8516 });
nicholas@103 8517
nicholas@103 8518
nicholas@103 8519 jQuery.ajaxSettings.xhr = function() {
nicholas@103 8520 try {
nicholas@103 8521 return new XMLHttpRequest();
nicholas@103 8522 } catch( e ) {}
nicholas@103 8523 };
nicholas@103 8524
nicholas@103 8525 var xhrId = 0,
nicholas@103 8526 xhrCallbacks = {},
nicholas@103 8527 xhrSuccessStatus = {
nicholas@103 8528 // file protocol always yields status code 0, assume 200
nicholas@103 8529 0: 200,
nicholas@103 8530 // Support: IE9
nicholas@103 8531 // #1450: sometimes IE returns 1223 when it should be 204
nicholas@103 8532 1223: 204
nicholas@103 8533 },
nicholas@103 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nicholas@103 8535
nicholas@103 8536 // Support: IE9
nicholas@103 8537 // Open requests must be manually aborted on unload (#5280)
nicholas@103 8538 // See https://support.microsoft.com/kb/2856746 for more info
nicholas@103 8539 if ( window.attachEvent ) {
nicholas@103 8540 window.attachEvent( "onunload", function() {
nicholas@103 8541 for ( var key in xhrCallbacks ) {
nicholas@103 8542 xhrCallbacks[ key ]();
nicholas@103 8543 }
nicholas@103 8544 });
nicholas@103 8545 }
nicholas@103 8546
nicholas@103 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nicholas@103 8548 support.ajax = xhrSupported = !!xhrSupported;
nicholas@103 8549
nicholas@103 8550 jQuery.ajaxTransport(function( options ) {
nicholas@103 8551 var callback;
nicholas@103 8552
nicholas@103 8553 // Cross domain only allowed if supported through XMLHttpRequest
nicholas@103 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nicholas@103 8555 return {
nicholas@103 8556 send: function( headers, complete ) {
nicholas@103 8557 var i,
nicholas@103 8558 xhr = options.xhr(),
nicholas@103 8559 id = ++xhrId;
nicholas@103 8560
nicholas@103 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nicholas@103 8562
nicholas@103 8563 // Apply custom fields if provided
nicholas@103 8564 if ( options.xhrFields ) {
nicholas@103 8565 for ( i in options.xhrFields ) {
nicholas@103 8566 xhr[ i ] = options.xhrFields[ i ];
nicholas@103 8567 }
nicholas@103 8568 }
nicholas@103 8569
nicholas@103 8570 // Override mime type if needed
nicholas@103 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nicholas@103 8572 xhr.overrideMimeType( options.mimeType );
nicholas@103 8573 }
nicholas@103 8574
nicholas@103 8575 // X-Requested-With header
nicholas@103 8576 // For cross-domain requests, seeing as conditions for a preflight are
nicholas@103 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nicholas@103 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nicholas@103 8579 // For same-domain requests, won't change header if already provided.
nicholas@103 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nicholas@103 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nicholas@103 8582 }
nicholas@103 8583
nicholas@103 8584 // Set headers
nicholas@103 8585 for ( i in headers ) {
nicholas@103 8586 xhr.setRequestHeader( i, headers[ i ] );
nicholas@103 8587 }
nicholas@103 8588
nicholas@103 8589 // Callback
nicholas@103 8590 callback = function( type ) {
nicholas@103 8591 return function() {
nicholas@103 8592 if ( callback ) {
nicholas@103 8593 delete xhrCallbacks[ id ];
nicholas@103 8594 callback = xhr.onload = xhr.onerror = null;
nicholas@103 8595
nicholas@103 8596 if ( type === "abort" ) {
nicholas@103 8597 xhr.abort();
nicholas@103 8598 } else if ( type === "error" ) {
nicholas@103 8599 complete(
nicholas@103 8600 // file: protocol always yields status 0; see #8605, #14207
nicholas@103 8601 xhr.status,
nicholas@103 8602 xhr.statusText
nicholas@103 8603 );
nicholas@103 8604 } else {
nicholas@103 8605 complete(
nicholas@103 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nicholas@103 8607 xhr.statusText,
nicholas@103 8608 // Support: IE9
nicholas@103 8609 // Accessing binary-data responseText throws an exception
nicholas@103 8610 // (#11426)
nicholas@103 8611 typeof xhr.responseText === "string" ? {
nicholas@103 8612 text: xhr.responseText
nicholas@103 8613 } : undefined,
nicholas@103 8614 xhr.getAllResponseHeaders()
nicholas@103 8615 );
nicholas@103 8616 }
nicholas@103 8617 }
nicholas@103 8618 };
nicholas@103 8619 };
nicholas@103 8620
nicholas@103 8621 // Listen to events
nicholas@103 8622 xhr.onload = callback();
nicholas@103 8623 xhr.onerror = callback("error");
nicholas@103 8624
nicholas@103 8625 // Create the abort callback
nicholas@103 8626 callback = xhrCallbacks[ id ] = callback("abort");
nicholas@103 8627
nicholas@103 8628 try {
nicholas@103 8629 // Do send the request (this may raise an exception)
nicholas@103 8630 xhr.send( options.hasContent && options.data || null );
nicholas@103 8631 } catch ( e ) {
nicholas@103 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nicholas@103 8633 if ( callback ) {
nicholas@103 8634 throw e;
nicholas@103 8635 }
nicholas@103 8636 }
nicholas@103 8637 },
nicholas@103 8638
nicholas@103 8639 abort: function() {
nicholas@103 8640 if ( callback ) {
nicholas@103 8641 callback();
nicholas@103 8642 }
nicholas@103 8643 }
nicholas@103 8644 };
nicholas@103 8645 }
nicholas@103 8646 });
nicholas@103 8647
nicholas@103 8648
nicholas@103 8649
nicholas@103 8650
nicholas@103 8651 // Install script dataType
nicholas@103 8652 jQuery.ajaxSetup({
nicholas@103 8653 accepts: {
nicholas@103 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nicholas@103 8655 },
nicholas@103 8656 contents: {
nicholas@103 8657 script: /(?:java|ecma)script/
nicholas@103 8658 },
nicholas@103 8659 converters: {
nicholas@103 8660 "text script": function( text ) {
nicholas@103 8661 jQuery.globalEval( text );
nicholas@103 8662 return text;
nicholas@103 8663 }
nicholas@103 8664 }
nicholas@103 8665 });
nicholas@103 8666
nicholas@103 8667 // Handle cache's special case and crossDomain
nicholas@103 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nicholas@103 8669 if ( s.cache === undefined ) {
nicholas@103 8670 s.cache = false;
nicholas@103 8671 }
nicholas@103 8672 if ( s.crossDomain ) {
nicholas@103 8673 s.type = "GET";
nicholas@103 8674 }
nicholas@103 8675 });
nicholas@103 8676
nicholas@103 8677 // Bind script tag hack transport
nicholas@103 8678 jQuery.ajaxTransport( "script", function( s ) {
nicholas@103 8679 // This transport only deals with cross domain requests
nicholas@103 8680 if ( s.crossDomain ) {
nicholas@103 8681 var script, callback;
nicholas@103 8682 return {
nicholas@103 8683 send: function( _, complete ) {
nicholas@103 8684 script = jQuery("<script>").prop({
nicholas@103 8685 async: true,
nicholas@103 8686 charset: s.scriptCharset,
nicholas@103 8687 src: s.url
nicholas@103 8688 }).on(
nicholas@103 8689 "load error",
nicholas@103 8690 callback = function( evt ) {
nicholas@103 8691 script.remove();
nicholas@103 8692 callback = null;
nicholas@103 8693 if ( evt ) {
nicholas@103 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nicholas@103 8695 }
nicholas@103 8696 }
nicholas@103 8697 );
nicholas@103 8698 document.head.appendChild( script[ 0 ] );
nicholas@103 8699 },
nicholas@103 8700 abort: function() {
nicholas@103 8701 if ( callback ) {
nicholas@103 8702 callback();
nicholas@103 8703 }
nicholas@103 8704 }
nicholas@103 8705 };
nicholas@103 8706 }
nicholas@103 8707 });
nicholas@103 8708
nicholas@103 8709
nicholas@103 8710
nicholas@103 8711
nicholas@103 8712 var oldCallbacks = [],
nicholas@103 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nicholas@103 8714
nicholas@103 8715 // Default jsonp settings
nicholas@103 8716 jQuery.ajaxSetup({
nicholas@103 8717 jsonp: "callback",
nicholas@103 8718 jsonpCallback: function() {
nicholas@103 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nicholas@103 8720 this[ callback ] = true;
nicholas@103 8721 return callback;
nicholas@103 8722 }
nicholas@103 8723 });
nicholas@103 8724
nicholas@103 8725 // Detect, normalize options and install callbacks for jsonp requests
nicholas@103 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nicholas@103 8727
nicholas@103 8728 var callbackName, overwritten, responseContainer,
nicholas@103 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nicholas@103 8730 "url" :
nicholas@103 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nicholas@103 8732 );
nicholas@103 8733
nicholas@103 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nicholas@103 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nicholas@103 8736
nicholas@103 8737 // Get callback name, remembering preexisting value associated with it
nicholas@103 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nicholas@103 8739 s.jsonpCallback() :
nicholas@103 8740 s.jsonpCallback;
nicholas@103 8741
nicholas@103 8742 // Insert callback into url or form data
nicholas@103 8743 if ( jsonProp ) {
nicholas@103 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nicholas@103 8745 } else if ( s.jsonp !== false ) {
nicholas@103 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nicholas@103 8747 }
nicholas@103 8748
nicholas@103 8749 // Use data converter to retrieve json after script execution
nicholas@103 8750 s.converters["script json"] = function() {
nicholas@103 8751 if ( !responseContainer ) {
nicholas@103 8752 jQuery.error( callbackName + " was not called" );
nicholas@103 8753 }
nicholas@103 8754 return responseContainer[ 0 ];
nicholas@103 8755 };
nicholas@103 8756
nicholas@103 8757 // force json dataType
nicholas@103 8758 s.dataTypes[ 0 ] = "json";
nicholas@103 8759
nicholas@103 8760 // Install callback
nicholas@103 8761 overwritten = window[ callbackName ];
nicholas@103 8762 window[ callbackName ] = function() {
nicholas@103 8763 responseContainer = arguments;
nicholas@103 8764 };
nicholas@103 8765
nicholas@103 8766 // Clean-up function (fires after converters)
nicholas@103 8767 jqXHR.always(function() {
nicholas@103 8768 // Restore preexisting value
nicholas@103 8769 window[ callbackName ] = overwritten;
nicholas@103 8770
nicholas@103 8771 // Save back as free
nicholas@103 8772 if ( s[ callbackName ] ) {
nicholas@103 8773 // make sure that re-using the options doesn't screw things around
nicholas@103 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nicholas@103 8775
nicholas@103 8776 // save the callback name for future use
nicholas@103 8777 oldCallbacks.push( callbackName );
nicholas@103 8778 }
nicholas@103 8779
nicholas@103 8780 // Call if it was a function and we have a response
nicholas@103 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nicholas@103 8782 overwritten( responseContainer[ 0 ] );
nicholas@103 8783 }
nicholas@103 8784
nicholas@103 8785 responseContainer = overwritten = undefined;
nicholas@103 8786 });
nicholas@103 8787
nicholas@103 8788 // Delegate to script
nicholas@103 8789 return "script";
nicholas@103 8790 }
nicholas@103 8791 });
nicholas@103 8792
nicholas@103 8793
nicholas@103 8794
nicholas@103 8795
nicholas@103 8796 // data: string of html
nicholas@103 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nicholas@103 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nicholas@103 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nicholas@103 8800 if ( !data || typeof data !== "string" ) {
nicholas@103 8801 return null;
nicholas@103 8802 }
nicholas@103 8803 if ( typeof context === "boolean" ) {
nicholas@103 8804 keepScripts = context;
nicholas@103 8805 context = false;
nicholas@103 8806 }
nicholas@103 8807 context = context || document;
nicholas@103 8808
nicholas@103 8809 var parsed = rsingleTag.exec( data ),
nicholas@103 8810 scripts = !keepScripts && [];
nicholas@103 8811
nicholas@103 8812 // Single tag
nicholas@103 8813 if ( parsed ) {
nicholas@103 8814 return [ context.createElement( parsed[1] ) ];
nicholas@103 8815 }
nicholas@103 8816
nicholas@103 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nicholas@103 8818
nicholas@103 8819 if ( scripts && scripts.length ) {
nicholas@103 8820 jQuery( scripts ).remove();
nicholas@103 8821 }
nicholas@103 8822
nicholas@103 8823 return jQuery.merge( [], parsed.childNodes );
nicholas@103 8824 };
nicholas@103 8825
nicholas@103 8826
nicholas@103 8827 // Keep a copy of the old load method
nicholas@103 8828 var _load = jQuery.fn.load;
nicholas@103 8829
nicholas@103 8830 /**
nicholas@103 8831 * Load a url into a page
nicholas@103 8832 */
nicholas@103 8833 jQuery.fn.load = function( url, params, callback ) {
nicholas@103 8834 if ( typeof url !== "string" && _load ) {
nicholas@103 8835 return _load.apply( this, arguments );
nicholas@103 8836 }
nicholas@103 8837
nicholas@103 8838 var selector, type, response,
nicholas@103 8839 self = this,
nicholas@103 8840 off = url.indexOf(" ");
nicholas@103 8841
nicholas@103 8842 if ( off >= 0 ) {
nicholas@103 8843 selector = jQuery.trim( url.slice( off ) );
nicholas@103 8844 url = url.slice( 0, off );
nicholas@103 8845 }
nicholas@103 8846
nicholas@103 8847 // If it's a function
nicholas@103 8848 if ( jQuery.isFunction( params ) ) {
nicholas@103 8849
nicholas@103 8850 // We assume that it's the callback
nicholas@103 8851 callback = params;
nicholas@103 8852 params = undefined;
nicholas@103 8853
nicholas@103 8854 // Otherwise, build a param string
nicholas@103 8855 } else if ( params && typeof params === "object" ) {
nicholas@103 8856 type = "POST";
nicholas@103 8857 }
nicholas@103 8858
nicholas@103 8859 // If we have elements to modify, make the request
nicholas@103 8860 if ( self.length > 0 ) {
nicholas@103 8861 jQuery.ajax({
nicholas@103 8862 url: url,
nicholas@103 8863
nicholas@103 8864 // if "type" variable is undefined, then "GET" method will be used
nicholas@103 8865 type: type,
nicholas@103 8866 dataType: "html",
nicholas@103 8867 data: params
nicholas@103 8868 }).done(function( responseText ) {
nicholas@103 8869
nicholas@103 8870 // Save response for use in complete callback
nicholas@103 8871 response = arguments;
nicholas@103 8872
nicholas@103 8873 self.html( selector ?
nicholas@103 8874
nicholas@103 8875 // If a selector was specified, locate the right elements in a dummy div
nicholas@103 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nicholas@103 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nicholas@103 8878
nicholas@103 8879 // Otherwise use the full result
nicholas@103 8880 responseText );
nicholas@103 8881
nicholas@103 8882 }).complete( callback && function( jqXHR, status ) {
nicholas@103 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nicholas@103 8884 });
nicholas@103 8885 }
nicholas@103 8886
nicholas@103 8887 return this;
nicholas@103 8888 };
nicholas@103 8889
nicholas@103 8890
nicholas@103 8891
nicholas@103 8892
nicholas@103 8893 // Attach a bunch of functions for handling common AJAX events
nicholas@103 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nicholas@103 8895 jQuery.fn[ type ] = function( fn ) {
nicholas@103 8896 return this.on( type, fn );
nicholas@103 8897 };
nicholas@103 8898 });
nicholas@103 8899
nicholas@103 8900
nicholas@103 8901
nicholas@103 8902
nicholas@103 8903 jQuery.expr.filters.animated = function( elem ) {
nicholas@103 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nicholas@103 8905 return elem === fn.elem;
nicholas@103 8906 }).length;
nicholas@103 8907 };
nicholas@103 8908
nicholas@103 8909
nicholas@103 8910
nicholas@103 8911
nicholas@103 8912 var docElem = window.document.documentElement;
nicholas@103 8913
nicholas@103 8914 /**
nicholas@103 8915 * Gets a window from an element
nicholas@103 8916 */
nicholas@103 8917 function getWindow( elem ) {
nicholas@103 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nicholas@103 8919 }
nicholas@103 8920
nicholas@103 8921 jQuery.offset = {
nicholas@103 8922 setOffset: function( elem, options, i ) {
nicholas@103 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nicholas@103 8924 position = jQuery.css( elem, "position" ),
nicholas@103 8925 curElem = jQuery( elem ),
nicholas@103 8926 props = {};
nicholas@103 8927
nicholas@103 8928 // Set position first, in-case top/left are set even on static elem
nicholas@103 8929 if ( position === "static" ) {
nicholas@103 8930 elem.style.position = "relative";
nicholas@103 8931 }
nicholas@103 8932
nicholas@103 8933 curOffset = curElem.offset();
nicholas@103 8934 curCSSTop = jQuery.css( elem, "top" );
nicholas@103 8935 curCSSLeft = jQuery.css( elem, "left" );
nicholas@103 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nicholas@103 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nicholas@103 8938
nicholas@103 8939 // Need to be able to calculate position if either
nicholas@103 8940 // top or left is auto and position is either absolute or fixed
nicholas@103 8941 if ( calculatePosition ) {
nicholas@103 8942 curPosition = curElem.position();
nicholas@103 8943 curTop = curPosition.top;
nicholas@103 8944 curLeft = curPosition.left;
nicholas@103 8945
nicholas@103 8946 } else {
nicholas@103 8947 curTop = parseFloat( curCSSTop ) || 0;
nicholas@103 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nicholas@103 8949 }
nicholas@103 8950
nicholas@103 8951 if ( jQuery.isFunction( options ) ) {
nicholas@103 8952 options = options.call( elem, i, curOffset );
nicholas@103 8953 }
nicholas@103 8954
nicholas@103 8955 if ( options.top != null ) {
nicholas@103 8956 props.top = ( options.top - curOffset.top ) + curTop;
nicholas@103 8957 }
nicholas@103 8958 if ( options.left != null ) {
nicholas@103 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nicholas@103 8960 }
nicholas@103 8961
nicholas@103 8962 if ( "using" in options ) {
nicholas@103 8963 options.using.call( elem, props );
nicholas@103 8964
nicholas@103 8965 } else {
nicholas@103 8966 curElem.css( props );
nicholas@103 8967 }
nicholas@103 8968 }
nicholas@103 8969 };
nicholas@103 8970
nicholas@103 8971 jQuery.fn.extend({
nicholas@103 8972 offset: function( options ) {
nicholas@103 8973 if ( arguments.length ) {
nicholas@103 8974 return options === undefined ?
nicholas@103 8975 this :
nicholas@103 8976 this.each(function( i ) {
nicholas@103 8977 jQuery.offset.setOffset( this, options, i );
nicholas@103 8978 });
nicholas@103 8979 }
nicholas@103 8980
nicholas@103 8981 var docElem, win,
nicholas@103 8982 elem = this[ 0 ],
nicholas@103 8983 box = { top: 0, left: 0 },
nicholas@103 8984 doc = elem && elem.ownerDocument;
nicholas@103 8985
nicholas@103 8986 if ( !doc ) {
nicholas@103 8987 return;
nicholas@103 8988 }
nicholas@103 8989
nicholas@103 8990 docElem = doc.documentElement;
nicholas@103 8991
nicholas@103 8992 // Make sure it's not a disconnected DOM node
nicholas@103 8993 if ( !jQuery.contains( docElem, elem ) ) {
nicholas@103 8994 return box;
nicholas@103 8995 }
nicholas@103 8996
nicholas@103 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nicholas@103 8998 // If we don't have gBCR, just use 0,0 rather than error
nicholas@103 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nicholas@103 9000 box = elem.getBoundingClientRect();
nicholas@103 9001 }
nicholas@103 9002 win = getWindow( doc );
nicholas@103 9003 return {
nicholas@103 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nicholas@103 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nicholas@103 9006 };
nicholas@103 9007 },
nicholas@103 9008
nicholas@103 9009 position: function() {
nicholas@103 9010 if ( !this[ 0 ] ) {
nicholas@103 9011 return;
nicholas@103 9012 }
nicholas@103 9013
nicholas@103 9014 var offsetParent, offset,
nicholas@103 9015 elem = this[ 0 ],
nicholas@103 9016 parentOffset = { top: 0, left: 0 };
nicholas@103 9017
nicholas@103 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nicholas@103 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nicholas@103 9020 // Assume getBoundingClientRect is there when computed position is fixed
nicholas@103 9021 offset = elem.getBoundingClientRect();
nicholas@103 9022
nicholas@103 9023 } else {
nicholas@103 9024 // Get *real* offsetParent
nicholas@103 9025 offsetParent = this.offsetParent();
nicholas@103 9026
nicholas@103 9027 // Get correct offsets
nicholas@103 9028 offset = this.offset();
nicholas@103 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nicholas@103 9030 parentOffset = offsetParent.offset();
nicholas@103 9031 }
nicholas@103 9032
nicholas@103 9033 // Add offsetParent borders
nicholas@103 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nicholas@103 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nicholas@103 9036 }
nicholas@103 9037
nicholas@103 9038 // Subtract parent offsets and element margins
nicholas@103 9039 return {
nicholas@103 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nicholas@103 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nicholas@103 9042 };
nicholas@103 9043 },
nicholas@103 9044
nicholas@103 9045 offsetParent: function() {
nicholas@103 9046 return this.map(function() {
nicholas@103 9047 var offsetParent = this.offsetParent || docElem;
nicholas@103 9048
nicholas@103 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nicholas@103 9050 offsetParent = offsetParent.offsetParent;
nicholas@103 9051 }
nicholas@103 9052
nicholas@103 9053 return offsetParent || docElem;
nicholas@103 9054 });
nicholas@103 9055 }
nicholas@103 9056 });
nicholas@103 9057
nicholas@103 9058 // Create scrollLeft and scrollTop methods
nicholas@103 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nicholas@103 9060 var top = "pageYOffset" === prop;
nicholas@103 9061
nicholas@103 9062 jQuery.fn[ method ] = function( val ) {
nicholas@103 9063 return access( this, function( elem, method, val ) {
nicholas@103 9064 var win = getWindow( elem );
nicholas@103 9065
nicholas@103 9066 if ( val === undefined ) {
nicholas@103 9067 return win ? win[ prop ] : elem[ method ];
nicholas@103 9068 }
nicholas@103 9069
nicholas@103 9070 if ( win ) {
nicholas@103 9071 win.scrollTo(
nicholas@103 9072 !top ? val : window.pageXOffset,
nicholas@103 9073 top ? val : window.pageYOffset
nicholas@103 9074 );
nicholas@103 9075
nicholas@103 9076 } else {
nicholas@103 9077 elem[ method ] = val;
nicholas@103 9078 }
nicholas@103 9079 }, method, val, arguments.length, null );
nicholas@103 9080 };
nicholas@103 9081 });
nicholas@103 9082
nicholas@103 9083 // Support: Safari<7+, Chrome<37+
nicholas@103 9084 // Add the top/left cssHooks using jQuery.fn.position
nicholas@103 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nicholas@103 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nicholas@103 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nicholas@103 9088 // rather than make the css module depend on the offset module, just check for it here
nicholas@103 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nicholas@103 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nicholas@103 9091 function( elem, computed ) {
nicholas@103 9092 if ( computed ) {
nicholas@103 9093 computed = curCSS( elem, prop );
nicholas@103 9094 // If curCSS returns percentage, fallback to offset
nicholas@103 9095 return rnumnonpx.test( computed ) ?
nicholas@103 9096 jQuery( elem ).position()[ prop ] + "px" :
nicholas@103 9097 computed;
nicholas@103 9098 }
nicholas@103 9099 }
nicholas@103 9100 );
nicholas@103 9101 });
nicholas@103 9102
nicholas@103 9103
nicholas@103 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nicholas@103 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nicholas@103 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nicholas@103 9107 // Margin is only for outerHeight, outerWidth
nicholas@103 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nicholas@103 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nicholas@103 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nicholas@103 9111
nicholas@103 9112 return access( this, function( elem, type, value ) {
nicholas@103 9113 var doc;
nicholas@103 9114
nicholas@103 9115 if ( jQuery.isWindow( elem ) ) {
nicholas@103 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nicholas@103 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nicholas@103 9118 // https://github.com/jquery/jquery/pull/764
nicholas@103 9119 return elem.document.documentElement[ "client" + name ];
nicholas@103 9120 }
nicholas@103 9121
nicholas@103 9122 // Get document width or height
nicholas@103 9123 if ( elem.nodeType === 9 ) {
nicholas@103 9124 doc = elem.documentElement;
nicholas@103 9125
nicholas@103 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nicholas@103 9127 // whichever is greatest
nicholas@103 9128 return Math.max(
nicholas@103 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nicholas@103 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nicholas@103 9131 doc[ "client" + name ]
nicholas@103 9132 );
nicholas@103 9133 }
nicholas@103 9134
nicholas@103 9135 return value === undefined ?
nicholas@103 9136 // Get width or height on the element, requesting but not forcing parseFloat
nicholas@103 9137 jQuery.css( elem, type, extra ) :
nicholas@103 9138
nicholas@103 9139 // Set width or height on the element
nicholas@103 9140 jQuery.style( elem, type, value, extra );
nicholas@103 9141 }, type, chainable ? margin : undefined, chainable, null );
nicholas@103 9142 };
nicholas@103 9143 });
nicholas@103 9144 });
nicholas@103 9145
nicholas@103 9146
nicholas@103 9147 // The number of elements contained in the matched element set
nicholas@103 9148 jQuery.fn.size = function() {
nicholas@103 9149 return this.length;
nicholas@103 9150 };
nicholas@103 9151
nicholas@103 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nicholas@103 9153
nicholas@103 9154
nicholas@103 9155
nicholas@103 9156
nicholas@103 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nicholas@103 9158 // files that may use define, but not via a proper concatenation script that
nicholas@103 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nicholas@103 9160 // way to register. Lowercase jquery is used because AMD module names are
nicholas@103 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nicholas@103 9162 // file name. Do this after creating the global so that if an AMD module wants
nicholas@103 9163 // to call noConflict to hide this version of jQuery, it will work.
nicholas@103 9164
nicholas@103 9165 // Note that for maximum portability, libraries that are not jQuery should
nicholas@103 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nicholas@103 9167 // AMD loader is present. jQuery is a special case. For more information, see
nicholas@103 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nicholas@103 9169
nicholas@103 9170 if ( typeof define === "function" && define.amd ) {
nicholas@103 9171 define( "jquery", [], function() {
nicholas@103 9172 return jQuery;
nicholas@103 9173 });
nicholas@103 9174 }
nicholas@103 9175
nicholas@103 9176
nicholas@103 9177
nicholas@103 9178
nicholas@103 9179 var
nicholas@103 9180 // Map over jQuery in case of overwrite
nicholas@103 9181 _jQuery = window.jQuery,
nicholas@103 9182
nicholas@103 9183 // Map over the $ in case of overwrite
nicholas@103 9184 _$ = window.$;
nicholas@103 9185
nicholas@103 9186 jQuery.noConflict = function( deep ) {
nicholas@103 9187 if ( window.$ === jQuery ) {
nicholas@103 9188 window.$ = _$;
nicholas@103 9189 }
nicholas@103 9190
nicholas@103 9191 if ( deep && window.jQuery === jQuery ) {
nicholas@103 9192 window.jQuery = _jQuery;
nicholas@103 9193 }
nicholas@103 9194
nicholas@103 9195 return jQuery;
nicholas@103 9196 };
nicholas@103 9197
nicholas@103 9198 // Expose jQuery and $ identifiers, even in AMD
nicholas@103 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nicholas@103 9200 // and CommonJS for browser emulators (#13566)
nicholas@103 9201 if ( typeof noGlobal === strundefined ) {
nicholas@103 9202 window.jQuery = window.$ = jQuery;
nicholas@103 9203 }
nicholas@103 9204
nicholas@103 9205
nicholas@103 9206
nicholas@103 9207
nicholas@103 9208 return jQuery;
nicholas@103 9209
nicholas@103 9210 }));