annotate jquery-2.1.4.js @ 718:0b095f66de65

Update to WAC paper references
author Dave <djmoffat@users.noreply.github.com>
date Thu, 24 Sep 2015 09:49:01 +0100
parents
children
rev   line source
djmoffat@718 1 /*!
djmoffat@718 2 * jQuery JavaScript Library v2.1.4
djmoffat@718 3 * http://jquery.com/
djmoffat@718 4 *
djmoffat@718 5 * Includes Sizzle.js
djmoffat@718 6 * http://sizzlejs.com/
djmoffat@718 7 *
djmoffat@718 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
djmoffat@718 9 * Released under the MIT license
djmoffat@718 10 * http://jquery.org/license
djmoffat@718 11 *
djmoffat@718 12 * Date: 2015-04-28T16:01Z
djmoffat@718 13 */
djmoffat@718 14
djmoffat@718 15 (function( global, factory ) {
djmoffat@718 16
djmoffat@718 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
djmoffat@718 18 // For CommonJS and CommonJS-like environments where a proper `window`
djmoffat@718 19 // is present, execute the factory and get jQuery.
djmoffat@718 20 // For environments that do not have a `window` with a `document`
djmoffat@718 21 // (such as Node.js), expose a factory as module.exports.
djmoffat@718 22 // This accentuates the need for the creation of a real `window`.
djmoffat@718 23 // e.g. var jQuery = require("jquery")(window);
djmoffat@718 24 // See ticket #14549 for more info.
djmoffat@718 25 module.exports = global.document ?
djmoffat@718 26 factory( global, true ) :
djmoffat@718 27 function( w ) {
djmoffat@718 28 if ( !w.document ) {
djmoffat@718 29 throw new Error( "jQuery requires a window with a document" );
djmoffat@718 30 }
djmoffat@718 31 return factory( w );
djmoffat@718 32 };
djmoffat@718 33 } else {
djmoffat@718 34 factory( global );
djmoffat@718 35 }
djmoffat@718 36
djmoffat@718 37 // Pass this if window is not defined yet
djmoffat@718 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
djmoffat@718 39
djmoffat@718 40 // Support: Firefox 18+
djmoffat@718 41 // Can't be in strict mode, several libs including ASP.NET trace
djmoffat@718 42 // the stack via arguments.caller.callee and Firefox dies if
djmoffat@718 43 // you try to trace through "use strict" call chains. (#13335)
djmoffat@718 44 //
djmoffat@718 45
djmoffat@718 46 var arr = [];
djmoffat@718 47
djmoffat@718 48 var slice = arr.slice;
djmoffat@718 49
djmoffat@718 50 var concat = arr.concat;
djmoffat@718 51
djmoffat@718 52 var push = arr.push;
djmoffat@718 53
djmoffat@718 54 var indexOf = arr.indexOf;
djmoffat@718 55
djmoffat@718 56 var class2type = {};
djmoffat@718 57
djmoffat@718 58 var toString = class2type.toString;
djmoffat@718 59
djmoffat@718 60 var hasOwn = class2type.hasOwnProperty;
djmoffat@718 61
djmoffat@718 62 var support = {};
djmoffat@718 63
djmoffat@718 64
djmoffat@718 65
djmoffat@718 66 var
djmoffat@718 67 // Use the correct document accordingly with window argument (sandbox)
djmoffat@718 68 document = window.document,
djmoffat@718 69
djmoffat@718 70 version = "2.1.4",
djmoffat@718 71
djmoffat@718 72 // Define a local copy of jQuery
djmoffat@718 73 jQuery = function( selector, context ) {
djmoffat@718 74 // The jQuery object is actually just the init constructor 'enhanced'
djmoffat@718 75 // Need init if jQuery is called (just allow error to be thrown if not included)
djmoffat@718 76 return new jQuery.fn.init( selector, context );
djmoffat@718 77 },
djmoffat@718 78
djmoffat@718 79 // Support: Android<4.1
djmoffat@718 80 // Make sure we trim BOM and NBSP
djmoffat@718 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
djmoffat@718 82
djmoffat@718 83 // Matches dashed string for camelizing
djmoffat@718 84 rmsPrefix = /^-ms-/,
djmoffat@718 85 rdashAlpha = /-([\da-z])/gi,
djmoffat@718 86
djmoffat@718 87 // Used by jQuery.camelCase as callback to replace()
djmoffat@718 88 fcamelCase = function( all, letter ) {
djmoffat@718 89 return letter.toUpperCase();
djmoffat@718 90 };
djmoffat@718 91
djmoffat@718 92 jQuery.fn = jQuery.prototype = {
djmoffat@718 93 // The current version of jQuery being used
djmoffat@718 94 jquery: version,
djmoffat@718 95
djmoffat@718 96 constructor: jQuery,
djmoffat@718 97
djmoffat@718 98 // Start with an empty selector
djmoffat@718 99 selector: "",
djmoffat@718 100
djmoffat@718 101 // The default length of a jQuery object is 0
djmoffat@718 102 length: 0,
djmoffat@718 103
djmoffat@718 104 toArray: function() {
djmoffat@718 105 return slice.call( this );
djmoffat@718 106 },
djmoffat@718 107
djmoffat@718 108 // Get the Nth element in the matched element set OR
djmoffat@718 109 // Get the whole matched element set as a clean array
djmoffat@718 110 get: function( num ) {
djmoffat@718 111 return num != null ?
djmoffat@718 112
djmoffat@718 113 // Return just the one element from the set
djmoffat@718 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
djmoffat@718 115
djmoffat@718 116 // Return all the elements in a clean array
djmoffat@718 117 slice.call( this );
djmoffat@718 118 },
djmoffat@718 119
djmoffat@718 120 // Take an array of elements and push it onto the stack
djmoffat@718 121 // (returning the new matched element set)
djmoffat@718 122 pushStack: function( elems ) {
djmoffat@718 123
djmoffat@718 124 // Build a new jQuery matched element set
djmoffat@718 125 var ret = jQuery.merge( this.constructor(), elems );
djmoffat@718 126
djmoffat@718 127 // Add the old object onto the stack (as a reference)
djmoffat@718 128 ret.prevObject = this;
djmoffat@718 129 ret.context = this.context;
djmoffat@718 130
djmoffat@718 131 // Return the newly-formed element set
djmoffat@718 132 return ret;
djmoffat@718 133 },
djmoffat@718 134
djmoffat@718 135 // Execute a callback for every element in the matched set.
djmoffat@718 136 // (You can seed the arguments with an array of args, but this is
djmoffat@718 137 // only used internally.)
djmoffat@718 138 each: function( callback, args ) {
djmoffat@718 139 return jQuery.each( this, callback, args );
djmoffat@718 140 },
djmoffat@718 141
djmoffat@718 142 map: function( callback ) {
djmoffat@718 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
djmoffat@718 144 return callback.call( elem, i, elem );
djmoffat@718 145 }));
djmoffat@718 146 },
djmoffat@718 147
djmoffat@718 148 slice: function() {
djmoffat@718 149 return this.pushStack( slice.apply( this, arguments ) );
djmoffat@718 150 },
djmoffat@718 151
djmoffat@718 152 first: function() {
djmoffat@718 153 return this.eq( 0 );
djmoffat@718 154 },
djmoffat@718 155
djmoffat@718 156 last: function() {
djmoffat@718 157 return this.eq( -1 );
djmoffat@718 158 },
djmoffat@718 159
djmoffat@718 160 eq: function( i ) {
djmoffat@718 161 var len = this.length,
djmoffat@718 162 j = +i + ( i < 0 ? len : 0 );
djmoffat@718 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
djmoffat@718 164 },
djmoffat@718 165
djmoffat@718 166 end: function() {
djmoffat@718 167 return this.prevObject || this.constructor(null);
djmoffat@718 168 },
djmoffat@718 169
djmoffat@718 170 // For internal use only.
djmoffat@718 171 // Behaves like an Array's method, not like a jQuery method.
djmoffat@718 172 push: push,
djmoffat@718 173 sort: arr.sort,
djmoffat@718 174 splice: arr.splice
djmoffat@718 175 };
djmoffat@718 176
djmoffat@718 177 jQuery.extend = jQuery.fn.extend = function() {
djmoffat@718 178 var options, name, src, copy, copyIsArray, clone,
djmoffat@718 179 target = arguments[0] || {},
djmoffat@718 180 i = 1,
djmoffat@718 181 length = arguments.length,
djmoffat@718 182 deep = false;
djmoffat@718 183
djmoffat@718 184 // Handle a deep copy situation
djmoffat@718 185 if ( typeof target === "boolean" ) {
djmoffat@718 186 deep = target;
djmoffat@718 187
djmoffat@718 188 // Skip the boolean and the target
djmoffat@718 189 target = arguments[ i ] || {};
djmoffat@718 190 i++;
djmoffat@718 191 }
djmoffat@718 192
djmoffat@718 193 // Handle case when target is a string or something (possible in deep copy)
djmoffat@718 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
djmoffat@718 195 target = {};
djmoffat@718 196 }
djmoffat@718 197
djmoffat@718 198 // Extend jQuery itself if only one argument is passed
djmoffat@718 199 if ( i === length ) {
djmoffat@718 200 target = this;
djmoffat@718 201 i--;
djmoffat@718 202 }
djmoffat@718 203
djmoffat@718 204 for ( ; i < length; i++ ) {
djmoffat@718 205 // Only deal with non-null/undefined values
djmoffat@718 206 if ( (options = arguments[ i ]) != null ) {
djmoffat@718 207 // Extend the base object
djmoffat@718 208 for ( name in options ) {
djmoffat@718 209 src = target[ name ];
djmoffat@718 210 copy = options[ name ];
djmoffat@718 211
djmoffat@718 212 // Prevent never-ending loop
djmoffat@718 213 if ( target === copy ) {
djmoffat@718 214 continue;
djmoffat@718 215 }
djmoffat@718 216
djmoffat@718 217 // Recurse if we're merging plain objects or arrays
djmoffat@718 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
djmoffat@718 219 if ( copyIsArray ) {
djmoffat@718 220 copyIsArray = false;
djmoffat@718 221 clone = src && jQuery.isArray(src) ? src : [];
djmoffat@718 222
djmoffat@718 223 } else {
djmoffat@718 224 clone = src && jQuery.isPlainObject(src) ? src : {};
djmoffat@718 225 }
djmoffat@718 226
djmoffat@718 227 // Never move original objects, clone them
djmoffat@718 228 target[ name ] = jQuery.extend( deep, clone, copy );
djmoffat@718 229
djmoffat@718 230 // Don't bring in undefined values
djmoffat@718 231 } else if ( copy !== undefined ) {
djmoffat@718 232 target[ name ] = copy;
djmoffat@718 233 }
djmoffat@718 234 }
djmoffat@718 235 }
djmoffat@718 236 }
djmoffat@718 237
djmoffat@718 238 // Return the modified object
djmoffat@718 239 return target;
djmoffat@718 240 };
djmoffat@718 241
djmoffat@718 242 jQuery.extend({
djmoffat@718 243 // Unique for each copy of jQuery on the page
djmoffat@718 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
djmoffat@718 245
djmoffat@718 246 // Assume jQuery is ready without the ready module
djmoffat@718 247 isReady: true,
djmoffat@718 248
djmoffat@718 249 error: function( msg ) {
djmoffat@718 250 throw new Error( msg );
djmoffat@718 251 },
djmoffat@718 252
djmoffat@718 253 noop: function() {},
djmoffat@718 254
djmoffat@718 255 isFunction: function( obj ) {
djmoffat@718 256 return jQuery.type(obj) === "function";
djmoffat@718 257 },
djmoffat@718 258
djmoffat@718 259 isArray: Array.isArray,
djmoffat@718 260
djmoffat@718 261 isWindow: function( obj ) {
djmoffat@718 262 return obj != null && obj === obj.window;
djmoffat@718 263 },
djmoffat@718 264
djmoffat@718 265 isNumeric: function( obj ) {
djmoffat@718 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
djmoffat@718 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
djmoffat@718 268 // subtraction forces infinities to NaN
djmoffat@718 269 // adding 1 corrects loss of precision from parseFloat (#15100)
djmoffat@718 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
djmoffat@718 271 },
djmoffat@718 272
djmoffat@718 273 isPlainObject: function( obj ) {
djmoffat@718 274 // Not plain objects:
djmoffat@718 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
djmoffat@718 276 // - DOM nodes
djmoffat@718 277 // - window
djmoffat@718 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
djmoffat@718 279 return false;
djmoffat@718 280 }
djmoffat@718 281
djmoffat@718 282 if ( obj.constructor &&
djmoffat@718 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
djmoffat@718 284 return false;
djmoffat@718 285 }
djmoffat@718 286
djmoffat@718 287 // If the function hasn't returned already, we're confident that
djmoffat@718 288 // |obj| is a plain object, created by {} or constructed with new Object
djmoffat@718 289 return true;
djmoffat@718 290 },
djmoffat@718 291
djmoffat@718 292 isEmptyObject: function( obj ) {
djmoffat@718 293 var name;
djmoffat@718 294 for ( name in obj ) {
djmoffat@718 295 return false;
djmoffat@718 296 }
djmoffat@718 297 return true;
djmoffat@718 298 },
djmoffat@718 299
djmoffat@718 300 type: function( obj ) {
djmoffat@718 301 if ( obj == null ) {
djmoffat@718 302 return obj + "";
djmoffat@718 303 }
djmoffat@718 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
djmoffat@718 305 return typeof obj === "object" || typeof obj === "function" ?
djmoffat@718 306 class2type[ toString.call(obj) ] || "object" :
djmoffat@718 307 typeof obj;
djmoffat@718 308 },
djmoffat@718 309
djmoffat@718 310 // Evaluates a script in a global context
djmoffat@718 311 globalEval: function( code ) {
djmoffat@718 312 var script,
djmoffat@718 313 indirect = eval;
djmoffat@718 314
djmoffat@718 315 code = jQuery.trim( code );
djmoffat@718 316
djmoffat@718 317 if ( code ) {
djmoffat@718 318 // If the code includes a valid, prologue position
djmoffat@718 319 // strict mode pragma, execute code by injecting a
djmoffat@718 320 // script tag into the document.
djmoffat@718 321 if ( code.indexOf("use strict") === 1 ) {
djmoffat@718 322 script = document.createElement("script");
djmoffat@718 323 script.text = code;
djmoffat@718 324 document.head.appendChild( script ).parentNode.removeChild( script );
djmoffat@718 325 } else {
djmoffat@718 326 // Otherwise, avoid the DOM node creation, insertion
djmoffat@718 327 // and removal by using an indirect global eval
djmoffat@718 328 indirect( code );
djmoffat@718 329 }
djmoffat@718 330 }
djmoffat@718 331 },
djmoffat@718 332
djmoffat@718 333 // Convert dashed to camelCase; used by the css and data modules
djmoffat@718 334 // Support: IE9-11+
djmoffat@718 335 // Microsoft forgot to hump their vendor prefix (#9572)
djmoffat@718 336 camelCase: function( string ) {
djmoffat@718 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
djmoffat@718 338 },
djmoffat@718 339
djmoffat@718 340 nodeName: function( elem, name ) {
djmoffat@718 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
djmoffat@718 342 },
djmoffat@718 343
djmoffat@718 344 // args is for internal usage only
djmoffat@718 345 each: function( obj, callback, args ) {
djmoffat@718 346 var value,
djmoffat@718 347 i = 0,
djmoffat@718 348 length = obj.length,
djmoffat@718 349 isArray = isArraylike( obj );
djmoffat@718 350
djmoffat@718 351 if ( args ) {
djmoffat@718 352 if ( isArray ) {
djmoffat@718 353 for ( ; i < length; i++ ) {
djmoffat@718 354 value = callback.apply( obj[ i ], args );
djmoffat@718 355
djmoffat@718 356 if ( value === false ) {
djmoffat@718 357 break;
djmoffat@718 358 }
djmoffat@718 359 }
djmoffat@718 360 } else {
djmoffat@718 361 for ( i in obj ) {
djmoffat@718 362 value = callback.apply( obj[ i ], args );
djmoffat@718 363
djmoffat@718 364 if ( value === false ) {
djmoffat@718 365 break;
djmoffat@718 366 }
djmoffat@718 367 }
djmoffat@718 368 }
djmoffat@718 369
djmoffat@718 370 // A special, fast, case for the most common use of each
djmoffat@718 371 } else {
djmoffat@718 372 if ( isArray ) {
djmoffat@718 373 for ( ; i < length; i++ ) {
djmoffat@718 374 value = callback.call( obj[ i ], i, obj[ i ] );
djmoffat@718 375
djmoffat@718 376 if ( value === false ) {
djmoffat@718 377 break;
djmoffat@718 378 }
djmoffat@718 379 }
djmoffat@718 380 } else {
djmoffat@718 381 for ( i in obj ) {
djmoffat@718 382 value = callback.call( obj[ i ], i, obj[ i ] );
djmoffat@718 383
djmoffat@718 384 if ( value === false ) {
djmoffat@718 385 break;
djmoffat@718 386 }
djmoffat@718 387 }
djmoffat@718 388 }
djmoffat@718 389 }
djmoffat@718 390
djmoffat@718 391 return obj;
djmoffat@718 392 },
djmoffat@718 393
djmoffat@718 394 // Support: Android<4.1
djmoffat@718 395 trim: function( text ) {
djmoffat@718 396 return text == null ?
djmoffat@718 397 "" :
djmoffat@718 398 ( text + "" ).replace( rtrim, "" );
djmoffat@718 399 },
djmoffat@718 400
djmoffat@718 401 // results is for internal usage only
djmoffat@718 402 makeArray: function( arr, results ) {
djmoffat@718 403 var ret = results || [];
djmoffat@718 404
djmoffat@718 405 if ( arr != null ) {
djmoffat@718 406 if ( isArraylike( Object(arr) ) ) {
djmoffat@718 407 jQuery.merge( ret,
djmoffat@718 408 typeof arr === "string" ?
djmoffat@718 409 [ arr ] : arr
djmoffat@718 410 );
djmoffat@718 411 } else {
djmoffat@718 412 push.call( ret, arr );
djmoffat@718 413 }
djmoffat@718 414 }
djmoffat@718 415
djmoffat@718 416 return ret;
djmoffat@718 417 },
djmoffat@718 418
djmoffat@718 419 inArray: function( elem, arr, i ) {
djmoffat@718 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
djmoffat@718 421 },
djmoffat@718 422
djmoffat@718 423 merge: function( first, second ) {
djmoffat@718 424 var len = +second.length,
djmoffat@718 425 j = 0,
djmoffat@718 426 i = first.length;
djmoffat@718 427
djmoffat@718 428 for ( ; j < len; j++ ) {
djmoffat@718 429 first[ i++ ] = second[ j ];
djmoffat@718 430 }
djmoffat@718 431
djmoffat@718 432 first.length = i;
djmoffat@718 433
djmoffat@718 434 return first;
djmoffat@718 435 },
djmoffat@718 436
djmoffat@718 437 grep: function( elems, callback, invert ) {
djmoffat@718 438 var callbackInverse,
djmoffat@718 439 matches = [],
djmoffat@718 440 i = 0,
djmoffat@718 441 length = elems.length,
djmoffat@718 442 callbackExpect = !invert;
djmoffat@718 443
djmoffat@718 444 // Go through the array, only saving the items
djmoffat@718 445 // that pass the validator function
djmoffat@718 446 for ( ; i < length; i++ ) {
djmoffat@718 447 callbackInverse = !callback( elems[ i ], i );
djmoffat@718 448 if ( callbackInverse !== callbackExpect ) {
djmoffat@718 449 matches.push( elems[ i ] );
djmoffat@718 450 }
djmoffat@718 451 }
djmoffat@718 452
djmoffat@718 453 return matches;
djmoffat@718 454 },
djmoffat@718 455
djmoffat@718 456 // arg is for internal usage only
djmoffat@718 457 map: function( elems, callback, arg ) {
djmoffat@718 458 var value,
djmoffat@718 459 i = 0,
djmoffat@718 460 length = elems.length,
djmoffat@718 461 isArray = isArraylike( elems ),
djmoffat@718 462 ret = [];
djmoffat@718 463
djmoffat@718 464 // Go through the array, translating each of the items to their new values
djmoffat@718 465 if ( isArray ) {
djmoffat@718 466 for ( ; i < length; i++ ) {
djmoffat@718 467 value = callback( elems[ i ], i, arg );
djmoffat@718 468
djmoffat@718 469 if ( value != null ) {
djmoffat@718 470 ret.push( value );
djmoffat@718 471 }
djmoffat@718 472 }
djmoffat@718 473
djmoffat@718 474 // Go through every key on the object,
djmoffat@718 475 } else {
djmoffat@718 476 for ( i in elems ) {
djmoffat@718 477 value = callback( elems[ i ], i, arg );
djmoffat@718 478
djmoffat@718 479 if ( value != null ) {
djmoffat@718 480 ret.push( value );
djmoffat@718 481 }
djmoffat@718 482 }
djmoffat@718 483 }
djmoffat@718 484
djmoffat@718 485 // Flatten any nested arrays
djmoffat@718 486 return concat.apply( [], ret );
djmoffat@718 487 },
djmoffat@718 488
djmoffat@718 489 // A global GUID counter for objects
djmoffat@718 490 guid: 1,
djmoffat@718 491
djmoffat@718 492 // Bind a function to a context, optionally partially applying any
djmoffat@718 493 // arguments.
djmoffat@718 494 proxy: function( fn, context ) {
djmoffat@718 495 var tmp, args, proxy;
djmoffat@718 496
djmoffat@718 497 if ( typeof context === "string" ) {
djmoffat@718 498 tmp = fn[ context ];
djmoffat@718 499 context = fn;
djmoffat@718 500 fn = tmp;
djmoffat@718 501 }
djmoffat@718 502
djmoffat@718 503 // Quick check to determine if target is callable, in the spec
djmoffat@718 504 // this throws a TypeError, but we will just return undefined.
djmoffat@718 505 if ( !jQuery.isFunction( fn ) ) {
djmoffat@718 506 return undefined;
djmoffat@718 507 }
djmoffat@718 508
djmoffat@718 509 // Simulated bind
djmoffat@718 510 args = slice.call( arguments, 2 );
djmoffat@718 511 proxy = function() {
djmoffat@718 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
djmoffat@718 513 };
djmoffat@718 514
djmoffat@718 515 // Set the guid of unique handler to the same of original handler, so it can be removed
djmoffat@718 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
djmoffat@718 517
djmoffat@718 518 return proxy;
djmoffat@718 519 },
djmoffat@718 520
djmoffat@718 521 now: Date.now,
djmoffat@718 522
djmoffat@718 523 // jQuery.support is not used in Core but other projects attach their
djmoffat@718 524 // properties to it so it needs to exist.
djmoffat@718 525 support: support
djmoffat@718 526 });
djmoffat@718 527
djmoffat@718 528 // Populate the class2type map
djmoffat@718 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
djmoffat@718 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
djmoffat@718 531 });
djmoffat@718 532
djmoffat@718 533 function isArraylike( obj ) {
djmoffat@718 534
djmoffat@718 535 // Support: iOS 8.2 (not reproducible in simulator)
djmoffat@718 536 // `in` check used to prevent JIT error (gh-2145)
djmoffat@718 537 // hasOwn isn't used here due to false negatives
djmoffat@718 538 // regarding Nodelist length in IE
djmoffat@718 539 var length = "length" in obj && obj.length,
djmoffat@718 540 type = jQuery.type( obj );
djmoffat@718 541
djmoffat@718 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
djmoffat@718 543 return false;
djmoffat@718 544 }
djmoffat@718 545
djmoffat@718 546 if ( obj.nodeType === 1 && length ) {
djmoffat@718 547 return true;
djmoffat@718 548 }
djmoffat@718 549
djmoffat@718 550 return type === "array" || length === 0 ||
djmoffat@718 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
djmoffat@718 552 }
djmoffat@718 553 var Sizzle =
djmoffat@718 554 /*!
djmoffat@718 555 * Sizzle CSS Selector Engine v2.2.0-pre
djmoffat@718 556 * http://sizzlejs.com/
djmoffat@718 557 *
djmoffat@718 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
djmoffat@718 559 * Released under the MIT license
djmoffat@718 560 * http://jquery.org/license
djmoffat@718 561 *
djmoffat@718 562 * Date: 2014-12-16
djmoffat@718 563 */
djmoffat@718 564 (function( window ) {
djmoffat@718 565
djmoffat@718 566 var i,
djmoffat@718 567 support,
djmoffat@718 568 Expr,
djmoffat@718 569 getText,
djmoffat@718 570 isXML,
djmoffat@718 571 tokenize,
djmoffat@718 572 compile,
djmoffat@718 573 select,
djmoffat@718 574 outermostContext,
djmoffat@718 575 sortInput,
djmoffat@718 576 hasDuplicate,
djmoffat@718 577
djmoffat@718 578 // Local document vars
djmoffat@718 579 setDocument,
djmoffat@718 580 document,
djmoffat@718 581 docElem,
djmoffat@718 582 documentIsHTML,
djmoffat@718 583 rbuggyQSA,
djmoffat@718 584 rbuggyMatches,
djmoffat@718 585 matches,
djmoffat@718 586 contains,
djmoffat@718 587
djmoffat@718 588 // Instance-specific data
djmoffat@718 589 expando = "sizzle" + 1 * new Date(),
djmoffat@718 590 preferredDoc = window.document,
djmoffat@718 591 dirruns = 0,
djmoffat@718 592 done = 0,
djmoffat@718 593 classCache = createCache(),
djmoffat@718 594 tokenCache = createCache(),
djmoffat@718 595 compilerCache = createCache(),
djmoffat@718 596 sortOrder = function( a, b ) {
djmoffat@718 597 if ( a === b ) {
djmoffat@718 598 hasDuplicate = true;
djmoffat@718 599 }
djmoffat@718 600 return 0;
djmoffat@718 601 },
djmoffat@718 602
djmoffat@718 603 // General-purpose constants
djmoffat@718 604 MAX_NEGATIVE = 1 << 31,
djmoffat@718 605
djmoffat@718 606 // Instance methods
djmoffat@718 607 hasOwn = ({}).hasOwnProperty,
djmoffat@718 608 arr = [],
djmoffat@718 609 pop = arr.pop,
djmoffat@718 610 push_native = arr.push,
djmoffat@718 611 push = arr.push,
djmoffat@718 612 slice = arr.slice,
djmoffat@718 613 // Use a stripped-down indexOf as it's faster than native
djmoffat@718 614 // http://jsperf.com/thor-indexof-vs-for/5
djmoffat@718 615 indexOf = function( list, elem ) {
djmoffat@718 616 var i = 0,
djmoffat@718 617 len = list.length;
djmoffat@718 618 for ( ; i < len; i++ ) {
djmoffat@718 619 if ( list[i] === elem ) {
djmoffat@718 620 return i;
djmoffat@718 621 }
djmoffat@718 622 }
djmoffat@718 623 return -1;
djmoffat@718 624 },
djmoffat@718 625
djmoffat@718 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
djmoffat@718 627
djmoffat@718 628 // Regular expressions
djmoffat@718 629
djmoffat@718 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
djmoffat@718 631 whitespace = "[\\x20\\t\\r\\n\\f]",
djmoffat@718 632 // http://www.w3.org/TR/css3-syntax/#characters
djmoffat@718 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
djmoffat@718 634
djmoffat@718 635 // Loosely modeled on CSS identifier characters
djmoffat@718 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
djmoffat@718 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
djmoffat@718 638 identifier = characterEncoding.replace( "w", "w#" ),
djmoffat@718 639
djmoffat@718 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
djmoffat@718 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
djmoffat@718 642 // Operator (capture 2)
djmoffat@718 643 "*([*^$|!~]?=)" + whitespace +
djmoffat@718 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
djmoffat@718 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
djmoffat@718 646 "*\\]",
djmoffat@718 647
djmoffat@718 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
djmoffat@718 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
djmoffat@718 650 // 1. quoted (capture 3; capture 4 or capture 5)
djmoffat@718 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
djmoffat@718 652 // 2. simple (capture 6)
djmoffat@718 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
djmoffat@718 654 // 3. anything else (capture 2)
djmoffat@718 655 ".*" +
djmoffat@718 656 ")\\)|)",
djmoffat@718 657
djmoffat@718 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
djmoffat@718 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
djmoffat@718 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
djmoffat@718 661
djmoffat@718 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
djmoffat@718 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
djmoffat@718 664
djmoffat@718 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
djmoffat@718 666
djmoffat@718 667 rpseudo = new RegExp( pseudos ),
djmoffat@718 668 ridentifier = new RegExp( "^" + identifier + "$" ),
djmoffat@718 669
djmoffat@718 670 matchExpr = {
djmoffat@718 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
djmoffat@718 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
djmoffat@718 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
djmoffat@718 674 "ATTR": new RegExp( "^" + attributes ),
djmoffat@718 675 "PSEUDO": new RegExp( "^" + pseudos ),
djmoffat@718 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
djmoffat@718 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
djmoffat@718 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
djmoffat@718 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
djmoffat@718 680 // For use in libraries implementing .is()
djmoffat@718 681 // We use this for POS matching in `select`
djmoffat@718 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
djmoffat@718 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
djmoffat@718 684 },
djmoffat@718 685
djmoffat@718 686 rinputs = /^(?:input|select|textarea|button)$/i,
djmoffat@718 687 rheader = /^h\d$/i,
djmoffat@718 688
djmoffat@718 689 rnative = /^[^{]+\{\s*\[native \w/,
djmoffat@718 690
djmoffat@718 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
djmoffat@718 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
djmoffat@718 693
djmoffat@718 694 rsibling = /[+~]/,
djmoffat@718 695 rescape = /'|\\/g,
djmoffat@718 696
djmoffat@718 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
djmoffat@718 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
djmoffat@718 699 funescape = function( _, escaped, escapedWhitespace ) {
djmoffat@718 700 var high = "0x" + escaped - 0x10000;
djmoffat@718 701 // NaN means non-codepoint
djmoffat@718 702 // Support: Firefox<24
djmoffat@718 703 // Workaround erroneous numeric interpretation of +"0x"
djmoffat@718 704 return high !== high || escapedWhitespace ?
djmoffat@718 705 escaped :
djmoffat@718 706 high < 0 ?
djmoffat@718 707 // BMP codepoint
djmoffat@718 708 String.fromCharCode( high + 0x10000 ) :
djmoffat@718 709 // Supplemental Plane codepoint (surrogate pair)
djmoffat@718 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
djmoffat@718 711 },
djmoffat@718 712
djmoffat@718 713 // Used for iframes
djmoffat@718 714 // See setDocument()
djmoffat@718 715 // Removing the function wrapper causes a "Permission Denied"
djmoffat@718 716 // error in IE
djmoffat@718 717 unloadHandler = function() {
djmoffat@718 718 setDocument();
djmoffat@718 719 };
djmoffat@718 720
djmoffat@718 721 // Optimize for push.apply( _, NodeList )
djmoffat@718 722 try {
djmoffat@718 723 push.apply(
djmoffat@718 724 (arr = slice.call( preferredDoc.childNodes )),
djmoffat@718 725 preferredDoc.childNodes
djmoffat@718 726 );
djmoffat@718 727 // Support: Android<4.0
djmoffat@718 728 // Detect silently failing push.apply
djmoffat@718 729 arr[ preferredDoc.childNodes.length ].nodeType;
djmoffat@718 730 } catch ( e ) {
djmoffat@718 731 push = { apply: arr.length ?
djmoffat@718 732
djmoffat@718 733 // Leverage slice if possible
djmoffat@718 734 function( target, els ) {
djmoffat@718 735 push_native.apply( target, slice.call(els) );
djmoffat@718 736 } :
djmoffat@718 737
djmoffat@718 738 // Support: IE<9
djmoffat@718 739 // Otherwise append directly
djmoffat@718 740 function( target, els ) {
djmoffat@718 741 var j = target.length,
djmoffat@718 742 i = 0;
djmoffat@718 743 // Can't trust NodeList.length
djmoffat@718 744 while ( (target[j++] = els[i++]) ) {}
djmoffat@718 745 target.length = j - 1;
djmoffat@718 746 }
djmoffat@718 747 };
djmoffat@718 748 }
djmoffat@718 749
djmoffat@718 750 function Sizzle( selector, context, results, seed ) {
djmoffat@718 751 var match, elem, m, nodeType,
djmoffat@718 752 // QSA vars
djmoffat@718 753 i, groups, old, nid, newContext, newSelector;
djmoffat@718 754
djmoffat@718 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
djmoffat@718 756 setDocument( context );
djmoffat@718 757 }
djmoffat@718 758
djmoffat@718 759 context = context || document;
djmoffat@718 760 results = results || [];
djmoffat@718 761 nodeType = context.nodeType;
djmoffat@718 762
djmoffat@718 763 if ( typeof selector !== "string" || !selector ||
djmoffat@718 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
djmoffat@718 765
djmoffat@718 766 return results;
djmoffat@718 767 }
djmoffat@718 768
djmoffat@718 769 if ( !seed && documentIsHTML ) {
djmoffat@718 770
djmoffat@718 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
djmoffat@718 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
djmoffat@718 773 // Speed-up: Sizzle("#ID")
djmoffat@718 774 if ( (m = match[1]) ) {
djmoffat@718 775 if ( nodeType === 9 ) {
djmoffat@718 776 elem = context.getElementById( m );
djmoffat@718 777 // Check parentNode to catch when Blackberry 4.6 returns
djmoffat@718 778 // nodes that are no longer in the document (jQuery #6963)
djmoffat@718 779 if ( elem && elem.parentNode ) {
djmoffat@718 780 // Handle the case where IE, Opera, and Webkit return items
djmoffat@718 781 // by name instead of ID
djmoffat@718 782 if ( elem.id === m ) {
djmoffat@718 783 results.push( elem );
djmoffat@718 784 return results;
djmoffat@718 785 }
djmoffat@718 786 } else {
djmoffat@718 787 return results;
djmoffat@718 788 }
djmoffat@718 789 } else {
djmoffat@718 790 // Context is not a document
djmoffat@718 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
djmoffat@718 792 contains( context, elem ) && elem.id === m ) {
djmoffat@718 793 results.push( elem );
djmoffat@718 794 return results;
djmoffat@718 795 }
djmoffat@718 796 }
djmoffat@718 797
djmoffat@718 798 // Speed-up: Sizzle("TAG")
djmoffat@718 799 } else if ( match[2] ) {
djmoffat@718 800 push.apply( results, context.getElementsByTagName( selector ) );
djmoffat@718 801 return results;
djmoffat@718 802
djmoffat@718 803 // Speed-up: Sizzle(".CLASS")
djmoffat@718 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
djmoffat@718 805 push.apply( results, context.getElementsByClassName( m ) );
djmoffat@718 806 return results;
djmoffat@718 807 }
djmoffat@718 808 }
djmoffat@718 809
djmoffat@718 810 // QSA path
djmoffat@718 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
djmoffat@718 812 nid = old = expando;
djmoffat@718 813 newContext = context;
djmoffat@718 814 newSelector = nodeType !== 1 && selector;
djmoffat@718 815
djmoffat@718 816 // qSA works strangely on Element-rooted queries
djmoffat@718 817 // We can work around this by specifying an extra ID on the root
djmoffat@718 818 // and working up from there (Thanks to Andrew Dupont for the technique)
djmoffat@718 819 // IE 8 doesn't work on object elements
djmoffat@718 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
djmoffat@718 821 groups = tokenize( selector );
djmoffat@718 822
djmoffat@718 823 if ( (old = context.getAttribute("id")) ) {
djmoffat@718 824 nid = old.replace( rescape, "\\$&" );
djmoffat@718 825 } else {
djmoffat@718 826 context.setAttribute( "id", nid );
djmoffat@718 827 }
djmoffat@718 828 nid = "[id='" + nid + "'] ";
djmoffat@718 829
djmoffat@718 830 i = groups.length;
djmoffat@718 831 while ( i-- ) {
djmoffat@718 832 groups[i] = nid + toSelector( groups[i] );
djmoffat@718 833 }
djmoffat@718 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
djmoffat@718 835 newSelector = groups.join(",");
djmoffat@718 836 }
djmoffat@718 837
djmoffat@718 838 if ( newSelector ) {
djmoffat@718 839 try {
djmoffat@718 840 push.apply( results,
djmoffat@718 841 newContext.querySelectorAll( newSelector )
djmoffat@718 842 );
djmoffat@718 843 return results;
djmoffat@718 844 } catch(qsaError) {
djmoffat@718 845 } finally {
djmoffat@718 846 if ( !old ) {
djmoffat@718 847 context.removeAttribute("id");
djmoffat@718 848 }
djmoffat@718 849 }
djmoffat@718 850 }
djmoffat@718 851 }
djmoffat@718 852 }
djmoffat@718 853
djmoffat@718 854 // All others
djmoffat@718 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
djmoffat@718 856 }
djmoffat@718 857
djmoffat@718 858 /**
djmoffat@718 859 * Create key-value caches of limited size
djmoffat@718 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
djmoffat@718 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
djmoffat@718 862 * deleting the oldest entry
djmoffat@718 863 */
djmoffat@718 864 function createCache() {
djmoffat@718 865 var keys = [];
djmoffat@718 866
djmoffat@718 867 function cache( key, value ) {
djmoffat@718 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
djmoffat@718 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
djmoffat@718 870 // Only keep the most recent entries
djmoffat@718 871 delete cache[ keys.shift() ];
djmoffat@718 872 }
djmoffat@718 873 return (cache[ key + " " ] = value);
djmoffat@718 874 }
djmoffat@718 875 return cache;
djmoffat@718 876 }
djmoffat@718 877
djmoffat@718 878 /**
djmoffat@718 879 * Mark a function for special use by Sizzle
djmoffat@718 880 * @param {Function} fn The function to mark
djmoffat@718 881 */
djmoffat@718 882 function markFunction( fn ) {
djmoffat@718 883 fn[ expando ] = true;
djmoffat@718 884 return fn;
djmoffat@718 885 }
djmoffat@718 886
djmoffat@718 887 /**
djmoffat@718 888 * Support testing using an element
djmoffat@718 889 * @param {Function} fn Passed the created div and expects a boolean result
djmoffat@718 890 */
djmoffat@718 891 function assert( fn ) {
djmoffat@718 892 var div = document.createElement("div");
djmoffat@718 893
djmoffat@718 894 try {
djmoffat@718 895 return !!fn( div );
djmoffat@718 896 } catch (e) {
djmoffat@718 897 return false;
djmoffat@718 898 } finally {
djmoffat@718 899 // Remove from its parent by default
djmoffat@718 900 if ( div.parentNode ) {
djmoffat@718 901 div.parentNode.removeChild( div );
djmoffat@718 902 }
djmoffat@718 903 // release memory in IE
djmoffat@718 904 div = null;
djmoffat@718 905 }
djmoffat@718 906 }
djmoffat@718 907
djmoffat@718 908 /**
djmoffat@718 909 * Adds the same handler for all of the specified attrs
djmoffat@718 910 * @param {String} attrs Pipe-separated list of attributes
djmoffat@718 911 * @param {Function} handler The method that will be applied
djmoffat@718 912 */
djmoffat@718 913 function addHandle( attrs, handler ) {
djmoffat@718 914 var arr = attrs.split("|"),
djmoffat@718 915 i = attrs.length;
djmoffat@718 916
djmoffat@718 917 while ( i-- ) {
djmoffat@718 918 Expr.attrHandle[ arr[i] ] = handler;
djmoffat@718 919 }
djmoffat@718 920 }
djmoffat@718 921
djmoffat@718 922 /**
djmoffat@718 923 * Checks document order of two siblings
djmoffat@718 924 * @param {Element} a
djmoffat@718 925 * @param {Element} b
djmoffat@718 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
djmoffat@718 927 */
djmoffat@718 928 function siblingCheck( a, b ) {
djmoffat@718 929 var cur = b && a,
djmoffat@718 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
djmoffat@718 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
djmoffat@718 932 ( ~a.sourceIndex || MAX_NEGATIVE );
djmoffat@718 933
djmoffat@718 934 // Use IE sourceIndex if available on both nodes
djmoffat@718 935 if ( diff ) {
djmoffat@718 936 return diff;
djmoffat@718 937 }
djmoffat@718 938
djmoffat@718 939 // Check if b follows a
djmoffat@718 940 if ( cur ) {
djmoffat@718 941 while ( (cur = cur.nextSibling) ) {
djmoffat@718 942 if ( cur === b ) {
djmoffat@718 943 return -1;
djmoffat@718 944 }
djmoffat@718 945 }
djmoffat@718 946 }
djmoffat@718 947
djmoffat@718 948 return a ? 1 : -1;
djmoffat@718 949 }
djmoffat@718 950
djmoffat@718 951 /**
djmoffat@718 952 * Returns a function to use in pseudos for input types
djmoffat@718 953 * @param {String} type
djmoffat@718 954 */
djmoffat@718 955 function createInputPseudo( type ) {
djmoffat@718 956 return function( elem ) {
djmoffat@718 957 var name = elem.nodeName.toLowerCase();
djmoffat@718 958 return name === "input" && elem.type === type;
djmoffat@718 959 };
djmoffat@718 960 }
djmoffat@718 961
djmoffat@718 962 /**
djmoffat@718 963 * Returns a function to use in pseudos for buttons
djmoffat@718 964 * @param {String} type
djmoffat@718 965 */
djmoffat@718 966 function createButtonPseudo( type ) {
djmoffat@718 967 return function( elem ) {
djmoffat@718 968 var name = elem.nodeName.toLowerCase();
djmoffat@718 969 return (name === "input" || name === "button") && elem.type === type;
djmoffat@718 970 };
djmoffat@718 971 }
djmoffat@718 972
djmoffat@718 973 /**
djmoffat@718 974 * Returns a function to use in pseudos for positionals
djmoffat@718 975 * @param {Function} fn
djmoffat@718 976 */
djmoffat@718 977 function createPositionalPseudo( fn ) {
djmoffat@718 978 return markFunction(function( argument ) {
djmoffat@718 979 argument = +argument;
djmoffat@718 980 return markFunction(function( seed, matches ) {
djmoffat@718 981 var j,
djmoffat@718 982 matchIndexes = fn( [], seed.length, argument ),
djmoffat@718 983 i = matchIndexes.length;
djmoffat@718 984
djmoffat@718 985 // Match elements found at the specified indexes
djmoffat@718 986 while ( i-- ) {
djmoffat@718 987 if ( seed[ (j = matchIndexes[i]) ] ) {
djmoffat@718 988 seed[j] = !(matches[j] = seed[j]);
djmoffat@718 989 }
djmoffat@718 990 }
djmoffat@718 991 });
djmoffat@718 992 });
djmoffat@718 993 }
djmoffat@718 994
djmoffat@718 995 /**
djmoffat@718 996 * Checks a node for validity as a Sizzle context
djmoffat@718 997 * @param {Element|Object=} context
djmoffat@718 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
djmoffat@718 999 */
djmoffat@718 1000 function testContext( context ) {
djmoffat@718 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
djmoffat@718 1002 }
djmoffat@718 1003
djmoffat@718 1004 // Expose support vars for convenience
djmoffat@718 1005 support = Sizzle.support = {};
djmoffat@718 1006
djmoffat@718 1007 /**
djmoffat@718 1008 * Detects XML nodes
djmoffat@718 1009 * @param {Element|Object} elem An element or a document
djmoffat@718 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
djmoffat@718 1011 */
djmoffat@718 1012 isXML = Sizzle.isXML = function( elem ) {
djmoffat@718 1013 // documentElement is verified for cases where it doesn't yet exist
djmoffat@718 1014 // (such as loading iframes in IE - #4833)
djmoffat@718 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
djmoffat@718 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
djmoffat@718 1017 };
djmoffat@718 1018
djmoffat@718 1019 /**
djmoffat@718 1020 * Sets document-related variables once based on the current document
djmoffat@718 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
djmoffat@718 1022 * @returns {Object} Returns the current document
djmoffat@718 1023 */
djmoffat@718 1024 setDocument = Sizzle.setDocument = function( node ) {
djmoffat@718 1025 var hasCompare, parent,
djmoffat@718 1026 doc = node ? node.ownerDocument || node : preferredDoc;
djmoffat@718 1027
djmoffat@718 1028 // If no document and documentElement is available, return
djmoffat@718 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
djmoffat@718 1030 return document;
djmoffat@718 1031 }
djmoffat@718 1032
djmoffat@718 1033 // Set our document
djmoffat@718 1034 document = doc;
djmoffat@718 1035 docElem = doc.documentElement;
djmoffat@718 1036 parent = doc.defaultView;
djmoffat@718 1037
djmoffat@718 1038 // Support: IE>8
djmoffat@718 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
djmoffat@718 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
djmoffat@718 1041 // IE6-8 do not support the defaultView property so parent will be undefined
djmoffat@718 1042 if ( parent && parent !== parent.top ) {
djmoffat@718 1043 // IE11 does not have attachEvent, so all must suffer
djmoffat@718 1044 if ( parent.addEventListener ) {
djmoffat@718 1045 parent.addEventListener( "unload", unloadHandler, false );
djmoffat@718 1046 } else if ( parent.attachEvent ) {
djmoffat@718 1047 parent.attachEvent( "onunload", unloadHandler );
djmoffat@718 1048 }
djmoffat@718 1049 }
djmoffat@718 1050
djmoffat@718 1051 /* Support tests
djmoffat@718 1052 ---------------------------------------------------------------------- */
djmoffat@718 1053 documentIsHTML = !isXML( doc );
djmoffat@718 1054
djmoffat@718 1055 /* Attributes
djmoffat@718 1056 ---------------------------------------------------------------------- */
djmoffat@718 1057
djmoffat@718 1058 // Support: IE<8
djmoffat@718 1059 // Verify that getAttribute really returns attributes and not properties
djmoffat@718 1060 // (excepting IE8 booleans)
djmoffat@718 1061 support.attributes = assert(function( div ) {
djmoffat@718 1062 div.className = "i";
djmoffat@718 1063 return !div.getAttribute("className");
djmoffat@718 1064 });
djmoffat@718 1065
djmoffat@718 1066 /* getElement(s)By*
djmoffat@718 1067 ---------------------------------------------------------------------- */
djmoffat@718 1068
djmoffat@718 1069 // Check if getElementsByTagName("*") returns only elements
djmoffat@718 1070 support.getElementsByTagName = assert(function( div ) {
djmoffat@718 1071 div.appendChild( doc.createComment("") );
djmoffat@718 1072 return !div.getElementsByTagName("*").length;
djmoffat@718 1073 });
djmoffat@718 1074
djmoffat@718 1075 // Support: IE<9
djmoffat@718 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
djmoffat@718 1077
djmoffat@718 1078 // Support: IE<10
djmoffat@718 1079 // Check if getElementById returns elements by name
djmoffat@718 1080 // The broken getElementById methods don't pick up programatically-set names,
djmoffat@718 1081 // so use a roundabout getElementsByName test
djmoffat@718 1082 support.getById = assert(function( div ) {
djmoffat@718 1083 docElem.appendChild( div ).id = expando;
djmoffat@718 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
djmoffat@718 1085 });
djmoffat@718 1086
djmoffat@718 1087 // ID find and filter
djmoffat@718 1088 if ( support.getById ) {
djmoffat@718 1089 Expr.find["ID"] = function( id, context ) {
djmoffat@718 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
djmoffat@718 1091 var m = context.getElementById( id );
djmoffat@718 1092 // Check parentNode to catch when Blackberry 4.6 returns
djmoffat@718 1093 // nodes that are no longer in the document #6963
djmoffat@718 1094 return m && m.parentNode ? [ m ] : [];
djmoffat@718 1095 }
djmoffat@718 1096 };
djmoffat@718 1097 Expr.filter["ID"] = function( id ) {
djmoffat@718 1098 var attrId = id.replace( runescape, funescape );
djmoffat@718 1099 return function( elem ) {
djmoffat@718 1100 return elem.getAttribute("id") === attrId;
djmoffat@718 1101 };
djmoffat@718 1102 };
djmoffat@718 1103 } else {
djmoffat@718 1104 // Support: IE6/7
djmoffat@718 1105 // getElementById is not reliable as a find shortcut
djmoffat@718 1106 delete Expr.find["ID"];
djmoffat@718 1107
djmoffat@718 1108 Expr.filter["ID"] = function( id ) {
djmoffat@718 1109 var attrId = id.replace( runescape, funescape );
djmoffat@718 1110 return function( elem ) {
djmoffat@718 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
djmoffat@718 1112 return node && node.value === attrId;
djmoffat@718 1113 };
djmoffat@718 1114 };
djmoffat@718 1115 }
djmoffat@718 1116
djmoffat@718 1117 // Tag
djmoffat@718 1118 Expr.find["TAG"] = support.getElementsByTagName ?
djmoffat@718 1119 function( tag, context ) {
djmoffat@718 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
djmoffat@718 1121 return context.getElementsByTagName( tag );
djmoffat@718 1122
djmoffat@718 1123 // DocumentFragment nodes don't have gEBTN
djmoffat@718 1124 } else if ( support.qsa ) {
djmoffat@718 1125 return context.querySelectorAll( tag );
djmoffat@718 1126 }
djmoffat@718 1127 } :
djmoffat@718 1128
djmoffat@718 1129 function( tag, context ) {
djmoffat@718 1130 var elem,
djmoffat@718 1131 tmp = [],
djmoffat@718 1132 i = 0,
djmoffat@718 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
djmoffat@718 1134 results = context.getElementsByTagName( tag );
djmoffat@718 1135
djmoffat@718 1136 // Filter out possible comments
djmoffat@718 1137 if ( tag === "*" ) {
djmoffat@718 1138 while ( (elem = results[i++]) ) {
djmoffat@718 1139 if ( elem.nodeType === 1 ) {
djmoffat@718 1140 tmp.push( elem );
djmoffat@718 1141 }
djmoffat@718 1142 }
djmoffat@718 1143
djmoffat@718 1144 return tmp;
djmoffat@718 1145 }
djmoffat@718 1146 return results;
djmoffat@718 1147 };
djmoffat@718 1148
djmoffat@718 1149 // Class
djmoffat@718 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
djmoffat@718 1151 if ( documentIsHTML ) {
djmoffat@718 1152 return context.getElementsByClassName( className );
djmoffat@718 1153 }
djmoffat@718 1154 };
djmoffat@718 1155
djmoffat@718 1156 /* QSA/matchesSelector
djmoffat@718 1157 ---------------------------------------------------------------------- */
djmoffat@718 1158
djmoffat@718 1159 // QSA and matchesSelector support
djmoffat@718 1160
djmoffat@718 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
djmoffat@718 1162 rbuggyMatches = [];
djmoffat@718 1163
djmoffat@718 1164 // qSa(:focus) reports false when true (Chrome 21)
djmoffat@718 1165 // We allow this because of a bug in IE8/9 that throws an error
djmoffat@718 1166 // whenever `document.activeElement` is accessed on an iframe
djmoffat@718 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
djmoffat@718 1168 // See http://bugs.jquery.com/ticket/13378
djmoffat@718 1169 rbuggyQSA = [];
djmoffat@718 1170
djmoffat@718 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
djmoffat@718 1172 // Build QSA regex
djmoffat@718 1173 // Regex strategy adopted from Diego Perini
djmoffat@718 1174 assert(function( div ) {
djmoffat@718 1175 // Select is set to empty string on purpose
djmoffat@718 1176 // This is to test IE's treatment of not explicitly
djmoffat@718 1177 // setting a boolean content attribute,
djmoffat@718 1178 // since its presence should be enough
djmoffat@718 1179 // http://bugs.jquery.com/ticket/12359
djmoffat@718 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
djmoffat@718 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
djmoffat@718 1182 "<option selected=''></option></select>";
djmoffat@718 1183
djmoffat@718 1184 // Support: IE8, Opera 11-12.16
djmoffat@718 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
djmoffat@718 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
djmoffat@718 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
djmoffat@718 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
djmoffat@718 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
djmoffat@718 1190 }
djmoffat@718 1191
djmoffat@718 1192 // Support: IE8
djmoffat@718 1193 // Boolean attributes and "value" are not treated correctly
djmoffat@718 1194 if ( !div.querySelectorAll("[selected]").length ) {
djmoffat@718 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
djmoffat@718 1196 }
djmoffat@718 1197
djmoffat@718 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
djmoffat@718 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
djmoffat@718 1200 rbuggyQSA.push("~=");
djmoffat@718 1201 }
djmoffat@718 1202
djmoffat@718 1203 // Webkit/Opera - :checked should return selected option elements
djmoffat@718 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
djmoffat@718 1205 // IE8 throws error here and will not see later tests
djmoffat@718 1206 if ( !div.querySelectorAll(":checked").length ) {
djmoffat@718 1207 rbuggyQSA.push(":checked");
djmoffat@718 1208 }
djmoffat@718 1209
djmoffat@718 1210 // Support: Safari 8+, iOS 8+
djmoffat@718 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
djmoffat@718 1212 // In-page `selector#id sibing-combinator selector` fails
djmoffat@718 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
djmoffat@718 1214 rbuggyQSA.push(".#.+[+~]");
djmoffat@718 1215 }
djmoffat@718 1216 });
djmoffat@718 1217
djmoffat@718 1218 assert(function( div ) {
djmoffat@718 1219 // Support: Windows 8 Native Apps
djmoffat@718 1220 // The type and name attributes are restricted during .innerHTML assignment
djmoffat@718 1221 var input = doc.createElement("input");
djmoffat@718 1222 input.setAttribute( "type", "hidden" );
djmoffat@718 1223 div.appendChild( input ).setAttribute( "name", "D" );
djmoffat@718 1224
djmoffat@718 1225 // Support: IE8
djmoffat@718 1226 // Enforce case-sensitivity of name attribute
djmoffat@718 1227 if ( div.querySelectorAll("[name=d]").length ) {
djmoffat@718 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
djmoffat@718 1229 }
djmoffat@718 1230
djmoffat@718 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
djmoffat@718 1232 // IE8 throws error here and will not see later tests
djmoffat@718 1233 if ( !div.querySelectorAll(":enabled").length ) {
djmoffat@718 1234 rbuggyQSA.push( ":enabled", ":disabled" );
djmoffat@718 1235 }
djmoffat@718 1236
djmoffat@718 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
djmoffat@718 1238 div.querySelectorAll("*,:x");
djmoffat@718 1239 rbuggyQSA.push(",.*:");
djmoffat@718 1240 });
djmoffat@718 1241 }
djmoffat@718 1242
djmoffat@718 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
djmoffat@718 1244 docElem.webkitMatchesSelector ||
djmoffat@718 1245 docElem.mozMatchesSelector ||
djmoffat@718 1246 docElem.oMatchesSelector ||
djmoffat@718 1247 docElem.msMatchesSelector) )) ) {
djmoffat@718 1248
djmoffat@718 1249 assert(function( div ) {
djmoffat@718 1250 // Check to see if it's possible to do matchesSelector
djmoffat@718 1251 // on a disconnected node (IE 9)
djmoffat@718 1252 support.disconnectedMatch = matches.call( div, "div" );
djmoffat@718 1253
djmoffat@718 1254 // This should fail with an exception
djmoffat@718 1255 // Gecko does not error, returns false instead
djmoffat@718 1256 matches.call( div, "[s!='']:x" );
djmoffat@718 1257 rbuggyMatches.push( "!=", pseudos );
djmoffat@718 1258 });
djmoffat@718 1259 }
djmoffat@718 1260
djmoffat@718 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
djmoffat@718 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
djmoffat@718 1263
djmoffat@718 1264 /* Contains
djmoffat@718 1265 ---------------------------------------------------------------------- */
djmoffat@718 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
djmoffat@718 1267
djmoffat@718 1268 // Element contains another
djmoffat@718 1269 // Purposefully does not implement inclusive descendent
djmoffat@718 1270 // As in, an element does not contain itself
djmoffat@718 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
djmoffat@718 1272 function( a, b ) {
djmoffat@718 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
djmoffat@718 1274 bup = b && b.parentNode;
djmoffat@718 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
djmoffat@718 1276 adown.contains ?
djmoffat@718 1277 adown.contains( bup ) :
djmoffat@718 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
djmoffat@718 1279 ));
djmoffat@718 1280 } :
djmoffat@718 1281 function( a, b ) {
djmoffat@718 1282 if ( b ) {
djmoffat@718 1283 while ( (b = b.parentNode) ) {
djmoffat@718 1284 if ( b === a ) {
djmoffat@718 1285 return true;
djmoffat@718 1286 }
djmoffat@718 1287 }
djmoffat@718 1288 }
djmoffat@718 1289 return false;
djmoffat@718 1290 };
djmoffat@718 1291
djmoffat@718 1292 /* Sorting
djmoffat@718 1293 ---------------------------------------------------------------------- */
djmoffat@718 1294
djmoffat@718 1295 // Document order sorting
djmoffat@718 1296 sortOrder = hasCompare ?
djmoffat@718 1297 function( a, b ) {
djmoffat@718 1298
djmoffat@718 1299 // Flag for duplicate removal
djmoffat@718 1300 if ( a === b ) {
djmoffat@718 1301 hasDuplicate = true;
djmoffat@718 1302 return 0;
djmoffat@718 1303 }
djmoffat@718 1304
djmoffat@718 1305 // Sort on method existence if only one input has compareDocumentPosition
djmoffat@718 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
djmoffat@718 1307 if ( compare ) {
djmoffat@718 1308 return compare;
djmoffat@718 1309 }
djmoffat@718 1310
djmoffat@718 1311 // Calculate position if both inputs belong to the same document
djmoffat@718 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
djmoffat@718 1313 a.compareDocumentPosition( b ) :
djmoffat@718 1314
djmoffat@718 1315 // Otherwise we know they are disconnected
djmoffat@718 1316 1;
djmoffat@718 1317
djmoffat@718 1318 // Disconnected nodes
djmoffat@718 1319 if ( compare & 1 ||
djmoffat@718 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
djmoffat@718 1321
djmoffat@718 1322 // Choose the first element that is related to our preferred document
djmoffat@718 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
djmoffat@718 1324 return -1;
djmoffat@718 1325 }
djmoffat@718 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
djmoffat@718 1327 return 1;
djmoffat@718 1328 }
djmoffat@718 1329
djmoffat@718 1330 // Maintain original order
djmoffat@718 1331 return sortInput ?
djmoffat@718 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
djmoffat@718 1333 0;
djmoffat@718 1334 }
djmoffat@718 1335
djmoffat@718 1336 return compare & 4 ? -1 : 1;
djmoffat@718 1337 } :
djmoffat@718 1338 function( a, b ) {
djmoffat@718 1339 // Exit early if the nodes are identical
djmoffat@718 1340 if ( a === b ) {
djmoffat@718 1341 hasDuplicate = true;
djmoffat@718 1342 return 0;
djmoffat@718 1343 }
djmoffat@718 1344
djmoffat@718 1345 var cur,
djmoffat@718 1346 i = 0,
djmoffat@718 1347 aup = a.parentNode,
djmoffat@718 1348 bup = b.parentNode,
djmoffat@718 1349 ap = [ a ],
djmoffat@718 1350 bp = [ b ];
djmoffat@718 1351
djmoffat@718 1352 // Parentless nodes are either documents or disconnected
djmoffat@718 1353 if ( !aup || !bup ) {
djmoffat@718 1354 return a === doc ? -1 :
djmoffat@718 1355 b === doc ? 1 :
djmoffat@718 1356 aup ? -1 :
djmoffat@718 1357 bup ? 1 :
djmoffat@718 1358 sortInput ?
djmoffat@718 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
djmoffat@718 1360 0;
djmoffat@718 1361
djmoffat@718 1362 // If the nodes are siblings, we can do a quick check
djmoffat@718 1363 } else if ( aup === bup ) {
djmoffat@718 1364 return siblingCheck( a, b );
djmoffat@718 1365 }
djmoffat@718 1366
djmoffat@718 1367 // Otherwise we need full lists of their ancestors for comparison
djmoffat@718 1368 cur = a;
djmoffat@718 1369 while ( (cur = cur.parentNode) ) {
djmoffat@718 1370 ap.unshift( cur );
djmoffat@718 1371 }
djmoffat@718 1372 cur = b;
djmoffat@718 1373 while ( (cur = cur.parentNode) ) {
djmoffat@718 1374 bp.unshift( cur );
djmoffat@718 1375 }
djmoffat@718 1376
djmoffat@718 1377 // Walk down the tree looking for a discrepancy
djmoffat@718 1378 while ( ap[i] === bp[i] ) {
djmoffat@718 1379 i++;
djmoffat@718 1380 }
djmoffat@718 1381
djmoffat@718 1382 return i ?
djmoffat@718 1383 // Do a sibling check if the nodes have a common ancestor
djmoffat@718 1384 siblingCheck( ap[i], bp[i] ) :
djmoffat@718 1385
djmoffat@718 1386 // Otherwise nodes in our document sort first
djmoffat@718 1387 ap[i] === preferredDoc ? -1 :
djmoffat@718 1388 bp[i] === preferredDoc ? 1 :
djmoffat@718 1389 0;
djmoffat@718 1390 };
djmoffat@718 1391
djmoffat@718 1392 return doc;
djmoffat@718 1393 };
djmoffat@718 1394
djmoffat@718 1395 Sizzle.matches = function( expr, elements ) {
djmoffat@718 1396 return Sizzle( expr, null, null, elements );
djmoffat@718 1397 };
djmoffat@718 1398
djmoffat@718 1399 Sizzle.matchesSelector = function( elem, expr ) {
djmoffat@718 1400 // Set document vars if needed
djmoffat@718 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
djmoffat@718 1402 setDocument( elem );
djmoffat@718 1403 }
djmoffat@718 1404
djmoffat@718 1405 // Make sure that attribute selectors are quoted
djmoffat@718 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
djmoffat@718 1407
djmoffat@718 1408 if ( support.matchesSelector && documentIsHTML &&
djmoffat@718 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
djmoffat@718 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
djmoffat@718 1411
djmoffat@718 1412 try {
djmoffat@718 1413 var ret = matches.call( elem, expr );
djmoffat@718 1414
djmoffat@718 1415 // IE 9's matchesSelector returns false on disconnected nodes
djmoffat@718 1416 if ( ret || support.disconnectedMatch ||
djmoffat@718 1417 // As well, disconnected nodes are said to be in a document
djmoffat@718 1418 // fragment in IE 9
djmoffat@718 1419 elem.document && elem.document.nodeType !== 11 ) {
djmoffat@718 1420 return ret;
djmoffat@718 1421 }
djmoffat@718 1422 } catch (e) {}
djmoffat@718 1423 }
djmoffat@718 1424
djmoffat@718 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
djmoffat@718 1426 };
djmoffat@718 1427
djmoffat@718 1428 Sizzle.contains = function( context, elem ) {
djmoffat@718 1429 // Set document vars if needed
djmoffat@718 1430 if ( ( context.ownerDocument || context ) !== document ) {
djmoffat@718 1431 setDocument( context );
djmoffat@718 1432 }
djmoffat@718 1433 return contains( context, elem );
djmoffat@718 1434 };
djmoffat@718 1435
djmoffat@718 1436 Sizzle.attr = function( elem, name ) {
djmoffat@718 1437 // Set document vars if needed
djmoffat@718 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
djmoffat@718 1439 setDocument( elem );
djmoffat@718 1440 }
djmoffat@718 1441
djmoffat@718 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
djmoffat@718 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
djmoffat@718 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
djmoffat@718 1445 fn( elem, name, !documentIsHTML ) :
djmoffat@718 1446 undefined;
djmoffat@718 1447
djmoffat@718 1448 return val !== undefined ?
djmoffat@718 1449 val :
djmoffat@718 1450 support.attributes || !documentIsHTML ?
djmoffat@718 1451 elem.getAttribute( name ) :
djmoffat@718 1452 (val = elem.getAttributeNode(name)) && val.specified ?
djmoffat@718 1453 val.value :
djmoffat@718 1454 null;
djmoffat@718 1455 };
djmoffat@718 1456
djmoffat@718 1457 Sizzle.error = function( msg ) {
djmoffat@718 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
djmoffat@718 1459 };
djmoffat@718 1460
djmoffat@718 1461 /**
djmoffat@718 1462 * Document sorting and removing duplicates
djmoffat@718 1463 * @param {ArrayLike} results
djmoffat@718 1464 */
djmoffat@718 1465 Sizzle.uniqueSort = function( results ) {
djmoffat@718 1466 var elem,
djmoffat@718 1467 duplicates = [],
djmoffat@718 1468 j = 0,
djmoffat@718 1469 i = 0;
djmoffat@718 1470
djmoffat@718 1471 // Unless we *know* we can detect duplicates, assume their presence
djmoffat@718 1472 hasDuplicate = !support.detectDuplicates;
djmoffat@718 1473 sortInput = !support.sortStable && results.slice( 0 );
djmoffat@718 1474 results.sort( sortOrder );
djmoffat@718 1475
djmoffat@718 1476 if ( hasDuplicate ) {
djmoffat@718 1477 while ( (elem = results[i++]) ) {
djmoffat@718 1478 if ( elem === results[ i ] ) {
djmoffat@718 1479 j = duplicates.push( i );
djmoffat@718 1480 }
djmoffat@718 1481 }
djmoffat@718 1482 while ( j-- ) {
djmoffat@718 1483 results.splice( duplicates[ j ], 1 );
djmoffat@718 1484 }
djmoffat@718 1485 }
djmoffat@718 1486
djmoffat@718 1487 // Clear input after sorting to release objects
djmoffat@718 1488 // See https://github.com/jquery/sizzle/pull/225
djmoffat@718 1489 sortInput = null;
djmoffat@718 1490
djmoffat@718 1491 return results;
djmoffat@718 1492 };
djmoffat@718 1493
djmoffat@718 1494 /**
djmoffat@718 1495 * Utility function for retrieving the text value of an array of DOM nodes
djmoffat@718 1496 * @param {Array|Element} elem
djmoffat@718 1497 */
djmoffat@718 1498 getText = Sizzle.getText = function( elem ) {
djmoffat@718 1499 var node,
djmoffat@718 1500 ret = "",
djmoffat@718 1501 i = 0,
djmoffat@718 1502 nodeType = elem.nodeType;
djmoffat@718 1503
djmoffat@718 1504 if ( !nodeType ) {
djmoffat@718 1505 // If no nodeType, this is expected to be an array
djmoffat@718 1506 while ( (node = elem[i++]) ) {
djmoffat@718 1507 // Do not traverse comment nodes
djmoffat@718 1508 ret += getText( node );
djmoffat@718 1509 }
djmoffat@718 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
djmoffat@718 1511 // Use textContent for elements
djmoffat@718 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
djmoffat@718 1513 if ( typeof elem.textContent === "string" ) {
djmoffat@718 1514 return elem.textContent;
djmoffat@718 1515 } else {
djmoffat@718 1516 // Traverse its children
djmoffat@718 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
djmoffat@718 1518 ret += getText( elem );
djmoffat@718 1519 }
djmoffat@718 1520 }
djmoffat@718 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
djmoffat@718 1522 return elem.nodeValue;
djmoffat@718 1523 }
djmoffat@718 1524 // Do not include comment or processing instruction nodes
djmoffat@718 1525
djmoffat@718 1526 return ret;
djmoffat@718 1527 };
djmoffat@718 1528
djmoffat@718 1529 Expr = Sizzle.selectors = {
djmoffat@718 1530
djmoffat@718 1531 // Can be adjusted by the user
djmoffat@718 1532 cacheLength: 50,
djmoffat@718 1533
djmoffat@718 1534 createPseudo: markFunction,
djmoffat@718 1535
djmoffat@718 1536 match: matchExpr,
djmoffat@718 1537
djmoffat@718 1538 attrHandle: {},
djmoffat@718 1539
djmoffat@718 1540 find: {},
djmoffat@718 1541
djmoffat@718 1542 relative: {
djmoffat@718 1543 ">": { dir: "parentNode", first: true },
djmoffat@718 1544 " ": { dir: "parentNode" },
djmoffat@718 1545 "+": { dir: "previousSibling", first: true },
djmoffat@718 1546 "~": { dir: "previousSibling" }
djmoffat@718 1547 },
djmoffat@718 1548
djmoffat@718 1549 preFilter: {
djmoffat@718 1550 "ATTR": function( match ) {
djmoffat@718 1551 match[1] = match[1].replace( runescape, funescape );
djmoffat@718 1552
djmoffat@718 1553 // Move the given value to match[3] whether quoted or unquoted
djmoffat@718 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
djmoffat@718 1555
djmoffat@718 1556 if ( match[2] === "~=" ) {
djmoffat@718 1557 match[3] = " " + match[3] + " ";
djmoffat@718 1558 }
djmoffat@718 1559
djmoffat@718 1560 return match.slice( 0, 4 );
djmoffat@718 1561 },
djmoffat@718 1562
djmoffat@718 1563 "CHILD": function( match ) {
djmoffat@718 1564 /* matches from matchExpr["CHILD"]
djmoffat@718 1565 1 type (only|nth|...)
djmoffat@718 1566 2 what (child|of-type)
djmoffat@718 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
djmoffat@718 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
djmoffat@718 1569 5 sign of xn-component
djmoffat@718 1570 6 x of xn-component
djmoffat@718 1571 7 sign of y-component
djmoffat@718 1572 8 y of y-component
djmoffat@718 1573 */
djmoffat@718 1574 match[1] = match[1].toLowerCase();
djmoffat@718 1575
djmoffat@718 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
djmoffat@718 1577 // nth-* requires argument
djmoffat@718 1578 if ( !match[3] ) {
djmoffat@718 1579 Sizzle.error( match[0] );
djmoffat@718 1580 }
djmoffat@718 1581
djmoffat@718 1582 // numeric x and y parameters for Expr.filter.CHILD
djmoffat@718 1583 // remember that false/true cast respectively to 0/1
djmoffat@718 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
djmoffat@718 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
djmoffat@718 1586
djmoffat@718 1587 // other types prohibit arguments
djmoffat@718 1588 } else if ( match[3] ) {
djmoffat@718 1589 Sizzle.error( match[0] );
djmoffat@718 1590 }
djmoffat@718 1591
djmoffat@718 1592 return match;
djmoffat@718 1593 },
djmoffat@718 1594
djmoffat@718 1595 "PSEUDO": function( match ) {
djmoffat@718 1596 var excess,
djmoffat@718 1597 unquoted = !match[6] && match[2];
djmoffat@718 1598
djmoffat@718 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
djmoffat@718 1600 return null;
djmoffat@718 1601 }
djmoffat@718 1602
djmoffat@718 1603 // Accept quoted arguments as-is
djmoffat@718 1604 if ( match[3] ) {
djmoffat@718 1605 match[2] = match[4] || match[5] || "";
djmoffat@718 1606
djmoffat@718 1607 // Strip excess characters from unquoted arguments
djmoffat@718 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
djmoffat@718 1609 // Get excess from tokenize (recursively)
djmoffat@718 1610 (excess = tokenize( unquoted, true )) &&
djmoffat@718 1611 // advance to the next closing parenthesis
djmoffat@718 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
djmoffat@718 1613
djmoffat@718 1614 // excess is a negative index
djmoffat@718 1615 match[0] = match[0].slice( 0, excess );
djmoffat@718 1616 match[2] = unquoted.slice( 0, excess );
djmoffat@718 1617 }
djmoffat@718 1618
djmoffat@718 1619 // Return only captures needed by the pseudo filter method (type and argument)
djmoffat@718 1620 return match.slice( 0, 3 );
djmoffat@718 1621 }
djmoffat@718 1622 },
djmoffat@718 1623
djmoffat@718 1624 filter: {
djmoffat@718 1625
djmoffat@718 1626 "TAG": function( nodeNameSelector ) {
djmoffat@718 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
djmoffat@718 1628 return nodeNameSelector === "*" ?
djmoffat@718 1629 function() { return true; } :
djmoffat@718 1630 function( elem ) {
djmoffat@718 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
djmoffat@718 1632 };
djmoffat@718 1633 },
djmoffat@718 1634
djmoffat@718 1635 "CLASS": function( className ) {
djmoffat@718 1636 var pattern = classCache[ className + " " ];
djmoffat@718 1637
djmoffat@718 1638 return pattern ||
djmoffat@718 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
djmoffat@718 1640 classCache( className, function( elem ) {
djmoffat@718 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
djmoffat@718 1642 });
djmoffat@718 1643 },
djmoffat@718 1644
djmoffat@718 1645 "ATTR": function( name, operator, check ) {
djmoffat@718 1646 return function( elem ) {
djmoffat@718 1647 var result = Sizzle.attr( elem, name );
djmoffat@718 1648
djmoffat@718 1649 if ( result == null ) {
djmoffat@718 1650 return operator === "!=";
djmoffat@718 1651 }
djmoffat@718 1652 if ( !operator ) {
djmoffat@718 1653 return true;
djmoffat@718 1654 }
djmoffat@718 1655
djmoffat@718 1656 result += "";
djmoffat@718 1657
djmoffat@718 1658 return operator === "=" ? result === check :
djmoffat@718 1659 operator === "!=" ? result !== check :
djmoffat@718 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
djmoffat@718 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
djmoffat@718 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
djmoffat@718 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
djmoffat@718 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
djmoffat@718 1665 false;
djmoffat@718 1666 };
djmoffat@718 1667 },
djmoffat@718 1668
djmoffat@718 1669 "CHILD": function( type, what, argument, first, last ) {
djmoffat@718 1670 var simple = type.slice( 0, 3 ) !== "nth",
djmoffat@718 1671 forward = type.slice( -4 ) !== "last",
djmoffat@718 1672 ofType = what === "of-type";
djmoffat@718 1673
djmoffat@718 1674 return first === 1 && last === 0 ?
djmoffat@718 1675
djmoffat@718 1676 // Shortcut for :nth-*(n)
djmoffat@718 1677 function( elem ) {
djmoffat@718 1678 return !!elem.parentNode;
djmoffat@718 1679 } :
djmoffat@718 1680
djmoffat@718 1681 function( elem, context, xml ) {
djmoffat@718 1682 var cache, outerCache, node, diff, nodeIndex, start,
djmoffat@718 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
djmoffat@718 1684 parent = elem.parentNode,
djmoffat@718 1685 name = ofType && elem.nodeName.toLowerCase(),
djmoffat@718 1686 useCache = !xml && !ofType;
djmoffat@718 1687
djmoffat@718 1688 if ( parent ) {
djmoffat@718 1689
djmoffat@718 1690 // :(first|last|only)-(child|of-type)
djmoffat@718 1691 if ( simple ) {
djmoffat@718 1692 while ( dir ) {
djmoffat@718 1693 node = elem;
djmoffat@718 1694 while ( (node = node[ dir ]) ) {
djmoffat@718 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
djmoffat@718 1696 return false;
djmoffat@718 1697 }
djmoffat@718 1698 }
djmoffat@718 1699 // Reverse direction for :only-* (if we haven't yet done so)
djmoffat@718 1700 start = dir = type === "only" && !start && "nextSibling";
djmoffat@718 1701 }
djmoffat@718 1702 return true;
djmoffat@718 1703 }
djmoffat@718 1704
djmoffat@718 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
djmoffat@718 1706
djmoffat@718 1707 // non-xml :nth-child(...) stores cache data on `parent`
djmoffat@718 1708 if ( forward && useCache ) {
djmoffat@718 1709 // Seek `elem` from a previously-cached index
djmoffat@718 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
djmoffat@718 1711 cache = outerCache[ type ] || [];
djmoffat@718 1712 nodeIndex = cache[0] === dirruns && cache[1];
djmoffat@718 1713 diff = cache[0] === dirruns && cache[2];
djmoffat@718 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
djmoffat@718 1715
djmoffat@718 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
djmoffat@718 1717
djmoffat@718 1718 // Fallback to seeking `elem` from the start
djmoffat@718 1719 (diff = nodeIndex = 0) || start.pop()) ) {
djmoffat@718 1720
djmoffat@718 1721 // When found, cache indexes on `parent` and break
djmoffat@718 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
djmoffat@718 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
djmoffat@718 1724 break;
djmoffat@718 1725 }
djmoffat@718 1726 }
djmoffat@718 1727
djmoffat@718 1728 // Use previously-cached element index if available
djmoffat@718 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
djmoffat@718 1730 diff = cache[1];
djmoffat@718 1731
djmoffat@718 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
djmoffat@718 1733 } else {
djmoffat@718 1734 // Use the same loop as above to seek `elem` from the start
djmoffat@718 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
djmoffat@718 1736 (diff = nodeIndex = 0) || start.pop()) ) {
djmoffat@718 1737
djmoffat@718 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
djmoffat@718 1739 // Cache the index of each encountered element
djmoffat@718 1740 if ( useCache ) {
djmoffat@718 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
djmoffat@718 1742 }
djmoffat@718 1743
djmoffat@718 1744 if ( node === elem ) {
djmoffat@718 1745 break;
djmoffat@718 1746 }
djmoffat@718 1747 }
djmoffat@718 1748 }
djmoffat@718 1749 }
djmoffat@718 1750
djmoffat@718 1751 // Incorporate the offset, then check against cycle size
djmoffat@718 1752 diff -= last;
djmoffat@718 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
djmoffat@718 1754 }
djmoffat@718 1755 };
djmoffat@718 1756 },
djmoffat@718 1757
djmoffat@718 1758 "PSEUDO": function( pseudo, argument ) {
djmoffat@718 1759 // pseudo-class names are case-insensitive
djmoffat@718 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
djmoffat@718 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
djmoffat@718 1762 // Remember that setFilters inherits from pseudos
djmoffat@718 1763 var args,
djmoffat@718 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
djmoffat@718 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
djmoffat@718 1766
djmoffat@718 1767 // The user may use createPseudo to indicate that
djmoffat@718 1768 // arguments are needed to create the filter function
djmoffat@718 1769 // just as Sizzle does
djmoffat@718 1770 if ( fn[ expando ] ) {
djmoffat@718 1771 return fn( argument );
djmoffat@718 1772 }
djmoffat@718 1773
djmoffat@718 1774 // But maintain support for old signatures
djmoffat@718 1775 if ( fn.length > 1 ) {
djmoffat@718 1776 args = [ pseudo, pseudo, "", argument ];
djmoffat@718 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
djmoffat@718 1778 markFunction(function( seed, matches ) {
djmoffat@718 1779 var idx,
djmoffat@718 1780 matched = fn( seed, argument ),
djmoffat@718 1781 i = matched.length;
djmoffat@718 1782 while ( i-- ) {
djmoffat@718 1783 idx = indexOf( seed, matched[i] );
djmoffat@718 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
djmoffat@718 1785 }
djmoffat@718 1786 }) :
djmoffat@718 1787 function( elem ) {
djmoffat@718 1788 return fn( elem, 0, args );
djmoffat@718 1789 };
djmoffat@718 1790 }
djmoffat@718 1791
djmoffat@718 1792 return fn;
djmoffat@718 1793 }
djmoffat@718 1794 },
djmoffat@718 1795
djmoffat@718 1796 pseudos: {
djmoffat@718 1797 // Potentially complex pseudos
djmoffat@718 1798 "not": markFunction(function( selector ) {
djmoffat@718 1799 // Trim the selector passed to compile
djmoffat@718 1800 // to avoid treating leading and trailing
djmoffat@718 1801 // spaces as combinators
djmoffat@718 1802 var input = [],
djmoffat@718 1803 results = [],
djmoffat@718 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
djmoffat@718 1805
djmoffat@718 1806 return matcher[ expando ] ?
djmoffat@718 1807 markFunction(function( seed, matches, context, xml ) {
djmoffat@718 1808 var elem,
djmoffat@718 1809 unmatched = matcher( seed, null, xml, [] ),
djmoffat@718 1810 i = seed.length;
djmoffat@718 1811
djmoffat@718 1812 // Match elements unmatched by `matcher`
djmoffat@718 1813 while ( i-- ) {
djmoffat@718 1814 if ( (elem = unmatched[i]) ) {
djmoffat@718 1815 seed[i] = !(matches[i] = elem);
djmoffat@718 1816 }
djmoffat@718 1817 }
djmoffat@718 1818 }) :
djmoffat@718 1819 function( elem, context, xml ) {
djmoffat@718 1820 input[0] = elem;
djmoffat@718 1821 matcher( input, null, xml, results );
djmoffat@718 1822 // Don't keep the element (issue #299)
djmoffat@718 1823 input[0] = null;
djmoffat@718 1824 return !results.pop();
djmoffat@718 1825 };
djmoffat@718 1826 }),
djmoffat@718 1827
djmoffat@718 1828 "has": markFunction(function( selector ) {
djmoffat@718 1829 return function( elem ) {
djmoffat@718 1830 return Sizzle( selector, elem ).length > 0;
djmoffat@718 1831 };
djmoffat@718 1832 }),
djmoffat@718 1833
djmoffat@718 1834 "contains": markFunction(function( text ) {
djmoffat@718 1835 text = text.replace( runescape, funescape );
djmoffat@718 1836 return function( elem ) {
djmoffat@718 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
djmoffat@718 1838 };
djmoffat@718 1839 }),
djmoffat@718 1840
djmoffat@718 1841 // "Whether an element is represented by a :lang() selector
djmoffat@718 1842 // is based solely on the element's language value
djmoffat@718 1843 // being equal to the identifier C,
djmoffat@718 1844 // or beginning with the identifier C immediately followed by "-".
djmoffat@718 1845 // The matching of C against the element's language value is performed case-insensitively.
djmoffat@718 1846 // The identifier C does not have to be a valid language name."
djmoffat@718 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
djmoffat@718 1848 "lang": markFunction( function( lang ) {
djmoffat@718 1849 // lang value must be a valid identifier
djmoffat@718 1850 if ( !ridentifier.test(lang || "") ) {
djmoffat@718 1851 Sizzle.error( "unsupported lang: " + lang );
djmoffat@718 1852 }
djmoffat@718 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
djmoffat@718 1854 return function( elem ) {
djmoffat@718 1855 var elemLang;
djmoffat@718 1856 do {
djmoffat@718 1857 if ( (elemLang = documentIsHTML ?
djmoffat@718 1858 elem.lang :
djmoffat@718 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
djmoffat@718 1860
djmoffat@718 1861 elemLang = elemLang.toLowerCase();
djmoffat@718 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
djmoffat@718 1863 }
djmoffat@718 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
djmoffat@718 1865 return false;
djmoffat@718 1866 };
djmoffat@718 1867 }),
djmoffat@718 1868
djmoffat@718 1869 // Miscellaneous
djmoffat@718 1870 "target": function( elem ) {
djmoffat@718 1871 var hash = window.location && window.location.hash;
djmoffat@718 1872 return hash && hash.slice( 1 ) === elem.id;
djmoffat@718 1873 },
djmoffat@718 1874
djmoffat@718 1875 "root": function( elem ) {
djmoffat@718 1876 return elem === docElem;
djmoffat@718 1877 },
djmoffat@718 1878
djmoffat@718 1879 "focus": function( elem ) {
djmoffat@718 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
djmoffat@718 1881 },
djmoffat@718 1882
djmoffat@718 1883 // Boolean properties
djmoffat@718 1884 "enabled": function( elem ) {
djmoffat@718 1885 return elem.disabled === false;
djmoffat@718 1886 },
djmoffat@718 1887
djmoffat@718 1888 "disabled": function( elem ) {
djmoffat@718 1889 return elem.disabled === true;
djmoffat@718 1890 },
djmoffat@718 1891
djmoffat@718 1892 "checked": function( elem ) {
djmoffat@718 1893 // In CSS3, :checked should return both checked and selected elements
djmoffat@718 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
djmoffat@718 1895 var nodeName = elem.nodeName.toLowerCase();
djmoffat@718 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
djmoffat@718 1897 },
djmoffat@718 1898
djmoffat@718 1899 "selected": function( elem ) {
djmoffat@718 1900 // Accessing this property makes selected-by-default
djmoffat@718 1901 // options in Safari work properly
djmoffat@718 1902 if ( elem.parentNode ) {
djmoffat@718 1903 elem.parentNode.selectedIndex;
djmoffat@718 1904 }
djmoffat@718 1905
djmoffat@718 1906 return elem.selected === true;
djmoffat@718 1907 },
djmoffat@718 1908
djmoffat@718 1909 // Contents
djmoffat@718 1910 "empty": function( elem ) {
djmoffat@718 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
djmoffat@718 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
djmoffat@718 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
djmoffat@718 1914 // nodeType < 6 works because attributes (2) do not appear as children
djmoffat@718 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
djmoffat@718 1916 if ( elem.nodeType < 6 ) {
djmoffat@718 1917 return false;
djmoffat@718 1918 }
djmoffat@718 1919 }
djmoffat@718 1920 return true;
djmoffat@718 1921 },
djmoffat@718 1922
djmoffat@718 1923 "parent": function( elem ) {
djmoffat@718 1924 return !Expr.pseudos["empty"]( elem );
djmoffat@718 1925 },
djmoffat@718 1926
djmoffat@718 1927 // Element/input types
djmoffat@718 1928 "header": function( elem ) {
djmoffat@718 1929 return rheader.test( elem.nodeName );
djmoffat@718 1930 },
djmoffat@718 1931
djmoffat@718 1932 "input": function( elem ) {
djmoffat@718 1933 return rinputs.test( elem.nodeName );
djmoffat@718 1934 },
djmoffat@718 1935
djmoffat@718 1936 "button": function( elem ) {
djmoffat@718 1937 var name = elem.nodeName.toLowerCase();
djmoffat@718 1938 return name === "input" && elem.type === "button" || name === "button";
djmoffat@718 1939 },
djmoffat@718 1940
djmoffat@718 1941 "text": function( elem ) {
djmoffat@718 1942 var attr;
djmoffat@718 1943 return elem.nodeName.toLowerCase() === "input" &&
djmoffat@718 1944 elem.type === "text" &&
djmoffat@718 1945
djmoffat@718 1946 // Support: IE<8
djmoffat@718 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
djmoffat@718 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
djmoffat@718 1949 },
djmoffat@718 1950
djmoffat@718 1951 // Position-in-collection
djmoffat@718 1952 "first": createPositionalPseudo(function() {
djmoffat@718 1953 return [ 0 ];
djmoffat@718 1954 }),
djmoffat@718 1955
djmoffat@718 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
djmoffat@718 1957 return [ length - 1 ];
djmoffat@718 1958 }),
djmoffat@718 1959
djmoffat@718 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
djmoffat@718 1961 return [ argument < 0 ? argument + length : argument ];
djmoffat@718 1962 }),
djmoffat@718 1963
djmoffat@718 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
djmoffat@718 1965 var i = 0;
djmoffat@718 1966 for ( ; i < length; i += 2 ) {
djmoffat@718 1967 matchIndexes.push( i );
djmoffat@718 1968 }
djmoffat@718 1969 return matchIndexes;
djmoffat@718 1970 }),
djmoffat@718 1971
djmoffat@718 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
djmoffat@718 1973 var i = 1;
djmoffat@718 1974 for ( ; i < length; i += 2 ) {
djmoffat@718 1975 matchIndexes.push( i );
djmoffat@718 1976 }
djmoffat@718 1977 return matchIndexes;
djmoffat@718 1978 }),
djmoffat@718 1979
djmoffat@718 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
djmoffat@718 1981 var i = argument < 0 ? argument + length : argument;
djmoffat@718 1982 for ( ; --i >= 0; ) {
djmoffat@718 1983 matchIndexes.push( i );
djmoffat@718 1984 }
djmoffat@718 1985 return matchIndexes;
djmoffat@718 1986 }),
djmoffat@718 1987
djmoffat@718 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
djmoffat@718 1989 var i = argument < 0 ? argument + length : argument;
djmoffat@718 1990 for ( ; ++i < length; ) {
djmoffat@718 1991 matchIndexes.push( i );
djmoffat@718 1992 }
djmoffat@718 1993 return matchIndexes;
djmoffat@718 1994 })
djmoffat@718 1995 }
djmoffat@718 1996 };
djmoffat@718 1997
djmoffat@718 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
djmoffat@718 1999
djmoffat@718 2000 // Add button/input type pseudos
djmoffat@718 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
djmoffat@718 2002 Expr.pseudos[ i ] = createInputPseudo( i );
djmoffat@718 2003 }
djmoffat@718 2004 for ( i in { submit: true, reset: true } ) {
djmoffat@718 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
djmoffat@718 2006 }
djmoffat@718 2007
djmoffat@718 2008 // Easy API for creating new setFilters
djmoffat@718 2009 function setFilters() {}
djmoffat@718 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
djmoffat@718 2011 Expr.setFilters = new setFilters();
djmoffat@718 2012
djmoffat@718 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
djmoffat@718 2014 var matched, match, tokens, type,
djmoffat@718 2015 soFar, groups, preFilters,
djmoffat@718 2016 cached = tokenCache[ selector + " " ];
djmoffat@718 2017
djmoffat@718 2018 if ( cached ) {
djmoffat@718 2019 return parseOnly ? 0 : cached.slice( 0 );
djmoffat@718 2020 }
djmoffat@718 2021
djmoffat@718 2022 soFar = selector;
djmoffat@718 2023 groups = [];
djmoffat@718 2024 preFilters = Expr.preFilter;
djmoffat@718 2025
djmoffat@718 2026 while ( soFar ) {
djmoffat@718 2027
djmoffat@718 2028 // Comma and first run
djmoffat@718 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
djmoffat@718 2030 if ( match ) {
djmoffat@718 2031 // Don't consume trailing commas as valid
djmoffat@718 2032 soFar = soFar.slice( match[0].length ) || soFar;
djmoffat@718 2033 }
djmoffat@718 2034 groups.push( (tokens = []) );
djmoffat@718 2035 }
djmoffat@718 2036
djmoffat@718 2037 matched = false;
djmoffat@718 2038
djmoffat@718 2039 // Combinators
djmoffat@718 2040 if ( (match = rcombinators.exec( soFar )) ) {
djmoffat@718 2041 matched = match.shift();
djmoffat@718 2042 tokens.push({
djmoffat@718 2043 value: matched,
djmoffat@718 2044 // Cast descendant combinators to space
djmoffat@718 2045 type: match[0].replace( rtrim, " " )
djmoffat@718 2046 });
djmoffat@718 2047 soFar = soFar.slice( matched.length );
djmoffat@718 2048 }
djmoffat@718 2049
djmoffat@718 2050 // Filters
djmoffat@718 2051 for ( type in Expr.filter ) {
djmoffat@718 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
djmoffat@718 2053 (match = preFilters[ type ]( match ))) ) {
djmoffat@718 2054 matched = match.shift();
djmoffat@718 2055 tokens.push({
djmoffat@718 2056 value: matched,
djmoffat@718 2057 type: type,
djmoffat@718 2058 matches: match
djmoffat@718 2059 });
djmoffat@718 2060 soFar = soFar.slice( matched.length );
djmoffat@718 2061 }
djmoffat@718 2062 }
djmoffat@718 2063
djmoffat@718 2064 if ( !matched ) {
djmoffat@718 2065 break;
djmoffat@718 2066 }
djmoffat@718 2067 }
djmoffat@718 2068
djmoffat@718 2069 // Return the length of the invalid excess
djmoffat@718 2070 // if we're just parsing
djmoffat@718 2071 // Otherwise, throw an error or return tokens
djmoffat@718 2072 return parseOnly ?
djmoffat@718 2073 soFar.length :
djmoffat@718 2074 soFar ?
djmoffat@718 2075 Sizzle.error( selector ) :
djmoffat@718 2076 // Cache the tokens
djmoffat@718 2077 tokenCache( selector, groups ).slice( 0 );
djmoffat@718 2078 };
djmoffat@718 2079
djmoffat@718 2080 function toSelector( tokens ) {
djmoffat@718 2081 var i = 0,
djmoffat@718 2082 len = tokens.length,
djmoffat@718 2083 selector = "";
djmoffat@718 2084 for ( ; i < len; i++ ) {
djmoffat@718 2085 selector += tokens[i].value;
djmoffat@718 2086 }
djmoffat@718 2087 return selector;
djmoffat@718 2088 }
djmoffat@718 2089
djmoffat@718 2090 function addCombinator( matcher, combinator, base ) {
djmoffat@718 2091 var dir = combinator.dir,
djmoffat@718 2092 checkNonElements = base && dir === "parentNode",
djmoffat@718 2093 doneName = done++;
djmoffat@718 2094
djmoffat@718 2095 return combinator.first ?
djmoffat@718 2096 // Check against closest ancestor/preceding element
djmoffat@718 2097 function( elem, context, xml ) {
djmoffat@718 2098 while ( (elem = elem[ dir ]) ) {
djmoffat@718 2099 if ( elem.nodeType === 1 || checkNonElements ) {
djmoffat@718 2100 return matcher( elem, context, xml );
djmoffat@718 2101 }
djmoffat@718 2102 }
djmoffat@718 2103 } :
djmoffat@718 2104
djmoffat@718 2105 // Check against all ancestor/preceding elements
djmoffat@718 2106 function( elem, context, xml ) {
djmoffat@718 2107 var oldCache, outerCache,
djmoffat@718 2108 newCache = [ dirruns, doneName ];
djmoffat@718 2109
djmoffat@718 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
djmoffat@718 2111 if ( xml ) {
djmoffat@718 2112 while ( (elem = elem[ dir ]) ) {
djmoffat@718 2113 if ( elem.nodeType === 1 || checkNonElements ) {
djmoffat@718 2114 if ( matcher( elem, context, xml ) ) {
djmoffat@718 2115 return true;
djmoffat@718 2116 }
djmoffat@718 2117 }
djmoffat@718 2118 }
djmoffat@718 2119 } else {
djmoffat@718 2120 while ( (elem = elem[ dir ]) ) {
djmoffat@718 2121 if ( elem.nodeType === 1 || checkNonElements ) {
djmoffat@718 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
djmoffat@718 2123 if ( (oldCache = outerCache[ dir ]) &&
djmoffat@718 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
djmoffat@718 2125
djmoffat@718 2126 // Assign to newCache so results back-propagate to previous elements
djmoffat@718 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
djmoffat@718 2128 } else {
djmoffat@718 2129 // Reuse newcache so results back-propagate to previous elements
djmoffat@718 2130 outerCache[ dir ] = newCache;
djmoffat@718 2131
djmoffat@718 2132 // A match means we're done; a fail means we have to keep checking
djmoffat@718 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
djmoffat@718 2134 return true;
djmoffat@718 2135 }
djmoffat@718 2136 }
djmoffat@718 2137 }
djmoffat@718 2138 }
djmoffat@718 2139 }
djmoffat@718 2140 };
djmoffat@718 2141 }
djmoffat@718 2142
djmoffat@718 2143 function elementMatcher( matchers ) {
djmoffat@718 2144 return matchers.length > 1 ?
djmoffat@718 2145 function( elem, context, xml ) {
djmoffat@718 2146 var i = matchers.length;
djmoffat@718 2147 while ( i-- ) {
djmoffat@718 2148 if ( !matchers[i]( elem, context, xml ) ) {
djmoffat@718 2149 return false;
djmoffat@718 2150 }
djmoffat@718 2151 }
djmoffat@718 2152 return true;
djmoffat@718 2153 } :
djmoffat@718 2154 matchers[0];
djmoffat@718 2155 }
djmoffat@718 2156
djmoffat@718 2157 function multipleContexts( selector, contexts, results ) {
djmoffat@718 2158 var i = 0,
djmoffat@718 2159 len = contexts.length;
djmoffat@718 2160 for ( ; i < len; i++ ) {
djmoffat@718 2161 Sizzle( selector, contexts[i], results );
djmoffat@718 2162 }
djmoffat@718 2163 return results;
djmoffat@718 2164 }
djmoffat@718 2165
djmoffat@718 2166 function condense( unmatched, map, filter, context, xml ) {
djmoffat@718 2167 var elem,
djmoffat@718 2168 newUnmatched = [],
djmoffat@718 2169 i = 0,
djmoffat@718 2170 len = unmatched.length,
djmoffat@718 2171 mapped = map != null;
djmoffat@718 2172
djmoffat@718 2173 for ( ; i < len; i++ ) {
djmoffat@718 2174 if ( (elem = unmatched[i]) ) {
djmoffat@718 2175 if ( !filter || filter( elem, context, xml ) ) {
djmoffat@718 2176 newUnmatched.push( elem );
djmoffat@718 2177 if ( mapped ) {
djmoffat@718 2178 map.push( i );
djmoffat@718 2179 }
djmoffat@718 2180 }
djmoffat@718 2181 }
djmoffat@718 2182 }
djmoffat@718 2183
djmoffat@718 2184 return newUnmatched;
djmoffat@718 2185 }
djmoffat@718 2186
djmoffat@718 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
djmoffat@718 2188 if ( postFilter && !postFilter[ expando ] ) {
djmoffat@718 2189 postFilter = setMatcher( postFilter );
djmoffat@718 2190 }
djmoffat@718 2191 if ( postFinder && !postFinder[ expando ] ) {
djmoffat@718 2192 postFinder = setMatcher( postFinder, postSelector );
djmoffat@718 2193 }
djmoffat@718 2194 return markFunction(function( seed, results, context, xml ) {
djmoffat@718 2195 var temp, i, elem,
djmoffat@718 2196 preMap = [],
djmoffat@718 2197 postMap = [],
djmoffat@718 2198 preexisting = results.length,
djmoffat@718 2199
djmoffat@718 2200 // Get initial elements from seed or context
djmoffat@718 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
djmoffat@718 2202
djmoffat@718 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
djmoffat@718 2204 matcherIn = preFilter && ( seed || !selector ) ?
djmoffat@718 2205 condense( elems, preMap, preFilter, context, xml ) :
djmoffat@718 2206 elems,
djmoffat@718 2207
djmoffat@718 2208 matcherOut = matcher ?
djmoffat@718 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
djmoffat@718 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
djmoffat@718 2211
djmoffat@718 2212 // ...intermediate processing is necessary
djmoffat@718 2213 [] :
djmoffat@718 2214
djmoffat@718 2215 // ...otherwise use results directly
djmoffat@718 2216 results :
djmoffat@718 2217 matcherIn;
djmoffat@718 2218
djmoffat@718 2219 // Find primary matches
djmoffat@718 2220 if ( matcher ) {
djmoffat@718 2221 matcher( matcherIn, matcherOut, context, xml );
djmoffat@718 2222 }
djmoffat@718 2223
djmoffat@718 2224 // Apply postFilter
djmoffat@718 2225 if ( postFilter ) {
djmoffat@718 2226 temp = condense( matcherOut, postMap );
djmoffat@718 2227 postFilter( temp, [], context, xml );
djmoffat@718 2228
djmoffat@718 2229 // Un-match failing elements by moving them back to matcherIn
djmoffat@718 2230 i = temp.length;
djmoffat@718 2231 while ( i-- ) {
djmoffat@718 2232 if ( (elem = temp[i]) ) {
djmoffat@718 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
djmoffat@718 2234 }
djmoffat@718 2235 }
djmoffat@718 2236 }
djmoffat@718 2237
djmoffat@718 2238 if ( seed ) {
djmoffat@718 2239 if ( postFinder || preFilter ) {
djmoffat@718 2240 if ( postFinder ) {
djmoffat@718 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
djmoffat@718 2242 temp = [];
djmoffat@718 2243 i = matcherOut.length;
djmoffat@718 2244 while ( i-- ) {
djmoffat@718 2245 if ( (elem = matcherOut[i]) ) {
djmoffat@718 2246 // Restore matcherIn since elem is not yet a final match
djmoffat@718 2247 temp.push( (matcherIn[i] = elem) );
djmoffat@718 2248 }
djmoffat@718 2249 }
djmoffat@718 2250 postFinder( null, (matcherOut = []), temp, xml );
djmoffat@718 2251 }
djmoffat@718 2252
djmoffat@718 2253 // Move matched elements from seed to results to keep them synchronized
djmoffat@718 2254 i = matcherOut.length;
djmoffat@718 2255 while ( i-- ) {
djmoffat@718 2256 if ( (elem = matcherOut[i]) &&
djmoffat@718 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
djmoffat@718 2258
djmoffat@718 2259 seed[temp] = !(results[temp] = elem);
djmoffat@718 2260 }
djmoffat@718 2261 }
djmoffat@718 2262 }
djmoffat@718 2263
djmoffat@718 2264 // Add elements to results, through postFinder if defined
djmoffat@718 2265 } else {
djmoffat@718 2266 matcherOut = condense(
djmoffat@718 2267 matcherOut === results ?
djmoffat@718 2268 matcherOut.splice( preexisting, matcherOut.length ) :
djmoffat@718 2269 matcherOut
djmoffat@718 2270 );
djmoffat@718 2271 if ( postFinder ) {
djmoffat@718 2272 postFinder( null, results, matcherOut, xml );
djmoffat@718 2273 } else {
djmoffat@718 2274 push.apply( results, matcherOut );
djmoffat@718 2275 }
djmoffat@718 2276 }
djmoffat@718 2277 });
djmoffat@718 2278 }
djmoffat@718 2279
djmoffat@718 2280 function matcherFromTokens( tokens ) {
djmoffat@718 2281 var checkContext, matcher, j,
djmoffat@718 2282 len = tokens.length,
djmoffat@718 2283 leadingRelative = Expr.relative[ tokens[0].type ],
djmoffat@718 2284 implicitRelative = leadingRelative || Expr.relative[" "],
djmoffat@718 2285 i = leadingRelative ? 1 : 0,
djmoffat@718 2286
djmoffat@718 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
djmoffat@718 2288 matchContext = addCombinator( function( elem ) {
djmoffat@718 2289 return elem === checkContext;
djmoffat@718 2290 }, implicitRelative, true ),
djmoffat@718 2291 matchAnyContext = addCombinator( function( elem ) {
djmoffat@718 2292 return indexOf( checkContext, elem ) > -1;
djmoffat@718 2293 }, implicitRelative, true ),
djmoffat@718 2294 matchers = [ function( elem, context, xml ) {
djmoffat@718 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
djmoffat@718 2296 (checkContext = context).nodeType ?
djmoffat@718 2297 matchContext( elem, context, xml ) :
djmoffat@718 2298 matchAnyContext( elem, context, xml ) );
djmoffat@718 2299 // Avoid hanging onto element (issue #299)
djmoffat@718 2300 checkContext = null;
djmoffat@718 2301 return ret;
djmoffat@718 2302 } ];
djmoffat@718 2303
djmoffat@718 2304 for ( ; i < len; i++ ) {
djmoffat@718 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
djmoffat@718 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
djmoffat@718 2307 } else {
djmoffat@718 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
djmoffat@718 2309
djmoffat@718 2310 // Return special upon seeing a positional matcher
djmoffat@718 2311 if ( matcher[ expando ] ) {
djmoffat@718 2312 // Find the next relative operator (if any) for proper handling
djmoffat@718 2313 j = ++i;
djmoffat@718 2314 for ( ; j < len; j++ ) {
djmoffat@718 2315 if ( Expr.relative[ tokens[j].type ] ) {
djmoffat@718 2316 break;
djmoffat@718 2317 }
djmoffat@718 2318 }
djmoffat@718 2319 return setMatcher(
djmoffat@718 2320 i > 1 && elementMatcher( matchers ),
djmoffat@718 2321 i > 1 && toSelector(
djmoffat@718 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
djmoffat@718 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
djmoffat@718 2324 ).replace( rtrim, "$1" ),
djmoffat@718 2325 matcher,
djmoffat@718 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
djmoffat@718 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
djmoffat@718 2328 j < len && toSelector( tokens )
djmoffat@718 2329 );
djmoffat@718 2330 }
djmoffat@718 2331 matchers.push( matcher );
djmoffat@718 2332 }
djmoffat@718 2333 }
djmoffat@718 2334
djmoffat@718 2335 return elementMatcher( matchers );
djmoffat@718 2336 }
djmoffat@718 2337
djmoffat@718 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
djmoffat@718 2339 var bySet = setMatchers.length > 0,
djmoffat@718 2340 byElement = elementMatchers.length > 0,
djmoffat@718 2341 superMatcher = function( seed, context, xml, results, outermost ) {
djmoffat@718 2342 var elem, j, matcher,
djmoffat@718 2343 matchedCount = 0,
djmoffat@718 2344 i = "0",
djmoffat@718 2345 unmatched = seed && [],
djmoffat@718 2346 setMatched = [],
djmoffat@718 2347 contextBackup = outermostContext,
djmoffat@718 2348 // We must always have either seed elements or outermost context
djmoffat@718 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
djmoffat@718 2350 // Use integer dirruns iff this is the outermost matcher
djmoffat@718 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
djmoffat@718 2352 len = elems.length;
djmoffat@718 2353
djmoffat@718 2354 if ( outermost ) {
djmoffat@718 2355 outermostContext = context !== document && context;
djmoffat@718 2356 }
djmoffat@718 2357
djmoffat@718 2358 // Add elements passing elementMatchers directly to results
djmoffat@718 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
djmoffat@718 2360 // Support: IE<9, Safari
djmoffat@718 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
djmoffat@718 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
djmoffat@718 2363 if ( byElement && elem ) {
djmoffat@718 2364 j = 0;
djmoffat@718 2365 while ( (matcher = elementMatchers[j++]) ) {
djmoffat@718 2366 if ( matcher( elem, context, xml ) ) {
djmoffat@718 2367 results.push( elem );
djmoffat@718 2368 break;
djmoffat@718 2369 }
djmoffat@718 2370 }
djmoffat@718 2371 if ( outermost ) {
djmoffat@718 2372 dirruns = dirrunsUnique;
djmoffat@718 2373 }
djmoffat@718 2374 }
djmoffat@718 2375
djmoffat@718 2376 // Track unmatched elements for set filters
djmoffat@718 2377 if ( bySet ) {
djmoffat@718 2378 // They will have gone through all possible matchers
djmoffat@718 2379 if ( (elem = !matcher && elem) ) {
djmoffat@718 2380 matchedCount--;
djmoffat@718 2381 }
djmoffat@718 2382
djmoffat@718 2383 // Lengthen the array for every element, matched or not
djmoffat@718 2384 if ( seed ) {
djmoffat@718 2385 unmatched.push( elem );
djmoffat@718 2386 }
djmoffat@718 2387 }
djmoffat@718 2388 }
djmoffat@718 2389
djmoffat@718 2390 // Apply set filters to unmatched elements
djmoffat@718 2391 matchedCount += i;
djmoffat@718 2392 if ( bySet && i !== matchedCount ) {
djmoffat@718 2393 j = 0;
djmoffat@718 2394 while ( (matcher = setMatchers[j++]) ) {
djmoffat@718 2395 matcher( unmatched, setMatched, context, xml );
djmoffat@718 2396 }
djmoffat@718 2397
djmoffat@718 2398 if ( seed ) {
djmoffat@718 2399 // Reintegrate element matches to eliminate the need for sorting
djmoffat@718 2400 if ( matchedCount > 0 ) {
djmoffat@718 2401 while ( i-- ) {
djmoffat@718 2402 if ( !(unmatched[i] || setMatched[i]) ) {
djmoffat@718 2403 setMatched[i] = pop.call( results );
djmoffat@718 2404 }
djmoffat@718 2405 }
djmoffat@718 2406 }
djmoffat@718 2407
djmoffat@718 2408 // Discard index placeholder values to get only actual matches
djmoffat@718 2409 setMatched = condense( setMatched );
djmoffat@718 2410 }
djmoffat@718 2411
djmoffat@718 2412 // Add matches to results
djmoffat@718 2413 push.apply( results, setMatched );
djmoffat@718 2414
djmoffat@718 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
djmoffat@718 2416 if ( outermost && !seed && setMatched.length > 0 &&
djmoffat@718 2417 ( matchedCount + setMatchers.length ) > 1 ) {
djmoffat@718 2418
djmoffat@718 2419 Sizzle.uniqueSort( results );
djmoffat@718 2420 }
djmoffat@718 2421 }
djmoffat@718 2422
djmoffat@718 2423 // Override manipulation of globals by nested matchers
djmoffat@718 2424 if ( outermost ) {
djmoffat@718 2425 dirruns = dirrunsUnique;
djmoffat@718 2426 outermostContext = contextBackup;
djmoffat@718 2427 }
djmoffat@718 2428
djmoffat@718 2429 return unmatched;
djmoffat@718 2430 };
djmoffat@718 2431
djmoffat@718 2432 return bySet ?
djmoffat@718 2433 markFunction( superMatcher ) :
djmoffat@718 2434 superMatcher;
djmoffat@718 2435 }
djmoffat@718 2436
djmoffat@718 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
djmoffat@718 2438 var i,
djmoffat@718 2439 setMatchers = [],
djmoffat@718 2440 elementMatchers = [],
djmoffat@718 2441 cached = compilerCache[ selector + " " ];
djmoffat@718 2442
djmoffat@718 2443 if ( !cached ) {
djmoffat@718 2444 // Generate a function of recursive functions that can be used to check each element
djmoffat@718 2445 if ( !match ) {
djmoffat@718 2446 match = tokenize( selector );
djmoffat@718 2447 }
djmoffat@718 2448 i = match.length;
djmoffat@718 2449 while ( i-- ) {
djmoffat@718 2450 cached = matcherFromTokens( match[i] );
djmoffat@718 2451 if ( cached[ expando ] ) {
djmoffat@718 2452 setMatchers.push( cached );
djmoffat@718 2453 } else {
djmoffat@718 2454 elementMatchers.push( cached );
djmoffat@718 2455 }
djmoffat@718 2456 }
djmoffat@718 2457
djmoffat@718 2458 // Cache the compiled function
djmoffat@718 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
djmoffat@718 2460
djmoffat@718 2461 // Save selector and tokenization
djmoffat@718 2462 cached.selector = selector;
djmoffat@718 2463 }
djmoffat@718 2464 return cached;
djmoffat@718 2465 };
djmoffat@718 2466
djmoffat@718 2467 /**
djmoffat@718 2468 * A low-level selection function that works with Sizzle's compiled
djmoffat@718 2469 * selector functions
djmoffat@718 2470 * @param {String|Function} selector A selector or a pre-compiled
djmoffat@718 2471 * selector function built with Sizzle.compile
djmoffat@718 2472 * @param {Element} context
djmoffat@718 2473 * @param {Array} [results]
djmoffat@718 2474 * @param {Array} [seed] A set of elements to match against
djmoffat@718 2475 */
djmoffat@718 2476 select = Sizzle.select = function( selector, context, results, seed ) {
djmoffat@718 2477 var i, tokens, token, type, find,
djmoffat@718 2478 compiled = typeof selector === "function" && selector,
djmoffat@718 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
djmoffat@718 2480
djmoffat@718 2481 results = results || [];
djmoffat@718 2482
djmoffat@718 2483 // Try to minimize operations if there is no seed and only one group
djmoffat@718 2484 if ( match.length === 1 ) {
djmoffat@718 2485
djmoffat@718 2486 // Take a shortcut and set the context if the root selector is an ID
djmoffat@718 2487 tokens = match[0] = match[0].slice( 0 );
djmoffat@718 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
djmoffat@718 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
djmoffat@718 2490 Expr.relative[ tokens[1].type ] ) {
djmoffat@718 2491
djmoffat@718 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
djmoffat@718 2493 if ( !context ) {
djmoffat@718 2494 return results;
djmoffat@718 2495
djmoffat@718 2496 // Precompiled matchers will still verify ancestry, so step up a level
djmoffat@718 2497 } else if ( compiled ) {
djmoffat@718 2498 context = context.parentNode;
djmoffat@718 2499 }
djmoffat@718 2500
djmoffat@718 2501 selector = selector.slice( tokens.shift().value.length );
djmoffat@718 2502 }
djmoffat@718 2503
djmoffat@718 2504 // Fetch a seed set for right-to-left matching
djmoffat@718 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
djmoffat@718 2506 while ( i-- ) {
djmoffat@718 2507 token = tokens[i];
djmoffat@718 2508
djmoffat@718 2509 // Abort if we hit a combinator
djmoffat@718 2510 if ( Expr.relative[ (type = token.type) ] ) {
djmoffat@718 2511 break;
djmoffat@718 2512 }
djmoffat@718 2513 if ( (find = Expr.find[ type ]) ) {
djmoffat@718 2514 // Search, expanding context for leading sibling combinators
djmoffat@718 2515 if ( (seed = find(
djmoffat@718 2516 token.matches[0].replace( runescape, funescape ),
djmoffat@718 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
djmoffat@718 2518 )) ) {
djmoffat@718 2519
djmoffat@718 2520 // If seed is empty or no tokens remain, we can return early
djmoffat@718 2521 tokens.splice( i, 1 );
djmoffat@718 2522 selector = seed.length && toSelector( tokens );
djmoffat@718 2523 if ( !selector ) {
djmoffat@718 2524 push.apply( results, seed );
djmoffat@718 2525 return results;
djmoffat@718 2526 }
djmoffat@718 2527
djmoffat@718 2528 break;
djmoffat@718 2529 }
djmoffat@718 2530 }
djmoffat@718 2531 }
djmoffat@718 2532 }
djmoffat@718 2533
djmoffat@718 2534 // Compile and execute a filtering function if one is not provided
djmoffat@718 2535 // Provide `match` to avoid retokenization if we modified the selector above
djmoffat@718 2536 ( compiled || compile( selector, match ) )(
djmoffat@718 2537 seed,
djmoffat@718 2538 context,
djmoffat@718 2539 !documentIsHTML,
djmoffat@718 2540 results,
djmoffat@718 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
djmoffat@718 2542 );
djmoffat@718 2543 return results;
djmoffat@718 2544 };
djmoffat@718 2545
djmoffat@718 2546 // One-time assignments
djmoffat@718 2547
djmoffat@718 2548 // Sort stability
djmoffat@718 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
djmoffat@718 2550
djmoffat@718 2551 // Support: Chrome 14-35+
djmoffat@718 2552 // Always assume duplicates if they aren't passed to the comparison function
djmoffat@718 2553 support.detectDuplicates = !!hasDuplicate;
djmoffat@718 2554
djmoffat@718 2555 // Initialize against the default document
djmoffat@718 2556 setDocument();
djmoffat@718 2557
djmoffat@718 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
djmoffat@718 2559 // Detached nodes confoundingly follow *each other*
djmoffat@718 2560 support.sortDetached = assert(function( div1 ) {
djmoffat@718 2561 // Should return 1, but returns 4 (following)
djmoffat@718 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
djmoffat@718 2563 });
djmoffat@718 2564
djmoffat@718 2565 // Support: IE<8
djmoffat@718 2566 // Prevent attribute/property "interpolation"
djmoffat@718 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
djmoffat@718 2568 if ( !assert(function( div ) {
djmoffat@718 2569 div.innerHTML = "<a href='#'></a>";
djmoffat@718 2570 return div.firstChild.getAttribute("href") === "#" ;
djmoffat@718 2571 }) ) {
djmoffat@718 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
djmoffat@718 2573 if ( !isXML ) {
djmoffat@718 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
djmoffat@718 2575 }
djmoffat@718 2576 });
djmoffat@718 2577 }
djmoffat@718 2578
djmoffat@718 2579 // Support: IE<9
djmoffat@718 2580 // Use defaultValue in place of getAttribute("value")
djmoffat@718 2581 if ( !support.attributes || !assert(function( div ) {
djmoffat@718 2582 div.innerHTML = "<input/>";
djmoffat@718 2583 div.firstChild.setAttribute( "value", "" );
djmoffat@718 2584 return div.firstChild.getAttribute( "value" ) === "";
djmoffat@718 2585 }) ) {
djmoffat@718 2586 addHandle( "value", function( elem, name, isXML ) {
djmoffat@718 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
djmoffat@718 2588 return elem.defaultValue;
djmoffat@718 2589 }
djmoffat@718 2590 });
djmoffat@718 2591 }
djmoffat@718 2592
djmoffat@718 2593 // Support: IE<9
djmoffat@718 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
djmoffat@718 2595 if ( !assert(function( div ) {
djmoffat@718 2596 return div.getAttribute("disabled") == null;
djmoffat@718 2597 }) ) {
djmoffat@718 2598 addHandle( booleans, function( elem, name, isXML ) {
djmoffat@718 2599 var val;
djmoffat@718 2600 if ( !isXML ) {
djmoffat@718 2601 return elem[ name ] === true ? name.toLowerCase() :
djmoffat@718 2602 (val = elem.getAttributeNode( name )) && val.specified ?
djmoffat@718 2603 val.value :
djmoffat@718 2604 null;
djmoffat@718 2605 }
djmoffat@718 2606 });
djmoffat@718 2607 }
djmoffat@718 2608
djmoffat@718 2609 return Sizzle;
djmoffat@718 2610
djmoffat@718 2611 })( window );
djmoffat@718 2612
djmoffat@718 2613
djmoffat@718 2614
djmoffat@718 2615 jQuery.find = Sizzle;
djmoffat@718 2616 jQuery.expr = Sizzle.selectors;
djmoffat@718 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
djmoffat@718 2618 jQuery.unique = Sizzle.uniqueSort;
djmoffat@718 2619 jQuery.text = Sizzle.getText;
djmoffat@718 2620 jQuery.isXMLDoc = Sizzle.isXML;
djmoffat@718 2621 jQuery.contains = Sizzle.contains;
djmoffat@718 2622
djmoffat@718 2623
djmoffat@718 2624
djmoffat@718 2625 var rneedsContext = jQuery.expr.match.needsContext;
djmoffat@718 2626
djmoffat@718 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
djmoffat@718 2628
djmoffat@718 2629
djmoffat@718 2630
djmoffat@718 2631 var risSimple = /^.[^:#\[\.,]*$/;
djmoffat@718 2632
djmoffat@718 2633 // Implement the identical functionality for filter and not
djmoffat@718 2634 function winnow( elements, qualifier, not ) {
djmoffat@718 2635 if ( jQuery.isFunction( qualifier ) ) {
djmoffat@718 2636 return jQuery.grep( elements, function( elem, i ) {
djmoffat@718 2637 /* jshint -W018 */
djmoffat@718 2638 return !!qualifier.call( elem, i, elem ) !== not;
djmoffat@718 2639 });
djmoffat@718 2640
djmoffat@718 2641 }
djmoffat@718 2642
djmoffat@718 2643 if ( qualifier.nodeType ) {
djmoffat@718 2644 return jQuery.grep( elements, function( elem ) {
djmoffat@718 2645 return ( elem === qualifier ) !== not;
djmoffat@718 2646 });
djmoffat@718 2647
djmoffat@718 2648 }
djmoffat@718 2649
djmoffat@718 2650 if ( typeof qualifier === "string" ) {
djmoffat@718 2651 if ( risSimple.test( qualifier ) ) {
djmoffat@718 2652 return jQuery.filter( qualifier, elements, not );
djmoffat@718 2653 }
djmoffat@718 2654
djmoffat@718 2655 qualifier = jQuery.filter( qualifier, elements );
djmoffat@718 2656 }
djmoffat@718 2657
djmoffat@718 2658 return jQuery.grep( elements, function( elem ) {
djmoffat@718 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
djmoffat@718 2660 });
djmoffat@718 2661 }
djmoffat@718 2662
djmoffat@718 2663 jQuery.filter = function( expr, elems, not ) {
djmoffat@718 2664 var elem = elems[ 0 ];
djmoffat@718 2665
djmoffat@718 2666 if ( not ) {
djmoffat@718 2667 expr = ":not(" + expr + ")";
djmoffat@718 2668 }
djmoffat@718 2669
djmoffat@718 2670 return elems.length === 1 && elem.nodeType === 1 ?
djmoffat@718 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
djmoffat@718 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
djmoffat@718 2673 return elem.nodeType === 1;
djmoffat@718 2674 }));
djmoffat@718 2675 };
djmoffat@718 2676
djmoffat@718 2677 jQuery.fn.extend({
djmoffat@718 2678 find: function( selector ) {
djmoffat@718 2679 var i,
djmoffat@718 2680 len = this.length,
djmoffat@718 2681 ret = [],
djmoffat@718 2682 self = this;
djmoffat@718 2683
djmoffat@718 2684 if ( typeof selector !== "string" ) {
djmoffat@718 2685 return this.pushStack( jQuery( selector ).filter(function() {
djmoffat@718 2686 for ( i = 0; i < len; i++ ) {
djmoffat@718 2687 if ( jQuery.contains( self[ i ], this ) ) {
djmoffat@718 2688 return true;
djmoffat@718 2689 }
djmoffat@718 2690 }
djmoffat@718 2691 }) );
djmoffat@718 2692 }
djmoffat@718 2693
djmoffat@718 2694 for ( i = 0; i < len; i++ ) {
djmoffat@718 2695 jQuery.find( selector, self[ i ], ret );
djmoffat@718 2696 }
djmoffat@718 2697
djmoffat@718 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
djmoffat@718 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
djmoffat@718 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
djmoffat@718 2701 return ret;
djmoffat@718 2702 },
djmoffat@718 2703 filter: function( selector ) {
djmoffat@718 2704 return this.pushStack( winnow(this, selector || [], false) );
djmoffat@718 2705 },
djmoffat@718 2706 not: function( selector ) {
djmoffat@718 2707 return this.pushStack( winnow(this, selector || [], true) );
djmoffat@718 2708 },
djmoffat@718 2709 is: function( selector ) {
djmoffat@718 2710 return !!winnow(
djmoffat@718 2711 this,
djmoffat@718 2712
djmoffat@718 2713 // If this is a positional/relative selector, check membership in the returned set
djmoffat@718 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
djmoffat@718 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
djmoffat@718 2716 jQuery( selector ) :
djmoffat@718 2717 selector || [],
djmoffat@718 2718 false
djmoffat@718 2719 ).length;
djmoffat@718 2720 }
djmoffat@718 2721 });
djmoffat@718 2722
djmoffat@718 2723
djmoffat@718 2724 // Initialize a jQuery object
djmoffat@718 2725
djmoffat@718 2726
djmoffat@718 2727 // A central reference to the root jQuery(document)
djmoffat@718 2728 var rootjQuery,
djmoffat@718 2729
djmoffat@718 2730 // A simple way to check for HTML strings
djmoffat@718 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
djmoffat@718 2732 // Strict HTML recognition (#11290: must start with <)
djmoffat@718 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
djmoffat@718 2734
djmoffat@718 2735 init = jQuery.fn.init = function( selector, context ) {
djmoffat@718 2736 var match, elem;
djmoffat@718 2737
djmoffat@718 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
djmoffat@718 2739 if ( !selector ) {
djmoffat@718 2740 return this;
djmoffat@718 2741 }
djmoffat@718 2742
djmoffat@718 2743 // Handle HTML strings
djmoffat@718 2744 if ( typeof selector === "string" ) {
djmoffat@718 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
djmoffat@718 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
djmoffat@718 2747 match = [ null, selector, null ];
djmoffat@718 2748
djmoffat@718 2749 } else {
djmoffat@718 2750 match = rquickExpr.exec( selector );
djmoffat@718 2751 }
djmoffat@718 2752
djmoffat@718 2753 // Match html or make sure no context is specified for #id
djmoffat@718 2754 if ( match && (match[1] || !context) ) {
djmoffat@718 2755
djmoffat@718 2756 // HANDLE: $(html) -> $(array)
djmoffat@718 2757 if ( match[1] ) {
djmoffat@718 2758 context = context instanceof jQuery ? context[0] : context;
djmoffat@718 2759
djmoffat@718 2760 // Option to run scripts is true for back-compat
djmoffat@718 2761 // Intentionally let the error be thrown if parseHTML is not present
djmoffat@718 2762 jQuery.merge( this, jQuery.parseHTML(
djmoffat@718 2763 match[1],
djmoffat@718 2764 context && context.nodeType ? context.ownerDocument || context : document,
djmoffat@718 2765 true
djmoffat@718 2766 ) );
djmoffat@718 2767
djmoffat@718 2768 // HANDLE: $(html, props)
djmoffat@718 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
djmoffat@718 2770 for ( match in context ) {
djmoffat@718 2771 // Properties of context are called as methods if possible
djmoffat@718 2772 if ( jQuery.isFunction( this[ match ] ) ) {
djmoffat@718 2773 this[ match ]( context[ match ] );
djmoffat@718 2774
djmoffat@718 2775 // ...and otherwise set as attributes
djmoffat@718 2776 } else {
djmoffat@718 2777 this.attr( match, context[ match ] );
djmoffat@718 2778 }
djmoffat@718 2779 }
djmoffat@718 2780 }
djmoffat@718 2781
djmoffat@718 2782 return this;
djmoffat@718 2783
djmoffat@718 2784 // HANDLE: $(#id)
djmoffat@718 2785 } else {
djmoffat@718 2786 elem = document.getElementById( match[2] );
djmoffat@718 2787
djmoffat@718 2788 // Support: Blackberry 4.6
djmoffat@718 2789 // gEBID returns nodes no longer in the document (#6963)
djmoffat@718 2790 if ( elem && elem.parentNode ) {
djmoffat@718 2791 // Inject the element directly into the jQuery object
djmoffat@718 2792 this.length = 1;
djmoffat@718 2793 this[0] = elem;
djmoffat@718 2794 }
djmoffat@718 2795
djmoffat@718 2796 this.context = document;
djmoffat@718 2797 this.selector = selector;
djmoffat@718 2798 return this;
djmoffat@718 2799 }
djmoffat@718 2800
djmoffat@718 2801 // HANDLE: $(expr, $(...))
djmoffat@718 2802 } else if ( !context || context.jquery ) {
djmoffat@718 2803 return ( context || rootjQuery ).find( selector );
djmoffat@718 2804
djmoffat@718 2805 // HANDLE: $(expr, context)
djmoffat@718 2806 // (which is just equivalent to: $(context).find(expr)
djmoffat@718 2807 } else {
djmoffat@718 2808 return this.constructor( context ).find( selector );
djmoffat@718 2809 }
djmoffat@718 2810
djmoffat@718 2811 // HANDLE: $(DOMElement)
djmoffat@718 2812 } else if ( selector.nodeType ) {
djmoffat@718 2813 this.context = this[0] = selector;
djmoffat@718 2814 this.length = 1;
djmoffat@718 2815 return this;
djmoffat@718 2816
djmoffat@718 2817 // HANDLE: $(function)
djmoffat@718 2818 // Shortcut for document ready
djmoffat@718 2819 } else if ( jQuery.isFunction( selector ) ) {
djmoffat@718 2820 return typeof rootjQuery.ready !== "undefined" ?
djmoffat@718 2821 rootjQuery.ready( selector ) :
djmoffat@718 2822 // Execute immediately if ready is not present
djmoffat@718 2823 selector( jQuery );
djmoffat@718 2824 }
djmoffat@718 2825
djmoffat@718 2826 if ( selector.selector !== undefined ) {
djmoffat@718 2827 this.selector = selector.selector;
djmoffat@718 2828 this.context = selector.context;
djmoffat@718 2829 }
djmoffat@718 2830
djmoffat@718 2831 return jQuery.makeArray( selector, this );
djmoffat@718 2832 };
djmoffat@718 2833
djmoffat@718 2834 // Give the init function the jQuery prototype for later instantiation
djmoffat@718 2835 init.prototype = jQuery.fn;
djmoffat@718 2836
djmoffat@718 2837 // Initialize central reference
djmoffat@718 2838 rootjQuery = jQuery( document );
djmoffat@718 2839
djmoffat@718 2840
djmoffat@718 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
djmoffat@718 2842 // Methods guaranteed to produce a unique set when starting from a unique set
djmoffat@718 2843 guaranteedUnique = {
djmoffat@718 2844 children: true,
djmoffat@718 2845 contents: true,
djmoffat@718 2846 next: true,
djmoffat@718 2847 prev: true
djmoffat@718 2848 };
djmoffat@718 2849
djmoffat@718 2850 jQuery.extend({
djmoffat@718 2851 dir: function( elem, dir, until ) {
djmoffat@718 2852 var matched = [],
djmoffat@718 2853 truncate = until !== undefined;
djmoffat@718 2854
djmoffat@718 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
djmoffat@718 2856 if ( elem.nodeType === 1 ) {
djmoffat@718 2857 if ( truncate && jQuery( elem ).is( until ) ) {
djmoffat@718 2858 break;
djmoffat@718 2859 }
djmoffat@718 2860 matched.push( elem );
djmoffat@718 2861 }
djmoffat@718 2862 }
djmoffat@718 2863 return matched;
djmoffat@718 2864 },
djmoffat@718 2865
djmoffat@718 2866 sibling: function( n, elem ) {
djmoffat@718 2867 var matched = [];
djmoffat@718 2868
djmoffat@718 2869 for ( ; n; n = n.nextSibling ) {
djmoffat@718 2870 if ( n.nodeType === 1 && n !== elem ) {
djmoffat@718 2871 matched.push( n );
djmoffat@718 2872 }
djmoffat@718 2873 }
djmoffat@718 2874
djmoffat@718 2875 return matched;
djmoffat@718 2876 }
djmoffat@718 2877 });
djmoffat@718 2878
djmoffat@718 2879 jQuery.fn.extend({
djmoffat@718 2880 has: function( target ) {
djmoffat@718 2881 var targets = jQuery( target, this ),
djmoffat@718 2882 l = targets.length;
djmoffat@718 2883
djmoffat@718 2884 return this.filter(function() {
djmoffat@718 2885 var i = 0;
djmoffat@718 2886 for ( ; i < l; i++ ) {
djmoffat@718 2887 if ( jQuery.contains( this, targets[i] ) ) {
djmoffat@718 2888 return true;
djmoffat@718 2889 }
djmoffat@718 2890 }
djmoffat@718 2891 });
djmoffat@718 2892 },
djmoffat@718 2893
djmoffat@718 2894 closest: function( selectors, context ) {
djmoffat@718 2895 var cur,
djmoffat@718 2896 i = 0,
djmoffat@718 2897 l = this.length,
djmoffat@718 2898 matched = [],
djmoffat@718 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
djmoffat@718 2900 jQuery( selectors, context || this.context ) :
djmoffat@718 2901 0;
djmoffat@718 2902
djmoffat@718 2903 for ( ; i < l; i++ ) {
djmoffat@718 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
djmoffat@718 2905 // Always skip document fragments
djmoffat@718 2906 if ( cur.nodeType < 11 && (pos ?
djmoffat@718 2907 pos.index(cur) > -1 :
djmoffat@718 2908
djmoffat@718 2909 // Don't pass non-elements to Sizzle
djmoffat@718 2910 cur.nodeType === 1 &&
djmoffat@718 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
djmoffat@718 2912
djmoffat@718 2913 matched.push( cur );
djmoffat@718 2914 break;
djmoffat@718 2915 }
djmoffat@718 2916 }
djmoffat@718 2917 }
djmoffat@718 2918
djmoffat@718 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
djmoffat@718 2920 },
djmoffat@718 2921
djmoffat@718 2922 // Determine the position of an element within the set
djmoffat@718 2923 index: function( elem ) {
djmoffat@718 2924
djmoffat@718 2925 // No argument, return index in parent
djmoffat@718 2926 if ( !elem ) {
djmoffat@718 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
djmoffat@718 2928 }
djmoffat@718 2929
djmoffat@718 2930 // Index in selector
djmoffat@718 2931 if ( typeof elem === "string" ) {
djmoffat@718 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
djmoffat@718 2933 }
djmoffat@718 2934
djmoffat@718 2935 // Locate the position of the desired element
djmoffat@718 2936 return indexOf.call( this,
djmoffat@718 2937
djmoffat@718 2938 // If it receives a jQuery object, the first element is used
djmoffat@718 2939 elem.jquery ? elem[ 0 ] : elem
djmoffat@718 2940 );
djmoffat@718 2941 },
djmoffat@718 2942
djmoffat@718 2943 add: function( selector, context ) {
djmoffat@718 2944 return this.pushStack(
djmoffat@718 2945 jQuery.unique(
djmoffat@718 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
djmoffat@718 2947 )
djmoffat@718 2948 );
djmoffat@718 2949 },
djmoffat@718 2950
djmoffat@718 2951 addBack: function( selector ) {
djmoffat@718 2952 return this.add( selector == null ?
djmoffat@718 2953 this.prevObject : this.prevObject.filter(selector)
djmoffat@718 2954 );
djmoffat@718 2955 }
djmoffat@718 2956 });
djmoffat@718 2957
djmoffat@718 2958 function sibling( cur, dir ) {
djmoffat@718 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
djmoffat@718 2960 return cur;
djmoffat@718 2961 }
djmoffat@718 2962
djmoffat@718 2963 jQuery.each({
djmoffat@718 2964 parent: function( elem ) {
djmoffat@718 2965 var parent = elem.parentNode;
djmoffat@718 2966 return parent && parent.nodeType !== 11 ? parent : null;
djmoffat@718 2967 },
djmoffat@718 2968 parents: function( elem ) {
djmoffat@718 2969 return jQuery.dir( elem, "parentNode" );
djmoffat@718 2970 },
djmoffat@718 2971 parentsUntil: function( elem, i, until ) {
djmoffat@718 2972 return jQuery.dir( elem, "parentNode", until );
djmoffat@718 2973 },
djmoffat@718 2974 next: function( elem ) {
djmoffat@718 2975 return sibling( elem, "nextSibling" );
djmoffat@718 2976 },
djmoffat@718 2977 prev: function( elem ) {
djmoffat@718 2978 return sibling( elem, "previousSibling" );
djmoffat@718 2979 },
djmoffat@718 2980 nextAll: function( elem ) {
djmoffat@718 2981 return jQuery.dir( elem, "nextSibling" );
djmoffat@718 2982 },
djmoffat@718 2983 prevAll: function( elem ) {
djmoffat@718 2984 return jQuery.dir( elem, "previousSibling" );
djmoffat@718 2985 },
djmoffat@718 2986 nextUntil: function( elem, i, until ) {
djmoffat@718 2987 return jQuery.dir( elem, "nextSibling", until );
djmoffat@718 2988 },
djmoffat@718 2989 prevUntil: function( elem, i, until ) {
djmoffat@718 2990 return jQuery.dir( elem, "previousSibling", until );
djmoffat@718 2991 },
djmoffat@718 2992 siblings: function( elem ) {
djmoffat@718 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
djmoffat@718 2994 },
djmoffat@718 2995 children: function( elem ) {
djmoffat@718 2996 return jQuery.sibling( elem.firstChild );
djmoffat@718 2997 },
djmoffat@718 2998 contents: function( elem ) {
djmoffat@718 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
djmoffat@718 3000 }
djmoffat@718 3001 }, function( name, fn ) {
djmoffat@718 3002 jQuery.fn[ name ] = function( until, selector ) {
djmoffat@718 3003 var matched = jQuery.map( this, fn, until );
djmoffat@718 3004
djmoffat@718 3005 if ( name.slice( -5 ) !== "Until" ) {
djmoffat@718 3006 selector = until;
djmoffat@718 3007 }
djmoffat@718 3008
djmoffat@718 3009 if ( selector && typeof selector === "string" ) {
djmoffat@718 3010 matched = jQuery.filter( selector, matched );
djmoffat@718 3011 }
djmoffat@718 3012
djmoffat@718 3013 if ( this.length > 1 ) {
djmoffat@718 3014 // Remove duplicates
djmoffat@718 3015 if ( !guaranteedUnique[ name ] ) {
djmoffat@718 3016 jQuery.unique( matched );
djmoffat@718 3017 }
djmoffat@718 3018
djmoffat@718 3019 // Reverse order for parents* and prev-derivatives
djmoffat@718 3020 if ( rparentsprev.test( name ) ) {
djmoffat@718 3021 matched.reverse();
djmoffat@718 3022 }
djmoffat@718 3023 }
djmoffat@718 3024
djmoffat@718 3025 return this.pushStack( matched );
djmoffat@718 3026 };
djmoffat@718 3027 });
djmoffat@718 3028 var rnotwhite = (/\S+/g);
djmoffat@718 3029
djmoffat@718 3030
djmoffat@718 3031
djmoffat@718 3032 // String to Object options format cache
djmoffat@718 3033 var optionsCache = {};
djmoffat@718 3034
djmoffat@718 3035 // Convert String-formatted options into Object-formatted ones and store in cache
djmoffat@718 3036 function createOptions( options ) {
djmoffat@718 3037 var object = optionsCache[ options ] = {};
djmoffat@718 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
djmoffat@718 3039 object[ flag ] = true;
djmoffat@718 3040 });
djmoffat@718 3041 return object;
djmoffat@718 3042 }
djmoffat@718 3043
djmoffat@718 3044 /*
djmoffat@718 3045 * Create a callback list using the following parameters:
djmoffat@718 3046 *
djmoffat@718 3047 * options: an optional list of space-separated options that will change how
djmoffat@718 3048 * the callback list behaves or a more traditional option object
djmoffat@718 3049 *
djmoffat@718 3050 * By default a callback list will act like an event callback list and can be
djmoffat@718 3051 * "fired" multiple times.
djmoffat@718 3052 *
djmoffat@718 3053 * Possible options:
djmoffat@718 3054 *
djmoffat@718 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
djmoffat@718 3056 *
djmoffat@718 3057 * memory: will keep track of previous values and will call any callback added
djmoffat@718 3058 * after the list has been fired right away with the latest "memorized"
djmoffat@718 3059 * values (like a Deferred)
djmoffat@718 3060 *
djmoffat@718 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
djmoffat@718 3062 *
djmoffat@718 3063 * stopOnFalse: interrupt callings when a callback returns false
djmoffat@718 3064 *
djmoffat@718 3065 */
djmoffat@718 3066 jQuery.Callbacks = function( options ) {
djmoffat@718 3067
djmoffat@718 3068 // Convert options from String-formatted to Object-formatted if needed
djmoffat@718 3069 // (we check in cache first)
djmoffat@718 3070 options = typeof options === "string" ?
djmoffat@718 3071 ( optionsCache[ options ] || createOptions( options ) ) :
djmoffat@718 3072 jQuery.extend( {}, options );
djmoffat@718 3073
djmoffat@718 3074 var // Last fire value (for non-forgettable lists)
djmoffat@718 3075 memory,
djmoffat@718 3076 // Flag to know if list was already fired
djmoffat@718 3077 fired,
djmoffat@718 3078 // Flag to know if list is currently firing
djmoffat@718 3079 firing,
djmoffat@718 3080 // First callback to fire (used internally by add and fireWith)
djmoffat@718 3081 firingStart,
djmoffat@718 3082 // End of the loop when firing
djmoffat@718 3083 firingLength,
djmoffat@718 3084 // Index of currently firing callback (modified by remove if needed)
djmoffat@718 3085 firingIndex,
djmoffat@718 3086 // Actual callback list
djmoffat@718 3087 list = [],
djmoffat@718 3088 // Stack of fire calls for repeatable lists
djmoffat@718 3089 stack = !options.once && [],
djmoffat@718 3090 // Fire callbacks
djmoffat@718 3091 fire = function( data ) {
djmoffat@718 3092 memory = options.memory && data;
djmoffat@718 3093 fired = true;
djmoffat@718 3094 firingIndex = firingStart || 0;
djmoffat@718 3095 firingStart = 0;
djmoffat@718 3096 firingLength = list.length;
djmoffat@718 3097 firing = true;
djmoffat@718 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
djmoffat@718 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
djmoffat@718 3100 memory = false; // To prevent further calls using add
djmoffat@718 3101 break;
djmoffat@718 3102 }
djmoffat@718 3103 }
djmoffat@718 3104 firing = false;
djmoffat@718 3105 if ( list ) {
djmoffat@718 3106 if ( stack ) {
djmoffat@718 3107 if ( stack.length ) {
djmoffat@718 3108 fire( stack.shift() );
djmoffat@718 3109 }
djmoffat@718 3110 } else if ( memory ) {
djmoffat@718 3111 list = [];
djmoffat@718 3112 } else {
djmoffat@718 3113 self.disable();
djmoffat@718 3114 }
djmoffat@718 3115 }
djmoffat@718 3116 },
djmoffat@718 3117 // Actual Callbacks object
djmoffat@718 3118 self = {
djmoffat@718 3119 // Add a callback or a collection of callbacks to the list
djmoffat@718 3120 add: function() {
djmoffat@718 3121 if ( list ) {
djmoffat@718 3122 // First, we save the current length
djmoffat@718 3123 var start = list.length;
djmoffat@718 3124 (function add( args ) {
djmoffat@718 3125 jQuery.each( args, function( _, arg ) {
djmoffat@718 3126 var type = jQuery.type( arg );
djmoffat@718 3127 if ( type === "function" ) {
djmoffat@718 3128 if ( !options.unique || !self.has( arg ) ) {
djmoffat@718 3129 list.push( arg );
djmoffat@718 3130 }
djmoffat@718 3131 } else if ( arg && arg.length && type !== "string" ) {
djmoffat@718 3132 // Inspect recursively
djmoffat@718 3133 add( arg );
djmoffat@718 3134 }
djmoffat@718 3135 });
djmoffat@718 3136 })( arguments );
djmoffat@718 3137 // Do we need to add the callbacks to the
djmoffat@718 3138 // current firing batch?
djmoffat@718 3139 if ( firing ) {
djmoffat@718 3140 firingLength = list.length;
djmoffat@718 3141 // With memory, if we're not firing then
djmoffat@718 3142 // we should call right away
djmoffat@718 3143 } else if ( memory ) {
djmoffat@718 3144 firingStart = start;
djmoffat@718 3145 fire( memory );
djmoffat@718 3146 }
djmoffat@718 3147 }
djmoffat@718 3148 return this;
djmoffat@718 3149 },
djmoffat@718 3150 // Remove a callback from the list
djmoffat@718 3151 remove: function() {
djmoffat@718 3152 if ( list ) {
djmoffat@718 3153 jQuery.each( arguments, function( _, arg ) {
djmoffat@718 3154 var index;
djmoffat@718 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
djmoffat@718 3156 list.splice( index, 1 );
djmoffat@718 3157 // Handle firing indexes
djmoffat@718 3158 if ( firing ) {
djmoffat@718 3159 if ( index <= firingLength ) {
djmoffat@718 3160 firingLength--;
djmoffat@718 3161 }
djmoffat@718 3162 if ( index <= firingIndex ) {
djmoffat@718 3163 firingIndex--;
djmoffat@718 3164 }
djmoffat@718 3165 }
djmoffat@718 3166 }
djmoffat@718 3167 });
djmoffat@718 3168 }
djmoffat@718 3169 return this;
djmoffat@718 3170 },
djmoffat@718 3171 // Check if a given callback is in the list.
djmoffat@718 3172 // If no argument is given, return whether or not list has callbacks attached.
djmoffat@718 3173 has: function( fn ) {
djmoffat@718 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
djmoffat@718 3175 },
djmoffat@718 3176 // Remove all callbacks from the list
djmoffat@718 3177 empty: function() {
djmoffat@718 3178 list = [];
djmoffat@718 3179 firingLength = 0;
djmoffat@718 3180 return this;
djmoffat@718 3181 },
djmoffat@718 3182 // Have the list do nothing anymore
djmoffat@718 3183 disable: function() {
djmoffat@718 3184 list = stack = memory = undefined;
djmoffat@718 3185 return this;
djmoffat@718 3186 },
djmoffat@718 3187 // Is it disabled?
djmoffat@718 3188 disabled: function() {
djmoffat@718 3189 return !list;
djmoffat@718 3190 },
djmoffat@718 3191 // Lock the list in its current state
djmoffat@718 3192 lock: function() {
djmoffat@718 3193 stack = undefined;
djmoffat@718 3194 if ( !memory ) {
djmoffat@718 3195 self.disable();
djmoffat@718 3196 }
djmoffat@718 3197 return this;
djmoffat@718 3198 },
djmoffat@718 3199 // Is it locked?
djmoffat@718 3200 locked: function() {
djmoffat@718 3201 return !stack;
djmoffat@718 3202 },
djmoffat@718 3203 // Call all callbacks with the given context and arguments
djmoffat@718 3204 fireWith: function( context, args ) {
djmoffat@718 3205 if ( list && ( !fired || stack ) ) {
djmoffat@718 3206 args = args || [];
djmoffat@718 3207 args = [ context, args.slice ? args.slice() : args ];
djmoffat@718 3208 if ( firing ) {
djmoffat@718 3209 stack.push( args );
djmoffat@718 3210 } else {
djmoffat@718 3211 fire( args );
djmoffat@718 3212 }
djmoffat@718 3213 }
djmoffat@718 3214 return this;
djmoffat@718 3215 },
djmoffat@718 3216 // Call all the callbacks with the given arguments
djmoffat@718 3217 fire: function() {
djmoffat@718 3218 self.fireWith( this, arguments );
djmoffat@718 3219 return this;
djmoffat@718 3220 },
djmoffat@718 3221 // To know if the callbacks have already been called at least once
djmoffat@718 3222 fired: function() {
djmoffat@718 3223 return !!fired;
djmoffat@718 3224 }
djmoffat@718 3225 };
djmoffat@718 3226
djmoffat@718 3227 return self;
djmoffat@718 3228 };
djmoffat@718 3229
djmoffat@718 3230
djmoffat@718 3231 jQuery.extend({
djmoffat@718 3232
djmoffat@718 3233 Deferred: function( func ) {
djmoffat@718 3234 var tuples = [
djmoffat@718 3235 // action, add listener, listener list, final state
djmoffat@718 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
djmoffat@718 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
djmoffat@718 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
djmoffat@718 3239 ],
djmoffat@718 3240 state = "pending",
djmoffat@718 3241 promise = {
djmoffat@718 3242 state: function() {
djmoffat@718 3243 return state;
djmoffat@718 3244 },
djmoffat@718 3245 always: function() {
djmoffat@718 3246 deferred.done( arguments ).fail( arguments );
djmoffat@718 3247 return this;
djmoffat@718 3248 },
djmoffat@718 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
djmoffat@718 3250 var fns = arguments;
djmoffat@718 3251 return jQuery.Deferred(function( newDefer ) {
djmoffat@718 3252 jQuery.each( tuples, function( i, tuple ) {
djmoffat@718 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
djmoffat@718 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
djmoffat@718 3255 deferred[ tuple[1] ](function() {
djmoffat@718 3256 var returned = fn && fn.apply( this, arguments );
djmoffat@718 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
djmoffat@718 3258 returned.promise()
djmoffat@718 3259 .done( newDefer.resolve )
djmoffat@718 3260 .fail( newDefer.reject )
djmoffat@718 3261 .progress( newDefer.notify );
djmoffat@718 3262 } else {
djmoffat@718 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
djmoffat@718 3264 }
djmoffat@718 3265 });
djmoffat@718 3266 });
djmoffat@718 3267 fns = null;
djmoffat@718 3268 }).promise();
djmoffat@718 3269 },
djmoffat@718 3270 // Get a promise for this deferred
djmoffat@718 3271 // If obj is provided, the promise aspect is added to the object
djmoffat@718 3272 promise: function( obj ) {
djmoffat@718 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
djmoffat@718 3274 }
djmoffat@718 3275 },
djmoffat@718 3276 deferred = {};
djmoffat@718 3277
djmoffat@718 3278 // Keep pipe for back-compat
djmoffat@718 3279 promise.pipe = promise.then;
djmoffat@718 3280
djmoffat@718 3281 // Add list-specific methods
djmoffat@718 3282 jQuery.each( tuples, function( i, tuple ) {
djmoffat@718 3283 var list = tuple[ 2 ],
djmoffat@718 3284 stateString = tuple[ 3 ];
djmoffat@718 3285
djmoffat@718 3286 // promise[ done | fail | progress ] = list.add
djmoffat@718 3287 promise[ tuple[1] ] = list.add;
djmoffat@718 3288
djmoffat@718 3289 // Handle state
djmoffat@718 3290 if ( stateString ) {
djmoffat@718 3291 list.add(function() {
djmoffat@718 3292 // state = [ resolved | rejected ]
djmoffat@718 3293 state = stateString;
djmoffat@718 3294
djmoffat@718 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
djmoffat@718 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
djmoffat@718 3297 }
djmoffat@718 3298
djmoffat@718 3299 // deferred[ resolve | reject | notify ]
djmoffat@718 3300 deferred[ tuple[0] ] = function() {
djmoffat@718 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
djmoffat@718 3302 return this;
djmoffat@718 3303 };
djmoffat@718 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
djmoffat@718 3305 });
djmoffat@718 3306
djmoffat@718 3307 // Make the deferred a promise
djmoffat@718 3308 promise.promise( deferred );
djmoffat@718 3309
djmoffat@718 3310 // Call given func if any
djmoffat@718 3311 if ( func ) {
djmoffat@718 3312 func.call( deferred, deferred );
djmoffat@718 3313 }
djmoffat@718 3314
djmoffat@718 3315 // All done!
djmoffat@718 3316 return deferred;
djmoffat@718 3317 },
djmoffat@718 3318
djmoffat@718 3319 // Deferred helper
djmoffat@718 3320 when: function( subordinate /* , ..., subordinateN */ ) {
djmoffat@718 3321 var i = 0,
djmoffat@718 3322 resolveValues = slice.call( arguments ),
djmoffat@718 3323 length = resolveValues.length,
djmoffat@718 3324
djmoffat@718 3325 // the count of uncompleted subordinates
djmoffat@718 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
djmoffat@718 3327
djmoffat@718 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
djmoffat@718 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
djmoffat@718 3330
djmoffat@718 3331 // Update function for both resolve and progress values
djmoffat@718 3332 updateFunc = function( i, contexts, values ) {
djmoffat@718 3333 return function( value ) {
djmoffat@718 3334 contexts[ i ] = this;
djmoffat@718 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
djmoffat@718 3336 if ( values === progressValues ) {
djmoffat@718 3337 deferred.notifyWith( contexts, values );
djmoffat@718 3338 } else if ( !( --remaining ) ) {
djmoffat@718 3339 deferred.resolveWith( contexts, values );
djmoffat@718 3340 }
djmoffat@718 3341 };
djmoffat@718 3342 },
djmoffat@718 3343
djmoffat@718 3344 progressValues, progressContexts, resolveContexts;
djmoffat@718 3345
djmoffat@718 3346 // Add listeners to Deferred subordinates; treat others as resolved
djmoffat@718 3347 if ( length > 1 ) {
djmoffat@718 3348 progressValues = new Array( length );
djmoffat@718 3349 progressContexts = new Array( length );
djmoffat@718 3350 resolveContexts = new Array( length );
djmoffat@718 3351 for ( ; i < length; i++ ) {
djmoffat@718 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
djmoffat@718 3353 resolveValues[ i ].promise()
djmoffat@718 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
djmoffat@718 3355 .fail( deferred.reject )
djmoffat@718 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
djmoffat@718 3357 } else {
djmoffat@718 3358 --remaining;
djmoffat@718 3359 }
djmoffat@718 3360 }
djmoffat@718 3361 }
djmoffat@718 3362
djmoffat@718 3363 // If we're not waiting on anything, resolve the master
djmoffat@718 3364 if ( !remaining ) {
djmoffat@718 3365 deferred.resolveWith( resolveContexts, resolveValues );
djmoffat@718 3366 }
djmoffat@718 3367
djmoffat@718 3368 return deferred.promise();
djmoffat@718 3369 }
djmoffat@718 3370 });
djmoffat@718 3371
djmoffat@718 3372
djmoffat@718 3373 // The deferred used on DOM ready
djmoffat@718 3374 var readyList;
djmoffat@718 3375
djmoffat@718 3376 jQuery.fn.ready = function( fn ) {
djmoffat@718 3377 // Add the callback
djmoffat@718 3378 jQuery.ready.promise().done( fn );
djmoffat@718 3379
djmoffat@718 3380 return this;
djmoffat@718 3381 };
djmoffat@718 3382
djmoffat@718 3383 jQuery.extend({
djmoffat@718 3384 // Is the DOM ready to be used? Set to true once it occurs.
djmoffat@718 3385 isReady: false,
djmoffat@718 3386
djmoffat@718 3387 // A counter to track how many items to wait for before
djmoffat@718 3388 // the ready event fires. See #6781
djmoffat@718 3389 readyWait: 1,
djmoffat@718 3390
djmoffat@718 3391 // Hold (or release) the ready event
djmoffat@718 3392 holdReady: function( hold ) {
djmoffat@718 3393 if ( hold ) {
djmoffat@718 3394 jQuery.readyWait++;
djmoffat@718 3395 } else {
djmoffat@718 3396 jQuery.ready( true );
djmoffat@718 3397 }
djmoffat@718 3398 },
djmoffat@718 3399
djmoffat@718 3400 // Handle when the DOM is ready
djmoffat@718 3401 ready: function( wait ) {
djmoffat@718 3402
djmoffat@718 3403 // Abort if there are pending holds or we're already ready
djmoffat@718 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
djmoffat@718 3405 return;
djmoffat@718 3406 }
djmoffat@718 3407
djmoffat@718 3408 // Remember that the DOM is ready
djmoffat@718 3409 jQuery.isReady = true;
djmoffat@718 3410
djmoffat@718 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
djmoffat@718 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
djmoffat@718 3413 return;
djmoffat@718 3414 }
djmoffat@718 3415
djmoffat@718 3416 // If there are functions bound, to execute
djmoffat@718 3417 readyList.resolveWith( document, [ jQuery ] );
djmoffat@718 3418
djmoffat@718 3419 // Trigger any bound ready events
djmoffat@718 3420 if ( jQuery.fn.triggerHandler ) {
djmoffat@718 3421 jQuery( document ).triggerHandler( "ready" );
djmoffat@718 3422 jQuery( document ).off( "ready" );
djmoffat@718 3423 }
djmoffat@718 3424 }
djmoffat@718 3425 });
djmoffat@718 3426
djmoffat@718 3427 /**
djmoffat@718 3428 * The ready event handler and self cleanup method
djmoffat@718 3429 */
djmoffat@718 3430 function completed() {
djmoffat@718 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
djmoffat@718 3432 window.removeEventListener( "load", completed, false );
djmoffat@718 3433 jQuery.ready();
djmoffat@718 3434 }
djmoffat@718 3435
djmoffat@718 3436 jQuery.ready.promise = function( obj ) {
djmoffat@718 3437 if ( !readyList ) {
djmoffat@718 3438
djmoffat@718 3439 readyList = jQuery.Deferred();
djmoffat@718 3440
djmoffat@718 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
djmoffat@718 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
djmoffat@718 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
djmoffat@718 3444 if ( document.readyState === "complete" ) {
djmoffat@718 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
djmoffat@718 3446 setTimeout( jQuery.ready );
djmoffat@718 3447
djmoffat@718 3448 } else {
djmoffat@718 3449
djmoffat@718 3450 // Use the handy event callback
djmoffat@718 3451 document.addEventListener( "DOMContentLoaded", completed, false );
djmoffat@718 3452
djmoffat@718 3453 // A fallback to window.onload, that will always work
djmoffat@718 3454 window.addEventListener( "load", completed, false );
djmoffat@718 3455 }
djmoffat@718 3456 }
djmoffat@718 3457 return readyList.promise( obj );
djmoffat@718 3458 };
djmoffat@718 3459
djmoffat@718 3460 // Kick off the DOM ready check even if the user does not
djmoffat@718 3461 jQuery.ready.promise();
djmoffat@718 3462
djmoffat@718 3463
djmoffat@718 3464
djmoffat@718 3465
djmoffat@718 3466 // Multifunctional method to get and set values of a collection
djmoffat@718 3467 // The value/s can optionally be executed if it's a function
djmoffat@718 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
djmoffat@718 3469 var i = 0,
djmoffat@718 3470 len = elems.length,
djmoffat@718 3471 bulk = key == null;
djmoffat@718 3472
djmoffat@718 3473 // Sets many values
djmoffat@718 3474 if ( jQuery.type( key ) === "object" ) {
djmoffat@718 3475 chainable = true;
djmoffat@718 3476 for ( i in key ) {
djmoffat@718 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
djmoffat@718 3478 }
djmoffat@718 3479
djmoffat@718 3480 // Sets one value
djmoffat@718 3481 } else if ( value !== undefined ) {
djmoffat@718 3482 chainable = true;
djmoffat@718 3483
djmoffat@718 3484 if ( !jQuery.isFunction( value ) ) {
djmoffat@718 3485 raw = true;
djmoffat@718 3486 }
djmoffat@718 3487
djmoffat@718 3488 if ( bulk ) {
djmoffat@718 3489 // Bulk operations run against the entire set
djmoffat@718 3490 if ( raw ) {
djmoffat@718 3491 fn.call( elems, value );
djmoffat@718 3492 fn = null;
djmoffat@718 3493
djmoffat@718 3494 // ...except when executing function values
djmoffat@718 3495 } else {
djmoffat@718 3496 bulk = fn;
djmoffat@718 3497 fn = function( elem, key, value ) {
djmoffat@718 3498 return bulk.call( jQuery( elem ), value );
djmoffat@718 3499 };
djmoffat@718 3500 }
djmoffat@718 3501 }
djmoffat@718 3502
djmoffat@718 3503 if ( fn ) {
djmoffat@718 3504 for ( ; i < len; i++ ) {
djmoffat@718 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
djmoffat@718 3506 }
djmoffat@718 3507 }
djmoffat@718 3508 }
djmoffat@718 3509
djmoffat@718 3510 return chainable ?
djmoffat@718 3511 elems :
djmoffat@718 3512
djmoffat@718 3513 // Gets
djmoffat@718 3514 bulk ?
djmoffat@718 3515 fn.call( elems ) :
djmoffat@718 3516 len ? fn( elems[0], key ) : emptyGet;
djmoffat@718 3517 };
djmoffat@718 3518
djmoffat@718 3519
djmoffat@718 3520 /**
djmoffat@718 3521 * Determines whether an object can have data
djmoffat@718 3522 */
djmoffat@718 3523 jQuery.acceptData = function( owner ) {
djmoffat@718 3524 // Accepts only:
djmoffat@718 3525 // - Node
djmoffat@718 3526 // - Node.ELEMENT_NODE
djmoffat@718 3527 // - Node.DOCUMENT_NODE
djmoffat@718 3528 // - Object
djmoffat@718 3529 // - Any
djmoffat@718 3530 /* jshint -W018 */
djmoffat@718 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
djmoffat@718 3532 };
djmoffat@718 3533
djmoffat@718 3534
djmoffat@718 3535 function Data() {
djmoffat@718 3536 // Support: Android<4,
djmoffat@718 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
djmoffat@718 3538 // return new empty object instead with no [[set]] accessor
djmoffat@718 3539 Object.defineProperty( this.cache = {}, 0, {
djmoffat@718 3540 get: function() {
djmoffat@718 3541 return {};
djmoffat@718 3542 }
djmoffat@718 3543 });
djmoffat@718 3544
djmoffat@718 3545 this.expando = jQuery.expando + Data.uid++;
djmoffat@718 3546 }
djmoffat@718 3547
djmoffat@718 3548 Data.uid = 1;
djmoffat@718 3549 Data.accepts = jQuery.acceptData;
djmoffat@718 3550
djmoffat@718 3551 Data.prototype = {
djmoffat@718 3552 key: function( owner ) {
djmoffat@718 3553 // We can accept data for non-element nodes in modern browsers,
djmoffat@718 3554 // but we should not, see #8335.
djmoffat@718 3555 // Always return the key for a frozen object.
djmoffat@718 3556 if ( !Data.accepts( owner ) ) {
djmoffat@718 3557 return 0;
djmoffat@718 3558 }
djmoffat@718 3559
djmoffat@718 3560 var descriptor = {},
djmoffat@718 3561 // Check if the owner object already has a cache key
djmoffat@718 3562 unlock = owner[ this.expando ];
djmoffat@718 3563
djmoffat@718 3564 // If not, create one
djmoffat@718 3565 if ( !unlock ) {
djmoffat@718 3566 unlock = Data.uid++;
djmoffat@718 3567
djmoffat@718 3568 // Secure it in a non-enumerable, non-writable property
djmoffat@718 3569 try {
djmoffat@718 3570 descriptor[ this.expando ] = { value: unlock };
djmoffat@718 3571 Object.defineProperties( owner, descriptor );
djmoffat@718 3572
djmoffat@718 3573 // Support: Android<4
djmoffat@718 3574 // Fallback to a less secure definition
djmoffat@718 3575 } catch ( e ) {
djmoffat@718 3576 descriptor[ this.expando ] = unlock;
djmoffat@718 3577 jQuery.extend( owner, descriptor );
djmoffat@718 3578 }
djmoffat@718 3579 }
djmoffat@718 3580
djmoffat@718 3581 // Ensure the cache object
djmoffat@718 3582 if ( !this.cache[ unlock ] ) {
djmoffat@718 3583 this.cache[ unlock ] = {};
djmoffat@718 3584 }
djmoffat@718 3585
djmoffat@718 3586 return unlock;
djmoffat@718 3587 },
djmoffat@718 3588 set: function( owner, data, value ) {
djmoffat@718 3589 var prop,
djmoffat@718 3590 // There may be an unlock assigned to this node,
djmoffat@718 3591 // if there is no entry for this "owner", create one inline
djmoffat@718 3592 // and set the unlock as though an owner entry had always existed
djmoffat@718 3593 unlock = this.key( owner ),
djmoffat@718 3594 cache = this.cache[ unlock ];
djmoffat@718 3595
djmoffat@718 3596 // Handle: [ owner, key, value ] args
djmoffat@718 3597 if ( typeof data === "string" ) {
djmoffat@718 3598 cache[ data ] = value;
djmoffat@718 3599
djmoffat@718 3600 // Handle: [ owner, { properties } ] args
djmoffat@718 3601 } else {
djmoffat@718 3602 // Fresh assignments by object are shallow copied
djmoffat@718 3603 if ( jQuery.isEmptyObject( cache ) ) {
djmoffat@718 3604 jQuery.extend( this.cache[ unlock ], data );
djmoffat@718 3605 // Otherwise, copy the properties one-by-one to the cache object
djmoffat@718 3606 } else {
djmoffat@718 3607 for ( prop in data ) {
djmoffat@718 3608 cache[ prop ] = data[ prop ];
djmoffat@718 3609 }
djmoffat@718 3610 }
djmoffat@718 3611 }
djmoffat@718 3612 return cache;
djmoffat@718 3613 },
djmoffat@718 3614 get: function( owner, key ) {
djmoffat@718 3615 // Either a valid cache is found, or will be created.
djmoffat@718 3616 // New caches will be created and the unlock returned,
djmoffat@718 3617 // allowing direct access to the newly created
djmoffat@718 3618 // empty data object. A valid owner object must be provided.
djmoffat@718 3619 var cache = this.cache[ this.key( owner ) ];
djmoffat@718 3620
djmoffat@718 3621 return key === undefined ?
djmoffat@718 3622 cache : cache[ key ];
djmoffat@718 3623 },
djmoffat@718 3624 access: function( owner, key, value ) {
djmoffat@718 3625 var stored;
djmoffat@718 3626 // In cases where either:
djmoffat@718 3627 //
djmoffat@718 3628 // 1. No key was specified
djmoffat@718 3629 // 2. A string key was specified, but no value provided
djmoffat@718 3630 //
djmoffat@718 3631 // Take the "read" path and allow the get method to determine
djmoffat@718 3632 // which value to return, respectively either:
djmoffat@718 3633 //
djmoffat@718 3634 // 1. The entire cache object
djmoffat@718 3635 // 2. The data stored at the key
djmoffat@718 3636 //
djmoffat@718 3637 if ( key === undefined ||
djmoffat@718 3638 ((key && typeof key === "string") && value === undefined) ) {
djmoffat@718 3639
djmoffat@718 3640 stored = this.get( owner, key );
djmoffat@718 3641
djmoffat@718 3642 return stored !== undefined ?
djmoffat@718 3643 stored : this.get( owner, jQuery.camelCase(key) );
djmoffat@718 3644 }
djmoffat@718 3645
djmoffat@718 3646 // [*]When the key is not a string, or both a key and value
djmoffat@718 3647 // are specified, set or extend (existing objects) with either:
djmoffat@718 3648 //
djmoffat@718 3649 // 1. An object of properties
djmoffat@718 3650 // 2. A key and value
djmoffat@718 3651 //
djmoffat@718 3652 this.set( owner, key, value );
djmoffat@718 3653
djmoffat@718 3654 // Since the "set" path can have two possible entry points
djmoffat@718 3655 // return the expected data based on which path was taken[*]
djmoffat@718 3656 return value !== undefined ? value : key;
djmoffat@718 3657 },
djmoffat@718 3658 remove: function( owner, key ) {
djmoffat@718 3659 var i, name, camel,
djmoffat@718 3660 unlock = this.key( owner ),
djmoffat@718 3661 cache = this.cache[ unlock ];
djmoffat@718 3662
djmoffat@718 3663 if ( key === undefined ) {
djmoffat@718 3664 this.cache[ unlock ] = {};
djmoffat@718 3665
djmoffat@718 3666 } else {
djmoffat@718 3667 // Support array or space separated string of keys
djmoffat@718 3668 if ( jQuery.isArray( key ) ) {
djmoffat@718 3669 // If "name" is an array of keys...
djmoffat@718 3670 // When data is initially created, via ("key", "val") signature,
djmoffat@718 3671 // keys will be converted to camelCase.
djmoffat@718 3672 // Since there is no way to tell _how_ a key was added, remove
djmoffat@718 3673 // both plain key and camelCase key. #12786
djmoffat@718 3674 // This will only penalize the array argument path.
djmoffat@718 3675 name = key.concat( key.map( jQuery.camelCase ) );
djmoffat@718 3676 } else {
djmoffat@718 3677 camel = jQuery.camelCase( key );
djmoffat@718 3678 // Try the string as a key before any manipulation
djmoffat@718 3679 if ( key in cache ) {
djmoffat@718 3680 name = [ key, camel ];
djmoffat@718 3681 } else {
djmoffat@718 3682 // If a key with the spaces exists, use it.
djmoffat@718 3683 // Otherwise, create an array by matching non-whitespace
djmoffat@718 3684 name = camel;
djmoffat@718 3685 name = name in cache ?
djmoffat@718 3686 [ name ] : ( name.match( rnotwhite ) || [] );
djmoffat@718 3687 }
djmoffat@718 3688 }
djmoffat@718 3689
djmoffat@718 3690 i = name.length;
djmoffat@718 3691 while ( i-- ) {
djmoffat@718 3692 delete cache[ name[ i ] ];
djmoffat@718 3693 }
djmoffat@718 3694 }
djmoffat@718 3695 },
djmoffat@718 3696 hasData: function( owner ) {
djmoffat@718 3697 return !jQuery.isEmptyObject(
djmoffat@718 3698 this.cache[ owner[ this.expando ] ] || {}
djmoffat@718 3699 );
djmoffat@718 3700 },
djmoffat@718 3701 discard: function( owner ) {
djmoffat@718 3702 if ( owner[ this.expando ] ) {
djmoffat@718 3703 delete this.cache[ owner[ this.expando ] ];
djmoffat@718 3704 }
djmoffat@718 3705 }
djmoffat@718 3706 };
djmoffat@718 3707 var data_priv = new Data();
djmoffat@718 3708
djmoffat@718 3709 var data_user = new Data();
djmoffat@718 3710
djmoffat@718 3711
djmoffat@718 3712
djmoffat@718 3713 // Implementation Summary
djmoffat@718 3714 //
djmoffat@718 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
djmoffat@718 3716 // 2. Improve the module's maintainability by reducing the storage
djmoffat@718 3717 // paths to a single mechanism.
djmoffat@718 3718 // 3. Use the same single mechanism to support "private" and "user" data.
djmoffat@718 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
djmoffat@718 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
djmoffat@718 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
djmoffat@718 3722
djmoffat@718 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
djmoffat@718 3724 rmultiDash = /([A-Z])/g;
djmoffat@718 3725
djmoffat@718 3726 function dataAttr( elem, key, data ) {
djmoffat@718 3727 var name;
djmoffat@718 3728
djmoffat@718 3729 // If nothing was found internally, try to fetch any
djmoffat@718 3730 // data from the HTML5 data-* attribute
djmoffat@718 3731 if ( data === undefined && elem.nodeType === 1 ) {
djmoffat@718 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
djmoffat@718 3733 data = elem.getAttribute( name );
djmoffat@718 3734
djmoffat@718 3735 if ( typeof data === "string" ) {
djmoffat@718 3736 try {
djmoffat@718 3737 data = data === "true" ? true :
djmoffat@718 3738 data === "false" ? false :
djmoffat@718 3739 data === "null" ? null :
djmoffat@718 3740 // Only convert to a number if it doesn't change the string
djmoffat@718 3741 +data + "" === data ? +data :
djmoffat@718 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
djmoffat@718 3743 data;
djmoffat@718 3744 } catch( e ) {}
djmoffat@718 3745
djmoffat@718 3746 // Make sure we set the data so it isn't changed later
djmoffat@718 3747 data_user.set( elem, key, data );
djmoffat@718 3748 } else {
djmoffat@718 3749 data = undefined;
djmoffat@718 3750 }
djmoffat@718 3751 }
djmoffat@718 3752 return data;
djmoffat@718 3753 }
djmoffat@718 3754
djmoffat@718 3755 jQuery.extend({
djmoffat@718 3756 hasData: function( elem ) {
djmoffat@718 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
djmoffat@718 3758 },
djmoffat@718 3759
djmoffat@718 3760 data: function( elem, name, data ) {
djmoffat@718 3761 return data_user.access( elem, name, data );
djmoffat@718 3762 },
djmoffat@718 3763
djmoffat@718 3764 removeData: function( elem, name ) {
djmoffat@718 3765 data_user.remove( elem, name );
djmoffat@718 3766 },
djmoffat@718 3767
djmoffat@718 3768 // TODO: Now that all calls to _data and _removeData have been replaced
djmoffat@718 3769 // with direct calls to data_priv methods, these can be deprecated.
djmoffat@718 3770 _data: function( elem, name, data ) {
djmoffat@718 3771 return data_priv.access( elem, name, data );
djmoffat@718 3772 },
djmoffat@718 3773
djmoffat@718 3774 _removeData: function( elem, name ) {
djmoffat@718 3775 data_priv.remove( elem, name );
djmoffat@718 3776 }
djmoffat@718 3777 });
djmoffat@718 3778
djmoffat@718 3779 jQuery.fn.extend({
djmoffat@718 3780 data: function( key, value ) {
djmoffat@718 3781 var i, name, data,
djmoffat@718 3782 elem = this[ 0 ],
djmoffat@718 3783 attrs = elem && elem.attributes;
djmoffat@718 3784
djmoffat@718 3785 // Gets all values
djmoffat@718 3786 if ( key === undefined ) {
djmoffat@718 3787 if ( this.length ) {
djmoffat@718 3788 data = data_user.get( elem );
djmoffat@718 3789
djmoffat@718 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
djmoffat@718 3791 i = attrs.length;
djmoffat@718 3792 while ( i-- ) {
djmoffat@718 3793
djmoffat@718 3794 // Support: IE11+
djmoffat@718 3795 // The attrs elements can be null (#14894)
djmoffat@718 3796 if ( attrs[ i ] ) {
djmoffat@718 3797 name = attrs[ i ].name;
djmoffat@718 3798 if ( name.indexOf( "data-" ) === 0 ) {
djmoffat@718 3799 name = jQuery.camelCase( name.slice(5) );
djmoffat@718 3800 dataAttr( elem, name, data[ name ] );
djmoffat@718 3801 }
djmoffat@718 3802 }
djmoffat@718 3803 }
djmoffat@718 3804 data_priv.set( elem, "hasDataAttrs", true );
djmoffat@718 3805 }
djmoffat@718 3806 }
djmoffat@718 3807
djmoffat@718 3808 return data;
djmoffat@718 3809 }
djmoffat@718 3810
djmoffat@718 3811 // Sets multiple values
djmoffat@718 3812 if ( typeof key === "object" ) {
djmoffat@718 3813 return this.each(function() {
djmoffat@718 3814 data_user.set( this, key );
djmoffat@718 3815 });
djmoffat@718 3816 }
djmoffat@718 3817
djmoffat@718 3818 return access( this, function( value ) {
djmoffat@718 3819 var data,
djmoffat@718 3820 camelKey = jQuery.camelCase( key );
djmoffat@718 3821
djmoffat@718 3822 // The calling jQuery object (element matches) is not empty
djmoffat@718 3823 // (and therefore has an element appears at this[ 0 ]) and the
djmoffat@718 3824 // `value` parameter was not undefined. An empty jQuery object
djmoffat@718 3825 // will result in `undefined` for elem = this[ 0 ] which will
djmoffat@718 3826 // throw an exception if an attempt to read a data cache is made.
djmoffat@718 3827 if ( elem && value === undefined ) {
djmoffat@718 3828 // Attempt to get data from the cache
djmoffat@718 3829 // with the key as-is
djmoffat@718 3830 data = data_user.get( elem, key );
djmoffat@718 3831 if ( data !== undefined ) {
djmoffat@718 3832 return data;
djmoffat@718 3833 }
djmoffat@718 3834
djmoffat@718 3835 // Attempt to get data from the cache
djmoffat@718 3836 // with the key camelized
djmoffat@718 3837 data = data_user.get( elem, camelKey );
djmoffat@718 3838 if ( data !== undefined ) {
djmoffat@718 3839 return data;
djmoffat@718 3840 }
djmoffat@718 3841
djmoffat@718 3842 // Attempt to "discover" the data in
djmoffat@718 3843 // HTML5 custom data-* attrs
djmoffat@718 3844 data = dataAttr( elem, camelKey, undefined );
djmoffat@718 3845 if ( data !== undefined ) {
djmoffat@718 3846 return data;
djmoffat@718 3847 }
djmoffat@718 3848
djmoffat@718 3849 // We tried really hard, but the data doesn't exist.
djmoffat@718 3850 return;
djmoffat@718 3851 }
djmoffat@718 3852
djmoffat@718 3853 // Set the data...
djmoffat@718 3854 this.each(function() {
djmoffat@718 3855 // First, attempt to store a copy or reference of any
djmoffat@718 3856 // data that might've been store with a camelCased key.
djmoffat@718 3857 var data = data_user.get( this, camelKey );
djmoffat@718 3858
djmoffat@718 3859 // For HTML5 data-* attribute interop, we have to
djmoffat@718 3860 // store property names with dashes in a camelCase form.
djmoffat@718 3861 // This might not apply to all properties...*
djmoffat@718 3862 data_user.set( this, camelKey, value );
djmoffat@718 3863
djmoffat@718 3864 // *... In the case of properties that might _actually_
djmoffat@718 3865 // have dashes, we need to also store a copy of that
djmoffat@718 3866 // unchanged property.
djmoffat@718 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
djmoffat@718 3868 data_user.set( this, key, value );
djmoffat@718 3869 }
djmoffat@718 3870 });
djmoffat@718 3871 }, null, value, arguments.length > 1, null, true );
djmoffat@718 3872 },
djmoffat@718 3873
djmoffat@718 3874 removeData: function( key ) {
djmoffat@718 3875 return this.each(function() {
djmoffat@718 3876 data_user.remove( this, key );
djmoffat@718 3877 });
djmoffat@718 3878 }
djmoffat@718 3879 });
djmoffat@718 3880
djmoffat@718 3881
djmoffat@718 3882 jQuery.extend({
djmoffat@718 3883 queue: function( elem, type, data ) {
djmoffat@718 3884 var queue;
djmoffat@718 3885
djmoffat@718 3886 if ( elem ) {
djmoffat@718 3887 type = ( type || "fx" ) + "queue";
djmoffat@718 3888 queue = data_priv.get( elem, type );
djmoffat@718 3889
djmoffat@718 3890 // Speed up dequeue by getting out quickly if this is just a lookup
djmoffat@718 3891 if ( data ) {
djmoffat@718 3892 if ( !queue || jQuery.isArray( data ) ) {
djmoffat@718 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
djmoffat@718 3894 } else {
djmoffat@718 3895 queue.push( data );
djmoffat@718 3896 }
djmoffat@718 3897 }
djmoffat@718 3898 return queue || [];
djmoffat@718 3899 }
djmoffat@718 3900 },
djmoffat@718 3901
djmoffat@718 3902 dequeue: function( elem, type ) {
djmoffat@718 3903 type = type || "fx";
djmoffat@718 3904
djmoffat@718 3905 var queue = jQuery.queue( elem, type ),
djmoffat@718 3906 startLength = queue.length,
djmoffat@718 3907 fn = queue.shift(),
djmoffat@718 3908 hooks = jQuery._queueHooks( elem, type ),
djmoffat@718 3909 next = function() {
djmoffat@718 3910 jQuery.dequeue( elem, type );
djmoffat@718 3911 };
djmoffat@718 3912
djmoffat@718 3913 // If the fx queue is dequeued, always remove the progress sentinel
djmoffat@718 3914 if ( fn === "inprogress" ) {
djmoffat@718 3915 fn = queue.shift();
djmoffat@718 3916 startLength--;
djmoffat@718 3917 }
djmoffat@718 3918
djmoffat@718 3919 if ( fn ) {
djmoffat@718 3920
djmoffat@718 3921 // Add a progress sentinel to prevent the fx queue from being
djmoffat@718 3922 // automatically dequeued
djmoffat@718 3923 if ( type === "fx" ) {
djmoffat@718 3924 queue.unshift( "inprogress" );
djmoffat@718 3925 }
djmoffat@718 3926
djmoffat@718 3927 // Clear up the last queue stop function
djmoffat@718 3928 delete hooks.stop;
djmoffat@718 3929 fn.call( elem, next, hooks );
djmoffat@718 3930 }
djmoffat@718 3931
djmoffat@718 3932 if ( !startLength && hooks ) {
djmoffat@718 3933 hooks.empty.fire();
djmoffat@718 3934 }
djmoffat@718 3935 },
djmoffat@718 3936
djmoffat@718 3937 // Not public - generate a queueHooks object, or return the current one
djmoffat@718 3938 _queueHooks: function( elem, type ) {
djmoffat@718 3939 var key = type + "queueHooks";
djmoffat@718 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
djmoffat@718 3941 empty: jQuery.Callbacks("once memory").add(function() {
djmoffat@718 3942 data_priv.remove( elem, [ type + "queue", key ] );
djmoffat@718 3943 })
djmoffat@718 3944 });
djmoffat@718 3945 }
djmoffat@718 3946 });
djmoffat@718 3947
djmoffat@718 3948 jQuery.fn.extend({
djmoffat@718 3949 queue: function( type, data ) {
djmoffat@718 3950 var setter = 2;
djmoffat@718 3951
djmoffat@718 3952 if ( typeof type !== "string" ) {
djmoffat@718 3953 data = type;
djmoffat@718 3954 type = "fx";
djmoffat@718 3955 setter--;
djmoffat@718 3956 }
djmoffat@718 3957
djmoffat@718 3958 if ( arguments.length < setter ) {
djmoffat@718 3959 return jQuery.queue( this[0], type );
djmoffat@718 3960 }
djmoffat@718 3961
djmoffat@718 3962 return data === undefined ?
djmoffat@718 3963 this :
djmoffat@718 3964 this.each(function() {
djmoffat@718 3965 var queue = jQuery.queue( this, type, data );
djmoffat@718 3966
djmoffat@718 3967 // Ensure a hooks for this queue
djmoffat@718 3968 jQuery._queueHooks( this, type );
djmoffat@718 3969
djmoffat@718 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
djmoffat@718 3971 jQuery.dequeue( this, type );
djmoffat@718 3972 }
djmoffat@718 3973 });
djmoffat@718 3974 },
djmoffat@718 3975 dequeue: function( type ) {
djmoffat@718 3976 return this.each(function() {
djmoffat@718 3977 jQuery.dequeue( this, type );
djmoffat@718 3978 });
djmoffat@718 3979 },
djmoffat@718 3980 clearQueue: function( type ) {
djmoffat@718 3981 return this.queue( type || "fx", [] );
djmoffat@718 3982 },
djmoffat@718 3983 // Get a promise resolved when queues of a certain type
djmoffat@718 3984 // are emptied (fx is the type by default)
djmoffat@718 3985 promise: function( type, obj ) {
djmoffat@718 3986 var tmp,
djmoffat@718 3987 count = 1,
djmoffat@718 3988 defer = jQuery.Deferred(),
djmoffat@718 3989 elements = this,
djmoffat@718 3990 i = this.length,
djmoffat@718 3991 resolve = function() {
djmoffat@718 3992 if ( !( --count ) ) {
djmoffat@718 3993 defer.resolveWith( elements, [ elements ] );
djmoffat@718 3994 }
djmoffat@718 3995 };
djmoffat@718 3996
djmoffat@718 3997 if ( typeof type !== "string" ) {
djmoffat@718 3998 obj = type;
djmoffat@718 3999 type = undefined;
djmoffat@718 4000 }
djmoffat@718 4001 type = type || "fx";
djmoffat@718 4002
djmoffat@718 4003 while ( i-- ) {
djmoffat@718 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
djmoffat@718 4005 if ( tmp && tmp.empty ) {
djmoffat@718 4006 count++;
djmoffat@718 4007 tmp.empty.add( resolve );
djmoffat@718 4008 }
djmoffat@718 4009 }
djmoffat@718 4010 resolve();
djmoffat@718 4011 return defer.promise( obj );
djmoffat@718 4012 }
djmoffat@718 4013 });
djmoffat@718 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
djmoffat@718 4015
djmoffat@718 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
djmoffat@718 4017
djmoffat@718 4018 var isHidden = function( elem, el ) {
djmoffat@718 4019 // isHidden might be called from jQuery#filter function;
djmoffat@718 4020 // in that case, element will be second argument
djmoffat@718 4021 elem = el || elem;
djmoffat@718 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
djmoffat@718 4023 };
djmoffat@718 4024
djmoffat@718 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
djmoffat@718 4026
djmoffat@718 4027
djmoffat@718 4028
djmoffat@718 4029 (function() {
djmoffat@718 4030 var fragment = document.createDocumentFragment(),
djmoffat@718 4031 div = fragment.appendChild( document.createElement( "div" ) ),
djmoffat@718 4032 input = document.createElement( "input" );
djmoffat@718 4033
djmoffat@718 4034 // Support: Safari<=5.1
djmoffat@718 4035 // Check state lost if the name is set (#11217)
djmoffat@718 4036 // Support: Windows Web Apps (WWA)
djmoffat@718 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
djmoffat@718 4038 input.setAttribute( "type", "radio" );
djmoffat@718 4039 input.setAttribute( "checked", "checked" );
djmoffat@718 4040 input.setAttribute( "name", "t" );
djmoffat@718 4041
djmoffat@718 4042 div.appendChild( input );
djmoffat@718 4043
djmoffat@718 4044 // Support: Safari<=5.1, Android<4.2
djmoffat@718 4045 // Older WebKit doesn't clone checked state correctly in fragments
djmoffat@718 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
djmoffat@718 4047
djmoffat@718 4048 // Support: IE<=11+
djmoffat@718 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
djmoffat@718 4050 div.innerHTML = "<textarea>x</textarea>";
djmoffat@718 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
djmoffat@718 4052 })();
djmoffat@718 4053 var strundefined = typeof undefined;
djmoffat@718 4054
djmoffat@718 4055
djmoffat@718 4056
djmoffat@718 4057 support.focusinBubbles = "onfocusin" in window;
djmoffat@718 4058
djmoffat@718 4059
djmoffat@718 4060 var
djmoffat@718 4061 rkeyEvent = /^key/,
djmoffat@718 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
djmoffat@718 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
djmoffat@718 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
djmoffat@718 4065
djmoffat@718 4066 function returnTrue() {
djmoffat@718 4067 return true;
djmoffat@718 4068 }
djmoffat@718 4069
djmoffat@718 4070 function returnFalse() {
djmoffat@718 4071 return false;
djmoffat@718 4072 }
djmoffat@718 4073
djmoffat@718 4074 function safeActiveElement() {
djmoffat@718 4075 try {
djmoffat@718 4076 return document.activeElement;
djmoffat@718 4077 } catch ( err ) { }
djmoffat@718 4078 }
djmoffat@718 4079
djmoffat@718 4080 /*
djmoffat@718 4081 * Helper functions for managing events -- not part of the public interface.
djmoffat@718 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
djmoffat@718 4083 */
djmoffat@718 4084 jQuery.event = {
djmoffat@718 4085
djmoffat@718 4086 global: {},
djmoffat@718 4087
djmoffat@718 4088 add: function( elem, types, handler, data, selector ) {
djmoffat@718 4089
djmoffat@718 4090 var handleObjIn, eventHandle, tmp,
djmoffat@718 4091 events, t, handleObj,
djmoffat@718 4092 special, handlers, type, namespaces, origType,
djmoffat@718 4093 elemData = data_priv.get( elem );
djmoffat@718 4094
djmoffat@718 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
djmoffat@718 4096 if ( !elemData ) {
djmoffat@718 4097 return;
djmoffat@718 4098 }
djmoffat@718 4099
djmoffat@718 4100 // Caller can pass in an object of custom data in lieu of the handler
djmoffat@718 4101 if ( handler.handler ) {
djmoffat@718 4102 handleObjIn = handler;
djmoffat@718 4103 handler = handleObjIn.handler;
djmoffat@718 4104 selector = handleObjIn.selector;
djmoffat@718 4105 }
djmoffat@718 4106
djmoffat@718 4107 // Make sure that the handler has a unique ID, used to find/remove it later
djmoffat@718 4108 if ( !handler.guid ) {
djmoffat@718 4109 handler.guid = jQuery.guid++;
djmoffat@718 4110 }
djmoffat@718 4111
djmoffat@718 4112 // Init the element's event structure and main handler, if this is the first
djmoffat@718 4113 if ( !(events = elemData.events) ) {
djmoffat@718 4114 events = elemData.events = {};
djmoffat@718 4115 }
djmoffat@718 4116 if ( !(eventHandle = elemData.handle) ) {
djmoffat@718 4117 eventHandle = elemData.handle = function( e ) {
djmoffat@718 4118 // Discard the second event of a jQuery.event.trigger() and
djmoffat@718 4119 // when an event is called after a page has unloaded
djmoffat@718 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
djmoffat@718 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
djmoffat@718 4122 };
djmoffat@718 4123 }
djmoffat@718 4124
djmoffat@718 4125 // Handle multiple events separated by a space
djmoffat@718 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
djmoffat@718 4127 t = types.length;
djmoffat@718 4128 while ( t-- ) {
djmoffat@718 4129 tmp = rtypenamespace.exec( types[t] ) || [];
djmoffat@718 4130 type = origType = tmp[1];
djmoffat@718 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
djmoffat@718 4132
djmoffat@718 4133 // There *must* be a type, no attaching namespace-only handlers
djmoffat@718 4134 if ( !type ) {
djmoffat@718 4135 continue;
djmoffat@718 4136 }
djmoffat@718 4137
djmoffat@718 4138 // If event changes its type, use the special event handlers for the changed type
djmoffat@718 4139 special = jQuery.event.special[ type ] || {};
djmoffat@718 4140
djmoffat@718 4141 // If selector defined, determine special event api type, otherwise given type
djmoffat@718 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
djmoffat@718 4143
djmoffat@718 4144 // Update special based on newly reset type
djmoffat@718 4145 special = jQuery.event.special[ type ] || {};
djmoffat@718 4146
djmoffat@718 4147 // handleObj is passed to all event handlers
djmoffat@718 4148 handleObj = jQuery.extend({
djmoffat@718 4149 type: type,
djmoffat@718 4150 origType: origType,
djmoffat@718 4151 data: data,
djmoffat@718 4152 handler: handler,
djmoffat@718 4153 guid: handler.guid,
djmoffat@718 4154 selector: selector,
djmoffat@718 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
djmoffat@718 4156 namespace: namespaces.join(".")
djmoffat@718 4157 }, handleObjIn );
djmoffat@718 4158
djmoffat@718 4159 // Init the event handler queue if we're the first
djmoffat@718 4160 if ( !(handlers = events[ type ]) ) {
djmoffat@718 4161 handlers = events[ type ] = [];
djmoffat@718 4162 handlers.delegateCount = 0;
djmoffat@718 4163
djmoffat@718 4164 // Only use addEventListener if the special events handler returns false
djmoffat@718 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
djmoffat@718 4166 if ( elem.addEventListener ) {
djmoffat@718 4167 elem.addEventListener( type, eventHandle, false );
djmoffat@718 4168 }
djmoffat@718 4169 }
djmoffat@718 4170 }
djmoffat@718 4171
djmoffat@718 4172 if ( special.add ) {
djmoffat@718 4173 special.add.call( elem, handleObj );
djmoffat@718 4174
djmoffat@718 4175 if ( !handleObj.handler.guid ) {
djmoffat@718 4176 handleObj.handler.guid = handler.guid;
djmoffat@718 4177 }
djmoffat@718 4178 }
djmoffat@718 4179
djmoffat@718 4180 // Add to the element's handler list, delegates in front
djmoffat@718 4181 if ( selector ) {
djmoffat@718 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
djmoffat@718 4183 } else {
djmoffat@718 4184 handlers.push( handleObj );
djmoffat@718 4185 }
djmoffat@718 4186
djmoffat@718 4187 // Keep track of which events have ever been used, for event optimization
djmoffat@718 4188 jQuery.event.global[ type ] = true;
djmoffat@718 4189 }
djmoffat@718 4190
djmoffat@718 4191 },
djmoffat@718 4192
djmoffat@718 4193 // Detach an event or set of events from an element
djmoffat@718 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
djmoffat@718 4195
djmoffat@718 4196 var j, origCount, tmp,
djmoffat@718 4197 events, t, handleObj,
djmoffat@718 4198 special, handlers, type, namespaces, origType,
djmoffat@718 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
djmoffat@718 4200
djmoffat@718 4201 if ( !elemData || !(events = elemData.events) ) {
djmoffat@718 4202 return;
djmoffat@718 4203 }
djmoffat@718 4204
djmoffat@718 4205 // Once for each type.namespace in types; type may be omitted
djmoffat@718 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
djmoffat@718 4207 t = types.length;
djmoffat@718 4208 while ( t-- ) {
djmoffat@718 4209 tmp = rtypenamespace.exec( types[t] ) || [];
djmoffat@718 4210 type = origType = tmp[1];
djmoffat@718 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
djmoffat@718 4212
djmoffat@718 4213 // Unbind all events (on this namespace, if provided) for the element
djmoffat@718 4214 if ( !type ) {
djmoffat@718 4215 for ( type in events ) {
djmoffat@718 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
djmoffat@718 4217 }
djmoffat@718 4218 continue;
djmoffat@718 4219 }
djmoffat@718 4220
djmoffat@718 4221 special = jQuery.event.special[ type ] || {};
djmoffat@718 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
djmoffat@718 4223 handlers = events[ type ] || [];
djmoffat@718 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
djmoffat@718 4225
djmoffat@718 4226 // Remove matching events
djmoffat@718 4227 origCount = j = handlers.length;
djmoffat@718 4228 while ( j-- ) {
djmoffat@718 4229 handleObj = handlers[ j ];
djmoffat@718 4230
djmoffat@718 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
djmoffat@718 4232 ( !handler || handler.guid === handleObj.guid ) &&
djmoffat@718 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
djmoffat@718 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
djmoffat@718 4235 handlers.splice( j, 1 );
djmoffat@718 4236
djmoffat@718 4237 if ( handleObj.selector ) {
djmoffat@718 4238 handlers.delegateCount--;
djmoffat@718 4239 }
djmoffat@718 4240 if ( special.remove ) {
djmoffat@718 4241 special.remove.call( elem, handleObj );
djmoffat@718 4242 }
djmoffat@718 4243 }
djmoffat@718 4244 }
djmoffat@718 4245
djmoffat@718 4246 // Remove generic event handler if we removed something and no more handlers exist
djmoffat@718 4247 // (avoids potential for endless recursion during removal of special event handlers)
djmoffat@718 4248 if ( origCount && !handlers.length ) {
djmoffat@718 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
djmoffat@718 4250 jQuery.removeEvent( elem, type, elemData.handle );
djmoffat@718 4251 }
djmoffat@718 4252
djmoffat@718 4253 delete events[ type ];
djmoffat@718 4254 }
djmoffat@718 4255 }
djmoffat@718 4256
djmoffat@718 4257 // Remove the expando if it's no longer used
djmoffat@718 4258 if ( jQuery.isEmptyObject( events ) ) {
djmoffat@718 4259 delete elemData.handle;
djmoffat@718 4260 data_priv.remove( elem, "events" );
djmoffat@718 4261 }
djmoffat@718 4262 },
djmoffat@718 4263
djmoffat@718 4264 trigger: function( event, data, elem, onlyHandlers ) {
djmoffat@718 4265
djmoffat@718 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
djmoffat@718 4267 eventPath = [ elem || document ],
djmoffat@718 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
djmoffat@718 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
djmoffat@718 4270
djmoffat@718 4271 cur = tmp = elem = elem || document;
djmoffat@718 4272
djmoffat@718 4273 // Don't do events on text and comment nodes
djmoffat@718 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
djmoffat@718 4275 return;
djmoffat@718 4276 }
djmoffat@718 4277
djmoffat@718 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
djmoffat@718 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
djmoffat@718 4280 return;
djmoffat@718 4281 }
djmoffat@718 4282
djmoffat@718 4283 if ( type.indexOf(".") >= 0 ) {
djmoffat@718 4284 // Namespaced trigger; create a regexp to match event type in handle()
djmoffat@718 4285 namespaces = type.split(".");
djmoffat@718 4286 type = namespaces.shift();
djmoffat@718 4287 namespaces.sort();
djmoffat@718 4288 }
djmoffat@718 4289 ontype = type.indexOf(":") < 0 && "on" + type;
djmoffat@718 4290
djmoffat@718 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
djmoffat@718 4292 event = event[ jQuery.expando ] ?
djmoffat@718 4293 event :
djmoffat@718 4294 new jQuery.Event( type, typeof event === "object" && event );
djmoffat@718 4295
djmoffat@718 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
djmoffat@718 4297 event.isTrigger = onlyHandlers ? 2 : 3;
djmoffat@718 4298 event.namespace = namespaces.join(".");
djmoffat@718 4299 event.namespace_re = event.namespace ?
djmoffat@718 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
djmoffat@718 4301 null;
djmoffat@718 4302
djmoffat@718 4303 // Clean up the event in case it is being reused
djmoffat@718 4304 event.result = undefined;
djmoffat@718 4305 if ( !event.target ) {
djmoffat@718 4306 event.target = elem;
djmoffat@718 4307 }
djmoffat@718 4308
djmoffat@718 4309 // Clone any incoming data and prepend the event, creating the handler arg list
djmoffat@718 4310 data = data == null ?
djmoffat@718 4311 [ event ] :
djmoffat@718 4312 jQuery.makeArray( data, [ event ] );
djmoffat@718 4313
djmoffat@718 4314 // Allow special events to draw outside the lines
djmoffat@718 4315 special = jQuery.event.special[ type ] || {};
djmoffat@718 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
djmoffat@718 4317 return;
djmoffat@718 4318 }
djmoffat@718 4319
djmoffat@718 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
djmoffat@718 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
djmoffat@718 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
djmoffat@718 4323
djmoffat@718 4324 bubbleType = special.delegateType || type;
djmoffat@718 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
djmoffat@718 4326 cur = cur.parentNode;
djmoffat@718 4327 }
djmoffat@718 4328 for ( ; cur; cur = cur.parentNode ) {
djmoffat@718 4329 eventPath.push( cur );
djmoffat@718 4330 tmp = cur;
djmoffat@718 4331 }
djmoffat@718 4332
djmoffat@718 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
djmoffat@718 4334 if ( tmp === (elem.ownerDocument || document) ) {
djmoffat@718 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
djmoffat@718 4336 }
djmoffat@718 4337 }
djmoffat@718 4338
djmoffat@718 4339 // Fire handlers on the event path
djmoffat@718 4340 i = 0;
djmoffat@718 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
djmoffat@718 4342
djmoffat@718 4343 event.type = i > 1 ?
djmoffat@718 4344 bubbleType :
djmoffat@718 4345 special.bindType || type;
djmoffat@718 4346
djmoffat@718 4347 // jQuery handler
djmoffat@718 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
djmoffat@718 4349 if ( handle ) {
djmoffat@718 4350 handle.apply( cur, data );
djmoffat@718 4351 }
djmoffat@718 4352
djmoffat@718 4353 // Native handler
djmoffat@718 4354 handle = ontype && cur[ ontype ];
djmoffat@718 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
djmoffat@718 4356 event.result = handle.apply( cur, data );
djmoffat@718 4357 if ( event.result === false ) {
djmoffat@718 4358 event.preventDefault();
djmoffat@718 4359 }
djmoffat@718 4360 }
djmoffat@718 4361 }
djmoffat@718 4362 event.type = type;
djmoffat@718 4363
djmoffat@718 4364 // If nobody prevented the default action, do it now
djmoffat@718 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
djmoffat@718 4366
djmoffat@718 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
djmoffat@718 4368 jQuery.acceptData( elem ) ) {
djmoffat@718 4369
djmoffat@718 4370 // Call a native DOM method on the target with the same name name as the event.
djmoffat@718 4371 // Don't do default actions on window, that's where global variables be (#6170)
djmoffat@718 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
djmoffat@718 4373
djmoffat@718 4374 // Don't re-trigger an onFOO event when we call its FOO() method
djmoffat@718 4375 tmp = elem[ ontype ];
djmoffat@718 4376
djmoffat@718 4377 if ( tmp ) {
djmoffat@718 4378 elem[ ontype ] = null;
djmoffat@718 4379 }
djmoffat@718 4380
djmoffat@718 4381 // Prevent re-triggering of the same event, since we already bubbled it above
djmoffat@718 4382 jQuery.event.triggered = type;
djmoffat@718 4383 elem[ type ]();
djmoffat@718 4384 jQuery.event.triggered = undefined;
djmoffat@718 4385
djmoffat@718 4386 if ( tmp ) {
djmoffat@718 4387 elem[ ontype ] = tmp;
djmoffat@718 4388 }
djmoffat@718 4389 }
djmoffat@718 4390 }
djmoffat@718 4391 }
djmoffat@718 4392
djmoffat@718 4393 return event.result;
djmoffat@718 4394 },
djmoffat@718 4395
djmoffat@718 4396 dispatch: function( event ) {
djmoffat@718 4397
djmoffat@718 4398 // Make a writable jQuery.Event from the native event object
djmoffat@718 4399 event = jQuery.event.fix( event );
djmoffat@718 4400
djmoffat@718 4401 var i, j, ret, matched, handleObj,
djmoffat@718 4402 handlerQueue = [],
djmoffat@718 4403 args = slice.call( arguments ),
djmoffat@718 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
djmoffat@718 4405 special = jQuery.event.special[ event.type ] || {};
djmoffat@718 4406
djmoffat@718 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
djmoffat@718 4408 args[0] = event;
djmoffat@718 4409 event.delegateTarget = this;
djmoffat@718 4410
djmoffat@718 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
djmoffat@718 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
djmoffat@718 4413 return;
djmoffat@718 4414 }
djmoffat@718 4415
djmoffat@718 4416 // Determine handlers
djmoffat@718 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
djmoffat@718 4418
djmoffat@718 4419 // Run delegates first; they may want to stop propagation beneath us
djmoffat@718 4420 i = 0;
djmoffat@718 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
djmoffat@718 4422 event.currentTarget = matched.elem;
djmoffat@718 4423
djmoffat@718 4424 j = 0;
djmoffat@718 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
djmoffat@718 4426
djmoffat@718 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
djmoffat@718 4428 // a subset or equal to those in the bound event (both can have no namespace).
djmoffat@718 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
djmoffat@718 4430
djmoffat@718 4431 event.handleObj = handleObj;
djmoffat@718 4432 event.data = handleObj.data;
djmoffat@718 4433
djmoffat@718 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
djmoffat@718 4435 .apply( matched.elem, args );
djmoffat@718 4436
djmoffat@718 4437 if ( ret !== undefined ) {
djmoffat@718 4438 if ( (event.result = ret) === false ) {
djmoffat@718 4439 event.preventDefault();
djmoffat@718 4440 event.stopPropagation();
djmoffat@718 4441 }
djmoffat@718 4442 }
djmoffat@718 4443 }
djmoffat@718 4444 }
djmoffat@718 4445 }
djmoffat@718 4446
djmoffat@718 4447 // Call the postDispatch hook for the mapped type
djmoffat@718 4448 if ( special.postDispatch ) {
djmoffat@718 4449 special.postDispatch.call( this, event );
djmoffat@718 4450 }
djmoffat@718 4451
djmoffat@718 4452 return event.result;
djmoffat@718 4453 },
djmoffat@718 4454
djmoffat@718 4455 handlers: function( event, handlers ) {
djmoffat@718 4456 var i, matches, sel, handleObj,
djmoffat@718 4457 handlerQueue = [],
djmoffat@718 4458 delegateCount = handlers.delegateCount,
djmoffat@718 4459 cur = event.target;
djmoffat@718 4460
djmoffat@718 4461 // Find delegate handlers
djmoffat@718 4462 // Black-hole SVG <use> instance trees (#13180)
djmoffat@718 4463 // Avoid non-left-click bubbling in Firefox (#3861)
djmoffat@718 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
djmoffat@718 4465
djmoffat@718 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
djmoffat@718 4467
djmoffat@718 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
djmoffat@718 4469 if ( cur.disabled !== true || event.type !== "click" ) {
djmoffat@718 4470 matches = [];
djmoffat@718 4471 for ( i = 0; i < delegateCount; i++ ) {
djmoffat@718 4472 handleObj = handlers[ i ];
djmoffat@718 4473
djmoffat@718 4474 // Don't conflict with Object.prototype properties (#13203)
djmoffat@718 4475 sel = handleObj.selector + " ";
djmoffat@718 4476
djmoffat@718 4477 if ( matches[ sel ] === undefined ) {
djmoffat@718 4478 matches[ sel ] = handleObj.needsContext ?
djmoffat@718 4479 jQuery( sel, this ).index( cur ) >= 0 :
djmoffat@718 4480 jQuery.find( sel, this, null, [ cur ] ).length;
djmoffat@718 4481 }
djmoffat@718 4482 if ( matches[ sel ] ) {
djmoffat@718 4483 matches.push( handleObj );
djmoffat@718 4484 }
djmoffat@718 4485 }
djmoffat@718 4486 if ( matches.length ) {
djmoffat@718 4487 handlerQueue.push({ elem: cur, handlers: matches });
djmoffat@718 4488 }
djmoffat@718 4489 }
djmoffat@718 4490 }
djmoffat@718 4491 }
djmoffat@718 4492
djmoffat@718 4493 // Add the remaining (directly-bound) handlers
djmoffat@718 4494 if ( delegateCount < handlers.length ) {
djmoffat@718 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
djmoffat@718 4496 }
djmoffat@718 4497
djmoffat@718 4498 return handlerQueue;
djmoffat@718 4499 },
djmoffat@718 4500
djmoffat@718 4501 // Includes some event props shared by KeyEvent and MouseEvent
djmoffat@718 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
djmoffat@718 4503
djmoffat@718 4504 fixHooks: {},
djmoffat@718 4505
djmoffat@718 4506 keyHooks: {
djmoffat@718 4507 props: "char charCode key keyCode".split(" "),
djmoffat@718 4508 filter: function( event, original ) {
djmoffat@718 4509
djmoffat@718 4510 // Add which for key events
djmoffat@718 4511 if ( event.which == null ) {
djmoffat@718 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
djmoffat@718 4513 }
djmoffat@718 4514
djmoffat@718 4515 return event;
djmoffat@718 4516 }
djmoffat@718 4517 },
djmoffat@718 4518
djmoffat@718 4519 mouseHooks: {
djmoffat@718 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
djmoffat@718 4521 filter: function( event, original ) {
djmoffat@718 4522 var eventDoc, doc, body,
djmoffat@718 4523 button = original.button;
djmoffat@718 4524
djmoffat@718 4525 // Calculate pageX/Y if missing and clientX/Y available
djmoffat@718 4526 if ( event.pageX == null && original.clientX != null ) {
djmoffat@718 4527 eventDoc = event.target.ownerDocument || document;
djmoffat@718 4528 doc = eventDoc.documentElement;
djmoffat@718 4529 body = eventDoc.body;
djmoffat@718 4530
djmoffat@718 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
djmoffat@718 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
djmoffat@718 4533 }
djmoffat@718 4534
djmoffat@718 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
djmoffat@718 4536 // Note: button is not normalized, so don't use it
djmoffat@718 4537 if ( !event.which && button !== undefined ) {
djmoffat@718 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
djmoffat@718 4539 }
djmoffat@718 4540
djmoffat@718 4541 return event;
djmoffat@718 4542 }
djmoffat@718 4543 },
djmoffat@718 4544
djmoffat@718 4545 fix: function( event ) {
djmoffat@718 4546 if ( event[ jQuery.expando ] ) {
djmoffat@718 4547 return event;
djmoffat@718 4548 }
djmoffat@718 4549
djmoffat@718 4550 // Create a writable copy of the event object and normalize some properties
djmoffat@718 4551 var i, prop, copy,
djmoffat@718 4552 type = event.type,
djmoffat@718 4553 originalEvent = event,
djmoffat@718 4554 fixHook = this.fixHooks[ type ];
djmoffat@718 4555
djmoffat@718 4556 if ( !fixHook ) {
djmoffat@718 4557 this.fixHooks[ type ] = fixHook =
djmoffat@718 4558 rmouseEvent.test( type ) ? this.mouseHooks :
djmoffat@718 4559 rkeyEvent.test( type ) ? this.keyHooks :
djmoffat@718 4560 {};
djmoffat@718 4561 }
djmoffat@718 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
djmoffat@718 4563
djmoffat@718 4564 event = new jQuery.Event( originalEvent );
djmoffat@718 4565
djmoffat@718 4566 i = copy.length;
djmoffat@718 4567 while ( i-- ) {
djmoffat@718 4568 prop = copy[ i ];
djmoffat@718 4569 event[ prop ] = originalEvent[ prop ];
djmoffat@718 4570 }
djmoffat@718 4571
djmoffat@718 4572 // Support: Cordova 2.5 (WebKit) (#13255)
djmoffat@718 4573 // All events should have a target; Cordova deviceready doesn't
djmoffat@718 4574 if ( !event.target ) {
djmoffat@718 4575 event.target = document;
djmoffat@718 4576 }
djmoffat@718 4577
djmoffat@718 4578 // Support: Safari 6.0+, Chrome<28
djmoffat@718 4579 // Target should not be a text node (#504, #13143)
djmoffat@718 4580 if ( event.target.nodeType === 3 ) {
djmoffat@718 4581 event.target = event.target.parentNode;
djmoffat@718 4582 }
djmoffat@718 4583
djmoffat@718 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
djmoffat@718 4585 },
djmoffat@718 4586
djmoffat@718 4587 special: {
djmoffat@718 4588 load: {
djmoffat@718 4589 // Prevent triggered image.load events from bubbling to window.load
djmoffat@718 4590 noBubble: true
djmoffat@718 4591 },
djmoffat@718 4592 focus: {
djmoffat@718 4593 // Fire native event if possible so blur/focus sequence is correct
djmoffat@718 4594 trigger: function() {
djmoffat@718 4595 if ( this !== safeActiveElement() && this.focus ) {
djmoffat@718 4596 this.focus();
djmoffat@718 4597 return false;
djmoffat@718 4598 }
djmoffat@718 4599 },
djmoffat@718 4600 delegateType: "focusin"
djmoffat@718 4601 },
djmoffat@718 4602 blur: {
djmoffat@718 4603 trigger: function() {
djmoffat@718 4604 if ( this === safeActiveElement() && this.blur ) {
djmoffat@718 4605 this.blur();
djmoffat@718 4606 return false;
djmoffat@718 4607 }
djmoffat@718 4608 },
djmoffat@718 4609 delegateType: "focusout"
djmoffat@718 4610 },
djmoffat@718 4611 click: {
djmoffat@718 4612 // For checkbox, fire native event so checked state will be right
djmoffat@718 4613 trigger: function() {
djmoffat@718 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
djmoffat@718 4615 this.click();
djmoffat@718 4616 return false;
djmoffat@718 4617 }
djmoffat@718 4618 },
djmoffat@718 4619
djmoffat@718 4620 // For cross-browser consistency, don't fire native .click() on links
djmoffat@718 4621 _default: function( event ) {
djmoffat@718 4622 return jQuery.nodeName( event.target, "a" );
djmoffat@718 4623 }
djmoffat@718 4624 },
djmoffat@718 4625
djmoffat@718 4626 beforeunload: {
djmoffat@718 4627 postDispatch: function( event ) {
djmoffat@718 4628
djmoffat@718 4629 // Support: Firefox 20+
djmoffat@718 4630 // Firefox doesn't alert if the returnValue field is not set.
djmoffat@718 4631 if ( event.result !== undefined && event.originalEvent ) {
djmoffat@718 4632 event.originalEvent.returnValue = event.result;
djmoffat@718 4633 }
djmoffat@718 4634 }
djmoffat@718 4635 }
djmoffat@718 4636 },
djmoffat@718 4637
djmoffat@718 4638 simulate: function( type, elem, event, bubble ) {
djmoffat@718 4639 // Piggyback on a donor event to simulate a different one.
djmoffat@718 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
djmoffat@718 4641 // simulated event prevents default then we do the same on the donor.
djmoffat@718 4642 var e = jQuery.extend(
djmoffat@718 4643 new jQuery.Event(),
djmoffat@718 4644 event,
djmoffat@718 4645 {
djmoffat@718 4646 type: type,
djmoffat@718 4647 isSimulated: true,
djmoffat@718 4648 originalEvent: {}
djmoffat@718 4649 }
djmoffat@718 4650 );
djmoffat@718 4651 if ( bubble ) {
djmoffat@718 4652 jQuery.event.trigger( e, null, elem );
djmoffat@718 4653 } else {
djmoffat@718 4654 jQuery.event.dispatch.call( elem, e );
djmoffat@718 4655 }
djmoffat@718 4656 if ( e.isDefaultPrevented() ) {
djmoffat@718 4657 event.preventDefault();
djmoffat@718 4658 }
djmoffat@718 4659 }
djmoffat@718 4660 };
djmoffat@718 4661
djmoffat@718 4662 jQuery.removeEvent = function( elem, type, handle ) {
djmoffat@718 4663 if ( elem.removeEventListener ) {
djmoffat@718 4664 elem.removeEventListener( type, handle, false );
djmoffat@718 4665 }
djmoffat@718 4666 };
djmoffat@718 4667
djmoffat@718 4668 jQuery.Event = function( src, props ) {
djmoffat@718 4669 // Allow instantiation without the 'new' keyword
djmoffat@718 4670 if ( !(this instanceof jQuery.Event) ) {
djmoffat@718 4671 return new jQuery.Event( src, props );
djmoffat@718 4672 }
djmoffat@718 4673
djmoffat@718 4674 // Event object
djmoffat@718 4675 if ( src && src.type ) {
djmoffat@718 4676 this.originalEvent = src;
djmoffat@718 4677 this.type = src.type;
djmoffat@718 4678
djmoffat@718 4679 // Events bubbling up the document may have been marked as prevented
djmoffat@718 4680 // by a handler lower down the tree; reflect the correct value.
djmoffat@718 4681 this.isDefaultPrevented = src.defaultPrevented ||
djmoffat@718 4682 src.defaultPrevented === undefined &&
djmoffat@718 4683 // Support: Android<4.0
djmoffat@718 4684 src.returnValue === false ?
djmoffat@718 4685 returnTrue :
djmoffat@718 4686 returnFalse;
djmoffat@718 4687
djmoffat@718 4688 // Event type
djmoffat@718 4689 } else {
djmoffat@718 4690 this.type = src;
djmoffat@718 4691 }
djmoffat@718 4692
djmoffat@718 4693 // Put explicitly provided properties onto the event object
djmoffat@718 4694 if ( props ) {
djmoffat@718 4695 jQuery.extend( this, props );
djmoffat@718 4696 }
djmoffat@718 4697
djmoffat@718 4698 // Create a timestamp if incoming event doesn't have one
djmoffat@718 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
djmoffat@718 4700
djmoffat@718 4701 // Mark it as fixed
djmoffat@718 4702 this[ jQuery.expando ] = true;
djmoffat@718 4703 };
djmoffat@718 4704
djmoffat@718 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
djmoffat@718 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
djmoffat@718 4707 jQuery.Event.prototype = {
djmoffat@718 4708 isDefaultPrevented: returnFalse,
djmoffat@718 4709 isPropagationStopped: returnFalse,
djmoffat@718 4710 isImmediatePropagationStopped: returnFalse,
djmoffat@718 4711
djmoffat@718 4712 preventDefault: function() {
djmoffat@718 4713 var e = this.originalEvent;
djmoffat@718 4714
djmoffat@718 4715 this.isDefaultPrevented = returnTrue;
djmoffat@718 4716
djmoffat@718 4717 if ( e && e.preventDefault ) {
djmoffat@718 4718 e.preventDefault();
djmoffat@718 4719 }
djmoffat@718 4720 },
djmoffat@718 4721 stopPropagation: function() {
djmoffat@718 4722 var e = this.originalEvent;
djmoffat@718 4723
djmoffat@718 4724 this.isPropagationStopped = returnTrue;
djmoffat@718 4725
djmoffat@718 4726 if ( e && e.stopPropagation ) {
djmoffat@718 4727 e.stopPropagation();
djmoffat@718 4728 }
djmoffat@718 4729 },
djmoffat@718 4730 stopImmediatePropagation: function() {
djmoffat@718 4731 var e = this.originalEvent;
djmoffat@718 4732
djmoffat@718 4733 this.isImmediatePropagationStopped = returnTrue;
djmoffat@718 4734
djmoffat@718 4735 if ( e && e.stopImmediatePropagation ) {
djmoffat@718 4736 e.stopImmediatePropagation();
djmoffat@718 4737 }
djmoffat@718 4738
djmoffat@718 4739 this.stopPropagation();
djmoffat@718 4740 }
djmoffat@718 4741 };
djmoffat@718 4742
djmoffat@718 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
djmoffat@718 4744 // Support: Chrome 15+
djmoffat@718 4745 jQuery.each({
djmoffat@718 4746 mouseenter: "mouseover",
djmoffat@718 4747 mouseleave: "mouseout",
djmoffat@718 4748 pointerenter: "pointerover",
djmoffat@718 4749 pointerleave: "pointerout"
djmoffat@718 4750 }, function( orig, fix ) {
djmoffat@718 4751 jQuery.event.special[ orig ] = {
djmoffat@718 4752 delegateType: fix,
djmoffat@718 4753 bindType: fix,
djmoffat@718 4754
djmoffat@718 4755 handle: function( event ) {
djmoffat@718 4756 var ret,
djmoffat@718 4757 target = this,
djmoffat@718 4758 related = event.relatedTarget,
djmoffat@718 4759 handleObj = event.handleObj;
djmoffat@718 4760
djmoffat@718 4761 // For mousenter/leave call the handler if related is outside the target.
djmoffat@718 4762 // NB: No relatedTarget if the mouse left/entered the browser window
djmoffat@718 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
djmoffat@718 4764 event.type = handleObj.origType;
djmoffat@718 4765 ret = handleObj.handler.apply( this, arguments );
djmoffat@718 4766 event.type = fix;
djmoffat@718 4767 }
djmoffat@718 4768 return ret;
djmoffat@718 4769 }
djmoffat@718 4770 };
djmoffat@718 4771 });
djmoffat@718 4772
djmoffat@718 4773 // Support: Firefox, Chrome, Safari
djmoffat@718 4774 // Create "bubbling" focus and blur events
djmoffat@718 4775 if ( !support.focusinBubbles ) {
djmoffat@718 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
djmoffat@718 4777
djmoffat@718 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
djmoffat@718 4779 var handler = function( event ) {
djmoffat@718 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
djmoffat@718 4781 };
djmoffat@718 4782
djmoffat@718 4783 jQuery.event.special[ fix ] = {
djmoffat@718 4784 setup: function() {
djmoffat@718 4785 var doc = this.ownerDocument || this,
djmoffat@718 4786 attaches = data_priv.access( doc, fix );
djmoffat@718 4787
djmoffat@718 4788 if ( !attaches ) {
djmoffat@718 4789 doc.addEventListener( orig, handler, true );
djmoffat@718 4790 }
djmoffat@718 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
djmoffat@718 4792 },
djmoffat@718 4793 teardown: function() {
djmoffat@718 4794 var doc = this.ownerDocument || this,
djmoffat@718 4795 attaches = data_priv.access( doc, fix ) - 1;
djmoffat@718 4796
djmoffat@718 4797 if ( !attaches ) {
djmoffat@718 4798 doc.removeEventListener( orig, handler, true );
djmoffat@718 4799 data_priv.remove( doc, fix );
djmoffat@718 4800
djmoffat@718 4801 } else {
djmoffat@718 4802 data_priv.access( doc, fix, attaches );
djmoffat@718 4803 }
djmoffat@718 4804 }
djmoffat@718 4805 };
djmoffat@718 4806 });
djmoffat@718 4807 }
djmoffat@718 4808
djmoffat@718 4809 jQuery.fn.extend({
djmoffat@718 4810
djmoffat@718 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
djmoffat@718 4812 var origFn, type;
djmoffat@718 4813
djmoffat@718 4814 // Types can be a map of types/handlers
djmoffat@718 4815 if ( typeof types === "object" ) {
djmoffat@718 4816 // ( types-Object, selector, data )
djmoffat@718 4817 if ( typeof selector !== "string" ) {
djmoffat@718 4818 // ( types-Object, data )
djmoffat@718 4819 data = data || selector;
djmoffat@718 4820 selector = undefined;
djmoffat@718 4821 }
djmoffat@718 4822 for ( type in types ) {
djmoffat@718 4823 this.on( type, selector, data, types[ type ], one );
djmoffat@718 4824 }
djmoffat@718 4825 return this;
djmoffat@718 4826 }
djmoffat@718 4827
djmoffat@718 4828 if ( data == null && fn == null ) {
djmoffat@718 4829 // ( types, fn )
djmoffat@718 4830 fn = selector;
djmoffat@718 4831 data = selector = undefined;
djmoffat@718 4832 } else if ( fn == null ) {
djmoffat@718 4833 if ( typeof selector === "string" ) {
djmoffat@718 4834 // ( types, selector, fn )
djmoffat@718 4835 fn = data;
djmoffat@718 4836 data = undefined;
djmoffat@718 4837 } else {
djmoffat@718 4838 // ( types, data, fn )
djmoffat@718 4839 fn = data;
djmoffat@718 4840 data = selector;
djmoffat@718 4841 selector = undefined;
djmoffat@718 4842 }
djmoffat@718 4843 }
djmoffat@718 4844 if ( fn === false ) {
djmoffat@718 4845 fn = returnFalse;
djmoffat@718 4846 } else if ( !fn ) {
djmoffat@718 4847 return this;
djmoffat@718 4848 }
djmoffat@718 4849
djmoffat@718 4850 if ( one === 1 ) {
djmoffat@718 4851 origFn = fn;
djmoffat@718 4852 fn = function( event ) {
djmoffat@718 4853 // Can use an empty set, since event contains the info
djmoffat@718 4854 jQuery().off( event );
djmoffat@718 4855 return origFn.apply( this, arguments );
djmoffat@718 4856 };
djmoffat@718 4857 // Use same guid so caller can remove using origFn
djmoffat@718 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
djmoffat@718 4859 }
djmoffat@718 4860 return this.each( function() {
djmoffat@718 4861 jQuery.event.add( this, types, fn, data, selector );
djmoffat@718 4862 });
djmoffat@718 4863 },
djmoffat@718 4864 one: function( types, selector, data, fn ) {
djmoffat@718 4865 return this.on( types, selector, data, fn, 1 );
djmoffat@718 4866 },
djmoffat@718 4867 off: function( types, selector, fn ) {
djmoffat@718 4868 var handleObj, type;
djmoffat@718 4869 if ( types && types.preventDefault && types.handleObj ) {
djmoffat@718 4870 // ( event ) dispatched jQuery.Event
djmoffat@718 4871 handleObj = types.handleObj;
djmoffat@718 4872 jQuery( types.delegateTarget ).off(
djmoffat@718 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
djmoffat@718 4874 handleObj.selector,
djmoffat@718 4875 handleObj.handler
djmoffat@718 4876 );
djmoffat@718 4877 return this;
djmoffat@718 4878 }
djmoffat@718 4879 if ( typeof types === "object" ) {
djmoffat@718 4880 // ( types-object [, selector] )
djmoffat@718 4881 for ( type in types ) {
djmoffat@718 4882 this.off( type, selector, types[ type ] );
djmoffat@718 4883 }
djmoffat@718 4884 return this;
djmoffat@718 4885 }
djmoffat@718 4886 if ( selector === false || typeof selector === "function" ) {
djmoffat@718 4887 // ( types [, fn] )
djmoffat@718 4888 fn = selector;
djmoffat@718 4889 selector = undefined;
djmoffat@718 4890 }
djmoffat@718 4891 if ( fn === false ) {
djmoffat@718 4892 fn = returnFalse;
djmoffat@718 4893 }
djmoffat@718 4894 return this.each(function() {
djmoffat@718 4895 jQuery.event.remove( this, types, fn, selector );
djmoffat@718 4896 });
djmoffat@718 4897 },
djmoffat@718 4898
djmoffat@718 4899 trigger: function( type, data ) {
djmoffat@718 4900 return this.each(function() {
djmoffat@718 4901 jQuery.event.trigger( type, data, this );
djmoffat@718 4902 });
djmoffat@718 4903 },
djmoffat@718 4904 triggerHandler: function( type, data ) {
djmoffat@718 4905 var elem = this[0];
djmoffat@718 4906 if ( elem ) {
djmoffat@718 4907 return jQuery.event.trigger( type, data, elem, true );
djmoffat@718 4908 }
djmoffat@718 4909 }
djmoffat@718 4910 });
djmoffat@718 4911
djmoffat@718 4912
djmoffat@718 4913 var
djmoffat@718 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
djmoffat@718 4915 rtagName = /<([\w:]+)/,
djmoffat@718 4916 rhtml = /<|&#?\w+;/,
djmoffat@718 4917 rnoInnerhtml = /<(?:script|style|link)/i,
djmoffat@718 4918 // checked="checked" or checked
djmoffat@718 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
djmoffat@718 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
djmoffat@718 4921 rscriptTypeMasked = /^true\/(.*)/,
djmoffat@718 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
djmoffat@718 4923
djmoffat@718 4924 // We have to close these tags to support XHTML (#13200)
djmoffat@718 4925 wrapMap = {
djmoffat@718 4926
djmoffat@718 4927 // Support: IE9
djmoffat@718 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
djmoffat@718 4929
djmoffat@718 4930 thead: [ 1, "<table>", "</table>" ],
djmoffat@718 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
djmoffat@718 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
djmoffat@718 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
djmoffat@718 4934
djmoffat@718 4935 _default: [ 0, "", "" ]
djmoffat@718 4936 };
djmoffat@718 4937
djmoffat@718 4938 // Support: IE9
djmoffat@718 4939 wrapMap.optgroup = wrapMap.option;
djmoffat@718 4940
djmoffat@718 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
djmoffat@718 4942 wrapMap.th = wrapMap.td;
djmoffat@718 4943
djmoffat@718 4944 // Support: 1.x compatibility
djmoffat@718 4945 // Manipulating tables requires a tbody
djmoffat@718 4946 function manipulationTarget( elem, content ) {
djmoffat@718 4947 return jQuery.nodeName( elem, "table" ) &&
djmoffat@718 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
djmoffat@718 4949
djmoffat@718 4950 elem.getElementsByTagName("tbody")[0] ||
djmoffat@718 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
djmoffat@718 4952 elem;
djmoffat@718 4953 }
djmoffat@718 4954
djmoffat@718 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
djmoffat@718 4956 function disableScript( elem ) {
djmoffat@718 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
djmoffat@718 4958 return elem;
djmoffat@718 4959 }
djmoffat@718 4960 function restoreScript( elem ) {
djmoffat@718 4961 var match = rscriptTypeMasked.exec( elem.type );
djmoffat@718 4962
djmoffat@718 4963 if ( match ) {
djmoffat@718 4964 elem.type = match[ 1 ];
djmoffat@718 4965 } else {
djmoffat@718 4966 elem.removeAttribute("type");
djmoffat@718 4967 }
djmoffat@718 4968
djmoffat@718 4969 return elem;
djmoffat@718 4970 }
djmoffat@718 4971
djmoffat@718 4972 // Mark scripts as having already been evaluated
djmoffat@718 4973 function setGlobalEval( elems, refElements ) {
djmoffat@718 4974 var i = 0,
djmoffat@718 4975 l = elems.length;
djmoffat@718 4976
djmoffat@718 4977 for ( ; i < l; i++ ) {
djmoffat@718 4978 data_priv.set(
djmoffat@718 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
djmoffat@718 4980 );
djmoffat@718 4981 }
djmoffat@718 4982 }
djmoffat@718 4983
djmoffat@718 4984 function cloneCopyEvent( src, dest ) {
djmoffat@718 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
djmoffat@718 4986
djmoffat@718 4987 if ( dest.nodeType !== 1 ) {
djmoffat@718 4988 return;
djmoffat@718 4989 }
djmoffat@718 4990
djmoffat@718 4991 // 1. Copy private data: events, handlers, etc.
djmoffat@718 4992 if ( data_priv.hasData( src ) ) {
djmoffat@718 4993 pdataOld = data_priv.access( src );
djmoffat@718 4994 pdataCur = data_priv.set( dest, pdataOld );
djmoffat@718 4995 events = pdataOld.events;
djmoffat@718 4996
djmoffat@718 4997 if ( events ) {
djmoffat@718 4998 delete pdataCur.handle;
djmoffat@718 4999 pdataCur.events = {};
djmoffat@718 5000
djmoffat@718 5001 for ( type in events ) {
djmoffat@718 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
djmoffat@718 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
djmoffat@718 5004 }
djmoffat@718 5005 }
djmoffat@718 5006 }
djmoffat@718 5007 }
djmoffat@718 5008
djmoffat@718 5009 // 2. Copy user data
djmoffat@718 5010 if ( data_user.hasData( src ) ) {
djmoffat@718 5011 udataOld = data_user.access( src );
djmoffat@718 5012 udataCur = jQuery.extend( {}, udataOld );
djmoffat@718 5013
djmoffat@718 5014 data_user.set( dest, udataCur );
djmoffat@718 5015 }
djmoffat@718 5016 }
djmoffat@718 5017
djmoffat@718 5018 function getAll( context, tag ) {
djmoffat@718 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
djmoffat@718 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
djmoffat@718 5021 [];
djmoffat@718 5022
djmoffat@718 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
djmoffat@718 5024 jQuery.merge( [ context ], ret ) :
djmoffat@718 5025 ret;
djmoffat@718 5026 }
djmoffat@718 5027
djmoffat@718 5028 // Fix IE bugs, see support tests
djmoffat@718 5029 function fixInput( src, dest ) {
djmoffat@718 5030 var nodeName = dest.nodeName.toLowerCase();
djmoffat@718 5031
djmoffat@718 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
djmoffat@718 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
djmoffat@718 5034 dest.checked = src.checked;
djmoffat@718 5035
djmoffat@718 5036 // Fails to return the selected option to the default selected state when cloning options
djmoffat@718 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
djmoffat@718 5038 dest.defaultValue = src.defaultValue;
djmoffat@718 5039 }
djmoffat@718 5040 }
djmoffat@718 5041
djmoffat@718 5042 jQuery.extend({
djmoffat@718 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
djmoffat@718 5044 var i, l, srcElements, destElements,
djmoffat@718 5045 clone = elem.cloneNode( true ),
djmoffat@718 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
djmoffat@718 5047
djmoffat@718 5048 // Fix IE cloning issues
djmoffat@718 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
djmoffat@718 5050 !jQuery.isXMLDoc( elem ) ) {
djmoffat@718 5051
djmoffat@718 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
djmoffat@718 5053 destElements = getAll( clone );
djmoffat@718 5054 srcElements = getAll( elem );
djmoffat@718 5055
djmoffat@718 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
djmoffat@718 5057 fixInput( srcElements[ i ], destElements[ i ] );
djmoffat@718 5058 }
djmoffat@718 5059 }
djmoffat@718 5060
djmoffat@718 5061 // Copy the events from the original to the clone
djmoffat@718 5062 if ( dataAndEvents ) {
djmoffat@718 5063 if ( deepDataAndEvents ) {
djmoffat@718 5064 srcElements = srcElements || getAll( elem );
djmoffat@718 5065 destElements = destElements || getAll( clone );
djmoffat@718 5066
djmoffat@718 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
djmoffat@718 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
djmoffat@718 5069 }
djmoffat@718 5070 } else {
djmoffat@718 5071 cloneCopyEvent( elem, clone );
djmoffat@718 5072 }
djmoffat@718 5073 }
djmoffat@718 5074
djmoffat@718 5075 // Preserve script evaluation history
djmoffat@718 5076 destElements = getAll( clone, "script" );
djmoffat@718 5077 if ( destElements.length > 0 ) {
djmoffat@718 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
djmoffat@718 5079 }
djmoffat@718 5080
djmoffat@718 5081 // Return the cloned set
djmoffat@718 5082 return clone;
djmoffat@718 5083 },
djmoffat@718 5084
djmoffat@718 5085 buildFragment: function( elems, context, scripts, selection ) {
djmoffat@718 5086 var elem, tmp, tag, wrap, contains, j,
djmoffat@718 5087 fragment = context.createDocumentFragment(),
djmoffat@718 5088 nodes = [],
djmoffat@718 5089 i = 0,
djmoffat@718 5090 l = elems.length;
djmoffat@718 5091
djmoffat@718 5092 for ( ; i < l; i++ ) {
djmoffat@718 5093 elem = elems[ i ];
djmoffat@718 5094
djmoffat@718 5095 if ( elem || elem === 0 ) {
djmoffat@718 5096
djmoffat@718 5097 // Add nodes directly
djmoffat@718 5098 if ( jQuery.type( elem ) === "object" ) {
djmoffat@718 5099 // Support: QtWebKit, PhantomJS
djmoffat@718 5100 // push.apply(_, arraylike) throws on ancient WebKit
djmoffat@718 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
djmoffat@718 5102
djmoffat@718 5103 // Convert non-html into a text node
djmoffat@718 5104 } else if ( !rhtml.test( elem ) ) {
djmoffat@718 5105 nodes.push( context.createTextNode( elem ) );
djmoffat@718 5106
djmoffat@718 5107 // Convert html into DOM nodes
djmoffat@718 5108 } else {
djmoffat@718 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
djmoffat@718 5110
djmoffat@718 5111 // Deserialize a standard representation
djmoffat@718 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
djmoffat@718 5113 wrap = wrapMap[ tag ] || wrapMap._default;
djmoffat@718 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
djmoffat@718 5115
djmoffat@718 5116 // Descend through wrappers to the right content
djmoffat@718 5117 j = wrap[ 0 ];
djmoffat@718 5118 while ( j-- ) {
djmoffat@718 5119 tmp = tmp.lastChild;
djmoffat@718 5120 }
djmoffat@718 5121
djmoffat@718 5122 // Support: QtWebKit, PhantomJS
djmoffat@718 5123 // push.apply(_, arraylike) throws on ancient WebKit
djmoffat@718 5124 jQuery.merge( nodes, tmp.childNodes );
djmoffat@718 5125
djmoffat@718 5126 // Remember the top-level container
djmoffat@718 5127 tmp = fragment.firstChild;
djmoffat@718 5128
djmoffat@718 5129 // Ensure the created nodes are orphaned (#12392)
djmoffat@718 5130 tmp.textContent = "";
djmoffat@718 5131 }
djmoffat@718 5132 }
djmoffat@718 5133 }
djmoffat@718 5134
djmoffat@718 5135 // Remove wrapper from fragment
djmoffat@718 5136 fragment.textContent = "";
djmoffat@718 5137
djmoffat@718 5138 i = 0;
djmoffat@718 5139 while ( (elem = nodes[ i++ ]) ) {
djmoffat@718 5140
djmoffat@718 5141 // #4087 - If origin and destination elements are the same, and this is
djmoffat@718 5142 // that element, do not do anything
djmoffat@718 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
djmoffat@718 5144 continue;
djmoffat@718 5145 }
djmoffat@718 5146
djmoffat@718 5147 contains = jQuery.contains( elem.ownerDocument, elem );
djmoffat@718 5148
djmoffat@718 5149 // Append to fragment
djmoffat@718 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
djmoffat@718 5151
djmoffat@718 5152 // Preserve script evaluation history
djmoffat@718 5153 if ( contains ) {
djmoffat@718 5154 setGlobalEval( tmp );
djmoffat@718 5155 }
djmoffat@718 5156
djmoffat@718 5157 // Capture executables
djmoffat@718 5158 if ( scripts ) {
djmoffat@718 5159 j = 0;
djmoffat@718 5160 while ( (elem = tmp[ j++ ]) ) {
djmoffat@718 5161 if ( rscriptType.test( elem.type || "" ) ) {
djmoffat@718 5162 scripts.push( elem );
djmoffat@718 5163 }
djmoffat@718 5164 }
djmoffat@718 5165 }
djmoffat@718 5166 }
djmoffat@718 5167
djmoffat@718 5168 return fragment;
djmoffat@718 5169 },
djmoffat@718 5170
djmoffat@718 5171 cleanData: function( elems ) {
djmoffat@718 5172 var data, elem, type, key,
djmoffat@718 5173 special = jQuery.event.special,
djmoffat@718 5174 i = 0;
djmoffat@718 5175
djmoffat@718 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
djmoffat@718 5177 if ( jQuery.acceptData( elem ) ) {
djmoffat@718 5178 key = elem[ data_priv.expando ];
djmoffat@718 5179
djmoffat@718 5180 if ( key && (data = data_priv.cache[ key ]) ) {
djmoffat@718 5181 if ( data.events ) {
djmoffat@718 5182 for ( type in data.events ) {
djmoffat@718 5183 if ( special[ type ] ) {
djmoffat@718 5184 jQuery.event.remove( elem, type );
djmoffat@718 5185
djmoffat@718 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
djmoffat@718 5187 } else {
djmoffat@718 5188 jQuery.removeEvent( elem, type, data.handle );
djmoffat@718 5189 }
djmoffat@718 5190 }
djmoffat@718 5191 }
djmoffat@718 5192 if ( data_priv.cache[ key ] ) {
djmoffat@718 5193 // Discard any remaining `private` data
djmoffat@718 5194 delete data_priv.cache[ key ];
djmoffat@718 5195 }
djmoffat@718 5196 }
djmoffat@718 5197 }
djmoffat@718 5198 // Discard any remaining `user` data
djmoffat@718 5199 delete data_user.cache[ elem[ data_user.expando ] ];
djmoffat@718 5200 }
djmoffat@718 5201 }
djmoffat@718 5202 });
djmoffat@718 5203
djmoffat@718 5204 jQuery.fn.extend({
djmoffat@718 5205 text: function( value ) {
djmoffat@718 5206 return access( this, function( value ) {
djmoffat@718 5207 return value === undefined ?
djmoffat@718 5208 jQuery.text( this ) :
djmoffat@718 5209 this.empty().each(function() {
djmoffat@718 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
djmoffat@718 5211 this.textContent = value;
djmoffat@718 5212 }
djmoffat@718 5213 });
djmoffat@718 5214 }, null, value, arguments.length );
djmoffat@718 5215 },
djmoffat@718 5216
djmoffat@718 5217 append: function() {
djmoffat@718 5218 return this.domManip( arguments, function( elem ) {
djmoffat@718 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
djmoffat@718 5220 var target = manipulationTarget( this, elem );
djmoffat@718 5221 target.appendChild( elem );
djmoffat@718 5222 }
djmoffat@718 5223 });
djmoffat@718 5224 },
djmoffat@718 5225
djmoffat@718 5226 prepend: function() {
djmoffat@718 5227 return this.domManip( arguments, function( elem ) {
djmoffat@718 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
djmoffat@718 5229 var target = manipulationTarget( this, elem );
djmoffat@718 5230 target.insertBefore( elem, target.firstChild );
djmoffat@718 5231 }
djmoffat@718 5232 });
djmoffat@718 5233 },
djmoffat@718 5234
djmoffat@718 5235 before: function() {
djmoffat@718 5236 return this.domManip( arguments, function( elem ) {
djmoffat@718 5237 if ( this.parentNode ) {
djmoffat@718 5238 this.parentNode.insertBefore( elem, this );
djmoffat@718 5239 }
djmoffat@718 5240 });
djmoffat@718 5241 },
djmoffat@718 5242
djmoffat@718 5243 after: function() {
djmoffat@718 5244 return this.domManip( arguments, function( elem ) {
djmoffat@718 5245 if ( this.parentNode ) {
djmoffat@718 5246 this.parentNode.insertBefore( elem, this.nextSibling );
djmoffat@718 5247 }
djmoffat@718 5248 });
djmoffat@718 5249 },
djmoffat@718 5250
djmoffat@718 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
djmoffat@718 5252 var elem,
djmoffat@718 5253 elems = selector ? jQuery.filter( selector, this ) : this,
djmoffat@718 5254 i = 0;
djmoffat@718 5255
djmoffat@718 5256 for ( ; (elem = elems[i]) != null; i++ ) {
djmoffat@718 5257 if ( !keepData && elem.nodeType === 1 ) {
djmoffat@718 5258 jQuery.cleanData( getAll( elem ) );
djmoffat@718 5259 }
djmoffat@718 5260
djmoffat@718 5261 if ( elem.parentNode ) {
djmoffat@718 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
djmoffat@718 5263 setGlobalEval( getAll( elem, "script" ) );
djmoffat@718 5264 }
djmoffat@718 5265 elem.parentNode.removeChild( elem );
djmoffat@718 5266 }
djmoffat@718 5267 }
djmoffat@718 5268
djmoffat@718 5269 return this;
djmoffat@718 5270 },
djmoffat@718 5271
djmoffat@718 5272 empty: function() {
djmoffat@718 5273 var elem,
djmoffat@718 5274 i = 0;
djmoffat@718 5275
djmoffat@718 5276 for ( ; (elem = this[i]) != null; i++ ) {
djmoffat@718 5277 if ( elem.nodeType === 1 ) {
djmoffat@718 5278
djmoffat@718 5279 // Prevent memory leaks
djmoffat@718 5280 jQuery.cleanData( getAll( elem, false ) );
djmoffat@718 5281
djmoffat@718 5282 // Remove any remaining nodes
djmoffat@718 5283 elem.textContent = "";
djmoffat@718 5284 }
djmoffat@718 5285 }
djmoffat@718 5286
djmoffat@718 5287 return this;
djmoffat@718 5288 },
djmoffat@718 5289
djmoffat@718 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
djmoffat@718 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
djmoffat@718 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
djmoffat@718 5293
djmoffat@718 5294 return this.map(function() {
djmoffat@718 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
djmoffat@718 5296 });
djmoffat@718 5297 },
djmoffat@718 5298
djmoffat@718 5299 html: function( value ) {
djmoffat@718 5300 return access( this, function( value ) {
djmoffat@718 5301 var elem = this[ 0 ] || {},
djmoffat@718 5302 i = 0,
djmoffat@718 5303 l = this.length;
djmoffat@718 5304
djmoffat@718 5305 if ( value === undefined && elem.nodeType === 1 ) {
djmoffat@718 5306 return elem.innerHTML;
djmoffat@718 5307 }
djmoffat@718 5308
djmoffat@718 5309 // See if we can take a shortcut and just use innerHTML
djmoffat@718 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
djmoffat@718 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
djmoffat@718 5312
djmoffat@718 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
djmoffat@718 5314
djmoffat@718 5315 try {
djmoffat@718 5316 for ( ; i < l; i++ ) {
djmoffat@718 5317 elem = this[ i ] || {};
djmoffat@718 5318
djmoffat@718 5319 // Remove element nodes and prevent memory leaks
djmoffat@718 5320 if ( elem.nodeType === 1 ) {
djmoffat@718 5321 jQuery.cleanData( getAll( elem, false ) );
djmoffat@718 5322 elem.innerHTML = value;
djmoffat@718 5323 }
djmoffat@718 5324 }
djmoffat@718 5325
djmoffat@718 5326 elem = 0;
djmoffat@718 5327
djmoffat@718 5328 // If using innerHTML throws an exception, use the fallback method
djmoffat@718 5329 } catch( e ) {}
djmoffat@718 5330 }
djmoffat@718 5331
djmoffat@718 5332 if ( elem ) {
djmoffat@718 5333 this.empty().append( value );
djmoffat@718 5334 }
djmoffat@718 5335 }, null, value, arguments.length );
djmoffat@718 5336 },
djmoffat@718 5337
djmoffat@718 5338 replaceWith: function() {
djmoffat@718 5339 var arg = arguments[ 0 ];
djmoffat@718 5340
djmoffat@718 5341 // Make the changes, replacing each context element with the new content
djmoffat@718 5342 this.domManip( arguments, function( elem ) {
djmoffat@718 5343 arg = this.parentNode;
djmoffat@718 5344
djmoffat@718 5345 jQuery.cleanData( getAll( this ) );
djmoffat@718 5346
djmoffat@718 5347 if ( arg ) {
djmoffat@718 5348 arg.replaceChild( elem, this );
djmoffat@718 5349 }
djmoffat@718 5350 });
djmoffat@718 5351
djmoffat@718 5352 // Force removal if there was no new content (e.g., from empty arguments)
djmoffat@718 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
djmoffat@718 5354 },
djmoffat@718 5355
djmoffat@718 5356 detach: function( selector ) {
djmoffat@718 5357 return this.remove( selector, true );
djmoffat@718 5358 },
djmoffat@718 5359
djmoffat@718 5360 domManip: function( args, callback ) {
djmoffat@718 5361
djmoffat@718 5362 // Flatten any nested arrays
djmoffat@718 5363 args = concat.apply( [], args );
djmoffat@718 5364
djmoffat@718 5365 var fragment, first, scripts, hasScripts, node, doc,
djmoffat@718 5366 i = 0,
djmoffat@718 5367 l = this.length,
djmoffat@718 5368 set = this,
djmoffat@718 5369 iNoClone = l - 1,
djmoffat@718 5370 value = args[ 0 ],
djmoffat@718 5371 isFunction = jQuery.isFunction( value );
djmoffat@718 5372
djmoffat@718 5373 // We can't cloneNode fragments that contain checked, in WebKit
djmoffat@718 5374 if ( isFunction ||
djmoffat@718 5375 ( l > 1 && typeof value === "string" &&
djmoffat@718 5376 !support.checkClone && rchecked.test( value ) ) ) {
djmoffat@718 5377 return this.each(function( index ) {
djmoffat@718 5378 var self = set.eq( index );
djmoffat@718 5379 if ( isFunction ) {
djmoffat@718 5380 args[ 0 ] = value.call( this, index, self.html() );
djmoffat@718 5381 }
djmoffat@718 5382 self.domManip( args, callback );
djmoffat@718 5383 });
djmoffat@718 5384 }
djmoffat@718 5385
djmoffat@718 5386 if ( l ) {
djmoffat@718 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
djmoffat@718 5388 first = fragment.firstChild;
djmoffat@718 5389
djmoffat@718 5390 if ( fragment.childNodes.length === 1 ) {
djmoffat@718 5391 fragment = first;
djmoffat@718 5392 }
djmoffat@718 5393
djmoffat@718 5394 if ( first ) {
djmoffat@718 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
djmoffat@718 5396 hasScripts = scripts.length;
djmoffat@718 5397
djmoffat@718 5398 // Use the original fragment for the last item instead of the first because it can end up
djmoffat@718 5399 // being emptied incorrectly in certain situations (#8070).
djmoffat@718 5400 for ( ; i < l; i++ ) {
djmoffat@718 5401 node = fragment;
djmoffat@718 5402
djmoffat@718 5403 if ( i !== iNoClone ) {
djmoffat@718 5404 node = jQuery.clone( node, true, true );
djmoffat@718 5405
djmoffat@718 5406 // Keep references to cloned scripts for later restoration
djmoffat@718 5407 if ( hasScripts ) {
djmoffat@718 5408 // Support: QtWebKit
djmoffat@718 5409 // jQuery.merge because push.apply(_, arraylike) throws
djmoffat@718 5410 jQuery.merge( scripts, getAll( node, "script" ) );
djmoffat@718 5411 }
djmoffat@718 5412 }
djmoffat@718 5413
djmoffat@718 5414 callback.call( this[ i ], node, i );
djmoffat@718 5415 }
djmoffat@718 5416
djmoffat@718 5417 if ( hasScripts ) {
djmoffat@718 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
djmoffat@718 5419
djmoffat@718 5420 // Reenable scripts
djmoffat@718 5421 jQuery.map( scripts, restoreScript );
djmoffat@718 5422
djmoffat@718 5423 // Evaluate executable scripts on first document insertion
djmoffat@718 5424 for ( i = 0; i < hasScripts; i++ ) {
djmoffat@718 5425 node = scripts[ i ];
djmoffat@718 5426 if ( rscriptType.test( node.type || "" ) &&
djmoffat@718 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
djmoffat@718 5428
djmoffat@718 5429 if ( node.src ) {
djmoffat@718 5430 // Optional AJAX dependency, but won't run scripts if not present
djmoffat@718 5431 if ( jQuery._evalUrl ) {
djmoffat@718 5432 jQuery._evalUrl( node.src );
djmoffat@718 5433 }
djmoffat@718 5434 } else {
djmoffat@718 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
djmoffat@718 5436 }
djmoffat@718 5437 }
djmoffat@718 5438 }
djmoffat@718 5439 }
djmoffat@718 5440 }
djmoffat@718 5441 }
djmoffat@718 5442
djmoffat@718 5443 return this;
djmoffat@718 5444 }
djmoffat@718 5445 });
djmoffat@718 5446
djmoffat@718 5447 jQuery.each({
djmoffat@718 5448 appendTo: "append",
djmoffat@718 5449 prependTo: "prepend",
djmoffat@718 5450 insertBefore: "before",
djmoffat@718 5451 insertAfter: "after",
djmoffat@718 5452 replaceAll: "replaceWith"
djmoffat@718 5453 }, function( name, original ) {
djmoffat@718 5454 jQuery.fn[ name ] = function( selector ) {
djmoffat@718 5455 var elems,
djmoffat@718 5456 ret = [],
djmoffat@718 5457 insert = jQuery( selector ),
djmoffat@718 5458 last = insert.length - 1,
djmoffat@718 5459 i = 0;
djmoffat@718 5460
djmoffat@718 5461 for ( ; i <= last; i++ ) {
djmoffat@718 5462 elems = i === last ? this : this.clone( true );
djmoffat@718 5463 jQuery( insert[ i ] )[ original ]( elems );
djmoffat@718 5464
djmoffat@718 5465 // Support: QtWebKit
djmoffat@718 5466 // .get() because push.apply(_, arraylike) throws
djmoffat@718 5467 push.apply( ret, elems.get() );
djmoffat@718 5468 }
djmoffat@718 5469
djmoffat@718 5470 return this.pushStack( ret );
djmoffat@718 5471 };
djmoffat@718 5472 });
djmoffat@718 5473
djmoffat@718 5474
djmoffat@718 5475 var iframe,
djmoffat@718 5476 elemdisplay = {};
djmoffat@718 5477
djmoffat@718 5478 /**
djmoffat@718 5479 * Retrieve the actual display of a element
djmoffat@718 5480 * @param {String} name nodeName of the element
djmoffat@718 5481 * @param {Object} doc Document object
djmoffat@718 5482 */
djmoffat@718 5483 // Called only from within defaultDisplay
djmoffat@718 5484 function actualDisplay( name, doc ) {
djmoffat@718 5485 var style,
djmoffat@718 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
djmoffat@718 5487
djmoffat@718 5488 // getDefaultComputedStyle might be reliably used only on attached element
djmoffat@718 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
djmoffat@718 5490
djmoffat@718 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
djmoffat@718 5492 // since it was removed from specification and supported only in FF
djmoffat@718 5493 style.display : jQuery.css( elem[ 0 ], "display" );
djmoffat@718 5494
djmoffat@718 5495 // We don't have any data stored on the element,
djmoffat@718 5496 // so use "detach" method as fast way to get rid of the element
djmoffat@718 5497 elem.detach();
djmoffat@718 5498
djmoffat@718 5499 return display;
djmoffat@718 5500 }
djmoffat@718 5501
djmoffat@718 5502 /**
djmoffat@718 5503 * Try to determine the default display value of an element
djmoffat@718 5504 * @param {String} nodeName
djmoffat@718 5505 */
djmoffat@718 5506 function defaultDisplay( nodeName ) {
djmoffat@718 5507 var doc = document,
djmoffat@718 5508 display = elemdisplay[ nodeName ];
djmoffat@718 5509
djmoffat@718 5510 if ( !display ) {
djmoffat@718 5511 display = actualDisplay( nodeName, doc );
djmoffat@718 5512
djmoffat@718 5513 // If the simple way fails, read from inside an iframe
djmoffat@718 5514 if ( display === "none" || !display ) {
djmoffat@718 5515
djmoffat@718 5516 // Use the already-created iframe if possible
djmoffat@718 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
djmoffat@718 5518
djmoffat@718 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
djmoffat@718 5520 doc = iframe[ 0 ].contentDocument;
djmoffat@718 5521
djmoffat@718 5522 // Support: IE
djmoffat@718 5523 doc.write();
djmoffat@718 5524 doc.close();
djmoffat@718 5525
djmoffat@718 5526 display = actualDisplay( nodeName, doc );
djmoffat@718 5527 iframe.detach();
djmoffat@718 5528 }
djmoffat@718 5529
djmoffat@718 5530 // Store the correct default display
djmoffat@718 5531 elemdisplay[ nodeName ] = display;
djmoffat@718 5532 }
djmoffat@718 5533
djmoffat@718 5534 return display;
djmoffat@718 5535 }
djmoffat@718 5536 var rmargin = (/^margin/);
djmoffat@718 5537
djmoffat@718 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
djmoffat@718 5539
djmoffat@718 5540 var getStyles = function( elem ) {
djmoffat@718 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
djmoffat@718 5542 // IE throws on elements created in popups
djmoffat@718 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
djmoffat@718 5544 if ( elem.ownerDocument.defaultView.opener ) {
djmoffat@718 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
djmoffat@718 5546 }
djmoffat@718 5547
djmoffat@718 5548 return window.getComputedStyle( elem, null );
djmoffat@718 5549 };
djmoffat@718 5550
djmoffat@718 5551
djmoffat@718 5552
djmoffat@718 5553 function curCSS( elem, name, computed ) {
djmoffat@718 5554 var width, minWidth, maxWidth, ret,
djmoffat@718 5555 style = elem.style;
djmoffat@718 5556
djmoffat@718 5557 computed = computed || getStyles( elem );
djmoffat@718 5558
djmoffat@718 5559 // Support: IE9
djmoffat@718 5560 // getPropertyValue is only needed for .css('filter') (#12537)
djmoffat@718 5561 if ( computed ) {
djmoffat@718 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
djmoffat@718 5563 }
djmoffat@718 5564
djmoffat@718 5565 if ( computed ) {
djmoffat@718 5566
djmoffat@718 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
djmoffat@718 5568 ret = jQuery.style( elem, name );
djmoffat@718 5569 }
djmoffat@718 5570
djmoffat@718 5571 // Support: iOS < 6
djmoffat@718 5572 // A tribute to the "awesome hack by Dean Edwards"
djmoffat@718 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
djmoffat@718 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
djmoffat@718 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
djmoffat@718 5576
djmoffat@718 5577 // Remember the original values
djmoffat@718 5578 width = style.width;
djmoffat@718 5579 minWidth = style.minWidth;
djmoffat@718 5580 maxWidth = style.maxWidth;
djmoffat@718 5581
djmoffat@718 5582 // Put in the new values to get a computed value out
djmoffat@718 5583 style.minWidth = style.maxWidth = style.width = ret;
djmoffat@718 5584 ret = computed.width;
djmoffat@718 5585
djmoffat@718 5586 // Revert the changed values
djmoffat@718 5587 style.width = width;
djmoffat@718 5588 style.minWidth = minWidth;
djmoffat@718 5589 style.maxWidth = maxWidth;
djmoffat@718 5590 }
djmoffat@718 5591 }
djmoffat@718 5592
djmoffat@718 5593 return ret !== undefined ?
djmoffat@718 5594 // Support: IE
djmoffat@718 5595 // IE returns zIndex value as an integer.
djmoffat@718 5596 ret + "" :
djmoffat@718 5597 ret;
djmoffat@718 5598 }
djmoffat@718 5599
djmoffat@718 5600
djmoffat@718 5601 function addGetHookIf( conditionFn, hookFn ) {
djmoffat@718 5602 // Define the hook, we'll check on the first run if it's really needed.
djmoffat@718 5603 return {
djmoffat@718 5604 get: function() {
djmoffat@718 5605 if ( conditionFn() ) {
djmoffat@718 5606 // Hook not needed (or it's not possible to use it due
djmoffat@718 5607 // to missing dependency), remove it.
djmoffat@718 5608 delete this.get;
djmoffat@718 5609 return;
djmoffat@718 5610 }
djmoffat@718 5611
djmoffat@718 5612 // Hook needed; redefine it so that the support test is not executed again.
djmoffat@718 5613 return (this.get = hookFn).apply( this, arguments );
djmoffat@718 5614 }
djmoffat@718 5615 };
djmoffat@718 5616 }
djmoffat@718 5617
djmoffat@718 5618
djmoffat@718 5619 (function() {
djmoffat@718 5620 var pixelPositionVal, boxSizingReliableVal,
djmoffat@718 5621 docElem = document.documentElement,
djmoffat@718 5622 container = document.createElement( "div" ),
djmoffat@718 5623 div = document.createElement( "div" );
djmoffat@718 5624
djmoffat@718 5625 if ( !div.style ) {
djmoffat@718 5626 return;
djmoffat@718 5627 }
djmoffat@718 5628
djmoffat@718 5629 // Support: IE9-11+
djmoffat@718 5630 // Style of cloned element affects source element cloned (#8908)
djmoffat@718 5631 div.style.backgroundClip = "content-box";
djmoffat@718 5632 div.cloneNode( true ).style.backgroundClip = "";
djmoffat@718 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
djmoffat@718 5634
djmoffat@718 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
djmoffat@718 5636 "position:absolute";
djmoffat@718 5637 container.appendChild( div );
djmoffat@718 5638
djmoffat@718 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
djmoffat@718 5640 // so they're executed at the same time to save the second computation.
djmoffat@718 5641 function computePixelPositionAndBoxSizingReliable() {
djmoffat@718 5642 div.style.cssText =
djmoffat@718 5643 // Support: Firefox<29, Android 2.3
djmoffat@718 5644 // Vendor-prefix box-sizing
djmoffat@718 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
djmoffat@718 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
djmoffat@718 5647 "border:1px;padding:1px;width:4px;position:absolute";
djmoffat@718 5648 div.innerHTML = "";
djmoffat@718 5649 docElem.appendChild( container );
djmoffat@718 5650
djmoffat@718 5651 var divStyle = window.getComputedStyle( div, null );
djmoffat@718 5652 pixelPositionVal = divStyle.top !== "1%";
djmoffat@718 5653 boxSizingReliableVal = divStyle.width === "4px";
djmoffat@718 5654
djmoffat@718 5655 docElem.removeChild( container );
djmoffat@718 5656 }
djmoffat@718 5657
djmoffat@718 5658 // Support: node.js jsdom
djmoffat@718 5659 // Don't assume that getComputedStyle is a property of the global object
djmoffat@718 5660 if ( window.getComputedStyle ) {
djmoffat@718 5661 jQuery.extend( support, {
djmoffat@718 5662 pixelPosition: function() {
djmoffat@718 5663
djmoffat@718 5664 // This test is executed only once but we still do memoizing
djmoffat@718 5665 // since we can use the boxSizingReliable pre-computing.
djmoffat@718 5666 // No need to check if the test was already performed, though.
djmoffat@718 5667 computePixelPositionAndBoxSizingReliable();
djmoffat@718 5668 return pixelPositionVal;
djmoffat@718 5669 },
djmoffat@718 5670 boxSizingReliable: function() {
djmoffat@718 5671 if ( boxSizingReliableVal == null ) {
djmoffat@718 5672 computePixelPositionAndBoxSizingReliable();
djmoffat@718 5673 }
djmoffat@718 5674 return boxSizingReliableVal;
djmoffat@718 5675 },
djmoffat@718 5676 reliableMarginRight: function() {
djmoffat@718 5677
djmoffat@718 5678 // Support: Android 2.3
djmoffat@718 5679 // Check if div with explicit width and no margin-right incorrectly
djmoffat@718 5680 // gets computed margin-right based on width of container. (#3333)
djmoffat@718 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
djmoffat@718 5682 // This support function is only executed once so no memoizing is needed.
djmoffat@718 5683 var ret,
djmoffat@718 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
djmoffat@718 5685
djmoffat@718 5686 // Reset CSS: box-sizing; display; margin; border; padding
djmoffat@718 5687 marginDiv.style.cssText = div.style.cssText =
djmoffat@718 5688 // Support: Firefox<29, Android 2.3
djmoffat@718 5689 // Vendor-prefix box-sizing
djmoffat@718 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
djmoffat@718 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
djmoffat@718 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
djmoffat@718 5693 div.style.width = "1px";
djmoffat@718 5694 docElem.appendChild( container );
djmoffat@718 5695
djmoffat@718 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
djmoffat@718 5697
djmoffat@718 5698 docElem.removeChild( container );
djmoffat@718 5699 div.removeChild( marginDiv );
djmoffat@718 5700
djmoffat@718 5701 return ret;
djmoffat@718 5702 }
djmoffat@718 5703 });
djmoffat@718 5704 }
djmoffat@718 5705 })();
djmoffat@718 5706
djmoffat@718 5707
djmoffat@718 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
djmoffat@718 5709 jQuery.swap = function( elem, options, callback, args ) {
djmoffat@718 5710 var ret, name,
djmoffat@718 5711 old = {};
djmoffat@718 5712
djmoffat@718 5713 // Remember the old values, and insert the new ones
djmoffat@718 5714 for ( name in options ) {
djmoffat@718 5715 old[ name ] = elem.style[ name ];
djmoffat@718 5716 elem.style[ name ] = options[ name ];
djmoffat@718 5717 }
djmoffat@718 5718
djmoffat@718 5719 ret = callback.apply( elem, args || [] );
djmoffat@718 5720
djmoffat@718 5721 // Revert the old values
djmoffat@718 5722 for ( name in options ) {
djmoffat@718 5723 elem.style[ name ] = old[ name ];
djmoffat@718 5724 }
djmoffat@718 5725
djmoffat@718 5726 return ret;
djmoffat@718 5727 };
djmoffat@718 5728
djmoffat@718 5729
djmoffat@718 5730 var
djmoffat@718 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
djmoffat@718 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
djmoffat@718 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
djmoffat@718 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
djmoffat@718 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
djmoffat@718 5736
djmoffat@718 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
djmoffat@718 5738 cssNormalTransform = {
djmoffat@718 5739 letterSpacing: "0",
djmoffat@718 5740 fontWeight: "400"
djmoffat@718 5741 },
djmoffat@718 5742
djmoffat@718 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
djmoffat@718 5744
djmoffat@718 5745 // Return a css property mapped to a potentially vendor prefixed property
djmoffat@718 5746 function vendorPropName( style, name ) {
djmoffat@718 5747
djmoffat@718 5748 // Shortcut for names that are not vendor prefixed
djmoffat@718 5749 if ( name in style ) {
djmoffat@718 5750 return name;
djmoffat@718 5751 }
djmoffat@718 5752
djmoffat@718 5753 // Check for vendor prefixed names
djmoffat@718 5754 var capName = name[0].toUpperCase() + name.slice(1),
djmoffat@718 5755 origName = name,
djmoffat@718 5756 i = cssPrefixes.length;
djmoffat@718 5757
djmoffat@718 5758 while ( i-- ) {
djmoffat@718 5759 name = cssPrefixes[ i ] + capName;
djmoffat@718 5760 if ( name in style ) {
djmoffat@718 5761 return name;
djmoffat@718 5762 }
djmoffat@718 5763 }
djmoffat@718 5764
djmoffat@718 5765 return origName;
djmoffat@718 5766 }
djmoffat@718 5767
djmoffat@718 5768 function setPositiveNumber( elem, value, subtract ) {
djmoffat@718 5769 var matches = rnumsplit.exec( value );
djmoffat@718 5770 return matches ?
djmoffat@718 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
djmoffat@718 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
djmoffat@718 5773 value;
djmoffat@718 5774 }
djmoffat@718 5775
djmoffat@718 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
djmoffat@718 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
djmoffat@718 5778 // If we already have the right measurement, avoid augmentation
djmoffat@718 5779 4 :
djmoffat@718 5780 // Otherwise initialize for horizontal or vertical properties
djmoffat@718 5781 name === "width" ? 1 : 0,
djmoffat@718 5782
djmoffat@718 5783 val = 0;
djmoffat@718 5784
djmoffat@718 5785 for ( ; i < 4; i += 2 ) {
djmoffat@718 5786 // Both box models exclude margin, so add it if we want it
djmoffat@718 5787 if ( extra === "margin" ) {
djmoffat@718 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
djmoffat@718 5789 }
djmoffat@718 5790
djmoffat@718 5791 if ( isBorderBox ) {
djmoffat@718 5792 // border-box includes padding, so remove it if we want content
djmoffat@718 5793 if ( extra === "content" ) {
djmoffat@718 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
djmoffat@718 5795 }
djmoffat@718 5796
djmoffat@718 5797 // At this point, extra isn't border nor margin, so remove border
djmoffat@718 5798 if ( extra !== "margin" ) {
djmoffat@718 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
djmoffat@718 5800 }
djmoffat@718 5801 } else {
djmoffat@718 5802 // At this point, extra isn't content, so add padding
djmoffat@718 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
djmoffat@718 5804
djmoffat@718 5805 // At this point, extra isn't content nor padding, so add border
djmoffat@718 5806 if ( extra !== "padding" ) {
djmoffat@718 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
djmoffat@718 5808 }
djmoffat@718 5809 }
djmoffat@718 5810 }
djmoffat@718 5811
djmoffat@718 5812 return val;
djmoffat@718 5813 }
djmoffat@718 5814
djmoffat@718 5815 function getWidthOrHeight( elem, name, extra ) {
djmoffat@718 5816
djmoffat@718 5817 // Start with offset property, which is equivalent to the border-box value
djmoffat@718 5818 var valueIsBorderBox = true,
djmoffat@718 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
djmoffat@718 5820 styles = getStyles( elem ),
djmoffat@718 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
djmoffat@718 5822
djmoffat@718 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
djmoffat@718 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
djmoffat@718 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
djmoffat@718 5826 if ( val <= 0 || val == null ) {
djmoffat@718 5827 // Fall back to computed then uncomputed css if necessary
djmoffat@718 5828 val = curCSS( elem, name, styles );
djmoffat@718 5829 if ( val < 0 || val == null ) {
djmoffat@718 5830 val = elem.style[ name ];
djmoffat@718 5831 }
djmoffat@718 5832
djmoffat@718 5833 // Computed unit is not pixels. Stop here and return.
djmoffat@718 5834 if ( rnumnonpx.test(val) ) {
djmoffat@718 5835 return val;
djmoffat@718 5836 }
djmoffat@718 5837
djmoffat@718 5838 // Check for style in case a browser which returns unreliable values
djmoffat@718 5839 // for getComputedStyle silently falls back to the reliable elem.style
djmoffat@718 5840 valueIsBorderBox = isBorderBox &&
djmoffat@718 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
djmoffat@718 5842
djmoffat@718 5843 // Normalize "", auto, and prepare for extra
djmoffat@718 5844 val = parseFloat( val ) || 0;
djmoffat@718 5845 }
djmoffat@718 5846
djmoffat@718 5847 // Use the active box-sizing model to add/subtract irrelevant styles
djmoffat@718 5848 return ( val +
djmoffat@718 5849 augmentWidthOrHeight(
djmoffat@718 5850 elem,
djmoffat@718 5851 name,
djmoffat@718 5852 extra || ( isBorderBox ? "border" : "content" ),
djmoffat@718 5853 valueIsBorderBox,
djmoffat@718 5854 styles
djmoffat@718 5855 )
djmoffat@718 5856 ) + "px";
djmoffat@718 5857 }
djmoffat@718 5858
djmoffat@718 5859 function showHide( elements, show ) {
djmoffat@718 5860 var display, elem, hidden,
djmoffat@718 5861 values = [],
djmoffat@718 5862 index = 0,
djmoffat@718 5863 length = elements.length;
djmoffat@718 5864
djmoffat@718 5865 for ( ; index < length; index++ ) {
djmoffat@718 5866 elem = elements[ index ];
djmoffat@718 5867 if ( !elem.style ) {
djmoffat@718 5868 continue;
djmoffat@718 5869 }
djmoffat@718 5870
djmoffat@718 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
djmoffat@718 5872 display = elem.style.display;
djmoffat@718 5873 if ( show ) {
djmoffat@718 5874 // Reset the inline display of this element to learn if it is
djmoffat@718 5875 // being hidden by cascaded rules or not
djmoffat@718 5876 if ( !values[ index ] && display === "none" ) {
djmoffat@718 5877 elem.style.display = "";
djmoffat@718 5878 }
djmoffat@718 5879
djmoffat@718 5880 // Set elements which have been overridden with display: none
djmoffat@718 5881 // in a stylesheet to whatever the default browser style is
djmoffat@718 5882 // for such an element
djmoffat@718 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
djmoffat@718 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
djmoffat@718 5885 }
djmoffat@718 5886 } else {
djmoffat@718 5887 hidden = isHidden( elem );
djmoffat@718 5888
djmoffat@718 5889 if ( display !== "none" || !hidden ) {
djmoffat@718 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
djmoffat@718 5891 }
djmoffat@718 5892 }
djmoffat@718 5893 }
djmoffat@718 5894
djmoffat@718 5895 // Set the display of most of the elements in a second loop
djmoffat@718 5896 // to avoid the constant reflow
djmoffat@718 5897 for ( index = 0; index < length; index++ ) {
djmoffat@718 5898 elem = elements[ index ];
djmoffat@718 5899 if ( !elem.style ) {
djmoffat@718 5900 continue;
djmoffat@718 5901 }
djmoffat@718 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
djmoffat@718 5903 elem.style.display = show ? values[ index ] || "" : "none";
djmoffat@718 5904 }
djmoffat@718 5905 }
djmoffat@718 5906
djmoffat@718 5907 return elements;
djmoffat@718 5908 }
djmoffat@718 5909
djmoffat@718 5910 jQuery.extend({
djmoffat@718 5911
djmoffat@718 5912 // Add in style property hooks for overriding the default
djmoffat@718 5913 // behavior of getting and setting a style property
djmoffat@718 5914 cssHooks: {
djmoffat@718 5915 opacity: {
djmoffat@718 5916 get: function( elem, computed ) {
djmoffat@718 5917 if ( computed ) {
djmoffat@718 5918
djmoffat@718 5919 // We should always get a number back from opacity
djmoffat@718 5920 var ret = curCSS( elem, "opacity" );
djmoffat@718 5921 return ret === "" ? "1" : ret;
djmoffat@718 5922 }
djmoffat@718 5923 }
djmoffat@718 5924 }
djmoffat@718 5925 },
djmoffat@718 5926
djmoffat@718 5927 // Don't automatically add "px" to these possibly-unitless properties
djmoffat@718 5928 cssNumber: {
djmoffat@718 5929 "columnCount": true,
djmoffat@718 5930 "fillOpacity": true,
djmoffat@718 5931 "flexGrow": true,
djmoffat@718 5932 "flexShrink": true,
djmoffat@718 5933 "fontWeight": true,
djmoffat@718 5934 "lineHeight": true,
djmoffat@718 5935 "opacity": true,
djmoffat@718 5936 "order": true,
djmoffat@718 5937 "orphans": true,
djmoffat@718 5938 "widows": true,
djmoffat@718 5939 "zIndex": true,
djmoffat@718 5940 "zoom": true
djmoffat@718 5941 },
djmoffat@718 5942
djmoffat@718 5943 // Add in properties whose names you wish to fix before
djmoffat@718 5944 // setting or getting the value
djmoffat@718 5945 cssProps: {
djmoffat@718 5946 "float": "cssFloat"
djmoffat@718 5947 },
djmoffat@718 5948
djmoffat@718 5949 // Get and set the style property on a DOM Node
djmoffat@718 5950 style: function( elem, name, value, extra ) {
djmoffat@718 5951
djmoffat@718 5952 // Don't set styles on text and comment nodes
djmoffat@718 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
djmoffat@718 5954 return;
djmoffat@718 5955 }
djmoffat@718 5956
djmoffat@718 5957 // Make sure that we're working with the right name
djmoffat@718 5958 var ret, type, hooks,
djmoffat@718 5959 origName = jQuery.camelCase( name ),
djmoffat@718 5960 style = elem.style;
djmoffat@718 5961
djmoffat@718 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
djmoffat@718 5963
djmoffat@718 5964 // Gets hook for the prefixed version, then unprefixed version
djmoffat@718 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
djmoffat@718 5966
djmoffat@718 5967 // Check if we're setting a value
djmoffat@718 5968 if ( value !== undefined ) {
djmoffat@718 5969 type = typeof value;
djmoffat@718 5970
djmoffat@718 5971 // Convert "+=" or "-=" to relative numbers (#7345)
djmoffat@718 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
djmoffat@718 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
djmoffat@718 5974 // Fixes bug #9237
djmoffat@718 5975 type = "number";
djmoffat@718 5976 }
djmoffat@718 5977
djmoffat@718 5978 // Make sure that null and NaN values aren't set (#7116)
djmoffat@718 5979 if ( value == null || value !== value ) {
djmoffat@718 5980 return;
djmoffat@718 5981 }
djmoffat@718 5982
djmoffat@718 5983 // If a number, add 'px' to the (except for certain CSS properties)
djmoffat@718 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
djmoffat@718 5985 value += "px";
djmoffat@718 5986 }
djmoffat@718 5987
djmoffat@718 5988 // Support: IE9-11+
djmoffat@718 5989 // background-* props affect original clone's values
djmoffat@718 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
djmoffat@718 5991 style[ name ] = "inherit";
djmoffat@718 5992 }
djmoffat@718 5993
djmoffat@718 5994 // If a hook was provided, use that value, otherwise just set the specified value
djmoffat@718 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
djmoffat@718 5996 style[ name ] = value;
djmoffat@718 5997 }
djmoffat@718 5998
djmoffat@718 5999 } else {
djmoffat@718 6000 // If a hook was provided get the non-computed value from there
djmoffat@718 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
djmoffat@718 6002 return ret;
djmoffat@718 6003 }
djmoffat@718 6004
djmoffat@718 6005 // Otherwise just get the value from the style object
djmoffat@718 6006 return style[ name ];
djmoffat@718 6007 }
djmoffat@718 6008 },
djmoffat@718 6009
djmoffat@718 6010 css: function( elem, name, extra, styles ) {
djmoffat@718 6011 var val, num, hooks,
djmoffat@718 6012 origName = jQuery.camelCase( name );
djmoffat@718 6013
djmoffat@718 6014 // Make sure that we're working with the right name
djmoffat@718 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
djmoffat@718 6016
djmoffat@718 6017 // Try prefixed name followed by the unprefixed name
djmoffat@718 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
djmoffat@718 6019
djmoffat@718 6020 // If a hook was provided get the computed value from there
djmoffat@718 6021 if ( hooks && "get" in hooks ) {
djmoffat@718 6022 val = hooks.get( elem, true, extra );
djmoffat@718 6023 }
djmoffat@718 6024
djmoffat@718 6025 // Otherwise, if a way to get the computed value exists, use that
djmoffat@718 6026 if ( val === undefined ) {
djmoffat@718 6027 val = curCSS( elem, name, styles );
djmoffat@718 6028 }
djmoffat@718 6029
djmoffat@718 6030 // Convert "normal" to computed value
djmoffat@718 6031 if ( val === "normal" && name in cssNormalTransform ) {
djmoffat@718 6032 val = cssNormalTransform[ name ];
djmoffat@718 6033 }
djmoffat@718 6034
djmoffat@718 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
djmoffat@718 6036 if ( extra === "" || extra ) {
djmoffat@718 6037 num = parseFloat( val );
djmoffat@718 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
djmoffat@718 6039 }
djmoffat@718 6040 return val;
djmoffat@718 6041 }
djmoffat@718 6042 });
djmoffat@718 6043
djmoffat@718 6044 jQuery.each([ "height", "width" ], function( i, name ) {
djmoffat@718 6045 jQuery.cssHooks[ name ] = {
djmoffat@718 6046 get: function( elem, computed, extra ) {
djmoffat@718 6047 if ( computed ) {
djmoffat@718 6048
djmoffat@718 6049 // Certain elements can have dimension info if we invisibly show them
djmoffat@718 6050 // but it must have a current display style that would benefit
djmoffat@718 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
djmoffat@718 6052 jQuery.swap( elem, cssShow, function() {
djmoffat@718 6053 return getWidthOrHeight( elem, name, extra );
djmoffat@718 6054 }) :
djmoffat@718 6055 getWidthOrHeight( elem, name, extra );
djmoffat@718 6056 }
djmoffat@718 6057 },
djmoffat@718 6058
djmoffat@718 6059 set: function( elem, value, extra ) {
djmoffat@718 6060 var styles = extra && getStyles( elem );
djmoffat@718 6061 return setPositiveNumber( elem, value, extra ?
djmoffat@718 6062 augmentWidthOrHeight(
djmoffat@718 6063 elem,
djmoffat@718 6064 name,
djmoffat@718 6065 extra,
djmoffat@718 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
djmoffat@718 6067 styles
djmoffat@718 6068 ) : 0
djmoffat@718 6069 );
djmoffat@718 6070 }
djmoffat@718 6071 };
djmoffat@718 6072 });
djmoffat@718 6073
djmoffat@718 6074 // Support: Android 2.3
djmoffat@718 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
djmoffat@718 6076 function( elem, computed ) {
djmoffat@718 6077 if ( computed ) {
djmoffat@718 6078 return jQuery.swap( elem, { "display": "inline-block" },
djmoffat@718 6079 curCSS, [ elem, "marginRight" ] );
djmoffat@718 6080 }
djmoffat@718 6081 }
djmoffat@718 6082 );
djmoffat@718 6083
djmoffat@718 6084 // These hooks are used by animate to expand properties
djmoffat@718 6085 jQuery.each({
djmoffat@718 6086 margin: "",
djmoffat@718 6087 padding: "",
djmoffat@718 6088 border: "Width"
djmoffat@718 6089 }, function( prefix, suffix ) {
djmoffat@718 6090 jQuery.cssHooks[ prefix + suffix ] = {
djmoffat@718 6091 expand: function( value ) {
djmoffat@718 6092 var i = 0,
djmoffat@718 6093 expanded = {},
djmoffat@718 6094
djmoffat@718 6095 // Assumes a single number if not a string
djmoffat@718 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
djmoffat@718 6097
djmoffat@718 6098 for ( ; i < 4; i++ ) {
djmoffat@718 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
djmoffat@718 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
djmoffat@718 6101 }
djmoffat@718 6102
djmoffat@718 6103 return expanded;
djmoffat@718 6104 }
djmoffat@718 6105 };
djmoffat@718 6106
djmoffat@718 6107 if ( !rmargin.test( prefix ) ) {
djmoffat@718 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
djmoffat@718 6109 }
djmoffat@718 6110 });
djmoffat@718 6111
djmoffat@718 6112 jQuery.fn.extend({
djmoffat@718 6113 css: function( name, value ) {
djmoffat@718 6114 return access( this, function( elem, name, value ) {
djmoffat@718 6115 var styles, len,
djmoffat@718 6116 map = {},
djmoffat@718 6117 i = 0;
djmoffat@718 6118
djmoffat@718 6119 if ( jQuery.isArray( name ) ) {
djmoffat@718 6120 styles = getStyles( elem );
djmoffat@718 6121 len = name.length;
djmoffat@718 6122
djmoffat@718 6123 for ( ; i < len; i++ ) {
djmoffat@718 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
djmoffat@718 6125 }
djmoffat@718 6126
djmoffat@718 6127 return map;
djmoffat@718 6128 }
djmoffat@718 6129
djmoffat@718 6130 return value !== undefined ?
djmoffat@718 6131 jQuery.style( elem, name, value ) :
djmoffat@718 6132 jQuery.css( elem, name );
djmoffat@718 6133 }, name, value, arguments.length > 1 );
djmoffat@718 6134 },
djmoffat@718 6135 show: function() {
djmoffat@718 6136 return showHide( this, true );
djmoffat@718 6137 },
djmoffat@718 6138 hide: function() {
djmoffat@718 6139 return showHide( this );
djmoffat@718 6140 },
djmoffat@718 6141 toggle: function( state ) {
djmoffat@718 6142 if ( typeof state === "boolean" ) {
djmoffat@718 6143 return state ? this.show() : this.hide();
djmoffat@718 6144 }
djmoffat@718 6145
djmoffat@718 6146 return this.each(function() {
djmoffat@718 6147 if ( isHidden( this ) ) {
djmoffat@718 6148 jQuery( this ).show();
djmoffat@718 6149 } else {
djmoffat@718 6150 jQuery( this ).hide();
djmoffat@718 6151 }
djmoffat@718 6152 });
djmoffat@718 6153 }
djmoffat@718 6154 });
djmoffat@718 6155
djmoffat@718 6156
djmoffat@718 6157 function Tween( elem, options, prop, end, easing ) {
djmoffat@718 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
djmoffat@718 6159 }
djmoffat@718 6160 jQuery.Tween = Tween;
djmoffat@718 6161
djmoffat@718 6162 Tween.prototype = {
djmoffat@718 6163 constructor: Tween,
djmoffat@718 6164 init: function( elem, options, prop, end, easing, unit ) {
djmoffat@718 6165 this.elem = elem;
djmoffat@718 6166 this.prop = prop;
djmoffat@718 6167 this.easing = easing || "swing";
djmoffat@718 6168 this.options = options;
djmoffat@718 6169 this.start = this.now = this.cur();
djmoffat@718 6170 this.end = end;
djmoffat@718 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
djmoffat@718 6172 },
djmoffat@718 6173 cur: function() {
djmoffat@718 6174 var hooks = Tween.propHooks[ this.prop ];
djmoffat@718 6175
djmoffat@718 6176 return hooks && hooks.get ?
djmoffat@718 6177 hooks.get( this ) :
djmoffat@718 6178 Tween.propHooks._default.get( this );
djmoffat@718 6179 },
djmoffat@718 6180 run: function( percent ) {
djmoffat@718 6181 var eased,
djmoffat@718 6182 hooks = Tween.propHooks[ this.prop ];
djmoffat@718 6183
djmoffat@718 6184 if ( this.options.duration ) {
djmoffat@718 6185 this.pos = eased = jQuery.easing[ this.easing ](
djmoffat@718 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
djmoffat@718 6187 );
djmoffat@718 6188 } else {
djmoffat@718 6189 this.pos = eased = percent;
djmoffat@718 6190 }
djmoffat@718 6191 this.now = ( this.end - this.start ) * eased + this.start;
djmoffat@718 6192
djmoffat@718 6193 if ( this.options.step ) {
djmoffat@718 6194 this.options.step.call( this.elem, this.now, this );
djmoffat@718 6195 }
djmoffat@718 6196
djmoffat@718 6197 if ( hooks && hooks.set ) {
djmoffat@718 6198 hooks.set( this );
djmoffat@718 6199 } else {
djmoffat@718 6200 Tween.propHooks._default.set( this );
djmoffat@718 6201 }
djmoffat@718 6202 return this;
djmoffat@718 6203 }
djmoffat@718 6204 };
djmoffat@718 6205
djmoffat@718 6206 Tween.prototype.init.prototype = Tween.prototype;
djmoffat@718 6207
djmoffat@718 6208 Tween.propHooks = {
djmoffat@718 6209 _default: {
djmoffat@718 6210 get: function( tween ) {
djmoffat@718 6211 var result;
djmoffat@718 6212
djmoffat@718 6213 if ( tween.elem[ tween.prop ] != null &&
djmoffat@718 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
djmoffat@718 6215 return tween.elem[ tween.prop ];
djmoffat@718 6216 }
djmoffat@718 6217
djmoffat@718 6218 // Passing an empty string as a 3rd parameter to .css will automatically
djmoffat@718 6219 // attempt a parseFloat and fallback to a string if the parse fails.
djmoffat@718 6220 // Simple values such as "10px" are parsed to Float;
djmoffat@718 6221 // complex values such as "rotate(1rad)" are returned as-is.
djmoffat@718 6222 result = jQuery.css( tween.elem, tween.prop, "" );
djmoffat@718 6223 // Empty strings, null, undefined and "auto" are converted to 0.
djmoffat@718 6224 return !result || result === "auto" ? 0 : result;
djmoffat@718 6225 },
djmoffat@718 6226 set: function( tween ) {
djmoffat@718 6227 // Use step hook for back compat.
djmoffat@718 6228 // Use cssHook if its there.
djmoffat@718 6229 // Use .style if available and use plain properties where available.
djmoffat@718 6230 if ( jQuery.fx.step[ tween.prop ] ) {
djmoffat@718 6231 jQuery.fx.step[ tween.prop ]( tween );
djmoffat@718 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
djmoffat@718 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
djmoffat@718 6234 } else {
djmoffat@718 6235 tween.elem[ tween.prop ] = tween.now;
djmoffat@718 6236 }
djmoffat@718 6237 }
djmoffat@718 6238 }
djmoffat@718 6239 };
djmoffat@718 6240
djmoffat@718 6241 // Support: IE9
djmoffat@718 6242 // Panic based approach to setting things on disconnected nodes
djmoffat@718 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
djmoffat@718 6244 set: function( tween ) {
djmoffat@718 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
djmoffat@718 6246 tween.elem[ tween.prop ] = tween.now;
djmoffat@718 6247 }
djmoffat@718 6248 }
djmoffat@718 6249 };
djmoffat@718 6250
djmoffat@718 6251 jQuery.easing = {
djmoffat@718 6252 linear: function( p ) {
djmoffat@718 6253 return p;
djmoffat@718 6254 },
djmoffat@718 6255 swing: function( p ) {
djmoffat@718 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
djmoffat@718 6257 }
djmoffat@718 6258 };
djmoffat@718 6259
djmoffat@718 6260 jQuery.fx = Tween.prototype.init;
djmoffat@718 6261
djmoffat@718 6262 // Back Compat <1.8 extension point
djmoffat@718 6263 jQuery.fx.step = {};
djmoffat@718 6264
djmoffat@718 6265
djmoffat@718 6266
djmoffat@718 6267
djmoffat@718 6268 var
djmoffat@718 6269 fxNow, timerId,
djmoffat@718 6270 rfxtypes = /^(?:toggle|show|hide)$/,
djmoffat@718 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
djmoffat@718 6272 rrun = /queueHooks$/,
djmoffat@718 6273 animationPrefilters = [ defaultPrefilter ],
djmoffat@718 6274 tweeners = {
djmoffat@718 6275 "*": [ function( prop, value ) {
djmoffat@718 6276 var tween = this.createTween( prop, value ),
djmoffat@718 6277 target = tween.cur(),
djmoffat@718 6278 parts = rfxnum.exec( value ),
djmoffat@718 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
djmoffat@718 6280
djmoffat@718 6281 // Starting value computation is required for potential unit mismatches
djmoffat@718 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
djmoffat@718 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
djmoffat@718 6284 scale = 1,
djmoffat@718 6285 maxIterations = 20;
djmoffat@718 6286
djmoffat@718 6287 if ( start && start[ 3 ] !== unit ) {
djmoffat@718 6288 // Trust units reported by jQuery.css
djmoffat@718 6289 unit = unit || start[ 3 ];
djmoffat@718 6290
djmoffat@718 6291 // Make sure we update the tween properties later on
djmoffat@718 6292 parts = parts || [];
djmoffat@718 6293
djmoffat@718 6294 // Iteratively approximate from a nonzero starting point
djmoffat@718 6295 start = +target || 1;
djmoffat@718 6296
djmoffat@718 6297 do {
djmoffat@718 6298 // If previous iteration zeroed out, double until we get *something*.
djmoffat@718 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
djmoffat@718 6300 scale = scale || ".5";
djmoffat@718 6301
djmoffat@718 6302 // Adjust and apply
djmoffat@718 6303 start = start / scale;
djmoffat@718 6304 jQuery.style( tween.elem, prop, start + unit );
djmoffat@718 6305
djmoffat@718 6306 // Update scale, tolerating zero or NaN from tween.cur(),
djmoffat@718 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
djmoffat@718 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
djmoffat@718 6309 }
djmoffat@718 6310
djmoffat@718 6311 // Update tween properties
djmoffat@718 6312 if ( parts ) {
djmoffat@718 6313 start = tween.start = +start || +target || 0;
djmoffat@718 6314 tween.unit = unit;
djmoffat@718 6315 // If a +=/-= token was provided, we're doing a relative animation
djmoffat@718 6316 tween.end = parts[ 1 ] ?
djmoffat@718 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
djmoffat@718 6318 +parts[ 2 ];
djmoffat@718 6319 }
djmoffat@718 6320
djmoffat@718 6321 return tween;
djmoffat@718 6322 } ]
djmoffat@718 6323 };
djmoffat@718 6324
djmoffat@718 6325 // Animations created synchronously will run synchronously
djmoffat@718 6326 function createFxNow() {
djmoffat@718 6327 setTimeout(function() {
djmoffat@718 6328 fxNow = undefined;
djmoffat@718 6329 });
djmoffat@718 6330 return ( fxNow = jQuery.now() );
djmoffat@718 6331 }
djmoffat@718 6332
djmoffat@718 6333 // Generate parameters to create a standard animation
djmoffat@718 6334 function genFx( type, includeWidth ) {
djmoffat@718 6335 var which,
djmoffat@718 6336 i = 0,
djmoffat@718 6337 attrs = { height: type };
djmoffat@718 6338
djmoffat@718 6339 // If we include width, step value is 1 to do all cssExpand values,
djmoffat@718 6340 // otherwise step value is 2 to skip over Left and Right
djmoffat@718 6341 includeWidth = includeWidth ? 1 : 0;
djmoffat@718 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
djmoffat@718 6343 which = cssExpand[ i ];
djmoffat@718 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
djmoffat@718 6345 }
djmoffat@718 6346
djmoffat@718 6347 if ( includeWidth ) {
djmoffat@718 6348 attrs.opacity = attrs.width = type;
djmoffat@718 6349 }
djmoffat@718 6350
djmoffat@718 6351 return attrs;
djmoffat@718 6352 }
djmoffat@718 6353
djmoffat@718 6354 function createTween( value, prop, animation ) {
djmoffat@718 6355 var tween,
djmoffat@718 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
djmoffat@718 6357 index = 0,
djmoffat@718 6358 length = collection.length;
djmoffat@718 6359 for ( ; index < length; index++ ) {
djmoffat@718 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
djmoffat@718 6361
djmoffat@718 6362 // We're done with this property
djmoffat@718 6363 return tween;
djmoffat@718 6364 }
djmoffat@718 6365 }
djmoffat@718 6366 }
djmoffat@718 6367
djmoffat@718 6368 function defaultPrefilter( elem, props, opts ) {
djmoffat@718 6369 /* jshint validthis: true */
djmoffat@718 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
djmoffat@718 6371 anim = this,
djmoffat@718 6372 orig = {},
djmoffat@718 6373 style = elem.style,
djmoffat@718 6374 hidden = elem.nodeType && isHidden( elem ),
djmoffat@718 6375 dataShow = data_priv.get( elem, "fxshow" );
djmoffat@718 6376
djmoffat@718 6377 // Handle queue: false promises
djmoffat@718 6378 if ( !opts.queue ) {
djmoffat@718 6379 hooks = jQuery._queueHooks( elem, "fx" );
djmoffat@718 6380 if ( hooks.unqueued == null ) {
djmoffat@718 6381 hooks.unqueued = 0;
djmoffat@718 6382 oldfire = hooks.empty.fire;
djmoffat@718 6383 hooks.empty.fire = function() {
djmoffat@718 6384 if ( !hooks.unqueued ) {
djmoffat@718 6385 oldfire();
djmoffat@718 6386 }
djmoffat@718 6387 };
djmoffat@718 6388 }
djmoffat@718 6389 hooks.unqueued++;
djmoffat@718 6390
djmoffat@718 6391 anim.always(function() {
djmoffat@718 6392 // Ensure the complete handler is called before this completes
djmoffat@718 6393 anim.always(function() {
djmoffat@718 6394 hooks.unqueued--;
djmoffat@718 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
djmoffat@718 6396 hooks.empty.fire();
djmoffat@718 6397 }
djmoffat@718 6398 });
djmoffat@718 6399 });
djmoffat@718 6400 }
djmoffat@718 6401
djmoffat@718 6402 // Height/width overflow pass
djmoffat@718 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
djmoffat@718 6404 // Make sure that nothing sneaks out
djmoffat@718 6405 // Record all 3 overflow attributes because IE9-10 do not
djmoffat@718 6406 // change the overflow attribute when overflowX and
djmoffat@718 6407 // overflowY are set to the same value
djmoffat@718 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
djmoffat@718 6409
djmoffat@718 6410 // Set display property to inline-block for height/width
djmoffat@718 6411 // animations on inline elements that are having width/height animated
djmoffat@718 6412 display = jQuery.css( elem, "display" );
djmoffat@718 6413
djmoffat@718 6414 // Test default display if display is currently "none"
djmoffat@718 6415 checkDisplay = display === "none" ?
djmoffat@718 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
djmoffat@718 6417
djmoffat@718 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
djmoffat@718 6419 style.display = "inline-block";
djmoffat@718 6420 }
djmoffat@718 6421 }
djmoffat@718 6422
djmoffat@718 6423 if ( opts.overflow ) {
djmoffat@718 6424 style.overflow = "hidden";
djmoffat@718 6425 anim.always(function() {
djmoffat@718 6426 style.overflow = opts.overflow[ 0 ];
djmoffat@718 6427 style.overflowX = opts.overflow[ 1 ];
djmoffat@718 6428 style.overflowY = opts.overflow[ 2 ];
djmoffat@718 6429 });
djmoffat@718 6430 }
djmoffat@718 6431
djmoffat@718 6432 // show/hide pass
djmoffat@718 6433 for ( prop in props ) {
djmoffat@718 6434 value = props[ prop ];
djmoffat@718 6435 if ( rfxtypes.exec( value ) ) {
djmoffat@718 6436 delete props[ prop ];
djmoffat@718 6437 toggle = toggle || value === "toggle";
djmoffat@718 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
djmoffat@718 6439
djmoffat@718 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
djmoffat@718 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
djmoffat@718 6442 hidden = true;
djmoffat@718 6443 } else {
djmoffat@718 6444 continue;
djmoffat@718 6445 }
djmoffat@718 6446 }
djmoffat@718 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
djmoffat@718 6448
djmoffat@718 6449 // Any non-fx value stops us from restoring the original display value
djmoffat@718 6450 } else {
djmoffat@718 6451 display = undefined;
djmoffat@718 6452 }
djmoffat@718 6453 }
djmoffat@718 6454
djmoffat@718 6455 if ( !jQuery.isEmptyObject( orig ) ) {
djmoffat@718 6456 if ( dataShow ) {
djmoffat@718 6457 if ( "hidden" in dataShow ) {
djmoffat@718 6458 hidden = dataShow.hidden;
djmoffat@718 6459 }
djmoffat@718 6460 } else {
djmoffat@718 6461 dataShow = data_priv.access( elem, "fxshow", {} );
djmoffat@718 6462 }
djmoffat@718 6463
djmoffat@718 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
djmoffat@718 6465 if ( toggle ) {
djmoffat@718 6466 dataShow.hidden = !hidden;
djmoffat@718 6467 }
djmoffat@718 6468 if ( hidden ) {
djmoffat@718 6469 jQuery( elem ).show();
djmoffat@718 6470 } else {
djmoffat@718 6471 anim.done(function() {
djmoffat@718 6472 jQuery( elem ).hide();
djmoffat@718 6473 });
djmoffat@718 6474 }
djmoffat@718 6475 anim.done(function() {
djmoffat@718 6476 var prop;
djmoffat@718 6477
djmoffat@718 6478 data_priv.remove( elem, "fxshow" );
djmoffat@718 6479 for ( prop in orig ) {
djmoffat@718 6480 jQuery.style( elem, prop, orig[ prop ] );
djmoffat@718 6481 }
djmoffat@718 6482 });
djmoffat@718 6483 for ( prop in orig ) {
djmoffat@718 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
djmoffat@718 6485
djmoffat@718 6486 if ( !( prop in dataShow ) ) {
djmoffat@718 6487 dataShow[ prop ] = tween.start;
djmoffat@718 6488 if ( hidden ) {
djmoffat@718 6489 tween.end = tween.start;
djmoffat@718 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
djmoffat@718 6491 }
djmoffat@718 6492 }
djmoffat@718 6493 }
djmoffat@718 6494
djmoffat@718 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
djmoffat@718 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
djmoffat@718 6497 style.display = display;
djmoffat@718 6498 }
djmoffat@718 6499 }
djmoffat@718 6500
djmoffat@718 6501 function propFilter( props, specialEasing ) {
djmoffat@718 6502 var index, name, easing, value, hooks;
djmoffat@718 6503
djmoffat@718 6504 // camelCase, specialEasing and expand cssHook pass
djmoffat@718 6505 for ( index in props ) {
djmoffat@718 6506 name = jQuery.camelCase( index );
djmoffat@718 6507 easing = specialEasing[ name ];
djmoffat@718 6508 value = props[ index ];
djmoffat@718 6509 if ( jQuery.isArray( value ) ) {
djmoffat@718 6510 easing = value[ 1 ];
djmoffat@718 6511 value = props[ index ] = value[ 0 ];
djmoffat@718 6512 }
djmoffat@718 6513
djmoffat@718 6514 if ( index !== name ) {
djmoffat@718 6515 props[ name ] = value;
djmoffat@718 6516 delete props[ index ];
djmoffat@718 6517 }
djmoffat@718 6518
djmoffat@718 6519 hooks = jQuery.cssHooks[ name ];
djmoffat@718 6520 if ( hooks && "expand" in hooks ) {
djmoffat@718 6521 value = hooks.expand( value );
djmoffat@718 6522 delete props[ name ];
djmoffat@718 6523
djmoffat@718 6524 // Not quite $.extend, this won't overwrite existing keys.
djmoffat@718 6525 // Reusing 'index' because we have the correct "name"
djmoffat@718 6526 for ( index in value ) {
djmoffat@718 6527 if ( !( index in props ) ) {
djmoffat@718 6528 props[ index ] = value[ index ];
djmoffat@718 6529 specialEasing[ index ] = easing;
djmoffat@718 6530 }
djmoffat@718 6531 }
djmoffat@718 6532 } else {
djmoffat@718 6533 specialEasing[ name ] = easing;
djmoffat@718 6534 }
djmoffat@718 6535 }
djmoffat@718 6536 }
djmoffat@718 6537
djmoffat@718 6538 function Animation( elem, properties, options ) {
djmoffat@718 6539 var result,
djmoffat@718 6540 stopped,
djmoffat@718 6541 index = 0,
djmoffat@718 6542 length = animationPrefilters.length,
djmoffat@718 6543 deferred = jQuery.Deferred().always( function() {
djmoffat@718 6544 // Don't match elem in the :animated selector
djmoffat@718 6545 delete tick.elem;
djmoffat@718 6546 }),
djmoffat@718 6547 tick = function() {
djmoffat@718 6548 if ( stopped ) {
djmoffat@718 6549 return false;
djmoffat@718 6550 }
djmoffat@718 6551 var currentTime = fxNow || createFxNow(),
djmoffat@718 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
djmoffat@718 6553 // Support: Android 2.3
djmoffat@718 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
djmoffat@718 6555 temp = remaining / animation.duration || 0,
djmoffat@718 6556 percent = 1 - temp,
djmoffat@718 6557 index = 0,
djmoffat@718 6558 length = animation.tweens.length;
djmoffat@718 6559
djmoffat@718 6560 for ( ; index < length ; index++ ) {
djmoffat@718 6561 animation.tweens[ index ].run( percent );
djmoffat@718 6562 }
djmoffat@718 6563
djmoffat@718 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
djmoffat@718 6565
djmoffat@718 6566 if ( percent < 1 && length ) {
djmoffat@718 6567 return remaining;
djmoffat@718 6568 } else {
djmoffat@718 6569 deferred.resolveWith( elem, [ animation ] );
djmoffat@718 6570 return false;
djmoffat@718 6571 }
djmoffat@718 6572 },
djmoffat@718 6573 animation = deferred.promise({
djmoffat@718 6574 elem: elem,
djmoffat@718 6575 props: jQuery.extend( {}, properties ),
djmoffat@718 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
djmoffat@718 6577 originalProperties: properties,
djmoffat@718 6578 originalOptions: options,
djmoffat@718 6579 startTime: fxNow || createFxNow(),
djmoffat@718 6580 duration: options.duration,
djmoffat@718 6581 tweens: [],
djmoffat@718 6582 createTween: function( prop, end ) {
djmoffat@718 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
djmoffat@718 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
djmoffat@718 6585 animation.tweens.push( tween );
djmoffat@718 6586 return tween;
djmoffat@718 6587 },
djmoffat@718 6588 stop: function( gotoEnd ) {
djmoffat@718 6589 var index = 0,
djmoffat@718 6590 // If we are going to the end, we want to run all the tweens
djmoffat@718 6591 // otherwise we skip this part
djmoffat@718 6592 length = gotoEnd ? animation.tweens.length : 0;
djmoffat@718 6593 if ( stopped ) {
djmoffat@718 6594 return this;
djmoffat@718 6595 }
djmoffat@718 6596 stopped = true;
djmoffat@718 6597 for ( ; index < length ; index++ ) {
djmoffat@718 6598 animation.tweens[ index ].run( 1 );
djmoffat@718 6599 }
djmoffat@718 6600
djmoffat@718 6601 // Resolve when we played the last frame; otherwise, reject
djmoffat@718 6602 if ( gotoEnd ) {
djmoffat@718 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
djmoffat@718 6604 } else {
djmoffat@718 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
djmoffat@718 6606 }
djmoffat@718 6607 return this;
djmoffat@718 6608 }
djmoffat@718 6609 }),
djmoffat@718 6610 props = animation.props;
djmoffat@718 6611
djmoffat@718 6612 propFilter( props, animation.opts.specialEasing );
djmoffat@718 6613
djmoffat@718 6614 for ( ; index < length ; index++ ) {
djmoffat@718 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
djmoffat@718 6616 if ( result ) {
djmoffat@718 6617 return result;
djmoffat@718 6618 }
djmoffat@718 6619 }
djmoffat@718 6620
djmoffat@718 6621 jQuery.map( props, createTween, animation );
djmoffat@718 6622
djmoffat@718 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
djmoffat@718 6624 animation.opts.start.call( elem, animation );
djmoffat@718 6625 }
djmoffat@718 6626
djmoffat@718 6627 jQuery.fx.timer(
djmoffat@718 6628 jQuery.extend( tick, {
djmoffat@718 6629 elem: elem,
djmoffat@718 6630 anim: animation,
djmoffat@718 6631 queue: animation.opts.queue
djmoffat@718 6632 })
djmoffat@718 6633 );
djmoffat@718 6634
djmoffat@718 6635 // attach callbacks from options
djmoffat@718 6636 return animation.progress( animation.opts.progress )
djmoffat@718 6637 .done( animation.opts.done, animation.opts.complete )
djmoffat@718 6638 .fail( animation.opts.fail )
djmoffat@718 6639 .always( animation.opts.always );
djmoffat@718 6640 }
djmoffat@718 6641
djmoffat@718 6642 jQuery.Animation = jQuery.extend( Animation, {
djmoffat@718 6643
djmoffat@718 6644 tweener: function( props, callback ) {
djmoffat@718 6645 if ( jQuery.isFunction( props ) ) {
djmoffat@718 6646 callback = props;
djmoffat@718 6647 props = [ "*" ];
djmoffat@718 6648 } else {
djmoffat@718 6649 props = props.split(" ");
djmoffat@718 6650 }
djmoffat@718 6651
djmoffat@718 6652 var prop,
djmoffat@718 6653 index = 0,
djmoffat@718 6654 length = props.length;
djmoffat@718 6655
djmoffat@718 6656 for ( ; index < length ; index++ ) {
djmoffat@718 6657 prop = props[ index ];
djmoffat@718 6658 tweeners[ prop ] = tweeners[ prop ] || [];
djmoffat@718 6659 tweeners[ prop ].unshift( callback );
djmoffat@718 6660 }
djmoffat@718 6661 },
djmoffat@718 6662
djmoffat@718 6663 prefilter: function( callback, prepend ) {
djmoffat@718 6664 if ( prepend ) {
djmoffat@718 6665 animationPrefilters.unshift( callback );
djmoffat@718 6666 } else {
djmoffat@718 6667 animationPrefilters.push( callback );
djmoffat@718 6668 }
djmoffat@718 6669 }
djmoffat@718 6670 });
djmoffat@718 6671
djmoffat@718 6672 jQuery.speed = function( speed, easing, fn ) {
djmoffat@718 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
djmoffat@718 6674 complete: fn || !fn && easing ||
djmoffat@718 6675 jQuery.isFunction( speed ) && speed,
djmoffat@718 6676 duration: speed,
djmoffat@718 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
djmoffat@718 6678 };
djmoffat@718 6679
djmoffat@718 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
djmoffat@718 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
djmoffat@718 6682
djmoffat@718 6683 // Normalize opt.queue - true/undefined/null -> "fx"
djmoffat@718 6684 if ( opt.queue == null || opt.queue === true ) {
djmoffat@718 6685 opt.queue = "fx";
djmoffat@718 6686 }
djmoffat@718 6687
djmoffat@718 6688 // Queueing
djmoffat@718 6689 opt.old = opt.complete;
djmoffat@718 6690
djmoffat@718 6691 opt.complete = function() {
djmoffat@718 6692 if ( jQuery.isFunction( opt.old ) ) {
djmoffat@718 6693 opt.old.call( this );
djmoffat@718 6694 }
djmoffat@718 6695
djmoffat@718 6696 if ( opt.queue ) {
djmoffat@718 6697 jQuery.dequeue( this, opt.queue );
djmoffat@718 6698 }
djmoffat@718 6699 };
djmoffat@718 6700
djmoffat@718 6701 return opt;
djmoffat@718 6702 };
djmoffat@718 6703
djmoffat@718 6704 jQuery.fn.extend({
djmoffat@718 6705 fadeTo: function( speed, to, easing, callback ) {
djmoffat@718 6706
djmoffat@718 6707 // Show any hidden elements after setting opacity to 0
djmoffat@718 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
djmoffat@718 6709
djmoffat@718 6710 // Animate to the value specified
djmoffat@718 6711 .end().animate({ opacity: to }, speed, easing, callback );
djmoffat@718 6712 },
djmoffat@718 6713 animate: function( prop, speed, easing, callback ) {
djmoffat@718 6714 var empty = jQuery.isEmptyObject( prop ),
djmoffat@718 6715 optall = jQuery.speed( speed, easing, callback ),
djmoffat@718 6716 doAnimation = function() {
djmoffat@718 6717 // Operate on a copy of prop so per-property easing won't be lost
djmoffat@718 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
djmoffat@718 6719
djmoffat@718 6720 // Empty animations, or finishing resolves immediately
djmoffat@718 6721 if ( empty || data_priv.get( this, "finish" ) ) {
djmoffat@718 6722 anim.stop( true );
djmoffat@718 6723 }
djmoffat@718 6724 };
djmoffat@718 6725 doAnimation.finish = doAnimation;
djmoffat@718 6726
djmoffat@718 6727 return empty || optall.queue === false ?
djmoffat@718 6728 this.each( doAnimation ) :
djmoffat@718 6729 this.queue( optall.queue, doAnimation );
djmoffat@718 6730 },
djmoffat@718 6731 stop: function( type, clearQueue, gotoEnd ) {
djmoffat@718 6732 var stopQueue = function( hooks ) {
djmoffat@718 6733 var stop = hooks.stop;
djmoffat@718 6734 delete hooks.stop;
djmoffat@718 6735 stop( gotoEnd );
djmoffat@718 6736 };
djmoffat@718 6737
djmoffat@718 6738 if ( typeof type !== "string" ) {
djmoffat@718 6739 gotoEnd = clearQueue;
djmoffat@718 6740 clearQueue = type;
djmoffat@718 6741 type = undefined;
djmoffat@718 6742 }
djmoffat@718 6743 if ( clearQueue && type !== false ) {
djmoffat@718 6744 this.queue( type || "fx", [] );
djmoffat@718 6745 }
djmoffat@718 6746
djmoffat@718 6747 return this.each(function() {
djmoffat@718 6748 var dequeue = true,
djmoffat@718 6749 index = type != null && type + "queueHooks",
djmoffat@718 6750 timers = jQuery.timers,
djmoffat@718 6751 data = data_priv.get( this );
djmoffat@718 6752
djmoffat@718 6753 if ( index ) {
djmoffat@718 6754 if ( data[ index ] && data[ index ].stop ) {
djmoffat@718 6755 stopQueue( data[ index ] );
djmoffat@718 6756 }
djmoffat@718 6757 } else {
djmoffat@718 6758 for ( index in data ) {
djmoffat@718 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
djmoffat@718 6760 stopQueue( data[ index ] );
djmoffat@718 6761 }
djmoffat@718 6762 }
djmoffat@718 6763 }
djmoffat@718 6764
djmoffat@718 6765 for ( index = timers.length; index--; ) {
djmoffat@718 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
djmoffat@718 6767 timers[ index ].anim.stop( gotoEnd );
djmoffat@718 6768 dequeue = false;
djmoffat@718 6769 timers.splice( index, 1 );
djmoffat@718 6770 }
djmoffat@718 6771 }
djmoffat@718 6772
djmoffat@718 6773 // Start the next in the queue if the last step wasn't forced.
djmoffat@718 6774 // Timers currently will call their complete callbacks, which
djmoffat@718 6775 // will dequeue but only if they were gotoEnd.
djmoffat@718 6776 if ( dequeue || !gotoEnd ) {
djmoffat@718 6777 jQuery.dequeue( this, type );
djmoffat@718 6778 }
djmoffat@718 6779 });
djmoffat@718 6780 },
djmoffat@718 6781 finish: function( type ) {
djmoffat@718 6782 if ( type !== false ) {
djmoffat@718 6783 type = type || "fx";
djmoffat@718 6784 }
djmoffat@718 6785 return this.each(function() {
djmoffat@718 6786 var index,
djmoffat@718 6787 data = data_priv.get( this ),
djmoffat@718 6788 queue = data[ type + "queue" ],
djmoffat@718 6789 hooks = data[ type + "queueHooks" ],
djmoffat@718 6790 timers = jQuery.timers,
djmoffat@718 6791 length = queue ? queue.length : 0;
djmoffat@718 6792
djmoffat@718 6793 // Enable finishing flag on private data
djmoffat@718 6794 data.finish = true;
djmoffat@718 6795
djmoffat@718 6796 // Empty the queue first
djmoffat@718 6797 jQuery.queue( this, type, [] );
djmoffat@718 6798
djmoffat@718 6799 if ( hooks && hooks.stop ) {
djmoffat@718 6800 hooks.stop.call( this, true );
djmoffat@718 6801 }
djmoffat@718 6802
djmoffat@718 6803 // Look for any active animations, and finish them
djmoffat@718 6804 for ( index = timers.length; index--; ) {
djmoffat@718 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
djmoffat@718 6806 timers[ index ].anim.stop( true );
djmoffat@718 6807 timers.splice( index, 1 );
djmoffat@718 6808 }
djmoffat@718 6809 }
djmoffat@718 6810
djmoffat@718 6811 // Look for any animations in the old queue and finish them
djmoffat@718 6812 for ( index = 0; index < length; index++ ) {
djmoffat@718 6813 if ( queue[ index ] && queue[ index ].finish ) {
djmoffat@718 6814 queue[ index ].finish.call( this );
djmoffat@718 6815 }
djmoffat@718 6816 }
djmoffat@718 6817
djmoffat@718 6818 // Turn off finishing flag
djmoffat@718 6819 delete data.finish;
djmoffat@718 6820 });
djmoffat@718 6821 }
djmoffat@718 6822 });
djmoffat@718 6823
djmoffat@718 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
djmoffat@718 6825 var cssFn = jQuery.fn[ name ];
djmoffat@718 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
djmoffat@718 6827 return speed == null || typeof speed === "boolean" ?
djmoffat@718 6828 cssFn.apply( this, arguments ) :
djmoffat@718 6829 this.animate( genFx( name, true ), speed, easing, callback );
djmoffat@718 6830 };
djmoffat@718 6831 });
djmoffat@718 6832
djmoffat@718 6833 // Generate shortcuts for custom animations
djmoffat@718 6834 jQuery.each({
djmoffat@718 6835 slideDown: genFx("show"),
djmoffat@718 6836 slideUp: genFx("hide"),
djmoffat@718 6837 slideToggle: genFx("toggle"),
djmoffat@718 6838 fadeIn: { opacity: "show" },
djmoffat@718 6839 fadeOut: { opacity: "hide" },
djmoffat@718 6840 fadeToggle: { opacity: "toggle" }
djmoffat@718 6841 }, function( name, props ) {
djmoffat@718 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
djmoffat@718 6843 return this.animate( props, speed, easing, callback );
djmoffat@718 6844 };
djmoffat@718 6845 });
djmoffat@718 6846
djmoffat@718 6847 jQuery.timers = [];
djmoffat@718 6848 jQuery.fx.tick = function() {
djmoffat@718 6849 var timer,
djmoffat@718 6850 i = 0,
djmoffat@718 6851 timers = jQuery.timers;
djmoffat@718 6852
djmoffat@718 6853 fxNow = jQuery.now();
djmoffat@718 6854
djmoffat@718 6855 for ( ; i < timers.length; i++ ) {
djmoffat@718 6856 timer = timers[ i ];
djmoffat@718 6857 // Checks the timer has not already been removed
djmoffat@718 6858 if ( !timer() && timers[ i ] === timer ) {
djmoffat@718 6859 timers.splice( i--, 1 );
djmoffat@718 6860 }
djmoffat@718 6861 }
djmoffat@718 6862
djmoffat@718 6863 if ( !timers.length ) {
djmoffat@718 6864 jQuery.fx.stop();
djmoffat@718 6865 }
djmoffat@718 6866 fxNow = undefined;
djmoffat@718 6867 };
djmoffat@718 6868
djmoffat@718 6869 jQuery.fx.timer = function( timer ) {
djmoffat@718 6870 jQuery.timers.push( timer );
djmoffat@718 6871 if ( timer() ) {
djmoffat@718 6872 jQuery.fx.start();
djmoffat@718 6873 } else {
djmoffat@718 6874 jQuery.timers.pop();
djmoffat@718 6875 }
djmoffat@718 6876 };
djmoffat@718 6877
djmoffat@718 6878 jQuery.fx.interval = 13;
djmoffat@718 6879
djmoffat@718 6880 jQuery.fx.start = function() {
djmoffat@718 6881 if ( !timerId ) {
djmoffat@718 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
djmoffat@718 6883 }
djmoffat@718 6884 };
djmoffat@718 6885
djmoffat@718 6886 jQuery.fx.stop = function() {
djmoffat@718 6887 clearInterval( timerId );
djmoffat@718 6888 timerId = null;
djmoffat@718 6889 };
djmoffat@718 6890
djmoffat@718 6891 jQuery.fx.speeds = {
djmoffat@718 6892 slow: 600,
djmoffat@718 6893 fast: 200,
djmoffat@718 6894 // Default speed
djmoffat@718 6895 _default: 400
djmoffat@718 6896 };
djmoffat@718 6897
djmoffat@718 6898
djmoffat@718 6899 // Based off of the plugin by Clint Helfers, with permission.
djmoffat@718 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
djmoffat@718 6901 jQuery.fn.delay = function( time, type ) {
djmoffat@718 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
djmoffat@718 6903 type = type || "fx";
djmoffat@718 6904
djmoffat@718 6905 return this.queue( type, function( next, hooks ) {
djmoffat@718 6906 var timeout = setTimeout( next, time );
djmoffat@718 6907 hooks.stop = function() {
djmoffat@718 6908 clearTimeout( timeout );
djmoffat@718 6909 };
djmoffat@718 6910 });
djmoffat@718 6911 };
djmoffat@718 6912
djmoffat@718 6913
djmoffat@718 6914 (function() {
djmoffat@718 6915 var input = document.createElement( "input" ),
djmoffat@718 6916 select = document.createElement( "select" ),
djmoffat@718 6917 opt = select.appendChild( document.createElement( "option" ) );
djmoffat@718 6918
djmoffat@718 6919 input.type = "checkbox";
djmoffat@718 6920
djmoffat@718 6921 // Support: iOS<=5.1, Android<=4.2+
djmoffat@718 6922 // Default value for a checkbox should be "on"
djmoffat@718 6923 support.checkOn = input.value !== "";
djmoffat@718 6924
djmoffat@718 6925 // Support: IE<=11+
djmoffat@718 6926 // Must access selectedIndex to make default options select
djmoffat@718 6927 support.optSelected = opt.selected;
djmoffat@718 6928
djmoffat@718 6929 // Support: Android<=2.3
djmoffat@718 6930 // Options inside disabled selects are incorrectly marked as disabled
djmoffat@718 6931 select.disabled = true;
djmoffat@718 6932 support.optDisabled = !opt.disabled;
djmoffat@718 6933
djmoffat@718 6934 // Support: IE<=11+
djmoffat@718 6935 // An input loses its value after becoming a radio
djmoffat@718 6936 input = document.createElement( "input" );
djmoffat@718 6937 input.value = "t";
djmoffat@718 6938 input.type = "radio";
djmoffat@718 6939 support.radioValue = input.value === "t";
djmoffat@718 6940 })();
djmoffat@718 6941
djmoffat@718 6942
djmoffat@718 6943 var nodeHook, boolHook,
djmoffat@718 6944 attrHandle = jQuery.expr.attrHandle;
djmoffat@718 6945
djmoffat@718 6946 jQuery.fn.extend({
djmoffat@718 6947 attr: function( name, value ) {
djmoffat@718 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
djmoffat@718 6949 },
djmoffat@718 6950
djmoffat@718 6951 removeAttr: function( name ) {
djmoffat@718 6952 return this.each(function() {
djmoffat@718 6953 jQuery.removeAttr( this, name );
djmoffat@718 6954 });
djmoffat@718 6955 }
djmoffat@718 6956 });
djmoffat@718 6957
djmoffat@718 6958 jQuery.extend({
djmoffat@718 6959 attr: function( elem, name, value ) {
djmoffat@718 6960 var hooks, ret,
djmoffat@718 6961 nType = elem.nodeType;
djmoffat@718 6962
djmoffat@718 6963 // don't get/set attributes on text, comment and attribute nodes
djmoffat@718 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
djmoffat@718 6965 return;
djmoffat@718 6966 }
djmoffat@718 6967
djmoffat@718 6968 // Fallback to prop when attributes are not supported
djmoffat@718 6969 if ( typeof elem.getAttribute === strundefined ) {
djmoffat@718 6970 return jQuery.prop( elem, name, value );
djmoffat@718 6971 }
djmoffat@718 6972
djmoffat@718 6973 // All attributes are lowercase
djmoffat@718 6974 // Grab necessary hook if one is defined
djmoffat@718 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
djmoffat@718 6976 name = name.toLowerCase();
djmoffat@718 6977 hooks = jQuery.attrHooks[ name ] ||
djmoffat@718 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
djmoffat@718 6979 }
djmoffat@718 6980
djmoffat@718 6981 if ( value !== undefined ) {
djmoffat@718 6982
djmoffat@718 6983 if ( value === null ) {
djmoffat@718 6984 jQuery.removeAttr( elem, name );
djmoffat@718 6985
djmoffat@718 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
djmoffat@718 6987 return ret;
djmoffat@718 6988
djmoffat@718 6989 } else {
djmoffat@718 6990 elem.setAttribute( name, value + "" );
djmoffat@718 6991 return value;
djmoffat@718 6992 }
djmoffat@718 6993
djmoffat@718 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
djmoffat@718 6995 return ret;
djmoffat@718 6996
djmoffat@718 6997 } else {
djmoffat@718 6998 ret = jQuery.find.attr( elem, name );
djmoffat@718 6999
djmoffat@718 7000 // Non-existent attributes return null, we normalize to undefined
djmoffat@718 7001 return ret == null ?
djmoffat@718 7002 undefined :
djmoffat@718 7003 ret;
djmoffat@718 7004 }
djmoffat@718 7005 },
djmoffat@718 7006
djmoffat@718 7007 removeAttr: function( elem, value ) {
djmoffat@718 7008 var name, propName,
djmoffat@718 7009 i = 0,
djmoffat@718 7010 attrNames = value && value.match( rnotwhite );
djmoffat@718 7011
djmoffat@718 7012 if ( attrNames && elem.nodeType === 1 ) {
djmoffat@718 7013 while ( (name = attrNames[i++]) ) {
djmoffat@718 7014 propName = jQuery.propFix[ name ] || name;
djmoffat@718 7015
djmoffat@718 7016 // Boolean attributes get special treatment (#10870)
djmoffat@718 7017 if ( jQuery.expr.match.bool.test( name ) ) {
djmoffat@718 7018 // Set corresponding property to false
djmoffat@718 7019 elem[ propName ] = false;
djmoffat@718 7020 }
djmoffat@718 7021
djmoffat@718 7022 elem.removeAttribute( name );
djmoffat@718 7023 }
djmoffat@718 7024 }
djmoffat@718 7025 },
djmoffat@718 7026
djmoffat@718 7027 attrHooks: {
djmoffat@718 7028 type: {
djmoffat@718 7029 set: function( elem, value ) {
djmoffat@718 7030 if ( !support.radioValue && value === "radio" &&
djmoffat@718 7031 jQuery.nodeName( elem, "input" ) ) {
djmoffat@718 7032 var val = elem.value;
djmoffat@718 7033 elem.setAttribute( "type", value );
djmoffat@718 7034 if ( val ) {
djmoffat@718 7035 elem.value = val;
djmoffat@718 7036 }
djmoffat@718 7037 return value;
djmoffat@718 7038 }
djmoffat@718 7039 }
djmoffat@718 7040 }
djmoffat@718 7041 }
djmoffat@718 7042 });
djmoffat@718 7043
djmoffat@718 7044 // Hooks for boolean attributes
djmoffat@718 7045 boolHook = {
djmoffat@718 7046 set: function( elem, value, name ) {
djmoffat@718 7047 if ( value === false ) {
djmoffat@718 7048 // Remove boolean attributes when set to false
djmoffat@718 7049 jQuery.removeAttr( elem, name );
djmoffat@718 7050 } else {
djmoffat@718 7051 elem.setAttribute( name, name );
djmoffat@718 7052 }
djmoffat@718 7053 return name;
djmoffat@718 7054 }
djmoffat@718 7055 };
djmoffat@718 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
djmoffat@718 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
djmoffat@718 7058
djmoffat@718 7059 attrHandle[ name ] = function( elem, name, isXML ) {
djmoffat@718 7060 var ret, handle;
djmoffat@718 7061 if ( !isXML ) {
djmoffat@718 7062 // Avoid an infinite loop by temporarily removing this function from the getter
djmoffat@718 7063 handle = attrHandle[ name ];
djmoffat@718 7064 attrHandle[ name ] = ret;
djmoffat@718 7065 ret = getter( elem, name, isXML ) != null ?
djmoffat@718 7066 name.toLowerCase() :
djmoffat@718 7067 null;
djmoffat@718 7068 attrHandle[ name ] = handle;
djmoffat@718 7069 }
djmoffat@718 7070 return ret;
djmoffat@718 7071 };
djmoffat@718 7072 });
djmoffat@718 7073
djmoffat@718 7074
djmoffat@718 7075
djmoffat@718 7076
djmoffat@718 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
djmoffat@718 7078
djmoffat@718 7079 jQuery.fn.extend({
djmoffat@718 7080 prop: function( name, value ) {
djmoffat@718 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
djmoffat@718 7082 },
djmoffat@718 7083
djmoffat@718 7084 removeProp: function( name ) {
djmoffat@718 7085 return this.each(function() {
djmoffat@718 7086 delete this[ jQuery.propFix[ name ] || name ];
djmoffat@718 7087 });
djmoffat@718 7088 }
djmoffat@718 7089 });
djmoffat@718 7090
djmoffat@718 7091 jQuery.extend({
djmoffat@718 7092 propFix: {
djmoffat@718 7093 "for": "htmlFor",
djmoffat@718 7094 "class": "className"
djmoffat@718 7095 },
djmoffat@718 7096
djmoffat@718 7097 prop: function( elem, name, value ) {
djmoffat@718 7098 var ret, hooks, notxml,
djmoffat@718 7099 nType = elem.nodeType;
djmoffat@718 7100
djmoffat@718 7101 // Don't get/set properties on text, comment and attribute nodes
djmoffat@718 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
djmoffat@718 7103 return;
djmoffat@718 7104 }
djmoffat@718 7105
djmoffat@718 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
djmoffat@718 7107
djmoffat@718 7108 if ( notxml ) {
djmoffat@718 7109 // Fix name and attach hooks
djmoffat@718 7110 name = jQuery.propFix[ name ] || name;
djmoffat@718 7111 hooks = jQuery.propHooks[ name ];
djmoffat@718 7112 }
djmoffat@718 7113
djmoffat@718 7114 if ( value !== undefined ) {
djmoffat@718 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
djmoffat@718 7116 ret :
djmoffat@718 7117 ( elem[ name ] = value );
djmoffat@718 7118
djmoffat@718 7119 } else {
djmoffat@718 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
djmoffat@718 7121 ret :
djmoffat@718 7122 elem[ name ];
djmoffat@718 7123 }
djmoffat@718 7124 },
djmoffat@718 7125
djmoffat@718 7126 propHooks: {
djmoffat@718 7127 tabIndex: {
djmoffat@718 7128 get: function( elem ) {
djmoffat@718 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
djmoffat@718 7130 elem.tabIndex :
djmoffat@718 7131 -1;
djmoffat@718 7132 }
djmoffat@718 7133 }
djmoffat@718 7134 }
djmoffat@718 7135 });
djmoffat@718 7136
djmoffat@718 7137 if ( !support.optSelected ) {
djmoffat@718 7138 jQuery.propHooks.selected = {
djmoffat@718 7139 get: function( elem ) {
djmoffat@718 7140 var parent = elem.parentNode;
djmoffat@718 7141 if ( parent && parent.parentNode ) {
djmoffat@718 7142 parent.parentNode.selectedIndex;
djmoffat@718 7143 }
djmoffat@718 7144 return null;
djmoffat@718 7145 }
djmoffat@718 7146 };
djmoffat@718 7147 }
djmoffat@718 7148
djmoffat@718 7149 jQuery.each([
djmoffat@718 7150 "tabIndex",
djmoffat@718 7151 "readOnly",
djmoffat@718 7152 "maxLength",
djmoffat@718 7153 "cellSpacing",
djmoffat@718 7154 "cellPadding",
djmoffat@718 7155 "rowSpan",
djmoffat@718 7156 "colSpan",
djmoffat@718 7157 "useMap",
djmoffat@718 7158 "frameBorder",
djmoffat@718 7159 "contentEditable"
djmoffat@718 7160 ], function() {
djmoffat@718 7161 jQuery.propFix[ this.toLowerCase() ] = this;
djmoffat@718 7162 });
djmoffat@718 7163
djmoffat@718 7164
djmoffat@718 7165
djmoffat@718 7166
djmoffat@718 7167 var rclass = /[\t\r\n\f]/g;
djmoffat@718 7168
djmoffat@718 7169 jQuery.fn.extend({
djmoffat@718 7170 addClass: function( value ) {
djmoffat@718 7171 var classes, elem, cur, clazz, j, finalValue,
djmoffat@718 7172 proceed = typeof value === "string" && value,
djmoffat@718 7173 i = 0,
djmoffat@718 7174 len = this.length;
djmoffat@718 7175
djmoffat@718 7176 if ( jQuery.isFunction( value ) ) {
djmoffat@718 7177 return this.each(function( j ) {
djmoffat@718 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
djmoffat@718 7179 });
djmoffat@718 7180 }
djmoffat@718 7181
djmoffat@718 7182 if ( proceed ) {
djmoffat@718 7183 // The disjunction here is for better compressibility (see removeClass)
djmoffat@718 7184 classes = ( value || "" ).match( rnotwhite ) || [];
djmoffat@718 7185
djmoffat@718 7186 for ( ; i < len; i++ ) {
djmoffat@718 7187 elem = this[ i ];
djmoffat@718 7188 cur = elem.nodeType === 1 && ( elem.className ?
djmoffat@718 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
djmoffat@718 7190 " "
djmoffat@718 7191 );
djmoffat@718 7192
djmoffat@718 7193 if ( cur ) {
djmoffat@718 7194 j = 0;
djmoffat@718 7195 while ( (clazz = classes[j++]) ) {
djmoffat@718 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
djmoffat@718 7197 cur += clazz + " ";
djmoffat@718 7198 }
djmoffat@718 7199 }
djmoffat@718 7200
djmoffat@718 7201 // only assign if different to avoid unneeded rendering.
djmoffat@718 7202 finalValue = jQuery.trim( cur );
djmoffat@718 7203 if ( elem.className !== finalValue ) {
djmoffat@718 7204 elem.className = finalValue;
djmoffat@718 7205 }
djmoffat@718 7206 }
djmoffat@718 7207 }
djmoffat@718 7208 }
djmoffat@718 7209
djmoffat@718 7210 return this;
djmoffat@718 7211 },
djmoffat@718 7212
djmoffat@718 7213 removeClass: function( value ) {
djmoffat@718 7214 var classes, elem, cur, clazz, j, finalValue,
djmoffat@718 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
djmoffat@718 7216 i = 0,
djmoffat@718 7217 len = this.length;
djmoffat@718 7218
djmoffat@718 7219 if ( jQuery.isFunction( value ) ) {
djmoffat@718 7220 return this.each(function( j ) {
djmoffat@718 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
djmoffat@718 7222 });
djmoffat@718 7223 }
djmoffat@718 7224 if ( proceed ) {
djmoffat@718 7225 classes = ( value || "" ).match( rnotwhite ) || [];
djmoffat@718 7226
djmoffat@718 7227 for ( ; i < len; i++ ) {
djmoffat@718 7228 elem = this[ i ];
djmoffat@718 7229 // This expression is here for better compressibility (see addClass)
djmoffat@718 7230 cur = elem.nodeType === 1 && ( elem.className ?
djmoffat@718 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
djmoffat@718 7232 ""
djmoffat@718 7233 );
djmoffat@718 7234
djmoffat@718 7235 if ( cur ) {
djmoffat@718 7236 j = 0;
djmoffat@718 7237 while ( (clazz = classes[j++]) ) {
djmoffat@718 7238 // Remove *all* instances
djmoffat@718 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
djmoffat@718 7240 cur = cur.replace( " " + clazz + " ", " " );
djmoffat@718 7241 }
djmoffat@718 7242 }
djmoffat@718 7243
djmoffat@718 7244 // Only assign if different to avoid unneeded rendering.
djmoffat@718 7245 finalValue = value ? jQuery.trim( cur ) : "";
djmoffat@718 7246 if ( elem.className !== finalValue ) {
djmoffat@718 7247 elem.className = finalValue;
djmoffat@718 7248 }
djmoffat@718 7249 }
djmoffat@718 7250 }
djmoffat@718 7251 }
djmoffat@718 7252
djmoffat@718 7253 return this;
djmoffat@718 7254 },
djmoffat@718 7255
djmoffat@718 7256 toggleClass: function( value, stateVal ) {
djmoffat@718 7257 var type = typeof value;
djmoffat@718 7258
djmoffat@718 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
djmoffat@718 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
djmoffat@718 7261 }
djmoffat@718 7262
djmoffat@718 7263 if ( jQuery.isFunction( value ) ) {
djmoffat@718 7264 return this.each(function( i ) {
djmoffat@718 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
djmoffat@718 7266 });
djmoffat@718 7267 }
djmoffat@718 7268
djmoffat@718 7269 return this.each(function() {
djmoffat@718 7270 if ( type === "string" ) {
djmoffat@718 7271 // Toggle individual class names
djmoffat@718 7272 var className,
djmoffat@718 7273 i = 0,
djmoffat@718 7274 self = jQuery( this ),
djmoffat@718 7275 classNames = value.match( rnotwhite ) || [];
djmoffat@718 7276
djmoffat@718 7277 while ( (className = classNames[ i++ ]) ) {
djmoffat@718 7278 // Check each className given, space separated list
djmoffat@718 7279 if ( self.hasClass( className ) ) {
djmoffat@718 7280 self.removeClass( className );
djmoffat@718 7281 } else {
djmoffat@718 7282 self.addClass( className );
djmoffat@718 7283 }
djmoffat@718 7284 }
djmoffat@718 7285
djmoffat@718 7286 // Toggle whole class name
djmoffat@718 7287 } else if ( type === strundefined || type === "boolean" ) {
djmoffat@718 7288 if ( this.className ) {
djmoffat@718 7289 // store className if set
djmoffat@718 7290 data_priv.set( this, "__className__", this.className );
djmoffat@718 7291 }
djmoffat@718 7292
djmoffat@718 7293 // If the element has a class name or if we're passed `false`,
djmoffat@718 7294 // then remove the whole classname (if there was one, the above saved it).
djmoffat@718 7295 // Otherwise bring back whatever was previously saved (if anything),
djmoffat@718 7296 // falling back to the empty string if nothing was stored.
djmoffat@718 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
djmoffat@718 7298 }
djmoffat@718 7299 });
djmoffat@718 7300 },
djmoffat@718 7301
djmoffat@718 7302 hasClass: function( selector ) {
djmoffat@718 7303 var className = " " + selector + " ",
djmoffat@718 7304 i = 0,
djmoffat@718 7305 l = this.length;
djmoffat@718 7306 for ( ; i < l; i++ ) {
djmoffat@718 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
djmoffat@718 7308 return true;
djmoffat@718 7309 }
djmoffat@718 7310 }
djmoffat@718 7311
djmoffat@718 7312 return false;
djmoffat@718 7313 }
djmoffat@718 7314 });
djmoffat@718 7315
djmoffat@718 7316
djmoffat@718 7317
djmoffat@718 7318
djmoffat@718 7319 var rreturn = /\r/g;
djmoffat@718 7320
djmoffat@718 7321 jQuery.fn.extend({
djmoffat@718 7322 val: function( value ) {
djmoffat@718 7323 var hooks, ret, isFunction,
djmoffat@718 7324 elem = this[0];
djmoffat@718 7325
djmoffat@718 7326 if ( !arguments.length ) {
djmoffat@718 7327 if ( elem ) {
djmoffat@718 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
djmoffat@718 7329
djmoffat@718 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
djmoffat@718 7331 return ret;
djmoffat@718 7332 }
djmoffat@718 7333
djmoffat@718 7334 ret = elem.value;
djmoffat@718 7335
djmoffat@718 7336 return typeof ret === "string" ?
djmoffat@718 7337 // Handle most common string cases
djmoffat@718 7338 ret.replace(rreturn, "") :
djmoffat@718 7339 // Handle cases where value is null/undef or number
djmoffat@718 7340 ret == null ? "" : ret;
djmoffat@718 7341 }
djmoffat@718 7342
djmoffat@718 7343 return;
djmoffat@718 7344 }
djmoffat@718 7345
djmoffat@718 7346 isFunction = jQuery.isFunction( value );
djmoffat@718 7347
djmoffat@718 7348 return this.each(function( i ) {
djmoffat@718 7349 var val;
djmoffat@718 7350
djmoffat@718 7351 if ( this.nodeType !== 1 ) {
djmoffat@718 7352 return;
djmoffat@718 7353 }
djmoffat@718 7354
djmoffat@718 7355 if ( isFunction ) {
djmoffat@718 7356 val = value.call( this, i, jQuery( this ).val() );
djmoffat@718 7357 } else {
djmoffat@718 7358 val = value;
djmoffat@718 7359 }
djmoffat@718 7360
djmoffat@718 7361 // Treat null/undefined as ""; convert numbers to string
djmoffat@718 7362 if ( val == null ) {
djmoffat@718 7363 val = "";
djmoffat@718 7364
djmoffat@718 7365 } else if ( typeof val === "number" ) {
djmoffat@718 7366 val += "";
djmoffat@718 7367
djmoffat@718 7368 } else if ( jQuery.isArray( val ) ) {
djmoffat@718 7369 val = jQuery.map( val, function( value ) {
djmoffat@718 7370 return value == null ? "" : value + "";
djmoffat@718 7371 });
djmoffat@718 7372 }
djmoffat@718 7373
djmoffat@718 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
djmoffat@718 7375
djmoffat@718 7376 // If set returns undefined, fall back to normal setting
djmoffat@718 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
djmoffat@718 7378 this.value = val;
djmoffat@718 7379 }
djmoffat@718 7380 });
djmoffat@718 7381 }
djmoffat@718 7382 });
djmoffat@718 7383
djmoffat@718 7384 jQuery.extend({
djmoffat@718 7385 valHooks: {
djmoffat@718 7386 option: {
djmoffat@718 7387 get: function( elem ) {
djmoffat@718 7388 var val = jQuery.find.attr( elem, "value" );
djmoffat@718 7389 return val != null ?
djmoffat@718 7390 val :
djmoffat@718 7391 // Support: IE10-11+
djmoffat@718 7392 // option.text throws exceptions (#14686, #14858)
djmoffat@718 7393 jQuery.trim( jQuery.text( elem ) );
djmoffat@718 7394 }
djmoffat@718 7395 },
djmoffat@718 7396 select: {
djmoffat@718 7397 get: function( elem ) {
djmoffat@718 7398 var value, option,
djmoffat@718 7399 options = elem.options,
djmoffat@718 7400 index = elem.selectedIndex,
djmoffat@718 7401 one = elem.type === "select-one" || index < 0,
djmoffat@718 7402 values = one ? null : [],
djmoffat@718 7403 max = one ? index + 1 : options.length,
djmoffat@718 7404 i = index < 0 ?
djmoffat@718 7405 max :
djmoffat@718 7406 one ? index : 0;
djmoffat@718 7407
djmoffat@718 7408 // Loop through all the selected options
djmoffat@718 7409 for ( ; i < max; i++ ) {
djmoffat@718 7410 option = options[ i ];
djmoffat@718 7411
djmoffat@718 7412 // IE6-9 doesn't update selected after form reset (#2551)
djmoffat@718 7413 if ( ( option.selected || i === index ) &&
djmoffat@718 7414 // Don't return options that are disabled or in a disabled optgroup
djmoffat@718 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
djmoffat@718 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
djmoffat@718 7417
djmoffat@718 7418 // Get the specific value for the option
djmoffat@718 7419 value = jQuery( option ).val();
djmoffat@718 7420
djmoffat@718 7421 // We don't need an array for one selects
djmoffat@718 7422 if ( one ) {
djmoffat@718 7423 return value;
djmoffat@718 7424 }
djmoffat@718 7425
djmoffat@718 7426 // Multi-Selects return an array
djmoffat@718 7427 values.push( value );
djmoffat@718 7428 }
djmoffat@718 7429 }
djmoffat@718 7430
djmoffat@718 7431 return values;
djmoffat@718 7432 },
djmoffat@718 7433
djmoffat@718 7434 set: function( elem, value ) {
djmoffat@718 7435 var optionSet, option,
djmoffat@718 7436 options = elem.options,
djmoffat@718 7437 values = jQuery.makeArray( value ),
djmoffat@718 7438 i = options.length;
djmoffat@718 7439
djmoffat@718 7440 while ( i-- ) {
djmoffat@718 7441 option = options[ i ];
djmoffat@718 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
djmoffat@718 7443 optionSet = true;
djmoffat@718 7444 }
djmoffat@718 7445 }
djmoffat@718 7446
djmoffat@718 7447 // Force browsers to behave consistently when non-matching value is set
djmoffat@718 7448 if ( !optionSet ) {
djmoffat@718 7449 elem.selectedIndex = -1;
djmoffat@718 7450 }
djmoffat@718 7451 return values;
djmoffat@718 7452 }
djmoffat@718 7453 }
djmoffat@718 7454 }
djmoffat@718 7455 });
djmoffat@718 7456
djmoffat@718 7457 // Radios and checkboxes getter/setter
djmoffat@718 7458 jQuery.each([ "radio", "checkbox" ], function() {
djmoffat@718 7459 jQuery.valHooks[ this ] = {
djmoffat@718 7460 set: function( elem, value ) {
djmoffat@718 7461 if ( jQuery.isArray( value ) ) {
djmoffat@718 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
djmoffat@718 7463 }
djmoffat@718 7464 }
djmoffat@718 7465 };
djmoffat@718 7466 if ( !support.checkOn ) {
djmoffat@718 7467 jQuery.valHooks[ this ].get = function( elem ) {
djmoffat@718 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
djmoffat@718 7469 };
djmoffat@718 7470 }
djmoffat@718 7471 });
djmoffat@718 7472
djmoffat@718 7473
djmoffat@718 7474
djmoffat@718 7475
djmoffat@718 7476 // Return jQuery for attributes-only inclusion
djmoffat@718 7477
djmoffat@718 7478
djmoffat@718 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
djmoffat@718 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
djmoffat@718 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
djmoffat@718 7482
djmoffat@718 7483 // Handle event binding
djmoffat@718 7484 jQuery.fn[ name ] = function( data, fn ) {
djmoffat@718 7485 return arguments.length > 0 ?
djmoffat@718 7486 this.on( name, null, data, fn ) :
djmoffat@718 7487 this.trigger( name );
djmoffat@718 7488 };
djmoffat@718 7489 });
djmoffat@718 7490
djmoffat@718 7491 jQuery.fn.extend({
djmoffat@718 7492 hover: function( fnOver, fnOut ) {
djmoffat@718 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
djmoffat@718 7494 },
djmoffat@718 7495
djmoffat@718 7496 bind: function( types, data, fn ) {
djmoffat@718 7497 return this.on( types, null, data, fn );
djmoffat@718 7498 },
djmoffat@718 7499 unbind: function( types, fn ) {
djmoffat@718 7500 return this.off( types, null, fn );
djmoffat@718 7501 },
djmoffat@718 7502
djmoffat@718 7503 delegate: function( selector, types, data, fn ) {
djmoffat@718 7504 return this.on( types, selector, data, fn );
djmoffat@718 7505 },
djmoffat@718 7506 undelegate: function( selector, types, fn ) {
djmoffat@718 7507 // ( namespace ) or ( selector, types [, fn] )
djmoffat@718 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
djmoffat@718 7509 }
djmoffat@718 7510 });
djmoffat@718 7511
djmoffat@718 7512
djmoffat@718 7513 var nonce = jQuery.now();
djmoffat@718 7514
djmoffat@718 7515 var rquery = (/\?/);
djmoffat@718 7516
djmoffat@718 7517
djmoffat@718 7518
djmoffat@718 7519 // Support: Android 2.3
djmoffat@718 7520 // Workaround failure to string-cast null input
djmoffat@718 7521 jQuery.parseJSON = function( data ) {
djmoffat@718 7522 return JSON.parse( data + "" );
djmoffat@718 7523 };
djmoffat@718 7524
djmoffat@718 7525
djmoffat@718 7526 // Cross-browser xml parsing
djmoffat@718 7527 jQuery.parseXML = function( data ) {
djmoffat@718 7528 var xml, tmp;
djmoffat@718 7529 if ( !data || typeof data !== "string" ) {
djmoffat@718 7530 return null;
djmoffat@718 7531 }
djmoffat@718 7532
djmoffat@718 7533 // Support: IE9
djmoffat@718 7534 try {
djmoffat@718 7535 tmp = new DOMParser();
djmoffat@718 7536 xml = tmp.parseFromString( data, "text/xml" );
djmoffat@718 7537 } catch ( e ) {
djmoffat@718 7538 xml = undefined;
djmoffat@718 7539 }
djmoffat@718 7540
djmoffat@718 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
djmoffat@718 7542 jQuery.error( "Invalid XML: " + data );
djmoffat@718 7543 }
djmoffat@718 7544 return xml;
djmoffat@718 7545 };
djmoffat@718 7546
djmoffat@718 7547
djmoffat@718 7548 var
djmoffat@718 7549 rhash = /#.*$/,
djmoffat@718 7550 rts = /([?&])_=[^&]*/,
djmoffat@718 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
djmoffat@718 7552 // #7653, #8125, #8152: local protocol detection
djmoffat@718 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
djmoffat@718 7554 rnoContent = /^(?:GET|HEAD)$/,
djmoffat@718 7555 rprotocol = /^\/\//,
djmoffat@718 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
djmoffat@718 7557
djmoffat@718 7558 /* Prefilters
djmoffat@718 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
djmoffat@718 7560 * 2) These are called:
djmoffat@718 7561 * - BEFORE asking for a transport
djmoffat@718 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
djmoffat@718 7563 * 3) key is the dataType
djmoffat@718 7564 * 4) the catchall symbol "*" can be used
djmoffat@718 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
djmoffat@718 7566 */
djmoffat@718 7567 prefilters = {},
djmoffat@718 7568
djmoffat@718 7569 /* Transports bindings
djmoffat@718 7570 * 1) key is the dataType
djmoffat@718 7571 * 2) the catchall symbol "*" can be used
djmoffat@718 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
djmoffat@718 7573 */
djmoffat@718 7574 transports = {},
djmoffat@718 7575
djmoffat@718 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
djmoffat@718 7577 allTypes = "*/".concat( "*" ),
djmoffat@718 7578
djmoffat@718 7579 // Document location
djmoffat@718 7580 ajaxLocation = window.location.href,
djmoffat@718 7581
djmoffat@718 7582 // Segment location into parts
djmoffat@718 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
djmoffat@718 7584
djmoffat@718 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
djmoffat@718 7586 function addToPrefiltersOrTransports( structure ) {
djmoffat@718 7587
djmoffat@718 7588 // dataTypeExpression is optional and defaults to "*"
djmoffat@718 7589 return function( dataTypeExpression, func ) {
djmoffat@718 7590
djmoffat@718 7591 if ( typeof dataTypeExpression !== "string" ) {
djmoffat@718 7592 func = dataTypeExpression;
djmoffat@718 7593 dataTypeExpression = "*";
djmoffat@718 7594 }
djmoffat@718 7595
djmoffat@718 7596 var dataType,
djmoffat@718 7597 i = 0,
djmoffat@718 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
djmoffat@718 7599
djmoffat@718 7600 if ( jQuery.isFunction( func ) ) {
djmoffat@718 7601 // For each dataType in the dataTypeExpression
djmoffat@718 7602 while ( (dataType = dataTypes[i++]) ) {
djmoffat@718 7603 // Prepend if requested
djmoffat@718 7604 if ( dataType[0] === "+" ) {
djmoffat@718 7605 dataType = dataType.slice( 1 ) || "*";
djmoffat@718 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
djmoffat@718 7607
djmoffat@718 7608 // Otherwise append
djmoffat@718 7609 } else {
djmoffat@718 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
djmoffat@718 7611 }
djmoffat@718 7612 }
djmoffat@718 7613 }
djmoffat@718 7614 };
djmoffat@718 7615 }
djmoffat@718 7616
djmoffat@718 7617 // Base inspection function for prefilters and transports
djmoffat@718 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
djmoffat@718 7619
djmoffat@718 7620 var inspected = {},
djmoffat@718 7621 seekingTransport = ( structure === transports );
djmoffat@718 7622
djmoffat@718 7623 function inspect( dataType ) {
djmoffat@718 7624 var selected;
djmoffat@718 7625 inspected[ dataType ] = true;
djmoffat@718 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
djmoffat@718 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
djmoffat@718 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
djmoffat@718 7629 options.dataTypes.unshift( dataTypeOrTransport );
djmoffat@718 7630 inspect( dataTypeOrTransport );
djmoffat@718 7631 return false;
djmoffat@718 7632 } else if ( seekingTransport ) {
djmoffat@718 7633 return !( selected = dataTypeOrTransport );
djmoffat@718 7634 }
djmoffat@718 7635 });
djmoffat@718 7636 return selected;
djmoffat@718 7637 }
djmoffat@718 7638
djmoffat@718 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
djmoffat@718 7640 }
djmoffat@718 7641
djmoffat@718 7642 // A special extend for ajax options
djmoffat@718 7643 // that takes "flat" options (not to be deep extended)
djmoffat@718 7644 // Fixes #9887
djmoffat@718 7645 function ajaxExtend( target, src ) {
djmoffat@718 7646 var key, deep,
djmoffat@718 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
djmoffat@718 7648
djmoffat@718 7649 for ( key in src ) {
djmoffat@718 7650 if ( src[ key ] !== undefined ) {
djmoffat@718 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
djmoffat@718 7652 }
djmoffat@718 7653 }
djmoffat@718 7654 if ( deep ) {
djmoffat@718 7655 jQuery.extend( true, target, deep );
djmoffat@718 7656 }
djmoffat@718 7657
djmoffat@718 7658 return target;
djmoffat@718 7659 }
djmoffat@718 7660
djmoffat@718 7661 /* Handles responses to an ajax request:
djmoffat@718 7662 * - finds the right dataType (mediates between content-type and expected dataType)
djmoffat@718 7663 * - returns the corresponding response
djmoffat@718 7664 */
djmoffat@718 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
djmoffat@718 7666
djmoffat@718 7667 var ct, type, finalDataType, firstDataType,
djmoffat@718 7668 contents = s.contents,
djmoffat@718 7669 dataTypes = s.dataTypes;
djmoffat@718 7670
djmoffat@718 7671 // Remove auto dataType and get content-type in the process
djmoffat@718 7672 while ( dataTypes[ 0 ] === "*" ) {
djmoffat@718 7673 dataTypes.shift();
djmoffat@718 7674 if ( ct === undefined ) {
djmoffat@718 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
djmoffat@718 7676 }
djmoffat@718 7677 }
djmoffat@718 7678
djmoffat@718 7679 // Check if we're dealing with a known content-type
djmoffat@718 7680 if ( ct ) {
djmoffat@718 7681 for ( type in contents ) {
djmoffat@718 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
djmoffat@718 7683 dataTypes.unshift( type );
djmoffat@718 7684 break;
djmoffat@718 7685 }
djmoffat@718 7686 }
djmoffat@718 7687 }
djmoffat@718 7688
djmoffat@718 7689 // Check to see if we have a response for the expected dataType
djmoffat@718 7690 if ( dataTypes[ 0 ] in responses ) {
djmoffat@718 7691 finalDataType = dataTypes[ 0 ];
djmoffat@718 7692 } else {
djmoffat@718 7693 // Try convertible dataTypes
djmoffat@718 7694 for ( type in responses ) {
djmoffat@718 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
djmoffat@718 7696 finalDataType = type;
djmoffat@718 7697 break;
djmoffat@718 7698 }
djmoffat@718 7699 if ( !firstDataType ) {
djmoffat@718 7700 firstDataType = type;
djmoffat@718 7701 }
djmoffat@718 7702 }
djmoffat@718 7703 // Or just use first one
djmoffat@718 7704 finalDataType = finalDataType || firstDataType;
djmoffat@718 7705 }
djmoffat@718 7706
djmoffat@718 7707 // If we found a dataType
djmoffat@718 7708 // We add the dataType to the list if needed
djmoffat@718 7709 // and return the corresponding response
djmoffat@718 7710 if ( finalDataType ) {
djmoffat@718 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
djmoffat@718 7712 dataTypes.unshift( finalDataType );
djmoffat@718 7713 }
djmoffat@718 7714 return responses[ finalDataType ];
djmoffat@718 7715 }
djmoffat@718 7716 }
djmoffat@718 7717
djmoffat@718 7718 /* Chain conversions given the request and the original response
djmoffat@718 7719 * Also sets the responseXXX fields on the jqXHR instance
djmoffat@718 7720 */
djmoffat@718 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
djmoffat@718 7722 var conv2, current, conv, tmp, prev,
djmoffat@718 7723 converters = {},
djmoffat@718 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
djmoffat@718 7725 dataTypes = s.dataTypes.slice();
djmoffat@718 7726
djmoffat@718 7727 // Create converters map with lowercased keys
djmoffat@718 7728 if ( dataTypes[ 1 ] ) {
djmoffat@718 7729 for ( conv in s.converters ) {
djmoffat@718 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
djmoffat@718 7731 }
djmoffat@718 7732 }
djmoffat@718 7733
djmoffat@718 7734 current = dataTypes.shift();
djmoffat@718 7735
djmoffat@718 7736 // Convert to each sequential dataType
djmoffat@718 7737 while ( current ) {
djmoffat@718 7738
djmoffat@718 7739 if ( s.responseFields[ current ] ) {
djmoffat@718 7740 jqXHR[ s.responseFields[ current ] ] = response;
djmoffat@718 7741 }
djmoffat@718 7742
djmoffat@718 7743 // Apply the dataFilter if provided
djmoffat@718 7744 if ( !prev && isSuccess && s.dataFilter ) {
djmoffat@718 7745 response = s.dataFilter( response, s.dataType );
djmoffat@718 7746 }
djmoffat@718 7747
djmoffat@718 7748 prev = current;
djmoffat@718 7749 current = dataTypes.shift();
djmoffat@718 7750
djmoffat@718 7751 if ( current ) {
djmoffat@718 7752
djmoffat@718 7753 // There's only work to do if current dataType is non-auto
djmoffat@718 7754 if ( current === "*" ) {
djmoffat@718 7755
djmoffat@718 7756 current = prev;
djmoffat@718 7757
djmoffat@718 7758 // Convert response if prev dataType is non-auto and differs from current
djmoffat@718 7759 } else if ( prev !== "*" && prev !== current ) {
djmoffat@718 7760
djmoffat@718 7761 // Seek a direct converter
djmoffat@718 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
djmoffat@718 7763
djmoffat@718 7764 // If none found, seek a pair
djmoffat@718 7765 if ( !conv ) {
djmoffat@718 7766 for ( conv2 in converters ) {
djmoffat@718 7767
djmoffat@718 7768 // If conv2 outputs current
djmoffat@718 7769 tmp = conv2.split( " " );
djmoffat@718 7770 if ( tmp[ 1 ] === current ) {
djmoffat@718 7771
djmoffat@718 7772 // If prev can be converted to accepted input
djmoffat@718 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
djmoffat@718 7774 converters[ "* " + tmp[ 0 ] ];
djmoffat@718 7775 if ( conv ) {
djmoffat@718 7776 // Condense equivalence converters
djmoffat@718 7777 if ( conv === true ) {
djmoffat@718 7778 conv = converters[ conv2 ];
djmoffat@718 7779
djmoffat@718 7780 // Otherwise, insert the intermediate dataType
djmoffat@718 7781 } else if ( converters[ conv2 ] !== true ) {
djmoffat@718 7782 current = tmp[ 0 ];
djmoffat@718 7783 dataTypes.unshift( tmp[ 1 ] );
djmoffat@718 7784 }
djmoffat@718 7785 break;
djmoffat@718 7786 }
djmoffat@718 7787 }
djmoffat@718 7788 }
djmoffat@718 7789 }
djmoffat@718 7790
djmoffat@718 7791 // Apply converter (if not an equivalence)
djmoffat@718 7792 if ( conv !== true ) {
djmoffat@718 7793
djmoffat@718 7794 // Unless errors are allowed to bubble, catch and return them
djmoffat@718 7795 if ( conv && s[ "throws" ] ) {
djmoffat@718 7796 response = conv( response );
djmoffat@718 7797 } else {
djmoffat@718 7798 try {
djmoffat@718 7799 response = conv( response );
djmoffat@718 7800 } catch ( e ) {
djmoffat@718 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
djmoffat@718 7802 }
djmoffat@718 7803 }
djmoffat@718 7804 }
djmoffat@718 7805 }
djmoffat@718 7806 }
djmoffat@718 7807 }
djmoffat@718 7808
djmoffat@718 7809 return { state: "success", data: response };
djmoffat@718 7810 }
djmoffat@718 7811
djmoffat@718 7812 jQuery.extend({
djmoffat@718 7813
djmoffat@718 7814 // Counter for holding the number of active queries
djmoffat@718 7815 active: 0,
djmoffat@718 7816
djmoffat@718 7817 // Last-Modified header cache for next request
djmoffat@718 7818 lastModified: {},
djmoffat@718 7819 etag: {},
djmoffat@718 7820
djmoffat@718 7821 ajaxSettings: {
djmoffat@718 7822 url: ajaxLocation,
djmoffat@718 7823 type: "GET",
djmoffat@718 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
djmoffat@718 7825 global: true,
djmoffat@718 7826 processData: true,
djmoffat@718 7827 async: true,
djmoffat@718 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
djmoffat@718 7829 /*
djmoffat@718 7830 timeout: 0,
djmoffat@718 7831 data: null,
djmoffat@718 7832 dataType: null,
djmoffat@718 7833 username: null,
djmoffat@718 7834 password: null,
djmoffat@718 7835 cache: null,
djmoffat@718 7836 throws: false,
djmoffat@718 7837 traditional: false,
djmoffat@718 7838 headers: {},
djmoffat@718 7839 */
djmoffat@718 7840
djmoffat@718 7841 accepts: {
djmoffat@718 7842 "*": allTypes,
djmoffat@718 7843 text: "text/plain",
djmoffat@718 7844 html: "text/html",
djmoffat@718 7845 xml: "application/xml, text/xml",
djmoffat@718 7846 json: "application/json, text/javascript"
djmoffat@718 7847 },
djmoffat@718 7848
djmoffat@718 7849 contents: {
djmoffat@718 7850 xml: /xml/,
djmoffat@718 7851 html: /html/,
djmoffat@718 7852 json: /json/
djmoffat@718 7853 },
djmoffat@718 7854
djmoffat@718 7855 responseFields: {
djmoffat@718 7856 xml: "responseXML",
djmoffat@718 7857 text: "responseText",
djmoffat@718 7858 json: "responseJSON"
djmoffat@718 7859 },
djmoffat@718 7860
djmoffat@718 7861 // Data converters
djmoffat@718 7862 // Keys separate source (or catchall "*") and destination types with a single space
djmoffat@718 7863 converters: {
djmoffat@718 7864
djmoffat@718 7865 // Convert anything to text
djmoffat@718 7866 "* text": String,
djmoffat@718 7867
djmoffat@718 7868 // Text to html (true = no transformation)
djmoffat@718 7869 "text html": true,
djmoffat@718 7870
djmoffat@718 7871 // Evaluate text as a json expression
djmoffat@718 7872 "text json": jQuery.parseJSON,
djmoffat@718 7873
djmoffat@718 7874 // Parse text as xml
djmoffat@718 7875 "text xml": jQuery.parseXML
djmoffat@718 7876 },
djmoffat@718 7877
djmoffat@718 7878 // For options that shouldn't be deep extended:
djmoffat@718 7879 // you can add your own custom options here if
djmoffat@718 7880 // and when you create one that shouldn't be
djmoffat@718 7881 // deep extended (see ajaxExtend)
djmoffat@718 7882 flatOptions: {
djmoffat@718 7883 url: true,
djmoffat@718 7884 context: true
djmoffat@718 7885 }
djmoffat@718 7886 },
djmoffat@718 7887
djmoffat@718 7888 // Creates a full fledged settings object into target
djmoffat@718 7889 // with both ajaxSettings and settings fields.
djmoffat@718 7890 // If target is omitted, writes into ajaxSettings.
djmoffat@718 7891 ajaxSetup: function( target, settings ) {
djmoffat@718 7892 return settings ?
djmoffat@718 7893
djmoffat@718 7894 // Building a settings object
djmoffat@718 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
djmoffat@718 7896
djmoffat@718 7897 // Extending ajaxSettings
djmoffat@718 7898 ajaxExtend( jQuery.ajaxSettings, target );
djmoffat@718 7899 },
djmoffat@718 7900
djmoffat@718 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
djmoffat@718 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
djmoffat@718 7903
djmoffat@718 7904 // Main method
djmoffat@718 7905 ajax: function( url, options ) {
djmoffat@718 7906
djmoffat@718 7907 // If url is an object, simulate pre-1.5 signature
djmoffat@718 7908 if ( typeof url === "object" ) {
djmoffat@718 7909 options = url;
djmoffat@718 7910 url = undefined;
djmoffat@718 7911 }
djmoffat@718 7912
djmoffat@718 7913 // Force options to be an object
djmoffat@718 7914 options = options || {};
djmoffat@718 7915
djmoffat@718 7916 var transport,
djmoffat@718 7917 // URL without anti-cache param
djmoffat@718 7918 cacheURL,
djmoffat@718 7919 // Response headers
djmoffat@718 7920 responseHeadersString,
djmoffat@718 7921 responseHeaders,
djmoffat@718 7922 // timeout handle
djmoffat@718 7923 timeoutTimer,
djmoffat@718 7924 // Cross-domain detection vars
djmoffat@718 7925 parts,
djmoffat@718 7926 // To know if global events are to be dispatched
djmoffat@718 7927 fireGlobals,
djmoffat@718 7928 // Loop variable
djmoffat@718 7929 i,
djmoffat@718 7930 // Create the final options object
djmoffat@718 7931 s = jQuery.ajaxSetup( {}, options ),
djmoffat@718 7932 // Callbacks context
djmoffat@718 7933 callbackContext = s.context || s,
djmoffat@718 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
djmoffat@718 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
djmoffat@718 7936 jQuery( callbackContext ) :
djmoffat@718 7937 jQuery.event,
djmoffat@718 7938 // Deferreds
djmoffat@718 7939 deferred = jQuery.Deferred(),
djmoffat@718 7940 completeDeferred = jQuery.Callbacks("once memory"),
djmoffat@718 7941 // Status-dependent callbacks
djmoffat@718 7942 statusCode = s.statusCode || {},
djmoffat@718 7943 // Headers (they are sent all at once)
djmoffat@718 7944 requestHeaders = {},
djmoffat@718 7945 requestHeadersNames = {},
djmoffat@718 7946 // The jqXHR state
djmoffat@718 7947 state = 0,
djmoffat@718 7948 // Default abort message
djmoffat@718 7949 strAbort = "canceled",
djmoffat@718 7950 // Fake xhr
djmoffat@718 7951 jqXHR = {
djmoffat@718 7952 readyState: 0,
djmoffat@718 7953
djmoffat@718 7954 // Builds headers hashtable if needed
djmoffat@718 7955 getResponseHeader: function( key ) {
djmoffat@718 7956 var match;
djmoffat@718 7957 if ( state === 2 ) {
djmoffat@718 7958 if ( !responseHeaders ) {
djmoffat@718 7959 responseHeaders = {};
djmoffat@718 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
djmoffat@718 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
djmoffat@718 7962 }
djmoffat@718 7963 }
djmoffat@718 7964 match = responseHeaders[ key.toLowerCase() ];
djmoffat@718 7965 }
djmoffat@718 7966 return match == null ? null : match;
djmoffat@718 7967 },
djmoffat@718 7968
djmoffat@718 7969 // Raw string
djmoffat@718 7970 getAllResponseHeaders: function() {
djmoffat@718 7971 return state === 2 ? responseHeadersString : null;
djmoffat@718 7972 },
djmoffat@718 7973
djmoffat@718 7974 // Caches the header
djmoffat@718 7975 setRequestHeader: function( name, value ) {
djmoffat@718 7976 var lname = name.toLowerCase();
djmoffat@718 7977 if ( !state ) {
djmoffat@718 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
djmoffat@718 7979 requestHeaders[ name ] = value;
djmoffat@718 7980 }
djmoffat@718 7981 return this;
djmoffat@718 7982 },
djmoffat@718 7983
djmoffat@718 7984 // Overrides response content-type header
djmoffat@718 7985 overrideMimeType: function( type ) {
djmoffat@718 7986 if ( !state ) {
djmoffat@718 7987 s.mimeType = type;
djmoffat@718 7988 }
djmoffat@718 7989 return this;
djmoffat@718 7990 },
djmoffat@718 7991
djmoffat@718 7992 // Status-dependent callbacks
djmoffat@718 7993 statusCode: function( map ) {
djmoffat@718 7994 var code;
djmoffat@718 7995 if ( map ) {
djmoffat@718 7996 if ( state < 2 ) {
djmoffat@718 7997 for ( code in map ) {
djmoffat@718 7998 // Lazy-add the new callback in a way that preserves old ones
djmoffat@718 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
djmoffat@718 8000 }
djmoffat@718 8001 } else {
djmoffat@718 8002 // Execute the appropriate callbacks
djmoffat@718 8003 jqXHR.always( map[ jqXHR.status ] );
djmoffat@718 8004 }
djmoffat@718 8005 }
djmoffat@718 8006 return this;
djmoffat@718 8007 },
djmoffat@718 8008
djmoffat@718 8009 // Cancel the request
djmoffat@718 8010 abort: function( statusText ) {
djmoffat@718 8011 var finalText = statusText || strAbort;
djmoffat@718 8012 if ( transport ) {
djmoffat@718 8013 transport.abort( finalText );
djmoffat@718 8014 }
djmoffat@718 8015 done( 0, finalText );
djmoffat@718 8016 return this;
djmoffat@718 8017 }
djmoffat@718 8018 };
djmoffat@718 8019
djmoffat@718 8020 // Attach deferreds
djmoffat@718 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
djmoffat@718 8022 jqXHR.success = jqXHR.done;
djmoffat@718 8023 jqXHR.error = jqXHR.fail;
djmoffat@718 8024
djmoffat@718 8025 // Remove hash character (#7531: and string promotion)
djmoffat@718 8026 // Add protocol if not provided (prefilters might expect it)
djmoffat@718 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
djmoffat@718 8028 // We also use the url parameter if available
djmoffat@718 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
djmoffat@718 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
djmoffat@718 8031
djmoffat@718 8032 // Alias method option to type as per ticket #12004
djmoffat@718 8033 s.type = options.method || options.type || s.method || s.type;
djmoffat@718 8034
djmoffat@718 8035 // Extract dataTypes list
djmoffat@718 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
djmoffat@718 8037
djmoffat@718 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
djmoffat@718 8039 if ( s.crossDomain == null ) {
djmoffat@718 8040 parts = rurl.exec( s.url.toLowerCase() );
djmoffat@718 8041 s.crossDomain = !!( parts &&
djmoffat@718 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
djmoffat@718 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
djmoffat@718 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
djmoffat@718 8045 );
djmoffat@718 8046 }
djmoffat@718 8047
djmoffat@718 8048 // Convert data if not already a string
djmoffat@718 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
djmoffat@718 8050 s.data = jQuery.param( s.data, s.traditional );
djmoffat@718 8051 }
djmoffat@718 8052
djmoffat@718 8053 // Apply prefilters
djmoffat@718 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
djmoffat@718 8055
djmoffat@718 8056 // If request was aborted inside a prefilter, stop there
djmoffat@718 8057 if ( state === 2 ) {
djmoffat@718 8058 return jqXHR;
djmoffat@718 8059 }
djmoffat@718 8060
djmoffat@718 8061 // We can fire global events as of now if asked to
djmoffat@718 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
djmoffat@718 8063 fireGlobals = jQuery.event && s.global;
djmoffat@718 8064
djmoffat@718 8065 // Watch for a new set of requests
djmoffat@718 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
djmoffat@718 8067 jQuery.event.trigger("ajaxStart");
djmoffat@718 8068 }
djmoffat@718 8069
djmoffat@718 8070 // Uppercase the type
djmoffat@718 8071 s.type = s.type.toUpperCase();
djmoffat@718 8072
djmoffat@718 8073 // Determine if request has content
djmoffat@718 8074 s.hasContent = !rnoContent.test( s.type );
djmoffat@718 8075
djmoffat@718 8076 // Save the URL in case we're toying with the If-Modified-Since
djmoffat@718 8077 // and/or If-None-Match header later on
djmoffat@718 8078 cacheURL = s.url;
djmoffat@718 8079
djmoffat@718 8080 // More options handling for requests with no content
djmoffat@718 8081 if ( !s.hasContent ) {
djmoffat@718 8082
djmoffat@718 8083 // If data is available, append data to url
djmoffat@718 8084 if ( s.data ) {
djmoffat@718 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
djmoffat@718 8086 // #9682: remove data so that it's not used in an eventual retry
djmoffat@718 8087 delete s.data;
djmoffat@718 8088 }
djmoffat@718 8089
djmoffat@718 8090 // Add anti-cache in url if needed
djmoffat@718 8091 if ( s.cache === false ) {
djmoffat@718 8092 s.url = rts.test( cacheURL ) ?
djmoffat@718 8093
djmoffat@718 8094 // If there is already a '_' parameter, set its value
djmoffat@718 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
djmoffat@718 8096
djmoffat@718 8097 // Otherwise add one to the end
djmoffat@718 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
djmoffat@718 8099 }
djmoffat@718 8100 }
djmoffat@718 8101
djmoffat@718 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
djmoffat@718 8103 if ( s.ifModified ) {
djmoffat@718 8104 if ( jQuery.lastModified[ cacheURL ] ) {
djmoffat@718 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
djmoffat@718 8106 }
djmoffat@718 8107 if ( jQuery.etag[ cacheURL ] ) {
djmoffat@718 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
djmoffat@718 8109 }
djmoffat@718 8110 }
djmoffat@718 8111
djmoffat@718 8112 // Set the correct header, if data is being sent
djmoffat@718 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
djmoffat@718 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
djmoffat@718 8115 }
djmoffat@718 8116
djmoffat@718 8117 // Set the Accepts header for the server, depending on the dataType
djmoffat@718 8118 jqXHR.setRequestHeader(
djmoffat@718 8119 "Accept",
djmoffat@718 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
djmoffat@718 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
djmoffat@718 8122 s.accepts[ "*" ]
djmoffat@718 8123 );
djmoffat@718 8124
djmoffat@718 8125 // Check for headers option
djmoffat@718 8126 for ( i in s.headers ) {
djmoffat@718 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
djmoffat@718 8128 }
djmoffat@718 8129
djmoffat@718 8130 // Allow custom headers/mimetypes and early abort
djmoffat@718 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
djmoffat@718 8132 // Abort if not done already and return
djmoffat@718 8133 return jqXHR.abort();
djmoffat@718 8134 }
djmoffat@718 8135
djmoffat@718 8136 // Aborting is no longer a cancellation
djmoffat@718 8137 strAbort = "abort";
djmoffat@718 8138
djmoffat@718 8139 // Install callbacks on deferreds
djmoffat@718 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
djmoffat@718 8141 jqXHR[ i ]( s[ i ] );
djmoffat@718 8142 }
djmoffat@718 8143
djmoffat@718 8144 // Get transport
djmoffat@718 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
djmoffat@718 8146
djmoffat@718 8147 // If no transport, we auto-abort
djmoffat@718 8148 if ( !transport ) {
djmoffat@718 8149 done( -1, "No Transport" );
djmoffat@718 8150 } else {
djmoffat@718 8151 jqXHR.readyState = 1;
djmoffat@718 8152
djmoffat@718 8153 // Send global event
djmoffat@718 8154 if ( fireGlobals ) {
djmoffat@718 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
djmoffat@718 8156 }
djmoffat@718 8157 // Timeout
djmoffat@718 8158 if ( s.async && s.timeout > 0 ) {
djmoffat@718 8159 timeoutTimer = setTimeout(function() {
djmoffat@718 8160 jqXHR.abort("timeout");
djmoffat@718 8161 }, s.timeout );
djmoffat@718 8162 }
djmoffat@718 8163
djmoffat@718 8164 try {
djmoffat@718 8165 state = 1;
djmoffat@718 8166 transport.send( requestHeaders, done );
djmoffat@718 8167 } catch ( e ) {
djmoffat@718 8168 // Propagate exception as error if not done
djmoffat@718 8169 if ( state < 2 ) {
djmoffat@718 8170 done( -1, e );
djmoffat@718 8171 // Simply rethrow otherwise
djmoffat@718 8172 } else {
djmoffat@718 8173 throw e;
djmoffat@718 8174 }
djmoffat@718 8175 }
djmoffat@718 8176 }
djmoffat@718 8177
djmoffat@718 8178 // Callback for when everything is done
djmoffat@718 8179 function done( status, nativeStatusText, responses, headers ) {
djmoffat@718 8180 var isSuccess, success, error, response, modified,
djmoffat@718 8181 statusText = nativeStatusText;
djmoffat@718 8182
djmoffat@718 8183 // Called once
djmoffat@718 8184 if ( state === 2 ) {
djmoffat@718 8185 return;
djmoffat@718 8186 }
djmoffat@718 8187
djmoffat@718 8188 // State is "done" now
djmoffat@718 8189 state = 2;
djmoffat@718 8190
djmoffat@718 8191 // Clear timeout if it exists
djmoffat@718 8192 if ( timeoutTimer ) {
djmoffat@718 8193 clearTimeout( timeoutTimer );
djmoffat@718 8194 }
djmoffat@718 8195
djmoffat@718 8196 // Dereference transport for early garbage collection
djmoffat@718 8197 // (no matter how long the jqXHR object will be used)
djmoffat@718 8198 transport = undefined;
djmoffat@718 8199
djmoffat@718 8200 // Cache response headers
djmoffat@718 8201 responseHeadersString = headers || "";
djmoffat@718 8202
djmoffat@718 8203 // Set readyState
djmoffat@718 8204 jqXHR.readyState = status > 0 ? 4 : 0;
djmoffat@718 8205
djmoffat@718 8206 // Determine if successful
djmoffat@718 8207 isSuccess = status >= 200 && status < 300 || status === 304;
djmoffat@718 8208
djmoffat@718 8209 // Get response data
djmoffat@718 8210 if ( responses ) {
djmoffat@718 8211 response = ajaxHandleResponses( s, jqXHR, responses );
djmoffat@718 8212 }
djmoffat@718 8213
djmoffat@718 8214 // Convert no matter what (that way responseXXX fields are always set)
djmoffat@718 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
djmoffat@718 8216
djmoffat@718 8217 // If successful, handle type chaining
djmoffat@718 8218 if ( isSuccess ) {
djmoffat@718 8219
djmoffat@718 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
djmoffat@718 8221 if ( s.ifModified ) {
djmoffat@718 8222 modified = jqXHR.getResponseHeader("Last-Modified");
djmoffat@718 8223 if ( modified ) {
djmoffat@718 8224 jQuery.lastModified[ cacheURL ] = modified;
djmoffat@718 8225 }
djmoffat@718 8226 modified = jqXHR.getResponseHeader("etag");
djmoffat@718 8227 if ( modified ) {
djmoffat@718 8228 jQuery.etag[ cacheURL ] = modified;
djmoffat@718 8229 }
djmoffat@718 8230 }
djmoffat@718 8231
djmoffat@718 8232 // if no content
djmoffat@718 8233 if ( status === 204 || s.type === "HEAD" ) {
djmoffat@718 8234 statusText = "nocontent";
djmoffat@718 8235
djmoffat@718 8236 // if not modified
djmoffat@718 8237 } else if ( status === 304 ) {
djmoffat@718 8238 statusText = "notmodified";
djmoffat@718 8239
djmoffat@718 8240 // If we have data, let's convert it
djmoffat@718 8241 } else {
djmoffat@718 8242 statusText = response.state;
djmoffat@718 8243 success = response.data;
djmoffat@718 8244 error = response.error;
djmoffat@718 8245 isSuccess = !error;
djmoffat@718 8246 }
djmoffat@718 8247 } else {
djmoffat@718 8248 // Extract error from statusText and normalize for non-aborts
djmoffat@718 8249 error = statusText;
djmoffat@718 8250 if ( status || !statusText ) {
djmoffat@718 8251 statusText = "error";
djmoffat@718 8252 if ( status < 0 ) {
djmoffat@718 8253 status = 0;
djmoffat@718 8254 }
djmoffat@718 8255 }
djmoffat@718 8256 }
djmoffat@718 8257
djmoffat@718 8258 // Set data for the fake xhr object
djmoffat@718 8259 jqXHR.status = status;
djmoffat@718 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
djmoffat@718 8261
djmoffat@718 8262 // Success/Error
djmoffat@718 8263 if ( isSuccess ) {
djmoffat@718 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
djmoffat@718 8265 } else {
djmoffat@718 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
djmoffat@718 8267 }
djmoffat@718 8268
djmoffat@718 8269 // Status-dependent callbacks
djmoffat@718 8270 jqXHR.statusCode( statusCode );
djmoffat@718 8271 statusCode = undefined;
djmoffat@718 8272
djmoffat@718 8273 if ( fireGlobals ) {
djmoffat@718 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
djmoffat@718 8275 [ jqXHR, s, isSuccess ? success : error ] );
djmoffat@718 8276 }
djmoffat@718 8277
djmoffat@718 8278 // Complete
djmoffat@718 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
djmoffat@718 8280
djmoffat@718 8281 if ( fireGlobals ) {
djmoffat@718 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
djmoffat@718 8283 // Handle the global AJAX counter
djmoffat@718 8284 if ( !( --jQuery.active ) ) {
djmoffat@718 8285 jQuery.event.trigger("ajaxStop");
djmoffat@718 8286 }
djmoffat@718 8287 }
djmoffat@718 8288 }
djmoffat@718 8289
djmoffat@718 8290 return jqXHR;
djmoffat@718 8291 },
djmoffat@718 8292
djmoffat@718 8293 getJSON: function( url, data, callback ) {
djmoffat@718 8294 return jQuery.get( url, data, callback, "json" );
djmoffat@718 8295 },
djmoffat@718 8296
djmoffat@718 8297 getScript: function( url, callback ) {
djmoffat@718 8298 return jQuery.get( url, undefined, callback, "script" );
djmoffat@718 8299 }
djmoffat@718 8300 });
djmoffat@718 8301
djmoffat@718 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
djmoffat@718 8303 jQuery[ method ] = function( url, data, callback, type ) {
djmoffat@718 8304 // Shift arguments if data argument was omitted
djmoffat@718 8305 if ( jQuery.isFunction( data ) ) {
djmoffat@718 8306 type = type || callback;
djmoffat@718 8307 callback = data;
djmoffat@718 8308 data = undefined;
djmoffat@718 8309 }
djmoffat@718 8310
djmoffat@718 8311 return jQuery.ajax({
djmoffat@718 8312 url: url,
djmoffat@718 8313 type: method,
djmoffat@718 8314 dataType: type,
djmoffat@718 8315 data: data,
djmoffat@718 8316 success: callback
djmoffat@718 8317 });
djmoffat@718 8318 };
djmoffat@718 8319 });
djmoffat@718 8320
djmoffat@718 8321
djmoffat@718 8322 jQuery._evalUrl = function( url ) {
djmoffat@718 8323 return jQuery.ajax({
djmoffat@718 8324 url: url,
djmoffat@718 8325 type: "GET",
djmoffat@718 8326 dataType: "script",
djmoffat@718 8327 async: false,
djmoffat@718 8328 global: false,
djmoffat@718 8329 "throws": true
djmoffat@718 8330 });
djmoffat@718 8331 };
djmoffat@718 8332
djmoffat@718 8333
djmoffat@718 8334 jQuery.fn.extend({
djmoffat@718 8335 wrapAll: function( html ) {
djmoffat@718 8336 var wrap;
djmoffat@718 8337
djmoffat@718 8338 if ( jQuery.isFunction( html ) ) {
djmoffat@718 8339 return this.each(function( i ) {
djmoffat@718 8340 jQuery( this ).wrapAll( html.call(this, i) );
djmoffat@718 8341 });
djmoffat@718 8342 }
djmoffat@718 8343
djmoffat@718 8344 if ( this[ 0 ] ) {
djmoffat@718 8345
djmoffat@718 8346 // The elements to wrap the target around
djmoffat@718 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
djmoffat@718 8348
djmoffat@718 8349 if ( this[ 0 ].parentNode ) {
djmoffat@718 8350 wrap.insertBefore( this[ 0 ] );
djmoffat@718 8351 }
djmoffat@718 8352
djmoffat@718 8353 wrap.map(function() {
djmoffat@718 8354 var elem = this;
djmoffat@718 8355
djmoffat@718 8356 while ( elem.firstElementChild ) {
djmoffat@718 8357 elem = elem.firstElementChild;
djmoffat@718 8358 }
djmoffat@718 8359
djmoffat@718 8360 return elem;
djmoffat@718 8361 }).append( this );
djmoffat@718 8362 }
djmoffat@718 8363
djmoffat@718 8364 return this;
djmoffat@718 8365 },
djmoffat@718 8366
djmoffat@718 8367 wrapInner: function( html ) {
djmoffat@718 8368 if ( jQuery.isFunction( html ) ) {
djmoffat@718 8369 return this.each(function( i ) {
djmoffat@718 8370 jQuery( this ).wrapInner( html.call(this, i) );
djmoffat@718 8371 });
djmoffat@718 8372 }
djmoffat@718 8373
djmoffat@718 8374 return this.each(function() {
djmoffat@718 8375 var self = jQuery( this ),
djmoffat@718 8376 contents = self.contents();
djmoffat@718 8377
djmoffat@718 8378 if ( contents.length ) {
djmoffat@718 8379 contents.wrapAll( html );
djmoffat@718 8380
djmoffat@718 8381 } else {
djmoffat@718 8382 self.append( html );
djmoffat@718 8383 }
djmoffat@718 8384 });
djmoffat@718 8385 },
djmoffat@718 8386
djmoffat@718 8387 wrap: function( html ) {
djmoffat@718 8388 var isFunction = jQuery.isFunction( html );
djmoffat@718 8389
djmoffat@718 8390 return this.each(function( i ) {
djmoffat@718 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
djmoffat@718 8392 });
djmoffat@718 8393 },
djmoffat@718 8394
djmoffat@718 8395 unwrap: function() {
djmoffat@718 8396 return this.parent().each(function() {
djmoffat@718 8397 if ( !jQuery.nodeName( this, "body" ) ) {
djmoffat@718 8398 jQuery( this ).replaceWith( this.childNodes );
djmoffat@718 8399 }
djmoffat@718 8400 }).end();
djmoffat@718 8401 }
djmoffat@718 8402 });
djmoffat@718 8403
djmoffat@718 8404
djmoffat@718 8405 jQuery.expr.filters.hidden = function( elem ) {
djmoffat@718 8406 // Support: Opera <= 12.12
djmoffat@718 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
djmoffat@718 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
djmoffat@718 8409 };
djmoffat@718 8410 jQuery.expr.filters.visible = function( elem ) {
djmoffat@718 8411 return !jQuery.expr.filters.hidden( elem );
djmoffat@718 8412 };
djmoffat@718 8413
djmoffat@718 8414
djmoffat@718 8415
djmoffat@718 8416
djmoffat@718 8417 var r20 = /%20/g,
djmoffat@718 8418 rbracket = /\[\]$/,
djmoffat@718 8419 rCRLF = /\r?\n/g,
djmoffat@718 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
djmoffat@718 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
djmoffat@718 8422
djmoffat@718 8423 function buildParams( prefix, obj, traditional, add ) {
djmoffat@718 8424 var name;
djmoffat@718 8425
djmoffat@718 8426 if ( jQuery.isArray( obj ) ) {
djmoffat@718 8427 // Serialize array item.
djmoffat@718 8428 jQuery.each( obj, function( i, v ) {
djmoffat@718 8429 if ( traditional || rbracket.test( prefix ) ) {
djmoffat@718 8430 // Treat each array item as a scalar.
djmoffat@718 8431 add( prefix, v );
djmoffat@718 8432
djmoffat@718 8433 } else {
djmoffat@718 8434 // Item is non-scalar (array or object), encode its numeric index.
djmoffat@718 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
djmoffat@718 8436 }
djmoffat@718 8437 });
djmoffat@718 8438
djmoffat@718 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
djmoffat@718 8440 // Serialize object item.
djmoffat@718 8441 for ( name in obj ) {
djmoffat@718 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
djmoffat@718 8443 }
djmoffat@718 8444
djmoffat@718 8445 } else {
djmoffat@718 8446 // Serialize scalar item.
djmoffat@718 8447 add( prefix, obj );
djmoffat@718 8448 }
djmoffat@718 8449 }
djmoffat@718 8450
djmoffat@718 8451 // Serialize an array of form elements or a set of
djmoffat@718 8452 // key/values into a query string
djmoffat@718 8453 jQuery.param = function( a, traditional ) {
djmoffat@718 8454 var prefix,
djmoffat@718 8455 s = [],
djmoffat@718 8456 add = function( key, value ) {
djmoffat@718 8457 // If value is a function, invoke it and return its value
djmoffat@718 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
djmoffat@718 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
djmoffat@718 8460 };
djmoffat@718 8461
djmoffat@718 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
djmoffat@718 8463 if ( traditional === undefined ) {
djmoffat@718 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
djmoffat@718 8465 }
djmoffat@718 8466
djmoffat@718 8467 // If an array was passed in, assume that it is an array of form elements.
djmoffat@718 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
djmoffat@718 8469 // Serialize the form elements
djmoffat@718 8470 jQuery.each( a, function() {
djmoffat@718 8471 add( this.name, this.value );
djmoffat@718 8472 });
djmoffat@718 8473
djmoffat@718 8474 } else {
djmoffat@718 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
djmoffat@718 8476 // did it), otherwise encode params recursively.
djmoffat@718 8477 for ( prefix in a ) {
djmoffat@718 8478 buildParams( prefix, a[ prefix ], traditional, add );
djmoffat@718 8479 }
djmoffat@718 8480 }
djmoffat@718 8481
djmoffat@718 8482 // Return the resulting serialization
djmoffat@718 8483 return s.join( "&" ).replace( r20, "+" );
djmoffat@718 8484 };
djmoffat@718 8485
djmoffat@718 8486 jQuery.fn.extend({
djmoffat@718 8487 serialize: function() {
djmoffat@718 8488 return jQuery.param( this.serializeArray() );
djmoffat@718 8489 },
djmoffat@718 8490 serializeArray: function() {
djmoffat@718 8491 return this.map(function() {
djmoffat@718 8492 // Can add propHook for "elements" to filter or add form elements
djmoffat@718 8493 var elements = jQuery.prop( this, "elements" );
djmoffat@718 8494 return elements ? jQuery.makeArray( elements ) : this;
djmoffat@718 8495 })
djmoffat@718 8496 .filter(function() {
djmoffat@718 8497 var type = this.type;
djmoffat@718 8498
djmoffat@718 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
djmoffat@718 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
djmoffat@718 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
djmoffat@718 8502 ( this.checked || !rcheckableType.test( type ) );
djmoffat@718 8503 })
djmoffat@718 8504 .map(function( i, elem ) {
djmoffat@718 8505 var val = jQuery( this ).val();
djmoffat@718 8506
djmoffat@718 8507 return val == null ?
djmoffat@718 8508 null :
djmoffat@718 8509 jQuery.isArray( val ) ?
djmoffat@718 8510 jQuery.map( val, function( val ) {
djmoffat@718 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
djmoffat@718 8512 }) :
djmoffat@718 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
djmoffat@718 8514 }).get();
djmoffat@718 8515 }
djmoffat@718 8516 });
djmoffat@718 8517
djmoffat@718 8518
djmoffat@718 8519 jQuery.ajaxSettings.xhr = function() {
djmoffat@718 8520 try {
djmoffat@718 8521 return new XMLHttpRequest();
djmoffat@718 8522 } catch( e ) {}
djmoffat@718 8523 };
djmoffat@718 8524
djmoffat@718 8525 var xhrId = 0,
djmoffat@718 8526 xhrCallbacks = {},
djmoffat@718 8527 xhrSuccessStatus = {
djmoffat@718 8528 // file protocol always yields status code 0, assume 200
djmoffat@718 8529 0: 200,
djmoffat@718 8530 // Support: IE9
djmoffat@718 8531 // #1450: sometimes IE returns 1223 when it should be 204
djmoffat@718 8532 1223: 204
djmoffat@718 8533 },
djmoffat@718 8534 xhrSupported = jQuery.ajaxSettings.xhr();
djmoffat@718 8535
djmoffat@718 8536 // Support: IE9
djmoffat@718 8537 // Open requests must be manually aborted on unload (#5280)
djmoffat@718 8538 // See https://support.microsoft.com/kb/2856746 for more info
djmoffat@718 8539 if ( window.attachEvent ) {
djmoffat@718 8540 window.attachEvent( "onunload", function() {
djmoffat@718 8541 for ( var key in xhrCallbacks ) {
djmoffat@718 8542 xhrCallbacks[ key ]();
djmoffat@718 8543 }
djmoffat@718 8544 });
djmoffat@718 8545 }
djmoffat@718 8546
djmoffat@718 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
djmoffat@718 8548 support.ajax = xhrSupported = !!xhrSupported;
djmoffat@718 8549
djmoffat@718 8550 jQuery.ajaxTransport(function( options ) {
djmoffat@718 8551 var callback;
djmoffat@718 8552
djmoffat@718 8553 // Cross domain only allowed if supported through XMLHttpRequest
djmoffat@718 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
djmoffat@718 8555 return {
djmoffat@718 8556 send: function( headers, complete ) {
djmoffat@718 8557 var i,
djmoffat@718 8558 xhr = options.xhr(),
djmoffat@718 8559 id = ++xhrId;
djmoffat@718 8560
djmoffat@718 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
djmoffat@718 8562
djmoffat@718 8563 // Apply custom fields if provided
djmoffat@718 8564 if ( options.xhrFields ) {
djmoffat@718 8565 for ( i in options.xhrFields ) {
djmoffat@718 8566 xhr[ i ] = options.xhrFields[ i ];
djmoffat@718 8567 }
djmoffat@718 8568 }
djmoffat@718 8569
djmoffat@718 8570 // Override mime type if needed
djmoffat@718 8571 if ( options.mimeType && xhr.overrideMimeType ) {
djmoffat@718 8572 xhr.overrideMimeType( options.mimeType );
djmoffat@718 8573 }
djmoffat@718 8574
djmoffat@718 8575 // X-Requested-With header
djmoffat@718 8576 // For cross-domain requests, seeing as conditions for a preflight are
djmoffat@718 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
djmoffat@718 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
djmoffat@718 8579 // For same-domain requests, won't change header if already provided.
djmoffat@718 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
djmoffat@718 8581 headers["X-Requested-With"] = "XMLHttpRequest";
djmoffat@718 8582 }
djmoffat@718 8583
djmoffat@718 8584 // Set headers
djmoffat@718 8585 for ( i in headers ) {
djmoffat@718 8586 xhr.setRequestHeader( i, headers[ i ] );
djmoffat@718 8587 }
djmoffat@718 8588
djmoffat@718 8589 // Callback
djmoffat@718 8590 callback = function( type ) {
djmoffat@718 8591 return function() {
djmoffat@718 8592 if ( callback ) {
djmoffat@718 8593 delete xhrCallbacks[ id ];
djmoffat@718 8594 callback = xhr.onload = xhr.onerror = null;
djmoffat@718 8595
djmoffat@718 8596 if ( type === "abort" ) {
djmoffat@718 8597 xhr.abort();
djmoffat@718 8598 } else if ( type === "error" ) {
djmoffat@718 8599 complete(
djmoffat@718 8600 // file: protocol always yields status 0; see #8605, #14207
djmoffat@718 8601 xhr.status,
djmoffat@718 8602 xhr.statusText
djmoffat@718 8603 );
djmoffat@718 8604 } else {
djmoffat@718 8605 complete(
djmoffat@718 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
djmoffat@718 8607 xhr.statusText,
djmoffat@718 8608 // Support: IE9
djmoffat@718 8609 // Accessing binary-data responseText throws an exception
djmoffat@718 8610 // (#11426)
djmoffat@718 8611 typeof xhr.responseText === "string" ? {
djmoffat@718 8612 text: xhr.responseText
djmoffat@718 8613 } : undefined,
djmoffat@718 8614 xhr.getAllResponseHeaders()
djmoffat@718 8615 );
djmoffat@718 8616 }
djmoffat@718 8617 }
djmoffat@718 8618 };
djmoffat@718 8619 };
djmoffat@718 8620
djmoffat@718 8621 // Listen to events
djmoffat@718 8622 xhr.onload = callback();
djmoffat@718 8623 xhr.onerror = callback("error");
djmoffat@718 8624
djmoffat@718 8625 // Create the abort callback
djmoffat@718 8626 callback = xhrCallbacks[ id ] = callback("abort");
djmoffat@718 8627
djmoffat@718 8628 try {
djmoffat@718 8629 // Do send the request (this may raise an exception)
djmoffat@718 8630 xhr.send( options.hasContent && options.data || null );
djmoffat@718 8631 } catch ( e ) {
djmoffat@718 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
djmoffat@718 8633 if ( callback ) {
djmoffat@718 8634 throw e;
djmoffat@718 8635 }
djmoffat@718 8636 }
djmoffat@718 8637 },
djmoffat@718 8638
djmoffat@718 8639 abort: function() {
djmoffat@718 8640 if ( callback ) {
djmoffat@718 8641 callback();
djmoffat@718 8642 }
djmoffat@718 8643 }
djmoffat@718 8644 };
djmoffat@718 8645 }
djmoffat@718 8646 });
djmoffat@718 8647
djmoffat@718 8648
djmoffat@718 8649
djmoffat@718 8650
djmoffat@718 8651 // Install script dataType
djmoffat@718 8652 jQuery.ajaxSetup({
djmoffat@718 8653 accepts: {
djmoffat@718 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
djmoffat@718 8655 },
djmoffat@718 8656 contents: {
djmoffat@718 8657 script: /(?:java|ecma)script/
djmoffat@718 8658 },
djmoffat@718 8659 converters: {
djmoffat@718 8660 "text script": function( text ) {
djmoffat@718 8661 jQuery.globalEval( text );
djmoffat@718 8662 return text;
djmoffat@718 8663 }
djmoffat@718 8664 }
djmoffat@718 8665 });
djmoffat@718 8666
djmoffat@718 8667 // Handle cache's special case and crossDomain
djmoffat@718 8668 jQuery.ajaxPrefilter( "script", function( s ) {
djmoffat@718 8669 if ( s.cache === undefined ) {
djmoffat@718 8670 s.cache = false;
djmoffat@718 8671 }
djmoffat@718 8672 if ( s.crossDomain ) {
djmoffat@718 8673 s.type = "GET";
djmoffat@718 8674 }
djmoffat@718 8675 });
djmoffat@718 8676
djmoffat@718 8677 // Bind script tag hack transport
djmoffat@718 8678 jQuery.ajaxTransport( "script", function( s ) {
djmoffat@718 8679 // This transport only deals with cross domain requests
djmoffat@718 8680 if ( s.crossDomain ) {
djmoffat@718 8681 var script, callback;
djmoffat@718 8682 return {
djmoffat@718 8683 send: function( _, complete ) {
djmoffat@718 8684 script = jQuery("<script>").prop({
djmoffat@718 8685 async: true,
djmoffat@718 8686 charset: s.scriptCharset,
djmoffat@718 8687 src: s.url
djmoffat@718 8688 }).on(
djmoffat@718 8689 "load error",
djmoffat@718 8690 callback = function( evt ) {
djmoffat@718 8691 script.remove();
djmoffat@718 8692 callback = null;
djmoffat@718 8693 if ( evt ) {
djmoffat@718 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
djmoffat@718 8695 }
djmoffat@718 8696 }
djmoffat@718 8697 );
djmoffat@718 8698 document.head.appendChild( script[ 0 ] );
djmoffat@718 8699 },
djmoffat@718 8700 abort: function() {
djmoffat@718 8701 if ( callback ) {
djmoffat@718 8702 callback();
djmoffat@718 8703 }
djmoffat@718 8704 }
djmoffat@718 8705 };
djmoffat@718 8706 }
djmoffat@718 8707 });
djmoffat@718 8708
djmoffat@718 8709
djmoffat@718 8710
djmoffat@718 8711
djmoffat@718 8712 var oldCallbacks = [],
djmoffat@718 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
djmoffat@718 8714
djmoffat@718 8715 // Default jsonp settings
djmoffat@718 8716 jQuery.ajaxSetup({
djmoffat@718 8717 jsonp: "callback",
djmoffat@718 8718 jsonpCallback: function() {
djmoffat@718 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
djmoffat@718 8720 this[ callback ] = true;
djmoffat@718 8721 return callback;
djmoffat@718 8722 }
djmoffat@718 8723 });
djmoffat@718 8724
djmoffat@718 8725 // Detect, normalize options and install callbacks for jsonp requests
djmoffat@718 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
djmoffat@718 8727
djmoffat@718 8728 var callbackName, overwritten, responseContainer,
djmoffat@718 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
djmoffat@718 8730 "url" :
djmoffat@718 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
djmoffat@718 8732 );
djmoffat@718 8733
djmoffat@718 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
djmoffat@718 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
djmoffat@718 8736
djmoffat@718 8737 // Get callback name, remembering preexisting value associated with it
djmoffat@718 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
djmoffat@718 8739 s.jsonpCallback() :
djmoffat@718 8740 s.jsonpCallback;
djmoffat@718 8741
djmoffat@718 8742 // Insert callback into url or form data
djmoffat@718 8743 if ( jsonProp ) {
djmoffat@718 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
djmoffat@718 8745 } else if ( s.jsonp !== false ) {
djmoffat@718 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
djmoffat@718 8747 }
djmoffat@718 8748
djmoffat@718 8749 // Use data converter to retrieve json after script execution
djmoffat@718 8750 s.converters["script json"] = function() {
djmoffat@718 8751 if ( !responseContainer ) {
djmoffat@718 8752 jQuery.error( callbackName + " was not called" );
djmoffat@718 8753 }
djmoffat@718 8754 return responseContainer[ 0 ];
djmoffat@718 8755 };
djmoffat@718 8756
djmoffat@718 8757 // force json dataType
djmoffat@718 8758 s.dataTypes[ 0 ] = "json";
djmoffat@718 8759
djmoffat@718 8760 // Install callback
djmoffat@718 8761 overwritten = window[ callbackName ];
djmoffat@718 8762 window[ callbackName ] = function() {
djmoffat@718 8763 responseContainer = arguments;
djmoffat@718 8764 };
djmoffat@718 8765
djmoffat@718 8766 // Clean-up function (fires after converters)
djmoffat@718 8767 jqXHR.always(function() {
djmoffat@718 8768 // Restore preexisting value
djmoffat@718 8769 window[ callbackName ] = overwritten;
djmoffat@718 8770
djmoffat@718 8771 // Save back as free
djmoffat@718 8772 if ( s[ callbackName ] ) {
djmoffat@718 8773 // make sure that re-using the options doesn't screw things around
djmoffat@718 8774 s.jsonpCallback = originalSettings.jsonpCallback;
djmoffat@718 8775
djmoffat@718 8776 // save the callback name for future use
djmoffat@718 8777 oldCallbacks.push( callbackName );
djmoffat@718 8778 }
djmoffat@718 8779
djmoffat@718 8780 // Call if it was a function and we have a response
djmoffat@718 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
djmoffat@718 8782 overwritten( responseContainer[ 0 ] );
djmoffat@718 8783 }
djmoffat@718 8784
djmoffat@718 8785 responseContainer = overwritten = undefined;
djmoffat@718 8786 });
djmoffat@718 8787
djmoffat@718 8788 // Delegate to script
djmoffat@718 8789 return "script";
djmoffat@718 8790 }
djmoffat@718 8791 });
djmoffat@718 8792
djmoffat@718 8793
djmoffat@718 8794
djmoffat@718 8795
djmoffat@718 8796 // data: string of html
djmoffat@718 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
djmoffat@718 8798 // keepScripts (optional): If true, will include scripts passed in the html string
djmoffat@718 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
djmoffat@718 8800 if ( !data || typeof data !== "string" ) {
djmoffat@718 8801 return null;
djmoffat@718 8802 }
djmoffat@718 8803 if ( typeof context === "boolean" ) {
djmoffat@718 8804 keepScripts = context;
djmoffat@718 8805 context = false;
djmoffat@718 8806 }
djmoffat@718 8807 context = context || document;
djmoffat@718 8808
djmoffat@718 8809 var parsed = rsingleTag.exec( data ),
djmoffat@718 8810 scripts = !keepScripts && [];
djmoffat@718 8811
djmoffat@718 8812 // Single tag
djmoffat@718 8813 if ( parsed ) {
djmoffat@718 8814 return [ context.createElement( parsed[1] ) ];
djmoffat@718 8815 }
djmoffat@718 8816
djmoffat@718 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
djmoffat@718 8818
djmoffat@718 8819 if ( scripts && scripts.length ) {
djmoffat@718 8820 jQuery( scripts ).remove();
djmoffat@718 8821 }
djmoffat@718 8822
djmoffat@718 8823 return jQuery.merge( [], parsed.childNodes );
djmoffat@718 8824 };
djmoffat@718 8825
djmoffat@718 8826
djmoffat@718 8827 // Keep a copy of the old load method
djmoffat@718 8828 var _load = jQuery.fn.load;
djmoffat@718 8829
djmoffat@718 8830 /**
djmoffat@718 8831 * Load a url into a page
djmoffat@718 8832 */
djmoffat@718 8833 jQuery.fn.load = function( url, params, callback ) {
djmoffat@718 8834 if ( typeof url !== "string" && _load ) {
djmoffat@718 8835 return _load.apply( this, arguments );
djmoffat@718 8836 }
djmoffat@718 8837
djmoffat@718 8838 var selector, type, response,
djmoffat@718 8839 self = this,
djmoffat@718 8840 off = url.indexOf(" ");
djmoffat@718 8841
djmoffat@718 8842 if ( off >= 0 ) {
djmoffat@718 8843 selector = jQuery.trim( url.slice( off ) );
djmoffat@718 8844 url = url.slice( 0, off );
djmoffat@718 8845 }
djmoffat@718 8846
djmoffat@718 8847 // If it's a function
djmoffat@718 8848 if ( jQuery.isFunction( params ) ) {
djmoffat@718 8849
djmoffat@718 8850 // We assume that it's the callback
djmoffat@718 8851 callback = params;
djmoffat@718 8852 params = undefined;
djmoffat@718 8853
djmoffat@718 8854 // Otherwise, build a param string
djmoffat@718 8855 } else if ( params && typeof params === "object" ) {
djmoffat@718 8856 type = "POST";
djmoffat@718 8857 }
djmoffat@718 8858
djmoffat@718 8859 // If we have elements to modify, make the request
djmoffat@718 8860 if ( self.length > 0 ) {
djmoffat@718 8861 jQuery.ajax({
djmoffat@718 8862 url: url,
djmoffat@718 8863
djmoffat@718 8864 // if "type" variable is undefined, then "GET" method will be used
djmoffat@718 8865 type: type,
djmoffat@718 8866 dataType: "html",
djmoffat@718 8867 data: params
djmoffat@718 8868 }).done(function( responseText ) {
djmoffat@718 8869
djmoffat@718 8870 // Save response for use in complete callback
djmoffat@718 8871 response = arguments;
djmoffat@718 8872
djmoffat@718 8873 self.html( selector ?
djmoffat@718 8874
djmoffat@718 8875 // If a selector was specified, locate the right elements in a dummy div
djmoffat@718 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
djmoffat@718 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
djmoffat@718 8878
djmoffat@718 8879 // Otherwise use the full result
djmoffat@718 8880 responseText );
djmoffat@718 8881
djmoffat@718 8882 }).complete( callback && function( jqXHR, status ) {
djmoffat@718 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
djmoffat@718 8884 });
djmoffat@718 8885 }
djmoffat@718 8886
djmoffat@718 8887 return this;
djmoffat@718 8888 };
djmoffat@718 8889
djmoffat@718 8890
djmoffat@718 8891
djmoffat@718 8892
djmoffat@718 8893 // Attach a bunch of functions for handling common AJAX events
djmoffat@718 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
djmoffat@718 8895 jQuery.fn[ type ] = function( fn ) {
djmoffat@718 8896 return this.on( type, fn );
djmoffat@718 8897 };
djmoffat@718 8898 });
djmoffat@718 8899
djmoffat@718 8900
djmoffat@718 8901
djmoffat@718 8902
djmoffat@718 8903 jQuery.expr.filters.animated = function( elem ) {
djmoffat@718 8904 return jQuery.grep(jQuery.timers, function( fn ) {
djmoffat@718 8905 return elem === fn.elem;
djmoffat@718 8906 }).length;
djmoffat@718 8907 };
djmoffat@718 8908
djmoffat@718 8909
djmoffat@718 8910
djmoffat@718 8911
djmoffat@718 8912 var docElem = window.document.documentElement;
djmoffat@718 8913
djmoffat@718 8914 /**
djmoffat@718 8915 * Gets a window from an element
djmoffat@718 8916 */
djmoffat@718 8917 function getWindow( elem ) {
djmoffat@718 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
djmoffat@718 8919 }
djmoffat@718 8920
djmoffat@718 8921 jQuery.offset = {
djmoffat@718 8922 setOffset: function( elem, options, i ) {
djmoffat@718 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
djmoffat@718 8924 position = jQuery.css( elem, "position" ),
djmoffat@718 8925 curElem = jQuery( elem ),
djmoffat@718 8926 props = {};
djmoffat@718 8927
djmoffat@718 8928 // Set position first, in-case top/left are set even on static elem
djmoffat@718 8929 if ( position === "static" ) {
djmoffat@718 8930 elem.style.position = "relative";
djmoffat@718 8931 }
djmoffat@718 8932
djmoffat@718 8933 curOffset = curElem.offset();
djmoffat@718 8934 curCSSTop = jQuery.css( elem, "top" );
djmoffat@718 8935 curCSSLeft = jQuery.css( elem, "left" );
djmoffat@718 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
djmoffat@718 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
djmoffat@718 8938
djmoffat@718 8939 // Need to be able to calculate position if either
djmoffat@718 8940 // top or left is auto and position is either absolute or fixed
djmoffat@718 8941 if ( calculatePosition ) {
djmoffat@718 8942 curPosition = curElem.position();
djmoffat@718 8943 curTop = curPosition.top;
djmoffat@718 8944 curLeft = curPosition.left;
djmoffat@718 8945
djmoffat@718 8946 } else {
djmoffat@718 8947 curTop = parseFloat( curCSSTop ) || 0;
djmoffat@718 8948 curLeft = parseFloat( curCSSLeft ) || 0;
djmoffat@718 8949 }
djmoffat@718 8950
djmoffat@718 8951 if ( jQuery.isFunction( options ) ) {
djmoffat@718 8952 options = options.call( elem, i, curOffset );
djmoffat@718 8953 }
djmoffat@718 8954
djmoffat@718 8955 if ( options.top != null ) {
djmoffat@718 8956 props.top = ( options.top - curOffset.top ) + curTop;
djmoffat@718 8957 }
djmoffat@718 8958 if ( options.left != null ) {
djmoffat@718 8959 props.left = ( options.left - curOffset.left ) + curLeft;
djmoffat@718 8960 }
djmoffat@718 8961
djmoffat@718 8962 if ( "using" in options ) {
djmoffat@718 8963 options.using.call( elem, props );
djmoffat@718 8964
djmoffat@718 8965 } else {
djmoffat@718 8966 curElem.css( props );
djmoffat@718 8967 }
djmoffat@718 8968 }
djmoffat@718 8969 };
djmoffat@718 8970
djmoffat@718 8971 jQuery.fn.extend({
djmoffat@718 8972 offset: function( options ) {
djmoffat@718 8973 if ( arguments.length ) {
djmoffat@718 8974 return options === undefined ?
djmoffat@718 8975 this :
djmoffat@718 8976 this.each(function( i ) {
djmoffat@718 8977 jQuery.offset.setOffset( this, options, i );
djmoffat@718 8978 });
djmoffat@718 8979 }
djmoffat@718 8980
djmoffat@718 8981 var docElem, win,
djmoffat@718 8982 elem = this[ 0 ],
djmoffat@718 8983 box = { top: 0, left: 0 },
djmoffat@718 8984 doc = elem && elem.ownerDocument;
djmoffat@718 8985
djmoffat@718 8986 if ( !doc ) {
djmoffat@718 8987 return;
djmoffat@718 8988 }
djmoffat@718 8989
djmoffat@718 8990 docElem = doc.documentElement;
djmoffat@718 8991
djmoffat@718 8992 // Make sure it's not a disconnected DOM node
djmoffat@718 8993 if ( !jQuery.contains( docElem, elem ) ) {
djmoffat@718 8994 return box;
djmoffat@718 8995 }
djmoffat@718 8996
djmoffat@718 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
djmoffat@718 8998 // If we don't have gBCR, just use 0,0 rather than error
djmoffat@718 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
djmoffat@718 9000 box = elem.getBoundingClientRect();
djmoffat@718 9001 }
djmoffat@718 9002 win = getWindow( doc );
djmoffat@718 9003 return {
djmoffat@718 9004 top: box.top + win.pageYOffset - docElem.clientTop,
djmoffat@718 9005 left: box.left + win.pageXOffset - docElem.clientLeft
djmoffat@718 9006 };
djmoffat@718 9007 },
djmoffat@718 9008
djmoffat@718 9009 position: function() {
djmoffat@718 9010 if ( !this[ 0 ] ) {
djmoffat@718 9011 return;
djmoffat@718 9012 }
djmoffat@718 9013
djmoffat@718 9014 var offsetParent, offset,
djmoffat@718 9015 elem = this[ 0 ],
djmoffat@718 9016 parentOffset = { top: 0, left: 0 };
djmoffat@718 9017
djmoffat@718 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
djmoffat@718 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
djmoffat@718 9020 // Assume getBoundingClientRect is there when computed position is fixed
djmoffat@718 9021 offset = elem.getBoundingClientRect();
djmoffat@718 9022
djmoffat@718 9023 } else {
djmoffat@718 9024 // Get *real* offsetParent
djmoffat@718 9025 offsetParent = this.offsetParent();
djmoffat@718 9026
djmoffat@718 9027 // Get correct offsets
djmoffat@718 9028 offset = this.offset();
djmoffat@718 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
djmoffat@718 9030 parentOffset = offsetParent.offset();
djmoffat@718 9031 }
djmoffat@718 9032
djmoffat@718 9033 // Add offsetParent borders
djmoffat@718 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
djmoffat@718 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
djmoffat@718 9036 }
djmoffat@718 9037
djmoffat@718 9038 // Subtract parent offsets and element margins
djmoffat@718 9039 return {
djmoffat@718 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
djmoffat@718 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
djmoffat@718 9042 };
djmoffat@718 9043 },
djmoffat@718 9044
djmoffat@718 9045 offsetParent: function() {
djmoffat@718 9046 return this.map(function() {
djmoffat@718 9047 var offsetParent = this.offsetParent || docElem;
djmoffat@718 9048
djmoffat@718 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
djmoffat@718 9050 offsetParent = offsetParent.offsetParent;
djmoffat@718 9051 }
djmoffat@718 9052
djmoffat@718 9053 return offsetParent || docElem;
djmoffat@718 9054 });
djmoffat@718 9055 }
djmoffat@718 9056 });
djmoffat@718 9057
djmoffat@718 9058 // Create scrollLeft and scrollTop methods
djmoffat@718 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
djmoffat@718 9060 var top = "pageYOffset" === prop;
djmoffat@718 9061
djmoffat@718 9062 jQuery.fn[ method ] = function( val ) {
djmoffat@718 9063 return access( this, function( elem, method, val ) {
djmoffat@718 9064 var win = getWindow( elem );
djmoffat@718 9065
djmoffat@718 9066 if ( val === undefined ) {
djmoffat@718 9067 return win ? win[ prop ] : elem[ method ];
djmoffat@718 9068 }
djmoffat@718 9069
djmoffat@718 9070 if ( win ) {
djmoffat@718 9071 win.scrollTo(
djmoffat@718 9072 !top ? val : window.pageXOffset,
djmoffat@718 9073 top ? val : window.pageYOffset
djmoffat@718 9074 );
djmoffat@718 9075
djmoffat@718 9076 } else {
djmoffat@718 9077 elem[ method ] = val;
djmoffat@718 9078 }
djmoffat@718 9079 }, method, val, arguments.length, null );
djmoffat@718 9080 };
djmoffat@718 9081 });
djmoffat@718 9082
djmoffat@718 9083 // Support: Safari<7+, Chrome<37+
djmoffat@718 9084 // Add the top/left cssHooks using jQuery.fn.position
djmoffat@718 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
djmoffat@718 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
djmoffat@718 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
djmoffat@718 9088 // rather than make the css module depend on the offset module, just check for it here
djmoffat@718 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
djmoffat@718 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
djmoffat@718 9091 function( elem, computed ) {
djmoffat@718 9092 if ( computed ) {
djmoffat@718 9093 computed = curCSS( elem, prop );
djmoffat@718 9094 // If curCSS returns percentage, fallback to offset
djmoffat@718 9095 return rnumnonpx.test( computed ) ?
djmoffat@718 9096 jQuery( elem ).position()[ prop ] + "px" :
djmoffat@718 9097 computed;
djmoffat@718 9098 }
djmoffat@718 9099 }
djmoffat@718 9100 );
djmoffat@718 9101 });
djmoffat@718 9102
djmoffat@718 9103
djmoffat@718 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
djmoffat@718 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
djmoffat@718 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
djmoffat@718 9107 // Margin is only for outerHeight, outerWidth
djmoffat@718 9108 jQuery.fn[ funcName ] = function( margin, value ) {
djmoffat@718 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
djmoffat@718 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
djmoffat@718 9111
djmoffat@718 9112 return access( this, function( elem, type, value ) {
djmoffat@718 9113 var doc;
djmoffat@718 9114
djmoffat@718 9115 if ( jQuery.isWindow( elem ) ) {
djmoffat@718 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
djmoffat@718 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
djmoffat@718 9118 // https://github.com/jquery/jquery/pull/764
djmoffat@718 9119 return elem.document.documentElement[ "client" + name ];
djmoffat@718 9120 }
djmoffat@718 9121
djmoffat@718 9122 // Get document width or height
djmoffat@718 9123 if ( elem.nodeType === 9 ) {
djmoffat@718 9124 doc = elem.documentElement;
djmoffat@718 9125
djmoffat@718 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
djmoffat@718 9127 // whichever is greatest
djmoffat@718 9128 return Math.max(
djmoffat@718 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
djmoffat@718 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
djmoffat@718 9131 doc[ "client" + name ]
djmoffat@718 9132 );
djmoffat@718 9133 }
djmoffat@718 9134
djmoffat@718 9135 return value === undefined ?
djmoffat@718 9136 // Get width or height on the element, requesting but not forcing parseFloat
djmoffat@718 9137 jQuery.css( elem, type, extra ) :
djmoffat@718 9138
djmoffat@718 9139 // Set width or height on the element
djmoffat@718 9140 jQuery.style( elem, type, value, extra );
djmoffat@718 9141 }, type, chainable ? margin : undefined, chainable, null );
djmoffat@718 9142 };
djmoffat@718 9143 });
djmoffat@718 9144 });
djmoffat@718 9145
djmoffat@718 9146
djmoffat@718 9147 // The number of elements contained in the matched element set
djmoffat@718 9148 jQuery.fn.size = function() {
djmoffat@718 9149 return this.length;
djmoffat@718 9150 };
djmoffat@718 9151
djmoffat@718 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
djmoffat@718 9153
djmoffat@718 9154
djmoffat@718 9155
djmoffat@718 9156
djmoffat@718 9157 // Register as a named AMD module, since jQuery can be concatenated with other
djmoffat@718 9158 // files that may use define, but not via a proper concatenation script that
djmoffat@718 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
djmoffat@718 9160 // way to register. Lowercase jquery is used because AMD module names are
djmoffat@718 9161 // derived from file names, and jQuery is normally delivered in a lowercase
djmoffat@718 9162 // file name. Do this after creating the global so that if an AMD module wants
djmoffat@718 9163 // to call noConflict to hide this version of jQuery, it will work.
djmoffat@718 9164
djmoffat@718 9165 // Note that for maximum portability, libraries that are not jQuery should
djmoffat@718 9166 // declare themselves as anonymous modules, and avoid setting a global if an
djmoffat@718 9167 // AMD loader is present. jQuery is a special case. For more information, see
djmoffat@718 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
djmoffat@718 9169
djmoffat@718 9170 if ( typeof define === "function" && define.amd ) {
djmoffat@718 9171 define( "jquery", [], function() {
djmoffat@718 9172 return jQuery;
djmoffat@718 9173 });
djmoffat@718 9174 }
djmoffat@718 9175
djmoffat@718 9176
djmoffat@718 9177
djmoffat@718 9178
djmoffat@718 9179 var
djmoffat@718 9180 // Map over jQuery in case of overwrite
djmoffat@718 9181 _jQuery = window.jQuery,
djmoffat@718 9182
djmoffat@718 9183 // Map over the $ in case of overwrite
djmoffat@718 9184 _$ = window.$;
djmoffat@718 9185
djmoffat@718 9186 jQuery.noConflict = function( deep ) {
djmoffat@718 9187 if ( window.$ === jQuery ) {
djmoffat@718 9188 window.$ = _$;
djmoffat@718 9189 }
djmoffat@718 9190
djmoffat@718 9191 if ( deep && window.jQuery === jQuery ) {
djmoffat@718 9192 window.jQuery = _jQuery;
djmoffat@718 9193 }
djmoffat@718 9194
djmoffat@718 9195 return jQuery;
djmoffat@718 9196 };
djmoffat@718 9197
djmoffat@718 9198 // Expose jQuery and $ identifiers, even in AMD
djmoffat@718 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
djmoffat@718 9200 // and CommonJS for browser emulators (#13566)
djmoffat@718 9201 if ( typeof noGlobal === strundefined ) {
djmoffat@718 9202 window.jQuery = window.$ = jQuery;
djmoffat@718 9203 }
djmoffat@718 9204
djmoffat@718 9205
djmoffat@718 9206
djmoffat@718 9207
djmoffat@718 9208 return jQuery;
djmoffat@718 9209
djmoffat@718 9210 }));