annotate jquery-2.1.4.js @ 1315:d9b9f707f862

Updated author list for WAC 2016
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Sun, 21 Feb 2016 11:15:52 +0000
parents
children
rev   line source
nickjillings@1315 1 /*!
nickjillings@1315 2 * jQuery JavaScript Library v2.1.4
nickjillings@1315 3 * http://jquery.com/
nickjillings@1315 4 *
nickjillings@1315 5 * Includes Sizzle.js
nickjillings@1315 6 * http://sizzlejs.com/
nickjillings@1315 7 *
nickjillings@1315 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1315 9 * Released under the MIT license
nickjillings@1315 10 * http://jquery.org/license
nickjillings@1315 11 *
nickjillings@1315 12 * Date: 2015-04-28T16:01Z
nickjillings@1315 13 */
nickjillings@1315 14
nickjillings@1315 15 (function( global, factory ) {
nickjillings@1315 16
nickjillings@1315 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nickjillings@1315 18 // For CommonJS and CommonJS-like environments where a proper `window`
nickjillings@1315 19 // is present, execute the factory and get jQuery.
nickjillings@1315 20 // For environments that do not have a `window` with a `document`
nickjillings@1315 21 // (such as Node.js), expose a factory as module.exports.
nickjillings@1315 22 // This accentuates the need for the creation of a real `window`.
nickjillings@1315 23 // e.g. var jQuery = require("jquery")(window);
nickjillings@1315 24 // See ticket #14549 for more info.
nickjillings@1315 25 module.exports = global.document ?
nickjillings@1315 26 factory( global, true ) :
nickjillings@1315 27 function( w ) {
nickjillings@1315 28 if ( !w.document ) {
nickjillings@1315 29 throw new Error( "jQuery requires a window with a document" );
nickjillings@1315 30 }
nickjillings@1315 31 return factory( w );
nickjillings@1315 32 };
nickjillings@1315 33 } else {
nickjillings@1315 34 factory( global );
nickjillings@1315 35 }
nickjillings@1315 36
nickjillings@1315 37 // Pass this if window is not defined yet
nickjillings@1315 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nickjillings@1315 39
nickjillings@1315 40 // Support: Firefox 18+
nickjillings@1315 41 // Can't be in strict mode, several libs including ASP.NET trace
nickjillings@1315 42 // the stack via arguments.caller.callee and Firefox dies if
nickjillings@1315 43 // you try to trace through "use strict" call chains. (#13335)
nickjillings@1315 44 //
nickjillings@1315 45
nickjillings@1315 46 var arr = [];
nickjillings@1315 47
nickjillings@1315 48 var slice = arr.slice;
nickjillings@1315 49
nickjillings@1315 50 var concat = arr.concat;
nickjillings@1315 51
nickjillings@1315 52 var push = arr.push;
nickjillings@1315 53
nickjillings@1315 54 var indexOf = arr.indexOf;
nickjillings@1315 55
nickjillings@1315 56 var class2type = {};
nickjillings@1315 57
nickjillings@1315 58 var toString = class2type.toString;
nickjillings@1315 59
nickjillings@1315 60 var hasOwn = class2type.hasOwnProperty;
nickjillings@1315 61
nickjillings@1315 62 var support = {};
nickjillings@1315 63
nickjillings@1315 64
nickjillings@1315 65
nickjillings@1315 66 var
nickjillings@1315 67 // Use the correct document accordingly with window argument (sandbox)
nickjillings@1315 68 document = window.document,
nickjillings@1315 69
nickjillings@1315 70 version = "2.1.4",
nickjillings@1315 71
nickjillings@1315 72 // Define a local copy of jQuery
nickjillings@1315 73 jQuery = function( selector, context ) {
nickjillings@1315 74 // The jQuery object is actually just the init constructor 'enhanced'
nickjillings@1315 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nickjillings@1315 76 return new jQuery.fn.init( selector, context );
nickjillings@1315 77 },
nickjillings@1315 78
nickjillings@1315 79 // Support: Android<4.1
nickjillings@1315 80 // Make sure we trim BOM and NBSP
nickjillings@1315 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nickjillings@1315 82
nickjillings@1315 83 // Matches dashed string for camelizing
nickjillings@1315 84 rmsPrefix = /^-ms-/,
nickjillings@1315 85 rdashAlpha = /-([\da-z])/gi,
nickjillings@1315 86
nickjillings@1315 87 // Used by jQuery.camelCase as callback to replace()
nickjillings@1315 88 fcamelCase = function( all, letter ) {
nickjillings@1315 89 return letter.toUpperCase();
nickjillings@1315 90 };
nickjillings@1315 91
nickjillings@1315 92 jQuery.fn = jQuery.prototype = {
nickjillings@1315 93 // The current version of jQuery being used
nickjillings@1315 94 jquery: version,
nickjillings@1315 95
nickjillings@1315 96 constructor: jQuery,
nickjillings@1315 97
nickjillings@1315 98 // Start with an empty selector
nickjillings@1315 99 selector: "",
nickjillings@1315 100
nickjillings@1315 101 // The default length of a jQuery object is 0
nickjillings@1315 102 length: 0,
nickjillings@1315 103
nickjillings@1315 104 toArray: function() {
nickjillings@1315 105 return slice.call( this );
nickjillings@1315 106 },
nickjillings@1315 107
nickjillings@1315 108 // Get the Nth element in the matched element set OR
nickjillings@1315 109 // Get the whole matched element set as a clean array
nickjillings@1315 110 get: function( num ) {
nickjillings@1315 111 return num != null ?
nickjillings@1315 112
nickjillings@1315 113 // Return just the one element from the set
nickjillings@1315 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nickjillings@1315 115
nickjillings@1315 116 // Return all the elements in a clean array
nickjillings@1315 117 slice.call( this );
nickjillings@1315 118 },
nickjillings@1315 119
nickjillings@1315 120 // Take an array of elements and push it onto the stack
nickjillings@1315 121 // (returning the new matched element set)
nickjillings@1315 122 pushStack: function( elems ) {
nickjillings@1315 123
nickjillings@1315 124 // Build a new jQuery matched element set
nickjillings@1315 125 var ret = jQuery.merge( this.constructor(), elems );
nickjillings@1315 126
nickjillings@1315 127 // Add the old object onto the stack (as a reference)
nickjillings@1315 128 ret.prevObject = this;
nickjillings@1315 129 ret.context = this.context;
nickjillings@1315 130
nickjillings@1315 131 // Return the newly-formed element set
nickjillings@1315 132 return ret;
nickjillings@1315 133 },
nickjillings@1315 134
nickjillings@1315 135 // Execute a callback for every element in the matched set.
nickjillings@1315 136 // (You can seed the arguments with an array of args, but this is
nickjillings@1315 137 // only used internally.)
nickjillings@1315 138 each: function( callback, args ) {
nickjillings@1315 139 return jQuery.each( this, callback, args );
nickjillings@1315 140 },
nickjillings@1315 141
nickjillings@1315 142 map: function( callback ) {
nickjillings@1315 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nickjillings@1315 144 return callback.call( elem, i, elem );
nickjillings@1315 145 }));
nickjillings@1315 146 },
nickjillings@1315 147
nickjillings@1315 148 slice: function() {
nickjillings@1315 149 return this.pushStack( slice.apply( this, arguments ) );
nickjillings@1315 150 },
nickjillings@1315 151
nickjillings@1315 152 first: function() {
nickjillings@1315 153 return this.eq( 0 );
nickjillings@1315 154 },
nickjillings@1315 155
nickjillings@1315 156 last: function() {
nickjillings@1315 157 return this.eq( -1 );
nickjillings@1315 158 },
nickjillings@1315 159
nickjillings@1315 160 eq: function( i ) {
nickjillings@1315 161 var len = this.length,
nickjillings@1315 162 j = +i + ( i < 0 ? len : 0 );
nickjillings@1315 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nickjillings@1315 164 },
nickjillings@1315 165
nickjillings@1315 166 end: function() {
nickjillings@1315 167 return this.prevObject || this.constructor(null);
nickjillings@1315 168 },
nickjillings@1315 169
nickjillings@1315 170 // For internal use only.
nickjillings@1315 171 // Behaves like an Array's method, not like a jQuery method.
nickjillings@1315 172 push: push,
nickjillings@1315 173 sort: arr.sort,
nickjillings@1315 174 splice: arr.splice
nickjillings@1315 175 };
nickjillings@1315 176
nickjillings@1315 177 jQuery.extend = jQuery.fn.extend = function() {
nickjillings@1315 178 var options, name, src, copy, copyIsArray, clone,
nickjillings@1315 179 target = arguments[0] || {},
nickjillings@1315 180 i = 1,
nickjillings@1315 181 length = arguments.length,
nickjillings@1315 182 deep = false;
nickjillings@1315 183
nickjillings@1315 184 // Handle a deep copy situation
nickjillings@1315 185 if ( typeof target === "boolean" ) {
nickjillings@1315 186 deep = target;
nickjillings@1315 187
nickjillings@1315 188 // Skip the boolean and the target
nickjillings@1315 189 target = arguments[ i ] || {};
nickjillings@1315 190 i++;
nickjillings@1315 191 }
nickjillings@1315 192
nickjillings@1315 193 // Handle case when target is a string or something (possible in deep copy)
nickjillings@1315 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nickjillings@1315 195 target = {};
nickjillings@1315 196 }
nickjillings@1315 197
nickjillings@1315 198 // Extend jQuery itself if only one argument is passed
nickjillings@1315 199 if ( i === length ) {
nickjillings@1315 200 target = this;
nickjillings@1315 201 i--;
nickjillings@1315 202 }
nickjillings@1315 203
nickjillings@1315 204 for ( ; i < length; i++ ) {
nickjillings@1315 205 // Only deal with non-null/undefined values
nickjillings@1315 206 if ( (options = arguments[ i ]) != null ) {
nickjillings@1315 207 // Extend the base object
nickjillings@1315 208 for ( name in options ) {
nickjillings@1315 209 src = target[ name ];
nickjillings@1315 210 copy = options[ name ];
nickjillings@1315 211
nickjillings@1315 212 // Prevent never-ending loop
nickjillings@1315 213 if ( target === copy ) {
nickjillings@1315 214 continue;
nickjillings@1315 215 }
nickjillings@1315 216
nickjillings@1315 217 // Recurse if we're merging plain objects or arrays
nickjillings@1315 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nickjillings@1315 219 if ( copyIsArray ) {
nickjillings@1315 220 copyIsArray = false;
nickjillings@1315 221 clone = src && jQuery.isArray(src) ? src : [];
nickjillings@1315 222
nickjillings@1315 223 } else {
nickjillings@1315 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nickjillings@1315 225 }
nickjillings@1315 226
nickjillings@1315 227 // Never move original objects, clone them
nickjillings@1315 228 target[ name ] = jQuery.extend( deep, clone, copy );
nickjillings@1315 229
nickjillings@1315 230 // Don't bring in undefined values
nickjillings@1315 231 } else if ( copy !== undefined ) {
nickjillings@1315 232 target[ name ] = copy;
nickjillings@1315 233 }
nickjillings@1315 234 }
nickjillings@1315 235 }
nickjillings@1315 236 }
nickjillings@1315 237
nickjillings@1315 238 // Return the modified object
nickjillings@1315 239 return target;
nickjillings@1315 240 };
nickjillings@1315 241
nickjillings@1315 242 jQuery.extend({
nickjillings@1315 243 // Unique for each copy of jQuery on the page
nickjillings@1315 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nickjillings@1315 245
nickjillings@1315 246 // Assume jQuery is ready without the ready module
nickjillings@1315 247 isReady: true,
nickjillings@1315 248
nickjillings@1315 249 error: function( msg ) {
nickjillings@1315 250 throw new Error( msg );
nickjillings@1315 251 },
nickjillings@1315 252
nickjillings@1315 253 noop: function() {},
nickjillings@1315 254
nickjillings@1315 255 isFunction: function( obj ) {
nickjillings@1315 256 return jQuery.type(obj) === "function";
nickjillings@1315 257 },
nickjillings@1315 258
nickjillings@1315 259 isArray: Array.isArray,
nickjillings@1315 260
nickjillings@1315 261 isWindow: function( obj ) {
nickjillings@1315 262 return obj != null && obj === obj.window;
nickjillings@1315 263 },
nickjillings@1315 264
nickjillings@1315 265 isNumeric: function( obj ) {
nickjillings@1315 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nickjillings@1315 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nickjillings@1315 268 // subtraction forces infinities to NaN
nickjillings@1315 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nickjillings@1315 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nickjillings@1315 271 },
nickjillings@1315 272
nickjillings@1315 273 isPlainObject: function( obj ) {
nickjillings@1315 274 // Not plain objects:
nickjillings@1315 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nickjillings@1315 276 // - DOM nodes
nickjillings@1315 277 // - window
nickjillings@1315 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nickjillings@1315 279 return false;
nickjillings@1315 280 }
nickjillings@1315 281
nickjillings@1315 282 if ( obj.constructor &&
nickjillings@1315 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nickjillings@1315 284 return false;
nickjillings@1315 285 }
nickjillings@1315 286
nickjillings@1315 287 // If the function hasn't returned already, we're confident that
nickjillings@1315 288 // |obj| is a plain object, created by {} or constructed with new Object
nickjillings@1315 289 return true;
nickjillings@1315 290 },
nickjillings@1315 291
nickjillings@1315 292 isEmptyObject: function( obj ) {
nickjillings@1315 293 var name;
nickjillings@1315 294 for ( name in obj ) {
nickjillings@1315 295 return false;
nickjillings@1315 296 }
nickjillings@1315 297 return true;
nickjillings@1315 298 },
nickjillings@1315 299
nickjillings@1315 300 type: function( obj ) {
nickjillings@1315 301 if ( obj == null ) {
nickjillings@1315 302 return obj + "";
nickjillings@1315 303 }
nickjillings@1315 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nickjillings@1315 305 return typeof obj === "object" || typeof obj === "function" ?
nickjillings@1315 306 class2type[ toString.call(obj) ] || "object" :
nickjillings@1315 307 typeof obj;
nickjillings@1315 308 },
nickjillings@1315 309
nickjillings@1315 310 // Evaluates a script in a global context
nickjillings@1315 311 globalEval: function( code ) {
nickjillings@1315 312 var script,
nickjillings@1315 313 indirect = eval;
nickjillings@1315 314
nickjillings@1315 315 code = jQuery.trim( code );
nickjillings@1315 316
nickjillings@1315 317 if ( code ) {
nickjillings@1315 318 // If the code includes a valid, prologue position
nickjillings@1315 319 // strict mode pragma, execute code by injecting a
nickjillings@1315 320 // script tag into the document.
nickjillings@1315 321 if ( code.indexOf("use strict") === 1 ) {
nickjillings@1315 322 script = document.createElement("script");
nickjillings@1315 323 script.text = code;
nickjillings@1315 324 document.head.appendChild( script ).parentNode.removeChild( script );
nickjillings@1315 325 } else {
nickjillings@1315 326 // Otherwise, avoid the DOM node creation, insertion
nickjillings@1315 327 // and removal by using an indirect global eval
nickjillings@1315 328 indirect( code );
nickjillings@1315 329 }
nickjillings@1315 330 }
nickjillings@1315 331 },
nickjillings@1315 332
nickjillings@1315 333 // Convert dashed to camelCase; used by the css and data modules
nickjillings@1315 334 // Support: IE9-11+
nickjillings@1315 335 // Microsoft forgot to hump their vendor prefix (#9572)
nickjillings@1315 336 camelCase: function( string ) {
nickjillings@1315 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nickjillings@1315 338 },
nickjillings@1315 339
nickjillings@1315 340 nodeName: function( elem, name ) {
nickjillings@1315 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nickjillings@1315 342 },
nickjillings@1315 343
nickjillings@1315 344 // args is for internal usage only
nickjillings@1315 345 each: function( obj, callback, args ) {
nickjillings@1315 346 var value,
nickjillings@1315 347 i = 0,
nickjillings@1315 348 length = obj.length,
nickjillings@1315 349 isArray = isArraylike( obj );
nickjillings@1315 350
nickjillings@1315 351 if ( args ) {
nickjillings@1315 352 if ( isArray ) {
nickjillings@1315 353 for ( ; i < length; i++ ) {
nickjillings@1315 354 value = callback.apply( obj[ i ], args );
nickjillings@1315 355
nickjillings@1315 356 if ( value === false ) {
nickjillings@1315 357 break;
nickjillings@1315 358 }
nickjillings@1315 359 }
nickjillings@1315 360 } else {
nickjillings@1315 361 for ( i in obj ) {
nickjillings@1315 362 value = callback.apply( obj[ i ], args );
nickjillings@1315 363
nickjillings@1315 364 if ( value === false ) {
nickjillings@1315 365 break;
nickjillings@1315 366 }
nickjillings@1315 367 }
nickjillings@1315 368 }
nickjillings@1315 369
nickjillings@1315 370 // A special, fast, case for the most common use of each
nickjillings@1315 371 } else {
nickjillings@1315 372 if ( isArray ) {
nickjillings@1315 373 for ( ; i < length; i++ ) {
nickjillings@1315 374 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1315 375
nickjillings@1315 376 if ( value === false ) {
nickjillings@1315 377 break;
nickjillings@1315 378 }
nickjillings@1315 379 }
nickjillings@1315 380 } else {
nickjillings@1315 381 for ( i in obj ) {
nickjillings@1315 382 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1315 383
nickjillings@1315 384 if ( value === false ) {
nickjillings@1315 385 break;
nickjillings@1315 386 }
nickjillings@1315 387 }
nickjillings@1315 388 }
nickjillings@1315 389 }
nickjillings@1315 390
nickjillings@1315 391 return obj;
nickjillings@1315 392 },
nickjillings@1315 393
nickjillings@1315 394 // Support: Android<4.1
nickjillings@1315 395 trim: function( text ) {
nickjillings@1315 396 return text == null ?
nickjillings@1315 397 "" :
nickjillings@1315 398 ( text + "" ).replace( rtrim, "" );
nickjillings@1315 399 },
nickjillings@1315 400
nickjillings@1315 401 // results is for internal usage only
nickjillings@1315 402 makeArray: function( arr, results ) {
nickjillings@1315 403 var ret = results || [];
nickjillings@1315 404
nickjillings@1315 405 if ( arr != null ) {
nickjillings@1315 406 if ( isArraylike( Object(arr) ) ) {
nickjillings@1315 407 jQuery.merge( ret,
nickjillings@1315 408 typeof arr === "string" ?
nickjillings@1315 409 [ arr ] : arr
nickjillings@1315 410 );
nickjillings@1315 411 } else {
nickjillings@1315 412 push.call( ret, arr );
nickjillings@1315 413 }
nickjillings@1315 414 }
nickjillings@1315 415
nickjillings@1315 416 return ret;
nickjillings@1315 417 },
nickjillings@1315 418
nickjillings@1315 419 inArray: function( elem, arr, i ) {
nickjillings@1315 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nickjillings@1315 421 },
nickjillings@1315 422
nickjillings@1315 423 merge: function( first, second ) {
nickjillings@1315 424 var len = +second.length,
nickjillings@1315 425 j = 0,
nickjillings@1315 426 i = first.length;
nickjillings@1315 427
nickjillings@1315 428 for ( ; j < len; j++ ) {
nickjillings@1315 429 first[ i++ ] = second[ j ];
nickjillings@1315 430 }
nickjillings@1315 431
nickjillings@1315 432 first.length = i;
nickjillings@1315 433
nickjillings@1315 434 return first;
nickjillings@1315 435 },
nickjillings@1315 436
nickjillings@1315 437 grep: function( elems, callback, invert ) {
nickjillings@1315 438 var callbackInverse,
nickjillings@1315 439 matches = [],
nickjillings@1315 440 i = 0,
nickjillings@1315 441 length = elems.length,
nickjillings@1315 442 callbackExpect = !invert;
nickjillings@1315 443
nickjillings@1315 444 // Go through the array, only saving the items
nickjillings@1315 445 // that pass the validator function
nickjillings@1315 446 for ( ; i < length; i++ ) {
nickjillings@1315 447 callbackInverse = !callback( elems[ i ], i );
nickjillings@1315 448 if ( callbackInverse !== callbackExpect ) {
nickjillings@1315 449 matches.push( elems[ i ] );
nickjillings@1315 450 }
nickjillings@1315 451 }
nickjillings@1315 452
nickjillings@1315 453 return matches;
nickjillings@1315 454 },
nickjillings@1315 455
nickjillings@1315 456 // arg is for internal usage only
nickjillings@1315 457 map: function( elems, callback, arg ) {
nickjillings@1315 458 var value,
nickjillings@1315 459 i = 0,
nickjillings@1315 460 length = elems.length,
nickjillings@1315 461 isArray = isArraylike( elems ),
nickjillings@1315 462 ret = [];
nickjillings@1315 463
nickjillings@1315 464 // Go through the array, translating each of the items to their new values
nickjillings@1315 465 if ( isArray ) {
nickjillings@1315 466 for ( ; i < length; i++ ) {
nickjillings@1315 467 value = callback( elems[ i ], i, arg );
nickjillings@1315 468
nickjillings@1315 469 if ( value != null ) {
nickjillings@1315 470 ret.push( value );
nickjillings@1315 471 }
nickjillings@1315 472 }
nickjillings@1315 473
nickjillings@1315 474 // Go through every key on the object,
nickjillings@1315 475 } else {
nickjillings@1315 476 for ( i in elems ) {
nickjillings@1315 477 value = callback( elems[ i ], i, arg );
nickjillings@1315 478
nickjillings@1315 479 if ( value != null ) {
nickjillings@1315 480 ret.push( value );
nickjillings@1315 481 }
nickjillings@1315 482 }
nickjillings@1315 483 }
nickjillings@1315 484
nickjillings@1315 485 // Flatten any nested arrays
nickjillings@1315 486 return concat.apply( [], ret );
nickjillings@1315 487 },
nickjillings@1315 488
nickjillings@1315 489 // A global GUID counter for objects
nickjillings@1315 490 guid: 1,
nickjillings@1315 491
nickjillings@1315 492 // Bind a function to a context, optionally partially applying any
nickjillings@1315 493 // arguments.
nickjillings@1315 494 proxy: function( fn, context ) {
nickjillings@1315 495 var tmp, args, proxy;
nickjillings@1315 496
nickjillings@1315 497 if ( typeof context === "string" ) {
nickjillings@1315 498 tmp = fn[ context ];
nickjillings@1315 499 context = fn;
nickjillings@1315 500 fn = tmp;
nickjillings@1315 501 }
nickjillings@1315 502
nickjillings@1315 503 // Quick check to determine if target is callable, in the spec
nickjillings@1315 504 // this throws a TypeError, but we will just return undefined.
nickjillings@1315 505 if ( !jQuery.isFunction( fn ) ) {
nickjillings@1315 506 return undefined;
nickjillings@1315 507 }
nickjillings@1315 508
nickjillings@1315 509 // Simulated bind
nickjillings@1315 510 args = slice.call( arguments, 2 );
nickjillings@1315 511 proxy = function() {
nickjillings@1315 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nickjillings@1315 513 };
nickjillings@1315 514
nickjillings@1315 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nickjillings@1315 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nickjillings@1315 517
nickjillings@1315 518 return proxy;
nickjillings@1315 519 },
nickjillings@1315 520
nickjillings@1315 521 now: Date.now,
nickjillings@1315 522
nickjillings@1315 523 // jQuery.support is not used in Core but other projects attach their
nickjillings@1315 524 // properties to it so it needs to exist.
nickjillings@1315 525 support: support
nickjillings@1315 526 });
nickjillings@1315 527
nickjillings@1315 528 // Populate the class2type map
nickjillings@1315 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nickjillings@1315 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nickjillings@1315 531 });
nickjillings@1315 532
nickjillings@1315 533 function isArraylike( obj ) {
nickjillings@1315 534
nickjillings@1315 535 // Support: iOS 8.2 (not reproducible in simulator)
nickjillings@1315 536 // `in` check used to prevent JIT error (gh-2145)
nickjillings@1315 537 // hasOwn isn't used here due to false negatives
nickjillings@1315 538 // regarding Nodelist length in IE
nickjillings@1315 539 var length = "length" in obj && obj.length,
nickjillings@1315 540 type = jQuery.type( obj );
nickjillings@1315 541
nickjillings@1315 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nickjillings@1315 543 return false;
nickjillings@1315 544 }
nickjillings@1315 545
nickjillings@1315 546 if ( obj.nodeType === 1 && length ) {
nickjillings@1315 547 return true;
nickjillings@1315 548 }
nickjillings@1315 549
nickjillings@1315 550 return type === "array" || length === 0 ||
nickjillings@1315 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nickjillings@1315 552 }
nickjillings@1315 553 var Sizzle =
nickjillings@1315 554 /*!
nickjillings@1315 555 * Sizzle CSS Selector Engine v2.2.0-pre
nickjillings@1315 556 * http://sizzlejs.com/
nickjillings@1315 557 *
nickjillings@1315 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1315 559 * Released under the MIT license
nickjillings@1315 560 * http://jquery.org/license
nickjillings@1315 561 *
nickjillings@1315 562 * Date: 2014-12-16
nickjillings@1315 563 */
nickjillings@1315 564 (function( window ) {
nickjillings@1315 565
nickjillings@1315 566 var i,
nickjillings@1315 567 support,
nickjillings@1315 568 Expr,
nickjillings@1315 569 getText,
nickjillings@1315 570 isXML,
nickjillings@1315 571 tokenize,
nickjillings@1315 572 compile,
nickjillings@1315 573 select,
nickjillings@1315 574 outermostContext,
nickjillings@1315 575 sortInput,
nickjillings@1315 576 hasDuplicate,
nickjillings@1315 577
nickjillings@1315 578 // Local document vars
nickjillings@1315 579 setDocument,
nickjillings@1315 580 document,
nickjillings@1315 581 docElem,
nickjillings@1315 582 documentIsHTML,
nickjillings@1315 583 rbuggyQSA,
nickjillings@1315 584 rbuggyMatches,
nickjillings@1315 585 matches,
nickjillings@1315 586 contains,
nickjillings@1315 587
nickjillings@1315 588 // Instance-specific data
nickjillings@1315 589 expando = "sizzle" + 1 * new Date(),
nickjillings@1315 590 preferredDoc = window.document,
nickjillings@1315 591 dirruns = 0,
nickjillings@1315 592 done = 0,
nickjillings@1315 593 classCache = createCache(),
nickjillings@1315 594 tokenCache = createCache(),
nickjillings@1315 595 compilerCache = createCache(),
nickjillings@1315 596 sortOrder = function( a, b ) {
nickjillings@1315 597 if ( a === b ) {
nickjillings@1315 598 hasDuplicate = true;
nickjillings@1315 599 }
nickjillings@1315 600 return 0;
nickjillings@1315 601 },
nickjillings@1315 602
nickjillings@1315 603 // General-purpose constants
nickjillings@1315 604 MAX_NEGATIVE = 1 << 31,
nickjillings@1315 605
nickjillings@1315 606 // Instance methods
nickjillings@1315 607 hasOwn = ({}).hasOwnProperty,
nickjillings@1315 608 arr = [],
nickjillings@1315 609 pop = arr.pop,
nickjillings@1315 610 push_native = arr.push,
nickjillings@1315 611 push = arr.push,
nickjillings@1315 612 slice = arr.slice,
nickjillings@1315 613 // Use a stripped-down indexOf as it's faster than native
nickjillings@1315 614 // http://jsperf.com/thor-indexof-vs-for/5
nickjillings@1315 615 indexOf = function( list, elem ) {
nickjillings@1315 616 var i = 0,
nickjillings@1315 617 len = list.length;
nickjillings@1315 618 for ( ; i < len; i++ ) {
nickjillings@1315 619 if ( list[i] === elem ) {
nickjillings@1315 620 return i;
nickjillings@1315 621 }
nickjillings@1315 622 }
nickjillings@1315 623 return -1;
nickjillings@1315 624 },
nickjillings@1315 625
nickjillings@1315 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nickjillings@1315 627
nickjillings@1315 628 // Regular expressions
nickjillings@1315 629
nickjillings@1315 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nickjillings@1315 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nickjillings@1315 632 // http://www.w3.org/TR/css3-syntax/#characters
nickjillings@1315 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nickjillings@1315 634
nickjillings@1315 635 // Loosely modeled on CSS identifier characters
nickjillings@1315 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nickjillings@1315 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nickjillings@1315 638 identifier = characterEncoding.replace( "w", "w#" ),
nickjillings@1315 639
nickjillings@1315 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nickjillings@1315 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nickjillings@1315 642 // Operator (capture 2)
nickjillings@1315 643 "*([*^$|!~]?=)" + whitespace +
nickjillings@1315 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nickjillings@1315 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nickjillings@1315 646 "*\\]",
nickjillings@1315 647
nickjillings@1315 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nickjillings@1315 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nickjillings@1315 650 // 1. quoted (capture 3; capture 4 or capture 5)
nickjillings@1315 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nickjillings@1315 652 // 2. simple (capture 6)
nickjillings@1315 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nickjillings@1315 654 // 3. anything else (capture 2)
nickjillings@1315 655 ".*" +
nickjillings@1315 656 ")\\)|)",
nickjillings@1315 657
nickjillings@1315 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nickjillings@1315 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nickjillings@1315 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nickjillings@1315 661
nickjillings@1315 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nickjillings@1315 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nickjillings@1315 664
nickjillings@1315 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nickjillings@1315 666
nickjillings@1315 667 rpseudo = new RegExp( pseudos ),
nickjillings@1315 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nickjillings@1315 669
nickjillings@1315 670 matchExpr = {
nickjillings@1315 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nickjillings@1315 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nickjillings@1315 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nickjillings@1315 674 "ATTR": new RegExp( "^" + attributes ),
nickjillings@1315 675 "PSEUDO": new RegExp( "^" + pseudos ),
nickjillings@1315 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nickjillings@1315 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nickjillings@1315 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nickjillings@1315 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nickjillings@1315 680 // For use in libraries implementing .is()
nickjillings@1315 681 // We use this for POS matching in `select`
nickjillings@1315 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nickjillings@1315 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nickjillings@1315 684 },
nickjillings@1315 685
nickjillings@1315 686 rinputs = /^(?:input|select|textarea|button)$/i,
nickjillings@1315 687 rheader = /^h\d$/i,
nickjillings@1315 688
nickjillings@1315 689 rnative = /^[^{]+\{\s*\[native \w/,
nickjillings@1315 690
nickjillings@1315 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nickjillings@1315 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nickjillings@1315 693
nickjillings@1315 694 rsibling = /[+~]/,
nickjillings@1315 695 rescape = /'|\\/g,
nickjillings@1315 696
nickjillings@1315 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nickjillings@1315 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nickjillings@1315 699 funescape = function( _, escaped, escapedWhitespace ) {
nickjillings@1315 700 var high = "0x" + escaped - 0x10000;
nickjillings@1315 701 // NaN means non-codepoint
nickjillings@1315 702 // Support: Firefox<24
nickjillings@1315 703 // Workaround erroneous numeric interpretation of +"0x"
nickjillings@1315 704 return high !== high || escapedWhitespace ?
nickjillings@1315 705 escaped :
nickjillings@1315 706 high < 0 ?
nickjillings@1315 707 // BMP codepoint
nickjillings@1315 708 String.fromCharCode( high + 0x10000 ) :
nickjillings@1315 709 // Supplemental Plane codepoint (surrogate pair)
nickjillings@1315 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nickjillings@1315 711 },
nickjillings@1315 712
nickjillings@1315 713 // Used for iframes
nickjillings@1315 714 // See setDocument()
nickjillings@1315 715 // Removing the function wrapper causes a "Permission Denied"
nickjillings@1315 716 // error in IE
nickjillings@1315 717 unloadHandler = function() {
nickjillings@1315 718 setDocument();
nickjillings@1315 719 };
nickjillings@1315 720
nickjillings@1315 721 // Optimize for push.apply( _, NodeList )
nickjillings@1315 722 try {
nickjillings@1315 723 push.apply(
nickjillings@1315 724 (arr = slice.call( preferredDoc.childNodes )),
nickjillings@1315 725 preferredDoc.childNodes
nickjillings@1315 726 );
nickjillings@1315 727 // Support: Android<4.0
nickjillings@1315 728 // Detect silently failing push.apply
nickjillings@1315 729 arr[ preferredDoc.childNodes.length ].nodeType;
nickjillings@1315 730 } catch ( e ) {
nickjillings@1315 731 push = { apply: arr.length ?
nickjillings@1315 732
nickjillings@1315 733 // Leverage slice if possible
nickjillings@1315 734 function( target, els ) {
nickjillings@1315 735 push_native.apply( target, slice.call(els) );
nickjillings@1315 736 } :
nickjillings@1315 737
nickjillings@1315 738 // Support: IE<9
nickjillings@1315 739 // Otherwise append directly
nickjillings@1315 740 function( target, els ) {
nickjillings@1315 741 var j = target.length,
nickjillings@1315 742 i = 0;
nickjillings@1315 743 // Can't trust NodeList.length
nickjillings@1315 744 while ( (target[j++] = els[i++]) ) {}
nickjillings@1315 745 target.length = j - 1;
nickjillings@1315 746 }
nickjillings@1315 747 };
nickjillings@1315 748 }
nickjillings@1315 749
nickjillings@1315 750 function Sizzle( selector, context, results, seed ) {
nickjillings@1315 751 var match, elem, m, nodeType,
nickjillings@1315 752 // QSA vars
nickjillings@1315 753 i, groups, old, nid, newContext, newSelector;
nickjillings@1315 754
nickjillings@1315 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nickjillings@1315 756 setDocument( context );
nickjillings@1315 757 }
nickjillings@1315 758
nickjillings@1315 759 context = context || document;
nickjillings@1315 760 results = results || [];
nickjillings@1315 761 nodeType = context.nodeType;
nickjillings@1315 762
nickjillings@1315 763 if ( typeof selector !== "string" || !selector ||
nickjillings@1315 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nickjillings@1315 765
nickjillings@1315 766 return results;
nickjillings@1315 767 }
nickjillings@1315 768
nickjillings@1315 769 if ( !seed && documentIsHTML ) {
nickjillings@1315 770
nickjillings@1315 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nickjillings@1315 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nickjillings@1315 773 // Speed-up: Sizzle("#ID")
nickjillings@1315 774 if ( (m = match[1]) ) {
nickjillings@1315 775 if ( nodeType === 9 ) {
nickjillings@1315 776 elem = context.getElementById( m );
nickjillings@1315 777 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1315 778 // nodes that are no longer in the document (jQuery #6963)
nickjillings@1315 779 if ( elem && elem.parentNode ) {
nickjillings@1315 780 // Handle the case where IE, Opera, and Webkit return items
nickjillings@1315 781 // by name instead of ID
nickjillings@1315 782 if ( elem.id === m ) {
nickjillings@1315 783 results.push( elem );
nickjillings@1315 784 return results;
nickjillings@1315 785 }
nickjillings@1315 786 } else {
nickjillings@1315 787 return results;
nickjillings@1315 788 }
nickjillings@1315 789 } else {
nickjillings@1315 790 // Context is not a document
nickjillings@1315 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nickjillings@1315 792 contains( context, elem ) && elem.id === m ) {
nickjillings@1315 793 results.push( elem );
nickjillings@1315 794 return results;
nickjillings@1315 795 }
nickjillings@1315 796 }
nickjillings@1315 797
nickjillings@1315 798 // Speed-up: Sizzle("TAG")
nickjillings@1315 799 } else if ( match[2] ) {
nickjillings@1315 800 push.apply( results, context.getElementsByTagName( selector ) );
nickjillings@1315 801 return results;
nickjillings@1315 802
nickjillings@1315 803 // Speed-up: Sizzle(".CLASS")
nickjillings@1315 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nickjillings@1315 805 push.apply( results, context.getElementsByClassName( m ) );
nickjillings@1315 806 return results;
nickjillings@1315 807 }
nickjillings@1315 808 }
nickjillings@1315 809
nickjillings@1315 810 // QSA path
nickjillings@1315 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nickjillings@1315 812 nid = old = expando;
nickjillings@1315 813 newContext = context;
nickjillings@1315 814 newSelector = nodeType !== 1 && selector;
nickjillings@1315 815
nickjillings@1315 816 // qSA works strangely on Element-rooted queries
nickjillings@1315 817 // We can work around this by specifying an extra ID on the root
nickjillings@1315 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nickjillings@1315 819 // IE 8 doesn't work on object elements
nickjillings@1315 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nickjillings@1315 821 groups = tokenize( selector );
nickjillings@1315 822
nickjillings@1315 823 if ( (old = context.getAttribute("id")) ) {
nickjillings@1315 824 nid = old.replace( rescape, "\\$&" );
nickjillings@1315 825 } else {
nickjillings@1315 826 context.setAttribute( "id", nid );
nickjillings@1315 827 }
nickjillings@1315 828 nid = "[id='" + nid + "'] ";
nickjillings@1315 829
nickjillings@1315 830 i = groups.length;
nickjillings@1315 831 while ( i-- ) {
nickjillings@1315 832 groups[i] = nid + toSelector( groups[i] );
nickjillings@1315 833 }
nickjillings@1315 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nickjillings@1315 835 newSelector = groups.join(",");
nickjillings@1315 836 }
nickjillings@1315 837
nickjillings@1315 838 if ( newSelector ) {
nickjillings@1315 839 try {
nickjillings@1315 840 push.apply( results,
nickjillings@1315 841 newContext.querySelectorAll( newSelector )
nickjillings@1315 842 );
nickjillings@1315 843 return results;
nickjillings@1315 844 } catch(qsaError) {
nickjillings@1315 845 } finally {
nickjillings@1315 846 if ( !old ) {
nickjillings@1315 847 context.removeAttribute("id");
nickjillings@1315 848 }
nickjillings@1315 849 }
nickjillings@1315 850 }
nickjillings@1315 851 }
nickjillings@1315 852 }
nickjillings@1315 853
nickjillings@1315 854 // All others
nickjillings@1315 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nickjillings@1315 856 }
nickjillings@1315 857
nickjillings@1315 858 /**
nickjillings@1315 859 * Create key-value caches of limited size
nickjillings@1315 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nickjillings@1315 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nickjillings@1315 862 * deleting the oldest entry
nickjillings@1315 863 */
nickjillings@1315 864 function createCache() {
nickjillings@1315 865 var keys = [];
nickjillings@1315 866
nickjillings@1315 867 function cache( key, value ) {
nickjillings@1315 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nickjillings@1315 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nickjillings@1315 870 // Only keep the most recent entries
nickjillings@1315 871 delete cache[ keys.shift() ];
nickjillings@1315 872 }
nickjillings@1315 873 return (cache[ key + " " ] = value);
nickjillings@1315 874 }
nickjillings@1315 875 return cache;
nickjillings@1315 876 }
nickjillings@1315 877
nickjillings@1315 878 /**
nickjillings@1315 879 * Mark a function for special use by Sizzle
nickjillings@1315 880 * @param {Function} fn The function to mark
nickjillings@1315 881 */
nickjillings@1315 882 function markFunction( fn ) {
nickjillings@1315 883 fn[ expando ] = true;
nickjillings@1315 884 return fn;
nickjillings@1315 885 }
nickjillings@1315 886
nickjillings@1315 887 /**
nickjillings@1315 888 * Support testing using an element
nickjillings@1315 889 * @param {Function} fn Passed the created div and expects a boolean result
nickjillings@1315 890 */
nickjillings@1315 891 function assert( fn ) {
nickjillings@1315 892 var div = document.createElement("div");
nickjillings@1315 893
nickjillings@1315 894 try {
nickjillings@1315 895 return !!fn( div );
nickjillings@1315 896 } catch (e) {
nickjillings@1315 897 return false;
nickjillings@1315 898 } finally {
nickjillings@1315 899 // Remove from its parent by default
nickjillings@1315 900 if ( div.parentNode ) {
nickjillings@1315 901 div.parentNode.removeChild( div );
nickjillings@1315 902 }
nickjillings@1315 903 // release memory in IE
nickjillings@1315 904 div = null;
nickjillings@1315 905 }
nickjillings@1315 906 }
nickjillings@1315 907
nickjillings@1315 908 /**
nickjillings@1315 909 * Adds the same handler for all of the specified attrs
nickjillings@1315 910 * @param {String} attrs Pipe-separated list of attributes
nickjillings@1315 911 * @param {Function} handler The method that will be applied
nickjillings@1315 912 */
nickjillings@1315 913 function addHandle( attrs, handler ) {
nickjillings@1315 914 var arr = attrs.split("|"),
nickjillings@1315 915 i = attrs.length;
nickjillings@1315 916
nickjillings@1315 917 while ( i-- ) {
nickjillings@1315 918 Expr.attrHandle[ arr[i] ] = handler;
nickjillings@1315 919 }
nickjillings@1315 920 }
nickjillings@1315 921
nickjillings@1315 922 /**
nickjillings@1315 923 * Checks document order of two siblings
nickjillings@1315 924 * @param {Element} a
nickjillings@1315 925 * @param {Element} b
nickjillings@1315 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nickjillings@1315 927 */
nickjillings@1315 928 function siblingCheck( a, b ) {
nickjillings@1315 929 var cur = b && a,
nickjillings@1315 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nickjillings@1315 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nickjillings@1315 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nickjillings@1315 933
nickjillings@1315 934 // Use IE sourceIndex if available on both nodes
nickjillings@1315 935 if ( diff ) {
nickjillings@1315 936 return diff;
nickjillings@1315 937 }
nickjillings@1315 938
nickjillings@1315 939 // Check if b follows a
nickjillings@1315 940 if ( cur ) {
nickjillings@1315 941 while ( (cur = cur.nextSibling) ) {
nickjillings@1315 942 if ( cur === b ) {
nickjillings@1315 943 return -1;
nickjillings@1315 944 }
nickjillings@1315 945 }
nickjillings@1315 946 }
nickjillings@1315 947
nickjillings@1315 948 return a ? 1 : -1;
nickjillings@1315 949 }
nickjillings@1315 950
nickjillings@1315 951 /**
nickjillings@1315 952 * Returns a function to use in pseudos for input types
nickjillings@1315 953 * @param {String} type
nickjillings@1315 954 */
nickjillings@1315 955 function createInputPseudo( type ) {
nickjillings@1315 956 return function( elem ) {
nickjillings@1315 957 var name = elem.nodeName.toLowerCase();
nickjillings@1315 958 return name === "input" && elem.type === type;
nickjillings@1315 959 };
nickjillings@1315 960 }
nickjillings@1315 961
nickjillings@1315 962 /**
nickjillings@1315 963 * Returns a function to use in pseudos for buttons
nickjillings@1315 964 * @param {String} type
nickjillings@1315 965 */
nickjillings@1315 966 function createButtonPseudo( type ) {
nickjillings@1315 967 return function( elem ) {
nickjillings@1315 968 var name = elem.nodeName.toLowerCase();
nickjillings@1315 969 return (name === "input" || name === "button") && elem.type === type;
nickjillings@1315 970 };
nickjillings@1315 971 }
nickjillings@1315 972
nickjillings@1315 973 /**
nickjillings@1315 974 * Returns a function to use in pseudos for positionals
nickjillings@1315 975 * @param {Function} fn
nickjillings@1315 976 */
nickjillings@1315 977 function createPositionalPseudo( fn ) {
nickjillings@1315 978 return markFunction(function( argument ) {
nickjillings@1315 979 argument = +argument;
nickjillings@1315 980 return markFunction(function( seed, matches ) {
nickjillings@1315 981 var j,
nickjillings@1315 982 matchIndexes = fn( [], seed.length, argument ),
nickjillings@1315 983 i = matchIndexes.length;
nickjillings@1315 984
nickjillings@1315 985 // Match elements found at the specified indexes
nickjillings@1315 986 while ( i-- ) {
nickjillings@1315 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nickjillings@1315 988 seed[j] = !(matches[j] = seed[j]);
nickjillings@1315 989 }
nickjillings@1315 990 }
nickjillings@1315 991 });
nickjillings@1315 992 });
nickjillings@1315 993 }
nickjillings@1315 994
nickjillings@1315 995 /**
nickjillings@1315 996 * Checks a node for validity as a Sizzle context
nickjillings@1315 997 * @param {Element|Object=} context
nickjillings@1315 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nickjillings@1315 999 */
nickjillings@1315 1000 function testContext( context ) {
nickjillings@1315 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nickjillings@1315 1002 }
nickjillings@1315 1003
nickjillings@1315 1004 // Expose support vars for convenience
nickjillings@1315 1005 support = Sizzle.support = {};
nickjillings@1315 1006
nickjillings@1315 1007 /**
nickjillings@1315 1008 * Detects XML nodes
nickjillings@1315 1009 * @param {Element|Object} elem An element or a document
nickjillings@1315 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nickjillings@1315 1011 */
nickjillings@1315 1012 isXML = Sizzle.isXML = function( elem ) {
nickjillings@1315 1013 // documentElement is verified for cases where it doesn't yet exist
nickjillings@1315 1014 // (such as loading iframes in IE - #4833)
nickjillings@1315 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nickjillings@1315 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nickjillings@1315 1017 };
nickjillings@1315 1018
nickjillings@1315 1019 /**
nickjillings@1315 1020 * Sets document-related variables once based on the current document
nickjillings@1315 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nickjillings@1315 1022 * @returns {Object} Returns the current document
nickjillings@1315 1023 */
nickjillings@1315 1024 setDocument = Sizzle.setDocument = function( node ) {
nickjillings@1315 1025 var hasCompare, parent,
nickjillings@1315 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nickjillings@1315 1027
nickjillings@1315 1028 // If no document and documentElement is available, return
nickjillings@1315 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nickjillings@1315 1030 return document;
nickjillings@1315 1031 }
nickjillings@1315 1032
nickjillings@1315 1033 // Set our document
nickjillings@1315 1034 document = doc;
nickjillings@1315 1035 docElem = doc.documentElement;
nickjillings@1315 1036 parent = doc.defaultView;
nickjillings@1315 1037
nickjillings@1315 1038 // Support: IE>8
nickjillings@1315 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nickjillings@1315 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nickjillings@1315 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nickjillings@1315 1042 if ( parent && parent !== parent.top ) {
nickjillings@1315 1043 // IE11 does not have attachEvent, so all must suffer
nickjillings@1315 1044 if ( parent.addEventListener ) {
nickjillings@1315 1045 parent.addEventListener( "unload", unloadHandler, false );
nickjillings@1315 1046 } else if ( parent.attachEvent ) {
nickjillings@1315 1047 parent.attachEvent( "onunload", unloadHandler );
nickjillings@1315 1048 }
nickjillings@1315 1049 }
nickjillings@1315 1050
nickjillings@1315 1051 /* Support tests
nickjillings@1315 1052 ---------------------------------------------------------------------- */
nickjillings@1315 1053 documentIsHTML = !isXML( doc );
nickjillings@1315 1054
nickjillings@1315 1055 /* Attributes
nickjillings@1315 1056 ---------------------------------------------------------------------- */
nickjillings@1315 1057
nickjillings@1315 1058 // Support: IE<8
nickjillings@1315 1059 // Verify that getAttribute really returns attributes and not properties
nickjillings@1315 1060 // (excepting IE8 booleans)
nickjillings@1315 1061 support.attributes = assert(function( div ) {
nickjillings@1315 1062 div.className = "i";
nickjillings@1315 1063 return !div.getAttribute("className");
nickjillings@1315 1064 });
nickjillings@1315 1065
nickjillings@1315 1066 /* getElement(s)By*
nickjillings@1315 1067 ---------------------------------------------------------------------- */
nickjillings@1315 1068
nickjillings@1315 1069 // Check if getElementsByTagName("*") returns only elements
nickjillings@1315 1070 support.getElementsByTagName = assert(function( div ) {
nickjillings@1315 1071 div.appendChild( doc.createComment("") );
nickjillings@1315 1072 return !div.getElementsByTagName("*").length;
nickjillings@1315 1073 });
nickjillings@1315 1074
nickjillings@1315 1075 // Support: IE<9
nickjillings@1315 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nickjillings@1315 1077
nickjillings@1315 1078 // Support: IE<10
nickjillings@1315 1079 // Check if getElementById returns elements by name
nickjillings@1315 1080 // The broken getElementById methods don't pick up programatically-set names,
nickjillings@1315 1081 // so use a roundabout getElementsByName test
nickjillings@1315 1082 support.getById = assert(function( div ) {
nickjillings@1315 1083 docElem.appendChild( div ).id = expando;
nickjillings@1315 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nickjillings@1315 1085 });
nickjillings@1315 1086
nickjillings@1315 1087 // ID find and filter
nickjillings@1315 1088 if ( support.getById ) {
nickjillings@1315 1089 Expr.find["ID"] = function( id, context ) {
nickjillings@1315 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nickjillings@1315 1091 var m = context.getElementById( id );
nickjillings@1315 1092 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1315 1093 // nodes that are no longer in the document #6963
nickjillings@1315 1094 return m && m.parentNode ? [ m ] : [];
nickjillings@1315 1095 }
nickjillings@1315 1096 };
nickjillings@1315 1097 Expr.filter["ID"] = function( id ) {
nickjillings@1315 1098 var attrId = id.replace( runescape, funescape );
nickjillings@1315 1099 return function( elem ) {
nickjillings@1315 1100 return elem.getAttribute("id") === attrId;
nickjillings@1315 1101 };
nickjillings@1315 1102 };
nickjillings@1315 1103 } else {
nickjillings@1315 1104 // Support: IE6/7
nickjillings@1315 1105 // getElementById is not reliable as a find shortcut
nickjillings@1315 1106 delete Expr.find["ID"];
nickjillings@1315 1107
nickjillings@1315 1108 Expr.filter["ID"] = function( id ) {
nickjillings@1315 1109 var attrId = id.replace( runescape, funescape );
nickjillings@1315 1110 return function( elem ) {
nickjillings@1315 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nickjillings@1315 1112 return node && node.value === attrId;
nickjillings@1315 1113 };
nickjillings@1315 1114 };
nickjillings@1315 1115 }
nickjillings@1315 1116
nickjillings@1315 1117 // Tag
nickjillings@1315 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nickjillings@1315 1119 function( tag, context ) {
nickjillings@1315 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nickjillings@1315 1121 return context.getElementsByTagName( tag );
nickjillings@1315 1122
nickjillings@1315 1123 // DocumentFragment nodes don't have gEBTN
nickjillings@1315 1124 } else if ( support.qsa ) {
nickjillings@1315 1125 return context.querySelectorAll( tag );
nickjillings@1315 1126 }
nickjillings@1315 1127 } :
nickjillings@1315 1128
nickjillings@1315 1129 function( tag, context ) {
nickjillings@1315 1130 var elem,
nickjillings@1315 1131 tmp = [],
nickjillings@1315 1132 i = 0,
nickjillings@1315 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nickjillings@1315 1134 results = context.getElementsByTagName( tag );
nickjillings@1315 1135
nickjillings@1315 1136 // Filter out possible comments
nickjillings@1315 1137 if ( tag === "*" ) {
nickjillings@1315 1138 while ( (elem = results[i++]) ) {
nickjillings@1315 1139 if ( elem.nodeType === 1 ) {
nickjillings@1315 1140 tmp.push( elem );
nickjillings@1315 1141 }
nickjillings@1315 1142 }
nickjillings@1315 1143
nickjillings@1315 1144 return tmp;
nickjillings@1315 1145 }
nickjillings@1315 1146 return results;
nickjillings@1315 1147 };
nickjillings@1315 1148
nickjillings@1315 1149 // Class
nickjillings@1315 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nickjillings@1315 1151 if ( documentIsHTML ) {
nickjillings@1315 1152 return context.getElementsByClassName( className );
nickjillings@1315 1153 }
nickjillings@1315 1154 };
nickjillings@1315 1155
nickjillings@1315 1156 /* QSA/matchesSelector
nickjillings@1315 1157 ---------------------------------------------------------------------- */
nickjillings@1315 1158
nickjillings@1315 1159 // QSA and matchesSelector support
nickjillings@1315 1160
nickjillings@1315 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nickjillings@1315 1162 rbuggyMatches = [];
nickjillings@1315 1163
nickjillings@1315 1164 // qSa(:focus) reports false when true (Chrome 21)
nickjillings@1315 1165 // We allow this because of a bug in IE8/9 that throws an error
nickjillings@1315 1166 // whenever `document.activeElement` is accessed on an iframe
nickjillings@1315 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nickjillings@1315 1168 // See http://bugs.jquery.com/ticket/13378
nickjillings@1315 1169 rbuggyQSA = [];
nickjillings@1315 1170
nickjillings@1315 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nickjillings@1315 1172 // Build QSA regex
nickjillings@1315 1173 // Regex strategy adopted from Diego Perini
nickjillings@1315 1174 assert(function( div ) {
nickjillings@1315 1175 // Select is set to empty string on purpose
nickjillings@1315 1176 // This is to test IE's treatment of not explicitly
nickjillings@1315 1177 // setting a boolean content attribute,
nickjillings@1315 1178 // since its presence should be enough
nickjillings@1315 1179 // http://bugs.jquery.com/ticket/12359
nickjillings@1315 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nickjillings@1315 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nickjillings@1315 1182 "<option selected=''></option></select>";
nickjillings@1315 1183
nickjillings@1315 1184 // Support: IE8, Opera 11-12.16
nickjillings@1315 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nickjillings@1315 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nickjillings@1315 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nickjillings@1315 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nickjillings@1315 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nickjillings@1315 1190 }
nickjillings@1315 1191
nickjillings@1315 1192 // Support: IE8
nickjillings@1315 1193 // Boolean attributes and "value" are not treated correctly
nickjillings@1315 1194 if ( !div.querySelectorAll("[selected]").length ) {
nickjillings@1315 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nickjillings@1315 1196 }
nickjillings@1315 1197
nickjillings@1315 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nickjillings@1315 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nickjillings@1315 1200 rbuggyQSA.push("~=");
nickjillings@1315 1201 }
nickjillings@1315 1202
nickjillings@1315 1203 // Webkit/Opera - :checked should return selected option elements
nickjillings@1315 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1315 1205 // IE8 throws error here and will not see later tests
nickjillings@1315 1206 if ( !div.querySelectorAll(":checked").length ) {
nickjillings@1315 1207 rbuggyQSA.push(":checked");
nickjillings@1315 1208 }
nickjillings@1315 1209
nickjillings@1315 1210 // Support: Safari 8+, iOS 8+
nickjillings@1315 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nickjillings@1315 1212 // In-page `selector#id sibing-combinator selector` fails
nickjillings@1315 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nickjillings@1315 1214 rbuggyQSA.push(".#.+[+~]");
nickjillings@1315 1215 }
nickjillings@1315 1216 });
nickjillings@1315 1217
nickjillings@1315 1218 assert(function( div ) {
nickjillings@1315 1219 // Support: Windows 8 Native Apps
nickjillings@1315 1220 // The type and name attributes are restricted during .innerHTML assignment
nickjillings@1315 1221 var input = doc.createElement("input");
nickjillings@1315 1222 input.setAttribute( "type", "hidden" );
nickjillings@1315 1223 div.appendChild( input ).setAttribute( "name", "D" );
nickjillings@1315 1224
nickjillings@1315 1225 // Support: IE8
nickjillings@1315 1226 // Enforce case-sensitivity of name attribute
nickjillings@1315 1227 if ( div.querySelectorAll("[name=d]").length ) {
nickjillings@1315 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nickjillings@1315 1229 }
nickjillings@1315 1230
nickjillings@1315 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nickjillings@1315 1232 // IE8 throws error here and will not see later tests
nickjillings@1315 1233 if ( !div.querySelectorAll(":enabled").length ) {
nickjillings@1315 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nickjillings@1315 1235 }
nickjillings@1315 1236
nickjillings@1315 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nickjillings@1315 1238 div.querySelectorAll("*,:x");
nickjillings@1315 1239 rbuggyQSA.push(",.*:");
nickjillings@1315 1240 });
nickjillings@1315 1241 }
nickjillings@1315 1242
nickjillings@1315 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nickjillings@1315 1244 docElem.webkitMatchesSelector ||
nickjillings@1315 1245 docElem.mozMatchesSelector ||
nickjillings@1315 1246 docElem.oMatchesSelector ||
nickjillings@1315 1247 docElem.msMatchesSelector) )) ) {
nickjillings@1315 1248
nickjillings@1315 1249 assert(function( div ) {
nickjillings@1315 1250 // Check to see if it's possible to do matchesSelector
nickjillings@1315 1251 // on a disconnected node (IE 9)
nickjillings@1315 1252 support.disconnectedMatch = matches.call( div, "div" );
nickjillings@1315 1253
nickjillings@1315 1254 // This should fail with an exception
nickjillings@1315 1255 // Gecko does not error, returns false instead
nickjillings@1315 1256 matches.call( div, "[s!='']:x" );
nickjillings@1315 1257 rbuggyMatches.push( "!=", pseudos );
nickjillings@1315 1258 });
nickjillings@1315 1259 }
nickjillings@1315 1260
nickjillings@1315 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nickjillings@1315 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nickjillings@1315 1263
nickjillings@1315 1264 /* Contains
nickjillings@1315 1265 ---------------------------------------------------------------------- */
nickjillings@1315 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nickjillings@1315 1267
nickjillings@1315 1268 // Element contains another
nickjillings@1315 1269 // Purposefully does not implement inclusive descendent
nickjillings@1315 1270 // As in, an element does not contain itself
nickjillings@1315 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nickjillings@1315 1272 function( a, b ) {
nickjillings@1315 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nickjillings@1315 1274 bup = b && b.parentNode;
nickjillings@1315 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nickjillings@1315 1276 adown.contains ?
nickjillings@1315 1277 adown.contains( bup ) :
nickjillings@1315 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nickjillings@1315 1279 ));
nickjillings@1315 1280 } :
nickjillings@1315 1281 function( a, b ) {
nickjillings@1315 1282 if ( b ) {
nickjillings@1315 1283 while ( (b = b.parentNode) ) {
nickjillings@1315 1284 if ( b === a ) {
nickjillings@1315 1285 return true;
nickjillings@1315 1286 }
nickjillings@1315 1287 }
nickjillings@1315 1288 }
nickjillings@1315 1289 return false;
nickjillings@1315 1290 };
nickjillings@1315 1291
nickjillings@1315 1292 /* Sorting
nickjillings@1315 1293 ---------------------------------------------------------------------- */
nickjillings@1315 1294
nickjillings@1315 1295 // Document order sorting
nickjillings@1315 1296 sortOrder = hasCompare ?
nickjillings@1315 1297 function( a, b ) {
nickjillings@1315 1298
nickjillings@1315 1299 // Flag for duplicate removal
nickjillings@1315 1300 if ( a === b ) {
nickjillings@1315 1301 hasDuplicate = true;
nickjillings@1315 1302 return 0;
nickjillings@1315 1303 }
nickjillings@1315 1304
nickjillings@1315 1305 // Sort on method existence if only one input has compareDocumentPosition
nickjillings@1315 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nickjillings@1315 1307 if ( compare ) {
nickjillings@1315 1308 return compare;
nickjillings@1315 1309 }
nickjillings@1315 1310
nickjillings@1315 1311 // Calculate position if both inputs belong to the same document
nickjillings@1315 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nickjillings@1315 1313 a.compareDocumentPosition( b ) :
nickjillings@1315 1314
nickjillings@1315 1315 // Otherwise we know they are disconnected
nickjillings@1315 1316 1;
nickjillings@1315 1317
nickjillings@1315 1318 // Disconnected nodes
nickjillings@1315 1319 if ( compare & 1 ||
nickjillings@1315 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nickjillings@1315 1321
nickjillings@1315 1322 // Choose the first element that is related to our preferred document
nickjillings@1315 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nickjillings@1315 1324 return -1;
nickjillings@1315 1325 }
nickjillings@1315 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nickjillings@1315 1327 return 1;
nickjillings@1315 1328 }
nickjillings@1315 1329
nickjillings@1315 1330 // Maintain original order
nickjillings@1315 1331 return sortInput ?
nickjillings@1315 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1315 1333 0;
nickjillings@1315 1334 }
nickjillings@1315 1335
nickjillings@1315 1336 return compare & 4 ? -1 : 1;
nickjillings@1315 1337 } :
nickjillings@1315 1338 function( a, b ) {
nickjillings@1315 1339 // Exit early if the nodes are identical
nickjillings@1315 1340 if ( a === b ) {
nickjillings@1315 1341 hasDuplicate = true;
nickjillings@1315 1342 return 0;
nickjillings@1315 1343 }
nickjillings@1315 1344
nickjillings@1315 1345 var cur,
nickjillings@1315 1346 i = 0,
nickjillings@1315 1347 aup = a.parentNode,
nickjillings@1315 1348 bup = b.parentNode,
nickjillings@1315 1349 ap = [ a ],
nickjillings@1315 1350 bp = [ b ];
nickjillings@1315 1351
nickjillings@1315 1352 // Parentless nodes are either documents or disconnected
nickjillings@1315 1353 if ( !aup || !bup ) {
nickjillings@1315 1354 return a === doc ? -1 :
nickjillings@1315 1355 b === doc ? 1 :
nickjillings@1315 1356 aup ? -1 :
nickjillings@1315 1357 bup ? 1 :
nickjillings@1315 1358 sortInput ?
nickjillings@1315 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1315 1360 0;
nickjillings@1315 1361
nickjillings@1315 1362 // If the nodes are siblings, we can do a quick check
nickjillings@1315 1363 } else if ( aup === bup ) {
nickjillings@1315 1364 return siblingCheck( a, b );
nickjillings@1315 1365 }
nickjillings@1315 1366
nickjillings@1315 1367 // Otherwise we need full lists of their ancestors for comparison
nickjillings@1315 1368 cur = a;
nickjillings@1315 1369 while ( (cur = cur.parentNode) ) {
nickjillings@1315 1370 ap.unshift( cur );
nickjillings@1315 1371 }
nickjillings@1315 1372 cur = b;
nickjillings@1315 1373 while ( (cur = cur.parentNode) ) {
nickjillings@1315 1374 bp.unshift( cur );
nickjillings@1315 1375 }
nickjillings@1315 1376
nickjillings@1315 1377 // Walk down the tree looking for a discrepancy
nickjillings@1315 1378 while ( ap[i] === bp[i] ) {
nickjillings@1315 1379 i++;
nickjillings@1315 1380 }
nickjillings@1315 1381
nickjillings@1315 1382 return i ?
nickjillings@1315 1383 // Do a sibling check if the nodes have a common ancestor
nickjillings@1315 1384 siblingCheck( ap[i], bp[i] ) :
nickjillings@1315 1385
nickjillings@1315 1386 // Otherwise nodes in our document sort first
nickjillings@1315 1387 ap[i] === preferredDoc ? -1 :
nickjillings@1315 1388 bp[i] === preferredDoc ? 1 :
nickjillings@1315 1389 0;
nickjillings@1315 1390 };
nickjillings@1315 1391
nickjillings@1315 1392 return doc;
nickjillings@1315 1393 };
nickjillings@1315 1394
nickjillings@1315 1395 Sizzle.matches = function( expr, elements ) {
nickjillings@1315 1396 return Sizzle( expr, null, null, elements );
nickjillings@1315 1397 };
nickjillings@1315 1398
nickjillings@1315 1399 Sizzle.matchesSelector = function( elem, expr ) {
nickjillings@1315 1400 // Set document vars if needed
nickjillings@1315 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1315 1402 setDocument( elem );
nickjillings@1315 1403 }
nickjillings@1315 1404
nickjillings@1315 1405 // Make sure that attribute selectors are quoted
nickjillings@1315 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nickjillings@1315 1407
nickjillings@1315 1408 if ( support.matchesSelector && documentIsHTML &&
nickjillings@1315 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nickjillings@1315 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nickjillings@1315 1411
nickjillings@1315 1412 try {
nickjillings@1315 1413 var ret = matches.call( elem, expr );
nickjillings@1315 1414
nickjillings@1315 1415 // IE 9's matchesSelector returns false on disconnected nodes
nickjillings@1315 1416 if ( ret || support.disconnectedMatch ||
nickjillings@1315 1417 // As well, disconnected nodes are said to be in a document
nickjillings@1315 1418 // fragment in IE 9
nickjillings@1315 1419 elem.document && elem.document.nodeType !== 11 ) {
nickjillings@1315 1420 return ret;
nickjillings@1315 1421 }
nickjillings@1315 1422 } catch (e) {}
nickjillings@1315 1423 }
nickjillings@1315 1424
nickjillings@1315 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nickjillings@1315 1426 };
nickjillings@1315 1427
nickjillings@1315 1428 Sizzle.contains = function( context, elem ) {
nickjillings@1315 1429 // Set document vars if needed
nickjillings@1315 1430 if ( ( context.ownerDocument || context ) !== document ) {
nickjillings@1315 1431 setDocument( context );
nickjillings@1315 1432 }
nickjillings@1315 1433 return contains( context, elem );
nickjillings@1315 1434 };
nickjillings@1315 1435
nickjillings@1315 1436 Sizzle.attr = function( elem, name ) {
nickjillings@1315 1437 // Set document vars if needed
nickjillings@1315 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1315 1439 setDocument( elem );
nickjillings@1315 1440 }
nickjillings@1315 1441
nickjillings@1315 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nickjillings@1315 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nickjillings@1315 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nickjillings@1315 1445 fn( elem, name, !documentIsHTML ) :
nickjillings@1315 1446 undefined;
nickjillings@1315 1447
nickjillings@1315 1448 return val !== undefined ?
nickjillings@1315 1449 val :
nickjillings@1315 1450 support.attributes || !documentIsHTML ?
nickjillings@1315 1451 elem.getAttribute( name ) :
nickjillings@1315 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nickjillings@1315 1453 val.value :
nickjillings@1315 1454 null;
nickjillings@1315 1455 };
nickjillings@1315 1456
nickjillings@1315 1457 Sizzle.error = function( msg ) {
nickjillings@1315 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nickjillings@1315 1459 };
nickjillings@1315 1460
nickjillings@1315 1461 /**
nickjillings@1315 1462 * Document sorting and removing duplicates
nickjillings@1315 1463 * @param {ArrayLike} results
nickjillings@1315 1464 */
nickjillings@1315 1465 Sizzle.uniqueSort = function( results ) {
nickjillings@1315 1466 var elem,
nickjillings@1315 1467 duplicates = [],
nickjillings@1315 1468 j = 0,
nickjillings@1315 1469 i = 0;
nickjillings@1315 1470
nickjillings@1315 1471 // Unless we *know* we can detect duplicates, assume their presence
nickjillings@1315 1472 hasDuplicate = !support.detectDuplicates;
nickjillings@1315 1473 sortInput = !support.sortStable && results.slice( 0 );
nickjillings@1315 1474 results.sort( sortOrder );
nickjillings@1315 1475
nickjillings@1315 1476 if ( hasDuplicate ) {
nickjillings@1315 1477 while ( (elem = results[i++]) ) {
nickjillings@1315 1478 if ( elem === results[ i ] ) {
nickjillings@1315 1479 j = duplicates.push( i );
nickjillings@1315 1480 }
nickjillings@1315 1481 }
nickjillings@1315 1482 while ( j-- ) {
nickjillings@1315 1483 results.splice( duplicates[ j ], 1 );
nickjillings@1315 1484 }
nickjillings@1315 1485 }
nickjillings@1315 1486
nickjillings@1315 1487 // Clear input after sorting to release objects
nickjillings@1315 1488 // See https://github.com/jquery/sizzle/pull/225
nickjillings@1315 1489 sortInput = null;
nickjillings@1315 1490
nickjillings@1315 1491 return results;
nickjillings@1315 1492 };
nickjillings@1315 1493
nickjillings@1315 1494 /**
nickjillings@1315 1495 * Utility function for retrieving the text value of an array of DOM nodes
nickjillings@1315 1496 * @param {Array|Element} elem
nickjillings@1315 1497 */
nickjillings@1315 1498 getText = Sizzle.getText = function( elem ) {
nickjillings@1315 1499 var node,
nickjillings@1315 1500 ret = "",
nickjillings@1315 1501 i = 0,
nickjillings@1315 1502 nodeType = elem.nodeType;
nickjillings@1315 1503
nickjillings@1315 1504 if ( !nodeType ) {
nickjillings@1315 1505 // If no nodeType, this is expected to be an array
nickjillings@1315 1506 while ( (node = elem[i++]) ) {
nickjillings@1315 1507 // Do not traverse comment nodes
nickjillings@1315 1508 ret += getText( node );
nickjillings@1315 1509 }
nickjillings@1315 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nickjillings@1315 1511 // Use textContent for elements
nickjillings@1315 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nickjillings@1315 1513 if ( typeof elem.textContent === "string" ) {
nickjillings@1315 1514 return elem.textContent;
nickjillings@1315 1515 } else {
nickjillings@1315 1516 // Traverse its children
nickjillings@1315 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1315 1518 ret += getText( elem );
nickjillings@1315 1519 }
nickjillings@1315 1520 }
nickjillings@1315 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nickjillings@1315 1522 return elem.nodeValue;
nickjillings@1315 1523 }
nickjillings@1315 1524 // Do not include comment or processing instruction nodes
nickjillings@1315 1525
nickjillings@1315 1526 return ret;
nickjillings@1315 1527 };
nickjillings@1315 1528
nickjillings@1315 1529 Expr = Sizzle.selectors = {
nickjillings@1315 1530
nickjillings@1315 1531 // Can be adjusted by the user
nickjillings@1315 1532 cacheLength: 50,
nickjillings@1315 1533
nickjillings@1315 1534 createPseudo: markFunction,
nickjillings@1315 1535
nickjillings@1315 1536 match: matchExpr,
nickjillings@1315 1537
nickjillings@1315 1538 attrHandle: {},
nickjillings@1315 1539
nickjillings@1315 1540 find: {},
nickjillings@1315 1541
nickjillings@1315 1542 relative: {
nickjillings@1315 1543 ">": { dir: "parentNode", first: true },
nickjillings@1315 1544 " ": { dir: "parentNode" },
nickjillings@1315 1545 "+": { dir: "previousSibling", first: true },
nickjillings@1315 1546 "~": { dir: "previousSibling" }
nickjillings@1315 1547 },
nickjillings@1315 1548
nickjillings@1315 1549 preFilter: {
nickjillings@1315 1550 "ATTR": function( match ) {
nickjillings@1315 1551 match[1] = match[1].replace( runescape, funescape );
nickjillings@1315 1552
nickjillings@1315 1553 // Move the given value to match[3] whether quoted or unquoted
nickjillings@1315 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nickjillings@1315 1555
nickjillings@1315 1556 if ( match[2] === "~=" ) {
nickjillings@1315 1557 match[3] = " " + match[3] + " ";
nickjillings@1315 1558 }
nickjillings@1315 1559
nickjillings@1315 1560 return match.slice( 0, 4 );
nickjillings@1315 1561 },
nickjillings@1315 1562
nickjillings@1315 1563 "CHILD": function( match ) {
nickjillings@1315 1564 /* matches from matchExpr["CHILD"]
nickjillings@1315 1565 1 type (only|nth|...)
nickjillings@1315 1566 2 what (child|of-type)
nickjillings@1315 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nickjillings@1315 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nickjillings@1315 1569 5 sign of xn-component
nickjillings@1315 1570 6 x of xn-component
nickjillings@1315 1571 7 sign of y-component
nickjillings@1315 1572 8 y of y-component
nickjillings@1315 1573 */
nickjillings@1315 1574 match[1] = match[1].toLowerCase();
nickjillings@1315 1575
nickjillings@1315 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nickjillings@1315 1577 // nth-* requires argument
nickjillings@1315 1578 if ( !match[3] ) {
nickjillings@1315 1579 Sizzle.error( match[0] );
nickjillings@1315 1580 }
nickjillings@1315 1581
nickjillings@1315 1582 // numeric x and y parameters for Expr.filter.CHILD
nickjillings@1315 1583 // remember that false/true cast respectively to 0/1
nickjillings@1315 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nickjillings@1315 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nickjillings@1315 1586
nickjillings@1315 1587 // other types prohibit arguments
nickjillings@1315 1588 } else if ( match[3] ) {
nickjillings@1315 1589 Sizzle.error( match[0] );
nickjillings@1315 1590 }
nickjillings@1315 1591
nickjillings@1315 1592 return match;
nickjillings@1315 1593 },
nickjillings@1315 1594
nickjillings@1315 1595 "PSEUDO": function( match ) {
nickjillings@1315 1596 var excess,
nickjillings@1315 1597 unquoted = !match[6] && match[2];
nickjillings@1315 1598
nickjillings@1315 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nickjillings@1315 1600 return null;
nickjillings@1315 1601 }
nickjillings@1315 1602
nickjillings@1315 1603 // Accept quoted arguments as-is
nickjillings@1315 1604 if ( match[3] ) {
nickjillings@1315 1605 match[2] = match[4] || match[5] || "";
nickjillings@1315 1606
nickjillings@1315 1607 // Strip excess characters from unquoted arguments
nickjillings@1315 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nickjillings@1315 1609 // Get excess from tokenize (recursively)
nickjillings@1315 1610 (excess = tokenize( unquoted, true )) &&
nickjillings@1315 1611 // advance to the next closing parenthesis
nickjillings@1315 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nickjillings@1315 1613
nickjillings@1315 1614 // excess is a negative index
nickjillings@1315 1615 match[0] = match[0].slice( 0, excess );
nickjillings@1315 1616 match[2] = unquoted.slice( 0, excess );
nickjillings@1315 1617 }
nickjillings@1315 1618
nickjillings@1315 1619 // Return only captures needed by the pseudo filter method (type and argument)
nickjillings@1315 1620 return match.slice( 0, 3 );
nickjillings@1315 1621 }
nickjillings@1315 1622 },
nickjillings@1315 1623
nickjillings@1315 1624 filter: {
nickjillings@1315 1625
nickjillings@1315 1626 "TAG": function( nodeNameSelector ) {
nickjillings@1315 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nickjillings@1315 1628 return nodeNameSelector === "*" ?
nickjillings@1315 1629 function() { return true; } :
nickjillings@1315 1630 function( elem ) {
nickjillings@1315 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nickjillings@1315 1632 };
nickjillings@1315 1633 },
nickjillings@1315 1634
nickjillings@1315 1635 "CLASS": function( className ) {
nickjillings@1315 1636 var pattern = classCache[ className + " " ];
nickjillings@1315 1637
nickjillings@1315 1638 return pattern ||
nickjillings@1315 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nickjillings@1315 1640 classCache( className, function( elem ) {
nickjillings@1315 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nickjillings@1315 1642 });
nickjillings@1315 1643 },
nickjillings@1315 1644
nickjillings@1315 1645 "ATTR": function( name, operator, check ) {
nickjillings@1315 1646 return function( elem ) {
nickjillings@1315 1647 var result = Sizzle.attr( elem, name );
nickjillings@1315 1648
nickjillings@1315 1649 if ( result == null ) {
nickjillings@1315 1650 return operator === "!=";
nickjillings@1315 1651 }
nickjillings@1315 1652 if ( !operator ) {
nickjillings@1315 1653 return true;
nickjillings@1315 1654 }
nickjillings@1315 1655
nickjillings@1315 1656 result += "";
nickjillings@1315 1657
nickjillings@1315 1658 return operator === "=" ? result === check :
nickjillings@1315 1659 operator === "!=" ? result !== check :
nickjillings@1315 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nickjillings@1315 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nickjillings@1315 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nickjillings@1315 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nickjillings@1315 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nickjillings@1315 1665 false;
nickjillings@1315 1666 };
nickjillings@1315 1667 },
nickjillings@1315 1668
nickjillings@1315 1669 "CHILD": function( type, what, argument, first, last ) {
nickjillings@1315 1670 var simple = type.slice( 0, 3 ) !== "nth",
nickjillings@1315 1671 forward = type.slice( -4 ) !== "last",
nickjillings@1315 1672 ofType = what === "of-type";
nickjillings@1315 1673
nickjillings@1315 1674 return first === 1 && last === 0 ?
nickjillings@1315 1675
nickjillings@1315 1676 // Shortcut for :nth-*(n)
nickjillings@1315 1677 function( elem ) {
nickjillings@1315 1678 return !!elem.parentNode;
nickjillings@1315 1679 } :
nickjillings@1315 1680
nickjillings@1315 1681 function( elem, context, xml ) {
nickjillings@1315 1682 var cache, outerCache, node, diff, nodeIndex, start,
nickjillings@1315 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nickjillings@1315 1684 parent = elem.parentNode,
nickjillings@1315 1685 name = ofType && elem.nodeName.toLowerCase(),
nickjillings@1315 1686 useCache = !xml && !ofType;
nickjillings@1315 1687
nickjillings@1315 1688 if ( parent ) {
nickjillings@1315 1689
nickjillings@1315 1690 // :(first|last|only)-(child|of-type)
nickjillings@1315 1691 if ( simple ) {
nickjillings@1315 1692 while ( dir ) {
nickjillings@1315 1693 node = elem;
nickjillings@1315 1694 while ( (node = node[ dir ]) ) {
nickjillings@1315 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nickjillings@1315 1696 return false;
nickjillings@1315 1697 }
nickjillings@1315 1698 }
nickjillings@1315 1699 // Reverse direction for :only-* (if we haven't yet done so)
nickjillings@1315 1700 start = dir = type === "only" && !start && "nextSibling";
nickjillings@1315 1701 }
nickjillings@1315 1702 return true;
nickjillings@1315 1703 }
nickjillings@1315 1704
nickjillings@1315 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nickjillings@1315 1706
nickjillings@1315 1707 // non-xml :nth-child(...) stores cache data on `parent`
nickjillings@1315 1708 if ( forward && useCache ) {
nickjillings@1315 1709 // Seek `elem` from a previously-cached index
nickjillings@1315 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nickjillings@1315 1711 cache = outerCache[ type ] || [];
nickjillings@1315 1712 nodeIndex = cache[0] === dirruns && cache[1];
nickjillings@1315 1713 diff = cache[0] === dirruns && cache[2];
nickjillings@1315 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nickjillings@1315 1715
nickjillings@1315 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1315 1717
nickjillings@1315 1718 // Fallback to seeking `elem` from the start
nickjillings@1315 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1315 1720
nickjillings@1315 1721 // When found, cache indexes on `parent` and break
nickjillings@1315 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nickjillings@1315 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nickjillings@1315 1724 break;
nickjillings@1315 1725 }
nickjillings@1315 1726 }
nickjillings@1315 1727
nickjillings@1315 1728 // Use previously-cached element index if available
nickjillings@1315 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nickjillings@1315 1730 diff = cache[1];
nickjillings@1315 1731
nickjillings@1315 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nickjillings@1315 1733 } else {
nickjillings@1315 1734 // Use the same loop as above to seek `elem` from the start
nickjillings@1315 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1315 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1315 1737
nickjillings@1315 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nickjillings@1315 1739 // Cache the index of each encountered element
nickjillings@1315 1740 if ( useCache ) {
nickjillings@1315 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nickjillings@1315 1742 }
nickjillings@1315 1743
nickjillings@1315 1744 if ( node === elem ) {
nickjillings@1315 1745 break;
nickjillings@1315 1746 }
nickjillings@1315 1747 }
nickjillings@1315 1748 }
nickjillings@1315 1749 }
nickjillings@1315 1750
nickjillings@1315 1751 // Incorporate the offset, then check against cycle size
nickjillings@1315 1752 diff -= last;
nickjillings@1315 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nickjillings@1315 1754 }
nickjillings@1315 1755 };
nickjillings@1315 1756 },
nickjillings@1315 1757
nickjillings@1315 1758 "PSEUDO": function( pseudo, argument ) {
nickjillings@1315 1759 // pseudo-class names are case-insensitive
nickjillings@1315 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nickjillings@1315 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nickjillings@1315 1762 // Remember that setFilters inherits from pseudos
nickjillings@1315 1763 var args,
nickjillings@1315 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nickjillings@1315 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nickjillings@1315 1766
nickjillings@1315 1767 // The user may use createPseudo to indicate that
nickjillings@1315 1768 // arguments are needed to create the filter function
nickjillings@1315 1769 // just as Sizzle does
nickjillings@1315 1770 if ( fn[ expando ] ) {
nickjillings@1315 1771 return fn( argument );
nickjillings@1315 1772 }
nickjillings@1315 1773
nickjillings@1315 1774 // But maintain support for old signatures
nickjillings@1315 1775 if ( fn.length > 1 ) {
nickjillings@1315 1776 args = [ pseudo, pseudo, "", argument ];
nickjillings@1315 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nickjillings@1315 1778 markFunction(function( seed, matches ) {
nickjillings@1315 1779 var idx,
nickjillings@1315 1780 matched = fn( seed, argument ),
nickjillings@1315 1781 i = matched.length;
nickjillings@1315 1782 while ( i-- ) {
nickjillings@1315 1783 idx = indexOf( seed, matched[i] );
nickjillings@1315 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nickjillings@1315 1785 }
nickjillings@1315 1786 }) :
nickjillings@1315 1787 function( elem ) {
nickjillings@1315 1788 return fn( elem, 0, args );
nickjillings@1315 1789 };
nickjillings@1315 1790 }
nickjillings@1315 1791
nickjillings@1315 1792 return fn;
nickjillings@1315 1793 }
nickjillings@1315 1794 },
nickjillings@1315 1795
nickjillings@1315 1796 pseudos: {
nickjillings@1315 1797 // Potentially complex pseudos
nickjillings@1315 1798 "not": markFunction(function( selector ) {
nickjillings@1315 1799 // Trim the selector passed to compile
nickjillings@1315 1800 // to avoid treating leading and trailing
nickjillings@1315 1801 // spaces as combinators
nickjillings@1315 1802 var input = [],
nickjillings@1315 1803 results = [],
nickjillings@1315 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nickjillings@1315 1805
nickjillings@1315 1806 return matcher[ expando ] ?
nickjillings@1315 1807 markFunction(function( seed, matches, context, xml ) {
nickjillings@1315 1808 var elem,
nickjillings@1315 1809 unmatched = matcher( seed, null, xml, [] ),
nickjillings@1315 1810 i = seed.length;
nickjillings@1315 1811
nickjillings@1315 1812 // Match elements unmatched by `matcher`
nickjillings@1315 1813 while ( i-- ) {
nickjillings@1315 1814 if ( (elem = unmatched[i]) ) {
nickjillings@1315 1815 seed[i] = !(matches[i] = elem);
nickjillings@1315 1816 }
nickjillings@1315 1817 }
nickjillings@1315 1818 }) :
nickjillings@1315 1819 function( elem, context, xml ) {
nickjillings@1315 1820 input[0] = elem;
nickjillings@1315 1821 matcher( input, null, xml, results );
nickjillings@1315 1822 // Don't keep the element (issue #299)
nickjillings@1315 1823 input[0] = null;
nickjillings@1315 1824 return !results.pop();
nickjillings@1315 1825 };
nickjillings@1315 1826 }),
nickjillings@1315 1827
nickjillings@1315 1828 "has": markFunction(function( selector ) {
nickjillings@1315 1829 return function( elem ) {
nickjillings@1315 1830 return Sizzle( selector, elem ).length > 0;
nickjillings@1315 1831 };
nickjillings@1315 1832 }),
nickjillings@1315 1833
nickjillings@1315 1834 "contains": markFunction(function( text ) {
nickjillings@1315 1835 text = text.replace( runescape, funescape );
nickjillings@1315 1836 return function( elem ) {
nickjillings@1315 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nickjillings@1315 1838 };
nickjillings@1315 1839 }),
nickjillings@1315 1840
nickjillings@1315 1841 // "Whether an element is represented by a :lang() selector
nickjillings@1315 1842 // is based solely on the element's language value
nickjillings@1315 1843 // being equal to the identifier C,
nickjillings@1315 1844 // or beginning with the identifier C immediately followed by "-".
nickjillings@1315 1845 // The matching of C against the element's language value is performed case-insensitively.
nickjillings@1315 1846 // The identifier C does not have to be a valid language name."
nickjillings@1315 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nickjillings@1315 1848 "lang": markFunction( function( lang ) {
nickjillings@1315 1849 // lang value must be a valid identifier
nickjillings@1315 1850 if ( !ridentifier.test(lang || "") ) {
nickjillings@1315 1851 Sizzle.error( "unsupported lang: " + lang );
nickjillings@1315 1852 }
nickjillings@1315 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nickjillings@1315 1854 return function( elem ) {
nickjillings@1315 1855 var elemLang;
nickjillings@1315 1856 do {
nickjillings@1315 1857 if ( (elemLang = documentIsHTML ?
nickjillings@1315 1858 elem.lang :
nickjillings@1315 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nickjillings@1315 1860
nickjillings@1315 1861 elemLang = elemLang.toLowerCase();
nickjillings@1315 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nickjillings@1315 1863 }
nickjillings@1315 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nickjillings@1315 1865 return false;
nickjillings@1315 1866 };
nickjillings@1315 1867 }),
nickjillings@1315 1868
nickjillings@1315 1869 // Miscellaneous
nickjillings@1315 1870 "target": function( elem ) {
nickjillings@1315 1871 var hash = window.location && window.location.hash;
nickjillings@1315 1872 return hash && hash.slice( 1 ) === elem.id;
nickjillings@1315 1873 },
nickjillings@1315 1874
nickjillings@1315 1875 "root": function( elem ) {
nickjillings@1315 1876 return elem === docElem;
nickjillings@1315 1877 },
nickjillings@1315 1878
nickjillings@1315 1879 "focus": function( elem ) {
nickjillings@1315 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nickjillings@1315 1881 },
nickjillings@1315 1882
nickjillings@1315 1883 // Boolean properties
nickjillings@1315 1884 "enabled": function( elem ) {
nickjillings@1315 1885 return elem.disabled === false;
nickjillings@1315 1886 },
nickjillings@1315 1887
nickjillings@1315 1888 "disabled": function( elem ) {
nickjillings@1315 1889 return elem.disabled === true;
nickjillings@1315 1890 },
nickjillings@1315 1891
nickjillings@1315 1892 "checked": function( elem ) {
nickjillings@1315 1893 // In CSS3, :checked should return both checked and selected elements
nickjillings@1315 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1315 1895 var nodeName = elem.nodeName.toLowerCase();
nickjillings@1315 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nickjillings@1315 1897 },
nickjillings@1315 1898
nickjillings@1315 1899 "selected": function( elem ) {
nickjillings@1315 1900 // Accessing this property makes selected-by-default
nickjillings@1315 1901 // options in Safari work properly
nickjillings@1315 1902 if ( elem.parentNode ) {
nickjillings@1315 1903 elem.parentNode.selectedIndex;
nickjillings@1315 1904 }
nickjillings@1315 1905
nickjillings@1315 1906 return elem.selected === true;
nickjillings@1315 1907 },
nickjillings@1315 1908
nickjillings@1315 1909 // Contents
nickjillings@1315 1910 "empty": function( elem ) {
nickjillings@1315 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nickjillings@1315 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nickjillings@1315 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nickjillings@1315 1914 // nodeType < 6 works because attributes (2) do not appear as children
nickjillings@1315 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1315 1916 if ( elem.nodeType < 6 ) {
nickjillings@1315 1917 return false;
nickjillings@1315 1918 }
nickjillings@1315 1919 }
nickjillings@1315 1920 return true;
nickjillings@1315 1921 },
nickjillings@1315 1922
nickjillings@1315 1923 "parent": function( elem ) {
nickjillings@1315 1924 return !Expr.pseudos["empty"]( elem );
nickjillings@1315 1925 },
nickjillings@1315 1926
nickjillings@1315 1927 // Element/input types
nickjillings@1315 1928 "header": function( elem ) {
nickjillings@1315 1929 return rheader.test( elem.nodeName );
nickjillings@1315 1930 },
nickjillings@1315 1931
nickjillings@1315 1932 "input": function( elem ) {
nickjillings@1315 1933 return rinputs.test( elem.nodeName );
nickjillings@1315 1934 },
nickjillings@1315 1935
nickjillings@1315 1936 "button": function( elem ) {
nickjillings@1315 1937 var name = elem.nodeName.toLowerCase();
nickjillings@1315 1938 return name === "input" && elem.type === "button" || name === "button";
nickjillings@1315 1939 },
nickjillings@1315 1940
nickjillings@1315 1941 "text": function( elem ) {
nickjillings@1315 1942 var attr;
nickjillings@1315 1943 return elem.nodeName.toLowerCase() === "input" &&
nickjillings@1315 1944 elem.type === "text" &&
nickjillings@1315 1945
nickjillings@1315 1946 // Support: IE<8
nickjillings@1315 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nickjillings@1315 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nickjillings@1315 1949 },
nickjillings@1315 1950
nickjillings@1315 1951 // Position-in-collection
nickjillings@1315 1952 "first": createPositionalPseudo(function() {
nickjillings@1315 1953 return [ 0 ];
nickjillings@1315 1954 }),
nickjillings@1315 1955
nickjillings@1315 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1315 1957 return [ length - 1 ];
nickjillings@1315 1958 }),
nickjillings@1315 1959
nickjillings@1315 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1315 1961 return [ argument < 0 ? argument + length : argument ];
nickjillings@1315 1962 }),
nickjillings@1315 1963
nickjillings@1315 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1315 1965 var i = 0;
nickjillings@1315 1966 for ( ; i < length; i += 2 ) {
nickjillings@1315 1967 matchIndexes.push( i );
nickjillings@1315 1968 }
nickjillings@1315 1969 return matchIndexes;
nickjillings@1315 1970 }),
nickjillings@1315 1971
nickjillings@1315 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1315 1973 var i = 1;
nickjillings@1315 1974 for ( ; i < length; i += 2 ) {
nickjillings@1315 1975 matchIndexes.push( i );
nickjillings@1315 1976 }
nickjillings@1315 1977 return matchIndexes;
nickjillings@1315 1978 }),
nickjillings@1315 1979
nickjillings@1315 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1315 1981 var i = argument < 0 ? argument + length : argument;
nickjillings@1315 1982 for ( ; --i >= 0; ) {
nickjillings@1315 1983 matchIndexes.push( i );
nickjillings@1315 1984 }
nickjillings@1315 1985 return matchIndexes;
nickjillings@1315 1986 }),
nickjillings@1315 1987
nickjillings@1315 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1315 1989 var i = argument < 0 ? argument + length : argument;
nickjillings@1315 1990 for ( ; ++i < length; ) {
nickjillings@1315 1991 matchIndexes.push( i );
nickjillings@1315 1992 }
nickjillings@1315 1993 return matchIndexes;
nickjillings@1315 1994 })
nickjillings@1315 1995 }
nickjillings@1315 1996 };
nickjillings@1315 1997
nickjillings@1315 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nickjillings@1315 1999
nickjillings@1315 2000 // Add button/input type pseudos
nickjillings@1315 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nickjillings@1315 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nickjillings@1315 2003 }
nickjillings@1315 2004 for ( i in { submit: true, reset: true } ) {
nickjillings@1315 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nickjillings@1315 2006 }
nickjillings@1315 2007
nickjillings@1315 2008 // Easy API for creating new setFilters
nickjillings@1315 2009 function setFilters() {}
nickjillings@1315 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nickjillings@1315 2011 Expr.setFilters = new setFilters();
nickjillings@1315 2012
nickjillings@1315 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nickjillings@1315 2014 var matched, match, tokens, type,
nickjillings@1315 2015 soFar, groups, preFilters,
nickjillings@1315 2016 cached = tokenCache[ selector + " " ];
nickjillings@1315 2017
nickjillings@1315 2018 if ( cached ) {
nickjillings@1315 2019 return parseOnly ? 0 : cached.slice( 0 );
nickjillings@1315 2020 }
nickjillings@1315 2021
nickjillings@1315 2022 soFar = selector;
nickjillings@1315 2023 groups = [];
nickjillings@1315 2024 preFilters = Expr.preFilter;
nickjillings@1315 2025
nickjillings@1315 2026 while ( soFar ) {
nickjillings@1315 2027
nickjillings@1315 2028 // Comma and first run
nickjillings@1315 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nickjillings@1315 2030 if ( match ) {
nickjillings@1315 2031 // Don't consume trailing commas as valid
nickjillings@1315 2032 soFar = soFar.slice( match[0].length ) || soFar;
nickjillings@1315 2033 }
nickjillings@1315 2034 groups.push( (tokens = []) );
nickjillings@1315 2035 }
nickjillings@1315 2036
nickjillings@1315 2037 matched = false;
nickjillings@1315 2038
nickjillings@1315 2039 // Combinators
nickjillings@1315 2040 if ( (match = rcombinators.exec( soFar )) ) {
nickjillings@1315 2041 matched = match.shift();
nickjillings@1315 2042 tokens.push({
nickjillings@1315 2043 value: matched,
nickjillings@1315 2044 // Cast descendant combinators to space
nickjillings@1315 2045 type: match[0].replace( rtrim, " " )
nickjillings@1315 2046 });
nickjillings@1315 2047 soFar = soFar.slice( matched.length );
nickjillings@1315 2048 }
nickjillings@1315 2049
nickjillings@1315 2050 // Filters
nickjillings@1315 2051 for ( type in Expr.filter ) {
nickjillings@1315 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nickjillings@1315 2053 (match = preFilters[ type ]( match ))) ) {
nickjillings@1315 2054 matched = match.shift();
nickjillings@1315 2055 tokens.push({
nickjillings@1315 2056 value: matched,
nickjillings@1315 2057 type: type,
nickjillings@1315 2058 matches: match
nickjillings@1315 2059 });
nickjillings@1315 2060 soFar = soFar.slice( matched.length );
nickjillings@1315 2061 }
nickjillings@1315 2062 }
nickjillings@1315 2063
nickjillings@1315 2064 if ( !matched ) {
nickjillings@1315 2065 break;
nickjillings@1315 2066 }
nickjillings@1315 2067 }
nickjillings@1315 2068
nickjillings@1315 2069 // Return the length of the invalid excess
nickjillings@1315 2070 // if we're just parsing
nickjillings@1315 2071 // Otherwise, throw an error or return tokens
nickjillings@1315 2072 return parseOnly ?
nickjillings@1315 2073 soFar.length :
nickjillings@1315 2074 soFar ?
nickjillings@1315 2075 Sizzle.error( selector ) :
nickjillings@1315 2076 // Cache the tokens
nickjillings@1315 2077 tokenCache( selector, groups ).slice( 0 );
nickjillings@1315 2078 };
nickjillings@1315 2079
nickjillings@1315 2080 function toSelector( tokens ) {
nickjillings@1315 2081 var i = 0,
nickjillings@1315 2082 len = tokens.length,
nickjillings@1315 2083 selector = "";
nickjillings@1315 2084 for ( ; i < len; i++ ) {
nickjillings@1315 2085 selector += tokens[i].value;
nickjillings@1315 2086 }
nickjillings@1315 2087 return selector;
nickjillings@1315 2088 }
nickjillings@1315 2089
nickjillings@1315 2090 function addCombinator( matcher, combinator, base ) {
nickjillings@1315 2091 var dir = combinator.dir,
nickjillings@1315 2092 checkNonElements = base && dir === "parentNode",
nickjillings@1315 2093 doneName = done++;
nickjillings@1315 2094
nickjillings@1315 2095 return combinator.first ?
nickjillings@1315 2096 // Check against closest ancestor/preceding element
nickjillings@1315 2097 function( elem, context, xml ) {
nickjillings@1315 2098 while ( (elem = elem[ dir ]) ) {
nickjillings@1315 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1315 2100 return matcher( elem, context, xml );
nickjillings@1315 2101 }
nickjillings@1315 2102 }
nickjillings@1315 2103 } :
nickjillings@1315 2104
nickjillings@1315 2105 // Check against all ancestor/preceding elements
nickjillings@1315 2106 function( elem, context, xml ) {
nickjillings@1315 2107 var oldCache, outerCache,
nickjillings@1315 2108 newCache = [ dirruns, doneName ];
nickjillings@1315 2109
nickjillings@1315 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nickjillings@1315 2111 if ( xml ) {
nickjillings@1315 2112 while ( (elem = elem[ dir ]) ) {
nickjillings@1315 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1315 2114 if ( matcher( elem, context, xml ) ) {
nickjillings@1315 2115 return true;
nickjillings@1315 2116 }
nickjillings@1315 2117 }
nickjillings@1315 2118 }
nickjillings@1315 2119 } else {
nickjillings@1315 2120 while ( (elem = elem[ dir ]) ) {
nickjillings@1315 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1315 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nickjillings@1315 2123 if ( (oldCache = outerCache[ dir ]) &&
nickjillings@1315 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nickjillings@1315 2125
nickjillings@1315 2126 // Assign to newCache so results back-propagate to previous elements
nickjillings@1315 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nickjillings@1315 2128 } else {
nickjillings@1315 2129 // Reuse newcache so results back-propagate to previous elements
nickjillings@1315 2130 outerCache[ dir ] = newCache;
nickjillings@1315 2131
nickjillings@1315 2132 // A match means we're done; a fail means we have to keep checking
nickjillings@1315 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nickjillings@1315 2134 return true;
nickjillings@1315 2135 }
nickjillings@1315 2136 }
nickjillings@1315 2137 }
nickjillings@1315 2138 }
nickjillings@1315 2139 }
nickjillings@1315 2140 };
nickjillings@1315 2141 }
nickjillings@1315 2142
nickjillings@1315 2143 function elementMatcher( matchers ) {
nickjillings@1315 2144 return matchers.length > 1 ?
nickjillings@1315 2145 function( elem, context, xml ) {
nickjillings@1315 2146 var i = matchers.length;
nickjillings@1315 2147 while ( i-- ) {
nickjillings@1315 2148 if ( !matchers[i]( elem, context, xml ) ) {
nickjillings@1315 2149 return false;
nickjillings@1315 2150 }
nickjillings@1315 2151 }
nickjillings@1315 2152 return true;
nickjillings@1315 2153 } :
nickjillings@1315 2154 matchers[0];
nickjillings@1315 2155 }
nickjillings@1315 2156
nickjillings@1315 2157 function multipleContexts( selector, contexts, results ) {
nickjillings@1315 2158 var i = 0,
nickjillings@1315 2159 len = contexts.length;
nickjillings@1315 2160 for ( ; i < len; i++ ) {
nickjillings@1315 2161 Sizzle( selector, contexts[i], results );
nickjillings@1315 2162 }
nickjillings@1315 2163 return results;
nickjillings@1315 2164 }
nickjillings@1315 2165
nickjillings@1315 2166 function condense( unmatched, map, filter, context, xml ) {
nickjillings@1315 2167 var elem,
nickjillings@1315 2168 newUnmatched = [],
nickjillings@1315 2169 i = 0,
nickjillings@1315 2170 len = unmatched.length,
nickjillings@1315 2171 mapped = map != null;
nickjillings@1315 2172
nickjillings@1315 2173 for ( ; i < len; i++ ) {
nickjillings@1315 2174 if ( (elem = unmatched[i]) ) {
nickjillings@1315 2175 if ( !filter || filter( elem, context, xml ) ) {
nickjillings@1315 2176 newUnmatched.push( elem );
nickjillings@1315 2177 if ( mapped ) {
nickjillings@1315 2178 map.push( i );
nickjillings@1315 2179 }
nickjillings@1315 2180 }
nickjillings@1315 2181 }
nickjillings@1315 2182 }
nickjillings@1315 2183
nickjillings@1315 2184 return newUnmatched;
nickjillings@1315 2185 }
nickjillings@1315 2186
nickjillings@1315 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nickjillings@1315 2188 if ( postFilter && !postFilter[ expando ] ) {
nickjillings@1315 2189 postFilter = setMatcher( postFilter );
nickjillings@1315 2190 }
nickjillings@1315 2191 if ( postFinder && !postFinder[ expando ] ) {
nickjillings@1315 2192 postFinder = setMatcher( postFinder, postSelector );
nickjillings@1315 2193 }
nickjillings@1315 2194 return markFunction(function( seed, results, context, xml ) {
nickjillings@1315 2195 var temp, i, elem,
nickjillings@1315 2196 preMap = [],
nickjillings@1315 2197 postMap = [],
nickjillings@1315 2198 preexisting = results.length,
nickjillings@1315 2199
nickjillings@1315 2200 // Get initial elements from seed or context
nickjillings@1315 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nickjillings@1315 2202
nickjillings@1315 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nickjillings@1315 2204 matcherIn = preFilter && ( seed || !selector ) ?
nickjillings@1315 2205 condense( elems, preMap, preFilter, context, xml ) :
nickjillings@1315 2206 elems,
nickjillings@1315 2207
nickjillings@1315 2208 matcherOut = matcher ?
nickjillings@1315 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nickjillings@1315 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nickjillings@1315 2211
nickjillings@1315 2212 // ...intermediate processing is necessary
nickjillings@1315 2213 [] :
nickjillings@1315 2214
nickjillings@1315 2215 // ...otherwise use results directly
nickjillings@1315 2216 results :
nickjillings@1315 2217 matcherIn;
nickjillings@1315 2218
nickjillings@1315 2219 // Find primary matches
nickjillings@1315 2220 if ( matcher ) {
nickjillings@1315 2221 matcher( matcherIn, matcherOut, context, xml );
nickjillings@1315 2222 }
nickjillings@1315 2223
nickjillings@1315 2224 // Apply postFilter
nickjillings@1315 2225 if ( postFilter ) {
nickjillings@1315 2226 temp = condense( matcherOut, postMap );
nickjillings@1315 2227 postFilter( temp, [], context, xml );
nickjillings@1315 2228
nickjillings@1315 2229 // Un-match failing elements by moving them back to matcherIn
nickjillings@1315 2230 i = temp.length;
nickjillings@1315 2231 while ( i-- ) {
nickjillings@1315 2232 if ( (elem = temp[i]) ) {
nickjillings@1315 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nickjillings@1315 2234 }
nickjillings@1315 2235 }
nickjillings@1315 2236 }
nickjillings@1315 2237
nickjillings@1315 2238 if ( seed ) {
nickjillings@1315 2239 if ( postFinder || preFilter ) {
nickjillings@1315 2240 if ( postFinder ) {
nickjillings@1315 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nickjillings@1315 2242 temp = [];
nickjillings@1315 2243 i = matcherOut.length;
nickjillings@1315 2244 while ( i-- ) {
nickjillings@1315 2245 if ( (elem = matcherOut[i]) ) {
nickjillings@1315 2246 // Restore matcherIn since elem is not yet a final match
nickjillings@1315 2247 temp.push( (matcherIn[i] = elem) );
nickjillings@1315 2248 }
nickjillings@1315 2249 }
nickjillings@1315 2250 postFinder( null, (matcherOut = []), temp, xml );
nickjillings@1315 2251 }
nickjillings@1315 2252
nickjillings@1315 2253 // Move matched elements from seed to results to keep them synchronized
nickjillings@1315 2254 i = matcherOut.length;
nickjillings@1315 2255 while ( i-- ) {
nickjillings@1315 2256 if ( (elem = matcherOut[i]) &&
nickjillings@1315 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nickjillings@1315 2258
nickjillings@1315 2259 seed[temp] = !(results[temp] = elem);
nickjillings@1315 2260 }
nickjillings@1315 2261 }
nickjillings@1315 2262 }
nickjillings@1315 2263
nickjillings@1315 2264 // Add elements to results, through postFinder if defined
nickjillings@1315 2265 } else {
nickjillings@1315 2266 matcherOut = condense(
nickjillings@1315 2267 matcherOut === results ?
nickjillings@1315 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nickjillings@1315 2269 matcherOut
nickjillings@1315 2270 );
nickjillings@1315 2271 if ( postFinder ) {
nickjillings@1315 2272 postFinder( null, results, matcherOut, xml );
nickjillings@1315 2273 } else {
nickjillings@1315 2274 push.apply( results, matcherOut );
nickjillings@1315 2275 }
nickjillings@1315 2276 }
nickjillings@1315 2277 });
nickjillings@1315 2278 }
nickjillings@1315 2279
nickjillings@1315 2280 function matcherFromTokens( tokens ) {
nickjillings@1315 2281 var checkContext, matcher, j,
nickjillings@1315 2282 len = tokens.length,
nickjillings@1315 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nickjillings@1315 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nickjillings@1315 2285 i = leadingRelative ? 1 : 0,
nickjillings@1315 2286
nickjillings@1315 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nickjillings@1315 2288 matchContext = addCombinator( function( elem ) {
nickjillings@1315 2289 return elem === checkContext;
nickjillings@1315 2290 }, implicitRelative, true ),
nickjillings@1315 2291 matchAnyContext = addCombinator( function( elem ) {
nickjillings@1315 2292 return indexOf( checkContext, elem ) > -1;
nickjillings@1315 2293 }, implicitRelative, true ),
nickjillings@1315 2294 matchers = [ function( elem, context, xml ) {
nickjillings@1315 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nickjillings@1315 2296 (checkContext = context).nodeType ?
nickjillings@1315 2297 matchContext( elem, context, xml ) :
nickjillings@1315 2298 matchAnyContext( elem, context, xml ) );
nickjillings@1315 2299 // Avoid hanging onto element (issue #299)
nickjillings@1315 2300 checkContext = null;
nickjillings@1315 2301 return ret;
nickjillings@1315 2302 } ];
nickjillings@1315 2303
nickjillings@1315 2304 for ( ; i < len; i++ ) {
nickjillings@1315 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nickjillings@1315 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nickjillings@1315 2307 } else {
nickjillings@1315 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nickjillings@1315 2309
nickjillings@1315 2310 // Return special upon seeing a positional matcher
nickjillings@1315 2311 if ( matcher[ expando ] ) {
nickjillings@1315 2312 // Find the next relative operator (if any) for proper handling
nickjillings@1315 2313 j = ++i;
nickjillings@1315 2314 for ( ; j < len; j++ ) {
nickjillings@1315 2315 if ( Expr.relative[ tokens[j].type ] ) {
nickjillings@1315 2316 break;
nickjillings@1315 2317 }
nickjillings@1315 2318 }
nickjillings@1315 2319 return setMatcher(
nickjillings@1315 2320 i > 1 && elementMatcher( matchers ),
nickjillings@1315 2321 i > 1 && toSelector(
nickjillings@1315 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nickjillings@1315 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nickjillings@1315 2324 ).replace( rtrim, "$1" ),
nickjillings@1315 2325 matcher,
nickjillings@1315 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nickjillings@1315 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nickjillings@1315 2328 j < len && toSelector( tokens )
nickjillings@1315 2329 );
nickjillings@1315 2330 }
nickjillings@1315 2331 matchers.push( matcher );
nickjillings@1315 2332 }
nickjillings@1315 2333 }
nickjillings@1315 2334
nickjillings@1315 2335 return elementMatcher( matchers );
nickjillings@1315 2336 }
nickjillings@1315 2337
nickjillings@1315 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nickjillings@1315 2339 var bySet = setMatchers.length > 0,
nickjillings@1315 2340 byElement = elementMatchers.length > 0,
nickjillings@1315 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nickjillings@1315 2342 var elem, j, matcher,
nickjillings@1315 2343 matchedCount = 0,
nickjillings@1315 2344 i = "0",
nickjillings@1315 2345 unmatched = seed && [],
nickjillings@1315 2346 setMatched = [],
nickjillings@1315 2347 contextBackup = outermostContext,
nickjillings@1315 2348 // We must always have either seed elements or outermost context
nickjillings@1315 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nickjillings@1315 2350 // Use integer dirruns iff this is the outermost matcher
nickjillings@1315 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nickjillings@1315 2352 len = elems.length;
nickjillings@1315 2353
nickjillings@1315 2354 if ( outermost ) {
nickjillings@1315 2355 outermostContext = context !== document && context;
nickjillings@1315 2356 }
nickjillings@1315 2357
nickjillings@1315 2358 // Add elements passing elementMatchers directly to results
nickjillings@1315 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nickjillings@1315 2360 // Support: IE<9, Safari
nickjillings@1315 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nickjillings@1315 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nickjillings@1315 2363 if ( byElement && elem ) {
nickjillings@1315 2364 j = 0;
nickjillings@1315 2365 while ( (matcher = elementMatchers[j++]) ) {
nickjillings@1315 2366 if ( matcher( elem, context, xml ) ) {
nickjillings@1315 2367 results.push( elem );
nickjillings@1315 2368 break;
nickjillings@1315 2369 }
nickjillings@1315 2370 }
nickjillings@1315 2371 if ( outermost ) {
nickjillings@1315 2372 dirruns = dirrunsUnique;
nickjillings@1315 2373 }
nickjillings@1315 2374 }
nickjillings@1315 2375
nickjillings@1315 2376 // Track unmatched elements for set filters
nickjillings@1315 2377 if ( bySet ) {
nickjillings@1315 2378 // They will have gone through all possible matchers
nickjillings@1315 2379 if ( (elem = !matcher && elem) ) {
nickjillings@1315 2380 matchedCount--;
nickjillings@1315 2381 }
nickjillings@1315 2382
nickjillings@1315 2383 // Lengthen the array for every element, matched or not
nickjillings@1315 2384 if ( seed ) {
nickjillings@1315 2385 unmatched.push( elem );
nickjillings@1315 2386 }
nickjillings@1315 2387 }
nickjillings@1315 2388 }
nickjillings@1315 2389
nickjillings@1315 2390 // Apply set filters to unmatched elements
nickjillings@1315 2391 matchedCount += i;
nickjillings@1315 2392 if ( bySet && i !== matchedCount ) {
nickjillings@1315 2393 j = 0;
nickjillings@1315 2394 while ( (matcher = setMatchers[j++]) ) {
nickjillings@1315 2395 matcher( unmatched, setMatched, context, xml );
nickjillings@1315 2396 }
nickjillings@1315 2397
nickjillings@1315 2398 if ( seed ) {
nickjillings@1315 2399 // Reintegrate element matches to eliminate the need for sorting
nickjillings@1315 2400 if ( matchedCount > 0 ) {
nickjillings@1315 2401 while ( i-- ) {
nickjillings@1315 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nickjillings@1315 2403 setMatched[i] = pop.call( results );
nickjillings@1315 2404 }
nickjillings@1315 2405 }
nickjillings@1315 2406 }
nickjillings@1315 2407
nickjillings@1315 2408 // Discard index placeholder values to get only actual matches
nickjillings@1315 2409 setMatched = condense( setMatched );
nickjillings@1315 2410 }
nickjillings@1315 2411
nickjillings@1315 2412 // Add matches to results
nickjillings@1315 2413 push.apply( results, setMatched );
nickjillings@1315 2414
nickjillings@1315 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nickjillings@1315 2416 if ( outermost && !seed && setMatched.length > 0 &&
nickjillings@1315 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nickjillings@1315 2418
nickjillings@1315 2419 Sizzle.uniqueSort( results );
nickjillings@1315 2420 }
nickjillings@1315 2421 }
nickjillings@1315 2422
nickjillings@1315 2423 // Override manipulation of globals by nested matchers
nickjillings@1315 2424 if ( outermost ) {
nickjillings@1315 2425 dirruns = dirrunsUnique;
nickjillings@1315 2426 outermostContext = contextBackup;
nickjillings@1315 2427 }
nickjillings@1315 2428
nickjillings@1315 2429 return unmatched;
nickjillings@1315 2430 };
nickjillings@1315 2431
nickjillings@1315 2432 return bySet ?
nickjillings@1315 2433 markFunction( superMatcher ) :
nickjillings@1315 2434 superMatcher;
nickjillings@1315 2435 }
nickjillings@1315 2436
nickjillings@1315 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nickjillings@1315 2438 var i,
nickjillings@1315 2439 setMatchers = [],
nickjillings@1315 2440 elementMatchers = [],
nickjillings@1315 2441 cached = compilerCache[ selector + " " ];
nickjillings@1315 2442
nickjillings@1315 2443 if ( !cached ) {
nickjillings@1315 2444 // Generate a function of recursive functions that can be used to check each element
nickjillings@1315 2445 if ( !match ) {
nickjillings@1315 2446 match = tokenize( selector );
nickjillings@1315 2447 }
nickjillings@1315 2448 i = match.length;
nickjillings@1315 2449 while ( i-- ) {
nickjillings@1315 2450 cached = matcherFromTokens( match[i] );
nickjillings@1315 2451 if ( cached[ expando ] ) {
nickjillings@1315 2452 setMatchers.push( cached );
nickjillings@1315 2453 } else {
nickjillings@1315 2454 elementMatchers.push( cached );
nickjillings@1315 2455 }
nickjillings@1315 2456 }
nickjillings@1315 2457
nickjillings@1315 2458 // Cache the compiled function
nickjillings@1315 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nickjillings@1315 2460
nickjillings@1315 2461 // Save selector and tokenization
nickjillings@1315 2462 cached.selector = selector;
nickjillings@1315 2463 }
nickjillings@1315 2464 return cached;
nickjillings@1315 2465 };
nickjillings@1315 2466
nickjillings@1315 2467 /**
nickjillings@1315 2468 * A low-level selection function that works with Sizzle's compiled
nickjillings@1315 2469 * selector functions
nickjillings@1315 2470 * @param {String|Function} selector A selector or a pre-compiled
nickjillings@1315 2471 * selector function built with Sizzle.compile
nickjillings@1315 2472 * @param {Element} context
nickjillings@1315 2473 * @param {Array} [results]
nickjillings@1315 2474 * @param {Array} [seed] A set of elements to match against
nickjillings@1315 2475 */
nickjillings@1315 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nickjillings@1315 2477 var i, tokens, token, type, find,
nickjillings@1315 2478 compiled = typeof selector === "function" && selector,
nickjillings@1315 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nickjillings@1315 2480
nickjillings@1315 2481 results = results || [];
nickjillings@1315 2482
nickjillings@1315 2483 // Try to minimize operations if there is no seed and only one group
nickjillings@1315 2484 if ( match.length === 1 ) {
nickjillings@1315 2485
nickjillings@1315 2486 // Take a shortcut and set the context if the root selector is an ID
nickjillings@1315 2487 tokens = match[0] = match[0].slice( 0 );
nickjillings@1315 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nickjillings@1315 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nickjillings@1315 2490 Expr.relative[ tokens[1].type ] ) {
nickjillings@1315 2491
nickjillings@1315 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nickjillings@1315 2493 if ( !context ) {
nickjillings@1315 2494 return results;
nickjillings@1315 2495
nickjillings@1315 2496 // Precompiled matchers will still verify ancestry, so step up a level
nickjillings@1315 2497 } else if ( compiled ) {
nickjillings@1315 2498 context = context.parentNode;
nickjillings@1315 2499 }
nickjillings@1315 2500
nickjillings@1315 2501 selector = selector.slice( tokens.shift().value.length );
nickjillings@1315 2502 }
nickjillings@1315 2503
nickjillings@1315 2504 // Fetch a seed set for right-to-left matching
nickjillings@1315 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nickjillings@1315 2506 while ( i-- ) {
nickjillings@1315 2507 token = tokens[i];
nickjillings@1315 2508
nickjillings@1315 2509 // Abort if we hit a combinator
nickjillings@1315 2510 if ( Expr.relative[ (type = token.type) ] ) {
nickjillings@1315 2511 break;
nickjillings@1315 2512 }
nickjillings@1315 2513 if ( (find = Expr.find[ type ]) ) {
nickjillings@1315 2514 // Search, expanding context for leading sibling combinators
nickjillings@1315 2515 if ( (seed = find(
nickjillings@1315 2516 token.matches[0].replace( runescape, funescape ),
nickjillings@1315 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nickjillings@1315 2518 )) ) {
nickjillings@1315 2519
nickjillings@1315 2520 // If seed is empty or no tokens remain, we can return early
nickjillings@1315 2521 tokens.splice( i, 1 );
nickjillings@1315 2522 selector = seed.length && toSelector( tokens );
nickjillings@1315 2523 if ( !selector ) {
nickjillings@1315 2524 push.apply( results, seed );
nickjillings@1315 2525 return results;
nickjillings@1315 2526 }
nickjillings@1315 2527
nickjillings@1315 2528 break;
nickjillings@1315 2529 }
nickjillings@1315 2530 }
nickjillings@1315 2531 }
nickjillings@1315 2532 }
nickjillings@1315 2533
nickjillings@1315 2534 // Compile and execute a filtering function if one is not provided
nickjillings@1315 2535 // Provide `match` to avoid retokenization if we modified the selector above
nickjillings@1315 2536 ( compiled || compile( selector, match ) )(
nickjillings@1315 2537 seed,
nickjillings@1315 2538 context,
nickjillings@1315 2539 !documentIsHTML,
nickjillings@1315 2540 results,
nickjillings@1315 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nickjillings@1315 2542 );
nickjillings@1315 2543 return results;
nickjillings@1315 2544 };
nickjillings@1315 2545
nickjillings@1315 2546 // One-time assignments
nickjillings@1315 2547
nickjillings@1315 2548 // Sort stability
nickjillings@1315 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nickjillings@1315 2550
nickjillings@1315 2551 // Support: Chrome 14-35+
nickjillings@1315 2552 // Always assume duplicates if they aren't passed to the comparison function
nickjillings@1315 2553 support.detectDuplicates = !!hasDuplicate;
nickjillings@1315 2554
nickjillings@1315 2555 // Initialize against the default document
nickjillings@1315 2556 setDocument();
nickjillings@1315 2557
nickjillings@1315 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nickjillings@1315 2559 // Detached nodes confoundingly follow *each other*
nickjillings@1315 2560 support.sortDetached = assert(function( div1 ) {
nickjillings@1315 2561 // Should return 1, but returns 4 (following)
nickjillings@1315 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nickjillings@1315 2563 });
nickjillings@1315 2564
nickjillings@1315 2565 // Support: IE<8
nickjillings@1315 2566 // Prevent attribute/property "interpolation"
nickjillings@1315 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nickjillings@1315 2568 if ( !assert(function( div ) {
nickjillings@1315 2569 div.innerHTML = "<a href='#'></a>";
nickjillings@1315 2570 return div.firstChild.getAttribute("href") === "#" ;
nickjillings@1315 2571 }) ) {
nickjillings@1315 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nickjillings@1315 2573 if ( !isXML ) {
nickjillings@1315 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nickjillings@1315 2575 }
nickjillings@1315 2576 });
nickjillings@1315 2577 }
nickjillings@1315 2578
nickjillings@1315 2579 // Support: IE<9
nickjillings@1315 2580 // Use defaultValue in place of getAttribute("value")
nickjillings@1315 2581 if ( !support.attributes || !assert(function( div ) {
nickjillings@1315 2582 div.innerHTML = "<input/>";
nickjillings@1315 2583 div.firstChild.setAttribute( "value", "" );
nickjillings@1315 2584 return div.firstChild.getAttribute( "value" ) === "";
nickjillings@1315 2585 }) ) {
nickjillings@1315 2586 addHandle( "value", function( elem, name, isXML ) {
nickjillings@1315 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nickjillings@1315 2588 return elem.defaultValue;
nickjillings@1315 2589 }
nickjillings@1315 2590 });
nickjillings@1315 2591 }
nickjillings@1315 2592
nickjillings@1315 2593 // Support: IE<9
nickjillings@1315 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nickjillings@1315 2595 if ( !assert(function( div ) {
nickjillings@1315 2596 return div.getAttribute("disabled") == null;
nickjillings@1315 2597 }) ) {
nickjillings@1315 2598 addHandle( booleans, function( elem, name, isXML ) {
nickjillings@1315 2599 var val;
nickjillings@1315 2600 if ( !isXML ) {
nickjillings@1315 2601 return elem[ name ] === true ? name.toLowerCase() :
nickjillings@1315 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nickjillings@1315 2603 val.value :
nickjillings@1315 2604 null;
nickjillings@1315 2605 }
nickjillings@1315 2606 });
nickjillings@1315 2607 }
nickjillings@1315 2608
nickjillings@1315 2609 return Sizzle;
nickjillings@1315 2610
nickjillings@1315 2611 })( window );
nickjillings@1315 2612
nickjillings@1315 2613
nickjillings@1315 2614
nickjillings@1315 2615 jQuery.find = Sizzle;
nickjillings@1315 2616 jQuery.expr = Sizzle.selectors;
nickjillings@1315 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nickjillings@1315 2618 jQuery.unique = Sizzle.uniqueSort;
nickjillings@1315 2619 jQuery.text = Sizzle.getText;
nickjillings@1315 2620 jQuery.isXMLDoc = Sizzle.isXML;
nickjillings@1315 2621 jQuery.contains = Sizzle.contains;
nickjillings@1315 2622
nickjillings@1315 2623
nickjillings@1315 2624
nickjillings@1315 2625 var rneedsContext = jQuery.expr.match.needsContext;
nickjillings@1315 2626
nickjillings@1315 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nickjillings@1315 2628
nickjillings@1315 2629
nickjillings@1315 2630
nickjillings@1315 2631 var risSimple = /^.[^:#\[\.,]*$/;
nickjillings@1315 2632
nickjillings@1315 2633 // Implement the identical functionality for filter and not
nickjillings@1315 2634 function winnow( elements, qualifier, not ) {
nickjillings@1315 2635 if ( jQuery.isFunction( qualifier ) ) {
nickjillings@1315 2636 return jQuery.grep( elements, function( elem, i ) {
nickjillings@1315 2637 /* jshint -W018 */
nickjillings@1315 2638 return !!qualifier.call( elem, i, elem ) !== not;
nickjillings@1315 2639 });
nickjillings@1315 2640
nickjillings@1315 2641 }
nickjillings@1315 2642
nickjillings@1315 2643 if ( qualifier.nodeType ) {
nickjillings@1315 2644 return jQuery.grep( elements, function( elem ) {
nickjillings@1315 2645 return ( elem === qualifier ) !== not;
nickjillings@1315 2646 });
nickjillings@1315 2647
nickjillings@1315 2648 }
nickjillings@1315 2649
nickjillings@1315 2650 if ( typeof qualifier === "string" ) {
nickjillings@1315 2651 if ( risSimple.test( qualifier ) ) {
nickjillings@1315 2652 return jQuery.filter( qualifier, elements, not );
nickjillings@1315 2653 }
nickjillings@1315 2654
nickjillings@1315 2655 qualifier = jQuery.filter( qualifier, elements );
nickjillings@1315 2656 }
nickjillings@1315 2657
nickjillings@1315 2658 return jQuery.grep( elements, function( elem ) {
nickjillings@1315 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nickjillings@1315 2660 });
nickjillings@1315 2661 }
nickjillings@1315 2662
nickjillings@1315 2663 jQuery.filter = function( expr, elems, not ) {
nickjillings@1315 2664 var elem = elems[ 0 ];
nickjillings@1315 2665
nickjillings@1315 2666 if ( not ) {
nickjillings@1315 2667 expr = ":not(" + expr + ")";
nickjillings@1315 2668 }
nickjillings@1315 2669
nickjillings@1315 2670 return elems.length === 1 && elem.nodeType === 1 ?
nickjillings@1315 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nickjillings@1315 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nickjillings@1315 2673 return elem.nodeType === 1;
nickjillings@1315 2674 }));
nickjillings@1315 2675 };
nickjillings@1315 2676
nickjillings@1315 2677 jQuery.fn.extend({
nickjillings@1315 2678 find: function( selector ) {
nickjillings@1315 2679 var i,
nickjillings@1315 2680 len = this.length,
nickjillings@1315 2681 ret = [],
nickjillings@1315 2682 self = this;
nickjillings@1315 2683
nickjillings@1315 2684 if ( typeof selector !== "string" ) {
nickjillings@1315 2685 return this.pushStack( jQuery( selector ).filter(function() {
nickjillings@1315 2686 for ( i = 0; i < len; i++ ) {
nickjillings@1315 2687 if ( jQuery.contains( self[ i ], this ) ) {
nickjillings@1315 2688 return true;
nickjillings@1315 2689 }
nickjillings@1315 2690 }
nickjillings@1315 2691 }) );
nickjillings@1315 2692 }
nickjillings@1315 2693
nickjillings@1315 2694 for ( i = 0; i < len; i++ ) {
nickjillings@1315 2695 jQuery.find( selector, self[ i ], ret );
nickjillings@1315 2696 }
nickjillings@1315 2697
nickjillings@1315 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nickjillings@1315 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nickjillings@1315 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nickjillings@1315 2701 return ret;
nickjillings@1315 2702 },
nickjillings@1315 2703 filter: function( selector ) {
nickjillings@1315 2704 return this.pushStack( winnow(this, selector || [], false) );
nickjillings@1315 2705 },
nickjillings@1315 2706 not: function( selector ) {
nickjillings@1315 2707 return this.pushStack( winnow(this, selector || [], true) );
nickjillings@1315 2708 },
nickjillings@1315 2709 is: function( selector ) {
nickjillings@1315 2710 return !!winnow(
nickjillings@1315 2711 this,
nickjillings@1315 2712
nickjillings@1315 2713 // If this is a positional/relative selector, check membership in the returned set
nickjillings@1315 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nickjillings@1315 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nickjillings@1315 2716 jQuery( selector ) :
nickjillings@1315 2717 selector || [],
nickjillings@1315 2718 false
nickjillings@1315 2719 ).length;
nickjillings@1315 2720 }
nickjillings@1315 2721 });
nickjillings@1315 2722
nickjillings@1315 2723
nickjillings@1315 2724 // Initialize a jQuery object
nickjillings@1315 2725
nickjillings@1315 2726
nickjillings@1315 2727 // A central reference to the root jQuery(document)
nickjillings@1315 2728 var rootjQuery,
nickjillings@1315 2729
nickjillings@1315 2730 // A simple way to check for HTML strings
nickjillings@1315 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nickjillings@1315 2732 // Strict HTML recognition (#11290: must start with <)
nickjillings@1315 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nickjillings@1315 2734
nickjillings@1315 2735 init = jQuery.fn.init = function( selector, context ) {
nickjillings@1315 2736 var match, elem;
nickjillings@1315 2737
nickjillings@1315 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nickjillings@1315 2739 if ( !selector ) {
nickjillings@1315 2740 return this;
nickjillings@1315 2741 }
nickjillings@1315 2742
nickjillings@1315 2743 // Handle HTML strings
nickjillings@1315 2744 if ( typeof selector === "string" ) {
nickjillings@1315 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nickjillings@1315 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nickjillings@1315 2747 match = [ null, selector, null ];
nickjillings@1315 2748
nickjillings@1315 2749 } else {
nickjillings@1315 2750 match = rquickExpr.exec( selector );
nickjillings@1315 2751 }
nickjillings@1315 2752
nickjillings@1315 2753 // Match html or make sure no context is specified for #id
nickjillings@1315 2754 if ( match && (match[1] || !context) ) {
nickjillings@1315 2755
nickjillings@1315 2756 // HANDLE: $(html) -> $(array)
nickjillings@1315 2757 if ( match[1] ) {
nickjillings@1315 2758 context = context instanceof jQuery ? context[0] : context;
nickjillings@1315 2759
nickjillings@1315 2760 // Option to run scripts is true for back-compat
nickjillings@1315 2761 // Intentionally let the error be thrown if parseHTML is not present
nickjillings@1315 2762 jQuery.merge( this, jQuery.parseHTML(
nickjillings@1315 2763 match[1],
nickjillings@1315 2764 context && context.nodeType ? context.ownerDocument || context : document,
nickjillings@1315 2765 true
nickjillings@1315 2766 ) );
nickjillings@1315 2767
nickjillings@1315 2768 // HANDLE: $(html, props)
nickjillings@1315 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nickjillings@1315 2770 for ( match in context ) {
nickjillings@1315 2771 // Properties of context are called as methods if possible
nickjillings@1315 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nickjillings@1315 2773 this[ match ]( context[ match ] );
nickjillings@1315 2774
nickjillings@1315 2775 // ...and otherwise set as attributes
nickjillings@1315 2776 } else {
nickjillings@1315 2777 this.attr( match, context[ match ] );
nickjillings@1315 2778 }
nickjillings@1315 2779 }
nickjillings@1315 2780 }
nickjillings@1315 2781
nickjillings@1315 2782 return this;
nickjillings@1315 2783
nickjillings@1315 2784 // HANDLE: $(#id)
nickjillings@1315 2785 } else {
nickjillings@1315 2786 elem = document.getElementById( match[2] );
nickjillings@1315 2787
nickjillings@1315 2788 // Support: Blackberry 4.6
nickjillings@1315 2789 // gEBID returns nodes no longer in the document (#6963)
nickjillings@1315 2790 if ( elem && elem.parentNode ) {
nickjillings@1315 2791 // Inject the element directly into the jQuery object
nickjillings@1315 2792 this.length = 1;
nickjillings@1315 2793 this[0] = elem;
nickjillings@1315 2794 }
nickjillings@1315 2795
nickjillings@1315 2796 this.context = document;
nickjillings@1315 2797 this.selector = selector;
nickjillings@1315 2798 return this;
nickjillings@1315 2799 }
nickjillings@1315 2800
nickjillings@1315 2801 // HANDLE: $(expr, $(...))
nickjillings@1315 2802 } else if ( !context || context.jquery ) {
nickjillings@1315 2803 return ( context || rootjQuery ).find( selector );
nickjillings@1315 2804
nickjillings@1315 2805 // HANDLE: $(expr, context)
nickjillings@1315 2806 // (which is just equivalent to: $(context).find(expr)
nickjillings@1315 2807 } else {
nickjillings@1315 2808 return this.constructor( context ).find( selector );
nickjillings@1315 2809 }
nickjillings@1315 2810
nickjillings@1315 2811 // HANDLE: $(DOMElement)
nickjillings@1315 2812 } else if ( selector.nodeType ) {
nickjillings@1315 2813 this.context = this[0] = selector;
nickjillings@1315 2814 this.length = 1;
nickjillings@1315 2815 return this;
nickjillings@1315 2816
nickjillings@1315 2817 // HANDLE: $(function)
nickjillings@1315 2818 // Shortcut for document ready
nickjillings@1315 2819 } else if ( jQuery.isFunction( selector ) ) {
nickjillings@1315 2820 return typeof rootjQuery.ready !== "undefined" ?
nickjillings@1315 2821 rootjQuery.ready( selector ) :
nickjillings@1315 2822 // Execute immediately if ready is not present
nickjillings@1315 2823 selector( jQuery );
nickjillings@1315 2824 }
nickjillings@1315 2825
nickjillings@1315 2826 if ( selector.selector !== undefined ) {
nickjillings@1315 2827 this.selector = selector.selector;
nickjillings@1315 2828 this.context = selector.context;
nickjillings@1315 2829 }
nickjillings@1315 2830
nickjillings@1315 2831 return jQuery.makeArray( selector, this );
nickjillings@1315 2832 };
nickjillings@1315 2833
nickjillings@1315 2834 // Give the init function the jQuery prototype for later instantiation
nickjillings@1315 2835 init.prototype = jQuery.fn;
nickjillings@1315 2836
nickjillings@1315 2837 // Initialize central reference
nickjillings@1315 2838 rootjQuery = jQuery( document );
nickjillings@1315 2839
nickjillings@1315 2840
nickjillings@1315 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nickjillings@1315 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nickjillings@1315 2843 guaranteedUnique = {
nickjillings@1315 2844 children: true,
nickjillings@1315 2845 contents: true,
nickjillings@1315 2846 next: true,
nickjillings@1315 2847 prev: true
nickjillings@1315 2848 };
nickjillings@1315 2849
nickjillings@1315 2850 jQuery.extend({
nickjillings@1315 2851 dir: function( elem, dir, until ) {
nickjillings@1315 2852 var matched = [],
nickjillings@1315 2853 truncate = until !== undefined;
nickjillings@1315 2854
nickjillings@1315 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nickjillings@1315 2856 if ( elem.nodeType === 1 ) {
nickjillings@1315 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nickjillings@1315 2858 break;
nickjillings@1315 2859 }
nickjillings@1315 2860 matched.push( elem );
nickjillings@1315 2861 }
nickjillings@1315 2862 }
nickjillings@1315 2863 return matched;
nickjillings@1315 2864 },
nickjillings@1315 2865
nickjillings@1315 2866 sibling: function( n, elem ) {
nickjillings@1315 2867 var matched = [];
nickjillings@1315 2868
nickjillings@1315 2869 for ( ; n; n = n.nextSibling ) {
nickjillings@1315 2870 if ( n.nodeType === 1 && n !== elem ) {
nickjillings@1315 2871 matched.push( n );
nickjillings@1315 2872 }
nickjillings@1315 2873 }
nickjillings@1315 2874
nickjillings@1315 2875 return matched;
nickjillings@1315 2876 }
nickjillings@1315 2877 });
nickjillings@1315 2878
nickjillings@1315 2879 jQuery.fn.extend({
nickjillings@1315 2880 has: function( target ) {
nickjillings@1315 2881 var targets = jQuery( target, this ),
nickjillings@1315 2882 l = targets.length;
nickjillings@1315 2883
nickjillings@1315 2884 return this.filter(function() {
nickjillings@1315 2885 var i = 0;
nickjillings@1315 2886 for ( ; i < l; i++ ) {
nickjillings@1315 2887 if ( jQuery.contains( this, targets[i] ) ) {
nickjillings@1315 2888 return true;
nickjillings@1315 2889 }
nickjillings@1315 2890 }
nickjillings@1315 2891 });
nickjillings@1315 2892 },
nickjillings@1315 2893
nickjillings@1315 2894 closest: function( selectors, context ) {
nickjillings@1315 2895 var cur,
nickjillings@1315 2896 i = 0,
nickjillings@1315 2897 l = this.length,
nickjillings@1315 2898 matched = [],
nickjillings@1315 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nickjillings@1315 2900 jQuery( selectors, context || this.context ) :
nickjillings@1315 2901 0;
nickjillings@1315 2902
nickjillings@1315 2903 for ( ; i < l; i++ ) {
nickjillings@1315 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nickjillings@1315 2905 // Always skip document fragments
nickjillings@1315 2906 if ( cur.nodeType < 11 && (pos ?
nickjillings@1315 2907 pos.index(cur) > -1 :
nickjillings@1315 2908
nickjillings@1315 2909 // Don't pass non-elements to Sizzle
nickjillings@1315 2910 cur.nodeType === 1 &&
nickjillings@1315 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nickjillings@1315 2912
nickjillings@1315 2913 matched.push( cur );
nickjillings@1315 2914 break;
nickjillings@1315 2915 }
nickjillings@1315 2916 }
nickjillings@1315 2917 }
nickjillings@1315 2918
nickjillings@1315 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nickjillings@1315 2920 },
nickjillings@1315 2921
nickjillings@1315 2922 // Determine the position of an element within the set
nickjillings@1315 2923 index: function( elem ) {
nickjillings@1315 2924
nickjillings@1315 2925 // No argument, return index in parent
nickjillings@1315 2926 if ( !elem ) {
nickjillings@1315 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nickjillings@1315 2928 }
nickjillings@1315 2929
nickjillings@1315 2930 // Index in selector
nickjillings@1315 2931 if ( typeof elem === "string" ) {
nickjillings@1315 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nickjillings@1315 2933 }
nickjillings@1315 2934
nickjillings@1315 2935 // Locate the position of the desired element
nickjillings@1315 2936 return indexOf.call( this,
nickjillings@1315 2937
nickjillings@1315 2938 // If it receives a jQuery object, the first element is used
nickjillings@1315 2939 elem.jquery ? elem[ 0 ] : elem
nickjillings@1315 2940 );
nickjillings@1315 2941 },
nickjillings@1315 2942
nickjillings@1315 2943 add: function( selector, context ) {
nickjillings@1315 2944 return this.pushStack(
nickjillings@1315 2945 jQuery.unique(
nickjillings@1315 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nickjillings@1315 2947 )
nickjillings@1315 2948 );
nickjillings@1315 2949 },
nickjillings@1315 2950
nickjillings@1315 2951 addBack: function( selector ) {
nickjillings@1315 2952 return this.add( selector == null ?
nickjillings@1315 2953 this.prevObject : this.prevObject.filter(selector)
nickjillings@1315 2954 );
nickjillings@1315 2955 }
nickjillings@1315 2956 });
nickjillings@1315 2957
nickjillings@1315 2958 function sibling( cur, dir ) {
nickjillings@1315 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nickjillings@1315 2960 return cur;
nickjillings@1315 2961 }
nickjillings@1315 2962
nickjillings@1315 2963 jQuery.each({
nickjillings@1315 2964 parent: function( elem ) {
nickjillings@1315 2965 var parent = elem.parentNode;
nickjillings@1315 2966 return parent && parent.nodeType !== 11 ? parent : null;
nickjillings@1315 2967 },
nickjillings@1315 2968 parents: function( elem ) {
nickjillings@1315 2969 return jQuery.dir( elem, "parentNode" );
nickjillings@1315 2970 },
nickjillings@1315 2971 parentsUntil: function( elem, i, until ) {
nickjillings@1315 2972 return jQuery.dir( elem, "parentNode", until );
nickjillings@1315 2973 },
nickjillings@1315 2974 next: function( elem ) {
nickjillings@1315 2975 return sibling( elem, "nextSibling" );
nickjillings@1315 2976 },
nickjillings@1315 2977 prev: function( elem ) {
nickjillings@1315 2978 return sibling( elem, "previousSibling" );
nickjillings@1315 2979 },
nickjillings@1315 2980 nextAll: function( elem ) {
nickjillings@1315 2981 return jQuery.dir( elem, "nextSibling" );
nickjillings@1315 2982 },
nickjillings@1315 2983 prevAll: function( elem ) {
nickjillings@1315 2984 return jQuery.dir( elem, "previousSibling" );
nickjillings@1315 2985 },
nickjillings@1315 2986 nextUntil: function( elem, i, until ) {
nickjillings@1315 2987 return jQuery.dir( elem, "nextSibling", until );
nickjillings@1315 2988 },
nickjillings@1315 2989 prevUntil: function( elem, i, until ) {
nickjillings@1315 2990 return jQuery.dir( elem, "previousSibling", until );
nickjillings@1315 2991 },
nickjillings@1315 2992 siblings: function( elem ) {
nickjillings@1315 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nickjillings@1315 2994 },
nickjillings@1315 2995 children: function( elem ) {
nickjillings@1315 2996 return jQuery.sibling( elem.firstChild );
nickjillings@1315 2997 },
nickjillings@1315 2998 contents: function( elem ) {
nickjillings@1315 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nickjillings@1315 3000 }
nickjillings@1315 3001 }, function( name, fn ) {
nickjillings@1315 3002 jQuery.fn[ name ] = function( until, selector ) {
nickjillings@1315 3003 var matched = jQuery.map( this, fn, until );
nickjillings@1315 3004
nickjillings@1315 3005 if ( name.slice( -5 ) !== "Until" ) {
nickjillings@1315 3006 selector = until;
nickjillings@1315 3007 }
nickjillings@1315 3008
nickjillings@1315 3009 if ( selector && typeof selector === "string" ) {
nickjillings@1315 3010 matched = jQuery.filter( selector, matched );
nickjillings@1315 3011 }
nickjillings@1315 3012
nickjillings@1315 3013 if ( this.length > 1 ) {
nickjillings@1315 3014 // Remove duplicates
nickjillings@1315 3015 if ( !guaranteedUnique[ name ] ) {
nickjillings@1315 3016 jQuery.unique( matched );
nickjillings@1315 3017 }
nickjillings@1315 3018
nickjillings@1315 3019 // Reverse order for parents* and prev-derivatives
nickjillings@1315 3020 if ( rparentsprev.test( name ) ) {
nickjillings@1315 3021 matched.reverse();
nickjillings@1315 3022 }
nickjillings@1315 3023 }
nickjillings@1315 3024
nickjillings@1315 3025 return this.pushStack( matched );
nickjillings@1315 3026 };
nickjillings@1315 3027 });
nickjillings@1315 3028 var rnotwhite = (/\S+/g);
nickjillings@1315 3029
nickjillings@1315 3030
nickjillings@1315 3031
nickjillings@1315 3032 // String to Object options format cache
nickjillings@1315 3033 var optionsCache = {};
nickjillings@1315 3034
nickjillings@1315 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nickjillings@1315 3036 function createOptions( options ) {
nickjillings@1315 3037 var object = optionsCache[ options ] = {};
nickjillings@1315 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nickjillings@1315 3039 object[ flag ] = true;
nickjillings@1315 3040 });
nickjillings@1315 3041 return object;
nickjillings@1315 3042 }
nickjillings@1315 3043
nickjillings@1315 3044 /*
nickjillings@1315 3045 * Create a callback list using the following parameters:
nickjillings@1315 3046 *
nickjillings@1315 3047 * options: an optional list of space-separated options that will change how
nickjillings@1315 3048 * the callback list behaves or a more traditional option object
nickjillings@1315 3049 *
nickjillings@1315 3050 * By default a callback list will act like an event callback list and can be
nickjillings@1315 3051 * "fired" multiple times.
nickjillings@1315 3052 *
nickjillings@1315 3053 * Possible options:
nickjillings@1315 3054 *
nickjillings@1315 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nickjillings@1315 3056 *
nickjillings@1315 3057 * memory: will keep track of previous values and will call any callback added
nickjillings@1315 3058 * after the list has been fired right away with the latest "memorized"
nickjillings@1315 3059 * values (like a Deferred)
nickjillings@1315 3060 *
nickjillings@1315 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nickjillings@1315 3062 *
nickjillings@1315 3063 * stopOnFalse: interrupt callings when a callback returns false
nickjillings@1315 3064 *
nickjillings@1315 3065 */
nickjillings@1315 3066 jQuery.Callbacks = function( options ) {
nickjillings@1315 3067
nickjillings@1315 3068 // Convert options from String-formatted to Object-formatted if needed
nickjillings@1315 3069 // (we check in cache first)
nickjillings@1315 3070 options = typeof options === "string" ?
nickjillings@1315 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nickjillings@1315 3072 jQuery.extend( {}, options );
nickjillings@1315 3073
nickjillings@1315 3074 var // Last fire value (for non-forgettable lists)
nickjillings@1315 3075 memory,
nickjillings@1315 3076 // Flag to know if list was already fired
nickjillings@1315 3077 fired,
nickjillings@1315 3078 // Flag to know if list is currently firing
nickjillings@1315 3079 firing,
nickjillings@1315 3080 // First callback to fire (used internally by add and fireWith)
nickjillings@1315 3081 firingStart,
nickjillings@1315 3082 // End of the loop when firing
nickjillings@1315 3083 firingLength,
nickjillings@1315 3084 // Index of currently firing callback (modified by remove if needed)
nickjillings@1315 3085 firingIndex,
nickjillings@1315 3086 // Actual callback list
nickjillings@1315 3087 list = [],
nickjillings@1315 3088 // Stack of fire calls for repeatable lists
nickjillings@1315 3089 stack = !options.once && [],
nickjillings@1315 3090 // Fire callbacks
nickjillings@1315 3091 fire = function( data ) {
nickjillings@1315 3092 memory = options.memory && data;
nickjillings@1315 3093 fired = true;
nickjillings@1315 3094 firingIndex = firingStart || 0;
nickjillings@1315 3095 firingStart = 0;
nickjillings@1315 3096 firingLength = list.length;
nickjillings@1315 3097 firing = true;
nickjillings@1315 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nickjillings@1315 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nickjillings@1315 3100 memory = false; // To prevent further calls using add
nickjillings@1315 3101 break;
nickjillings@1315 3102 }
nickjillings@1315 3103 }
nickjillings@1315 3104 firing = false;
nickjillings@1315 3105 if ( list ) {
nickjillings@1315 3106 if ( stack ) {
nickjillings@1315 3107 if ( stack.length ) {
nickjillings@1315 3108 fire( stack.shift() );
nickjillings@1315 3109 }
nickjillings@1315 3110 } else if ( memory ) {
nickjillings@1315 3111 list = [];
nickjillings@1315 3112 } else {
nickjillings@1315 3113 self.disable();
nickjillings@1315 3114 }
nickjillings@1315 3115 }
nickjillings@1315 3116 },
nickjillings@1315 3117 // Actual Callbacks object
nickjillings@1315 3118 self = {
nickjillings@1315 3119 // Add a callback or a collection of callbacks to the list
nickjillings@1315 3120 add: function() {
nickjillings@1315 3121 if ( list ) {
nickjillings@1315 3122 // First, we save the current length
nickjillings@1315 3123 var start = list.length;
nickjillings@1315 3124 (function add( args ) {
nickjillings@1315 3125 jQuery.each( args, function( _, arg ) {
nickjillings@1315 3126 var type = jQuery.type( arg );
nickjillings@1315 3127 if ( type === "function" ) {
nickjillings@1315 3128 if ( !options.unique || !self.has( arg ) ) {
nickjillings@1315 3129 list.push( arg );
nickjillings@1315 3130 }
nickjillings@1315 3131 } else if ( arg && arg.length && type !== "string" ) {
nickjillings@1315 3132 // Inspect recursively
nickjillings@1315 3133 add( arg );
nickjillings@1315 3134 }
nickjillings@1315 3135 });
nickjillings@1315 3136 })( arguments );
nickjillings@1315 3137 // Do we need to add the callbacks to the
nickjillings@1315 3138 // current firing batch?
nickjillings@1315 3139 if ( firing ) {
nickjillings@1315 3140 firingLength = list.length;
nickjillings@1315 3141 // With memory, if we're not firing then
nickjillings@1315 3142 // we should call right away
nickjillings@1315 3143 } else if ( memory ) {
nickjillings@1315 3144 firingStart = start;
nickjillings@1315 3145 fire( memory );
nickjillings@1315 3146 }
nickjillings@1315 3147 }
nickjillings@1315 3148 return this;
nickjillings@1315 3149 },
nickjillings@1315 3150 // Remove a callback from the list
nickjillings@1315 3151 remove: function() {
nickjillings@1315 3152 if ( list ) {
nickjillings@1315 3153 jQuery.each( arguments, function( _, arg ) {
nickjillings@1315 3154 var index;
nickjillings@1315 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nickjillings@1315 3156 list.splice( index, 1 );
nickjillings@1315 3157 // Handle firing indexes
nickjillings@1315 3158 if ( firing ) {
nickjillings@1315 3159 if ( index <= firingLength ) {
nickjillings@1315 3160 firingLength--;
nickjillings@1315 3161 }
nickjillings@1315 3162 if ( index <= firingIndex ) {
nickjillings@1315 3163 firingIndex--;
nickjillings@1315 3164 }
nickjillings@1315 3165 }
nickjillings@1315 3166 }
nickjillings@1315 3167 });
nickjillings@1315 3168 }
nickjillings@1315 3169 return this;
nickjillings@1315 3170 },
nickjillings@1315 3171 // Check if a given callback is in the list.
nickjillings@1315 3172 // If no argument is given, return whether or not list has callbacks attached.
nickjillings@1315 3173 has: function( fn ) {
nickjillings@1315 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nickjillings@1315 3175 },
nickjillings@1315 3176 // Remove all callbacks from the list
nickjillings@1315 3177 empty: function() {
nickjillings@1315 3178 list = [];
nickjillings@1315 3179 firingLength = 0;
nickjillings@1315 3180 return this;
nickjillings@1315 3181 },
nickjillings@1315 3182 // Have the list do nothing anymore
nickjillings@1315 3183 disable: function() {
nickjillings@1315 3184 list = stack = memory = undefined;
nickjillings@1315 3185 return this;
nickjillings@1315 3186 },
nickjillings@1315 3187 // Is it disabled?
nickjillings@1315 3188 disabled: function() {
nickjillings@1315 3189 return !list;
nickjillings@1315 3190 },
nickjillings@1315 3191 // Lock the list in its current state
nickjillings@1315 3192 lock: function() {
nickjillings@1315 3193 stack = undefined;
nickjillings@1315 3194 if ( !memory ) {
nickjillings@1315 3195 self.disable();
nickjillings@1315 3196 }
nickjillings@1315 3197 return this;
nickjillings@1315 3198 },
nickjillings@1315 3199 // Is it locked?
nickjillings@1315 3200 locked: function() {
nickjillings@1315 3201 return !stack;
nickjillings@1315 3202 },
nickjillings@1315 3203 // Call all callbacks with the given context and arguments
nickjillings@1315 3204 fireWith: function( context, args ) {
nickjillings@1315 3205 if ( list && ( !fired || stack ) ) {
nickjillings@1315 3206 args = args || [];
nickjillings@1315 3207 args = [ context, args.slice ? args.slice() : args ];
nickjillings@1315 3208 if ( firing ) {
nickjillings@1315 3209 stack.push( args );
nickjillings@1315 3210 } else {
nickjillings@1315 3211 fire( args );
nickjillings@1315 3212 }
nickjillings@1315 3213 }
nickjillings@1315 3214 return this;
nickjillings@1315 3215 },
nickjillings@1315 3216 // Call all the callbacks with the given arguments
nickjillings@1315 3217 fire: function() {
nickjillings@1315 3218 self.fireWith( this, arguments );
nickjillings@1315 3219 return this;
nickjillings@1315 3220 },
nickjillings@1315 3221 // To know if the callbacks have already been called at least once
nickjillings@1315 3222 fired: function() {
nickjillings@1315 3223 return !!fired;
nickjillings@1315 3224 }
nickjillings@1315 3225 };
nickjillings@1315 3226
nickjillings@1315 3227 return self;
nickjillings@1315 3228 };
nickjillings@1315 3229
nickjillings@1315 3230
nickjillings@1315 3231 jQuery.extend({
nickjillings@1315 3232
nickjillings@1315 3233 Deferred: function( func ) {
nickjillings@1315 3234 var tuples = [
nickjillings@1315 3235 // action, add listener, listener list, final state
nickjillings@1315 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nickjillings@1315 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nickjillings@1315 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nickjillings@1315 3239 ],
nickjillings@1315 3240 state = "pending",
nickjillings@1315 3241 promise = {
nickjillings@1315 3242 state: function() {
nickjillings@1315 3243 return state;
nickjillings@1315 3244 },
nickjillings@1315 3245 always: function() {
nickjillings@1315 3246 deferred.done( arguments ).fail( arguments );
nickjillings@1315 3247 return this;
nickjillings@1315 3248 },
nickjillings@1315 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nickjillings@1315 3250 var fns = arguments;
nickjillings@1315 3251 return jQuery.Deferred(function( newDefer ) {
nickjillings@1315 3252 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1315 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nickjillings@1315 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nickjillings@1315 3255 deferred[ tuple[1] ](function() {
nickjillings@1315 3256 var returned = fn && fn.apply( this, arguments );
nickjillings@1315 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nickjillings@1315 3258 returned.promise()
nickjillings@1315 3259 .done( newDefer.resolve )
nickjillings@1315 3260 .fail( newDefer.reject )
nickjillings@1315 3261 .progress( newDefer.notify );
nickjillings@1315 3262 } else {
nickjillings@1315 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nickjillings@1315 3264 }
nickjillings@1315 3265 });
nickjillings@1315 3266 });
nickjillings@1315 3267 fns = null;
nickjillings@1315 3268 }).promise();
nickjillings@1315 3269 },
nickjillings@1315 3270 // Get a promise for this deferred
nickjillings@1315 3271 // If obj is provided, the promise aspect is added to the object
nickjillings@1315 3272 promise: function( obj ) {
nickjillings@1315 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nickjillings@1315 3274 }
nickjillings@1315 3275 },
nickjillings@1315 3276 deferred = {};
nickjillings@1315 3277
nickjillings@1315 3278 // Keep pipe for back-compat
nickjillings@1315 3279 promise.pipe = promise.then;
nickjillings@1315 3280
nickjillings@1315 3281 // Add list-specific methods
nickjillings@1315 3282 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1315 3283 var list = tuple[ 2 ],
nickjillings@1315 3284 stateString = tuple[ 3 ];
nickjillings@1315 3285
nickjillings@1315 3286 // promise[ done | fail | progress ] = list.add
nickjillings@1315 3287 promise[ tuple[1] ] = list.add;
nickjillings@1315 3288
nickjillings@1315 3289 // Handle state
nickjillings@1315 3290 if ( stateString ) {
nickjillings@1315 3291 list.add(function() {
nickjillings@1315 3292 // state = [ resolved | rejected ]
nickjillings@1315 3293 state = stateString;
nickjillings@1315 3294
nickjillings@1315 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nickjillings@1315 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nickjillings@1315 3297 }
nickjillings@1315 3298
nickjillings@1315 3299 // deferred[ resolve | reject | notify ]
nickjillings@1315 3300 deferred[ tuple[0] ] = function() {
nickjillings@1315 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nickjillings@1315 3302 return this;
nickjillings@1315 3303 };
nickjillings@1315 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nickjillings@1315 3305 });
nickjillings@1315 3306
nickjillings@1315 3307 // Make the deferred a promise
nickjillings@1315 3308 promise.promise( deferred );
nickjillings@1315 3309
nickjillings@1315 3310 // Call given func if any
nickjillings@1315 3311 if ( func ) {
nickjillings@1315 3312 func.call( deferred, deferred );
nickjillings@1315 3313 }
nickjillings@1315 3314
nickjillings@1315 3315 // All done!
nickjillings@1315 3316 return deferred;
nickjillings@1315 3317 },
nickjillings@1315 3318
nickjillings@1315 3319 // Deferred helper
nickjillings@1315 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nickjillings@1315 3321 var i = 0,
nickjillings@1315 3322 resolveValues = slice.call( arguments ),
nickjillings@1315 3323 length = resolveValues.length,
nickjillings@1315 3324
nickjillings@1315 3325 // the count of uncompleted subordinates
nickjillings@1315 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nickjillings@1315 3327
nickjillings@1315 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nickjillings@1315 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nickjillings@1315 3330
nickjillings@1315 3331 // Update function for both resolve and progress values
nickjillings@1315 3332 updateFunc = function( i, contexts, values ) {
nickjillings@1315 3333 return function( value ) {
nickjillings@1315 3334 contexts[ i ] = this;
nickjillings@1315 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nickjillings@1315 3336 if ( values === progressValues ) {
nickjillings@1315 3337 deferred.notifyWith( contexts, values );
nickjillings@1315 3338 } else if ( !( --remaining ) ) {
nickjillings@1315 3339 deferred.resolveWith( contexts, values );
nickjillings@1315 3340 }
nickjillings@1315 3341 };
nickjillings@1315 3342 },
nickjillings@1315 3343
nickjillings@1315 3344 progressValues, progressContexts, resolveContexts;
nickjillings@1315 3345
nickjillings@1315 3346 // Add listeners to Deferred subordinates; treat others as resolved
nickjillings@1315 3347 if ( length > 1 ) {
nickjillings@1315 3348 progressValues = new Array( length );
nickjillings@1315 3349 progressContexts = new Array( length );
nickjillings@1315 3350 resolveContexts = new Array( length );
nickjillings@1315 3351 for ( ; i < length; i++ ) {
nickjillings@1315 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nickjillings@1315 3353 resolveValues[ i ].promise()
nickjillings@1315 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nickjillings@1315 3355 .fail( deferred.reject )
nickjillings@1315 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nickjillings@1315 3357 } else {
nickjillings@1315 3358 --remaining;
nickjillings@1315 3359 }
nickjillings@1315 3360 }
nickjillings@1315 3361 }
nickjillings@1315 3362
nickjillings@1315 3363 // If we're not waiting on anything, resolve the master
nickjillings@1315 3364 if ( !remaining ) {
nickjillings@1315 3365 deferred.resolveWith( resolveContexts, resolveValues );
nickjillings@1315 3366 }
nickjillings@1315 3367
nickjillings@1315 3368 return deferred.promise();
nickjillings@1315 3369 }
nickjillings@1315 3370 });
nickjillings@1315 3371
nickjillings@1315 3372
nickjillings@1315 3373 // The deferred used on DOM ready
nickjillings@1315 3374 var readyList;
nickjillings@1315 3375
nickjillings@1315 3376 jQuery.fn.ready = function( fn ) {
nickjillings@1315 3377 // Add the callback
nickjillings@1315 3378 jQuery.ready.promise().done( fn );
nickjillings@1315 3379
nickjillings@1315 3380 return this;
nickjillings@1315 3381 };
nickjillings@1315 3382
nickjillings@1315 3383 jQuery.extend({
nickjillings@1315 3384 // Is the DOM ready to be used? Set to true once it occurs.
nickjillings@1315 3385 isReady: false,
nickjillings@1315 3386
nickjillings@1315 3387 // A counter to track how many items to wait for before
nickjillings@1315 3388 // the ready event fires. See #6781
nickjillings@1315 3389 readyWait: 1,
nickjillings@1315 3390
nickjillings@1315 3391 // Hold (or release) the ready event
nickjillings@1315 3392 holdReady: function( hold ) {
nickjillings@1315 3393 if ( hold ) {
nickjillings@1315 3394 jQuery.readyWait++;
nickjillings@1315 3395 } else {
nickjillings@1315 3396 jQuery.ready( true );
nickjillings@1315 3397 }
nickjillings@1315 3398 },
nickjillings@1315 3399
nickjillings@1315 3400 // Handle when the DOM is ready
nickjillings@1315 3401 ready: function( wait ) {
nickjillings@1315 3402
nickjillings@1315 3403 // Abort if there are pending holds or we're already ready
nickjillings@1315 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nickjillings@1315 3405 return;
nickjillings@1315 3406 }
nickjillings@1315 3407
nickjillings@1315 3408 // Remember that the DOM is ready
nickjillings@1315 3409 jQuery.isReady = true;
nickjillings@1315 3410
nickjillings@1315 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nickjillings@1315 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nickjillings@1315 3413 return;
nickjillings@1315 3414 }
nickjillings@1315 3415
nickjillings@1315 3416 // If there are functions bound, to execute
nickjillings@1315 3417 readyList.resolveWith( document, [ jQuery ] );
nickjillings@1315 3418
nickjillings@1315 3419 // Trigger any bound ready events
nickjillings@1315 3420 if ( jQuery.fn.triggerHandler ) {
nickjillings@1315 3421 jQuery( document ).triggerHandler( "ready" );
nickjillings@1315 3422 jQuery( document ).off( "ready" );
nickjillings@1315 3423 }
nickjillings@1315 3424 }
nickjillings@1315 3425 });
nickjillings@1315 3426
nickjillings@1315 3427 /**
nickjillings@1315 3428 * The ready event handler and self cleanup method
nickjillings@1315 3429 */
nickjillings@1315 3430 function completed() {
nickjillings@1315 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nickjillings@1315 3432 window.removeEventListener( "load", completed, false );
nickjillings@1315 3433 jQuery.ready();
nickjillings@1315 3434 }
nickjillings@1315 3435
nickjillings@1315 3436 jQuery.ready.promise = function( obj ) {
nickjillings@1315 3437 if ( !readyList ) {
nickjillings@1315 3438
nickjillings@1315 3439 readyList = jQuery.Deferred();
nickjillings@1315 3440
nickjillings@1315 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nickjillings@1315 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nickjillings@1315 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nickjillings@1315 3444 if ( document.readyState === "complete" ) {
nickjillings@1315 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nickjillings@1315 3446 setTimeout( jQuery.ready );
nickjillings@1315 3447
nickjillings@1315 3448 } else {
nickjillings@1315 3449
nickjillings@1315 3450 // Use the handy event callback
nickjillings@1315 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nickjillings@1315 3452
nickjillings@1315 3453 // A fallback to window.onload, that will always work
nickjillings@1315 3454 window.addEventListener( "load", completed, false );
nickjillings@1315 3455 }
nickjillings@1315 3456 }
nickjillings@1315 3457 return readyList.promise( obj );
nickjillings@1315 3458 };
nickjillings@1315 3459
nickjillings@1315 3460 // Kick off the DOM ready check even if the user does not
nickjillings@1315 3461 jQuery.ready.promise();
nickjillings@1315 3462
nickjillings@1315 3463
nickjillings@1315 3464
nickjillings@1315 3465
nickjillings@1315 3466 // Multifunctional method to get and set values of a collection
nickjillings@1315 3467 // The value/s can optionally be executed if it's a function
nickjillings@1315 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nickjillings@1315 3469 var i = 0,
nickjillings@1315 3470 len = elems.length,
nickjillings@1315 3471 bulk = key == null;
nickjillings@1315 3472
nickjillings@1315 3473 // Sets many values
nickjillings@1315 3474 if ( jQuery.type( key ) === "object" ) {
nickjillings@1315 3475 chainable = true;
nickjillings@1315 3476 for ( i in key ) {
nickjillings@1315 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nickjillings@1315 3478 }
nickjillings@1315 3479
nickjillings@1315 3480 // Sets one value
nickjillings@1315 3481 } else if ( value !== undefined ) {
nickjillings@1315 3482 chainable = true;
nickjillings@1315 3483
nickjillings@1315 3484 if ( !jQuery.isFunction( value ) ) {
nickjillings@1315 3485 raw = true;
nickjillings@1315 3486 }
nickjillings@1315 3487
nickjillings@1315 3488 if ( bulk ) {
nickjillings@1315 3489 // Bulk operations run against the entire set
nickjillings@1315 3490 if ( raw ) {
nickjillings@1315 3491 fn.call( elems, value );
nickjillings@1315 3492 fn = null;
nickjillings@1315 3493
nickjillings@1315 3494 // ...except when executing function values
nickjillings@1315 3495 } else {
nickjillings@1315 3496 bulk = fn;
nickjillings@1315 3497 fn = function( elem, key, value ) {
nickjillings@1315 3498 return bulk.call( jQuery( elem ), value );
nickjillings@1315 3499 };
nickjillings@1315 3500 }
nickjillings@1315 3501 }
nickjillings@1315 3502
nickjillings@1315 3503 if ( fn ) {
nickjillings@1315 3504 for ( ; i < len; i++ ) {
nickjillings@1315 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nickjillings@1315 3506 }
nickjillings@1315 3507 }
nickjillings@1315 3508 }
nickjillings@1315 3509
nickjillings@1315 3510 return chainable ?
nickjillings@1315 3511 elems :
nickjillings@1315 3512
nickjillings@1315 3513 // Gets
nickjillings@1315 3514 bulk ?
nickjillings@1315 3515 fn.call( elems ) :
nickjillings@1315 3516 len ? fn( elems[0], key ) : emptyGet;
nickjillings@1315 3517 };
nickjillings@1315 3518
nickjillings@1315 3519
nickjillings@1315 3520 /**
nickjillings@1315 3521 * Determines whether an object can have data
nickjillings@1315 3522 */
nickjillings@1315 3523 jQuery.acceptData = function( owner ) {
nickjillings@1315 3524 // Accepts only:
nickjillings@1315 3525 // - Node
nickjillings@1315 3526 // - Node.ELEMENT_NODE
nickjillings@1315 3527 // - Node.DOCUMENT_NODE
nickjillings@1315 3528 // - Object
nickjillings@1315 3529 // - Any
nickjillings@1315 3530 /* jshint -W018 */
nickjillings@1315 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nickjillings@1315 3532 };
nickjillings@1315 3533
nickjillings@1315 3534
nickjillings@1315 3535 function Data() {
nickjillings@1315 3536 // Support: Android<4,
nickjillings@1315 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nickjillings@1315 3538 // return new empty object instead with no [[set]] accessor
nickjillings@1315 3539 Object.defineProperty( this.cache = {}, 0, {
nickjillings@1315 3540 get: function() {
nickjillings@1315 3541 return {};
nickjillings@1315 3542 }
nickjillings@1315 3543 });
nickjillings@1315 3544
nickjillings@1315 3545 this.expando = jQuery.expando + Data.uid++;
nickjillings@1315 3546 }
nickjillings@1315 3547
nickjillings@1315 3548 Data.uid = 1;
nickjillings@1315 3549 Data.accepts = jQuery.acceptData;
nickjillings@1315 3550
nickjillings@1315 3551 Data.prototype = {
nickjillings@1315 3552 key: function( owner ) {
nickjillings@1315 3553 // We can accept data for non-element nodes in modern browsers,
nickjillings@1315 3554 // but we should not, see #8335.
nickjillings@1315 3555 // Always return the key for a frozen object.
nickjillings@1315 3556 if ( !Data.accepts( owner ) ) {
nickjillings@1315 3557 return 0;
nickjillings@1315 3558 }
nickjillings@1315 3559
nickjillings@1315 3560 var descriptor = {},
nickjillings@1315 3561 // Check if the owner object already has a cache key
nickjillings@1315 3562 unlock = owner[ this.expando ];
nickjillings@1315 3563
nickjillings@1315 3564 // If not, create one
nickjillings@1315 3565 if ( !unlock ) {
nickjillings@1315 3566 unlock = Data.uid++;
nickjillings@1315 3567
nickjillings@1315 3568 // Secure it in a non-enumerable, non-writable property
nickjillings@1315 3569 try {
nickjillings@1315 3570 descriptor[ this.expando ] = { value: unlock };
nickjillings@1315 3571 Object.defineProperties( owner, descriptor );
nickjillings@1315 3572
nickjillings@1315 3573 // Support: Android<4
nickjillings@1315 3574 // Fallback to a less secure definition
nickjillings@1315 3575 } catch ( e ) {
nickjillings@1315 3576 descriptor[ this.expando ] = unlock;
nickjillings@1315 3577 jQuery.extend( owner, descriptor );
nickjillings@1315 3578 }
nickjillings@1315 3579 }
nickjillings@1315 3580
nickjillings@1315 3581 // Ensure the cache object
nickjillings@1315 3582 if ( !this.cache[ unlock ] ) {
nickjillings@1315 3583 this.cache[ unlock ] = {};
nickjillings@1315 3584 }
nickjillings@1315 3585
nickjillings@1315 3586 return unlock;
nickjillings@1315 3587 },
nickjillings@1315 3588 set: function( owner, data, value ) {
nickjillings@1315 3589 var prop,
nickjillings@1315 3590 // There may be an unlock assigned to this node,
nickjillings@1315 3591 // if there is no entry for this "owner", create one inline
nickjillings@1315 3592 // and set the unlock as though an owner entry had always existed
nickjillings@1315 3593 unlock = this.key( owner ),
nickjillings@1315 3594 cache = this.cache[ unlock ];
nickjillings@1315 3595
nickjillings@1315 3596 // Handle: [ owner, key, value ] args
nickjillings@1315 3597 if ( typeof data === "string" ) {
nickjillings@1315 3598 cache[ data ] = value;
nickjillings@1315 3599
nickjillings@1315 3600 // Handle: [ owner, { properties } ] args
nickjillings@1315 3601 } else {
nickjillings@1315 3602 // Fresh assignments by object are shallow copied
nickjillings@1315 3603 if ( jQuery.isEmptyObject( cache ) ) {
nickjillings@1315 3604 jQuery.extend( this.cache[ unlock ], data );
nickjillings@1315 3605 // Otherwise, copy the properties one-by-one to the cache object
nickjillings@1315 3606 } else {
nickjillings@1315 3607 for ( prop in data ) {
nickjillings@1315 3608 cache[ prop ] = data[ prop ];
nickjillings@1315 3609 }
nickjillings@1315 3610 }
nickjillings@1315 3611 }
nickjillings@1315 3612 return cache;
nickjillings@1315 3613 },
nickjillings@1315 3614 get: function( owner, key ) {
nickjillings@1315 3615 // Either a valid cache is found, or will be created.
nickjillings@1315 3616 // New caches will be created and the unlock returned,
nickjillings@1315 3617 // allowing direct access to the newly created
nickjillings@1315 3618 // empty data object. A valid owner object must be provided.
nickjillings@1315 3619 var cache = this.cache[ this.key( owner ) ];
nickjillings@1315 3620
nickjillings@1315 3621 return key === undefined ?
nickjillings@1315 3622 cache : cache[ key ];
nickjillings@1315 3623 },
nickjillings@1315 3624 access: function( owner, key, value ) {
nickjillings@1315 3625 var stored;
nickjillings@1315 3626 // In cases where either:
nickjillings@1315 3627 //
nickjillings@1315 3628 // 1. No key was specified
nickjillings@1315 3629 // 2. A string key was specified, but no value provided
nickjillings@1315 3630 //
nickjillings@1315 3631 // Take the "read" path and allow the get method to determine
nickjillings@1315 3632 // which value to return, respectively either:
nickjillings@1315 3633 //
nickjillings@1315 3634 // 1. The entire cache object
nickjillings@1315 3635 // 2. The data stored at the key
nickjillings@1315 3636 //
nickjillings@1315 3637 if ( key === undefined ||
nickjillings@1315 3638 ((key && typeof key === "string") && value === undefined) ) {
nickjillings@1315 3639
nickjillings@1315 3640 stored = this.get( owner, key );
nickjillings@1315 3641
nickjillings@1315 3642 return stored !== undefined ?
nickjillings@1315 3643 stored : this.get( owner, jQuery.camelCase(key) );
nickjillings@1315 3644 }
nickjillings@1315 3645
nickjillings@1315 3646 // [*]When the key is not a string, or both a key and value
nickjillings@1315 3647 // are specified, set or extend (existing objects) with either:
nickjillings@1315 3648 //
nickjillings@1315 3649 // 1. An object of properties
nickjillings@1315 3650 // 2. A key and value
nickjillings@1315 3651 //
nickjillings@1315 3652 this.set( owner, key, value );
nickjillings@1315 3653
nickjillings@1315 3654 // Since the "set" path can have two possible entry points
nickjillings@1315 3655 // return the expected data based on which path was taken[*]
nickjillings@1315 3656 return value !== undefined ? value : key;
nickjillings@1315 3657 },
nickjillings@1315 3658 remove: function( owner, key ) {
nickjillings@1315 3659 var i, name, camel,
nickjillings@1315 3660 unlock = this.key( owner ),
nickjillings@1315 3661 cache = this.cache[ unlock ];
nickjillings@1315 3662
nickjillings@1315 3663 if ( key === undefined ) {
nickjillings@1315 3664 this.cache[ unlock ] = {};
nickjillings@1315 3665
nickjillings@1315 3666 } else {
nickjillings@1315 3667 // Support array or space separated string of keys
nickjillings@1315 3668 if ( jQuery.isArray( key ) ) {
nickjillings@1315 3669 // If "name" is an array of keys...
nickjillings@1315 3670 // When data is initially created, via ("key", "val") signature,
nickjillings@1315 3671 // keys will be converted to camelCase.
nickjillings@1315 3672 // Since there is no way to tell _how_ a key was added, remove
nickjillings@1315 3673 // both plain key and camelCase key. #12786
nickjillings@1315 3674 // This will only penalize the array argument path.
nickjillings@1315 3675 name = key.concat( key.map( jQuery.camelCase ) );
nickjillings@1315 3676 } else {
nickjillings@1315 3677 camel = jQuery.camelCase( key );
nickjillings@1315 3678 // Try the string as a key before any manipulation
nickjillings@1315 3679 if ( key in cache ) {
nickjillings@1315 3680 name = [ key, camel ];
nickjillings@1315 3681 } else {
nickjillings@1315 3682 // If a key with the spaces exists, use it.
nickjillings@1315 3683 // Otherwise, create an array by matching non-whitespace
nickjillings@1315 3684 name = camel;
nickjillings@1315 3685 name = name in cache ?
nickjillings@1315 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nickjillings@1315 3687 }
nickjillings@1315 3688 }
nickjillings@1315 3689
nickjillings@1315 3690 i = name.length;
nickjillings@1315 3691 while ( i-- ) {
nickjillings@1315 3692 delete cache[ name[ i ] ];
nickjillings@1315 3693 }
nickjillings@1315 3694 }
nickjillings@1315 3695 },
nickjillings@1315 3696 hasData: function( owner ) {
nickjillings@1315 3697 return !jQuery.isEmptyObject(
nickjillings@1315 3698 this.cache[ owner[ this.expando ] ] || {}
nickjillings@1315 3699 );
nickjillings@1315 3700 },
nickjillings@1315 3701 discard: function( owner ) {
nickjillings@1315 3702 if ( owner[ this.expando ] ) {
nickjillings@1315 3703 delete this.cache[ owner[ this.expando ] ];
nickjillings@1315 3704 }
nickjillings@1315 3705 }
nickjillings@1315 3706 };
nickjillings@1315 3707 var data_priv = new Data();
nickjillings@1315 3708
nickjillings@1315 3709 var data_user = new Data();
nickjillings@1315 3710
nickjillings@1315 3711
nickjillings@1315 3712
nickjillings@1315 3713 // Implementation Summary
nickjillings@1315 3714 //
nickjillings@1315 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nickjillings@1315 3716 // 2. Improve the module's maintainability by reducing the storage
nickjillings@1315 3717 // paths to a single mechanism.
nickjillings@1315 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nickjillings@1315 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nickjillings@1315 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nickjillings@1315 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nickjillings@1315 3722
nickjillings@1315 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nickjillings@1315 3724 rmultiDash = /([A-Z])/g;
nickjillings@1315 3725
nickjillings@1315 3726 function dataAttr( elem, key, data ) {
nickjillings@1315 3727 var name;
nickjillings@1315 3728
nickjillings@1315 3729 // If nothing was found internally, try to fetch any
nickjillings@1315 3730 // data from the HTML5 data-* attribute
nickjillings@1315 3731 if ( data === undefined && elem.nodeType === 1 ) {
nickjillings@1315 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nickjillings@1315 3733 data = elem.getAttribute( name );
nickjillings@1315 3734
nickjillings@1315 3735 if ( typeof data === "string" ) {
nickjillings@1315 3736 try {
nickjillings@1315 3737 data = data === "true" ? true :
nickjillings@1315 3738 data === "false" ? false :
nickjillings@1315 3739 data === "null" ? null :
nickjillings@1315 3740 // Only convert to a number if it doesn't change the string
nickjillings@1315 3741 +data + "" === data ? +data :
nickjillings@1315 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nickjillings@1315 3743 data;
nickjillings@1315 3744 } catch( e ) {}
nickjillings@1315 3745
nickjillings@1315 3746 // Make sure we set the data so it isn't changed later
nickjillings@1315 3747 data_user.set( elem, key, data );
nickjillings@1315 3748 } else {
nickjillings@1315 3749 data = undefined;
nickjillings@1315 3750 }
nickjillings@1315 3751 }
nickjillings@1315 3752 return data;
nickjillings@1315 3753 }
nickjillings@1315 3754
nickjillings@1315 3755 jQuery.extend({
nickjillings@1315 3756 hasData: function( elem ) {
nickjillings@1315 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nickjillings@1315 3758 },
nickjillings@1315 3759
nickjillings@1315 3760 data: function( elem, name, data ) {
nickjillings@1315 3761 return data_user.access( elem, name, data );
nickjillings@1315 3762 },
nickjillings@1315 3763
nickjillings@1315 3764 removeData: function( elem, name ) {
nickjillings@1315 3765 data_user.remove( elem, name );
nickjillings@1315 3766 },
nickjillings@1315 3767
nickjillings@1315 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nickjillings@1315 3769 // with direct calls to data_priv methods, these can be deprecated.
nickjillings@1315 3770 _data: function( elem, name, data ) {
nickjillings@1315 3771 return data_priv.access( elem, name, data );
nickjillings@1315 3772 },
nickjillings@1315 3773
nickjillings@1315 3774 _removeData: function( elem, name ) {
nickjillings@1315 3775 data_priv.remove( elem, name );
nickjillings@1315 3776 }
nickjillings@1315 3777 });
nickjillings@1315 3778
nickjillings@1315 3779 jQuery.fn.extend({
nickjillings@1315 3780 data: function( key, value ) {
nickjillings@1315 3781 var i, name, data,
nickjillings@1315 3782 elem = this[ 0 ],
nickjillings@1315 3783 attrs = elem && elem.attributes;
nickjillings@1315 3784
nickjillings@1315 3785 // Gets all values
nickjillings@1315 3786 if ( key === undefined ) {
nickjillings@1315 3787 if ( this.length ) {
nickjillings@1315 3788 data = data_user.get( elem );
nickjillings@1315 3789
nickjillings@1315 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nickjillings@1315 3791 i = attrs.length;
nickjillings@1315 3792 while ( i-- ) {
nickjillings@1315 3793
nickjillings@1315 3794 // Support: IE11+
nickjillings@1315 3795 // The attrs elements can be null (#14894)
nickjillings@1315 3796 if ( attrs[ i ] ) {
nickjillings@1315 3797 name = attrs[ i ].name;
nickjillings@1315 3798 if ( name.indexOf( "data-" ) === 0 ) {
nickjillings@1315 3799 name = jQuery.camelCase( name.slice(5) );
nickjillings@1315 3800 dataAttr( elem, name, data[ name ] );
nickjillings@1315 3801 }
nickjillings@1315 3802 }
nickjillings@1315 3803 }
nickjillings@1315 3804 data_priv.set( elem, "hasDataAttrs", true );
nickjillings@1315 3805 }
nickjillings@1315 3806 }
nickjillings@1315 3807
nickjillings@1315 3808 return data;
nickjillings@1315 3809 }
nickjillings@1315 3810
nickjillings@1315 3811 // Sets multiple values
nickjillings@1315 3812 if ( typeof key === "object" ) {
nickjillings@1315 3813 return this.each(function() {
nickjillings@1315 3814 data_user.set( this, key );
nickjillings@1315 3815 });
nickjillings@1315 3816 }
nickjillings@1315 3817
nickjillings@1315 3818 return access( this, function( value ) {
nickjillings@1315 3819 var data,
nickjillings@1315 3820 camelKey = jQuery.camelCase( key );
nickjillings@1315 3821
nickjillings@1315 3822 // The calling jQuery object (element matches) is not empty
nickjillings@1315 3823 // (and therefore has an element appears at this[ 0 ]) and the
nickjillings@1315 3824 // `value` parameter was not undefined. An empty jQuery object
nickjillings@1315 3825 // will result in `undefined` for elem = this[ 0 ] which will
nickjillings@1315 3826 // throw an exception if an attempt to read a data cache is made.
nickjillings@1315 3827 if ( elem && value === undefined ) {
nickjillings@1315 3828 // Attempt to get data from the cache
nickjillings@1315 3829 // with the key as-is
nickjillings@1315 3830 data = data_user.get( elem, key );
nickjillings@1315 3831 if ( data !== undefined ) {
nickjillings@1315 3832 return data;
nickjillings@1315 3833 }
nickjillings@1315 3834
nickjillings@1315 3835 // Attempt to get data from the cache
nickjillings@1315 3836 // with the key camelized
nickjillings@1315 3837 data = data_user.get( elem, camelKey );
nickjillings@1315 3838 if ( data !== undefined ) {
nickjillings@1315 3839 return data;
nickjillings@1315 3840 }
nickjillings@1315 3841
nickjillings@1315 3842 // Attempt to "discover" the data in
nickjillings@1315 3843 // HTML5 custom data-* attrs
nickjillings@1315 3844 data = dataAttr( elem, camelKey, undefined );
nickjillings@1315 3845 if ( data !== undefined ) {
nickjillings@1315 3846 return data;
nickjillings@1315 3847 }
nickjillings@1315 3848
nickjillings@1315 3849 // We tried really hard, but the data doesn't exist.
nickjillings@1315 3850 return;
nickjillings@1315 3851 }
nickjillings@1315 3852
nickjillings@1315 3853 // Set the data...
nickjillings@1315 3854 this.each(function() {
nickjillings@1315 3855 // First, attempt to store a copy or reference of any
nickjillings@1315 3856 // data that might've been store with a camelCased key.
nickjillings@1315 3857 var data = data_user.get( this, camelKey );
nickjillings@1315 3858
nickjillings@1315 3859 // For HTML5 data-* attribute interop, we have to
nickjillings@1315 3860 // store property names with dashes in a camelCase form.
nickjillings@1315 3861 // This might not apply to all properties...*
nickjillings@1315 3862 data_user.set( this, camelKey, value );
nickjillings@1315 3863
nickjillings@1315 3864 // *... In the case of properties that might _actually_
nickjillings@1315 3865 // have dashes, we need to also store a copy of that
nickjillings@1315 3866 // unchanged property.
nickjillings@1315 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nickjillings@1315 3868 data_user.set( this, key, value );
nickjillings@1315 3869 }
nickjillings@1315 3870 });
nickjillings@1315 3871 }, null, value, arguments.length > 1, null, true );
nickjillings@1315 3872 },
nickjillings@1315 3873
nickjillings@1315 3874 removeData: function( key ) {
nickjillings@1315 3875 return this.each(function() {
nickjillings@1315 3876 data_user.remove( this, key );
nickjillings@1315 3877 });
nickjillings@1315 3878 }
nickjillings@1315 3879 });
nickjillings@1315 3880
nickjillings@1315 3881
nickjillings@1315 3882 jQuery.extend({
nickjillings@1315 3883 queue: function( elem, type, data ) {
nickjillings@1315 3884 var queue;
nickjillings@1315 3885
nickjillings@1315 3886 if ( elem ) {
nickjillings@1315 3887 type = ( type || "fx" ) + "queue";
nickjillings@1315 3888 queue = data_priv.get( elem, type );
nickjillings@1315 3889
nickjillings@1315 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nickjillings@1315 3891 if ( data ) {
nickjillings@1315 3892 if ( !queue || jQuery.isArray( data ) ) {
nickjillings@1315 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nickjillings@1315 3894 } else {
nickjillings@1315 3895 queue.push( data );
nickjillings@1315 3896 }
nickjillings@1315 3897 }
nickjillings@1315 3898 return queue || [];
nickjillings@1315 3899 }
nickjillings@1315 3900 },
nickjillings@1315 3901
nickjillings@1315 3902 dequeue: function( elem, type ) {
nickjillings@1315 3903 type = type || "fx";
nickjillings@1315 3904
nickjillings@1315 3905 var queue = jQuery.queue( elem, type ),
nickjillings@1315 3906 startLength = queue.length,
nickjillings@1315 3907 fn = queue.shift(),
nickjillings@1315 3908 hooks = jQuery._queueHooks( elem, type ),
nickjillings@1315 3909 next = function() {
nickjillings@1315 3910 jQuery.dequeue( elem, type );
nickjillings@1315 3911 };
nickjillings@1315 3912
nickjillings@1315 3913 // If the fx queue is dequeued, always remove the progress sentinel
nickjillings@1315 3914 if ( fn === "inprogress" ) {
nickjillings@1315 3915 fn = queue.shift();
nickjillings@1315 3916 startLength--;
nickjillings@1315 3917 }
nickjillings@1315 3918
nickjillings@1315 3919 if ( fn ) {
nickjillings@1315 3920
nickjillings@1315 3921 // Add a progress sentinel to prevent the fx queue from being
nickjillings@1315 3922 // automatically dequeued
nickjillings@1315 3923 if ( type === "fx" ) {
nickjillings@1315 3924 queue.unshift( "inprogress" );
nickjillings@1315 3925 }
nickjillings@1315 3926
nickjillings@1315 3927 // Clear up the last queue stop function
nickjillings@1315 3928 delete hooks.stop;
nickjillings@1315 3929 fn.call( elem, next, hooks );
nickjillings@1315 3930 }
nickjillings@1315 3931
nickjillings@1315 3932 if ( !startLength && hooks ) {
nickjillings@1315 3933 hooks.empty.fire();
nickjillings@1315 3934 }
nickjillings@1315 3935 },
nickjillings@1315 3936
nickjillings@1315 3937 // Not public - generate a queueHooks object, or return the current one
nickjillings@1315 3938 _queueHooks: function( elem, type ) {
nickjillings@1315 3939 var key = type + "queueHooks";
nickjillings@1315 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nickjillings@1315 3941 empty: jQuery.Callbacks("once memory").add(function() {
nickjillings@1315 3942 data_priv.remove( elem, [ type + "queue", key ] );
nickjillings@1315 3943 })
nickjillings@1315 3944 });
nickjillings@1315 3945 }
nickjillings@1315 3946 });
nickjillings@1315 3947
nickjillings@1315 3948 jQuery.fn.extend({
nickjillings@1315 3949 queue: function( type, data ) {
nickjillings@1315 3950 var setter = 2;
nickjillings@1315 3951
nickjillings@1315 3952 if ( typeof type !== "string" ) {
nickjillings@1315 3953 data = type;
nickjillings@1315 3954 type = "fx";
nickjillings@1315 3955 setter--;
nickjillings@1315 3956 }
nickjillings@1315 3957
nickjillings@1315 3958 if ( arguments.length < setter ) {
nickjillings@1315 3959 return jQuery.queue( this[0], type );
nickjillings@1315 3960 }
nickjillings@1315 3961
nickjillings@1315 3962 return data === undefined ?
nickjillings@1315 3963 this :
nickjillings@1315 3964 this.each(function() {
nickjillings@1315 3965 var queue = jQuery.queue( this, type, data );
nickjillings@1315 3966
nickjillings@1315 3967 // Ensure a hooks for this queue
nickjillings@1315 3968 jQuery._queueHooks( this, type );
nickjillings@1315 3969
nickjillings@1315 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nickjillings@1315 3971 jQuery.dequeue( this, type );
nickjillings@1315 3972 }
nickjillings@1315 3973 });
nickjillings@1315 3974 },
nickjillings@1315 3975 dequeue: function( type ) {
nickjillings@1315 3976 return this.each(function() {
nickjillings@1315 3977 jQuery.dequeue( this, type );
nickjillings@1315 3978 });
nickjillings@1315 3979 },
nickjillings@1315 3980 clearQueue: function( type ) {
nickjillings@1315 3981 return this.queue( type || "fx", [] );
nickjillings@1315 3982 },
nickjillings@1315 3983 // Get a promise resolved when queues of a certain type
nickjillings@1315 3984 // are emptied (fx is the type by default)
nickjillings@1315 3985 promise: function( type, obj ) {
nickjillings@1315 3986 var tmp,
nickjillings@1315 3987 count = 1,
nickjillings@1315 3988 defer = jQuery.Deferred(),
nickjillings@1315 3989 elements = this,
nickjillings@1315 3990 i = this.length,
nickjillings@1315 3991 resolve = function() {
nickjillings@1315 3992 if ( !( --count ) ) {
nickjillings@1315 3993 defer.resolveWith( elements, [ elements ] );
nickjillings@1315 3994 }
nickjillings@1315 3995 };
nickjillings@1315 3996
nickjillings@1315 3997 if ( typeof type !== "string" ) {
nickjillings@1315 3998 obj = type;
nickjillings@1315 3999 type = undefined;
nickjillings@1315 4000 }
nickjillings@1315 4001 type = type || "fx";
nickjillings@1315 4002
nickjillings@1315 4003 while ( i-- ) {
nickjillings@1315 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nickjillings@1315 4005 if ( tmp && tmp.empty ) {
nickjillings@1315 4006 count++;
nickjillings@1315 4007 tmp.empty.add( resolve );
nickjillings@1315 4008 }
nickjillings@1315 4009 }
nickjillings@1315 4010 resolve();
nickjillings@1315 4011 return defer.promise( obj );
nickjillings@1315 4012 }
nickjillings@1315 4013 });
nickjillings@1315 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nickjillings@1315 4015
nickjillings@1315 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nickjillings@1315 4017
nickjillings@1315 4018 var isHidden = function( elem, el ) {
nickjillings@1315 4019 // isHidden might be called from jQuery#filter function;
nickjillings@1315 4020 // in that case, element will be second argument
nickjillings@1315 4021 elem = el || elem;
nickjillings@1315 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nickjillings@1315 4023 };
nickjillings@1315 4024
nickjillings@1315 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nickjillings@1315 4026
nickjillings@1315 4027
nickjillings@1315 4028
nickjillings@1315 4029 (function() {
nickjillings@1315 4030 var fragment = document.createDocumentFragment(),
nickjillings@1315 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nickjillings@1315 4032 input = document.createElement( "input" );
nickjillings@1315 4033
nickjillings@1315 4034 // Support: Safari<=5.1
nickjillings@1315 4035 // Check state lost if the name is set (#11217)
nickjillings@1315 4036 // Support: Windows Web Apps (WWA)
nickjillings@1315 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nickjillings@1315 4038 input.setAttribute( "type", "radio" );
nickjillings@1315 4039 input.setAttribute( "checked", "checked" );
nickjillings@1315 4040 input.setAttribute( "name", "t" );
nickjillings@1315 4041
nickjillings@1315 4042 div.appendChild( input );
nickjillings@1315 4043
nickjillings@1315 4044 // Support: Safari<=5.1, Android<4.2
nickjillings@1315 4045 // Older WebKit doesn't clone checked state correctly in fragments
nickjillings@1315 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nickjillings@1315 4047
nickjillings@1315 4048 // Support: IE<=11+
nickjillings@1315 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nickjillings@1315 4050 div.innerHTML = "<textarea>x</textarea>";
nickjillings@1315 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nickjillings@1315 4052 })();
nickjillings@1315 4053 var strundefined = typeof undefined;
nickjillings@1315 4054
nickjillings@1315 4055
nickjillings@1315 4056
nickjillings@1315 4057 support.focusinBubbles = "onfocusin" in window;
nickjillings@1315 4058
nickjillings@1315 4059
nickjillings@1315 4060 var
nickjillings@1315 4061 rkeyEvent = /^key/,
nickjillings@1315 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nickjillings@1315 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nickjillings@1315 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nickjillings@1315 4065
nickjillings@1315 4066 function returnTrue() {
nickjillings@1315 4067 return true;
nickjillings@1315 4068 }
nickjillings@1315 4069
nickjillings@1315 4070 function returnFalse() {
nickjillings@1315 4071 return false;
nickjillings@1315 4072 }
nickjillings@1315 4073
nickjillings@1315 4074 function safeActiveElement() {
nickjillings@1315 4075 try {
nickjillings@1315 4076 return document.activeElement;
nickjillings@1315 4077 } catch ( err ) { }
nickjillings@1315 4078 }
nickjillings@1315 4079
nickjillings@1315 4080 /*
nickjillings@1315 4081 * Helper functions for managing events -- not part of the public interface.
nickjillings@1315 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nickjillings@1315 4083 */
nickjillings@1315 4084 jQuery.event = {
nickjillings@1315 4085
nickjillings@1315 4086 global: {},
nickjillings@1315 4087
nickjillings@1315 4088 add: function( elem, types, handler, data, selector ) {
nickjillings@1315 4089
nickjillings@1315 4090 var handleObjIn, eventHandle, tmp,
nickjillings@1315 4091 events, t, handleObj,
nickjillings@1315 4092 special, handlers, type, namespaces, origType,
nickjillings@1315 4093 elemData = data_priv.get( elem );
nickjillings@1315 4094
nickjillings@1315 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nickjillings@1315 4096 if ( !elemData ) {
nickjillings@1315 4097 return;
nickjillings@1315 4098 }
nickjillings@1315 4099
nickjillings@1315 4100 // Caller can pass in an object of custom data in lieu of the handler
nickjillings@1315 4101 if ( handler.handler ) {
nickjillings@1315 4102 handleObjIn = handler;
nickjillings@1315 4103 handler = handleObjIn.handler;
nickjillings@1315 4104 selector = handleObjIn.selector;
nickjillings@1315 4105 }
nickjillings@1315 4106
nickjillings@1315 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nickjillings@1315 4108 if ( !handler.guid ) {
nickjillings@1315 4109 handler.guid = jQuery.guid++;
nickjillings@1315 4110 }
nickjillings@1315 4111
nickjillings@1315 4112 // Init the element's event structure and main handler, if this is the first
nickjillings@1315 4113 if ( !(events = elemData.events) ) {
nickjillings@1315 4114 events = elemData.events = {};
nickjillings@1315 4115 }
nickjillings@1315 4116 if ( !(eventHandle = elemData.handle) ) {
nickjillings@1315 4117 eventHandle = elemData.handle = function( e ) {
nickjillings@1315 4118 // Discard the second event of a jQuery.event.trigger() and
nickjillings@1315 4119 // when an event is called after a page has unloaded
nickjillings@1315 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nickjillings@1315 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nickjillings@1315 4122 };
nickjillings@1315 4123 }
nickjillings@1315 4124
nickjillings@1315 4125 // Handle multiple events separated by a space
nickjillings@1315 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1315 4127 t = types.length;
nickjillings@1315 4128 while ( t-- ) {
nickjillings@1315 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1315 4130 type = origType = tmp[1];
nickjillings@1315 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1315 4132
nickjillings@1315 4133 // There *must* be a type, no attaching namespace-only handlers
nickjillings@1315 4134 if ( !type ) {
nickjillings@1315 4135 continue;
nickjillings@1315 4136 }
nickjillings@1315 4137
nickjillings@1315 4138 // If event changes its type, use the special event handlers for the changed type
nickjillings@1315 4139 special = jQuery.event.special[ type ] || {};
nickjillings@1315 4140
nickjillings@1315 4141 // If selector defined, determine special event api type, otherwise given type
nickjillings@1315 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1315 4143
nickjillings@1315 4144 // Update special based on newly reset type
nickjillings@1315 4145 special = jQuery.event.special[ type ] || {};
nickjillings@1315 4146
nickjillings@1315 4147 // handleObj is passed to all event handlers
nickjillings@1315 4148 handleObj = jQuery.extend({
nickjillings@1315 4149 type: type,
nickjillings@1315 4150 origType: origType,
nickjillings@1315 4151 data: data,
nickjillings@1315 4152 handler: handler,
nickjillings@1315 4153 guid: handler.guid,
nickjillings@1315 4154 selector: selector,
nickjillings@1315 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nickjillings@1315 4156 namespace: namespaces.join(".")
nickjillings@1315 4157 }, handleObjIn );
nickjillings@1315 4158
nickjillings@1315 4159 // Init the event handler queue if we're the first
nickjillings@1315 4160 if ( !(handlers = events[ type ]) ) {
nickjillings@1315 4161 handlers = events[ type ] = [];
nickjillings@1315 4162 handlers.delegateCount = 0;
nickjillings@1315 4163
nickjillings@1315 4164 // Only use addEventListener if the special events handler returns false
nickjillings@1315 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nickjillings@1315 4166 if ( elem.addEventListener ) {
nickjillings@1315 4167 elem.addEventListener( type, eventHandle, false );
nickjillings@1315 4168 }
nickjillings@1315 4169 }
nickjillings@1315 4170 }
nickjillings@1315 4171
nickjillings@1315 4172 if ( special.add ) {
nickjillings@1315 4173 special.add.call( elem, handleObj );
nickjillings@1315 4174
nickjillings@1315 4175 if ( !handleObj.handler.guid ) {
nickjillings@1315 4176 handleObj.handler.guid = handler.guid;
nickjillings@1315 4177 }
nickjillings@1315 4178 }
nickjillings@1315 4179
nickjillings@1315 4180 // Add to the element's handler list, delegates in front
nickjillings@1315 4181 if ( selector ) {
nickjillings@1315 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nickjillings@1315 4183 } else {
nickjillings@1315 4184 handlers.push( handleObj );
nickjillings@1315 4185 }
nickjillings@1315 4186
nickjillings@1315 4187 // Keep track of which events have ever been used, for event optimization
nickjillings@1315 4188 jQuery.event.global[ type ] = true;
nickjillings@1315 4189 }
nickjillings@1315 4190
nickjillings@1315 4191 },
nickjillings@1315 4192
nickjillings@1315 4193 // Detach an event or set of events from an element
nickjillings@1315 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nickjillings@1315 4195
nickjillings@1315 4196 var j, origCount, tmp,
nickjillings@1315 4197 events, t, handleObj,
nickjillings@1315 4198 special, handlers, type, namespaces, origType,
nickjillings@1315 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nickjillings@1315 4200
nickjillings@1315 4201 if ( !elemData || !(events = elemData.events) ) {
nickjillings@1315 4202 return;
nickjillings@1315 4203 }
nickjillings@1315 4204
nickjillings@1315 4205 // Once for each type.namespace in types; type may be omitted
nickjillings@1315 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1315 4207 t = types.length;
nickjillings@1315 4208 while ( t-- ) {
nickjillings@1315 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1315 4210 type = origType = tmp[1];
nickjillings@1315 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1315 4212
nickjillings@1315 4213 // Unbind all events (on this namespace, if provided) for the element
nickjillings@1315 4214 if ( !type ) {
nickjillings@1315 4215 for ( type in events ) {
nickjillings@1315 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nickjillings@1315 4217 }
nickjillings@1315 4218 continue;
nickjillings@1315 4219 }
nickjillings@1315 4220
nickjillings@1315 4221 special = jQuery.event.special[ type ] || {};
nickjillings@1315 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1315 4223 handlers = events[ type ] || [];
nickjillings@1315 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nickjillings@1315 4225
nickjillings@1315 4226 // Remove matching events
nickjillings@1315 4227 origCount = j = handlers.length;
nickjillings@1315 4228 while ( j-- ) {
nickjillings@1315 4229 handleObj = handlers[ j ];
nickjillings@1315 4230
nickjillings@1315 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nickjillings@1315 4232 ( !handler || handler.guid === handleObj.guid ) &&
nickjillings@1315 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nickjillings@1315 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nickjillings@1315 4235 handlers.splice( j, 1 );
nickjillings@1315 4236
nickjillings@1315 4237 if ( handleObj.selector ) {
nickjillings@1315 4238 handlers.delegateCount--;
nickjillings@1315 4239 }
nickjillings@1315 4240 if ( special.remove ) {
nickjillings@1315 4241 special.remove.call( elem, handleObj );
nickjillings@1315 4242 }
nickjillings@1315 4243 }
nickjillings@1315 4244 }
nickjillings@1315 4245
nickjillings@1315 4246 // Remove generic event handler if we removed something and no more handlers exist
nickjillings@1315 4247 // (avoids potential for endless recursion during removal of special event handlers)
nickjillings@1315 4248 if ( origCount && !handlers.length ) {
nickjillings@1315 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nickjillings@1315 4250 jQuery.removeEvent( elem, type, elemData.handle );
nickjillings@1315 4251 }
nickjillings@1315 4252
nickjillings@1315 4253 delete events[ type ];
nickjillings@1315 4254 }
nickjillings@1315 4255 }
nickjillings@1315 4256
nickjillings@1315 4257 // Remove the expando if it's no longer used
nickjillings@1315 4258 if ( jQuery.isEmptyObject( events ) ) {
nickjillings@1315 4259 delete elemData.handle;
nickjillings@1315 4260 data_priv.remove( elem, "events" );
nickjillings@1315 4261 }
nickjillings@1315 4262 },
nickjillings@1315 4263
nickjillings@1315 4264 trigger: function( event, data, elem, onlyHandlers ) {
nickjillings@1315 4265
nickjillings@1315 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nickjillings@1315 4267 eventPath = [ elem || document ],
nickjillings@1315 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nickjillings@1315 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nickjillings@1315 4270
nickjillings@1315 4271 cur = tmp = elem = elem || document;
nickjillings@1315 4272
nickjillings@1315 4273 // Don't do events on text and comment nodes
nickjillings@1315 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nickjillings@1315 4275 return;
nickjillings@1315 4276 }
nickjillings@1315 4277
nickjillings@1315 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nickjillings@1315 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nickjillings@1315 4280 return;
nickjillings@1315 4281 }
nickjillings@1315 4282
nickjillings@1315 4283 if ( type.indexOf(".") >= 0 ) {
nickjillings@1315 4284 // Namespaced trigger; create a regexp to match event type in handle()
nickjillings@1315 4285 namespaces = type.split(".");
nickjillings@1315 4286 type = namespaces.shift();
nickjillings@1315 4287 namespaces.sort();
nickjillings@1315 4288 }
nickjillings@1315 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nickjillings@1315 4290
nickjillings@1315 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nickjillings@1315 4292 event = event[ jQuery.expando ] ?
nickjillings@1315 4293 event :
nickjillings@1315 4294 new jQuery.Event( type, typeof event === "object" && event );
nickjillings@1315 4295
nickjillings@1315 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nickjillings@1315 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nickjillings@1315 4298 event.namespace = namespaces.join(".");
nickjillings@1315 4299 event.namespace_re = event.namespace ?
nickjillings@1315 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nickjillings@1315 4301 null;
nickjillings@1315 4302
nickjillings@1315 4303 // Clean up the event in case it is being reused
nickjillings@1315 4304 event.result = undefined;
nickjillings@1315 4305 if ( !event.target ) {
nickjillings@1315 4306 event.target = elem;
nickjillings@1315 4307 }
nickjillings@1315 4308
nickjillings@1315 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nickjillings@1315 4310 data = data == null ?
nickjillings@1315 4311 [ event ] :
nickjillings@1315 4312 jQuery.makeArray( data, [ event ] );
nickjillings@1315 4313
nickjillings@1315 4314 // Allow special events to draw outside the lines
nickjillings@1315 4315 special = jQuery.event.special[ type ] || {};
nickjillings@1315 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nickjillings@1315 4317 return;
nickjillings@1315 4318 }
nickjillings@1315 4319
nickjillings@1315 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nickjillings@1315 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nickjillings@1315 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nickjillings@1315 4323
nickjillings@1315 4324 bubbleType = special.delegateType || type;
nickjillings@1315 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nickjillings@1315 4326 cur = cur.parentNode;
nickjillings@1315 4327 }
nickjillings@1315 4328 for ( ; cur; cur = cur.parentNode ) {
nickjillings@1315 4329 eventPath.push( cur );
nickjillings@1315 4330 tmp = cur;
nickjillings@1315 4331 }
nickjillings@1315 4332
nickjillings@1315 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nickjillings@1315 4334 if ( tmp === (elem.ownerDocument || document) ) {
nickjillings@1315 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nickjillings@1315 4336 }
nickjillings@1315 4337 }
nickjillings@1315 4338
nickjillings@1315 4339 // Fire handlers on the event path
nickjillings@1315 4340 i = 0;
nickjillings@1315 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nickjillings@1315 4342
nickjillings@1315 4343 event.type = i > 1 ?
nickjillings@1315 4344 bubbleType :
nickjillings@1315 4345 special.bindType || type;
nickjillings@1315 4346
nickjillings@1315 4347 // jQuery handler
nickjillings@1315 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nickjillings@1315 4349 if ( handle ) {
nickjillings@1315 4350 handle.apply( cur, data );
nickjillings@1315 4351 }
nickjillings@1315 4352
nickjillings@1315 4353 // Native handler
nickjillings@1315 4354 handle = ontype && cur[ ontype ];
nickjillings@1315 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nickjillings@1315 4356 event.result = handle.apply( cur, data );
nickjillings@1315 4357 if ( event.result === false ) {
nickjillings@1315 4358 event.preventDefault();
nickjillings@1315 4359 }
nickjillings@1315 4360 }
nickjillings@1315 4361 }
nickjillings@1315 4362 event.type = type;
nickjillings@1315 4363
nickjillings@1315 4364 // If nobody prevented the default action, do it now
nickjillings@1315 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nickjillings@1315 4366
nickjillings@1315 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nickjillings@1315 4368 jQuery.acceptData( elem ) ) {
nickjillings@1315 4369
nickjillings@1315 4370 // Call a native DOM method on the target with the same name name as the event.
nickjillings@1315 4371 // Don't do default actions on window, that's where global variables be (#6170)
nickjillings@1315 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nickjillings@1315 4373
nickjillings@1315 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nickjillings@1315 4375 tmp = elem[ ontype ];
nickjillings@1315 4376
nickjillings@1315 4377 if ( tmp ) {
nickjillings@1315 4378 elem[ ontype ] = null;
nickjillings@1315 4379 }
nickjillings@1315 4380
nickjillings@1315 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nickjillings@1315 4382 jQuery.event.triggered = type;
nickjillings@1315 4383 elem[ type ]();
nickjillings@1315 4384 jQuery.event.triggered = undefined;
nickjillings@1315 4385
nickjillings@1315 4386 if ( tmp ) {
nickjillings@1315 4387 elem[ ontype ] = tmp;
nickjillings@1315 4388 }
nickjillings@1315 4389 }
nickjillings@1315 4390 }
nickjillings@1315 4391 }
nickjillings@1315 4392
nickjillings@1315 4393 return event.result;
nickjillings@1315 4394 },
nickjillings@1315 4395
nickjillings@1315 4396 dispatch: function( event ) {
nickjillings@1315 4397
nickjillings@1315 4398 // Make a writable jQuery.Event from the native event object
nickjillings@1315 4399 event = jQuery.event.fix( event );
nickjillings@1315 4400
nickjillings@1315 4401 var i, j, ret, matched, handleObj,
nickjillings@1315 4402 handlerQueue = [],
nickjillings@1315 4403 args = slice.call( arguments ),
nickjillings@1315 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nickjillings@1315 4405 special = jQuery.event.special[ event.type ] || {};
nickjillings@1315 4406
nickjillings@1315 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nickjillings@1315 4408 args[0] = event;
nickjillings@1315 4409 event.delegateTarget = this;
nickjillings@1315 4410
nickjillings@1315 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nickjillings@1315 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nickjillings@1315 4413 return;
nickjillings@1315 4414 }
nickjillings@1315 4415
nickjillings@1315 4416 // Determine handlers
nickjillings@1315 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nickjillings@1315 4418
nickjillings@1315 4419 // Run delegates first; they may want to stop propagation beneath us
nickjillings@1315 4420 i = 0;
nickjillings@1315 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nickjillings@1315 4422 event.currentTarget = matched.elem;
nickjillings@1315 4423
nickjillings@1315 4424 j = 0;
nickjillings@1315 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nickjillings@1315 4426
nickjillings@1315 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nickjillings@1315 4428 // a subset or equal to those in the bound event (both can have no namespace).
nickjillings@1315 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nickjillings@1315 4430
nickjillings@1315 4431 event.handleObj = handleObj;
nickjillings@1315 4432 event.data = handleObj.data;
nickjillings@1315 4433
nickjillings@1315 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nickjillings@1315 4435 .apply( matched.elem, args );
nickjillings@1315 4436
nickjillings@1315 4437 if ( ret !== undefined ) {
nickjillings@1315 4438 if ( (event.result = ret) === false ) {
nickjillings@1315 4439 event.preventDefault();
nickjillings@1315 4440 event.stopPropagation();
nickjillings@1315 4441 }
nickjillings@1315 4442 }
nickjillings@1315 4443 }
nickjillings@1315 4444 }
nickjillings@1315 4445 }
nickjillings@1315 4446
nickjillings@1315 4447 // Call the postDispatch hook for the mapped type
nickjillings@1315 4448 if ( special.postDispatch ) {
nickjillings@1315 4449 special.postDispatch.call( this, event );
nickjillings@1315 4450 }
nickjillings@1315 4451
nickjillings@1315 4452 return event.result;
nickjillings@1315 4453 },
nickjillings@1315 4454
nickjillings@1315 4455 handlers: function( event, handlers ) {
nickjillings@1315 4456 var i, matches, sel, handleObj,
nickjillings@1315 4457 handlerQueue = [],
nickjillings@1315 4458 delegateCount = handlers.delegateCount,
nickjillings@1315 4459 cur = event.target;
nickjillings@1315 4460
nickjillings@1315 4461 // Find delegate handlers
nickjillings@1315 4462 // Black-hole SVG <use> instance trees (#13180)
nickjillings@1315 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nickjillings@1315 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nickjillings@1315 4465
nickjillings@1315 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nickjillings@1315 4467
nickjillings@1315 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nickjillings@1315 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nickjillings@1315 4470 matches = [];
nickjillings@1315 4471 for ( i = 0; i < delegateCount; i++ ) {
nickjillings@1315 4472 handleObj = handlers[ i ];
nickjillings@1315 4473
nickjillings@1315 4474 // Don't conflict with Object.prototype properties (#13203)
nickjillings@1315 4475 sel = handleObj.selector + " ";
nickjillings@1315 4476
nickjillings@1315 4477 if ( matches[ sel ] === undefined ) {
nickjillings@1315 4478 matches[ sel ] = handleObj.needsContext ?
nickjillings@1315 4479 jQuery( sel, this ).index( cur ) >= 0 :
nickjillings@1315 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nickjillings@1315 4481 }
nickjillings@1315 4482 if ( matches[ sel ] ) {
nickjillings@1315 4483 matches.push( handleObj );
nickjillings@1315 4484 }
nickjillings@1315 4485 }
nickjillings@1315 4486 if ( matches.length ) {
nickjillings@1315 4487 handlerQueue.push({ elem: cur, handlers: matches });
nickjillings@1315 4488 }
nickjillings@1315 4489 }
nickjillings@1315 4490 }
nickjillings@1315 4491 }
nickjillings@1315 4492
nickjillings@1315 4493 // Add the remaining (directly-bound) handlers
nickjillings@1315 4494 if ( delegateCount < handlers.length ) {
nickjillings@1315 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nickjillings@1315 4496 }
nickjillings@1315 4497
nickjillings@1315 4498 return handlerQueue;
nickjillings@1315 4499 },
nickjillings@1315 4500
nickjillings@1315 4501 // Includes some event props shared by KeyEvent and MouseEvent
nickjillings@1315 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nickjillings@1315 4503
nickjillings@1315 4504 fixHooks: {},
nickjillings@1315 4505
nickjillings@1315 4506 keyHooks: {
nickjillings@1315 4507 props: "char charCode key keyCode".split(" "),
nickjillings@1315 4508 filter: function( event, original ) {
nickjillings@1315 4509
nickjillings@1315 4510 // Add which for key events
nickjillings@1315 4511 if ( event.which == null ) {
nickjillings@1315 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nickjillings@1315 4513 }
nickjillings@1315 4514
nickjillings@1315 4515 return event;
nickjillings@1315 4516 }
nickjillings@1315 4517 },
nickjillings@1315 4518
nickjillings@1315 4519 mouseHooks: {
nickjillings@1315 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nickjillings@1315 4521 filter: function( event, original ) {
nickjillings@1315 4522 var eventDoc, doc, body,
nickjillings@1315 4523 button = original.button;
nickjillings@1315 4524
nickjillings@1315 4525 // Calculate pageX/Y if missing and clientX/Y available
nickjillings@1315 4526 if ( event.pageX == null && original.clientX != null ) {
nickjillings@1315 4527 eventDoc = event.target.ownerDocument || document;
nickjillings@1315 4528 doc = eventDoc.documentElement;
nickjillings@1315 4529 body = eventDoc.body;
nickjillings@1315 4530
nickjillings@1315 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nickjillings@1315 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nickjillings@1315 4533 }
nickjillings@1315 4534
nickjillings@1315 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nickjillings@1315 4536 // Note: button is not normalized, so don't use it
nickjillings@1315 4537 if ( !event.which && button !== undefined ) {
nickjillings@1315 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nickjillings@1315 4539 }
nickjillings@1315 4540
nickjillings@1315 4541 return event;
nickjillings@1315 4542 }
nickjillings@1315 4543 },
nickjillings@1315 4544
nickjillings@1315 4545 fix: function( event ) {
nickjillings@1315 4546 if ( event[ jQuery.expando ] ) {
nickjillings@1315 4547 return event;
nickjillings@1315 4548 }
nickjillings@1315 4549
nickjillings@1315 4550 // Create a writable copy of the event object and normalize some properties
nickjillings@1315 4551 var i, prop, copy,
nickjillings@1315 4552 type = event.type,
nickjillings@1315 4553 originalEvent = event,
nickjillings@1315 4554 fixHook = this.fixHooks[ type ];
nickjillings@1315 4555
nickjillings@1315 4556 if ( !fixHook ) {
nickjillings@1315 4557 this.fixHooks[ type ] = fixHook =
nickjillings@1315 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nickjillings@1315 4559 rkeyEvent.test( type ) ? this.keyHooks :
nickjillings@1315 4560 {};
nickjillings@1315 4561 }
nickjillings@1315 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nickjillings@1315 4563
nickjillings@1315 4564 event = new jQuery.Event( originalEvent );
nickjillings@1315 4565
nickjillings@1315 4566 i = copy.length;
nickjillings@1315 4567 while ( i-- ) {
nickjillings@1315 4568 prop = copy[ i ];
nickjillings@1315 4569 event[ prop ] = originalEvent[ prop ];
nickjillings@1315 4570 }
nickjillings@1315 4571
nickjillings@1315 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nickjillings@1315 4573 // All events should have a target; Cordova deviceready doesn't
nickjillings@1315 4574 if ( !event.target ) {
nickjillings@1315 4575 event.target = document;
nickjillings@1315 4576 }
nickjillings@1315 4577
nickjillings@1315 4578 // Support: Safari 6.0+, Chrome<28
nickjillings@1315 4579 // Target should not be a text node (#504, #13143)
nickjillings@1315 4580 if ( event.target.nodeType === 3 ) {
nickjillings@1315 4581 event.target = event.target.parentNode;
nickjillings@1315 4582 }
nickjillings@1315 4583
nickjillings@1315 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nickjillings@1315 4585 },
nickjillings@1315 4586
nickjillings@1315 4587 special: {
nickjillings@1315 4588 load: {
nickjillings@1315 4589 // Prevent triggered image.load events from bubbling to window.load
nickjillings@1315 4590 noBubble: true
nickjillings@1315 4591 },
nickjillings@1315 4592 focus: {
nickjillings@1315 4593 // Fire native event if possible so blur/focus sequence is correct
nickjillings@1315 4594 trigger: function() {
nickjillings@1315 4595 if ( this !== safeActiveElement() && this.focus ) {
nickjillings@1315 4596 this.focus();
nickjillings@1315 4597 return false;
nickjillings@1315 4598 }
nickjillings@1315 4599 },
nickjillings@1315 4600 delegateType: "focusin"
nickjillings@1315 4601 },
nickjillings@1315 4602 blur: {
nickjillings@1315 4603 trigger: function() {
nickjillings@1315 4604 if ( this === safeActiveElement() && this.blur ) {
nickjillings@1315 4605 this.blur();
nickjillings@1315 4606 return false;
nickjillings@1315 4607 }
nickjillings@1315 4608 },
nickjillings@1315 4609 delegateType: "focusout"
nickjillings@1315 4610 },
nickjillings@1315 4611 click: {
nickjillings@1315 4612 // For checkbox, fire native event so checked state will be right
nickjillings@1315 4613 trigger: function() {
nickjillings@1315 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nickjillings@1315 4615 this.click();
nickjillings@1315 4616 return false;
nickjillings@1315 4617 }
nickjillings@1315 4618 },
nickjillings@1315 4619
nickjillings@1315 4620 // For cross-browser consistency, don't fire native .click() on links
nickjillings@1315 4621 _default: function( event ) {
nickjillings@1315 4622 return jQuery.nodeName( event.target, "a" );
nickjillings@1315 4623 }
nickjillings@1315 4624 },
nickjillings@1315 4625
nickjillings@1315 4626 beforeunload: {
nickjillings@1315 4627 postDispatch: function( event ) {
nickjillings@1315 4628
nickjillings@1315 4629 // Support: Firefox 20+
nickjillings@1315 4630 // Firefox doesn't alert if the returnValue field is not set.
nickjillings@1315 4631 if ( event.result !== undefined && event.originalEvent ) {
nickjillings@1315 4632 event.originalEvent.returnValue = event.result;
nickjillings@1315 4633 }
nickjillings@1315 4634 }
nickjillings@1315 4635 }
nickjillings@1315 4636 },
nickjillings@1315 4637
nickjillings@1315 4638 simulate: function( type, elem, event, bubble ) {
nickjillings@1315 4639 // Piggyback on a donor event to simulate a different one.
nickjillings@1315 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nickjillings@1315 4641 // simulated event prevents default then we do the same on the donor.
nickjillings@1315 4642 var e = jQuery.extend(
nickjillings@1315 4643 new jQuery.Event(),
nickjillings@1315 4644 event,
nickjillings@1315 4645 {
nickjillings@1315 4646 type: type,
nickjillings@1315 4647 isSimulated: true,
nickjillings@1315 4648 originalEvent: {}
nickjillings@1315 4649 }
nickjillings@1315 4650 );
nickjillings@1315 4651 if ( bubble ) {
nickjillings@1315 4652 jQuery.event.trigger( e, null, elem );
nickjillings@1315 4653 } else {
nickjillings@1315 4654 jQuery.event.dispatch.call( elem, e );
nickjillings@1315 4655 }
nickjillings@1315 4656 if ( e.isDefaultPrevented() ) {
nickjillings@1315 4657 event.preventDefault();
nickjillings@1315 4658 }
nickjillings@1315 4659 }
nickjillings@1315 4660 };
nickjillings@1315 4661
nickjillings@1315 4662 jQuery.removeEvent = function( elem, type, handle ) {
nickjillings@1315 4663 if ( elem.removeEventListener ) {
nickjillings@1315 4664 elem.removeEventListener( type, handle, false );
nickjillings@1315 4665 }
nickjillings@1315 4666 };
nickjillings@1315 4667
nickjillings@1315 4668 jQuery.Event = function( src, props ) {
nickjillings@1315 4669 // Allow instantiation without the 'new' keyword
nickjillings@1315 4670 if ( !(this instanceof jQuery.Event) ) {
nickjillings@1315 4671 return new jQuery.Event( src, props );
nickjillings@1315 4672 }
nickjillings@1315 4673
nickjillings@1315 4674 // Event object
nickjillings@1315 4675 if ( src && src.type ) {
nickjillings@1315 4676 this.originalEvent = src;
nickjillings@1315 4677 this.type = src.type;
nickjillings@1315 4678
nickjillings@1315 4679 // Events bubbling up the document may have been marked as prevented
nickjillings@1315 4680 // by a handler lower down the tree; reflect the correct value.
nickjillings@1315 4681 this.isDefaultPrevented = src.defaultPrevented ||
nickjillings@1315 4682 src.defaultPrevented === undefined &&
nickjillings@1315 4683 // Support: Android<4.0
nickjillings@1315 4684 src.returnValue === false ?
nickjillings@1315 4685 returnTrue :
nickjillings@1315 4686 returnFalse;
nickjillings@1315 4687
nickjillings@1315 4688 // Event type
nickjillings@1315 4689 } else {
nickjillings@1315 4690 this.type = src;
nickjillings@1315 4691 }
nickjillings@1315 4692
nickjillings@1315 4693 // Put explicitly provided properties onto the event object
nickjillings@1315 4694 if ( props ) {
nickjillings@1315 4695 jQuery.extend( this, props );
nickjillings@1315 4696 }
nickjillings@1315 4697
nickjillings@1315 4698 // Create a timestamp if incoming event doesn't have one
nickjillings@1315 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nickjillings@1315 4700
nickjillings@1315 4701 // Mark it as fixed
nickjillings@1315 4702 this[ jQuery.expando ] = true;
nickjillings@1315 4703 };
nickjillings@1315 4704
nickjillings@1315 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nickjillings@1315 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nickjillings@1315 4707 jQuery.Event.prototype = {
nickjillings@1315 4708 isDefaultPrevented: returnFalse,
nickjillings@1315 4709 isPropagationStopped: returnFalse,
nickjillings@1315 4710 isImmediatePropagationStopped: returnFalse,
nickjillings@1315 4711
nickjillings@1315 4712 preventDefault: function() {
nickjillings@1315 4713 var e = this.originalEvent;
nickjillings@1315 4714
nickjillings@1315 4715 this.isDefaultPrevented = returnTrue;
nickjillings@1315 4716
nickjillings@1315 4717 if ( e && e.preventDefault ) {
nickjillings@1315 4718 e.preventDefault();
nickjillings@1315 4719 }
nickjillings@1315 4720 },
nickjillings@1315 4721 stopPropagation: function() {
nickjillings@1315 4722 var e = this.originalEvent;
nickjillings@1315 4723
nickjillings@1315 4724 this.isPropagationStopped = returnTrue;
nickjillings@1315 4725
nickjillings@1315 4726 if ( e && e.stopPropagation ) {
nickjillings@1315 4727 e.stopPropagation();
nickjillings@1315 4728 }
nickjillings@1315 4729 },
nickjillings@1315 4730 stopImmediatePropagation: function() {
nickjillings@1315 4731 var e = this.originalEvent;
nickjillings@1315 4732
nickjillings@1315 4733 this.isImmediatePropagationStopped = returnTrue;
nickjillings@1315 4734
nickjillings@1315 4735 if ( e && e.stopImmediatePropagation ) {
nickjillings@1315 4736 e.stopImmediatePropagation();
nickjillings@1315 4737 }
nickjillings@1315 4738
nickjillings@1315 4739 this.stopPropagation();
nickjillings@1315 4740 }
nickjillings@1315 4741 };
nickjillings@1315 4742
nickjillings@1315 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nickjillings@1315 4744 // Support: Chrome 15+
nickjillings@1315 4745 jQuery.each({
nickjillings@1315 4746 mouseenter: "mouseover",
nickjillings@1315 4747 mouseleave: "mouseout",
nickjillings@1315 4748 pointerenter: "pointerover",
nickjillings@1315 4749 pointerleave: "pointerout"
nickjillings@1315 4750 }, function( orig, fix ) {
nickjillings@1315 4751 jQuery.event.special[ orig ] = {
nickjillings@1315 4752 delegateType: fix,
nickjillings@1315 4753 bindType: fix,
nickjillings@1315 4754
nickjillings@1315 4755 handle: function( event ) {
nickjillings@1315 4756 var ret,
nickjillings@1315 4757 target = this,
nickjillings@1315 4758 related = event.relatedTarget,
nickjillings@1315 4759 handleObj = event.handleObj;
nickjillings@1315 4760
nickjillings@1315 4761 // For mousenter/leave call the handler if related is outside the target.
nickjillings@1315 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nickjillings@1315 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nickjillings@1315 4764 event.type = handleObj.origType;
nickjillings@1315 4765 ret = handleObj.handler.apply( this, arguments );
nickjillings@1315 4766 event.type = fix;
nickjillings@1315 4767 }
nickjillings@1315 4768 return ret;
nickjillings@1315 4769 }
nickjillings@1315 4770 };
nickjillings@1315 4771 });
nickjillings@1315 4772
nickjillings@1315 4773 // Support: Firefox, Chrome, Safari
nickjillings@1315 4774 // Create "bubbling" focus and blur events
nickjillings@1315 4775 if ( !support.focusinBubbles ) {
nickjillings@1315 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nickjillings@1315 4777
nickjillings@1315 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nickjillings@1315 4779 var handler = function( event ) {
nickjillings@1315 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nickjillings@1315 4781 };
nickjillings@1315 4782
nickjillings@1315 4783 jQuery.event.special[ fix ] = {
nickjillings@1315 4784 setup: function() {
nickjillings@1315 4785 var doc = this.ownerDocument || this,
nickjillings@1315 4786 attaches = data_priv.access( doc, fix );
nickjillings@1315 4787
nickjillings@1315 4788 if ( !attaches ) {
nickjillings@1315 4789 doc.addEventListener( orig, handler, true );
nickjillings@1315 4790 }
nickjillings@1315 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nickjillings@1315 4792 },
nickjillings@1315 4793 teardown: function() {
nickjillings@1315 4794 var doc = this.ownerDocument || this,
nickjillings@1315 4795 attaches = data_priv.access( doc, fix ) - 1;
nickjillings@1315 4796
nickjillings@1315 4797 if ( !attaches ) {
nickjillings@1315 4798 doc.removeEventListener( orig, handler, true );
nickjillings@1315 4799 data_priv.remove( doc, fix );
nickjillings@1315 4800
nickjillings@1315 4801 } else {
nickjillings@1315 4802 data_priv.access( doc, fix, attaches );
nickjillings@1315 4803 }
nickjillings@1315 4804 }
nickjillings@1315 4805 };
nickjillings@1315 4806 });
nickjillings@1315 4807 }
nickjillings@1315 4808
nickjillings@1315 4809 jQuery.fn.extend({
nickjillings@1315 4810
nickjillings@1315 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nickjillings@1315 4812 var origFn, type;
nickjillings@1315 4813
nickjillings@1315 4814 // Types can be a map of types/handlers
nickjillings@1315 4815 if ( typeof types === "object" ) {
nickjillings@1315 4816 // ( types-Object, selector, data )
nickjillings@1315 4817 if ( typeof selector !== "string" ) {
nickjillings@1315 4818 // ( types-Object, data )
nickjillings@1315 4819 data = data || selector;
nickjillings@1315 4820 selector = undefined;
nickjillings@1315 4821 }
nickjillings@1315 4822 for ( type in types ) {
nickjillings@1315 4823 this.on( type, selector, data, types[ type ], one );
nickjillings@1315 4824 }
nickjillings@1315 4825 return this;
nickjillings@1315 4826 }
nickjillings@1315 4827
nickjillings@1315 4828 if ( data == null && fn == null ) {
nickjillings@1315 4829 // ( types, fn )
nickjillings@1315 4830 fn = selector;
nickjillings@1315 4831 data = selector = undefined;
nickjillings@1315 4832 } else if ( fn == null ) {
nickjillings@1315 4833 if ( typeof selector === "string" ) {
nickjillings@1315 4834 // ( types, selector, fn )
nickjillings@1315 4835 fn = data;
nickjillings@1315 4836 data = undefined;
nickjillings@1315 4837 } else {
nickjillings@1315 4838 // ( types, data, fn )
nickjillings@1315 4839 fn = data;
nickjillings@1315 4840 data = selector;
nickjillings@1315 4841 selector = undefined;
nickjillings@1315 4842 }
nickjillings@1315 4843 }
nickjillings@1315 4844 if ( fn === false ) {
nickjillings@1315 4845 fn = returnFalse;
nickjillings@1315 4846 } else if ( !fn ) {
nickjillings@1315 4847 return this;
nickjillings@1315 4848 }
nickjillings@1315 4849
nickjillings@1315 4850 if ( one === 1 ) {
nickjillings@1315 4851 origFn = fn;
nickjillings@1315 4852 fn = function( event ) {
nickjillings@1315 4853 // Can use an empty set, since event contains the info
nickjillings@1315 4854 jQuery().off( event );
nickjillings@1315 4855 return origFn.apply( this, arguments );
nickjillings@1315 4856 };
nickjillings@1315 4857 // Use same guid so caller can remove using origFn
nickjillings@1315 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nickjillings@1315 4859 }
nickjillings@1315 4860 return this.each( function() {
nickjillings@1315 4861 jQuery.event.add( this, types, fn, data, selector );
nickjillings@1315 4862 });
nickjillings@1315 4863 },
nickjillings@1315 4864 one: function( types, selector, data, fn ) {
nickjillings@1315 4865 return this.on( types, selector, data, fn, 1 );
nickjillings@1315 4866 },
nickjillings@1315 4867 off: function( types, selector, fn ) {
nickjillings@1315 4868 var handleObj, type;
nickjillings@1315 4869 if ( types && types.preventDefault && types.handleObj ) {
nickjillings@1315 4870 // ( event ) dispatched jQuery.Event
nickjillings@1315 4871 handleObj = types.handleObj;
nickjillings@1315 4872 jQuery( types.delegateTarget ).off(
nickjillings@1315 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nickjillings@1315 4874 handleObj.selector,
nickjillings@1315 4875 handleObj.handler
nickjillings@1315 4876 );
nickjillings@1315 4877 return this;
nickjillings@1315 4878 }
nickjillings@1315 4879 if ( typeof types === "object" ) {
nickjillings@1315 4880 // ( types-object [, selector] )
nickjillings@1315 4881 for ( type in types ) {
nickjillings@1315 4882 this.off( type, selector, types[ type ] );
nickjillings@1315 4883 }
nickjillings@1315 4884 return this;
nickjillings@1315 4885 }
nickjillings@1315 4886 if ( selector === false || typeof selector === "function" ) {
nickjillings@1315 4887 // ( types [, fn] )
nickjillings@1315 4888 fn = selector;
nickjillings@1315 4889 selector = undefined;
nickjillings@1315 4890 }
nickjillings@1315 4891 if ( fn === false ) {
nickjillings@1315 4892 fn = returnFalse;
nickjillings@1315 4893 }
nickjillings@1315 4894 return this.each(function() {
nickjillings@1315 4895 jQuery.event.remove( this, types, fn, selector );
nickjillings@1315 4896 });
nickjillings@1315 4897 },
nickjillings@1315 4898
nickjillings@1315 4899 trigger: function( type, data ) {
nickjillings@1315 4900 return this.each(function() {
nickjillings@1315 4901 jQuery.event.trigger( type, data, this );
nickjillings@1315 4902 });
nickjillings@1315 4903 },
nickjillings@1315 4904 triggerHandler: function( type, data ) {
nickjillings@1315 4905 var elem = this[0];
nickjillings@1315 4906 if ( elem ) {
nickjillings@1315 4907 return jQuery.event.trigger( type, data, elem, true );
nickjillings@1315 4908 }
nickjillings@1315 4909 }
nickjillings@1315 4910 });
nickjillings@1315 4911
nickjillings@1315 4912
nickjillings@1315 4913 var
nickjillings@1315 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nickjillings@1315 4915 rtagName = /<([\w:]+)/,
nickjillings@1315 4916 rhtml = /<|&#?\w+;/,
nickjillings@1315 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nickjillings@1315 4918 // checked="checked" or checked
nickjillings@1315 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nickjillings@1315 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nickjillings@1315 4921 rscriptTypeMasked = /^true\/(.*)/,
nickjillings@1315 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nickjillings@1315 4923
nickjillings@1315 4924 // We have to close these tags to support XHTML (#13200)
nickjillings@1315 4925 wrapMap = {
nickjillings@1315 4926
nickjillings@1315 4927 // Support: IE9
nickjillings@1315 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nickjillings@1315 4929
nickjillings@1315 4930 thead: [ 1, "<table>", "</table>" ],
nickjillings@1315 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nickjillings@1315 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nickjillings@1315 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nickjillings@1315 4934
nickjillings@1315 4935 _default: [ 0, "", "" ]
nickjillings@1315 4936 };
nickjillings@1315 4937
nickjillings@1315 4938 // Support: IE9
nickjillings@1315 4939 wrapMap.optgroup = wrapMap.option;
nickjillings@1315 4940
nickjillings@1315 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nickjillings@1315 4942 wrapMap.th = wrapMap.td;
nickjillings@1315 4943
nickjillings@1315 4944 // Support: 1.x compatibility
nickjillings@1315 4945 // Manipulating tables requires a tbody
nickjillings@1315 4946 function manipulationTarget( elem, content ) {
nickjillings@1315 4947 return jQuery.nodeName( elem, "table" ) &&
nickjillings@1315 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nickjillings@1315 4949
nickjillings@1315 4950 elem.getElementsByTagName("tbody")[0] ||
nickjillings@1315 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nickjillings@1315 4952 elem;
nickjillings@1315 4953 }
nickjillings@1315 4954
nickjillings@1315 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nickjillings@1315 4956 function disableScript( elem ) {
nickjillings@1315 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nickjillings@1315 4958 return elem;
nickjillings@1315 4959 }
nickjillings@1315 4960 function restoreScript( elem ) {
nickjillings@1315 4961 var match = rscriptTypeMasked.exec( elem.type );
nickjillings@1315 4962
nickjillings@1315 4963 if ( match ) {
nickjillings@1315 4964 elem.type = match[ 1 ];
nickjillings@1315 4965 } else {
nickjillings@1315 4966 elem.removeAttribute("type");
nickjillings@1315 4967 }
nickjillings@1315 4968
nickjillings@1315 4969 return elem;
nickjillings@1315 4970 }
nickjillings@1315 4971
nickjillings@1315 4972 // Mark scripts as having already been evaluated
nickjillings@1315 4973 function setGlobalEval( elems, refElements ) {
nickjillings@1315 4974 var i = 0,
nickjillings@1315 4975 l = elems.length;
nickjillings@1315 4976
nickjillings@1315 4977 for ( ; i < l; i++ ) {
nickjillings@1315 4978 data_priv.set(
nickjillings@1315 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nickjillings@1315 4980 );
nickjillings@1315 4981 }
nickjillings@1315 4982 }
nickjillings@1315 4983
nickjillings@1315 4984 function cloneCopyEvent( src, dest ) {
nickjillings@1315 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nickjillings@1315 4986
nickjillings@1315 4987 if ( dest.nodeType !== 1 ) {
nickjillings@1315 4988 return;
nickjillings@1315 4989 }
nickjillings@1315 4990
nickjillings@1315 4991 // 1. Copy private data: events, handlers, etc.
nickjillings@1315 4992 if ( data_priv.hasData( src ) ) {
nickjillings@1315 4993 pdataOld = data_priv.access( src );
nickjillings@1315 4994 pdataCur = data_priv.set( dest, pdataOld );
nickjillings@1315 4995 events = pdataOld.events;
nickjillings@1315 4996
nickjillings@1315 4997 if ( events ) {
nickjillings@1315 4998 delete pdataCur.handle;
nickjillings@1315 4999 pdataCur.events = {};
nickjillings@1315 5000
nickjillings@1315 5001 for ( type in events ) {
nickjillings@1315 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nickjillings@1315 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nickjillings@1315 5004 }
nickjillings@1315 5005 }
nickjillings@1315 5006 }
nickjillings@1315 5007 }
nickjillings@1315 5008
nickjillings@1315 5009 // 2. Copy user data
nickjillings@1315 5010 if ( data_user.hasData( src ) ) {
nickjillings@1315 5011 udataOld = data_user.access( src );
nickjillings@1315 5012 udataCur = jQuery.extend( {}, udataOld );
nickjillings@1315 5013
nickjillings@1315 5014 data_user.set( dest, udataCur );
nickjillings@1315 5015 }
nickjillings@1315 5016 }
nickjillings@1315 5017
nickjillings@1315 5018 function getAll( context, tag ) {
nickjillings@1315 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nickjillings@1315 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nickjillings@1315 5021 [];
nickjillings@1315 5022
nickjillings@1315 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nickjillings@1315 5024 jQuery.merge( [ context ], ret ) :
nickjillings@1315 5025 ret;
nickjillings@1315 5026 }
nickjillings@1315 5027
nickjillings@1315 5028 // Fix IE bugs, see support tests
nickjillings@1315 5029 function fixInput( src, dest ) {
nickjillings@1315 5030 var nodeName = dest.nodeName.toLowerCase();
nickjillings@1315 5031
nickjillings@1315 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nickjillings@1315 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nickjillings@1315 5034 dest.checked = src.checked;
nickjillings@1315 5035
nickjillings@1315 5036 // Fails to return the selected option to the default selected state when cloning options
nickjillings@1315 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nickjillings@1315 5038 dest.defaultValue = src.defaultValue;
nickjillings@1315 5039 }
nickjillings@1315 5040 }
nickjillings@1315 5041
nickjillings@1315 5042 jQuery.extend({
nickjillings@1315 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nickjillings@1315 5044 var i, l, srcElements, destElements,
nickjillings@1315 5045 clone = elem.cloneNode( true ),
nickjillings@1315 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1315 5047
nickjillings@1315 5048 // Fix IE cloning issues
nickjillings@1315 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nickjillings@1315 5050 !jQuery.isXMLDoc( elem ) ) {
nickjillings@1315 5051
nickjillings@1315 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nickjillings@1315 5053 destElements = getAll( clone );
nickjillings@1315 5054 srcElements = getAll( elem );
nickjillings@1315 5055
nickjillings@1315 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1315 5057 fixInput( srcElements[ i ], destElements[ i ] );
nickjillings@1315 5058 }
nickjillings@1315 5059 }
nickjillings@1315 5060
nickjillings@1315 5061 // Copy the events from the original to the clone
nickjillings@1315 5062 if ( dataAndEvents ) {
nickjillings@1315 5063 if ( deepDataAndEvents ) {
nickjillings@1315 5064 srcElements = srcElements || getAll( elem );
nickjillings@1315 5065 destElements = destElements || getAll( clone );
nickjillings@1315 5066
nickjillings@1315 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1315 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nickjillings@1315 5069 }
nickjillings@1315 5070 } else {
nickjillings@1315 5071 cloneCopyEvent( elem, clone );
nickjillings@1315 5072 }
nickjillings@1315 5073 }
nickjillings@1315 5074
nickjillings@1315 5075 // Preserve script evaluation history
nickjillings@1315 5076 destElements = getAll( clone, "script" );
nickjillings@1315 5077 if ( destElements.length > 0 ) {
nickjillings@1315 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nickjillings@1315 5079 }
nickjillings@1315 5080
nickjillings@1315 5081 // Return the cloned set
nickjillings@1315 5082 return clone;
nickjillings@1315 5083 },
nickjillings@1315 5084
nickjillings@1315 5085 buildFragment: function( elems, context, scripts, selection ) {
nickjillings@1315 5086 var elem, tmp, tag, wrap, contains, j,
nickjillings@1315 5087 fragment = context.createDocumentFragment(),
nickjillings@1315 5088 nodes = [],
nickjillings@1315 5089 i = 0,
nickjillings@1315 5090 l = elems.length;
nickjillings@1315 5091
nickjillings@1315 5092 for ( ; i < l; i++ ) {
nickjillings@1315 5093 elem = elems[ i ];
nickjillings@1315 5094
nickjillings@1315 5095 if ( elem || elem === 0 ) {
nickjillings@1315 5096
nickjillings@1315 5097 // Add nodes directly
nickjillings@1315 5098 if ( jQuery.type( elem ) === "object" ) {
nickjillings@1315 5099 // Support: QtWebKit, PhantomJS
nickjillings@1315 5100 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1315 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nickjillings@1315 5102
nickjillings@1315 5103 // Convert non-html into a text node
nickjillings@1315 5104 } else if ( !rhtml.test( elem ) ) {
nickjillings@1315 5105 nodes.push( context.createTextNode( elem ) );
nickjillings@1315 5106
nickjillings@1315 5107 // Convert html into DOM nodes
nickjillings@1315 5108 } else {
nickjillings@1315 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nickjillings@1315 5110
nickjillings@1315 5111 // Deserialize a standard representation
nickjillings@1315 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nickjillings@1315 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nickjillings@1315 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nickjillings@1315 5115
nickjillings@1315 5116 // Descend through wrappers to the right content
nickjillings@1315 5117 j = wrap[ 0 ];
nickjillings@1315 5118 while ( j-- ) {
nickjillings@1315 5119 tmp = tmp.lastChild;
nickjillings@1315 5120 }
nickjillings@1315 5121
nickjillings@1315 5122 // Support: QtWebKit, PhantomJS
nickjillings@1315 5123 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1315 5124 jQuery.merge( nodes, tmp.childNodes );
nickjillings@1315 5125
nickjillings@1315 5126 // Remember the top-level container
nickjillings@1315 5127 tmp = fragment.firstChild;
nickjillings@1315 5128
nickjillings@1315 5129 // Ensure the created nodes are orphaned (#12392)
nickjillings@1315 5130 tmp.textContent = "";
nickjillings@1315 5131 }
nickjillings@1315 5132 }
nickjillings@1315 5133 }
nickjillings@1315 5134
nickjillings@1315 5135 // Remove wrapper from fragment
nickjillings@1315 5136 fragment.textContent = "";
nickjillings@1315 5137
nickjillings@1315 5138 i = 0;
nickjillings@1315 5139 while ( (elem = nodes[ i++ ]) ) {
nickjillings@1315 5140
nickjillings@1315 5141 // #4087 - If origin and destination elements are the same, and this is
nickjillings@1315 5142 // that element, do not do anything
nickjillings@1315 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nickjillings@1315 5144 continue;
nickjillings@1315 5145 }
nickjillings@1315 5146
nickjillings@1315 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1315 5148
nickjillings@1315 5149 // Append to fragment
nickjillings@1315 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nickjillings@1315 5151
nickjillings@1315 5152 // Preserve script evaluation history
nickjillings@1315 5153 if ( contains ) {
nickjillings@1315 5154 setGlobalEval( tmp );
nickjillings@1315 5155 }
nickjillings@1315 5156
nickjillings@1315 5157 // Capture executables
nickjillings@1315 5158 if ( scripts ) {
nickjillings@1315 5159 j = 0;
nickjillings@1315 5160 while ( (elem = tmp[ j++ ]) ) {
nickjillings@1315 5161 if ( rscriptType.test( elem.type || "" ) ) {
nickjillings@1315 5162 scripts.push( elem );
nickjillings@1315 5163 }
nickjillings@1315 5164 }
nickjillings@1315 5165 }
nickjillings@1315 5166 }
nickjillings@1315 5167
nickjillings@1315 5168 return fragment;
nickjillings@1315 5169 },
nickjillings@1315 5170
nickjillings@1315 5171 cleanData: function( elems ) {
nickjillings@1315 5172 var data, elem, type, key,
nickjillings@1315 5173 special = jQuery.event.special,
nickjillings@1315 5174 i = 0;
nickjillings@1315 5175
nickjillings@1315 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nickjillings@1315 5177 if ( jQuery.acceptData( elem ) ) {
nickjillings@1315 5178 key = elem[ data_priv.expando ];
nickjillings@1315 5179
nickjillings@1315 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nickjillings@1315 5181 if ( data.events ) {
nickjillings@1315 5182 for ( type in data.events ) {
nickjillings@1315 5183 if ( special[ type ] ) {
nickjillings@1315 5184 jQuery.event.remove( elem, type );
nickjillings@1315 5185
nickjillings@1315 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nickjillings@1315 5187 } else {
nickjillings@1315 5188 jQuery.removeEvent( elem, type, data.handle );
nickjillings@1315 5189 }
nickjillings@1315 5190 }
nickjillings@1315 5191 }
nickjillings@1315 5192 if ( data_priv.cache[ key ] ) {
nickjillings@1315 5193 // Discard any remaining `private` data
nickjillings@1315 5194 delete data_priv.cache[ key ];
nickjillings@1315 5195 }
nickjillings@1315 5196 }
nickjillings@1315 5197 }
nickjillings@1315 5198 // Discard any remaining `user` data
nickjillings@1315 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nickjillings@1315 5200 }
nickjillings@1315 5201 }
nickjillings@1315 5202 });
nickjillings@1315 5203
nickjillings@1315 5204 jQuery.fn.extend({
nickjillings@1315 5205 text: function( value ) {
nickjillings@1315 5206 return access( this, function( value ) {
nickjillings@1315 5207 return value === undefined ?
nickjillings@1315 5208 jQuery.text( this ) :
nickjillings@1315 5209 this.empty().each(function() {
nickjillings@1315 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1315 5211 this.textContent = value;
nickjillings@1315 5212 }
nickjillings@1315 5213 });
nickjillings@1315 5214 }, null, value, arguments.length );
nickjillings@1315 5215 },
nickjillings@1315 5216
nickjillings@1315 5217 append: function() {
nickjillings@1315 5218 return this.domManip( arguments, function( elem ) {
nickjillings@1315 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1315 5220 var target = manipulationTarget( this, elem );
nickjillings@1315 5221 target.appendChild( elem );
nickjillings@1315 5222 }
nickjillings@1315 5223 });
nickjillings@1315 5224 },
nickjillings@1315 5225
nickjillings@1315 5226 prepend: function() {
nickjillings@1315 5227 return this.domManip( arguments, function( elem ) {
nickjillings@1315 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1315 5229 var target = manipulationTarget( this, elem );
nickjillings@1315 5230 target.insertBefore( elem, target.firstChild );
nickjillings@1315 5231 }
nickjillings@1315 5232 });
nickjillings@1315 5233 },
nickjillings@1315 5234
nickjillings@1315 5235 before: function() {
nickjillings@1315 5236 return this.domManip( arguments, function( elem ) {
nickjillings@1315 5237 if ( this.parentNode ) {
nickjillings@1315 5238 this.parentNode.insertBefore( elem, this );
nickjillings@1315 5239 }
nickjillings@1315 5240 });
nickjillings@1315 5241 },
nickjillings@1315 5242
nickjillings@1315 5243 after: function() {
nickjillings@1315 5244 return this.domManip( arguments, function( elem ) {
nickjillings@1315 5245 if ( this.parentNode ) {
nickjillings@1315 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nickjillings@1315 5247 }
nickjillings@1315 5248 });
nickjillings@1315 5249 },
nickjillings@1315 5250
nickjillings@1315 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nickjillings@1315 5252 var elem,
nickjillings@1315 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nickjillings@1315 5254 i = 0;
nickjillings@1315 5255
nickjillings@1315 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nickjillings@1315 5257 if ( !keepData && elem.nodeType === 1 ) {
nickjillings@1315 5258 jQuery.cleanData( getAll( elem ) );
nickjillings@1315 5259 }
nickjillings@1315 5260
nickjillings@1315 5261 if ( elem.parentNode ) {
nickjillings@1315 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1315 5263 setGlobalEval( getAll( elem, "script" ) );
nickjillings@1315 5264 }
nickjillings@1315 5265 elem.parentNode.removeChild( elem );
nickjillings@1315 5266 }
nickjillings@1315 5267 }
nickjillings@1315 5268
nickjillings@1315 5269 return this;
nickjillings@1315 5270 },
nickjillings@1315 5271
nickjillings@1315 5272 empty: function() {
nickjillings@1315 5273 var elem,
nickjillings@1315 5274 i = 0;
nickjillings@1315 5275
nickjillings@1315 5276 for ( ; (elem = this[i]) != null; i++ ) {
nickjillings@1315 5277 if ( elem.nodeType === 1 ) {
nickjillings@1315 5278
nickjillings@1315 5279 // Prevent memory leaks
nickjillings@1315 5280 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1315 5281
nickjillings@1315 5282 // Remove any remaining nodes
nickjillings@1315 5283 elem.textContent = "";
nickjillings@1315 5284 }
nickjillings@1315 5285 }
nickjillings@1315 5286
nickjillings@1315 5287 return this;
nickjillings@1315 5288 },
nickjillings@1315 5289
nickjillings@1315 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nickjillings@1315 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nickjillings@1315 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nickjillings@1315 5293
nickjillings@1315 5294 return this.map(function() {
nickjillings@1315 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nickjillings@1315 5296 });
nickjillings@1315 5297 },
nickjillings@1315 5298
nickjillings@1315 5299 html: function( value ) {
nickjillings@1315 5300 return access( this, function( value ) {
nickjillings@1315 5301 var elem = this[ 0 ] || {},
nickjillings@1315 5302 i = 0,
nickjillings@1315 5303 l = this.length;
nickjillings@1315 5304
nickjillings@1315 5305 if ( value === undefined && elem.nodeType === 1 ) {
nickjillings@1315 5306 return elem.innerHTML;
nickjillings@1315 5307 }
nickjillings@1315 5308
nickjillings@1315 5309 // See if we can take a shortcut and just use innerHTML
nickjillings@1315 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nickjillings@1315 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nickjillings@1315 5312
nickjillings@1315 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nickjillings@1315 5314
nickjillings@1315 5315 try {
nickjillings@1315 5316 for ( ; i < l; i++ ) {
nickjillings@1315 5317 elem = this[ i ] || {};
nickjillings@1315 5318
nickjillings@1315 5319 // Remove element nodes and prevent memory leaks
nickjillings@1315 5320 if ( elem.nodeType === 1 ) {
nickjillings@1315 5321 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1315 5322 elem.innerHTML = value;
nickjillings@1315 5323 }
nickjillings@1315 5324 }
nickjillings@1315 5325
nickjillings@1315 5326 elem = 0;
nickjillings@1315 5327
nickjillings@1315 5328 // If using innerHTML throws an exception, use the fallback method
nickjillings@1315 5329 } catch( e ) {}
nickjillings@1315 5330 }
nickjillings@1315 5331
nickjillings@1315 5332 if ( elem ) {
nickjillings@1315 5333 this.empty().append( value );
nickjillings@1315 5334 }
nickjillings@1315 5335 }, null, value, arguments.length );
nickjillings@1315 5336 },
nickjillings@1315 5337
nickjillings@1315 5338 replaceWith: function() {
nickjillings@1315 5339 var arg = arguments[ 0 ];
nickjillings@1315 5340
nickjillings@1315 5341 // Make the changes, replacing each context element with the new content
nickjillings@1315 5342 this.domManip( arguments, function( elem ) {
nickjillings@1315 5343 arg = this.parentNode;
nickjillings@1315 5344
nickjillings@1315 5345 jQuery.cleanData( getAll( this ) );
nickjillings@1315 5346
nickjillings@1315 5347 if ( arg ) {
nickjillings@1315 5348 arg.replaceChild( elem, this );
nickjillings@1315 5349 }
nickjillings@1315 5350 });
nickjillings@1315 5351
nickjillings@1315 5352 // Force removal if there was no new content (e.g., from empty arguments)
nickjillings@1315 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nickjillings@1315 5354 },
nickjillings@1315 5355
nickjillings@1315 5356 detach: function( selector ) {
nickjillings@1315 5357 return this.remove( selector, true );
nickjillings@1315 5358 },
nickjillings@1315 5359
nickjillings@1315 5360 domManip: function( args, callback ) {
nickjillings@1315 5361
nickjillings@1315 5362 // Flatten any nested arrays
nickjillings@1315 5363 args = concat.apply( [], args );
nickjillings@1315 5364
nickjillings@1315 5365 var fragment, first, scripts, hasScripts, node, doc,
nickjillings@1315 5366 i = 0,
nickjillings@1315 5367 l = this.length,
nickjillings@1315 5368 set = this,
nickjillings@1315 5369 iNoClone = l - 1,
nickjillings@1315 5370 value = args[ 0 ],
nickjillings@1315 5371 isFunction = jQuery.isFunction( value );
nickjillings@1315 5372
nickjillings@1315 5373 // We can't cloneNode fragments that contain checked, in WebKit
nickjillings@1315 5374 if ( isFunction ||
nickjillings@1315 5375 ( l > 1 && typeof value === "string" &&
nickjillings@1315 5376 !support.checkClone && rchecked.test( value ) ) ) {
nickjillings@1315 5377 return this.each(function( index ) {
nickjillings@1315 5378 var self = set.eq( index );
nickjillings@1315 5379 if ( isFunction ) {
nickjillings@1315 5380 args[ 0 ] = value.call( this, index, self.html() );
nickjillings@1315 5381 }
nickjillings@1315 5382 self.domManip( args, callback );
nickjillings@1315 5383 });
nickjillings@1315 5384 }
nickjillings@1315 5385
nickjillings@1315 5386 if ( l ) {
nickjillings@1315 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nickjillings@1315 5388 first = fragment.firstChild;
nickjillings@1315 5389
nickjillings@1315 5390 if ( fragment.childNodes.length === 1 ) {
nickjillings@1315 5391 fragment = first;
nickjillings@1315 5392 }
nickjillings@1315 5393
nickjillings@1315 5394 if ( first ) {
nickjillings@1315 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nickjillings@1315 5396 hasScripts = scripts.length;
nickjillings@1315 5397
nickjillings@1315 5398 // Use the original fragment for the last item instead of the first because it can end up
nickjillings@1315 5399 // being emptied incorrectly in certain situations (#8070).
nickjillings@1315 5400 for ( ; i < l; i++ ) {
nickjillings@1315 5401 node = fragment;
nickjillings@1315 5402
nickjillings@1315 5403 if ( i !== iNoClone ) {
nickjillings@1315 5404 node = jQuery.clone( node, true, true );
nickjillings@1315 5405
nickjillings@1315 5406 // Keep references to cloned scripts for later restoration
nickjillings@1315 5407 if ( hasScripts ) {
nickjillings@1315 5408 // Support: QtWebKit
nickjillings@1315 5409 // jQuery.merge because push.apply(_, arraylike) throws
nickjillings@1315 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nickjillings@1315 5411 }
nickjillings@1315 5412 }
nickjillings@1315 5413
nickjillings@1315 5414 callback.call( this[ i ], node, i );
nickjillings@1315 5415 }
nickjillings@1315 5416
nickjillings@1315 5417 if ( hasScripts ) {
nickjillings@1315 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nickjillings@1315 5419
nickjillings@1315 5420 // Reenable scripts
nickjillings@1315 5421 jQuery.map( scripts, restoreScript );
nickjillings@1315 5422
nickjillings@1315 5423 // Evaluate executable scripts on first document insertion
nickjillings@1315 5424 for ( i = 0; i < hasScripts; i++ ) {
nickjillings@1315 5425 node = scripts[ i ];
nickjillings@1315 5426 if ( rscriptType.test( node.type || "" ) &&
nickjillings@1315 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nickjillings@1315 5428
nickjillings@1315 5429 if ( node.src ) {
nickjillings@1315 5430 // Optional AJAX dependency, but won't run scripts if not present
nickjillings@1315 5431 if ( jQuery._evalUrl ) {
nickjillings@1315 5432 jQuery._evalUrl( node.src );
nickjillings@1315 5433 }
nickjillings@1315 5434 } else {
nickjillings@1315 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nickjillings@1315 5436 }
nickjillings@1315 5437 }
nickjillings@1315 5438 }
nickjillings@1315 5439 }
nickjillings@1315 5440 }
nickjillings@1315 5441 }
nickjillings@1315 5442
nickjillings@1315 5443 return this;
nickjillings@1315 5444 }
nickjillings@1315 5445 });
nickjillings@1315 5446
nickjillings@1315 5447 jQuery.each({
nickjillings@1315 5448 appendTo: "append",
nickjillings@1315 5449 prependTo: "prepend",
nickjillings@1315 5450 insertBefore: "before",
nickjillings@1315 5451 insertAfter: "after",
nickjillings@1315 5452 replaceAll: "replaceWith"
nickjillings@1315 5453 }, function( name, original ) {
nickjillings@1315 5454 jQuery.fn[ name ] = function( selector ) {
nickjillings@1315 5455 var elems,
nickjillings@1315 5456 ret = [],
nickjillings@1315 5457 insert = jQuery( selector ),
nickjillings@1315 5458 last = insert.length - 1,
nickjillings@1315 5459 i = 0;
nickjillings@1315 5460
nickjillings@1315 5461 for ( ; i <= last; i++ ) {
nickjillings@1315 5462 elems = i === last ? this : this.clone( true );
nickjillings@1315 5463 jQuery( insert[ i ] )[ original ]( elems );
nickjillings@1315 5464
nickjillings@1315 5465 // Support: QtWebKit
nickjillings@1315 5466 // .get() because push.apply(_, arraylike) throws
nickjillings@1315 5467 push.apply( ret, elems.get() );
nickjillings@1315 5468 }
nickjillings@1315 5469
nickjillings@1315 5470 return this.pushStack( ret );
nickjillings@1315 5471 };
nickjillings@1315 5472 });
nickjillings@1315 5473
nickjillings@1315 5474
nickjillings@1315 5475 var iframe,
nickjillings@1315 5476 elemdisplay = {};
nickjillings@1315 5477
nickjillings@1315 5478 /**
nickjillings@1315 5479 * Retrieve the actual display of a element
nickjillings@1315 5480 * @param {String} name nodeName of the element
nickjillings@1315 5481 * @param {Object} doc Document object
nickjillings@1315 5482 */
nickjillings@1315 5483 // Called only from within defaultDisplay
nickjillings@1315 5484 function actualDisplay( name, doc ) {
nickjillings@1315 5485 var style,
nickjillings@1315 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nickjillings@1315 5487
nickjillings@1315 5488 // getDefaultComputedStyle might be reliably used only on attached element
nickjillings@1315 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nickjillings@1315 5490
nickjillings@1315 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nickjillings@1315 5492 // since it was removed from specification and supported only in FF
nickjillings@1315 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nickjillings@1315 5494
nickjillings@1315 5495 // We don't have any data stored on the element,
nickjillings@1315 5496 // so use "detach" method as fast way to get rid of the element
nickjillings@1315 5497 elem.detach();
nickjillings@1315 5498
nickjillings@1315 5499 return display;
nickjillings@1315 5500 }
nickjillings@1315 5501
nickjillings@1315 5502 /**
nickjillings@1315 5503 * Try to determine the default display value of an element
nickjillings@1315 5504 * @param {String} nodeName
nickjillings@1315 5505 */
nickjillings@1315 5506 function defaultDisplay( nodeName ) {
nickjillings@1315 5507 var doc = document,
nickjillings@1315 5508 display = elemdisplay[ nodeName ];
nickjillings@1315 5509
nickjillings@1315 5510 if ( !display ) {
nickjillings@1315 5511 display = actualDisplay( nodeName, doc );
nickjillings@1315 5512
nickjillings@1315 5513 // If the simple way fails, read from inside an iframe
nickjillings@1315 5514 if ( display === "none" || !display ) {
nickjillings@1315 5515
nickjillings@1315 5516 // Use the already-created iframe if possible
nickjillings@1315 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nickjillings@1315 5518
nickjillings@1315 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nickjillings@1315 5520 doc = iframe[ 0 ].contentDocument;
nickjillings@1315 5521
nickjillings@1315 5522 // Support: IE
nickjillings@1315 5523 doc.write();
nickjillings@1315 5524 doc.close();
nickjillings@1315 5525
nickjillings@1315 5526 display = actualDisplay( nodeName, doc );
nickjillings@1315 5527 iframe.detach();
nickjillings@1315 5528 }
nickjillings@1315 5529
nickjillings@1315 5530 // Store the correct default display
nickjillings@1315 5531 elemdisplay[ nodeName ] = display;
nickjillings@1315 5532 }
nickjillings@1315 5533
nickjillings@1315 5534 return display;
nickjillings@1315 5535 }
nickjillings@1315 5536 var rmargin = (/^margin/);
nickjillings@1315 5537
nickjillings@1315 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nickjillings@1315 5539
nickjillings@1315 5540 var getStyles = function( elem ) {
nickjillings@1315 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nickjillings@1315 5542 // IE throws on elements created in popups
nickjillings@1315 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nickjillings@1315 5544 if ( elem.ownerDocument.defaultView.opener ) {
nickjillings@1315 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nickjillings@1315 5546 }
nickjillings@1315 5547
nickjillings@1315 5548 return window.getComputedStyle( elem, null );
nickjillings@1315 5549 };
nickjillings@1315 5550
nickjillings@1315 5551
nickjillings@1315 5552
nickjillings@1315 5553 function curCSS( elem, name, computed ) {
nickjillings@1315 5554 var width, minWidth, maxWidth, ret,
nickjillings@1315 5555 style = elem.style;
nickjillings@1315 5556
nickjillings@1315 5557 computed = computed || getStyles( elem );
nickjillings@1315 5558
nickjillings@1315 5559 // Support: IE9
nickjillings@1315 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nickjillings@1315 5561 if ( computed ) {
nickjillings@1315 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nickjillings@1315 5563 }
nickjillings@1315 5564
nickjillings@1315 5565 if ( computed ) {
nickjillings@1315 5566
nickjillings@1315 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1315 5568 ret = jQuery.style( elem, name );
nickjillings@1315 5569 }
nickjillings@1315 5570
nickjillings@1315 5571 // Support: iOS < 6
nickjillings@1315 5572 // A tribute to the "awesome hack by Dean Edwards"
nickjillings@1315 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nickjillings@1315 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nickjillings@1315 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nickjillings@1315 5576
nickjillings@1315 5577 // Remember the original values
nickjillings@1315 5578 width = style.width;
nickjillings@1315 5579 minWidth = style.minWidth;
nickjillings@1315 5580 maxWidth = style.maxWidth;
nickjillings@1315 5581
nickjillings@1315 5582 // Put in the new values to get a computed value out
nickjillings@1315 5583 style.minWidth = style.maxWidth = style.width = ret;
nickjillings@1315 5584 ret = computed.width;
nickjillings@1315 5585
nickjillings@1315 5586 // Revert the changed values
nickjillings@1315 5587 style.width = width;
nickjillings@1315 5588 style.minWidth = minWidth;
nickjillings@1315 5589 style.maxWidth = maxWidth;
nickjillings@1315 5590 }
nickjillings@1315 5591 }
nickjillings@1315 5592
nickjillings@1315 5593 return ret !== undefined ?
nickjillings@1315 5594 // Support: IE
nickjillings@1315 5595 // IE returns zIndex value as an integer.
nickjillings@1315 5596 ret + "" :
nickjillings@1315 5597 ret;
nickjillings@1315 5598 }
nickjillings@1315 5599
nickjillings@1315 5600
nickjillings@1315 5601 function addGetHookIf( conditionFn, hookFn ) {
nickjillings@1315 5602 // Define the hook, we'll check on the first run if it's really needed.
nickjillings@1315 5603 return {
nickjillings@1315 5604 get: function() {
nickjillings@1315 5605 if ( conditionFn() ) {
nickjillings@1315 5606 // Hook not needed (or it's not possible to use it due
nickjillings@1315 5607 // to missing dependency), remove it.
nickjillings@1315 5608 delete this.get;
nickjillings@1315 5609 return;
nickjillings@1315 5610 }
nickjillings@1315 5611
nickjillings@1315 5612 // Hook needed; redefine it so that the support test is not executed again.
nickjillings@1315 5613 return (this.get = hookFn).apply( this, arguments );
nickjillings@1315 5614 }
nickjillings@1315 5615 };
nickjillings@1315 5616 }
nickjillings@1315 5617
nickjillings@1315 5618
nickjillings@1315 5619 (function() {
nickjillings@1315 5620 var pixelPositionVal, boxSizingReliableVal,
nickjillings@1315 5621 docElem = document.documentElement,
nickjillings@1315 5622 container = document.createElement( "div" ),
nickjillings@1315 5623 div = document.createElement( "div" );
nickjillings@1315 5624
nickjillings@1315 5625 if ( !div.style ) {
nickjillings@1315 5626 return;
nickjillings@1315 5627 }
nickjillings@1315 5628
nickjillings@1315 5629 // Support: IE9-11+
nickjillings@1315 5630 // Style of cloned element affects source element cloned (#8908)
nickjillings@1315 5631 div.style.backgroundClip = "content-box";
nickjillings@1315 5632 div.cloneNode( true ).style.backgroundClip = "";
nickjillings@1315 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nickjillings@1315 5634
nickjillings@1315 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nickjillings@1315 5636 "position:absolute";
nickjillings@1315 5637 container.appendChild( div );
nickjillings@1315 5638
nickjillings@1315 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nickjillings@1315 5640 // so they're executed at the same time to save the second computation.
nickjillings@1315 5641 function computePixelPositionAndBoxSizingReliable() {
nickjillings@1315 5642 div.style.cssText =
nickjillings@1315 5643 // Support: Firefox<29, Android 2.3
nickjillings@1315 5644 // Vendor-prefix box-sizing
nickjillings@1315 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nickjillings@1315 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nickjillings@1315 5647 "border:1px;padding:1px;width:4px;position:absolute";
nickjillings@1315 5648 div.innerHTML = "";
nickjillings@1315 5649 docElem.appendChild( container );
nickjillings@1315 5650
nickjillings@1315 5651 var divStyle = window.getComputedStyle( div, null );
nickjillings@1315 5652 pixelPositionVal = divStyle.top !== "1%";
nickjillings@1315 5653 boxSizingReliableVal = divStyle.width === "4px";
nickjillings@1315 5654
nickjillings@1315 5655 docElem.removeChild( container );
nickjillings@1315 5656 }
nickjillings@1315 5657
nickjillings@1315 5658 // Support: node.js jsdom
nickjillings@1315 5659 // Don't assume that getComputedStyle is a property of the global object
nickjillings@1315 5660 if ( window.getComputedStyle ) {
nickjillings@1315 5661 jQuery.extend( support, {
nickjillings@1315 5662 pixelPosition: function() {
nickjillings@1315 5663
nickjillings@1315 5664 // This test is executed only once but we still do memoizing
nickjillings@1315 5665 // since we can use the boxSizingReliable pre-computing.
nickjillings@1315 5666 // No need to check if the test was already performed, though.
nickjillings@1315 5667 computePixelPositionAndBoxSizingReliable();
nickjillings@1315 5668 return pixelPositionVal;
nickjillings@1315 5669 },
nickjillings@1315 5670 boxSizingReliable: function() {
nickjillings@1315 5671 if ( boxSizingReliableVal == null ) {
nickjillings@1315 5672 computePixelPositionAndBoxSizingReliable();
nickjillings@1315 5673 }
nickjillings@1315 5674 return boxSizingReliableVal;
nickjillings@1315 5675 },
nickjillings@1315 5676 reliableMarginRight: function() {
nickjillings@1315 5677
nickjillings@1315 5678 // Support: Android 2.3
nickjillings@1315 5679 // Check if div with explicit width and no margin-right incorrectly
nickjillings@1315 5680 // gets computed margin-right based on width of container. (#3333)
nickjillings@1315 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nickjillings@1315 5682 // This support function is only executed once so no memoizing is needed.
nickjillings@1315 5683 var ret,
nickjillings@1315 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nickjillings@1315 5685
nickjillings@1315 5686 // Reset CSS: box-sizing; display; margin; border; padding
nickjillings@1315 5687 marginDiv.style.cssText = div.style.cssText =
nickjillings@1315 5688 // Support: Firefox<29, Android 2.3
nickjillings@1315 5689 // Vendor-prefix box-sizing
nickjillings@1315 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nickjillings@1315 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nickjillings@1315 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nickjillings@1315 5693 div.style.width = "1px";
nickjillings@1315 5694 docElem.appendChild( container );
nickjillings@1315 5695
nickjillings@1315 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nickjillings@1315 5697
nickjillings@1315 5698 docElem.removeChild( container );
nickjillings@1315 5699 div.removeChild( marginDiv );
nickjillings@1315 5700
nickjillings@1315 5701 return ret;
nickjillings@1315 5702 }
nickjillings@1315 5703 });
nickjillings@1315 5704 }
nickjillings@1315 5705 })();
nickjillings@1315 5706
nickjillings@1315 5707
nickjillings@1315 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nickjillings@1315 5709 jQuery.swap = function( elem, options, callback, args ) {
nickjillings@1315 5710 var ret, name,
nickjillings@1315 5711 old = {};
nickjillings@1315 5712
nickjillings@1315 5713 // Remember the old values, and insert the new ones
nickjillings@1315 5714 for ( name in options ) {
nickjillings@1315 5715 old[ name ] = elem.style[ name ];
nickjillings@1315 5716 elem.style[ name ] = options[ name ];
nickjillings@1315 5717 }
nickjillings@1315 5718
nickjillings@1315 5719 ret = callback.apply( elem, args || [] );
nickjillings@1315 5720
nickjillings@1315 5721 // Revert the old values
nickjillings@1315 5722 for ( name in options ) {
nickjillings@1315 5723 elem.style[ name ] = old[ name ];
nickjillings@1315 5724 }
nickjillings@1315 5725
nickjillings@1315 5726 return ret;
nickjillings@1315 5727 };
nickjillings@1315 5728
nickjillings@1315 5729
nickjillings@1315 5730 var
nickjillings@1315 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nickjillings@1315 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nickjillings@1315 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nickjillings@1315 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nickjillings@1315 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nickjillings@1315 5736
nickjillings@1315 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nickjillings@1315 5738 cssNormalTransform = {
nickjillings@1315 5739 letterSpacing: "0",
nickjillings@1315 5740 fontWeight: "400"
nickjillings@1315 5741 },
nickjillings@1315 5742
nickjillings@1315 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nickjillings@1315 5744
nickjillings@1315 5745 // Return a css property mapped to a potentially vendor prefixed property
nickjillings@1315 5746 function vendorPropName( style, name ) {
nickjillings@1315 5747
nickjillings@1315 5748 // Shortcut for names that are not vendor prefixed
nickjillings@1315 5749 if ( name in style ) {
nickjillings@1315 5750 return name;
nickjillings@1315 5751 }
nickjillings@1315 5752
nickjillings@1315 5753 // Check for vendor prefixed names
nickjillings@1315 5754 var capName = name[0].toUpperCase() + name.slice(1),
nickjillings@1315 5755 origName = name,
nickjillings@1315 5756 i = cssPrefixes.length;
nickjillings@1315 5757
nickjillings@1315 5758 while ( i-- ) {
nickjillings@1315 5759 name = cssPrefixes[ i ] + capName;
nickjillings@1315 5760 if ( name in style ) {
nickjillings@1315 5761 return name;
nickjillings@1315 5762 }
nickjillings@1315 5763 }
nickjillings@1315 5764
nickjillings@1315 5765 return origName;
nickjillings@1315 5766 }
nickjillings@1315 5767
nickjillings@1315 5768 function setPositiveNumber( elem, value, subtract ) {
nickjillings@1315 5769 var matches = rnumsplit.exec( value );
nickjillings@1315 5770 return matches ?
nickjillings@1315 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nickjillings@1315 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nickjillings@1315 5773 value;
nickjillings@1315 5774 }
nickjillings@1315 5775
nickjillings@1315 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nickjillings@1315 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nickjillings@1315 5778 // If we already have the right measurement, avoid augmentation
nickjillings@1315 5779 4 :
nickjillings@1315 5780 // Otherwise initialize for horizontal or vertical properties
nickjillings@1315 5781 name === "width" ? 1 : 0,
nickjillings@1315 5782
nickjillings@1315 5783 val = 0;
nickjillings@1315 5784
nickjillings@1315 5785 for ( ; i < 4; i += 2 ) {
nickjillings@1315 5786 // Both box models exclude margin, so add it if we want it
nickjillings@1315 5787 if ( extra === "margin" ) {
nickjillings@1315 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nickjillings@1315 5789 }
nickjillings@1315 5790
nickjillings@1315 5791 if ( isBorderBox ) {
nickjillings@1315 5792 // border-box includes padding, so remove it if we want content
nickjillings@1315 5793 if ( extra === "content" ) {
nickjillings@1315 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1315 5795 }
nickjillings@1315 5796
nickjillings@1315 5797 // At this point, extra isn't border nor margin, so remove border
nickjillings@1315 5798 if ( extra !== "margin" ) {
nickjillings@1315 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1315 5800 }
nickjillings@1315 5801 } else {
nickjillings@1315 5802 // At this point, extra isn't content, so add padding
nickjillings@1315 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1315 5804
nickjillings@1315 5805 // At this point, extra isn't content nor padding, so add border
nickjillings@1315 5806 if ( extra !== "padding" ) {
nickjillings@1315 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1315 5808 }
nickjillings@1315 5809 }
nickjillings@1315 5810 }
nickjillings@1315 5811
nickjillings@1315 5812 return val;
nickjillings@1315 5813 }
nickjillings@1315 5814
nickjillings@1315 5815 function getWidthOrHeight( elem, name, extra ) {
nickjillings@1315 5816
nickjillings@1315 5817 // Start with offset property, which is equivalent to the border-box value
nickjillings@1315 5818 var valueIsBorderBox = true,
nickjillings@1315 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nickjillings@1315 5820 styles = getStyles( elem ),
nickjillings@1315 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nickjillings@1315 5822
nickjillings@1315 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nickjillings@1315 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nickjillings@1315 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nickjillings@1315 5826 if ( val <= 0 || val == null ) {
nickjillings@1315 5827 // Fall back to computed then uncomputed css if necessary
nickjillings@1315 5828 val = curCSS( elem, name, styles );
nickjillings@1315 5829 if ( val < 0 || val == null ) {
nickjillings@1315 5830 val = elem.style[ name ];
nickjillings@1315 5831 }
nickjillings@1315 5832
nickjillings@1315 5833 // Computed unit is not pixels. Stop here and return.
nickjillings@1315 5834 if ( rnumnonpx.test(val) ) {
nickjillings@1315 5835 return val;
nickjillings@1315 5836 }
nickjillings@1315 5837
nickjillings@1315 5838 // Check for style in case a browser which returns unreliable values
nickjillings@1315 5839 // for getComputedStyle silently falls back to the reliable elem.style
nickjillings@1315 5840 valueIsBorderBox = isBorderBox &&
nickjillings@1315 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nickjillings@1315 5842
nickjillings@1315 5843 // Normalize "", auto, and prepare for extra
nickjillings@1315 5844 val = parseFloat( val ) || 0;
nickjillings@1315 5845 }
nickjillings@1315 5846
nickjillings@1315 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nickjillings@1315 5848 return ( val +
nickjillings@1315 5849 augmentWidthOrHeight(
nickjillings@1315 5850 elem,
nickjillings@1315 5851 name,
nickjillings@1315 5852 extra || ( isBorderBox ? "border" : "content" ),
nickjillings@1315 5853 valueIsBorderBox,
nickjillings@1315 5854 styles
nickjillings@1315 5855 )
nickjillings@1315 5856 ) + "px";
nickjillings@1315 5857 }
nickjillings@1315 5858
nickjillings@1315 5859 function showHide( elements, show ) {
nickjillings@1315 5860 var display, elem, hidden,
nickjillings@1315 5861 values = [],
nickjillings@1315 5862 index = 0,
nickjillings@1315 5863 length = elements.length;
nickjillings@1315 5864
nickjillings@1315 5865 for ( ; index < length; index++ ) {
nickjillings@1315 5866 elem = elements[ index ];
nickjillings@1315 5867 if ( !elem.style ) {
nickjillings@1315 5868 continue;
nickjillings@1315 5869 }
nickjillings@1315 5870
nickjillings@1315 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nickjillings@1315 5872 display = elem.style.display;
nickjillings@1315 5873 if ( show ) {
nickjillings@1315 5874 // Reset the inline display of this element to learn if it is
nickjillings@1315 5875 // being hidden by cascaded rules or not
nickjillings@1315 5876 if ( !values[ index ] && display === "none" ) {
nickjillings@1315 5877 elem.style.display = "";
nickjillings@1315 5878 }
nickjillings@1315 5879
nickjillings@1315 5880 // Set elements which have been overridden with display: none
nickjillings@1315 5881 // in a stylesheet to whatever the default browser style is
nickjillings@1315 5882 // for such an element
nickjillings@1315 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nickjillings@1315 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nickjillings@1315 5885 }
nickjillings@1315 5886 } else {
nickjillings@1315 5887 hidden = isHidden( elem );
nickjillings@1315 5888
nickjillings@1315 5889 if ( display !== "none" || !hidden ) {
nickjillings@1315 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nickjillings@1315 5891 }
nickjillings@1315 5892 }
nickjillings@1315 5893 }
nickjillings@1315 5894
nickjillings@1315 5895 // Set the display of most of the elements in a second loop
nickjillings@1315 5896 // to avoid the constant reflow
nickjillings@1315 5897 for ( index = 0; index < length; index++ ) {
nickjillings@1315 5898 elem = elements[ index ];
nickjillings@1315 5899 if ( !elem.style ) {
nickjillings@1315 5900 continue;
nickjillings@1315 5901 }
nickjillings@1315 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nickjillings@1315 5903 elem.style.display = show ? values[ index ] || "" : "none";
nickjillings@1315 5904 }
nickjillings@1315 5905 }
nickjillings@1315 5906
nickjillings@1315 5907 return elements;
nickjillings@1315 5908 }
nickjillings@1315 5909
nickjillings@1315 5910 jQuery.extend({
nickjillings@1315 5911
nickjillings@1315 5912 // Add in style property hooks for overriding the default
nickjillings@1315 5913 // behavior of getting and setting a style property
nickjillings@1315 5914 cssHooks: {
nickjillings@1315 5915 opacity: {
nickjillings@1315 5916 get: function( elem, computed ) {
nickjillings@1315 5917 if ( computed ) {
nickjillings@1315 5918
nickjillings@1315 5919 // We should always get a number back from opacity
nickjillings@1315 5920 var ret = curCSS( elem, "opacity" );
nickjillings@1315 5921 return ret === "" ? "1" : ret;
nickjillings@1315 5922 }
nickjillings@1315 5923 }
nickjillings@1315 5924 }
nickjillings@1315 5925 },
nickjillings@1315 5926
nickjillings@1315 5927 // Don't automatically add "px" to these possibly-unitless properties
nickjillings@1315 5928 cssNumber: {
nickjillings@1315 5929 "columnCount": true,
nickjillings@1315 5930 "fillOpacity": true,
nickjillings@1315 5931 "flexGrow": true,
nickjillings@1315 5932 "flexShrink": true,
nickjillings@1315 5933 "fontWeight": true,
nickjillings@1315 5934 "lineHeight": true,
nickjillings@1315 5935 "opacity": true,
nickjillings@1315 5936 "order": true,
nickjillings@1315 5937 "orphans": true,
nickjillings@1315 5938 "widows": true,
nickjillings@1315 5939 "zIndex": true,
nickjillings@1315 5940 "zoom": true
nickjillings@1315 5941 },
nickjillings@1315 5942
nickjillings@1315 5943 // Add in properties whose names you wish to fix before
nickjillings@1315 5944 // setting or getting the value
nickjillings@1315 5945 cssProps: {
nickjillings@1315 5946 "float": "cssFloat"
nickjillings@1315 5947 },
nickjillings@1315 5948
nickjillings@1315 5949 // Get and set the style property on a DOM Node
nickjillings@1315 5950 style: function( elem, name, value, extra ) {
nickjillings@1315 5951
nickjillings@1315 5952 // Don't set styles on text and comment nodes
nickjillings@1315 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nickjillings@1315 5954 return;
nickjillings@1315 5955 }
nickjillings@1315 5956
nickjillings@1315 5957 // Make sure that we're working with the right name
nickjillings@1315 5958 var ret, type, hooks,
nickjillings@1315 5959 origName = jQuery.camelCase( name ),
nickjillings@1315 5960 style = elem.style;
nickjillings@1315 5961
nickjillings@1315 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nickjillings@1315 5963
nickjillings@1315 5964 // Gets hook for the prefixed version, then unprefixed version
nickjillings@1315 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1315 5966
nickjillings@1315 5967 // Check if we're setting a value
nickjillings@1315 5968 if ( value !== undefined ) {
nickjillings@1315 5969 type = typeof value;
nickjillings@1315 5970
nickjillings@1315 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nickjillings@1315 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nickjillings@1315 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nickjillings@1315 5974 // Fixes bug #9237
nickjillings@1315 5975 type = "number";
nickjillings@1315 5976 }
nickjillings@1315 5977
nickjillings@1315 5978 // Make sure that null and NaN values aren't set (#7116)
nickjillings@1315 5979 if ( value == null || value !== value ) {
nickjillings@1315 5980 return;
nickjillings@1315 5981 }
nickjillings@1315 5982
nickjillings@1315 5983 // If a number, add 'px' to the (except for certain CSS properties)
nickjillings@1315 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nickjillings@1315 5985 value += "px";
nickjillings@1315 5986 }
nickjillings@1315 5987
nickjillings@1315 5988 // Support: IE9-11+
nickjillings@1315 5989 // background-* props affect original clone's values
nickjillings@1315 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nickjillings@1315 5991 style[ name ] = "inherit";
nickjillings@1315 5992 }
nickjillings@1315 5993
nickjillings@1315 5994 // If a hook was provided, use that value, otherwise just set the specified value
nickjillings@1315 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nickjillings@1315 5996 style[ name ] = value;
nickjillings@1315 5997 }
nickjillings@1315 5998
nickjillings@1315 5999 } else {
nickjillings@1315 6000 // If a hook was provided get the non-computed value from there
nickjillings@1315 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nickjillings@1315 6002 return ret;
nickjillings@1315 6003 }
nickjillings@1315 6004
nickjillings@1315 6005 // Otherwise just get the value from the style object
nickjillings@1315 6006 return style[ name ];
nickjillings@1315 6007 }
nickjillings@1315 6008 },
nickjillings@1315 6009
nickjillings@1315 6010 css: function( elem, name, extra, styles ) {
nickjillings@1315 6011 var val, num, hooks,
nickjillings@1315 6012 origName = jQuery.camelCase( name );
nickjillings@1315 6013
nickjillings@1315 6014 // Make sure that we're working with the right name
nickjillings@1315 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nickjillings@1315 6016
nickjillings@1315 6017 // Try prefixed name followed by the unprefixed name
nickjillings@1315 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1315 6019
nickjillings@1315 6020 // If a hook was provided get the computed value from there
nickjillings@1315 6021 if ( hooks && "get" in hooks ) {
nickjillings@1315 6022 val = hooks.get( elem, true, extra );
nickjillings@1315 6023 }
nickjillings@1315 6024
nickjillings@1315 6025 // Otherwise, if a way to get the computed value exists, use that
nickjillings@1315 6026 if ( val === undefined ) {
nickjillings@1315 6027 val = curCSS( elem, name, styles );
nickjillings@1315 6028 }
nickjillings@1315 6029
nickjillings@1315 6030 // Convert "normal" to computed value
nickjillings@1315 6031 if ( val === "normal" && name in cssNormalTransform ) {
nickjillings@1315 6032 val = cssNormalTransform[ name ];
nickjillings@1315 6033 }
nickjillings@1315 6034
nickjillings@1315 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nickjillings@1315 6036 if ( extra === "" || extra ) {
nickjillings@1315 6037 num = parseFloat( val );
nickjillings@1315 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nickjillings@1315 6039 }
nickjillings@1315 6040 return val;
nickjillings@1315 6041 }
nickjillings@1315 6042 });
nickjillings@1315 6043
nickjillings@1315 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nickjillings@1315 6045 jQuery.cssHooks[ name ] = {
nickjillings@1315 6046 get: function( elem, computed, extra ) {
nickjillings@1315 6047 if ( computed ) {
nickjillings@1315 6048
nickjillings@1315 6049 // Certain elements can have dimension info if we invisibly show them
nickjillings@1315 6050 // but it must have a current display style that would benefit
nickjillings@1315 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nickjillings@1315 6052 jQuery.swap( elem, cssShow, function() {
nickjillings@1315 6053 return getWidthOrHeight( elem, name, extra );
nickjillings@1315 6054 }) :
nickjillings@1315 6055 getWidthOrHeight( elem, name, extra );
nickjillings@1315 6056 }
nickjillings@1315 6057 },
nickjillings@1315 6058
nickjillings@1315 6059 set: function( elem, value, extra ) {
nickjillings@1315 6060 var styles = extra && getStyles( elem );
nickjillings@1315 6061 return setPositiveNumber( elem, value, extra ?
nickjillings@1315 6062 augmentWidthOrHeight(
nickjillings@1315 6063 elem,
nickjillings@1315 6064 name,
nickjillings@1315 6065 extra,
nickjillings@1315 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nickjillings@1315 6067 styles
nickjillings@1315 6068 ) : 0
nickjillings@1315 6069 );
nickjillings@1315 6070 }
nickjillings@1315 6071 };
nickjillings@1315 6072 });
nickjillings@1315 6073
nickjillings@1315 6074 // Support: Android 2.3
nickjillings@1315 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nickjillings@1315 6076 function( elem, computed ) {
nickjillings@1315 6077 if ( computed ) {
nickjillings@1315 6078 return jQuery.swap( elem, { "display": "inline-block" },
nickjillings@1315 6079 curCSS, [ elem, "marginRight" ] );
nickjillings@1315 6080 }
nickjillings@1315 6081 }
nickjillings@1315 6082 );
nickjillings@1315 6083
nickjillings@1315 6084 // These hooks are used by animate to expand properties
nickjillings@1315 6085 jQuery.each({
nickjillings@1315 6086 margin: "",
nickjillings@1315 6087 padding: "",
nickjillings@1315 6088 border: "Width"
nickjillings@1315 6089 }, function( prefix, suffix ) {
nickjillings@1315 6090 jQuery.cssHooks[ prefix + suffix ] = {
nickjillings@1315 6091 expand: function( value ) {
nickjillings@1315 6092 var i = 0,
nickjillings@1315 6093 expanded = {},
nickjillings@1315 6094
nickjillings@1315 6095 // Assumes a single number if not a string
nickjillings@1315 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nickjillings@1315 6097
nickjillings@1315 6098 for ( ; i < 4; i++ ) {
nickjillings@1315 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nickjillings@1315 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nickjillings@1315 6101 }
nickjillings@1315 6102
nickjillings@1315 6103 return expanded;
nickjillings@1315 6104 }
nickjillings@1315 6105 };
nickjillings@1315 6106
nickjillings@1315 6107 if ( !rmargin.test( prefix ) ) {
nickjillings@1315 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nickjillings@1315 6109 }
nickjillings@1315 6110 });
nickjillings@1315 6111
nickjillings@1315 6112 jQuery.fn.extend({
nickjillings@1315 6113 css: function( name, value ) {
nickjillings@1315 6114 return access( this, function( elem, name, value ) {
nickjillings@1315 6115 var styles, len,
nickjillings@1315 6116 map = {},
nickjillings@1315 6117 i = 0;
nickjillings@1315 6118
nickjillings@1315 6119 if ( jQuery.isArray( name ) ) {
nickjillings@1315 6120 styles = getStyles( elem );
nickjillings@1315 6121 len = name.length;
nickjillings@1315 6122
nickjillings@1315 6123 for ( ; i < len; i++ ) {
nickjillings@1315 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nickjillings@1315 6125 }
nickjillings@1315 6126
nickjillings@1315 6127 return map;
nickjillings@1315 6128 }
nickjillings@1315 6129
nickjillings@1315 6130 return value !== undefined ?
nickjillings@1315 6131 jQuery.style( elem, name, value ) :
nickjillings@1315 6132 jQuery.css( elem, name );
nickjillings@1315 6133 }, name, value, arguments.length > 1 );
nickjillings@1315 6134 },
nickjillings@1315 6135 show: function() {
nickjillings@1315 6136 return showHide( this, true );
nickjillings@1315 6137 },
nickjillings@1315 6138 hide: function() {
nickjillings@1315 6139 return showHide( this );
nickjillings@1315 6140 },
nickjillings@1315 6141 toggle: function( state ) {
nickjillings@1315 6142 if ( typeof state === "boolean" ) {
nickjillings@1315 6143 return state ? this.show() : this.hide();
nickjillings@1315 6144 }
nickjillings@1315 6145
nickjillings@1315 6146 return this.each(function() {
nickjillings@1315 6147 if ( isHidden( this ) ) {
nickjillings@1315 6148 jQuery( this ).show();
nickjillings@1315 6149 } else {
nickjillings@1315 6150 jQuery( this ).hide();
nickjillings@1315 6151 }
nickjillings@1315 6152 });
nickjillings@1315 6153 }
nickjillings@1315 6154 });
nickjillings@1315 6155
nickjillings@1315 6156
nickjillings@1315 6157 function Tween( elem, options, prop, end, easing ) {
nickjillings@1315 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nickjillings@1315 6159 }
nickjillings@1315 6160 jQuery.Tween = Tween;
nickjillings@1315 6161
nickjillings@1315 6162 Tween.prototype = {
nickjillings@1315 6163 constructor: Tween,
nickjillings@1315 6164 init: function( elem, options, prop, end, easing, unit ) {
nickjillings@1315 6165 this.elem = elem;
nickjillings@1315 6166 this.prop = prop;
nickjillings@1315 6167 this.easing = easing || "swing";
nickjillings@1315 6168 this.options = options;
nickjillings@1315 6169 this.start = this.now = this.cur();
nickjillings@1315 6170 this.end = end;
nickjillings@1315 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nickjillings@1315 6172 },
nickjillings@1315 6173 cur: function() {
nickjillings@1315 6174 var hooks = Tween.propHooks[ this.prop ];
nickjillings@1315 6175
nickjillings@1315 6176 return hooks && hooks.get ?
nickjillings@1315 6177 hooks.get( this ) :
nickjillings@1315 6178 Tween.propHooks._default.get( this );
nickjillings@1315 6179 },
nickjillings@1315 6180 run: function( percent ) {
nickjillings@1315 6181 var eased,
nickjillings@1315 6182 hooks = Tween.propHooks[ this.prop ];
nickjillings@1315 6183
nickjillings@1315 6184 if ( this.options.duration ) {
nickjillings@1315 6185 this.pos = eased = jQuery.easing[ this.easing ](
nickjillings@1315 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nickjillings@1315 6187 );
nickjillings@1315 6188 } else {
nickjillings@1315 6189 this.pos = eased = percent;
nickjillings@1315 6190 }
nickjillings@1315 6191 this.now = ( this.end - this.start ) * eased + this.start;
nickjillings@1315 6192
nickjillings@1315 6193 if ( this.options.step ) {
nickjillings@1315 6194 this.options.step.call( this.elem, this.now, this );
nickjillings@1315 6195 }
nickjillings@1315 6196
nickjillings@1315 6197 if ( hooks && hooks.set ) {
nickjillings@1315 6198 hooks.set( this );
nickjillings@1315 6199 } else {
nickjillings@1315 6200 Tween.propHooks._default.set( this );
nickjillings@1315 6201 }
nickjillings@1315 6202 return this;
nickjillings@1315 6203 }
nickjillings@1315 6204 };
nickjillings@1315 6205
nickjillings@1315 6206 Tween.prototype.init.prototype = Tween.prototype;
nickjillings@1315 6207
nickjillings@1315 6208 Tween.propHooks = {
nickjillings@1315 6209 _default: {
nickjillings@1315 6210 get: function( tween ) {
nickjillings@1315 6211 var result;
nickjillings@1315 6212
nickjillings@1315 6213 if ( tween.elem[ tween.prop ] != null &&
nickjillings@1315 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nickjillings@1315 6215 return tween.elem[ tween.prop ];
nickjillings@1315 6216 }
nickjillings@1315 6217
nickjillings@1315 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nickjillings@1315 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nickjillings@1315 6220 // Simple values such as "10px" are parsed to Float;
nickjillings@1315 6221 // complex values such as "rotate(1rad)" are returned as-is.
nickjillings@1315 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nickjillings@1315 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nickjillings@1315 6224 return !result || result === "auto" ? 0 : result;
nickjillings@1315 6225 },
nickjillings@1315 6226 set: function( tween ) {
nickjillings@1315 6227 // Use step hook for back compat.
nickjillings@1315 6228 // Use cssHook if its there.
nickjillings@1315 6229 // Use .style if available and use plain properties where available.
nickjillings@1315 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nickjillings@1315 6231 jQuery.fx.step[ tween.prop ]( tween );
nickjillings@1315 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nickjillings@1315 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nickjillings@1315 6234 } else {
nickjillings@1315 6235 tween.elem[ tween.prop ] = tween.now;
nickjillings@1315 6236 }
nickjillings@1315 6237 }
nickjillings@1315 6238 }
nickjillings@1315 6239 };
nickjillings@1315 6240
nickjillings@1315 6241 // Support: IE9
nickjillings@1315 6242 // Panic based approach to setting things on disconnected nodes
nickjillings@1315 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nickjillings@1315 6244 set: function( tween ) {
nickjillings@1315 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nickjillings@1315 6246 tween.elem[ tween.prop ] = tween.now;
nickjillings@1315 6247 }
nickjillings@1315 6248 }
nickjillings@1315 6249 };
nickjillings@1315 6250
nickjillings@1315 6251 jQuery.easing = {
nickjillings@1315 6252 linear: function( p ) {
nickjillings@1315 6253 return p;
nickjillings@1315 6254 },
nickjillings@1315 6255 swing: function( p ) {
nickjillings@1315 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nickjillings@1315 6257 }
nickjillings@1315 6258 };
nickjillings@1315 6259
nickjillings@1315 6260 jQuery.fx = Tween.prototype.init;
nickjillings@1315 6261
nickjillings@1315 6262 // Back Compat <1.8 extension point
nickjillings@1315 6263 jQuery.fx.step = {};
nickjillings@1315 6264
nickjillings@1315 6265
nickjillings@1315 6266
nickjillings@1315 6267
nickjillings@1315 6268 var
nickjillings@1315 6269 fxNow, timerId,
nickjillings@1315 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nickjillings@1315 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nickjillings@1315 6272 rrun = /queueHooks$/,
nickjillings@1315 6273 animationPrefilters = [ defaultPrefilter ],
nickjillings@1315 6274 tweeners = {
nickjillings@1315 6275 "*": [ function( prop, value ) {
nickjillings@1315 6276 var tween = this.createTween( prop, value ),
nickjillings@1315 6277 target = tween.cur(),
nickjillings@1315 6278 parts = rfxnum.exec( value ),
nickjillings@1315 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nickjillings@1315 6280
nickjillings@1315 6281 // Starting value computation is required for potential unit mismatches
nickjillings@1315 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nickjillings@1315 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nickjillings@1315 6284 scale = 1,
nickjillings@1315 6285 maxIterations = 20;
nickjillings@1315 6286
nickjillings@1315 6287 if ( start && start[ 3 ] !== unit ) {
nickjillings@1315 6288 // Trust units reported by jQuery.css
nickjillings@1315 6289 unit = unit || start[ 3 ];
nickjillings@1315 6290
nickjillings@1315 6291 // Make sure we update the tween properties later on
nickjillings@1315 6292 parts = parts || [];
nickjillings@1315 6293
nickjillings@1315 6294 // Iteratively approximate from a nonzero starting point
nickjillings@1315 6295 start = +target || 1;
nickjillings@1315 6296
nickjillings@1315 6297 do {
nickjillings@1315 6298 // If previous iteration zeroed out, double until we get *something*.
nickjillings@1315 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nickjillings@1315 6300 scale = scale || ".5";
nickjillings@1315 6301
nickjillings@1315 6302 // Adjust and apply
nickjillings@1315 6303 start = start / scale;
nickjillings@1315 6304 jQuery.style( tween.elem, prop, start + unit );
nickjillings@1315 6305
nickjillings@1315 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nickjillings@1315 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nickjillings@1315 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nickjillings@1315 6309 }
nickjillings@1315 6310
nickjillings@1315 6311 // Update tween properties
nickjillings@1315 6312 if ( parts ) {
nickjillings@1315 6313 start = tween.start = +start || +target || 0;
nickjillings@1315 6314 tween.unit = unit;
nickjillings@1315 6315 // If a +=/-= token was provided, we're doing a relative animation
nickjillings@1315 6316 tween.end = parts[ 1 ] ?
nickjillings@1315 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nickjillings@1315 6318 +parts[ 2 ];
nickjillings@1315 6319 }
nickjillings@1315 6320
nickjillings@1315 6321 return tween;
nickjillings@1315 6322 } ]
nickjillings@1315 6323 };
nickjillings@1315 6324
nickjillings@1315 6325 // Animations created synchronously will run synchronously
nickjillings@1315 6326 function createFxNow() {
nickjillings@1315 6327 setTimeout(function() {
nickjillings@1315 6328 fxNow = undefined;
nickjillings@1315 6329 });
nickjillings@1315 6330 return ( fxNow = jQuery.now() );
nickjillings@1315 6331 }
nickjillings@1315 6332
nickjillings@1315 6333 // Generate parameters to create a standard animation
nickjillings@1315 6334 function genFx( type, includeWidth ) {
nickjillings@1315 6335 var which,
nickjillings@1315 6336 i = 0,
nickjillings@1315 6337 attrs = { height: type };
nickjillings@1315 6338
nickjillings@1315 6339 // If we include width, step value is 1 to do all cssExpand values,
nickjillings@1315 6340 // otherwise step value is 2 to skip over Left and Right
nickjillings@1315 6341 includeWidth = includeWidth ? 1 : 0;
nickjillings@1315 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nickjillings@1315 6343 which = cssExpand[ i ];
nickjillings@1315 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nickjillings@1315 6345 }
nickjillings@1315 6346
nickjillings@1315 6347 if ( includeWidth ) {
nickjillings@1315 6348 attrs.opacity = attrs.width = type;
nickjillings@1315 6349 }
nickjillings@1315 6350
nickjillings@1315 6351 return attrs;
nickjillings@1315 6352 }
nickjillings@1315 6353
nickjillings@1315 6354 function createTween( value, prop, animation ) {
nickjillings@1315 6355 var tween,
nickjillings@1315 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nickjillings@1315 6357 index = 0,
nickjillings@1315 6358 length = collection.length;
nickjillings@1315 6359 for ( ; index < length; index++ ) {
nickjillings@1315 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nickjillings@1315 6361
nickjillings@1315 6362 // We're done with this property
nickjillings@1315 6363 return tween;
nickjillings@1315 6364 }
nickjillings@1315 6365 }
nickjillings@1315 6366 }
nickjillings@1315 6367
nickjillings@1315 6368 function defaultPrefilter( elem, props, opts ) {
nickjillings@1315 6369 /* jshint validthis: true */
nickjillings@1315 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nickjillings@1315 6371 anim = this,
nickjillings@1315 6372 orig = {},
nickjillings@1315 6373 style = elem.style,
nickjillings@1315 6374 hidden = elem.nodeType && isHidden( elem ),
nickjillings@1315 6375 dataShow = data_priv.get( elem, "fxshow" );
nickjillings@1315 6376
nickjillings@1315 6377 // Handle queue: false promises
nickjillings@1315 6378 if ( !opts.queue ) {
nickjillings@1315 6379 hooks = jQuery._queueHooks( elem, "fx" );
nickjillings@1315 6380 if ( hooks.unqueued == null ) {
nickjillings@1315 6381 hooks.unqueued = 0;
nickjillings@1315 6382 oldfire = hooks.empty.fire;
nickjillings@1315 6383 hooks.empty.fire = function() {
nickjillings@1315 6384 if ( !hooks.unqueued ) {
nickjillings@1315 6385 oldfire();
nickjillings@1315 6386 }
nickjillings@1315 6387 };
nickjillings@1315 6388 }
nickjillings@1315 6389 hooks.unqueued++;
nickjillings@1315 6390
nickjillings@1315 6391 anim.always(function() {
nickjillings@1315 6392 // Ensure the complete handler is called before this completes
nickjillings@1315 6393 anim.always(function() {
nickjillings@1315 6394 hooks.unqueued--;
nickjillings@1315 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nickjillings@1315 6396 hooks.empty.fire();
nickjillings@1315 6397 }
nickjillings@1315 6398 });
nickjillings@1315 6399 });
nickjillings@1315 6400 }
nickjillings@1315 6401
nickjillings@1315 6402 // Height/width overflow pass
nickjillings@1315 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nickjillings@1315 6404 // Make sure that nothing sneaks out
nickjillings@1315 6405 // Record all 3 overflow attributes because IE9-10 do not
nickjillings@1315 6406 // change the overflow attribute when overflowX and
nickjillings@1315 6407 // overflowY are set to the same value
nickjillings@1315 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nickjillings@1315 6409
nickjillings@1315 6410 // Set display property to inline-block for height/width
nickjillings@1315 6411 // animations on inline elements that are having width/height animated
nickjillings@1315 6412 display = jQuery.css( elem, "display" );
nickjillings@1315 6413
nickjillings@1315 6414 // Test default display if display is currently "none"
nickjillings@1315 6415 checkDisplay = display === "none" ?
nickjillings@1315 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nickjillings@1315 6417
nickjillings@1315 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nickjillings@1315 6419 style.display = "inline-block";
nickjillings@1315 6420 }
nickjillings@1315 6421 }
nickjillings@1315 6422
nickjillings@1315 6423 if ( opts.overflow ) {
nickjillings@1315 6424 style.overflow = "hidden";
nickjillings@1315 6425 anim.always(function() {
nickjillings@1315 6426 style.overflow = opts.overflow[ 0 ];
nickjillings@1315 6427 style.overflowX = opts.overflow[ 1 ];
nickjillings@1315 6428 style.overflowY = opts.overflow[ 2 ];
nickjillings@1315 6429 });
nickjillings@1315 6430 }
nickjillings@1315 6431
nickjillings@1315 6432 // show/hide pass
nickjillings@1315 6433 for ( prop in props ) {
nickjillings@1315 6434 value = props[ prop ];
nickjillings@1315 6435 if ( rfxtypes.exec( value ) ) {
nickjillings@1315 6436 delete props[ prop ];
nickjillings@1315 6437 toggle = toggle || value === "toggle";
nickjillings@1315 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nickjillings@1315 6439
nickjillings@1315 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@1315 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nickjillings@1315 6442 hidden = true;
nickjillings@1315 6443 } else {
nickjillings@1315 6444 continue;
nickjillings@1315 6445 }
nickjillings@1315 6446 }
nickjillings@1315 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nickjillings@1315 6448
nickjillings@1315 6449 // Any non-fx value stops us from restoring the original display value
nickjillings@1315 6450 } else {
nickjillings@1315 6451 display = undefined;
nickjillings@1315 6452 }
nickjillings@1315 6453 }
nickjillings@1315 6454
nickjillings@1315 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nickjillings@1315 6456 if ( dataShow ) {
nickjillings@1315 6457 if ( "hidden" in dataShow ) {
nickjillings@1315 6458 hidden = dataShow.hidden;
nickjillings@1315 6459 }
nickjillings@1315 6460 } else {
nickjillings@1315 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nickjillings@1315 6462 }
nickjillings@1315 6463
nickjillings@1315 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nickjillings@1315 6465 if ( toggle ) {
nickjillings@1315 6466 dataShow.hidden = !hidden;
nickjillings@1315 6467 }
nickjillings@1315 6468 if ( hidden ) {
nickjillings@1315 6469 jQuery( elem ).show();
nickjillings@1315 6470 } else {
nickjillings@1315 6471 anim.done(function() {
nickjillings@1315 6472 jQuery( elem ).hide();
nickjillings@1315 6473 });
nickjillings@1315 6474 }
nickjillings@1315 6475 anim.done(function() {
nickjillings@1315 6476 var prop;
nickjillings@1315 6477
nickjillings@1315 6478 data_priv.remove( elem, "fxshow" );
nickjillings@1315 6479 for ( prop in orig ) {
nickjillings@1315 6480 jQuery.style( elem, prop, orig[ prop ] );
nickjillings@1315 6481 }
nickjillings@1315 6482 });
nickjillings@1315 6483 for ( prop in orig ) {
nickjillings@1315 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nickjillings@1315 6485
nickjillings@1315 6486 if ( !( prop in dataShow ) ) {
nickjillings@1315 6487 dataShow[ prop ] = tween.start;
nickjillings@1315 6488 if ( hidden ) {
nickjillings@1315 6489 tween.end = tween.start;
nickjillings@1315 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nickjillings@1315 6491 }
nickjillings@1315 6492 }
nickjillings@1315 6493 }
nickjillings@1315 6494
nickjillings@1315 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nickjillings@1315 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nickjillings@1315 6497 style.display = display;
nickjillings@1315 6498 }
nickjillings@1315 6499 }
nickjillings@1315 6500
nickjillings@1315 6501 function propFilter( props, specialEasing ) {
nickjillings@1315 6502 var index, name, easing, value, hooks;
nickjillings@1315 6503
nickjillings@1315 6504 // camelCase, specialEasing and expand cssHook pass
nickjillings@1315 6505 for ( index in props ) {
nickjillings@1315 6506 name = jQuery.camelCase( index );
nickjillings@1315 6507 easing = specialEasing[ name ];
nickjillings@1315 6508 value = props[ index ];
nickjillings@1315 6509 if ( jQuery.isArray( value ) ) {
nickjillings@1315 6510 easing = value[ 1 ];
nickjillings@1315 6511 value = props[ index ] = value[ 0 ];
nickjillings@1315 6512 }
nickjillings@1315 6513
nickjillings@1315 6514 if ( index !== name ) {
nickjillings@1315 6515 props[ name ] = value;
nickjillings@1315 6516 delete props[ index ];
nickjillings@1315 6517 }
nickjillings@1315 6518
nickjillings@1315 6519 hooks = jQuery.cssHooks[ name ];
nickjillings@1315 6520 if ( hooks && "expand" in hooks ) {
nickjillings@1315 6521 value = hooks.expand( value );
nickjillings@1315 6522 delete props[ name ];
nickjillings@1315 6523
nickjillings@1315 6524 // Not quite $.extend, this won't overwrite existing keys.
nickjillings@1315 6525 // Reusing 'index' because we have the correct "name"
nickjillings@1315 6526 for ( index in value ) {
nickjillings@1315 6527 if ( !( index in props ) ) {
nickjillings@1315 6528 props[ index ] = value[ index ];
nickjillings@1315 6529 specialEasing[ index ] = easing;
nickjillings@1315 6530 }
nickjillings@1315 6531 }
nickjillings@1315 6532 } else {
nickjillings@1315 6533 specialEasing[ name ] = easing;
nickjillings@1315 6534 }
nickjillings@1315 6535 }
nickjillings@1315 6536 }
nickjillings@1315 6537
nickjillings@1315 6538 function Animation( elem, properties, options ) {
nickjillings@1315 6539 var result,
nickjillings@1315 6540 stopped,
nickjillings@1315 6541 index = 0,
nickjillings@1315 6542 length = animationPrefilters.length,
nickjillings@1315 6543 deferred = jQuery.Deferred().always( function() {
nickjillings@1315 6544 // Don't match elem in the :animated selector
nickjillings@1315 6545 delete tick.elem;
nickjillings@1315 6546 }),
nickjillings@1315 6547 tick = function() {
nickjillings@1315 6548 if ( stopped ) {
nickjillings@1315 6549 return false;
nickjillings@1315 6550 }
nickjillings@1315 6551 var currentTime = fxNow || createFxNow(),
nickjillings@1315 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nickjillings@1315 6553 // Support: Android 2.3
nickjillings@1315 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nickjillings@1315 6555 temp = remaining / animation.duration || 0,
nickjillings@1315 6556 percent = 1 - temp,
nickjillings@1315 6557 index = 0,
nickjillings@1315 6558 length = animation.tweens.length;
nickjillings@1315 6559
nickjillings@1315 6560 for ( ; index < length ; index++ ) {
nickjillings@1315 6561 animation.tweens[ index ].run( percent );
nickjillings@1315 6562 }
nickjillings@1315 6563
nickjillings@1315 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nickjillings@1315 6565
nickjillings@1315 6566 if ( percent < 1 && length ) {
nickjillings@1315 6567 return remaining;
nickjillings@1315 6568 } else {
nickjillings@1315 6569 deferred.resolveWith( elem, [ animation ] );
nickjillings@1315 6570 return false;
nickjillings@1315 6571 }
nickjillings@1315 6572 },
nickjillings@1315 6573 animation = deferred.promise({
nickjillings@1315 6574 elem: elem,
nickjillings@1315 6575 props: jQuery.extend( {}, properties ),
nickjillings@1315 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nickjillings@1315 6577 originalProperties: properties,
nickjillings@1315 6578 originalOptions: options,
nickjillings@1315 6579 startTime: fxNow || createFxNow(),
nickjillings@1315 6580 duration: options.duration,
nickjillings@1315 6581 tweens: [],
nickjillings@1315 6582 createTween: function( prop, end ) {
nickjillings@1315 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nickjillings@1315 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nickjillings@1315 6585 animation.tweens.push( tween );
nickjillings@1315 6586 return tween;
nickjillings@1315 6587 },
nickjillings@1315 6588 stop: function( gotoEnd ) {
nickjillings@1315 6589 var index = 0,
nickjillings@1315 6590 // If we are going to the end, we want to run all the tweens
nickjillings@1315 6591 // otherwise we skip this part
nickjillings@1315 6592 length = gotoEnd ? animation.tweens.length : 0;
nickjillings@1315 6593 if ( stopped ) {
nickjillings@1315 6594 return this;
nickjillings@1315 6595 }
nickjillings@1315 6596 stopped = true;
nickjillings@1315 6597 for ( ; index < length ; index++ ) {
nickjillings@1315 6598 animation.tweens[ index ].run( 1 );
nickjillings@1315 6599 }
nickjillings@1315 6600
nickjillings@1315 6601 // Resolve when we played the last frame; otherwise, reject
nickjillings@1315 6602 if ( gotoEnd ) {
nickjillings@1315 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nickjillings@1315 6604 } else {
nickjillings@1315 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nickjillings@1315 6606 }
nickjillings@1315 6607 return this;
nickjillings@1315 6608 }
nickjillings@1315 6609 }),
nickjillings@1315 6610 props = animation.props;
nickjillings@1315 6611
nickjillings@1315 6612 propFilter( props, animation.opts.specialEasing );
nickjillings@1315 6613
nickjillings@1315 6614 for ( ; index < length ; index++ ) {
nickjillings@1315 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nickjillings@1315 6616 if ( result ) {
nickjillings@1315 6617 return result;
nickjillings@1315 6618 }
nickjillings@1315 6619 }
nickjillings@1315 6620
nickjillings@1315 6621 jQuery.map( props, createTween, animation );
nickjillings@1315 6622
nickjillings@1315 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nickjillings@1315 6624 animation.opts.start.call( elem, animation );
nickjillings@1315 6625 }
nickjillings@1315 6626
nickjillings@1315 6627 jQuery.fx.timer(
nickjillings@1315 6628 jQuery.extend( tick, {
nickjillings@1315 6629 elem: elem,
nickjillings@1315 6630 anim: animation,
nickjillings@1315 6631 queue: animation.opts.queue
nickjillings@1315 6632 })
nickjillings@1315 6633 );
nickjillings@1315 6634
nickjillings@1315 6635 // attach callbacks from options
nickjillings@1315 6636 return animation.progress( animation.opts.progress )
nickjillings@1315 6637 .done( animation.opts.done, animation.opts.complete )
nickjillings@1315 6638 .fail( animation.opts.fail )
nickjillings@1315 6639 .always( animation.opts.always );
nickjillings@1315 6640 }
nickjillings@1315 6641
nickjillings@1315 6642 jQuery.Animation = jQuery.extend( Animation, {
nickjillings@1315 6643
nickjillings@1315 6644 tweener: function( props, callback ) {
nickjillings@1315 6645 if ( jQuery.isFunction( props ) ) {
nickjillings@1315 6646 callback = props;
nickjillings@1315 6647 props = [ "*" ];
nickjillings@1315 6648 } else {
nickjillings@1315 6649 props = props.split(" ");
nickjillings@1315 6650 }
nickjillings@1315 6651
nickjillings@1315 6652 var prop,
nickjillings@1315 6653 index = 0,
nickjillings@1315 6654 length = props.length;
nickjillings@1315 6655
nickjillings@1315 6656 for ( ; index < length ; index++ ) {
nickjillings@1315 6657 prop = props[ index ];
nickjillings@1315 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nickjillings@1315 6659 tweeners[ prop ].unshift( callback );
nickjillings@1315 6660 }
nickjillings@1315 6661 },
nickjillings@1315 6662
nickjillings@1315 6663 prefilter: function( callback, prepend ) {
nickjillings@1315 6664 if ( prepend ) {
nickjillings@1315 6665 animationPrefilters.unshift( callback );
nickjillings@1315 6666 } else {
nickjillings@1315 6667 animationPrefilters.push( callback );
nickjillings@1315 6668 }
nickjillings@1315 6669 }
nickjillings@1315 6670 });
nickjillings@1315 6671
nickjillings@1315 6672 jQuery.speed = function( speed, easing, fn ) {
nickjillings@1315 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nickjillings@1315 6674 complete: fn || !fn && easing ||
nickjillings@1315 6675 jQuery.isFunction( speed ) && speed,
nickjillings@1315 6676 duration: speed,
nickjillings@1315 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nickjillings@1315 6678 };
nickjillings@1315 6679
nickjillings@1315 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nickjillings@1315 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nickjillings@1315 6682
nickjillings@1315 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nickjillings@1315 6684 if ( opt.queue == null || opt.queue === true ) {
nickjillings@1315 6685 opt.queue = "fx";
nickjillings@1315 6686 }
nickjillings@1315 6687
nickjillings@1315 6688 // Queueing
nickjillings@1315 6689 opt.old = opt.complete;
nickjillings@1315 6690
nickjillings@1315 6691 opt.complete = function() {
nickjillings@1315 6692 if ( jQuery.isFunction( opt.old ) ) {
nickjillings@1315 6693 opt.old.call( this );
nickjillings@1315 6694 }
nickjillings@1315 6695
nickjillings@1315 6696 if ( opt.queue ) {
nickjillings@1315 6697 jQuery.dequeue( this, opt.queue );
nickjillings@1315 6698 }
nickjillings@1315 6699 };
nickjillings@1315 6700
nickjillings@1315 6701 return opt;
nickjillings@1315 6702 };
nickjillings@1315 6703
nickjillings@1315 6704 jQuery.fn.extend({
nickjillings@1315 6705 fadeTo: function( speed, to, easing, callback ) {
nickjillings@1315 6706
nickjillings@1315 6707 // Show any hidden elements after setting opacity to 0
nickjillings@1315 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nickjillings@1315 6709
nickjillings@1315 6710 // Animate to the value specified
nickjillings@1315 6711 .end().animate({ opacity: to }, speed, easing, callback );
nickjillings@1315 6712 },
nickjillings@1315 6713 animate: function( prop, speed, easing, callback ) {
nickjillings@1315 6714 var empty = jQuery.isEmptyObject( prop ),
nickjillings@1315 6715 optall = jQuery.speed( speed, easing, callback ),
nickjillings@1315 6716 doAnimation = function() {
nickjillings@1315 6717 // Operate on a copy of prop so per-property easing won't be lost
nickjillings@1315 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nickjillings@1315 6719
nickjillings@1315 6720 // Empty animations, or finishing resolves immediately
nickjillings@1315 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nickjillings@1315 6722 anim.stop( true );
nickjillings@1315 6723 }
nickjillings@1315 6724 };
nickjillings@1315 6725 doAnimation.finish = doAnimation;
nickjillings@1315 6726
nickjillings@1315 6727 return empty || optall.queue === false ?
nickjillings@1315 6728 this.each( doAnimation ) :
nickjillings@1315 6729 this.queue( optall.queue, doAnimation );
nickjillings@1315 6730 },
nickjillings@1315 6731 stop: function( type, clearQueue, gotoEnd ) {
nickjillings@1315 6732 var stopQueue = function( hooks ) {
nickjillings@1315 6733 var stop = hooks.stop;
nickjillings@1315 6734 delete hooks.stop;
nickjillings@1315 6735 stop( gotoEnd );
nickjillings@1315 6736 };
nickjillings@1315 6737
nickjillings@1315 6738 if ( typeof type !== "string" ) {
nickjillings@1315 6739 gotoEnd = clearQueue;
nickjillings@1315 6740 clearQueue = type;
nickjillings@1315 6741 type = undefined;
nickjillings@1315 6742 }
nickjillings@1315 6743 if ( clearQueue && type !== false ) {
nickjillings@1315 6744 this.queue( type || "fx", [] );
nickjillings@1315 6745 }
nickjillings@1315 6746
nickjillings@1315 6747 return this.each(function() {
nickjillings@1315 6748 var dequeue = true,
nickjillings@1315 6749 index = type != null && type + "queueHooks",
nickjillings@1315 6750 timers = jQuery.timers,
nickjillings@1315 6751 data = data_priv.get( this );
nickjillings@1315 6752
nickjillings@1315 6753 if ( index ) {
nickjillings@1315 6754 if ( data[ index ] && data[ index ].stop ) {
nickjillings@1315 6755 stopQueue( data[ index ] );
nickjillings@1315 6756 }
nickjillings@1315 6757 } else {
nickjillings@1315 6758 for ( index in data ) {
nickjillings@1315 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nickjillings@1315 6760 stopQueue( data[ index ] );
nickjillings@1315 6761 }
nickjillings@1315 6762 }
nickjillings@1315 6763 }
nickjillings@1315 6764
nickjillings@1315 6765 for ( index = timers.length; index--; ) {
nickjillings@1315 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nickjillings@1315 6767 timers[ index ].anim.stop( gotoEnd );
nickjillings@1315 6768 dequeue = false;
nickjillings@1315 6769 timers.splice( index, 1 );
nickjillings@1315 6770 }
nickjillings@1315 6771 }
nickjillings@1315 6772
nickjillings@1315 6773 // Start the next in the queue if the last step wasn't forced.
nickjillings@1315 6774 // Timers currently will call their complete callbacks, which
nickjillings@1315 6775 // will dequeue but only if they were gotoEnd.
nickjillings@1315 6776 if ( dequeue || !gotoEnd ) {
nickjillings@1315 6777 jQuery.dequeue( this, type );
nickjillings@1315 6778 }
nickjillings@1315 6779 });
nickjillings@1315 6780 },
nickjillings@1315 6781 finish: function( type ) {
nickjillings@1315 6782 if ( type !== false ) {
nickjillings@1315 6783 type = type || "fx";
nickjillings@1315 6784 }
nickjillings@1315 6785 return this.each(function() {
nickjillings@1315 6786 var index,
nickjillings@1315 6787 data = data_priv.get( this ),
nickjillings@1315 6788 queue = data[ type + "queue" ],
nickjillings@1315 6789 hooks = data[ type + "queueHooks" ],
nickjillings@1315 6790 timers = jQuery.timers,
nickjillings@1315 6791 length = queue ? queue.length : 0;
nickjillings@1315 6792
nickjillings@1315 6793 // Enable finishing flag on private data
nickjillings@1315 6794 data.finish = true;
nickjillings@1315 6795
nickjillings@1315 6796 // Empty the queue first
nickjillings@1315 6797 jQuery.queue( this, type, [] );
nickjillings@1315 6798
nickjillings@1315 6799 if ( hooks && hooks.stop ) {
nickjillings@1315 6800 hooks.stop.call( this, true );
nickjillings@1315 6801 }
nickjillings@1315 6802
nickjillings@1315 6803 // Look for any active animations, and finish them
nickjillings@1315 6804 for ( index = timers.length; index--; ) {
nickjillings@1315 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nickjillings@1315 6806 timers[ index ].anim.stop( true );
nickjillings@1315 6807 timers.splice( index, 1 );
nickjillings@1315 6808 }
nickjillings@1315 6809 }
nickjillings@1315 6810
nickjillings@1315 6811 // Look for any animations in the old queue and finish them
nickjillings@1315 6812 for ( index = 0; index < length; index++ ) {
nickjillings@1315 6813 if ( queue[ index ] && queue[ index ].finish ) {
nickjillings@1315 6814 queue[ index ].finish.call( this );
nickjillings@1315 6815 }
nickjillings@1315 6816 }
nickjillings@1315 6817
nickjillings@1315 6818 // Turn off finishing flag
nickjillings@1315 6819 delete data.finish;
nickjillings@1315 6820 });
nickjillings@1315 6821 }
nickjillings@1315 6822 });
nickjillings@1315 6823
nickjillings@1315 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nickjillings@1315 6825 var cssFn = jQuery.fn[ name ];
nickjillings@1315 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1315 6827 return speed == null || typeof speed === "boolean" ?
nickjillings@1315 6828 cssFn.apply( this, arguments ) :
nickjillings@1315 6829 this.animate( genFx( name, true ), speed, easing, callback );
nickjillings@1315 6830 };
nickjillings@1315 6831 });
nickjillings@1315 6832
nickjillings@1315 6833 // Generate shortcuts for custom animations
nickjillings@1315 6834 jQuery.each({
nickjillings@1315 6835 slideDown: genFx("show"),
nickjillings@1315 6836 slideUp: genFx("hide"),
nickjillings@1315 6837 slideToggle: genFx("toggle"),
nickjillings@1315 6838 fadeIn: { opacity: "show" },
nickjillings@1315 6839 fadeOut: { opacity: "hide" },
nickjillings@1315 6840 fadeToggle: { opacity: "toggle" }
nickjillings@1315 6841 }, function( name, props ) {
nickjillings@1315 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1315 6843 return this.animate( props, speed, easing, callback );
nickjillings@1315 6844 };
nickjillings@1315 6845 });
nickjillings@1315 6846
nickjillings@1315 6847 jQuery.timers = [];
nickjillings@1315 6848 jQuery.fx.tick = function() {
nickjillings@1315 6849 var timer,
nickjillings@1315 6850 i = 0,
nickjillings@1315 6851 timers = jQuery.timers;
nickjillings@1315 6852
nickjillings@1315 6853 fxNow = jQuery.now();
nickjillings@1315 6854
nickjillings@1315 6855 for ( ; i < timers.length; i++ ) {
nickjillings@1315 6856 timer = timers[ i ];
nickjillings@1315 6857 // Checks the timer has not already been removed
nickjillings@1315 6858 if ( !timer() && timers[ i ] === timer ) {
nickjillings@1315 6859 timers.splice( i--, 1 );
nickjillings@1315 6860 }
nickjillings@1315 6861 }
nickjillings@1315 6862
nickjillings@1315 6863 if ( !timers.length ) {
nickjillings@1315 6864 jQuery.fx.stop();
nickjillings@1315 6865 }
nickjillings@1315 6866 fxNow = undefined;
nickjillings@1315 6867 };
nickjillings@1315 6868
nickjillings@1315 6869 jQuery.fx.timer = function( timer ) {
nickjillings@1315 6870 jQuery.timers.push( timer );
nickjillings@1315 6871 if ( timer() ) {
nickjillings@1315 6872 jQuery.fx.start();
nickjillings@1315 6873 } else {
nickjillings@1315 6874 jQuery.timers.pop();
nickjillings@1315 6875 }
nickjillings@1315 6876 };
nickjillings@1315 6877
nickjillings@1315 6878 jQuery.fx.interval = 13;
nickjillings@1315 6879
nickjillings@1315 6880 jQuery.fx.start = function() {
nickjillings@1315 6881 if ( !timerId ) {
nickjillings@1315 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nickjillings@1315 6883 }
nickjillings@1315 6884 };
nickjillings@1315 6885
nickjillings@1315 6886 jQuery.fx.stop = function() {
nickjillings@1315 6887 clearInterval( timerId );
nickjillings@1315 6888 timerId = null;
nickjillings@1315 6889 };
nickjillings@1315 6890
nickjillings@1315 6891 jQuery.fx.speeds = {
nickjillings@1315 6892 slow: 600,
nickjillings@1315 6893 fast: 200,
nickjillings@1315 6894 // Default speed
nickjillings@1315 6895 _default: 400
nickjillings@1315 6896 };
nickjillings@1315 6897
nickjillings@1315 6898
nickjillings@1315 6899 // Based off of the plugin by Clint Helfers, with permission.
nickjillings@1315 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nickjillings@1315 6901 jQuery.fn.delay = function( time, type ) {
nickjillings@1315 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nickjillings@1315 6903 type = type || "fx";
nickjillings@1315 6904
nickjillings@1315 6905 return this.queue( type, function( next, hooks ) {
nickjillings@1315 6906 var timeout = setTimeout( next, time );
nickjillings@1315 6907 hooks.stop = function() {
nickjillings@1315 6908 clearTimeout( timeout );
nickjillings@1315 6909 };
nickjillings@1315 6910 });
nickjillings@1315 6911 };
nickjillings@1315 6912
nickjillings@1315 6913
nickjillings@1315 6914 (function() {
nickjillings@1315 6915 var input = document.createElement( "input" ),
nickjillings@1315 6916 select = document.createElement( "select" ),
nickjillings@1315 6917 opt = select.appendChild( document.createElement( "option" ) );
nickjillings@1315 6918
nickjillings@1315 6919 input.type = "checkbox";
nickjillings@1315 6920
nickjillings@1315 6921 // Support: iOS<=5.1, Android<=4.2+
nickjillings@1315 6922 // Default value for a checkbox should be "on"
nickjillings@1315 6923 support.checkOn = input.value !== "";
nickjillings@1315 6924
nickjillings@1315 6925 // Support: IE<=11+
nickjillings@1315 6926 // Must access selectedIndex to make default options select
nickjillings@1315 6927 support.optSelected = opt.selected;
nickjillings@1315 6928
nickjillings@1315 6929 // Support: Android<=2.3
nickjillings@1315 6930 // Options inside disabled selects are incorrectly marked as disabled
nickjillings@1315 6931 select.disabled = true;
nickjillings@1315 6932 support.optDisabled = !opt.disabled;
nickjillings@1315 6933
nickjillings@1315 6934 // Support: IE<=11+
nickjillings@1315 6935 // An input loses its value after becoming a radio
nickjillings@1315 6936 input = document.createElement( "input" );
nickjillings@1315 6937 input.value = "t";
nickjillings@1315 6938 input.type = "radio";
nickjillings@1315 6939 support.radioValue = input.value === "t";
nickjillings@1315 6940 })();
nickjillings@1315 6941
nickjillings@1315 6942
nickjillings@1315 6943 var nodeHook, boolHook,
nickjillings@1315 6944 attrHandle = jQuery.expr.attrHandle;
nickjillings@1315 6945
nickjillings@1315 6946 jQuery.fn.extend({
nickjillings@1315 6947 attr: function( name, value ) {
nickjillings@1315 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nickjillings@1315 6949 },
nickjillings@1315 6950
nickjillings@1315 6951 removeAttr: function( name ) {
nickjillings@1315 6952 return this.each(function() {
nickjillings@1315 6953 jQuery.removeAttr( this, name );
nickjillings@1315 6954 });
nickjillings@1315 6955 }
nickjillings@1315 6956 });
nickjillings@1315 6957
nickjillings@1315 6958 jQuery.extend({
nickjillings@1315 6959 attr: function( elem, name, value ) {
nickjillings@1315 6960 var hooks, ret,
nickjillings@1315 6961 nType = elem.nodeType;
nickjillings@1315 6962
nickjillings@1315 6963 // don't get/set attributes on text, comment and attribute nodes
nickjillings@1315 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1315 6965 return;
nickjillings@1315 6966 }
nickjillings@1315 6967
nickjillings@1315 6968 // Fallback to prop when attributes are not supported
nickjillings@1315 6969 if ( typeof elem.getAttribute === strundefined ) {
nickjillings@1315 6970 return jQuery.prop( elem, name, value );
nickjillings@1315 6971 }
nickjillings@1315 6972
nickjillings@1315 6973 // All attributes are lowercase
nickjillings@1315 6974 // Grab necessary hook if one is defined
nickjillings@1315 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nickjillings@1315 6976 name = name.toLowerCase();
nickjillings@1315 6977 hooks = jQuery.attrHooks[ name ] ||
nickjillings@1315 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nickjillings@1315 6979 }
nickjillings@1315 6980
nickjillings@1315 6981 if ( value !== undefined ) {
nickjillings@1315 6982
nickjillings@1315 6983 if ( value === null ) {
nickjillings@1315 6984 jQuery.removeAttr( elem, name );
nickjillings@1315 6985
nickjillings@1315 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nickjillings@1315 6987 return ret;
nickjillings@1315 6988
nickjillings@1315 6989 } else {
nickjillings@1315 6990 elem.setAttribute( name, value + "" );
nickjillings@1315 6991 return value;
nickjillings@1315 6992 }
nickjillings@1315 6993
nickjillings@1315 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nickjillings@1315 6995 return ret;
nickjillings@1315 6996
nickjillings@1315 6997 } else {
nickjillings@1315 6998 ret = jQuery.find.attr( elem, name );
nickjillings@1315 6999
nickjillings@1315 7000 // Non-existent attributes return null, we normalize to undefined
nickjillings@1315 7001 return ret == null ?
nickjillings@1315 7002 undefined :
nickjillings@1315 7003 ret;
nickjillings@1315 7004 }
nickjillings@1315 7005 },
nickjillings@1315 7006
nickjillings@1315 7007 removeAttr: function( elem, value ) {
nickjillings@1315 7008 var name, propName,
nickjillings@1315 7009 i = 0,
nickjillings@1315 7010 attrNames = value && value.match( rnotwhite );
nickjillings@1315 7011
nickjillings@1315 7012 if ( attrNames && elem.nodeType === 1 ) {
nickjillings@1315 7013 while ( (name = attrNames[i++]) ) {
nickjillings@1315 7014 propName = jQuery.propFix[ name ] || name;
nickjillings@1315 7015
nickjillings@1315 7016 // Boolean attributes get special treatment (#10870)
nickjillings@1315 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nickjillings@1315 7018 // Set corresponding property to false
nickjillings@1315 7019 elem[ propName ] = false;
nickjillings@1315 7020 }
nickjillings@1315 7021
nickjillings@1315 7022 elem.removeAttribute( name );
nickjillings@1315 7023 }
nickjillings@1315 7024 }
nickjillings@1315 7025 },
nickjillings@1315 7026
nickjillings@1315 7027 attrHooks: {
nickjillings@1315 7028 type: {
nickjillings@1315 7029 set: function( elem, value ) {
nickjillings@1315 7030 if ( !support.radioValue && value === "radio" &&
nickjillings@1315 7031 jQuery.nodeName( elem, "input" ) ) {
nickjillings@1315 7032 var val = elem.value;
nickjillings@1315 7033 elem.setAttribute( "type", value );
nickjillings@1315 7034 if ( val ) {
nickjillings@1315 7035 elem.value = val;
nickjillings@1315 7036 }
nickjillings@1315 7037 return value;
nickjillings@1315 7038 }
nickjillings@1315 7039 }
nickjillings@1315 7040 }
nickjillings@1315 7041 }
nickjillings@1315 7042 });
nickjillings@1315 7043
nickjillings@1315 7044 // Hooks for boolean attributes
nickjillings@1315 7045 boolHook = {
nickjillings@1315 7046 set: function( elem, value, name ) {
nickjillings@1315 7047 if ( value === false ) {
nickjillings@1315 7048 // Remove boolean attributes when set to false
nickjillings@1315 7049 jQuery.removeAttr( elem, name );
nickjillings@1315 7050 } else {
nickjillings@1315 7051 elem.setAttribute( name, name );
nickjillings@1315 7052 }
nickjillings@1315 7053 return name;
nickjillings@1315 7054 }
nickjillings@1315 7055 };
nickjillings@1315 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nickjillings@1315 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nickjillings@1315 7058
nickjillings@1315 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nickjillings@1315 7060 var ret, handle;
nickjillings@1315 7061 if ( !isXML ) {
nickjillings@1315 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nickjillings@1315 7063 handle = attrHandle[ name ];
nickjillings@1315 7064 attrHandle[ name ] = ret;
nickjillings@1315 7065 ret = getter( elem, name, isXML ) != null ?
nickjillings@1315 7066 name.toLowerCase() :
nickjillings@1315 7067 null;
nickjillings@1315 7068 attrHandle[ name ] = handle;
nickjillings@1315 7069 }
nickjillings@1315 7070 return ret;
nickjillings@1315 7071 };
nickjillings@1315 7072 });
nickjillings@1315 7073
nickjillings@1315 7074
nickjillings@1315 7075
nickjillings@1315 7076
nickjillings@1315 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nickjillings@1315 7078
nickjillings@1315 7079 jQuery.fn.extend({
nickjillings@1315 7080 prop: function( name, value ) {
nickjillings@1315 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nickjillings@1315 7082 },
nickjillings@1315 7083
nickjillings@1315 7084 removeProp: function( name ) {
nickjillings@1315 7085 return this.each(function() {
nickjillings@1315 7086 delete this[ jQuery.propFix[ name ] || name ];
nickjillings@1315 7087 });
nickjillings@1315 7088 }
nickjillings@1315 7089 });
nickjillings@1315 7090
nickjillings@1315 7091 jQuery.extend({
nickjillings@1315 7092 propFix: {
nickjillings@1315 7093 "for": "htmlFor",
nickjillings@1315 7094 "class": "className"
nickjillings@1315 7095 },
nickjillings@1315 7096
nickjillings@1315 7097 prop: function( elem, name, value ) {
nickjillings@1315 7098 var ret, hooks, notxml,
nickjillings@1315 7099 nType = elem.nodeType;
nickjillings@1315 7100
nickjillings@1315 7101 // Don't get/set properties on text, comment and attribute nodes
nickjillings@1315 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1315 7103 return;
nickjillings@1315 7104 }
nickjillings@1315 7105
nickjillings@1315 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nickjillings@1315 7107
nickjillings@1315 7108 if ( notxml ) {
nickjillings@1315 7109 // Fix name and attach hooks
nickjillings@1315 7110 name = jQuery.propFix[ name ] || name;
nickjillings@1315 7111 hooks = jQuery.propHooks[ name ];
nickjillings@1315 7112 }
nickjillings@1315 7113
nickjillings@1315 7114 if ( value !== undefined ) {
nickjillings@1315 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nickjillings@1315 7116 ret :
nickjillings@1315 7117 ( elem[ name ] = value );
nickjillings@1315 7118
nickjillings@1315 7119 } else {
nickjillings@1315 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nickjillings@1315 7121 ret :
nickjillings@1315 7122 elem[ name ];
nickjillings@1315 7123 }
nickjillings@1315 7124 },
nickjillings@1315 7125
nickjillings@1315 7126 propHooks: {
nickjillings@1315 7127 tabIndex: {
nickjillings@1315 7128 get: function( elem ) {
nickjillings@1315 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nickjillings@1315 7130 elem.tabIndex :
nickjillings@1315 7131 -1;
nickjillings@1315 7132 }
nickjillings@1315 7133 }
nickjillings@1315 7134 }
nickjillings@1315 7135 });
nickjillings@1315 7136
nickjillings@1315 7137 if ( !support.optSelected ) {
nickjillings@1315 7138 jQuery.propHooks.selected = {
nickjillings@1315 7139 get: function( elem ) {
nickjillings@1315 7140 var parent = elem.parentNode;
nickjillings@1315 7141 if ( parent && parent.parentNode ) {
nickjillings@1315 7142 parent.parentNode.selectedIndex;
nickjillings@1315 7143 }
nickjillings@1315 7144 return null;
nickjillings@1315 7145 }
nickjillings@1315 7146 };
nickjillings@1315 7147 }
nickjillings@1315 7148
nickjillings@1315 7149 jQuery.each([
nickjillings@1315 7150 "tabIndex",
nickjillings@1315 7151 "readOnly",
nickjillings@1315 7152 "maxLength",
nickjillings@1315 7153 "cellSpacing",
nickjillings@1315 7154 "cellPadding",
nickjillings@1315 7155 "rowSpan",
nickjillings@1315 7156 "colSpan",
nickjillings@1315 7157 "useMap",
nickjillings@1315 7158 "frameBorder",
nickjillings@1315 7159 "contentEditable"
nickjillings@1315 7160 ], function() {
nickjillings@1315 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nickjillings@1315 7162 });
nickjillings@1315 7163
nickjillings@1315 7164
nickjillings@1315 7165
nickjillings@1315 7166
nickjillings@1315 7167 var rclass = /[\t\r\n\f]/g;
nickjillings@1315 7168
nickjillings@1315 7169 jQuery.fn.extend({
nickjillings@1315 7170 addClass: function( value ) {
nickjillings@1315 7171 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1315 7172 proceed = typeof value === "string" && value,
nickjillings@1315 7173 i = 0,
nickjillings@1315 7174 len = this.length;
nickjillings@1315 7175
nickjillings@1315 7176 if ( jQuery.isFunction( value ) ) {
nickjillings@1315 7177 return this.each(function( j ) {
nickjillings@1315 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nickjillings@1315 7179 });
nickjillings@1315 7180 }
nickjillings@1315 7181
nickjillings@1315 7182 if ( proceed ) {
nickjillings@1315 7183 // The disjunction here is for better compressibility (see removeClass)
nickjillings@1315 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1315 7185
nickjillings@1315 7186 for ( ; i < len; i++ ) {
nickjillings@1315 7187 elem = this[ i ];
nickjillings@1315 7188 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1315 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1315 7190 " "
nickjillings@1315 7191 );
nickjillings@1315 7192
nickjillings@1315 7193 if ( cur ) {
nickjillings@1315 7194 j = 0;
nickjillings@1315 7195 while ( (clazz = classes[j++]) ) {
nickjillings@1315 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nickjillings@1315 7197 cur += clazz + " ";
nickjillings@1315 7198 }
nickjillings@1315 7199 }
nickjillings@1315 7200
nickjillings@1315 7201 // only assign if different to avoid unneeded rendering.
nickjillings@1315 7202 finalValue = jQuery.trim( cur );
nickjillings@1315 7203 if ( elem.className !== finalValue ) {
nickjillings@1315 7204 elem.className = finalValue;
nickjillings@1315 7205 }
nickjillings@1315 7206 }
nickjillings@1315 7207 }
nickjillings@1315 7208 }
nickjillings@1315 7209
nickjillings@1315 7210 return this;
nickjillings@1315 7211 },
nickjillings@1315 7212
nickjillings@1315 7213 removeClass: function( value ) {
nickjillings@1315 7214 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1315 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nickjillings@1315 7216 i = 0,
nickjillings@1315 7217 len = this.length;
nickjillings@1315 7218
nickjillings@1315 7219 if ( jQuery.isFunction( value ) ) {
nickjillings@1315 7220 return this.each(function( j ) {
nickjillings@1315 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nickjillings@1315 7222 });
nickjillings@1315 7223 }
nickjillings@1315 7224 if ( proceed ) {
nickjillings@1315 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1315 7226
nickjillings@1315 7227 for ( ; i < len; i++ ) {
nickjillings@1315 7228 elem = this[ i ];
nickjillings@1315 7229 // This expression is here for better compressibility (see addClass)
nickjillings@1315 7230 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1315 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1315 7232 ""
nickjillings@1315 7233 );
nickjillings@1315 7234
nickjillings@1315 7235 if ( cur ) {
nickjillings@1315 7236 j = 0;
nickjillings@1315 7237 while ( (clazz = classes[j++]) ) {
nickjillings@1315 7238 // Remove *all* instances
nickjillings@1315 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nickjillings@1315 7240 cur = cur.replace( " " + clazz + " ", " " );
nickjillings@1315 7241 }
nickjillings@1315 7242 }
nickjillings@1315 7243
nickjillings@1315 7244 // Only assign if different to avoid unneeded rendering.
nickjillings@1315 7245 finalValue = value ? jQuery.trim( cur ) : "";
nickjillings@1315 7246 if ( elem.className !== finalValue ) {
nickjillings@1315 7247 elem.className = finalValue;
nickjillings@1315 7248 }
nickjillings@1315 7249 }
nickjillings@1315 7250 }
nickjillings@1315 7251 }
nickjillings@1315 7252
nickjillings@1315 7253 return this;
nickjillings@1315 7254 },
nickjillings@1315 7255
nickjillings@1315 7256 toggleClass: function( value, stateVal ) {
nickjillings@1315 7257 var type = typeof value;
nickjillings@1315 7258
nickjillings@1315 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nickjillings@1315 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nickjillings@1315 7261 }
nickjillings@1315 7262
nickjillings@1315 7263 if ( jQuery.isFunction( value ) ) {
nickjillings@1315 7264 return this.each(function( i ) {
nickjillings@1315 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nickjillings@1315 7266 });
nickjillings@1315 7267 }
nickjillings@1315 7268
nickjillings@1315 7269 return this.each(function() {
nickjillings@1315 7270 if ( type === "string" ) {
nickjillings@1315 7271 // Toggle individual class names
nickjillings@1315 7272 var className,
nickjillings@1315 7273 i = 0,
nickjillings@1315 7274 self = jQuery( this ),
nickjillings@1315 7275 classNames = value.match( rnotwhite ) || [];
nickjillings@1315 7276
nickjillings@1315 7277 while ( (className = classNames[ i++ ]) ) {
nickjillings@1315 7278 // Check each className given, space separated list
nickjillings@1315 7279 if ( self.hasClass( className ) ) {
nickjillings@1315 7280 self.removeClass( className );
nickjillings@1315 7281 } else {
nickjillings@1315 7282 self.addClass( className );
nickjillings@1315 7283 }
nickjillings@1315 7284 }
nickjillings@1315 7285
nickjillings@1315 7286 // Toggle whole class name
nickjillings@1315 7287 } else if ( type === strundefined || type === "boolean" ) {
nickjillings@1315 7288 if ( this.className ) {
nickjillings@1315 7289 // store className if set
nickjillings@1315 7290 data_priv.set( this, "__className__", this.className );
nickjillings@1315 7291 }
nickjillings@1315 7292
nickjillings@1315 7293 // If the element has a class name or if we're passed `false`,
nickjillings@1315 7294 // then remove the whole classname (if there was one, the above saved it).
nickjillings@1315 7295 // Otherwise bring back whatever was previously saved (if anything),
nickjillings@1315 7296 // falling back to the empty string if nothing was stored.
nickjillings@1315 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nickjillings@1315 7298 }
nickjillings@1315 7299 });
nickjillings@1315 7300 },
nickjillings@1315 7301
nickjillings@1315 7302 hasClass: function( selector ) {
nickjillings@1315 7303 var className = " " + selector + " ",
nickjillings@1315 7304 i = 0,
nickjillings@1315 7305 l = this.length;
nickjillings@1315 7306 for ( ; i < l; i++ ) {
nickjillings@1315 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nickjillings@1315 7308 return true;
nickjillings@1315 7309 }
nickjillings@1315 7310 }
nickjillings@1315 7311
nickjillings@1315 7312 return false;
nickjillings@1315 7313 }
nickjillings@1315 7314 });
nickjillings@1315 7315
nickjillings@1315 7316
nickjillings@1315 7317
nickjillings@1315 7318
nickjillings@1315 7319 var rreturn = /\r/g;
nickjillings@1315 7320
nickjillings@1315 7321 jQuery.fn.extend({
nickjillings@1315 7322 val: function( value ) {
nickjillings@1315 7323 var hooks, ret, isFunction,
nickjillings@1315 7324 elem = this[0];
nickjillings@1315 7325
nickjillings@1315 7326 if ( !arguments.length ) {
nickjillings@1315 7327 if ( elem ) {
nickjillings@1315 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nickjillings@1315 7329
nickjillings@1315 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nickjillings@1315 7331 return ret;
nickjillings@1315 7332 }
nickjillings@1315 7333
nickjillings@1315 7334 ret = elem.value;
nickjillings@1315 7335
nickjillings@1315 7336 return typeof ret === "string" ?
nickjillings@1315 7337 // Handle most common string cases
nickjillings@1315 7338 ret.replace(rreturn, "") :
nickjillings@1315 7339 // Handle cases where value is null/undef or number
nickjillings@1315 7340 ret == null ? "" : ret;
nickjillings@1315 7341 }
nickjillings@1315 7342
nickjillings@1315 7343 return;
nickjillings@1315 7344 }
nickjillings@1315 7345
nickjillings@1315 7346 isFunction = jQuery.isFunction( value );
nickjillings@1315 7347
nickjillings@1315 7348 return this.each(function( i ) {
nickjillings@1315 7349 var val;
nickjillings@1315 7350
nickjillings@1315 7351 if ( this.nodeType !== 1 ) {
nickjillings@1315 7352 return;
nickjillings@1315 7353 }
nickjillings@1315 7354
nickjillings@1315 7355 if ( isFunction ) {
nickjillings@1315 7356 val = value.call( this, i, jQuery( this ).val() );
nickjillings@1315 7357 } else {
nickjillings@1315 7358 val = value;
nickjillings@1315 7359 }
nickjillings@1315 7360
nickjillings@1315 7361 // Treat null/undefined as ""; convert numbers to string
nickjillings@1315 7362 if ( val == null ) {
nickjillings@1315 7363 val = "";
nickjillings@1315 7364
nickjillings@1315 7365 } else if ( typeof val === "number" ) {
nickjillings@1315 7366 val += "";
nickjillings@1315 7367
nickjillings@1315 7368 } else if ( jQuery.isArray( val ) ) {
nickjillings@1315 7369 val = jQuery.map( val, function( value ) {
nickjillings@1315 7370 return value == null ? "" : value + "";
nickjillings@1315 7371 });
nickjillings@1315 7372 }
nickjillings@1315 7373
nickjillings@1315 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nickjillings@1315 7375
nickjillings@1315 7376 // If set returns undefined, fall back to normal setting
nickjillings@1315 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nickjillings@1315 7378 this.value = val;
nickjillings@1315 7379 }
nickjillings@1315 7380 });
nickjillings@1315 7381 }
nickjillings@1315 7382 });
nickjillings@1315 7383
nickjillings@1315 7384 jQuery.extend({
nickjillings@1315 7385 valHooks: {
nickjillings@1315 7386 option: {
nickjillings@1315 7387 get: function( elem ) {
nickjillings@1315 7388 var val = jQuery.find.attr( elem, "value" );
nickjillings@1315 7389 return val != null ?
nickjillings@1315 7390 val :
nickjillings@1315 7391 // Support: IE10-11+
nickjillings@1315 7392 // option.text throws exceptions (#14686, #14858)
nickjillings@1315 7393 jQuery.trim( jQuery.text( elem ) );
nickjillings@1315 7394 }
nickjillings@1315 7395 },
nickjillings@1315 7396 select: {
nickjillings@1315 7397 get: function( elem ) {
nickjillings@1315 7398 var value, option,
nickjillings@1315 7399 options = elem.options,
nickjillings@1315 7400 index = elem.selectedIndex,
nickjillings@1315 7401 one = elem.type === "select-one" || index < 0,
nickjillings@1315 7402 values = one ? null : [],
nickjillings@1315 7403 max = one ? index + 1 : options.length,
nickjillings@1315 7404 i = index < 0 ?
nickjillings@1315 7405 max :
nickjillings@1315 7406 one ? index : 0;
nickjillings@1315 7407
nickjillings@1315 7408 // Loop through all the selected options
nickjillings@1315 7409 for ( ; i < max; i++ ) {
nickjillings@1315 7410 option = options[ i ];
nickjillings@1315 7411
nickjillings@1315 7412 // IE6-9 doesn't update selected after form reset (#2551)
nickjillings@1315 7413 if ( ( option.selected || i === index ) &&
nickjillings@1315 7414 // Don't return options that are disabled or in a disabled optgroup
nickjillings@1315 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nickjillings@1315 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nickjillings@1315 7417
nickjillings@1315 7418 // Get the specific value for the option
nickjillings@1315 7419 value = jQuery( option ).val();
nickjillings@1315 7420
nickjillings@1315 7421 // We don't need an array for one selects
nickjillings@1315 7422 if ( one ) {
nickjillings@1315 7423 return value;
nickjillings@1315 7424 }
nickjillings@1315 7425
nickjillings@1315 7426 // Multi-Selects return an array
nickjillings@1315 7427 values.push( value );
nickjillings@1315 7428 }
nickjillings@1315 7429 }
nickjillings@1315 7430
nickjillings@1315 7431 return values;
nickjillings@1315 7432 },
nickjillings@1315 7433
nickjillings@1315 7434 set: function( elem, value ) {
nickjillings@1315 7435 var optionSet, option,
nickjillings@1315 7436 options = elem.options,
nickjillings@1315 7437 values = jQuery.makeArray( value ),
nickjillings@1315 7438 i = options.length;
nickjillings@1315 7439
nickjillings@1315 7440 while ( i-- ) {
nickjillings@1315 7441 option = options[ i ];
nickjillings@1315 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nickjillings@1315 7443 optionSet = true;
nickjillings@1315 7444 }
nickjillings@1315 7445 }
nickjillings@1315 7446
nickjillings@1315 7447 // Force browsers to behave consistently when non-matching value is set
nickjillings@1315 7448 if ( !optionSet ) {
nickjillings@1315 7449 elem.selectedIndex = -1;
nickjillings@1315 7450 }
nickjillings@1315 7451 return values;
nickjillings@1315 7452 }
nickjillings@1315 7453 }
nickjillings@1315 7454 }
nickjillings@1315 7455 });
nickjillings@1315 7456
nickjillings@1315 7457 // Radios and checkboxes getter/setter
nickjillings@1315 7458 jQuery.each([ "radio", "checkbox" ], function() {
nickjillings@1315 7459 jQuery.valHooks[ this ] = {
nickjillings@1315 7460 set: function( elem, value ) {
nickjillings@1315 7461 if ( jQuery.isArray( value ) ) {
nickjillings@1315 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nickjillings@1315 7463 }
nickjillings@1315 7464 }
nickjillings@1315 7465 };
nickjillings@1315 7466 if ( !support.checkOn ) {
nickjillings@1315 7467 jQuery.valHooks[ this ].get = function( elem ) {
nickjillings@1315 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nickjillings@1315 7469 };
nickjillings@1315 7470 }
nickjillings@1315 7471 });
nickjillings@1315 7472
nickjillings@1315 7473
nickjillings@1315 7474
nickjillings@1315 7475
nickjillings@1315 7476 // Return jQuery for attributes-only inclusion
nickjillings@1315 7477
nickjillings@1315 7478
nickjillings@1315 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nickjillings@1315 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nickjillings@1315 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nickjillings@1315 7482
nickjillings@1315 7483 // Handle event binding
nickjillings@1315 7484 jQuery.fn[ name ] = function( data, fn ) {
nickjillings@1315 7485 return arguments.length > 0 ?
nickjillings@1315 7486 this.on( name, null, data, fn ) :
nickjillings@1315 7487 this.trigger( name );
nickjillings@1315 7488 };
nickjillings@1315 7489 });
nickjillings@1315 7490
nickjillings@1315 7491 jQuery.fn.extend({
nickjillings@1315 7492 hover: function( fnOver, fnOut ) {
nickjillings@1315 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nickjillings@1315 7494 },
nickjillings@1315 7495
nickjillings@1315 7496 bind: function( types, data, fn ) {
nickjillings@1315 7497 return this.on( types, null, data, fn );
nickjillings@1315 7498 },
nickjillings@1315 7499 unbind: function( types, fn ) {
nickjillings@1315 7500 return this.off( types, null, fn );
nickjillings@1315 7501 },
nickjillings@1315 7502
nickjillings@1315 7503 delegate: function( selector, types, data, fn ) {
nickjillings@1315 7504 return this.on( types, selector, data, fn );
nickjillings@1315 7505 },
nickjillings@1315 7506 undelegate: function( selector, types, fn ) {
nickjillings@1315 7507 // ( namespace ) or ( selector, types [, fn] )
nickjillings@1315 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nickjillings@1315 7509 }
nickjillings@1315 7510 });
nickjillings@1315 7511
nickjillings@1315 7512
nickjillings@1315 7513 var nonce = jQuery.now();
nickjillings@1315 7514
nickjillings@1315 7515 var rquery = (/\?/);
nickjillings@1315 7516
nickjillings@1315 7517
nickjillings@1315 7518
nickjillings@1315 7519 // Support: Android 2.3
nickjillings@1315 7520 // Workaround failure to string-cast null input
nickjillings@1315 7521 jQuery.parseJSON = function( data ) {
nickjillings@1315 7522 return JSON.parse( data + "" );
nickjillings@1315 7523 };
nickjillings@1315 7524
nickjillings@1315 7525
nickjillings@1315 7526 // Cross-browser xml parsing
nickjillings@1315 7527 jQuery.parseXML = function( data ) {
nickjillings@1315 7528 var xml, tmp;
nickjillings@1315 7529 if ( !data || typeof data !== "string" ) {
nickjillings@1315 7530 return null;
nickjillings@1315 7531 }
nickjillings@1315 7532
nickjillings@1315 7533 // Support: IE9
nickjillings@1315 7534 try {
nickjillings@1315 7535 tmp = new DOMParser();
nickjillings@1315 7536 xml = tmp.parseFromString( data, "text/xml" );
nickjillings@1315 7537 } catch ( e ) {
nickjillings@1315 7538 xml = undefined;
nickjillings@1315 7539 }
nickjillings@1315 7540
nickjillings@1315 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nickjillings@1315 7542 jQuery.error( "Invalid XML: " + data );
nickjillings@1315 7543 }
nickjillings@1315 7544 return xml;
nickjillings@1315 7545 };
nickjillings@1315 7546
nickjillings@1315 7547
nickjillings@1315 7548 var
nickjillings@1315 7549 rhash = /#.*$/,
nickjillings@1315 7550 rts = /([?&])_=[^&]*/,
nickjillings@1315 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nickjillings@1315 7552 // #7653, #8125, #8152: local protocol detection
nickjillings@1315 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nickjillings@1315 7554 rnoContent = /^(?:GET|HEAD)$/,
nickjillings@1315 7555 rprotocol = /^\/\//,
nickjillings@1315 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nickjillings@1315 7557
nickjillings@1315 7558 /* Prefilters
nickjillings@1315 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nickjillings@1315 7560 * 2) These are called:
nickjillings@1315 7561 * - BEFORE asking for a transport
nickjillings@1315 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nickjillings@1315 7563 * 3) key is the dataType
nickjillings@1315 7564 * 4) the catchall symbol "*" can be used
nickjillings@1315 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nickjillings@1315 7566 */
nickjillings@1315 7567 prefilters = {},
nickjillings@1315 7568
nickjillings@1315 7569 /* Transports bindings
nickjillings@1315 7570 * 1) key is the dataType
nickjillings@1315 7571 * 2) the catchall symbol "*" can be used
nickjillings@1315 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nickjillings@1315 7573 */
nickjillings@1315 7574 transports = {},
nickjillings@1315 7575
nickjillings@1315 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nickjillings@1315 7577 allTypes = "*/".concat( "*" ),
nickjillings@1315 7578
nickjillings@1315 7579 // Document location
nickjillings@1315 7580 ajaxLocation = window.location.href,
nickjillings@1315 7581
nickjillings@1315 7582 // Segment location into parts
nickjillings@1315 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nickjillings@1315 7584
nickjillings@1315 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nickjillings@1315 7586 function addToPrefiltersOrTransports( structure ) {
nickjillings@1315 7587
nickjillings@1315 7588 // dataTypeExpression is optional and defaults to "*"
nickjillings@1315 7589 return function( dataTypeExpression, func ) {
nickjillings@1315 7590
nickjillings@1315 7591 if ( typeof dataTypeExpression !== "string" ) {
nickjillings@1315 7592 func = dataTypeExpression;
nickjillings@1315 7593 dataTypeExpression = "*";
nickjillings@1315 7594 }
nickjillings@1315 7595
nickjillings@1315 7596 var dataType,
nickjillings@1315 7597 i = 0,
nickjillings@1315 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nickjillings@1315 7599
nickjillings@1315 7600 if ( jQuery.isFunction( func ) ) {
nickjillings@1315 7601 // For each dataType in the dataTypeExpression
nickjillings@1315 7602 while ( (dataType = dataTypes[i++]) ) {
nickjillings@1315 7603 // Prepend if requested
nickjillings@1315 7604 if ( dataType[0] === "+" ) {
nickjillings@1315 7605 dataType = dataType.slice( 1 ) || "*";
nickjillings@1315 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nickjillings@1315 7607
nickjillings@1315 7608 // Otherwise append
nickjillings@1315 7609 } else {
nickjillings@1315 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nickjillings@1315 7611 }
nickjillings@1315 7612 }
nickjillings@1315 7613 }
nickjillings@1315 7614 };
nickjillings@1315 7615 }
nickjillings@1315 7616
nickjillings@1315 7617 // Base inspection function for prefilters and transports
nickjillings@1315 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nickjillings@1315 7619
nickjillings@1315 7620 var inspected = {},
nickjillings@1315 7621 seekingTransport = ( structure === transports );
nickjillings@1315 7622
nickjillings@1315 7623 function inspect( dataType ) {
nickjillings@1315 7624 var selected;
nickjillings@1315 7625 inspected[ dataType ] = true;
nickjillings@1315 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nickjillings@1315 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nickjillings@1315 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nickjillings@1315 7629 options.dataTypes.unshift( dataTypeOrTransport );
nickjillings@1315 7630 inspect( dataTypeOrTransport );
nickjillings@1315 7631 return false;
nickjillings@1315 7632 } else if ( seekingTransport ) {
nickjillings@1315 7633 return !( selected = dataTypeOrTransport );
nickjillings@1315 7634 }
nickjillings@1315 7635 });
nickjillings@1315 7636 return selected;
nickjillings@1315 7637 }
nickjillings@1315 7638
nickjillings@1315 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nickjillings@1315 7640 }
nickjillings@1315 7641
nickjillings@1315 7642 // A special extend for ajax options
nickjillings@1315 7643 // that takes "flat" options (not to be deep extended)
nickjillings@1315 7644 // Fixes #9887
nickjillings@1315 7645 function ajaxExtend( target, src ) {
nickjillings@1315 7646 var key, deep,
nickjillings@1315 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nickjillings@1315 7648
nickjillings@1315 7649 for ( key in src ) {
nickjillings@1315 7650 if ( src[ key ] !== undefined ) {
nickjillings@1315 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nickjillings@1315 7652 }
nickjillings@1315 7653 }
nickjillings@1315 7654 if ( deep ) {
nickjillings@1315 7655 jQuery.extend( true, target, deep );
nickjillings@1315 7656 }
nickjillings@1315 7657
nickjillings@1315 7658 return target;
nickjillings@1315 7659 }
nickjillings@1315 7660
nickjillings@1315 7661 /* Handles responses to an ajax request:
nickjillings@1315 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nickjillings@1315 7663 * - returns the corresponding response
nickjillings@1315 7664 */
nickjillings@1315 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nickjillings@1315 7666
nickjillings@1315 7667 var ct, type, finalDataType, firstDataType,
nickjillings@1315 7668 contents = s.contents,
nickjillings@1315 7669 dataTypes = s.dataTypes;
nickjillings@1315 7670
nickjillings@1315 7671 // Remove auto dataType and get content-type in the process
nickjillings@1315 7672 while ( dataTypes[ 0 ] === "*" ) {
nickjillings@1315 7673 dataTypes.shift();
nickjillings@1315 7674 if ( ct === undefined ) {
nickjillings@1315 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nickjillings@1315 7676 }
nickjillings@1315 7677 }
nickjillings@1315 7678
nickjillings@1315 7679 // Check if we're dealing with a known content-type
nickjillings@1315 7680 if ( ct ) {
nickjillings@1315 7681 for ( type in contents ) {
nickjillings@1315 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nickjillings@1315 7683 dataTypes.unshift( type );
nickjillings@1315 7684 break;
nickjillings@1315 7685 }
nickjillings@1315 7686 }
nickjillings@1315 7687 }
nickjillings@1315 7688
nickjillings@1315 7689 // Check to see if we have a response for the expected dataType
nickjillings@1315 7690 if ( dataTypes[ 0 ] in responses ) {
nickjillings@1315 7691 finalDataType = dataTypes[ 0 ];
nickjillings@1315 7692 } else {
nickjillings@1315 7693 // Try convertible dataTypes
nickjillings@1315 7694 for ( type in responses ) {
nickjillings@1315 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nickjillings@1315 7696 finalDataType = type;
nickjillings@1315 7697 break;
nickjillings@1315 7698 }
nickjillings@1315 7699 if ( !firstDataType ) {
nickjillings@1315 7700 firstDataType = type;
nickjillings@1315 7701 }
nickjillings@1315 7702 }
nickjillings@1315 7703 // Or just use first one
nickjillings@1315 7704 finalDataType = finalDataType || firstDataType;
nickjillings@1315 7705 }
nickjillings@1315 7706
nickjillings@1315 7707 // If we found a dataType
nickjillings@1315 7708 // We add the dataType to the list if needed
nickjillings@1315 7709 // and return the corresponding response
nickjillings@1315 7710 if ( finalDataType ) {
nickjillings@1315 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nickjillings@1315 7712 dataTypes.unshift( finalDataType );
nickjillings@1315 7713 }
nickjillings@1315 7714 return responses[ finalDataType ];
nickjillings@1315 7715 }
nickjillings@1315 7716 }
nickjillings@1315 7717
nickjillings@1315 7718 /* Chain conversions given the request and the original response
nickjillings@1315 7719 * Also sets the responseXXX fields on the jqXHR instance
nickjillings@1315 7720 */
nickjillings@1315 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nickjillings@1315 7722 var conv2, current, conv, tmp, prev,
nickjillings@1315 7723 converters = {},
nickjillings@1315 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nickjillings@1315 7725 dataTypes = s.dataTypes.slice();
nickjillings@1315 7726
nickjillings@1315 7727 // Create converters map with lowercased keys
nickjillings@1315 7728 if ( dataTypes[ 1 ] ) {
nickjillings@1315 7729 for ( conv in s.converters ) {
nickjillings@1315 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nickjillings@1315 7731 }
nickjillings@1315 7732 }
nickjillings@1315 7733
nickjillings@1315 7734 current = dataTypes.shift();
nickjillings@1315 7735
nickjillings@1315 7736 // Convert to each sequential dataType
nickjillings@1315 7737 while ( current ) {
nickjillings@1315 7738
nickjillings@1315 7739 if ( s.responseFields[ current ] ) {
nickjillings@1315 7740 jqXHR[ s.responseFields[ current ] ] = response;
nickjillings@1315 7741 }
nickjillings@1315 7742
nickjillings@1315 7743 // Apply the dataFilter if provided
nickjillings@1315 7744 if ( !prev && isSuccess && s.dataFilter ) {
nickjillings@1315 7745 response = s.dataFilter( response, s.dataType );
nickjillings@1315 7746 }
nickjillings@1315 7747
nickjillings@1315 7748 prev = current;
nickjillings@1315 7749 current = dataTypes.shift();
nickjillings@1315 7750
nickjillings@1315 7751 if ( current ) {
nickjillings@1315 7752
nickjillings@1315 7753 // There's only work to do if current dataType is non-auto
nickjillings@1315 7754 if ( current === "*" ) {
nickjillings@1315 7755
nickjillings@1315 7756 current = prev;
nickjillings@1315 7757
nickjillings@1315 7758 // Convert response if prev dataType is non-auto and differs from current
nickjillings@1315 7759 } else if ( prev !== "*" && prev !== current ) {
nickjillings@1315 7760
nickjillings@1315 7761 // Seek a direct converter
nickjillings@1315 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nickjillings@1315 7763
nickjillings@1315 7764 // If none found, seek a pair
nickjillings@1315 7765 if ( !conv ) {
nickjillings@1315 7766 for ( conv2 in converters ) {
nickjillings@1315 7767
nickjillings@1315 7768 // If conv2 outputs current
nickjillings@1315 7769 tmp = conv2.split( " " );
nickjillings@1315 7770 if ( tmp[ 1 ] === current ) {
nickjillings@1315 7771
nickjillings@1315 7772 // If prev can be converted to accepted input
nickjillings@1315 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nickjillings@1315 7774 converters[ "* " + tmp[ 0 ] ];
nickjillings@1315 7775 if ( conv ) {
nickjillings@1315 7776 // Condense equivalence converters
nickjillings@1315 7777 if ( conv === true ) {
nickjillings@1315 7778 conv = converters[ conv2 ];
nickjillings@1315 7779
nickjillings@1315 7780 // Otherwise, insert the intermediate dataType
nickjillings@1315 7781 } else if ( converters[ conv2 ] !== true ) {
nickjillings@1315 7782 current = tmp[ 0 ];
nickjillings@1315 7783 dataTypes.unshift( tmp[ 1 ] );
nickjillings@1315 7784 }
nickjillings@1315 7785 break;
nickjillings@1315 7786 }
nickjillings@1315 7787 }
nickjillings@1315 7788 }
nickjillings@1315 7789 }
nickjillings@1315 7790
nickjillings@1315 7791 // Apply converter (if not an equivalence)
nickjillings@1315 7792 if ( conv !== true ) {
nickjillings@1315 7793
nickjillings@1315 7794 // Unless errors are allowed to bubble, catch and return them
nickjillings@1315 7795 if ( conv && s[ "throws" ] ) {
nickjillings@1315 7796 response = conv( response );
nickjillings@1315 7797 } else {
nickjillings@1315 7798 try {
nickjillings@1315 7799 response = conv( response );
nickjillings@1315 7800 } catch ( e ) {
nickjillings@1315 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nickjillings@1315 7802 }
nickjillings@1315 7803 }
nickjillings@1315 7804 }
nickjillings@1315 7805 }
nickjillings@1315 7806 }
nickjillings@1315 7807 }
nickjillings@1315 7808
nickjillings@1315 7809 return { state: "success", data: response };
nickjillings@1315 7810 }
nickjillings@1315 7811
nickjillings@1315 7812 jQuery.extend({
nickjillings@1315 7813
nickjillings@1315 7814 // Counter for holding the number of active queries
nickjillings@1315 7815 active: 0,
nickjillings@1315 7816
nickjillings@1315 7817 // Last-Modified header cache for next request
nickjillings@1315 7818 lastModified: {},
nickjillings@1315 7819 etag: {},
nickjillings@1315 7820
nickjillings@1315 7821 ajaxSettings: {
nickjillings@1315 7822 url: ajaxLocation,
nickjillings@1315 7823 type: "GET",
nickjillings@1315 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nickjillings@1315 7825 global: true,
nickjillings@1315 7826 processData: true,
nickjillings@1315 7827 async: true,
nickjillings@1315 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nickjillings@1315 7829 /*
nickjillings@1315 7830 timeout: 0,
nickjillings@1315 7831 data: null,
nickjillings@1315 7832 dataType: null,
nickjillings@1315 7833 username: null,
nickjillings@1315 7834 password: null,
nickjillings@1315 7835 cache: null,
nickjillings@1315 7836 throws: false,
nickjillings@1315 7837 traditional: false,
nickjillings@1315 7838 headers: {},
nickjillings@1315 7839 */
nickjillings@1315 7840
nickjillings@1315 7841 accepts: {
nickjillings@1315 7842 "*": allTypes,
nickjillings@1315 7843 text: "text/plain",
nickjillings@1315 7844 html: "text/html",
nickjillings@1315 7845 xml: "application/xml, text/xml",
nickjillings@1315 7846 json: "application/json, text/javascript"
nickjillings@1315 7847 },
nickjillings@1315 7848
nickjillings@1315 7849 contents: {
nickjillings@1315 7850 xml: /xml/,
nickjillings@1315 7851 html: /html/,
nickjillings@1315 7852 json: /json/
nickjillings@1315 7853 },
nickjillings@1315 7854
nickjillings@1315 7855 responseFields: {
nickjillings@1315 7856 xml: "responseXML",
nickjillings@1315 7857 text: "responseText",
nickjillings@1315 7858 json: "responseJSON"
nickjillings@1315 7859 },
nickjillings@1315 7860
nickjillings@1315 7861 // Data converters
nickjillings@1315 7862 // Keys separate source (or catchall "*") and destination types with a single space
nickjillings@1315 7863 converters: {
nickjillings@1315 7864
nickjillings@1315 7865 // Convert anything to text
nickjillings@1315 7866 "* text": String,
nickjillings@1315 7867
nickjillings@1315 7868 // Text to html (true = no transformation)
nickjillings@1315 7869 "text html": true,
nickjillings@1315 7870
nickjillings@1315 7871 // Evaluate text as a json expression
nickjillings@1315 7872 "text json": jQuery.parseJSON,
nickjillings@1315 7873
nickjillings@1315 7874 // Parse text as xml
nickjillings@1315 7875 "text xml": jQuery.parseXML
nickjillings@1315 7876 },
nickjillings@1315 7877
nickjillings@1315 7878 // For options that shouldn't be deep extended:
nickjillings@1315 7879 // you can add your own custom options here if
nickjillings@1315 7880 // and when you create one that shouldn't be
nickjillings@1315 7881 // deep extended (see ajaxExtend)
nickjillings@1315 7882 flatOptions: {
nickjillings@1315 7883 url: true,
nickjillings@1315 7884 context: true
nickjillings@1315 7885 }
nickjillings@1315 7886 },
nickjillings@1315 7887
nickjillings@1315 7888 // Creates a full fledged settings object into target
nickjillings@1315 7889 // with both ajaxSettings and settings fields.
nickjillings@1315 7890 // If target is omitted, writes into ajaxSettings.
nickjillings@1315 7891 ajaxSetup: function( target, settings ) {
nickjillings@1315 7892 return settings ?
nickjillings@1315 7893
nickjillings@1315 7894 // Building a settings object
nickjillings@1315 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nickjillings@1315 7896
nickjillings@1315 7897 // Extending ajaxSettings
nickjillings@1315 7898 ajaxExtend( jQuery.ajaxSettings, target );
nickjillings@1315 7899 },
nickjillings@1315 7900
nickjillings@1315 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nickjillings@1315 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nickjillings@1315 7903
nickjillings@1315 7904 // Main method
nickjillings@1315 7905 ajax: function( url, options ) {
nickjillings@1315 7906
nickjillings@1315 7907 // If url is an object, simulate pre-1.5 signature
nickjillings@1315 7908 if ( typeof url === "object" ) {
nickjillings@1315 7909 options = url;
nickjillings@1315 7910 url = undefined;
nickjillings@1315 7911 }
nickjillings@1315 7912
nickjillings@1315 7913 // Force options to be an object
nickjillings@1315 7914 options = options || {};
nickjillings@1315 7915
nickjillings@1315 7916 var transport,
nickjillings@1315 7917 // URL without anti-cache param
nickjillings@1315 7918 cacheURL,
nickjillings@1315 7919 // Response headers
nickjillings@1315 7920 responseHeadersString,
nickjillings@1315 7921 responseHeaders,
nickjillings@1315 7922 // timeout handle
nickjillings@1315 7923 timeoutTimer,
nickjillings@1315 7924 // Cross-domain detection vars
nickjillings@1315 7925 parts,
nickjillings@1315 7926 // To know if global events are to be dispatched
nickjillings@1315 7927 fireGlobals,
nickjillings@1315 7928 // Loop variable
nickjillings@1315 7929 i,
nickjillings@1315 7930 // Create the final options object
nickjillings@1315 7931 s = jQuery.ajaxSetup( {}, options ),
nickjillings@1315 7932 // Callbacks context
nickjillings@1315 7933 callbackContext = s.context || s,
nickjillings@1315 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nickjillings@1315 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nickjillings@1315 7936 jQuery( callbackContext ) :
nickjillings@1315 7937 jQuery.event,
nickjillings@1315 7938 // Deferreds
nickjillings@1315 7939 deferred = jQuery.Deferred(),
nickjillings@1315 7940 completeDeferred = jQuery.Callbacks("once memory"),
nickjillings@1315 7941 // Status-dependent callbacks
nickjillings@1315 7942 statusCode = s.statusCode || {},
nickjillings@1315 7943 // Headers (they are sent all at once)
nickjillings@1315 7944 requestHeaders = {},
nickjillings@1315 7945 requestHeadersNames = {},
nickjillings@1315 7946 // The jqXHR state
nickjillings@1315 7947 state = 0,
nickjillings@1315 7948 // Default abort message
nickjillings@1315 7949 strAbort = "canceled",
nickjillings@1315 7950 // Fake xhr
nickjillings@1315 7951 jqXHR = {
nickjillings@1315 7952 readyState: 0,
nickjillings@1315 7953
nickjillings@1315 7954 // Builds headers hashtable if needed
nickjillings@1315 7955 getResponseHeader: function( key ) {
nickjillings@1315 7956 var match;
nickjillings@1315 7957 if ( state === 2 ) {
nickjillings@1315 7958 if ( !responseHeaders ) {
nickjillings@1315 7959 responseHeaders = {};
nickjillings@1315 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nickjillings@1315 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nickjillings@1315 7962 }
nickjillings@1315 7963 }
nickjillings@1315 7964 match = responseHeaders[ key.toLowerCase() ];
nickjillings@1315 7965 }
nickjillings@1315 7966 return match == null ? null : match;
nickjillings@1315 7967 },
nickjillings@1315 7968
nickjillings@1315 7969 // Raw string
nickjillings@1315 7970 getAllResponseHeaders: function() {
nickjillings@1315 7971 return state === 2 ? responseHeadersString : null;
nickjillings@1315 7972 },
nickjillings@1315 7973
nickjillings@1315 7974 // Caches the header
nickjillings@1315 7975 setRequestHeader: function( name, value ) {
nickjillings@1315 7976 var lname = name.toLowerCase();
nickjillings@1315 7977 if ( !state ) {
nickjillings@1315 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nickjillings@1315 7979 requestHeaders[ name ] = value;
nickjillings@1315 7980 }
nickjillings@1315 7981 return this;
nickjillings@1315 7982 },
nickjillings@1315 7983
nickjillings@1315 7984 // Overrides response content-type header
nickjillings@1315 7985 overrideMimeType: function( type ) {
nickjillings@1315 7986 if ( !state ) {
nickjillings@1315 7987 s.mimeType = type;
nickjillings@1315 7988 }
nickjillings@1315 7989 return this;
nickjillings@1315 7990 },
nickjillings@1315 7991
nickjillings@1315 7992 // Status-dependent callbacks
nickjillings@1315 7993 statusCode: function( map ) {
nickjillings@1315 7994 var code;
nickjillings@1315 7995 if ( map ) {
nickjillings@1315 7996 if ( state < 2 ) {
nickjillings@1315 7997 for ( code in map ) {
nickjillings@1315 7998 // Lazy-add the new callback in a way that preserves old ones
nickjillings@1315 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nickjillings@1315 8000 }
nickjillings@1315 8001 } else {
nickjillings@1315 8002 // Execute the appropriate callbacks
nickjillings@1315 8003 jqXHR.always( map[ jqXHR.status ] );
nickjillings@1315 8004 }
nickjillings@1315 8005 }
nickjillings@1315 8006 return this;
nickjillings@1315 8007 },
nickjillings@1315 8008
nickjillings@1315 8009 // Cancel the request
nickjillings@1315 8010 abort: function( statusText ) {
nickjillings@1315 8011 var finalText = statusText || strAbort;
nickjillings@1315 8012 if ( transport ) {
nickjillings@1315 8013 transport.abort( finalText );
nickjillings@1315 8014 }
nickjillings@1315 8015 done( 0, finalText );
nickjillings@1315 8016 return this;
nickjillings@1315 8017 }
nickjillings@1315 8018 };
nickjillings@1315 8019
nickjillings@1315 8020 // Attach deferreds
nickjillings@1315 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nickjillings@1315 8022 jqXHR.success = jqXHR.done;
nickjillings@1315 8023 jqXHR.error = jqXHR.fail;
nickjillings@1315 8024
nickjillings@1315 8025 // Remove hash character (#7531: and string promotion)
nickjillings@1315 8026 // Add protocol if not provided (prefilters might expect it)
nickjillings@1315 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nickjillings@1315 8028 // We also use the url parameter if available
nickjillings@1315 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nickjillings@1315 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nickjillings@1315 8031
nickjillings@1315 8032 // Alias method option to type as per ticket #12004
nickjillings@1315 8033 s.type = options.method || options.type || s.method || s.type;
nickjillings@1315 8034
nickjillings@1315 8035 // Extract dataTypes list
nickjillings@1315 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nickjillings@1315 8037
nickjillings@1315 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nickjillings@1315 8039 if ( s.crossDomain == null ) {
nickjillings@1315 8040 parts = rurl.exec( s.url.toLowerCase() );
nickjillings@1315 8041 s.crossDomain = !!( parts &&
nickjillings@1315 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nickjillings@1315 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nickjillings@1315 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nickjillings@1315 8045 );
nickjillings@1315 8046 }
nickjillings@1315 8047
nickjillings@1315 8048 // Convert data if not already a string
nickjillings@1315 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nickjillings@1315 8050 s.data = jQuery.param( s.data, s.traditional );
nickjillings@1315 8051 }
nickjillings@1315 8052
nickjillings@1315 8053 // Apply prefilters
nickjillings@1315 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nickjillings@1315 8055
nickjillings@1315 8056 // If request was aborted inside a prefilter, stop there
nickjillings@1315 8057 if ( state === 2 ) {
nickjillings@1315 8058 return jqXHR;
nickjillings@1315 8059 }
nickjillings@1315 8060
nickjillings@1315 8061 // We can fire global events as of now if asked to
nickjillings@1315 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nickjillings@1315 8063 fireGlobals = jQuery.event && s.global;
nickjillings@1315 8064
nickjillings@1315 8065 // Watch for a new set of requests
nickjillings@1315 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nickjillings@1315 8067 jQuery.event.trigger("ajaxStart");
nickjillings@1315 8068 }
nickjillings@1315 8069
nickjillings@1315 8070 // Uppercase the type
nickjillings@1315 8071 s.type = s.type.toUpperCase();
nickjillings@1315 8072
nickjillings@1315 8073 // Determine if request has content
nickjillings@1315 8074 s.hasContent = !rnoContent.test( s.type );
nickjillings@1315 8075
nickjillings@1315 8076 // Save the URL in case we're toying with the If-Modified-Since
nickjillings@1315 8077 // and/or If-None-Match header later on
nickjillings@1315 8078 cacheURL = s.url;
nickjillings@1315 8079
nickjillings@1315 8080 // More options handling for requests with no content
nickjillings@1315 8081 if ( !s.hasContent ) {
nickjillings@1315 8082
nickjillings@1315 8083 // If data is available, append data to url
nickjillings@1315 8084 if ( s.data ) {
nickjillings@1315 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nickjillings@1315 8086 // #9682: remove data so that it's not used in an eventual retry
nickjillings@1315 8087 delete s.data;
nickjillings@1315 8088 }
nickjillings@1315 8089
nickjillings@1315 8090 // Add anti-cache in url if needed
nickjillings@1315 8091 if ( s.cache === false ) {
nickjillings@1315 8092 s.url = rts.test( cacheURL ) ?
nickjillings@1315 8093
nickjillings@1315 8094 // If there is already a '_' parameter, set its value
nickjillings@1315 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nickjillings@1315 8096
nickjillings@1315 8097 // Otherwise add one to the end
nickjillings@1315 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nickjillings@1315 8099 }
nickjillings@1315 8100 }
nickjillings@1315 8101
nickjillings@1315 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1315 8103 if ( s.ifModified ) {
nickjillings@1315 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nickjillings@1315 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nickjillings@1315 8106 }
nickjillings@1315 8107 if ( jQuery.etag[ cacheURL ] ) {
nickjillings@1315 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nickjillings@1315 8109 }
nickjillings@1315 8110 }
nickjillings@1315 8111
nickjillings@1315 8112 // Set the correct header, if data is being sent
nickjillings@1315 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nickjillings@1315 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nickjillings@1315 8115 }
nickjillings@1315 8116
nickjillings@1315 8117 // Set the Accepts header for the server, depending on the dataType
nickjillings@1315 8118 jqXHR.setRequestHeader(
nickjillings@1315 8119 "Accept",
nickjillings@1315 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nickjillings@1315 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nickjillings@1315 8122 s.accepts[ "*" ]
nickjillings@1315 8123 );
nickjillings@1315 8124
nickjillings@1315 8125 // Check for headers option
nickjillings@1315 8126 for ( i in s.headers ) {
nickjillings@1315 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nickjillings@1315 8128 }
nickjillings@1315 8129
nickjillings@1315 8130 // Allow custom headers/mimetypes and early abort
nickjillings@1315 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nickjillings@1315 8132 // Abort if not done already and return
nickjillings@1315 8133 return jqXHR.abort();
nickjillings@1315 8134 }
nickjillings@1315 8135
nickjillings@1315 8136 // Aborting is no longer a cancellation
nickjillings@1315 8137 strAbort = "abort";
nickjillings@1315 8138
nickjillings@1315 8139 // Install callbacks on deferreds
nickjillings@1315 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nickjillings@1315 8141 jqXHR[ i ]( s[ i ] );
nickjillings@1315 8142 }
nickjillings@1315 8143
nickjillings@1315 8144 // Get transport
nickjillings@1315 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nickjillings@1315 8146
nickjillings@1315 8147 // If no transport, we auto-abort
nickjillings@1315 8148 if ( !transport ) {
nickjillings@1315 8149 done( -1, "No Transport" );
nickjillings@1315 8150 } else {
nickjillings@1315 8151 jqXHR.readyState = 1;
nickjillings@1315 8152
nickjillings@1315 8153 // Send global event
nickjillings@1315 8154 if ( fireGlobals ) {
nickjillings@1315 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nickjillings@1315 8156 }
nickjillings@1315 8157 // Timeout
nickjillings@1315 8158 if ( s.async && s.timeout > 0 ) {
nickjillings@1315 8159 timeoutTimer = setTimeout(function() {
nickjillings@1315 8160 jqXHR.abort("timeout");
nickjillings@1315 8161 }, s.timeout );
nickjillings@1315 8162 }
nickjillings@1315 8163
nickjillings@1315 8164 try {
nickjillings@1315 8165 state = 1;
nickjillings@1315 8166 transport.send( requestHeaders, done );
nickjillings@1315 8167 } catch ( e ) {
nickjillings@1315 8168 // Propagate exception as error if not done
nickjillings@1315 8169 if ( state < 2 ) {
nickjillings@1315 8170 done( -1, e );
nickjillings@1315 8171 // Simply rethrow otherwise
nickjillings@1315 8172 } else {
nickjillings@1315 8173 throw e;
nickjillings@1315 8174 }
nickjillings@1315 8175 }
nickjillings@1315 8176 }
nickjillings@1315 8177
nickjillings@1315 8178 // Callback for when everything is done
nickjillings@1315 8179 function done( status, nativeStatusText, responses, headers ) {
nickjillings@1315 8180 var isSuccess, success, error, response, modified,
nickjillings@1315 8181 statusText = nativeStatusText;
nickjillings@1315 8182
nickjillings@1315 8183 // Called once
nickjillings@1315 8184 if ( state === 2 ) {
nickjillings@1315 8185 return;
nickjillings@1315 8186 }
nickjillings@1315 8187
nickjillings@1315 8188 // State is "done" now
nickjillings@1315 8189 state = 2;
nickjillings@1315 8190
nickjillings@1315 8191 // Clear timeout if it exists
nickjillings@1315 8192 if ( timeoutTimer ) {
nickjillings@1315 8193 clearTimeout( timeoutTimer );
nickjillings@1315 8194 }
nickjillings@1315 8195
nickjillings@1315 8196 // Dereference transport for early garbage collection
nickjillings@1315 8197 // (no matter how long the jqXHR object will be used)
nickjillings@1315 8198 transport = undefined;
nickjillings@1315 8199
nickjillings@1315 8200 // Cache response headers
nickjillings@1315 8201 responseHeadersString = headers || "";
nickjillings@1315 8202
nickjillings@1315 8203 // Set readyState
nickjillings@1315 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nickjillings@1315 8205
nickjillings@1315 8206 // Determine if successful
nickjillings@1315 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nickjillings@1315 8208
nickjillings@1315 8209 // Get response data
nickjillings@1315 8210 if ( responses ) {
nickjillings@1315 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nickjillings@1315 8212 }
nickjillings@1315 8213
nickjillings@1315 8214 // Convert no matter what (that way responseXXX fields are always set)
nickjillings@1315 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nickjillings@1315 8216
nickjillings@1315 8217 // If successful, handle type chaining
nickjillings@1315 8218 if ( isSuccess ) {
nickjillings@1315 8219
nickjillings@1315 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1315 8221 if ( s.ifModified ) {
nickjillings@1315 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nickjillings@1315 8223 if ( modified ) {
nickjillings@1315 8224 jQuery.lastModified[ cacheURL ] = modified;
nickjillings@1315 8225 }
nickjillings@1315 8226 modified = jqXHR.getResponseHeader("etag");
nickjillings@1315 8227 if ( modified ) {
nickjillings@1315 8228 jQuery.etag[ cacheURL ] = modified;
nickjillings@1315 8229 }
nickjillings@1315 8230 }
nickjillings@1315 8231
nickjillings@1315 8232 // if no content
nickjillings@1315 8233 if ( status === 204 || s.type === "HEAD" ) {
nickjillings@1315 8234 statusText = "nocontent";
nickjillings@1315 8235
nickjillings@1315 8236 // if not modified
nickjillings@1315 8237 } else if ( status === 304 ) {
nickjillings@1315 8238 statusText = "notmodified";
nickjillings@1315 8239
nickjillings@1315 8240 // If we have data, let's convert it
nickjillings@1315 8241 } else {
nickjillings@1315 8242 statusText = response.state;
nickjillings@1315 8243 success = response.data;
nickjillings@1315 8244 error = response.error;
nickjillings@1315 8245 isSuccess = !error;
nickjillings@1315 8246 }
nickjillings@1315 8247 } else {
nickjillings@1315 8248 // Extract error from statusText and normalize for non-aborts
nickjillings@1315 8249 error = statusText;
nickjillings@1315 8250 if ( status || !statusText ) {
nickjillings@1315 8251 statusText = "error";
nickjillings@1315 8252 if ( status < 0 ) {
nickjillings@1315 8253 status = 0;
nickjillings@1315 8254 }
nickjillings@1315 8255 }
nickjillings@1315 8256 }
nickjillings@1315 8257
nickjillings@1315 8258 // Set data for the fake xhr object
nickjillings@1315 8259 jqXHR.status = status;
nickjillings@1315 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nickjillings@1315 8261
nickjillings@1315 8262 // Success/Error
nickjillings@1315 8263 if ( isSuccess ) {
nickjillings@1315 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nickjillings@1315 8265 } else {
nickjillings@1315 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nickjillings@1315 8267 }
nickjillings@1315 8268
nickjillings@1315 8269 // Status-dependent callbacks
nickjillings@1315 8270 jqXHR.statusCode( statusCode );
nickjillings@1315 8271 statusCode = undefined;
nickjillings@1315 8272
nickjillings@1315 8273 if ( fireGlobals ) {
nickjillings@1315 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nickjillings@1315 8275 [ jqXHR, s, isSuccess ? success : error ] );
nickjillings@1315 8276 }
nickjillings@1315 8277
nickjillings@1315 8278 // Complete
nickjillings@1315 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nickjillings@1315 8280
nickjillings@1315 8281 if ( fireGlobals ) {
nickjillings@1315 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nickjillings@1315 8283 // Handle the global AJAX counter
nickjillings@1315 8284 if ( !( --jQuery.active ) ) {
nickjillings@1315 8285 jQuery.event.trigger("ajaxStop");
nickjillings@1315 8286 }
nickjillings@1315 8287 }
nickjillings@1315 8288 }
nickjillings@1315 8289
nickjillings@1315 8290 return jqXHR;
nickjillings@1315 8291 },
nickjillings@1315 8292
nickjillings@1315 8293 getJSON: function( url, data, callback ) {
nickjillings@1315 8294 return jQuery.get( url, data, callback, "json" );
nickjillings@1315 8295 },
nickjillings@1315 8296
nickjillings@1315 8297 getScript: function( url, callback ) {
nickjillings@1315 8298 return jQuery.get( url, undefined, callback, "script" );
nickjillings@1315 8299 }
nickjillings@1315 8300 });
nickjillings@1315 8301
nickjillings@1315 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nickjillings@1315 8303 jQuery[ method ] = function( url, data, callback, type ) {
nickjillings@1315 8304 // Shift arguments if data argument was omitted
nickjillings@1315 8305 if ( jQuery.isFunction( data ) ) {
nickjillings@1315 8306 type = type || callback;
nickjillings@1315 8307 callback = data;
nickjillings@1315 8308 data = undefined;
nickjillings@1315 8309 }
nickjillings@1315 8310
nickjillings@1315 8311 return jQuery.ajax({
nickjillings@1315 8312 url: url,
nickjillings@1315 8313 type: method,
nickjillings@1315 8314 dataType: type,
nickjillings@1315 8315 data: data,
nickjillings@1315 8316 success: callback
nickjillings@1315 8317 });
nickjillings@1315 8318 };
nickjillings@1315 8319 });
nickjillings@1315 8320
nickjillings@1315 8321
nickjillings@1315 8322 jQuery._evalUrl = function( url ) {
nickjillings@1315 8323 return jQuery.ajax({
nickjillings@1315 8324 url: url,
nickjillings@1315 8325 type: "GET",
nickjillings@1315 8326 dataType: "script",
nickjillings@1315 8327 async: false,
nickjillings@1315 8328 global: false,
nickjillings@1315 8329 "throws": true
nickjillings@1315 8330 });
nickjillings@1315 8331 };
nickjillings@1315 8332
nickjillings@1315 8333
nickjillings@1315 8334 jQuery.fn.extend({
nickjillings@1315 8335 wrapAll: function( html ) {
nickjillings@1315 8336 var wrap;
nickjillings@1315 8337
nickjillings@1315 8338 if ( jQuery.isFunction( html ) ) {
nickjillings@1315 8339 return this.each(function( i ) {
nickjillings@1315 8340 jQuery( this ).wrapAll( html.call(this, i) );
nickjillings@1315 8341 });
nickjillings@1315 8342 }
nickjillings@1315 8343
nickjillings@1315 8344 if ( this[ 0 ] ) {
nickjillings@1315 8345
nickjillings@1315 8346 // The elements to wrap the target around
nickjillings@1315 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nickjillings@1315 8348
nickjillings@1315 8349 if ( this[ 0 ].parentNode ) {
nickjillings@1315 8350 wrap.insertBefore( this[ 0 ] );
nickjillings@1315 8351 }
nickjillings@1315 8352
nickjillings@1315 8353 wrap.map(function() {
nickjillings@1315 8354 var elem = this;
nickjillings@1315 8355
nickjillings@1315 8356 while ( elem.firstElementChild ) {
nickjillings@1315 8357 elem = elem.firstElementChild;
nickjillings@1315 8358 }
nickjillings@1315 8359
nickjillings@1315 8360 return elem;
nickjillings@1315 8361 }).append( this );
nickjillings@1315 8362 }
nickjillings@1315 8363
nickjillings@1315 8364 return this;
nickjillings@1315 8365 },
nickjillings@1315 8366
nickjillings@1315 8367 wrapInner: function( html ) {
nickjillings@1315 8368 if ( jQuery.isFunction( html ) ) {
nickjillings@1315 8369 return this.each(function( i ) {
nickjillings@1315 8370 jQuery( this ).wrapInner( html.call(this, i) );
nickjillings@1315 8371 });
nickjillings@1315 8372 }
nickjillings@1315 8373
nickjillings@1315 8374 return this.each(function() {
nickjillings@1315 8375 var self = jQuery( this ),
nickjillings@1315 8376 contents = self.contents();
nickjillings@1315 8377
nickjillings@1315 8378 if ( contents.length ) {
nickjillings@1315 8379 contents.wrapAll( html );
nickjillings@1315 8380
nickjillings@1315 8381 } else {
nickjillings@1315 8382 self.append( html );
nickjillings@1315 8383 }
nickjillings@1315 8384 });
nickjillings@1315 8385 },
nickjillings@1315 8386
nickjillings@1315 8387 wrap: function( html ) {
nickjillings@1315 8388 var isFunction = jQuery.isFunction( html );
nickjillings@1315 8389
nickjillings@1315 8390 return this.each(function( i ) {
nickjillings@1315 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nickjillings@1315 8392 });
nickjillings@1315 8393 },
nickjillings@1315 8394
nickjillings@1315 8395 unwrap: function() {
nickjillings@1315 8396 return this.parent().each(function() {
nickjillings@1315 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nickjillings@1315 8398 jQuery( this ).replaceWith( this.childNodes );
nickjillings@1315 8399 }
nickjillings@1315 8400 }).end();
nickjillings@1315 8401 }
nickjillings@1315 8402 });
nickjillings@1315 8403
nickjillings@1315 8404
nickjillings@1315 8405 jQuery.expr.filters.hidden = function( elem ) {
nickjillings@1315 8406 // Support: Opera <= 12.12
nickjillings@1315 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nickjillings@1315 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nickjillings@1315 8409 };
nickjillings@1315 8410 jQuery.expr.filters.visible = function( elem ) {
nickjillings@1315 8411 return !jQuery.expr.filters.hidden( elem );
nickjillings@1315 8412 };
nickjillings@1315 8413
nickjillings@1315 8414
nickjillings@1315 8415
nickjillings@1315 8416
nickjillings@1315 8417 var r20 = /%20/g,
nickjillings@1315 8418 rbracket = /\[\]$/,
nickjillings@1315 8419 rCRLF = /\r?\n/g,
nickjillings@1315 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nickjillings@1315 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nickjillings@1315 8422
nickjillings@1315 8423 function buildParams( prefix, obj, traditional, add ) {
nickjillings@1315 8424 var name;
nickjillings@1315 8425
nickjillings@1315 8426 if ( jQuery.isArray( obj ) ) {
nickjillings@1315 8427 // Serialize array item.
nickjillings@1315 8428 jQuery.each( obj, function( i, v ) {
nickjillings@1315 8429 if ( traditional || rbracket.test( prefix ) ) {
nickjillings@1315 8430 // Treat each array item as a scalar.
nickjillings@1315 8431 add( prefix, v );
nickjillings@1315 8432
nickjillings@1315 8433 } else {
nickjillings@1315 8434 // Item is non-scalar (array or object), encode its numeric index.
nickjillings@1315 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nickjillings@1315 8436 }
nickjillings@1315 8437 });
nickjillings@1315 8438
nickjillings@1315 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nickjillings@1315 8440 // Serialize object item.
nickjillings@1315 8441 for ( name in obj ) {
nickjillings@1315 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nickjillings@1315 8443 }
nickjillings@1315 8444
nickjillings@1315 8445 } else {
nickjillings@1315 8446 // Serialize scalar item.
nickjillings@1315 8447 add( prefix, obj );
nickjillings@1315 8448 }
nickjillings@1315 8449 }
nickjillings@1315 8450
nickjillings@1315 8451 // Serialize an array of form elements or a set of
nickjillings@1315 8452 // key/values into a query string
nickjillings@1315 8453 jQuery.param = function( a, traditional ) {
nickjillings@1315 8454 var prefix,
nickjillings@1315 8455 s = [],
nickjillings@1315 8456 add = function( key, value ) {
nickjillings@1315 8457 // If value is a function, invoke it and return its value
nickjillings@1315 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nickjillings@1315 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nickjillings@1315 8460 };
nickjillings@1315 8461
nickjillings@1315 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nickjillings@1315 8463 if ( traditional === undefined ) {
nickjillings@1315 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nickjillings@1315 8465 }
nickjillings@1315 8466
nickjillings@1315 8467 // If an array was passed in, assume that it is an array of form elements.
nickjillings@1315 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nickjillings@1315 8469 // Serialize the form elements
nickjillings@1315 8470 jQuery.each( a, function() {
nickjillings@1315 8471 add( this.name, this.value );
nickjillings@1315 8472 });
nickjillings@1315 8473
nickjillings@1315 8474 } else {
nickjillings@1315 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nickjillings@1315 8476 // did it), otherwise encode params recursively.
nickjillings@1315 8477 for ( prefix in a ) {
nickjillings@1315 8478 buildParams( prefix, a[ prefix ], traditional, add );
nickjillings@1315 8479 }
nickjillings@1315 8480 }
nickjillings@1315 8481
nickjillings@1315 8482 // Return the resulting serialization
nickjillings@1315 8483 return s.join( "&" ).replace( r20, "+" );
nickjillings@1315 8484 };
nickjillings@1315 8485
nickjillings@1315 8486 jQuery.fn.extend({
nickjillings@1315 8487 serialize: function() {
nickjillings@1315 8488 return jQuery.param( this.serializeArray() );
nickjillings@1315 8489 },
nickjillings@1315 8490 serializeArray: function() {
nickjillings@1315 8491 return this.map(function() {
nickjillings@1315 8492 // Can add propHook for "elements" to filter or add form elements
nickjillings@1315 8493 var elements = jQuery.prop( this, "elements" );
nickjillings@1315 8494 return elements ? jQuery.makeArray( elements ) : this;
nickjillings@1315 8495 })
nickjillings@1315 8496 .filter(function() {
nickjillings@1315 8497 var type = this.type;
nickjillings@1315 8498
nickjillings@1315 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nickjillings@1315 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nickjillings@1315 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nickjillings@1315 8502 ( this.checked || !rcheckableType.test( type ) );
nickjillings@1315 8503 })
nickjillings@1315 8504 .map(function( i, elem ) {
nickjillings@1315 8505 var val = jQuery( this ).val();
nickjillings@1315 8506
nickjillings@1315 8507 return val == null ?
nickjillings@1315 8508 null :
nickjillings@1315 8509 jQuery.isArray( val ) ?
nickjillings@1315 8510 jQuery.map( val, function( val ) {
nickjillings@1315 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1315 8512 }) :
nickjillings@1315 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1315 8514 }).get();
nickjillings@1315 8515 }
nickjillings@1315 8516 });
nickjillings@1315 8517
nickjillings@1315 8518
nickjillings@1315 8519 jQuery.ajaxSettings.xhr = function() {
nickjillings@1315 8520 try {
nickjillings@1315 8521 return new XMLHttpRequest();
nickjillings@1315 8522 } catch( e ) {}
nickjillings@1315 8523 };
nickjillings@1315 8524
nickjillings@1315 8525 var xhrId = 0,
nickjillings@1315 8526 xhrCallbacks = {},
nickjillings@1315 8527 xhrSuccessStatus = {
nickjillings@1315 8528 // file protocol always yields status code 0, assume 200
nickjillings@1315 8529 0: 200,
nickjillings@1315 8530 // Support: IE9
nickjillings@1315 8531 // #1450: sometimes IE returns 1223 when it should be 204
nickjillings@1315 8532 1223: 204
nickjillings@1315 8533 },
nickjillings@1315 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nickjillings@1315 8535
nickjillings@1315 8536 // Support: IE9
nickjillings@1315 8537 // Open requests must be manually aborted on unload (#5280)
nickjillings@1315 8538 // See https://support.microsoft.com/kb/2856746 for more info
nickjillings@1315 8539 if ( window.attachEvent ) {
nickjillings@1315 8540 window.attachEvent( "onunload", function() {
nickjillings@1315 8541 for ( var key in xhrCallbacks ) {
nickjillings@1315 8542 xhrCallbacks[ key ]();
nickjillings@1315 8543 }
nickjillings@1315 8544 });
nickjillings@1315 8545 }
nickjillings@1315 8546
nickjillings@1315 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nickjillings@1315 8548 support.ajax = xhrSupported = !!xhrSupported;
nickjillings@1315 8549
nickjillings@1315 8550 jQuery.ajaxTransport(function( options ) {
nickjillings@1315 8551 var callback;
nickjillings@1315 8552
nickjillings@1315 8553 // Cross domain only allowed if supported through XMLHttpRequest
nickjillings@1315 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nickjillings@1315 8555 return {
nickjillings@1315 8556 send: function( headers, complete ) {
nickjillings@1315 8557 var i,
nickjillings@1315 8558 xhr = options.xhr(),
nickjillings@1315 8559 id = ++xhrId;
nickjillings@1315 8560
nickjillings@1315 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nickjillings@1315 8562
nickjillings@1315 8563 // Apply custom fields if provided
nickjillings@1315 8564 if ( options.xhrFields ) {
nickjillings@1315 8565 for ( i in options.xhrFields ) {
nickjillings@1315 8566 xhr[ i ] = options.xhrFields[ i ];
nickjillings@1315 8567 }
nickjillings@1315 8568 }
nickjillings@1315 8569
nickjillings@1315 8570 // Override mime type if needed
nickjillings@1315 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nickjillings@1315 8572 xhr.overrideMimeType( options.mimeType );
nickjillings@1315 8573 }
nickjillings@1315 8574
nickjillings@1315 8575 // X-Requested-With header
nickjillings@1315 8576 // For cross-domain requests, seeing as conditions for a preflight are
nickjillings@1315 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nickjillings@1315 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nickjillings@1315 8579 // For same-domain requests, won't change header if already provided.
nickjillings@1315 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nickjillings@1315 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nickjillings@1315 8582 }
nickjillings@1315 8583
nickjillings@1315 8584 // Set headers
nickjillings@1315 8585 for ( i in headers ) {
nickjillings@1315 8586 xhr.setRequestHeader( i, headers[ i ] );
nickjillings@1315 8587 }
nickjillings@1315 8588
nickjillings@1315 8589 // Callback
nickjillings@1315 8590 callback = function( type ) {
nickjillings@1315 8591 return function() {
nickjillings@1315 8592 if ( callback ) {
nickjillings@1315 8593 delete xhrCallbacks[ id ];
nickjillings@1315 8594 callback = xhr.onload = xhr.onerror = null;
nickjillings@1315 8595
nickjillings@1315 8596 if ( type === "abort" ) {
nickjillings@1315 8597 xhr.abort();
nickjillings@1315 8598 } else if ( type === "error" ) {
nickjillings@1315 8599 complete(
nickjillings@1315 8600 // file: protocol always yields status 0; see #8605, #14207
nickjillings@1315 8601 xhr.status,
nickjillings@1315 8602 xhr.statusText
nickjillings@1315 8603 );
nickjillings@1315 8604 } else {
nickjillings@1315 8605 complete(
nickjillings@1315 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nickjillings@1315 8607 xhr.statusText,
nickjillings@1315 8608 // Support: IE9
nickjillings@1315 8609 // Accessing binary-data responseText throws an exception
nickjillings@1315 8610 // (#11426)
nickjillings@1315 8611 typeof xhr.responseText === "string" ? {
nickjillings@1315 8612 text: xhr.responseText
nickjillings@1315 8613 } : undefined,
nickjillings@1315 8614 xhr.getAllResponseHeaders()
nickjillings@1315 8615 );
nickjillings@1315 8616 }
nickjillings@1315 8617 }
nickjillings@1315 8618 };
nickjillings@1315 8619 };
nickjillings@1315 8620
nickjillings@1315 8621 // Listen to events
nickjillings@1315 8622 xhr.onload = callback();
nickjillings@1315 8623 xhr.onerror = callback("error");
nickjillings@1315 8624
nickjillings@1315 8625 // Create the abort callback
nickjillings@1315 8626 callback = xhrCallbacks[ id ] = callback("abort");
nickjillings@1315 8627
nickjillings@1315 8628 try {
nickjillings@1315 8629 // Do send the request (this may raise an exception)
nickjillings@1315 8630 xhr.send( options.hasContent && options.data || null );
nickjillings@1315 8631 } catch ( e ) {
nickjillings@1315 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nickjillings@1315 8633 if ( callback ) {
nickjillings@1315 8634 throw e;
nickjillings@1315 8635 }
nickjillings@1315 8636 }
nickjillings@1315 8637 },
nickjillings@1315 8638
nickjillings@1315 8639 abort: function() {
nickjillings@1315 8640 if ( callback ) {
nickjillings@1315 8641 callback();
nickjillings@1315 8642 }
nickjillings@1315 8643 }
nickjillings@1315 8644 };
nickjillings@1315 8645 }
nickjillings@1315 8646 });
nickjillings@1315 8647
nickjillings@1315 8648
nickjillings@1315 8649
nickjillings@1315 8650
nickjillings@1315 8651 // Install script dataType
nickjillings@1315 8652 jQuery.ajaxSetup({
nickjillings@1315 8653 accepts: {
nickjillings@1315 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nickjillings@1315 8655 },
nickjillings@1315 8656 contents: {
nickjillings@1315 8657 script: /(?:java|ecma)script/
nickjillings@1315 8658 },
nickjillings@1315 8659 converters: {
nickjillings@1315 8660 "text script": function( text ) {
nickjillings@1315 8661 jQuery.globalEval( text );
nickjillings@1315 8662 return text;
nickjillings@1315 8663 }
nickjillings@1315 8664 }
nickjillings@1315 8665 });
nickjillings@1315 8666
nickjillings@1315 8667 // Handle cache's special case and crossDomain
nickjillings@1315 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nickjillings@1315 8669 if ( s.cache === undefined ) {
nickjillings@1315 8670 s.cache = false;
nickjillings@1315 8671 }
nickjillings@1315 8672 if ( s.crossDomain ) {
nickjillings@1315 8673 s.type = "GET";
nickjillings@1315 8674 }
nickjillings@1315 8675 });
nickjillings@1315 8676
nickjillings@1315 8677 // Bind script tag hack transport
nickjillings@1315 8678 jQuery.ajaxTransport( "script", function( s ) {
nickjillings@1315 8679 // This transport only deals with cross domain requests
nickjillings@1315 8680 if ( s.crossDomain ) {
nickjillings@1315 8681 var script, callback;
nickjillings@1315 8682 return {
nickjillings@1315 8683 send: function( _, complete ) {
nickjillings@1315 8684 script = jQuery("<script>").prop({
nickjillings@1315 8685 async: true,
nickjillings@1315 8686 charset: s.scriptCharset,
nickjillings@1315 8687 src: s.url
nickjillings@1315 8688 }).on(
nickjillings@1315 8689 "load error",
nickjillings@1315 8690 callback = function( evt ) {
nickjillings@1315 8691 script.remove();
nickjillings@1315 8692 callback = null;
nickjillings@1315 8693 if ( evt ) {
nickjillings@1315 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nickjillings@1315 8695 }
nickjillings@1315 8696 }
nickjillings@1315 8697 );
nickjillings@1315 8698 document.head.appendChild( script[ 0 ] );
nickjillings@1315 8699 },
nickjillings@1315 8700 abort: function() {
nickjillings@1315 8701 if ( callback ) {
nickjillings@1315 8702 callback();
nickjillings@1315 8703 }
nickjillings@1315 8704 }
nickjillings@1315 8705 };
nickjillings@1315 8706 }
nickjillings@1315 8707 });
nickjillings@1315 8708
nickjillings@1315 8709
nickjillings@1315 8710
nickjillings@1315 8711
nickjillings@1315 8712 var oldCallbacks = [],
nickjillings@1315 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nickjillings@1315 8714
nickjillings@1315 8715 // Default jsonp settings
nickjillings@1315 8716 jQuery.ajaxSetup({
nickjillings@1315 8717 jsonp: "callback",
nickjillings@1315 8718 jsonpCallback: function() {
nickjillings@1315 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nickjillings@1315 8720 this[ callback ] = true;
nickjillings@1315 8721 return callback;
nickjillings@1315 8722 }
nickjillings@1315 8723 });
nickjillings@1315 8724
nickjillings@1315 8725 // Detect, normalize options and install callbacks for jsonp requests
nickjillings@1315 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nickjillings@1315 8727
nickjillings@1315 8728 var callbackName, overwritten, responseContainer,
nickjillings@1315 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nickjillings@1315 8730 "url" :
nickjillings@1315 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nickjillings@1315 8732 );
nickjillings@1315 8733
nickjillings@1315 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nickjillings@1315 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nickjillings@1315 8736
nickjillings@1315 8737 // Get callback name, remembering preexisting value associated with it
nickjillings@1315 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nickjillings@1315 8739 s.jsonpCallback() :
nickjillings@1315 8740 s.jsonpCallback;
nickjillings@1315 8741
nickjillings@1315 8742 // Insert callback into url or form data
nickjillings@1315 8743 if ( jsonProp ) {
nickjillings@1315 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nickjillings@1315 8745 } else if ( s.jsonp !== false ) {
nickjillings@1315 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nickjillings@1315 8747 }
nickjillings@1315 8748
nickjillings@1315 8749 // Use data converter to retrieve json after script execution
nickjillings@1315 8750 s.converters["script json"] = function() {
nickjillings@1315 8751 if ( !responseContainer ) {
nickjillings@1315 8752 jQuery.error( callbackName + " was not called" );
nickjillings@1315 8753 }
nickjillings@1315 8754 return responseContainer[ 0 ];
nickjillings@1315 8755 };
nickjillings@1315 8756
nickjillings@1315 8757 // force json dataType
nickjillings@1315 8758 s.dataTypes[ 0 ] = "json";
nickjillings@1315 8759
nickjillings@1315 8760 // Install callback
nickjillings@1315 8761 overwritten = window[ callbackName ];
nickjillings@1315 8762 window[ callbackName ] = function() {
nickjillings@1315 8763 responseContainer = arguments;
nickjillings@1315 8764 };
nickjillings@1315 8765
nickjillings@1315 8766 // Clean-up function (fires after converters)
nickjillings@1315 8767 jqXHR.always(function() {
nickjillings@1315 8768 // Restore preexisting value
nickjillings@1315 8769 window[ callbackName ] = overwritten;
nickjillings@1315 8770
nickjillings@1315 8771 // Save back as free
nickjillings@1315 8772 if ( s[ callbackName ] ) {
nickjillings@1315 8773 // make sure that re-using the options doesn't screw things around
nickjillings@1315 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nickjillings@1315 8775
nickjillings@1315 8776 // save the callback name for future use
nickjillings@1315 8777 oldCallbacks.push( callbackName );
nickjillings@1315 8778 }
nickjillings@1315 8779
nickjillings@1315 8780 // Call if it was a function and we have a response
nickjillings@1315 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nickjillings@1315 8782 overwritten( responseContainer[ 0 ] );
nickjillings@1315 8783 }
nickjillings@1315 8784
nickjillings@1315 8785 responseContainer = overwritten = undefined;
nickjillings@1315 8786 });
nickjillings@1315 8787
nickjillings@1315 8788 // Delegate to script
nickjillings@1315 8789 return "script";
nickjillings@1315 8790 }
nickjillings@1315 8791 });
nickjillings@1315 8792
nickjillings@1315 8793
nickjillings@1315 8794
nickjillings@1315 8795
nickjillings@1315 8796 // data: string of html
nickjillings@1315 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nickjillings@1315 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nickjillings@1315 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nickjillings@1315 8800 if ( !data || typeof data !== "string" ) {
nickjillings@1315 8801 return null;
nickjillings@1315 8802 }
nickjillings@1315 8803 if ( typeof context === "boolean" ) {
nickjillings@1315 8804 keepScripts = context;
nickjillings@1315 8805 context = false;
nickjillings@1315 8806 }
nickjillings@1315 8807 context = context || document;
nickjillings@1315 8808
nickjillings@1315 8809 var parsed = rsingleTag.exec( data ),
nickjillings@1315 8810 scripts = !keepScripts && [];
nickjillings@1315 8811
nickjillings@1315 8812 // Single tag
nickjillings@1315 8813 if ( parsed ) {
nickjillings@1315 8814 return [ context.createElement( parsed[1] ) ];
nickjillings@1315 8815 }
nickjillings@1315 8816
nickjillings@1315 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nickjillings@1315 8818
nickjillings@1315 8819 if ( scripts && scripts.length ) {
nickjillings@1315 8820 jQuery( scripts ).remove();
nickjillings@1315 8821 }
nickjillings@1315 8822
nickjillings@1315 8823 return jQuery.merge( [], parsed.childNodes );
nickjillings@1315 8824 };
nickjillings@1315 8825
nickjillings@1315 8826
nickjillings@1315 8827 // Keep a copy of the old load method
nickjillings@1315 8828 var _load = jQuery.fn.load;
nickjillings@1315 8829
nickjillings@1315 8830 /**
nickjillings@1315 8831 * Load a url into a page
nickjillings@1315 8832 */
nickjillings@1315 8833 jQuery.fn.load = function( url, params, callback ) {
nickjillings@1315 8834 if ( typeof url !== "string" && _load ) {
nickjillings@1315 8835 return _load.apply( this, arguments );
nickjillings@1315 8836 }
nickjillings@1315 8837
nickjillings@1315 8838 var selector, type, response,
nickjillings@1315 8839 self = this,
nickjillings@1315 8840 off = url.indexOf(" ");
nickjillings@1315 8841
nickjillings@1315 8842 if ( off >= 0 ) {
nickjillings@1315 8843 selector = jQuery.trim( url.slice( off ) );
nickjillings@1315 8844 url = url.slice( 0, off );
nickjillings@1315 8845 }
nickjillings@1315 8846
nickjillings@1315 8847 // If it's a function
nickjillings@1315 8848 if ( jQuery.isFunction( params ) ) {
nickjillings@1315 8849
nickjillings@1315 8850 // We assume that it's the callback
nickjillings@1315 8851 callback = params;
nickjillings@1315 8852 params = undefined;
nickjillings@1315 8853
nickjillings@1315 8854 // Otherwise, build a param string
nickjillings@1315 8855 } else if ( params && typeof params === "object" ) {
nickjillings@1315 8856 type = "POST";
nickjillings@1315 8857 }
nickjillings@1315 8858
nickjillings@1315 8859 // If we have elements to modify, make the request
nickjillings@1315 8860 if ( self.length > 0 ) {
nickjillings@1315 8861 jQuery.ajax({
nickjillings@1315 8862 url: url,
nickjillings@1315 8863
nickjillings@1315 8864 // if "type" variable is undefined, then "GET" method will be used
nickjillings@1315 8865 type: type,
nickjillings@1315 8866 dataType: "html",
nickjillings@1315 8867 data: params
nickjillings@1315 8868 }).done(function( responseText ) {
nickjillings@1315 8869
nickjillings@1315 8870 // Save response for use in complete callback
nickjillings@1315 8871 response = arguments;
nickjillings@1315 8872
nickjillings@1315 8873 self.html( selector ?
nickjillings@1315 8874
nickjillings@1315 8875 // If a selector was specified, locate the right elements in a dummy div
nickjillings@1315 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nickjillings@1315 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nickjillings@1315 8878
nickjillings@1315 8879 // Otherwise use the full result
nickjillings@1315 8880 responseText );
nickjillings@1315 8881
nickjillings@1315 8882 }).complete( callback && function( jqXHR, status ) {
nickjillings@1315 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nickjillings@1315 8884 });
nickjillings@1315 8885 }
nickjillings@1315 8886
nickjillings@1315 8887 return this;
nickjillings@1315 8888 };
nickjillings@1315 8889
nickjillings@1315 8890
nickjillings@1315 8891
nickjillings@1315 8892
nickjillings@1315 8893 // Attach a bunch of functions for handling common AJAX events
nickjillings@1315 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nickjillings@1315 8895 jQuery.fn[ type ] = function( fn ) {
nickjillings@1315 8896 return this.on( type, fn );
nickjillings@1315 8897 };
nickjillings@1315 8898 });
nickjillings@1315 8899
nickjillings@1315 8900
nickjillings@1315 8901
nickjillings@1315 8902
nickjillings@1315 8903 jQuery.expr.filters.animated = function( elem ) {
nickjillings@1315 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nickjillings@1315 8905 return elem === fn.elem;
nickjillings@1315 8906 }).length;
nickjillings@1315 8907 };
nickjillings@1315 8908
nickjillings@1315 8909
nickjillings@1315 8910
nickjillings@1315 8911
nickjillings@1315 8912 var docElem = window.document.documentElement;
nickjillings@1315 8913
nickjillings@1315 8914 /**
nickjillings@1315 8915 * Gets a window from an element
nickjillings@1315 8916 */
nickjillings@1315 8917 function getWindow( elem ) {
nickjillings@1315 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nickjillings@1315 8919 }
nickjillings@1315 8920
nickjillings@1315 8921 jQuery.offset = {
nickjillings@1315 8922 setOffset: function( elem, options, i ) {
nickjillings@1315 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nickjillings@1315 8924 position = jQuery.css( elem, "position" ),
nickjillings@1315 8925 curElem = jQuery( elem ),
nickjillings@1315 8926 props = {};
nickjillings@1315 8927
nickjillings@1315 8928 // Set position first, in-case top/left are set even on static elem
nickjillings@1315 8929 if ( position === "static" ) {
nickjillings@1315 8930 elem.style.position = "relative";
nickjillings@1315 8931 }
nickjillings@1315 8932
nickjillings@1315 8933 curOffset = curElem.offset();
nickjillings@1315 8934 curCSSTop = jQuery.css( elem, "top" );
nickjillings@1315 8935 curCSSLeft = jQuery.css( elem, "left" );
nickjillings@1315 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nickjillings@1315 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nickjillings@1315 8938
nickjillings@1315 8939 // Need to be able to calculate position if either
nickjillings@1315 8940 // top or left is auto and position is either absolute or fixed
nickjillings@1315 8941 if ( calculatePosition ) {
nickjillings@1315 8942 curPosition = curElem.position();
nickjillings@1315 8943 curTop = curPosition.top;
nickjillings@1315 8944 curLeft = curPosition.left;
nickjillings@1315 8945
nickjillings@1315 8946 } else {
nickjillings@1315 8947 curTop = parseFloat( curCSSTop ) || 0;
nickjillings@1315 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nickjillings@1315 8949 }
nickjillings@1315 8950
nickjillings@1315 8951 if ( jQuery.isFunction( options ) ) {
nickjillings@1315 8952 options = options.call( elem, i, curOffset );
nickjillings@1315 8953 }
nickjillings@1315 8954
nickjillings@1315 8955 if ( options.top != null ) {
nickjillings@1315 8956 props.top = ( options.top - curOffset.top ) + curTop;
nickjillings@1315 8957 }
nickjillings@1315 8958 if ( options.left != null ) {
nickjillings@1315 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nickjillings@1315 8960 }
nickjillings@1315 8961
nickjillings@1315 8962 if ( "using" in options ) {
nickjillings@1315 8963 options.using.call( elem, props );
nickjillings@1315 8964
nickjillings@1315 8965 } else {
nickjillings@1315 8966 curElem.css( props );
nickjillings@1315 8967 }
nickjillings@1315 8968 }
nickjillings@1315 8969 };
nickjillings@1315 8970
nickjillings@1315 8971 jQuery.fn.extend({
nickjillings@1315 8972 offset: function( options ) {
nickjillings@1315 8973 if ( arguments.length ) {
nickjillings@1315 8974 return options === undefined ?
nickjillings@1315 8975 this :
nickjillings@1315 8976 this.each(function( i ) {
nickjillings@1315 8977 jQuery.offset.setOffset( this, options, i );
nickjillings@1315 8978 });
nickjillings@1315 8979 }
nickjillings@1315 8980
nickjillings@1315 8981 var docElem, win,
nickjillings@1315 8982 elem = this[ 0 ],
nickjillings@1315 8983 box = { top: 0, left: 0 },
nickjillings@1315 8984 doc = elem && elem.ownerDocument;
nickjillings@1315 8985
nickjillings@1315 8986 if ( !doc ) {
nickjillings@1315 8987 return;
nickjillings@1315 8988 }
nickjillings@1315 8989
nickjillings@1315 8990 docElem = doc.documentElement;
nickjillings@1315 8991
nickjillings@1315 8992 // Make sure it's not a disconnected DOM node
nickjillings@1315 8993 if ( !jQuery.contains( docElem, elem ) ) {
nickjillings@1315 8994 return box;
nickjillings@1315 8995 }
nickjillings@1315 8996
nickjillings@1315 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nickjillings@1315 8998 // If we don't have gBCR, just use 0,0 rather than error
nickjillings@1315 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nickjillings@1315 9000 box = elem.getBoundingClientRect();
nickjillings@1315 9001 }
nickjillings@1315 9002 win = getWindow( doc );
nickjillings@1315 9003 return {
nickjillings@1315 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nickjillings@1315 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nickjillings@1315 9006 };
nickjillings@1315 9007 },
nickjillings@1315 9008
nickjillings@1315 9009 position: function() {
nickjillings@1315 9010 if ( !this[ 0 ] ) {
nickjillings@1315 9011 return;
nickjillings@1315 9012 }
nickjillings@1315 9013
nickjillings@1315 9014 var offsetParent, offset,
nickjillings@1315 9015 elem = this[ 0 ],
nickjillings@1315 9016 parentOffset = { top: 0, left: 0 };
nickjillings@1315 9017
nickjillings@1315 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nickjillings@1315 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nickjillings@1315 9020 // Assume getBoundingClientRect is there when computed position is fixed
nickjillings@1315 9021 offset = elem.getBoundingClientRect();
nickjillings@1315 9022
nickjillings@1315 9023 } else {
nickjillings@1315 9024 // Get *real* offsetParent
nickjillings@1315 9025 offsetParent = this.offsetParent();
nickjillings@1315 9026
nickjillings@1315 9027 // Get correct offsets
nickjillings@1315 9028 offset = this.offset();
nickjillings@1315 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nickjillings@1315 9030 parentOffset = offsetParent.offset();
nickjillings@1315 9031 }
nickjillings@1315 9032
nickjillings@1315 9033 // Add offsetParent borders
nickjillings@1315 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nickjillings@1315 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nickjillings@1315 9036 }
nickjillings@1315 9037
nickjillings@1315 9038 // Subtract parent offsets and element margins
nickjillings@1315 9039 return {
nickjillings@1315 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nickjillings@1315 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nickjillings@1315 9042 };
nickjillings@1315 9043 },
nickjillings@1315 9044
nickjillings@1315 9045 offsetParent: function() {
nickjillings@1315 9046 return this.map(function() {
nickjillings@1315 9047 var offsetParent = this.offsetParent || docElem;
nickjillings@1315 9048
nickjillings@1315 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nickjillings@1315 9050 offsetParent = offsetParent.offsetParent;
nickjillings@1315 9051 }
nickjillings@1315 9052
nickjillings@1315 9053 return offsetParent || docElem;
nickjillings@1315 9054 });
nickjillings@1315 9055 }
nickjillings@1315 9056 });
nickjillings@1315 9057
nickjillings@1315 9058 // Create scrollLeft and scrollTop methods
nickjillings@1315 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nickjillings@1315 9060 var top = "pageYOffset" === prop;
nickjillings@1315 9061
nickjillings@1315 9062 jQuery.fn[ method ] = function( val ) {
nickjillings@1315 9063 return access( this, function( elem, method, val ) {
nickjillings@1315 9064 var win = getWindow( elem );
nickjillings@1315 9065
nickjillings@1315 9066 if ( val === undefined ) {
nickjillings@1315 9067 return win ? win[ prop ] : elem[ method ];
nickjillings@1315 9068 }
nickjillings@1315 9069
nickjillings@1315 9070 if ( win ) {
nickjillings@1315 9071 win.scrollTo(
nickjillings@1315 9072 !top ? val : window.pageXOffset,
nickjillings@1315 9073 top ? val : window.pageYOffset
nickjillings@1315 9074 );
nickjillings@1315 9075
nickjillings@1315 9076 } else {
nickjillings@1315 9077 elem[ method ] = val;
nickjillings@1315 9078 }
nickjillings@1315 9079 }, method, val, arguments.length, null );
nickjillings@1315 9080 };
nickjillings@1315 9081 });
nickjillings@1315 9082
nickjillings@1315 9083 // Support: Safari<7+, Chrome<37+
nickjillings@1315 9084 // Add the top/left cssHooks using jQuery.fn.position
nickjillings@1315 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nickjillings@1315 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nickjillings@1315 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nickjillings@1315 9088 // rather than make the css module depend on the offset module, just check for it here
nickjillings@1315 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nickjillings@1315 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nickjillings@1315 9091 function( elem, computed ) {
nickjillings@1315 9092 if ( computed ) {
nickjillings@1315 9093 computed = curCSS( elem, prop );
nickjillings@1315 9094 // If curCSS returns percentage, fallback to offset
nickjillings@1315 9095 return rnumnonpx.test( computed ) ?
nickjillings@1315 9096 jQuery( elem ).position()[ prop ] + "px" :
nickjillings@1315 9097 computed;
nickjillings@1315 9098 }
nickjillings@1315 9099 }
nickjillings@1315 9100 );
nickjillings@1315 9101 });
nickjillings@1315 9102
nickjillings@1315 9103
nickjillings@1315 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nickjillings@1315 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nickjillings@1315 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nickjillings@1315 9107 // Margin is only for outerHeight, outerWidth
nickjillings@1315 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nickjillings@1315 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nickjillings@1315 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nickjillings@1315 9111
nickjillings@1315 9112 return access( this, function( elem, type, value ) {
nickjillings@1315 9113 var doc;
nickjillings@1315 9114
nickjillings@1315 9115 if ( jQuery.isWindow( elem ) ) {
nickjillings@1315 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nickjillings@1315 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nickjillings@1315 9118 // https://github.com/jquery/jquery/pull/764
nickjillings@1315 9119 return elem.document.documentElement[ "client" + name ];
nickjillings@1315 9120 }
nickjillings@1315 9121
nickjillings@1315 9122 // Get document width or height
nickjillings@1315 9123 if ( elem.nodeType === 9 ) {
nickjillings@1315 9124 doc = elem.documentElement;
nickjillings@1315 9125
nickjillings@1315 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nickjillings@1315 9127 // whichever is greatest
nickjillings@1315 9128 return Math.max(
nickjillings@1315 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nickjillings@1315 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nickjillings@1315 9131 doc[ "client" + name ]
nickjillings@1315 9132 );
nickjillings@1315 9133 }
nickjillings@1315 9134
nickjillings@1315 9135 return value === undefined ?
nickjillings@1315 9136 // Get width or height on the element, requesting but not forcing parseFloat
nickjillings@1315 9137 jQuery.css( elem, type, extra ) :
nickjillings@1315 9138
nickjillings@1315 9139 // Set width or height on the element
nickjillings@1315 9140 jQuery.style( elem, type, value, extra );
nickjillings@1315 9141 }, type, chainable ? margin : undefined, chainable, null );
nickjillings@1315 9142 };
nickjillings@1315 9143 });
nickjillings@1315 9144 });
nickjillings@1315 9145
nickjillings@1315 9146
nickjillings@1315 9147 // The number of elements contained in the matched element set
nickjillings@1315 9148 jQuery.fn.size = function() {
nickjillings@1315 9149 return this.length;
nickjillings@1315 9150 };
nickjillings@1315 9151
nickjillings@1315 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nickjillings@1315 9153
nickjillings@1315 9154
nickjillings@1315 9155
nickjillings@1315 9156
nickjillings@1315 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nickjillings@1315 9158 // files that may use define, but not via a proper concatenation script that
nickjillings@1315 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nickjillings@1315 9160 // way to register. Lowercase jquery is used because AMD module names are
nickjillings@1315 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nickjillings@1315 9162 // file name. Do this after creating the global so that if an AMD module wants
nickjillings@1315 9163 // to call noConflict to hide this version of jQuery, it will work.
nickjillings@1315 9164
nickjillings@1315 9165 // Note that for maximum portability, libraries that are not jQuery should
nickjillings@1315 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nickjillings@1315 9167 // AMD loader is present. jQuery is a special case. For more information, see
nickjillings@1315 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nickjillings@1315 9169
nickjillings@1315 9170 if ( typeof define === "function" && define.amd ) {
nickjillings@1315 9171 define( "jquery", [], function() {
nickjillings@1315 9172 return jQuery;
nickjillings@1315 9173 });
nickjillings@1315 9174 }
nickjillings@1315 9175
nickjillings@1315 9176
nickjillings@1315 9177
nickjillings@1315 9178
nickjillings@1315 9179 var
nickjillings@1315 9180 // Map over jQuery in case of overwrite
nickjillings@1315 9181 _jQuery = window.jQuery,
nickjillings@1315 9182
nickjillings@1315 9183 // Map over the $ in case of overwrite
nickjillings@1315 9184 _$ = window.$;
nickjillings@1315 9185
nickjillings@1315 9186 jQuery.noConflict = function( deep ) {
nickjillings@1315 9187 if ( window.$ === jQuery ) {
nickjillings@1315 9188 window.$ = _$;
nickjillings@1315 9189 }
nickjillings@1315 9190
nickjillings@1315 9191 if ( deep && window.jQuery === jQuery ) {
nickjillings@1315 9192 window.jQuery = _jQuery;
nickjillings@1315 9193 }
nickjillings@1315 9194
nickjillings@1315 9195 return jQuery;
nickjillings@1315 9196 };
nickjillings@1315 9197
nickjillings@1315 9198 // Expose jQuery and $ identifiers, even in AMD
nickjillings@1315 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nickjillings@1315 9200 // and CommonJS for browser emulators (#13566)
nickjillings@1315 9201 if ( typeof noGlobal === strundefined ) {
nickjillings@1315 9202 window.jQuery = window.$ = jQuery;
nickjillings@1315 9203 }
nickjillings@1315 9204
nickjillings@1315 9205
nickjillings@1315 9206
nickjillings@1315 9207
nickjillings@1315 9208 return jQuery;
nickjillings@1315 9209
nickjillings@1315 9210 }));