annotate jquery-2.1.4.js @ 2212:279733b3b67e

Move pythonServer-legacy.py to scripts
author Brecht De Man <b.deman@qmul.ac.uk>
date Wed, 13 Apr 2016 15:46:12 +0100
parents 175cf75946f7
children
rev   line source
nickjillings@1289 1 /*!
nickjillings@1289 2 * jQuery JavaScript Library v2.1.4
nickjillings@1289 3 * http://jquery.com/
nickjillings@1289 4 *
nickjillings@1289 5 * Includes Sizzle.js
nickjillings@1289 6 * http://sizzlejs.com/
nickjillings@1289 7 *
nickjillings@1289 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1289 9 * Released under the MIT license
nickjillings@1289 10 * http://jquery.org/license
nickjillings@1289 11 *
nickjillings@1289 12 * Date: 2015-04-28T16:01Z
nickjillings@1289 13 */
nickjillings@1289 14
nickjillings@1289 15 (function( global, factory ) {
nickjillings@1289 16
nickjillings@1289 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nickjillings@1289 18 // For CommonJS and CommonJS-like environments where a proper `window`
nickjillings@1289 19 // is present, execute the factory and get jQuery.
nickjillings@1289 20 // For environments that do not have a `window` with a `document`
nickjillings@1289 21 // (such as Node.js), expose a factory as module.exports.
nickjillings@1289 22 // This accentuates the need for the creation of a real `window`.
nickjillings@1289 23 // e.g. var jQuery = require("jquery")(window);
nickjillings@1289 24 // See ticket #14549 for more info.
nickjillings@1289 25 module.exports = global.document ?
nickjillings@1289 26 factory( global, true ) :
nickjillings@1289 27 function( w ) {
nickjillings@1289 28 if ( !w.document ) {
nickjillings@1289 29 throw new Error( "jQuery requires a window with a document" );
nickjillings@1289 30 }
nickjillings@1289 31 return factory( w );
nickjillings@1289 32 };
nickjillings@1289 33 } else {
nickjillings@1289 34 factory( global );
nickjillings@1289 35 }
nickjillings@1289 36
nickjillings@1289 37 // Pass this if window is not defined yet
nickjillings@1289 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nickjillings@1289 39
nickjillings@1289 40 // Support: Firefox 18+
nickjillings@1289 41 // Can't be in strict mode, several libs including ASP.NET trace
nickjillings@1289 42 // the stack via arguments.caller.callee and Firefox dies if
nickjillings@1289 43 // you try to trace through "use strict" call chains. (#13335)
nickjillings@1289 44 //
nickjillings@1289 45
nickjillings@1289 46 var arr = [];
nickjillings@1289 47
nickjillings@1289 48 var slice = arr.slice;
nickjillings@1289 49
nickjillings@1289 50 var concat = arr.concat;
nickjillings@1289 51
nickjillings@1289 52 var push = arr.push;
nickjillings@1289 53
nickjillings@1289 54 var indexOf = arr.indexOf;
nickjillings@1289 55
nickjillings@1289 56 var class2type = {};
nickjillings@1289 57
nickjillings@1289 58 var toString = class2type.toString;
nickjillings@1289 59
nickjillings@1289 60 var hasOwn = class2type.hasOwnProperty;
nickjillings@1289 61
nickjillings@1289 62 var support = {};
nickjillings@1289 63
nickjillings@1289 64
nickjillings@1289 65
nickjillings@1289 66 var
nickjillings@1289 67 // Use the correct document accordingly with window argument (sandbox)
nickjillings@1289 68 document = window.document,
nickjillings@1289 69
nickjillings@1289 70 version = "2.1.4",
nickjillings@1289 71
nickjillings@1289 72 // Define a local copy of jQuery
nickjillings@1289 73 jQuery = function( selector, context ) {
nickjillings@1289 74 // The jQuery object is actually just the init constructor 'enhanced'
nickjillings@1289 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nickjillings@1289 76 return new jQuery.fn.init( selector, context );
nickjillings@1289 77 },
nickjillings@1289 78
nickjillings@1289 79 // Support: Android<4.1
nickjillings@1289 80 // Make sure we trim BOM and NBSP
nickjillings@1289 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nickjillings@1289 82
nickjillings@1289 83 // Matches dashed string for camelizing
nickjillings@1289 84 rmsPrefix = /^-ms-/,
nickjillings@1289 85 rdashAlpha = /-([\da-z])/gi,
nickjillings@1289 86
nickjillings@1289 87 // Used by jQuery.camelCase as callback to replace()
nickjillings@1289 88 fcamelCase = function( all, letter ) {
nickjillings@1289 89 return letter.toUpperCase();
nickjillings@1289 90 };
nickjillings@1289 91
nickjillings@1289 92 jQuery.fn = jQuery.prototype = {
nickjillings@1289 93 // The current version of jQuery being used
nickjillings@1289 94 jquery: version,
nickjillings@1289 95
nickjillings@1289 96 constructor: jQuery,
nickjillings@1289 97
nickjillings@1289 98 // Start with an empty selector
nickjillings@1289 99 selector: "",
nickjillings@1289 100
nickjillings@1289 101 // The default length of a jQuery object is 0
nickjillings@1289 102 length: 0,
nickjillings@1289 103
nickjillings@1289 104 toArray: function() {
nickjillings@1289 105 return slice.call( this );
nickjillings@1289 106 },
nickjillings@1289 107
nickjillings@1289 108 // Get the Nth element in the matched element set OR
nickjillings@1289 109 // Get the whole matched element set as a clean array
nickjillings@1289 110 get: function( num ) {
nickjillings@1289 111 return num != null ?
nickjillings@1289 112
nickjillings@1289 113 // Return just the one element from the set
nickjillings@1289 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nickjillings@1289 115
nickjillings@1289 116 // Return all the elements in a clean array
nickjillings@1289 117 slice.call( this );
nickjillings@1289 118 },
nickjillings@1289 119
nickjillings@1289 120 // Take an array of elements and push it onto the stack
nickjillings@1289 121 // (returning the new matched element set)
nickjillings@1289 122 pushStack: function( elems ) {
nickjillings@1289 123
nickjillings@1289 124 // Build a new jQuery matched element set
nickjillings@1289 125 var ret = jQuery.merge( this.constructor(), elems );
nickjillings@1289 126
nickjillings@1289 127 // Add the old object onto the stack (as a reference)
nickjillings@1289 128 ret.prevObject = this;
nickjillings@1289 129 ret.context = this.context;
nickjillings@1289 130
nickjillings@1289 131 // Return the newly-formed element set
nickjillings@1289 132 return ret;
nickjillings@1289 133 },
nickjillings@1289 134
nickjillings@1289 135 // Execute a callback for every element in the matched set.
nickjillings@1289 136 // (You can seed the arguments with an array of args, but this is
nickjillings@1289 137 // only used internally.)
nickjillings@1289 138 each: function( callback, args ) {
nickjillings@1289 139 return jQuery.each( this, callback, args );
nickjillings@1289 140 },
nickjillings@1289 141
nickjillings@1289 142 map: function( callback ) {
nickjillings@1289 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nickjillings@1289 144 return callback.call( elem, i, elem );
nickjillings@1289 145 }));
nickjillings@1289 146 },
nickjillings@1289 147
nickjillings@1289 148 slice: function() {
nickjillings@1289 149 return this.pushStack( slice.apply( this, arguments ) );
nickjillings@1289 150 },
nickjillings@1289 151
nickjillings@1289 152 first: function() {
nickjillings@1289 153 return this.eq( 0 );
nickjillings@1289 154 },
nickjillings@1289 155
nickjillings@1289 156 last: function() {
nickjillings@1289 157 return this.eq( -1 );
nickjillings@1289 158 },
nickjillings@1289 159
nickjillings@1289 160 eq: function( i ) {
nickjillings@1289 161 var len = this.length,
nickjillings@1289 162 j = +i + ( i < 0 ? len : 0 );
nickjillings@1289 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nickjillings@1289 164 },
nickjillings@1289 165
nickjillings@1289 166 end: function() {
nickjillings@1289 167 return this.prevObject || this.constructor(null);
nickjillings@1289 168 },
nickjillings@1289 169
nickjillings@1289 170 // For internal use only.
nickjillings@1289 171 // Behaves like an Array's method, not like a jQuery method.
nickjillings@1289 172 push: push,
nickjillings@1289 173 sort: arr.sort,
nickjillings@1289 174 splice: arr.splice
nickjillings@1289 175 };
nickjillings@1289 176
nickjillings@1289 177 jQuery.extend = jQuery.fn.extend = function() {
nickjillings@1289 178 var options, name, src, copy, copyIsArray, clone,
nickjillings@1289 179 target = arguments[0] || {},
nickjillings@1289 180 i = 1,
nickjillings@1289 181 length = arguments.length,
nickjillings@1289 182 deep = false;
nickjillings@1289 183
nickjillings@1289 184 // Handle a deep copy situation
nickjillings@1289 185 if ( typeof target === "boolean" ) {
nickjillings@1289 186 deep = target;
nickjillings@1289 187
nickjillings@1289 188 // Skip the boolean and the target
nickjillings@1289 189 target = arguments[ i ] || {};
nickjillings@1289 190 i++;
nickjillings@1289 191 }
nickjillings@1289 192
nickjillings@1289 193 // Handle case when target is a string or something (possible in deep copy)
nickjillings@1289 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nickjillings@1289 195 target = {};
nickjillings@1289 196 }
nickjillings@1289 197
nickjillings@1289 198 // Extend jQuery itself if only one argument is passed
nickjillings@1289 199 if ( i === length ) {
nickjillings@1289 200 target = this;
nickjillings@1289 201 i--;
nickjillings@1289 202 }
nickjillings@1289 203
nickjillings@1289 204 for ( ; i < length; i++ ) {
nickjillings@1289 205 // Only deal with non-null/undefined values
nickjillings@1289 206 if ( (options = arguments[ i ]) != null ) {
nickjillings@1289 207 // Extend the base object
nickjillings@1289 208 for ( name in options ) {
nickjillings@1289 209 src = target[ name ];
nickjillings@1289 210 copy = options[ name ];
nickjillings@1289 211
nickjillings@1289 212 // Prevent never-ending loop
nickjillings@1289 213 if ( target === copy ) {
nickjillings@1289 214 continue;
nickjillings@1289 215 }
nickjillings@1289 216
nickjillings@1289 217 // Recurse if we're merging plain objects or arrays
nickjillings@1289 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nickjillings@1289 219 if ( copyIsArray ) {
nickjillings@1289 220 copyIsArray = false;
nickjillings@1289 221 clone = src && jQuery.isArray(src) ? src : [];
nickjillings@1289 222
nickjillings@1289 223 } else {
nickjillings@1289 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nickjillings@1289 225 }
nickjillings@1289 226
nickjillings@1289 227 // Never move original objects, clone them
nickjillings@1289 228 target[ name ] = jQuery.extend( deep, clone, copy );
nickjillings@1289 229
nickjillings@1289 230 // Don't bring in undefined values
nickjillings@1289 231 } else if ( copy !== undefined ) {
nickjillings@1289 232 target[ name ] = copy;
nickjillings@1289 233 }
nickjillings@1289 234 }
nickjillings@1289 235 }
nickjillings@1289 236 }
nickjillings@1289 237
nickjillings@1289 238 // Return the modified object
nickjillings@1289 239 return target;
nickjillings@1289 240 };
nickjillings@1289 241
nickjillings@1289 242 jQuery.extend({
nickjillings@1289 243 // Unique for each copy of jQuery on the page
nickjillings@1289 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nickjillings@1289 245
nickjillings@1289 246 // Assume jQuery is ready without the ready module
nickjillings@1289 247 isReady: true,
nickjillings@1289 248
nickjillings@1289 249 error: function( msg ) {
nickjillings@1289 250 throw new Error( msg );
nickjillings@1289 251 },
nickjillings@1289 252
nickjillings@1289 253 noop: function() {},
nickjillings@1289 254
nickjillings@1289 255 isFunction: function( obj ) {
nickjillings@1289 256 return jQuery.type(obj) === "function";
nickjillings@1289 257 },
nickjillings@1289 258
nickjillings@1289 259 isArray: Array.isArray,
nickjillings@1289 260
nickjillings@1289 261 isWindow: function( obj ) {
nickjillings@1289 262 return obj != null && obj === obj.window;
nickjillings@1289 263 },
nickjillings@1289 264
nickjillings@1289 265 isNumeric: function( obj ) {
nickjillings@1289 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nickjillings@1289 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nickjillings@1289 268 // subtraction forces infinities to NaN
nickjillings@1289 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nickjillings@1289 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nickjillings@1289 271 },
nickjillings@1289 272
nickjillings@1289 273 isPlainObject: function( obj ) {
nickjillings@1289 274 // Not plain objects:
nickjillings@1289 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nickjillings@1289 276 // - DOM nodes
nickjillings@1289 277 // - window
nickjillings@1289 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nickjillings@1289 279 return false;
nickjillings@1289 280 }
nickjillings@1289 281
nickjillings@1289 282 if ( obj.constructor &&
nickjillings@1289 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nickjillings@1289 284 return false;
nickjillings@1289 285 }
nickjillings@1289 286
nickjillings@1289 287 // If the function hasn't returned already, we're confident that
nickjillings@1289 288 // |obj| is a plain object, created by {} or constructed with new Object
nickjillings@1289 289 return true;
nickjillings@1289 290 },
nickjillings@1289 291
nickjillings@1289 292 isEmptyObject: function( obj ) {
nickjillings@1289 293 var name;
nickjillings@1289 294 for ( name in obj ) {
nickjillings@1289 295 return false;
nickjillings@1289 296 }
nickjillings@1289 297 return true;
nickjillings@1289 298 },
nickjillings@1289 299
nickjillings@1289 300 type: function( obj ) {
nickjillings@1289 301 if ( obj == null ) {
nickjillings@1289 302 return obj + "";
nickjillings@1289 303 }
nickjillings@1289 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nickjillings@1289 305 return typeof obj === "object" || typeof obj === "function" ?
nickjillings@1289 306 class2type[ toString.call(obj) ] || "object" :
nickjillings@1289 307 typeof obj;
nickjillings@1289 308 },
nickjillings@1289 309
nickjillings@1289 310 // Evaluates a script in a global context
nickjillings@1289 311 globalEval: function( code ) {
nickjillings@1289 312 var script,
nickjillings@1289 313 indirect = eval;
nickjillings@1289 314
nickjillings@1289 315 code = jQuery.trim( code );
nickjillings@1289 316
nickjillings@1289 317 if ( code ) {
nickjillings@1289 318 // If the code includes a valid, prologue position
nickjillings@1289 319 // strict mode pragma, execute code by injecting a
nickjillings@1289 320 // script tag into the document.
nickjillings@1289 321 if ( code.indexOf("use strict") === 1 ) {
nickjillings@1289 322 script = document.createElement("script");
nickjillings@1289 323 script.text = code;
nickjillings@1289 324 document.head.appendChild( script ).parentNode.removeChild( script );
nickjillings@1289 325 } else {
nickjillings@1289 326 // Otherwise, avoid the DOM node creation, insertion
nickjillings@1289 327 // and removal by using an indirect global eval
nickjillings@1289 328 indirect( code );
nickjillings@1289 329 }
nickjillings@1289 330 }
nickjillings@1289 331 },
nickjillings@1289 332
nickjillings@1289 333 // Convert dashed to camelCase; used by the css and data modules
nickjillings@1289 334 // Support: IE9-11+
nickjillings@1289 335 // Microsoft forgot to hump their vendor prefix (#9572)
nickjillings@1289 336 camelCase: function( string ) {
nickjillings@1289 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nickjillings@1289 338 },
nickjillings@1289 339
nickjillings@1289 340 nodeName: function( elem, name ) {
nickjillings@1289 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nickjillings@1289 342 },
nickjillings@1289 343
nickjillings@1289 344 // args is for internal usage only
nickjillings@1289 345 each: function( obj, callback, args ) {
nickjillings@1289 346 var value,
nickjillings@1289 347 i = 0,
nickjillings@1289 348 length = obj.length,
nickjillings@1289 349 isArray = isArraylike( obj );
nickjillings@1289 350
nickjillings@1289 351 if ( args ) {
nickjillings@1289 352 if ( isArray ) {
nickjillings@1289 353 for ( ; i < length; i++ ) {
nickjillings@1289 354 value = callback.apply( obj[ i ], args );
nickjillings@1289 355
nickjillings@1289 356 if ( value === false ) {
nickjillings@1289 357 break;
nickjillings@1289 358 }
nickjillings@1289 359 }
nickjillings@1289 360 } else {
nickjillings@1289 361 for ( i in obj ) {
nickjillings@1289 362 value = callback.apply( obj[ i ], args );
nickjillings@1289 363
nickjillings@1289 364 if ( value === false ) {
nickjillings@1289 365 break;
nickjillings@1289 366 }
nickjillings@1289 367 }
nickjillings@1289 368 }
nickjillings@1289 369
nickjillings@1289 370 // A special, fast, case for the most common use of each
nickjillings@1289 371 } else {
nickjillings@1289 372 if ( isArray ) {
nickjillings@1289 373 for ( ; i < length; i++ ) {
nickjillings@1289 374 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1289 375
nickjillings@1289 376 if ( value === false ) {
nickjillings@1289 377 break;
nickjillings@1289 378 }
nickjillings@1289 379 }
nickjillings@1289 380 } else {
nickjillings@1289 381 for ( i in obj ) {
nickjillings@1289 382 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1289 383
nickjillings@1289 384 if ( value === false ) {
nickjillings@1289 385 break;
nickjillings@1289 386 }
nickjillings@1289 387 }
nickjillings@1289 388 }
nickjillings@1289 389 }
nickjillings@1289 390
nickjillings@1289 391 return obj;
nickjillings@1289 392 },
nickjillings@1289 393
nickjillings@1289 394 // Support: Android<4.1
nickjillings@1289 395 trim: function( text ) {
nickjillings@1289 396 return text == null ?
nickjillings@1289 397 "" :
nickjillings@1289 398 ( text + "" ).replace( rtrim, "" );
nickjillings@1289 399 },
nickjillings@1289 400
nickjillings@1289 401 // results is for internal usage only
nickjillings@1289 402 makeArray: function( arr, results ) {
nickjillings@1289 403 var ret = results || [];
nickjillings@1289 404
nickjillings@1289 405 if ( arr != null ) {
nickjillings@1289 406 if ( isArraylike( Object(arr) ) ) {
nickjillings@1289 407 jQuery.merge( ret,
nickjillings@1289 408 typeof arr === "string" ?
nickjillings@1289 409 [ arr ] : arr
nickjillings@1289 410 );
nickjillings@1289 411 } else {
nickjillings@1289 412 push.call( ret, arr );
nickjillings@1289 413 }
nickjillings@1289 414 }
nickjillings@1289 415
nickjillings@1289 416 return ret;
nickjillings@1289 417 },
nickjillings@1289 418
nickjillings@1289 419 inArray: function( elem, arr, i ) {
nickjillings@1289 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nickjillings@1289 421 },
nickjillings@1289 422
nickjillings@1289 423 merge: function( first, second ) {
nickjillings@1289 424 var len = +second.length,
nickjillings@1289 425 j = 0,
nickjillings@1289 426 i = first.length;
nickjillings@1289 427
nickjillings@1289 428 for ( ; j < len; j++ ) {
nickjillings@1289 429 first[ i++ ] = second[ j ];
nickjillings@1289 430 }
nickjillings@1289 431
nickjillings@1289 432 first.length = i;
nickjillings@1289 433
nickjillings@1289 434 return first;
nickjillings@1289 435 },
nickjillings@1289 436
nickjillings@1289 437 grep: function( elems, callback, invert ) {
nickjillings@1289 438 var callbackInverse,
nickjillings@1289 439 matches = [],
nickjillings@1289 440 i = 0,
nickjillings@1289 441 length = elems.length,
nickjillings@1289 442 callbackExpect = !invert;
nickjillings@1289 443
nickjillings@1289 444 // Go through the array, only saving the items
nickjillings@1289 445 // that pass the validator function
nickjillings@1289 446 for ( ; i < length; i++ ) {
nickjillings@1289 447 callbackInverse = !callback( elems[ i ], i );
nickjillings@1289 448 if ( callbackInverse !== callbackExpect ) {
nickjillings@1289 449 matches.push( elems[ i ] );
nickjillings@1289 450 }
nickjillings@1289 451 }
nickjillings@1289 452
nickjillings@1289 453 return matches;
nickjillings@1289 454 },
nickjillings@1289 455
nickjillings@1289 456 // arg is for internal usage only
nickjillings@1289 457 map: function( elems, callback, arg ) {
nickjillings@1289 458 var value,
nickjillings@1289 459 i = 0,
nickjillings@1289 460 length = elems.length,
nickjillings@1289 461 isArray = isArraylike( elems ),
nickjillings@1289 462 ret = [];
nickjillings@1289 463
nickjillings@1289 464 // Go through the array, translating each of the items to their new values
nickjillings@1289 465 if ( isArray ) {
nickjillings@1289 466 for ( ; i < length; i++ ) {
nickjillings@1289 467 value = callback( elems[ i ], i, arg );
nickjillings@1289 468
nickjillings@1289 469 if ( value != null ) {
nickjillings@1289 470 ret.push( value );
nickjillings@1289 471 }
nickjillings@1289 472 }
nickjillings@1289 473
nickjillings@1289 474 // Go through every key on the object,
nickjillings@1289 475 } else {
nickjillings@1289 476 for ( i in elems ) {
nickjillings@1289 477 value = callback( elems[ i ], i, arg );
nickjillings@1289 478
nickjillings@1289 479 if ( value != null ) {
nickjillings@1289 480 ret.push( value );
nickjillings@1289 481 }
nickjillings@1289 482 }
nickjillings@1289 483 }
nickjillings@1289 484
nickjillings@1289 485 // Flatten any nested arrays
nickjillings@1289 486 return concat.apply( [], ret );
nickjillings@1289 487 },
nickjillings@1289 488
nickjillings@1289 489 // A global GUID counter for objects
nickjillings@1289 490 guid: 1,
nickjillings@1289 491
nickjillings@1289 492 // Bind a function to a context, optionally partially applying any
nickjillings@1289 493 // arguments.
nickjillings@1289 494 proxy: function( fn, context ) {
nickjillings@1289 495 var tmp, args, proxy;
nickjillings@1289 496
nickjillings@1289 497 if ( typeof context === "string" ) {
nickjillings@1289 498 tmp = fn[ context ];
nickjillings@1289 499 context = fn;
nickjillings@1289 500 fn = tmp;
nickjillings@1289 501 }
nickjillings@1289 502
nickjillings@1289 503 // Quick check to determine if target is callable, in the spec
nickjillings@1289 504 // this throws a TypeError, but we will just return undefined.
nickjillings@1289 505 if ( !jQuery.isFunction( fn ) ) {
nickjillings@1289 506 return undefined;
nickjillings@1289 507 }
nickjillings@1289 508
nickjillings@1289 509 // Simulated bind
nickjillings@1289 510 args = slice.call( arguments, 2 );
nickjillings@1289 511 proxy = function() {
nickjillings@1289 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nickjillings@1289 513 };
nickjillings@1289 514
nickjillings@1289 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nickjillings@1289 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nickjillings@1289 517
nickjillings@1289 518 return proxy;
nickjillings@1289 519 },
nickjillings@1289 520
nickjillings@1289 521 now: Date.now,
nickjillings@1289 522
nickjillings@1289 523 // jQuery.support is not used in Core but other projects attach their
nickjillings@1289 524 // properties to it so it needs to exist.
nickjillings@1289 525 support: support
nickjillings@1289 526 });
nickjillings@1289 527
nickjillings@1289 528 // Populate the class2type map
nickjillings@1289 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nickjillings@1289 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nickjillings@1289 531 });
nickjillings@1289 532
nickjillings@1289 533 function isArraylike( obj ) {
nickjillings@1289 534
nickjillings@1289 535 // Support: iOS 8.2 (not reproducible in simulator)
nickjillings@1289 536 // `in` check used to prevent JIT error (gh-2145)
nickjillings@1289 537 // hasOwn isn't used here due to false negatives
nickjillings@1289 538 // regarding Nodelist length in IE
nickjillings@1289 539 var length = "length" in obj && obj.length,
nickjillings@1289 540 type = jQuery.type( obj );
nickjillings@1289 541
nickjillings@1289 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nickjillings@1289 543 return false;
nickjillings@1289 544 }
nickjillings@1289 545
nickjillings@1289 546 if ( obj.nodeType === 1 && length ) {
nickjillings@1289 547 return true;
nickjillings@1289 548 }
nickjillings@1289 549
nickjillings@1289 550 return type === "array" || length === 0 ||
nickjillings@1289 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nickjillings@1289 552 }
nickjillings@1289 553 var Sizzle =
nickjillings@1289 554 /*!
nickjillings@1289 555 * Sizzle CSS Selector Engine v2.2.0-pre
nickjillings@1289 556 * http://sizzlejs.com/
nickjillings@1289 557 *
nickjillings@1289 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1289 559 * Released under the MIT license
nickjillings@1289 560 * http://jquery.org/license
nickjillings@1289 561 *
nickjillings@1289 562 * Date: 2014-12-16
nickjillings@1289 563 */
nickjillings@1289 564 (function( window ) {
nickjillings@1289 565
nickjillings@1289 566 var i,
nickjillings@1289 567 support,
nickjillings@1289 568 Expr,
nickjillings@1289 569 getText,
nickjillings@1289 570 isXML,
nickjillings@1289 571 tokenize,
nickjillings@1289 572 compile,
nickjillings@1289 573 select,
nickjillings@1289 574 outermostContext,
nickjillings@1289 575 sortInput,
nickjillings@1289 576 hasDuplicate,
nickjillings@1289 577
nickjillings@1289 578 // Local document vars
nickjillings@1289 579 setDocument,
nickjillings@1289 580 document,
nickjillings@1289 581 docElem,
nickjillings@1289 582 documentIsHTML,
nickjillings@1289 583 rbuggyQSA,
nickjillings@1289 584 rbuggyMatches,
nickjillings@1289 585 matches,
nickjillings@1289 586 contains,
nickjillings@1289 587
nickjillings@1289 588 // Instance-specific data
nickjillings@1289 589 expando = "sizzle" + 1 * new Date(),
nickjillings@1289 590 preferredDoc = window.document,
nickjillings@1289 591 dirruns = 0,
nickjillings@1289 592 done = 0,
nickjillings@1289 593 classCache = createCache(),
nickjillings@1289 594 tokenCache = createCache(),
nickjillings@1289 595 compilerCache = createCache(),
nickjillings@1289 596 sortOrder = function( a, b ) {
nickjillings@1289 597 if ( a === b ) {
nickjillings@1289 598 hasDuplicate = true;
nickjillings@1289 599 }
nickjillings@1289 600 return 0;
nickjillings@1289 601 },
nickjillings@1289 602
nickjillings@1289 603 // General-purpose constants
nickjillings@1289 604 MAX_NEGATIVE = 1 << 31,
nickjillings@1289 605
nickjillings@1289 606 // Instance methods
nickjillings@1289 607 hasOwn = ({}).hasOwnProperty,
nickjillings@1289 608 arr = [],
nickjillings@1289 609 pop = arr.pop,
nickjillings@1289 610 push_native = arr.push,
nickjillings@1289 611 push = arr.push,
nickjillings@1289 612 slice = arr.slice,
nickjillings@1289 613 // Use a stripped-down indexOf as it's faster than native
nickjillings@1289 614 // http://jsperf.com/thor-indexof-vs-for/5
nickjillings@1289 615 indexOf = function( list, elem ) {
nickjillings@1289 616 var i = 0,
nickjillings@1289 617 len = list.length;
nickjillings@1289 618 for ( ; i < len; i++ ) {
nickjillings@1289 619 if ( list[i] === elem ) {
nickjillings@1289 620 return i;
nickjillings@1289 621 }
nickjillings@1289 622 }
nickjillings@1289 623 return -1;
nickjillings@1289 624 },
nickjillings@1289 625
nickjillings@1289 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nickjillings@1289 627
nickjillings@1289 628 // Regular expressions
nickjillings@1289 629
nickjillings@1289 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nickjillings@1289 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nickjillings@1289 632 // http://www.w3.org/TR/css3-syntax/#characters
nickjillings@1289 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nickjillings@1289 634
nickjillings@1289 635 // Loosely modeled on CSS identifier characters
nickjillings@1289 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nickjillings@1289 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nickjillings@1289 638 identifier = characterEncoding.replace( "w", "w#" ),
nickjillings@1289 639
nickjillings@1289 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nickjillings@1289 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nickjillings@1289 642 // Operator (capture 2)
nickjillings@1289 643 "*([*^$|!~]?=)" + whitespace +
nickjillings@1289 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nickjillings@1289 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nickjillings@1289 646 "*\\]",
nickjillings@1289 647
nickjillings@1289 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nickjillings@1289 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nickjillings@1289 650 // 1. quoted (capture 3; capture 4 or capture 5)
nickjillings@1289 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nickjillings@1289 652 // 2. simple (capture 6)
nickjillings@1289 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nickjillings@1289 654 // 3. anything else (capture 2)
nickjillings@1289 655 ".*" +
nickjillings@1289 656 ")\\)|)",
nickjillings@1289 657
nickjillings@1289 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nickjillings@1289 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nickjillings@1289 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nickjillings@1289 661
nickjillings@1289 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nickjillings@1289 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nickjillings@1289 664
nickjillings@1289 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nickjillings@1289 666
nickjillings@1289 667 rpseudo = new RegExp( pseudos ),
nickjillings@1289 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nickjillings@1289 669
nickjillings@1289 670 matchExpr = {
nickjillings@1289 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nickjillings@1289 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nickjillings@1289 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nickjillings@1289 674 "ATTR": new RegExp( "^" + attributes ),
nickjillings@1289 675 "PSEUDO": new RegExp( "^" + pseudos ),
nickjillings@1289 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nickjillings@1289 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nickjillings@1289 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nickjillings@1289 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nickjillings@1289 680 // For use in libraries implementing .is()
nickjillings@1289 681 // We use this for POS matching in `select`
nickjillings@1289 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nickjillings@1289 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nickjillings@1289 684 },
nickjillings@1289 685
nickjillings@1289 686 rinputs = /^(?:input|select|textarea|button)$/i,
nickjillings@1289 687 rheader = /^h\d$/i,
nickjillings@1289 688
nickjillings@1289 689 rnative = /^[^{]+\{\s*\[native \w/,
nickjillings@1289 690
nickjillings@1289 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nickjillings@1289 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nickjillings@1289 693
nickjillings@1289 694 rsibling = /[+~]/,
nickjillings@1289 695 rescape = /'|\\/g,
nickjillings@1289 696
nickjillings@1289 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nickjillings@1289 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nickjillings@1289 699 funescape = function( _, escaped, escapedWhitespace ) {
nickjillings@1289 700 var high = "0x" + escaped - 0x10000;
nickjillings@1289 701 // NaN means non-codepoint
nickjillings@1289 702 // Support: Firefox<24
nickjillings@1289 703 // Workaround erroneous numeric interpretation of +"0x"
nickjillings@1289 704 return high !== high || escapedWhitespace ?
nickjillings@1289 705 escaped :
nickjillings@1289 706 high < 0 ?
nickjillings@1289 707 // BMP codepoint
nickjillings@1289 708 String.fromCharCode( high + 0x10000 ) :
nickjillings@1289 709 // Supplemental Plane codepoint (surrogate pair)
nickjillings@1289 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nickjillings@1289 711 },
nickjillings@1289 712
nickjillings@1289 713 // Used for iframes
nickjillings@1289 714 // See setDocument()
nickjillings@1289 715 // Removing the function wrapper causes a "Permission Denied"
nickjillings@1289 716 // error in IE
nickjillings@1289 717 unloadHandler = function() {
nickjillings@1289 718 setDocument();
nickjillings@1289 719 };
nickjillings@1289 720
nickjillings@1289 721 // Optimize for push.apply( _, NodeList )
nickjillings@1289 722 try {
nickjillings@1289 723 push.apply(
nickjillings@1289 724 (arr = slice.call( preferredDoc.childNodes )),
nickjillings@1289 725 preferredDoc.childNodes
nickjillings@1289 726 );
nickjillings@1289 727 // Support: Android<4.0
nickjillings@1289 728 // Detect silently failing push.apply
nickjillings@1289 729 arr[ preferredDoc.childNodes.length ].nodeType;
nickjillings@1289 730 } catch ( e ) {
nickjillings@1289 731 push = { apply: arr.length ?
nickjillings@1289 732
nickjillings@1289 733 // Leverage slice if possible
nickjillings@1289 734 function( target, els ) {
nickjillings@1289 735 push_native.apply( target, slice.call(els) );
nickjillings@1289 736 } :
nickjillings@1289 737
nickjillings@1289 738 // Support: IE<9
nickjillings@1289 739 // Otherwise append directly
nickjillings@1289 740 function( target, els ) {
nickjillings@1289 741 var j = target.length,
nickjillings@1289 742 i = 0;
nickjillings@1289 743 // Can't trust NodeList.length
nickjillings@1289 744 while ( (target[j++] = els[i++]) ) {}
nickjillings@1289 745 target.length = j - 1;
nickjillings@1289 746 }
nickjillings@1289 747 };
nickjillings@1289 748 }
nickjillings@1289 749
nickjillings@1289 750 function Sizzle( selector, context, results, seed ) {
nickjillings@1289 751 var match, elem, m, nodeType,
nickjillings@1289 752 // QSA vars
nickjillings@1289 753 i, groups, old, nid, newContext, newSelector;
nickjillings@1289 754
nickjillings@1289 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nickjillings@1289 756 setDocument( context );
nickjillings@1289 757 }
nickjillings@1289 758
nickjillings@1289 759 context = context || document;
nickjillings@1289 760 results = results || [];
nickjillings@1289 761 nodeType = context.nodeType;
nickjillings@1289 762
nickjillings@1289 763 if ( typeof selector !== "string" || !selector ||
nickjillings@1289 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nickjillings@1289 765
nickjillings@1289 766 return results;
nickjillings@1289 767 }
nickjillings@1289 768
nickjillings@1289 769 if ( !seed && documentIsHTML ) {
nickjillings@1289 770
nickjillings@1289 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nickjillings@1289 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nickjillings@1289 773 // Speed-up: Sizzle("#ID")
nickjillings@1289 774 if ( (m = match[1]) ) {
nickjillings@1289 775 if ( nodeType === 9 ) {
nickjillings@1289 776 elem = context.getElementById( m );
nickjillings@1289 777 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1289 778 // nodes that are no longer in the document (jQuery #6963)
nickjillings@1289 779 if ( elem && elem.parentNode ) {
nickjillings@1289 780 // Handle the case where IE, Opera, and Webkit return items
nickjillings@1289 781 // by name instead of ID
nickjillings@1289 782 if ( elem.id === m ) {
nickjillings@1289 783 results.push( elem );
nickjillings@1289 784 return results;
nickjillings@1289 785 }
nickjillings@1289 786 } else {
nickjillings@1289 787 return results;
nickjillings@1289 788 }
nickjillings@1289 789 } else {
nickjillings@1289 790 // Context is not a document
nickjillings@1289 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nickjillings@1289 792 contains( context, elem ) && elem.id === m ) {
nickjillings@1289 793 results.push( elem );
nickjillings@1289 794 return results;
nickjillings@1289 795 }
nickjillings@1289 796 }
nickjillings@1289 797
nickjillings@1289 798 // Speed-up: Sizzle("TAG")
nickjillings@1289 799 } else if ( match[2] ) {
nickjillings@1289 800 push.apply( results, context.getElementsByTagName( selector ) );
nickjillings@1289 801 return results;
nickjillings@1289 802
nickjillings@1289 803 // Speed-up: Sizzle(".CLASS")
nickjillings@1289 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nickjillings@1289 805 push.apply( results, context.getElementsByClassName( m ) );
nickjillings@1289 806 return results;
nickjillings@1289 807 }
nickjillings@1289 808 }
nickjillings@1289 809
nickjillings@1289 810 // QSA path
nickjillings@1289 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nickjillings@1289 812 nid = old = expando;
nickjillings@1289 813 newContext = context;
nickjillings@1289 814 newSelector = nodeType !== 1 && selector;
nickjillings@1289 815
nickjillings@1289 816 // qSA works strangely on Element-rooted queries
nickjillings@1289 817 // We can work around this by specifying an extra ID on the root
nickjillings@1289 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nickjillings@1289 819 // IE 8 doesn't work on object elements
nickjillings@1289 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nickjillings@1289 821 groups = tokenize( selector );
nickjillings@1289 822
nickjillings@1289 823 if ( (old = context.getAttribute("id")) ) {
nickjillings@1289 824 nid = old.replace( rescape, "\\$&" );
nickjillings@1289 825 } else {
nickjillings@1289 826 context.setAttribute( "id", nid );
nickjillings@1289 827 }
nickjillings@1289 828 nid = "[id='" + nid + "'] ";
nickjillings@1289 829
nickjillings@1289 830 i = groups.length;
nickjillings@1289 831 while ( i-- ) {
nickjillings@1289 832 groups[i] = nid + toSelector( groups[i] );
nickjillings@1289 833 }
nickjillings@1289 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nickjillings@1289 835 newSelector = groups.join(",");
nickjillings@1289 836 }
nickjillings@1289 837
nickjillings@1289 838 if ( newSelector ) {
nickjillings@1289 839 try {
nickjillings@1289 840 push.apply( results,
nickjillings@1289 841 newContext.querySelectorAll( newSelector )
nickjillings@1289 842 );
nickjillings@1289 843 return results;
nickjillings@1289 844 } catch(qsaError) {
nickjillings@1289 845 } finally {
nickjillings@1289 846 if ( !old ) {
nickjillings@1289 847 context.removeAttribute("id");
nickjillings@1289 848 }
nickjillings@1289 849 }
nickjillings@1289 850 }
nickjillings@1289 851 }
nickjillings@1289 852 }
nickjillings@1289 853
nickjillings@1289 854 // All others
nickjillings@1289 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nickjillings@1289 856 }
nickjillings@1289 857
nickjillings@1289 858 /**
nickjillings@1289 859 * Create key-value caches of limited size
nickjillings@1289 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nickjillings@1289 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nickjillings@1289 862 * deleting the oldest entry
nickjillings@1289 863 */
nickjillings@1289 864 function createCache() {
nickjillings@1289 865 var keys = [];
nickjillings@1289 866
nickjillings@1289 867 function cache( key, value ) {
nickjillings@1289 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nickjillings@1289 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nickjillings@1289 870 // Only keep the most recent entries
nickjillings@1289 871 delete cache[ keys.shift() ];
nickjillings@1289 872 }
nickjillings@1289 873 return (cache[ key + " " ] = value);
nickjillings@1289 874 }
nickjillings@1289 875 return cache;
nickjillings@1289 876 }
nickjillings@1289 877
nickjillings@1289 878 /**
nickjillings@1289 879 * Mark a function for special use by Sizzle
nickjillings@1289 880 * @param {Function} fn The function to mark
nickjillings@1289 881 */
nickjillings@1289 882 function markFunction( fn ) {
nickjillings@1289 883 fn[ expando ] = true;
nickjillings@1289 884 return fn;
nickjillings@1289 885 }
nickjillings@1289 886
nickjillings@1289 887 /**
nickjillings@1289 888 * Support testing using an element
nickjillings@1289 889 * @param {Function} fn Passed the created div and expects a boolean result
nickjillings@1289 890 */
nickjillings@1289 891 function assert( fn ) {
nickjillings@1289 892 var div = document.createElement("div");
nickjillings@1289 893
nickjillings@1289 894 try {
nickjillings@1289 895 return !!fn( div );
nickjillings@1289 896 } catch (e) {
nickjillings@1289 897 return false;
nickjillings@1289 898 } finally {
nickjillings@1289 899 // Remove from its parent by default
nickjillings@1289 900 if ( div.parentNode ) {
nickjillings@1289 901 div.parentNode.removeChild( div );
nickjillings@1289 902 }
nickjillings@1289 903 // release memory in IE
nickjillings@1289 904 div = null;
nickjillings@1289 905 }
nickjillings@1289 906 }
nickjillings@1289 907
nickjillings@1289 908 /**
nickjillings@1289 909 * Adds the same handler for all of the specified attrs
nickjillings@1289 910 * @param {String} attrs Pipe-separated list of attributes
nickjillings@1289 911 * @param {Function} handler The method that will be applied
nickjillings@1289 912 */
nickjillings@1289 913 function addHandle( attrs, handler ) {
nickjillings@1289 914 var arr = attrs.split("|"),
nickjillings@1289 915 i = attrs.length;
nickjillings@1289 916
nickjillings@1289 917 while ( i-- ) {
nickjillings@1289 918 Expr.attrHandle[ arr[i] ] = handler;
nickjillings@1289 919 }
nickjillings@1289 920 }
nickjillings@1289 921
nickjillings@1289 922 /**
nickjillings@1289 923 * Checks document order of two siblings
nickjillings@1289 924 * @param {Element} a
nickjillings@1289 925 * @param {Element} b
nickjillings@1289 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nickjillings@1289 927 */
nickjillings@1289 928 function siblingCheck( a, b ) {
nickjillings@1289 929 var cur = b && a,
nickjillings@1289 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nickjillings@1289 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nickjillings@1289 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nickjillings@1289 933
nickjillings@1289 934 // Use IE sourceIndex if available on both nodes
nickjillings@1289 935 if ( diff ) {
nickjillings@1289 936 return diff;
nickjillings@1289 937 }
nickjillings@1289 938
nickjillings@1289 939 // Check if b follows a
nickjillings@1289 940 if ( cur ) {
nickjillings@1289 941 while ( (cur = cur.nextSibling) ) {
nickjillings@1289 942 if ( cur === b ) {
nickjillings@1289 943 return -1;
nickjillings@1289 944 }
nickjillings@1289 945 }
nickjillings@1289 946 }
nickjillings@1289 947
nickjillings@1289 948 return a ? 1 : -1;
nickjillings@1289 949 }
nickjillings@1289 950
nickjillings@1289 951 /**
nickjillings@1289 952 * Returns a function to use in pseudos for input types
nickjillings@1289 953 * @param {String} type
nickjillings@1289 954 */
nickjillings@1289 955 function createInputPseudo( type ) {
nickjillings@1289 956 return function( elem ) {
nickjillings@1289 957 var name = elem.nodeName.toLowerCase();
nickjillings@1289 958 return name === "input" && elem.type === type;
nickjillings@1289 959 };
nickjillings@1289 960 }
nickjillings@1289 961
nickjillings@1289 962 /**
nickjillings@1289 963 * Returns a function to use in pseudos for buttons
nickjillings@1289 964 * @param {String} type
nickjillings@1289 965 */
nickjillings@1289 966 function createButtonPseudo( type ) {
nickjillings@1289 967 return function( elem ) {
nickjillings@1289 968 var name = elem.nodeName.toLowerCase();
nickjillings@1289 969 return (name === "input" || name === "button") && elem.type === type;
nickjillings@1289 970 };
nickjillings@1289 971 }
nickjillings@1289 972
nickjillings@1289 973 /**
nickjillings@1289 974 * Returns a function to use in pseudos for positionals
nickjillings@1289 975 * @param {Function} fn
nickjillings@1289 976 */
nickjillings@1289 977 function createPositionalPseudo( fn ) {
nickjillings@1289 978 return markFunction(function( argument ) {
nickjillings@1289 979 argument = +argument;
nickjillings@1289 980 return markFunction(function( seed, matches ) {
nickjillings@1289 981 var j,
nickjillings@1289 982 matchIndexes = fn( [], seed.length, argument ),
nickjillings@1289 983 i = matchIndexes.length;
nickjillings@1289 984
nickjillings@1289 985 // Match elements found at the specified indexes
nickjillings@1289 986 while ( i-- ) {
nickjillings@1289 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nickjillings@1289 988 seed[j] = !(matches[j] = seed[j]);
nickjillings@1289 989 }
nickjillings@1289 990 }
nickjillings@1289 991 });
nickjillings@1289 992 });
nickjillings@1289 993 }
nickjillings@1289 994
nickjillings@1289 995 /**
nickjillings@1289 996 * Checks a node for validity as a Sizzle context
nickjillings@1289 997 * @param {Element|Object=} context
nickjillings@1289 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nickjillings@1289 999 */
nickjillings@1289 1000 function testContext( context ) {
nickjillings@1289 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nickjillings@1289 1002 }
nickjillings@1289 1003
nickjillings@1289 1004 // Expose support vars for convenience
nickjillings@1289 1005 support = Sizzle.support = {};
nickjillings@1289 1006
nickjillings@1289 1007 /**
nickjillings@1289 1008 * Detects XML nodes
nickjillings@1289 1009 * @param {Element|Object} elem An element or a document
nickjillings@1289 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nickjillings@1289 1011 */
nickjillings@1289 1012 isXML = Sizzle.isXML = function( elem ) {
nickjillings@1289 1013 // documentElement is verified for cases where it doesn't yet exist
nickjillings@1289 1014 // (such as loading iframes in IE - #4833)
nickjillings@1289 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nickjillings@1289 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nickjillings@1289 1017 };
nickjillings@1289 1018
nickjillings@1289 1019 /**
nickjillings@1289 1020 * Sets document-related variables once based on the current document
nickjillings@1289 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nickjillings@1289 1022 * @returns {Object} Returns the current document
nickjillings@1289 1023 */
nickjillings@1289 1024 setDocument = Sizzle.setDocument = function( node ) {
nickjillings@1289 1025 var hasCompare, parent,
nickjillings@1289 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nickjillings@1289 1027
nickjillings@1289 1028 // If no document and documentElement is available, return
nickjillings@1289 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nickjillings@1289 1030 return document;
nickjillings@1289 1031 }
nickjillings@1289 1032
nickjillings@1289 1033 // Set our document
nickjillings@1289 1034 document = doc;
nickjillings@1289 1035 docElem = doc.documentElement;
nickjillings@1289 1036 parent = doc.defaultView;
nickjillings@1289 1037
nickjillings@1289 1038 // Support: IE>8
nickjillings@1289 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nickjillings@1289 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nickjillings@1289 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nickjillings@1289 1042 if ( parent && parent !== parent.top ) {
nickjillings@1289 1043 // IE11 does not have attachEvent, so all must suffer
nickjillings@1289 1044 if ( parent.addEventListener ) {
nickjillings@1289 1045 parent.addEventListener( "unload", unloadHandler, false );
nickjillings@1289 1046 } else if ( parent.attachEvent ) {
nickjillings@1289 1047 parent.attachEvent( "onunload", unloadHandler );
nickjillings@1289 1048 }
nickjillings@1289 1049 }
nickjillings@1289 1050
nickjillings@1289 1051 /* Support tests
nickjillings@1289 1052 ---------------------------------------------------------------------- */
nickjillings@1289 1053 documentIsHTML = !isXML( doc );
nickjillings@1289 1054
nickjillings@1289 1055 /* Attributes
nickjillings@1289 1056 ---------------------------------------------------------------------- */
nickjillings@1289 1057
nickjillings@1289 1058 // Support: IE<8
nickjillings@1289 1059 // Verify that getAttribute really returns attributes and not properties
nickjillings@1289 1060 // (excepting IE8 booleans)
nickjillings@1289 1061 support.attributes = assert(function( div ) {
nickjillings@1289 1062 div.className = "i";
nickjillings@1289 1063 return !div.getAttribute("className");
nickjillings@1289 1064 });
nickjillings@1289 1065
nickjillings@1289 1066 /* getElement(s)By*
nickjillings@1289 1067 ---------------------------------------------------------------------- */
nickjillings@1289 1068
nickjillings@1289 1069 // Check if getElementsByTagName("*") returns only elements
nickjillings@1289 1070 support.getElementsByTagName = assert(function( div ) {
nickjillings@1289 1071 div.appendChild( doc.createComment("") );
nickjillings@1289 1072 return !div.getElementsByTagName("*").length;
nickjillings@1289 1073 });
nickjillings@1289 1074
nickjillings@1289 1075 // Support: IE<9
nickjillings@1289 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nickjillings@1289 1077
nickjillings@1289 1078 // Support: IE<10
nickjillings@1289 1079 // Check if getElementById returns elements by name
nickjillings@1289 1080 // The broken getElementById methods don't pick up programatically-set names,
nickjillings@1289 1081 // so use a roundabout getElementsByName test
nickjillings@1289 1082 support.getById = assert(function( div ) {
nickjillings@1289 1083 docElem.appendChild( div ).id = expando;
nickjillings@1289 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nickjillings@1289 1085 });
nickjillings@1289 1086
nickjillings@1289 1087 // ID find and filter
nickjillings@1289 1088 if ( support.getById ) {
nickjillings@1289 1089 Expr.find["ID"] = function( id, context ) {
nickjillings@1289 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nickjillings@1289 1091 var m = context.getElementById( id );
nickjillings@1289 1092 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1289 1093 // nodes that are no longer in the document #6963
nickjillings@1289 1094 return m && m.parentNode ? [ m ] : [];
nickjillings@1289 1095 }
nickjillings@1289 1096 };
nickjillings@1289 1097 Expr.filter["ID"] = function( id ) {
nickjillings@1289 1098 var attrId = id.replace( runescape, funescape );
nickjillings@1289 1099 return function( elem ) {
nickjillings@1289 1100 return elem.getAttribute("id") === attrId;
nickjillings@1289 1101 };
nickjillings@1289 1102 };
nickjillings@1289 1103 } else {
nickjillings@1289 1104 // Support: IE6/7
nickjillings@1289 1105 // getElementById is not reliable as a find shortcut
nickjillings@1289 1106 delete Expr.find["ID"];
nickjillings@1289 1107
nickjillings@1289 1108 Expr.filter["ID"] = function( id ) {
nickjillings@1289 1109 var attrId = id.replace( runescape, funescape );
nickjillings@1289 1110 return function( elem ) {
nickjillings@1289 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nickjillings@1289 1112 return node && node.value === attrId;
nickjillings@1289 1113 };
nickjillings@1289 1114 };
nickjillings@1289 1115 }
nickjillings@1289 1116
nickjillings@1289 1117 // Tag
nickjillings@1289 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nickjillings@1289 1119 function( tag, context ) {
nickjillings@1289 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nickjillings@1289 1121 return context.getElementsByTagName( tag );
nickjillings@1289 1122
nickjillings@1289 1123 // DocumentFragment nodes don't have gEBTN
nickjillings@1289 1124 } else if ( support.qsa ) {
nickjillings@1289 1125 return context.querySelectorAll( tag );
nickjillings@1289 1126 }
nickjillings@1289 1127 } :
nickjillings@1289 1128
nickjillings@1289 1129 function( tag, context ) {
nickjillings@1289 1130 var elem,
nickjillings@1289 1131 tmp = [],
nickjillings@1289 1132 i = 0,
nickjillings@1289 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nickjillings@1289 1134 results = context.getElementsByTagName( tag );
nickjillings@1289 1135
nickjillings@1289 1136 // Filter out possible comments
nickjillings@1289 1137 if ( tag === "*" ) {
nickjillings@1289 1138 while ( (elem = results[i++]) ) {
nickjillings@1289 1139 if ( elem.nodeType === 1 ) {
nickjillings@1289 1140 tmp.push( elem );
nickjillings@1289 1141 }
nickjillings@1289 1142 }
nickjillings@1289 1143
nickjillings@1289 1144 return tmp;
nickjillings@1289 1145 }
nickjillings@1289 1146 return results;
nickjillings@1289 1147 };
nickjillings@1289 1148
nickjillings@1289 1149 // Class
nickjillings@1289 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nickjillings@1289 1151 if ( documentIsHTML ) {
nickjillings@1289 1152 return context.getElementsByClassName( className );
nickjillings@1289 1153 }
nickjillings@1289 1154 };
nickjillings@1289 1155
nickjillings@1289 1156 /* QSA/matchesSelector
nickjillings@1289 1157 ---------------------------------------------------------------------- */
nickjillings@1289 1158
nickjillings@1289 1159 // QSA and matchesSelector support
nickjillings@1289 1160
nickjillings@1289 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nickjillings@1289 1162 rbuggyMatches = [];
nickjillings@1289 1163
nickjillings@1289 1164 // qSa(:focus) reports false when true (Chrome 21)
nickjillings@1289 1165 // We allow this because of a bug in IE8/9 that throws an error
nickjillings@1289 1166 // whenever `document.activeElement` is accessed on an iframe
nickjillings@1289 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nickjillings@1289 1168 // See http://bugs.jquery.com/ticket/13378
nickjillings@1289 1169 rbuggyQSA = [];
nickjillings@1289 1170
nickjillings@1289 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nickjillings@1289 1172 // Build QSA regex
nickjillings@1289 1173 // Regex strategy adopted from Diego Perini
nickjillings@1289 1174 assert(function( div ) {
nickjillings@1289 1175 // Select is set to empty string on purpose
nickjillings@1289 1176 // This is to test IE's treatment of not explicitly
nickjillings@1289 1177 // setting a boolean content attribute,
nickjillings@1289 1178 // since its presence should be enough
nickjillings@1289 1179 // http://bugs.jquery.com/ticket/12359
nickjillings@1289 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nickjillings@1289 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nickjillings@1289 1182 "<option selected=''></option></select>";
nickjillings@1289 1183
nickjillings@1289 1184 // Support: IE8, Opera 11-12.16
nickjillings@1289 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nickjillings@1289 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nickjillings@1289 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nickjillings@1289 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nickjillings@1289 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nickjillings@1289 1190 }
nickjillings@1289 1191
nickjillings@1289 1192 // Support: IE8
nickjillings@1289 1193 // Boolean attributes and "value" are not treated correctly
nickjillings@1289 1194 if ( !div.querySelectorAll("[selected]").length ) {
nickjillings@1289 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nickjillings@1289 1196 }
nickjillings@1289 1197
nickjillings@1289 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nickjillings@1289 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nickjillings@1289 1200 rbuggyQSA.push("~=");
nickjillings@1289 1201 }
nickjillings@1289 1202
nickjillings@1289 1203 // Webkit/Opera - :checked should return selected option elements
nickjillings@1289 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1289 1205 // IE8 throws error here and will not see later tests
nickjillings@1289 1206 if ( !div.querySelectorAll(":checked").length ) {
nickjillings@1289 1207 rbuggyQSA.push(":checked");
nickjillings@1289 1208 }
nickjillings@1289 1209
nickjillings@1289 1210 // Support: Safari 8+, iOS 8+
nickjillings@1289 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nickjillings@1289 1212 // In-page `selector#id sibing-combinator selector` fails
nickjillings@1289 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nickjillings@1289 1214 rbuggyQSA.push(".#.+[+~]");
nickjillings@1289 1215 }
nickjillings@1289 1216 });
nickjillings@1289 1217
nickjillings@1289 1218 assert(function( div ) {
nickjillings@1289 1219 // Support: Windows 8 Native Apps
nickjillings@1289 1220 // The type and name attributes are restricted during .innerHTML assignment
nickjillings@1289 1221 var input = doc.createElement("input");
nickjillings@1289 1222 input.setAttribute( "type", "hidden" );
nickjillings@1289 1223 div.appendChild( input ).setAttribute( "name", "D" );
nickjillings@1289 1224
nickjillings@1289 1225 // Support: IE8
nickjillings@1289 1226 // Enforce case-sensitivity of name attribute
nickjillings@1289 1227 if ( div.querySelectorAll("[name=d]").length ) {
nickjillings@1289 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nickjillings@1289 1229 }
nickjillings@1289 1230
nickjillings@1289 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nickjillings@1289 1232 // IE8 throws error here and will not see later tests
nickjillings@1289 1233 if ( !div.querySelectorAll(":enabled").length ) {
nickjillings@1289 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nickjillings@1289 1235 }
nickjillings@1289 1236
nickjillings@1289 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nickjillings@1289 1238 div.querySelectorAll("*,:x");
nickjillings@1289 1239 rbuggyQSA.push(",.*:");
nickjillings@1289 1240 });
nickjillings@1289 1241 }
nickjillings@1289 1242
nickjillings@1289 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nickjillings@1289 1244 docElem.webkitMatchesSelector ||
nickjillings@1289 1245 docElem.mozMatchesSelector ||
nickjillings@1289 1246 docElem.oMatchesSelector ||
nickjillings@1289 1247 docElem.msMatchesSelector) )) ) {
nickjillings@1289 1248
nickjillings@1289 1249 assert(function( div ) {
nickjillings@1289 1250 // Check to see if it's possible to do matchesSelector
nickjillings@1289 1251 // on a disconnected node (IE 9)
nickjillings@1289 1252 support.disconnectedMatch = matches.call( div, "div" );
nickjillings@1289 1253
nickjillings@1289 1254 // This should fail with an exception
nickjillings@1289 1255 // Gecko does not error, returns false instead
nickjillings@1289 1256 matches.call( div, "[s!='']:x" );
nickjillings@1289 1257 rbuggyMatches.push( "!=", pseudos );
nickjillings@1289 1258 });
nickjillings@1289 1259 }
nickjillings@1289 1260
nickjillings@1289 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nickjillings@1289 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nickjillings@1289 1263
nickjillings@1289 1264 /* Contains
nickjillings@1289 1265 ---------------------------------------------------------------------- */
nickjillings@1289 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nickjillings@1289 1267
nickjillings@1289 1268 // Element contains another
nickjillings@1289 1269 // Purposefully does not implement inclusive descendent
nickjillings@1289 1270 // As in, an element does not contain itself
nickjillings@1289 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nickjillings@1289 1272 function( a, b ) {
nickjillings@1289 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nickjillings@1289 1274 bup = b && b.parentNode;
nickjillings@1289 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nickjillings@1289 1276 adown.contains ?
nickjillings@1289 1277 adown.contains( bup ) :
nickjillings@1289 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nickjillings@1289 1279 ));
nickjillings@1289 1280 } :
nickjillings@1289 1281 function( a, b ) {
nickjillings@1289 1282 if ( b ) {
nickjillings@1289 1283 while ( (b = b.parentNode) ) {
nickjillings@1289 1284 if ( b === a ) {
nickjillings@1289 1285 return true;
nickjillings@1289 1286 }
nickjillings@1289 1287 }
nickjillings@1289 1288 }
nickjillings@1289 1289 return false;
nickjillings@1289 1290 };
nickjillings@1289 1291
nickjillings@1289 1292 /* Sorting
nickjillings@1289 1293 ---------------------------------------------------------------------- */
nickjillings@1289 1294
nickjillings@1289 1295 // Document order sorting
nickjillings@1289 1296 sortOrder = hasCompare ?
nickjillings@1289 1297 function( a, b ) {
nickjillings@1289 1298
nickjillings@1289 1299 // Flag for duplicate removal
nickjillings@1289 1300 if ( a === b ) {
nickjillings@1289 1301 hasDuplicate = true;
nickjillings@1289 1302 return 0;
nickjillings@1289 1303 }
nickjillings@1289 1304
nickjillings@1289 1305 // Sort on method existence if only one input has compareDocumentPosition
nickjillings@1289 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nickjillings@1289 1307 if ( compare ) {
nickjillings@1289 1308 return compare;
nickjillings@1289 1309 }
nickjillings@1289 1310
nickjillings@1289 1311 // Calculate position if both inputs belong to the same document
nickjillings@1289 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nickjillings@1289 1313 a.compareDocumentPosition( b ) :
nickjillings@1289 1314
nickjillings@1289 1315 // Otherwise we know they are disconnected
nickjillings@1289 1316 1;
nickjillings@1289 1317
nickjillings@1289 1318 // Disconnected nodes
nickjillings@1289 1319 if ( compare & 1 ||
nickjillings@1289 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nickjillings@1289 1321
nickjillings@1289 1322 // Choose the first element that is related to our preferred document
nickjillings@1289 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nickjillings@1289 1324 return -1;
nickjillings@1289 1325 }
nickjillings@1289 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nickjillings@1289 1327 return 1;
nickjillings@1289 1328 }
nickjillings@1289 1329
nickjillings@1289 1330 // Maintain original order
nickjillings@1289 1331 return sortInput ?
nickjillings@1289 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1289 1333 0;
nickjillings@1289 1334 }
nickjillings@1289 1335
nickjillings@1289 1336 return compare & 4 ? -1 : 1;
nickjillings@1289 1337 } :
nickjillings@1289 1338 function( a, b ) {
nickjillings@1289 1339 // Exit early if the nodes are identical
nickjillings@1289 1340 if ( a === b ) {
nickjillings@1289 1341 hasDuplicate = true;
nickjillings@1289 1342 return 0;
nickjillings@1289 1343 }
nickjillings@1289 1344
nickjillings@1289 1345 var cur,
nickjillings@1289 1346 i = 0,
nickjillings@1289 1347 aup = a.parentNode,
nickjillings@1289 1348 bup = b.parentNode,
nickjillings@1289 1349 ap = [ a ],
nickjillings@1289 1350 bp = [ b ];
nickjillings@1289 1351
nickjillings@1289 1352 // Parentless nodes are either documents or disconnected
nickjillings@1289 1353 if ( !aup || !bup ) {
nickjillings@1289 1354 return a === doc ? -1 :
nickjillings@1289 1355 b === doc ? 1 :
nickjillings@1289 1356 aup ? -1 :
nickjillings@1289 1357 bup ? 1 :
nickjillings@1289 1358 sortInput ?
nickjillings@1289 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1289 1360 0;
nickjillings@1289 1361
nickjillings@1289 1362 // If the nodes are siblings, we can do a quick check
nickjillings@1289 1363 } else if ( aup === bup ) {
nickjillings@1289 1364 return siblingCheck( a, b );
nickjillings@1289 1365 }
nickjillings@1289 1366
nickjillings@1289 1367 // Otherwise we need full lists of their ancestors for comparison
nickjillings@1289 1368 cur = a;
nickjillings@1289 1369 while ( (cur = cur.parentNode) ) {
nickjillings@1289 1370 ap.unshift( cur );
nickjillings@1289 1371 }
nickjillings@1289 1372 cur = b;
nickjillings@1289 1373 while ( (cur = cur.parentNode) ) {
nickjillings@1289 1374 bp.unshift( cur );
nickjillings@1289 1375 }
nickjillings@1289 1376
nickjillings@1289 1377 // Walk down the tree looking for a discrepancy
nickjillings@1289 1378 while ( ap[i] === bp[i] ) {
nickjillings@1289 1379 i++;
nickjillings@1289 1380 }
nickjillings@1289 1381
nickjillings@1289 1382 return i ?
nickjillings@1289 1383 // Do a sibling check if the nodes have a common ancestor
nickjillings@1289 1384 siblingCheck( ap[i], bp[i] ) :
nickjillings@1289 1385
nickjillings@1289 1386 // Otherwise nodes in our document sort first
nickjillings@1289 1387 ap[i] === preferredDoc ? -1 :
nickjillings@1289 1388 bp[i] === preferredDoc ? 1 :
nickjillings@1289 1389 0;
nickjillings@1289 1390 };
nickjillings@1289 1391
nickjillings@1289 1392 return doc;
nickjillings@1289 1393 };
nickjillings@1289 1394
nickjillings@1289 1395 Sizzle.matches = function( expr, elements ) {
nickjillings@1289 1396 return Sizzle( expr, null, null, elements );
nickjillings@1289 1397 };
nickjillings@1289 1398
nickjillings@1289 1399 Sizzle.matchesSelector = function( elem, expr ) {
nickjillings@1289 1400 // Set document vars if needed
nickjillings@1289 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1289 1402 setDocument( elem );
nickjillings@1289 1403 }
nickjillings@1289 1404
nickjillings@1289 1405 // Make sure that attribute selectors are quoted
nickjillings@1289 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nickjillings@1289 1407
nickjillings@1289 1408 if ( support.matchesSelector && documentIsHTML &&
nickjillings@1289 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nickjillings@1289 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nickjillings@1289 1411
nickjillings@1289 1412 try {
nickjillings@1289 1413 var ret = matches.call( elem, expr );
nickjillings@1289 1414
nickjillings@1289 1415 // IE 9's matchesSelector returns false on disconnected nodes
nickjillings@1289 1416 if ( ret || support.disconnectedMatch ||
nickjillings@1289 1417 // As well, disconnected nodes are said to be in a document
nickjillings@1289 1418 // fragment in IE 9
nickjillings@1289 1419 elem.document && elem.document.nodeType !== 11 ) {
nickjillings@1289 1420 return ret;
nickjillings@1289 1421 }
nickjillings@1289 1422 } catch (e) {}
nickjillings@1289 1423 }
nickjillings@1289 1424
nickjillings@1289 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nickjillings@1289 1426 };
nickjillings@1289 1427
nickjillings@1289 1428 Sizzle.contains = function( context, elem ) {
nickjillings@1289 1429 // Set document vars if needed
nickjillings@1289 1430 if ( ( context.ownerDocument || context ) !== document ) {
nickjillings@1289 1431 setDocument( context );
nickjillings@1289 1432 }
nickjillings@1289 1433 return contains( context, elem );
nickjillings@1289 1434 };
nickjillings@1289 1435
nickjillings@1289 1436 Sizzle.attr = function( elem, name ) {
nickjillings@1289 1437 // Set document vars if needed
nickjillings@1289 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1289 1439 setDocument( elem );
nickjillings@1289 1440 }
nickjillings@1289 1441
nickjillings@1289 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nickjillings@1289 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nickjillings@1289 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nickjillings@1289 1445 fn( elem, name, !documentIsHTML ) :
nickjillings@1289 1446 undefined;
nickjillings@1289 1447
nickjillings@1289 1448 return val !== undefined ?
nickjillings@1289 1449 val :
nickjillings@1289 1450 support.attributes || !documentIsHTML ?
nickjillings@1289 1451 elem.getAttribute( name ) :
nickjillings@1289 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nickjillings@1289 1453 val.value :
nickjillings@1289 1454 null;
nickjillings@1289 1455 };
nickjillings@1289 1456
nickjillings@1289 1457 Sizzle.error = function( msg ) {
nickjillings@1289 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nickjillings@1289 1459 };
nickjillings@1289 1460
nickjillings@1289 1461 /**
nickjillings@1289 1462 * Document sorting and removing duplicates
nickjillings@1289 1463 * @param {ArrayLike} results
nickjillings@1289 1464 */
nickjillings@1289 1465 Sizzle.uniqueSort = function( results ) {
nickjillings@1289 1466 var elem,
nickjillings@1289 1467 duplicates = [],
nickjillings@1289 1468 j = 0,
nickjillings@1289 1469 i = 0;
nickjillings@1289 1470
nickjillings@1289 1471 // Unless we *know* we can detect duplicates, assume their presence
nickjillings@1289 1472 hasDuplicate = !support.detectDuplicates;
nickjillings@1289 1473 sortInput = !support.sortStable && results.slice( 0 );
nickjillings@1289 1474 results.sort( sortOrder );
nickjillings@1289 1475
nickjillings@1289 1476 if ( hasDuplicate ) {
nickjillings@1289 1477 while ( (elem = results[i++]) ) {
nickjillings@1289 1478 if ( elem === results[ i ] ) {
nickjillings@1289 1479 j = duplicates.push( i );
nickjillings@1289 1480 }
nickjillings@1289 1481 }
nickjillings@1289 1482 while ( j-- ) {
nickjillings@1289 1483 results.splice( duplicates[ j ], 1 );
nickjillings@1289 1484 }
nickjillings@1289 1485 }
nickjillings@1289 1486
nickjillings@1289 1487 // Clear input after sorting to release objects
nickjillings@1289 1488 // See https://github.com/jquery/sizzle/pull/225
nickjillings@1289 1489 sortInput = null;
nickjillings@1289 1490
nickjillings@1289 1491 return results;
nickjillings@1289 1492 };
nickjillings@1289 1493
nickjillings@1289 1494 /**
nickjillings@1289 1495 * Utility function for retrieving the text value of an array of DOM nodes
nickjillings@1289 1496 * @param {Array|Element} elem
nickjillings@1289 1497 */
nickjillings@1289 1498 getText = Sizzle.getText = function( elem ) {
nickjillings@1289 1499 var node,
nickjillings@1289 1500 ret = "",
nickjillings@1289 1501 i = 0,
nickjillings@1289 1502 nodeType = elem.nodeType;
nickjillings@1289 1503
nickjillings@1289 1504 if ( !nodeType ) {
nickjillings@1289 1505 // If no nodeType, this is expected to be an array
nickjillings@1289 1506 while ( (node = elem[i++]) ) {
nickjillings@1289 1507 // Do not traverse comment nodes
nickjillings@1289 1508 ret += getText( node );
nickjillings@1289 1509 }
nickjillings@1289 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nickjillings@1289 1511 // Use textContent for elements
nickjillings@1289 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nickjillings@1289 1513 if ( typeof elem.textContent === "string" ) {
nickjillings@1289 1514 return elem.textContent;
nickjillings@1289 1515 } else {
nickjillings@1289 1516 // Traverse its children
nickjillings@1289 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1289 1518 ret += getText( elem );
nickjillings@1289 1519 }
nickjillings@1289 1520 }
nickjillings@1289 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nickjillings@1289 1522 return elem.nodeValue;
nickjillings@1289 1523 }
nickjillings@1289 1524 // Do not include comment or processing instruction nodes
nickjillings@1289 1525
nickjillings@1289 1526 return ret;
nickjillings@1289 1527 };
nickjillings@1289 1528
nickjillings@1289 1529 Expr = Sizzle.selectors = {
nickjillings@1289 1530
nickjillings@1289 1531 // Can be adjusted by the user
nickjillings@1289 1532 cacheLength: 50,
nickjillings@1289 1533
nickjillings@1289 1534 createPseudo: markFunction,
nickjillings@1289 1535
nickjillings@1289 1536 match: matchExpr,
nickjillings@1289 1537
nickjillings@1289 1538 attrHandle: {},
nickjillings@1289 1539
nickjillings@1289 1540 find: {},
nickjillings@1289 1541
nickjillings@1289 1542 relative: {
nickjillings@1289 1543 ">": { dir: "parentNode", first: true },
nickjillings@1289 1544 " ": { dir: "parentNode" },
nickjillings@1289 1545 "+": { dir: "previousSibling", first: true },
nickjillings@1289 1546 "~": { dir: "previousSibling" }
nickjillings@1289 1547 },
nickjillings@1289 1548
nickjillings@1289 1549 preFilter: {
nickjillings@1289 1550 "ATTR": function( match ) {
nickjillings@1289 1551 match[1] = match[1].replace( runescape, funescape );
nickjillings@1289 1552
nickjillings@1289 1553 // Move the given value to match[3] whether quoted or unquoted
nickjillings@1289 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nickjillings@1289 1555
nickjillings@1289 1556 if ( match[2] === "~=" ) {
nickjillings@1289 1557 match[3] = " " + match[3] + " ";
nickjillings@1289 1558 }
nickjillings@1289 1559
nickjillings@1289 1560 return match.slice( 0, 4 );
nickjillings@1289 1561 },
nickjillings@1289 1562
nickjillings@1289 1563 "CHILD": function( match ) {
nickjillings@1289 1564 /* matches from matchExpr["CHILD"]
nickjillings@1289 1565 1 type (only|nth|...)
nickjillings@1289 1566 2 what (child|of-type)
nickjillings@1289 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nickjillings@1289 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nickjillings@1289 1569 5 sign of xn-component
nickjillings@1289 1570 6 x of xn-component
nickjillings@1289 1571 7 sign of y-component
nickjillings@1289 1572 8 y of y-component
nickjillings@1289 1573 */
nickjillings@1289 1574 match[1] = match[1].toLowerCase();
nickjillings@1289 1575
nickjillings@1289 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nickjillings@1289 1577 // nth-* requires argument
nickjillings@1289 1578 if ( !match[3] ) {
nickjillings@1289 1579 Sizzle.error( match[0] );
nickjillings@1289 1580 }
nickjillings@1289 1581
nickjillings@1289 1582 // numeric x and y parameters for Expr.filter.CHILD
nickjillings@1289 1583 // remember that false/true cast respectively to 0/1
nickjillings@1289 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nickjillings@1289 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nickjillings@1289 1586
nickjillings@1289 1587 // other types prohibit arguments
nickjillings@1289 1588 } else if ( match[3] ) {
nickjillings@1289 1589 Sizzle.error( match[0] );
nickjillings@1289 1590 }
nickjillings@1289 1591
nickjillings@1289 1592 return match;
nickjillings@1289 1593 },
nickjillings@1289 1594
nickjillings@1289 1595 "PSEUDO": function( match ) {
nickjillings@1289 1596 var excess,
nickjillings@1289 1597 unquoted = !match[6] && match[2];
nickjillings@1289 1598
nickjillings@1289 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nickjillings@1289 1600 return null;
nickjillings@1289 1601 }
nickjillings@1289 1602
nickjillings@1289 1603 // Accept quoted arguments as-is
nickjillings@1289 1604 if ( match[3] ) {
nickjillings@1289 1605 match[2] = match[4] || match[5] || "";
nickjillings@1289 1606
nickjillings@1289 1607 // Strip excess characters from unquoted arguments
nickjillings@1289 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nickjillings@1289 1609 // Get excess from tokenize (recursively)
nickjillings@1289 1610 (excess = tokenize( unquoted, true )) &&
nickjillings@1289 1611 // advance to the next closing parenthesis
nickjillings@1289 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nickjillings@1289 1613
nickjillings@1289 1614 // excess is a negative index
nickjillings@1289 1615 match[0] = match[0].slice( 0, excess );
nickjillings@1289 1616 match[2] = unquoted.slice( 0, excess );
nickjillings@1289 1617 }
nickjillings@1289 1618
nickjillings@1289 1619 // Return only captures needed by the pseudo filter method (type and argument)
nickjillings@1289 1620 return match.slice( 0, 3 );
nickjillings@1289 1621 }
nickjillings@1289 1622 },
nickjillings@1289 1623
nickjillings@1289 1624 filter: {
nickjillings@1289 1625
nickjillings@1289 1626 "TAG": function( nodeNameSelector ) {
nickjillings@1289 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nickjillings@1289 1628 return nodeNameSelector === "*" ?
nickjillings@1289 1629 function() { return true; } :
nickjillings@1289 1630 function( elem ) {
nickjillings@1289 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nickjillings@1289 1632 };
nickjillings@1289 1633 },
nickjillings@1289 1634
nickjillings@1289 1635 "CLASS": function( className ) {
nickjillings@1289 1636 var pattern = classCache[ className + " " ];
nickjillings@1289 1637
nickjillings@1289 1638 return pattern ||
nickjillings@1289 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nickjillings@1289 1640 classCache( className, function( elem ) {
nickjillings@1289 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nickjillings@1289 1642 });
nickjillings@1289 1643 },
nickjillings@1289 1644
nickjillings@1289 1645 "ATTR": function( name, operator, check ) {
nickjillings@1289 1646 return function( elem ) {
nickjillings@1289 1647 var result = Sizzle.attr( elem, name );
nickjillings@1289 1648
nickjillings@1289 1649 if ( result == null ) {
nickjillings@1289 1650 return operator === "!=";
nickjillings@1289 1651 }
nickjillings@1289 1652 if ( !operator ) {
nickjillings@1289 1653 return true;
nickjillings@1289 1654 }
nickjillings@1289 1655
nickjillings@1289 1656 result += "";
nickjillings@1289 1657
nickjillings@1289 1658 return operator === "=" ? result === check :
nickjillings@1289 1659 operator === "!=" ? result !== check :
nickjillings@1289 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nickjillings@1289 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nickjillings@1289 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nickjillings@1289 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nickjillings@1289 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nickjillings@1289 1665 false;
nickjillings@1289 1666 };
nickjillings@1289 1667 },
nickjillings@1289 1668
nickjillings@1289 1669 "CHILD": function( type, what, argument, first, last ) {
nickjillings@1289 1670 var simple = type.slice( 0, 3 ) !== "nth",
nickjillings@1289 1671 forward = type.slice( -4 ) !== "last",
nickjillings@1289 1672 ofType = what === "of-type";
nickjillings@1289 1673
nickjillings@1289 1674 return first === 1 && last === 0 ?
nickjillings@1289 1675
nickjillings@1289 1676 // Shortcut for :nth-*(n)
nickjillings@1289 1677 function( elem ) {
nickjillings@1289 1678 return !!elem.parentNode;
nickjillings@1289 1679 } :
nickjillings@1289 1680
nickjillings@1289 1681 function( elem, context, xml ) {
nickjillings@1289 1682 var cache, outerCache, node, diff, nodeIndex, start,
nickjillings@1289 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nickjillings@1289 1684 parent = elem.parentNode,
nickjillings@1289 1685 name = ofType && elem.nodeName.toLowerCase(),
nickjillings@1289 1686 useCache = !xml && !ofType;
nickjillings@1289 1687
nickjillings@1289 1688 if ( parent ) {
nickjillings@1289 1689
nickjillings@1289 1690 // :(first|last|only)-(child|of-type)
nickjillings@1289 1691 if ( simple ) {
nickjillings@1289 1692 while ( dir ) {
nickjillings@1289 1693 node = elem;
nickjillings@1289 1694 while ( (node = node[ dir ]) ) {
nickjillings@1289 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nickjillings@1289 1696 return false;
nickjillings@1289 1697 }
nickjillings@1289 1698 }
nickjillings@1289 1699 // Reverse direction for :only-* (if we haven't yet done so)
nickjillings@1289 1700 start = dir = type === "only" && !start && "nextSibling";
nickjillings@1289 1701 }
nickjillings@1289 1702 return true;
nickjillings@1289 1703 }
nickjillings@1289 1704
nickjillings@1289 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nickjillings@1289 1706
nickjillings@1289 1707 // non-xml :nth-child(...) stores cache data on `parent`
nickjillings@1289 1708 if ( forward && useCache ) {
nickjillings@1289 1709 // Seek `elem` from a previously-cached index
nickjillings@1289 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nickjillings@1289 1711 cache = outerCache[ type ] || [];
nickjillings@1289 1712 nodeIndex = cache[0] === dirruns && cache[1];
nickjillings@1289 1713 diff = cache[0] === dirruns && cache[2];
nickjillings@1289 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nickjillings@1289 1715
nickjillings@1289 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1289 1717
nickjillings@1289 1718 // Fallback to seeking `elem` from the start
nickjillings@1289 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1289 1720
nickjillings@1289 1721 // When found, cache indexes on `parent` and break
nickjillings@1289 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nickjillings@1289 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nickjillings@1289 1724 break;
nickjillings@1289 1725 }
nickjillings@1289 1726 }
nickjillings@1289 1727
nickjillings@1289 1728 // Use previously-cached element index if available
nickjillings@1289 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nickjillings@1289 1730 diff = cache[1];
nickjillings@1289 1731
nickjillings@1289 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nickjillings@1289 1733 } else {
nickjillings@1289 1734 // Use the same loop as above to seek `elem` from the start
nickjillings@1289 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1289 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1289 1737
nickjillings@1289 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nickjillings@1289 1739 // Cache the index of each encountered element
nickjillings@1289 1740 if ( useCache ) {
nickjillings@1289 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nickjillings@1289 1742 }
nickjillings@1289 1743
nickjillings@1289 1744 if ( node === elem ) {
nickjillings@1289 1745 break;
nickjillings@1289 1746 }
nickjillings@1289 1747 }
nickjillings@1289 1748 }
nickjillings@1289 1749 }
nickjillings@1289 1750
nickjillings@1289 1751 // Incorporate the offset, then check against cycle size
nickjillings@1289 1752 diff -= last;
nickjillings@1289 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nickjillings@1289 1754 }
nickjillings@1289 1755 };
nickjillings@1289 1756 },
nickjillings@1289 1757
nickjillings@1289 1758 "PSEUDO": function( pseudo, argument ) {
nickjillings@1289 1759 // pseudo-class names are case-insensitive
nickjillings@1289 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nickjillings@1289 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nickjillings@1289 1762 // Remember that setFilters inherits from pseudos
nickjillings@1289 1763 var args,
nickjillings@1289 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nickjillings@1289 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nickjillings@1289 1766
nickjillings@1289 1767 // The user may use createPseudo to indicate that
nickjillings@1289 1768 // arguments are needed to create the filter function
nickjillings@1289 1769 // just as Sizzle does
nickjillings@1289 1770 if ( fn[ expando ] ) {
nickjillings@1289 1771 return fn( argument );
nickjillings@1289 1772 }
nickjillings@1289 1773
nickjillings@1289 1774 // But maintain support for old signatures
nickjillings@1289 1775 if ( fn.length > 1 ) {
nickjillings@1289 1776 args = [ pseudo, pseudo, "", argument ];
nickjillings@1289 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nickjillings@1289 1778 markFunction(function( seed, matches ) {
nickjillings@1289 1779 var idx,
nickjillings@1289 1780 matched = fn( seed, argument ),
nickjillings@1289 1781 i = matched.length;
nickjillings@1289 1782 while ( i-- ) {
nickjillings@1289 1783 idx = indexOf( seed, matched[i] );
nickjillings@1289 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nickjillings@1289 1785 }
nickjillings@1289 1786 }) :
nickjillings@1289 1787 function( elem ) {
nickjillings@1289 1788 return fn( elem, 0, args );
nickjillings@1289 1789 };
nickjillings@1289 1790 }
nickjillings@1289 1791
nickjillings@1289 1792 return fn;
nickjillings@1289 1793 }
nickjillings@1289 1794 },
nickjillings@1289 1795
nickjillings@1289 1796 pseudos: {
nickjillings@1289 1797 // Potentially complex pseudos
nickjillings@1289 1798 "not": markFunction(function( selector ) {
nickjillings@1289 1799 // Trim the selector passed to compile
nickjillings@1289 1800 // to avoid treating leading and trailing
nickjillings@1289 1801 // spaces as combinators
nickjillings@1289 1802 var input = [],
nickjillings@1289 1803 results = [],
nickjillings@1289 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nickjillings@1289 1805
nickjillings@1289 1806 return matcher[ expando ] ?
nickjillings@1289 1807 markFunction(function( seed, matches, context, xml ) {
nickjillings@1289 1808 var elem,
nickjillings@1289 1809 unmatched = matcher( seed, null, xml, [] ),
nickjillings@1289 1810 i = seed.length;
nickjillings@1289 1811
nickjillings@1289 1812 // Match elements unmatched by `matcher`
nickjillings@1289 1813 while ( i-- ) {
nickjillings@1289 1814 if ( (elem = unmatched[i]) ) {
nickjillings@1289 1815 seed[i] = !(matches[i] = elem);
nickjillings@1289 1816 }
nickjillings@1289 1817 }
nickjillings@1289 1818 }) :
nickjillings@1289 1819 function( elem, context, xml ) {
nickjillings@1289 1820 input[0] = elem;
nickjillings@1289 1821 matcher( input, null, xml, results );
nickjillings@1289 1822 // Don't keep the element (issue #299)
nickjillings@1289 1823 input[0] = null;
nickjillings@1289 1824 return !results.pop();
nickjillings@1289 1825 };
nickjillings@1289 1826 }),
nickjillings@1289 1827
nickjillings@1289 1828 "has": markFunction(function( selector ) {
nickjillings@1289 1829 return function( elem ) {
nickjillings@1289 1830 return Sizzle( selector, elem ).length > 0;
nickjillings@1289 1831 };
nickjillings@1289 1832 }),
nickjillings@1289 1833
nickjillings@1289 1834 "contains": markFunction(function( text ) {
nickjillings@1289 1835 text = text.replace( runescape, funescape );
nickjillings@1289 1836 return function( elem ) {
nickjillings@1289 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nickjillings@1289 1838 };
nickjillings@1289 1839 }),
nickjillings@1289 1840
nickjillings@1289 1841 // "Whether an element is represented by a :lang() selector
nickjillings@1289 1842 // is based solely on the element's language value
nickjillings@1289 1843 // being equal to the identifier C,
nickjillings@1289 1844 // or beginning with the identifier C immediately followed by "-".
nickjillings@1289 1845 // The matching of C against the element's language value is performed case-insensitively.
nickjillings@1289 1846 // The identifier C does not have to be a valid language name."
nickjillings@1289 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nickjillings@1289 1848 "lang": markFunction( function( lang ) {
nickjillings@1289 1849 // lang value must be a valid identifier
nickjillings@1289 1850 if ( !ridentifier.test(lang || "") ) {
nickjillings@1289 1851 Sizzle.error( "unsupported lang: " + lang );
nickjillings@1289 1852 }
nickjillings@1289 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nickjillings@1289 1854 return function( elem ) {
nickjillings@1289 1855 var elemLang;
nickjillings@1289 1856 do {
nickjillings@1289 1857 if ( (elemLang = documentIsHTML ?
nickjillings@1289 1858 elem.lang :
nickjillings@1289 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nickjillings@1289 1860
nickjillings@1289 1861 elemLang = elemLang.toLowerCase();
nickjillings@1289 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nickjillings@1289 1863 }
nickjillings@1289 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nickjillings@1289 1865 return false;
nickjillings@1289 1866 };
nickjillings@1289 1867 }),
nickjillings@1289 1868
nickjillings@1289 1869 // Miscellaneous
nickjillings@1289 1870 "target": function( elem ) {
nickjillings@1289 1871 var hash = window.location && window.location.hash;
nickjillings@1289 1872 return hash && hash.slice( 1 ) === elem.id;
nickjillings@1289 1873 },
nickjillings@1289 1874
nickjillings@1289 1875 "root": function( elem ) {
nickjillings@1289 1876 return elem === docElem;
nickjillings@1289 1877 },
nickjillings@1289 1878
nickjillings@1289 1879 "focus": function( elem ) {
nickjillings@1289 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nickjillings@1289 1881 },
nickjillings@1289 1882
nickjillings@1289 1883 // Boolean properties
nickjillings@1289 1884 "enabled": function( elem ) {
nickjillings@1289 1885 return elem.disabled === false;
nickjillings@1289 1886 },
nickjillings@1289 1887
nickjillings@1289 1888 "disabled": function( elem ) {
nickjillings@1289 1889 return elem.disabled === true;
nickjillings@1289 1890 },
nickjillings@1289 1891
nickjillings@1289 1892 "checked": function( elem ) {
nickjillings@1289 1893 // In CSS3, :checked should return both checked and selected elements
nickjillings@1289 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1289 1895 var nodeName = elem.nodeName.toLowerCase();
nickjillings@1289 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nickjillings@1289 1897 },
nickjillings@1289 1898
nickjillings@1289 1899 "selected": function( elem ) {
nickjillings@1289 1900 // Accessing this property makes selected-by-default
nickjillings@1289 1901 // options in Safari work properly
nickjillings@1289 1902 if ( elem.parentNode ) {
nickjillings@1289 1903 elem.parentNode.selectedIndex;
nickjillings@1289 1904 }
nickjillings@1289 1905
nickjillings@1289 1906 return elem.selected === true;
nickjillings@1289 1907 },
nickjillings@1289 1908
nickjillings@1289 1909 // Contents
nickjillings@1289 1910 "empty": function( elem ) {
nickjillings@1289 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nickjillings@1289 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nickjillings@1289 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nickjillings@1289 1914 // nodeType < 6 works because attributes (2) do not appear as children
nickjillings@1289 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1289 1916 if ( elem.nodeType < 6 ) {
nickjillings@1289 1917 return false;
nickjillings@1289 1918 }
nickjillings@1289 1919 }
nickjillings@1289 1920 return true;
nickjillings@1289 1921 },
nickjillings@1289 1922
nickjillings@1289 1923 "parent": function( elem ) {
nickjillings@1289 1924 return !Expr.pseudos["empty"]( elem );
nickjillings@1289 1925 },
nickjillings@1289 1926
nickjillings@1289 1927 // Element/input types
nickjillings@1289 1928 "header": function( elem ) {
nickjillings@1289 1929 return rheader.test( elem.nodeName );
nickjillings@1289 1930 },
nickjillings@1289 1931
nickjillings@1289 1932 "input": function( elem ) {
nickjillings@1289 1933 return rinputs.test( elem.nodeName );
nickjillings@1289 1934 },
nickjillings@1289 1935
nickjillings@1289 1936 "button": function( elem ) {
nickjillings@1289 1937 var name = elem.nodeName.toLowerCase();
nickjillings@1289 1938 return name === "input" && elem.type === "button" || name === "button";
nickjillings@1289 1939 },
nickjillings@1289 1940
nickjillings@1289 1941 "text": function( elem ) {
nickjillings@1289 1942 var attr;
nickjillings@1289 1943 return elem.nodeName.toLowerCase() === "input" &&
nickjillings@1289 1944 elem.type === "text" &&
nickjillings@1289 1945
nickjillings@1289 1946 // Support: IE<8
nickjillings@1289 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nickjillings@1289 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nickjillings@1289 1949 },
nickjillings@1289 1950
nickjillings@1289 1951 // Position-in-collection
nickjillings@1289 1952 "first": createPositionalPseudo(function() {
nickjillings@1289 1953 return [ 0 ];
nickjillings@1289 1954 }),
nickjillings@1289 1955
nickjillings@1289 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1289 1957 return [ length - 1 ];
nickjillings@1289 1958 }),
nickjillings@1289 1959
nickjillings@1289 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1289 1961 return [ argument < 0 ? argument + length : argument ];
nickjillings@1289 1962 }),
nickjillings@1289 1963
nickjillings@1289 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1289 1965 var i = 0;
nickjillings@1289 1966 for ( ; i < length; i += 2 ) {
nickjillings@1289 1967 matchIndexes.push( i );
nickjillings@1289 1968 }
nickjillings@1289 1969 return matchIndexes;
nickjillings@1289 1970 }),
nickjillings@1289 1971
nickjillings@1289 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1289 1973 var i = 1;
nickjillings@1289 1974 for ( ; i < length; i += 2 ) {
nickjillings@1289 1975 matchIndexes.push( i );
nickjillings@1289 1976 }
nickjillings@1289 1977 return matchIndexes;
nickjillings@1289 1978 }),
nickjillings@1289 1979
nickjillings@1289 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1289 1981 var i = argument < 0 ? argument + length : argument;
nickjillings@1289 1982 for ( ; --i >= 0; ) {
nickjillings@1289 1983 matchIndexes.push( i );
nickjillings@1289 1984 }
nickjillings@1289 1985 return matchIndexes;
nickjillings@1289 1986 }),
nickjillings@1289 1987
nickjillings@1289 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1289 1989 var i = argument < 0 ? argument + length : argument;
nickjillings@1289 1990 for ( ; ++i < length; ) {
nickjillings@1289 1991 matchIndexes.push( i );
nickjillings@1289 1992 }
nickjillings@1289 1993 return matchIndexes;
nickjillings@1289 1994 })
nickjillings@1289 1995 }
nickjillings@1289 1996 };
nickjillings@1289 1997
nickjillings@1289 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nickjillings@1289 1999
nickjillings@1289 2000 // Add button/input type pseudos
nickjillings@1289 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nickjillings@1289 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nickjillings@1289 2003 }
nickjillings@1289 2004 for ( i in { submit: true, reset: true } ) {
nickjillings@1289 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nickjillings@1289 2006 }
nickjillings@1289 2007
nickjillings@1289 2008 // Easy API for creating new setFilters
nickjillings@1289 2009 function setFilters() {}
nickjillings@1289 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nickjillings@1289 2011 Expr.setFilters = new setFilters();
nickjillings@1289 2012
nickjillings@1289 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nickjillings@1289 2014 var matched, match, tokens, type,
nickjillings@1289 2015 soFar, groups, preFilters,
nickjillings@1289 2016 cached = tokenCache[ selector + " " ];
nickjillings@1289 2017
nickjillings@1289 2018 if ( cached ) {
nickjillings@1289 2019 return parseOnly ? 0 : cached.slice( 0 );
nickjillings@1289 2020 }
nickjillings@1289 2021
nickjillings@1289 2022 soFar = selector;
nickjillings@1289 2023 groups = [];
nickjillings@1289 2024 preFilters = Expr.preFilter;
nickjillings@1289 2025
nickjillings@1289 2026 while ( soFar ) {
nickjillings@1289 2027
nickjillings@1289 2028 // Comma and first run
nickjillings@1289 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nickjillings@1289 2030 if ( match ) {
nickjillings@1289 2031 // Don't consume trailing commas as valid
nickjillings@1289 2032 soFar = soFar.slice( match[0].length ) || soFar;
nickjillings@1289 2033 }
nickjillings@1289 2034 groups.push( (tokens = []) );
nickjillings@1289 2035 }
nickjillings@1289 2036
nickjillings@1289 2037 matched = false;
nickjillings@1289 2038
nickjillings@1289 2039 // Combinators
nickjillings@1289 2040 if ( (match = rcombinators.exec( soFar )) ) {
nickjillings@1289 2041 matched = match.shift();
nickjillings@1289 2042 tokens.push({
nickjillings@1289 2043 value: matched,
nickjillings@1289 2044 // Cast descendant combinators to space
nickjillings@1289 2045 type: match[0].replace( rtrim, " " )
nickjillings@1289 2046 });
nickjillings@1289 2047 soFar = soFar.slice( matched.length );
nickjillings@1289 2048 }
nickjillings@1289 2049
nickjillings@1289 2050 // Filters
nickjillings@1289 2051 for ( type in Expr.filter ) {
nickjillings@1289 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nickjillings@1289 2053 (match = preFilters[ type ]( match ))) ) {
nickjillings@1289 2054 matched = match.shift();
nickjillings@1289 2055 tokens.push({
nickjillings@1289 2056 value: matched,
nickjillings@1289 2057 type: type,
nickjillings@1289 2058 matches: match
nickjillings@1289 2059 });
nickjillings@1289 2060 soFar = soFar.slice( matched.length );
nickjillings@1289 2061 }
nickjillings@1289 2062 }
nickjillings@1289 2063
nickjillings@1289 2064 if ( !matched ) {
nickjillings@1289 2065 break;
nickjillings@1289 2066 }
nickjillings@1289 2067 }
nickjillings@1289 2068
nickjillings@1289 2069 // Return the length of the invalid excess
nickjillings@1289 2070 // if we're just parsing
nickjillings@1289 2071 // Otherwise, throw an error or return tokens
nickjillings@1289 2072 return parseOnly ?
nickjillings@1289 2073 soFar.length :
nickjillings@1289 2074 soFar ?
nickjillings@1289 2075 Sizzle.error( selector ) :
nickjillings@1289 2076 // Cache the tokens
nickjillings@1289 2077 tokenCache( selector, groups ).slice( 0 );
nickjillings@1289 2078 };
nickjillings@1289 2079
nickjillings@1289 2080 function toSelector( tokens ) {
nickjillings@1289 2081 var i = 0,
nickjillings@1289 2082 len = tokens.length,
nickjillings@1289 2083 selector = "";
nickjillings@1289 2084 for ( ; i < len; i++ ) {
nickjillings@1289 2085 selector += tokens[i].value;
nickjillings@1289 2086 }
nickjillings@1289 2087 return selector;
nickjillings@1289 2088 }
nickjillings@1289 2089
nickjillings@1289 2090 function addCombinator( matcher, combinator, base ) {
nickjillings@1289 2091 var dir = combinator.dir,
nickjillings@1289 2092 checkNonElements = base && dir === "parentNode",
nickjillings@1289 2093 doneName = done++;
nickjillings@1289 2094
nickjillings@1289 2095 return combinator.first ?
nickjillings@1289 2096 // Check against closest ancestor/preceding element
nickjillings@1289 2097 function( elem, context, xml ) {
nickjillings@1289 2098 while ( (elem = elem[ dir ]) ) {
nickjillings@1289 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1289 2100 return matcher( elem, context, xml );
nickjillings@1289 2101 }
nickjillings@1289 2102 }
nickjillings@1289 2103 } :
nickjillings@1289 2104
nickjillings@1289 2105 // Check against all ancestor/preceding elements
nickjillings@1289 2106 function( elem, context, xml ) {
nickjillings@1289 2107 var oldCache, outerCache,
nickjillings@1289 2108 newCache = [ dirruns, doneName ];
nickjillings@1289 2109
nickjillings@1289 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nickjillings@1289 2111 if ( xml ) {
nickjillings@1289 2112 while ( (elem = elem[ dir ]) ) {
nickjillings@1289 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1289 2114 if ( matcher( elem, context, xml ) ) {
nickjillings@1289 2115 return true;
nickjillings@1289 2116 }
nickjillings@1289 2117 }
nickjillings@1289 2118 }
nickjillings@1289 2119 } else {
nickjillings@1289 2120 while ( (elem = elem[ dir ]) ) {
nickjillings@1289 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1289 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nickjillings@1289 2123 if ( (oldCache = outerCache[ dir ]) &&
nickjillings@1289 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nickjillings@1289 2125
nickjillings@1289 2126 // Assign to newCache so results back-propagate to previous elements
nickjillings@1289 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nickjillings@1289 2128 } else {
nickjillings@1289 2129 // Reuse newcache so results back-propagate to previous elements
nickjillings@1289 2130 outerCache[ dir ] = newCache;
nickjillings@1289 2131
nickjillings@1289 2132 // A match means we're done; a fail means we have to keep checking
nickjillings@1289 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nickjillings@1289 2134 return true;
nickjillings@1289 2135 }
nickjillings@1289 2136 }
nickjillings@1289 2137 }
nickjillings@1289 2138 }
nickjillings@1289 2139 }
nickjillings@1289 2140 };
nickjillings@1289 2141 }
nickjillings@1289 2142
nickjillings@1289 2143 function elementMatcher( matchers ) {
nickjillings@1289 2144 return matchers.length > 1 ?
nickjillings@1289 2145 function( elem, context, xml ) {
nickjillings@1289 2146 var i = matchers.length;
nickjillings@1289 2147 while ( i-- ) {
nickjillings@1289 2148 if ( !matchers[i]( elem, context, xml ) ) {
nickjillings@1289 2149 return false;
nickjillings@1289 2150 }
nickjillings@1289 2151 }
nickjillings@1289 2152 return true;
nickjillings@1289 2153 } :
nickjillings@1289 2154 matchers[0];
nickjillings@1289 2155 }
nickjillings@1289 2156
nickjillings@1289 2157 function multipleContexts( selector, contexts, results ) {
nickjillings@1289 2158 var i = 0,
nickjillings@1289 2159 len = contexts.length;
nickjillings@1289 2160 for ( ; i < len; i++ ) {
nickjillings@1289 2161 Sizzle( selector, contexts[i], results );
nickjillings@1289 2162 }
nickjillings@1289 2163 return results;
nickjillings@1289 2164 }
nickjillings@1289 2165
nickjillings@1289 2166 function condense( unmatched, map, filter, context, xml ) {
nickjillings@1289 2167 var elem,
nickjillings@1289 2168 newUnmatched = [],
nickjillings@1289 2169 i = 0,
nickjillings@1289 2170 len = unmatched.length,
nickjillings@1289 2171 mapped = map != null;
nickjillings@1289 2172
nickjillings@1289 2173 for ( ; i < len; i++ ) {
nickjillings@1289 2174 if ( (elem = unmatched[i]) ) {
nickjillings@1289 2175 if ( !filter || filter( elem, context, xml ) ) {
nickjillings@1289 2176 newUnmatched.push( elem );
nickjillings@1289 2177 if ( mapped ) {
nickjillings@1289 2178 map.push( i );
nickjillings@1289 2179 }
nickjillings@1289 2180 }
nickjillings@1289 2181 }
nickjillings@1289 2182 }
nickjillings@1289 2183
nickjillings@1289 2184 return newUnmatched;
nickjillings@1289 2185 }
nickjillings@1289 2186
nickjillings@1289 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nickjillings@1289 2188 if ( postFilter && !postFilter[ expando ] ) {
nickjillings@1289 2189 postFilter = setMatcher( postFilter );
nickjillings@1289 2190 }
nickjillings@1289 2191 if ( postFinder && !postFinder[ expando ] ) {
nickjillings@1289 2192 postFinder = setMatcher( postFinder, postSelector );
nickjillings@1289 2193 }
nickjillings@1289 2194 return markFunction(function( seed, results, context, xml ) {
nickjillings@1289 2195 var temp, i, elem,
nickjillings@1289 2196 preMap = [],
nickjillings@1289 2197 postMap = [],
nickjillings@1289 2198 preexisting = results.length,
nickjillings@1289 2199
nickjillings@1289 2200 // Get initial elements from seed or context
nickjillings@1289 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nickjillings@1289 2202
nickjillings@1289 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nickjillings@1289 2204 matcherIn = preFilter && ( seed || !selector ) ?
nickjillings@1289 2205 condense( elems, preMap, preFilter, context, xml ) :
nickjillings@1289 2206 elems,
nickjillings@1289 2207
nickjillings@1289 2208 matcherOut = matcher ?
nickjillings@1289 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nickjillings@1289 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nickjillings@1289 2211
nickjillings@1289 2212 // ...intermediate processing is necessary
nickjillings@1289 2213 [] :
nickjillings@1289 2214
nickjillings@1289 2215 // ...otherwise use results directly
nickjillings@1289 2216 results :
nickjillings@1289 2217 matcherIn;
nickjillings@1289 2218
nickjillings@1289 2219 // Find primary matches
nickjillings@1289 2220 if ( matcher ) {
nickjillings@1289 2221 matcher( matcherIn, matcherOut, context, xml );
nickjillings@1289 2222 }
nickjillings@1289 2223
nickjillings@1289 2224 // Apply postFilter
nickjillings@1289 2225 if ( postFilter ) {
nickjillings@1289 2226 temp = condense( matcherOut, postMap );
nickjillings@1289 2227 postFilter( temp, [], context, xml );
nickjillings@1289 2228
nickjillings@1289 2229 // Un-match failing elements by moving them back to matcherIn
nickjillings@1289 2230 i = temp.length;
nickjillings@1289 2231 while ( i-- ) {
nickjillings@1289 2232 if ( (elem = temp[i]) ) {
nickjillings@1289 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nickjillings@1289 2234 }
nickjillings@1289 2235 }
nickjillings@1289 2236 }
nickjillings@1289 2237
nickjillings@1289 2238 if ( seed ) {
nickjillings@1289 2239 if ( postFinder || preFilter ) {
nickjillings@1289 2240 if ( postFinder ) {
nickjillings@1289 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nickjillings@1289 2242 temp = [];
nickjillings@1289 2243 i = matcherOut.length;
nickjillings@1289 2244 while ( i-- ) {
nickjillings@1289 2245 if ( (elem = matcherOut[i]) ) {
nickjillings@1289 2246 // Restore matcherIn since elem is not yet a final match
nickjillings@1289 2247 temp.push( (matcherIn[i] = elem) );
nickjillings@1289 2248 }
nickjillings@1289 2249 }
nickjillings@1289 2250 postFinder( null, (matcherOut = []), temp, xml );
nickjillings@1289 2251 }
nickjillings@1289 2252
nickjillings@1289 2253 // Move matched elements from seed to results to keep them synchronized
nickjillings@1289 2254 i = matcherOut.length;
nickjillings@1289 2255 while ( i-- ) {
nickjillings@1289 2256 if ( (elem = matcherOut[i]) &&
nickjillings@1289 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nickjillings@1289 2258
nickjillings@1289 2259 seed[temp] = !(results[temp] = elem);
nickjillings@1289 2260 }
nickjillings@1289 2261 }
nickjillings@1289 2262 }
nickjillings@1289 2263
nickjillings@1289 2264 // Add elements to results, through postFinder if defined
nickjillings@1289 2265 } else {
nickjillings@1289 2266 matcherOut = condense(
nickjillings@1289 2267 matcherOut === results ?
nickjillings@1289 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nickjillings@1289 2269 matcherOut
nickjillings@1289 2270 );
nickjillings@1289 2271 if ( postFinder ) {
nickjillings@1289 2272 postFinder( null, results, matcherOut, xml );
nickjillings@1289 2273 } else {
nickjillings@1289 2274 push.apply( results, matcherOut );
nickjillings@1289 2275 }
nickjillings@1289 2276 }
nickjillings@1289 2277 });
nickjillings@1289 2278 }
nickjillings@1289 2279
nickjillings@1289 2280 function matcherFromTokens( tokens ) {
nickjillings@1289 2281 var checkContext, matcher, j,
nickjillings@1289 2282 len = tokens.length,
nickjillings@1289 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nickjillings@1289 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nickjillings@1289 2285 i = leadingRelative ? 1 : 0,
nickjillings@1289 2286
nickjillings@1289 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nickjillings@1289 2288 matchContext = addCombinator( function( elem ) {
nickjillings@1289 2289 return elem === checkContext;
nickjillings@1289 2290 }, implicitRelative, true ),
nickjillings@1289 2291 matchAnyContext = addCombinator( function( elem ) {
nickjillings@1289 2292 return indexOf( checkContext, elem ) > -1;
nickjillings@1289 2293 }, implicitRelative, true ),
nickjillings@1289 2294 matchers = [ function( elem, context, xml ) {
nickjillings@1289 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nickjillings@1289 2296 (checkContext = context).nodeType ?
nickjillings@1289 2297 matchContext( elem, context, xml ) :
nickjillings@1289 2298 matchAnyContext( elem, context, xml ) );
nickjillings@1289 2299 // Avoid hanging onto element (issue #299)
nickjillings@1289 2300 checkContext = null;
nickjillings@1289 2301 return ret;
nickjillings@1289 2302 } ];
nickjillings@1289 2303
nickjillings@1289 2304 for ( ; i < len; i++ ) {
nickjillings@1289 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nickjillings@1289 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nickjillings@1289 2307 } else {
nickjillings@1289 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nickjillings@1289 2309
nickjillings@1289 2310 // Return special upon seeing a positional matcher
nickjillings@1289 2311 if ( matcher[ expando ] ) {
nickjillings@1289 2312 // Find the next relative operator (if any) for proper handling
nickjillings@1289 2313 j = ++i;
nickjillings@1289 2314 for ( ; j < len; j++ ) {
nickjillings@1289 2315 if ( Expr.relative[ tokens[j].type ] ) {
nickjillings@1289 2316 break;
nickjillings@1289 2317 }
nickjillings@1289 2318 }
nickjillings@1289 2319 return setMatcher(
nickjillings@1289 2320 i > 1 && elementMatcher( matchers ),
nickjillings@1289 2321 i > 1 && toSelector(
nickjillings@1289 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nickjillings@1289 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nickjillings@1289 2324 ).replace( rtrim, "$1" ),
nickjillings@1289 2325 matcher,
nickjillings@1289 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nickjillings@1289 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nickjillings@1289 2328 j < len && toSelector( tokens )
nickjillings@1289 2329 );
nickjillings@1289 2330 }
nickjillings@1289 2331 matchers.push( matcher );
nickjillings@1289 2332 }
nickjillings@1289 2333 }
nickjillings@1289 2334
nickjillings@1289 2335 return elementMatcher( matchers );
nickjillings@1289 2336 }
nickjillings@1289 2337
nickjillings@1289 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nickjillings@1289 2339 var bySet = setMatchers.length > 0,
nickjillings@1289 2340 byElement = elementMatchers.length > 0,
nickjillings@1289 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nickjillings@1289 2342 var elem, j, matcher,
nickjillings@1289 2343 matchedCount = 0,
nickjillings@1289 2344 i = "0",
nickjillings@1289 2345 unmatched = seed && [],
nickjillings@1289 2346 setMatched = [],
nickjillings@1289 2347 contextBackup = outermostContext,
nickjillings@1289 2348 // We must always have either seed elements or outermost context
nickjillings@1289 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nickjillings@1289 2350 // Use integer dirruns iff this is the outermost matcher
nickjillings@1289 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nickjillings@1289 2352 len = elems.length;
nickjillings@1289 2353
nickjillings@1289 2354 if ( outermost ) {
nickjillings@1289 2355 outermostContext = context !== document && context;
nickjillings@1289 2356 }
nickjillings@1289 2357
nickjillings@1289 2358 // Add elements passing elementMatchers directly to results
nickjillings@1289 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nickjillings@1289 2360 // Support: IE<9, Safari
nickjillings@1289 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nickjillings@1289 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nickjillings@1289 2363 if ( byElement && elem ) {
nickjillings@1289 2364 j = 0;
nickjillings@1289 2365 while ( (matcher = elementMatchers[j++]) ) {
nickjillings@1289 2366 if ( matcher( elem, context, xml ) ) {
nickjillings@1289 2367 results.push( elem );
nickjillings@1289 2368 break;
nickjillings@1289 2369 }
nickjillings@1289 2370 }
nickjillings@1289 2371 if ( outermost ) {
nickjillings@1289 2372 dirruns = dirrunsUnique;
nickjillings@1289 2373 }
nickjillings@1289 2374 }
nickjillings@1289 2375
nickjillings@1289 2376 // Track unmatched elements for set filters
nickjillings@1289 2377 if ( bySet ) {
nickjillings@1289 2378 // They will have gone through all possible matchers
nickjillings@1289 2379 if ( (elem = !matcher && elem) ) {
nickjillings@1289 2380 matchedCount--;
nickjillings@1289 2381 }
nickjillings@1289 2382
nickjillings@1289 2383 // Lengthen the array for every element, matched or not
nickjillings@1289 2384 if ( seed ) {
nickjillings@1289 2385 unmatched.push( elem );
nickjillings@1289 2386 }
nickjillings@1289 2387 }
nickjillings@1289 2388 }
nickjillings@1289 2389
nickjillings@1289 2390 // Apply set filters to unmatched elements
nickjillings@1289 2391 matchedCount += i;
nickjillings@1289 2392 if ( bySet && i !== matchedCount ) {
nickjillings@1289 2393 j = 0;
nickjillings@1289 2394 while ( (matcher = setMatchers[j++]) ) {
nickjillings@1289 2395 matcher( unmatched, setMatched, context, xml );
nickjillings@1289 2396 }
nickjillings@1289 2397
nickjillings@1289 2398 if ( seed ) {
nickjillings@1289 2399 // Reintegrate element matches to eliminate the need for sorting
nickjillings@1289 2400 if ( matchedCount > 0 ) {
nickjillings@1289 2401 while ( i-- ) {
nickjillings@1289 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nickjillings@1289 2403 setMatched[i] = pop.call( results );
nickjillings@1289 2404 }
nickjillings@1289 2405 }
nickjillings@1289 2406 }
nickjillings@1289 2407
nickjillings@1289 2408 // Discard index placeholder values to get only actual matches
nickjillings@1289 2409 setMatched = condense( setMatched );
nickjillings@1289 2410 }
nickjillings@1289 2411
nickjillings@1289 2412 // Add matches to results
nickjillings@1289 2413 push.apply( results, setMatched );
nickjillings@1289 2414
nickjillings@1289 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nickjillings@1289 2416 if ( outermost && !seed && setMatched.length > 0 &&
nickjillings@1289 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nickjillings@1289 2418
nickjillings@1289 2419 Sizzle.uniqueSort( results );
nickjillings@1289 2420 }
nickjillings@1289 2421 }
nickjillings@1289 2422
nickjillings@1289 2423 // Override manipulation of globals by nested matchers
nickjillings@1289 2424 if ( outermost ) {
nickjillings@1289 2425 dirruns = dirrunsUnique;
nickjillings@1289 2426 outermostContext = contextBackup;
nickjillings@1289 2427 }
nickjillings@1289 2428
nickjillings@1289 2429 return unmatched;
nickjillings@1289 2430 };
nickjillings@1289 2431
nickjillings@1289 2432 return bySet ?
nickjillings@1289 2433 markFunction( superMatcher ) :
nickjillings@1289 2434 superMatcher;
nickjillings@1289 2435 }
nickjillings@1289 2436
nickjillings@1289 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nickjillings@1289 2438 var i,
nickjillings@1289 2439 setMatchers = [],
nickjillings@1289 2440 elementMatchers = [],
nickjillings@1289 2441 cached = compilerCache[ selector + " " ];
nickjillings@1289 2442
nickjillings@1289 2443 if ( !cached ) {
nickjillings@1289 2444 // Generate a function of recursive functions that can be used to check each element
nickjillings@1289 2445 if ( !match ) {
nickjillings@1289 2446 match = tokenize( selector );
nickjillings@1289 2447 }
nickjillings@1289 2448 i = match.length;
nickjillings@1289 2449 while ( i-- ) {
nickjillings@1289 2450 cached = matcherFromTokens( match[i] );
nickjillings@1289 2451 if ( cached[ expando ] ) {
nickjillings@1289 2452 setMatchers.push( cached );
nickjillings@1289 2453 } else {
nickjillings@1289 2454 elementMatchers.push( cached );
nickjillings@1289 2455 }
nickjillings@1289 2456 }
nickjillings@1289 2457
nickjillings@1289 2458 // Cache the compiled function
nickjillings@1289 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nickjillings@1289 2460
nickjillings@1289 2461 // Save selector and tokenization
nickjillings@1289 2462 cached.selector = selector;
nickjillings@1289 2463 }
nickjillings@1289 2464 return cached;
nickjillings@1289 2465 };
nickjillings@1289 2466
nickjillings@1289 2467 /**
nickjillings@1289 2468 * A low-level selection function that works with Sizzle's compiled
nickjillings@1289 2469 * selector functions
nickjillings@1289 2470 * @param {String|Function} selector A selector or a pre-compiled
nickjillings@1289 2471 * selector function built with Sizzle.compile
nickjillings@1289 2472 * @param {Element} context
nickjillings@1289 2473 * @param {Array} [results]
nickjillings@1289 2474 * @param {Array} [seed] A set of elements to match against
nickjillings@1289 2475 */
nickjillings@1289 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nickjillings@1289 2477 var i, tokens, token, type, find,
nickjillings@1289 2478 compiled = typeof selector === "function" && selector,
nickjillings@1289 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nickjillings@1289 2480
nickjillings@1289 2481 results = results || [];
nickjillings@1289 2482
nickjillings@1289 2483 // Try to minimize operations if there is no seed and only one group
nickjillings@1289 2484 if ( match.length === 1 ) {
nickjillings@1289 2485
nickjillings@1289 2486 // Take a shortcut and set the context if the root selector is an ID
nickjillings@1289 2487 tokens = match[0] = match[0].slice( 0 );
nickjillings@1289 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nickjillings@1289 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nickjillings@1289 2490 Expr.relative[ tokens[1].type ] ) {
nickjillings@1289 2491
nickjillings@1289 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nickjillings@1289 2493 if ( !context ) {
nickjillings@1289 2494 return results;
nickjillings@1289 2495
nickjillings@1289 2496 // Precompiled matchers will still verify ancestry, so step up a level
nickjillings@1289 2497 } else if ( compiled ) {
nickjillings@1289 2498 context = context.parentNode;
nickjillings@1289 2499 }
nickjillings@1289 2500
nickjillings@1289 2501 selector = selector.slice( tokens.shift().value.length );
nickjillings@1289 2502 }
nickjillings@1289 2503
nickjillings@1289 2504 // Fetch a seed set for right-to-left matching
nickjillings@1289 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nickjillings@1289 2506 while ( i-- ) {
nickjillings@1289 2507 token = tokens[i];
nickjillings@1289 2508
nickjillings@1289 2509 // Abort if we hit a combinator
nickjillings@1289 2510 if ( Expr.relative[ (type = token.type) ] ) {
nickjillings@1289 2511 break;
nickjillings@1289 2512 }
nickjillings@1289 2513 if ( (find = Expr.find[ type ]) ) {
nickjillings@1289 2514 // Search, expanding context for leading sibling combinators
nickjillings@1289 2515 if ( (seed = find(
nickjillings@1289 2516 token.matches[0].replace( runescape, funescape ),
nickjillings@1289 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nickjillings@1289 2518 )) ) {
nickjillings@1289 2519
nickjillings@1289 2520 // If seed is empty or no tokens remain, we can return early
nickjillings@1289 2521 tokens.splice( i, 1 );
nickjillings@1289 2522 selector = seed.length && toSelector( tokens );
nickjillings@1289 2523 if ( !selector ) {
nickjillings@1289 2524 push.apply( results, seed );
nickjillings@1289 2525 return results;
nickjillings@1289 2526 }
nickjillings@1289 2527
nickjillings@1289 2528 break;
nickjillings@1289 2529 }
nickjillings@1289 2530 }
nickjillings@1289 2531 }
nickjillings@1289 2532 }
nickjillings@1289 2533
nickjillings@1289 2534 // Compile and execute a filtering function if one is not provided
nickjillings@1289 2535 // Provide `match` to avoid retokenization if we modified the selector above
nickjillings@1289 2536 ( compiled || compile( selector, match ) )(
nickjillings@1289 2537 seed,
nickjillings@1289 2538 context,
nickjillings@1289 2539 !documentIsHTML,
nickjillings@1289 2540 results,
nickjillings@1289 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nickjillings@1289 2542 );
nickjillings@1289 2543 return results;
nickjillings@1289 2544 };
nickjillings@1289 2545
nickjillings@1289 2546 // One-time assignments
nickjillings@1289 2547
nickjillings@1289 2548 // Sort stability
nickjillings@1289 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nickjillings@1289 2550
nickjillings@1289 2551 // Support: Chrome 14-35+
nickjillings@1289 2552 // Always assume duplicates if they aren't passed to the comparison function
nickjillings@1289 2553 support.detectDuplicates = !!hasDuplicate;
nickjillings@1289 2554
nickjillings@1289 2555 // Initialize against the default document
nickjillings@1289 2556 setDocument();
nickjillings@1289 2557
nickjillings@1289 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nickjillings@1289 2559 // Detached nodes confoundingly follow *each other*
nickjillings@1289 2560 support.sortDetached = assert(function( div1 ) {
nickjillings@1289 2561 // Should return 1, but returns 4 (following)
nickjillings@1289 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nickjillings@1289 2563 });
nickjillings@1289 2564
nickjillings@1289 2565 // Support: IE<8
nickjillings@1289 2566 // Prevent attribute/property "interpolation"
nickjillings@1289 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nickjillings@1289 2568 if ( !assert(function( div ) {
nickjillings@1289 2569 div.innerHTML = "<a href='#'></a>";
nickjillings@1289 2570 return div.firstChild.getAttribute("href") === "#" ;
nickjillings@1289 2571 }) ) {
nickjillings@1289 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nickjillings@1289 2573 if ( !isXML ) {
nickjillings@1289 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nickjillings@1289 2575 }
nickjillings@1289 2576 });
nickjillings@1289 2577 }
nickjillings@1289 2578
nickjillings@1289 2579 // Support: IE<9
nickjillings@1289 2580 // Use defaultValue in place of getAttribute("value")
nickjillings@1289 2581 if ( !support.attributes || !assert(function( div ) {
nickjillings@1289 2582 div.innerHTML = "<input/>";
nickjillings@1289 2583 div.firstChild.setAttribute( "value", "" );
nickjillings@1289 2584 return div.firstChild.getAttribute( "value" ) === "";
nickjillings@1289 2585 }) ) {
nickjillings@1289 2586 addHandle( "value", function( elem, name, isXML ) {
nickjillings@1289 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nickjillings@1289 2588 return elem.defaultValue;
nickjillings@1289 2589 }
nickjillings@1289 2590 });
nickjillings@1289 2591 }
nickjillings@1289 2592
nickjillings@1289 2593 // Support: IE<9
nickjillings@1289 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nickjillings@1289 2595 if ( !assert(function( div ) {
nickjillings@1289 2596 return div.getAttribute("disabled") == null;
nickjillings@1289 2597 }) ) {
nickjillings@1289 2598 addHandle( booleans, function( elem, name, isXML ) {
nickjillings@1289 2599 var val;
nickjillings@1289 2600 if ( !isXML ) {
nickjillings@1289 2601 return elem[ name ] === true ? name.toLowerCase() :
nickjillings@1289 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nickjillings@1289 2603 val.value :
nickjillings@1289 2604 null;
nickjillings@1289 2605 }
nickjillings@1289 2606 });
nickjillings@1289 2607 }
nickjillings@1289 2608
nickjillings@1289 2609 return Sizzle;
nickjillings@1289 2610
nickjillings@1289 2611 })( window );
nickjillings@1289 2612
nickjillings@1289 2613
nickjillings@1289 2614
nickjillings@1289 2615 jQuery.find = Sizzle;
nickjillings@1289 2616 jQuery.expr = Sizzle.selectors;
nickjillings@1289 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nickjillings@1289 2618 jQuery.unique = Sizzle.uniqueSort;
nickjillings@1289 2619 jQuery.text = Sizzle.getText;
nickjillings@1289 2620 jQuery.isXMLDoc = Sizzle.isXML;
nickjillings@1289 2621 jQuery.contains = Sizzle.contains;
nickjillings@1289 2622
nickjillings@1289 2623
nickjillings@1289 2624
nickjillings@1289 2625 var rneedsContext = jQuery.expr.match.needsContext;
nickjillings@1289 2626
nickjillings@1289 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nickjillings@1289 2628
nickjillings@1289 2629
nickjillings@1289 2630
nickjillings@1289 2631 var risSimple = /^.[^:#\[\.,]*$/;
nickjillings@1289 2632
nickjillings@1289 2633 // Implement the identical functionality for filter and not
nickjillings@1289 2634 function winnow( elements, qualifier, not ) {
nickjillings@1289 2635 if ( jQuery.isFunction( qualifier ) ) {
nickjillings@1289 2636 return jQuery.grep( elements, function( elem, i ) {
nickjillings@1289 2637 /* jshint -W018 */
nickjillings@1289 2638 return !!qualifier.call( elem, i, elem ) !== not;
nickjillings@1289 2639 });
nickjillings@1289 2640
nickjillings@1289 2641 }
nickjillings@1289 2642
nickjillings@1289 2643 if ( qualifier.nodeType ) {
nickjillings@1289 2644 return jQuery.grep( elements, function( elem ) {
nickjillings@1289 2645 return ( elem === qualifier ) !== not;
nickjillings@1289 2646 });
nickjillings@1289 2647
nickjillings@1289 2648 }
nickjillings@1289 2649
nickjillings@1289 2650 if ( typeof qualifier === "string" ) {
nickjillings@1289 2651 if ( risSimple.test( qualifier ) ) {
nickjillings@1289 2652 return jQuery.filter( qualifier, elements, not );
nickjillings@1289 2653 }
nickjillings@1289 2654
nickjillings@1289 2655 qualifier = jQuery.filter( qualifier, elements );
nickjillings@1289 2656 }
nickjillings@1289 2657
nickjillings@1289 2658 return jQuery.grep( elements, function( elem ) {
nickjillings@1289 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nickjillings@1289 2660 });
nickjillings@1289 2661 }
nickjillings@1289 2662
nickjillings@1289 2663 jQuery.filter = function( expr, elems, not ) {
nickjillings@1289 2664 var elem = elems[ 0 ];
nickjillings@1289 2665
nickjillings@1289 2666 if ( not ) {
nickjillings@1289 2667 expr = ":not(" + expr + ")";
nickjillings@1289 2668 }
nickjillings@1289 2669
nickjillings@1289 2670 return elems.length === 1 && elem.nodeType === 1 ?
nickjillings@1289 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nickjillings@1289 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nickjillings@1289 2673 return elem.nodeType === 1;
nickjillings@1289 2674 }));
nickjillings@1289 2675 };
nickjillings@1289 2676
nickjillings@1289 2677 jQuery.fn.extend({
nickjillings@1289 2678 find: function( selector ) {
nickjillings@1289 2679 var i,
nickjillings@1289 2680 len = this.length,
nickjillings@1289 2681 ret = [],
nickjillings@1289 2682 self = this;
nickjillings@1289 2683
nickjillings@1289 2684 if ( typeof selector !== "string" ) {
nickjillings@1289 2685 return this.pushStack( jQuery( selector ).filter(function() {
nickjillings@1289 2686 for ( i = 0; i < len; i++ ) {
nickjillings@1289 2687 if ( jQuery.contains( self[ i ], this ) ) {
nickjillings@1289 2688 return true;
nickjillings@1289 2689 }
nickjillings@1289 2690 }
nickjillings@1289 2691 }) );
nickjillings@1289 2692 }
nickjillings@1289 2693
nickjillings@1289 2694 for ( i = 0; i < len; i++ ) {
nickjillings@1289 2695 jQuery.find( selector, self[ i ], ret );
nickjillings@1289 2696 }
nickjillings@1289 2697
nickjillings@1289 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nickjillings@1289 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nickjillings@1289 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nickjillings@1289 2701 return ret;
nickjillings@1289 2702 },
nickjillings@1289 2703 filter: function( selector ) {
nickjillings@1289 2704 return this.pushStack( winnow(this, selector || [], false) );
nickjillings@1289 2705 },
nickjillings@1289 2706 not: function( selector ) {
nickjillings@1289 2707 return this.pushStack( winnow(this, selector || [], true) );
nickjillings@1289 2708 },
nickjillings@1289 2709 is: function( selector ) {
nickjillings@1289 2710 return !!winnow(
nickjillings@1289 2711 this,
nickjillings@1289 2712
nickjillings@1289 2713 // If this is a positional/relative selector, check membership in the returned set
nickjillings@1289 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nickjillings@1289 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nickjillings@1289 2716 jQuery( selector ) :
nickjillings@1289 2717 selector || [],
nickjillings@1289 2718 false
nickjillings@1289 2719 ).length;
nickjillings@1289 2720 }
nickjillings@1289 2721 });
nickjillings@1289 2722
nickjillings@1289 2723
nickjillings@1289 2724 // Initialize a jQuery object
nickjillings@1289 2725
nickjillings@1289 2726
nickjillings@1289 2727 // A central reference to the root jQuery(document)
nickjillings@1289 2728 var rootjQuery,
nickjillings@1289 2729
nickjillings@1289 2730 // A simple way to check for HTML strings
nickjillings@1289 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nickjillings@1289 2732 // Strict HTML recognition (#11290: must start with <)
nickjillings@1289 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nickjillings@1289 2734
nickjillings@1289 2735 init = jQuery.fn.init = function( selector, context ) {
nickjillings@1289 2736 var match, elem;
nickjillings@1289 2737
nickjillings@1289 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nickjillings@1289 2739 if ( !selector ) {
nickjillings@1289 2740 return this;
nickjillings@1289 2741 }
nickjillings@1289 2742
nickjillings@1289 2743 // Handle HTML strings
nickjillings@1289 2744 if ( typeof selector === "string" ) {
nickjillings@1289 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nickjillings@1289 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nickjillings@1289 2747 match = [ null, selector, null ];
nickjillings@1289 2748
nickjillings@1289 2749 } else {
nickjillings@1289 2750 match = rquickExpr.exec( selector );
nickjillings@1289 2751 }
nickjillings@1289 2752
nickjillings@1289 2753 // Match html or make sure no context is specified for #id
nickjillings@1289 2754 if ( match && (match[1] || !context) ) {
nickjillings@1289 2755
nickjillings@1289 2756 // HANDLE: $(html) -> $(array)
nickjillings@1289 2757 if ( match[1] ) {
nickjillings@1289 2758 context = context instanceof jQuery ? context[0] : context;
nickjillings@1289 2759
nickjillings@1289 2760 // Option to run scripts is true for back-compat
nickjillings@1289 2761 // Intentionally let the error be thrown if parseHTML is not present
nickjillings@1289 2762 jQuery.merge( this, jQuery.parseHTML(
nickjillings@1289 2763 match[1],
nickjillings@1289 2764 context && context.nodeType ? context.ownerDocument || context : document,
nickjillings@1289 2765 true
nickjillings@1289 2766 ) );
nickjillings@1289 2767
nickjillings@1289 2768 // HANDLE: $(html, props)
nickjillings@1289 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nickjillings@1289 2770 for ( match in context ) {
nickjillings@1289 2771 // Properties of context are called as methods if possible
nickjillings@1289 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nickjillings@1289 2773 this[ match ]( context[ match ] );
nickjillings@1289 2774
nickjillings@1289 2775 // ...and otherwise set as attributes
nickjillings@1289 2776 } else {
nickjillings@1289 2777 this.attr( match, context[ match ] );
nickjillings@1289 2778 }
nickjillings@1289 2779 }
nickjillings@1289 2780 }
nickjillings@1289 2781
nickjillings@1289 2782 return this;
nickjillings@1289 2783
nickjillings@1289 2784 // HANDLE: $(#id)
nickjillings@1289 2785 } else {
nickjillings@1289 2786 elem = document.getElementById( match[2] );
nickjillings@1289 2787
nickjillings@1289 2788 // Support: Blackberry 4.6
nickjillings@1289 2789 // gEBID returns nodes no longer in the document (#6963)
nickjillings@1289 2790 if ( elem && elem.parentNode ) {
nickjillings@1289 2791 // Inject the element directly into the jQuery object
nickjillings@1289 2792 this.length = 1;
nickjillings@1289 2793 this[0] = elem;
nickjillings@1289 2794 }
nickjillings@1289 2795
nickjillings@1289 2796 this.context = document;
nickjillings@1289 2797 this.selector = selector;
nickjillings@1289 2798 return this;
nickjillings@1289 2799 }
nickjillings@1289 2800
nickjillings@1289 2801 // HANDLE: $(expr, $(...))
nickjillings@1289 2802 } else if ( !context || context.jquery ) {
nickjillings@1289 2803 return ( context || rootjQuery ).find( selector );
nickjillings@1289 2804
nickjillings@1289 2805 // HANDLE: $(expr, context)
nickjillings@1289 2806 // (which is just equivalent to: $(context).find(expr)
nickjillings@1289 2807 } else {
nickjillings@1289 2808 return this.constructor( context ).find( selector );
nickjillings@1289 2809 }
nickjillings@1289 2810
nickjillings@1289 2811 // HANDLE: $(DOMElement)
nickjillings@1289 2812 } else if ( selector.nodeType ) {
nickjillings@1289 2813 this.context = this[0] = selector;
nickjillings@1289 2814 this.length = 1;
nickjillings@1289 2815 return this;
nickjillings@1289 2816
nickjillings@1289 2817 // HANDLE: $(function)
nickjillings@1289 2818 // Shortcut for document ready
nickjillings@1289 2819 } else if ( jQuery.isFunction( selector ) ) {
nickjillings@1289 2820 return typeof rootjQuery.ready !== "undefined" ?
nickjillings@1289 2821 rootjQuery.ready( selector ) :
nickjillings@1289 2822 // Execute immediately if ready is not present
nickjillings@1289 2823 selector( jQuery );
nickjillings@1289 2824 }
nickjillings@1289 2825
nickjillings@1289 2826 if ( selector.selector !== undefined ) {
nickjillings@1289 2827 this.selector = selector.selector;
nickjillings@1289 2828 this.context = selector.context;
nickjillings@1289 2829 }
nickjillings@1289 2830
nickjillings@1289 2831 return jQuery.makeArray( selector, this );
nickjillings@1289 2832 };
nickjillings@1289 2833
nickjillings@1289 2834 // Give the init function the jQuery prototype for later instantiation
nickjillings@1289 2835 init.prototype = jQuery.fn;
nickjillings@1289 2836
nickjillings@1289 2837 // Initialize central reference
nickjillings@1289 2838 rootjQuery = jQuery( document );
nickjillings@1289 2839
nickjillings@1289 2840
nickjillings@1289 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nickjillings@1289 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nickjillings@1289 2843 guaranteedUnique = {
nickjillings@1289 2844 children: true,
nickjillings@1289 2845 contents: true,
nickjillings@1289 2846 next: true,
nickjillings@1289 2847 prev: true
nickjillings@1289 2848 };
nickjillings@1289 2849
nickjillings@1289 2850 jQuery.extend({
nickjillings@1289 2851 dir: function( elem, dir, until ) {
nickjillings@1289 2852 var matched = [],
nickjillings@1289 2853 truncate = until !== undefined;
nickjillings@1289 2854
nickjillings@1289 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nickjillings@1289 2856 if ( elem.nodeType === 1 ) {
nickjillings@1289 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nickjillings@1289 2858 break;
nickjillings@1289 2859 }
nickjillings@1289 2860 matched.push( elem );
nickjillings@1289 2861 }
nickjillings@1289 2862 }
nickjillings@1289 2863 return matched;
nickjillings@1289 2864 },
nickjillings@1289 2865
nickjillings@1289 2866 sibling: function( n, elem ) {
nickjillings@1289 2867 var matched = [];
nickjillings@1289 2868
nickjillings@1289 2869 for ( ; n; n = n.nextSibling ) {
nickjillings@1289 2870 if ( n.nodeType === 1 && n !== elem ) {
nickjillings@1289 2871 matched.push( n );
nickjillings@1289 2872 }
nickjillings@1289 2873 }
nickjillings@1289 2874
nickjillings@1289 2875 return matched;
nickjillings@1289 2876 }
nickjillings@1289 2877 });
nickjillings@1289 2878
nickjillings@1289 2879 jQuery.fn.extend({
nickjillings@1289 2880 has: function( target ) {
nickjillings@1289 2881 var targets = jQuery( target, this ),
nickjillings@1289 2882 l = targets.length;
nickjillings@1289 2883
nickjillings@1289 2884 return this.filter(function() {
nickjillings@1289 2885 var i = 0;
nickjillings@1289 2886 for ( ; i < l; i++ ) {
nickjillings@1289 2887 if ( jQuery.contains( this, targets[i] ) ) {
nickjillings@1289 2888 return true;
nickjillings@1289 2889 }
nickjillings@1289 2890 }
nickjillings@1289 2891 });
nickjillings@1289 2892 },
nickjillings@1289 2893
nickjillings@1289 2894 closest: function( selectors, context ) {
nickjillings@1289 2895 var cur,
nickjillings@1289 2896 i = 0,
nickjillings@1289 2897 l = this.length,
nickjillings@1289 2898 matched = [],
nickjillings@1289 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nickjillings@1289 2900 jQuery( selectors, context || this.context ) :
nickjillings@1289 2901 0;
nickjillings@1289 2902
nickjillings@1289 2903 for ( ; i < l; i++ ) {
nickjillings@1289 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nickjillings@1289 2905 // Always skip document fragments
nickjillings@1289 2906 if ( cur.nodeType < 11 && (pos ?
nickjillings@1289 2907 pos.index(cur) > -1 :
nickjillings@1289 2908
nickjillings@1289 2909 // Don't pass non-elements to Sizzle
nickjillings@1289 2910 cur.nodeType === 1 &&
nickjillings@1289 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nickjillings@1289 2912
nickjillings@1289 2913 matched.push( cur );
nickjillings@1289 2914 break;
nickjillings@1289 2915 }
nickjillings@1289 2916 }
nickjillings@1289 2917 }
nickjillings@1289 2918
nickjillings@1289 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nickjillings@1289 2920 },
nickjillings@1289 2921
nickjillings@1289 2922 // Determine the position of an element within the set
nickjillings@1289 2923 index: function( elem ) {
nickjillings@1289 2924
nickjillings@1289 2925 // No argument, return index in parent
nickjillings@1289 2926 if ( !elem ) {
nickjillings@1289 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nickjillings@1289 2928 }
nickjillings@1289 2929
nickjillings@1289 2930 // Index in selector
nickjillings@1289 2931 if ( typeof elem === "string" ) {
nickjillings@1289 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nickjillings@1289 2933 }
nickjillings@1289 2934
nickjillings@1289 2935 // Locate the position of the desired element
nickjillings@1289 2936 return indexOf.call( this,
nickjillings@1289 2937
nickjillings@1289 2938 // If it receives a jQuery object, the first element is used
nickjillings@1289 2939 elem.jquery ? elem[ 0 ] : elem
nickjillings@1289 2940 );
nickjillings@1289 2941 },
nickjillings@1289 2942
nickjillings@1289 2943 add: function( selector, context ) {
nickjillings@1289 2944 return this.pushStack(
nickjillings@1289 2945 jQuery.unique(
nickjillings@1289 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nickjillings@1289 2947 )
nickjillings@1289 2948 );
nickjillings@1289 2949 },
nickjillings@1289 2950
nickjillings@1289 2951 addBack: function( selector ) {
nickjillings@1289 2952 return this.add( selector == null ?
nickjillings@1289 2953 this.prevObject : this.prevObject.filter(selector)
nickjillings@1289 2954 );
nickjillings@1289 2955 }
nickjillings@1289 2956 });
nickjillings@1289 2957
nickjillings@1289 2958 function sibling( cur, dir ) {
nickjillings@1289 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nickjillings@1289 2960 return cur;
nickjillings@1289 2961 }
nickjillings@1289 2962
nickjillings@1289 2963 jQuery.each({
nickjillings@1289 2964 parent: function( elem ) {
nickjillings@1289 2965 var parent = elem.parentNode;
nickjillings@1289 2966 return parent && parent.nodeType !== 11 ? parent : null;
nickjillings@1289 2967 },
nickjillings@1289 2968 parents: function( elem ) {
nickjillings@1289 2969 return jQuery.dir( elem, "parentNode" );
nickjillings@1289 2970 },
nickjillings@1289 2971 parentsUntil: function( elem, i, until ) {
nickjillings@1289 2972 return jQuery.dir( elem, "parentNode", until );
nickjillings@1289 2973 },
nickjillings@1289 2974 next: function( elem ) {
nickjillings@1289 2975 return sibling( elem, "nextSibling" );
nickjillings@1289 2976 },
nickjillings@1289 2977 prev: function( elem ) {
nickjillings@1289 2978 return sibling( elem, "previousSibling" );
nickjillings@1289 2979 },
nickjillings@1289 2980 nextAll: function( elem ) {
nickjillings@1289 2981 return jQuery.dir( elem, "nextSibling" );
nickjillings@1289 2982 },
nickjillings@1289 2983 prevAll: function( elem ) {
nickjillings@1289 2984 return jQuery.dir( elem, "previousSibling" );
nickjillings@1289 2985 },
nickjillings@1289 2986 nextUntil: function( elem, i, until ) {
nickjillings@1289 2987 return jQuery.dir( elem, "nextSibling", until );
nickjillings@1289 2988 },
nickjillings@1289 2989 prevUntil: function( elem, i, until ) {
nickjillings@1289 2990 return jQuery.dir( elem, "previousSibling", until );
nickjillings@1289 2991 },
nickjillings@1289 2992 siblings: function( elem ) {
nickjillings@1289 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nickjillings@1289 2994 },
nickjillings@1289 2995 children: function( elem ) {
nickjillings@1289 2996 return jQuery.sibling( elem.firstChild );
nickjillings@1289 2997 },
nickjillings@1289 2998 contents: function( elem ) {
nickjillings@1289 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nickjillings@1289 3000 }
nickjillings@1289 3001 }, function( name, fn ) {
nickjillings@1289 3002 jQuery.fn[ name ] = function( until, selector ) {
nickjillings@1289 3003 var matched = jQuery.map( this, fn, until );
nickjillings@1289 3004
nickjillings@1289 3005 if ( name.slice( -5 ) !== "Until" ) {
nickjillings@1289 3006 selector = until;
nickjillings@1289 3007 }
nickjillings@1289 3008
nickjillings@1289 3009 if ( selector && typeof selector === "string" ) {
nickjillings@1289 3010 matched = jQuery.filter( selector, matched );
nickjillings@1289 3011 }
nickjillings@1289 3012
nickjillings@1289 3013 if ( this.length > 1 ) {
nickjillings@1289 3014 // Remove duplicates
nickjillings@1289 3015 if ( !guaranteedUnique[ name ] ) {
nickjillings@1289 3016 jQuery.unique( matched );
nickjillings@1289 3017 }
nickjillings@1289 3018
nickjillings@1289 3019 // Reverse order for parents* and prev-derivatives
nickjillings@1289 3020 if ( rparentsprev.test( name ) ) {
nickjillings@1289 3021 matched.reverse();
nickjillings@1289 3022 }
nickjillings@1289 3023 }
nickjillings@1289 3024
nickjillings@1289 3025 return this.pushStack( matched );
nickjillings@1289 3026 };
nickjillings@1289 3027 });
nickjillings@1289 3028 var rnotwhite = (/\S+/g);
nickjillings@1289 3029
nickjillings@1289 3030
nickjillings@1289 3031
nickjillings@1289 3032 // String to Object options format cache
nickjillings@1289 3033 var optionsCache = {};
nickjillings@1289 3034
nickjillings@1289 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nickjillings@1289 3036 function createOptions( options ) {
nickjillings@1289 3037 var object = optionsCache[ options ] = {};
nickjillings@1289 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nickjillings@1289 3039 object[ flag ] = true;
nickjillings@1289 3040 });
nickjillings@1289 3041 return object;
nickjillings@1289 3042 }
nickjillings@1289 3043
nickjillings@1289 3044 /*
nickjillings@1289 3045 * Create a callback list using the following parameters:
nickjillings@1289 3046 *
nickjillings@1289 3047 * options: an optional list of space-separated options that will change how
nickjillings@1289 3048 * the callback list behaves or a more traditional option object
nickjillings@1289 3049 *
nickjillings@1289 3050 * By default a callback list will act like an event callback list and can be
nickjillings@1289 3051 * "fired" multiple times.
nickjillings@1289 3052 *
nickjillings@1289 3053 * Possible options:
nickjillings@1289 3054 *
nickjillings@1289 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nickjillings@1289 3056 *
nickjillings@1289 3057 * memory: will keep track of previous values and will call any callback added
nickjillings@1289 3058 * after the list has been fired right away with the latest "memorized"
nickjillings@1289 3059 * values (like a Deferred)
nickjillings@1289 3060 *
nickjillings@1289 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nickjillings@1289 3062 *
nickjillings@1289 3063 * stopOnFalse: interrupt callings when a callback returns false
nickjillings@1289 3064 *
nickjillings@1289 3065 */
nickjillings@1289 3066 jQuery.Callbacks = function( options ) {
nickjillings@1289 3067
nickjillings@1289 3068 // Convert options from String-formatted to Object-formatted if needed
nickjillings@1289 3069 // (we check in cache first)
nickjillings@1289 3070 options = typeof options === "string" ?
nickjillings@1289 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nickjillings@1289 3072 jQuery.extend( {}, options );
nickjillings@1289 3073
nickjillings@1289 3074 var // Last fire value (for non-forgettable lists)
nickjillings@1289 3075 memory,
nickjillings@1289 3076 // Flag to know if list was already fired
nickjillings@1289 3077 fired,
nickjillings@1289 3078 // Flag to know if list is currently firing
nickjillings@1289 3079 firing,
nickjillings@1289 3080 // First callback to fire (used internally by add and fireWith)
nickjillings@1289 3081 firingStart,
nickjillings@1289 3082 // End of the loop when firing
nickjillings@1289 3083 firingLength,
nickjillings@1289 3084 // Index of currently firing callback (modified by remove if needed)
nickjillings@1289 3085 firingIndex,
nickjillings@1289 3086 // Actual callback list
nickjillings@1289 3087 list = [],
nickjillings@1289 3088 // Stack of fire calls for repeatable lists
nickjillings@1289 3089 stack = !options.once && [],
nickjillings@1289 3090 // Fire callbacks
nickjillings@1289 3091 fire = function( data ) {
nickjillings@1289 3092 memory = options.memory && data;
nickjillings@1289 3093 fired = true;
nickjillings@1289 3094 firingIndex = firingStart || 0;
nickjillings@1289 3095 firingStart = 0;
nickjillings@1289 3096 firingLength = list.length;
nickjillings@1289 3097 firing = true;
nickjillings@1289 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nickjillings@1289 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nickjillings@1289 3100 memory = false; // To prevent further calls using add
nickjillings@1289 3101 break;
nickjillings@1289 3102 }
nickjillings@1289 3103 }
nickjillings@1289 3104 firing = false;
nickjillings@1289 3105 if ( list ) {
nickjillings@1289 3106 if ( stack ) {
nickjillings@1289 3107 if ( stack.length ) {
nickjillings@1289 3108 fire( stack.shift() );
nickjillings@1289 3109 }
nickjillings@1289 3110 } else if ( memory ) {
nickjillings@1289 3111 list = [];
nickjillings@1289 3112 } else {
nickjillings@1289 3113 self.disable();
nickjillings@1289 3114 }
nickjillings@1289 3115 }
nickjillings@1289 3116 },
nickjillings@1289 3117 // Actual Callbacks object
nickjillings@1289 3118 self = {
nickjillings@1289 3119 // Add a callback or a collection of callbacks to the list
nickjillings@1289 3120 add: function() {
nickjillings@1289 3121 if ( list ) {
nickjillings@1289 3122 // First, we save the current length
nickjillings@1289 3123 var start = list.length;
nickjillings@1289 3124 (function add( args ) {
nickjillings@1289 3125 jQuery.each( args, function( _, arg ) {
nickjillings@1289 3126 var type = jQuery.type( arg );
nickjillings@1289 3127 if ( type === "function" ) {
nickjillings@1289 3128 if ( !options.unique || !self.has( arg ) ) {
nickjillings@1289 3129 list.push( arg );
nickjillings@1289 3130 }
nickjillings@1289 3131 } else if ( arg && arg.length && type !== "string" ) {
nickjillings@1289 3132 // Inspect recursively
nickjillings@1289 3133 add( arg );
nickjillings@1289 3134 }
nickjillings@1289 3135 });
nickjillings@1289 3136 })( arguments );
nickjillings@1289 3137 // Do we need to add the callbacks to the
nickjillings@1289 3138 // current firing batch?
nickjillings@1289 3139 if ( firing ) {
nickjillings@1289 3140 firingLength = list.length;
nickjillings@1289 3141 // With memory, if we're not firing then
nickjillings@1289 3142 // we should call right away
nickjillings@1289 3143 } else if ( memory ) {
nickjillings@1289 3144 firingStart = start;
nickjillings@1289 3145 fire( memory );
nickjillings@1289 3146 }
nickjillings@1289 3147 }
nickjillings@1289 3148 return this;
nickjillings@1289 3149 },
nickjillings@1289 3150 // Remove a callback from the list
nickjillings@1289 3151 remove: function() {
nickjillings@1289 3152 if ( list ) {
nickjillings@1289 3153 jQuery.each( arguments, function( _, arg ) {
nickjillings@1289 3154 var index;
nickjillings@1289 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nickjillings@1289 3156 list.splice( index, 1 );
nickjillings@1289 3157 // Handle firing indexes
nickjillings@1289 3158 if ( firing ) {
nickjillings@1289 3159 if ( index <= firingLength ) {
nickjillings@1289 3160 firingLength--;
nickjillings@1289 3161 }
nickjillings@1289 3162 if ( index <= firingIndex ) {
nickjillings@1289 3163 firingIndex--;
nickjillings@1289 3164 }
nickjillings@1289 3165 }
nickjillings@1289 3166 }
nickjillings@1289 3167 });
nickjillings@1289 3168 }
nickjillings@1289 3169 return this;
nickjillings@1289 3170 },
nickjillings@1289 3171 // Check if a given callback is in the list.
nickjillings@1289 3172 // If no argument is given, return whether or not list has callbacks attached.
nickjillings@1289 3173 has: function( fn ) {
nickjillings@1289 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nickjillings@1289 3175 },
nickjillings@1289 3176 // Remove all callbacks from the list
nickjillings@1289 3177 empty: function() {
nickjillings@1289 3178 list = [];
nickjillings@1289 3179 firingLength = 0;
nickjillings@1289 3180 return this;
nickjillings@1289 3181 },
nickjillings@1289 3182 // Have the list do nothing anymore
nickjillings@1289 3183 disable: function() {
nickjillings@1289 3184 list = stack = memory = undefined;
nickjillings@1289 3185 return this;
nickjillings@1289 3186 },
nickjillings@1289 3187 // Is it disabled?
nickjillings@1289 3188 disabled: function() {
nickjillings@1289 3189 return !list;
nickjillings@1289 3190 },
nickjillings@1289 3191 // Lock the list in its current state
nickjillings@1289 3192 lock: function() {
nickjillings@1289 3193 stack = undefined;
nickjillings@1289 3194 if ( !memory ) {
nickjillings@1289 3195 self.disable();
nickjillings@1289 3196 }
nickjillings@1289 3197 return this;
nickjillings@1289 3198 },
nickjillings@1289 3199 // Is it locked?
nickjillings@1289 3200 locked: function() {
nickjillings@1289 3201 return !stack;
nickjillings@1289 3202 },
nickjillings@1289 3203 // Call all callbacks with the given context and arguments
nickjillings@1289 3204 fireWith: function( context, args ) {
nickjillings@1289 3205 if ( list && ( !fired || stack ) ) {
nickjillings@1289 3206 args = args || [];
nickjillings@1289 3207 args = [ context, args.slice ? args.slice() : args ];
nickjillings@1289 3208 if ( firing ) {
nickjillings@1289 3209 stack.push( args );
nickjillings@1289 3210 } else {
nickjillings@1289 3211 fire( args );
nickjillings@1289 3212 }
nickjillings@1289 3213 }
nickjillings@1289 3214 return this;
nickjillings@1289 3215 },
nickjillings@1289 3216 // Call all the callbacks with the given arguments
nickjillings@1289 3217 fire: function() {
nickjillings@1289 3218 self.fireWith( this, arguments );
nickjillings@1289 3219 return this;
nickjillings@1289 3220 },
nickjillings@1289 3221 // To know if the callbacks have already been called at least once
nickjillings@1289 3222 fired: function() {
nickjillings@1289 3223 return !!fired;
nickjillings@1289 3224 }
nickjillings@1289 3225 };
nickjillings@1289 3226
nickjillings@1289 3227 return self;
nickjillings@1289 3228 };
nickjillings@1289 3229
nickjillings@1289 3230
nickjillings@1289 3231 jQuery.extend({
nickjillings@1289 3232
nickjillings@1289 3233 Deferred: function( func ) {
nickjillings@1289 3234 var tuples = [
nickjillings@1289 3235 // action, add listener, listener list, final state
nickjillings@1289 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nickjillings@1289 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nickjillings@1289 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nickjillings@1289 3239 ],
nickjillings@1289 3240 state = "pending",
nickjillings@1289 3241 promise = {
nickjillings@1289 3242 state: function() {
nickjillings@1289 3243 return state;
nickjillings@1289 3244 },
nickjillings@1289 3245 always: function() {
nickjillings@1289 3246 deferred.done( arguments ).fail( arguments );
nickjillings@1289 3247 return this;
nickjillings@1289 3248 },
nickjillings@1289 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nickjillings@1289 3250 var fns = arguments;
nickjillings@1289 3251 return jQuery.Deferred(function( newDefer ) {
nickjillings@1289 3252 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1289 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nickjillings@1289 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nickjillings@1289 3255 deferred[ tuple[1] ](function() {
nickjillings@1289 3256 var returned = fn && fn.apply( this, arguments );
nickjillings@1289 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nickjillings@1289 3258 returned.promise()
nickjillings@1289 3259 .done( newDefer.resolve )
nickjillings@1289 3260 .fail( newDefer.reject )
nickjillings@1289 3261 .progress( newDefer.notify );
nickjillings@1289 3262 } else {
nickjillings@1289 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nickjillings@1289 3264 }
nickjillings@1289 3265 });
nickjillings@1289 3266 });
nickjillings@1289 3267 fns = null;
nickjillings@1289 3268 }).promise();
nickjillings@1289 3269 },
nickjillings@1289 3270 // Get a promise for this deferred
nickjillings@1289 3271 // If obj is provided, the promise aspect is added to the object
nickjillings@1289 3272 promise: function( obj ) {
nickjillings@1289 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nickjillings@1289 3274 }
nickjillings@1289 3275 },
nickjillings@1289 3276 deferred = {};
nickjillings@1289 3277
nickjillings@1289 3278 // Keep pipe for back-compat
nickjillings@1289 3279 promise.pipe = promise.then;
nickjillings@1289 3280
nickjillings@1289 3281 // Add list-specific methods
nickjillings@1289 3282 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1289 3283 var list = tuple[ 2 ],
nickjillings@1289 3284 stateString = tuple[ 3 ];
nickjillings@1289 3285
nickjillings@1289 3286 // promise[ done | fail | progress ] = list.add
nickjillings@1289 3287 promise[ tuple[1] ] = list.add;
nickjillings@1289 3288
nickjillings@1289 3289 // Handle state
nickjillings@1289 3290 if ( stateString ) {
nickjillings@1289 3291 list.add(function() {
nickjillings@1289 3292 // state = [ resolved | rejected ]
nickjillings@1289 3293 state = stateString;
nickjillings@1289 3294
nickjillings@1289 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nickjillings@1289 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nickjillings@1289 3297 }
nickjillings@1289 3298
nickjillings@1289 3299 // deferred[ resolve | reject | notify ]
nickjillings@1289 3300 deferred[ tuple[0] ] = function() {
nickjillings@1289 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nickjillings@1289 3302 return this;
nickjillings@1289 3303 };
nickjillings@1289 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nickjillings@1289 3305 });
nickjillings@1289 3306
nickjillings@1289 3307 // Make the deferred a promise
nickjillings@1289 3308 promise.promise( deferred );
nickjillings@1289 3309
nickjillings@1289 3310 // Call given func if any
nickjillings@1289 3311 if ( func ) {
nickjillings@1289 3312 func.call( deferred, deferred );
nickjillings@1289 3313 }
nickjillings@1289 3314
nickjillings@1289 3315 // All done!
nickjillings@1289 3316 return deferred;
nickjillings@1289 3317 },
nickjillings@1289 3318
nickjillings@1289 3319 // Deferred helper
nickjillings@1289 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nickjillings@1289 3321 var i = 0,
nickjillings@1289 3322 resolveValues = slice.call( arguments ),
nickjillings@1289 3323 length = resolveValues.length,
nickjillings@1289 3324
nickjillings@1289 3325 // the count of uncompleted subordinates
nickjillings@1289 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nickjillings@1289 3327
nickjillings@1289 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nickjillings@1289 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nickjillings@1289 3330
nickjillings@1289 3331 // Update function for both resolve and progress values
nickjillings@1289 3332 updateFunc = function( i, contexts, values ) {
nickjillings@1289 3333 return function( value ) {
nickjillings@1289 3334 contexts[ i ] = this;
nickjillings@1289 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nickjillings@1289 3336 if ( values === progressValues ) {
nickjillings@1289 3337 deferred.notifyWith( contexts, values );
nickjillings@1289 3338 } else if ( !( --remaining ) ) {
nickjillings@1289 3339 deferred.resolveWith( contexts, values );
nickjillings@1289 3340 }
nickjillings@1289 3341 };
nickjillings@1289 3342 },
nickjillings@1289 3343
nickjillings@1289 3344 progressValues, progressContexts, resolveContexts;
nickjillings@1289 3345
nickjillings@1289 3346 // Add listeners to Deferred subordinates; treat others as resolved
nickjillings@1289 3347 if ( length > 1 ) {
nickjillings@1289 3348 progressValues = new Array( length );
nickjillings@1289 3349 progressContexts = new Array( length );
nickjillings@1289 3350 resolveContexts = new Array( length );
nickjillings@1289 3351 for ( ; i < length; i++ ) {
nickjillings@1289 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nickjillings@1289 3353 resolveValues[ i ].promise()
nickjillings@1289 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nickjillings@1289 3355 .fail( deferred.reject )
nickjillings@1289 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nickjillings@1289 3357 } else {
nickjillings@1289 3358 --remaining;
nickjillings@1289 3359 }
nickjillings@1289 3360 }
nickjillings@1289 3361 }
nickjillings@1289 3362
nickjillings@1289 3363 // If we're not waiting on anything, resolve the master
nickjillings@1289 3364 if ( !remaining ) {
nickjillings@1289 3365 deferred.resolveWith( resolveContexts, resolveValues );
nickjillings@1289 3366 }
nickjillings@1289 3367
nickjillings@1289 3368 return deferred.promise();
nickjillings@1289 3369 }
nickjillings@1289 3370 });
nickjillings@1289 3371
nickjillings@1289 3372
nickjillings@1289 3373 // The deferred used on DOM ready
nickjillings@1289 3374 var readyList;
nickjillings@1289 3375
nickjillings@1289 3376 jQuery.fn.ready = function( fn ) {
nickjillings@1289 3377 // Add the callback
nickjillings@1289 3378 jQuery.ready.promise().done( fn );
nickjillings@1289 3379
nickjillings@1289 3380 return this;
nickjillings@1289 3381 };
nickjillings@1289 3382
nickjillings@1289 3383 jQuery.extend({
nickjillings@1289 3384 // Is the DOM ready to be used? Set to true once it occurs.
nickjillings@1289 3385 isReady: false,
nickjillings@1289 3386
nickjillings@1289 3387 // A counter to track how many items to wait for before
nickjillings@1289 3388 // the ready event fires. See #6781
nickjillings@1289 3389 readyWait: 1,
nickjillings@1289 3390
nickjillings@1289 3391 // Hold (or release) the ready event
nickjillings@1289 3392 holdReady: function( hold ) {
nickjillings@1289 3393 if ( hold ) {
nickjillings@1289 3394 jQuery.readyWait++;
nickjillings@1289 3395 } else {
nickjillings@1289 3396 jQuery.ready( true );
nickjillings@1289 3397 }
nickjillings@1289 3398 },
nickjillings@1289 3399
nickjillings@1289 3400 // Handle when the DOM is ready
nickjillings@1289 3401 ready: function( wait ) {
nickjillings@1289 3402
nickjillings@1289 3403 // Abort if there are pending holds or we're already ready
nickjillings@1289 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nickjillings@1289 3405 return;
nickjillings@1289 3406 }
nickjillings@1289 3407
nickjillings@1289 3408 // Remember that the DOM is ready
nickjillings@1289 3409 jQuery.isReady = true;
nickjillings@1289 3410
nickjillings@1289 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nickjillings@1289 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nickjillings@1289 3413 return;
nickjillings@1289 3414 }
nickjillings@1289 3415
nickjillings@1289 3416 // If there are functions bound, to execute
nickjillings@1289 3417 readyList.resolveWith( document, [ jQuery ] );
nickjillings@1289 3418
nickjillings@1289 3419 // Trigger any bound ready events
nickjillings@1289 3420 if ( jQuery.fn.triggerHandler ) {
nickjillings@1289 3421 jQuery( document ).triggerHandler( "ready" );
nickjillings@1289 3422 jQuery( document ).off( "ready" );
nickjillings@1289 3423 }
nickjillings@1289 3424 }
nickjillings@1289 3425 });
nickjillings@1289 3426
nickjillings@1289 3427 /**
nickjillings@1289 3428 * The ready event handler and self cleanup method
nickjillings@1289 3429 */
nickjillings@1289 3430 function completed() {
nickjillings@1289 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nickjillings@1289 3432 window.removeEventListener( "load", completed, false );
nickjillings@1289 3433 jQuery.ready();
nickjillings@1289 3434 }
nickjillings@1289 3435
nickjillings@1289 3436 jQuery.ready.promise = function( obj ) {
nickjillings@1289 3437 if ( !readyList ) {
nickjillings@1289 3438
nickjillings@1289 3439 readyList = jQuery.Deferred();
nickjillings@1289 3440
nickjillings@1289 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nickjillings@1289 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nickjillings@1289 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nickjillings@1289 3444 if ( document.readyState === "complete" ) {
nickjillings@1289 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nickjillings@1289 3446 setTimeout( jQuery.ready );
nickjillings@1289 3447
nickjillings@1289 3448 } else {
nickjillings@1289 3449
nickjillings@1289 3450 // Use the handy event callback
nickjillings@1289 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nickjillings@1289 3452
nickjillings@1289 3453 // A fallback to window.onload, that will always work
nickjillings@1289 3454 window.addEventListener( "load", completed, false );
nickjillings@1289 3455 }
nickjillings@1289 3456 }
nickjillings@1289 3457 return readyList.promise( obj );
nickjillings@1289 3458 };
nickjillings@1289 3459
nickjillings@1289 3460 // Kick off the DOM ready check even if the user does not
nickjillings@1289 3461 jQuery.ready.promise();
nickjillings@1289 3462
nickjillings@1289 3463
nickjillings@1289 3464
nickjillings@1289 3465
nickjillings@1289 3466 // Multifunctional method to get and set values of a collection
nickjillings@1289 3467 // The value/s can optionally be executed if it's a function
nickjillings@1289 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nickjillings@1289 3469 var i = 0,
nickjillings@1289 3470 len = elems.length,
nickjillings@1289 3471 bulk = key == null;
nickjillings@1289 3472
nickjillings@1289 3473 // Sets many values
nickjillings@1289 3474 if ( jQuery.type( key ) === "object" ) {
nickjillings@1289 3475 chainable = true;
nickjillings@1289 3476 for ( i in key ) {
nickjillings@1289 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nickjillings@1289 3478 }
nickjillings@1289 3479
nickjillings@1289 3480 // Sets one value
nickjillings@1289 3481 } else if ( value !== undefined ) {
nickjillings@1289 3482 chainable = true;
nickjillings@1289 3483
nickjillings@1289 3484 if ( !jQuery.isFunction( value ) ) {
nickjillings@1289 3485 raw = true;
nickjillings@1289 3486 }
nickjillings@1289 3487
nickjillings@1289 3488 if ( bulk ) {
nickjillings@1289 3489 // Bulk operations run against the entire set
nickjillings@1289 3490 if ( raw ) {
nickjillings@1289 3491 fn.call( elems, value );
nickjillings@1289 3492 fn = null;
nickjillings@1289 3493
nickjillings@1289 3494 // ...except when executing function values
nickjillings@1289 3495 } else {
nickjillings@1289 3496 bulk = fn;
nickjillings@1289 3497 fn = function( elem, key, value ) {
nickjillings@1289 3498 return bulk.call( jQuery( elem ), value );
nickjillings@1289 3499 };
nickjillings@1289 3500 }
nickjillings@1289 3501 }
nickjillings@1289 3502
nickjillings@1289 3503 if ( fn ) {
nickjillings@1289 3504 for ( ; i < len; i++ ) {
nickjillings@1289 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nickjillings@1289 3506 }
nickjillings@1289 3507 }
nickjillings@1289 3508 }
nickjillings@1289 3509
nickjillings@1289 3510 return chainable ?
nickjillings@1289 3511 elems :
nickjillings@1289 3512
nickjillings@1289 3513 // Gets
nickjillings@1289 3514 bulk ?
nickjillings@1289 3515 fn.call( elems ) :
nickjillings@1289 3516 len ? fn( elems[0], key ) : emptyGet;
nickjillings@1289 3517 };
nickjillings@1289 3518
nickjillings@1289 3519
nickjillings@1289 3520 /**
nickjillings@1289 3521 * Determines whether an object can have data
nickjillings@1289 3522 */
nickjillings@1289 3523 jQuery.acceptData = function( owner ) {
nickjillings@1289 3524 // Accepts only:
nickjillings@1289 3525 // - Node
nickjillings@1289 3526 // - Node.ELEMENT_NODE
nickjillings@1289 3527 // - Node.DOCUMENT_NODE
nickjillings@1289 3528 // - Object
nickjillings@1289 3529 // - Any
nickjillings@1289 3530 /* jshint -W018 */
nickjillings@1289 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nickjillings@1289 3532 };
nickjillings@1289 3533
nickjillings@1289 3534
nickjillings@1289 3535 function Data() {
nickjillings@1289 3536 // Support: Android<4,
nickjillings@1289 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nickjillings@1289 3538 // return new empty object instead with no [[set]] accessor
nickjillings@1289 3539 Object.defineProperty( this.cache = {}, 0, {
nickjillings@1289 3540 get: function() {
nickjillings@1289 3541 return {};
nickjillings@1289 3542 }
nickjillings@1289 3543 });
nickjillings@1289 3544
nickjillings@1289 3545 this.expando = jQuery.expando + Data.uid++;
nickjillings@1289 3546 }
nickjillings@1289 3547
nickjillings@1289 3548 Data.uid = 1;
nickjillings@1289 3549 Data.accepts = jQuery.acceptData;
nickjillings@1289 3550
nickjillings@1289 3551 Data.prototype = {
nickjillings@1289 3552 key: function( owner ) {
nickjillings@1289 3553 // We can accept data for non-element nodes in modern browsers,
nickjillings@1289 3554 // but we should not, see #8335.
nickjillings@1289 3555 // Always return the key for a frozen object.
nickjillings@1289 3556 if ( !Data.accepts( owner ) ) {
nickjillings@1289 3557 return 0;
nickjillings@1289 3558 }
nickjillings@1289 3559
nickjillings@1289 3560 var descriptor = {},
nickjillings@1289 3561 // Check if the owner object already has a cache key
nickjillings@1289 3562 unlock = owner[ this.expando ];
nickjillings@1289 3563
nickjillings@1289 3564 // If not, create one
nickjillings@1289 3565 if ( !unlock ) {
nickjillings@1289 3566 unlock = Data.uid++;
nickjillings@1289 3567
nickjillings@1289 3568 // Secure it in a non-enumerable, non-writable property
nickjillings@1289 3569 try {
nickjillings@1289 3570 descriptor[ this.expando ] = { value: unlock };
nickjillings@1289 3571 Object.defineProperties( owner, descriptor );
nickjillings@1289 3572
nickjillings@1289 3573 // Support: Android<4
nickjillings@1289 3574 // Fallback to a less secure definition
nickjillings@1289 3575 } catch ( e ) {
nickjillings@1289 3576 descriptor[ this.expando ] = unlock;
nickjillings@1289 3577 jQuery.extend( owner, descriptor );
nickjillings@1289 3578 }
nickjillings@1289 3579 }
nickjillings@1289 3580
nickjillings@1289 3581 // Ensure the cache object
nickjillings@1289 3582 if ( !this.cache[ unlock ] ) {
nickjillings@1289 3583 this.cache[ unlock ] = {};
nickjillings@1289 3584 }
nickjillings@1289 3585
nickjillings@1289 3586 return unlock;
nickjillings@1289 3587 },
nickjillings@1289 3588 set: function( owner, data, value ) {
nickjillings@1289 3589 var prop,
nickjillings@1289 3590 // There may be an unlock assigned to this node,
nickjillings@1289 3591 // if there is no entry for this "owner", create one inline
nickjillings@1289 3592 // and set the unlock as though an owner entry had always existed
nickjillings@1289 3593 unlock = this.key( owner ),
nickjillings@1289 3594 cache = this.cache[ unlock ];
nickjillings@1289 3595
nickjillings@1289 3596 // Handle: [ owner, key, value ] args
nickjillings@1289 3597 if ( typeof data === "string" ) {
nickjillings@1289 3598 cache[ data ] = value;
nickjillings@1289 3599
nickjillings@1289 3600 // Handle: [ owner, { properties } ] args
nickjillings@1289 3601 } else {
nickjillings@1289 3602 // Fresh assignments by object are shallow copied
nickjillings@1289 3603 if ( jQuery.isEmptyObject( cache ) ) {
nickjillings@1289 3604 jQuery.extend( this.cache[ unlock ], data );
nickjillings@1289 3605 // Otherwise, copy the properties one-by-one to the cache object
nickjillings@1289 3606 } else {
nickjillings@1289 3607 for ( prop in data ) {
nickjillings@1289 3608 cache[ prop ] = data[ prop ];
nickjillings@1289 3609 }
nickjillings@1289 3610 }
nickjillings@1289 3611 }
nickjillings@1289 3612 return cache;
nickjillings@1289 3613 },
nickjillings@1289 3614 get: function( owner, key ) {
nickjillings@1289 3615 // Either a valid cache is found, or will be created.
nickjillings@1289 3616 // New caches will be created and the unlock returned,
nickjillings@1289 3617 // allowing direct access to the newly created
nickjillings@1289 3618 // empty data object. A valid owner object must be provided.
nickjillings@1289 3619 var cache = this.cache[ this.key( owner ) ];
nickjillings@1289 3620
nickjillings@1289 3621 return key === undefined ?
nickjillings@1289 3622 cache : cache[ key ];
nickjillings@1289 3623 },
nickjillings@1289 3624 access: function( owner, key, value ) {
nickjillings@1289 3625 var stored;
nickjillings@1289 3626 // In cases where either:
nickjillings@1289 3627 //
nickjillings@1289 3628 // 1. No key was specified
nickjillings@1289 3629 // 2. A string key was specified, but no value provided
nickjillings@1289 3630 //
nickjillings@1289 3631 // Take the "read" path and allow the get method to determine
nickjillings@1289 3632 // which value to return, respectively either:
nickjillings@1289 3633 //
nickjillings@1289 3634 // 1. The entire cache object
nickjillings@1289 3635 // 2. The data stored at the key
nickjillings@1289 3636 //
nickjillings@1289 3637 if ( key === undefined ||
nickjillings@1289 3638 ((key && typeof key === "string") && value === undefined) ) {
nickjillings@1289 3639
nickjillings@1289 3640 stored = this.get( owner, key );
nickjillings@1289 3641
nickjillings@1289 3642 return stored !== undefined ?
nickjillings@1289 3643 stored : this.get( owner, jQuery.camelCase(key) );
nickjillings@1289 3644 }
nickjillings@1289 3645
nickjillings@1289 3646 // [*]When the key is not a string, or both a key and value
nickjillings@1289 3647 // are specified, set or extend (existing objects) with either:
nickjillings@1289 3648 //
nickjillings@1289 3649 // 1. An object of properties
nickjillings@1289 3650 // 2. A key and value
nickjillings@1289 3651 //
nickjillings@1289 3652 this.set( owner, key, value );
nickjillings@1289 3653
nickjillings@1289 3654 // Since the "set" path can have two possible entry points
nickjillings@1289 3655 // return the expected data based on which path was taken[*]
nickjillings@1289 3656 return value !== undefined ? value : key;
nickjillings@1289 3657 },
nickjillings@1289 3658 remove: function( owner, key ) {
nickjillings@1289 3659 var i, name, camel,
nickjillings@1289 3660 unlock = this.key( owner ),
nickjillings@1289 3661 cache = this.cache[ unlock ];
nickjillings@1289 3662
nickjillings@1289 3663 if ( key === undefined ) {
nickjillings@1289 3664 this.cache[ unlock ] = {};
nickjillings@1289 3665
nickjillings@1289 3666 } else {
nickjillings@1289 3667 // Support array or space separated string of keys
nickjillings@1289 3668 if ( jQuery.isArray( key ) ) {
nickjillings@1289 3669 // If "name" is an array of keys...
nickjillings@1289 3670 // When data is initially created, via ("key", "val") signature,
nickjillings@1289 3671 // keys will be converted to camelCase.
nickjillings@1289 3672 // Since there is no way to tell _how_ a key was added, remove
nickjillings@1289 3673 // both plain key and camelCase key. #12786
nickjillings@1289 3674 // This will only penalize the array argument path.
nickjillings@1289 3675 name = key.concat( key.map( jQuery.camelCase ) );
nickjillings@1289 3676 } else {
nickjillings@1289 3677 camel = jQuery.camelCase( key );
nickjillings@1289 3678 // Try the string as a key before any manipulation
nickjillings@1289 3679 if ( key in cache ) {
nickjillings@1289 3680 name = [ key, camel ];
nickjillings@1289 3681 } else {
nickjillings@1289 3682 // If a key with the spaces exists, use it.
nickjillings@1289 3683 // Otherwise, create an array by matching non-whitespace
nickjillings@1289 3684 name = camel;
nickjillings@1289 3685 name = name in cache ?
nickjillings@1289 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nickjillings@1289 3687 }
nickjillings@1289 3688 }
nickjillings@1289 3689
nickjillings@1289 3690 i = name.length;
nickjillings@1289 3691 while ( i-- ) {
nickjillings@1289 3692 delete cache[ name[ i ] ];
nickjillings@1289 3693 }
nickjillings@1289 3694 }
nickjillings@1289 3695 },
nickjillings@1289 3696 hasData: function( owner ) {
nickjillings@1289 3697 return !jQuery.isEmptyObject(
nickjillings@1289 3698 this.cache[ owner[ this.expando ] ] || {}
nickjillings@1289 3699 );
nickjillings@1289 3700 },
nickjillings@1289 3701 discard: function( owner ) {
nickjillings@1289 3702 if ( owner[ this.expando ] ) {
nickjillings@1289 3703 delete this.cache[ owner[ this.expando ] ];
nickjillings@1289 3704 }
nickjillings@1289 3705 }
nickjillings@1289 3706 };
nickjillings@1289 3707 var data_priv = new Data();
nickjillings@1289 3708
nickjillings@1289 3709 var data_user = new Data();
nickjillings@1289 3710
nickjillings@1289 3711
nickjillings@1289 3712
nickjillings@1289 3713 // Implementation Summary
nickjillings@1289 3714 //
nickjillings@1289 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nickjillings@1289 3716 // 2. Improve the module's maintainability by reducing the storage
nickjillings@1289 3717 // paths to a single mechanism.
nickjillings@1289 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nickjillings@1289 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nickjillings@1289 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nickjillings@1289 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nickjillings@1289 3722
nickjillings@1289 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nickjillings@1289 3724 rmultiDash = /([A-Z])/g;
nickjillings@1289 3725
nickjillings@1289 3726 function dataAttr( elem, key, data ) {
nickjillings@1289 3727 var name;
nickjillings@1289 3728
nickjillings@1289 3729 // If nothing was found internally, try to fetch any
nickjillings@1289 3730 // data from the HTML5 data-* attribute
nickjillings@1289 3731 if ( data === undefined && elem.nodeType === 1 ) {
nickjillings@1289 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nickjillings@1289 3733 data = elem.getAttribute( name );
nickjillings@1289 3734
nickjillings@1289 3735 if ( typeof data === "string" ) {
nickjillings@1289 3736 try {
nickjillings@1289 3737 data = data === "true" ? true :
nickjillings@1289 3738 data === "false" ? false :
nickjillings@1289 3739 data === "null" ? null :
nickjillings@1289 3740 // Only convert to a number if it doesn't change the string
nickjillings@1289 3741 +data + "" === data ? +data :
nickjillings@1289 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nickjillings@1289 3743 data;
nickjillings@1289 3744 } catch( e ) {}
nickjillings@1289 3745
nickjillings@1289 3746 // Make sure we set the data so it isn't changed later
nickjillings@1289 3747 data_user.set( elem, key, data );
nickjillings@1289 3748 } else {
nickjillings@1289 3749 data = undefined;
nickjillings@1289 3750 }
nickjillings@1289 3751 }
nickjillings@1289 3752 return data;
nickjillings@1289 3753 }
nickjillings@1289 3754
nickjillings@1289 3755 jQuery.extend({
nickjillings@1289 3756 hasData: function( elem ) {
nickjillings@1289 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nickjillings@1289 3758 },
nickjillings@1289 3759
nickjillings@1289 3760 data: function( elem, name, data ) {
nickjillings@1289 3761 return data_user.access( elem, name, data );
nickjillings@1289 3762 },
nickjillings@1289 3763
nickjillings@1289 3764 removeData: function( elem, name ) {
nickjillings@1289 3765 data_user.remove( elem, name );
nickjillings@1289 3766 },
nickjillings@1289 3767
nickjillings@1289 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nickjillings@1289 3769 // with direct calls to data_priv methods, these can be deprecated.
nickjillings@1289 3770 _data: function( elem, name, data ) {
nickjillings@1289 3771 return data_priv.access( elem, name, data );
nickjillings@1289 3772 },
nickjillings@1289 3773
nickjillings@1289 3774 _removeData: function( elem, name ) {
nickjillings@1289 3775 data_priv.remove( elem, name );
nickjillings@1289 3776 }
nickjillings@1289 3777 });
nickjillings@1289 3778
nickjillings@1289 3779 jQuery.fn.extend({
nickjillings@1289 3780 data: function( key, value ) {
nickjillings@1289 3781 var i, name, data,
nickjillings@1289 3782 elem = this[ 0 ],
nickjillings@1289 3783 attrs = elem && elem.attributes;
nickjillings@1289 3784
nickjillings@1289 3785 // Gets all values
nickjillings@1289 3786 if ( key === undefined ) {
nickjillings@1289 3787 if ( this.length ) {
nickjillings@1289 3788 data = data_user.get( elem );
nickjillings@1289 3789
nickjillings@1289 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nickjillings@1289 3791 i = attrs.length;
nickjillings@1289 3792 while ( i-- ) {
nickjillings@1289 3793
nickjillings@1289 3794 // Support: IE11+
nickjillings@1289 3795 // The attrs elements can be null (#14894)
nickjillings@1289 3796 if ( attrs[ i ] ) {
nickjillings@1289 3797 name = attrs[ i ].name;
nickjillings@1289 3798 if ( name.indexOf( "data-" ) === 0 ) {
nickjillings@1289 3799 name = jQuery.camelCase( name.slice(5) );
nickjillings@1289 3800 dataAttr( elem, name, data[ name ] );
nickjillings@1289 3801 }
nickjillings@1289 3802 }
nickjillings@1289 3803 }
nickjillings@1289 3804 data_priv.set( elem, "hasDataAttrs", true );
nickjillings@1289 3805 }
nickjillings@1289 3806 }
nickjillings@1289 3807
nickjillings@1289 3808 return data;
nickjillings@1289 3809 }
nickjillings@1289 3810
nickjillings@1289 3811 // Sets multiple values
nickjillings@1289 3812 if ( typeof key === "object" ) {
nickjillings@1289 3813 return this.each(function() {
nickjillings@1289 3814 data_user.set( this, key );
nickjillings@1289 3815 });
nickjillings@1289 3816 }
nickjillings@1289 3817
nickjillings@1289 3818 return access( this, function( value ) {
nickjillings@1289 3819 var data,
nickjillings@1289 3820 camelKey = jQuery.camelCase( key );
nickjillings@1289 3821
nickjillings@1289 3822 // The calling jQuery object (element matches) is not empty
nickjillings@1289 3823 // (and therefore has an element appears at this[ 0 ]) and the
nickjillings@1289 3824 // `value` parameter was not undefined. An empty jQuery object
nickjillings@1289 3825 // will result in `undefined` for elem = this[ 0 ] which will
nickjillings@1289 3826 // throw an exception if an attempt to read a data cache is made.
nickjillings@1289 3827 if ( elem && value === undefined ) {
nickjillings@1289 3828 // Attempt to get data from the cache
nickjillings@1289 3829 // with the key as-is
nickjillings@1289 3830 data = data_user.get( elem, key );
nickjillings@1289 3831 if ( data !== undefined ) {
nickjillings@1289 3832 return data;
nickjillings@1289 3833 }
nickjillings@1289 3834
nickjillings@1289 3835 // Attempt to get data from the cache
nickjillings@1289 3836 // with the key camelized
nickjillings@1289 3837 data = data_user.get( elem, camelKey );
nickjillings@1289 3838 if ( data !== undefined ) {
nickjillings@1289 3839 return data;
nickjillings@1289 3840 }
nickjillings@1289 3841
nickjillings@1289 3842 // Attempt to "discover" the data in
nickjillings@1289 3843 // HTML5 custom data-* attrs
nickjillings@1289 3844 data = dataAttr( elem, camelKey, undefined );
nickjillings@1289 3845 if ( data !== undefined ) {
nickjillings@1289 3846 return data;
nickjillings@1289 3847 }
nickjillings@1289 3848
nickjillings@1289 3849 // We tried really hard, but the data doesn't exist.
nickjillings@1289 3850 return;
nickjillings@1289 3851 }
nickjillings@1289 3852
nickjillings@1289 3853 // Set the data...
nickjillings@1289 3854 this.each(function() {
nickjillings@1289 3855 // First, attempt to store a copy or reference of any
nickjillings@1289 3856 // data that might've been store with a camelCased key.
nickjillings@1289 3857 var data = data_user.get( this, camelKey );
nickjillings@1289 3858
nickjillings@1289 3859 // For HTML5 data-* attribute interop, we have to
nickjillings@1289 3860 // store property names with dashes in a camelCase form.
nickjillings@1289 3861 // This might not apply to all properties...*
nickjillings@1289 3862 data_user.set( this, camelKey, value );
nickjillings@1289 3863
nickjillings@1289 3864 // *... In the case of properties that might _actually_
nickjillings@1289 3865 // have dashes, we need to also store a copy of that
nickjillings@1289 3866 // unchanged property.
nickjillings@1289 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nickjillings@1289 3868 data_user.set( this, key, value );
nickjillings@1289 3869 }
nickjillings@1289 3870 });
nickjillings@1289 3871 }, null, value, arguments.length > 1, null, true );
nickjillings@1289 3872 },
nickjillings@1289 3873
nickjillings@1289 3874 removeData: function( key ) {
nickjillings@1289 3875 return this.each(function() {
nickjillings@1289 3876 data_user.remove( this, key );
nickjillings@1289 3877 });
nickjillings@1289 3878 }
nickjillings@1289 3879 });
nickjillings@1289 3880
nickjillings@1289 3881
nickjillings@1289 3882 jQuery.extend({
nickjillings@1289 3883 queue: function( elem, type, data ) {
nickjillings@1289 3884 var queue;
nickjillings@1289 3885
nickjillings@1289 3886 if ( elem ) {
nickjillings@1289 3887 type = ( type || "fx" ) + "queue";
nickjillings@1289 3888 queue = data_priv.get( elem, type );
nickjillings@1289 3889
nickjillings@1289 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nickjillings@1289 3891 if ( data ) {
nickjillings@1289 3892 if ( !queue || jQuery.isArray( data ) ) {
nickjillings@1289 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nickjillings@1289 3894 } else {
nickjillings@1289 3895 queue.push( data );
nickjillings@1289 3896 }
nickjillings@1289 3897 }
nickjillings@1289 3898 return queue || [];
nickjillings@1289 3899 }
nickjillings@1289 3900 },
nickjillings@1289 3901
nickjillings@1289 3902 dequeue: function( elem, type ) {
nickjillings@1289 3903 type = type || "fx";
nickjillings@1289 3904
nickjillings@1289 3905 var queue = jQuery.queue( elem, type ),
nickjillings@1289 3906 startLength = queue.length,
nickjillings@1289 3907 fn = queue.shift(),
nickjillings@1289 3908 hooks = jQuery._queueHooks( elem, type ),
nickjillings@1289 3909 next = function() {
nickjillings@1289 3910 jQuery.dequeue( elem, type );
nickjillings@1289 3911 };
nickjillings@1289 3912
nickjillings@1289 3913 // If the fx queue is dequeued, always remove the progress sentinel
nickjillings@1289 3914 if ( fn === "inprogress" ) {
nickjillings@1289 3915 fn = queue.shift();
nickjillings@1289 3916 startLength--;
nickjillings@1289 3917 }
nickjillings@1289 3918
nickjillings@1289 3919 if ( fn ) {
nickjillings@1289 3920
nickjillings@1289 3921 // Add a progress sentinel to prevent the fx queue from being
nickjillings@1289 3922 // automatically dequeued
nickjillings@1289 3923 if ( type === "fx" ) {
nickjillings@1289 3924 queue.unshift( "inprogress" );
nickjillings@1289 3925 }
nickjillings@1289 3926
nickjillings@1289 3927 // Clear up the last queue stop function
nickjillings@1289 3928 delete hooks.stop;
nickjillings@1289 3929 fn.call( elem, next, hooks );
nickjillings@1289 3930 }
nickjillings@1289 3931
nickjillings@1289 3932 if ( !startLength && hooks ) {
nickjillings@1289 3933 hooks.empty.fire();
nickjillings@1289 3934 }
nickjillings@1289 3935 },
nickjillings@1289 3936
nickjillings@1289 3937 // Not public - generate a queueHooks object, or return the current one
nickjillings@1289 3938 _queueHooks: function( elem, type ) {
nickjillings@1289 3939 var key = type + "queueHooks";
nickjillings@1289 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nickjillings@1289 3941 empty: jQuery.Callbacks("once memory").add(function() {
nickjillings@1289 3942 data_priv.remove( elem, [ type + "queue", key ] );
nickjillings@1289 3943 })
nickjillings@1289 3944 });
nickjillings@1289 3945 }
nickjillings@1289 3946 });
nickjillings@1289 3947
nickjillings@1289 3948 jQuery.fn.extend({
nickjillings@1289 3949 queue: function( type, data ) {
nickjillings@1289 3950 var setter = 2;
nickjillings@1289 3951
nickjillings@1289 3952 if ( typeof type !== "string" ) {
nickjillings@1289 3953 data = type;
nickjillings@1289 3954 type = "fx";
nickjillings@1289 3955 setter--;
nickjillings@1289 3956 }
nickjillings@1289 3957
nickjillings@1289 3958 if ( arguments.length < setter ) {
nickjillings@1289 3959 return jQuery.queue( this[0], type );
nickjillings@1289 3960 }
nickjillings@1289 3961
nickjillings@1289 3962 return data === undefined ?
nickjillings@1289 3963 this :
nickjillings@1289 3964 this.each(function() {
nickjillings@1289 3965 var queue = jQuery.queue( this, type, data );
nickjillings@1289 3966
nickjillings@1289 3967 // Ensure a hooks for this queue
nickjillings@1289 3968 jQuery._queueHooks( this, type );
nickjillings@1289 3969
nickjillings@1289 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nickjillings@1289 3971 jQuery.dequeue( this, type );
nickjillings@1289 3972 }
nickjillings@1289 3973 });
nickjillings@1289 3974 },
nickjillings@1289 3975 dequeue: function( type ) {
nickjillings@1289 3976 return this.each(function() {
nickjillings@1289 3977 jQuery.dequeue( this, type );
nickjillings@1289 3978 });
nickjillings@1289 3979 },
nickjillings@1289 3980 clearQueue: function( type ) {
nickjillings@1289 3981 return this.queue( type || "fx", [] );
nickjillings@1289 3982 },
nickjillings@1289 3983 // Get a promise resolved when queues of a certain type
nickjillings@1289 3984 // are emptied (fx is the type by default)
nickjillings@1289 3985 promise: function( type, obj ) {
nickjillings@1289 3986 var tmp,
nickjillings@1289 3987 count = 1,
nickjillings@1289 3988 defer = jQuery.Deferred(),
nickjillings@1289 3989 elements = this,
nickjillings@1289 3990 i = this.length,
nickjillings@1289 3991 resolve = function() {
nickjillings@1289 3992 if ( !( --count ) ) {
nickjillings@1289 3993 defer.resolveWith( elements, [ elements ] );
nickjillings@1289 3994 }
nickjillings@1289 3995 };
nickjillings@1289 3996
nickjillings@1289 3997 if ( typeof type !== "string" ) {
nickjillings@1289 3998 obj = type;
nickjillings@1289 3999 type = undefined;
nickjillings@1289 4000 }
nickjillings@1289 4001 type = type || "fx";
nickjillings@1289 4002
nickjillings@1289 4003 while ( i-- ) {
nickjillings@1289 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nickjillings@1289 4005 if ( tmp && tmp.empty ) {
nickjillings@1289 4006 count++;
nickjillings@1289 4007 tmp.empty.add( resolve );
nickjillings@1289 4008 }
nickjillings@1289 4009 }
nickjillings@1289 4010 resolve();
nickjillings@1289 4011 return defer.promise( obj );
nickjillings@1289 4012 }
nickjillings@1289 4013 });
nickjillings@1289 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nickjillings@1289 4015
nickjillings@1289 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nickjillings@1289 4017
nickjillings@1289 4018 var isHidden = function( elem, el ) {
nickjillings@1289 4019 // isHidden might be called from jQuery#filter function;
nickjillings@1289 4020 // in that case, element will be second argument
nickjillings@1289 4021 elem = el || elem;
nickjillings@1289 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nickjillings@1289 4023 };
nickjillings@1289 4024
nickjillings@1289 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nickjillings@1289 4026
nickjillings@1289 4027
nickjillings@1289 4028
nickjillings@1289 4029 (function() {
nickjillings@1289 4030 var fragment = document.createDocumentFragment(),
nickjillings@1289 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nickjillings@1289 4032 input = document.createElement( "input" );
nickjillings@1289 4033
nickjillings@1289 4034 // Support: Safari<=5.1
nickjillings@1289 4035 // Check state lost if the name is set (#11217)
nickjillings@1289 4036 // Support: Windows Web Apps (WWA)
nickjillings@1289 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nickjillings@1289 4038 input.setAttribute( "type", "radio" );
nickjillings@1289 4039 input.setAttribute( "checked", "checked" );
nickjillings@1289 4040 input.setAttribute( "name", "t" );
nickjillings@1289 4041
nickjillings@1289 4042 div.appendChild( input );
nickjillings@1289 4043
nickjillings@1289 4044 // Support: Safari<=5.1, Android<4.2
nickjillings@1289 4045 // Older WebKit doesn't clone checked state correctly in fragments
nickjillings@1289 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nickjillings@1289 4047
nickjillings@1289 4048 // Support: IE<=11+
nickjillings@1289 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nickjillings@1289 4050 div.innerHTML = "<textarea>x</textarea>";
nickjillings@1289 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nickjillings@1289 4052 })();
nickjillings@1289 4053 var strundefined = typeof undefined;
nickjillings@1289 4054
nickjillings@1289 4055
nickjillings@1289 4056
nickjillings@1289 4057 support.focusinBubbles = "onfocusin" in window;
nickjillings@1289 4058
nickjillings@1289 4059
nickjillings@1289 4060 var
nickjillings@1289 4061 rkeyEvent = /^key/,
nickjillings@1289 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nickjillings@1289 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nickjillings@1289 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nickjillings@1289 4065
nickjillings@1289 4066 function returnTrue() {
nickjillings@1289 4067 return true;
nickjillings@1289 4068 }
nickjillings@1289 4069
nickjillings@1289 4070 function returnFalse() {
nickjillings@1289 4071 return false;
nickjillings@1289 4072 }
nickjillings@1289 4073
nickjillings@1289 4074 function safeActiveElement() {
nickjillings@1289 4075 try {
nickjillings@1289 4076 return document.activeElement;
nickjillings@1289 4077 } catch ( err ) { }
nickjillings@1289 4078 }
nickjillings@1289 4079
nickjillings@1289 4080 /*
nickjillings@1289 4081 * Helper functions for managing events -- not part of the public interface.
nickjillings@1289 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nickjillings@1289 4083 */
nickjillings@1289 4084 jQuery.event = {
nickjillings@1289 4085
nickjillings@1289 4086 global: {},
nickjillings@1289 4087
nickjillings@1289 4088 add: function( elem, types, handler, data, selector ) {
nickjillings@1289 4089
nickjillings@1289 4090 var handleObjIn, eventHandle, tmp,
nickjillings@1289 4091 events, t, handleObj,
nickjillings@1289 4092 special, handlers, type, namespaces, origType,
nickjillings@1289 4093 elemData = data_priv.get( elem );
nickjillings@1289 4094
nickjillings@1289 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nickjillings@1289 4096 if ( !elemData ) {
nickjillings@1289 4097 return;
nickjillings@1289 4098 }
nickjillings@1289 4099
nickjillings@1289 4100 // Caller can pass in an object of custom data in lieu of the handler
nickjillings@1289 4101 if ( handler.handler ) {
nickjillings@1289 4102 handleObjIn = handler;
nickjillings@1289 4103 handler = handleObjIn.handler;
nickjillings@1289 4104 selector = handleObjIn.selector;
nickjillings@1289 4105 }
nickjillings@1289 4106
nickjillings@1289 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nickjillings@1289 4108 if ( !handler.guid ) {
nickjillings@1289 4109 handler.guid = jQuery.guid++;
nickjillings@1289 4110 }
nickjillings@1289 4111
nickjillings@1289 4112 // Init the element's event structure and main handler, if this is the first
nickjillings@1289 4113 if ( !(events = elemData.events) ) {
nickjillings@1289 4114 events = elemData.events = {};
nickjillings@1289 4115 }
nickjillings@1289 4116 if ( !(eventHandle = elemData.handle) ) {
nickjillings@1289 4117 eventHandle = elemData.handle = function( e ) {
nickjillings@1289 4118 // Discard the second event of a jQuery.event.trigger() and
nickjillings@1289 4119 // when an event is called after a page has unloaded
nickjillings@1289 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nickjillings@1289 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nickjillings@1289 4122 };
nickjillings@1289 4123 }
nickjillings@1289 4124
nickjillings@1289 4125 // Handle multiple events separated by a space
nickjillings@1289 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1289 4127 t = types.length;
nickjillings@1289 4128 while ( t-- ) {
nickjillings@1289 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1289 4130 type = origType = tmp[1];
nickjillings@1289 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1289 4132
nickjillings@1289 4133 // There *must* be a type, no attaching namespace-only handlers
nickjillings@1289 4134 if ( !type ) {
nickjillings@1289 4135 continue;
nickjillings@1289 4136 }
nickjillings@1289 4137
nickjillings@1289 4138 // If event changes its type, use the special event handlers for the changed type
nickjillings@1289 4139 special = jQuery.event.special[ type ] || {};
nickjillings@1289 4140
nickjillings@1289 4141 // If selector defined, determine special event api type, otherwise given type
nickjillings@1289 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1289 4143
nickjillings@1289 4144 // Update special based on newly reset type
nickjillings@1289 4145 special = jQuery.event.special[ type ] || {};
nickjillings@1289 4146
nickjillings@1289 4147 // handleObj is passed to all event handlers
nickjillings@1289 4148 handleObj = jQuery.extend({
nickjillings@1289 4149 type: type,
nickjillings@1289 4150 origType: origType,
nickjillings@1289 4151 data: data,
nickjillings@1289 4152 handler: handler,
nickjillings@1289 4153 guid: handler.guid,
nickjillings@1289 4154 selector: selector,
nickjillings@1289 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nickjillings@1289 4156 namespace: namespaces.join(".")
nickjillings@1289 4157 }, handleObjIn );
nickjillings@1289 4158
nickjillings@1289 4159 // Init the event handler queue if we're the first
nickjillings@1289 4160 if ( !(handlers = events[ type ]) ) {
nickjillings@1289 4161 handlers = events[ type ] = [];
nickjillings@1289 4162 handlers.delegateCount = 0;
nickjillings@1289 4163
nickjillings@1289 4164 // Only use addEventListener if the special events handler returns false
nickjillings@1289 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nickjillings@1289 4166 if ( elem.addEventListener ) {
nickjillings@1289 4167 elem.addEventListener( type, eventHandle, false );
nickjillings@1289 4168 }
nickjillings@1289 4169 }
nickjillings@1289 4170 }
nickjillings@1289 4171
nickjillings@1289 4172 if ( special.add ) {
nickjillings@1289 4173 special.add.call( elem, handleObj );
nickjillings@1289 4174
nickjillings@1289 4175 if ( !handleObj.handler.guid ) {
nickjillings@1289 4176 handleObj.handler.guid = handler.guid;
nickjillings@1289 4177 }
nickjillings@1289 4178 }
nickjillings@1289 4179
nickjillings@1289 4180 // Add to the element's handler list, delegates in front
nickjillings@1289 4181 if ( selector ) {
nickjillings@1289 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nickjillings@1289 4183 } else {
nickjillings@1289 4184 handlers.push( handleObj );
nickjillings@1289 4185 }
nickjillings@1289 4186
nickjillings@1289 4187 // Keep track of which events have ever been used, for event optimization
nickjillings@1289 4188 jQuery.event.global[ type ] = true;
nickjillings@1289 4189 }
nickjillings@1289 4190
nickjillings@1289 4191 },
nickjillings@1289 4192
nickjillings@1289 4193 // Detach an event or set of events from an element
nickjillings@1289 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nickjillings@1289 4195
nickjillings@1289 4196 var j, origCount, tmp,
nickjillings@1289 4197 events, t, handleObj,
nickjillings@1289 4198 special, handlers, type, namespaces, origType,
nickjillings@1289 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nickjillings@1289 4200
nickjillings@1289 4201 if ( !elemData || !(events = elemData.events) ) {
nickjillings@1289 4202 return;
nickjillings@1289 4203 }
nickjillings@1289 4204
nickjillings@1289 4205 // Once for each type.namespace in types; type may be omitted
nickjillings@1289 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1289 4207 t = types.length;
nickjillings@1289 4208 while ( t-- ) {
nickjillings@1289 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1289 4210 type = origType = tmp[1];
nickjillings@1289 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1289 4212
nickjillings@1289 4213 // Unbind all events (on this namespace, if provided) for the element
nickjillings@1289 4214 if ( !type ) {
nickjillings@1289 4215 for ( type in events ) {
nickjillings@1289 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nickjillings@1289 4217 }
nickjillings@1289 4218 continue;
nickjillings@1289 4219 }
nickjillings@1289 4220
nickjillings@1289 4221 special = jQuery.event.special[ type ] || {};
nickjillings@1289 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1289 4223 handlers = events[ type ] || [];
nickjillings@1289 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nickjillings@1289 4225
nickjillings@1289 4226 // Remove matching events
nickjillings@1289 4227 origCount = j = handlers.length;
nickjillings@1289 4228 while ( j-- ) {
nickjillings@1289 4229 handleObj = handlers[ j ];
nickjillings@1289 4230
nickjillings@1289 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nickjillings@1289 4232 ( !handler || handler.guid === handleObj.guid ) &&
nickjillings@1289 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nickjillings@1289 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nickjillings@1289 4235 handlers.splice( j, 1 );
nickjillings@1289 4236
nickjillings@1289 4237 if ( handleObj.selector ) {
nickjillings@1289 4238 handlers.delegateCount--;
nickjillings@1289 4239 }
nickjillings@1289 4240 if ( special.remove ) {
nickjillings@1289 4241 special.remove.call( elem, handleObj );
nickjillings@1289 4242 }
nickjillings@1289 4243 }
nickjillings@1289 4244 }
nickjillings@1289 4245
nickjillings@1289 4246 // Remove generic event handler if we removed something and no more handlers exist
nickjillings@1289 4247 // (avoids potential for endless recursion during removal of special event handlers)
nickjillings@1289 4248 if ( origCount && !handlers.length ) {
nickjillings@1289 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nickjillings@1289 4250 jQuery.removeEvent( elem, type, elemData.handle );
nickjillings@1289 4251 }
nickjillings@1289 4252
nickjillings@1289 4253 delete events[ type ];
nickjillings@1289 4254 }
nickjillings@1289 4255 }
nickjillings@1289 4256
nickjillings@1289 4257 // Remove the expando if it's no longer used
nickjillings@1289 4258 if ( jQuery.isEmptyObject( events ) ) {
nickjillings@1289 4259 delete elemData.handle;
nickjillings@1289 4260 data_priv.remove( elem, "events" );
nickjillings@1289 4261 }
nickjillings@1289 4262 },
nickjillings@1289 4263
nickjillings@1289 4264 trigger: function( event, data, elem, onlyHandlers ) {
nickjillings@1289 4265
nickjillings@1289 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nickjillings@1289 4267 eventPath = [ elem || document ],
nickjillings@1289 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nickjillings@1289 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nickjillings@1289 4270
nickjillings@1289 4271 cur = tmp = elem = elem || document;
nickjillings@1289 4272
nickjillings@1289 4273 // Don't do events on text and comment nodes
nickjillings@1289 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nickjillings@1289 4275 return;
nickjillings@1289 4276 }
nickjillings@1289 4277
nickjillings@1289 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nickjillings@1289 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nickjillings@1289 4280 return;
nickjillings@1289 4281 }
nickjillings@1289 4282
nickjillings@1289 4283 if ( type.indexOf(".") >= 0 ) {
nickjillings@1289 4284 // Namespaced trigger; create a regexp to match event type in handle()
nickjillings@1289 4285 namespaces = type.split(".");
nickjillings@1289 4286 type = namespaces.shift();
nickjillings@1289 4287 namespaces.sort();
nickjillings@1289 4288 }
nickjillings@1289 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nickjillings@1289 4290
nickjillings@1289 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nickjillings@1289 4292 event = event[ jQuery.expando ] ?
nickjillings@1289 4293 event :
nickjillings@1289 4294 new jQuery.Event( type, typeof event === "object" && event );
nickjillings@1289 4295
nickjillings@1289 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nickjillings@1289 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nickjillings@1289 4298 event.namespace = namespaces.join(".");
nickjillings@1289 4299 event.namespace_re = event.namespace ?
nickjillings@1289 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nickjillings@1289 4301 null;
nickjillings@1289 4302
nickjillings@1289 4303 // Clean up the event in case it is being reused
nickjillings@1289 4304 event.result = undefined;
nickjillings@1289 4305 if ( !event.target ) {
nickjillings@1289 4306 event.target = elem;
nickjillings@1289 4307 }
nickjillings@1289 4308
nickjillings@1289 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nickjillings@1289 4310 data = data == null ?
nickjillings@1289 4311 [ event ] :
nickjillings@1289 4312 jQuery.makeArray( data, [ event ] );
nickjillings@1289 4313
nickjillings@1289 4314 // Allow special events to draw outside the lines
nickjillings@1289 4315 special = jQuery.event.special[ type ] || {};
nickjillings@1289 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nickjillings@1289 4317 return;
nickjillings@1289 4318 }
nickjillings@1289 4319
nickjillings@1289 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nickjillings@1289 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nickjillings@1289 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nickjillings@1289 4323
nickjillings@1289 4324 bubbleType = special.delegateType || type;
nickjillings@1289 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nickjillings@1289 4326 cur = cur.parentNode;
nickjillings@1289 4327 }
nickjillings@1289 4328 for ( ; cur; cur = cur.parentNode ) {
nickjillings@1289 4329 eventPath.push( cur );
nickjillings@1289 4330 tmp = cur;
nickjillings@1289 4331 }
nickjillings@1289 4332
nickjillings@1289 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nickjillings@1289 4334 if ( tmp === (elem.ownerDocument || document) ) {
nickjillings@1289 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nickjillings@1289 4336 }
nickjillings@1289 4337 }
nickjillings@1289 4338
nickjillings@1289 4339 // Fire handlers on the event path
nickjillings@1289 4340 i = 0;
nickjillings@1289 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nickjillings@1289 4342
nickjillings@1289 4343 event.type = i > 1 ?
nickjillings@1289 4344 bubbleType :
nickjillings@1289 4345 special.bindType || type;
nickjillings@1289 4346
nickjillings@1289 4347 // jQuery handler
nickjillings@1289 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nickjillings@1289 4349 if ( handle ) {
nickjillings@1289 4350 handle.apply( cur, data );
nickjillings@1289 4351 }
nickjillings@1289 4352
nickjillings@1289 4353 // Native handler
nickjillings@1289 4354 handle = ontype && cur[ ontype ];
nickjillings@1289 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nickjillings@1289 4356 event.result = handle.apply( cur, data );
nickjillings@1289 4357 if ( event.result === false ) {
nickjillings@1289 4358 event.preventDefault();
nickjillings@1289 4359 }
nickjillings@1289 4360 }
nickjillings@1289 4361 }
nickjillings@1289 4362 event.type = type;
nickjillings@1289 4363
nickjillings@1289 4364 // If nobody prevented the default action, do it now
nickjillings@1289 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nickjillings@1289 4366
nickjillings@1289 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nickjillings@1289 4368 jQuery.acceptData( elem ) ) {
nickjillings@1289 4369
nickjillings@1289 4370 // Call a native DOM method on the target with the same name name as the event.
nickjillings@1289 4371 // Don't do default actions on window, that's where global variables be (#6170)
nickjillings@1289 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nickjillings@1289 4373
nickjillings@1289 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nickjillings@1289 4375 tmp = elem[ ontype ];
nickjillings@1289 4376
nickjillings@1289 4377 if ( tmp ) {
nickjillings@1289 4378 elem[ ontype ] = null;
nickjillings@1289 4379 }
nickjillings@1289 4380
nickjillings@1289 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nickjillings@1289 4382 jQuery.event.triggered = type;
nickjillings@1289 4383 elem[ type ]();
nickjillings@1289 4384 jQuery.event.triggered = undefined;
nickjillings@1289 4385
nickjillings@1289 4386 if ( tmp ) {
nickjillings@1289 4387 elem[ ontype ] = tmp;
nickjillings@1289 4388 }
nickjillings@1289 4389 }
nickjillings@1289 4390 }
nickjillings@1289 4391 }
nickjillings@1289 4392
nickjillings@1289 4393 return event.result;
nickjillings@1289 4394 },
nickjillings@1289 4395
nickjillings@1289 4396 dispatch: function( event ) {
nickjillings@1289 4397
nickjillings@1289 4398 // Make a writable jQuery.Event from the native event object
nickjillings@1289 4399 event = jQuery.event.fix( event );
nickjillings@1289 4400
nickjillings@1289 4401 var i, j, ret, matched, handleObj,
nickjillings@1289 4402 handlerQueue = [],
nickjillings@1289 4403 args = slice.call( arguments ),
nickjillings@1289 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nickjillings@1289 4405 special = jQuery.event.special[ event.type ] || {};
nickjillings@1289 4406
nickjillings@1289 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nickjillings@1289 4408 args[0] = event;
nickjillings@1289 4409 event.delegateTarget = this;
nickjillings@1289 4410
nickjillings@1289 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nickjillings@1289 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nickjillings@1289 4413 return;
nickjillings@1289 4414 }
nickjillings@1289 4415
nickjillings@1289 4416 // Determine handlers
nickjillings@1289 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nickjillings@1289 4418
nickjillings@1289 4419 // Run delegates first; they may want to stop propagation beneath us
nickjillings@1289 4420 i = 0;
nickjillings@1289 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nickjillings@1289 4422 event.currentTarget = matched.elem;
nickjillings@1289 4423
nickjillings@1289 4424 j = 0;
nickjillings@1289 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nickjillings@1289 4426
nickjillings@1289 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nickjillings@1289 4428 // a subset or equal to those in the bound event (both can have no namespace).
nickjillings@1289 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nickjillings@1289 4430
nickjillings@1289 4431 event.handleObj = handleObj;
nickjillings@1289 4432 event.data = handleObj.data;
nickjillings@1289 4433
nickjillings@1289 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nickjillings@1289 4435 .apply( matched.elem, args );
nickjillings@1289 4436
nickjillings@1289 4437 if ( ret !== undefined ) {
nickjillings@1289 4438 if ( (event.result = ret) === false ) {
nickjillings@1289 4439 event.preventDefault();
nickjillings@1289 4440 event.stopPropagation();
nickjillings@1289 4441 }
nickjillings@1289 4442 }
nickjillings@1289 4443 }
nickjillings@1289 4444 }
nickjillings@1289 4445 }
nickjillings@1289 4446
nickjillings@1289 4447 // Call the postDispatch hook for the mapped type
nickjillings@1289 4448 if ( special.postDispatch ) {
nickjillings@1289 4449 special.postDispatch.call( this, event );
nickjillings@1289 4450 }
nickjillings@1289 4451
nickjillings@1289 4452 return event.result;
nickjillings@1289 4453 },
nickjillings@1289 4454
nickjillings@1289 4455 handlers: function( event, handlers ) {
nickjillings@1289 4456 var i, matches, sel, handleObj,
nickjillings@1289 4457 handlerQueue = [],
nickjillings@1289 4458 delegateCount = handlers.delegateCount,
nickjillings@1289 4459 cur = event.target;
nickjillings@1289 4460
nickjillings@1289 4461 // Find delegate handlers
nickjillings@1289 4462 // Black-hole SVG <use> instance trees (#13180)
nickjillings@1289 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nickjillings@1289 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nickjillings@1289 4465
nickjillings@1289 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nickjillings@1289 4467
nickjillings@1289 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nickjillings@1289 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nickjillings@1289 4470 matches = [];
nickjillings@1289 4471 for ( i = 0; i < delegateCount; i++ ) {
nickjillings@1289 4472 handleObj = handlers[ i ];
nickjillings@1289 4473
nickjillings@1289 4474 // Don't conflict with Object.prototype properties (#13203)
nickjillings@1289 4475 sel = handleObj.selector + " ";
nickjillings@1289 4476
nickjillings@1289 4477 if ( matches[ sel ] === undefined ) {
nickjillings@1289 4478 matches[ sel ] = handleObj.needsContext ?
nickjillings@1289 4479 jQuery( sel, this ).index( cur ) >= 0 :
nickjillings@1289 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nickjillings@1289 4481 }
nickjillings@1289 4482 if ( matches[ sel ] ) {
nickjillings@1289 4483 matches.push( handleObj );
nickjillings@1289 4484 }
nickjillings@1289 4485 }
nickjillings@1289 4486 if ( matches.length ) {
nickjillings@1289 4487 handlerQueue.push({ elem: cur, handlers: matches });
nickjillings@1289 4488 }
nickjillings@1289 4489 }
nickjillings@1289 4490 }
nickjillings@1289 4491 }
nickjillings@1289 4492
nickjillings@1289 4493 // Add the remaining (directly-bound) handlers
nickjillings@1289 4494 if ( delegateCount < handlers.length ) {
nickjillings@1289 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nickjillings@1289 4496 }
nickjillings@1289 4497
nickjillings@1289 4498 return handlerQueue;
nickjillings@1289 4499 },
nickjillings@1289 4500
nickjillings@1289 4501 // Includes some event props shared by KeyEvent and MouseEvent
nickjillings@1289 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nickjillings@1289 4503
nickjillings@1289 4504 fixHooks: {},
nickjillings@1289 4505
nickjillings@1289 4506 keyHooks: {
nickjillings@1289 4507 props: "char charCode key keyCode".split(" "),
nickjillings@1289 4508 filter: function( event, original ) {
nickjillings@1289 4509
nickjillings@1289 4510 // Add which for key events
nickjillings@1289 4511 if ( event.which == null ) {
nickjillings@1289 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nickjillings@1289 4513 }
nickjillings@1289 4514
nickjillings@1289 4515 return event;
nickjillings@1289 4516 }
nickjillings@1289 4517 },
nickjillings@1289 4518
nickjillings@1289 4519 mouseHooks: {
nickjillings@1289 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nickjillings@1289 4521 filter: function( event, original ) {
nickjillings@1289 4522 var eventDoc, doc, body,
nickjillings@1289 4523 button = original.button;
nickjillings@1289 4524
nickjillings@1289 4525 // Calculate pageX/Y if missing and clientX/Y available
nickjillings@1289 4526 if ( event.pageX == null && original.clientX != null ) {
nickjillings@1289 4527 eventDoc = event.target.ownerDocument || document;
nickjillings@1289 4528 doc = eventDoc.documentElement;
nickjillings@1289 4529 body = eventDoc.body;
nickjillings@1289 4530
nickjillings@1289 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nickjillings@1289 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nickjillings@1289 4533 }
nickjillings@1289 4534
nickjillings@1289 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nickjillings@1289 4536 // Note: button is not normalized, so don't use it
nickjillings@1289 4537 if ( !event.which && button !== undefined ) {
nickjillings@1289 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nickjillings@1289 4539 }
nickjillings@1289 4540
nickjillings@1289 4541 return event;
nickjillings@1289 4542 }
nickjillings@1289 4543 },
nickjillings@1289 4544
nickjillings@1289 4545 fix: function( event ) {
nickjillings@1289 4546 if ( event[ jQuery.expando ] ) {
nickjillings@1289 4547 return event;
nickjillings@1289 4548 }
nickjillings@1289 4549
nickjillings@1289 4550 // Create a writable copy of the event object and normalize some properties
nickjillings@1289 4551 var i, prop, copy,
nickjillings@1289 4552 type = event.type,
nickjillings@1289 4553 originalEvent = event,
nickjillings@1289 4554 fixHook = this.fixHooks[ type ];
nickjillings@1289 4555
nickjillings@1289 4556 if ( !fixHook ) {
nickjillings@1289 4557 this.fixHooks[ type ] = fixHook =
nickjillings@1289 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nickjillings@1289 4559 rkeyEvent.test( type ) ? this.keyHooks :
nickjillings@1289 4560 {};
nickjillings@1289 4561 }
nickjillings@1289 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nickjillings@1289 4563
nickjillings@1289 4564 event = new jQuery.Event( originalEvent );
nickjillings@1289 4565
nickjillings@1289 4566 i = copy.length;
nickjillings@1289 4567 while ( i-- ) {
nickjillings@1289 4568 prop = copy[ i ];
nickjillings@1289 4569 event[ prop ] = originalEvent[ prop ];
nickjillings@1289 4570 }
nickjillings@1289 4571
nickjillings@1289 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nickjillings@1289 4573 // All events should have a target; Cordova deviceready doesn't
nickjillings@1289 4574 if ( !event.target ) {
nickjillings@1289 4575 event.target = document;
nickjillings@1289 4576 }
nickjillings@1289 4577
nickjillings@1289 4578 // Support: Safari 6.0+, Chrome<28
nickjillings@1289 4579 // Target should not be a text node (#504, #13143)
nickjillings@1289 4580 if ( event.target.nodeType === 3 ) {
nickjillings@1289 4581 event.target = event.target.parentNode;
nickjillings@1289 4582 }
nickjillings@1289 4583
nickjillings@1289 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nickjillings@1289 4585 },
nickjillings@1289 4586
nickjillings@1289 4587 special: {
nickjillings@1289 4588 load: {
nickjillings@1289 4589 // Prevent triggered image.load events from bubbling to window.load
nickjillings@1289 4590 noBubble: true
nickjillings@1289 4591 },
nickjillings@1289 4592 focus: {
nickjillings@1289 4593 // Fire native event if possible so blur/focus sequence is correct
nickjillings@1289 4594 trigger: function() {
nickjillings@1289 4595 if ( this !== safeActiveElement() && this.focus ) {
nickjillings@1289 4596 this.focus();
nickjillings@1289 4597 return false;
nickjillings@1289 4598 }
nickjillings@1289 4599 },
nickjillings@1289 4600 delegateType: "focusin"
nickjillings@1289 4601 },
nickjillings@1289 4602 blur: {
nickjillings@1289 4603 trigger: function() {
nickjillings@1289 4604 if ( this === safeActiveElement() && this.blur ) {
nickjillings@1289 4605 this.blur();
nickjillings@1289 4606 return false;
nickjillings@1289 4607 }
nickjillings@1289 4608 },
nickjillings@1289 4609 delegateType: "focusout"
nickjillings@1289 4610 },
nickjillings@1289 4611 click: {
nickjillings@1289 4612 // For checkbox, fire native event so checked state will be right
nickjillings@1289 4613 trigger: function() {
nickjillings@1289 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nickjillings@1289 4615 this.click();
nickjillings@1289 4616 return false;
nickjillings@1289 4617 }
nickjillings@1289 4618 },
nickjillings@1289 4619
nickjillings@1289 4620 // For cross-browser consistency, don't fire native .click() on links
nickjillings@1289 4621 _default: function( event ) {
nickjillings@1289 4622 return jQuery.nodeName( event.target, "a" );
nickjillings@1289 4623 }
nickjillings@1289 4624 },
nickjillings@1289 4625
nickjillings@1289 4626 beforeunload: {
nickjillings@1289 4627 postDispatch: function( event ) {
nickjillings@1289 4628
nickjillings@1289 4629 // Support: Firefox 20+
nickjillings@1289 4630 // Firefox doesn't alert if the returnValue field is not set.
nickjillings@1289 4631 if ( event.result !== undefined && event.originalEvent ) {
nickjillings@1289 4632 event.originalEvent.returnValue = event.result;
nickjillings@1289 4633 }
nickjillings@1289 4634 }
nickjillings@1289 4635 }
nickjillings@1289 4636 },
nickjillings@1289 4637
nickjillings@1289 4638 simulate: function( type, elem, event, bubble ) {
nickjillings@1289 4639 // Piggyback on a donor event to simulate a different one.
nickjillings@1289 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nickjillings@1289 4641 // simulated event prevents default then we do the same on the donor.
nickjillings@1289 4642 var e = jQuery.extend(
nickjillings@1289 4643 new jQuery.Event(),
nickjillings@1289 4644 event,
nickjillings@1289 4645 {
nickjillings@1289 4646 type: type,
nickjillings@1289 4647 isSimulated: true,
nickjillings@1289 4648 originalEvent: {}
nickjillings@1289 4649 }
nickjillings@1289 4650 );
nickjillings@1289 4651 if ( bubble ) {
nickjillings@1289 4652 jQuery.event.trigger( e, null, elem );
nickjillings@1289 4653 } else {
nickjillings@1289 4654 jQuery.event.dispatch.call( elem, e );
nickjillings@1289 4655 }
nickjillings@1289 4656 if ( e.isDefaultPrevented() ) {
nickjillings@1289 4657 event.preventDefault();
nickjillings@1289 4658 }
nickjillings@1289 4659 }
nickjillings@1289 4660 };
nickjillings@1289 4661
nickjillings@1289 4662 jQuery.removeEvent = function( elem, type, handle ) {
nickjillings@1289 4663 if ( elem.removeEventListener ) {
nickjillings@1289 4664 elem.removeEventListener( type, handle, false );
nickjillings@1289 4665 }
nickjillings@1289 4666 };
nickjillings@1289 4667
nickjillings@1289 4668 jQuery.Event = function( src, props ) {
nickjillings@1289 4669 // Allow instantiation without the 'new' keyword
nickjillings@1289 4670 if ( !(this instanceof jQuery.Event) ) {
nickjillings@1289 4671 return new jQuery.Event( src, props );
nickjillings@1289 4672 }
nickjillings@1289 4673
nickjillings@1289 4674 // Event object
nickjillings@1289 4675 if ( src && src.type ) {
nickjillings@1289 4676 this.originalEvent = src;
nickjillings@1289 4677 this.type = src.type;
nickjillings@1289 4678
nickjillings@1289 4679 // Events bubbling up the document may have been marked as prevented
nickjillings@1289 4680 // by a handler lower down the tree; reflect the correct value.
nickjillings@1289 4681 this.isDefaultPrevented = src.defaultPrevented ||
nickjillings@1289 4682 src.defaultPrevented === undefined &&
nickjillings@1289 4683 // Support: Android<4.0
nickjillings@1289 4684 src.returnValue === false ?
nickjillings@1289 4685 returnTrue :
nickjillings@1289 4686 returnFalse;
nickjillings@1289 4687
nickjillings@1289 4688 // Event type
nickjillings@1289 4689 } else {
nickjillings@1289 4690 this.type = src;
nickjillings@1289 4691 }
nickjillings@1289 4692
nickjillings@1289 4693 // Put explicitly provided properties onto the event object
nickjillings@1289 4694 if ( props ) {
nickjillings@1289 4695 jQuery.extend( this, props );
nickjillings@1289 4696 }
nickjillings@1289 4697
nickjillings@1289 4698 // Create a timestamp if incoming event doesn't have one
nickjillings@1289 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nickjillings@1289 4700
nickjillings@1289 4701 // Mark it as fixed
nickjillings@1289 4702 this[ jQuery.expando ] = true;
nickjillings@1289 4703 };
nickjillings@1289 4704
nickjillings@1289 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nickjillings@1289 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nickjillings@1289 4707 jQuery.Event.prototype = {
nickjillings@1289 4708 isDefaultPrevented: returnFalse,
nickjillings@1289 4709 isPropagationStopped: returnFalse,
nickjillings@1289 4710 isImmediatePropagationStopped: returnFalse,
nickjillings@1289 4711
nickjillings@1289 4712 preventDefault: function() {
nickjillings@1289 4713 var e = this.originalEvent;
nickjillings@1289 4714
nickjillings@1289 4715 this.isDefaultPrevented = returnTrue;
nickjillings@1289 4716
nickjillings@1289 4717 if ( e && e.preventDefault ) {
nickjillings@1289 4718 e.preventDefault();
nickjillings@1289 4719 }
nickjillings@1289 4720 },
nickjillings@1289 4721 stopPropagation: function() {
nickjillings@1289 4722 var e = this.originalEvent;
nickjillings@1289 4723
nickjillings@1289 4724 this.isPropagationStopped = returnTrue;
nickjillings@1289 4725
nickjillings@1289 4726 if ( e && e.stopPropagation ) {
nickjillings@1289 4727 e.stopPropagation();
nickjillings@1289 4728 }
nickjillings@1289 4729 },
nickjillings@1289 4730 stopImmediatePropagation: function() {
nickjillings@1289 4731 var e = this.originalEvent;
nickjillings@1289 4732
nickjillings@1289 4733 this.isImmediatePropagationStopped = returnTrue;
nickjillings@1289 4734
nickjillings@1289 4735 if ( e && e.stopImmediatePropagation ) {
nickjillings@1289 4736 e.stopImmediatePropagation();
nickjillings@1289 4737 }
nickjillings@1289 4738
nickjillings@1289 4739 this.stopPropagation();
nickjillings@1289 4740 }
nickjillings@1289 4741 };
nickjillings@1289 4742
nickjillings@1289 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nickjillings@1289 4744 // Support: Chrome 15+
nickjillings@1289 4745 jQuery.each({
nickjillings@1289 4746 mouseenter: "mouseover",
nickjillings@1289 4747 mouseleave: "mouseout",
nickjillings@1289 4748 pointerenter: "pointerover",
nickjillings@1289 4749 pointerleave: "pointerout"
nickjillings@1289 4750 }, function( orig, fix ) {
nickjillings@1289 4751 jQuery.event.special[ orig ] = {
nickjillings@1289 4752 delegateType: fix,
nickjillings@1289 4753 bindType: fix,
nickjillings@1289 4754
nickjillings@1289 4755 handle: function( event ) {
nickjillings@1289 4756 var ret,
nickjillings@1289 4757 target = this,
nickjillings@1289 4758 related = event.relatedTarget,
nickjillings@1289 4759 handleObj = event.handleObj;
nickjillings@1289 4760
nickjillings@1289 4761 // For mousenter/leave call the handler if related is outside the target.
nickjillings@1289 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nickjillings@1289 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nickjillings@1289 4764 event.type = handleObj.origType;
nickjillings@1289 4765 ret = handleObj.handler.apply( this, arguments );
nickjillings@1289 4766 event.type = fix;
nickjillings@1289 4767 }
nickjillings@1289 4768 return ret;
nickjillings@1289 4769 }
nickjillings@1289 4770 };
nickjillings@1289 4771 });
nickjillings@1289 4772
nickjillings@1289 4773 // Support: Firefox, Chrome, Safari
nickjillings@1289 4774 // Create "bubbling" focus and blur events
nickjillings@1289 4775 if ( !support.focusinBubbles ) {
nickjillings@1289 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nickjillings@1289 4777
nickjillings@1289 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nickjillings@1289 4779 var handler = function( event ) {
nickjillings@1289 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nickjillings@1289 4781 };
nickjillings@1289 4782
nickjillings@1289 4783 jQuery.event.special[ fix ] = {
nickjillings@1289 4784 setup: function() {
nickjillings@1289 4785 var doc = this.ownerDocument || this,
nickjillings@1289 4786 attaches = data_priv.access( doc, fix );
nickjillings@1289 4787
nickjillings@1289 4788 if ( !attaches ) {
nickjillings@1289 4789 doc.addEventListener( orig, handler, true );
nickjillings@1289 4790 }
nickjillings@1289 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nickjillings@1289 4792 },
nickjillings@1289 4793 teardown: function() {
nickjillings@1289 4794 var doc = this.ownerDocument || this,
nickjillings@1289 4795 attaches = data_priv.access( doc, fix ) - 1;
nickjillings@1289 4796
nickjillings@1289 4797 if ( !attaches ) {
nickjillings@1289 4798 doc.removeEventListener( orig, handler, true );
nickjillings@1289 4799 data_priv.remove( doc, fix );
nickjillings@1289 4800
nickjillings@1289 4801 } else {
nickjillings@1289 4802 data_priv.access( doc, fix, attaches );
nickjillings@1289 4803 }
nickjillings@1289 4804 }
nickjillings@1289 4805 };
nickjillings@1289 4806 });
nickjillings@1289 4807 }
nickjillings@1289 4808
nickjillings@1289 4809 jQuery.fn.extend({
nickjillings@1289 4810
nickjillings@1289 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nickjillings@1289 4812 var origFn, type;
nickjillings@1289 4813
nickjillings@1289 4814 // Types can be a map of types/handlers
nickjillings@1289 4815 if ( typeof types === "object" ) {
nickjillings@1289 4816 // ( types-Object, selector, data )
nickjillings@1289 4817 if ( typeof selector !== "string" ) {
nickjillings@1289 4818 // ( types-Object, data )
nickjillings@1289 4819 data = data || selector;
nickjillings@1289 4820 selector = undefined;
nickjillings@1289 4821 }
nickjillings@1289 4822 for ( type in types ) {
nickjillings@1289 4823 this.on( type, selector, data, types[ type ], one );
nickjillings@1289 4824 }
nickjillings@1289 4825 return this;
nickjillings@1289 4826 }
nickjillings@1289 4827
nickjillings@1289 4828 if ( data == null && fn == null ) {
nickjillings@1289 4829 // ( types, fn )
nickjillings@1289 4830 fn = selector;
nickjillings@1289 4831 data = selector = undefined;
nickjillings@1289 4832 } else if ( fn == null ) {
nickjillings@1289 4833 if ( typeof selector === "string" ) {
nickjillings@1289 4834 // ( types, selector, fn )
nickjillings@1289 4835 fn = data;
nickjillings@1289 4836 data = undefined;
nickjillings@1289 4837 } else {
nickjillings@1289 4838 // ( types, data, fn )
nickjillings@1289 4839 fn = data;
nickjillings@1289 4840 data = selector;
nickjillings@1289 4841 selector = undefined;
nickjillings@1289 4842 }
nickjillings@1289 4843 }
nickjillings@1289 4844 if ( fn === false ) {
nickjillings@1289 4845 fn = returnFalse;
nickjillings@1289 4846 } else if ( !fn ) {
nickjillings@1289 4847 return this;
nickjillings@1289 4848 }
nickjillings@1289 4849
nickjillings@1289 4850 if ( one === 1 ) {
nickjillings@1289 4851 origFn = fn;
nickjillings@1289 4852 fn = function( event ) {
nickjillings@1289 4853 // Can use an empty set, since event contains the info
nickjillings@1289 4854 jQuery().off( event );
nickjillings@1289 4855 return origFn.apply( this, arguments );
nickjillings@1289 4856 };
nickjillings@1289 4857 // Use same guid so caller can remove using origFn
nickjillings@1289 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nickjillings@1289 4859 }
nickjillings@1289 4860 return this.each( function() {
nickjillings@1289 4861 jQuery.event.add( this, types, fn, data, selector );
nickjillings@1289 4862 });
nickjillings@1289 4863 },
nickjillings@1289 4864 one: function( types, selector, data, fn ) {
nickjillings@1289 4865 return this.on( types, selector, data, fn, 1 );
nickjillings@1289 4866 },
nickjillings@1289 4867 off: function( types, selector, fn ) {
nickjillings@1289 4868 var handleObj, type;
nickjillings@1289 4869 if ( types && types.preventDefault && types.handleObj ) {
nickjillings@1289 4870 // ( event ) dispatched jQuery.Event
nickjillings@1289 4871 handleObj = types.handleObj;
nickjillings@1289 4872 jQuery( types.delegateTarget ).off(
nickjillings@1289 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nickjillings@1289 4874 handleObj.selector,
nickjillings@1289 4875 handleObj.handler
nickjillings@1289 4876 );
nickjillings@1289 4877 return this;
nickjillings@1289 4878 }
nickjillings@1289 4879 if ( typeof types === "object" ) {
nickjillings@1289 4880 // ( types-object [, selector] )
nickjillings@1289 4881 for ( type in types ) {
nickjillings@1289 4882 this.off( type, selector, types[ type ] );
nickjillings@1289 4883 }
nickjillings@1289 4884 return this;
nickjillings@1289 4885 }
nickjillings@1289 4886 if ( selector === false || typeof selector === "function" ) {
nickjillings@1289 4887 // ( types [, fn] )
nickjillings@1289 4888 fn = selector;
nickjillings@1289 4889 selector = undefined;
nickjillings@1289 4890 }
nickjillings@1289 4891 if ( fn === false ) {
nickjillings@1289 4892 fn = returnFalse;
nickjillings@1289 4893 }
nickjillings@1289 4894 return this.each(function() {
nickjillings@1289 4895 jQuery.event.remove( this, types, fn, selector );
nickjillings@1289 4896 });
nickjillings@1289 4897 },
nickjillings@1289 4898
nickjillings@1289 4899 trigger: function( type, data ) {
nickjillings@1289 4900 return this.each(function() {
nickjillings@1289 4901 jQuery.event.trigger( type, data, this );
nickjillings@1289 4902 });
nickjillings@1289 4903 },
nickjillings@1289 4904 triggerHandler: function( type, data ) {
nickjillings@1289 4905 var elem = this[0];
nickjillings@1289 4906 if ( elem ) {
nickjillings@1289 4907 return jQuery.event.trigger( type, data, elem, true );
nickjillings@1289 4908 }
nickjillings@1289 4909 }
nickjillings@1289 4910 });
nickjillings@1289 4911
nickjillings@1289 4912
nickjillings@1289 4913 var
nickjillings@1289 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nickjillings@1289 4915 rtagName = /<([\w:]+)/,
nickjillings@1289 4916 rhtml = /<|&#?\w+;/,
nickjillings@1289 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nickjillings@1289 4918 // checked="checked" or checked
nickjillings@1289 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nickjillings@1289 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nickjillings@1289 4921 rscriptTypeMasked = /^true\/(.*)/,
nickjillings@1289 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nickjillings@1289 4923
nickjillings@1289 4924 // We have to close these tags to support XHTML (#13200)
nickjillings@1289 4925 wrapMap = {
nickjillings@1289 4926
nickjillings@1289 4927 // Support: IE9
nickjillings@1289 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nickjillings@1289 4929
nickjillings@1289 4930 thead: [ 1, "<table>", "</table>" ],
nickjillings@1289 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nickjillings@1289 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nickjillings@1289 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nickjillings@1289 4934
nickjillings@1289 4935 _default: [ 0, "", "" ]
nickjillings@1289 4936 };
nickjillings@1289 4937
nickjillings@1289 4938 // Support: IE9
nickjillings@1289 4939 wrapMap.optgroup = wrapMap.option;
nickjillings@1289 4940
nickjillings@1289 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nickjillings@1289 4942 wrapMap.th = wrapMap.td;
nickjillings@1289 4943
nickjillings@1289 4944 // Support: 1.x compatibility
nickjillings@1289 4945 // Manipulating tables requires a tbody
nickjillings@1289 4946 function manipulationTarget( elem, content ) {
nickjillings@1289 4947 return jQuery.nodeName( elem, "table" ) &&
nickjillings@1289 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nickjillings@1289 4949
nickjillings@1289 4950 elem.getElementsByTagName("tbody")[0] ||
nickjillings@1289 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nickjillings@1289 4952 elem;
nickjillings@1289 4953 }
nickjillings@1289 4954
nickjillings@1289 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nickjillings@1289 4956 function disableScript( elem ) {
nickjillings@1289 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nickjillings@1289 4958 return elem;
nickjillings@1289 4959 }
nickjillings@1289 4960 function restoreScript( elem ) {
nickjillings@1289 4961 var match = rscriptTypeMasked.exec( elem.type );
nickjillings@1289 4962
nickjillings@1289 4963 if ( match ) {
nickjillings@1289 4964 elem.type = match[ 1 ];
nickjillings@1289 4965 } else {
nickjillings@1289 4966 elem.removeAttribute("type");
nickjillings@1289 4967 }
nickjillings@1289 4968
nickjillings@1289 4969 return elem;
nickjillings@1289 4970 }
nickjillings@1289 4971
nickjillings@1289 4972 // Mark scripts as having already been evaluated
nickjillings@1289 4973 function setGlobalEval( elems, refElements ) {
nickjillings@1289 4974 var i = 0,
nickjillings@1289 4975 l = elems.length;
nickjillings@1289 4976
nickjillings@1289 4977 for ( ; i < l; i++ ) {
nickjillings@1289 4978 data_priv.set(
nickjillings@1289 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nickjillings@1289 4980 );
nickjillings@1289 4981 }
nickjillings@1289 4982 }
nickjillings@1289 4983
nickjillings@1289 4984 function cloneCopyEvent( src, dest ) {
nickjillings@1289 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nickjillings@1289 4986
nickjillings@1289 4987 if ( dest.nodeType !== 1 ) {
nickjillings@1289 4988 return;
nickjillings@1289 4989 }
nickjillings@1289 4990
nickjillings@1289 4991 // 1. Copy private data: events, handlers, etc.
nickjillings@1289 4992 if ( data_priv.hasData( src ) ) {
nickjillings@1289 4993 pdataOld = data_priv.access( src );
nickjillings@1289 4994 pdataCur = data_priv.set( dest, pdataOld );
nickjillings@1289 4995 events = pdataOld.events;
nickjillings@1289 4996
nickjillings@1289 4997 if ( events ) {
nickjillings@1289 4998 delete pdataCur.handle;
nickjillings@1289 4999 pdataCur.events = {};
nickjillings@1289 5000
nickjillings@1289 5001 for ( type in events ) {
nickjillings@1289 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nickjillings@1289 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nickjillings@1289 5004 }
nickjillings@1289 5005 }
nickjillings@1289 5006 }
nickjillings@1289 5007 }
nickjillings@1289 5008
nickjillings@1289 5009 // 2. Copy user data
nickjillings@1289 5010 if ( data_user.hasData( src ) ) {
nickjillings@1289 5011 udataOld = data_user.access( src );
nickjillings@1289 5012 udataCur = jQuery.extend( {}, udataOld );
nickjillings@1289 5013
nickjillings@1289 5014 data_user.set( dest, udataCur );
nickjillings@1289 5015 }
nickjillings@1289 5016 }
nickjillings@1289 5017
nickjillings@1289 5018 function getAll( context, tag ) {
nickjillings@1289 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nickjillings@1289 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nickjillings@1289 5021 [];
nickjillings@1289 5022
nickjillings@1289 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nickjillings@1289 5024 jQuery.merge( [ context ], ret ) :
nickjillings@1289 5025 ret;
nickjillings@1289 5026 }
nickjillings@1289 5027
nickjillings@1289 5028 // Fix IE bugs, see support tests
nickjillings@1289 5029 function fixInput( src, dest ) {
nickjillings@1289 5030 var nodeName = dest.nodeName.toLowerCase();
nickjillings@1289 5031
nickjillings@1289 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nickjillings@1289 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nickjillings@1289 5034 dest.checked = src.checked;
nickjillings@1289 5035
nickjillings@1289 5036 // Fails to return the selected option to the default selected state when cloning options
nickjillings@1289 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nickjillings@1289 5038 dest.defaultValue = src.defaultValue;
nickjillings@1289 5039 }
nickjillings@1289 5040 }
nickjillings@1289 5041
nickjillings@1289 5042 jQuery.extend({
nickjillings@1289 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nickjillings@1289 5044 var i, l, srcElements, destElements,
nickjillings@1289 5045 clone = elem.cloneNode( true ),
nickjillings@1289 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1289 5047
nickjillings@1289 5048 // Fix IE cloning issues
nickjillings@1289 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nickjillings@1289 5050 !jQuery.isXMLDoc( elem ) ) {
nickjillings@1289 5051
nickjillings@1289 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nickjillings@1289 5053 destElements = getAll( clone );
nickjillings@1289 5054 srcElements = getAll( elem );
nickjillings@1289 5055
nickjillings@1289 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1289 5057 fixInput( srcElements[ i ], destElements[ i ] );
nickjillings@1289 5058 }
nickjillings@1289 5059 }
nickjillings@1289 5060
nickjillings@1289 5061 // Copy the events from the original to the clone
nickjillings@1289 5062 if ( dataAndEvents ) {
nickjillings@1289 5063 if ( deepDataAndEvents ) {
nickjillings@1289 5064 srcElements = srcElements || getAll( elem );
nickjillings@1289 5065 destElements = destElements || getAll( clone );
nickjillings@1289 5066
nickjillings@1289 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1289 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nickjillings@1289 5069 }
nickjillings@1289 5070 } else {
nickjillings@1289 5071 cloneCopyEvent( elem, clone );
nickjillings@1289 5072 }
nickjillings@1289 5073 }
nickjillings@1289 5074
nickjillings@1289 5075 // Preserve script evaluation history
nickjillings@1289 5076 destElements = getAll( clone, "script" );
nickjillings@1289 5077 if ( destElements.length > 0 ) {
nickjillings@1289 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nickjillings@1289 5079 }
nickjillings@1289 5080
nickjillings@1289 5081 // Return the cloned set
nickjillings@1289 5082 return clone;
nickjillings@1289 5083 },
nickjillings@1289 5084
nickjillings@1289 5085 buildFragment: function( elems, context, scripts, selection ) {
nickjillings@1289 5086 var elem, tmp, tag, wrap, contains, j,
nickjillings@1289 5087 fragment = context.createDocumentFragment(),
nickjillings@1289 5088 nodes = [],
nickjillings@1289 5089 i = 0,
nickjillings@1289 5090 l = elems.length;
nickjillings@1289 5091
nickjillings@1289 5092 for ( ; i < l; i++ ) {
nickjillings@1289 5093 elem = elems[ i ];
nickjillings@1289 5094
nickjillings@1289 5095 if ( elem || elem === 0 ) {
nickjillings@1289 5096
nickjillings@1289 5097 // Add nodes directly
nickjillings@1289 5098 if ( jQuery.type( elem ) === "object" ) {
nickjillings@1289 5099 // Support: QtWebKit, PhantomJS
nickjillings@1289 5100 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1289 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nickjillings@1289 5102
nickjillings@1289 5103 // Convert non-html into a text node
nickjillings@1289 5104 } else if ( !rhtml.test( elem ) ) {
nickjillings@1289 5105 nodes.push( context.createTextNode( elem ) );
nickjillings@1289 5106
nickjillings@1289 5107 // Convert html into DOM nodes
nickjillings@1289 5108 } else {
nickjillings@1289 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nickjillings@1289 5110
nickjillings@1289 5111 // Deserialize a standard representation
nickjillings@1289 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nickjillings@1289 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nickjillings@1289 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nickjillings@1289 5115
nickjillings@1289 5116 // Descend through wrappers to the right content
nickjillings@1289 5117 j = wrap[ 0 ];
nickjillings@1289 5118 while ( j-- ) {
nickjillings@1289 5119 tmp = tmp.lastChild;
nickjillings@1289 5120 }
nickjillings@1289 5121
nickjillings@1289 5122 // Support: QtWebKit, PhantomJS
nickjillings@1289 5123 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1289 5124 jQuery.merge( nodes, tmp.childNodes );
nickjillings@1289 5125
nickjillings@1289 5126 // Remember the top-level container
nickjillings@1289 5127 tmp = fragment.firstChild;
nickjillings@1289 5128
nickjillings@1289 5129 // Ensure the created nodes are orphaned (#12392)
nickjillings@1289 5130 tmp.textContent = "";
nickjillings@1289 5131 }
nickjillings@1289 5132 }
nickjillings@1289 5133 }
nickjillings@1289 5134
nickjillings@1289 5135 // Remove wrapper from fragment
nickjillings@1289 5136 fragment.textContent = "";
nickjillings@1289 5137
nickjillings@1289 5138 i = 0;
nickjillings@1289 5139 while ( (elem = nodes[ i++ ]) ) {
nickjillings@1289 5140
nickjillings@1289 5141 // #4087 - If origin and destination elements are the same, and this is
nickjillings@1289 5142 // that element, do not do anything
nickjillings@1289 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nickjillings@1289 5144 continue;
nickjillings@1289 5145 }
nickjillings@1289 5146
nickjillings@1289 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1289 5148
nickjillings@1289 5149 // Append to fragment
nickjillings@1289 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nickjillings@1289 5151
nickjillings@1289 5152 // Preserve script evaluation history
nickjillings@1289 5153 if ( contains ) {
nickjillings@1289 5154 setGlobalEval( tmp );
nickjillings@1289 5155 }
nickjillings@1289 5156
nickjillings@1289 5157 // Capture executables
nickjillings@1289 5158 if ( scripts ) {
nickjillings@1289 5159 j = 0;
nickjillings@1289 5160 while ( (elem = tmp[ j++ ]) ) {
nickjillings@1289 5161 if ( rscriptType.test( elem.type || "" ) ) {
nickjillings@1289 5162 scripts.push( elem );
nickjillings@1289 5163 }
nickjillings@1289 5164 }
nickjillings@1289 5165 }
nickjillings@1289 5166 }
nickjillings@1289 5167
nickjillings@1289 5168 return fragment;
nickjillings@1289 5169 },
nickjillings@1289 5170
nickjillings@1289 5171 cleanData: function( elems ) {
nickjillings@1289 5172 var data, elem, type, key,
nickjillings@1289 5173 special = jQuery.event.special,
nickjillings@1289 5174 i = 0;
nickjillings@1289 5175
nickjillings@1289 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nickjillings@1289 5177 if ( jQuery.acceptData( elem ) ) {
nickjillings@1289 5178 key = elem[ data_priv.expando ];
nickjillings@1289 5179
nickjillings@1289 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nickjillings@1289 5181 if ( data.events ) {
nickjillings@1289 5182 for ( type in data.events ) {
nickjillings@1289 5183 if ( special[ type ] ) {
nickjillings@1289 5184 jQuery.event.remove( elem, type );
nickjillings@1289 5185
nickjillings@1289 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nickjillings@1289 5187 } else {
nickjillings@1289 5188 jQuery.removeEvent( elem, type, data.handle );
nickjillings@1289 5189 }
nickjillings@1289 5190 }
nickjillings@1289 5191 }
nickjillings@1289 5192 if ( data_priv.cache[ key ] ) {
nickjillings@1289 5193 // Discard any remaining `private` data
nickjillings@1289 5194 delete data_priv.cache[ key ];
nickjillings@1289 5195 }
nickjillings@1289 5196 }
nickjillings@1289 5197 }
nickjillings@1289 5198 // Discard any remaining `user` data
nickjillings@1289 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nickjillings@1289 5200 }
nickjillings@1289 5201 }
nickjillings@1289 5202 });
nickjillings@1289 5203
nickjillings@1289 5204 jQuery.fn.extend({
nickjillings@1289 5205 text: function( value ) {
nickjillings@1289 5206 return access( this, function( value ) {
nickjillings@1289 5207 return value === undefined ?
nickjillings@1289 5208 jQuery.text( this ) :
nickjillings@1289 5209 this.empty().each(function() {
nickjillings@1289 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1289 5211 this.textContent = value;
nickjillings@1289 5212 }
nickjillings@1289 5213 });
nickjillings@1289 5214 }, null, value, arguments.length );
nickjillings@1289 5215 },
nickjillings@1289 5216
nickjillings@1289 5217 append: function() {
nickjillings@1289 5218 return this.domManip( arguments, function( elem ) {
nickjillings@1289 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1289 5220 var target = manipulationTarget( this, elem );
nickjillings@1289 5221 target.appendChild( elem );
nickjillings@1289 5222 }
nickjillings@1289 5223 });
nickjillings@1289 5224 },
nickjillings@1289 5225
nickjillings@1289 5226 prepend: function() {
nickjillings@1289 5227 return this.domManip( arguments, function( elem ) {
nickjillings@1289 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1289 5229 var target = manipulationTarget( this, elem );
nickjillings@1289 5230 target.insertBefore( elem, target.firstChild );
nickjillings@1289 5231 }
nickjillings@1289 5232 });
nickjillings@1289 5233 },
nickjillings@1289 5234
nickjillings@1289 5235 before: function() {
nickjillings@1289 5236 return this.domManip( arguments, function( elem ) {
nickjillings@1289 5237 if ( this.parentNode ) {
nickjillings@1289 5238 this.parentNode.insertBefore( elem, this );
nickjillings@1289 5239 }
nickjillings@1289 5240 });
nickjillings@1289 5241 },
nickjillings@1289 5242
nickjillings@1289 5243 after: function() {
nickjillings@1289 5244 return this.domManip( arguments, function( elem ) {
nickjillings@1289 5245 if ( this.parentNode ) {
nickjillings@1289 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nickjillings@1289 5247 }
nickjillings@1289 5248 });
nickjillings@1289 5249 },
nickjillings@1289 5250
nickjillings@1289 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nickjillings@1289 5252 var elem,
nickjillings@1289 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nickjillings@1289 5254 i = 0;
nickjillings@1289 5255
nickjillings@1289 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nickjillings@1289 5257 if ( !keepData && elem.nodeType === 1 ) {
nickjillings@1289 5258 jQuery.cleanData( getAll( elem ) );
nickjillings@1289 5259 }
nickjillings@1289 5260
nickjillings@1289 5261 if ( elem.parentNode ) {
nickjillings@1289 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1289 5263 setGlobalEval( getAll( elem, "script" ) );
nickjillings@1289 5264 }
nickjillings@1289 5265 elem.parentNode.removeChild( elem );
nickjillings@1289 5266 }
nickjillings@1289 5267 }
nickjillings@1289 5268
nickjillings@1289 5269 return this;
nickjillings@1289 5270 },
nickjillings@1289 5271
nickjillings@1289 5272 empty: function() {
nickjillings@1289 5273 var elem,
nickjillings@1289 5274 i = 0;
nickjillings@1289 5275
nickjillings@1289 5276 for ( ; (elem = this[i]) != null; i++ ) {
nickjillings@1289 5277 if ( elem.nodeType === 1 ) {
nickjillings@1289 5278
nickjillings@1289 5279 // Prevent memory leaks
nickjillings@1289 5280 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1289 5281
nickjillings@1289 5282 // Remove any remaining nodes
nickjillings@1289 5283 elem.textContent = "";
nickjillings@1289 5284 }
nickjillings@1289 5285 }
nickjillings@1289 5286
nickjillings@1289 5287 return this;
nickjillings@1289 5288 },
nickjillings@1289 5289
nickjillings@1289 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nickjillings@1289 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nickjillings@1289 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nickjillings@1289 5293
nickjillings@1289 5294 return this.map(function() {
nickjillings@1289 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nickjillings@1289 5296 });
nickjillings@1289 5297 },
nickjillings@1289 5298
nickjillings@1289 5299 html: function( value ) {
nickjillings@1289 5300 return access( this, function( value ) {
nickjillings@1289 5301 var elem = this[ 0 ] || {},
nickjillings@1289 5302 i = 0,
nickjillings@1289 5303 l = this.length;
nickjillings@1289 5304
nickjillings@1289 5305 if ( value === undefined && elem.nodeType === 1 ) {
nickjillings@1289 5306 return elem.innerHTML;
nickjillings@1289 5307 }
nickjillings@1289 5308
nickjillings@1289 5309 // See if we can take a shortcut and just use innerHTML
nickjillings@1289 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nickjillings@1289 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nickjillings@1289 5312
nickjillings@1289 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nickjillings@1289 5314
nickjillings@1289 5315 try {
nickjillings@1289 5316 for ( ; i < l; i++ ) {
nickjillings@1289 5317 elem = this[ i ] || {};
nickjillings@1289 5318
nickjillings@1289 5319 // Remove element nodes and prevent memory leaks
nickjillings@1289 5320 if ( elem.nodeType === 1 ) {
nickjillings@1289 5321 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1289 5322 elem.innerHTML = value;
nickjillings@1289 5323 }
nickjillings@1289 5324 }
nickjillings@1289 5325
nickjillings@1289 5326 elem = 0;
nickjillings@1289 5327
nickjillings@1289 5328 // If using innerHTML throws an exception, use the fallback method
nickjillings@1289 5329 } catch( e ) {}
nickjillings@1289 5330 }
nickjillings@1289 5331
nickjillings@1289 5332 if ( elem ) {
nickjillings@1289 5333 this.empty().append( value );
nickjillings@1289 5334 }
nickjillings@1289 5335 }, null, value, arguments.length );
nickjillings@1289 5336 },
nickjillings@1289 5337
nickjillings@1289 5338 replaceWith: function() {
nickjillings@1289 5339 var arg = arguments[ 0 ];
nickjillings@1289 5340
nickjillings@1289 5341 // Make the changes, replacing each context element with the new content
nickjillings@1289 5342 this.domManip( arguments, function( elem ) {
nickjillings@1289 5343 arg = this.parentNode;
nickjillings@1289 5344
nickjillings@1289 5345 jQuery.cleanData( getAll( this ) );
nickjillings@1289 5346
nickjillings@1289 5347 if ( arg ) {
nickjillings@1289 5348 arg.replaceChild( elem, this );
nickjillings@1289 5349 }
nickjillings@1289 5350 });
nickjillings@1289 5351
nickjillings@1289 5352 // Force removal if there was no new content (e.g., from empty arguments)
nickjillings@1289 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nickjillings@1289 5354 },
nickjillings@1289 5355
nickjillings@1289 5356 detach: function( selector ) {
nickjillings@1289 5357 return this.remove( selector, true );
nickjillings@1289 5358 },
nickjillings@1289 5359
nickjillings@1289 5360 domManip: function( args, callback ) {
nickjillings@1289 5361
nickjillings@1289 5362 // Flatten any nested arrays
nickjillings@1289 5363 args = concat.apply( [], args );
nickjillings@1289 5364
nickjillings@1289 5365 var fragment, first, scripts, hasScripts, node, doc,
nickjillings@1289 5366 i = 0,
nickjillings@1289 5367 l = this.length,
nickjillings@1289 5368 set = this,
nickjillings@1289 5369 iNoClone = l - 1,
nickjillings@1289 5370 value = args[ 0 ],
nickjillings@1289 5371 isFunction = jQuery.isFunction( value );
nickjillings@1289 5372
nickjillings@1289 5373 // We can't cloneNode fragments that contain checked, in WebKit
nickjillings@1289 5374 if ( isFunction ||
nickjillings@1289 5375 ( l > 1 && typeof value === "string" &&
nickjillings@1289 5376 !support.checkClone && rchecked.test( value ) ) ) {
nickjillings@1289 5377 return this.each(function( index ) {
nickjillings@1289 5378 var self = set.eq( index );
nickjillings@1289 5379 if ( isFunction ) {
nickjillings@1289 5380 args[ 0 ] = value.call( this, index, self.html() );
nickjillings@1289 5381 }
nickjillings@1289 5382 self.domManip( args, callback );
nickjillings@1289 5383 });
nickjillings@1289 5384 }
nickjillings@1289 5385
nickjillings@1289 5386 if ( l ) {
nickjillings@1289 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nickjillings@1289 5388 first = fragment.firstChild;
nickjillings@1289 5389
nickjillings@1289 5390 if ( fragment.childNodes.length === 1 ) {
nickjillings@1289 5391 fragment = first;
nickjillings@1289 5392 }
nickjillings@1289 5393
nickjillings@1289 5394 if ( first ) {
nickjillings@1289 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nickjillings@1289 5396 hasScripts = scripts.length;
nickjillings@1289 5397
nickjillings@1289 5398 // Use the original fragment for the last item instead of the first because it can end up
nickjillings@1289 5399 // being emptied incorrectly in certain situations (#8070).
nickjillings@1289 5400 for ( ; i < l; i++ ) {
nickjillings@1289 5401 node = fragment;
nickjillings@1289 5402
nickjillings@1289 5403 if ( i !== iNoClone ) {
nickjillings@1289 5404 node = jQuery.clone( node, true, true );
nickjillings@1289 5405
nickjillings@1289 5406 // Keep references to cloned scripts for later restoration
nickjillings@1289 5407 if ( hasScripts ) {
nickjillings@1289 5408 // Support: QtWebKit
nickjillings@1289 5409 // jQuery.merge because push.apply(_, arraylike) throws
nickjillings@1289 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nickjillings@1289 5411 }
nickjillings@1289 5412 }
nickjillings@1289 5413
nickjillings@1289 5414 callback.call( this[ i ], node, i );
nickjillings@1289 5415 }
nickjillings@1289 5416
nickjillings@1289 5417 if ( hasScripts ) {
nickjillings@1289 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nickjillings@1289 5419
nickjillings@1289 5420 // Reenable scripts
nickjillings@1289 5421 jQuery.map( scripts, restoreScript );
nickjillings@1289 5422
nickjillings@1289 5423 // Evaluate executable scripts on first document insertion
nickjillings@1289 5424 for ( i = 0; i < hasScripts; i++ ) {
nickjillings@1289 5425 node = scripts[ i ];
nickjillings@1289 5426 if ( rscriptType.test( node.type || "" ) &&
nickjillings@1289 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nickjillings@1289 5428
nickjillings@1289 5429 if ( node.src ) {
nickjillings@1289 5430 // Optional AJAX dependency, but won't run scripts if not present
nickjillings@1289 5431 if ( jQuery._evalUrl ) {
nickjillings@1289 5432 jQuery._evalUrl( node.src );
nickjillings@1289 5433 }
nickjillings@1289 5434 } else {
nickjillings@1289 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nickjillings@1289 5436 }
nickjillings@1289 5437 }
nickjillings@1289 5438 }
nickjillings@1289 5439 }
nickjillings@1289 5440 }
nickjillings@1289 5441 }
nickjillings@1289 5442
nickjillings@1289 5443 return this;
nickjillings@1289 5444 }
nickjillings@1289 5445 });
nickjillings@1289 5446
nickjillings@1289 5447 jQuery.each({
nickjillings@1289 5448 appendTo: "append",
nickjillings@1289 5449 prependTo: "prepend",
nickjillings@1289 5450 insertBefore: "before",
nickjillings@1289 5451 insertAfter: "after",
nickjillings@1289 5452 replaceAll: "replaceWith"
nickjillings@1289 5453 }, function( name, original ) {
nickjillings@1289 5454 jQuery.fn[ name ] = function( selector ) {
nickjillings@1289 5455 var elems,
nickjillings@1289 5456 ret = [],
nickjillings@1289 5457 insert = jQuery( selector ),
nickjillings@1289 5458 last = insert.length - 1,
nickjillings@1289 5459 i = 0;
nickjillings@1289 5460
nickjillings@1289 5461 for ( ; i <= last; i++ ) {
nickjillings@1289 5462 elems = i === last ? this : this.clone( true );
nickjillings@1289 5463 jQuery( insert[ i ] )[ original ]( elems );
nickjillings@1289 5464
nickjillings@1289 5465 // Support: QtWebKit
nickjillings@1289 5466 // .get() because push.apply(_, arraylike) throws
nickjillings@1289 5467 push.apply( ret, elems.get() );
nickjillings@1289 5468 }
nickjillings@1289 5469
nickjillings@1289 5470 return this.pushStack( ret );
nickjillings@1289 5471 };
nickjillings@1289 5472 });
nickjillings@1289 5473
nickjillings@1289 5474
nickjillings@1289 5475 var iframe,
nickjillings@1289 5476 elemdisplay = {};
nickjillings@1289 5477
nickjillings@1289 5478 /**
nickjillings@1289 5479 * Retrieve the actual display of a element
nickjillings@1289 5480 * @param {String} name nodeName of the element
nickjillings@1289 5481 * @param {Object} doc Document object
nickjillings@1289 5482 */
nickjillings@1289 5483 // Called only from within defaultDisplay
nickjillings@1289 5484 function actualDisplay( name, doc ) {
nickjillings@1289 5485 var style,
nickjillings@1289 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nickjillings@1289 5487
nickjillings@1289 5488 // getDefaultComputedStyle might be reliably used only on attached element
nickjillings@1289 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nickjillings@1289 5490
nickjillings@1289 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nickjillings@1289 5492 // since it was removed from specification and supported only in FF
nickjillings@1289 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nickjillings@1289 5494
nickjillings@1289 5495 // We don't have any data stored on the element,
nickjillings@1289 5496 // so use "detach" method as fast way to get rid of the element
nickjillings@1289 5497 elem.detach();
nickjillings@1289 5498
nickjillings@1289 5499 return display;
nickjillings@1289 5500 }
nickjillings@1289 5501
nickjillings@1289 5502 /**
nickjillings@1289 5503 * Try to determine the default display value of an element
nickjillings@1289 5504 * @param {String} nodeName
nickjillings@1289 5505 */
nickjillings@1289 5506 function defaultDisplay( nodeName ) {
nickjillings@1289 5507 var doc = document,
nickjillings@1289 5508 display = elemdisplay[ nodeName ];
nickjillings@1289 5509
nickjillings@1289 5510 if ( !display ) {
nickjillings@1289 5511 display = actualDisplay( nodeName, doc );
nickjillings@1289 5512
nickjillings@1289 5513 // If the simple way fails, read from inside an iframe
nickjillings@1289 5514 if ( display === "none" || !display ) {
nickjillings@1289 5515
nickjillings@1289 5516 // Use the already-created iframe if possible
nickjillings@1289 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nickjillings@1289 5518
nickjillings@1289 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nickjillings@1289 5520 doc = iframe[ 0 ].contentDocument;
nickjillings@1289 5521
nickjillings@1289 5522 // Support: IE
nickjillings@1289 5523 doc.write();
nickjillings@1289 5524 doc.close();
nickjillings@1289 5525
nickjillings@1289 5526 display = actualDisplay( nodeName, doc );
nickjillings@1289 5527 iframe.detach();
nickjillings@1289 5528 }
nickjillings@1289 5529
nickjillings@1289 5530 // Store the correct default display
nickjillings@1289 5531 elemdisplay[ nodeName ] = display;
nickjillings@1289 5532 }
nickjillings@1289 5533
nickjillings@1289 5534 return display;
nickjillings@1289 5535 }
nickjillings@1289 5536 var rmargin = (/^margin/);
nickjillings@1289 5537
nickjillings@1289 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nickjillings@1289 5539
nickjillings@1289 5540 var getStyles = function( elem ) {
nickjillings@1289 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nickjillings@1289 5542 // IE throws on elements created in popups
nickjillings@1289 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nickjillings@1289 5544 if ( elem.ownerDocument.defaultView.opener ) {
nickjillings@1289 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nickjillings@1289 5546 }
nickjillings@1289 5547
nickjillings@1289 5548 return window.getComputedStyle( elem, null );
nickjillings@1289 5549 };
nickjillings@1289 5550
nickjillings@1289 5551
nickjillings@1289 5552
nickjillings@1289 5553 function curCSS( elem, name, computed ) {
nickjillings@1289 5554 var width, minWidth, maxWidth, ret,
nickjillings@1289 5555 style = elem.style;
nickjillings@1289 5556
nickjillings@1289 5557 computed = computed || getStyles( elem );
nickjillings@1289 5558
nickjillings@1289 5559 // Support: IE9
nickjillings@1289 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nickjillings@1289 5561 if ( computed ) {
nickjillings@1289 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nickjillings@1289 5563 }
nickjillings@1289 5564
nickjillings@1289 5565 if ( computed ) {
nickjillings@1289 5566
nickjillings@1289 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1289 5568 ret = jQuery.style( elem, name );
nickjillings@1289 5569 }
nickjillings@1289 5570
nickjillings@1289 5571 // Support: iOS < 6
nickjillings@1289 5572 // A tribute to the "awesome hack by Dean Edwards"
nickjillings@1289 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nickjillings@1289 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nickjillings@1289 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nickjillings@1289 5576
nickjillings@1289 5577 // Remember the original values
nickjillings@1289 5578 width = style.width;
nickjillings@1289 5579 minWidth = style.minWidth;
nickjillings@1289 5580 maxWidth = style.maxWidth;
nickjillings@1289 5581
nickjillings@1289 5582 // Put in the new values to get a computed value out
nickjillings@1289 5583 style.minWidth = style.maxWidth = style.width = ret;
nickjillings@1289 5584 ret = computed.width;
nickjillings@1289 5585
nickjillings@1289 5586 // Revert the changed values
nickjillings@1289 5587 style.width = width;
nickjillings@1289 5588 style.minWidth = minWidth;
nickjillings@1289 5589 style.maxWidth = maxWidth;
nickjillings@1289 5590 }
nickjillings@1289 5591 }
nickjillings@1289 5592
nickjillings@1289 5593 return ret !== undefined ?
nickjillings@1289 5594 // Support: IE
nickjillings@1289 5595 // IE returns zIndex value as an integer.
nickjillings@1289 5596 ret + "" :
nickjillings@1289 5597 ret;
nickjillings@1289 5598 }
nickjillings@1289 5599
nickjillings@1289 5600
nickjillings@1289 5601 function addGetHookIf( conditionFn, hookFn ) {
nickjillings@1289 5602 // Define the hook, we'll check on the first run if it's really needed.
nickjillings@1289 5603 return {
nickjillings@1289 5604 get: function() {
nickjillings@1289 5605 if ( conditionFn() ) {
nickjillings@1289 5606 // Hook not needed (or it's not possible to use it due
nickjillings@1289 5607 // to missing dependency), remove it.
nickjillings@1289 5608 delete this.get;
nickjillings@1289 5609 return;
nickjillings@1289 5610 }
nickjillings@1289 5611
nickjillings@1289 5612 // Hook needed; redefine it so that the support test is not executed again.
nickjillings@1289 5613 return (this.get = hookFn).apply( this, arguments );
nickjillings@1289 5614 }
nickjillings@1289 5615 };
nickjillings@1289 5616 }
nickjillings@1289 5617
nickjillings@1289 5618
nickjillings@1289 5619 (function() {
nickjillings@1289 5620 var pixelPositionVal, boxSizingReliableVal,
nickjillings@1289 5621 docElem = document.documentElement,
nickjillings@1289 5622 container = document.createElement( "div" ),
nickjillings@1289 5623 div = document.createElement( "div" );
nickjillings@1289 5624
nickjillings@1289 5625 if ( !div.style ) {
nickjillings@1289 5626 return;
nickjillings@1289 5627 }
nickjillings@1289 5628
nickjillings@1289 5629 // Support: IE9-11+
nickjillings@1289 5630 // Style of cloned element affects source element cloned (#8908)
nickjillings@1289 5631 div.style.backgroundClip = "content-box";
nickjillings@1289 5632 div.cloneNode( true ).style.backgroundClip = "";
nickjillings@1289 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nickjillings@1289 5634
nickjillings@1289 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nickjillings@1289 5636 "position:absolute";
nickjillings@1289 5637 container.appendChild( div );
nickjillings@1289 5638
nickjillings@1289 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nickjillings@1289 5640 // so they're executed at the same time to save the second computation.
nickjillings@1289 5641 function computePixelPositionAndBoxSizingReliable() {
nickjillings@1289 5642 div.style.cssText =
nickjillings@1289 5643 // Support: Firefox<29, Android 2.3
nickjillings@1289 5644 // Vendor-prefix box-sizing
nickjillings@1289 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nickjillings@1289 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nickjillings@1289 5647 "border:1px;padding:1px;width:4px;position:absolute";
nickjillings@1289 5648 div.innerHTML = "";
nickjillings@1289 5649 docElem.appendChild( container );
nickjillings@1289 5650
nickjillings@1289 5651 var divStyle = window.getComputedStyle( div, null );
nickjillings@1289 5652 pixelPositionVal = divStyle.top !== "1%";
nickjillings@1289 5653 boxSizingReliableVal = divStyle.width === "4px";
nickjillings@1289 5654
nickjillings@1289 5655 docElem.removeChild( container );
nickjillings@1289 5656 }
nickjillings@1289 5657
nickjillings@1289 5658 // Support: node.js jsdom
nickjillings@1289 5659 // Don't assume that getComputedStyle is a property of the global object
nickjillings@1289 5660 if ( window.getComputedStyle ) {
nickjillings@1289 5661 jQuery.extend( support, {
nickjillings@1289 5662 pixelPosition: function() {
nickjillings@1289 5663
nickjillings@1289 5664 // This test is executed only once but we still do memoizing
nickjillings@1289 5665 // since we can use the boxSizingReliable pre-computing.
nickjillings@1289 5666 // No need to check if the test was already performed, though.
nickjillings@1289 5667 computePixelPositionAndBoxSizingReliable();
nickjillings@1289 5668 return pixelPositionVal;
nickjillings@1289 5669 },
nickjillings@1289 5670 boxSizingReliable: function() {
nickjillings@1289 5671 if ( boxSizingReliableVal == null ) {
nickjillings@1289 5672 computePixelPositionAndBoxSizingReliable();
nickjillings@1289 5673 }
nickjillings@1289 5674 return boxSizingReliableVal;
nickjillings@1289 5675 },
nickjillings@1289 5676 reliableMarginRight: function() {
nickjillings@1289 5677
nickjillings@1289 5678 // Support: Android 2.3
nickjillings@1289 5679 // Check if div with explicit width and no margin-right incorrectly
nickjillings@1289 5680 // gets computed margin-right based on width of container. (#3333)
nickjillings@1289 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nickjillings@1289 5682 // This support function is only executed once so no memoizing is needed.
nickjillings@1289 5683 var ret,
nickjillings@1289 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nickjillings@1289 5685
nickjillings@1289 5686 // Reset CSS: box-sizing; display; margin; border; padding
nickjillings@1289 5687 marginDiv.style.cssText = div.style.cssText =
nickjillings@1289 5688 // Support: Firefox<29, Android 2.3
nickjillings@1289 5689 // Vendor-prefix box-sizing
nickjillings@1289 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nickjillings@1289 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nickjillings@1289 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nickjillings@1289 5693 div.style.width = "1px";
nickjillings@1289 5694 docElem.appendChild( container );
nickjillings@1289 5695
nickjillings@1289 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nickjillings@1289 5697
nickjillings@1289 5698 docElem.removeChild( container );
nickjillings@1289 5699 div.removeChild( marginDiv );
nickjillings@1289 5700
nickjillings@1289 5701 return ret;
nickjillings@1289 5702 }
nickjillings@1289 5703 });
nickjillings@1289 5704 }
nickjillings@1289 5705 })();
nickjillings@1289 5706
nickjillings@1289 5707
nickjillings@1289 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nickjillings@1289 5709 jQuery.swap = function( elem, options, callback, args ) {
nickjillings@1289 5710 var ret, name,
nickjillings@1289 5711 old = {};
nickjillings@1289 5712
nickjillings@1289 5713 // Remember the old values, and insert the new ones
nickjillings@1289 5714 for ( name in options ) {
nickjillings@1289 5715 old[ name ] = elem.style[ name ];
nickjillings@1289 5716 elem.style[ name ] = options[ name ];
nickjillings@1289 5717 }
nickjillings@1289 5718
nickjillings@1289 5719 ret = callback.apply( elem, args || [] );
nickjillings@1289 5720
nickjillings@1289 5721 // Revert the old values
nickjillings@1289 5722 for ( name in options ) {
nickjillings@1289 5723 elem.style[ name ] = old[ name ];
nickjillings@1289 5724 }
nickjillings@1289 5725
nickjillings@1289 5726 return ret;
nickjillings@1289 5727 };
nickjillings@1289 5728
nickjillings@1289 5729
nickjillings@1289 5730 var
nickjillings@1289 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nickjillings@1289 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nickjillings@1289 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nickjillings@1289 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nickjillings@1289 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nickjillings@1289 5736
nickjillings@1289 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nickjillings@1289 5738 cssNormalTransform = {
nickjillings@1289 5739 letterSpacing: "0",
nickjillings@1289 5740 fontWeight: "400"
nickjillings@1289 5741 },
nickjillings@1289 5742
nickjillings@1289 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nickjillings@1289 5744
nickjillings@1289 5745 // Return a css property mapped to a potentially vendor prefixed property
nickjillings@1289 5746 function vendorPropName( style, name ) {
nickjillings@1289 5747
nickjillings@1289 5748 // Shortcut for names that are not vendor prefixed
nickjillings@1289 5749 if ( name in style ) {
nickjillings@1289 5750 return name;
nickjillings@1289 5751 }
nickjillings@1289 5752
nickjillings@1289 5753 // Check for vendor prefixed names
nickjillings@1289 5754 var capName = name[0].toUpperCase() + name.slice(1),
nickjillings@1289 5755 origName = name,
nickjillings@1289 5756 i = cssPrefixes.length;
nickjillings@1289 5757
nickjillings@1289 5758 while ( i-- ) {
nickjillings@1289 5759 name = cssPrefixes[ i ] + capName;
nickjillings@1289 5760 if ( name in style ) {
nickjillings@1289 5761 return name;
nickjillings@1289 5762 }
nickjillings@1289 5763 }
nickjillings@1289 5764
nickjillings@1289 5765 return origName;
nickjillings@1289 5766 }
nickjillings@1289 5767
nickjillings@1289 5768 function setPositiveNumber( elem, value, subtract ) {
nickjillings@1289 5769 var matches = rnumsplit.exec( value );
nickjillings@1289 5770 return matches ?
nickjillings@1289 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nickjillings@1289 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nickjillings@1289 5773 value;
nickjillings@1289 5774 }
nickjillings@1289 5775
nickjillings@1289 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nickjillings@1289 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nickjillings@1289 5778 // If we already have the right measurement, avoid augmentation
nickjillings@1289 5779 4 :
nickjillings@1289 5780 // Otherwise initialize for horizontal or vertical properties
nickjillings@1289 5781 name === "width" ? 1 : 0,
nickjillings@1289 5782
nickjillings@1289 5783 val = 0;
nickjillings@1289 5784
nickjillings@1289 5785 for ( ; i < 4; i += 2 ) {
nickjillings@1289 5786 // Both box models exclude margin, so add it if we want it
nickjillings@1289 5787 if ( extra === "margin" ) {
nickjillings@1289 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nickjillings@1289 5789 }
nickjillings@1289 5790
nickjillings@1289 5791 if ( isBorderBox ) {
nickjillings@1289 5792 // border-box includes padding, so remove it if we want content
nickjillings@1289 5793 if ( extra === "content" ) {
nickjillings@1289 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1289 5795 }
nickjillings@1289 5796
nickjillings@1289 5797 // At this point, extra isn't border nor margin, so remove border
nickjillings@1289 5798 if ( extra !== "margin" ) {
nickjillings@1289 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1289 5800 }
nickjillings@1289 5801 } else {
nickjillings@1289 5802 // At this point, extra isn't content, so add padding
nickjillings@1289 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1289 5804
nickjillings@1289 5805 // At this point, extra isn't content nor padding, so add border
nickjillings@1289 5806 if ( extra !== "padding" ) {
nickjillings@1289 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1289 5808 }
nickjillings@1289 5809 }
nickjillings@1289 5810 }
nickjillings@1289 5811
nickjillings@1289 5812 return val;
nickjillings@1289 5813 }
nickjillings@1289 5814
nickjillings@1289 5815 function getWidthOrHeight( elem, name, extra ) {
nickjillings@1289 5816
nickjillings@1289 5817 // Start with offset property, which is equivalent to the border-box value
nickjillings@1289 5818 var valueIsBorderBox = true,
nickjillings@1289 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nickjillings@1289 5820 styles = getStyles( elem ),
nickjillings@1289 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nickjillings@1289 5822
nickjillings@1289 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nickjillings@1289 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nickjillings@1289 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nickjillings@1289 5826 if ( val <= 0 || val == null ) {
nickjillings@1289 5827 // Fall back to computed then uncomputed css if necessary
nickjillings@1289 5828 val = curCSS( elem, name, styles );
nickjillings@1289 5829 if ( val < 0 || val == null ) {
nickjillings@1289 5830 val = elem.style[ name ];
nickjillings@1289 5831 }
nickjillings@1289 5832
nickjillings@1289 5833 // Computed unit is not pixels. Stop here and return.
nickjillings@1289 5834 if ( rnumnonpx.test(val) ) {
nickjillings@1289 5835 return val;
nickjillings@1289 5836 }
nickjillings@1289 5837
nickjillings@1289 5838 // Check for style in case a browser which returns unreliable values
nickjillings@1289 5839 // for getComputedStyle silently falls back to the reliable elem.style
nickjillings@1289 5840 valueIsBorderBox = isBorderBox &&
nickjillings@1289 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nickjillings@1289 5842
nickjillings@1289 5843 // Normalize "", auto, and prepare for extra
nickjillings@1289 5844 val = parseFloat( val ) || 0;
nickjillings@1289 5845 }
nickjillings@1289 5846
nickjillings@1289 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nickjillings@1289 5848 return ( val +
nickjillings@1289 5849 augmentWidthOrHeight(
nickjillings@1289 5850 elem,
nickjillings@1289 5851 name,
nickjillings@1289 5852 extra || ( isBorderBox ? "border" : "content" ),
nickjillings@1289 5853 valueIsBorderBox,
nickjillings@1289 5854 styles
nickjillings@1289 5855 )
nickjillings@1289 5856 ) + "px";
nickjillings@1289 5857 }
nickjillings@1289 5858
nickjillings@1289 5859 function showHide( elements, show ) {
nickjillings@1289 5860 var display, elem, hidden,
nickjillings@1289 5861 values = [],
nickjillings@1289 5862 index = 0,
nickjillings@1289 5863 length = elements.length;
nickjillings@1289 5864
nickjillings@1289 5865 for ( ; index < length; index++ ) {
nickjillings@1289 5866 elem = elements[ index ];
nickjillings@1289 5867 if ( !elem.style ) {
nickjillings@1289 5868 continue;
nickjillings@1289 5869 }
nickjillings@1289 5870
nickjillings@1289 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nickjillings@1289 5872 display = elem.style.display;
nickjillings@1289 5873 if ( show ) {
nickjillings@1289 5874 // Reset the inline display of this element to learn if it is
nickjillings@1289 5875 // being hidden by cascaded rules or not
nickjillings@1289 5876 if ( !values[ index ] && display === "none" ) {
nickjillings@1289 5877 elem.style.display = "";
nickjillings@1289 5878 }
nickjillings@1289 5879
nickjillings@1289 5880 // Set elements which have been overridden with display: none
nickjillings@1289 5881 // in a stylesheet to whatever the default browser style is
nickjillings@1289 5882 // for such an element
nickjillings@1289 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nickjillings@1289 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nickjillings@1289 5885 }
nickjillings@1289 5886 } else {
nickjillings@1289 5887 hidden = isHidden( elem );
nickjillings@1289 5888
nickjillings@1289 5889 if ( display !== "none" || !hidden ) {
nickjillings@1289 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nickjillings@1289 5891 }
nickjillings@1289 5892 }
nickjillings@1289 5893 }
nickjillings@1289 5894
nickjillings@1289 5895 // Set the display of most of the elements in a second loop
nickjillings@1289 5896 // to avoid the constant reflow
nickjillings@1289 5897 for ( index = 0; index < length; index++ ) {
nickjillings@1289 5898 elem = elements[ index ];
nickjillings@1289 5899 if ( !elem.style ) {
nickjillings@1289 5900 continue;
nickjillings@1289 5901 }
nickjillings@1289 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nickjillings@1289 5903 elem.style.display = show ? values[ index ] || "" : "none";
nickjillings@1289 5904 }
nickjillings@1289 5905 }
nickjillings@1289 5906
nickjillings@1289 5907 return elements;
nickjillings@1289 5908 }
nickjillings@1289 5909
nickjillings@1289 5910 jQuery.extend({
nickjillings@1289 5911
nickjillings@1289 5912 // Add in style property hooks for overriding the default
nickjillings@1289 5913 // behavior of getting and setting a style property
nickjillings@1289 5914 cssHooks: {
nickjillings@1289 5915 opacity: {
nickjillings@1289 5916 get: function( elem, computed ) {
nickjillings@1289 5917 if ( computed ) {
nickjillings@1289 5918
nickjillings@1289 5919 // We should always get a number back from opacity
nickjillings@1289 5920 var ret = curCSS( elem, "opacity" );
nickjillings@1289 5921 return ret === "" ? "1" : ret;
nickjillings@1289 5922 }
nickjillings@1289 5923 }
nickjillings@1289 5924 }
nickjillings@1289 5925 },
nickjillings@1289 5926
nickjillings@1289 5927 // Don't automatically add "px" to these possibly-unitless properties
nickjillings@1289 5928 cssNumber: {
nickjillings@1289 5929 "columnCount": true,
nickjillings@1289 5930 "fillOpacity": true,
nickjillings@1289 5931 "flexGrow": true,
nickjillings@1289 5932 "flexShrink": true,
nickjillings@1289 5933 "fontWeight": true,
nickjillings@1289 5934 "lineHeight": true,
nickjillings@1289 5935 "opacity": true,
nickjillings@1289 5936 "order": true,
nickjillings@1289 5937 "orphans": true,
nickjillings@1289 5938 "widows": true,
nickjillings@1289 5939 "zIndex": true,
nickjillings@1289 5940 "zoom": true
nickjillings@1289 5941 },
nickjillings@1289 5942
nickjillings@1289 5943 // Add in properties whose names you wish to fix before
nickjillings@1289 5944 // setting or getting the value
nickjillings@1289 5945 cssProps: {
nickjillings@1289 5946 "float": "cssFloat"
nickjillings@1289 5947 },
nickjillings@1289 5948
nickjillings@1289 5949 // Get and set the style property on a DOM Node
nickjillings@1289 5950 style: function( elem, name, value, extra ) {
nickjillings@1289 5951
nickjillings@1289 5952 // Don't set styles on text and comment nodes
nickjillings@1289 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nickjillings@1289 5954 return;
nickjillings@1289 5955 }
nickjillings@1289 5956
nickjillings@1289 5957 // Make sure that we're working with the right name
nickjillings@1289 5958 var ret, type, hooks,
nickjillings@1289 5959 origName = jQuery.camelCase( name ),
nickjillings@1289 5960 style = elem.style;
nickjillings@1289 5961
nickjillings@1289 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nickjillings@1289 5963
nickjillings@1289 5964 // Gets hook for the prefixed version, then unprefixed version
nickjillings@1289 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1289 5966
nickjillings@1289 5967 // Check if we're setting a value
nickjillings@1289 5968 if ( value !== undefined ) {
nickjillings@1289 5969 type = typeof value;
nickjillings@1289 5970
nickjillings@1289 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nickjillings@1289 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nickjillings@1289 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nickjillings@1289 5974 // Fixes bug #9237
nickjillings@1289 5975 type = "number";
nickjillings@1289 5976 }
nickjillings@1289 5977
nickjillings@1289 5978 // Make sure that null and NaN values aren't set (#7116)
nickjillings@1289 5979 if ( value == null || value !== value ) {
nickjillings@1289 5980 return;
nickjillings@1289 5981 }
nickjillings@1289 5982
nickjillings@1289 5983 // If a number, add 'px' to the (except for certain CSS properties)
nickjillings@1289 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nickjillings@1289 5985 value += "px";
nickjillings@1289 5986 }
nickjillings@1289 5987
nickjillings@1289 5988 // Support: IE9-11+
nickjillings@1289 5989 // background-* props affect original clone's values
nickjillings@1289 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nickjillings@1289 5991 style[ name ] = "inherit";
nickjillings@1289 5992 }
nickjillings@1289 5993
nickjillings@1289 5994 // If a hook was provided, use that value, otherwise just set the specified value
nickjillings@1289 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nickjillings@1289 5996 style[ name ] = value;
nickjillings@1289 5997 }
nickjillings@1289 5998
nickjillings@1289 5999 } else {
nickjillings@1289 6000 // If a hook was provided get the non-computed value from there
nickjillings@1289 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nickjillings@1289 6002 return ret;
nickjillings@1289 6003 }
nickjillings@1289 6004
nickjillings@1289 6005 // Otherwise just get the value from the style object
nickjillings@1289 6006 return style[ name ];
nickjillings@1289 6007 }
nickjillings@1289 6008 },
nickjillings@1289 6009
nickjillings@1289 6010 css: function( elem, name, extra, styles ) {
nickjillings@1289 6011 var val, num, hooks,
nickjillings@1289 6012 origName = jQuery.camelCase( name );
nickjillings@1289 6013
nickjillings@1289 6014 // Make sure that we're working with the right name
nickjillings@1289 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nickjillings@1289 6016
nickjillings@1289 6017 // Try prefixed name followed by the unprefixed name
nickjillings@1289 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1289 6019
nickjillings@1289 6020 // If a hook was provided get the computed value from there
nickjillings@1289 6021 if ( hooks && "get" in hooks ) {
nickjillings@1289 6022 val = hooks.get( elem, true, extra );
nickjillings@1289 6023 }
nickjillings@1289 6024
nickjillings@1289 6025 // Otherwise, if a way to get the computed value exists, use that
nickjillings@1289 6026 if ( val === undefined ) {
nickjillings@1289 6027 val = curCSS( elem, name, styles );
nickjillings@1289 6028 }
nickjillings@1289 6029
nickjillings@1289 6030 // Convert "normal" to computed value
nickjillings@1289 6031 if ( val === "normal" && name in cssNormalTransform ) {
nickjillings@1289 6032 val = cssNormalTransform[ name ];
nickjillings@1289 6033 }
nickjillings@1289 6034
nickjillings@1289 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nickjillings@1289 6036 if ( extra === "" || extra ) {
nickjillings@1289 6037 num = parseFloat( val );
nickjillings@1289 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nickjillings@1289 6039 }
nickjillings@1289 6040 return val;
nickjillings@1289 6041 }
nickjillings@1289 6042 });
nickjillings@1289 6043
nickjillings@1289 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nickjillings@1289 6045 jQuery.cssHooks[ name ] = {
nickjillings@1289 6046 get: function( elem, computed, extra ) {
nickjillings@1289 6047 if ( computed ) {
nickjillings@1289 6048
nickjillings@1289 6049 // Certain elements can have dimension info if we invisibly show them
nickjillings@1289 6050 // but it must have a current display style that would benefit
nickjillings@1289 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nickjillings@1289 6052 jQuery.swap( elem, cssShow, function() {
nickjillings@1289 6053 return getWidthOrHeight( elem, name, extra );
nickjillings@1289 6054 }) :
nickjillings@1289 6055 getWidthOrHeight( elem, name, extra );
nickjillings@1289 6056 }
nickjillings@1289 6057 },
nickjillings@1289 6058
nickjillings@1289 6059 set: function( elem, value, extra ) {
nickjillings@1289 6060 var styles = extra && getStyles( elem );
nickjillings@1289 6061 return setPositiveNumber( elem, value, extra ?
nickjillings@1289 6062 augmentWidthOrHeight(
nickjillings@1289 6063 elem,
nickjillings@1289 6064 name,
nickjillings@1289 6065 extra,
nickjillings@1289 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nickjillings@1289 6067 styles
nickjillings@1289 6068 ) : 0
nickjillings@1289 6069 );
nickjillings@1289 6070 }
nickjillings@1289 6071 };
nickjillings@1289 6072 });
nickjillings@1289 6073
nickjillings@1289 6074 // Support: Android 2.3
nickjillings@1289 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nickjillings@1289 6076 function( elem, computed ) {
nickjillings@1289 6077 if ( computed ) {
nickjillings@1289 6078 return jQuery.swap( elem, { "display": "inline-block" },
nickjillings@1289 6079 curCSS, [ elem, "marginRight" ] );
nickjillings@1289 6080 }
nickjillings@1289 6081 }
nickjillings@1289 6082 );
nickjillings@1289 6083
nickjillings@1289 6084 // These hooks are used by animate to expand properties
nickjillings@1289 6085 jQuery.each({
nickjillings@1289 6086 margin: "",
nickjillings@1289 6087 padding: "",
nickjillings@1289 6088 border: "Width"
nickjillings@1289 6089 }, function( prefix, suffix ) {
nickjillings@1289 6090 jQuery.cssHooks[ prefix + suffix ] = {
nickjillings@1289 6091 expand: function( value ) {
nickjillings@1289 6092 var i = 0,
nickjillings@1289 6093 expanded = {},
nickjillings@1289 6094
nickjillings@1289 6095 // Assumes a single number if not a string
nickjillings@1289 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nickjillings@1289 6097
nickjillings@1289 6098 for ( ; i < 4; i++ ) {
nickjillings@1289 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nickjillings@1289 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nickjillings@1289 6101 }
nickjillings@1289 6102
nickjillings@1289 6103 return expanded;
nickjillings@1289 6104 }
nickjillings@1289 6105 };
nickjillings@1289 6106
nickjillings@1289 6107 if ( !rmargin.test( prefix ) ) {
nickjillings@1289 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nickjillings@1289 6109 }
nickjillings@1289 6110 });
nickjillings@1289 6111
nickjillings@1289 6112 jQuery.fn.extend({
nickjillings@1289 6113 css: function( name, value ) {
nickjillings@1289 6114 return access( this, function( elem, name, value ) {
nickjillings@1289 6115 var styles, len,
nickjillings@1289 6116 map = {},
nickjillings@1289 6117 i = 0;
nickjillings@1289 6118
nickjillings@1289 6119 if ( jQuery.isArray( name ) ) {
nickjillings@1289 6120 styles = getStyles( elem );
nickjillings@1289 6121 len = name.length;
nickjillings@1289 6122
nickjillings@1289 6123 for ( ; i < len; i++ ) {
nickjillings@1289 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nickjillings@1289 6125 }
nickjillings@1289 6126
nickjillings@1289 6127 return map;
nickjillings@1289 6128 }
nickjillings@1289 6129
nickjillings@1289 6130 return value !== undefined ?
nickjillings@1289 6131 jQuery.style( elem, name, value ) :
nickjillings@1289 6132 jQuery.css( elem, name );
nickjillings@1289 6133 }, name, value, arguments.length > 1 );
nickjillings@1289 6134 },
nickjillings@1289 6135 show: function() {
nickjillings@1289 6136 return showHide( this, true );
nickjillings@1289 6137 },
nickjillings@1289 6138 hide: function() {
nickjillings@1289 6139 return showHide( this );
nickjillings@1289 6140 },
nickjillings@1289 6141 toggle: function( state ) {
nickjillings@1289 6142 if ( typeof state === "boolean" ) {
nickjillings@1289 6143 return state ? this.show() : this.hide();
nickjillings@1289 6144 }
nickjillings@1289 6145
nickjillings@1289 6146 return this.each(function() {
nickjillings@1289 6147 if ( isHidden( this ) ) {
nickjillings@1289 6148 jQuery( this ).show();
nickjillings@1289 6149 } else {
nickjillings@1289 6150 jQuery( this ).hide();
nickjillings@1289 6151 }
nickjillings@1289 6152 });
nickjillings@1289 6153 }
nickjillings@1289 6154 });
nickjillings@1289 6155
nickjillings@1289 6156
nickjillings@1289 6157 function Tween( elem, options, prop, end, easing ) {
nickjillings@1289 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nickjillings@1289 6159 }
nickjillings@1289 6160 jQuery.Tween = Tween;
nickjillings@1289 6161
nickjillings@1289 6162 Tween.prototype = {
nickjillings@1289 6163 constructor: Tween,
nickjillings@1289 6164 init: function( elem, options, prop, end, easing, unit ) {
nickjillings@1289 6165 this.elem = elem;
nickjillings@1289 6166 this.prop = prop;
nickjillings@1289 6167 this.easing = easing || "swing";
nickjillings@1289 6168 this.options = options;
nickjillings@1289 6169 this.start = this.now = this.cur();
nickjillings@1289 6170 this.end = end;
nickjillings@1289 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nickjillings@1289 6172 },
nickjillings@1289 6173 cur: function() {
nickjillings@1289 6174 var hooks = Tween.propHooks[ this.prop ];
nickjillings@1289 6175
nickjillings@1289 6176 return hooks && hooks.get ?
nickjillings@1289 6177 hooks.get( this ) :
nickjillings@1289 6178 Tween.propHooks._default.get( this );
nickjillings@1289 6179 },
nickjillings@1289 6180 run: function( percent ) {
nickjillings@1289 6181 var eased,
nickjillings@1289 6182 hooks = Tween.propHooks[ this.prop ];
nickjillings@1289 6183
nickjillings@1289 6184 if ( this.options.duration ) {
nickjillings@1289 6185 this.pos = eased = jQuery.easing[ this.easing ](
nickjillings@1289 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nickjillings@1289 6187 );
nickjillings@1289 6188 } else {
nickjillings@1289 6189 this.pos = eased = percent;
nickjillings@1289 6190 }
nickjillings@1289 6191 this.now = ( this.end - this.start ) * eased + this.start;
nickjillings@1289 6192
nickjillings@1289 6193 if ( this.options.step ) {
nickjillings@1289 6194 this.options.step.call( this.elem, this.now, this );
nickjillings@1289 6195 }
nickjillings@1289 6196
nickjillings@1289 6197 if ( hooks && hooks.set ) {
nickjillings@1289 6198 hooks.set( this );
nickjillings@1289 6199 } else {
nickjillings@1289 6200 Tween.propHooks._default.set( this );
nickjillings@1289 6201 }
nickjillings@1289 6202 return this;
nickjillings@1289 6203 }
nickjillings@1289 6204 };
nickjillings@1289 6205
nickjillings@1289 6206 Tween.prototype.init.prototype = Tween.prototype;
nickjillings@1289 6207
nickjillings@1289 6208 Tween.propHooks = {
nickjillings@1289 6209 _default: {
nickjillings@1289 6210 get: function( tween ) {
nickjillings@1289 6211 var result;
nickjillings@1289 6212
nickjillings@1289 6213 if ( tween.elem[ tween.prop ] != null &&
nickjillings@1289 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nickjillings@1289 6215 return tween.elem[ tween.prop ];
nickjillings@1289 6216 }
nickjillings@1289 6217
nickjillings@1289 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nickjillings@1289 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nickjillings@1289 6220 // Simple values such as "10px" are parsed to Float;
nickjillings@1289 6221 // complex values such as "rotate(1rad)" are returned as-is.
nickjillings@1289 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nickjillings@1289 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nickjillings@1289 6224 return !result || result === "auto" ? 0 : result;
nickjillings@1289 6225 },
nickjillings@1289 6226 set: function( tween ) {
nickjillings@1289 6227 // Use step hook for back compat.
nickjillings@1289 6228 // Use cssHook if its there.
nickjillings@1289 6229 // Use .style if available and use plain properties where available.
nickjillings@1289 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nickjillings@1289 6231 jQuery.fx.step[ tween.prop ]( tween );
nickjillings@1289 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nickjillings@1289 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nickjillings@1289 6234 } else {
nickjillings@1289 6235 tween.elem[ tween.prop ] = tween.now;
nickjillings@1289 6236 }
nickjillings@1289 6237 }
nickjillings@1289 6238 }
nickjillings@1289 6239 };
nickjillings@1289 6240
nickjillings@1289 6241 // Support: IE9
nickjillings@1289 6242 // Panic based approach to setting things on disconnected nodes
nickjillings@1289 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nickjillings@1289 6244 set: function( tween ) {
nickjillings@1289 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nickjillings@1289 6246 tween.elem[ tween.prop ] = tween.now;
nickjillings@1289 6247 }
nickjillings@1289 6248 }
nickjillings@1289 6249 };
nickjillings@1289 6250
nickjillings@1289 6251 jQuery.easing = {
nickjillings@1289 6252 linear: function( p ) {
nickjillings@1289 6253 return p;
nickjillings@1289 6254 },
nickjillings@1289 6255 swing: function( p ) {
nickjillings@1289 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nickjillings@1289 6257 }
nickjillings@1289 6258 };
nickjillings@1289 6259
nickjillings@1289 6260 jQuery.fx = Tween.prototype.init;
nickjillings@1289 6261
nickjillings@1289 6262 // Back Compat <1.8 extension point
nickjillings@1289 6263 jQuery.fx.step = {};
nickjillings@1289 6264
nickjillings@1289 6265
nickjillings@1289 6266
nickjillings@1289 6267
nickjillings@1289 6268 var
nickjillings@1289 6269 fxNow, timerId,
nickjillings@1289 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nickjillings@1289 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nickjillings@1289 6272 rrun = /queueHooks$/,
nickjillings@1289 6273 animationPrefilters = [ defaultPrefilter ],
nickjillings@1289 6274 tweeners = {
nickjillings@1289 6275 "*": [ function( prop, value ) {
nickjillings@1289 6276 var tween = this.createTween( prop, value ),
nickjillings@1289 6277 target = tween.cur(),
nickjillings@1289 6278 parts = rfxnum.exec( value ),
nickjillings@1289 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nickjillings@1289 6280
nickjillings@1289 6281 // Starting value computation is required for potential unit mismatches
nickjillings@1289 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nickjillings@1289 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nickjillings@1289 6284 scale = 1,
nickjillings@1289 6285 maxIterations = 20;
nickjillings@1289 6286
nickjillings@1289 6287 if ( start && start[ 3 ] !== unit ) {
nickjillings@1289 6288 // Trust units reported by jQuery.css
nickjillings@1289 6289 unit = unit || start[ 3 ];
nickjillings@1289 6290
nickjillings@1289 6291 // Make sure we update the tween properties later on
nickjillings@1289 6292 parts = parts || [];
nickjillings@1289 6293
nickjillings@1289 6294 // Iteratively approximate from a nonzero starting point
nickjillings@1289 6295 start = +target || 1;
nickjillings@1289 6296
nickjillings@1289 6297 do {
nickjillings@1289 6298 // If previous iteration zeroed out, double until we get *something*.
nickjillings@1289 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nickjillings@1289 6300 scale = scale || ".5";
nickjillings@1289 6301
nickjillings@1289 6302 // Adjust and apply
nickjillings@1289 6303 start = start / scale;
nickjillings@1289 6304 jQuery.style( tween.elem, prop, start + unit );
nickjillings@1289 6305
nickjillings@1289 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nickjillings@1289 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nickjillings@1289 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nickjillings@1289 6309 }
nickjillings@1289 6310
nickjillings@1289 6311 // Update tween properties
nickjillings@1289 6312 if ( parts ) {
nickjillings@1289 6313 start = tween.start = +start || +target || 0;
nickjillings@1289 6314 tween.unit = unit;
nickjillings@1289 6315 // If a +=/-= token was provided, we're doing a relative animation
nickjillings@1289 6316 tween.end = parts[ 1 ] ?
nickjillings@1289 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nickjillings@1289 6318 +parts[ 2 ];
nickjillings@1289 6319 }
nickjillings@1289 6320
nickjillings@1289 6321 return tween;
nickjillings@1289 6322 } ]
nickjillings@1289 6323 };
nickjillings@1289 6324
nickjillings@1289 6325 // Animations created synchronously will run synchronously
nickjillings@1289 6326 function createFxNow() {
nickjillings@1289 6327 setTimeout(function() {
nickjillings@1289 6328 fxNow = undefined;
nickjillings@1289 6329 });
nickjillings@1289 6330 return ( fxNow = jQuery.now() );
nickjillings@1289 6331 }
nickjillings@1289 6332
nickjillings@1289 6333 // Generate parameters to create a standard animation
nickjillings@1289 6334 function genFx( type, includeWidth ) {
nickjillings@1289 6335 var which,
nickjillings@1289 6336 i = 0,
nickjillings@1289 6337 attrs = { height: type };
nickjillings@1289 6338
nickjillings@1289 6339 // If we include width, step value is 1 to do all cssExpand values,
nickjillings@1289 6340 // otherwise step value is 2 to skip over Left and Right
nickjillings@1289 6341 includeWidth = includeWidth ? 1 : 0;
nickjillings@1289 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nickjillings@1289 6343 which = cssExpand[ i ];
nickjillings@1289 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nickjillings@1289 6345 }
nickjillings@1289 6346
nickjillings@1289 6347 if ( includeWidth ) {
nickjillings@1289 6348 attrs.opacity = attrs.width = type;
nickjillings@1289 6349 }
nickjillings@1289 6350
nickjillings@1289 6351 return attrs;
nickjillings@1289 6352 }
nickjillings@1289 6353
nickjillings@1289 6354 function createTween( value, prop, animation ) {
nickjillings@1289 6355 var tween,
nickjillings@1289 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nickjillings@1289 6357 index = 0,
nickjillings@1289 6358 length = collection.length;
nickjillings@1289 6359 for ( ; index < length; index++ ) {
nickjillings@1289 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nickjillings@1289 6361
nickjillings@1289 6362 // We're done with this property
nickjillings@1289 6363 return tween;
nickjillings@1289 6364 }
nickjillings@1289 6365 }
nickjillings@1289 6366 }
nickjillings@1289 6367
nickjillings@1289 6368 function defaultPrefilter( elem, props, opts ) {
nickjillings@1289 6369 /* jshint validthis: true */
nickjillings@1289 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nickjillings@1289 6371 anim = this,
nickjillings@1289 6372 orig = {},
nickjillings@1289 6373 style = elem.style,
nickjillings@1289 6374 hidden = elem.nodeType && isHidden( elem ),
nickjillings@1289 6375 dataShow = data_priv.get( elem, "fxshow" );
nickjillings@1289 6376
nickjillings@1289 6377 // Handle queue: false promises
nickjillings@1289 6378 if ( !opts.queue ) {
nickjillings@1289 6379 hooks = jQuery._queueHooks( elem, "fx" );
nickjillings@1289 6380 if ( hooks.unqueued == null ) {
nickjillings@1289 6381 hooks.unqueued = 0;
nickjillings@1289 6382 oldfire = hooks.empty.fire;
nickjillings@1289 6383 hooks.empty.fire = function() {
nickjillings@1289 6384 if ( !hooks.unqueued ) {
nickjillings@1289 6385 oldfire();
nickjillings@1289 6386 }
nickjillings@1289 6387 };
nickjillings@1289 6388 }
nickjillings@1289 6389 hooks.unqueued++;
nickjillings@1289 6390
nickjillings@1289 6391 anim.always(function() {
nickjillings@1289 6392 // Ensure the complete handler is called before this completes
nickjillings@1289 6393 anim.always(function() {
nickjillings@1289 6394 hooks.unqueued--;
nickjillings@1289 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nickjillings@1289 6396 hooks.empty.fire();
nickjillings@1289 6397 }
nickjillings@1289 6398 });
nickjillings@1289 6399 });
nickjillings@1289 6400 }
nickjillings@1289 6401
nickjillings@1289 6402 // Height/width overflow pass
nickjillings@1289 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nickjillings@1289 6404 // Make sure that nothing sneaks out
nickjillings@1289 6405 // Record all 3 overflow attributes because IE9-10 do not
nickjillings@1289 6406 // change the overflow attribute when overflowX and
nickjillings@1289 6407 // overflowY are set to the same value
nickjillings@1289 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nickjillings@1289 6409
nickjillings@1289 6410 // Set display property to inline-block for height/width
nickjillings@1289 6411 // animations on inline elements that are having width/height animated
nickjillings@1289 6412 display = jQuery.css( elem, "display" );
nickjillings@1289 6413
nickjillings@1289 6414 // Test default display if display is currently "none"
nickjillings@1289 6415 checkDisplay = display === "none" ?
nickjillings@1289 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nickjillings@1289 6417
nickjillings@1289 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nickjillings@1289 6419 style.display = "inline-block";
nickjillings@1289 6420 }
nickjillings@1289 6421 }
nickjillings@1289 6422
nickjillings@1289 6423 if ( opts.overflow ) {
nickjillings@1289 6424 style.overflow = "hidden";
nickjillings@1289 6425 anim.always(function() {
nickjillings@1289 6426 style.overflow = opts.overflow[ 0 ];
nickjillings@1289 6427 style.overflowX = opts.overflow[ 1 ];
nickjillings@1289 6428 style.overflowY = opts.overflow[ 2 ];
nickjillings@1289 6429 });
nickjillings@1289 6430 }
nickjillings@1289 6431
nickjillings@1289 6432 // show/hide pass
nickjillings@1289 6433 for ( prop in props ) {
nickjillings@1289 6434 value = props[ prop ];
nickjillings@1289 6435 if ( rfxtypes.exec( value ) ) {
nickjillings@1289 6436 delete props[ prop ];
nickjillings@1289 6437 toggle = toggle || value === "toggle";
nickjillings@1289 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nickjillings@1289 6439
nickjillings@1289 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@1289 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nickjillings@1289 6442 hidden = true;
nickjillings@1289 6443 } else {
nickjillings@1289 6444 continue;
nickjillings@1289 6445 }
nickjillings@1289 6446 }
nickjillings@1289 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nickjillings@1289 6448
nickjillings@1289 6449 // Any non-fx value stops us from restoring the original display value
nickjillings@1289 6450 } else {
nickjillings@1289 6451 display = undefined;
nickjillings@1289 6452 }
nickjillings@1289 6453 }
nickjillings@1289 6454
nickjillings@1289 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nickjillings@1289 6456 if ( dataShow ) {
nickjillings@1289 6457 if ( "hidden" in dataShow ) {
nickjillings@1289 6458 hidden = dataShow.hidden;
nickjillings@1289 6459 }
nickjillings@1289 6460 } else {
nickjillings@1289 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nickjillings@1289 6462 }
nickjillings@1289 6463
nickjillings@1289 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nickjillings@1289 6465 if ( toggle ) {
nickjillings@1289 6466 dataShow.hidden = !hidden;
nickjillings@1289 6467 }
nickjillings@1289 6468 if ( hidden ) {
nickjillings@1289 6469 jQuery( elem ).show();
nickjillings@1289 6470 } else {
nickjillings@1289 6471 anim.done(function() {
nickjillings@1289 6472 jQuery( elem ).hide();
nickjillings@1289 6473 });
nickjillings@1289 6474 }
nickjillings@1289 6475 anim.done(function() {
nickjillings@1289 6476 var prop;
nickjillings@1289 6477
nickjillings@1289 6478 data_priv.remove( elem, "fxshow" );
nickjillings@1289 6479 for ( prop in orig ) {
nickjillings@1289 6480 jQuery.style( elem, prop, orig[ prop ] );
nickjillings@1289 6481 }
nickjillings@1289 6482 });
nickjillings@1289 6483 for ( prop in orig ) {
nickjillings@1289 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nickjillings@1289 6485
nickjillings@1289 6486 if ( !( prop in dataShow ) ) {
nickjillings@1289 6487 dataShow[ prop ] = tween.start;
nickjillings@1289 6488 if ( hidden ) {
nickjillings@1289 6489 tween.end = tween.start;
nickjillings@1289 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nickjillings@1289 6491 }
nickjillings@1289 6492 }
nickjillings@1289 6493 }
nickjillings@1289 6494
nickjillings@1289 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nickjillings@1289 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nickjillings@1289 6497 style.display = display;
nickjillings@1289 6498 }
nickjillings@1289 6499 }
nickjillings@1289 6500
nickjillings@1289 6501 function propFilter( props, specialEasing ) {
nickjillings@1289 6502 var index, name, easing, value, hooks;
nickjillings@1289 6503
nickjillings@1289 6504 // camelCase, specialEasing and expand cssHook pass
nickjillings@1289 6505 for ( index in props ) {
nickjillings@1289 6506 name = jQuery.camelCase( index );
nickjillings@1289 6507 easing = specialEasing[ name ];
nickjillings@1289 6508 value = props[ index ];
nickjillings@1289 6509 if ( jQuery.isArray( value ) ) {
nickjillings@1289 6510 easing = value[ 1 ];
nickjillings@1289 6511 value = props[ index ] = value[ 0 ];
nickjillings@1289 6512 }
nickjillings@1289 6513
nickjillings@1289 6514 if ( index !== name ) {
nickjillings@1289 6515 props[ name ] = value;
nickjillings@1289 6516 delete props[ index ];
nickjillings@1289 6517 }
nickjillings@1289 6518
nickjillings@1289 6519 hooks = jQuery.cssHooks[ name ];
nickjillings@1289 6520 if ( hooks && "expand" in hooks ) {
nickjillings@1289 6521 value = hooks.expand( value );
nickjillings@1289 6522 delete props[ name ];
nickjillings@1289 6523
nickjillings@1289 6524 // Not quite $.extend, this won't overwrite existing keys.
nickjillings@1289 6525 // Reusing 'index' because we have the correct "name"
nickjillings@1289 6526 for ( index in value ) {
nickjillings@1289 6527 if ( !( index in props ) ) {
nickjillings@1289 6528 props[ index ] = value[ index ];
nickjillings@1289 6529 specialEasing[ index ] = easing;
nickjillings@1289 6530 }
nickjillings@1289 6531 }
nickjillings@1289 6532 } else {
nickjillings@1289 6533 specialEasing[ name ] = easing;
nickjillings@1289 6534 }
nickjillings@1289 6535 }
nickjillings@1289 6536 }
nickjillings@1289 6537
nickjillings@1289 6538 function Animation( elem, properties, options ) {
nickjillings@1289 6539 var result,
nickjillings@1289 6540 stopped,
nickjillings@1289 6541 index = 0,
nickjillings@1289 6542 length = animationPrefilters.length,
nickjillings@1289 6543 deferred = jQuery.Deferred().always( function() {
nickjillings@1289 6544 // Don't match elem in the :animated selector
nickjillings@1289 6545 delete tick.elem;
nickjillings@1289 6546 }),
nickjillings@1289 6547 tick = function() {
nickjillings@1289 6548 if ( stopped ) {
nickjillings@1289 6549 return false;
nickjillings@1289 6550 }
nickjillings@1289 6551 var currentTime = fxNow || createFxNow(),
nickjillings@1289 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nickjillings@1289 6553 // Support: Android 2.3
nickjillings@1289 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nickjillings@1289 6555 temp = remaining / animation.duration || 0,
nickjillings@1289 6556 percent = 1 - temp,
nickjillings@1289 6557 index = 0,
nickjillings@1289 6558 length = animation.tweens.length;
nickjillings@1289 6559
nickjillings@1289 6560 for ( ; index < length ; index++ ) {
nickjillings@1289 6561 animation.tweens[ index ].run( percent );
nickjillings@1289 6562 }
nickjillings@1289 6563
nickjillings@1289 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nickjillings@1289 6565
nickjillings@1289 6566 if ( percent < 1 && length ) {
nickjillings@1289 6567 return remaining;
nickjillings@1289 6568 } else {
nickjillings@1289 6569 deferred.resolveWith( elem, [ animation ] );
nickjillings@1289 6570 return false;
nickjillings@1289 6571 }
nickjillings@1289 6572 },
nickjillings@1289 6573 animation = deferred.promise({
nickjillings@1289 6574 elem: elem,
nickjillings@1289 6575 props: jQuery.extend( {}, properties ),
nickjillings@1289 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nickjillings@1289 6577 originalProperties: properties,
nickjillings@1289 6578 originalOptions: options,
nickjillings@1289 6579 startTime: fxNow || createFxNow(),
nickjillings@1289 6580 duration: options.duration,
nickjillings@1289 6581 tweens: [],
nickjillings@1289 6582 createTween: function( prop, end ) {
nickjillings@1289 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nickjillings@1289 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nickjillings@1289 6585 animation.tweens.push( tween );
nickjillings@1289 6586 return tween;
nickjillings@1289 6587 },
nickjillings@1289 6588 stop: function( gotoEnd ) {
nickjillings@1289 6589 var index = 0,
nickjillings@1289 6590 // If we are going to the end, we want to run all the tweens
nickjillings@1289 6591 // otherwise we skip this part
nickjillings@1289 6592 length = gotoEnd ? animation.tweens.length : 0;
nickjillings@1289 6593 if ( stopped ) {
nickjillings@1289 6594 return this;
nickjillings@1289 6595 }
nickjillings@1289 6596 stopped = true;
nickjillings@1289 6597 for ( ; index < length ; index++ ) {
nickjillings@1289 6598 animation.tweens[ index ].run( 1 );
nickjillings@1289 6599 }
nickjillings@1289 6600
nickjillings@1289 6601 // Resolve when we played the last frame; otherwise, reject
nickjillings@1289 6602 if ( gotoEnd ) {
nickjillings@1289 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nickjillings@1289 6604 } else {
nickjillings@1289 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nickjillings@1289 6606 }
nickjillings@1289 6607 return this;
nickjillings@1289 6608 }
nickjillings@1289 6609 }),
nickjillings@1289 6610 props = animation.props;
nickjillings@1289 6611
nickjillings@1289 6612 propFilter( props, animation.opts.specialEasing );
nickjillings@1289 6613
nickjillings@1289 6614 for ( ; index < length ; index++ ) {
nickjillings@1289 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nickjillings@1289 6616 if ( result ) {
nickjillings@1289 6617 return result;
nickjillings@1289 6618 }
nickjillings@1289 6619 }
nickjillings@1289 6620
nickjillings@1289 6621 jQuery.map( props, createTween, animation );
nickjillings@1289 6622
nickjillings@1289 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nickjillings@1289 6624 animation.opts.start.call( elem, animation );
nickjillings@1289 6625 }
nickjillings@1289 6626
nickjillings@1289 6627 jQuery.fx.timer(
nickjillings@1289 6628 jQuery.extend( tick, {
nickjillings@1289 6629 elem: elem,
nickjillings@1289 6630 anim: animation,
nickjillings@1289 6631 queue: animation.opts.queue
nickjillings@1289 6632 })
nickjillings@1289 6633 );
nickjillings@1289 6634
nickjillings@1289 6635 // attach callbacks from options
nickjillings@1289 6636 return animation.progress( animation.opts.progress )
nickjillings@1289 6637 .done( animation.opts.done, animation.opts.complete )
nickjillings@1289 6638 .fail( animation.opts.fail )
nickjillings@1289 6639 .always( animation.opts.always );
nickjillings@1289 6640 }
nickjillings@1289 6641
nickjillings@1289 6642 jQuery.Animation = jQuery.extend( Animation, {
nickjillings@1289 6643
nickjillings@1289 6644 tweener: function( props, callback ) {
nickjillings@1289 6645 if ( jQuery.isFunction( props ) ) {
nickjillings@1289 6646 callback = props;
nickjillings@1289 6647 props = [ "*" ];
nickjillings@1289 6648 } else {
nickjillings@1289 6649 props = props.split(" ");
nickjillings@1289 6650 }
nickjillings@1289 6651
nickjillings@1289 6652 var prop,
nickjillings@1289 6653 index = 0,
nickjillings@1289 6654 length = props.length;
nickjillings@1289 6655
nickjillings@1289 6656 for ( ; index < length ; index++ ) {
nickjillings@1289 6657 prop = props[ index ];
nickjillings@1289 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nickjillings@1289 6659 tweeners[ prop ].unshift( callback );
nickjillings@1289 6660 }
nickjillings@1289 6661 },
nickjillings@1289 6662
nickjillings@1289 6663 prefilter: function( callback, prepend ) {
nickjillings@1289 6664 if ( prepend ) {
nickjillings@1289 6665 animationPrefilters.unshift( callback );
nickjillings@1289 6666 } else {
nickjillings@1289 6667 animationPrefilters.push( callback );
nickjillings@1289 6668 }
nickjillings@1289 6669 }
nickjillings@1289 6670 });
nickjillings@1289 6671
nickjillings@1289 6672 jQuery.speed = function( speed, easing, fn ) {
nickjillings@1289 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nickjillings@1289 6674 complete: fn || !fn && easing ||
nickjillings@1289 6675 jQuery.isFunction( speed ) && speed,
nickjillings@1289 6676 duration: speed,
nickjillings@1289 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nickjillings@1289 6678 };
nickjillings@1289 6679
nickjillings@1289 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nickjillings@1289 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nickjillings@1289 6682
nickjillings@1289 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nickjillings@1289 6684 if ( opt.queue == null || opt.queue === true ) {
nickjillings@1289 6685 opt.queue = "fx";
nickjillings@1289 6686 }
nickjillings@1289 6687
nickjillings@1289 6688 // Queueing
nickjillings@1289 6689 opt.old = opt.complete;
nickjillings@1289 6690
nickjillings@1289 6691 opt.complete = function() {
nickjillings@1289 6692 if ( jQuery.isFunction( opt.old ) ) {
nickjillings@1289 6693 opt.old.call( this );
nickjillings@1289 6694 }
nickjillings@1289 6695
nickjillings@1289 6696 if ( opt.queue ) {
nickjillings@1289 6697 jQuery.dequeue( this, opt.queue );
nickjillings@1289 6698 }
nickjillings@1289 6699 };
nickjillings@1289 6700
nickjillings@1289 6701 return opt;
nickjillings@1289 6702 };
nickjillings@1289 6703
nickjillings@1289 6704 jQuery.fn.extend({
nickjillings@1289 6705 fadeTo: function( speed, to, easing, callback ) {
nickjillings@1289 6706
nickjillings@1289 6707 // Show any hidden elements after setting opacity to 0
nickjillings@1289 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nickjillings@1289 6709
nickjillings@1289 6710 // Animate to the value specified
nickjillings@1289 6711 .end().animate({ opacity: to }, speed, easing, callback );
nickjillings@1289 6712 },
nickjillings@1289 6713 animate: function( prop, speed, easing, callback ) {
nickjillings@1289 6714 var empty = jQuery.isEmptyObject( prop ),
nickjillings@1289 6715 optall = jQuery.speed( speed, easing, callback ),
nickjillings@1289 6716 doAnimation = function() {
nickjillings@1289 6717 // Operate on a copy of prop so per-property easing won't be lost
nickjillings@1289 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nickjillings@1289 6719
nickjillings@1289 6720 // Empty animations, or finishing resolves immediately
nickjillings@1289 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nickjillings@1289 6722 anim.stop( true );
nickjillings@1289 6723 }
nickjillings@1289 6724 };
nickjillings@1289 6725 doAnimation.finish = doAnimation;
nickjillings@1289 6726
nickjillings@1289 6727 return empty || optall.queue === false ?
nickjillings@1289 6728 this.each( doAnimation ) :
nickjillings@1289 6729 this.queue( optall.queue, doAnimation );
nickjillings@1289 6730 },
nickjillings@1289 6731 stop: function( type, clearQueue, gotoEnd ) {
nickjillings@1289 6732 var stopQueue = function( hooks ) {
nickjillings@1289 6733 var stop = hooks.stop;
nickjillings@1289 6734 delete hooks.stop;
nickjillings@1289 6735 stop( gotoEnd );
nickjillings@1289 6736 };
nickjillings@1289 6737
nickjillings@1289 6738 if ( typeof type !== "string" ) {
nickjillings@1289 6739 gotoEnd = clearQueue;
nickjillings@1289 6740 clearQueue = type;
nickjillings@1289 6741 type = undefined;
nickjillings@1289 6742 }
nickjillings@1289 6743 if ( clearQueue && type !== false ) {
nickjillings@1289 6744 this.queue( type || "fx", [] );
nickjillings@1289 6745 }
nickjillings@1289 6746
nickjillings@1289 6747 return this.each(function() {
nickjillings@1289 6748 var dequeue = true,
nickjillings@1289 6749 index = type != null && type + "queueHooks",
nickjillings@1289 6750 timers = jQuery.timers,
nickjillings@1289 6751 data = data_priv.get( this );
nickjillings@1289 6752
nickjillings@1289 6753 if ( index ) {
nickjillings@1289 6754 if ( data[ index ] && data[ index ].stop ) {
nickjillings@1289 6755 stopQueue( data[ index ] );
nickjillings@1289 6756 }
nickjillings@1289 6757 } else {
nickjillings@1289 6758 for ( index in data ) {
nickjillings@1289 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nickjillings@1289 6760 stopQueue( data[ index ] );
nickjillings@1289 6761 }
nickjillings@1289 6762 }
nickjillings@1289 6763 }
nickjillings@1289 6764
nickjillings@1289 6765 for ( index = timers.length; index--; ) {
nickjillings@1289 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nickjillings@1289 6767 timers[ index ].anim.stop( gotoEnd );
nickjillings@1289 6768 dequeue = false;
nickjillings@1289 6769 timers.splice( index, 1 );
nickjillings@1289 6770 }
nickjillings@1289 6771 }
nickjillings@1289 6772
nickjillings@1289 6773 // Start the next in the queue if the last step wasn't forced.
nickjillings@1289 6774 // Timers currently will call their complete callbacks, which
nickjillings@1289 6775 // will dequeue but only if they were gotoEnd.
nickjillings@1289 6776 if ( dequeue || !gotoEnd ) {
nickjillings@1289 6777 jQuery.dequeue( this, type );
nickjillings@1289 6778 }
nickjillings@1289 6779 });
nickjillings@1289 6780 },
nickjillings@1289 6781 finish: function( type ) {
nickjillings@1289 6782 if ( type !== false ) {
nickjillings@1289 6783 type = type || "fx";
nickjillings@1289 6784 }
nickjillings@1289 6785 return this.each(function() {
nickjillings@1289 6786 var index,
nickjillings@1289 6787 data = data_priv.get( this ),
nickjillings@1289 6788 queue = data[ type + "queue" ],
nickjillings@1289 6789 hooks = data[ type + "queueHooks" ],
nickjillings@1289 6790 timers = jQuery.timers,
nickjillings@1289 6791 length = queue ? queue.length : 0;
nickjillings@1289 6792
nickjillings@1289 6793 // Enable finishing flag on private data
nickjillings@1289 6794 data.finish = true;
nickjillings@1289 6795
nickjillings@1289 6796 // Empty the queue first
nickjillings@1289 6797 jQuery.queue( this, type, [] );
nickjillings@1289 6798
nickjillings@1289 6799 if ( hooks && hooks.stop ) {
nickjillings@1289 6800 hooks.stop.call( this, true );
nickjillings@1289 6801 }
nickjillings@1289 6802
nickjillings@1289 6803 // Look for any active animations, and finish them
nickjillings@1289 6804 for ( index = timers.length; index--; ) {
nickjillings@1289 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nickjillings@1289 6806 timers[ index ].anim.stop( true );
nickjillings@1289 6807 timers.splice( index, 1 );
nickjillings@1289 6808 }
nickjillings@1289 6809 }
nickjillings@1289 6810
nickjillings@1289 6811 // Look for any animations in the old queue and finish them
nickjillings@1289 6812 for ( index = 0; index < length; index++ ) {
nickjillings@1289 6813 if ( queue[ index ] && queue[ index ].finish ) {
nickjillings@1289 6814 queue[ index ].finish.call( this );
nickjillings@1289 6815 }
nickjillings@1289 6816 }
nickjillings@1289 6817
nickjillings@1289 6818 // Turn off finishing flag
nickjillings@1289 6819 delete data.finish;
nickjillings@1289 6820 });
nickjillings@1289 6821 }
nickjillings@1289 6822 });
nickjillings@1289 6823
nickjillings@1289 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nickjillings@1289 6825 var cssFn = jQuery.fn[ name ];
nickjillings@1289 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1289 6827 return speed == null || typeof speed === "boolean" ?
nickjillings@1289 6828 cssFn.apply( this, arguments ) :
nickjillings@1289 6829 this.animate( genFx( name, true ), speed, easing, callback );
nickjillings@1289 6830 };
nickjillings@1289 6831 });
nickjillings@1289 6832
nickjillings@1289 6833 // Generate shortcuts for custom animations
nickjillings@1289 6834 jQuery.each({
nickjillings@1289 6835 slideDown: genFx("show"),
nickjillings@1289 6836 slideUp: genFx("hide"),
nickjillings@1289 6837 slideToggle: genFx("toggle"),
nickjillings@1289 6838 fadeIn: { opacity: "show" },
nickjillings@1289 6839 fadeOut: { opacity: "hide" },
nickjillings@1289 6840 fadeToggle: { opacity: "toggle" }
nickjillings@1289 6841 }, function( name, props ) {
nickjillings@1289 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1289 6843 return this.animate( props, speed, easing, callback );
nickjillings@1289 6844 };
nickjillings@1289 6845 });
nickjillings@1289 6846
nickjillings@1289 6847 jQuery.timers = [];
nickjillings@1289 6848 jQuery.fx.tick = function() {
nickjillings@1289 6849 var timer,
nickjillings@1289 6850 i = 0,
nickjillings@1289 6851 timers = jQuery.timers;
nickjillings@1289 6852
nickjillings@1289 6853 fxNow = jQuery.now();
nickjillings@1289 6854
nickjillings@1289 6855 for ( ; i < timers.length; i++ ) {
nickjillings@1289 6856 timer = timers[ i ];
nickjillings@1289 6857 // Checks the timer has not already been removed
nickjillings@1289 6858 if ( !timer() && timers[ i ] === timer ) {
nickjillings@1289 6859 timers.splice( i--, 1 );
nickjillings@1289 6860 }
nickjillings@1289 6861 }
nickjillings@1289 6862
nickjillings@1289 6863 if ( !timers.length ) {
nickjillings@1289 6864 jQuery.fx.stop();
nickjillings@1289 6865 }
nickjillings@1289 6866 fxNow = undefined;
nickjillings@1289 6867 };
nickjillings@1289 6868
nickjillings@1289 6869 jQuery.fx.timer = function( timer ) {
nickjillings@1289 6870 jQuery.timers.push( timer );
nickjillings@1289 6871 if ( timer() ) {
nickjillings@1289 6872 jQuery.fx.start();
nickjillings@1289 6873 } else {
nickjillings@1289 6874 jQuery.timers.pop();
nickjillings@1289 6875 }
nickjillings@1289 6876 };
nickjillings@1289 6877
nickjillings@1289 6878 jQuery.fx.interval = 13;
nickjillings@1289 6879
nickjillings@1289 6880 jQuery.fx.start = function() {
nickjillings@1289 6881 if ( !timerId ) {
nickjillings@1289 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nickjillings@1289 6883 }
nickjillings@1289 6884 };
nickjillings@1289 6885
nickjillings@1289 6886 jQuery.fx.stop = function() {
nickjillings@1289 6887 clearInterval( timerId );
nickjillings@1289 6888 timerId = null;
nickjillings@1289 6889 };
nickjillings@1289 6890
nickjillings@1289 6891 jQuery.fx.speeds = {
nickjillings@1289 6892 slow: 600,
nickjillings@1289 6893 fast: 200,
nickjillings@1289 6894 // Default speed
nickjillings@1289 6895 _default: 400
nickjillings@1289 6896 };
nickjillings@1289 6897
nickjillings@1289 6898
nickjillings@1289 6899 // Based off of the plugin by Clint Helfers, with permission.
nickjillings@1289 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nickjillings@1289 6901 jQuery.fn.delay = function( time, type ) {
nickjillings@1289 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nickjillings@1289 6903 type = type || "fx";
nickjillings@1289 6904
nickjillings@1289 6905 return this.queue( type, function( next, hooks ) {
nickjillings@1289 6906 var timeout = setTimeout( next, time );
nickjillings@1289 6907 hooks.stop = function() {
nickjillings@1289 6908 clearTimeout( timeout );
nickjillings@1289 6909 };
nickjillings@1289 6910 });
nickjillings@1289 6911 };
nickjillings@1289 6912
nickjillings@1289 6913
nickjillings@1289 6914 (function() {
nickjillings@1289 6915 var input = document.createElement( "input" ),
nickjillings@1289 6916 select = document.createElement( "select" ),
nickjillings@1289 6917 opt = select.appendChild( document.createElement( "option" ) );
nickjillings@1289 6918
nickjillings@1289 6919 input.type = "checkbox";
nickjillings@1289 6920
nickjillings@1289 6921 // Support: iOS<=5.1, Android<=4.2+
nickjillings@1289 6922 // Default value for a checkbox should be "on"
nickjillings@1289 6923 support.checkOn = input.value !== "";
nickjillings@1289 6924
nickjillings@1289 6925 // Support: IE<=11+
nickjillings@1289 6926 // Must access selectedIndex to make default options select
nickjillings@1289 6927 support.optSelected = opt.selected;
nickjillings@1289 6928
nickjillings@1289 6929 // Support: Android<=2.3
nickjillings@1289 6930 // Options inside disabled selects are incorrectly marked as disabled
nickjillings@1289 6931 select.disabled = true;
nickjillings@1289 6932 support.optDisabled = !opt.disabled;
nickjillings@1289 6933
nickjillings@1289 6934 // Support: IE<=11+
nickjillings@1289 6935 // An input loses its value after becoming a radio
nickjillings@1289 6936 input = document.createElement( "input" );
nickjillings@1289 6937 input.value = "t";
nickjillings@1289 6938 input.type = "radio";
nickjillings@1289 6939 support.radioValue = input.value === "t";
nickjillings@1289 6940 })();
nickjillings@1289 6941
nickjillings@1289 6942
nickjillings@1289 6943 var nodeHook, boolHook,
nickjillings@1289 6944 attrHandle = jQuery.expr.attrHandle;
nickjillings@1289 6945
nickjillings@1289 6946 jQuery.fn.extend({
nickjillings@1289 6947 attr: function( name, value ) {
nickjillings@1289 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nickjillings@1289 6949 },
nickjillings@1289 6950
nickjillings@1289 6951 removeAttr: function( name ) {
nickjillings@1289 6952 return this.each(function() {
nickjillings@1289 6953 jQuery.removeAttr( this, name );
nickjillings@1289 6954 });
nickjillings@1289 6955 }
nickjillings@1289 6956 });
nickjillings@1289 6957
nickjillings@1289 6958 jQuery.extend({
nickjillings@1289 6959 attr: function( elem, name, value ) {
nickjillings@1289 6960 var hooks, ret,
nickjillings@1289 6961 nType = elem.nodeType;
nickjillings@1289 6962
nickjillings@1289 6963 // don't get/set attributes on text, comment and attribute nodes
nickjillings@1289 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1289 6965 return;
nickjillings@1289 6966 }
nickjillings@1289 6967
nickjillings@1289 6968 // Fallback to prop when attributes are not supported
nickjillings@1289 6969 if ( typeof elem.getAttribute === strundefined ) {
nickjillings@1289 6970 return jQuery.prop( elem, name, value );
nickjillings@1289 6971 }
nickjillings@1289 6972
nickjillings@1289 6973 // All attributes are lowercase
nickjillings@1289 6974 // Grab necessary hook if one is defined
nickjillings@1289 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nickjillings@1289 6976 name = name.toLowerCase();
nickjillings@1289 6977 hooks = jQuery.attrHooks[ name ] ||
nickjillings@1289 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nickjillings@1289 6979 }
nickjillings@1289 6980
nickjillings@1289 6981 if ( value !== undefined ) {
nickjillings@1289 6982
nickjillings@1289 6983 if ( value === null ) {
nickjillings@1289 6984 jQuery.removeAttr( elem, name );
nickjillings@1289 6985
nickjillings@1289 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nickjillings@1289 6987 return ret;
nickjillings@1289 6988
nickjillings@1289 6989 } else {
nickjillings@1289 6990 elem.setAttribute( name, value + "" );
nickjillings@1289 6991 return value;
nickjillings@1289 6992 }
nickjillings@1289 6993
nickjillings@1289 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nickjillings@1289 6995 return ret;
nickjillings@1289 6996
nickjillings@1289 6997 } else {
nickjillings@1289 6998 ret = jQuery.find.attr( elem, name );
nickjillings@1289 6999
nickjillings@1289 7000 // Non-existent attributes return null, we normalize to undefined
nickjillings@1289 7001 return ret == null ?
nickjillings@1289 7002 undefined :
nickjillings@1289 7003 ret;
nickjillings@1289 7004 }
nickjillings@1289 7005 },
nickjillings@1289 7006
nickjillings@1289 7007 removeAttr: function( elem, value ) {
nickjillings@1289 7008 var name, propName,
nickjillings@1289 7009 i = 0,
nickjillings@1289 7010 attrNames = value && value.match( rnotwhite );
nickjillings@1289 7011
nickjillings@1289 7012 if ( attrNames && elem.nodeType === 1 ) {
nickjillings@1289 7013 while ( (name = attrNames[i++]) ) {
nickjillings@1289 7014 propName = jQuery.propFix[ name ] || name;
nickjillings@1289 7015
nickjillings@1289 7016 // Boolean attributes get special treatment (#10870)
nickjillings@1289 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nickjillings@1289 7018 // Set corresponding property to false
nickjillings@1289 7019 elem[ propName ] = false;
nickjillings@1289 7020 }
nickjillings@1289 7021
nickjillings@1289 7022 elem.removeAttribute( name );
nickjillings@1289 7023 }
nickjillings@1289 7024 }
nickjillings@1289 7025 },
nickjillings@1289 7026
nickjillings@1289 7027 attrHooks: {
nickjillings@1289 7028 type: {
nickjillings@1289 7029 set: function( elem, value ) {
nickjillings@1289 7030 if ( !support.radioValue && value === "radio" &&
nickjillings@1289 7031 jQuery.nodeName( elem, "input" ) ) {
nickjillings@1289 7032 var val = elem.value;
nickjillings@1289 7033 elem.setAttribute( "type", value );
nickjillings@1289 7034 if ( val ) {
nickjillings@1289 7035 elem.value = val;
nickjillings@1289 7036 }
nickjillings@1289 7037 return value;
nickjillings@1289 7038 }
nickjillings@1289 7039 }
nickjillings@1289 7040 }
nickjillings@1289 7041 }
nickjillings@1289 7042 });
nickjillings@1289 7043
nickjillings@1289 7044 // Hooks for boolean attributes
nickjillings@1289 7045 boolHook = {
nickjillings@1289 7046 set: function( elem, value, name ) {
nickjillings@1289 7047 if ( value === false ) {
nickjillings@1289 7048 // Remove boolean attributes when set to false
nickjillings@1289 7049 jQuery.removeAttr( elem, name );
nickjillings@1289 7050 } else {
nickjillings@1289 7051 elem.setAttribute( name, name );
nickjillings@1289 7052 }
nickjillings@1289 7053 return name;
nickjillings@1289 7054 }
nickjillings@1289 7055 };
nickjillings@1289 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nickjillings@1289 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nickjillings@1289 7058
nickjillings@1289 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nickjillings@1289 7060 var ret, handle;
nickjillings@1289 7061 if ( !isXML ) {
nickjillings@1289 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nickjillings@1289 7063 handle = attrHandle[ name ];
nickjillings@1289 7064 attrHandle[ name ] = ret;
nickjillings@1289 7065 ret = getter( elem, name, isXML ) != null ?
nickjillings@1289 7066 name.toLowerCase() :
nickjillings@1289 7067 null;
nickjillings@1289 7068 attrHandle[ name ] = handle;
nickjillings@1289 7069 }
nickjillings@1289 7070 return ret;
nickjillings@1289 7071 };
nickjillings@1289 7072 });
nickjillings@1289 7073
nickjillings@1289 7074
nickjillings@1289 7075
nickjillings@1289 7076
nickjillings@1289 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nickjillings@1289 7078
nickjillings@1289 7079 jQuery.fn.extend({
nickjillings@1289 7080 prop: function( name, value ) {
nickjillings@1289 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nickjillings@1289 7082 },
nickjillings@1289 7083
nickjillings@1289 7084 removeProp: function( name ) {
nickjillings@1289 7085 return this.each(function() {
nickjillings@1289 7086 delete this[ jQuery.propFix[ name ] || name ];
nickjillings@1289 7087 });
nickjillings@1289 7088 }
nickjillings@1289 7089 });
nickjillings@1289 7090
nickjillings@1289 7091 jQuery.extend({
nickjillings@1289 7092 propFix: {
nickjillings@1289 7093 "for": "htmlFor",
nickjillings@1289 7094 "class": "className"
nickjillings@1289 7095 },
nickjillings@1289 7096
nickjillings@1289 7097 prop: function( elem, name, value ) {
nickjillings@1289 7098 var ret, hooks, notxml,
nickjillings@1289 7099 nType = elem.nodeType;
nickjillings@1289 7100
nickjillings@1289 7101 // Don't get/set properties on text, comment and attribute nodes
nickjillings@1289 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1289 7103 return;
nickjillings@1289 7104 }
nickjillings@1289 7105
nickjillings@1289 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nickjillings@1289 7107
nickjillings@1289 7108 if ( notxml ) {
nickjillings@1289 7109 // Fix name and attach hooks
nickjillings@1289 7110 name = jQuery.propFix[ name ] || name;
nickjillings@1289 7111 hooks = jQuery.propHooks[ name ];
nickjillings@1289 7112 }
nickjillings@1289 7113
nickjillings@1289 7114 if ( value !== undefined ) {
nickjillings@1289 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nickjillings@1289 7116 ret :
nickjillings@1289 7117 ( elem[ name ] = value );
nickjillings@1289 7118
nickjillings@1289 7119 } else {
nickjillings@1289 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nickjillings@1289 7121 ret :
nickjillings@1289 7122 elem[ name ];
nickjillings@1289 7123 }
nickjillings@1289 7124 },
nickjillings@1289 7125
nickjillings@1289 7126 propHooks: {
nickjillings@1289 7127 tabIndex: {
nickjillings@1289 7128 get: function( elem ) {
nickjillings@1289 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nickjillings@1289 7130 elem.tabIndex :
nickjillings@1289 7131 -1;
nickjillings@1289 7132 }
nickjillings@1289 7133 }
nickjillings@1289 7134 }
nickjillings@1289 7135 });
nickjillings@1289 7136
nickjillings@1289 7137 if ( !support.optSelected ) {
nickjillings@1289 7138 jQuery.propHooks.selected = {
nickjillings@1289 7139 get: function( elem ) {
nickjillings@1289 7140 var parent = elem.parentNode;
nickjillings@1289 7141 if ( parent && parent.parentNode ) {
nickjillings@1289 7142 parent.parentNode.selectedIndex;
nickjillings@1289 7143 }
nickjillings@1289 7144 return null;
nickjillings@1289 7145 }
nickjillings@1289 7146 };
nickjillings@1289 7147 }
nickjillings@1289 7148
nickjillings@1289 7149 jQuery.each([
nickjillings@1289 7150 "tabIndex",
nickjillings@1289 7151 "readOnly",
nickjillings@1289 7152 "maxLength",
nickjillings@1289 7153 "cellSpacing",
nickjillings@1289 7154 "cellPadding",
nickjillings@1289 7155 "rowSpan",
nickjillings@1289 7156 "colSpan",
nickjillings@1289 7157 "useMap",
nickjillings@1289 7158 "frameBorder",
nickjillings@1289 7159 "contentEditable"
nickjillings@1289 7160 ], function() {
nickjillings@1289 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nickjillings@1289 7162 });
nickjillings@1289 7163
nickjillings@1289 7164
nickjillings@1289 7165
nickjillings@1289 7166
nickjillings@1289 7167 var rclass = /[\t\r\n\f]/g;
nickjillings@1289 7168
nickjillings@1289 7169 jQuery.fn.extend({
nickjillings@1289 7170 addClass: function( value ) {
nickjillings@1289 7171 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1289 7172 proceed = typeof value === "string" && value,
nickjillings@1289 7173 i = 0,
nickjillings@1289 7174 len = this.length;
nickjillings@1289 7175
nickjillings@1289 7176 if ( jQuery.isFunction( value ) ) {
nickjillings@1289 7177 return this.each(function( j ) {
nickjillings@1289 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nickjillings@1289 7179 });
nickjillings@1289 7180 }
nickjillings@1289 7181
nickjillings@1289 7182 if ( proceed ) {
nickjillings@1289 7183 // The disjunction here is for better compressibility (see removeClass)
nickjillings@1289 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1289 7185
nickjillings@1289 7186 for ( ; i < len; i++ ) {
nickjillings@1289 7187 elem = this[ i ];
nickjillings@1289 7188 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1289 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1289 7190 " "
nickjillings@1289 7191 );
nickjillings@1289 7192
nickjillings@1289 7193 if ( cur ) {
nickjillings@1289 7194 j = 0;
nickjillings@1289 7195 while ( (clazz = classes[j++]) ) {
nickjillings@1289 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nickjillings@1289 7197 cur += clazz + " ";
nickjillings@1289 7198 }
nickjillings@1289 7199 }
nickjillings@1289 7200
nickjillings@1289 7201 // only assign if different to avoid unneeded rendering.
nickjillings@1289 7202 finalValue = jQuery.trim( cur );
nickjillings@1289 7203 if ( elem.className !== finalValue ) {
nickjillings@1289 7204 elem.className = finalValue;
nickjillings@1289 7205 }
nickjillings@1289 7206 }
nickjillings@1289 7207 }
nickjillings@1289 7208 }
nickjillings@1289 7209
nickjillings@1289 7210 return this;
nickjillings@1289 7211 },
nickjillings@1289 7212
nickjillings@1289 7213 removeClass: function( value ) {
nickjillings@1289 7214 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1289 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nickjillings@1289 7216 i = 0,
nickjillings@1289 7217 len = this.length;
nickjillings@1289 7218
nickjillings@1289 7219 if ( jQuery.isFunction( value ) ) {
nickjillings@1289 7220 return this.each(function( j ) {
nickjillings@1289 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nickjillings@1289 7222 });
nickjillings@1289 7223 }
nickjillings@1289 7224 if ( proceed ) {
nickjillings@1289 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1289 7226
nickjillings@1289 7227 for ( ; i < len; i++ ) {
nickjillings@1289 7228 elem = this[ i ];
nickjillings@1289 7229 // This expression is here for better compressibility (see addClass)
nickjillings@1289 7230 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1289 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1289 7232 ""
nickjillings@1289 7233 );
nickjillings@1289 7234
nickjillings@1289 7235 if ( cur ) {
nickjillings@1289 7236 j = 0;
nickjillings@1289 7237 while ( (clazz = classes[j++]) ) {
nickjillings@1289 7238 // Remove *all* instances
nickjillings@1289 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nickjillings@1289 7240 cur = cur.replace( " " + clazz + " ", " " );
nickjillings@1289 7241 }
nickjillings@1289 7242 }
nickjillings@1289 7243
nickjillings@1289 7244 // Only assign if different to avoid unneeded rendering.
nickjillings@1289 7245 finalValue = value ? jQuery.trim( cur ) : "";
nickjillings@1289 7246 if ( elem.className !== finalValue ) {
nickjillings@1289 7247 elem.className = finalValue;
nickjillings@1289 7248 }
nickjillings@1289 7249 }
nickjillings@1289 7250 }
nickjillings@1289 7251 }
nickjillings@1289 7252
nickjillings@1289 7253 return this;
nickjillings@1289 7254 },
nickjillings@1289 7255
nickjillings@1289 7256 toggleClass: function( value, stateVal ) {
nickjillings@1289 7257 var type = typeof value;
nickjillings@1289 7258
nickjillings@1289 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nickjillings@1289 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nickjillings@1289 7261 }
nickjillings@1289 7262
nickjillings@1289 7263 if ( jQuery.isFunction( value ) ) {
nickjillings@1289 7264 return this.each(function( i ) {
nickjillings@1289 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nickjillings@1289 7266 });
nickjillings@1289 7267 }
nickjillings@1289 7268
nickjillings@1289 7269 return this.each(function() {
nickjillings@1289 7270 if ( type === "string" ) {
nickjillings@1289 7271 // Toggle individual class names
nickjillings@1289 7272 var className,
nickjillings@1289 7273 i = 0,
nickjillings@1289 7274 self = jQuery( this ),
nickjillings@1289 7275 classNames = value.match( rnotwhite ) || [];
nickjillings@1289 7276
nickjillings@1289 7277 while ( (className = classNames[ i++ ]) ) {
nickjillings@1289 7278 // Check each className given, space separated list
nickjillings@1289 7279 if ( self.hasClass( className ) ) {
nickjillings@1289 7280 self.removeClass( className );
nickjillings@1289 7281 } else {
nickjillings@1289 7282 self.addClass( className );
nickjillings@1289 7283 }
nickjillings@1289 7284 }
nickjillings@1289 7285
nickjillings@1289 7286 // Toggle whole class name
nickjillings@1289 7287 } else if ( type === strundefined || type === "boolean" ) {
nickjillings@1289 7288 if ( this.className ) {
nickjillings@1289 7289 // store className if set
nickjillings@1289 7290 data_priv.set( this, "__className__", this.className );
nickjillings@1289 7291 }
nickjillings@1289 7292
nickjillings@1289 7293 // If the element has a class name or if we're passed `false`,
nickjillings@1289 7294 // then remove the whole classname (if there was one, the above saved it).
nickjillings@1289 7295 // Otherwise bring back whatever was previously saved (if anything),
nickjillings@1289 7296 // falling back to the empty string if nothing was stored.
nickjillings@1289 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nickjillings@1289 7298 }
nickjillings@1289 7299 });
nickjillings@1289 7300 },
nickjillings@1289 7301
nickjillings@1289 7302 hasClass: function( selector ) {
nickjillings@1289 7303 var className = " " + selector + " ",
nickjillings@1289 7304 i = 0,
nickjillings@1289 7305 l = this.length;
nickjillings@1289 7306 for ( ; i < l; i++ ) {
nickjillings@1289 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nickjillings@1289 7308 return true;
nickjillings@1289 7309 }
nickjillings@1289 7310 }
nickjillings@1289 7311
nickjillings@1289 7312 return false;
nickjillings@1289 7313 }
nickjillings@1289 7314 });
nickjillings@1289 7315
nickjillings@1289 7316
nickjillings@1289 7317
nickjillings@1289 7318
nickjillings@1289 7319 var rreturn = /\r/g;
nickjillings@1289 7320
nickjillings@1289 7321 jQuery.fn.extend({
nickjillings@1289 7322 val: function( value ) {
nickjillings@1289 7323 var hooks, ret, isFunction,
nickjillings@1289 7324 elem = this[0];
nickjillings@1289 7325
nickjillings@1289 7326 if ( !arguments.length ) {
nickjillings@1289 7327 if ( elem ) {
nickjillings@1289 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nickjillings@1289 7329
nickjillings@1289 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nickjillings@1289 7331 return ret;
nickjillings@1289 7332 }
nickjillings@1289 7333
nickjillings@1289 7334 ret = elem.value;
nickjillings@1289 7335
nickjillings@1289 7336 return typeof ret === "string" ?
nickjillings@1289 7337 // Handle most common string cases
nickjillings@1289 7338 ret.replace(rreturn, "") :
nickjillings@1289 7339 // Handle cases where value is null/undef or number
nickjillings@1289 7340 ret == null ? "" : ret;
nickjillings@1289 7341 }
nickjillings@1289 7342
nickjillings@1289 7343 return;
nickjillings@1289 7344 }
nickjillings@1289 7345
nickjillings@1289 7346 isFunction = jQuery.isFunction( value );
nickjillings@1289 7347
nickjillings@1289 7348 return this.each(function( i ) {
nickjillings@1289 7349 var val;
nickjillings@1289 7350
nickjillings@1289 7351 if ( this.nodeType !== 1 ) {
nickjillings@1289 7352 return;
nickjillings@1289 7353 }
nickjillings@1289 7354
nickjillings@1289 7355 if ( isFunction ) {
nickjillings@1289 7356 val = value.call( this, i, jQuery( this ).val() );
nickjillings@1289 7357 } else {
nickjillings@1289 7358 val = value;
nickjillings@1289 7359 }
nickjillings@1289 7360
nickjillings@1289 7361 // Treat null/undefined as ""; convert numbers to string
nickjillings@1289 7362 if ( val == null ) {
nickjillings@1289 7363 val = "";
nickjillings@1289 7364
nickjillings@1289 7365 } else if ( typeof val === "number" ) {
nickjillings@1289 7366 val += "";
nickjillings@1289 7367
nickjillings@1289 7368 } else if ( jQuery.isArray( val ) ) {
nickjillings@1289 7369 val = jQuery.map( val, function( value ) {
nickjillings@1289 7370 return value == null ? "" : value + "";
nickjillings@1289 7371 });
nickjillings@1289 7372 }
nickjillings@1289 7373
nickjillings@1289 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nickjillings@1289 7375
nickjillings@1289 7376 // If set returns undefined, fall back to normal setting
nickjillings@1289 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nickjillings@1289 7378 this.value = val;
nickjillings@1289 7379 }
nickjillings@1289 7380 });
nickjillings@1289 7381 }
nickjillings@1289 7382 });
nickjillings@1289 7383
nickjillings@1289 7384 jQuery.extend({
nickjillings@1289 7385 valHooks: {
nickjillings@1289 7386 option: {
nickjillings@1289 7387 get: function( elem ) {
nickjillings@1289 7388 var val = jQuery.find.attr( elem, "value" );
nickjillings@1289 7389 return val != null ?
nickjillings@1289 7390 val :
nickjillings@1289 7391 // Support: IE10-11+
nickjillings@1289 7392 // option.text throws exceptions (#14686, #14858)
nickjillings@1289 7393 jQuery.trim( jQuery.text( elem ) );
nickjillings@1289 7394 }
nickjillings@1289 7395 },
nickjillings@1289 7396 select: {
nickjillings@1289 7397 get: function( elem ) {
nickjillings@1289 7398 var value, option,
nickjillings@1289 7399 options = elem.options,
nickjillings@1289 7400 index = elem.selectedIndex,
nickjillings@1289 7401 one = elem.type === "select-one" || index < 0,
nickjillings@1289 7402 values = one ? null : [],
nickjillings@1289 7403 max = one ? index + 1 : options.length,
nickjillings@1289 7404 i = index < 0 ?
nickjillings@1289 7405 max :
nickjillings@1289 7406 one ? index : 0;
nickjillings@1289 7407
nickjillings@1289 7408 // Loop through all the selected options
nickjillings@1289 7409 for ( ; i < max; i++ ) {
nickjillings@1289 7410 option = options[ i ];
nickjillings@1289 7411
nickjillings@1289 7412 // IE6-9 doesn't update selected after form reset (#2551)
nickjillings@1289 7413 if ( ( option.selected || i === index ) &&
nickjillings@1289 7414 // Don't return options that are disabled or in a disabled optgroup
nickjillings@1289 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nickjillings@1289 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nickjillings@1289 7417
nickjillings@1289 7418 // Get the specific value for the option
nickjillings@1289 7419 value = jQuery( option ).val();
nickjillings@1289 7420
nickjillings@1289 7421 // We don't need an array for one selects
nickjillings@1289 7422 if ( one ) {
nickjillings@1289 7423 return value;
nickjillings@1289 7424 }
nickjillings@1289 7425
nickjillings@1289 7426 // Multi-Selects return an array
nickjillings@1289 7427 values.push( value );
nickjillings@1289 7428 }
nickjillings@1289 7429 }
nickjillings@1289 7430
nickjillings@1289 7431 return values;
nickjillings@1289 7432 },
nickjillings@1289 7433
nickjillings@1289 7434 set: function( elem, value ) {
nickjillings@1289 7435 var optionSet, option,
nickjillings@1289 7436 options = elem.options,
nickjillings@1289 7437 values = jQuery.makeArray( value ),
nickjillings@1289 7438 i = options.length;
nickjillings@1289 7439
nickjillings@1289 7440 while ( i-- ) {
nickjillings@1289 7441 option = options[ i ];
nickjillings@1289 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nickjillings@1289 7443 optionSet = true;
nickjillings@1289 7444 }
nickjillings@1289 7445 }
nickjillings@1289 7446
nickjillings@1289 7447 // Force browsers to behave consistently when non-matching value is set
nickjillings@1289 7448 if ( !optionSet ) {
nickjillings@1289 7449 elem.selectedIndex = -1;
nickjillings@1289 7450 }
nickjillings@1289 7451 return values;
nickjillings@1289 7452 }
nickjillings@1289 7453 }
nickjillings@1289 7454 }
nickjillings@1289 7455 });
nickjillings@1289 7456
nickjillings@1289 7457 // Radios and checkboxes getter/setter
nickjillings@1289 7458 jQuery.each([ "radio", "checkbox" ], function() {
nickjillings@1289 7459 jQuery.valHooks[ this ] = {
nickjillings@1289 7460 set: function( elem, value ) {
nickjillings@1289 7461 if ( jQuery.isArray( value ) ) {
nickjillings@1289 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nickjillings@1289 7463 }
nickjillings@1289 7464 }
nickjillings@1289 7465 };
nickjillings@1289 7466 if ( !support.checkOn ) {
nickjillings@1289 7467 jQuery.valHooks[ this ].get = function( elem ) {
nickjillings@1289 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nickjillings@1289 7469 };
nickjillings@1289 7470 }
nickjillings@1289 7471 });
nickjillings@1289 7472
nickjillings@1289 7473
nickjillings@1289 7474
nickjillings@1289 7475
nickjillings@1289 7476 // Return jQuery for attributes-only inclusion
nickjillings@1289 7477
nickjillings@1289 7478
nickjillings@1289 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nickjillings@1289 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nickjillings@1289 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nickjillings@1289 7482
nickjillings@1289 7483 // Handle event binding
nickjillings@1289 7484 jQuery.fn[ name ] = function( data, fn ) {
nickjillings@1289 7485 return arguments.length > 0 ?
nickjillings@1289 7486 this.on( name, null, data, fn ) :
nickjillings@1289 7487 this.trigger( name );
nickjillings@1289 7488 };
nickjillings@1289 7489 });
nickjillings@1289 7490
nickjillings@1289 7491 jQuery.fn.extend({
nickjillings@1289 7492 hover: function( fnOver, fnOut ) {
nickjillings@1289 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nickjillings@1289 7494 },
nickjillings@1289 7495
nickjillings@1289 7496 bind: function( types, data, fn ) {
nickjillings@1289 7497 return this.on( types, null, data, fn );
nickjillings@1289 7498 },
nickjillings@1289 7499 unbind: function( types, fn ) {
nickjillings@1289 7500 return this.off( types, null, fn );
nickjillings@1289 7501 },
nickjillings@1289 7502
nickjillings@1289 7503 delegate: function( selector, types, data, fn ) {
nickjillings@1289 7504 return this.on( types, selector, data, fn );
nickjillings@1289 7505 },
nickjillings@1289 7506 undelegate: function( selector, types, fn ) {
nickjillings@1289 7507 // ( namespace ) or ( selector, types [, fn] )
nickjillings@1289 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nickjillings@1289 7509 }
nickjillings@1289 7510 });
nickjillings@1289 7511
nickjillings@1289 7512
nickjillings@1289 7513 var nonce = jQuery.now();
nickjillings@1289 7514
nickjillings@1289 7515 var rquery = (/\?/);
nickjillings@1289 7516
nickjillings@1289 7517
nickjillings@1289 7518
nickjillings@1289 7519 // Support: Android 2.3
nickjillings@1289 7520 // Workaround failure to string-cast null input
nickjillings@1289 7521 jQuery.parseJSON = function( data ) {
nickjillings@1289 7522 return JSON.parse( data + "" );
nickjillings@1289 7523 };
nickjillings@1289 7524
nickjillings@1289 7525
nickjillings@1289 7526 // Cross-browser xml parsing
nickjillings@1289 7527 jQuery.parseXML = function( data ) {
nickjillings@1289 7528 var xml, tmp;
nickjillings@1289 7529 if ( !data || typeof data !== "string" ) {
nickjillings@1289 7530 return null;
nickjillings@1289 7531 }
nickjillings@1289 7532
nickjillings@1289 7533 // Support: IE9
nickjillings@1289 7534 try {
nickjillings@1289 7535 tmp = new DOMParser();
nickjillings@1289 7536 xml = tmp.parseFromString( data, "text/xml" );
nickjillings@1289 7537 } catch ( e ) {
nickjillings@1289 7538 xml = undefined;
nickjillings@1289 7539 }
nickjillings@1289 7540
nickjillings@1289 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nickjillings@1289 7542 jQuery.error( "Invalid XML: " + data );
nickjillings@1289 7543 }
nickjillings@1289 7544 return xml;
nickjillings@1289 7545 };
nickjillings@1289 7546
nickjillings@1289 7547
nickjillings@1289 7548 var
nickjillings@1289 7549 rhash = /#.*$/,
nickjillings@1289 7550 rts = /([?&])_=[^&]*/,
nickjillings@1289 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nickjillings@1289 7552 // #7653, #8125, #8152: local protocol detection
nickjillings@1289 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nickjillings@1289 7554 rnoContent = /^(?:GET|HEAD)$/,
nickjillings@1289 7555 rprotocol = /^\/\//,
nickjillings@1289 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nickjillings@1289 7557
nickjillings@1289 7558 /* Prefilters
nickjillings@1289 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nickjillings@1289 7560 * 2) These are called:
nickjillings@1289 7561 * - BEFORE asking for a transport
nickjillings@1289 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nickjillings@1289 7563 * 3) key is the dataType
nickjillings@1289 7564 * 4) the catchall symbol "*" can be used
nickjillings@1289 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nickjillings@1289 7566 */
nickjillings@1289 7567 prefilters = {},
nickjillings@1289 7568
nickjillings@1289 7569 /* Transports bindings
nickjillings@1289 7570 * 1) key is the dataType
nickjillings@1289 7571 * 2) the catchall symbol "*" can be used
nickjillings@1289 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nickjillings@1289 7573 */
nickjillings@1289 7574 transports = {},
nickjillings@1289 7575
nickjillings@1289 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nickjillings@1289 7577 allTypes = "*/".concat( "*" ),
nickjillings@1289 7578
nickjillings@1289 7579 // Document location
nickjillings@1289 7580 ajaxLocation = window.location.href,
nickjillings@1289 7581
nickjillings@1289 7582 // Segment location into parts
nickjillings@1289 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nickjillings@1289 7584
nickjillings@1289 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nickjillings@1289 7586 function addToPrefiltersOrTransports( structure ) {
nickjillings@1289 7587
nickjillings@1289 7588 // dataTypeExpression is optional and defaults to "*"
nickjillings@1289 7589 return function( dataTypeExpression, func ) {
nickjillings@1289 7590
nickjillings@1289 7591 if ( typeof dataTypeExpression !== "string" ) {
nickjillings@1289 7592 func = dataTypeExpression;
nickjillings@1289 7593 dataTypeExpression = "*";
nickjillings@1289 7594 }
nickjillings@1289 7595
nickjillings@1289 7596 var dataType,
nickjillings@1289 7597 i = 0,
nickjillings@1289 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nickjillings@1289 7599
nickjillings@1289 7600 if ( jQuery.isFunction( func ) ) {
nickjillings@1289 7601 // For each dataType in the dataTypeExpression
nickjillings@1289 7602 while ( (dataType = dataTypes[i++]) ) {
nickjillings@1289 7603 // Prepend if requested
nickjillings@1289 7604 if ( dataType[0] === "+" ) {
nickjillings@1289 7605 dataType = dataType.slice( 1 ) || "*";
nickjillings@1289 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nickjillings@1289 7607
nickjillings@1289 7608 // Otherwise append
nickjillings@1289 7609 } else {
nickjillings@1289 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nickjillings@1289 7611 }
nickjillings@1289 7612 }
nickjillings@1289 7613 }
nickjillings@1289 7614 };
nickjillings@1289 7615 }
nickjillings@1289 7616
nickjillings@1289 7617 // Base inspection function for prefilters and transports
nickjillings@1289 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nickjillings@1289 7619
nickjillings@1289 7620 var inspected = {},
nickjillings@1289 7621 seekingTransport = ( structure === transports );
nickjillings@1289 7622
nickjillings@1289 7623 function inspect( dataType ) {
nickjillings@1289 7624 var selected;
nickjillings@1289 7625 inspected[ dataType ] = true;
nickjillings@1289 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nickjillings@1289 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nickjillings@1289 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nickjillings@1289 7629 options.dataTypes.unshift( dataTypeOrTransport );
nickjillings@1289 7630 inspect( dataTypeOrTransport );
nickjillings@1289 7631 return false;
nickjillings@1289 7632 } else if ( seekingTransport ) {
nickjillings@1289 7633 return !( selected = dataTypeOrTransport );
nickjillings@1289 7634 }
nickjillings@1289 7635 });
nickjillings@1289 7636 return selected;
nickjillings@1289 7637 }
nickjillings@1289 7638
nickjillings@1289 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nickjillings@1289 7640 }
nickjillings@1289 7641
nickjillings@1289 7642 // A special extend for ajax options
nickjillings@1289 7643 // that takes "flat" options (not to be deep extended)
nickjillings@1289 7644 // Fixes #9887
nickjillings@1289 7645 function ajaxExtend( target, src ) {
nickjillings@1289 7646 var key, deep,
nickjillings@1289 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nickjillings@1289 7648
nickjillings@1289 7649 for ( key in src ) {
nickjillings@1289 7650 if ( src[ key ] !== undefined ) {
nickjillings@1289 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nickjillings@1289 7652 }
nickjillings@1289 7653 }
nickjillings@1289 7654 if ( deep ) {
nickjillings@1289 7655 jQuery.extend( true, target, deep );
nickjillings@1289 7656 }
nickjillings@1289 7657
nickjillings@1289 7658 return target;
nickjillings@1289 7659 }
nickjillings@1289 7660
nickjillings@1289 7661 /* Handles responses to an ajax request:
nickjillings@1289 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nickjillings@1289 7663 * - returns the corresponding response
nickjillings@1289 7664 */
nickjillings@1289 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nickjillings@1289 7666
nickjillings@1289 7667 var ct, type, finalDataType, firstDataType,
nickjillings@1289 7668 contents = s.contents,
nickjillings@1289 7669 dataTypes = s.dataTypes;
nickjillings@1289 7670
nickjillings@1289 7671 // Remove auto dataType and get content-type in the process
nickjillings@1289 7672 while ( dataTypes[ 0 ] === "*" ) {
nickjillings@1289 7673 dataTypes.shift();
nickjillings@1289 7674 if ( ct === undefined ) {
nickjillings@1289 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nickjillings@1289 7676 }
nickjillings@1289 7677 }
nickjillings@1289 7678
nickjillings@1289 7679 // Check if we're dealing with a known content-type
nickjillings@1289 7680 if ( ct ) {
nickjillings@1289 7681 for ( type in contents ) {
nickjillings@1289 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nickjillings@1289 7683 dataTypes.unshift( type );
nickjillings@1289 7684 break;
nickjillings@1289 7685 }
nickjillings@1289 7686 }
nickjillings@1289 7687 }
nickjillings@1289 7688
nickjillings@1289 7689 // Check to see if we have a response for the expected dataType
nickjillings@1289 7690 if ( dataTypes[ 0 ] in responses ) {
nickjillings@1289 7691 finalDataType = dataTypes[ 0 ];
nickjillings@1289 7692 } else {
nickjillings@1289 7693 // Try convertible dataTypes
nickjillings@1289 7694 for ( type in responses ) {
nickjillings@1289 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nickjillings@1289 7696 finalDataType = type;
nickjillings@1289 7697 break;
nickjillings@1289 7698 }
nickjillings@1289 7699 if ( !firstDataType ) {
nickjillings@1289 7700 firstDataType = type;
nickjillings@1289 7701 }
nickjillings@1289 7702 }
nickjillings@1289 7703 // Or just use first one
nickjillings@1289 7704 finalDataType = finalDataType || firstDataType;
nickjillings@1289 7705 }
nickjillings@1289 7706
nickjillings@1289 7707 // If we found a dataType
nickjillings@1289 7708 // We add the dataType to the list if needed
nickjillings@1289 7709 // and return the corresponding response
nickjillings@1289 7710 if ( finalDataType ) {
nickjillings@1289 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nickjillings@1289 7712 dataTypes.unshift( finalDataType );
nickjillings@1289 7713 }
nickjillings@1289 7714 return responses[ finalDataType ];
nickjillings@1289 7715 }
nickjillings@1289 7716 }
nickjillings@1289 7717
nickjillings@1289 7718 /* Chain conversions given the request and the original response
nickjillings@1289 7719 * Also sets the responseXXX fields on the jqXHR instance
nickjillings@1289 7720 */
nickjillings@1289 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nickjillings@1289 7722 var conv2, current, conv, tmp, prev,
nickjillings@1289 7723 converters = {},
nickjillings@1289 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nickjillings@1289 7725 dataTypes = s.dataTypes.slice();
nickjillings@1289 7726
nickjillings@1289 7727 // Create converters map with lowercased keys
nickjillings@1289 7728 if ( dataTypes[ 1 ] ) {
nickjillings@1289 7729 for ( conv in s.converters ) {
nickjillings@1289 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nickjillings@1289 7731 }
nickjillings@1289 7732 }
nickjillings@1289 7733
nickjillings@1289 7734 current = dataTypes.shift();
nickjillings@1289 7735
nickjillings@1289 7736 // Convert to each sequential dataType
nickjillings@1289 7737 while ( current ) {
nickjillings@1289 7738
nickjillings@1289 7739 if ( s.responseFields[ current ] ) {
nickjillings@1289 7740 jqXHR[ s.responseFields[ current ] ] = response;
nickjillings@1289 7741 }
nickjillings@1289 7742
nickjillings@1289 7743 // Apply the dataFilter if provided
nickjillings@1289 7744 if ( !prev && isSuccess && s.dataFilter ) {
nickjillings@1289 7745 response = s.dataFilter( response, s.dataType );
nickjillings@1289 7746 }
nickjillings@1289 7747
nickjillings@1289 7748 prev = current;
nickjillings@1289 7749 current = dataTypes.shift();
nickjillings@1289 7750
nickjillings@1289 7751 if ( current ) {
nickjillings@1289 7752
nickjillings@1289 7753 // There's only work to do if current dataType is non-auto
nickjillings@1289 7754 if ( current === "*" ) {
nickjillings@1289 7755
nickjillings@1289 7756 current = prev;
nickjillings@1289 7757
nickjillings@1289 7758 // Convert response if prev dataType is non-auto and differs from current
nickjillings@1289 7759 } else if ( prev !== "*" && prev !== current ) {
nickjillings@1289 7760
nickjillings@1289 7761 // Seek a direct converter
nickjillings@1289 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nickjillings@1289 7763
nickjillings@1289 7764 // If none found, seek a pair
nickjillings@1289 7765 if ( !conv ) {
nickjillings@1289 7766 for ( conv2 in converters ) {
nickjillings@1289 7767
nickjillings@1289 7768 // If conv2 outputs current
nickjillings@1289 7769 tmp = conv2.split( " " );
nickjillings@1289 7770 if ( tmp[ 1 ] === current ) {
nickjillings@1289 7771
nickjillings@1289 7772 // If prev can be converted to accepted input
nickjillings@1289 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nickjillings@1289 7774 converters[ "* " + tmp[ 0 ] ];
nickjillings@1289 7775 if ( conv ) {
nickjillings@1289 7776 // Condense equivalence converters
nickjillings@1289 7777 if ( conv === true ) {
nickjillings@1289 7778 conv = converters[ conv2 ];
nickjillings@1289 7779
nickjillings@1289 7780 // Otherwise, insert the intermediate dataType
nickjillings@1289 7781 } else if ( converters[ conv2 ] !== true ) {
nickjillings@1289 7782 current = tmp[ 0 ];
nickjillings@1289 7783 dataTypes.unshift( tmp[ 1 ] );
nickjillings@1289 7784 }
nickjillings@1289 7785 break;
nickjillings@1289 7786 }
nickjillings@1289 7787 }
nickjillings@1289 7788 }
nickjillings@1289 7789 }
nickjillings@1289 7790
nickjillings@1289 7791 // Apply converter (if not an equivalence)
nickjillings@1289 7792 if ( conv !== true ) {
nickjillings@1289 7793
nickjillings@1289 7794 // Unless errors are allowed to bubble, catch and return them
nickjillings@1289 7795 if ( conv && s[ "throws" ] ) {
nickjillings@1289 7796 response = conv( response );
nickjillings@1289 7797 } else {
nickjillings@1289 7798 try {
nickjillings@1289 7799 response = conv( response );
nickjillings@1289 7800 } catch ( e ) {
nickjillings@1289 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nickjillings@1289 7802 }
nickjillings@1289 7803 }
nickjillings@1289 7804 }
nickjillings@1289 7805 }
nickjillings@1289 7806 }
nickjillings@1289 7807 }
nickjillings@1289 7808
nickjillings@1289 7809 return { state: "success", data: response };
nickjillings@1289 7810 }
nickjillings@1289 7811
nickjillings@1289 7812 jQuery.extend({
nickjillings@1289 7813
nickjillings@1289 7814 // Counter for holding the number of active queries
nickjillings@1289 7815 active: 0,
nickjillings@1289 7816
nickjillings@1289 7817 // Last-Modified header cache for next request
nickjillings@1289 7818 lastModified: {},
nickjillings@1289 7819 etag: {},
nickjillings@1289 7820
nickjillings@1289 7821 ajaxSettings: {
nickjillings@1289 7822 url: ajaxLocation,
nickjillings@1289 7823 type: "GET",
nickjillings@1289 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nickjillings@1289 7825 global: true,
nickjillings@1289 7826 processData: true,
nickjillings@1289 7827 async: true,
nickjillings@1289 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nickjillings@1289 7829 /*
nickjillings@1289 7830 timeout: 0,
nickjillings@1289 7831 data: null,
nickjillings@1289 7832 dataType: null,
nickjillings@1289 7833 username: null,
nickjillings@1289 7834 password: null,
nickjillings@1289 7835 cache: null,
nickjillings@1289 7836 throws: false,
nickjillings@1289 7837 traditional: false,
nickjillings@1289 7838 headers: {},
nickjillings@1289 7839 */
nickjillings@1289 7840
nickjillings@1289 7841 accepts: {
nickjillings@1289 7842 "*": allTypes,
nickjillings@1289 7843 text: "text/plain",
nickjillings@1289 7844 html: "text/html",
nickjillings@1289 7845 xml: "application/xml, text/xml",
nickjillings@1289 7846 json: "application/json, text/javascript"
nickjillings@1289 7847 },
nickjillings@1289 7848
nickjillings@1289 7849 contents: {
nickjillings@1289 7850 xml: /xml/,
nickjillings@1289 7851 html: /html/,
nickjillings@1289 7852 json: /json/
nickjillings@1289 7853 },
nickjillings@1289 7854
nickjillings@1289 7855 responseFields: {
nickjillings@1289 7856 xml: "responseXML",
nickjillings@1289 7857 text: "responseText",
nickjillings@1289 7858 json: "responseJSON"
nickjillings@1289 7859 },
nickjillings@1289 7860
nickjillings@1289 7861 // Data converters
nickjillings@1289 7862 // Keys separate source (or catchall "*") and destination types with a single space
nickjillings@1289 7863 converters: {
nickjillings@1289 7864
nickjillings@1289 7865 // Convert anything to text
nickjillings@1289 7866 "* text": String,
nickjillings@1289 7867
nickjillings@1289 7868 // Text to html (true = no transformation)
nickjillings@1289 7869 "text html": true,
nickjillings@1289 7870
nickjillings@1289 7871 // Evaluate text as a json expression
nickjillings@1289 7872 "text json": jQuery.parseJSON,
nickjillings@1289 7873
nickjillings@1289 7874 // Parse text as xml
nickjillings@1289 7875 "text xml": jQuery.parseXML
nickjillings@1289 7876 },
nickjillings@1289 7877
nickjillings@1289 7878 // For options that shouldn't be deep extended:
nickjillings@1289 7879 // you can add your own custom options here if
nickjillings@1289 7880 // and when you create one that shouldn't be
nickjillings@1289 7881 // deep extended (see ajaxExtend)
nickjillings@1289 7882 flatOptions: {
nickjillings@1289 7883 url: true,
nickjillings@1289 7884 context: true
nickjillings@1289 7885 }
nickjillings@1289 7886 },
nickjillings@1289 7887
nickjillings@1289 7888 // Creates a full fledged settings object into target
nickjillings@1289 7889 // with both ajaxSettings and settings fields.
nickjillings@1289 7890 // If target is omitted, writes into ajaxSettings.
nickjillings@1289 7891 ajaxSetup: function( target, settings ) {
nickjillings@1289 7892 return settings ?
nickjillings@1289 7893
nickjillings@1289 7894 // Building a settings object
nickjillings@1289 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nickjillings@1289 7896
nickjillings@1289 7897 // Extending ajaxSettings
nickjillings@1289 7898 ajaxExtend( jQuery.ajaxSettings, target );
nickjillings@1289 7899 },
nickjillings@1289 7900
nickjillings@1289 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nickjillings@1289 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nickjillings@1289 7903
nickjillings@1289 7904 // Main method
nickjillings@1289 7905 ajax: function( url, options ) {
nickjillings@1289 7906
nickjillings@1289 7907 // If url is an object, simulate pre-1.5 signature
nickjillings@1289 7908 if ( typeof url === "object" ) {
nickjillings@1289 7909 options = url;
nickjillings@1289 7910 url = undefined;
nickjillings@1289 7911 }
nickjillings@1289 7912
nickjillings@1289 7913 // Force options to be an object
nickjillings@1289 7914 options = options || {};
nickjillings@1289 7915
nickjillings@1289 7916 var transport,
nickjillings@1289 7917 // URL without anti-cache param
nickjillings@1289 7918 cacheURL,
nickjillings@1289 7919 // Response headers
nickjillings@1289 7920 responseHeadersString,
nickjillings@1289 7921 responseHeaders,
nickjillings@1289 7922 // timeout handle
nickjillings@1289 7923 timeoutTimer,
nickjillings@1289 7924 // Cross-domain detection vars
nickjillings@1289 7925 parts,
nickjillings@1289 7926 // To know if global events are to be dispatched
nickjillings@1289 7927 fireGlobals,
nickjillings@1289 7928 // Loop variable
nickjillings@1289 7929 i,
nickjillings@1289 7930 // Create the final options object
nickjillings@1289 7931 s = jQuery.ajaxSetup( {}, options ),
nickjillings@1289 7932 // Callbacks context
nickjillings@1289 7933 callbackContext = s.context || s,
nickjillings@1289 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nickjillings@1289 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nickjillings@1289 7936 jQuery( callbackContext ) :
nickjillings@1289 7937 jQuery.event,
nickjillings@1289 7938 // Deferreds
nickjillings@1289 7939 deferred = jQuery.Deferred(),
nickjillings@1289 7940 completeDeferred = jQuery.Callbacks("once memory"),
nickjillings@1289 7941 // Status-dependent callbacks
nickjillings@1289 7942 statusCode = s.statusCode || {},
nickjillings@1289 7943 // Headers (they are sent all at once)
nickjillings@1289 7944 requestHeaders = {},
nickjillings@1289 7945 requestHeadersNames = {},
nickjillings@1289 7946 // The jqXHR state
nickjillings@1289 7947 state = 0,
nickjillings@1289 7948 // Default abort message
nickjillings@1289 7949 strAbort = "canceled",
nickjillings@1289 7950 // Fake xhr
nickjillings@1289 7951 jqXHR = {
nickjillings@1289 7952 readyState: 0,
nickjillings@1289 7953
nickjillings@1289 7954 // Builds headers hashtable if needed
nickjillings@1289 7955 getResponseHeader: function( key ) {
nickjillings@1289 7956 var match;
nickjillings@1289 7957 if ( state === 2 ) {
nickjillings@1289 7958 if ( !responseHeaders ) {
nickjillings@1289 7959 responseHeaders = {};
nickjillings@1289 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nickjillings@1289 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nickjillings@1289 7962 }
nickjillings@1289 7963 }
nickjillings@1289 7964 match = responseHeaders[ key.toLowerCase() ];
nickjillings@1289 7965 }
nickjillings@1289 7966 return match == null ? null : match;
nickjillings@1289 7967 },
nickjillings@1289 7968
nickjillings@1289 7969 // Raw string
nickjillings@1289 7970 getAllResponseHeaders: function() {
nickjillings@1289 7971 return state === 2 ? responseHeadersString : null;
nickjillings@1289 7972 },
nickjillings@1289 7973
nickjillings@1289 7974 // Caches the header
nickjillings@1289 7975 setRequestHeader: function( name, value ) {
nickjillings@1289 7976 var lname = name.toLowerCase();
nickjillings@1289 7977 if ( !state ) {
nickjillings@1289 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nickjillings@1289 7979 requestHeaders[ name ] = value;
nickjillings@1289 7980 }
nickjillings@1289 7981 return this;
nickjillings@1289 7982 },
nickjillings@1289 7983
nickjillings@1289 7984 // Overrides response content-type header
nickjillings@1289 7985 overrideMimeType: function( type ) {
nickjillings@1289 7986 if ( !state ) {
nickjillings@1289 7987 s.mimeType = type;
nickjillings@1289 7988 }
nickjillings@1289 7989 return this;
nickjillings@1289 7990 },
nickjillings@1289 7991
nickjillings@1289 7992 // Status-dependent callbacks
nickjillings@1289 7993 statusCode: function( map ) {
nickjillings@1289 7994 var code;
nickjillings@1289 7995 if ( map ) {
nickjillings@1289 7996 if ( state < 2 ) {
nickjillings@1289 7997 for ( code in map ) {
nickjillings@1289 7998 // Lazy-add the new callback in a way that preserves old ones
nickjillings@1289 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nickjillings@1289 8000 }
nickjillings@1289 8001 } else {
nickjillings@1289 8002 // Execute the appropriate callbacks
nickjillings@1289 8003 jqXHR.always( map[ jqXHR.status ] );
nickjillings@1289 8004 }
nickjillings@1289 8005 }
nickjillings@1289 8006 return this;
nickjillings@1289 8007 },
nickjillings@1289 8008
nickjillings@1289 8009 // Cancel the request
nickjillings@1289 8010 abort: function( statusText ) {
nickjillings@1289 8011 var finalText = statusText || strAbort;
nickjillings@1289 8012 if ( transport ) {
nickjillings@1289 8013 transport.abort( finalText );
nickjillings@1289 8014 }
nickjillings@1289 8015 done( 0, finalText );
nickjillings@1289 8016 return this;
nickjillings@1289 8017 }
nickjillings@1289 8018 };
nickjillings@1289 8019
nickjillings@1289 8020 // Attach deferreds
nickjillings@1289 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nickjillings@1289 8022 jqXHR.success = jqXHR.done;
nickjillings@1289 8023 jqXHR.error = jqXHR.fail;
nickjillings@1289 8024
nickjillings@1289 8025 // Remove hash character (#7531: and string promotion)
nickjillings@1289 8026 // Add protocol if not provided (prefilters might expect it)
nickjillings@1289 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nickjillings@1289 8028 // We also use the url parameter if available
nickjillings@1289 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nickjillings@1289 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nickjillings@1289 8031
nickjillings@1289 8032 // Alias method option to type as per ticket #12004
nickjillings@1289 8033 s.type = options.method || options.type || s.method || s.type;
nickjillings@1289 8034
nickjillings@1289 8035 // Extract dataTypes list
nickjillings@1289 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nickjillings@1289 8037
nickjillings@1289 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nickjillings@1289 8039 if ( s.crossDomain == null ) {
nickjillings@1289 8040 parts = rurl.exec( s.url.toLowerCase() );
nickjillings@1289 8041 s.crossDomain = !!( parts &&
nickjillings@1289 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nickjillings@1289 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nickjillings@1289 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nickjillings@1289 8045 );
nickjillings@1289 8046 }
nickjillings@1289 8047
nickjillings@1289 8048 // Convert data if not already a string
nickjillings@1289 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nickjillings@1289 8050 s.data = jQuery.param( s.data, s.traditional );
nickjillings@1289 8051 }
nickjillings@1289 8052
nickjillings@1289 8053 // Apply prefilters
nickjillings@1289 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nickjillings@1289 8055
nickjillings@1289 8056 // If request was aborted inside a prefilter, stop there
nickjillings@1289 8057 if ( state === 2 ) {
nickjillings@1289 8058 return jqXHR;
nickjillings@1289 8059 }
nickjillings@1289 8060
nickjillings@1289 8061 // We can fire global events as of now if asked to
nickjillings@1289 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nickjillings@1289 8063 fireGlobals = jQuery.event && s.global;
nickjillings@1289 8064
nickjillings@1289 8065 // Watch for a new set of requests
nickjillings@1289 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nickjillings@1289 8067 jQuery.event.trigger("ajaxStart");
nickjillings@1289 8068 }
nickjillings@1289 8069
nickjillings@1289 8070 // Uppercase the type
nickjillings@1289 8071 s.type = s.type.toUpperCase();
nickjillings@1289 8072
nickjillings@1289 8073 // Determine if request has content
nickjillings@1289 8074 s.hasContent = !rnoContent.test( s.type );
nickjillings@1289 8075
nickjillings@1289 8076 // Save the URL in case we're toying with the If-Modified-Since
nickjillings@1289 8077 // and/or If-None-Match header later on
nickjillings@1289 8078 cacheURL = s.url;
nickjillings@1289 8079
nickjillings@1289 8080 // More options handling for requests with no content
nickjillings@1289 8081 if ( !s.hasContent ) {
nickjillings@1289 8082
nickjillings@1289 8083 // If data is available, append data to url
nickjillings@1289 8084 if ( s.data ) {
nickjillings@1289 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nickjillings@1289 8086 // #9682: remove data so that it's not used in an eventual retry
nickjillings@1289 8087 delete s.data;
nickjillings@1289 8088 }
nickjillings@1289 8089
nickjillings@1289 8090 // Add anti-cache in url if needed
nickjillings@1289 8091 if ( s.cache === false ) {
nickjillings@1289 8092 s.url = rts.test( cacheURL ) ?
nickjillings@1289 8093
nickjillings@1289 8094 // If there is already a '_' parameter, set its value
nickjillings@1289 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nickjillings@1289 8096
nickjillings@1289 8097 // Otherwise add one to the end
nickjillings@1289 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nickjillings@1289 8099 }
nickjillings@1289 8100 }
nickjillings@1289 8101
nickjillings@1289 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1289 8103 if ( s.ifModified ) {
nickjillings@1289 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nickjillings@1289 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nickjillings@1289 8106 }
nickjillings@1289 8107 if ( jQuery.etag[ cacheURL ] ) {
nickjillings@1289 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nickjillings@1289 8109 }
nickjillings@1289 8110 }
nickjillings@1289 8111
nickjillings@1289 8112 // Set the correct header, if data is being sent
nickjillings@1289 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nickjillings@1289 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nickjillings@1289 8115 }
nickjillings@1289 8116
nickjillings@1289 8117 // Set the Accepts header for the server, depending on the dataType
nickjillings@1289 8118 jqXHR.setRequestHeader(
nickjillings@1289 8119 "Accept",
nickjillings@1289 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nickjillings@1289 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nickjillings@1289 8122 s.accepts[ "*" ]
nickjillings@1289 8123 );
nickjillings@1289 8124
nickjillings@1289 8125 // Check for headers option
nickjillings@1289 8126 for ( i in s.headers ) {
nickjillings@1289 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nickjillings@1289 8128 }
nickjillings@1289 8129
nickjillings@1289 8130 // Allow custom headers/mimetypes and early abort
nickjillings@1289 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nickjillings@1289 8132 // Abort if not done already and return
nickjillings@1289 8133 return jqXHR.abort();
nickjillings@1289 8134 }
nickjillings@1289 8135
nickjillings@1289 8136 // Aborting is no longer a cancellation
nickjillings@1289 8137 strAbort = "abort";
nickjillings@1289 8138
nickjillings@1289 8139 // Install callbacks on deferreds
nickjillings@1289 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nickjillings@1289 8141 jqXHR[ i ]( s[ i ] );
nickjillings@1289 8142 }
nickjillings@1289 8143
nickjillings@1289 8144 // Get transport
nickjillings@1289 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nickjillings@1289 8146
nickjillings@1289 8147 // If no transport, we auto-abort
nickjillings@1289 8148 if ( !transport ) {
nickjillings@1289 8149 done( -1, "No Transport" );
nickjillings@1289 8150 } else {
nickjillings@1289 8151 jqXHR.readyState = 1;
nickjillings@1289 8152
nickjillings@1289 8153 // Send global event
nickjillings@1289 8154 if ( fireGlobals ) {
nickjillings@1289 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nickjillings@1289 8156 }
nickjillings@1289 8157 // Timeout
nickjillings@1289 8158 if ( s.async && s.timeout > 0 ) {
nickjillings@1289 8159 timeoutTimer = setTimeout(function() {
nickjillings@1289 8160 jqXHR.abort("timeout");
nickjillings@1289 8161 }, s.timeout );
nickjillings@1289 8162 }
nickjillings@1289 8163
nickjillings@1289 8164 try {
nickjillings@1289 8165 state = 1;
nickjillings@1289 8166 transport.send( requestHeaders, done );
nickjillings@1289 8167 } catch ( e ) {
nickjillings@1289 8168 // Propagate exception as error if not done
nickjillings@1289 8169 if ( state < 2 ) {
nickjillings@1289 8170 done( -1, e );
nickjillings@1289 8171 // Simply rethrow otherwise
nickjillings@1289 8172 } else {
nickjillings@1289 8173 throw e;
nickjillings@1289 8174 }
nickjillings@1289 8175 }
nickjillings@1289 8176 }
nickjillings@1289 8177
nickjillings@1289 8178 // Callback for when everything is done
nickjillings@1289 8179 function done( status, nativeStatusText, responses, headers ) {
nickjillings@1289 8180 var isSuccess, success, error, response, modified,
nickjillings@1289 8181 statusText = nativeStatusText;
nickjillings@1289 8182
nickjillings@1289 8183 // Called once
nickjillings@1289 8184 if ( state === 2 ) {
nickjillings@1289 8185 return;
nickjillings@1289 8186 }
nickjillings@1289 8187
nickjillings@1289 8188 // State is "done" now
nickjillings@1289 8189 state = 2;
nickjillings@1289 8190
nickjillings@1289 8191 // Clear timeout if it exists
nickjillings@1289 8192 if ( timeoutTimer ) {
nickjillings@1289 8193 clearTimeout( timeoutTimer );
nickjillings@1289 8194 }
nickjillings@1289 8195
nickjillings@1289 8196 // Dereference transport for early garbage collection
nickjillings@1289 8197 // (no matter how long the jqXHR object will be used)
nickjillings@1289 8198 transport = undefined;
nickjillings@1289 8199
nickjillings@1289 8200 // Cache response headers
nickjillings@1289 8201 responseHeadersString = headers || "";
nickjillings@1289 8202
nickjillings@1289 8203 // Set readyState
nickjillings@1289 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nickjillings@1289 8205
nickjillings@1289 8206 // Determine if successful
nickjillings@1289 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nickjillings@1289 8208
nickjillings@1289 8209 // Get response data
nickjillings@1289 8210 if ( responses ) {
nickjillings@1289 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nickjillings@1289 8212 }
nickjillings@1289 8213
nickjillings@1289 8214 // Convert no matter what (that way responseXXX fields are always set)
nickjillings@1289 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nickjillings@1289 8216
nickjillings@1289 8217 // If successful, handle type chaining
nickjillings@1289 8218 if ( isSuccess ) {
nickjillings@1289 8219
nickjillings@1289 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1289 8221 if ( s.ifModified ) {
nickjillings@1289 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nickjillings@1289 8223 if ( modified ) {
nickjillings@1289 8224 jQuery.lastModified[ cacheURL ] = modified;
nickjillings@1289 8225 }
nickjillings@1289 8226 modified = jqXHR.getResponseHeader("etag");
nickjillings@1289 8227 if ( modified ) {
nickjillings@1289 8228 jQuery.etag[ cacheURL ] = modified;
nickjillings@1289 8229 }
nickjillings@1289 8230 }
nickjillings@1289 8231
nickjillings@1289 8232 // if no content
nickjillings@1289 8233 if ( status === 204 || s.type === "HEAD" ) {
nickjillings@1289 8234 statusText = "nocontent";
nickjillings@1289 8235
nickjillings@1289 8236 // if not modified
nickjillings@1289 8237 } else if ( status === 304 ) {
nickjillings@1289 8238 statusText = "notmodified";
nickjillings@1289 8239
nickjillings@1289 8240 // If we have data, let's convert it
nickjillings@1289 8241 } else {
nickjillings@1289 8242 statusText = response.state;
nickjillings@1289 8243 success = response.data;
nickjillings@1289 8244 error = response.error;
nickjillings@1289 8245 isSuccess = !error;
nickjillings@1289 8246 }
nickjillings@1289 8247 } else {
nickjillings@1289 8248 // Extract error from statusText and normalize for non-aborts
nickjillings@1289 8249 error = statusText;
nickjillings@1289 8250 if ( status || !statusText ) {
nickjillings@1289 8251 statusText = "error";
nickjillings@1289 8252 if ( status < 0 ) {
nickjillings@1289 8253 status = 0;
nickjillings@1289 8254 }
nickjillings@1289 8255 }
nickjillings@1289 8256 }
nickjillings@1289 8257
nickjillings@1289 8258 // Set data for the fake xhr object
nickjillings@1289 8259 jqXHR.status = status;
nickjillings@1289 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nickjillings@1289 8261
nickjillings@1289 8262 // Success/Error
nickjillings@1289 8263 if ( isSuccess ) {
nickjillings@1289 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nickjillings@1289 8265 } else {
nickjillings@1289 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nickjillings@1289 8267 }
nickjillings@1289 8268
nickjillings@1289 8269 // Status-dependent callbacks
nickjillings@1289 8270 jqXHR.statusCode( statusCode );
nickjillings@1289 8271 statusCode = undefined;
nickjillings@1289 8272
nickjillings@1289 8273 if ( fireGlobals ) {
nickjillings@1289 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nickjillings@1289 8275 [ jqXHR, s, isSuccess ? success : error ] );
nickjillings@1289 8276 }
nickjillings@1289 8277
nickjillings@1289 8278 // Complete
nickjillings@1289 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nickjillings@1289 8280
nickjillings@1289 8281 if ( fireGlobals ) {
nickjillings@1289 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nickjillings@1289 8283 // Handle the global AJAX counter
nickjillings@1289 8284 if ( !( --jQuery.active ) ) {
nickjillings@1289 8285 jQuery.event.trigger("ajaxStop");
nickjillings@1289 8286 }
nickjillings@1289 8287 }
nickjillings@1289 8288 }
nickjillings@1289 8289
nickjillings@1289 8290 return jqXHR;
nickjillings@1289 8291 },
nickjillings@1289 8292
nickjillings@1289 8293 getJSON: function( url, data, callback ) {
nickjillings@1289 8294 return jQuery.get( url, data, callback, "json" );
nickjillings@1289 8295 },
nickjillings@1289 8296
nickjillings@1289 8297 getScript: function( url, callback ) {
nickjillings@1289 8298 return jQuery.get( url, undefined, callback, "script" );
nickjillings@1289 8299 }
nickjillings@1289 8300 });
nickjillings@1289 8301
nickjillings@1289 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nickjillings@1289 8303 jQuery[ method ] = function( url, data, callback, type ) {
nickjillings@1289 8304 // Shift arguments if data argument was omitted
nickjillings@1289 8305 if ( jQuery.isFunction( data ) ) {
nickjillings@1289 8306 type = type || callback;
nickjillings@1289 8307 callback = data;
nickjillings@1289 8308 data = undefined;
nickjillings@1289 8309 }
nickjillings@1289 8310
nickjillings@1289 8311 return jQuery.ajax({
nickjillings@1289 8312 url: url,
nickjillings@1289 8313 type: method,
nickjillings@1289 8314 dataType: type,
nickjillings@1289 8315 data: data,
nickjillings@1289 8316 success: callback
nickjillings@1289 8317 });
nickjillings@1289 8318 };
nickjillings@1289 8319 });
nickjillings@1289 8320
nickjillings@1289 8321
nickjillings@1289 8322 jQuery._evalUrl = function( url ) {
nickjillings@1289 8323 return jQuery.ajax({
nickjillings@1289 8324 url: url,
nickjillings@1289 8325 type: "GET",
nickjillings@1289 8326 dataType: "script",
nickjillings@1289 8327 async: false,
nickjillings@1289 8328 global: false,
nickjillings@1289 8329 "throws": true
nickjillings@1289 8330 });
nickjillings@1289 8331 };
nickjillings@1289 8332
nickjillings@1289 8333
nickjillings@1289 8334 jQuery.fn.extend({
nickjillings@1289 8335 wrapAll: function( html ) {
nickjillings@1289 8336 var wrap;
nickjillings@1289 8337
nickjillings@1289 8338 if ( jQuery.isFunction( html ) ) {
nickjillings@1289 8339 return this.each(function( i ) {
nickjillings@1289 8340 jQuery( this ).wrapAll( html.call(this, i) );
nickjillings@1289 8341 });
nickjillings@1289 8342 }
nickjillings@1289 8343
nickjillings@1289 8344 if ( this[ 0 ] ) {
nickjillings@1289 8345
nickjillings@1289 8346 // The elements to wrap the target around
nickjillings@1289 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nickjillings@1289 8348
nickjillings@1289 8349 if ( this[ 0 ].parentNode ) {
nickjillings@1289 8350 wrap.insertBefore( this[ 0 ] );
nickjillings@1289 8351 }
nickjillings@1289 8352
nickjillings@1289 8353 wrap.map(function() {
nickjillings@1289 8354 var elem = this;
nickjillings@1289 8355
nickjillings@1289 8356 while ( elem.firstElementChild ) {
nickjillings@1289 8357 elem = elem.firstElementChild;
nickjillings@1289 8358 }
nickjillings@1289 8359
nickjillings@1289 8360 return elem;
nickjillings@1289 8361 }).append( this );
nickjillings@1289 8362 }
nickjillings@1289 8363
nickjillings@1289 8364 return this;
nickjillings@1289 8365 },
nickjillings@1289 8366
nickjillings@1289 8367 wrapInner: function( html ) {
nickjillings@1289 8368 if ( jQuery.isFunction( html ) ) {
nickjillings@1289 8369 return this.each(function( i ) {
nickjillings@1289 8370 jQuery( this ).wrapInner( html.call(this, i) );
nickjillings@1289 8371 });
nickjillings@1289 8372 }
nickjillings@1289 8373
nickjillings@1289 8374 return this.each(function() {
nickjillings@1289 8375 var self = jQuery( this ),
nickjillings@1289 8376 contents = self.contents();
nickjillings@1289 8377
nickjillings@1289 8378 if ( contents.length ) {
nickjillings@1289 8379 contents.wrapAll( html );
nickjillings@1289 8380
nickjillings@1289 8381 } else {
nickjillings@1289 8382 self.append( html );
nickjillings@1289 8383 }
nickjillings@1289 8384 });
nickjillings@1289 8385 },
nickjillings@1289 8386
nickjillings@1289 8387 wrap: function( html ) {
nickjillings@1289 8388 var isFunction = jQuery.isFunction( html );
nickjillings@1289 8389
nickjillings@1289 8390 return this.each(function( i ) {
nickjillings@1289 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nickjillings@1289 8392 });
nickjillings@1289 8393 },
nickjillings@1289 8394
nickjillings@1289 8395 unwrap: function() {
nickjillings@1289 8396 return this.parent().each(function() {
nickjillings@1289 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nickjillings@1289 8398 jQuery( this ).replaceWith( this.childNodes );
nickjillings@1289 8399 }
nickjillings@1289 8400 }).end();
nickjillings@1289 8401 }
nickjillings@1289 8402 });
nickjillings@1289 8403
nickjillings@1289 8404
nickjillings@1289 8405 jQuery.expr.filters.hidden = function( elem ) {
nickjillings@1289 8406 // Support: Opera <= 12.12
nickjillings@1289 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nickjillings@1289 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nickjillings@1289 8409 };
nickjillings@1289 8410 jQuery.expr.filters.visible = function( elem ) {
nickjillings@1289 8411 return !jQuery.expr.filters.hidden( elem );
nickjillings@1289 8412 };
nickjillings@1289 8413
nickjillings@1289 8414
nickjillings@1289 8415
nickjillings@1289 8416
nickjillings@1289 8417 var r20 = /%20/g,
nickjillings@1289 8418 rbracket = /\[\]$/,
nickjillings@1289 8419 rCRLF = /\r?\n/g,
nickjillings@1289 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nickjillings@1289 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nickjillings@1289 8422
nickjillings@1289 8423 function buildParams( prefix, obj, traditional, add ) {
nickjillings@1289 8424 var name;
nickjillings@1289 8425
nickjillings@1289 8426 if ( jQuery.isArray( obj ) ) {
nickjillings@1289 8427 // Serialize array item.
nickjillings@1289 8428 jQuery.each( obj, function( i, v ) {
nickjillings@1289 8429 if ( traditional || rbracket.test( prefix ) ) {
nickjillings@1289 8430 // Treat each array item as a scalar.
nickjillings@1289 8431 add( prefix, v );
nickjillings@1289 8432
nickjillings@1289 8433 } else {
nickjillings@1289 8434 // Item is non-scalar (array or object), encode its numeric index.
nickjillings@1289 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nickjillings@1289 8436 }
nickjillings@1289 8437 });
nickjillings@1289 8438
nickjillings@1289 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nickjillings@1289 8440 // Serialize object item.
nickjillings@1289 8441 for ( name in obj ) {
nickjillings@1289 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nickjillings@1289 8443 }
nickjillings@1289 8444
nickjillings@1289 8445 } else {
nickjillings@1289 8446 // Serialize scalar item.
nickjillings@1289 8447 add( prefix, obj );
nickjillings@1289 8448 }
nickjillings@1289 8449 }
nickjillings@1289 8450
nickjillings@1289 8451 // Serialize an array of form elements or a set of
nickjillings@1289 8452 // key/values into a query string
nickjillings@1289 8453 jQuery.param = function( a, traditional ) {
nickjillings@1289 8454 var prefix,
nickjillings@1289 8455 s = [],
nickjillings@1289 8456 add = function( key, value ) {
nickjillings@1289 8457 // If value is a function, invoke it and return its value
nickjillings@1289 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nickjillings@1289 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nickjillings@1289 8460 };
nickjillings@1289 8461
nickjillings@1289 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nickjillings@1289 8463 if ( traditional === undefined ) {
nickjillings@1289 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nickjillings@1289 8465 }
nickjillings@1289 8466
nickjillings@1289 8467 // If an array was passed in, assume that it is an array of form elements.
nickjillings@1289 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nickjillings@1289 8469 // Serialize the form elements
nickjillings@1289 8470 jQuery.each( a, function() {
nickjillings@1289 8471 add( this.name, this.value );
nickjillings@1289 8472 });
nickjillings@1289 8473
nickjillings@1289 8474 } else {
nickjillings@1289 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nickjillings@1289 8476 // did it), otherwise encode params recursively.
nickjillings@1289 8477 for ( prefix in a ) {
nickjillings@1289 8478 buildParams( prefix, a[ prefix ], traditional, add );
nickjillings@1289 8479 }
nickjillings@1289 8480 }
nickjillings@1289 8481
nickjillings@1289 8482 // Return the resulting serialization
nickjillings@1289 8483 return s.join( "&" ).replace( r20, "+" );
nickjillings@1289 8484 };
nickjillings@1289 8485
nickjillings@1289 8486 jQuery.fn.extend({
nickjillings@1289 8487 serialize: function() {
nickjillings@1289 8488 return jQuery.param( this.serializeArray() );
nickjillings@1289 8489 },
nickjillings@1289 8490 serializeArray: function() {
nickjillings@1289 8491 return this.map(function() {
nickjillings@1289 8492 // Can add propHook for "elements" to filter or add form elements
nickjillings@1289 8493 var elements = jQuery.prop( this, "elements" );
nickjillings@1289 8494 return elements ? jQuery.makeArray( elements ) : this;
nickjillings@1289 8495 })
nickjillings@1289 8496 .filter(function() {
nickjillings@1289 8497 var type = this.type;
nickjillings@1289 8498
nickjillings@1289 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nickjillings@1289 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nickjillings@1289 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nickjillings@1289 8502 ( this.checked || !rcheckableType.test( type ) );
nickjillings@1289 8503 })
nickjillings@1289 8504 .map(function( i, elem ) {
nickjillings@1289 8505 var val = jQuery( this ).val();
nickjillings@1289 8506
nickjillings@1289 8507 return val == null ?
nickjillings@1289 8508 null :
nickjillings@1289 8509 jQuery.isArray( val ) ?
nickjillings@1289 8510 jQuery.map( val, function( val ) {
nickjillings@1289 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1289 8512 }) :
nickjillings@1289 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1289 8514 }).get();
nickjillings@1289 8515 }
nickjillings@1289 8516 });
nickjillings@1289 8517
nickjillings@1289 8518
nickjillings@1289 8519 jQuery.ajaxSettings.xhr = function() {
nickjillings@1289 8520 try {
nickjillings@1289 8521 return new XMLHttpRequest();
nickjillings@1289 8522 } catch( e ) {}
nickjillings@1289 8523 };
nickjillings@1289 8524
nickjillings@1289 8525 var xhrId = 0,
nickjillings@1289 8526 xhrCallbacks = {},
nickjillings@1289 8527 xhrSuccessStatus = {
nickjillings@1289 8528 // file protocol always yields status code 0, assume 200
nickjillings@1289 8529 0: 200,
nickjillings@1289 8530 // Support: IE9
nickjillings@1289 8531 // #1450: sometimes IE returns 1223 when it should be 204
nickjillings@1289 8532 1223: 204
nickjillings@1289 8533 },
nickjillings@1289 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nickjillings@1289 8535
nickjillings@1289 8536 // Support: IE9
nickjillings@1289 8537 // Open requests must be manually aborted on unload (#5280)
nickjillings@1289 8538 // See https://support.microsoft.com/kb/2856746 for more info
nickjillings@1289 8539 if ( window.attachEvent ) {
nickjillings@1289 8540 window.attachEvent( "onunload", function() {
nickjillings@1289 8541 for ( var key in xhrCallbacks ) {
nickjillings@1289 8542 xhrCallbacks[ key ]();
nickjillings@1289 8543 }
nickjillings@1289 8544 });
nickjillings@1289 8545 }
nickjillings@1289 8546
nickjillings@1289 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nickjillings@1289 8548 support.ajax = xhrSupported = !!xhrSupported;
nickjillings@1289 8549
nickjillings@1289 8550 jQuery.ajaxTransport(function( options ) {
nickjillings@1289 8551 var callback;
nickjillings@1289 8552
nickjillings@1289 8553 // Cross domain only allowed if supported through XMLHttpRequest
nickjillings@1289 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nickjillings@1289 8555 return {
nickjillings@1289 8556 send: function( headers, complete ) {
nickjillings@1289 8557 var i,
nickjillings@1289 8558 xhr = options.xhr(),
nickjillings@1289 8559 id = ++xhrId;
nickjillings@1289 8560
nickjillings@1289 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nickjillings@1289 8562
nickjillings@1289 8563 // Apply custom fields if provided
nickjillings@1289 8564 if ( options.xhrFields ) {
nickjillings@1289 8565 for ( i in options.xhrFields ) {
nickjillings@1289 8566 xhr[ i ] = options.xhrFields[ i ];
nickjillings@1289 8567 }
nickjillings@1289 8568 }
nickjillings@1289 8569
nickjillings@1289 8570 // Override mime type if needed
nickjillings@1289 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nickjillings@1289 8572 xhr.overrideMimeType( options.mimeType );
nickjillings@1289 8573 }
nickjillings@1289 8574
nickjillings@1289 8575 // X-Requested-With header
nickjillings@1289 8576 // For cross-domain requests, seeing as conditions for a preflight are
nickjillings@1289 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nickjillings@1289 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nickjillings@1289 8579 // For same-domain requests, won't change header if already provided.
nickjillings@1289 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nickjillings@1289 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nickjillings@1289 8582 }
nickjillings@1289 8583
nickjillings@1289 8584 // Set headers
nickjillings@1289 8585 for ( i in headers ) {
nickjillings@1289 8586 xhr.setRequestHeader( i, headers[ i ] );
nickjillings@1289 8587 }
nickjillings@1289 8588
nickjillings@1289 8589 // Callback
nickjillings@1289 8590 callback = function( type ) {
nickjillings@1289 8591 return function() {
nickjillings@1289 8592 if ( callback ) {
nickjillings@1289 8593 delete xhrCallbacks[ id ];
nickjillings@1289 8594 callback = xhr.onload = xhr.onerror = null;
nickjillings@1289 8595
nickjillings@1289 8596 if ( type === "abort" ) {
nickjillings@1289 8597 xhr.abort();
nickjillings@1289 8598 } else if ( type === "error" ) {
nickjillings@1289 8599 complete(
nickjillings@1289 8600 // file: protocol always yields status 0; see #8605, #14207
nickjillings@1289 8601 xhr.status,
nickjillings@1289 8602 xhr.statusText
nickjillings@1289 8603 );
nickjillings@1289 8604 } else {
nickjillings@1289 8605 complete(
nickjillings@1289 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nickjillings@1289 8607 xhr.statusText,
nickjillings@1289 8608 // Support: IE9
nickjillings@1289 8609 // Accessing binary-data responseText throws an exception
nickjillings@1289 8610 // (#11426)
nickjillings@1289 8611 typeof xhr.responseText === "string" ? {
nickjillings@1289 8612 text: xhr.responseText
nickjillings@1289 8613 } : undefined,
nickjillings@1289 8614 xhr.getAllResponseHeaders()
nickjillings@1289 8615 );
nickjillings@1289 8616 }
nickjillings@1289 8617 }
nickjillings@1289 8618 };
nickjillings@1289 8619 };
nickjillings@1289 8620
nickjillings@1289 8621 // Listen to events
nickjillings@1289 8622 xhr.onload = callback();
nickjillings@1289 8623 xhr.onerror = callback("error");
nickjillings@1289 8624
nickjillings@1289 8625 // Create the abort callback
nickjillings@1289 8626 callback = xhrCallbacks[ id ] = callback("abort");
nickjillings@1289 8627
nickjillings@1289 8628 try {
nickjillings@1289 8629 // Do send the request (this may raise an exception)
nickjillings@1289 8630 xhr.send( options.hasContent && options.data || null );
nickjillings@1289 8631 } catch ( e ) {
nickjillings@1289 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nickjillings@1289 8633 if ( callback ) {
nickjillings@1289 8634 throw e;
nickjillings@1289 8635 }
nickjillings@1289 8636 }
nickjillings@1289 8637 },
nickjillings@1289 8638
nickjillings@1289 8639 abort: function() {
nickjillings@1289 8640 if ( callback ) {
nickjillings@1289 8641 callback();
nickjillings@1289 8642 }
nickjillings@1289 8643 }
nickjillings@1289 8644 };
nickjillings@1289 8645 }
nickjillings@1289 8646 });
nickjillings@1289 8647
nickjillings@1289 8648
nickjillings@1289 8649
nickjillings@1289 8650
nickjillings@1289 8651 // Install script dataType
nickjillings@1289 8652 jQuery.ajaxSetup({
nickjillings@1289 8653 accepts: {
nickjillings@1289 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nickjillings@1289 8655 },
nickjillings@1289 8656 contents: {
nickjillings@1289 8657 script: /(?:java|ecma)script/
nickjillings@1289 8658 },
nickjillings@1289 8659 converters: {
nickjillings@1289 8660 "text script": function( text ) {
nickjillings@1289 8661 jQuery.globalEval( text );
nickjillings@1289 8662 return text;
nickjillings@1289 8663 }
nickjillings@1289 8664 }
nickjillings@1289 8665 });
nickjillings@1289 8666
nickjillings@1289 8667 // Handle cache's special case and crossDomain
nickjillings@1289 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nickjillings@1289 8669 if ( s.cache === undefined ) {
nickjillings@1289 8670 s.cache = false;
nickjillings@1289 8671 }
nickjillings@1289 8672 if ( s.crossDomain ) {
nickjillings@1289 8673 s.type = "GET";
nickjillings@1289 8674 }
nickjillings@1289 8675 });
nickjillings@1289 8676
nickjillings@1289 8677 // Bind script tag hack transport
nickjillings@1289 8678 jQuery.ajaxTransport( "script", function( s ) {
nickjillings@1289 8679 // This transport only deals with cross domain requests
nickjillings@1289 8680 if ( s.crossDomain ) {
nickjillings@1289 8681 var script, callback;
nickjillings@1289 8682 return {
nickjillings@1289 8683 send: function( _, complete ) {
nickjillings@1289 8684 script = jQuery("<script>").prop({
nickjillings@1289 8685 async: true,
nickjillings@1289 8686 charset: s.scriptCharset,
nickjillings@1289 8687 src: s.url
nickjillings@1289 8688 }).on(
nickjillings@1289 8689 "load error",
nickjillings@1289 8690 callback = function( evt ) {
nickjillings@1289 8691 script.remove();
nickjillings@1289 8692 callback = null;
nickjillings@1289 8693 if ( evt ) {
nickjillings@1289 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nickjillings@1289 8695 }
nickjillings@1289 8696 }
nickjillings@1289 8697 );
nickjillings@1289 8698 document.head.appendChild( script[ 0 ] );
nickjillings@1289 8699 },
nickjillings@1289 8700 abort: function() {
nickjillings@1289 8701 if ( callback ) {
nickjillings@1289 8702 callback();
nickjillings@1289 8703 }
nickjillings@1289 8704 }
nickjillings@1289 8705 };
nickjillings@1289 8706 }
nickjillings@1289 8707 });
nickjillings@1289 8708
nickjillings@1289 8709
nickjillings@1289 8710
nickjillings@1289 8711
nickjillings@1289 8712 var oldCallbacks = [],
nickjillings@1289 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nickjillings@1289 8714
nickjillings@1289 8715 // Default jsonp settings
nickjillings@1289 8716 jQuery.ajaxSetup({
nickjillings@1289 8717 jsonp: "callback",
nickjillings@1289 8718 jsonpCallback: function() {
nickjillings@1289 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nickjillings@1289 8720 this[ callback ] = true;
nickjillings@1289 8721 return callback;
nickjillings@1289 8722 }
nickjillings@1289 8723 });
nickjillings@1289 8724
nickjillings@1289 8725 // Detect, normalize options and install callbacks for jsonp requests
nickjillings@1289 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nickjillings@1289 8727
nickjillings@1289 8728 var callbackName, overwritten, responseContainer,
nickjillings@1289 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nickjillings@1289 8730 "url" :
nickjillings@1289 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nickjillings@1289 8732 );
nickjillings@1289 8733
nickjillings@1289 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nickjillings@1289 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nickjillings@1289 8736
nickjillings@1289 8737 // Get callback name, remembering preexisting value associated with it
nickjillings@1289 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nickjillings@1289 8739 s.jsonpCallback() :
nickjillings@1289 8740 s.jsonpCallback;
nickjillings@1289 8741
nickjillings@1289 8742 // Insert callback into url or form data
nickjillings@1289 8743 if ( jsonProp ) {
nickjillings@1289 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nickjillings@1289 8745 } else if ( s.jsonp !== false ) {
nickjillings@1289 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nickjillings@1289 8747 }
nickjillings@1289 8748
nickjillings@1289 8749 // Use data converter to retrieve json after script execution
nickjillings@1289 8750 s.converters["script json"] = function() {
nickjillings@1289 8751 if ( !responseContainer ) {
nickjillings@1289 8752 jQuery.error( callbackName + " was not called" );
nickjillings@1289 8753 }
nickjillings@1289 8754 return responseContainer[ 0 ];
nickjillings@1289 8755 };
nickjillings@1289 8756
nickjillings@1289 8757 // force json dataType
nickjillings@1289 8758 s.dataTypes[ 0 ] = "json";
nickjillings@1289 8759
nickjillings@1289 8760 // Install callback
nickjillings@1289 8761 overwritten = window[ callbackName ];
nickjillings@1289 8762 window[ callbackName ] = function() {
nickjillings@1289 8763 responseContainer = arguments;
nickjillings@1289 8764 };
nickjillings@1289 8765
nickjillings@1289 8766 // Clean-up function (fires after converters)
nickjillings@1289 8767 jqXHR.always(function() {
nickjillings@1289 8768 // Restore preexisting value
nickjillings@1289 8769 window[ callbackName ] = overwritten;
nickjillings@1289 8770
nickjillings@1289 8771 // Save back as free
nickjillings@1289 8772 if ( s[ callbackName ] ) {
nickjillings@1289 8773 // make sure that re-using the options doesn't screw things around
nickjillings@1289 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nickjillings@1289 8775
nickjillings@1289 8776 // save the callback name for future use
nickjillings@1289 8777 oldCallbacks.push( callbackName );
nickjillings@1289 8778 }
nickjillings@1289 8779
nickjillings@1289 8780 // Call if it was a function and we have a response
nickjillings@1289 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nickjillings@1289 8782 overwritten( responseContainer[ 0 ] );
nickjillings@1289 8783 }
nickjillings@1289 8784
nickjillings@1289 8785 responseContainer = overwritten = undefined;
nickjillings@1289 8786 });
nickjillings@1289 8787
nickjillings@1289 8788 // Delegate to script
nickjillings@1289 8789 return "script";
nickjillings@1289 8790 }
nickjillings@1289 8791 });
nickjillings@1289 8792
nickjillings@1289 8793
nickjillings@1289 8794
nickjillings@1289 8795
nickjillings@1289 8796 // data: string of html
nickjillings@1289 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nickjillings@1289 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nickjillings@1289 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nickjillings@1289 8800 if ( !data || typeof data !== "string" ) {
nickjillings@1289 8801 return null;
nickjillings@1289 8802 }
nickjillings@1289 8803 if ( typeof context === "boolean" ) {
nickjillings@1289 8804 keepScripts = context;
nickjillings@1289 8805 context = false;
nickjillings@1289 8806 }
nickjillings@1289 8807 context = context || document;
nickjillings@1289 8808
nickjillings@1289 8809 var parsed = rsingleTag.exec( data ),
nickjillings@1289 8810 scripts = !keepScripts && [];
nickjillings@1289 8811
nickjillings@1289 8812 // Single tag
nickjillings@1289 8813 if ( parsed ) {
nickjillings@1289 8814 return [ context.createElement( parsed[1] ) ];
nickjillings@1289 8815 }
nickjillings@1289 8816
nickjillings@1289 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nickjillings@1289 8818
nickjillings@1289 8819 if ( scripts && scripts.length ) {
nickjillings@1289 8820 jQuery( scripts ).remove();
nickjillings@1289 8821 }
nickjillings@1289 8822
nickjillings@1289 8823 return jQuery.merge( [], parsed.childNodes );
nickjillings@1289 8824 };
nickjillings@1289 8825
nickjillings@1289 8826
nickjillings@1289 8827 // Keep a copy of the old load method
nickjillings@1289 8828 var _load = jQuery.fn.load;
nickjillings@1289 8829
nickjillings@1289 8830 /**
nickjillings@1289 8831 * Load a url into a page
nickjillings@1289 8832 */
nickjillings@1289 8833 jQuery.fn.load = function( url, params, callback ) {
nickjillings@1289 8834 if ( typeof url !== "string" && _load ) {
nickjillings@1289 8835 return _load.apply( this, arguments );
nickjillings@1289 8836 }
nickjillings@1289 8837
nickjillings@1289 8838 var selector, type, response,
nickjillings@1289 8839 self = this,
nickjillings@1289 8840 off = url.indexOf(" ");
nickjillings@1289 8841
nickjillings@1289 8842 if ( off >= 0 ) {
nickjillings@1289 8843 selector = jQuery.trim( url.slice( off ) );
nickjillings@1289 8844 url = url.slice( 0, off );
nickjillings@1289 8845 }
nickjillings@1289 8846
nickjillings@1289 8847 // If it's a function
nickjillings@1289 8848 if ( jQuery.isFunction( params ) ) {
nickjillings@1289 8849
nickjillings@1289 8850 // We assume that it's the callback
nickjillings@1289 8851 callback = params;
nickjillings@1289 8852 params = undefined;
nickjillings@1289 8853
nickjillings@1289 8854 // Otherwise, build a param string
nickjillings@1289 8855 } else if ( params && typeof params === "object" ) {
nickjillings@1289 8856 type = "POST";
nickjillings@1289 8857 }
nickjillings@1289 8858
nickjillings@1289 8859 // If we have elements to modify, make the request
nickjillings@1289 8860 if ( self.length > 0 ) {
nickjillings@1289 8861 jQuery.ajax({
nickjillings@1289 8862 url: url,
nickjillings@1289 8863
nickjillings@1289 8864 // if "type" variable is undefined, then "GET" method will be used
nickjillings@1289 8865 type: type,
nickjillings@1289 8866 dataType: "html",
nickjillings@1289 8867 data: params
nickjillings@1289 8868 }).done(function( responseText ) {
nickjillings@1289 8869
nickjillings@1289 8870 // Save response for use in complete callback
nickjillings@1289 8871 response = arguments;
nickjillings@1289 8872
nickjillings@1289 8873 self.html( selector ?
nickjillings@1289 8874
nickjillings@1289 8875 // If a selector was specified, locate the right elements in a dummy div
nickjillings@1289 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nickjillings@1289 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nickjillings@1289 8878
nickjillings@1289 8879 // Otherwise use the full result
nickjillings@1289 8880 responseText );
nickjillings@1289 8881
nickjillings@1289 8882 }).complete( callback && function( jqXHR, status ) {
nickjillings@1289 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nickjillings@1289 8884 });
nickjillings@1289 8885 }
nickjillings@1289 8886
nickjillings@1289 8887 return this;
nickjillings@1289 8888 };
nickjillings@1289 8889
nickjillings@1289 8890
nickjillings@1289 8891
nickjillings@1289 8892
nickjillings@1289 8893 // Attach a bunch of functions for handling common AJAX events
nickjillings@1289 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nickjillings@1289 8895 jQuery.fn[ type ] = function( fn ) {
nickjillings@1289 8896 return this.on( type, fn );
nickjillings@1289 8897 };
nickjillings@1289 8898 });
nickjillings@1289 8899
nickjillings@1289 8900
nickjillings@1289 8901
nickjillings@1289 8902
nickjillings@1289 8903 jQuery.expr.filters.animated = function( elem ) {
nickjillings@1289 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nickjillings@1289 8905 return elem === fn.elem;
nickjillings@1289 8906 }).length;
nickjillings@1289 8907 };
nickjillings@1289 8908
nickjillings@1289 8909
nickjillings@1289 8910
nickjillings@1289 8911
nickjillings@1289 8912 var docElem = window.document.documentElement;
nickjillings@1289 8913
nickjillings@1289 8914 /**
nickjillings@1289 8915 * Gets a window from an element
nickjillings@1289 8916 */
nickjillings@1289 8917 function getWindow( elem ) {
nickjillings@1289 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nickjillings@1289 8919 }
nickjillings@1289 8920
nickjillings@1289 8921 jQuery.offset = {
nickjillings@1289 8922 setOffset: function( elem, options, i ) {
nickjillings@1289 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nickjillings@1289 8924 position = jQuery.css( elem, "position" ),
nickjillings@1289 8925 curElem = jQuery( elem ),
nickjillings@1289 8926 props = {};
nickjillings@1289 8927
nickjillings@1289 8928 // Set position first, in-case top/left are set even on static elem
nickjillings@1289 8929 if ( position === "static" ) {
nickjillings@1289 8930 elem.style.position = "relative";
nickjillings@1289 8931 }
nickjillings@1289 8932
nickjillings@1289 8933 curOffset = curElem.offset();
nickjillings@1289 8934 curCSSTop = jQuery.css( elem, "top" );
nickjillings@1289 8935 curCSSLeft = jQuery.css( elem, "left" );
nickjillings@1289 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nickjillings@1289 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nickjillings@1289 8938
nickjillings@1289 8939 // Need to be able to calculate position if either
nickjillings@1289 8940 // top or left is auto and position is either absolute or fixed
nickjillings@1289 8941 if ( calculatePosition ) {
nickjillings@1289 8942 curPosition = curElem.position();
nickjillings@1289 8943 curTop = curPosition.top;
nickjillings@1289 8944 curLeft = curPosition.left;
nickjillings@1289 8945
nickjillings@1289 8946 } else {
nickjillings@1289 8947 curTop = parseFloat( curCSSTop ) || 0;
nickjillings@1289 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nickjillings@1289 8949 }
nickjillings@1289 8950
nickjillings@1289 8951 if ( jQuery.isFunction( options ) ) {
nickjillings@1289 8952 options = options.call( elem, i, curOffset );
nickjillings@1289 8953 }
nickjillings@1289 8954
nickjillings@1289 8955 if ( options.top != null ) {
nickjillings@1289 8956 props.top = ( options.top - curOffset.top ) + curTop;
nickjillings@1289 8957 }
nickjillings@1289 8958 if ( options.left != null ) {
nickjillings@1289 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nickjillings@1289 8960 }
nickjillings@1289 8961
nickjillings@1289 8962 if ( "using" in options ) {
nickjillings@1289 8963 options.using.call( elem, props );
nickjillings@1289 8964
nickjillings@1289 8965 } else {
nickjillings@1289 8966 curElem.css( props );
nickjillings@1289 8967 }
nickjillings@1289 8968 }
nickjillings@1289 8969 };
nickjillings@1289 8970
nickjillings@1289 8971 jQuery.fn.extend({
nickjillings@1289 8972 offset: function( options ) {
nickjillings@1289 8973 if ( arguments.length ) {
nickjillings@1289 8974 return options === undefined ?
nickjillings@1289 8975 this :
nickjillings@1289 8976 this.each(function( i ) {
nickjillings@1289 8977 jQuery.offset.setOffset( this, options, i );
nickjillings@1289 8978 });
nickjillings@1289 8979 }
nickjillings@1289 8980
nickjillings@1289 8981 var docElem, win,
nickjillings@1289 8982 elem = this[ 0 ],
nickjillings@1289 8983 box = { top: 0, left: 0 },
nickjillings@1289 8984 doc = elem && elem.ownerDocument;
nickjillings@1289 8985
nickjillings@1289 8986 if ( !doc ) {
nickjillings@1289 8987 return;
nickjillings@1289 8988 }
nickjillings@1289 8989
nickjillings@1289 8990 docElem = doc.documentElement;
nickjillings@1289 8991
nickjillings@1289 8992 // Make sure it's not a disconnected DOM node
nickjillings@1289 8993 if ( !jQuery.contains( docElem, elem ) ) {
nickjillings@1289 8994 return box;
nickjillings@1289 8995 }
nickjillings@1289 8996
nickjillings@1289 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nickjillings@1289 8998 // If we don't have gBCR, just use 0,0 rather than error
nickjillings@1289 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nickjillings@1289 9000 box = elem.getBoundingClientRect();
nickjillings@1289 9001 }
nickjillings@1289 9002 win = getWindow( doc );
nickjillings@1289 9003 return {
nickjillings@1289 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nickjillings@1289 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nickjillings@1289 9006 };
nickjillings@1289 9007 },
nickjillings@1289 9008
nickjillings@1289 9009 position: function() {
nickjillings@1289 9010 if ( !this[ 0 ] ) {
nickjillings@1289 9011 return;
nickjillings@1289 9012 }
nickjillings@1289 9013
nickjillings@1289 9014 var offsetParent, offset,
nickjillings@1289 9015 elem = this[ 0 ],
nickjillings@1289 9016 parentOffset = { top: 0, left: 0 };
nickjillings@1289 9017
nickjillings@1289 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nickjillings@1289 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nickjillings@1289 9020 // Assume getBoundingClientRect is there when computed position is fixed
nickjillings@1289 9021 offset = elem.getBoundingClientRect();
nickjillings@1289 9022
nickjillings@1289 9023 } else {
nickjillings@1289 9024 // Get *real* offsetParent
nickjillings@1289 9025 offsetParent = this.offsetParent();
nickjillings@1289 9026
nickjillings@1289 9027 // Get correct offsets
nickjillings@1289 9028 offset = this.offset();
nickjillings@1289 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nickjillings@1289 9030 parentOffset = offsetParent.offset();
nickjillings@1289 9031 }
nickjillings@1289 9032
nickjillings@1289 9033 // Add offsetParent borders
nickjillings@1289 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nickjillings@1289 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nickjillings@1289 9036 }
nickjillings@1289 9037
nickjillings@1289 9038 // Subtract parent offsets and element margins
nickjillings@1289 9039 return {
nickjillings@1289 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nickjillings@1289 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nickjillings@1289 9042 };
nickjillings@1289 9043 },
nickjillings@1289 9044
nickjillings@1289 9045 offsetParent: function() {
nickjillings@1289 9046 return this.map(function() {
nickjillings@1289 9047 var offsetParent = this.offsetParent || docElem;
nickjillings@1289 9048
nickjillings@1289 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nickjillings@1289 9050 offsetParent = offsetParent.offsetParent;
nickjillings@1289 9051 }
nickjillings@1289 9052
nickjillings@1289 9053 return offsetParent || docElem;
nickjillings@1289 9054 });
nickjillings@1289 9055 }
nickjillings@1289 9056 });
nickjillings@1289 9057
nickjillings@1289 9058 // Create scrollLeft and scrollTop methods
nickjillings@1289 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nickjillings@1289 9060 var top = "pageYOffset" === prop;
nickjillings@1289 9061
nickjillings@1289 9062 jQuery.fn[ method ] = function( val ) {
nickjillings@1289 9063 return access( this, function( elem, method, val ) {
nickjillings@1289 9064 var win = getWindow( elem );
nickjillings@1289 9065
nickjillings@1289 9066 if ( val === undefined ) {
nickjillings@1289 9067 return win ? win[ prop ] : elem[ method ];
nickjillings@1289 9068 }
nickjillings@1289 9069
nickjillings@1289 9070 if ( win ) {
nickjillings@1289 9071 win.scrollTo(
nickjillings@1289 9072 !top ? val : window.pageXOffset,
nickjillings@1289 9073 top ? val : window.pageYOffset
nickjillings@1289 9074 );
nickjillings@1289 9075
nickjillings@1289 9076 } else {
nickjillings@1289 9077 elem[ method ] = val;
nickjillings@1289 9078 }
nickjillings@1289 9079 }, method, val, arguments.length, null );
nickjillings@1289 9080 };
nickjillings@1289 9081 });
nickjillings@1289 9082
nickjillings@1289 9083 // Support: Safari<7+, Chrome<37+
nickjillings@1289 9084 // Add the top/left cssHooks using jQuery.fn.position
nickjillings@1289 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nickjillings@1289 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nickjillings@1289 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nickjillings@1289 9088 // rather than make the css module depend on the offset module, just check for it here
nickjillings@1289 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nickjillings@1289 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nickjillings@1289 9091 function( elem, computed ) {
nickjillings@1289 9092 if ( computed ) {
nickjillings@1289 9093 computed = curCSS( elem, prop );
nickjillings@1289 9094 // If curCSS returns percentage, fallback to offset
nickjillings@1289 9095 return rnumnonpx.test( computed ) ?
nickjillings@1289 9096 jQuery( elem ).position()[ prop ] + "px" :
nickjillings@1289 9097 computed;
nickjillings@1289 9098 }
nickjillings@1289 9099 }
nickjillings@1289 9100 );
nickjillings@1289 9101 });
nickjillings@1289 9102
nickjillings@1289 9103
nickjillings@1289 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nickjillings@1289 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nickjillings@1289 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nickjillings@1289 9107 // Margin is only for outerHeight, outerWidth
nickjillings@1289 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nickjillings@1289 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nickjillings@1289 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nickjillings@1289 9111
nickjillings@1289 9112 return access( this, function( elem, type, value ) {
nickjillings@1289 9113 var doc;
nickjillings@1289 9114
nickjillings@1289 9115 if ( jQuery.isWindow( elem ) ) {
nickjillings@1289 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nickjillings@1289 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nickjillings@1289 9118 // https://github.com/jquery/jquery/pull/764
nickjillings@1289 9119 return elem.document.documentElement[ "client" + name ];
nickjillings@1289 9120 }
nickjillings@1289 9121
nickjillings@1289 9122 // Get document width or height
nickjillings@1289 9123 if ( elem.nodeType === 9 ) {
nickjillings@1289 9124 doc = elem.documentElement;
nickjillings@1289 9125
nickjillings@1289 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nickjillings@1289 9127 // whichever is greatest
nickjillings@1289 9128 return Math.max(
nickjillings@1289 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nickjillings@1289 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nickjillings@1289 9131 doc[ "client" + name ]
nickjillings@1289 9132 );
nickjillings@1289 9133 }
nickjillings@1289 9134
nickjillings@1289 9135 return value === undefined ?
nickjillings@1289 9136 // Get width or height on the element, requesting but not forcing parseFloat
nickjillings@1289 9137 jQuery.css( elem, type, extra ) :
nickjillings@1289 9138
nickjillings@1289 9139 // Set width or height on the element
nickjillings@1289 9140 jQuery.style( elem, type, value, extra );
nickjillings@1289 9141 }, type, chainable ? margin : undefined, chainable, null );
nickjillings@1289 9142 };
nickjillings@1289 9143 });
nickjillings@1289 9144 });
nickjillings@1289 9145
nickjillings@1289 9146
nickjillings@1289 9147 // The number of elements contained in the matched element set
nickjillings@1289 9148 jQuery.fn.size = function() {
nickjillings@1289 9149 return this.length;
nickjillings@1289 9150 };
nickjillings@1289 9151
nickjillings@1289 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nickjillings@1289 9153
nickjillings@1289 9154
nickjillings@1289 9155
nickjillings@1289 9156
nickjillings@1289 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nickjillings@1289 9158 // files that may use define, but not via a proper concatenation script that
nickjillings@1289 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nickjillings@1289 9160 // way to register. Lowercase jquery is used because AMD module names are
nickjillings@1289 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nickjillings@1289 9162 // file name. Do this after creating the global so that if an AMD module wants
nickjillings@1289 9163 // to call noConflict to hide this version of jQuery, it will work.
nickjillings@1289 9164
nickjillings@1289 9165 // Note that for maximum portability, libraries that are not jQuery should
nickjillings@1289 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nickjillings@1289 9167 // AMD loader is present. jQuery is a special case. For more information, see
nickjillings@1289 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nickjillings@1289 9169
nickjillings@1289 9170 if ( typeof define === "function" && define.amd ) {
nickjillings@1289 9171 define( "jquery", [], function() {
nickjillings@1289 9172 return jQuery;
nickjillings@1289 9173 });
nickjillings@1289 9174 }
nickjillings@1289 9175
nickjillings@1289 9176
nickjillings@1289 9177
nickjillings@1289 9178
nickjillings@1289 9179 var
nickjillings@1289 9180 // Map over jQuery in case of overwrite
nickjillings@1289 9181 _jQuery = window.jQuery,
nickjillings@1289 9182
nickjillings@1289 9183 // Map over the $ in case of overwrite
nickjillings@1289 9184 _$ = window.$;
nickjillings@1289 9185
nickjillings@1289 9186 jQuery.noConflict = function( deep ) {
nickjillings@1289 9187 if ( window.$ === jQuery ) {
nickjillings@1289 9188 window.$ = _$;
nickjillings@1289 9189 }
nickjillings@1289 9190
nickjillings@1289 9191 if ( deep && window.jQuery === jQuery ) {
nickjillings@1289 9192 window.jQuery = _jQuery;
nickjillings@1289 9193 }
nickjillings@1289 9194
nickjillings@1289 9195 return jQuery;
nickjillings@1289 9196 };
nickjillings@1289 9197
nickjillings@1289 9198 // Expose jQuery and $ identifiers, even in AMD
nickjillings@1289 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nickjillings@1289 9200 // and CommonJS for browser emulators (#13566)
nickjillings@1289 9201 if ( typeof noGlobal === strundefined ) {
nickjillings@1289 9202 window.jQuery = window.$ = jQuery;
nickjillings@1289 9203 }
nickjillings@1289 9204
nickjillings@1289 9205
nickjillings@1289 9206
nickjillings@1289 9207
nickjillings@1289 9208 return jQuery;
nickjillings@1289 9209
nickjillings@1289 9210 }));