annotate jquery-2.1.4.js @ 1350:b6389ceaeaa5

Confirmed working (using examples) on OSX (Chrome/Safari/Firefox)
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 14 Jan 2016 16:00:52 +0000
parents 64541cd9265d
children
rev   line source
nickjillings@1318 1 /*!
nickjillings@1318 2 * jQuery JavaScript Library v2.1.4
nickjillings@1318 3 * http://jquery.com/
nickjillings@1318 4 *
nickjillings@1318 5 * Includes Sizzle.js
nickjillings@1318 6 * http://sizzlejs.com/
nickjillings@1318 7 *
nickjillings@1318 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1318 9 * Released under the MIT license
nickjillings@1318 10 * http://jquery.org/license
nickjillings@1318 11 *
nickjillings@1318 12 * Date: 2015-04-28T16:01Z
nickjillings@1318 13 */
nickjillings@1318 14
nickjillings@1318 15 (function( global, factory ) {
nickjillings@1318 16
nickjillings@1318 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nickjillings@1318 18 // For CommonJS and CommonJS-like environments where a proper `window`
nickjillings@1318 19 // is present, execute the factory and get jQuery.
nickjillings@1318 20 // For environments that do not have a `window` with a `document`
nickjillings@1318 21 // (such as Node.js), expose a factory as module.exports.
nickjillings@1318 22 // This accentuates the need for the creation of a real `window`.
nickjillings@1318 23 // e.g. var jQuery = require("jquery")(window);
nickjillings@1318 24 // See ticket #14549 for more info.
nickjillings@1318 25 module.exports = global.document ?
nickjillings@1318 26 factory( global, true ) :
nickjillings@1318 27 function( w ) {
nickjillings@1318 28 if ( !w.document ) {
nickjillings@1318 29 throw new Error( "jQuery requires a window with a document" );
nickjillings@1318 30 }
nickjillings@1318 31 return factory( w );
nickjillings@1318 32 };
nickjillings@1318 33 } else {
nickjillings@1318 34 factory( global );
nickjillings@1318 35 }
nickjillings@1318 36
nickjillings@1318 37 // Pass this if window is not defined yet
nickjillings@1318 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nickjillings@1318 39
nickjillings@1318 40 // Support: Firefox 18+
nickjillings@1318 41 // Can't be in strict mode, several libs including ASP.NET trace
nickjillings@1318 42 // the stack via arguments.caller.callee and Firefox dies if
nickjillings@1318 43 // you try to trace through "use strict" call chains. (#13335)
nickjillings@1318 44 //
nickjillings@1318 45
nickjillings@1318 46 var arr = [];
nickjillings@1318 47
nickjillings@1318 48 var slice = arr.slice;
nickjillings@1318 49
nickjillings@1318 50 var concat = arr.concat;
nickjillings@1318 51
nickjillings@1318 52 var push = arr.push;
nickjillings@1318 53
nickjillings@1318 54 var indexOf = arr.indexOf;
nickjillings@1318 55
nickjillings@1318 56 var class2type = {};
nickjillings@1318 57
nickjillings@1318 58 var toString = class2type.toString;
nickjillings@1318 59
nickjillings@1318 60 var hasOwn = class2type.hasOwnProperty;
nickjillings@1318 61
nickjillings@1318 62 var support = {};
nickjillings@1318 63
nickjillings@1318 64
nickjillings@1318 65
nickjillings@1318 66 var
nickjillings@1318 67 // Use the correct document accordingly with window argument (sandbox)
nickjillings@1318 68 document = window.document,
nickjillings@1318 69
nickjillings@1318 70 version = "2.1.4",
nickjillings@1318 71
nickjillings@1318 72 // Define a local copy of jQuery
nickjillings@1318 73 jQuery = function( selector, context ) {
nickjillings@1318 74 // The jQuery object is actually just the init constructor 'enhanced'
nickjillings@1318 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nickjillings@1318 76 return new jQuery.fn.init( selector, context );
nickjillings@1318 77 },
nickjillings@1318 78
nickjillings@1318 79 // Support: Android<4.1
nickjillings@1318 80 // Make sure we trim BOM and NBSP
nickjillings@1318 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nickjillings@1318 82
nickjillings@1318 83 // Matches dashed string for camelizing
nickjillings@1318 84 rmsPrefix = /^-ms-/,
nickjillings@1318 85 rdashAlpha = /-([\da-z])/gi,
nickjillings@1318 86
nickjillings@1318 87 // Used by jQuery.camelCase as callback to replace()
nickjillings@1318 88 fcamelCase = function( all, letter ) {
nickjillings@1318 89 return letter.toUpperCase();
nickjillings@1318 90 };
nickjillings@1318 91
nickjillings@1318 92 jQuery.fn = jQuery.prototype = {
nickjillings@1318 93 // The current version of jQuery being used
nickjillings@1318 94 jquery: version,
nickjillings@1318 95
nickjillings@1318 96 constructor: jQuery,
nickjillings@1318 97
nickjillings@1318 98 // Start with an empty selector
nickjillings@1318 99 selector: "",
nickjillings@1318 100
nickjillings@1318 101 // The default length of a jQuery object is 0
nickjillings@1318 102 length: 0,
nickjillings@1318 103
nickjillings@1318 104 toArray: function() {
nickjillings@1318 105 return slice.call( this );
nickjillings@1318 106 },
nickjillings@1318 107
nickjillings@1318 108 // Get the Nth element in the matched element set OR
nickjillings@1318 109 // Get the whole matched element set as a clean array
nickjillings@1318 110 get: function( num ) {
nickjillings@1318 111 return num != null ?
nickjillings@1318 112
nickjillings@1318 113 // Return just the one element from the set
nickjillings@1318 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nickjillings@1318 115
nickjillings@1318 116 // Return all the elements in a clean array
nickjillings@1318 117 slice.call( this );
nickjillings@1318 118 },
nickjillings@1318 119
nickjillings@1318 120 // Take an array of elements and push it onto the stack
nickjillings@1318 121 // (returning the new matched element set)
nickjillings@1318 122 pushStack: function( elems ) {
nickjillings@1318 123
nickjillings@1318 124 // Build a new jQuery matched element set
nickjillings@1318 125 var ret = jQuery.merge( this.constructor(), elems );
nickjillings@1318 126
nickjillings@1318 127 // Add the old object onto the stack (as a reference)
nickjillings@1318 128 ret.prevObject = this;
nickjillings@1318 129 ret.context = this.context;
nickjillings@1318 130
nickjillings@1318 131 // Return the newly-formed element set
nickjillings@1318 132 return ret;
nickjillings@1318 133 },
nickjillings@1318 134
nickjillings@1318 135 // Execute a callback for every element in the matched set.
nickjillings@1318 136 // (You can seed the arguments with an array of args, but this is
nickjillings@1318 137 // only used internally.)
nickjillings@1318 138 each: function( callback, args ) {
nickjillings@1318 139 return jQuery.each( this, callback, args );
nickjillings@1318 140 },
nickjillings@1318 141
nickjillings@1318 142 map: function( callback ) {
nickjillings@1318 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nickjillings@1318 144 return callback.call( elem, i, elem );
nickjillings@1318 145 }));
nickjillings@1318 146 },
nickjillings@1318 147
nickjillings@1318 148 slice: function() {
nickjillings@1318 149 return this.pushStack( slice.apply( this, arguments ) );
nickjillings@1318 150 },
nickjillings@1318 151
nickjillings@1318 152 first: function() {
nickjillings@1318 153 return this.eq( 0 );
nickjillings@1318 154 },
nickjillings@1318 155
nickjillings@1318 156 last: function() {
nickjillings@1318 157 return this.eq( -1 );
nickjillings@1318 158 },
nickjillings@1318 159
nickjillings@1318 160 eq: function( i ) {
nickjillings@1318 161 var len = this.length,
nickjillings@1318 162 j = +i + ( i < 0 ? len : 0 );
nickjillings@1318 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nickjillings@1318 164 },
nickjillings@1318 165
nickjillings@1318 166 end: function() {
nickjillings@1318 167 return this.prevObject || this.constructor(null);
nickjillings@1318 168 },
nickjillings@1318 169
nickjillings@1318 170 // For internal use only.
nickjillings@1318 171 // Behaves like an Array's method, not like a jQuery method.
nickjillings@1318 172 push: push,
nickjillings@1318 173 sort: arr.sort,
nickjillings@1318 174 splice: arr.splice
nickjillings@1318 175 };
nickjillings@1318 176
nickjillings@1318 177 jQuery.extend = jQuery.fn.extend = function() {
nickjillings@1318 178 var options, name, src, copy, copyIsArray, clone,
nickjillings@1318 179 target = arguments[0] || {},
nickjillings@1318 180 i = 1,
nickjillings@1318 181 length = arguments.length,
nickjillings@1318 182 deep = false;
nickjillings@1318 183
nickjillings@1318 184 // Handle a deep copy situation
nickjillings@1318 185 if ( typeof target === "boolean" ) {
nickjillings@1318 186 deep = target;
nickjillings@1318 187
nickjillings@1318 188 // Skip the boolean and the target
nickjillings@1318 189 target = arguments[ i ] || {};
nickjillings@1318 190 i++;
nickjillings@1318 191 }
nickjillings@1318 192
nickjillings@1318 193 // Handle case when target is a string or something (possible in deep copy)
nickjillings@1318 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nickjillings@1318 195 target = {};
nickjillings@1318 196 }
nickjillings@1318 197
nickjillings@1318 198 // Extend jQuery itself if only one argument is passed
nickjillings@1318 199 if ( i === length ) {
nickjillings@1318 200 target = this;
nickjillings@1318 201 i--;
nickjillings@1318 202 }
nickjillings@1318 203
nickjillings@1318 204 for ( ; i < length; i++ ) {
nickjillings@1318 205 // Only deal with non-null/undefined values
nickjillings@1318 206 if ( (options = arguments[ i ]) != null ) {
nickjillings@1318 207 // Extend the base object
nickjillings@1318 208 for ( name in options ) {
nickjillings@1318 209 src = target[ name ];
nickjillings@1318 210 copy = options[ name ];
nickjillings@1318 211
nickjillings@1318 212 // Prevent never-ending loop
nickjillings@1318 213 if ( target === copy ) {
nickjillings@1318 214 continue;
nickjillings@1318 215 }
nickjillings@1318 216
nickjillings@1318 217 // Recurse if we're merging plain objects or arrays
nickjillings@1318 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nickjillings@1318 219 if ( copyIsArray ) {
nickjillings@1318 220 copyIsArray = false;
nickjillings@1318 221 clone = src && jQuery.isArray(src) ? src : [];
nickjillings@1318 222
nickjillings@1318 223 } else {
nickjillings@1318 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nickjillings@1318 225 }
nickjillings@1318 226
nickjillings@1318 227 // Never move original objects, clone them
nickjillings@1318 228 target[ name ] = jQuery.extend( deep, clone, copy );
nickjillings@1318 229
nickjillings@1318 230 // Don't bring in undefined values
nickjillings@1318 231 } else if ( copy !== undefined ) {
nickjillings@1318 232 target[ name ] = copy;
nickjillings@1318 233 }
nickjillings@1318 234 }
nickjillings@1318 235 }
nickjillings@1318 236 }
nickjillings@1318 237
nickjillings@1318 238 // Return the modified object
nickjillings@1318 239 return target;
nickjillings@1318 240 };
nickjillings@1318 241
nickjillings@1318 242 jQuery.extend({
nickjillings@1318 243 // Unique for each copy of jQuery on the page
nickjillings@1318 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nickjillings@1318 245
nickjillings@1318 246 // Assume jQuery is ready without the ready module
nickjillings@1318 247 isReady: true,
nickjillings@1318 248
nickjillings@1318 249 error: function( msg ) {
nickjillings@1318 250 throw new Error( msg );
nickjillings@1318 251 },
nickjillings@1318 252
nickjillings@1318 253 noop: function() {},
nickjillings@1318 254
nickjillings@1318 255 isFunction: function( obj ) {
nickjillings@1318 256 return jQuery.type(obj) === "function";
nickjillings@1318 257 },
nickjillings@1318 258
nickjillings@1318 259 isArray: Array.isArray,
nickjillings@1318 260
nickjillings@1318 261 isWindow: function( obj ) {
nickjillings@1318 262 return obj != null && obj === obj.window;
nickjillings@1318 263 },
nickjillings@1318 264
nickjillings@1318 265 isNumeric: function( obj ) {
nickjillings@1318 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nickjillings@1318 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nickjillings@1318 268 // subtraction forces infinities to NaN
nickjillings@1318 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nickjillings@1318 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nickjillings@1318 271 },
nickjillings@1318 272
nickjillings@1318 273 isPlainObject: function( obj ) {
nickjillings@1318 274 // Not plain objects:
nickjillings@1318 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nickjillings@1318 276 // - DOM nodes
nickjillings@1318 277 // - window
nickjillings@1318 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nickjillings@1318 279 return false;
nickjillings@1318 280 }
nickjillings@1318 281
nickjillings@1318 282 if ( obj.constructor &&
nickjillings@1318 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nickjillings@1318 284 return false;
nickjillings@1318 285 }
nickjillings@1318 286
nickjillings@1318 287 // If the function hasn't returned already, we're confident that
nickjillings@1318 288 // |obj| is a plain object, created by {} or constructed with new Object
nickjillings@1318 289 return true;
nickjillings@1318 290 },
nickjillings@1318 291
nickjillings@1318 292 isEmptyObject: function( obj ) {
nickjillings@1318 293 var name;
nickjillings@1318 294 for ( name in obj ) {
nickjillings@1318 295 return false;
nickjillings@1318 296 }
nickjillings@1318 297 return true;
nickjillings@1318 298 },
nickjillings@1318 299
nickjillings@1318 300 type: function( obj ) {
nickjillings@1318 301 if ( obj == null ) {
nickjillings@1318 302 return obj + "";
nickjillings@1318 303 }
nickjillings@1318 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nickjillings@1318 305 return typeof obj === "object" || typeof obj === "function" ?
nickjillings@1318 306 class2type[ toString.call(obj) ] || "object" :
nickjillings@1318 307 typeof obj;
nickjillings@1318 308 },
nickjillings@1318 309
nickjillings@1318 310 // Evaluates a script in a global context
nickjillings@1318 311 globalEval: function( code ) {
nickjillings@1318 312 var script,
nickjillings@1318 313 indirect = eval;
nickjillings@1318 314
nickjillings@1318 315 code = jQuery.trim( code );
nickjillings@1318 316
nickjillings@1318 317 if ( code ) {
nickjillings@1318 318 // If the code includes a valid, prologue position
nickjillings@1318 319 // strict mode pragma, execute code by injecting a
nickjillings@1318 320 // script tag into the document.
nickjillings@1318 321 if ( code.indexOf("use strict") === 1 ) {
nickjillings@1318 322 script = document.createElement("script");
nickjillings@1318 323 script.text = code;
nickjillings@1318 324 document.head.appendChild( script ).parentNode.removeChild( script );
nickjillings@1318 325 } else {
nickjillings@1318 326 // Otherwise, avoid the DOM node creation, insertion
nickjillings@1318 327 // and removal by using an indirect global eval
nickjillings@1318 328 indirect( code );
nickjillings@1318 329 }
nickjillings@1318 330 }
nickjillings@1318 331 },
nickjillings@1318 332
nickjillings@1318 333 // Convert dashed to camelCase; used by the css and data modules
nickjillings@1318 334 // Support: IE9-11+
nickjillings@1318 335 // Microsoft forgot to hump their vendor prefix (#9572)
nickjillings@1318 336 camelCase: function( string ) {
nickjillings@1318 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nickjillings@1318 338 },
nickjillings@1318 339
nickjillings@1318 340 nodeName: function( elem, name ) {
nickjillings@1318 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nickjillings@1318 342 },
nickjillings@1318 343
nickjillings@1318 344 // args is for internal usage only
nickjillings@1318 345 each: function( obj, callback, args ) {
nickjillings@1318 346 var value,
nickjillings@1318 347 i = 0,
nickjillings@1318 348 length = obj.length,
nickjillings@1318 349 isArray = isArraylike( obj );
nickjillings@1318 350
nickjillings@1318 351 if ( args ) {
nickjillings@1318 352 if ( isArray ) {
nickjillings@1318 353 for ( ; i < length; i++ ) {
nickjillings@1318 354 value = callback.apply( obj[ i ], args );
nickjillings@1318 355
nickjillings@1318 356 if ( value === false ) {
nickjillings@1318 357 break;
nickjillings@1318 358 }
nickjillings@1318 359 }
nickjillings@1318 360 } else {
nickjillings@1318 361 for ( i in obj ) {
nickjillings@1318 362 value = callback.apply( obj[ i ], args );
nickjillings@1318 363
nickjillings@1318 364 if ( value === false ) {
nickjillings@1318 365 break;
nickjillings@1318 366 }
nickjillings@1318 367 }
nickjillings@1318 368 }
nickjillings@1318 369
nickjillings@1318 370 // A special, fast, case for the most common use of each
nickjillings@1318 371 } else {
nickjillings@1318 372 if ( isArray ) {
nickjillings@1318 373 for ( ; i < length; i++ ) {
nickjillings@1318 374 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1318 375
nickjillings@1318 376 if ( value === false ) {
nickjillings@1318 377 break;
nickjillings@1318 378 }
nickjillings@1318 379 }
nickjillings@1318 380 } else {
nickjillings@1318 381 for ( i in obj ) {
nickjillings@1318 382 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1318 383
nickjillings@1318 384 if ( value === false ) {
nickjillings@1318 385 break;
nickjillings@1318 386 }
nickjillings@1318 387 }
nickjillings@1318 388 }
nickjillings@1318 389 }
nickjillings@1318 390
nickjillings@1318 391 return obj;
nickjillings@1318 392 },
nickjillings@1318 393
nickjillings@1318 394 // Support: Android<4.1
nickjillings@1318 395 trim: function( text ) {
nickjillings@1318 396 return text == null ?
nickjillings@1318 397 "" :
nickjillings@1318 398 ( text + "" ).replace( rtrim, "" );
nickjillings@1318 399 },
nickjillings@1318 400
nickjillings@1318 401 // results is for internal usage only
nickjillings@1318 402 makeArray: function( arr, results ) {
nickjillings@1318 403 var ret = results || [];
nickjillings@1318 404
nickjillings@1318 405 if ( arr != null ) {
nickjillings@1318 406 if ( isArraylike( Object(arr) ) ) {
nickjillings@1318 407 jQuery.merge( ret,
nickjillings@1318 408 typeof arr === "string" ?
nickjillings@1318 409 [ arr ] : arr
nickjillings@1318 410 );
nickjillings@1318 411 } else {
nickjillings@1318 412 push.call( ret, arr );
nickjillings@1318 413 }
nickjillings@1318 414 }
nickjillings@1318 415
nickjillings@1318 416 return ret;
nickjillings@1318 417 },
nickjillings@1318 418
nickjillings@1318 419 inArray: function( elem, arr, i ) {
nickjillings@1318 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nickjillings@1318 421 },
nickjillings@1318 422
nickjillings@1318 423 merge: function( first, second ) {
nickjillings@1318 424 var len = +second.length,
nickjillings@1318 425 j = 0,
nickjillings@1318 426 i = first.length;
nickjillings@1318 427
nickjillings@1318 428 for ( ; j < len; j++ ) {
nickjillings@1318 429 first[ i++ ] = second[ j ];
nickjillings@1318 430 }
nickjillings@1318 431
nickjillings@1318 432 first.length = i;
nickjillings@1318 433
nickjillings@1318 434 return first;
nickjillings@1318 435 },
nickjillings@1318 436
nickjillings@1318 437 grep: function( elems, callback, invert ) {
nickjillings@1318 438 var callbackInverse,
nickjillings@1318 439 matches = [],
nickjillings@1318 440 i = 0,
nickjillings@1318 441 length = elems.length,
nickjillings@1318 442 callbackExpect = !invert;
nickjillings@1318 443
nickjillings@1318 444 // Go through the array, only saving the items
nickjillings@1318 445 // that pass the validator function
nickjillings@1318 446 for ( ; i < length; i++ ) {
nickjillings@1318 447 callbackInverse = !callback( elems[ i ], i );
nickjillings@1318 448 if ( callbackInverse !== callbackExpect ) {
nickjillings@1318 449 matches.push( elems[ i ] );
nickjillings@1318 450 }
nickjillings@1318 451 }
nickjillings@1318 452
nickjillings@1318 453 return matches;
nickjillings@1318 454 },
nickjillings@1318 455
nickjillings@1318 456 // arg is for internal usage only
nickjillings@1318 457 map: function( elems, callback, arg ) {
nickjillings@1318 458 var value,
nickjillings@1318 459 i = 0,
nickjillings@1318 460 length = elems.length,
nickjillings@1318 461 isArray = isArraylike( elems ),
nickjillings@1318 462 ret = [];
nickjillings@1318 463
nickjillings@1318 464 // Go through the array, translating each of the items to their new values
nickjillings@1318 465 if ( isArray ) {
nickjillings@1318 466 for ( ; i < length; i++ ) {
nickjillings@1318 467 value = callback( elems[ i ], i, arg );
nickjillings@1318 468
nickjillings@1318 469 if ( value != null ) {
nickjillings@1318 470 ret.push( value );
nickjillings@1318 471 }
nickjillings@1318 472 }
nickjillings@1318 473
nickjillings@1318 474 // Go through every key on the object,
nickjillings@1318 475 } else {
nickjillings@1318 476 for ( i in elems ) {
nickjillings@1318 477 value = callback( elems[ i ], i, arg );
nickjillings@1318 478
nickjillings@1318 479 if ( value != null ) {
nickjillings@1318 480 ret.push( value );
nickjillings@1318 481 }
nickjillings@1318 482 }
nickjillings@1318 483 }
nickjillings@1318 484
nickjillings@1318 485 // Flatten any nested arrays
nickjillings@1318 486 return concat.apply( [], ret );
nickjillings@1318 487 },
nickjillings@1318 488
nickjillings@1318 489 // A global GUID counter for objects
nickjillings@1318 490 guid: 1,
nickjillings@1318 491
nickjillings@1318 492 // Bind a function to a context, optionally partially applying any
nickjillings@1318 493 // arguments.
nickjillings@1318 494 proxy: function( fn, context ) {
nickjillings@1318 495 var tmp, args, proxy;
nickjillings@1318 496
nickjillings@1318 497 if ( typeof context === "string" ) {
nickjillings@1318 498 tmp = fn[ context ];
nickjillings@1318 499 context = fn;
nickjillings@1318 500 fn = tmp;
nickjillings@1318 501 }
nickjillings@1318 502
nickjillings@1318 503 // Quick check to determine if target is callable, in the spec
nickjillings@1318 504 // this throws a TypeError, but we will just return undefined.
nickjillings@1318 505 if ( !jQuery.isFunction( fn ) ) {
nickjillings@1318 506 return undefined;
nickjillings@1318 507 }
nickjillings@1318 508
nickjillings@1318 509 // Simulated bind
nickjillings@1318 510 args = slice.call( arguments, 2 );
nickjillings@1318 511 proxy = function() {
nickjillings@1318 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nickjillings@1318 513 };
nickjillings@1318 514
nickjillings@1318 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nickjillings@1318 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nickjillings@1318 517
nickjillings@1318 518 return proxy;
nickjillings@1318 519 },
nickjillings@1318 520
nickjillings@1318 521 now: Date.now,
nickjillings@1318 522
nickjillings@1318 523 // jQuery.support is not used in Core but other projects attach their
nickjillings@1318 524 // properties to it so it needs to exist.
nickjillings@1318 525 support: support
nickjillings@1318 526 });
nickjillings@1318 527
nickjillings@1318 528 // Populate the class2type map
nickjillings@1318 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nickjillings@1318 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nickjillings@1318 531 });
nickjillings@1318 532
nickjillings@1318 533 function isArraylike( obj ) {
nickjillings@1318 534
nickjillings@1318 535 // Support: iOS 8.2 (not reproducible in simulator)
nickjillings@1318 536 // `in` check used to prevent JIT error (gh-2145)
nickjillings@1318 537 // hasOwn isn't used here due to false negatives
nickjillings@1318 538 // regarding Nodelist length in IE
nickjillings@1318 539 var length = "length" in obj && obj.length,
nickjillings@1318 540 type = jQuery.type( obj );
nickjillings@1318 541
nickjillings@1318 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nickjillings@1318 543 return false;
nickjillings@1318 544 }
nickjillings@1318 545
nickjillings@1318 546 if ( obj.nodeType === 1 && length ) {
nickjillings@1318 547 return true;
nickjillings@1318 548 }
nickjillings@1318 549
nickjillings@1318 550 return type === "array" || length === 0 ||
nickjillings@1318 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nickjillings@1318 552 }
nickjillings@1318 553 var Sizzle =
nickjillings@1318 554 /*!
nickjillings@1318 555 * Sizzle CSS Selector Engine v2.2.0-pre
nickjillings@1318 556 * http://sizzlejs.com/
nickjillings@1318 557 *
nickjillings@1318 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1318 559 * Released under the MIT license
nickjillings@1318 560 * http://jquery.org/license
nickjillings@1318 561 *
nickjillings@1318 562 * Date: 2014-12-16
nickjillings@1318 563 */
nickjillings@1318 564 (function( window ) {
nickjillings@1318 565
nickjillings@1318 566 var i,
nickjillings@1318 567 support,
nickjillings@1318 568 Expr,
nickjillings@1318 569 getText,
nickjillings@1318 570 isXML,
nickjillings@1318 571 tokenize,
nickjillings@1318 572 compile,
nickjillings@1318 573 select,
nickjillings@1318 574 outermostContext,
nickjillings@1318 575 sortInput,
nickjillings@1318 576 hasDuplicate,
nickjillings@1318 577
nickjillings@1318 578 // Local document vars
nickjillings@1318 579 setDocument,
nickjillings@1318 580 document,
nickjillings@1318 581 docElem,
nickjillings@1318 582 documentIsHTML,
nickjillings@1318 583 rbuggyQSA,
nickjillings@1318 584 rbuggyMatches,
nickjillings@1318 585 matches,
nickjillings@1318 586 contains,
nickjillings@1318 587
nickjillings@1318 588 // Instance-specific data
nickjillings@1318 589 expando = "sizzle" + 1 * new Date(),
nickjillings@1318 590 preferredDoc = window.document,
nickjillings@1318 591 dirruns = 0,
nickjillings@1318 592 done = 0,
nickjillings@1318 593 classCache = createCache(),
nickjillings@1318 594 tokenCache = createCache(),
nickjillings@1318 595 compilerCache = createCache(),
nickjillings@1318 596 sortOrder = function( a, b ) {
nickjillings@1318 597 if ( a === b ) {
nickjillings@1318 598 hasDuplicate = true;
nickjillings@1318 599 }
nickjillings@1318 600 return 0;
nickjillings@1318 601 },
nickjillings@1318 602
nickjillings@1318 603 // General-purpose constants
nickjillings@1318 604 MAX_NEGATIVE = 1 << 31,
nickjillings@1318 605
nickjillings@1318 606 // Instance methods
nickjillings@1318 607 hasOwn = ({}).hasOwnProperty,
nickjillings@1318 608 arr = [],
nickjillings@1318 609 pop = arr.pop,
nickjillings@1318 610 push_native = arr.push,
nickjillings@1318 611 push = arr.push,
nickjillings@1318 612 slice = arr.slice,
nickjillings@1318 613 // Use a stripped-down indexOf as it's faster than native
nickjillings@1318 614 // http://jsperf.com/thor-indexof-vs-for/5
nickjillings@1318 615 indexOf = function( list, elem ) {
nickjillings@1318 616 var i = 0,
nickjillings@1318 617 len = list.length;
nickjillings@1318 618 for ( ; i < len; i++ ) {
nickjillings@1318 619 if ( list[i] === elem ) {
nickjillings@1318 620 return i;
nickjillings@1318 621 }
nickjillings@1318 622 }
nickjillings@1318 623 return -1;
nickjillings@1318 624 },
nickjillings@1318 625
nickjillings@1318 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nickjillings@1318 627
nickjillings@1318 628 // Regular expressions
nickjillings@1318 629
nickjillings@1318 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nickjillings@1318 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nickjillings@1318 632 // http://www.w3.org/TR/css3-syntax/#characters
nickjillings@1318 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nickjillings@1318 634
nickjillings@1318 635 // Loosely modeled on CSS identifier characters
nickjillings@1318 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nickjillings@1318 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nickjillings@1318 638 identifier = characterEncoding.replace( "w", "w#" ),
nickjillings@1318 639
nickjillings@1318 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nickjillings@1318 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nickjillings@1318 642 // Operator (capture 2)
nickjillings@1318 643 "*([*^$|!~]?=)" + whitespace +
nickjillings@1318 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nickjillings@1318 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nickjillings@1318 646 "*\\]",
nickjillings@1318 647
nickjillings@1318 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nickjillings@1318 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nickjillings@1318 650 // 1. quoted (capture 3; capture 4 or capture 5)
nickjillings@1318 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nickjillings@1318 652 // 2. simple (capture 6)
nickjillings@1318 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nickjillings@1318 654 // 3. anything else (capture 2)
nickjillings@1318 655 ".*" +
nickjillings@1318 656 ")\\)|)",
nickjillings@1318 657
nickjillings@1318 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nickjillings@1318 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nickjillings@1318 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nickjillings@1318 661
nickjillings@1318 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nickjillings@1318 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nickjillings@1318 664
nickjillings@1318 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nickjillings@1318 666
nickjillings@1318 667 rpseudo = new RegExp( pseudos ),
nickjillings@1318 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nickjillings@1318 669
nickjillings@1318 670 matchExpr = {
nickjillings@1318 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nickjillings@1318 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nickjillings@1318 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nickjillings@1318 674 "ATTR": new RegExp( "^" + attributes ),
nickjillings@1318 675 "PSEUDO": new RegExp( "^" + pseudos ),
nickjillings@1318 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nickjillings@1318 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nickjillings@1318 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nickjillings@1318 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nickjillings@1318 680 // For use in libraries implementing .is()
nickjillings@1318 681 // We use this for POS matching in `select`
nickjillings@1318 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nickjillings@1318 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nickjillings@1318 684 },
nickjillings@1318 685
nickjillings@1318 686 rinputs = /^(?:input|select|textarea|button)$/i,
nickjillings@1318 687 rheader = /^h\d$/i,
nickjillings@1318 688
nickjillings@1318 689 rnative = /^[^{]+\{\s*\[native \w/,
nickjillings@1318 690
nickjillings@1318 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nickjillings@1318 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nickjillings@1318 693
nickjillings@1318 694 rsibling = /[+~]/,
nickjillings@1318 695 rescape = /'|\\/g,
nickjillings@1318 696
nickjillings@1318 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nickjillings@1318 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nickjillings@1318 699 funescape = function( _, escaped, escapedWhitespace ) {
nickjillings@1318 700 var high = "0x" + escaped - 0x10000;
nickjillings@1318 701 // NaN means non-codepoint
nickjillings@1318 702 // Support: Firefox<24
nickjillings@1318 703 // Workaround erroneous numeric interpretation of +"0x"
nickjillings@1318 704 return high !== high || escapedWhitespace ?
nickjillings@1318 705 escaped :
nickjillings@1318 706 high < 0 ?
nickjillings@1318 707 // BMP codepoint
nickjillings@1318 708 String.fromCharCode( high + 0x10000 ) :
nickjillings@1318 709 // Supplemental Plane codepoint (surrogate pair)
nickjillings@1318 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nickjillings@1318 711 },
nickjillings@1318 712
nickjillings@1318 713 // Used for iframes
nickjillings@1318 714 // See setDocument()
nickjillings@1318 715 // Removing the function wrapper causes a "Permission Denied"
nickjillings@1318 716 // error in IE
nickjillings@1318 717 unloadHandler = function() {
nickjillings@1318 718 setDocument();
nickjillings@1318 719 };
nickjillings@1318 720
nickjillings@1318 721 // Optimize for push.apply( _, NodeList )
nickjillings@1318 722 try {
nickjillings@1318 723 push.apply(
nickjillings@1318 724 (arr = slice.call( preferredDoc.childNodes )),
nickjillings@1318 725 preferredDoc.childNodes
nickjillings@1318 726 );
nickjillings@1318 727 // Support: Android<4.0
nickjillings@1318 728 // Detect silently failing push.apply
nickjillings@1318 729 arr[ preferredDoc.childNodes.length ].nodeType;
nickjillings@1318 730 } catch ( e ) {
nickjillings@1318 731 push = { apply: arr.length ?
nickjillings@1318 732
nickjillings@1318 733 // Leverage slice if possible
nickjillings@1318 734 function( target, els ) {
nickjillings@1318 735 push_native.apply( target, slice.call(els) );
nickjillings@1318 736 } :
nickjillings@1318 737
nickjillings@1318 738 // Support: IE<9
nickjillings@1318 739 // Otherwise append directly
nickjillings@1318 740 function( target, els ) {
nickjillings@1318 741 var j = target.length,
nickjillings@1318 742 i = 0;
nickjillings@1318 743 // Can't trust NodeList.length
nickjillings@1318 744 while ( (target[j++] = els[i++]) ) {}
nickjillings@1318 745 target.length = j - 1;
nickjillings@1318 746 }
nickjillings@1318 747 };
nickjillings@1318 748 }
nickjillings@1318 749
nickjillings@1318 750 function Sizzle( selector, context, results, seed ) {
nickjillings@1318 751 var match, elem, m, nodeType,
nickjillings@1318 752 // QSA vars
nickjillings@1318 753 i, groups, old, nid, newContext, newSelector;
nickjillings@1318 754
nickjillings@1318 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nickjillings@1318 756 setDocument( context );
nickjillings@1318 757 }
nickjillings@1318 758
nickjillings@1318 759 context = context || document;
nickjillings@1318 760 results = results || [];
nickjillings@1318 761 nodeType = context.nodeType;
nickjillings@1318 762
nickjillings@1318 763 if ( typeof selector !== "string" || !selector ||
nickjillings@1318 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nickjillings@1318 765
nickjillings@1318 766 return results;
nickjillings@1318 767 }
nickjillings@1318 768
nickjillings@1318 769 if ( !seed && documentIsHTML ) {
nickjillings@1318 770
nickjillings@1318 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nickjillings@1318 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nickjillings@1318 773 // Speed-up: Sizzle("#ID")
nickjillings@1318 774 if ( (m = match[1]) ) {
nickjillings@1318 775 if ( nodeType === 9 ) {
nickjillings@1318 776 elem = context.getElementById( m );
nickjillings@1318 777 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1318 778 // nodes that are no longer in the document (jQuery #6963)
nickjillings@1318 779 if ( elem && elem.parentNode ) {
nickjillings@1318 780 // Handle the case where IE, Opera, and Webkit return items
nickjillings@1318 781 // by name instead of ID
nickjillings@1318 782 if ( elem.id === m ) {
nickjillings@1318 783 results.push( elem );
nickjillings@1318 784 return results;
nickjillings@1318 785 }
nickjillings@1318 786 } else {
nickjillings@1318 787 return results;
nickjillings@1318 788 }
nickjillings@1318 789 } else {
nickjillings@1318 790 // Context is not a document
nickjillings@1318 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nickjillings@1318 792 contains( context, elem ) && elem.id === m ) {
nickjillings@1318 793 results.push( elem );
nickjillings@1318 794 return results;
nickjillings@1318 795 }
nickjillings@1318 796 }
nickjillings@1318 797
nickjillings@1318 798 // Speed-up: Sizzle("TAG")
nickjillings@1318 799 } else if ( match[2] ) {
nickjillings@1318 800 push.apply( results, context.getElementsByTagName( selector ) );
nickjillings@1318 801 return results;
nickjillings@1318 802
nickjillings@1318 803 // Speed-up: Sizzle(".CLASS")
nickjillings@1318 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nickjillings@1318 805 push.apply( results, context.getElementsByClassName( m ) );
nickjillings@1318 806 return results;
nickjillings@1318 807 }
nickjillings@1318 808 }
nickjillings@1318 809
nickjillings@1318 810 // QSA path
nickjillings@1318 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nickjillings@1318 812 nid = old = expando;
nickjillings@1318 813 newContext = context;
nickjillings@1318 814 newSelector = nodeType !== 1 && selector;
nickjillings@1318 815
nickjillings@1318 816 // qSA works strangely on Element-rooted queries
nickjillings@1318 817 // We can work around this by specifying an extra ID on the root
nickjillings@1318 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nickjillings@1318 819 // IE 8 doesn't work on object elements
nickjillings@1318 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nickjillings@1318 821 groups = tokenize( selector );
nickjillings@1318 822
nickjillings@1318 823 if ( (old = context.getAttribute("id")) ) {
nickjillings@1318 824 nid = old.replace( rescape, "\\$&" );
nickjillings@1318 825 } else {
nickjillings@1318 826 context.setAttribute( "id", nid );
nickjillings@1318 827 }
nickjillings@1318 828 nid = "[id='" + nid + "'] ";
nickjillings@1318 829
nickjillings@1318 830 i = groups.length;
nickjillings@1318 831 while ( i-- ) {
nickjillings@1318 832 groups[i] = nid + toSelector( groups[i] );
nickjillings@1318 833 }
nickjillings@1318 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nickjillings@1318 835 newSelector = groups.join(",");
nickjillings@1318 836 }
nickjillings@1318 837
nickjillings@1318 838 if ( newSelector ) {
nickjillings@1318 839 try {
nickjillings@1318 840 push.apply( results,
nickjillings@1318 841 newContext.querySelectorAll( newSelector )
nickjillings@1318 842 );
nickjillings@1318 843 return results;
nickjillings@1318 844 } catch(qsaError) {
nickjillings@1318 845 } finally {
nickjillings@1318 846 if ( !old ) {
nickjillings@1318 847 context.removeAttribute("id");
nickjillings@1318 848 }
nickjillings@1318 849 }
nickjillings@1318 850 }
nickjillings@1318 851 }
nickjillings@1318 852 }
nickjillings@1318 853
nickjillings@1318 854 // All others
nickjillings@1318 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nickjillings@1318 856 }
nickjillings@1318 857
nickjillings@1318 858 /**
nickjillings@1318 859 * Create key-value caches of limited size
nickjillings@1318 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nickjillings@1318 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nickjillings@1318 862 * deleting the oldest entry
nickjillings@1318 863 */
nickjillings@1318 864 function createCache() {
nickjillings@1318 865 var keys = [];
nickjillings@1318 866
nickjillings@1318 867 function cache( key, value ) {
nickjillings@1318 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nickjillings@1318 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nickjillings@1318 870 // Only keep the most recent entries
nickjillings@1318 871 delete cache[ keys.shift() ];
nickjillings@1318 872 }
nickjillings@1318 873 return (cache[ key + " " ] = value);
nickjillings@1318 874 }
nickjillings@1318 875 return cache;
nickjillings@1318 876 }
nickjillings@1318 877
nickjillings@1318 878 /**
nickjillings@1318 879 * Mark a function for special use by Sizzle
nickjillings@1318 880 * @param {Function} fn The function to mark
nickjillings@1318 881 */
nickjillings@1318 882 function markFunction( fn ) {
nickjillings@1318 883 fn[ expando ] = true;
nickjillings@1318 884 return fn;
nickjillings@1318 885 }
nickjillings@1318 886
nickjillings@1318 887 /**
nickjillings@1318 888 * Support testing using an element
nickjillings@1318 889 * @param {Function} fn Passed the created div and expects a boolean result
nickjillings@1318 890 */
nickjillings@1318 891 function assert( fn ) {
nickjillings@1318 892 var div = document.createElement("div");
nickjillings@1318 893
nickjillings@1318 894 try {
nickjillings@1318 895 return !!fn( div );
nickjillings@1318 896 } catch (e) {
nickjillings@1318 897 return false;
nickjillings@1318 898 } finally {
nickjillings@1318 899 // Remove from its parent by default
nickjillings@1318 900 if ( div.parentNode ) {
nickjillings@1318 901 div.parentNode.removeChild( div );
nickjillings@1318 902 }
nickjillings@1318 903 // release memory in IE
nickjillings@1318 904 div = null;
nickjillings@1318 905 }
nickjillings@1318 906 }
nickjillings@1318 907
nickjillings@1318 908 /**
nickjillings@1318 909 * Adds the same handler for all of the specified attrs
nickjillings@1318 910 * @param {String} attrs Pipe-separated list of attributes
nickjillings@1318 911 * @param {Function} handler The method that will be applied
nickjillings@1318 912 */
nickjillings@1318 913 function addHandle( attrs, handler ) {
nickjillings@1318 914 var arr = attrs.split("|"),
nickjillings@1318 915 i = attrs.length;
nickjillings@1318 916
nickjillings@1318 917 while ( i-- ) {
nickjillings@1318 918 Expr.attrHandle[ arr[i] ] = handler;
nickjillings@1318 919 }
nickjillings@1318 920 }
nickjillings@1318 921
nickjillings@1318 922 /**
nickjillings@1318 923 * Checks document order of two siblings
nickjillings@1318 924 * @param {Element} a
nickjillings@1318 925 * @param {Element} b
nickjillings@1318 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nickjillings@1318 927 */
nickjillings@1318 928 function siblingCheck( a, b ) {
nickjillings@1318 929 var cur = b && a,
nickjillings@1318 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nickjillings@1318 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nickjillings@1318 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nickjillings@1318 933
nickjillings@1318 934 // Use IE sourceIndex if available on both nodes
nickjillings@1318 935 if ( diff ) {
nickjillings@1318 936 return diff;
nickjillings@1318 937 }
nickjillings@1318 938
nickjillings@1318 939 // Check if b follows a
nickjillings@1318 940 if ( cur ) {
nickjillings@1318 941 while ( (cur = cur.nextSibling) ) {
nickjillings@1318 942 if ( cur === b ) {
nickjillings@1318 943 return -1;
nickjillings@1318 944 }
nickjillings@1318 945 }
nickjillings@1318 946 }
nickjillings@1318 947
nickjillings@1318 948 return a ? 1 : -1;
nickjillings@1318 949 }
nickjillings@1318 950
nickjillings@1318 951 /**
nickjillings@1318 952 * Returns a function to use in pseudos for input types
nickjillings@1318 953 * @param {String} type
nickjillings@1318 954 */
nickjillings@1318 955 function createInputPseudo( type ) {
nickjillings@1318 956 return function( elem ) {
nickjillings@1318 957 var name = elem.nodeName.toLowerCase();
nickjillings@1318 958 return name === "input" && elem.type === type;
nickjillings@1318 959 };
nickjillings@1318 960 }
nickjillings@1318 961
nickjillings@1318 962 /**
nickjillings@1318 963 * Returns a function to use in pseudos for buttons
nickjillings@1318 964 * @param {String} type
nickjillings@1318 965 */
nickjillings@1318 966 function createButtonPseudo( type ) {
nickjillings@1318 967 return function( elem ) {
nickjillings@1318 968 var name = elem.nodeName.toLowerCase();
nickjillings@1318 969 return (name === "input" || name === "button") && elem.type === type;
nickjillings@1318 970 };
nickjillings@1318 971 }
nickjillings@1318 972
nickjillings@1318 973 /**
nickjillings@1318 974 * Returns a function to use in pseudos for positionals
nickjillings@1318 975 * @param {Function} fn
nickjillings@1318 976 */
nickjillings@1318 977 function createPositionalPseudo( fn ) {
nickjillings@1318 978 return markFunction(function( argument ) {
nickjillings@1318 979 argument = +argument;
nickjillings@1318 980 return markFunction(function( seed, matches ) {
nickjillings@1318 981 var j,
nickjillings@1318 982 matchIndexes = fn( [], seed.length, argument ),
nickjillings@1318 983 i = matchIndexes.length;
nickjillings@1318 984
nickjillings@1318 985 // Match elements found at the specified indexes
nickjillings@1318 986 while ( i-- ) {
nickjillings@1318 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nickjillings@1318 988 seed[j] = !(matches[j] = seed[j]);
nickjillings@1318 989 }
nickjillings@1318 990 }
nickjillings@1318 991 });
nickjillings@1318 992 });
nickjillings@1318 993 }
nickjillings@1318 994
nickjillings@1318 995 /**
nickjillings@1318 996 * Checks a node for validity as a Sizzle context
nickjillings@1318 997 * @param {Element|Object=} context
nickjillings@1318 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nickjillings@1318 999 */
nickjillings@1318 1000 function testContext( context ) {
nickjillings@1318 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nickjillings@1318 1002 }
nickjillings@1318 1003
nickjillings@1318 1004 // Expose support vars for convenience
nickjillings@1318 1005 support = Sizzle.support = {};
nickjillings@1318 1006
nickjillings@1318 1007 /**
nickjillings@1318 1008 * Detects XML nodes
nickjillings@1318 1009 * @param {Element|Object} elem An element or a document
nickjillings@1318 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nickjillings@1318 1011 */
nickjillings@1318 1012 isXML = Sizzle.isXML = function( elem ) {
nickjillings@1318 1013 // documentElement is verified for cases where it doesn't yet exist
nickjillings@1318 1014 // (such as loading iframes in IE - #4833)
nickjillings@1318 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nickjillings@1318 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nickjillings@1318 1017 };
nickjillings@1318 1018
nickjillings@1318 1019 /**
nickjillings@1318 1020 * Sets document-related variables once based on the current document
nickjillings@1318 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nickjillings@1318 1022 * @returns {Object} Returns the current document
nickjillings@1318 1023 */
nickjillings@1318 1024 setDocument = Sizzle.setDocument = function( node ) {
nickjillings@1318 1025 var hasCompare, parent,
nickjillings@1318 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nickjillings@1318 1027
nickjillings@1318 1028 // If no document and documentElement is available, return
nickjillings@1318 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nickjillings@1318 1030 return document;
nickjillings@1318 1031 }
nickjillings@1318 1032
nickjillings@1318 1033 // Set our document
nickjillings@1318 1034 document = doc;
nickjillings@1318 1035 docElem = doc.documentElement;
nickjillings@1318 1036 parent = doc.defaultView;
nickjillings@1318 1037
nickjillings@1318 1038 // Support: IE>8
nickjillings@1318 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nickjillings@1318 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nickjillings@1318 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nickjillings@1318 1042 if ( parent && parent !== parent.top ) {
nickjillings@1318 1043 // IE11 does not have attachEvent, so all must suffer
nickjillings@1318 1044 if ( parent.addEventListener ) {
nickjillings@1318 1045 parent.addEventListener( "unload", unloadHandler, false );
nickjillings@1318 1046 } else if ( parent.attachEvent ) {
nickjillings@1318 1047 parent.attachEvent( "onunload", unloadHandler );
nickjillings@1318 1048 }
nickjillings@1318 1049 }
nickjillings@1318 1050
nickjillings@1318 1051 /* Support tests
nickjillings@1318 1052 ---------------------------------------------------------------------- */
nickjillings@1318 1053 documentIsHTML = !isXML( doc );
nickjillings@1318 1054
nickjillings@1318 1055 /* Attributes
nickjillings@1318 1056 ---------------------------------------------------------------------- */
nickjillings@1318 1057
nickjillings@1318 1058 // Support: IE<8
nickjillings@1318 1059 // Verify that getAttribute really returns attributes and not properties
nickjillings@1318 1060 // (excepting IE8 booleans)
nickjillings@1318 1061 support.attributes = assert(function( div ) {
nickjillings@1318 1062 div.className = "i";
nickjillings@1318 1063 return !div.getAttribute("className");
nickjillings@1318 1064 });
nickjillings@1318 1065
nickjillings@1318 1066 /* getElement(s)By*
nickjillings@1318 1067 ---------------------------------------------------------------------- */
nickjillings@1318 1068
nickjillings@1318 1069 // Check if getElementsByTagName("*") returns only elements
nickjillings@1318 1070 support.getElementsByTagName = assert(function( div ) {
nickjillings@1318 1071 div.appendChild( doc.createComment("") );
nickjillings@1318 1072 return !div.getElementsByTagName("*").length;
nickjillings@1318 1073 });
nickjillings@1318 1074
nickjillings@1318 1075 // Support: IE<9
nickjillings@1318 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nickjillings@1318 1077
nickjillings@1318 1078 // Support: IE<10
nickjillings@1318 1079 // Check if getElementById returns elements by name
nickjillings@1318 1080 // The broken getElementById methods don't pick up programatically-set names,
nickjillings@1318 1081 // so use a roundabout getElementsByName test
nickjillings@1318 1082 support.getById = assert(function( div ) {
nickjillings@1318 1083 docElem.appendChild( div ).id = expando;
nickjillings@1318 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nickjillings@1318 1085 });
nickjillings@1318 1086
nickjillings@1318 1087 // ID find and filter
nickjillings@1318 1088 if ( support.getById ) {
nickjillings@1318 1089 Expr.find["ID"] = function( id, context ) {
nickjillings@1318 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nickjillings@1318 1091 var m = context.getElementById( id );
nickjillings@1318 1092 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1318 1093 // nodes that are no longer in the document #6963
nickjillings@1318 1094 return m && m.parentNode ? [ m ] : [];
nickjillings@1318 1095 }
nickjillings@1318 1096 };
nickjillings@1318 1097 Expr.filter["ID"] = function( id ) {
nickjillings@1318 1098 var attrId = id.replace( runescape, funescape );
nickjillings@1318 1099 return function( elem ) {
nickjillings@1318 1100 return elem.getAttribute("id") === attrId;
nickjillings@1318 1101 };
nickjillings@1318 1102 };
nickjillings@1318 1103 } else {
nickjillings@1318 1104 // Support: IE6/7
nickjillings@1318 1105 // getElementById is not reliable as a find shortcut
nickjillings@1318 1106 delete Expr.find["ID"];
nickjillings@1318 1107
nickjillings@1318 1108 Expr.filter["ID"] = function( id ) {
nickjillings@1318 1109 var attrId = id.replace( runescape, funescape );
nickjillings@1318 1110 return function( elem ) {
nickjillings@1318 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nickjillings@1318 1112 return node && node.value === attrId;
nickjillings@1318 1113 };
nickjillings@1318 1114 };
nickjillings@1318 1115 }
nickjillings@1318 1116
nickjillings@1318 1117 // Tag
nickjillings@1318 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nickjillings@1318 1119 function( tag, context ) {
nickjillings@1318 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nickjillings@1318 1121 return context.getElementsByTagName( tag );
nickjillings@1318 1122
nickjillings@1318 1123 // DocumentFragment nodes don't have gEBTN
nickjillings@1318 1124 } else if ( support.qsa ) {
nickjillings@1318 1125 return context.querySelectorAll( tag );
nickjillings@1318 1126 }
nickjillings@1318 1127 } :
nickjillings@1318 1128
nickjillings@1318 1129 function( tag, context ) {
nickjillings@1318 1130 var elem,
nickjillings@1318 1131 tmp = [],
nickjillings@1318 1132 i = 0,
nickjillings@1318 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nickjillings@1318 1134 results = context.getElementsByTagName( tag );
nickjillings@1318 1135
nickjillings@1318 1136 // Filter out possible comments
nickjillings@1318 1137 if ( tag === "*" ) {
nickjillings@1318 1138 while ( (elem = results[i++]) ) {
nickjillings@1318 1139 if ( elem.nodeType === 1 ) {
nickjillings@1318 1140 tmp.push( elem );
nickjillings@1318 1141 }
nickjillings@1318 1142 }
nickjillings@1318 1143
nickjillings@1318 1144 return tmp;
nickjillings@1318 1145 }
nickjillings@1318 1146 return results;
nickjillings@1318 1147 };
nickjillings@1318 1148
nickjillings@1318 1149 // Class
nickjillings@1318 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nickjillings@1318 1151 if ( documentIsHTML ) {
nickjillings@1318 1152 return context.getElementsByClassName( className );
nickjillings@1318 1153 }
nickjillings@1318 1154 };
nickjillings@1318 1155
nickjillings@1318 1156 /* QSA/matchesSelector
nickjillings@1318 1157 ---------------------------------------------------------------------- */
nickjillings@1318 1158
nickjillings@1318 1159 // QSA and matchesSelector support
nickjillings@1318 1160
nickjillings@1318 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nickjillings@1318 1162 rbuggyMatches = [];
nickjillings@1318 1163
nickjillings@1318 1164 // qSa(:focus) reports false when true (Chrome 21)
nickjillings@1318 1165 // We allow this because of a bug in IE8/9 that throws an error
nickjillings@1318 1166 // whenever `document.activeElement` is accessed on an iframe
nickjillings@1318 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nickjillings@1318 1168 // See http://bugs.jquery.com/ticket/13378
nickjillings@1318 1169 rbuggyQSA = [];
nickjillings@1318 1170
nickjillings@1318 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nickjillings@1318 1172 // Build QSA regex
nickjillings@1318 1173 // Regex strategy adopted from Diego Perini
nickjillings@1318 1174 assert(function( div ) {
nickjillings@1318 1175 // Select is set to empty string on purpose
nickjillings@1318 1176 // This is to test IE's treatment of not explicitly
nickjillings@1318 1177 // setting a boolean content attribute,
nickjillings@1318 1178 // since its presence should be enough
nickjillings@1318 1179 // http://bugs.jquery.com/ticket/12359
nickjillings@1318 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nickjillings@1318 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nickjillings@1318 1182 "<option selected=''></option></select>";
nickjillings@1318 1183
nickjillings@1318 1184 // Support: IE8, Opera 11-12.16
nickjillings@1318 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nickjillings@1318 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nickjillings@1318 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nickjillings@1318 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nickjillings@1318 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nickjillings@1318 1190 }
nickjillings@1318 1191
nickjillings@1318 1192 // Support: IE8
nickjillings@1318 1193 // Boolean attributes and "value" are not treated correctly
nickjillings@1318 1194 if ( !div.querySelectorAll("[selected]").length ) {
nickjillings@1318 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nickjillings@1318 1196 }
nickjillings@1318 1197
nickjillings@1318 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nickjillings@1318 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nickjillings@1318 1200 rbuggyQSA.push("~=");
nickjillings@1318 1201 }
nickjillings@1318 1202
nickjillings@1318 1203 // Webkit/Opera - :checked should return selected option elements
nickjillings@1318 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1318 1205 // IE8 throws error here and will not see later tests
nickjillings@1318 1206 if ( !div.querySelectorAll(":checked").length ) {
nickjillings@1318 1207 rbuggyQSA.push(":checked");
nickjillings@1318 1208 }
nickjillings@1318 1209
nickjillings@1318 1210 // Support: Safari 8+, iOS 8+
nickjillings@1318 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nickjillings@1318 1212 // In-page `selector#id sibing-combinator selector` fails
nickjillings@1318 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nickjillings@1318 1214 rbuggyQSA.push(".#.+[+~]");
nickjillings@1318 1215 }
nickjillings@1318 1216 });
nickjillings@1318 1217
nickjillings@1318 1218 assert(function( div ) {
nickjillings@1318 1219 // Support: Windows 8 Native Apps
nickjillings@1318 1220 // The type and name attributes are restricted during .innerHTML assignment
nickjillings@1318 1221 var input = doc.createElement("input");
nickjillings@1318 1222 input.setAttribute( "type", "hidden" );
nickjillings@1318 1223 div.appendChild( input ).setAttribute( "name", "D" );
nickjillings@1318 1224
nickjillings@1318 1225 // Support: IE8
nickjillings@1318 1226 // Enforce case-sensitivity of name attribute
nickjillings@1318 1227 if ( div.querySelectorAll("[name=d]").length ) {
nickjillings@1318 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nickjillings@1318 1229 }
nickjillings@1318 1230
nickjillings@1318 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nickjillings@1318 1232 // IE8 throws error here and will not see later tests
nickjillings@1318 1233 if ( !div.querySelectorAll(":enabled").length ) {
nickjillings@1318 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nickjillings@1318 1235 }
nickjillings@1318 1236
nickjillings@1318 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nickjillings@1318 1238 div.querySelectorAll("*,:x");
nickjillings@1318 1239 rbuggyQSA.push(",.*:");
nickjillings@1318 1240 });
nickjillings@1318 1241 }
nickjillings@1318 1242
nickjillings@1318 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nickjillings@1318 1244 docElem.webkitMatchesSelector ||
nickjillings@1318 1245 docElem.mozMatchesSelector ||
nickjillings@1318 1246 docElem.oMatchesSelector ||
nickjillings@1318 1247 docElem.msMatchesSelector) )) ) {
nickjillings@1318 1248
nickjillings@1318 1249 assert(function( div ) {
nickjillings@1318 1250 // Check to see if it's possible to do matchesSelector
nickjillings@1318 1251 // on a disconnected node (IE 9)
nickjillings@1318 1252 support.disconnectedMatch = matches.call( div, "div" );
nickjillings@1318 1253
nickjillings@1318 1254 // This should fail with an exception
nickjillings@1318 1255 // Gecko does not error, returns false instead
nickjillings@1318 1256 matches.call( div, "[s!='']:x" );
nickjillings@1318 1257 rbuggyMatches.push( "!=", pseudos );
nickjillings@1318 1258 });
nickjillings@1318 1259 }
nickjillings@1318 1260
nickjillings@1318 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nickjillings@1318 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nickjillings@1318 1263
nickjillings@1318 1264 /* Contains
nickjillings@1318 1265 ---------------------------------------------------------------------- */
nickjillings@1318 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nickjillings@1318 1267
nickjillings@1318 1268 // Element contains another
nickjillings@1318 1269 // Purposefully does not implement inclusive descendent
nickjillings@1318 1270 // As in, an element does not contain itself
nickjillings@1318 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nickjillings@1318 1272 function( a, b ) {
nickjillings@1318 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nickjillings@1318 1274 bup = b && b.parentNode;
nickjillings@1318 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nickjillings@1318 1276 adown.contains ?
nickjillings@1318 1277 adown.contains( bup ) :
nickjillings@1318 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nickjillings@1318 1279 ));
nickjillings@1318 1280 } :
nickjillings@1318 1281 function( a, b ) {
nickjillings@1318 1282 if ( b ) {
nickjillings@1318 1283 while ( (b = b.parentNode) ) {
nickjillings@1318 1284 if ( b === a ) {
nickjillings@1318 1285 return true;
nickjillings@1318 1286 }
nickjillings@1318 1287 }
nickjillings@1318 1288 }
nickjillings@1318 1289 return false;
nickjillings@1318 1290 };
nickjillings@1318 1291
nickjillings@1318 1292 /* Sorting
nickjillings@1318 1293 ---------------------------------------------------------------------- */
nickjillings@1318 1294
nickjillings@1318 1295 // Document order sorting
nickjillings@1318 1296 sortOrder = hasCompare ?
nickjillings@1318 1297 function( a, b ) {
nickjillings@1318 1298
nickjillings@1318 1299 // Flag for duplicate removal
nickjillings@1318 1300 if ( a === b ) {
nickjillings@1318 1301 hasDuplicate = true;
nickjillings@1318 1302 return 0;
nickjillings@1318 1303 }
nickjillings@1318 1304
nickjillings@1318 1305 // Sort on method existence if only one input has compareDocumentPosition
nickjillings@1318 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nickjillings@1318 1307 if ( compare ) {
nickjillings@1318 1308 return compare;
nickjillings@1318 1309 }
nickjillings@1318 1310
nickjillings@1318 1311 // Calculate position if both inputs belong to the same document
nickjillings@1318 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nickjillings@1318 1313 a.compareDocumentPosition( b ) :
nickjillings@1318 1314
nickjillings@1318 1315 // Otherwise we know they are disconnected
nickjillings@1318 1316 1;
nickjillings@1318 1317
nickjillings@1318 1318 // Disconnected nodes
nickjillings@1318 1319 if ( compare & 1 ||
nickjillings@1318 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nickjillings@1318 1321
nickjillings@1318 1322 // Choose the first element that is related to our preferred document
nickjillings@1318 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nickjillings@1318 1324 return -1;
nickjillings@1318 1325 }
nickjillings@1318 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nickjillings@1318 1327 return 1;
nickjillings@1318 1328 }
nickjillings@1318 1329
nickjillings@1318 1330 // Maintain original order
nickjillings@1318 1331 return sortInput ?
nickjillings@1318 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1318 1333 0;
nickjillings@1318 1334 }
nickjillings@1318 1335
nickjillings@1318 1336 return compare & 4 ? -1 : 1;
nickjillings@1318 1337 } :
nickjillings@1318 1338 function( a, b ) {
nickjillings@1318 1339 // Exit early if the nodes are identical
nickjillings@1318 1340 if ( a === b ) {
nickjillings@1318 1341 hasDuplicate = true;
nickjillings@1318 1342 return 0;
nickjillings@1318 1343 }
nickjillings@1318 1344
nickjillings@1318 1345 var cur,
nickjillings@1318 1346 i = 0,
nickjillings@1318 1347 aup = a.parentNode,
nickjillings@1318 1348 bup = b.parentNode,
nickjillings@1318 1349 ap = [ a ],
nickjillings@1318 1350 bp = [ b ];
nickjillings@1318 1351
nickjillings@1318 1352 // Parentless nodes are either documents or disconnected
nickjillings@1318 1353 if ( !aup || !bup ) {
nickjillings@1318 1354 return a === doc ? -1 :
nickjillings@1318 1355 b === doc ? 1 :
nickjillings@1318 1356 aup ? -1 :
nickjillings@1318 1357 bup ? 1 :
nickjillings@1318 1358 sortInput ?
nickjillings@1318 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1318 1360 0;
nickjillings@1318 1361
nickjillings@1318 1362 // If the nodes are siblings, we can do a quick check
nickjillings@1318 1363 } else if ( aup === bup ) {
nickjillings@1318 1364 return siblingCheck( a, b );
nickjillings@1318 1365 }
nickjillings@1318 1366
nickjillings@1318 1367 // Otherwise we need full lists of their ancestors for comparison
nickjillings@1318 1368 cur = a;
nickjillings@1318 1369 while ( (cur = cur.parentNode) ) {
nickjillings@1318 1370 ap.unshift( cur );
nickjillings@1318 1371 }
nickjillings@1318 1372 cur = b;
nickjillings@1318 1373 while ( (cur = cur.parentNode) ) {
nickjillings@1318 1374 bp.unshift( cur );
nickjillings@1318 1375 }
nickjillings@1318 1376
nickjillings@1318 1377 // Walk down the tree looking for a discrepancy
nickjillings@1318 1378 while ( ap[i] === bp[i] ) {
nickjillings@1318 1379 i++;
nickjillings@1318 1380 }
nickjillings@1318 1381
nickjillings@1318 1382 return i ?
nickjillings@1318 1383 // Do a sibling check if the nodes have a common ancestor
nickjillings@1318 1384 siblingCheck( ap[i], bp[i] ) :
nickjillings@1318 1385
nickjillings@1318 1386 // Otherwise nodes in our document sort first
nickjillings@1318 1387 ap[i] === preferredDoc ? -1 :
nickjillings@1318 1388 bp[i] === preferredDoc ? 1 :
nickjillings@1318 1389 0;
nickjillings@1318 1390 };
nickjillings@1318 1391
nickjillings@1318 1392 return doc;
nickjillings@1318 1393 };
nickjillings@1318 1394
nickjillings@1318 1395 Sizzle.matches = function( expr, elements ) {
nickjillings@1318 1396 return Sizzle( expr, null, null, elements );
nickjillings@1318 1397 };
nickjillings@1318 1398
nickjillings@1318 1399 Sizzle.matchesSelector = function( elem, expr ) {
nickjillings@1318 1400 // Set document vars if needed
nickjillings@1318 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1318 1402 setDocument( elem );
nickjillings@1318 1403 }
nickjillings@1318 1404
nickjillings@1318 1405 // Make sure that attribute selectors are quoted
nickjillings@1318 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nickjillings@1318 1407
nickjillings@1318 1408 if ( support.matchesSelector && documentIsHTML &&
nickjillings@1318 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nickjillings@1318 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nickjillings@1318 1411
nickjillings@1318 1412 try {
nickjillings@1318 1413 var ret = matches.call( elem, expr );
nickjillings@1318 1414
nickjillings@1318 1415 // IE 9's matchesSelector returns false on disconnected nodes
nickjillings@1318 1416 if ( ret || support.disconnectedMatch ||
nickjillings@1318 1417 // As well, disconnected nodes are said to be in a document
nickjillings@1318 1418 // fragment in IE 9
nickjillings@1318 1419 elem.document && elem.document.nodeType !== 11 ) {
nickjillings@1318 1420 return ret;
nickjillings@1318 1421 }
nickjillings@1318 1422 } catch (e) {}
nickjillings@1318 1423 }
nickjillings@1318 1424
nickjillings@1318 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nickjillings@1318 1426 };
nickjillings@1318 1427
nickjillings@1318 1428 Sizzle.contains = function( context, elem ) {
nickjillings@1318 1429 // Set document vars if needed
nickjillings@1318 1430 if ( ( context.ownerDocument || context ) !== document ) {
nickjillings@1318 1431 setDocument( context );
nickjillings@1318 1432 }
nickjillings@1318 1433 return contains( context, elem );
nickjillings@1318 1434 };
nickjillings@1318 1435
nickjillings@1318 1436 Sizzle.attr = function( elem, name ) {
nickjillings@1318 1437 // Set document vars if needed
nickjillings@1318 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1318 1439 setDocument( elem );
nickjillings@1318 1440 }
nickjillings@1318 1441
nickjillings@1318 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nickjillings@1318 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nickjillings@1318 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nickjillings@1318 1445 fn( elem, name, !documentIsHTML ) :
nickjillings@1318 1446 undefined;
nickjillings@1318 1447
nickjillings@1318 1448 return val !== undefined ?
nickjillings@1318 1449 val :
nickjillings@1318 1450 support.attributes || !documentIsHTML ?
nickjillings@1318 1451 elem.getAttribute( name ) :
nickjillings@1318 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nickjillings@1318 1453 val.value :
nickjillings@1318 1454 null;
nickjillings@1318 1455 };
nickjillings@1318 1456
nickjillings@1318 1457 Sizzle.error = function( msg ) {
nickjillings@1318 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nickjillings@1318 1459 };
nickjillings@1318 1460
nickjillings@1318 1461 /**
nickjillings@1318 1462 * Document sorting and removing duplicates
nickjillings@1318 1463 * @param {ArrayLike} results
nickjillings@1318 1464 */
nickjillings@1318 1465 Sizzle.uniqueSort = function( results ) {
nickjillings@1318 1466 var elem,
nickjillings@1318 1467 duplicates = [],
nickjillings@1318 1468 j = 0,
nickjillings@1318 1469 i = 0;
nickjillings@1318 1470
nickjillings@1318 1471 // Unless we *know* we can detect duplicates, assume their presence
nickjillings@1318 1472 hasDuplicate = !support.detectDuplicates;
nickjillings@1318 1473 sortInput = !support.sortStable && results.slice( 0 );
nickjillings@1318 1474 results.sort( sortOrder );
nickjillings@1318 1475
nickjillings@1318 1476 if ( hasDuplicate ) {
nickjillings@1318 1477 while ( (elem = results[i++]) ) {
nickjillings@1318 1478 if ( elem === results[ i ] ) {
nickjillings@1318 1479 j = duplicates.push( i );
nickjillings@1318 1480 }
nickjillings@1318 1481 }
nickjillings@1318 1482 while ( j-- ) {
nickjillings@1318 1483 results.splice( duplicates[ j ], 1 );
nickjillings@1318 1484 }
nickjillings@1318 1485 }
nickjillings@1318 1486
nickjillings@1318 1487 // Clear input after sorting to release objects
nickjillings@1318 1488 // See https://github.com/jquery/sizzle/pull/225
nickjillings@1318 1489 sortInput = null;
nickjillings@1318 1490
nickjillings@1318 1491 return results;
nickjillings@1318 1492 };
nickjillings@1318 1493
nickjillings@1318 1494 /**
nickjillings@1318 1495 * Utility function for retrieving the text value of an array of DOM nodes
nickjillings@1318 1496 * @param {Array|Element} elem
nickjillings@1318 1497 */
nickjillings@1318 1498 getText = Sizzle.getText = function( elem ) {
nickjillings@1318 1499 var node,
nickjillings@1318 1500 ret = "",
nickjillings@1318 1501 i = 0,
nickjillings@1318 1502 nodeType = elem.nodeType;
nickjillings@1318 1503
nickjillings@1318 1504 if ( !nodeType ) {
nickjillings@1318 1505 // If no nodeType, this is expected to be an array
nickjillings@1318 1506 while ( (node = elem[i++]) ) {
nickjillings@1318 1507 // Do not traverse comment nodes
nickjillings@1318 1508 ret += getText( node );
nickjillings@1318 1509 }
nickjillings@1318 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nickjillings@1318 1511 // Use textContent for elements
nickjillings@1318 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nickjillings@1318 1513 if ( typeof elem.textContent === "string" ) {
nickjillings@1318 1514 return elem.textContent;
nickjillings@1318 1515 } else {
nickjillings@1318 1516 // Traverse its children
nickjillings@1318 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1318 1518 ret += getText( elem );
nickjillings@1318 1519 }
nickjillings@1318 1520 }
nickjillings@1318 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nickjillings@1318 1522 return elem.nodeValue;
nickjillings@1318 1523 }
nickjillings@1318 1524 // Do not include comment or processing instruction nodes
nickjillings@1318 1525
nickjillings@1318 1526 return ret;
nickjillings@1318 1527 };
nickjillings@1318 1528
nickjillings@1318 1529 Expr = Sizzle.selectors = {
nickjillings@1318 1530
nickjillings@1318 1531 // Can be adjusted by the user
nickjillings@1318 1532 cacheLength: 50,
nickjillings@1318 1533
nickjillings@1318 1534 createPseudo: markFunction,
nickjillings@1318 1535
nickjillings@1318 1536 match: matchExpr,
nickjillings@1318 1537
nickjillings@1318 1538 attrHandle: {},
nickjillings@1318 1539
nickjillings@1318 1540 find: {},
nickjillings@1318 1541
nickjillings@1318 1542 relative: {
nickjillings@1318 1543 ">": { dir: "parentNode", first: true },
nickjillings@1318 1544 " ": { dir: "parentNode" },
nickjillings@1318 1545 "+": { dir: "previousSibling", first: true },
nickjillings@1318 1546 "~": { dir: "previousSibling" }
nickjillings@1318 1547 },
nickjillings@1318 1548
nickjillings@1318 1549 preFilter: {
nickjillings@1318 1550 "ATTR": function( match ) {
nickjillings@1318 1551 match[1] = match[1].replace( runescape, funescape );
nickjillings@1318 1552
nickjillings@1318 1553 // Move the given value to match[3] whether quoted or unquoted
nickjillings@1318 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nickjillings@1318 1555
nickjillings@1318 1556 if ( match[2] === "~=" ) {
nickjillings@1318 1557 match[3] = " " + match[3] + " ";
nickjillings@1318 1558 }
nickjillings@1318 1559
nickjillings@1318 1560 return match.slice( 0, 4 );
nickjillings@1318 1561 },
nickjillings@1318 1562
nickjillings@1318 1563 "CHILD": function( match ) {
nickjillings@1318 1564 /* matches from matchExpr["CHILD"]
nickjillings@1318 1565 1 type (only|nth|...)
nickjillings@1318 1566 2 what (child|of-type)
nickjillings@1318 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nickjillings@1318 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nickjillings@1318 1569 5 sign of xn-component
nickjillings@1318 1570 6 x of xn-component
nickjillings@1318 1571 7 sign of y-component
nickjillings@1318 1572 8 y of y-component
nickjillings@1318 1573 */
nickjillings@1318 1574 match[1] = match[1].toLowerCase();
nickjillings@1318 1575
nickjillings@1318 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nickjillings@1318 1577 // nth-* requires argument
nickjillings@1318 1578 if ( !match[3] ) {
nickjillings@1318 1579 Sizzle.error( match[0] );
nickjillings@1318 1580 }
nickjillings@1318 1581
nickjillings@1318 1582 // numeric x and y parameters for Expr.filter.CHILD
nickjillings@1318 1583 // remember that false/true cast respectively to 0/1
nickjillings@1318 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nickjillings@1318 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nickjillings@1318 1586
nickjillings@1318 1587 // other types prohibit arguments
nickjillings@1318 1588 } else if ( match[3] ) {
nickjillings@1318 1589 Sizzle.error( match[0] );
nickjillings@1318 1590 }
nickjillings@1318 1591
nickjillings@1318 1592 return match;
nickjillings@1318 1593 },
nickjillings@1318 1594
nickjillings@1318 1595 "PSEUDO": function( match ) {
nickjillings@1318 1596 var excess,
nickjillings@1318 1597 unquoted = !match[6] && match[2];
nickjillings@1318 1598
nickjillings@1318 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nickjillings@1318 1600 return null;
nickjillings@1318 1601 }
nickjillings@1318 1602
nickjillings@1318 1603 // Accept quoted arguments as-is
nickjillings@1318 1604 if ( match[3] ) {
nickjillings@1318 1605 match[2] = match[4] || match[5] || "";
nickjillings@1318 1606
nickjillings@1318 1607 // Strip excess characters from unquoted arguments
nickjillings@1318 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nickjillings@1318 1609 // Get excess from tokenize (recursively)
nickjillings@1318 1610 (excess = tokenize( unquoted, true )) &&
nickjillings@1318 1611 // advance to the next closing parenthesis
nickjillings@1318 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nickjillings@1318 1613
nickjillings@1318 1614 // excess is a negative index
nickjillings@1318 1615 match[0] = match[0].slice( 0, excess );
nickjillings@1318 1616 match[2] = unquoted.slice( 0, excess );
nickjillings@1318 1617 }
nickjillings@1318 1618
nickjillings@1318 1619 // Return only captures needed by the pseudo filter method (type and argument)
nickjillings@1318 1620 return match.slice( 0, 3 );
nickjillings@1318 1621 }
nickjillings@1318 1622 },
nickjillings@1318 1623
nickjillings@1318 1624 filter: {
nickjillings@1318 1625
nickjillings@1318 1626 "TAG": function( nodeNameSelector ) {
nickjillings@1318 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nickjillings@1318 1628 return nodeNameSelector === "*" ?
nickjillings@1318 1629 function() { return true; } :
nickjillings@1318 1630 function( elem ) {
nickjillings@1318 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nickjillings@1318 1632 };
nickjillings@1318 1633 },
nickjillings@1318 1634
nickjillings@1318 1635 "CLASS": function( className ) {
nickjillings@1318 1636 var pattern = classCache[ className + " " ];
nickjillings@1318 1637
nickjillings@1318 1638 return pattern ||
nickjillings@1318 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nickjillings@1318 1640 classCache( className, function( elem ) {
nickjillings@1318 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nickjillings@1318 1642 });
nickjillings@1318 1643 },
nickjillings@1318 1644
nickjillings@1318 1645 "ATTR": function( name, operator, check ) {
nickjillings@1318 1646 return function( elem ) {
nickjillings@1318 1647 var result = Sizzle.attr( elem, name );
nickjillings@1318 1648
nickjillings@1318 1649 if ( result == null ) {
nickjillings@1318 1650 return operator === "!=";
nickjillings@1318 1651 }
nickjillings@1318 1652 if ( !operator ) {
nickjillings@1318 1653 return true;
nickjillings@1318 1654 }
nickjillings@1318 1655
nickjillings@1318 1656 result += "";
nickjillings@1318 1657
nickjillings@1318 1658 return operator === "=" ? result === check :
nickjillings@1318 1659 operator === "!=" ? result !== check :
nickjillings@1318 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nickjillings@1318 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nickjillings@1318 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nickjillings@1318 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nickjillings@1318 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nickjillings@1318 1665 false;
nickjillings@1318 1666 };
nickjillings@1318 1667 },
nickjillings@1318 1668
nickjillings@1318 1669 "CHILD": function( type, what, argument, first, last ) {
nickjillings@1318 1670 var simple = type.slice( 0, 3 ) !== "nth",
nickjillings@1318 1671 forward = type.slice( -4 ) !== "last",
nickjillings@1318 1672 ofType = what === "of-type";
nickjillings@1318 1673
nickjillings@1318 1674 return first === 1 && last === 0 ?
nickjillings@1318 1675
nickjillings@1318 1676 // Shortcut for :nth-*(n)
nickjillings@1318 1677 function( elem ) {
nickjillings@1318 1678 return !!elem.parentNode;
nickjillings@1318 1679 } :
nickjillings@1318 1680
nickjillings@1318 1681 function( elem, context, xml ) {
nickjillings@1318 1682 var cache, outerCache, node, diff, nodeIndex, start,
nickjillings@1318 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nickjillings@1318 1684 parent = elem.parentNode,
nickjillings@1318 1685 name = ofType && elem.nodeName.toLowerCase(),
nickjillings@1318 1686 useCache = !xml && !ofType;
nickjillings@1318 1687
nickjillings@1318 1688 if ( parent ) {
nickjillings@1318 1689
nickjillings@1318 1690 // :(first|last|only)-(child|of-type)
nickjillings@1318 1691 if ( simple ) {
nickjillings@1318 1692 while ( dir ) {
nickjillings@1318 1693 node = elem;
nickjillings@1318 1694 while ( (node = node[ dir ]) ) {
nickjillings@1318 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nickjillings@1318 1696 return false;
nickjillings@1318 1697 }
nickjillings@1318 1698 }
nickjillings@1318 1699 // Reverse direction for :only-* (if we haven't yet done so)
nickjillings@1318 1700 start = dir = type === "only" && !start && "nextSibling";
nickjillings@1318 1701 }
nickjillings@1318 1702 return true;
nickjillings@1318 1703 }
nickjillings@1318 1704
nickjillings@1318 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nickjillings@1318 1706
nickjillings@1318 1707 // non-xml :nth-child(...) stores cache data on `parent`
nickjillings@1318 1708 if ( forward && useCache ) {
nickjillings@1318 1709 // Seek `elem` from a previously-cached index
nickjillings@1318 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nickjillings@1318 1711 cache = outerCache[ type ] || [];
nickjillings@1318 1712 nodeIndex = cache[0] === dirruns && cache[1];
nickjillings@1318 1713 diff = cache[0] === dirruns && cache[2];
nickjillings@1318 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nickjillings@1318 1715
nickjillings@1318 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1318 1717
nickjillings@1318 1718 // Fallback to seeking `elem` from the start
nickjillings@1318 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1318 1720
nickjillings@1318 1721 // When found, cache indexes on `parent` and break
nickjillings@1318 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nickjillings@1318 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nickjillings@1318 1724 break;
nickjillings@1318 1725 }
nickjillings@1318 1726 }
nickjillings@1318 1727
nickjillings@1318 1728 // Use previously-cached element index if available
nickjillings@1318 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nickjillings@1318 1730 diff = cache[1];
nickjillings@1318 1731
nickjillings@1318 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nickjillings@1318 1733 } else {
nickjillings@1318 1734 // Use the same loop as above to seek `elem` from the start
nickjillings@1318 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1318 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1318 1737
nickjillings@1318 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nickjillings@1318 1739 // Cache the index of each encountered element
nickjillings@1318 1740 if ( useCache ) {
nickjillings@1318 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nickjillings@1318 1742 }
nickjillings@1318 1743
nickjillings@1318 1744 if ( node === elem ) {
nickjillings@1318 1745 break;
nickjillings@1318 1746 }
nickjillings@1318 1747 }
nickjillings@1318 1748 }
nickjillings@1318 1749 }
nickjillings@1318 1750
nickjillings@1318 1751 // Incorporate the offset, then check against cycle size
nickjillings@1318 1752 diff -= last;
nickjillings@1318 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nickjillings@1318 1754 }
nickjillings@1318 1755 };
nickjillings@1318 1756 },
nickjillings@1318 1757
nickjillings@1318 1758 "PSEUDO": function( pseudo, argument ) {
nickjillings@1318 1759 // pseudo-class names are case-insensitive
nickjillings@1318 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nickjillings@1318 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nickjillings@1318 1762 // Remember that setFilters inherits from pseudos
nickjillings@1318 1763 var args,
nickjillings@1318 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nickjillings@1318 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nickjillings@1318 1766
nickjillings@1318 1767 // The user may use createPseudo to indicate that
nickjillings@1318 1768 // arguments are needed to create the filter function
nickjillings@1318 1769 // just as Sizzle does
nickjillings@1318 1770 if ( fn[ expando ] ) {
nickjillings@1318 1771 return fn( argument );
nickjillings@1318 1772 }
nickjillings@1318 1773
nickjillings@1318 1774 // But maintain support for old signatures
nickjillings@1318 1775 if ( fn.length > 1 ) {
nickjillings@1318 1776 args = [ pseudo, pseudo, "", argument ];
nickjillings@1318 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nickjillings@1318 1778 markFunction(function( seed, matches ) {
nickjillings@1318 1779 var idx,
nickjillings@1318 1780 matched = fn( seed, argument ),
nickjillings@1318 1781 i = matched.length;
nickjillings@1318 1782 while ( i-- ) {
nickjillings@1318 1783 idx = indexOf( seed, matched[i] );
nickjillings@1318 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nickjillings@1318 1785 }
nickjillings@1318 1786 }) :
nickjillings@1318 1787 function( elem ) {
nickjillings@1318 1788 return fn( elem, 0, args );
nickjillings@1318 1789 };
nickjillings@1318 1790 }
nickjillings@1318 1791
nickjillings@1318 1792 return fn;
nickjillings@1318 1793 }
nickjillings@1318 1794 },
nickjillings@1318 1795
nickjillings@1318 1796 pseudos: {
nickjillings@1318 1797 // Potentially complex pseudos
nickjillings@1318 1798 "not": markFunction(function( selector ) {
nickjillings@1318 1799 // Trim the selector passed to compile
nickjillings@1318 1800 // to avoid treating leading and trailing
nickjillings@1318 1801 // spaces as combinators
nickjillings@1318 1802 var input = [],
nickjillings@1318 1803 results = [],
nickjillings@1318 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nickjillings@1318 1805
nickjillings@1318 1806 return matcher[ expando ] ?
nickjillings@1318 1807 markFunction(function( seed, matches, context, xml ) {
nickjillings@1318 1808 var elem,
nickjillings@1318 1809 unmatched = matcher( seed, null, xml, [] ),
nickjillings@1318 1810 i = seed.length;
nickjillings@1318 1811
nickjillings@1318 1812 // Match elements unmatched by `matcher`
nickjillings@1318 1813 while ( i-- ) {
nickjillings@1318 1814 if ( (elem = unmatched[i]) ) {
nickjillings@1318 1815 seed[i] = !(matches[i] = elem);
nickjillings@1318 1816 }
nickjillings@1318 1817 }
nickjillings@1318 1818 }) :
nickjillings@1318 1819 function( elem, context, xml ) {
nickjillings@1318 1820 input[0] = elem;
nickjillings@1318 1821 matcher( input, null, xml, results );
nickjillings@1318 1822 // Don't keep the element (issue #299)
nickjillings@1318 1823 input[0] = null;
nickjillings@1318 1824 return !results.pop();
nickjillings@1318 1825 };
nickjillings@1318 1826 }),
nickjillings@1318 1827
nickjillings@1318 1828 "has": markFunction(function( selector ) {
nickjillings@1318 1829 return function( elem ) {
nickjillings@1318 1830 return Sizzle( selector, elem ).length > 0;
nickjillings@1318 1831 };
nickjillings@1318 1832 }),
nickjillings@1318 1833
nickjillings@1318 1834 "contains": markFunction(function( text ) {
nickjillings@1318 1835 text = text.replace( runescape, funescape );
nickjillings@1318 1836 return function( elem ) {
nickjillings@1318 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nickjillings@1318 1838 };
nickjillings@1318 1839 }),
nickjillings@1318 1840
nickjillings@1318 1841 // "Whether an element is represented by a :lang() selector
nickjillings@1318 1842 // is based solely on the element's language value
nickjillings@1318 1843 // being equal to the identifier C,
nickjillings@1318 1844 // or beginning with the identifier C immediately followed by "-".
nickjillings@1318 1845 // The matching of C against the element's language value is performed case-insensitively.
nickjillings@1318 1846 // The identifier C does not have to be a valid language name."
nickjillings@1318 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nickjillings@1318 1848 "lang": markFunction( function( lang ) {
nickjillings@1318 1849 // lang value must be a valid identifier
nickjillings@1318 1850 if ( !ridentifier.test(lang || "") ) {
nickjillings@1318 1851 Sizzle.error( "unsupported lang: " + lang );
nickjillings@1318 1852 }
nickjillings@1318 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nickjillings@1318 1854 return function( elem ) {
nickjillings@1318 1855 var elemLang;
nickjillings@1318 1856 do {
nickjillings@1318 1857 if ( (elemLang = documentIsHTML ?
nickjillings@1318 1858 elem.lang :
nickjillings@1318 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nickjillings@1318 1860
nickjillings@1318 1861 elemLang = elemLang.toLowerCase();
nickjillings@1318 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nickjillings@1318 1863 }
nickjillings@1318 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nickjillings@1318 1865 return false;
nickjillings@1318 1866 };
nickjillings@1318 1867 }),
nickjillings@1318 1868
nickjillings@1318 1869 // Miscellaneous
nickjillings@1318 1870 "target": function( elem ) {
nickjillings@1318 1871 var hash = window.location && window.location.hash;
nickjillings@1318 1872 return hash && hash.slice( 1 ) === elem.id;
nickjillings@1318 1873 },
nickjillings@1318 1874
nickjillings@1318 1875 "root": function( elem ) {
nickjillings@1318 1876 return elem === docElem;
nickjillings@1318 1877 },
nickjillings@1318 1878
nickjillings@1318 1879 "focus": function( elem ) {
nickjillings@1318 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nickjillings@1318 1881 },
nickjillings@1318 1882
nickjillings@1318 1883 // Boolean properties
nickjillings@1318 1884 "enabled": function( elem ) {
nickjillings@1318 1885 return elem.disabled === false;
nickjillings@1318 1886 },
nickjillings@1318 1887
nickjillings@1318 1888 "disabled": function( elem ) {
nickjillings@1318 1889 return elem.disabled === true;
nickjillings@1318 1890 },
nickjillings@1318 1891
nickjillings@1318 1892 "checked": function( elem ) {
nickjillings@1318 1893 // In CSS3, :checked should return both checked and selected elements
nickjillings@1318 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1318 1895 var nodeName = elem.nodeName.toLowerCase();
nickjillings@1318 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nickjillings@1318 1897 },
nickjillings@1318 1898
nickjillings@1318 1899 "selected": function( elem ) {
nickjillings@1318 1900 // Accessing this property makes selected-by-default
nickjillings@1318 1901 // options in Safari work properly
nickjillings@1318 1902 if ( elem.parentNode ) {
nickjillings@1318 1903 elem.parentNode.selectedIndex;
nickjillings@1318 1904 }
nickjillings@1318 1905
nickjillings@1318 1906 return elem.selected === true;
nickjillings@1318 1907 },
nickjillings@1318 1908
nickjillings@1318 1909 // Contents
nickjillings@1318 1910 "empty": function( elem ) {
nickjillings@1318 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nickjillings@1318 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nickjillings@1318 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nickjillings@1318 1914 // nodeType < 6 works because attributes (2) do not appear as children
nickjillings@1318 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1318 1916 if ( elem.nodeType < 6 ) {
nickjillings@1318 1917 return false;
nickjillings@1318 1918 }
nickjillings@1318 1919 }
nickjillings@1318 1920 return true;
nickjillings@1318 1921 },
nickjillings@1318 1922
nickjillings@1318 1923 "parent": function( elem ) {
nickjillings@1318 1924 return !Expr.pseudos["empty"]( elem );
nickjillings@1318 1925 },
nickjillings@1318 1926
nickjillings@1318 1927 // Element/input types
nickjillings@1318 1928 "header": function( elem ) {
nickjillings@1318 1929 return rheader.test( elem.nodeName );
nickjillings@1318 1930 },
nickjillings@1318 1931
nickjillings@1318 1932 "input": function( elem ) {
nickjillings@1318 1933 return rinputs.test( elem.nodeName );
nickjillings@1318 1934 },
nickjillings@1318 1935
nickjillings@1318 1936 "button": function( elem ) {
nickjillings@1318 1937 var name = elem.nodeName.toLowerCase();
nickjillings@1318 1938 return name === "input" && elem.type === "button" || name === "button";
nickjillings@1318 1939 },
nickjillings@1318 1940
nickjillings@1318 1941 "text": function( elem ) {
nickjillings@1318 1942 var attr;
nickjillings@1318 1943 return elem.nodeName.toLowerCase() === "input" &&
nickjillings@1318 1944 elem.type === "text" &&
nickjillings@1318 1945
nickjillings@1318 1946 // Support: IE<8
nickjillings@1318 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nickjillings@1318 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nickjillings@1318 1949 },
nickjillings@1318 1950
nickjillings@1318 1951 // Position-in-collection
nickjillings@1318 1952 "first": createPositionalPseudo(function() {
nickjillings@1318 1953 return [ 0 ];
nickjillings@1318 1954 }),
nickjillings@1318 1955
nickjillings@1318 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1318 1957 return [ length - 1 ];
nickjillings@1318 1958 }),
nickjillings@1318 1959
nickjillings@1318 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1318 1961 return [ argument < 0 ? argument + length : argument ];
nickjillings@1318 1962 }),
nickjillings@1318 1963
nickjillings@1318 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1318 1965 var i = 0;
nickjillings@1318 1966 for ( ; i < length; i += 2 ) {
nickjillings@1318 1967 matchIndexes.push( i );
nickjillings@1318 1968 }
nickjillings@1318 1969 return matchIndexes;
nickjillings@1318 1970 }),
nickjillings@1318 1971
nickjillings@1318 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1318 1973 var i = 1;
nickjillings@1318 1974 for ( ; i < length; i += 2 ) {
nickjillings@1318 1975 matchIndexes.push( i );
nickjillings@1318 1976 }
nickjillings@1318 1977 return matchIndexes;
nickjillings@1318 1978 }),
nickjillings@1318 1979
nickjillings@1318 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1318 1981 var i = argument < 0 ? argument + length : argument;
nickjillings@1318 1982 for ( ; --i >= 0; ) {
nickjillings@1318 1983 matchIndexes.push( i );
nickjillings@1318 1984 }
nickjillings@1318 1985 return matchIndexes;
nickjillings@1318 1986 }),
nickjillings@1318 1987
nickjillings@1318 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1318 1989 var i = argument < 0 ? argument + length : argument;
nickjillings@1318 1990 for ( ; ++i < length; ) {
nickjillings@1318 1991 matchIndexes.push( i );
nickjillings@1318 1992 }
nickjillings@1318 1993 return matchIndexes;
nickjillings@1318 1994 })
nickjillings@1318 1995 }
nickjillings@1318 1996 };
nickjillings@1318 1997
nickjillings@1318 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nickjillings@1318 1999
nickjillings@1318 2000 // Add button/input type pseudos
nickjillings@1318 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nickjillings@1318 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nickjillings@1318 2003 }
nickjillings@1318 2004 for ( i in { submit: true, reset: true } ) {
nickjillings@1318 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nickjillings@1318 2006 }
nickjillings@1318 2007
nickjillings@1318 2008 // Easy API for creating new setFilters
nickjillings@1318 2009 function setFilters() {}
nickjillings@1318 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nickjillings@1318 2011 Expr.setFilters = new setFilters();
nickjillings@1318 2012
nickjillings@1318 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nickjillings@1318 2014 var matched, match, tokens, type,
nickjillings@1318 2015 soFar, groups, preFilters,
nickjillings@1318 2016 cached = tokenCache[ selector + " " ];
nickjillings@1318 2017
nickjillings@1318 2018 if ( cached ) {
nickjillings@1318 2019 return parseOnly ? 0 : cached.slice( 0 );
nickjillings@1318 2020 }
nickjillings@1318 2021
nickjillings@1318 2022 soFar = selector;
nickjillings@1318 2023 groups = [];
nickjillings@1318 2024 preFilters = Expr.preFilter;
nickjillings@1318 2025
nickjillings@1318 2026 while ( soFar ) {
nickjillings@1318 2027
nickjillings@1318 2028 // Comma and first run
nickjillings@1318 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nickjillings@1318 2030 if ( match ) {
nickjillings@1318 2031 // Don't consume trailing commas as valid
nickjillings@1318 2032 soFar = soFar.slice( match[0].length ) || soFar;
nickjillings@1318 2033 }
nickjillings@1318 2034 groups.push( (tokens = []) );
nickjillings@1318 2035 }
nickjillings@1318 2036
nickjillings@1318 2037 matched = false;
nickjillings@1318 2038
nickjillings@1318 2039 // Combinators
nickjillings@1318 2040 if ( (match = rcombinators.exec( soFar )) ) {
nickjillings@1318 2041 matched = match.shift();
nickjillings@1318 2042 tokens.push({
nickjillings@1318 2043 value: matched,
nickjillings@1318 2044 // Cast descendant combinators to space
nickjillings@1318 2045 type: match[0].replace( rtrim, " " )
nickjillings@1318 2046 });
nickjillings@1318 2047 soFar = soFar.slice( matched.length );
nickjillings@1318 2048 }
nickjillings@1318 2049
nickjillings@1318 2050 // Filters
nickjillings@1318 2051 for ( type in Expr.filter ) {
nickjillings@1318 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nickjillings@1318 2053 (match = preFilters[ type ]( match ))) ) {
nickjillings@1318 2054 matched = match.shift();
nickjillings@1318 2055 tokens.push({
nickjillings@1318 2056 value: matched,
nickjillings@1318 2057 type: type,
nickjillings@1318 2058 matches: match
nickjillings@1318 2059 });
nickjillings@1318 2060 soFar = soFar.slice( matched.length );
nickjillings@1318 2061 }
nickjillings@1318 2062 }
nickjillings@1318 2063
nickjillings@1318 2064 if ( !matched ) {
nickjillings@1318 2065 break;
nickjillings@1318 2066 }
nickjillings@1318 2067 }
nickjillings@1318 2068
nickjillings@1318 2069 // Return the length of the invalid excess
nickjillings@1318 2070 // if we're just parsing
nickjillings@1318 2071 // Otherwise, throw an error or return tokens
nickjillings@1318 2072 return parseOnly ?
nickjillings@1318 2073 soFar.length :
nickjillings@1318 2074 soFar ?
nickjillings@1318 2075 Sizzle.error( selector ) :
nickjillings@1318 2076 // Cache the tokens
nickjillings@1318 2077 tokenCache( selector, groups ).slice( 0 );
nickjillings@1318 2078 };
nickjillings@1318 2079
nickjillings@1318 2080 function toSelector( tokens ) {
nickjillings@1318 2081 var i = 0,
nickjillings@1318 2082 len = tokens.length,
nickjillings@1318 2083 selector = "";
nickjillings@1318 2084 for ( ; i < len; i++ ) {
nickjillings@1318 2085 selector += tokens[i].value;
nickjillings@1318 2086 }
nickjillings@1318 2087 return selector;
nickjillings@1318 2088 }
nickjillings@1318 2089
nickjillings@1318 2090 function addCombinator( matcher, combinator, base ) {
nickjillings@1318 2091 var dir = combinator.dir,
nickjillings@1318 2092 checkNonElements = base && dir === "parentNode",
nickjillings@1318 2093 doneName = done++;
nickjillings@1318 2094
nickjillings@1318 2095 return combinator.first ?
nickjillings@1318 2096 // Check against closest ancestor/preceding element
nickjillings@1318 2097 function( elem, context, xml ) {
nickjillings@1318 2098 while ( (elem = elem[ dir ]) ) {
nickjillings@1318 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1318 2100 return matcher( elem, context, xml );
nickjillings@1318 2101 }
nickjillings@1318 2102 }
nickjillings@1318 2103 } :
nickjillings@1318 2104
nickjillings@1318 2105 // Check against all ancestor/preceding elements
nickjillings@1318 2106 function( elem, context, xml ) {
nickjillings@1318 2107 var oldCache, outerCache,
nickjillings@1318 2108 newCache = [ dirruns, doneName ];
nickjillings@1318 2109
nickjillings@1318 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nickjillings@1318 2111 if ( xml ) {
nickjillings@1318 2112 while ( (elem = elem[ dir ]) ) {
nickjillings@1318 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1318 2114 if ( matcher( elem, context, xml ) ) {
nickjillings@1318 2115 return true;
nickjillings@1318 2116 }
nickjillings@1318 2117 }
nickjillings@1318 2118 }
nickjillings@1318 2119 } else {
nickjillings@1318 2120 while ( (elem = elem[ dir ]) ) {
nickjillings@1318 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1318 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nickjillings@1318 2123 if ( (oldCache = outerCache[ dir ]) &&
nickjillings@1318 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nickjillings@1318 2125
nickjillings@1318 2126 // Assign to newCache so results back-propagate to previous elements
nickjillings@1318 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nickjillings@1318 2128 } else {
nickjillings@1318 2129 // Reuse newcache so results back-propagate to previous elements
nickjillings@1318 2130 outerCache[ dir ] = newCache;
nickjillings@1318 2131
nickjillings@1318 2132 // A match means we're done; a fail means we have to keep checking
nickjillings@1318 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nickjillings@1318 2134 return true;
nickjillings@1318 2135 }
nickjillings@1318 2136 }
nickjillings@1318 2137 }
nickjillings@1318 2138 }
nickjillings@1318 2139 }
nickjillings@1318 2140 };
nickjillings@1318 2141 }
nickjillings@1318 2142
nickjillings@1318 2143 function elementMatcher( matchers ) {
nickjillings@1318 2144 return matchers.length > 1 ?
nickjillings@1318 2145 function( elem, context, xml ) {
nickjillings@1318 2146 var i = matchers.length;
nickjillings@1318 2147 while ( i-- ) {
nickjillings@1318 2148 if ( !matchers[i]( elem, context, xml ) ) {
nickjillings@1318 2149 return false;
nickjillings@1318 2150 }
nickjillings@1318 2151 }
nickjillings@1318 2152 return true;
nickjillings@1318 2153 } :
nickjillings@1318 2154 matchers[0];
nickjillings@1318 2155 }
nickjillings@1318 2156
nickjillings@1318 2157 function multipleContexts( selector, contexts, results ) {
nickjillings@1318 2158 var i = 0,
nickjillings@1318 2159 len = contexts.length;
nickjillings@1318 2160 for ( ; i < len; i++ ) {
nickjillings@1318 2161 Sizzle( selector, contexts[i], results );
nickjillings@1318 2162 }
nickjillings@1318 2163 return results;
nickjillings@1318 2164 }
nickjillings@1318 2165
nickjillings@1318 2166 function condense( unmatched, map, filter, context, xml ) {
nickjillings@1318 2167 var elem,
nickjillings@1318 2168 newUnmatched = [],
nickjillings@1318 2169 i = 0,
nickjillings@1318 2170 len = unmatched.length,
nickjillings@1318 2171 mapped = map != null;
nickjillings@1318 2172
nickjillings@1318 2173 for ( ; i < len; i++ ) {
nickjillings@1318 2174 if ( (elem = unmatched[i]) ) {
nickjillings@1318 2175 if ( !filter || filter( elem, context, xml ) ) {
nickjillings@1318 2176 newUnmatched.push( elem );
nickjillings@1318 2177 if ( mapped ) {
nickjillings@1318 2178 map.push( i );
nickjillings@1318 2179 }
nickjillings@1318 2180 }
nickjillings@1318 2181 }
nickjillings@1318 2182 }
nickjillings@1318 2183
nickjillings@1318 2184 return newUnmatched;
nickjillings@1318 2185 }
nickjillings@1318 2186
nickjillings@1318 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nickjillings@1318 2188 if ( postFilter && !postFilter[ expando ] ) {
nickjillings@1318 2189 postFilter = setMatcher( postFilter );
nickjillings@1318 2190 }
nickjillings@1318 2191 if ( postFinder && !postFinder[ expando ] ) {
nickjillings@1318 2192 postFinder = setMatcher( postFinder, postSelector );
nickjillings@1318 2193 }
nickjillings@1318 2194 return markFunction(function( seed, results, context, xml ) {
nickjillings@1318 2195 var temp, i, elem,
nickjillings@1318 2196 preMap = [],
nickjillings@1318 2197 postMap = [],
nickjillings@1318 2198 preexisting = results.length,
nickjillings@1318 2199
nickjillings@1318 2200 // Get initial elements from seed or context
nickjillings@1318 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nickjillings@1318 2202
nickjillings@1318 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nickjillings@1318 2204 matcherIn = preFilter && ( seed || !selector ) ?
nickjillings@1318 2205 condense( elems, preMap, preFilter, context, xml ) :
nickjillings@1318 2206 elems,
nickjillings@1318 2207
nickjillings@1318 2208 matcherOut = matcher ?
nickjillings@1318 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nickjillings@1318 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nickjillings@1318 2211
nickjillings@1318 2212 // ...intermediate processing is necessary
nickjillings@1318 2213 [] :
nickjillings@1318 2214
nickjillings@1318 2215 // ...otherwise use results directly
nickjillings@1318 2216 results :
nickjillings@1318 2217 matcherIn;
nickjillings@1318 2218
nickjillings@1318 2219 // Find primary matches
nickjillings@1318 2220 if ( matcher ) {
nickjillings@1318 2221 matcher( matcherIn, matcherOut, context, xml );
nickjillings@1318 2222 }
nickjillings@1318 2223
nickjillings@1318 2224 // Apply postFilter
nickjillings@1318 2225 if ( postFilter ) {
nickjillings@1318 2226 temp = condense( matcherOut, postMap );
nickjillings@1318 2227 postFilter( temp, [], context, xml );
nickjillings@1318 2228
nickjillings@1318 2229 // Un-match failing elements by moving them back to matcherIn
nickjillings@1318 2230 i = temp.length;
nickjillings@1318 2231 while ( i-- ) {
nickjillings@1318 2232 if ( (elem = temp[i]) ) {
nickjillings@1318 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nickjillings@1318 2234 }
nickjillings@1318 2235 }
nickjillings@1318 2236 }
nickjillings@1318 2237
nickjillings@1318 2238 if ( seed ) {
nickjillings@1318 2239 if ( postFinder || preFilter ) {
nickjillings@1318 2240 if ( postFinder ) {
nickjillings@1318 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nickjillings@1318 2242 temp = [];
nickjillings@1318 2243 i = matcherOut.length;
nickjillings@1318 2244 while ( i-- ) {
nickjillings@1318 2245 if ( (elem = matcherOut[i]) ) {
nickjillings@1318 2246 // Restore matcherIn since elem is not yet a final match
nickjillings@1318 2247 temp.push( (matcherIn[i] = elem) );
nickjillings@1318 2248 }
nickjillings@1318 2249 }
nickjillings@1318 2250 postFinder( null, (matcherOut = []), temp, xml );
nickjillings@1318 2251 }
nickjillings@1318 2252
nickjillings@1318 2253 // Move matched elements from seed to results to keep them synchronized
nickjillings@1318 2254 i = matcherOut.length;
nickjillings@1318 2255 while ( i-- ) {
nickjillings@1318 2256 if ( (elem = matcherOut[i]) &&
nickjillings@1318 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nickjillings@1318 2258
nickjillings@1318 2259 seed[temp] = !(results[temp] = elem);
nickjillings@1318 2260 }
nickjillings@1318 2261 }
nickjillings@1318 2262 }
nickjillings@1318 2263
nickjillings@1318 2264 // Add elements to results, through postFinder if defined
nickjillings@1318 2265 } else {
nickjillings@1318 2266 matcherOut = condense(
nickjillings@1318 2267 matcherOut === results ?
nickjillings@1318 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nickjillings@1318 2269 matcherOut
nickjillings@1318 2270 );
nickjillings@1318 2271 if ( postFinder ) {
nickjillings@1318 2272 postFinder( null, results, matcherOut, xml );
nickjillings@1318 2273 } else {
nickjillings@1318 2274 push.apply( results, matcherOut );
nickjillings@1318 2275 }
nickjillings@1318 2276 }
nickjillings@1318 2277 });
nickjillings@1318 2278 }
nickjillings@1318 2279
nickjillings@1318 2280 function matcherFromTokens( tokens ) {
nickjillings@1318 2281 var checkContext, matcher, j,
nickjillings@1318 2282 len = tokens.length,
nickjillings@1318 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nickjillings@1318 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nickjillings@1318 2285 i = leadingRelative ? 1 : 0,
nickjillings@1318 2286
nickjillings@1318 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nickjillings@1318 2288 matchContext = addCombinator( function( elem ) {
nickjillings@1318 2289 return elem === checkContext;
nickjillings@1318 2290 }, implicitRelative, true ),
nickjillings@1318 2291 matchAnyContext = addCombinator( function( elem ) {
nickjillings@1318 2292 return indexOf( checkContext, elem ) > -1;
nickjillings@1318 2293 }, implicitRelative, true ),
nickjillings@1318 2294 matchers = [ function( elem, context, xml ) {
nickjillings@1318 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nickjillings@1318 2296 (checkContext = context).nodeType ?
nickjillings@1318 2297 matchContext( elem, context, xml ) :
nickjillings@1318 2298 matchAnyContext( elem, context, xml ) );
nickjillings@1318 2299 // Avoid hanging onto element (issue #299)
nickjillings@1318 2300 checkContext = null;
nickjillings@1318 2301 return ret;
nickjillings@1318 2302 } ];
nickjillings@1318 2303
nickjillings@1318 2304 for ( ; i < len; i++ ) {
nickjillings@1318 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nickjillings@1318 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nickjillings@1318 2307 } else {
nickjillings@1318 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nickjillings@1318 2309
nickjillings@1318 2310 // Return special upon seeing a positional matcher
nickjillings@1318 2311 if ( matcher[ expando ] ) {
nickjillings@1318 2312 // Find the next relative operator (if any) for proper handling
nickjillings@1318 2313 j = ++i;
nickjillings@1318 2314 for ( ; j < len; j++ ) {
nickjillings@1318 2315 if ( Expr.relative[ tokens[j].type ] ) {
nickjillings@1318 2316 break;
nickjillings@1318 2317 }
nickjillings@1318 2318 }
nickjillings@1318 2319 return setMatcher(
nickjillings@1318 2320 i > 1 && elementMatcher( matchers ),
nickjillings@1318 2321 i > 1 && toSelector(
nickjillings@1318 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nickjillings@1318 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nickjillings@1318 2324 ).replace( rtrim, "$1" ),
nickjillings@1318 2325 matcher,
nickjillings@1318 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nickjillings@1318 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nickjillings@1318 2328 j < len && toSelector( tokens )
nickjillings@1318 2329 );
nickjillings@1318 2330 }
nickjillings@1318 2331 matchers.push( matcher );
nickjillings@1318 2332 }
nickjillings@1318 2333 }
nickjillings@1318 2334
nickjillings@1318 2335 return elementMatcher( matchers );
nickjillings@1318 2336 }
nickjillings@1318 2337
nickjillings@1318 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nickjillings@1318 2339 var bySet = setMatchers.length > 0,
nickjillings@1318 2340 byElement = elementMatchers.length > 0,
nickjillings@1318 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nickjillings@1318 2342 var elem, j, matcher,
nickjillings@1318 2343 matchedCount = 0,
nickjillings@1318 2344 i = "0",
nickjillings@1318 2345 unmatched = seed && [],
nickjillings@1318 2346 setMatched = [],
nickjillings@1318 2347 contextBackup = outermostContext,
nickjillings@1318 2348 // We must always have either seed elements or outermost context
nickjillings@1318 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nickjillings@1318 2350 // Use integer dirruns iff this is the outermost matcher
nickjillings@1318 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nickjillings@1318 2352 len = elems.length;
nickjillings@1318 2353
nickjillings@1318 2354 if ( outermost ) {
nickjillings@1318 2355 outermostContext = context !== document && context;
nickjillings@1318 2356 }
nickjillings@1318 2357
nickjillings@1318 2358 // Add elements passing elementMatchers directly to results
nickjillings@1318 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nickjillings@1318 2360 // Support: IE<9, Safari
nickjillings@1318 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nickjillings@1318 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nickjillings@1318 2363 if ( byElement && elem ) {
nickjillings@1318 2364 j = 0;
nickjillings@1318 2365 while ( (matcher = elementMatchers[j++]) ) {
nickjillings@1318 2366 if ( matcher( elem, context, xml ) ) {
nickjillings@1318 2367 results.push( elem );
nickjillings@1318 2368 break;
nickjillings@1318 2369 }
nickjillings@1318 2370 }
nickjillings@1318 2371 if ( outermost ) {
nickjillings@1318 2372 dirruns = dirrunsUnique;
nickjillings@1318 2373 }
nickjillings@1318 2374 }
nickjillings@1318 2375
nickjillings@1318 2376 // Track unmatched elements for set filters
nickjillings@1318 2377 if ( bySet ) {
nickjillings@1318 2378 // They will have gone through all possible matchers
nickjillings@1318 2379 if ( (elem = !matcher && elem) ) {
nickjillings@1318 2380 matchedCount--;
nickjillings@1318 2381 }
nickjillings@1318 2382
nickjillings@1318 2383 // Lengthen the array for every element, matched or not
nickjillings@1318 2384 if ( seed ) {
nickjillings@1318 2385 unmatched.push( elem );
nickjillings@1318 2386 }
nickjillings@1318 2387 }
nickjillings@1318 2388 }
nickjillings@1318 2389
nickjillings@1318 2390 // Apply set filters to unmatched elements
nickjillings@1318 2391 matchedCount += i;
nickjillings@1318 2392 if ( bySet && i !== matchedCount ) {
nickjillings@1318 2393 j = 0;
nickjillings@1318 2394 while ( (matcher = setMatchers[j++]) ) {
nickjillings@1318 2395 matcher( unmatched, setMatched, context, xml );
nickjillings@1318 2396 }
nickjillings@1318 2397
nickjillings@1318 2398 if ( seed ) {
nickjillings@1318 2399 // Reintegrate element matches to eliminate the need for sorting
nickjillings@1318 2400 if ( matchedCount > 0 ) {
nickjillings@1318 2401 while ( i-- ) {
nickjillings@1318 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nickjillings@1318 2403 setMatched[i] = pop.call( results );
nickjillings@1318 2404 }
nickjillings@1318 2405 }
nickjillings@1318 2406 }
nickjillings@1318 2407
nickjillings@1318 2408 // Discard index placeholder values to get only actual matches
nickjillings@1318 2409 setMatched = condense( setMatched );
nickjillings@1318 2410 }
nickjillings@1318 2411
nickjillings@1318 2412 // Add matches to results
nickjillings@1318 2413 push.apply( results, setMatched );
nickjillings@1318 2414
nickjillings@1318 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nickjillings@1318 2416 if ( outermost && !seed && setMatched.length > 0 &&
nickjillings@1318 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nickjillings@1318 2418
nickjillings@1318 2419 Sizzle.uniqueSort( results );
nickjillings@1318 2420 }
nickjillings@1318 2421 }
nickjillings@1318 2422
nickjillings@1318 2423 // Override manipulation of globals by nested matchers
nickjillings@1318 2424 if ( outermost ) {
nickjillings@1318 2425 dirruns = dirrunsUnique;
nickjillings@1318 2426 outermostContext = contextBackup;
nickjillings@1318 2427 }
nickjillings@1318 2428
nickjillings@1318 2429 return unmatched;
nickjillings@1318 2430 };
nickjillings@1318 2431
nickjillings@1318 2432 return bySet ?
nickjillings@1318 2433 markFunction( superMatcher ) :
nickjillings@1318 2434 superMatcher;
nickjillings@1318 2435 }
nickjillings@1318 2436
nickjillings@1318 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nickjillings@1318 2438 var i,
nickjillings@1318 2439 setMatchers = [],
nickjillings@1318 2440 elementMatchers = [],
nickjillings@1318 2441 cached = compilerCache[ selector + " " ];
nickjillings@1318 2442
nickjillings@1318 2443 if ( !cached ) {
nickjillings@1318 2444 // Generate a function of recursive functions that can be used to check each element
nickjillings@1318 2445 if ( !match ) {
nickjillings@1318 2446 match = tokenize( selector );
nickjillings@1318 2447 }
nickjillings@1318 2448 i = match.length;
nickjillings@1318 2449 while ( i-- ) {
nickjillings@1318 2450 cached = matcherFromTokens( match[i] );
nickjillings@1318 2451 if ( cached[ expando ] ) {
nickjillings@1318 2452 setMatchers.push( cached );
nickjillings@1318 2453 } else {
nickjillings@1318 2454 elementMatchers.push( cached );
nickjillings@1318 2455 }
nickjillings@1318 2456 }
nickjillings@1318 2457
nickjillings@1318 2458 // Cache the compiled function
nickjillings@1318 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nickjillings@1318 2460
nickjillings@1318 2461 // Save selector and tokenization
nickjillings@1318 2462 cached.selector = selector;
nickjillings@1318 2463 }
nickjillings@1318 2464 return cached;
nickjillings@1318 2465 };
nickjillings@1318 2466
nickjillings@1318 2467 /**
nickjillings@1318 2468 * A low-level selection function that works with Sizzle's compiled
nickjillings@1318 2469 * selector functions
nickjillings@1318 2470 * @param {String|Function} selector A selector or a pre-compiled
nickjillings@1318 2471 * selector function built with Sizzle.compile
nickjillings@1318 2472 * @param {Element} context
nickjillings@1318 2473 * @param {Array} [results]
nickjillings@1318 2474 * @param {Array} [seed] A set of elements to match against
nickjillings@1318 2475 */
nickjillings@1318 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nickjillings@1318 2477 var i, tokens, token, type, find,
nickjillings@1318 2478 compiled = typeof selector === "function" && selector,
nickjillings@1318 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nickjillings@1318 2480
nickjillings@1318 2481 results = results || [];
nickjillings@1318 2482
nickjillings@1318 2483 // Try to minimize operations if there is no seed and only one group
nickjillings@1318 2484 if ( match.length === 1 ) {
nickjillings@1318 2485
nickjillings@1318 2486 // Take a shortcut and set the context if the root selector is an ID
nickjillings@1318 2487 tokens = match[0] = match[0].slice( 0 );
nickjillings@1318 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nickjillings@1318 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nickjillings@1318 2490 Expr.relative[ tokens[1].type ] ) {
nickjillings@1318 2491
nickjillings@1318 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nickjillings@1318 2493 if ( !context ) {
nickjillings@1318 2494 return results;
nickjillings@1318 2495
nickjillings@1318 2496 // Precompiled matchers will still verify ancestry, so step up a level
nickjillings@1318 2497 } else if ( compiled ) {
nickjillings@1318 2498 context = context.parentNode;
nickjillings@1318 2499 }
nickjillings@1318 2500
nickjillings@1318 2501 selector = selector.slice( tokens.shift().value.length );
nickjillings@1318 2502 }
nickjillings@1318 2503
nickjillings@1318 2504 // Fetch a seed set for right-to-left matching
nickjillings@1318 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nickjillings@1318 2506 while ( i-- ) {
nickjillings@1318 2507 token = tokens[i];
nickjillings@1318 2508
nickjillings@1318 2509 // Abort if we hit a combinator
nickjillings@1318 2510 if ( Expr.relative[ (type = token.type) ] ) {
nickjillings@1318 2511 break;
nickjillings@1318 2512 }
nickjillings@1318 2513 if ( (find = Expr.find[ type ]) ) {
nickjillings@1318 2514 // Search, expanding context for leading sibling combinators
nickjillings@1318 2515 if ( (seed = find(
nickjillings@1318 2516 token.matches[0].replace( runescape, funescape ),
nickjillings@1318 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nickjillings@1318 2518 )) ) {
nickjillings@1318 2519
nickjillings@1318 2520 // If seed is empty or no tokens remain, we can return early
nickjillings@1318 2521 tokens.splice( i, 1 );
nickjillings@1318 2522 selector = seed.length && toSelector( tokens );
nickjillings@1318 2523 if ( !selector ) {
nickjillings@1318 2524 push.apply( results, seed );
nickjillings@1318 2525 return results;
nickjillings@1318 2526 }
nickjillings@1318 2527
nickjillings@1318 2528 break;
nickjillings@1318 2529 }
nickjillings@1318 2530 }
nickjillings@1318 2531 }
nickjillings@1318 2532 }
nickjillings@1318 2533
nickjillings@1318 2534 // Compile and execute a filtering function if one is not provided
nickjillings@1318 2535 // Provide `match` to avoid retokenization if we modified the selector above
nickjillings@1318 2536 ( compiled || compile( selector, match ) )(
nickjillings@1318 2537 seed,
nickjillings@1318 2538 context,
nickjillings@1318 2539 !documentIsHTML,
nickjillings@1318 2540 results,
nickjillings@1318 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nickjillings@1318 2542 );
nickjillings@1318 2543 return results;
nickjillings@1318 2544 };
nickjillings@1318 2545
nickjillings@1318 2546 // One-time assignments
nickjillings@1318 2547
nickjillings@1318 2548 // Sort stability
nickjillings@1318 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nickjillings@1318 2550
nickjillings@1318 2551 // Support: Chrome 14-35+
nickjillings@1318 2552 // Always assume duplicates if they aren't passed to the comparison function
nickjillings@1318 2553 support.detectDuplicates = !!hasDuplicate;
nickjillings@1318 2554
nickjillings@1318 2555 // Initialize against the default document
nickjillings@1318 2556 setDocument();
nickjillings@1318 2557
nickjillings@1318 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nickjillings@1318 2559 // Detached nodes confoundingly follow *each other*
nickjillings@1318 2560 support.sortDetached = assert(function( div1 ) {
nickjillings@1318 2561 // Should return 1, but returns 4 (following)
nickjillings@1318 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nickjillings@1318 2563 });
nickjillings@1318 2564
nickjillings@1318 2565 // Support: IE<8
nickjillings@1318 2566 // Prevent attribute/property "interpolation"
nickjillings@1318 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nickjillings@1318 2568 if ( !assert(function( div ) {
nickjillings@1318 2569 div.innerHTML = "<a href='#'></a>";
nickjillings@1318 2570 return div.firstChild.getAttribute("href") === "#" ;
nickjillings@1318 2571 }) ) {
nickjillings@1318 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nickjillings@1318 2573 if ( !isXML ) {
nickjillings@1318 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nickjillings@1318 2575 }
nickjillings@1318 2576 });
nickjillings@1318 2577 }
nickjillings@1318 2578
nickjillings@1318 2579 // Support: IE<9
nickjillings@1318 2580 // Use defaultValue in place of getAttribute("value")
nickjillings@1318 2581 if ( !support.attributes || !assert(function( div ) {
nickjillings@1318 2582 div.innerHTML = "<input/>";
nickjillings@1318 2583 div.firstChild.setAttribute( "value", "" );
nickjillings@1318 2584 return div.firstChild.getAttribute( "value" ) === "";
nickjillings@1318 2585 }) ) {
nickjillings@1318 2586 addHandle( "value", function( elem, name, isXML ) {
nickjillings@1318 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nickjillings@1318 2588 return elem.defaultValue;
nickjillings@1318 2589 }
nickjillings@1318 2590 });
nickjillings@1318 2591 }
nickjillings@1318 2592
nickjillings@1318 2593 // Support: IE<9
nickjillings@1318 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nickjillings@1318 2595 if ( !assert(function( div ) {
nickjillings@1318 2596 return div.getAttribute("disabled") == null;
nickjillings@1318 2597 }) ) {
nickjillings@1318 2598 addHandle( booleans, function( elem, name, isXML ) {
nickjillings@1318 2599 var val;
nickjillings@1318 2600 if ( !isXML ) {
nickjillings@1318 2601 return elem[ name ] === true ? name.toLowerCase() :
nickjillings@1318 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nickjillings@1318 2603 val.value :
nickjillings@1318 2604 null;
nickjillings@1318 2605 }
nickjillings@1318 2606 });
nickjillings@1318 2607 }
nickjillings@1318 2608
nickjillings@1318 2609 return Sizzle;
nickjillings@1318 2610
nickjillings@1318 2611 })( window );
nickjillings@1318 2612
nickjillings@1318 2613
nickjillings@1318 2614
nickjillings@1318 2615 jQuery.find = Sizzle;
nickjillings@1318 2616 jQuery.expr = Sizzle.selectors;
nickjillings@1318 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nickjillings@1318 2618 jQuery.unique = Sizzle.uniqueSort;
nickjillings@1318 2619 jQuery.text = Sizzle.getText;
nickjillings@1318 2620 jQuery.isXMLDoc = Sizzle.isXML;
nickjillings@1318 2621 jQuery.contains = Sizzle.contains;
nickjillings@1318 2622
nickjillings@1318 2623
nickjillings@1318 2624
nickjillings@1318 2625 var rneedsContext = jQuery.expr.match.needsContext;
nickjillings@1318 2626
nickjillings@1318 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nickjillings@1318 2628
nickjillings@1318 2629
nickjillings@1318 2630
nickjillings@1318 2631 var risSimple = /^.[^:#\[\.,]*$/;
nickjillings@1318 2632
nickjillings@1318 2633 // Implement the identical functionality for filter and not
nickjillings@1318 2634 function winnow( elements, qualifier, not ) {
nickjillings@1318 2635 if ( jQuery.isFunction( qualifier ) ) {
nickjillings@1318 2636 return jQuery.grep( elements, function( elem, i ) {
nickjillings@1318 2637 /* jshint -W018 */
nickjillings@1318 2638 return !!qualifier.call( elem, i, elem ) !== not;
nickjillings@1318 2639 });
nickjillings@1318 2640
nickjillings@1318 2641 }
nickjillings@1318 2642
nickjillings@1318 2643 if ( qualifier.nodeType ) {
nickjillings@1318 2644 return jQuery.grep( elements, function( elem ) {
nickjillings@1318 2645 return ( elem === qualifier ) !== not;
nickjillings@1318 2646 });
nickjillings@1318 2647
nickjillings@1318 2648 }
nickjillings@1318 2649
nickjillings@1318 2650 if ( typeof qualifier === "string" ) {
nickjillings@1318 2651 if ( risSimple.test( qualifier ) ) {
nickjillings@1318 2652 return jQuery.filter( qualifier, elements, not );
nickjillings@1318 2653 }
nickjillings@1318 2654
nickjillings@1318 2655 qualifier = jQuery.filter( qualifier, elements );
nickjillings@1318 2656 }
nickjillings@1318 2657
nickjillings@1318 2658 return jQuery.grep( elements, function( elem ) {
nickjillings@1318 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nickjillings@1318 2660 });
nickjillings@1318 2661 }
nickjillings@1318 2662
nickjillings@1318 2663 jQuery.filter = function( expr, elems, not ) {
nickjillings@1318 2664 var elem = elems[ 0 ];
nickjillings@1318 2665
nickjillings@1318 2666 if ( not ) {
nickjillings@1318 2667 expr = ":not(" + expr + ")";
nickjillings@1318 2668 }
nickjillings@1318 2669
nickjillings@1318 2670 return elems.length === 1 && elem.nodeType === 1 ?
nickjillings@1318 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nickjillings@1318 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nickjillings@1318 2673 return elem.nodeType === 1;
nickjillings@1318 2674 }));
nickjillings@1318 2675 };
nickjillings@1318 2676
nickjillings@1318 2677 jQuery.fn.extend({
nickjillings@1318 2678 find: function( selector ) {
nickjillings@1318 2679 var i,
nickjillings@1318 2680 len = this.length,
nickjillings@1318 2681 ret = [],
nickjillings@1318 2682 self = this;
nickjillings@1318 2683
nickjillings@1318 2684 if ( typeof selector !== "string" ) {
nickjillings@1318 2685 return this.pushStack( jQuery( selector ).filter(function() {
nickjillings@1318 2686 for ( i = 0; i < len; i++ ) {
nickjillings@1318 2687 if ( jQuery.contains( self[ i ], this ) ) {
nickjillings@1318 2688 return true;
nickjillings@1318 2689 }
nickjillings@1318 2690 }
nickjillings@1318 2691 }) );
nickjillings@1318 2692 }
nickjillings@1318 2693
nickjillings@1318 2694 for ( i = 0; i < len; i++ ) {
nickjillings@1318 2695 jQuery.find( selector, self[ i ], ret );
nickjillings@1318 2696 }
nickjillings@1318 2697
nickjillings@1318 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nickjillings@1318 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nickjillings@1318 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nickjillings@1318 2701 return ret;
nickjillings@1318 2702 },
nickjillings@1318 2703 filter: function( selector ) {
nickjillings@1318 2704 return this.pushStack( winnow(this, selector || [], false) );
nickjillings@1318 2705 },
nickjillings@1318 2706 not: function( selector ) {
nickjillings@1318 2707 return this.pushStack( winnow(this, selector || [], true) );
nickjillings@1318 2708 },
nickjillings@1318 2709 is: function( selector ) {
nickjillings@1318 2710 return !!winnow(
nickjillings@1318 2711 this,
nickjillings@1318 2712
nickjillings@1318 2713 // If this is a positional/relative selector, check membership in the returned set
nickjillings@1318 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nickjillings@1318 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nickjillings@1318 2716 jQuery( selector ) :
nickjillings@1318 2717 selector || [],
nickjillings@1318 2718 false
nickjillings@1318 2719 ).length;
nickjillings@1318 2720 }
nickjillings@1318 2721 });
nickjillings@1318 2722
nickjillings@1318 2723
nickjillings@1318 2724 // Initialize a jQuery object
nickjillings@1318 2725
nickjillings@1318 2726
nickjillings@1318 2727 // A central reference to the root jQuery(document)
nickjillings@1318 2728 var rootjQuery,
nickjillings@1318 2729
nickjillings@1318 2730 // A simple way to check for HTML strings
nickjillings@1318 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nickjillings@1318 2732 // Strict HTML recognition (#11290: must start with <)
nickjillings@1318 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nickjillings@1318 2734
nickjillings@1318 2735 init = jQuery.fn.init = function( selector, context ) {
nickjillings@1318 2736 var match, elem;
nickjillings@1318 2737
nickjillings@1318 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nickjillings@1318 2739 if ( !selector ) {
nickjillings@1318 2740 return this;
nickjillings@1318 2741 }
nickjillings@1318 2742
nickjillings@1318 2743 // Handle HTML strings
nickjillings@1318 2744 if ( typeof selector === "string" ) {
nickjillings@1318 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nickjillings@1318 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nickjillings@1318 2747 match = [ null, selector, null ];
nickjillings@1318 2748
nickjillings@1318 2749 } else {
nickjillings@1318 2750 match = rquickExpr.exec( selector );
nickjillings@1318 2751 }
nickjillings@1318 2752
nickjillings@1318 2753 // Match html or make sure no context is specified for #id
nickjillings@1318 2754 if ( match && (match[1] || !context) ) {
nickjillings@1318 2755
nickjillings@1318 2756 // HANDLE: $(html) -> $(array)
nickjillings@1318 2757 if ( match[1] ) {
nickjillings@1318 2758 context = context instanceof jQuery ? context[0] : context;
nickjillings@1318 2759
nickjillings@1318 2760 // Option to run scripts is true for back-compat
nickjillings@1318 2761 // Intentionally let the error be thrown if parseHTML is not present
nickjillings@1318 2762 jQuery.merge( this, jQuery.parseHTML(
nickjillings@1318 2763 match[1],
nickjillings@1318 2764 context && context.nodeType ? context.ownerDocument || context : document,
nickjillings@1318 2765 true
nickjillings@1318 2766 ) );
nickjillings@1318 2767
nickjillings@1318 2768 // HANDLE: $(html, props)
nickjillings@1318 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nickjillings@1318 2770 for ( match in context ) {
nickjillings@1318 2771 // Properties of context are called as methods if possible
nickjillings@1318 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nickjillings@1318 2773 this[ match ]( context[ match ] );
nickjillings@1318 2774
nickjillings@1318 2775 // ...and otherwise set as attributes
nickjillings@1318 2776 } else {
nickjillings@1318 2777 this.attr( match, context[ match ] );
nickjillings@1318 2778 }
nickjillings@1318 2779 }
nickjillings@1318 2780 }
nickjillings@1318 2781
nickjillings@1318 2782 return this;
nickjillings@1318 2783
nickjillings@1318 2784 // HANDLE: $(#id)
nickjillings@1318 2785 } else {
nickjillings@1318 2786 elem = document.getElementById( match[2] );
nickjillings@1318 2787
nickjillings@1318 2788 // Support: Blackberry 4.6
nickjillings@1318 2789 // gEBID returns nodes no longer in the document (#6963)
nickjillings@1318 2790 if ( elem && elem.parentNode ) {
nickjillings@1318 2791 // Inject the element directly into the jQuery object
nickjillings@1318 2792 this.length = 1;
nickjillings@1318 2793 this[0] = elem;
nickjillings@1318 2794 }
nickjillings@1318 2795
nickjillings@1318 2796 this.context = document;
nickjillings@1318 2797 this.selector = selector;
nickjillings@1318 2798 return this;
nickjillings@1318 2799 }
nickjillings@1318 2800
nickjillings@1318 2801 // HANDLE: $(expr, $(...))
nickjillings@1318 2802 } else if ( !context || context.jquery ) {
nickjillings@1318 2803 return ( context || rootjQuery ).find( selector );
nickjillings@1318 2804
nickjillings@1318 2805 // HANDLE: $(expr, context)
nickjillings@1318 2806 // (which is just equivalent to: $(context).find(expr)
nickjillings@1318 2807 } else {
nickjillings@1318 2808 return this.constructor( context ).find( selector );
nickjillings@1318 2809 }
nickjillings@1318 2810
nickjillings@1318 2811 // HANDLE: $(DOMElement)
nickjillings@1318 2812 } else if ( selector.nodeType ) {
nickjillings@1318 2813 this.context = this[0] = selector;
nickjillings@1318 2814 this.length = 1;
nickjillings@1318 2815 return this;
nickjillings@1318 2816
nickjillings@1318 2817 // HANDLE: $(function)
nickjillings@1318 2818 // Shortcut for document ready
nickjillings@1318 2819 } else if ( jQuery.isFunction( selector ) ) {
nickjillings@1318 2820 return typeof rootjQuery.ready !== "undefined" ?
nickjillings@1318 2821 rootjQuery.ready( selector ) :
nickjillings@1318 2822 // Execute immediately if ready is not present
nickjillings@1318 2823 selector( jQuery );
nickjillings@1318 2824 }
nickjillings@1318 2825
nickjillings@1318 2826 if ( selector.selector !== undefined ) {
nickjillings@1318 2827 this.selector = selector.selector;
nickjillings@1318 2828 this.context = selector.context;
nickjillings@1318 2829 }
nickjillings@1318 2830
nickjillings@1318 2831 return jQuery.makeArray( selector, this );
nickjillings@1318 2832 };
nickjillings@1318 2833
nickjillings@1318 2834 // Give the init function the jQuery prototype for later instantiation
nickjillings@1318 2835 init.prototype = jQuery.fn;
nickjillings@1318 2836
nickjillings@1318 2837 // Initialize central reference
nickjillings@1318 2838 rootjQuery = jQuery( document );
nickjillings@1318 2839
nickjillings@1318 2840
nickjillings@1318 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nickjillings@1318 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nickjillings@1318 2843 guaranteedUnique = {
nickjillings@1318 2844 children: true,
nickjillings@1318 2845 contents: true,
nickjillings@1318 2846 next: true,
nickjillings@1318 2847 prev: true
nickjillings@1318 2848 };
nickjillings@1318 2849
nickjillings@1318 2850 jQuery.extend({
nickjillings@1318 2851 dir: function( elem, dir, until ) {
nickjillings@1318 2852 var matched = [],
nickjillings@1318 2853 truncate = until !== undefined;
nickjillings@1318 2854
nickjillings@1318 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nickjillings@1318 2856 if ( elem.nodeType === 1 ) {
nickjillings@1318 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nickjillings@1318 2858 break;
nickjillings@1318 2859 }
nickjillings@1318 2860 matched.push( elem );
nickjillings@1318 2861 }
nickjillings@1318 2862 }
nickjillings@1318 2863 return matched;
nickjillings@1318 2864 },
nickjillings@1318 2865
nickjillings@1318 2866 sibling: function( n, elem ) {
nickjillings@1318 2867 var matched = [];
nickjillings@1318 2868
nickjillings@1318 2869 for ( ; n; n = n.nextSibling ) {
nickjillings@1318 2870 if ( n.nodeType === 1 && n !== elem ) {
nickjillings@1318 2871 matched.push( n );
nickjillings@1318 2872 }
nickjillings@1318 2873 }
nickjillings@1318 2874
nickjillings@1318 2875 return matched;
nickjillings@1318 2876 }
nickjillings@1318 2877 });
nickjillings@1318 2878
nickjillings@1318 2879 jQuery.fn.extend({
nickjillings@1318 2880 has: function( target ) {
nickjillings@1318 2881 var targets = jQuery( target, this ),
nickjillings@1318 2882 l = targets.length;
nickjillings@1318 2883
nickjillings@1318 2884 return this.filter(function() {
nickjillings@1318 2885 var i = 0;
nickjillings@1318 2886 for ( ; i < l; i++ ) {
nickjillings@1318 2887 if ( jQuery.contains( this, targets[i] ) ) {
nickjillings@1318 2888 return true;
nickjillings@1318 2889 }
nickjillings@1318 2890 }
nickjillings@1318 2891 });
nickjillings@1318 2892 },
nickjillings@1318 2893
nickjillings@1318 2894 closest: function( selectors, context ) {
nickjillings@1318 2895 var cur,
nickjillings@1318 2896 i = 0,
nickjillings@1318 2897 l = this.length,
nickjillings@1318 2898 matched = [],
nickjillings@1318 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nickjillings@1318 2900 jQuery( selectors, context || this.context ) :
nickjillings@1318 2901 0;
nickjillings@1318 2902
nickjillings@1318 2903 for ( ; i < l; i++ ) {
nickjillings@1318 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nickjillings@1318 2905 // Always skip document fragments
nickjillings@1318 2906 if ( cur.nodeType < 11 && (pos ?
nickjillings@1318 2907 pos.index(cur) > -1 :
nickjillings@1318 2908
nickjillings@1318 2909 // Don't pass non-elements to Sizzle
nickjillings@1318 2910 cur.nodeType === 1 &&
nickjillings@1318 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nickjillings@1318 2912
nickjillings@1318 2913 matched.push( cur );
nickjillings@1318 2914 break;
nickjillings@1318 2915 }
nickjillings@1318 2916 }
nickjillings@1318 2917 }
nickjillings@1318 2918
nickjillings@1318 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nickjillings@1318 2920 },
nickjillings@1318 2921
nickjillings@1318 2922 // Determine the position of an element within the set
nickjillings@1318 2923 index: function( elem ) {
nickjillings@1318 2924
nickjillings@1318 2925 // No argument, return index in parent
nickjillings@1318 2926 if ( !elem ) {
nickjillings@1318 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nickjillings@1318 2928 }
nickjillings@1318 2929
nickjillings@1318 2930 // Index in selector
nickjillings@1318 2931 if ( typeof elem === "string" ) {
nickjillings@1318 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nickjillings@1318 2933 }
nickjillings@1318 2934
nickjillings@1318 2935 // Locate the position of the desired element
nickjillings@1318 2936 return indexOf.call( this,
nickjillings@1318 2937
nickjillings@1318 2938 // If it receives a jQuery object, the first element is used
nickjillings@1318 2939 elem.jquery ? elem[ 0 ] : elem
nickjillings@1318 2940 );
nickjillings@1318 2941 },
nickjillings@1318 2942
nickjillings@1318 2943 add: function( selector, context ) {
nickjillings@1318 2944 return this.pushStack(
nickjillings@1318 2945 jQuery.unique(
nickjillings@1318 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nickjillings@1318 2947 )
nickjillings@1318 2948 );
nickjillings@1318 2949 },
nickjillings@1318 2950
nickjillings@1318 2951 addBack: function( selector ) {
nickjillings@1318 2952 return this.add( selector == null ?
nickjillings@1318 2953 this.prevObject : this.prevObject.filter(selector)
nickjillings@1318 2954 );
nickjillings@1318 2955 }
nickjillings@1318 2956 });
nickjillings@1318 2957
nickjillings@1318 2958 function sibling( cur, dir ) {
nickjillings@1318 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nickjillings@1318 2960 return cur;
nickjillings@1318 2961 }
nickjillings@1318 2962
nickjillings@1318 2963 jQuery.each({
nickjillings@1318 2964 parent: function( elem ) {
nickjillings@1318 2965 var parent = elem.parentNode;
nickjillings@1318 2966 return parent && parent.nodeType !== 11 ? parent : null;
nickjillings@1318 2967 },
nickjillings@1318 2968 parents: function( elem ) {
nickjillings@1318 2969 return jQuery.dir( elem, "parentNode" );
nickjillings@1318 2970 },
nickjillings@1318 2971 parentsUntil: function( elem, i, until ) {
nickjillings@1318 2972 return jQuery.dir( elem, "parentNode", until );
nickjillings@1318 2973 },
nickjillings@1318 2974 next: function( elem ) {
nickjillings@1318 2975 return sibling( elem, "nextSibling" );
nickjillings@1318 2976 },
nickjillings@1318 2977 prev: function( elem ) {
nickjillings@1318 2978 return sibling( elem, "previousSibling" );
nickjillings@1318 2979 },
nickjillings@1318 2980 nextAll: function( elem ) {
nickjillings@1318 2981 return jQuery.dir( elem, "nextSibling" );
nickjillings@1318 2982 },
nickjillings@1318 2983 prevAll: function( elem ) {
nickjillings@1318 2984 return jQuery.dir( elem, "previousSibling" );
nickjillings@1318 2985 },
nickjillings@1318 2986 nextUntil: function( elem, i, until ) {
nickjillings@1318 2987 return jQuery.dir( elem, "nextSibling", until );
nickjillings@1318 2988 },
nickjillings@1318 2989 prevUntil: function( elem, i, until ) {
nickjillings@1318 2990 return jQuery.dir( elem, "previousSibling", until );
nickjillings@1318 2991 },
nickjillings@1318 2992 siblings: function( elem ) {
nickjillings@1318 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nickjillings@1318 2994 },
nickjillings@1318 2995 children: function( elem ) {
nickjillings@1318 2996 return jQuery.sibling( elem.firstChild );
nickjillings@1318 2997 },
nickjillings@1318 2998 contents: function( elem ) {
nickjillings@1318 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nickjillings@1318 3000 }
nickjillings@1318 3001 }, function( name, fn ) {
nickjillings@1318 3002 jQuery.fn[ name ] = function( until, selector ) {
nickjillings@1318 3003 var matched = jQuery.map( this, fn, until );
nickjillings@1318 3004
nickjillings@1318 3005 if ( name.slice( -5 ) !== "Until" ) {
nickjillings@1318 3006 selector = until;
nickjillings@1318 3007 }
nickjillings@1318 3008
nickjillings@1318 3009 if ( selector && typeof selector === "string" ) {
nickjillings@1318 3010 matched = jQuery.filter( selector, matched );
nickjillings@1318 3011 }
nickjillings@1318 3012
nickjillings@1318 3013 if ( this.length > 1 ) {
nickjillings@1318 3014 // Remove duplicates
nickjillings@1318 3015 if ( !guaranteedUnique[ name ] ) {
nickjillings@1318 3016 jQuery.unique( matched );
nickjillings@1318 3017 }
nickjillings@1318 3018
nickjillings@1318 3019 // Reverse order for parents* and prev-derivatives
nickjillings@1318 3020 if ( rparentsprev.test( name ) ) {
nickjillings@1318 3021 matched.reverse();
nickjillings@1318 3022 }
nickjillings@1318 3023 }
nickjillings@1318 3024
nickjillings@1318 3025 return this.pushStack( matched );
nickjillings@1318 3026 };
nickjillings@1318 3027 });
nickjillings@1318 3028 var rnotwhite = (/\S+/g);
nickjillings@1318 3029
nickjillings@1318 3030
nickjillings@1318 3031
nickjillings@1318 3032 // String to Object options format cache
nickjillings@1318 3033 var optionsCache = {};
nickjillings@1318 3034
nickjillings@1318 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nickjillings@1318 3036 function createOptions( options ) {
nickjillings@1318 3037 var object = optionsCache[ options ] = {};
nickjillings@1318 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nickjillings@1318 3039 object[ flag ] = true;
nickjillings@1318 3040 });
nickjillings@1318 3041 return object;
nickjillings@1318 3042 }
nickjillings@1318 3043
nickjillings@1318 3044 /*
nickjillings@1318 3045 * Create a callback list using the following parameters:
nickjillings@1318 3046 *
nickjillings@1318 3047 * options: an optional list of space-separated options that will change how
nickjillings@1318 3048 * the callback list behaves or a more traditional option object
nickjillings@1318 3049 *
nickjillings@1318 3050 * By default a callback list will act like an event callback list and can be
nickjillings@1318 3051 * "fired" multiple times.
nickjillings@1318 3052 *
nickjillings@1318 3053 * Possible options:
nickjillings@1318 3054 *
nickjillings@1318 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nickjillings@1318 3056 *
nickjillings@1318 3057 * memory: will keep track of previous values and will call any callback added
nickjillings@1318 3058 * after the list has been fired right away with the latest "memorized"
nickjillings@1318 3059 * values (like a Deferred)
nickjillings@1318 3060 *
nickjillings@1318 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nickjillings@1318 3062 *
nickjillings@1318 3063 * stopOnFalse: interrupt callings when a callback returns false
nickjillings@1318 3064 *
nickjillings@1318 3065 */
nickjillings@1318 3066 jQuery.Callbacks = function( options ) {
nickjillings@1318 3067
nickjillings@1318 3068 // Convert options from String-formatted to Object-formatted if needed
nickjillings@1318 3069 // (we check in cache first)
nickjillings@1318 3070 options = typeof options === "string" ?
nickjillings@1318 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nickjillings@1318 3072 jQuery.extend( {}, options );
nickjillings@1318 3073
nickjillings@1318 3074 var // Last fire value (for non-forgettable lists)
nickjillings@1318 3075 memory,
nickjillings@1318 3076 // Flag to know if list was already fired
nickjillings@1318 3077 fired,
nickjillings@1318 3078 // Flag to know if list is currently firing
nickjillings@1318 3079 firing,
nickjillings@1318 3080 // First callback to fire (used internally by add and fireWith)
nickjillings@1318 3081 firingStart,
nickjillings@1318 3082 // End of the loop when firing
nickjillings@1318 3083 firingLength,
nickjillings@1318 3084 // Index of currently firing callback (modified by remove if needed)
nickjillings@1318 3085 firingIndex,
nickjillings@1318 3086 // Actual callback list
nickjillings@1318 3087 list = [],
nickjillings@1318 3088 // Stack of fire calls for repeatable lists
nickjillings@1318 3089 stack = !options.once && [],
nickjillings@1318 3090 // Fire callbacks
nickjillings@1318 3091 fire = function( data ) {
nickjillings@1318 3092 memory = options.memory && data;
nickjillings@1318 3093 fired = true;
nickjillings@1318 3094 firingIndex = firingStart || 0;
nickjillings@1318 3095 firingStart = 0;
nickjillings@1318 3096 firingLength = list.length;
nickjillings@1318 3097 firing = true;
nickjillings@1318 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nickjillings@1318 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nickjillings@1318 3100 memory = false; // To prevent further calls using add
nickjillings@1318 3101 break;
nickjillings@1318 3102 }
nickjillings@1318 3103 }
nickjillings@1318 3104 firing = false;
nickjillings@1318 3105 if ( list ) {
nickjillings@1318 3106 if ( stack ) {
nickjillings@1318 3107 if ( stack.length ) {
nickjillings@1318 3108 fire( stack.shift() );
nickjillings@1318 3109 }
nickjillings@1318 3110 } else if ( memory ) {
nickjillings@1318 3111 list = [];
nickjillings@1318 3112 } else {
nickjillings@1318 3113 self.disable();
nickjillings@1318 3114 }
nickjillings@1318 3115 }
nickjillings@1318 3116 },
nickjillings@1318 3117 // Actual Callbacks object
nickjillings@1318 3118 self = {
nickjillings@1318 3119 // Add a callback or a collection of callbacks to the list
nickjillings@1318 3120 add: function() {
nickjillings@1318 3121 if ( list ) {
nickjillings@1318 3122 // First, we save the current length
nickjillings@1318 3123 var start = list.length;
nickjillings@1318 3124 (function add( args ) {
nickjillings@1318 3125 jQuery.each( args, function( _, arg ) {
nickjillings@1318 3126 var type = jQuery.type( arg );
nickjillings@1318 3127 if ( type === "function" ) {
nickjillings@1318 3128 if ( !options.unique || !self.has( arg ) ) {
nickjillings@1318 3129 list.push( arg );
nickjillings@1318 3130 }
nickjillings@1318 3131 } else if ( arg && arg.length && type !== "string" ) {
nickjillings@1318 3132 // Inspect recursively
nickjillings@1318 3133 add( arg );
nickjillings@1318 3134 }
nickjillings@1318 3135 });
nickjillings@1318 3136 })( arguments );
nickjillings@1318 3137 // Do we need to add the callbacks to the
nickjillings@1318 3138 // current firing batch?
nickjillings@1318 3139 if ( firing ) {
nickjillings@1318 3140 firingLength = list.length;
nickjillings@1318 3141 // With memory, if we're not firing then
nickjillings@1318 3142 // we should call right away
nickjillings@1318 3143 } else if ( memory ) {
nickjillings@1318 3144 firingStart = start;
nickjillings@1318 3145 fire( memory );
nickjillings@1318 3146 }
nickjillings@1318 3147 }
nickjillings@1318 3148 return this;
nickjillings@1318 3149 },
nickjillings@1318 3150 // Remove a callback from the list
nickjillings@1318 3151 remove: function() {
nickjillings@1318 3152 if ( list ) {
nickjillings@1318 3153 jQuery.each( arguments, function( _, arg ) {
nickjillings@1318 3154 var index;
nickjillings@1318 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nickjillings@1318 3156 list.splice( index, 1 );
nickjillings@1318 3157 // Handle firing indexes
nickjillings@1318 3158 if ( firing ) {
nickjillings@1318 3159 if ( index <= firingLength ) {
nickjillings@1318 3160 firingLength--;
nickjillings@1318 3161 }
nickjillings@1318 3162 if ( index <= firingIndex ) {
nickjillings@1318 3163 firingIndex--;
nickjillings@1318 3164 }
nickjillings@1318 3165 }
nickjillings@1318 3166 }
nickjillings@1318 3167 });
nickjillings@1318 3168 }
nickjillings@1318 3169 return this;
nickjillings@1318 3170 },
nickjillings@1318 3171 // Check if a given callback is in the list.
nickjillings@1318 3172 // If no argument is given, return whether or not list has callbacks attached.
nickjillings@1318 3173 has: function( fn ) {
nickjillings@1318 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nickjillings@1318 3175 },
nickjillings@1318 3176 // Remove all callbacks from the list
nickjillings@1318 3177 empty: function() {
nickjillings@1318 3178 list = [];
nickjillings@1318 3179 firingLength = 0;
nickjillings@1318 3180 return this;
nickjillings@1318 3181 },
nickjillings@1318 3182 // Have the list do nothing anymore
nickjillings@1318 3183 disable: function() {
nickjillings@1318 3184 list = stack = memory = undefined;
nickjillings@1318 3185 return this;
nickjillings@1318 3186 },
nickjillings@1318 3187 // Is it disabled?
nickjillings@1318 3188 disabled: function() {
nickjillings@1318 3189 return !list;
nickjillings@1318 3190 },
nickjillings@1318 3191 // Lock the list in its current state
nickjillings@1318 3192 lock: function() {
nickjillings@1318 3193 stack = undefined;
nickjillings@1318 3194 if ( !memory ) {
nickjillings@1318 3195 self.disable();
nickjillings@1318 3196 }
nickjillings@1318 3197 return this;
nickjillings@1318 3198 },
nickjillings@1318 3199 // Is it locked?
nickjillings@1318 3200 locked: function() {
nickjillings@1318 3201 return !stack;
nickjillings@1318 3202 },
nickjillings@1318 3203 // Call all callbacks with the given context and arguments
nickjillings@1318 3204 fireWith: function( context, args ) {
nickjillings@1318 3205 if ( list && ( !fired || stack ) ) {
nickjillings@1318 3206 args = args || [];
nickjillings@1318 3207 args = [ context, args.slice ? args.slice() : args ];
nickjillings@1318 3208 if ( firing ) {
nickjillings@1318 3209 stack.push( args );
nickjillings@1318 3210 } else {
nickjillings@1318 3211 fire( args );
nickjillings@1318 3212 }
nickjillings@1318 3213 }
nickjillings@1318 3214 return this;
nickjillings@1318 3215 },
nickjillings@1318 3216 // Call all the callbacks with the given arguments
nickjillings@1318 3217 fire: function() {
nickjillings@1318 3218 self.fireWith( this, arguments );
nickjillings@1318 3219 return this;
nickjillings@1318 3220 },
nickjillings@1318 3221 // To know if the callbacks have already been called at least once
nickjillings@1318 3222 fired: function() {
nickjillings@1318 3223 return !!fired;
nickjillings@1318 3224 }
nickjillings@1318 3225 };
nickjillings@1318 3226
nickjillings@1318 3227 return self;
nickjillings@1318 3228 };
nickjillings@1318 3229
nickjillings@1318 3230
nickjillings@1318 3231 jQuery.extend({
nickjillings@1318 3232
nickjillings@1318 3233 Deferred: function( func ) {
nickjillings@1318 3234 var tuples = [
nickjillings@1318 3235 // action, add listener, listener list, final state
nickjillings@1318 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nickjillings@1318 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nickjillings@1318 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nickjillings@1318 3239 ],
nickjillings@1318 3240 state = "pending",
nickjillings@1318 3241 promise = {
nickjillings@1318 3242 state: function() {
nickjillings@1318 3243 return state;
nickjillings@1318 3244 },
nickjillings@1318 3245 always: function() {
nickjillings@1318 3246 deferred.done( arguments ).fail( arguments );
nickjillings@1318 3247 return this;
nickjillings@1318 3248 },
nickjillings@1318 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nickjillings@1318 3250 var fns = arguments;
nickjillings@1318 3251 return jQuery.Deferred(function( newDefer ) {
nickjillings@1318 3252 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1318 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nickjillings@1318 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nickjillings@1318 3255 deferred[ tuple[1] ](function() {
nickjillings@1318 3256 var returned = fn && fn.apply( this, arguments );
nickjillings@1318 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nickjillings@1318 3258 returned.promise()
nickjillings@1318 3259 .done( newDefer.resolve )
nickjillings@1318 3260 .fail( newDefer.reject )
nickjillings@1318 3261 .progress( newDefer.notify );
nickjillings@1318 3262 } else {
nickjillings@1318 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nickjillings@1318 3264 }
nickjillings@1318 3265 });
nickjillings@1318 3266 });
nickjillings@1318 3267 fns = null;
nickjillings@1318 3268 }).promise();
nickjillings@1318 3269 },
nickjillings@1318 3270 // Get a promise for this deferred
nickjillings@1318 3271 // If obj is provided, the promise aspect is added to the object
nickjillings@1318 3272 promise: function( obj ) {
nickjillings@1318 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nickjillings@1318 3274 }
nickjillings@1318 3275 },
nickjillings@1318 3276 deferred = {};
nickjillings@1318 3277
nickjillings@1318 3278 // Keep pipe for back-compat
nickjillings@1318 3279 promise.pipe = promise.then;
nickjillings@1318 3280
nickjillings@1318 3281 // Add list-specific methods
nickjillings@1318 3282 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1318 3283 var list = tuple[ 2 ],
nickjillings@1318 3284 stateString = tuple[ 3 ];
nickjillings@1318 3285
nickjillings@1318 3286 // promise[ done | fail | progress ] = list.add
nickjillings@1318 3287 promise[ tuple[1] ] = list.add;
nickjillings@1318 3288
nickjillings@1318 3289 // Handle state
nickjillings@1318 3290 if ( stateString ) {
nickjillings@1318 3291 list.add(function() {
nickjillings@1318 3292 // state = [ resolved | rejected ]
nickjillings@1318 3293 state = stateString;
nickjillings@1318 3294
nickjillings@1318 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nickjillings@1318 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nickjillings@1318 3297 }
nickjillings@1318 3298
nickjillings@1318 3299 // deferred[ resolve | reject | notify ]
nickjillings@1318 3300 deferred[ tuple[0] ] = function() {
nickjillings@1318 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nickjillings@1318 3302 return this;
nickjillings@1318 3303 };
nickjillings@1318 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nickjillings@1318 3305 });
nickjillings@1318 3306
nickjillings@1318 3307 // Make the deferred a promise
nickjillings@1318 3308 promise.promise( deferred );
nickjillings@1318 3309
nickjillings@1318 3310 // Call given func if any
nickjillings@1318 3311 if ( func ) {
nickjillings@1318 3312 func.call( deferred, deferred );
nickjillings@1318 3313 }
nickjillings@1318 3314
nickjillings@1318 3315 // All done!
nickjillings@1318 3316 return deferred;
nickjillings@1318 3317 },
nickjillings@1318 3318
nickjillings@1318 3319 // Deferred helper
nickjillings@1318 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nickjillings@1318 3321 var i = 0,
nickjillings@1318 3322 resolveValues = slice.call( arguments ),
nickjillings@1318 3323 length = resolveValues.length,
nickjillings@1318 3324
nickjillings@1318 3325 // the count of uncompleted subordinates
nickjillings@1318 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nickjillings@1318 3327
nickjillings@1318 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nickjillings@1318 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nickjillings@1318 3330
nickjillings@1318 3331 // Update function for both resolve and progress values
nickjillings@1318 3332 updateFunc = function( i, contexts, values ) {
nickjillings@1318 3333 return function( value ) {
nickjillings@1318 3334 contexts[ i ] = this;
nickjillings@1318 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nickjillings@1318 3336 if ( values === progressValues ) {
nickjillings@1318 3337 deferred.notifyWith( contexts, values );
nickjillings@1318 3338 } else if ( !( --remaining ) ) {
nickjillings@1318 3339 deferred.resolveWith( contexts, values );
nickjillings@1318 3340 }
nickjillings@1318 3341 };
nickjillings@1318 3342 },
nickjillings@1318 3343
nickjillings@1318 3344 progressValues, progressContexts, resolveContexts;
nickjillings@1318 3345
nickjillings@1318 3346 // Add listeners to Deferred subordinates; treat others as resolved
nickjillings@1318 3347 if ( length > 1 ) {
nickjillings@1318 3348 progressValues = new Array( length );
nickjillings@1318 3349 progressContexts = new Array( length );
nickjillings@1318 3350 resolveContexts = new Array( length );
nickjillings@1318 3351 for ( ; i < length; i++ ) {
nickjillings@1318 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nickjillings@1318 3353 resolveValues[ i ].promise()
nickjillings@1318 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nickjillings@1318 3355 .fail( deferred.reject )
nickjillings@1318 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nickjillings@1318 3357 } else {
nickjillings@1318 3358 --remaining;
nickjillings@1318 3359 }
nickjillings@1318 3360 }
nickjillings@1318 3361 }
nickjillings@1318 3362
nickjillings@1318 3363 // If we're not waiting on anything, resolve the master
nickjillings@1318 3364 if ( !remaining ) {
nickjillings@1318 3365 deferred.resolveWith( resolveContexts, resolveValues );
nickjillings@1318 3366 }
nickjillings@1318 3367
nickjillings@1318 3368 return deferred.promise();
nickjillings@1318 3369 }
nickjillings@1318 3370 });
nickjillings@1318 3371
nickjillings@1318 3372
nickjillings@1318 3373 // The deferred used on DOM ready
nickjillings@1318 3374 var readyList;
nickjillings@1318 3375
nickjillings@1318 3376 jQuery.fn.ready = function( fn ) {
nickjillings@1318 3377 // Add the callback
nickjillings@1318 3378 jQuery.ready.promise().done( fn );
nickjillings@1318 3379
nickjillings@1318 3380 return this;
nickjillings@1318 3381 };
nickjillings@1318 3382
nickjillings@1318 3383 jQuery.extend({
nickjillings@1318 3384 // Is the DOM ready to be used? Set to true once it occurs.
nickjillings@1318 3385 isReady: false,
nickjillings@1318 3386
nickjillings@1318 3387 // A counter to track how many items to wait for before
nickjillings@1318 3388 // the ready event fires. See #6781
nickjillings@1318 3389 readyWait: 1,
nickjillings@1318 3390
nickjillings@1318 3391 // Hold (or release) the ready event
nickjillings@1318 3392 holdReady: function( hold ) {
nickjillings@1318 3393 if ( hold ) {
nickjillings@1318 3394 jQuery.readyWait++;
nickjillings@1318 3395 } else {
nickjillings@1318 3396 jQuery.ready( true );
nickjillings@1318 3397 }
nickjillings@1318 3398 },
nickjillings@1318 3399
nickjillings@1318 3400 // Handle when the DOM is ready
nickjillings@1318 3401 ready: function( wait ) {
nickjillings@1318 3402
nickjillings@1318 3403 // Abort if there are pending holds or we're already ready
nickjillings@1318 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nickjillings@1318 3405 return;
nickjillings@1318 3406 }
nickjillings@1318 3407
nickjillings@1318 3408 // Remember that the DOM is ready
nickjillings@1318 3409 jQuery.isReady = true;
nickjillings@1318 3410
nickjillings@1318 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nickjillings@1318 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nickjillings@1318 3413 return;
nickjillings@1318 3414 }
nickjillings@1318 3415
nickjillings@1318 3416 // If there are functions bound, to execute
nickjillings@1318 3417 readyList.resolveWith( document, [ jQuery ] );
nickjillings@1318 3418
nickjillings@1318 3419 // Trigger any bound ready events
nickjillings@1318 3420 if ( jQuery.fn.triggerHandler ) {
nickjillings@1318 3421 jQuery( document ).triggerHandler( "ready" );
nickjillings@1318 3422 jQuery( document ).off( "ready" );
nickjillings@1318 3423 }
nickjillings@1318 3424 }
nickjillings@1318 3425 });
nickjillings@1318 3426
nickjillings@1318 3427 /**
nickjillings@1318 3428 * The ready event handler and self cleanup method
nickjillings@1318 3429 */
nickjillings@1318 3430 function completed() {
nickjillings@1318 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nickjillings@1318 3432 window.removeEventListener( "load", completed, false );
nickjillings@1318 3433 jQuery.ready();
nickjillings@1318 3434 }
nickjillings@1318 3435
nickjillings@1318 3436 jQuery.ready.promise = function( obj ) {
nickjillings@1318 3437 if ( !readyList ) {
nickjillings@1318 3438
nickjillings@1318 3439 readyList = jQuery.Deferred();
nickjillings@1318 3440
nickjillings@1318 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nickjillings@1318 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nickjillings@1318 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nickjillings@1318 3444 if ( document.readyState === "complete" ) {
nickjillings@1318 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nickjillings@1318 3446 setTimeout( jQuery.ready );
nickjillings@1318 3447
nickjillings@1318 3448 } else {
nickjillings@1318 3449
nickjillings@1318 3450 // Use the handy event callback
nickjillings@1318 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nickjillings@1318 3452
nickjillings@1318 3453 // A fallback to window.onload, that will always work
nickjillings@1318 3454 window.addEventListener( "load", completed, false );
nickjillings@1318 3455 }
nickjillings@1318 3456 }
nickjillings@1318 3457 return readyList.promise( obj );
nickjillings@1318 3458 };
nickjillings@1318 3459
nickjillings@1318 3460 // Kick off the DOM ready check even if the user does not
nickjillings@1318 3461 jQuery.ready.promise();
nickjillings@1318 3462
nickjillings@1318 3463
nickjillings@1318 3464
nickjillings@1318 3465
nickjillings@1318 3466 // Multifunctional method to get and set values of a collection
nickjillings@1318 3467 // The value/s can optionally be executed if it's a function
nickjillings@1318 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nickjillings@1318 3469 var i = 0,
nickjillings@1318 3470 len = elems.length,
nickjillings@1318 3471 bulk = key == null;
nickjillings@1318 3472
nickjillings@1318 3473 // Sets many values
nickjillings@1318 3474 if ( jQuery.type( key ) === "object" ) {
nickjillings@1318 3475 chainable = true;
nickjillings@1318 3476 for ( i in key ) {
nickjillings@1318 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nickjillings@1318 3478 }
nickjillings@1318 3479
nickjillings@1318 3480 // Sets one value
nickjillings@1318 3481 } else if ( value !== undefined ) {
nickjillings@1318 3482 chainable = true;
nickjillings@1318 3483
nickjillings@1318 3484 if ( !jQuery.isFunction( value ) ) {
nickjillings@1318 3485 raw = true;
nickjillings@1318 3486 }
nickjillings@1318 3487
nickjillings@1318 3488 if ( bulk ) {
nickjillings@1318 3489 // Bulk operations run against the entire set
nickjillings@1318 3490 if ( raw ) {
nickjillings@1318 3491 fn.call( elems, value );
nickjillings@1318 3492 fn = null;
nickjillings@1318 3493
nickjillings@1318 3494 // ...except when executing function values
nickjillings@1318 3495 } else {
nickjillings@1318 3496 bulk = fn;
nickjillings@1318 3497 fn = function( elem, key, value ) {
nickjillings@1318 3498 return bulk.call( jQuery( elem ), value );
nickjillings@1318 3499 };
nickjillings@1318 3500 }
nickjillings@1318 3501 }
nickjillings@1318 3502
nickjillings@1318 3503 if ( fn ) {
nickjillings@1318 3504 for ( ; i < len; i++ ) {
nickjillings@1318 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nickjillings@1318 3506 }
nickjillings@1318 3507 }
nickjillings@1318 3508 }
nickjillings@1318 3509
nickjillings@1318 3510 return chainable ?
nickjillings@1318 3511 elems :
nickjillings@1318 3512
nickjillings@1318 3513 // Gets
nickjillings@1318 3514 bulk ?
nickjillings@1318 3515 fn.call( elems ) :
nickjillings@1318 3516 len ? fn( elems[0], key ) : emptyGet;
nickjillings@1318 3517 };
nickjillings@1318 3518
nickjillings@1318 3519
nickjillings@1318 3520 /**
nickjillings@1318 3521 * Determines whether an object can have data
nickjillings@1318 3522 */
nickjillings@1318 3523 jQuery.acceptData = function( owner ) {
nickjillings@1318 3524 // Accepts only:
nickjillings@1318 3525 // - Node
nickjillings@1318 3526 // - Node.ELEMENT_NODE
nickjillings@1318 3527 // - Node.DOCUMENT_NODE
nickjillings@1318 3528 // - Object
nickjillings@1318 3529 // - Any
nickjillings@1318 3530 /* jshint -W018 */
nickjillings@1318 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nickjillings@1318 3532 };
nickjillings@1318 3533
nickjillings@1318 3534
nickjillings@1318 3535 function Data() {
nickjillings@1318 3536 // Support: Android<4,
nickjillings@1318 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nickjillings@1318 3538 // return new empty object instead with no [[set]] accessor
nickjillings@1318 3539 Object.defineProperty( this.cache = {}, 0, {
nickjillings@1318 3540 get: function() {
nickjillings@1318 3541 return {};
nickjillings@1318 3542 }
nickjillings@1318 3543 });
nickjillings@1318 3544
nickjillings@1318 3545 this.expando = jQuery.expando + Data.uid++;
nickjillings@1318 3546 }
nickjillings@1318 3547
nickjillings@1318 3548 Data.uid = 1;
nickjillings@1318 3549 Data.accepts = jQuery.acceptData;
nickjillings@1318 3550
nickjillings@1318 3551 Data.prototype = {
nickjillings@1318 3552 key: function( owner ) {
nickjillings@1318 3553 // We can accept data for non-element nodes in modern browsers,
nickjillings@1318 3554 // but we should not, see #8335.
nickjillings@1318 3555 // Always return the key for a frozen object.
nickjillings@1318 3556 if ( !Data.accepts( owner ) ) {
nickjillings@1318 3557 return 0;
nickjillings@1318 3558 }
nickjillings@1318 3559
nickjillings@1318 3560 var descriptor = {},
nickjillings@1318 3561 // Check if the owner object already has a cache key
nickjillings@1318 3562 unlock = owner[ this.expando ];
nickjillings@1318 3563
nickjillings@1318 3564 // If not, create one
nickjillings@1318 3565 if ( !unlock ) {
nickjillings@1318 3566 unlock = Data.uid++;
nickjillings@1318 3567
nickjillings@1318 3568 // Secure it in a non-enumerable, non-writable property
nickjillings@1318 3569 try {
nickjillings@1318 3570 descriptor[ this.expando ] = { value: unlock };
nickjillings@1318 3571 Object.defineProperties( owner, descriptor );
nickjillings@1318 3572
nickjillings@1318 3573 // Support: Android<4
nickjillings@1318 3574 // Fallback to a less secure definition
nickjillings@1318 3575 } catch ( e ) {
nickjillings@1318 3576 descriptor[ this.expando ] = unlock;
nickjillings@1318 3577 jQuery.extend( owner, descriptor );
nickjillings@1318 3578 }
nickjillings@1318 3579 }
nickjillings@1318 3580
nickjillings@1318 3581 // Ensure the cache object
nickjillings@1318 3582 if ( !this.cache[ unlock ] ) {
nickjillings@1318 3583 this.cache[ unlock ] = {};
nickjillings@1318 3584 }
nickjillings@1318 3585
nickjillings@1318 3586 return unlock;
nickjillings@1318 3587 },
nickjillings@1318 3588 set: function( owner, data, value ) {
nickjillings@1318 3589 var prop,
nickjillings@1318 3590 // There may be an unlock assigned to this node,
nickjillings@1318 3591 // if there is no entry for this "owner", create one inline
nickjillings@1318 3592 // and set the unlock as though an owner entry had always existed
nickjillings@1318 3593 unlock = this.key( owner ),
nickjillings@1318 3594 cache = this.cache[ unlock ];
nickjillings@1318 3595
nickjillings@1318 3596 // Handle: [ owner, key, value ] args
nickjillings@1318 3597 if ( typeof data === "string" ) {
nickjillings@1318 3598 cache[ data ] = value;
nickjillings@1318 3599
nickjillings@1318 3600 // Handle: [ owner, { properties } ] args
nickjillings@1318 3601 } else {
nickjillings@1318 3602 // Fresh assignments by object are shallow copied
nickjillings@1318 3603 if ( jQuery.isEmptyObject( cache ) ) {
nickjillings@1318 3604 jQuery.extend( this.cache[ unlock ], data );
nickjillings@1318 3605 // Otherwise, copy the properties one-by-one to the cache object
nickjillings@1318 3606 } else {
nickjillings@1318 3607 for ( prop in data ) {
nickjillings@1318 3608 cache[ prop ] = data[ prop ];
nickjillings@1318 3609 }
nickjillings@1318 3610 }
nickjillings@1318 3611 }
nickjillings@1318 3612 return cache;
nickjillings@1318 3613 },
nickjillings@1318 3614 get: function( owner, key ) {
nickjillings@1318 3615 // Either a valid cache is found, or will be created.
nickjillings@1318 3616 // New caches will be created and the unlock returned,
nickjillings@1318 3617 // allowing direct access to the newly created
nickjillings@1318 3618 // empty data object. A valid owner object must be provided.
nickjillings@1318 3619 var cache = this.cache[ this.key( owner ) ];
nickjillings@1318 3620
nickjillings@1318 3621 return key === undefined ?
nickjillings@1318 3622 cache : cache[ key ];
nickjillings@1318 3623 },
nickjillings@1318 3624 access: function( owner, key, value ) {
nickjillings@1318 3625 var stored;
nickjillings@1318 3626 // In cases where either:
nickjillings@1318 3627 //
nickjillings@1318 3628 // 1. No key was specified
nickjillings@1318 3629 // 2. A string key was specified, but no value provided
nickjillings@1318 3630 //
nickjillings@1318 3631 // Take the "read" path and allow the get method to determine
nickjillings@1318 3632 // which value to return, respectively either:
nickjillings@1318 3633 //
nickjillings@1318 3634 // 1. The entire cache object
nickjillings@1318 3635 // 2. The data stored at the key
nickjillings@1318 3636 //
nickjillings@1318 3637 if ( key === undefined ||
nickjillings@1318 3638 ((key && typeof key === "string") && value === undefined) ) {
nickjillings@1318 3639
nickjillings@1318 3640 stored = this.get( owner, key );
nickjillings@1318 3641
nickjillings@1318 3642 return stored !== undefined ?
nickjillings@1318 3643 stored : this.get( owner, jQuery.camelCase(key) );
nickjillings@1318 3644 }
nickjillings@1318 3645
nickjillings@1318 3646 // [*]When the key is not a string, or both a key and value
nickjillings@1318 3647 // are specified, set or extend (existing objects) with either:
nickjillings@1318 3648 //
nickjillings@1318 3649 // 1. An object of properties
nickjillings@1318 3650 // 2. A key and value
nickjillings@1318 3651 //
nickjillings@1318 3652 this.set( owner, key, value );
nickjillings@1318 3653
nickjillings@1318 3654 // Since the "set" path can have two possible entry points
nickjillings@1318 3655 // return the expected data based on which path was taken[*]
nickjillings@1318 3656 return value !== undefined ? value : key;
nickjillings@1318 3657 },
nickjillings@1318 3658 remove: function( owner, key ) {
nickjillings@1318 3659 var i, name, camel,
nickjillings@1318 3660 unlock = this.key( owner ),
nickjillings@1318 3661 cache = this.cache[ unlock ];
nickjillings@1318 3662
nickjillings@1318 3663 if ( key === undefined ) {
nickjillings@1318 3664 this.cache[ unlock ] = {};
nickjillings@1318 3665
nickjillings@1318 3666 } else {
nickjillings@1318 3667 // Support array or space separated string of keys
nickjillings@1318 3668 if ( jQuery.isArray( key ) ) {
nickjillings@1318 3669 // If "name" is an array of keys...
nickjillings@1318 3670 // When data is initially created, via ("key", "val") signature,
nickjillings@1318 3671 // keys will be converted to camelCase.
nickjillings@1318 3672 // Since there is no way to tell _how_ a key was added, remove
nickjillings@1318 3673 // both plain key and camelCase key. #12786
nickjillings@1318 3674 // This will only penalize the array argument path.
nickjillings@1318 3675 name = key.concat( key.map( jQuery.camelCase ) );
nickjillings@1318 3676 } else {
nickjillings@1318 3677 camel = jQuery.camelCase( key );
nickjillings@1318 3678 // Try the string as a key before any manipulation
nickjillings@1318 3679 if ( key in cache ) {
nickjillings@1318 3680 name = [ key, camel ];
nickjillings@1318 3681 } else {
nickjillings@1318 3682 // If a key with the spaces exists, use it.
nickjillings@1318 3683 // Otherwise, create an array by matching non-whitespace
nickjillings@1318 3684 name = camel;
nickjillings@1318 3685 name = name in cache ?
nickjillings@1318 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nickjillings@1318 3687 }
nickjillings@1318 3688 }
nickjillings@1318 3689
nickjillings@1318 3690 i = name.length;
nickjillings@1318 3691 while ( i-- ) {
nickjillings@1318 3692 delete cache[ name[ i ] ];
nickjillings@1318 3693 }
nickjillings@1318 3694 }
nickjillings@1318 3695 },
nickjillings@1318 3696 hasData: function( owner ) {
nickjillings@1318 3697 return !jQuery.isEmptyObject(
nickjillings@1318 3698 this.cache[ owner[ this.expando ] ] || {}
nickjillings@1318 3699 );
nickjillings@1318 3700 },
nickjillings@1318 3701 discard: function( owner ) {
nickjillings@1318 3702 if ( owner[ this.expando ] ) {
nickjillings@1318 3703 delete this.cache[ owner[ this.expando ] ];
nickjillings@1318 3704 }
nickjillings@1318 3705 }
nickjillings@1318 3706 };
nickjillings@1318 3707 var data_priv = new Data();
nickjillings@1318 3708
nickjillings@1318 3709 var data_user = new Data();
nickjillings@1318 3710
nickjillings@1318 3711
nickjillings@1318 3712
nickjillings@1318 3713 // Implementation Summary
nickjillings@1318 3714 //
nickjillings@1318 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nickjillings@1318 3716 // 2. Improve the module's maintainability by reducing the storage
nickjillings@1318 3717 // paths to a single mechanism.
nickjillings@1318 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nickjillings@1318 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nickjillings@1318 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nickjillings@1318 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nickjillings@1318 3722
nickjillings@1318 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nickjillings@1318 3724 rmultiDash = /([A-Z])/g;
nickjillings@1318 3725
nickjillings@1318 3726 function dataAttr( elem, key, data ) {
nickjillings@1318 3727 var name;
nickjillings@1318 3728
nickjillings@1318 3729 // If nothing was found internally, try to fetch any
nickjillings@1318 3730 // data from the HTML5 data-* attribute
nickjillings@1318 3731 if ( data === undefined && elem.nodeType === 1 ) {
nickjillings@1318 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nickjillings@1318 3733 data = elem.getAttribute( name );
nickjillings@1318 3734
nickjillings@1318 3735 if ( typeof data === "string" ) {
nickjillings@1318 3736 try {
nickjillings@1318 3737 data = data === "true" ? true :
nickjillings@1318 3738 data === "false" ? false :
nickjillings@1318 3739 data === "null" ? null :
nickjillings@1318 3740 // Only convert to a number if it doesn't change the string
nickjillings@1318 3741 +data + "" === data ? +data :
nickjillings@1318 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nickjillings@1318 3743 data;
nickjillings@1318 3744 } catch( e ) {}
nickjillings@1318 3745
nickjillings@1318 3746 // Make sure we set the data so it isn't changed later
nickjillings@1318 3747 data_user.set( elem, key, data );
nickjillings@1318 3748 } else {
nickjillings@1318 3749 data = undefined;
nickjillings@1318 3750 }
nickjillings@1318 3751 }
nickjillings@1318 3752 return data;
nickjillings@1318 3753 }
nickjillings@1318 3754
nickjillings@1318 3755 jQuery.extend({
nickjillings@1318 3756 hasData: function( elem ) {
nickjillings@1318 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nickjillings@1318 3758 },
nickjillings@1318 3759
nickjillings@1318 3760 data: function( elem, name, data ) {
nickjillings@1318 3761 return data_user.access( elem, name, data );
nickjillings@1318 3762 },
nickjillings@1318 3763
nickjillings@1318 3764 removeData: function( elem, name ) {
nickjillings@1318 3765 data_user.remove( elem, name );
nickjillings@1318 3766 },
nickjillings@1318 3767
nickjillings@1318 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nickjillings@1318 3769 // with direct calls to data_priv methods, these can be deprecated.
nickjillings@1318 3770 _data: function( elem, name, data ) {
nickjillings@1318 3771 return data_priv.access( elem, name, data );
nickjillings@1318 3772 },
nickjillings@1318 3773
nickjillings@1318 3774 _removeData: function( elem, name ) {
nickjillings@1318 3775 data_priv.remove( elem, name );
nickjillings@1318 3776 }
nickjillings@1318 3777 });
nickjillings@1318 3778
nickjillings@1318 3779 jQuery.fn.extend({
nickjillings@1318 3780 data: function( key, value ) {
nickjillings@1318 3781 var i, name, data,
nickjillings@1318 3782 elem = this[ 0 ],
nickjillings@1318 3783 attrs = elem && elem.attributes;
nickjillings@1318 3784
nickjillings@1318 3785 // Gets all values
nickjillings@1318 3786 if ( key === undefined ) {
nickjillings@1318 3787 if ( this.length ) {
nickjillings@1318 3788 data = data_user.get( elem );
nickjillings@1318 3789
nickjillings@1318 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nickjillings@1318 3791 i = attrs.length;
nickjillings@1318 3792 while ( i-- ) {
nickjillings@1318 3793
nickjillings@1318 3794 // Support: IE11+
nickjillings@1318 3795 // The attrs elements can be null (#14894)
nickjillings@1318 3796 if ( attrs[ i ] ) {
nickjillings@1318 3797 name = attrs[ i ].name;
nickjillings@1318 3798 if ( name.indexOf( "data-" ) === 0 ) {
nickjillings@1318 3799 name = jQuery.camelCase( name.slice(5) );
nickjillings@1318 3800 dataAttr( elem, name, data[ name ] );
nickjillings@1318 3801 }
nickjillings@1318 3802 }
nickjillings@1318 3803 }
nickjillings@1318 3804 data_priv.set( elem, "hasDataAttrs", true );
nickjillings@1318 3805 }
nickjillings@1318 3806 }
nickjillings@1318 3807
nickjillings@1318 3808 return data;
nickjillings@1318 3809 }
nickjillings@1318 3810
nickjillings@1318 3811 // Sets multiple values
nickjillings@1318 3812 if ( typeof key === "object" ) {
nickjillings@1318 3813 return this.each(function() {
nickjillings@1318 3814 data_user.set( this, key );
nickjillings@1318 3815 });
nickjillings@1318 3816 }
nickjillings@1318 3817
nickjillings@1318 3818 return access( this, function( value ) {
nickjillings@1318 3819 var data,
nickjillings@1318 3820 camelKey = jQuery.camelCase( key );
nickjillings@1318 3821
nickjillings@1318 3822 // The calling jQuery object (element matches) is not empty
nickjillings@1318 3823 // (and therefore has an element appears at this[ 0 ]) and the
nickjillings@1318 3824 // `value` parameter was not undefined. An empty jQuery object
nickjillings@1318 3825 // will result in `undefined` for elem = this[ 0 ] which will
nickjillings@1318 3826 // throw an exception if an attempt to read a data cache is made.
nickjillings@1318 3827 if ( elem && value === undefined ) {
nickjillings@1318 3828 // Attempt to get data from the cache
nickjillings@1318 3829 // with the key as-is
nickjillings@1318 3830 data = data_user.get( elem, key );
nickjillings@1318 3831 if ( data !== undefined ) {
nickjillings@1318 3832 return data;
nickjillings@1318 3833 }
nickjillings@1318 3834
nickjillings@1318 3835 // Attempt to get data from the cache
nickjillings@1318 3836 // with the key camelized
nickjillings@1318 3837 data = data_user.get( elem, camelKey );
nickjillings@1318 3838 if ( data !== undefined ) {
nickjillings@1318 3839 return data;
nickjillings@1318 3840 }
nickjillings@1318 3841
nickjillings@1318 3842 // Attempt to "discover" the data in
nickjillings@1318 3843 // HTML5 custom data-* attrs
nickjillings@1318 3844 data = dataAttr( elem, camelKey, undefined );
nickjillings@1318 3845 if ( data !== undefined ) {
nickjillings@1318 3846 return data;
nickjillings@1318 3847 }
nickjillings@1318 3848
nickjillings@1318 3849 // We tried really hard, but the data doesn't exist.
nickjillings@1318 3850 return;
nickjillings@1318 3851 }
nickjillings@1318 3852
nickjillings@1318 3853 // Set the data...
nickjillings@1318 3854 this.each(function() {
nickjillings@1318 3855 // First, attempt to store a copy or reference of any
nickjillings@1318 3856 // data that might've been store with a camelCased key.
nickjillings@1318 3857 var data = data_user.get( this, camelKey );
nickjillings@1318 3858
nickjillings@1318 3859 // For HTML5 data-* attribute interop, we have to
nickjillings@1318 3860 // store property names with dashes in a camelCase form.
nickjillings@1318 3861 // This might not apply to all properties...*
nickjillings@1318 3862 data_user.set( this, camelKey, value );
nickjillings@1318 3863
nickjillings@1318 3864 // *... In the case of properties that might _actually_
nickjillings@1318 3865 // have dashes, we need to also store a copy of that
nickjillings@1318 3866 // unchanged property.
nickjillings@1318 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nickjillings@1318 3868 data_user.set( this, key, value );
nickjillings@1318 3869 }
nickjillings@1318 3870 });
nickjillings@1318 3871 }, null, value, arguments.length > 1, null, true );
nickjillings@1318 3872 },
nickjillings@1318 3873
nickjillings@1318 3874 removeData: function( key ) {
nickjillings@1318 3875 return this.each(function() {
nickjillings@1318 3876 data_user.remove( this, key );
nickjillings@1318 3877 });
nickjillings@1318 3878 }
nickjillings@1318 3879 });
nickjillings@1318 3880
nickjillings@1318 3881
nickjillings@1318 3882 jQuery.extend({
nickjillings@1318 3883 queue: function( elem, type, data ) {
nickjillings@1318 3884 var queue;
nickjillings@1318 3885
nickjillings@1318 3886 if ( elem ) {
nickjillings@1318 3887 type = ( type || "fx" ) + "queue";
nickjillings@1318 3888 queue = data_priv.get( elem, type );
nickjillings@1318 3889
nickjillings@1318 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nickjillings@1318 3891 if ( data ) {
nickjillings@1318 3892 if ( !queue || jQuery.isArray( data ) ) {
nickjillings@1318 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nickjillings@1318 3894 } else {
nickjillings@1318 3895 queue.push( data );
nickjillings@1318 3896 }
nickjillings@1318 3897 }
nickjillings@1318 3898 return queue || [];
nickjillings@1318 3899 }
nickjillings@1318 3900 },
nickjillings@1318 3901
nickjillings@1318 3902 dequeue: function( elem, type ) {
nickjillings@1318 3903 type = type || "fx";
nickjillings@1318 3904
nickjillings@1318 3905 var queue = jQuery.queue( elem, type ),
nickjillings@1318 3906 startLength = queue.length,
nickjillings@1318 3907 fn = queue.shift(),
nickjillings@1318 3908 hooks = jQuery._queueHooks( elem, type ),
nickjillings@1318 3909 next = function() {
nickjillings@1318 3910 jQuery.dequeue( elem, type );
nickjillings@1318 3911 };
nickjillings@1318 3912
nickjillings@1318 3913 // If the fx queue is dequeued, always remove the progress sentinel
nickjillings@1318 3914 if ( fn === "inprogress" ) {
nickjillings@1318 3915 fn = queue.shift();
nickjillings@1318 3916 startLength--;
nickjillings@1318 3917 }
nickjillings@1318 3918
nickjillings@1318 3919 if ( fn ) {
nickjillings@1318 3920
nickjillings@1318 3921 // Add a progress sentinel to prevent the fx queue from being
nickjillings@1318 3922 // automatically dequeued
nickjillings@1318 3923 if ( type === "fx" ) {
nickjillings@1318 3924 queue.unshift( "inprogress" );
nickjillings@1318 3925 }
nickjillings@1318 3926
nickjillings@1318 3927 // Clear up the last queue stop function
nickjillings@1318 3928 delete hooks.stop;
nickjillings@1318 3929 fn.call( elem, next, hooks );
nickjillings@1318 3930 }
nickjillings@1318 3931
nickjillings@1318 3932 if ( !startLength && hooks ) {
nickjillings@1318 3933 hooks.empty.fire();
nickjillings@1318 3934 }
nickjillings@1318 3935 },
nickjillings@1318 3936
nickjillings@1318 3937 // Not public - generate a queueHooks object, or return the current one
nickjillings@1318 3938 _queueHooks: function( elem, type ) {
nickjillings@1318 3939 var key = type + "queueHooks";
nickjillings@1318 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nickjillings@1318 3941 empty: jQuery.Callbacks("once memory").add(function() {
nickjillings@1318 3942 data_priv.remove( elem, [ type + "queue", key ] );
nickjillings@1318 3943 })
nickjillings@1318 3944 });
nickjillings@1318 3945 }
nickjillings@1318 3946 });
nickjillings@1318 3947
nickjillings@1318 3948 jQuery.fn.extend({
nickjillings@1318 3949 queue: function( type, data ) {
nickjillings@1318 3950 var setter = 2;
nickjillings@1318 3951
nickjillings@1318 3952 if ( typeof type !== "string" ) {
nickjillings@1318 3953 data = type;
nickjillings@1318 3954 type = "fx";
nickjillings@1318 3955 setter--;
nickjillings@1318 3956 }
nickjillings@1318 3957
nickjillings@1318 3958 if ( arguments.length < setter ) {
nickjillings@1318 3959 return jQuery.queue( this[0], type );
nickjillings@1318 3960 }
nickjillings@1318 3961
nickjillings@1318 3962 return data === undefined ?
nickjillings@1318 3963 this :
nickjillings@1318 3964 this.each(function() {
nickjillings@1318 3965 var queue = jQuery.queue( this, type, data );
nickjillings@1318 3966
nickjillings@1318 3967 // Ensure a hooks for this queue
nickjillings@1318 3968 jQuery._queueHooks( this, type );
nickjillings@1318 3969
nickjillings@1318 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nickjillings@1318 3971 jQuery.dequeue( this, type );
nickjillings@1318 3972 }
nickjillings@1318 3973 });
nickjillings@1318 3974 },
nickjillings@1318 3975 dequeue: function( type ) {
nickjillings@1318 3976 return this.each(function() {
nickjillings@1318 3977 jQuery.dequeue( this, type );
nickjillings@1318 3978 });
nickjillings@1318 3979 },
nickjillings@1318 3980 clearQueue: function( type ) {
nickjillings@1318 3981 return this.queue( type || "fx", [] );
nickjillings@1318 3982 },
nickjillings@1318 3983 // Get a promise resolved when queues of a certain type
nickjillings@1318 3984 // are emptied (fx is the type by default)
nickjillings@1318 3985 promise: function( type, obj ) {
nickjillings@1318 3986 var tmp,
nickjillings@1318 3987 count = 1,
nickjillings@1318 3988 defer = jQuery.Deferred(),
nickjillings@1318 3989 elements = this,
nickjillings@1318 3990 i = this.length,
nickjillings@1318 3991 resolve = function() {
nickjillings@1318 3992 if ( !( --count ) ) {
nickjillings@1318 3993 defer.resolveWith( elements, [ elements ] );
nickjillings@1318 3994 }
nickjillings@1318 3995 };
nickjillings@1318 3996
nickjillings@1318 3997 if ( typeof type !== "string" ) {
nickjillings@1318 3998 obj = type;
nickjillings@1318 3999 type = undefined;
nickjillings@1318 4000 }
nickjillings@1318 4001 type = type || "fx";
nickjillings@1318 4002
nickjillings@1318 4003 while ( i-- ) {
nickjillings@1318 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nickjillings@1318 4005 if ( tmp && tmp.empty ) {
nickjillings@1318 4006 count++;
nickjillings@1318 4007 tmp.empty.add( resolve );
nickjillings@1318 4008 }
nickjillings@1318 4009 }
nickjillings@1318 4010 resolve();
nickjillings@1318 4011 return defer.promise( obj );
nickjillings@1318 4012 }
nickjillings@1318 4013 });
nickjillings@1318 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nickjillings@1318 4015
nickjillings@1318 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nickjillings@1318 4017
nickjillings@1318 4018 var isHidden = function( elem, el ) {
nickjillings@1318 4019 // isHidden might be called from jQuery#filter function;
nickjillings@1318 4020 // in that case, element will be second argument
nickjillings@1318 4021 elem = el || elem;
nickjillings@1318 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nickjillings@1318 4023 };
nickjillings@1318 4024
nickjillings@1318 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nickjillings@1318 4026
nickjillings@1318 4027
nickjillings@1318 4028
nickjillings@1318 4029 (function() {
nickjillings@1318 4030 var fragment = document.createDocumentFragment(),
nickjillings@1318 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nickjillings@1318 4032 input = document.createElement( "input" );
nickjillings@1318 4033
nickjillings@1318 4034 // Support: Safari<=5.1
nickjillings@1318 4035 // Check state lost if the name is set (#11217)
nickjillings@1318 4036 // Support: Windows Web Apps (WWA)
nickjillings@1318 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nickjillings@1318 4038 input.setAttribute( "type", "radio" );
nickjillings@1318 4039 input.setAttribute( "checked", "checked" );
nickjillings@1318 4040 input.setAttribute( "name", "t" );
nickjillings@1318 4041
nickjillings@1318 4042 div.appendChild( input );
nickjillings@1318 4043
nickjillings@1318 4044 // Support: Safari<=5.1, Android<4.2
nickjillings@1318 4045 // Older WebKit doesn't clone checked state correctly in fragments
nickjillings@1318 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nickjillings@1318 4047
nickjillings@1318 4048 // Support: IE<=11+
nickjillings@1318 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nickjillings@1318 4050 div.innerHTML = "<textarea>x</textarea>";
nickjillings@1318 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nickjillings@1318 4052 })();
nickjillings@1318 4053 var strundefined = typeof undefined;
nickjillings@1318 4054
nickjillings@1318 4055
nickjillings@1318 4056
nickjillings@1318 4057 support.focusinBubbles = "onfocusin" in window;
nickjillings@1318 4058
nickjillings@1318 4059
nickjillings@1318 4060 var
nickjillings@1318 4061 rkeyEvent = /^key/,
nickjillings@1318 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nickjillings@1318 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nickjillings@1318 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nickjillings@1318 4065
nickjillings@1318 4066 function returnTrue() {
nickjillings@1318 4067 return true;
nickjillings@1318 4068 }
nickjillings@1318 4069
nickjillings@1318 4070 function returnFalse() {
nickjillings@1318 4071 return false;
nickjillings@1318 4072 }
nickjillings@1318 4073
nickjillings@1318 4074 function safeActiveElement() {
nickjillings@1318 4075 try {
nickjillings@1318 4076 return document.activeElement;
nickjillings@1318 4077 } catch ( err ) { }
nickjillings@1318 4078 }
nickjillings@1318 4079
nickjillings@1318 4080 /*
nickjillings@1318 4081 * Helper functions for managing events -- not part of the public interface.
nickjillings@1318 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nickjillings@1318 4083 */
nickjillings@1318 4084 jQuery.event = {
nickjillings@1318 4085
nickjillings@1318 4086 global: {},
nickjillings@1318 4087
nickjillings@1318 4088 add: function( elem, types, handler, data, selector ) {
nickjillings@1318 4089
nickjillings@1318 4090 var handleObjIn, eventHandle, tmp,
nickjillings@1318 4091 events, t, handleObj,
nickjillings@1318 4092 special, handlers, type, namespaces, origType,
nickjillings@1318 4093 elemData = data_priv.get( elem );
nickjillings@1318 4094
nickjillings@1318 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nickjillings@1318 4096 if ( !elemData ) {
nickjillings@1318 4097 return;
nickjillings@1318 4098 }
nickjillings@1318 4099
nickjillings@1318 4100 // Caller can pass in an object of custom data in lieu of the handler
nickjillings@1318 4101 if ( handler.handler ) {
nickjillings@1318 4102 handleObjIn = handler;
nickjillings@1318 4103 handler = handleObjIn.handler;
nickjillings@1318 4104 selector = handleObjIn.selector;
nickjillings@1318 4105 }
nickjillings@1318 4106
nickjillings@1318 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nickjillings@1318 4108 if ( !handler.guid ) {
nickjillings@1318 4109 handler.guid = jQuery.guid++;
nickjillings@1318 4110 }
nickjillings@1318 4111
nickjillings@1318 4112 // Init the element's event structure and main handler, if this is the first
nickjillings@1318 4113 if ( !(events = elemData.events) ) {
nickjillings@1318 4114 events = elemData.events = {};
nickjillings@1318 4115 }
nickjillings@1318 4116 if ( !(eventHandle = elemData.handle) ) {
nickjillings@1318 4117 eventHandle = elemData.handle = function( e ) {
nickjillings@1318 4118 // Discard the second event of a jQuery.event.trigger() and
nickjillings@1318 4119 // when an event is called after a page has unloaded
nickjillings@1318 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nickjillings@1318 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nickjillings@1318 4122 };
nickjillings@1318 4123 }
nickjillings@1318 4124
nickjillings@1318 4125 // Handle multiple events separated by a space
nickjillings@1318 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1318 4127 t = types.length;
nickjillings@1318 4128 while ( t-- ) {
nickjillings@1318 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1318 4130 type = origType = tmp[1];
nickjillings@1318 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1318 4132
nickjillings@1318 4133 // There *must* be a type, no attaching namespace-only handlers
nickjillings@1318 4134 if ( !type ) {
nickjillings@1318 4135 continue;
nickjillings@1318 4136 }
nickjillings@1318 4137
nickjillings@1318 4138 // If event changes its type, use the special event handlers for the changed type
nickjillings@1318 4139 special = jQuery.event.special[ type ] || {};
nickjillings@1318 4140
nickjillings@1318 4141 // If selector defined, determine special event api type, otherwise given type
nickjillings@1318 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1318 4143
nickjillings@1318 4144 // Update special based on newly reset type
nickjillings@1318 4145 special = jQuery.event.special[ type ] || {};
nickjillings@1318 4146
nickjillings@1318 4147 // handleObj is passed to all event handlers
nickjillings@1318 4148 handleObj = jQuery.extend({
nickjillings@1318 4149 type: type,
nickjillings@1318 4150 origType: origType,
nickjillings@1318 4151 data: data,
nickjillings@1318 4152 handler: handler,
nickjillings@1318 4153 guid: handler.guid,
nickjillings@1318 4154 selector: selector,
nickjillings@1318 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nickjillings@1318 4156 namespace: namespaces.join(".")
nickjillings@1318 4157 }, handleObjIn );
nickjillings@1318 4158
nickjillings@1318 4159 // Init the event handler queue if we're the first
nickjillings@1318 4160 if ( !(handlers = events[ type ]) ) {
nickjillings@1318 4161 handlers = events[ type ] = [];
nickjillings@1318 4162 handlers.delegateCount = 0;
nickjillings@1318 4163
nickjillings@1318 4164 // Only use addEventListener if the special events handler returns false
nickjillings@1318 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nickjillings@1318 4166 if ( elem.addEventListener ) {
nickjillings@1318 4167 elem.addEventListener( type, eventHandle, false );
nickjillings@1318 4168 }
nickjillings@1318 4169 }
nickjillings@1318 4170 }
nickjillings@1318 4171
nickjillings@1318 4172 if ( special.add ) {
nickjillings@1318 4173 special.add.call( elem, handleObj );
nickjillings@1318 4174
nickjillings@1318 4175 if ( !handleObj.handler.guid ) {
nickjillings@1318 4176 handleObj.handler.guid = handler.guid;
nickjillings@1318 4177 }
nickjillings@1318 4178 }
nickjillings@1318 4179
nickjillings@1318 4180 // Add to the element's handler list, delegates in front
nickjillings@1318 4181 if ( selector ) {
nickjillings@1318 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nickjillings@1318 4183 } else {
nickjillings@1318 4184 handlers.push( handleObj );
nickjillings@1318 4185 }
nickjillings@1318 4186
nickjillings@1318 4187 // Keep track of which events have ever been used, for event optimization
nickjillings@1318 4188 jQuery.event.global[ type ] = true;
nickjillings@1318 4189 }
nickjillings@1318 4190
nickjillings@1318 4191 },
nickjillings@1318 4192
nickjillings@1318 4193 // Detach an event or set of events from an element
nickjillings@1318 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nickjillings@1318 4195
nickjillings@1318 4196 var j, origCount, tmp,
nickjillings@1318 4197 events, t, handleObj,
nickjillings@1318 4198 special, handlers, type, namespaces, origType,
nickjillings@1318 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nickjillings@1318 4200
nickjillings@1318 4201 if ( !elemData || !(events = elemData.events) ) {
nickjillings@1318 4202 return;
nickjillings@1318 4203 }
nickjillings@1318 4204
nickjillings@1318 4205 // Once for each type.namespace in types; type may be omitted
nickjillings@1318 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1318 4207 t = types.length;
nickjillings@1318 4208 while ( t-- ) {
nickjillings@1318 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1318 4210 type = origType = tmp[1];
nickjillings@1318 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1318 4212
nickjillings@1318 4213 // Unbind all events (on this namespace, if provided) for the element
nickjillings@1318 4214 if ( !type ) {
nickjillings@1318 4215 for ( type in events ) {
nickjillings@1318 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nickjillings@1318 4217 }
nickjillings@1318 4218 continue;
nickjillings@1318 4219 }
nickjillings@1318 4220
nickjillings@1318 4221 special = jQuery.event.special[ type ] || {};
nickjillings@1318 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1318 4223 handlers = events[ type ] || [];
nickjillings@1318 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nickjillings@1318 4225
nickjillings@1318 4226 // Remove matching events
nickjillings@1318 4227 origCount = j = handlers.length;
nickjillings@1318 4228 while ( j-- ) {
nickjillings@1318 4229 handleObj = handlers[ j ];
nickjillings@1318 4230
nickjillings@1318 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nickjillings@1318 4232 ( !handler || handler.guid === handleObj.guid ) &&
nickjillings@1318 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nickjillings@1318 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nickjillings@1318 4235 handlers.splice( j, 1 );
nickjillings@1318 4236
nickjillings@1318 4237 if ( handleObj.selector ) {
nickjillings@1318 4238 handlers.delegateCount--;
nickjillings@1318 4239 }
nickjillings@1318 4240 if ( special.remove ) {
nickjillings@1318 4241 special.remove.call( elem, handleObj );
nickjillings@1318 4242 }
nickjillings@1318 4243 }
nickjillings@1318 4244 }
nickjillings@1318 4245
nickjillings@1318 4246 // Remove generic event handler if we removed something and no more handlers exist
nickjillings@1318 4247 // (avoids potential for endless recursion during removal of special event handlers)
nickjillings@1318 4248 if ( origCount && !handlers.length ) {
nickjillings@1318 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nickjillings@1318 4250 jQuery.removeEvent( elem, type, elemData.handle );
nickjillings@1318 4251 }
nickjillings@1318 4252
nickjillings@1318 4253 delete events[ type ];
nickjillings@1318 4254 }
nickjillings@1318 4255 }
nickjillings@1318 4256
nickjillings@1318 4257 // Remove the expando if it's no longer used
nickjillings@1318 4258 if ( jQuery.isEmptyObject( events ) ) {
nickjillings@1318 4259 delete elemData.handle;
nickjillings@1318 4260 data_priv.remove( elem, "events" );
nickjillings@1318 4261 }
nickjillings@1318 4262 },
nickjillings@1318 4263
nickjillings@1318 4264 trigger: function( event, data, elem, onlyHandlers ) {
nickjillings@1318 4265
nickjillings@1318 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nickjillings@1318 4267 eventPath = [ elem || document ],
nickjillings@1318 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nickjillings@1318 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nickjillings@1318 4270
nickjillings@1318 4271 cur = tmp = elem = elem || document;
nickjillings@1318 4272
nickjillings@1318 4273 // Don't do events on text and comment nodes
nickjillings@1318 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nickjillings@1318 4275 return;
nickjillings@1318 4276 }
nickjillings@1318 4277
nickjillings@1318 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nickjillings@1318 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nickjillings@1318 4280 return;
nickjillings@1318 4281 }
nickjillings@1318 4282
nickjillings@1318 4283 if ( type.indexOf(".") >= 0 ) {
nickjillings@1318 4284 // Namespaced trigger; create a regexp to match event type in handle()
nickjillings@1318 4285 namespaces = type.split(".");
nickjillings@1318 4286 type = namespaces.shift();
nickjillings@1318 4287 namespaces.sort();
nickjillings@1318 4288 }
nickjillings@1318 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nickjillings@1318 4290
nickjillings@1318 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nickjillings@1318 4292 event = event[ jQuery.expando ] ?
nickjillings@1318 4293 event :
nickjillings@1318 4294 new jQuery.Event( type, typeof event === "object" && event );
nickjillings@1318 4295
nickjillings@1318 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nickjillings@1318 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nickjillings@1318 4298 event.namespace = namespaces.join(".");
nickjillings@1318 4299 event.namespace_re = event.namespace ?
nickjillings@1318 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nickjillings@1318 4301 null;
nickjillings@1318 4302
nickjillings@1318 4303 // Clean up the event in case it is being reused
nickjillings@1318 4304 event.result = undefined;
nickjillings@1318 4305 if ( !event.target ) {
nickjillings@1318 4306 event.target = elem;
nickjillings@1318 4307 }
nickjillings@1318 4308
nickjillings@1318 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nickjillings@1318 4310 data = data == null ?
nickjillings@1318 4311 [ event ] :
nickjillings@1318 4312 jQuery.makeArray( data, [ event ] );
nickjillings@1318 4313
nickjillings@1318 4314 // Allow special events to draw outside the lines
nickjillings@1318 4315 special = jQuery.event.special[ type ] || {};
nickjillings@1318 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nickjillings@1318 4317 return;
nickjillings@1318 4318 }
nickjillings@1318 4319
nickjillings@1318 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nickjillings@1318 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nickjillings@1318 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nickjillings@1318 4323
nickjillings@1318 4324 bubbleType = special.delegateType || type;
nickjillings@1318 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nickjillings@1318 4326 cur = cur.parentNode;
nickjillings@1318 4327 }
nickjillings@1318 4328 for ( ; cur; cur = cur.parentNode ) {
nickjillings@1318 4329 eventPath.push( cur );
nickjillings@1318 4330 tmp = cur;
nickjillings@1318 4331 }
nickjillings@1318 4332
nickjillings@1318 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nickjillings@1318 4334 if ( tmp === (elem.ownerDocument || document) ) {
nickjillings@1318 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nickjillings@1318 4336 }
nickjillings@1318 4337 }
nickjillings@1318 4338
nickjillings@1318 4339 // Fire handlers on the event path
nickjillings@1318 4340 i = 0;
nickjillings@1318 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nickjillings@1318 4342
nickjillings@1318 4343 event.type = i > 1 ?
nickjillings@1318 4344 bubbleType :
nickjillings@1318 4345 special.bindType || type;
nickjillings@1318 4346
nickjillings@1318 4347 // jQuery handler
nickjillings@1318 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nickjillings@1318 4349 if ( handle ) {
nickjillings@1318 4350 handle.apply( cur, data );
nickjillings@1318 4351 }
nickjillings@1318 4352
nickjillings@1318 4353 // Native handler
nickjillings@1318 4354 handle = ontype && cur[ ontype ];
nickjillings@1318 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nickjillings@1318 4356 event.result = handle.apply( cur, data );
nickjillings@1318 4357 if ( event.result === false ) {
nickjillings@1318 4358 event.preventDefault();
nickjillings@1318 4359 }
nickjillings@1318 4360 }
nickjillings@1318 4361 }
nickjillings@1318 4362 event.type = type;
nickjillings@1318 4363
nickjillings@1318 4364 // If nobody prevented the default action, do it now
nickjillings@1318 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nickjillings@1318 4366
nickjillings@1318 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nickjillings@1318 4368 jQuery.acceptData( elem ) ) {
nickjillings@1318 4369
nickjillings@1318 4370 // Call a native DOM method on the target with the same name name as the event.
nickjillings@1318 4371 // Don't do default actions on window, that's where global variables be (#6170)
nickjillings@1318 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nickjillings@1318 4373
nickjillings@1318 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nickjillings@1318 4375 tmp = elem[ ontype ];
nickjillings@1318 4376
nickjillings@1318 4377 if ( tmp ) {
nickjillings@1318 4378 elem[ ontype ] = null;
nickjillings@1318 4379 }
nickjillings@1318 4380
nickjillings@1318 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nickjillings@1318 4382 jQuery.event.triggered = type;
nickjillings@1318 4383 elem[ type ]();
nickjillings@1318 4384 jQuery.event.triggered = undefined;
nickjillings@1318 4385
nickjillings@1318 4386 if ( tmp ) {
nickjillings@1318 4387 elem[ ontype ] = tmp;
nickjillings@1318 4388 }
nickjillings@1318 4389 }
nickjillings@1318 4390 }
nickjillings@1318 4391 }
nickjillings@1318 4392
nickjillings@1318 4393 return event.result;
nickjillings@1318 4394 },
nickjillings@1318 4395
nickjillings@1318 4396 dispatch: function( event ) {
nickjillings@1318 4397
nickjillings@1318 4398 // Make a writable jQuery.Event from the native event object
nickjillings@1318 4399 event = jQuery.event.fix( event );
nickjillings@1318 4400
nickjillings@1318 4401 var i, j, ret, matched, handleObj,
nickjillings@1318 4402 handlerQueue = [],
nickjillings@1318 4403 args = slice.call( arguments ),
nickjillings@1318 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nickjillings@1318 4405 special = jQuery.event.special[ event.type ] || {};
nickjillings@1318 4406
nickjillings@1318 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nickjillings@1318 4408 args[0] = event;
nickjillings@1318 4409 event.delegateTarget = this;
nickjillings@1318 4410
nickjillings@1318 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nickjillings@1318 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nickjillings@1318 4413 return;
nickjillings@1318 4414 }
nickjillings@1318 4415
nickjillings@1318 4416 // Determine handlers
nickjillings@1318 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nickjillings@1318 4418
nickjillings@1318 4419 // Run delegates first; they may want to stop propagation beneath us
nickjillings@1318 4420 i = 0;
nickjillings@1318 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nickjillings@1318 4422 event.currentTarget = matched.elem;
nickjillings@1318 4423
nickjillings@1318 4424 j = 0;
nickjillings@1318 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nickjillings@1318 4426
nickjillings@1318 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nickjillings@1318 4428 // a subset or equal to those in the bound event (both can have no namespace).
nickjillings@1318 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nickjillings@1318 4430
nickjillings@1318 4431 event.handleObj = handleObj;
nickjillings@1318 4432 event.data = handleObj.data;
nickjillings@1318 4433
nickjillings@1318 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nickjillings@1318 4435 .apply( matched.elem, args );
nickjillings@1318 4436
nickjillings@1318 4437 if ( ret !== undefined ) {
nickjillings@1318 4438 if ( (event.result = ret) === false ) {
nickjillings@1318 4439 event.preventDefault();
nickjillings@1318 4440 event.stopPropagation();
nickjillings@1318 4441 }
nickjillings@1318 4442 }
nickjillings@1318 4443 }
nickjillings@1318 4444 }
nickjillings@1318 4445 }
nickjillings@1318 4446
nickjillings@1318 4447 // Call the postDispatch hook for the mapped type
nickjillings@1318 4448 if ( special.postDispatch ) {
nickjillings@1318 4449 special.postDispatch.call( this, event );
nickjillings@1318 4450 }
nickjillings@1318 4451
nickjillings@1318 4452 return event.result;
nickjillings@1318 4453 },
nickjillings@1318 4454
nickjillings@1318 4455 handlers: function( event, handlers ) {
nickjillings@1318 4456 var i, matches, sel, handleObj,
nickjillings@1318 4457 handlerQueue = [],
nickjillings@1318 4458 delegateCount = handlers.delegateCount,
nickjillings@1318 4459 cur = event.target;
nickjillings@1318 4460
nickjillings@1318 4461 // Find delegate handlers
nickjillings@1318 4462 // Black-hole SVG <use> instance trees (#13180)
nickjillings@1318 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nickjillings@1318 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nickjillings@1318 4465
nickjillings@1318 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nickjillings@1318 4467
nickjillings@1318 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nickjillings@1318 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nickjillings@1318 4470 matches = [];
nickjillings@1318 4471 for ( i = 0; i < delegateCount; i++ ) {
nickjillings@1318 4472 handleObj = handlers[ i ];
nickjillings@1318 4473
nickjillings@1318 4474 // Don't conflict with Object.prototype properties (#13203)
nickjillings@1318 4475 sel = handleObj.selector + " ";
nickjillings@1318 4476
nickjillings@1318 4477 if ( matches[ sel ] === undefined ) {
nickjillings@1318 4478 matches[ sel ] = handleObj.needsContext ?
nickjillings@1318 4479 jQuery( sel, this ).index( cur ) >= 0 :
nickjillings@1318 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nickjillings@1318 4481 }
nickjillings@1318 4482 if ( matches[ sel ] ) {
nickjillings@1318 4483 matches.push( handleObj );
nickjillings@1318 4484 }
nickjillings@1318 4485 }
nickjillings@1318 4486 if ( matches.length ) {
nickjillings@1318 4487 handlerQueue.push({ elem: cur, handlers: matches });
nickjillings@1318 4488 }
nickjillings@1318 4489 }
nickjillings@1318 4490 }
nickjillings@1318 4491 }
nickjillings@1318 4492
nickjillings@1318 4493 // Add the remaining (directly-bound) handlers
nickjillings@1318 4494 if ( delegateCount < handlers.length ) {
nickjillings@1318 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nickjillings@1318 4496 }
nickjillings@1318 4497
nickjillings@1318 4498 return handlerQueue;
nickjillings@1318 4499 },
nickjillings@1318 4500
nickjillings@1318 4501 // Includes some event props shared by KeyEvent and MouseEvent
nickjillings@1318 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nickjillings@1318 4503
nickjillings@1318 4504 fixHooks: {},
nickjillings@1318 4505
nickjillings@1318 4506 keyHooks: {
nickjillings@1318 4507 props: "char charCode key keyCode".split(" "),
nickjillings@1318 4508 filter: function( event, original ) {
nickjillings@1318 4509
nickjillings@1318 4510 // Add which for key events
nickjillings@1318 4511 if ( event.which == null ) {
nickjillings@1318 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nickjillings@1318 4513 }
nickjillings@1318 4514
nickjillings@1318 4515 return event;
nickjillings@1318 4516 }
nickjillings@1318 4517 },
nickjillings@1318 4518
nickjillings@1318 4519 mouseHooks: {
nickjillings@1318 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nickjillings@1318 4521 filter: function( event, original ) {
nickjillings@1318 4522 var eventDoc, doc, body,
nickjillings@1318 4523 button = original.button;
nickjillings@1318 4524
nickjillings@1318 4525 // Calculate pageX/Y if missing and clientX/Y available
nickjillings@1318 4526 if ( event.pageX == null && original.clientX != null ) {
nickjillings@1318 4527 eventDoc = event.target.ownerDocument || document;
nickjillings@1318 4528 doc = eventDoc.documentElement;
nickjillings@1318 4529 body = eventDoc.body;
nickjillings@1318 4530
nickjillings@1318 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nickjillings@1318 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nickjillings@1318 4533 }
nickjillings@1318 4534
nickjillings@1318 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nickjillings@1318 4536 // Note: button is not normalized, so don't use it
nickjillings@1318 4537 if ( !event.which && button !== undefined ) {
nickjillings@1318 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nickjillings@1318 4539 }
nickjillings@1318 4540
nickjillings@1318 4541 return event;
nickjillings@1318 4542 }
nickjillings@1318 4543 },
nickjillings@1318 4544
nickjillings@1318 4545 fix: function( event ) {
nickjillings@1318 4546 if ( event[ jQuery.expando ] ) {
nickjillings@1318 4547 return event;
nickjillings@1318 4548 }
nickjillings@1318 4549
nickjillings@1318 4550 // Create a writable copy of the event object and normalize some properties
nickjillings@1318 4551 var i, prop, copy,
nickjillings@1318 4552 type = event.type,
nickjillings@1318 4553 originalEvent = event,
nickjillings@1318 4554 fixHook = this.fixHooks[ type ];
nickjillings@1318 4555
nickjillings@1318 4556 if ( !fixHook ) {
nickjillings@1318 4557 this.fixHooks[ type ] = fixHook =
nickjillings@1318 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nickjillings@1318 4559 rkeyEvent.test( type ) ? this.keyHooks :
nickjillings@1318 4560 {};
nickjillings@1318 4561 }
nickjillings@1318 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nickjillings@1318 4563
nickjillings@1318 4564 event = new jQuery.Event( originalEvent );
nickjillings@1318 4565
nickjillings@1318 4566 i = copy.length;
nickjillings@1318 4567 while ( i-- ) {
nickjillings@1318 4568 prop = copy[ i ];
nickjillings@1318 4569 event[ prop ] = originalEvent[ prop ];
nickjillings@1318 4570 }
nickjillings@1318 4571
nickjillings@1318 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nickjillings@1318 4573 // All events should have a target; Cordova deviceready doesn't
nickjillings@1318 4574 if ( !event.target ) {
nickjillings@1318 4575 event.target = document;
nickjillings@1318 4576 }
nickjillings@1318 4577
nickjillings@1318 4578 // Support: Safari 6.0+, Chrome<28
nickjillings@1318 4579 // Target should not be a text node (#504, #13143)
nickjillings@1318 4580 if ( event.target.nodeType === 3 ) {
nickjillings@1318 4581 event.target = event.target.parentNode;
nickjillings@1318 4582 }
nickjillings@1318 4583
nickjillings@1318 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nickjillings@1318 4585 },
nickjillings@1318 4586
nickjillings@1318 4587 special: {
nickjillings@1318 4588 load: {
nickjillings@1318 4589 // Prevent triggered image.load events from bubbling to window.load
nickjillings@1318 4590 noBubble: true
nickjillings@1318 4591 },
nickjillings@1318 4592 focus: {
nickjillings@1318 4593 // Fire native event if possible so blur/focus sequence is correct
nickjillings@1318 4594 trigger: function() {
nickjillings@1318 4595 if ( this !== safeActiveElement() && this.focus ) {
nickjillings@1318 4596 this.focus();
nickjillings@1318 4597 return false;
nickjillings@1318 4598 }
nickjillings@1318 4599 },
nickjillings@1318 4600 delegateType: "focusin"
nickjillings@1318 4601 },
nickjillings@1318 4602 blur: {
nickjillings@1318 4603 trigger: function() {
nickjillings@1318 4604 if ( this === safeActiveElement() && this.blur ) {
nickjillings@1318 4605 this.blur();
nickjillings@1318 4606 return false;
nickjillings@1318 4607 }
nickjillings@1318 4608 },
nickjillings@1318 4609 delegateType: "focusout"
nickjillings@1318 4610 },
nickjillings@1318 4611 click: {
nickjillings@1318 4612 // For checkbox, fire native event so checked state will be right
nickjillings@1318 4613 trigger: function() {
nickjillings@1318 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nickjillings@1318 4615 this.click();
nickjillings@1318 4616 return false;
nickjillings@1318 4617 }
nickjillings@1318 4618 },
nickjillings@1318 4619
nickjillings@1318 4620 // For cross-browser consistency, don't fire native .click() on links
nickjillings@1318 4621 _default: function( event ) {
nickjillings@1318 4622 return jQuery.nodeName( event.target, "a" );
nickjillings@1318 4623 }
nickjillings@1318 4624 },
nickjillings@1318 4625
nickjillings@1318 4626 beforeunload: {
nickjillings@1318 4627 postDispatch: function( event ) {
nickjillings@1318 4628
nickjillings@1318 4629 // Support: Firefox 20+
nickjillings@1318 4630 // Firefox doesn't alert if the returnValue field is not set.
nickjillings@1318 4631 if ( event.result !== undefined && event.originalEvent ) {
nickjillings@1318 4632 event.originalEvent.returnValue = event.result;
nickjillings@1318 4633 }
nickjillings@1318 4634 }
nickjillings@1318 4635 }
nickjillings@1318 4636 },
nickjillings@1318 4637
nickjillings@1318 4638 simulate: function( type, elem, event, bubble ) {
nickjillings@1318 4639 // Piggyback on a donor event to simulate a different one.
nickjillings@1318 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nickjillings@1318 4641 // simulated event prevents default then we do the same on the donor.
nickjillings@1318 4642 var e = jQuery.extend(
nickjillings@1318 4643 new jQuery.Event(),
nickjillings@1318 4644 event,
nickjillings@1318 4645 {
nickjillings@1318 4646 type: type,
nickjillings@1318 4647 isSimulated: true,
nickjillings@1318 4648 originalEvent: {}
nickjillings@1318 4649 }
nickjillings@1318 4650 );
nickjillings@1318 4651 if ( bubble ) {
nickjillings@1318 4652 jQuery.event.trigger( e, null, elem );
nickjillings@1318 4653 } else {
nickjillings@1318 4654 jQuery.event.dispatch.call( elem, e );
nickjillings@1318 4655 }
nickjillings@1318 4656 if ( e.isDefaultPrevented() ) {
nickjillings@1318 4657 event.preventDefault();
nickjillings@1318 4658 }
nickjillings@1318 4659 }
nickjillings@1318 4660 };
nickjillings@1318 4661
nickjillings@1318 4662 jQuery.removeEvent = function( elem, type, handle ) {
nickjillings@1318 4663 if ( elem.removeEventListener ) {
nickjillings@1318 4664 elem.removeEventListener( type, handle, false );
nickjillings@1318 4665 }
nickjillings@1318 4666 };
nickjillings@1318 4667
nickjillings@1318 4668 jQuery.Event = function( src, props ) {
nickjillings@1318 4669 // Allow instantiation without the 'new' keyword
nickjillings@1318 4670 if ( !(this instanceof jQuery.Event) ) {
nickjillings@1318 4671 return new jQuery.Event( src, props );
nickjillings@1318 4672 }
nickjillings@1318 4673
nickjillings@1318 4674 // Event object
nickjillings@1318 4675 if ( src && src.type ) {
nickjillings@1318 4676 this.originalEvent = src;
nickjillings@1318 4677 this.type = src.type;
nickjillings@1318 4678
nickjillings@1318 4679 // Events bubbling up the document may have been marked as prevented
nickjillings@1318 4680 // by a handler lower down the tree; reflect the correct value.
nickjillings@1318 4681 this.isDefaultPrevented = src.defaultPrevented ||
nickjillings@1318 4682 src.defaultPrevented === undefined &&
nickjillings@1318 4683 // Support: Android<4.0
nickjillings@1318 4684 src.returnValue === false ?
nickjillings@1318 4685 returnTrue :
nickjillings@1318 4686 returnFalse;
nickjillings@1318 4687
nickjillings@1318 4688 // Event type
nickjillings@1318 4689 } else {
nickjillings@1318 4690 this.type = src;
nickjillings@1318 4691 }
nickjillings@1318 4692
nickjillings@1318 4693 // Put explicitly provided properties onto the event object
nickjillings@1318 4694 if ( props ) {
nickjillings@1318 4695 jQuery.extend( this, props );
nickjillings@1318 4696 }
nickjillings@1318 4697
nickjillings@1318 4698 // Create a timestamp if incoming event doesn't have one
nickjillings@1318 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nickjillings@1318 4700
nickjillings@1318 4701 // Mark it as fixed
nickjillings@1318 4702 this[ jQuery.expando ] = true;
nickjillings@1318 4703 };
nickjillings@1318 4704
nickjillings@1318 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nickjillings@1318 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nickjillings@1318 4707 jQuery.Event.prototype = {
nickjillings@1318 4708 isDefaultPrevented: returnFalse,
nickjillings@1318 4709 isPropagationStopped: returnFalse,
nickjillings@1318 4710 isImmediatePropagationStopped: returnFalse,
nickjillings@1318 4711
nickjillings@1318 4712 preventDefault: function() {
nickjillings@1318 4713 var e = this.originalEvent;
nickjillings@1318 4714
nickjillings@1318 4715 this.isDefaultPrevented = returnTrue;
nickjillings@1318 4716
nickjillings@1318 4717 if ( e && e.preventDefault ) {
nickjillings@1318 4718 e.preventDefault();
nickjillings@1318 4719 }
nickjillings@1318 4720 },
nickjillings@1318 4721 stopPropagation: function() {
nickjillings@1318 4722 var e = this.originalEvent;
nickjillings@1318 4723
nickjillings@1318 4724 this.isPropagationStopped = returnTrue;
nickjillings@1318 4725
nickjillings@1318 4726 if ( e && e.stopPropagation ) {
nickjillings@1318 4727 e.stopPropagation();
nickjillings@1318 4728 }
nickjillings@1318 4729 },
nickjillings@1318 4730 stopImmediatePropagation: function() {
nickjillings@1318 4731 var e = this.originalEvent;
nickjillings@1318 4732
nickjillings@1318 4733 this.isImmediatePropagationStopped = returnTrue;
nickjillings@1318 4734
nickjillings@1318 4735 if ( e && e.stopImmediatePropagation ) {
nickjillings@1318 4736 e.stopImmediatePropagation();
nickjillings@1318 4737 }
nickjillings@1318 4738
nickjillings@1318 4739 this.stopPropagation();
nickjillings@1318 4740 }
nickjillings@1318 4741 };
nickjillings@1318 4742
nickjillings@1318 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nickjillings@1318 4744 // Support: Chrome 15+
nickjillings@1318 4745 jQuery.each({
nickjillings@1318 4746 mouseenter: "mouseover",
nickjillings@1318 4747 mouseleave: "mouseout",
nickjillings@1318 4748 pointerenter: "pointerover",
nickjillings@1318 4749 pointerleave: "pointerout"
nickjillings@1318 4750 }, function( orig, fix ) {
nickjillings@1318 4751 jQuery.event.special[ orig ] = {
nickjillings@1318 4752 delegateType: fix,
nickjillings@1318 4753 bindType: fix,
nickjillings@1318 4754
nickjillings@1318 4755 handle: function( event ) {
nickjillings@1318 4756 var ret,
nickjillings@1318 4757 target = this,
nickjillings@1318 4758 related = event.relatedTarget,
nickjillings@1318 4759 handleObj = event.handleObj;
nickjillings@1318 4760
nickjillings@1318 4761 // For mousenter/leave call the handler if related is outside the target.
nickjillings@1318 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nickjillings@1318 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nickjillings@1318 4764 event.type = handleObj.origType;
nickjillings@1318 4765 ret = handleObj.handler.apply( this, arguments );
nickjillings@1318 4766 event.type = fix;
nickjillings@1318 4767 }
nickjillings@1318 4768 return ret;
nickjillings@1318 4769 }
nickjillings@1318 4770 };
nickjillings@1318 4771 });
nickjillings@1318 4772
nickjillings@1318 4773 // Support: Firefox, Chrome, Safari
nickjillings@1318 4774 // Create "bubbling" focus and blur events
nickjillings@1318 4775 if ( !support.focusinBubbles ) {
nickjillings@1318 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nickjillings@1318 4777
nickjillings@1318 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nickjillings@1318 4779 var handler = function( event ) {
nickjillings@1318 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nickjillings@1318 4781 };
nickjillings@1318 4782
nickjillings@1318 4783 jQuery.event.special[ fix ] = {
nickjillings@1318 4784 setup: function() {
nickjillings@1318 4785 var doc = this.ownerDocument || this,
nickjillings@1318 4786 attaches = data_priv.access( doc, fix );
nickjillings@1318 4787
nickjillings@1318 4788 if ( !attaches ) {
nickjillings@1318 4789 doc.addEventListener( orig, handler, true );
nickjillings@1318 4790 }
nickjillings@1318 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nickjillings@1318 4792 },
nickjillings@1318 4793 teardown: function() {
nickjillings@1318 4794 var doc = this.ownerDocument || this,
nickjillings@1318 4795 attaches = data_priv.access( doc, fix ) - 1;
nickjillings@1318 4796
nickjillings@1318 4797 if ( !attaches ) {
nickjillings@1318 4798 doc.removeEventListener( orig, handler, true );
nickjillings@1318 4799 data_priv.remove( doc, fix );
nickjillings@1318 4800
nickjillings@1318 4801 } else {
nickjillings@1318 4802 data_priv.access( doc, fix, attaches );
nickjillings@1318 4803 }
nickjillings@1318 4804 }
nickjillings@1318 4805 };
nickjillings@1318 4806 });
nickjillings@1318 4807 }
nickjillings@1318 4808
nickjillings@1318 4809 jQuery.fn.extend({
nickjillings@1318 4810
nickjillings@1318 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nickjillings@1318 4812 var origFn, type;
nickjillings@1318 4813
nickjillings@1318 4814 // Types can be a map of types/handlers
nickjillings@1318 4815 if ( typeof types === "object" ) {
nickjillings@1318 4816 // ( types-Object, selector, data )
nickjillings@1318 4817 if ( typeof selector !== "string" ) {
nickjillings@1318 4818 // ( types-Object, data )
nickjillings@1318 4819 data = data || selector;
nickjillings@1318 4820 selector = undefined;
nickjillings@1318 4821 }
nickjillings@1318 4822 for ( type in types ) {
nickjillings@1318 4823 this.on( type, selector, data, types[ type ], one );
nickjillings@1318 4824 }
nickjillings@1318 4825 return this;
nickjillings@1318 4826 }
nickjillings@1318 4827
nickjillings@1318 4828 if ( data == null && fn == null ) {
nickjillings@1318 4829 // ( types, fn )
nickjillings@1318 4830 fn = selector;
nickjillings@1318 4831 data = selector = undefined;
nickjillings@1318 4832 } else if ( fn == null ) {
nickjillings@1318 4833 if ( typeof selector === "string" ) {
nickjillings@1318 4834 // ( types, selector, fn )
nickjillings@1318 4835 fn = data;
nickjillings@1318 4836 data = undefined;
nickjillings@1318 4837 } else {
nickjillings@1318 4838 // ( types, data, fn )
nickjillings@1318 4839 fn = data;
nickjillings@1318 4840 data = selector;
nickjillings@1318 4841 selector = undefined;
nickjillings@1318 4842 }
nickjillings@1318 4843 }
nickjillings@1318 4844 if ( fn === false ) {
nickjillings@1318 4845 fn = returnFalse;
nickjillings@1318 4846 } else if ( !fn ) {
nickjillings@1318 4847 return this;
nickjillings@1318 4848 }
nickjillings@1318 4849
nickjillings@1318 4850 if ( one === 1 ) {
nickjillings@1318 4851 origFn = fn;
nickjillings@1318 4852 fn = function( event ) {
nickjillings@1318 4853 // Can use an empty set, since event contains the info
nickjillings@1318 4854 jQuery().off( event );
nickjillings@1318 4855 return origFn.apply( this, arguments );
nickjillings@1318 4856 };
nickjillings@1318 4857 // Use same guid so caller can remove using origFn
nickjillings@1318 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nickjillings@1318 4859 }
nickjillings@1318 4860 return this.each( function() {
nickjillings@1318 4861 jQuery.event.add( this, types, fn, data, selector );
nickjillings@1318 4862 });
nickjillings@1318 4863 },
nickjillings@1318 4864 one: function( types, selector, data, fn ) {
nickjillings@1318 4865 return this.on( types, selector, data, fn, 1 );
nickjillings@1318 4866 },
nickjillings@1318 4867 off: function( types, selector, fn ) {
nickjillings@1318 4868 var handleObj, type;
nickjillings@1318 4869 if ( types && types.preventDefault && types.handleObj ) {
nickjillings@1318 4870 // ( event ) dispatched jQuery.Event
nickjillings@1318 4871 handleObj = types.handleObj;
nickjillings@1318 4872 jQuery( types.delegateTarget ).off(
nickjillings@1318 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nickjillings@1318 4874 handleObj.selector,
nickjillings@1318 4875 handleObj.handler
nickjillings@1318 4876 );
nickjillings@1318 4877 return this;
nickjillings@1318 4878 }
nickjillings@1318 4879 if ( typeof types === "object" ) {
nickjillings@1318 4880 // ( types-object [, selector] )
nickjillings@1318 4881 for ( type in types ) {
nickjillings@1318 4882 this.off( type, selector, types[ type ] );
nickjillings@1318 4883 }
nickjillings@1318 4884 return this;
nickjillings@1318 4885 }
nickjillings@1318 4886 if ( selector === false || typeof selector === "function" ) {
nickjillings@1318 4887 // ( types [, fn] )
nickjillings@1318 4888 fn = selector;
nickjillings@1318 4889 selector = undefined;
nickjillings@1318 4890 }
nickjillings@1318 4891 if ( fn === false ) {
nickjillings@1318 4892 fn = returnFalse;
nickjillings@1318 4893 }
nickjillings@1318 4894 return this.each(function() {
nickjillings@1318 4895 jQuery.event.remove( this, types, fn, selector );
nickjillings@1318 4896 });
nickjillings@1318 4897 },
nickjillings@1318 4898
nickjillings@1318 4899 trigger: function( type, data ) {
nickjillings@1318 4900 return this.each(function() {
nickjillings@1318 4901 jQuery.event.trigger( type, data, this );
nickjillings@1318 4902 });
nickjillings@1318 4903 },
nickjillings@1318 4904 triggerHandler: function( type, data ) {
nickjillings@1318 4905 var elem = this[0];
nickjillings@1318 4906 if ( elem ) {
nickjillings@1318 4907 return jQuery.event.trigger( type, data, elem, true );
nickjillings@1318 4908 }
nickjillings@1318 4909 }
nickjillings@1318 4910 });
nickjillings@1318 4911
nickjillings@1318 4912
nickjillings@1318 4913 var
nickjillings@1318 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nickjillings@1318 4915 rtagName = /<([\w:]+)/,
nickjillings@1318 4916 rhtml = /<|&#?\w+;/,
nickjillings@1318 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nickjillings@1318 4918 // checked="checked" or checked
nickjillings@1318 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nickjillings@1318 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nickjillings@1318 4921 rscriptTypeMasked = /^true\/(.*)/,
nickjillings@1318 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nickjillings@1318 4923
nickjillings@1318 4924 // We have to close these tags to support XHTML (#13200)
nickjillings@1318 4925 wrapMap = {
nickjillings@1318 4926
nickjillings@1318 4927 // Support: IE9
nickjillings@1318 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nickjillings@1318 4929
nickjillings@1318 4930 thead: [ 1, "<table>", "</table>" ],
nickjillings@1318 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nickjillings@1318 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nickjillings@1318 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nickjillings@1318 4934
nickjillings@1318 4935 _default: [ 0, "", "" ]
nickjillings@1318 4936 };
nickjillings@1318 4937
nickjillings@1318 4938 // Support: IE9
nickjillings@1318 4939 wrapMap.optgroup = wrapMap.option;
nickjillings@1318 4940
nickjillings@1318 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nickjillings@1318 4942 wrapMap.th = wrapMap.td;
nickjillings@1318 4943
nickjillings@1318 4944 // Support: 1.x compatibility
nickjillings@1318 4945 // Manipulating tables requires a tbody
nickjillings@1318 4946 function manipulationTarget( elem, content ) {
nickjillings@1318 4947 return jQuery.nodeName( elem, "table" ) &&
nickjillings@1318 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nickjillings@1318 4949
nickjillings@1318 4950 elem.getElementsByTagName("tbody")[0] ||
nickjillings@1318 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nickjillings@1318 4952 elem;
nickjillings@1318 4953 }
nickjillings@1318 4954
nickjillings@1318 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nickjillings@1318 4956 function disableScript( elem ) {
nickjillings@1318 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nickjillings@1318 4958 return elem;
nickjillings@1318 4959 }
nickjillings@1318 4960 function restoreScript( elem ) {
nickjillings@1318 4961 var match = rscriptTypeMasked.exec( elem.type );
nickjillings@1318 4962
nickjillings@1318 4963 if ( match ) {
nickjillings@1318 4964 elem.type = match[ 1 ];
nickjillings@1318 4965 } else {
nickjillings@1318 4966 elem.removeAttribute("type");
nickjillings@1318 4967 }
nickjillings@1318 4968
nickjillings@1318 4969 return elem;
nickjillings@1318 4970 }
nickjillings@1318 4971
nickjillings@1318 4972 // Mark scripts as having already been evaluated
nickjillings@1318 4973 function setGlobalEval( elems, refElements ) {
nickjillings@1318 4974 var i = 0,
nickjillings@1318 4975 l = elems.length;
nickjillings@1318 4976
nickjillings@1318 4977 for ( ; i < l; i++ ) {
nickjillings@1318 4978 data_priv.set(
nickjillings@1318 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nickjillings@1318 4980 );
nickjillings@1318 4981 }
nickjillings@1318 4982 }
nickjillings@1318 4983
nickjillings@1318 4984 function cloneCopyEvent( src, dest ) {
nickjillings@1318 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nickjillings@1318 4986
nickjillings@1318 4987 if ( dest.nodeType !== 1 ) {
nickjillings@1318 4988 return;
nickjillings@1318 4989 }
nickjillings@1318 4990
nickjillings@1318 4991 // 1. Copy private data: events, handlers, etc.
nickjillings@1318 4992 if ( data_priv.hasData( src ) ) {
nickjillings@1318 4993 pdataOld = data_priv.access( src );
nickjillings@1318 4994 pdataCur = data_priv.set( dest, pdataOld );
nickjillings@1318 4995 events = pdataOld.events;
nickjillings@1318 4996
nickjillings@1318 4997 if ( events ) {
nickjillings@1318 4998 delete pdataCur.handle;
nickjillings@1318 4999 pdataCur.events = {};
nickjillings@1318 5000
nickjillings@1318 5001 for ( type in events ) {
nickjillings@1318 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nickjillings@1318 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nickjillings@1318 5004 }
nickjillings@1318 5005 }
nickjillings@1318 5006 }
nickjillings@1318 5007 }
nickjillings@1318 5008
nickjillings@1318 5009 // 2. Copy user data
nickjillings@1318 5010 if ( data_user.hasData( src ) ) {
nickjillings@1318 5011 udataOld = data_user.access( src );
nickjillings@1318 5012 udataCur = jQuery.extend( {}, udataOld );
nickjillings@1318 5013
nickjillings@1318 5014 data_user.set( dest, udataCur );
nickjillings@1318 5015 }
nickjillings@1318 5016 }
nickjillings@1318 5017
nickjillings@1318 5018 function getAll( context, tag ) {
nickjillings@1318 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nickjillings@1318 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nickjillings@1318 5021 [];
nickjillings@1318 5022
nickjillings@1318 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nickjillings@1318 5024 jQuery.merge( [ context ], ret ) :
nickjillings@1318 5025 ret;
nickjillings@1318 5026 }
nickjillings@1318 5027
nickjillings@1318 5028 // Fix IE bugs, see support tests
nickjillings@1318 5029 function fixInput( src, dest ) {
nickjillings@1318 5030 var nodeName = dest.nodeName.toLowerCase();
nickjillings@1318 5031
nickjillings@1318 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nickjillings@1318 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nickjillings@1318 5034 dest.checked = src.checked;
nickjillings@1318 5035
nickjillings@1318 5036 // Fails to return the selected option to the default selected state when cloning options
nickjillings@1318 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nickjillings@1318 5038 dest.defaultValue = src.defaultValue;
nickjillings@1318 5039 }
nickjillings@1318 5040 }
nickjillings@1318 5041
nickjillings@1318 5042 jQuery.extend({
nickjillings@1318 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nickjillings@1318 5044 var i, l, srcElements, destElements,
nickjillings@1318 5045 clone = elem.cloneNode( true ),
nickjillings@1318 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1318 5047
nickjillings@1318 5048 // Fix IE cloning issues
nickjillings@1318 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nickjillings@1318 5050 !jQuery.isXMLDoc( elem ) ) {
nickjillings@1318 5051
nickjillings@1318 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nickjillings@1318 5053 destElements = getAll( clone );
nickjillings@1318 5054 srcElements = getAll( elem );
nickjillings@1318 5055
nickjillings@1318 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1318 5057 fixInput( srcElements[ i ], destElements[ i ] );
nickjillings@1318 5058 }
nickjillings@1318 5059 }
nickjillings@1318 5060
nickjillings@1318 5061 // Copy the events from the original to the clone
nickjillings@1318 5062 if ( dataAndEvents ) {
nickjillings@1318 5063 if ( deepDataAndEvents ) {
nickjillings@1318 5064 srcElements = srcElements || getAll( elem );
nickjillings@1318 5065 destElements = destElements || getAll( clone );
nickjillings@1318 5066
nickjillings@1318 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1318 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nickjillings@1318 5069 }
nickjillings@1318 5070 } else {
nickjillings@1318 5071 cloneCopyEvent( elem, clone );
nickjillings@1318 5072 }
nickjillings@1318 5073 }
nickjillings@1318 5074
nickjillings@1318 5075 // Preserve script evaluation history
nickjillings@1318 5076 destElements = getAll( clone, "script" );
nickjillings@1318 5077 if ( destElements.length > 0 ) {
nickjillings@1318 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nickjillings@1318 5079 }
nickjillings@1318 5080
nickjillings@1318 5081 // Return the cloned set
nickjillings@1318 5082 return clone;
nickjillings@1318 5083 },
nickjillings@1318 5084
nickjillings@1318 5085 buildFragment: function( elems, context, scripts, selection ) {
nickjillings@1318 5086 var elem, tmp, tag, wrap, contains, j,
nickjillings@1318 5087 fragment = context.createDocumentFragment(),
nickjillings@1318 5088 nodes = [],
nickjillings@1318 5089 i = 0,
nickjillings@1318 5090 l = elems.length;
nickjillings@1318 5091
nickjillings@1318 5092 for ( ; i < l; i++ ) {
nickjillings@1318 5093 elem = elems[ i ];
nickjillings@1318 5094
nickjillings@1318 5095 if ( elem || elem === 0 ) {
nickjillings@1318 5096
nickjillings@1318 5097 // Add nodes directly
nickjillings@1318 5098 if ( jQuery.type( elem ) === "object" ) {
nickjillings@1318 5099 // Support: QtWebKit, PhantomJS
nickjillings@1318 5100 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1318 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nickjillings@1318 5102
nickjillings@1318 5103 // Convert non-html into a text node
nickjillings@1318 5104 } else if ( !rhtml.test( elem ) ) {
nickjillings@1318 5105 nodes.push( context.createTextNode( elem ) );
nickjillings@1318 5106
nickjillings@1318 5107 // Convert html into DOM nodes
nickjillings@1318 5108 } else {
nickjillings@1318 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nickjillings@1318 5110
nickjillings@1318 5111 // Deserialize a standard representation
nickjillings@1318 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nickjillings@1318 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nickjillings@1318 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nickjillings@1318 5115
nickjillings@1318 5116 // Descend through wrappers to the right content
nickjillings@1318 5117 j = wrap[ 0 ];
nickjillings@1318 5118 while ( j-- ) {
nickjillings@1318 5119 tmp = tmp.lastChild;
nickjillings@1318 5120 }
nickjillings@1318 5121
nickjillings@1318 5122 // Support: QtWebKit, PhantomJS
nickjillings@1318 5123 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1318 5124 jQuery.merge( nodes, tmp.childNodes );
nickjillings@1318 5125
nickjillings@1318 5126 // Remember the top-level container
nickjillings@1318 5127 tmp = fragment.firstChild;
nickjillings@1318 5128
nickjillings@1318 5129 // Ensure the created nodes are orphaned (#12392)
nickjillings@1318 5130 tmp.textContent = "";
nickjillings@1318 5131 }
nickjillings@1318 5132 }
nickjillings@1318 5133 }
nickjillings@1318 5134
nickjillings@1318 5135 // Remove wrapper from fragment
nickjillings@1318 5136 fragment.textContent = "";
nickjillings@1318 5137
nickjillings@1318 5138 i = 0;
nickjillings@1318 5139 while ( (elem = nodes[ i++ ]) ) {
nickjillings@1318 5140
nickjillings@1318 5141 // #4087 - If origin and destination elements are the same, and this is
nickjillings@1318 5142 // that element, do not do anything
nickjillings@1318 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nickjillings@1318 5144 continue;
nickjillings@1318 5145 }
nickjillings@1318 5146
nickjillings@1318 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1318 5148
nickjillings@1318 5149 // Append to fragment
nickjillings@1318 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nickjillings@1318 5151
nickjillings@1318 5152 // Preserve script evaluation history
nickjillings@1318 5153 if ( contains ) {
nickjillings@1318 5154 setGlobalEval( tmp );
nickjillings@1318 5155 }
nickjillings@1318 5156
nickjillings@1318 5157 // Capture executables
nickjillings@1318 5158 if ( scripts ) {
nickjillings@1318 5159 j = 0;
nickjillings@1318 5160 while ( (elem = tmp[ j++ ]) ) {
nickjillings@1318 5161 if ( rscriptType.test( elem.type || "" ) ) {
nickjillings@1318 5162 scripts.push( elem );
nickjillings@1318 5163 }
nickjillings@1318 5164 }
nickjillings@1318 5165 }
nickjillings@1318 5166 }
nickjillings@1318 5167
nickjillings@1318 5168 return fragment;
nickjillings@1318 5169 },
nickjillings@1318 5170
nickjillings@1318 5171 cleanData: function( elems ) {
nickjillings@1318 5172 var data, elem, type, key,
nickjillings@1318 5173 special = jQuery.event.special,
nickjillings@1318 5174 i = 0;
nickjillings@1318 5175
nickjillings@1318 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nickjillings@1318 5177 if ( jQuery.acceptData( elem ) ) {
nickjillings@1318 5178 key = elem[ data_priv.expando ];
nickjillings@1318 5179
nickjillings@1318 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nickjillings@1318 5181 if ( data.events ) {
nickjillings@1318 5182 for ( type in data.events ) {
nickjillings@1318 5183 if ( special[ type ] ) {
nickjillings@1318 5184 jQuery.event.remove( elem, type );
nickjillings@1318 5185
nickjillings@1318 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nickjillings@1318 5187 } else {
nickjillings@1318 5188 jQuery.removeEvent( elem, type, data.handle );
nickjillings@1318 5189 }
nickjillings@1318 5190 }
nickjillings@1318 5191 }
nickjillings@1318 5192 if ( data_priv.cache[ key ] ) {
nickjillings@1318 5193 // Discard any remaining `private` data
nickjillings@1318 5194 delete data_priv.cache[ key ];
nickjillings@1318 5195 }
nickjillings@1318 5196 }
nickjillings@1318 5197 }
nickjillings@1318 5198 // Discard any remaining `user` data
nickjillings@1318 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nickjillings@1318 5200 }
nickjillings@1318 5201 }
nickjillings@1318 5202 });
nickjillings@1318 5203
nickjillings@1318 5204 jQuery.fn.extend({
nickjillings@1318 5205 text: function( value ) {
nickjillings@1318 5206 return access( this, function( value ) {
nickjillings@1318 5207 return value === undefined ?
nickjillings@1318 5208 jQuery.text( this ) :
nickjillings@1318 5209 this.empty().each(function() {
nickjillings@1318 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1318 5211 this.textContent = value;
nickjillings@1318 5212 }
nickjillings@1318 5213 });
nickjillings@1318 5214 }, null, value, arguments.length );
nickjillings@1318 5215 },
nickjillings@1318 5216
nickjillings@1318 5217 append: function() {
nickjillings@1318 5218 return this.domManip( arguments, function( elem ) {
nickjillings@1318 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1318 5220 var target = manipulationTarget( this, elem );
nickjillings@1318 5221 target.appendChild( elem );
nickjillings@1318 5222 }
nickjillings@1318 5223 });
nickjillings@1318 5224 },
nickjillings@1318 5225
nickjillings@1318 5226 prepend: function() {
nickjillings@1318 5227 return this.domManip( arguments, function( elem ) {
nickjillings@1318 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1318 5229 var target = manipulationTarget( this, elem );
nickjillings@1318 5230 target.insertBefore( elem, target.firstChild );
nickjillings@1318 5231 }
nickjillings@1318 5232 });
nickjillings@1318 5233 },
nickjillings@1318 5234
nickjillings@1318 5235 before: function() {
nickjillings@1318 5236 return this.domManip( arguments, function( elem ) {
nickjillings@1318 5237 if ( this.parentNode ) {
nickjillings@1318 5238 this.parentNode.insertBefore( elem, this );
nickjillings@1318 5239 }
nickjillings@1318 5240 });
nickjillings@1318 5241 },
nickjillings@1318 5242
nickjillings@1318 5243 after: function() {
nickjillings@1318 5244 return this.domManip( arguments, function( elem ) {
nickjillings@1318 5245 if ( this.parentNode ) {
nickjillings@1318 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nickjillings@1318 5247 }
nickjillings@1318 5248 });
nickjillings@1318 5249 },
nickjillings@1318 5250
nickjillings@1318 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nickjillings@1318 5252 var elem,
nickjillings@1318 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nickjillings@1318 5254 i = 0;
nickjillings@1318 5255
nickjillings@1318 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nickjillings@1318 5257 if ( !keepData && elem.nodeType === 1 ) {
nickjillings@1318 5258 jQuery.cleanData( getAll( elem ) );
nickjillings@1318 5259 }
nickjillings@1318 5260
nickjillings@1318 5261 if ( elem.parentNode ) {
nickjillings@1318 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1318 5263 setGlobalEval( getAll( elem, "script" ) );
nickjillings@1318 5264 }
nickjillings@1318 5265 elem.parentNode.removeChild( elem );
nickjillings@1318 5266 }
nickjillings@1318 5267 }
nickjillings@1318 5268
nickjillings@1318 5269 return this;
nickjillings@1318 5270 },
nickjillings@1318 5271
nickjillings@1318 5272 empty: function() {
nickjillings@1318 5273 var elem,
nickjillings@1318 5274 i = 0;
nickjillings@1318 5275
nickjillings@1318 5276 for ( ; (elem = this[i]) != null; i++ ) {
nickjillings@1318 5277 if ( elem.nodeType === 1 ) {
nickjillings@1318 5278
nickjillings@1318 5279 // Prevent memory leaks
nickjillings@1318 5280 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1318 5281
nickjillings@1318 5282 // Remove any remaining nodes
nickjillings@1318 5283 elem.textContent = "";
nickjillings@1318 5284 }
nickjillings@1318 5285 }
nickjillings@1318 5286
nickjillings@1318 5287 return this;
nickjillings@1318 5288 },
nickjillings@1318 5289
nickjillings@1318 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nickjillings@1318 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nickjillings@1318 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nickjillings@1318 5293
nickjillings@1318 5294 return this.map(function() {
nickjillings@1318 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nickjillings@1318 5296 });
nickjillings@1318 5297 },
nickjillings@1318 5298
nickjillings@1318 5299 html: function( value ) {
nickjillings@1318 5300 return access( this, function( value ) {
nickjillings@1318 5301 var elem = this[ 0 ] || {},
nickjillings@1318 5302 i = 0,
nickjillings@1318 5303 l = this.length;
nickjillings@1318 5304
nickjillings@1318 5305 if ( value === undefined && elem.nodeType === 1 ) {
nickjillings@1318 5306 return elem.innerHTML;
nickjillings@1318 5307 }
nickjillings@1318 5308
nickjillings@1318 5309 // See if we can take a shortcut and just use innerHTML
nickjillings@1318 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nickjillings@1318 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nickjillings@1318 5312
nickjillings@1318 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nickjillings@1318 5314
nickjillings@1318 5315 try {
nickjillings@1318 5316 for ( ; i < l; i++ ) {
nickjillings@1318 5317 elem = this[ i ] || {};
nickjillings@1318 5318
nickjillings@1318 5319 // Remove element nodes and prevent memory leaks
nickjillings@1318 5320 if ( elem.nodeType === 1 ) {
nickjillings@1318 5321 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1318 5322 elem.innerHTML = value;
nickjillings@1318 5323 }
nickjillings@1318 5324 }
nickjillings@1318 5325
nickjillings@1318 5326 elem = 0;
nickjillings@1318 5327
nickjillings@1318 5328 // If using innerHTML throws an exception, use the fallback method
nickjillings@1318 5329 } catch( e ) {}
nickjillings@1318 5330 }
nickjillings@1318 5331
nickjillings@1318 5332 if ( elem ) {
nickjillings@1318 5333 this.empty().append( value );
nickjillings@1318 5334 }
nickjillings@1318 5335 }, null, value, arguments.length );
nickjillings@1318 5336 },
nickjillings@1318 5337
nickjillings@1318 5338 replaceWith: function() {
nickjillings@1318 5339 var arg = arguments[ 0 ];
nickjillings@1318 5340
nickjillings@1318 5341 // Make the changes, replacing each context element with the new content
nickjillings@1318 5342 this.domManip( arguments, function( elem ) {
nickjillings@1318 5343 arg = this.parentNode;
nickjillings@1318 5344
nickjillings@1318 5345 jQuery.cleanData( getAll( this ) );
nickjillings@1318 5346
nickjillings@1318 5347 if ( arg ) {
nickjillings@1318 5348 arg.replaceChild( elem, this );
nickjillings@1318 5349 }
nickjillings@1318 5350 });
nickjillings@1318 5351
nickjillings@1318 5352 // Force removal if there was no new content (e.g., from empty arguments)
nickjillings@1318 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nickjillings@1318 5354 },
nickjillings@1318 5355
nickjillings@1318 5356 detach: function( selector ) {
nickjillings@1318 5357 return this.remove( selector, true );
nickjillings@1318 5358 },
nickjillings@1318 5359
nickjillings@1318 5360 domManip: function( args, callback ) {
nickjillings@1318 5361
nickjillings@1318 5362 // Flatten any nested arrays
nickjillings@1318 5363 args = concat.apply( [], args );
nickjillings@1318 5364
nickjillings@1318 5365 var fragment, first, scripts, hasScripts, node, doc,
nickjillings@1318 5366 i = 0,
nickjillings@1318 5367 l = this.length,
nickjillings@1318 5368 set = this,
nickjillings@1318 5369 iNoClone = l - 1,
nickjillings@1318 5370 value = args[ 0 ],
nickjillings@1318 5371 isFunction = jQuery.isFunction( value );
nickjillings@1318 5372
nickjillings@1318 5373 // We can't cloneNode fragments that contain checked, in WebKit
nickjillings@1318 5374 if ( isFunction ||
nickjillings@1318 5375 ( l > 1 && typeof value === "string" &&
nickjillings@1318 5376 !support.checkClone && rchecked.test( value ) ) ) {
nickjillings@1318 5377 return this.each(function( index ) {
nickjillings@1318 5378 var self = set.eq( index );
nickjillings@1318 5379 if ( isFunction ) {
nickjillings@1318 5380 args[ 0 ] = value.call( this, index, self.html() );
nickjillings@1318 5381 }
nickjillings@1318 5382 self.domManip( args, callback );
nickjillings@1318 5383 });
nickjillings@1318 5384 }
nickjillings@1318 5385
nickjillings@1318 5386 if ( l ) {
nickjillings@1318 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nickjillings@1318 5388 first = fragment.firstChild;
nickjillings@1318 5389
nickjillings@1318 5390 if ( fragment.childNodes.length === 1 ) {
nickjillings@1318 5391 fragment = first;
nickjillings@1318 5392 }
nickjillings@1318 5393
nickjillings@1318 5394 if ( first ) {
nickjillings@1318 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nickjillings@1318 5396 hasScripts = scripts.length;
nickjillings@1318 5397
nickjillings@1318 5398 // Use the original fragment for the last item instead of the first because it can end up
nickjillings@1318 5399 // being emptied incorrectly in certain situations (#8070).
nickjillings@1318 5400 for ( ; i < l; i++ ) {
nickjillings@1318 5401 node = fragment;
nickjillings@1318 5402
nickjillings@1318 5403 if ( i !== iNoClone ) {
nickjillings@1318 5404 node = jQuery.clone( node, true, true );
nickjillings@1318 5405
nickjillings@1318 5406 // Keep references to cloned scripts for later restoration
nickjillings@1318 5407 if ( hasScripts ) {
nickjillings@1318 5408 // Support: QtWebKit
nickjillings@1318 5409 // jQuery.merge because push.apply(_, arraylike) throws
nickjillings@1318 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nickjillings@1318 5411 }
nickjillings@1318 5412 }
nickjillings@1318 5413
nickjillings@1318 5414 callback.call( this[ i ], node, i );
nickjillings@1318 5415 }
nickjillings@1318 5416
nickjillings@1318 5417 if ( hasScripts ) {
nickjillings@1318 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nickjillings@1318 5419
nickjillings@1318 5420 // Reenable scripts
nickjillings@1318 5421 jQuery.map( scripts, restoreScript );
nickjillings@1318 5422
nickjillings@1318 5423 // Evaluate executable scripts on first document insertion
nickjillings@1318 5424 for ( i = 0; i < hasScripts; i++ ) {
nickjillings@1318 5425 node = scripts[ i ];
nickjillings@1318 5426 if ( rscriptType.test( node.type || "" ) &&
nickjillings@1318 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nickjillings@1318 5428
nickjillings@1318 5429 if ( node.src ) {
nickjillings@1318 5430 // Optional AJAX dependency, but won't run scripts if not present
nickjillings@1318 5431 if ( jQuery._evalUrl ) {
nickjillings@1318 5432 jQuery._evalUrl( node.src );
nickjillings@1318 5433 }
nickjillings@1318 5434 } else {
nickjillings@1318 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nickjillings@1318 5436 }
nickjillings@1318 5437 }
nickjillings@1318 5438 }
nickjillings@1318 5439 }
nickjillings@1318 5440 }
nickjillings@1318 5441 }
nickjillings@1318 5442
nickjillings@1318 5443 return this;
nickjillings@1318 5444 }
nickjillings@1318 5445 });
nickjillings@1318 5446
nickjillings@1318 5447 jQuery.each({
nickjillings@1318 5448 appendTo: "append",
nickjillings@1318 5449 prependTo: "prepend",
nickjillings@1318 5450 insertBefore: "before",
nickjillings@1318 5451 insertAfter: "after",
nickjillings@1318 5452 replaceAll: "replaceWith"
nickjillings@1318 5453 }, function( name, original ) {
nickjillings@1318 5454 jQuery.fn[ name ] = function( selector ) {
nickjillings@1318 5455 var elems,
nickjillings@1318 5456 ret = [],
nickjillings@1318 5457 insert = jQuery( selector ),
nickjillings@1318 5458 last = insert.length - 1,
nickjillings@1318 5459 i = 0;
nickjillings@1318 5460
nickjillings@1318 5461 for ( ; i <= last; i++ ) {
nickjillings@1318 5462 elems = i === last ? this : this.clone( true );
nickjillings@1318 5463 jQuery( insert[ i ] )[ original ]( elems );
nickjillings@1318 5464
nickjillings@1318 5465 // Support: QtWebKit
nickjillings@1318 5466 // .get() because push.apply(_, arraylike) throws
nickjillings@1318 5467 push.apply( ret, elems.get() );
nickjillings@1318 5468 }
nickjillings@1318 5469
nickjillings@1318 5470 return this.pushStack( ret );
nickjillings@1318 5471 };
nickjillings@1318 5472 });
nickjillings@1318 5473
nickjillings@1318 5474
nickjillings@1318 5475 var iframe,
nickjillings@1318 5476 elemdisplay = {};
nickjillings@1318 5477
nickjillings@1318 5478 /**
nickjillings@1318 5479 * Retrieve the actual display of a element
nickjillings@1318 5480 * @param {String} name nodeName of the element
nickjillings@1318 5481 * @param {Object} doc Document object
nickjillings@1318 5482 */
nickjillings@1318 5483 // Called only from within defaultDisplay
nickjillings@1318 5484 function actualDisplay( name, doc ) {
nickjillings@1318 5485 var style,
nickjillings@1318 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nickjillings@1318 5487
nickjillings@1318 5488 // getDefaultComputedStyle might be reliably used only on attached element
nickjillings@1318 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nickjillings@1318 5490
nickjillings@1318 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nickjillings@1318 5492 // since it was removed from specification and supported only in FF
nickjillings@1318 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nickjillings@1318 5494
nickjillings@1318 5495 // We don't have any data stored on the element,
nickjillings@1318 5496 // so use "detach" method as fast way to get rid of the element
nickjillings@1318 5497 elem.detach();
nickjillings@1318 5498
nickjillings@1318 5499 return display;
nickjillings@1318 5500 }
nickjillings@1318 5501
nickjillings@1318 5502 /**
nickjillings@1318 5503 * Try to determine the default display value of an element
nickjillings@1318 5504 * @param {String} nodeName
nickjillings@1318 5505 */
nickjillings@1318 5506 function defaultDisplay( nodeName ) {
nickjillings@1318 5507 var doc = document,
nickjillings@1318 5508 display = elemdisplay[ nodeName ];
nickjillings@1318 5509
nickjillings@1318 5510 if ( !display ) {
nickjillings@1318 5511 display = actualDisplay( nodeName, doc );
nickjillings@1318 5512
nickjillings@1318 5513 // If the simple way fails, read from inside an iframe
nickjillings@1318 5514 if ( display === "none" || !display ) {
nickjillings@1318 5515
nickjillings@1318 5516 // Use the already-created iframe if possible
nickjillings@1318 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nickjillings@1318 5518
nickjillings@1318 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nickjillings@1318 5520 doc = iframe[ 0 ].contentDocument;
nickjillings@1318 5521
nickjillings@1318 5522 // Support: IE
nickjillings@1318 5523 doc.write();
nickjillings@1318 5524 doc.close();
nickjillings@1318 5525
nickjillings@1318 5526 display = actualDisplay( nodeName, doc );
nickjillings@1318 5527 iframe.detach();
nickjillings@1318 5528 }
nickjillings@1318 5529
nickjillings@1318 5530 // Store the correct default display
nickjillings@1318 5531 elemdisplay[ nodeName ] = display;
nickjillings@1318 5532 }
nickjillings@1318 5533
nickjillings@1318 5534 return display;
nickjillings@1318 5535 }
nickjillings@1318 5536 var rmargin = (/^margin/);
nickjillings@1318 5537
nickjillings@1318 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nickjillings@1318 5539
nickjillings@1318 5540 var getStyles = function( elem ) {
nickjillings@1318 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nickjillings@1318 5542 // IE throws on elements created in popups
nickjillings@1318 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nickjillings@1318 5544 if ( elem.ownerDocument.defaultView.opener ) {
nickjillings@1318 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nickjillings@1318 5546 }
nickjillings@1318 5547
nickjillings@1318 5548 return window.getComputedStyle( elem, null );
nickjillings@1318 5549 };
nickjillings@1318 5550
nickjillings@1318 5551
nickjillings@1318 5552
nickjillings@1318 5553 function curCSS( elem, name, computed ) {
nickjillings@1318 5554 var width, minWidth, maxWidth, ret,
nickjillings@1318 5555 style = elem.style;
nickjillings@1318 5556
nickjillings@1318 5557 computed = computed || getStyles( elem );
nickjillings@1318 5558
nickjillings@1318 5559 // Support: IE9
nickjillings@1318 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nickjillings@1318 5561 if ( computed ) {
nickjillings@1318 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nickjillings@1318 5563 }
nickjillings@1318 5564
nickjillings@1318 5565 if ( computed ) {
nickjillings@1318 5566
nickjillings@1318 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1318 5568 ret = jQuery.style( elem, name );
nickjillings@1318 5569 }
nickjillings@1318 5570
nickjillings@1318 5571 // Support: iOS < 6
nickjillings@1318 5572 // A tribute to the "awesome hack by Dean Edwards"
nickjillings@1318 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nickjillings@1318 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nickjillings@1318 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nickjillings@1318 5576
nickjillings@1318 5577 // Remember the original values
nickjillings@1318 5578 width = style.width;
nickjillings@1318 5579 minWidth = style.minWidth;
nickjillings@1318 5580 maxWidth = style.maxWidth;
nickjillings@1318 5581
nickjillings@1318 5582 // Put in the new values to get a computed value out
nickjillings@1318 5583 style.minWidth = style.maxWidth = style.width = ret;
nickjillings@1318 5584 ret = computed.width;
nickjillings@1318 5585
nickjillings@1318 5586 // Revert the changed values
nickjillings@1318 5587 style.width = width;
nickjillings@1318 5588 style.minWidth = minWidth;
nickjillings@1318 5589 style.maxWidth = maxWidth;
nickjillings@1318 5590 }
nickjillings@1318 5591 }
nickjillings@1318 5592
nickjillings@1318 5593 return ret !== undefined ?
nickjillings@1318 5594 // Support: IE
nickjillings@1318 5595 // IE returns zIndex value as an integer.
nickjillings@1318 5596 ret + "" :
nickjillings@1318 5597 ret;
nickjillings@1318 5598 }
nickjillings@1318 5599
nickjillings@1318 5600
nickjillings@1318 5601 function addGetHookIf( conditionFn, hookFn ) {
nickjillings@1318 5602 // Define the hook, we'll check on the first run if it's really needed.
nickjillings@1318 5603 return {
nickjillings@1318 5604 get: function() {
nickjillings@1318 5605 if ( conditionFn() ) {
nickjillings@1318 5606 // Hook not needed (or it's not possible to use it due
nickjillings@1318 5607 // to missing dependency), remove it.
nickjillings@1318 5608 delete this.get;
nickjillings@1318 5609 return;
nickjillings@1318 5610 }
nickjillings@1318 5611
nickjillings@1318 5612 // Hook needed; redefine it so that the support test is not executed again.
nickjillings@1318 5613 return (this.get = hookFn).apply( this, arguments );
nickjillings@1318 5614 }
nickjillings@1318 5615 };
nickjillings@1318 5616 }
nickjillings@1318 5617
nickjillings@1318 5618
nickjillings@1318 5619 (function() {
nickjillings@1318 5620 var pixelPositionVal, boxSizingReliableVal,
nickjillings@1318 5621 docElem = document.documentElement,
nickjillings@1318 5622 container = document.createElement( "div" ),
nickjillings@1318 5623 div = document.createElement( "div" );
nickjillings@1318 5624
nickjillings@1318 5625 if ( !div.style ) {
nickjillings@1318 5626 return;
nickjillings@1318 5627 }
nickjillings@1318 5628
nickjillings@1318 5629 // Support: IE9-11+
nickjillings@1318 5630 // Style of cloned element affects source element cloned (#8908)
nickjillings@1318 5631 div.style.backgroundClip = "content-box";
nickjillings@1318 5632 div.cloneNode( true ).style.backgroundClip = "";
nickjillings@1318 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nickjillings@1318 5634
nickjillings@1318 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nickjillings@1318 5636 "position:absolute";
nickjillings@1318 5637 container.appendChild( div );
nickjillings@1318 5638
nickjillings@1318 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nickjillings@1318 5640 // so they're executed at the same time to save the second computation.
nickjillings@1318 5641 function computePixelPositionAndBoxSizingReliable() {
nickjillings@1318 5642 div.style.cssText =
nickjillings@1318 5643 // Support: Firefox<29, Android 2.3
nickjillings@1318 5644 // Vendor-prefix box-sizing
nickjillings@1318 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nickjillings@1318 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nickjillings@1318 5647 "border:1px;padding:1px;width:4px;position:absolute";
nickjillings@1318 5648 div.innerHTML = "";
nickjillings@1318 5649 docElem.appendChild( container );
nickjillings@1318 5650
nickjillings@1318 5651 var divStyle = window.getComputedStyle( div, null );
nickjillings@1318 5652 pixelPositionVal = divStyle.top !== "1%";
nickjillings@1318 5653 boxSizingReliableVal = divStyle.width === "4px";
nickjillings@1318 5654
nickjillings@1318 5655 docElem.removeChild( container );
nickjillings@1318 5656 }
nickjillings@1318 5657
nickjillings@1318 5658 // Support: node.js jsdom
nickjillings@1318 5659 // Don't assume that getComputedStyle is a property of the global object
nickjillings@1318 5660 if ( window.getComputedStyle ) {
nickjillings@1318 5661 jQuery.extend( support, {
nickjillings@1318 5662 pixelPosition: function() {
nickjillings@1318 5663
nickjillings@1318 5664 // This test is executed only once but we still do memoizing
nickjillings@1318 5665 // since we can use the boxSizingReliable pre-computing.
nickjillings@1318 5666 // No need to check if the test was already performed, though.
nickjillings@1318 5667 computePixelPositionAndBoxSizingReliable();
nickjillings@1318 5668 return pixelPositionVal;
nickjillings@1318 5669 },
nickjillings@1318 5670 boxSizingReliable: function() {
nickjillings@1318 5671 if ( boxSizingReliableVal == null ) {
nickjillings@1318 5672 computePixelPositionAndBoxSizingReliable();
nickjillings@1318 5673 }
nickjillings@1318 5674 return boxSizingReliableVal;
nickjillings@1318 5675 },
nickjillings@1318 5676 reliableMarginRight: function() {
nickjillings@1318 5677
nickjillings@1318 5678 // Support: Android 2.3
nickjillings@1318 5679 // Check if div with explicit width and no margin-right incorrectly
nickjillings@1318 5680 // gets computed margin-right based on width of container. (#3333)
nickjillings@1318 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nickjillings@1318 5682 // This support function is only executed once so no memoizing is needed.
nickjillings@1318 5683 var ret,
nickjillings@1318 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nickjillings@1318 5685
nickjillings@1318 5686 // Reset CSS: box-sizing; display; margin; border; padding
nickjillings@1318 5687 marginDiv.style.cssText = div.style.cssText =
nickjillings@1318 5688 // Support: Firefox<29, Android 2.3
nickjillings@1318 5689 // Vendor-prefix box-sizing
nickjillings@1318 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nickjillings@1318 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nickjillings@1318 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nickjillings@1318 5693 div.style.width = "1px";
nickjillings@1318 5694 docElem.appendChild( container );
nickjillings@1318 5695
nickjillings@1318 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nickjillings@1318 5697
nickjillings@1318 5698 docElem.removeChild( container );
nickjillings@1318 5699 div.removeChild( marginDiv );
nickjillings@1318 5700
nickjillings@1318 5701 return ret;
nickjillings@1318 5702 }
nickjillings@1318 5703 });
nickjillings@1318 5704 }
nickjillings@1318 5705 })();
nickjillings@1318 5706
nickjillings@1318 5707
nickjillings@1318 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nickjillings@1318 5709 jQuery.swap = function( elem, options, callback, args ) {
nickjillings@1318 5710 var ret, name,
nickjillings@1318 5711 old = {};
nickjillings@1318 5712
nickjillings@1318 5713 // Remember the old values, and insert the new ones
nickjillings@1318 5714 for ( name in options ) {
nickjillings@1318 5715 old[ name ] = elem.style[ name ];
nickjillings@1318 5716 elem.style[ name ] = options[ name ];
nickjillings@1318 5717 }
nickjillings@1318 5718
nickjillings@1318 5719 ret = callback.apply( elem, args || [] );
nickjillings@1318 5720
nickjillings@1318 5721 // Revert the old values
nickjillings@1318 5722 for ( name in options ) {
nickjillings@1318 5723 elem.style[ name ] = old[ name ];
nickjillings@1318 5724 }
nickjillings@1318 5725
nickjillings@1318 5726 return ret;
nickjillings@1318 5727 };
nickjillings@1318 5728
nickjillings@1318 5729
nickjillings@1318 5730 var
nickjillings@1318 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nickjillings@1318 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nickjillings@1318 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nickjillings@1318 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nickjillings@1318 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nickjillings@1318 5736
nickjillings@1318 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nickjillings@1318 5738 cssNormalTransform = {
nickjillings@1318 5739 letterSpacing: "0",
nickjillings@1318 5740 fontWeight: "400"
nickjillings@1318 5741 },
nickjillings@1318 5742
nickjillings@1318 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nickjillings@1318 5744
nickjillings@1318 5745 // Return a css property mapped to a potentially vendor prefixed property
nickjillings@1318 5746 function vendorPropName( style, name ) {
nickjillings@1318 5747
nickjillings@1318 5748 // Shortcut for names that are not vendor prefixed
nickjillings@1318 5749 if ( name in style ) {
nickjillings@1318 5750 return name;
nickjillings@1318 5751 }
nickjillings@1318 5752
nickjillings@1318 5753 // Check for vendor prefixed names
nickjillings@1318 5754 var capName = name[0].toUpperCase() + name.slice(1),
nickjillings@1318 5755 origName = name,
nickjillings@1318 5756 i = cssPrefixes.length;
nickjillings@1318 5757
nickjillings@1318 5758 while ( i-- ) {
nickjillings@1318 5759 name = cssPrefixes[ i ] + capName;
nickjillings@1318 5760 if ( name in style ) {
nickjillings@1318 5761 return name;
nickjillings@1318 5762 }
nickjillings@1318 5763 }
nickjillings@1318 5764
nickjillings@1318 5765 return origName;
nickjillings@1318 5766 }
nickjillings@1318 5767
nickjillings@1318 5768 function setPositiveNumber( elem, value, subtract ) {
nickjillings@1318 5769 var matches = rnumsplit.exec( value );
nickjillings@1318 5770 return matches ?
nickjillings@1318 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nickjillings@1318 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nickjillings@1318 5773 value;
nickjillings@1318 5774 }
nickjillings@1318 5775
nickjillings@1318 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nickjillings@1318 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nickjillings@1318 5778 // If we already have the right measurement, avoid augmentation
nickjillings@1318 5779 4 :
nickjillings@1318 5780 // Otherwise initialize for horizontal or vertical properties
nickjillings@1318 5781 name === "width" ? 1 : 0,
nickjillings@1318 5782
nickjillings@1318 5783 val = 0;
nickjillings@1318 5784
nickjillings@1318 5785 for ( ; i < 4; i += 2 ) {
nickjillings@1318 5786 // Both box models exclude margin, so add it if we want it
nickjillings@1318 5787 if ( extra === "margin" ) {
nickjillings@1318 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nickjillings@1318 5789 }
nickjillings@1318 5790
nickjillings@1318 5791 if ( isBorderBox ) {
nickjillings@1318 5792 // border-box includes padding, so remove it if we want content
nickjillings@1318 5793 if ( extra === "content" ) {
nickjillings@1318 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1318 5795 }
nickjillings@1318 5796
nickjillings@1318 5797 // At this point, extra isn't border nor margin, so remove border
nickjillings@1318 5798 if ( extra !== "margin" ) {
nickjillings@1318 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1318 5800 }
nickjillings@1318 5801 } else {
nickjillings@1318 5802 // At this point, extra isn't content, so add padding
nickjillings@1318 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1318 5804
nickjillings@1318 5805 // At this point, extra isn't content nor padding, so add border
nickjillings@1318 5806 if ( extra !== "padding" ) {
nickjillings@1318 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1318 5808 }
nickjillings@1318 5809 }
nickjillings@1318 5810 }
nickjillings@1318 5811
nickjillings@1318 5812 return val;
nickjillings@1318 5813 }
nickjillings@1318 5814
nickjillings@1318 5815 function getWidthOrHeight( elem, name, extra ) {
nickjillings@1318 5816
nickjillings@1318 5817 // Start with offset property, which is equivalent to the border-box value
nickjillings@1318 5818 var valueIsBorderBox = true,
nickjillings@1318 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nickjillings@1318 5820 styles = getStyles( elem ),
nickjillings@1318 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nickjillings@1318 5822
nickjillings@1318 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nickjillings@1318 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nickjillings@1318 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nickjillings@1318 5826 if ( val <= 0 || val == null ) {
nickjillings@1318 5827 // Fall back to computed then uncomputed css if necessary
nickjillings@1318 5828 val = curCSS( elem, name, styles );
nickjillings@1318 5829 if ( val < 0 || val == null ) {
nickjillings@1318 5830 val = elem.style[ name ];
nickjillings@1318 5831 }
nickjillings@1318 5832
nickjillings@1318 5833 // Computed unit is not pixels. Stop here and return.
nickjillings@1318 5834 if ( rnumnonpx.test(val) ) {
nickjillings@1318 5835 return val;
nickjillings@1318 5836 }
nickjillings@1318 5837
nickjillings@1318 5838 // Check for style in case a browser which returns unreliable values
nickjillings@1318 5839 // for getComputedStyle silently falls back to the reliable elem.style
nickjillings@1318 5840 valueIsBorderBox = isBorderBox &&
nickjillings@1318 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nickjillings@1318 5842
nickjillings@1318 5843 // Normalize "", auto, and prepare for extra
nickjillings@1318 5844 val = parseFloat( val ) || 0;
nickjillings@1318 5845 }
nickjillings@1318 5846
nickjillings@1318 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nickjillings@1318 5848 return ( val +
nickjillings@1318 5849 augmentWidthOrHeight(
nickjillings@1318 5850 elem,
nickjillings@1318 5851 name,
nickjillings@1318 5852 extra || ( isBorderBox ? "border" : "content" ),
nickjillings@1318 5853 valueIsBorderBox,
nickjillings@1318 5854 styles
nickjillings@1318 5855 )
nickjillings@1318 5856 ) + "px";
nickjillings@1318 5857 }
nickjillings@1318 5858
nickjillings@1318 5859 function showHide( elements, show ) {
nickjillings@1318 5860 var display, elem, hidden,
nickjillings@1318 5861 values = [],
nickjillings@1318 5862 index = 0,
nickjillings@1318 5863 length = elements.length;
nickjillings@1318 5864
nickjillings@1318 5865 for ( ; index < length; index++ ) {
nickjillings@1318 5866 elem = elements[ index ];
nickjillings@1318 5867 if ( !elem.style ) {
nickjillings@1318 5868 continue;
nickjillings@1318 5869 }
nickjillings@1318 5870
nickjillings@1318 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nickjillings@1318 5872 display = elem.style.display;
nickjillings@1318 5873 if ( show ) {
nickjillings@1318 5874 // Reset the inline display of this element to learn if it is
nickjillings@1318 5875 // being hidden by cascaded rules or not
nickjillings@1318 5876 if ( !values[ index ] && display === "none" ) {
nickjillings@1318 5877 elem.style.display = "";
nickjillings@1318 5878 }
nickjillings@1318 5879
nickjillings@1318 5880 // Set elements which have been overridden with display: none
nickjillings@1318 5881 // in a stylesheet to whatever the default browser style is
nickjillings@1318 5882 // for such an element
nickjillings@1318 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nickjillings@1318 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nickjillings@1318 5885 }
nickjillings@1318 5886 } else {
nickjillings@1318 5887 hidden = isHidden( elem );
nickjillings@1318 5888
nickjillings@1318 5889 if ( display !== "none" || !hidden ) {
nickjillings@1318 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nickjillings@1318 5891 }
nickjillings@1318 5892 }
nickjillings@1318 5893 }
nickjillings@1318 5894
nickjillings@1318 5895 // Set the display of most of the elements in a second loop
nickjillings@1318 5896 // to avoid the constant reflow
nickjillings@1318 5897 for ( index = 0; index < length; index++ ) {
nickjillings@1318 5898 elem = elements[ index ];
nickjillings@1318 5899 if ( !elem.style ) {
nickjillings@1318 5900 continue;
nickjillings@1318 5901 }
nickjillings@1318 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nickjillings@1318 5903 elem.style.display = show ? values[ index ] || "" : "none";
nickjillings@1318 5904 }
nickjillings@1318 5905 }
nickjillings@1318 5906
nickjillings@1318 5907 return elements;
nickjillings@1318 5908 }
nickjillings@1318 5909
nickjillings@1318 5910 jQuery.extend({
nickjillings@1318 5911
nickjillings@1318 5912 // Add in style property hooks for overriding the default
nickjillings@1318 5913 // behavior of getting and setting a style property
nickjillings@1318 5914 cssHooks: {
nickjillings@1318 5915 opacity: {
nickjillings@1318 5916 get: function( elem, computed ) {
nickjillings@1318 5917 if ( computed ) {
nickjillings@1318 5918
nickjillings@1318 5919 // We should always get a number back from opacity
nickjillings@1318 5920 var ret = curCSS( elem, "opacity" );
nickjillings@1318 5921 return ret === "" ? "1" : ret;
nickjillings@1318 5922 }
nickjillings@1318 5923 }
nickjillings@1318 5924 }
nickjillings@1318 5925 },
nickjillings@1318 5926
nickjillings@1318 5927 // Don't automatically add "px" to these possibly-unitless properties
nickjillings@1318 5928 cssNumber: {
nickjillings@1318 5929 "columnCount": true,
nickjillings@1318 5930 "fillOpacity": true,
nickjillings@1318 5931 "flexGrow": true,
nickjillings@1318 5932 "flexShrink": true,
nickjillings@1318 5933 "fontWeight": true,
nickjillings@1318 5934 "lineHeight": true,
nickjillings@1318 5935 "opacity": true,
nickjillings@1318 5936 "order": true,
nickjillings@1318 5937 "orphans": true,
nickjillings@1318 5938 "widows": true,
nickjillings@1318 5939 "zIndex": true,
nickjillings@1318 5940 "zoom": true
nickjillings@1318 5941 },
nickjillings@1318 5942
nickjillings@1318 5943 // Add in properties whose names you wish to fix before
nickjillings@1318 5944 // setting or getting the value
nickjillings@1318 5945 cssProps: {
nickjillings@1318 5946 "float": "cssFloat"
nickjillings@1318 5947 },
nickjillings@1318 5948
nickjillings@1318 5949 // Get and set the style property on a DOM Node
nickjillings@1318 5950 style: function( elem, name, value, extra ) {
nickjillings@1318 5951
nickjillings@1318 5952 // Don't set styles on text and comment nodes
nickjillings@1318 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nickjillings@1318 5954 return;
nickjillings@1318 5955 }
nickjillings@1318 5956
nickjillings@1318 5957 // Make sure that we're working with the right name
nickjillings@1318 5958 var ret, type, hooks,
nickjillings@1318 5959 origName = jQuery.camelCase( name ),
nickjillings@1318 5960 style = elem.style;
nickjillings@1318 5961
nickjillings@1318 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nickjillings@1318 5963
nickjillings@1318 5964 // Gets hook for the prefixed version, then unprefixed version
nickjillings@1318 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1318 5966
nickjillings@1318 5967 // Check if we're setting a value
nickjillings@1318 5968 if ( value !== undefined ) {
nickjillings@1318 5969 type = typeof value;
nickjillings@1318 5970
nickjillings@1318 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nickjillings@1318 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nickjillings@1318 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nickjillings@1318 5974 // Fixes bug #9237
nickjillings@1318 5975 type = "number";
nickjillings@1318 5976 }
nickjillings@1318 5977
nickjillings@1318 5978 // Make sure that null and NaN values aren't set (#7116)
nickjillings@1318 5979 if ( value == null || value !== value ) {
nickjillings@1318 5980 return;
nickjillings@1318 5981 }
nickjillings@1318 5982
nickjillings@1318 5983 // If a number, add 'px' to the (except for certain CSS properties)
nickjillings@1318 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nickjillings@1318 5985 value += "px";
nickjillings@1318 5986 }
nickjillings@1318 5987
nickjillings@1318 5988 // Support: IE9-11+
nickjillings@1318 5989 // background-* props affect original clone's values
nickjillings@1318 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nickjillings@1318 5991 style[ name ] = "inherit";
nickjillings@1318 5992 }
nickjillings@1318 5993
nickjillings@1318 5994 // If a hook was provided, use that value, otherwise just set the specified value
nickjillings@1318 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nickjillings@1318 5996 style[ name ] = value;
nickjillings@1318 5997 }
nickjillings@1318 5998
nickjillings@1318 5999 } else {
nickjillings@1318 6000 // If a hook was provided get the non-computed value from there
nickjillings@1318 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nickjillings@1318 6002 return ret;
nickjillings@1318 6003 }
nickjillings@1318 6004
nickjillings@1318 6005 // Otherwise just get the value from the style object
nickjillings@1318 6006 return style[ name ];
nickjillings@1318 6007 }
nickjillings@1318 6008 },
nickjillings@1318 6009
nickjillings@1318 6010 css: function( elem, name, extra, styles ) {
nickjillings@1318 6011 var val, num, hooks,
nickjillings@1318 6012 origName = jQuery.camelCase( name );
nickjillings@1318 6013
nickjillings@1318 6014 // Make sure that we're working with the right name
nickjillings@1318 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nickjillings@1318 6016
nickjillings@1318 6017 // Try prefixed name followed by the unprefixed name
nickjillings@1318 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1318 6019
nickjillings@1318 6020 // If a hook was provided get the computed value from there
nickjillings@1318 6021 if ( hooks && "get" in hooks ) {
nickjillings@1318 6022 val = hooks.get( elem, true, extra );
nickjillings@1318 6023 }
nickjillings@1318 6024
nickjillings@1318 6025 // Otherwise, if a way to get the computed value exists, use that
nickjillings@1318 6026 if ( val === undefined ) {
nickjillings@1318 6027 val = curCSS( elem, name, styles );
nickjillings@1318 6028 }
nickjillings@1318 6029
nickjillings@1318 6030 // Convert "normal" to computed value
nickjillings@1318 6031 if ( val === "normal" && name in cssNormalTransform ) {
nickjillings@1318 6032 val = cssNormalTransform[ name ];
nickjillings@1318 6033 }
nickjillings@1318 6034
nickjillings@1318 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nickjillings@1318 6036 if ( extra === "" || extra ) {
nickjillings@1318 6037 num = parseFloat( val );
nickjillings@1318 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nickjillings@1318 6039 }
nickjillings@1318 6040 return val;
nickjillings@1318 6041 }
nickjillings@1318 6042 });
nickjillings@1318 6043
nickjillings@1318 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nickjillings@1318 6045 jQuery.cssHooks[ name ] = {
nickjillings@1318 6046 get: function( elem, computed, extra ) {
nickjillings@1318 6047 if ( computed ) {
nickjillings@1318 6048
nickjillings@1318 6049 // Certain elements can have dimension info if we invisibly show them
nickjillings@1318 6050 // but it must have a current display style that would benefit
nickjillings@1318 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nickjillings@1318 6052 jQuery.swap( elem, cssShow, function() {
nickjillings@1318 6053 return getWidthOrHeight( elem, name, extra );
nickjillings@1318 6054 }) :
nickjillings@1318 6055 getWidthOrHeight( elem, name, extra );
nickjillings@1318 6056 }
nickjillings@1318 6057 },
nickjillings@1318 6058
nickjillings@1318 6059 set: function( elem, value, extra ) {
nickjillings@1318 6060 var styles = extra && getStyles( elem );
nickjillings@1318 6061 return setPositiveNumber( elem, value, extra ?
nickjillings@1318 6062 augmentWidthOrHeight(
nickjillings@1318 6063 elem,
nickjillings@1318 6064 name,
nickjillings@1318 6065 extra,
nickjillings@1318 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nickjillings@1318 6067 styles
nickjillings@1318 6068 ) : 0
nickjillings@1318 6069 );
nickjillings@1318 6070 }
nickjillings@1318 6071 };
nickjillings@1318 6072 });
nickjillings@1318 6073
nickjillings@1318 6074 // Support: Android 2.3
nickjillings@1318 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nickjillings@1318 6076 function( elem, computed ) {
nickjillings@1318 6077 if ( computed ) {
nickjillings@1318 6078 return jQuery.swap( elem, { "display": "inline-block" },
nickjillings@1318 6079 curCSS, [ elem, "marginRight" ] );
nickjillings@1318 6080 }
nickjillings@1318 6081 }
nickjillings@1318 6082 );
nickjillings@1318 6083
nickjillings@1318 6084 // These hooks are used by animate to expand properties
nickjillings@1318 6085 jQuery.each({
nickjillings@1318 6086 margin: "",
nickjillings@1318 6087 padding: "",
nickjillings@1318 6088 border: "Width"
nickjillings@1318 6089 }, function( prefix, suffix ) {
nickjillings@1318 6090 jQuery.cssHooks[ prefix + suffix ] = {
nickjillings@1318 6091 expand: function( value ) {
nickjillings@1318 6092 var i = 0,
nickjillings@1318 6093 expanded = {},
nickjillings@1318 6094
nickjillings@1318 6095 // Assumes a single number if not a string
nickjillings@1318 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nickjillings@1318 6097
nickjillings@1318 6098 for ( ; i < 4; i++ ) {
nickjillings@1318 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nickjillings@1318 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nickjillings@1318 6101 }
nickjillings@1318 6102
nickjillings@1318 6103 return expanded;
nickjillings@1318 6104 }
nickjillings@1318 6105 };
nickjillings@1318 6106
nickjillings@1318 6107 if ( !rmargin.test( prefix ) ) {
nickjillings@1318 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nickjillings@1318 6109 }
nickjillings@1318 6110 });
nickjillings@1318 6111
nickjillings@1318 6112 jQuery.fn.extend({
nickjillings@1318 6113 css: function( name, value ) {
nickjillings@1318 6114 return access( this, function( elem, name, value ) {
nickjillings@1318 6115 var styles, len,
nickjillings@1318 6116 map = {},
nickjillings@1318 6117 i = 0;
nickjillings@1318 6118
nickjillings@1318 6119 if ( jQuery.isArray( name ) ) {
nickjillings@1318 6120 styles = getStyles( elem );
nickjillings@1318 6121 len = name.length;
nickjillings@1318 6122
nickjillings@1318 6123 for ( ; i < len; i++ ) {
nickjillings@1318 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nickjillings@1318 6125 }
nickjillings@1318 6126
nickjillings@1318 6127 return map;
nickjillings@1318 6128 }
nickjillings@1318 6129
nickjillings@1318 6130 return value !== undefined ?
nickjillings@1318 6131 jQuery.style( elem, name, value ) :
nickjillings@1318 6132 jQuery.css( elem, name );
nickjillings@1318 6133 }, name, value, arguments.length > 1 );
nickjillings@1318 6134 },
nickjillings@1318 6135 show: function() {
nickjillings@1318 6136 return showHide( this, true );
nickjillings@1318 6137 },
nickjillings@1318 6138 hide: function() {
nickjillings@1318 6139 return showHide( this );
nickjillings@1318 6140 },
nickjillings@1318 6141 toggle: function( state ) {
nickjillings@1318 6142 if ( typeof state === "boolean" ) {
nickjillings@1318 6143 return state ? this.show() : this.hide();
nickjillings@1318 6144 }
nickjillings@1318 6145
nickjillings@1318 6146 return this.each(function() {
nickjillings@1318 6147 if ( isHidden( this ) ) {
nickjillings@1318 6148 jQuery( this ).show();
nickjillings@1318 6149 } else {
nickjillings@1318 6150 jQuery( this ).hide();
nickjillings@1318 6151 }
nickjillings@1318 6152 });
nickjillings@1318 6153 }
nickjillings@1318 6154 });
nickjillings@1318 6155
nickjillings@1318 6156
nickjillings@1318 6157 function Tween( elem, options, prop, end, easing ) {
nickjillings@1318 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nickjillings@1318 6159 }
nickjillings@1318 6160 jQuery.Tween = Tween;
nickjillings@1318 6161
nickjillings@1318 6162 Tween.prototype = {
nickjillings@1318 6163 constructor: Tween,
nickjillings@1318 6164 init: function( elem, options, prop, end, easing, unit ) {
nickjillings@1318 6165 this.elem = elem;
nickjillings@1318 6166 this.prop = prop;
nickjillings@1318 6167 this.easing = easing || "swing";
nickjillings@1318 6168 this.options = options;
nickjillings@1318 6169 this.start = this.now = this.cur();
nickjillings@1318 6170 this.end = end;
nickjillings@1318 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nickjillings@1318 6172 },
nickjillings@1318 6173 cur: function() {
nickjillings@1318 6174 var hooks = Tween.propHooks[ this.prop ];
nickjillings@1318 6175
nickjillings@1318 6176 return hooks && hooks.get ?
nickjillings@1318 6177 hooks.get( this ) :
nickjillings@1318 6178 Tween.propHooks._default.get( this );
nickjillings@1318 6179 },
nickjillings@1318 6180 run: function( percent ) {
nickjillings@1318 6181 var eased,
nickjillings@1318 6182 hooks = Tween.propHooks[ this.prop ];
nickjillings@1318 6183
nickjillings@1318 6184 if ( this.options.duration ) {
nickjillings@1318 6185 this.pos = eased = jQuery.easing[ this.easing ](
nickjillings@1318 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nickjillings@1318 6187 );
nickjillings@1318 6188 } else {
nickjillings@1318 6189 this.pos = eased = percent;
nickjillings@1318 6190 }
nickjillings@1318 6191 this.now = ( this.end - this.start ) * eased + this.start;
nickjillings@1318 6192
nickjillings@1318 6193 if ( this.options.step ) {
nickjillings@1318 6194 this.options.step.call( this.elem, this.now, this );
nickjillings@1318 6195 }
nickjillings@1318 6196
nickjillings@1318 6197 if ( hooks && hooks.set ) {
nickjillings@1318 6198 hooks.set( this );
nickjillings@1318 6199 } else {
nickjillings@1318 6200 Tween.propHooks._default.set( this );
nickjillings@1318 6201 }
nickjillings@1318 6202 return this;
nickjillings@1318 6203 }
nickjillings@1318 6204 };
nickjillings@1318 6205
nickjillings@1318 6206 Tween.prototype.init.prototype = Tween.prototype;
nickjillings@1318 6207
nickjillings@1318 6208 Tween.propHooks = {
nickjillings@1318 6209 _default: {
nickjillings@1318 6210 get: function( tween ) {
nickjillings@1318 6211 var result;
nickjillings@1318 6212
nickjillings@1318 6213 if ( tween.elem[ tween.prop ] != null &&
nickjillings@1318 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nickjillings@1318 6215 return tween.elem[ tween.prop ];
nickjillings@1318 6216 }
nickjillings@1318 6217
nickjillings@1318 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nickjillings@1318 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nickjillings@1318 6220 // Simple values such as "10px" are parsed to Float;
nickjillings@1318 6221 // complex values such as "rotate(1rad)" are returned as-is.
nickjillings@1318 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nickjillings@1318 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nickjillings@1318 6224 return !result || result === "auto" ? 0 : result;
nickjillings@1318 6225 },
nickjillings@1318 6226 set: function( tween ) {
nickjillings@1318 6227 // Use step hook for back compat.
nickjillings@1318 6228 // Use cssHook if its there.
nickjillings@1318 6229 // Use .style if available and use plain properties where available.
nickjillings@1318 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nickjillings@1318 6231 jQuery.fx.step[ tween.prop ]( tween );
nickjillings@1318 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nickjillings@1318 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nickjillings@1318 6234 } else {
nickjillings@1318 6235 tween.elem[ tween.prop ] = tween.now;
nickjillings@1318 6236 }
nickjillings@1318 6237 }
nickjillings@1318 6238 }
nickjillings@1318 6239 };
nickjillings@1318 6240
nickjillings@1318 6241 // Support: IE9
nickjillings@1318 6242 // Panic based approach to setting things on disconnected nodes
nickjillings@1318 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nickjillings@1318 6244 set: function( tween ) {
nickjillings@1318 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nickjillings@1318 6246 tween.elem[ tween.prop ] = tween.now;
nickjillings@1318 6247 }
nickjillings@1318 6248 }
nickjillings@1318 6249 };
nickjillings@1318 6250
nickjillings@1318 6251 jQuery.easing = {
nickjillings@1318 6252 linear: function( p ) {
nickjillings@1318 6253 return p;
nickjillings@1318 6254 },
nickjillings@1318 6255 swing: function( p ) {
nickjillings@1318 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nickjillings@1318 6257 }
nickjillings@1318 6258 };
nickjillings@1318 6259
nickjillings@1318 6260 jQuery.fx = Tween.prototype.init;
nickjillings@1318 6261
nickjillings@1318 6262 // Back Compat <1.8 extension point
nickjillings@1318 6263 jQuery.fx.step = {};
nickjillings@1318 6264
nickjillings@1318 6265
nickjillings@1318 6266
nickjillings@1318 6267
nickjillings@1318 6268 var
nickjillings@1318 6269 fxNow, timerId,
nickjillings@1318 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nickjillings@1318 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nickjillings@1318 6272 rrun = /queueHooks$/,
nickjillings@1318 6273 animationPrefilters = [ defaultPrefilter ],
nickjillings@1318 6274 tweeners = {
nickjillings@1318 6275 "*": [ function( prop, value ) {
nickjillings@1318 6276 var tween = this.createTween( prop, value ),
nickjillings@1318 6277 target = tween.cur(),
nickjillings@1318 6278 parts = rfxnum.exec( value ),
nickjillings@1318 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nickjillings@1318 6280
nickjillings@1318 6281 // Starting value computation is required for potential unit mismatches
nickjillings@1318 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nickjillings@1318 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nickjillings@1318 6284 scale = 1,
nickjillings@1318 6285 maxIterations = 20;
nickjillings@1318 6286
nickjillings@1318 6287 if ( start && start[ 3 ] !== unit ) {
nickjillings@1318 6288 // Trust units reported by jQuery.css
nickjillings@1318 6289 unit = unit || start[ 3 ];
nickjillings@1318 6290
nickjillings@1318 6291 // Make sure we update the tween properties later on
nickjillings@1318 6292 parts = parts || [];
nickjillings@1318 6293
nickjillings@1318 6294 // Iteratively approximate from a nonzero starting point
nickjillings@1318 6295 start = +target || 1;
nickjillings@1318 6296
nickjillings@1318 6297 do {
nickjillings@1318 6298 // If previous iteration zeroed out, double until we get *something*.
nickjillings@1318 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nickjillings@1318 6300 scale = scale || ".5";
nickjillings@1318 6301
nickjillings@1318 6302 // Adjust and apply
nickjillings@1318 6303 start = start / scale;
nickjillings@1318 6304 jQuery.style( tween.elem, prop, start + unit );
nickjillings@1318 6305
nickjillings@1318 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nickjillings@1318 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nickjillings@1318 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nickjillings@1318 6309 }
nickjillings@1318 6310
nickjillings@1318 6311 // Update tween properties
nickjillings@1318 6312 if ( parts ) {
nickjillings@1318 6313 start = tween.start = +start || +target || 0;
nickjillings@1318 6314 tween.unit = unit;
nickjillings@1318 6315 // If a +=/-= token was provided, we're doing a relative animation
nickjillings@1318 6316 tween.end = parts[ 1 ] ?
nickjillings@1318 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nickjillings@1318 6318 +parts[ 2 ];
nickjillings@1318 6319 }
nickjillings@1318 6320
nickjillings@1318 6321 return tween;
nickjillings@1318 6322 } ]
nickjillings@1318 6323 };
nickjillings@1318 6324
nickjillings@1318 6325 // Animations created synchronously will run synchronously
nickjillings@1318 6326 function createFxNow() {
nickjillings@1318 6327 setTimeout(function() {
nickjillings@1318 6328 fxNow = undefined;
nickjillings@1318 6329 });
nickjillings@1318 6330 return ( fxNow = jQuery.now() );
nickjillings@1318 6331 }
nickjillings@1318 6332
nickjillings@1318 6333 // Generate parameters to create a standard animation
nickjillings@1318 6334 function genFx( type, includeWidth ) {
nickjillings@1318 6335 var which,
nickjillings@1318 6336 i = 0,
nickjillings@1318 6337 attrs = { height: type };
nickjillings@1318 6338
nickjillings@1318 6339 // If we include width, step value is 1 to do all cssExpand values,
nickjillings@1318 6340 // otherwise step value is 2 to skip over Left and Right
nickjillings@1318 6341 includeWidth = includeWidth ? 1 : 0;
nickjillings@1318 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nickjillings@1318 6343 which = cssExpand[ i ];
nickjillings@1318 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nickjillings@1318 6345 }
nickjillings@1318 6346
nickjillings@1318 6347 if ( includeWidth ) {
nickjillings@1318 6348 attrs.opacity = attrs.width = type;
nickjillings@1318 6349 }
nickjillings@1318 6350
nickjillings@1318 6351 return attrs;
nickjillings@1318 6352 }
nickjillings@1318 6353
nickjillings@1318 6354 function createTween( value, prop, animation ) {
nickjillings@1318 6355 var tween,
nickjillings@1318 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nickjillings@1318 6357 index = 0,
nickjillings@1318 6358 length = collection.length;
nickjillings@1318 6359 for ( ; index < length; index++ ) {
nickjillings@1318 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nickjillings@1318 6361
nickjillings@1318 6362 // We're done with this property
nickjillings@1318 6363 return tween;
nickjillings@1318 6364 }
nickjillings@1318 6365 }
nickjillings@1318 6366 }
nickjillings@1318 6367
nickjillings@1318 6368 function defaultPrefilter( elem, props, opts ) {
nickjillings@1318 6369 /* jshint validthis: true */
nickjillings@1318 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nickjillings@1318 6371 anim = this,
nickjillings@1318 6372 orig = {},
nickjillings@1318 6373 style = elem.style,
nickjillings@1318 6374 hidden = elem.nodeType && isHidden( elem ),
nickjillings@1318 6375 dataShow = data_priv.get( elem, "fxshow" );
nickjillings@1318 6376
nickjillings@1318 6377 // Handle queue: false promises
nickjillings@1318 6378 if ( !opts.queue ) {
nickjillings@1318 6379 hooks = jQuery._queueHooks( elem, "fx" );
nickjillings@1318 6380 if ( hooks.unqueued == null ) {
nickjillings@1318 6381 hooks.unqueued = 0;
nickjillings@1318 6382 oldfire = hooks.empty.fire;
nickjillings@1318 6383 hooks.empty.fire = function() {
nickjillings@1318 6384 if ( !hooks.unqueued ) {
nickjillings@1318 6385 oldfire();
nickjillings@1318 6386 }
nickjillings@1318 6387 };
nickjillings@1318 6388 }
nickjillings@1318 6389 hooks.unqueued++;
nickjillings@1318 6390
nickjillings@1318 6391 anim.always(function() {
nickjillings@1318 6392 // Ensure the complete handler is called before this completes
nickjillings@1318 6393 anim.always(function() {
nickjillings@1318 6394 hooks.unqueued--;
nickjillings@1318 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nickjillings@1318 6396 hooks.empty.fire();
nickjillings@1318 6397 }
nickjillings@1318 6398 });
nickjillings@1318 6399 });
nickjillings@1318 6400 }
nickjillings@1318 6401
nickjillings@1318 6402 // Height/width overflow pass
nickjillings@1318 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nickjillings@1318 6404 // Make sure that nothing sneaks out
nickjillings@1318 6405 // Record all 3 overflow attributes because IE9-10 do not
nickjillings@1318 6406 // change the overflow attribute when overflowX and
nickjillings@1318 6407 // overflowY are set to the same value
nickjillings@1318 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nickjillings@1318 6409
nickjillings@1318 6410 // Set display property to inline-block for height/width
nickjillings@1318 6411 // animations on inline elements that are having width/height animated
nickjillings@1318 6412 display = jQuery.css( elem, "display" );
nickjillings@1318 6413
nickjillings@1318 6414 // Test default display if display is currently "none"
nickjillings@1318 6415 checkDisplay = display === "none" ?
nickjillings@1318 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nickjillings@1318 6417
nickjillings@1318 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nickjillings@1318 6419 style.display = "inline-block";
nickjillings@1318 6420 }
nickjillings@1318 6421 }
nickjillings@1318 6422
nickjillings@1318 6423 if ( opts.overflow ) {
nickjillings@1318 6424 style.overflow = "hidden";
nickjillings@1318 6425 anim.always(function() {
nickjillings@1318 6426 style.overflow = opts.overflow[ 0 ];
nickjillings@1318 6427 style.overflowX = opts.overflow[ 1 ];
nickjillings@1318 6428 style.overflowY = opts.overflow[ 2 ];
nickjillings@1318 6429 });
nickjillings@1318 6430 }
nickjillings@1318 6431
nickjillings@1318 6432 // show/hide pass
nickjillings@1318 6433 for ( prop in props ) {
nickjillings@1318 6434 value = props[ prop ];
nickjillings@1318 6435 if ( rfxtypes.exec( value ) ) {
nickjillings@1318 6436 delete props[ prop ];
nickjillings@1318 6437 toggle = toggle || value === "toggle";
nickjillings@1318 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nickjillings@1318 6439
nickjillings@1318 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@1318 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nickjillings@1318 6442 hidden = true;
nickjillings@1318 6443 } else {
nickjillings@1318 6444 continue;
nickjillings@1318 6445 }
nickjillings@1318 6446 }
nickjillings@1318 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nickjillings@1318 6448
nickjillings@1318 6449 // Any non-fx value stops us from restoring the original display value
nickjillings@1318 6450 } else {
nickjillings@1318 6451 display = undefined;
nickjillings@1318 6452 }
nickjillings@1318 6453 }
nickjillings@1318 6454
nickjillings@1318 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nickjillings@1318 6456 if ( dataShow ) {
nickjillings@1318 6457 if ( "hidden" in dataShow ) {
nickjillings@1318 6458 hidden = dataShow.hidden;
nickjillings@1318 6459 }
nickjillings@1318 6460 } else {
nickjillings@1318 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nickjillings@1318 6462 }
nickjillings@1318 6463
nickjillings@1318 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nickjillings@1318 6465 if ( toggle ) {
nickjillings@1318 6466 dataShow.hidden = !hidden;
nickjillings@1318 6467 }
nickjillings@1318 6468 if ( hidden ) {
nickjillings@1318 6469 jQuery( elem ).show();
nickjillings@1318 6470 } else {
nickjillings@1318 6471 anim.done(function() {
nickjillings@1318 6472 jQuery( elem ).hide();
nickjillings@1318 6473 });
nickjillings@1318 6474 }
nickjillings@1318 6475 anim.done(function() {
nickjillings@1318 6476 var prop;
nickjillings@1318 6477
nickjillings@1318 6478 data_priv.remove( elem, "fxshow" );
nickjillings@1318 6479 for ( prop in orig ) {
nickjillings@1318 6480 jQuery.style( elem, prop, orig[ prop ] );
nickjillings@1318 6481 }
nickjillings@1318 6482 });
nickjillings@1318 6483 for ( prop in orig ) {
nickjillings@1318 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nickjillings@1318 6485
nickjillings@1318 6486 if ( !( prop in dataShow ) ) {
nickjillings@1318 6487 dataShow[ prop ] = tween.start;
nickjillings@1318 6488 if ( hidden ) {
nickjillings@1318 6489 tween.end = tween.start;
nickjillings@1318 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nickjillings@1318 6491 }
nickjillings@1318 6492 }
nickjillings@1318 6493 }
nickjillings@1318 6494
nickjillings@1318 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nickjillings@1318 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nickjillings@1318 6497 style.display = display;
nickjillings@1318 6498 }
nickjillings@1318 6499 }
nickjillings@1318 6500
nickjillings@1318 6501 function propFilter( props, specialEasing ) {
nickjillings@1318 6502 var index, name, easing, value, hooks;
nickjillings@1318 6503
nickjillings@1318 6504 // camelCase, specialEasing and expand cssHook pass
nickjillings@1318 6505 for ( index in props ) {
nickjillings@1318 6506 name = jQuery.camelCase( index );
nickjillings@1318 6507 easing = specialEasing[ name ];
nickjillings@1318 6508 value = props[ index ];
nickjillings@1318 6509 if ( jQuery.isArray( value ) ) {
nickjillings@1318 6510 easing = value[ 1 ];
nickjillings@1318 6511 value = props[ index ] = value[ 0 ];
nickjillings@1318 6512 }
nickjillings@1318 6513
nickjillings@1318 6514 if ( index !== name ) {
nickjillings@1318 6515 props[ name ] = value;
nickjillings@1318 6516 delete props[ index ];
nickjillings@1318 6517 }
nickjillings@1318 6518
nickjillings@1318 6519 hooks = jQuery.cssHooks[ name ];
nickjillings@1318 6520 if ( hooks && "expand" in hooks ) {
nickjillings@1318 6521 value = hooks.expand( value );
nickjillings@1318 6522 delete props[ name ];
nickjillings@1318 6523
nickjillings@1318 6524 // Not quite $.extend, this won't overwrite existing keys.
nickjillings@1318 6525 // Reusing 'index' because we have the correct "name"
nickjillings@1318 6526 for ( index in value ) {
nickjillings@1318 6527 if ( !( index in props ) ) {
nickjillings@1318 6528 props[ index ] = value[ index ];
nickjillings@1318 6529 specialEasing[ index ] = easing;
nickjillings@1318 6530 }
nickjillings@1318 6531 }
nickjillings@1318 6532 } else {
nickjillings@1318 6533 specialEasing[ name ] = easing;
nickjillings@1318 6534 }
nickjillings@1318 6535 }
nickjillings@1318 6536 }
nickjillings@1318 6537
nickjillings@1318 6538 function Animation( elem, properties, options ) {
nickjillings@1318 6539 var result,
nickjillings@1318 6540 stopped,
nickjillings@1318 6541 index = 0,
nickjillings@1318 6542 length = animationPrefilters.length,
nickjillings@1318 6543 deferred = jQuery.Deferred().always( function() {
nickjillings@1318 6544 // Don't match elem in the :animated selector
nickjillings@1318 6545 delete tick.elem;
nickjillings@1318 6546 }),
nickjillings@1318 6547 tick = function() {
nickjillings@1318 6548 if ( stopped ) {
nickjillings@1318 6549 return false;
nickjillings@1318 6550 }
nickjillings@1318 6551 var currentTime = fxNow || createFxNow(),
nickjillings@1318 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nickjillings@1318 6553 // Support: Android 2.3
nickjillings@1318 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nickjillings@1318 6555 temp = remaining / animation.duration || 0,
nickjillings@1318 6556 percent = 1 - temp,
nickjillings@1318 6557 index = 0,
nickjillings@1318 6558 length = animation.tweens.length;
nickjillings@1318 6559
nickjillings@1318 6560 for ( ; index < length ; index++ ) {
nickjillings@1318 6561 animation.tweens[ index ].run( percent );
nickjillings@1318 6562 }
nickjillings@1318 6563
nickjillings@1318 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nickjillings@1318 6565
nickjillings@1318 6566 if ( percent < 1 && length ) {
nickjillings@1318 6567 return remaining;
nickjillings@1318 6568 } else {
nickjillings@1318 6569 deferred.resolveWith( elem, [ animation ] );
nickjillings@1318 6570 return false;
nickjillings@1318 6571 }
nickjillings@1318 6572 },
nickjillings@1318 6573 animation = deferred.promise({
nickjillings@1318 6574 elem: elem,
nickjillings@1318 6575 props: jQuery.extend( {}, properties ),
nickjillings@1318 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nickjillings@1318 6577 originalProperties: properties,
nickjillings@1318 6578 originalOptions: options,
nickjillings@1318 6579 startTime: fxNow || createFxNow(),
nickjillings@1318 6580 duration: options.duration,
nickjillings@1318 6581 tweens: [],
nickjillings@1318 6582 createTween: function( prop, end ) {
nickjillings@1318 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nickjillings@1318 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nickjillings@1318 6585 animation.tweens.push( tween );
nickjillings@1318 6586 return tween;
nickjillings@1318 6587 },
nickjillings@1318 6588 stop: function( gotoEnd ) {
nickjillings@1318 6589 var index = 0,
nickjillings@1318 6590 // If we are going to the end, we want to run all the tweens
nickjillings@1318 6591 // otherwise we skip this part
nickjillings@1318 6592 length = gotoEnd ? animation.tweens.length : 0;
nickjillings@1318 6593 if ( stopped ) {
nickjillings@1318 6594 return this;
nickjillings@1318 6595 }
nickjillings@1318 6596 stopped = true;
nickjillings@1318 6597 for ( ; index < length ; index++ ) {
nickjillings@1318 6598 animation.tweens[ index ].run( 1 );
nickjillings@1318 6599 }
nickjillings@1318 6600
nickjillings@1318 6601 // Resolve when we played the last frame; otherwise, reject
nickjillings@1318 6602 if ( gotoEnd ) {
nickjillings@1318 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nickjillings@1318 6604 } else {
nickjillings@1318 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nickjillings@1318 6606 }
nickjillings@1318 6607 return this;
nickjillings@1318 6608 }
nickjillings@1318 6609 }),
nickjillings@1318 6610 props = animation.props;
nickjillings@1318 6611
nickjillings@1318 6612 propFilter( props, animation.opts.specialEasing );
nickjillings@1318 6613
nickjillings@1318 6614 for ( ; index < length ; index++ ) {
nickjillings@1318 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nickjillings@1318 6616 if ( result ) {
nickjillings@1318 6617 return result;
nickjillings@1318 6618 }
nickjillings@1318 6619 }
nickjillings@1318 6620
nickjillings@1318 6621 jQuery.map( props, createTween, animation );
nickjillings@1318 6622
nickjillings@1318 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nickjillings@1318 6624 animation.opts.start.call( elem, animation );
nickjillings@1318 6625 }
nickjillings@1318 6626
nickjillings@1318 6627 jQuery.fx.timer(
nickjillings@1318 6628 jQuery.extend( tick, {
nickjillings@1318 6629 elem: elem,
nickjillings@1318 6630 anim: animation,
nickjillings@1318 6631 queue: animation.opts.queue
nickjillings@1318 6632 })
nickjillings@1318 6633 );
nickjillings@1318 6634
nickjillings@1318 6635 // attach callbacks from options
nickjillings@1318 6636 return animation.progress( animation.opts.progress )
nickjillings@1318 6637 .done( animation.opts.done, animation.opts.complete )
nickjillings@1318 6638 .fail( animation.opts.fail )
nickjillings@1318 6639 .always( animation.opts.always );
nickjillings@1318 6640 }
nickjillings@1318 6641
nickjillings@1318 6642 jQuery.Animation = jQuery.extend( Animation, {
nickjillings@1318 6643
nickjillings@1318 6644 tweener: function( props, callback ) {
nickjillings@1318 6645 if ( jQuery.isFunction( props ) ) {
nickjillings@1318 6646 callback = props;
nickjillings@1318 6647 props = [ "*" ];
nickjillings@1318 6648 } else {
nickjillings@1318 6649 props = props.split(" ");
nickjillings@1318 6650 }
nickjillings@1318 6651
nickjillings@1318 6652 var prop,
nickjillings@1318 6653 index = 0,
nickjillings@1318 6654 length = props.length;
nickjillings@1318 6655
nickjillings@1318 6656 for ( ; index < length ; index++ ) {
nickjillings@1318 6657 prop = props[ index ];
nickjillings@1318 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nickjillings@1318 6659 tweeners[ prop ].unshift( callback );
nickjillings@1318 6660 }
nickjillings@1318 6661 },
nickjillings@1318 6662
nickjillings@1318 6663 prefilter: function( callback, prepend ) {
nickjillings@1318 6664 if ( prepend ) {
nickjillings@1318 6665 animationPrefilters.unshift( callback );
nickjillings@1318 6666 } else {
nickjillings@1318 6667 animationPrefilters.push( callback );
nickjillings@1318 6668 }
nickjillings@1318 6669 }
nickjillings@1318 6670 });
nickjillings@1318 6671
nickjillings@1318 6672 jQuery.speed = function( speed, easing, fn ) {
nickjillings@1318 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nickjillings@1318 6674 complete: fn || !fn && easing ||
nickjillings@1318 6675 jQuery.isFunction( speed ) && speed,
nickjillings@1318 6676 duration: speed,
nickjillings@1318 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nickjillings@1318 6678 };
nickjillings@1318 6679
nickjillings@1318 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nickjillings@1318 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nickjillings@1318 6682
nickjillings@1318 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nickjillings@1318 6684 if ( opt.queue == null || opt.queue === true ) {
nickjillings@1318 6685 opt.queue = "fx";
nickjillings@1318 6686 }
nickjillings@1318 6687
nickjillings@1318 6688 // Queueing
nickjillings@1318 6689 opt.old = opt.complete;
nickjillings@1318 6690
nickjillings@1318 6691 opt.complete = function() {
nickjillings@1318 6692 if ( jQuery.isFunction( opt.old ) ) {
nickjillings@1318 6693 opt.old.call( this );
nickjillings@1318 6694 }
nickjillings@1318 6695
nickjillings@1318 6696 if ( opt.queue ) {
nickjillings@1318 6697 jQuery.dequeue( this, opt.queue );
nickjillings@1318 6698 }
nickjillings@1318 6699 };
nickjillings@1318 6700
nickjillings@1318 6701 return opt;
nickjillings@1318 6702 };
nickjillings@1318 6703
nickjillings@1318 6704 jQuery.fn.extend({
nickjillings@1318 6705 fadeTo: function( speed, to, easing, callback ) {
nickjillings@1318 6706
nickjillings@1318 6707 // Show any hidden elements after setting opacity to 0
nickjillings@1318 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nickjillings@1318 6709
nickjillings@1318 6710 // Animate to the value specified
nickjillings@1318 6711 .end().animate({ opacity: to }, speed, easing, callback );
nickjillings@1318 6712 },
nickjillings@1318 6713 animate: function( prop, speed, easing, callback ) {
nickjillings@1318 6714 var empty = jQuery.isEmptyObject( prop ),
nickjillings@1318 6715 optall = jQuery.speed( speed, easing, callback ),
nickjillings@1318 6716 doAnimation = function() {
nickjillings@1318 6717 // Operate on a copy of prop so per-property easing won't be lost
nickjillings@1318 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nickjillings@1318 6719
nickjillings@1318 6720 // Empty animations, or finishing resolves immediately
nickjillings@1318 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nickjillings@1318 6722 anim.stop( true );
nickjillings@1318 6723 }
nickjillings@1318 6724 };
nickjillings@1318 6725 doAnimation.finish = doAnimation;
nickjillings@1318 6726
nickjillings@1318 6727 return empty || optall.queue === false ?
nickjillings@1318 6728 this.each( doAnimation ) :
nickjillings@1318 6729 this.queue( optall.queue, doAnimation );
nickjillings@1318 6730 },
nickjillings@1318 6731 stop: function( type, clearQueue, gotoEnd ) {
nickjillings@1318 6732 var stopQueue = function( hooks ) {
nickjillings@1318 6733 var stop = hooks.stop;
nickjillings@1318 6734 delete hooks.stop;
nickjillings@1318 6735 stop( gotoEnd );
nickjillings@1318 6736 };
nickjillings@1318 6737
nickjillings@1318 6738 if ( typeof type !== "string" ) {
nickjillings@1318 6739 gotoEnd = clearQueue;
nickjillings@1318 6740 clearQueue = type;
nickjillings@1318 6741 type = undefined;
nickjillings@1318 6742 }
nickjillings@1318 6743 if ( clearQueue && type !== false ) {
nickjillings@1318 6744 this.queue( type || "fx", [] );
nickjillings@1318 6745 }
nickjillings@1318 6746
nickjillings@1318 6747 return this.each(function() {
nickjillings@1318 6748 var dequeue = true,
nickjillings@1318 6749 index = type != null && type + "queueHooks",
nickjillings@1318 6750 timers = jQuery.timers,
nickjillings@1318 6751 data = data_priv.get( this );
nickjillings@1318 6752
nickjillings@1318 6753 if ( index ) {
nickjillings@1318 6754 if ( data[ index ] && data[ index ].stop ) {
nickjillings@1318 6755 stopQueue( data[ index ] );
nickjillings@1318 6756 }
nickjillings@1318 6757 } else {
nickjillings@1318 6758 for ( index in data ) {
nickjillings@1318 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nickjillings@1318 6760 stopQueue( data[ index ] );
nickjillings@1318 6761 }
nickjillings@1318 6762 }
nickjillings@1318 6763 }
nickjillings@1318 6764
nickjillings@1318 6765 for ( index = timers.length; index--; ) {
nickjillings@1318 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nickjillings@1318 6767 timers[ index ].anim.stop( gotoEnd );
nickjillings@1318 6768 dequeue = false;
nickjillings@1318 6769 timers.splice( index, 1 );
nickjillings@1318 6770 }
nickjillings@1318 6771 }
nickjillings@1318 6772
nickjillings@1318 6773 // Start the next in the queue if the last step wasn't forced.
nickjillings@1318 6774 // Timers currently will call their complete callbacks, which
nickjillings@1318 6775 // will dequeue but only if they were gotoEnd.
nickjillings@1318 6776 if ( dequeue || !gotoEnd ) {
nickjillings@1318 6777 jQuery.dequeue( this, type );
nickjillings@1318 6778 }
nickjillings@1318 6779 });
nickjillings@1318 6780 },
nickjillings@1318 6781 finish: function( type ) {
nickjillings@1318 6782 if ( type !== false ) {
nickjillings@1318 6783 type = type || "fx";
nickjillings@1318 6784 }
nickjillings@1318 6785 return this.each(function() {
nickjillings@1318 6786 var index,
nickjillings@1318 6787 data = data_priv.get( this ),
nickjillings@1318 6788 queue = data[ type + "queue" ],
nickjillings@1318 6789 hooks = data[ type + "queueHooks" ],
nickjillings@1318 6790 timers = jQuery.timers,
nickjillings@1318 6791 length = queue ? queue.length : 0;
nickjillings@1318 6792
nickjillings@1318 6793 // Enable finishing flag on private data
nickjillings@1318 6794 data.finish = true;
nickjillings@1318 6795
nickjillings@1318 6796 // Empty the queue first
nickjillings@1318 6797 jQuery.queue( this, type, [] );
nickjillings@1318 6798
nickjillings@1318 6799 if ( hooks && hooks.stop ) {
nickjillings@1318 6800 hooks.stop.call( this, true );
nickjillings@1318 6801 }
nickjillings@1318 6802
nickjillings@1318 6803 // Look for any active animations, and finish them
nickjillings@1318 6804 for ( index = timers.length; index--; ) {
nickjillings@1318 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nickjillings@1318 6806 timers[ index ].anim.stop( true );
nickjillings@1318 6807 timers.splice( index, 1 );
nickjillings@1318 6808 }
nickjillings@1318 6809 }
nickjillings@1318 6810
nickjillings@1318 6811 // Look for any animations in the old queue and finish them
nickjillings@1318 6812 for ( index = 0; index < length; index++ ) {
nickjillings@1318 6813 if ( queue[ index ] && queue[ index ].finish ) {
nickjillings@1318 6814 queue[ index ].finish.call( this );
nickjillings@1318 6815 }
nickjillings@1318 6816 }
nickjillings@1318 6817
nickjillings@1318 6818 // Turn off finishing flag
nickjillings@1318 6819 delete data.finish;
nickjillings@1318 6820 });
nickjillings@1318 6821 }
nickjillings@1318 6822 });
nickjillings@1318 6823
nickjillings@1318 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nickjillings@1318 6825 var cssFn = jQuery.fn[ name ];
nickjillings@1318 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1318 6827 return speed == null || typeof speed === "boolean" ?
nickjillings@1318 6828 cssFn.apply( this, arguments ) :
nickjillings@1318 6829 this.animate( genFx( name, true ), speed, easing, callback );
nickjillings@1318 6830 };
nickjillings@1318 6831 });
nickjillings@1318 6832
nickjillings@1318 6833 // Generate shortcuts for custom animations
nickjillings@1318 6834 jQuery.each({
nickjillings@1318 6835 slideDown: genFx("show"),
nickjillings@1318 6836 slideUp: genFx("hide"),
nickjillings@1318 6837 slideToggle: genFx("toggle"),
nickjillings@1318 6838 fadeIn: { opacity: "show" },
nickjillings@1318 6839 fadeOut: { opacity: "hide" },
nickjillings@1318 6840 fadeToggle: { opacity: "toggle" }
nickjillings@1318 6841 }, function( name, props ) {
nickjillings@1318 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1318 6843 return this.animate( props, speed, easing, callback );
nickjillings@1318 6844 };
nickjillings@1318 6845 });
nickjillings@1318 6846
nickjillings@1318 6847 jQuery.timers = [];
nickjillings@1318 6848 jQuery.fx.tick = function() {
nickjillings@1318 6849 var timer,
nickjillings@1318 6850 i = 0,
nickjillings@1318 6851 timers = jQuery.timers;
nickjillings@1318 6852
nickjillings@1318 6853 fxNow = jQuery.now();
nickjillings@1318 6854
nickjillings@1318 6855 for ( ; i < timers.length; i++ ) {
nickjillings@1318 6856 timer = timers[ i ];
nickjillings@1318 6857 // Checks the timer has not already been removed
nickjillings@1318 6858 if ( !timer() && timers[ i ] === timer ) {
nickjillings@1318 6859 timers.splice( i--, 1 );
nickjillings@1318 6860 }
nickjillings@1318 6861 }
nickjillings@1318 6862
nickjillings@1318 6863 if ( !timers.length ) {
nickjillings@1318 6864 jQuery.fx.stop();
nickjillings@1318 6865 }
nickjillings@1318 6866 fxNow = undefined;
nickjillings@1318 6867 };
nickjillings@1318 6868
nickjillings@1318 6869 jQuery.fx.timer = function( timer ) {
nickjillings@1318 6870 jQuery.timers.push( timer );
nickjillings@1318 6871 if ( timer() ) {
nickjillings@1318 6872 jQuery.fx.start();
nickjillings@1318 6873 } else {
nickjillings@1318 6874 jQuery.timers.pop();
nickjillings@1318 6875 }
nickjillings@1318 6876 };
nickjillings@1318 6877
nickjillings@1318 6878 jQuery.fx.interval = 13;
nickjillings@1318 6879
nickjillings@1318 6880 jQuery.fx.start = function() {
nickjillings@1318 6881 if ( !timerId ) {
nickjillings@1318 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nickjillings@1318 6883 }
nickjillings@1318 6884 };
nickjillings@1318 6885
nickjillings@1318 6886 jQuery.fx.stop = function() {
nickjillings@1318 6887 clearInterval( timerId );
nickjillings@1318 6888 timerId = null;
nickjillings@1318 6889 };
nickjillings@1318 6890
nickjillings@1318 6891 jQuery.fx.speeds = {
nickjillings@1318 6892 slow: 600,
nickjillings@1318 6893 fast: 200,
nickjillings@1318 6894 // Default speed
nickjillings@1318 6895 _default: 400
nickjillings@1318 6896 };
nickjillings@1318 6897
nickjillings@1318 6898
nickjillings@1318 6899 // Based off of the plugin by Clint Helfers, with permission.
nickjillings@1318 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nickjillings@1318 6901 jQuery.fn.delay = function( time, type ) {
nickjillings@1318 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nickjillings@1318 6903 type = type || "fx";
nickjillings@1318 6904
nickjillings@1318 6905 return this.queue( type, function( next, hooks ) {
nickjillings@1318 6906 var timeout = setTimeout( next, time );
nickjillings@1318 6907 hooks.stop = function() {
nickjillings@1318 6908 clearTimeout( timeout );
nickjillings@1318 6909 };
nickjillings@1318 6910 });
nickjillings@1318 6911 };
nickjillings@1318 6912
nickjillings@1318 6913
nickjillings@1318 6914 (function() {
nickjillings@1318 6915 var input = document.createElement( "input" ),
nickjillings@1318 6916 select = document.createElement( "select" ),
nickjillings@1318 6917 opt = select.appendChild( document.createElement( "option" ) );
nickjillings@1318 6918
nickjillings@1318 6919 input.type = "checkbox";
nickjillings@1318 6920
nickjillings@1318 6921 // Support: iOS<=5.1, Android<=4.2+
nickjillings@1318 6922 // Default value for a checkbox should be "on"
nickjillings@1318 6923 support.checkOn = input.value !== "";
nickjillings@1318 6924
nickjillings@1318 6925 // Support: IE<=11+
nickjillings@1318 6926 // Must access selectedIndex to make default options select
nickjillings@1318 6927 support.optSelected = opt.selected;
nickjillings@1318 6928
nickjillings@1318 6929 // Support: Android<=2.3
nickjillings@1318 6930 // Options inside disabled selects are incorrectly marked as disabled
nickjillings@1318 6931 select.disabled = true;
nickjillings@1318 6932 support.optDisabled = !opt.disabled;
nickjillings@1318 6933
nickjillings@1318 6934 // Support: IE<=11+
nickjillings@1318 6935 // An input loses its value after becoming a radio
nickjillings@1318 6936 input = document.createElement( "input" );
nickjillings@1318 6937 input.value = "t";
nickjillings@1318 6938 input.type = "radio";
nickjillings@1318 6939 support.radioValue = input.value === "t";
nickjillings@1318 6940 })();
nickjillings@1318 6941
nickjillings@1318 6942
nickjillings@1318 6943 var nodeHook, boolHook,
nickjillings@1318 6944 attrHandle = jQuery.expr.attrHandle;
nickjillings@1318 6945
nickjillings@1318 6946 jQuery.fn.extend({
nickjillings@1318 6947 attr: function( name, value ) {
nickjillings@1318 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nickjillings@1318 6949 },
nickjillings@1318 6950
nickjillings@1318 6951 removeAttr: function( name ) {
nickjillings@1318 6952 return this.each(function() {
nickjillings@1318 6953 jQuery.removeAttr( this, name );
nickjillings@1318 6954 });
nickjillings@1318 6955 }
nickjillings@1318 6956 });
nickjillings@1318 6957
nickjillings@1318 6958 jQuery.extend({
nickjillings@1318 6959 attr: function( elem, name, value ) {
nickjillings@1318 6960 var hooks, ret,
nickjillings@1318 6961 nType = elem.nodeType;
nickjillings@1318 6962
nickjillings@1318 6963 // don't get/set attributes on text, comment and attribute nodes
nickjillings@1318 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1318 6965 return;
nickjillings@1318 6966 }
nickjillings@1318 6967
nickjillings@1318 6968 // Fallback to prop when attributes are not supported
nickjillings@1318 6969 if ( typeof elem.getAttribute === strundefined ) {
nickjillings@1318 6970 return jQuery.prop( elem, name, value );
nickjillings@1318 6971 }
nickjillings@1318 6972
nickjillings@1318 6973 // All attributes are lowercase
nickjillings@1318 6974 // Grab necessary hook if one is defined
nickjillings@1318 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nickjillings@1318 6976 name = name.toLowerCase();
nickjillings@1318 6977 hooks = jQuery.attrHooks[ name ] ||
nickjillings@1318 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nickjillings@1318 6979 }
nickjillings@1318 6980
nickjillings@1318 6981 if ( value !== undefined ) {
nickjillings@1318 6982
nickjillings@1318 6983 if ( value === null ) {
nickjillings@1318 6984 jQuery.removeAttr( elem, name );
nickjillings@1318 6985
nickjillings@1318 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nickjillings@1318 6987 return ret;
nickjillings@1318 6988
nickjillings@1318 6989 } else {
nickjillings@1318 6990 elem.setAttribute( name, value + "" );
nickjillings@1318 6991 return value;
nickjillings@1318 6992 }
nickjillings@1318 6993
nickjillings@1318 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nickjillings@1318 6995 return ret;
nickjillings@1318 6996
nickjillings@1318 6997 } else {
nickjillings@1318 6998 ret = jQuery.find.attr( elem, name );
nickjillings@1318 6999
nickjillings@1318 7000 // Non-existent attributes return null, we normalize to undefined
nickjillings@1318 7001 return ret == null ?
nickjillings@1318 7002 undefined :
nickjillings@1318 7003 ret;
nickjillings@1318 7004 }
nickjillings@1318 7005 },
nickjillings@1318 7006
nickjillings@1318 7007 removeAttr: function( elem, value ) {
nickjillings@1318 7008 var name, propName,
nickjillings@1318 7009 i = 0,
nickjillings@1318 7010 attrNames = value && value.match( rnotwhite );
nickjillings@1318 7011
nickjillings@1318 7012 if ( attrNames && elem.nodeType === 1 ) {
nickjillings@1318 7013 while ( (name = attrNames[i++]) ) {
nickjillings@1318 7014 propName = jQuery.propFix[ name ] || name;
nickjillings@1318 7015
nickjillings@1318 7016 // Boolean attributes get special treatment (#10870)
nickjillings@1318 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nickjillings@1318 7018 // Set corresponding property to false
nickjillings@1318 7019 elem[ propName ] = false;
nickjillings@1318 7020 }
nickjillings@1318 7021
nickjillings@1318 7022 elem.removeAttribute( name );
nickjillings@1318 7023 }
nickjillings@1318 7024 }
nickjillings@1318 7025 },
nickjillings@1318 7026
nickjillings@1318 7027 attrHooks: {
nickjillings@1318 7028 type: {
nickjillings@1318 7029 set: function( elem, value ) {
nickjillings@1318 7030 if ( !support.radioValue && value === "radio" &&
nickjillings@1318 7031 jQuery.nodeName( elem, "input" ) ) {
nickjillings@1318 7032 var val = elem.value;
nickjillings@1318 7033 elem.setAttribute( "type", value );
nickjillings@1318 7034 if ( val ) {
nickjillings@1318 7035 elem.value = val;
nickjillings@1318 7036 }
nickjillings@1318 7037 return value;
nickjillings@1318 7038 }
nickjillings@1318 7039 }
nickjillings@1318 7040 }
nickjillings@1318 7041 }
nickjillings@1318 7042 });
nickjillings@1318 7043
nickjillings@1318 7044 // Hooks for boolean attributes
nickjillings@1318 7045 boolHook = {
nickjillings@1318 7046 set: function( elem, value, name ) {
nickjillings@1318 7047 if ( value === false ) {
nickjillings@1318 7048 // Remove boolean attributes when set to false
nickjillings@1318 7049 jQuery.removeAttr( elem, name );
nickjillings@1318 7050 } else {
nickjillings@1318 7051 elem.setAttribute( name, name );
nickjillings@1318 7052 }
nickjillings@1318 7053 return name;
nickjillings@1318 7054 }
nickjillings@1318 7055 };
nickjillings@1318 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nickjillings@1318 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nickjillings@1318 7058
nickjillings@1318 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nickjillings@1318 7060 var ret, handle;
nickjillings@1318 7061 if ( !isXML ) {
nickjillings@1318 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nickjillings@1318 7063 handle = attrHandle[ name ];
nickjillings@1318 7064 attrHandle[ name ] = ret;
nickjillings@1318 7065 ret = getter( elem, name, isXML ) != null ?
nickjillings@1318 7066 name.toLowerCase() :
nickjillings@1318 7067 null;
nickjillings@1318 7068 attrHandle[ name ] = handle;
nickjillings@1318 7069 }
nickjillings@1318 7070 return ret;
nickjillings@1318 7071 };
nickjillings@1318 7072 });
nickjillings@1318 7073
nickjillings@1318 7074
nickjillings@1318 7075
nickjillings@1318 7076
nickjillings@1318 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nickjillings@1318 7078
nickjillings@1318 7079 jQuery.fn.extend({
nickjillings@1318 7080 prop: function( name, value ) {
nickjillings@1318 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nickjillings@1318 7082 },
nickjillings@1318 7083
nickjillings@1318 7084 removeProp: function( name ) {
nickjillings@1318 7085 return this.each(function() {
nickjillings@1318 7086 delete this[ jQuery.propFix[ name ] || name ];
nickjillings@1318 7087 });
nickjillings@1318 7088 }
nickjillings@1318 7089 });
nickjillings@1318 7090
nickjillings@1318 7091 jQuery.extend({
nickjillings@1318 7092 propFix: {
nickjillings@1318 7093 "for": "htmlFor",
nickjillings@1318 7094 "class": "className"
nickjillings@1318 7095 },
nickjillings@1318 7096
nickjillings@1318 7097 prop: function( elem, name, value ) {
nickjillings@1318 7098 var ret, hooks, notxml,
nickjillings@1318 7099 nType = elem.nodeType;
nickjillings@1318 7100
nickjillings@1318 7101 // Don't get/set properties on text, comment and attribute nodes
nickjillings@1318 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1318 7103 return;
nickjillings@1318 7104 }
nickjillings@1318 7105
nickjillings@1318 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nickjillings@1318 7107
nickjillings@1318 7108 if ( notxml ) {
nickjillings@1318 7109 // Fix name and attach hooks
nickjillings@1318 7110 name = jQuery.propFix[ name ] || name;
nickjillings@1318 7111 hooks = jQuery.propHooks[ name ];
nickjillings@1318 7112 }
nickjillings@1318 7113
nickjillings@1318 7114 if ( value !== undefined ) {
nickjillings@1318 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nickjillings@1318 7116 ret :
nickjillings@1318 7117 ( elem[ name ] = value );
nickjillings@1318 7118
nickjillings@1318 7119 } else {
nickjillings@1318 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nickjillings@1318 7121 ret :
nickjillings@1318 7122 elem[ name ];
nickjillings@1318 7123 }
nickjillings@1318 7124 },
nickjillings@1318 7125
nickjillings@1318 7126 propHooks: {
nickjillings@1318 7127 tabIndex: {
nickjillings@1318 7128 get: function( elem ) {
nickjillings@1318 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nickjillings@1318 7130 elem.tabIndex :
nickjillings@1318 7131 -1;
nickjillings@1318 7132 }
nickjillings@1318 7133 }
nickjillings@1318 7134 }
nickjillings@1318 7135 });
nickjillings@1318 7136
nickjillings@1318 7137 if ( !support.optSelected ) {
nickjillings@1318 7138 jQuery.propHooks.selected = {
nickjillings@1318 7139 get: function( elem ) {
nickjillings@1318 7140 var parent = elem.parentNode;
nickjillings@1318 7141 if ( parent && parent.parentNode ) {
nickjillings@1318 7142 parent.parentNode.selectedIndex;
nickjillings@1318 7143 }
nickjillings@1318 7144 return null;
nickjillings@1318 7145 }
nickjillings@1318 7146 };
nickjillings@1318 7147 }
nickjillings@1318 7148
nickjillings@1318 7149 jQuery.each([
nickjillings@1318 7150 "tabIndex",
nickjillings@1318 7151 "readOnly",
nickjillings@1318 7152 "maxLength",
nickjillings@1318 7153 "cellSpacing",
nickjillings@1318 7154 "cellPadding",
nickjillings@1318 7155 "rowSpan",
nickjillings@1318 7156 "colSpan",
nickjillings@1318 7157 "useMap",
nickjillings@1318 7158 "frameBorder",
nickjillings@1318 7159 "contentEditable"
nickjillings@1318 7160 ], function() {
nickjillings@1318 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nickjillings@1318 7162 });
nickjillings@1318 7163
nickjillings@1318 7164
nickjillings@1318 7165
nickjillings@1318 7166
nickjillings@1318 7167 var rclass = /[\t\r\n\f]/g;
nickjillings@1318 7168
nickjillings@1318 7169 jQuery.fn.extend({
nickjillings@1318 7170 addClass: function( value ) {
nickjillings@1318 7171 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1318 7172 proceed = typeof value === "string" && value,
nickjillings@1318 7173 i = 0,
nickjillings@1318 7174 len = this.length;
nickjillings@1318 7175
nickjillings@1318 7176 if ( jQuery.isFunction( value ) ) {
nickjillings@1318 7177 return this.each(function( j ) {
nickjillings@1318 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nickjillings@1318 7179 });
nickjillings@1318 7180 }
nickjillings@1318 7181
nickjillings@1318 7182 if ( proceed ) {
nickjillings@1318 7183 // The disjunction here is for better compressibility (see removeClass)
nickjillings@1318 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1318 7185
nickjillings@1318 7186 for ( ; i < len; i++ ) {
nickjillings@1318 7187 elem = this[ i ];
nickjillings@1318 7188 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1318 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1318 7190 " "
nickjillings@1318 7191 );
nickjillings@1318 7192
nickjillings@1318 7193 if ( cur ) {
nickjillings@1318 7194 j = 0;
nickjillings@1318 7195 while ( (clazz = classes[j++]) ) {
nickjillings@1318 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nickjillings@1318 7197 cur += clazz + " ";
nickjillings@1318 7198 }
nickjillings@1318 7199 }
nickjillings@1318 7200
nickjillings@1318 7201 // only assign if different to avoid unneeded rendering.
nickjillings@1318 7202 finalValue = jQuery.trim( cur );
nickjillings@1318 7203 if ( elem.className !== finalValue ) {
nickjillings@1318 7204 elem.className = finalValue;
nickjillings@1318 7205 }
nickjillings@1318 7206 }
nickjillings@1318 7207 }
nickjillings@1318 7208 }
nickjillings@1318 7209
nickjillings@1318 7210 return this;
nickjillings@1318 7211 },
nickjillings@1318 7212
nickjillings@1318 7213 removeClass: function( value ) {
nickjillings@1318 7214 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1318 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nickjillings@1318 7216 i = 0,
nickjillings@1318 7217 len = this.length;
nickjillings@1318 7218
nickjillings@1318 7219 if ( jQuery.isFunction( value ) ) {
nickjillings@1318 7220 return this.each(function( j ) {
nickjillings@1318 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nickjillings@1318 7222 });
nickjillings@1318 7223 }
nickjillings@1318 7224 if ( proceed ) {
nickjillings@1318 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1318 7226
nickjillings@1318 7227 for ( ; i < len; i++ ) {
nickjillings@1318 7228 elem = this[ i ];
nickjillings@1318 7229 // This expression is here for better compressibility (see addClass)
nickjillings@1318 7230 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1318 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1318 7232 ""
nickjillings@1318 7233 );
nickjillings@1318 7234
nickjillings@1318 7235 if ( cur ) {
nickjillings@1318 7236 j = 0;
nickjillings@1318 7237 while ( (clazz = classes[j++]) ) {
nickjillings@1318 7238 // Remove *all* instances
nickjillings@1318 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nickjillings@1318 7240 cur = cur.replace( " " + clazz + " ", " " );
nickjillings@1318 7241 }
nickjillings@1318 7242 }
nickjillings@1318 7243
nickjillings@1318 7244 // Only assign if different to avoid unneeded rendering.
nickjillings@1318 7245 finalValue = value ? jQuery.trim( cur ) : "";
nickjillings@1318 7246 if ( elem.className !== finalValue ) {
nickjillings@1318 7247 elem.className = finalValue;
nickjillings@1318 7248 }
nickjillings@1318 7249 }
nickjillings@1318 7250 }
nickjillings@1318 7251 }
nickjillings@1318 7252
nickjillings@1318 7253 return this;
nickjillings@1318 7254 },
nickjillings@1318 7255
nickjillings@1318 7256 toggleClass: function( value, stateVal ) {
nickjillings@1318 7257 var type = typeof value;
nickjillings@1318 7258
nickjillings@1318 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nickjillings@1318 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nickjillings@1318 7261 }
nickjillings@1318 7262
nickjillings@1318 7263 if ( jQuery.isFunction( value ) ) {
nickjillings@1318 7264 return this.each(function( i ) {
nickjillings@1318 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nickjillings@1318 7266 });
nickjillings@1318 7267 }
nickjillings@1318 7268
nickjillings@1318 7269 return this.each(function() {
nickjillings@1318 7270 if ( type === "string" ) {
nickjillings@1318 7271 // Toggle individual class names
nickjillings@1318 7272 var className,
nickjillings@1318 7273 i = 0,
nickjillings@1318 7274 self = jQuery( this ),
nickjillings@1318 7275 classNames = value.match( rnotwhite ) || [];
nickjillings@1318 7276
nickjillings@1318 7277 while ( (className = classNames[ i++ ]) ) {
nickjillings@1318 7278 // Check each className given, space separated list
nickjillings@1318 7279 if ( self.hasClass( className ) ) {
nickjillings@1318 7280 self.removeClass( className );
nickjillings@1318 7281 } else {
nickjillings@1318 7282 self.addClass( className );
nickjillings@1318 7283 }
nickjillings@1318 7284 }
nickjillings@1318 7285
nickjillings@1318 7286 // Toggle whole class name
nickjillings@1318 7287 } else if ( type === strundefined || type === "boolean" ) {
nickjillings@1318 7288 if ( this.className ) {
nickjillings@1318 7289 // store className if set
nickjillings@1318 7290 data_priv.set( this, "__className__", this.className );
nickjillings@1318 7291 }
nickjillings@1318 7292
nickjillings@1318 7293 // If the element has a class name or if we're passed `false`,
nickjillings@1318 7294 // then remove the whole classname (if there was one, the above saved it).
nickjillings@1318 7295 // Otherwise bring back whatever was previously saved (if anything),
nickjillings@1318 7296 // falling back to the empty string if nothing was stored.
nickjillings@1318 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nickjillings@1318 7298 }
nickjillings@1318 7299 });
nickjillings@1318 7300 },
nickjillings@1318 7301
nickjillings@1318 7302 hasClass: function( selector ) {
nickjillings@1318 7303 var className = " " + selector + " ",
nickjillings@1318 7304 i = 0,
nickjillings@1318 7305 l = this.length;
nickjillings@1318 7306 for ( ; i < l; i++ ) {
nickjillings@1318 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nickjillings@1318 7308 return true;
nickjillings@1318 7309 }
nickjillings@1318 7310 }
nickjillings@1318 7311
nickjillings@1318 7312 return false;
nickjillings@1318 7313 }
nickjillings@1318 7314 });
nickjillings@1318 7315
nickjillings@1318 7316
nickjillings@1318 7317
nickjillings@1318 7318
nickjillings@1318 7319 var rreturn = /\r/g;
nickjillings@1318 7320
nickjillings@1318 7321 jQuery.fn.extend({
nickjillings@1318 7322 val: function( value ) {
nickjillings@1318 7323 var hooks, ret, isFunction,
nickjillings@1318 7324 elem = this[0];
nickjillings@1318 7325
nickjillings@1318 7326 if ( !arguments.length ) {
nickjillings@1318 7327 if ( elem ) {
nickjillings@1318 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nickjillings@1318 7329
nickjillings@1318 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nickjillings@1318 7331 return ret;
nickjillings@1318 7332 }
nickjillings@1318 7333
nickjillings@1318 7334 ret = elem.value;
nickjillings@1318 7335
nickjillings@1318 7336 return typeof ret === "string" ?
nickjillings@1318 7337 // Handle most common string cases
nickjillings@1318 7338 ret.replace(rreturn, "") :
nickjillings@1318 7339 // Handle cases where value is null/undef or number
nickjillings@1318 7340 ret == null ? "" : ret;
nickjillings@1318 7341 }
nickjillings@1318 7342
nickjillings@1318 7343 return;
nickjillings@1318 7344 }
nickjillings@1318 7345
nickjillings@1318 7346 isFunction = jQuery.isFunction( value );
nickjillings@1318 7347
nickjillings@1318 7348 return this.each(function( i ) {
nickjillings@1318 7349 var val;
nickjillings@1318 7350
nickjillings@1318 7351 if ( this.nodeType !== 1 ) {
nickjillings@1318 7352 return;
nickjillings@1318 7353 }
nickjillings@1318 7354
nickjillings@1318 7355 if ( isFunction ) {
nickjillings@1318 7356 val = value.call( this, i, jQuery( this ).val() );
nickjillings@1318 7357 } else {
nickjillings@1318 7358 val = value;
nickjillings@1318 7359 }
nickjillings@1318 7360
nickjillings@1318 7361 // Treat null/undefined as ""; convert numbers to string
nickjillings@1318 7362 if ( val == null ) {
nickjillings@1318 7363 val = "";
nickjillings@1318 7364
nickjillings@1318 7365 } else if ( typeof val === "number" ) {
nickjillings@1318 7366 val += "";
nickjillings@1318 7367
nickjillings@1318 7368 } else if ( jQuery.isArray( val ) ) {
nickjillings@1318 7369 val = jQuery.map( val, function( value ) {
nickjillings@1318 7370 return value == null ? "" : value + "";
nickjillings@1318 7371 });
nickjillings@1318 7372 }
nickjillings@1318 7373
nickjillings@1318 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nickjillings@1318 7375
nickjillings@1318 7376 // If set returns undefined, fall back to normal setting
nickjillings@1318 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nickjillings@1318 7378 this.value = val;
nickjillings@1318 7379 }
nickjillings@1318 7380 });
nickjillings@1318 7381 }
nickjillings@1318 7382 });
nickjillings@1318 7383
nickjillings@1318 7384 jQuery.extend({
nickjillings@1318 7385 valHooks: {
nickjillings@1318 7386 option: {
nickjillings@1318 7387 get: function( elem ) {
nickjillings@1318 7388 var val = jQuery.find.attr( elem, "value" );
nickjillings@1318 7389 return val != null ?
nickjillings@1318 7390 val :
nickjillings@1318 7391 // Support: IE10-11+
nickjillings@1318 7392 // option.text throws exceptions (#14686, #14858)
nickjillings@1318 7393 jQuery.trim( jQuery.text( elem ) );
nickjillings@1318 7394 }
nickjillings@1318 7395 },
nickjillings@1318 7396 select: {
nickjillings@1318 7397 get: function( elem ) {
nickjillings@1318 7398 var value, option,
nickjillings@1318 7399 options = elem.options,
nickjillings@1318 7400 index = elem.selectedIndex,
nickjillings@1318 7401 one = elem.type === "select-one" || index < 0,
nickjillings@1318 7402 values = one ? null : [],
nickjillings@1318 7403 max = one ? index + 1 : options.length,
nickjillings@1318 7404 i = index < 0 ?
nickjillings@1318 7405 max :
nickjillings@1318 7406 one ? index : 0;
nickjillings@1318 7407
nickjillings@1318 7408 // Loop through all the selected options
nickjillings@1318 7409 for ( ; i < max; i++ ) {
nickjillings@1318 7410 option = options[ i ];
nickjillings@1318 7411
nickjillings@1318 7412 // IE6-9 doesn't update selected after form reset (#2551)
nickjillings@1318 7413 if ( ( option.selected || i === index ) &&
nickjillings@1318 7414 // Don't return options that are disabled or in a disabled optgroup
nickjillings@1318 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nickjillings@1318 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nickjillings@1318 7417
nickjillings@1318 7418 // Get the specific value for the option
nickjillings@1318 7419 value = jQuery( option ).val();
nickjillings@1318 7420
nickjillings@1318 7421 // We don't need an array for one selects
nickjillings@1318 7422 if ( one ) {
nickjillings@1318 7423 return value;
nickjillings@1318 7424 }
nickjillings@1318 7425
nickjillings@1318 7426 // Multi-Selects return an array
nickjillings@1318 7427 values.push( value );
nickjillings@1318 7428 }
nickjillings@1318 7429 }
nickjillings@1318 7430
nickjillings@1318 7431 return values;
nickjillings@1318 7432 },
nickjillings@1318 7433
nickjillings@1318 7434 set: function( elem, value ) {
nickjillings@1318 7435 var optionSet, option,
nickjillings@1318 7436 options = elem.options,
nickjillings@1318 7437 values = jQuery.makeArray( value ),
nickjillings@1318 7438 i = options.length;
nickjillings@1318 7439
nickjillings@1318 7440 while ( i-- ) {
nickjillings@1318 7441 option = options[ i ];
nickjillings@1318 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nickjillings@1318 7443 optionSet = true;
nickjillings@1318 7444 }
nickjillings@1318 7445 }
nickjillings@1318 7446
nickjillings@1318 7447 // Force browsers to behave consistently when non-matching value is set
nickjillings@1318 7448 if ( !optionSet ) {
nickjillings@1318 7449 elem.selectedIndex = -1;
nickjillings@1318 7450 }
nickjillings@1318 7451 return values;
nickjillings@1318 7452 }
nickjillings@1318 7453 }
nickjillings@1318 7454 }
nickjillings@1318 7455 });
nickjillings@1318 7456
nickjillings@1318 7457 // Radios and checkboxes getter/setter
nickjillings@1318 7458 jQuery.each([ "radio", "checkbox" ], function() {
nickjillings@1318 7459 jQuery.valHooks[ this ] = {
nickjillings@1318 7460 set: function( elem, value ) {
nickjillings@1318 7461 if ( jQuery.isArray( value ) ) {
nickjillings@1318 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nickjillings@1318 7463 }
nickjillings@1318 7464 }
nickjillings@1318 7465 };
nickjillings@1318 7466 if ( !support.checkOn ) {
nickjillings@1318 7467 jQuery.valHooks[ this ].get = function( elem ) {
nickjillings@1318 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nickjillings@1318 7469 };
nickjillings@1318 7470 }
nickjillings@1318 7471 });
nickjillings@1318 7472
nickjillings@1318 7473
nickjillings@1318 7474
nickjillings@1318 7475
nickjillings@1318 7476 // Return jQuery for attributes-only inclusion
nickjillings@1318 7477
nickjillings@1318 7478
nickjillings@1318 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nickjillings@1318 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nickjillings@1318 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nickjillings@1318 7482
nickjillings@1318 7483 // Handle event binding
nickjillings@1318 7484 jQuery.fn[ name ] = function( data, fn ) {
nickjillings@1318 7485 return arguments.length > 0 ?
nickjillings@1318 7486 this.on( name, null, data, fn ) :
nickjillings@1318 7487 this.trigger( name );
nickjillings@1318 7488 };
nickjillings@1318 7489 });
nickjillings@1318 7490
nickjillings@1318 7491 jQuery.fn.extend({
nickjillings@1318 7492 hover: function( fnOver, fnOut ) {
nickjillings@1318 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nickjillings@1318 7494 },
nickjillings@1318 7495
nickjillings@1318 7496 bind: function( types, data, fn ) {
nickjillings@1318 7497 return this.on( types, null, data, fn );
nickjillings@1318 7498 },
nickjillings@1318 7499 unbind: function( types, fn ) {
nickjillings@1318 7500 return this.off( types, null, fn );
nickjillings@1318 7501 },
nickjillings@1318 7502
nickjillings@1318 7503 delegate: function( selector, types, data, fn ) {
nickjillings@1318 7504 return this.on( types, selector, data, fn );
nickjillings@1318 7505 },
nickjillings@1318 7506 undelegate: function( selector, types, fn ) {
nickjillings@1318 7507 // ( namespace ) or ( selector, types [, fn] )
nickjillings@1318 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nickjillings@1318 7509 }
nickjillings@1318 7510 });
nickjillings@1318 7511
nickjillings@1318 7512
nickjillings@1318 7513 var nonce = jQuery.now();
nickjillings@1318 7514
nickjillings@1318 7515 var rquery = (/\?/);
nickjillings@1318 7516
nickjillings@1318 7517
nickjillings@1318 7518
nickjillings@1318 7519 // Support: Android 2.3
nickjillings@1318 7520 // Workaround failure to string-cast null input
nickjillings@1318 7521 jQuery.parseJSON = function( data ) {
nickjillings@1318 7522 return JSON.parse( data + "" );
nickjillings@1318 7523 };
nickjillings@1318 7524
nickjillings@1318 7525
nickjillings@1318 7526 // Cross-browser xml parsing
nickjillings@1318 7527 jQuery.parseXML = function( data ) {
nickjillings@1318 7528 var xml, tmp;
nickjillings@1318 7529 if ( !data || typeof data !== "string" ) {
nickjillings@1318 7530 return null;
nickjillings@1318 7531 }
nickjillings@1318 7532
nickjillings@1318 7533 // Support: IE9
nickjillings@1318 7534 try {
nickjillings@1318 7535 tmp = new DOMParser();
nickjillings@1318 7536 xml = tmp.parseFromString( data, "text/xml" );
nickjillings@1318 7537 } catch ( e ) {
nickjillings@1318 7538 xml = undefined;
nickjillings@1318 7539 }
nickjillings@1318 7540
nickjillings@1318 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nickjillings@1318 7542 jQuery.error( "Invalid XML: " + data );
nickjillings@1318 7543 }
nickjillings@1318 7544 return xml;
nickjillings@1318 7545 };
nickjillings@1318 7546
nickjillings@1318 7547
nickjillings@1318 7548 var
nickjillings@1318 7549 rhash = /#.*$/,
nickjillings@1318 7550 rts = /([?&])_=[^&]*/,
nickjillings@1318 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nickjillings@1318 7552 // #7653, #8125, #8152: local protocol detection
nickjillings@1318 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nickjillings@1318 7554 rnoContent = /^(?:GET|HEAD)$/,
nickjillings@1318 7555 rprotocol = /^\/\//,
nickjillings@1318 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nickjillings@1318 7557
nickjillings@1318 7558 /* Prefilters
nickjillings@1318 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nickjillings@1318 7560 * 2) These are called:
nickjillings@1318 7561 * - BEFORE asking for a transport
nickjillings@1318 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nickjillings@1318 7563 * 3) key is the dataType
nickjillings@1318 7564 * 4) the catchall symbol "*" can be used
nickjillings@1318 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nickjillings@1318 7566 */
nickjillings@1318 7567 prefilters = {},
nickjillings@1318 7568
nickjillings@1318 7569 /* Transports bindings
nickjillings@1318 7570 * 1) key is the dataType
nickjillings@1318 7571 * 2) the catchall symbol "*" can be used
nickjillings@1318 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nickjillings@1318 7573 */
nickjillings@1318 7574 transports = {},
nickjillings@1318 7575
nickjillings@1318 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nickjillings@1318 7577 allTypes = "*/".concat( "*" ),
nickjillings@1318 7578
nickjillings@1318 7579 // Document location
nickjillings@1318 7580 ajaxLocation = window.location.href,
nickjillings@1318 7581
nickjillings@1318 7582 // Segment location into parts
nickjillings@1318 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nickjillings@1318 7584
nickjillings@1318 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nickjillings@1318 7586 function addToPrefiltersOrTransports( structure ) {
nickjillings@1318 7587
nickjillings@1318 7588 // dataTypeExpression is optional and defaults to "*"
nickjillings@1318 7589 return function( dataTypeExpression, func ) {
nickjillings@1318 7590
nickjillings@1318 7591 if ( typeof dataTypeExpression !== "string" ) {
nickjillings@1318 7592 func = dataTypeExpression;
nickjillings@1318 7593 dataTypeExpression = "*";
nickjillings@1318 7594 }
nickjillings@1318 7595
nickjillings@1318 7596 var dataType,
nickjillings@1318 7597 i = 0,
nickjillings@1318 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nickjillings@1318 7599
nickjillings@1318 7600 if ( jQuery.isFunction( func ) ) {
nickjillings@1318 7601 // For each dataType in the dataTypeExpression
nickjillings@1318 7602 while ( (dataType = dataTypes[i++]) ) {
nickjillings@1318 7603 // Prepend if requested
nickjillings@1318 7604 if ( dataType[0] === "+" ) {
nickjillings@1318 7605 dataType = dataType.slice( 1 ) || "*";
nickjillings@1318 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nickjillings@1318 7607
nickjillings@1318 7608 // Otherwise append
nickjillings@1318 7609 } else {
nickjillings@1318 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nickjillings@1318 7611 }
nickjillings@1318 7612 }
nickjillings@1318 7613 }
nickjillings@1318 7614 };
nickjillings@1318 7615 }
nickjillings@1318 7616
nickjillings@1318 7617 // Base inspection function for prefilters and transports
nickjillings@1318 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nickjillings@1318 7619
nickjillings@1318 7620 var inspected = {},
nickjillings@1318 7621 seekingTransport = ( structure === transports );
nickjillings@1318 7622
nickjillings@1318 7623 function inspect( dataType ) {
nickjillings@1318 7624 var selected;
nickjillings@1318 7625 inspected[ dataType ] = true;
nickjillings@1318 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nickjillings@1318 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nickjillings@1318 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nickjillings@1318 7629 options.dataTypes.unshift( dataTypeOrTransport );
nickjillings@1318 7630 inspect( dataTypeOrTransport );
nickjillings@1318 7631 return false;
nickjillings@1318 7632 } else if ( seekingTransport ) {
nickjillings@1318 7633 return !( selected = dataTypeOrTransport );
nickjillings@1318 7634 }
nickjillings@1318 7635 });
nickjillings@1318 7636 return selected;
nickjillings@1318 7637 }
nickjillings@1318 7638
nickjillings@1318 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nickjillings@1318 7640 }
nickjillings@1318 7641
nickjillings@1318 7642 // A special extend for ajax options
nickjillings@1318 7643 // that takes "flat" options (not to be deep extended)
nickjillings@1318 7644 // Fixes #9887
nickjillings@1318 7645 function ajaxExtend( target, src ) {
nickjillings@1318 7646 var key, deep,
nickjillings@1318 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nickjillings@1318 7648
nickjillings@1318 7649 for ( key in src ) {
nickjillings@1318 7650 if ( src[ key ] !== undefined ) {
nickjillings@1318 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nickjillings@1318 7652 }
nickjillings@1318 7653 }
nickjillings@1318 7654 if ( deep ) {
nickjillings@1318 7655 jQuery.extend( true, target, deep );
nickjillings@1318 7656 }
nickjillings@1318 7657
nickjillings@1318 7658 return target;
nickjillings@1318 7659 }
nickjillings@1318 7660
nickjillings@1318 7661 /* Handles responses to an ajax request:
nickjillings@1318 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nickjillings@1318 7663 * - returns the corresponding response
nickjillings@1318 7664 */
nickjillings@1318 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nickjillings@1318 7666
nickjillings@1318 7667 var ct, type, finalDataType, firstDataType,
nickjillings@1318 7668 contents = s.contents,
nickjillings@1318 7669 dataTypes = s.dataTypes;
nickjillings@1318 7670
nickjillings@1318 7671 // Remove auto dataType and get content-type in the process
nickjillings@1318 7672 while ( dataTypes[ 0 ] === "*" ) {
nickjillings@1318 7673 dataTypes.shift();
nickjillings@1318 7674 if ( ct === undefined ) {
nickjillings@1318 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nickjillings@1318 7676 }
nickjillings@1318 7677 }
nickjillings@1318 7678
nickjillings@1318 7679 // Check if we're dealing with a known content-type
nickjillings@1318 7680 if ( ct ) {
nickjillings@1318 7681 for ( type in contents ) {
nickjillings@1318 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nickjillings@1318 7683 dataTypes.unshift( type );
nickjillings@1318 7684 break;
nickjillings@1318 7685 }
nickjillings@1318 7686 }
nickjillings@1318 7687 }
nickjillings@1318 7688
nickjillings@1318 7689 // Check to see if we have a response for the expected dataType
nickjillings@1318 7690 if ( dataTypes[ 0 ] in responses ) {
nickjillings@1318 7691 finalDataType = dataTypes[ 0 ];
nickjillings@1318 7692 } else {
nickjillings@1318 7693 // Try convertible dataTypes
nickjillings@1318 7694 for ( type in responses ) {
nickjillings@1318 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nickjillings@1318 7696 finalDataType = type;
nickjillings@1318 7697 break;
nickjillings@1318 7698 }
nickjillings@1318 7699 if ( !firstDataType ) {
nickjillings@1318 7700 firstDataType = type;
nickjillings@1318 7701 }
nickjillings@1318 7702 }
nickjillings@1318 7703 // Or just use first one
nickjillings@1318 7704 finalDataType = finalDataType || firstDataType;
nickjillings@1318 7705 }
nickjillings@1318 7706
nickjillings@1318 7707 // If we found a dataType
nickjillings@1318 7708 // We add the dataType to the list if needed
nickjillings@1318 7709 // and return the corresponding response
nickjillings@1318 7710 if ( finalDataType ) {
nickjillings@1318 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nickjillings@1318 7712 dataTypes.unshift( finalDataType );
nickjillings@1318 7713 }
nickjillings@1318 7714 return responses[ finalDataType ];
nickjillings@1318 7715 }
nickjillings@1318 7716 }
nickjillings@1318 7717
nickjillings@1318 7718 /* Chain conversions given the request and the original response
nickjillings@1318 7719 * Also sets the responseXXX fields on the jqXHR instance
nickjillings@1318 7720 */
nickjillings@1318 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nickjillings@1318 7722 var conv2, current, conv, tmp, prev,
nickjillings@1318 7723 converters = {},
nickjillings@1318 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nickjillings@1318 7725 dataTypes = s.dataTypes.slice();
nickjillings@1318 7726
nickjillings@1318 7727 // Create converters map with lowercased keys
nickjillings@1318 7728 if ( dataTypes[ 1 ] ) {
nickjillings@1318 7729 for ( conv in s.converters ) {
nickjillings@1318 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nickjillings@1318 7731 }
nickjillings@1318 7732 }
nickjillings@1318 7733
nickjillings@1318 7734 current = dataTypes.shift();
nickjillings@1318 7735
nickjillings@1318 7736 // Convert to each sequential dataType
nickjillings@1318 7737 while ( current ) {
nickjillings@1318 7738
nickjillings@1318 7739 if ( s.responseFields[ current ] ) {
nickjillings@1318 7740 jqXHR[ s.responseFields[ current ] ] = response;
nickjillings@1318 7741 }
nickjillings@1318 7742
nickjillings@1318 7743 // Apply the dataFilter if provided
nickjillings@1318 7744 if ( !prev && isSuccess && s.dataFilter ) {
nickjillings@1318 7745 response = s.dataFilter( response, s.dataType );
nickjillings@1318 7746 }
nickjillings@1318 7747
nickjillings@1318 7748 prev = current;
nickjillings@1318 7749 current = dataTypes.shift();
nickjillings@1318 7750
nickjillings@1318 7751 if ( current ) {
nickjillings@1318 7752
nickjillings@1318 7753 // There's only work to do if current dataType is non-auto
nickjillings@1318 7754 if ( current === "*" ) {
nickjillings@1318 7755
nickjillings@1318 7756 current = prev;
nickjillings@1318 7757
nickjillings@1318 7758 // Convert response if prev dataType is non-auto and differs from current
nickjillings@1318 7759 } else if ( prev !== "*" && prev !== current ) {
nickjillings@1318 7760
nickjillings@1318 7761 // Seek a direct converter
nickjillings@1318 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nickjillings@1318 7763
nickjillings@1318 7764 // If none found, seek a pair
nickjillings@1318 7765 if ( !conv ) {
nickjillings@1318 7766 for ( conv2 in converters ) {
nickjillings@1318 7767
nickjillings@1318 7768 // If conv2 outputs current
nickjillings@1318 7769 tmp = conv2.split( " " );
nickjillings@1318 7770 if ( tmp[ 1 ] === current ) {
nickjillings@1318 7771
nickjillings@1318 7772 // If prev can be converted to accepted input
nickjillings@1318 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nickjillings@1318 7774 converters[ "* " + tmp[ 0 ] ];
nickjillings@1318 7775 if ( conv ) {
nickjillings@1318 7776 // Condense equivalence converters
nickjillings@1318 7777 if ( conv === true ) {
nickjillings@1318 7778 conv = converters[ conv2 ];
nickjillings@1318 7779
nickjillings@1318 7780 // Otherwise, insert the intermediate dataType
nickjillings@1318 7781 } else if ( converters[ conv2 ] !== true ) {
nickjillings@1318 7782 current = tmp[ 0 ];
nickjillings@1318 7783 dataTypes.unshift( tmp[ 1 ] );
nickjillings@1318 7784 }
nickjillings@1318 7785 break;
nickjillings@1318 7786 }
nickjillings@1318 7787 }
nickjillings@1318 7788 }
nickjillings@1318 7789 }
nickjillings@1318 7790
nickjillings@1318 7791 // Apply converter (if not an equivalence)
nickjillings@1318 7792 if ( conv !== true ) {
nickjillings@1318 7793
nickjillings@1318 7794 // Unless errors are allowed to bubble, catch and return them
nickjillings@1318 7795 if ( conv && s[ "throws" ] ) {
nickjillings@1318 7796 response = conv( response );
nickjillings@1318 7797 } else {
nickjillings@1318 7798 try {
nickjillings@1318 7799 response = conv( response );
nickjillings@1318 7800 } catch ( e ) {
nickjillings@1318 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nickjillings@1318 7802 }
nickjillings@1318 7803 }
nickjillings@1318 7804 }
nickjillings@1318 7805 }
nickjillings@1318 7806 }
nickjillings@1318 7807 }
nickjillings@1318 7808
nickjillings@1318 7809 return { state: "success", data: response };
nickjillings@1318 7810 }
nickjillings@1318 7811
nickjillings@1318 7812 jQuery.extend({
nickjillings@1318 7813
nickjillings@1318 7814 // Counter for holding the number of active queries
nickjillings@1318 7815 active: 0,
nickjillings@1318 7816
nickjillings@1318 7817 // Last-Modified header cache for next request
nickjillings@1318 7818 lastModified: {},
nickjillings@1318 7819 etag: {},
nickjillings@1318 7820
nickjillings@1318 7821 ajaxSettings: {
nickjillings@1318 7822 url: ajaxLocation,
nickjillings@1318 7823 type: "GET",
nickjillings@1318 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nickjillings@1318 7825 global: true,
nickjillings@1318 7826 processData: true,
nickjillings@1318 7827 async: true,
nickjillings@1318 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nickjillings@1318 7829 /*
nickjillings@1318 7830 timeout: 0,
nickjillings@1318 7831 data: null,
nickjillings@1318 7832 dataType: null,
nickjillings@1318 7833 username: null,
nickjillings@1318 7834 password: null,
nickjillings@1318 7835 cache: null,
nickjillings@1318 7836 throws: false,
nickjillings@1318 7837 traditional: false,
nickjillings@1318 7838 headers: {},
nickjillings@1318 7839 */
nickjillings@1318 7840
nickjillings@1318 7841 accepts: {
nickjillings@1318 7842 "*": allTypes,
nickjillings@1318 7843 text: "text/plain",
nickjillings@1318 7844 html: "text/html",
nickjillings@1318 7845 xml: "application/xml, text/xml",
nickjillings@1318 7846 json: "application/json, text/javascript"
nickjillings@1318 7847 },
nickjillings@1318 7848
nickjillings@1318 7849 contents: {
nickjillings@1318 7850 xml: /xml/,
nickjillings@1318 7851 html: /html/,
nickjillings@1318 7852 json: /json/
nickjillings@1318 7853 },
nickjillings@1318 7854
nickjillings@1318 7855 responseFields: {
nickjillings@1318 7856 xml: "responseXML",
nickjillings@1318 7857 text: "responseText",
nickjillings@1318 7858 json: "responseJSON"
nickjillings@1318 7859 },
nickjillings@1318 7860
nickjillings@1318 7861 // Data converters
nickjillings@1318 7862 // Keys separate source (or catchall "*") and destination types with a single space
nickjillings@1318 7863 converters: {
nickjillings@1318 7864
nickjillings@1318 7865 // Convert anything to text
nickjillings@1318 7866 "* text": String,
nickjillings@1318 7867
nickjillings@1318 7868 // Text to html (true = no transformation)
nickjillings@1318 7869 "text html": true,
nickjillings@1318 7870
nickjillings@1318 7871 // Evaluate text as a json expression
nickjillings@1318 7872 "text json": jQuery.parseJSON,
nickjillings@1318 7873
nickjillings@1318 7874 // Parse text as xml
nickjillings@1318 7875 "text xml": jQuery.parseXML
nickjillings@1318 7876 },
nickjillings@1318 7877
nickjillings@1318 7878 // For options that shouldn't be deep extended:
nickjillings@1318 7879 // you can add your own custom options here if
nickjillings@1318 7880 // and when you create one that shouldn't be
nickjillings@1318 7881 // deep extended (see ajaxExtend)
nickjillings@1318 7882 flatOptions: {
nickjillings@1318 7883 url: true,
nickjillings@1318 7884 context: true
nickjillings@1318 7885 }
nickjillings@1318 7886 },
nickjillings@1318 7887
nickjillings@1318 7888 // Creates a full fledged settings object into target
nickjillings@1318 7889 // with both ajaxSettings and settings fields.
nickjillings@1318 7890 // If target is omitted, writes into ajaxSettings.
nickjillings@1318 7891 ajaxSetup: function( target, settings ) {
nickjillings@1318 7892 return settings ?
nickjillings@1318 7893
nickjillings@1318 7894 // Building a settings object
nickjillings@1318 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nickjillings@1318 7896
nickjillings@1318 7897 // Extending ajaxSettings
nickjillings@1318 7898 ajaxExtend( jQuery.ajaxSettings, target );
nickjillings@1318 7899 },
nickjillings@1318 7900
nickjillings@1318 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nickjillings@1318 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nickjillings@1318 7903
nickjillings@1318 7904 // Main method
nickjillings@1318 7905 ajax: function( url, options ) {
nickjillings@1318 7906
nickjillings@1318 7907 // If url is an object, simulate pre-1.5 signature
nickjillings@1318 7908 if ( typeof url === "object" ) {
nickjillings@1318 7909 options = url;
nickjillings@1318 7910 url = undefined;
nickjillings@1318 7911 }
nickjillings@1318 7912
nickjillings@1318 7913 // Force options to be an object
nickjillings@1318 7914 options = options || {};
nickjillings@1318 7915
nickjillings@1318 7916 var transport,
nickjillings@1318 7917 // URL without anti-cache param
nickjillings@1318 7918 cacheURL,
nickjillings@1318 7919 // Response headers
nickjillings@1318 7920 responseHeadersString,
nickjillings@1318 7921 responseHeaders,
nickjillings@1318 7922 // timeout handle
nickjillings@1318 7923 timeoutTimer,
nickjillings@1318 7924 // Cross-domain detection vars
nickjillings@1318 7925 parts,
nickjillings@1318 7926 // To know if global events are to be dispatched
nickjillings@1318 7927 fireGlobals,
nickjillings@1318 7928 // Loop variable
nickjillings@1318 7929 i,
nickjillings@1318 7930 // Create the final options object
nickjillings@1318 7931 s = jQuery.ajaxSetup( {}, options ),
nickjillings@1318 7932 // Callbacks context
nickjillings@1318 7933 callbackContext = s.context || s,
nickjillings@1318 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nickjillings@1318 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nickjillings@1318 7936 jQuery( callbackContext ) :
nickjillings@1318 7937 jQuery.event,
nickjillings@1318 7938 // Deferreds
nickjillings@1318 7939 deferred = jQuery.Deferred(),
nickjillings@1318 7940 completeDeferred = jQuery.Callbacks("once memory"),
nickjillings@1318 7941 // Status-dependent callbacks
nickjillings@1318 7942 statusCode = s.statusCode || {},
nickjillings@1318 7943 // Headers (they are sent all at once)
nickjillings@1318 7944 requestHeaders = {},
nickjillings@1318 7945 requestHeadersNames = {},
nickjillings@1318 7946 // The jqXHR state
nickjillings@1318 7947 state = 0,
nickjillings@1318 7948 // Default abort message
nickjillings@1318 7949 strAbort = "canceled",
nickjillings@1318 7950 // Fake xhr
nickjillings@1318 7951 jqXHR = {
nickjillings@1318 7952 readyState: 0,
nickjillings@1318 7953
nickjillings@1318 7954 // Builds headers hashtable if needed
nickjillings@1318 7955 getResponseHeader: function( key ) {
nickjillings@1318 7956 var match;
nickjillings@1318 7957 if ( state === 2 ) {
nickjillings@1318 7958 if ( !responseHeaders ) {
nickjillings@1318 7959 responseHeaders = {};
nickjillings@1318 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nickjillings@1318 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nickjillings@1318 7962 }
nickjillings@1318 7963 }
nickjillings@1318 7964 match = responseHeaders[ key.toLowerCase() ];
nickjillings@1318 7965 }
nickjillings@1318 7966 return match == null ? null : match;
nickjillings@1318 7967 },
nickjillings@1318 7968
nickjillings@1318 7969 // Raw string
nickjillings@1318 7970 getAllResponseHeaders: function() {
nickjillings@1318 7971 return state === 2 ? responseHeadersString : null;
nickjillings@1318 7972 },
nickjillings@1318 7973
nickjillings@1318 7974 // Caches the header
nickjillings@1318 7975 setRequestHeader: function( name, value ) {
nickjillings@1318 7976 var lname = name.toLowerCase();
nickjillings@1318 7977 if ( !state ) {
nickjillings@1318 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nickjillings@1318 7979 requestHeaders[ name ] = value;
nickjillings@1318 7980 }
nickjillings@1318 7981 return this;
nickjillings@1318 7982 },
nickjillings@1318 7983
nickjillings@1318 7984 // Overrides response content-type header
nickjillings@1318 7985 overrideMimeType: function( type ) {
nickjillings@1318 7986 if ( !state ) {
nickjillings@1318 7987 s.mimeType = type;
nickjillings@1318 7988 }
nickjillings@1318 7989 return this;
nickjillings@1318 7990 },
nickjillings@1318 7991
nickjillings@1318 7992 // Status-dependent callbacks
nickjillings@1318 7993 statusCode: function( map ) {
nickjillings@1318 7994 var code;
nickjillings@1318 7995 if ( map ) {
nickjillings@1318 7996 if ( state < 2 ) {
nickjillings@1318 7997 for ( code in map ) {
nickjillings@1318 7998 // Lazy-add the new callback in a way that preserves old ones
nickjillings@1318 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nickjillings@1318 8000 }
nickjillings@1318 8001 } else {
nickjillings@1318 8002 // Execute the appropriate callbacks
nickjillings@1318 8003 jqXHR.always( map[ jqXHR.status ] );
nickjillings@1318 8004 }
nickjillings@1318 8005 }
nickjillings@1318 8006 return this;
nickjillings@1318 8007 },
nickjillings@1318 8008
nickjillings@1318 8009 // Cancel the request
nickjillings@1318 8010 abort: function( statusText ) {
nickjillings@1318 8011 var finalText = statusText || strAbort;
nickjillings@1318 8012 if ( transport ) {
nickjillings@1318 8013 transport.abort( finalText );
nickjillings@1318 8014 }
nickjillings@1318 8015 done( 0, finalText );
nickjillings@1318 8016 return this;
nickjillings@1318 8017 }
nickjillings@1318 8018 };
nickjillings@1318 8019
nickjillings@1318 8020 // Attach deferreds
nickjillings@1318 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nickjillings@1318 8022 jqXHR.success = jqXHR.done;
nickjillings@1318 8023 jqXHR.error = jqXHR.fail;
nickjillings@1318 8024
nickjillings@1318 8025 // Remove hash character (#7531: and string promotion)
nickjillings@1318 8026 // Add protocol if not provided (prefilters might expect it)
nickjillings@1318 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nickjillings@1318 8028 // We also use the url parameter if available
nickjillings@1318 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nickjillings@1318 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nickjillings@1318 8031
nickjillings@1318 8032 // Alias method option to type as per ticket #12004
nickjillings@1318 8033 s.type = options.method || options.type || s.method || s.type;
nickjillings@1318 8034
nickjillings@1318 8035 // Extract dataTypes list
nickjillings@1318 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nickjillings@1318 8037
nickjillings@1318 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nickjillings@1318 8039 if ( s.crossDomain == null ) {
nickjillings@1318 8040 parts = rurl.exec( s.url.toLowerCase() );
nickjillings@1318 8041 s.crossDomain = !!( parts &&
nickjillings@1318 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nickjillings@1318 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nickjillings@1318 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nickjillings@1318 8045 );
nickjillings@1318 8046 }
nickjillings@1318 8047
nickjillings@1318 8048 // Convert data if not already a string
nickjillings@1318 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nickjillings@1318 8050 s.data = jQuery.param( s.data, s.traditional );
nickjillings@1318 8051 }
nickjillings@1318 8052
nickjillings@1318 8053 // Apply prefilters
nickjillings@1318 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nickjillings@1318 8055
nickjillings@1318 8056 // If request was aborted inside a prefilter, stop there
nickjillings@1318 8057 if ( state === 2 ) {
nickjillings@1318 8058 return jqXHR;
nickjillings@1318 8059 }
nickjillings@1318 8060
nickjillings@1318 8061 // We can fire global events as of now if asked to
nickjillings@1318 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nickjillings@1318 8063 fireGlobals = jQuery.event && s.global;
nickjillings@1318 8064
nickjillings@1318 8065 // Watch for a new set of requests
nickjillings@1318 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nickjillings@1318 8067 jQuery.event.trigger("ajaxStart");
nickjillings@1318 8068 }
nickjillings@1318 8069
nickjillings@1318 8070 // Uppercase the type
nickjillings@1318 8071 s.type = s.type.toUpperCase();
nickjillings@1318 8072
nickjillings@1318 8073 // Determine if request has content
nickjillings@1318 8074 s.hasContent = !rnoContent.test( s.type );
nickjillings@1318 8075
nickjillings@1318 8076 // Save the URL in case we're toying with the If-Modified-Since
nickjillings@1318 8077 // and/or If-None-Match header later on
nickjillings@1318 8078 cacheURL = s.url;
nickjillings@1318 8079
nickjillings@1318 8080 // More options handling for requests with no content
nickjillings@1318 8081 if ( !s.hasContent ) {
nickjillings@1318 8082
nickjillings@1318 8083 // If data is available, append data to url
nickjillings@1318 8084 if ( s.data ) {
nickjillings@1318 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nickjillings@1318 8086 // #9682: remove data so that it's not used in an eventual retry
nickjillings@1318 8087 delete s.data;
nickjillings@1318 8088 }
nickjillings@1318 8089
nickjillings@1318 8090 // Add anti-cache in url if needed
nickjillings@1318 8091 if ( s.cache === false ) {
nickjillings@1318 8092 s.url = rts.test( cacheURL ) ?
nickjillings@1318 8093
nickjillings@1318 8094 // If there is already a '_' parameter, set its value
nickjillings@1318 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nickjillings@1318 8096
nickjillings@1318 8097 // Otherwise add one to the end
nickjillings@1318 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nickjillings@1318 8099 }
nickjillings@1318 8100 }
nickjillings@1318 8101
nickjillings@1318 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1318 8103 if ( s.ifModified ) {
nickjillings@1318 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nickjillings@1318 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nickjillings@1318 8106 }
nickjillings@1318 8107 if ( jQuery.etag[ cacheURL ] ) {
nickjillings@1318 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nickjillings@1318 8109 }
nickjillings@1318 8110 }
nickjillings@1318 8111
nickjillings@1318 8112 // Set the correct header, if data is being sent
nickjillings@1318 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nickjillings@1318 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nickjillings@1318 8115 }
nickjillings@1318 8116
nickjillings@1318 8117 // Set the Accepts header for the server, depending on the dataType
nickjillings@1318 8118 jqXHR.setRequestHeader(
nickjillings@1318 8119 "Accept",
nickjillings@1318 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nickjillings@1318 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nickjillings@1318 8122 s.accepts[ "*" ]
nickjillings@1318 8123 );
nickjillings@1318 8124
nickjillings@1318 8125 // Check for headers option
nickjillings@1318 8126 for ( i in s.headers ) {
nickjillings@1318 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nickjillings@1318 8128 }
nickjillings@1318 8129
nickjillings@1318 8130 // Allow custom headers/mimetypes and early abort
nickjillings@1318 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nickjillings@1318 8132 // Abort if not done already and return
nickjillings@1318 8133 return jqXHR.abort();
nickjillings@1318 8134 }
nickjillings@1318 8135
nickjillings@1318 8136 // Aborting is no longer a cancellation
nickjillings@1318 8137 strAbort = "abort";
nickjillings@1318 8138
nickjillings@1318 8139 // Install callbacks on deferreds
nickjillings@1318 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nickjillings@1318 8141 jqXHR[ i ]( s[ i ] );
nickjillings@1318 8142 }
nickjillings@1318 8143
nickjillings@1318 8144 // Get transport
nickjillings@1318 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nickjillings@1318 8146
nickjillings@1318 8147 // If no transport, we auto-abort
nickjillings@1318 8148 if ( !transport ) {
nickjillings@1318 8149 done( -1, "No Transport" );
nickjillings@1318 8150 } else {
nickjillings@1318 8151 jqXHR.readyState = 1;
nickjillings@1318 8152
nickjillings@1318 8153 // Send global event
nickjillings@1318 8154 if ( fireGlobals ) {
nickjillings@1318 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nickjillings@1318 8156 }
nickjillings@1318 8157 // Timeout
nickjillings@1318 8158 if ( s.async && s.timeout > 0 ) {
nickjillings@1318 8159 timeoutTimer = setTimeout(function() {
nickjillings@1318 8160 jqXHR.abort("timeout");
nickjillings@1318 8161 }, s.timeout );
nickjillings@1318 8162 }
nickjillings@1318 8163
nickjillings@1318 8164 try {
nickjillings@1318 8165 state = 1;
nickjillings@1318 8166 transport.send( requestHeaders, done );
nickjillings@1318 8167 } catch ( e ) {
nickjillings@1318 8168 // Propagate exception as error if not done
nickjillings@1318 8169 if ( state < 2 ) {
nickjillings@1318 8170 done( -1, e );
nickjillings@1318 8171 // Simply rethrow otherwise
nickjillings@1318 8172 } else {
nickjillings@1318 8173 throw e;
nickjillings@1318 8174 }
nickjillings@1318 8175 }
nickjillings@1318 8176 }
nickjillings@1318 8177
nickjillings@1318 8178 // Callback for when everything is done
nickjillings@1318 8179 function done( status, nativeStatusText, responses, headers ) {
nickjillings@1318 8180 var isSuccess, success, error, response, modified,
nickjillings@1318 8181 statusText = nativeStatusText;
nickjillings@1318 8182
nickjillings@1318 8183 // Called once
nickjillings@1318 8184 if ( state === 2 ) {
nickjillings@1318 8185 return;
nickjillings@1318 8186 }
nickjillings@1318 8187
nickjillings@1318 8188 // State is "done" now
nickjillings@1318 8189 state = 2;
nickjillings@1318 8190
nickjillings@1318 8191 // Clear timeout if it exists
nickjillings@1318 8192 if ( timeoutTimer ) {
nickjillings@1318 8193 clearTimeout( timeoutTimer );
nickjillings@1318 8194 }
nickjillings@1318 8195
nickjillings@1318 8196 // Dereference transport for early garbage collection
nickjillings@1318 8197 // (no matter how long the jqXHR object will be used)
nickjillings@1318 8198 transport = undefined;
nickjillings@1318 8199
nickjillings@1318 8200 // Cache response headers
nickjillings@1318 8201 responseHeadersString = headers || "";
nickjillings@1318 8202
nickjillings@1318 8203 // Set readyState
nickjillings@1318 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nickjillings@1318 8205
nickjillings@1318 8206 // Determine if successful
nickjillings@1318 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nickjillings@1318 8208
nickjillings@1318 8209 // Get response data
nickjillings@1318 8210 if ( responses ) {
nickjillings@1318 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nickjillings@1318 8212 }
nickjillings@1318 8213
nickjillings@1318 8214 // Convert no matter what (that way responseXXX fields are always set)
nickjillings@1318 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nickjillings@1318 8216
nickjillings@1318 8217 // If successful, handle type chaining
nickjillings@1318 8218 if ( isSuccess ) {
nickjillings@1318 8219
nickjillings@1318 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1318 8221 if ( s.ifModified ) {
nickjillings@1318 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nickjillings@1318 8223 if ( modified ) {
nickjillings@1318 8224 jQuery.lastModified[ cacheURL ] = modified;
nickjillings@1318 8225 }
nickjillings@1318 8226 modified = jqXHR.getResponseHeader("etag");
nickjillings@1318 8227 if ( modified ) {
nickjillings@1318 8228 jQuery.etag[ cacheURL ] = modified;
nickjillings@1318 8229 }
nickjillings@1318 8230 }
nickjillings@1318 8231
nickjillings@1318 8232 // if no content
nickjillings@1318 8233 if ( status === 204 || s.type === "HEAD" ) {
nickjillings@1318 8234 statusText = "nocontent";
nickjillings@1318 8235
nickjillings@1318 8236 // if not modified
nickjillings@1318 8237 } else if ( status === 304 ) {
nickjillings@1318 8238 statusText = "notmodified";
nickjillings@1318 8239
nickjillings@1318 8240 // If we have data, let's convert it
nickjillings@1318 8241 } else {
nickjillings@1318 8242 statusText = response.state;
nickjillings@1318 8243 success = response.data;
nickjillings@1318 8244 error = response.error;
nickjillings@1318 8245 isSuccess = !error;
nickjillings@1318 8246 }
nickjillings@1318 8247 } else {
nickjillings@1318 8248 // Extract error from statusText and normalize for non-aborts
nickjillings@1318 8249 error = statusText;
nickjillings@1318 8250 if ( status || !statusText ) {
nickjillings@1318 8251 statusText = "error";
nickjillings@1318 8252 if ( status < 0 ) {
nickjillings@1318 8253 status = 0;
nickjillings@1318 8254 }
nickjillings@1318 8255 }
nickjillings@1318 8256 }
nickjillings@1318 8257
nickjillings@1318 8258 // Set data for the fake xhr object
nickjillings@1318 8259 jqXHR.status = status;
nickjillings@1318 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nickjillings@1318 8261
nickjillings@1318 8262 // Success/Error
nickjillings@1318 8263 if ( isSuccess ) {
nickjillings@1318 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nickjillings@1318 8265 } else {
nickjillings@1318 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nickjillings@1318 8267 }
nickjillings@1318 8268
nickjillings@1318 8269 // Status-dependent callbacks
nickjillings@1318 8270 jqXHR.statusCode( statusCode );
nickjillings@1318 8271 statusCode = undefined;
nickjillings@1318 8272
nickjillings@1318 8273 if ( fireGlobals ) {
nickjillings@1318 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nickjillings@1318 8275 [ jqXHR, s, isSuccess ? success : error ] );
nickjillings@1318 8276 }
nickjillings@1318 8277
nickjillings@1318 8278 // Complete
nickjillings@1318 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nickjillings@1318 8280
nickjillings@1318 8281 if ( fireGlobals ) {
nickjillings@1318 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nickjillings@1318 8283 // Handle the global AJAX counter
nickjillings@1318 8284 if ( !( --jQuery.active ) ) {
nickjillings@1318 8285 jQuery.event.trigger("ajaxStop");
nickjillings@1318 8286 }
nickjillings@1318 8287 }
nickjillings@1318 8288 }
nickjillings@1318 8289
nickjillings@1318 8290 return jqXHR;
nickjillings@1318 8291 },
nickjillings@1318 8292
nickjillings@1318 8293 getJSON: function( url, data, callback ) {
nickjillings@1318 8294 return jQuery.get( url, data, callback, "json" );
nickjillings@1318 8295 },
nickjillings@1318 8296
nickjillings@1318 8297 getScript: function( url, callback ) {
nickjillings@1318 8298 return jQuery.get( url, undefined, callback, "script" );
nickjillings@1318 8299 }
nickjillings@1318 8300 });
nickjillings@1318 8301
nickjillings@1318 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nickjillings@1318 8303 jQuery[ method ] = function( url, data, callback, type ) {
nickjillings@1318 8304 // Shift arguments if data argument was omitted
nickjillings@1318 8305 if ( jQuery.isFunction( data ) ) {
nickjillings@1318 8306 type = type || callback;
nickjillings@1318 8307 callback = data;
nickjillings@1318 8308 data = undefined;
nickjillings@1318 8309 }
nickjillings@1318 8310
nickjillings@1318 8311 return jQuery.ajax({
nickjillings@1318 8312 url: url,
nickjillings@1318 8313 type: method,
nickjillings@1318 8314 dataType: type,
nickjillings@1318 8315 data: data,
nickjillings@1318 8316 success: callback
nickjillings@1318 8317 });
nickjillings@1318 8318 };
nickjillings@1318 8319 });
nickjillings@1318 8320
nickjillings@1318 8321
nickjillings@1318 8322 jQuery._evalUrl = function( url ) {
nickjillings@1318 8323 return jQuery.ajax({
nickjillings@1318 8324 url: url,
nickjillings@1318 8325 type: "GET",
nickjillings@1318 8326 dataType: "script",
nickjillings@1318 8327 async: false,
nickjillings@1318 8328 global: false,
nickjillings@1318 8329 "throws": true
nickjillings@1318 8330 });
nickjillings@1318 8331 };
nickjillings@1318 8332
nickjillings@1318 8333
nickjillings@1318 8334 jQuery.fn.extend({
nickjillings@1318 8335 wrapAll: function( html ) {
nickjillings@1318 8336 var wrap;
nickjillings@1318 8337
nickjillings@1318 8338 if ( jQuery.isFunction( html ) ) {
nickjillings@1318 8339 return this.each(function( i ) {
nickjillings@1318 8340 jQuery( this ).wrapAll( html.call(this, i) );
nickjillings@1318 8341 });
nickjillings@1318 8342 }
nickjillings@1318 8343
nickjillings@1318 8344 if ( this[ 0 ] ) {
nickjillings@1318 8345
nickjillings@1318 8346 // The elements to wrap the target around
nickjillings@1318 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nickjillings@1318 8348
nickjillings@1318 8349 if ( this[ 0 ].parentNode ) {
nickjillings@1318 8350 wrap.insertBefore( this[ 0 ] );
nickjillings@1318 8351 }
nickjillings@1318 8352
nickjillings@1318 8353 wrap.map(function() {
nickjillings@1318 8354 var elem = this;
nickjillings@1318 8355
nickjillings@1318 8356 while ( elem.firstElementChild ) {
nickjillings@1318 8357 elem = elem.firstElementChild;
nickjillings@1318 8358 }
nickjillings@1318 8359
nickjillings@1318 8360 return elem;
nickjillings@1318 8361 }).append( this );
nickjillings@1318 8362 }
nickjillings@1318 8363
nickjillings@1318 8364 return this;
nickjillings@1318 8365 },
nickjillings@1318 8366
nickjillings@1318 8367 wrapInner: function( html ) {
nickjillings@1318 8368 if ( jQuery.isFunction( html ) ) {
nickjillings@1318 8369 return this.each(function( i ) {
nickjillings@1318 8370 jQuery( this ).wrapInner( html.call(this, i) );
nickjillings@1318 8371 });
nickjillings@1318 8372 }
nickjillings@1318 8373
nickjillings@1318 8374 return this.each(function() {
nickjillings@1318 8375 var self = jQuery( this ),
nickjillings@1318 8376 contents = self.contents();
nickjillings@1318 8377
nickjillings@1318 8378 if ( contents.length ) {
nickjillings@1318 8379 contents.wrapAll( html );
nickjillings@1318 8380
nickjillings@1318 8381 } else {
nickjillings@1318 8382 self.append( html );
nickjillings@1318 8383 }
nickjillings@1318 8384 });
nickjillings@1318 8385 },
nickjillings@1318 8386
nickjillings@1318 8387 wrap: function( html ) {
nickjillings@1318 8388 var isFunction = jQuery.isFunction( html );
nickjillings@1318 8389
nickjillings@1318 8390 return this.each(function( i ) {
nickjillings@1318 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nickjillings@1318 8392 });
nickjillings@1318 8393 },
nickjillings@1318 8394
nickjillings@1318 8395 unwrap: function() {
nickjillings@1318 8396 return this.parent().each(function() {
nickjillings@1318 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nickjillings@1318 8398 jQuery( this ).replaceWith( this.childNodes );
nickjillings@1318 8399 }
nickjillings@1318 8400 }).end();
nickjillings@1318 8401 }
nickjillings@1318 8402 });
nickjillings@1318 8403
nickjillings@1318 8404
nickjillings@1318 8405 jQuery.expr.filters.hidden = function( elem ) {
nickjillings@1318 8406 // Support: Opera <= 12.12
nickjillings@1318 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nickjillings@1318 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nickjillings@1318 8409 };
nickjillings@1318 8410 jQuery.expr.filters.visible = function( elem ) {
nickjillings@1318 8411 return !jQuery.expr.filters.hidden( elem );
nickjillings@1318 8412 };
nickjillings@1318 8413
nickjillings@1318 8414
nickjillings@1318 8415
nickjillings@1318 8416
nickjillings@1318 8417 var r20 = /%20/g,
nickjillings@1318 8418 rbracket = /\[\]$/,
nickjillings@1318 8419 rCRLF = /\r?\n/g,
nickjillings@1318 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nickjillings@1318 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nickjillings@1318 8422
nickjillings@1318 8423 function buildParams( prefix, obj, traditional, add ) {
nickjillings@1318 8424 var name;
nickjillings@1318 8425
nickjillings@1318 8426 if ( jQuery.isArray( obj ) ) {
nickjillings@1318 8427 // Serialize array item.
nickjillings@1318 8428 jQuery.each( obj, function( i, v ) {
nickjillings@1318 8429 if ( traditional || rbracket.test( prefix ) ) {
nickjillings@1318 8430 // Treat each array item as a scalar.
nickjillings@1318 8431 add( prefix, v );
nickjillings@1318 8432
nickjillings@1318 8433 } else {
nickjillings@1318 8434 // Item is non-scalar (array or object), encode its numeric index.
nickjillings@1318 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nickjillings@1318 8436 }
nickjillings@1318 8437 });
nickjillings@1318 8438
nickjillings@1318 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nickjillings@1318 8440 // Serialize object item.
nickjillings@1318 8441 for ( name in obj ) {
nickjillings@1318 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nickjillings@1318 8443 }
nickjillings@1318 8444
nickjillings@1318 8445 } else {
nickjillings@1318 8446 // Serialize scalar item.
nickjillings@1318 8447 add( prefix, obj );
nickjillings@1318 8448 }
nickjillings@1318 8449 }
nickjillings@1318 8450
nickjillings@1318 8451 // Serialize an array of form elements or a set of
nickjillings@1318 8452 // key/values into a query string
nickjillings@1318 8453 jQuery.param = function( a, traditional ) {
nickjillings@1318 8454 var prefix,
nickjillings@1318 8455 s = [],
nickjillings@1318 8456 add = function( key, value ) {
nickjillings@1318 8457 // If value is a function, invoke it and return its value
nickjillings@1318 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nickjillings@1318 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nickjillings@1318 8460 };
nickjillings@1318 8461
nickjillings@1318 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nickjillings@1318 8463 if ( traditional === undefined ) {
nickjillings@1318 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nickjillings@1318 8465 }
nickjillings@1318 8466
nickjillings@1318 8467 // If an array was passed in, assume that it is an array of form elements.
nickjillings@1318 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nickjillings@1318 8469 // Serialize the form elements
nickjillings@1318 8470 jQuery.each( a, function() {
nickjillings@1318 8471 add( this.name, this.value );
nickjillings@1318 8472 });
nickjillings@1318 8473
nickjillings@1318 8474 } else {
nickjillings@1318 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nickjillings@1318 8476 // did it), otherwise encode params recursively.
nickjillings@1318 8477 for ( prefix in a ) {
nickjillings@1318 8478 buildParams( prefix, a[ prefix ], traditional, add );
nickjillings@1318 8479 }
nickjillings@1318 8480 }
nickjillings@1318 8481
nickjillings@1318 8482 // Return the resulting serialization
nickjillings@1318 8483 return s.join( "&" ).replace( r20, "+" );
nickjillings@1318 8484 };
nickjillings@1318 8485
nickjillings@1318 8486 jQuery.fn.extend({
nickjillings@1318 8487 serialize: function() {
nickjillings@1318 8488 return jQuery.param( this.serializeArray() );
nickjillings@1318 8489 },
nickjillings@1318 8490 serializeArray: function() {
nickjillings@1318 8491 return this.map(function() {
nickjillings@1318 8492 // Can add propHook for "elements" to filter or add form elements
nickjillings@1318 8493 var elements = jQuery.prop( this, "elements" );
nickjillings@1318 8494 return elements ? jQuery.makeArray( elements ) : this;
nickjillings@1318 8495 })
nickjillings@1318 8496 .filter(function() {
nickjillings@1318 8497 var type = this.type;
nickjillings@1318 8498
nickjillings@1318 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nickjillings@1318 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nickjillings@1318 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nickjillings@1318 8502 ( this.checked || !rcheckableType.test( type ) );
nickjillings@1318 8503 })
nickjillings@1318 8504 .map(function( i, elem ) {
nickjillings@1318 8505 var val = jQuery( this ).val();
nickjillings@1318 8506
nickjillings@1318 8507 return val == null ?
nickjillings@1318 8508 null :
nickjillings@1318 8509 jQuery.isArray( val ) ?
nickjillings@1318 8510 jQuery.map( val, function( val ) {
nickjillings@1318 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1318 8512 }) :
nickjillings@1318 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1318 8514 }).get();
nickjillings@1318 8515 }
nickjillings@1318 8516 });
nickjillings@1318 8517
nickjillings@1318 8518
nickjillings@1318 8519 jQuery.ajaxSettings.xhr = function() {
nickjillings@1318 8520 try {
nickjillings@1318 8521 return new XMLHttpRequest();
nickjillings@1318 8522 } catch( e ) {}
nickjillings@1318 8523 };
nickjillings@1318 8524
nickjillings@1318 8525 var xhrId = 0,
nickjillings@1318 8526 xhrCallbacks = {},
nickjillings@1318 8527 xhrSuccessStatus = {
nickjillings@1318 8528 // file protocol always yields status code 0, assume 200
nickjillings@1318 8529 0: 200,
nickjillings@1318 8530 // Support: IE9
nickjillings@1318 8531 // #1450: sometimes IE returns 1223 when it should be 204
nickjillings@1318 8532 1223: 204
nickjillings@1318 8533 },
nickjillings@1318 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nickjillings@1318 8535
nickjillings@1318 8536 // Support: IE9
nickjillings@1318 8537 // Open requests must be manually aborted on unload (#5280)
nickjillings@1318 8538 // See https://support.microsoft.com/kb/2856746 for more info
nickjillings@1318 8539 if ( window.attachEvent ) {
nickjillings@1318 8540 window.attachEvent( "onunload", function() {
nickjillings@1318 8541 for ( var key in xhrCallbacks ) {
nickjillings@1318 8542 xhrCallbacks[ key ]();
nickjillings@1318 8543 }
nickjillings@1318 8544 });
nickjillings@1318 8545 }
nickjillings@1318 8546
nickjillings@1318 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nickjillings@1318 8548 support.ajax = xhrSupported = !!xhrSupported;
nickjillings@1318 8549
nickjillings@1318 8550 jQuery.ajaxTransport(function( options ) {
nickjillings@1318 8551 var callback;
nickjillings@1318 8552
nickjillings@1318 8553 // Cross domain only allowed if supported through XMLHttpRequest
nickjillings@1318 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nickjillings@1318 8555 return {
nickjillings@1318 8556 send: function( headers, complete ) {
nickjillings@1318 8557 var i,
nickjillings@1318 8558 xhr = options.xhr(),
nickjillings@1318 8559 id = ++xhrId;
nickjillings@1318 8560
nickjillings@1318 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nickjillings@1318 8562
nickjillings@1318 8563 // Apply custom fields if provided
nickjillings@1318 8564 if ( options.xhrFields ) {
nickjillings@1318 8565 for ( i in options.xhrFields ) {
nickjillings@1318 8566 xhr[ i ] = options.xhrFields[ i ];
nickjillings@1318 8567 }
nickjillings@1318 8568 }
nickjillings@1318 8569
nickjillings@1318 8570 // Override mime type if needed
nickjillings@1318 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nickjillings@1318 8572 xhr.overrideMimeType( options.mimeType );
nickjillings@1318 8573 }
nickjillings@1318 8574
nickjillings@1318 8575 // X-Requested-With header
nickjillings@1318 8576 // For cross-domain requests, seeing as conditions for a preflight are
nickjillings@1318 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nickjillings@1318 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nickjillings@1318 8579 // For same-domain requests, won't change header if already provided.
nickjillings@1318 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nickjillings@1318 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nickjillings@1318 8582 }
nickjillings@1318 8583
nickjillings@1318 8584 // Set headers
nickjillings@1318 8585 for ( i in headers ) {
nickjillings@1318 8586 xhr.setRequestHeader( i, headers[ i ] );
nickjillings@1318 8587 }
nickjillings@1318 8588
nickjillings@1318 8589 // Callback
nickjillings@1318 8590 callback = function( type ) {
nickjillings@1318 8591 return function() {
nickjillings@1318 8592 if ( callback ) {
nickjillings@1318 8593 delete xhrCallbacks[ id ];
nickjillings@1318 8594 callback = xhr.onload = xhr.onerror = null;
nickjillings@1318 8595
nickjillings@1318 8596 if ( type === "abort" ) {
nickjillings@1318 8597 xhr.abort();
nickjillings@1318 8598 } else if ( type === "error" ) {
nickjillings@1318 8599 complete(
nickjillings@1318 8600 // file: protocol always yields status 0; see #8605, #14207
nickjillings@1318 8601 xhr.status,
nickjillings@1318 8602 xhr.statusText
nickjillings@1318 8603 );
nickjillings@1318 8604 } else {
nickjillings@1318 8605 complete(
nickjillings@1318 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nickjillings@1318 8607 xhr.statusText,
nickjillings@1318 8608 // Support: IE9
nickjillings@1318 8609 // Accessing binary-data responseText throws an exception
nickjillings@1318 8610 // (#11426)
nickjillings@1318 8611 typeof xhr.responseText === "string" ? {
nickjillings@1318 8612 text: xhr.responseText
nickjillings@1318 8613 } : undefined,
nickjillings@1318 8614 xhr.getAllResponseHeaders()
nickjillings@1318 8615 );
nickjillings@1318 8616 }
nickjillings@1318 8617 }
nickjillings@1318 8618 };
nickjillings@1318 8619 };
nickjillings@1318 8620
nickjillings@1318 8621 // Listen to events
nickjillings@1318 8622 xhr.onload = callback();
nickjillings@1318 8623 xhr.onerror = callback("error");
nickjillings@1318 8624
nickjillings@1318 8625 // Create the abort callback
nickjillings@1318 8626 callback = xhrCallbacks[ id ] = callback("abort");
nickjillings@1318 8627
nickjillings@1318 8628 try {
nickjillings@1318 8629 // Do send the request (this may raise an exception)
nickjillings@1318 8630 xhr.send( options.hasContent && options.data || null );
nickjillings@1318 8631 } catch ( e ) {
nickjillings@1318 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nickjillings@1318 8633 if ( callback ) {
nickjillings@1318 8634 throw e;
nickjillings@1318 8635 }
nickjillings@1318 8636 }
nickjillings@1318 8637 },
nickjillings@1318 8638
nickjillings@1318 8639 abort: function() {
nickjillings@1318 8640 if ( callback ) {
nickjillings@1318 8641 callback();
nickjillings@1318 8642 }
nickjillings@1318 8643 }
nickjillings@1318 8644 };
nickjillings@1318 8645 }
nickjillings@1318 8646 });
nickjillings@1318 8647
nickjillings@1318 8648
nickjillings@1318 8649
nickjillings@1318 8650
nickjillings@1318 8651 // Install script dataType
nickjillings@1318 8652 jQuery.ajaxSetup({
nickjillings@1318 8653 accepts: {
nickjillings@1318 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nickjillings@1318 8655 },
nickjillings@1318 8656 contents: {
nickjillings@1318 8657 script: /(?:java|ecma)script/
nickjillings@1318 8658 },
nickjillings@1318 8659 converters: {
nickjillings@1318 8660 "text script": function( text ) {
nickjillings@1318 8661 jQuery.globalEval( text );
nickjillings@1318 8662 return text;
nickjillings@1318 8663 }
nickjillings@1318 8664 }
nickjillings@1318 8665 });
nickjillings@1318 8666
nickjillings@1318 8667 // Handle cache's special case and crossDomain
nickjillings@1318 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nickjillings@1318 8669 if ( s.cache === undefined ) {
nickjillings@1318 8670 s.cache = false;
nickjillings@1318 8671 }
nickjillings@1318 8672 if ( s.crossDomain ) {
nickjillings@1318 8673 s.type = "GET";
nickjillings@1318 8674 }
nickjillings@1318 8675 });
nickjillings@1318 8676
nickjillings@1318 8677 // Bind script tag hack transport
nickjillings@1318 8678 jQuery.ajaxTransport( "script", function( s ) {
nickjillings@1318 8679 // This transport only deals with cross domain requests
nickjillings@1318 8680 if ( s.crossDomain ) {
nickjillings@1318 8681 var script, callback;
nickjillings@1318 8682 return {
nickjillings@1318 8683 send: function( _, complete ) {
nickjillings@1318 8684 script = jQuery("<script>").prop({
nickjillings@1318 8685 async: true,
nickjillings@1318 8686 charset: s.scriptCharset,
nickjillings@1318 8687 src: s.url
nickjillings@1318 8688 }).on(
nickjillings@1318 8689 "load error",
nickjillings@1318 8690 callback = function( evt ) {
nickjillings@1318 8691 script.remove();
nickjillings@1318 8692 callback = null;
nickjillings@1318 8693 if ( evt ) {
nickjillings@1318 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nickjillings@1318 8695 }
nickjillings@1318 8696 }
nickjillings@1318 8697 );
nickjillings@1318 8698 document.head.appendChild( script[ 0 ] );
nickjillings@1318 8699 },
nickjillings@1318 8700 abort: function() {
nickjillings@1318 8701 if ( callback ) {
nickjillings@1318 8702 callback();
nickjillings@1318 8703 }
nickjillings@1318 8704 }
nickjillings@1318 8705 };
nickjillings@1318 8706 }
nickjillings@1318 8707 });
nickjillings@1318 8708
nickjillings@1318 8709
nickjillings@1318 8710
nickjillings@1318 8711
nickjillings@1318 8712 var oldCallbacks = [],
nickjillings@1318 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nickjillings@1318 8714
nickjillings@1318 8715 // Default jsonp settings
nickjillings@1318 8716 jQuery.ajaxSetup({
nickjillings@1318 8717 jsonp: "callback",
nickjillings@1318 8718 jsonpCallback: function() {
nickjillings@1318 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nickjillings@1318 8720 this[ callback ] = true;
nickjillings@1318 8721 return callback;
nickjillings@1318 8722 }
nickjillings@1318 8723 });
nickjillings@1318 8724
nickjillings@1318 8725 // Detect, normalize options and install callbacks for jsonp requests
nickjillings@1318 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nickjillings@1318 8727
nickjillings@1318 8728 var callbackName, overwritten, responseContainer,
nickjillings@1318 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nickjillings@1318 8730 "url" :
nickjillings@1318 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nickjillings@1318 8732 );
nickjillings@1318 8733
nickjillings@1318 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nickjillings@1318 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nickjillings@1318 8736
nickjillings@1318 8737 // Get callback name, remembering preexisting value associated with it
nickjillings@1318 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nickjillings@1318 8739 s.jsonpCallback() :
nickjillings@1318 8740 s.jsonpCallback;
nickjillings@1318 8741
nickjillings@1318 8742 // Insert callback into url or form data
nickjillings@1318 8743 if ( jsonProp ) {
nickjillings@1318 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nickjillings@1318 8745 } else if ( s.jsonp !== false ) {
nickjillings@1318 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nickjillings@1318 8747 }
nickjillings@1318 8748
nickjillings@1318 8749 // Use data converter to retrieve json after script execution
nickjillings@1318 8750 s.converters["script json"] = function() {
nickjillings@1318 8751 if ( !responseContainer ) {
nickjillings@1318 8752 jQuery.error( callbackName + " was not called" );
nickjillings@1318 8753 }
nickjillings@1318 8754 return responseContainer[ 0 ];
nickjillings@1318 8755 };
nickjillings@1318 8756
nickjillings@1318 8757 // force json dataType
nickjillings@1318 8758 s.dataTypes[ 0 ] = "json";
nickjillings@1318 8759
nickjillings@1318 8760 // Install callback
nickjillings@1318 8761 overwritten = window[ callbackName ];
nickjillings@1318 8762 window[ callbackName ] = function() {
nickjillings@1318 8763 responseContainer = arguments;
nickjillings@1318 8764 };
nickjillings@1318 8765
nickjillings@1318 8766 // Clean-up function (fires after converters)
nickjillings@1318 8767 jqXHR.always(function() {
nickjillings@1318 8768 // Restore preexisting value
nickjillings@1318 8769 window[ callbackName ] = overwritten;
nickjillings@1318 8770
nickjillings@1318 8771 // Save back as free
nickjillings@1318 8772 if ( s[ callbackName ] ) {
nickjillings@1318 8773 // make sure that re-using the options doesn't screw things around
nickjillings@1318 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nickjillings@1318 8775
nickjillings@1318 8776 // save the callback name for future use
nickjillings@1318 8777 oldCallbacks.push( callbackName );
nickjillings@1318 8778 }
nickjillings@1318 8779
nickjillings@1318 8780 // Call if it was a function and we have a response
nickjillings@1318 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nickjillings@1318 8782 overwritten( responseContainer[ 0 ] );
nickjillings@1318 8783 }
nickjillings@1318 8784
nickjillings@1318 8785 responseContainer = overwritten = undefined;
nickjillings@1318 8786 });
nickjillings@1318 8787
nickjillings@1318 8788 // Delegate to script
nickjillings@1318 8789 return "script";
nickjillings@1318 8790 }
nickjillings@1318 8791 });
nickjillings@1318 8792
nickjillings@1318 8793
nickjillings@1318 8794
nickjillings@1318 8795
nickjillings@1318 8796 // data: string of html
nickjillings@1318 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nickjillings@1318 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nickjillings@1318 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nickjillings@1318 8800 if ( !data || typeof data !== "string" ) {
nickjillings@1318 8801 return null;
nickjillings@1318 8802 }
nickjillings@1318 8803 if ( typeof context === "boolean" ) {
nickjillings@1318 8804 keepScripts = context;
nickjillings@1318 8805 context = false;
nickjillings@1318 8806 }
nickjillings@1318 8807 context = context || document;
nickjillings@1318 8808
nickjillings@1318 8809 var parsed = rsingleTag.exec( data ),
nickjillings@1318 8810 scripts = !keepScripts && [];
nickjillings@1318 8811
nickjillings@1318 8812 // Single tag
nickjillings@1318 8813 if ( parsed ) {
nickjillings@1318 8814 return [ context.createElement( parsed[1] ) ];
nickjillings@1318 8815 }
nickjillings@1318 8816
nickjillings@1318 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nickjillings@1318 8818
nickjillings@1318 8819 if ( scripts && scripts.length ) {
nickjillings@1318 8820 jQuery( scripts ).remove();
nickjillings@1318 8821 }
nickjillings@1318 8822
nickjillings@1318 8823 return jQuery.merge( [], parsed.childNodes );
nickjillings@1318 8824 };
nickjillings@1318 8825
nickjillings@1318 8826
nickjillings@1318 8827 // Keep a copy of the old load method
nickjillings@1318 8828 var _load = jQuery.fn.load;
nickjillings@1318 8829
nickjillings@1318 8830 /**
nickjillings@1318 8831 * Load a url into a page
nickjillings@1318 8832 */
nickjillings@1318 8833 jQuery.fn.load = function( url, params, callback ) {
nickjillings@1318 8834 if ( typeof url !== "string" && _load ) {
nickjillings@1318 8835 return _load.apply( this, arguments );
nickjillings@1318 8836 }
nickjillings@1318 8837
nickjillings@1318 8838 var selector, type, response,
nickjillings@1318 8839 self = this,
nickjillings@1318 8840 off = url.indexOf(" ");
nickjillings@1318 8841
nickjillings@1318 8842 if ( off >= 0 ) {
nickjillings@1318 8843 selector = jQuery.trim( url.slice( off ) );
nickjillings@1318 8844 url = url.slice( 0, off );
nickjillings@1318 8845 }
nickjillings@1318 8846
nickjillings@1318 8847 // If it's a function
nickjillings@1318 8848 if ( jQuery.isFunction( params ) ) {
nickjillings@1318 8849
nickjillings@1318 8850 // We assume that it's the callback
nickjillings@1318 8851 callback = params;
nickjillings@1318 8852 params = undefined;
nickjillings@1318 8853
nickjillings@1318 8854 // Otherwise, build a param string
nickjillings@1318 8855 } else if ( params && typeof params === "object" ) {
nickjillings@1318 8856 type = "POST";
nickjillings@1318 8857 }
nickjillings@1318 8858
nickjillings@1318 8859 // If we have elements to modify, make the request
nickjillings@1318 8860 if ( self.length > 0 ) {
nickjillings@1318 8861 jQuery.ajax({
nickjillings@1318 8862 url: url,
nickjillings@1318 8863
nickjillings@1318 8864 // if "type" variable is undefined, then "GET" method will be used
nickjillings@1318 8865 type: type,
nickjillings@1318 8866 dataType: "html",
nickjillings@1318 8867 data: params
nickjillings@1318 8868 }).done(function( responseText ) {
nickjillings@1318 8869
nickjillings@1318 8870 // Save response for use in complete callback
nickjillings@1318 8871 response = arguments;
nickjillings@1318 8872
nickjillings@1318 8873 self.html( selector ?
nickjillings@1318 8874
nickjillings@1318 8875 // If a selector was specified, locate the right elements in a dummy div
nickjillings@1318 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nickjillings@1318 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nickjillings@1318 8878
nickjillings@1318 8879 // Otherwise use the full result
nickjillings@1318 8880 responseText );
nickjillings@1318 8881
nickjillings@1318 8882 }).complete( callback && function( jqXHR, status ) {
nickjillings@1318 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nickjillings@1318 8884 });
nickjillings@1318 8885 }
nickjillings@1318 8886
nickjillings@1318 8887 return this;
nickjillings@1318 8888 };
nickjillings@1318 8889
nickjillings@1318 8890
nickjillings@1318 8891
nickjillings@1318 8892
nickjillings@1318 8893 // Attach a bunch of functions for handling common AJAX events
nickjillings@1318 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nickjillings@1318 8895 jQuery.fn[ type ] = function( fn ) {
nickjillings@1318 8896 return this.on( type, fn );
nickjillings@1318 8897 };
nickjillings@1318 8898 });
nickjillings@1318 8899
nickjillings@1318 8900
nickjillings@1318 8901
nickjillings@1318 8902
nickjillings@1318 8903 jQuery.expr.filters.animated = function( elem ) {
nickjillings@1318 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nickjillings@1318 8905 return elem === fn.elem;
nickjillings@1318 8906 }).length;
nickjillings@1318 8907 };
nickjillings@1318 8908
nickjillings@1318 8909
nickjillings@1318 8910
nickjillings@1318 8911
nickjillings@1318 8912 var docElem = window.document.documentElement;
nickjillings@1318 8913
nickjillings@1318 8914 /**
nickjillings@1318 8915 * Gets a window from an element
nickjillings@1318 8916 */
nickjillings@1318 8917 function getWindow( elem ) {
nickjillings@1318 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nickjillings@1318 8919 }
nickjillings@1318 8920
nickjillings@1318 8921 jQuery.offset = {
nickjillings@1318 8922 setOffset: function( elem, options, i ) {
nickjillings@1318 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nickjillings@1318 8924 position = jQuery.css( elem, "position" ),
nickjillings@1318 8925 curElem = jQuery( elem ),
nickjillings@1318 8926 props = {};
nickjillings@1318 8927
nickjillings@1318 8928 // Set position first, in-case top/left are set even on static elem
nickjillings@1318 8929 if ( position === "static" ) {
nickjillings@1318 8930 elem.style.position = "relative";
nickjillings@1318 8931 }
nickjillings@1318 8932
nickjillings@1318 8933 curOffset = curElem.offset();
nickjillings@1318 8934 curCSSTop = jQuery.css( elem, "top" );
nickjillings@1318 8935 curCSSLeft = jQuery.css( elem, "left" );
nickjillings@1318 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nickjillings@1318 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nickjillings@1318 8938
nickjillings@1318 8939 // Need to be able to calculate position if either
nickjillings@1318 8940 // top or left is auto and position is either absolute or fixed
nickjillings@1318 8941 if ( calculatePosition ) {
nickjillings@1318 8942 curPosition = curElem.position();
nickjillings@1318 8943 curTop = curPosition.top;
nickjillings@1318 8944 curLeft = curPosition.left;
nickjillings@1318 8945
nickjillings@1318 8946 } else {
nickjillings@1318 8947 curTop = parseFloat( curCSSTop ) || 0;
nickjillings@1318 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nickjillings@1318 8949 }
nickjillings@1318 8950
nickjillings@1318 8951 if ( jQuery.isFunction( options ) ) {
nickjillings@1318 8952 options = options.call( elem, i, curOffset );
nickjillings@1318 8953 }
nickjillings@1318 8954
nickjillings@1318 8955 if ( options.top != null ) {
nickjillings@1318 8956 props.top = ( options.top - curOffset.top ) + curTop;
nickjillings@1318 8957 }
nickjillings@1318 8958 if ( options.left != null ) {
nickjillings@1318 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nickjillings@1318 8960 }
nickjillings@1318 8961
nickjillings@1318 8962 if ( "using" in options ) {
nickjillings@1318 8963 options.using.call( elem, props );
nickjillings@1318 8964
nickjillings@1318 8965 } else {
nickjillings@1318 8966 curElem.css( props );
nickjillings@1318 8967 }
nickjillings@1318 8968 }
nickjillings@1318 8969 };
nickjillings@1318 8970
nickjillings@1318 8971 jQuery.fn.extend({
nickjillings@1318 8972 offset: function( options ) {
nickjillings@1318 8973 if ( arguments.length ) {
nickjillings@1318 8974 return options === undefined ?
nickjillings@1318 8975 this :
nickjillings@1318 8976 this.each(function( i ) {
nickjillings@1318 8977 jQuery.offset.setOffset( this, options, i );
nickjillings@1318 8978 });
nickjillings@1318 8979 }
nickjillings@1318 8980
nickjillings@1318 8981 var docElem, win,
nickjillings@1318 8982 elem = this[ 0 ],
nickjillings@1318 8983 box = { top: 0, left: 0 },
nickjillings@1318 8984 doc = elem && elem.ownerDocument;
nickjillings@1318 8985
nickjillings@1318 8986 if ( !doc ) {
nickjillings@1318 8987 return;
nickjillings@1318 8988 }
nickjillings@1318 8989
nickjillings@1318 8990 docElem = doc.documentElement;
nickjillings@1318 8991
nickjillings@1318 8992 // Make sure it's not a disconnected DOM node
nickjillings@1318 8993 if ( !jQuery.contains( docElem, elem ) ) {
nickjillings@1318 8994 return box;
nickjillings@1318 8995 }
nickjillings@1318 8996
nickjillings@1318 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nickjillings@1318 8998 // If we don't have gBCR, just use 0,0 rather than error
nickjillings@1318 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nickjillings@1318 9000 box = elem.getBoundingClientRect();
nickjillings@1318 9001 }
nickjillings@1318 9002 win = getWindow( doc );
nickjillings@1318 9003 return {
nickjillings@1318 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nickjillings@1318 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nickjillings@1318 9006 };
nickjillings@1318 9007 },
nickjillings@1318 9008
nickjillings@1318 9009 position: function() {
nickjillings@1318 9010 if ( !this[ 0 ] ) {
nickjillings@1318 9011 return;
nickjillings@1318 9012 }
nickjillings@1318 9013
nickjillings@1318 9014 var offsetParent, offset,
nickjillings@1318 9015 elem = this[ 0 ],
nickjillings@1318 9016 parentOffset = { top: 0, left: 0 };
nickjillings@1318 9017
nickjillings@1318 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nickjillings@1318 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nickjillings@1318 9020 // Assume getBoundingClientRect is there when computed position is fixed
nickjillings@1318 9021 offset = elem.getBoundingClientRect();
nickjillings@1318 9022
nickjillings@1318 9023 } else {
nickjillings@1318 9024 // Get *real* offsetParent
nickjillings@1318 9025 offsetParent = this.offsetParent();
nickjillings@1318 9026
nickjillings@1318 9027 // Get correct offsets
nickjillings@1318 9028 offset = this.offset();
nickjillings@1318 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nickjillings@1318 9030 parentOffset = offsetParent.offset();
nickjillings@1318 9031 }
nickjillings@1318 9032
nickjillings@1318 9033 // Add offsetParent borders
nickjillings@1318 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nickjillings@1318 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nickjillings@1318 9036 }
nickjillings@1318 9037
nickjillings@1318 9038 // Subtract parent offsets and element margins
nickjillings@1318 9039 return {
nickjillings@1318 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nickjillings@1318 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nickjillings@1318 9042 };
nickjillings@1318 9043 },
nickjillings@1318 9044
nickjillings@1318 9045 offsetParent: function() {
nickjillings@1318 9046 return this.map(function() {
nickjillings@1318 9047 var offsetParent = this.offsetParent || docElem;
nickjillings@1318 9048
nickjillings@1318 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nickjillings@1318 9050 offsetParent = offsetParent.offsetParent;
nickjillings@1318 9051 }
nickjillings@1318 9052
nickjillings@1318 9053 return offsetParent || docElem;
nickjillings@1318 9054 });
nickjillings@1318 9055 }
nickjillings@1318 9056 });
nickjillings@1318 9057
nickjillings@1318 9058 // Create scrollLeft and scrollTop methods
nickjillings@1318 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nickjillings@1318 9060 var top = "pageYOffset" === prop;
nickjillings@1318 9061
nickjillings@1318 9062 jQuery.fn[ method ] = function( val ) {
nickjillings@1318 9063 return access( this, function( elem, method, val ) {
nickjillings@1318 9064 var win = getWindow( elem );
nickjillings@1318 9065
nickjillings@1318 9066 if ( val === undefined ) {
nickjillings@1318 9067 return win ? win[ prop ] : elem[ method ];
nickjillings@1318 9068 }
nickjillings@1318 9069
nickjillings@1318 9070 if ( win ) {
nickjillings@1318 9071 win.scrollTo(
nickjillings@1318 9072 !top ? val : window.pageXOffset,
nickjillings@1318 9073 top ? val : window.pageYOffset
nickjillings@1318 9074 );
nickjillings@1318 9075
nickjillings@1318 9076 } else {
nickjillings@1318 9077 elem[ method ] = val;
nickjillings@1318 9078 }
nickjillings@1318 9079 }, method, val, arguments.length, null );
nickjillings@1318 9080 };
nickjillings@1318 9081 });
nickjillings@1318 9082
nickjillings@1318 9083 // Support: Safari<7+, Chrome<37+
nickjillings@1318 9084 // Add the top/left cssHooks using jQuery.fn.position
nickjillings@1318 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nickjillings@1318 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nickjillings@1318 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nickjillings@1318 9088 // rather than make the css module depend on the offset module, just check for it here
nickjillings@1318 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nickjillings@1318 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nickjillings@1318 9091 function( elem, computed ) {
nickjillings@1318 9092 if ( computed ) {
nickjillings@1318 9093 computed = curCSS( elem, prop );
nickjillings@1318 9094 // If curCSS returns percentage, fallback to offset
nickjillings@1318 9095 return rnumnonpx.test( computed ) ?
nickjillings@1318 9096 jQuery( elem ).position()[ prop ] + "px" :
nickjillings@1318 9097 computed;
nickjillings@1318 9098 }
nickjillings@1318 9099 }
nickjillings@1318 9100 );
nickjillings@1318 9101 });
nickjillings@1318 9102
nickjillings@1318 9103
nickjillings@1318 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nickjillings@1318 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nickjillings@1318 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nickjillings@1318 9107 // Margin is only for outerHeight, outerWidth
nickjillings@1318 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nickjillings@1318 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nickjillings@1318 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nickjillings@1318 9111
nickjillings@1318 9112 return access( this, function( elem, type, value ) {
nickjillings@1318 9113 var doc;
nickjillings@1318 9114
nickjillings@1318 9115 if ( jQuery.isWindow( elem ) ) {
nickjillings@1318 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nickjillings@1318 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nickjillings@1318 9118 // https://github.com/jquery/jquery/pull/764
nickjillings@1318 9119 return elem.document.documentElement[ "client" + name ];
nickjillings@1318 9120 }
nickjillings@1318 9121
nickjillings@1318 9122 // Get document width or height
nickjillings@1318 9123 if ( elem.nodeType === 9 ) {
nickjillings@1318 9124 doc = elem.documentElement;
nickjillings@1318 9125
nickjillings@1318 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nickjillings@1318 9127 // whichever is greatest
nickjillings@1318 9128 return Math.max(
nickjillings@1318 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nickjillings@1318 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nickjillings@1318 9131 doc[ "client" + name ]
nickjillings@1318 9132 );
nickjillings@1318 9133 }
nickjillings@1318 9134
nickjillings@1318 9135 return value === undefined ?
nickjillings@1318 9136 // Get width or height on the element, requesting but not forcing parseFloat
nickjillings@1318 9137 jQuery.css( elem, type, extra ) :
nickjillings@1318 9138
nickjillings@1318 9139 // Set width or height on the element
nickjillings@1318 9140 jQuery.style( elem, type, value, extra );
nickjillings@1318 9141 }, type, chainable ? margin : undefined, chainable, null );
nickjillings@1318 9142 };
nickjillings@1318 9143 });
nickjillings@1318 9144 });
nickjillings@1318 9145
nickjillings@1318 9146
nickjillings@1318 9147 // The number of elements contained in the matched element set
nickjillings@1318 9148 jQuery.fn.size = function() {
nickjillings@1318 9149 return this.length;
nickjillings@1318 9150 };
nickjillings@1318 9151
nickjillings@1318 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nickjillings@1318 9153
nickjillings@1318 9154
nickjillings@1318 9155
nickjillings@1318 9156
nickjillings@1318 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nickjillings@1318 9158 // files that may use define, but not via a proper concatenation script that
nickjillings@1318 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nickjillings@1318 9160 // way to register. Lowercase jquery is used because AMD module names are
nickjillings@1318 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nickjillings@1318 9162 // file name. Do this after creating the global so that if an AMD module wants
nickjillings@1318 9163 // to call noConflict to hide this version of jQuery, it will work.
nickjillings@1318 9164
nickjillings@1318 9165 // Note that for maximum portability, libraries that are not jQuery should
nickjillings@1318 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nickjillings@1318 9167 // AMD loader is present. jQuery is a special case. For more information, see
nickjillings@1318 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nickjillings@1318 9169
nickjillings@1318 9170 if ( typeof define === "function" && define.amd ) {
nickjillings@1318 9171 define( "jquery", [], function() {
nickjillings@1318 9172 return jQuery;
nickjillings@1318 9173 });
nickjillings@1318 9174 }
nickjillings@1318 9175
nickjillings@1318 9176
nickjillings@1318 9177
nickjillings@1318 9178
nickjillings@1318 9179 var
nickjillings@1318 9180 // Map over jQuery in case of overwrite
nickjillings@1318 9181 _jQuery = window.jQuery,
nickjillings@1318 9182
nickjillings@1318 9183 // Map over the $ in case of overwrite
nickjillings@1318 9184 _$ = window.$;
nickjillings@1318 9185
nickjillings@1318 9186 jQuery.noConflict = function( deep ) {
nickjillings@1318 9187 if ( window.$ === jQuery ) {
nickjillings@1318 9188 window.$ = _$;
nickjillings@1318 9189 }
nickjillings@1318 9190
nickjillings@1318 9191 if ( deep && window.jQuery === jQuery ) {
nickjillings@1318 9192 window.jQuery = _jQuery;
nickjillings@1318 9193 }
nickjillings@1318 9194
nickjillings@1318 9195 return jQuery;
nickjillings@1318 9196 };
nickjillings@1318 9197
nickjillings@1318 9198 // Expose jQuery and $ identifiers, even in AMD
nickjillings@1318 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nickjillings@1318 9200 // and CommonJS for browser emulators (#13566)
nickjillings@1318 9201 if ( typeof noGlobal === strundefined ) {
nickjillings@1318 9202 window.jQuery = window.$ = jQuery;
nickjillings@1318 9203 }
nickjillings@1318 9204
nickjillings@1318 9205
nickjillings@1318 9206
nickjillings@1318 9207
nickjillings@1318 9208 return jQuery;
nickjillings@1318 9209
nickjillings@1318 9210 }));