annotate jquery-2.1.4.js @ 2060:31ea66f4509d

README: paragraph on troubleshooting (copy from JavaScript Console)
author Brecht De Man <b.deman@qmul.ac.uk>
date Wed, 01 Jul 2015 11:55:08 +0100
parents c115a0b304b3
children
rev   line source
nickjillings@1541 1 /*!
nickjillings@1541 2 * jQuery JavaScript Library v2.1.4
nickjillings@1541 3 * http://jquery.com/
nickjillings@1541 4 *
nickjillings@1541 5 * Includes Sizzle.js
nickjillings@1541 6 * http://sizzlejs.com/
nickjillings@1541 7 *
nickjillings@1541 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1541 9 * Released under the MIT license
nickjillings@1541 10 * http://jquery.org/license
nickjillings@1541 11 *
nickjillings@1541 12 * Date: 2015-04-28T16:01Z
nickjillings@1541 13 */
nickjillings@1541 14
nickjillings@1541 15 (function( global, factory ) {
nickjillings@1541 16
nickjillings@1541 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nickjillings@1541 18 // For CommonJS and CommonJS-like environments where a proper `window`
nickjillings@1541 19 // is present, execute the factory and get jQuery.
nickjillings@1541 20 // For environments that do not have a `window` with a `document`
nickjillings@1541 21 // (such as Node.js), expose a factory as module.exports.
nickjillings@1541 22 // This accentuates the need for the creation of a real `window`.
nickjillings@1541 23 // e.g. var jQuery = require("jquery")(window);
nickjillings@1541 24 // See ticket #14549 for more info.
nickjillings@1541 25 module.exports = global.document ?
nickjillings@1541 26 factory( global, true ) :
nickjillings@1541 27 function( w ) {
nickjillings@1541 28 if ( !w.document ) {
nickjillings@1541 29 throw new Error( "jQuery requires a window with a document" );
nickjillings@1541 30 }
nickjillings@1541 31 return factory( w );
nickjillings@1541 32 };
nickjillings@1541 33 } else {
nickjillings@1541 34 factory( global );
nickjillings@1541 35 }
nickjillings@1541 36
nickjillings@1541 37 // Pass this if window is not defined yet
nickjillings@1541 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nickjillings@1541 39
nickjillings@1541 40 // Support: Firefox 18+
nickjillings@1541 41 // Can't be in strict mode, several libs including ASP.NET trace
nickjillings@1541 42 // the stack via arguments.caller.callee and Firefox dies if
nickjillings@1541 43 // you try to trace through "use strict" call chains. (#13335)
nickjillings@1541 44 //
nickjillings@1541 45
nickjillings@1541 46 var arr = [];
nickjillings@1541 47
nickjillings@1541 48 var slice = arr.slice;
nickjillings@1541 49
nickjillings@1541 50 var concat = arr.concat;
nickjillings@1541 51
nickjillings@1541 52 var push = arr.push;
nickjillings@1541 53
nickjillings@1541 54 var indexOf = arr.indexOf;
nickjillings@1541 55
nickjillings@1541 56 var class2type = {};
nickjillings@1541 57
nickjillings@1541 58 var toString = class2type.toString;
nickjillings@1541 59
nickjillings@1541 60 var hasOwn = class2type.hasOwnProperty;
nickjillings@1541 61
nickjillings@1541 62 var support = {};
nickjillings@1541 63
nickjillings@1541 64
nickjillings@1541 65
nickjillings@1541 66 var
nickjillings@1541 67 // Use the correct document accordingly with window argument (sandbox)
nickjillings@1541 68 document = window.document,
nickjillings@1541 69
nickjillings@1541 70 version = "2.1.4",
nickjillings@1541 71
nickjillings@1541 72 // Define a local copy of jQuery
nickjillings@1541 73 jQuery = function( selector, context ) {
nickjillings@1541 74 // The jQuery object is actually just the init constructor 'enhanced'
nickjillings@1541 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nickjillings@1541 76 return new jQuery.fn.init( selector, context );
nickjillings@1541 77 },
nickjillings@1541 78
nickjillings@1541 79 // Support: Android<4.1
nickjillings@1541 80 // Make sure we trim BOM and NBSP
nickjillings@1541 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nickjillings@1541 82
nickjillings@1541 83 // Matches dashed string for camelizing
nickjillings@1541 84 rmsPrefix = /^-ms-/,
nickjillings@1541 85 rdashAlpha = /-([\da-z])/gi,
nickjillings@1541 86
nickjillings@1541 87 // Used by jQuery.camelCase as callback to replace()
nickjillings@1541 88 fcamelCase = function( all, letter ) {
nickjillings@1541 89 return letter.toUpperCase();
nickjillings@1541 90 };
nickjillings@1541 91
nickjillings@1541 92 jQuery.fn = jQuery.prototype = {
nickjillings@1541 93 // The current version of jQuery being used
nickjillings@1541 94 jquery: version,
nickjillings@1541 95
nickjillings@1541 96 constructor: jQuery,
nickjillings@1541 97
nickjillings@1541 98 // Start with an empty selector
nickjillings@1541 99 selector: "",
nickjillings@1541 100
nickjillings@1541 101 // The default length of a jQuery object is 0
nickjillings@1541 102 length: 0,
nickjillings@1541 103
nickjillings@1541 104 toArray: function() {
nickjillings@1541 105 return slice.call( this );
nickjillings@1541 106 },
nickjillings@1541 107
nickjillings@1541 108 // Get the Nth element in the matched element set OR
nickjillings@1541 109 // Get the whole matched element set as a clean array
nickjillings@1541 110 get: function( num ) {
nickjillings@1541 111 return num != null ?
nickjillings@1541 112
nickjillings@1541 113 // Return just the one element from the set
nickjillings@1541 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nickjillings@1541 115
nickjillings@1541 116 // Return all the elements in a clean array
nickjillings@1541 117 slice.call( this );
nickjillings@1541 118 },
nickjillings@1541 119
nickjillings@1541 120 // Take an array of elements and push it onto the stack
nickjillings@1541 121 // (returning the new matched element set)
nickjillings@1541 122 pushStack: function( elems ) {
nickjillings@1541 123
nickjillings@1541 124 // Build a new jQuery matched element set
nickjillings@1541 125 var ret = jQuery.merge( this.constructor(), elems );
nickjillings@1541 126
nickjillings@1541 127 // Add the old object onto the stack (as a reference)
nickjillings@1541 128 ret.prevObject = this;
nickjillings@1541 129 ret.context = this.context;
nickjillings@1541 130
nickjillings@1541 131 // Return the newly-formed element set
nickjillings@1541 132 return ret;
nickjillings@1541 133 },
nickjillings@1541 134
nickjillings@1541 135 // Execute a callback for every element in the matched set.
nickjillings@1541 136 // (You can seed the arguments with an array of args, but this is
nickjillings@1541 137 // only used internally.)
nickjillings@1541 138 each: function( callback, args ) {
nickjillings@1541 139 return jQuery.each( this, callback, args );
nickjillings@1541 140 },
nickjillings@1541 141
nickjillings@1541 142 map: function( callback ) {
nickjillings@1541 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nickjillings@1541 144 return callback.call( elem, i, elem );
nickjillings@1541 145 }));
nickjillings@1541 146 },
nickjillings@1541 147
nickjillings@1541 148 slice: function() {
nickjillings@1541 149 return this.pushStack( slice.apply( this, arguments ) );
nickjillings@1541 150 },
nickjillings@1541 151
nickjillings@1541 152 first: function() {
nickjillings@1541 153 return this.eq( 0 );
nickjillings@1541 154 },
nickjillings@1541 155
nickjillings@1541 156 last: function() {
nickjillings@1541 157 return this.eq( -1 );
nickjillings@1541 158 },
nickjillings@1541 159
nickjillings@1541 160 eq: function( i ) {
nickjillings@1541 161 var len = this.length,
nickjillings@1541 162 j = +i + ( i < 0 ? len : 0 );
nickjillings@1541 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nickjillings@1541 164 },
nickjillings@1541 165
nickjillings@1541 166 end: function() {
nickjillings@1541 167 return this.prevObject || this.constructor(null);
nickjillings@1541 168 },
nickjillings@1541 169
nickjillings@1541 170 // For internal use only.
nickjillings@1541 171 // Behaves like an Array's method, not like a jQuery method.
nickjillings@1541 172 push: push,
nickjillings@1541 173 sort: arr.sort,
nickjillings@1541 174 splice: arr.splice
nickjillings@1541 175 };
nickjillings@1541 176
nickjillings@1541 177 jQuery.extend = jQuery.fn.extend = function() {
nickjillings@1541 178 var options, name, src, copy, copyIsArray, clone,
nickjillings@1541 179 target = arguments[0] || {},
nickjillings@1541 180 i = 1,
nickjillings@1541 181 length = arguments.length,
nickjillings@1541 182 deep = false;
nickjillings@1541 183
nickjillings@1541 184 // Handle a deep copy situation
nickjillings@1541 185 if ( typeof target === "boolean" ) {
nickjillings@1541 186 deep = target;
nickjillings@1541 187
nickjillings@1541 188 // Skip the boolean and the target
nickjillings@1541 189 target = arguments[ i ] || {};
nickjillings@1541 190 i++;
nickjillings@1541 191 }
nickjillings@1541 192
nickjillings@1541 193 // Handle case when target is a string or something (possible in deep copy)
nickjillings@1541 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nickjillings@1541 195 target = {};
nickjillings@1541 196 }
nickjillings@1541 197
nickjillings@1541 198 // Extend jQuery itself if only one argument is passed
nickjillings@1541 199 if ( i === length ) {
nickjillings@1541 200 target = this;
nickjillings@1541 201 i--;
nickjillings@1541 202 }
nickjillings@1541 203
nickjillings@1541 204 for ( ; i < length; i++ ) {
nickjillings@1541 205 // Only deal with non-null/undefined values
nickjillings@1541 206 if ( (options = arguments[ i ]) != null ) {
nickjillings@1541 207 // Extend the base object
nickjillings@1541 208 for ( name in options ) {
nickjillings@1541 209 src = target[ name ];
nickjillings@1541 210 copy = options[ name ];
nickjillings@1541 211
nickjillings@1541 212 // Prevent never-ending loop
nickjillings@1541 213 if ( target === copy ) {
nickjillings@1541 214 continue;
nickjillings@1541 215 }
nickjillings@1541 216
nickjillings@1541 217 // Recurse if we're merging plain objects or arrays
nickjillings@1541 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nickjillings@1541 219 if ( copyIsArray ) {
nickjillings@1541 220 copyIsArray = false;
nickjillings@1541 221 clone = src && jQuery.isArray(src) ? src : [];
nickjillings@1541 222
nickjillings@1541 223 } else {
nickjillings@1541 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nickjillings@1541 225 }
nickjillings@1541 226
nickjillings@1541 227 // Never move original objects, clone them
nickjillings@1541 228 target[ name ] = jQuery.extend( deep, clone, copy );
nickjillings@1541 229
nickjillings@1541 230 // Don't bring in undefined values
nickjillings@1541 231 } else if ( copy !== undefined ) {
nickjillings@1541 232 target[ name ] = copy;
nickjillings@1541 233 }
nickjillings@1541 234 }
nickjillings@1541 235 }
nickjillings@1541 236 }
nickjillings@1541 237
nickjillings@1541 238 // Return the modified object
nickjillings@1541 239 return target;
nickjillings@1541 240 };
nickjillings@1541 241
nickjillings@1541 242 jQuery.extend({
nickjillings@1541 243 // Unique for each copy of jQuery on the page
nickjillings@1541 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nickjillings@1541 245
nickjillings@1541 246 // Assume jQuery is ready without the ready module
nickjillings@1541 247 isReady: true,
nickjillings@1541 248
nickjillings@1541 249 error: function( msg ) {
nickjillings@1541 250 throw new Error( msg );
nickjillings@1541 251 },
nickjillings@1541 252
nickjillings@1541 253 noop: function() {},
nickjillings@1541 254
nickjillings@1541 255 isFunction: function( obj ) {
nickjillings@1541 256 return jQuery.type(obj) === "function";
nickjillings@1541 257 },
nickjillings@1541 258
nickjillings@1541 259 isArray: Array.isArray,
nickjillings@1541 260
nickjillings@1541 261 isWindow: function( obj ) {
nickjillings@1541 262 return obj != null && obj === obj.window;
nickjillings@1541 263 },
nickjillings@1541 264
nickjillings@1541 265 isNumeric: function( obj ) {
nickjillings@1541 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nickjillings@1541 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nickjillings@1541 268 // subtraction forces infinities to NaN
nickjillings@1541 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nickjillings@1541 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nickjillings@1541 271 },
nickjillings@1541 272
nickjillings@1541 273 isPlainObject: function( obj ) {
nickjillings@1541 274 // Not plain objects:
nickjillings@1541 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nickjillings@1541 276 // - DOM nodes
nickjillings@1541 277 // - window
nickjillings@1541 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nickjillings@1541 279 return false;
nickjillings@1541 280 }
nickjillings@1541 281
nickjillings@1541 282 if ( obj.constructor &&
nickjillings@1541 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nickjillings@1541 284 return false;
nickjillings@1541 285 }
nickjillings@1541 286
nickjillings@1541 287 // If the function hasn't returned already, we're confident that
nickjillings@1541 288 // |obj| is a plain object, created by {} or constructed with new Object
nickjillings@1541 289 return true;
nickjillings@1541 290 },
nickjillings@1541 291
nickjillings@1541 292 isEmptyObject: function( obj ) {
nickjillings@1541 293 var name;
nickjillings@1541 294 for ( name in obj ) {
nickjillings@1541 295 return false;
nickjillings@1541 296 }
nickjillings@1541 297 return true;
nickjillings@1541 298 },
nickjillings@1541 299
nickjillings@1541 300 type: function( obj ) {
nickjillings@1541 301 if ( obj == null ) {
nickjillings@1541 302 return obj + "";
nickjillings@1541 303 }
nickjillings@1541 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nickjillings@1541 305 return typeof obj === "object" || typeof obj === "function" ?
nickjillings@1541 306 class2type[ toString.call(obj) ] || "object" :
nickjillings@1541 307 typeof obj;
nickjillings@1541 308 },
nickjillings@1541 309
nickjillings@1541 310 // Evaluates a script in a global context
nickjillings@1541 311 globalEval: function( code ) {
nickjillings@1541 312 var script,
nickjillings@1541 313 indirect = eval;
nickjillings@1541 314
nickjillings@1541 315 code = jQuery.trim( code );
nickjillings@1541 316
nickjillings@1541 317 if ( code ) {
nickjillings@1541 318 // If the code includes a valid, prologue position
nickjillings@1541 319 // strict mode pragma, execute code by injecting a
nickjillings@1541 320 // script tag into the document.
nickjillings@1541 321 if ( code.indexOf("use strict") === 1 ) {
nickjillings@1541 322 script = document.createElement("script");
nickjillings@1541 323 script.text = code;
nickjillings@1541 324 document.head.appendChild( script ).parentNode.removeChild( script );
nickjillings@1541 325 } else {
nickjillings@1541 326 // Otherwise, avoid the DOM node creation, insertion
nickjillings@1541 327 // and removal by using an indirect global eval
nickjillings@1541 328 indirect( code );
nickjillings@1541 329 }
nickjillings@1541 330 }
nickjillings@1541 331 },
nickjillings@1541 332
nickjillings@1541 333 // Convert dashed to camelCase; used by the css and data modules
nickjillings@1541 334 // Support: IE9-11+
nickjillings@1541 335 // Microsoft forgot to hump their vendor prefix (#9572)
nickjillings@1541 336 camelCase: function( string ) {
nickjillings@1541 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nickjillings@1541 338 },
nickjillings@1541 339
nickjillings@1541 340 nodeName: function( elem, name ) {
nickjillings@1541 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nickjillings@1541 342 },
nickjillings@1541 343
nickjillings@1541 344 // args is for internal usage only
nickjillings@1541 345 each: function( obj, callback, args ) {
nickjillings@1541 346 var value,
nickjillings@1541 347 i = 0,
nickjillings@1541 348 length = obj.length,
nickjillings@1541 349 isArray = isArraylike( obj );
nickjillings@1541 350
nickjillings@1541 351 if ( args ) {
nickjillings@1541 352 if ( isArray ) {
nickjillings@1541 353 for ( ; i < length; i++ ) {
nickjillings@1541 354 value = callback.apply( obj[ i ], args );
nickjillings@1541 355
nickjillings@1541 356 if ( value === false ) {
nickjillings@1541 357 break;
nickjillings@1541 358 }
nickjillings@1541 359 }
nickjillings@1541 360 } else {
nickjillings@1541 361 for ( i in obj ) {
nickjillings@1541 362 value = callback.apply( obj[ i ], args );
nickjillings@1541 363
nickjillings@1541 364 if ( value === false ) {
nickjillings@1541 365 break;
nickjillings@1541 366 }
nickjillings@1541 367 }
nickjillings@1541 368 }
nickjillings@1541 369
nickjillings@1541 370 // A special, fast, case for the most common use of each
nickjillings@1541 371 } else {
nickjillings@1541 372 if ( isArray ) {
nickjillings@1541 373 for ( ; i < length; i++ ) {
nickjillings@1541 374 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1541 375
nickjillings@1541 376 if ( value === false ) {
nickjillings@1541 377 break;
nickjillings@1541 378 }
nickjillings@1541 379 }
nickjillings@1541 380 } else {
nickjillings@1541 381 for ( i in obj ) {
nickjillings@1541 382 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1541 383
nickjillings@1541 384 if ( value === false ) {
nickjillings@1541 385 break;
nickjillings@1541 386 }
nickjillings@1541 387 }
nickjillings@1541 388 }
nickjillings@1541 389 }
nickjillings@1541 390
nickjillings@1541 391 return obj;
nickjillings@1541 392 },
nickjillings@1541 393
nickjillings@1541 394 // Support: Android<4.1
nickjillings@1541 395 trim: function( text ) {
nickjillings@1541 396 return text == null ?
nickjillings@1541 397 "" :
nickjillings@1541 398 ( text + "" ).replace( rtrim, "" );
nickjillings@1541 399 },
nickjillings@1541 400
nickjillings@1541 401 // results is for internal usage only
nickjillings@1541 402 makeArray: function( arr, results ) {
nickjillings@1541 403 var ret = results || [];
nickjillings@1541 404
nickjillings@1541 405 if ( arr != null ) {
nickjillings@1541 406 if ( isArraylike( Object(arr) ) ) {
nickjillings@1541 407 jQuery.merge( ret,
nickjillings@1541 408 typeof arr === "string" ?
nickjillings@1541 409 [ arr ] : arr
nickjillings@1541 410 );
nickjillings@1541 411 } else {
nickjillings@1541 412 push.call( ret, arr );
nickjillings@1541 413 }
nickjillings@1541 414 }
nickjillings@1541 415
nickjillings@1541 416 return ret;
nickjillings@1541 417 },
nickjillings@1541 418
nickjillings@1541 419 inArray: function( elem, arr, i ) {
nickjillings@1541 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nickjillings@1541 421 },
nickjillings@1541 422
nickjillings@1541 423 merge: function( first, second ) {
nickjillings@1541 424 var len = +second.length,
nickjillings@1541 425 j = 0,
nickjillings@1541 426 i = first.length;
nickjillings@1541 427
nickjillings@1541 428 for ( ; j < len; j++ ) {
nickjillings@1541 429 first[ i++ ] = second[ j ];
nickjillings@1541 430 }
nickjillings@1541 431
nickjillings@1541 432 first.length = i;
nickjillings@1541 433
nickjillings@1541 434 return first;
nickjillings@1541 435 },
nickjillings@1541 436
nickjillings@1541 437 grep: function( elems, callback, invert ) {
nickjillings@1541 438 var callbackInverse,
nickjillings@1541 439 matches = [],
nickjillings@1541 440 i = 0,
nickjillings@1541 441 length = elems.length,
nickjillings@1541 442 callbackExpect = !invert;
nickjillings@1541 443
nickjillings@1541 444 // Go through the array, only saving the items
nickjillings@1541 445 // that pass the validator function
nickjillings@1541 446 for ( ; i < length; i++ ) {
nickjillings@1541 447 callbackInverse = !callback( elems[ i ], i );
nickjillings@1541 448 if ( callbackInverse !== callbackExpect ) {
nickjillings@1541 449 matches.push( elems[ i ] );
nickjillings@1541 450 }
nickjillings@1541 451 }
nickjillings@1541 452
nickjillings@1541 453 return matches;
nickjillings@1541 454 },
nickjillings@1541 455
nickjillings@1541 456 // arg is for internal usage only
nickjillings@1541 457 map: function( elems, callback, arg ) {
nickjillings@1541 458 var value,
nickjillings@1541 459 i = 0,
nickjillings@1541 460 length = elems.length,
nickjillings@1541 461 isArray = isArraylike( elems ),
nickjillings@1541 462 ret = [];
nickjillings@1541 463
nickjillings@1541 464 // Go through the array, translating each of the items to their new values
nickjillings@1541 465 if ( isArray ) {
nickjillings@1541 466 for ( ; i < length; i++ ) {
nickjillings@1541 467 value = callback( elems[ i ], i, arg );
nickjillings@1541 468
nickjillings@1541 469 if ( value != null ) {
nickjillings@1541 470 ret.push( value );
nickjillings@1541 471 }
nickjillings@1541 472 }
nickjillings@1541 473
nickjillings@1541 474 // Go through every key on the object,
nickjillings@1541 475 } else {
nickjillings@1541 476 for ( i in elems ) {
nickjillings@1541 477 value = callback( elems[ i ], i, arg );
nickjillings@1541 478
nickjillings@1541 479 if ( value != null ) {
nickjillings@1541 480 ret.push( value );
nickjillings@1541 481 }
nickjillings@1541 482 }
nickjillings@1541 483 }
nickjillings@1541 484
nickjillings@1541 485 // Flatten any nested arrays
nickjillings@1541 486 return concat.apply( [], ret );
nickjillings@1541 487 },
nickjillings@1541 488
nickjillings@1541 489 // A global GUID counter for objects
nickjillings@1541 490 guid: 1,
nickjillings@1541 491
nickjillings@1541 492 // Bind a function to a context, optionally partially applying any
nickjillings@1541 493 // arguments.
nickjillings@1541 494 proxy: function( fn, context ) {
nickjillings@1541 495 var tmp, args, proxy;
nickjillings@1541 496
nickjillings@1541 497 if ( typeof context === "string" ) {
nickjillings@1541 498 tmp = fn[ context ];
nickjillings@1541 499 context = fn;
nickjillings@1541 500 fn = tmp;
nickjillings@1541 501 }
nickjillings@1541 502
nickjillings@1541 503 // Quick check to determine if target is callable, in the spec
nickjillings@1541 504 // this throws a TypeError, but we will just return undefined.
nickjillings@1541 505 if ( !jQuery.isFunction( fn ) ) {
nickjillings@1541 506 return undefined;
nickjillings@1541 507 }
nickjillings@1541 508
nickjillings@1541 509 // Simulated bind
nickjillings@1541 510 args = slice.call( arguments, 2 );
nickjillings@1541 511 proxy = function() {
nickjillings@1541 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nickjillings@1541 513 };
nickjillings@1541 514
nickjillings@1541 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nickjillings@1541 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nickjillings@1541 517
nickjillings@1541 518 return proxy;
nickjillings@1541 519 },
nickjillings@1541 520
nickjillings@1541 521 now: Date.now,
nickjillings@1541 522
nickjillings@1541 523 // jQuery.support is not used in Core but other projects attach their
nickjillings@1541 524 // properties to it so it needs to exist.
nickjillings@1541 525 support: support
nickjillings@1541 526 });
nickjillings@1541 527
nickjillings@1541 528 // Populate the class2type map
nickjillings@1541 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nickjillings@1541 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nickjillings@1541 531 });
nickjillings@1541 532
nickjillings@1541 533 function isArraylike( obj ) {
nickjillings@1541 534
nickjillings@1541 535 // Support: iOS 8.2 (not reproducible in simulator)
nickjillings@1541 536 // `in` check used to prevent JIT error (gh-2145)
nickjillings@1541 537 // hasOwn isn't used here due to false negatives
nickjillings@1541 538 // regarding Nodelist length in IE
nickjillings@1541 539 var length = "length" in obj && obj.length,
nickjillings@1541 540 type = jQuery.type( obj );
nickjillings@1541 541
nickjillings@1541 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nickjillings@1541 543 return false;
nickjillings@1541 544 }
nickjillings@1541 545
nickjillings@1541 546 if ( obj.nodeType === 1 && length ) {
nickjillings@1541 547 return true;
nickjillings@1541 548 }
nickjillings@1541 549
nickjillings@1541 550 return type === "array" || length === 0 ||
nickjillings@1541 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nickjillings@1541 552 }
nickjillings@1541 553 var Sizzle =
nickjillings@1541 554 /*!
nickjillings@1541 555 * Sizzle CSS Selector Engine v2.2.0-pre
nickjillings@1541 556 * http://sizzlejs.com/
nickjillings@1541 557 *
nickjillings@1541 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1541 559 * Released under the MIT license
nickjillings@1541 560 * http://jquery.org/license
nickjillings@1541 561 *
nickjillings@1541 562 * Date: 2014-12-16
nickjillings@1541 563 */
nickjillings@1541 564 (function( window ) {
nickjillings@1541 565
nickjillings@1541 566 var i,
nickjillings@1541 567 support,
nickjillings@1541 568 Expr,
nickjillings@1541 569 getText,
nickjillings@1541 570 isXML,
nickjillings@1541 571 tokenize,
nickjillings@1541 572 compile,
nickjillings@1541 573 select,
nickjillings@1541 574 outermostContext,
nickjillings@1541 575 sortInput,
nickjillings@1541 576 hasDuplicate,
nickjillings@1541 577
nickjillings@1541 578 // Local document vars
nickjillings@1541 579 setDocument,
nickjillings@1541 580 document,
nickjillings@1541 581 docElem,
nickjillings@1541 582 documentIsHTML,
nickjillings@1541 583 rbuggyQSA,
nickjillings@1541 584 rbuggyMatches,
nickjillings@1541 585 matches,
nickjillings@1541 586 contains,
nickjillings@1541 587
nickjillings@1541 588 // Instance-specific data
nickjillings@1541 589 expando = "sizzle" + 1 * new Date(),
nickjillings@1541 590 preferredDoc = window.document,
nickjillings@1541 591 dirruns = 0,
nickjillings@1541 592 done = 0,
nickjillings@1541 593 classCache = createCache(),
nickjillings@1541 594 tokenCache = createCache(),
nickjillings@1541 595 compilerCache = createCache(),
nickjillings@1541 596 sortOrder = function( a, b ) {
nickjillings@1541 597 if ( a === b ) {
nickjillings@1541 598 hasDuplicate = true;
nickjillings@1541 599 }
nickjillings@1541 600 return 0;
nickjillings@1541 601 },
nickjillings@1541 602
nickjillings@1541 603 // General-purpose constants
nickjillings@1541 604 MAX_NEGATIVE = 1 << 31,
nickjillings@1541 605
nickjillings@1541 606 // Instance methods
nickjillings@1541 607 hasOwn = ({}).hasOwnProperty,
nickjillings@1541 608 arr = [],
nickjillings@1541 609 pop = arr.pop,
nickjillings@1541 610 push_native = arr.push,
nickjillings@1541 611 push = arr.push,
nickjillings@1541 612 slice = arr.slice,
nickjillings@1541 613 // Use a stripped-down indexOf as it's faster than native
nickjillings@1541 614 // http://jsperf.com/thor-indexof-vs-for/5
nickjillings@1541 615 indexOf = function( list, elem ) {
nickjillings@1541 616 var i = 0,
nickjillings@1541 617 len = list.length;
nickjillings@1541 618 for ( ; i < len; i++ ) {
nickjillings@1541 619 if ( list[i] === elem ) {
nickjillings@1541 620 return i;
nickjillings@1541 621 }
nickjillings@1541 622 }
nickjillings@1541 623 return -1;
nickjillings@1541 624 },
nickjillings@1541 625
nickjillings@1541 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nickjillings@1541 627
nickjillings@1541 628 // Regular expressions
nickjillings@1541 629
nickjillings@1541 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nickjillings@1541 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nickjillings@1541 632 // http://www.w3.org/TR/css3-syntax/#characters
nickjillings@1541 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nickjillings@1541 634
nickjillings@1541 635 // Loosely modeled on CSS identifier characters
nickjillings@1541 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nickjillings@1541 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nickjillings@1541 638 identifier = characterEncoding.replace( "w", "w#" ),
nickjillings@1541 639
nickjillings@1541 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nickjillings@1541 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nickjillings@1541 642 // Operator (capture 2)
nickjillings@1541 643 "*([*^$|!~]?=)" + whitespace +
nickjillings@1541 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nickjillings@1541 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nickjillings@1541 646 "*\\]",
nickjillings@1541 647
nickjillings@1541 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nickjillings@1541 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nickjillings@1541 650 // 1. quoted (capture 3; capture 4 or capture 5)
nickjillings@1541 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nickjillings@1541 652 // 2. simple (capture 6)
nickjillings@1541 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nickjillings@1541 654 // 3. anything else (capture 2)
nickjillings@1541 655 ".*" +
nickjillings@1541 656 ")\\)|)",
nickjillings@1541 657
nickjillings@1541 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nickjillings@1541 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nickjillings@1541 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nickjillings@1541 661
nickjillings@1541 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nickjillings@1541 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nickjillings@1541 664
nickjillings@1541 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nickjillings@1541 666
nickjillings@1541 667 rpseudo = new RegExp( pseudos ),
nickjillings@1541 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nickjillings@1541 669
nickjillings@1541 670 matchExpr = {
nickjillings@1541 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nickjillings@1541 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nickjillings@1541 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nickjillings@1541 674 "ATTR": new RegExp( "^" + attributes ),
nickjillings@1541 675 "PSEUDO": new RegExp( "^" + pseudos ),
nickjillings@1541 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nickjillings@1541 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nickjillings@1541 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nickjillings@1541 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nickjillings@1541 680 // For use in libraries implementing .is()
nickjillings@1541 681 // We use this for POS matching in `select`
nickjillings@1541 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nickjillings@1541 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nickjillings@1541 684 },
nickjillings@1541 685
nickjillings@1541 686 rinputs = /^(?:input|select|textarea|button)$/i,
nickjillings@1541 687 rheader = /^h\d$/i,
nickjillings@1541 688
nickjillings@1541 689 rnative = /^[^{]+\{\s*\[native \w/,
nickjillings@1541 690
nickjillings@1541 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nickjillings@1541 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nickjillings@1541 693
nickjillings@1541 694 rsibling = /[+~]/,
nickjillings@1541 695 rescape = /'|\\/g,
nickjillings@1541 696
nickjillings@1541 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nickjillings@1541 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nickjillings@1541 699 funescape = function( _, escaped, escapedWhitespace ) {
nickjillings@1541 700 var high = "0x" + escaped - 0x10000;
nickjillings@1541 701 // NaN means non-codepoint
nickjillings@1541 702 // Support: Firefox<24
nickjillings@1541 703 // Workaround erroneous numeric interpretation of +"0x"
nickjillings@1541 704 return high !== high || escapedWhitespace ?
nickjillings@1541 705 escaped :
nickjillings@1541 706 high < 0 ?
nickjillings@1541 707 // BMP codepoint
nickjillings@1541 708 String.fromCharCode( high + 0x10000 ) :
nickjillings@1541 709 // Supplemental Plane codepoint (surrogate pair)
nickjillings@1541 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nickjillings@1541 711 },
nickjillings@1541 712
nickjillings@1541 713 // Used for iframes
nickjillings@1541 714 // See setDocument()
nickjillings@1541 715 // Removing the function wrapper causes a "Permission Denied"
nickjillings@1541 716 // error in IE
nickjillings@1541 717 unloadHandler = function() {
nickjillings@1541 718 setDocument();
nickjillings@1541 719 };
nickjillings@1541 720
nickjillings@1541 721 // Optimize for push.apply( _, NodeList )
nickjillings@1541 722 try {
nickjillings@1541 723 push.apply(
nickjillings@1541 724 (arr = slice.call( preferredDoc.childNodes )),
nickjillings@1541 725 preferredDoc.childNodes
nickjillings@1541 726 );
nickjillings@1541 727 // Support: Android<4.0
nickjillings@1541 728 // Detect silently failing push.apply
nickjillings@1541 729 arr[ preferredDoc.childNodes.length ].nodeType;
nickjillings@1541 730 } catch ( e ) {
nickjillings@1541 731 push = { apply: arr.length ?
nickjillings@1541 732
nickjillings@1541 733 // Leverage slice if possible
nickjillings@1541 734 function( target, els ) {
nickjillings@1541 735 push_native.apply( target, slice.call(els) );
nickjillings@1541 736 } :
nickjillings@1541 737
nickjillings@1541 738 // Support: IE<9
nickjillings@1541 739 // Otherwise append directly
nickjillings@1541 740 function( target, els ) {
nickjillings@1541 741 var j = target.length,
nickjillings@1541 742 i = 0;
nickjillings@1541 743 // Can't trust NodeList.length
nickjillings@1541 744 while ( (target[j++] = els[i++]) ) {}
nickjillings@1541 745 target.length = j - 1;
nickjillings@1541 746 }
nickjillings@1541 747 };
nickjillings@1541 748 }
nickjillings@1541 749
nickjillings@1541 750 function Sizzle( selector, context, results, seed ) {
nickjillings@1541 751 var match, elem, m, nodeType,
nickjillings@1541 752 // QSA vars
nickjillings@1541 753 i, groups, old, nid, newContext, newSelector;
nickjillings@1541 754
nickjillings@1541 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nickjillings@1541 756 setDocument( context );
nickjillings@1541 757 }
nickjillings@1541 758
nickjillings@1541 759 context = context || document;
nickjillings@1541 760 results = results || [];
nickjillings@1541 761 nodeType = context.nodeType;
nickjillings@1541 762
nickjillings@1541 763 if ( typeof selector !== "string" || !selector ||
nickjillings@1541 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nickjillings@1541 765
nickjillings@1541 766 return results;
nickjillings@1541 767 }
nickjillings@1541 768
nickjillings@1541 769 if ( !seed && documentIsHTML ) {
nickjillings@1541 770
nickjillings@1541 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nickjillings@1541 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nickjillings@1541 773 // Speed-up: Sizzle("#ID")
nickjillings@1541 774 if ( (m = match[1]) ) {
nickjillings@1541 775 if ( nodeType === 9 ) {
nickjillings@1541 776 elem = context.getElementById( m );
nickjillings@1541 777 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1541 778 // nodes that are no longer in the document (jQuery #6963)
nickjillings@1541 779 if ( elem && elem.parentNode ) {
nickjillings@1541 780 // Handle the case where IE, Opera, and Webkit return items
nickjillings@1541 781 // by name instead of ID
nickjillings@1541 782 if ( elem.id === m ) {
nickjillings@1541 783 results.push( elem );
nickjillings@1541 784 return results;
nickjillings@1541 785 }
nickjillings@1541 786 } else {
nickjillings@1541 787 return results;
nickjillings@1541 788 }
nickjillings@1541 789 } else {
nickjillings@1541 790 // Context is not a document
nickjillings@1541 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nickjillings@1541 792 contains( context, elem ) && elem.id === m ) {
nickjillings@1541 793 results.push( elem );
nickjillings@1541 794 return results;
nickjillings@1541 795 }
nickjillings@1541 796 }
nickjillings@1541 797
nickjillings@1541 798 // Speed-up: Sizzle("TAG")
nickjillings@1541 799 } else if ( match[2] ) {
nickjillings@1541 800 push.apply( results, context.getElementsByTagName( selector ) );
nickjillings@1541 801 return results;
nickjillings@1541 802
nickjillings@1541 803 // Speed-up: Sizzle(".CLASS")
nickjillings@1541 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nickjillings@1541 805 push.apply( results, context.getElementsByClassName( m ) );
nickjillings@1541 806 return results;
nickjillings@1541 807 }
nickjillings@1541 808 }
nickjillings@1541 809
nickjillings@1541 810 // QSA path
nickjillings@1541 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nickjillings@1541 812 nid = old = expando;
nickjillings@1541 813 newContext = context;
nickjillings@1541 814 newSelector = nodeType !== 1 && selector;
nickjillings@1541 815
nickjillings@1541 816 // qSA works strangely on Element-rooted queries
nickjillings@1541 817 // We can work around this by specifying an extra ID on the root
nickjillings@1541 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nickjillings@1541 819 // IE 8 doesn't work on object elements
nickjillings@1541 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nickjillings@1541 821 groups = tokenize( selector );
nickjillings@1541 822
nickjillings@1541 823 if ( (old = context.getAttribute("id")) ) {
nickjillings@1541 824 nid = old.replace( rescape, "\\$&" );
nickjillings@1541 825 } else {
nickjillings@1541 826 context.setAttribute( "id", nid );
nickjillings@1541 827 }
nickjillings@1541 828 nid = "[id='" + nid + "'] ";
nickjillings@1541 829
nickjillings@1541 830 i = groups.length;
nickjillings@1541 831 while ( i-- ) {
nickjillings@1541 832 groups[i] = nid + toSelector( groups[i] );
nickjillings@1541 833 }
nickjillings@1541 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nickjillings@1541 835 newSelector = groups.join(",");
nickjillings@1541 836 }
nickjillings@1541 837
nickjillings@1541 838 if ( newSelector ) {
nickjillings@1541 839 try {
nickjillings@1541 840 push.apply( results,
nickjillings@1541 841 newContext.querySelectorAll( newSelector )
nickjillings@1541 842 );
nickjillings@1541 843 return results;
nickjillings@1541 844 } catch(qsaError) {
nickjillings@1541 845 } finally {
nickjillings@1541 846 if ( !old ) {
nickjillings@1541 847 context.removeAttribute("id");
nickjillings@1541 848 }
nickjillings@1541 849 }
nickjillings@1541 850 }
nickjillings@1541 851 }
nickjillings@1541 852 }
nickjillings@1541 853
nickjillings@1541 854 // All others
nickjillings@1541 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nickjillings@1541 856 }
nickjillings@1541 857
nickjillings@1541 858 /**
nickjillings@1541 859 * Create key-value caches of limited size
nickjillings@1541 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nickjillings@1541 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nickjillings@1541 862 * deleting the oldest entry
nickjillings@1541 863 */
nickjillings@1541 864 function createCache() {
nickjillings@1541 865 var keys = [];
nickjillings@1541 866
nickjillings@1541 867 function cache( key, value ) {
nickjillings@1541 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nickjillings@1541 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nickjillings@1541 870 // Only keep the most recent entries
nickjillings@1541 871 delete cache[ keys.shift() ];
nickjillings@1541 872 }
nickjillings@1541 873 return (cache[ key + " " ] = value);
nickjillings@1541 874 }
nickjillings@1541 875 return cache;
nickjillings@1541 876 }
nickjillings@1541 877
nickjillings@1541 878 /**
nickjillings@1541 879 * Mark a function for special use by Sizzle
nickjillings@1541 880 * @param {Function} fn The function to mark
nickjillings@1541 881 */
nickjillings@1541 882 function markFunction( fn ) {
nickjillings@1541 883 fn[ expando ] = true;
nickjillings@1541 884 return fn;
nickjillings@1541 885 }
nickjillings@1541 886
nickjillings@1541 887 /**
nickjillings@1541 888 * Support testing using an element
nickjillings@1541 889 * @param {Function} fn Passed the created div and expects a boolean result
nickjillings@1541 890 */
nickjillings@1541 891 function assert( fn ) {
nickjillings@1541 892 var div = document.createElement("div");
nickjillings@1541 893
nickjillings@1541 894 try {
nickjillings@1541 895 return !!fn( div );
nickjillings@1541 896 } catch (e) {
nickjillings@1541 897 return false;
nickjillings@1541 898 } finally {
nickjillings@1541 899 // Remove from its parent by default
nickjillings@1541 900 if ( div.parentNode ) {
nickjillings@1541 901 div.parentNode.removeChild( div );
nickjillings@1541 902 }
nickjillings@1541 903 // release memory in IE
nickjillings@1541 904 div = null;
nickjillings@1541 905 }
nickjillings@1541 906 }
nickjillings@1541 907
nickjillings@1541 908 /**
nickjillings@1541 909 * Adds the same handler for all of the specified attrs
nickjillings@1541 910 * @param {String} attrs Pipe-separated list of attributes
nickjillings@1541 911 * @param {Function} handler The method that will be applied
nickjillings@1541 912 */
nickjillings@1541 913 function addHandle( attrs, handler ) {
nickjillings@1541 914 var arr = attrs.split("|"),
nickjillings@1541 915 i = attrs.length;
nickjillings@1541 916
nickjillings@1541 917 while ( i-- ) {
nickjillings@1541 918 Expr.attrHandle[ arr[i] ] = handler;
nickjillings@1541 919 }
nickjillings@1541 920 }
nickjillings@1541 921
nickjillings@1541 922 /**
nickjillings@1541 923 * Checks document order of two siblings
nickjillings@1541 924 * @param {Element} a
nickjillings@1541 925 * @param {Element} b
nickjillings@1541 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nickjillings@1541 927 */
nickjillings@1541 928 function siblingCheck( a, b ) {
nickjillings@1541 929 var cur = b && a,
nickjillings@1541 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nickjillings@1541 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nickjillings@1541 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nickjillings@1541 933
nickjillings@1541 934 // Use IE sourceIndex if available on both nodes
nickjillings@1541 935 if ( diff ) {
nickjillings@1541 936 return diff;
nickjillings@1541 937 }
nickjillings@1541 938
nickjillings@1541 939 // Check if b follows a
nickjillings@1541 940 if ( cur ) {
nickjillings@1541 941 while ( (cur = cur.nextSibling) ) {
nickjillings@1541 942 if ( cur === b ) {
nickjillings@1541 943 return -1;
nickjillings@1541 944 }
nickjillings@1541 945 }
nickjillings@1541 946 }
nickjillings@1541 947
nickjillings@1541 948 return a ? 1 : -1;
nickjillings@1541 949 }
nickjillings@1541 950
nickjillings@1541 951 /**
nickjillings@1541 952 * Returns a function to use in pseudos for input types
nickjillings@1541 953 * @param {String} type
nickjillings@1541 954 */
nickjillings@1541 955 function createInputPseudo( type ) {
nickjillings@1541 956 return function( elem ) {
nickjillings@1541 957 var name = elem.nodeName.toLowerCase();
nickjillings@1541 958 return name === "input" && elem.type === type;
nickjillings@1541 959 };
nickjillings@1541 960 }
nickjillings@1541 961
nickjillings@1541 962 /**
nickjillings@1541 963 * Returns a function to use in pseudos for buttons
nickjillings@1541 964 * @param {String} type
nickjillings@1541 965 */
nickjillings@1541 966 function createButtonPseudo( type ) {
nickjillings@1541 967 return function( elem ) {
nickjillings@1541 968 var name = elem.nodeName.toLowerCase();
nickjillings@1541 969 return (name === "input" || name === "button") && elem.type === type;
nickjillings@1541 970 };
nickjillings@1541 971 }
nickjillings@1541 972
nickjillings@1541 973 /**
nickjillings@1541 974 * Returns a function to use in pseudos for positionals
nickjillings@1541 975 * @param {Function} fn
nickjillings@1541 976 */
nickjillings@1541 977 function createPositionalPseudo( fn ) {
nickjillings@1541 978 return markFunction(function( argument ) {
nickjillings@1541 979 argument = +argument;
nickjillings@1541 980 return markFunction(function( seed, matches ) {
nickjillings@1541 981 var j,
nickjillings@1541 982 matchIndexes = fn( [], seed.length, argument ),
nickjillings@1541 983 i = matchIndexes.length;
nickjillings@1541 984
nickjillings@1541 985 // Match elements found at the specified indexes
nickjillings@1541 986 while ( i-- ) {
nickjillings@1541 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nickjillings@1541 988 seed[j] = !(matches[j] = seed[j]);
nickjillings@1541 989 }
nickjillings@1541 990 }
nickjillings@1541 991 });
nickjillings@1541 992 });
nickjillings@1541 993 }
nickjillings@1541 994
nickjillings@1541 995 /**
nickjillings@1541 996 * Checks a node for validity as a Sizzle context
nickjillings@1541 997 * @param {Element|Object=} context
nickjillings@1541 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nickjillings@1541 999 */
nickjillings@1541 1000 function testContext( context ) {
nickjillings@1541 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nickjillings@1541 1002 }
nickjillings@1541 1003
nickjillings@1541 1004 // Expose support vars for convenience
nickjillings@1541 1005 support = Sizzle.support = {};
nickjillings@1541 1006
nickjillings@1541 1007 /**
nickjillings@1541 1008 * Detects XML nodes
nickjillings@1541 1009 * @param {Element|Object} elem An element or a document
nickjillings@1541 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nickjillings@1541 1011 */
nickjillings@1541 1012 isXML = Sizzle.isXML = function( elem ) {
nickjillings@1541 1013 // documentElement is verified for cases where it doesn't yet exist
nickjillings@1541 1014 // (such as loading iframes in IE - #4833)
nickjillings@1541 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nickjillings@1541 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nickjillings@1541 1017 };
nickjillings@1541 1018
nickjillings@1541 1019 /**
nickjillings@1541 1020 * Sets document-related variables once based on the current document
nickjillings@1541 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nickjillings@1541 1022 * @returns {Object} Returns the current document
nickjillings@1541 1023 */
nickjillings@1541 1024 setDocument = Sizzle.setDocument = function( node ) {
nickjillings@1541 1025 var hasCompare, parent,
nickjillings@1541 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nickjillings@1541 1027
nickjillings@1541 1028 // If no document and documentElement is available, return
nickjillings@1541 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nickjillings@1541 1030 return document;
nickjillings@1541 1031 }
nickjillings@1541 1032
nickjillings@1541 1033 // Set our document
nickjillings@1541 1034 document = doc;
nickjillings@1541 1035 docElem = doc.documentElement;
nickjillings@1541 1036 parent = doc.defaultView;
nickjillings@1541 1037
nickjillings@1541 1038 // Support: IE>8
nickjillings@1541 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nickjillings@1541 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nickjillings@1541 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nickjillings@1541 1042 if ( parent && parent !== parent.top ) {
nickjillings@1541 1043 // IE11 does not have attachEvent, so all must suffer
nickjillings@1541 1044 if ( parent.addEventListener ) {
nickjillings@1541 1045 parent.addEventListener( "unload", unloadHandler, false );
nickjillings@1541 1046 } else if ( parent.attachEvent ) {
nickjillings@1541 1047 parent.attachEvent( "onunload", unloadHandler );
nickjillings@1541 1048 }
nickjillings@1541 1049 }
nickjillings@1541 1050
nickjillings@1541 1051 /* Support tests
nickjillings@1541 1052 ---------------------------------------------------------------------- */
nickjillings@1541 1053 documentIsHTML = !isXML( doc );
nickjillings@1541 1054
nickjillings@1541 1055 /* Attributes
nickjillings@1541 1056 ---------------------------------------------------------------------- */
nickjillings@1541 1057
nickjillings@1541 1058 // Support: IE<8
nickjillings@1541 1059 // Verify that getAttribute really returns attributes and not properties
nickjillings@1541 1060 // (excepting IE8 booleans)
nickjillings@1541 1061 support.attributes = assert(function( div ) {
nickjillings@1541 1062 div.className = "i";
nickjillings@1541 1063 return !div.getAttribute("className");
nickjillings@1541 1064 });
nickjillings@1541 1065
nickjillings@1541 1066 /* getElement(s)By*
nickjillings@1541 1067 ---------------------------------------------------------------------- */
nickjillings@1541 1068
nickjillings@1541 1069 // Check if getElementsByTagName("*") returns only elements
nickjillings@1541 1070 support.getElementsByTagName = assert(function( div ) {
nickjillings@1541 1071 div.appendChild( doc.createComment("") );
nickjillings@1541 1072 return !div.getElementsByTagName("*").length;
nickjillings@1541 1073 });
nickjillings@1541 1074
nickjillings@1541 1075 // Support: IE<9
nickjillings@1541 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nickjillings@1541 1077
nickjillings@1541 1078 // Support: IE<10
nickjillings@1541 1079 // Check if getElementById returns elements by name
nickjillings@1541 1080 // The broken getElementById methods don't pick up programatically-set names,
nickjillings@1541 1081 // so use a roundabout getElementsByName test
nickjillings@1541 1082 support.getById = assert(function( div ) {
nickjillings@1541 1083 docElem.appendChild( div ).id = expando;
nickjillings@1541 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nickjillings@1541 1085 });
nickjillings@1541 1086
nickjillings@1541 1087 // ID find and filter
nickjillings@1541 1088 if ( support.getById ) {
nickjillings@1541 1089 Expr.find["ID"] = function( id, context ) {
nickjillings@1541 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nickjillings@1541 1091 var m = context.getElementById( id );
nickjillings@1541 1092 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1541 1093 // nodes that are no longer in the document #6963
nickjillings@1541 1094 return m && m.parentNode ? [ m ] : [];
nickjillings@1541 1095 }
nickjillings@1541 1096 };
nickjillings@1541 1097 Expr.filter["ID"] = function( id ) {
nickjillings@1541 1098 var attrId = id.replace( runescape, funescape );
nickjillings@1541 1099 return function( elem ) {
nickjillings@1541 1100 return elem.getAttribute("id") === attrId;
nickjillings@1541 1101 };
nickjillings@1541 1102 };
nickjillings@1541 1103 } else {
nickjillings@1541 1104 // Support: IE6/7
nickjillings@1541 1105 // getElementById is not reliable as a find shortcut
nickjillings@1541 1106 delete Expr.find["ID"];
nickjillings@1541 1107
nickjillings@1541 1108 Expr.filter["ID"] = function( id ) {
nickjillings@1541 1109 var attrId = id.replace( runescape, funescape );
nickjillings@1541 1110 return function( elem ) {
nickjillings@1541 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nickjillings@1541 1112 return node && node.value === attrId;
nickjillings@1541 1113 };
nickjillings@1541 1114 };
nickjillings@1541 1115 }
nickjillings@1541 1116
nickjillings@1541 1117 // Tag
nickjillings@1541 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nickjillings@1541 1119 function( tag, context ) {
nickjillings@1541 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nickjillings@1541 1121 return context.getElementsByTagName( tag );
nickjillings@1541 1122
nickjillings@1541 1123 // DocumentFragment nodes don't have gEBTN
nickjillings@1541 1124 } else if ( support.qsa ) {
nickjillings@1541 1125 return context.querySelectorAll( tag );
nickjillings@1541 1126 }
nickjillings@1541 1127 } :
nickjillings@1541 1128
nickjillings@1541 1129 function( tag, context ) {
nickjillings@1541 1130 var elem,
nickjillings@1541 1131 tmp = [],
nickjillings@1541 1132 i = 0,
nickjillings@1541 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nickjillings@1541 1134 results = context.getElementsByTagName( tag );
nickjillings@1541 1135
nickjillings@1541 1136 // Filter out possible comments
nickjillings@1541 1137 if ( tag === "*" ) {
nickjillings@1541 1138 while ( (elem = results[i++]) ) {
nickjillings@1541 1139 if ( elem.nodeType === 1 ) {
nickjillings@1541 1140 tmp.push( elem );
nickjillings@1541 1141 }
nickjillings@1541 1142 }
nickjillings@1541 1143
nickjillings@1541 1144 return tmp;
nickjillings@1541 1145 }
nickjillings@1541 1146 return results;
nickjillings@1541 1147 };
nickjillings@1541 1148
nickjillings@1541 1149 // Class
nickjillings@1541 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nickjillings@1541 1151 if ( documentIsHTML ) {
nickjillings@1541 1152 return context.getElementsByClassName( className );
nickjillings@1541 1153 }
nickjillings@1541 1154 };
nickjillings@1541 1155
nickjillings@1541 1156 /* QSA/matchesSelector
nickjillings@1541 1157 ---------------------------------------------------------------------- */
nickjillings@1541 1158
nickjillings@1541 1159 // QSA and matchesSelector support
nickjillings@1541 1160
nickjillings@1541 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nickjillings@1541 1162 rbuggyMatches = [];
nickjillings@1541 1163
nickjillings@1541 1164 // qSa(:focus) reports false when true (Chrome 21)
nickjillings@1541 1165 // We allow this because of a bug in IE8/9 that throws an error
nickjillings@1541 1166 // whenever `document.activeElement` is accessed on an iframe
nickjillings@1541 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nickjillings@1541 1168 // See http://bugs.jquery.com/ticket/13378
nickjillings@1541 1169 rbuggyQSA = [];
nickjillings@1541 1170
nickjillings@1541 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nickjillings@1541 1172 // Build QSA regex
nickjillings@1541 1173 // Regex strategy adopted from Diego Perini
nickjillings@1541 1174 assert(function( div ) {
nickjillings@1541 1175 // Select is set to empty string on purpose
nickjillings@1541 1176 // This is to test IE's treatment of not explicitly
nickjillings@1541 1177 // setting a boolean content attribute,
nickjillings@1541 1178 // since its presence should be enough
nickjillings@1541 1179 // http://bugs.jquery.com/ticket/12359
nickjillings@1541 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nickjillings@1541 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nickjillings@1541 1182 "<option selected=''></option></select>";
nickjillings@1541 1183
nickjillings@1541 1184 // Support: IE8, Opera 11-12.16
nickjillings@1541 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nickjillings@1541 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nickjillings@1541 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nickjillings@1541 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nickjillings@1541 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nickjillings@1541 1190 }
nickjillings@1541 1191
nickjillings@1541 1192 // Support: IE8
nickjillings@1541 1193 // Boolean attributes and "value" are not treated correctly
nickjillings@1541 1194 if ( !div.querySelectorAll("[selected]").length ) {
nickjillings@1541 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nickjillings@1541 1196 }
nickjillings@1541 1197
nickjillings@1541 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nickjillings@1541 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nickjillings@1541 1200 rbuggyQSA.push("~=");
nickjillings@1541 1201 }
nickjillings@1541 1202
nickjillings@1541 1203 // Webkit/Opera - :checked should return selected option elements
nickjillings@1541 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1541 1205 // IE8 throws error here and will not see later tests
nickjillings@1541 1206 if ( !div.querySelectorAll(":checked").length ) {
nickjillings@1541 1207 rbuggyQSA.push(":checked");
nickjillings@1541 1208 }
nickjillings@1541 1209
nickjillings@1541 1210 // Support: Safari 8+, iOS 8+
nickjillings@1541 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nickjillings@1541 1212 // In-page `selector#id sibing-combinator selector` fails
nickjillings@1541 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nickjillings@1541 1214 rbuggyQSA.push(".#.+[+~]");
nickjillings@1541 1215 }
nickjillings@1541 1216 });
nickjillings@1541 1217
nickjillings@1541 1218 assert(function( div ) {
nickjillings@1541 1219 // Support: Windows 8 Native Apps
nickjillings@1541 1220 // The type and name attributes are restricted during .innerHTML assignment
nickjillings@1541 1221 var input = doc.createElement("input");
nickjillings@1541 1222 input.setAttribute( "type", "hidden" );
nickjillings@1541 1223 div.appendChild( input ).setAttribute( "name", "D" );
nickjillings@1541 1224
nickjillings@1541 1225 // Support: IE8
nickjillings@1541 1226 // Enforce case-sensitivity of name attribute
nickjillings@1541 1227 if ( div.querySelectorAll("[name=d]").length ) {
nickjillings@1541 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nickjillings@1541 1229 }
nickjillings@1541 1230
nickjillings@1541 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nickjillings@1541 1232 // IE8 throws error here and will not see later tests
nickjillings@1541 1233 if ( !div.querySelectorAll(":enabled").length ) {
nickjillings@1541 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nickjillings@1541 1235 }
nickjillings@1541 1236
nickjillings@1541 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nickjillings@1541 1238 div.querySelectorAll("*,:x");
nickjillings@1541 1239 rbuggyQSA.push(",.*:");
nickjillings@1541 1240 });
nickjillings@1541 1241 }
nickjillings@1541 1242
nickjillings@1541 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nickjillings@1541 1244 docElem.webkitMatchesSelector ||
nickjillings@1541 1245 docElem.mozMatchesSelector ||
nickjillings@1541 1246 docElem.oMatchesSelector ||
nickjillings@1541 1247 docElem.msMatchesSelector) )) ) {
nickjillings@1541 1248
nickjillings@1541 1249 assert(function( div ) {
nickjillings@1541 1250 // Check to see if it's possible to do matchesSelector
nickjillings@1541 1251 // on a disconnected node (IE 9)
nickjillings@1541 1252 support.disconnectedMatch = matches.call( div, "div" );
nickjillings@1541 1253
nickjillings@1541 1254 // This should fail with an exception
nickjillings@1541 1255 // Gecko does not error, returns false instead
nickjillings@1541 1256 matches.call( div, "[s!='']:x" );
nickjillings@1541 1257 rbuggyMatches.push( "!=", pseudos );
nickjillings@1541 1258 });
nickjillings@1541 1259 }
nickjillings@1541 1260
nickjillings@1541 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nickjillings@1541 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nickjillings@1541 1263
nickjillings@1541 1264 /* Contains
nickjillings@1541 1265 ---------------------------------------------------------------------- */
nickjillings@1541 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nickjillings@1541 1267
nickjillings@1541 1268 // Element contains another
nickjillings@1541 1269 // Purposefully does not implement inclusive descendent
nickjillings@1541 1270 // As in, an element does not contain itself
nickjillings@1541 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nickjillings@1541 1272 function( a, b ) {
nickjillings@1541 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nickjillings@1541 1274 bup = b && b.parentNode;
nickjillings@1541 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nickjillings@1541 1276 adown.contains ?
nickjillings@1541 1277 adown.contains( bup ) :
nickjillings@1541 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nickjillings@1541 1279 ));
nickjillings@1541 1280 } :
nickjillings@1541 1281 function( a, b ) {
nickjillings@1541 1282 if ( b ) {
nickjillings@1541 1283 while ( (b = b.parentNode) ) {
nickjillings@1541 1284 if ( b === a ) {
nickjillings@1541 1285 return true;
nickjillings@1541 1286 }
nickjillings@1541 1287 }
nickjillings@1541 1288 }
nickjillings@1541 1289 return false;
nickjillings@1541 1290 };
nickjillings@1541 1291
nickjillings@1541 1292 /* Sorting
nickjillings@1541 1293 ---------------------------------------------------------------------- */
nickjillings@1541 1294
nickjillings@1541 1295 // Document order sorting
nickjillings@1541 1296 sortOrder = hasCompare ?
nickjillings@1541 1297 function( a, b ) {
nickjillings@1541 1298
nickjillings@1541 1299 // Flag for duplicate removal
nickjillings@1541 1300 if ( a === b ) {
nickjillings@1541 1301 hasDuplicate = true;
nickjillings@1541 1302 return 0;
nickjillings@1541 1303 }
nickjillings@1541 1304
nickjillings@1541 1305 // Sort on method existence if only one input has compareDocumentPosition
nickjillings@1541 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nickjillings@1541 1307 if ( compare ) {
nickjillings@1541 1308 return compare;
nickjillings@1541 1309 }
nickjillings@1541 1310
nickjillings@1541 1311 // Calculate position if both inputs belong to the same document
nickjillings@1541 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nickjillings@1541 1313 a.compareDocumentPosition( b ) :
nickjillings@1541 1314
nickjillings@1541 1315 // Otherwise we know they are disconnected
nickjillings@1541 1316 1;
nickjillings@1541 1317
nickjillings@1541 1318 // Disconnected nodes
nickjillings@1541 1319 if ( compare & 1 ||
nickjillings@1541 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nickjillings@1541 1321
nickjillings@1541 1322 // Choose the first element that is related to our preferred document
nickjillings@1541 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nickjillings@1541 1324 return -1;
nickjillings@1541 1325 }
nickjillings@1541 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nickjillings@1541 1327 return 1;
nickjillings@1541 1328 }
nickjillings@1541 1329
nickjillings@1541 1330 // Maintain original order
nickjillings@1541 1331 return sortInput ?
nickjillings@1541 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1541 1333 0;
nickjillings@1541 1334 }
nickjillings@1541 1335
nickjillings@1541 1336 return compare & 4 ? -1 : 1;
nickjillings@1541 1337 } :
nickjillings@1541 1338 function( a, b ) {
nickjillings@1541 1339 // Exit early if the nodes are identical
nickjillings@1541 1340 if ( a === b ) {
nickjillings@1541 1341 hasDuplicate = true;
nickjillings@1541 1342 return 0;
nickjillings@1541 1343 }
nickjillings@1541 1344
nickjillings@1541 1345 var cur,
nickjillings@1541 1346 i = 0,
nickjillings@1541 1347 aup = a.parentNode,
nickjillings@1541 1348 bup = b.parentNode,
nickjillings@1541 1349 ap = [ a ],
nickjillings@1541 1350 bp = [ b ];
nickjillings@1541 1351
nickjillings@1541 1352 // Parentless nodes are either documents or disconnected
nickjillings@1541 1353 if ( !aup || !bup ) {
nickjillings@1541 1354 return a === doc ? -1 :
nickjillings@1541 1355 b === doc ? 1 :
nickjillings@1541 1356 aup ? -1 :
nickjillings@1541 1357 bup ? 1 :
nickjillings@1541 1358 sortInput ?
nickjillings@1541 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1541 1360 0;
nickjillings@1541 1361
nickjillings@1541 1362 // If the nodes are siblings, we can do a quick check
nickjillings@1541 1363 } else if ( aup === bup ) {
nickjillings@1541 1364 return siblingCheck( a, b );
nickjillings@1541 1365 }
nickjillings@1541 1366
nickjillings@1541 1367 // Otherwise we need full lists of their ancestors for comparison
nickjillings@1541 1368 cur = a;
nickjillings@1541 1369 while ( (cur = cur.parentNode) ) {
nickjillings@1541 1370 ap.unshift( cur );
nickjillings@1541 1371 }
nickjillings@1541 1372 cur = b;
nickjillings@1541 1373 while ( (cur = cur.parentNode) ) {
nickjillings@1541 1374 bp.unshift( cur );
nickjillings@1541 1375 }
nickjillings@1541 1376
nickjillings@1541 1377 // Walk down the tree looking for a discrepancy
nickjillings@1541 1378 while ( ap[i] === bp[i] ) {
nickjillings@1541 1379 i++;
nickjillings@1541 1380 }
nickjillings@1541 1381
nickjillings@1541 1382 return i ?
nickjillings@1541 1383 // Do a sibling check if the nodes have a common ancestor
nickjillings@1541 1384 siblingCheck( ap[i], bp[i] ) :
nickjillings@1541 1385
nickjillings@1541 1386 // Otherwise nodes in our document sort first
nickjillings@1541 1387 ap[i] === preferredDoc ? -1 :
nickjillings@1541 1388 bp[i] === preferredDoc ? 1 :
nickjillings@1541 1389 0;
nickjillings@1541 1390 };
nickjillings@1541 1391
nickjillings@1541 1392 return doc;
nickjillings@1541 1393 };
nickjillings@1541 1394
nickjillings@1541 1395 Sizzle.matches = function( expr, elements ) {
nickjillings@1541 1396 return Sizzle( expr, null, null, elements );
nickjillings@1541 1397 };
nickjillings@1541 1398
nickjillings@1541 1399 Sizzle.matchesSelector = function( elem, expr ) {
nickjillings@1541 1400 // Set document vars if needed
nickjillings@1541 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1541 1402 setDocument( elem );
nickjillings@1541 1403 }
nickjillings@1541 1404
nickjillings@1541 1405 // Make sure that attribute selectors are quoted
nickjillings@1541 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nickjillings@1541 1407
nickjillings@1541 1408 if ( support.matchesSelector && documentIsHTML &&
nickjillings@1541 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nickjillings@1541 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nickjillings@1541 1411
nickjillings@1541 1412 try {
nickjillings@1541 1413 var ret = matches.call( elem, expr );
nickjillings@1541 1414
nickjillings@1541 1415 // IE 9's matchesSelector returns false on disconnected nodes
nickjillings@1541 1416 if ( ret || support.disconnectedMatch ||
nickjillings@1541 1417 // As well, disconnected nodes are said to be in a document
nickjillings@1541 1418 // fragment in IE 9
nickjillings@1541 1419 elem.document && elem.document.nodeType !== 11 ) {
nickjillings@1541 1420 return ret;
nickjillings@1541 1421 }
nickjillings@1541 1422 } catch (e) {}
nickjillings@1541 1423 }
nickjillings@1541 1424
nickjillings@1541 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nickjillings@1541 1426 };
nickjillings@1541 1427
nickjillings@1541 1428 Sizzle.contains = function( context, elem ) {
nickjillings@1541 1429 // Set document vars if needed
nickjillings@1541 1430 if ( ( context.ownerDocument || context ) !== document ) {
nickjillings@1541 1431 setDocument( context );
nickjillings@1541 1432 }
nickjillings@1541 1433 return contains( context, elem );
nickjillings@1541 1434 };
nickjillings@1541 1435
nickjillings@1541 1436 Sizzle.attr = function( elem, name ) {
nickjillings@1541 1437 // Set document vars if needed
nickjillings@1541 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1541 1439 setDocument( elem );
nickjillings@1541 1440 }
nickjillings@1541 1441
nickjillings@1541 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nickjillings@1541 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nickjillings@1541 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nickjillings@1541 1445 fn( elem, name, !documentIsHTML ) :
nickjillings@1541 1446 undefined;
nickjillings@1541 1447
nickjillings@1541 1448 return val !== undefined ?
nickjillings@1541 1449 val :
nickjillings@1541 1450 support.attributes || !documentIsHTML ?
nickjillings@1541 1451 elem.getAttribute( name ) :
nickjillings@1541 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nickjillings@1541 1453 val.value :
nickjillings@1541 1454 null;
nickjillings@1541 1455 };
nickjillings@1541 1456
nickjillings@1541 1457 Sizzle.error = function( msg ) {
nickjillings@1541 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nickjillings@1541 1459 };
nickjillings@1541 1460
nickjillings@1541 1461 /**
nickjillings@1541 1462 * Document sorting and removing duplicates
nickjillings@1541 1463 * @param {ArrayLike} results
nickjillings@1541 1464 */
nickjillings@1541 1465 Sizzle.uniqueSort = function( results ) {
nickjillings@1541 1466 var elem,
nickjillings@1541 1467 duplicates = [],
nickjillings@1541 1468 j = 0,
nickjillings@1541 1469 i = 0;
nickjillings@1541 1470
nickjillings@1541 1471 // Unless we *know* we can detect duplicates, assume their presence
nickjillings@1541 1472 hasDuplicate = !support.detectDuplicates;
nickjillings@1541 1473 sortInput = !support.sortStable && results.slice( 0 );
nickjillings@1541 1474 results.sort( sortOrder );
nickjillings@1541 1475
nickjillings@1541 1476 if ( hasDuplicate ) {
nickjillings@1541 1477 while ( (elem = results[i++]) ) {
nickjillings@1541 1478 if ( elem === results[ i ] ) {
nickjillings@1541 1479 j = duplicates.push( i );
nickjillings@1541 1480 }
nickjillings@1541 1481 }
nickjillings@1541 1482 while ( j-- ) {
nickjillings@1541 1483 results.splice( duplicates[ j ], 1 );
nickjillings@1541 1484 }
nickjillings@1541 1485 }
nickjillings@1541 1486
nickjillings@1541 1487 // Clear input after sorting to release objects
nickjillings@1541 1488 // See https://github.com/jquery/sizzle/pull/225
nickjillings@1541 1489 sortInput = null;
nickjillings@1541 1490
nickjillings@1541 1491 return results;
nickjillings@1541 1492 };
nickjillings@1541 1493
nickjillings@1541 1494 /**
nickjillings@1541 1495 * Utility function for retrieving the text value of an array of DOM nodes
nickjillings@1541 1496 * @param {Array|Element} elem
nickjillings@1541 1497 */
nickjillings@1541 1498 getText = Sizzle.getText = function( elem ) {
nickjillings@1541 1499 var node,
nickjillings@1541 1500 ret = "",
nickjillings@1541 1501 i = 0,
nickjillings@1541 1502 nodeType = elem.nodeType;
nickjillings@1541 1503
nickjillings@1541 1504 if ( !nodeType ) {
nickjillings@1541 1505 // If no nodeType, this is expected to be an array
nickjillings@1541 1506 while ( (node = elem[i++]) ) {
nickjillings@1541 1507 // Do not traverse comment nodes
nickjillings@1541 1508 ret += getText( node );
nickjillings@1541 1509 }
nickjillings@1541 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nickjillings@1541 1511 // Use textContent for elements
nickjillings@1541 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nickjillings@1541 1513 if ( typeof elem.textContent === "string" ) {
nickjillings@1541 1514 return elem.textContent;
nickjillings@1541 1515 } else {
nickjillings@1541 1516 // Traverse its children
nickjillings@1541 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1541 1518 ret += getText( elem );
nickjillings@1541 1519 }
nickjillings@1541 1520 }
nickjillings@1541 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nickjillings@1541 1522 return elem.nodeValue;
nickjillings@1541 1523 }
nickjillings@1541 1524 // Do not include comment or processing instruction nodes
nickjillings@1541 1525
nickjillings@1541 1526 return ret;
nickjillings@1541 1527 };
nickjillings@1541 1528
nickjillings@1541 1529 Expr = Sizzle.selectors = {
nickjillings@1541 1530
nickjillings@1541 1531 // Can be adjusted by the user
nickjillings@1541 1532 cacheLength: 50,
nickjillings@1541 1533
nickjillings@1541 1534 createPseudo: markFunction,
nickjillings@1541 1535
nickjillings@1541 1536 match: matchExpr,
nickjillings@1541 1537
nickjillings@1541 1538 attrHandle: {},
nickjillings@1541 1539
nickjillings@1541 1540 find: {},
nickjillings@1541 1541
nickjillings@1541 1542 relative: {
nickjillings@1541 1543 ">": { dir: "parentNode", first: true },
nickjillings@1541 1544 " ": { dir: "parentNode" },
nickjillings@1541 1545 "+": { dir: "previousSibling", first: true },
nickjillings@1541 1546 "~": { dir: "previousSibling" }
nickjillings@1541 1547 },
nickjillings@1541 1548
nickjillings@1541 1549 preFilter: {
nickjillings@1541 1550 "ATTR": function( match ) {
nickjillings@1541 1551 match[1] = match[1].replace( runescape, funescape );
nickjillings@1541 1552
nickjillings@1541 1553 // Move the given value to match[3] whether quoted or unquoted
nickjillings@1541 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nickjillings@1541 1555
nickjillings@1541 1556 if ( match[2] === "~=" ) {
nickjillings@1541 1557 match[3] = " " + match[3] + " ";
nickjillings@1541 1558 }
nickjillings@1541 1559
nickjillings@1541 1560 return match.slice( 0, 4 );
nickjillings@1541 1561 },
nickjillings@1541 1562
nickjillings@1541 1563 "CHILD": function( match ) {
nickjillings@1541 1564 /* matches from matchExpr["CHILD"]
nickjillings@1541 1565 1 type (only|nth|...)
nickjillings@1541 1566 2 what (child|of-type)
nickjillings@1541 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nickjillings@1541 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nickjillings@1541 1569 5 sign of xn-component
nickjillings@1541 1570 6 x of xn-component
nickjillings@1541 1571 7 sign of y-component
nickjillings@1541 1572 8 y of y-component
nickjillings@1541 1573 */
nickjillings@1541 1574 match[1] = match[1].toLowerCase();
nickjillings@1541 1575
nickjillings@1541 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nickjillings@1541 1577 // nth-* requires argument
nickjillings@1541 1578 if ( !match[3] ) {
nickjillings@1541 1579 Sizzle.error( match[0] );
nickjillings@1541 1580 }
nickjillings@1541 1581
nickjillings@1541 1582 // numeric x and y parameters for Expr.filter.CHILD
nickjillings@1541 1583 // remember that false/true cast respectively to 0/1
nickjillings@1541 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nickjillings@1541 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nickjillings@1541 1586
nickjillings@1541 1587 // other types prohibit arguments
nickjillings@1541 1588 } else if ( match[3] ) {
nickjillings@1541 1589 Sizzle.error( match[0] );
nickjillings@1541 1590 }
nickjillings@1541 1591
nickjillings@1541 1592 return match;
nickjillings@1541 1593 },
nickjillings@1541 1594
nickjillings@1541 1595 "PSEUDO": function( match ) {
nickjillings@1541 1596 var excess,
nickjillings@1541 1597 unquoted = !match[6] && match[2];
nickjillings@1541 1598
nickjillings@1541 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nickjillings@1541 1600 return null;
nickjillings@1541 1601 }
nickjillings@1541 1602
nickjillings@1541 1603 // Accept quoted arguments as-is
nickjillings@1541 1604 if ( match[3] ) {
nickjillings@1541 1605 match[2] = match[4] || match[5] || "";
nickjillings@1541 1606
nickjillings@1541 1607 // Strip excess characters from unquoted arguments
nickjillings@1541 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nickjillings@1541 1609 // Get excess from tokenize (recursively)
nickjillings@1541 1610 (excess = tokenize( unquoted, true )) &&
nickjillings@1541 1611 // advance to the next closing parenthesis
nickjillings@1541 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nickjillings@1541 1613
nickjillings@1541 1614 // excess is a negative index
nickjillings@1541 1615 match[0] = match[0].slice( 0, excess );
nickjillings@1541 1616 match[2] = unquoted.slice( 0, excess );
nickjillings@1541 1617 }
nickjillings@1541 1618
nickjillings@1541 1619 // Return only captures needed by the pseudo filter method (type and argument)
nickjillings@1541 1620 return match.slice( 0, 3 );
nickjillings@1541 1621 }
nickjillings@1541 1622 },
nickjillings@1541 1623
nickjillings@1541 1624 filter: {
nickjillings@1541 1625
nickjillings@1541 1626 "TAG": function( nodeNameSelector ) {
nickjillings@1541 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nickjillings@1541 1628 return nodeNameSelector === "*" ?
nickjillings@1541 1629 function() { return true; } :
nickjillings@1541 1630 function( elem ) {
nickjillings@1541 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nickjillings@1541 1632 };
nickjillings@1541 1633 },
nickjillings@1541 1634
nickjillings@1541 1635 "CLASS": function( className ) {
nickjillings@1541 1636 var pattern = classCache[ className + " " ];
nickjillings@1541 1637
nickjillings@1541 1638 return pattern ||
nickjillings@1541 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nickjillings@1541 1640 classCache( className, function( elem ) {
nickjillings@1541 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nickjillings@1541 1642 });
nickjillings@1541 1643 },
nickjillings@1541 1644
nickjillings@1541 1645 "ATTR": function( name, operator, check ) {
nickjillings@1541 1646 return function( elem ) {
nickjillings@1541 1647 var result = Sizzle.attr( elem, name );
nickjillings@1541 1648
nickjillings@1541 1649 if ( result == null ) {
nickjillings@1541 1650 return operator === "!=";
nickjillings@1541 1651 }
nickjillings@1541 1652 if ( !operator ) {
nickjillings@1541 1653 return true;
nickjillings@1541 1654 }
nickjillings@1541 1655
nickjillings@1541 1656 result += "";
nickjillings@1541 1657
nickjillings@1541 1658 return operator === "=" ? result === check :
nickjillings@1541 1659 operator === "!=" ? result !== check :
nickjillings@1541 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nickjillings@1541 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nickjillings@1541 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nickjillings@1541 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nickjillings@1541 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nickjillings@1541 1665 false;
nickjillings@1541 1666 };
nickjillings@1541 1667 },
nickjillings@1541 1668
nickjillings@1541 1669 "CHILD": function( type, what, argument, first, last ) {
nickjillings@1541 1670 var simple = type.slice( 0, 3 ) !== "nth",
nickjillings@1541 1671 forward = type.slice( -4 ) !== "last",
nickjillings@1541 1672 ofType = what === "of-type";
nickjillings@1541 1673
nickjillings@1541 1674 return first === 1 && last === 0 ?
nickjillings@1541 1675
nickjillings@1541 1676 // Shortcut for :nth-*(n)
nickjillings@1541 1677 function( elem ) {
nickjillings@1541 1678 return !!elem.parentNode;
nickjillings@1541 1679 } :
nickjillings@1541 1680
nickjillings@1541 1681 function( elem, context, xml ) {
nickjillings@1541 1682 var cache, outerCache, node, diff, nodeIndex, start,
nickjillings@1541 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nickjillings@1541 1684 parent = elem.parentNode,
nickjillings@1541 1685 name = ofType && elem.nodeName.toLowerCase(),
nickjillings@1541 1686 useCache = !xml && !ofType;
nickjillings@1541 1687
nickjillings@1541 1688 if ( parent ) {
nickjillings@1541 1689
nickjillings@1541 1690 // :(first|last|only)-(child|of-type)
nickjillings@1541 1691 if ( simple ) {
nickjillings@1541 1692 while ( dir ) {
nickjillings@1541 1693 node = elem;
nickjillings@1541 1694 while ( (node = node[ dir ]) ) {
nickjillings@1541 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nickjillings@1541 1696 return false;
nickjillings@1541 1697 }
nickjillings@1541 1698 }
nickjillings@1541 1699 // Reverse direction for :only-* (if we haven't yet done so)
nickjillings@1541 1700 start = dir = type === "only" && !start && "nextSibling";
nickjillings@1541 1701 }
nickjillings@1541 1702 return true;
nickjillings@1541 1703 }
nickjillings@1541 1704
nickjillings@1541 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nickjillings@1541 1706
nickjillings@1541 1707 // non-xml :nth-child(...) stores cache data on `parent`
nickjillings@1541 1708 if ( forward && useCache ) {
nickjillings@1541 1709 // Seek `elem` from a previously-cached index
nickjillings@1541 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nickjillings@1541 1711 cache = outerCache[ type ] || [];
nickjillings@1541 1712 nodeIndex = cache[0] === dirruns && cache[1];
nickjillings@1541 1713 diff = cache[0] === dirruns && cache[2];
nickjillings@1541 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nickjillings@1541 1715
nickjillings@1541 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1541 1717
nickjillings@1541 1718 // Fallback to seeking `elem` from the start
nickjillings@1541 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1541 1720
nickjillings@1541 1721 // When found, cache indexes on `parent` and break
nickjillings@1541 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nickjillings@1541 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nickjillings@1541 1724 break;
nickjillings@1541 1725 }
nickjillings@1541 1726 }
nickjillings@1541 1727
nickjillings@1541 1728 // Use previously-cached element index if available
nickjillings@1541 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nickjillings@1541 1730 diff = cache[1];
nickjillings@1541 1731
nickjillings@1541 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nickjillings@1541 1733 } else {
nickjillings@1541 1734 // Use the same loop as above to seek `elem` from the start
nickjillings@1541 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1541 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1541 1737
nickjillings@1541 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nickjillings@1541 1739 // Cache the index of each encountered element
nickjillings@1541 1740 if ( useCache ) {
nickjillings@1541 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nickjillings@1541 1742 }
nickjillings@1541 1743
nickjillings@1541 1744 if ( node === elem ) {
nickjillings@1541 1745 break;
nickjillings@1541 1746 }
nickjillings@1541 1747 }
nickjillings@1541 1748 }
nickjillings@1541 1749 }
nickjillings@1541 1750
nickjillings@1541 1751 // Incorporate the offset, then check against cycle size
nickjillings@1541 1752 diff -= last;
nickjillings@1541 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nickjillings@1541 1754 }
nickjillings@1541 1755 };
nickjillings@1541 1756 },
nickjillings@1541 1757
nickjillings@1541 1758 "PSEUDO": function( pseudo, argument ) {
nickjillings@1541 1759 // pseudo-class names are case-insensitive
nickjillings@1541 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nickjillings@1541 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nickjillings@1541 1762 // Remember that setFilters inherits from pseudos
nickjillings@1541 1763 var args,
nickjillings@1541 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nickjillings@1541 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nickjillings@1541 1766
nickjillings@1541 1767 // The user may use createPseudo to indicate that
nickjillings@1541 1768 // arguments are needed to create the filter function
nickjillings@1541 1769 // just as Sizzle does
nickjillings@1541 1770 if ( fn[ expando ] ) {
nickjillings@1541 1771 return fn( argument );
nickjillings@1541 1772 }
nickjillings@1541 1773
nickjillings@1541 1774 // But maintain support for old signatures
nickjillings@1541 1775 if ( fn.length > 1 ) {
nickjillings@1541 1776 args = [ pseudo, pseudo, "", argument ];
nickjillings@1541 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nickjillings@1541 1778 markFunction(function( seed, matches ) {
nickjillings@1541 1779 var idx,
nickjillings@1541 1780 matched = fn( seed, argument ),
nickjillings@1541 1781 i = matched.length;
nickjillings@1541 1782 while ( i-- ) {
nickjillings@1541 1783 idx = indexOf( seed, matched[i] );
nickjillings@1541 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nickjillings@1541 1785 }
nickjillings@1541 1786 }) :
nickjillings@1541 1787 function( elem ) {
nickjillings@1541 1788 return fn( elem, 0, args );
nickjillings@1541 1789 };
nickjillings@1541 1790 }
nickjillings@1541 1791
nickjillings@1541 1792 return fn;
nickjillings@1541 1793 }
nickjillings@1541 1794 },
nickjillings@1541 1795
nickjillings@1541 1796 pseudos: {
nickjillings@1541 1797 // Potentially complex pseudos
nickjillings@1541 1798 "not": markFunction(function( selector ) {
nickjillings@1541 1799 // Trim the selector passed to compile
nickjillings@1541 1800 // to avoid treating leading and trailing
nickjillings@1541 1801 // spaces as combinators
nickjillings@1541 1802 var input = [],
nickjillings@1541 1803 results = [],
nickjillings@1541 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nickjillings@1541 1805
nickjillings@1541 1806 return matcher[ expando ] ?
nickjillings@1541 1807 markFunction(function( seed, matches, context, xml ) {
nickjillings@1541 1808 var elem,
nickjillings@1541 1809 unmatched = matcher( seed, null, xml, [] ),
nickjillings@1541 1810 i = seed.length;
nickjillings@1541 1811
nickjillings@1541 1812 // Match elements unmatched by `matcher`
nickjillings@1541 1813 while ( i-- ) {
nickjillings@1541 1814 if ( (elem = unmatched[i]) ) {
nickjillings@1541 1815 seed[i] = !(matches[i] = elem);
nickjillings@1541 1816 }
nickjillings@1541 1817 }
nickjillings@1541 1818 }) :
nickjillings@1541 1819 function( elem, context, xml ) {
nickjillings@1541 1820 input[0] = elem;
nickjillings@1541 1821 matcher( input, null, xml, results );
nickjillings@1541 1822 // Don't keep the element (issue #299)
nickjillings@1541 1823 input[0] = null;
nickjillings@1541 1824 return !results.pop();
nickjillings@1541 1825 };
nickjillings@1541 1826 }),
nickjillings@1541 1827
nickjillings@1541 1828 "has": markFunction(function( selector ) {
nickjillings@1541 1829 return function( elem ) {
nickjillings@1541 1830 return Sizzle( selector, elem ).length > 0;
nickjillings@1541 1831 };
nickjillings@1541 1832 }),
nickjillings@1541 1833
nickjillings@1541 1834 "contains": markFunction(function( text ) {
nickjillings@1541 1835 text = text.replace( runescape, funescape );
nickjillings@1541 1836 return function( elem ) {
nickjillings@1541 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nickjillings@1541 1838 };
nickjillings@1541 1839 }),
nickjillings@1541 1840
nickjillings@1541 1841 // "Whether an element is represented by a :lang() selector
nickjillings@1541 1842 // is based solely on the element's language value
nickjillings@1541 1843 // being equal to the identifier C,
nickjillings@1541 1844 // or beginning with the identifier C immediately followed by "-".
nickjillings@1541 1845 // The matching of C against the element's language value is performed case-insensitively.
nickjillings@1541 1846 // The identifier C does not have to be a valid language name."
nickjillings@1541 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nickjillings@1541 1848 "lang": markFunction( function( lang ) {
nickjillings@1541 1849 // lang value must be a valid identifier
nickjillings@1541 1850 if ( !ridentifier.test(lang || "") ) {
nickjillings@1541 1851 Sizzle.error( "unsupported lang: " + lang );
nickjillings@1541 1852 }
nickjillings@1541 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nickjillings@1541 1854 return function( elem ) {
nickjillings@1541 1855 var elemLang;
nickjillings@1541 1856 do {
nickjillings@1541 1857 if ( (elemLang = documentIsHTML ?
nickjillings@1541 1858 elem.lang :
nickjillings@1541 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nickjillings@1541 1860
nickjillings@1541 1861 elemLang = elemLang.toLowerCase();
nickjillings@1541 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nickjillings@1541 1863 }
nickjillings@1541 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nickjillings@1541 1865 return false;
nickjillings@1541 1866 };
nickjillings@1541 1867 }),
nickjillings@1541 1868
nickjillings@1541 1869 // Miscellaneous
nickjillings@1541 1870 "target": function( elem ) {
nickjillings@1541 1871 var hash = window.location && window.location.hash;
nickjillings@1541 1872 return hash && hash.slice( 1 ) === elem.id;
nickjillings@1541 1873 },
nickjillings@1541 1874
nickjillings@1541 1875 "root": function( elem ) {
nickjillings@1541 1876 return elem === docElem;
nickjillings@1541 1877 },
nickjillings@1541 1878
nickjillings@1541 1879 "focus": function( elem ) {
nickjillings@1541 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nickjillings@1541 1881 },
nickjillings@1541 1882
nickjillings@1541 1883 // Boolean properties
nickjillings@1541 1884 "enabled": function( elem ) {
nickjillings@1541 1885 return elem.disabled === false;
nickjillings@1541 1886 },
nickjillings@1541 1887
nickjillings@1541 1888 "disabled": function( elem ) {
nickjillings@1541 1889 return elem.disabled === true;
nickjillings@1541 1890 },
nickjillings@1541 1891
nickjillings@1541 1892 "checked": function( elem ) {
nickjillings@1541 1893 // In CSS3, :checked should return both checked and selected elements
nickjillings@1541 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1541 1895 var nodeName = elem.nodeName.toLowerCase();
nickjillings@1541 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nickjillings@1541 1897 },
nickjillings@1541 1898
nickjillings@1541 1899 "selected": function( elem ) {
nickjillings@1541 1900 // Accessing this property makes selected-by-default
nickjillings@1541 1901 // options in Safari work properly
nickjillings@1541 1902 if ( elem.parentNode ) {
nickjillings@1541 1903 elem.parentNode.selectedIndex;
nickjillings@1541 1904 }
nickjillings@1541 1905
nickjillings@1541 1906 return elem.selected === true;
nickjillings@1541 1907 },
nickjillings@1541 1908
nickjillings@1541 1909 // Contents
nickjillings@1541 1910 "empty": function( elem ) {
nickjillings@1541 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nickjillings@1541 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nickjillings@1541 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nickjillings@1541 1914 // nodeType < 6 works because attributes (2) do not appear as children
nickjillings@1541 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1541 1916 if ( elem.nodeType < 6 ) {
nickjillings@1541 1917 return false;
nickjillings@1541 1918 }
nickjillings@1541 1919 }
nickjillings@1541 1920 return true;
nickjillings@1541 1921 },
nickjillings@1541 1922
nickjillings@1541 1923 "parent": function( elem ) {
nickjillings@1541 1924 return !Expr.pseudos["empty"]( elem );
nickjillings@1541 1925 },
nickjillings@1541 1926
nickjillings@1541 1927 // Element/input types
nickjillings@1541 1928 "header": function( elem ) {
nickjillings@1541 1929 return rheader.test( elem.nodeName );
nickjillings@1541 1930 },
nickjillings@1541 1931
nickjillings@1541 1932 "input": function( elem ) {
nickjillings@1541 1933 return rinputs.test( elem.nodeName );
nickjillings@1541 1934 },
nickjillings@1541 1935
nickjillings@1541 1936 "button": function( elem ) {
nickjillings@1541 1937 var name = elem.nodeName.toLowerCase();
nickjillings@1541 1938 return name === "input" && elem.type === "button" || name === "button";
nickjillings@1541 1939 },
nickjillings@1541 1940
nickjillings@1541 1941 "text": function( elem ) {
nickjillings@1541 1942 var attr;
nickjillings@1541 1943 return elem.nodeName.toLowerCase() === "input" &&
nickjillings@1541 1944 elem.type === "text" &&
nickjillings@1541 1945
nickjillings@1541 1946 // Support: IE<8
nickjillings@1541 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nickjillings@1541 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nickjillings@1541 1949 },
nickjillings@1541 1950
nickjillings@1541 1951 // Position-in-collection
nickjillings@1541 1952 "first": createPositionalPseudo(function() {
nickjillings@1541 1953 return [ 0 ];
nickjillings@1541 1954 }),
nickjillings@1541 1955
nickjillings@1541 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1541 1957 return [ length - 1 ];
nickjillings@1541 1958 }),
nickjillings@1541 1959
nickjillings@1541 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1541 1961 return [ argument < 0 ? argument + length : argument ];
nickjillings@1541 1962 }),
nickjillings@1541 1963
nickjillings@1541 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1541 1965 var i = 0;
nickjillings@1541 1966 for ( ; i < length; i += 2 ) {
nickjillings@1541 1967 matchIndexes.push( i );
nickjillings@1541 1968 }
nickjillings@1541 1969 return matchIndexes;
nickjillings@1541 1970 }),
nickjillings@1541 1971
nickjillings@1541 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1541 1973 var i = 1;
nickjillings@1541 1974 for ( ; i < length; i += 2 ) {
nickjillings@1541 1975 matchIndexes.push( i );
nickjillings@1541 1976 }
nickjillings@1541 1977 return matchIndexes;
nickjillings@1541 1978 }),
nickjillings@1541 1979
nickjillings@1541 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1541 1981 var i = argument < 0 ? argument + length : argument;
nickjillings@1541 1982 for ( ; --i >= 0; ) {
nickjillings@1541 1983 matchIndexes.push( i );
nickjillings@1541 1984 }
nickjillings@1541 1985 return matchIndexes;
nickjillings@1541 1986 }),
nickjillings@1541 1987
nickjillings@1541 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1541 1989 var i = argument < 0 ? argument + length : argument;
nickjillings@1541 1990 for ( ; ++i < length; ) {
nickjillings@1541 1991 matchIndexes.push( i );
nickjillings@1541 1992 }
nickjillings@1541 1993 return matchIndexes;
nickjillings@1541 1994 })
nickjillings@1541 1995 }
nickjillings@1541 1996 };
nickjillings@1541 1997
nickjillings@1541 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nickjillings@1541 1999
nickjillings@1541 2000 // Add button/input type pseudos
nickjillings@1541 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nickjillings@1541 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nickjillings@1541 2003 }
nickjillings@1541 2004 for ( i in { submit: true, reset: true } ) {
nickjillings@1541 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nickjillings@1541 2006 }
nickjillings@1541 2007
nickjillings@1541 2008 // Easy API for creating new setFilters
nickjillings@1541 2009 function setFilters() {}
nickjillings@1541 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nickjillings@1541 2011 Expr.setFilters = new setFilters();
nickjillings@1541 2012
nickjillings@1541 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nickjillings@1541 2014 var matched, match, tokens, type,
nickjillings@1541 2015 soFar, groups, preFilters,
nickjillings@1541 2016 cached = tokenCache[ selector + " " ];
nickjillings@1541 2017
nickjillings@1541 2018 if ( cached ) {
nickjillings@1541 2019 return parseOnly ? 0 : cached.slice( 0 );
nickjillings@1541 2020 }
nickjillings@1541 2021
nickjillings@1541 2022 soFar = selector;
nickjillings@1541 2023 groups = [];
nickjillings@1541 2024 preFilters = Expr.preFilter;
nickjillings@1541 2025
nickjillings@1541 2026 while ( soFar ) {
nickjillings@1541 2027
nickjillings@1541 2028 // Comma and first run
nickjillings@1541 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nickjillings@1541 2030 if ( match ) {
nickjillings@1541 2031 // Don't consume trailing commas as valid
nickjillings@1541 2032 soFar = soFar.slice( match[0].length ) || soFar;
nickjillings@1541 2033 }
nickjillings@1541 2034 groups.push( (tokens = []) );
nickjillings@1541 2035 }
nickjillings@1541 2036
nickjillings@1541 2037 matched = false;
nickjillings@1541 2038
nickjillings@1541 2039 // Combinators
nickjillings@1541 2040 if ( (match = rcombinators.exec( soFar )) ) {
nickjillings@1541 2041 matched = match.shift();
nickjillings@1541 2042 tokens.push({
nickjillings@1541 2043 value: matched,
nickjillings@1541 2044 // Cast descendant combinators to space
nickjillings@1541 2045 type: match[0].replace( rtrim, " " )
nickjillings@1541 2046 });
nickjillings@1541 2047 soFar = soFar.slice( matched.length );
nickjillings@1541 2048 }
nickjillings@1541 2049
nickjillings@1541 2050 // Filters
nickjillings@1541 2051 for ( type in Expr.filter ) {
nickjillings@1541 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nickjillings@1541 2053 (match = preFilters[ type ]( match ))) ) {
nickjillings@1541 2054 matched = match.shift();
nickjillings@1541 2055 tokens.push({
nickjillings@1541 2056 value: matched,
nickjillings@1541 2057 type: type,
nickjillings@1541 2058 matches: match
nickjillings@1541 2059 });
nickjillings@1541 2060 soFar = soFar.slice( matched.length );
nickjillings@1541 2061 }
nickjillings@1541 2062 }
nickjillings@1541 2063
nickjillings@1541 2064 if ( !matched ) {
nickjillings@1541 2065 break;
nickjillings@1541 2066 }
nickjillings@1541 2067 }
nickjillings@1541 2068
nickjillings@1541 2069 // Return the length of the invalid excess
nickjillings@1541 2070 // if we're just parsing
nickjillings@1541 2071 // Otherwise, throw an error or return tokens
nickjillings@1541 2072 return parseOnly ?
nickjillings@1541 2073 soFar.length :
nickjillings@1541 2074 soFar ?
nickjillings@1541 2075 Sizzle.error( selector ) :
nickjillings@1541 2076 // Cache the tokens
nickjillings@1541 2077 tokenCache( selector, groups ).slice( 0 );
nickjillings@1541 2078 };
nickjillings@1541 2079
nickjillings@1541 2080 function toSelector( tokens ) {
nickjillings@1541 2081 var i = 0,
nickjillings@1541 2082 len = tokens.length,
nickjillings@1541 2083 selector = "";
nickjillings@1541 2084 for ( ; i < len; i++ ) {
nickjillings@1541 2085 selector += tokens[i].value;
nickjillings@1541 2086 }
nickjillings@1541 2087 return selector;
nickjillings@1541 2088 }
nickjillings@1541 2089
nickjillings@1541 2090 function addCombinator( matcher, combinator, base ) {
nickjillings@1541 2091 var dir = combinator.dir,
nickjillings@1541 2092 checkNonElements = base && dir === "parentNode",
nickjillings@1541 2093 doneName = done++;
nickjillings@1541 2094
nickjillings@1541 2095 return combinator.first ?
nickjillings@1541 2096 // Check against closest ancestor/preceding element
nickjillings@1541 2097 function( elem, context, xml ) {
nickjillings@1541 2098 while ( (elem = elem[ dir ]) ) {
nickjillings@1541 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1541 2100 return matcher( elem, context, xml );
nickjillings@1541 2101 }
nickjillings@1541 2102 }
nickjillings@1541 2103 } :
nickjillings@1541 2104
nickjillings@1541 2105 // Check against all ancestor/preceding elements
nickjillings@1541 2106 function( elem, context, xml ) {
nickjillings@1541 2107 var oldCache, outerCache,
nickjillings@1541 2108 newCache = [ dirruns, doneName ];
nickjillings@1541 2109
nickjillings@1541 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nickjillings@1541 2111 if ( xml ) {
nickjillings@1541 2112 while ( (elem = elem[ dir ]) ) {
nickjillings@1541 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1541 2114 if ( matcher( elem, context, xml ) ) {
nickjillings@1541 2115 return true;
nickjillings@1541 2116 }
nickjillings@1541 2117 }
nickjillings@1541 2118 }
nickjillings@1541 2119 } else {
nickjillings@1541 2120 while ( (elem = elem[ dir ]) ) {
nickjillings@1541 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1541 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nickjillings@1541 2123 if ( (oldCache = outerCache[ dir ]) &&
nickjillings@1541 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nickjillings@1541 2125
nickjillings@1541 2126 // Assign to newCache so results back-propagate to previous elements
nickjillings@1541 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nickjillings@1541 2128 } else {
nickjillings@1541 2129 // Reuse newcache so results back-propagate to previous elements
nickjillings@1541 2130 outerCache[ dir ] = newCache;
nickjillings@1541 2131
nickjillings@1541 2132 // A match means we're done; a fail means we have to keep checking
nickjillings@1541 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nickjillings@1541 2134 return true;
nickjillings@1541 2135 }
nickjillings@1541 2136 }
nickjillings@1541 2137 }
nickjillings@1541 2138 }
nickjillings@1541 2139 }
nickjillings@1541 2140 };
nickjillings@1541 2141 }
nickjillings@1541 2142
nickjillings@1541 2143 function elementMatcher( matchers ) {
nickjillings@1541 2144 return matchers.length > 1 ?
nickjillings@1541 2145 function( elem, context, xml ) {
nickjillings@1541 2146 var i = matchers.length;
nickjillings@1541 2147 while ( i-- ) {
nickjillings@1541 2148 if ( !matchers[i]( elem, context, xml ) ) {
nickjillings@1541 2149 return false;
nickjillings@1541 2150 }
nickjillings@1541 2151 }
nickjillings@1541 2152 return true;
nickjillings@1541 2153 } :
nickjillings@1541 2154 matchers[0];
nickjillings@1541 2155 }
nickjillings@1541 2156
nickjillings@1541 2157 function multipleContexts( selector, contexts, results ) {
nickjillings@1541 2158 var i = 0,
nickjillings@1541 2159 len = contexts.length;
nickjillings@1541 2160 for ( ; i < len; i++ ) {
nickjillings@1541 2161 Sizzle( selector, contexts[i], results );
nickjillings@1541 2162 }
nickjillings@1541 2163 return results;
nickjillings@1541 2164 }
nickjillings@1541 2165
nickjillings@1541 2166 function condense( unmatched, map, filter, context, xml ) {
nickjillings@1541 2167 var elem,
nickjillings@1541 2168 newUnmatched = [],
nickjillings@1541 2169 i = 0,
nickjillings@1541 2170 len = unmatched.length,
nickjillings@1541 2171 mapped = map != null;
nickjillings@1541 2172
nickjillings@1541 2173 for ( ; i < len; i++ ) {
nickjillings@1541 2174 if ( (elem = unmatched[i]) ) {
nickjillings@1541 2175 if ( !filter || filter( elem, context, xml ) ) {
nickjillings@1541 2176 newUnmatched.push( elem );
nickjillings@1541 2177 if ( mapped ) {
nickjillings@1541 2178 map.push( i );
nickjillings@1541 2179 }
nickjillings@1541 2180 }
nickjillings@1541 2181 }
nickjillings@1541 2182 }
nickjillings@1541 2183
nickjillings@1541 2184 return newUnmatched;
nickjillings@1541 2185 }
nickjillings@1541 2186
nickjillings@1541 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nickjillings@1541 2188 if ( postFilter && !postFilter[ expando ] ) {
nickjillings@1541 2189 postFilter = setMatcher( postFilter );
nickjillings@1541 2190 }
nickjillings@1541 2191 if ( postFinder && !postFinder[ expando ] ) {
nickjillings@1541 2192 postFinder = setMatcher( postFinder, postSelector );
nickjillings@1541 2193 }
nickjillings@1541 2194 return markFunction(function( seed, results, context, xml ) {
nickjillings@1541 2195 var temp, i, elem,
nickjillings@1541 2196 preMap = [],
nickjillings@1541 2197 postMap = [],
nickjillings@1541 2198 preexisting = results.length,
nickjillings@1541 2199
nickjillings@1541 2200 // Get initial elements from seed or context
nickjillings@1541 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nickjillings@1541 2202
nickjillings@1541 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nickjillings@1541 2204 matcherIn = preFilter && ( seed || !selector ) ?
nickjillings@1541 2205 condense( elems, preMap, preFilter, context, xml ) :
nickjillings@1541 2206 elems,
nickjillings@1541 2207
nickjillings@1541 2208 matcherOut = matcher ?
nickjillings@1541 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nickjillings@1541 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nickjillings@1541 2211
nickjillings@1541 2212 // ...intermediate processing is necessary
nickjillings@1541 2213 [] :
nickjillings@1541 2214
nickjillings@1541 2215 // ...otherwise use results directly
nickjillings@1541 2216 results :
nickjillings@1541 2217 matcherIn;
nickjillings@1541 2218
nickjillings@1541 2219 // Find primary matches
nickjillings@1541 2220 if ( matcher ) {
nickjillings@1541 2221 matcher( matcherIn, matcherOut, context, xml );
nickjillings@1541 2222 }
nickjillings@1541 2223
nickjillings@1541 2224 // Apply postFilter
nickjillings@1541 2225 if ( postFilter ) {
nickjillings@1541 2226 temp = condense( matcherOut, postMap );
nickjillings@1541 2227 postFilter( temp, [], context, xml );
nickjillings@1541 2228
nickjillings@1541 2229 // Un-match failing elements by moving them back to matcherIn
nickjillings@1541 2230 i = temp.length;
nickjillings@1541 2231 while ( i-- ) {
nickjillings@1541 2232 if ( (elem = temp[i]) ) {
nickjillings@1541 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nickjillings@1541 2234 }
nickjillings@1541 2235 }
nickjillings@1541 2236 }
nickjillings@1541 2237
nickjillings@1541 2238 if ( seed ) {
nickjillings@1541 2239 if ( postFinder || preFilter ) {
nickjillings@1541 2240 if ( postFinder ) {
nickjillings@1541 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nickjillings@1541 2242 temp = [];
nickjillings@1541 2243 i = matcherOut.length;
nickjillings@1541 2244 while ( i-- ) {
nickjillings@1541 2245 if ( (elem = matcherOut[i]) ) {
nickjillings@1541 2246 // Restore matcherIn since elem is not yet a final match
nickjillings@1541 2247 temp.push( (matcherIn[i] = elem) );
nickjillings@1541 2248 }
nickjillings@1541 2249 }
nickjillings@1541 2250 postFinder( null, (matcherOut = []), temp, xml );
nickjillings@1541 2251 }
nickjillings@1541 2252
nickjillings@1541 2253 // Move matched elements from seed to results to keep them synchronized
nickjillings@1541 2254 i = matcherOut.length;
nickjillings@1541 2255 while ( i-- ) {
nickjillings@1541 2256 if ( (elem = matcherOut[i]) &&
nickjillings@1541 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nickjillings@1541 2258
nickjillings@1541 2259 seed[temp] = !(results[temp] = elem);
nickjillings@1541 2260 }
nickjillings@1541 2261 }
nickjillings@1541 2262 }
nickjillings@1541 2263
nickjillings@1541 2264 // Add elements to results, through postFinder if defined
nickjillings@1541 2265 } else {
nickjillings@1541 2266 matcherOut = condense(
nickjillings@1541 2267 matcherOut === results ?
nickjillings@1541 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nickjillings@1541 2269 matcherOut
nickjillings@1541 2270 );
nickjillings@1541 2271 if ( postFinder ) {
nickjillings@1541 2272 postFinder( null, results, matcherOut, xml );
nickjillings@1541 2273 } else {
nickjillings@1541 2274 push.apply( results, matcherOut );
nickjillings@1541 2275 }
nickjillings@1541 2276 }
nickjillings@1541 2277 });
nickjillings@1541 2278 }
nickjillings@1541 2279
nickjillings@1541 2280 function matcherFromTokens( tokens ) {
nickjillings@1541 2281 var checkContext, matcher, j,
nickjillings@1541 2282 len = tokens.length,
nickjillings@1541 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nickjillings@1541 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nickjillings@1541 2285 i = leadingRelative ? 1 : 0,
nickjillings@1541 2286
nickjillings@1541 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nickjillings@1541 2288 matchContext = addCombinator( function( elem ) {
nickjillings@1541 2289 return elem === checkContext;
nickjillings@1541 2290 }, implicitRelative, true ),
nickjillings@1541 2291 matchAnyContext = addCombinator( function( elem ) {
nickjillings@1541 2292 return indexOf( checkContext, elem ) > -1;
nickjillings@1541 2293 }, implicitRelative, true ),
nickjillings@1541 2294 matchers = [ function( elem, context, xml ) {
nickjillings@1541 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nickjillings@1541 2296 (checkContext = context).nodeType ?
nickjillings@1541 2297 matchContext( elem, context, xml ) :
nickjillings@1541 2298 matchAnyContext( elem, context, xml ) );
nickjillings@1541 2299 // Avoid hanging onto element (issue #299)
nickjillings@1541 2300 checkContext = null;
nickjillings@1541 2301 return ret;
nickjillings@1541 2302 } ];
nickjillings@1541 2303
nickjillings@1541 2304 for ( ; i < len; i++ ) {
nickjillings@1541 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nickjillings@1541 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nickjillings@1541 2307 } else {
nickjillings@1541 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nickjillings@1541 2309
nickjillings@1541 2310 // Return special upon seeing a positional matcher
nickjillings@1541 2311 if ( matcher[ expando ] ) {
nickjillings@1541 2312 // Find the next relative operator (if any) for proper handling
nickjillings@1541 2313 j = ++i;
nickjillings@1541 2314 for ( ; j < len; j++ ) {
nickjillings@1541 2315 if ( Expr.relative[ tokens[j].type ] ) {
nickjillings@1541 2316 break;
nickjillings@1541 2317 }
nickjillings@1541 2318 }
nickjillings@1541 2319 return setMatcher(
nickjillings@1541 2320 i > 1 && elementMatcher( matchers ),
nickjillings@1541 2321 i > 1 && toSelector(
nickjillings@1541 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nickjillings@1541 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nickjillings@1541 2324 ).replace( rtrim, "$1" ),
nickjillings@1541 2325 matcher,
nickjillings@1541 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nickjillings@1541 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nickjillings@1541 2328 j < len && toSelector( tokens )
nickjillings@1541 2329 );
nickjillings@1541 2330 }
nickjillings@1541 2331 matchers.push( matcher );
nickjillings@1541 2332 }
nickjillings@1541 2333 }
nickjillings@1541 2334
nickjillings@1541 2335 return elementMatcher( matchers );
nickjillings@1541 2336 }
nickjillings@1541 2337
nickjillings@1541 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nickjillings@1541 2339 var bySet = setMatchers.length > 0,
nickjillings@1541 2340 byElement = elementMatchers.length > 0,
nickjillings@1541 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nickjillings@1541 2342 var elem, j, matcher,
nickjillings@1541 2343 matchedCount = 0,
nickjillings@1541 2344 i = "0",
nickjillings@1541 2345 unmatched = seed && [],
nickjillings@1541 2346 setMatched = [],
nickjillings@1541 2347 contextBackup = outermostContext,
nickjillings@1541 2348 // We must always have either seed elements or outermost context
nickjillings@1541 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nickjillings@1541 2350 // Use integer dirruns iff this is the outermost matcher
nickjillings@1541 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nickjillings@1541 2352 len = elems.length;
nickjillings@1541 2353
nickjillings@1541 2354 if ( outermost ) {
nickjillings@1541 2355 outermostContext = context !== document && context;
nickjillings@1541 2356 }
nickjillings@1541 2357
nickjillings@1541 2358 // Add elements passing elementMatchers directly to results
nickjillings@1541 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nickjillings@1541 2360 // Support: IE<9, Safari
nickjillings@1541 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nickjillings@1541 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nickjillings@1541 2363 if ( byElement && elem ) {
nickjillings@1541 2364 j = 0;
nickjillings@1541 2365 while ( (matcher = elementMatchers[j++]) ) {
nickjillings@1541 2366 if ( matcher( elem, context, xml ) ) {
nickjillings@1541 2367 results.push( elem );
nickjillings@1541 2368 break;
nickjillings@1541 2369 }
nickjillings@1541 2370 }
nickjillings@1541 2371 if ( outermost ) {
nickjillings@1541 2372 dirruns = dirrunsUnique;
nickjillings@1541 2373 }
nickjillings@1541 2374 }
nickjillings@1541 2375
nickjillings@1541 2376 // Track unmatched elements for set filters
nickjillings@1541 2377 if ( bySet ) {
nickjillings@1541 2378 // They will have gone through all possible matchers
nickjillings@1541 2379 if ( (elem = !matcher && elem) ) {
nickjillings@1541 2380 matchedCount--;
nickjillings@1541 2381 }
nickjillings@1541 2382
nickjillings@1541 2383 // Lengthen the array for every element, matched or not
nickjillings@1541 2384 if ( seed ) {
nickjillings@1541 2385 unmatched.push( elem );
nickjillings@1541 2386 }
nickjillings@1541 2387 }
nickjillings@1541 2388 }
nickjillings@1541 2389
nickjillings@1541 2390 // Apply set filters to unmatched elements
nickjillings@1541 2391 matchedCount += i;
nickjillings@1541 2392 if ( bySet && i !== matchedCount ) {
nickjillings@1541 2393 j = 0;
nickjillings@1541 2394 while ( (matcher = setMatchers[j++]) ) {
nickjillings@1541 2395 matcher( unmatched, setMatched, context, xml );
nickjillings@1541 2396 }
nickjillings@1541 2397
nickjillings@1541 2398 if ( seed ) {
nickjillings@1541 2399 // Reintegrate element matches to eliminate the need for sorting
nickjillings@1541 2400 if ( matchedCount > 0 ) {
nickjillings@1541 2401 while ( i-- ) {
nickjillings@1541 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nickjillings@1541 2403 setMatched[i] = pop.call( results );
nickjillings@1541 2404 }
nickjillings@1541 2405 }
nickjillings@1541 2406 }
nickjillings@1541 2407
nickjillings@1541 2408 // Discard index placeholder values to get only actual matches
nickjillings@1541 2409 setMatched = condense( setMatched );
nickjillings@1541 2410 }
nickjillings@1541 2411
nickjillings@1541 2412 // Add matches to results
nickjillings@1541 2413 push.apply( results, setMatched );
nickjillings@1541 2414
nickjillings@1541 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nickjillings@1541 2416 if ( outermost && !seed && setMatched.length > 0 &&
nickjillings@1541 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nickjillings@1541 2418
nickjillings@1541 2419 Sizzle.uniqueSort( results );
nickjillings@1541 2420 }
nickjillings@1541 2421 }
nickjillings@1541 2422
nickjillings@1541 2423 // Override manipulation of globals by nested matchers
nickjillings@1541 2424 if ( outermost ) {
nickjillings@1541 2425 dirruns = dirrunsUnique;
nickjillings@1541 2426 outermostContext = contextBackup;
nickjillings@1541 2427 }
nickjillings@1541 2428
nickjillings@1541 2429 return unmatched;
nickjillings@1541 2430 };
nickjillings@1541 2431
nickjillings@1541 2432 return bySet ?
nickjillings@1541 2433 markFunction( superMatcher ) :
nickjillings@1541 2434 superMatcher;
nickjillings@1541 2435 }
nickjillings@1541 2436
nickjillings@1541 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nickjillings@1541 2438 var i,
nickjillings@1541 2439 setMatchers = [],
nickjillings@1541 2440 elementMatchers = [],
nickjillings@1541 2441 cached = compilerCache[ selector + " " ];
nickjillings@1541 2442
nickjillings@1541 2443 if ( !cached ) {
nickjillings@1541 2444 // Generate a function of recursive functions that can be used to check each element
nickjillings@1541 2445 if ( !match ) {
nickjillings@1541 2446 match = tokenize( selector );
nickjillings@1541 2447 }
nickjillings@1541 2448 i = match.length;
nickjillings@1541 2449 while ( i-- ) {
nickjillings@1541 2450 cached = matcherFromTokens( match[i] );
nickjillings@1541 2451 if ( cached[ expando ] ) {
nickjillings@1541 2452 setMatchers.push( cached );
nickjillings@1541 2453 } else {
nickjillings@1541 2454 elementMatchers.push( cached );
nickjillings@1541 2455 }
nickjillings@1541 2456 }
nickjillings@1541 2457
nickjillings@1541 2458 // Cache the compiled function
nickjillings@1541 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nickjillings@1541 2460
nickjillings@1541 2461 // Save selector and tokenization
nickjillings@1541 2462 cached.selector = selector;
nickjillings@1541 2463 }
nickjillings@1541 2464 return cached;
nickjillings@1541 2465 };
nickjillings@1541 2466
nickjillings@1541 2467 /**
nickjillings@1541 2468 * A low-level selection function that works with Sizzle's compiled
nickjillings@1541 2469 * selector functions
nickjillings@1541 2470 * @param {String|Function} selector A selector or a pre-compiled
nickjillings@1541 2471 * selector function built with Sizzle.compile
nickjillings@1541 2472 * @param {Element} context
nickjillings@1541 2473 * @param {Array} [results]
nickjillings@1541 2474 * @param {Array} [seed] A set of elements to match against
nickjillings@1541 2475 */
nickjillings@1541 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nickjillings@1541 2477 var i, tokens, token, type, find,
nickjillings@1541 2478 compiled = typeof selector === "function" && selector,
nickjillings@1541 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nickjillings@1541 2480
nickjillings@1541 2481 results = results || [];
nickjillings@1541 2482
nickjillings@1541 2483 // Try to minimize operations if there is no seed and only one group
nickjillings@1541 2484 if ( match.length === 1 ) {
nickjillings@1541 2485
nickjillings@1541 2486 // Take a shortcut and set the context if the root selector is an ID
nickjillings@1541 2487 tokens = match[0] = match[0].slice( 0 );
nickjillings@1541 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nickjillings@1541 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nickjillings@1541 2490 Expr.relative[ tokens[1].type ] ) {
nickjillings@1541 2491
nickjillings@1541 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nickjillings@1541 2493 if ( !context ) {
nickjillings@1541 2494 return results;
nickjillings@1541 2495
nickjillings@1541 2496 // Precompiled matchers will still verify ancestry, so step up a level
nickjillings@1541 2497 } else if ( compiled ) {
nickjillings@1541 2498 context = context.parentNode;
nickjillings@1541 2499 }
nickjillings@1541 2500
nickjillings@1541 2501 selector = selector.slice( tokens.shift().value.length );
nickjillings@1541 2502 }
nickjillings@1541 2503
nickjillings@1541 2504 // Fetch a seed set for right-to-left matching
nickjillings@1541 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nickjillings@1541 2506 while ( i-- ) {
nickjillings@1541 2507 token = tokens[i];
nickjillings@1541 2508
nickjillings@1541 2509 // Abort if we hit a combinator
nickjillings@1541 2510 if ( Expr.relative[ (type = token.type) ] ) {
nickjillings@1541 2511 break;
nickjillings@1541 2512 }
nickjillings@1541 2513 if ( (find = Expr.find[ type ]) ) {
nickjillings@1541 2514 // Search, expanding context for leading sibling combinators
nickjillings@1541 2515 if ( (seed = find(
nickjillings@1541 2516 token.matches[0].replace( runescape, funescape ),
nickjillings@1541 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nickjillings@1541 2518 )) ) {
nickjillings@1541 2519
nickjillings@1541 2520 // If seed is empty or no tokens remain, we can return early
nickjillings@1541 2521 tokens.splice( i, 1 );
nickjillings@1541 2522 selector = seed.length && toSelector( tokens );
nickjillings@1541 2523 if ( !selector ) {
nickjillings@1541 2524 push.apply( results, seed );
nickjillings@1541 2525 return results;
nickjillings@1541 2526 }
nickjillings@1541 2527
nickjillings@1541 2528 break;
nickjillings@1541 2529 }
nickjillings@1541 2530 }
nickjillings@1541 2531 }
nickjillings@1541 2532 }
nickjillings@1541 2533
nickjillings@1541 2534 // Compile and execute a filtering function if one is not provided
nickjillings@1541 2535 // Provide `match` to avoid retokenization if we modified the selector above
nickjillings@1541 2536 ( compiled || compile( selector, match ) )(
nickjillings@1541 2537 seed,
nickjillings@1541 2538 context,
nickjillings@1541 2539 !documentIsHTML,
nickjillings@1541 2540 results,
nickjillings@1541 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nickjillings@1541 2542 );
nickjillings@1541 2543 return results;
nickjillings@1541 2544 };
nickjillings@1541 2545
nickjillings@1541 2546 // One-time assignments
nickjillings@1541 2547
nickjillings@1541 2548 // Sort stability
nickjillings@1541 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nickjillings@1541 2550
nickjillings@1541 2551 // Support: Chrome 14-35+
nickjillings@1541 2552 // Always assume duplicates if they aren't passed to the comparison function
nickjillings@1541 2553 support.detectDuplicates = !!hasDuplicate;
nickjillings@1541 2554
nickjillings@1541 2555 // Initialize against the default document
nickjillings@1541 2556 setDocument();
nickjillings@1541 2557
nickjillings@1541 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nickjillings@1541 2559 // Detached nodes confoundingly follow *each other*
nickjillings@1541 2560 support.sortDetached = assert(function( div1 ) {
nickjillings@1541 2561 // Should return 1, but returns 4 (following)
nickjillings@1541 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nickjillings@1541 2563 });
nickjillings@1541 2564
nickjillings@1541 2565 // Support: IE<8
nickjillings@1541 2566 // Prevent attribute/property "interpolation"
nickjillings@1541 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nickjillings@1541 2568 if ( !assert(function( div ) {
nickjillings@1541 2569 div.innerHTML = "<a href='#'></a>";
nickjillings@1541 2570 return div.firstChild.getAttribute("href") === "#" ;
nickjillings@1541 2571 }) ) {
nickjillings@1541 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nickjillings@1541 2573 if ( !isXML ) {
nickjillings@1541 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nickjillings@1541 2575 }
nickjillings@1541 2576 });
nickjillings@1541 2577 }
nickjillings@1541 2578
nickjillings@1541 2579 // Support: IE<9
nickjillings@1541 2580 // Use defaultValue in place of getAttribute("value")
nickjillings@1541 2581 if ( !support.attributes || !assert(function( div ) {
nickjillings@1541 2582 div.innerHTML = "<input/>";
nickjillings@1541 2583 div.firstChild.setAttribute( "value", "" );
nickjillings@1541 2584 return div.firstChild.getAttribute( "value" ) === "";
nickjillings@1541 2585 }) ) {
nickjillings@1541 2586 addHandle( "value", function( elem, name, isXML ) {
nickjillings@1541 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nickjillings@1541 2588 return elem.defaultValue;
nickjillings@1541 2589 }
nickjillings@1541 2590 });
nickjillings@1541 2591 }
nickjillings@1541 2592
nickjillings@1541 2593 // Support: IE<9
nickjillings@1541 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nickjillings@1541 2595 if ( !assert(function( div ) {
nickjillings@1541 2596 return div.getAttribute("disabled") == null;
nickjillings@1541 2597 }) ) {
nickjillings@1541 2598 addHandle( booleans, function( elem, name, isXML ) {
nickjillings@1541 2599 var val;
nickjillings@1541 2600 if ( !isXML ) {
nickjillings@1541 2601 return elem[ name ] === true ? name.toLowerCase() :
nickjillings@1541 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nickjillings@1541 2603 val.value :
nickjillings@1541 2604 null;
nickjillings@1541 2605 }
nickjillings@1541 2606 });
nickjillings@1541 2607 }
nickjillings@1541 2608
nickjillings@1541 2609 return Sizzle;
nickjillings@1541 2610
nickjillings@1541 2611 })( window );
nickjillings@1541 2612
nickjillings@1541 2613
nickjillings@1541 2614
nickjillings@1541 2615 jQuery.find = Sizzle;
nickjillings@1541 2616 jQuery.expr = Sizzle.selectors;
nickjillings@1541 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nickjillings@1541 2618 jQuery.unique = Sizzle.uniqueSort;
nickjillings@1541 2619 jQuery.text = Sizzle.getText;
nickjillings@1541 2620 jQuery.isXMLDoc = Sizzle.isXML;
nickjillings@1541 2621 jQuery.contains = Sizzle.contains;
nickjillings@1541 2622
nickjillings@1541 2623
nickjillings@1541 2624
nickjillings@1541 2625 var rneedsContext = jQuery.expr.match.needsContext;
nickjillings@1541 2626
nickjillings@1541 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nickjillings@1541 2628
nickjillings@1541 2629
nickjillings@1541 2630
nickjillings@1541 2631 var risSimple = /^.[^:#\[\.,]*$/;
nickjillings@1541 2632
nickjillings@1541 2633 // Implement the identical functionality for filter and not
nickjillings@1541 2634 function winnow( elements, qualifier, not ) {
nickjillings@1541 2635 if ( jQuery.isFunction( qualifier ) ) {
nickjillings@1541 2636 return jQuery.grep( elements, function( elem, i ) {
nickjillings@1541 2637 /* jshint -W018 */
nickjillings@1541 2638 return !!qualifier.call( elem, i, elem ) !== not;
nickjillings@1541 2639 });
nickjillings@1541 2640
nickjillings@1541 2641 }
nickjillings@1541 2642
nickjillings@1541 2643 if ( qualifier.nodeType ) {
nickjillings@1541 2644 return jQuery.grep( elements, function( elem ) {
nickjillings@1541 2645 return ( elem === qualifier ) !== not;
nickjillings@1541 2646 });
nickjillings@1541 2647
nickjillings@1541 2648 }
nickjillings@1541 2649
nickjillings@1541 2650 if ( typeof qualifier === "string" ) {
nickjillings@1541 2651 if ( risSimple.test( qualifier ) ) {
nickjillings@1541 2652 return jQuery.filter( qualifier, elements, not );
nickjillings@1541 2653 }
nickjillings@1541 2654
nickjillings@1541 2655 qualifier = jQuery.filter( qualifier, elements );
nickjillings@1541 2656 }
nickjillings@1541 2657
nickjillings@1541 2658 return jQuery.grep( elements, function( elem ) {
nickjillings@1541 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nickjillings@1541 2660 });
nickjillings@1541 2661 }
nickjillings@1541 2662
nickjillings@1541 2663 jQuery.filter = function( expr, elems, not ) {
nickjillings@1541 2664 var elem = elems[ 0 ];
nickjillings@1541 2665
nickjillings@1541 2666 if ( not ) {
nickjillings@1541 2667 expr = ":not(" + expr + ")";
nickjillings@1541 2668 }
nickjillings@1541 2669
nickjillings@1541 2670 return elems.length === 1 && elem.nodeType === 1 ?
nickjillings@1541 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nickjillings@1541 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nickjillings@1541 2673 return elem.nodeType === 1;
nickjillings@1541 2674 }));
nickjillings@1541 2675 };
nickjillings@1541 2676
nickjillings@1541 2677 jQuery.fn.extend({
nickjillings@1541 2678 find: function( selector ) {
nickjillings@1541 2679 var i,
nickjillings@1541 2680 len = this.length,
nickjillings@1541 2681 ret = [],
nickjillings@1541 2682 self = this;
nickjillings@1541 2683
nickjillings@1541 2684 if ( typeof selector !== "string" ) {
nickjillings@1541 2685 return this.pushStack( jQuery( selector ).filter(function() {
nickjillings@1541 2686 for ( i = 0; i < len; i++ ) {
nickjillings@1541 2687 if ( jQuery.contains( self[ i ], this ) ) {
nickjillings@1541 2688 return true;
nickjillings@1541 2689 }
nickjillings@1541 2690 }
nickjillings@1541 2691 }) );
nickjillings@1541 2692 }
nickjillings@1541 2693
nickjillings@1541 2694 for ( i = 0; i < len; i++ ) {
nickjillings@1541 2695 jQuery.find( selector, self[ i ], ret );
nickjillings@1541 2696 }
nickjillings@1541 2697
nickjillings@1541 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nickjillings@1541 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nickjillings@1541 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nickjillings@1541 2701 return ret;
nickjillings@1541 2702 },
nickjillings@1541 2703 filter: function( selector ) {
nickjillings@1541 2704 return this.pushStack( winnow(this, selector || [], false) );
nickjillings@1541 2705 },
nickjillings@1541 2706 not: function( selector ) {
nickjillings@1541 2707 return this.pushStack( winnow(this, selector || [], true) );
nickjillings@1541 2708 },
nickjillings@1541 2709 is: function( selector ) {
nickjillings@1541 2710 return !!winnow(
nickjillings@1541 2711 this,
nickjillings@1541 2712
nickjillings@1541 2713 // If this is a positional/relative selector, check membership in the returned set
nickjillings@1541 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nickjillings@1541 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nickjillings@1541 2716 jQuery( selector ) :
nickjillings@1541 2717 selector || [],
nickjillings@1541 2718 false
nickjillings@1541 2719 ).length;
nickjillings@1541 2720 }
nickjillings@1541 2721 });
nickjillings@1541 2722
nickjillings@1541 2723
nickjillings@1541 2724 // Initialize a jQuery object
nickjillings@1541 2725
nickjillings@1541 2726
nickjillings@1541 2727 // A central reference to the root jQuery(document)
nickjillings@1541 2728 var rootjQuery,
nickjillings@1541 2729
nickjillings@1541 2730 // A simple way to check for HTML strings
nickjillings@1541 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nickjillings@1541 2732 // Strict HTML recognition (#11290: must start with <)
nickjillings@1541 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nickjillings@1541 2734
nickjillings@1541 2735 init = jQuery.fn.init = function( selector, context ) {
nickjillings@1541 2736 var match, elem;
nickjillings@1541 2737
nickjillings@1541 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nickjillings@1541 2739 if ( !selector ) {
nickjillings@1541 2740 return this;
nickjillings@1541 2741 }
nickjillings@1541 2742
nickjillings@1541 2743 // Handle HTML strings
nickjillings@1541 2744 if ( typeof selector === "string" ) {
nickjillings@1541 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nickjillings@1541 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nickjillings@1541 2747 match = [ null, selector, null ];
nickjillings@1541 2748
nickjillings@1541 2749 } else {
nickjillings@1541 2750 match = rquickExpr.exec( selector );
nickjillings@1541 2751 }
nickjillings@1541 2752
nickjillings@1541 2753 // Match html or make sure no context is specified for #id
nickjillings@1541 2754 if ( match && (match[1] || !context) ) {
nickjillings@1541 2755
nickjillings@1541 2756 // HANDLE: $(html) -> $(array)
nickjillings@1541 2757 if ( match[1] ) {
nickjillings@1541 2758 context = context instanceof jQuery ? context[0] : context;
nickjillings@1541 2759
nickjillings@1541 2760 // Option to run scripts is true for back-compat
nickjillings@1541 2761 // Intentionally let the error be thrown if parseHTML is not present
nickjillings@1541 2762 jQuery.merge( this, jQuery.parseHTML(
nickjillings@1541 2763 match[1],
nickjillings@1541 2764 context && context.nodeType ? context.ownerDocument || context : document,
nickjillings@1541 2765 true
nickjillings@1541 2766 ) );
nickjillings@1541 2767
nickjillings@1541 2768 // HANDLE: $(html, props)
nickjillings@1541 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nickjillings@1541 2770 for ( match in context ) {
nickjillings@1541 2771 // Properties of context are called as methods if possible
nickjillings@1541 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nickjillings@1541 2773 this[ match ]( context[ match ] );
nickjillings@1541 2774
nickjillings@1541 2775 // ...and otherwise set as attributes
nickjillings@1541 2776 } else {
nickjillings@1541 2777 this.attr( match, context[ match ] );
nickjillings@1541 2778 }
nickjillings@1541 2779 }
nickjillings@1541 2780 }
nickjillings@1541 2781
nickjillings@1541 2782 return this;
nickjillings@1541 2783
nickjillings@1541 2784 // HANDLE: $(#id)
nickjillings@1541 2785 } else {
nickjillings@1541 2786 elem = document.getElementById( match[2] );
nickjillings@1541 2787
nickjillings@1541 2788 // Support: Blackberry 4.6
nickjillings@1541 2789 // gEBID returns nodes no longer in the document (#6963)
nickjillings@1541 2790 if ( elem && elem.parentNode ) {
nickjillings@1541 2791 // Inject the element directly into the jQuery object
nickjillings@1541 2792 this.length = 1;
nickjillings@1541 2793 this[0] = elem;
nickjillings@1541 2794 }
nickjillings@1541 2795
nickjillings@1541 2796 this.context = document;
nickjillings@1541 2797 this.selector = selector;
nickjillings@1541 2798 return this;
nickjillings@1541 2799 }
nickjillings@1541 2800
nickjillings@1541 2801 // HANDLE: $(expr, $(...))
nickjillings@1541 2802 } else if ( !context || context.jquery ) {
nickjillings@1541 2803 return ( context || rootjQuery ).find( selector );
nickjillings@1541 2804
nickjillings@1541 2805 // HANDLE: $(expr, context)
nickjillings@1541 2806 // (which is just equivalent to: $(context).find(expr)
nickjillings@1541 2807 } else {
nickjillings@1541 2808 return this.constructor( context ).find( selector );
nickjillings@1541 2809 }
nickjillings@1541 2810
nickjillings@1541 2811 // HANDLE: $(DOMElement)
nickjillings@1541 2812 } else if ( selector.nodeType ) {
nickjillings@1541 2813 this.context = this[0] = selector;
nickjillings@1541 2814 this.length = 1;
nickjillings@1541 2815 return this;
nickjillings@1541 2816
nickjillings@1541 2817 // HANDLE: $(function)
nickjillings@1541 2818 // Shortcut for document ready
nickjillings@1541 2819 } else if ( jQuery.isFunction( selector ) ) {
nickjillings@1541 2820 return typeof rootjQuery.ready !== "undefined" ?
nickjillings@1541 2821 rootjQuery.ready( selector ) :
nickjillings@1541 2822 // Execute immediately if ready is not present
nickjillings@1541 2823 selector( jQuery );
nickjillings@1541 2824 }
nickjillings@1541 2825
nickjillings@1541 2826 if ( selector.selector !== undefined ) {
nickjillings@1541 2827 this.selector = selector.selector;
nickjillings@1541 2828 this.context = selector.context;
nickjillings@1541 2829 }
nickjillings@1541 2830
nickjillings@1541 2831 return jQuery.makeArray( selector, this );
nickjillings@1541 2832 };
nickjillings@1541 2833
nickjillings@1541 2834 // Give the init function the jQuery prototype for later instantiation
nickjillings@1541 2835 init.prototype = jQuery.fn;
nickjillings@1541 2836
nickjillings@1541 2837 // Initialize central reference
nickjillings@1541 2838 rootjQuery = jQuery( document );
nickjillings@1541 2839
nickjillings@1541 2840
nickjillings@1541 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nickjillings@1541 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nickjillings@1541 2843 guaranteedUnique = {
nickjillings@1541 2844 children: true,
nickjillings@1541 2845 contents: true,
nickjillings@1541 2846 next: true,
nickjillings@1541 2847 prev: true
nickjillings@1541 2848 };
nickjillings@1541 2849
nickjillings@1541 2850 jQuery.extend({
nickjillings@1541 2851 dir: function( elem, dir, until ) {
nickjillings@1541 2852 var matched = [],
nickjillings@1541 2853 truncate = until !== undefined;
nickjillings@1541 2854
nickjillings@1541 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nickjillings@1541 2856 if ( elem.nodeType === 1 ) {
nickjillings@1541 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nickjillings@1541 2858 break;
nickjillings@1541 2859 }
nickjillings@1541 2860 matched.push( elem );
nickjillings@1541 2861 }
nickjillings@1541 2862 }
nickjillings@1541 2863 return matched;
nickjillings@1541 2864 },
nickjillings@1541 2865
nickjillings@1541 2866 sibling: function( n, elem ) {
nickjillings@1541 2867 var matched = [];
nickjillings@1541 2868
nickjillings@1541 2869 for ( ; n; n = n.nextSibling ) {
nickjillings@1541 2870 if ( n.nodeType === 1 && n !== elem ) {
nickjillings@1541 2871 matched.push( n );
nickjillings@1541 2872 }
nickjillings@1541 2873 }
nickjillings@1541 2874
nickjillings@1541 2875 return matched;
nickjillings@1541 2876 }
nickjillings@1541 2877 });
nickjillings@1541 2878
nickjillings@1541 2879 jQuery.fn.extend({
nickjillings@1541 2880 has: function( target ) {
nickjillings@1541 2881 var targets = jQuery( target, this ),
nickjillings@1541 2882 l = targets.length;
nickjillings@1541 2883
nickjillings@1541 2884 return this.filter(function() {
nickjillings@1541 2885 var i = 0;
nickjillings@1541 2886 for ( ; i < l; i++ ) {
nickjillings@1541 2887 if ( jQuery.contains( this, targets[i] ) ) {
nickjillings@1541 2888 return true;
nickjillings@1541 2889 }
nickjillings@1541 2890 }
nickjillings@1541 2891 });
nickjillings@1541 2892 },
nickjillings@1541 2893
nickjillings@1541 2894 closest: function( selectors, context ) {
nickjillings@1541 2895 var cur,
nickjillings@1541 2896 i = 0,
nickjillings@1541 2897 l = this.length,
nickjillings@1541 2898 matched = [],
nickjillings@1541 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nickjillings@1541 2900 jQuery( selectors, context || this.context ) :
nickjillings@1541 2901 0;
nickjillings@1541 2902
nickjillings@1541 2903 for ( ; i < l; i++ ) {
nickjillings@1541 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nickjillings@1541 2905 // Always skip document fragments
nickjillings@1541 2906 if ( cur.nodeType < 11 && (pos ?
nickjillings@1541 2907 pos.index(cur) > -1 :
nickjillings@1541 2908
nickjillings@1541 2909 // Don't pass non-elements to Sizzle
nickjillings@1541 2910 cur.nodeType === 1 &&
nickjillings@1541 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nickjillings@1541 2912
nickjillings@1541 2913 matched.push( cur );
nickjillings@1541 2914 break;
nickjillings@1541 2915 }
nickjillings@1541 2916 }
nickjillings@1541 2917 }
nickjillings@1541 2918
nickjillings@1541 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nickjillings@1541 2920 },
nickjillings@1541 2921
nickjillings@1541 2922 // Determine the position of an element within the set
nickjillings@1541 2923 index: function( elem ) {
nickjillings@1541 2924
nickjillings@1541 2925 // No argument, return index in parent
nickjillings@1541 2926 if ( !elem ) {
nickjillings@1541 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nickjillings@1541 2928 }
nickjillings@1541 2929
nickjillings@1541 2930 // Index in selector
nickjillings@1541 2931 if ( typeof elem === "string" ) {
nickjillings@1541 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nickjillings@1541 2933 }
nickjillings@1541 2934
nickjillings@1541 2935 // Locate the position of the desired element
nickjillings@1541 2936 return indexOf.call( this,
nickjillings@1541 2937
nickjillings@1541 2938 // If it receives a jQuery object, the first element is used
nickjillings@1541 2939 elem.jquery ? elem[ 0 ] : elem
nickjillings@1541 2940 );
nickjillings@1541 2941 },
nickjillings@1541 2942
nickjillings@1541 2943 add: function( selector, context ) {
nickjillings@1541 2944 return this.pushStack(
nickjillings@1541 2945 jQuery.unique(
nickjillings@1541 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nickjillings@1541 2947 )
nickjillings@1541 2948 );
nickjillings@1541 2949 },
nickjillings@1541 2950
nickjillings@1541 2951 addBack: function( selector ) {
nickjillings@1541 2952 return this.add( selector == null ?
nickjillings@1541 2953 this.prevObject : this.prevObject.filter(selector)
nickjillings@1541 2954 );
nickjillings@1541 2955 }
nickjillings@1541 2956 });
nickjillings@1541 2957
nickjillings@1541 2958 function sibling( cur, dir ) {
nickjillings@1541 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nickjillings@1541 2960 return cur;
nickjillings@1541 2961 }
nickjillings@1541 2962
nickjillings@1541 2963 jQuery.each({
nickjillings@1541 2964 parent: function( elem ) {
nickjillings@1541 2965 var parent = elem.parentNode;
nickjillings@1541 2966 return parent && parent.nodeType !== 11 ? parent : null;
nickjillings@1541 2967 },
nickjillings@1541 2968 parents: function( elem ) {
nickjillings@1541 2969 return jQuery.dir( elem, "parentNode" );
nickjillings@1541 2970 },
nickjillings@1541 2971 parentsUntil: function( elem, i, until ) {
nickjillings@1541 2972 return jQuery.dir( elem, "parentNode", until );
nickjillings@1541 2973 },
nickjillings@1541 2974 next: function( elem ) {
nickjillings@1541 2975 return sibling( elem, "nextSibling" );
nickjillings@1541 2976 },
nickjillings@1541 2977 prev: function( elem ) {
nickjillings@1541 2978 return sibling( elem, "previousSibling" );
nickjillings@1541 2979 },
nickjillings@1541 2980 nextAll: function( elem ) {
nickjillings@1541 2981 return jQuery.dir( elem, "nextSibling" );
nickjillings@1541 2982 },
nickjillings@1541 2983 prevAll: function( elem ) {
nickjillings@1541 2984 return jQuery.dir( elem, "previousSibling" );
nickjillings@1541 2985 },
nickjillings@1541 2986 nextUntil: function( elem, i, until ) {
nickjillings@1541 2987 return jQuery.dir( elem, "nextSibling", until );
nickjillings@1541 2988 },
nickjillings@1541 2989 prevUntil: function( elem, i, until ) {
nickjillings@1541 2990 return jQuery.dir( elem, "previousSibling", until );
nickjillings@1541 2991 },
nickjillings@1541 2992 siblings: function( elem ) {
nickjillings@1541 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nickjillings@1541 2994 },
nickjillings@1541 2995 children: function( elem ) {
nickjillings@1541 2996 return jQuery.sibling( elem.firstChild );
nickjillings@1541 2997 },
nickjillings@1541 2998 contents: function( elem ) {
nickjillings@1541 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nickjillings@1541 3000 }
nickjillings@1541 3001 }, function( name, fn ) {
nickjillings@1541 3002 jQuery.fn[ name ] = function( until, selector ) {
nickjillings@1541 3003 var matched = jQuery.map( this, fn, until );
nickjillings@1541 3004
nickjillings@1541 3005 if ( name.slice( -5 ) !== "Until" ) {
nickjillings@1541 3006 selector = until;
nickjillings@1541 3007 }
nickjillings@1541 3008
nickjillings@1541 3009 if ( selector && typeof selector === "string" ) {
nickjillings@1541 3010 matched = jQuery.filter( selector, matched );
nickjillings@1541 3011 }
nickjillings@1541 3012
nickjillings@1541 3013 if ( this.length > 1 ) {
nickjillings@1541 3014 // Remove duplicates
nickjillings@1541 3015 if ( !guaranteedUnique[ name ] ) {
nickjillings@1541 3016 jQuery.unique( matched );
nickjillings@1541 3017 }
nickjillings@1541 3018
nickjillings@1541 3019 // Reverse order for parents* and prev-derivatives
nickjillings@1541 3020 if ( rparentsprev.test( name ) ) {
nickjillings@1541 3021 matched.reverse();
nickjillings@1541 3022 }
nickjillings@1541 3023 }
nickjillings@1541 3024
nickjillings@1541 3025 return this.pushStack( matched );
nickjillings@1541 3026 };
nickjillings@1541 3027 });
nickjillings@1541 3028 var rnotwhite = (/\S+/g);
nickjillings@1541 3029
nickjillings@1541 3030
nickjillings@1541 3031
nickjillings@1541 3032 // String to Object options format cache
nickjillings@1541 3033 var optionsCache = {};
nickjillings@1541 3034
nickjillings@1541 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nickjillings@1541 3036 function createOptions( options ) {
nickjillings@1541 3037 var object = optionsCache[ options ] = {};
nickjillings@1541 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nickjillings@1541 3039 object[ flag ] = true;
nickjillings@1541 3040 });
nickjillings@1541 3041 return object;
nickjillings@1541 3042 }
nickjillings@1541 3043
nickjillings@1541 3044 /*
nickjillings@1541 3045 * Create a callback list using the following parameters:
nickjillings@1541 3046 *
nickjillings@1541 3047 * options: an optional list of space-separated options that will change how
nickjillings@1541 3048 * the callback list behaves or a more traditional option object
nickjillings@1541 3049 *
nickjillings@1541 3050 * By default a callback list will act like an event callback list and can be
nickjillings@1541 3051 * "fired" multiple times.
nickjillings@1541 3052 *
nickjillings@1541 3053 * Possible options:
nickjillings@1541 3054 *
nickjillings@1541 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nickjillings@1541 3056 *
nickjillings@1541 3057 * memory: will keep track of previous values and will call any callback added
nickjillings@1541 3058 * after the list has been fired right away with the latest "memorized"
nickjillings@1541 3059 * values (like a Deferred)
nickjillings@1541 3060 *
nickjillings@1541 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nickjillings@1541 3062 *
nickjillings@1541 3063 * stopOnFalse: interrupt callings when a callback returns false
nickjillings@1541 3064 *
nickjillings@1541 3065 */
nickjillings@1541 3066 jQuery.Callbacks = function( options ) {
nickjillings@1541 3067
nickjillings@1541 3068 // Convert options from String-formatted to Object-formatted if needed
nickjillings@1541 3069 // (we check in cache first)
nickjillings@1541 3070 options = typeof options === "string" ?
nickjillings@1541 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nickjillings@1541 3072 jQuery.extend( {}, options );
nickjillings@1541 3073
nickjillings@1541 3074 var // Last fire value (for non-forgettable lists)
nickjillings@1541 3075 memory,
nickjillings@1541 3076 // Flag to know if list was already fired
nickjillings@1541 3077 fired,
nickjillings@1541 3078 // Flag to know if list is currently firing
nickjillings@1541 3079 firing,
nickjillings@1541 3080 // First callback to fire (used internally by add and fireWith)
nickjillings@1541 3081 firingStart,
nickjillings@1541 3082 // End of the loop when firing
nickjillings@1541 3083 firingLength,
nickjillings@1541 3084 // Index of currently firing callback (modified by remove if needed)
nickjillings@1541 3085 firingIndex,
nickjillings@1541 3086 // Actual callback list
nickjillings@1541 3087 list = [],
nickjillings@1541 3088 // Stack of fire calls for repeatable lists
nickjillings@1541 3089 stack = !options.once && [],
nickjillings@1541 3090 // Fire callbacks
nickjillings@1541 3091 fire = function( data ) {
nickjillings@1541 3092 memory = options.memory && data;
nickjillings@1541 3093 fired = true;
nickjillings@1541 3094 firingIndex = firingStart || 0;
nickjillings@1541 3095 firingStart = 0;
nickjillings@1541 3096 firingLength = list.length;
nickjillings@1541 3097 firing = true;
nickjillings@1541 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nickjillings@1541 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nickjillings@1541 3100 memory = false; // To prevent further calls using add
nickjillings@1541 3101 break;
nickjillings@1541 3102 }
nickjillings@1541 3103 }
nickjillings@1541 3104 firing = false;
nickjillings@1541 3105 if ( list ) {
nickjillings@1541 3106 if ( stack ) {
nickjillings@1541 3107 if ( stack.length ) {
nickjillings@1541 3108 fire( stack.shift() );
nickjillings@1541 3109 }
nickjillings@1541 3110 } else if ( memory ) {
nickjillings@1541 3111 list = [];
nickjillings@1541 3112 } else {
nickjillings@1541 3113 self.disable();
nickjillings@1541 3114 }
nickjillings@1541 3115 }
nickjillings@1541 3116 },
nickjillings@1541 3117 // Actual Callbacks object
nickjillings@1541 3118 self = {
nickjillings@1541 3119 // Add a callback or a collection of callbacks to the list
nickjillings@1541 3120 add: function() {
nickjillings@1541 3121 if ( list ) {
nickjillings@1541 3122 // First, we save the current length
nickjillings@1541 3123 var start = list.length;
nickjillings@1541 3124 (function add( args ) {
nickjillings@1541 3125 jQuery.each( args, function( _, arg ) {
nickjillings@1541 3126 var type = jQuery.type( arg );
nickjillings@1541 3127 if ( type === "function" ) {
nickjillings@1541 3128 if ( !options.unique || !self.has( arg ) ) {
nickjillings@1541 3129 list.push( arg );
nickjillings@1541 3130 }
nickjillings@1541 3131 } else if ( arg && arg.length && type !== "string" ) {
nickjillings@1541 3132 // Inspect recursively
nickjillings@1541 3133 add( arg );
nickjillings@1541 3134 }
nickjillings@1541 3135 });
nickjillings@1541 3136 })( arguments );
nickjillings@1541 3137 // Do we need to add the callbacks to the
nickjillings@1541 3138 // current firing batch?
nickjillings@1541 3139 if ( firing ) {
nickjillings@1541 3140 firingLength = list.length;
nickjillings@1541 3141 // With memory, if we're not firing then
nickjillings@1541 3142 // we should call right away
nickjillings@1541 3143 } else if ( memory ) {
nickjillings@1541 3144 firingStart = start;
nickjillings@1541 3145 fire( memory );
nickjillings@1541 3146 }
nickjillings@1541 3147 }
nickjillings@1541 3148 return this;
nickjillings@1541 3149 },
nickjillings@1541 3150 // Remove a callback from the list
nickjillings@1541 3151 remove: function() {
nickjillings@1541 3152 if ( list ) {
nickjillings@1541 3153 jQuery.each( arguments, function( _, arg ) {
nickjillings@1541 3154 var index;
nickjillings@1541 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nickjillings@1541 3156 list.splice( index, 1 );
nickjillings@1541 3157 // Handle firing indexes
nickjillings@1541 3158 if ( firing ) {
nickjillings@1541 3159 if ( index <= firingLength ) {
nickjillings@1541 3160 firingLength--;
nickjillings@1541 3161 }
nickjillings@1541 3162 if ( index <= firingIndex ) {
nickjillings@1541 3163 firingIndex--;
nickjillings@1541 3164 }
nickjillings@1541 3165 }
nickjillings@1541 3166 }
nickjillings@1541 3167 });
nickjillings@1541 3168 }
nickjillings@1541 3169 return this;
nickjillings@1541 3170 },
nickjillings@1541 3171 // Check if a given callback is in the list.
nickjillings@1541 3172 // If no argument is given, return whether or not list has callbacks attached.
nickjillings@1541 3173 has: function( fn ) {
nickjillings@1541 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nickjillings@1541 3175 },
nickjillings@1541 3176 // Remove all callbacks from the list
nickjillings@1541 3177 empty: function() {
nickjillings@1541 3178 list = [];
nickjillings@1541 3179 firingLength = 0;
nickjillings@1541 3180 return this;
nickjillings@1541 3181 },
nickjillings@1541 3182 // Have the list do nothing anymore
nickjillings@1541 3183 disable: function() {
nickjillings@1541 3184 list = stack = memory = undefined;
nickjillings@1541 3185 return this;
nickjillings@1541 3186 },
nickjillings@1541 3187 // Is it disabled?
nickjillings@1541 3188 disabled: function() {
nickjillings@1541 3189 return !list;
nickjillings@1541 3190 },
nickjillings@1541 3191 // Lock the list in its current state
nickjillings@1541 3192 lock: function() {
nickjillings@1541 3193 stack = undefined;
nickjillings@1541 3194 if ( !memory ) {
nickjillings@1541 3195 self.disable();
nickjillings@1541 3196 }
nickjillings@1541 3197 return this;
nickjillings@1541 3198 },
nickjillings@1541 3199 // Is it locked?
nickjillings@1541 3200 locked: function() {
nickjillings@1541 3201 return !stack;
nickjillings@1541 3202 },
nickjillings@1541 3203 // Call all callbacks with the given context and arguments
nickjillings@1541 3204 fireWith: function( context, args ) {
nickjillings@1541 3205 if ( list && ( !fired || stack ) ) {
nickjillings@1541 3206 args = args || [];
nickjillings@1541 3207 args = [ context, args.slice ? args.slice() : args ];
nickjillings@1541 3208 if ( firing ) {
nickjillings@1541 3209 stack.push( args );
nickjillings@1541 3210 } else {
nickjillings@1541 3211 fire( args );
nickjillings@1541 3212 }
nickjillings@1541 3213 }
nickjillings@1541 3214 return this;
nickjillings@1541 3215 },
nickjillings@1541 3216 // Call all the callbacks with the given arguments
nickjillings@1541 3217 fire: function() {
nickjillings@1541 3218 self.fireWith( this, arguments );
nickjillings@1541 3219 return this;
nickjillings@1541 3220 },
nickjillings@1541 3221 // To know if the callbacks have already been called at least once
nickjillings@1541 3222 fired: function() {
nickjillings@1541 3223 return !!fired;
nickjillings@1541 3224 }
nickjillings@1541 3225 };
nickjillings@1541 3226
nickjillings@1541 3227 return self;
nickjillings@1541 3228 };
nickjillings@1541 3229
nickjillings@1541 3230
nickjillings@1541 3231 jQuery.extend({
nickjillings@1541 3232
nickjillings@1541 3233 Deferred: function( func ) {
nickjillings@1541 3234 var tuples = [
nickjillings@1541 3235 // action, add listener, listener list, final state
nickjillings@1541 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nickjillings@1541 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nickjillings@1541 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nickjillings@1541 3239 ],
nickjillings@1541 3240 state = "pending",
nickjillings@1541 3241 promise = {
nickjillings@1541 3242 state: function() {
nickjillings@1541 3243 return state;
nickjillings@1541 3244 },
nickjillings@1541 3245 always: function() {
nickjillings@1541 3246 deferred.done( arguments ).fail( arguments );
nickjillings@1541 3247 return this;
nickjillings@1541 3248 },
nickjillings@1541 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nickjillings@1541 3250 var fns = arguments;
nickjillings@1541 3251 return jQuery.Deferred(function( newDefer ) {
nickjillings@1541 3252 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1541 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nickjillings@1541 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nickjillings@1541 3255 deferred[ tuple[1] ](function() {
nickjillings@1541 3256 var returned = fn && fn.apply( this, arguments );
nickjillings@1541 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nickjillings@1541 3258 returned.promise()
nickjillings@1541 3259 .done( newDefer.resolve )
nickjillings@1541 3260 .fail( newDefer.reject )
nickjillings@1541 3261 .progress( newDefer.notify );
nickjillings@1541 3262 } else {
nickjillings@1541 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nickjillings@1541 3264 }
nickjillings@1541 3265 });
nickjillings@1541 3266 });
nickjillings@1541 3267 fns = null;
nickjillings@1541 3268 }).promise();
nickjillings@1541 3269 },
nickjillings@1541 3270 // Get a promise for this deferred
nickjillings@1541 3271 // If obj is provided, the promise aspect is added to the object
nickjillings@1541 3272 promise: function( obj ) {
nickjillings@1541 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nickjillings@1541 3274 }
nickjillings@1541 3275 },
nickjillings@1541 3276 deferred = {};
nickjillings@1541 3277
nickjillings@1541 3278 // Keep pipe for back-compat
nickjillings@1541 3279 promise.pipe = promise.then;
nickjillings@1541 3280
nickjillings@1541 3281 // Add list-specific methods
nickjillings@1541 3282 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1541 3283 var list = tuple[ 2 ],
nickjillings@1541 3284 stateString = tuple[ 3 ];
nickjillings@1541 3285
nickjillings@1541 3286 // promise[ done | fail | progress ] = list.add
nickjillings@1541 3287 promise[ tuple[1] ] = list.add;
nickjillings@1541 3288
nickjillings@1541 3289 // Handle state
nickjillings@1541 3290 if ( stateString ) {
nickjillings@1541 3291 list.add(function() {
nickjillings@1541 3292 // state = [ resolved | rejected ]
nickjillings@1541 3293 state = stateString;
nickjillings@1541 3294
nickjillings@1541 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nickjillings@1541 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nickjillings@1541 3297 }
nickjillings@1541 3298
nickjillings@1541 3299 // deferred[ resolve | reject | notify ]
nickjillings@1541 3300 deferred[ tuple[0] ] = function() {
nickjillings@1541 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nickjillings@1541 3302 return this;
nickjillings@1541 3303 };
nickjillings@1541 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nickjillings@1541 3305 });
nickjillings@1541 3306
nickjillings@1541 3307 // Make the deferred a promise
nickjillings@1541 3308 promise.promise( deferred );
nickjillings@1541 3309
nickjillings@1541 3310 // Call given func if any
nickjillings@1541 3311 if ( func ) {
nickjillings@1541 3312 func.call( deferred, deferred );
nickjillings@1541 3313 }
nickjillings@1541 3314
nickjillings@1541 3315 // All done!
nickjillings@1541 3316 return deferred;
nickjillings@1541 3317 },
nickjillings@1541 3318
nickjillings@1541 3319 // Deferred helper
nickjillings@1541 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nickjillings@1541 3321 var i = 0,
nickjillings@1541 3322 resolveValues = slice.call( arguments ),
nickjillings@1541 3323 length = resolveValues.length,
nickjillings@1541 3324
nickjillings@1541 3325 // the count of uncompleted subordinates
nickjillings@1541 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nickjillings@1541 3327
nickjillings@1541 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nickjillings@1541 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nickjillings@1541 3330
nickjillings@1541 3331 // Update function for both resolve and progress values
nickjillings@1541 3332 updateFunc = function( i, contexts, values ) {
nickjillings@1541 3333 return function( value ) {
nickjillings@1541 3334 contexts[ i ] = this;
nickjillings@1541 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nickjillings@1541 3336 if ( values === progressValues ) {
nickjillings@1541 3337 deferred.notifyWith( contexts, values );
nickjillings@1541 3338 } else if ( !( --remaining ) ) {
nickjillings@1541 3339 deferred.resolveWith( contexts, values );
nickjillings@1541 3340 }
nickjillings@1541 3341 };
nickjillings@1541 3342 },
nickjillings@1541 3343
nickjillings@1541 3344 progressValues, progressContexts, resolveContexts;
nickjillings@1541 3345
nickjillings@1541 3346 // Add listeners to Deferred subordinates; treat others as resolved
nickjillings@1541 3347 if ( length > 1 ) {
nickjillings@1541 3348 progressValues = new Array( length );
nickjillings@1541 3349 progressContexts = new Array( length );
nickjillings@1541 3350 resolveContexts = new Array( length );
nickjillings@1541 3351 for ( ; i < length; i++ ) {
nickjillings@1541 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nickjillings@1541 3353 resolveValues[ i ].promise()
nickjillings@1541 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nickjillings@1541 3355 .fail( deferred.reject )
nickjillings@1541 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nickjillings@1541 3357 } else {
nickjillings@1541 3358 --remaining;
nickjillings@1541 3359 }
nickjillings@1541 3360 }
nickjillings@1541 3361 }
nickjillings@1541 3362
nickjillings@1541 3363 // If we're not waiting on anything, resolve the master
nickjillings@1541 3364 if ( !remaining ) {
nickjillings@1541 3365 deferred.resolveWith( resolveContexts, resolveValues );
nickjillings@1541 3366 }
nickjillings@1541 3367
nickjillings@1541 3368 return deferred.promise();
nickjillings@1541 3369 }
nickjillings@1541 3370 });
nickjillings@1541 3371
nickjillings@1541 3372
nickjillings@1541 3373 // The deferred used on DOM ready
nickjillings@1541 3374 var readyList;
nickjillings@1541 3375
nickjillings@1541 3376 jQuery.fn.ready = function( fn ) {
nickjillings@1541 3377 // Add the callback
nickjillings@1541 3378 jQuery.ready.promise().done( fn );
nickjillings@1541 3379
nickjillings@1541 3380 return this;
nickjillings@1541 3381 };
nickjillings@1541 3382
nickjillings@1541 3383 jQuery.extend({
nickjillings@1541 3384 // Is the DOM ready to be used? Set to true once it occurs.
nickjillings@1541 3385 isReady: false,
nickjillings@1541 3386
nickjillings@1541 3387 // A counter to track how many items to wait for before
nickjillings@1541 3388 // the ready event fires. See #6781
nickjillings@1541 3389 readyWait: 1,
nickjillings@1541 3390
nickjillings@1541 3391 // Hold (or release) the ready event
nickjillings@1541 3392 holdReady: function( hold ) {
nickjillings@1541 3393 if ( hold ) {
nickjillings@1541 3394 jQuery.readyWait++;
nickjillings@1541 3395 } else {
nickjillings@1541 3396 jQuery.ready( true );
nickjillings@1541 3397 }
nickjillings@1541 3398 },
nickjillings@1541 3399
nickjillings@1541 3400 // Handle when the DOM is ready
nickjillings@1541 3401 ready: function( wait ) {
nickjillings@1541 3402
nickjillings@1541 3403 // Abort if there are pending holds or we're already ready
nickjillings@1541 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nickjillings@1541 3405 return;
nickjillings@1541 3406 }
nickjillings@1541 3407
nickjillings@1541 3408 // Remember that the DOM is ready
nickjillings@1541 3409 jQuery.isReady = true;
nickjillings@1541 3410
nickjillings@1541 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nickjillings@1541 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nickjillings@1541 3413 return;
nickjillings@1541 3414 }
nickjillings@1541 3415
nickjillings@1541 3416 // If there are functions bound, to execute
nickjillings@1541 3417 readyList.resolveWith( document, [ jQuery ] );
nickjillings@1541 3418
nickjillings@1541 3419 // Trigger any bound ready events
nickjillings@1541 3420 if ( jQuery.fn.triggerHandler ) {
nickjillings@1541 3421 jQuery( document ).triggerHandler( "ready" );
nickjillings@1541 3422 jQuery( document ).off( "ready" );
nickjillings@1541 3423 }
nickjillings@1541 3424 }
nickjillings@1541 3425 });
nickjillings@1541 3426
nickjillings@1541 3427 /**
nickjillings@1541 3428 * The ready event handler and self cleanup method
nickjillings@1541 3429 */
nickjillings@1541 3430 function completed() {
nickjillings@1541 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nickjillings@1541 3432 window.removeEventListener( "load", completed, false );
nickjillings@1541 3433 jQuery.ready();
nickjillings@1541 3434 }
nickjillings@1541 3435
nickjillings@1541 3436 jQuery.ready.promise = function( obj ) {
nickjillings@1541 3437 if ( !readyList ) {
nickjillings@1541 3438
nickjillings@1541 3439 readyList = jQuery.Deferred();
nickjillings@1541 3440
nickjillings@1541 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nickjillings@1541 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nickjillings@1541 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nickjillings@1541 3444 if ( document.readyState === "complete" ) {
nickjillings@1541 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nickjillings@1541 3446 setTimeout( jQuery.ready );
nickjillings@1541 3447
nickjillings@1541 3448 } else {
nickjillings@1541 3449
nickjillings@1541 3450 // Use the handy event callback
nickjillings@1541 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nickjillings@1541 3452
nickjillings@1541 3453 // A fallback to window.onload, that will always work
nickjillings@1541 3454 window.addEventListener( "load", completed, false );
nickjillings@1541 3455 }
nickjillings@1541 3456 }
nickjillings@1541 3457 return readyList.promise( obj );
nickjillings@1541 3458 };
nickjillings@1541 3459
nickjillings@1541 3460 // Kick off the DOM ready check even if the user does not
nickjillings@1541 3461 jQuery.ready.promise();
nickjillings@1541 3462
nickjillings@1541 3463
nickjillings@1541 3464
nickjillings@1541 3465
nickjillings@1541 3466 // Multifunctional method to get and set values of a collection
nickjillings@1541 3467 // The value/s can optionally be executed if it's a function
nickjillings@1541 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nickjillings@1541 3469 var i = 0,
nickjillings@1541 3470 len = elems.length,
nickjillings@1541 3471 bulk = key == null;
nickjillings@1541 3472
nickjillings@1541 3473 // Sets many values
nickjillings@1541 3474 if ( jQuery.type( key ) === "object" ) {
nickjillings@1541 3475 chainable = true;
nickjillings@1541 3476 for ( i in key ) {
nickjillings@1541 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nickjillings@1541 3478 }
nickjillings@1541 3479
nickjillings@1541 3480 // Sets one value
nickjillings@1541 3481 } else if ( value !== undefined ) {
nickjillings@1541 3482 chainable = true;
nickjillings@1541 3483
nickjillings@1541 3484 if ( !jQuery.isFunction( value ) ) {
nickjillings@1541 3485 raw = true;
nickjillings@1541 3486 }
nickjillings@1541 3487
nickjillings@1541 3488 if ( bulk ) {
nickjillings@1541 3489 // Bulk operations run against the entire set
nickjillings@1541 3490 if ( raw ) {
nickjillings@1541 3491 fn.call( elems, value );
nickjillings@1541 3492 fn = null;
nickjillings@1541 3493
nickjillings@1541 3494 // ...except when executing function values
nickjillings@1541 3495 } else {
nickjillings@1541 3496 bulk = fn;
nickjillings@1541 3497 fn = function( elem, key, value ) {
nickjillings@1541 3498 return bulk.call( jQuery( elem ), value );
nickjillings@1541 3499 };
nickjillings@1541 3500 }
nickjillings@1541 3501 }
nickjillings@1541 3502
nickjillings@1541 3503 if ( fn ) {
nickjillings@1541 3504 for ( ; i < len; i++ ) {
nickjillings@1541 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nickjillings@1541 3506 }
nickjillings@1541 3507 }
nickjillings@1541 3508 }
nickjillings@1541 3509
nickjillings@1541 3510 return chainable ?
nickjillings@1541 3511 elems :
nickjillings@1541 3512
nickjillings@1541 3513 // Gets
nickjillings@1541 3514 bulk ?
nickjillings@1541 3515 fn.call( elems ) :
nickjillings@1541 3516 len ? fn( elems[0], key ) : emptyGet;
nickjillings@1541 3517 };
nickjillings@1541 3518
nickjillings@1541 3519
nickjillings@1541 3520 /**
nickjillings@1541 3521 * Determines whether an object can have data
nickjillings@1541 3522 */
nickjillings@1541 3523 jQuery.acceptData = function( owner ) {
nickjillings@1541 3524 // Accepts only:
nickjillings@1541 3525 // - Node
nickjillings@1541 3526 // - Node.ELEMENT_NODE
nickjillings@1541 3527 // - Node.DOCUMENT_NODE
nickjillings@1541 3528 // - Object
nickjillings@1541 3529 // - Any
nickjillings@1541 3530 /* jshint -W018 */
nickjillings@1541 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nickjillings@1541 3532 };
nickjillings@1541 3533
nickjillings@1541 3534
nickjillings@1541 3535 function Data() {
nickjillings@1541 3536 // Support: Android<4,
nickjillings@1541 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nickjillings@1541 3538 // return new empty object instead with no [[set]] accessor
nickjillings@1541 3539 Object.defineProperty( this.cache = {}, 0, {
nickjillings@1541 3540 get: function() {
nickjillings@1541 3541 return {};
nickjillings@1541 3542 }
nickjillings@1541 3543 });
nickjillings@1541 3544
nickjillings@1541 3545 this.expando = jQuery.expando + Data.uid++;
nickjillings@1541 3546 }
nickjillings@1541 3547
nickjillings@1541 3548 Data.uid = 1;
nickjillings@1541 3549 Data.accepts = jQuery.acceptData;
nickjillings@1541 3550
nickjillings@1541 3551 Data.prototype = {
nickjillings@1541 3552 key: function( owner ) {
nickjillings@1541 3553 // We can accept data for non-element nodes in modern browsers,
nickjillings@1541 3554 // but we should not, see #8335.
nickjillings@1541 3555 // Always return the key for a frozen object.
nickjillings@1541 3556 if ( !Data.accepts( owner ) ) {
nickjillings@1541 3557 return 0;
nickjillings@1541 3558 }
nickjillings@1541 3559
nickjillings@1541 3560 var descriptor = {},
nickjillings@1541 3561 // Check if the owner object already has a cache key
nickjillings@1541 3562 unlock = owner[ this.expando ];
nickjillings@1541 3563
nickjillings@1541 3564 // If not, create one
nickjillings@1541 3565 if ( !unlock ) {
nickjillings@1541 3566 unlock = Data.uid++;
nickjillings@1541 3567
nickjillings@1541 3568 // Secure it in a non-enumerable, non-writable property
nickjillings@1541 3569 try {
nickjillings@1541 3570 descriptor[ this.expando ] = { value: unlock };
nickjillings@1541 3571 Object.defineProperties( owner, descriptor );
nickjillings@1541 3572
nickjillings@1541 3573 // Support: Android<4
nickjillings@1541 3574 // Fallback to a less secure definition
nickjillings@1541 3575 } catch ( e ) {
nickjillings@1541 3576 descriptor[ this.expando ] = unlock;
nickjillings@1541 3577 jQuery.extend( owner, descriptor );
nickjillings@1541 3578 }
nickjillings@1541 3579 }
nickjillings@1541 3580
nickjillings@1541 3581 // Ensure the cache object
nickjillings@1541 3582 if ( !this.cache[ unlock ] ) {
nickjillings@1541 3583 this.cache[ unlock ] = {};
nickjillings@1541 3584 }
nickjillings@1541 3585
nickjillings@1541 3586 return unlock;
nickjillings@1541 3587 },
nickjillings@1541 3588 set: function( owner, data, value ) {
nickjillings@1541 3589 var prop,
nickjillings@1541 3590 // There may be an unlock assigned to this node,
nickjillings@1541 3591 // if there is no entry for this "owner", create one inline
nickjillings@1541 3592 // and set the unlock as though an owner entry had always existed
nickjillings@1541 3593 unlock = this.key( owner ),
nickjillings@1541 3594 cache = this.cache[ unlock ];
nickjillings@1541 3595
nickjillings@1541 3596 // Handle: [ owner, key, value ] args
nickjillings@1541 3597 if ( typeof data === "string" ) {
nickjillings@1541 3598 cache[ data ] = value;
nickjillings@1541 3599
nickjillings@1541 3600 // Handle: [ owner, { properties } ] args
nickjillings@1541 3601 } else {
nickjillings@1541 3602 // Fresh assignments by object are shallow copied
nickjillings@1541 3603 if ( jQuery.isEmptyObject( cache ) ) {
nickjillings@1541 3604 jQuery.extend( this.cache[ unlock ], data );
nickjillings@1541 3605 // Otherwise, copy the properties one-by-one to the cache object
nickjillings@1541 3606 } else {
nickjillings@1541 3607 for ( prop in data ) {
nickjillings@1541 3608 cache[ prop ] = data[ prop ];
nickjillings@1541 3609 }
nickjillings@1541 3610 }
nickjillings@1541 3611 }
nickjillings@1541 3612 return cache;
nickjillings@1541 3613 },
nickjillings@1541 3614 get: function( owner, key ) {
nickjillings@1541 3615 // Either a valid cache is found, or will be created.
nickjillings@1541 3616 // New caches will be created and the unlock returned,
nickjillings@1541 3617 // allowing direct access to the newly created
nickjillings@1541 3618 // empty data object. A valid owner object must be provided.
nickjillings@1541 3619 var cache = this.cache[ this.key( owner ) ];
nickjillings@1541 3620
nickjillings@1541 3621 return key === undefined ?
nickjillings@1541 3622 cache : cache[ key ];
nickjillings@1541 3623 },
nickjillings@1541 3624 access: function( owner, key, value ) {
nickjillings@1541 3625 var stored;
nickjillings@1541 3626 // In cases where either:
nickjillings@1541 3627 //
nickjillings@1541 3628 // 1. No key was specified
nickjillings@1541 3629 // 2. A string key was specified, but no value provided
nickjillings@1541 3630 //
nickjillings@1541 3631 // Take the "read" path and allow the get method to determine
nickjillings@1541 3632 // which value to return, respectively either:
nickjillings@1541 3633 //
nickjillings@1541 3634 // 1. The entire cache object
nickjillings@1541 3635 // 2. The data stored at the key
nickjillings@1541 3636 //
nickjillings@1541 3637 if ( key === undefined ||
nickjillings@1541 3638 ((key && typeof key === "string") && value === undefined) ) {
nickjillings@1541 3639
nickjillings@1541 3640 stored = this.get( owner, key );
nickjillings@1541 3641
nickjillings@1541 3642 return stored !== undefined ?
nickjillings@1541 3643 stored : this.get( owner, jQuery.camelCase(key) );
nickjillings@1541 3644 }
nickjillings@1541 3645
nickjillings@1541 3646 // [*]When the key is not a string, or both a key and value
nickjillings@1541 3647 // are specified, set or extend (existing objects) with either:
nickjillings@1541 3648 //
nickjillings@1541 3649 // 1. An object of properties
nickjillings@1541 3650 // 2. A key and value
nickjillings@1541 3651 //
nickjillings@1541 3652 this.set( owner, key, value );
nickjillings@1541 3653
nickjillings@1541 3654 // Since the "set" path can have two possible entry points
nickjillings@1541 3655 // return the expected data based on which path was taken[*]
nickjillings@1541 3656 return value !== undefined ? value : key;
nickjillings@1541 3657 },
nickjillings@1541 3658 remove: function( owner, key ) {
nickjillings@1541 3659 var i, name, camel,
nickjillings@1541 3660 unlock = this.key( owner ),
nickjillings@1541 3661 cache = this.cache[ unlock ];
nickjillings@1541 3662
nickjillings@1541 3663 if ( key === undefined ) {
nickjillings@1541 3664 this.cache[ unlock ] = {};
nickjillings@1541 3665
nickjillings@1541 3666 } else {
nickjillings@1541 3667 // Support array or space separated string of keys
nickjillings@1541 3668 if ( jQuery.isArray( key ) ) {
nickjillings@1541 3669 // If "name" is an array of keys...
nickjillings@1541 3670 // When data is initially created, via ("key", "val") signature,
nickjillings@1541 3671 // keys will be converted to camelCase.
nickjillings@1541 3672 // Since there is no way to tell _how_ a key was added, remove
nickjillings@1541 3673 // both plain key and camelCase key. #12786
nickjillings@1541 3674 // This will only penalize the array argument path.
nickjillings@1541 3675 name = key.concat( key.map( jQuery.camelCase ) );
nickjillings@1541 3676 } else {
nickjillings@1541 3677 camel = jQuery.camelCase( key );
nickjillings@1541 3678 // Try the string as a key before any manipulation
nickjillings@1541 3679 if ( key in cache ) {
nickjillings@1541 3680 name = [ key, camel ];
nickjillings@1541 3681 } else {
nickjillings@1541 3682 // If a key with the spaces exists, use it.
nickjillings@1541 3683 // Otherwise, create an array by matching non-whitespace
nickjillings@1541 3684 name = camel;
nickjillings@1541 3685 name = name in cache ?
nickjillings@1541 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nickjillings@1541 3687 }
nickjillings@1541 3688 }
nickjillings@1541 3689
nickjillings@1541 3690 i = name.length;
nickjillings@1541 3691 while ( i-- ) {
nickjillings@1541 3692 delete cache[ name[ i ] ];
nickjillings@1541 3693 }
nickjillings@1541 3694 }
nickjillings@1541 3695 },
nickjillings@1541 3696 hasData: function( owner ) {
nickjillings@1541 3697 return !jQuery.isEmptyObject(
nickjillings@1541 3698 this.cache[ owner[ this.expando ] ] || {}
nickjillings@1541 3699 );
nickjillings@1541 3700 },
nickjillings@1541 3701 discard: function( owner ) {
nickjillings@1541 3702 if ( owner[ this.expando ] ) {
nickjillings@1541 3703 delete this.cache[ owner[ this.expando ] ];
nickjillings@1541 3704 }
nickjillings@1541 3705 }
nickjillings@1541 3706 };
nickjillings@1541 3707 var data_priv = new Data();
nickjillings@1541 3708
nickjillings@1541 3709 var data_user = new Data();
nickjillings@1541 3710
nickjillings@1541 3711
nickjillings@1541 3712
nickjillings@1541 3713 // Implementation Summary
nickjillings@1541 3714 //
nickjillings@1541 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nickjillings@1541 3716 // 2. Improve the module's maintainability by reducing the storage
nickjillings@1541 3717 // paths to a single mechanism.
nickjillings@1541 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nickjillings@1541 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nickjillings@1541 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nickjillings@1541 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nickjillings@1541 3722
nickjillings@1541 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nickjillings@1541 3724 rmultiDash = /([A-Z])/g;
nickjillings@1541 3725
nickjillings@1541 3726 function dataAttr( elem, key, data ) {
nickjillings@1541 3727 var name;
nickjillings@1541 3728
nickjillings@1541 3729 // If nothing was found internally, try to fetch any
nickjillings@1541 3730 // data from the HTML5 data-* attribute
nickjillings@1541 3731 if ( data === undefined && elem.nodeType === 1 ) {
nickjillings@1541 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nickjillings@1541 3733 data = elem.getAttribute( name );
nickjillings@1541 3734
nickjillings@1541 3735 if ( typeof data === "string" ) {
nickjillings@1541 3736 try {
nickjillings@1541 3737 data = data === "true" ? true :
nickjillings@1541 3738 data === "false" ? false :
nickjillings@1541 3739 data === "null" ? null :
nickjillings@1541 3740 // Only convert to a number if it doesn't change the string
nickjillings@1541 3741 +data + "" === data ? +data :
nickjillings@1541 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nickjillings@1541 3743 data;
nickjillings@1541 3744 } catch( e ) {}
nickjillings@1541 3745
nickjillings@1541 3746 // Make sure we set the data so it isn't changed later
nickjillings@1541 3747 data_user.set( elem, key, data );
nickjillings@1541 3748 } else {
nickjillings@1541 3749 data = undefined;
nickjillings@1541 3750 }
nickjillings@1541 3751 }
nickjillings@1541 3752 return data;
nickjillings@1541 3753 }
nickjillings@1541 3754
nickjillings@1541 3755 jQuery.extend({
nickjillings@1541 3756 hasData: function( elem ) {
nickjillings@1541 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nickjillings@1541 3758 },
nickjillings@1541 3759
nickjillings@1541 3760 data: function( elem, name, data ) {
nickjillings@1541 3761 return data_user.access( elem, name, data );
nickjillings@1541 3762 },
nickjillings@1541 3763
nickjillings@1541 3764 removeData: function( elem, name ) {
nickjillings@1541 3765 data_user.remove( elem, name );
nickjillings@1541 3766 },
nickjillings@1541 3767
nickjillings@1541 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nickjillings@1541 3769 // with direct calls to data_priv methods, these can be deprecated.
nickjillings@1541 3770 _data: function( elem, name, data ) {
nickjillings@1541 3771 return data_priv.access( elem, name, data );
nickjillings@1541 3772 },
nickjillings@1541 3773
nickjillings@1541 3774 _removeData: function( elem, name ) {
nickjillings@1541 3775 data_priv.remove( elem, name );
nickjillings@1541 3776 }
nickjillings@1541 3777 });
nickjillings@1541 3778
nickjillings@1541 3779 jQuery.fn.extend({
nickjillings@1541 3780 data: function( key, value ) {
nickjillings@1541 3781 var i, name, data,
nickjillings@1541 3782 elem = this[ 0 ],
nickjillings@1541 3783 attrs = elem && elem.attributes;
nickjillings@1541 3784
nickjillings@1541 3785 // Gets all values
nickjillings@1541 3786 if ( key === undefined ) {
nickjillings@1541 3787 if ( this.length ) {
nickjillings@1541 3788 data = data_user.get( elem );
nickjillings@1541 3789
nickjillings@1541 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nickjillings@1541 3791 i = attrs.length;
nickjillings@1541 3792 while ( i-- ) {
nickjillings@1541 3793
nickjillings@1541 3794 // Support: IE11+
nickjillings@1541 3795 // The attrs elements can be null (#14894)
nickjillings@1541 3796 if ( attrs[ i ] ) {
nickjillings@1541 3797 name = attrs[ i ].name;
nickjillings@1541 3798 if ( name.indexOf( "data-" ) === 0 ) {
nickjillings@1541 3799 name = jQuery.camelCase( name.slice(5) );
nickjillings@1541 3800 dataAttr( elem, name, data[ name ] );
nickjillings@1541 3801 }
nickjillings@1541 3802 }
nickjillings@1541 3803 }
nickjillings@1541 3804 data_priv.set( elem, "hasDataAttrs", true );
nickjillings@1541 3805 }
nickjillings@1541 3806 }
nickjillings@1541 3807
nickjillings@1541 3808 return data;
nickjillings@1541 3809 }
nickjillings@1541 3810
nickjillings@1541 3811 // Sets multiple values
nickjillings@1541 3812 if ( typeof key === "object" ) {
nickjillings@1541 3813 return this.each(function() {
nickjillings@1541 3814 data_user.set( this, key );
nickjillings@1541 3815 });
nickjillings@1541 3816 }
nickjillings@1541 3817
nickjillings@1541 3818 return access( this, function( value ) {
nickjillings@1541 3819 var data,
nickjillings@1541 3820 camelKey = jQuery.camelCase( key );
nickjillings@1541 3821
nickjillings@1541 3822 // The calling jQuery object (element matches) is not empty
nickjillings@1541 3823 // (and therefore has an element appears at this[ 0 ]) and the
nickjillings@1541 3824 // `value` parameter was not undefined. An empty jQuery object
nickjillings@1541 3825 // will result in `undefined` for elem = this[ 0 ] which will
nickjillings@1541 3826 // throw an exception if an attempt to read a data cache is made.
nickjillings@1541 3827 if ( elem && value === undefined ) {
nickjillings@1541 3828 // Attempt to get data from the cache
nickjillings@1541 3829 // with the key as-is
nickjillings@1541 3830 data = data_user.get( elem, key );
nickjillings@1541 3831 if ( data !== undefined ) {
nickjillings@1541 3832 return data;
nickjillings@1541 3833 }
nickjillings@1541 3834
nickjillings@1541 3835 // Attempt to get data from the cache
nickjillings@1541 3836 // with the key camelized
nickjillings@1541 3837 data = data_user.get( elem, camelKey );
nickjillings@1541 3838 if ( data !== undefined ) {
nickjillings@1541 3839 return data;
nickjillings@1541 3840 }
nickjillings@1541 3841
nickjillings@1541 3842 // Attempt to "discover" the data in
nickjillings@1541 3843 // HTML5 custom data-* attrs
nickjillings@1541 3844 data = dataAttr( elem, camelKey, undefined );
nickjillings@1541 3845 if ( data !== undefined ) {
nickjillings@1541 3846 return data;
nickjillings@1541 3847 }
nickjillings@1541 3848
nickjillings@1541 3849 // We tried really hard, but the data doesn't exist.
nickjillings@1541 3850 return;
nickjillings@1541 3851 }
nickjillings@1541 3852
nickjillings@1541 3853 // Set the data...
nickjillings@1541 3854 this.each(function() {
nickjillings@1541 3855 // First, attempt to store a copy or reference of any
nickjillings@1541 3856 // data that might've been store with a camelCased key.
nickjillings@1541 3857 var data = data_user.get( this, camelKey );
nickjillings@1541 3858
nickjillings@1541 3859 // For HTML5 data-* attribute interop, we have to
nickjillings@1541 3860 // store property names with dashes in a camelCase form.
nickjillings@1541 3861 // This might not apply to all properties...*
nickjillings@1541 3862 data_user.set( this, camelKey, value );
nickjillings@1541 3863
nickjillings@1541 3864 // *... In the case of properties that might _actually_
nickjillings@1541 3865 // have dashes, we need to also store a copy of that
nickjillings@1541 3866 // unchanged property.
nickjillings@1541 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nickjillings@1541 3868 data_user.set( this, key, value );
nickjillings@1541 3869 }
nickjillings@1541 3870 });
nickjillings@1541 3871 }, null, value, arguments.length > 1, null, true );
nickjillings@1541 3872 },
nickjillings@1541 3873
nickjillings@1541 3874 removeData: function( key ) {
nickjillings@1541 3875 return this.each(function() {
nickjillings@1541 3876 data_user.remove( this, key );
nickjillings@1541 3877 });
nickjillings@1541 3878 }
nickjillings@1541 3879 });
nickjillings@1541 3880
nickjillings@1541 3881
nickjillings@1541 3882 jQuery.extend({
nickjillings@1541 3883 queue: function( elem, type, data ) {
nickjillings@1541 3884 var queue;
nickjillings@1541 3885
nickjillings@1541 3886 if ( elem ) {
nickjillings@1541 3887 type = ( type || "fx" ) + "queue";
nickjillings@1541 3888 queue = data_priv.get( elem, type );
nickjillings@1541 3889
nickjillings@1541 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nickjillings@1541 3891 if ( data ) {
nickjillings@1541 3892 if ( !queue || jQuery.isArray( data ) ) {
nickjillings@1541 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nickjillings@1541 3894 } else {
nickjillings@1541 3895 queue.push( data );
nickjillings@1541 3896 }
nickjillings@1541 3897 }
nickjillings@1541 3898 return queue || [];
nickjillings@1541 3899 }
nickjillings@1541 3900 },
nickjillings@1541 3901
nickjillings@1541 3902 dequeue: function( elem, type ) {
nickjillings@1541 3903 type = type || "fx";
nickjillings@1541 3904
nickjillings@1541 3905 var queue = jQuery.queue( elem, type ),
nickjillings@1541 3906 startLength = queue.length,
nickjillings@1541 3907 fn = queue.shift(),
nickjillings@1541 3908 hooks = jQuery._queueHooks( elem, type ),
nickjillings@1541 3909 next = function() {
nickjillings@1541 3910 jQuery.dequeue( elem, type );
nickjillings@1541 3911 };
nickjillings@1541 3912
nickjillings@1541 3913 // If the fx queue is dequeued, always remove the progress sentinel
nickjillings@1541 3914 if ( fn === "inprogress" ) {
nickjillings@1541 3915 fn = queue.shift();
nickjillings@1541 3916 startLength--;
nickjillings@1541 3917 }
nickjillings@1541 3918
nickjillings@1541 3919 if ( fn ) {
nickjillings@1541 3920
nickjillings@1541 3921 // Add a progress sentinel to prevent the fx queue from being
nickjillings@1541 3922 // automatically dequeued
nickjillings@1541 3923 if ( type === "fx" ) {
nickjillings@1541 3924 queue.unshift( "inprogress" );
nickjillings@1541 3925 }
nickjillings@1541 3926
nickjillings@1541 3927 // Clear up the last queue stop function
nickjillings@1541 3928 delete hooks.stop;
nickjillings@1541 3929 fn.call( elem, next, hooks );
nickjillings@1541 3930 }
nickjillings@1541 3931
nickjillings@1541 3932 if ( !startLength && hooks ) {
nickjillings@1541 3933 hooks.empty.fire();
nickjillings@1541 3934 }
nickjillings@1541 3935 },
nickjillings@1541 3936
nickjillings@1541 3937 // Not public - generate a queueHooks object, or return the current one
nickjillings@1541 3938 _queueHooks: function( elem, type ) {
nickjillings@1541 3939 var key = type + "queueHooks";
nickjillings@1541 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nickjillings@1541 3941 empty: jQuery.Callbacks("once memory").add(function() {
nickjillings@1541 3942 data_priv.remove( elem, [ type + "queue", key ] );
nickjillings@1541 3943 })
nickjillings@1541 3944 });
nickjillings@1541 3945 }
nickjillings@1541 3946 });
nickjillings@1541 3947
nickjillings@1541 3948 jQuery.fn.extend({
nickjillings@1541 3949 queue: function( type, data ) {
nickjillings@1541 3950 var setter = 2;
nickjillings@1541 3951
nickjillings@1541 3952 if ( typeof type !== "string" ) {
nickjillings@1541 3953 data = type;
nickjillings@1541 3954 type = "fx";
nickjillings@1541 3955 setter--;
nickjillings@1541 3956 }
nickjillings@1541 3957
nickjillings@1541 3958 if ( arguments.length < setter ) {
nickjillings@1541 3959 return jQuery.queue( this[0], type );
nickjillings@1541 3960 }
nickjillings@1541 3961
nickjillings@1541 3962 return data === undefined ?
nickjillings@1541 3963 this :
nickjillings@1541 3964 this.each(function() {
nickjillings@1541 3965 var queue = jQuery.queue( this, type, data );
nickjillings@1541 3966
nickjillings@1541 3967 // Ensure a hooks for this queue
nickjillings@1541 3968 jQuery._queueHooks( this, type );
nickjillings@1541 3969
nickjillings@1541 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nickjillings@1541 3971 jQuery.dequeue( this, type );
nickjillings@1541 3972 }
nickjillings@1541 3973 });
nickjillings@1541 3974 },
nickjillings@1541 3975 dequeue: function( type ) {
nickjillings@1541 3976 return this.each(function() {
nickjillings@1541 3977 jQuery.dequeue( this, type );
nickjillings@1541 3978 });
nickjillings@1541 3979 },
nickjillings@1541 3980 clearQueue: function( type ) {
nickjillings@1541 3981 return this.queue( type || "fx", [] );
nickjillings@1541 3982 },
nickjillings@1541 3983 // Get a promise resolved when queues of a certain type
nickjillings@1541 3984 // are emptied (fx is the type by default)
nickjillings@1541 3985 promise: function( type, obj ) {
nickjillings@1541 3986 var tmp,
nickjillings@1541 3987 count = 1,
nickjillings@1541 3988 defer = jQuery.Deferred(),
nickjillings@1541 3989 elements = this,
nickjillings@1541 3990 i = this.length,
nickjillings@1541 3991 resolve = function() {
nickjillings@1541 3992 if ( !( --count ) ) {
nickjillings@1541 3993 defer.resolveWith( elements, [ elements ] );
nickjillings@1541 3994 }
nickjillings@1541 3995 };
nickjillings@1541 3996
nickjillings@1541 3997 if ( typeof type !== "string" ) {
nickjillings@1541 3998 obj = type;
nickjillings@1541 3999 type = undefined;
nickjillings@1541 4000 }
nickjillings@1541 4001 type = type || "fx";
nickjillings@1541 4002
nickjillings@1541 4003 while ( i-- ) {
nickjillings@1541 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nickjillings@1541 4005 if ( tmp && tmp.empty ) {
nickjillings@1541 4006 count++;
nickjillings@1541 4007 tmp.empty.add( resolve );
nickjillings@1541 4008 }
nickjillings@1541 4009 }
nickjillings@1541 4010 resolve();
nickjillings@1541 4011 return defer.promise( obj );
nickjillings@1541 4012 }
nickjillings@1541 4013 });
nickjillings@1541 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nickjillings@1541 4015
nickjillings@1541 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nickjillings@1541 4017
nickjillings@1541 4018 var isHidden = function( elem, el ) {
nickjillings@1541 4019 // isHidden might be called from jQuery#filter function;
nickjillings@1541 4020 // in that case, element will be second argument
nickjillings@1541 4021 elem = el || elem;
nickjillings@1541 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nickjillings@1541 4023 };
nickjillings@1541 4024
nickjillings@1541 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nickjillings@1541 4026
nickjillings@1541 4027
nickjillings@1541 4028
nickjillings@1541 4029 (function() {
nickjillings@1541 4030 var fragment = document.createDocumentFragment(),
nickjillings@1541 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nickjillings@1541 4032 input = document.createElement( "input" );
nickjillings@1541 4033
nickjillings@1541 4034 // Support: Safari<=5.1
nickjillings@1541 4035 // Check state lost if the name is set (#11217)
nickjillings@1541 4036 // Support: Windows Web Apps (WWA)
nickjillings@1541 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nickjillings@1541 4038 input.setAttribute( "type", "radio" );
nickjillings@1541 4039 input.setAttribute( "checked", "checked" );
nickjillings@1541 4040 input.setAttribute( "name", "t" );
nickjillings@1541 4041
nickjillings@1541 4042 div.appendChild( input );
nickjillings@1541 4043
nickjillings@1541 4044 // Support: Safari<=5.1, Android<4.2
nickjillings@1541 4045 // Older WebKit doesn't clone checked state correctly in fragments
nickjillings@1541 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nickjillings@1541 4047
nickjillings@1541 4048 // Support: IE<=11+
nickjillings@1541 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nickjillings@1541 4050 div.innerHTML = "<textarea>x</textarea>";
nickjillings@1541 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nickjillings@1541 4052 })();
nickjillings@1541 4053 var strundefined = typeof undefined;
nickjillings@1541 4054
nickjillings@1541 4055
nickjillings@1541 4056
nickjillings@1541 4057 support.focusinBubbles = "onfocusin" in window;
nickjillings@1541 4058
nickjillings@1541 4059
nickjillings@1541 4060 var
nickjillings@1541 4061 rkeyEvent = /^key/,
nickjillings@1541 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nickjillings@1541 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nickjillings@1541 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nickjillings@1541 4065
nickjillings@1541 4066 function returnTrue() {
nickjillings@1541 4067 return true;
nickjillings@1541 4068 }
nickjillings@1541 4069
nickjillings@1541 4070 function returnFalse() {
nickjillings@1541 4071 return false;
nickjillings@1541 4072 }
nickjillings@1541 4073
nickjillings@1541 4074 function safeActiveElement() {
nickjillings@1541 4075 try {
nickjillings@1541 4076 return document.activeElement;
nickjillings@1541 4077 } catch ( err ) { }
nickjillings@1541 4078 }
nickjillings@1541 4079
nickjillings@1541 4080 /*
nickjillings@1541 4081 * Helper functions for managing events -- not part of the public interface.
nickjillings@1541 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nickjillings@1541 4083 */
nickjillings@1541 4084 jQuery.event = {
nickjillings@1541 4085
nickjillings@1541 4086 global: {},
nickjillings@1541 4087
nickjillings@1541 4088 add: function( elem, types, handler, data, selector ) {
nickjillings@1541 4089
nickjillings@1541 4090 var handleObjIn, eventHandle, tmp,
nickjillings@1541 4091 events, t, handleObj,
nickjillings@1541 4092 special, handlers, type, namespaces, origType,
nickjillings@1541 4093 elemData = data_priv.get( elem );
nickjillings@1541 4094
nickjillings@1541 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nickjillings@1541 4096 if ( !elemData ) {
nickjillings@1541 4097 return;
nickjillings@1541 4098 }
nickjillings@1541 4099
nickjillings@1541 4100 // Caller can pass in an object of custom data in lieu of the handler
nickjillings@1541 4101 if ( handler.handler ) {
nickjillings@1541 4102 handleObjIn = handler;
nickjillings@1541 4103 handler = handleObjIn.handler;
nickjillings@1541 4104 selector = handleObjIn.selector;
nickjillings@1541 4105 }
nickjillings@1541 4106
nickjillings@1541 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nickjillings@1541 4108 if ( !handler.guid ) {
nickjillings@1541 4109 handler.guid = jQuery.guid++;
nickjillings@1541 4110 }
nickjillings@1541 4111
nickjillings@1541 4112 // Init the element's event structure and main handler, if this is the first
nickjillings@1541 4113 if ( !(events = elemData.events) ) {
nickjillings@1541 4114 events = elemData.events = {};
nickjillings@1541 4115 }
nickjillings@1541 4116 if ( !(eventHandle = elemData.handle) ) {
nickjillings@1541 4117 eventHandle = elemData.handle = function( e ) {
nickjillings@1541 4118 // Discard the second event of a jQuery.event.trigger() and
nickjillings@1541 4119 // when an event is called after a page has unloaded
nickjillings@1541 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nickjillings@1541 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nickjillings@1541 4122 };
nickjillings@1541 4123 }
nickjillings@1541 4124
nickjillings@1541 4125 // Handle multiple events separated by a space
nickjillings@1541 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1541 4127 t = types.length;
nickjillings@1541 4128 while ( t-- ) {
nickjillings@1541 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1541 4130 type = origType = tmp[1];
nickjillings@1541 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1541 4132
nickjillings@1541 4133 // There *must* be a type, no attaching namespace-only handlers
nickjillings@1541 4134 if ( !type ) {
nickjillings@1541 4135 continue;
nickjillings@1541 4136 }
nickjillings@1541 4137
nickjillings@1541 4138 // If event changes its type, use the special event handlers for the changed type
nickjillings@1541 4139 special = jQuery.event.special[ type ] || {};
nickjillings@1541 4140
nickjillings@1541 4141 // If selector defined, determine special event api type, otherwise given type
nickjillings@1541 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1541 4143
nickjillings@1541 4144 // Update special based on newly reset type
nickjillings@1541 4145 special = jQuery.event.special[ type ] || {};
nickjillings@1541 4146
nickjillings@1541 4147 // handleObj is passed to all event handlers
nickjillings@1541 4148 handleObj = jQuery.extend({
nickjillings@1541 4149 type: type,
nickjillings@1541 4150 origType: origType,
nickjillings@1541 4151 data: data,
nickjillings@1541 4152 handler: handler,
nickjillings@1541 4153 guid: handler.guid,
nickjillings@1541 4154 selector: selector,
nickjillings@1541 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nickjillings@1541 4156 namespace: namespaces.join(".")
nickjillings@1541 4157 }, handleObjIn );
nickjillings@1541 4158
nickjillings@1541 4159 // Init the event handler queue if we're the first
nickjillings@1541 4160 if ( !(handlers = events[ type ]) ) {
nickjillings@1541 4161 handlers = events[ type ] = [];
nickjillings@1541 4162 handlers.delegateCount = 0;
nickjillings@1541 4163
nickjillings@1541 4164 // Only use addEventListener if the special events handler returns false
nickjillings@1541 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nickjillings@1541 4166 if ( elem.addEventListener ) {
nickjillings@1541 4167 elem.addEventListener( type, eventHandle, false );
nickjillings@1541 4168 }
nickjillings@1541 4169 }
nickjillings@1541 4170 }
nickjillings@1541 4171
nickjillings@1541 4172 if ( special.add ) {
nickjillings@1541 4173 special.add.call( elem, handleObj );
nickjillings@1541 4174
nickjillings@1541 4175 if ( !handleObj.handler.guid ) {
nickjillings@1541 4176 handleObj.handler.guid = handler.guid;
nickjillings@1541 4177 }
nickjillings@1541 4178 }
nickjillings@1541 4179
nickjillings@1541 4180 // Add to the element's handler list, delegates in front
nickjillings@1541 4181 if ( selector ) {
nickjillings@1541 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nickjillings@1541 4183 } else {
nickjillings@1541 4184 handlers.push( handleObj );
nickjillings@1541 4185 }
nickjillings@1541 4186
nickjillings@1541 4187 // Keep track of which events have ever been used, for event optimization
nickjillings@1541 4188 jQuery.event.global[ type ] = true;
nickjillings@1541 4189 }
nickjillings@1541 4190
nickjillings@1541 4191 },
nickjillings@1541 4192
nickjillings@1541 4193 // Detach an event or set of events from an element
nickjillings@1541 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nickjillings@1541 4195
nickjillings@1541 4196 var j, origCount, tmp,
nickjillings@1541 4197 events, t, handleObj,
nickjillings@1541 4198 special, handlers, type, namespaces, origType,
nickjillings@1541 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nickjillings@1541 4200
nickjillings@1541 4201 if ( !elemData || !(events = elemData.events) ) {
nickjillings@1541 4202 return;
nickjillings@1541 4203 }
nickjillings@1541 4204
nickjillings@1541 4205 // Once for each type.namespace in types; type may be omitted
nickjillings@1541 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1541 4207 t = types.length;
nickjillings@1541 4208 while ( t-- ) {
nickjillings@1541 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1541 4210 type = origType = tmp[1];
nickjillings@1541 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1541 4212
nickjillings@1541 4213 // Unbind all events (on this namespace, if provided) for the element
nickjillings@1541 4214 if ( !type ) {
nickjillings@1541 4215 for ( type in events ) {
nickjillings@1541 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nickjillings@1541 4217 }
nickjillings@1541 4218 continue;
nickjillings@1541 4219 }
nickjillings@1541 4220
nickjillings@1541 4221 special = jQuery.event.special[ type ] || {};
nickjillings@1541 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1541 4223 handlers = events[ type ] || [];
nickjillings@1541 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nickjillings@1541 4225
nickjillings@1541 4226 // Remove matching events
nickjillings@1541 4227 origCount = j = handlers.length;
nickjillings@1541 4228 while ( j-- ) {
nickjillings@1541 4229 handleObj = handlers[ j ];
nickjillings@1541 4230
nickjillings@1541 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nickjillings@1541 4232 ( !handler || handler.guid === handleObj.guid ) &&
nickjillings@1541 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nickjillings@1541 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nickjillings@1541 4235 handlers.splice( j, 1 );
nickjillings@1541 4236
nickjillings@1541 4237 if ( handleObj.selector ) {
nickjillings@1541 4238 handlers.delegateCount--;
nickjillings@1541 4239 }
nickjillings@1541 4240 if ( special.remove ) {
nickjillings@1541 4241 special.remove.call( elem, handleObj );
nickjillings@1541 4242 }
nickjillings@1541 4243 }
nickjillings@1541 4244 }
nickjillings@1541 4245
nickjillings@1541 4246 // Remove generic event handler if we removed something and no more handlers exist
nickjillings@1541 4247 // (avoids potential for endless recursion during removal of special event handlers)
nickjillings@1541 4248 if ( origCount && !handlers.length ) {
nickjillings@1541 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nickjillings@1541 4250 jQuery.removeEvent( elem, type, elemData.handle );
nickjillings@1541 4251 }
nickjillings@1541 4252
nickjillings@1541 4253 delete events[ type ];
nickjillings@1541 4254 }
nickjillings@1541 4255 }
nickjillings@1541 4256
nickjillings@1541 4257 // Remove the expando if it's no longer used
nickjillings@1541 4258 if ( jQuery.isEmptyObject( events ) ) {
nickjillings@1541 4259 delete elemData.handle;
nickjillings@1541 4260 data_priv.remove( elem, "events" );
nickjillings@1541 4261 }
nickjillings@1541 4262 },
nickjillings@1541 4263
nickjillings@1541 4264 trigger: function( event, data, elem, onlyHandlers ) {
nickjillings@1541 4265
nickjillings@1541 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nickjillings@1541 4267 eventPath = [ elem || document ],
nickjillings@1541 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nickjillings@1541 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nickjillings@1541 4270
nickjillings@1541 4271 cur = tmp = elem = elem || document;
nickjillings@1541 4272
nickjillings@1541 4273 // Don't do events on text and comment nodes
nickjillings@1541 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nickjillings@1541 4275 return;
nickjillings@1541 4276 }
nickjillings@1541 4277
nickjillings@1541 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nickjillings@1541 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nickjillings@1541 4280 return;
nickjillings@1541 4281 }
nickjillings@1541 4282
nickjillings@1541 4283 if ( type.indexOf(".") >= 0 ) {
nickjillings@1541 4284 // Namespaced trigger; create a regexp to match event type in handle()
nickjillings@1541 4285 namespaces = type.split(".");
nickjillings@1541 4286 type = namespaces.shift();
nickjillings@1541 4287 namespaces.sort();
nickjillings@1541 4288 }
nickjillings@1541 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nickjillings@1541 4290
nickjillings@1541 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nickjillings@1541 4292 event = event[ jQuery.expando ] ?
nickjillings@1541 4293 event :
nickjillings@1541 4294 new jQuery.Event( type, typeof event === "object" && event );
nickjillings@1541 4295
nickjillings@1541 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nickjillings@1541 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nickjillings@1541 4298 event.namespace = namespaces.join(".");
nickjillings@1541 4299 event.namespace_re = event.namespace ?
nickjillings@1541 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nickjillings@1541 4301 null;
nickjillings@1541 4302
nickjillings@1541 4303 // Clean up the event in case it is being reused
nickjillings@1541 4304 event.result = undefined;
nickjillings@1541 4305 if ( !event.target ) {
nickjillings@1541 4306 event.target = elem;
nickjillings@1541 4307 }
nickjillings@1541 4308
nickjillings@1541 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nickjillings@1541 4310 data = data == null ?
nickjillings@1541 4311 [ event ] :
nickjillings@1541 4312 jQuery.makeArray( data, [ event ] );
nickjillings@1541 4313
nickjillings@1541 4314 // Allow special events to draw outside the lines
nickjillings@1541 4315 special = jQuery.event.special[ type ] || {};
nickjillings@1541 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nickjillings@1541 4317 return;
nickjillings@1541 4318 }
nickjillings@1541 4319
nickjillings@1541 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nickjillings@1541 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nickjillings@1541 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nickjillings@1541 4323
nickjillings@1541 4324 bubbleType = special.delegateType || type;
nickjillings@1541 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nickjillings@1541 4326 cur = cur.parentNode;
nickjillings@1541 4327 }
nickjillings@1541 4328 for ( ; cur; cur = cur.parentNode ) {
nickjillings@1541 4329 eventPath.push( cur );
nickjillings@1541 4330 tmp = cur;
nickjillings@1541 4331 }
nickjillings@1541 4332
nickjillings@1541 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nickjillings@1541 4334 if ( tmp === (elem.ownerDocument || document) ) {
nickjillings@1541 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nickjillings@1541 4336 }
nickjillings@1541 4337 }
nickjillings@1541 4338
nickjillings@1541 4339 // Fire handlers on the event path
nickjillings@1541 4340 i = 0;
nickjillings@1541 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nickjillings@1541 4342
nickjillings@1541 4343 event.type = i > 1 ?
nickjillings@1541 4344 bubbleType :
nickjillings@1541 4345 special.bindType || type;
nickjillings@1541 4346
nickjillings@1541 4347 // jQuery handler
nickjillings@1541 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nickjillings@1541 4349 if ( handle ) {
nickjillings@1541 4350 handle.apply( cur, data );
nickjillings@1541 4351 }
nickjillings@1541 4352
nickjillings@1541 4353 // Native handler
nickjillings@1541 4354 handle = ontype && cur[ ontype ];
nickjillings@1541 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nickjillings@1541 4356 event.result = handle.apply( cur, data );
nickjillings@1541 4357 if ( event.result === false ) {
nickjillings@1541 4358 event.preventDefault();
nickjillings@1541 4359 }
nickjillings@1541 4360 }
nickjillings@1541 4361 }
nickjillings@1541 4362 event.type = type;
nickjillings@1541 4363
nickjillings@1541 4364 // If nobody prevented the default action, do it now
nickjillings@1541 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nickjillings@1541 4366
nickjillings@1541 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nickjillings@1541 4368 jQuery.acceptData( elem ) ) {
nickjillings@1541 4369
nickjillings@1541 4370 // Call a native DOM method on the target with the same name name as the event.
nickjillings@1541 4371 // Don't do default actions on window, that's where global variables be (#6170)
nickjillings@1541 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nickjillings@1541 4373
nickjillings@1541 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nickjillings@1541 4375 tmp = elem[ ontype ];
nickjillings@1541 4376
nickjillings@1541 4377 if ( tmp ) {
nickjillings@1541 4378 elem[ ontype ] = null;
nickjillings@1541 4379 }
nickjillings@1541 4380
nickjillings@1541 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nickjillings@1541 4382 jQuery.event.triggered = type;
nickjillings@1541 4383 elem[ type ]();
nickjillings@1541 4384 jQuery.event.triggered = undefined;
nickjillings@1541 4385
nickjillings@1541 4386 if ( tmp ) {
nickjillings@1541 4387 elem[ ontype ] = tmp;
nickjillings@1541 4388 }
nickjillings@1541 4389 }
nickjillings@1541 4390 }
nickjillings@1541 4391 }
nickjillings@1541 4392
nickjillings@1541 4393 return event.result;
nickjillings@1541 4394 },
nickjillings@1541 4395
nickjillings@1541 4396 dispatch: function( event ) {
nickjillings@1541 4397
nickjillings@1541 4398 // Make a writable jQuery.Event from the native event object
nickjillings@1541 4399 event = jQuery.event.fix( event );
nickjillings@1541 4400
nickjillings@1541 4401 var i, j, ret, matched, handleObj,
nickjillings@1541 4402 handlerQueue = [],
nickjillings@1541 4403 args = slice.call( arguments ),
nickjillings@1541 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nickjillings@1541 4405 special = jQuery.event.special[ event.type ] || {};
nickjillings@1541 4406
nickjillings@1541 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nickjillings@1541 4408 args[0] = event;
nickjillings@1541 4409 event.delegateTarget = this;
nickjillings@1541 4410
nickjillings@1541 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nickjillings@1541 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nickjillings@1541 4413 return;
nickjillings@1541 4414 }
nickjillings@1541 4415
nickjillings@1541 4416 // Determine handlers
nickjillings@1541 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nickjillings@1541 4418
nickjillings@1541 4419 // Run delegates first; they may want to stop propagation beneath us
nickjillings@1541 4420 i = 0;
nickjillings@1541 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nickjillings@1541 4422 event.currentTarget = matched.elem;
nickjillings@1541 4423
nickjillings@1541 4424 j = 0;
nickjillings@1541 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nickjillings@1541 4426
nickjillings@1541 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nickjillings@1541 4428 // a subset or equal to those in the bound event (both can have no namespace).
nickjillings@1541 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nickjillings@1541 4430
nickjillings@1541 4431 event.handleObj = handleObj;
nickjillings@1541 4432 event.data = handleObj.data;
nickjillings@1541 4433
nickjillings@1541 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nickjillings@1541 4435 .apply( matched.elem, args );
nickjillings@1541 4436
nickjillings@1541 4437 if ( ret !== undefined ) {
nickjillings@1541 4438 if ( (event.result = ret) === false ) {
nickjillings@1541 4439 event.preventDefault();
nickjillings@1541 4440 event.stopPropagation();
nickjillings@1541 4441 }
nickjillings@1541 4442 }
nickjillings@1541 4443 }
nickjillings@1541 4444 }
nickjillings@1541 4445 }
nickjillings@1541 4446
nickjillings@1541 4447 // Call the postDispatch hook for the mapped type
nickjillings@1541 4448 if ( special.postDispatch ) {
nickjillings@1541 4449 special.postDispatch.call( this, event );
nickjillings@1541 4450 }
nickjillings@1541 4451
nickjillings@1541 4452 return event.result;
nickjillings@1541 4453 },
nickjillings@1541 4454
nickjillings@1541 4455 handlers: function( event, handlers ) {
nickjillings@1541 4456 var i, matches, sel, handleObj,
nickjillings@1541 4457 handlerQueue = [],
nickjillings@1541 4458 delegateCount = handlers.delegateCount,
nickjillings@1541 4459 cur = event.target;
nickjillings@1541 4460
nickjillings@1541 4461 // Find delegate handlers
nickjillings@1541 4462 // Black-hole SVG <use> instance trees (#13180)
nickjillings@1541 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nickjillings@1541 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nickjillings@1541 4465
nickjillings@1541 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nickjillings@1541 4467
nickjillings@1541 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nickjillings@1541 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nickjillings@1541 4470 matches = [];
nickjillings@1541 4471 for ( i = 0; i < delegateCount; i++ ) {
nickjillings@1541 4472 handleObj = handlers[ i ];
nickjillings@1541 4473
nickjillings@1541 4474 // Don't conflict with Object.prototype properties (#13203)
nickjillings@1541 4475 sel = handleObj.selector + " ";
nickjillings@1541 4476
nickjillings@1541 4477 if ( matches[ sel ] === undefined ) {
nickjillings@1541 4478 matches[ sel ] = handleObj.needsContext ?
nickjillings@1541 4479 jQuery( sel, this ).index( cur ) >= 0 :
nickjillings@1541 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nickjillings@1541 4481 }
nickjillings@1541 4482 if ( matches[ sel ] ) {
nickjillings@1541 4483 matches.push( handleObj );
nickjillings@1541 4484 }
nickjillings@1541 4485 }
nickjillings@1541 4486 if ( matches.length ) {
nickjillings@1541 4487 handlerQueue.push({ elem: cur, handlers: matches });
nickjillings@1541 4488 }
nickjillings@1541 4489 }
nickjillings@1541 4490 }
nickjillings@1541 4491 }
nickjillings@1541 4492
nickjillings@1541 4493 // Add the remaining (directly-bound) handlers
nickjillings@1541 4494 if ( delegateCount < handlers.length ) {
nickjillings@1541 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nickjillings@1541 4496 }
nickjillings@1541 4497
nickjillings@1541 4498 return handlerQueue;
nickjillings@1541 4499 },
nickjillings@1541 4500
nickjillings@1541 4501 // Includes some event props shared by KeyEvent and MouseEvent
nickjillings@1541 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nickjillings@1541 4503
nickjillings@1541 4504 fixHooks: {},
nickjillings@1541 4505
nickjillings@1541 4506 keyHooks: {
nickjillings@1541 4507 props: "char charCode key keyCode".split(" "),
nickjillings@1541 4508 filter: function( event, original ) {
nickjillings@1541 4509
nickjillings@1541 4510 // Add which for key events
nickjillings@1541 4511 if ( event.which == null ) {
nickjillings@1541 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nickjillings@1541 4513 }
nickjillings@1541 4514
nickjillings@1541 4515 return event;
nickjillings@1541 4516 }
nickjillings@1541 4517 },
nickjillings@1541 4518
nickjillings@1541 4519 mouseHooks: {
nickjillings@1541 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nickjillings@1541 4521 filter: function( event, original ) {
nickjillings@1541 4522 var eventDoc, doc, body,
nickjillings@1541 4523 button = original.button;
nickjillings@1541 4524
nickjillings@1541 4525 // Calculate pageX/Y if missing and clientX/Y available
nickjillings@1541 4526 if ( event.pageX == null && original.clientX != null ) {
nickjillings@1541 4527 eventDoc = event.target.ownerDocument || document;
nickjillings@1541 4528 doc = eventDoc.documentElement;
nickjillings@1541 4529 body = eventDoc.body;
nickjillings@1541 4530
nickjillings@1541 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nickjillings@1541 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nickjillings@1541 4533 }
nickjillings@1541 4534
nickjillings@1541 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nickjillings@1541 4536 // Note: button is not normalized, so don't use it
nickjillings@1541 4537 if ( !event.which && button !== undefined ) {
nickjillings@1541 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nickjillings@1541 4539 }
nickjillings@1541 4540
nickjillings@1541 4541 return event;
nickjillings@1541 4542 }
nickjillings@1541 4543 },
nickjillings@1541 4544
nickjillings@1541 4545 fix: function( event ) {
nickjillings@1541 4546 if ( event[ jQuery.expando ] ) {
nickjillings@1541 4547 return event;
nickjillings@1541 4548 }
nickjillings@1541 4549
nickjillings@1541 4550 // Create a writable copy of the event object and normalize some properties
nickjillings@1541 4551 var i, prop, copy,
nickjillings@1541 4552 type = event.type,
nickjillings@1541 4553 originalEvent = event,
nickjillings@1541 4554 fixHook = this.fixHooks[ type ];
nickjillings@1541 4555
nickjillings@1541 4556 if ( !fixHook ) {
nickjillings@1541 4557 this.fixHooks[ type ] = fixHook =
nickjillings@1541 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nickjillings@1541 4559 rkeyEvent.test( type ) ? this.keyHooks :
nickjillings@1541 4560 {};
nickjillings@1541 4561 }
nickjillings@1541 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nickjillings@1541 4563
nickjillings@1541 4564 event = new jQuery.Event( originalEvent );
nickjillings@1541 4565
nickjillings@1541 4566 i = copy.length;
nickjillings@1541 4567 while ( i-- ) {
nickjillings@1541 4568 prop = copy[ i ];
nickjillings@1541 4569 event[ prop ] = originalEvent[ prop ];
nickjillings@1541 4570 }
nickjillings@1541 4571
nickjillings@1541 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nickjillings@1541 4573 // All events should have a target; Cordova deviceready doesn't
nickjillings@1541 4574 if ( !event.target ) {
nickjillings@1541 4575 event.target = document;
nickjillings@1541 4576 }
nickjillings@1541 4577
nickjillings@1541 4578 // Support: Safari 6.0+, Chrome<28
nickjillings@1541 4579 // Target should not be a text node (#504, #13143)
nickjillings@1541 4580 if ( event.target.nodeType === 3 ) {
nickjillings@1541 4581 event.target = event.target.parentNode;
nickjillings@1541 4582 }
nickjillings@1541 4583
nickjillings@1541 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nickjillings@1541 4585 },
nickjillings@1541 4586
nickjillings@1541 4587 special: {
nickjillings@1541 4588 load: {
nickjillings@1541 4589 // Prevent triggered image.load events from bubbling to window.load
nickjillings@1541 4590 noBubble: true
nickjillings@1541 4591 },
nickjillings@1541 4592 focus: {
nickjillings@1541 4593 // Fire native event if possible so blur/focus sequence is correct
nickjillings@1541 4594 trigger: function() {
nickjillings@1541 4595 if ( this !== safeActiveElement() && this.focus ) {
nickjillings@1541 4596 this.focus();
nickjillings@1541 4597 return false;
nickjillings@1541 4598 }
nickjillings@1541 4599 },
nickjillings@1541 4600 delegateType: "focusin"
nickjillings@1541 4601 },
nickjillings@1541 4602 blur: {
nickjillings@1541 4603 trigger: function() {
nickjillings@1541 4604 if ( this === safeActiveElement() && this.blur ) {
nickjillings@1541 4605 this.blur();
nickjillings@1541 4606 return false;
nickjillings@1541 4607 }
nickjillings@1541 4608 },
nickjillings@1541 4609 delegateType: "focusout"
nickjillings@1541 4610 },
nickjillings@1541 4611 click: {
nickjillings@1541 4612 // For checkbox, fire native event so checked state will be right
nickjillings@1541 4613 trigger: function() {
nickjillings@1541 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nickjillings@1541 4615 this.click();
nickjillings@1541 4616 return false;
nickjillings@1541 4617 }
nickjillings@1541 4618 },
nickjillings@1541 4619
nickjillings@1541 4620 // For cross-browser consistency, don't fire native .click() on links
nickjillings@1541 4621 _default: function( event ) {
nickjillings@1541 4622 return jQuery.nodeName( event.target, "a" );
nickjillings@1541 4623 }
nickjillings@1541 4624 },
nickjillings@1541 4625
nickjillings@1541 4626 beforeunload: {
nickjillings@1541 4627 postDispatch: function( event ) {
nickjillings@1541 4628
nickjillings@1541 4629 // Support: Firefox 20+
nickjillings@1541 4630 // Firefox doesn't alert if the returnValue field is not set.
nickjillings@1541 4631 if ( event.result !== undefined && event.originalEvent ) {
nickjillings@1541 4632 event.originalEvent.returnValue = event.result;
nickjillings@1541 4633 }
nickjillings@1541 4634 }
nickjillings@1541 4635 }
nickjillings@1541 4636 },
nickjillings@1541 4637
nickjillings@1541 4638 simulate: function( type, elem, event, bubble ) {
nickjillings@1541 4639 // Piggyback on a donor event to simulate a different one.
nickjillings@1541 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nickjillings@1541 4641 // simulated event prevents default then we do the same on the donor.
nickjillings@1541 4642 var e = jQuery.extend(
nickjillings@1541 4643 new jQuery.Event(),
nickjillings@1541 4644 event,
nickjillings@1541 4645 {
nickjillings@1541 4646 type: type,
nickjillings@1541 4647 isSimulated: true,
nickjillings@1541 4648 originalEvent: {}
nickjillings@1541 4649 }
nickjillings@1541 4650 );
nickjillings@1541 4651 if ( bubble ) {
nickjillings@1541 4652 jQuery.event.trigger( e, null, elem );
nickjillings@1541 4653 } else {
nickjillings@1541 4654 jQuery.event.dispatch.call( elem, e );
nickjillings@1541 4655 }
nickjillings@1541 4656 if ( e.isDefaultPrevented() ) {
nickjillings@1541 4657 event.preventDefault();
nickjillings@1541 4658 }
nickjillings@1541 4659 }
nickjillings@1541 4660 };
nickjillings@1541 4661
nickjillings@1541 4662 jQuery.removeEvent = function( elem, type, handle ) {
nickjillings@1541 4663 if ( elem.removeEventListener ) {
nickjillings@1541 4664 elem.removeEventListener( type, handle, false );
nickjillings@1541 4665 }
nickjillings@1541 4666 };
nickjillings@1541 4667
nickjillings@1541 4668 jQuery.Event = function( src, props ) {
nickjillings@1541 4669 // Allow instantiation without the 'new' keyword
nickjillings@1541 4670 if ( !(this instanceof jQuery.Event) ) {
nickjillings@1541 4671 return new jQuery.Event( src, props );
nickjillings@1541 4672 }
nickjillings@1541 4673
nickjillings@1541 4674 // Event object
nickjillings@1541 4675 if ( src && src.type ) {
nickjillings@1541 4676 this.originalEvent = src;
nickjillings@1541 4677 this.type = src.type;
nickjillings@1541 4678
nickjillings@1541 4679 // Events bubbling up the document may have been marked as prevented
nickjillings@1541 4680 // by a handler lower down the tree; reflect the correct value.
nickjillings@1541 4681 this.isDefaultPrevented = src.defaultPrevented ||
nickjillings@1541 4682 src.defaultPrevented === undefined &&
nickjillings@1541 4683 // Support: Android<4.0
nickjillings@1541 4684 src.returnValue === false ?
nickjillings@1541 4685 returnTrue :
nickjillings@1541 4686 returnFalse;
nickjillings@1541 4687
nickjillings@1541 4688 // Event type
nickjillings@1541 4689 } else {
nickjillings@1541 4690 this.type = src;
nickjillings@1541 4691 }
nickjillings@1541 4692
nickjillings@1541 4693 // Put explicitly provided properties onto the event object
nickjillings@1541 4694 if ( props ) {
nickjillings@1541 4695 jQuery.extend( this, props );
nickjillings@1541 4696 }
nickjillings@1541 4697
nickjillings@1541 4698 // Create a timestamp if incoming event doesn't have one
nickjillings@1541 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nickjillings@1541 4700
nickjillings@1541 4701 // Mark it as fixed
nickjillings@1541 4702 this[ jQuery.expando ] = true;
nickjillings@1541 4703 };
nickjillings@1541 4704
nickjillings@1541 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nickjillings@1541 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nickjillings@1541 4707 jQuery.Event.prototype = {
nickjillings@1541 4708 isDefaultPrevented: returnFalse,
nickjillings@1541 4709 isPropagationStopped: returnFalse,
nickjillings@1541 4710 isImmediatePropagationStopped: returnFalse,
nickjillings@1541 4711
nickjillings@1541 4712 preventDefault: function() {
nickjillings@1541 4713 var e = this.originalEvent;
nickjillings@1541 4714
nickjillings@1541 4715 this.isDefaultPrevented = returnTrue;
nickjillings@1541 4716
nickjillings@1541 4717 if ( e && e.preventDefault ) {
nickjillings@1541 4718 e.preventDefault();
nickjillings@1541 4719 }
nickjillings@1541 4720 },
nickjillings@1541 4721 stopPropagation: function() {
nickjillings@1541 4722 var e = this.originalEvent;
nickjillings@1541 4723
nickjillings@1541 4724 this.isPropagationStopped = returnTrue;
nickjillings@1541 4725
nickjillings@1541 4726 if ( e && e.stopPropagation ) {
nickjillings@1541 4727 e.stopPropagation();
nickjillings@1541 4728 }
nickjillings@1541 4729 },
nickjillings@1541 4730 stopImmediatePropagation: function() {
nickjillings@1541 4731 var e = this.originalEvent;
nickjillings@1541 4732
nickjillings@1541 4733 this.isImmediatePropagationStopped = returnTrue;
nickjillings@1541 4734
nickjillings@1541 4735 if ( e && e.stopImmediatePropagation ) {
nickjillings@1541 4736 e.stopImmediatePropagation();
nickjillings@1541 4737 }
nickjillings@1541 4738
nickjillings@1541 4739 this.stopPropagation();
nickjillings@1541 4740 }
nickjillings@1541 4741 };
nickjillings@1541 4742
nickjillings@1541 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nickjillings@1541 4744 // Support: Chrome 15+
nickjillings@1541 4745 jQuery.each({
nickjillings@1541 4746 mouseenter: "mouseover",
nickjillings@1541 4747 mouseleave: "mouseout",
nickjillings@1541 4748 pointerenter: "pointerover",
nickjillings@1541 4749 pointerleave: "pointerout"
nickjillings@1541 4750 }, function( orig, fix ) {
nickjillings@1541 4751 jQuery.event.special[ orig ] = {
nickjillings@1541 4752 delegateType: fix,
nickjillings@1541 4753 bindType: fix,
nickjillings@1541 4754
nickjillings@1541 4755 handle: function( event ) {
nickjillings@1541 4756 var ret,
nickjillings@1541 4757 target = this,
nickjillings@1541 4758 related = event.relatedTarget,
nickjillings@1541 4759 handleObj = event.handleObj;
nickjillings@1541 4760
nickjillings@1541 4761 // For mousenter/leave call the handler if related is outside the target.
nickjillings@1541 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nickjillings@1541 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nickjillings@1541 4764 event.type = handleObj.origType;
nickjillings@1541 4765 ret = handleObj.handler.apply( this, arguments );
nickjillings@1541 4766 event.type = fix;
nickjillings@1541 4767 }
nickjillings@1541 4768 return ret;
nickjillings@1541 4769 }
nickjillings@1541 4770 };
nickjillings@1541 4771 });
nickjillings@1541 4772
nickjillings@1541 4773 // Support: Firefox, Chrome, Safari
nickjillings@1541 4774 // Create "bubbling" focus and blur events
nickjillings@1541 4775 if ( !support.focusinBubbles ) {
nickjillings@1541 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nickjillings@1541 4777
nickjillings@1541 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nickjillings@1541 4779 var handler = function( event ) {
nickjillings@1541 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nickjillings@1541 4781 };
nickjillings@1541 4782
nickjillings@1541 4783 jQuery.event.special[ fix ] = {
nickjillings@1541 4784 setup: function() {
nickjillings@1541 4785 var doc = this.ownerDocument || this,
nickjillings@1541 4786 attaches = data_priv.access( doc, fix );
nickjillings@1541 4787
nickjillings@1541 4788 if ( !attaches ) {
nickjillings@1541 4789 doc.addEventListener( orig, handler, true );
nickjillings@1541 4790 }
nickjillings@1541 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nickjillings@1541 4792 },
nickjillings@1541 4793 teardown: function() {
nickjillings@1541 4794 var doc = this.ownerDocument || this,
nickjillings@1541 4795 attaches = data_priv.access( doc, fix ) - 1;
nickjillings@1541 4796
nickjillings@1541 4797 if ( !attaches ) {
nickjillings@1541 4798 doc.removeEventListener( orig, handler, true );
nickjillings@1541 4799 data_priv.remove( doc, fix );
nickjillings@1541 4800
nickjillings@1541 4801 } else {
nickjillings@1541 4802 data_priv.access( doc, fix, attaches );
nickjillings@1541 4803 }
nickjillings@1541 4804 }
nickjillings@1541 4805 };
nickjillings@1541 4806 });
nickjillings@1541 4807 }
nickjillings@1541 4808
nickjillings@1541 4809 jQuery.fn.extend({
nickjillings@1541 4810
nickjillings@1541 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nickjillings@1541 4812 var origFn, type;
nickjillings@1541 4813
nickjillings@1541 4814 // Types can be a map of types/handlers
nickjillings@1541 4815 if ( typeof types === "object" ) {
nickjillings@1541 4816 // ( types-Object, selector, data )
nickjillings@1541 4817 if ( typeof selector !== "string" ) {
nickjillings@1541 4818 // ( types-Object, data )
nickjillings@1541 4819 data = data || selector;
nickjillings@1541 4820 selector = undefined;
nickjillings@1541 4821 }
nickjillings@1541 4822 for ( type in types ) {
nickjillings@1541 4823 this.on( type, selector, data, types[ type ], one );
nickjillings@1541 4824 }
nickjillings@1541 4825 return this;
nickjillings@1541 4826 }
nickjillings@1541 4827
nickjillings@1541 4828 if ( data == null && fn == null ) {
nickjillings@1541 4829 // ( types, fn )
nickjillings@1541 4830 fn = selector;
nickjillings@1541 4831 data = selector = undefined;
nickjillings@1541 4832 } else if ( fn == null ) {
nickjillings@1541 4833 if ( typeof selector === "string" ) {
nickjillings@1541 4834 // ( types, selector, fn )
nickjillings@1541 4835 fn = data;
nickjillings@1541 4836 data = undefined;
nickjillings@1541 4837 } else {
nickjillings@1541 4838 // ( types, data, fn )
nickjillings@1541 4839 fn = data;
nickjillings@1541 4840 data = selector;
nickjillings@1541 4841 selector = undefined;
nickjillings@1541 4842 }
nickjillings@1541 4843 }
nickjillings@1541 4844 if ( fn === false ) {
nickjillings@1541 4845 fn = returnFalse;
nickjillings@1541 4846 } else if ( !fn ) {
nickjillings@1541 4847 return this;
nickjillings@1541 4848 }
nickjillings@1541 4849
nickjillings@1541 4850 if ( one === 1 ) {
nickjillings@1541 4851 origFn = fn;
nickjillings@1541 4852 fn = function( event ) {
nickjillings@1541 4853 // Can use an empty set, since event contains the info
nickjillings@1541 4854 jQuery().off( event );
nickjillings@1541 4855 return origFn.apply( this, arguments );
nickjillings@1541 4856 };
nickjillings@1541 4857 // Use same guid so caller can remove using origFn
nickjillings@1541 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nickjillings@1541 4859 }
nickjillings@1541 4860 return this.each( function() {
nickjillings@1541 4861 jQuery.event.add( this, types, fn, data, selector );
nickjillings@1541 4862 });
nickjillings@1541 4863 },
nickjillings@1541 4864 one: function( types, selector, data, fn ) {
nickjillings@1541 4865 return this.on( types, selector, data, fn, 1 );
nickjillings@1541 4866 },
nickjillings@1541 4867 off: function( types, selector, fn ) {
nickjillings@1541 4868 var handleObj, type;
nickjillings@1541 4869 if ( types && types.preventDefault && types.handleObj ) {
nickjillings@1541 4870 // ( event ) dispatched jQuery.Event
nickjillings@1541 4871 handleObj = types.handleObj;
nickjillings@1541 4872 jQuery( types.delegateTarget ).off(
nickjillings@1541 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nickjillings@1541 4874 handleObj.selector,
nickjillings@1541 4875 handleObj.handler
nickjillings@1541 4876 );
nickjillings@1541 4877 return this;
nickjillings@1541 4878 }
nickjillings@1541 4879 if ( typeof types === "object" ) {
nickjillings@1541 4880 // ( types-object [, selector] )
nickjillings@1541 4881 for ( type in types ) {
nickjillings@1541 4882 this.off( type, selector, types[ type ] );
nickjillings@1541 4883 }
nickjillings@1541 4884 return this;
nickjillings@1541 4885 }
nickjillings@1541 4886 if ( selector === false || typeof selector === "function" ) {
nickjillings@1541 4887 // ( types [, fn] )
nickjillings@1541 4888 fn = selector;
nickjillings@1541 4889 selector = undefined;
nickjillings@1541 4890 }
nickjillings@1541 4891 if ( fn === false ) {
nickjillings@1541 4892 fn = returnFalse;
nickjillings@1541 4893 }
nickjillings@1541 4894 return this.each(function() {
nickjillings@1541 4895 jQuery.event.remove( this, types, fn, selector );
nickjillings@1541 4896 });
nickjillings@1541 4897 },
nickjillings@1541 4898
nickjillings@1541 4899 trigger: function( type, data ) {
nickjillings@1541 4900 return this.each(function() {
nickjillings@1541 4901 jQuery.event.trigger( type, data, this );
nickjillings@1541 4902 });
nickjillings@1541 4903 },
nickjillings@1541 4904 triggerHandler: function( type, data ) {
nickjillings@1541 4905 var elem = this[0];
nickjillings@1541 4906 if ( elem ) {
nickjillings@1541 4907 return jQuery.event.trigger( type, data, elem, true );
nickjillings@1541 4908 }
nickjillings@1541 4909 }
nickjillings@1541 4910 });
nickjillings@1541 4911
nickjillings@1541 4912
nickjillings@1541 4913 var
nickjillings@1541 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nickjillings@1541 4915 rtagName = /<([\w:]+)/,
nickjillings@1541 4916 rhtml = /<|&#?\w+;/,
nickjillings@1541 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nickjillings@1541 4918 // checked="checked" or checked
nickjillings@1541 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nickjillings@1541 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nickjillings@1541 4921 rscriptTypeMasked = /^true\/(.*)/,
nickjillings@1541 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nickjillings@1541 4923
nickjillings@1541 4924 // We have to close these tags to support XHTML (#13200)
nickjillings@1541 4925 wrapMap = {
nickjillings@1541 4926
nickjillings@1541 4927 // Support: IE9
nickjillings@1541 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nickjillings@1541 4929
nickjillings@1541 4930 thead: [ 1, "<table>", "</table>" ],
nickjillings@1541 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nickjillings@1541 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nickjillings@1541 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nickjillings@1541 4934
nickjillings@1541 4935 _default: [ 0, "", "" ]
nickjillings@1541 4936 };
nickjillings@1541 4937
nickjillings@1541 4938 // Support: IE9
nickjillings@1541 4939 wrapMap.optgroup = wrapMap.option;
nickjillings@1541 4940
nickjillings@1541 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nickjillings@1541 4942 wrapMap.th = wrapMap.td;
nickjillings@1541 4943
nickjillings@1541 4944 // Support: 1.x compatibility
nickjillings@1541 4945 // Manipulating tables requires a tbody
nickjillings@1541 4946 function manipulationTarget( elem, content ) {
nickjillings@1541 4947 return jQuery.nodeName( elem, "table" ) &&
nickjillings@1541 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nickjillings@1541 4949
nickjillings@1541 4950 elem.getElementsByTagName("tbody")[0] ||
nickjillings@1541 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nickjillings@1541 4952 elem;
nickjillings@1541 4953 }
nickjillings@1541 4954
nickjillings@1541 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nickjillings@1541 4956 function disableScript( elem ) {
nickjillings@1541 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nickjillings@1541 4958 return elem;
nickjillings@1541 4959 }
nickjillings@1541 4960 function restoreScript( elem ) {
nickjillings@1541 4961 var match = rscriptTypeMasked.exec( elem.type );
nickjillings@1541 4962
nickjillings@1541 4963 if ( match ) {
nickjillings@1541 4964 elem.type = match[ 1 ];
nickjillings@1541 4965 } else {
nickjillings@1541 4966 elem.removeAttribute("type");
nickjillings@1541 4967 }
nickjillings@1541 4968
nickjillings@1541 4969 return elem;
nickjillings@1541 4970 }
nickjillings@1541 4971
nickjillings@1541 4972 // Mark scripts as having already been evaluated
nickjillings@1541 4973 function setGlobalEval( elems, refElements ) {
nickjillings@1541 4974 var i = 0,
nickjillings@1541 4975 l = elems.length;
nickjillings@1541 4976
nickjillings@1541 4977 for ( ; i < l; i++ ) {
nickjillings@1541 4978 data_priv.set(
nickjillings@1541 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nickjillings@1541 4980 );
nickjillings@1541 4981 }
nickjillings@1541 4982 }
nickjillings@1541 4983
nickjillings@1541 4984 function cloneCopyEvent( src, dest ) {
nickjillings@1541 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nickjillings@1541 4986
nickjillings@1541 4987 if ( dest.nodeType !== 1 ) {
nickjillings@1541 4988 return;
nickjillings@1541 4989 }
nickjillings@1541 4990
nickjillings@1541 4991 // 1. Copy private data: events, handlers, etc.
nickjillings@1541 4992 if ( data_priv.hasData( src ) ) {
nickjillings@1541 4993 pdataOld = data_priv.access( src );
nickjillings@1541 4994 pdataCur = data_priv.set( dest, pdataOld );
nickjillings@1541 4995 events = pdataOld.events;
nickjillings@1541 4996
nickjillings@1541 4997 if ( events ) {
nickjillings@1541 4998 delete pdataCur.handle;
nickjillings@1541 4999 pdataCur.events = {};
nickjillings@1541 5000
nickjillings@1541 5001 for ( type in events ) {
nickjillings@1541 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nickjillings@1541 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nickjillings@1541 5004 }
nickjillings@1541 5005 }
nickjillings@1541 5006 }
nickjillings@1541 5007 }
nickjillings@1541 5008
nickjillings@1541 5009 // 2. Copy user data
nickjillings@1541 5010 if ( data_user.hasData( src ) ) {
nickjillings@1541 5011 udataOld = data_user.access( src );
nickjillings@1541 5012 udataCur = jQuery.extend( {}, udataOld );
nickjillings@1541 5013
nickjillings@1541 5014 data_user.set( dest, udataCur );
nickjillings@1541 5015 }
nickjillings@1541 5016 }
nickjillings@1541 5017
nickjillings@1541 5018 function getAll( context, tag ) {
nickjillings@1541 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nickjillings@1541 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nickjillings@1541 5021 [];
nickjillings@1541 5022
nickjillings@1541 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nickjillings@1541 5024 jQuery.merge( [ context ], ret ) :
nickjillings@1541 5025 ret;
nickjillings@1541 5026 }
nickjillings@1541 5027
nickjillings@1541 5028 // Fix IE bugs, see support tests
nickjillings@1541 5029 function fixInput( src, dest ) {
nickjillings@1541 5030 var nodeName = dest.nodeName.toLowerCase();
nickjillings@1541 5031
nickjillings@1541 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nickjillings@1541 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nickjillings@1541 5034 dest.checked = src.checked;
nickjillings@1541 5035
nickjillings@1541 5036 // Fails to return the selected option to the default selected state when cloning options
nickjillings@1541 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nickjillings@1541 5038 dest.defaultValue = src.defaultValue;
nickjillings@1541 5039 }
nickjillings@1541 5040 }
nickjillings@1541 5041
nickjillings@1541 5042 jQuery.extend({
nickjillings@1541 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nickjillings@1541 5044 var i, l, srcElements, destElements,
nickjillings@1541 5045 clone = elem.cloneNode( true ),
nickjillings@1541 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1541 5047
nickjillings@1541 5048 // Fix IE cloning issues
nickjillings@1541 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nickjillings@1541 5050 !jQuery.isXMLDoc( elem ) ) {
nickjillings@1541 5051
nickjillings@1541 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nickjillings@1541 5053 destElements = getAll( clone );
nickjillings@1541 5054 srcElements = getAll( elem );
nickjillings@1541 5055
nickjillings@1541 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1541 5057 fixInput( srcElements[ i ], destElements[ i ] );
nickjillings@1541 5058 }
nickjillings@1541 5059 }
nickjillings@1541 5060
nickjillings@1541 5061 // Copy the events from the original to the clone
nickjillings@1541 5062 if ( dataAndEvents ) {
nickjillings@1541 5063 if ( deepDataAndEvents ) {
nickjillings@1541 5064 srcElements = srcElements || getAll( elem );
nickjillings@1541 5065 destElements = destElements || getAll( clone );
nickjillings@1541 5066
nickjillings@1541 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1541 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nickjillings@1541 5069 }
nickjillings@1541 5070 } else {
nickjillings@1541 5071 cloneCopyEvent( elem, clone );
nickjillings@1541 5072 }
nickjillings@1541 5073 }
nickjillings@1541 5074
nickjillings@1541 5075 // Preserve script evaluation history
nickjillings@1541 5076 destElements = getAll( clone, "script" );
nickjillings@1541 5077 if ( destElements.length > 0 ) {
nickjillings@1541 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nickjillings@1541 5079 }
nickjillings@1541 5080
nickjillings@1541 5081 // Return the cloned set
nickjillings@1541 5082 return clone;
nickjillings@1541 5083 },
nickjillings@1541 5084
nickjillings@1541 5085 buildFragment: function( elems, context, scripts, selection ) {
nickjillings@1541 5086 var elem, tmp, tag, wrap, contains, j,
nickjillings@1541 5087 fragment = context.createDocumentFragment(),
nickjillings@1541 5088 nodes = [],
nickjillings@1541 5089 i = 0,
nickjillings@1541 5090 l = elems.length;
nickjillings@1541 5091
nickjillings@1541 5092 for ( ; i < l; i++ ) {
nickjillings@1541 5093 elem = elems[ i ];
nickjillings@1541 5094
nickjillings@1541 5095 if ( elem || elem === 0 ) {
nickjillings@1541 5096
nickjillings@1541 5097 // Add nodes directly
nickjillings@1541 5098 if ( jQuery.type( elem ) === "object" ) {
nickjillings@1541 5099 // Support: QtWebKit, PhantomJS
nickjillings@1541 5100 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1541 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nickjillings@1541 5102
nickjillings@1541 5103 // Convert non-html into a text node
nickjillings@1541 5104 } else if ( !rhtml.test( elem ) ) {
nickjillings@1541 5105 nodes.push( context.createTextNode( elem ) );
nickjillings@1541 5106
nickjillings@1541 5107 // Convert html into DOM nodes
nickjillings@1541 5108 } else {
nickjillings@1541 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nickjillings@1541 5110
nickjillings@1541 5111 // Deserialize a standard representation
nickjillings@1541 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nickjillings@1541 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nickjillings@1541 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nickjillings@1541 5115
nickjillings@1541 5116 // Descend through wrappers to the right content
nickjillings@1541 5117 j = wrap[ 0 ];
nickjillings@1541 5118 while ( j-- ) {
nickjillings@1541 5119 tmp = tmp.lastChild;
nickjillings@1541 5120 }
nickjillings@1541 5121
nickjillings@1541 5122 // Support: QtWebKit, PhantomJS
nickjillings@1541 5123 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1541 5124 jQuery.merge( nodes, tmp.childNodes );
nickjillings@1541 5125
nickjillings@1541 5126 // Remember the top-level container
nickjillings@1541 5127 tmp = fragment.firstChild;
nickjillings@1541 5128
nickjillings@1541 5129 // Ensure the created nodes are orphaned (#12392)
nickjillings@1541 5130 tmp.textContent = "";
nickjillings@1541 5131 }
nickjillings@1541 5132 }
nickjillings@1541 5133 }
nickjillings@1541 5134
nickjillings@1541 5135 // Remove wrapper from fragment
nickjillings@1541 5136 fragment.textContent = "";
nickjillings@1541 5137
nickjillings@1541 5138 i = 0;
nickjillings@1541 5139 while ( (elem = nodes[ i++ ]) ) {
nickjillings@1541 5140
nickjillings@1541 5141 // #4087 - If origin and destination elements are the same, and this is
nickjillings@1541 5142 // that element, do not do anything
nickjillings@1541 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nickjillings@1541 5144 continue;
nickjillings@1541 5145 }
nickjillings@1541 5146
nickjillings@1541 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1541 5148
nickjillings@1541 5149 // Append to fragment
nickjillings@1541 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nickjillings@1541 5151
nickjillings@1541 5152 // Preserve script evaluation history
nickjillings@1541 5153 if ( contains ) {
nickjillings@1541 5154 setGlobalEval( tmp );
nickjillings@1541 5155 }
nickjillings@1541 5156
nickjillings@1541 5157 // Capture executables
nickjillings@1541 5158 if ( scripts ) {
nickjillings@1541 5159 j = 0;
nickjillings@1541 5160 while ( (elem = tmp[ j++ ]) ) {
nickjillings@1541 5161 if ( rscriptType.test( elem.type || "" ) ) {
nickjillings@1541 5162 scripts.push( elem );
nickjillings@1541 5163 }
nickjillings@1541 5164 }
nickjillings@1541 5165 }
nickjillings@1541 5166 }
nickjillings@1541 5167
nickjillings@1541 5168 return fragment;
nickjillings@1541 5169 },
nickjillings@1541 5170
nickjillings@1541 5171 cleanData: function( elems ) {
nickjillings@1541 5172 var data, elem, type, key,
nickjillings@1541 5173 special = jQuery.event.special,
nickjillings@1541 5174 i = 0;
nickjillings@1541 5175
nickjillings@1541 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nickjillings@1541 5177 if ( jQuery.acceptData( elem ) ) {
nickjillings@1541 5178 key = elem[ data_priv.expando ];
nickjillings@1541 5179
nickjillings@1541 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nickjillings@1541 5181 if ( data.events ) {
nickjillings@1541 5182 for ( type in data.events ) {
nickjillings@1541 5183 if ( special[ type ] ) {
nickjillings@1541 5184 jQuery.event.remove( elem, type );
nickjillings@1541 5185
nickjillings@1541 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nickjillings@1541 5187 } else {
nickjillings@1541 5188 jQuery.removeEvent( elem, type, data.handle );
nickjillings@1541 5189 }
nickjillings@1541 5190 }
nickjillings@1541 5191 }
nickjillings@1541 5192 if ( data_priv.cache[ key ] ) {
nickjillings@1541 5193 // Discard any remaining `private` data
nickjillings@1541 5194 delete data_priv.cache[ key ];
nickjillings@1541 5195 }
nickjillings@1541 5196 }
nickjillings@1541 5197 }
nickjillings@1541 5198 // Discard any remaining `user` data
nickjillings@1541 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nickjillings@1541 5200 }
nickjillings@1541 5201 }
nickjillings@1541 5202 });
nickjillings@1541 5203
nickjillings@1541 5204 jQuery.fn.extend({
nickjillings@1541 5205 text: function( value ) {
nickjillings@1541 5206 return access( this, function( value ) {
nickjillings@1541 5207 return value === undefined ?
nickjillings@1541 5208 jQuery.text( this ) :
nickjillings@1541 5209 this.empty().each(function() {
nickjillings@1541 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1541 5211 this.textContent = value;
nickjillings@1541 5212 }
nickjillings@1541 5213 });
nickjillings@1541 5214 }, null, value, arguments.length );
nickjillings@1541 5215 },
nickjillings@1541 5216
nickjillings@1541 5217 append: function() {
nickjillings@1541 5218 return this.domManip( arguments, function( elem ) {
nickjillings@1541 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1541 5220 var target = manipulationTarget( this, elem );
nickjillings@1541 5221 target.appendChild( elem );
nickjillings@1541 5222 }
nickjillings@1541 5223 });
nickjillings@1541 5224 },
nickjillings@1541 5225
nickjillings@1541 5226 prepend: function() {
nickjillings@1541 5227 return this.domManip( arguments, function( elem ) {
nickjillings@1541 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1541 5229 var target = manipulationTarget( this, elem );
nickjillings@1541 5230 target.insertBefore( elem, target.firstChild );
nickjillings@1541 5231 }
nickjillings@1541 5232 });
nickjillings@1541 5233 },
nickjillings@1541 5234
nickjillings@1541 5235 before: function() {
nickjillings@1541 5236 return this.domManip( arguments, function( elem ) {
nickjillings@1541 5237 if ( this.parentNode ) {
nickjillings@1541 5238 this.parentNode.insertBefore( elem, this );
nickjillings@1541 5239 }
nickjillings@1541 5240 });
nickjillings@1541 5241 },
nickjillings@1541 5242
nickjillings@1541 5243 after: function() {
nickjillings@1541 5244 return this.domManip( arguments, function( elem ) {
nickjillings@1541 5245 if ( this.parentNode ) {
nickjillings@1541 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nickjillings@1541 5247 }
nickjillings@1541 5248 });
nickjillings@1541 5249 },
nickjillings@1541 5250
nickjillings@1541 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nickjillings@1541 5252 var elem,
nickjillings@1541 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nickjillings@1541 5254 i = 0;
nickjillings@1541 5255
nickjillings@1541 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nickjillings@1541 5257 if ( !keepData && elem.nodeType === 1 ) {
nickjillings@1541 5258 jQuery.cleanData( getAll( elem ) );
nickjillings@1541 5259 }
nickjillings@1541 5260
nickjillings@1541 5261 if ( elem.parentNode ) {
nickjillings@1541 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1541 5263 setGlobalEval( getAll( elem, "script" ) );
nickjillings@1541 5264 }
nickjillings@1541 5265 elem.parentNode.removeChild( elem );
nickjillings@1541 5266 }
nickjillings@1541 5267 }
nickjillings@1541 5268
nickjillings@1541 5269 return this;
nickjillings@1541 5270 },
nickjillings@1541 5271
nickjillings@1541 5272 empty: function() {
nickjillings@1541 5273 var elem,
nickjillings@1541 5274 i = 0;
nickjillings@1541 5275
nickjillings@1541 5276 for ( ; (elem = this[i]) != null; i++ ) {
nickjillings@1541 5277 if ( elem.nodeType === 1 ) {
nickjillings@1541 5278
nickjillings@1541 5279 // Prevent memory leaks
nickjillings@1541 5280 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1541 5281
nickjillings@1541 5282 // Remove any remaining nodes
nickjillings@1541 5283 elem.textContent = "";
nickjillings@1541 5284 }
nickjillings@1541 5285 }
nickjillings@1541 5286
nickjillings@1541 5287 return this;
nickjillings@1541 5288 },
nickjillings@1541 5289
nickjillings@1541 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nickjillings@1541 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nickjillings@1541 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nickjillings@1541 5293
nickjillings@1541 5294 return this.map(function() {
nickjillings@1541 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nickjillings@1541 5296 });
nickjillings@1541 5297 },
nickjillings@1541 5298
nickjillings@1541 5299 html: function( value ) {
nickjillings@1541 5300 return access( this, function( value ) {
nickjillings@1541 5301 var elem = this[ 0 ] || {},
nickjillings@1541 5302 i = 0,
nickjillings@1541 5303 l = this.length;
nickjillings@1541 5304
nickjillings@1541 5305 if ( value === undefined && elem.nodeType === 1 ) {
nickjillings@1541 5306 return elem.innerHTML;
nickjillings@1541 5307 }
nickjillings@1541 5308
nickjillings@1541 5309 // See if we can take a shortcut and just use innerHTML
nickjillings@1541 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nickjillings@1541 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nickjillings@1541 5312
nickjillings@1541 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nickjillings@1541 5314
nickjillings@1541 5315 try {
nickjillings@1541 5316 for ( ; i < l; i++ ) {
nickjillings@1541 5317 elem = this[ i ] || {};
nickjillings@1541 5318
nickjillings@1541 5319 // Remove element nodes and prevent memory leaks
nickjillings@1541 5320 if ( elem.nodeType === 1 ) {
nickjillings@1541 5321 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1541 5322 elem.innerHTML = value;
nickjillings@1541 5323 }
nickjillings@1541 5324 }
nickjillings@1541 5325
nickjillings@1541 5326 elem = 0;
nickjillings@1541 5327
nickjillings@1541 5328 // If using innerHTML throws an exception, use the fallback method
nickjillings@1541 5329 } catch( e ) {}
nickjillings@1541 5330 }
nickjillings@1541 5331
nickjillings@1541 5332 if ( elem ) {
nickjillings@1541 5333 this.empty().append( value );
nickjillings@1541 5334 }
nickjillings@1541 5335 }, null, value, arguments.length );
nickjillings@1541 5336 },
nickjillings@1541 5337
nickjillings@1541 5338 replaceWith: function() {
nickjillings@1541 5339 var arg = arguments[ 0 ];
nickjillings@1541 5340
nickjillings@1541 5341 // Make the changes, replacing each context element with the new content
nickjillings@1541 5342 this.domManip( arguments, function( elem ) {
nickjillings@1541 5343 arg = this.parentNode;
nickjillings@1541 5344
nickjillings@1541 5345 jQuery.cleanData( getAll( this ) );
nickjillings@1541 5346
nickjillings@1541 5347 if ( arg ) {
nickjillings@1541 5348 arg.replaceChild( elem, this );
nickjillings@1541 5349 }
nickjillings@1541 5350 });
nickjillings@1541 5351
nickjillings@1541 5352 // Force removal if there was no new content (e.g., from empty arguments)
nickjillings@1541 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nickjillings@1541 5354 },
nickjillings@1541 5355
nickjillings@1541 5356 detach: function( selector ) {
nickjillings@1541 5357 return this.remove( selector, true );
nickjillings@1541 5358 },
nickjillings@1541 5359
nickjillings@1541 5360 domManip: function( args, callback ) {
nickjillings@1541 5361
nickjillings@1541 5362 // Flatten any nested arrays
nickjillings@1541 5363 args = concat.apply( [], args );
nickjillings@1541 5364
nickjillings@1541 5365 var fragment, first, scripts, hasScripts, node, doc,
nickjillings@1541 5366 i = 0,
nickjillings@1541 5367 l = this.length,
nickjillings@1541 5368 set = this,
nickjillings@1541 5369 iNoClone = l - 1,
nickjillings@1541 5370 value = args[ 0 ],
nickjillings@1541 5371 isFunction = jQuery.isFunction( value );
nickjillings@1541 5372
nickjillings@1541 5373 // We can't cloneNode fragments that contain checked, in WebKit
nickjillings@1541 5374 if ( isFunction ||
nickjillings@1541 5375 ( l > 1 && typeof value === "string" &&
nickjillings@1541 5376 !support.checkClone && rchecked.test( value ) ) ) {
nickjillings@1541 5377 return this.each(function( index ) {
nickjillings@1541 5378 var self = set.eq( index );
nickjillings@1541 5379 if ( isFunction ) {
nickjillings@1541 5380 args[ 0 ] = value.call( this, index, self.html() );
nickjillings@1541 5381 }
nickjillings@1541 5382 self.domManip( args, callback );
nickjillings@1541 5383 });
nickjillings@1541 5384 }
nickjillings@1541 5385
nickjillings@1541 5386 if ( l ) {
nickjillings@1541 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nickjillings@1541 5388 first = fragment.firstChild;
nickjillings@1541 5389
nickjillings@1541 5390 if ( fragment.childNodes.length === 1 ) {
nickjillings@1541 5391 fragment = first;
nickjillings@1541 5392 }
nickjillings@1541 5393
nickjillings@1541 5394 if ( first ) {
nickjillings@1541 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nickjillings@1541 5396 hasScripts = scripts.length;
nickjillings@1541 5397
nickjillings@1541 5398 // Use the original fragment for the last item instead of the first because it can end up
nickjillings@1541 5399 // being emptied incorrectly in certain situations (#8070).
nickjillings@1541 5400 for ( ; i < l; i++ ) {
nickjillings@1541 5401 node = fragment;
nickjillings@1541 5402
nickjillings@1541 5403 if ( i !== iNoClone ) {
nickjillings@1541 5404 node = jQuery.clone( node, true, true );
nickjillings@1541 5405
nickjillings@1541 5406 // Keep references to cloned scripts for later restoration
nickjillings@1541 5407 if ( hasScripts ) {
nickjillings@1541 5408 // Support: QtWebKit
nickjillings@1541 5409 // jQuery.merge because push.apply(_, arraylike) throws
nickjillings@1541 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nickjillings@1541 5411 }
nickjillings@1541 5412 }
nickjillings@1541 5413
nickjillings@1541 5414 callback.call( this[ i ], node, i );
nickjillings@1541 5415 }
nickjillings@1541 5416
nickjillings@1541 5417 if ( hasScripts ) {
nickjillings@1541 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nickjillings@1541 5419
nickjillings@1541 5420 // Reenable scripts
nickjillings@1541 5421 jQuery.map( scripts, restoreScript );
nickjillings@1541 5422
nickjillings@1541 5423 // Evaluate executable scripts on first document insertion
nickjillings@1541 5424 for ( i = 0; i < hasScripts; i++ ) {
nickjillings@1541 5425 node = scripts[ i ];
nickjillings@1541 5426 if ( rscriptType.test( node.type || "" ) &&
nickjillings@1541 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nickjillings@1541 5428
nickjillings@1541 5429 if ( node.src ) {
nickjillings@1541 5430 // Optional AJAX dependency, but won't run scripts if not present
nickjillings@1541 5431 if ( jQuery._evalUrl ) {
nickjillings@1541 5432 jQuery._evalUrl( node.src );
nickjillings@1541 5433 }
nickjillings@1541 5434 } else {
nickjillings@1541 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nickjillings@1541 5436 }
nickjillings@1541 5437 }
nickjillings@1541 5438 }
nickjillings@1541 5439 }
nickjillings@1541 5440 }
nickjillings@1541 5441 }
nickjillings@1541 5442
nickjillings@1541 5443 return this;
nickjillings@1541 5444 }
nickjillings@1541 5445 });
nickjillings@1541 5446
nickjillings@1541 5447 jQuery.each({
nickjillings@1541 5448 appendTo: "append",
nickjillings@1541 5449 prependTo: "prepend",
nickjillings@1541 5450 insertBefore: "before",
nickjillings@1541 5451 insertAfter: "after",
nickjillings@1541 5452 replaceAll: "replaceWith"
nickjillings@1541 5453 }, function( name, original ) {
nickjillings@1541 5454 jQuery.fn[ name ] = function( selector ) {
nickjillings@1541 5455 var elems,
nickjillings@1541 5456 ret = [],
nickjillings@1541 5457 insert = jQuery( selector ),
nickjillings@1541 5458 last = insert.length - 1,
nickjillings@1541 5459 i = 0;
nickjillings@1541 5460
nickjillings@1541 5461 for ( ; i <= last; i++ ) {
nickjillings@1541 5462 elems = i === last ? this : this.clone( true );
nickjillings@1541 5463 jQuery( insert[ i ] )[ original ]( elems );
nickjillings@1541 5464
nickjillings@1541 5465 // Support: QtWebKit
nickjillings@1541 5466 // .get() because push.apply(_, arraylike) throws
nickjillings@1541 5467 push.apply( ret, elems.get() );
nickjillings@1541 5468 }
nickjillings@1541 5469
nickjillings@1541 5470 return this.pushStack( ret );
nickjillings@1541 5471 };
nickjillings@1541 5472 });
nickjillings@1541 5473
nickjillings@1541 5474
nickjillings@1541 5475 var iframe,
nickjillings@1541 5476 elemdisplay = {};
nickjillings@1541 5477
nickjillings@1541 5478 /**
nickjillings@1541 5479 * Retrieve the actual display of a element
nickjillings@1541 5480 * @param {String} name nodeName of the element
nickjillings@1541 5481 * @param {Object} doc Document object
nickjillings@1541 5482 */
nickjillings@1541 5483 // Called only from within defaultDisplay
nickjillings@1541 5484 function actualDisplay( name, doc ) {
nickjillings@1541 5485 var style,
nickjillings@1541 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nickjillings@1541 5487
nickjillings@1541 5488 // getDefaultComputedStyle might be reliably used only on attached element
nickjillings@1541 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nickjillings@1541 5490
nickjillings@1541 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nickjillings@1541 5492 // since it was removed from specification and supported only in FF
nickjillings@1541 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nickjillings@1541 5494
nickjillings@1541 5495 // We don't have any data stored on the element,
nickjillings@1541 5496 // so use "detach" method as fast way to get rid of the element
nickjillings@1541 5497 elem.detach();
nickjillings@1541 5498
nickjillings@1541 5499 return display;
nickjillings@1541 5500 }
nickjillings@1541 5501
nickjillings@1541 5502 /**
nickjillings@1541 5503 * Try to determine the default display value of an element
nickjillings@1541 5504 * @param {String} nodeName
nickjillings@1541 5505 */
nickjillings@1541 5506 function defaultDisplay( nodeName ) {
nickjillings@1541 5507 var doc = document,
nickjillings@1541 5508 display = elemdisplay[ nodeName ];
nickjillings@1541 5509
nickjillings@1541 5510 if ( !display ) {
nickjillings@1541 5511 display = actualDisplay( nodeName, doc );
nickjillings@1541 5512
nickjillings@1541 5513 // If the simple way fails, read from inside an iframe
nickjillings@1541 5514 if ( display === "none" || !display ) {
nickjillings@1541 5515
nickjillings@1541 5516 // Use the already-created iframe if possible
nickjillings@1541 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nickjillings@1541 5518
nickjillings@1541 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nickjillings@1541 5520 doc = iframe[ 0 ].contentDocument;
nickjillings@1541 5521
nickjillings@1541 5522 // Support: IE
nickjillings@1541 5523 doc.write();
nickjillings@1541 5524 doc.close();
nickjillings@1541 5525
nickjillings@1541 5526 display = actualDisplay( nodeName, doc );
nickjillings@1541 5527 iframe.detach();
nickjillings@1541 5528 }
nickjillings@1541 5529
nickjillings@1541 5530 // Store the correct default display
nickjillings@1541 5531 elemdisplay[ nodeName ] = display;
nickjillings@1541 5532 }
nickjillings@1541 5533
nickjillings@1541 5534 return display;
nickjillings@1541 5535 }
nickjillings@1541 5536 var rmargin = (/^margin/);
nickjillings@1541 5537
nickjillings@1541 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nickjillings@1541 5539
nickjillings@1541 5540 var getStyles = function( elem ) {
nickjillings@1541 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nickjillings@1541 5542 // IE throws on elements created in popups
nickjillings@1541 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nickjillings@1541 5544 if ( elem.ownerDocument.defaultView.opener ) {
nickjillings@1541 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nickjillings@1541 5546 }
nickjillings@1541 5547
nickjillings@1541 5548 return window.getComputedStyle( elem, null );
nickjillings@1541 5549 };
nickjillings@1541 5550
nickjillings@1541 5551
nickjillings@1541 5552
nickjillings@1541 5553 function curCSS( elem, name, computed ) {
nickjillings@1541 5554 var width, minWidth, maxWidth, ret,
nickjillings@1541 5555 style = elem.style;
nickjillings@1541 5556
nickjillings@1541 5557 computed = computed || getStyles( elem );
nickjillings@1541 5558
nickjillings@1541 5559 // Support: IE9
nickjillings@1541 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nickjillings@1541 5561 if ( computed ) {
nickjillings@1541 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nickjillings@1541 5563 }
nickjillings@1541 5564
nickjillings@1541 5565 if ( computed ) {
nickjillings@1541 5566
nickjillings@1541 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1541 5568 ret = jQuery.style( elem, name );
nickjillings@1541 5569 }
nickjillings@1541 5570
nickjillings@1541 5571 // Support: iOS < 6
nickjillings@1541 5572 // A tribute to the "awesome hack by Dean Edwards"
nickjillings@1541 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nickjillings@1541 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nickjillings@1541 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nickjillings@1541 5576
nickjillings@1541 5577 // Remember the original values
nickjillings@1541 5578 width = style.width;
nickjillings@1541 5579 minWidth = style.minWidth;
nickjillings@1541 5580 maxWidth = style.maxWidth;
nickjillings@1541 5581
nickjillings@1541 5582 // Put in the new values to get a computed value out
nickjillings@1541 5583 style.minWidth = style.maxWidth = style.width = ret;
nickjillings@1541 5584 ret = computed.width;
nickjillings@1541 5585
nickjillings@1541 5586 // Revert the changed values
nickjillings@1541 5587 style.width = width;
nickjillings@1541 5588 style.minWidth = minWidth;
nickjillings@1541 5589 style.maxWidth = maxWidth;
nickjillings@1541 5590 }
nickjillings@1541 5591 }
nickjillings@1541 5592
nickjillings@1541 5593 return ret !== undefined ?
nickjillings@1541 5594 // Support: IE
nickjillings@1541 5595 // IE returns zIndex value as an integer.
nickjillings@1541 5596 ret + "" :
nickjillings@1541 5597 ret;
nickjillings@1541 5598 }
nickjillings@1541 5599
nickjillings@1541 5600
nickjillings@1541 5601 function addGetHookIf( conditionFn, hookFn ) {
nickjillings@1541 5602 // Define the hook, we'll check on the first run if it's really needed.
nickjillings@1541 5603 return {
nickjillings@1541 5604 get: function() {
nickjillings@1541 5605 if ( conditionFn() ) {
nickjillings@1541 5606 // Hook not needed (or it's not possible to use it due
nickjillings@1541 5607 // to missing dependency), remove it.
nickjillings@1541 5608 delete this.get;
nickjillings@1541 5609 return;
nickjillings@1541 5610 }
nickjillings@1541 5611
nickjillings@1541 5612 // Hook needed; redefine it so that the support test is not executed again.
nickjillings@1541 5613 return (this.get = hookFn).apply( this, arguments );
nickjillings@1541 5614 }
nickjillings@1541 5615 };
nickjillings@1541 5616 }
nickjillings@1541 5617
nickjillings@1541 5618
nickjillings@1541 5619 (function() {
nickjillings@1541 5620 var pixelPositionVal, boxSizingReliableVal,
nickjillings@1541 5621 docElem = document.documentElement,
nickjillings@1541 5622 container = document.createElement( "div" ),
nickjillings@1541 5623 div = document.createElement( "div" );
nickjillings@1541 5624
nickjillings@1541 5625 if ( !div.style ) {
nickjillings@1541 5626 return;
nickjillings@1541 5627 }
nickjillings@1541 5628
nickjillings@1541 5629 // Support: IE9-11+
nickjillings@1541 5630 // Style of cloned element affects source element cloned (#8908)
nickjillings@1541 5631 div.style.backgroundClip = "content-box";
nickjillings@1541 5632 div.cloneNode( true ).style.backgroundClip = "";
nickjillings@1541 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nickjillings@1541 5634
nickjillings@1541 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nickjillings@1541 5636 "position:absolute";
nickjillings@1541 5637 container.appendChild( div );
nickjillings@1541 5638
nickjillings@1541 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nickjillings@1541 5640 // so they're executed at the same time to save the second computation.
nickjillings@1541 5641 function computePixelPositionAndBoxSizingReliable() {
nickjillings@1541 5642 div.style.cssText =
nickjillings@1541 5643 // Support: Firefox<29, Android 2.3
nickjillings@1541 5644 // Vendor-prefix box-sizing
nickjillings@1541 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nickjillings@1541 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nickjillings@1541 5647 "border:1px;padding:1px;width:4px;position:absolute";
nickjillings@1541 5648 div.innerHTML = "";
nickjillings@1541 5649 docElem.appendChild( container );
nickjillings@1541 5650
nickjillings@1541 5651 var divStyle = window.getComputedStyle( div, null );
nickjillings@1541 5652 pixelPositionVal = divStyle.top !== "1%";
nickjillings@1541 5653 boxSizingReliableVal = divStyle.width === "4px";
nickjillings@1541 5654
nickjillings@1541 5655 docElem.removeChild( container );
nickjillings@1541 5656 }
nickjillings@1541 5657
nickjillings@1541 5658 // Support: node.js jsdom
nickjillings@1541 5659 // Don't assume that getComputedStyle is a property of the global object
nickjillings@1541 5660 if ( window.getComputedStyle ) {
nickjillings@1541 5661 jQuery.extend( support, {
nickjillings@1541 5662 pixelPosition: function() {
nickjillings@1541 5663
nickjillings@1541 5664 // This test is executed only once but we still do memoizing
nickjillings@1541 5665 // since we can use the boxSizingReliable pre-computing.
nickjillings@1541 5666 // No need to check if the test was already performed, though.
nickjillings@1541 5667 computePixelPositionAndBoxSizingReliable();
nickjillings@1541 5668 return pixelPositionVal;
nickjillings@1541 5669 },
nickjillings@1541 5670 boxSizingReliable: function() {
nickjillings@1541 5671 if ( boxSizingReliableVal == null ) {
nickjillings@1541 5672 computePixelPositionAndBoxSizingReliable();
nickjillings@1541 5673 }
nickjillings@1541 5674 return boxSizingReliableVal;
nickjillings@1541 5675 },
nickjillings@1541 5676 reliableMarginRight: function() {
nickjillings@1541 5677
nickjillings@1541 5678 // Support: Android 2.3
nickjillings@1541 5679 // Check if div with explicit width and no margin-right incorrectly
nickjillings@1541 5680 // gets computed margin-right based on width of container. (#3333)
nickjillings@1541 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nickjillings@1541 5682 // This support function is only executed once so no memoizing is needed.
nickjillings@1541 5683 var ret,
nickjillings@1541 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nickjillings@1541 5685
nickjillings@1541 5686 // Reset CSS: box-sizing; display; margin; border; padding
nickjillings@1541 5687 marginDiv.style.cssText = div.style.cssText =
nickjillings@1541 5688 // Support: Firefox<29, Android 2.3
nickjillings@1541 5689 // Vendor-prefix box-sizing
nickjillings@1541 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nickjillings@1541 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nickjillings@1541 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nickjillings@1541 5693 div.style.width = "1px";
nickjillings@1541 5694 docElem.appendChild( container );
nickjillings@1541 5695
nickjillings@1541 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nickjillings@1541 5697
nickjillings@1541 5698 docElem.removeChild( container );
nickjillings@1541 5699 div.removeChild( marginDiv );
nickjillings@1541 5700
nickjillings@1541 5701 return ret;
nickjillings@1541 5702 }
nickjillings@1541 5703 });
nickjillings@1541 5704 }
nickjillings@1541 5705 })();
nickjillings@1541 5706
nickjillings@1541 5707
nickjillings@1541 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nickjillings@1541 5709 jQuery.swap = function( elem, options, callback, args ) {
nickjillings@1541 5710 var ret, name,
nickjillings@1541 5711 old = {};
nickjillings@1541 5712
nickjillings@1541 5713 // Remember the old values, and insert the new ones
nickjillings@1541 5714 for ( name in options ) {
nickjillings@1541 5715 old[ name ] = elem.style[ name ];
nickjillings@1541 5716 elem.style[ name ] = options[ name ];
nickjillings@1541 5717 }
nickjillings@1541 5718
nickjillings@1541 5719 ret = callback.apply( elem, args || [] );
nickjillings@1541 5720
nickjillings@1541 5721 // Revert the old values
nickjillings@1541 5722 for ( name in options ) {
nickjillings@1541 5723 elem.style[ name ] = old[ name ];
nickjillings@1541 5724 }
nickjillings@1541 5725
nickjillings@1541 5726 return ret;
nickjillings@1541 5727 };
nickjillings@1541 5728
nickjillings@1541 5729
nickjillings@1541 5730 var
nickjillings@1541 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nickjillings@1541 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nickjillings@1541 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nickjillings@1541 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nickjillings@1541 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nickjillings@1541 5736
nickjillings@1541 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nickjillings@1541 5738 cssNormalTransform = {
nickjillings@1541 5739 letterSpacing: "0",
nickjillings@1541 5740 fontWeight: "400"
nickjillings@1541 5741 },
nickjillings@1541 5742
nickjillings@1541 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nickjillings@1541 5744
nickjillings@1541 5745 // Return a css property mapped to a potentially vendor prefixed property
nickjillings@1541 5746 function vendorPropName( style, name ) {
nickjillings@1541 5747
nickjillings@1541 5748 // Shortcut for names that are not vendor prefixed
nickjillings@1541 5749 if ( name in style ) {
nickjillings@1541 5750 return name;
nickjillings@1541 5751 }
nickjillings@1541 5752
nickjillings@1541 5753 // Check for vendor prefixed names
nickjillings@1541 5754 var capName = name[0].toUpperCase() + name.slice(1),
nickjillings@1541 5755 origName = name,
nickjillings@1541 5756 i = cssPrefixes.length;
nickjillings@1541 5757
nickjillings@1541 5758 while ( i-- ) {
nickjillings@1541 5759 name = cssPrefixes[ i ] + capName;
nickjillings@1541 5760 if ( name in style ) {
nickjillings@1541 5761 return name;
nickjillings@1541 5762 }
nickjillings@1541 5763 }
nickjillings@1541 5764
nickjillings@1541 5765 return origName;
nickjillings@1541 5766 }
nickjillings@1541 5767
nickjillings@1541 5768 function setPositiveNumber( elem, value, subtract ) {
nickjillings@1541 5769 var matches = rnumsplit.exec( value );
nickjillings@1541 5770 return matches ?
nickjillings@1541 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nickjillings@1541 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nickjillings@1541 5773 value;
nickjillings@1541 5774 }
nickjillings@1541 5775
nickjillings@1541 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nickjillings@1541 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nickjillings@1541 5778 // If we already have the right measurement, avoid augmentation
nickjillings@1541 5779 4 :
nickjillings@1541 5780 // Otherwise initialize for horizontal or vertical properties
nickjillings@1541 5781 name === "width" ? 1 : 0,
nickjillings@1541 5782
nickjillings@1541 5783 val = 0;
nickjillings@1541 5784
nickjillings@1541 5785 for ( ; i < 4; i += 2 ) {
nickjillings@1541 5786 // Both box models exclude margin, so add it if we want it
nickjillings@1541 5787 if ( extra === "margin" ) {
nickjillings@1541 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nickjillings@1541 5789 }
nickjillings@1541 5790
nickjillings@1541 5791 if ( isBorderBox ) {
nickjillings@1541 5792 // border-box includes padding, so remove it if we want content
nickjillings@1541 5793 if ( extra === "content" ) {
nickjillings@1541 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1541 5795 }
nickjillings@1541 5796
nickjillings@1541 5797 // At this point, extra isn't border nor margin, so remove border
nickjillings@1541 5798 if ( extra !== "margin" ) {
nickjillings@1541 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1541 5800 }
nickjillings@1541 5801 } else {
nickjillings@1541 5802 // At this point, extra isn't content, so add padding
nickjillings@1541 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1541 5804
nickjillings@1541 5805 // At this point, extra isn't content nor padding, so add border
nickjillings@1541 5806 if ( extra !== "padding" ) {
nickjillings@1541 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1541 5808 }
nickjillings@1541 5809 }
nickjillings@1541 5810 }
nickjillings@1541 5811
nickjillings@1541 5812 return val;
nickjillings@1541 5813 }
nickjillings@1541 5814
nickjillings@1541 5815 function getWidthOrHeight( elem, name, extra ) {
nickjillings@1541 5816
nickjillings@1541 5817 // Start with offset property, which is equivalent to the border-box value
nickjillings@1541 5818 var valueIsBorderBox = true,
nickjillings@1541 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nickjillings@1541 5820 styles = getStyles( elem ),
nickjillings@1541 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nickjillings@1541 5822
nickjillings@1541 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nickjillings@1541 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nickjillings@1541 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nickjillings@1541 5826 if ( val <= 0 || val == null ) {
nickjillings@1541 5827 // Fall back to computed then uncomputed css if necessary
nickjillings@1541 5828 val = curCSS( elem, name, styles );
nickjillings@1541 5829 if ( val < 0 || val == null ) {
nickjillings@1541 5830 val = elem.style[ name ];
nickjillings@1541 5831 }
nickjillings@1541 5832
nickjillings@1541 5833 // Computed unit is not pixels. Stop here and return.
nickjillings@1541 5834 if ( rnumnonpx.test(val) ) {
nickjillings@1541 5835 return val;
nickjillings@1541 5836 }
nickjillings@1541 5837
nickjillings@1541 5838 // Check for style in case a browser which returns unreliable values
nickjillings@1541 5839 // for getComputedStyle silently falls back to the reliable elem.style
nickjillings@1541 5840 valueIsBorderBox = isBorderBox &&
nickjillings@1541 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nickjillings@1541 5842
nickjillings@1541 5843 // Normalize "", auto, and prepare for extra
nickjillings@1541 5844 val = parseFloat( val ) || 0;
nickjillings@1541 5845 }
nickjillings@1541 5846
nickjillings@1541 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nickjillings@1541 5848 return ( val +
nickjillings@1541 5849 augmentWidthOrHeight(
nickjillings@1541 5850 elem,
nickjillings@1541 5851 name,
nickjillings@1541 5852 extra || ( isBorderBox ? "border" : "content" ),
nickjillings@1541 5853 valueIsBorderBox,
nickjillings@1541 5854 styles
nickjillings@1541 5855 )
nickjillings@1541 5856 ) + "px";
nickjillings@1541 5857 }
nickjillings@1541 5858
nickjillings@1541 5859 function showHide( elements, show ) {
nickjillings@1541 5860 var display, elem, hidden,
nickjillings@1541 5861 values = [],
nickjillings@1541 5862 index = 0,
nickjillings@1541 5863 length = elements.length;
nickjillings@1541 5864
nickjillings@1541 5865 for ( ; index < length; index++ ) {
nickjillings@1541 5866 elem = elements[ index ];
nickjillings@1541 5867 if ( !elem.style ) {
nickjillings@1541 5868 continue;
nickjillings@1541 5869 }
nickjillings@1541 5870
nickjillings@1541 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nickjillings@1541 5872 display = elem.style.display;
nickjillings@1541 5873 if ( show ) {
nickjillings@1541 5874 // Reset the inline display of this element to learn if it is
nickjillings@1541 5875 // being hidden by cascaded rules or not
nickjillings@1541 5876 if ( !values[ index ] && display === "none" ) {
nickjillings@1541 5877 elem.style.display = "";
nickjillings@1541 5878 }
nickjillings@1541 5879
nickjillings@1541 5880 // Set elements which have been overridden with display: none
nickjillings@1541 5881 // in a stylesheet to whatever the default browser style is
nickjillings@1541 5882 // for such an element
nickjillings@1541 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nickjillings@1541 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nickjillings@1541 5885 }
nickjillings@1541 5886 } else {
nickjillings@1541 5887 hidden = isHidden( elem );
nickjillings@1541 5888
nickjillings@1541 5889 if ( display !== "none" || !hidden ) {
nickjillings@1541 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nickjillings@1541 5891 }
nickjillings@1541 5892 }
nickjillings@1541 5893 }
nickjillings@1541 5894
nickjillings@1541 5895 // Set the display of most of the elements in a second loop
nickjillings@1541 5896 // to avoid the constant reflow
nickjillings@1541 5897 for ( index = 0; index < length; index++ ) {
nickjillings@1541 5898 elem = elements[ index ];
nickjillings@1541 5899 if ( !elem.style ) {
nickjillings@1541 5900 continue;
nickjillings@1541 5901 }
nickjillings@1541 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nickjillings@1541 5903 elem.style.display = show ? values[ index ] || "" : "none";
nickjillings@1541 5904 }
nickjillings@1541 5905 }
nickjillings@1541 5906
nickjillings@1541 5907 return elements;
nickjillings@1541 5908 }
nickjillings@1541 5909
nickjillings@1541 5910 jQuery.extend({
nickjillings@1541 5911
nickjillings@1541 5912 // Add in style property hooks for overriding the default
nickjillings@1541 5913 // behavior of getting and setting a style property
nickjillings@1541 5914 cssHooks: {
nickjillings@1541 5915 opacity: {
nickjillings@1541 5916 get: function( elem, computed ) {
nickjillings@1541 5917 if ( computed ) {
nickjillings@1541 5918
nickjillings@1541 5919 // We should always get a number back from opacity
nickjillings@1541 5920 var ret = curCSS( elem, "opacity" );
nickjillings@1541 5921 return ret === "" ? "1" : ret;
nickjillings@1541 5922 }
nickjillings@1541 5923 }
nickjillings@1541 5924 }
nickjillings@1541 5925 },
nickjillings@1541 5926
nickjillings@1541 5927 // Don't automatically add "px" to these possibly-unitless properties
nickjillings@1541 5928 cssNumber: {
nickjillings@1541 5929 "columnCount": true,
nickjillings@1541 5930 "fillOpacity": true,
nickjillings@1541 5931 "flexGrow": true,
nickjillings@1541 5932 "flexShrink": true,
nickjillings@1541 5933 "fontWeight": true,
nickjillings@1541 5934 "lineHeight": true,
nickjillings@1541 5935 "opacity": true,
nickjillings@1541 5936 "order": true,
nickjillings@1541 5937 "orphans": true,
nickjillings@1541 5938 "widows": true,
nickjillings@1541 5939 "zIndex": true,
nickjillings@1541 5940 "zoom": true
nickjillings@1541 5941 },
nickjillings@1541 5942
nickjillings@1541 5943 // Add in properties whose names you wish to fix before
nickjillings@1541 5944 // setting or getting the value
nickjillings@1541 5945 cssProps: {
nickjillings@1541 5946 "float": "cssFloat"
nickjillings@1541 5947 },
nickjillings@1541 5948
nickjillings@1541 5949 // Get and set the style property on a DOM Node
nickjillings@1541 5950 style: function( elem, name, value, extra ) {
nickjillings@1541 5951
nickjillings@1541 5952 // Don't set styles on text and comment nodes
nickjillings@1541 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nickjillings@1541 5954 return;
nickjillings@1541 5955 }
nickjillings@1541 5956
nickjillings@1541 5957 // Make sure that we're working with the right name
nickjillings@1541 5958 var ret, type, hooks,
nickjillings@1541 5959 origName = jQuery.camelCase( name ),
nickjillings@1541 5960 style = elem.style;
nickjillings@1541 5961
nickjillings@1541 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nickjillings@1541 5963
nickjillings@1541 5964 // Gets hook for the prefixed version, then unprefixed version
nickjillings@1541 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1541 5966
nickjillings@1541 5967 // Check if we're setting a value
nickjillings@1541 5968 if ( value !== undefined ) {
nickjillings@1541 5969 type = typeof value;
nickjillings@1541 5970
nickjillings@1541 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nickjillings@1541 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nickjillings@1541 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nickjillings@1541 5974 // Fixes bug #9237
nickjillings@1541 5975 type = "number";
nickjillings@1541 5976 }
nickjillings@1541 5977
nickjillings@1541 5978 // Make sure that null and NaN values aren't set (#7116)
nickjillings@1541 5979 if ( value == null || value !== value ) {
nickjillings@1541 5980 return;
nickjillings@1541 5981 }
nickjillings@1541 5982
nickjillings@1541 5983 // If a number, add 'px' to the (except for certain CSS properties)
nickjillings@1541 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nickjillings@1541 5985 value += "px";
nickjillings@1541 5986 }
nickjillings@1541 5987
nickjillings@1541 5988 // Support: IE9-11+
nickjillings@1541 5989 // background-* props affect original clone's values
nickjillings@1541 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nickjillings@1541 5991 style[ name ] = "inherit";
nickjillings@1541 5992 }
nickjillings@1541 5993
nickjillings@1541 5994 // If a hook was provided, use that value, otherwise just set the specified value
nickjillings@1541 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nickjillings@1541 5996 style[ name ] = value;
nickjillings@1541 5997 }
nickjillings@1541 5998
nickjillings@1541 5999 } else {
nickjillings@1541 6000 // If a hook was provided get the non-computed value from there
nickjillings@1541 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nickjillings@1541 6002 return ret;
nickjillings@1541 6003 }
nickjillings@1541 6004
nickjillings@1541 6005 // Otherwise just get the value from the style object
nickjillings@1541 6006 return style[ name ];
nickjillings@1541 6007 }
nickjillings@1541 6008 },
nickjillings@1541 6009
nickjillings@1541 6010 css: function( elem, name, extra, styles ) {
nickjillings@1541 6011 var val, num, hooks,
nickjillings@1541 6012 origName = jQuery.camelCase( name );
nickjillings@1541 6013
nickjillings@1541 6014 // Make sure that we're working with the right name
nickjillings@1541 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nickjillings@1541 6016
nickjillings@1541 6017 // Try prefixed name followed by the unprefixed name
nickjillings@1541 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1541 6019
nickjillings@1541 6020 // If a hook was provided get the computed value from there
nickjillings@1541 6021 if ( hooks && "get" in hooks ) {
nickjillings@1541 6022 val = hooks.get( elem, true, extra );
nickjillings@1541 6023 }
nickjillings@1541 6024
nickjillings@1541 6025 // Otherwise, if a way to get the computed value exists, use that
nickjillings@1541 6026 if ( val === undefined ) {
nickjillings@1541 6027 val = curCSS( elem, name, styles );
nickjillings@1541 6028 }
nickjillings@1541 6029
nickjillings@1541 6030 // Convert "normal" to computed value
nickjillings@1541 6031 if ( val === "normal" && name in cssNormalTransform ) {
nickjillings@1541 6032 val = cssNormalTransform[ name ];
nickjillings@1541 6033 }
nickjillings@1541 6034
nickjillings@1541 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nickjillings@1541 6036 if ( extra === "" || extra ) {
nickjillings@1541 6037 num = parseFloat( val );
nickjillings@1541 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nickjillings@1541 6039 }
nickjillings@1541 6040 return val;
nickjillings@1541 6041 }
nickjillings@1541 6042 });
nickjillings@1541 6043
nickjillings@1541 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nickjillings@1541 6045 jQuery.cssHooks[ name ] = {
nickjillings@1541 6046 get: function( elem, computed, extra ) {
nickjillings@1541 6047 if ( computed ) {
nickjillings@1541 6048
nickjillings@1541 6049 // Certain elements can have dimension info if we invisibly show them
nickjillings@1541 6050 // but it must have a current display style that would benefit
nickjillings@1541 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nickjillings@1541 6052 jQuery.swap( elem, cssShow, function() {
nickjillings@1541 6053 return getWidthOrHeight( elem, name, extra );
nickjillings@1541 6054 }) :
nickjillings@1541 6055 getWidthOrHeight( elem, name, extra );
nickjillings@1541 6056 }
nickjillings@1541 6057 },
nickjillings@1541 6058
nickjillings@1541 6059 set: function( elem, value, extra ) {
nickjillings@1541 6060 var styles = extra && getStyles( elem );
nickjillings@1541 6061 return setPositiveNumber( elem, value, extra ?
nickjillings@1541 6062 augmentWidthOrHeight(
nickjillings@1541 6063 elem,
nickjillings@1541 6064 name,
nickjillings@1541 6065 extra,
nickjillings@1541 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nickjillings@1541 6067 styles
nickjillings@1541 6068 ) : 0
nickjillings@1541 6069 );
nickjillings@1541 6070 }
nickjillings@1541 6071 };
nickjillings@1541 6072 });
nickjillings@1541 6073
nickjillings@1541 6074 // Support: Android 2.3
nickjillings@1541 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nickjillings@1541 6076 function( elem, computed ) {
nickjillings@1541 6077 if ( computed ) {
nickjillings@1541 6078 return jQuery.swap( elem, { "display": "inline-block" },
nickjillings@1541 6079 curCSS, [ elem, "marginRight" ] );
nickjillings@1541 6080 }
nickjillings@1541 6081 }
nickjillings@1541 6082 );
nickjillings@1541 6083
nickjillings@1541 6084 // These hooks are used by animate to expand properties
nickjillings@1541 6085 jQuery.each({
nickjillings@1541 6086 margin: "",
nickjillings@1541 6087 padding: "",
nickjillings@1541 6088 border: "Width"
nickjillings@1541 6089 }, function( prefix, suffix ) {
nickjillings@1541 6090 jQuery.cssHooks[ prefix + suffix ] = {
nickjillings@1541 6091 expand: function( value ) {
nickjillings@1541 6092 var i = 0,
nickjillings@1541 6093 expanded = {},
nickjillings@1541 6094
nickjillings@1541 6095 // Assumes a single number if not a string
nickjillings@1541 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nickjillings@1541 6097
nickjillings@1541 6098 for ( ; i < 4; i++ ) {
nickjillings@1541 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nickjillings@1541 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nickjillings@1541 6101 }
nickjillings@1541 6102
nickjillings@1541 6103 return expanded;
nickjillings@1541 6104 }
nickjillings@1541 6105 };
nickjillings@1541 6106
nickjillings@1541 6107 if ( !rmargin.test( prefix ) ) {
nickjillings@1541 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nickjillings@1541 6109 }
nickjillings@1541 6110 });
nickjillings@1541 6111
nickjillings@1541 6112 jQuery.fn.extend({
nickjillings@1541 6113 css: function( name, value ) {
nickjillings@1541 6114 return access( this, function( elem, name, value ) {
nickjillings@1541 6115 var styles, len,
nickjillings@1541 6116 map = {},
nickjillings@1541 6117 i = 0;
nickjillings@1541 6118
nickjillings@1541 6119 if ( jQuery.isArray( name ) ) {
nickjillings@1541 6120 styles = getStyles( elem );
nickjillings@1541 6121 len = name.length;
nickjillings@1541 6122
nickjillings@1541 6123 for ( ; i < len; i++ ) {
nickjillings@1541 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nickjillings@1541 6125 }
nickjillings@1541 6126
nickjillings@1541 6127 return map;
nickjillings@1541 6128 }
nickjillings@1541 6129
nickjillings@1541 6130 return value !== undefined ?
nickjillings@1541 6131 jQuery.style( elem, name, value ) :
nickjillings@1541 6132 jQuery.css( elem, name );
nickjillings@1541 6133 }, name, value, arguments.length > 1 );
nickjillings@1541 6134 },
nickjillings@1541 6135 show: function() {
nickjillings@1541 6136 return showHide( this, true );
nickjillings@1541 6137 },
nickjillings@1541 6138 hide: function() {
nickjillings@1541 6139 return showHide( this );
nickjillings@1541 6140 },
nickjillings@1541 6141 toggle: function( state ) {
nickjillings@1541 6142 if ( typeof state === "boolean" ) {
nickjillings@1541 6143 return state ? this.show() : this.hide();
nickjillings@1541 6144 }
nickjillings@1541 6145
nickjillings@1541 6146 return this.each(function() {
nickjillings@1541 6147 if ( isHidden( this ) ) {
nickjillings@1541 6148 jQuery( this ).show();
nickjillings@1541 6149 } else {
nickjillings@1541 6150 jQuery( this ).hide();
nickjillings@1541 6151 }
nickjillings@1541 6152 });
nickjillings@1541 6153 }
nickjillings@1541 6154 });
nickjillings@1541 6155
nickjillings@1541 6156
nickjillings@1541 6157 function Tween( elem, options, prop, end, easing ) {
nickjillings@1541 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nickjillings@1541 6159 }
nickjillings@1541 6160 jQuery.Tween = Tween;
nickjillings@1541 6161
nickjillings@1541 6162 Tween.prototype = {
nickjillings@1541 6163 constructor: Tween,
nickjillings@1541 6164 init: function( elem, options, prop, end, easing, unit ) {
nickjillings@1541 6165 this.elem = elem;
nickjillings@1541 6166 this.prop = prop;
nickjillings@1541 6167 this.easing = easing || "swing";
nickjillings@1541 6168 this.options = options;
nickjillings@1541 6169 this.start = this.now = this.cur();
nickjillings@1541 6170 this.end = end;
nickjillings@1541 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nickjillings@1541 6172 },
nickjillings@1541 6173 cur: function() {
nickjillings@1541 6174 var hooks = Tween.propHooks[ this.prop ];
nickjillings@1541 6175
nickjillings@1541 6176 return hooks && hooks.get ?
nickjillings@1541 6177 hooks.get( this ) :
nickjillings@1541 6178 Tween.propHooks._default.get( this );
nickjillings@1541 6179 },
nickjillings@1541 6180 run: function( percent ) {
nickjillings@1541 6181 var eased,
nickjillings@1541 6182 hooks = Tween.propHooks[ this.prop ];
nickjillings@1541 6183
nickjillings@1541 6184 if ( this.options.duration ) {
nickjillings@1541 6185 this.pos = eased = jQuery.easing[ this.easing ](
nickjillings@1541 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nickjillings@1541 6187 );
nickjillings@1541 6188 } else {
nickjillings@1541 6189 this.pos = eased = percent;
nickjillings@1541 6190 }
nickjillings@1541 6191 this.now = ( this.end - this.start ) * eased + this.start;
nickjillings@1541 6192
nickjillings@1541 6193 if ( this.options.step ) {
nickjillings@1541 6194 this.options.step.call( this.elem, this.now, this );
nickjillings@1541 6195 }
nickjillings@1541 6196
nickjillings@1541 6197 if ( hooks && hooks.set ) {
nickjillings@1541 6198 hooks.set( this );
nickjillings@1541 6199 } else {
nickjillings@1541 6200 Tween.propHooks._default.set( this );
nickjillings@1541 6201 }
nickjillings@1541 6202 return this;
nickjillings@1541 6203 }
nickjillings@1541 6204 };
nickjillings@1541 6205
nickjillings@1541 6206 Tween.prototype.init.prototype = Tween.prototype;
nickjillings@1541 6207
nickjillings@1541 6208 Tween.propHooks = {
nickjillings@1541 6209 _default: {
nickjillings@1541 6210 get: function( tween ) {
nickjillings@1541 6211 var result;
nickjillings@1541 6212
nickjillings@1541 6213 if ( tween.elem[ tween.prop ] != null &&
nickjillings@1541 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nickjillings@1541 6215 return tween.elem[ tween.prop ];
nickjillings@1541 6216 }
nickjillings@1541 6217
nickjillings@1541 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nickjillings@1541 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nickjillings@1541 6220 // Simple values such as "10px" are parsed to Float;
nickjillings@1541 6221 // complex values such as "rotate(1rad)" are returned as-is.
nickjillings@1541 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nickjillings@1541 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nickjillings@1541 6224 return !result || result === "auto" ? 0 : result;
nickjillings@1541 6225 },
nickjillings@1541 6226 set: function( tween ) {
nickjillings@1541 6227 // Use step hook for back compat.
nickjillings@1541 6228 // Use cssHook if its there.
nickjillings@1541 6229 // Use .style if available and use plain properties where available.
nickjillings@1541 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nickjillings@1541 6231 jQuery.fx.step[ tween.prop ]( tween );
nickjillings@1541 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nickjillings@1541 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nickjillings@1541 6234 } else {
nickjillings@1541 6235 tween.elem[ tween.prop ] = tween.now;
nickjillings@1541 6236 }
nickjillings@1541 6237 }
nickjillings@1541 6238 }
nickjillings@1541 6239 };
nickjillings@1541 6240
nickjillings@1541 6241 // Support: IE9
nickjillings@1541 6242 // Panic based approach to setting things on disconnected nodes
nickjillings@1541 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nickjillings@1541 6244 set: function( tween ) {
nickjillings@1541 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nickjillings@1541 6246 tween.elem[ tween.prop ] = tween.now;
nickjillings@1541 6247 }
nickjillings@1541 6248 }
nickjillings@1541 6249 };
nickjillings@1541 6250
nickjillings@1541 6251 jQuery.easing = {
nickjillings@1541 6252 linear: function( p ) {
nickjillings@1541 6253 return p;
nickjillings@1541 6254 },
nickjillings@1541 6255 swing: function( p ) {
nickjillings@1541 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nickjillings@1541 6257 }
nickjillings@1541 6258 };
nickjillings@1541 6259
nickjillings@1541 6260 jQuery.fx = Tween.prototype.init;
nickjillings@1541 6261
nickjillings@1541 6262 // Back Compat <1.8 extension point
nickjillings@1541 6263 jQuery.fx.step = {};
nickjillings@1541 6264
nickjillings@1541 6265
nickjillings@1541 6266
nickjillings@1541 6267
nickjillings@1541 6268 var
nickjillings@1541 6269 fxNow, timerId,
nickjillings@1541 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nickjillings@1541 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nickjillings@1541 6272 rrun = /queueHooks$/,
nickjillings@1541 6273 animationPrefilters = [ defaultPrefilter ],
nickjillings@1541 6274 tweeners = {
nickjillings@1541 6275 "*": [ function( prop, value ) {
nickjillings@1541 6276 var tween = this.createTween( prop, value ),
nickjillings@1541 6277 target = tween.cur(),
nickjillings@1541 6278 parts = rfxnum.exec( value ),
nickjillings@1541 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nickjillings@1541 6280
nickjillings@1541 6281 // Starting value computation is required for potential unit mismatches
nickjillings@1541 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nickjillings@1541 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nickjillings@1541 6284 scale = 1,
nickjillings@1541 6285 maxIterations = 20;
nickjillings@1541 6286
nickjillings@1541 6287 if ( start && start[ 3 ] !== unit ) {
nickjillings@1541 6288 // Trust units reported by jQuery.css
nickjillings@1541 6289 unit = unit || start[ 3 ];
nickjillings@1541 6290
nickjillings@1541 6291 // Make sure we update the tween properties later on
nickjillings@1541 6292 parts = parts || [];
nickjillings@1541 6293
nickjillings@1541 6294 // Iteratively approximate from a nonzero starting point
nickjillings@1541 6295 start = +target || 1;
nickjillings@1541 6296
nickjillings@1541 6297 do {
nickjillings@1541 6298 // If previous iteration zeroed out, double until we get *something*.
nickjillings@1541 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nickjillings@1541 6300 scale = scale || ".5";
nickjillings@1541 6301
nickjillings@1541 6302 // Adjust and apply
nickjillings@1541 6303 start = start / scale;
nickjillings@1541 6304 jQuery.style( tween.elem, prop, start + unit );
nickjillings@1541 6305
nickjillings@1541 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nickjillings@1541 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nickjillings@1541 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nickjillings@1541 6309 }
nickjillings@1541 6310
nickjillings@1541 6311 // Update tween properties
nickjillings@1541 6312 if ( parts ) {
nickjillings@1541 6313 start = tween.start = +start || +target || 0;
nickjillings@1541 6314 tween.unit = unit;
nickjillings@1541 6315 // If a +=/-= token was provided, we're doing a relative animation
nickjillings@1541 6316 tween.end = parts[ 1 ] ?
nickjillings@1541 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nickjillings@1541 6318 +parts[ 2 ];
nickjillings@1541 6319 }
nickjillings@1541 6320
nickjillings@1541 6321 return tween;
nickjillings@1541 6322 } ]
nickjillings@1541 6323 };
nickjillings@1541 6324
nickjillings@1541 6325 // Animations created synchronously will run synchronously
nickjillings@1541 6326 function createFxNow() {
nickjillings@1541 6327 setTimeout(function() {
nickjillings@1541 6328 fxNow = undefined;
nickjillings@1541 6329 });
nickjillings@1541 6330 return ( fxNow = jQuery.now() );
nickjillings@1541 6331 }
nickjillings@1541 6332
nickjillings@1541 6333 // Generate parameters to create a standard animation
nickjillings@1541 6334 function genFx( type, includeWidth ) {
nickjillings@1541 6335 var which,
nickjillings@1541 6336 i = 0,
nickjillings@1541 6337 attrs = { height: type };
nickjillings@1541 6338
nickjillings@1541 6339 // If we include width, step value is 1 to do all cssExpand values,
nickjillings@1541 6340 // otherwise step value is 2 to skip over Left and Right
nickjillings@1541 6341 includeWidth = includeWidth ? 1 : 0;
nickjillings@1541 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nickjillings@1541 6343 which = cssExpand[ i ];
nickjillings@1541 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nickjillings@1541 6345 }
nickjillings@1541 6346
nickjillings@1541 6347 if ( includeWidth ) {
nickjillings@1541 6348 attrs.opacity = attrs.width = type;
nickjillings@1541 6349 }
nickjillings@1541 6350
nickjillings@1541 6351 return attrs;
nickjillings@1541 6352 }
nickjillings@1541 6353
nickjillings@1541 6354 function createTween( value, prop, animation ) {
nickjillings@1541 6355 var tween,
nickjillings@1541 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nickjillings@1541 6357 index = 0,
nickjillings@1541 6358 length = collection.length;
nickjillings@1541 6359 for ( ; index < length; index++ ) {
nickjillings@1541 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nickjillings@1541 6361
nickjillings@1541 6362 // We're done with this property
nickjillings@1541 6363 return tween;
nickjillings@1541 6364 }
nickjillings@1541 6365 }
nickjillings@1541 6366 }
nickjillings@1541 6367
nickjillings@1541 6368 function defaultPrefilter( elem, props, opts ) {
nickjillings@1541 6369 /* jshint validthis: true */
nickjillings@1541 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nickjillings@1541 6371 anim = this,
nickjillings@1541 6372 orig = {},
nickjillings@1541 6373 style = elem.style,
nickjillings@1541 6374 hidden = elem.nodeType && isHidden( elem ),
nickjillings@1541 6375 dataShow = data_priv.get( elem, "fxshow" );
nickjillings@1541 6376
nickjillings@1541 6377 // Handle queue: false promises
nickjillings@1541 6378 if ( !opts.queue ) {
nickjillings@1541 6379 hooks = jQuery._queueHooks( elem, "fx" );
nickjillings@1541 6380 if ( hooks.unqueued == null ) {
nickjillings@1541 6381 hooks.unqueued = 0;
nickjillings@1541 6382 oldfire = hooks.empty.fire;
nickjillings@1541 6383 hooks.empty.fire = function() {
nickjillings@1541 6384 if ( !hooks.unqueued ) {
nickjillings@1541 6385 oldfire();
nickjillings@1541 6386 }
nickjillings@1541 6387 };
nickjillings@1541 6388 }
nickjillings@1541 6389 hooks.unqueued++;
nickjillings@1541 6390
nickjillings@1541 6391 anim.always(function() {
nickjillings@1541 6392 // Ensure the complete handler is called before this completes
nickjillings@1541 6393 anim.always(function() {
nickjillings@1541 6394 hooks.unqueued--;
nickjillings@1541 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nickjillings@1541 6396 hooks.empty.fire();
nickjillings@1541 6397 }
nickjillings@1541 6398 });
nickjillings@1541 6399 });
nickjillings@1541 6400 }
nickjillings@1541 6401
nickjillings@1541 6402 // Height/width overflow pass
nickjillings@1541 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nickjillings@1541 6404 // Make sure that nothing sneaks out
nickjillings@1541 6405 // Record all 3 overflow attributes because IE9-10 do not
nickjillings@1541 6406 // change the overflow attribute when overflowX and
nickjillings@1541 6407 // overflowY are set to the same value
nickjillings@1541 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nickjillings@1541 6409
nickjillings@1541 6410 // Set display property to inline-block for height/width
nickjillings@1541 6411 // animations on inline elements that are having width/height animated
nickjillings@1541 6412 display = jQuery.css( elem, "display" );
nickjillings@1541 6413
nickjillings@1541 6414 // Test default display if display is currently "none"
nickjillings@1541 6415 checkDisplay = display === "none" ?
nickjillings@1541 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nickjillings@1541 6417
nickjillings@1541 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nickjillings@1541 6419 style.display = "inline-block";
nickjillings@1541 6420 }
nickjillings@1541 6421 }
nickjillings@1541 6422
nickjillings@1541 6423 if ( opts.overflow ) {
nickjillings@1541 6424 style.overflow = "hidden";
nickjillings@1541 6425 anim.always(function() {
nickjillings@1541 6426 style.overflow = opts.overflow[ 0 ];
nickjillings@1541 6427 style.overflowX = opts.overflow[ 1 ];
nickjillings@1541 6428 style.overflowY = opts.overflow[ 2 ];
nickjillings@1541 6429 });
nickjillings@1541 6430 }
nickjillings@1541 6431
nickjillings@1541 6432 // show/hide pass
nickjillings@1541 6433 for ( prop in props ) {
nickjillings@1541 6434 value = props[ prop ];
nickjillings@1541 6435 if ( rfxtypes.exec( value ) ) {
nickjillings@1541 6436 delete props[ prop ];
nickjillings@1541 6437 toggle = toggle || value === "toggle";
nickjillings@1541 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nickjillings@1541 6439
nickjillings@1541 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
nickjillings@1541 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nickjillings@1541 6442 hidden = true;
nickjillings@1541 6443 } else {
nickjillings@1541 6444 continue;
nickjillings@1541 6445 }
nickjillings@1541 6446 }
nickjillings@1541 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nickjillings@1541 6448
nickjillings@1541 6449 // Any non-fx value stops us from restoring the original display value
nickjillings@1541 6450 } else {
nickjillings@1541 6451 display = undefined;
nickjillings@1541 6452 }
nickjillings@1541 6453 }
nickjillings@1541 6454
nickjillings@1541 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nickjillings@1541 6456 if ( dataShow ) {
nickjillings@1541 6457 if ( "hidden" in dataShow ) {
nickjillings@1541 6458 hidden = dataShow.hidden;
nickjillings@1541 6459 }
nickjillings@1541 6460 } else {
nickjillings@1541 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nickjillings@1541 6462 }
nickjillings@1541 6463
nickjillings@1541 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nickjillings@1541 6465 if ( toggle ) {
nickjillings@1541 6466 dataShow.hidden = !hidden;
nickjillings@1541 6467 }
nickjillings@1541 6468 if ( hidden ) {
nickjillings@1541 6469 jQuery( elem ).show();
nickjillings@1541 6470 } else {
nickjillings@1541 6471 anim.done(function() {
nickjillings@1541 6472 jQuery( elem ).hide();
nickjillings@1541 6473 });
nickjillings@1541 6474 }
nickjillings@1541 6475 anim.done(function() {
nickjillings@1541 6476 var prop;
nickjillings@1541 6477
nickjillings@1541 6478 data_priv.remove( elem, "fxshow" );
nickjillings@1541 6479 for ( prop in orig ) {
nickjillings@1541 6480 jQuery.style( elem, prop, orig[ prop ] );
nickjillings@1541 6481 }
nickjillings@1541 6482 });
nickjillings@1541 6483 for ( prop in orig ) {
nickjillings@1541 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nickjillings@1541 6485
nickjillings@1541 6486 if ( !( prop in dataShow ) ) {
nickjillings@1541 6487 dataShow[ prop ] = tween.start;
nickjillings@1541 6488 if ( hidden ) {
nickjillings@1541 6489 tween.end = tween.start;
nickjillings@1541 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nickjillings@1541 6491 }
nickjillings@1541 6492 }
nickjillings@1541 6493 }
nickjillings@1541 6494
nickjillings@1541 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nickjillings@1541 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nickjillings@1541 6497 style.display = display;
nickjillings@1541 6498 }
nickjillings@1541 6499 }
nickjillings@1541 6500
nickjillings@1541 6501 function propFilter( props, specialEasing ) {
nickjillings@1541 6502 var index, name, easing, value, hooks;
nickjillings@1541 6503
nickjillings@1541 6504 // camelCase, specialEasing and expand cssHook pass
nickjillings@1541 6505 for ( index in props ) {
nickjillings@1541 6506 name = jQuery.camelCase( index );
nickjillings@1541 6507 easing = specialEasing[ name ];
nickjillings@1541 6508 value = props[ index ];
nickjillings@1541 6509 if ( jQuery.isArray( value ) ) {
nickjillings@1541 6510 easing = value[ 1 ];
nickjillings@1541 6511 value = props[ index ] = value[ 0 ];
nickjillings@1541 6512 }
nickjillings@1541 6513
nickjillings@1541 6514 if ( index !== name ) {
nickjillings@1541 6515 props[ name ] = value;
nickjillings@1541 6516 delete props[ index ];
nickjillings@1541 6517 }
nickjillings@1541 6518
nickjillings@1541 6519 hooks = jQuery.cssHooks[ name ];
nickjillings@1541 6520 if ( hooks && "expand" in hooks ) {
nickjillings@1541 6521 value = hooks.expand( value );
nickjillings@1541 6522 delete props[ name ];
nickjillings@1541 6523
nickjillings@1541 6524 // Not quite $.extend, this won't overwrite existing keys.
nickjillings@1541 6525 // Reusing 'index' because we have the correct "name"
nickjillings@1541 6526 for ( index in value ) {
nickjillings@1541 6527 if ( !( index in props ) ) {
nickjillings@1541 6528 props[ index ] = value[ index ];
nickjillings@1541 6529 specialEasing[ index ] = easing;
nickjillings@1541 6530 }
nickjillings@1541 6531 }
nickjillings@1541 6532 } else {
nickjillings@1541 6533 specialEasing[ name ] = easing;
nickjillings@1541 6534 }
nickjillings@1541 6535 }
nickjillings@1541 6536 }
nickjillings@1541 6537
nickjillings@1541 6538 function Animation( elem, properties, options ) {
nickjillings@1541 6539 var result,
nickjillings@1541 6540 stopped,
nickjillings@1541 6541 index = 0,
nickjillings@1541 6542 length = animationPrefilters.length,
nickjillings@1541 6543 deferred = jQuery.Deferred().always( function() {
nickjillings@1541 6544 // Don't match elem in the :animated selector
nickjillings@1541 6545 delete tick.elem;
nickjillings@1541 6546 }),
nickjillings@1541 6547 tick = function() {
nickjillings@1541 6548 if ( stopped ) {
nickjillings@1541 6549 return false;
nickjillings@1541 6550 }
nickjillings@1541 6551 var currentTime = fxNow || createFxNow(),
nickjillings@1541 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nickjillings@1541 6553 // Support: Android 2.3
nickjillings@1541 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nickjillings@1541 6555 temp = remaining / animation.duration || 0,
nickjillings@1541 6556 percent = 1 - temp,
nickjillings@1541 6557 index = 0,
nickjillings@1541 6558 length = animation.tweens.length;
nickjillings@1541 6559
nickjillings@1541 6560 for ( ; index < length ; index++ ) {
nickjillings@1541 6561 animation.tweens[ index ].run( percent );
nickjillings@1541 6562 }
nickjillings@1541 6563
nickjillings@1541 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nickjillings@1541 6565
nickjillings@1541 6566 if ( percent < 1 && length ) {
nickjillings@1541 6567 return remaining;
nickjillings@1541 6568 } else {
nickjillings@1541 6569 deferred.resolveWith( elem, [ animation ] );
nickjillings@1541 6570 return false;
nickjillings@1541 6571 }
nickjillings@1541 6572 },
nickjillings@1541 6573 animation = deferred.promise({
nickjillings@1541 6574 elem: elem,
nickjillings@1541 6575 props: jQuery.extend( {}, properties ),
nickjillings@1541 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nickjillings@1541 6577 originalProperties: properties,
nickjillings@1541 6578 originalOptions: options,
nickjillings@1541 6579 startTime: fxNow || createFxNow(),
nickjillings@1541 6580 duration: options.duration,
nickjillings@1541 6581 tweens: [],
nickjillings@1541 6582 createTween: function( prop, end ) {
nickjillings@1541 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nickjillings@1541 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nickjillings@1541 6585 animation.tweens.push( tween );
nickjillings@1541 6586 return tween;
nickjillings@1541 6587 },
nickjillings@1541 6588 stop: function( gotoEnd ) {
nickjillings@1541 6589 var index = 0,
nickjillings@1541 6590 // If we are going to the end, we want to run all the tweens
nickjillings@1541 6591 // otherwise we skip this part
nickjillings@1541 6592 length = gotoEnd ? animation.tweens.length : 0;
nickjillings@1541 6593 if ( stopped ) {
nickjillings@1541 6594 return this;
nickjillings@1541 6595 }
nickjillings@1541 6596 stopped = true;
nickjillings@1541 6597 for ( ; index < length ; index++ ) {
nickjillings@1541 6598 animation.tweens[ index ].run( 1 );
nickjillings@1541 6599 }
nickjillings@1541 6600
nickjillings@1541 6601 // Resolve when we played the last frame; otherwise, reject
nickjillings@1541 6602 if ( gotoEnd ) {
nickjillings@1541 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nickjillings@1541 6604 } else {
nickjillings@1541 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nickjillings@1541 6606 }
nickjillings@1541 6607 return this;
nickjillings@1541 6608 }
nickjillings@1541 6609 }),
nickjillings@1541 6610 props = animation.props;
nickjillings@1541 6611
nickjillings@1541 6612 propFilter( props, animation.opts.specialEasing );
nickjillings@1541 6613
nickjillings@1541 6614 for ( ; index < length ; index++ ) {
nickjillings@1541 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nickjillings@1541 6616 if ( result ) {
nickjillings@1541 6617 return result;
nickjillings@1541 6618 }
nickjillings@1541 6619 }
nickjillings@1541 6620
nickjillings@1541 6621 jQuery.map( props, createTween, animation );
nickjillings@1541 6622
nickjillings@1541 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nickjillings@1541 6624 animation.opts.start.call( elem, animation );
nickjillings@1541 6625 }
nickjillings@1541 6626
nickjillings@1541 6627 jQuery.fx.timer(
nickjillings@1541 6628 jQuery.extend( tick, {
nickjillings@1541 6629 elem: elem,
nickjillings@1541 6630 anim: animation,
nickjillings@1541 6631 queue: animation.opts.queue
nickjillings@1541 6632 })
nickjillings@1541 6633 );
nickjillings@1541 6634
nickjillings@1541 6635 // attach callbacks from options
nickjillings@1541 6636 return animation.progress( animation.opts.progress )
nickjillings@1541 6637 .done( animation.opts.done, animation.opts.complete )
nickjillings@1541 6638 .fail( animation.opts.fail )
nickjillings@1541 6639 .always( animation.opts.always );
nickjillings@1541 6640 }
nickjillings@1541 6641
nickjillings@1541 6642 jQuery.Animation = jQuery.extend( Animation, {
nickjillings@1541 6643
nickjillings@1541 6644 tweener: function( props, callback ) {
nickjillings@1541 6645 if ( jQuery.isFunction( props ) ) {
nickjillings@1541 6646 callback = props;
nickjillings@1541 6647 props = [ "*" ];
nickjillings@1541 6648 } else {
nickjillings@1541 6649 props = props.split(" ");
nickjillings@1541 6650 }
nickjillings@1541 6651
nickjillings@1541 6652 var prop,
nickjillings@1541 6653 index = 0,
nickjillings@1541 6654 length = props.length;
nickjillings@1541 6655
nickjillings@1541 6656 for ( ; index < length ; index++ ) {
nickjillings@1541 6657 prop = props[ index ];
nickjillings@1541 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nickjillings@1541 6659 tweeners[ prop ].unshift( callback );
nickjillings@1541 6660 }
nickjillings@1541 6661 },
nickjillings@1541 6662
nickjillings@1541 6663 prefilter: function( callback, prepend ) {
nickjillings@1541 6664 if ( prepend ) {
nickjillings@1541 6665 animationPrefilters.unshift( callback );
nickjillings@1541 6666 } else {
nickjillings@1541 6667 animationPrefilters.push( callback );
nickjillings@1541 6668 }
nickjillings@1541 6669 }
nickjillings@1541 6670 });
nickjillings@1541 6671
nickjillings@1541 6672 jQuery.speed = function( speed, easing, fn ) {
nickjillings@1541 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nickjillings@1541 6674 complete: fn || !fn && easing ||
nickjillings@1541 6675 jQuery.isFunction( speed ) && speed,
nickjillings@1541 6676 duration: speed,
nickjillings@1541 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nickjillings@1541 6678 };
nickjillings@1541 6679
nickjillings@1541 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nickjillings@1541 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nickjillings@1541 6682
nickjillings@1541 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nickjillings@1541 6684 if ( opt.queue == null || opt.queue === true ) {
nickjillings@1541 6685 opt.queue = "fx";
nickjillings@1541 6686 }
nickjillings@1541 6687
nickjillings@1541 6688 // Queueing
nickjillings@1541 6689 opt.old = opt.complete;
nickjillings@1541 6690
nickjillings@1541 6691 opt.complete = function() {
nickjillings@1541 6692 if ( jQuery.isFunction( opt.old ) ) {
nickjillings@1541 6693 opt.old.call( this );
nickjillings@1541 6694 }
nickjillings@1541 6695
nickjillings@1541 6696 if ( opt.queue ) {
nickjillings@1541 6697 jQuery.dequeue( this, opt.queue );
nickjillings@1541 6698 }
nickjillings@1541 6699 };
nickjillings@1541 6700
nickjillings@1541 6701 return opt;
nickjillings@1541 6702 };
nickjillings@1541 6703
nickjillings@1541 6704 jQuery.fn.extend({
nickjillings@1541 6705 fadeTo: function( speed, to, easing, callback ) {
nickjillings@1541 6706
nickjillings@1541 6707 // Show any hidden elements after setting opacity to 0
nickjillings@1541 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nickjillings@1541 6709
nickjillings@1541 6710 // Animate to the value specified
nickjillings@1541 6711 .end().animate({ opacity: to }, speed, easing, callback );
nickjillings@1541 6712 },
nickjillings@1541 6713 animate: function( prop, speed, easing, callback ) {
nickjillings@1541 6714 var empty = jQuery.isEmptyObject( prop ),
nickjillings@1541 6715 optall = jQuery.speed( speed, easing, callback ),
nickjillings@1541 6716 doAnimation = function() {
nickjillings@1541 6717 // Operate on a copy of prop so per-property easing won't be lost
nickjillings@1541 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nickjillings@1541 6719
nickjillings@1541 6720 // Empty animations, or finishing resolves immediately
nickjillings@1541 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nickjillings@1541 6722 anim.stop( true );
nickjillings@1541 6723 }
nickjillings@1541 6724 };
nickjillings@1541 6725 doAnimation.finish = doAnimation;
nickjillings@1541 6726
nickjillings@1541 6727 return empty || optall.queue === false ?
nickjillings@1541 6728 this.each( doAnimation ) :
nickjillings@1541 6729 this.queue( optall.queue, doAnimation );
nickjillings@1541 6730 },
nickjillings@1541 6731 stop: function( type, clearQueue, gotoEnd ) {
nickjillings@1541 6732 var stopQueue = function( hooks ) {
nickjillings@1541 6733 var stop = hooks.stop;
nickjillings@1541 6734 delete hooks.stop;
nickjillings@1541 6735 stop( gotoEnd );
nickjillings@1541 6736 };
nickjillings@1541 6737
nickjillings@1541 6738 if ( typeof type !== "string" ) {
nickjillings@1541 6739 gotoEnd = clearQueue;
nickjillings@1541 6740 clearQueue = type;
nickjillings@1541 6741 type = undefined;
nickjillings@1541 6742 }
nickjillings@1541 6743 if ( clearQueue && type !== false ) {
nickjillings@1541 6744 this.queue( type || "fx", [] );
nickjillings@1541 6745 }
nickjillings@1541 6746
nickjillings@1541 6747 return this.each(function() {
nickjillings@1541 6748 var dequeue = true,
nickjillings@1541 6749 index = type != null && type + "queueHooks",
nickjillings@1541 6750 timers = jQuery.timers,
nickjillings@1541 6751 data = data_priv.get( this );
nickjillings@1541 6752
nickjillings@1541 6753 if ( index ) {
nickjillings@1541 6754 if ( data[ index ] && data[ index ].stop ) {
nickjillings@1541 6755 stopQueue( data[ index ] );
nickjillings@1541 6756 }
nickjillings@1541 6757 } else {
nickjillings@1541 6758 for ( index in data ) {
nickjillings@1541 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nickjillings@1541 6760 stopQueue( data[ index ] );
nickjillings@1541 6761 }
nickjillings@1541 6762 }
nickjillings@1541 6763 }
nickjillings@1541 6764
nickjillings@1541 6765 for ( index = timers.length; index--; ) {
nickjillings@1541 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nickjillings@1541 6767 timers[ index ].anim.stop( gotoEnd );
nickjillings@1541 6768 dequeue = false;
nickjillings@1541 6769 timers.splice( index, 1 );
nickjillings@1541 6770 }
nickjillings@1541 6771 }
nickjillings@1541 6772
nickjillings@1541 6773 // Start the next in the queue if the last step wasn't forced.
nickjillings@1541 6774 // Timers currently will call their complete callbacks, which
nickjillings@1541 6775 // will dequeue but only if they were gotoEnd.
nickjillings@1541 6776 if ( dequeue || !gotoEnd ) {
nickjillings@1541 6777 jQuery.dequeue( this, type );
nickjillings@1541 6778 }
nickjillings@1541 6779 });
nickjillings@1541 6780 },
nickjillings@1541 6781 finish: function( type ) {
nickjillings@1541 6782 if ( type !== false ) {
nickjillings@1541 6783 type = type || "fx";
nickjillings@1541 6784 }
nickjillings@1541 6785 return this.each(function() {
nickjillings@1541 6786 var index,
nickjillings@1541 6787 data = data_priv.get( this ),
nickjillings@1541 6788 queue = data[ type + "queue" ],
nickjillings@1541 6789 hooks = data[ type + "queueHooks" ],
nickjillings@1541 6790 timers = jQuery.timers,
nickjillings@1541 6791 length = queue ? queue.length : 0;
nickjillings@1541 6792
nickjillings@1541 6793 // Enable finishing flag on private data
nickjillings@1541 6794 data.finish = true;
nickjillings@1541 6795
nickjillings@1541 6796 // Empty the queue first
nickjillings@1541 6797 jQuery.queue( this, type, [] );
nickjillings@1541 6798
nickjillings@1541 6799 if ( hooks && hooks.stop ) {
nickjillings@1541 6800 hooks.stop.call( this, true );
nickjillings@1541 6801 }
nickjillings@1541 6802
nickjillings@1541 6803 // Look for any active animations, and finish them
nickjillings@1541 6804 for ( index = timers.length; index--; ) {
nickjillings@1541 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nickjillings@1541 6806 timers[ index ].anim.stop( true );
nickjillings@1541 6807 timers.splice( index, 1 );
nickjillings@1541 6808 }
nickjillings@1541 6809 }
nickjillings@1541 6810
nickjillings@1541 6811 // Look for any animations in the old queue and finish them
nickjillings@1541 6812 for ( index = 0; index < length; index++ ) {
nickjillings@1541 6813 if ( queue[ index ] && queue[ index ].finish ) {
nickjillings@1541 6814 queue[ index ].finish.call( this );
nickjillings@1541 6815 }
nickjillings@1541 6816 }
nickjillings@1541 6817
nickjillings@1541 6818 // Turn off finishing flag
nickjillings@1541 6819 delete data.finish;
nickjillings@1541 6820 });
nickjillings@1541 6821 }
nickjillings@1541 6822 });
nickjillings@1541 6823
nickjillings@1541 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nickjillings@1541 6825 var cssFn = jQuery.fn[ name ];
nickjillings@1541 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1541 6827 return speed == null || typeof speed === "boolean" ?
nickjillings@1541 6828 cssFn.apply( this, arguments ) :
nickjillings@1541 6829 this.animate( genFx( name, true ), speed, easing, callback );
nickjillings@1541 6830 };
nickjillings@1541 6831 });
nickjillings@1541 6832
nickjillings@1541 6833 // Generate shortcuts for custom animations
nickjillings@1541 6834 jQuery.each({
nickjillings@1541 6835 slideDown: genFx("show"),
nickjillings@1541 6836 slideUp: genFx("hide"),
nickjillings@1541 6837 slideToggle: genFx("toggle"),
nickjillings@1541 6838 fadeIn: { opacity: "show" },
nickjillings@1541 6839 fadeOut: { opacity: "hide" },
nickjillings@1541 6840 fadeToggle: { opacity: "toggle" }
nickjillings@1541 6841 }, function( name, props ) {
nickjillings@1541 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1541 6843 return this.animate( props, speed, easing, callback );
nickjillings@1541 6844 };
nickjillings@1541 6845 });
nickjillings@1541 6846
nickjillings@1541 6847 jQuery.timers = [];
nickjillings@1541 6848 jQuery.fx.tick = function() {
nickjillings@1541 6849 var timer,
nickjillings@1541 6850 i = 0,
nickjillings@1541 6851 timers = jQuery.timers;
nickjillings@1541 6852
nickjillings@1541 6853 fxNow = jQuery.now();
nickjillings@1541 6854
nickjillings@1541 6855 for ( ; i < timers.length; i++ ) {
nickjillings@1541 6856 timer = timers[ i ];
nickjillings@1541 6857 // Checks the timer has not already been removed
nickjillings@1541 6858 if ( !timer() && timers[ i ] === timer ) {
nickjillings@1541 6859 timers.splice( i--, 1 );
nickjillings@1541 6860 }
nickjillings@1541 6861 }
nickjillings@1541 6862
nickjillings@1541 6863 if ( !timers.length ) {
nickjillings@1541 6864 jQuery.fx.stop();
nickjillings@1541 6865 }
nickjillings@1541 6866 fxNow = undefined;
nickjillings@1541 6867 };
nickjillings@1541 6868
nickjillings@1541 6869 jQuery.fx.timer = function( timer ) {
nickjillings@1541 6870 jQuery.timers.push( timer );
nickjillings@1541 6871 if ( timer() ) {
nickjillings@1541 6872 jQuery.fx.start();
nickjillings@1541 6873 } else {
nickjillings@1541 6874 jQuery.timers.pop();
nickjillings@1541 6875 }
nickjillings@1541 6876 };
nickjillings@1541 6877
nickjillings@1541 6878 jQuery.fx.interval = 13;
nickjillings@1541 6879
nickjillings@1541 6880 jQuery.fx.start = function() {
nickjillings@1541 6881 if ( !timerId ) {
nickjillings@1541 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nickjillings@1541 6883 }
nickjillings@1541 6884 };
nickjillings@1541 6885
nickjillings@1541 6886 jQuery.fx.stop = function() {
nickjillings@1541 6887 clearInterval( timerId );
nickjillings@1541 6888 timerId = null;
nickjillings@1541 6889 };
nickjillings@1541 6890
nickjillings@1541 6891 jQuery.fx.speeds = {
nickjillings@1541 6892 slow: 600,
nickjillings@1541 6893 fast: 200,
nickjillings@1541 6894 // Default speed
nickjillings@1541 6895 _default: 400
nickjillings@1541 6896 };
nickjillings@1541 6897
nickjillings@1541 6898
nickjillings@1541 6899 // Based off of the plugin by Clint Helfers, with permission.
nickjillings@1541 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nickjillings@1541 6901 jQuery.fn.delay = function( time, type ) {
nickjillings@1541 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nickjillings@1541 6903 type = type || "fx";
nickjillings@1541 6904
nickjillings@1541 6905 return this.queue( type, function( next, hooks ) {
nickjillings@1541 6906 var timeout = setTimeout( next, time );
nickjillings@1541 6907 hooks.stop = function() {
nickjillings@1541 6908 clearTimeout( timeout );
nickjillings@1541 6909 };
nickjillings@1541 6910 });
nickjillings@1541 6911 };
nickjillings@1541 6912
nickjillings@1541 6913
nickjillings@1541 6914 (function() {
nickjillings@1541 6915 var input = document.createElement( "input" ),
nickjillings@1541 6916 select = document.createElement( "select" ),
nickjillings@1541 6917 opt = select.appendChild( document.createElement( "option" ) );
nickjillings@1541 6918
nickjillings@1541 6919 input.type = "checkbox";
nickjillings@1541 6920
nickjillings@1541 6921 // Support: iOS<=5.1, Android<=4.2+
nickjillings@1541 6922 // Default value for a checkbox should be "on"
nickjillings@1541 6923 support.checkOn = input.value !== "";
nickjillings@1541 6924
nickjillings@1541 6925 // Support: IE<=11+
nickjillings@1541 6926 // Must access selectedIndex to make default options select
nickjillings@1541 6927 support.optSelected = opt.selected;
nickjillings@1541 6928
nickjillings@1541 6929 // Support: Android<=2.3
nickjillings@1541 6930 // Options inside disabled selects are incorrectly marked as disabled
nickjillings@1541 6931 select.disabled = true;
nickjillings@1541 6932 support.optDisabled = !opt.disabled;
nickjillings@1541 6933
nickjillings@1541 6934 // Support: IE<=11+
nickjillings@1541 6935 // An input loses its value after becoming a radio
nickjillings@1541 6936 input = document.createElement( "input" );
nickjillings@1541 6937 input.value = "t";
nickjillings@1541 6938 input.type = "radio";
nickjillings@1541 6939 support.radioValue = input.value === "t";
nickjillings@1541 6940 })();
nickjillings@1541 6941
nickjillings@1541 6942
nickjillings@1541 6943 var nodeHook, boolHook,
nickjillings@1541 6944 attrHandle = jQuery.expr.attrHandle;
nickjillings@1541 6945
nickjillings@1541 6946 jQuery.fn.extend({
nickjillings@1541 6947 attr: function( name, value ) {
nickjillings@1541 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nickjillings@1541 6949 },
nickjillings@1541 6950
nickjillings@1541 6951 removeAttr: function( name ) {
nickjillings@1541 6952 return this.each(function() {
nickjillings@1541 6953 jQuery.removeAttr( this, name );
nickjillings@1541 6954 });
nickjillings@1541 6955 }
nickjillings@1541 6956 });
nickjillings@1541 6957
nickjillings@1541 6958 jQuery.extend({
nickjillings@1541 6959 attr: function( elem, name, value ) {
nickjillings@1541 6960 var hooks, ret,
nickjillings@1541 6961 nType = elem.nodeType;
nickjillings@1541 6962
nickjillings@1541 6963 // don't get/set attributes on text, comment and attribute nodes
nickjillings@1541 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1541 6965 return;
nickjillings@1541 6966 }
nickjillings@1541 6967
nickjillings@1541 6968 // Fallback to prop when attributes are not supported
nickjillings@1541 6969 if ( typeof elem.getAttribute === strundefined ) {
nickjillings@1541 6970 return jQuery.prop( elem, name, value );
nickjillings@1541 6971 }
nickjillings@1541 6972
nickjillings@1541 6973 // All attributes are lowercase
nickjillings@1541 6974 // Grab necessary hook if one is defined
nickjillings@1541 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nickjillings@1541 6976 name = name.toLowerCase();
nickjillings@1541 6977 hooks = jQuery.attrHooks[ name ] ||
nickjillings@1541 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nickjillings@1541 6979 }
nickjillings@1541 6980
nickjillings@1541 6981 if ( value !== undefined ) {
nickjillings@1541 6982
nickjillings@1541 6983 if ( value === null ) {
nickjillings@1541 6984 jQuery.removeAttr( elem, name );
nickjillings@1541 6985
nickjillings@1541 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nickjillings@1541 6987 return ret;
nickjillings@1541 6988
nickjillings@1541 6989 } else {
nickjillings@1541 6990 elem.setAttribute( name, value + "" );
nickjillings@1541 6991 return value;
nickjillings@1541 6992 }
nickjillings@1541 6993
nickjillings@1541 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nickjillings@1541 6995 return ret;
nickjillings@1541 6996
nickjillings@1541 6997 } else {
nickjillings@1541 6998 ret = jQuery.find.attr( elem, name );
nickjillings@1541 6999
nickjillings@1541 7000 // Non-existent attributes return null, we normalize to undefined
nickjillings@1541 7001 return ret == null ?
nickjillings@1541 7002 undefined :
nickjillings@1541 7003 ret;
nickjillings@1541 7004 }
nickjillings@1541 7005 },
nickjillings@1541 7006
nickjillings@1541 7007 removeAttr: function( elem, value ) {
nickjillings@1541 7008 var name, propName,
nickjillings@1541 7009 i = 0,
nickjillings@1541 7010 attrNames = value && value.match( rnotwhite );
nickjillings@1541 7011
nickjillings@1541 7012 if ( attrNames && elem.nodeType === 1 ) {
nickjillings@1541 7013 while ( (name = attrNames[i++]) ) {
nickjillings@1541 7014 propName = jQuery.propFix[ name ] || name;
nickjillings@1541 7015
nickjillings@1541 7016 // Boolean attributes get special treatment (#10870)
nickjillings@1541 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nickjillings@1541 7018 // Set corresponding property to false
nickjillings@1541 7019 elem[ propName ] = false;
nickjillings@1541 7020 }
nickjillings@1541 7021
nickjillings@1541 7022 elem.removeAttribute( name );
nickjillings@1541 7023 }
nickjillings@1541 7024 }
nickjillings@1541 7025 },
nickjillings@1541 7026
nickjillings@1541 7027 attrHooks: {
nickjillings@1541 7028 type: {
nickjillings@1541 7029 set: function( elem, value ) {
nickjillings@1541 7030 if ( !support.radioValue && value === "radio" &&
nickjillings@1541 7031 jQuery.nodeName( elem, "input" ) ) {
nickjillings@1541 7032 var val = elem.value;
nickjillings@1541 7033 elem.setAttribute( "type", value );
nickjillings@1541 7034 if ( val ) {
nickjillings@1541 7035 elem.value = val;
nickjillings@1541 7036 }
nickjillings@1541 7037 return value;
nickjillings@1541 7038 }
nickjillings@1541 7039 }
nickjillings@1541 7040 }
nickjillings@1541 7041 }
nickjillings@1541 7042 });
nickjillings@1541 7043
nickjillings@1541 7044 // Hooks for boolean attributes
nickjillings@1541 7045 boolHook = {
nickjillings@1541 7046 set: function( elem, value, name ) {
nickjillings@1541 7047 if ( value === false ) {
nickjillings@1541 7048 // Remove boolean attributes when set to false
nickjillings@1541 7049 jQuery.removeAttr( elem, name );
nickjillings@1541 7050 } else {
nickjillings@1541 7051 elem.setAttribute( name, name );
nickjillings@1541 7052 }
nickjillings@1541 7053 return name;
nickjillings@1541 7054 }
nickjillings@1541 7055 };
nickjillings@1541 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nickjillings@1541 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nickjillings@1541 7058
nickjillings@1541 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nickjillings@1541 7060 var ret, handle;
nickjillings@1541 7061 if ( !isXML ) {
nickjillings@1541 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nickjillings@1541 7063 handle = attrHandle[ name ];
nickjillings@1541 7064 attrHandle[ name ] = ret;
nickjillings@1541 7065 ret = getter( elem, name, isXML ) != null ?
nickjillings@1541 7066 name.toLowerCase() :
nickjillings@1541 7067 null;
nickjillings@1541 7068 attrHandle[ name ] = handle;
nickjillings@1541 7069 }
nickjillings@1541 7070 return ret;
nickjillings@1541 7071 };
nickjillings@1541 7072 });
nickjillings@1541 7073
nickjillings@1541 7074
nickjillings@1541 7075
nickjillings@1541 7076
nickjillings@1541 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nickjillings@1541 7078
nickjillings@1541 7079 jQuery.fn.extend({
nickjillings@1541 7080 prop: function( name, value ) {
nickjillings@1541 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nickjillings@1541 7082 },
nickjillings@1541 7083
nickjillings@1541 7084 removeProp: function( name ) {
nickjillings@1541 7085 return this.each(function() {
nickjillings@1541 7086 delete this[ jQuery.propFix[ name ] || name ];
nickjillings@1541 7087 });
nickjillings@1541 7088 }
nickjillings@1541 7089 });
nickjillings@1541 7090
nickjillings@1541 7091 jQuery.extend({
nickjillings@1541 7092 propFix: {
nickjillings@1541 7093 "for": "htmlFor",
nickjillings@1541 7094 "class": "className"
nickjillings@1541 7095 },
nickjillings@1541 7096
nickjillings@1541 7097 prop: function( elem, name, value ) {
nickjillings@1541 7098 var ret, hooks, notxml,
nickjillings@1541 7099 nType = elem.nodeType;
nickjillings@1541 7100
nickjillings@1541 7101 // Don't get/set properties on text, comment and attribute nodes
nickjillings@1541 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1541 7103 return;
nickjillings@1541 7104 }
nickjillings@1541 7105
nickjillings@1541 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nickjillings@1541 7107
nickjillings@1541 7108 if ( notxml ) {
nickjillings@1541 7109 // Fix name and attach hooks
nickjillings@1541 7110 name = jQuery.propFix[ name ] || name;
nickjillings@1541 7111 hooks = jQuery.propHooks[ name ];
nickjillings@1541 7112 }
nickjillings@1541 7113
nickjillings@1541 7114 if ( value !== undefined ) {
nickjillings@1541 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nickjillings@1541 7116 ret :
nickjillings@1541 7117 ( elem[ name ] = value );
nickjillings@1541 7118
nickjillings@1541 7119 } else {
nickjillings@1541 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nickjillings@1541 7121 ret :
nickjillings@1541 7122 elem[ name ];
nickjillings@1541 7123 }
nickjillings@1541 7124 },
nickjillings@1541 7125
nickjillings@1541 7126 propHooks: {
nickjillings@1541 7127 tabIndex: {
nickjillings@1541 7128 get: function( elem ) {
nickjillings@1541 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nickjillings@1541 7130 elem.tabIndex :
nickjillings@1541 7131 -1;
nickjillings@1541 7132 }
nickjillings@1541 7133 }
nickjillings@1541 7134 }
nickjillings@1541 7135 });
nickjillings@1541 7136
nickjillings@1541 7137 if ( !support.optSelected ) {
nickjillings@1541 7138 jQuery.propHooks.selected = {
nickjillings@1541 7139 get: function( elem ) {
nickjillings@1541 7140 var parent = elem.parentNode;
nickjillings@1541 7141 if ( parent && parent.parentNode ) {
nickjillings@1541 7142 parent.parentNode.selectedIndex;
nickjillings@1541 7143 }
nickjillings@1541 7144 return null;
nickjillings@1541 7145 }
nickjillings@1541 7146 };
nickjillings@1541 7147 }
nickjillings@1541 7148
nickjillings@1541 7149 jQuery.each([
nickjillings@1541 7150 "tabIndex",
nickjillings@1541 7151 "readOnly",
nickjillings@1541 7152 "maxLength",
nickjillings@1541 7153 "cellSpacing",
nickjillings@1541 7154 "cellPadding",
nickjillings@1541 7155 "rowSpan",
nickjillings@1541 7156 "colSpan",
nickjillings@1541 7157 "useMap",
nickjillings@1541 7158 "frameBorder",
nickjillings@1541 7159 "contentEditable"
nickjillings@1541 7160 ], function() {
nickjillings@1541 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nickjillings@1541 7162 });
nickjillings@1541 7163
nickjillings@1541 7164
nickjillings@1541 7165
nickjillings@1541 7166
nickjillings@1541 7167 var rclass = /[\t\r\n\f]/g;
nickjillings@1541 7168
nickjillings@1541 7169 jQuery.fn.extend({
nickjillings@1541 7170 addClass: function( value ) {
nickjillings@1541 7171 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1541 7172 proceed = typeof value === "string" && value,
nickjillings@1541 7173 i = 0,
nickjillings@1541 7174 len = this.length;
nickjillings@1541 7175
nickjillings@1541 7176 if ( jQuery.isFunction( value ) ) {
nickjillings@1541 7177 return this.each(function( j ) {
nickjillings@1541 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nickjillings@1541 7179 });
nickjillings@1541 7180 }
nickjillings@1541 7181
nickjillings@1541 7182 if ( proceed ) {
nickjillings@1541 7183 // The disjunction here is for better compressibility (see removeClass)
nickjillings@1541 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1541 7185
nickjillings@1541 7186 for ( ; i < len; i++ ) {
nickjillings@1541 7187 elem = this[ i ];
nickjillings@1541 7188 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1541 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1541 7190 " "
nickjillings@1541 7191 );
nickjillings@1541 7192
nickjillings@1541 7193 if ( cur ) {
nickjillings@1541 7194 j = 0;
nickjillings@1541 7195 while ( (clazz = classes[j++]) ) {
nickjillings@1541 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nickjillings@1541 7197 cur += clazz + " ";
nickjillings@1541 7198 }
nickjillings@1541 7199 }
nickjillings@1541 7200
nickjillings@1541 7201 // only assign if different to avoid unneeded rendering.
nickjillings@1541 7202 finalValue = jQuery.trim( cur );
nickjillings@1541 7203 if ( elem.className !== finalValue ) {
nickjillings@1541 7204 elem.className = finalValue;
nickjillings@1541 7205 }
nickjillings@1541 7206 }
nickjillings@1541 7207 }
nickjillings@1541 7208 }
nickjillings@1541 7209
nickjillings@1541 7210 return this;
nickjillings@1541 7211 },
nickjillings@1541 7212
nickjillings@1541 7213 removeClass: function( value ) {
nickjillings@1541 7214 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1541 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nickjillings@1541 7216 i = 0,
nickjillings@1541 7217 len = this.length;
nickjillings@1541 7218
nickjillings@1541 7219 if ( jQuery.isFunction( value ) ) {
nickjillings@1541 7220 return this.each(function( j ) {
nickjillings@1541 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nickjillings@1541 7222 });
nickjillings@1541 7223 }
nickjillings@1541 7224 if ( proceed ) {
nickjillings@1541 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1541 7226
nickjillings@1541 7227 for ( ; i < len; i++ ) {
nickjillings@1541 7228 elem = this[ i ];
nickjillings@1541 7229 // This expression is here for better compressibility (see addClass)
nickjillings@1541 7230 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1541 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1541 7232 ""
nickjillings@1541 7233 );
nickjillings@1541 7234
nickjillings@1541 7235 if ( cur ) {
nickjillings@1541 7236 j = 0;
nickjillings@1541 7237 while ( (clazz = classes[j++]) ) {
nickjillings@1541 7238 // Remove *all* instances
nickjillings@1541 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nickjillings@1541 7240 cur = cur.replace( " " + clazz + " ", " " );
nickjillings@1541 7241 }
nickjillings@1541 7242 }
nickjillings@1541 7243
nickjillings@1541 7244 // Only assign if different to avoid unneeded rendering.
nickjillings@1541 7245 finalValue = value ? jQuery.trim( cur ) : "";
nickjillings@1541 7246 if ( elem.className !== finalValue ) {
nickjillings@1541 7247 elem.className = finalValue;
nickjillings@1541 7248 }
nickjillings@1541 7249 }
nickjillings@1541 7250 }
nickjillings@1541 7251 }
nickjillings@1541 7252
nickjillings@1541 7253 return this;
nickjillings@1541 7254 },
nickjillings@1541 7255
nickjillings@1541 7256 toggleClass: function( value, stateVal ) {
nickjillings@1541 7257 var type = typeof value;
nickjillings@1541 7258
nickjillings@1541 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nickjillings@1541 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nickjillings@1541 7261 }
nickjillings@1541 7262
nickjillings@1541 7263 if ( jQuery.isFunction( value ) ) {
nickjillings@1541 7264 return this.each(function( i ) {
nickjillings@1541 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nickjillings@1541 7266 });
nickjillings@1541 7267 }
nickjillings@1541 7268
nickjillings@1541 7269 return this.each(function() {
nickjillings@1541 7270 if ( type === "string" ) {
nickjillings@1541 7271 // Toggle individual class names
nickjillings@1541 7272 var className,
nickjillings@1541 7273 i = 0,
nickjillings@1541 7274 self = jQuery( this ),
nickjillings@1541 7275 classNames = value.match( rnotwhite ) || [];
nickjillings@1541 7276
nickjillings@1541 7277 while ( (className = classNames[ i++ ]) ) {
nickjillings@1541 7278 // Check each className given, space separated list
nickjillings@1541 7279 if ( self.hasClass( className ) ) {
nickjillings@1541 7280 self.removeClass( className );
nickjillings@1541 7281 } else {
nickjillings@1541 7282 self.addClass( className );
nickjillings@1541 7283 }
nickjillings@1541 7284 }
nickjillings@1541 7285
nickjillings@1541 7286 // Toggle whole class name
nickjillings@1541 7287 } else if ( type === strundefined || type === "boolean" ) {
nickjillings@1541 7288 if ( this.className ) {
nickjillings@1541 7289 // store className if set
nickjillings@1541 7290 data_priv.set( this, "__className__", this.className );
nickjillings@1541 7291 }
nickjillings@1541 7292
nickjillings@1541 7293 // If the element has a class name or if we're passed `false`,
nickjillings@1541 7294 // then remove the whole classname (if there was one, the above saved it).
nickjillings@1541 7295 // Otherwise bring back whatever was previously saved (if anything),
nickjillings@1541 7296 // falling back to the empty string if nothing was stored.
nickjillings@1541 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nickjillings@1541 7298 }
nickjillings@1541 7299 });
nickjillings@1541 7300 },
nickjillings@1541 7301
nickjillings@1541 7302 hasClass: function( selector ) {
nickjillings@1541 7303 var className = " " + selector + " ",
nickjillings@1541 7304 i = 0,
nickjillings@1541 7305 l = this.length;
nickjillings@1541 7306 for ( ; i < l; i++ ) {
nickjillings@1541 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nickjillings@1541 7308 return true;
nickjillings@1541 7309 }
nickjillings@1541 7310 }
nickjillings@1541 7311
nickjillings@1541 7312 return false;
nickjillings@1541 7313 }
nickjillings@1541 7314 });
nickjillings@1541 7315
nickjillings@1541 7316
nickjillings@1541 7317
nickjillings@1541 7318
nickjillings@1541 7319 var rreturn = /\r/g;
nickjillings@1541 7320
nickjillings@1541 7321 jQuery.fn.extend({
nickjillings@1541 7322 val: function( value ) {
nickjillings@1541 7323 var hooks, ret, isFunction,
nickjillings@1541 7324 elem = this[0];
nickjillings@1541 7325
nickjillings@1541 7326 if ( !arguments.length ) {
nickjillings@1541 7327 if ( elem ) {
nickjillings@1541 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nickjillings@1541 7329
nickjillings@1541 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nickjillings@1541 7331 return ret;
nickjillings@1541 7332 }
nickjillings@1541 7333
nickjillings@1541 7334 ret = elem.value;
nickjillings@1541 7335
nickjillings@1541 7336 return typeof ret === "string" ?
nickjillings@1541 7337 // Handle most common string cases
nickjillings@1541 7338 ret.replace(rreturn, "") :
nickjillings@1541 7339 // Handle cases where value is null/undef or number
nickjillings@1541 7340 ret == null ? "" : ret;
nickjillings@1541 7341 }
nickjillings@1541 7342
nickjillings@1541 7343 return;
nickjillings@1541 7344 }
nickjillings@1541 7345
nickjillings@1541 7346 isFunction = jQuery.isFunction( value );
nickjillings@1541 7347
nickjillings@1541 7348 return this.each(function( i ) {
nickjillings@1541 7349 var val;
nickjillings@1541 7350
nickjillings@1541 7351 if ( this.nodeType !== 1 ) {
nickjillings@1541 7352 return;
nickjillings@1541 7353 }
nickjillings@1541 7354
nickjillings@1541 7355 if ( isFunction ) {
nickjillings@1541 7356 val = value.call( this, i, jQuery( this ).val() );
nickjillings@1541 7357 } else {
nickjillings@1541 7358 val = value;
nickjillings@1541 7359 }
nickjillings@1541 7360
nickjillings@1541 7361 // Treat null/undefined as ""; convert numbers to string
nickjillings@1541 7362 if ( val == null ) {
nickjillings@1541 7363 val = "";
nickjillings@1541 7364
nickjillings@1541 7365 } else if ( typeof val === "number" ) {
nickjillings@1541 7366 val += "";
nickjillings@1541 7367
nickjillings@1541 7368 } else if ( jQuery.isArray( val ) ) {
nickjillings@1541 7369 val = jQuery.map( val, function( value ) {
nickjillings@1541 7370 return value == null ? "" : value + "";
nickjillings@1541 7371 });
nickjillings@1541 7372 }
nickjillings@1541 7373
nickjillings@1541 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nickjillings@1541 7375
nickjillings@1541 7376 // If set returns undefined, fall back to normal setting
nickjillings@1541 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nickjillings@1541 7378 this.value = val;
nickjillings@1541 7379 }
nickjillings@1541 7380 });
nickjillings@1541 7381 }
nickjillings@1541 7382 });
nickjillings@1541 7383
nickjillings@1541 7384 jQuery.extend({
nickjillings@1541 7385 valHooks: {
nickjillings@1541 7386 option: {
nickjillings@1541 7387 get: function( elem ) {
nickjillings@1541 7388 var val = jQuery.find.attr( elem, "value" );
nickjillings@1541 7389 return val != null ?
nickjillings@1541 7390 val :
nickjillings@1541 7391 // Support: IE10-11+
nickjillings@1541 7392 // option.text throws exceptions (#14686, #14858)
nickjillings@1541 7393 jQuery.trim( jQuery.text( elem ) );
nickjillings@1541 7394 }
nickjillings@1541 7395 },
nickjillings@1541 7396 select: {
nickjillings@1541 7397 get: function( elem ) {
nickjillings@1541 7398 var value, option,
nickjillings@1541 7399 options = elem.options,
nickjillings@1541 7400 index = elem.selectedIndex,
nickjillings@1541 7401 one = elem.type === "select-one" || index < 0,
nickjillings@1541 7402 values = one ? null : [],
nickjillings@1541 7403 max = one ? index + 1 : options.length,
nickjillings@1541 7404 i = index < 0 ?
nickjillings@1541 7405 max :
nickjillings@1541 7406 one ? index : 0;
nickjillings@1541 7407
nickjillings@1541 7408 // Loop through all the selected options
nickjillings@1541 7409 for ( ; i < max; i++ ) {
nickjillings@1541 7410 option = options[ i ];
nickjillings@1541 7411
nickjillings@1541 7412 // IE6-9 doesn't update selected after form reset (#2551)
nickjillings@1541 7413 if ( ( option.selected || i === index ) &&
nickjillings@1541 7414 // Don't return options that are disabled or in a disabled optgroup
nickjillings@1541 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nickjillings@1541 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nickjillings@1541 7417
nickjillings@1541 7418 // Get the specific value for the option
nickjillings@1541 7419 value = jQuery( option ).val();
nickjillings@1541 7420
nickjillings@1541 7421 // We don't need an array for one selects
nickjillings@1541 7422 if ( one ) {
nickjillings@1541 7423 return value;
nickjillings@1541 7424 }
nickjillings@1541 7425
nickjillings@1541 7426 // Multi-Selects return an array
nickjillings@1541 7427 values.push( value );
nickjillings@1541 7428 }
nickjillings@1541 7429 }
nickjillings@1541 7430
nickjillings@1541 7431 return values;
nickjillings@1541 7432 },
nickjillings@1541 7433
nickjillings@1541 7434 set: function( elem, value ) {
nickjillings@1541 7435 var optionSet, option,
nickjillings@1541 7436 options = elem.options,
nickjillings@1541 7437 values = jQuery.makeArray( value ),
nickjillings@1541 7438 i = options.length;
nickjillings@1541 7439
nickjillings@1541 7440 while ( i-- ) {
nickjillings@1541 7441 option = options[ i ];
nickjillings@1541 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nickjillings@1541 7443 optionSet = true;
nickjillings@1541 7444 }
nickjillings@1541 7445 }
nickjillings@1541 7446
nickjillings@1541 7447 // Force browsers to behave consistently when non-matching value is set
nickjillings@1541 7448 if ( !optionSet ) {
nickjillings@1541 7449 elem.selectedIndex = -1;
nickjillings@1541 7450 }
nickjillings@1541 7451 return values;
nickjillings@1541 7452 }
nickjillings@1541 7453 }
nickjillings@1541 7454 }
nickjillings@1541 7455 });
nickjillings@1541 7456
nickjillings@1541 7457 // Radios and checkboxes getter/setter
nickjillings@1541 7458 jQuery.each([ "radio", "checkbox" ], function() {
nickjillings@1541 7459 jQuery.valHooks[ this ] = {
nickjillings@1541 7460 set: function( elem, value ) {
nickjillings@1541 7461 if ( jQuery.isArray( value ) ) {
nickjillings@1541 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nickjillings@1541 7463 }
nickjillings@1541 7464 }
nickjillings@1541 7465 };
nickjillings@1541 7466 if ( !support.checkOn ) {
nickjillings@1541 7467 jQuery.valHooks[ this ].get = function( elem ) {
nickjillings@1541 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nickjillings@1541 7469 };
nickjillings@1541 7470 }
nickjillings@1541 7471 });
nickjillings@1541 7472
nickjillings@1541 7473
nickjillings@1541 7474
nickjillings@1541 7475
nickjillings@1541 7476 // Return jQuery for attributes-only inclusion
nickjillings@1541 7477
nickjillings@1541 7478
nickjillings@1541 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nickjillings@1541 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nickjillings@1541 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nickjillings@1541 7482
nickjillings@1541 7483 // Handle event binding
nickjillings@1541 7484 jQuery.fn[ name ] = function( data, fn ) {
nickjillings@1541 7485 return arguments.length > 0 ?
nickjillings@1541 7486 this.on( name, null, data, fn ) :
nickjillings@1541 7487 this.trigger( name );
nickjillings@1541 7488 };
nickjillings@1541 7489 });
nickjillings@1541 7490
nickjillings@1541 7491 jQuery.fn.extend({
nickjillings@1541 7492 hover: function( fnOver, fnOut ) {
nickjillings@1541 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nickjillings@1541 7494 },
nickjillings@1541 7495
nickjillings@1541 7496 bind: function( types, data, fn ) {
nickjillings@1541 7497 return this.on( types, null, data, fn );
nickjillings@1541 7498 },
nickjillings@1541 7499 unbind: function( types, fn ) {
nickjillings@1541 7500 return this.off( types, null, fn );
nickjillings@1541 7501 },
nickjillings@1541 7502
nickjillings@1541 7503 delegate: function( selector, types, data, fn ) {
nickjillings@1541 7504 return this.on( types, selector, data, fn );
nickjillings@1541 7505 },
nickjillings@1541 7506 undelegate: function( selector, types, fn ) {
nickjillings@1541 7507 // ( namespace ) or ( selector, types [, fn] )
nickjillings@1541 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nickjillings@1541 7509 }
nickjillings@1541 7510 });
nickjillings@1541 7511
nickjillings@1541 7512
nickjillings@1541 7513 var nonce = jQuery.now();
nickjillings@1541 7514
nickjillings@1541 7515 var rquery = (/\?/);
nickjillings@1541 7516
nickjillings@1541 7517
nickjillings@1541 7518
nickjillings@1541 7519 // Support: Android 2.3
nickjillings@1541 7520 // Workaround failure to string-cast null input
nickjillings@1541 7521 jQuery.parseJSON = function( data ) {
nickjillings@1541 7522 return JSON.parse( data + "" );
nickjillings@1541 7523 };
nickjillings@1541 7524
nickjillings@1541 7525
nickjillings@1541 7526 // Cross-browser xml parsing
nickjillings@1541 7527 jQuery.parseXML = function( data ) {
nickjillings@1541 7528 var xml, tmp;
nickjillings@1541 7529 if ( !data || typeof data !== "string" ) {
nickjillings@1541 7530 return null;
nickjillings@1541 7531 }
nickjillings@1541 7532
nickjillings@1541 7533 // Support: IE9
nickjillings@1541 7534 try {
nickjillings@1541 7535 tmp = new DOMParser();
nickjillings@1541 7536 xml = tmp.parseFromString( data, "text/xml" );
nickjillings@1541 7537 } catch ( e ) {
nickjillings@1541 7538 xml = undefined;
nickjillings@1541 7539 }
nickjillings@1541 7540
nickjillings@1541 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nickjillings@1541 7542 jQuery.error( "Invalid XML: " + data );
nickjillings@1541 7543 }
nickjillings@1541 7544 return xml;
nickjillings@1541 7545 };
nickjillings@1541 7546
nickjillings@1541 7547
nickjillings@1541 7548 var
nickjillings@1541 7549 rhash = /#.*$/,
nickjillings@1541 7550 rts = /([?&])_=[^&]*/,
nickjillings@1541 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nickjillings@1541 7552 // #7653, #8125, #8152: local protocol detection
nickjillings@1541 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nickjillings@1541 7554 rnoContent = /^(?:GET|HEAD)$/,
nickjillings@1541 7555 rprotocol = /^\/\//,
nickjillings@1541 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nickjillings@1541 7557
nickjillings@1541 7558 /* Prefilters
nickjillings@1541 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nickjillings@1541 7560 * 2) These are called:
nickjillings@1541 7561 * - BEFORE asking for a transport
nickjillings@1541 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nickjillings@1541 7563 * 3) key is the dataType
nickjillings@1541 7564 * 4) the catchall symbol "*" can be used
nickjillings@1541 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nickjillings@1541 7566 */
nickjillings@1541 7567 prefilters = {},
nickjillings@1541 7568
nickjillings@1541 7569 /* Transports bindings
nickjillings@1541 7570 * 1) key is the dataType
nickjillings@1541 7571 * 2) the catchall symbol "*" can be used
nickjillings@1541 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nickjillings@1541 7573 */
nickjillings@1541 7574 transports = {},
nickjillings@1541 7575
nickjillings@1541 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nickjillings@1541 7577 allTypes = "*/".concat( "*" ),
nickjillings@1541 7578
nickjillings@1541 7579 // Document location
nickjillings@1541 7580 ajaxLocation = window.location.href,
nickjillings@1541 7581
nickjillings@1541 7582 // Segment location into parts
nickjillings@1541 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nickjillings@1541 7584
nickjillings@1541 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nickjillings@1541 7586 function addToPrefiltersOrTransports( structure ) {
nickjillings@1541 7587
nickjillings@1541 7588 // dataTypeExpression is optional and defaults to "*"
nickjillings@1541 7589 return function( dataTypeExpression, func ) {
nickjillings@1541 7590
nickjillings@1541 7591 if ( typeof dataTypeExpression !== "string" ) {
nickjillings@1541 7592 func = dataTypeExpression;
nickjillings@1541 7593 dataTypeExpression = "*";
nickjillings@1541 7594 }
nickjillings@1541 7595
nickjillings@1541 7596 var dataType,
nickjillings@1541 7597 i = 0,
nickjillings@1541 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nickjillings@1541 7599
nickjillings@1541 7600 if ( jQuery.isFunction( func ) ) {
nickjillings@1541 7601 // For each dataType in the dataTypeExpression
nickjillings@1541 7602 while ( (dataType = dataTypes[i++]) ) {
nickjillings@1541 7603 // Prepend if requested
nickjillings@1541 7604 if ( dataType[0] === "+" ) {
nickjillings@1541 7605 dataType = dataType.slice( 1 ) || "*";
nickjillings@1541 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nickjillings@1541 7607
nickjillings@1541 7608 // Otherwise append
nickjillings@1541 7609 } else {
nickjillings@1541 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nickjillings@1541 7611 }
nickjillings@1541 7612 }
nickjillings@1541 7613 }
nickjillings@1541 7614 };
nickjillings@1541 7615 }
nickjillings@1541 7616
nickjillings@1541 7617 // Base inspection function for prefilters and transports
nickjillings@1541 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nickjillings@1541 7619
nickjillings@1541 7620 var inspected = {},
nickjillings@1541 7621 seekingTransport = ( structure === transports );
nickjillings@1541 7622
nickjillings@1541 7623 function inspect( dataType ) {
nickjillings@1541 7624 var selected;
nickjillings@1541 7625 inspected[ dataType ] = true;
nickjillings@1541 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nickjillings@1541 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nickjillings@1541 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nickjillings@1541 7629 options.dataTypes.unshift( dataTypeOrTransport );
nickjillings@1541 7630 inspect( dataTypeOrTransport );
nickjillings@1541 7631 return false;
nickjillings@1541 7632 } else if ( seekingTransport ) {
nickjillings@1541 7633 return !( selected = dataTypeOrTransport );
nickjillings@1541 7634 }
nickjillings@1541 7635 });
nickjillings@1541 7636 return selected;
nickjillings@1541 7637 }
nickjillings@1541 7638
nickjillings@1541 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nickjillings@1541 7640 }
nickjillings@1541 7641
nickjillings@1541 7642 // A special extend for ajax options
nickjillings@1541 7643 // that takes "flat" options (not to be deep extended)
nickjillings@1541 7644 // Fixes #9887
nickjillings@1541 7645 function ajaxExtend( target, src ) {
nickjillings@1541 7646 var key, deep,
nickjillings@1541 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nickjillings@1541 7648
nickjillings@1541 7649 for ( key in src ) {
nickjillings@1541 7650 if ( src[ key ] !== undefined ) {
nickjillings@1541 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nickjillings@1541 7652 }
nickjillings@1541 7653 }
nickjillings@1541 7654 if ( deep ) {
nickjillings@1541 7655 jQuery.extend( true, target, deep );
nickjillings@1541 7656 }
nickjillings@1541 7657
nickjillings@1541 7658 return target;
nickjillings@1541 7659 }
nickjillings@1541 7660
nickjillings@1541 7661 /* Handles responses to an ajax request:
nickjillings@1541 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nickjillings@1541 7663 * - returns the corresponding response
nickjillings@1541 7664 */
nickjillings@1541 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nickjillings@1541 7666
nickjillings@1541 7667 var ct, type, finalDataType, firstDataType,
nickjillings@1541 7668 contents = s.contents,
nickjillings@1541 7669 dataTypes = s.dataTypes;
nickjillings@1541 7670
nickjillings@1541 7671 // Remove auto dataType and get content-type in the process
nickjillings@1541 7672 while ( dataTypes[ 0 ] === "*" ) {
nickjillings@1541 7673 dataTypes.shift();
nickjillings@1541 7674 if ( ct === undefined ) {
nickjillings@1541 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nickjillings@1541 7676 }
nickjillings@1541 7677 }
nickjillings@1541 7678
nickjillings@1541 7679 // Check if we're dealing with a known content-type
nickjillings@1541 7680 if ( ct ) {
nickjillings@1541 7681 for ( type in contents ) {
nickjillings@1541 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nickjillings@1541 7683 dataTypes.unshift( type );
nickjillings@1541 7684 break;
nickjillings@1541 7685 }
nickjillings@1541 7686 }
nickjillings@1541 7687 }
nickjillings@1541 7688
nickjillings@1541 7689 // Check to see if we have a response for the expected dataType
nickjillings@1541 7690 if ( dataTypes[ 0 ] in responses ) {
nickjillings@1541 7691 finalDataType = dataTypes[ 0 ];
nickjillings@1541 7692 } else {
nickjillings@1541 7693 // Try convertible dataTypes
nickjillings@1541 7694 for ( type in responses ) {
nickjillings@1541 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nickjillings@1541 7696 finalDataType = type;
nickjillings@1541 7697 break;
nickjillings@1541 7698 }
nickjillings@1541 7699 if ( !firstDataType ) {
nickjillings@1541 7700 firstDataType = type;
nickjillings@1541 7701 }
nickjillings@1541 7702 }
nickjillings@1541 7703 // Or just use first one
nickjillings@1541 7704 finalDataType = finalDataType || firstDataType;
nickjillings@1541 7705 }
nickjillings@1541 7706
nickjillings@1541 7707 // If we found a dataType
nickjillings@1541 7708 // We add the dataType to the list if needed
nickjillings@1541 7709 // and return the corresponding response
nickjillings@1541 7710 if ( finalDataType ) {
nickjillings@1541 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nickjillings@1541 7712 dataTypes.unshift( finalDataType );
nickjillings@1541 7713 }
nickjillings@1541 7714 return responses[ finalDataType ];
nickjillings@1541 7715 }
nickjillings@1541 7716 }
nickjillings@1541 7717
nickjillings@1541 7718 /* Chain conversions given the request and the original response
nickjillings@1541 7719 * Also sets the responseXXX fields on the jqXHR instance
nickjillings@1541 7720 */
nickjillings@1541 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nickjillings@1541 7722 var conv2, current, conv, tmp, prev,
nickjillings@1541 7723 converters = {},
nickjillings@1541 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nickjillings@1541 7725 dataTypes = s.dataTypes.slice();
nickjillings@1541 7726
nickjillings@1541 7727 // Create converters map with lowercased keys
nickjillings@1541 7728 if ( dataTypes[ 1 ] ) {
nickjillings@1541 7729 for ( conv in s.converters ) {
nickjillings@1541 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nickjillings@1541 7731 }
nickjillings@1541 7732 }
nickjillings@1541 7733
nickjillings@1541 7734 current = dataTypes.shift();
nickjillings@1541 7735
nickjillings@1541 7736 // Convert to each sequential dataType
nickjillings@1541 7737 while ( current ) {
nickjillings@1541 7738
nickjillings@1541 7739 if ( s.responseFields[ current ] ) {
nickjillings@1541 7740 jqXHR[ s.responseFields[ current ] ] = response;
nickjillings@1541 7741 }
nickjillings@1541 7742
nickjillings@1541 7743 // Apply the dataFilter if provided
nickjillings@1541 7744 if ( !prev && isSuccess && s.dataFilter ) {
nickjillings@1541 7745 response = s.dataFilter( response, s.dataType );
nickjillings@1541 7746 }
nickjillings@1541 7747
nickjillings@1541 7748 prev = current;
nickjillings@1541 7749 current = dataTypes.shift();
nickjillings@1541 7750
nickjillings@1541 7751 if ( current ) {
nickjillings@1541 7752
nickjillings@1541 7753 // There's only work to do if current dataType is non-auto
nickjillings@1541 7754 if ( current === "*" ) {
nickjillings@1541 7755
nickjillings@1541 7756 current = prev;
nickjillings@1541 7757
nickjillings@1541 7758 // Convert response if prev dataType is non-auto and differs from current
nickjillings@1541 7759 } else if ( prev !== "*" && prev !== current ) {
nickjillings@1541 7760
nickjillings@1541 7761 // Seek a direct converter
nickjillings@1541 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nickjillings@1541 7763
nickjillings@1541 7764 // If none found, seek a pair
nickjillings@1541 7765 if ( !conv ) {
nickjillings@1541 7766 for ( conv2 in converters ) {
nickjillings@1541 7767
nickjillings@1541 7768 // If conv2 outputs current
nickjillings@1541 7769 tmp = conv2.split( " " );
nickjillings@1541 7770 if ( tmp[ 1 ] === current ) {
nickjillings@1541 7771
nickjillings@1541 7772 // If prev can be converted to accepted input
nickjillings@1541 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nickjillings@1541 7774 converters[ "* " + tmp[ 0 ] ];
nickjillings@1541 7775 if ( conv ) {
nickjillings@1541 7776 // Condense equivalence converters
nickjillings@1541 7777 if ( conv === true ) {
nickjillings@1541 7778 conv = converters[ conv2 ];
nickjillings@1541 7779
nickjillings@1541 7780 // Otherwise, insert the intermediate dataType
nickjillings@1541 7781 } else if ( converters[ conv2 ] !== true ) {
nickjillings@1541 7782 current = tmp[ 0 ];
nickjillings@1541 7783 dataTypes.unshift( tmp[ 1 ] );
nickjillings@1541 7784 }
nickjillings@1541 7785 break;
nickjillings@1541 7786 }
nickjillings@1541 7787 }
nickjillings@1541 7788 }
nickjillings@1541 7789 }
nickjillings@1541 7790
nickjillings@1541 7791 // Apply converter (if not an equivalence)
nickjillings@1541 7792 if ( conv !== true ) {
nickjillings@1541 7793
nickjillings@1541 7794 // Unless errors are allowed to bubble, catch and return them
nickjillings@1541 7795 if ( conv && s[ "throws" ] ) {
nickjillings@1541 7796 response = conv( response );
nickjillings@1541 7797 } else {
nickjillings@1541 7798 try {
nickjillings@1541 7799 response = conv( response );
nickjillings@1541 7800 } catch ( e ) {
nickjillings@1541 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nickjillings@1541 7802 }
nickjillings@1541 7803 }
nickjillings@1541 7804 }
nickjillings@1541 7805 }
nickjillings@1541 7806 }
nickjillings@1541 7807 }
nickjillings@1541 7808
nickjillings@1541 7809 return { state: "success", data: response };
nickjillings@1541 7810 }
nickjillings@1541 7811
nickjillings@1541 7812 jQuery.extend({
nickjillings@1541 7813
nickjillings@1541 7814 // Counter for holding the number of active queries
nickjillings@1541 7815 active: 0,
nickjillings@1541 7816
nickjillings@1541 7817 // Last-Modified header cache for next request
nickjillings@1541 7818 lastModified: {},
nickjillings@1541 7819 etag: {},
nickjillings@1541 7820
nickjillings@1541 7821 ajaxSettings: {
nickjillings@1541 7822 url: ajaxLocation,
nickjillings@1541 7823 type: "GET",
nickjillings@1541 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nickjillings@1541 7825 global: true,
nickjillings@1541 7826 processData: true,
nickjillings@1541 7827 async: true,
nickjillings@1541 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nickjillings@1541 7829 /*
nickjillings@1541 7830 timeout: 0,
nickjillings@1541 7831 data: null,
nickjillings@1541 7832 dataType: null,
nickjillings@1541 7833 username: null,
nickjillings@1541 7834 password: null,
nickjillings@1541 7835 cache: null,
nickjillings@1541 7836 throws: false,
nickjillings@1541 7837 traditional: false,
nickjillings@1541 7838 headers: {},
nickjillings@1541 7839 */
nickjillings@1541 7840
nickjillings@1541 7841 accepts: {
nickjillings@1541 7842 "*": allTypes,
nickjillings@1541 7843 text: "text/plain",
nickjillings@1541 7844 html: "text/html",
nickjillings@1541 7845 xml: "application/xml, text/xml",
nickjillings@1541 7846 json: "application/json, text/javascript"
nickjillings@1541 7847 },
nickjillings@1541 7848
nickjillings@1541 7849 contents: {
nickjillings@1541 7850 xml: /xml/,
nickjillings@1541 7851 html: /html/,
nickjillings@1541 7852 json: /json/
nickjillings@1541 7853 },
nickjillings@1541 7854
nickjillings@1541 7855 responseFields: {
nickjillings@1541 7856 xml: "responseXML",
nickjillings@1541 7857 text: "responseText",
nickjillings@1541 7858 json: "responseJSON"
nickjillings@1541 7859 },
nickjillings@1541 7860
nickjillings@1541 7861 // Data converters
nickjillings@1541 7862 // Keys separate source (or catchall "*") and destination types with a single space
nickjillings@1541 7863 converters: {
nickjillings@1541 7864
nickjillings@1541 7865 // Convert anything to text
nickjillings@1541 7866 "* text": String,
nickjillings@1541 7867
nickjillings@1541 7868 // Text to html (true = no transformation)
nickjillings@1541 7869 "text html": true,
nickjillings@1541 7870
nickjillings@1541 7871 // Evaluate text as a json expression
nickjillings@1541 7872 "text json": jQuery.parseJSON,
nickjillings@1541 7873
nickjillings@1541 7874 // Parse text as xml
nickjillings@1541 7875 "text xml": jQuery.parseXML
nickjillings@1541 7876 },
nickjillings@1541 7877
nickjillings@1541 7878 // For options that shouldn't be deep extended:
nickjillings@1541 7879 // you can add your own custom options here if
nickjillings@1541 7880 // and when you create one that shouldn't be
nickjillings@1541 7881 // deep extended (see ajaxExtend)
nickjillings@1541 7882 flatOptions: {
nickjillings@1541 7883 url: true,
nickjillings@1541 7884 context: true
nickjillings@1541 7885 }
nickjillings@1541 7886 },
nickjillings@1541 7887
nickjillings@1541 7888 // Creates a full fledged settings object into target
nickjillings@1541 7889 // with both ajaxSettings and settings fields.
nickjillings@1541 7890 // If target is omitted, writes into ajaxSettings.
nickjillings@1541 7891 ajaxSetup: function( target, settings ) {
nickjillings@1541 7892 return settings ?
nickjillings@1541 7893
nickjillings@1541 7894 // Building a settings object
nickjillings@1541 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nickjillings@1541 7896
nickjillings@1541 7897 // Extending ajaxSettings
nickjillings@1541 7898 ajaxExtend( jQuery.ajaxSettings, target );
nickjillings@1541 7899 },
nickjillings@1541 7900
nickjillings@1541 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nickjillings@1541 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nickjillings@1541 7903
nickjillings@1541 7904 // Main method
nickjillings@1541 7905 ajax: function( url, options ) {
nickjillings@1541 7906
nickjillings@1541 7907 // If url is an object, simulate pre-1.5 signature
nickjillings@1541 7908 if ( typeof url === "object" ) {
nickjillings@1541 7909 options = url;
nickjillings@1541 7910 url = undefined;
nickjillings@1541 7911 }
nickjillings@1541 7912
nickjillings@1541 7913 // Force options to be an object
nickjillings@1541 7914 options = options || {};
nickjillings@1541 7915
nickjillings@1541 7916 var transport,
nickjillings@1541 7917 // URL without anti-cache param
nickjillings@1541 7918 cacheURL,
nickjillings@1541 7919 // Response headers
nickjillings@1541 7920 responseHeadersString,
nickjillings@1541 7921 responseHeaders,
nickjillings@1541 7922 // timeout handle
nickjillings@1541 7923 timeoutTimer,
nickjillings@1541 7924 // Cross-domain detection vars
nickjillings@1541 7925 parts,
nickjillings@1541 7926 // To know if global events are to be dispatched
nickjillings@1541 7927 fireGlobals,
nickjillings@1541 7928 // Loop variable
nickjillings@1541 7929 i,
nickjillings@1541 7930 // Create the final options object
nickjillings@1541 7931 s = jQuery.ajaxSetup( {}, options ),
nickjillings@1541 7932 // Callbacks context
nickjillings@1541 7933 callbackContext = s.context || s,
nickjillings@1541 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nickjillings@1541 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nickjillings@1541 7936 jQuery( callbackContext ) :
nickjillings@1541 7937 jQuery.event,
nickjillings@1541 7938 // Deferreds
nickjillings@1541 7939 deferred = jQuery.Deferred(),
nickjillings@1541 7940 completeDeferred = jQuery.Callbacks("once memory"),
nickjillings@1541 7941 // Status-dependent callbacks
nickjillings@1541 7942 statusCode = s.statusCode || {},
nickjillings@1541 7943 // Headers (they are sent all at once)
nickjillings@1541 7944 requestHeaders = {},
nickjillings@1541 7945 requestHeadersNames = {},
nickjillings@1541 7946 // The jqXHR state
nickjillings@1541 7947 state = 0,
nickjillings@1541 7948 // Default abort message
nickjillings@1541 7949 strAbort = "canceled",
nickjillings@1541 7950 // Fake xhr
nickjillings@1541 7951 jqXHR = {
nickjillings@1541 7952 readyState: 0,
nickjillings@1541 7953
nickjillings@1541 7954 // Builds headers hashtable if needed
nickjillings@1541 7955 getResponseHeader: function( key ) {
nickjillings@1541 7956 var match;
nickjillings@1541 7957 if ( state === 2 ) {
nickjillings@1541 7958 if ( !responseHeaders ) {
nickjillings@1541 7959 responseHeaders = {};
nickjillings@1541 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nickjillings@1541 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nickjillings@1541 7962 }
nickjillings@1541 7963 }
nickjillings@1541 7964 match = responseHeaders[ key.toLowerCase() ];
nickjillings@1541 7965 }
nickjillings@1541 7966 return match == null ? null : match;
nickjillings@1541 7967 },
nickjillings@1541 7968
nickjillings@1541 7969 // Raw string
nickjillings@1541 7970 getAllResponseHeaders: function() {
nickjillings@1541 7971 return state === 2 ? responseHeadersString : null;
nickjillings@1541 7972 },
nickjillings@1541 7973
nickjillings@1541 7974 // Caches the header
nickjillings@1541 7975 setRequestHeader: function( name, value ) {
nickjillings@1541 7976 var lname = name.toLowerCase();
nickjillings@1541 7977 if ( !state ) {
nickjillings@1541 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nickjillings@1541 7979 requestHeaders[ name ] = value;
nickjillings@1541 7980 }
nickjillings@1541 7981 return this;
nickjillings@1541 7982 },
nickjillings@1541 7983
nickjillings@1541 7984 // Overrides response content-type header
nickjillings@1541 7985 overrideMimeType: function( type ) {
nickjillings@1541 7986 if ( !state ) {
nickjillings@1541 7987 s.mimeType = type;
nickjillings@1541 7988 }
nickjillings@1541 7989 return this;
nickjillings@1541 7990 },
nickjillings@1541 7991
nickjillings@1541 7992 // Status-dependent callbacks
nickjillings@1541 7993 statusCode: function( map ) {
nickjillings@1541 7994 var code;
nickjillings@1541 7995 if ( map ) {
nickjillings@1541 7996 if ( state < 2 ) {
nickjillings@1541 7997 for ( code in map ) {
nickjillings@1541 7998 // Lazy-add the new callback in a way that preserves old ones
nickjillings@1541 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nickjillings@1541 8000 }
nickjillings@1541 8001 } else {
nickjillings@1541 8002 // Execute the appropriate callbacks
nickjillings@1541 8003 jqXHR.always( map[ jqXHR.status ] );
nickjillings@1541 8004 }
nickjillings@1541 8005 }
nickjillings@1541 8006 return this;
nickjillings@1541 8007 },
nickjillings@1541 8008
nickjillings@1541 8009 // Cancel the request
nickjillings@1541 8010 abort: function( statusText ) {
nickjillings@1541 8011 var finalText = statusText || strAbort;
nickjillings@1541 8012 if ( transport ) {
nickjillings@1541 8013 transport.abort( finalText );
nickjillings@1541 8014 }
nickjillings@1541 8015 done( 0, finalText );
nickjillings@1541 8016 return this;
nickjillings@1541 8017 }
nickjillings@1541 8018 };
nickjillings@1541 8019
nickjillings@1541 8020 // Attach deferreds
nickjillings@1541 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nickjillings@1541 8022 jqXHR.success = jqXHR.done;
nickjillings@1541 8023 jqXHR.error = jqXHR.fail;
nickjillings@1541 8024
nickjillings@1541 8025 // Remove hash character (#7531: and string promotion)
nickjillings@1541 8026 // Add protocol if not provided (prefilters might expect it)
nickjillings@1541 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nickjillings@1541 8028 // We also use the url parameter if available
nickjillings@1541 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nickjillings@1541 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nickjillings@1541 8031
nickjillings@1541 8032 // Alias method option to type as per ticket #12004
nickjillings@1541 8033 s.type = options.method || options.type || s.method || s.type;
nickjillings@1541 8034
nickjillings@1541 8035 // Extract dataTypes list
nickjillings@1541 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nickjillings@1541 8037
nickjillings@1541 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nickjillings@1541 8039 if ( s.crossDomain == null ) {
nickjillings@1541 8040 parts = rurl.exec( s.url.toLowerCase() );
nickjillings@1541 8041 s.crossDomain = !!( parts &&
nickjillings@1541 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nickjillings@1541 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nickjillings@1541 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nickjillings@1541 8045 );
nickjillings@1541 8046 }
nickjillings@1541 8047
nickjillings@1541 8048 // Convert data if not already a string
nickjillings@1541 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nickjillings@1541 8050 s.data = jQuery.param( s.data, s.traditional );
nickjillings@1541 8051 }
nickjillings@1541 8052
nickjillings@1541 8053 // Apply prefilters
nickjillings@1541 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nickjillings@1541 8055
nickjillings@1541 8056 // If request was aborted inside a prefilter, stop there
nickjillings@1541 8057 if ( state === 2 ) {
nickjillings@1541 8058 return jqXHR;
nickjillings@1541 8059 }
nickjillings@1541 8060
nickjillings@1541 8061 // We can fire global events as of now if asked to
nickjillings@1541 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nickjillings@1541 8063 fireGlobals = jQuery.event && s.global;
nickjillings@1541 8064
nickjillings@1541 8065 // Watch for a new set of requests
nickjillings@1541 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nickjillings@1541 8067 jQuery.event.trigger("ajaxStart");
nickjillings@1541 8068 }
nickjillings@1541 8069
nickjillings@1541 8070 // Uppercase the type
nickjillings@1541 8071 s.type = s.type.toUpperCase();
nickjillings@1541 8072
nickjillings@1541 8073 // Determine if request has content
nickjillings@1541 8074 s.hasContent = !rnoContent.test( s.type );
nickjillings@1541 8075
nickjillings@1541 8076 // Save the URL in case we're toying with the If-Modified-Since
nickjillings@1541 8077 // and/or If-None-Match header later on
nickjillings@1541 8078 cacheURL = s.url;
nickjillings@1541 8079
nickjillings@1541 8080 // More options handling for requests with no content
nickjillings@1541 8081 if ( !s.hasContent ) {
nickjillings@1541 8082
nickjillings@1541 8083 // If data is available, append data to url
nickjillings@1541 8084 if ( s.data ) {
nickjillings@1541 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nickjillings@1541 8086 // #9682: remove data so that it's not used in an eventual retry
nickjillings@1541 8087 delete s.data;
nickjillings@1541 8088 }
nickjillings@1541 8089
nickjillings@1541 8090 // Add anti-cache in url if needed
nickjillings@1541 8091 if ( s.cache === false ) {
nickjillings@1541 8092 s.url = rts.test( cacheURL ) ?
nickjillings@1541 8093
nickjillings@1541 8094 // If there is already a '_' parameter, set its value
nickjillings@1541 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nickjillings@1541 8096
nickjillings@1541 8097 // Otherwise add one to the end
nickjillings@1541 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nickjillings@1541 8099 }
nickjillings@1541 8100 }
nickjillings@1541 8101
nickjillings@1541 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1541 8103 if ( s.ifModified ) {
nickjillings@1541 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nickjillings@1541 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nickjillings@1541 8106 }
nickjillings@1541 8107 if ( jQuery.etag[ cacheURL ] ) {
nickjillings@1541 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nickjillings@1541 8109 }
nickjillings@1541 8110 }
nickjillings@1541 8111
nickjillings@1541 8112 // Set the correct header, if data is being sent
nickjillings@1541 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nickjillings@1541 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nickjillings@1541 8115 }
nickjillings@1541 8116
nickjillings@1541 8117 // Set the Accepts header for the server, depending on the dataType
nickjillings@1541 8118 jqXHR.setRequestHeader(
nickjillings@1541 8119 "Accept",
nickjillings@1541 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nickjillings@1541 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nickjillings@1541 8122 s.accepts[ "*" ]
nickjillings@1541 8123 );
nickjillings@1541 8124
nickjillings@1541 8125 // Check for headers option
nickjillings@1541 8126 for ( i in s.headers ) {
nickjillings@1541 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nickjillings@1541 8128 }
nickjillings@1541 8129
nickjillings@1541 8130 // Allow custom headers/mimetypes and early abort
nickjillings@1541 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nickjillings@1541 8132 // Abort if not done already and return
nickjillings@1541 8133 return jqXHR.abort();
nickjillings@1541 8134 }
nickjillings@1541 8135
nickjillings@1541 8136 // Aborting is no longer a cancellation
nickjillings@1541 8137 strAbort = "abort";
nickjillings@1541 8138
nickjillings@1541 8139 // Install callbacks on deferreds
nickjillings@1541 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nickjillings@1541 8141 jqXHR[ i ]( s[ i ] );
nickjillings@1541 8142 }
nickjillings@1541 8143
nickjillings@1541 8144 // Get transport
nickjillings@1541 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nickjillings@1541 8146
nickjillings@1541 8147 // If no transport, we auto-abort
nickjillings@1541 8148 if ( !transport ) {
nickjillings@1541 8149 done( -1, "No Transport" );
nickjillings@1541 8150 } else {
nickjillings@1541 8151 jqXHR.readyState = 1;
nickjillings@1541 8152
nickjillings@1541 8153 // Send global event
nickjillings@1541 8154 if ( fireGlobals ) {
nickjillings@1541 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nickjillings@1541 8156 }
nickjillings@1541 8157 // Timeout
nickjillings@1541 8158 if ( s.async && s.timeout > 0 ) {
nickjillings@1541 8159 timeoutTimer = setTimeout(function() {
nickjillings@1541 8160 jqXHR.abort("timeout");
nickjillings@1541 8161 }, s.timeout );
nickjillings@1541 8162 }
nickjillings@1541 8163
nickjillings@1541 8164 try {
nickjillings@1541 8165 state = 1;
nickjillings@1541 8166 transport.send( requestHeaders, done );
nickjillings@1541 8167 } catch ( e ) {
nickjillings@1541 8168 // Propagate exception as error if not done
nickjillings@1541 8169 if ( state < 2 ) {
nickjillings@1541 8170 done( -1, e );
nickjillings@1541 8171 // Simply rethrow otherwise
nickjillings@1541 8172 } else {
nickjillings@1541 8173 throw e;
nickjillings@1541 8174 }
nickjillings@1541 8175 }
nickjillings@1541 8176 }
nickjillings@1541 8177
nickjillings@1541 8178 // Callback for when everything is done
nickjillings@1541 8179 function done( status, nativeStatusText, responses, headers ) {
nickjillings@1541 8180 var isSuccess, success, error, response, modified,
nickjillings@1541 8181 statusText = nativeStatusText;
nickjillings@1541 8182
nickjillings@1541 8183 // Called once
nickjillings@1541 8184 if ( state === 2 ) {
nickjillings@1541 8185 return;
nickjillings@1541 8186 }
nickjillings@1541 8187
nickjillings@1541 8188 // State is "done" now
nickjillings@1541 8189 state = 2;
nickjillings@1541 8190
nickjillings@1541 8191 // Clear timeout if it exists
nickjillings@1541 8192 if ( timeoutTimer ) {
nickjillings@1541 8193 clearTimeout( timeoutTimer );
nickjillings@1541 8194 }
nickjillings@1541 8195
nickjillings@1541 8196 // Dereference transport for early garbage collection
nickjillings@1541 8197 // (no matter how long the jqXHR object will be used)
nickjillings@1541 8198 transport = undefined;
nickjillings@1541 8199
nickjillings@1541 8200 // Cache response headers
nickjillings@1541 8201 responseHeadersString = headers || "";
nickjillings@1541 8202
nickjillings@1541 8203 // Set readyState
nickjillings@1541 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nickjillings@1541 8205
nickjillings@1541 8206 // Determine if successful
nickjillings@1541 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nickjillings@1541 8208
nickjillings@1541 8209 // Get response data
nickjillings@1541 8210 if ( responses ) {
nickjillings@1541 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nickjillings@1541 8212 }
nickjillings@1541 8213
nickjillings@1541 8214 // Convert no matter what (that way responseXXX fields are always set)
nickjillings@1541 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nickjillings@1541 8216
nickjillings@1541 8217 // If successful, handle type chaining
nickjillings@1541 8218 if ( isSuccess ) {
nickjillings@1541 8219
nickjillings@1541 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1541 8221 if ( s.ifModified ) {
nickjillings@1541 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nickjillings@1541 8223 if ( modified ) {
nickjillings@1541 8224 jQuery.lastModified[ cacheURL ] = modified;
nickjillings@1541 8225 }
nickjillings@1541 8226 modified = jqXHR.getResponseHeader("etag");
nickjillings@1541 8227 if ( modified ) {
nickjillings@1541 8228 jQuery.etag[ cacheURL ] = modified;
nickjillings@1541 8229 }
nickjillings@1541 8230 }
nickjillings@1541 8231
nickjillings@1541 8232 // if no content
nickjillings@1541 8233 if ( status === 204 || s.type === "HEAD" ) {
nickjillings@1541 8234 statusText = "nocontent";
nickjillings@1541 8235
nickjillings@1541 8236 // if not modified
nickjillings@1541 8237 } else if ( status === 304 ) {
nickjillings@1541 8238 statusText = "notmodified";
nickjillings@1541 8239
nickjillings@1541 8240 // If we have data, let's convert it
nickjillings@1541 8241 } else {
nickjillings@1541 8242 statusText = response.state;
nickjillings@1541 8243 success = response.data;
nickjillings@1541 8244 error = response.error;
nickjillings@1541 8245 isSuccess = !error;
nickjillings@1541 8246 }
nickjillings@1541 8247 } else {
nickjillings@1541 8248 // Extract error from statusText and normalize for non-aborts
nickjillings@1541 8249 error = statusText;
nickjillings@1541 8250 if ( status || !statusText ) {
nickjillings@1541 8251 statusText = "error";
nickjillings@1541 8252 if ( status < 0 ) {
nickjillings@1541 8253 status = 0;
nickjillings@1541 8254 }
nickjillings@1541 8255 }
nickjillings@1541 8256 }
nickjillings@1541 8257
nickjillings@1541 8258 // Set data for the fake xhr object
nickjillings@1541 8259 jqXHR.status = status;
nickjillings@1541 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nickjillings@1541 8261
nickjillings@1541 8262 // Success/Error
nickjillings@1541 8263 if ( isSuccess ) {
nickjillings@1541 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nickjillings@1541 8265 } else {
nickjillings@1541 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nickjillings@1541 8267 }
nickjillings@1541 8268
nickjillings@1541 8269 // Status-dependent callbacks
nickjillings@1541 8270 jqXHR.statusCode( statusCode );
nickjillings@1541 8271 statusCode = undefined;
nickjillings@1541 8272
nickjillings@1541 8273 if ( fireGlobals ) {
nickjillings@1541 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nickjillings@1541 8275 [ jqXHR, s, isSuccess ? success : error ] );
nickjillings@1541 8276 }
nickjillings@1541 8277
nickjillings@1541 8278 // Complete
nickjillings@1541 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nickjillings@1541 8280
nickjillings@1541 8281 if ( fireGlobals ) {
nickjillings@1541 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nickjillings@1541 8283 // Handle the global AJAX counter
nickjillings@1541 8284 if ( !( --jQuery.active ) ) {
nickjillings@1541 8285 jQuery.event.trigger("ajaxStop");
nickjillings@1541 8286 }
nickjillings@1541 8287 }
nickjillings@1541 8288 }
nickjillings@1541 8289
nickjillings@1541 8290 return jqXHR;
nickjillings@1541 8291 },
nickjillings@1541 8292
nickjillings@1541 8293 getJSON: function( url, data, callback ) {
nickjillings@1541 8294 return jQuery.get( url, data, callback, "json" );
nickjillings@1541 8295 },
nickjillings@1541 8296
nickjillings@1541 8297 getScript: function( url, callback ) {
nickjillings@1541 8298 return jQuery.get( url, undefined, callback, "script" );
nickjillings@1541 8299 }
nickjillings@1541 8300 });
nickjillings@1541 8301
nickjillings@1541 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nickjillings@1541 8303 jQuery[ method ] = function( url, data, callback, type ) {
nickjillings@1541 8304 // Shift arguments if data argument was omitted
nickjillings@1541 8305 if ( jQuery.isFunction( data ) ) {
nickjillings@1541 8306 type = type || callback;
nickjillings@1541 8307 callback = data;
nickjillings@1541 8308 data = undefined;
nickjillings@1541 8309 }
nickjillings@1541 8310
nickjillings@1541 8311 return jQuery.ajax({
nickjillings@1541 8312 url: url,
nickjillings@1541 8313 type: method,
nickjillings@1541 8314 dataType: type,
nickjillings@1541 8315 data: data,
nickjillings@1541 8316 success: callback
nickjillings@1541 8317 });
nickjillings@1541 8318 };
nickjillings@1541 8319 });
nickjillings@1541 8320
nickjillings@1541 8321
nickjillings@1541 8322 jQuery._evalUrl = function( url ) {
nickjillings@1541 8323 return jQuery.ajax({
nickjillings@1541 8324 url: url,
nickjillings@1541 8325 type: "GET",
nickjillings@1541 8326 dataType: "script",
nickjillings@1541 8327 async: false,
nickjillings@1541 8328 global: false,
nickjillings@1541 8329 "throws": true
nickjillings@1541 8330 });
nickjillings@1541 8331 };
nickjillings@1541 8332
nickjillings@1541 8333
nickjillings@1541 8334 jQuery.fn.extend({
nickjillings@1541 8335 wrapAll: function( html ) {
nickjillings@1541 8336 var wrap;
nickjillings@1541 8337
nickjillings@1541 8338 if ( jQuery.isFunction( html ) ) {
nickjillings@1541 8339 return this.each(function( i ) {
nickjillings@1541 8340 jQuery( this ).wrapAll( html.call(this, i) );
nickjillings@1541 8341 });
nickjillings@1541 8342 }
nickjillings@1541 8343
nickjillings@1541 8344 if ( this[ 0 ] ) {
nickjillings@1541 8345
nickjillings@1541 8346 // The elements to wrap the target around
nickjillings@1541 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nickjillings@1541 8348
nickjillings@1541 8349 if ( this[ 0 ].parentNode ) {
nickjillings@1541 8350 wrap.insertBefore( this[ 0 ] );
nickjillings@1541 8351 }
nickjillings@1541 8352
nickjillings@1541 8353 wrap.map(function() {
nickjillings@1541 8354 var elem = this;
nickjillings@1541 8355
nickjillings@1541 8356 while ( elem.firstElementChild ) {
nickjillings@1541 8357 elem = elem.firstElementChild;
nickjillings@1541 8358 }
nickjillings@1541 8359
nickjillings@1541 8360 return elem;
nickjillings@1541 8361 }).append( this );
nickjillings@1541 8362 }
nickjillings@1541 8363
nickjillings@1541 8364 return this;
nickjillings@1541 8365 },
nickjillings@1541 8366
nickjillings@1541 8367 wrapInner: function( html ) {
nickjillings@1541 8368 if ( jQuery.isFunction( html ) ) {
nickjillings@1541 8369 return this.each(function( i ) {
nickjillings@1541 8370 jQuery( this ).wrapInner( html.call(this, i) );
nickjillings@1541 8371 });
nickjillings@1541 8372 }
nickjillings@1541 8373
nickjillings@1541 8374 return this.each(function() {
nickjillings@1541 8375 var self = jQuery( this ),
nickjillings@1541 8376 contents = self.contents();
nickjillings@1541 8377
nickjillings@1541 8378 if ( contents.length ) {
nickjillings@1541 8379 contents.wrapAll( html );
nickjillings@1541 8380
nickjillings@1541 8381 } else {
nickjillings@1541 8382 self.append( html );
nickjillings@1541 8383 }
nickjillings@1541 8384 });
nickjillings@1541 8385 },
nickjillings@1541 8386
nickjillings@1541 8387 wrap: function( html ) {
nickjillings@1541 8388 var isFunction = jQuery.isFunction( html );
nickjillings@1541 8389
nickjillings@1541 8390 return this.each(function( i ) {
nickjillings@1541 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nickjillings@1541 8392 });
nickjillings@1541 8393 },
nickjillings@1541 8394
nickjillings@1541 8395 unwrap: function() {
nickjillings@1541 8396 return this.parent().each(function() {
nickjillings@1541 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nickjillings@1541 8398 jQuery( this ).replaceWith( this.childNodes );
nickjillings@1541 8399 }
nickjillings@1541 8400 }).end();
nickjillings@1541 8401 }
nickjillings@1541 8402 });
nickjillings@1541 8403
nickjillings@1541 8404
nickjillings@1541 8405 jQuery.expr.filters.hidden = function( elem ) {
nickjillings@1541 8406 // Support: Opera <= 12.12
nickjillings@1541 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nickjillings@1541 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nickjillings@1541 8409 };
nickjillings@1541 8410 jQuery.expr.filters.visible = function( elem ) {
nickjillings@1541 8411 return !jQuery.expr.filters.hidden( elem );
nickjillings@1541 8412 };
nickjillings@1541 8413
nickjillings@1541 8414
nickjillings@1541 8415
nickjillings@1541 8416
nickjillings@1541 8417 var r20 = /%20/g,
nickjillings@1541 8418 rbracket = /\[\]$/,
nickjillings@1541 8419 rCRLF = /\r?\n/g,
nickjillings@1541 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nickjillings@1541 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nickjillings@1541 8422
nickjillings@1541 8423 function buildParams( prefix, obj, traditional, add ) {
nickjillings@1541 8424 var name;
nickjillings@1541 8425
nickjillings@1541 8426 if ( jQuery.isArray( obj ) ) {
nickjillings@1541 8427 // Serialize array item.
nickjillings@1541 8428 jQuery.each( obj, function( i, v ) {
nickjillings@1541 8429 if ( traditional || rbracket.test( prefix ) ) {
nickjillings@1541 8430 // Treat each array item as a scalar.
nickjillings@1541 8431 add( prefix, v );
nickjillings@1541 8432
nickjillings@1541 8433 } else {
nickjillings@1541 8434 // Item is non-scalar (array or object), encode its numeric index.
nickjillings@1541 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nickjillings@1541 8436 }
nickjillings@1541 8437 });
nickjillings@1541 8438
nickjillings@1541 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nickjillings@1541 8440 // Serialize object item.
nickjillings@1541 8441 for ( name in obj ) {
nickjillings@1541 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nickjillings@1541 8443 }
nickjillings@1541 8444
nickjillings@1541 8445 } else {
nickjillings@1541 8446 // Serialize scalar item.
nickjillings@1541 8447 add( prefix, obj );
nickjillings@1541 8448 }
nickjillings@1541 8449 }
nickjillings@1541 8450
nickjillings@1541 8451 // Serialize an array of form elements or a set of
nickjillings@1541 8452 // key/values into a query string
nickjillings@1541 8453 jQuery.param = function( a, traditional ) {
nickjillings@1541 8454 var prefix,
nickjillings@1541 8455 s = [],
nickjillings@1541 8456 add = function( key, value ) {
nickjillings@1541 8457 // If value is a function, invoke it and return its value
nickjillings@1541 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nickjillings@1541 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nickjillings@1541 8460 };
nickjillings@1541 8461
nickjillings@1541 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nickjillings@1541 8463 if ( traditional === undefined ) {
nickjillings@1541 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nickjillings@1541 8465 }
nickjillings@1541 8466
nickjillings@1541 8467 // If an array was passed in, assume that it is an array of form elements.
nickjillings@1541 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nickjillings@1541 8469 // Serialize the form elements
nickjillings@1541 8470 jQuery.each( a, function() {
nickjillings@1541 8471 add( this.name, this.value );
nickjillings@1541 8472 });
nickjillings@1541 8473
nickjillings@1541 8474 } else {
nickjillings@1541 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nickjillings@1541 8476 // did it), otherwise encode params recursively.
nickjillings@1541 8477 for ( prefix in a ) {
nickjillings@1541 8478 buildParams( prefix, a[ prefix ], traditional, add );
nickjillings@1541 8479 }
nickjillings@1541 8480 }
nickjillings@1541 8481
nickjillings@1541 8482 // Return the resulting serialization
nickjillings@1541 8483 return s.join( "&" ).replace( r20, "+" );
nickjillings@1541 8484 };
nickjillings@1541 8485
nickjillings@1541 8486 jQuery.fn.extend({
nickjillings@1541 8487 serialize: function() {
nickjillings@1541 8488 return jQuery.param( this.serializeArray() );
nickjillings@1541 8489 },
nickjillings@1541 8490 serializeArray: function() {
nickjillings@1541 8491 return this.map(function() {
nickjillings@1541 8492 // Can add propHook for "elements" to filter or add form elements
nickjillings@1541 8493 var elements = jQuery.prop( this, "elements" );
nickjillings@1541 8494 return elements ? jQuery.makeArray( elements ) : this;
nickjillings@1541 8495 })
nickjillings@1541 8496 .filter(function() {
nickjillings@1541 8497 var type = this.type;
nickjillings@1541 8498
nickjillings@1541 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nickjillings@1541 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nickjillings@1541 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nickjillings@1541 8502 ( this.checked || !rcheckableType.test( type ) );
nickjillings@1541 8503 })
nickjillings@1541 8504 .map(function( i, elem ) {
nickjillings@1541 8505 var val = jQuery( this ).val();
nickjillings@1541 8506
nickjillings@1541 8507 return val == null ?
nickjillings@1541 8508 null :
nickjillings@1541 8509 jQuery.isArray( val ) ?
nickjillings@1541 8510 jQuery.map( val, function( val ) {
nickjillings@1541 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1541 8512 }) :
nickjillings@1541 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1541 8514 }).get();
nickjillings@1541 8515 }
nickjillings@1541 8516 });
nickjillings@1541 8517
nickjillings@1541 8518
nickjillings@1541 8519 jQuery.ajaxSettings.xhr = function() {
nickjillings@1541 8520 try {
nickjillings@1541 8521 return new XMLHttpRequest();
nickjillings@1541 8522 } catch( e ) {}
nickjillings@1541 8523 };
nickjillings@1541 8524
nickjillings@1541 8525 var xhrId = 0,
nickjillings@1541 8526 xhrCallbacks = {},
nickjillings@1541 8527 xhrSuccessStatus = {
nickjillings@1541 8528 // file protocol always yields status code 0, assume 200
nickjillings@1541 8529 0: 200,
nickjillings@1541 8530 // Support: IE9
nickjillings@1541 8531 // #1450: sometimes IE returns 1223 when it should be 204
nickjillings@1541 8532 1223: 204
nickjillings@1541 8533 },
nickjillings@1541 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nickjillings@1541 8535
nickjillings@1541 8536 // Support: IE9
nickjillings@1541 8537 // Open requests must be manually aborted on unload (#5280)
nickjillings@1541 8538 // See https://support.microsoft.com/kb/2856746 for more info
nickjillings@1541 8539 if ( window.attachEvent ) {
nickjillings@1541 8540 window.attachEvent( "onunload", function() {
nickjillings@1541 8541 for ( var key in xhrCallbacks ) {
nickjillings@1541 8542 xhrCallbacks[ key ]();
nickjillings@1541 8543 }
nickjillings@1541 8544 });
nickjillings@1541 8545 }
nickjillings@1541 8546
nickjillings@1541 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nickjillings@1541 8548 support.ajax = xhrSupported = !!xhrSupported;
nickjillings@1541 8549
nickjillings@1541 8550 jQuery.ajaxTransport(function( options ) {
nickjillings@1541 8551 var callback;
nickjillings@1541 8552
nickjillings@1541 8553 // Cross domain only allowed if supported through XMLHttpRequest
nickjillings@1541 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nickjillings@1541 8555 return {
nickjillings@1541 8556 send: function( headers, complete ) {
nickjillings@1541 8557 var i,
nickjillings@1541 8558 xhr = options.xhr(),
nickjillings@1541 8559 id = ++xhrId;
nickjillings@1541 8560
nickjillings@1541 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nickjillings@1541 8562
nickjillings@1541 8563 // Apply custom fields if provided
nickjillings@1541 8564 if ( options.xhrFields ) {
nickjillings@1541 8565 for ( i in options.xhrFields ) {
nickjillings@1541 8566 xhr[ i ] = options.xhrFields[ i ];
nickjillings@1541 8567 }
nickjillings@1541 8568 }
nickjillings@1541 8569
nickjillings@1541 8570 // Override mime type if needed
nickjillings@1541 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nickjillings@1541 8572 xhr.overrideMimeType( options.mimeType );
nickjillings@1541 8573 }
nickjillings@1541 8574
nickjillings@1541 8575 // X-Requested-With header
nickjillings@1541 8576 // For cross-domain requests, seeing as conditions for a preflight are
nickjillings@1541 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nickjillings@1541 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nickjillings@1541 8579 // For same-domain requests, won't change header if already provided.
nickjillings@1541 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nickjillings@1541 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nickjillings@1541 8582 }
nickjillings@1541 8583
nickjillings@1541 8584 // Set headers
nickjillings@1541 8585 for ( i in headers ) {
nickjillings@1541 8586 xhr.setRequestHeader( i, headers[ i ] );
nickjillings@1541 8587 }
nickjillings@1541 8588
nickjillings@1541 8589 // Callback
nickjillings@1541 8590 callback = function( type ) {
nickjillings@1541 8591 return function() {
nickjillings@1541 8592 if ( callback ) {
nickjillings@1541 8593 delete xhrCallbacks[ id ];
nickjillings@1541 8594 callback = xhr.onload = xhr.onerror = null;
nickjillings@1541 8595
nickjillings@1541 8596 if ( type === "abort" ) {
nickjillings@1541 8597 xhr.abort();
nickjillings@1541 8598 } else if ( type === "error" ) {
nickjillings@1541 8599 complete(
nickjillings@1541 8600 // file: protocol always yields status 0; see #8605, #14207
nickjillings@1541 8601 xhr.status,
nickjillings@1541 8602 xhr.statusText
nickjillings@1541 8603 );
nickjillings@1541 8604 } else {
nickjillings@1541 8605 complete(
nickjillings@1541 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nickjillings@1541 8607 xhr.statusText,
nickjillings@1541 8608 // Support: IE9
nickjillings@1541 8609 // Accessing binary-data responseText throws an exception
nickjillings@1541 8610 // (#11426)
nickjillings@1541 8611 typeof xhr.responseText === "string" ? {
nickjillings@1541 8612 text: xhr.responseText
nickjillings@1541 8613 } : undefined,
nickjillings@1541 8614 xhr.getAllResponseHeaders()
nickjillings@1541 8615 );
nickjillings@1541 8616 }
nickjillings@1541 8617 }
nickjillings@1541 8618 };
nickjillings@1541 8619 };
nickjillings@1541 8620
nickjillings@1541 8621 // Listen to events
nickjillings@1541 8622 xhr.onload = callback();
nickjillings@1541 8623 xhr.onerror = callback("error");
nickjillings@1541 8624
nickjillings@1541 8625 // Create the abort callback
nickjillings@1541 8626 callback = xhrCallbacks[ id ] = callback("abort");
nickjillings@1541 8627
nickjillings@1541 8628 try {
nickjillings@1541 8629 // Do send the request (this may raise an exception)
nickjillings@1541 8630 xhr.send( options.hasContent && options.data || null );
nickjillings@1541 8631 } catch ( e ) {
nickjillings@1541 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nickjillings@1541 8633 if ( callback ) {
nickjillings@1541 8634 throw e;
nickjillings@1541 8635 }
nickjillings@1541 8636 }
nickjillings@1541 8637 },
nickjillings@1541 8638
nickjillings@1541 8639 abort: function() {
nickjillings@1541 8640 if ( callback ) {
nickjillings@1541 8641 callback();
nickjillings@1541 8642 }
nickjillings@1541 8643 }
nickjillings@1541 8644 };
nickjillings@1541 8645 }
nickjillings@1541 8646 });
nickjillings@1541 8647
nickjillings@1541 8648
nickjillings@1541 8649
nickjillings@1541 8650
nickjillings@1541 8651 // Install script dataType
nickjillings@1541 8652 jQuery.ajaxSetup({
nickjillings@1541 8653 accepts: {
nickjillings@1541 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nickjillings@1541 8655 },
nickjillings@1541 8656 contents: {
nickjillings@1541 8657 script: /(?:java|ecma)script/
nickjillings@1541 8658 },
nickjillings@1541 8659 converters: {
nickjillings@1541 8660 "text script": function( text ) {
nickjillings@1541 8661 jQuery.globalEval( text );
nickjillings@1541 8662 return text;
nickjillings@1541 8663 }
nickjillings@1541 8664 }
nickjillings@1541 8665 });
nickjillings@1541 8666
nickjillings@1541 8667 // Handle cache's special case and crossDomain
nickjillings@1541 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nickjillings@1541 8669 if ( s.cache === undefined ) {
nickjillings@1541 8670 s.cache = false;
nickjillings@1541 8671 }
nickjillings@1541 8672 if ( s.crossDomain ) {
nickjillings@1541 8673 s.type = "GET";
nickjillings@1541 8674 }
nickjillings@1541 8675 });
nickjillings@1541 8676
nickjillings@1541 8677 // Bind script tag hack transport
nickjillings@1541 8678 jQuery.ajaxTransport( "script", function( s ) {
nickjillings@1541 8679 // This transport only deals with cross domain requests
nickjillings@1541 8680 if ( s.crossDomain ) {
nickjillings@1541 8681 var script, callback;
nickjillings@1541 8682 return {
nickjillings@1541 8683 send: function( _, complete ) {
nickjillings@1541 8684 script = jQuery("<script>").prop({
nickjillings@1541 8685 async: true,
nickjillings@1541 8686 charset: s.scriptCharset,
nickjillings@1541 8687 src: s.url
nickjillings@1541 8688 }).on(
nickjillings@1541 8689 "load error",
nickjillings@1541 8690 callback = function( evt ) {
nickjillings@1541 8691 script.remove();
nickjillings@1541 8692 callback = null;
nickjillings@1541 8693 if ( evt ) {
nickjillings@1541 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nickjillings@1541 8695 }
nickjillings@1541 8696 }
nickjillings@1541 8697 );
nickjillings@1541 8698 document.head.appendChild( script[ 0 ] );
nickjillings@1541 8699 },
nickjillings@1541 8700 abort: function() {
nickjillings@1541 8701 if ( callback ) {
nickjillings@1541 8702 callback();
nickjillings@1541 8703 }
nickjillings@1541 8704 }
nickjillings@1541 8705 };
nickjillings@1541 8706 }
nickjillings@1541 8707 });
nickjillings@1541 8708
nickjillings@1541 8709
nickjillings@1541 8710
nickjillings@1541 8711
nickjillings@1541 8712 var oldCallbacks = [],
nickjillings@1541 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nickjillings@1541 8714
nickjillings@1541 8715 // Default jsonp settings
nickjillings@1541 8716 jQuery.ajaxSetup({
nickjillings@1541 8717 jsonp: "callback",
nickjillings@1541 8718 jsonpCallback: function() {
nickjillings@1541 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nickjillings@1541 8720 this[ callback ] = true;
nickjillings@1541 8721 return callback;
nickjillings@1541 8722 }
nickjillings@1541 8723 });
nickjillings@1541 8724
nickjillings@1541 8725 // Detect, normalize options and install callbacks for jsonp requests
nickjillings@1541 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nickjillings@1541 8727
nickjillings@1541 8728 var callbackName, overwritten, responseContainer,
nickjillings@1541 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nickjillings@1541 8730 "url" :
nickjillings@1541 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nickjillings@1541 8732 );
nickjillings@1541 8733
nickjillings@1541 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nickjillings@1541 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nickjillings@1541 8736
nickjillings@1541 8737 // Get callback name, remembering preexisting value associated with it
nickjillings@1541 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nickjillings@1541 8739 s.jsonpCallback() :
nickjillings@1541 8740 s.jsonpCallback;
nickjillings@1541 8741
nickjillings@1541 8742 // Insert callback into url or form data
nickjillings@1541 8743 if ( jsonProp ) {
nickjillings@1541 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nickjillings@1541 8745 } else if ( s.jsonp !== false ) {
nickjillings@1541 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nickjillings@1541 8747 }
nickjillings@1541 8748
nickjillings@1541 8749 // Use data converter to retrieve json after script execution
nickjillings@1541 8750 s.converters["script json"] = function() {
nickjillings@1541 8751 if ( !responseContainer ) {
nickjillings@1541 8752 jQuery.error( callbackName + " was not called" );
nickjillings@1541 8753 }
nickjillings@1541 8754 return responseContainer[ 0 ];
nickjillings@1541 8755 };
nickjillings@1541 8756
nickjillings@1541 8757 // force json dataType
nickjillings@1541 8758 s.dataTypes[ 0 ] = "json";
nickjillings@1541 8759
nickjillings@1541 8760 // Install callback
nickjillings@1541 8761 overwritten = window[ callbackName ];
nickjillings@1541 8762 window[ callbackName ] = function() {
nickjillings@1541 8763 responseContainer = arguments;
nickjillings@1541 8764 };
nickjillings@1541 8765
nickjillings@1541 8766 // Clean-up function (fires after converters)
nickjillings@1541 8767 jqXHR.always(function() {
nickjillings@1541 8768 // Restore preexisting value
nickjillings@1541 8769 window[ callbackName ] = overwritten;
nickjillings@1541 8770
nickjillings@1541 8771 // Save back as free
nickjillings@1541 8772 if ( s[ callbackName ] ) {
nickjillings@1541 8773 // make sure that re-using the options doesn't screw things around
nickjillings@1541 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nickjillings@1541 8775
nickjillings@1541 8776 // save the callback name for future use
nickjillings@1541 8777 oldCallbacks.push( callbackName );
nickjillings@1541 8778 }
nickjillings@1541 8779
nickjillings@1541 8780 // Call if it was a function and we have a response
nickjillings@1541 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nickjillings@1541 8782 overwritten( responseContainer[ 0 ] );
nickjillings@1541 8783 }
nickjillings@1541 8784
nickjillings@1541 8785 responseContainer = overwritten = undefined;
nickjillings@1541 8786 });
nickjillings@1541 8787
nickjillings@1541 8788 // Delegate to script
nickjillings@1541 8789 return "script";
nickjillings@1541 8790 }
nickjillings@1541 8791 });
nickjillings@1541 8792
nickjillings@1541 8793
nickjillings@1541 8794
nickjillings@1541 8795
nickjillings@1541 8796 // data: string of html
nickjillings@1541 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nickjillings@1541 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nickjillings@1541 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nickjillings@1541 8800 if ( !data || typeof data !== "string" ) {
nickjillings@1541 8801 return null;
nickjillings@1541 8802 }
nickjillings@1541 8803 if ( typeof context === "boolean" ) {
nickjillings@1541 8804 keepScripts = context;
nickjillings@1541 8805 context = false;
nickjillings@1541 8806 }
nickjillings@1541 8807 context = context || document;
nickjillings@1541 8808
nickjillings@1541 8809 var parsed = rsingleTag.exec( data ),
nickjillings@1541 8810 scripts = !keepScripts && [];
nickjillings@1541 8811
nickjillings@1541 8812 // Single tag
nickjillings@1541 8813 if ( parsed ) {
nickjillings@1541 8814 return [ context.createElement( parsed[1] ) ];
nickjillings@1541 8815 }
nickjillings@1541 8816
nickjillings@1541 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nickjillings@1541 8818
nickjillings@1541 8819 if ( scripts && scripts.length ) {
nickjillings@1541 8820 jQuery( scripts ).remove();
nickjillings@1541 8821 }
nickjillings@1541 8822
nickjillings@1541 8823 return jQuery.merge( [], parsed.childNodes );
nickjillings@1541 8824 };
nickjillings@1541 8825
nickjillings@1541 8826
nickjillings@1541 8827 // Keep a copy of the old load method
nickjillings@1541 8828 var _load = jQuery.fn.load;
nickjillings@1541 8829
nickjillings@1541 8830 /**
nickjillings@1541 8831 * Load a url into a page
nickjillings@1541 8832 */
nickjillings@1541 8833 jQuery.fn.load = function( url, params, callback ) {
nickjillings@1541 8834 if ( typeof url !== "string" && _load ) {
nickjillings@1541 8835 return _load.apply( this, arguments );
nickjillings@1541 8836 }
nickjillings@1541 8837
nickjillings@1541 8838 var selector, type, response,
nickjillings@1541 8839 self = this,
nickjillings@1541 8840 off = url.indexOf(" ");
nickjillings@1541 8841
nickjillings@1541 8842 if ( off >= 0 ) {
nickjillings@1541 8843 selector = jQuery.trim( url.slice( off ) );
nickjillings@1541 8844 url = url.slice( 0, off );
nickjillings@1541 8845 }
nickjillings@1541 8846
nickjillings@1541 8847 // If it's a function
nickjillings@1541 8848 if ( jQuery.isFunction( params ) ) {
nickjillings@1541 8849
nickjillings@1541 8850 // We assume that it's the callback
nickjillings@1541 8851 callback = params;
nickjillings@1541 8852 params = undefined;
nickjillings@1541 8853
nickjillings@1541 8854 // Otherwise, build a param string
nickjillings@1541 8855 } else if ( params && typeof params === "object" ) {
nickjillings@1541 8856 type = "POST";
nickjillings@1541 8857 }
nickjillings@1541 8858
nickjillings@1541 8859 // If we have elements to modify, make the request
nickjillings@1541 8860 if ( self.length > 0 ) {
nickjillings@1541 8861 jQuery.ajax({
nickjillings@1541 8862 url: url,
nickjillings@1541 8863
nickjillings@1541 8864 // if "type" variable is undefined, then "GET" method will be used
nickjillings@1541 8865 type: type,
nickjillings@1541 8866 dataType: "html",
nickjillings@1541 8867 data: params
nickjillings@1541 8868 }).done(function( responseText ) {
nickjillings@1541 8869
nickjillings@1541 8870 // Save response for use in complete callback
nickjillings@1541 8871 response = arguments;
nickjillings@1541 8872
nickjillings@1541 8873 self.html( selector ?
nickjillings@1541 8874
nickjillings@1541 8875 // If a selector was specified, locate the right elements in a dummy div
nickjillings@1541 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nickjillings@1541 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nickjillings@1541 8878
nickjillings@1541 8879 // Otherwise use the full result
nickjillings@1541 8880 responseText );
nickjillings@1541 8881
nickjillings@1541 8882 }).complete( callback && function( jqXHR, status ) {
nickjillings@1541 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nickjillings@1541 8884 });
nickjillings@1541 8885 }
nickjillings@1541 8886
nickjillings@1541 8887 return this;
nickjillings@1541 8888 };
nickjillings@1541 8889
nickjillings@1541 8890
nickjillings@1541 8891
nickjillings@1541 8892
nickjillings@1541 8893 // Attach a bunch of functions for handling common AJAX events
nickjillings@1541 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nickjillings@1541 8895 jQuery.fn[ type ] = function( fn ) {
nickjillings@1541 8896 return this.on( type, fn );
nickjillings@1541 8897 };
nickjillings@1541 8898 });
nickjillings@1541 8899
nickjillings@1541 8900
nickjillings@1541 8901
nickjillings@1541 8902
nickjillings@1541 8903 jQuery.expr.filters.animated = function( elem ) {
nickjillings@1541 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nickjillings@1541 8905 return elem === fn.elem;
nickjillings@1541 8906 }).length;
nickjillings@1541 8907 };
nickjillings@1541 8908
nickjillings@1541 8909
nickjillings@1541 8910
nickjillings@1541 8911
nickjillings@1541 8912 var docElem = window.document.documentElement;
nickjillings@1541 8913
nickjillings@1541 8914 /**
nickjillings@1541 8915 * Gets a window from an element
nickjillings@1541 8916 */
nickjillings@1541 8917 function getWindow( elem ) {
nickjillings@1541 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nickjillings@1541 8919 }
nickjillings@1541 8920
nickjillings@1541 8921 jQuery.offset = {
nickjillings@1541 8922 setOffset: function( elem, options, i ) {
nickjillings@1541 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nickjillings@1541 8924 position = jQuery.css( elem, "position" ),
nickjillings@1541 8925 curElem = jQuery( elem ),
nickjillings@1541 8926 props = {};
nickjillings@1541 8927
nickjillings@1541 8928 // Set position first, in-case top/left are set even on static elem
nickjillings@1541 8929 if ( position === "static" ) {
nickjillings@1541 8930 elem.style.position = "relative";
nickjillings@1541 8931 }
nickjillings@1541 8932
nickjillings@1541 8933 curOffset = curElem.offset();
nickjillings@1541 8934 curCSSTop = jQuery.css( elem, "top" );
nickjillings@1541 8935 curCSSLeft = jQuery.css( elem, "left" );
nickjillings@1541 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nickjillings@1541 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nickjillings@1541 8938
nickjillings@1541 8939 // Need to be able to calculate position if either
nickjillings@1541 8940 // top or left is auto and position is either absolute or fixed
nickjillings@1541 8941 if ( calculatePosition ) {
nickjillings@1541 8942 curPosition = curElem.position();
nickjillings@1541 8943 curTop = curPosition.top;
nickjillings@1541 8944 curLeft = curPosition.left;
nickjillings@1541 8945
nickjillings@1541 8946 } else {
nickjillings@1541 8947 curTop = parseFloat( curCSSTop ) || 0;
nickjillings@1541 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nickjillings@1541 8949 }
nickjillings@1541 8950
nickjillings@1541 8951 if ( jQuery.isFunction( options ) ) {
nickjillings@1541 8952 options = options.call( elem, i, curOffset );
nickjillings@1541 8953 }
nickjillings@1541 8954
nickjillings@1541 8955 if ( options.top != null ) {
nickjillings@1541 8956 props.top = ( options.top - curOffset.top ) + curTop;
nickjillings@1541 8957 }
nickjillings@1541 8958 if ( options.left != null ) {
nickjillings@1541 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nickjillings@1541 8960 }
nickjillings@1541 8961
nickjillings@1541 8962 if ( "using" in options ) {
nickjillings@1541 8963 options.using.call( elem, props );
nickjillings@1541 8964
nickjillings@1541 8965 } else {
nickjillings@1541 8966 curElem.css( props );
nickjillings@1541 8967 }
nickjillings@1541 8968 }
nickjillings@1541 8969 };
nickjillings@1541 8970
nickjillings@1541 8971 jQuery.fn.extend({
nickjillings@1541 8972 offset: function( options ) {
nickjillings@1541 8973 if ( arguments.length ) {
nickjillings@1541 8974 return options === undefined ?
nickjillings@1541 8975 this :
nickjillings@1541 8976 this.each(function( i ) {
nickjillings@1541 8977 jQuery.offset.setOffset( this, options, i );
nickjillings@1541 8978 });
nickjillings@1541 8979 }
nickjillings@1541 8980
nickjillings@1541 8981 var docElem, win,
nickjillings@1541 8982 elem = this[ 0 ],
nickjillings@1541 8983 box = { top: 0, left: 0 },
nickjillings@1541 8984 doc = elem && elem.ownerDocument;
nickjillings@1541 8985
nickjillings@1541 8986 if ( !doc ) {
nickjillings@1541 8987 return;
nickjillings@1541 8988 }
nickjillings@1541 8989
nickjillings@1541 8990 docElem = doc.documentElement;
nickjillings@1541 8991
nickjillings@1541 8992 // Make sure it's not a disconnected DOM node
nickjillings@1541 8993 if ( !jQuery.contains( docElem, elem ) ) {
nickjillings@1541 8994 return box;
nickjillings@1541 8995 }
nickjillings@1541 8996
nickjillings@1541 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nickjillings@1541 8998 // If we don't have gBCR, just use 0,0 rather than error
nickjillings@1541 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nickjillings@1541 9000 box = elem.getBoundingClientRect();
nickjillings@1541 9001 }
nickjillings@1541 9002 win = getWindow( doc );
nickjillings@1541 9003 return {
nickjillings@1541 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nickjillings@1541 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nickjillings@1541 9006 };
nickjillings@1541 9007 },
nickjillings@1541 9008
nickjillings@1541 9009 position: function() {
nickjillings@1541 9010 if ( !this[ 0 ] ) {
nickjillings@1541 9011 return;
nickjillings@1541 9012 }
nickjillings@1541 9013
nickjillings@1541 9014 var offsetParent, offset,
nickjillings@1541 9015 elem = this[ 0 ],
nickjillings@1541 9016 parentOffset = { top: 0, left: 0 };
nickjillings@1541 9017
nickjillings@1541 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nickjillings@1541 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nickjillings@1541 9020 // Assume getBoundingClientRect is there when computed position is fixed
nickjillings@1541 9021 offset = elem.getBoundingClientRect();
nickjillings@1541 9022
nickjillings@1541 9023 } else {
nickjillings@1541 9024 // Get *real* offsetParent
nickjillings@1541 9025 offsetParent = this.offsetParent();
nickjillings@1541 9026
nickjillings@1541 9027 // Get correct offsets
nickjillings@1541 9028 offset = this.offset();
nickjillings@1541 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nickjillings@1541 9030 parentOffset = offsetParent.offset();
nickjillings@1541 9031 }
nickjillings@1541 9032
nickjillings@1541 9033 // Add offsetParent borders
nickjillings@1541 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nickjillings@1541 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nickjillings@1541 9036 }
nickjillings@1541 9037
nickjillings@1541 9038 // Subtract parent offsets and element margins
nickjillings@1541 9039 return {
nickjillings@1541 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nickjillings@1541 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nickjillings@1541 9042 };
nickjillings@1541 9043 },
nickjillings@1541 9044
nickjillings@1541 9045 offsetParent: function() {
nickjillings@1541 9046 return this.map(function() {
nickjillings@1541 9047 var offsetParent = this.offsetParent || docElem;
nickjillings@1541 9048
nickjillings@1541 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nickjillings@1541 9050 offsetParent = offsetParent.offsetParent;
nickjillings@1541 9051 }
nickjillings@1541 9052
nickjillings@1541 9053 return offsetParent || docElem;
nickjillings@1541 9054 });
nickjillings@1541 9055 }
nickjillings@1541 9056 });
nickjillings@1541 9057
nickjillings@1541 9058 // Create scrollLeft and scrollTop methods
nickjillings@1541 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nickjillings@1541 9060 var top = "pageYOffset" === prop;
nickjillings@1541 9061
nickjillings@1541 9062 jQuery.fn[ method ] = function( val ) {
nickjillings@1541 9063 return access( this, function( elem, method, val ) {
nickjillings@1541 9064 var win = getWindow( elem );
nickjillings@1541 9065
nickjillings@1541 9066 if ( val === undefined ) {
nickjillings@1541 9067 return win ? win[ prop ] : elem[ method ];
nickjillings@1541 9068 }
nickjillings@1541 9069
nickjillings@1541 9070 if ( win ) {
nickjillings@1541 9071 win.scrollTo(
nickjillings@1541 9072 !top ? val : window.pageXOffset,
nickjillings@1541 9073 top ? val : window.pageYOffset
nickjillings@1541 9074 );
nickjillings@1541 9075
nickjillings@1541 9076 } else {
nickjillings@1541 9077 elem[ method ] = val;
nickjillings@1541 9078 }
nickjillings@1541 9079 }, method, val, arguments.length, null );
nickjillings@1541 9080 };
nickjillings@1541 9081 });
nickjillings@1541 9082
nickjillings@1541 9083 // Support: Safari<7+, Chrome<37+
nickjillings@1541 9084 // Add the top/left cssHooks using jQuery.fn.position
nickjillings@1541 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nickjillings@1541 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nickjillings@1541 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nickjillings@1541 9088 // rather than make the css module depend on the offset module, just check for it here
nickjillings@1541 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nickjillings@1541 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nickjillings@1541 9091 function( elem, computed ) {
nickjillings@1541 9092 if ( computed ) {
nickjillings@1541 9093 computed = curCSS( elem, prop );
nickjillings@1541 9094 // If curCSS returns percentage, fallback to offset
nickjillings@1541 9095 return rnumnonpx.test( computed ) ?
nickjillings@1541 9096 jQuery( elem ).position()[ prop ] + "px" :
nickjillings@1541 9097 computed;
nickjillings@1541 9098 }
nickjillings@1541 9099 }
nickjillings@1541 9100 );
nickjillings@1541 9101 });
nickjillings@1541 9102
nickjillings@1541 9103
nickjillings@1541 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nickjillings@1541 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nickjillings@1541 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nickjillings@1541 9107 // Margin is only for outerHeight, outerWidth
nickjillings@1541 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nickjillings@1541 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nickjillings@1541 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nickjillings@1541 9111
nickjillings@1541 9112 return access( this, function( elem, type, value ) {
nickjillings@1541 9113 var doc;
nickjillings@1541 9114
nickjillings@1541 9115 if ( jQuery.isWindow( elem ) ) {
nickjillings@1541 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nickjillings@1541 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nickjillings@1541 9118 // https://github.com/jquery/jquery/pull/764
nickjillings@1541 9119 return elem.document.documentElement[ "client" + name ];
nickjillings@1541 9120 }
nickjillings@1541 9121
nickjillings@1541 9122 // Get document width or height
nickjillings@1541 9123 if ( elem.nodeType === 9 ) {
nickjillings@1541 9124 doc = elem.documentElement;
nickjillings@1541 9125
nickjillings@1541 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nickjillings@1541 9127 // whichever is greatest
nickjillings@1541 9128 return Math.max(
nickjillings@1541 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nickjillings@1541 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nickjillings@1541 9131 doc[ "client" + name ]
nickjillings@1541 9132 );
nickjillings@1541 9133 }
nickjillings@1541 9134
nickjillings@1541 9135 return value === undefined ?
nickjillings@1541 9136 // Get width or height on the element, requesting but not forcing parseFloat
nickjillings@1541 9137 jQuery.css( elem, type, extra ) :
nickjillings@1541 9138
nickjillings@1541 9139 // Set width or height on the element
nickjillings@1541 9140 jQuery.style( elem, type, value, extra );
nickjillings@1541 9141 }, type, chainable ? margin : undefined, chainable, null );
nickjillings@1541 9142 };
nickjillings@1541 9143 });
nickjillings@1541 9144 });
nickjillings@1541 9145
nickjillings@1541 9146
nickjillings@1541 9147 // The number of elements contained in the matched element set
nickjillings@1541 9148 jQuery.fn.size = function() {
nickjillings@1541 9149 return this.length;
nickjillings@1541 9150 };
nickjillings@1541 9151
nickjillings@1541 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nickjillings@1541 9153
nickjillings@1541 9154
nickjillings@1541 9155
nickjillings@1541 9156
nickjillings@1541 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nickjillings@1541 9158 // files that may use define, but not via a proper concatenation script that
nickjillings@1541 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nickjillings@1541 9160 // way to register. Lowercase jquery is used because AMD module names are
nickjillings@1541 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nickjillings@1541 9162 // file name. Do this after creating the global so that if an AMD module wants
nickjillings@1541 9163 // to call noConflict to hide this version of jQuery, it will work.
nickjillings@1541 9164
nickjillings@1541 9165 // Note that for maximum portability, libraries that are not jQuery should
nickjillings@1541 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nickjillings@1541 9167 // AMD loader is present. jQuery is a special case. For more information, see
nickjillings@1541 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nickjillings@1541 9169
nickjillings@1541 9170 if ( typeof define === "function" && define.amd ) {
nickjillings@1541 9171 define( "jquery", [], function() {
nickjillings@1541 9172 return jQuery;
nickjillings@1541 9173 });
nickjillings@1541 9174 }
nickjillings@1541 9175
nickjillings@1541 9176
nickjillings@1541 9177
nickjillings@1541 9178
nickjillings@1541 9179 var
nickjillings@1541 9180 // Map over jQuery in case of overwrite
nickjillings@1541 9181 _jQuery = window.jQuery,
nickjillings@1541 9182
nickjillings@1541 9183 // Map over the $ in case of overwrite
nickjillings@1541 9184 _$ = window.$;
nickjillings@1541 9185
nickjillings@1541 9186 jQuery.noConflict = function( deep ) {
nickjillings@1541 9187 if ( window.$ === jQuery ) {
nickjillings@1541 9188 window.$ = _$;
nickjillings@1541 9189 }
nickjillings@1541 9190
nickjillings@1541 9191 if ( deep && window.jQuery === jQuery ) {
nickjillings@1541 9192 window.jQuery = _jQuery;
nickjillings@1541 9193 }
nickjillings@1541 9194
nickjillings@1541 9195 return jQuery;
nickjillings@1541 9196 };
nickjillings@1541 9197
nickjillings@1541 9198 // Expose jQuery and $ identifiers, even in AMD
nickjillings@1541 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nickjillings@1541 9200 // and CommonJS for browser emulators (#13566)
nickjillings@1541 9201 if ( typeof noGlobal === strundefined ) {
nickjillings@1541 9202 window.jQuery = window.$ = jQuery;
nickjillings@1541 9203 }
nickjillings@1541 9204
nickjillings@1541 9205
nickjillings@1541 9206
nickjillings@1541 9207
nickjillings@1541 9208 return jQuery;
nickjillings@1541 9209
nickjillings@1541 9210 }));