annotate js/jquery-2.1.4.js @ 3141:335bc77627e0 tip

fixing discrete interface to allow labels to display
author Dave Moffat <me@davemoffat.com>
date Mon, 26 Jul 2021 12:15:24 +0100
parents 760719986df3
children
rev   line source
nicholas@2224 1 /*!
nicholas@2224 2 * jQuery JavaScript Library v2.1.4
nicholas@2224 3 * http://jquery.com/
nicholas@2224 4 *
nicholas@2224 5 * Includes Sizzle.js
nicholas@2224 6 * http://sizzlejs.com/
nicholas@2224 7 *
nicholas@2224 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nicholas@2224 9 * Released under the MIT license
nicholas@2224 10 * http://jquery.org/license
nicholas@2224 11 *
nicholas@2224 12 * Date: 2015-04-28T16:01Z
nicholas@2224 13 */
nicholas@2224 14
nicholas@2224 15 (function( global, factory ) {
nicholas@2224 16
nicholas@2224 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nicholas@2224 18 // For CommonJS and CommonJS-like environments where a proper `window`
nicholas@2224 19 // is present, execute the factory and get jQuery.
nicholas@2224 20 // For environments that do not have a `window` with a `document`
nicholas@2224 21 // (such as Node.js), expose a factory as module.exports.
nicholas@2224 22 // This accentuates the need for the creation of a real `window`.
nicholas@2224 23 // e.g. var jQuery = require("jquery")(window);
nicholas@2224 24 // See ticket #14549 for more info.
nicholas@2224 25 module.exports = global.document ?
nicholas@2224 26 factory( global, true ) :
nicholas@2224 27 function( w ) {
nicholas@2224 28 if ( !w.document ) {
nicholas@2224 29 throw new Error( "jQuery requires a window with a document" );
nicholas@2224 30 }
nicholas@2224 31 return factory( w );
nicholas@2224 32 };
nicholas@2224 33 } else {
nicholas@2224 34 factory( global );
nicholas@2224 35 }
nicholas@2224 36
nicholas@2224 37 // Pass this if window is not defined yet
nicholas@2224 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nicholas@2224 39
nicholas@2224 40 // Support: Firefox 18+
nicholas@2224 41 // Can't be in strict mode, several libs including ASP.NET trace
nicholas@2224 42 // the stack via arguments.caller.callee and Firefox dies if
nicholas@2224 43 // you try to trace through "use strict" call chains. (#13335)
nicholas@2224 44 //
nicholas@2224 45
nicholas@2224 46 var arr = [];
nicholas@2224 47
nicholas@2224 48 var slice = arr.slice;
nicholas@2224 49
nicholas@2224 50 var concat = arr.concat;
nicholas@2224 51
nicholas@2224 52 var push = arr.push;
nicholas@2224 53
nicholas@2224 54 var indexOf = arr.indexOf;
nicholas@2224 55
nicholas@2224 56 var class2type = {};
nicholas@2224 57
nicholas@2224 58 var toString = class2type.toString;
nicholas@2224 59
nicholas@2224 60 var hasOwn = class2type.hasOwnProperty;
nicholas@2224 61
nicholas@2224 62 var support = {};
nicholas@2224 63
nicholas@2224 64
nicholas@2224 65
nicholas@2224 66 var
nicholas@2224 67 // Use the correct document accordingly with window argument (sandbox)
nicholas@2224 68 document = window.document,
nicholas@2224 69
nicholas@2224 70 version = "2.1.4",
nicholas@2224 71
nicholas@2224 72 // Define a local copy of jQuery
nicholas@2224 73 jQuery = function( selector, context ) {
nicholas@2224 74 // The jQuery object is actually just the init constructor 'enhanced'
nicholas@2224 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nicholas@2224 76 return new jQuery.fn.init( selector, context );
nicholas@2224 77 },
nicholas@2224 78
nicholas@2224 79 // Support: Android<4.1
nicholas@2224 80 // Make sure we trim BOM and NBSP
nicholas@2224 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nicholas@2224 82
nicholas@2224 83 // Matches dashed string for camelizing
nicholas@2224 84 rmsPrefix = /^-ms-/,
nicholas@2224 85 rdashAlpha = /-([\da-z])/gi,
nicholas@2224 86
nicholas@2224 87 // Used by jQuery.camelCase as callback to replace()
nicholas@2224 88 fcamelCase = function( all, letter ) {
nicholas@2224 89 return letter.toUpperCase();
nicholas@2224 90 };
nicholas@2224 91
nicholas@2224 92 jQuery.fn = jQuery.prototype = {
nicholas@2224 93 // The current version of jQuery being used
nicholas@2224 94 jquery: version,
nicholas@2224 95
nicholas@2224 96 constructor: jQuery,
nicholas@2224 97
nicholas@2224 98 // Start with an empty selector
nicholas@2224 99 selector: "",
nicholas@2224 100
nicholas@2224 101 // The default length of a jQuery object is 0
nicholas@2224 102 length: 0,
nicholas@2224 103
nicholas@2224 104 toArray: function() {
nicholas@2224 105 return slice.call( this );
nicholas@2224 106 },
nicholas@2224 107
nicholas@2224 108 // Get the Nth element in the matched element set OR
nicholas@2224 109 // Get the whole matched element set as a clean array
nicholas@2224 110 get: function( num ) {
nicholas@2224 111 return num != null ?
nicholas@2224 112
nicholas@2224 113 // Return just the one element from the set
nicholas@2224 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nicholas@2224 115
nicholas@2224 116 // Return all the elements in a clean array
nicholas@2224 117 slice.call( this );
nicholas@2224 118 },
nicholas@2224 119
nicholas@2224 120 // Take an array of elements and push it onto the stack
nicholas@2224 121 // (returning the new matched element set)
nicholas@2224 122 pushStack: function( elems ) {
nicholas@2224 123
nicholas@2224 124 // Build a new jQuery matched element set
nicholas@2224 125 var ret = jQuery.merge( this.constructor(), elems );
nicholas@2224 126
nicholas@2224 127 // Add the old object onto the stack (as a reference)
nicholas@2224 128 ret.prevObject = this;
nicholas@2224 129 ret.context = this.context;
nicholas@2224 130
nicholas@2224 131 // Return the newly-formed element set
nicholas@2224 132 return ret;
nicholas@2224 133 },
nicholas@2224 134
nicholas@2224 135 // Execute a callback for every element in the matched set.
nicholas@2224 136 // (You can seed the arguments with an array of args, but this is
nicholas@2224 137 // only used internally.)
nicholas@2224 138 each: function( callback, args ) {
nicholas@2224 139 return jQuery.each( this, callback, args );
nicholas@2224 140 },
nicholas@2224 141
nicholas@2224 142 map: function( callback ) {
nicholas@2224 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nicholas@2224 144 return callback.call( elem, i, elem );
nicholas@2224 145 }));
nicholas@2224 146 },
nicholas@2224 147
nicholas@2224 148 slice: function() {
nicholas@2224 149 return this.pushStack( slice.apply( this, arguments ) );
nicholas@2224 150 },
nicholas@2224 151
nicholas@2224 152 first: function() {
nicholas@2224 153 return this.eq( 0 );
nicholas@2224 154 },
nicholas@2224 155
nicholas@2224 156 last: function() {
nicholas@2224 157 return this.eq( -1 );
nicholas@2224 158 },
nicholas@2224 159
nicholas@2224 160 eq: function( i ) {
nicholas@2224 161 var len = this.length,
nicholas@2224 162 j = +i + ( i < 0 ? len : 0 );
nicholas@2224 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nicholas@2224 164 },
nicholas@2224 165
nicholas@2224 166 end: function() {
nicholas@2224 167 return this.prevObject || this.constructor(null);
nicholas@2224 168 },
nicholas@2224 169
nicholas@2224 170 // For internal use only.
nicholas@2224 171 // Behaves like an Array's method, not like a jQuery method.
nicholas@2224 172 push: push,
nicholas@2224 173 sort: arr.sort,
nicholas@2224 174 splice: arr.splice
nicholas@2224 175 };
nicholas@2224 176
nicholas@2224 177 jQuery.extend = jQuery.fn.extend = function() {
nicholas@2224 178 var options, name, src, copy, copyIsArray, clone,
nicholas@2224 179 target = arguments[0] || {},
nicholas@2224 180 i = 1,
nicholas@2224 181 length = arguments.length,
nicholas@2224 182 deep = false;
nicholas@2224 183
nicholas@2224 184 // Handle a deep copy situation
nicholas@2224 185 if ( typeof target === "boolean" ) {
nicholas@2224 186 deep = target;
nicholas@2224 187
nicholas@2224 188 // Skip the boolean and the target
nicholas@2224 189 target = arguments[ i ] || {};
nicholas@2224 190 i++;
nicholas@2224 191 }
nicholas@2224 192
nicholas@2224 193 // Handle case when target is a string or something (possible in deep copy)
nicholas@2224 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nicholas@2224 195 target = {};
nicholas@2224 196 }
nicholas@2224 197
nicholas@2224 198 // Extend jQuery itself if only one argument is passed
nicholas@2224 199 if ( i === length ) {
nicholas@2224 200 target = this;
nicholas@2224 201 i--;
nicholas@2224 202 }
nicholas@2224 203
nicholas@2224 204 for ( ; i < length; i++ ) {
nicholas@2224 205 // Only deal with non-null/undefined values
nicholas@2224 206 if ( (options = arguments[ i ]) != null ) {
nicholas@2224 207 // Extend the base object
nicholas@2224 208 for ( name in options ) {
nicholas@2224 209 src = target[ name ];
nicholas@2224 210 copy = options[ name ];
nicholas@2224 211
nicholas@2224 212 // Prevent never-ending loop
nicholas@2224 213 if ( target === copy ) {
nicholas@2224 214 continue;
nicholas@2224 215 }
nicholas@2224 216
nicholas@2224 217 // Recurse if we're merging plain objects or arrays
nicholas@2224 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nicholas@2224 219 if ( copyIsArray ) {
nicholas@2224 220 copyIsArray = false;
nicholas@2224 221 clone = src && jQuery.isArray(src) ? src : [];
nicholas@2224 222
nicholas@2224 223 } else {
nicholas@2224 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nicholas@2224 225 }
nicholas@2224 226
nicholas@2224 227 // Never move original objects, clone them
nicholas@2224 228 target[ name ] = jQuery.extend( deep, clone, copy );
nicholas@2224 229
nicholas@2224 230 // Don't bring in undefined values
nicholas@2224 231 } else if ( copy !== undefined ) {
nicholas@2224 232 target[ name ] = copy;
nicholas@2224 233 }
nicholas@2224 234 }
nicholas@2224 235 }
nicholas@2224 236 }
nicholas@2224 237
nicholas@2224 238 // Return the modified object
nicholas@2224 239 return target;
nicholas@2224 240 };
nicholas@2224 241
nicholas@2224 242 jQuery.extend({
nicholas@2224 243 // Unique for each copy of jQuery on the page
nicholas@2224 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nicholas@2224 245
nicholas@2224 246 // Assume jQuery is ready without the ready module
nicholas@2224 247 isReady: true,
nicholas@2224 248
nicholas@2224 249 error: function( msg ) {
nicholas@2224 250 throw new Error( msg );
nicholas@2224 251 },
nicholas@2224 252
nicholas@2224 253 noop: function() {},
nicholas@2224 254
nicholas@2224 255 isFunction: function( obj ) {
nicholas@2224 256 return jQuery.type(obj) === "function";
nicholas@2224 257 },
nicholas@2224 258
nicholas@2224 259 isArray: Array.isArray,
nicholas@2224 260
nicholas@2224 261 isWindow: function( obj ) {
nicholas@2224 262 return obj != null && obj === obj.window;
nicholas@2224 263 },
nicholas@2224 264
nicholas@2224 265 isNumeric: function( obj ) {
nicholas@2224 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nicholas@2224 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nicholas@2224 268 // subtraction forces infinities to NaN
nicholas@2224 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nicholas@2224 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nicholas@2224 271 },
nicholas@2224 272
nicholas@2224 273 isPlainObject: function( obj ) {
nicholas@2224 274 // Not plain objects:
nicholas@2224 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nicholas@2224 276 // - DOM nodes
nicholas@2224 277 // - window
nicholas@2224 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nicholas@2224 279 return false;
nicholas@2224 280 }
nicholas@2224 281
nicholas@2224 282 if ( obj.constructor &&
nicholas@2224 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nicholas@2224 284 return false;
nicholas@2224 285 }
nicholas@2224 286
nicholas@2224 287 // If the function hasn't returned already, we're confident that
nicholas@2224 288 // |obj| is a plain object, created by {} or constructed with new Object
nicholas@2224 289 return true;
nicholas@2224 290 },
nicholas@2224 291
nicholas@2224 292 isEmptyObject: function( obj ) {
nicholas@2224 293 var name;
nicholas@2224 294 for ( name in obj ) {
nicholas@2224 295 return false;
nicholas@2224 296 }
nicholas@2224 297 return true;
nicholas@2224 298 },
nicholas@2224 299
nicholas@2224 300 type: function( obj ) {
nicholas@2224 301 if ( obj == null ) {
nicholas@2224 302 return obj + "";
nicholas@2224 303 }
nicholas@2224 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nicholas@2224 305 return typeof obj === "object" || typeof obj === "function" ?
nicholas@2224 306 class2type[ toString.call(obj) ] || "object" :
nicholas@2224 307 typeof obj;
nicholas@2224 308 },
nicholas@2224 309
nicholas@2224 310 // Evaluates a script in a global context
nicholas@2224 311 globalEval: function( code ) {
nicholas@2224 312 var script,
nicholas@2224 313 indirect = eval;
nicholas@2224 314
nicholas@2224 315 code = jQuery.trim( code );
nicholas@2224 316
nicholas@2224 317 if ( code ) {
nicholas@2224 318 // If the code includes a valid, prologue position
nicholas@2224 319 // strict mode pragma, execute code by injecting a
nicholas@2224 320 // script tag into the document.
nicholas@2224 321 if ( code.indexOf("use strict") === 1 ) {
nicholas@2224 322 script = document.createElement("script");
nicholas@2224 323 script.text = code;
nicholas@2224 324 document.head.appendChild( script ).parentNode.removeChild( script );
nicholas@2224 325 } else {
nicholas@2224 326 // Otherwise, avoid the DOM node creation, insertion
nicholas@2224 327 // and removal by using an indirect global eval
nicholas@2224 328 indirect( code );
nicholas@2224 329 }
nicholas@2224 330 }
nicholas@2224 331 },
nicholas@2224 332
nicholas@2224 333 // Convert dashed to camelCase; used by the css and data modules
nicholas@2224 334 // Support: IE9-11+
nicholas@2224 335 // Microsoft forgot to hump their vendor prefix (#9572)
nicholas@2224 336 camelCase: function( string ) {
nicholas@2224 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nicholas@2224 338 },
nicholas@2224 339
nicholas@2224 340 nodeName: function( elem, name ) {
nicholas@2224 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nicholas@2224 342 },
nicholas@2224 343
nicholas@2224 344 // args is for internal usage only
nicholas@2224 345 each: function( obj, callback, args ) {
nicholas@2224 346 var value,
nicholas@2224 347 i = 0,
nicholas@2224 348 length = obj.length,
nicholas@2224 349 isArray = isArraylike( obj );
nicholas@2224 350
nicholas@2224 351 if ( args ) {
nicholas@2224 352 if ( isArray ) {
nicholas@2224 353 for ( ; i < length; i++ ) {
nicholas@2224 354 value = callback.apply( obj[ i ], args );
nicholas@2224 355
nicholas@2224 356 if ( value === false ) {
nicholas@2224 357 break;
nicholas@2224 358 }
nicholas@2224 359 }
nicholas@2224 360 } else {
nicholas@2224 361 for ( i in obj ) {
nicholas@2224 362 value = callback.apply( obj[ i ], args );
nicholas@2224 363
nicholas@2224 364 if ( value === false ) {
nicholas@2224 365 break;
nicholas@2224 366 }
nicholas@2224 367 }
nicholas@2224 368 }
nicholas@2224 369
nicholas@2224 370 // A special, fast, case for the most common use of each
nicholas@2224 371 } else {
nicholas@2224 372 if ( isArray ) {
nicholas@2224 373 for ( ; i < length; i++ ) {
nicholas@2224 374 value = callback.call( obj[ i ], i, obj[ i ] );
nicholas@2224 375
nicholas@2224 376 if ( value === false ) {
nicholas@2224 377 break;
nicholas@2224 378 }
nicholas@2224 379 }
nicholas@2224 380 } else {
nicholas@2224 381 for ( i in obj ) {
nicholas@2224 382 value = callback.call( obj[ i ], i, obj[ i ] );
nicholas@2224 383
nicholas@2224 384 if ( value === false ) {
nicholas@2224 385 break;
nicholas@2224 386 }
nicholas@2224 387 }
nicholas@2224 388 }
nicholas@2224 389 }
nicholas@2224 390
nicholas@2224 391 return obj;
nicholas@2224 392 },
nicholas@2224 393
nicholas@2224 394 // Support: Android<4.1
nicholas@2224 395 trim: function( text ) {
nicholas@2224 396 return text == null ?
nicholas@2224 397 "" :
nicholas@2224 398 ( text + "" ).replace( rtrim, "" );
nicholas@2224 399 },
nicholas@2224 400
nicholas@2224 401 // results is for internal usage only
nicholas@2224 402 makeArray: function( arr, results ) {
nicholas@2224 403 var ret = results || [];
nicholas@2224 404
nicholas@2224 405 if ( arr != null ) {
nicholas@2224 406 if ( isArraylike( Object(arr) ) ) {
nicholas@2224 407 jQuery.merge( ret,
nicholas@2224 408 typeof arr === "string" ?
nicholas@2224 409 [ arr ] : arr
nicholas@2224 410 );
nicholas@2224 411 } else {
nicholas@2224 412 push.call( ret, arr );
nicholas@2224 413 }
nicholas@2224 414 }
nicholas@2224 415
nicholas@2224 416 return ret;
nicholas@2224 417 },
nicholas@2224 418
nicholas@2224 419 inArray: function( elem, arr, i ) {
nicholas@2224 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nicholas@2224 421 },
nicholas@2224 422
nicholas@2224 423 merge: function( first, second ) {
nicholas@2224 424 var len = +second.length,
nicholas@2224 425 j = 0,
nicholas@2224 426 i = first.length;
nicholas@2224 427
nicholas@2224 428 for ( ; j < len; j++ ) {
nicholas@2224 429 first[ i++ ] = second[ j ];
nicholas@2224 430 }
nicholas@2224 431
nicholas@2224 432 first.length = i;
nicholas@2224 433
nicholas@2224 434 return first;
nicholas@2224 435 },
nicholas@2224 436
nicholas@2224 437 grep: function( elems, callback, invert ) {
nicholas@2224 438 var callbackInverse,
nicholas@2224 439 matches = [],
nicholas@2224 440 i = 0,
nicholas@2224 441 length = elems.length,
nicholas@2224 442 callbackExpect = !invert;
nicholas@2224 443
nicholas@2224 444 // Go through the array, only saving the items
nicholas@2224 445 // that pass the validator function
nicholas@2224 446 for ( ; i < length; i++ ) {
nicholas@2224 447 callbackInverse = !callback( elems[ i ], i );
nicholas@2224 448 if ( callbackInverse !== callbackExpect ) {
nicholas@2224 449 matches.push( elems[ i ] );
nicholas@2224 450 }
nicholas@2224 451 }
nicholas@2224 452
nicholas@2224 453 return matches;
nicholas@2224 454 },
nicholas@2224 455
nicholas@2224 456 // arg is for internal usage only
nicholas@2224 457 map: function( elems, callback, arg ) {
nicholas@2224 458 var value,
nicholas@2224 459 i = 0,
nicholas@2224 460 length = elems.length,
nicholas@2224 461 isArray = isArraylike( elems ),
nicholas@2224 462 ret = [];
nicholas@2224 463
nicholas@2224 464 // Go through the array, translating each of the items to their new values
nicholas@2224 465 if ( isArray ) {
nicholas@2224 466 for ( ; i < length; i++ ) {
nicholas@2224 467 value = callback( elems[ i ], i, arg );
nicholas@2224 468
nicholas@2224 469 if ( value != null ) {
nicholas@2224 470 ret.push( value );
nicholas@2224 471 }
nicholas@2224 472 }
nicholas@2224 473
nicholas@2224 474 // Go through every key on the object,
nicholas@2224 475 } else {
nicholas@2224 476 for ( i in elems ) {
nicholas@2224 477 value = callback( elems[ i ], i, arg );
nicholas@2224 478
nicholas@2224 479 if ( value != null ) {
nicholas@2224 480 ret.push( value );
nicholas@2224 481 }
nicholas@2224 482 }
nicholas@2224 483 }
nicholas@2224 484
nicholas@2224 485 // Flatten any nested arrays
nicholas@2224 486 return concat.apply( [], ret );
nicholas@2224 487 },
nicholas@2224 488
nicholas@2224 489 // A global GUID counter for objects
nicholas@2224 490 guid: 1,
nicholas@2224 491
nicholas@2224 492 // Bind a function to a context, optionally partially applying any
nicholas@2224 493 // arguments.
nicholas@2224 494 proxy: function( fn, context ) {
nicholas@2224 495 var tmp, args, proxy;
nicholas@2224 496
nicholas@2224 497 if ( typeof context === "string" ) {
nicholas@2224 498 tmp = fn[ context ];
nicholas@2224 499 context = fn;
nicholas@2224 500 fn = tmp;
nicholas@2224 501 }
nicholas@2224 502
nicholas@2224 503 // Quick check to determine if target is callable, in the spec
nicholas@2224 504 // this throws a TypeError, but we will just return undefined.
nicholas@2224 505 if ( !jQuery.isFunction( fn ) ) {
nicholas@2224 506 return undefined;
nicholas@2224 507 }
nicholas@2224 508
nicholas@2224 509 // Simulated bind
nicholas@2224 510 args = slice.call( arguments, 2 );
nicholas@2224 511 proxy = function() {
nicholas@2224 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nicholas@2224 513 };
nicholas@2224 514
nicholas@2224 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nicholas@2224 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nicholas@2224 517
nicholas@2224 518 return proxy;
nicholas@2224 519 },
nicholas@2224 520
nicholas@2224 521 now: Date.now,
nicholas@2224 522
nicholas@2224 523 // jQuery.support is not used in Core but other projects attach their
nicholas@2224 524 // properties to it so it needs to exist.
nicholas@2224 525 support: support
nicholas@2224 526 });
nicholas@2224 527
nicholas@2224 528 // Populate the class2type map
nicholas@2224 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nicholas@2224 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nicholas@2224 531 });
nicholas@2224 532
nicholas@2224 533 function isArraylike( obj ) {
nicholas@2224 534
nicholas@2224 535 // Support: iOS 8.2 (not reproducible in simulator)
nicholas@2224 536 // `in` check used to prevent JIT error (gh-2145)
nicholas@2224 537 // hasOwn isn't used here due to false negatives
nicholas@2224 538 // regarding Nodelist length in IE
nicholas@2224 539 var length = "length" in obj && obj.length,
nicholas@2224 540 type = jQuery.type( obj );
nicholas@2224 541
nicholas@2224 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nicholas@2224 543 return false;
nicholas@2224 544 }
nicholas@2224 545
nicholas@2224 546 if ( obj.nodeType === 1 && length ) {
nicholas@2224 547 return true;
nicholas@2224 548 }
nicholas@2224 549
nicholas@2224 550 return type === "array" || length === 0 ||
nicholas@2224 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nicholas@2224 552 }
nicholas@2224 553 var Sizzle =
nicholas@2224 554 /*!
nicholas@2224 555 * Sizzle CSS Selector Engine v2.2.0-pre
nicholas@2224 556 * http://sizzlejs.com/
nicholas@2224 557 *
nicholas@2224 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nicholas@2224 559 * Released under the MIT license
nicholas@2224 560 * http://jquery.org/license
nicholas@2224 561 *
nicholas@2224 562 * Date: 2014-12-16
nicholas@2224 563 */
nicholas@2224 564 (function( window ) {
nicholas@2224 565
nicholas@2224 566 var i,
nicholas@2224 567 support,
nicholas@2224 568 Expr,
nicholas@2224 569 getText,
nicholas@2224 570 isXML,
nicholas@2224 571 tokenize,
nicholas@2224 572 compile,
nicholas@2224 573 select,
nicholas@2224 574 outermostContext,
nicholas@2224 575 sortInput,
nicholas@2224 576 hasDuplicate,
nicholas@2224 577
nicholas@2224 578 // Local document vars
nicholas@2224 579 setDocument,
nicholas@2224 580 document,
nicholas@2224 581 docElem,
nicholas@2224 582 documentIsHTML,
nicholas@2224 583 rbuggyQSA,
nicholas@2224 584 rbuggyMatches,
nicholas@2224 585 matches,
nicholas@2224 586 contains,
nicholas@2224 587
nicholas@2224 588 // Instance-specific data
nicholas@2224 589 expando = "sizzle" + 1 * new Date(),
nicholas@2224 590 preferredDoc = window.document,
nicholas@2224 591 dirruns = 0,
nicholas@2224 592 done = 0,
nicholas@2224 593 classCache = createCache(),
nicholas@2224 594 tokenCache = createCache(),
nicholas@2224 595 compilerCache = createCache(),
nicholas@2224 596 sortOrder = function( a, b ) {
nicholas@2224 597 if ( a === b ) {
nicholas@2224 598 hasDuplicate = true;
nicholas@2224 599 }
nicholas@2224 600 return 0;
nicholas@2224 601 },
nicholas@2224 602
nicholas@2224 603 // General-purpose constants
nicholas@2224 604 MAX_NEGATIVE = 1 << 31,
nicholas@2224 605
nicholas@2224 606 // Instance methods
nicholas@2224 607 hasOwn = ({}).hasOwnProperty,
nicholas@2224 608 arr = [],
nicholas@2224 609 pop = arr.pop,
nicholas@2224 610 push_native = arr.push,
nicholas@2224 611 push = arr.push,
nicholas@2224 612 slice = arr.slice,
nicholas@2224 613 // Use a stripped-down indexOf as it's faster than native
nicholas@2224 614 // http://jsperf.com/thor-indexof-vs-for/5
nicholas@2224 615 indexOf = function( list, elem ) {
nicholas@2224 616 var i = 0,
nicholas@2224 617 len = list.length;
nicholas@2224 618 for ( ; i < len; i++ ) {
nicholas@2224 619 if ( list[i] === elem ) {
nicholas@2224 620 return i;
nicholas@2224 621 }
nicholas@2224 622 }
nicholas@2224 623 return -1;
nicholas@2224 624 },
nicholas@2224 625
nicholas@2224 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nicholas@2224 627
nicholas@2224 628 // Regular expressions
nicholas@2224 629
nicholas@2224 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nicholas@2224 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nicholas@2224 632 // http://www.w3.org/TR/css3-syntax/#characters
nicholas@2224 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nicholas@2224 634
nicholas@2224 635 // Loosely modeled on CSS identifier characters
nicholas@2224 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nicholas@2224 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nicholas@2224 638 identifier = characterEncoding.replace( "w", "w#" ),
nicholas@2224 639
nicholas@2224 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nicholas@2224 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nicholas@2224 642 // Operator (capture 2)
nicholas@2224 643 "*([*^$|!~]?=)" + whitespace +
nicholas@2224 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nicholas@2224 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nicholas@2224 646 "*\\]",
nicholas@2224 647
nicholas@2224 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nicholas@2224 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nicholas@2224 650 // 1. quoted (capture 3; capture 4 or capture 5)
nicholas@2224 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nicholas@2224 652 // 2. simple (capture 6)
nicholas@2224 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nicholas@2224 654 // 3. anything else (capture 2)
nicholas@2224 655 ".*" +
nicholas@2224 656 ")\\)|)",
nicholas@2224 657
nicholas@2224 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nicholas@2224 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nicholas@2224 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nicholas@2224 661
nicholas@2224 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nicholas@2224 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nicholas@2224 664
nicholas@2224 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nicholas@2224 666
nicholas@2224 667 rpseudo = new RegExp( pseudos ),
nicholas@2224 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nicholas@2224 669
nicholas@2224 670 matchExpr = {
nicholas@2224 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nicholas@2224 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nicholas@2224 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nicholas@2224 674 "ATTR": new RegExp( "^" + attributes ),
nicholas@2224 675 "PSEUDO": new RegExp( "^" + pseudos ),
nicholas@2224 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nicholas@2224 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nicholas@2224 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nicholas@2224 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nicholas@2224 680 // For use in libraries implementing .is()
nicholas@2224 681 // We use this for POS matching in `select`
nicholas@2224 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nicholas@2224 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nicholas@2224 684 },
nicholas@2224 685
nicholas@2224 686 rinputs = /^(?:input|select|textarea|button)$/i,
nicholas@2224 687 rheader = /^h\d$/i,
nicholas@2224 688
nicholas@2224 689 rnative = /^[^{]+\{\s*\[native \w/,
nicholas@2224 690
nicholas@2224 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nicholas@2224 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nicholas@2224 693
nicholas@2224 694 rsibling = /[+~]/,
nicholas@2224 695 rescape = /'|\\/g,
nicholas@2224 696
nicholas@2224 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nicholas@2224 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nicholas@2224 699 funescape = function( _, escaped, escapedWhitespace ) {
nicholas@2224 700 var high = "0x" + escaped - 0x10000;
nicholas@2224 701 // NaN means non-codepoint
nicholas@2224 702 // Support: Firefox<24
nicholas@2224 703 // Workaround erroneous numeric interpretation of +"0x"
nicholas@2224 704 return high !== high || escapedWhitespace ?
nicholas@2224 705 escaped :
nicholas@2224 706 high < 0 ?
nicholas@2224 707 // BMP codepoint
nicholas@2224 708 String.fromCharCode( high + 0x10000 ) :
nicholas@2224 709 // Supplemental Plane codepoint (surrogate pair)
nicholas@2224 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nicholas@2224 711 },
nicholas@2224 712
nicholas@2224 713 // Used for iframes
nicholas@2224 714 // See setDocument()
nicholas@2224 715 // Removing the function wrapper causes a "Permission Denied"
nicholas@2224 716 // error in IE
nicholas@2224 717 unloadHandler = function() {
nicholas@2224 718 setDocument();
nicholas@2224 719 };
nicholas@2224 720
nicholas@2224 721 // Optimize for push.apply( _, NodeList )
nicholas@2224 722 try {
nicholas@2224 723 push.apply(
nicholas@2224 724 (arr = slice.call( preferredDoc.childNodes )),
nicholas@2224 725 preferredDoc.childNodes
nicholas@2224 726 );
nicholas@2224 727 // Support: Android<4.0
nicholas@2224 728 // Detect silently failing push.apply
nicholas@2224 729 arr[ preferredDoc.childNodes.length ].nodeType;
nicholas@2224 730 } catch ( e ) {
nicholas@2224 731 push = { apply: arr.length ?
nicholas@2224 732
nicholas@2224 733 // Leverage slice if possible
nicholas@2224 734 function( target, els ) {
nicholas@2224 735 push_native.apply( target, slice.call(els) );
nicholas@2224 736 } :
nicholas@2224 737
nicholas@2224 738 // Support: IE<9
nicholas@2224 739 // Otherwise append directly
nicholas@2224 740 function( target, els ) {
nicholas@2224 741 var j = target.length,
nicholas@2224 742 i = 0;
nicholas@2224 743 // Can't trust NodeList.length
nicholas@2224 744 while ( (target[j++] = els[i++]) ) {}
nicholas@2224 745 target.length = j - 1;
nicholas@2224 746 }
nicholas@2224 747 };
nicholas@2224 748 }
nicholas@2224 749
nicholas@2224 750 function Sizzle( selector, context, results, seed ) {
nicholas@2224 751 var match, elem, m, nodeType,
nicholas@2224 752 // QSA vars
nicholas@2224 753 i, groups, old, nid, newContext, newSelector;
nicholas@2224 754
nicholas@2224 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nicholas@2224 756 setDocument( context );
nicholas@2224 757 }
nicholas@2224 758
nicholas@2224 759 context = context || document;
nicholas@2224 760 results = results || [];
nicholas@2224 761 nodeType = context.nodeType;
nicholas@2224 762
nicholas@2224 763 if ( typeof selector !== "string" || !selector ||
nicholas@2224 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nicholas@2224 765
nicholas@2224 766 return results;
nicholas@2224 767 }
nicholas@2224 768
nicholas@2224 769 if ( !seed && documentIsHTML ) {
nicholas@2224 770
nicholas@2224 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nicholas@2224 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nicholas@2224 773 // Speed-up: Sizzle("#ID")
nicholas@2224 774 if ( (m = match[1]) ) {
nicholas@2224 775 if ( nodeType === 9 ) {
nicholas@2224 776 elem = context.getElementById( m );
nicholas@2224 777 // Check parentNode to catch when Blackberry 4.6 returns
nicholas@2224 778 // nodes that are no longer in the document (jQuery #6963)
nicholas@2224 779 if ( elem && elem.parentNode ) {
nicholas@2224 780 // Handle the case where IE, Opera, and Webkit return items
nicholas@2224 781 // by name instead of ID
nicholas@2224 782 if ( elem.id === m ) {
nicholas@2224 783 results.push( elem );
nicholas@2224 784 return results;
nicholas@2224 785 }
nicholas@2224 786 } else {
nicholas@2224 787 return results;
nicholas@2224 788 }
nicholas@2224 789 } else {
nicholas@2224 790 // Context is not a document
nicholas@2224 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nicholas@2224 792 contains( context, elem ) && elem.id === m ) {
nicholas@2224 793 results.push( elem );
nicholas@2224 794 return results;
nicholas@2224 795 }
nicholas@2224 796 }
nicholas@2224 797
nicholas@2224 798 // Speed-up: Sizzle("TAG")
nicholas@2224 799 } else if ( match[2] ) {
nicholas@2224 800 push.apply( results, context.getElementsByTagName( selector ) );
nicholas@2224 801 return results;
nicholas@2224 802
nicholas@2224 803 // Speed-up: Sizzle(".CLASS")
nicholas@2224 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nicholas@2224 805 push.apply( results, context.getElementsByClassName( m ) );
nicholas@2224 806 return results;
nicholas@2224 807 }
nicholas@2224 808 }
nicholas@2224 809
nicholas@2224 810 // QSA path
nicholas@2224 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nicholas@2224 812 nid = old = expando;
nicholas@2224 813 newContext = context;
nicholas@2224 814 newSelector = nodeType !== 1 && selector;
nicholas@2224 815
nicholas@2224 816 // qSA works strangely on Element-rooted queries
nicholas@2224 817 // We can work around this by specifying an extra ID on the root
nicholas@2224 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nicholas@2224 819 // IE 8 doesn't work on object elements
nicholas@2224 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nicholas@2224 821 groups = tokenize( selector );
nicholas@2224 822
nicholas@2224 823 if ( (old = context.getAttribute("id")) ) {
nicholas@2224 824 nid = old.replace( rescape, "\\$&" );
nicholas@2224 825 } else {
nicholas@2224 826 context.setAttribute( "id", nid );
nicholas@2224 827 }
nicholas@2224 828 nid = "[id='" + nid + "'] ";
nicholas@2224 829
nicholas@2224 830 i = groups.length;
nicholas@2224 831 while ( i-- ) {
nicholas@2224 832 groups[i] = nid + toSelector( groups[i] );
nicholas@2224 833 }
nicholas@2224 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nicholas@2224 835 newSelector = groups.join(",");
nicholas@2224 836 }
nicholas@2224 837
nicholas@2224 838 if ( newSelector ) {
nicholas@2224 839 try {
nicholas@2224 840 push.apply( results,
nicholas@2224 841 newContext.querySelectorAll( newSelector )
nicholas@2224 842 );
nicholas@2224 843 return results;
nicholas@2224 844 } catch(qsaError) {
nicholas@2224 845 } finally {
nicholas@2224 846 if ( !old ) {
nicholas@2224 847 context.removeAttribute("id");
nicholas@2224 848 }
nicholas@2224 849 }
nicholas@2224 850 }
nicholas@2224 851 }
nicholas@2224 852 }
nicholas@2224 853
nicholas@2224 854 // All others
nicholas@2224 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nicholas@2224 856 }
nicholas@2224 857
nicholas@2224 858 /**
nicholas@2224 859 * Create key-value caches of limited size
nicholas@2224 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nicholas@2224 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nicholas@2224 862 * deleting the oldest entry
nicholas@2224 863 */
nicholas@2224 864 function createCache() {
nicholas@2224 865 var keys = [];
nicholas@2224 866
nicholas@2224 867 function cache( key, value ) {
nicholas@2224 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nicholas@2224 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nicholas@2224 870 // Only keep the most recent entries
nicholas@2224 871 delete cache[ keys.shift() ];
nicholas@2224 872 }
nicholas@2224 873 return (cache[ key + " " ] = value);
nicholas@2224 874 }
nicholas@2224 875 return cache;
nicholas@2224 876 }
nicholas@2224 877
nicholas@2224 878 /**
nicholas@2224 879 * Mark a function for special use by Sizzle
nicholas@2224 880 * @param {Function} fn The function to mark
nicholas@2224 881 */
nicholas@2224 882 function markFunction( fn ) {
nicholas@2224 883 fn[ expando ] = true;
nicholas@2224 884 return fn;
nicholas@2224 885 }
nicholas@2224 886
nicholas@2224 887 /**
nicholas@2224 888 * Support testing using an element
nicholas@2224 889 * @param {Function} fn Passed the created div and expects a boolean result
nicholas@2224 890 */
nicholas@2224 891 function assert( fn ) {
nicholas@2224 892 var div = document.createElement("div");
nicholas@2224 893
nicholas@2224 894 try {
nicholas@2224 895 return !!fn( div );
nicholas@2224 896 } catch (e) {
nicholas@2224 897 return false;
nicholas@2224 898 } finally {
nicholas@2224 899 // Remove from its parent by default
nicholas@2224 900 if ( div.parentNode ) {
nicholas@2224 901 div.parentNode.removeChild( div );
nicholas@2224 902 }
nicholas@2224 903 // release memory in IE
nicholas@2224 904 div = null;
nicholas@2224 905 }
nicholas@2224 906 }
nicholas@2224 907
nicholas@2224 908 /**
nicholas@2224 909 * Adds the same handler for all of the specified attrs
nicholas@2224 910 * @param {String} attrs Pipe-separated list of attributes
nicholas@2224 911 * @param {Function} handler The method that will be applied
nicholas@2224 912 */
nicholas@2224 913 function addHandle( attrs, handler ) {
nicholas@2224 914 var arr = attrs.split("|"),
nicholas@2224 915 i = attrs.length;
nicholas@2224 916
nicholas@2224 917 while ( i-- ) {
nicholas@2224 918 Expr.attrHandle[ arr[i] ] = handler;
nicholas@2224 919 }
nicholas@2224 920 }
nicholas@2224 921
nicholas@2224 922 /**
nicholas@2224 923 * Checks document order of two siblings
nicholas@2224 924 * @param {Element} a
nicholas@2224 925 * @param {Element} b
nicholas@2224 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nicholas@2224 927 */
nicholas@2224 928 function siblingCheck( a, b ) {
nicholas@2224 929 var cur = b && a,
nicholas@2224 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nicholas@2224 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nicholas@2224 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nicholas@2224 933
nicholas@2224 934 // Use IE sourceIndex if available on both nodes
nicholas@2224 935 if ( diff ) {
nicholas@2224 936 return diff;
nicholas@2224 937 }
nicholas@2224 938
nicholas@2224 939 // Check if b follows a
nicholas@2224 940 if ( cur ) {
nicholas@2224 941 while ( (cur = cur.nextSibling) ) {
nicholas@2224 942 if ( cur === b ) {
nicholas@2224 943 return -1;
nicholas@2224 944 }
nicholas@2224 945 }
nicholas@2224 946 }
nicholas@2224 947
nicholas@2224 948 return a ? 1 : -1;
nicholas@2224 949 }
nicholas@2224 950
nicholas@2224 951 /**
nicholas@2224 952 * Returns a function to use in pseudos for input types
nicholas@2224 953 * @param {String} type
nicholas@2224 954 */
nicholas@2224 955 function createInputPseudo( type ) {
nicholas@2224 956 return function( elem ) {
nicholas@2224 957 var name = elem.nodeName.toLowerCase();
nicholas@2224 958 return name === "input" && elem.type === type;
nicholas@2224 959 };
nicholas@2224 960 }
nicholas@2224 961
nicholas@2224 962 /**
nicholas@2224 963 * Returns a function to use in pseudos for buttons
nicholas@2224 964 * @param {String} type
nicholas@2224 965 */
nicholas@2224 966 function createButtonPseudo( type ) {
nicholas@2224 967 return function( elem ) {
nicholas@2224 968 var name = elem.nodeName.toLowerCase();
nicholas@2224 969 return (name === "input" || name === "button") && elem.type === type;
nicholas@2224 970 };
nicholas@2224 971 }
nicholas@2224 972
nicholas@2224 973 /**
nicholas@2224 974 * Returns a function to use in pseudos for positionals
nicholas@2224 975 * @param {Function} fn
nicholas@2224 976 */
nicholas@2224 977 function createPositionalPseudo( fn ) {
nicholas@2224 978 return markFunction(function( argument ) {
nicholas@2224 979 argument = +argument;
nicholas@2224 980 return markFunction(function( seed, matches ) {
nicholas@2224 981 var j,
nicholas@2224 982 matchIndexes = fn( [], seed.length, argument ),
nicholas@2224 983 i = matchIndexes.length;
nicholas@2224 984
nicholas@2224 985 // Match elements found at the specified indexes
nicholas@2224 986 while ( i-- ) {
nicholas@2224 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nicholas@2224 988 seed[j] = !(matches[j] = seed[j]);
nicholas@2224 989 }
nicholas@2224 990 }
nicholas@2224 991 });
nicholas@2224 992 });
nicholas@2224 993 }
nicholas@2224 994
nicholas@2224 995 /**
nicholas@2224 996 * Checks a node for validity as a Sizzle context
nicholas@2224 997 * @param {Element|Object=} context
nicholas@2224 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nicholas@2224 999 */
nicholas@2224 1000 function testContext( context ) {
nicholas@2224 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nicholas@2224 1002 }
nicholas@2224 1003
nicholas@2224 1004 // Expose support vars for convenience
nicholas@2224 1005 support = Sizzle.support = {};
nicholas@2224 1006
nicholas@2224 1007 /**
nicholas@2224 1008 * Detects XML nodes
nicholas@2224 1009 * @param {Element|Object} elem An element or a document
nicholas@2224 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nicholas@2224 1011 */
nicholas@2224 1012 isXML = Sizzle.isXML = function( elem ) {
nicholas@2224 1013 // documentElement is verified for cases where it doesn't yet exist
nicholas@2224 1014 // (such as loading iframes in IE - #4833)
nicholas@2224 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nicholas@2224 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nicholas@2224 1017 };
nicholas@2224 1018
nicholas@2224 1019 /**
nicholas@2224 1020 * Sets document-related variables once based on the current document
nicholas@2224 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nicholas@2224 1022 * @returns {Object} Returns the current document
nicholas@2224 1023 */
nicholas@2224 1024 setDocument = Sizzle.setDocument = function( node ) {
nicholas@2224 1025 var hasCompare, parent,
nicholas@2224 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nicholas@2224 1027
nicholas@2224 1028 // If no document and documentElement is available, return
nicholas@2224 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nicholas@2224 1030 return document;
nicholas@2224 1031 }
nicholas@2224 1032
nicholas@2224 1033 // Set our document
nicholas@2224 1034 document = doc;
nicholas@2224 1035 docElem = doc.documentElement;
nicholas@2224 1036 parent = doc.defaultView;
nicholas@2224 1037
nicholas@2224 1038 // Support: IE>8
nicholas@2224 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nicholas@2224 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nicholas@2224 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nicholas@2224 1042 if ( parent && parent !== parent.top ) {
nicholas@2224 1043 // IE11 does not have attachEvent, so all must suffer
nicholas@2224 1044 if ( parent.addEventListener ) {
nicholas@2224 1045 parent.addEventListener( "unload", unloadHandler, false );
nicholas@2224 1046 } else if ( parent.attachEvent ) {
nicholas@2224 1047 parent.attachEvent( "onunload", unloadHandler );
nicholas@2224 1048 }
nicholas@2224 1049 }
nicholas@2224 1050
nicholas@2224 1051 /* Support tests
nicholas@2224 1052 ---------------------------------------------------------------------- */
nicholas@2224 1053 documentIsHTML = !isXML( doc );
nicholas@2224 1054
nicholas@2224 1055 /* Attributes
nicholas@2224 1056 ---------------------------------------------------------------------- */
nicholas@2224 1057
nicholas@2224 1058 // Support: IE<8
nicholas@2224 1059 // Verify that getAttribute really returns attributes and not properties
nicholas@2224 1060 // (excepting IE8 booleans)
nicholas@2224 1061 support.attributes = assert(function( div ) {
nicholas@2224 1062 div.className = "i";
nicholas@2224 1063 return !div.getAttribute("className");
nicholas@2224 1064 });
nicholas@2224 1065
nicholas@2224 1066 /* getElement(s)By*
nicholas@2224 1067 ---------------------------------------------------------------------- */
nicholas@2224 1068
nicholas@2224 1069 // Check if getElementsByTagName("*") returns only elements
nicholas@2224 1070 support.getElementsByTagName = assert(function( div ) {
nicholas@2224 1071 div.appendChild( doc.createComment("") );
nicholas@2224 1072 return !div.getElementsByTagName("*").length;
nicholas@2224 1073 });
nicholas@2224 1074
nicholas@2224 1075 // Support: IE<9
nicholas@2224 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nicholas@2224 1077
nicholas@2224 1078 // Support: IE<10
nicholas@2224 1079 // Check if getElementById returns elements by name
nicholas@2224 1080 // The broken getElementById methods don't pick up programatically-set names,
nicholas@2224 1081 // so use a roundabout getElementsByName test
nicholas@2224 1082 support.getById = assert(function( div ) {
nicholas@2224 1083 docElem.appendChild( div ).id = expando;
nicholas@2224 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nicholas@2224 1085 });
nicholas@2224 1086
nicholas@2224 1087 // ID find and filter
nicholas@2224 1088 if ( support.getById ) {
nicholas@2224 1089 Expr.find["ID"] = function( id, context ) {
nicholas@2224 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nicholas@2224 1091 var m = context.getElementById( id );
nicholas@2224 1092 // Check parentNode to catch when Blackberry 4.6 returns
nicholas@2224 1093 // nodes that are no longer in the document #6963
nicholas@2224 1094 return m && m.parentNode ? [ m ] : [];
nicholas@2224 1095 }
nicholas@2224 1096 };
nicholas@2224 1097 Expr.filter["ID"] = function( id ) {
nicholas@2224 1098 var attrId = id.replace( runescape, funescape );
nicholas@2224 1099 return function( elem ) {
nicholas@2224 1100 return elem.getAttribute("id") === attrId;
nicholas@2224 1101 };
nicholas@2224 1102 };
nicholas@2224 1103 } else {
nicholas@2224 1104 // Support: IE6/7
nicholas@2224 1105 // getElementById is not reliable as a find shortcut
nicholas@2224 1106 delete Expr.find["ID"];
nicholas@2224 1107
nicholas@2224 1108 Expr.filter["ID"] = function( id ) {
nicholas@2224 1109 var attrId = id.replace( runescape, funescape );
nicholas@2224 1110 return function( elem ) {
nicholas@2224 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nicholas@2224 1112 return node && node.value === attrId;
nicholas@2224 1113 };
nicholas@2224 1114 };
nicholas@2224 1115 }
nicholas@2224 1116
nicholas@2224 1117 // Tag
nicholas@2224 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nicholas@2224 1119 function( tag, context ) {
nicholas@2224 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nicholas@2224 1121 return context.getElementsByTagName( tag );
nicholas@2224 1122
nicholas@2224 1123 // DocumentFragment nodes don't have gEBTN
nicholas@2224 1124 } else if ( support.qsa ) {
nicholas@2224 1125 return context.querySelectorAll( tag );
nicholas@2224 1126 }
nicholas@2224 1127 } :
nicholas@2224 1128
nicholas@2224 1129 function( tag, context ) {
nicholas@2224 1130 var elem,
nicholas@2224 1131 tmp = [],
nicholas@2224 1132 i = 0,
nicholas@2224 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nicholas@2224 1134 results = context.getElementsByTagName( tag );
nicholas@2224 1135
nicholas@2224 1136 // Filter out possible comments
nicholas@2224 1137 if ( tag === "*" ) {
nicholas@2224 1138 while ( (elem = results[i++]) ) {
nicholas@2224 1139 if ( elem.nodeType === 1 ) {
nicholas@2224 1140 tmp.push( elem );
nicholas@2224 1141 }
nicholas@2224 1142 }
nicholas@2224 1143
nicholas@2224 1144 return tmp;
nicholas@2224 1145 }
nicholas@2224 1146 return results;
nicholas@2224 1147 };
nicholas@2224 1148
nicholas@2224 1149 // Class
nicholas@2224 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nicholas@2224 1151 if ( documentIsHTML ) {
nicholas@2224 1152 return context.getElementsByClassName( className );
nicholas@2224 1153 }
nicholas@2224 1154 };
nicholas@2224 1155
nicholas@2224 1156 /* QSA/matchesSelector
nicholas@2224 1157 ---------------------------------------------------------------------- */
nicholas@2224 1158
nicholas@2224 1159 // QSA and matchesSelector support
nicholas@2224 1160
nicholas@2224 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nicholas@2224 1162 rbuggyMatches = [];
nicholas@2224 1163
nicholas@2224 1164 // qSa(:focus) reports false when true (Chrome 21)
nicholas@2224 1165 // We allow this because of a bug in IE8/9 that throws an error
nicholas@2224 1166 // whenever `document.activeElement` is accessed on an iframe
nicholas@2224 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nicholas@2224 1168 // See http://bugs.jquery.com/ticket/13378
nicholas@2224 1169 rbuggyQSA = [];
nicholas@2224 1170
nicholas@2224 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nicholas@2224 1172 // Build QSA regex
nicholas@2224 1173 // Regex strategy adopted from Diego Perini
nicholas@2224 1174 assert(function( div ) {
nicholas@2224 1175 // Select is set to empty string on purpose
nicholas@2224 1176 // This is to test IE's treatment of not explicitly
nicholas@2224 1177 // setting a boolean content attribute,
nicholas@2224 1178 // since its presence should be enough
nicholas@2224 1179 // http://bugs.jquery.com/ticket/12359
nicholas@2224 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nicholas@2224 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nicholas@2224 1182 "<option selected=''></option></select>";
nicholas@2224 1183
nicholas@2224 1184 // Support: IE8, Opera 11-12.16
nicholas@2224 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nicholas@2224 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nicholas@2224 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nicholas@2224 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nicholas@2224 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nicholas@2224 1190 }
nicholas@2224 1191
nicholas@2224 1192 // Support: IE8
nicholas@2224 1193 // Boolean attributes and "value" are not treated correctly
nicholas@2224 1194 if ( !div.querySelectorAll("[selected]").length ) {
nicholas@2224 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nicholas@2224 1196 }
nicholas@2224 1197
nicholas@2224 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nicholas@2224 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nicholas@2224 1200 rbuggyQSA.push("~=");
nicholas@2224 1201 }
nicholas@2224 1202
nicholas@2224 1203 // Webkit/Opera - :checked should return selected option elements
nicholas@2224 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nicholas@2224 1205 // IE8 throws error here and will not see later tests
nicholas@2224 1206 if ( !div.querySelectorAll(":checked").length ) {
nicholas@2224 1207 rbuggyQSA.push(":checked");
nicholas@2224 1208 }
nicholas@2224 1209
nicholas@2224 1210 // Support: Safari 8+, iOS 8+
nicholas@2224 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nicholas@2224 1212 // In-page `selector#id sibing-combinator selector` fails
nicholas@2224 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nicholas@2224 1214 rbuggyQSA.push(".#.+[+~]");
nicholas@2224 1215 }
nicholas@2224 1216 });
nicholas@2224 1217
nicholas@2224 1218 assert(function( div ) {
nicholas@2224 1219 // Support: Windows 8 Native Apps
nicholas@2224 1220 // The type and name attributes are restricted during .innerHTML assignment
nicholas@2224 1221 var input = doc.createElement("input");
nicholas@2224 1222 input.setAttribute( "type", "hidden" );
nicholas@2224 1223 div.appendChild( input ).setAttribute( "name", "D" );
nicholas@2224 1224
nicholas@2224 1225 // Support: IE8
nicholas@2224 1226 // Enforce case-sensitivity of name attribute
nicholas@2224 1227 if ( div.querySelectorAll("[name=d]").length ) {
nicholas@2224 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nicholas@2224 1229 }
nicholas@2224 1230
nicholas@2224 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nicholas@2224 1232 // IE8 throws error here and will not see later tests
nicholas@2224 1233 if ( !div.querySelectorAll(":enabled").length ) {
nicholas@2224 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nicholas@2224 1235 }
nicholas@2224 1236
nicholas@2224 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nicholas@2224 1238 div.querySelectorAll("*,:x");
nicholas@2224 1239 rbuggyQSA.push(",.*:");
nicholas@2224 1240 });
nicholas@2224 1241 }
nicholas@2224 1242
nicholas@2224 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nicholas@2224 1244 docElem.webkitMatchesSelector ||
nicholas@2224 1245 docElem.mozMatchesSelector ||
nicholas@2224 1246 docElem.oMatchesSelector ||
nicholas@2224 1247 docElem.msMatchesSelector) )) ) {
nicholas@2224 1248
nicholas@2224 1249 assert(function( div ) {
nicholas@2224 1250 // Check to see if it's possible to do matchesSelector
nicholas@2224 1251 // on a disconnected node (IE 9)
nicholas@2224 1252 support.disconnectedMatch = matches.call( div, "div" );
nicholas@2224 1253
nicholas@2224 1254 // This should fail with an exception
nicholas@2224 1255 // Gecko does not error, returns false instead
nicholas@2224 1256 matches.call( div, "[s!='']:x" );
nicholas@2224 1257 rbuggyMatches.push( "!=", pseudos );
nicholas@2224 1258 });
nicholas@2224 1259 }
nicholas@2224 1260
nicholas@2224 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nicholas@2224 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nicholas@2224 1263
nicholas@2224 1264 /* Contains
nicholas@2224 1265 ---------------------------------------------------------------------- */
nicholas@2224 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nicholas@2224 1267
nicholas@2224 1268 // Element contains another
nicholas@2224 1269 // Purposefully does not implement inclusive descendent
nicholas@2224 1270 // As in, an element does not contain itself
nicholas@2224 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nicholas@2224 1272 function( a, b ) {
nicholas@2224 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nicholas@2224 1274 bup = b && b.parentNode;
nicholas@2224 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nicholas@2224 1276 adown.contains ?
nicholas@2224 1277 adown.contains( bup ) :
nicholas@2224 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nicholas@2224 1279 ));
nicholas@2224 1280 } :
nicholas@2224 1281 function( a, b ) {
nicholas@2224 1282 if ( b ) {
nicholas@2224 1283 while ( (b = b.parentNode) ) {
nicholas@2224 1284 if ( b === a ) {
nicholas@2224 1285 return true;
nicholas@2224 1286 }
nicholas@2224 1287 }
nicholas@2224 1288 }
nicholas@2224 1289 return false;
nicholas@2224 1290 };
nicholas@2224 1291
nicholas@2224 1292 /* Sorting
nicholas@2224 1293 ---------------------------------------------------------------------- */
nicholas@2224 1294
nicholas@2224 1295 // Document order sorting
nicholas@2224 1296 sortOrder = hasCompare ?
nicholas@2224 1297 function( a, b ) {
nicholas@2224 1298
nicholas@2224 1299 // Flag for duplicate removal
nicholas@2224 1300 if ( a === b ) {
nicholas@2224 1301 hasDuplicate = true;
nicholas@2224 1302 return 0;
nicholas@2224 1303 }
nicholas@2224 1304
nicholas@2224 1305 // Sort on method existence if only one input has compareDocumentPosition
nicholas@2224 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nicholas@2224 1307 if ( compare ) {
nicholas@2224 1308 return compare;
nicholas@2224 1309 }
nicholas@2224 1310
nicholas@2224 1311 // Calculate position if both inputs belong to the same document
nicholas@2224 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nicholas@2224 1313 a.compareDocumentPosition( b ) :
nicholas@2224 1314
nicholas@2224 1315 // Otherwise we know they are disconnected
nicholas@2224 1316 1;
nicholas@2224 1317
nicholas@2224 1318 // Disconnected nodes
nicholas@2224 1319 if ( compare & 1 ||
nicholas@2224 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nicholas@2224 1321
nicholas@2224 1322 // Choose the first element that is related to our preferred document
nicholas@2224 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nicholas@2224 1324 return -1;
nicholas@2224 1325 }
nicholas@2224 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nicholas@2224 1327 return 1;
nicholas@2224 1328 }
nicholas@2224 1329
nicholas@2224 1330 // Maintain original order
nicholas@2224 1331 return sortInput ?
nicholas@2224 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nicholas@2224 1333 0;
nicholas@2224 1334 }
nicholas@2224 1335
nicholas@2224 1336 return compare & 4 ? -1 : 1;
nicholas@2224 1337 } :
nicholas@2224 1338 function( a, b ) {
nicholas@2224 1339 // Exit early if the nodes are identical
nicholas@2224 1340 if ( a === b ) {
nicholas@2224 1341 hasDuplicate = true;
nicholas@2224 1342 return 0;
nicholas@2224 1343 }
nicholas@2224 1344
nicholas@2224 1345 var cur,
nicholas@2224 1346 i = 0,
nicholas@2224 1347 aup = a.parentNode,
nicholas@2224 1348 bup = b.parentNode,
nicholas@2224 1349 ap = [ a ],
nicholas@2224 1350 bp = [ b ];
nicholas@2224 1351
nicholas@2224 1352 // Parentless nodes are either documents or disconnected
nicholas@2224 1353 if ( !aup || !bup ) {
nicholas@2224 1354 return a === doc ? -1 :
nicholas@2224 1355 b === doc ? 1 :
nicholas@2224 1356 aup ? -1 :
nicholas@2224 1357 bup ? 1 :
nicholas@2224 1358 sortInput ?
nicholas@2224 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nicholas@2224 1360 0;
nicholas@2224 1361
nicholas@2224 1362 // If the nodes are siblings, we can do a quick check
nicholas@2224 1363 } else if ( aup === bup ) {
nicholas@2224 1364 return siblingCheck( a, b );
nicholas@2224 1365 }
nicholas@2224 1366
nicholas@2224 1367 // Otherwise we need full lists of their ancestors for comparison
nicholas@2224 1368 cur = a;
nicholas@2224 1369 while ( (cur = cur.parentNode) ) {
nicholas@2224 1370 ap.unshift( cur );
nicholas@2224 1371 }
nicholas@2224 1372 cur = b;
nicholas@2224 1373 while ( (cur = cur.parentNode) ) {
nicholas@2224 1374 bp.unshift( cur );
nicholas@2224 1375 }
nicholas@2224 1376
nicholas@2224 1377 // Walk down the tree looking for a discrepancy
nicholas@2224 1378 while ( ap[i] === bp[i] ) {
nicholas@2224 1379 i++;
nicholas@2224 1380 }
nicholas@2224 1381
nicholas@2224 1382 return i ?
nicholas@2224 1383 // Do a sibling check if the nodes have a common ancestor
nicholas@2224 1384 siblingCheck( ap[i], bp[i] ) :
nicholas@2224 1385
nicholas@2224 1386 // Otherwise nodes in our document sort first
nicholas@2224 1387 ap[i] === preferredDoc ? -1 :
nicholas@2224 1388 bp[i] === preferredDoc ? 1 :
nicholas@2224 1389 0;
nicholas@2224 1390 };
nicholas@2224 1391
nicholas@2224 1392 return doc;
nicholas@2224 1393 };
nicholas@2224 1394
nicholas@2224 1395 Sizzle.matches = function( expr, elements ) {
nicholas@2224 1396 return Sizzle( expr, null, null, elements );
nicholas@2224 1397 };
nicholas@2224 1398
nicholas@2224 1399 Sizzle.matchesSelector = function( elem, expr ) {
nicholas@2224 1400 // Set document vars if needed
nicholas@2224 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nicholas@2224 1402 setDocument( elem );
nicholas@2224 1403 }
nicholas@2224 1404
nicholas@2224 1405 // Make sure that attribute selectors are quoted
nicholas@2224 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nicholas@2224 1407
nicholas@2224 1408 if ( support.matchesSelector && documentIsHTML &&
nicholas@2224 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nicholas@2224 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nicholas@2224 1411
nicholas@2224 1412 try {
nicholas@2224 1413 var ret = matches.call( elem, expr );
nicholas@2224 1414
nicholas@2224 1415 // IE 9's matchesSelector returns false on disconnected nodes
nicholas@2224 1416 if ( ret || support.disconnectedMatch ||
nicholas@2224 1417 // As well, disconnected nodes are said to be in a document
nicholas@2224 1418 // fragment in IE 9
nicholas@2224 1419 elem.document && elem.document.nodeType !== 11 ) {
nicholas@2224 1420 return ret;
nicholas@2224 1421 }
nicholas@2224 1422 } catch (e) {}
nicholas@2224 1423 }
nicholas@2224 1424
nicholas@2224 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nicholas@2224 1426 };
nicholas@2224 1427
nicholas@2224 1428 Sizzle.contains = function( context, elem ) {
nicholas@2224 1429 // Set document vars if needed
nicholas@2224 1430 if ( ( context.ownerDocument || context ) !== document ) {
nicholas@2224 1431 setDocument( context );
nicholas@2224 1432 }
nicholas@2224 1433 return contains( context, elem );
nicholas@2224 1434 };
nicholas@2224 1435
nicholas@2224 1436 Sizzle.attr = function( elem, name ) {
nicholas@2224 1437 // Set document vars if needed
nicholas@2224 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nicholas@2224 1439 setDocument( elem );
nicholas@2224 1440 }
nicholas@2224 1441
nicholas@2224 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nicholas@2224 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nicholas@2224 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nicholas@2224 1445 fn( elem, name, !documentIsHTML ) :
nicholas@2224 1446 undefined;
nicholas@2224 1447
nicholas@2224 1448 return val !== undefined ?
nicholas@2224 1449 val :
nicholas@2224 1450 support.attributes || !documentIsHTML ?
nicholas@2224 1451 elem.getAttribute( name ) :
nicholas@2224 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nicholas@2224 1453 val.value :
nicholas@2224 1454 null;
nicholas@2224 1455 };
nicholas@2224 1456
nicholas@2224 1457 Sizzle.error = function( msg ) {
nicholas@2224 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nicholas@2224 1459 };
nicholas@2224 1460
nicholas@2224 1461 /**
nicholas@2224 1462 * Document sorting and removing duplicates
nicholas@2224 1463 * @param {ArrayLike} results
nicholas@2224 1464 */
nicholas@2224 1465 Sizzle.uniqueSort = function( results ) {
nicholas@2224 1466 var elem,
nicholas@2224 1467 duplicates = [],
nicholas@2224 1468 j = 0,
nicholas@2224 1469 i = 0;
nicholas@2224 1470
nicholas@2224 1471 // Unless we *know* we can detect duplicates, assume their presence
nicholas@2224 1472 hasDuplicate = !support.detectDuplicates;
nicholas@2224 1473 sortInput = !support.sortStable && results.slice( 0 );
nicholas@2224 1474 results.sort( sortOrder );
nicholas@2224 1475
nicholas@2224 1476 if ( hasDuplicate ) {
nicholas@2224 1477 while ( (elem = results[i++]) ) {
nicholas@2224 1478 if ( elem === results[ i ] ) {
nicholas@2224 1479 j = duplicates.push( i );
nicholas@2224 1480 }
nicholas@2224 1481 }
nicholas@2224 1482 while ( j-- ) {
nicholas@2224 1483 results.splice( duplicates[ j ], 1 );
nicholas@2224 1484 }
nicholas@2224 1485 }
nicholas@2224 1486
nicholas@2224 1487 // Clear input after sorting to release objects
nicholas@2224 1488 // See https://github.com/jquery/sizzle/pull/225
nicholas@2224 1489 sortInput = null;
nicholas@2224 1490
nicholas@2224 1491 return results;
nicholas@2224 1492 };
nicholas@2224 1493
nicholas@2224 1494 /**
nicholas@2224 1495 * Utility function for retrieving the text value of an array of DOM nodes
nicholas@2224 1496 * @param {Array|Element} elem
nicholas@2224 1497 */
nicholas@2224 1498 getText = Sizzle.getText = function( elem ) {
nicholas@2224 1499 var node,
nicholas@2224 1500 ret = "",
nicholas@2224 1501 i = 0,
nicholas@2224 1502 nodeType = elem.nodeType;
nicholas@2224 1503
nicholas@2224 1504 if ( !nodeType ) {
nicholas@2224 1505 // If no nodeType, this is expected to be an array
nicholas@2224 1506 while ( (node = elem[i++]) ) {
nicholas@2224 1507 // Do not traverse comment nodes
nicholas@2224 1508 ret += getText( node );
nicholas@2224 1509 }
nicholas@2224 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nicholas@2224 1511 // Use textContent for elements
nicholas@2224 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nicholas@2224 1513 if ( typeof elem.textContent === "string" ) {
nicholas@2224 1514 return elem.textContent;
nicholas@2224 1515 } else {
nicholas@2224 1516 // Traverse its children
nicholas@2224 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nicholas@2224 1518 ret += getText( elem );
nicholas@2224 1519 }
nicholas@2224 1520 }
nicholas@2224 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nicholas@2224 1522 return elem.nodeValue;
nicholas@2224 1523 }
nicholas@2224 1524 // Do not include comment or processing instruction nodes
nicholas@2224 1525
nicholas@2224 1526 return ret;
nicholas@2224 1527 };
nicholas@2224 1528
nicholas@2224 1529 Expr = Sizzle.selectors = {
nicholas@2224 1530
nicholas@2224 1531 // Can be adjusted by the user
nicholas@2224 1532 cacheLength: 50,
nicholas@2224 1533
nicholas@2224 1534 createPseudo: markFunction,
nicholas@2224 1535
nicholas@2224 1536 match: matchExpr,
nicholas@2224 1537
nicholas@2224 1538 attrHandle: {},
nicholas@2224 1539
nicholas@2224 1540 find: {},
nicholas@2224 1541
nicholas@2224 1542 relative: {
nicholas@2224 1543 ">": { dir: "parentNode", first: true },
nicholas@2224 1544 " ": { dir: "parentNode" },
nicholas@2224 1545 "+": { dir: "previousSibling", first: true },
nicholas@2224 1546 "~": { dir: "previousSibling" }
nicholas@2224 1547 },
nicholas@2224 1548
nicholas@2224 1549 preFilter: {
nicholas@2224 1550 "ATTR": function( match ) {
nicholas@2224 1551 match[1] = match[1].replace( runescape, funescape );
nicholas@2224 1552
nicholas@2224 1553 // Move the given value to match[3] whether quoted or unquoted
nicholas@2224 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nicholas@2224 1555
nicholas@2224 1556 if ( match[2] === "~=" ) {
nicholas@2224 1557 match[3] = " " + match[3] + " ";
nicholas@2224 1558 }
nicholas@2224 1559
nicholas@2224 1560 return match.slice( 0, 4 );
nicholas@2224 1561 },
nicholas@2224 1562
nicholas@2224 1563 "CHILD": function( match ) {
nicholas@2224 1564 /* matches from matchExpr["CHILD"]
nicholas@2224 1565 1 type (only|nth|...)
nicholas@2224 1566 2 what (child|of-type)
nicholas@2224 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nicholas@2224 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nicholas@2224 1569 5 sign of xn-component
nicholas@2224 1570 6 x of xn-component
nicholas@2224 1571 7 sign of y-component
nicholas@2224 1572 8 y of y-component
nicholas@2224 1573 */
nicholas@2224 1574 match[1] = match[1].toLowerCase();
nicholas@2224 1575
nicholas@2224 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nicholas@2224 1577 // nth-* requires argument
nicholas@2224 1578 if ( !match[3] ) {
nicholas@2224 1579 Sizzle.error( match[0] );
nicholas@2224 1580 }
nicholas@2224 1581
nicholas@2224 1582 // numeric x and y parameters for Expr.filter.CHILD
nicholas@2224 1583 // remember that false/true cast respectively to 0/1
nicholas@2224 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nicholas@2224 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nicholas@2224 1586
nicholas@2224 1587 // other types prohibit arguments
nicholas@2224 1588 } else if ( match[3] ) {
nicholas@2224 1589 Sizzle.error( match[0] );
nicholas@2224 1590 }
nicholas@2224 1591
nicholas@2224 1592 return match;
nicholas@2224 1593 },
nicholas@2224 1594
nicholas@2224 1595 "PSEUDO": function( match ) {
nicholas@2224 1596 var excess,
nicholas@2224 1597 unquoted = !match[6] && match[2];
nicholas@2224 1598
nicholas@2224 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nicholas@2224 1600 return null;
nicholas@2224 1601 }
nicholas@2224 1602
nicholas@2224 1603 // Accept quoted arguments as-is
nicholas@2224 1604 if ( match[3] ) {
nicholas@2224 1605 match[2] = match[4] || match[5] || "";
nicholas@2224 1606
nicholas@2224 1607 // Strip excess characters from unquoted arguments
nicholas@2224 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nicholas@2224 1609 // Get excess from tokenize (recursively)
nicholas@2224 1610 (excess = tokenize( unquoted, true )) &&
nicholas@2224 1611 // advance to the next closing parenthesis
nicholas@2224 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nicholas@2224 1613
nicholas@2224 1614 // excess is a negative index
nicholas@2224 1615 match[0] = match[0].slice( 0, excess );
nicholas@2224 1616 match[2] = unquoted.slice( 0, excess );
nicholas@2224 1617 }
nicholas@2224 1618
nicholas@2224 1619 // Return only captures needed by the pseudo filter method (type and argument)
nicholas@2224 1620 return match.slice( 0, 3 );
nicholas@2224 1621 }
nicholas@2224 1622 },
nicholas@2224 1623
nicholas@2224 1624 filter: {
nicholas@2224 1625
nicholas@2224 1626 "TAG": function( nodeNameSelector ) {
nicholas@2224 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nicholas@2224 1628 return nodeNameSelector === "*" ?
nicholas@2224 1629 function() { return true; } :
nicholas@2224 1630 function( elem ) {
nicholas@2224 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nicholas@2224 1632 };
nicholas@2224 1633 },
nicholas@2224 1634
nicholas@2224 1635 "CLASS": function( className ) {
nicholas@2224 1636 var pattern = classCache[ className + " " ];
nicholas@2224 1637
nicholas@2224 1638 return pattern ||
nicholas@2224 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nicholas@2224 1640 classCache( className, function( elem ) {
nicholas@2224 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nicholas@2224 1642 });
nicholas@2224 1643 },
nicholas@2224 1644
nicholas@2224 1645 "ATTR": function( name, operator, check ) {
nicholas@2224 1646 return function( elem ) {
nicholas@2224 1647 var result = Sizzle.attr( elem, name );
nicholas@2224 1648
nicholas@2224 1649 if ( result == null ) {
nicholas@2224 1650 return operator === "!=";
nicholas@2224 1651 }
nicholas@2224 1652 if ( !operator ) {
nicholas@2224 1653 return true;
nicholas@2224 1654 }
nicholas@2224 1655
nicholas@2224 1656 result += "";
nicholas@2224 1657
nicholas@2224 1658 return operator === "=" ? result === check :
nicholas@2224 1659 operator === "!=" ? result !== check :
nicholas@2224 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nicholas@2224 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nicholas@2224 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nicholas@2224 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nicholas@2224 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nicholas@2224 1665 false;
nicholas@2224 1666 };
nicholas@2224 1667 },
nicholas@2224 1668
nicholas@2224 1669 "CHILD": function( type, what, argument, first, last ) {
nicholas@2224 1670 var simple = type.slice( 0, 3 ) !== "nth",
nicholas@2224 1671 forward = type.slice( -4 ) !== "last",
nicholas@2224 1672 ofType = what === "of-type";
nicholas@2224 1673
nicholas@2224 1674 return first === 1 && last === 0 ?
nicholas@2224 1675
nicholas@2224 1676 // Shortcut for :nth-*(n)
nicholas@2224 1677 function( elem ) {
nicholas@2224 1678 return !!elem.parentNode;
nicholas@2224 1679 } :
nicholas@2224 1680
nicholas@2224 1681 function( elem, context, xml ) {
nicholas@2224 1682 var cache, outerCache, node, diff, nodeIndex, start,
nicholas@2224 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nicholas@2224 1684 parent = elem.parentNode,
nicholas@2224 1685 name = ofType && elem.nodeName.toLowerCase(),
nicholas@2224 1686 useCache = !xml && !ofType;
nicholas@2224 1687
nicholas@2224 1688 if ( parent ) {
nicholas@2224 1689
nicholas@2224 1690 // :(first|last|only)-(child|of-type)
nicholas@2224 1691 if ( simple ) {
nicholas@2224 1692 while ( dir ) {
nicholas@2224 1693 node = elem;
nicholas@2224 1694 while ( (node = node[ dir ]) ) {
nicholas@2224 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nicholas@2224 1696 return false;
nicholas@2224 1697 }
nicholas@2224 1698 }
nicholas@2224 1699 // Reverse direction for :only-* (if we haven't yet done so)
nicholas@2224 1700 start = dir = type === "only" && !start && "nextSibling";
nicholas@2224 1701 }
nicholas@2224 1702 return true;
nicholas@2224 1703 }
nicholas@2224 1704
nicholas@2224 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nicholas@2224 1706
nicholas@2224 1707 // non-xml :nth-child(...) stores cache data on `parent`
nicholas@2224 1708 if ( forward && useCache ) {
nicholas@2224 1709 // Seek `elem` from a previously-cached index
nicholas@2224 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nicholas@2224 1711 cache = outerCache[ type ] || [];
nicholas@2224 1712 nodeIndex = cache[0] === dirruns && cache[1];
nicholas@2224 1713 diff = cache[0] === dirruns && cache[2];
nicholas@2224 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nicholas@2224 1715
nicholas@2224 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nicholas@2224 1717
nicholas@2224 1718 // Fallback to seeking `elem` from the start
nicholas@2224 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nicholas@2224 1720
nicholas@2224 1721 // When found, cache indexes on `parent` and break
nicholas@2224 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nicholas@2224 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nicholas@2224 1724 break;
nicholas@2224 1725 }
nicholas@2224 1726 }
nicholas@2224 1727
nicholas@2224 1728 // Use previously-cached element index if available
nicholas@2224 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nicholas@2224 1730 diff = cache[1];
nicholas@2224 1731
nicholas@2224 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nicholas@2224 1733 } else {
nicholas@2224 1734 // Use the same loop as above to seek `elem` from the start
nicholas@2224 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nicholas@2224 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nicholas@2224 1737
nicholas@2224 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nicholas@2224 1739 // Cache the index of each encountered element
nicholas@2224 1740 if ( useCache ) {
nicholas@2224 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nicholas@2224 1742 }
nicholas@2224 1743
nicholas@2224 1744 if ( node === elem ) {
nicholas@2224 1745 break;
nicholas@2224 1746 }
nicholas@2224 1747 }
nicholas@2224 1748 }
nicholas@2224 1749 }
nicholas@2224 1750
nicholas@2224 1751 // Incorporate the offset, then check against cycle size
nicholas@2224 1752 diff -= last;
nicholas@2224 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nicholas@2224 1754 }
nicholas@2224 1755 };
nicholas@2224 1756 },
nicholas@2224 1757
nicholas@2224 1758 "PSEUDO": function( pseudo, argument ) {
nicholas@2224 1759 // pseudo-class names are case-insensitive
nicholas@2224 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nicholas@2224 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nicholas@2224 1762 // Remember that setFilters inherits from pseudos
nicholas@2224 1763 var args,
nicholas@2224 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nicholas@2224 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nicholas@2224 1766
nicholas@2224 1767 // The user may use createPseudo to indicate that
nicholas@2224 1768 // arguments are needed to create the filter function
nicholas@2224 1769 // just as Sizzle does
nicholas@2224 1770 if ( fn[ expando ] ) {
nicholas@2224 1771 return fn( argument );
nicholas@2224 1772 }
nicholas@2224 1773
nicholas@2224 1774 // But maintain support for old signatures
nicholas@2224 1775 if ( fn.length > 1 ) {
nicholas@2224 1776 args = [ pseudo, pseudo, "", argument ];
nicholas@2224 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nicholas@2224 1778 markFunction(function( seed, matches ) {
nicholas@2224 1779 var idx,
nicholas@2224 1780 matched = fn( seed, argument ),
nicholas@2224 1781 i = matched.length;
nicholas@2224 1782 while ( i-- ) {
nicholas@2224 1783 idx = indexOf( seed, matched[i] );
nicholas@2224 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nicholas@2224 1785 }
nicholas@2224 1786 }) :
nicholas@2224 1787 function( elem ) {
nicholas@2224 1788 return fn( elem, 0, args );
nicholas@2224 1789 };
nicholas@2224 1790 }
nicholas@2224 1791
nicholas@2224 1792 return fn;
nicholas@2224 1793 }
nicholas@2224 1794 },
nicholas@2224 1795
nicholas@2224 1796 pseudos: {
nicholas@2224 1797 // Potentially complex pseudos
nicholas@2224 1798 "not": markFunction(function( selector ) {
nicholas@2224 1799 // Trim the selector passed to compile
nicholas@2224 1800 // to avoid treating leading and trailing
nicholas@2224 1801 // spaces as combinators
nicholas@2224 1802 var input = [],
nicholas@2224 1803 results = [],
nicholas@2224 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nicholas@2224 1805
nicholas@2224 1806 return matcher[ expando ] ?
nicholas@2224 1807 markFunction(function( seed, matches, context, xml ) {
nicholas@2224 1808 var elem,
nicholas@2224 1809 unmatched = matcher( seed, null, xml, [] ),
nicholas@2224 1810 i = seed.length;
nicholas@2224 1811
nicholas@2224 1812 // Match elements unmatched by `matcher`
nicholas@2224 1813 while ( i-- ) {
nicholas@2224 1814 if ( (elem = unmatched[i]) ) {
nicholas@2224 1815 seed[i] = !(matches[i] = elem);
nicholas@2224 1816 }
nicholas@2224 1817 }
nicholas@2224 1818 }) :
nicholas@2224 1819 function( elem, context, xml ) {
nicholas@2224 1820 input[0] = elem;
nicholas@2224 1821 matcher( input, null, xml, results );
nicholas@2224 1822 // Don't keep the element (issue #299)
nicholas@2224 1823 input[0] = null;
nicholas@2224 1824 return !results.pop();
nicholas@2224 1825 };
nicholas@2224 1826 }),
nicholas@2224 1827
nicholas@2224 1828 "has": markFunction(function( selector ) {
nicholas@2224 1829 return function( elem ) {
nicholas@2224 1830 return Sizzle( selector, elem ).length > 0;
nicholas@2224 1831 };
nicholas@2224 1832 }),
nicholas@2224 1833
nicholas@2224 1834 "contains": markFunction(function( text ) {
nicholas@2224 1835 text = text.replace( runescape, funescape );
nicholas@2224 1836 return function( elem ) {
nicholas@2224 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nicholas@2224 1838 };
nicholas@2224 1839 }),
nicholas@2224 1840
nicholas@2224 1841 // "Whether an element is represented by a :lang() selector
nicholas@2224 1842 // is based solely on the element's language value
nicholas@2224 1843 // being equal to the identifier C,
nicholas@2224 1844 // or beginning with the identifier C immediately followed by "-".
nicholas@2224 1845 // The matching of C against the element's language value is performed case-insensitively.
nicholas@2224 1846 // The identifier C does not have to be a valid language name."
nicholas@2224 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nicholas@2224 1848 "lang": markFunction( function( lang ) {
nicholas@2224 1849 // lang value must be a valid identifier
nicholas@2224 1850 if ( !ridentifier.test(lang || "") ) {
nicholas@2224 1851 Sizzle.error( "unsupported lang: " + lang );
nicholas@2224 1852 }
nicholas@2224 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nicholas@2224 1854 return function( elem ) {
nicholas@2224 1855 var elemLang;
nicholas@2224 1856 do {
nicholas@2224 1857 if ( (elemLang = documentIsHTML ?
nicholas@2224 1858 elem.lang :
nicholas@2224 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nicholas@2224 1860
nicholas@2224 1861 elemLang = elemLang.toLowerCase();
nicholas@2224 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nicholas@2224 1863 }
nicholas@2224 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nicholas@2224 1865 return false;
nicholas@2224 1866 };
nicholas@2224 1867 }),
nicholas@2224 1868
nicholas@2224 1869 // Miscellaneous
nicholas@2224 1870 "target": function( elem ) {
nicholas@2224 1871 var hash = window.location && window.location.hash;
nicholas@2224 1872 return hash && hash.slice( 1 ) === elem.id;
nicholas@2224 1873 },
nicholas@2224 1874
nicholas@2224 1875 "root": function( elem ) {
nicholas@2224 1876 return elem === docElem;
nicholas@2224 1877 },
nicholas@2224 1878
nicholas@2224 1879 "focus": function( elem ) {
nicholas@2224 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nicholas@2224 1881 },
nicholas@2224 1882
nicholas@2224 1883 // Boolean properties
nicholas@2224 1884 "enabled": function( elem ) {
nicholas@2224 1885 return elem.disabled === false;
nicholas@2224 1886 },
nicholas@2224 1887
nicholas@2224 1888 "disabled": function( elem ) {
nicholas@2224 1889 return elem.disabled === true;
nicholas@2224 1890 },
nicholas@2224 1891
nicholas@2224 1892 "checked": function( elem ) {
nicholas@2224 1893 // In CSS3, :checked should return both checked and selected elements
nicholas@2224 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nicholas@2224 1895 var nodeName = elem.nodeName.toLowerCase();
nicholas@2224 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nicholas@2224 1897 },
nicholas@2224 1898
nicholas@2224 1899 "selected": function( elem ) {
nicholas@2224 1900 // Accessing this property makes selected-by-default
nicholas@2224 1901 // options in Safari work properly
nicholas@2224 1902 if ( elem.parentNode ) {
nicholas@2224 1903 elem.parentNode.selectedIndex;
nicholas@2224 1904 }
nicholas@2224 1905
nicholas@2224 1906 return elem.selected === true;
nicholas@2224 1907 },
nicholas@2224 1908
nicholas@2224 1909 // Contents
nicholas@2224 1910 "empty": function( elem ) {
nicholas@2224 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nicholas@2224 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nicholas@2224 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nicholas@2224 1914 // nodeType < 6 works because attributes (2) do not appear as children
nicholas@2224 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nicholas@2224 1916 if ( elem.nodeType < 6 ) {
nicholas@2224 1917 return false;
nicholas@2224 1918 }
nicholas@2224 1919 }
nicholas@2224 1920 return true;
nicholas@2224 1921 },
nicholas@2224 1922
nicholas@2224 1923 "parent": function( elem ) {
nicholas@2224 1924 return !Expr.pseudos["empty"]( elem );
nicholas@2224 1925 },
nicholas@2224 1926
nicholas@2224 1927 // Element/input types
nicholas@2224 1928 "header": function( elem ) {
nicholas@2224 1929 return rheader.test( elem.nodeName );
nicholas@2224 1930 },
nicholas@2224 1931
nicholas@2224 1932 "input": function( elem ) {
nicholas@2224 1933 return rinputs.test( elem.nodeName );
nicholas@2224 1934 },
nicholas@2224 1935
nicholas@2224 1936 "button": function( elem ) {
nicholas@2224 1937 var name = elem.nodeName.toLowerCase();
nicholas@2224 1938 return name === "input" && elem.type === "button" || name === "button";
nicholas@2224 1939 },
nicholas@2224 1940
nicholas@2224 1941 "text": function( elem ) {
nicholas@2224 1942 var attr;
nicholas@2224 1943 return elem.nodeName.toLowerCase() === "input" &&
nicholas@2224 1944 elem.type === "text" &&
nicholas@2224 1945
nicholas@2224 1946 // Support: IE<8
nicholas@2224 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nicholas@2224 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nicholas@2224 1949 },
nicholas@2224 1950
nicholas@2224 1951 // Position-in-collection
nicholas@2224 1952 "first": createPositionalPseudo(function() {
nicholas@2224 1953 return [ 0 ];
nicholas@2224 1954 }),
nicholas@2224 1955
nicholas@2224 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@2224 1957 return [ length - 1 ];
nicholas@2224 1958 }),
nicholas@2224 1959
nicholas@2224 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@2224 1961 return [ argument < 0 ? argument + length : argument ];
nicholas@2224 1962 }),
nicholas@2224 1963
nicholas@2224 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@2224 1965 var i = 0;
nicholas@2224 1966 for ( ; i < length; i += 2 ) {
nicholas@2224 1967 matchIndexes.push( i );
nicholas@2224 1968 }
nicholas@2224 1969 return matchIndexes;
nicholas@2224 1970 }),
nicholas@2224 1971
nicholas@2224 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nicholas@2224 1973 var i = 1;
nicholas@2224 1974 for ( ; i < length; i += 2 ) {
nicholas@2224 1975 matchIndexes.push( i );
nicholas@2224 1976 }
nicholas@2224 1977 return matchIndexes;
nicholas@2224 1978 }),
nicholas@2224 1979
nicholas@2224 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@2224 1981 var i = argument < 0 ? argument + length : argument;
nicholas@2224 1982 for ( ; --i >= 0; ) {
nicholas@2224 1983 matchIndexes.push( i );
nicholas@2224 1984 }
nicholas@2224 1985 return matchIndexes;
nicholas@2224 1986 }),
nicholas@2224 1987
nicholas@2224 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nicholas@2224 1989 var i = argument < 0 ? argument + length : argument;
nicholas@2224 1990 for ( ; ++i < length; ) {
nicholas@2224 1991 matchIndexes.push( i );
nicholas@2224 1992 }
nicholas@2224 1993 return matchIndexes;
nicholas@2224 1994 })
nicholas@2224 1995 }
nicholas@2224 1996 };
nicholas@2224 1997
nicholas@2224 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nicholas@2224 1999
nicholas@2224 2000 // Add button/input type pseudos
nicholas@2224 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nicholas@2224 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nicholas@2224 2003 }
nicholas@2224 2004 for ( i in { submit: true, reset: true } ) {
nicholas@2224 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nicholas@2224 2006 }
nicholas@2224 2007
nicholas@2224 2008 // Easy API for creating new setFilters
nicholas@2224 2009 function setFilters() {}
nicholas@2224 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nicholas@2224 2011 Expr.setFilters = new setFilters();
nicholas@2224 2012
nicholas@2224 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nicholas@2224 2014 var matched, match, tokens, type,
nicholas@2224 2015 soFar, groups, preFilters,
nicholas@2224 2016 cached = tokenCache[ selector + " " ];
nicholas@2224 2017
nicholas@2224 2018 if ( cached ) {
nicholas@2224 2019 return parseOnly ? 0 : cached.slice( 0 );
nicholas@2224 2020 }
nicholas@2224 2021
nicholas@2224 2022 soFar = selector;
nicholas@2224 2023 groups = [];
nicholas@2224 2024 preFilters = Expr.preFilter;
nicholas@2224 2025
nicholas@2224 2026 while ( soFar ) {
nicholas@2224 2027
nicholas@2224 2028 // Comma and first run
nicholas@2224 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nicholas@2224 2030 if ( match ) {
nicholas@2224 2031 // Don't consume trailing commas as valid
nicholas@2224 2032 soFar = soFar.slice( match[0].length ) || soFar;
nicholas@2224 2033 }
nicholas@2224 2034 groups.push( (tokens = []) );
nicholas@2224 2035 }
nicholas@2224 2036
nicholas@2224 2037 matched = false;
nicholas@2224 2038
nicholas@2224 2039 // Combinators
nicholas@2224 2040 if ( (match = rcombinators.exec( soFar )) ) {
nicholas@2224 2041 matched = match.shift();
nicholas@2224 2042 tokens.push({
nicholas@2224 2043 value: matched,
nicholas@2224 2044 // Cast descendant combinators to space
nicholas@2224 2045 type: match[0].replace( rtrim, " " )
nicholas@2224 2046 });
nicholas@2224 2047 soFar = soFar.slice( matched.length );
nicholas@2224 2048 }
nicholas@2224 2049
nicholas@2224 2050 // Filters
nicholas@2224 2051 for ( type in Expr.filter ) {
nicholas@2224 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nicholas@2224 2053 (match = preFilters[ type ]( match ))) ) {
nicholas@2224 2054 matched = match.shift();
nicholas@2224 2055 tokens.push({
nicholas@2224 2056 value: matched,
nicholas@2224 2057 type: type,
nicholas@2224 2058 matches: match
nicholas@2224 2059 });
nicholas@2224 2060 soFar = soFar.slice( matched.length );
nicholas@2224 2061 }
nicholas@2224 2062 }
nicholas@2224 2063
nicholas@2224 2064 if ( !matched ) {
nicholas@2224 2065 break;
nicholas@2224 2066 }
nicholas@2224 2067 }
nicholas@2224 2068
nicholas@2224 2069 // Return the length of the invalid excess
nicholas@2224 2070 // if we're just parsing
nicholas@2224 2071 // Otherwise, throw an error or return tokens
nicholas@2224 2072 return parseOnly ?
nicholas@2224 2073 soFar.length :
nicholas@2224 2074 soFar ?
nicholas@2224 2075 Sizzle.error( selector ) :
nicholas@2224 2076 // Cache the tokens
nicholas@2224 2077 tokenCache( selector, groups ).slice( 0 );
nicholas@2224 2078 };
nicholas@2224 2079
nicholas@2224 2080 function toSelector( tokens ) {
nicholas@2224 2081 var i = 0,
nicholas@2224 2082 len = tokens.length,
nicholas@2224 2083 selector = "";
nicholas@2224 2084 for ( ; i < len; i++ ) {
nicholas@2224 2085 selector += tokens[i].value;
nicholas@2224 2086 }
nicholas@2224 2087 return selector;
nicholas@2224 2088 }
nicholas@2224 2089
nicholas@2224 2090 function addCombinator( matcher, combinator, base ) {
nicholas@2224 2091 var dir = combinator.dir,
nicholas@2224 2092 checkNonElements = base && dir === "parentNode",
nicholas@2224 2093 doneName = done++;
nicholas@2224 2094
nicholas@2224 2095 return combinator.first ?
nicholas@2224 2096 // Check against closest ancestor/preceding element
nicholas@2224 2097 function( elem, context, xml ) {
nicholas@2224 2098 while ( (elem = elem[ dir ]) ) {
nicholas@2224 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@2224 2100 return matcher( elem, context, xml );
nicholas@2224 2101 }
nicholas@2224 2102 }
nicholas@2224 2103 } :
nicholas@2224 2104
nicholas@2224 2105 // Check against all ancestor/preceding elements
nicholas@2224 2106 function( elem, context, xml ) {
nicholas@2224 2107 var oldCache, outerCache,
nicholas@2224 2108 newCache = [ dirruns, doneName ];
nicholas@2224 2109
nicholas@2224 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nicholas@2224 2111 if ( xml ) {
nicholas@2224 2112 while ( (elem = elem[ dir ]) ) {
nicholas@2224 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@2224 2114 if ( matcher( elem, context, xml ) ) {
nicholas@2224 2115 return true;
nicholas@2224 2116 }
nicholas@2224 2117 }
nicholas@2224 2118 }
nicholas@2224 2119 } else {
nicholas@2224 2120 while ( (elem = elem[ dir ]) ) {
nicholas@2224 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nicholas@2224 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nicholas@2224 2123 if ( (oldCache = outerCache[ dir ]) &&
nicholas@2224 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nicholas@2224 2125
nicholas@2224 2126 // Assign to newCache so results back-propagate to previous elements
nicholas@2224 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nicholas@2224 2128 } else {
nicholas@2224 2129 // Reuse newcache so results back-propagate to previous elements
nicholas@2224 2130 outerCache[ dir ] = newCache;
nicholas@2224 2131
nicholas@2224 2132 // A match means we're done; a fail means we have to keep checking
nicholas@2224 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nicholas@2224 2134 return true;
nicholas@2224 2135 }
nicholas@2224 2136 }
nicholas@2224 2137 }
nicholas@2224 2138 }
nicholas@2224 2139 }
nicholas@2224 2140 };
nicholas@2224 2141 }
nicholas@2224 2142
nicholas@2224 2143 function elementMatcher( matchers ) {
nicholas@2224 2144 return matchers.length > 1 ?
nicholas@2224 2145 function( elem, context, xml ) {
nicholas@2224 2146 var i = matchers.length;
nicholas@2224 2147 while ( i-- ) {
nicholas@2224 2148 if ( !matchers[i]( elem, context, xml ) ) {
nicholas@2224 2149 return false;
nicholas@2224 2150 }
nicholas@2224 2151 }
nicholas@2224 2152 return true;
nicholas@2224 2153 } :
nicholas@2224 2154 matchers[0];
nicholas@2224 2155 }
nicholas@2224 2156
nicholas@2224 2157 function multipleContexts( selector, contexts, results ) {
nicholas@2224 2158 var i = 0,
nicholas@2224 2159 len = contexts.length;
nicholas@2224 2160 for ( ; i < len; i++ ) {
nicholas@2224 2161 Sizzle( selector, contexts[i], results );
nicholas@2224 2162 }
nicholas@2224 2163 return results;
nicholas@2224 2164 }
nicholas@2224 2165
nicholas@2224 2166 function condense( unmatched, map, filter, context, xml ) {
nicholas@2224 2167 var elem,
nicholas@2224 2168 newUnmatched = [],
nicholas@2224 2169 i = 0,
nicholas@2224 2170 len = unmatched.length,
nicholas@2224 2171 mapped = map != null;
nicholas@2224 2172
nicholas@2224 2173 for ( ; i < len; i++ ) {
nicholas@2224 2174 if ( (elem = unmatched[i]) ) {
nicholas@2224 2175 if ( !filter || filter( elem, context, xml ) ) {
nicholas@2224 2176 newUnmatched.push( elem );
nicholas@2224 2177 if ( mapped ) {
nicholas@2224 2178 map.push( i );
nicholas@2224 2179 }
nicholas@2224 2180 }
nicholas@2224 2181 }
nicholas@2224 2182 }
nicholas@2224 2183
nicholas@2224 2184 return newUnmatched;
nicholas@2224 2185 }
nicholas@2224 2186
nicholas@2224 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nicholas@2224 2188 if ( postFilter && !postFilter[ expando ] ) {
nicholas@2224 2189 postFilter = setMatcher( postFilter );
nicholas@2224 2190 }
nicholas@2224 2191 if ( postFinder && !postFinder[ expando ] ) {
nicholas@2224 2192 postFinder = setMatcher( postFinder, postSelector );
nicholas@2224 2193 }
nicholas@2224 2194 return markFunction(function( seed, results, context, xml ) {
nicholas@2224 2195 var temp, i, elem,
nicholas@2224 2196 preMap = [],
nicholas@2224 2197 postMap = [],
nicholas@2224 2198 preexisting = results.length,
nicholas@2224 2199
nicholas@2224 2200 // Get initial elements from seed or context
nicholas@2224 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nicholas@2224 2202
nicholas@2224 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nicholas@2224 2204 matcherIn = preFilter && ( seed || !selector ) ?
nicholas@2224 2205 condense( elems, preMap, preFilter, context, xml ) :
nicholas@2224 2206 elems,
nicholas@2224 2207
nicholas@2224 2208 matcherOut = matcher ?
nicholas@2224 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nicholas@2224 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nicholas@2224 2211
nicholas@2224 2212 // ...intermediate processing is necessary
nicholas@2224 2213 [] :
nicholas@2224 2214
nicholas@2224 2215 // ...otherwise use results directly
nicholas@2224 2216 results :
nicholas@2224 2217 matcherIn;
nicholas@2224 2218
nicholas@2224 2219 // Find primary matches
nicholas@2224 2220 if ( matcher ) {
nicholas@2224 2221 matcher( matcherIn, matcherOut, context, xml );
nicholas@2224 2222 }
nicholas@2224 2223
nicholas@2224 2224 // Apply postFilter
nicholas@2224 2225 if ( postFilter ) {
nicholas@2224 2226 temp = condense( matcherOut, postMap );
nicholas@2224 2227 postFilter( temp, [], context, xml );
nicholas@2224 2228
nicholas@2224 2229 // Un-match failing elements by moving them back to matcherIn
nicholas@2224 2230 i = temp.length;
nicholas@2224 2231 while ( i-- ) {
nicholas@2224 2232 if ( (elem = temp[i]) ) {
nicholas@2224 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nicholas@2224 2234 }
nicholas@2224 2235 }
nicholas@2224 2236 }
nicholas@2224 2237
nicholas@2224 2238 if ( seed ) {
nicholas@2224 2239 if ( postFinder || preFilter ) {
nicholas@2224 2240 if ( postFinder ) {
nicholas@2224 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nicholas@2224 2242 temp = [];
nicholas@2224 2243 i = matcherOut.length;
nicholas@2224 2244 while ( i-- ) {
nicholas@2224 2245 if ( (elem = matcherOut[i]) ) {
nicholas@2224 2246 // Restore matcherIn since elem is not yet a final match
nicholas@2224 2247 temp.push( (matcherIn[i] = elem) );
nicholas@2224 2248 }
nicholas@2224 2249 }
nicholas@2224 2250 postFinder( null, (matcherOut = []), temp, xml );
nicholas@2224 2251 }
nicholas@2224 2252
nicholas@2224 2253 // Move matched elements from seed to results to keep them synchronized
nicholas@2224 2254 i = matcherOut.length;
nicholas@2224 2255 while ( i-- ) {
nicholas@2224 2256 if ( (elem = matcherOut[i]) &&
nicholas@2224 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nicholas@2224 2258
nicholas@2224 2259 seed[temp] = !(results[temp] = elem);
nicholas@2224 2260 }
nicholas@2224 2261 }
nicholas@2224 2262 }
nicholas@2224 2263
nicholas@2224 2264 // Add elements to results, through postFinder if defined
nicholas@2224 2265 } else {
nicholas@2224 2266 matcherOut = condense(
nicholas@2224 2267 matcherOut === results ?
nicholas@2224 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nicholas@2224 2269 matcherOut
nicholas@2224 2270 );
nicholas@2224 2271 if ( postFinder ) {
nicholas@2224 2272 postFinder( null, results, matcherOut, xml );
nicholas@2224 2273 } else {
nicholas@2224 2274 push.apply( results, matcherOut );
nicholas@2224 2275 }
nicholas@2224 2276 }
nicholas@2224 2277 });
nicholas@2224 2278 }
nicholas@2224 2279
nicholas@2224 2280 function matcherFromTokens( tokens ) {
nicholas@2224 2281 var checkContext, matcher, j,
nicholas@2224 2282 len = tokens.length,
nicholas@2224 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nicholas@2224 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nicholas@2224 2285 i = leadingRelative ? 1 : 0,
nicholas@2224 2286
nicholas@2224 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nicholas@2224 2288 matchContext = addCombinator( function( elem ) {
nicholas@2224 2289 return elem === checkContext;
nicholas@2224 2290 }, implicitRelative, true ),
nicholas@2224 2291 matchAnyContext = addCombinator( function( elem ) {
nicholas@2224 2292 return indexOf( checkContext, elem ) > -1;
nicholas@2224 2293 }, implicitRelative, true ),
nicholas@2224 2294 matchers = [ function( elem, context, xml ) {
nicholas@2224 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nicholas@2224 2296 (checkContext = context).nodeType ?
nicholas@2224 2297 matchContext( elem, context, xml ) :
nicholas@2224 2298 matchAnyContext( elem, context, xml ) );
nicholas@2224 2299 // Avoid hanging onto element (issue #299)
nicholas@2224 2300 checkContext = null;
nicholas@2224 2301 return ret;
nicholas@2224 2302 } ];
nicholas@2224 2303
nicholas@2224 2304 for ( ; i < len; i++ ) {
nicholas@2224 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nicholas@2224 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nicholas@2224 2307 } else {
nicholas@2224 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nicholas@2224 2309
nicholas@2224 2310 // Return special upon seeing a positional matcher
nicholas@2224 2311 if ( matcher[ expando ] ) {
nicholas@2224 2312 // Find the next relative operator (if any) for proper handling
nicholas@2224 2313 j = ++i;
nicholas@2224 2314 for ( ; j < len; j++ ) {
nicholas@2224 2315 if ( Expr.relative[ tokens[j].type ] ) {
nicholas@2224 2316 break;
nicholas@2224 2317 }
nicholas@2224 2318 }
nicholas@2224 2319 return setMatcher(
nicholas@2224 2320 i > 1 && elementMatcher( matchers ),
nicholas@2224 2321 i > 1 && toSelector(
nicholas@2224 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nicholas@2224 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nicholas@2224 2324 ).replace( rtrim, "$1" ),
nicholas@2224 2325 matcher,
nicholas@2224 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nicholas@2224 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nicholas@2224 2328 j < len && toSelector( tokens )
nicholas@2224 2329 );
nicholas@2224 2330 }
nicholas@2224 2331 matchers.push( matcher );
nicholas@2224 2332 }
nicholas@2224 2333 }
nicholas@2224 2334
nicholas@2224 2335 return elementMatcher( matchers );
nicholas@2224 2336 }
nicholas@2224 2337
nicholas@2224 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nicholas@2224 2339 var bySet = setMatchers.length > 0,
nicholas@2224 2340 byElement = elementMatchers.length > 0,
nicholas@2224 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nicholas@2224 2342 var elem, j, matcher,
nicholas@2224 2343 matchedCount = 0,
nicholas@2224 2344 i = "0",
nicholas@2224 2345 unmatched = seed && [],
nicholas@2224 2346 setMatched = [],
nicholas@2224 2347 contextBackup = outermostContext,
nicholas@2224 2348 // We must always have either seed elements or outermost context
nicholas@2224 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nicholas@2224 2350 // Use integer dirruns iff this is the outermost matcher
nicholas@2224 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nicholas@2224 2352 len = elems.length;
nicholas@2224 2353
nicholas@2224 2354 if ( outermost ) {
nicholas@2224 2355 outermostContext = context !== document && context;
nicholas@2224 2356 }
nicholas@2224 2357
nicholas@2224 2358 // Add elements passing elementMatchers directly to results
nicholas@2224 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nicholas@2224 2360 // Support: IE<9, Safari
nicholas@2224 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nicholas@2224 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nicholas@2224 2363 if ( byElement && elem ) {
nicholas@2224 2364 j = 0;
nicholas@2224 2365 while ( (matcher = elementMatchers[j++]) ) {
nicholas@2224 2366 if ( matcher( elem, context, xml ) ) {
nicholas@2224 2367 results.push( elem );
nicholas@2224 2368 break;
nicholas@2224 2369 }
nicholas@2224 2370 }
nicholas@2224 2371 if ( outermost ) {
nicholas@2224 2372 dirruns = dirrunsUnique;
nicholas@2224 2373 }
nicholas@2224 2374 }
nicholas@2224 2375
nicholas@2224 2376 // Track unmatched elements for set filters
nicholas@2224 2377 if ( bySet ) {
nicholas@2224 2378 // They will have gone through all possible matchers
nicholas@2224 2379 if ( (elem = !matcher && elem) ) {
nicholas@2224 2380 matchedCount--;
nicholas@2224 2381 }
nicholas@2224 2382
nicholas@2224 2383 // Lengthen the array for every element, matched or not
nicholas@2224 2384 if ( seed ) {
nicholas@2224 2385 unmatched.push( elem );
nicholas@2224 2386 }
nicholas@2224 2387 }
nicholas@2224 2388 }
nicholas@2224 2389
nicholas@2224 2390 // Apply set filters to unmatched elements
nicholas@2224 2391 matchedCount += i;
nicholas@2224 2392 if ( bySet && i !== matchedCount ) {
nicholas@2224 2393 j = 0;
nicholas@2224 2394 while ( (matcher = setMatchers[j++]) ) {
nicholas@2224 2395 matcher( unmatched, setMatched, context, xml );
nicholas@2224 2396 }
nicholas@2224 2397
nicholas@2224 2398 if ( seed ) {
nicholas@2224 2399 // Reintegrate element matches to eliminate the need for sorting
nicholas@2224 2400 if ( matchedCount > 0 ) {
nicholas@2224 2401 while ( i-- ) {
nicholas@2224 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nicholas@2224 2403 setMatched[i] = pop.call( results );
nicholas@2224 2404 }
nicholas@2224 2405 }
nicholas@2224 2406 }
nicholas@2224 2407
nicholas@2224 2408 // Discard index placeholder values to get only actual matches
nicholas@2224 2409 setMatched = condense( setMatched );
nicholas@2224 2410 }
nicholas@2224 2411
nicholas@2224 2412 // Add matches to results
nicholas@2224 2413 push.apply( results, setMatched );
nicholas@2224 2414
nicholas@2224 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nicholas@2224 2416 if ( outermost && !seed && setMatched.length > 0 &&
nicholas@2224 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nicholas@2224 2418
nicholas@2224 2419 Sizzle.uniqueSort( results );
nicholas@2224 2420 }
nicholas@2224 2421 }
nicholas@2224 2422
nicholas@2224 2423 // Override manipulation of globals by nested matchers
nicholas@2224 2424 if ( outermost ) {
nicholas@2224 2425 dirruns = dirrunsUnique;
nicholas@2224 2426 outermostContext = contextBackup;
nicholas@2224 2427 }
nicholas@2224 2428
nicholas@2224 2429 return unmatched;
nicholas@2224 2430 };
nicholas@2224 2431
nicholas@2224 2432 return bySet ?
nicholas@2224 2433 markFunction( superMatcher ) :
nicholas@2224 2434 superMatcher;
nicholas@2224 2435 }
nicholas@2224 2436
nicholas@2224 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nicholas@2224 2438 var i,
nicholas@2224 2439 setMatchers = [],
nicholas@2224 2440 elementMatchers = [],
nicholas@2224 2441 cached = compilerCache[ selector + " " ];
nicholas@2224 2442
nicholas@2224 2443 if ( !cached ) {
nicholas@2224 2444 // Generate a function of recursive functions that can be used to check each element
nicholas@2224 2445 if ( !match ) {
nicholas@2224 2446 match = tokenize( selector );
nicholas@2224 2447 }
nicholas@2224 2448 i = match.length;
nicholas@2224 2449 while ( i-- ) {
nicholas@2224 2450 cached = matcherFromTokens( match[i] );
nicholas@2224 2451 if ( cached[ expando ] ) {
nicholas@2224 2452 setMatchers.push( cached );
nicholas@2224 2453 } else {
nicholas@2224 2454 elementMatchers.push( cached );
nicholas@2224 2455 }
nicholas@2224 2456 }
nicholas@2224 2457
nicholas@2224 2458 // Cache the compiled function
nicholas@2224 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nicholas@2224 2460
nicholas@2224 2461 // Save selector and tokenization
nicholas@2224 2462 cached.selector = selector;
nicholas@2224 2463 }
nicholas@2224 2464 return cached;
nicholas@2224 2465 };
nicholas@2224 2466
nicholas@2224 2467 /**
nicholas@2224 2468 * A low-level selection function that works with Sizzle's compiled
nicholas@2224 2469 * selector functions
nicholas@2224 2470 * @param {String|Function} selector A selector or a pre-compiled
nicholas@2224 2471 * selector function built with Sizzle.compile
nicholas@2224 2472 * @param {Element} context
nicholas@2224 2473 * @param {Array} [results]
nicholas@2224 2474 * @param {Array} [seed] A set of elements to match against
nicholas@2224 2475 */
nicholas@2224 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nicholas@2224 2477 var i, tokens, token, type, find,
nicholas@2224 2478 compiled = typeof selector === "function" && selector,
nicholas@2224 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nicholas@2224 2480
nicholas@2224 2481 results = results || [];
nicholas@2224 2482
nicholas@2224 2483 // Try to minimize operations if there is no seed and only one group
nicholas@2224 2484 if ( match.length === 1 ) {
nicholas@2224 2485
nicholas@2224 2486 // Take a shortcut and set the context if the root selector is an ID
nicholas@2224 2487 tokens = match[0] = match[0].slice( 0 );
nicholas@2224 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nicholas@2224 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nicholas@2224 2490 Expr.relative[ tokens[1].type ] ) {
nicholas@2224 2491
nicholas@2224 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nicholas@2224 2493 if ( !context ) {
nicholas@2224 2494 return results;
nicholas@2224 2495
nicholas@2224 2496 // Precompiled matchers will still verify ancestry, so step up a level
nicholas@2224 2497 } else if ( compiled ) {
nicholas@2224 2498 context = context.parentNode;
nicholas@2224 2499 }
nicholas@2224 2500
nicholas@2224 2501 selector = selector.slice( tokens.shift().value.length );
nicholas@2224 2502 }
nicholas@2224 2503
nicholas@2224 2504 // Fetch a seed set for right-to-left matching
nicholas@2224 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nicholas@2224 2506 while ( i-- ) {
nicholas@2224 2507 token = tokens[i];
nicholas@2224 2508
nicholas@2224 2509 // Abort if we hit a combinator
nicholas@2224 2510 if ( Expr.relative[ (type = token.type) ] ) {
nicholas@2224 2511 break;
nicholas@2224 2512 }
nicholas@2224 2513 if ( (find = Expr.find[ type ]) ) {
nicholas@2224 2514 // Search, expanding context for leading sibling combinators
nicholas@2224 2515 if ( (seed = find(
nicholas@2224 2516 token.matches[0].replace( runescape, funescape ),
nicholas@2224 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nicholas@2224 2518 )) ) {
nicholas@2224 2519
nicholas@2224 2520 // If seed is empty or no tokens remain, we can return early
nicholas@2224 2521 tokens.splice( i, 1 );
nicholas@2224 2522 selector = seed.length && toSelector( tokens );
nicholas@2224 2523 if ( !selector ) {
nicholas@2224 2524 push.apply( results, seed );
nicholas@2224 2525 return results;
nicholas@2224 2526 }
nicholas@2224 2527
nicholas@2224 2528 break;
nicholas@2224 2529 }
nicholas@2224 2530 }
nicholas@2224 2531 }
nicholas@2224 2532 }
nicholas@2224 2533
nicholas@2224 2534 // Compile and execute a filtering function if one is not provided
nicholas@2224 2535 // Provide `match` to avoid retokenization if we modified the selector above
nicholas@2224 2536 ( compiled || compile( selector, match ) )(
nicholas@2224 2537 seed,
nicholas@2224 2538 context,
nicholas@2224 2539 !documentIsHTML,
nicholas@2224 2540 results,
nicholas@2224 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nicholas@2224 2542 );
nicholas@2224 2543 return results;
nicholas@2224 2544 };
nicholas@2224 2545
nicholas@2224 2546 // One-time assignments
nicholas@2224 2547
nicholas@2224 2548 // Sort stability
nicholas@2224 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nicholas@2224 2550
nicholas@2224 2551 // Support: Chrome 14-35+
nicholas@2224 2552 // Always assume duplicates if they aren't passed to the comparison function
nicholas@2224 2553 support.detectDuplicates = !!hasDuplicate;
nicholas@2224 2554
nicholas@2224 2555 // Initialize against the default document
nicholas@2224 2556 setDocument();
nicholas@2224 2557
nicholas@2224 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nicholas@2224 2559 // Detached nodes confoundingly follow *each other*
nicholas@2224 2560 support.sortDetached = assert(function( div1 ) {
nicholas@2224 2561 // Should return 1, but returns 4 (following)
nicholas@2224 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nicholas@2224 2563 });
nicholas@2224 2564
nicholas@2224 2565 // Support: IE<8
nicholas@2224 2566 // Prevent attribute/property "interpolation"
nicholas@2224 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nicholas@2224 2568 if ( !assert(function( div ) {
nicholas@2224 2569 div.innerHTML = "<a href='#'></a>";
nicholas@2224 2570 return div.firstChild.getAttribute("href") === "#" ;
nicholas@2224 2571 }) ) {
nicholas@2224 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nicholas@2224 2573 if ( !isXML ) {
nicholas@2224 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nicholas@2224 2575 }
nicholas@2224 2576 });
nicholas@2224 2577 }
nicholas@2224 2578
nicholas@2224 2579 // Support: IE<9
nicholas@2224 2580 // Use defaultValue in place of getAttribute("value")
nicholas@2224 2581 if ( !support.attributes || !assert(function( div ) {
nicholas@2224 2582 div.innerHTML = "<input/>";
nicholas@2224 2583 div.firstChild.setAttribute( "value", "" );
nicholas@2224 2584 return div.firstChild.getAttribute( "value" ) === "";
nicholas@2224 2585 }) ) {
nicholas@2224 2586 addHandle( "value", function( elem, name, isXML ) {
nicholas@2224 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nicholas@2224 2588 return elem.defaultValue;
nicholas@2224 2589 }
nicholas@2224 2590 });
nicholas@2224 2591 }
nicholas@2224 2592
nicholas@2224 2593 // Support: IE<9
nicholas@2224 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nicholas@2224 2595 if ( !assert(function( div ) {
nicholas@2224 2596 return div.getAttribute("disabled") == null;
nicholas@2224 2597 }) ) {
nicholas@2224 2598 addHandle( booleans, function( elem, name, isXML ) {
nicholas@2224 2599 var val;
nicholas@2224 2600 if ( !isXML ) {
nicholas@2224 2601 return elem[ name ] === true ? name.toLowerCase() :
nicholas@2224 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nicholas@2224 2603 val.value :
nicholas@2224 2604 null;
nicholas@2224 2605 }
nicholas@2224 2606 });
nicholas@2224 2607 }
nicholas@2224 2608
nicholas@2224 2609 return Sizzle;
nicholas@2224 2610
nicholas@2224 2611 })( window );
nicholas@2224 2612
nicholas@2224 2613
nicholas@2224 2614
nicholas@2224 2615 jQuery.find = Sizzle;
nicholas@2224 2616 jQuery.expr = Sizzle.selectors;
nicholas@2224 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nicholas@2224 2618 jQuery.unique = Sizzle.uniqueSort;
nicholas@2224 2619 jQuery.text = Sizzle.getText;
nicholas@2224 2620 jQuery.isXMLDoc = Sizzle.isXML;
nicholas@2224 2621 jQuery.contains = Sizzle.contains;
nicholas@2224 2622
nicholas@2224 2623
nicholas@2224 2624
nicholas@2224 2625 var rneedsContext = jQuery.expr.match.needsContext;
nicholas@2224 2626
nicholas@2224 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nicholas@2224 2628
nicholas@2224 2629
nicholas@2224 2630
nicholas@2224 2631 var risSimple = /^.[^:#\[\.,]*$/;
nicholas@2224 2632
nicholas@2224 2633 // Implement the identical functionality for filter and not
nicholas@2224 2634 function winnow( elements, qualifier, not ) {
nicholas@2224 2635 if ( jQuery.isFunction( qualifier ) ) {
nicholas@2224 2636 return jQuery.grep( elements, function( elem, i ) {
nicholas@2224 2637 /* jshint -W018 */
nicholas@2224 2638 return !!qualifier.call( elem, i, elem ) !== not;
nicholas@2224 2639 });
nicholas@2224 2640
nicholas@2224 2641 }
nicholas@2224 2642
nicholas@2224 2643 if ( qualifier.nodeType ) {
nicholas@2224 2644 return jQuery.grep( elements, function( elem ) {
nicholas@2224 2645 return ( elem === qualifier ) !== not;
nicholas@2224 2646 });
nicholas@2224 2647
nicholas@2224 2648 }
nicholas@2224 2649
nicholas@2224 2650 if ( typeof qualifier === "string" ) {
nicholas@2224 2651 if ( risSimple.test( qualifier ) ) {
nicholas@2224 2652 return jQuery.filter( qualifier, elements, not );
nicholas@2224 2653 }
nicholas@2224 2654
nicholas@2224 2655 qualifier = jQuery.filter( qualifier, elements );
nicholas@2224 2656 }
nicholas@2224 2657
nicholas@2224 2658 return jQuery.grep( elements, function( elem ) {
nicholas@2224 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nicholas@2224 2660 });
nicholas@2224 2661 }
nicholas@2224 2662
nicholas@2224 2663 jQuery.filter = function( expr, elems, not ) {
nicholas@2224 2664 var elem = elems[ 0 ];
nicholas@2224 2665
nicholas@2224 2666 if ( not ) {
nicholas@2224 2667 expr = ":not(" + expr + ")";
nicholas@2224 2668 }
nicholas@2224 2669
nicholas@2224 2670 return elems.length === 1 && elem.nodeType === 1 ?
nicholas@2224 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nicholas@2224 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nicholas@2224 2673 return elem.nodeType === 1;
nicholas@2224 2674 }));
nicholas@2224 2675 };
nicholas@2224 2676
nicholas@2224 2677 jQuery.fn.extend({
nicholas@2224 2678 find: function( selector ) {
nicholas@2224 2679 var i,
nicholas@2224 2680 len = this.length,
nicholas@2224 2681 ret = [],
nicholas@2224 2682 self = this;
nicholas@2224 2683
nicholas@2224 2684 if ( typeof selector !== "string" ) {
nicholas@2224 2685 return this.pushStack( jQuery( selector ).filter(function() {
nicholas@2224 2686 for ( i = 0; i < len; i++ ) {
nicholas@2224 2687 if ( jQuery.contains( self[ i ], this ) ) {
nicholas@2224 2688 return true;
nicholas@2224 2689 }
nicholas@2224 2690 }
nicholas@2224 2691 }) );
nicholas@2224 2692 }
nicholas@2224 2693
nicholas@2224 2694 for ( i = 0; i < len; i++ ) {
nicholas@2224 2695 jQuery.find( selector, self[ i ], ret );
nicholas@2224 2696 }
nicholas@2224 2697
nicholas@2224 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nicholas@2224 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nicholas@2224 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nicholas@2224 2701 return ret;
nicholas@2224 2702 },
nicholas@2224 2703 filter: function( selector ) {
nicholas@2224 2704 return this.pushStack( winnow(this, selector || [], false) );
nicholas@2224 2705 },
nicholas@2224 2706 not: function( selector ) {
nicholas@2224 2707 return this.pushStack( winnow(this, selector || [], true) );
nicholas@2224 2708 },
nicholas@2224 2709 is: function( selector ) {
nicholas@2224 2710 return !!winnow(
nicholas@2224 2711 this,
nicholas@2224 2712
nicholas@2224 2713 // If this is a positional/relative selector, check membership in the returned set
nicholas@2224 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nicholas@2224 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nicholas@2224 2716 jQuery( selector ) :
nicholas@2224 2717 selector || [],
nicholas@2224 2718 false
nicholas@2224 2719 ).length;
nicholas@2224 2720 }
nicholas@2224 2721 });
nicholas@2224 2722
nicholas@2224 2723
nicholas@2224 2724 // Initialize a jQuery object
nicholas@2224 2725
nicholas@2224 2726
nicholas@2224 2727 // A central reference to the root jQuery(document)
nicholas@2224 2728 var rootjQuery,
nicholas@2224 2729
nicholas@2224 2730 // A simple way to check for HTML strings
nicholas@2224 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nicholas@2224 2732 // Strict HTML recognition (#11290: must start with <)
nicholas@2224 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nicholas@2224 2734
nicholas@2224 2735 init = jQuery.fn.init = function( selector, context ) {
nicholas@2224 2736 var match, elem;
nicholas@2224 2737
nicholas@2224 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nicholas@2224 2739 if ( !selector ) {
nicholas@2224 2740 return this;
nicholas@2224 2741 }
nicholas@2224 2742
nicholas@2224 2743 // Handle HTML strings
nicholas@2224 2744 if ( typeof selector === "string" ) {
nicholas@2224 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nicholas@2224 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nicholas@2224 2747 match = [ null, selector, null ];
nicholas@2224 2748
nicholas@2224 2749 } else {
nicholas@2224 2750 match = rquickExpr.exec( selector );
nicholas@2224 2751 }
nicholas@2224 2752
nicholas@2224 2753 // Match html or make sure no context is specified for #id
nicholas@2224 2754 if ( match && (match[1] || !context) ) {
nicholas@2224 2755
nicholas@2224 2756 // HANDLE: $(html) -> $(array)
nicholas@2224 2757 if ( match[1] ) {
nicholas@2224 2758 context = context instanceof jQuery ? context[0] : context;
nicholas@2224 2759
nicholas@2224 2760 // Option to run scripts is true for back-compat
nicholas@2224 2761 // Intentionally let the error be thrown if parseHTML is not present
nicholas@2224 2762 jQuery.merge( this, jQuery.parseHTML(
nicholas@2224 2763 match[1],
nicholas@2224 2764 context && context.nodeType ? context.ownerDocument || context : document,
nicholas@2224 2765 true
nicholas@2224 2766 ) );
nicholas@2224 2767
nicholas@2224 2768 // HANDLE: $(html, props)
nicholas@2224 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nicholas@2224 2770 for ( match in context ) {
nicholas@2224 2771 // Properties of context are called as methods if possible
nicholas@2224 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nicholas@2224 2773 this[ match ]( context[ match ] );
nicholas@2224 2774
nicholas@2224 2775 // ...and otherwise set as attributes
nicholas@2224 2776 } else {
nicholas@2224 2777 this.attr( match, context[ match ] );
nicholas@2224 2778 }
nicholas@2224 2779 }
nicholas@2224 2780 }
nicholas@2224 2781
nicholas@2224 2782 return this;
nicholas@2224 2783
nicholas@2224 2784 // HANDLE: $(#id)
nicholas@2224 2785 } else {
nicholas@2224 2786 elem = document.getElementById( match[2] );
nicholas@2224 2787
nicholas@2224 2788 // Support: Blackberry 4.6
nicholas@2224 2789 // gEBID returns nodes no longer in the document (#6963)
nicholas@2224 2790 if ( elem && elem.parentNode ) {
nicholas@2224 2791 // Inject the element directly into the jQuery object
nicholas@2224 2792 this.length = 1;
nicholas@2224 2793 this[0] = elem;
nicholas@2224 2794 }
nicholas@2224 2795
nicholas@2224 2796 this.context = document;
nicholas@2224 2797 this.selector = selector;
nicholas@2224 2798 return this;
nicholas@2224 2799 }
nicholas@2224 2800
nicholas@2224 2801 // HANDLE: $(expr, $(...))
nicholas@2224 2802 } else if ( !context || context.jquery ) {
nicholas@2224 2803 return ( context || rootjQuery ).find( selector );
nicholas@2224 2804
nicholas@2224 2805 // HANDLE: $(expr, context)
nicholas@2224 2806 // (which is just equivalent to: $(context).find(expr)
nicholas@2224 2807 } else {
nicholas@2224 2808 return this.constructor( context ).find( selector );
nicholas@2224 2809 }
nicholas@2224 2810
nicholas@2224 2811 // HANDLE: $(DOMElement)
nicholas@2224 2812 } else if ( selector.nodeType ) {
nicholas@2224 2813 this.context = this[0] = selector;
nicholas@2224 2814 this.length = 1;
nicholas@2224 2815 return this;
nicholas@2224 2816
nicholas@2224 2817 // HANDLE: $(function)
nicholas@2224 2818 // Shortcut for document ready
nicholas@2224 2819 } else if ( jQuery.isFunction( selector ) ) {
nicholas@2224 2820 return typeof rootjQuery.ready !== "undefined" ?
nicholas@2224 2821 rootjQuery.ready( selector ) :
nicholas@2224 2822 // Execute immediately if ready is not present
nicholas@2224 2823 selector( jQuery );
nicholas@2224 2824 }
nicholas@2224 2825
nicholas@2224 2826 if ( selector.selector !== undefined ) {
nicholas@2224 2827 this.selector = selector.selector;
nicholas@2224 2828 this.context = selector.context;
nicholas@2224 2829 }
nicholas@2224 2830
nicholas@2224 2831 return jQuery.makeArray( selector, this );
nicholas@2224 2832 };
nicholas@2224 2833
nicholas@2224 2834 // Give the init function the jQuery prototype for later instantiation
nicholas@2224 2835 init.prototype = jQuery.fn;
nicholas@2224 2836
nicholas@2224 2837 // Initialize central reference
nicholas@2224 2838 rootjQuery = jQuery( document );
nicholas@2224 2839
nicholas@2224 2840
nicholas@2224 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nicholas@2224 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nicholas@2224 2843 guaranteedUnique = {
nicholas@2224 2844 children: true,
nicholas@2224 2845 contents: true,
nicholas@2224 2846 next: true,
nicholas@2224 2847 prev: true
nicholas@2224 2848 };
nicholas@2224 2849
nicholas@2224 2850 jQuery.extend({
nicholas@2224 2851 dir: function( elem, dir, until ) {
nicholas@2224 2852 var matched = [],
nicholas@2224 2853 truncate = until !== undefined;
nicholas@2224 2854
nicholas@2224 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nicholas@2224 2856 if ( elem.nodeType === 1 ) {
nicholas@2224 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nicholas@2224 2858 break;
nicholas@2224 2859 }
nicholas@2224 2860 matched.push( elem );
nicholas@2224 2861 }
nicholas@2224 2862 }
nicholas@2224 2863 return matched;
nicholas@2224 2864 },
nicholas@2224 2865
nicholas@2224 2866 sibling: function( n, elem ) {
nicholas@2224 2867 var matched = [];
nicholas@2224 2868
nicholas@2224 2869 for ( ; n; n = n.nextSibling ) {
nicholas@2224 2870 if ( n.nodeType === 1 && n !== elem ) {
nicholas@2224 2871 matched.push( n );
nicholas@2224 2872 }
nicholas@2224 2873 }
nicholas@2224 2874
nicholas@2224 2875 return matched;
nicholas@2224 2876 }
nicholas@2224 2877 });
nicholas@2224 2878
nicholas@2224 2879 jQuery.fn.extend({
nicholas@2224 2880 has: function( target ) {
nicholas@2224 2881 var targets = jQuery( target, this ),
nicholas@2224 2882 l = targets.length;
nicholas@2224 2883
nicholas@2224 2884 return this.filter(function() {
nicholas@2224 2885 var i = 0;
nicholas@2224 2886 for ( ; i < l; i++ ) {
nicholas@2224 2887 if ( jQuery.contains( this, targets[i] ) ) {
nicholas@2224 2888 return true;
nicholas@2224 2889 }
nicholas@2224 2890 }
nicholas@2224 2891 });
nicholas@2224 2892 },
nicholas@2224 2893
nicholas@2224 2894 closest: function( selectors, context ) {
nicholas@2224 2895 var cur,
nicholas@2224 2896 i = 0,
nicholas@2224 2897 l = this.length,
nicholas@2224 2898 matched = [],
nicholas@2224 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nicholas@2224 2900 jQuery( selectors, context || this.context ) :
nicholas@2224 2901 0;
nicholas@2224 2902
nicholas@2224 2903 for ( ; i < l; i++ ) {
nicholas@2224 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nicholas@2224 2905 // Always skip document fragments
nicholas@2224 2906 if ( cur.nodeType < 11 && (pos ?
nicholas@2224 2907 pos.index(cur) > -1 :
nicholas@2224 2908
nicholas@2224 2909 // Don't pass non-elements to Sizzle
nicholas@2224 2910 cur.nodeType === 1 &&
nicholas@2224 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nicholas@2224 2912
nicholas@2224 2913 matched.push( cur );
nicholas@2224 2914 break;
nicholas@2224 2915 }
nicholas@2224 2916 }
nicholas@2224 2917 }
nicholas@2224 2918
nicholas@2224 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nicholas@2224 2920 },
nicholas@2224 2921
nicholas@2224 2922 // Determine the position of an element within the set
nicholas@2224 2923 index: function( elem ) {
nicholas@2224 2924
nicholas@2224 2925 // No argument, return index in parent
nicholas@2224 2926 if ( !elem ) {
nicholas@2224 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nicholas@2224 2928 }
nicholas@2224 2929
nicholas@2224 2930 // Index in selector
nicholas@2224 2931 if ( typeof elem === "string" ) {
nicholas@2224 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nicholas@2224 2933 }
nicholas@2224 2934
nicholas@2224 2935 // Locate the position of the desired element
nicholas@2224 2936 return indexOf.call( this,
nicholas@2224 2937
nicholas@2224 2938 // If it receives a jQuery object, the first element is used
nicholas@2224 2939 elem.jquery ? elem[ 0 ] : elem
nicholas@2224 2940 );
nicholas@2224 2941 },
nicholas@2224 2942
nicholas@2224 2943 add: function( selector, context ) {
nicholas@2224 2944 return this.pushStack(
nicholas@2224 2945 jQuery.unique(
nicholas@2224 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nicholas@2224 2947 )
nicholas@2224 2948 );
nicholas@2224 2949 },
nicholas@2224 2950
nicholas@2224 2951 addBack: function( selector ) {
nicholas@2224 2952 return this.add( selector == null ?
nicholas@2224 2953 this.prevObject : this.prevObject.filter(selector)
nicholas@2224 2954 );
nicholas@2224 2955 }
nicholas@2224 2956 });
nicholas@2224 2957
nicholas@2224 2958 function sibling( cur, dir ) {
nicholas@2224 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nicholas@2224 2960 return cur;
nicholas@2224 2961 }
nicholas@2224 2962
nicholas@2224 2963 jQuery.each({
nicholas@2224 2964 parent: function( elem ) {
nicholas@2224 2965 var parent = elem.parentNode;
nicholas@2224 2966 return parent && parent.nodeType !== 11 ? parent : null;
nicholas@2224 2967 },
nicholas@2224 2968 parents: function( elem ) {
nicholas@2224 2969 return jQuery.dir( elem, "parentNode" );
nicholas@2224 2970 },
nicholas@2224 2971 parentsUntil: function( elem, i, until ) {
nicholas@2224 2972 return jQuery.dir( elem, "parentNode", until );
nicholas@2224 2973 },
nicholas@2224 2974 next: function( elem ) {
nicholas@2224 2975 return sibling( elem, "nextSibling" );
nicholas@2224 2976 },
nicholas@2224 2977 prev: function( elem ) {
nicholas@2224 2978 return sibling( elem, "previousSibling" );
nicholas@2224 2979 },
nicholas@2224 2980 nextAll: function( elem ) {
nicholas@2224 2981 return jQuery.dir( elem, "nextSibling" );
nicholas@2224 2982 },
nicholas@2224 2983 prevAll: function( elem ) {
nicholas@2224 2984 return jQuery.dir( elem, "previousSibling" );
nicholas@2224 2985 },
nicholas@2224 2986 nextUntil: function( elem, i, until ) {
nicholas@2224 2987 return jQuery.dir( elem, "nextSibling", until );
nicholas@2224 2988 },
nicholas@2224 2989 prevUntil: function( elem, i, until ) {
nicholas@2224 2990 return jQuery.dir( elem, "previousSibling", until );
nicholas@2224 2991 },
nicholas@2224 2992 siblings: function( elem ) {
nicholas@2224 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nicholas@2224 2994 },
nicholas@2224 2995 children: function( elem ) {
nicholas@2224 2996 return jQuery.sibling( elem.firstChild );
nicholas@2224 2997 },
nicholas@2224 2998 contents: function( elem ) {
nicholas@2224 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nicholas@2224 3000 }
nicholas@2224 3001 }, function( name, fn ) {
nicholas@2224 3002 jQuery.fn[ name ] = function( until, selector ) {
nicholas@2224 3003 var matched = jQuery.map( this, fn, until );
nicholas@2224 3004
nicholas@2224 3005 if ( name.slice( -5 ) !== "Until" ) {
nicholas@2224 3006 selector = until;
nicholas@2224 3007 }
nicholas@2224 3008
nicholas@2224 3009 if ( selector && typeof selector === "string" ) {
nicholas@2224 3010 matched = jQuery.filter( selector, matched );
nicholas@2224 3011 }
nicholas@2224 3012
nicholas@2224 3013 if ( this.length > 1 ) {
nicholas@2224 3014 // Remove duplicates
nicholas@2224 3015 if ( !guaranteedUnique[ name ] ) {
nicholas@2224 3016 jQuery.unique( matched );
nicholas@2224 3017 }
nicholas@2224 3018
nicholas@2224 3019 // Reverse order for parents* and prev-derivatives
nicholas@2224 3020 if ( rparentsprev.test( name ) ) {
nicholas@2224 3021 matched.reverse();
nicholas@2224 3022 }
nicholas@2224 3023 }
nicholas@2224 3024
nicholas@2224 3025 return this.pushStack( matched );
nicholas@2224 3026 };
nicholas@2224 3027 });
nicholas@2224 3028 var rnotwhite = (/\S+/g);
nicholas@2224 3029
nicholas@2224 3030
nicholas@2224 3031
nicholas@2224 3032 // String to Object options format cache
nicholas@2224 3033 var optionsCache = {};
nicholas@2224 3034
nicholas@2224 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nicholas@2224 3036 function createOptions( options ) {
nicholas@2224 3037 var object = optionsCache[ options ] = {};
nicholas@2224 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nicholas@2224 3039 object[ flag ] = true;
nicholas@2224 3040 });
nicholas@2224 3041 return object;
nicholas@2224 3042 }
nicholas@2224 3043
nicholas@2224 3044 /*
nicholas@2224 3045 * Create a callback list using the following parameters:
nicholas@2224 3046 *
nicholas@2224 3047 * options: an optional list of space-separated options that will change how
nicholas@2224 3048 * the callback list behaves or a more traditional option object
nicholas@2224 3049 *
nicholas@2224 3050 * By default a callback list will act like an event callback list and can be
nicholas@2224 3051 * "fired" multiple times.
nicholas@2224 3052 *
nicholas@2224 3053 * Possible options:
nicholas@2224 3054 *
nicholas@2224 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nicholas@2224 3056 *
nicholas@2224 3057 * memory: will keep track of previous values and will call any callback added
nicholas@2224 3058 * after the list has been fired right away with the latest "memorized"
nicholas@2224 3059 * values (like a Deferred)
nicholas@2224 3060 *
nicholas@2224 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nicholas@2224 3062 *
nicholas@2224 3063 * stopOnFalse: interrupt callings when a callback returns false
nicholas@2224 3064 *
nicholas@2224 3065 */
nicholas@2224 3066 jQuery.Callbacks = function( options ) {
nicholas@2224 3067
nicholas@2224 3068 // Convert options from String-formatted to Object-formatted if needed
nicholas@2224 3069 // (we check in cache first)
nicholas@2224 3070 options = typeof options === "string" ?
nicholas@2224 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nicholas@2224 3072 jQuery.extend( {}, options );
nicholas@2224 3073
nicholas@2224 3074 var // Last fire value (for non-forgettable lists)
nicholas@2224 3075 memory,
nicholas@2224 3076 // Flag to know if list was already fired
nicholas@2224 3077 fired,
nicholas@2224 3078 // Flag to know if list is currently firing
nicholas@2224 3079 firing,
nicholas@2224 3080 // First callback to fire (used internally by add and fireWith)
nicholas@2224 3081 firingStart,
nicholas@2224 3082 // End of the loop when firing
nicholas@2224 3083 firingLength,
nicholas@2224 3084 // Index of currently firing callback (modified by remove if needed)
nicholas@2224 3085 firingIndex,
nicholas@2224 3086 // Actual callback list
nicholas@2224 3087 list = [],
nicholas@2224 3088 // Stack of fire calls for repeatable lists
nicholas@2224 3089 stack = !options.once && [],
nicholas@2224 3090 // Fire callbacks
nicholas@2224 3091 fire = function( data ) {
nicholas@2224 3092 memory = options.memory && data;
nicholas@2224 3093 fired = true;
nicholas@2224 3094 firingIndex = firingStart || 0;
nicholas@2224 3095 firingStart = 0;
nicholas@2224 3096 firingLength = list.length;
nicholas@2224 3097 firing = true;
nicholas@2224 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nicholas@2224 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nicholas@2224 3100 memory = false; // To prevent further calls using add
nicholas@2224 3101 break;
nicholas@2224 3102 }
nicholas@2224 3103 }
nicholas@2224 3104 firing = false;
nicholas@2224 3105 if ( list ) {
nicholas@2224 3106 if ( stack ) {
nicholas@2224 3107 if ( stack.length ) {
nicholas@2224 3108 fire( stack.shift() );
nicholas@2224 3109 }
nicholas@2224 3110 } else if ( memory ) {
nicholas@2224 3111 list = [];
nicholas@2224 3112 } else {
nicholas@2224 3113 self.disable();
nicholas@2224 3114 }
nicholas@2224 3115 }
nicholas@2224 3116 },
nicholas@2224 3117 // Actual Callbacks object
nicholas@2224 3118 self = {
nicholas@2224 3119 // Add a callback or a collection of callbacks to the list
nicholas@2224 3120 add: function() {
nicholas@2224 3121 if ( list ) {
nicholas@2224 3122 // First, we save the current length
nicholas@2224 3123 var start = list.length;
nicholas@2224 3124 (function add( args ) {
nicholas@2224 3125 jQuery.each( args, function( _, arg ) {
nicholas@2224 3126 var type = jQuery.type( arg );
nicholas@2224 3127 if ( type === "function" ) {
nicholas@2224 3128 if ( !options.unique || !self.has( arg ) ) {
nicholas@2224 3129 list.push( arg );
nicholas@2224 3130 }
nicholas@2224 3131 } else if ( arg && arg.length && type !== "string" ) {
nicholas@2224 3132 // Inspect recursively
nicholas@2224 3133 add( arg );
nicholas@2224 3134 }
nicholas@2224 3135 });
nicholas@2224 3136 })( arguments );
nicholas@2224 3137 // Do we need to add the callbacks to the
nicholas@2224 3138 // current firing batch?
nicholas@2224 3139 if ( firing ) {
nicholas@2224 3140 firingLength = list.length;
nicholas@2224 3141 // With memory, if we're not firing then
nicholas@2224 3142 // we should call right away
nicholas@2224 3143 } else if ( memory ) {
nicholas@2224 3144 firingStart = start;
nicholas@2224 3145 fire( memory );
nicholas@2224 3146 }
nicholas@2224 3147 }
nicholas@2224 3148 return this;
nicholas@2224 3149 },
nicholas@2224 3150 // Remove a callback from the list
nicholas@2224 3151 remove: function() {
nicholas@2224 3152 if ( list ) {
nicholas@2224 3153 jQuery.each( arguments, function( _, arg ) {
nicholas@2224 3154 var index;
nicholas@2224 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nicholas@2224 3156 list.splice( index, 1 );
nicholas@2224 3157 // Handle firing indexes
nicholas@2224 3158 if ( firing ) {
nicholas@2224 3159 if ( index <= firingLength ) {
nicholas@2224 3160 firingLength--;
nicholas@2224 3161 }
nicholas@2224 3162 if ( index <= firingIndex ) {
nicholas@2224 3163 firingIndex--;
nicholas@2224 3164 }
nicholas@2224 3165 }
nicholas@2224 3166 }
nicholas@2224 3167 });
nicholas@2224 3168 }
nicholas@2224 3169 return this;
nicholas@2224 3170 },
nicholas@2224 3171 // Check if a given callback is in the list.
nicholas@2224 3172 // If no argument is given, return whether or not list has callbacks attached.
nicholas@2224 3173 has: function( fn ) {
nicholas@2224 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nicholas@2224 3175 },
nicholas@2224 3176 // Remove all callbacks from the list
nicholas@2224 3177 empty: function() {
nicholas@2224 3178 list = [];
nicholas@2224 3179 firingLength = 0;
nicholas@2224 3180 return this;
nicholas@2224 3181 },
nicholas@2224 3182 // Have the list do nothing anymore
nicholas@2224 3183 disable: function() {
nicholas@2224 3184 list = stack = memory = undefined;
nicholas@2224 3185 return this;
nicholas@2224 3186 },
nicholas@2224 3187 // Is it disabled?
nicholas@2224 3188 disabled: function() {
nicholas@2224 3189 return !list;
nicholas@2224 3190 },
nicholas@2224 3191 // Lock the list in its current state
nicholas@2224 3192 lock: function() {
nicholas@2224 3193 stack = undefined;
nicholas@2224 3194 if ( !memory ) {
nicholas@2224 3195 self.disable();
nicholas@2224 3196 }
nicholas@2224 3197 return this;
nicholas@2224 3198 },
nicholas@2224 3199 // Is it locked?
nicholas@2224 3200 locked: function() {
nicholas@2224 3201 return !stack;
nicholas@2224 3202 },
nicholas@2224 3203 // Call all callbacks with the given context and arguments
nicholas@2224 3204 fireWith: function( context, args ) {
nicholas@2224 3205 if ( list && ( !fired || stack ) ) {
nicholas@2224 3206 args = args || [];
nicholas@2224 3207 args = [ context, args.slice ? args.slice() : args ];
nicholas@2224 3208 if ( firing ) {
nicholas@2224 3209 stack.push( args );
nicholas@2224 3210 } else {
nicholas@2224 3211 fire( args );
nicholas@2224 3212 }
nicholas@2224 3213 }
nicholas@2224 3214 return this;
nicholas@2224 3215 },
nicholas@2224 3216 // Call all the callbacks with the given arguments
nicholas@2224 3217 fire: function() {
nicholas@2224 3218 self.fireWith( this, arguments );
nicholas@2224 3219 return this;
nicholas@2224 3220 },
nicholas@2224 3221 // To know if the callbacks have already been called at least once
nicholas@2224 3222 fired: function() {
nicholas@2224 3223 return !!fired;
nicholas@2224 3224 }
nicholas@2224 3225 };
nicholas@2224 3226
nicholas@2224 3227 return self;
nicholas@2224 3228 };
nicholas@2224 3229
nicholas@2224 3230
nicholas@2224 3231 jQuery.extend({
nicholas@2224 3232
nicholas@2224 3233 Deferred: function( func ) {
nicholas@2224 3234 var tuples = [
nicholas@2224 3235 // action, add listener, listener list, final state
nicholas@2224 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nicholas@2224 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nicholas@2224 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nicholas@2224 3239 ],
nicholas@2224 3240 state = "pending",
nicholas@2224 3241 promise = {
nicholas@2224 3242 state: function() {
nicholas@2224 3243 return state;
nicholas@2224 3244 },
nicholas@2224 3245 always: function() {
nicholas@2224 3246 deferred.done( arguments ).fail( arguments );
nicholas@2224 3247 return this;
nicholas@2224 3248 },
nicholas@2224 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nicholas@2224 3250 var fns = arguments;
nicholas@2224 3251 return jQuery.Deferred(function( newDefer ) {
nicholas@2224 3252 jQuery.each( tuples, function( i, tuple ) {
nicholas@2224 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nicholas@2224 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nicholas@2224 3255 deferred[ tuple[1] ](function() {
nicholas@2224 3256 var returned = fn && fn.apply( this, arguments );
nicholas@2224 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nicholas@2224 3258 returned.promise()
nicholas@2224 3259 .done( newDefer.resolve )
nicholas@2224 3260 .fail( newDefer.reject )
nicholas@2224 3261 .progress( newDefer.notify );
nicholas@2224 3262 } else {
nicholas@2224 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nicholas@2224 3264 }
nicholas@2224 3265 });
nicholas@2224 3266 });
nicholas@2224 3267 fns = null;
nicholas@2224 3268 }).promise();
nicholas@2224 3269 },
nicholas@2224 3270 // Get a promise for this deferred
nicholas@2224 3271 // If obj is provided, the promise aspect is added to the object
nicholas@2224 3272 promise: function( obj ) {
nicholas@2224 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nicholas@2224 3274 }
nicholas@2224 3275 },
nicholas@2224 3276 deferred = {};
nicholas@2224 3277
nicholas@2224 3278 // Keep pipe for back-compat
nicholas@2224 3279 promise.pipe = promise.then;
nicholas@2224 3280
nicholas@2224 3281 // Add list-specific methods
nicholas@2224 3282 jQuery.each( tuples, function( i, tuple ) {
nicholas@2224 3283 var list = tuple[ 2 ],
nicholas@2224 3284 stateString = tuple[ 3 ];
nicholas@2224 3285
nicholas@2224 3286 // promise[ done | fail | progress ] = list.add
nicholas@2224 3287 promise[ tuple[1] ] = list.add;
nicholas@2224 3288
nicholas@2224 3289 // Handle state
nicholas@2224 3290 if ( stateString ) {
nicholas@2224 3291 list.add(function() {
nicholas@2224 3292 // state = [ resolved | rejected ]
nicholas@2224 3293 state = stateString;
nicholas@2224 3294
nicholas@2224 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nicholas@2224 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nicholas@2224 3297 }
nicholas@2224 3298
nicholas@2224 3299 // deferred[ resolve | reject | notify ]
nicholas@2224 3300 deferred[ tuple[0] ] = function() {
nicholas@2224 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nicholas@2224 3302 return this;
nicholas@2224 3303 };
nicholas@2224 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nicholas@2224 3305 });
nicholas@2224 3306
nicholas@2224 3307 // Make the deferred a promise
nicholas@2224 3308 promise.promise( deferred );
nicholas@2224 3309
nicholas@2224 3310 // Call given func if any
nicholas@2224 3311 if ( func ) {
nicholas@2224 3312 func.call( deferred, deferred );
nicholas@2224 3313 }
nicholas@2224 3314
nicholas@2224 3315 // All done!
nicholas@2224 3316 return deferred;
nicholas@2224 3317 },
nicholas@2224 3318
nicholas@2224 3319 // Deferred helper
nicholas@2224 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nicholas@2224 3321 var i = 0,
nicholas@2224 3322 resolveValues = slice.call( arguments ),
nicholas@2224 3323 length = resolveValues.length,
nicholas@2224 3324
nicholas@2224 3325 // the count of uncompleted subordinates
nicholas@2224 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nicholas@2224 3327
nicholas@2224 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nicholas@2224 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nicholas@2224 3330
nicholas@2224 3331 // Update function for both resolve and progress values
nicholas@2224 3332 updateFunc = function( i, contexts, values ) {
nicholas@2224 3333 return function( value ) {
nicholas@2224 3334 contexts[ i ] = this;
nicholas@2224 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nicholas@2224 3336 if ( values === progressValues ) {
nicholas@2224 3337 deferred.notifyWith( contexts, values );
nicholas@2224 3338 } else if ( !( --remaining ) ) {
nicholas@2224 3339 deferred.resolveWith( contexts, values );
nicholas@2224 3340 }
nicholas@2224 3341 };
nicholas@2224 3342 },
nicholas@2224 3343
nicholas@2224 3344 progressValues, progressContexts, resolveContexts;
nicholas@2224 3345
nicholas@2224 3346 // Add listeners to Deferred subordinates; treat others as resolved
nicholas@2224 3347 if ( length > 1 ) {
nicholas@2224 3348 progressValues = new Array( length );
nicholas@2224 3349 progressContexts = new Array( length );
nicholas@2224 3350 resolveContexts = new Array( length );
nicholas@2224 3351 for ( ; i < length; i++ ) {
nicholas@2224 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nicholas@2224 3353 resolveValues[ i ].promise()
nicholas@2224 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nicholas@2224 3355 .fail( deferred.reject )
nicholas@2224 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nicholas@2224 3357 } else {
nicholas@2224 3358 --remaining;
nicholas@2224 3359 }
nicholas@2224 3360 }
nicholas@2224 3361 }
nicholas@2224 3362
nicholas@2224 3363 // If we're not waiting on anything, resolve the master
nicholas@2224 3364 if ( !remaining ) {
nicholas@2224 3365 deferred.resolveWith( resolveContexts, resolveValues );
nicholas@2224 3366 }
nicholas@2224 3367
nicholas@2224 3368 return deferred.promise();
nicholas@2224 3369 }
nicholas@2224 3370 });
nicholas@2224 3371
nicholas@2224 3372
nicholas@2224 3373 // The deferred used on DOM ready
nicholas@2224 3374 var readyList;
nicholas@2224 3375
nicholas@2224 3376 jQuery.fn.ready = function( fn ) {
nicholas@2224 3377 // Add the callback
nicholas@2224 3378 jQuery.ready.promise().done( fn );
nicholas@2224 3379
nicholas@2224 3380 return this;
nicholas@2224 3381 };
nicholas@2224 3382
nicholas@2224 3383 jQuery.extend({
nicholas@2224 3384 // Is the DOM ready to be used? Set to true once it occurs.
nicholas@2224 3385 isReady: false,
nicholas@2224 3386
nicholas@2224 3387 // A counter to track how many items to wait for before
nicholas@2224 3388 // the ready event fires. See #6781
nicholas@2224 3389 readyWait: 1,
nicholas@2224 3390
nicholas@2224 3391 // Hold (or release) the ready event
nicholas@2224 3392 holdReady: function( hold ) {
nicholas@2224 3393 if ( hold ) {
nicholas@2224 3394 jQuery.readyWait++;
nicholas@2224 3395 } else {
nicholas@2224 3396 jQuery.ready( true );
nicholas@2224 3397 }
nicholas@2224 3398 },
nicholas@2224 3399
nicholas@2224 3400 // Handle when the DOM is ready
nicholas@2224 3401 ready: function( wait ) {
nicholas@2224 3402
nicholas@2224 3403 // Abort if there are pending holds or we're already ready
nicholas@2224 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nicholas@2224 3405 return;
nicholas@2224 3406 }
nicholas@2224 3407
nicholas@2224 3408 // Remember that the DOM is ready
nicholas@2224 3409 jQuery.isReady = true;
nicholas@2224 3410
nicholas@2224 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nicholas@2224 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nicholas@2224 3413 return;
nicholas@2224 3414 }
nicholas@2224 3415
nicholas@2224 3416 // If there are functions bound, to execute
nicholas@2224 3417 readyList.resolveWith( document, [ jQuery ] );
nicholas@2224 3418
nicholas@2224 3419 // Trigger any bound ready events
nicholas@2224 3420 if ( jQuery.fn.triggerHandler ) {
nicholas@2224 3421 jQuery( document ).triggerHandler( "ready" );
nicholas@2224 3422 jQuery( document ).off( "ready" );
nicholas@2224 3423 }
nicholas@2224 3424 }
nicholas@2224 3425 });
nicholas@2224 3426
nicholas@2224 3427 /**
nicholas@2224 3428 * The ready event handler and self cleanup method
nicholas@2224 3429 */
nicholas@2224 3430 function completed() {
nicholas@2224 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nicholas@2224 3432 window.removeEventListener( "load", completed, false );
nicholas@2224 3433 jQuery.ready();
nicholas@2224 3434 }
nicholas@2224 3435
nicholas@2224 3436 jQuery.ready.promise = function( obj ) {
nicholas@2224 3437 if ( !readyList ) {
nicholas@2224 3438
nicholas@2224 3439 readyList = jQuery.Deferred();
nicholas@2224 3440
nicholas@2224 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nicholas@2224 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nicholas@2224 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nicholas@2224 3444 if ( document.readyState === "complete" ) {
nicholas@2224 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nicholas@2224 3446 setTimeout( jQuery.ready );
nicholas@2224 3447
nicholas@2224 3448 } else {
nicholas@2224 3449
nicholas@2224 3450 // Use the handy event callback
nicholas@2224 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nicholas@2224 3452
nicholas@2224 3453 // A fallback to window.onload, that will always work
nicholas@2224 3454 window.addEventListener( "load", completed, false );
nicholas@2224 3455 }
nicholas@2224 3456 }
nicholas@2224 3457 return readyList.promise( obj );
nicholas@2224 3458 };
nicholas@2224 3459
nicholas@2224 3460 // Kick off the DOM ready check even if the user does not
nicholas@2224 3461 jQuery.ready.promise();
nicholas@2224 3462
nicholas@2224 3463
nicholas@2224 3464
nicholas@2224 3465
nicholas@2224 3466 // Multifunctional method to get and set values of a collection
nicholas@2224 3467 // The value/s can optionally be executed if it's a function
nicholas@2224 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nicholas@2224 3469 var i = 0,
nicholas@2224 3470 len = elems.length,
nicholas@2224 3471 bulk = key == null;
nicholas@2224 3472
nicholas@2224 3473 // Sets many values
nicholas@2224 3474 if ( jQuery.type( key ) === "object" ) {
nicholas@2224 3475 chainable = true;
nicholas@2224 3476 for ( i in key ) {
nicholas@2224 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nicholas@2224 3478 }
nicholas@2224 3479
nicholas@2224 3480 // Sets one value
nicholas@2224 3481 } else if ( value !== undefined ) {
nicholas@2224 3482 chainable = true;
nicholas@2224 3483
nicholas@2224 3484 if ( !jQuery.isFunction( value ) ) {
nicholas@2224 3485 raw = true;
nicholas@2224 3486 }
nicholas@2224 3487
nicholas@2224 3488 if ( bulk ) {
nicholas@2224 3489 // Bulk operations run against the entire set
nicholas@2224 3490 if ( raw ) {
nicholas@2224 3491 fn.call( elems, value );
nicholas@2224 3492 fn = null;
nicholas@2224 3493
nicholas@2224 3494 // ...except when executing function values
nicholas@2224 3495 } else {
nicholas@2224 3496 bulk = fn;
nicholas@2224 3497 fn = function( elem, key, value ) {
nicholas@2224 3498 return bulk.call( jQuery( elem ), value );
nicholas@2224 3499 };
nicholas@2224 3500 }
nicholas@2224 3501 }
nicholas@2224 3502
nicholas@2224 3503 if ( fn ) {
nicholas@2224 3504 for ( ; i < len; i++ ) {
nicholas@2224 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nicholas@2224 3506 }
nicholas@2224 3507 }
nicholas@2224 3508 }
nicholas@2224 3509
nicholas@2224 3510 return chainable ?
nicholas@2224 3511 elems :
nicholas@2224 3512
nicholas@2224 3513 // Gets
nicholas@2224 3514 bulk ?
nicholas@2224 3515 fn.call( elems ) :
nicholas@2224 3516 len ? fn( elems[0], key ) : emptyGet;
nicholas@2224 3517 };
nicholas@2224 3518
nicholas@2224 3519
nicholas@2224 3520 /**
nicholas@2224 3521 * Determines whether an object can have data
nicholas@2224 3522 */
nicholas@2224 3523 jQuery.acceptData = function( owner ) {
nicholas@2224 3524 // Accepts only:
nicholas@2224 3525 // - Node
nicholas@2224 3526 // - Node.ELEMENT_NODE
nicholas@2224 3527 // - Node.DOCUMENT_NODE
nicholas@2224 3528 // - Object
nicholas@2224 3529 // - Any
nicholas@2224 3530 /* jshint -W018 */
nicholas@2224 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nicholas@2224 3532 };
nicholas@2224 3533
nicholas@2224 3534
nicholas@2224 3535 function Data() {
nicholas@2224 3536 // Support: Android<4,
nicholas@2224 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nicholas@2224 3538 // return new empty object instead with no [[set]] accessor
nicholas@2224 3539 Object.defineProperty( this.cache = {}, 0, {
nicholas@2224 3540 get: function() {
nicholas@2224 3541 return {};
nicholas@2224 3542 }
nicholas@2224 3543 });
nicholas@2224 3544
nicholas@2224 3545 this.expando = jQuery.expando + Data.uid++;
nicholas@2224 3546 }
nicholas@2224 3547
nicholas@2224 3548 Data.uid = 1;
nicholas@2224 3549 Data.accepts = jQuery.acceptData;
nicholas@2224 3550
nicholas@2224 3551 Data.prototype = {
nicholas@2224 3552 key: function( owner ) {
nicholas@2224 3553 // We can accept data for non-element nodes in modern browsers,
nicholas@2224 3554 // but we should not, see #8335.
nicholas@2224 3555 // Always return the key for a frozen object.
nicholas@2224 3556 if ( !Data.accepts( owner ) ) {
nicholas@2224 3557 return 0;
nicholas@2224 3558 }
nicholas@2224 3559
nicholas@2224 3560 var descriptor = {},
nicholas@2224 3561 // Check if the owner object already has a cache key
nicholas@2224 3562 unlock = owner[ this.expando ];
nicholas@2224 3563
nicholas@2224 3564 // If not, create one
nicholas@2224 3565 if ( !unlock ) {
nicholas@2224 3566 unlock = Data.uid++;
nicholas@2224 3567
nicholas@2224 3568 // Secure it in a non-enumerable, non-writable property
nicholas@2224 3569 try {
nicholas@2224 3570 descriptor[ this.expando ] = { value: unlock };
nicholas@2224 3571 Object.defineProperties( owner, descriptor );
nicholas@2224 3572
nicholas@2224 3573 // Support: Android<4
nicholas@2224 3574 // Fallback to a less secure definition
nicholas@2224 3575 } catch ( e ) {
nicholas@2224 3576 descriptor[ this.expando ] = unlock;
nicholas@2224 3577 jQuery.extend( owner, descriptor );
nicholas@2224 3578 }
nicholas@2224 3579 }
nicholas@2224 3580
nicholas@2224 3581 // Ensure the cache object
nicholas@2224 3582 if ( !this.cache[ unlock ] ) {
nicholas@2224 3583 this.cache[ unlock ] = {};
nicholas@2224 3584 }
nicholas@2224 3585
nicholas@2224 3586 return unlock;
nicholas@2224 3587 },
nicholas@2224 3588 set: function( owner, data, value ) {
nicholas@2224 3589 var prop,
nicholas@2224 3590 // There may be an unlock assigned to this node,
nicholas@2224 3591 // if there is no entry for this "owner", create one inline
nicholas@2224 3592 // and set the unlock as though an owner entry had always existed
nicholas@2224 3593 unlock = this.key( owner ),
nicholas@2224 3594 cache = this.cache[ unlock ];
nicholas@2224 3595
nicholas@2224 3596 // Handle: [ owner, key, value ] args
nicholas@2224 3597 if ( typeof data === "string" ) {
nicholas@2224 3598 cache[ data ] = value;
nicholas@2224 3599
nicholas@2224 3600 // Handle: [ owner, { properties } ] args
nicholas@2224 3601 } else {
nicholas@2224 3602 // Fresh assignments by object are shallow copied
nicholas@2224 3603 if ( jQuery.isEmptyObject( cache ) ) {
nicholas@2224 3604 jQuery.extend( this.cache[ unlock ], data );
nicholas@2224 3605 // Otherwise, copy the properties one-by-one to the cache object
nicholas@2224 3606 } else {
nicholas@2224 3607 for ( prop in data ) {
nicholas@2224 3608 cache[ prop ] = data[ prop ];
nicholas@2224 3609 }
nicholas@2224 3610 }
nicholas@2224 3611 }
nicholas@2224 3612 return cache;
nicholas@2224 3613 },
nicholas@2224 3614 get: function( owner, key ) {
nicholas@2224 3615 // Either a valid cache is found, or will be created.
nicholas@2224 3616 // New caches will be created and the unlock returned,
nicholas@2224 3617 // allowing direct access to the newly created
nicholas@2224 3618 // empty data object. A valid owner object must be provided.
nicholas@2224 3619 var cache = this.cache[ this.key( owner ) ];
nicholas@2224 3620
nicholas@2224 3621 return key === undefined ?
nicholas@2224 3622 cache : cache[ key ];
nicholas@2224 3623 },
nicholas@2224 3624 access: function( owner, key, value ) {
nicholas@2224 3625 var stored;
nicholas@2224 3626 // In cases where either:
nicholas@2224 3627 //
nicholas@2224 3628 // 1. No key was specified
nicholas@2224 3629 // 2. A string key was specified, but no value provided
nicholas@2224 3630 //
nicholas@2224 3631 // Take the "read" path and allow the get method to determine
nicholas@2224 3632 // which value to return, respectively either:
nicholas@2224 3633 //
nicholas@2224 3634 // 1. The entire cache object
nicholas@2224 3635 // 2. The data stored at the key
nicholas@2224 3636 //
nicholas@2224 3637 if ( key === undefined ||
nicholas@2224 3638 ((key && typeof key === "string") && value === undefined) ) {
nicholas@2224 3639
nicholas@2224 3640 stored = this.get( owner, key );
nicholas@2224 3641
nicholas@2224 3642 return stored !== undefined ?
nicholas@2224 3643 stored : this.get( owner, jQuery.camelCase(key) );
nicholas@2224 3644 }
nicholas@2224 3645
nicholas@2224 3646 // [*]When the key is not a string, or both a key and value
nicholas@2224 3647 // are specified, set or extend (existing objects) with either:
nicholas@2224 3648 //
nicholas@2224 3649 // 1. An object of properties
nicholas@2224 3650 // 2. A key and value
nicholas@2224 3651 //
nicholas@2224 3652 this.set( owner, key, value );
nicholas@2224 3653
nicholas@2224 3654 // Since the "set" path can have two possible entry points
nicholas@2224 3655 // return the expected data based on which path was taken[*]
nicholas@2224 3656 return value !== undefined ? value : key;
nicholas@2224 3657 },
nicholas@2224 3658 remove: function( owner, key ) {
nicholas@2224 3659 var i, name, camel,
nicholas@2224 3660 unlock = this.key( owner ),
nicholas@2224 3661 cache = this.cache[ unlock ];
nicholas@2224 3662
nicholas@2224 3663 if ( key === undefined ) {
nicholas@2224 3664 this.cache[ unlock ] = {};
nicholas@2224 3665
nicholas@2224 3666 } else {
nicholas@2224 3667 // Support array or space separated string of keys
nicholas@2224 3668 if ( jQuery.isArray( key ) ) {
nicholas@2224 3669 // If "name" is an array of keys...
nicholas@2224 3670 // When data is initially created, via ("key", "val") signature,
nicholas@2224 3671 // keys will be converted to camelCase.
nicholas@2224 3672 // Since there is no way to tell _how_ a key was added, remove
nicholas@2224 3673 // both plain key and camelCase key. #12786
nicholas@2224 3674 // This will only penalize the array argument path.
nicholas@2224 3675 name = key.concat( key.map( jQuery.camelCase ) );
nicholas@2224 3676 } else {
nicholas@2224 3677 camel = jQuery.camelCase( key );
nicholas@2224 3678 // Try the string as a key before any manipulation
nicholas@2224 3679 if ( key in cache ) {
nicholas@2224 3680 name = [ key, camel ];
nicholas@2224 3681 } else {
nicholas@2224 3682 // If a key with the spaces exists, use it.
nicholas@2224 3683 // Otherwise, create an array by matching non-whitespace
nicholas@2224 3684 name = camel;
nicholas@2224 3685 name = name in cache ?
nicholas@2224 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nicholas@2224 3687 }
nicholas@2224 3688 }
nicholas@2224 3689
nicholas@2224 3690 i = name.length;
nicholas@2224 3691 while ( i-- ) {
nicholas@2224 3692 delete cache[ name[ i ] ];
nicholas@2224 3693 }
nicholas@2224 3694 }
nicholas@2224 3695 },
nicholas@2224 3696 hasData: function( owner ) {
nicholas@2224 3697 return !jQuery.isEmptyObject(
nicholas@2224 3698 this.cache[ owner[ this.expando ] ] || {}
nicholas@2224 3699 );
nicholas@2224 3700 },
nicholas@2224 3701 discard: function( owner ) {
nicholas@2224 3702 if ( owner[ this.expando ] ) {
nicholas@2224 3703 delete this.cache[ owner[ this.expando ] ];
nicholas@2224 3704 }
nicholas@2224 3705 }
nicholas@2224 3706 };
nicholas@2224 3707 var data_priv = new Data();
nicholas@2224 3708
nicholas@2224 3709 var data_user = new Data();
nicholas@2224 3710
nicholas@2224 3711
nicholas@2224 3712
nicholas@2224 3713 // Implementation Summary
nicholas@2224 3714 //
nicholas@2224 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nicholas@2224 3716 // 2. Improve the module's maintainability by reducing the storage
nicholas@2224 3717 // paths to a single mechanism.
nicholas@2224 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nicholas@2224 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nicholas@2224 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nicholas@2224 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nicholas@2224 3722
nicholas@2224 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nicholas@2224 3724 rmultiDash = /([A-Z])/g;
nicholas@2224 3725
nicholas@2224 3726 function dataAttr( elem, key, data ) {
nicholas@2224 3727 var name;
nicholas@2224 3728
nicholas@2224 3729 // If nothing was found internally, try to fetch any
nicholas@2224 3730 // data from the HTML5 data-* attribute
nicholas@2224 3731 if ( data === undefined && elem.nodeType === 1 ) {
nicholas@2224 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nicholas@2224 3733 data = elem.getAttribute( name );
nicholas@2224 3734
nicholas@2224 3735 if ( typeof data === "string" ) {
nicholas@2224 3736 try {
nicholas@2224 3737 data = data === "true" ? true :
nicholas@2224 3738 data === "false" ? false :
nicholas@2224 3739 data === "null" ? null :
nicholas@2224 3740 // Only convert to a number if it doesn't change the string
nicholas@2224 3741 +data + "" === data ? +data :
nicholas@2224 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nicholas@2224 3743 data;
nicholas@2224 3744 } catch( e ) {}
nicholas@2224 3745
nicholas@2224 3746 // Make sure we set the data so it isn't changed later
nicholas@2224 3747 data_user.set( elem, key, data );
nicholas@2224 3748 } else {
nicholas@2224 3749 data = undefined;
nicholas@2224 3750 }
nicholas@2224 3751 }
nicholas@2224 3752 return data;
nicholas@2224 3753 }
nicholas@2224 3754
nicholas@2224 3755 jQuery.extend({
nicholas@2224 3756 hasData: function( elem ) {
nicholas@2224 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nicholas@2224 3758 },
nicholas@2224 3759
nicholas@2224 3760 data: function( elem, name, data ) {
nicholas@2224 3761 return data_user.access( elem, name, data );
nicholas@2224 3762 },
nicholas@2224 3763
nicholas@2224 3764 removeData: function( elem, name ) {
nicholas@2224 3765 data_user.remove( elem, name );
nicholas@2224 3766 },
nicholas@2224 3767
nicholas@2224 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nicholas@2224 3769 // with direct calls to data_priv methods, these can be deprecated.
nicholas@2224 3770 _data: function( elem, name, data ) {
nicholas@2224 3771 return data_priv.access( elem, name, data );
nicholas@2224 3772 },
nicholas@2224 3773
nicholas@2224 3774 _removeData: function( elem, name ) {
nicholas@2224 3775 data_priv.remove( elem, name );
nicholas@2224 3776 }
nicholas@2224 3777 });
nicholas@2224 3778
nicholas@2224 3779 jQuery.fn.extend({
nicholas@2224 3780 data: function( key, value ) {
nicholas@2224 3781 var i, name, data,
nicholas@2224 3782 elem = this[ 0 ],
nicholas@2224 3783 attrs = elem && elem.attributes;
nicholas@2224 3784
nicholas@2224 3785 // Gets all values
nicholas@2224 3786 if ( key === undefined ) {
nicholas@2224 3787 if ( this.length ) {
nicholas@2224 3788 data = data_user.get( elem );
nicholas@2224 3789
nicholas@2224 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nicholas@2224 3791 i = attrs.length;
nicholas@2224 3792 while ( i-- ) {
nicholas@2224 3793
nicholas@2224 3794 // Support: IE11+
nicholas@2224 3795 // The attrs elements can be null (#14894)
nicholas@2224 3796 if ( attrs[ i ] ) {
nicholas@2224 3797 name = attrs[ i ].name;
nicholas@2224 3798 if ( name.indexOf( "data-" ) === 0 ) {
nicholas@2224 3799 name = jQuery.camelCase( name.slice(5) );
nicholas@2224 3800 dataAttr( elem, name, data[ name ] );
nicholas@2224 3801 }
nicholas@2224 3802 }
nicholas@2224 3803 }
nicholas@2224 3804 data_priv.set( elem, "hasDataAttrs", true );
nicholas@2224 3805 }
nicholas@2224 3806 }
nicholas@2224 3807
nicholas@2224 3808 return data;
nicholas@2224 3809 }
nicholas@2224 3810
nicholas@2224 3811 // Sets multiple values
nicholas@2224 3812 if ( typeof key === "object" ) {
nicholas@2224 3813 return this.each(function() {
nicholas@2224 3814 data_user.set( this, key );
nicholas@2224 3815 });
nicholas@2224 3816 }
nicholas@2224 3817
nicholas@2224 3818 return access( this, function( value ) {
nicholas@2224 3819 var data,
nicholas@2224 3820 camelKey = jQuery.camelCase( key );
nicholas@2224 3821
nicholas@2224 3822 // The calling jQuery object (element matches) is not empty
nicholas@2224 3823 // (and therefore has an element appears at this[ 0 ]) and the
nicholas@2224 3824 // `value` parameter was not undefined. An empty jQuery object
nicholas@2224 3825 // will result in `undefined` for elem = this[ 0 ] which will
nicholas@2224 3826 // throw an exception if an attempt to read a data cache is made.
nicholas@2224 3827 if ( elem && value === undefined ) {
nicholas@2224 3828 // Attempt to get data from the cache
nicholas@2224 3829 // with the key as-is
nicholas@2224 3830 data = data_user.get( elem, key );
nicholas@2224 3831 if ( data !== undefined ) {
nicholas@2224 3832 return data;
nicholas@2224 3833 }
nicholas@2224 3834
nicholas@2224 3835 // Attempt to get data from the cache
nicholas@2224 3836 // with the key camelized
nicholas@2224 3837 data = data_user.get( elem, camelKey );
nicholas@2224 3838 if ( data !== undefined ) {
nicholas@2224 3839 return data;
nicholas@2224 3840 }
nicholas@2224 3841
nicholas@2224 3842 // Attempt to "discover" the data in
nicholas@2224 3843 // HTML5 custom data-* attrs
nicholas@2224 3844 data = dataAttr( elem, camelKey, undefined );
nicholas@2224 3845 if ( data !== undefined ) {
nicholas@2224 3846 return data;
nicholas@2224 3847 }
nicholas@2224 3848
nicholas@2224 3849 // We tried really hard, but the data doesn't exist.
nicholas@2224 3850 return;
nicholas@2224 3851 }
nicholas@2224 3852
nicholas@2224 3853 // Set the data...
nicholas@2224 3854 this.each(function() {
nicholas@2224 3855 // First, attempt to store a copy or reference of any
nicholas@2224 3856 // data that might've been store with a camelCased key.
nicholas@2224 3857 var data = data_user.get( this, camelKey );
nicholas@2224 3858
nicholas@2224 3859 // For HTML5 data-* attribute interop, we have to
nicholas@2224 3860 // store property names with dashes in a camelCase form.
nicholas@2224 3861 // This might not apply to all properties...*
nicholas@2224 3862 data_user.set( this, camelKey, value );
nicholas@2224 3863
nicholas@2224 3864 // *... In the case of properties that might _actually_
nicholas@2224 3865 // have dashes, we need to also store a copy of that
nicholas@2224 3866 // unchanged property.
nicholas@2224 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nicholas@2224 3868 data_user.set( this, key, value );
nicholas@2224 3869 }
nicholas@2224 3870 });
nicholas@2224 3871 }, null, value, arguments.length > 1, null, true );
nicholas@2224 3872 },
nicholas@2224 3873
nicholas@2224 3874 removeData: function( key ) {
nicholas@2224 3875 return this.each(function() {
nicholas@2224 3876 data_user.remove( this, key );
nicholas@2224 3877 });
nicholas@2224 3878 }
nicholas@2224 3879 });
nicholas@2224 3880
nicholas@2224 3881
nicholas@2224 3882 jQuery.extend({
nicholas@2224 3883 queue: function( elem, type, data ) {
nicholas@2224 3884 var queue;
nicholas@2224 3885
nicholas@2224 3886 if ( elem ) {
nicholas@2224 3887 type = ( type || "fx" ) + "queue";
nicholas@2224 3888 queue = data_priv.get( elem, type );
nicholas@2224 3889
nicholas@2224 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nicholas@2224 3891 if ( data ) {
nicholas@2224 3892 if ( !queue || jQuery.isArray( data ) ) {
nicholas@2224 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nicholas@2224 3894 } else {
nicholas@2224 3895 queue.push( data );
nicholas@2224 3896 }
nicholas@2224 3897 }
nicholas@2224 3898 return queue || [];
nicholas@2224 3899 }
nicholas@2224 3900 },
nicholas@2224 3901
nicholas@2224 3902 dequeue: function( elem, type ) {
nicholas@2224 3903 type = type || "fx";
nicholas@2224 3904
nicholas@2224 3905 var queue = jQuery.queue( elem, type ),
nicholas@2224 3906 startLength = queue.length,
nicholas@2224 3907 fn = queue.shift(),
nicholas@2224 3908 hooks = jQuery._queueHooks( elem, type ),
nicholas@2224 3909 next = function() {
nicholas@2224 3910 jQuery.dequeue( elem, type );
nicholas@2224 3911 };
nicholas@2224 3912
nicholas@2224 3913 // If the fx queue is dequeued, always remove the progress sentinel
nicholas@2224 3914 if ( fn === "inprogress" ) {
nicholas@2224 3915 fn = queue.shift();
nicholas@2224 3916 startLength--;
nicholas@2224 3917 }
nicholas@2224 3918
nicholas@2224 3919 if ( fn ) {
nicholas@2224 3920
nicholas@2224 3921 // Add a progress sentinel to prevent the fx queue from being
nicholas@2224 3922 // automatically dequeued
nicholas@2224 3923 if ( type === "fx" ) {
nicholas@2224 3924 queue.unshift( "inprogress" );
nicholas@2224 3925 }
nicholas@2224 3926
nicholas@2224 3927 // Clear up the last queue stop function
nicholas@2224 3928 delete hooks.stop;
nicholas@2224 3929 fn.call( elem, next, hooks );
nicholas@2224 3930 }
nicholas@2224 3931
nicholas@2224 3932 if ( !startLength && hooks ) {
nicholas@2224 3933 hooks.empty.fire();
nicholas@2224 3934 }
nicholas@2224 3935 },
nicholas@2224 3936
nicholas@2224 3937 // Not public - generate a queueHooks object, or return the current one
nicholas@2224 3938 _queueHooks: function( elem, type ) {
nicholas@2224 3939 var key = type + "queueHooks";
nicholas@2224 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nicholas@2224 3941 empty: jQuery.Callbacks("once memory").add(function() {
nicholas@2224 3942 data_priv.remove( elem, [ type + "queue", key ] );
nicholas@2224 3943 })
nicholas@2224 3944 });
nicholas@2224 3945 }
nicholas@2224 3946 });
nicholas@2224 3947
nicholas@2224 3948 jQuery.fn.extend({
nicholas@2224 3949 queue: function( type, data ) {
nicholas@2224 3950 var setter = 2;
nicholas@2224 3951
nicholas@2224 3952 if ( typeof type !== "string" ) {
nicholas@2224 3953 data = type;
nicholas@2224 3954 type = "fx";
nicholas@2224 3955 setter--;
nicholas@2224 3956 }
nicholas@2224 3957
nicholas@2224 3958 if ( arguments.length < setter ) {
nicholas@2224 3959 return jQuery.queue( this[0], type );
nicholas@2224 3960 }
nicholas@2224 3961
nicholas@2224 3962 return data === undefined ?
nicholas@2224 3963 this :
nicholas@2224 3964 this.each(function() {
nicholas@2224 3965 var queue = jQuery.queue( this, type, data );
nicholas@2224 3966
nicholas@2224 3967 // Ensure a hooks for this queue
nicholas@2224 3968 jQuery._queueHooks( this, type );
nicholas@2224 3969
nicholas@2224 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nicholas@2224 3971 jQuery.dequeue( this, type );
nicholas@2224 3972 }
nicholas@2224 3973 });
nicholas@2224 3974 },
nicholas@2224 3975 dequeue: function( type ) {
nicholas@2224 3976 return this.each(function() {
nicholas@2224 3977 jQuery.dequeue( this, type );
nicholas@2224 3978 });
nicholas@2224 3979 },
nicholas@2224 3980 clearQueue: function( type ) {
nicholas@2224 3981 return this.queue( type || "fx", [] );
nicholas@2224 3982 },
nicholas@2224 3983 // Get a promise resolved when queues of a certain type
nicholas@2224 3984 // are emptied (fx is the type by default)
nicholas@2224 3985 promise: function( type, obj ) {
nicholas@2224 3986 var tmp,
nicholas@2224 3987 count = 1,
nicholas@2224 3988 defer = jQuery.Deferred(),
nicholas@2224 3989 elements = this,
nicholas@2224 3990 i = this.length,
nicholas@2224 3991 resolve = function() {
nicholas@2224 3992 if ( !( --count ) ) {
nicholas@2224 3993 defer.resolveWith( elements, [ elements ] );
nicholas@2224 3994 }
nicholas@2224 3995 };
nicholas@2224 3996
nicholas@2224 3997 if ( typeof type !== "string" ) {
nicholas@2224 3998 obj = type;
nicholas@2224 3999 type = undefined;
nicholas@2224 4000 }
nicholas@2224 4001 type = type || "fx";
nicholas@2224 4002
nicholas@2224 4003 while ( i-- ) {
nicholas@2224 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nicholas@2224 4005 if ( tmp && tmp.empty ) {
nicholas@2224 4006 count++;
nicholas@2224 4007 tmp.empty.add( resolve );
nicholas@2224 4008 }
nicholas@2224 4009 }
nicholas@2224 4010 resolve();
nicholas@2224 4011 return defer.promise( obj );
nicholas@2224 4012 }
nicholas@2224 4013 });
nicholas@2224 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nicholas@2224 4015
nicholas@2224 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nicholas@2224 4017
nicholas@2224 4018 var isHidden = function( elem, el ) {
nicholas@2224 4019 // isHidden might be called from jQuery#filter function;
nicholas@2224 4020 // in that case, element will be second argument
nicholas@2224 4021 elem = el || elem;
nicholas@2224 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nicholas@2224 4023 };
nicholas@2224 4024
nicholas@2224 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nicholas@2224 4026
nicholas@2224 4027
nicholas@2224 4028
nicholas@2224 4029 (function() {
nicholas@2224 4030 var fragment = document.createDocumentFragment(),
nicholas@2224 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nicholas@2224 4032 input = document.createElement( "input" );
nicholas@2224 4033
nicholas@2224 4034 // Support: Safari<=5.1
nicholas@2224 4035 // Check state lost if the name is set (#11217)
nicholas@2224 4036 // Support: Windows Web Apps (WWA)
nicholas@2224 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nicholas@2224 4038 input.setAttribute( "type", "radio" );
nicholas@2224 4039 input.setAttribute( "checked", "checked" );
nicholas@2224 4040 input.setAttribute( "name", "t" );
nicholas@2224 4041
nicholas@2224 4042 div.appendChild( input );
nicholas@2224 4043
nicholas@2224 4044 // Support: Safari<=5.1, Android<4.2
nicholas@2224 4045 // Older WebKit doesn't clone checked state correctly in fragments
nicholas@2224 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nicholas@2224 4047
nicholas@2224 4048 // Support: IE<=11+
nicholas@2224 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nicholas@2224 4050 div.innerHTML = "<textarea>x</textarea>";
nicholas@2224 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nicholas@2224 4052 })();
nicholas@2224 4053 var strundefined = typeof undefined;
nicholas@2224 4054
nicholas@2224 4055
nicholas@2224 4056
nicholas@2224 4057 support.focusinBubbles = "onfocusin" in window;
nicholas@2224 4058
nicholas@2224 4059
nicholas@2224 4060 var
nicholas@2224 4061 rkeyEvent = /^key/,
nicholas@2224 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nicholas@2224 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nicholas@2224 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nicholas@2224 4065
nicholas@2224 4066 function returnTrue() {
nicholas@2224 4067 return true;
nicholas@2224 4068 }
nicholas@2224 4069
nicholas@2224 4070 function returnFalse() {
nicholas@2224 4071 return false;
nicholas@2224 4072 }
nicholas@2224 4073
nicholas@2224 4074 function safeActiveElement() {
nicholas@2224 4075 try {
nicholas@2224 4076 return document.activeElement;
nicholas@2224 4077 } catch ( err ) { }
nicholas@2224 4078 }
nicholas@2224 4079
nicholas@2224 4080 /*
nicholas@2224 4081 * Helper functions for managing events -- not part of the public interface.
nicholas@2224 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nicholas@2224 4083 */
nicholas@2224 4084 jQuery.event = {
nicholas@2224 4085
nicholas@2224 4086 global: {},
nicholas@2224 4087
nicholas@2224 4088 add: function( elem, types, handler, data, selector ) {
nicholas@2224 4089
nicholas@2224 4090 var handleObjIn, eventHandle, tmp,
nicholas@2224 4091 events, t, handleObj,
nicholas@2224 4092 special, handlers, type, namespaces, origType,
nicholas@2224 4093 elemData = data_priv.get( elem );
nicholas@2224 4094
nicholas@2224 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nicholas@2224 4096 if ( !elemData ) {
nicholas@2224 4097 return;
nicholas@2224 4098 }
nicholas@2224 4099
nicholas@2224 4100 // Caller can pass in an object of custom data in lieu of the handler
nicholas@2224 4101 if ( handler.handler ) {
nicholas@2224 4102 handleObjIn = handler;
nicholas@2224 4103 handler = handleObjIn.handler;
nicholas@2224 4104 selector = handleObjIn.selector;
nicholas@2224 4105 }
nicholas@2224 4106
nicholas@2224 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nicholas@2224 4108 if ( !handler.guid ) {
nicholas@2224 4109 handler.guid = jQuery.guid++;
nicholas@2224 4110 }
nicholas@2224 4111
nicholas@2224 4112 // Init the element's event structure and main handler, if this is the first
nicholas@2224 4113 if ( !(events = elemData.events) ) {
nicholas@2224 4114 events = elemData.events = {};
nicholas@2224 4115 }
nicholas@2224 4116 if ( !(eventHandle = elemData.handle) ) {
nicholas@2224 4117 eventHandle = elemData.handle = function( e ) {
nicholas@2224 4118 // Discard the second event of a jQuery.event.trigger() and
nicholas@2224 4119 // when an event is called after a page has unloaded
nicholas@2224 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nicholas@2224 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nicholas@2224 4122 };
nicholas@2224 4123 }
nicholas@2224 4124
nicholas@2224 4125 // Handle multiple events separated by a space
nicholas@2224 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nicholas@2224 4127 t = types.length;
nicholas@2224 4128 while ( t-- ) {
nicholas@2224 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nicholas@2224 4130 type = origType = tmp[1];
nicholas@2224 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nicholas@2224 4132
nicholas@2224 4133 // There *must* be a type, no attaching namespace-only handlers
nicholas@2224 4134 if ( !type ) {
nicholas@2224 4135 continue;
nicholas@2224 4136 }
nicholas@2224 4137
nicholas@2224 4138 // If event changes its type, use the special event handlers for the changed type
nicholas@2224 4139 special = jQuery.event.special[ type ] || {};
nicholas@2224 4140
nicholas@2224 4141 // If selector defined, determine special event api type, otherwise given type
nicholas@2224 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nicholas@2224 4143
nicholas@2224 4144 // Update special based on newly reset type
nicholas@2224 4145 special = jQuery.event.special[ type ] || {};
nicholas@2224 4146
nicholas@2224 4147 // handleObj is passed to all event handlers
nicholas@2224 4148 handleObj = jQuery.extend({
nicholas@2224 4149 type: type,
nicholas@2224 4150 origType: origType,
nicholas@2224 4151 data: data,
nicholas@2224 4152 handler: handler,
nicholas@2224 4153 guid: handler.guid,
nicholas@2224 4154 selector: selector,
nicholas@2224 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nicholas@2224 4156 namespace: namespaces.join(".")
nicholas@2224 4157 }, handleObjIn );
nicholas@2224 4158
nicholas@2224 4159 // Init the event handler queue if we're the first
nicholas@2224 4160 if ( !(handlers = events[ type ]) ) {
nicholas@2224 4161 handlers = events[ type ] = [];
nicholas@2224 4162 handlers.delegateCount = 0;
nicholas@2224 4163
nicholas@2224 4164 // Only use addEventListener if the special events handler returns false
nicholas@2224 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nicholas@2224 4166 if ( elem.addEventListener ) {
nicholas@2224 4167 elem.addEventListener( type, eventHandle, false );
nicholas@2224 4168 }
nicholas@2224 4169 }
nicholas@2224 4170 }
nicholas@2224 4171
nicholas@2224 4172 if ( special.add ) {
nicholas@2224 4173 special.add.call( elem, handleObj );
nicholas@2224 4174
nicholas@2224 4175 if ( !handleObj.handler.guid ) {
nicholas@2224 4176 handleObj.handler.guid = handler.guid;
nicholas@2224 4177 }
nicholas@2224 4178 }
nicholas@2224 4179
nicholas@2224 4180 // Add to the element's handler list, delegates in front
nicholas@2224 4181 if ( selector ) {
nicholas@2224 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nicholas@2224 4183 } else {
nicholas@2224 4184 handlers.push( handleObj );
nicholas@2224 4185 }
nicholas@2224 4186
nicholas@2224 4187 // Keep track of which events have ever been used, for event optimization
nicholas@2224 4188 jQuery.event.global[ type ] = true;
nicholas@2224 4189 }
nicholas@2224 4190
nicholas@2224 4191 },
nicholas@2224 4192
nicholas@2224 4193 // Detach an event or set of events from an element
nicholas@2224 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nicholas@2224 4195
nicholas@2224 4196 var j, origCount, tmp,
nicholas@2224 4197 events, t, handleObj,
nicholas@2224 4198 special, handlers, type, namespaces, origType,
nicholas@2224 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nicholas@2224 4200
nicholas@2224 4201 if ( !elemData || !(events = elemData.events) ) {
nicholas@2224 4202 return;
nicholas@2224 4203 }
nicholas@2224 4204
nicholas@2224 4205 // Once for each type.namespace in types; type may be omitted
nicholas@2224 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nicholas@2224 4207 t = types.length;
nicholas@2224 4208 while ( t-- ) {
nicholas@2224 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nicholas@2224 4210 type = origType = tmp[1];
nicholas@2224 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nicholas@2224 4212
nicholas@2224 4213 // Unbind all events (on this namespace, if provided) for the element
nicholas@2224 4214 if ( !type ) {
nicholas@2224 4215 for ( type in events ) {
nicholas@2224 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nicholas@2224 4217 }
nicholas@2224 4218 continue;
nicholas@2224 4219 }
nicholas@2224 4220
nicholas@2224 4221 special = jQuery.event.special[ type ] || {};
nicholas@2224 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nicholas@2224 4223 handlers = events[ type ] || [];
nicholas@2224 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nicholas@2224 4225
nicholas@2224 4226 // Remove matching events
nicholas@2224 4227 origCount = j = handlers.length;
nicholas@2224 4228 while ( j-- ) {
nicholas@2224 4229 handleObj = handlers[ j ];
nicholas@2224 4230
nicholas@2224 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nicholas@2224 4232 ( !handler || handler.guid === handleObj.guid ) &&
nicholas@2224 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nicholas@2224 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nicholas@2224 4235 handlers.splice( j, 1 );
nicholas@2224 4236
nicholas@2224 4237 if ( handleObj.selector ) {
nicholas@2224 4238 handlers.delegateCount--;
nicholas@2224 4239 }
nicholas@2224 4240 if ( special.remove ) {
nicholas@2224 4241 special.remove.call( elem, handleObj );
nicholas@2224 4242 }
nicholas@2224 4243 }
nicholas@2224 4244 }
nicholas@2224 4245
nicholas@2224 4246 // Remove generic event handler if we removed something and no more handlers exist
nicholas@2224 4247 // (avoids potential for endless recursion during removal of special event handlers)
nicholas@2224 4248 if ( origCount && !handlers.length ) {
nicholas@2224 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nicholas@2224 4250 jQuery.removeEvent( elem, type, elemData.handle );
nicholas@2224 4251 }
nicholas@2224 4252
nicholas@2224 4253 delete events[ type ];
nicholas@2224 4254 }
nicholas@2224 4255 }
nicholas@2224 4256
nicholas@2224 4257 // Remove the expando if it's no longer used
nicholas@2224 4258 if ( jQuery.isEmptyObject( events ) ) {
nicholas@2224 4259 delete elemData.handle;
nicholas@2224 4260 data_priv.remove( elem, "events" );
nicholas@2224 4261 }
nicholas@2224 4262 },
nicholas@2224 4263
nicholas@2224 4264 trigger: function( event, data, elem, onlyHandlers ) {
nicholas@2224 4265
nicholas@2224 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nicholas@2224 4267 eventPath = [ elem || document ],
nicholas@2224 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nicholas@2224 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nicholas@2224 4270
nicholas@2224 4271 cur = tmp = elem = elem || document;
nicholas@2224 4272
nicholas@2224 4273 // Don't do events on text and comment nodes
nicholas@2224 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nicholas@2224 4275 return;
nicholas@2224 4276 }
nicholas@2224 4277
nicholas@2224 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nicholas@2224 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nicholas@2224 4280 return;
nicholas@2224 4281 }
nicholas@2224 4282
nicholas@2224 4283 if ( type.indexOf(".") >= 0 ) {
nicholas@2224 4284 // Namespaced trigger; create a regexp to match event type in handle()
nicholas@2224 4285 namespaces = type.split(".");
nicholas@2224 4286 type = namespaces.shift();
nicholas@2224 4287 namespaces.sort();
nicholas@2224 4288 }
nicholas@2224 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nicholas@2224 4290
nicholas@2224 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nicholas@2224 4292 event = event[ jQuery.expando ] ?
nicholas@2224 4293 event :
nicholas@2224 4294 new jQuery.Event( type, typeof event === "object" && event );
nicholas@2224 4295
nicholas@2224 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nicholas@2224 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nicholas@2224 4298 event.namespace = namespaces.join(".");
nicholas@2224 4299 event.namespace_re = event.namespace ?
nicholas@2224 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nicholas@2224 4301 null;
nicholas@2224 4302
nicholas@2224 4303 // Clean up the event in case it is being reused
nicholas@2224 4304 event.result = undefined;
nicholas@2224 4305 if ( !event.target ) {
nicholas@2224 4306 event.target = elem;
nicholas@2224 4307 }
nicholas@2224 4308
nicholas@2224 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nicholas@2224 4310 data = data == null ?
nicholas@2224 4311 [ event ] :
nicholas@2224 4312 jQuery.makeArray( data, [ event ] );
nicholas@2224 4313
nicholas@2224 4314 // Allow special events to draw outside the lines
nicholas@2224 4315 special = jQuery.event.special[ type ] || {};
nicholas@2224 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nicholas@2224 4317 return;
nicholas@2224 4318 }
nicholas@2224 4319
nicholas@2224 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nicholas@2224 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nicholas@2224 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nicholas@2224 4323
nicholas@2224 4324 bubbleType = special.delegateType || type;
nicholas@2224 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nicholas@2224 4326 cur = cur.parentNode;
nicholas@2224 4327 }
nicholas@2224 4328 for ( ; cur; cur = cur.parentNode ) {
nicholas@2224 4329 eventPath.push( cur );
nicholas@2224 4330 tmp = cur;
nicholas@2224 4331 }
nicholas@2224 4332
nicholas@2224 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nicholas@2224 4334 if ( tmp === (elem.ownerDocument || document) ) {
nicholas@2224 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nicholas@2224 4336 }
nicholas@2224 4337 }
nicholas@2224 4338
nicholas@2224 4339 // Fire handlers on the event path
nicholas@2224 4340 i = 0;
nicholas@2224 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nicholas@2224 4342
nicholas@2224 4343 event.type = i > 1 ?
nicholas@2224 4344 bubbleType :
nicholas@2224 4345 special.bindType || type;
nicholas@2224 4346
nicholas@2224 4347 // jQuery handler
nicholas@2224 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nicholas@2224 4349 if ( handle ) {
nicholas@2224 4350 handle.apply( cur, data );
nicholas@2224 4351 }
nicholas@2224 4352
nicholas@2224 4353 // Native handler
nicholas@2224 4354 handle = ontype && cur[ ontype ];
nicholas@2224 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nicholas@2224 4356 event.result = handle.apply( cur, data );
nicholas@2224 4357 if ( event.result === false ) {
nicholas@2224 4358 event.preventDefault();
nicholas@2224 4359 }
nicholas@2224 4360 }
nicholas@2224 4361 }
nicholas@2224 4362 event.type = type;
nicholas@2224 4363
nicholas@2224 4364 // If nobody prevented the default action, do it now
nicholas@2224 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nicholas@2224 4366
nicholas@2224 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nicholas@2224 4368 jQuery.acceptData( elem ) ) {
nicholas@2224 4369
nicholas@2224 4370 // Call a native DOM method on the target with the same name name as the event.
nicholas@2224 4371 // Don't do default actions on window, that's where global variables be (#6170)
nicholas@2224 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nicholas@2224 4373
nicholas@2224 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nicholas@2224 4375 tmp = elem[ ontype ];
nicholas@2224 4376
nicholas@2224 4377 if ( tmp ) {
nicholas@2224 4378 elem[ ontype ] = null;
nicholas@2224 4379 }
nicholas@2224 4380
nicholas@2224 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nicholas@2224 4382 jQuery.event.triggered = type;
nicholas@2224 4383 elem[ type ]();
nicholas@2224 4384 jQuery.event.triggered = undefined;
nicholas@2224 4385
nicholas@2224 4386 if ( tmp ) {
nicholas@2224 4387 elem[ ontype ] = tmp;
nicholas@2224 4388 }
nicholas@2224 4389 }
nicholas@2224 4390 }
nicholas@2224 4391 }
nicholas@2224 4392
nicholas@2224 4393 return event.result;
nicholas@2224 4394 },
nicholas@2224 4395
nicholas@2224 4396 dispatch: function( event ) {
nicholas@2224 4397
nicholas@2224 4398 // Make a writable jQuery.Event from the native event object
nicholas@2224 4399 event = jQuery.event.fix( event );
nicholas@2224 4400
nicholas@2224 4401 var i, j, ret, matched, handleObj,
nicholas@2224 4402 handlerQueue = [],
nicholas@2224 4403 args = slice.call( arguments ),
nicholas@2224 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nicholas@2224 4405 special = jQuery.event.special[ event.type ] || {};
nicholas@2224 4406
nicholas@2224 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nicholas@2224 4408 args[0] = event;
nicholas@2224 4409 event.delegateTarget = this;
nicholas@2224 4410
nicholas@2224 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nicholas@2224 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nicholas@2224 4413 return;
nicholas@2224 4414 }
nicholas@2224 4415
nicholas@2224 4416 // Determine handlers
nicholas@2224 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nicholas@2224 4418
nicholas@2224 4419 // Run delegates first; they may want to stop propagation beneath us
nicholas@2224 4420 i = 0;
nicholas@2224 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nicholas@2224 4422 event.currentTarget = matched.elem;
nicholas@2224 4423
nicholas@2224 4424 j = 0;
nicholas@2224 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nicholas@2224 4426
nicholas@2224 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nicholas@2224 4428 // a subset or equal to those in the bound event (both can have no namespace).
nicholas@2224 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nicholas@2224 4430
nicholas@2224 4431 event.handleObj = handleObj;
nicholas@2224 4432 event.data = handleObj.data;
nicholas@2224 4433
nicholas@2224 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nicholas@2224 4435 .apply( matched.elem, args );
nicholas@2224 4436
nicholas@2224 4437 if ( ret !== undefined ) {
nicholas@2224 4438 if ( (event.result = ret) === false ) {
nicholas@2224 4439 event.preventDefault();
nicholas@2224 4440 event.stopPropagation();
nicholas@2224 4441 }
nicholas@2224 4442 }
nicholas@2224 4443 }
nicholas@2224 4444 }
nicholas@2224 4445 }
nicholas@2224 4446
nicholas@2224 4447 // Call the postDispatch hook for the mapped type
nicholas@2224 4448 if ( special.postDispatch ) {
nicholas@2224 4449 special.postDispatch.call( this, event );
nicholas@2224 4450 }
nicholas@2224 4451
nicholas@2224 4452 return event.result;
nicholas@2224 4453 },
nicholas@2224 4454
nicholas@2224 4455 handlers: function( event, handlers ) {
nicholas@2224 4456 var i, matches, sel, handleObj,
nicholas@2224 4457 handlerQueue = [],
nicholas@2224 4458 delegateCount = handlers.delegateCount,
nicholas@2224 4459 cur = event.target;
nicholas@2224 4460
nicholas@2224 4461 // Find delegate handlers
nicholas@2224 4462 // Black-hole SVG <use> instance trees (#13180)
nicholas@2224 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nicholas@2224 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nicholas@2224 4465
nicholas@2224 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nicholas@2224 4467
nicholas@2224 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nicholas@2224 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nicholas@2224 4470 matches = [];
nicholas@2224 4471 for ( i = 0; i < delegateCount; i++ ) {
nicholas@2224 4472 handleObj = handlers[ i ];
nicholas@2224 4473
nicholas@2224 4474 // Don't conflict with Object.prototype properties (#13203)
nicholas@2224 4475 sel = handleObj.selector + " ";
nicholas@2224 4476
nicholas@2224 4477 if ( matches[ sel ] === undefined ) {
nicholas@2224 4478 matches[ sel ] = handleObj.needsContext ?
nicholas@2224 4479 jQuery( sel, this ).index( cur ) >= 0 :
nicholas@2224 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nicholas@2224 4481 }
nicholas@2224 4482 if ( matches[ sel ] ) {
nicholas@2224 4483 matches.push( handleObj );
nicholas@2224 4484 }
nicholas@2224 4485 }
nicholas@2224 4486 if ( matches.length ) {
nicholas@2224 4487 handlerQueue.push({ elem: cur, handlers: matches });
nicholas@2224 4488 }
nicholas@2224 4489 }
nicholas@2224 4490 }
nicholas@2224 4491 }
nicholas@2224 4492
nicholas@2224 4493 // Add the remaining (directly-bound) handlers
nicholas@2224 4494 if ( delegateCount < handlers.length ) {
nicholas@2224 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nicholas@2224 4496 }
nicholas@2224 4497
nicholas@2224 4498 return handlerQueue;
nicholas@2224 4499 },
nicholas@2224 4500
nicholas@2224 4501 // Includes some event props shared by KeyEvent and MouseEvent
nicholas@2224 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nicholas@2224 4503
nicholas@2224 4504 fixHooks: {},
nicholas@2224 4505
nicholas@2224 4506 keyHooks: {
nicholas@2224 4507 props: "char charCode key keyCode".split(" "),
nicholas@2224 4508 filter: function( event, original ) {
nicholas@2224 4509
nicholas@2224 4510 // Add which for key events
nicholas@2224 4511 if ( event.which == null ) {
nicholas@2224 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nicholas@2224 4513 }
nicholas@2224 4514
nicholas@2224 4515 return event;
nicholas@2224 4516 }
nicholas@2224 4517 },
nicholas@2224 4518
nicholas@2224 4519 mouseHooks: {
nicholas@2224 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nicholas@2224 4521 filter: function( event, original ) {
nicholas@2224 4522 var eventDoc, doc, body,
nicholas@2224 4523 button = original.button;
nicholas@2224 4524
nicholas@2224 4525 // Calculate pageX/Y if missing and clientX/Y available
nicholas@2224 4526 if ( event.pageX == null && original.clientX != null ) {
nicholas@2224 4527 eventDoc = event.target.ownerDocument || document;
nicholas@2224 4528 doc = eventDoc.documentElement;
nicholas@2224 4529 body = eventDoc.body;
nicholas@2224 4530
nicholas@2224 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nicholas@2224 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nicholas@2224 4533 }
nicholas@2224 4534
nicholas@2224 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nicholas@2224 4536 // Note: button is not normalized, so don't use it
nicholas@2224 4537 if ( !event.which && button !== undefined ) {
nicholas@2224 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nicholas@2224 4539 }
nicholas@2224 4540
nicholas@2224 4541 return event;
nicholas@2224 4542 }
nicholas@2224 4543 },
nicholas@2224 4544
nicholas@2224 4545 fix: function( event ) {
nicholas@2224 4546 if ( event[ jQuery.expando ] ) {
nicholas@2224 4547 return event;
nicholas@2224 4548 }
nicholas@2224 4549
nicholas@2224 4550 // Create a writable copy of the event object and normalize some properties
nicholas@2224 4551 var i, prop, copy,
nicholas@2224 4552 type = event.type,
nicholas@2224 4553 originalEvent = event,
nicholas@2224 4554 fixHook = this.fixHooks[ type ];
nicholas@2224 4555
nicholas@2224 4556 if ( !fixHook ) {
nicholas@2224 4557 this.fixHooks[ type ] = fixHook =
nicholas@2224 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nicholas@2224 4559 rkeyEvent.test( type ) ? this.keyHooks :
nicholas@2224 4560 {};
nicholas@2224 4561 }
nicholas@2224 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nicholas@2224 4563
nicholas@2224 4564 event = new jQuery.Event( originalEvent );
nicholas@2224 4565
nicholas@2224 4566 i = copy.length;
nicholas@2224 4567 while ( i-- ) {
nicholas@2224 4568 prop = copy[ i ];
nicholas@2224 4569 event[ prop ] = originalEvent[ prop ];
nicholas@2224 4570 }
nicholas@2224 4571
nicholas@2224 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nicholas@2224 4573 // All events should have a target; Cordova deviceready doesn't
nicholas@2224 4574 if ( !event.target ) {
nicholas@2224 4575 event.target = document;
nicholas@2224 4576 }
nicholas@2224 4577
nicholas@2224 4578 // Support: Safari 6.0+, Chrome<28
nicholas@2224 4579 // Target should not be a text node (#504, #13143)
nicholas@2224 4580 if ( event.target.nodeType === 3 ) {
nicholas@2224 4581 event.target = event.target.parentNode;
nicholas@2224 4582 }
nicholas@2224 4583
nicholas@2224 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nicholas@2224 4585 },
nicholas@2224 4586
nicholas@2224 4587 special: {
nicholas@2224 4588 load: {
nicholas@2224 4589 // Prevent triggered image.load events from bubbling to window.load
nicholas@2224 4590 noBubble: true
nicholas@2224 4591 },
nicholas@2224 4592 focus: {
nicholas@2224 4593 // Fire native event if possible so blur/focus sequence is correct
nicholas@2224 4594 trigger: function() {
nicholas@2224 4595 if ( this !== safeActiveElement() && this.focus ) {
nicholas@2224 4596 this.focus();
nicholas@2224 4597 return false;
nicholas@2224 4598 }
nicholas@2224 4599 },
nicholas@2224 4600 delegateType: "focusin"
nicholas@2224 4601 },
nicholas@2224 4602 blur: {
nicholas@2224 4603 trigger: function() {
nicholas@2224 4604 if ( this === safeActiveElement() && this.blur ) {
nicholas@2224 4605 this.blur();
nicholas@2224 4606 return false;
nicholas@2224 4607 }
nicholas@2224 4608 },
nicholas@2224 4609 delegateType: "focusout"
nicholas@2224 4610 },
nicholas@2224 4611 click: {
nicholas@2224 4612 // For checkbox, fire native event so checked state will be right
nicholas@2224 4613 trigger: function() {
nicholas@2224 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nicholas@2224 4615 this.click();
nicholas@2224 4616 return false;
nicholas@2224 4617 }
nicholas@2224 4618 },
nicholas@2224 4619
nicholas@2224 4620 // For cross-browser consistency, don't fire native .click() on links
nicholas@2224 4621 _default: function( event ) {
nicholas@2224 4622 return jQuery.nodeName( event.target, "a" );
nicholas@2224 4623 }
nicholas@2224 4624 },
nicholas@2224 4625
nicholas@2224 4626 beforeunload: {
nicholas@2224 4627 postDispatch: function( event ) {
nicholas@2224 4628
nicholas@2224 4629 // Support: Firefox 20+
nicholas@2224 4630 // Firefox doesn't alert if the returnValue field is not set.
nicholas@2224 4631 if ( event.result !== undefined && event.originalEvent ) {
nicholas@2224 4632 event.originalEvent.returnValue = event.result;
nicholas@2224 4633 }
nicholas@2224 4634 }
nicholas@2224 4635 }
nicholas@2224 4636 },
nicholas@2224 4637
nicholas@2224 4638 simulate: function( type, elem, event, bubble ) {
nicholas@2224 4639 // Piggyback on a donor event to simulate a different one.
nicholas@2224 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nicholas@2224 4641 // simulated event prevents default then we do the same on the donor.
nicholas@2224 4642 var e = jQuery.extend(
nicholas@2224 4643 new jQuery.Event(),
nicholas@2224 4644 event,
nicholas@2224 4645 {
nicholas@2224 4646 type: type,
nicholas@2224 4647 isSimulated: true,
nicholas@2224 4648 originalEvent: {}
nicholas@2224 4649 }
nicholas@2224 4650 );
nicholas@2224 4651 if ( bubble ) {
nicholas@2224 4652 jQuery.event.trigger( e, null, elem );
nicholas@2224 4653 } else {
nicholas@2224 4654 jQuery.event.dispatch.call( elem, e );
nicholas@2224 4655 }
nicholas@2224 4656 if ( e.isDefaultPrevented() ) {
nicholas@2224 4657 event.preventDefault();
nicholas@2224 4658 }
nicholas@2224 4659 }
nicholas@2224 4660 };
nicholas@2224 4661
nicholas@2224 4662 jQuery.removeEvent = function( elem, type, handle ) {
nicholas@2224 4663 if ( elem.removeEventListener ) {
nicholas@2224 4664 elem.removeEventListener( type, handle, false );
nicholas@2224 4665 }
nicholas@2224 4666 };
nicholas@2224 4667
nicholas@2224 4668 jQuery.Event = function( src, props ) {
nicholas@2224 4669 // Allow instantiation without the 'new' keyword
nicholas@2224 4670 if ( !(this instanceof jQuery.Event) ) {
nicholas@2224 4671 return new jQuery.Event( src, props );
nicholas@2224 4672 }
nicholas@2224 4673
nicholas@2224 4674 // Event object
nicholas@2224 4675 if ( src && src.type ) {
nicholas@2224 4676 this.originalEvent = src;
nicholas@2224 4677 this.type = src.type;
nicholas@2224 4678
nicholas@2224 4679 // Events bubbling up the document may have been marked as prevented
nicholas@2224 4680 // by a handler lower down the tree; reflect the correct value.
nicholas@2224 4681 this.isDefaultPrevented = src.defaultPrevented ||
nicholas@2224 4682 src.defaultPrevented === undefined &&
nicholas@2224 4683 // Support: Android<4.0
nicholas@2224 4684 src.returnValue === false ?
nicholas@2224 4685 returnTrue :
nicholas@2224 4686 returnFalse;
nicholas@2224 4687
nicholas@2224 4688 // Event type
nicholas@2224 4689 } else {
nicholas@2224 4690 this.type = src;
nicholas@2224 4691 }
nicholas@2224 4692
nicholas@2224 4693 // Put explicitly provided properties onto the event object
nicholas@2224 4694 if ( props ) {
nicholas@2224 4695 jQuery.extend( this, props );
nicholas@2224 4696 }
nicholas@2224 4697
nicholas@2224 4698 // Create a timestamp if incoming event doesn't have one
nicholas@2224 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nicholas@2224 4700
nicholas@2224 4701 // Mark it as fixed
nicholas@2224 4702 this[ jQuery.expando ] = true;
nicholas@2224 4703 };
nicholas@2224 4704
nicholas@2224 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nicholas@2224 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nicholas@2224 4707 jQuery.Event.prototype = {
nicholas@2224 4708 isDefaultPrevented: returnFalse,
nicholas@2224 4709 isPropagationStopped: returnFalse,
nicholas@2224 4710 isImmediatePropagationStopped: returnFalse,
nicholas@2224 4711
nicholas@2224 4712 preventDefault: function() {
nicholas@2224 4713 var e = this.originalEvent;
nicholas@2224 4714
nicholas@2224 4715 this.isDefaultPrevented = returnTrue;
nicholas@2224 4716
nicholas@2224 4717 if ( e && e.preventDefault ) {
nicholas@2224 4718 e.preventDefault();
nicholas@2224 4719 }
nicholas@2224 4720 },
nicholas@2224 4721 stopPropagation: function() {
nicholas@2224 4722 var e = this.originalEvent;
nicholas@2224 4723
nicholas@2224 4724 this.isPropagationStopped = returnTrue;
nicholas@2224 4725
nicholas@2224 4726 if ( e && e.stopPropagation ) {
nicholas@2224 4727 e.stopPropagation();
nicholas@2224 4728 }
nicholas@2224 4729 },
nicholas@2224 4730 stopImmediatePropagation: function() {
nicholas@2224 4731 var e = this.originalEvent;
nicholas@2224 4732
nicholas@2224 4733 this.isImmediatePropagationStopped = returnTrue;
nicholas@2224 4734
nicholas@2224 4735 if ( e && e.stopImmediatePropagation ) {
nicholas@2224 4736 e.stopImmediatePropagation();
nicholas@2224 4737 }
nicholas@2224 4738
nicholas@2224 4739 this.stopPropagation();
nicholas@2224 4740 }
nicholas@2224 4741 };
nicholas@2224 4742
nicholas@2224 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nicholas@2224 4744 // Support: Chrome 15+
nicholas@2224 4745 jQuery.each({
nicholas@2224 4746 mouseenter: "mouseover",
nicholas@2224 4747 mouseleave: "mouseout",
nicholas@2224 4748 pointerenter: "pointerover",
nicholas@2224 4749 pointerleave: "pointerout"
nicholas@2224 4750 }, function( orig, fix ) {
nicholas@2224 4751 jQuery.event.special[ orig ] = {
nicholas@2224 4752 delegateType: fix,
nicholas@2224 4753 bindType: fix,
nicholas@2224 4754
nicholas@2224 4755 handle: function( event ) {
nicholas@2224 4756 var ret,
nicholas@2224 4757 target = this,
nicholas@2224 4758 related = event.relatedTarget,
nicholas@2224 4759 handleObj = event.handleObj;
nicholas@2224 4760
nicholas@2224 4761 // For mousenter/leave call the handler if related is outside the target.
nicholas@2224 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nicholas@2224 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nicholas@2224 4764 event.type = handleObj.origType;
nicholas@2224 4765 ret = handleObj.handler.apply( this, arguments );
nicholas@2224 4766 event.type = fix;
nicholas@2224 4767 }
nicholas@2224 4768 return ret;
nicholas@2224 4769 }
nicholas@2224 4770 };
nicholas@2224 4771 });
nicholas@2224 4772
nicholas@2224 4773 // Support: Firefox, Chrome, Safari
nicholas@2224 4774 // Create "bubbling" focus and blur events
nicholas@2224 4775 if ( !support.focusinBubbles ) {
nicholas@2224 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nicholas@2224 4777
nicholas@2224 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nicholas@2224 4779 var handler = function( event ) {
nicholas@2224 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nicholas@2224 4781 };
nicholas@2224 4782
nicholas@2224 4783 jQuery.event.special[ fix ] = {
nicholas@2224 4784 setup: function() {
nicholas@2224 4785 var doc = this.ownerDocument || this,
nicholas@2224 4786 attaches = data_priv.access( doc, fix );
nicholas@2224 4787
nicholas@2224 4788 if ( !attaches ) {
nicholas@2224 4789 doc.addEventListener( orig, handler, true );
nicholas@2224 4790 }
nicholas@2224 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nicholas@2224 4792 },
nicholas@2224 4793 teardown: function() {
nicholas@2224 4794 var doc = this.ownerDocument || this,
nicholas@2224 4795 attaches = data_priv.access( doc, fix ) - 1;
nicholas@2224 4796
nicholas@2224 4797 if ( !attaches ) {
nicholas@2224 4798 doc.removeEventListener( orig, handler, true );
nicholas@2224 4799 data_priv.remove( doc, fix );
nicholas@2224 4800
nicholas@2224 4801 } else {
nicholas@2224 4802 data_priv.access( doc, fix, attaches );
nicholas@2224 4803 }
nicholas@2224 4804 }
nicholas@2224 4805 };
nicholas@2224 4806 });
nicholas@2224 4807 }
nicholas@2224 4808
nicholas@2224 4809 jQuery.fn.extend({
nicholas@2224 4810
nicholas@2224 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nicholas@2224 4812 var origFn, type;
nicholas@2224 4813
nicholas@2224 4814 // Types can be a map of types/handlers
nicholas@2224 4815 if ( typeof types === "object" ) {
nicholas@2224 4816 // ( types-Object, selector, data )
nicholas@2224 4817 if ( typeof selector !== "string" ) {
nicholas@2224 4818 // ( types-Object, data )
nicholas@2224 4819 data = data || selector;
nicholas@2224 4820 selector = undefined;
nicholas@2224 4821 }
nicholas@2224 4822 for ( type in types ) {
nicholas@2224 4823 this.on( type, selector, data, types[ type ], one );
nicholas@2224 4824 }
nicholas@2224 4825 return this;
nicholas@2224 4826 }
nicholas@2224 4827
nicholas@2224 4828 if ( data == null && fn == null ) {
nicholas@2224 4829 // ( types, fn )
nicholas@2224 4830 fn = selector;
nicholas@2224 4831 data = selector = undefined;
nicholas@2224 4832 } else if ( fn == null ) {
nicholas@2224 4833 if ( typeof selector === "string" ) {
nicholas@2224 4834 // ( types, selector, fn )
nicholas@2224 4835 fn = data;
nicholas@2224 4836 data = undefined;
nicholas@2224 4837 } else {
nicholas@2224 4838 // ( types, data, fn )
nicholas@2224 4839 fn = data;
nicholas@2224 4840 data = selector;
nicholas@2224 4841 selector = undefined;
nicholas@2224 4842 }
nicholas@2224 4843 }
nicholas@2224 4844 if ( fn === false ) {
nicholas@2224 4845 fn = returnFalse;
nicholas@2224 4846 } else if ( !fn ) {
nicholas@2224 4847 return this;
nicholas@2224 4848 }
nicholas@2224 4849
nicholas@2224 4850 if ( one === 1 ) {
nicholas@2224 4851 origFn = fn;
nicholas@2224 4852 fn = function( event ) {
nicholas@2224 4853 // Can use an empty set, since event contains the info
nicholas@2224 4854 jQuery().off( event );
nicholas@2224 4855 return origFn.apply( this, arguments );
nicholas@2224 4856 };
nicholas@2224 4857 // Use same guid so caller can remove using origFn
nicholas@2224 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nicholas@2224 4859 }
nicholas@2224 4860 return this.each( function() {
nicholas@2224 4861 jQuery.event.add( this, types, fn, data, selector );
nicholas@2224 4862 });
nicholas@2224 4863 },
nicholas@2224 4864 one: function( types, selector, data, fn ) {
nicholas@2224 4865 return this.on( types, selector, data, fn, 1 );
nicholas@2224 4866 },
nicholas@2224 4867 off: function( types, selector, fn ) {
nicholas@2224 4868 var handleObj, type;
nicholas@2224 4869 if ( types && types.preventDefault && types.handleObj ) {
nicholas@2224 4870 // ( event ) dispatched jQuery.Event
nicholas@2224 4871 handleObj = types.handleObj;
nicholas@2224 4872 jQuery( types.delegateTarget ).off(
nicholas@2224 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nicholas@2224 4874 handleObj.selector,
nicholas@2224 4875 handleObj.handler
nicholas@2224 4876 );
nicholas@2224 4877 return this;
nicholas@2224 4878 }
nicholas@2224 4879 if ( typeof types === "object" ) {
nicholas@2224 4880 // ( types-object [, selector] )
nicholas@2224 4881 for ( type in types ) {
nicholas@2224 4882 this.off( type, selector, types[ type ] );
nicholas@2224 4883 }
nicholas@2224 4884 return this;
nicholas@2224 4885 }
nicholas@2224 4886 if ( selector === false || typeof selector === "function" ) {
nicholas@2224 4887 // ( types [, fn] )
nicholas@2224 4888 fn = selector;
nicholas@2224 4889 selector = undefined;
nicholas@2224 4890 }
nicholas@2224 4891 if ( fn === false ) {
nicholas@2224 4892 fn = returnFalse;
nicholas@2224 4893 }
nicholas@2224 4894 return this.each(function() {
nicholas@2224 4895 jQuery.event.remove( this, types, fn, selector );
nicholas@2224 4896 });
nicholas@2224 4897 },
nicholas@2224 4898
nicholas@2224 4899 trigger: function( type, data ) {
nicholas@2224 4900 return this.each(function() {
nicholas@2224 4901 jQuery.event.trigger( type, data, this );
nicholas@2224 4902 });
nicholas@2224 4903 },
nicholas@2224 4904 triggerHandler: function( type, data ) {
nicholas@2224 4905 var elem = this[0];
nicholas@2224 4906 if ( elem ) {
nicholas@2224 4907 return jQuery.event.trigger( type, data, elem, true );
nicholas@2224 4908 }
nicholas@2224 4909 }
nicholas@2224 4910 });
nicholas@2224 4911
nicholas@2224 4912
nicholas@2224 4913 var
nicholas@2224 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nicholas@2224 4915 rtagName = /<([\w:]+)/,
nicholas@2224 4916 rhtml = /<|&#?\w+;/,
nicholas@2224 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nicholas@2224 4918 // checked="checked" or checked
nicholas@2224 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nicholas@2224 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nicholas@2224 4921 rscriptTypeMasked = /^true\/(.*)/,
nicholas@2224 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nicholas@2224 4923
nicholas@2224 4924 // We have to close these tags to support XHTML (#13200)
nicholas@2224 4925 wrapMap = {
nicholas@2224 4926
nicholas@2224 4927 // Support: IE9
nicholas@2224 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nicholas@2224 4929
nicholas@2224 4930 thead: [ 1, "<table>", "</table>" ],
nicholas@2224 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nicholas@2224 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nicholas@2224 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nicholas@2224 4934
nicholas@2224 4935 _default: [ 0, "", "" ]
nicholas@2224 4936 };
nicholas@2224 4937
nicholas@2224 4938 // Support: IE9
nicholas@2224 4939 wrapMap.optgroup = wrapMap.option;
nicholas@2224 4940
nicholas@2224 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nicholas@2224 4942 wrapMap.th = wrapMap.td;
nicholas@2224 4943
nicholas@2224 4944 // Support: 1.x compatibility
nicholas@2224 4945 // Manipulating tables requires a tbody
nicholas@2224 4946 function manipulationTarget( elem, content ) {
nicholas@2224 4947 return jQuery.nodeName( elem, "table" ) &&
nicholas@2224 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nicholas@2224 4949
nicholas@2224 4950 elem.getElementsByTagName("tbody")[0] ||
nicholas@2224 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nicholas@2224 4952 elem;
nicholas@2224 4953 }
nicholas@2224 4954
nicholas@2224 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nicholas@2224 4956 function disableScript( elem ) {
nicholas@2224 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nicholas@2224 4958 return elem;
nicholas@2224 4959 }
nicholas@2224 4960 function restoreScript( elem ) {
nicholas@2224 4961 var match = rscriptTypeMasked.exec( elem.type );
nicholas@2224 4962
nicholas@2224 4963 if ( match ) {
nicholas@2224 4964 elem.type = match[ 1 ];
nicholas@2224 4965 } else {
nicholas@2224 4966 elem.removeAttribute("type");
nicholas@2224 4967 }
nicholas@2224 4968
nicholas@2224 4969 return elem;
nicholas@2224 4970 }
nicholas@2224 4971
nicholas@2224 4972 // Mark scripts as having already been evaluated
nicholas@2224 4973 function setGlobalEval( elems, refElements ) {
nicholas@2224 4974 var i = 0,
nicholas@2224 4975 l = elems.length;
nicholas@2224 4976
nicholas@2224 4977 for ( ; i < l; i++ ) {
nicholas@2224 4978 data_priv.set(
nicholas@2224 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nicholas@2224 4980 );
nicholas@2224 4981 }
nicholas@2224 4982 }
nicholas@2224 4983
nicholas@2224 4984 function cloneCopyEvent( src, dest ) {
nicholas@2224 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nicholas@2224 4986
nicholas@2224 4987 if ( dest.nodeType !== 1 ) {
nicholas@2224 4988 return;
nicholas@2224 4989 }
nicholas@2224 4990
nicholas@2224 4991 // 1. Copy private data: events, handlers, etc.
nicholas@2224 4992 if ( data_priv.hasData( src ) ) {
nicholas@2224 4993 pdataOld = data_priv.access( src );
nicholas@2224 4994 pdataCur = data_priv.set( dest, pdataOld );
nicholas@2224 4995 events = pdataOld.events;
nicholas@2224 4996
nicholas@2224 4997 if ( events ) {
nicholas@2224 4998 delete pdataCur.handle;
nicholas@2224 4999 pdataCur.events = {};
nicholas@2224 5000
nicholas@2224 5001 for ( type in events ) {
nicholas@2224 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nicholas@2224 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nicholas@2224 5004 }
nicholas@2224 5005 }
nicholas@2224 5006 }
nicholas@2224 5007 }
nicholas@2224 5008
nicholas@2224 5009 // 2. Copy user data
nicholas@2224 5010 if ( data_user.hasData( src ) ) {
nicholas@2224 5011 udataOld = data_user.access( src );
nicholas@2224 5012 udataCur = jQuery.extend( {}, udataOld );
nicholas@2224 5013
nicholas@2224 5014 data_user.set( dest, udataCur );
nicholas@2224 5015 }
nicholas@2224 5016 }
nicholas@2224 5017
nicholas@2224 5018 function getAll( context, tag ) {
nicholas@2224 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nicholas@2224 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nicholas@2224 5021 [];
nicholas@2224 5022
nicholas@2224 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nicholas@2224 5024 jQuery.merge( [ context ], ret ) :
nicholas@2224 5025 ret;
nicholas@2224 5026 }
nicholas@2224 5027
nicholas@2224 5028 // Fix IE bugs, see support tests
nicholas@2224 5029 function fixInput( src, dest ) {
nicholas@2224 5030 var nodeName = dest.nodeName.toLowerCase();
nicholas@2224 5031
nicholas@2224 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nicholas@2224 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nicholas@2224 5034 dest.checked = src.checked;
nicholas@2224 5035
nicholas@2224 5036 // Fails to return the selected option to the default selected state when cloning options
nicholas@2224 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nicholas@2224 5038 dest.defaultValue = src.defaultValue;
nicholas@2224 5039 }
nicholas@2224 5040 }
nicholas@2224 5041
nicholas@2224 5042 jQuery.extend({
nicholas@2224 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nicholas@2224 5044 var i, l, srcElements, destElements,
nicholas@2224 5045 clone = elem.cloneNode( true ),
nicholas@2224 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nicholas@2224 5047
nicholas@2224 5048 // Fix IE cloning issues
nicholas@2224 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nicholas@2224 5050 !jQuery.isXMLDoc( elem ) ) {
nicholas@2224 5051
nicholas@2224 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nicholas@2224 5053 destElements = getAll( clone );
nicholas@2224 5054 srcElements = getAll( elem );
nicholas@2224 5055
nicholas@2224 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nicholas@2224 5057 fixInput( srcElements[ i ], destElements[ i ] );
nicholas@2224 5058 }
nicholas@2224 5059 }
nicholas@2224 5060
nicholas@2224 5061 // Copy the events from the original to the clone
nicholas@2224 5062 if ( dataAndEvents ) {
nicholas@2224 5063 if ( deepDataAndEvents ) {
nicholas@2224 5064 srcElements = srcElements || getAll( elem );
nicholas@2224 5065 destElements = destElements || getAll( clone );
nicholas@2224 5066
nicholas@2224 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nicholas@2224 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nicholas@2224 5069 }
nicholas@2224 5070 } else {
nicholas@2224 5071 cloneCopyEvent( elem, clone );
nicholas@2224 5072 }
nicholas@2224 5073 }
nicholas@2224 5074
nicholas@2224 5075 // Preserve script evaluation history
nicholas@2224 5076 destElements = getAll( clone, "script" );
nicholas@2224 5077 if ( destElements.length > 0 ) {
nicholas@2224 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nicholas@2224 5079 }
nicholas@2224 5080
nicholas@2224 5081 // Return the cloned set
nicholas@2224 5082 return clone;
nicholas@2224 5083 },
nicholas@2224 5084
nicholas@2224 5085 buildFragment: function( elems, context, scripts, selection ) {
nicholas@2224 5086 var elem, tmp, tag, wrap, contains, j,
nicholas@2224 5087 fragment = context.createDocumentFragment(),
nicholas@2224 5088 nodes = [],
nicholas@2224 5089 i = 0,
nicholas@2224 5090 l = elems.length;
nicholas@2224 5091
nicholas@2224 5092 for ( ; i < l; i++ ) {
nicholas@2224 5093 elem = elems[ i ];
nicholas@2224 5094
nicholas@2224 5095 if ( elem || elem === 0 ) {
nicholas@2224 5096
nicholas@2224 5097 // Add nodes directly
nicholas@2224 5098 if ( jQuery.type( elem ) === "object" ) {
nicholas@2224 5099 // Support: QtWebKit, PhantomJS
nicholas@2224 5100 // push.apply(_, arraylike) throws on ancient WebKit
nicholas@2224 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nicholas@2224 5102
nicholas@2224 5103 // Convert non-html into a text node
nicholas@2224 5104 } else if ( !rhtml.test( elem ) ) {
nicholas@2224 5105 nodes.push( context.createTextNode( elem ) );
nicholas@2224 5106
nicholas@2224 5107 // Convert html into DOM nodes
nicholas@2224 5108 } else {
nicholas@2224 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nicholas@2224 5110
nicholas@2224 5111 // Deserialize a standard representation
nicholas@2224 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nicholas@2224 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nicholas@2224 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nicholas@2224 5115
nicholas@2224 5116 // Descend through wrappers to the right content
nicholas@2224 5117 j = wrap[ 0 ];
nicholas@2224 5118 while ( j-- ) {
nicholas@2224 5119 tmp = tmp.lastChild;
nicholas@2224 5120 }
nicholas@2224 5121
nicholas@2224 5122 // Support: QtWebKit, PhantomJS
nicholas@2224 5123 // push.apply(_, arraylike) throws on ancient WebKit
nicholas@2224 5124 jQuery.merge( nodes, tmp.childNodes );
nicholas@2224 5125
nicholas@2224 5126 // Remember the top-level container
nicholas@2224 5127 tmp = fragment.firstChild;
nicholas@2224 5128
nicholas@2224 5129 // Ensure the created nodes are orphaned (#12392)
nicholas@2224 5130 tmp.textContent = "";
nicholas@2224 5131 }
nicholas@2224 5132 }
nicholas@2224 5133 }
nicholas@2224 5134
nicholas@2224 5135 // Remove wrapper from fragment
nicholas@2224 5136 fragment.textContent = "";
nicholas@2224 5137
nicholas@2224 5138 i = 0;
nicholas@2224 5139 while ( (elem = nodes[ i++ ]) ) {
nicholas@2224 5140
nicholas@2224 5141 // #4087 - If origin and destination elements are the same, and this is
nicholas@2224 5142 // that element, do not do anything
nicholas@2224 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nicholas@2224 5144 continue;
nicholas@2224 5145 }
nicholas@2224 5146
nicholas@2224 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nicholas@2224 5148
nicholas@2224 5149 // Append to fragment
nicholas@2224 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nicholas@2224 5151
nicholas@2224 5152 // Preserve script evaluation history
nicholas@2224 5153 if ( contains ) {
nicholas@2224 5154 setGlobalEval( tmp );
nicholas@2224 5155 }
nicholas@2224 5156
nicholas@2224 5157 // Capture executables
nicholas@2224 5158 if ( scripts ) {
nicholas@2224 5159 j = 0;
nicholas@2224 5160 while ( (elem = tmp[ j++ ]) ) {
nicholas@2224 5161 if ( rscriptType.test( elem.type || "" ) ) {
nicholas@2224 5162 scripts.push( elem );
nicholas@2224 5163 }
nicholas@2224 5164 }
nicholas@2224 5165 }
nicholas@2224 5166 }
nicholas@2224 5167
nicholas@2224 5168 return fragment;
nicholas@2224 5169 },
nicholas@2224 5170
nicholas@2224 5171 cleanData: function( elems ) {
nicholas@2224 5172 var data, elem, type, key,
nicholas@2224 5173 special = jQuery.event.special,
nicholas@2224 5174 i = 0;
nicholas@2224 5175
nicholas@2224 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nicholas@2224 5177 if ( jQuery.acceptData( elem ) ) {
nicholas@2224 5178 key = elem[ data_priv.expando ];
nicholas@2224 5179
nicholas@2224 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nicholas@2224 5181 if ( data.events ) {
nicholas@2224 5182 for ( type in data.events ) {
nicholas@2224 5183 if ( special[ type ] ) {
nicholas@2224 5184 jQuery.event.remove( elem, type );
nicholas@2224 5185
nicholas@2224 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nicholas@2224 5187 } else {
nicholas@2224 5188 jQuery.removeEvent( elem, type, data.handle );
nicholas@2224 5189 }
nicholas@2224 5190 }
nicholas@2224 5191 }
nicholas@2224 5192 if ( data_priv.cache[ key ] ) {
nicholas@2224 5193 // Discard any remaining `private` data
nicholas@2224 5194 delete data_priv.cache[ key ];
nicholas@2224 5195 }
nicholas@2224 5196 }
nicholas@2224 5197 }
nicholas@2224 5198 // Discard any remaining `user` data
nicholas@2224 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nicholas@2224 5200 }
nicholas@2224 5201 }
nicholas@2224 5202 });
nicholas@2224 5203
nicholas@2224 5204 jQuery.fn.extend({
nicholas@2224 5205 text: function( value ) {
nicholas@2224 5206 return access( this, function( value ) {
nicholas@2224 5207 return value === undefined ?
nicholas@2224 5208 jQuery.text( this ) :
nicholas@2224 5209 this.empty().each(function() {
nicholas@2224 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@2224 5211 this.textContent = value;
nicholas@2224 5212 }
nicholas@2224 5213 });
nicholas@2224 5214 }, null, value, arguments.length );
nicholas@2224 5215 },
nicholas@2224 5216
nicholas@2224 5217 append: function() {
nicholas@2224 5218 return this.domManip( arguments, function( elem ) {
nicholas@2224 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@2224 5220 var target = manipulationTarget( this, elem );
nicholas@2224 5221 target.appendChild( elem );
nicholas@2224 5222 }
nicholas@2224 5223 });
nicholas@2224 5224 },
nicholas@2224 5225
nicholas@2224 5226 prepend: function() {
nicholas@2224 5227 return this.domManip( arguments, function( elem ) {
nicholas@2224 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nicholas@2224 5229 var target = manipulationTarget( this, elem );
nicholas@2224 5230 target.insertBefore( elem, target.firstChild );
nicholas@2224 5231 }
nicholas@2224 5232 });
nicholas@2224 5233 },
nicholas@2224 5234
nicholas@2224 5235 before: function() {
nicholas@2224 5236 return this.domManip( arguments, function( elem ) {
nicholas@2224 5237 if ( this.parentNode ) {
nicholas@2224 5238 this.parentNode.insertBefore( elem, this );
nicholas@2224 5239 }
nicholas@2224 5240 });
nicholas@2224 5241 },
nicholas@2224 5242
nicholas@2224 5243 after: function() {
nicholas@2224 5244 return this.domManip( arguments, function( elem ) {
nicholas@2224 5245 if ( this.parentNode ) {
nicholas@2224 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nicholas@2224 5247 }
nicholas@2224 5248 });
nicholas@2224 5249 },
nicholas@2224 5250
nicholas@2224 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nicholas@2224 5252 var elem,
nicholas@2224 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nicholas@2224 5254 i = 0;
nicholas@2224 5255
nicholas@2224 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nicholas@2224 5257 if ( !keepData && elem.nodeType === 1 ) {
nicholas@2224 5258 jQuery.cleanData( getAll( elem ) );
nicholas@2224 5259 }
nicholas@2224 5260
nicholas@2224 5261 if ( elem.parentNode ) {
nicholas@2224 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nicholas@2224 5263 setGlobalEval( getAll( elem, "script" ) );
nicholas@2224 5264 }
nicholas@2224 5265 elem.parentNode.removeChild( elem );
nicholas@2224 5266 }
nicholas@2224 5267 }
nicholas@2224 5268
nicholas@2224 5269 return this;
nicholas@2224 5270 },
nicholas@2224 5271
nicholas@2224 5272 empty: function() {
nicholas@2224 5273 var elem,
nicholas@2224 5274 i = 0;
nicholas@2224 5275
nicholas@2224 5276 for ( ; (elem = this[i]) != null; i++ ) {
nicholas@2224 5277 if ( elem.nodeType === 1 ) {
nicholas@2224 5278
nicholas@2224 5279 // Prevent memory leaks
nicholas@2224 5280 jQuery.cleanData( getAll( elem, false ) );
nicholas@2224 5281
nicholas@2224 5282 // Remove any remaining nodes
nicholas@2224 5283 elem.textContent = "";
nicholas@2224 5284 }
nicholas@2224 5285 }
nicholas@2224 5286
nicholas@2224 5287 return this;
nicholas@2224 5288 },
nicholas@2224 5289
nicholas@2224 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nicholas@2224 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nicholas@2224 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nicholas@2224 5293
nicholas@2224 5294 return this.map(function() {
nicholas@2224 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nicholas@2224 5296 });
nicholas@2224 5297 },
nicholas@2224 5298
nicholas@2224 5299 html: function( value ) {
nicholas@2224 5300 return access( this, function( value ) {
nicholas@2224 5301 var elem = this[ 0 ] || {},
nicholas@2224 5302 i = 0,
nicholas@2224 5303 l = this.length;
nicholas@2224 5304
nicholas@2224 5305 if ( value === undefined && elem.nodeType === 1 ) {
nicholas@2224 5306 return elem.innerHTML;
nicholas@2224 5307 }
nicholas@2224 5308
nicholas@2224 5309 // See if we can take a shortcut and just use innerHTML
nicholas@2224 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nicholas@2224 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nicholas@2224 5312
nicholas@2224 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nicholas@2224 5314
nicholas@2224 5315 try {
nicholas@2224 5316 for ( ; i < l; i++ ) {
nicholas@2224 5317 elem = this[ i ] || {};
nicholas@2224 5318
nicholas@2224 5319 // Remove element nodes and prevent memory leaks
nicholas@2224 5320 if ( elem.nodeType === 1 ) {
nicholas@2224 5321 jQuery.cleanData( getAll( elem, false ) );
nicholas@2224 5322 elem.innerHTML = value;
nicholas@2224 5323 }
nicholas@2224 5324 }
nicholas@2224 5325
nicholas@2224 5326 elem = 0;
nicholas@2224 5327
nicholas@2224 5328 // If using innerHTML throws an exception, use the fallback method
nicholas@2224 5329 } catch( e ) {}
nicholas@2224 5330 }
nicholas@2224 5331
nicholas@2224 5332 if ( elem ) {
nicholas@2224 5333 this.empty().append( value );
nicholas@2224 5334 }
nicholas@2224 5335 }, null, value, arguments.length );
nicholas@2224 5336 },
nicholas@2224 5337
nicholas@2224 5338 replaceWith: function() {
nicholas@2224 5339 var arg = arguments[ 0 ];
nicholas@2224 5340
nicholas@2224 5341 // Make the changes, replacing each context element with the new content
nicholas@2224 5342 this.domManip( arguments, function( elem ) {
nicholas@2224 5343 arg = this.parentNode;
nicholas@2224 5344
nicholas@2224 5345 jQuery.cleanData( getAll( this ) );
nicholas@2224 5346
nicholas@2224 5347 if ( arg ) {
nicholas@2224 5348 arg.replaceChild( elem, this );
nicholas@2224 5349 }
nicholas@2224 5350 });
nicholas@2224 5351
nicholas@2224 5352 // Force removal if there was no new content (e.g., from empty arguments)
nicholas@2224 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nicholas@2224 5354 },
nicholas@2224 5355
nicholas@2224 5356 detach: function( selector ) {
nicholas@2224 5357 return this.remove( selector, true );
nicholas@2224 5358 },
nicholas@2224 5359
nicholas@2224 5360 domManip: function( args, callback ) {
nicholas@2224 5361
nicholas@2224 5362 // Flatten any nested arrays
nicholas@2224 5363 args = concat.apply( [], args );
nicholas@2224 5364
nicholas@2224 5365 var fragment, first, scripts, hasScripts, node, doc,
nicholas@2224 5366 i = 0,
nicholas@2224 5367 l = this.length,
nicholas@2224 5368 set = this,
nicholas@2224 5369 iNoClone = l - 1,
nicholas@2224 5370 value = args[ 0 ],
nicholas@2224 5371 isFunction = jQuery.isFunction( value );
nicholas@2224 5372
nicholas@2224 5373 // We can't cloneNode fragments that contain checked, in WebKit
nicholas@2224 5374 if ( isFunction ||
nicholas@2224 5375 ( l > 1 && typeof value === "string" &&
nicholas@2224 5376 !support.checkClone && rchecked.test( value ) ) ) {
nicholas@2224 5377 return this.each(function( index ) {
nicholas@2224 5378 var self = set.eq( index );
nicholas@2224 5379 if ( isFunction ) {
nicholas@2224 5380 args[ 0 ] = value.call( this, index, self.html() );
nicholas@2224 5381 }
nicholas@2224 5382 self.domManip( args, callback );
nicholas@2224 5383 });
nicholas@2224 5384 }
nicholas@2224 5385
nicholas@2224 5386 if ( l ) {
nicholas@2224 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nicholas@2224 5388 first = fragment.firstChild;
nicholas@2224 5389
nicholas@2224 5390 if ( fragment.childNodes.length === 1 ) {
nicholas@2224 5391 fragment = first;
nicholas@2224 5392 }
nicholas@2224 5393
nicholas@2224 5394 if ( first ) {
nicholas@2224 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nicholas@2224 5396 hasScripts = scripts.length;
nicholas@2224 5397
nicholas@2224 5398 // Use the original fragment for the last item instead of the first because it can end up
nicholas@2224 5399 // being emptied incorrectly in certain situations (#8070).
nicholas@2224 5400 for ( ; i < l; i++ ) {
nicholas@2224 5401 node = fragment;
nicholas@2224 5402
nicholas@2224 5403 if ( i !== iNoClone ) {
nicholas@2224 5404 node = jQuery.clone( node, true, true );
nicholas@2224 5405
nicholas@2224 5406 // Keep references to cloned scripts for later restoration
nicholas@2224 5407 if ( hasScripts ) {
nicholas@2224 5408 // Support: QtWebKit
nicholas@2224 5409 // jQuery.merge because push.apply(_, arraylike) throws
nicholas@2224 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nicholas@2224 5411 }
nicholas@2224 5412 }
nicholas@2224 5413
nicholas@2224 5414 callback.call( this[ i ], node, i );
nicholas@2224 5415 }
nicholas@2224 5416
nicholas@2224 5417 if ( hasScripts ) {
nicholas@2224 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nicholas@2224 5419
nicholas@2224 5420 // Reenable scripts
nicholas@2224 5421 jQuery.map( scripts, restoreScript );
nicholas@2224 5422
nicholas@2224 5423 // Evaluate executable scripts on first document insertion
nicholas@2224 5424 for ( i = 0; i < hasScripts; i++ ) {
nicholas@2224 5425 node = scripts[ i ];
nicholas@2224 5426 if ( rscriptType.test( node.type || "" ) &&
nicholas@2224 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nicholas@2224 5428
nicholas@2224 5429 if ( node.src ) {
nicholas@2224 5430 // Optional AJAX dependency, but won't run scripts if not present
nicholas@2224 5431 if ( jQuery._evalUrl ) {
nicholas@2224 5432 jQuery._evalUrl( node.src );
nicholas@2224 5433 }
nicholas@2224 5434 } else {
nicholas@2224 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nicholas@2224 5436 }
nicholas@2224 5437 }
nicholas@2224 5438 }
nicholas@2224 5439 }
nicholas@2224 5440 }
nicholas@2224 5441 }
nicholas@2224 5442
nicholas@2224 5443 return this;
nicholas@2224 5444 }
nicholas@2224 5445 });
nicholas@2224 5446
nicholas@2224 5447 jQuery.each({
nicholas@2224 5448 appendTo: "append",
nicholas@2224 5449 prependTo: "prepend",
nicholas@2224 5450 insertBefore: "before",
nicholas@2224 5451 insertAfter: "after",
nicholas@2224 5452 replaceAll: "replaceWith"
nicholas@2224 5453 }, function( name, original ) {
nicholas@2224 5454 jQuery.fn[ name ] = function( selector ) {
nicholas@2224 5455 var elems,
nicholas@2224 5456 ret = [],
nicholas@2224 5457 insert = jQuery( selector ),
nicholas@2224 5458 last = insert.length - 1,
nicholas@2224 5459 i = 0;
nicholas@2224 5460
nicholas@2224 5461 for ( ; i <= last; i++ ) {
nicholas@2224 5462 elems = i === last ? this : this.clone( true );
nicholas@2224 5463 jQuery( insert[ i ] )[ original ]( elems );
nicholas@2224 5464
nicholas@2224 5465 // Support: QtWebKit
nicholas@2224 5466 // .get() because push.apply(_, arraylike) throws
nicholas@2224 5467 push.apply( ret, elems.get() );
nicholas@2224 5468 }
nicholas@2224 5469
nicholas@2224 5470 return this.pushStack( ret );
nicholas@2224 5471 };
nicholas@2224 5472 });
nicholas@2224 5473
nicholas@2224 5474
nicholas@2224 5475 var iframe,
nicholas@2224 5476 elemdisplay = {};
nicholas@2224 5477
nicholas@2224 5478 /**
nicholas@2224 5479 * Retrieve the actual display of a element
nicholas@2224 5480 * @param {String} name nodeName of the element
nicholas@2224 5481 * @param {Object} doc Document object
nicholas@2224 5482 */
nicholas@2224 5483 // Called only from within defaultDisplay
nicholas@2224 5484 function actualDisplay( name, doc ) {
nicholas@2224 5485 var style,
nicholas@2224 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nicholas@2224 5487
nicholas@2224 5488 // getDefaultComputedStyle might be reliably used only on attached element
nicholas@2224 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nicholas@2224 5490
nicholas@2224 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nicholas@2224 5492 // since it was removed from specification and supported only in FF
nicholas@2224 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nicholas@2224 5494
nicholas@2224 5495 // We don't have any data stored on the element,
nicholas@2224 5496 // so use "detach" method as fast way to get rid of the element
nicholas@2224 5497 elem.detach();
nicholas@2224 5498
nicholas@2224 5499 return display;
nicholas@2224 5500 }
nicholas@2224 5501
nicholas@2224 5502 /**
nicholas@2224 5503 * Try to determine the default display value of an element
nicholas@2224 5504 * @param {String} nodeName
nicholas@2224 5505 */
nicholas@2224 5506 function defaultDisplay( nodeName ) {
nicholas@2224 5507 var doc = document,
nicholas@2224 5508 display = elemdisplay[ nodeName ];
nicholas@2224 5509
nicholas@2224 5510 if ( !display ) {
nicholas@2224 5511 display = actualDisplay( nodeName, doc );
nicholas@2224 5512
nicholas@2224 5513 // If the simple way fails, read from inside an iframe
nicholas@2224 5514 if ( display === "none" || !display ) {
nicholas@2224 5515
nicholas@2224 5516 // Use the already-created iframe if possible
nicholas@2224 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nicholas@2224 5518
nicholas@2224 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nicholas@2224 5520 doc = iframe[ 0 ].contentDocument;
nicholas@2224 5521
nicholas@2224 5522 // Support: IE
nicholas@2224 5523 doc.write();
nicholas@2224 5524 doc.close();
nicholas@2224 5525
nicholas@2224 5526 display = actualDisplay( nodeName, doc );
nicholas@2224 5527 iframe.detach();
nicholas@2224 5528 }
nicholas@2224 5529
nicholas@2224 5530 // Store the correct default display
nicholas@2224 5531 elemdisplay[ nodeName ] = display;
nicholas@2224 5532 }
nicholas@2224 5533
nicholas@2224 5534 return display;
nicholas@2224 5535 }
nicholas@2224 5536 var rmargin = (/^margin/);
nicholas@2224 5537
nicholas@2224 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nicholas@2224 5539
nicholas@2224 5540 var getStyles = function( elem ) {
nicholas@2224 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nicholas@2224 5542 // IE throws on elements created in popups
nicholas@2224 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nicholas@2224 5544 if ( elem.ownerDocument.defaultView.opener ) {
nicholas@2224 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nicholas@2224 5546 }
nicholas@2224 5547
nicholas@2224 5548 return window.getComputedStyle( elem, null );
nicholas@2224 5549 };
nicholas@2224 5550
nicholas@2224 5551
nicholas@2224 5552
nicholas@2224 5553 function curCSS( elem, name, computed ) {
nicholas@2224 5554 var width, minWidth, maxWidth, ret,
nicholas@2224 5555 style = elem.style;
nicholas@2224 5556
nicholas@2224 5557 computed = computed || getStyles( elem );
nicholas@2224 5558
nicholas@2224 5559 // Support: IE9
nicholas@2224 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nicholas@2224 5561 if ( computed ) {
nicholas@2224 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nicholas@2224 5563 }
nicholas@2224 5564
nicholas@2224 5565 if ( computed ) {
nicholas@2224 5566
nicholas@2224 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nicholas@2224 5568 ret = jQuery.style( elem, name );
nicholas@2224 5569 }
nicholas@2224 5570
nicholas@2224 5571 // Support: iOS < 6
nicholas@2224 5572 // A tribute to the "awesome hack by Dean Edwards"
nicholas@2224 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nicholas@2224 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nicholas@2224 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nicholas@2224 5576
nicholas@2224 5577 // Remember the original values
nicholas@2224 5578 width = style.width;
nicholas@2224 5579 minWidth = style.minWidth;
nicholas@2224 5580 maxWidth = style.maxWidth;
nicholas@2224 5581
nicholas@2224 5582 // Put in the new values to get a computed value out
nicholas@2224 5583 style.minWidth = style.maxWidth = style.width = ret;
nicholas@2224 5584 ret = computed.width;
nicholas@2224 5585
nicholas@2224 5586 // Revert the changed values
nicholas@2224 5587 style.width = width;
nicholas@2224 5588 style.minWidth = minWidth;
nicholas@2224 5589 style.maxWidth = maxWidth;
nicholas@2224 5590 }
nicholas@2224 5591 }
nicholas@2224 5592
nicholas@2224 5593 return ret !== undefined ?
nicholas@2224 5594 // Support: IE
nicholas@2224 5595 // IE returns zIndex value as an integer.
nicholas@2224 5596 ret + "" :
nicholas@2224 5597 ret;
nicholas@2224 5598 }
nicholas@2224 5599
nicholas@2224 5600
nicholas@2224 5601 function addGetHookIf( conditionFn, hookFn ) {
nicholas@2224 5602 // Define the hook, we'll check on the first run if it's really needed.
nicholas@2224 5603 return {
nicholas@2224 5604 get: function() {
nicholas@2224 5605 if ( conditionFn() ) {
nicholas@2224 5606 // Hook not needed (or it's not possible to use it due
nicholas@2224 5607 // to missing dependency), remove it.
nicholas@2224 5608 delete this.get;
nicholas@2224 5609 return;
nicholas@2224 5610 }
nicholas@2224 5611
nicholas@2224 5612 // Hook needed; redefine it so that the support test is not executed again.
nicholas@2224 5613 return (this.get = hookFn).apply( this, arguments );
nicholas@2224 5614 }
nicholas@2224 5615 };
nicholas@2224 5616 }
nicholas@2224 5617
nicholas@2224 5618
nicholas@2224 5619 (function() {
nicholas@2224 5620 var pixelPositionVal, boxSizingReliableVal,
nicholas@2224 5621 docElem = document.documentElement,
nicholas@2224 5622 container = document.createElement( "div" ),
nicholas@2224 5623 div = document.createElement( "div" );
nicholas@2224 5624
nicholas@2224 5625 if ( !div.style ) {
nicholas@2224 5626 return;
nicholas@2224 5627 }
nicholas@2224 5628
nicholas@2224 5629 // Support: IE9-11+
nicholas@2224 5630 // Style of cloned element affects source element cloned (#8908)
nicholas@2224 5631 div.style.backgroundClip = "content-box";
nicholas@2224 5632 div.cloneNode( true ).style.backgroundClip = "";
nicholas@2224 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nicholas@2224 5634
nicholas@2224 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nicholas@2224 5636 "position:absolute";
nicholas@2224 5637 container.appendChild( div );
nicholas@2224 5638
nicholas@2224 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nicholas@2224 5640 // so they're executed at the same time to save the second computation.
nicholas@2224 5641 function computePixelPositionAndBoxSizingReliable() {
nicholas@2224 5642 div.style.cssText =
nicholas@2224 5643 // Support: Firefox<29, Android 2.3
nicholas@2224 5644 // Vendor-prefix box-sizing
nicholas@2224 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nicholas@2224 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nicholas@2224 5647 "border:1px;padding:1px;width:4px;position:absolute";
nicholas@2224 5648 div.innerHTML = "";
nicholas@2224 5649 docElem.appendChild( container );
nicholas@2224 5650
nicholas@2224 5651 var divStyle = window.getComputedStyle( div, null );
nicholas@2224 5652 pixelPositionVal = divStyle.top !== "1%";
nicholas@2224 5653 boxSizingReliableVal = divStyle.width === "4px";
nicholas@2224 5654
nicholas@2224 5655 docElem.removeChild( container );
nicholas@2224 5656 }
nicholas@2224 5657
nicholas@2224 5658 // Support: node.js jsdom
nicholas@2224 5659 // Don't assume that getComputedStyle is a property of the global object
nicholas@2224 5660 if ( window.getComputedStyle ) {
nicholas@2224 5661 jQuery.extend( support, {
nicholas@2224 5662 pixelPosition: function() {
nicholas@2224 5663
nicholas@2224 5664 // This test is executed only once but we still do memoizing
nicholas@2224 5665 // since we can use the boxSizingReliable pre-computing.
nicholas@2224 5666 // No need to check if the test was already performed, though.
nicholas@2224 5667 computePixelPositionAndBoxSizingReliable();
nicholas@2224 5668 return pixelPositionVal;
nicholas@2224 5669 },
nicholas@2224 5670 boxSizingReliable: function() {
nicholas@2224 5671 if ( boxSizingReliableVal == null ) {
nicholas@2224 5672 computePixelPositionAndBoxSizingReliable();
nicholas@2224 5673 }
nicholas@2224 5674 return boxSizingReliableVal;
nicholas@2224 5675 },
nicholas@2224 5676 reliableMarginRight: function() {
nicholas@2224 5677
nicholas@2224 5678 // Support: Android 2.3
nicholas@2224 5679 // Check if div with explicit width and no margin-right incorrectly
nicholas@2224 5680 // gets computed margin-right based on width of container. (#3333)
nicholas@2224 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nicholas@2224 5682 // This support function is only executed once so no memoizing is needed.
nicholas@2224 5683 var ret,
nicholas@2224 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nicholas@2224 5685
nicholas@2224 5686 // Reset CSS: box-sizing; display; margin; border; padding
nicholas@2224 5687 marginDiv.style.cssText = div.style.cssText =
nicholas@2224 5688 // Support: Firefox<29, Android 2.3
nicholas@2224 5689 // Vendor-prefix box-sizing
nicholas@2224 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nicholas@2224 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nicholas@2224 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nicholas@2224 5693 div.style.width = "1px";
nicholas@2224 5694 docElem.appendChild( container );
nicholas@2224 5695
nicholas@2224 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nicholas@2224 5697
nicholas@2224 5698 docElem.removeChild( container );
nicholas@2224 5699 div.removeChild( marginDiv );
nicholas@2224 5700
nicholas@2224 5701 return ret;
nicholas@2224 5702 }
nicholas@2224 5703 });
nicholas@2224 5704 }
nicholas@2224 5705 })();
nicholas@2224 5706
nicholas@2224 5707
nicholas@2224 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nicholas@2224 5709 jQuery.swap = function( elem, options, callback, args ) {
nicholas@2224 5710 var ret, name,
nicholas@2224 5711 old = {};
nicholas@2224 5712
nicholas@2224 5713 // Remember the old values, and insert the new ones
nicholas@2224 5714 for ( name in options ) {
nicholas@2224 5715 old[ name ] = elem.style[ name ];
nicholas@2224 5716 elem.style[ name ] = options[ name ];
nicholas@2224 5717 }
nicholas@2224 5718
nicholas@2224 5719 ret = callback.apply( elem, args || [] );
nicholas@2224 5720
nicholas@2224 5721 // Revert the old values
nicholas@2224 5722 for ( name in options ) {
nicholas@2224 5723 elem.style[ name ] = old[ name ];
nicholas@2224 5724 }
nicholas@2224 5725
nicholas@2224 5726 return ret;
nicholas@2224 5727 };
nicholas@2224 5728
nicholas@2224 5729
nicholas@2224 5730 var
nicholas@2224 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nicholas@2224 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nicholas@2224 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nicholas@2224 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nicholas@2224 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nicholas@2224 5736
nicholas@2224 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nicholas@2224 5738 cssNormalTransform = {
nicholas@2224 5739 letterSpacing: "0",
nicholas@2224 5740 fontWeight: "400"
nicholas@2224 5741 },
nicholas@2224 5742
nicholas@2224 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nicholas@2224 5744
nicholas@2224 5745 // Return a css property mapped to a potentially vendor prefixed property
nicholas@2224 5746 function vendorPropName( style, name ) {
nicholas@2224 5747
nicholas@2224 5748 // Shortcut for names that are not vendor prefixed
nicholas@2224 5749 if ( name in style ) {
nicholas@2224 5750 return name;
nicholas@2224 5751 }
nicholas@2224 5752
nicholas@2224 5753 // Check for vendor prefixed names
nicholas@2224 5754 var capName = name[0].toUpperCase() + name.slice(1),
nicholas@2224 5755 origName = name,
nicholas@2224 5756 i = cssPrefixes.length;
nicholas@2224 5757
nicholas@2224 5758 while ( i-- ) {
nicholas@2224 5759 name = cssPrefixes[ i ] + capName;
nicholas@2224 5760 if ( name in style ) {
nicholas@2224 5761 return name;
nicholas@2224 5762 }
nicholas@2224 5763 }
nicholas@2224 5764
nicholas@2224 5765 return origName;
nicholas@2224 5766 }
nicholas@2224 5767
nicholas@2224 5768 function setPositiveNumber( elem, value, subtract ) {
nicholas@2224 5769 var matches = rnumsplit.exec( value );
nicholas@2224 5770 return matches ?
nicholas@2224 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nicholas@2224 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nicholas@2224 5773 value;
nicholas@2224 5774 }
nicholas@2224 5775
nicholas@2224 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nicholas@2224 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nicholas@2224 5778 // If we already have the right measurement, avoid augmentation
nicholas@2224 5779 4 :
nicholas@2224 5780 // Otherwise initialize for horizontal or vertical properties
nicholas@2224 5781 name === "width" ? 1 : 0,
nicholas@2224 5782
nicholas@2224 5783 val = 0;
nicholas@2224 5784
nicholas@2224 5785 for ( ; i < 4; i += 2 ) {
nicholas@2224 5786 // Both box models exclude margin, so add it if we want it
nicholas@2224 5787 if ( extra === "margin" ) {
nicholas@2224 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nicholas@2224 5789 }
nicholas@2224 5790
nicholas@2224 5791 if ( isBorderBox ) {
nicholas@2224 5792 // border-box includes padding, so remove it if we want content
nicholas@2224 5793 if ( extra === "content" ) {
nicholas@2224 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nicholas@2224 5795 }
nicholas@2224 5796
nicholas@2224 5797 // At this point, extra isn't border nor margin, so remove border
nicholas@2224 5798 if ( extra !== "margin" ) {
nicholas@2224 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nicholas@2224 5800 }
nicholas@2224 5801 } else {
nicholas@2224 5802 // At this point, extra isn't content, so add padding
nicholas@2224 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nicholas@2224 5804
nicholas@2224 5805 // At this point, extra isn't content nor padding, so add border
nicholas@2224 5806 if ( extra !== "padding" ) {
nicholas@2224 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nicholas@2224 5808 }
nicholas@2224 5809 }
nicholas@2224 5810 }
nicholas@2224 5811
nicholas@2224 5812 return val;
nicholas@2224 5813 }
nicholas@2224 5814
nicholas@2224 5815 function getWidthOrHeight( elem, name, extra ) {
nicholas@2224 5816
nicholas@2224 5817 // Start with offset property, which is equivalent to the border-box value
nicholas@2224 5818 var valueIsBorderBox = true,
nicholas@2224 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nicholas@2224 5820 styles = getStyles( elem ),
nicholas@2224 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nicholas@2224 5822
nicholas@2224 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nicholas@2224 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nicholas@2224 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nicholas@2224 5826 if ( val <= 0 || val == null ) {
nicholas@2224 5827 // Fall back to computed then uncomputed css if necessary
nicholas@2224 5828 val = curCSS( elem, name, styles );
nicholas@2224 5829 if ( val < 0 || val == null ) {
nicholas@2224 5830 val = elem.style[ name ];
nicholas@2224 5831 }
nicholas@2224 5832
nicholas@2224 5833 // Computed unit is not pixels. Stop here and return.
nicholas@2224 5834 if ( rnumnonpx.test(val) ) {
nicholas@2224 5835 return val;
nicholas@2224 5836 }
nicholas@2224 5837
nicholas@2224 5838 // Check for style in case a browser which returns unreliable values
nicholas@2224 5839 // for getComputedStyle silently falls back to the reliable elem.style
nicholas@2224 5840 valueIsBorderBox = isBorderBox &&
nicholas@2224 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nicholas@2224 5842
nicholas@2224 5843 // Normalize "", auto, and prepare for extra
nicholas@2224 5844 val = parseFloat( val ) || 0;
nicholas@2224 5845 }
nicholas@2224 5846
nicholas@2224 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nicholas@2224 5848 return ( val +
nicholas@2224 5849 augmentWidthOrHeight(
nicholas@2224 5850 elem,
nicholas@2224 5851 name,
nicholas@2224 5852 extra || ( isBorderBox ? "border" : "content" ),
nicholas@2224 5853 valueIsBorderBox,
nicholas@2224 5854 styles
nicholas@2224 5855 )
nicholas@2224 5856 ) + "px";
nicholas@2224 5857 }
nicholas@2224 5858
nicholas@2224 5859 function showHide( elements, show ) {
nicholas@2224 5860 var display, elem, hidden,
nicholas@2224 5861 values = [],
nicholas@2224 5862 index = 0,
nicholas@2224 5863 length = elements.length;
nicholas@2224 5864
nicholas@2224 5865 for ( ; index < length; index++ ) {
nicholas@2224 5866 elem = elements[ index ];
nicholas@2224 5867 if ( !elem.style ) {
nicholas@2224 5868 continue;
nicholas@2224 5869 }
nicholas@2224 5870
nicholas@2224 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nicholas@2224 5872 display = elem.style.display;
nicholas@2224 5873 if ( show ) {
nicholas@2224 5874 // Reset the inline display of this element to learn if it is
nicholas@2224 5875 // being hidden by cascaded rules or not
nicholas@2224 5876 if ( !values[ index ] && display === "none" ) {
nicholas@2224 5877 elem.style.display = "";
nicholas@2224 5878 }
nicholas@2224 5879
nicholas@2224 5880 // Set elements which have been overridden with display: none
nicholas@2224 5881 // in a stylesheet to whatever the default browser style is
nicholas@2224 5882 // for such an element
nicholas@2224 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nicholas@2224 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nicholas@2224 5885 }
nicholas@2224 5886 } else {
nicholas@2224 5887 hidden = isHidden( elem );
nicholas@2224 5888
nicholas@2224 5889 if ( display !== "none" || !hidden ) {
nicholas@2224 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nicholas@2224 5891 }
nicholas@2224 5892 }
nicholas@2224 5893 }
nicholas@2224 5894
nicholas@2224 5895 // Set the display of most of the elements in a second loop
nicholas@2224 5896 // to avoid the constant reflow
nicholas@2224 5897 for ( index = 0; index < length; index++ ) {
nicholas@2224 5898 elem = elements[ index ];
nicholas@2224 5899 if ( !elem.style ) {
nicholas@2224 5900 continue;
nicholas@2224 5901 }
nicholas@2224 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nicholas@2224 5903 elem.style.display = show ? values[ index ] || "" : "none";
nicholas@2224 5904 }
nicholas@2224 5905 }
nicholas@2224 5906
nicholas@2224 5907 return elements;
nicholas@2224 5908 }
nicholas@2224 5909
nicholas@2224 5910 jQuery.extend({
nicholas@2224 5911
nicholas@2224 5912 // Add in style property hooks for overriding the default
nicholas@2224 5913 // behavior of getting and setting a style property
nicholas@2224 5914 cssHooks: {
nicholas@2224 5915 opacity: {
nicholas@2224 5916 get: function( elem, computed ) {
nicholas@2224 5917 if ( computed ) {
nicholas@2224 5918
nicholas@2224 5919 // We should always get a number back from opacity
nicholas@2224 5920 var ret = curCSS( elem, "opacity" );
nicholas@2224 5921 return ret === "" ? "1" : ret;
nicholas@2224 5922 }
nicholas@2224 5923 }
nicholas@2224 5924 }
nicholas@2224 5925 },
nicholas@2224 5926
nicholas@2224 5927 // Don't automatically add "px" to these possibly-unitless properties
nicholas@2224 5928 cssNumber: {
nicholas@2224 5929 "columnCount": true,
nicholas@2224 5930 "fillOpacity": true,
nicholas@2224 5931 "flexGrow": true,
nicholas@2224 5932 "flexShrink": true,
nicholas@2224 5933 "fontWeight": true,
nicholas@2224 5934 "lineHeight": true,
nicholas@2224 5935 "opacity": true,
nicholas@2224 5936 "order": true,
nicholas@2224 5937 "orphans": true,
nicholas@2224 5938 "widows": true,
nicholas@2224 5939 "zIndex": true,
nicholas@2224 5940 "zoom": true
nicholas@2224 5941 },
nicholas@2224 5942
nicholas@2224 5943 // Add in properties whose names you wish to fix before
nicholas@2224 5944 // setting or getting the value
nicholas@2224 5945 cssProps: {
nicholas@2224 5946 "float": "cssFloat"
nicholas@2224 5947 },
nicholas@2224 5948
nicholas@2224 5949 // Get and set the style property on a DOM Node
nicholas@2224 5950 style: function( elem, name, value, extra ) {
nicholas@2224 5951
nicholas@2224 5952 // Don't set styles on text and comment nodes
nicholas@2224 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nicholas@2224 5954 return;
nicholas@2224 5955 }
nicholas@2224 5956
nicholas@2224 5957 // Make sure that we're working with the right name
nicholas@2224 5958 var ret, type, hooks,
nicholas@2224 5959 origName = jQuery.camelCase( name ),
nicholas@2224 5960 style = elem.style;
nicholas@2224 5961
nicholas@2224 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nicholas@2224 5963
nicholas@2224 5964 // Gets hook for the prefixed version, then unprefixed version
nicholas@2224 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nicholas@2224 5966
nicholas@2224 5967 // Check if we're setting a value
nicholas@2224 5968 if ( value !== undefined ) {
nicholas@2224 5969 type = typeof value;
nicholas@2224 5970
nicholas@2224 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nicholas@2224 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nicholas@2224 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nicholas@2224 5974 // Fixes bug #9237
nicholas@2224 5975 type = "number";
nicholas@2224 5976 }
nicholas@2224 5977
nicholas@2224 5978 // Make sure that null and NaN values aren't set (#7116)
nicholas@2224 5979 if ( value == null || value !== value ) {
nicholas@2224 5980 return;
nicholas@2224 5981 }
nicholas@2224 5982
nicholas@2224 5983 // If a number, add 'px' to the (except for certain CSS properties)
nicholas@2224 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nicholas@2224 5985 value += "px";
nicholas@2224 5986 }
nicholas@2224 5987
nicholas@2224 5988 // Support: IE9-11+
nicholas@2224 5989 // background-* props affect original clone's values
nicholas@2224 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nicholas@2224 5991 style[ name ] = "inherit";
nicholas@2224 5992 }
nicholas@2224 5993
nicholas@2224 5994 // If a hook was provided, use that value, otherwise just set the specified value
nicholas@2224 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nicholas@2224 5996 style[ name ] = value;
nicholas@2224 5997 }
nicholas@2224 5998
nicholas@2224 5999 } else {
nicholas@2224 6000 // If a hook was provided get the non-computed value from there
nicholas@2224 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nicholas@2224 6002 return ret;
nicholas@2224 6003 }
nicholas@2224 6004
nicholas@2224 6005 // Otherwise just get the value from the style object
nicholas@2224 6006 return style[ name ];
nicholas@2224 6007 }
nicholas@2224 6008 },
nicholas@2224 6009
nicholas@2224 6010 css: function( elem, name, extra, styles ) {
nicholas@2224 6011 var val, num, hooks,
nicholas@2224 6012 origName = jQuery.camelCase( name );
nicholas@2224 6013
nicholas@2224 6014 // Make sure that we're working with the right name
nicholas@2224 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nicholas@2224 6016
nicholas@2224 6017 // Try prefixed name followed by the unprefixed name
nicholas@2224 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nicholas@2224 6019
nicholas@2224 6020 // If a hook was provided get the computed value from there
nicholas@2224 6021 if ( hooks && "get" in hooks ) {
nicholas@2224 6022 val = hooks.get( elem, true, extra );
nicholas@2224 6023 }
nicholas@2224 6024
nicholas@2224 6025 // Otherwise, if a way to get the computed value exists, use that
nicholas@2224 6026 if ( val === undefined ) {
nicholas@2224 6027 val = curCSS( elem, name, styles );
nicholas@2224 6028 }
nicholas@2224 6029
nicholas@2224 6030 // Convert "normal" to computed value
nicholas@2224 6031 if ( val === "normal" && name in cssNormalTransform ) {
nicholas@2224 6032 val = cssNormalTransform[ name ];
nicholas@2224 6033 }
nicholas@2224 6034
nicholas@2224 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nicholas@2224 6036 if ( extra === "" || extra ) {
nicholas@2224 6037 num = parseFloat( val );
nicholas@2224 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nicholas@2224 6039 }
nicholas@2224 6040 return val;
nicholas@2224 6041 }
nicholas@2224 6042 });
nicholas@2224 6043
nicholas@2224 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nicholas@2224 6045 jQuery.cssHooks[ name ] = {
nicholas@2224 6046 get: function( elem, computed, extra ) {
nicholas@2224 6047 if ( computed ) {
nicholas@2224 6048
nicholas@2224 6049 // Certain elements can have dimension info if we invisibly show them
nicholas@2224 6050 // but it must have a current display style that would benefit
nicholas@2224 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nicholas@2224 6052 jQuery.swap( elem, cssShow, function() {
nicholas@2224 6053 return getWidthOrHeight( elem, name, extra );
nicholas@2224 6054 }) :
nicholas@2224 6055 getWidthOrHeight( elem, name, extra );
nicholas@2224 6056 }
nicholas@2224 6057 },
nicholas@2224 6058
nicholas@2224 6059 set: function( elem, value, extra ) {
nicholas@2224 6060 var styles = extra && getStyles( elem );
nicholas@2224 6061 return setPositiveNumber( elem, value, extra ?
nicholas@2224 6062 augmentWidthOrHeight(
nicholas@2224 6063 elem,
nicholas@2224 6064 name,
nicholas@2224 6065 extra,
nicholas@2224 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nicholas@2224 6067 styles
nicholas@2224 6068 ) : 0
nicholas@2224 6069 );
nicholas@2224 6070 }
nicholas@2224 6071 };
nicholas@2224 6072 });
nicholas@2224 6073
nicholas@2224 6074 // Support: Android 2.3
nicholas@2224 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nicholas@2224 6076 function( elem, computed ) {
nicholas@2224 6077 if ( computed ) {
nicholas@2224 6078 return jQuery.swap( elem, { "display": "inline-block" },
nicholas@2224 6079 curCSS, [ elem, "marginRight" ] );
nicholas@2224 6080 }
nicholas@2224 6081 }
nicholas@2224 6082 );
nicholas@2224 6083
nicholas@2224 6084 // These hooks are used by animate to expand properties
nicholas@2224 6085 jQuery.each({
nicholas@2224 6086 margin: "",
nicholas@2224 6087 padding: "",
nicholas@2224 6088 border: "Width"
nicholas@2224 6089 }, function( prefix, suffix ) {
nicholas@2224 6090 jQuery.cssHooks[ prefix + suffix ] = {
nicholas@2224 6091 expand: function( value ) {
nicholas@2224 6092 var i = 0,
nicholas@2224 6093 expanded = {},
nicholas@2224 6094
nicholas@2224 6095 // Assumes a single number if not a string
nicholas@2224 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nicholas@2224 6097
nicholas@2224 6098 for ( ; i < 4; i++ ) {
nicholas@2224 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nicholas@2224 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nicholas@2224 6101 }
nicholas@2224 6102
nicholas@2224 6103 return expanded;
nicholas@2224 6104 }
nicholas@2224 6105 };
nicholas@2224 6106
nicholas@2224 6107 if ( !rmargin.test( prefix ) ) {
nicholas@2224 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nicholas@2224 6109 }
nicholas@2224 6110 });
nicholas@2224 6111
nicholas@2224 6112 jQuery.fn.extend({
nicholas@2224 6113 css: function( name, value ) {
nicholas@2224 6114 return access( this, function( elem, name, value ) {
nicholas@2224 6115 var styles, len,
nicholas@2224 6116 map = {},
nicholas@2224 6117 i = 0;
nicholas@2224 6118
nicholas@2224 6119 if ( jQuery.isArray( name ) ) {
nicholas@2224 6120 styles = getStyles( elem );
nicholas@2224 6121 len = name.length;
nicholas@2224 6122
nicholas@2224 6123 for ( ; i < len; i++ ) {
nicholas@2224 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nicholas@2224 6125 }
nicholas@2224 6126
nicholas@2224 6127 return map;
nicholas@2224 6128 }
nicholas@2224 6129
nicholas@2224 6130 return value !== undefined ?
nicholas@2224 6131 jQuery.style( elem, name, value ) :
nicholas@2224 6132 jQuery.css( elem, name );
nicholas@2224 6133 }, name, value, arguments.length > 1 );
nicholas@2224 6134 },
nicholas@2224 6135 show: function() {
nicholas@2224 6136 return showHide( this, true );
nicholas@2224 6137 },
nicholas@2224 6138 hide: function() {
nicholas@2224 6139 return showHide( this );
nicholas@2224 6140 },
nicholas@2224 6141 toggle: function( state ) {
nicholas@2224 6142 if ( typeof state === "boolean" ) {
nicholas@2224 6143 return state ? this.show() : this.hide();
nicholas@2224 6144 }
nicholas@2224 6145
nicholas@2224 6146 return this.each(function() {
nicholas@2224 6147 if ( isHidden( this ) ) {
nicholas@2224 6148 jQuery( this ).show();
nicholas@2224 6149 } else {
nicholas@2224 6150 jQuery( this ).hide();
nicholas@2224 6151 }
nicholas@2224 6152 });
nicholas@2224 6153 }
nicholas@2224 6154 });
nicholas@2224 6155
nicholas@2224 6156
nicholas@2224 6157 function Tween( elem, options, prop, end, easing ) {
nicholas@2224 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nicholas@2224 6159 }
nicholas@2224 6160 jQuery.Tween = Tween;
nicholas@2224 6161
nicholas@2224 6162 Tween.prototype = {
nicholas@2224 6163 constructor: Tween,
nicholas@2224 6164 init: function( elem, options, prop, end, easing, unit ) {
nicholas@2224 6165 this.elem = elem;
nicholas@2224 6166 this.prop = prop;
nicholas@2224 6167 this.easing = easing || "swing";
nicholas@2224 6168 this.options = options;
nicholas@2224 6169 this.start = this.now = this.cur();
nicholas@2224 6170 this.end = end;
nicholas@2224 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nicholas@2224 6172 },
nicholas@2224 6173 cur: function() {
nicholas@2224 6174 var hooks = Tween.propHooks[ this.prop ];
nicholas@2224 6175
nicholas@2224 6176 return hooks && hooks.get ?
nicholas@2224 6177 hooks.get( this ) :
nicholas@2224 6178 Tween.propHooks._default.get( this );
nicholas@2224 6179 },
nicholas@2224 6180 run: function( percent ) {
nicholas@2224 6181 var eased,
nicholas@2224 6182 hooks = Tween.propHooks[ this.prop ];
nicholas@2224 6183
nicholas@2224 6184 if ( this.options.duration ) {
nicholas@2224 6185 this.pos = eased = jQuery.easing[ this.easing ](
nicholas@2224 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nicholas@2224 6187 );
nicholas@2224 6188 } else {
nicholas@2224 6189 this.pos = eased = percent;
nicholas@2224 6190 }
nicholas@2224 6191 this.now = ( this.end - this.start ) * eased + this.start;
nicholas@2224 6192
nicholas@2224 6193 if ( this.options.step ) {
nicholas@2224 6194 this.options.step.call( this.elem, this.now, this );
nicholas@2224 6195 }
nicholas@2224 6196
nicholas@2224 6197 if ( hooks && hooks.set ) {
nicholas@2224 6198 hooks.set( this );
nicholas@2224 6199 } else {
nicholas@2224 6200 Tween.propHooks._default.set( this );
nicholas@2224 6201 }
nicholas@2224 6202 return this;
nicholas@2224 6203 }
nicholas@2224 6204 };
nicholas@2224 6205
nicholas@2224 6206 Tween.prototype.init.prototype = Tween.prototype;
nicholas@2224 6207
nicholas@2224 6208 Tween.propHooks = {
nicholas@2224 6209 _default: {
nicholas@2224 6210 get: function( tween ) {
nicholas@2224 6211 var result;
nicholas@2224 6212
nicholas@2224 6213 if ( tween.elem[ tween.prop ] != null &&
nicholas@2224 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nicholas@2224 6215 return tween.elem[ tween.prop ];
nicholas@2224 6216 }
nicholas@2224 6217
nicholas@2224 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nicholas@2224 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nicholas@2224 6220 // Simple values such as "10px" are parsed to Float;
nicholas@2224 6221 // complex values such as "rotate(1rad)" are returned as-is.
nicholas@2224 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nicholas@2224 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nicholas@2224 6224 return !result || result === "auto" ? 0 : result;
nicholas@2224 6225 },
nicholas@2224 6226 set: function( tween ) {
nicholas@2224 6227 // Use step hook for back compat.
nicholas@2224 6228 // Use cssHook if its there.
nicholas@2224 6229 // Use .style if available and use plain properties where available.
nicholas@2224 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nicholas@2224 6231 jQuery.fx.step[ tween.prop ]( tween );
nicholas@2224 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nicholas@2224 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nicholas@2224 6234 } else {
nicholas@2224 6235 tween.elem[ tween.prop ] = tween.now;
nicholas@2224 6236 }
nicholas@2224 6237 }
nicholas@2224 6238 }
nicholas@2224 6239 };
nicholas@2224 6240
nicholas@2224 6241 // Support: IE9
nicholas@2224 6242 // Panic based approach to setting things on disconnected nodes
nicholas@2224 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nicholas@2224 6244 set: function( tween ) {
nicholas@2224 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nicholas@2224 6246 tween.elem[ tween.prop ] = tween.now;
nicholas@2224 6247 }
nicholas@2224 6248 }
nicholas@2224 6249 };
nicholas@2224 6250
nicholas@2224 6251 jQuery.easing = {
nicholas@2224 6252 linear: function( p ) {
nicholas@2224 6253 return p;
nicholas@2224 6254 },
nicholas@2224 6255 swing: function( p ) {
nicholas@2224 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nicholas@2224 6257 }
nicholas@2224 6258 };
nicholas@2224 6259
nicholas@2224 6260 jQuery.fx = Tween.prototype.init;
nicholas@2224 6261
nicholas@2224 6262 // Back Compat <1.8 extension point
nicholas@2224 6263 jQuery.fx.step = {};
nicholas@2224 6264
nicholas@2224 6265
nicholas@2224 6266
nicholas@2224 6267
nicholas@2224 6268 var
nicholas@2224 6269 fxNow, timerId,
nicholas@2224 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nicholas@2224 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nicholas@2224 6272 rrun = /queueHooks$/,
nicholas@2224 6273 animationPrefilters = [ defaultPrefilter ],
nicholas@2224 6274 tweeners = {
nicholas@2224 6275 "*": [ function( prop, value ) {
nicholas@2224 6276 var tween = this.createTween( prop, value ),
nicholas@2224 6277 target = tween.cur(),
nicholas@2224 6278 parts = rfxnum.exec( value ),
nicholas@2224 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nicholas@2224 6280
nicholas@2224 6281 // Starting value computation is required for potential unit mismatches
nicholas@2224 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nicholas@2224 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nicholas@2224 6284 scale = 1,
nicholas@2224 6285 maxIterations = 20;
nicholas@2224 6286
nicholas@2224 6287 if ( start && start[ 3 ] !== unit ) {
nicholas@2224 6288 // Trust units reported by jQuery.css
nicholas@2224 6289 unit = unit || start[ 3 ];
nicholas@2224 6290
nicholas@2224 6291 // Make sure we update the tween properties later on
nicholas@2224 6292 parts = parts || [];
nicholas@2224 6293
nicholas@2224 6294 // Iteratively approximate from a nonzero starting point
nicholas@2224 6295 start = +target || 1;
nicholas@2224 6296
nicholas@2224 6297 do {
nicholas@2224 6298 // If previous iteration zeroed out, double until we get *something*.
nicholas@2224 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nicholas@2224 6300 scale = scale || ".5";
nicholas@2224 6301
nicholas@2224 6302 // Adjust and apply
nicholas@2224 6303 start = start / scale;
nicholas@2224 6304 jQuery.style( tween.elem, prop, start + unit );
nicholas@2224 6305
nicholas@2224 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nicholas@2224 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nicholas@2224 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nicholas@2224 6309 }
nicholas@2224 6310
nicholas@2224 6311 // Update tween properties
nicholas@2224 6312 if ( parts ) {
nicholas@2224 6313 start = tween.start = +start || +target || 0;
nicholas@2224 6314 tween.unit = unit;
nicholas@2224 6315 // If a +=/-= token was provided, we're doing a relative animation
nicholas@2224 6316 tween.end = parts[ 1 ] ?
nicholas@2224 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nicholas@2224 6318 +parts[ 2 ];
nicholas@2224 6319 }
nicholas@2224 6320
nicholas@2224 6321 return tween;
nicholas@2224 6322 } ]
nicholas@2224 6323 };
nicholas@2224 6324
nicholas@2224 6325 // Animations created synchronously will run synchronously
nicholas@2224 6326 function createFxNow() {
nicholas@2224 6327 setTimeout(function() {
nicholas@2224 6328 fxNow = undefined;
nicholas@2224 6329 });
nicholas@2224 6330 return ( fxNow = jQuery.now() );
nicholas@2224 6331 }
nicholas@2224 6332
nicholas@2224 6333 // Generate parameters to create a standard animation
nicholas@2224 6334 function genFx( type, includeWidth ) {
nicholas@2224 6335 var which,
nicholas@2224 6336 i = 0,
nicholas@2224 6337 attrs = { height: type };
nicholas@2224 6338
nicholas@2224 6339 // If we include width, step value is 1 to do all cssExpand values,
nicholas@2224 6340 // otherwise step value is 2 to skip over Left and Right
nicholas@2224 6341 includeWidth = includeWidth ? 1 : 0;
nicholas@2224 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nicholas@2224 6343 which = cssExpand[ i ];
nicholas@2224 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nicholas@2224 6345 }
nicholas@2224 6346
nicholas@2224 6347 if ( includeWidth ) {
nicholas@2224 6348 attrs.opacity = attrs.width = type;
nicholas@2224 6349 }
nicholas@2224 6350
nicholas@2224 6351 return attrs;
nicholas@2224 6352 }
nicholas@2224 6353
nicholas@2224 6354 function createTween( value, prop, animation ) {
nicholas@2224 6355 var tween,
nicholas@2224 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nicholas@2224 6357 index = 0,
nicholas@2224 6358 length = collection.length;
nicholas@2224 6359 for ( ; index < length; index++ ) {
nicholas@2224 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nicholas@2224 6361
nicholas@2224 6362 // We're done with this property
nicholas@2224 6363 return tween;
nicholas@2224 6364 }
nicholas@2224 6365 }
nicholas@2224 6366 }
nicholas@2224 6367
nicholas@2224 6368 function defaultPrefilter( elem, props, opts ) {
nicholas@2224 6369 /* jshint validthis: true */
nicholas@2224 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nicholas@2224 6371 anim = this,
nicholas@2224 6372 orig = {},
nicholas@2224 6373 style = elem.style,
nicholas@2224 6374 hidden = elem.nodeType && isHidden( elem ),
nicholas@2224 6375 dataShow = data_priv.get( elem, "fxshow" );
nicholas@2224 6376
nicholas@2224 6377 // Handle queue: false promises
nicholas@2224 6378 if ( !opts.queue ) {
nicholas@2224 6379 hooks = jQuery._queueHooks( elem, "fx" );
nicholas@2224 6380 if ( hooks.unqueued == null ) {
nicholas@2224 6381 hooks.unqueued = 0;
nicholas@2224 6382 oldfire = hooks.empty.fire;
nicholas@2224 6383 hooks.empty.fire = function() {
nicholas@2224 6384 if ( !hooks.unqueued ) {
nicholas@2224 6385 oldfire();
nicholas@2224 6386 }
nicholas@2224 6387 };
nicholas@2224 6388 }
nicholas@2224 6389 hooks.unqueued++;
nicholas@2224 6390
nicholas@2224 6391 anim.always(function() {
nicholas@2224 6392 // Ensure the complete handler is called before this completes
nicholas@2224 6393 anim.always(function() {
nicholas@2224 6394 hooks.unqueued--;
nicholas@2224 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nicholas@2224 6396 hooks.empty.fire();
nicholas@2224 6397 }
nicholas@2224 6398 });
nicholas@2224 6399 });
nicholas@2224 6400 }
nicholas@2224 6401
nicholas@2224 6402 // Height/width overflow pass
nicholas@2224 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nicholas@2224 6404 // Make sure that nothing sneaks out
nicholas@2224 6405 // Record all 3 overflow attributes because IE9-10 do not
nicholas@2224 6406 // change the overflow attribute when overflowX and
nicholas@2224 6407 // overflowY are set to the same value
nicholas@2224 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nicholas@2224 6409
nicholas@2224 6410 // Set display property to inline-block for height/width
nicholas@2224 6411 // animations on inline elements that are having width/height animated
nicholas@2224 6412 display = jQuery.css( elem, "display" );
nicholas@2224 6413
nicholas@2224 6414 // Test default display if display is currently "none"
nicholas@2224 6415 checkDisplay = display === "none" ?
nicholas@2224 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nicholas@2224 6417
nicholas@2224 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nicholas@2224 6419 style.display = "inline-block";
nicholas@2224 6420 }
nicholas@2224 6421 }
nicholas@2224 6422
nicholas@2224 6423 if ( opts.overflow ) {
nicholas@2224 6424 style.overflow = "hidden";
nicholas@2224 6425 anim.always(function() {
nicholas@2224 6426 style.overflow = opts.overflow[ 0 ];
nicholas@2224 6427 style.overflowX = opts.overflow[ 1 ];
nicholas@2224 6428 style.overflowY = opts.overflow[ 2 ];
nicholas@2224 6429 });
nicholas@2224 6430 }
nicholas@2224 6431
nicholas@2224 6432 // show/hide pass
nicholas@2224 6433 for ( prop in props ) {
nicholas@2224 6434 value = props[ prop ];
nicholas@2224 6435 if ( rfxtypes.exec( value ) ) {
nicholas@2224 6436 delete props[ prop ];
nicholas@2224 6437 toggle = toggle || value === "toggle";
nicholas@2224 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nicholas@2224 6439
nicholas@2224 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@2224 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nicholas@2224 6442 hidden = true;
nicholas@2224 6443 } else {
nicholas@2224 6444 continue;
nicholas@2224 6445 }
nicholas@2224 6446 }
nicholas@2224 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nicholas@2224 6448
nicholas@2224 6449 // Any non-fx value stops us from restoring the original display value
nicholas@2224 6450 } else {
nicholas@2224 6451 display = undefined;
nicholas@2224 6452 }
nicholas@2224 6453 }
nicholas@2224 6454
nicholas@2224 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nicholas@2224 6456 if ( dataShow ) {
nicholas@2224 6457 if ( "hidden" in dataShow ) {
nicholas@2224 6458 hidden = dataShow.hidden;
nicholas@2224 6459 }
nicholas@2224 6460 } else {
nicholas@2224 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nicholas@2224 6462 }
nicholas@2224 6463
nicholas@2224 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nicholas@2224 6465 if ( toggle ) {
nicholas@2224 6466 dataShow.hidden = !hidden;
nicholas@2224 6467 }
nicholas@2224 6468 if ( hidden ) {
nicholas@2224 6469 jQuery( elem ).show();
nicholas@2224 6470 } else {
nicholas@2224 6471 anim.done(function() {
nicholas@2224 6472 jQuery( elem ).hide();
nicholas@2224 6473 });
nicholas@2224 6474 }
nicholas@2224 6475 anim.done(function() {
nicholas@2224 6476 var prop;
nicholas@2224 6477
nicholas@2224 6478 data_priv.remove( elem, "fxshow" );
nicholas@2224 6479 for ( prop in orig ) {
nicholas@2224 6480 jQuery.style( elem, prop, orig[ prop ] );
nicholas@2224 6481 }
nicholas@2224 6482 });
nicholas@2224 6483 for ( prop in orig ) {
nicholas@2224 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nicholas@2224 6485
nicholas@2224 6486 if ( !( prop in dataShow ) ) {
nicholas@2224 6487 dataShow[ prop ] = tween.start;
nicholas@2224 6488 if ( hidden ) {
nicholas@2224 6489 tween.end = tween.start;
nicholas@2224 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nicholas@2224 6491 }
nicholas@2224 6492 }
nicholas@2224 6493 }
nicholas@2224 6494
nicholas@2224 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nicholas@2224 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nicholas@2224 6497 style.display = display;
nicholas@2224 6498 }
nicholas@2224 6499 }
nicholas@2224 6500
nicholas@2224 6501 function propFilter( props, specialEasing ) {
nicholas@2224 6502 var index, name, easing, value, hooks;
nicholas@2224 6503
nicholas@2224 6504 // camelCase, specialEasing and expand cssHook pass
nicholas@2224 6505 for ( index in props ) {
nicholas@2224 6506 name = jQuery.camelCase( index );
nicholas@2224 6507 easing = specialEasing[ name ];
nicholas@2224 6508 value = props[ index ];
nicholas@2224 6509 if ( jQuery.isArray( value ) ) {
nicholas@2224 6510 easing = value[ 1 ];
nicholas@2224 6511 value = props[ index ] = value[ 0 ];
nicholas@2224 6512 }
nicholas@2224 6513
nicholas@2224 6514 if ( index !== name ) {
nicholas@2224 6515 props[ name ] = value;
nicholas@2224 6516 delete props[ index ];
nicholas@2224 6517 }
nicholas@2224 6518
nicholas@2224 6519 hooks = jQuery.cssHooks[ name ];
nicholas@2224 6520 if ( hooks && "expand" in hooks ) {
nicholas@2224 6521 value = hooks.expand( value );
nicholas@2224 6522 delete props[ name ];
nicholas@2224 6523
nicholas@2224 6524 // Not quite $.extend, this won't overwrite existing keys.
nicholas@2224 6525 // Reusing 'index' because we have the correct "name"
nicholas@2224 6526 for ( index in value ) {
nicholas@2224 6527 if ( !( index in props ) ) {
nicholas@2224 6528 props[ index ] = value[ index ];
nicholas@2224 6529 specialEasing[ index ] = easing;
nicholas@2224 6530 }
nicholas@2224 6531 }
nicholas@2224 6532 } else {
nicholas@2224 6533 specialEasing[ name ] = easing;
nicholas@2224 6534 }
nicholas@2224 6535 }
nicholas@2224 6536 }
nicholas@2224 6537
nicholas@2224 6538 function Animation( elem, properties, options ) {
nicholas@2224 6539 var result,
nicholas@2224 6540 stopped,
nicholas@2224 6541 index = 0,
nicholas@2224 6542 length = animationPrefilters.length,
nicholas@2224 6543 deferred = jQuery.Deferred().always( function() {
nicholas@2224 6544 // Don't match elem in the :animated selector
nicholas@2224 6545 delete tick.elem;
nicholas@2224 6546 }),
nicholas@2224 6547 tick = function() {
nicholas@2224 6548 if ( stopped ) {
nicholas@2224 6549 return false;
nicholas@2224 6550 }
nicholas@2224 6551 var currentTime = fxNow || createFxNow(),
nicholas@2224 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nicholas@2224 6553 // Support: Android 2.3
nicholas@2224 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nicholas@2224 6555 temp = remaining / animation.duration || 0,
nicholas@2224 6556 percent = 1 - temp,
nicholas@2224 6557 index = 0,
nicholas@2224 6558 length = animation.tweens.length;
nicholas@2224 6559
nicholas@2224 6560 for ( ; index < length ; index++ ) {
nicholas@2224 6561 animation.tweens[ index ].run( percent );
nicholas@2224 6562 }
nicholas@2224 6563
nicholas@2224 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nicholas@2224 6565
nicholas@2224 6566 if ( percent < 1 && length ) {
nicholas@2224 6567 return remaining;
nicholas@2224 6568 } else {
nicholas@2224 6569 deferred.resolveWith( elem, [ animation ] );
nicholas@2224 6570 return false;
nicholas@2224 6571 }
nicholas@2224 6572 },
nicholas@2224 6573 animation = deferred.promise({
nicholas@2224 6574 elem: elem,
nicholas@2224 6575 props: jQuery.extend( {}, properties ),
nicholas@2224 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nicholas@2224 6577 originalProperties: properties,
nicholas@2224 6578 originalOptions: options,
nicholas@2224 6579 startTime: fxNow || createFxNow(),
nicholas@2224 6580 duration: options.duration,
nicholas@2224 6581 tweens: [],
nicholas@2224 6582 createTween: function( prop, end ) {
nicholas@2224 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nicholas@2224 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nicholas@2224 6585 animation.tweens.push( tween );
nicholas@2224 6586 return tween;
nicholas@2224 6587 },
nicholas@2224 6588 stop: function( gotoEnd ) {
nicholas@2224 6589 var index = 0,
nicholas@2224 6590 // If we are going to the end, we want to run all the tweens
nicholas@2224 6591 // otherwise we skip this part
nicholas@2224 6592 length = gotoEnd ? animation.tweens.length : 0;
nicholas@2224 6593 if ( stopped ) {
nicholas@2224 6594 return this;
nicholas@2224 6595 }
nicholas@2224 6596 stopped = true;
nicholas@2224 6597 for ( ; index < length ; index++ ) {
nicholas@2224 6598 animation.tweens[ index ].run( 1 );
nicholas@2224 6599 }
nicholas@2224 6600
nicholas@2224 6601 // Resolve when we played the last frame; otherwise, reject
nicholas@2224 6602 if ( gotoEnd ) {
nicholas@2224 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nicholas@2224 6604 } else {
nicholas@2224 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nicholas@2224 6606 }
nicholas@2224 6607 return this;
nicholas@2224 6608 }
nicholas@2224 6609 }),
nicholas@2224 6610 props = animation.props;
nicholas@2224 6611
nicholas@2224 6612 propFilter( props, animation.opts.specialEasing );
nicholas@2224 6613
nicholas@2224 6614 for ( ; index < length ; index++ ) {
nicholas@2224 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nicholas@2224 6616 if ( result ) {
nicholas@2224 6617 return result;
nicholas@2224 6618 }
nicholas@2224 6619 }
nicholas@2224 6620
nicholas@2224 6621 jQuery.map( props, createTween, animation );
nicholas@2224 6622
nicholas@2224 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nicholas@2224 6624 animation.opts.start.call( elem, animation );
nicholas@2224 6625 }
nicholas@2224 6626
nicholas@2224 6627 jQuery.fx.timer(
nicholas@2224 6628 jQuery.extend( tick, {
nicholas@2224 6629 elem: elem,
nicholas@2224 6630 anim: animation,
nicholas@2224 6631 queue: animation.opts.queue
nicholas@2224 6632 })
nicholas@2224 6633 );
nicholas@2224 6634
nicholas@2224 6635 // attach callbacks from options
nicholas@2224 6636 return animation.progress( animation.opts.progress )
nicholas@2224 6637 .done( animation.opts.done, animation.opts.complete )
nicholas@2224 6638 .fail( animation.opts.fail )
nicholas@2224 6639 .always( animation.opts.always );
nicholas@2224 6640 }
nicholas@2224 6641
nicholas@2224 6642 jQuery.Animation = jQuery.extend( Animation, {
nicholas@2224 6643
nicholas@2224 6644 tweener: function( props, callback ) {
nicholas@2224 6645 if ( jQuery.isFunction( props ) ) {
nicholas@2224 6646 callback = props;
nicholas@2224 6647 props = [ "*" ];
nicholas@2224 6648 } else {
nicholas@2224 6649 props = props.split(" ");
nicholas@2224 6650 }
nicholas@2224 6651
nicholas@2224 6652 var prop,
nicholas@2224 6653 index = 0,
nicholas@2224 6654 length = props.length;
nicholas@2224 6655
nicholas@2224 6656 for ( ; index < length ; index++ ) {
nicholas@2224 6657 prop = props[ index ];
nicholas@2224 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nicholas@2224 6659 tweeners[ prop ].unshift( callback );
nicholas@2224 6660 }
nicholas@2224 6661 },
nicholas@2224 6662
nicholas@2224 6663 prefilter: function( callback, prepend ) {
nicholas@2224 6664 if ( prepend ) {
nicholas@2224 6665 animationPrefilters.unshift( callback );
nicholas@2224 6666 } else {
nicholas@2224 6667 animationPrefilters.push( callback );
nicholas@2224 6668 }
nicholas@2224 6669 }
nicholas@2224 6670 });
nicholas@2224 6671
nicholas@2224 6672 jQuery.speed = function( speed, easing, fn ) {
nicholas@2224 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nicholas@2224 6674 complete: fn || !fn && easing ||
nicholas@2224 6675 jQuery.isFunction( speed ) && speed,
nicholas@2224 6676 duration: speed,
nicholas@2224 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nicholas@2224 6678 };
nicholas@2224 6679
nicholas@2224 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nicholas@2224 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nicholas@2224 6682
nicholas@2224 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nicholas@2224 6684 if ( opt.queue == null || opt.queue === true ) {
nicholas@2224 6685 opt.queue = "fx";
nicholas@2224 6686 }
nicholas@2224 6687
nicholas@2224 6688 // Queueing
nicholas@2224 6689 opt.old = opt.complete;
nicholas@2224 6690
nicholas@2224 6691 opt.complete = function() {
nicholas@2224 6692 if ( jQuery.isFunction( opt.old ) ) {
nicholas@2224 6693 opt.old.call( this );
nicholas@2224 6694 }
nicholas@2224 6695
nicholas@2224 6696 if ( opt.queue ) {
nicholas@2224 6697 jQuery.dequeue( this, opt.queue );
nicholas@2224 6698 }
nicholas@2224 6699 };
nicholas@2224 6700
nicholas@2224 6701 return opt;
nicholas@2224 6702 };
nicholas@2224 6703
nicholas@2224 6704 jQuery.fn.extend({
nicholas@2224 6705 fadeTo: function( speed, to, easing, callback ) {
nicholas@2224 6706
nicholas@2224 6707 // Show any hidden elements after setting opacity to 0
nicholas@2224 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nicholas@2224 6709
nicholas@2224 6710 // Animate to the value specified
nicholas@2224 6711 .end().animate({ opacity: to }, speed, easing, callback );
nicholas@2224 6712 },
nicholas@2224 6713 animate: function( prop, speed, easing, callback ) {
nicholas@2224 6714 var empty = jQuery.isEmptyObject( prop ),
nicholas@2224 6715 optall = jQuery.speed( speed, easing, callback ),
nicholas@2224 6716 doAnimation = function() {
nicholas@2224 6717 // Operate on a copy of prop so per-property easing won't be lost
nicholas@2224 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nicholas@2224 6719
nicholas@2224 6720 // Empty animations, or finishing resolves immediately
nicholas@2224 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nicholas@2224 6722 anim.stop( true );
nicholas@2224 6723 }
nicholas@2224 6724 };
nicholas@2224 6725 doAnimation.finish = doAnimation;
nicholas@2224 6726
nicholas@2224 6727 return empty || optall.queue === false ?
nicholas@2224 6728 this.each( doAnimation ) :
nicholas@2224 6729 this.queue( optall.queue, doAnimation );
nicholas@2224 6730 },
nicholas@2224 6731 stop: function( type, clearQueue, gotoEnd ) {
nicholas@2224 6732 var stopQueue = function( hooks ) {
nicholas@2224 6733 var stop = hooks.stop;
nicholas@2224 6734 delete hooks.stop;
nicholas@2224 6735 stop( gotoEnd );
nicholas@2224 6736 };
nicholas@2224 6737
nicholas@2224 6738 if ( typeof type !== "string" ) {
nicholas@2224 6739 gotoEnd = clearQueue;
nicholas@2224 6740 clearQueue = type;
nicholas@2224 6741 type = undefined;
nicholas@2224 6742 }
nicholas@2224 6743 if ( clearQueue && type !== false ) {
nicholas@2224 6744 this.queue( type || "fx", [] );
nicholas@2224 6745 }
nicholas@2224 6746
nicholas@2224 6747 return this.each(function() {
nicholas@2224 6748 var dequeue = true,
nicholas@2224 6749 index = type != null && type + "queueHooks",
nicholas@2224 6750 timers = jQuery.timers,
nicholas@2224 6751 data = data_priv.get( this );
nicholas@2224 6752
nicholas@2224 6753 if ( index ) {
nicholas@2224 6754 if ( data[ index ] && data[ index ].stop ) {
nicholas@2224 6755 stopQueue( data[ index ] );
nicholas@2224 6756 }
nicholas@2224 6757 } else {
nicholas@2224 6758 for ( index in data ) {
nicholas@2224 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nicholas@2224 6760 stopQueue( data[ index ] );
nicholas@2224 6761 }
nicholas@2224 6762 }
nicholas@2224 6763 }
nicholas@2224 6764
nicholas@2224 6765 for ( index = timers.length; index--; ) {
nicholas@2224 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nicholas@2224 6767 timers[ index ].anim.stop( gotoEnd );
nicholas@2224 6768 dequeue = false;
nicholas@2224 6769 timers.splice( index, 1 );
nicholas@2224 6770 }
nicholas@2224 6771 }
nicholas@2224 6772
nicholas@2224 6773 // Start the next in the queue if the last step wasn't forced.
nicholas@2224 6774 // Timers currently will call their complete callbacks, which
nicholas@2224 6775 // will dequeue but only if they were gotoEnd.
nicholas@2224 6776 if ( dequeue || !gotoEnd ) {
nicholas@2224 6777 jQuery.dequeue( this, type );
nicholas@2224 6778 }
nicholas@2224 6779 });
nicholas@2224 6780 },
nicholas@2224 6781 finish: function( type ) {
nicholas@2224 6782 if ( type !== false ) {
nicholas@2224 6783 type = type || "fx";
nicholas@2224 6784 }
nicholas@2224 6785 return this.each(function() {
nicholas@2224 6786 var index,
nicholas@2224 6787 data = data_priv.get( this ),
nicholas@2224 6788 queue = data[ type + "queue" ],
nicholas@2224 6789 hooks = data[ type + "queueHooks" ],
nicholas@2224 6790 timers = jQuery.timers,
nicholas@2224 6791 length = queue ? queue.length : 0;
nicholas@2224 6792
nicholas@2224 6793 // Enable finishing flag on private data
nicholas@2224 6794 data.finish = true;
nicholas@2224 6795
nicholas@2224 6796 // Empty the queue first
nicholas@2224 6797 jQuery.queue( this, type, [] );
nicholas@2224 6798
nicholas@2224 6799 if ( hooks && hooks.stop ) {
nicholas@2224 6800 hooks.stop.call( this, true );
nicholas@2224 6801 }
nicholas@2224 6802
nicholas@2224 6803 // Look for any active animations, and finish them
nicholas@2224 6804 for ( index = timers.length; index--; ) {
nicholas@2224 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nicholas@2224 6806 timers[ index ].anim.stop( true );
nicholas@2224 6807 timers.splice( index, 1 );
nicholas@2224 6808 }
nicholas@2224 6809 }
nicholas@2224 6810
nicholas@2224 6811 // Look for any animations in the old queue and finish them
nicholas@2224 6812 for ( index = 0; index < length; index++ ) {
nicholas@2224 6813 if ( queue[ index ] && queue[ index ].finish ) {
nicholas@2224 6814 queue[ index ].finish.call( this );
nicholas@2224 6815 }
nicholas@2224 6816 }
nicholas@2224 6817
nicholas@2224 6818 // Turn off finishing flag
nicholas@2224 6819 delete data.finish;
nicholas@2224 6820 });
nicholas@2224 6821 }
nicholas@2224 6822 });
nicholas@2224 6823
nicholas@2224 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nicholas@2224 6825 var cssFn = jQuery.fn[ name ];
nicholas@2224 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nicholas@2224 6827 return speed == null || typeof speed === "boolean" ?
nicholas@2224 6828 cssFn.apply( this, arguments ) :
nicholas@2224 6829 this.animate( genFx( name, true ), speed, easing, callback );
nicholas@2224 6830 };
nicholas@2224 6831 });
nicholas@2224 6832
nicholas@2224 6833 // Generate shortcuts for custom animations
nicholas@2224 6834 jQuery.each({
nicholas@2224 6835 slideDown: genFx("show"),
nicholas@2224 6836 slideUp: genFx("hide"),
nicholas@2224 6837 slideToggle: genFx("toggle"),
nicholas@2224 6838 fadeIn: { opacity: "show" },
nicholas@2224 6839 fadeOut: { opacity: "hide" },
nicholas@2224 6840 fadeToggle: { opacity: "toggle" }
nicholas@2224 6841 }, function( name, props ) {
nicholas@2224 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nicholas@2224 6843 return this.animate( props, speed, easing, callback );
nicholas@2224 6844 };
nicholas@2224 6845 });
nicholas@2224 6846
nicholas@2224 6847 jQuery.timers = [];
nicholas@2224 6848 jQuery.fx.tick = function() {
nicholas@2224 6849 var timer,
nicholas@2224 6850 i = 0,
nicholas@2224 6851 timers = jQuery.timers;
nicholas@2224 6852
nicholas@2224 6853 fxNow = jQuery.now();
nicholas@2224 6854
nicholas@2224 6855 for ( ; i < timers.length; i++ ) {
nicholas@2224 6856 timer = timers[ i ];
nicholas@2224 6857 // Checks the timer has not already been removed
nicholas@2224 6858 if ( !timer() && timers[ i ] === timer ) {
nicholas@2224 6859 timers.splice( i--, 1 );
nicholas@2224 6860 }
nicholas@2224 6861 }
nicholas@2224 6862
nicholas@2224 6863 if ( !timers.length ) {
nicholas@2224 6864 jQuery.fx.stop();
nicholas@2224 6865 }
nicholas@2224 6866 fxNow = undefined;
nicholas@2224 6867 };
nicholas@2224 6868
nicholas@2224 6869 jQuery.fx.timer = function( timer ) {
nicholas@2224 6870 jQuery.timers.push( timer );
nicholas@2224 6871 if ( timer() ) {
nicholas@2224 6872 jQuery.fx.start();
nicholas@2224 6873 } else {
nicholas@2224 6874 jQuery.timers.pop();
nicholas@2224 6875 }
nicholas@2224 6876 };
nicholas@2224 6877
nicholas@2224 6878 jQuery.fx.interval = 13;
nicholas@2224 6879
nicholas@2224 6880 jQuery.fx.start = function() {
nicholas@2224 6881 if ( !timerId ) {
nicholas@2224 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nicholas@2224 6883 }
nicholas@2224 6884 };
nicholas@2224 6885
nicholas@2224 6886 jQuery.fx.stop = function() {
nicholas@2224 6887 clearInterval( timerId );
nicholas@2224 6888 timerId = null;
nicholas@2224 6889 };
nicholas@2224 6890
nicholas@2224 6891 jQuery.fx.speeds = {
nicholas@2224 6892 slow: 600,
nicholas@2224 6893 fast: 200,
nicholas@2224 6894 // Default speed
nicholas@2224 6895 _default: 400
nicholas@2224 6896 };
nicholas@2224 6897
nicholas@2224 6898
nicholas@2224 6899 // Based off of the plugin by Clint Helfers, with permission.
nicholas@2224 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nicholas@2224 6901 jQuery.fn.delay = function( time, type ) {
nicholas@2224 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nicholas@2224 6903 type = type || "fx";
nicholas@2224 6904
nicholas@2224 6905 return this.queue( type, function( next, hooks ) {
nicholas@2224 6906 var timeout = setTimeout( next, time );
nicholas@2224 6907 hooks.stop = function() {
nicholas@2224 6908 clearTimeout( timeout );
nicholas@2224 6909 };
nicholas@2224 6910 });
nicholas@2224 6911 };
nicholas@2224 6912
nicholas@2224 6913
nicholas@2224 6914 (function() {
nicholas@2224 6915 var input = document.createElement( "input" ),
nicholas@2224 6916 select = document.createElement( "select" ),
nicholas@2224 6917 opt = select.appendChild( document.createElement( "option" ) );
nicholas@2224 6918
nicholas@2224 6919 input.type = "checkbox";
nicholas@2224 6920
nicholas@2224 6921 // Support: iOS<=5.1, Android<=4.2+
nicholas@2224 6922 // Default value for a checkbox should be "on"
nicholas@2224 6923 support.checkOn = input.value !== "";
nicholas@2224 6924
nicholas@2224 6925 // Support: IE<=11+
nicholas@2224 6926 // Must access selectedIndex to make default options select
nicholas@2224 6927 support.optSelected = opt.selected;
nicholas@2224 6928
nicholas@2224 6929 // Support: Android<=2.3
nicholas@2224 6930 // Options inside disabled selects are incorrectly marked as disabled
nicholas@2224 6931 select.disabled = true;
nicholas@2224 6932 support.optDisabled = !opt.disabled;
nicholas@2224 6933
nicholas@2224 6934 // Support: IE<=11+
nicholas@2224 6935 // An input loses its value after becoming a radio
nicholas@2224 6936 input = document.createElement( "input" );
nicholas@2224 6937 input.value = "t";
nicholas@2224 6938 input.type = "radio";
nicholas@2224 6939 support.radioValue = input.value === "t";
nicholas@2224 6940 })();
nicholas@2224 6941
nicholas@2224 6942
nicholas@2224 6943 var nodeHook, boolHook,
nicholas@2224 6944 attrHandle = jQuery.expr.attrHandle;
nicholas@2224 6945
nicholas@2224 6946 jQuery.fn.extend({
nicholas@2224 6947 attr: function( name, value ) {
nicholas@2224 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nicholas@2224 6949 },
nicholas@2224 6950
nicholas@2224 6951 removeAttr: function( name ) {
nicholas@2224 6952 return this.each(function() {
nicholas@2224 6953 jQuery.removeAttr( this, name );
nicholas@2224 6954 });
nicholas@2224 6955 }
nicholas@2224 6956 });
nicholas@2224 6957
nicholas@2224 6958 jQuery.extend({
nicholas@2224 6959 attr: function( elem, name, value ) {
nicholas@2224 6960 var hooks, ret,
nicholas@2224 6961 nType = elem.nodeType;
nicholas@2224 6962
nicholas@2224 6963 // don't get/set attributes on text, comment and attribute nodes
nicholas@2224 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nicholas@2224 6965 return;
nicholas@2224 6966 }
nicholas@2224 6967
nicholas@2224 6968 // Fallback to prop when attributes are not supported
nicholas@2224 6969 if ( typeof elem.getAttribute === strundefined ) {
nicholas@2224 6970 return jQuery.prop( elem, name, value );
nicholas@2224 6971 }
nicholas@2224 6972
nicholas@2224 6973 // All attributes are lowercase
nicholas@2224 6974 // Grab necessary hook if one is defined
nicholas@2224 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nicholas@2224 6976 name = name.toLowerCase();
nicholas@2224 6977 hooks = jQuery.attrHooks[ name ] ||
nicholas@2224 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nicholas@2224 6979 }
nicholas@2224 6980
nicholas@2224 6981 if ( value !== undefined ) {
nicholas@2224 6982
nicholas@2224 6983 if ( value === null ) {
nicholas@2224 6984 jQuery.removeAttr( elem, name );
nicholas@2224 6985
nicholas@2224 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nicholas@2224 6987 return ret;
nicholas@2224 6988
nicholas@2224 6989 } else {
nicholas@2224 6990 elem.setAttribute( name, value + "" );
nicholas@2224 6991 return value;
nicholas@2224 6992 }
nicholas@2224 6993
nicholas@2224 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nicholas@2224 6995 return ret;
nicholas@2224 6996
nicholas@2224 6997 } else {
nicholas@2224 6998 ret = jQuery.find.attr( elem, name );
nicholas@2224 6999
nicholas@2224 7000 // Non-existent attributes return null, we normalize to undefined
nicholas@2224 7001 return ret == null ?
nicholas@2224 7002 undefined :
nicholas@2224 7003 ret;
nicholas@2224 7004 }
nicholas@2224 7005 },
nicholas@2224 7006
nicholas@2224 7007 removeAttr: function( elem, value ) {
nicholas@2224 7008 var name, propName,
nicholas@2224 7009 i = 0,
nicholas@2224 7010 attrNames = value && value.match( rnotwhite );
nicholas@2224 7011
nicholas@2224 7012 if ( attrNames && elem.nodeType === 1 ) {
nicholas@2224 7013 while ( (name = attrNames[i++]) ) {
nicholas@2224 7014 propName = jQuery.propFix[ name ] || name;
nicholas@2224 7015
nicholas@2224 7016 // Boolean attributes get special treatment (#10870)
nicholas@2224 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nicholas@2224 7018 // Set corresponding property to false
nicholas@2224 7019 elem[ propName ] = false;
nicholas@2224 7020 }
nicholas@2224 7021
nicholas@2224 7022 elem.removeAttribute( name );
nicholas@2224 7023 }
nicholas@2224 7024 }
nicholas@2224 7025 },
nicholas@2224 7026
nicholas@2224 7027 attrHooks: {
nicholas@2224 7028 type: {
nicholas@2224 7029 set: function( elem, value ) {
nicholas@2224 7030 if ( !support.radioValue && value === "radio" &&
nicholas@2224 7031 jQuery.nodeName( elem, "input" ) ) {
nicholas@2224 7032 var val = elem.value;
nicholas@2224 7033 elem.setAttribute( "type", value );
nicholas@2224 7034 if ( val ) {
nicholas@2224 7035 elem.value = val;
nicholas@2224 7036 }
nicholas@2224 7037 return value;
nicholas@2224 7038 }
nicholas@2224 7039 }
nicholas@2224 7040 }
nicholas@2224 7041 }
nicholas@2224 7042 });
nicholas@2224 7043
nicholas@2224 7044 // Hooks for boolean attributes
nicholas@2224 7045 boolHook = {
nicholas@2224 7046 set: function( elem, value, name ) {
nicholas@2224 7047 if ( value === false ) {
nicholas@2224 7048 // Remove boolean attributes when set to false
nicholas@2224 7049 jQuery.removeAttr( elem, name );
nicholas@2224 7050 } else {
nicholas@2224 7051 elem.setAttribute( name, name );
nicholas@2224 7052 }
nicholas@2224 7053 return name;
nicholas@2224 7054 }
nicholas@2224 7055 };
nicholas@2224 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nicholas@2224 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nicholas@2224 7058
nicholas@2224 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nicholas@2224 7060 var ret, handle;
nicholas@2224 7061 if ( !isXML ) {
nicholas@2224 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nicholas@2224 7063 handle = attrHandle[ name ];
nicholas@2224 7064 attrHandle[ name ] = ret;
nicholas@2224 7065 ret = getter( elem, name, isXML ) != null ?
nicholas@2224 7066 name.toLowerCase() :
nicholas@2224 7067 null;
nicholas@2224 7068 attrHandle[ name ] = handle;
nicholas@2224 7069 }
nicholas@2224 7070 return ret;
nicholas@2224 7071 };
nicholas@2224 7072 });
nicholas@2224 7073
nicholas@2224 7074
nicholas@2224 7075
nicholas@2224 7076
nicholas@2224 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nicholas@2224 7078
nicholas@2224 7079 jQuery.fn.extend({
nicholas@2224 7080 prop: function( name, value ) {
nicholas@2224 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nicholas@2224 7082 },
nicholas@2224 7083
nicholas@2224 7084 removeProp: function( name ) {
nicholas@2224 7085 return this.each(function() {
nicholas@2224 7086 delete this[ jQuery.propFix[ name ] || name ];
nicholas@2224 7087 });
nicholas@2224 7088 }
nicholas@2224 7089 });
nicholas@2224 7090
nicholas@2224 7091 jQuery.extend({
nicholas@2224 7092 propFix: {
nicholas@2224 7093 "for": "htmlFor",
nicholas@2224 7094 "class": "className"
nicholas@2224 7095 },
nicholas@2224 7096
nicholas@2224 7097 prop: function( elem, name, value ) {
nicholas@2224 7098 var ret, hooks, notxml,
nicholas@2224 7099 nType = elem.nodeType;
nicholas@2224 7100
nicholas@2224 7101 // Don't get/set properties on text, comment and attribute nodes
nicholas@2224 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nicholas@2224 7103 return;
nicholas@2224 7104 }
nicholas@2224 7105
nicholas@2224 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nicholas@2224 7107
nicholas@2224 7108 if ( notxml ) {
nicholas@2224 7109 // Fix name and attach hooks
nicholas@2224 7110 name = jQuery.propFix[ name ] || name;
nicholas@2224 7111 hooks = jQuery.propHooks[ name ];
nicholas@2224 7112 }
nicholas@2224 7113
nicholas@2224 7114 if ( value !== undefined ) {
nicholas@2224 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nicholas@2224 7116 ret :
nicholas@2224 7117 ( elem[ name ] = value );
nicholas@2224 7118
nicholas@2224 7119 } else {
nicholas@2224 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nicholas@2224 7121 ret :
nicholas@2224 7122 elem[ name ];
nicholas@2224 7123 }
nicholas@2224 7124 },
nicholas@2224 7125
nicholas@2224 7126 propHooks: {
nicholas@2224 7127 tabIndex: {
nicholas@2224 7128 get: function( elem ) {
nicholas@2224 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nicholas@2224 7130 elem.tabIndex :
nicholas@2224 7131 -1;
nicholas@2224 7132 }
nicholas@2224 7133 }
nicholas@2224 7134 }
nicholas@2224 7135 });
nicholas@2224 7136
nicholas@2224 7137 if ( !support.optSelected ) {
nicholas@2224 7138 jQuery.propHooks.selected = {
nicholas@2224 7139 get: function( elem ) {
nicholas@2224 7140 var parent = elem.parentNode;
nicholas@2224 7141 if ( parent && parent.parentNode ) {
nicholas@2224 7142 parent.parentNode.selectedIndex;
nicholas@2224 7143 }
nicholas@2224 7144 return null;
nicholas@2224 7145 }
nicholas@2224 7146 };
nicholas@2224 7147 }
nicholas@2224 7148
nicholas@2224 7149 jQuery.each([
nicholas@2224 7150 "tabIndex",
nicholas@2224 7151 "readOnly",
nicholas@2224 7152 "maxLength",
nicholas@2224 7153 "cellSpacing",
nicholas@2224 7154 "cellPadding",
nicholas@2224 7155 "rowSpan",
nicholas@2224 7156 "colSpan",
nicholas@2224 7157 "useMap",
nicholas@2224 7158 "frameBorder",
nicholas@2224 7159 "contentEditable"
nicholas@2224 7160 ], function() {
nicholas@2224 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nicholas@2224 7162 });
nicholas@2224 7163
nicholas@2224 7164
nicholas@2224 7165
nicholas@2224 7166
nicholas@2224 7167 var rclass = /[\t\r\n\f]/g;
nicholas@2224 7168
nicholas@2224 7169 jQuery.fn.extend({
nicholas@2224 7170 addClass: function( value ) {
nicholas@2224 7171 var classes, elem, cur, clazz, j, finalValue,
nicholas@2224 7172 proceed = typeof value === "string" && value,
nicholas@2224 7173 i = 0,
nicholas@2224 7174 len = this.length;
nicholas@2224 7175
nicholas@2224 7176 if ( jQuery.isFunction( value ) ) {
nicholas@2224 7177 return this.each(function( j ) {
nicholas@2224 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nicholas@2224 7179 });
nicholas@2224 7180 }
nicholas@2224 7181
nicholas@2224 7182 if ( proceed ) {
nicholas@2224 7183 // The disjunction here is for better compressibility (see removeClass)
nicholas@2224 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nicholas@2224 7185
nicholas@2224 7186 for ( ; i < len; i++ ) {
nicholas@2224 7187 elem = this[ i ];
nicholas@2224 7188 cur = elem.nodeType === 1 && ( elem.className ?
nicholas@2224 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nicholas@2224 7190 " "
nicholas@2224 7191 );
nicholas@2224 7192
nicholas@2224 7193 if ( cur ) {
nicholas@2224 7194 j = 0;
nicholas@2224 7195 while ( (clazz = classes[j++]) ) {
nicholas@2224 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nicholas@2224 7197 cur += clazz + " ";
nicholas@2224 7198 }
nicholas@2224 7199 }
nicholas@2224 7200
nicholas@2224 7201 // only assign if different to avoid unneeded rendering.
nicholas@2224 7202 finalValue = jQuery.trim( cur );
nicholas@2224 7203 if ( elem.className !== finalValue ) {
nicholas@2224 7204 elem.className = finalValue;
nicholas@2224 7205 }
nicholas@2224 7206 }
nicholas@2224 7207 }
nicholas@2224 7208 }
nicholas@2224 7209
nicholas@2224 7210 return this;
nicholas@2224 7211 },
nicholas@2224 7212
nicholas@2224 7213 removeClass: function( value ) {
nicholas@2224 7214 var classes, elem, cur, clazz, j, finalValue,
nicholas@2224 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nicholas@2224 7216 i = 0,
nicholas@2224 7217 len = this.length;
nicholas@2224 7218
nicholas@2224 7219 if ( jQuery.isFunction( value ) ) {
nicholas@2224 7220 return this.each(function( j ) {
nicholas@2224 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nicholas@2224 7222 });
nicholas@2224 7223 }
nicholas@2224 7224 if ( proceed ) {
nicholas@2224 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nicholas@2224 7226
nicholas@2224 7227 for ( ; i < len; i++ ) {
nicholas@2224 7228 elem = this[ i ];
nicholas@2224 7229 // This expression is here for better compressibility (see addClass)
nicholas@2224 7230 cur = elem.nodeType === 1 && ( elem.className ?
nicholas@2224 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nicholas@2224 7232 ""
nicholas@2224 7233 );
nicholas@2224 7234
nicholas@2224 7235 if ( cur ) {
nicholas@2224 7236 j = 0;
nicholas@2224 7237 while ( (clazz = classes[j++]) ) {
nicholas@2224 7238 // Remove *all* instances
nicholas@2224 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nicholas@2224 7240 cur = cur.replace( " " + clazz + " ", " " );
nicholas@2224 7241 }
nicholas@2224 7242 }
nicholas@2224 7243
nicholas@2224 7244 // Only assign if different to avoid unneeded rendering.
nicholas@2224 7245 finalValue = value ? jQuery.trim( cur ) : "";
nicholas@2224 7246 if ( elem.className !== finalValue ) {
nicholas@2224 7247 elem.className = finalValue;
nicholas@2224 7248 }
nicholas@2224 7249 }
nicholas@2224 7250 }
nicholas@2224 7251 }
nicholas@2224 7252
nicholas@2224 7253 return this;
nicholas@2224 7254 },
nicholas@2224 7255
nicholas@2224 7256 toggleClass: function( value, stateVal ) {
nicholas@2224 7257 var type = typeof value;
nicholas@2224 7258
nicholas@2224 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nicholas@2224 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nicholas@2224 7261 }
nicholas@2224 7262
nicholas@2224 7263 if ( jQuery.isFunction( value ) ) {
nicholas@2224 7264 return this.each(function( i ) {
nicholas@2224 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nicholas@2224 7266 });
nicholas@2224 7267 }
nicholas@2224 7268
nicholas@2224 7269 return this.each(function() {
nicholas@2224 7270 if ( type === "string" ) {
nicholas@2224 7271 // Toggle individual class names
nicholas@2224 7272 var className,
nicholas@2224 7273 i = 0,
nicholas@2224 7274 self = jQuery( this ),
nicholas@2224 7275 classNames = value.match( rnotwhite ) || [];
nicholas@2224 7276
nicholas@2224 7277 while ( (className = classNames[ i++ ]) ) {
nicholas@2224 7278 // Check each className given, space separated list
nicholas@2224 7279 if ( self.hasClass( className ) ) {
nicholas@2224 7280 self.removeClass( className );
nicholas@2224 7281 } else {
nicholas@2224 7282 self.addClass( className );
nicholas@2224 7283 }
nicholas@2224 7284 }
nicholas@2224 7285
nicholas@2224 7286 // Toggle whole class name
nicholas@2224 7287 } else if ( type === strundefined || type === "boolean" ) {
nicholas@2224 7288 if ( this.className ) {
nicholas@2224 7289 // store className if set
nicholas@2224 7290 data_priv.set( this, "__className__", this.className );
nicholas@2224 7291 }
nicholas@2224 7292
nicholas@2224 7293 // If the element has a class name or if we're passed `false`,
nicholas@2224 7294 // then remove the whole classname (if there was one, the above saved it).
nicholas@2224 7295 // Otherwise bring back whatever was previously saved (if anything),
nicholas@2224 7296 // falling back to the empty string if nothing was stored.
nicholas@2224 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nicholas@2224 7298 }
nicholas@2224 7299 });
nicholas@2224 7300 },
nicholas@2224 7301
nicholas@2224 7302 hasClass: function( selector ) {
nicholas@2224 7303 var className = " " + selector + " ",
nicholas@2224 7304 i = 0,
nicholas@2224 7305 l = this.length;
nicholas@2224 7306 for ( ; i < l; i++ ) {
nicholas@2224 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nicholas@2224 7308 return true;
nicholas@2224 7309 }
nicholas@2224 7310 }
nicholas@2224 7311
nicholas@2224 7312 return false;
nicholas@2224 7313 }
nicholas@2224 7314 });
nicholas@2224 7315
nicholas@2224 7316
nicholas@2224 7317
nicholas@2224 7318
nicholas@2224 7319 var rreturn = /\r/g;
nicholas@2224 7320
nicholas@2224 7321 jQuery.fn.extend({
nicholas@2224 7322 val: function( value ) {
nicholas@2224 7323 var hooks, ret, isFunction,
nicholas@2224 7324 elem = this[0];
nicholas@2224 7325
nicholas@2224 7326 if ( !arguments.length ) {
nicholas@2224 7327 if ( elem ) {
nicholas@2224 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nicholas@2224 7329
nicholas@2224 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nicholas@2224 7331 return ret;
nicholas@2224 7332 }
nicholas@2224 7333
nicholas@2224 7334 ret = elem.value;
nicholas@2224 7335
nicholas@2224 7336 return typeof ret === "string" ?
nicholas@2224 7337 // Handle most common string cases
nicholas@2224 7338 ret.replace(rreturn, "") :
nicholas@2224 7339 // Handle cases where value is null/undef or number
nicholas@2224 7340 ret == null ? "" : ret;
nicholas@2224 7341 }
nicholas@2224 7342
nicholas@2224 7343 return;
nicholas@2224 7344 }
nicholas@2224 7345
nicholas@2224 7346 isFunction = jQuery.isFunction( value );
nicholas@2224 7347
nicholas@2224 7348 return this.each(function( i ) {
nicholas@2224 7349 var val;
nicholas@2224 7350
nicholas@2224 7351 if ( this.nodeType !== 1 ) {
nicholas@2224 7352 return;
nicholas@2224 7353 }
nicholas@2224 7354
nicholas@2224 7355 if ( isFunction ) {
nicholas@2224 7356 val = value.call( this, i, jQuery( this ).val() );
nicholas@2224 7357 } else {
nicholas@2224 7358 val = value;
nicholas@2224 7359 }
nicholas@2224 7360
nicholas@2224 7361 // Treat null/undefined as ""; convert numbers to string
nicholas@2224 7362 if ( val == null ) {
nicholas@2224 7363 val = "";
nicholas@2224 7364
nicholas@2224 7365 } else if ( typeof val === "number" ) {
nicholas@2224 7366 val += "";
nicholas@2224 7367
nicholas@2224 7368 } else if ( jQuery.isArray( val ) ) {
nicholas@2224 7369 val = jQuery.map( val, function( value ) {
nicholas@2224 7370 return value == null ? "" : value + "";
nicholas@2224 7371 });
nicholas@2224 7372 }
nicholas@2224 7373
nicholas@2224 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nicholas@2224 7375
nicholas@2224 7376 // If set returns undefined, fall back to normal setting
nicholas@2224 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nicholas@2224 7378 this.value = val;
nicholas@2224 7379 }
nicholas@2224 7380 });
nicholas@2224 7381 }
nicholas@2224 7382 });
nicholas@2224 7383
nicholas@2224 7384 jQuery.extend({
nicholas@2224 7385 valHooks: {
nicholas@2224 7386 option: {
nicholas@2224 7387 get: function( elem ) {
nicholas@2224 7388 var val = jQuery.find.attr( elem, "value" );
nicholas@2224 7389 return val != null ?
nicholas@2224 7390 val :
nicholas@2224 7391 // Support: IE10-11+
nicholas@2224 7392 // option.text throws exceptions (#14686, #14858)
nicholas@2224 7393 jQuery.trim( jQuery.text( elem ) );
nicholas@2224 7394 }
nicholas@2224 7395 },
nicholas@2224 7396 select: {
nicholas@2224 7397 get: function( elem ) {
nicholas@2224 7398 var value, option,
nicholas@2224 7399 options = elem.options,
nicholas@2224 7400 index = elem.selectedIndex,
nicholas@2224 7401 one = elem.type === "select-one" || index < 0,
nicholas@2224 7402 values = one ? null : [],
nicholas@2224 7403 max = one ? index + 1 : options.length,
nicholas@2224 7404 i = index < 0 ?
nicholas@2224 7405 max :
nicholas@2224 7406 one ? index : 0;
nicholas@2224 7407
nicholas@2224 7408 // Loop through all the selected options
nicholas@2224 7409 for ( ; i < max; i++ ) {
nicholas@2224 7410 option = options[ i ];
nicholas@2224 7411
nicholas@2224 7412 // IE6-9 doesn't update selected after form reset (#2551)
nicholas@2224 7413 if ( ( option.selected || i === index ) &&
nicholas@2224 7414 // Don't return options that are disabled or in a disabled optgroup
nicholas@2224 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nicholas@2224 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nicholas@2224 7417
nicholas@2224 7418 // Get the specific value for the option
nicholas@2224 7419 value = jQuery( option ).val();
nicholas@2224 7420
nicholas@2224 7421 // We don't need an array for one selects
nicholas@2224 7422 if ( one ) {
nicholas@2224 7423 return value;
nicholas@2224 7424 }
nicholas@2224 7425
nicholas@2224 7426 // Multi-Selects return an array
nicholas@2224 7427 values.push( value );
nicholas@2224 7428 }
nicholas@2224 7429 }
nicholas@2224 7430
nicholas@2224 7431 return values;
nicholas@2224 7432 },
nicholas@2224 7433
nicholas@2224 7434 set: function( elem, value ) {
nicholas@2224 7435 var optionSet, option,
nicholas@2224 7436 options = elem.options,
nicholas@2224 7437 values = jQuery.makeArray( value ),
nicholas@2224 7438 i = options.length;
nicholas@2224 7439
nicholas@2224 7440 while ( i-- ) {
nicholas@2224 7441 option = options[ i ];
nicholas@2224 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nicholas@2224 7443 optionSet = true;
nicholas@2224 7444 }
nicholas@2224 7445 }
nicholas@2224 7446
nicholas@2224 7447 // Force browsers to behave consistently when non-matching value is set
nicholas@2224 7448 if ( !optionSet ) {
nicholas@2224 7449 elem.selectedIndex = -1;
nicholas@2224 7450 }
nicholas@2224 7451 return values;
nicholas@2224 7452 }
nicholas@2224 7453 }
nicholas@2224 7454 }
nicholas@2224 7455 });
nicholas@2224 7456
nicholas@2224 7457 // Radios and checkboxes getter/setter
nicholas@2224 7458 jQuery.each([ "radio", "checkbox" ], function() {
nicholas@2224 7459 jQuery.valHooks[ this ] = {
nicholas@2224 7460 set: function( elem, value ) {
nicholas@2224 7461 if ( jQuery.isArray( value ) ) {
nicholas@2224 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nicholas@2224 7463 }
nicholas@2224 7464 }
nicholas@2224 7465 };
nicholas@2224 7466 if ( !support.checkOn ) {
nicholas@2224 7467 jQuery.valHooks[ this ].get = function( elem ) {
nicholas@2224 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nicholas@2224 7469 };
nicholas@2224 7470 }
nicholas@2224 7471 });
nicholas@2224 7472
nicholas@2224 7473
nicholas@2224 7474
nicholas@2224 7475
nicholas@2224 7476 // Return jQuery for attributes-only inclusion
nicholas@2224 7477
nicholas@2224 7478
nicholas@2224 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nicholas@2224 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nicholas@2224 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nicholas@2224 7482
nicholas@2224 7483 // Handle event binding
nicholas@2224 7484 jQuery.fn[ name ] = function( data, fn ) {
nicholas@2224 7485 return arguments.length > 0 ?
nicholas@2224 7486 this.on( name, null, data, fn ) :
nicholas@2224 7487 this.trigger( name );
nicholas@2224 7488 };
nicholas@2224 7489 });
nicholas@2224 7490
nicholas@2224 7491 jQuery.fn.extend({
nicholas@2224 7492 hover: function( fnOver, fnOut ) {
nicholas@2224 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nicholas@2224 7494 },
nicholas@2224 7495
nicholas@2224 7496 bind: function( types, data, fn ) {
nicholas@2224 7497 return this.on( types, null, data, fn );
nicholas@2224 7498 },
nicholas@2224 7499 unbind: function( types, fn ) {
nicholas@2224 7500 return this.off( types, null, fn );
nicholas@2224 7501 },
nicholas@2224 7502
nicholas@2224 7503 delegate: function( selector, types, data, fn ) {
nicholas@2224 7504 return this.on( types, selector, data, fn );
nicholas@2224 7505 },
nicholas@2224 7506 undelegate: function( selector, types, fn ) {
nicholas@2224 7507 // ( namespace ) or ( selector, types [, fn] )
nicholas@2224 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nicholas@2224 7509 }
nicholas@2224 7510 });
nicholas@2224 7511
nicholas@2224 7512
nicholas@2224 7513 var nonce = jQuery.now();
nicholas@2224 7514
nicholas@2224 7515 var rquery = (/\?/);
nicholas@2224 7516
nicholas@2224 7517
nicholas@2224 7518
nicholas@2224 7519 // Support: Android 2.3
nicholas@2224 7520 // Workaround failure to string-cast null input
nicholas@2224 7521 jQuery.parseJSON = function( data ) {
nicholas@2224 7522 return JSON.parse( data + "" );
nicholas@2224 7523 };
nicholas@2224 7524
nicholas@2224 7525
nicholas@2224 7526 // Cross-browser xml parsing
nicholas@2224 7527 jQuery.parseXML = function( data ) {
nicholas@2224 7528 var xml, tmp;
nicholas@2224 7529 if ( !data || typeof data !== "string" ) {
nicholas@2224 7530 return null;
nicholas@2224 7531 }
nicholas@2224 7532
nicholas@2224 7533 // Support: IE9
nicholas@2224 7534 try {
nicholas@2224 7535 tmp = new DOMParser();
nicholas@2224 7536 xml = tmp.parseFromString( data, "text/xml" );
nicholas@2224 7537 } catch ( e ) {
nicholas@2224 7538 xml = undefined;
nicholas@2224 7539 }
nicholas@2224 7540
nicholas@2224 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nicholas@2224 7542 jQuery.error( "Invalid XML: " + data );
nicholas@2224 7543 }
nicholas@2224 7544 return xml;
nicholas@2224 7545 };
nicholas@2224 7546
nicholas@2224 7547
nicholas@2224 7548 var
nicholas@2224 7549 rhash = /#.*$/,
nicholas@2224 7550 rts = /([?&])_=[^&]*/,
nicholas@2224 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nicholas@2224 7552 // #7653, #8125, #8152: local protocol detection
nicholas@2224 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nicholas@2224 7554 rnoContent = /^(?:GET|HEAD)$/,
nicholas@2224 7555 rprotocol = /^\/\//,
nicholas@2224 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nicholas@2224 7557
nicholas@2224 7558 /* Prefilters
nicholas@2224 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nicholas@2224 7560 * 2) These are called:
nicholas@2224 7561 * - BEFORE asking for a transport
nicholas@2224 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nicholas@2224 7563 * 3) key is the dataType
nicholas@2224 7564 * 4) the catchall symbol "*" can be used
nicholas@2224 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nicholas@2224 7566 */
nicholas@2224 7567 prefilters = {},
nicholas@2224 7568
nicholas@2224 7569 /* Transports bindings
nicholas@2224 7570 * 1) key is the dataType
nicholas@2224 7571 * 2) the catchall symbol "*" can be used
nicholas@2224 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nicholas@2224 7573 */
nicholas@2224 7574 transports = {},
nicholas@2224 7575
nicholas@2224 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nicholas@2224 7577 allTypes = "*/".concat( "*" ),
nicholas@2224 7578
nicholas@2224 7579 // Document location
nicholas@2224 7580 ajaxLocation = window.location.href,
nicholas@2224 7581
nicholas@2224 7582 // Segment location into parts
nicholas@2224 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nicholas@2224 7584
nicholas@2224 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nicholas@2224 7586 function addToPrefiltersOrTransports( structure ) {
nicholas@2224 7587
nicholas@2224 7588 // dataTypeExpression is optional and defaults to "*"
nicholas@2224 7589 return function( dataTypeExpression, func ) {
nicholas@2224 7590
nicholas@2224 7591 if ( typeof dataTypeExpression !== "string" ) {
nicholas@2224 7592 func = dataTypeExpression;
nicholas@2224 7593 dataTypeExpression = "*";
nicholas@2224 7594 }
nicholas@2224 7595
nicholas@2224 7596 var dataType,
nicholas@2224 7597 i = 0,
nicholas@2224 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nicholas@2224 7599
nicholas@2224 7600 if ( jQuery.isFunction( func ) ) {
nicholas@2224 7601 // For each dataType in the dataTypeExpression
nicholas@2224 7602 while ( (dataType = dataTypes[i++]) ) {
nicholas@2224 7603 // Prepend if requested
nicholas@2224 7604 if ( dataType[0] === "+" ) {
nicholas@2224 7605 dataType = dataType.slice( 1 ) || "*";
nicholas@2224 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nicholas@2224 7607
nicholas@2224 7608 // Otherwise append
nicholas@2224 7609 } else {
nicholas@2224 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nicholas@2224 7611 }
nicholas@2224 7612 }
nicholas@2224 7613 }
nicholas@2224 7614 };
nicholas@2224 7615 }
nicholas@2224 7616
nicholas@2224 7617 // Base inspection function for prefilters and transports
nicholas@2224 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nicholas@2224 7619
nicholas@2224 7620 var inspected = {},
nicholas@2224 7621 seekingTransport = ( structure === transports );
nicholas@2224 7622
nicholas@2224 7623 function inspect( dataType ) {
nicholas@2224 7624 var selected;
nicholas@2224 7625 inspected[ dataType ] = true;
nicholas@2224 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nicholas@2224 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nicholas@2224 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nicholas@2224 7629 options.dataTypes.unshift( dataTypeOrTransport );
nicholas@2224 7630 inspect( dataTypeOrTransport );
nicholas@2224 7631 return false;
nicholas@2224 7632 } else if ( seekingTransport ) {
nicholas@2224 7633 return !( selected = dataTypeOrTransport );
nicholas@2224 7634 }
nicholas@2224 7635 });
nicholas@2224 7636 return selected;
nicholas@2224 7637 }
nicholas@2224 7638
nicholas@2224 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nicholas@2224 7640 }
nicholas@2224 7641
nicholas@2224 7642 // A special extend for ajax options
nicholas@2224 7643 // that takes "flat" options (not to be deep extended)
nicholas@2224 7644 // Fixes #9887
nicholas@2224 7645 function ajaxExtend( target, src ) {
nicholas@2224 7646 var key, deep,
nicholas@2224 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nicholas@2224 7648
nicholas@2224 7649 for ( key in src ) {
nicholas@2224 7650 if ( src[ key ] !== undefined ) {
nicholas@2224 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nicholas@2224 7652 }
nicholas@2224 7653 }
nicholas@2224 7654 if ( deep ) {
nicholas@2224 7655 jQuery.extend( true, target, deep );
nicholas@2224 7656 }
nicholas@2224 7657
nicholas@2224 7658 return target;
nicholas@2224 7659 }
nicholas@2224 7660
nicholas@2224 7661 /* Handles responses to an ajax request:
nicholas@2224 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nicholas@2224 7663 * - returns the corresponding response
nicholas@2224 7664 */
nicholas@2224 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nicholas@2224 7666
nicholas@2224 7667 var ct, type, finalDataType, firstDataType,
nicholas@2224 7668 contents = s.contents,
nicholas@2224 7669 dataTypes = s.dataTypes;
nicholas@2224 7670
nicholas@2224 7671 // Remove auto dataType and get content-type in the process
nicholas@2224 7672 while ( dataTypes[ 0 ] === "*" ) {
nicholas@2224 7673 dataTypes.shift();
nicholas@2224 7674 if ( ct === undefined ) {
nicholas@2224 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nicholas@2224 7676 }
nicholas@2224 7677 }
nicholas@2224 7678
nicholas@2224 7679 // Check if we're dealing with a known content-type
nicholas@2224 7680 if ( ct ) {
nicholas@2224 7681 for ( type in contents ) {
nicholas@2224 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nicholas@2224 7683 dataTypes.unshift( type );
nicholas@2224 7684 break;
nicholas@2224 7685 }
nicholas@2224 7686 }
nicholas@2224 7687 }
nicholas@2224 7688
nicholas@2224 7689 // Check to see if we have a response for the expected dataType
nicholas@2224 7690 if ( dataTypes[ 0 ] in responses ) {
nicholas@2224 7691 finalDataType = dataTypes[ 0 ];
nicholas@2224 7692 } else {
nicholas@2224 7693 // Try convertible dataTypes
nicholas@2224 7694 for ( type in responses ) {
nicholas@2224 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nicholas@2224 7696 finalDataType = type;
nicholas@2224 7697 break;
nicholas@2224 7698 }
nicholas@2224 7699 if ( !firstDataType ) {
nicholas@2224 7700 firstDataType = type;
nicholas@2224 7701 }
nicholas@2224 7702 }
nicholas@2224 7703 // Or just use first one
nicholas@2224 7704 finalDataType = finalDataType || firstDataType;
nicholas@2224 7705 }
nicholas@2224 7706
nicholas@2224 7707 // If we found a dataType
nicholas@2224 7708 // We add the dataType to the list if needed
nicholas@2224 7709 // and return the corresponding response
nicholas@2224 7710 if ( finalDataType ) {
nicholas@2224 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nicholas@2224 7712 dataTypes.unshift( finalDataType );
nicholas@2224 7713 }
nicholas@2224 7714 return responses[ finalDataType ];
nicholas@2224 7715 }
nicholas@2224 7716 }
nicholas@2224 7717
nicholas@2224 7718 /* Chain conversions given the request and the original response
nicholas@2224 7719 * Also sets the responseXXX fields on the jqXHR instance
nicholas@2224 7720 */
nicholas@2224 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nicholas@2224 7722 var conv2, current, conv, tmp, prev,
nicholas@2224 7723 converters = {},
nicholas@2224 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nicholas@2224 7725 dataTypes = s.dataTypes.slice();
nicholas@2224 7726
nicholas@2224 7727 // Create converters map with lowercased keys
nicholas@2224 7728 if ( dataTypes[ 1 ] ) {
nicholas@2224 7729 for ( conv in s.converters ) {
nicholas@2224 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nicholas@2224 7731 }
nicholas@2224 7732 }
nicholas@2224 7733
nicholas@2224 7734 current = dataTypes.shift();
nicholas@2224 7735
nicholas@2224 7736 // Convert to each sequential dataType
nicholas@2224 7737 while ( current ) {
nicholas@2224 7738
nicholas@2224 7739 if ( s.responseFields[ current ] ) {
nicholas@2224 7740 jqXHR[ s.responseFields[ current ] ] = response;
nicholas@2224 7741 }
nicholas@2224 7742
nicholas@2224 7743 // Apply the dataFilter if provided
nicholas@2224 7744 if ( !prev && isSuccess && s.dataFilter ) {
nicholas@2224 7745 response = s.dataFilter( response, s.dataType );
nicholas@2224 7746 }
nicholas@2224 7747
nicholas@2224 7748 prev = current;
nicholas@2224 7749 current = dataTypes.shift();
nicholas@2224 7750
nicholas@2224 7751 if ( current ) {
nicholas@2224 7752
nicholas@2224 7753 // There's only work to do if current dataType is non-auto
nicholas@2224 7754 if ( current === "*" ) {
nicholas@2224 7755
nicholas@2224 7756 current = prev;
nicholas@2224 7757
nicholas@2224 7758 // Convert response if prev dataType is non-auto and differs from current
nicholas@2224 7759 } else if ( prev !== "*" && prev !== current ) {
nicholas@2224 7760
nicholas@2224 7761 // Seek a direct converter
nicholas@2224 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nicholas@2224 7763
nicholas@2224 7764 // If none found, seek a pair
nicholas@2224 7765 if ( !conv ) {
nicholas@2224 7766 for ( conv2 in converters ) {
nicholas@2224 7767
nicholas@2224 7768 // If conv2 outputs current
nicholas@2224 7769 tmp = conv2.split( " " );
nicholas@2224 7770 if ( tmp[ 1 ] === current ) {
nicholas@2224 7771
nicholas@2224 7772 // If prev can be converted to accepted input
nicholas@2224 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nicholas@2224 7774 converters[ "* " + tmp[ 0 ] ];
nicholas@2224 7775 if ( conv ) {
nicholas@2224 7776 // Condense equivalence converters
nicholas@2224 7777 if ( conv === true ) {
nicholas@2224 7778 conv = converters[ conv2 ];
nicholas@2224 7779
nicholas@2224 7780 // Otherwise, insert the intermediate dataType
nicholas@2224 7781 } else if ( converters[ conv2 ] !== true ) {
nicholas@2224 7782 current = tmp[ 0 ];
nicholas@2224 7783 dataTypes.unshift( tmp[ 1 ] );
nicholas@2224 7784 }
nicholas@2224 7785 break;
nicholas@2224 7786 }
nicholas@2224 7787 }
nicholas@2224 7788 }
nicholas@2224 7789 }
nicholas@2224 7790
nicholas@2224 7791 // Apply converter (if not an equivalence)
nicholas@2224 7792 if ( conv !== true ) {
nicholas@2224 7793
nicholas@2224 7794 // Unless errors are allowed to bubble, catch and return them
nicholas@2224 7795 if ( conv && s[ "throws" ] ) {
nicholas@2224 7796 response = conv( response );
nicholas@2224 7797 } else {
nicholas@2224 7798 try {
nicholas@2224 7799 response = conv( response );
nicholas@2224 7800 } catch ( e ) {
nicholas@2224 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nicholas@2224 7802 }
nicholas@2224 7803 }
nicholas@2224 7804 }
nicholas@2224 7805 }
nicholas@2224 7806 }
nicholas@2224 7807 }
nicholas@2224 7808
nicholas@2224 7809 return { state: "success", data: response };
nicholas@2224 7810 }
nicholas@2224 7811
nicholas@2224 7812 jQuery.extend({
nicholas@2224 7813
nicholas@2224 7814 // Counter for holding the number of active queries
nicholas@2224 7815 active: 0,
nicholas@2224 7816
nicholas@2224 7817 // Last-Modified header cache for next request
nicholas@2224 7818 lastModified: {},
nicholas@2224 7819 etag: {},
nicholas@2224 7820
nicholas@2224 7821 ajaxSettings: {
nicholas@2224 7822 url: ajaxLocation,
nicholas@2224 7823 type: "GET",
nicholas@2224 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nicholas@2224 7825 global: true,
nicholas@2224 7826 processData: true,
nicholas@2224 7827 async: true,
nicholas@2224 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nicholas@2224 7829 /*
nicholas@2224 7830 timeout: 0,
nicholas@2224 7831 data: null,
nicholas@2224 7832 dataType: null,
nicholas@2224 7833 username: null,
nicholas@2224 7834 password: null,
nicholas@2224 7835 cache: null,
nicholas@2224 7836 throws: false,
nicholas@2224 7837 traditional: false,
nicholas@2224 7838 headers: {},
nicholas@2224 7839 */
nicholas@2224 7840
nicholas@2224 7841 accepts: {
nicholas@2224 7842 "*": allTypes,
nicholas@2224 7843 text: "text/plain",
nicholas@2224 7844 html: "text/html",
nicholas@2224 7845 xml: "application/xml, text/xml",
nicholas@2224 7846 json: "application/json, text/javascript"
nicholas@2224 7847 },
nicholas@2224 7848
nicholas@2224 7849 contents: {
nicholas@2224 7850 xml: /xml/,
nicholas@2224 7851 html: /html/,
nicholas@2224 7852 json: /json/
nicholas@2224 7853 },
nicholas@2224 7854
nicholas@2224 7855 responseFields: {
nicholas@2224 7856 xml: "responseXML",
nicholas@2224 7857 text: "responseText",
nicholas@2224 7858 json: "responseJSON"
nicholas@2224 7859 },
nicholas@2224 7860
nicholas@2224 7861 // Data converters
nicholas@2224 7862 // Keys separate source (or catchall "*") and destination types with a single space
nicholas@2224 7863 converters: {
nicholas@2224 7864
nicholas@2224 7865 // Convert anything to text
nicholas@2224 7866 "* text": String,
nicholas@2224 7867
nicholas@2224 7868 // Text to html (true = no transformation)
nicholas@2224 7869 "text html": true,
nicholas@2224 7870
nicholas@2224 7871 // Evaluate text as a json expression
nicholas@2224 7872 "text json": jQuery.parseJSON,
nicholas@2224 7873
nicholas@2224 7874 // Parse text as xml
nicholas@2224 7875 "text xml": jQuery.parseXML
nicholas@2224 7876 },
nicholas@2224 7877
nicholas@2224 7878 // For options that shouldn't be deep extended:
nicholas@2224 7879 // you can add your own custom options here if
nicholas@2224 7880 // and when you create one that shouldn't be
nicholas@2224 7881 // deep extended (see ajaxExtend)
nicholas@2224 7882 flatOptions: {
nicholas@2224 7883 url: true,
nicholas@2224 7884 context: true
nicholas@2224 7885 }
nicholas@2224 7886 },
nicholas@2224 7887
nicholas@2224 7888 // Creates a full fledged settings object into target
nicholas@2224 7889 // with both ajaxSettings and settings fields.
nicholas@2224 7890 // If target is omitted, writes into ajaxSettings.
nicholas@2224 7891 ajaxSetup: function( target, settings ) {
nicholas@2224 7892 return settings ?
nicholas@2224 7893
nicholas@2224 7894 // Building a settings object
nicholas@2224 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nicholas@2224 7896
nicholas@2224 7897 // Extending ajaxSettings
nicholas@2224 7898 ajaxExtend( jQuery.ajaxSettings, target );
nicholas@2224 7899 },
nicholas@2224 7900
nicholas@2224 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nicholas@2224 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nicholas@2224 7903
nicholas@2224 7904 // Main method
nicholas@2224 7905 ajax: function( url, options ) {
nicholas@2224 7906
nicholas@2224 7907 // If url is an object, simulate pre-1.5 signature
nicholas@2224 7908 if ( typeof url === "object" ) {
nicholas@2224 7909 options = url;
nicholas@2224 7910 url = undefined;
nicholas@2224 7911 }
nicholas@2224 7912
nicholas@2224 7913 // Force options to be an object
nicholas@2224 7914 options = options || {};
nicholas@2224 7915
nicholas@2224 7916 var transport,
nicholas@2224 7917 // URL without anti-cache param
nicholas@2224 7918 cacheURL,
nicholas@2224 7919 // Response headers
nicholas@2224 7920 responseHeadersString,
nicholas@2224 7921 responseHeaders,
nicholas@2224 7922 // timeout handle
nicholas@2224 7923 timeoutTimer,
nicholas@2224 7924 // Cross-domain detection vars
nicholas@2224 7925 parts,
nicholas@2224 7926 // To know if global events are to be dispatched
nicholas@2224 7927 fireGlobals,
nicholas@2224 7928 // Loop variable
nicholas@2224 7929 i,
nicholas@2224 7930 // Create the final options object
nicholas@2224 7931 s = jQuery.ajaxSetup( {}, options ),
nicholas@2224 7932 // Callbacks context
nicholas@2224 7933 callbackContext = s.context || s,
nicholas@2224 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nicholas@2224 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nicholas@2224 7936 jQuery( callbackContext ) :
nicholas@2224 7937 jQuery.event,
nicholas@2224 7938 // Deferreds
nicholas@2224 7939 deferred = jQuery.Deferred(),
nicholas@2224 7940 completeDeferred = jQuery.Callbacks("once memory"),
nicholas@2224 7941 // Status-dependent callbacks
nicholas@2224 7942 statusCode = s.statusCode || {},
nicholas@2224 7943 // Headers (they are sent all at once)
nicholas@2224 7944 requestHeaders = {},
nicholas@2224 7945 requestHeadersNames = {},
nicholas@2224 7946 // The jqXHR state
nicholas@2224 7947 state = 0,
nicholas@2224 7948 // Default abort message
nicholas@2224 7949 strAbort = "canceled",
nicholas@2224 7950 // Fake xhr
nicholas@2224 7951 jqXHR = {
nicholas@2224 7952 readyState: 0,
nicholas@2224 7953
nicholas@2224 7954 // Builds headers hashtable if needed
nicholas@2224 7955 getResponseHeader: function( key ) {
nicholas@2224 7956 var match;
nicholas@2224 7957 if ( state === 2 ) {
nicholas@2224 7958 if ( !responseHeaders ) {
nicholas@2224 7959 responseHeaders = {};
nicholas@2224 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nicholas@2224 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nicholas@2224 7962 }
nicholas@2224 7963 }
nicholas@2224 7964 match = responseHeaders[ key.toLowerCase() ];
nicholas@2224 7965 }
nicholas@2224 7966 return match == null ? null : match;
nicholas@2224 7967 },
nicholas@2224 7968
nicholas@2224 7969 // Raw string
nicholas@2224 7970 getAllResponseHeaders: function() {
nicholas@2224 7971 return state === 2 ? responseHeadersString : null;
nicholas@2224 7972 },
nicholas@2224 7973
nicholas@2224 7974 // Caches the header
nicholas@2224 7975 setRequestHeader: function( name, value ) {
nicholas@2224 7976 var lname = name.toLowerCase();
nicholas@2224 7977 if ( !state ) {
nicholas@2224 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nicholas@2224 7979 requestHeaders[ name ] = value;
nicholas@2224 7980 }
nicholas@2224 7981 return this;
nicholas@2224 7982 },
nicholas@2224 7983
nicholas@2224 7984 // Overrides response content-type header
nicholas@2224 7985 overrideMimeType: function( type ) {
nicholas@2224 7986 if ( !state ) {
nicholas@2224 7987 s.mimeType = type;
nicholas@2224 7988 }
nicholas@2224 7989 return this;
nicholas@2224 7990 },
nicholas@2224 7991
nicholas@2224 7992 // Status-dependent callbacks
nicholas@2224 7993 statusCode: function( map ) {
nicholas@2224 7994 var code;
nicholas@2224 7995 if ( map ) {
nicholas@2224 7996 if ( state < 2 ) {
nicholas@2224 7997 for ( code in map ) {
nicholas@2224 7998 // Lazy-add the new callback in a way that preserves old ones
nicholas@2224 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nicholas@2224 8000 }
nicholas@2224 8001 } else {
nicholas@2224 8002 // Execute the appropriate callbacks
nicholas@2224 8003 jqXHR.always( map[ jqXHR.status ] );
nicholas@2224 8004 }
nicholas@2224 8005 }
nicholas@2224 8006 return this;
nicholas@2224 8007 },
nicholas@2224 8008
nicholas@2224 8009 // Cancel the request
nicholas@2224 8010 abort: function( statusText ) {
nicholas@2224 8011 var finalText = statusText || strAbort;
nicholas@2224 8012 if ( transport ) {
nicholas@2224 8013 transport.abort( finalText );
nicholas@2224 8014 }
nicholas@2224 8015 done( 0, finalText );
nicholas@2224 8016 return this;
nicholas@2224 8017 }
nicholas@2224 8018 };
nicholas@2224 8019
nicholas@2224 8020 // Attach deferreds
nicholas@2224 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nicholas@2224 8022 jqXHR.success = jqXHR.done;
nicholas@2224 8023 jqXHR.error = jqXHR.fail;
nicholas@2224 8024
nicholas@2224 8025 // Remove hash character (#7531: and string promotion)
nicholas@2224 8026 // Add protocol if not provided (prefilters might expect it)
nicholas@2224 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nicholas@2224 8028 // We also use the url parameter if available
nicholas@2224 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nicholas@2224 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nicholas@2224 8031
nicholas@2224 8032 // Alias method option to type as per ticket #12004
nicholas@2224 8033 s.type = options.method || options.type || s.method || s.type;
nicholas@2224 8034
nicholas@2224 8035 // Extract dataTypes list
nicholas@2224 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nicholas@2224 8037
nicholas@2224 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nicholas@2224 8039 if ( s.crossDomain == null ) {
nicholas@2224 8040 parts = rurl.exec( s.url.toLowerCase() );
nicholas@2224 8041 s.crossDomain = !!( parts &&
nicholas@2224 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nicholas@2224 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nicholas@2224 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nicholas@2224 8045 );
nicholas@2224 8046 }
nicholas@2224 8047
nicholas@2224 8048 // Convert data if not already a string
nicholas@2224 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nicholas@2224 8050 s.data = jQuery.param( s.data, s.traditional );
nicholas@2224 8051 }
nicholas@2224 8052
nicholas@2224 8053 // Apply prefilters
nicholas@2224 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nicholas@2224 8055
nicholas@2224 8056 // If request was aborted inside a prefilter, stop there
nicholas@2224 8057 if ( state === 2 ) {
nicholas@2224 8058 return jqXHR;
nicholas@2224 8059 }
nicholas@2224 8060
nicholas@2224 8061 // We can fire global events as of now if asked to
nicholas@2224 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nicholas@2224 8063 fireGlobals = jQuery.event && s.global;
nicholas@2224 8064
nicholas@2224 8065 // Watch for a new set of requests
nicholas@2224 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nicholas@2224 8067 jQuery.event.trigger("ajaxStart");
nicholas@2224 8068 }
nicholas@2224 8069
nicholas@2224 8070 // Uppercase the type
nicholas@2224 8071 s.type = s.type.toUpperCase();
nicholas@2224 8072
nicholas@2224 8073 // Determine if request has content
nicholas@2224 8074 s.hasContent = !rnoContent.test( s.type );
nicholas@2224 8075
nicholas@2224 8076 // Save the URL in case we're toying with the If-Modified-Since
nicholas@2224 8077 // and/or If-None-Match header later on
nicholas@2224 8078 cacheURL = s.url;
nicholas@2224 8079
nicholas@2224 8080 // More options handling for requests with no content
nicholas@2224 8081 if ( !s.hasContent ) {
nicholas@2224 8082
nicholas@2224 8083 // If data is available, append data to url
nicholas@2224 8084 if ( s.data ) {
nicholas@2224 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nicholas@2224 8086 // #9682: remove data so that it's not used in an eventual retry
nicholas@2224 8087 delete s.data;
nicholas@2224 8088 }
nicholas@2224 8089
nicholas@2224 8090 // Add anti-cache in url if needed
nicholas@2224 8091 if ( s.cache === false ) {
nicholas@2224 8092 s.url = rts.test( cacheURL ) ?
nicholas@2224 8093
nicholas@2224 8094 // If there is already a '_' parameter, set its value
nicholas@2224 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nicholas@2224 8096
nicholas@2224 8097 // Otherwise add one to the end
nicholas@2224 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nicholas@2224 8099 }
nicholas@2224 8100 }
nicholas@2224 8101
nicholas@2224 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nicholas@2224 8103 if ( s.ifModified ) {
nicholas@2224 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nicholas@2224 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nicholas@2224 8106 }
nicholas@2224 8107 if ( jQuery.etag[ cacheURL ] ) {
nicholas@2224 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nicholas@2224 8109 }
nicholas@2224 8110 }
nicholas@2224 8111
nicholas@2224 8112 // Set the correct header, if data is being sent
nicholas@2224 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nicholas@2224 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nicholas@2224 8115 }
nicholas@2224 8116
nicholas@2224 8117 // Set the Accepts header for the server, depending on the dataType
nicholas@2224 8118 jqXHR.setRequestHeader(
nicholas@2224 8119 "Accept",
nicholas@2224 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nicholas@2224 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nicholas@2224 8122 s.accepts[ "*" ]
nicholas@2224 8123 );
nicholas@2224 8124
nicholas@2224 8125 // Check for headers option
nicholas@2224 8126 for ( i in s.headers ) {
nicholas@2224 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nicholas@2224 8128 }
nicholas@2224 8129
nicholas@2224 8130 // Allow custom headers/mimetypes and early abort
nicholas@2224 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nicholas@2224 8132 // Abort if not done already and return
nicholas@2224 8133 return jqXHR.abort();
nicholas@2224 8134 }
nicholas@2224 8135
nicholas@2224 8136 // Aborting is no longer a cancellation
nicholas@2224 8137 strAbort = "abort";
nicholas@2224 8138
nicholas@2224 8139 // Install callbacks on deferreds
nicholas@2224 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nicholas@2224 8141 jqXHR[ i ]( s[ i ] );
nicholas@2224 8142 }
nicholas@2224 8143
nicholas@2224 8144 // Get transport
nicholas@2224 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nicholas@2224 8146
nicholas@2224 8147 // If no transport, we auto-abort
nicholas@2224 8148 if ( !transport ) {
nicholas@2224 8149 done( -1, "No Transport" );
nicholas@2224 8150 } else {
nicholas@2224 8151 jqXHR.readyState = 1;
nicholas@2224 8152
nicholas@2224 8153 // Send global event
nicholas@2224 8154 if ( fireGlobals ) {
nicholas@2224 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nicholas@2224 8156 }
nicholas@2224 8157 // Timeout
nicholas@2224 8158 if ( s.async && s.timeout > 0 ) {
nicholas@2224 8159 timeoutTimer = setTimeout(function() {
nicholas@2224 8160 jqXHR.abort("timeout");
nicholas@2224 8161 }, s.timeout );
nicholas@2224 8162 }
nicholas@2224 8163
nicholas@2224 8164 try {
nicholas@2224 8165 state = 1;
nicholas@2224 8166 transport.send( requestHeaders, done );
nicholas@2224 8167 } catch ( e ) {
nicholas@2224 8168 // Propagate exception as error if not done
nicholas@2224 8169 if ( state < 2 ) {
nicholas@2224 8170 done( -1, e );
nicholas@2224 8171 // Simply rethrow otherwise
nicholas@2224 8172 } else {
nicholas@2224 8173 throw e;
nicholas@2224 8174 }
nicholas@2224 8175 }
nicholas@2224 8176 }
nicholas@2224 8177
nicholas@2224 8178 // Callback for when everything is done
nicholas@2224 8179 function done( status, nativeStatusText, responses, headers ) {
nicholas@2224 8180 var isSuccess, success, error, response, modified,
nicholas@2224 8181 statusText = nativeStatusText;
nicholas@2224 8182
nicholas@2224 8183 // Called once
nicholas@2224 8184 if ( state === 2 ) {
nicholas@2224 8185 return;
nicholas@2224 8186 }
nicholas@2224 8187
nicholas@2224 8188 // State is "done" now
nicholas@2224 8189 state = 2;
nicholas@2224 8190
nicholas@2224 8191 // Clear timeout if it exists
nicholas@2224 8192 if ( timeoutTimer ) {
nicholas@2224 8193 clearTimeout( timeoutTimer );
nicholas@2224 8194 }
nicholas@2224 8195
nicholas@2224 8196 // Dereference transport for early garbage collection
nicholas@2224 8197 // (no matter how long the jqXHR object will be used)
nicholas@2224 8198 transport = undefined;
nicholas@2224 8199
nicholas@2224 8200 // Cache response headers
nicholas@2224 8201 responseHeadersString = headers || "";
nicholas@2224 8202
nicholas@2224 8203 // Set readyState
nicholas@2224 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nicholas@2224 8205
nicholas@2224 8206 // Determine if successful
nicholas@2224 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nicholas@2224 8208
nicholas@2224 8209 // Get response data
nicholas@2224 8210 if ( responses ) {
nicholas@2224 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nicholas@2224 8212 }
nicholas@2224 8213
nicholas@2224 8214 // Convert no matter what (that way responseXXX fields are always set)
nicholas@2224 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nicholas@2224 8216
nicholas@2224 8217 // If successful, handle type chaining
nicholas@2224 8218 if ( isSuccess ) {
nicholas@2224 8219
nicholas@2224 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nicholas@2224 8221 if ( s.ifModified ) {
nicholas@2224 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nicholas@2224 8223 if ( modified ) {
nicholas@2224 8224 jQuery.lastModified[ cacheURL ] = modified;
nicholas@2224 8225 }
nicholas@2224 8226 modified = jqXHR.getResponseHeader("etag");
nicholas@2224 8227 if ( modified ) {
nicholas@2224 8228 jQuery.etag[ cacheURL ] = modified;
nicholas@2224 8229 }
nicholas@2224 8230 }
nicholas@2224 8231
nicholas@2224 8232 // if no content
nicholas@2224 8233 if ( status === 204 || s.type === "HEAD" ) {
nicholas@2224 8234 statusText = "nocontent";
nicholas@2224 8235
nicholas@2224 8236 // if not modified
nicholas@2224 8237 } else if ( status === 304 ) {
nicholas@2224 8238 statusText = "notmodified";
nicholas@2224 8239
nicholas@2224 8240 // If we have data, let's convert it
nicholas@2224 8241 } else {
nicholas@2224 8242 statusText = response.state;
nicholas@2224 8243 success = response.data;
nicholas@2224 8244 error = response.error;
nicholas@2224 8245 isSuccess = !error;
nicholas@2224 8246 }
nicholas@2224 8247 } else {
nicholas@2224 8248 // Extract error from statusText and normalize for non-aborts
nicholas@2224 8249 error = statusText;
nicholas@2224 8250 if ( status || !statusText ) {
nicholas@2224 8251 statusText = "error";
nicholas@2224 8252 if ( status < 0 ) {
nicholas@2224 8253 status = 0;
nicholas@2224 8254 }
nicholas@2224 8255 }
nicholas@2224 8256 }
nicholas@2224 8257
nicholas@2224 8258 // Set data for the fake xhr object
nicholas@2224 8259 jqXHR.status = status;
nicholas@2224 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nicholas@2224 8261
nicholas@2224 8262 // Success/Error
nicholas@2224 8263 if ( isSuccess ) {
nicholas@2224 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nicholas@2224 8265 } else {
nicholas@2224 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nicholas@2224 8267 }
nicholas@2224 8268
nicholas@2224 8269 // Status-dependent callbacks
nicholas@2224 8270 jqXHR.statusCode( statusCode );
nicholas@2224 8271 statusCode = undefined;
nicholas@2224 8272
nicholas@2224 8273 if ( fireGlobals ) {
nicholas@2224 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nicholas@2224 8275 [ jqXHR, s, isSuccess ? success : error ] );
nicholas@2224 8276 }
nicholas@2224 8277
nicholas@2224 8278 // Complete
nicholas@2224 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nicholas@2224 8280
nicholas@2224 8281 if ( fireGlobals ) {
nicholas@2224 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nicholas@2224 8283 // Handle the global AJAX counter
nicholas@2224 8284 if ( !( --jQuery.active ) ) {
nicholas@2224 8285 jQuery.event.trigger("ajaxStop");
nicholas@2224 8286 }
nicholas@2224 8287 }
nicholas@2224 8288 }
nicholas@2224 8289
nicholas@2224 8290 return jqXHR;
nicholas@2224 8291 },
nicholas@2224 8292
nicholas@2224 8293 getJSON: function( url, data, callback ) {
nicholas@2224 8294 return jQuery.get( url, data, callback, "json" );
nicholas@2224 8295 },
nicholas@2224 8296
nicholas@2224 8297 getScript: function( url, callback ) {
nicholas@2224 8298 return jQuery.get( url, undefined, callback, "script" );
nicholas@2224 8299 }
nicholas@2224 8300 });
nicholas@2224 8301
nicholas@2224 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nicholas@2224 8303 jQuery[ method ] = function( url, data, callback, type ) {
nicholas@2224 8304 // Shift arguments if data argument was omitted
nicholas@2224 8305 if ( jQuery.isFunction( data ) ) {
nicholas@2224 8306 type = type || callback;
nicholas@2224 8307 callback = data;
nicholas@2224 8308 data = undefined;
nicholas@2224 8309 }
nicholas@2224 8310
nicholas@2224 8311 return jQuery.ajax({
nicholas@2224 8312 url: url,
nicholas@2224 8313 type: method,
nicholas@2224 8314 dataType: type,
nicholas@2224 8315 data: data,
nicholas@2224 8316 success: callback
nicholas@2224 8317 });
nicholas@2224 8318 };
nicholas@2224 8319 });
nicholas@2224 8320
nicholas@2224 8321
nicholas@2224 8322 jQuery._evalUrl = function( url ) {
nicholas@2224 8323 return jQuery.ajax({
nicholas@2224 8324 url: url,
nicholas@2224 8325 type: "GET",
nicholas@2224 8326 dataType: "script",
nicholas@2224 8327 async: false,
nicholas@2224 8328 global: false,
nicholas@2224 8329 "throws": true
nicholas@2224 8330 });
nicholas@2224 8331 };
nicholas@2224 8332
nicholas@2224 8333
nicholas@2224 8334 jQuery.fn.extend({
nicholas@2224 8335 wrapAll: function( html ) {
nicholas@2224 8336 var wrap;
nicholas@2224 8337
nicholas@2224 8338 if ( jQuery.isFunction( html ) ) {
nicholas@2224 8339 return this.each(function( i ) {
nicholas@2224 8340 jQuery( this ).wrapAll( html.call(this, i) );
nicholas@2224 8341 });
nicholas@2224 8342 }
nicholas@2224 8343
nicholas@2224 8344 if ( this[ 0 ] ) {
nicholas@2224 8345
nicholas@2224 8346 // The elements to wrap the target around
nicholas@2224 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nicholas@2224 8348
nicholas@2224 8349 if ( this[ 0 ].parentNode ) {
nicholas@2224 8350 wrap.insertBefore( this[ 0 ] );
nicholas@2224 8351 }
nicholas@2224 8352
nicholas@2224 8353 wrap.map(function() {
nicholas@2224 8354 var elem = this;
nicholas@2224 8355
nicholas@2224 8356 while ( elem.firstElementChild ) {
nicholas@2224 8357 elem = elem.firstElementChild;
nicholas@2224 8358 }
nicholas@2224 8359
nicholas@2224 8360 return elem;
nicholas@2224 8361 }).append( this );
nicholas@2224 8362 }
nicholas@2224 8363
nicholas@2224 8364 return this;
nicholas@2224 8365 },
nicholas@2224 8366
nicholas@2224 8367 wrapInner: function( html ) {
nicholas@2224 8368 if ( jQuery.isFunction( html ) ) {
nicholas@2224 8369 return this.each(function( i ) {
nicholas@2224 8370 jQuery( this ).wrapInner( html.call(this, i) );
nicholas@2224 8371 });
nicholas@2224 8372 }
nicholas@2224 8373
nicholas@2224 8374 return this.each(function() {
nicholas@2224 8375 var self = jQuery( this ),
nicholas@2224 8376 contents = self.contents();
nicholas@2224 8377
nicholas@2224 8378 if ( contents.length ) {
nicholas@2224 8379 contents.wrapAll( html );
nicholas@2224 8380
nicholas@2224 8381 } else {
nicholas@2224 8382 self.append( html );
nicholas@2224 8383 }
nicholas@2224 8384 });
nicholas@2224 8385 },
nicholas@2224 8386
nicholas@2224 8387 wrap: function( html ) {
nicholas@2224 8388 var isFunction = jQuery.isFunction( html );
nicholas@2224 8389
nicholas@2224 8390 return this.each(function( i ) {
nicholas@2224 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nicholas@2224 8392 });
nicholas@2224 8393 },
nicholas@2224 8394
nicholas@2224 8395 unwrap: function() {
nicholas@2224 8396 return this.parent().each(function() {
nicholas@2224 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nicholas@2224 8398 jQuery( this ).replaceWith( this.childNodes );
nicholas@2224 8399 }
nicholas@2224 8400 }).end();
nicholas@2224 8401 }
nicholas@2224 8402 });
nicholas@2224 8403
nicholas@2224 8404
nicholas@2224 8405 jQuery.expr.filters.hidden = function( elem ) {
nicholas@2224 8406 // Support: Opera <= 12.12
nicholas@2224 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nicholas@2224 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nicholas@2224 8409 };
nicholas@2224 8410 jQuery.expr.filters.visible = function( elem ) {
nicholas@2224 8411 return !jQuery.expr.filters.hidden( elem );
nicholas@2224 8412 };
nicholas@2224 8413
nicholas@2224 8414
nicholas@2224 8415
nicholas@2224 8416
nicholas@2224 8417 var r20 = /%20/g,
nicholas@2224 8418 rbracket = /\[\]$/,
nicholas@2224 8419 rCRLF = /\r?\n/g,
nicholas@2224 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nicholas@2224 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nicholas@2224 8422
nicholas@2224 8423 function buildParams( prefix, obj, traditional, add ) {
nicholas@2224 8424 var name;
nicholas@2224 8425
nicholas@2224 8426 if ( jQuery.isArray( obj ) ) {
nicholas@2224 8427 // Serialize array item.
nicholas@2224 8428 jQuery.each( obj, function( i, v ) {
nicholas@2224 8429 if ( traditional || rbracket.test( prefix ) ) {
nicholas@2224 8430 // Treat each array item as a scalar.
nicholas@2224 8431 add( prefix, v );
nicholas@2224 8432
nicholas@2224 8433 } else {
nicholas@2224 8434 // Item is non-scalar (array or object), encode its numeric index.
nicholas@2224 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nicholas@2224 8436 }
nicholas@2224 8437 });
nicholas@2224 8438
nicholas@2224 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nicholas@2224 8440 // Serialize object item.
nicholas@2224 8441 for ( name in obj ) {
nicholas@2224 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nicholas@2224 8443 }
nicholas@2224 8444
nicholas@2224 8445 } else {
nicholas@2224 8446 // Serialize scalar item.
nicholas@2224 8447 add( prefix, obj );
nicholas@2224 8448 }
nicholas@2224 8449 }
nicholas@2224 8450
nicholas@2224 8451 // Serialize an array of form elements or a set of
nicholas@2224 8452 // key/values into a query string
nicholas@2224 8453 jQuery.param = function( a, traditional ) {
nicholas@2224 8454 var prefix,
nicholas@2224 8455 s = [],
nicholas@2224 8456 add = function( key, value ) {
nicholas@2224 8457 // If value is a function, invoke it and return its value
nicholas@2224 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nicholas@2224 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nicholas@2224 8460 };
nicholas@2224 8461
nicholas@2224 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nicholas@2224 8463 if ( traditional === undefined ) {
nicholas@2224 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nicholas@2224 8465 }
nicholas@2224 8466
nicholas@2224 8467 // If an array was passed in, assume that it is an array of form elements.
nicholas@2224 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nicholas@2224 8469 // Serialize the form elements
nicholas@2224 8470 jQuery.each( a, function() {
nicholas@2224 8471 add( this.name, this.value );
nicholas@2224 8472 });
nicholas@2224 8473
nicholas@2224 8474 } else {
nicholas@2224 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nicholas@2224 8476 // did it), otherwise encode params recursively.
nicholas@2224 8477 for ( prefix in a ) {
nicholas@2224 8478 buildParams( prefix, a[ prefix ], traditional, add );
nicholas@2224 8479 }
nicholas@2224 8480 }
nicholas@2224 8481
nicholas@2224 8482 // Return the resulting serialization
nicholas@2224 8483 return s.join( "&" ).replace( r20, "+" );
nicholas@2224 8484 };
nicholas@2224 8485
nicholas@2224 8486 jQuery.fn.extend({
nicholas@2224 8487 serialize: function() {
nicholas@2224 8488 return jQuery.param( this.serializeArray() );
nicholas@2224 8489 },
nicholas@2224 8490 serializeArray: function() {
nicholas@2224 8491 return this.map(function() {
nicholas@2224 8492 // Can add propHook for "elements" to filter or add form elements
nicholas@2224 8493 var elements = jQuery.prop( this, "elements" );
nicholas@2224 8494 return elements ? jQuery.makeArray( elements ) : this;
nicholas@2224 8495 })
nicholas@2224 8496 .filter(function() {
nicholas@2224 8497 var type = this.type;
nicholas@2224 8498
nicholas@2224 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nicholas@2224 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nicholas@2224 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nicholas@2224 8502 ( this.checked || !rcheckableType.test( type ) );
nicholas@2224 8503 })
nicholas@2224 8504 .map(function( i, elem ) {
nicholas@2224 8505 var val = jQuery( this ).val();
nicholas@2224 8506
nicholas@2224 8507 return val == null ?
nicholas@2224 8508 null :
nicholas@2224 8509 jQuery.isArray( val ) ?
nicholas@2224 8510 jQuery.map( val, function( val ) {
nicholas@2224 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nicholas@2224 8512 }) :
nicholas@2224 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nicholas@2224 8514 }).get();
nicholas@2224 8515 }
nicholas@2224 8516 });
nicholas@2224 8517
nicholas@2224 8518
nicholas@2224 8519 jQuery.ajaxSettings.xhr = function() {
nicholas@2224 8520 try {
nicholas@2224 8521 return new XMLHttpRequest();
nicholas@2224 8522 } catch( e ) {}
nicholas@2224 8523 };
nicholas@2224 8524
nicholas@2224 8525 var xhrId = 0,
nicholas@2224 8526 xhrCallbacks = {},
nicholas@2224 8527 xhrSuccessStatus = {
nicholas@2224 8528 // file protocol always yields status code 0, assume 200
nicholas@2224 8529 0: 200,
nicholas@2224 8530 // Support: IE9
nicholas@2224 8531 // #1450: sometimes IE returns 1223 when it should be 204
nicholas@2224 8532 1223: 204
nicholas@2224 8533 },
nicholas@2224 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nicholas@2224 8535
nicholas@2224 8536 // Support: IE9
nicholas@2224 8537 // Open requests must be manually aborted on unload (#5280)
nicholas@2224 8538 // See https://support.microsoft.com/kb/2856746 for more info
nicholas@2224 8539 if ( window.attachEvent ) {
nicholas@2224 8540 window.attachEvent( "onunload", function() {
nicholas@2224 8541 for ( var key in xhrCallbacks ) {
nicholas@2224 8542 xhrCallbacks[ key ]();
nicholas@2224 8543 }
nicholas@2224 8544 });
nicholas@2224 8545 }
nicholas@2224 8546
nicholas@2224 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nicholas@2224 8548 support.ajax = xhrSupported = !!xhrSupported;
nicholas@2224 8549
nicholas@2224 8550 jQuery.ajaxTransport(function( options ) {
nicholas@2224 8551 var callback;
nicholas@2224 8552
nicholas@2224 8553 // Cross domain only allowed if supported through XMLHttpRequest
nicholas@2224 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nicholas@2224 8555 return {
nicholas@2224 8556 send: function( headers, complete ) {
nicholas@2224 8557 var i,
nicholas@2224 8558 xhr = options.xhr(),
nicholas@2224 8559 id = ++xhrId;
nicholas@2224 8560
nicholas@2224 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nicholas@2224 8562
nicholas@2224 8563 // Apply custom fields if provided
nicholas@2224 8564 if ( options.xhrFields ) {
nicholas@2224 8565 for ( i in options.xhrFields ) {
nicholas@2224 8566 xhr[ i ] = options.xhrFields[ i ];
nicholas@2224 8567 }
nicholas@2224 8568 }
nicholas@2224 8569
nicholas@2224 8570 // Override mime type if needed
nicholas@2224 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nicholas@2224 8572 xhr.overrideMimeType( options.mimeType );
nicholas@2224 8573 }
nicholas@2224 8574
nicholas@2224 8575 // X-Requested-With header
nicholas@2224 8576 // For cross-domain requests, seeing as conditions for a preflight are
nicholas@2224 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nicholas@2224 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nicholas@2224 8579 // For same-domain requests, won't change header if already provided.
nicholas@2224 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nicholas@2224 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nicholas@2224 8582 }
nicholas@2224 8583
nicholas@2224 8584 // Set headers
nicholas@2224 8585 for ( i in headers ) {
nicholas@2224 8586 xhr.setRequestHeader( i, headers[ i ] );
nicholas@2224 8587 }
nicholas@2224 8588
nicholas@2224 8589 // Callback
nicholas@2224 8590 callback = function( type ) {
nicholas@2224 8591 return function() {
nicholas@2224 8592 if ( callback ) {
nicholas@2224 8593 delete xhrCallbacks[ id ];
nicholas@2224 8594 callback = xhr.onload = xhr.onerror = null;
nicholas@2224 8595
nicholas@2224 8596 if ( type === "abort" ) {
nicholas@2224 8597 xhr.abort();
nicholas@2224 8598 } else if ( type === "error" ) {
nicholas@2224 8599 complete(
nicholas@2224 8600 // file: protocol always yields status 0; see #8605, #14207
nicholas@2224 8601 xhr.status,
nicholas@2224 8602 xhr.statusText
nicholas@2224 8603 );
nicholas@2224 8604 } else {
nicholas@2224 8605 complete(
nicholas@2224 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nicholas@2224 8607 xhr.statusText,
nicholas@2224 8608 // Support: IE9
nicholas@2224 8609 // Accessing binary-data responseText throws an exception
nicholas@2224 8610 // (#11426)
nicholas@2224 8611 typeof xhr.responseText === "string" ? {
nicholas@2224 8612 text: xhr.responseText
nicholas@2224 8613 } : undefined,
nicholas@2224 8614 xhr.getAllResponseHeaders()
nicholas@2224 8615 );
nicholas@2224 8616 }
nicholas@2224 8617 }
nicholas@2224 8618 };
nicholas@2224 8619 };
nicholas@2224 8620
nicholas@2224 8621 // Listen to events
nicholas@2224 8622 xhr.onload = callback();
nicholas@2224 8623 xhr.onerror = callback("error");
nicholas@2224 8624
nicholas@2224 8625 // Create the abort callback
nicholas@2224 8626 callback = xhrCallbacks[ id ] = callback("abort");
nicholas@2224 8627
nicholas@2224 8628 try {
nicholas@2224 8629 // Do send the request (this may raise an exception)
nicholas@2224 8630 xhr.send( options.hasContent && options.data || null );
nicholas@2224 8631 } catch ( e ) {
nicholas@2224 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nicholas@2224 8633 if ( callback ) {
nicholas@2224 8634 throw e;
nicholas@2224 8635 }
nicholas@2224 8636 }
nicholas@2224 8637 },
nicholas@2224 8638
nicholas@2224 8639 abort: function() {
nicholas@2224 8640 if ( callback ) {
nicholas@2224 8641 callback();
nicholas@2224 8642 }
nicholas@2224 8643 }
nicholas@2224 8644 };
nicholas@2224 8645 }
nicholas@2224 8646 });
nicholas@2224 8647
nicholas@2224 8648
nicholas@2224 8649
nicholas@2224 8650
nicholas@2224 8651 // Install script dataType
nicholas@2224 8652 jQuery.ajaxSetup({
nicholas@2224 8653 accepts: {
nicholas@2224 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nicholas@2224 8655 },
nicholas@2224 8656 contents: {
nicholas@2224 8657 script: /(?:java|ecma)script/
nicholas@2224 8658 },
nicholas@2224 8659 converters: {
nicholas@2224 8660 "text script": function( text ) {
nicholas@2224 8661 jQuery.globalEval( text );
nicholas@2224 8662 return text;
nicholas@2224 8663 }
nicholas@2224 8664 }
nicholas@2224 8665 });
nicholas@2224 8666
nicholas@2224 8667 // Handle cache's special case and crossDomain
nicholas@2224 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nicholas@2224 8669 if ( s.cache === undefined ) {
nicholas@2224 8670 s.cache = false;
nicholas@2224 8671 }
nicholas@2224 8672 if ( s.crossDomain ) {
nicholas@2224 8673 s.type = "GET";
nicholas@2224 8674 }
nicholas@2224 8675 });
nicholas@2224 8676
nicholas@2224 8677 // Bind script tag hack transport
nicholas@2224 8678 jQuery.ajaxTransport( "script", function( s ) {
nicholas@2224 8679 // This transport only deals with cross domain requests
nicholas@2224 8680 if ( s.crossDomain ) {
nicholas@2224 8681 var script, callback;
nicholas@2224 8682 return {
nicholas@2224 8683 send: function( _, complete ) {
nicholas@2224 8684 script = jQuery("<script>").prop({
nicholas@2224 8685 async: true,
nicholas@2224 8686 charset: s.scriptCharset,
nicholas@2224 8687 src: s.url
nicholas@2224 8688 }).on(
nicholas@2224 8689 "load error",
nicholas@2224 8690 callback = function( evt ) {
nicholas@2224 8691 script.remove();
nicholas@2224 8692 callback = null;
nicholas@2224 8693 if ( evt ) {
nicholas@2224 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nicholas@2224 8695 }
nicholas@2224 8696 }
nicholas@2224 8697 );
nicholas@2224 8698 document.head.appendChild( script[ 0 ] );
nicholas@2224 8699 },
nicholas@2224 8700 abort: function() {
nicholas@2224 8701 if ( callback ) {
nicholas@2224 8702 callback();
nicholas@2224 8703 }
nicholas@2224 8704 }
nicholas@2224 8705 };
nicholas@2224 8706 }
nicholas@2224 8707 });
nicholas@2224 8708
nicholas@2224 8709
nicholas@2224 8710
nicholas@2224 8711
nicholas@2224 8712 var oldCallbacks = [],
nicholas@2224 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nicholas@2224 8714
nicholas@2224 8715 // Default jsonp settings
nicholas@2224 8716 jQuery.ajaxSetup({
nicholas@2224 8717 jsonp: "callback",
nicholas@2224 8718 jsonpCallback: function() {
nicholas@2224 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nicholas@2224 8720 this[ callback ] = true;
nicholas@2224 8721 return callback;
nicholas@2224 8722 }
nicholas@2224 8723 });
nicholas@2224 8724
nicholas@2224 8725 // Detect, normalize options and install callbacks for jsonp requests
nicholas@2224 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nicholas@2224 8727
nicholas@2224 8728 var callbackName, overwritten, responseContainer,
nicholas@2224 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nicholas@2224 8730 "url" :
nicholas@2224 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nicholas@2224 8732 );
nicholas@2224 8733
nicholas@2224 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nicholas@2224 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nicholas@2224 8736
nicholas@2224 8737 // Get callback name, remembering preexisting value associated with it
nicholas@2224 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nicholas@2224 8739 s.jsonpCallback() :
nicholas@2224 8740 s.jsonpCallback;
nicholas@2224 8741
nicholas@2224 8742 // Insert callback into url or form data
nicholas@2224 8743 if ( jsonProp ) {
nicholas@2224 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nicholas@2224 8745 } else if ( s.jsonp !== false ) {
nicholas@2224 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nicholas@2224 8747 }
nicholas@2224 8748
nicholas@2224 8749 // Use data converter to retrieve json after script execution
nicholas@2224 8750 s.converters["script json"] = function() {
nicholas@2224 8751 if ( !responseContainer ) {
nicholas@2224 8752 jQuery.error( callbackName + " was not called" );
nicholas@2224 8753 }
nicholas@2224 8754 return responseContainer[ 0 ];
nicholas@2224 8755 };
nicholas@2224 8756
nicholas@2224 8757 // force json dataType
nicholas@2224 8758 s.dataTypes[ 0 ] = "json";
nicholas@2224 8759
nicholas@2224 8760 // Install callback
nicholas@2224 8761 overwritten = window[ callbackName ];
nicholas@2224 8762 window[ callbackName ] = function() {
nicholas@2224 8763 responseContainer = arguments;
nicholas@2224 8764 };
nicholas@2224 8765
nicholas@2224 8766 // Clean-up function (fires after converters)
nicholas@2224 8767 jqXHR.always(function() {
nicholas@2224 8768 // Restore preexisting value
nicholas@2224 8769 window[ callbackName ] = overwritten;
nicholas@2224 8770
nicholas@2224 8771 // Save back as free
nicholas@2224 8772 if ( s[ callbackName ] ) {
nicholas@2224 8773 // make sure that re-using the options doesn't screw things around
nicholas@2224 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nicholas@2224 8775
nicholas@2224 8776 // save the callback name for future use
nicholas@2224 8777 oldCallbacks.push( callbackName );
nicholas@2224 8778 }
nicholas@2224 8779
nicholas@2224 8780 // Call if it was a function and we have a response
nicholas@2224 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nicholas@2224 8782 overwritten( responseContainer[ 0 ] );
nicholas@2224 8783 }
nicholas@2224 8784
nicholas@2224 8785 responseContainer = overwritten = undefined;
nicholas@2224 8786 });
nicholas@2224 8787
nicholas@2224 8788 // Delegate to script
nicholas@2224 8789 return "script";
nicholas@2224 8790 }
nicholas@2224 8791 });
nicholas@2224 8792
nicholas@2224 8793
nicholas@2224 8794
nicholas@2224 8795
nicholas@2224 8796 // data: string of html
nicholas@2224 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nicholas@2224 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nicholas@2224 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nicholas@2224 8800 if ( !data || typeof data !== "string" ) {
nicholas@2224 8801 return null;
nicholas@2224 8802 }
nicholas@2224 8803 if ( typeof context === "boolean" ) {
nicholas@2224 8804 keepScripts = context;
nicholas@2224 8805 context = false;
nicholas@2224 8806 }
nicholas@2224 8807 context = context || document;
nicholas@2224 8808
nicholas@2224 8809 var parsed = rsingleTag.exec( data ),
nicholas@2224 8810 scripts = !keepScripts && [];
nicholas@2224 8811
nicholas@2224 8812 // Single tag
nicholas@2224 8813 if ( parsed ) {
nicholas@2224 8814 return [ context.createElement( parsed[1] ) ];
nicholas@2224 8815 }
nicholas@2224 8816
nicholas@2224 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nicholas@2224 8818
nicholas@2224 8819 if ( scripts && scripts.length ) {
nicholas@2224 8820 jQuery( scripts ).remove();
nicholas@2224 8821 }
nicholas@2224 8822
nicholas@2224 8823 return jQuery.merge( [], parsed.childNodes );
nicholas@2224 8824 };
nicholas@2224 8825
nicholas@2224 8826
nicholas@2224 8827 // Keep a copy of the old load method
nicholas@2224 8828 var _load = jQuery.fn.load;
nicholas@2224 8829
nicholas@2224 8830 /**
nicholas@2224 8831 * Load a url into a page
nicholas@2224 8832 */
nicholas@2224 8833 jQuery.fn.load = function( url, params, callback ) {
nicholas@2224 8834 if ( typeof url !== "string" && _load ) {
nicholas@2224 8835 return _load.apply( this, arguments );
nicholas@2224 8836 }
nicholas@2224 8837
nicholas@2224 8838 var selector, type, response,
nicholas@2224 8839 self = this,
nicholas@2224 8840 off = url.indexOf(" ");
nicholas@2224 8841
nicholas@2224 8842 if ( off >= 0 ) {
nicholas@2224 8843 selector = jQuery.trim( url.slice( off ) );
nicholas@2224 8844 url = url.slice( 0, off );
nicholas@2224 8845 }
nicholas@2224 8846
nicholas@2224 8847 // If it's a function
nicholas@2224 8848 if ( jQuery.isFunction( params ) ) {
nicholas@2224 8849
nicholas@2224 8850 // We assume that it's the callback
nicholas@2224 8851 callback = params;
nicholas@2224 8852 params = undefined;
nicholas@2224 8853
nicholas@2224 8854 // Otherwise, build a param string
nicholas@2224 8855 } else if ( params && typeof params === "object" ) {
nicholas@2224 8856 type = "POST";
nicholas@2224 8857 }
nicholas@2224 8858
nicholas@2224 8859 // If we have elements to modify, make the request
nicholas@2224 8860 if ( self.length > 0 ) {
nicholas@2224 8861 jQuery.ajax({
nicholas@2224 8862 url: url,
nicholas@2224 8863
nicholas@2224 8864 // if "type" variable is undefined, then "GET" method will be used
nicholas@2224 8865 type: type,
nicholas@2224 8866 dataType: "html",
nicholas@2224 8867 data: params
nicholas@2224 8868 }).done(function( responseText ) {
nicholas@2224 8869
nicholas@2224 8870 // Save response for use in complete callback
nicholas@2224 8871 response = arguments;
nicholas@2224 8872
nicholas@2224 8873 self.html( selector ?
nicholas@2224 8874
nicholas@2224 8875 // If a selector was specified, locate the right elements in a dummy div
nicholas@2224 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nicholas@2224 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nicholas@2224 8878
nicholas@2224 8879 // Otherwise use the full result
nicholas@2224 8880 responseText );
nicholas@2224 8881
nicholas@2224 8882 }).complete( callback && function( jqXHR, status ) {
nicholas@2224 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nicholas@2224 8884 });
nicholas@2224 8885 }
nicholas@2224 8886
nicholas@2224 8887 return this;
nicholas@2224 8888 };
nicholas@2224 8889
nicholas@2224 8890
nicholas@2224 8891
nicholas@2224 8892
nicholas@2224 8893 // Attach a bunch of functions for handling common AJAX events
nicholas@2224 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nicholas@2224 8895 jQuery.fn[ type ] = function( fn ) {
nicholas@2224 8896 return this.on( type, fn );
nicholas@2224 8897 };
nicholas@2224 8898 });
nicholas@2224 8899
nicholas@2224 8900
nicholas@2224 8901
nicholas@2224 8902
nicholas@2224 8903 jQuery.expr.filters.animated = function( elem ) {
nicholas@2224 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nicholas@2224 8905 return elem === fn.elem;
nicholas@2224 8906 }).length;
nicholas@2224 8907 };
nicholas@2224 8908
nicholas@2224 8909
nicholas@2224 8910
nicholas@2224 8911
nicholas@2224 8912 var docElem = window.document.documentElement;
nicholas@2224 8913
nicholas@2224 8914 /**
nicholas@2224 8915 * Gets a window from an element
nicholas@2224 8916 */
nicholas@2224 8917 function getWindow( elem ) {
nicholas@2224 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nicholas@2224 8919 }
nicholas@2224 8920
nicholas@2224 8921 jQuery.offset = {
nicholas@2224 8922 setOffset: function( elem, options, i ) {
nicholas@2224 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nicholas@2224 8924 position = jQuery.css( elem, "position" ),
nicholas@2224 8925 curElem = jQuery( elem ),
nicholas@2224 8926 props = {};
nicholas@2224 8927
nicholas@2224 8928 // Set position first, in-case top/left are set even on static elem
nicholas@2224 8929 if ( position === "static" ) {
nicholas@2224 8930 elem.style.position = "relative";
nicholas@2224 8931 }
nicholas@2224 8932
nicholas@2224 8933 curOffset = curElem.offset();
nicholas@2224 8934 curCSSTop = jQuery.css( elem, "top" );
nicholas@2224 8935 curCSSLeft = jQuery.css( elem, "left" );
nicholas@2224 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nicholas@2224 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nicholas@2224 8938
nicholas@2224 8939 // Need to be able to calculate position if either
nicholas@2224 8940 // top or left is auto and position is either absolute or fixed
nicholas@2224 8941 if ( calculatePosition ) {
nicholas@2224 8942 curPosition = curElem.position();
nicholas@2224 8943 curTop = curPosition.top;
nicholas@2224 8944 curLeft = curPosition.left;
nicholas@2224 8945
nicholas@2224 8946 } else {
nicholas@2224 8947 curTop = parseFloat( curCSSTop ) || 0;
nicholas@2224 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nicholas@2224 8949 }
nicholas@2224 8950
nicholas@2224 8951 if ( jQuery.isFunction( options ) ) {
nicholas@2224 8952 options = options.call( elem, i, curOffset );
nicholas@2224 8953 }
nicholas@2224 8954
nicholas@2224 8955 if ( options.top != null ) {
nicholas@2224 8956 props.top = ( options.top - curOffset.top ) + curTop;
nicholas@2224 8957 }
nicholas@2224 8958 if ( options.left != null ) {
nicholas@2224 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nicholas@2224 8960 }
nicholas@2224 8961
nicholas@2224 8962 if ( "using" in options ) {
nicholas@2224 8963 options.using.call( elem, props );
nicholas@2224 8964
nicholas@2224 8965 } else {
nicholas@2224 8966 curElem.css( props );
nicholas@2224 8967 }
nicholas@2224 8968 }
nicholas@2224 8969 };
nicholas@2224 8970
nicholas@2224 8971 jQuery.fn.extend({
nicholas@2224 8972 offset: function( options ) {
nicholas@2224 8973 if ( arguments.length ) {
nicholas@2224 8974 return options === undefined ?
nicholas@2224 8975 this :
nicholas@2224 8976 this.each(function( i ) {
nicholas@2224 8977 jQuery.offset.setOffset( this, options, i );
nicholas@2224 8978 });
nicholas@2224 8979 }
nicholas@2224 8980
nicholas@2224 8981 var docElem, win,
nicholas@2224 8982 elem = this[ 0 ],
nicholas@2224 8983 box = { top: 0, left: 0 },
nicholas@2224 8984 doc = elem && elem.ownerDocument;
nicholas@2224 8985
nicholas@2224 8986 if ( !doc ) {
nicholas@2224 8987 return;
nicholas@2224 8988 }
nicholas@2224 8989
nicholas@2224 8990 docElem = doc.documentElement;
nicholas@2224 8991
nicholas@2224 8992 // Make sure it's not a disconnected DOM node
nicholas@2224 8993 if ( !jQuery.contains( docElem, elem ) ) {
nicholas@2224 8994 return box;
nicholas@2224 8995 }
nicholas@2224 8996
nicholas@2224 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nicholas@2224 8998 // If we don't have gBCR, just use 0,0 rather than error
nicholas@2224 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nicholas@2224 9000 box = elem.getBoundingClientRect();
nicholas@2224 9001 }
nicholas@2224 9002 win = getWindow( doc );
nicholas@2224 9003 return {
nicholas@2224 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nicholas@2224 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nicholas@2224 9006 };
nicholas@2224 9007 },
nicholas@2224 9008
nicholas@2224 9009 position: function() {
nicholas@2224 9010 if ( !this[ 0 ] ) {
nicholas@2224 9011 return;
nicholas@2224 9012 }
nicholas@2224 9013
nicholas@2224 9014 var offsetParent, offset,
nicholas@2224 9015 elem = this[ 0 ],
nicholas@2224 9016 parentOffset = { top: 0, left: 0 };
nicholas@2224 9017
nicholas@2224 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nicholas@2224 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nicholas@2224 9020 // Assume getBoundingClientRect is there when computed position is fixed
nicholas@2224 9021 offset = elem.getBoundingClientRect();
nicholas@2224 9022
nicholas@2224 9023 } else {
nicholas@2224 9024 // Get *real* offsetParent
nicholas@2224 9025 offsetParent = this.offsetParent();
nicholas@2224 9026
nicholas@2224 9027 // Get correct offsets
nicholas@2224 9028 offset = this.offset();
nicholas@2224 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nicholas@2224 9030 parentOffset = offsetParent.offset();
nicholas@2224 9031 }
nicholas@2224 9032
nicholas@2224 9033 // Add offsetParent borders
nicholas@2224 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nicholas@2224 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nicholas@2224 9036 }
nicholas@2224 9037
nicholas@2224 9038 // Subtract parent offsets and element margins
nicholas@2224 9039 return {
nicholas@2224 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nicholas@2224 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nicholas@2224 9042 };
nicholas@2224 9043 },
nicholas@2224 9044
nicholas@2224 9045 offsetParent: function() {
nicholas@2224 9046 return this.map(function() {
nicholas@2224 9047 var offsetParent = this.offsetParent || docElem;
nicholas@2224 9048
nicholas@2224 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nicholas@2224 9050 offsetParent = offsetParent.offsetParent;
nicholas@2224 9051 }
nicholas@2224 9052
nicholas@2224 9053 return offsetParent || docElem;
nicholas@2224 9054 });
nicholas@2224 9055 }
nicholas@2224 9056 });
nicholas@2224 9057
nicholas@2224 9058 // Create scrollLeft and scrollTop methods
nicholas@2224 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nicholas@2224 9060 var top = "pageYOffset" === prop;
nicholas@2224 9061
nicholas@2224 9062 jQuery.fn[ method ] = function( val ) {
nicholas@2224 9063 return access( this, function( elem, method, val ) {
nicholas@2224 9064 var win = getWindow( elem );
nicholas@2224 9065
nicholas@2224 9066 if ( val === undefined ) {
nicholas@2224 9067 return win ? win[ prop ] : elem[ method ];
nicholas@2224 9068 }
nicholas@2224 9069
nicholas@2224 9070 if ( win ) {
nicholas@2224 9071 win.scrollTo(
nicholas@2224 9072 !top ? val : window.pageXOffset,
nicholas@2224 9073 top ? val : window.pageYOffset
nicholas@2224 9074 );
nicholas@2224 9075
nicholas@2224 9076 } else {
nicholas@2224 9077 elem[ method ] = val;
nicholas@2224 9078 }
nicholas@2224 9079 }, method, val, arguments.length, null );
nicholas@2224 9080 };
nicholas@2224 9081 });
nicholas@2224 9082
nicholas@2224 9083 // Support: Safari<7+, Chrome<37+
nicholas@2224 9084 // Add the top/left cssHooks using jQuery.fn.position
nicholas@2224 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nicholas@2224 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nicholas@2224 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nicholas@2224 9088 // rather than make the css module depend on the offset module, just check for it here
nicholas@2224 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nicholas@2224 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nicholas@2224 9091 function( elem, computed ) {
nicholas@2224 9092 if ( computed ) {
nicholas@2224 9093 computed = curCSS( elem, prop );
nicholas@2224 9094 // If curCSS returns percentage, fallback to offset
nicholas@2224 9095 return rnumnonpx.test( computed ) ?
nicholas@2224 9096 jQuery( elem ).position()[ prop ] + "px" :
nicholas@2224 9097 computed;
nicholas@2224 9098 }
nicholas@2224 9099 }
nicholas@2224 9100 );
nicholas@2224 9101 });
nicholas@2224 9102
nicholas@2224 9103
nicholas@2224 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nicholas@2224 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nicholas@2224 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nicholas@2224 9107 // Margin is only for outerHeight, outerWidth
nicholas@2224 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nicholas@2224 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nicholas@2224 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nicholas@2224 9111
nicholas@2224 9112 return access( this, function( elem, type, value ) {
nicholas@2224 9113 var doc;
nicholas@2224 9114
nicholas@2224 9115 if ( jQuery.isWindow( elem ) ) {
nicholas@2224 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nicholas@2224 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nicholas@2224 9118 // https://github.com/jquery/jquery/pull/764
nicholas@2224 9119 return elem.document.documentElement[ "client" + name ];
nicholas@2224 9120 }
nicholas@2224 9121
nicholas@2224 9122 // Get document width or height
nicholas@2224 9123 if ( elem.nodeType === 9 ) {
nicholas@2224 9124 doc = elem.documentElement;
nicholas@2224 9125
nicholas@2224 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nicholas@2224 9127 // whichever is greatest
nicholas@2224 9128 return Math.max(
nicholas@2224 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nicholas@2224 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nicholas@2224 9131 doc[ "client" + name ]
nicholas@2224 9132 );
nicholas@2224 9133 }
nicholas@2224 9134
nicholas@2224 9135 return value === undefined ?
nicholas@2224 9136 // Get width or height on the element, requesting but not forcing parseFloat
nicholas@2224 9137 jQuery.css( elem, type, extra ) :
nicholas@2224 9138
nicholas@2224 9139 // Set width or height on the element
nicholas@2224 9140 jQuery.style( elem, type, value, extra );
nicholas@2224 9141 }, type, chainable ? margin : undefined, chainable, null );
nicholas@2224 9142 };
nicholas@2224 9143 });
nicholas@2224 9144 });
nicholas@2224 9145
nicholas@2224 9146
nicholas@2224 9147 // The number of elements contained in the matched element set
nicholas@2224 9148 jQuery.fn.size = function() {
nicholas@2224 9149 return this.length;
nicholas@2224 9150 };
nicholas@2224 9151
nicholas@2224 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nicholas@2224 9153
nicholas@2224 9154
nicholas@2224 9155
nicholas@2224 9156
nicholas@2224 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nicholas@2224 9158 // files that may use define, but not via a proper concatenation script that
nicholas@2224 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nicholas@2224 9160 // way to register. Lowercase jquery is used because AMD module names are
nicholas@2224 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nicholas@2224 9162 // file name. Do this after creating the global so that if an AMD module wants
nicholas@2224 9163 // to call noConflict to hide this version of jQuery, it will work.
nicholas@2224 9164
nicholas@2224 9165 // Note that for maximum portability, libraries that are not jQuery should
nicholas@2224 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nicholas@2224 9167 // AMD loader is present. jQuery is a special case. For more information, see
nicholas@2224 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nicholas@2224 9169
nicholas@2224 9170 if ( typeof define === "function" && define.amd ) {
nicholas@2224 9171 define( "jquery", [], function() {
nicholas@2224 9172 return jQuery;
nicholas@2224 9173 });
nicholas@2224 9174 }
nicholas@2224 9175
nicholas@2224 9176
nicholas@2224 9177
nicholas@2224 9178
nicholas@2224 9179 var
nicholas@2224 9180 // Map over jQuery in case of overwrite
nicholas@2224 9181 _jQuery = window.jQuery,
nicholas@2224 9182
nicholas@2224 9183 // Map over the $ in case of overwrite
nicholas@2224 9184 _$ = window.$;
nicholas@2224 9185
nicholas@2224 9186 jQuery.noConflict = function( deep ) {
nicholas@2224 9187 if ( window.$ === jQuery ) {
nicholas@2224 9188 window.$ = _$;
nicholas@2224 9189 }
nicholas@2224 9190
nicholas@2224 9191 if ( deep && window.jQuery === jQuery ) {
nicholas@2224 9192 window.jQuery = _jQuery;
nicholas@2224 9193 }
nicholas@2224 9194
nicholas@2224 9195 return jQuery;
nicholas@2224 9196 };
nicholas@2224 9197
nicholas@2224 9198 // Expose jQuery and $ identifiers, even in AMD
nicholas@2224 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nicholas@2224 9200 // and CommonJS for browser emulators (#13566)
nicholas@2224 9201 if ( typeof noGlobal === strundefined ) {
nicholas@2224 9202 window.jQuery = window.$ = jQuery;
nicholas@2224 9203 }
nicholas@2224 9204
nicholas@2224 9205
nicholas@2224 9206
nicholas@2224 9207
nicholas@2224 9208 return jQuery;
nicholas@2224 9209
nicholas@2224 9210 }));