annotate jquery-2.1.4.js @ 1750:1365362c12d5

Merge from 156:402bb0f56dc4
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 01 Jun 2015 12:56:15 +0100
parents 4d71d16c1816
children
rev   line source
nickjillings@1596 1 /*!
nickjillings@1596 2 * jQuery JavaScript Library v2.1.4
nickjillings@1596 3 * http://jquery.com/
nickjillings@1596 4 *
nickjillings@1596 5 * Includes Sizzle.js
nickjillings@1596 6 * http://sizzlejs.com/
nickjillings@1596 7 *
nickjillings@1596 8 * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1596 9 * Released under the MIT license
nickjillings@1596 10 * http://jquery.org/license
nickjillings@1596 11 *
nickjillings@1596 12 * Date: 2015-04-28T16:01Z
nickjillings@1596 13 */
nickjillings@1596 14
nickjillings@1596 15 (function( global, factory ) {
nickjillings@1596 16
nickjillings@1596 17 if ( typeof module === "object" && typeof module.exports === "object" ) {
nickjillings@1596 18 // For CommonJS and CommonJS-like environments where a proper `window`
nickjillings@1596 19 // is present, execute the factory and get jQuery.
nickjillings@1596 20 // For environments that do not have a `window` with a `document`
nickjillings@1596 21 // (such as Node.js), expose a factory as module.exports.
nickjillings@1596 22 // This accentuates the need for the creation of a real `window`.
nickjillings@1596 23 // e.g. var jQuery = require("jquery")(window);
nickjillings@1596 24 // See ticket #14549 for more info.
nickjillings@1596 25 module.exports = global.document ?
nickjillings@1596 26 factory( global, true ) :
nickjillings@1596 27 function( w ) {
nickjillings@1596 28 if ( !w.document ) {
nickjillings@1596 29 throw new Error( "jQuery requires a window with a document" );
nickjillings@1596 30 }
nickjillings@1596 31 return factory( w );
nickjillings@1596 32 };
nickjillings@1596 33 } else {
nickjillings@1596 34 factory( global );
nickjillings@1596 35 }
nickjillings@1596 36
nickjillings@1596 37 // Pass this if window is not defined yet
nickjillings@1596 38 }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nickjillings@1596 39
nickjillings@1596 40 // Support: Firefox 18+
nickjillings@1596 41 // Can't be in strict mode, several libs including ASP.NET trace
nickjillings@1596 42 // the stack via arguments.caller.callee and Firefox dies if
nickjillings@1596 43 // you try to trace through "use strict" call chains. (#13335)
nickjillings@1596 44 //
nickjillings@1596 45
nickjillings@1596 46 var arr = [];
nickjillings@1596 47
nickjillings@1596 48 var slice = arr.slice;
nickjillings@1596 49
nickjillings@1596 50 var concat = arr.concat;
nickjillings@1596 51
nickjillings@1596 52 var push = arr.push;
nickjillings@1596 53
nickjillings@1596 54 var indexOf = arr.indexOf;
nickjillings@1596 55
nickjillings@1596 56 var class2type = {};
nickjillings@1596 57
nickjillings@1596 58 var toString = class2type.toString;
nickjillings@1596 59
nickjillings@1596 60 var hasOwn = class2type.hasOwnProperty;
nickjillings@1596 61
nickjillings@1596 62 var support = {};
nickjillings@1596 63
nickjillings@1596 64
nickjillings@1596 65
nickjillings@1596 66 var
nickjillings@1596 67 // Use the correct document accordingly with window argument (sandbox)
nickjillings@1596 68 document = window.document,
nickjillings@1596 69
nickjillings@1596 70 version = "2.1.4",
nickjillings@1596 71
nickjillings@1596 72 // Define a local copy of jQuery
nickjillings@1596 73 jQuery = function( selector, context ) {
nickjillings@1596 74 // The jQuery object is actually just the init constructor 'enhanced'
nickjillings@1596 75 // Need init if jQuery is called (just allow error to be thrown if not included)
nickjillings@1596 76 return new jQuery.fn.init( selector, context );
nickjillings@1596 77 },
nickjillings@1596 78
nickjillings@1596 79 // Support: Android<4.1
nickjillings@1596 80 // Make sure we trim BOM and NBSP
nickjillings@1596 81 rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nickjillings@1596 82
nickjillings@1596 83 // Matches dashed string for camelizing
nickjillings@1596 84 rmsPrefix = /^-ms-/,
nickjillings@1596 85 rdashAlpha = /-([\da-z])/gi,
nickjillings@1596 86
nickjillings@1596 87 // Used by jQuery.camelCase as callback to replace()
nickjillings@1596 88 fcamelCase = function( all, letter ) {
nickjillings@1596 89 return letter.toUpperCase();
nickjillings@1596 90 };
nickjillings@1596 91
nickjillings@1596 92 jQuery.fn = jQuery.prototype = {
nickjillings@1596 93 // The current version of jQuery being used
nickjillings@1596 94 jquery: version,
nickjillings@1596 95
nickjillings@1596 96 constructor: jQuery,
nickjillings@1596 97
nickjillings@1596 98 // Start with an empty selector
nickjillings@1596 99 selector: "",
nickjillings@1596 100
nickjillings@1596 101 // The default length of a jQuery object is 0
nickjillings@1596 102 length: 0,
nickjillings@1596 103
nickjillings@1596 104 toArray: function() {
nickjillings@1596 105 return slice.call( this );
nickjillings@1596 106 },
nickjillings@1596 107
nickjillings@1596 108 // Get the Nth element in the matched element set OR
nickjillings@1596 109 // Get the whole matched element set as a clean array
nickjillings@1596 110 get: function( num ) {
nickjillings@1596 111 return num != null ?
nickjillings@1596 112
nickjillings@1596 113 // Return just the one element from the set
nickjillings@1596 114 ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nickjillings@1596 115
nickjillings@1596 116 // Return all the elements in a clean array
nickjillings@1596 117 slice.call( this );
nickjillings@1596 118 },
nickjillings@1596 119
nickjillings@1596 120 // Take an array of elements and push it onto the stack
nickjillings@1596 121 // (returning the new matched element set)
nickjillings@1596 122 pushStack: function( elems ) {
nickjillings@1596 123
nickjillings@1596 124 // Build a new jQuery matched element set
nickjillings@1596 125 var ret = jQuery.merge( this.constructor(), elems );
nickjillings@1596 126
nickjillings@1596 127 // Add the old object onto the stack (as a reference)
nickjillings@1596 128 ret.prevObject = this;
nickjillings@1596 129 ret.context = this.context;
nickjillings@1596 130
nickjillings@1596 131 // Return the newly-formed element set
nickjillings@1596 132 return ret;
nickjillings@1596 133 },
nickjillings@1596 134
nickjillings@1596 135 // Execute a callback for every element in the matched set.
nickjillings@1596 136 // (You can seed the arguments with an array of args, but this is
nickjillings@1596 137 // only used internally.)
nickjillings@1596 138 each: function( callback, args ) {
nickjillings@1596 139 return jQuery.each( this, callback, args );
nickjillings@1596 140 },
nickjillings@1596 141
nickjillings@1596 142 map: function( callback ) {
nickjillings@1596 143 return this.pushStack( jQuery.map(this, function( elem, i ) {
nickjillings@1596 144 return callback.call( elem, i, elem );
nickjillings@1596 145 }));
nickjillings@1596 146 },
nickjillings@1596 147
nickjillings@1596 148 slice: function() {
nickjillings@1596 149 return this.pushStack( slice.apply( this, arguments ) );
nickjillings@1596 150 },
nickjillings@1596 151
nickjillings@1596 152 first: function() {
nickjillings@1596 153 return this.eq( 0 );
nickjillings@1596 154 },
nickjillings@1596 155
nickjillings@1596 156 last: function() {
nickjillings@1596 157 return this.eq( -1 );
nickjillings@1596 158 },
nickjillings@1596 159
nickjillings@1596 160 eq: function( i ) {
nickjillings@1596 161 var len = this.length,
nickjillings@1596 162 j = +i + ( i < 0 ? len : 0 );
nickjillings@1596 163 return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nickjillings@1596 164 },
nickjillings@1596 165
nickjillings@1596 166 end: function() {
nickjillings@1596 167 return this.prevObject || this.constructor(null);
nickjillings@1596 168 },
nickjillings@1596 169
nickjillings@1596 170 // For internal use only.
nickjillings@1596 171 // Behaves like an Array's method, not like a jQuery method.
nickjillings@1596 172 push: push,
nickjillings@1596 173 sort: arr.sort,
nickjillings@1596 174 splice: arr.splice
nickjillings@1596 175 };
nickjillings@1596 176
nickjillings@1596 177 jQuery.extend = jQuery.fn.extend = function() {
nickjillings@1596 178 var options, name, src, copy, copyIsArray, clone,
nickjillings@1596 179 target = arguments[0] || {},
nickjillings@1596 180 i = 1,
nickjillings@1596 181 length = arguments.length,
nickjillings@1596 182 deep = false;
nickjillings@1596 183
nickjillings@1596 184 // Handle a deep copy situation
nickjillings@1596 185 if ( typeof target === "boolean" ) {
nickjillings@1596 186 deep = target;
nickjillings@1596 187
nickjillings@1596 188 // Skip the boolean and the target
nickjillings@1596 189 target = arguments[ i ] || {};
nickjillings@1596 190 i++;
nickjillings@1596 191 }
nickjillings@1596 192
nickjillings@1596 193 // Handle case when target is a string or something (possible in deep copy)
nickjillings@1596 194 if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nickjillings@1596 195 target = {};
nickjillings@1596 196 }
nickjillings@1596 197
nickjillings@1596 198 // Extend jQuery itself if only one argument is passed
nickjillings@1596 199 if ( i === length ) {
nickjillings@1596 200 target = this;
nickjillings@1596 201 i--;
nickjillings@1596 202 }
nickjillings@1596 203
nickjillings@1596 204 for ( ; i < length; i++ ) {
nickjillings@1596 205 // Only deal with non-null/undefined values
nickjillings@1596 206 if ( (options = arguments[ i ]) != null ) {
nickjillings@1596 207 // Extend the base object
nickjillings@1596 208 for ( name in options ) {
nickjillings@1596 209 src = target[ name ];
nickjillings@1596 210 copy = options[ name ];
nickjillings@1596 211
nickjillings@1596 212 // Prevent never-ending loop
nickjillings@1596 213 if ( target === copy ) {
nickjillings@1596 214 continue;
nickjillings@1596 215 }
nickjillings@1596 216
nickjillings@1596 217 // Recurse if we're merging plain objects or arrays
nickjillings@1596 218 if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nickjillings@1596 219 if ( copyIsArray ) {
nickjillings@1596 220 copyIsArray = false;
nickjillings@1596 221 clone = src && jQuery.isArray(src) ? src : [];
nickjillings@1596 222
nickjillings@1596 223 } else {
nickjillings@1596 224 clone = src && jQuery.isPlainObject(src) ? src : {};
nickjillings@1596 225 }
nickjillings@1596 226
nickjillings@1596 227 // Never move original objects, clone them
nickjillings@1596 228 target[ name ] = jQuery.extend( deep, clone, copy );
nickjillings@1596 229
nickjillings@1596 230 // Don't bring in undefined values
nickjillings@1596 231 } else if ( copy !== undefined ) {
nickjillings@1596 232 target[ name ] = copy;
nickjillings@1596 233 }
nickjillings@1596 234 }
nickjillings@1596 235 }
nickjillings@1596 236 }
nickjillings@1596 237
nickjillings@1596 238 // Return the modified object
nickjillings@1596 239 return target;
nickjillings@1596 240 };
nickjillings@1596 241
nickjillings@1596 242 jQuery.extend({
nickjillings@1596 243 // Unique for each copy of jQuery on the page
nickjillings@1596 244 expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nickjillings@1596 245
nickjillings@1596 246 // Assume jQuery is ready without the ready module
nickjillings@1596 247 isReady: true,
nickjillings@1596 248
nickjillings@1596 249 error: function( msg ) {
nickjillings@1596 250 throw new Error( msg );
nickjillings@1596 251 },
nickjillings@1596 252
nickjillings@1596 253 noop: function() {},
nickjillings@1596 254
nickjillings@1596 255 isFunction: function( obj ) {
nickjillings@1596 256 return jQuery.type(obj) === "function";
nickjillings@1596 257 },
nickjillings@1596 258
nickjillings@1596 259 isArray: Array.isArray,
nickjillings@1596 260
nickjillings@1596 261 isWindow: function( obj ) {
nickjillings@1596 262 return obj != null && obj === obj.window;
nickjillings@1596 263 },
nickjillings@1596 264
nickjillings@1596 265 isNumeric: function( obj ) {
nickjillings@1596 266 // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nickjillings@1596 267 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nickjillings@1596 268 // subtraction forces infinities to NaN
nickjillings@1596 269 // adding 1 corrects loss of precision from parseFloat (#15100)
nickjillings@1596 270 return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nickjillings@1596 271 },
nickjillings@1596 272
nickjillings@1596 273 isPlainObject: function( obj ) {
nickjillings@1596 274 // Not plain objects:
nickjillings@1596 275 // - Any object or value whose internal [[Class]] property is not "[object Object]"
nickjillings@1596 276 // - DOM nodes
nickjillings@1596 277 // - window
nickjillings@1596 278 if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nickjillings@1596 279 return false;
nickjillings@1596 280 }
nickjillings@1596 281
nickjillings@1596 282 if ( obj.constructor &&
nickjillings@1596 283 !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nickjillings@1596 284 return false;
nickjillings@1596 285 }
nickjillings@1596 286
nickjillings@1596 287 // If the function hasn't returned already, we're confident that
nickjillings@1596 288 // |obj| is a plain object, created by {} or constructed with new Object
nickjillings@1596 289 return true;
nickjillings@1596 290 },
nickjillings@1596 291
nickjillings@1596 292 isEmptyObject: function( obj ) {
nickjillings@1596 293 var name;
nickjillings@1596 294 for ( name in obj ) {
nickjillings@1596 295 return false;
nickjillings@1596 296 }
nickjillings@1596 297 return true;
nickjillings@1596 298 },
nickjillings@1596 299
nickjillings@1596 300 type: function( obj ) {
nickjillings@1596 301 if ( obj == null ) {
nickjillings@1596 302 return obj + "";
nickjillings@1596 303 }
nickjillings@1596 304 // Support: Android<4.0, iOS<6 (functionish RegExp)
nickjillings@1596 305 return typeof obj === "object" || typeof obj === "function" ?
nickjillings@1596 306 class2type[ toString.call(obj) ] || "object" :
nickjillings@1596 307 typeof obj;
nickjillings@1596 308 },
nickjillings@1596 309
nickjillings@1596 310 // Evaluates a script in a global context
nickjillings@1596 311 globalEval: function( code ) {
nickjillings@1596 312 var script,
nickjillings@1596 313 indirect = eval;
nickjillings@1596 314
nickjillings@1596 315 code = jQuery.trim( code );
nickjillings@1596 316
nickjillings@1596 317 if ( code ) {
nickjillings@1596 318 // If the code includes a valid, prologue position
nickjillings@1596 319 // strict mode pragma, execute code by injecting a
nickjillings@1596 320 // script tag into the document.
nickjillings@1596 321 if ( code.indexOf("use strict") === 1 ) {
nickjillings@1596 322 script = document.createElement("script");
nickjillings@1596 323 script.text = code;
nickjillings@1596 324 document.head.appendChild( script ).parentNode.removeChild( script );
nickjillings@1596 325 } else {
nickjillings@1596 326 // Otherwise, avoid the DOM node creation, insertion
nickjillings@1596 327 // and removal by using an indirect global eval
nickjillings@1596 328 indirect( code );
nickjillings@1596 329 }
nickjillings@1596 330 }
nickjillings@1596 331 },
nickjillings@1596 332
nickjillings@1596 333 // Convert dashed to camelCase; used by the css and data modules
nickjillings@1596 334 // Support: IE9-11+
nickjillings@1596 335 // Microsoft forgot to hump their vendor prefix (#9572)
nickjillings@1596 336 camelCase: function( string ) {
nickjillings@1596 337 return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nickjillings@1596 338 },
nickjillings@1596 339
nickjillings@1596 340 nodeName: function( elem, name ) {
nickjillings@1596 341 return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nickjillings@1596 342 },
nickjillings@1596 343
nickjillings@1596 344 // args is for internal usage only
nickjillings@1596 345 each: function( obj, callback, args ) {
nickjillings@1596 346 var value,
nickjillings@1596 347 i = 0,
nickjillings@1596 348 length = obj.length,
nickjillings@1596 349 isArray = isArraylike( obj );
nickjillings@1596 350
nickjillings@1596 351 if ( args ) {
nickjillings@1596 352 if ( isArray ) {
nickjillings@1596 353 for ( ; i < length; i++ ) {
nickjillings@1596 354 value = callback.apply( obj[ i ], args );
nickjillings@1596 355
nickjillings@1596 356 if ( value === false ) {
nickjillings@1596 357 break;
nickjillings@1596 358 }
nickjillings@1596 359 }
nickjillings@1596 360 } else {
nickjillings@1596 361 for ( i in obj ) {
nickjillings@1596 362 value = callback.apply( obj[ i ], args );
nickjillings@1596 363
nickjillings@1596 364 if ( value === false ) {
nickjillings@1596 365 break;
nickjillings@1596 366 }
nickjillings@1596 367 }
nickjillings@1596 368 }
nickjillings@1596 369
nickjillings@1596 370 // A special, fast, case for the most common use of each
nickjillings@1596 371 } else {
nickjillings@1596 372 if ( isArray ) {
nickjillings@1596 373 for ( ; i < length; i++ ) {
nickjillings@1596 374 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1596 375
nickjillings@1596 376 if ( value === false ) {
nickjillings@1596 377 break;
nickjillings@1596 378 }
nickjillings@1596 379 }
nickjillings@1596 380 } else {
nickjillings@1596 381 for ( i in obj ) {
nickjillings@1596 382 value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1596 383
nickjillings@1596 384 if ( value === false ) {
nickjillings@1596 385 break;
nickjillings@1596 386 }
nickjillings@1596 387 }
nickjillings@1596 388 }
nickjillings@1596 389 }
nickjillings@1596 390
nickjillings@1596 391 return obj;
nickjillings@1596 392 },
nickjillings@1596 393
nickjillings@1596 394 // Support: Android<4.1
nickjillings@1596 395 trim: function( text ) {
nickjillings@1596 396 return text == null ?
nickjillings@1596 397 "" :
nickjillings@1596 398 ( text + "" ).replace( rtrim, "" );
nickjillings@1596 399 },
nickjillings@1596 400
nickjillings@1596 401 // results is for internal usage only
nickjillings@1596 402 makeArray: function( arr, results ) {
nickjillings@1596 403 var ret = results || [];
nickjillings@1596 404
nickjillings@1596 405 if ( arr != null ) {
nickjillings@1596 406 if ( isArraylike( Object(arr) ) ) {
nickjillings@1596 407 jQuery.merge( ret,
nickjillings@1596 408 typeof arr === "string" ?
nickjillings@1596 409 [ arr ] : arr
nickjillings@1596 410 );
nickjillings@1596 411 } else {
nickjillings@1596 412 push.call( ret, arr );
nickjillings@1596 413 }
nickjillings@1596 414 }
nickjillings@1596 415
nickjillings@1596 416 return ret;
nickjillings@1596 417 },
nickjillings@1596 418
nickjillings@1596 419 inArray: function( elem, arr, i ) {
nickjillings@1596 420 return arr == null ? -1 : indexOf.call( arr, elem, i );
nickjillings@1596 421 },
nickjillings@1596 422
nickjillings@1596 423 merge: function( first, second ) {
nickjillings@1596 424 var len = +second.length,
nickjillings@1596 425 j = 0,
nickjillings@1596 426 i = first.length;
nickjillings@1596 427
nickjillings@1596 428 for ( ; j < len; j++ ) {
nickjillings@1596 429 first[ i++ ] = second[ j ];
nickjillings@1596 430 }
nickjillings@1596 431
nickjillings@1596 432 first.length = i;
nickjillings@1596 433
nickjillings@1596 434 return first;
nickjillings@1596 435 },
nickjillings@1596 436
nickjillings@1596 437 grep: function( elems, callback, invert ) {
nickjillings@1596 438 var callbackInverse,
nickjillings@1596 439 matches = [],
nickjillings@1596 440 i = 0,
nickjillings@1596 441 length = elems.length,
nickjillings@1596 442 callbackExpect = !invert;
nickjillings@1596 443
nickjillings@1596 444 // Go through the array, only saving the items
nickjillings@1596 445 // that pass the validator function
nickjillings@1596 446 for ( ; i < length; i++ ) {
nickjillings@1596 447 callbackInverse = !callback( elems[ i ], i );
nickjillings@1596 448 if ( callbackInverse !== callbackExpect ) {
nickjillings@1596 449 matches.push( elems[ i ] );
nickjillings@1596 450 }
nickjillings@1596 451 }
nickjillings@1596 452
nickjillings@1596 453 return matches;
nickjillings@1596 454 },
nickjillings@1596 455
nickjillings@1596 456 // arg is for internal usage only
nickjillings@1596 457 map: function( elems, callback, arg ) {
nickjillings@1596 458 var value,
nickjillings@1596 459 i = 0,
nickjillings@1596 460 length = elems.length,
nickjillings@1596 461 isArray = isArraylike( elems ),
nickjillings@1596 462 ret = [];
nickjillings@1596 463
nickjillings@1596 464 // Go through the array, translating each of the items to their new values
nickjillings@1596 465 if ( isArray ) {
nickjillings@1596 466 for ( ; i < length; i++ ) {
nickjillings@1596 467 value = callback( elems[ i ], i, arg );
nickjillings@1596 468
nickjillings@1596 469 if ( value != null ) {
nickjillings@1596 470 ret.push( value );
nickjillings@1596 471 }
nickjillings@1596 472 }
nickjillings@1596 473
nickjillings@1596 474 // Go through every key on the object,
nickjillings@1596 475 } else {
nickjillings@1596 476 for ( i in elems ) {
nickjillings@1596 477 value = callback( elems[ i ], i, arg );
nickjillings@1596 478
nickjillings@1596 479 if ( value != null ) {
nickjillings@1596 480 ret.push( value );
nickjillings@1596 481 }
nickjillings@1596 482 }
nickjillings@1596 483 }
nickjillings@1596 484
nickjillings@1596 485 // Flatten any nested arrays
nickjillings@1596 486 return concat.apply( [], ret );
nickjillings@1596 487 },
nickjillings@1596 488
nickjillings@1596 489 // A global GUID counter for objects
nickjillings@1596 490 guid: 1,
nickjillings@1596 491
nickjillings@1596 492 // Bind a function to a context, optionally partially applying any
nickjillings@1596 493 // arguments.
nickjillings@1596 494 proxy: function( fn, context ) {
nickjillings@1596 495 var tmp, args, proxy;
nickjillings@1596 496
nickjillings@1596 497 if ( typeof context === "string" ) {
nickjillings@1596 498 tmp = fn[ context ];
nickjillings@1596 499 context = fn;
nickjillings@1596 500 fn = tmp;
nickjillings@1596 501 }
nickjillings@1596 502
nickjillings@1596 503 // Quick check to determine if target is callable, in the spec
nickjillings@1596 504 // this throws a TypeError, but we will just return undefined.
nickjillings@1596 505 if ( !jQuery.isFunction( fn ) ) {
nickjillings@1596 506 return undefined;
nickjillings@1596 507 }
nickjillings@1596 508
nickjillings@1596 509 // Simulated bind
nickjillings@1596 510 args = slice.call( arguments, 2 );
nickjillings@1596 511 proxy = function() {
nickjillings@1596 512 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nickjillings@1596 513 };
nickjillings@1596 514
nickjillings@1596 515 // Set the guid of unique handler to the same of original handler, so it can be removed
nickjillings@1596 516 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nickjillings@1596 517
nickjillings@1596 518 return proxy;
nickjillings@1596 519 },
nickjillings@1596 520
nickjillings@1596 521 now: Date.now,
nickjillings@1596 522
nickjillings@1596 523 // jQuery.support is not used in Core but other projects attach their
nickjillings@1596 524 // properties to it so it needs to exist.
nickjillings@1596 525 support: support
nickjillings@1596 526 });
nickjillings@1596 527
nickjillings@1596 528 // Populate the class2type map
nickjillings@1596 529 jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nickjillings@1596 530 class2type[ "[object " + name + "]" ] = name.toLowerCase();
nickjillings@1596 531 });
nickjillings@1596 532
nickjillings@1596 533 function isArraylike( obj ) {
nickjillings@1596 534
nickjillings@1596 535 // Support: iOS 8.2 (not reproducible in simulator)
nickjillings@1596 536 // `in` check used to prevent JIT error (gh-2145)
nickjillings@1596 537 // hasOwn isn't used here due to false negatives
nickjillings@1596 538 // regarding Nodelist length in IE
nickjillings@1596 539 var length = "length" in obj && obj.length,
nickjillings@1596 540 type = jQuery.type( obj );
nickjillings@1596 541
nickjillings@1596 542 if ( type === "function" || jQuery.isWindow( obj ) ) {
nickjillings@1596 543 return false;
nickjillings@1596 544 }
nickjillings@1596 545
nickjillings@1596 546 if ( obj.nodeType === 1 && length ) {
nickjillings@1596 547 return true;
nickjillings@1596 548 }
nickjillings@1596 549
nickjillings@1596 550 return type === "array" || length === 0 ||
nickjillings@1596 551 typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nickjillings@1596 552 }
nickjillings@1596 553 var Sizzle =
nickjillings@1596 554 /*!
nickjillings@1596 555 * Sizzle CSS Selector Engine v2.2.0-pre
nickjillings@1596 556 * http://sizzlejs.com/
nickjillings@1596 557 *
nickjillings@1596 558 * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1596 559 * Released under the MIT license
nickjillings@1596 560 * http://jquery.org/license
nickjillings@1596 561 *
nickjillings@1596 562 * Date: 2014-12-16
nickjillings@1596 563 */
nickjillings@1596 564 (function( window ) {
nickjillings@1596 565
nickjillings@1596 566 var i,
nickjillings@1596 567 support,
nickjillings@1596 568 Expr,
nickjillings@1596 569 getText,
nickjillings@1596 570 isXML,
nickjillings@1596 571 tokenize,
nickjillings@1596 572 compile,
nickjillings@1596 573 select,
nickjillings@1596 574 outermostContext,
nickjillings@1596 575 sortInput,
nickjillings@1596 576 hasDuplicate,
nickjillings@1596 577
nickjillings@1596 578 // Local document vars
nickjillings@1596 579 setDocument,
nickjillings@1596 580 document,
nickjillings@1596 581 docElem,
nickjillings@1596 582 documentIsHTML,
nickjillings@1596 583 rbuggyQSA,
nickjillings@1596 584 rbuggyMatches,
nickjillings@1596 585 matches,
nickjillings@1596 586 contains,
nickjillings@1596 587
nickjillings@1596 588 // Instance-specific data
nickjillings@1596 589 expando = "sizzle" + 1 * new Date(),
nickjillings@1596 590 preferredDoc = window.document,
nickjillings@1596 591 dirruns = 0,
nickjillings@1596 592 done = 0,
nickjillings@1596 593 classCache = createCache(),
nickjillings@1596 594 tokenCache = createCache(),
nickjillings@1596 595 compilerCache = createCache(),
nickjillings@1596 596 sortOrder = function( a, b ) {
nickjillings@1596 597 if ( a === b ) {
nickjillings@1596 598 hasDuplicate = true;
nickjillings@1596 599 }
nickjillings@1596 600 return 0;
nickjillings@1596 601 },
nickjillings@1596 602
nickjillings@1596 603 // General-purpose constants
nickjillings@1596 604 MAX_NEGATIVE = 1 << 31,
nickjillings@1596 605
nickjillings@1596 606 // Instance methods
nickjillings@1596 607 hasOwn = ({}).hasOwnProperty,
nickjillings@1596 608 arr = [],
nickjillings@1596 609 pop = arr.pop,
nickjillings@1596 610 push_native = arr.push,
nickjillings@1596 611 push = arr.push,
nickjillings@1596 612 slice = arr.slice,
nickjillings@1596 613 // Use a stripped-down indexOf as it's faster than native
nickjillings@1596 614 // http://jsperf.com/thor-indexof-vs-for/5
nickjillings@1596 615 indexOf = function( list, elem ) {
nickjillings@1596 616 var i = 0,
nickjillings@1596 617 len = list.length;
nickjillings@1596 618 for ( ; i < len; i++ ) {
nickjillings@1596 619 if ( list[i] === elem ) {
nickjillings@1596 620 return i;
nickjillings@1596 621 }
nickjillings@1596 622 }
nickjillings@1596 623 return -1;
nickjillings@1596 624 },
nickjillings@1596 625
nickjillings@1596 626 booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nickjillings@1596 627
nickjillings@1596 628 // Regular expressions
nickjillings@1596 629
nickjillings@1596 630 // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nickjillings@1596 631 whitespace = "[\\x20\\t\\r\\n\\f]",
nickjillings@1596 632 // http://www.w3.org/TR/css3-syntax/#characters
nickjillings@1596 633 characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nickjillings@1596 634
nickjillings@1596 635 // Loosely modeled on CSS identifier characters
nickjillings@1596 636 // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nickjillings@1596 637 // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nickjillings@1596 638 identifier = characterEncoding.replace( "w", "w#" ),
nickjillings@1596 639
nickjillings@1596 640 // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nickjillings@1596 641 attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nickjillings@1596 642 // Operator (capture 2)
nickjillings@1596 643 "*([*^$|!~]?=)" + whitespace +
nickjillings@1596 644 // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nickjillings@1596 645 "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nickjillings@1596 646 "*\\]",
nickjillings@1596 647
nickjillings@1596 648 pseudos = ":(" + characterEncoding + ")(?:\\((" +
nickjillings@1596 649 // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nickjillings@1596 650 // 1. quoted (capture 3; capture 4 or capture 5)
nickjillings@1596 651 "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nickjillings@1596 652 // 2. simple (capture 6)
nickjillings@1596 653 "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nickjillings@1596 654 // 3. anything else (capture 2)
nickjillings@1596 655 ".*" +
nickjillings@1596 656 ")\\)|)",
nickjillings@1596 657
nickjillings@1596 658 // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nickjillings@1596 659 rwhitespace = new RegExp( whitespace + "+", "g" ),
nickjillings@1596 660 rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nickjillings@1596 661
nickjillings@1596 662 rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nickjillings@1596 663 rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nickjillings@1596 664
nickjillings@1596 665 rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nickjillings@1596 666
nickjillings@1596 667 rpseudo = new RegExp( pseudos ),
nickjillings@1596 668 ridentifier = new RegExp( "^" + identifier + "$" ),
nickjillings@1596 669
nickjillings@1596 670 matchExpr = {
nickjillings@1596 671 "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nickjillings@1596 672 "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nickjillings@1596 673 "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nickjillings@1596 674 "ATTR": new RegExp( "^" + attributes ),
nickjillings@1596 675 "PSEUDO": new RegExp( "^" + pseudos ),
nickjillings@1596 676 "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nickjillings@1596 677 "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nickjillings@1596 678 "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nickjillings@1596 679 "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nickjillings@1596 680 // For use in libraries implementing .is()
nickjillings@1596 681 // We use this for POS matching in `select`
nickjillings@1596 682 "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nickjillings@1596 683 whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nickjillings@1596 684 },
nickjillings@1596 685
nickjillings@1596 686 rinputs = /^(?:input|select|textarea|button)$/i,
nickjillings@1596 687 rheader = /^h\d$/i,
nickjillings@1596 688
nickjillings@1596 689 rnative = /^[^{]+\{\s*\[native \w/,
nickjillings@1596 690
nickjillings@1596 691 // Easily-parseable/retrievable ID or TAG or CLASS selectors
nickjillings@1596 692 rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nickjillings@1596 693
nickjillings@1596 694 rsibling = /[+~]/,
nickjillings@1596 695 rescape = /'|\\/g,
nickjillings@1596 696
nickjillings@1596 697 // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nickjillings@1596 698 runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nickjillings@1596 699 funescape = function( _, escaped, escapedWhitespace ) {
nickjillings@1596 700 var high = "0x" + escaped - 0x10000;
nickjillings@1596 701 // NaN means non-codepoint
nickjillings@1596 702 // Support: Firefox<24
nickjillings@1596 703 // Workaround erroneous numeric interpretation of +"0x"
nickjillings@1596 704 return high !== high || escapedWhitespace ?
nickjillings@1596 705 escaped :
nickjillings@1596 706 high < 0 ?
nickjillings@1596 707 // BMP codepoint
nickjillings@1596 708 String.fromCharCode( high + 0x10000 ) :
nickjillings@1596 709 // Supplemental Plane codepoint (surrogate pair)
nickjillings@1596 710 String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nickjillings@1596 711 },
nickjillings@1596 712
nickjillings@1596 713 // Used for iframes
nickjillings@1596 714 // See setDocument()
nickjillings@1596 715 // Removing the function wrapper causes a "Permission Denied"
nickjillings@1596 716 // error in IE
nickjillings@1596 717 unloadHandler = function() {
nickjillings@1596 718 setDocument();
nickjillings@1596 719 };
nickjillings@1596 720
nickjillings@1596 721 // Optimize for push.apply( _, NodeList )
nickjillings@1596 722 try {
nickjillings@1596 723 push.apply(
nickjillings@1596 724 (arr = slice.call( preferredDoc.childNodes )),
nickjillings@1596 725 preferredDoc.childNodes
nickjillings@1596 726 );
nickjillings@1596 727 // Support: Android<4.0
nickjillings@1596 728 // Detect silently failing push.apply
nickjillings@1596 729 arr[ preferredDoc.childNodes.length ].nodeType;
nickjillings@1596 730 } catch ( e ) {
nickjillings@1596 731 push = { apply: arr.length ?
nickjillings@1596 732
nickjillings@1596 733 // Leverage slice if possible
nickjillings@1596 734 function( target, els ) {
nickjillings@1596 735 push_native.apply( target, slice.call(els) );
nickjillings@1596 736 } :
nickjillings@1596 737
nickjillings@1596 738 // Support: IE<9
nickjillings@1596 739 // Otherwise append directly
nickjillings@1596 740 function( target, els ) {
nickjillings@1596 741 var j = target.length,
nickjillings@1596 742 i = 0;
nickjillings@1596 743 // Can't trust NodeList.length
nickjillings@1596 744 while ( (target[j++] = els[i++]) ) {}
nickjillings@1596 745 target.length = j - 1;
nickjillings@1596 746 }
nickjillings@1596 747 };
nickjillings@1596 748 }
nickjillings@1596 749
nickjillings@1596 750 function Sizzle( selector, context, results, seed ) {
nickjillings@1596 751 var match, elem, m, nodeType,
nickjillings@1596 752 // QSA vars
nickjillings@1596 753 i, groups, old, nid, newContext, newSelector;
nickjillings@1596 754
nickjillings@1596 755 if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nickjillings@1596 756 setDocument( context );
nickjillings@1596 757 }
nickjillings@1596 758
nickjillings@1596 759 context = context || document;
nickjillings@1596 760 results = results || [];
nickjillings@1596 761 nodeType = context.nodeType;
nickjillings@1596 762
nickjillings@1596 763 if ( typeof selector !== "string" || !selector ||
nickjillings@1596 764 nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nickjillings@1596 765
nickjillings@1596 766 return results;
nickjillings@1596 767 }
nickjillings@1596 768
nickjillings@1596 769 if ( !seed && documentIsHTML ) {
nickjillings@1596 770
nickjillings@1596 771 // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nickjillings@1596 772 if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nickjillings@1596 773 // Speed-up: Sizzle("#ID")
nickjillings@1596 774 if ( (m = match[1]) ) {
nickjillings@1596 775 if ( nodeType === 9 ) {
nickjillings@1596 776 elem = context.getElementById( m );
nickjillings@1596 777 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1596 778 // nodes that are no longer in the document (jQuery #6963)
nickjillings@1596 779 if ( elem && elem.parentNode ) {
nickjillings@1596 780 // Handle the case where IE, Opera, and Webkit return items
nickjillings@1596 781 // by name instead of ID
nickjillings@1596 782 if ( elem.id === m ) {
nickjillings@1596 783 results.push( elem );
nickjillings@1596 784 return results;
nickjillings@1596 785 }
nickjillings@1596 786 } else {
nickjillings@1596 787 return results;
nickjillings@1596 788 }
nickjillings@1596 789 } else {
nickjillings@1596 790 // Context is not a document
nickjillings@1596 791 if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nickjillings@1596 792 contains( context, elem ) && elem.id === m ) {
nickjillings@1596 793 results.push( elem );
nickjillings@1596 794 return results;
nickjillings@1596 795 }
nickjillings@1596 796 }
nickjillings@1596 797
nickjillings@1596 798 // Speed-up: Sizzle("TAG")
nickjillings@1596 799 } else if ( match[2] ) {
nickjillings@1596 800 push.apply( results, context.getElementsByTagName( selector ) );
nickjillings@1596 801 return results;
nickjillings@1596 802
nickjillings@1596 803 // Speed-up: Sizzle(".CLASS")
nickjillings@1596 804 } else if ( (m = match[3]) && support.getElementsByClassName ) {
nickjillings@1596 805 push.apply( results, context.getElementsByClassName( m ) );
nickjillings@1596 806 return results;
nickjillings@1596 807 }
nickjillings@1596 808 }
nickjillings@1596 809
nickjillings@1596 810 // QSA path
nickjillings@1596 811 if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nickjillings@1596 812 nid = old = expando;
nickjillings@1596 813 newContext = context;
nickjillings@1596 814 newSelector = nodeType !== 1 && selector;
nickjillings@1596 815
nickjillings@1596 816 // qSA works strangely on Element-rooted queries
nickjillings@1596 817 // We can work around this by specifying an extra ID on the root
nickjillings@1596 818 // and working up from there (Thanks to Andrew Dupont for the technique)
nickjillings@1596 819 // IE 8 doesn't work on object elements
nickjillings@1596 820 if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nickjillings@1596 821 groups = tokenize( selector );
nickjillings@1596 822
nickjillings@1596 823 if ( (old = context.getAttribute("id")) ) {
nickjillings@1596 824 nid = old.replace( rescape, "\\$&" );
nickjillings@1596 825 } else {
nickjillings@1596 826 context.setAttribute( "id", nid );
nickjillings@1596 827 }
nickjillings@1596 828 nid = "[id='" + nid + "'] ";
nickjillings@1596 829
nickjillings@1596 830 i = groups.length;
nickjillings@1596 831 while ( i-- ) {
nickjillings@1596 832 groups[i] = nid + toSelector( groups[i] );
nickjillings@1596 833 }
nickjillings@1596 834 newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nickjillings@1596 835 newSelector = groups.join(",");
nickjillings@1596 836 }
nickjillings@1596 837
nickjillings@1596 838 if ( newSelector ) {
nickjillings@1596 839 try {
nickjillings@1596 840 push.apply( results,
nickjillings@1596 841 newContext.querySelectorAll( newSelector )
nickjillings@1596 842 );
nickjillings@1596 843 return results;
nickjillings@1596 844 } catch(qsaError) {
nickjillings@1596 845 } finally {
nickjillings@1596 846 if ( !old ) {
nickjillings@1596 847 context.removeAttribute("id");
nickjillings@1596 848 }
nickjillings@1596 849 }
nickjillings@1596 850 }
nickjillings@1596 851 }
nickjillings@1596 852 }
nickjillings@1596 853
nickjillings@1596 854 // All others
nickjillings@1596 855 return select( selector.replace( rtrim, "$1" ), context, results, seed );
nickjillings@1596 856 }
nickjillings@1596 857
nickjillings@1596 858 /**
nickjillings@1596 859 * Create key-value caches of limited size
nickjillings@1596 860 * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nickjillings@1596 861 * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nickjillings@1596 862 * deleting the oldest entry
nickjillings@1596 863 */
nickjillings@1596 864 function createCache() {
nickjillings@1596 865 var keys = [];
nickjillings@1596 866
nickjillings@1596 867 function cache( key, value ) {
nickjillings@1596 868 // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nickjillings@1596 869 if ( keys.push( key + " " ) > Expr.cacheLength ) {
nickjillings@1596 870 // Only keep the most recent entries
nickjillings@1596 871 delete cache[ keys.shift() ];
nickjillings@1596 872 }
nickjillings@1596 873 return (cache[ key + " " ] = value);
nickjillings@1596 874 }
nickjillings@1596 875 return cache;
nickjillings@1596 876 }
nickjillings@1596 877
nickjillings@1596 878 /**
nickjillings@1596 879 * Mark a function for special use by Sizzle
nickjillings@1596 880 * @param {Function} fn The function to mark
nickjillings@1596 881 */
nickjillings@1596 882 function markFunction( fn ) {
nickjillings@1596 883 fn[ expando ] = true;
nickjillings@1596 884 return fn;
nickjillings@1596 885 }
nickjillings@1596 886
nickjillings@1596 887 /**
nickjillings@1596 888 * Support testing using an element
nickjillings@1596 889 * @param {Function} fn Passed the created div and expects a boolean result
nickjillings@1596 890 */
nickjillings@1596 891 function assert( fn ) {
nickjillings@1596 892 var div = document.createElement("div");
nickjillings@1596 893
nickjillings@1596 894 try {
nickjillings@1596 895 return !!fn( div );
nickjillings@1596 896 } catch (e) {
nickjillings@1596 897 return false;
nickjillings@1596 898 } finally {
nickjillings@1596 899 // Remove from its parent by default
nickjillings@1596 900 if ( div.parentNode ) {
nickjillings@1596 901 div.parentNode.removeChild( div );
nickjillings@1596 902 }
nickjillings@1596 903 // release memory in IE
nickjillings@1596 904 div = null;
nickjillings@1596 905 }
nickjillings@1596 906 }
nickjillings@1596 907
nickjillings@1596 908 /**
nickjillings@1596 909 * Adds the same handler for all of the specified attrs
nickjillings@1596 910 * @param {String} attrs Pipe-separated list of attributes
nickjillings@1596 911 * @param {Function} handler The method that will be applied
nickjillings@1596 912 */
nickjillings@1596 913 function addHandle( attrs, handler ) {
nickjillings@1596 914 var arr = attrs.split("|"),
nickjillings@1596 915 i = attrs.length;
nickjillings@1596 916
nickjillings@1596 917 while ( i-- ) {
nickjillings@1596 918 Expr.attrHandle[ arr[i] ] = handler;
nickjillings@1596 919 }
nickjillings@1596 920 }
nickjillings@1596 921
nickjillings@1596 922 /**
nickjillings@1596 923 * Checks document order of two siblings
nickjillings@1596 924 * @param {Element} a
nickjillings@1596 925 * @param {Element} b
nickjillings@1596 926 * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nickjillings@1596 927 */
nickjillings@1596 928 function siblingCheck( a, b ) {
nickjillings@1596 929 var cur = b && a,
nickjillings@1596 930 diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nickjillings@1596 931 ( ~b.sourceIndex || MAX_NEGATIVE ) -
nickjillings@1596 932 ( ~a.sourceIndex || MAX_NEGATIVE );
nickjillings@1596 933
nickjillings@1596 934 // Use IE sourceIndex if available on both nodes
nickjillings@1596 935 if ( diff ) {
nickjillings@1596 936 return diff;
nickjillings@1596 937 }
nickjillings@1596 938
nickjillings@1596 939 // Check if b follows a
nickjillings@1596 940 if ( cur ) {
nickjillings@1596 941 while ( (cur = cur.nextSibling) ) {
nickjillings@1596 942 if ( cur === b ) {
nickjillings@1596 943 return -1;
nickjillings@1596 944 }
nickjillings@1596 945 }
nickjillings@1596 946 }
nickjillings@1596 947
nickjillings@1596 948 return a ? 1 : -1;
nickjillings@1596 949 }
nickjillings@1596 950
nickjillings@1596 951 /**
nickjillings@1596 952 * Returns a function to use in pseudos for input types
nickjillings@1596 953 * @param {String} type
nickjillings@1596 954 */
nickjillings@1596 955 function createInputPseudo( type ) {
nickjillings@1596 956 return function( elem ) {
nickjillings@1596 957 var name = elem.nodeName.toLowerCase();
nickjillings@1596 958 return name === "input" && elem.type === type;
nickjillings@1596 959 };
nickjillings@1596 960 }
nickjillings@1596 961
nickjillings@1596 962 /**
nickjillings@1596 963 * Returns a function to use in pseudos for buttons
nickjillings@1596 964 * @param {String} type
nickjillings@1596 965 */
nickjillings@1596 966 function createButtonPseudo( type ) {
nickjillings@1596 967 return function( elem ) {
nickjillings@1596 968 var name = elem.nodeName.toLowerCase();
nickjillings@1596 969 return (name === "input" || name === "button") && elem.type === type;
nickjillings@1596 970 };
nickjillings@1596 971 }
nickjillings@1596 972
nickjillings@1596 973 /**
nickjillings@1596 974 * Returns a function to use in pseudos for positionals
nickjillings@1596 975 * @param {Function} fn
nickjillings@1596 976 */
nickjillings@1596 977 function createPositionalPseudo( fn ) {
nickjillings@1596 978 return markFunction(function( argument ) {
nickjillings@1596 979 argument = +argument;
nickjillings@1596 980 return markFunction(function( seed, matches ) {
nickjillings@1596 981 var j,
nickjillings@1596 982 matchIndexes = fn( [], seed.length, argument ),
nickjillings@1596 983 i = matchIndexes.length;
nickjillings@1596 984
nickjillings@1596 985 // Match elements found at the specified indexes
nickjillings@1596 986 while ( i-- ) {
nickjillings@1596 987 if ( seed[ (j = matchIndexes[i]) ] ) {
nickjillings@1596 988 seed[j] = !(matches[j] = seed[j]);
nickjillings@1596 989 }
nickjillings@1596 990 }
nickjillings@1596 991 });
nickjillings@1596 992 });
nickjillings@1596 993 }
nickjillings@1596 994
nickjillings@1596 995 /**
nickjillings@1596 996 * Checks a node for validity as a Sizzle context
nickjillings@1596 997 * @param {Element|Object=} context
nickjillings@1596 998 * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nickjillings@1596 999 */
nickjillings@1596 1000 function testContext( context ) {
nickjillings@1596 1001 return context && typeof context.getElementsByTagName !== "undefined" && context;
nickjillings@1596 1002 }
nickjillings@1596 1003
nickjillings@1596 1004 // Expose support vars for convenience
nickjillings@1596 1005 support = Sizzle.support = {};
nickjillings@1596 1006
nickjillings@1596 1007 /**
nickjillings@1596 1008 * Detects XML nodes
nickjillings@1596 1009 * @param {Element|Object} elem An element or a document
nickjillings@1596 1010 * @returns {Boolean} True iff elem is a non-HTML XML node
nickjillings@1596 1011 */
nickjillings@1596 1012 isXML = Sizzle.isXML = function( elem ) {
nickjillings@1596 1013 // documentElement is verified for cases where it doesn't yet exist
nickjillings@1596 1014 // (such as loading iframes in IE - #4833)
nickjillings@1596 1015 var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nickjillings@1596 1016 return documentElement ? documentElement.nodeName !== "HTML" : false;
nickjillings@1596 1017 };
nickjillings@1596 1018
nickjillings@1596 1019 /**
nickjillings@1596 1020 * Sets document-related variables once based on the current document
nickjillings@1596 1021 * @param {Element|Object} [doc] An element or document object to use to set the document
nickjillings@1596 1022 * @returns {Object} Returns the current document
nickjillings@1596 1023 */
nickjillings@1596 1024 setDocument = Sizzle.setDocument = function( node ) {
nickjillings@1596 1025 var hasCompare, parent,
nickjillings@1596 1026 doc = node ? node.ownerDocument || node : preferredDoc;
nickjillings@1596 1027
nickjillings@1596 1028 // If no document and documentElement is available, return
nickjillings@1596 1029 if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nickjillings@1596 1030 return document;
nickjillings@1596 1031 }
nickjillings@1596 1032
nickjillings@1596 1033 // Set our document
nickjillings@1596 1034 document = doc;
nickjillings@1596 1035 docElem = doc.documentElement;
nickjillings@1596 1036 parent = doc.defaultView;
nickjillings@1596 1037
nickjillings@1596 1038 // Support: IE>8
nickjillings@1596 1039 // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nickjillings@1596 1040 // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nickjillings@1596 1041 // IE6-8 do not support the defaultView property so parent will be undefined
nickjillings@1596 1042 if ( parent && parent !== parent.top ) {
nickjillings@1596 1043 // IE11 does not have attachEvent, so all must suffer
nickjillings@1596 1044 if ( parent.addEventListener ) {
nickjillings@1596 1045 parent.addEventListener( "unload", unloadHandler, false );
nickjillings@1596 1046 } else if ( parent.attachEvent ) {
nickjillings@1596 1047 parent.attachEvent( "onunload", unloadHandler );
nickjillings@1596 1048 }
nickjillings@1596 1049 }
nickjillings@1596 1050
nickjillings@1596 1051 /* Support tests
nickjillings@1596 1052 ---------------------------------------------------------------------- */
nickjillings@1596 1053 documentIsHTML = !isXML( doc );
nickjillings@1596 1054
nickjillings@1596 1055 /* Attributes
nickjillings@1596 1056 ---------------------------------------------------------------------- */
nickjillings@1596 1057
nickjillings@1596 1058 // Support: IE<8
nickjillings@1596 1059 // Verify that getAttribute really returns attributes and not properties
nickjillings@1596 1060 // (excepting IE8 booleans)
nickjillings@1596 1061 support.attributes = assert(function( div ) {
nickjillings@1596 1062 div.className = "i";
nickjillings@1596 1063 return !div.getAttribute("className");
nickjillings@1596 1064 });
nickjillings@1596 1065
nickjillings@1596 1066 /* getElement(s)By*
nickjillings@1596 1067 ---------------------------------------------------------------------- */
nickjillings@1596 1068
nickjillings@1596 1069 // Check if getElementsByTagName("*") returns only elements
nickjillings@1596 1070 support.getElementsByTagName = assert(function( div ) {
nickjillings@1596 1071 div.appendChild( doc.createComment("") );
nickjillings@1596 1072 return !div.getElementsByTagName("*").length;
nickjillings@1596 1073 });
nickjillings@1596 1074
nickjillings@1596 1075 // Support: IE<9
nickjillings@1596 1076 support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nickjillings@1596 1077
nickjillings@1596 1078 // Support: IE<10
nickjillings@1596 1079 // Check if getElementById returns elements by name
nickjillings@1596 1080 // The broken getElementById methods don't pick up programatically-set names,
nickjillings@1596 1081 // so use a roundabout getElementsByName test
nickjillings@1596 1082 support.getById = assert(function( div ) {
nickjillings@1596 1083 docElem.appendChild( div ).id = expando;
nickjillings@1596 1084 return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nickjillings@1596 1085 });
nickjillings@1596 1086
nickjillings@1596 1087 // ID find and filter
nickjillings@1596 1088 if ( support.getById ) {
nickjillings@1596 1089 Expr.find["ID"] = function( id, context ) {
nickjillings@1596 1090 if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nickjillings@1596 1091 var m = context.getElementById( id );
nickjillings@1596 1092 // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1596 1093 // nodes that are no longer in the document #6963
nickjillings@1596 1094 return m && m.parentNode ? [ m ] : [];
nickjillings@1596 1095 }
nickjillings@1596 1096 };
nickjillings@1596 1097 Expr.filter["ID"] = function( id ) {
nickjillings@1596 1098 var attrId = id.replace( runescape, funescape );
nickjillings@1596 1099 return function( elem ) {
nickjillings@1596 1100 return elem.getAttribute("id") === attrId;
nickjillings@1596 1101 };
nickjillings@1596 1102 };
nickjillings@1596 1103 } else {
nickjillings@1596 1104 // Support: IE6/7
nickjillings@1596 1105 // getElementById is not reliable as a find shortcut
nickjillings@1596 1106 delete Expr.find["ID"];
nickjillings@1596 1107
nickjillings@1596 1108 Expr.filter["ID"] = function( id ) {
nickjillings@1596 1109 var attrId = id.replace( runescape, funescape );
nickjillings@1596 1110 return function( elem ) {
nickjillings@1596 1111 var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nickjillings@1596 1112 return node && node.value === attrId;
nickjillings@1596 1113 };
nickjillings@1596 1114 };
nickjillings@1596 1115 }
nickjillings@1596 1116
nickjillings@1596 1117 // Tag
nickjillings@1596 1118 Expr.find["TAG"] = support.getElementsByTagName ?
nickjillings@1596 1119 function( tag, context ) {
nickjillings@1596 1120 if ( typeof context.getElementsByTagName !== "undefined" ) {
nickjillings@1596 1121 return context.getElementsByTagName( tag );
nickjillings@1596 1122
nickjillings@1596 1123 // DocumentFragment nodes don't have gEBTN
nickjillings@1596 1124 } else if ( support.qsa ) {
nickjillings@1596 1125 return context.querySelectorAll( tag );
nickjillings@1596 1126 }
nickjillings@1596 1127 } :
nickjillings@1596 1128
nickjillings@1596 1129 function( tag, context ) {
nickjillings@1596 1130 var elem,
nickjillings@1596 1131 tmp = [],
nickjillings@1596 1132 i = 0,
nickjillings@1596 1133 // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nickjillings@1596 1134 results = context.getElementsByTagName( tag );
nickjillings@1596 1135
nickjillings@1596 1136 // Filter out possible comments
nickjillings@1596 1137 if ( tag === "*" ) {
nickjillings@1596 1138 while ( (elem = results[i++]) ) {
nickjillings@1596 1139 if ( elem.nodeType === 1 ) {
nickjillings@1596 1140 tmp.push( elem );
nickjillings@1596 1141 }
nickjillings@1596 1142 }
nickjillings@1596 1143
nickjillings@1596 1144 return tmp;
nickjillings@1596 1145 }
nickjillings@1596 1146 return results;
nickjillings@1596 1147 };
nickjillings@1596 1148
nickjillings@1596 1149 // Class
nickjillings@1596 1150 Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nickjillings@1596 1151 if ( documentIsHTML ) {
nickjillings@1596 1152 return context.getElementsByClassName( className );
nickjillings@1596 1153 }
nickjillings@1596 1154 };
nickjillings@1596 1155
nickjillings@1596 1156 /* QSA/matchesSelector
nickjillings@1596 1157 ---------------------------------------------------------------------- */
nickjillings@1596 1158
nickjillings@1596 1159 // QSA and matchesSelector support
nickjillings@1596 1160
nickjillings@1596 1161 // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nickjillings@1596 1162 rbuggyMatches = [];
nickjillings@1596 1163
nickjillings@1596 1164 // qSa(:focus) reports false when true (Chrome 21)
nickjillings@1596 1165 // We allow this because of a bug in IE8/9 that throws an error
nickjillings@1596 1166 // whenever `document.activeElement` is accessed on an iframe
nickjillings@1596 1167 // So, we allow :focus to pass through QSA all the time to avoid the IE error
nickjillings@1596 1168 // See http://bugs.jquery.com/ticket/13378
nickjillings@1596 1169 rbuggyQSA = [];
nickjillings@1596 1170
nickjillings@1596 1171 if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nickjillings@1596 1172 // Build QSA regex
nickjillings@1596 1173 // Regex strategy adopted from Diego Perini
nickjillings@1596 1174 assert(function( div ) {
nickjillings@1596 1175 // Select is set to empty string on purpose
nickjillings@1596 1176 // This is to test IE's treatment of not explicitly
nickjillings@1596 1177 // setting a boolean content attribute,
nickjillings@1596 1178 // since its presence should be enough
nickjillings@1596 1179 // http://bugs.jquery.com/ticket/12359
nickjillings@1596 1180 docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
nickjillings@1596 1181 "<select id='" + expando + "-\f]' msallowcapture=''>" +
nickjillings@1596 1182 "<option selected=''></option></select>";
nickjillings@1596 1183
nickjillings@1596 1184 // Support: IE8, Opera 11-12.16
nickjillings@1596 1185 // Nothing should be selected when empty strings follow ^= or $= or *=
nickjillings@1596 1186 // The test attribute must be unknown in Opera but "safe" for WinRT
nickjillings@1596 1187 // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nickjillings@1596 1188 if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nickjillings@1596 1189 rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nickjillings@1596 1190 }
nickjillings@1596 1191
nickjillings@1596 1192 // Support: IE8
nickjillings@1596 1193 // Boolean attributes and "value" are not treated correctly
nickjillings@1596 1194 if ( !div.querySelectorAll("[selected]").length ) {
nickjillings@1596 1195 rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nickjillings@1596 1196 }
nickjillings@1596 1197
nickjillings@1596 1198 // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nickjillings@1596 1199 if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nickjillings@1596 1200 rbuggyQSA.push("~=");
nickjillings@1596 1201 }
nickjillings@1596 1202
nickjillings@1596 1203 // Webkit/Opera - :checked should return selected option elements
nickjillings@1596 1204 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1596 1205 // IE8 throws error here and will not see later tests
nickjillings@1596 1206 if ( !div.querySelectorAll(":checked").length ) {
nickjillings@1596 1207 rbuggyQSA.push(":checked");
nickjillings@1596 1208 }
nickjillings@1596 1209
nickjillings@1596 1210 // Support: Safari 8+, iOS 8+
nickjillings@1596 1211 // https://bugs.webkit.org/show_bug.cgi?id=136851
nickjillings@1596 1212 // In-page `selector#id sibing-combinator selector` fails
nickjillings@1596 1213 if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nickjillings@1596 1214 rbuggyQSA.push(".#.+[+~]");
nickjillings@1596 1215 }
nickjillings@1596 1216 });
nickjillings@1596 1217
nickjillings@1596 1218 assert(function( div ) {
nickjillings@1596 1219 // Support: Windows 8 Native Apps
nickjillings@1596 1220 // The type and name attributes are restricted during .innerHTML assignment
nickjillings@1596 1221 var input = doc.createElement("input");
nickjillings@1596 1222 input.setAttribute( "type", "hidden" );
nickjillings@1596 1223 div.appendChild( input ).setAttribute( "name", "D" );
nickjillings@1596 1224
nickjillings@1596 1225 // Support: IE8
nickjillings@1596 1226 // Enforce case-sensitivity of name attribute
nickjillings@1596 1227 if ( div.querySelectorAll("[name=d]").length ) {
nickjillings@1596 1228 rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nickjillings@1596 1229 }
nickjillings@1596 1230
nickjillings@1596 1231 // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nickjillings@1596 1232 // IE8 throws error here and will not see later tests
nickjillings@1596 1233 if ( !div.querySelectorAll(":enabled").length ) {
nickjillings@1596 1234 rbuggyQSA.push( ":enabled", ":disabled" );
nickjillings@1596 1235 }
nickjillings@1596 1236
nickjillings@1596 1237 // Opera 10-11 does not throw on post-comma invalid pseudos
nickjillings@1596 1238 div.querySelectorAll("*,:x");
nickjillings@1596 1239 rbuggyQSA.push(",.*:");
nickjillings@1596 1240 });
nickjillings@1596 1241 }
nickjillings@1596 1242
nickjillings@1596 1243 if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nickjillings@1596 1244 docElem.webkitMatchesSelector ||
nickjillings@1596 1245 docElem.mozMatchesSelector ||
nickjillings@1596 1246 docElem.oMatchesSelector ||
nickjillings@1596 1247 docElem.msMatchesSelector) )) ) {
nickjillings@1596 1248
nickjillings@1596 1249 assert(function( div ) {
nickjillings@1596 1250 // Check to see if it's possible to do matchesSelector
nickjillings@1596 1251 // on a disconnected node (IE 9)
nickjillings@1596 1252 support.disconnectedMatch = matches.call( div, "div" );
nickjillings@1596 1253
nickjillings@1596 1254 // This should fail with an exception
nickjillings@1596 1255 // Gecko does not error, returns false instead
nickjillings@1596 1256 matches.call( div, "[s!='']:x" );
nickjillings@1596 1257 rbuggyMatches.push( "!=", pseudos );
nickjillings@1596 1258 });
nickjillings@1596 1259 }
nickjillings@1596 1260
nickjillings@1596 1261 rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nickjillings@1596 1262 rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nickjillings@1596 1263
nickjillings@1596 1264 /* Contains
nickjillings@1596 1265 ---------------------------------------------------------------------- */
nickjillings@1596 1266 hasCompare = rnative.test( docElem.compareDocumentPosition );
nickjillings@1596 1267
nickjillings@1596 1268 // Element contains another
nickjillings@1596 1269 // Purposefully does not implement inclusive descendent
nickjillings@1596 1270 // As in, an element does not contain itself
nickjillings@1596 1271 contains = hasCompare || rnative.test( docElem.contains ) ?
nickjillings@1596 1272 function( a, b ) {
nickjillings@1596 1273 var adown = a.nodeType === 9 ? a.documentElement : a,
nickjillings@1596 1274 bup = b && b.parentNode;
nickjillings@1596 1275 return a === bup || !!( bup && bup.nodeType === 1 && (
nickjillings@1596 1276 adown.contains ?
nickjillings@1596 1277 adown.contains( bup ) :
nickjillings@1596 1278 a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nickjillings@1596 1279 ));
nickjillings@1596 1280 } :
nickjillings@1596 1281 function( a, b ) {
nickjillings@1596 1282 if ( b ) {
nickjillings@1596 1283 while ( (b = b.parentNode) ) {
nickjillings@1596 1284 if ( b === a ) {
nickjillings@1596 1285 return true;
nickjillings@1596 1286 }
nickjillings@1596 1287 }
nickjillings@1596 1288 }
nickjillings@1596 1289 return false;
nickjillings@1596 1290 };
nickjillings@1596 1291
nickjillings@1596 1292 /* Sorting
nickjillings@1596 1293 ---------------------------------------------------------------------- */
nickjillings@1596 1294
nickjillings@1596 1295 // Document order sorting
nickjillings@1596 1296 sortOrder = hasCompare ?
nickjillings@1596 1297 function( a, b ) {
nickjillings@1596 1298
nickjillings@1596 1299 // Flag for duplicate removal
nickjillings@1596 1300 if ( a === b ) {
nickjillings@1596 1301 hasDuplicate = true;
nickjillings@1596 1302 return 0;
nickjillings@1596 1303 }
nickjillings@1596 1304
nickjillings@1596 1305 // Sort on method existence if only one input has compareDocumentPosition
nickjillings@1596 1306 var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nickjillings@1596 1307 if ( compare ) {
nickjillings@1596 1308 return compare;
nickjillings@1596 1309 }
nickjillings@1596 1310
nickjillings@1596 1311 // Calculate position if both inputs belong to the same document
nickjillings@1596 1312 compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nickjillings@1596 1313 a.compareDocumentPosition( b ) :
nickjillings@1596 1314
nickjillings@1596 1315 // Otherwise we know they are disconnected
nickjillings@1596 1316 1;
nickjillings@1596 1317
nickjillings@1596 1318 // Disconnected nodes
nickjillings@1596 1319 if ( compare & 1 ||
nickjillings@1596 1320 (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nickjillings@1596 1321
nickjillings@1596 1322 // Choose the first element that is related to our preferred document
nickjillings@1596 1323 if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nickjillings@1596 1324 return -1;
nickjillings@1596 1325 }
nickjillings@1596 1326 if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nickjillings@1596 1327 return 1;
nickjillings@1596 1328 }
nickjillings@1596 1329
nickjillings@1596 1330 // Maintain original order
nickjillings@1596 1331 return sortInput ?
nickjillings@1596 1332 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1596 1333 0;
nickjillings@1596 1334 }
nickjillings@1596 1335
nickjillings@1596 1336 return compare & 4 ? -1 : 1;
nickjillings@1596 1337 } :
nickjillings@1596 1338 function( a, b ) {
nickjillings@1596 1339 // Exit early if the nodes are identical
nickjillings@1596 1340 if ( a === b ) {
nickjillings@1596 1341 hasDuplicate = true;
nickjillings@1596 1342 return 0;
nickjillings@1596 1343 }
nickjillings@1596 1344
nickjillings@1596 1345 var cur,
nickjillings@1596 1346 i = 0,
nickjillings@1596 1347 aup = a.parentNode,
nickjillings@1596 1348 bup = b.parentNode,
nickjillings@1596 1349 ap = [ a ],
nickjillings@1596 1350 bp = [ b ];
nickjillings@1596 1351
nickjillings@1596 1352 // Parentless nodes are either documents or disconnected
nickjillings@1596 1353 if ( !aup || !bup ) {
nickjillings@1596 1354 return a === doc ? -1 :
nickjillings@1596 1355 b === doc ? 1 :
nickjillings@1596 1356 aup ? -1 :
nickjillings@1596 1357 bup ? 1 :
nickjillings@1596 1358 sortInput ?
nickjillings@1596 1359 ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1596 1360 0;
nickjillings@1596 1361
nickjillings@1596 1362 // If the nodes are siblings, we can do a quick check
nickjillings@1596 1363 } else if ( aup === bup ) {
nickjillings@1596 1364 return siblingCheck( a, b );
nickjillings@1596 1365 }
nickjillings@1596 1366
nickjillings@1596 1367 // Otherwise we need full lists of their ancestors for comparison
nickjillings@1596 1368 cur = a;
nickjillings@1596 1369 while ( (cur = cur.parentNode) ) {
nickjillings@1596 1370 ap.unshift( cur );
nickjillings@1596 1371 }
nickjillings@1596 1372 cur = b;
nickjillings@1596 1373 while ( (cur = cur.parentNode) ) {
nickjillings@1596 1374 bp.unshift( cur );
nickjillings@1596 1375 }
nickjillings@1596 1376
nickjillings@1596 1377 // Walk down the tree looking for a discrepancy
nickjillings@1596 1378 while ( ap[i] === bp[i] ) {
nickjillings@1596 1379 i++;
nickjillings@1596 1380 }
nickjillings@1596 1381
nickjillings@1596 1382 return i ?
nickjillings@1596 1383 // Do a sibling check if the nodes have a common ancestor
nickjillings@1596 1384 siblingCheck( ap[i], bp[i] ) :
nickjillings@1596 1385
nickjillings@1596 1386 // Otherwise nodes in our document sort first
nickjillings@1596 1387 ap[i] === preferredDoc ? -1 :
nickjillings@1596 1388 bp[i] === preferredDoc ? 1 :
nickjillings@1596 1389 0;
nickjillings@1596 1390 };
nickjillings@1596 1391
nickjillings@1596 1392 return doc;
nickjillings@1596 1393 };
nickjillings@1596 1394
nickjillings@1596 1395 Sizzle.matches = function( expr, elements ) {
nickjillings@1596 1396 return Sizzle( expr, null, null, elements );
nickjillings@1596 1397 };
nickjillings@1596 1398
nickjillings@1596 1399 Sizzle.matchesSelector = function( elem, expr ) {
nickjillings@1596 1400 // Set document vars if needed
nickjillings@1596 1401 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1596 1402 setDocument( elem );
nickjillings@1596 1403 }
nickjillings@1596 1404
nickjillings@1596 1405 // Make sure that attribute selectors are quoted
nickjillings@1596 1406 expr = expr.replace( rattributeQuotes, "='$1']" );
nickjillings@1596 1407
nickjillings@1596 1408 if ( support.matchesSelector && documentIsHTML &&
nickjillings@1596 1409 ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nickjillings@1596 1410 ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nickjillings@1596 1411
nickjillings@1596 1412 try {
nickjillings@1596 1413 var ret = matches.call( elem, expr );
nickjillings@1596 1414
nickjillings@1596 1415 // IE 9's matchesSelector returns false on disconnected nodes
nickjillings@1596 1416 if ( ret || support.disconnectedMatch ||
nickjillings@1596 1417 // As well, disconnected nodes are said to be in a document
nickjillings@1596 1418 // fragment in IE 9
nickjillings@1596 1419 elem.document && elem.document.nodeType !== 11 ) {
nickjillings@1596 1420 return ret;
nickjillings@1596 1421 }
nickjillings@1596 1422 } catch (e) {}
nickjillings@1596 1423 }
nickjillings@1596 1424
nickjillings@1596 1425 return Sizzle( expr, document, null, [ elem ] ).length > 0;
nickjillings@1596 1426 };
nickjillings@1596 1427
nickjillings@1596 1428 Sizzle.contains = function( context, elem ) {
nickjillings@1596 1429 // Set document vars if needed
nickjillings@1596 1430 if ( ( context.ownerDocument || context ) !== document ) {
nickjillings@1596 1431 setDocument( context );
nickjillings@1596 1432 }
nickjillings@1596 1433 return contains( context, elem );
nickjillings@1596 1434 };
nickjillings@1596 1435
nickjillings@1596 1436 Sizzle.attr = function( elem, name ) {
nickjillings@1596 1437 // Set document vars if needed
nickjillings@1596 1438 if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1596 1439 setDocument( elem );
nickjillings@1596 1440 }
nickjillings@1596 1441
nickjillings@1596 1442 var fn = Expr.attrHandle[ name.toLowerCase() ],
nickjillings@1596 1443 // Don't get fooled by Object.prototype properties (jQuery #13807)
nickjillings@1596 1444 val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nickjillings@1596 1445 fn( elem, name, !documentIsHTML ) :
nickjillings@1596 1446 undefined;
nickjillings@1596 1447
nickjillings@1596 1448 return val !== undefined ?
nickjillings@1596 1449 val :
nickjillings@1596 1450 support.attributes || !documentIsHTML ?
nickjillings@1596 1451 elem.getAttribute( name ) :
nickjillings@1596 1452 (val = elem.getAttributeNode(name)) && val.specified ?
nickjillings@1596 1453 val.value :
nickjillings@1596 1454 null;
nickjillings@1596 1455 };
nickjillings@1596 1456
nickjillings@1596 1457 Sizzle.error = function( msg ) {
nickjillings@1596 1458 throw new Error( "Syntax error, unrecognized expression: " + msg );
nickjillings@1596 1459 };
nickjillings@1596 1460
nickjillings@1596 1461 /**
nickjillings@1596 1462 * Document sorting and removing duplicates
nickjillings@1596 1463 * @param {ArrayLike} results
nickjillings@1596 1464 */
nickjillings@1596 1465 Sizzle.uniqueSort = function( results ) {
nickjillings@1596 1466 var elem,
nickjillings@1596 1467 duplicates = [],
nickjillings@1596 1468 j = 0,
nickjillings@1596 1469 i = 0;
nickjillings@1596 1470
nickjillings@1596 1471 // Unless we *know* we can detect duplicates, assume their presence
nickjillings@1596 1472 hasDuplicate = !support.detectDuplicates;
nickjillings@1596 1473 sortInput = !support.sortStable && results.slice( 0 );
nickjillings@1596 1474 results.sort( sortOrder );
nickjillings@1596 1475
nickjillings@1596 1476 if ( hasDuplicate ) {
nickjillings@1596 1477 while ( (elem = results[i++]) ) {
nickjillings@1596 1478 if ( elem === results[ i ] ) {
nickjillings@1596 1479 j = duplicates.push( i );
nickjillings@1596 1480 }
nickjillings@1596 1481 }
nickjillings@1596 1482 while ( j-- ) {
nickjillings@1596 1483 results.splice( duplicates[ j ], 1 );
nickjillings@1596 1484 }
nickjillings@1596 1485 }
nickjillings@1596 1486
nickjillings@1596 1487 // Clear input after sorting to release objects
nickjillings@1596 1488 // See https://github.com/jquery/sizzle/pull/225
nickjillings@1596 1489 sortInput = null;
nickjillings@1596 1490
nickjillings@1596 1491 return results;
nickjillings@1596 1492 };
nickjillings@1596 1493
nickjillings@1596 1494 /**
nickjillings@1596 1495 * Utility function for retrieving the text value of an array of DOM nodes
nickjillings@1596 1496 * @param {Array|Element} elem
nickjillings@1596 1497 */
nickjillings@1596 1498 getText = Sizzle.getText = function( elem ) {
nickjillings@1596 1499 var node,
nickjillings@1596 1500 ret = "",
nickjillings@1596 1501 i = 0,
nickjillings@1596 1502 nodeType = elem.nodeType;
nickjillings@1596 1503
nickjillings@1596 1504 if ( !nodeType ) {
nickjillings@1596 1505 // If no nodeType, this is expected to be an array
nickjillings@1596 1506 while ( (node = elem[i++]) ) {
nickjillings@1596 1507 // Do not traverse comment nodes
nickjillings@1596 1508 ret += getText( node );
nickjillings@1596 1509 }
nickjillings@1596 1510 } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nickjillings@1596 1511 // Use textContent for elements
nickjillings@1596 1512 // innerText usage removed for consistency of new lines (jQuery #11153)
nickjillings@1596 1513 if ( typeof elem.textContent === "string" ) {
nickjillings@1596 1514 return elem.textContent;
nickjillings@1596 1515 } else {
nickjillings@1596 1516 // Traverse its children
nickjillings@1596 1517 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1596 1518 ret += getText( elem );
nickjillings@1596 1519 }
nickjillings@1596 1520 }
nickjillings@1596 1521 } else if ( nodeType === 3 || nodeType === 4 ) {
nickjillings@1596 1522 return elem.nodeValue;
nickjillings@1596 1523 }
nickjillings@1596 1524 // Do not include comment or processing instruction nodes
nickjillings@1596 1525
nickjillings@1596 1526 return ret;
nickjillings@1596 1527 };
nickjillings@1596 1528
nickjillings@1596 1529 Expr = Sizzle.selectors = {
nickjillings@1596 1530
nickjillings@1596 1531 // Can be adjusted by the user
nickjillings@1596 1532 cacheLength: 50,
nickjillings@1596 1533
nickjillings@1596 1534 createPseudo: markFunction,
nickjillings@1596 1535
nickjillings@1596 1536 match: matchExpr,
nickjillings@1596 1537
nickjillings@1596 1538 attrHandle: {},
nickjillings@1596 1539
nickjillings@1596 1540 find: {},
nickjillings@1596 1541
nickjillings@1596 1542 relative: {
nickjillings@1596 1543 ">": { dir: "parentNode", first: true },
nickjillings@1596 1544 " ": { dir: "parentNode" },
nickjillings@1596 1545 "+": { dir: "previousSibling", first: true },
nickjillings@1596 1546 "~": { dir: "previousSibling" }
nickjillings@1596 1547 },
nickjillings@1596 1548
nickjillings@1596 1549 preFilter: {
nickjillings@1596 1550 "ATTR": function( match ) {
nickjillings@1596 1551 match[1] = match[1].replace( runescape, funescape );
nickjillings@1596 1552
nickjillings@1596 1553 // Move the given value to match[3] whether quoted or unquoted
nickjillings@1596 1554 match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nickjillings@1596 1555
nickjillings@1596 1556 if ( match[2] === "~=" ) {
nickjillings@1596 1557 match[3] = " " + match[3] + " ";
nickjillings@1596 1558 }
nickjillings@1596 1559
nickjillings@1596 1560 return match.slice( 0, 4 );
nickjillings@1596 1561 },
nickjillings@1596 1562
nickjillings@1596 1563 "CHILD": function( match ) {
nickjillings@1596 1564 /* matches from matchExpr["CHILD"]
nickjillings@1596 1565 1 type (only|nth|...)
nickjillings@1596 1566 2 what (child|of-type)
nickjillings@1596 1567 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nickjillings@1596 1568 4 xn-component of xn+y argument ([+-]?\d*n|)
nickjillings@1596 1569 5 sign of xn-component
nickjillings@1596 1570 6 x of xn-component
nickjillings@1596 1571 7 sign of y-component
nickjillings@1596 1572 8 y of y-component
nickjillings@1596 1573 */
nickjillings@1596 1574 match[1] = match[1].toLowerCase();
nickjillings@1596 1575
nickjillings@1596 1576 if ( match[1].slice( 0, 3 ) === "nth" ) {
nickjillings@1596 1577 // nth-* requires argument
nickjillings@1596 1578 if ( !match[3] ) {
nickjillings@1596 1579 Sizzle.error( match[0] );
nickjillings@1596 1580 }
nickjillings@1596 1581
nickjillings@1596 1582 // numeric x and y parameters for Expr.filter.CHILD
nickjillings@1596 1583 // remember that false/true cast respectively to 0/1
nickjillings@1596 1584 match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nickjillings@1596 1585 match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nickjillings@1596 1586
nickjillings@1596 1587 // other types prohibit arguments
nickjillings@1596 1588 } else if ( match[3] ) {
nickjillings@1596 1589 Sizzle.error( match[0] );
nickjillings@1596 1590 }
nickjillings@1596 1591
nickjillings@1596 1592 return match;
nickjillings@1596 1593 },
nickjillings@1596 1594
nickjillings@1596 1595 "PSEUDO": function( match ) {
nickjillings@1596 1596 var excess,
nickjillings@1596 1597 unquoted = !match[6] && match[2];
nickjillings@1596 1598
nickjillings@1596 1599 if ( matchExpr["CHILD"].test( match[0] ) ) {
nickjillings@1596 1600 return null;
nickjillings@1596 1601 }
nickjillings@1596 1602
nickjillings@1596 1603 // Accept quoted arguments as-is
nickjillings@1596 1604 if ( match[3] ) {
nickjillings@1596 1605 match[2] = match[4] || match[5] || "";
nickjillings@1596 1606
nickjillings@1596 1607 // Strip excess characters from unquoted arguments
nickjillings@1596 1608 } else if ( unquoted && rpseudo.test( unquoted ) &&
nickjillings@1596 1609 // Get excess from tokenize (recursively)
nickjillings@1596 1610 (excess = tokenize( unquoted, true )) &&
nickjillings@1596 1611 // advance to the next closing parenthesis
nickjillings@1596 1612 (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nickjillings@1596 1613
nickjillings@1596 1614 // excess is a negative index
nickjillings@1596 1615 match[0] = match[0].slice( 0, excess );
nickjillings@1596 1616 match[2] = unquoted.slice( 0, excess );
nickjillings@1596 1617 }
nickjillings@1596 1618
nickjillings@1596 1619 // Return only captures needed by the pseudo filter method (type and argument)
nickjillings@1596 1620 return match.slice( 0, 3 );
nickjillings@1596 1621 }
nickjillings@1596 1622 },
nickjillings@1596 1623
nickjillings@1596 1624 filter: {
nickjillings@1596 1625
nickjillings@1596 1626 "TAG": function( nodeNameSelector ) {
nickjillings@1596 1627 var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nickjillings@1596 1628 return nodeNameSelector === "*" ?
nickjillings@1596 1629 function() { return true; } :
nickjillings@1596 1630 function( elem ) {
nickjillings@1596 1631 return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nickjillings@1596 1632 };
nickjillings@1596 1633 },
nickjillings@1596 1634
nickjillings@1596 1635 "CLASS": function( className ) {
nickjillings@1596 1636 var pattern = classCache[ className + " " ];
nickjillings@1596 1637
nickjillings@1596 1638 return pattern ||
nickjillings@1596 1639 (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nickjillings@1596 1640 classCache( className, function( elem ) {
nickjillings@1596 1641 return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nickjillings@1596 1642 });
nickjillings@1596 1643 },
nickjillings@1596 1644
nickjillings@1596 1645 "ATTR": function( name, operator, check ) {
nickjillings@1596 1646 return function( elem ) {
nickjillings@1596 1647 var result = Sizzle.attr( elem, name );
nickjillings@1596 1648
nickjillings@1596 1649 if ( result == null ) {
nickjillings@1596 1650 return operator === "!=";
nickjillings@1596 1651 }
nickjillings@1596 1652 if ( !operator ) {
nickjillings@1596 1653 return true;
nickjillings@1596 1654 }
nickjillings@1596 1655
nickjillings@1596 1656 result += "";
nickjillings@1596 1657
nickjillings@1596 1658 return operator === "=" ? result === check :
nickjillings@1596 1659 operator === "!=" ? result !== check :
nickjillings@1596 1660 operator === "^=" ? check && result.indexOf( check ) === 0 :
nickjillings@1596 1661 operator === "*=" ? check && result.indexOf( check ) > -1 :
nickjillings@1596 1662 operator === "$=" ? check && result.slice( -check.length ) === check :
nickjillings@1596 1663 operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nickjillings@1596 1664 operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nickjillings@1596 1665 false;
nickjillings@1596 1666 };
nickjillings@1596 1667 },
nickjillings@1596 1668
nickjillings@1596 1669 "CHILD": function( type, what, argument, first, last ) {
nickjillings@1596 1670 var simple = type.slice( 0, 3 ) !== "nth",
nickjillings@1596 1671 forward = type.slice( -4 ) !== "last",
nickjillings@1596 1672 ofType = what === "of-type";
nickjillings@1596 1673
nickjillings@1596 1674 return first === 1 && last === 0 ?
nickjillings@1596 1675
nickjillings@1596 1676 // Shortcut for :nth-*(n)
nickjillings@1596 1677 function( elem ) {
nickjillings@1596 1678 return !!elem.parentNode;
nickjillings@1596 1679 } :
nickjillings@1596 1680
nickjillings@1596 1681 function( elem, context, xml ) {
nickjillings@1596 1682 var cache, outerCache, node, diff, nodeIndex, start,
nickjillings@1596 1683 dir = simple !== forward ? "nextSibling" : "previousSibling",
nickjillings@1596 1684 parent = elem.parentNode,
nickjillings@1596 1685 name = ofType && elem.nodeName.toLowerCase(),
nickjillings@1596 1686 useCache = !xml && !ofType;
nickjillings@1596 1687
nickjillings@1596 1688 if ( parent ) {
nickjillings@1596 1689
nickjillings@1596 1690 // :(first|last|only)-(child|of-type)
nickjillings@1596 1691 if ( simple ) {
nickjillings@1596 1692 while ( dir ) {
nickjillings@1596 1693 node = elem;
nickjillings@1596 1694 while ( (node = node[ dir ]) ) {
nickjillings@1596 1695 if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nickjillings@1596 1696 return false;
nickjillings@1596 1697 }
nickjillings@1596 1698 }
nickjillings@1596 1699 // Reverse direction for :only-* (if we haven't yet done so)
nickjillings@1596 1700 start = dir = type === "only" && !start && "nextSibling";
nickjillings@1596 1701 }
nickjillings@1596 1702 return true;
nickjillings@1596 1703 }
nickjillings@1596 1704
nickjillings@1596 1705 start = [ forward ? parent.firstChild : parent.lastChild ];
nickjillings@1596 1706
nickjillings@1596 1707 // non-xml :nth-child(...) stores cache data on `parent`
nickjillings@1596 1708 if ( forward && useCache ) {
nickjillings@1596 1709 // Seek `elem` from a previously-cached index
nickjillings@1596 1710 outerCache = parent[ expando ] || (parent[ expando ] = {});
nickjillings@1596 1711 cache = outerCache[ type ] || [];
nickjillings@1596 1712 nodeIndex = cache[0] === dirruns && cache[1];
nickjillings@1596 1713 diff = cache[0] === dirruns && cache[2];
nickjillings@1596 1714 node = nodeIndex && parent.childNodes[ nodeIndex ];
nickjillings@1596 1715
nickjillings@1596 1716 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1596 1717
nickjillings@1596 1718 // Fallback to seeking `elem` from the start
nickjillings@1596 1719 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1596 1720
nickjillings@1596 1721 // When found, cache indexes on `parent` and break
nickjillings@1596 1722 if ( node.nodeType === 1 && ++diff && node === elem ) {
nickjillings@1596 1723 outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nickjillings@1596 1724 break;
nickjillings@1596 1725 }
nickjillings@1596 1726 }
nickjillings@1596 1727
nickjillings@1596 1728 // Use previously-cached element index if available
nickjillings@1596 1729 } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nickjillings@1596 1730 diff = cache[1];
nickjillings@1596 1731
nickjillings@1596 1732 // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nickjillings@1596 1733 } else {
nickjillings@1596 1734 // Use the same loop as above to seek `elem` from the start
nickjillings@1596 1735 while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1596 1736 (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1596 1737
nickjillings@1596 1738 if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nickjillings@1596 1739 // Cache the index of each encountered element
nickjillings@1596 1740 if ( useCache ) {
nickjillings@1596 1741 (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nickjillings@1596 1742 }
nickjillings@1596 1743
nickjillings@1596 1744 if ( node === elem ) {
nickjillings@1596 1745 break;
nickjillings@1596 1746 }
nickjillings@1596 1747 }
nickjillings@1596 1748 }
nickjillings@1596 1749 }
nickjillings@1596 1750
nickjillings@1596 1751 // Incorporate the offset, then check against cycle size
nickjillings@1596 1752 diff -= last;
nickjillings@1596 1753 return diff === first || ( diff % first === 0 && diff / first >= 0 );
nickjillings@1596 1754 }
nickjillings@1596 1755 };
nickjillings@1596 1756 },
nickjillings@1596 1757
nickjillings@1596 1758 "PSEUDO": function( pseudo, argument ) {
nickjillings@1596 1759 // pseudo-class names are case-insensitive
nickjillings@1596 1760 // http://www.w3.org/TR/selectors/#pseudo-classes
nickjillings@1596 1761 // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nickjillings@1596 1762 // Remember that setFilters inherits from pseudos
nickjillings@1596 1763 var args,
nickjillings@1596 1764 fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nickjillings@1596 1765 Sizzle.error( "unsupported pseudo: " + pseudo );
nickjillings@1596 1766
nickjillings@1596 1767 // The user may use createPseudo to indicate that
nickjillings@1596 1768 // arguments are needed to create the filter function
nickjillings@1596 1769 // just as Sizzle does
nickjillings@1596 1770 if ( fn[ expando ] ) {
nickjillings@1596 1771 return fn( argument );
nickjillings@1596 1772 }
nickjillings@1596 1773
nickjillings@1596 1774 // But maintain support for old signatures
nickjillings@1596 1775 if ( fn.length > 1 ) {
nickjillings@1596 1776 args = [ pseudo, pseudo, "", argument ];
nickjillings@1596 1777 return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nickjillings@1596 1778 markFunction(function( seed, matches ) {
nickjillings@1596 1779 var idx,
nickjillings@1596 1780 matched = fn( seed, argument ),
nickjillings@1596 1781 i = matched.length;
nickjillings@1596 1782 while ( i-- ) {
nickjillings@1596 1783 idx = indexOf( seed, matched[i] );
nickjillings@1596 1784 seed[ idx ] = !( matches[ idx ] = matched[i] );
nickjillings@1596 1785 }
nickjillings@1596 1786 }) :
nickjillings@1596 1787 function( elem ) {
nickjillings@1596 1788 return fn( elem, 0, args );
nickjillings@1596 1789 };
nickjillings@1596 1790 }
nickjillings@1596 1791
nickjillings@1596 1792 return fn;
nickjillings@1596 1793 }
nickjillings@1596 1794 },
nickjillings@1596 1795
nickjillings@1596 1796 pseudos: {
nickjillings@1596 1797 // Potentially complex pseudos
nickjillings@1596 1798 "not": markFunction(function( selector ) {
nickjillings@1596 1799 // Trim the selector passed to compile
nickjillings@1596 1800 // to avoid treating leading and trailing
nickjillings@1596 1801 // spaces as combinators
nickjillings@1596 1802 var input = [],
nickjillings@1596 1803 results = [],
nickjillings@1596 1804 matcher = compile( selector.replace( rtrim, "$1" ) );
nickjillings@1596 1805
nickjillings@1596 1806 return matcher[ expando ] ?
nickjillings@1596 1807 markFunction(function( seed, matches, context, xml ) {
nickjillings@1596 1808 var elem,
nickjillings@1596 1809 unmatched = matcher( seed, null, xml, [] ),
nickjillings@1596 1810 i = seed.length;
nickjillings@1596 1811
nickjillings@1596 1812 // Match elements unmatched by `matcher`
nickjillings@1596 1813 while ( i-- ) {
nickjillings@1596 1814 if ( (elem = unmatched[i]) ) {
nickjillings@1596 1815 seed[i] = !(matches[i] = elem);
nickjillings@1596 1816 }
nickjillings@1596 1817 }
nickjillings@1596 1818 }) :
nickjillings@1596 1819 function( elem, context, xml ) {
nickjillings@1596 1820 input[0] = elem;
nickjillings@1596 1821 matcher( input, null, xml, results );
nickjillings@1596 1822 // Don't keep the element (issue #299)
nickjillings@1596 1823 input[0] = null;
nickjillings@1596 1824 return !results.pop();
nickjillings@1596 1825 };
nickjillings@1596 1826 }),
nickjillings@1596 1827
nickjillings@1596 1828 "has": markFunction(function( selector ) {
nickjillings@1596 1829 return function( elem ) {
nickjillings@1596 1830 return Sizzle( selector, elem ).length > 0;
nickjillings@1596 1831 };
nickjillings@1596 1832 }),
nickjillings@1596 1833
nickjillings@1596 1834 "contains": markFunction(function( text ) {
nickjillings@1596 1835 text = text.replace( runescape, funescape );
nickjillings@1596 1836 return function( elem ) {
nickjillings@1596 1837 return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nickjillings@1596 1838 };
nickjillings@1596 1839 }),
nickjillings@1596 1840
nickjillings@1596 1841 // "Whether an element is represented by a :lang() selector
nickjillings@1596 1842 // is based solely on the element's language value
nickjillings@1596 1843 // being equal to the identifier C,
nickjillings@1596 1844 // or beginning with the identifier C immediately followed by "-".
nickjillings@1596 1845 // The matching of C against the element's language value is performed case-insensitively.
nickjillings@1596 1846 // The identifier C does not have to be a valid language name."
nickjillings@1596 1847 // http://www.w3.org/TR/selectors/#lang-pseudo
nickjillings@1596 1848 "lang": markFunction( function( lang ) {
nickjillings@1596 1849 // lang value must be a valid identifier
nickjillings@1596 1850 if ( !ridentifier.test(lang || "") ) {
nickjillings@1596 1851 Sizzle.error( "unsupported lang: " + lang );
nickjillings@1596 1852 }
nickjillings@1596 1853 lang = lang.replace( runescape, funescape ).toLowerCase();
nickjillings@1596 1854 return function( elem ) {
nickjillings@1596 1855 var elemLang;
nickjillings@1596 1856 do {
nickjillings@1596 1857 if ( (elemLang = documentIsHTML ?
nickjillings@1596 1858 elem.lang :
nickjillings@1596 1859 elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nickjillings@1596 1860
nickjillings@1596 1861 elemLang = elemLang.toLowerCase();
nickjillings@1596 1862 return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nickjillings@1596 1863 }
nickjillings@1596 1864 } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nickjillings@1596 1865 return false;
nickjillings@1596 1866 };
nickjillings@1596 1867 }),
nickjillings@1596 1868
nickjillings@1596 1869 // Miscellaneous
nickjillings@1596 1870 "target": function( elem ) {
nickjillings@1596 1871 var hash = window.location && window.location.hash;
nickjillings@1596 1872 return hash && hash.slice( 1 ) === elem.id;
nickjillings@1596 1873 },
nickjillings@1596 1874
nickjillings@1596 1875 "root": function( elem ) {
nickjillings@1596 1876 return elem === docElem;
nickjillings@1596 1877 },
nickjillings@1596 1878
nickjillings@1596 1879 "focus": function( elem ) {
nickjillings@1596 1880 return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nickjillings@1596 1881 },
nickjillings@1596 1882
nickjillings@1596 1883 // Boolean properties
nickjillings@1596 1884 "enabled": function( elem ) {
nickjillings@1596 1885 return elem.disabled === false;
nickjillings@1596 1886 },
nickjillings@1596 1887
nickjillings@1596 1888 "disabled": function( elem ) {
nickjillings@1596 1889 return elem.disabled === true;
nickjillings@1596 1890 },
nickjillings@1596 1891
nickjillings@1596 1892 "checked": function( elem ) {
nickjillings@1596 1893 // In CSS3, :checked should return both checked and selected elements
nickjillings@1596 1894 // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1596 1895 var nodeName = elem.nodeName.toLowerCase();
nickjillings@1596 1896 return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nickjillings@1596 1897 },
nickjillings@1596 1898
nickjillings@1596 1899 "selected": function( elem ) {
nickjillings@1596 1900 // Accessing this property makes selected-by-default
nickjillings@1596 1901 // options in Safari work properly
nickjillings@1596 1902 if ( elem.parentNode ) {
nickjillings@1596 1903 elem.parentNode.selectedIndex;
nickjillings@1596 1904 }
nickjillings@1596 1905
nickjillings@1596 1906 return elem.selected === true;
nickjillings@1596 1907 },
nickjillings@1596 1908
nickjillings@1596 1909 // Contents
nickjillings@1596 1910 "empty": function( elem ) {
nickjillings@1596 1911 // http://www.w3.org/TR/selectors/#empty-pseudo
nickjillings@1596 1912 // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nickjillings@1596 1913 // but not by others (comment: 8; processing instruction: 7; etc.)
nickjillings@1596 1914 // nodeType < 6 works because attributes (2) do not appear as children
nickjillings@1596 1915 for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1596 1916 if ( elem.nodeType < 6 ) {
nickjillings@1596 1917 return false;
nickjillings@1596 1918 }
nickjillings@1596 1919 }
nickjillings@1596 1920 return true;
nickjillings@1596 1921 },
nickjillings@1596 1922
nickjillings@1596 1923 "parent": function( elem ) {
nickjillings@1596 1924 return !Expr.pseudos["empty"]( elem );
nickjillings@1596 1925 },
nickjillings@1596 1926
nickjillings@1596 1927 // Element/input types
nickjillings@1596 1928 "header": function( elem ) {
nickjillings@1596 1929 return rheader.test( elem.nodeName );
nickjillings@1596 1930 },
nickjillings@1596 1931
nickjillings@1596 1932 "input": function( elem ) {
nickjillings@1596 1933 return rinputs.test( elem.nodeName );
nickjillings@1596 1934 },
nickjillings@1596 1935
nickjillings@1596 1936 "button": function( elem ) {
nickjillings@1596 1937 var name = elem.nodeName.toLowerCase();
nickjillings@1596 1938 return name === "input" && elem.type === "button" || name === "button";
nickjillings@1596 1939 },
nickjillings@1596 1940
nickjillings@1596 1941 "text": function( elem ) {
nickjillings@1596 1942 var attr;
nickjillings@1596 1943 return elem.nodeName.toLowerCase() === "input" &&
nickjillings@1596 1944 elem.type === "text" &&
nickjillings@1596 1945
nickjillings@1596 1946 // Support: IE<8
nickjillings@1596 1947 // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nickjillings@1596 1948 ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nickjillings@1596 1949 },
nickjillings@1596 1950
nickjillings@1596 1951 // Position-in-collection
nickjillings@1596 1952 "first": createPositionalPseudo(function() {
nickjillings@1596 1953 return [ 0 ];
nickjillings@1596 1954 }),
nickjillings@1596 1955
nickjillings@1596 1956 "last": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1596 1957 return [ length - 1 ];
nickjillings@1596 1958 }),
nickjillings@1596 1959
nickjillings@1596 1960 "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1596 1961 return [ argument < 0 ? argument + length : argument ];
nickjillings@1596 1962 }),
nickjillings@1596 1963
nickjillings@1596 1964 "even": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1596 1965 var i = 0;
nickjillings@1596 1966 for ( ; i < length; i += 2 ) {
nickjillings@1596 1967 matchIndexes.push( i );
nickjillings@1596 1968 }
nickjillings@1596 1969 return matchIndexes;
nickjillings@1596 1970 }),
nickjillings@1596 1971
nickjillings@1596 1972 "odd": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1596 1973 var i = 1;
nickjillings@1596 1974 for ( ; i < length; i += 2 ) {
nickjillings@1596 1975 matchIndexes.push( i );
nickjillings@1596 1976 }
nickjillings@1596 1977 return matchIndexes;
nickjillings@1596 1978 }),
nickjillings@1596 1979
nickjillings@1596 1980 "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1596 1981 var i = argument < 0 ? argument + length : argument;
nickjillings@1596 1982 for ( ; --i >= 0; ) {
nickjillings@1596 1983 matchIndexes.push( i );
nickjillings@1596 1984 }
nickjillings@1596 1985 return matchIndexes;
nickjillings@1596 1986 }),
nickjillings@1596 1987
nickjillings@1596 1988 "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1596 1989 var i = argument < 0 ? argument + length : argument;
nickjillings@1596 1990 for ( ; ++i < length; ) {
nickjillings@1596 1991 matchIndexes.push( i );
nickjillings@1596 1992 }
nickjillings@1596 1993 return matchIndexes;
nickjillings@1596 1994 })
nickjillings@1596 1995 }
nickjillings@1596 1996 };
nickjillings@1596 1997
nickjillings@1596 1998 Expr.pseudos["nth"] = Expr.pseudos["eq"];
nickjillings@1596 1999
nickjillings@1596 2000 // Add button/input type pseudos
nickjillings@1596 2001 for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nickjillings@1596 2002 Expr.pseudos[ i ] = createInputPseudo( i );
nickjillings@1596 2003 }
nickjillings@1596 2004 for ( i in { submit: true, reset: true } ) {
nickjillings@1596 2005 Expr.pseudos[ i ] = createButtonPseudo( i );
nickjillings@1596 2006 }
nickjillings@1596 2007
nickjillings@1596 2008 // Easy API for creating new setFilters
nickjillings@1596 2009 function setFilters() {}
nickjillings@1596 2010 setFilters.prototype = Expr.filters = Expr.pseudos;
nickjillings@1596 2011 Expr.setFilters = new setFilters();
nickjillings@1596 2012
nickjillings@1596 2013 tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nickjillings@1596 2014 var matched, match, tokens, type,
nickjillings@1596 2015 soFar, groups, preFilters,
nickjillings@1596 2016 cached = tokenCache[ selector + " " ];
nickjillings@1596 2017
nickjillings@1596 2018 if ( cached ) {
nickjillings@1596 2019 return parseOnly ? 0 : cached.slice( 0 );
nickjillings@1596 2020 }
nickjillings@1596 2021
nickjillings@1596 2022 soFar = selector;
nickjillings@1596 2023 groups = [];
nickjillings@1596 2024 preFilters = Expr.preFilter;
nickjillings@1596 2025
nickjillings@1596 2026 while ( soFar ) {
nickjillings@1596 2027
nickjillings@1596 2028 // Comma and first run
nickjillings@1596 2029 if ( !matched || (match = rcomma.exec( soFar )) ) {
nickjillings@1596 2030 if ( match ) {
nickjillings@1596 2031 // Don't consume trailing commas as valid
nickjillings@1596 2032 soFar = soFar.slice( match[0].length ) || soFar;
nickjillings@1596 2033 }
nickjillings@1596 2034 groups.push( (tokens = []) );
nickjillings@1596 2035 }
nickjillings@1596 2036
nickjillings@1596 2037 matched = false;
nickjillings@1596 2038
nickjillings@1596 2039 // Combinators
nickjillings@1596 2040 if ( (match = rcombinators.exec( soFar )) ) {
nickjillings@1596 2041 matched = match.shift();
nickjillings@1596 2042 tokens.push({
nickjillings@1596 2043 value: matched,
nickjillings@1596 2044 // Cast descendant combinators to space
nickjillings@1596 2045 type: match[0].replace( rtrim, " " )
nickjillings@1596 2046 });
nickjillings@1596 2047 soFar = soFar.slice( matched.length );
nickjillings@1596 2048 }
nickjillings@1596 2049
nickjillings@1596 2050 // Filters
nickjillings@1596 2051 for ( type in Expr.filter ) {
nickjillings@1596 2052 if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nickjillings@1596 2053 (match = preFilters[ type ]( match ))) ) {
nickjillings@1596 2054 matched = match.shift();
nickjillings@1596 2055 tokens.push({
nickjillings@1596 2056 value: matched,
nickjillings@1596 2057 type: type,
nickjillings@1596 2058 matches: match
nickjillings@1596 2059 });
nickjillings@1596 2060 soFar = soFar.slice( matched.length );
nickjillings@1596 2061 }
nickjillings@1596 2062 }
nickjillings@1596 2063
nickjillings@1596 2064 if ( !matched ) {
nickjillings@1596 2065 break;
nickjillings@1596 2066 }
nickjillings@1596 2067 }
nickjillings@1596 2068
nickjillings@1596 2069 // Return the length of the invalid excess
nickjillings@1596 2070 // if we're just parsing
nickjillings@1596 2071 // Otherwise, throw an error or return tokens
nickjillings@1596 2072 return parseOnly ?
nickjillings@1596 2073 soFar.length :
nickjillings@1596 2074 soFar ?
nickjillings@1596 2075 Sizzle.error( selector ) :
nickjillings@1596 2076 // Cache the tokens
nickjillings@1596 2077 tokenCache( selector, groups ).slice( 0 );
nickjillings@1596 2078 };
nickjillings@1596 2079
nickjillings@1596 2080 function toSelector( tokens ) {
nickjillings@1596 2081 var i = 0,
nickjillings@1596 2082 len = tokens.length,
nickjillings@1596 2083 selector = "";
nickjillings@1596 2084 for ( ; i < len; i++ ) {
nickjillings@1596 2085 selector += tokens[i].value;
nickjillings@1596 2086 }
nickjillings@1596 2087 return selector;
nickjillings@1596 2088 }
nickjillings@1596 2089
nickjillings@1596 2090 function addCombinator( matcher, combinator, base ) {
nickjillings@1596 2091 var dir = combinator.dir,
nickjillings@1596 2092 checkNonElements = base && dir === "parentNode",
nickjillings@1596 2093 doneName = done++;
nickjillings@1596 2094
nickjillings@1596 2095 return combinator.first ?
nickjillings@1596 2096 // Check against closest ancestor/preceding element
nickjillings@1596 2097 function( elem, context, xml ) {
nickjillings@1596 2098 while ( (elem = elem[ dir ]) ) {
nickjillings@1596 2099 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1596 2100 return matcher( elem, context, xml );
nickjillings@1596 2101 }
nickjillings@1596 2102 }
nickjillings@1596 2103 } :
nickjillings@1596 2104
nickjillings@1596 2105 // Check against all ancestor/preceding elements
nickjillings@1596 2106 function( elem, context, xml ) {
nickjillings@1596 2107 var oldCache, outerCache,
nickjillings@1596 2108 newCache = [ dirruns, doneName ];
nickjillings@1596 2109
nickjillings@1596 2110 // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nickjillings@1596 2111 if ( xml ) {
nickjillings@1596 2112 while ( (elem = elem[ dir ]) ) {
nickjillings@1596 2113 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1596 2114 if ( matcher( elem, context, xml ) ) {
nickjillings@1596 2115 return true;
nickjillings@1596 2116 }
nickjillings@1596 2117 }
nickjillings@1596 2118 }
nickjillings@1596 2119 } else {
nickjillings@1596 2120 while ( (elem = elem[ dir ]) ) {
nickjillings@1596 2121 if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1596 2122 outerCache = elem[ expando ] || (elem[ expando ] = {});
nickjillings@1596 2123 if ( (oldCache = outerCache[ dir ]) &&
nickjillings@1596 2124 oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nickjillings@1596 2125
nickjillings@1596 2126 // Assign to newCache so results back-propagate to previous elements
nickjillings@1596 2127 return (newCache[ 2 ] = oldCache[ 2 ]);
nickjillings@1596 2128 } else {
nickjillings@1596 2129 // Reuse newcache so results back-propagate to previous elements
nickjillings@1596 2130 outerCache[ dir ] = newCache;
nickjillings@1596 2131
nickjillings@1596 2132 // A match means we're done; a fail means we have to keep checking
nickjillings@1596 2133 if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nickjillings@1596 2134 return true;
nickjillings@1596 2135 }
nickjillings@1596 2136 }
nickjillings@1596 2137 }
nickjillings@1596 2138 }
nickjillings@1596 2139 }
nickjillings@1596 2140 };
nickjillings@1596 2141 }
nickjillings@1596 2142
nickjillings@1596 2143 function elementMatcher( matchers ) {
nickjillings@1596 2144 return matchers.length > 1 ?
nickjillings@1596 2145 function( elem, context, xml ) {
nickjillings@1596 2146 var i = matchers.length;
nickjillings@1596 2147 while ( i-- ) {
nickjillings@1596 2148 if ( !matchers[i]( elem, context, xml ) ) {
nickjillings@1596 2149 return false;
nickjillings@1596 2150 }
nickjillings@1596 2151 }
nickjillings@1596 2152 return true;
nickjillings@1596 2153 } :
nickjillings@1596 2154 matchers[0];
nickjillings@1596 2155 }
nickjillings@1596 2156
nickjillings@1596 2157 function multipleContexts( selector, contexts, results ) {
nickjillings@1596 2158 var i = 0,
nickjillings@1596 2159 len = contexts.length;
nickjillings@1596 2160 for ( ; i < len; i++ ) {
nickjillings@1596 2161 Sizzle( selector, contexts[i], results );
nickjillings@1596 2162 }
nickjillings@1596 2163 return results;
nickjillings@1596 2164 }
nickjillings@1596 2165
nickjillings@1596 2166 function condense( unmatched, map, filter, context, xml ) {
nickjillings@1596 2167 var elem,
nickjillings@1596 2168 newUnmatched = [],
nickjillings@1596 2169 i = 0,
nickjillings@1596 2170 len = unmatched.length,
nickjillings@1596 2171 mapped = map != null;
nickjillings@1596 2172
nickjillings@1596 2173 for ( ; i < len; i++ ) {
nickjillings@1596 2174 if ( (elem = unmatched[i]) ) {
nickjillings@1596 2175 if ( !filter || filter( elem, context, xml ) ) {
nickjillings@1596 2176 newUnmatched.push( elem );
nickjillings@1596 2177 if ( mapped ) {
nickjillings@1596 2178 map.push( i );
nickjillings@1596 2179 }
nickjillings@1596 2180 }
nickjillings@1596 2181 }
nickjillings@1596 2182 }
nickjillings@1596 2183
nickjillings@1596 2184 return newUnmatched;
nickjillings@1596 2185 }
nickjillings@1596 2186
nickjillings@1596 2187 function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nickjillings@1596 2188 if ( postFilter && !postFilter[ expando ] ) {
nickjillings@1596 2189 postFilter = setMatcher( postFilter );
nickjillings@1596 2190 }
nickjillings@1596 2191 if ( postFinder && !postFinder[ expando ] ) {
nickjillings@1596 2192 postFinder = setMatcher( postFinder, postSelector );
nickjillings@1596 2193 }
nickjillings@1596 2194 return markFunction(function( seed, results, context, xml ) {
nickjillings@1596 2195 var temp, i, elem,
nickjillings@1596 2196 preMap = [],
nickjillings@1596 2197 postMap = [],
nickjillings@1596 2198 preexisting = results.length,
nickjillings@1596 2199
nickjillings@1596 2200 // Get initial elements from seed or context
nickjillings@1596 2201 elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nickjillings@1596 2202
nickjillings@1596 2203 // Prefilter to get matcher input, preserving a map for seed-results synchronization
nickjillings@1596 2204 matcherIn = preFilter && ( seed || !selector ) ?
nickjillings@1596 2205 condense( elems, preMap, preFilter, context, xml ) :
nickjillings@1596 2206 elems,
nickjillings@1596 2207
nickjillings@1596 2208 matcherOut = matcher ?
nickjillings@1596 2209 // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nickjillings@1596 2210 postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nickjillings@1596 2211
nickjillings@1596 2212 // ...intermediate processing is necessary
nickjillings@1596 2213 [] :
nickjillings@1596 2214
nickjillings@1596 2215 // ...otherwise use results directly
nickjillings@1596 2216 results :
nickjillings@1596 2217 matcherIn;
nickjillings@1596 2218
nickjillings@1596 2219 // Find primary matches
nickjillings@1596 2220 if ( matcher ) {
nickjillings@1596 2221 matcher( matcherIn, matcherOut, context, xml );
nickjillings@1596 2222 }
nickjillings@1596 2223
nickjillings@1596 2224 // Apply postFilter
nickjillings@1596 2225 if ( postFilter ) {
nickjillings@1596 2226 temp = condense( matcherOut, postMap );
nickjillings@1596 2227 postFilter( temp, [], context, xml );
nickjillings@1596 2228
nickjillings@1596 2229 // Un-match failing elements by moving them back to matcherIn
nickjillings@1596 2230 i = temp.length;
nickjillings@1596 2231 while ( i-- ) {
nickjillings@1596 2232 if ( (elem = temp[i]) ) {
nickjillings@1596 2233 matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nickjillings@1596 2234 }
nickjillings@1596 2235 }
nickjillings@1596 2236 }
nickjillings@1596 2237
nickjillings@1596 2238 if ( seed ) {
nickjillings@1596 2239 if ( postFinder || preFilter ) {
nickjillings@1596 2240 if ( postFinder ) {
nickjillings@1596 2241 // Get the final matcherOut by condensing this intermediate into postFinder contexts
nickjillings@1596 2242 temp = [];
nickjillings@1596 2243 i = matcherOut.length;
nickjillings@1596 2244 while ( i-- ) {
nickjillings@1596 2245 if ( (elem = matcherOut[i]) ) {
nickjillings@1596 2246 // Restore matcherIn since elem is not yet a final match
nickjillings@1596 2247 temp.push( (matcherIn[i] = elem) );
nickjillings@1596 2248 }
nickjillings@1596 2249 }
nickjillings@1596 2250 postFinder( null, (matcherOut = []), temp, xml );
nickjillings@1596 2251 }
nickjillings@1596 2252
nickjillings@1596 2253 // Move matched elements from seed to results to keep them synchronized
nickjillings@1596 2254 i = matcherOut.length;
nickjillings@1596 2255 while ( i-- ) {
nickjillings@1596 2256 if ( (elem = matcherOut[i]) &&
nickjillings@1596 2257 (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nickjillings@1596 2258
nickjillings@1596 2259 seed[temp] = !(results[temp] = elem);
nickjillings@1596 2260 }
nickjillings@1596 2261 }
nickjillings@1596 2262 }
nickjillings@1596 2263
nickjillings@1596 2264 // Add elements to results, through postFinder if defined
nickjillings@1596 2265 } else {
nickjillings@1596 2266 matcherOut = condense(
nickjillings@1596 2267 matcherOut === results ?
nickjillings@1596 2268 matcherOut.splice( preexisting, matcherOut.length ) :
nickjillings@1596 2269 matcherOut
nickjillings@1596 2270 );
nickjillings@1596 2271 if ( postFinder ) {
nickjillings@1596 2272 postFinder( null, results, matcherOut, xml );
nickjillings@1596 2273 } else {
nickjillings@1596 2274 push.apply( results, matcherOut );
nickjillings@1596 2275 }
nickjillings@1596 2276 }
nickjillings@1596 2277 });
nickjillings@1596 2278 }
nickjillings@1596 2279
nickjillings@1596 2280 function matcherFromTokens( tokens ) {
nickjillings@1596 2281 var checkContext, matcher, j,
nickjillings@1596 2282 len = tokens.length,
nickjillings@1596 2283 leadingRelative = Expr.relative[ tokens[0].type ],
nickjillings@1596 2284 implicitRelative = leadingRelative || Expr.relative[" "],
nickjillings@1596 2285 i = leadingRelative ? 1 : 0,
nickjillings@1596 2286
nickjillings@1596 2287 // The foundational matcher ensures that elements are reachable from top-level context(s)
nickjillings@1596 2288 matchContext = addCombinator( function( elem ) {
nickjillings@1596 2289 return elem === checkContext;
nickjillings@1596 2290 }, implicitRelative, true ),
nickjillings@1596 2291 matchAnyContext = addCombinator( function( elem ) {
nickjillings@1596 2292 return indexOf( checkContext, elem ) > -1;
nickjillings@1596 2293 }, implicitRelative, true ),
nickjillings@1596 2294 matchers = [ function( elem, context, xml ) {
nickjillings@1596 2295 var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nickjillings@1596 2296 (checkContext = context).nodeType ?
nickjillings@1596 2297 matchContext( elem, context, xml ) :
nickjillings@1596 2298 matchAnyContext( elem, context, xml ) );
nickjillings@1596 2299 // Avoid hanging onto element (issue #299)
nickjillings@1596 2300 checkContext = null;
nickjillings@1596 2301 return ret;
nickjillings@1596 2302 } ];
nickjillings@1596 2303
nickjillings@1596 2304 for ( ; i < len; i++ ) {
nickjillings@1596 2305 if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nickjillings@1596 2306 matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nickjillings@1596 2307 } else {
nickjillings@1596 2308 matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nickjillings@1596 2309
nickjillings@1596 2310 // Return special upon seeing a positional matcher
nickjillings@1596 2311 if ( matcher[ expando ] ) {
nickjillings@1596 2312 // Find the next relative operator (if any) for proper handling
nickjillings@1596 2313 j = ++i;
nickjillings@1596 2314 for ( ; j < len; j++ ) {
nickjillings@1596 2315 if ( Expr.relative[ tokens[j].type ] ) {
nickjillings@1596 2316 break;
nickjillings@1596 2317 }
nickjillings@1596 2318 }
nickjillings@1596 2319 return setMatcher(
nickjillings@1596 2320 i > 1 && elementMatcher( matchers ),
nickjillings@1596 2321 i > 1 && toSelector(
nickjillings@1596 2322 // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nickjillings@1596 2323 tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nickjillings@1596 2324 ).replace( rtrim, "$1" ),
nickjillings@1596 2325 matcher,
nickjillings@1596 2326 i < j && matcherFromTokens( tokens.slice( i, j ) ),
nickjillings@1596 2327 j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nickjillings@1596 2328 j < len && toSelector( tokens )
nickjillings@1596 2329 );
nickjillings@1596 2330 }
nickjillings@1596 2331 matchers.push( matcher );
nickjillings@1596 2332 }
nickjillings@1596 2333 }
nickjillings@1596 2334
nickjillings@1596 2335 return elementMatcher( matchers );
nickjillings@1596 2336 }
nickjillings@1596 2337
nickjillings@1596 2338 function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nickjillings@1596 2339 var bySet = setMatchers.length > 0,
nickjillings@1596 2340 byElement = elementMatchers.length > 0,
nickjillings@1596 2341 superMatcher = function( seed, context, xml, results, outermost ) {
nickjillings@1596 2342 var elem, j, matcher,
nickjillings@1596 2343 matchedCount = 0,
nickjillings@1596 2344 i = "0",
nickjillings@1596 2345 unmatched = seed && [],
nickjillings@1596 2346 setMatched = [],
nickjillings@1596 2347 contextBackup = outermostContext,
nickjillings@1596 2348 // We must always have either seed elements or outermost context
nickjillings@1596 2349 elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nickjillings@1596 2350 // Use integer dirruns iff this is the outermost matcher
nickjillings@1596 2351 dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nickjillings@1596 2352 len = elems.length;
nickjillings@1596 2353
nickjillings@1596 2354 if ( outermost ) {
nickjillings@1596 2355 outermostContext = context !== document && context;
nickjillings@1596 2356 }
nickjillings@1596 2357
nickjillings@1596 2358 // Add elements passing elementMatchers directly to results
nickjillings@1596 2359 // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nickjillings@1596 2360 // Support: IE<9, Safari
nickjillings@1596 2361 // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
nickjillings@1596 2362 for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nickjillings@1596 2363 if ( byElement && elem ) {
nickjillings@1596 2364 j = 0;
nickjillings@1596 2365 while ( (matcher = elementMatchers[j++]) ) {
nickjillings@1596 2366 if ( matcher( elem, context, xml ) ) {
nickjillings@1596 2367 results.push( elem );
nickjillings@1596 2368 break;
nickjillings@1596 2369 }
nickjillings@1596 2370 }
nickjillings@1596 2371 if ( outermost ) {
nickjillings@1596 2372 dirruns = dirrunsUnique;
nickjillings@1596 2373 }
nickjillings@1596 2374 }
nickjillings@1596 2375
nickjillings@1596 2376 // Track unmatched elements for set filters
nickjillings@1596 2377 if ( bySet ) {
nickjillings@1596 2378 // They will have gone through all possible matchers
nickjillings@1596 2379 if ( (elem = !matcher && elem) ) {
nickjillings@1596 2380 matchedCount--;
nickjillings@1596 2381 }
nickjillings@1596 2382
nickjillings@1596 2383 // Lengthen the array for every element, matched or not
nickjillings@1596 2384 if ( seed ) {
nickjillings@1596 2385 unmatched.push( elem );
nickjillings@1596 2386 }
nickjillings@1596 2387 }
nickjillings@1596 2388 }
nickjillings@1596 2389
nickjillings@1596 2390 // Apply set filters to unmatched elements
nickjillings@1596 2391 matchedCount += i;
nickjillings@1596 2392 if ( bySet && i !== matchedCount ) {
nickjillings@1596 2393 j = 0;
nickjillings@1596 2394 while ( (matcher = setMatchers[j++]) ) {
nickjillings@1596 2395 matcher( unmatched, setMatched, context, xml );
nickjillings@1596 2396 }
nickjillings@1596 2397
nickjillings@1596 2398 if ( seed ) {
nickjillings@1596 2399 // Reintegrate element matches to eliminate the need for sorting
nickjillings@1596 2400 if ( matchedCount > 0 ) {
nickjillings@1596 2401 while ( i-- ) {
nickjillings@1596 2402 if ( !(unmatched[i] || setMatched[i]) ) {
nickjillings@1596 2403 setMatched[i] = pop.call( results );
nickjillings@1596 2404 }
nickjillings@1596 2405 }
nickjillings@1596 2406 }
nickjillings@1596 2407
nickjillings@1596 2408 // Discard index placeholder values to get only actual matches
nickjillings@1596 2409 setMatched = condense( setMatched );
nickjillings@1596 2410 }
nickjillings@1596 2411
nickjillings@1596 2412 // Add matches to results
nickjillings@1596 2413 push.apply( results, setMatched );
nickjillings@1596 2414
nickjillings@1596 2415 // Seedless set matches succeeding multiple successful matchers stipulate sorting
nickjillings@1596 2416 if ( outermost && !seed && setMatched.length > 0 &&
nickjillings@1596 2417 ( matchedCount + setMatchers.length ) > 1 ) {
nickjillings@1596 2418
nickjillings@1596 2419 Sizzle.uniqueSort( results );
nickjillings@1596 2420 }
nickjillings@1596 2421 }
nickjillings@1596 2422
nickjillings@1596 2423 // Override manipulation of globals by nested matchers
nickjillings@1596 2424 if ( outermost ) {
nickjillings@1596 2425 dirruns = dirrunsUnique;
nickjillings@1596 2426 outermostContext = contextBackup;
nickjillings@1596 2427 }
nickjillings@1596 2428
nickjillings@1596 2429 return unmatched;
nickjillings@1596 2430 };
nickjillings@1596 2431
nickjillings@1596 2432 return bySet ?
nickjillings@1596 2433 markFunction( superMatcher ) :
nickjillings@1596 2434 superMatcher;
nickjillings@1596 2435 }
nickjillings@1596 2436
nickjillings@1596 2437 compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nickjillings@1596 2438 var i,
nickjillings@1596 2439 setMatchers = [],
nickjillings@1596 2440 elementMatchers = [],
nickjillings@1596 2441 cached = compilerCache[ selector + " " ];
nickjillings@1596 2442
nickjillings@1596 2443 if ( !cached ) {
nickjillings@1596 2444 // Generate a function of recursive functions that can be used to check each element
nickjillings@1596 2445 if ( !match ) {
nickjillings@1596 2446 match = tokenize( selector );
nickjillings@1596 2447 }
nickjillings@1596 2448 i = match.length;
nickjillings@1596 2449 while ( i-- ) {
nickjillings@1596 2450 cached = matcherFromTokens( match[i] );
nickjillings@1596 2451 if ( cached[ expando ] ) {
nickjillings@1596 2452 setMatchers.push( cached );
nickjillings@1596 2453 } else {
nickjillings@1596 2454 elementMatchers.push( cached );
nickjillings@1596 2455 }
nickjillings@1596 2456 }
nickjillings@1596 2457
nickjillings@1596 2458 // Cache the compiled function
nickjillings@1596 2459 cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nickjillings@1596 2460
nickjillings@1596 2461 // Save selector and tokenization
nickjillings@1596 2462 cached.selector = selector;
nickjillings@1596 2463 }
nickjillings@1596 2464 return cached;
nickjillings@1596 2465 };
nickjillings@1596 2466
nickjillings@1596 2467 /**
nickjillings@1596 2468 * A low-level selection function that works with Sizzle's compiled
nickjillings@1596 2469 * selector functions
nickjillings@1596 2470 * @param {String|Function} selector A selector or a pre-compiled
nickjillings@1596 2471 * selector function built with Sizzle.compile
nickjillings@1596 2472 * @param {Element} context
nickjillings@1596 2473 * @param {Array} [results]
nickjillings@1596 2474 * @param {Array} [seed] A set of elements to match against
nickjillings@1596 2475 */
nickjillings@1596 2476 select = Sizzle.select = function( selector, context, results, seed ) {
nickjillings@1596 2477 var i, tokens, token, type, find,
nickjillings@1596 2478 compiled = typeof selector === "function" && selector,
nickjillings@1596 2479 match = !seed && tokenize( (selector = compiled.selector || selector) );
nickjillings@1596 2480
nickjillings@1596 2481 results = results || [];
nickjillings@1596 2482
nickjillings@1596 2483 // Try to minimize operations if there is no seed and only one group
nickjillings@1596 2484 if ( match.length === 1 ) {
nickjillings@1596 2485
nickjillings@1596 2486 // Take a shortcut and set the context if the root selector is an ID
nickjillings@1596 2487 tokens = match[0] = match[0].slice( 0 );
nickjillings@1596 2488 if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nickjillings@1596 2489 support.getById && context.nodeType === 9 && documentIsHTML &&
nickjillings@1596 2490 Expr.relative[ tokens[1].type ] ) {
nickjillings@1596 2491
nickjillings@1596 2492 context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nickjillings@1596 2493 if ( !context ) {
nickjillings@1596 2494 return results;
nickjillings@1596 2495
nickjillings@1596 2496 // Precompiled matchers will still verify ancestry, so step up a level
nickjillings@1596 2497 } else if ( compiled ) {
nickjillings@1596 2498 context = context.parentNode;
nickjillings@1596 2499 }
nickjillings@1596 2500
nickjillings@1596 2501 selector = selector.slice( tokens.shift().value.length );
nickjillings@1596 2502 }
nickjillings@1596 2503
nickjillings@1596 2504 // Fetch a seed set for right-to-left matching
nickjillings@1596 2505 i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nickjillings@1596 2506 while ( i-- ) {
nickjillings@1596 2507 token = tokens[i];
nickjillings@1596 2508
nickjillings@1596 2509 // Abort if we hit a combinator
nickjillings@1596 2510 if ( Expr.relative[ (type = token.type) ] ) {
nickjillings@1596 2511 break;
nickjillings@1596 2512 }
nickjillings@1596 2513 if ( (find = Expr.find[ type ]) ) {
nickjillings@1596 2514 // Search, expanding context for leading sibling combinators
nickjillings@1596 2515 if ( (seed = find(
nickjillings@1596 2516 token.matches[0].replace( runescape, funescape ),
nickjillings@1596 2517 rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nickjillings@1596 2518 )) ) {
nickjillings@1596 2519
nickjillings@1596 2520 // If seed is empty or no tokens remain, we can return early
nickjillings@1596 2521 tokens.splice( i, 1 );
nickjillings@1596 2522 selector = seed.length && toSelector( tokens );
nickjillings@1596 2523 if ( !selector ) {
nickjillings@1596 2524 push.apply( results, seed );
nickjillings@1596 2525 return results;
nickjillings@1596 2526 }
nickjillings@1596 2527
nickjillings@1596 2528 break;
nickjillings@1596 2529 }
nickjillings@1596 2530 }
nickjillings@1596 2531 }
nickjillings@1596 2532 }
nickjillings@1596 2533
nickjillings@1596 2534 // Compile and execute a filtering function if one is not provided
nickjillings@1596 2535 // Provide `match` to avoid retokenization if we modified the selector above
nickjillings@1596 2536 ( compiled || compile( selector, match ) )(
nickjillings@1596 2537 seed,
nickjillings@1596 2538 context,
nickjillings@1596 2539 !documentIsHTML,
nickjillings@1596 2540 results,
nickjillings@1596 2541 rsibling.test( selector ) && testContext( context.parentNode ) || context
nickjillings@1596 2542 );
nickjillings@1596 2543 return results;
nickjillings@1596 2544 };
nickjillings@1596 2545
nickjillings@1596 2546 // One-time assignments
nickjillings@1596 2547
nickjillings@1596 2548 // Sort stability
nickjillings@1596 2549 support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nickjillings@1596 2550
nickjillings@1596 2551 // Support: Chrome 14-35+
nickjillings@1596 2552 // Always assume duplicates if they aren't passed to the comparison function
nickjillings@1596 2553 support.detectDuplicates = !!hasDuplicate;
nickjillings@1596 2554
nickjillings@1596 2555 // Initialize against the default document
nickjillings@1596 2556 setDocument();
nickjillings@1596 2557
nickjillings@1596 2558 // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nickjillings@1596 2559 // Detached nodes confoundingly follow *each other*
nickjillings@1596 2560 support.sortDetached = assert(function( div1 ) {
nickjillings@1596 2561 // Should return 1, but returns 4 (following)
nickjillings@1596 2562 return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nickjillings@1596 2563 });
nickjillings@1596 2564
nickjillings@1596 2565 // Support: IE<8
nickjillings@1596 2566 // Prevent attribute/property "interpolation"
nickjillings@1596 2567 // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nickjillings@1596 2568 if ( !assert(function( div ) {
nickjillings@1596 2569 div.innerHTML = "<a href='#'></a>";
nickjillings@1596 2570 return div.firstChild.getAttribute("href") === "#" ;
nickjillings@1596 2571 }) ) {
nickjillings@1596 2572 addHandle( "type|href|height|width", function( elem, name, isXML ) {
nickjillings@1596 2573 if ( !isXML ) {
nickjillings@1596 2574 return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nickjillings@1596 2575 }
nickjillings@1596 2576 });
nickjillings@1596 2577 }
nickjillings@1596 2578
nickjillings@1596 2579 // Support: IE<9
nickjillings@1596 2580 // Use defaultValue in place of getAttribute("value")
nickjillings@1596 2581 if ( !support.attributes || !assert(function( div ) {
nickjillings@1596 2582 div.innerHTML = "<input/>";
nickjillings@1596 2583 div.firstChild.setAttribute( "value", "" );
nickjillings@1596 2584 return div.firstChild.getAttribute( "value" ) === "";
nickjillings@1596 2585 }) ) {
nickjillings@1596 2586 addHandle( "value", function( elem, name, isXML ) {
nickjillings@1596 2587 if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nickjillings@1596 2588 return elem.defaultValue;
nickjillings@1596 2589 }
nickjillings@1596 2590 });
nickjillings@1596 2591 }
nickjillings@1596 2592
nickjillings@1596 2593 // Support: IE<9
nickjillings@1596 2594 // Use getAttributeNode to fetch booleans when getAttribute lies
nickjillings@1596 2595 if ( !assert(function( div ) {
nickjillings@1596 2596 return div.getAttribute("disabled") == null;
nickjillings@1596 2597 }) ) {
nickjillings@1596 2598 addHandle( booleans, function( elem, name, isXML ) {
nickjillings@1596 2599 var val;
nickjillings@1596 2600 if ( !isXML ) {
nickjillings@1596 2601 return elem[ name ] === true ? name.toLowerCase() :
nickjillings@1596 2602 (val = elem.getAttributeNode( name )) && val.specified ?
nickjillings@1596 2603 val.value :
nickjillings@1596 2604 null;
nickjillings@1596 2605 }
nickjillings@1596 2606 });
nickjillings@1596 2607 }
nickjillings@1596 2608
nickjillings@1596 2609 return Sizzle;
nickjillings@1596 2610
nickjillings@1596 2611 })( window );
nickjillings@1596 2612
nickjillings@1596 2613
nickjillings@1596 2614
nickjillings@1596 2615 jQuery.find = Sizzle;
nickjillings@1596 2616 jQuery.expr = Sizzle.selectors;
nickjillings@1596 2617 jQuery.expr[":"] = jQuery.expr.pseudos;
nickjillings@1596 2618 jQuery.unique = Sizzle.uniqueSort;
nickjillings@1596 2619 jQuery.text = Sizzle.getText;
nickjillings@1596 2620 jQuery.isXMLDoc = Sizzle.isXML;
nickjillings@1596 2621 jQuery.contains = Sizzle.contains;
nickjillings@1596 2622
nickjillings@1596 2623
nickjillings@1596 2624
nickjillings@1596 2625 var rneedsContext = jQuery.expr.match.needsContext;
nickjillings@1596 2626
nickjillings@1596 2627 var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nickjillings@1596 2628
nickjillings@1596 2629
nickjillings@1596 2630
nickjillings@1596 2631 var risSimple = /^.[^:#\[\.,]*$/;
nickjillings@1596 2632
nickjillings@1596 2633 // Implement the identical functionality for filter and not
nickjillings@1596 2634 function winnow( elements, qualifier, not ) {
nickjillings@1596 2635 if ( jQuery.isFunction( qualifier ) ) {
nickjillings@1596 2636 return jQuery.grep( elements, function( elem, i ) {
nickjillings@1596 2637 /* jshint -W018 */
nickjillings@1596 2638 return !!qualifier.call( elem, i, elem ) !== not;
nickjillings@1596 2639 });
nickjillings@1596 2640
nickjillings@1596 2641 }
nickjillings@1596 2642
nickjillings@1596 2643 if ( qualifier.nodeType ) {
nickjillings@1596 2644 return jQuery.grep( elements, function( elem ) {
nickjillings@1596 2645 return ( elem === qualifier ) !== not;
nickjillings@1596 2646 });
nickjillings@1596 2647
nickjillings@1596 2648 }
nickjillings@1596 2649
nickjillings@1596 2650 if ( typeof qualifier === "string" ) {
nickjillings@1596 2651 if ( risSimple.test( qualifier ) ) {
nickjillings@1596 2652 return jQuery.filter( qualifier, elements, not );
nickjillings@1596 2653 }
nickjillings@1596 2654
nickjillings@1596 2655 qualifier = jQuery.filter( qualifier, elements );
nickjillings@1596 2656 }
nickjillings@1596 2657
nickjillings@1596 2658 return jQuery.grep( elements, function( elem ) {
nickjillings@1596 2659 return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nickjillings@1596 2660 });
nickjillings@1596 2661 }
nickjillings@1596 2662
nickjillings@1596 2663 jQuery.filter = function( expr, elems, not ) {
nickjillings@1596 2664 var elem = elems[ 0 ];
nickjillings@1596 2665
nickjillings@1596 2666 if ( not ) {
nickjillings@1596 2667 expr = ":not(" + expr + ")";
nickjillings@1596 2668 }
nickjillings@1596 2669
nickjillings@1596 2670 return elems.length === 1 && elem.nodeType === 1 ?
nickjillings@1596 2671 jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nickjillings@1596 2672 jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nickjillings@1596 2673 return elem.nodeType === 1;
nickjillings@1596 2674 }));
nickjillings@1596 2675 };
nickjillings@1596 2676
nickjillings@1596 2677 jQuery.fn.extend({
nickjillings@1596 2678 find: function( selector ) {
nickjillings@1596 2679 var i,
nickjillings@1596 2680 len = this.length,
nickjillings@1596 2681 ret = [],
nickjillings@1596 2682 self = this;
nickjillings@1596 2683
nickjillings@1596 2684 if ( typeof selector !== "string" ) {
nickjillings@1596 2685 return this.pushStack( jQuery( selector ).filter(function() {
nickjillings@1596 2686 for ( i = 0; i < len; i++ ) {
nickjillings@1596 2687 if ( jQuery.contains( self[ i ], this ) ) {
nickjillings@1596 2688 return true;
nickjillings@1596 2689 }
nickjillings@1596 2690 }
nickjillings@1596 2691 }) );
nickjillings@1596 2692 }
nickjillings@1596 2693
nickjillings@1596 2694 for ( i = 0; i < len; i++ ) {
nickjillings@1596 2695 jQuery.find( selector, self[ i ], ret );
nickjillings@1596 2696 }
nickjillings@1596 2697
nickjillings@1596 2698 // Needed because $( selector, context ) becomes $( context ).find( selector )
nickjillings@1596 2699 ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nickjillings@1596 2700 ret.selector = this.selector ? this.selector + " " + selector : selector;
nickjillings@1596 2701 return ret;
nickjillings@1596 2702 },
nickjillings@1596 2703 filter: function( selector ) {
nickjillings@1596 2704 return this.pushStack( winnow(this, selector || [], false) );
nickjillings@1596 2705 },
nickjillings@1596 2706 not: function( selector ) {
nickjillings@1596 2707 return this.pushStack( winnow(this, selector || [], true) );
nickjillings@1596 2708 },
nickjillings@1596 2709 is: function( selector ) {
nickjillings@1596 2710 return !!winnow(
nickjillings@1596 2711 this,
nickjillings@1596 2712
nickjillings@1596 2713 // If this is a positional/relative selector, check membership in the returned set
nickjillings@1596 2714 // so $("p:first").is("p:last") won't return true for a doc with two "p".
nickjillings@1596 2715 typeof selector === "string" && rneedsContext.test( selector ) ?
nickjillings@1596 2716 jQuery( selector ) :
nickjillings@1596 2717 selector || [],
nickjillings@1596 2718 false
nickjillings@1596 2719 ).length;
nickjillings@1596 2720 }
nickjillings@1596 2721 });
nickjillings@1596 2722
nickjillings@1596 2723
nickjillings@1596 2724 // Initialize a jQuery object
nickjillings@1596 2725
nickjillings@1596 2726
nickjillings@1596 2727 // A central reference to the root jQuery(document)
nickjillings@1596 2728 var rootjQuery,
nickjillings@1596 2729
nickjillings@1596 2730 // A simple way to check for HTML strings
nickjillings@1596 2731 // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
nickjillings@1596 2732 // Strict HTML recognition (#11290: must start with <)
nickjillings@1596 2733 rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nickjillings@1596 2734
nickjillings@1596 2735 init = jQuery.fn.init = function( selector, context ) {
nickjillings@1596 2736 var match, elem;
nickjillings@1596 2737
nickjillings@1596 2738 // HANDLE: $(""), $(null), $(undefined), $(false)
nickjillings@1596 2739 if ( !selector ) {
nickjillings@1596 2740 return this;
nickjillings@1596 2741 }
nickjillings@1596 2742
nickjillings@1596 2743 // Handle HTML strings
nickjillings@1596 2744 if ( typeof selector === "string" ) {
nickjillings@1596 2745 if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nickjillings@1596 2746 // Assume that strings that start and end with <> are HTML and skip the regex check
nickjillings@1596 2747 match = [ null, selector, null ];
nickjillings@1596 2748
nickjillings@1596 2749 } else {
nickjillings@1596 2750 match = rquickExpr.exec( selector );
nickjillings@1596 2751 }
nickjillings@1596 2752
nickjillings@1596 2753 // Match html or make sure no context is specified for #id
nickjillings@1596 2754 if ( match && (match[1] || !context) ) {
nickjillings@1596 2755
nickjillings@1596 2756 // HANDLE: $(html) -> $(array)
nickjillings@1596 2757 if ( match[1] ) {
nickjillings@1596 2758 context = context instanceof jQuery ? context[0] : context;
nickjillings@1596 2759
nickjillings@1596 2760 // Option to run scripts is true for back-compat
nickjillings@1596 2761 // Intentionally let the error be thrown if parseHTML is not present
nickjillings@1596 2762 jQuery.merge( this, jQuery.parseHTML(
nickjillings@1596 2763 match[1],
nickjillings@1596 2764 context && context.nodeType ? context.ownerDocument || context : document,
nickjillings@1596 2765 true
nickjillings@1596 2766 ) );
nickjillings@1596 2767
nickjillings@1596 2768 // HANDLE: $(html, props)
nickjillings@1596 2769 if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nickjillings@1596 2770 for ( match in context ) {
nickjillings@1596 2771 // Properties of context are called as methods if possible
nickjillings@1596 2772 if ( jQuery.isFunction( this[ match ] ) ) {
nickjillings@1596 2773 this[ match ]( context[ match ] );
nickjillings@1596 2774
nickjillings@1596 2775 // ...and otherwise set as attributes
nickjillings@1596 2776 } else {
nickjillings@1596 2777 this.attr( match, context[ match ] );
nickjillings@1596 2778 }
nickjillings@1596 2779 }
nickjillings@1596 2780 }
nickjillings@1596 2781
nickjillings@1596 2782 return this;
nickjillings@1596 2783
nickjillings@1596 2784 // HANDLE: $(#id)
nickjillings@1596 2785 } else {
nickjillings@1596 2786 elem = document.getElementById( match[2] );
nickjillings@1596 2787
nickjillings@1596 2788 // Support: Blackberry 4.6
nickjillings@1596 2789 // gEBID returns nodes no longer in the document (#6963)
nickjillings@1596 2790 if ( elem && elem.parentNode ) {
nickjillings@1596 2791 // Inject the element directly into the jQuery object
nickjillings@1596 2792 this.length = 1;
nickjillings@1596 2793 this[0] = elem;
nickjillings@1596 2794 }
nickjillings@1596 2795
nickjillings@1596 2796 this.context = document;
nickjillings@1596 2797 this.selector = selector;
nickjillings@1596 2798 return this;
nickjillings@1596 2799 }
nickjillings@1596 2800
nickjillings@1596 2801 // HANDLE: $(expr, $(...))
nickjillings@1596 2802 } else if ( !context || context.jquery ) {
nickjillings@1596 2803 return ( context || rootjQuery ).find( selector );
nickjillings@1596 2804
nickjillings@1596 2805 // HANDLE: $(expr, context)
nickjillings@1596 2806 // (which is just equivalent to: $(context).find(expr)
nickjillings@1596 2807 } else {
nickjillings@1596 2808 return this.constructor( context ).find( selector );
nickjillings@1596 2809 }
nickjillings@1596 2810
nickjillings@1596 2811 // HANDLE: $(DOMElement)
nickjillings@1596 2812 } else if ( selector.nodeType ) {
nickjillings@1596 2813 this.context = this[0] = selector;
nickjillings@1596 2814 this.length = 1;
nickjillings@1596 2815 return this;
nickjillings@1596 2816
nickjillings@1596 2817 // HANDLE: $(function)
nickjillings@1596 2818 // Shortcut for document ready
nickjillings@1596 2819 } else if ( jQuery.isFunction( selector ) ) {
nickjillings@1596 2820 return typeof rootjQuery.ready !== "undefined" ?
nickjillings@1596 2821 rootjQuery.ready( selector ) :
nickjillings@1596 2822 // Execute immediately if ready is not present
nickjillings@1596 2823 selector( jQuery );
nickjillings@1596 2824 }
nickjillings@1596 2825
nickjillings@1596 2826 if ( selector.selector !== undefined ) {
nickjillings@1596 2827 this.selector = selector.selector;
nickjillings@1596 2828 this.context = selector.context;
nickjillings@1596 2829 }
nickjillings@1596 2830
nickjillings@1596 2831 return jQuery.makeArray( selector, this );
nickjillings@1596 2832 };
nickjillings@1596 2833
nickjillings@1596 2834 // Give the init function the jQuery prototype for later instantiation
nickjillings@1596 2835 init.prototype = jQuery.fn;
nickjillings@1596 2836
nickjillings@1596 2837 // Initialize central reference
nickjillings@1596 2838 rootjQuery = jQuery( document );
nickjillings@1596 2839
nickjillings@1596 2840
nickjillings@1596 2841 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nickjillings@1596 2842 // Methods guaranteed to produce a unique set when starting from a unique set
nickjillings@1596 2843 guaranteedUnique = {
nickjillings@1596 2844 children: true,
nickjillings@1596 2845 contents: true,
nickjillings@1596 2846 next: true,
nickjillings@1596 2847 prev: true
nickjillings@1596 2848 };
nickjillings@1596 2849
nickjillings@1596 2850 jQuery.extend({
nickjillings@1596 2851 dir: function( elem, dir, until ) {
nickjillings@1596 2852 var matched = [],
nickjillings@1596 2853 truncate = until !== undefined;
nickjillings@1596 2854
nickjillings@1596 2855 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nickjillings@1596 2856 if ( elem.nodeType === 1 ) {
nickjillings@1596 2857 if ( truncate && jQuery( elem ).is( until ) ) {
nickjillings@1596 2858 break;
nickjillings@1596 2859 }
nickjillings@1596 2860 matched.push( elem );
nickjillings@1596 2861 }
nickjillings@1596 2862 }
nickjillings@1596 2863 return matched;
nickjillings@1596 2864 },
nickjillings@1596 2865
nickjillings@1596 2866 sibling: function( n, elem ) {
nickjillings@1596 2867 var matched = [];
nickjillings@1596 2868
nickjillings@1596 2869 for ( ; n; n = n.nextSibling ) {
nickjillings@1596 2870 if ( n.nodeType === 1 && n !== elem ) {
nickjillings@1596 2871 matched.push( n );
nickjillings@1596 2872 }
nickjillings@1596 2873 }
nickjillings@1596 2874
nickjillings@1596 2875 return matched;
nickjillings@1596 2876 }
nickjillings@1596 2877 });
nickjillings@1596 2878
nickjillings@1596 2879 jQuery.fn.extend({
nickjillings@1596 2880 has: function( target ) {
nickjillings@1596 2881 var targets = jQuery( target, this ),
nickjillings@1596 2882 l = targets.length;
nickjillings@1596 2883
nickjillings@1596 2884 return this.filter(function() {
nickjillings@1596 2885 var i = 0;
nickjillings@1596 2886 for ( ; i < l; i++ ) {
nickjillings@1596 2887 if ( jQuery.contains( this, targets[i] ) ) {
nickjillings@1596 2888 return true;
nickjillings@1596 2889 }
nickjillings@1596 2890 }
nickjillings@1596 2891 });
nickjillings@1596 2892 },
nickjillings@1596 2893
nickjillings@1596 2894 closest: function( selectors, context ) {
nickjillings@1596 2895 var cur,
nickjillings@1596 2896 i = 0,
nickjillings@1596 2897 l = this.length,
nickjillings@1596 2898 matched = [],
nickjillings@1596 2899 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nickjillings@1596 2900 jQuery( selectors, context || this.context ) :
nickjillings@1596 2901 0;
nickjillings@1596 2902
nickjillings@1596 2903 for ( ; i < l; i++ ) {
nickjillings@1596 2904 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nickjillings@1596 2905 // Always skip document fragments
nickjillings@1596 2906 if ( cur.nodeType < 11 && (pos ?
nickjillings@1596 2907 pos.index(cur) > -1 :
nickjillings@1596 2908
nickjillings@1596 2909 // Don't pass non-elements to Sizzle
nickjillings@1596 2910 cur.nodeType === 1 &&
nickjillings@1596 2911 jQuery.find.matchesSelector(cur, selectors)) ) {
nickjillings@1596 2912
nickjillings@1596 2913 matched.push( cur );
nickjillings@1596 2914 break;
nickjillings@1596 2915 }
nickjillings@1596 2916 }
nickjillings@1596 2917 }
nickjillings@1596 2918
nickjillings@1596 2919 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nickjillings@1596 2920 },
nickjillings@1596 2921
nickjillings@1596 2922 // Determine the position of an element within the set
nickjillings@1596 2923 index: function( elem ) {
nickjillings@1596 2924
nickjillings@1596 2925 // No argument, return index in parent
nickjillings@1596 2926 if ( !elem ) {
nickjillings@1596 2927 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nickjillings@1596 2928 }
nickjillings@1596 2929
nickjillings@1596 2930 // Index in selector
nickjillings@1596 2931 if ( typeof elem === "string" ) {
nickjillings@1596 2932 return indexOf.call( jQuery( elem ), this[ 0 ] );
nickjillings@1596 2933 }
nickjillings@1596 2934
nickjillings@1596 2935 // Locate the position of the desired element
nickjillings@1596 2936 return indexOf.call( this,
nickjillings@1596 2937
nickjillings@1596 2938 // If it receives a jQuery object, the first element is used
nickjillings@1596 2939 elem.jquery ? elem[ 0 ] : elem
nickjillings@1596 2940 );
nickjillings@1596 2941 },
nickjillings@1596 2942
nickjillings@1596 2943 add: function( selector, context ) {
nickjillings@1596 2944 return this.pushStack(
nickjillings@1596 2945 jQuery.unique(
nickjillings@1596 2946 jQuery.merge( this.get(), jQuery( selector, context ) )
nickjillings@1596 2947 )
nickjillings@1596 2948 );
nickjillings@1596 2949 },
nickjillings@1596 2950
nickjillings@1596 2951 addBack: function( selector ) {
nickjillings@1596 2952 return this.add( selector == null ?
nickjillings@1596 2953 this.prevObject : this.prevObject.filter(selector)
nickjillings@1596 2954 );
nickjillings@1596 2955 }
nickjillings@1596 2956 });
nickjillings@1596 2957
nickjillings@1596 2958 function sibling( cur, dir ) {
nickjillings@1596 2959 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nickjillings@1596 2960 return cur;
nickjillings@1596 2961 }
nickjillings@1596 2962
nickjillings@1596 2963 jQuery.each({
nickjillings@1596 2964 parent: function( elem ) {
nickjillings@1596 2965 var parent = elem.parentNode;
nickjillings@1596 2966 return parent && parent.nodeType !== 11 ? parent : null;
nickjillings@1596 2967 },
nickjillings@1596 2968 parents: function( elem ) {
nickjillings@1596 2969 return jQuery.dir( elem, "parentNode" );
nickjillings@1596 2970 },
nickjillings@1596 2971 parentsUntil: function( elem, i, until ) {
nickjillings@1596 2972 return jQuery.dir( elem, "parentNode", until );
nickjillings@1596 2973 },
nickjillings@1596 2974 next: function( elem ) {
nickjillings@1596 2975 return sibling( elem, "nextSibling" );
nickjillings@1596 2976 },
nickjillings@1596 2977 prev: function( elem ) {
nickjillings@1596 2978 return sibling( elem, "previousSibling" );
nickjillings@1596 2979 },
nickjillings@1596 2980 nextAll: function( elem ) {
nickjillings@1596 2981 return jQuery.dir( elem, "nextSibling" );
nickjillings@1596 2982 },
nickjillings@1596 2983 prevAll: function( elem ) {
nickjillings@1596 2984 return jQuery.dir( elem, "previousSibling" );
nickjillings@1596 2985 },
nickjillings@1596 2986 nextUntil: function( elem, i, until ) {
nickjillings@1596 2987 return jQuery.dir( elem, "nextSibling", until );
nickjillings@1596 2988 },
nickjillings@1596 2989 prevUntil: function( elem, i, until ) {
nickjillings@1596 2990 return jQuery.dir( elem, "previousSibling", until );
nickjillings@1596 2991 },
nickjillings@1596 2992 siblings: function( elem ) {
nickjillings@1596 2993 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nickjillings@1596 2994 },
nickjillings@1596 2995 children: function( elem ) {
nickjillings@1596 2996 return jQuery.sibling( elem.firstChild );
nickjillings@1596 2997 },
nickjillings@1596 2998 contents: function( elem ) {
nickjillings@1596 2999 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nickjillings@1596 3000 }
nickjillings@1596 3001 }, function( name, fn ) {
nickjillings@1596 3002 jQuery.fn[ name ] = function( until, selector ) {
nickjillings@1596 3003 var matched = jQuery.map( this, fn, until );
nickjillings@1596 3004
nickjillings@1596 3005 if ( name.slice( -5 ) !== "Until" ) {
nickjillings@1596 3006 selector = until;
nickjillings@1596 3007 }
nickjillings@1596 3008
nickjillings@1596 3009 if ( selector && typeof selector === "string" ) {
nickjillings@1596 3010 matched = jQuery.filter( selector, matched );
nickjillings@1596 3011 }
nickjillings@1596 3012
nickjillings@1596 3013 if ( this.length > 1 ) {
nickjillings@1596 3014 // Remove duplicates
nickjillings@1596 3015 if ( !guaranteedUnique[ name ] ) {
nickjillings@1596 3016 jQuery.unique( matched );
nickjillings@1596 3017 }
nickjillings@1596 3018
nickjillings@1596 3019 // Reverse order for parents* and prev-derivatives
nickjillings@1596 3020 if ( rparentsprev.test( name ) ) {
nickjillings@1596 3021 matched.reverse();
nickjillings@1596 3022 }
nickjillings@1596 3023 }
nickjillings@1596 3024
nickjillings@1596 3025 return this.pushStack( matched );
nickjillings@1596 3026 };
nickjillings@1596 3027 });
nickjillings@1596 3028 var rnotwhite = (/\S+/g);
nickjillings@1596 3029
nickjillings@1596 3030
nickjillings@1596 3031
nickjillings@1596 3032 // String to Object options format cache
nickjillings@1596 3033 var optionsCache = {};
nickjillings@1596 3034
nickjillings@1596 3035 // Convert String-formatted options into Object-formatted ones and store in cache
nickjillings@1596 3036 function createOptions( options ) {
nickjillings@1596 3037 var object = optionsCache[ options ] = {};
nickjillings@1596 3038 jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nickjillings@1596 3039 object[ flag ] = true;
nickjillings@1596 3040 });
nickjillings@1596 3041 return object;
nickjillings@1596 3042 }
nickjillings@1596 3043
nickjillings@1596 3044 /*
nickjillings@1596 3045 * Create a callback list using the following parameters:
nickjillings@1596 3046 *
nickjillings@1596 3047 * options: an optional list of space-separated options that will change how
nickjillings@1596 3048 * the callback list behaves or a more traditional option object
nickjillings@1596 3049 *
nickjillings@1596 3050 * By default a callback list will act like an event callback list and can be
nickjillings@1596 3051 * "fired" multiple times.
nickjillings@1596 3052 *
nickjillings@1596 3053 * Possible options:
nickjillings@1596 3054 *
nickjillings@1596 3055 * once: will ensure the callback list can only be fired once (like a Deferred)
nickjillings@1596 3056 *
nickjillings@1596 3057 * memory: will keep track of previous values and will call any callback added
nickjillings@1596 3058 * after the list has been fired right away with the latest "memorized"
nickjillings@1596 3059 * values (like a Deferred)
nickjillings@1596 3060 *
nickjillings@1596 3061 * unique: will ensure a callback can only be added once (no duplicate in the list)
nickjillings@1596 3062 *
nickjillings@1596 3063 * stopOnFalse: interrupt callings when a callback returns false
nickjillings@1596 3064 *
nickjillings@1596 3065 */
nickjillings@1596 3066 jQuery.Callbacks = function( options ) {
nickjillings@1596 3067
nickjillings@1596 3068 // Convert options from String-formatted to Object-formatted if needed
nickjillings@1596 3069 // (we check in cache first)
nickjillings@1596 3070 options = typeof options === "string" ?
nickjillings@1596 3071 ( optionsCache[ options ] || createOptions( options ) ) :
nickjillings@1596 3072 jQuery.extend( {}, options );
nickjillings@1596 3073
nickjillings@1596 3074 var // Last fire value (for non-forgettable lists)
nickjillings@1596 3075 memory,
nickjillings@1596 3076 // Flag to know if list was already fired
nickjillings@1596 3077 fired,
nickjillings@1596 3078 // Flag to know if list is currently firing
nickjillings@1596 3079 firing,
nickjillings@1596 3080 // First callback to fire (used internally by add and fireWith)
nickjillings@1596 3081 firingStart,
nickjillings@1596 3082 // End of the loop when firing
nickjillings@1596 3083 firingLength,
nickjillings@1596 3084 // Index of currently firing callback (modified by remove if needed)
nickjillings@1596 3085 firingIndex,
nickjillings@1596 3086 // Actual callback list
nickjillings@1596 3087 list = [],
nickjillings@1596 3088 // Stack of fire calls for repeatable lists
nickjillings@1596 3089 stack = !options.once && [],
nickjillings@1596 3090 // Fire callbacks
nickjillings@1596 3091 fire = function( data ) {
nickjillings@1596 3092 memory = options.memory && data;
nickjillings@1596 3093 fired = true;
nickjillings@1596 3094 firingIndex = firingStart || 0;
nickjillings@1596 3095 firingStart = 0;
nickjillings@1596 3096 firingLength = list.length;
nickjillings@1596 3097 firing = true;
nickjillings@1596 3098 for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nickjillings@1596 3099 if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nickjillings@1596 3100 memory = false; // To prevent further calls using add
nickjillings@1596 3101 break;
nickjillings@1596 3102 }
nickjillings@1596 3103 }
nickjillings@1596 3104 firing = false;
nickjillings@1596 3105 if ( list ) {
nickjillings@1596 3106 if ( stack ) {
nickjillings@1596 3107 if ( stack.length ) {
nickjillings@1596 3108 fire( stack.shift() );
nickjillings@1596 3109 }
nickjillings@1596 3110 } else if ( memory ) {
nickjillings@1596 3111 list = [];
nickjillings@1596 3112 } else {
nickjillings@1596 3113 self.disable();
nickjillings@1596 3114 }
nickjillings@1596 3115 }
nickjillings@1596 3116 },
nickjillings@1596 3117 // Actual Callbacks object
nickjillings@1596 3118 self = {
nickjillings@1596 3119 // Add a callback or a collection of callbacks to the list
nickjillings@1596 3120 add: function() {
nickjillings@1596 3121 if ( list ) {
nickjillings@1596 3122 // First, we save the current length
nickjillings@1596 3123 var start = list.length;
nickjillings@1596 3124 (function add( args ) {
nickjillings@1596 3125 jQuery.each( args, function( _, arg ) {
nickjillings@1596 3126 var type = jQuery.type( arg );
nickjillings@1596 3127 if ( type === "function" ) {
nickjillings@1596 3128 if ( !options.unique || !self.has( arg ) ) {
nickjillings@1596 3129 list.push( arg );
nickjillings@1596 3130 }
nickjillings@1596 3131 } else if ( arg && arg.length && type !== "string" ) {
nickjillings@1596 3132 // Inspect recursively
nickjillings@1596 3133 add( arg );
nickjillings@1596 3134 }
nickjillings@1596 3135 });
nickjillings@1596 3136 })( arguments );
nickjillings@1596 3137 // Do we need to add the callbacks to the
nickjillings@1596 3138 // current firing batch?
nickjillings@1596 3139 if ( firing ) {
nickjillings@1596 3140 firingLength = list.length;
nickjillings@1596 3141 // With memory, if we're not firing then
nickjillings@1596 3142 // we should call right away
nickjillings@1596 3143 } else if ( memory ) {
nickjillings@1596 3144 firingStart = start;
nickjillings@1596 3145 fire( memory );
nickjillings@1596 3146 }
nickjillings@1596 3147 }
nickjillings@1596 3148 return this;
nickjillings@1596 3149 },
nickjillings@1596 3150 // Remove a callback from the list
nickjillings@1596 3151 remove: function() {
nickjillings@1596 3152 if ( list ) {
nickjillings@1596 3153 jQuery.each( arguments, function( _, arg ) {
nickjillings@1596 3154 var index;
nickjillings@1596 3155 while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nickjillings@1596 3156 list.splice( index, 1 );
nickjillings@1596 3157 // Handle firing indexes
nickjillings@1596 3158 if ( firing ) {
nickjillings@1596 3159 if ( index <= firingLength ) {
nickjillings@1596 3160 firingLength--;
nickjillings@1596 3161 }
nickjillings@1596 3162 if ( index <= firingIndex ) {
nickjillings@1596 3163 firingIndex--;
nickjillings@1596 3164 }
nickjillings@1596 3165 }
nickjillings@1596 3166 }
nickjillings@1596 3167 });
nickjillings@1596 3168 }
nickjillings@1596 3169 return this;
nickjillings@1596 3170 },
nickjillings@1596 3171 // Check if a given callback is in the list.
nickjillings@1596 3172 // If no argument is given, return whether or not list has callbacks attached.
nickjillings@1596 3173 has: function( fn ) {
nickjillings@1596 3174 return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nickjillings@1596 3175 },
nickjillings@1596 3176 // Remove all callbacks from the list
nickjillings@1596 3177 empty: function() {
nickjillings@1596 3178 list = [];
nickjillings@1596 3179 firingLength = 0;
nickjillings@1596 3180 return this;
nickjillings@1596 3181 },
nickjillings@1596 3182 // Have the list do nothing anymore
nickjillings@1596 3183 disable: function() {
nickjillings@1596 3184 list = stack = memory = undefined;
nickjillings@1596 3185 return this;
nickjillings@1596 3186 },
nickjillings@1596 3187 // Is it disabled?
nickjillings@1596 3188 disabled: function() {
nickjillings@1596 3189 return !list;
nickjillings@1596 3190 },
nickjillings@1596 3191 // Lock the list in its current state
nickjillings@1596 3192 lock: function() {
nickjillings@1596 3193 stack = undefined;
nickjillings@1596 3194 if ( !memory ) {
nickjillings@1596 3195 self.disable();
nickjillings@1596 3196 }
nickjillings@1596 3197 return this;
nickjillings@1596 3198 },
nickjillings@1596 3199 // Is it locked?
nickjillings@1596 3200 locked: function() {
nickjillings@1596 3201 return !stack;
nickjillings@1596 3202 },
nickjillings@1596 3203 // Call all callbacks with the given context and arguments
nickjillings@1596 3204 fireWith: function( context, args ) {
nickjillings@1596 3205 if ( list && ( !fired || stack ) ) {
nickjillings@1596 3206 args = args || [];
nickjillings@1596 3207 args = [ context, args.slice ? args.slice() : args ];
nickjillings@1596 3208 if ( firing ) {
nickjillings@1596 3209 stack.push( args );
nickjillings@1596 3210 } else {
nickjillings@1596 3211 fire( args );
nickjillings@1596 3212 }
nickjillings@1596 3213 }
nickjillings@1596 3214 return this;
nickjillings@1596 3215 },
nickjillings@1596 3216 // Call all the callbacks with the given arguments
nickjillings@1596 3217 fire: function() {
nickjillings@1596 3218 self.fireWith( this, arguments );
nickjillings@1596 3219 return this;
nickjillings@1596 3220 },
nickjillings@1596 3221 // To know if the callbacks have already been called at least once
nickjillings@1596 3222 fired: function() {
nickjillings@1596 3223 return !!fired;
nickjillings@1596 3224 }
nickjillings@1596 3225 };
nickjillings@1596 3226
nickjillings@1596 3227 return self;
nickjillings@1596 3228 };
nickjillings@1596 3229
nickjillings@1596 3230
nickjillings@1596 3231 jQuery.extend({
nickjillings@1596 3232
nickjillings@1596 3233 Deferred: function( func ) {
nickjillings@1596 3234 var tuples = [
nickjillings@1596 3235 // action, add listener, listener list, final state
nickjillings@1596 3236 [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nickjillings@1596 3237 [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nickjillings@1596 3238 [ "notify", "progress", jQuery.Callbacks("memory") ]
nickjillings@1596 3239 ],
nickjillings@1596 3240 state = "pending",
nickjillings@1596 3241 promise = {
nickjillings@1596 3242 state: function() {
nickjillings@1596 3243 return state;
nickjillings@1596 3244 },
nickjillings@1596 3245 always: function() {
nickjillings@1596 3246 deferred.done( arguments ).fail( arguments );
nickjillings@1596 3247 return this;
nickjillings@1596 3248 },
nickjillings@1596 3249 then: function( /* fnDone, fnFail, fnProgress */ ) {
nickjillings@1596 3250 var fns = arguments;
nickjillings@1596 3251 return jQuery.Deferred(function( newDefer ) {
nickjillings@1596 3252 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1596 3253 var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nickjillings@1596 3254 // deferred[ done | fail | progress ] for forwarding actions to newDefer
nickjillings@1596 3255 deferred[ tuple[1] ](function() {
nickjillings@1596 3256 var returned = fn && fn.apply( this, arguments );
nickjillings@1596 3257 if ( returned && jQuery.isFunction( returned.promise ) ) {
nickjillings@1596 3258 returned.promise()
nickjillings@1596 3259 .done( newDefer.resolve )
nickjillings@1596 3260 .fail( newDefer.reject )
nickjillings@1596 3261 .progress( newDefer.notify );
nickjillings@1596 3262 } else {
nickjillings@1596 3263 newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nickjillings@1596 3264 }
nickjillings@1596 3265 });
nickjillings@1596 3266 });
nickjillings@1596 3267 fns = null;
nickjillings@1596 3268 }).promise();
nickjillings@1596 3269 },
nickjillings@1596 3270 // Get a promise for this deferred
nickjillings@1596 3271 // If obj is provided, the promise aspect is added to the object
nickjillings@1596 3272 promise: function( obj ) {
nickjillings@1596 3273 return obj != null ? jQuery.extend( obj, promise ) : promise;
nickjillings@1596 3274 }
nickjillings@1596 3275 },
nickjillings@1596 3276 deferred = {};
nickjillings@1596 3277
nickjillings@1596 3278 // Keep pipe for back-compat
nickjillings@1596 3279 promise.pipe = promise.then;
nickjillings@1596 3280
nickjillings@1596 3281 // Add list-specific methods
nickjillings@1596 3282 jQuery.each( tuples, function( i, tuple ) {
nickjillings@1596 3283 var list = tuple[ 2 ],
nickjillings@1596 3284 stateString = tuple[ 3 ];
nickjillings@1596 3285
nickjillings@1596 3286 // promise[ done | fail | progress ] = list.add
nickjillings@1596 3287 promise[ tuple[1] ] = list.add;
nickjillings@1596 3288
nickjillings@1596 3289 // Handle state
nickjillings@1596 3290 if ( stateString ) {
nickjillings@1596 3291 list.add(function() {
nickjillings@1596 3292 // state = [ resolved | rejected ]
nickjillings@1596 3293 state = stateString;
nickjillings@1596 3294
nickjillings@1596 3295 // [ reject_list | resolve_list ].disable; progress_list.lock
nickjillings@1596 3296 }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nickjillings@1596 3297 }
nickjillings@1596 3298
nickjillings@1596 3299 // deferred[ resolve | reject | notify ]
nickjillings@1596 3300 deferred[ tuple[0] ] = function() {
nickjillings@1596 3301 deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nickjillings@1596 3302 return this;
nickjillings@1596 3303 };
nickjillings@1596 3304 deferred[ tuple[0] + "With" ] = list.fireWith;
nickjillings@1596 3305 });
nickjillings@1596 3306
nickjillings@1596 3307 // Make the deferred a promise
nickjillings@1596 3308 promise.promise( deferred );
nickjillings@1596 3309
nickjillings@1596 3310 // Call given func if any
nickjillings@1596 3311 if ( func ) {
nickjillings@1596 3312 func.call( deferred, deferred );
nickjillings@1596 3313 }
nickjillings@1596 3314
nickjillings@1596 3315 // All done!
nickjillings@1596 3316 return deferred;
nickjillings@1596 3317 },
nickjillings@1596 3318
nickjillings@1596 3319 // Deferred helper
nickjillings@1596 3320 when: function( subordinate /* , ..., subordinateN */ ) {
nickjillings@1596 3321 var i = 0,
nickjillings@1596 3322 resolveValues = slice.call( arguments ),
nickjillings@1596 3323 length = resolveValues.length,
nickjillings@1596 3324
nickjillings@1596 3325 // the count of uncompleted subordinates
nickjillings@1596 3326 remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nickjillings@1596 3327
nickjillings@1596 3328 // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nickjillings@1596 3329 deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nickjillings@1596 3330
nickjillings@1596 3331 // Update function for both resolve and progress values
nickjillings@1596 3332 updateFunc = function( i, contexts, values ) {
nickjillings@1596 3333 return function( value ) {
nickjillings@1596 3334 contexts[ i ] = this;
nickjillings@1596 3335 values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nickjillings@1596 3336 if ( values === progressValues ) {
nickjillings@1596 3337 deferred.notifyWith( contexts, values );
nickjillings@1596 3338 } else if ( !( --remaining ) ) {
nickjillings@1596 3339 deferred.resolveWith( contexts, values );
nickjillings@1596 3340 }
nickjillings@1596 3341 };
nickjillings@1596 3342 },
nickjillings@1596 3343
nickjillings@1596 3344 progressValues, progressContexts, resolveContexts;
nickjillings@1596 3345
nickjillings@1596 3346 // Add listeners to Deferred subordinates; treat others as resolved
nickjillings@1596 3347 if ( length > 1 ) {
nickjillings@1596 3348 progressValues = new Array( length );
nickjillings@1596 3349 progressContexts = new Array( length );
nickjillings@1596 3350 resolveContexts = new Array( length );
nickjillings@1596 3351 for ( ; i < length; i++ ) {
nickjillings@1596 3352 if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nickjillings@1596 3353 resolveValues[ i ].promise()
nickjillings@1596 3354 .done( updateFunc( i, resolveContexts, resolveValues ) )
nickjillings@1596 3355 .fail( deferred.reject )
nickjillings@1596 3356 .progress( updateFunc( i, progressContexts, progressValues ) );
nickjillings@1596 3357 } else {
nickjillings@1596 3358 --remaining;
nickjillings@1596 3359 }
nickjillings@1596 3360 }
nickjillings@1596 3361 }
nickjillings@1596 3362
nickjillings@1596 3363 // If we're not waiting on anything, resolve the master
nickjillings@1596 3364 if ( !remaining ) {
nickjillings@1596 3365 deferred.resolveWith( resolveContexts, resolveValues );
nickjillings@1596 3366 }
nickjillings@1596 3367
nickjillings@1596 3368 return deferred.promise();
nickjillings@1596 3369 }
nickjillings@1596 3370 });
nickjillings@1596 3371
nickjillings@1596 3372
nickjillings@1596 3373 // The deferred used on DOM ready
nickjillings@1596 3374 var readyList;
nickjillings@1596 3375
nickjillings@1596 3376 jQuery.fn.ready = function( fn ) {
nickjillings@1596 3377 // Add the callback
nickjillings@1596 3378 jQuery.ready.promise().done( fn );
nickjillings@1596 3379
nickjillings@1596 3380 return this;
nickjillings@1596 3381 };
nickjillings@1596 3382
nickjillings@1596 3383 jQuery.extend({
nickjillings@1596 3384 // Is the DOM ready to be used? Set to true once it occurs.
nickjillings@1596 3385 isReady: false,
nickjillings@1596 3386
nickjillings@1596 3387 // A counter to track how many items to wait for before
nickjillings@1596 3388 // the ready event fires. See #6781
nickjillings@1596 3389 readyWait: 1,
nickjillings@1596 3390
nickjillings@1596 3391 // Hold (or release) the ready event
nickjillings@1596 3392 holdReady: function( hold ) {
nickjillings@1596 3393 if ( hold ) {
nickjillings@1596 3394 jQuery.readyWait++;
nickjillings@1596 3395 } else {
nickjillings@1596 3396 jQuery.ready( true );
nickjillings@1596 3397 }
nickjillings@1596 3398 },
nickjillings@1596 3399
nickjillings@1596 3400 // Handle when the DOM is ready
nickjillings@1596 3401 ready: function( wait ) {
nickjillings@1596 3402
nickjillings@1596 3403 // Abort if there are pending holds or we're already ready
nickjillings@1596 3404 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nickjillings@1596 3405 return;
nickjillings@1596 3406 }
nickjillings@1596 3407
nickjillings@1596 3408 // Remember that the DOM is ready
nickjillings@1596 3409 jQuery.isReady = true;
nickjillings@1596 3410
nickjillings@1596 3411 // If a normal DOM Ready event fired, decrement, and wait if need be
nickjillings@1596 3412 if ( wait !== true && --jQuery.readyWait > 0 ) {
nickjillings@1596 3413 return;
nickjillings@1596 3414 }
nickjillings@1596 3415
nickjillings@1596 3416 // If there are functions bound, to execute
nickjillings@1596 3417 readyList.resolveWith( document, [ jQuery ] );
nickjillings@1596 3418
nickjillings@1596 3419 // Trigger any bound ready events
nickjillings@1596 3420 if ( jQuery.fn.triggerHandler ) {
nickjillings@1596 3421 jQuery( document ).triggerHandler( "ready" );
nickjillings@1596 3422 jQuery( document ).off( "ready" );
nickjillings@1596 3423 }
nickjillings@1596 3424 }
nickjillings@1596 3425 });
nickjillings@1596 3426
nickjillings@1596 3427 /**
nickjillings@1596 3428 * The ready event handler and self cleanup method
nickjillings@1596 3429 */
nickjillings@1596 3430 function completed() {
nickjillings@1596 3431 document.removeEventListener( "DOMContentLoaded", completed, false );
nickjillings@1596 3432 window.removeEventListener( "load", completed, false );
nickjillings@1596 3433 jQuery.ready();
nickjillings@1596 3434 }
nickjillings@1596 3435
nickjillings@1596 3436 jQuery.ready.promise = function( obj ) {
nickjillings@1596 3437 if ( !readyList ) {
nickjillings@1596 3438
nickjillings@1596 3439 readyList = jQuery.Deferred();
nickjillings@1596 3440
nickjillings@1596 3441 // Catch cases where $(document).ready() is called after the browser event has already occurred.
nickjillings@1596 3442 // We once tried to use readyState "interactive" here, but it caused issues like the one
nickjillings@1596 3443 // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nickjillings@1596 3444 if ( document.readyState === "complete" ) {
nickjillings@1596 3445 // Handle it asynchronously to allow scripts the opportunity to delay ready
nickjillings@1596 3446 setTimeout( jQuery.ready );
nickjillings@1596 3447
nickjillings@1596 3448 } else {
nickjillings@1596 3449
nickjillings@1596 3450 // Use the handy event callback
nickjillings@1596 3451 document.addEventListener( "DOMContentLoaded", completed, false );
nickjillings@1596 3452
nickjillings@1596 3453 // A fallback to window.onload, that will always work
nickjillings@1596 3454 window.addEventListener( "load", completed, false );
nickjillings@1596 3455 }
nickjillings@1596 3456 }
nickjillings@1596 3457 return readyList.promise( obj );
nickjillings@1596 3458 };
nickjillings@1596 3459
nickjillings@1596 3460 // Kick off the DOM ready check even if the user does not
nickjillings@1596 3461 jQuery.ready.promise();
nickjillings@1596 3462
nickjillings@1596 3463
nickjillings@1596 3464
nickjillings@1596 3465
nickjillings@1596 3466 // Multifunctional method to get and set values of a collection
nickjillings@1596 3467 // The value/s can optionally be executed if it's a function
nickjillings@1596 3468 var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nickjillings@1596 3469 var i = 0,
nickjillings@1596 3470 len = elems.length,
nickjillings@1596 3471 bulk = key == null;
nickjillings@1596 3472
nickjillings@1596 3473 // Sets many values
nickjillings@1596 3474 if ( jQuery.type( key ) === "object" ) {
nickjillings@1596 3475 chainable = true;
nickjillings@1596 3476 for ( i in key ) {
nickjillings@1596 3477 jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nickjillings@1596 3478 }
nickjillings@1596 3479
nickjillings@1596 3480 // Sets one value
nickjillings@1596 3481 } else if ( value !== undefined ) {
nickjillings@1596 3482 chainable = true;
nickjillings@1596 3483
nickjillings@1596 3484 if ( !jQuery.isFunction( value ) ) {
nickjillings@1596 3485 raw = true;
nickjillings@1596 3486 }
nickjillings@1596 3487
nickjillings@1596 3488 if ( bulk ) {
nickjillings@1596 3489 // Bulk operations run against the entire set
nickjillings@1596 3490 if ( raw ) {
nickjillings@1596 3491 fn.call( elems, value );
nickjillings@1596 3492 fn = null;
nickjillings@1596 3493
nickjillings@1596 3494 // ...except when executing function values
nickjillings@1596 3495 } else {
nickjillings@1596 3496 bulk = fn;
nickjillings@1596 3497 fn = function( elem, key, value ) {
nickjillings@1596 3498 return bulk.call( jQuery( elem ), value );
nickjillings@1596 3499 };
nickjillings@1596 3500 }
nickjillings@1596 3501 }
nickjillings@1596 3502
nickjillings@1596 3503 if ( fn ) {
nickjillings@1596 3504 for ( ; i < len; i++ ) {
nickjillings@1596 3505 fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nickjillings@1596 3506 }
nickjillings@1596 3507 }
nickjillings@1596 3508 }
nickjillings@1596 3509
nickjillings@1596 3510 return chainable ?
nickjillings@1596 3511 elems :
nickjillings@1596 3512
nickjillings@1596 3513 // Gets
nickjillings@1596 3514 bulk ?
nickjillings@1596 3515 fn.call( elems ) :
nickjillings@1596 3516 len ? fn( elems[0], key ) : emptyGet;
nickjillings@1596 3517 };
nickjillings@1596 3518
nickjillings@1596 3519
nickjillings@1596 3520 /**
nickjillings@1596 3521 * Determines whether an object can have data
nickjillings@1596 3522 */
nickjillings@1596 3523 jQuery.acceptData = function( owner ) {
nickjillings@1596 3524 // Accepts only:
nickjillings@1596 3525 // - Node
nickjillings@1596 3526 // - Node.ELEMENT_NODE
nickjillings@1596 3527 // - Node.DOCUMENT_NODE
nickjillings@1596 3528 // - Object
nickjillings@1596 3529 // - Any
nickjillings@1596 3530 /* jshint -W018 */
nickjillings@1596 3531 return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nickjillings@1596 3532 };
nickjillings@1596 3533
nickjillings@1596 3534
nickjillings@1596 3535 function Data() {
nickjillings@1596 3536 // Support: Android<4,
nickjillings@1596 3537 // Old WebKit does not have Object.preventExtensions/freeze method,
nickjillings@1596 3538 // return new empty object instead with no [[set]] accessor
nickjillings@1596 3539 Object.defineProperty( this.cache = {}, 0, {
nickjillings@1596 3540 get: function() {
nickjillings@1596 3541 return {};
nickjillings@1596 3542 }
nickjillings@1596 3543 });
nickjillings@1596 3544
nickjillings@1596 3545 this.expando = jQuery.expando + Data.uid++;
nickjillings@1596 3546 }
nickjillings@1596 3547
nickjillings@1596 3548 Data.uid = 1;
nickjillings@1596 3549 Data.accepts = jQuery.acceptData;
nickjillings@1596 3550
nickjillings@1596 3551 Data.prototype = {
nickjillings@1596 3552 key: function( owner ) {
nickjillings@1596 3553 // We can accept data for non-element nodes in modern browsers,
nickjillings@1596 3554 // but we should not, see #8335.
nickjillings@1596 3555 // Always return the key for a frozen object.
nickjillings@1596 3556 if ( !Data.accepts( owner ) ) {
nickjillings@1596 3557 return 0;
nickjillings@1596 3558 }
nickjillings@1596 3559
nickjillings@1596 3560 var descriptor = {},
nickjillings@1596 3561 // Check if the owner object already has a cache key
nickjillings@1596 3562 unlock = owner[ this.expando ];
nickjillings@1596 3563
nickjillings@1596 3564 // If not, create one
nickjillings@1596 3565 if ( !unlock ) {
nickjillings@1596 3566 unlock = Data.uid++;
nickjillings@1596 3567
nickjillings@1596 3568 // Secure it in a non-enumerable, non-writable property
nickjillings@1596 3569 try {
nickjillings@1596 3570 descriptor[ this.expando ] = { value: unlock };
nickjillings@1596 3571 Object.defineProperties( owner, descriptor );
nickjillings@1596 3572
nickjillings@1596 3573 // Support: Android<4
nickjillings@1596 3574 // Fallback to a less secure definition
nickjillings@1596 3575 } catch ( e ) {
nickjillings@1596 3576 descriptor[ this.expando ] = unlock;
nickjillings@1596 3577 jQuery.extend( owner, descriptor );
nickjillings@1596 3578 }
nickjillings@1596 3579 }
nickjillings@1596 3580
nickjillings@1596 3581 // Ensure the cache object
nickjillings@1596 3582 if ( !this.cache[ unlock ] ) {
nickjillings@1596 3583 this.cache[ unlock ] = {};
nickjillings@1596 3584 }
nickjillings@1596 3585
nickjillings@1596 3586 return unlock;
nickjillings@1596 3587 },
nickjillings@1596 3588 set: function( owner, data, value ) {
nickjillings@1596 3589 var prop,
nickjillings@1596 3590 // There may be an unlock assigned to this node,
nickjillings@1596 3591 // if there is no entry for this "owner", create one inline
nickjillings@1596 3592 // and set the unlock as though an owner entry had always existed
nickjillings@1596 3593 unlock = this.key( owner ),
nickjillings@1596 3594 cache = this.cache[ unlock ];
nickjillings@1596 3595
nickjillings@1596 3596 // Handle: [ owner, key, value ] args
nickjillings@1596 3597 if ( typeof data === "string" ) {
nickjillings@1596 3598 cache[ data ] = value;
nickjillings@1596 3599
nickjillings@1596 3600 // Handle: [ owner, { properties } ] args
nickjillings@1596 3601 } else {
nickjillings@1596 3602 // Fresh assignments by object are shallow copied
nickjillings@1596 3603 if ( jQuery.isEmptyObject( cache ) ) {
nickjillings@1596 3604 jQuery.extend( this.cache[ unlock ], data );
nickjillings@1596 3605 // Otherwise, copy the properties one-by-one to the cache object
nickjillings@1596 3606 } else {
nickjillings@1596 3607 for ( prop in data ) {
nickjillings@1596 3608 cache[ prop ] = data[ prop ];
nickjillings@1596 3609 }
nickjillings@1596 3610 }
nickjillings@1596 3611 }
nickjillings@1596 3612 return cache;
nickjillings@1596 3613 },
nickjillings@1596 3614 get: function( owner, key ) {
nickjillings@1596 3615 // Either a valid cache is found, or will be created.
nickjillings@1596 3616 // New caches will be created and the unlock returned,
nickjillings@1596 3617 // allowing direct access to the newly created
nickjillings@1596 3618 // empty data object. A valid owner object must be provided.
nickjillings@1596 3619 var cache = this.cache[ this.key( owner ) ];
nickjillings@1596 3620
nickjillings@1596 3621 return key === undefined ?
nickjillings@1596 3622 cache : cache[ key ];
nickjillings@1596 3623 },
nickjillings@1596 3624 access: function( owner, key, value ) {
nickjillings@1596 3625 var stored;
nickjillings@1596 3626 // In cases where either:
nickjillings@1596 3627 //
nickjillings@1596 3628 // 1. No key was specified
nickjillings@1596 3629 // 2. A string key was specified, but no value provided
nickjillings@1596 3630 //
nickjillings@1596 3631 // Take the "read" path and allow the get method to determine
nickjillings@1596 3632 // which value to return, respectively either:
nickjillings@1596 3633 //
nickjillings@1596 3634 // 1. The entire cache object
nickjillings@1596 3635 // 2. The data stored at the key
nickjillings@1596 3636 //
nickjillings@1596 3637 if ( key === undefined ||
nickjillings@1596 3638 ((key && typeof key === "string") && value === undefined) ) {
nickjillings@1596 3639
nickjillings@1596 3640 stored = this.get( owner, key );
nickjillings@1596 3641
nickjillings@1596 3642 return stored !== undefined ?
nickjillings@1596 3643 stored : this.get( owner, jQuery.camelCase(key) );
nickjillings@1596 3644 }
nickjillings@1596 3645
nickjillings@1596 3646 // [*]When the key is not a string, or both a key and value
nickjillings@1596 3647 // are specified, set or extend (existing objects) with either:
nickjillings@1596 3648 //
nickjillings@1596 3649 // 1. An object of properties
nickjillings@1596 3650 // 2. A key and value
nickjillings@1596 3651 //
nickjillings@1596 3652 this.set( owner, key, value );
nickjillings@1596 3653
nickjillings@1596 3654 // Since the "set" path can have two possible entry points
nickjillings@1596 3655 // return the expected data based on which path was taken[*]
nickjillings@1596 3656 return value !== undefined ? value : key;
nickjillings@1596 3657 },
nickjillings@1596 3658 remove: function( owner, key ) {
nickjillings@1596 3659 var i, name, camel,
nickjillings@1596 3660 unlock = this.key( owner ),
nickjillings@1596 3661 cache = this.cache[ unlock ];
nickjillings@1596 3662
nickjillings@1596 3663 if ( key === undefined ) {
nickjillings@1596 3664 this.cache[ unlock ] = {};
nickjillings@1596 3665
nickjillings@1596 3666 } else {
nickjillings@1596 3667 // Support array or space separated string of keys
nickjillings@1596 3668 if ( jQuery.isArray( key ) ) {
nickjillings@1596 3669 // If "name" is an array of keys...
nickjillings@1596 3670 // When data is initially created, via ("key", "val") signature,
nickjillings@1596 3671 // keys will be converted to camelCase.
nickjillings@1596 3672 // Since there is no way to tell _how_ a key was added, remove
nickjillings@1596 3673 // both plain key and camelCase key. #12786
nickjillings@1596 3674 // This will only penalize the array argument path.
nickjillings@1596 3675 name = key.concat( key.map( jQuery.camelCase ) );
nickjillings@1596 3676 } else {
nickjillings@1596 3677 camel = jQuery.camelCase( key );
nickjillings@1596 3678 // Try the string as a key before any manipulation
nickjillings@1596 3679 if ( key in cache ) {
nickjillings@1596 3680 name = [ key, camel ];
nickjillings@1596 3681 } else {
nickjillings@1596 3682 // If a key with the spaces exists, use it.
nickjillings@1596 3683 // Otherwise, create an array by matching non-whitespace
nickjillings@1596 3684 name = camel;
nickjillings@1596 3685 name = name in cache ?
nickjillings@1596 3686 [ name ] : ( name.match( rnotwhite ) || [] );
nickjillings@1596 3687 }
nickjillings@1596 3688 }
nickjillings@1596 3689
nickjillings@1596 3690 i = name.length;
nickjillings@1596 3691 while ( i-- ) {
nickjillings@1596 3692 delete cache[ name[ i ] ];
nickjillings@1596 3693 }
nickjillings@1596 3694 }
nickjillings@1596 3695 },
nickjillings@1596 3696 hasData: function( owner ) {
nickjillings@1596 3697 return !jQuery.isEmptyObject(
nickjillings@1596 3698 this.cache[ owner[ this.expando ] ] || {}
nickjillings@1596 3699 );
nickjillings@1596 3700 },
nickjillings@1596 3701 discard: function( owner ) {
nickjillings@1596 3702 if ( owner[ this.expando ] ) {
nickjillings@1596 3703 delete this.cache[ owner[ this.expando ] ];
nickjillings@1596 3704 }
nickjillings@1596 3705 }
nickjillings@1596 3706 };
nickjillings@1596 3707 var data_priv = new Data();
nickjillings@1596 3708
nickjillings@1596 3709 var data_user = new Data();
nickjillings@1596 3710
nickjillings@1596 3711
nickjillings@1596 3712
nickjillings@1596 3713 // Implementation Summary
nickjillings@1596 3714 //
nickjillings@1596 3715 // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nickjillings@1596 3716 // 2. Improve the module's maintainability by reducing the storage
nickjillings@1596 3717 // paths to a single mechanism.
nickjillings@1596 3718 // 3. Use the same single mechanism to support "private" and "user" data.
nickjillings@1596 3719 // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nickjillings@1596 3720 // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nickjillings@1596 3721 // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nickjillings@1596 3722
nickjillings@1596 3723 var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nickjillings@1596 3724 rmultiDash = /([A-Z])/g;
nickjillings@1596 3725
nickjillings@1596 3726 function dataAttr( elem, key, data ) {
nickjillings@1596 3727 var name;
nickjillings@1596 3728
nickjillings@1596 3729 // If nothing was found internally, try to fetch any
nickjillings@1596 3730 // data from the HTML5 data-* attribute
nickjillings@1596 3731 if ( data === undefined && elem.nodeType === 1 ) {
nickjillings@1596 3732 name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nickjillings@1596 3733 data = elem.getAttribute( name );
nickjillings@1596 3734
nickjillings@1596 3735 if ( typeof data === "string" ) {
nickjillings@1596 3736 try {
nickjillings@1596 3737 data = data === "true" ? true :
nickjillings@1596 3738 data === "false" ? false :
nickjillings@1596 3739 data === "null" ? null :
nickjillings@1596 3740 // Only convert to a number if it doesn't change the string
nickjillings@1596 3741 +data + "" === data ? +data :
nickjillings@1596 3742 rbrace.test( data ) ? jQuery.parseJSON( data ) :
nickjillings@1596 3743 data;
nickjillings@1596 3744 } catch( e ) {}
nickjillings@1596 3745
nickjillings@1596 3746 // Make sure we set the data so it isn't changed later
nickjillings@1596 3747 data_user.set( elem, key, data );
nickjillings@1596 3748 } else {
nickjillings@1596 3749 data = undefined;
nickjillings@1596 3750 }
nickjillings@1596 3751 }
nickjillings@1596 3752 return data;
nickjillings@1596 3753 }
nickjillings@1596 3754
nickjillings@1596 3755 jQuery.extend({
nickjillings@1596 3756 hasData: function( elem ) {
nickjillings@1596 3757 return data_user.hasData( elem ) || data_priv.hasData( elem );
nickjillings@1596 3758 },
nickjillings@1596 3759
nickjillings@1596 3760 data: function( elem, name, data ) {
nickjillings@1596 3761 return data_user.access( elem, name, data );
nickjillings@1596 3762 },
nickjillings@1596 3763
nickjillings@1596 3764 removeData: function( elem, name ) {
nickjillings@1596 3765 data_user.remove( elem, name );
nickjillings@1596 3766 },
nickjillings@1596 3767
nickjillings@1596 3768 // TODO: Now that all calls to _data and _removeData have been replaced
nickjillings@1596 3769 // with direct calls to data_priv methods, these can be deprecated.
nickjillings@1596 3770 _data: function( elem, name, data ) {
nickjillings@1596 3771 return data_priv.access( elem, name, data );
nickjillings@1596 3772 },
nickjillings@1596 3773
nickjillings@1596 3774 _removeData: function( elem, name ) {
nickjillings@1596 3775 data_priv.remove( elem, name );
nickjillings@1596 3776 }
nickjillings@1596 3777 });
nickjillings@1596 3778
nickjillings@1596 3779 jQuery.fn.extend({
nickjillings@1596 3780 data: function( key, value ) {
nickjillings@1596 3781 var i, name, data,
nickjillings@1596 3782 elem = this[ 0 ],
nickjillings@1596 3783 attrs = elem && elem.attributes;
nickjillings@1596 3784
nickjillings@1596 3785 // Gets all values
nickjillings@1596 3786 if ( key === undefined ) {
nickjillings@1596 3787 if ( this.length ) {
nickjillings@1596 3788 data = data_user.get( elem );
nickjillings@1596 3789
nickjillings@1596 3790 if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nickjillings@1596 3791 i = attrs.length;
nickjillings@1596 3792 while ( i-- ) {
nickjillings@1596 3793
nickjillings@1596 3794 // Support: IE11+
nickjillings@1596 3795 // The attrs elements can be null (#14894)
nickjillings@1596 3796 if ( attrs[ i ] ) {
nickjillings@1596 3797 name = attrs[ i ].name;
nickjillings@1596 3798 if ( name.indexOf( "data-" ) === 0 ) {
nickjillings@1596 3799 name = jQuery.camelCase( name.slice(5) );
nickjillings@1596 3800 dataAttr( elem, name, data[ name ] );
nickjillings@1596 3801 }
nickjillings@1596 3802 }
nickjillings@1596 3803 }
nickjillings@1596 3804 data_priv.set( elem, "hasDataAttrs", true );
nickjillings@1596 3805 }
nickjillings@1596 3806 }
nickjillings@1596 3807
nickjillings@1596 3808 return data;
nickjillings@1596 3809 }
nickjillings@1596 3810
nickjillings@1596 3811 // Sets multiple values
nickjillings@1596 3812 if ( typeof key === "object" ) {
nickjillings@1596 3813 return this.each(function() {
nickjillings@1596 3814 data_user.set( this, key );
nickjillings@1596 3815 });
nickjillings@1596 3816 }
nickjillings@1596 3817
nickjillings@1596 3818 return access( this, function( value ) {
nickjillings@1596 3819 var data,
nickjillings@1596 3820 camelKey = jQuery.camelCase( key );
nickjillings@1596 3821
nickjillings@1596 3822 // The calling jQuery object (element matches) is not empty
nickjillings@1596 3823 // (and therefore has an element appears at this[ 0 ]) and the
nickjillings@1596 3824 // `value` parameter was not undefined. An empty jQuery object
nickjillings@1596 3825 // will result in `undefined` for elem = this[ 0 ] which will
nickjillings@1596 3826 // throw an exception if an attempt to read a data cache is made.
nickjillings@1596 3827 if ( elem && value === undefined ) {
nickjillings@1596 3828 // Attempt to get data from the cache
nickjillings@1596 3829 // with the key as-is
nickjillings@1596 3830 data = data_user.get( elem, key );
nickjillings@1596 3831 if ( data !== undefined ) {
nickjillings@1596 3832 return data;
nickjillings@1596 3833 }
nickjillings@1596 3834
nickjillings@1596 3835 // Attempt to get data from the cache
nickjillings@1596 3836 // with the key camelized
nickjillings@1596 3837 data = data_user.get( elem, camelKey );
nickjillings@1596 3838 if ( data !== undefined ) {
nickjillings@1596 3839 return data;
nickjillings@1596 3840 }
nickjillings@1596 3841
nickjillings@1596 3842 // Attempt to "discover" the data in
nickjillings@1596 3843 // HTML5 custom data-* attrs
nickjillings@1596 3844 data = dataAttr( elem, camelKey, undefined );
nickjillings@1596 3845 if ( data !== undefined ) {
nickjillings@1596 3846 return data;
nickjillings@1596 3847 }
nickjillings@1596 3848
nickjillings@1596 3849 // We tried really hard, but the data doesn't exist.
nickjillings@1596 3850 return;
nickjillings@1596 3851 }
nickjillings@1596 3852
nickjillings@1596 3853 // Set the data...
nickjillings@1596 3854 this.each(function() {
nickjillings@1596 3855 // First, attempt to store a copy or reference of any
nickjillings@1596 3856 // data that might've been store with a camelCased key.
nickjillings@1596 3857 var data = data_user.get( this, camelKey );
nickjillings@1596 3858
nickjillings@1596 3859 // For HTML5 data-* attribute interop, we have to
nickjillings@1596 3860 // store property names with dashes in a camelCase form.
nickjillings@1596 3861 // This might not apply to all properties...*
nickjillings@1596 3862 data_user.set( this, camelKey, value );
nickjillings@1596 3863
nickjillings@1596 3864 // *... In the case of properties that might _actually_
nickjillings@1596 3865 // have dashes, we need to also store a copy of that
nickjillings@1596 3866 // unchanged property.
nickjillings@1596 3867 if ( key.indexOf("-") !== -1 && data !== undefined ) {
nickjillings@1596 3868 data_user.set( this, key, value );
nickjillings@1596 3869 }
nickjillings@1596 3870 });
nickjillings@1596 3871 }, null, value, arguments.length > 1, null, true );
nickjillings@1596 3872 },
nickjillings@1596 3873
nickjillings@1596 3874 removeData: function( key ) {
nickjillings@1596 3875 return this.each(function() {
nickjillings@1596 3876 data_user.remove( this, key );
nickjillings@1596 3877 });
nickjillings@1596 3878 }
nickjillings@1596 3879 });
nickjillings@1596 3880
nickjillings@1596 3881
nickjillings@1596 3882 jQuery.extend({
nickjillings@1596 3883 queue: function( elem, type, data ) {
nickjillings@1596 3884 var queue;
nickjillings@1596 3885
nickjillings@1596 3886 if ( elem ) {
nickjillings@1596 3887 type = ( type || "fx" ) + "queue";
nickjillings@1596 3888 queue = data_priv.get( elem, type );
nickjillings@1596 3889
nickjillings@1596 3890 // Speed up dequeue by getting out quickly if this is just a lookup
nickjillings@1596 3891 if ( data ) {
nickjillings@1596 3892 if ( !queue || jQuery.isArray( data ) ) {
nickjillings@1596 3893 queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nickjillings@1596 3894 } else {
nickjillings@1596 3895 queue.push( data );
nickjillings@1596 3896 }
nickjillings@1596 3897 }
nickjillings@1596 3898 return queue || [];
nickjillings@1596 3899 }
nickjillings@1596 3900 },
nickjillings@1596 3901
nickjillings@1596 3902 dequeue: function( elem, type ) {
nickjillings@1596 3903 type = type || "fx";
nickjillings@1596 3904
nickjillings@1596 3905 var queue = jQuery.queue( elem, type ),
nickjillings@1596 3906 startLength = queue.length,
nickjillings@1596 3907 fn = queue.shift(),
nickjillings@1596 3908 hooks = jQuery._queueHooks( elem, type ),
nickjillings@1596 3909 next = function() {
nickjillings@1596 3910 jQuery.dequeue( elem, type );
nickjillings@1596 3911 };
nickjillings@1596 3912
nickjillings@1596 3913 // If the fx queue is dequeued, always remove the progress sentinel
nickjillings@1596 3914 if ( fn === "inprogress" ) {
nickjillings@1596 3915 fn = queue.shift();
nickjillings@1596 3916 startLength--;
nickjillings@1596 3917 }
nickjillings@1596 3918
nickjillings@1596 3919 if ( fn ) {
nickjillings@1596 3920
nickjillings@1596 3921 // Add a progress sentinel to prevent the fx queue from being
nickjillings@1596 3922 // automatically dequeued
nickjillings@1596 3923 if ( type === "fx" ) {
nickjillings@1596 3924 queue.unshift( "inprogress" );
nickjillings@1596 3925 }
nickjillings@1596 3926
nickjillings@1596 3927 // Clear up the last queue stop function
nickjillings@1596 3928 delete hooks.stop;
nickjillings@1596 3929 fn.call( elem, next, hooks );
nickjillings@1596 3930 }
nickjillings@1596 3931
nickjillings@1596 3932 if ( !startLength && hooks ) {
nickjillings@1596 3933 hooks.empty.fire();
nickjillings@1596 3934 }
nickjillings@1596 3935 },
nickjillings@1596 3936
nickjillings@1596 3937 // Not public - generate a queueHooks object, or return the current one
nickjillings@1596 3938 _queueHooks: function( elem, type ) {
nickjillings@1596 3939 var key = type + "queueHooks";
nickjillings@1596 3940 return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nickjillings@1596 3941 empty: jQuery.Callbacks("once memory").add(function() {
nickjillings@1596 3942 data_priv.remove( elem, [ type + "queue", key ] );
nickjillings@1596 3943 })
nickjillings@1596 3944 });
nickjillings@1596 3945 }
nickjillings@1596 3946 });
nickjillings@1596 3947
nickjillings@1596 3948 jQuery.fn.extend({
nickjillings@1596 3949 queue: function( type, data ) {
nickjillings@1596 3950 var setter = 2;
nickjillings@1596 3951
nickjillings@1596 3952 if ( typeof type !== "string" ) {
nickjillings@1596 3953 data = type;
nickjillings@1596 3954 type = "fx";
nickjillings@1596 3955 setter--;
nickjillings@1596 3956 }
nickjillings@1596 3957
nickjillings@1596 3958 if ( arguments.length < setter ) {
nickjillings@1596 3959 return jQuery.queue( this[0], type );
nickjillings@1596 3960 }
nickjillings@1596 3961
nickjillings@1596 3962 return data === undefined ?
nickjillings@1596 3963 this :
nickjillings@1596 3964 this.each(function() {
nickjillings@1596 3965 var queue = jQuery.queue( this, type, data );
nickjillings@1596 3966
nickjillings@1596 3967 // Ensure a hooks for this queue
nickjillings@1596 3968 jQuery._queueHooks( this, type );
nickjillings@1596 3969
nickjillings@1596 3970 if ( type === "fx" && queue[0] !== "inprogress" ) {
nickjillings@1596 3971 jQuery.dequeue( this, type );
nickjillings@1596 3972 }
nickjillings@1596 3973 });
nickjillings@1596 3974 },
nickjillings@1596 3975 dequeue: function( type ) {
nickjillings@1596 3976 return this.each(function() {
nickjillings@1596 3977 jQuery.dequeue( this, type );
nickjillings@1596 3978 });
nickjillings@1596 3979 },
nickjillings@1596 3980 clearQueue: function( type ) {
nickjillings@1596 3981 return this.queue( type || "fx", [] );
nickjillings@1596 3982 },
nickjillings@1596 3983 // Get a promise resolved when queues of a certain type
nickjillings@1596 3984 // are emptied (fx is the type by default)
nickjillings@1596 3985 promise: function( type, obj ) {
nickjillings@1596 3986 var tmp,
nickjillings@1596 3987 count = 1,
nickjillings@1596 3988 defer = jQuery.Deferred(),
nickjillings@1596 3989 elements = this,
nickjillings@1596 3990 i = this.length,
nickjillings@1596 3991 resolve = function() {
nickjillings@1596 3992 if ( !( --count ) ) {
nickjillings@1596 3993 defer.resolveWith( elements, [ elements ] );
nickjillings@1596 3994 }
nickjillings@1596 3995 };
nickjillings@1596 3996
nickjillings@1596 3997 if ( typeof type !== "string" ) {
nickjillings@1596 3998 obj = type;
nickjillings@1596 3999 type = undefined;
nickjillings@1596 4000 }
nickjillings@1596 4001 type = type || "fx";
nickjillings@1596 4002
nickjillings@1596 4003 while ( i-- ) {
nickjillings@1596 4004 tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nickjillings@1596 4005 if ( tmp && tmp.empty ) {
nickjillings@1596 4006 count++;
nickjillings@1596 4007 tmp.empty.add( resolve );
nickjillings@1596 4008 }
nickjillings@1596 4009 }
nickjillings@1596 4010 resolve();
nickjillings@1596 4011 return defer.promise( obj );
nickjillings@1596 4012 }
nickjillings@1596 4013 });
nickjillings@1596 4014 var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nickjillings@1596 4015
nickjillings@1596 4016 var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nickjillings@1596 4017
nickjillings@1596 4018 var isHidden = function( elem, el ) {
nickjillings@1596 4019 // isHidden might be called from jQuery#filter function;
nickjillings@1596 4020 // in that case, element will be second argument
nickjillings@1596 4021 elem = el || elem;
nickjillings@1596 4022 return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nickjillings@1596 4023 };
nickjillings@1596 4024
nickjillings@1596 4025 var rcheckableType = (/^(?:checkbox|radio)$/i);
nickjillings@1596 4026
nickjillings@1596 4027
nickjillings@1596 4028
nickjillings@1596 4029 (function() {
nickjillings@1596 4030 var fragment = document.createDocumentFragment(),
nickjillings@1596 4031 div = fragment.appendChild( document.createElement( "div" ) ),
nickjillings@1596 4032 input = document.createElement( "input" );
nickjillings@1596 4033
nickjillings@1596 4034 // Support: Safari<=5.1
nickjillings@1596 4035 // Check state lost if the name is set (#11217)
nickjillings@1596 4036 // Support: Windows Web Apps (WWA)
nickjillings@1596 4037 // `name` and `type` must use .setAttribute for WWA (#14901)
nickjillings@1596 4038 input.setAttribute( "type", "radio" );
nickjillings@1596 4039 input.setAttribute( "checked", "checked" );
nickjillings@1596 4040 input.setAttribute( "name", "t" );
nickjillings@1596 4041
nickjillings@1596 4042 div.appendChild( input );
nickjillings@1596 4043
nickjillings@1596 4044 // Support: Safari<=5.1, Android<4.2
nickjillings@1596 4045 // Older WebKit doesn't clone checked state correctly in fragments
nickjillings@1596 4046 support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nickjillings@1596 4047
nickjillings@1596 4048 // Support: IE<=11+
nickjillings@1596 4049 // Make sure textarea (and checkbox) defaultValue is properly cloned
nickjillings@1596 4050 div.innerHTML = "<textarea>x</textarea>";
nickjillings@1596 4051 support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nickjillings@1596 4052 })();
nickjillings@1596 4053 var strundefined = typeof undefined;
nickjillings@1596 4054
nickjillings@1596 4055
nickjillings@1596 4056
nickjillings@1596 4057 support.focusinBubbles = "onfocusin" in window;
nickjillings@1596 4058
nickjillings@1596 4059
nickjillings@1596 4060 var
nickjillings@1596 4061 rkeyEvent = /^key/,
nickjillings@1596 4062 rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nickjillings@1596 4063 rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nickjillings@1596 4064 rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nickjillings@1596 4065
nickjillings@1596 4066 function returnTrue() {
nickjillings@1596 4067 return true;
nickjillings@1596 4068 }
nickjillings@1596 4069
nickjillings@1596 4070 function returnFalse() {
nickjillings@1596 4071 return false;
nickjillings@1596 4072 }
nickjillings@1596 4073
nickjillings@1596 4074 function safeActiveElement() {
nickjillings@1596 4075 try {
nickjillings@1596 4076 return document.activeElement;
nickjillings@1596 4077 } catch ( err ) { }
nickjillings@1596 4078 }
nickjillings@1596 4079
nickjillings@1596 4080 /*
nickjillings@1596 4081 * Helper functions for managing events -- not part of the public interface.
nickjillings@1596 4082 * Props to Dean Edwards' addEvent library for many of the ideas.
nickjillings@1596 4083 */
nickjillings@1596 4084 jQuery.event = {
nickjillings@1596 4085
nickjillings@1596 4086 global: {},
nickjillings@1596 4087
nickjillings@1596 4088 add: function( elem, types, handler, data, selector ) {
nickjillings@1596 4089
nickjillings@1596 4090 var handleObjIn, eventHandle, tmp,
nickjillings@1596 4091 events, t, handleObj,
nickjillings@1596 4092 special, handlers, type, namespaces, origType,
nickjillings@1596 4093 elemData = data_priv.get( elem );
nickjillings@1596 4094
nickjillings@1596 4095 // Don't attach events to noData or text/comment nodes (but allow plain objects)
nickjillings@1596 4096 if ( !elemData ) {
nickjillings@1596 4097 return;
nickjillings@1596 4098 }
nickjillings@1596 4099
nickjillings@1596 4100 // Caller can pass in an object of custom data in lieu of the handler
nickjillings@1596 4101 if ( handler.handler ) {
nickjillings@1596 4102 handleObjIn = handler;
nickjillings@1596 4103 handler = handleObjIn.handler;
nickjillings@1596 4104 selector = handleObjIn.selector;
nickjillings@1596 4105 }
nickjillings@1596 4106
nickjillings@1596 4107 // Make sure that the handler has a unique ID, used to find/remove it later
nickjillings@1596 4108 if ( !handler.guid ) {
nickjillings@1596 4109 handler.guid = jQuery.guid++;
nickjillings@1596 4110 }
nickjillings@1596 4111
nickjillings@1596 4112 // Init the element's event structure and main handler, if this is the first
nickjillings@1596 4113 if ( !(events = elemData.events) ) {
nickjillings@1596 4114 events = elemData.events = {};
nickjillings@1596 4115 }
nickjillings@1596 4116 if ( !(eventHandle = elemData.handle) ) {
nickjillings@1596 4117 eventHandle = elemData.handle = function( e ) {
nickjillings@1596 4118 // Discard the second event of a jQuery.event.trigger() and
nickjillings@1596 4119 // when an event is called after a page has unloaded
nickjillings@1596 4120 return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nickjillings@1596 4121 jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nickjillings@1596 4122 };
nickjillings@1596 4123 }
nickjillings@1596 4124
nickjillings@1596 4125 // Handle multiple events separated by a space
nickjillings@1596 4126 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1596 4127 t = types.length;
nickjillings@1596 4128 while ( t-- ) {
nickjillings@1596 4129 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1596 4130 type = origType = tmp[1];
nickjillings@1596 4131 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1596 4132
nickjillings@1596 4133 // There *must* be a type, no attaching namespace-only handlers
nickjillings@1596 4134 if ( !type ) {
nickjillings@1596 4135 continue;
nickjillings@1596 4136 }
nickjillings@1596 4137
nickjillings@1596 4138 // If event changes its type, use the special event handlers for the changed type
nickjillings@1596 4139 special = jQuery.event.special[ type ] || {};
nickjillings@1596 4140
nickjillings@1596 4141 // If selector defined, determine special event api type, otherwise given type
nickjillings@1596 4142 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1596 4143
nickjillings@1596 4144 // Update special based on newly reset type
nickjillings@1596 4145 special = jQuery.event.special[ type ] || {};
nickjillings@1596 4146
nickjillings@1596 4147 // handleObj is passed to all event handlers
nickjillings@1596 4148 handleObj = jQuery.extend({
nickjillings@1596 4149 type: type,
nickjillings@1596 4150 origType: origType,
nickjillings@1596 4151 data: data,
nickjillings@1596 4152 handler: handler,
nickjillings@1596 4153 guid: handler.guid,
nickjillings@1596 4154 selector: selector,
nickjillings@1596 4155 needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nickjillings@1596 4156 namespace: namespaces.join(".")
nickjillings@1596 4157 }, handleObjIn );
nickjillings@1596 4158
nickjillings@1596 4159 // Init the event handler queue if we're the first
nickjillings@1596 4160 if ( !(handlers = events[ type ]) ) {
nickjillings@1596 4161 handlers = events[ type ] = [];
nickjillings@1596 4162 handlers.delegateCount = 0;
nickjillings@1596 4163
nickjillings@1596 4164 // Only use addEventListener if the special events handler returns false
nickjillings@1596 4165 if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nickjillings@1596 4166 if ( elem.addEventListener ) {
nickjillings@1596 4167 elem.addEventListener( type, eventHandle, false );
nickjillings@1596 4168 }
nickjillings@1596 4169 }
nickjillings@1596 4170 }
nickjillings@1596 4171
nickjillings@1596 4172 if ( special.add ) {
nickjillings@1596 4173 special.add.call( elem, handleObj );
nickjillings@1596 4174
nickjillings@1596 4175 if ( !handleObj.handler.guid ) {
nickjillings@1596 4176 handleObj.handler.guid = handler.guid;
nickjillings@1596 4177 }
nickjillings@1596 4178 }
nickjillings@1596 4179
nickjillings@1596 4180 // Add to the element's handler list, delegates in front
nickjillings@1596 4181 if ( selector ) {
nickjillings@1596 4182 handlers.splice( handlers.delegateCount++, 0, handleObj );
nickjillings@1596 4183 } else {
nickjillings@1596 4184 handlers.push( handleObj );
nickjillings@1596 4185 }
nickjillings@1596 4186
nickjillings@1596 4187 // Keep track of which events have ever been used, for event optimization
nickjillings@1596 4188 jQuery.event.global[ type ] = true;
nickjillings@1596 4189 }
nickjillings@1596 4190
nickjillings@1596 4191 },
nickjillings@1596 4192
nickjillings@1596 4193 // Detach an event or set of events from an element
nickjillings@1596 4194 remove: function( elem, types, handler, selector, mappedTypes ) {
nickjillings@1596 4195
nickjillings@1596 4196 var j, origCount, tmp,
nickjillings@1596 4197 events, t, handleObj,
nickjillings@1596 4198 special, handlers, type, namespaces, origType,
nickjillings@1596 4199 elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nickjillings@1596 4200
nickjillings@1596 4201 if ( !elemData || !(events = elemData.events) ) {
nickjillings@1596 4202 return;
nickjillings@1596 4203 }
nickjillings@1596 4204
nickjillings@1596 4205 // Once for each type.namespace in types; type may be omitted
nickjillings@1596 4206 types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1596 4207 t = types.length;
nickjillings@1596 4208 while ( t-- ) {
nickjillings@1596 4209 tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1596 4210 type = origType = tmp[1];
nickjillings@1596 4211 namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1596 4212
nickjillings@1596 4213 // Unbind all events (on this namespace, if provided) for the element
nickjillings@1596 4214 if ( !type ) {
nickjillings@1596 4215 for ( type in events ) {
nickjillings@1596 4216 jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nickjillings@1596 4217 }
nickjillings@1596 4218 continue;
nickjillings@1596 4219 }
nickjillings@1596 4220
nickjillings@1596 4221 special = jQuery.event.special[ type ] || {};
nickjillings@1596 4222 type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1596 4223 handlers = events[ type ] || [];
nickjillings@1596 4224 tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nickjillings@1596 4225
nickjillings@1596 4226 // Remove matching events
nickjillings@1596 4227 origCount = j = handlers.length;
nickjillings@1596 4228 while ( j-- ) {
nickjillings@1596 4229 handleObj = handlers[ j ];
nickjillings@1596 4230
nickjillings@1596 4231 if ( ( mappedTypes || origType === handleObj.origType ) &&
nickjillings@1596 4232 ( !handler || handler.guid === handleObj.guid ) &&
nickjillings@1596 4233 ( !tmp || tmp.test( handleObj.namespace ) ) &&
nickjillings@1596 4234 ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nickjillings@1596 4235 handlers.splice( j, 1 );
nickjillings@1596 4236
nickjillings@1596 4237 if ( handleObj.selector ) {
nickjillings@1596 4238 handlers.delegateCount--;
nickjillings@1596 4239 }
nickjillings@1596 4240 if ( special.remove ) {
nickjillings@1596 4241 special.remove.call( elem, handleObj );
nickjillings@1596 4242 }
nickjillings@1596 4243 }
nickjillings@1596 4244 }
nickjillings@1596 4245
nickjillings@1596 4246 // Remove generic event handler if we removed something and no more handlers exist
nickjillings@1596 4247 // (avoids potential for endless recursion during removal of special event handlers)
nickjillings@1596 4248 if ( origCount && !handlers.length ) {
nickjillings@1596 4249 if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nickjillings@1596 4250 jQuery.removeEvent( elem, type, elemData.handle );
nickjillings@1596 4251 }
nickjillings@1596 4252
nickjillings@1596 4253 delete events[ type ];
nickjillings@1596 4254 }
nickjillings@1596 4255 }
nickjillings@1596 4256
nickjillings@1596 4257 // Remove the expando if it's no longer used
nickjillings@1596 4258 if ( jQuery.isEmptyObject( events ) ) {
nickjillings@1596 4259 delete elemData.handle;
nickjillings@1596 4260 data_priv.remove( elem, "events" );
nickjillings@1596 4261 }
nickjillings@1596 4262 },
nickjillings@1596 4263
nickjillings@1596 4264 trigger: function( event, data, elem, onlyHandlers ) {
nickjillings@1596 4265
nickjillings@1596 4266 var i, cur, tmp, bubbleType, ontype, handle, special,
nickjillings@1596 4267 eventPath = [ elem || document ],
nickjillings@1596 4268 type = hasOwn.call( event, "type" ) ? event.type : event,
nickjillings@1596 4269 namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nickjillings@1596 4270
nickjillings@1596 4271 cur = tmp = elem = elem || document;
nickjillings@1596 4272
nickjillings@1596 4273 // Don't do events on text and comment nodes
nickjillings@1596 4274 if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nickjillings@1596 4275 return;
nickjillings@1596 4276 }
nickjillings@1596 4277
nickjillings@1596 4278 // focus/blur morphs to focusin/out; ensure we're not firing them right now
nickjillings@1596 4279 if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nickjillings@1596 4280 return;
nickjillings@1596 4281 }
nickjillings@1596 4282
nickjillings@1596 4283 if ( type.indexOf(".") >= 0 ) {
nickjillings@1596 4284 // Namespaced trigger; create a regexp to match event type in handle()
nickjillings@1596 4285 namespaces = type.split(".");
nickjillings@1596 4286 type = namespaces.shift();
nickjillings@1596 4287 namespaces.sort();
nickjillings@1596 4288 }
nickjillings@1596 4289 ontype = type.indexOf(":") < 0 && "on" + type;
nickjillings@1596 4290
nickjillings@1596 4291 // Caller can pass in a jQuery.Event object, Object, or just an event type string
nickjillings@1596 4292 event = event[ jQuery.expando ] ?
nickjillings@1596 4293 event :
nickjillings@1596 4294 new jQuery.Event( type, typeof event === "object" && event );
nickjillings@1596 4295
nickjillings@1596 4296 // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nickjillings@1596 4297 event.isTrigger = onlyHandlers ? 2 : 3;
nickjillings@1596 4298 event.namespace = namespaces.join(".");
nickjillings@1596 4299 event.namespace_re = event.namespace ?
nickjillings@1596 4300 new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nickjillings@1596 4301 null;
nickjillings@1596 4302
nickjillings@1596 4303 // Clean up the event in case it is being reused
nickjillings@1596 4304 event.result = undefined;
nickjillings@1596 4305 if ( !event.target ) {
nickjillings@1596 4306 event.target = elem;
nickjillings@1596 4307 }
nickjillings@1596 4308
nickjillings@1596 4309 // Clone any incoming data and prepend the event, creating the handler arg list
nickjillings@1596 4310 data = data == null ?
nickjillings@1596 4311 [ event ] :
nickjillings@1596 4312 jQuery.makeArray( data, [ event ] );
nickjillings@1596 4313
nickjillings@1596 4314 // Allow special events to draw outside the lines
nickjillings@1596 4315 special = jQuery.event.special[ type ] || {};
nickjillings@1596 4316 if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nickjillings@1596 4317 return;
nickjillings@1596 4318 }
nickjillings@1596 4319
nickjillings@1596 4320 // Determine event propagation path in advance, per W3C events spec (#9951)
nickjillings@1596 4321 // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nickjillings@1596 4322 if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nickjillings@1596 4323
nickjillings@1596 4324 bubbleType = special.delegateType || type;
nickjillings@1596 4325 if ( !rfocusMorph.test( bubbleType + type ) ) {
nickjillings@1596 4326 cur = cur.parentNode;
nickjillings@1596 4327 }
nickjillings@1596 4328 for ( ; cur; cur = cur.parentNode ) {
nickjillings@1596 4329 eventPath.push( cur );
nickjillings@1596 4330 tmp = cur;
nickjillings@1596 4331 }
nickjillings@1596 4332
nickjillings@1596 4333 // Only add window if we got to document (e.g., not plain obj or detached DOM)
nickjillings@1596 4334 if ( tmp === (elem.ownerDocument || document) ) {
nickjillings@1596 4335 eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nickjillings@1596 4336 }
nickjillings@1596 4337 }
nickjillings@1596 4338
nickjillings@1596 4339 // Fire handlers on the event path
nickjillings@1596 4340 i = 0;
nickjillings@1596 4341 while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nickjillings@1596 4342
nickjillings@1596 4343 event.type = i > 1 ?
nickjillings@1596 4344 bubbleType :
nickjillings@1596 4345 special.bindType || type;
nickjillings@1596 4346
nickjillings@1596 4347 // jQuery handler
nickjillings@1596 4348 handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nickjillings@1596 4349 if ( handle ) {
nickjillings@1596 4350 handle.apply( cur, data );
nickjillings@1596 4351 }
nickjillings@1596 4352
nickjillings@1596 4353 // Native handler
nickjillings@1596 4354 handle = ontype && cur[ ontype ];
nickjillings@1596 4355 if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nickjillings@1596 4356 event.result = handle.apply( cur, data );
nickjillings@1596 4357 if ( event.result === false ) {
nickjillings@1596 4358 event.preventDefault();
nickjillings@1596 4359 }
nickjillings@1596 4360 }
nickjillings@1596 4361 }
nickjillings@1596 4362 event.type = type;
nickjillings@1596 4363
nickjillings@1596 4364 // If nobody prevented the default action, do it now
nickjillings@1596 4365 if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nickjillings@1596 4366
nickjillings@1596 4367 if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nickjillings@1596 4368 jQuery.acceptData( elem ) ) {
nickjillings@1596 4369
nickjillings@1596 4370 // Call a native DOM method on the target with the same name name as the event.
nickjillings@1596 4371 // Don't do default actions on window, that's where global variables be (#6170)
nickjillings@1596 4372 if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nickjillings@1596 4373
nickjillings@1596 4374 // Don't re-trigger an onFOO event when we call its FOO() method
nickjillings@1596 4375 tmp = elem[ ontype ];
nickjillings@1596 4376
nickjillings@1596 4377 if ( tmp ) {
nickjillings@1596 4378 elem[ ontype ] = null;
nickjillings@1596 4379 }
nickjillings@1596 4380
nickjillings@1596 4381 // Prevent re-triggering of the same event, since we already bubbled it above
nickjillings@1596 4382 jQuery.event.triggered = type;
nickjillings@1596 4383 elem[ type ]();
nickjillings@1596 4384 jQuery.event.triggered = undefined;
nickjillings@1596 4385
nickjillings@1596 4386 if ( tmp ) {
nickjillings@1596 4387 elem[ ontype ] = tmp;
nickjillings@1596 4388 }
nickjillings@1596 4389 }
nickjillings@1596 4390 }
nickjillings@1596 4391 }
nickjillings@1596 4392
nickjillings@1596 4393 return event.result;
nickjillings@1596 4394 },
nickjillings@1596 4395
nickjillings@1596 4396 dispatch: function( event ) {
nickjillings@1596 4397
nickjillings@1596 4398 // Make a writable jQuery.Event from the native event object
nickjillings@1596 4399 event = jQuery.event.fix( event );
nickjillings@1596 4400
nickjillings@1596 4401 var i, j, ret, matched, handleObj,
nickjillings@1596 4402 handlerQueue = [],
nickjillings@1596 4403 args = slice.call( arguments ),
nickjillings@1596 4404 handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nickjillings@1596 4405 special = jQuery.event.special[ event.type ] || {};
nickjillings@1596 4406
nickjillings@1596 4407 // Use the fix-ed jQuery.Event rather than the (read-only) native event
nickjillings@1596 4408 args[0] = event;
nickjillings@1596 4409 event.delegateTarget = this;
nickjillings@1596 4410
nickjillings@1596 4411 // Call the preDispatch hook for the mapped type, and let it bail if desired
nickjillings@1596 4412 if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nickjillings@1596 4413 return;
nickjillings@1596 4414 }
nickjillings@1596 4415
nickjillings@1596 4416 // Determine handlers
nickjillings@1596 4417 handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nickjillings@1596 4418
nickjillings@1596 4419 // Run delegates first; they may want to stop propagation beneath us
nickjillings@1596 4420 i = 0;
nickjillings@1596 4421 while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nickjillings@1596 4422 event.currentTarget = matched.elem;
nickjillings@1596 4423
nickjillings@1596 4424 j = 0;
nickjillings@1596 4425 while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nickjillings@1596 4426
nickjillings@1596 4427 // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nickjillings@1596 4428 // a subset or equal to those in the bound event (both can have no namespace).
nickjillings@1596 4429 if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nickjillings@1596 4430
nickjillings@1596 4431 event.handleObj = handleObj;
nickjillings@1596 4432 event.data = handleObj.data;
nickjillings@1596 4433
nickjillings@1596 4434 ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nickjillings@1596 4435 .apply( matched.elem, args );
nickjillings@1596 4436
nickjillings@1596 4437 if ( ret !== undefined ) {
nickjillings@1596 4438 if ( (event.result = ret) === false ) {
nickjillings@1596 4439 event.preventDefault();
nickjillings@1596 4440 event.stopPropagation();
nickjillings@1596 4441 }
nickjillings@1596 4442 }
nickjillings@1596 4443 }
nickjillings@1596 4444 }
nickjillings@1596 4445 }
nickjillings@1596 4446
nickjillings@1596 4447 // Call the postDispatch hook for the mapped type
nickjillings@1596 4448 if ( special.postDispatch ) {
nickjillings@1596 4449 special.postDispatch.call( this, event );
nickjillings@1596 4450 }
nickjillings@1596 4451
nickjillings@1596 4452 return event.result;
nickjillings@1596 4453 },
nickjillings@1596 4454
nickjillings@1596 4455 handlers: function( event, handlers ) {
nickjillings@1596 4456 var i, matches, sel, handleObj,
nickjillings@1596 4457 handlerQueue = [],
nickjillings@1596 4458 delegateCount = handlers.delegateCount,
nickjillings@1596 4459 cur = event.target;
nickjillings@1596 4460
nickjillings@1596 4461 // Find delegate handlers
nickjillings@1596 4462 // Black-hole SVG <use> instance trees (#13180)
nickjillings@1596 4463 // Avoid non-left-click bubbling in Firefox (#3861)
nickjillings@1596 4464 if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) {
nickjillings@1596 4465
nickjillings@1596 4466 for ( ; cur !== this; cur = cur.parentNode || this ) {
nickjillings@1596 4467
nickjillings@1596 4468 // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
nickjillings@1596 4469 if ( cur.disabled !== true || event.type !== "click" ) {
nickjillings@1596 4470 matches = [];
nickjillings@1596 4471 for ( i = 0; i < delegateCount; i++ ) {
nickjillings@1596 4472 handleObj = handlers[ i ];
nickjillings@1596 4473
nickjillings@1596 4474 // Don't conflict with Object.prototype properties (#13203)
nickjillings@1596 4475 sel = handleObj.selector + " ";
nickjillings@1596 4476
nickjillings@1596 4477 if ( matches[ sel ] === undefined ) {
nickjillings@1596 4478 matches[ sel ] = handleObj.needsContext ?
nickjillings@1596 4479 jQuery( sel, this ).index( cur ) >= 0 :
nickjillings@1596 4480 jQuery.find( sel, this, null, [ cur ] ).length;
nickjillings@1596 4481 }
nickjillings@1596 4482 if ( matches[ sel ] ) {
nickjillings@1596 4483 matches.push( handleObj );
nickjillings@1596 4484 }
nickjillings@1596 4485 }
nickjillings@1596 4486 if ( matches.length ) {
nickjillings@1596 4487 handlerQueue.push({ elem: cur, handlers: matches });
nickjillings@1596 4488 }
nickjillings@1596 4489 }
nickjillings@1596 4490 }
nickjillings@1596 4491 }
nickjillings@1596 4492
nickjillings@1596 4493 // Add the remaining (directly-bound) handlers
nickjillings@1596 4494 if ( delegateCount < handlers.length ) {
nickjillings@1596 4495 handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) });
nickjillings@1596 4496 }
nickjillings@1596 4497
nickjillings@1596 4498 return handlerQueue;
nickjillings@1596 4499 },
nickjillings@1596 4500
nickjillings@1596 4501 // Includes some event props shared by KeyEvent and MouseEvent
nickjillings@1596 4502 props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),
nickjillings@1596 4503
nickjillings@1596 4504 fixHooks: {},
nickjillings@1596 4505
nickjillings@1596 4506 keyHooks: {
nickjillings@1596 4507 props: "char charCode key keyCode".split(" "),
nickjillings@1596 4508 filter: function( event, original ) {
nickjillings@1596 4509
nickjillings@1596 4510 // Add which for key events
nickjillings@1596 4511 if ( event.which == null ) {
nickjillings@1596 4512 event.which = original.charCode != null ? original.charCode : original.keyCode;
nickjillings@1596 4513 }
nickjillings@1596 4514
nickjillings@1596 4515 return event;
nickjillings@1596 4516 }
nickjillings@1596 4517 },
nickjillings@1596 4518
nickjillings@1596 4519 mouseHooks: {
nickjillings@1596 4520 props: "button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),
nickjillings@1596 4521 filter: function( event, original ) {
nickjillings@1596 4522 var eventDoc, doc, body,
nickjillings@1596 4523 button = original.button;
nickjillings@1596 4524
nickjillings@1596 4525 // Calculate pageX/Y if missing and clientX/Y available
nickjillings@1596 4526 if ( event.pageX == null && original.clientX != null ) {
nickjillings@1596 4527 eventDoc = event.target.ownerDocument || document;
nickjillings@1596 4528 doc = eventDoc.documentElement;
nickjillings@1596 4529 body = eventDoc.body;
nickjillings@1596 4530
nickjillings@1596 4531 event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 );
nickjillings@1596 4532 event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 );
nickjillings@1596 4533 }
nickjillings@1596 4534
nickjillings@1596 4535 // Add which for click: 1 === left; 2 === middle; 3 === right
nickjillings@1596 4536 // Note: button is not normalized, so don't use it
nickjillings@1596 4537 if ( !event.which && button !== undefined ) {
nickjillings@1596 4538 event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
nickjillings@1596 4539 }
nickjillings@1596 4540
nickjillings@1596 4541 return event;
nickjillings@1596 4542 }
nickjillings@1596 4543 },
nickjillings@1596 4544
nickjillings@1596 4545 fix: function( event ) {
nickjillings@1596 4546 if ( event[ jQuery.expando ] ) {
nickjillings@1596 4547 return event;
nickjillings@1596 4548 }
nickjillings@1596 4549
nickjillings@1596 4550 // Create a writable copy of the event object and normalize some properties
nickjillings@1596 4551 var i, prop, copy,
nickjillings@1596 4552 type = event.type,
nickjillings@1596 4553 originalEvent = event,
nickjillings@1596 4554 fixHook = this.fixHooks[ type ];
nickjillings@1596 4555
nickjillings@1596 4556 if ( !fixHook ) {
nickjillings@1596 4557 this.fixHooks[ type ] = fixHook =
nickjillings@1596 4558 rmouseEvent.test( type ) ? this.mouseHooks :
nickjillings@1596 4559 rkeyEvent.test( type ) ? this.keyHooks :
nickjillings@1596 4560 {};
nickjillings@1596 4561 }
nickjillings@1596 4562 copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
nickjillings@1596 4563
nickjillings@1596 4564 event = new jQuery.Event( originalEvent );
nickjillings@1596 4565
nickjillings@1596 4566 i = copy.length;
nickjillings@1596 4567 while ( i-- ) {
nickjillings@1596 4568 prop = copy[ i ];
nickjillings@1596 4569 event[ prop ] = originalEvent[ prop ];
nickjillings@1596 4570 }
nickjillings@1596 4571
nickjillings@1596 4572 // Support: Cordova 2.5 (WebKit) (#13255)
nickjillings@1596 4573 // All events should have a target; Cordova deviceready doesn't
nickjillings@1596 4574 if ( !event.target ) {
nickjillings@1596 4575 event.target = document;
nickjillings@1596 4576 }
nickjillings@1596 4577
nickjillings@1596 4578 // Support: Safari 6.0+, Chrome<28
nickjillings@1596 4579 // Target should not be a text node (#504, #13143)
nickjillings@1596 4580 if ( event.target.nodeType === 3 ) {
nickjillings@1596 4581 event.target = event.target.parentNode;
nickjillings@1596 4582 }
nickjillings@1596 4583
nickjillings@1596 4584 return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
nickjillings@1596 4585 },
nickjillings@1596 4586
nickjillings@1596 4587 special: {
nickjillings@1596 4588 load: {
nickjillings@1596 4589 // Prevent triggered image.load events from bubbling to window.load
nickjillings@1596 4590 noBubble: true
nickjillings@1596 4591 },
nickjillings@1596 4592 focus: {
nickjillings@1596 4593 // Fire native event if possible so blur/focus sequence is correct
nickjillings@1596 4594 trigger: function() {
nickjillings@1596 4595 if ( this !== safeActiveElement() && this.focus ) {
nickjillings@1596 4596 this.focus();
nickjillings@1596 4597 return false;
nickjillings@1596 4598 }
nickjillings@1596 4599 },
nickjillings@1596 4600 delegateType: "focusin"
nickjillings@1596 4601 },
nickjillings@1596 4602 blur: {
nickjillings@1596 4603 trigger: function() {
nickjillings@1596 4604 if ( this === safeActiveElement() && this.blur ) {
nickjillings@1596 4605 this.blur();
nickjillings@1596 4606 return false;
nickjillings@1596 4607 }
nickjillings@1596 4608 },
nickjillings@1596 4609 delegateType: "focusout"
nickjillings@1596 4610 },
nickjillings@1596 4611 click: {
nickjillings@1596 4612 // For checkbox, fire native event so checked state will be right
nickjillings@1596 4613 trigger: function() {
nickjillings@1596 4614 if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
nickjillings@1596 4615 this.click();
nickjillings@1596 4616 return false;
nickjillings@1596 4617 }
nickjillings@1596 4618 },
nickjillings@1596 4619
nickjillings@1596 4620 // For cross-browser consistency, don't fire native .click() on links
nickjillings@1596 4621 _default: function( event ) {
nickjillings@1596 4622 return jQuery.nodeName( event.target, "a" );
nickjillings@1596 4623 }
nickjillings@1596 4624 },
nickjillings@1596 4625
nickjillings@1596 4626 beforeunload: {
nickjillings@1596 4627 postDispatch: function( event ) {
nickjillings@1596 4628
nickjillings@1596 4629 // Support: Firefox 20+
nickjillings@1596 4630 // Firefox doesn't alert if the returnValue field is not set.
nickjillings@1596 4631 if ( event.result !== undefined && event.originalEvent ) {
nickjillings@1596 4632 event.originalEvent.returnValue = event.result;
nickjillings@1596 4633 }
nickjillings@1596 4634 }
nickjillings@1596 4635 }
nickjillings@1596 4636 },
nickjillings@1596 4637
nickjillings@1596 4638 simulate: function( type, elem, event, bubble ) {
nickjillings@1596 4639 // Piggyback on a donor event to simulate a different one.
nickjillings@1596 4640 // Fake originalEvent to avoid donor's stopPropagation, but if the
nickjillings@1596 4641 // simulated event prevents default then we do the same on the donor.
nickjillings@1596 4642 var e = jQuery.extend(
nickjillings@1596 4643 new jQuery.Event(),
nickjillings@1596 4644 event,
nickjillings@1596 4645 {
nickjillings@1596 4646 type: type,
nickjillings@1596 4647 isSimulated: true,
nickjillings@1596 4648 originalEvent: {}
nickjillings@1596 4649 }
nickjillings@1596 4650 );
nickjillings@1596 4651 if ( bubble ) {
nickjillings@1596 4652 jQuery.event.trigger( e, null, elem );
nickjillings@1596 4653 } else {
nickjillings@1596 4654 jQuery.event.dispatch.call( elem, e );
nickjillings@1596 4655 }
nickjillings@1596 4656 if ( e.isDefaultPrevented() ) {
nickjillings@1596 4657 event.preventDefault();
nickjillings@1596 4658 }
nickjillings@1596 4659 }
nickjillings@1596 4660 };
nickjillings@1596 4661
nickjillings@1596 4662 jQuery.removeEvent = function( elem, type, handle ) {
nickjillings@1596 4663 if ( elem.removeEventListener ) {
nickjillings@1596 4664 elem.removeEventListener( type, handle, false );
nickjillings@1596 4665 }
nickjillings@1596 4666 };
nickjillings@1596 4667
nickjillings@1596 4668 jQuery.Event = function( src, props ) {
nickjillings@1596 4669 // Allow instantiation without the 'new' keyword
nickjillings@1596 4670 if ( !(this instanceof jQuery.Event) ) {
nickjillings@1596 4671 return new jQuery.Event( src, props );
nickjillings@1596 4672 }
nickjillings@1596 4673
nickjillings@1596 4674 // Event object
nickjillings@1596 4675 if ( src && src.type ) {
nickjillings@1596 4676 this.originalEvent = src;
nickjillings@1596 4677 this.type = src.type;
nickjillings@1596 4678
nickjillings@1596 4679 // Events bubbling up the document may have been marked as prevented
nickjillings@1596 4680 // by a handler lower down the tree; reflect the correct value.
nickjillings@1596 4681 this.isDefaultPrevented = src.defaultPrevented ||
nickjillings@1596 4682 src.defaultPrevented === undefined &&
nickjillings@1596 4683 // Support: Android<4.0
nickjillings@1596 4684 src.returnValue === false ?
nickjillings@1596 4685 returnTrue :
nickjillings@1596 4686 returnFalse;
nickjillings@1596 4687
nickjillings@1596 4688 // Event type
nickjillings@1596 4689 } else {
nickjillings@1596 4690 this.type = src;
nickjillings@1596 4691 }
nickjillings@1596 4692
nickjillings@1596 4693 // Put explicitly provided properties onto the event object
nickjillings@1596 4694 if ( props ) {
nickjillings@1596 4695 jQuery.extend( this, props );
nickjillings@1596 4696 }
nickjillings@1596 4697
nickjillings@1596 4698 // Create a timestamp if incoming event doesn't have one
nickjillings@1596 4699 this.timeStamp = src && src.timeStamp || jQuery.now();
nickjillings@1596 4700
nickjillings@1596 4701 // Mark it as fixed
nickjillings@1596 4702 this[ jQuery.expando ] = true;
nickjillings@1596 4703 };
nickjillings@1596 4704
nickjillings@1596 4705 // jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
nickjillings@1596 4706 // http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
nickjillings@1596 4707 jQuery.Event.prototype = {
nickjillings@1596 4708 isDefaultPrevented: returnFalse,
nickjillings@1596 4709 isPropagationStopped: returnFalse,
nickjillings@1596 4710 isImmediatePropagationStopped: returnFalse,
nickjillings@1596 4711
nickjillings@1596 4712 preventDefault: function() {
nickjillings@1596 4713 var e = this.originalEvent;
nickjillings@1596 4714
nickjillings@1596 4715 this.isDefaultPrevented = returnTrue;
nickjillings@1596 4716
nickjillings@1596 4717 if ( e && e.preventDefault ) {
nickjillings@1596 4718 e.preventDefault();
nickjillings@1596 4719 }
nickjillings@1596 4720 },
nickjillings@1596 4721 stopPropagation: function() {
nickjillings@1596 4722 var e = this.originalEvent;
nickjillings@1596 4723
nickjillings@1596 4724 this.isPropagationStopped = returnTrue;
nickjillings@1596 4725
nickjillings@1596 4726 if ( e && e.stopPropagation ) {
nickjillings@1596 4727 e.stopPropagation();
nickjillings@1596 4728 }
nickjillings@1596 4729 },
nickjillings@1596 4730 stopImmediatePropagation: function() {
nickjillings@1596 4731 var e = this.originalEvent;
nickjillings@1596 4732
nickjillings@1596 4733 this.isImmediatePropagationStopped = returnTrue;
nickjillings@1596 4734
nickjillings@1596 4735 if ( e && e.stopImmediatePropagation ) {
nickjillings@1596 4736 e.stopImmediatePropagation();
nickjillings@1596 4737 }
nickjillings@1596 4738
nickjillings@1596 4739 this.stopPropagation();
nickjillings@1596 4740 }
nickjillings@1596 4741 };
nickjillings@1596 4742
nickjillings@1596 4743 // Create mouseenter/leave events using mouseover/out and event-time checks
nickjillings@1596 4744 // Support: Chrome 15+
nickjillings@1596 4745 jQuery.each({
nickjillings@1596 4746 mouseenter: "mouseover",
nickjillings@1596 4747 mouseleave: "mouseout",
nickjillings@1596 4748 pointerenter: "pointerover",
nickjillings@1596 4749 pointerleave: "pointerout"
nickjillings@1596 4750 }, function( orig, fix ) {
nickjillings@1596 4751 jQuery.event.special[ orig ] = {
nickjillings@1596 4752 delegateType: fix,
nickjillings@1596 4753 bindType: fix,
nickjillings@1596 4754
nickjillings@1596 4755 handle: function( event ) {
nickjillings@1596 4756 var ret,
nickjillings@1596 4757 target = this,
nickjillings@1596 4758 related = event.relatedTarget,
nickjillings@1596 4759 handleObj = event.handleObj;
nickjillings@1596 4760
nickjillings@1596 4761 // For mousenter/leave call the handler if related is outside the target.
nickjillings@1596 4762 // NB: No relatedTarget if the mouse left/entered the browser window
nickjillings@1596 4763 if ( !related || (related !== target && !jQuery.contains( target, related )) ) {
nickjillings@1596 4764 event.type = handleObj.origType;
nickjillings@1596 4765 ret = handleObj.handler.apply( this, arguments );
nickjillings@1596 4766 event.type = fix;
nickjillings@1596 4767 }
nickjillings@1596 4768 return ret;
nickjillings@1596 4769 }
nickjillings@1596 4770 };
nickjillings@1596 4771 });
nickjillings@1596 4772
nickjillings@1596 4773 // Support: Firefox, Chrome, Safari
nickjillings@1596 4774 // Create "bubbling" focus and blur events
nickjillings@1596 4775 if ( !support.focusinBubbles ) {
nickjillings@1596 4776 jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) {
nickjillings@1596 4777
nickjillings@1596 4778 // Attach a single capturing handler on the document while someone wants focusin/focusout
nickjillings@1596 4779 var handler = function( event ) {
nickjillings@1596 4780 jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true );
nickjillings@1596 4781 };
nickjillings@1596 4782
nickjillings@1596 4783 jQuery.event.special[ fix ] = {
nickjillings@1596 4784 setup: function() {
nickjillings@1596 4785 var doc = this.ownerDocument || this,
nickjillings@1596 4786 attaches = data_priv.access( doc, fix );
nickjillings@1596 4787
nickjillings@1596 4788 if ( !attaches ) {
nickjillings@1596 4789 doc.addEventListener( orig, handler, true );
nickjillings@1596 4790 }
nickjillings@1596 4791 data_priv.access( doc, fix, ( attaches || 0 ) + 1 );
nickjillings@1596 4792 },
nickjillings@1596 4793 teardown: function() {
nickjillings@1596 4794 var doc = this.ownerDocument || this,
nickjillings@1596 4795 attaches = data_priv.access( doc, fix ) - 1;
nickjillings@1596 4796
nickjillings@1596 4797 if ( !attaches ) {
nickjillings@1596 4798 doc.removeEventListener( orig, handler, true );
nickjillings@1596 4799 data_priv.remove( doc, fix );
nickjillings@1596 4800
nickjillings@1596 4801 } else {
nickjillings@1596 4802 data_priv.access( doc, fix, attaches );
nickjillings@1596 4803 }
nickjillings@1596 4804 }
nickjillings@1596 4805 };
nickjillings@1596 4806 });
nickjillings@1596 4807 }
nickjillings@1596 4808
nickjillings@1596 4809 jQuery.fn.extend({
nickjillings@1596 4810
nickjillings@1596 4811 on: function( types, selector, data, fn, /*INTERNAL*/ one ) {
nickjillings@1596 4812 var origFn, type;
nickjillings@1596 4813
nickjillings@1596 4814 // Types can be a map of types/handlers
nickjillings@1596 4815 if ( typeof types === "object" ) {
nickjillings@1596 4816 // ( types-Object, selector, data )
nickjillings@1596 4817 if ( typeof selector !== "string" ) {
nickjillings@1596 4818 // ( types-Object, data )
nickjillings@1596 4819 data = data || selector;
nickjillings@1596 4820 selector = undefined;
nickjillings@1596 4821 }
nickjillings@1596 4822 for ( type in types ) {
nickjillings@1596 4823 this.on( type, selector, data, types[ type ], one );
nickjillings@1596 4824 }
nickjillings@1596 4825 return this;
nickjillings@1596 4826 }
nickjillings@1596 4827
nickjillings@1596 4828 if ( data == null && fn == null ) {
nickjillings@1596 4829 // ( types, fn )
nickjillings@1596 4830 fn = selector;
nickjillings@1596 4831 data = selector = undefined;
nickjillings@1596 4832 } else if ( fn == null ) {
nickjillings@1596 4833 if ( typeof selector === "string" ) {
nickjillings@1596 4834 // ( types, selector, fn )
nickjillings@1596 4835 fn = data;
nickjillings@1596 4836 data = undefined;
nickjillings@1596 4837 } else {
nickjillings@1596 4838 // ( types, data, fn )
nickjillings@1596 4839 fn = data;
nickjillings@1596 4840 data = selector;
nickjillings@1596 4841 selector = undefined;
nickjillings@1596 4842 }
nickjillings@1596 4843 }
nickjillings@1596 4844 if ( fn === false ) {
nickjillings@1596 4845 fn = returnFalse;
nickjillings@1596 4846 } else if ( !fn ) {
nickjillings@1596 4847 return this;
nickjillings@1596 4848 }
nickjillings@1596 4849
nickjillings@1596 4850 if ( one === 1 ) {
nickjillings@1596 4851 origFn = fn;
nickjillings@1596 4852 fn = function( event ) {
nickjillings@1596 4853 // Can use an empty set, since event contains the info
nickjillings@1596 4854 jQuery().off( event );
nickjillings@1596 4855 return origFn.apply( this, arguments );
nickjillings@1596 4856 };
nickjillings@1596 4857 // Use same guid so caller can remove using origFn
nickjillings@1596 4858 fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
nickjillings@1596 4859 }
nickjillings@1596 4860 return this.each( function() {
nickjillings@1596 4861 jQuery.event.add( this, types, fn, data, selector );
nickjillings@1596 4862 });
nickjillings@1596 4863 },
nickjillings@1596 4864 one: function( types, selector, data, fn ) {
nickjillings@1596 4865 return this.on( types, selector, data, fn, 1 );
nickjillings@1596 4866 },
nickjillings@1596 4867 off: function( types, selector, fn ) {
nickjillings@1596 4868 var handleObj, type;
nickjillings@1596 4869 if ( types && types.preventDefault && types.handleObj ) {
nickjillings@1596 4870 // ( event ) dispatched jQuery.Event
nickjillings@1596 4871 handleObj = types.handleObj;
nickjillings@1596 4872 jQuery( types.delegateTarget ).off(
nickjillings@1596 4873 handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType,
nickjillings@1596 4874 handleObj.selector,
nickjillings@1596 4875 handleObj.handler
nickjillings@1596 4876 );
nickjillings@1596 4877 return this;
nickjillings@1596 4878 }
nickjillings@1596 4879 if ( typeof types === "object" ) {
nickjillings@1596 4880 // ( types-object [, selector] )
nickjillings@1596 4881 for ( type in types ) {
nickjillings@1596 4882 this.off( type, selector, types[ type ] );
nickjillings@1596 4883 }
nickjillings@1596 4884 return this;
nickjillings@1596 4885 }
nickjillings@1596 4886 if ( selector === false || typeof selector === "function" ) {
nickjillings@1596 4887 // ( types [, fn] )
nickjillings@1596 4888 fn = selector;
nickjillings@1596 4889 selector = undefined;
nickjillings@1596 4890 }
nickjillings@1596 4891 if ( fn === false ) {
nickjillings@1596 4892 fn = returnFalse;
nickjillings@1596 4893 }
nickjillings@1596 4894 return this.each(function() {
nickjillings@1596 4895 jQuery.event.remove( this, types, fn, selector );
nickjillings@1596 4896 });
nickjillings@1596 4897 },
nickjillings@1596 4898
nickjillings@1596 4899 trigger: function( type, data ) {
nickjillings@1596 4900 return this.each(function() {
nickjillings@1596 4901 jQuery.event.trigger( type, data, this );
nickjillings@1596 4902 });
nickjillings@1596 4903 },
nickjillings@1596 4904 triggerHandler: function( type, data ) {
nickjillings@1596 4905 var elem = this[0];
nickjillings@1596 4906 if ( elem ) {
nickjillings@1596 4907 return jQuery.event.trigger( type, data, elem, true );
nickjillings@1596 4908 }
nickjillings@1596 4909 }
nickjillings@1596 4910 });
nickjillings@1596 4911
nickjillings@1596 4912
nickjillings@1596 4913 var
nickjillings@1596 4914 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
nickjillings@1596 4915 rtagName = /<([\w:]+)/,
nickjillings@1596 4916 rhtml = /<|&#?\w+;/,
nickjillings@1596 4917 rnoInnerhtml = /<(?:script|style|link)/i,
nickjillings@1596 4918 // checked="checked" or checked
nickjillings@1596 4919 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
nickjillings@1596 4920 rscriptType = /^$|\/(?:java|ecma)script/i,
nickjillings@1596 4921 rscriptTypeMasked = /^true\/(.*)/,
nickjillings@1596 4922 rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,
nickjillings@1596 4923
nickjillings@1596 4924 // We have to close these tags to support XHTML (#13200)
nickjillings@1596 4925 wrapMap = {
nickjillings@1596 4926
nickjillings@1596 4927 // Support: IE9
nickjillings@1596 4928 option: [ 1, "<select multiple='multiple'>", "</select>" ],
nickjillings@1596 4929
nickjillings@1596 4930 thead: [ 1, "<table>", "</table>" ],
nickjillings@1596 4931 col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
nickjillings@1596 4932 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
nickjillings@1596 4933 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
nickjillings@1596 4934
nickjillings@1596 4935 _default: [ 0, "", "" ]
nickjillings@1596 4936 };
nickjillings@1596 4937
nickjillings@1596 4938 // Support: IE9
nickjillings@1596 4939 wrapMap.optgroup = wrapMap.option;
nickjillings@1596 4940
nickjillings@1596 4941 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
nickjillings@1596 4942 wrapMap.th = wrapMap.td;
nickjillings@1596 4943
nickjillings@1596 4944 // Support: 1.x compatibility
nickjillings@1596 4945 // Manipulating tables requires a tbody
nickjillings@1596 4946 function manipulationTarget( elem, content ) {
nickjillings@1596 4947 return jQuery.nodeName( elem, "table" ) &&
nickjillings@1596 4948 jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
nickjillings@1596 4949
nickjillings@1596 4950 elem.getElementsByTagName("tbody")[0] ||
nickjillings@1596 4951 elem.appendChild( elem.ownerDocument.createElement("tbody") ) :
nickjillings@1596 4952 elem;
nickjillings@1596 4953 }
nickjillings@1596 4954
nickjillings@1596 4955 // Replace/restore the type attribute of script elements for safe DOM manipulation
nickjillings@1596 4956 function disableScript( elem ) {
nickjillings@1596 4957 elem.type = (elem.getAttribute("type") !== null) + "/" + elem.type;
nickjillings@1596 4958 return elem;
nickjillings@1596 4959 }
nickjillings@1596 4960 function restoreScript( elem ) {
nickjillings@1596 4961 var match = rscriptTypeMasked.exec( elem.type );
nickjillings@1596 4962
nickjillings@1596 4963 if ( match ) {
nickjillings@1596 4964 elem.type = match[ 1 ];
nickjillings@1596 4965 } else {
nickjillings@1596 4966 elem.removeAttribute("type");
nickjillings@1596 4967 }
nickjillings@1596 4968
nickjillings@1596 4969 return elem;
nickjillings@1596 4970 }
nickjillings@1596 4971
nickjillings@1596 4972 // Mark scripts as having already been evaluated
nickjillings@1596 4973 function setGlobalEval( elems, refElements ) {
nickjillings@1596 4974 var i = 0,
nickjillings@1596 4975 l = elems.length;
nickjillings@1596 4976
nickjillings@1596 4977 for ( ; i < l; i++ ) {
nickjillings@1596 4978 data_priv.set(
nickjillings@1596 4979 elems[ i ], "globalEval", !refElements || data_priv.get( refElements[ i ], "globalEval" )
nickjillings@1596 4980 );
nickjillings@1596 4981 }
nickjillings@1596 4982 }
nickjillings@1596 4983
nickjillings@1596 4984 function cloneCopyEvent( src, dest ) {
nickjillings@1596 4985 var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
nickjillings@1596 4986
nickjillings@1596 4987 if ( dest.nodeType !== 1 ) {
nickjillings@1596 4988 return;
nickjillings@1596 4989 }
nickjillings@1596 4990
nickjillings@1596 4991 // 1. Copy private data: events, handlers, etc.
nickjillings@1596 4992 if ( data_priv.hasData( src ) ) {
nickjillings@1596 4993 pdataOld = data_priv.access( src );
nickjillings@1596 4994 pdataCur = data_priv.set( dest, pdataOld );
nickjillings@1596 4995 events = pdataOld.events;
nickjillings@1596 4996
nickjillings@1596 4997 if ( events ) {
nickjillings@1596 4998 delete pdataCur.handle;
nickjillings@1596 4999 pdataCur.events = {};
nickjillings@1596 5000
nickjillings@1596 5001 for ( type in events ) {
nickjillings@1596 5002 for ( i = 0, l = events[ type ].length; i < l; i++ ) {
nickjillings@1596 5003 jQuery.event.add( dest, type, events[ type ][ i ] );
nickjillings@1596 5004 }
nickjillings@1596 5005 }
nickjillings@1596 5006 }
nickjillings@1596 5007 }
nickjillings@1596 5008
nickjillings@1596 5009 // 2. Copy user data
nickjillings@1596 5010 if ( data_user.hasData( src ) ) {
nickjillings@1596 5011 udataOld = data_user.access( src );
nickjillings@1596 5012 udataCur = jQuery.extend( {}, udataOld );
nickjillings@1596 5013
nickjillings@1596 5014 data_user.set( dest, udataCur );
nickjillings@1596 5015 }
nickjillings@1596 5016 }
nickjillings@1596 5017
nickjillings@1596 5018 function getAll( context, tag ) {
nickjillings@1596 5019 var ret = context.getElementsByTagName ? context.getElementsByTagName( tag || "*" ) :
nickjillings@1596 5020 context.querySelectorAll ? context.querySelectorAll( tag || "*" ) :
nickjillings@1596 5021 [];
nickjillings@1596 5022
nickjillings@1596 5023 return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
nickjillings@1596 5024 jQuery.merge( [ context ], ret ) :
nickjillings@1596 5025 ret;
nickjillings@1596 5026 }
nickjillings@1596 5027
nickjillings@1596 5028 // Fix IE bugs, see support tests
nickjillings@1596 5029 function fixInput( src, dest ) {
nickjillings@1596 5030 var nodeName = dest.nodeName.toLowerCase();
nickjillings@1596 5031
nickjillings@1596 5032 // Fails to persist the checked state of a cloned checkbox or radio button.
nickjillings@1596 5033 if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
nickjillings@1596 5034 dest.checked = src.checked;
nickjillings@1596 5035
nickjillings@1596 5036 // Fails to return the selected option to the default selected state when cloning options
nickjillings@1596 5037 } else if ( nodeName === "input" || nodeName === "textarea" ) {
nickjillings@1596 5038 dest.defaultValue = src.defaultValue;
nickjillings@1596 5039 }
nickjillings@1596 5040 }
nickjillings@1596 5041
nickjillings@1596 5042 jQuery.extend({
nickjillings@1596 5043 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
nickjillings@1596 5044 var i, l, srcElements, destElements,
nickjillings@1596 5045 clone = elem.cloneNode( true ),
nickjillings@1596 5046 inPage = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1596 5047
nickjillings@1596 5048 // Fix IE cloning issues
nickjillings@1596 5049 if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
nickjillings@1596 5050 !jQuery.isXMLDoc( elem ) ) {
nickjillings@1596 5051
nickjillings@1596 5052 // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
nickjillings@1596 5053 destElements = getAll( clone );
nickjillings@1596 5054 srcElements = getAll( elem );
nickjillings@1596 5055
nickjillings@1596 5056 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1596 5057 fixInput( srcElements[ i ], destElements[ i ] );
nickjillings@1596 5058 }
nickjillings@1596 5059 }
nickjillings@1596 5060
nickjillings@1596 5061 // Copy the events from the original to the clone
nickjillings@1596 5062 if ( dataAndEvents ) {
nickjillings@1596 5063 if ( deepDataAndEvents ) {
nickjillings@1596 5064 srcElements = srcElements || getAll( elem );
nickjillings@1596 5065 destElements = destElements || getAll( clone );
nickjillings@1596 5066
nickjillings@1596 5067 for ( i = 0, l = srcElements.length; i < l; i++ ) {
nickjillings@1596 5068 cloneCopyEvent( srcElements[ i ], destElements[ i ] );
nickjillings@1596 5069 }
nickjillings@1596 5070 } else {
nickjillings@1596 5071 cloneCopyEvent( elem, clone );
nickjillings@1596 5072 }
nickjillings@1596 5073 }
nickjillings@1596 5074
nickjillings@1596 5075 // Preserve script evaluation history
nickjillings@1596 5076 destElements = getAll( clone, "script" );
nickjillings@1596 5077 if ( destElements.length > 0 ) {
nickjillings@1596 5078 setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
nickjillings@1596 5079 }
nickjillings@1596 5080
nickjillings@1596 5081 // Return the cloned set
nickjillings@1596 5082 return clone;
nickjillings@1596 5083 },
nickjillings@1596 5084
nickjillings@1596 5085 buildFragment: function( elems, context, scripts, selection ) {
nickjillings@1596 5086 var elem, tmp, tag, wrap, contains, j,
nickjillings@1596 5087 fragment = context.createDocumentFragment(),
nickjillings@1596 5088 nodes = [],
nickjillings@1596 5089 i = 0,
nickjillings@1596 5090 l = elems.length;
nickjillings@1596 5091
nickjillings@1596 5092 for ( ; i < l; i++ ) {
nickjillings@1596 5093 elem = elems[ i ];
nickjillings@1596 5094
nickjillings@1596 5095 if ( elem || elem === 0 ) {
nickjillings@1596 5096
nickjillings@1596 5097 // Add nodes directly
nickjillings@1596 5098 if ( jQuery.type( elem ) === "object" ) {
nickjillings@1596 5099 // Support: QtWebKit, PhantomJS
nickjillings@1596 5100 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1596 5101 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
nickjillings@1596 5102
nickjillings@1596 5103 // Convert non-html into a text node
nickjillings@1596 5104 } else if ( !rhtml.test( elem ) ) {
nickjillings@1596 5105 nodes.push( context.createTextNode( elem ) );
nickjillings@1596 5106
nickjillings@1596 5107 // Convert html into DOM nodes
nickjillings@1596 5108 } else {
nickjillings@1596 5109 tmp = tmp || fragment.appendChild( context.createElement("div") );
nickjillings@1596 5110
nickjillings@1596 5111 // Deserialize a standard representation
nickjillings@1596 5112 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
nickjillings@1596 5113 wrap = wrapMap[ tag ] || wrapMap._default;
nickjillings@1596 5114 tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];
nickjillings@1596 5115
nickjillings@1596 5116 // Descend through wrappers to the right content
nickjillings@1596 5117 j = wrap[ 0 ];
nickjillings@1596 5118 while ( j-- ) {
nickjillings@1596 5119 tmp = tmp.lastChild;
nickjillings@1596 5120 }
nickjillings@1596 5121
nickjillings@1596 5122 // Support: QtWebKit, PhantomJS
nickjillings@1596 5123 // push.apply(_, arraylike) throws on ancient WebKit
nickjillings@1596 5124 jQuery.merge( nodes, tmp.childNodes );
nickjillings@1596 5125
nickjillings@1596 5126 // Remember the top-level container
nickjillings@1596 5127 tmp = fragment.firstChild;
nickjillings@1596 5128
nickjillings@1596 5129 // Ensure the created nodes are orphaned (#12392)
nickjillings@1596 5130 tmp.textContent = "";
nickjillings@1596 5131 }
nickjillings@1596 5132 }
nickjillings@1596 5133 }
nickjillings@1596 5134
nickjillings@1596 5135 // Remove wrapper from fragment
nickjillings@1596 5136 fragment.textContent = "";
nickjillings@1596 5137
nickjillings@1596 5138 i = 0;
nickjillings@1596 5139 while ( (elem = nodes[ i++ ]) ) {
nickjillings@1596 5140
nickjillings@1596 5141 // #4087 - If origin and destination elements are the same, and this is
nickjillings@1596 5142 // that element, do not do anything
nickjillings@1596 5143 if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
nickjillings@1596 5144 continue;
nickjillings@1596 5145 }
nickjillings@1596 5146
nickjillings@1596 5147 contains = jQuery.contains( elem.ownerDocument, elem );
nickjillings@1596 5148
nickjillings@1596 5149 // Append to fragment
nickjillings@1596 5150 tmp = getAll( fragment.appendChild( elem ), "script" );
nickjillings@1596 5151
nickjillings@1596 5152 // Preserve script evaluation history
nickjillings@1596 5153 if ( contains ) {
nickjillings@1596 5154 setGlobalEval( tmp );
nickjillings@1596 5155 }
nickjillings@1596 5156
nickjillings@1596 5157 // Capture executables
nickjillings@1596 5158 if ( scripts ) {
nickjillings@1596 5159 j = 0;
nickjillings@1596 5160 while ( (elem = tmp[ j++ ]) ) {
nickjillings@1596 5161 if ( rscriptType.test( elem.type || "" ) ) {
nickjillings@1596 5162 scripts.push( elem );
nickjillings@1596 5163 }
nickjillings@1596 5164 }
nickjillings@1596 5165 }
nickjillings@1596 5166 }
nickjillings@1596 5167
nickjillings@1596 5168 return fragment;
nickjillings@1596 5169 },
nickjillings@1596 5170
nickjillings@1596 5171 cleanData: function( elems ) {
nickjillings@1596 5172 var data, elem, type, key,
nickjillings@1596 5173 special = jQuery.event.special,
nickjillings@1596 5174 i = 0;
nickjillings@1596 5175
nickjillings@1596 5176 for ( ; (elem = elems[ i ]) !== undefined; i++ ) {
nickjillings@1596 5177 if ( jQuery.acceptData( elem ) ) {
nickjillings@1596 5178 key = elem[ data_priv.expando ];
nickjillings@1596 5179
nickjillings@1596 5180 if ( key && (data = data_priv.cache[ key ]) ) {
nickjillings@1596 5181 if ( data.events ) {
nickjillings@1596 5182 for ( type in data.events ) {
nickjillings@1596 5183 if ( special[ type ] ) {
nickjillings@1596 5184 jQuery.event.remove( elem, type );
nickjillings@1596 5185
nickjillings@1596 5186 // This is a shortcut to avoid jQuery.event.remove's overhead
nickjillings@1596 5187 } else {
nickjillings@1596 5188 jQuery.removeEvent( elem, type, data.handle );
nickjillings@1596 5189 }
nickjillings@1596 5190 }
nickjillings@1596 5191 }
nickjillings@1596 5192 if ( data_priv.cache[ key ] ) {
nickjillings@1596 5193 // Discard any remaining `private` data
nickjillings@1596 5194 delete data_priv.cache[ key ];
nickjillings@1596 5195 }
nickjillings@1596 5196 }
nickjillings@1596 5197 }
nickjillings@1596 5198 // Discard any remaining `user` data
nickjillings@1596 5199 delete data_user.cache[ elem[ data_user.expando ] ];
nickjillings@1596 5200 }
nickjillings@1596 5201 }
nickjillings@1596 5202 });
nickjillings@1596 5203
nickjillings@1596 5204 jQuery.fn.extend({
nickjillings@1596 5205 text: function( value ) {
nickjillings@1596 5206 return access( this, function( value ) {
nickjillings@1596 5207 return value === undefined ?
nickjillings@1596 5208 jQuery.text( this ) :
nickjillings@1596 5209 this.empty().each(function() {
nickjillings@1596 5210 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1596 5211 this.textContent = value;
nickjillings@1596 5212 }
nickjillings@1596 5213 });
nickjillings@1596 5214 }, null, value, arguments.length );
nickjillings@1596 5215 },
nickjillings@1596 5216
nickjillings@1596 5217 append: function() {
nickjillings@1596 5218 return this.domManip( arguments, function( elem ) {
nickjillings@1596 5219 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1596 5220 var target = manipulationTarget( this, elem );
nickjillings@1596 5221 target.appendChild( elem );
nickjillings@1596 5222 }
nickjillings@1596 5223 });
nickjillings@1596 5224 },
nickjillings@1596 5225
nickjillings@1596 5226 prepend: function() {
nickjillings@1596 5227 return this.domManip( arguments, function( elem ) {
nickjillings@1596 5228 if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
nickjillings@1596 5229 var target = manipulationTarget( this, elem );
nickjillings@1596 5230 target.insertBefore( elem, target.firstChild );
nickjillings@1596 5231 }
nickjillings@1596 5232 });
nickjillings@1596 5233 },
nickjillings@1596 5234
nickjillings@1596 5235 before: function() {
nickjillings@1596 5236 return this.domManip( arguments, function( elem ) {
nickjillings@1596 5237 if ( this.parentNode ) {
nickjillings@1596 5238 this.parentNode.insertBefore( elem, this );
nickjillings@1596 5239 }
nickjillings@1596 5240 });
nickjillings@1596 5241 },
nickjillings@1596 5242
nickjillings@1596 5243 after: function() {
nickjillings@1596 5244 return this.domManip( arguments, function( elem ) {
nickjillings@1596 5245 if ( this.parentNode ) {
nickjillings@1596 5246 this.parentNode.insertBefore( elem, this.nextSibling );
nickjillings@1596 5247 }
nickjillings@1596 5248 });
nickjillings@1596 5249 },
nickjillings@1596 5250
nickjillings@1596 5251 remove: function( selector, keepData /* Internal Use Only */ ) {
nickjillings@1596 5252 var elem,
nickjillings@1596 5253 elems = selector ? jQuery.filter( selector, this ) : this,
nickjillings@1596 5254 i = 0;
nickjillings@1596 5255
nickjillings@1596 5256 for ( ; (elem = elems[i]) != null; i++ ) {
nickjillings@1596 5257 if ( !keepData && elem.nodeType === 1 ) {
nickjillings@1596 5258 jQuery.cleanData( getAll( elem ) );
nickjillings@1596 5259 }
nickjillings@1596 5260
nickjillings@1596 5261 if ( elem.parentNode ) {
nickjillings@1596 5262 if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1596 5263 setGlobalEval( getAll( elem, "script" ) );
nickjillings@1596 5264 }
nickjillings@1596 5265 elem.parentNode.removeChild( elem );
nickjillings@1596 5266 }
nickjillings@1596 5267 }
nickjillings@1596 5268
nickjillings@1596 5269 return this;
nickjillings@1596 5270 },
nickjillings@1596 5271
nickjillings@1596 5272 empty: function() {
nickjillings@1596 5273 var elem,
nickjillings@1596 5274 i = 0;
nickjillings@1596 5275
nickjillings@1596 5276 for ( ; (elem = this[i]) != null; i++ ) {
nickjillings@1596 5277 if ( elem.nodeType === 1 ) {
nickjillings@1596 5278
nickjillings@1596 5279 // Prevent memory leaks
nickjillings@1596 5280 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1596 5281
nickjillings@1596 5282 // Remove any remaining nodes
nickjillings@1596 5283 elem.textContent = "";
nickjillings@1596 5284 }
nickjillings@1596 5285 }
nickjillings@1596 5286
nickjillings@1596 5287 return this;
nickjillings@1596 5288 },
nickjillings@1596 5289
nickjillings@1596 5290 clone: function( dataAndEvents, deepDataAndEvents ) {
nickjillings@1596 5291 dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
nickjillings@1596 5292 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
nickjillings@1596 5293
nickjillings@1596 5294 return this.map(function() {
nickjillings@1596 5295 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
nickjillings@1596 5296 });
nickjillings@1596 5297 },
nickjillings@1596 5298
nickjillings@1596 5299 html: function( value ) {
nickjillings@1596 5300 return access( this, function( value ) {
nickjillings@1596 5301 var elem = this[ 0 ] || {},
nickjillings@1596 5302 i = 0,
nickjillings@1596 5303 l = this.length;
nickjillings@1596 5304
nickjillings@1596 5305 if ( value === undefined && elem.nodeType === 1 ) {
nickjillings@1596 5306 return elem.innerHTML;
nickjillings@1596 5307 }
nickjillings@1596 5308
nickjillings@1596 5309 // See if we can take a shortcut and just use innerHTML
nickjillings@1596 5310 if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
nickjillings@1596 5311 !wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
nickjillings@1596 5312
nickjillings@1596 5313 value = value.replace( rxhtmlTag, "<$1></$2>" );
nickjillings@1596 5314
nickjillings@1596 5315 try {
nickjillings@1596 5316 for ( ; i < l; i++ ) {
nickjillings@1596 5317 elem = this[ i ] || {};
nickjillings@1596 5318
nickjillings@1596 5319 // Remove element nodes and prevent memory leaks
nickjillings@1596 5320 if ( elem.nodeType === 1 ) {
nickjillings@1596 5321 jQuery.cleanData( getAll( elem, false ) );
nickjillings@1596 5322 elem.innerHTML = value;
nickjillings@1596 5323 }
nickjillings@1596 5324 }
nickjillings@1596 5325
nickjillings@1596 5326 elem = 0;
nickjillings@1596 5327
nickjillings@1596 5328 // If using innerHTML throws an exception, use the fallback method
nickjillings@1596 5329 } catch( e ) {}
nickjillings@1596 5330 }
nickjillings@1596 5331
nickjillings@1596 5332 if ( elem ) {
nickjillings@1596 5333 this.empty().append( value );
nickjillings@1596 5334 }
nickjillings@1596 5335 }, null, value, arguments.length );
nickjillings@1596 5336 },
nickjillings@1596 5337
nickjillings@1596 5338 replaceWith: function() {
nickjillings@1596 5339 var arg = arguments[ 0 ];
nickjillings@1596 5340
nickjillings@1596 5341 // Make the changes, replacing each context element with the new content
nickjillings@1596 5342 this.domManip( arguments, function( elem ) {
nickjillings@1596 5343 arg = this.parentNode;
nickjillings@1596 5344
nickjillings@1596 5345 jQuery.cleanData( getAll( this ) );
nickjillings@1596 5346
nickjillings@1596 5347 if ( arg ) {
nickjillings@1596 5348 arg.replaceChild( elem, this );
nickjillings@1596 5349 }
nickjillings@1596 5350 });
nickjillings@1596 5351
nickjillings@1596 5352 // Force removal if there was no new content (e.g., from empty arguments)
nickjillings@1596 5353 return arg && (arg.length || arg.nodeType) ? this : this.remove();
nickjillings@1596 5354 },
nickjillings@1596 5355
nickjillings@1596 5356 detach: function( selector ) {
nickjillings@1596 5357 return this.remove( selector, true );
nickjillings@1596 5358 },
nickjillings@1596 5359
nickjillings@1596 5360 domManip: function( args, callback ) {
nickjillings@1596 5361
nickjillings@1596 5362 // Flatten any nested arrays
nickjillings@1596 5363 args = concat.apply( [], args );
nickjillings@1596 5364
nickjillings@1596 5365 var fragment, first, scripts, hasScripts, node, doc,
nickjillings@1596 5366 i = 0,
nickjillings@1596 5367 l = this.length,
nickjillings@1596 5368 set = this,
nickjillings@1596 5369 iNoClone = l - 1,
nickjillings@1596 5370 value = args[ 0 ],
nickjillings@1596 5371 isFunction = jQuery.isFunction( value );
nickjillings@1596 5372
nickjillings@1596 5373 // We can't cloneNode fragments that contain checked, in WebKit
nickjillings@1596 5374 if ( isFunction ||
nickjillings@1596 5375 ( l > 1 && typeof value === "string" &&
nickjillings@1596 5376 !support.checkClone && rchecked.test( value ) ) ) {
nickjillings@1596 5377 return this.each(function( index ) {
nickjillings@1596 5378 var self = set.eq( index );
nickjillings@1596 5379 if ( isFunction ) {
nickjillings@1596 5380 args[ 0 ] = value.call( this, index, self.html() );
nickjillings@1596 5381 }
nickjillings@1596 5382 self.domManip( args, callback );
nickjillings@1596 5383 });
nickjillings@1596 5384 }
nickjillings@1596 5385
nickjillings@1596 5386 if ( l ) {
nickjillings@1596 5387 fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
nickjillings@1596 5388 first = fragment.firstChild;
nickjillings@1596 5389
nickjillings@1596 5390 if ( fragment.childNodes.length === 1 ) {
nickjillings@1596 5391 fragment = first;
nickjillings@1596 5392 }
nickjillings@1596 5393
nickjillings@1596 5394 if ( first ) {
nickjillings@1596 5395 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
nickjillings@1596 5396 hasScripts = scripts.length;
nickjillings@1596 5397
nickjillings@1596 5398 // Use the original fragment for the last item instead of the first because it can end up
nickjillings@1596 5399 // being emptied incorrectly in certain situations (#8070).
nickjillings@1596 5400 for ( ; i < l; i++ ) {
nickjillings@1596 5401 node = fragment;
nickjillings@1596 5402
nickjillings@1596 5403 if ( i !== iNoClone ) {
nickjillings@1596 5404 node = jQuery.clone( node, true, true );
nickjillings@1596 5405
nickjillings@1596 5406 // Keep references to cloned scripts for later restoration
nickjillings@1596 5407 if ( hasScripts ) {
nickjillings@1596 5408 // Support: QtWebKit
nickjillings@1596 5409 // jQuery.merge because push.apply(_, arraylike) throws
nickjillings@1596 5410 jQuery.merge( scripts, getAll( node, "script" ) );
nickjillings@1596 5411 }
nickjillings@1596 5412 }
nickjillings@1596 5413
nickjillings@1596 5414 callback.call( this[ i ], node, i );
nickjillings@1596 5415 }
nickjillings@1596 5416
nickjillings@1596 5417 if ( hasScripts ) {
nickjillings@1596 5418 doc = scripts[ scripts.length - 1 ].ownerDocument;
nickjillings@1596 5419
nickjillings@1596 5420 // Reenable scripts
nickjillings@1596 5421 jQuery.map( scripts, restoreScript );
nickjillings@1596 5422
nickjillings@1596 5423 // Evaluate executable scripts on first document insertion
nickjillings@1596 5424 for ( i = 0; i < hasScripts; i++ ) {
nickjillings@1596 5425 node = scripts[ i ];
nickjillings@1596 5426 if ( rscriptType.test( node.type || "" ) &&
nickjillings@1596 5427 !data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) ) {
nickjillings@1596 5428
nickjillings@1596 5429 if ( node.src ) {
nickjillings@1596 5430 // Optional AJAX dependency, but won't run scripts if not present
nickjillings@1596 5431 if ( jQuery._evalUrl ) {
nickjillings@1596 5432 jQuery._evalUrl( node.src );
nickjillings@1596 5433 }
nickjillings@1596 5434 } else {
nickjillings@1596 5435 jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
nickjillings@1596 5436 }
nickjillings@1596 5437 }
nickjillings@1596 5438 }
nickjillings@1596 5439 }
nickjillings@1596 5440 }
nickjillings@1596 5441 }
nickjillings@1596 5442
nickjillings@1596 5443 return this;
nickjillings@1596 5444 }
nickjillings@1596 5445 });
nickjillings@1596 5446
nickjillings@1596 5447 jQuery.each({
nickjillings@1596 5448 appendTo: "append",
nickjillings@1596 5449 prependTo: "prepend",
nickjillings@1596 5450 insertBefore: "before",
nickjillings@1596 5451 insertAfter: "after",
nickjillings@1596 5452 replaceAll: "replaceWith"
nickjillings@1596 5453 }, function( name, original ) {
nickjillings@1596 5454 jQuery.fn[ name ] = function( selector ) {
nickjillings@1596 5455 var elems,
nickjillings@1596 5456 ret = [],
nickjillings@1596 5457 insert = jQuery( selector ),
nickjillings@1596 5458 last = insert.length - 1,
nickjillings@1596 5459 i = 0;
nickjillings@1596 5460
nickjillings@1596 5461 for ( ; i <= last; i++ ) {
nickjillings@1596 5462 elems = i === last ? this : this.clone( true );
nickjillings@1596 5463 jQuery( insert[ i ] )[ original ]( elems );
nickjillings@1596 5464
nickjillings@1596 5465 // Support: QtWebKit
nickjillings@1596 5466 // .get() because push.apply(_, arraylike) throws
nickjillings@1596 5467 push.apply( ret, elems.get() );
nickjillings@1596 5468 }
nickjillings@1596 5469
nickjillings@1596 5470 return this.pushStack( ret );
nickjillings@1596 5471 };
nickjillings@1596 5472 });
nickjillings@1596 5473
nickjillings@1596 5474
nickjillings@1596 5475 var iframe,
nickjillings@1596 5476 elemdisplay = {};
nickjillings@1596 5477
nickjillings@1596 5478 /**
nickjillings@1596 5479 * Retrieve the actual display of a element
nickjillings@1596 5480 * @param {String} name nodeName of the element
nickjillings@1596 5481 * @param {Object} doc Document object
nickjillings@1596 5482 */
nickjillings@1596 5483 // Called only from within defaultDisplay
nickjillings@1596 5484 function actualDisplay( name, doc ) {
nickjillings@1596 5485 var style,
nickjillings@1596 5486 elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
nickjillings@1596 5487
nickjillings@1596 5488 // getDefaultComputedStyle might be reliably used only on attached element
nickjillings@1596 5489 display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ?
nickjillings@1596 5490
nickjillings@1596 5491 // Use of this method is a temporary fix (more like optimization) until something better comes along,
nickjillings@1596 5492 // since it was removed from specification and supported only in FF
nickjillings@1596 5493 style.display : jQuery.css( elem[ 0 ], "display" );
nickjillings@1596 5494
nickjillings@1596 5495 // We don't have any data stored on the element,
nickjillings@1596 5496 // so use "detach" method as fast way to get rid of the element
nickjillings@1596 5497 elem.detach();
nickjillings@1596 5498
nickjillings@1596 5499 return display;
nickjillings@1596 5500 }
nickjillings@1596 5501
nickjillings@1596 5502 /**
nickjillings@1596 5503 * Try to determine the default display value of an element
nickjillings@1596 5504 * @param {String} nodeName
nickjillings@1596 5505 */
nickjillings@1596 5506 function defaultDisplay( nodeName ) {
nickjillings@1596 5507 var doc = document,
nickjillings@1596 5508 display = elemdisplay[ nodeName ];
nickjillings@1596 5509
nickjillings@1596 5510 if ( !display ) {
nickjillings@1596 5511 display = actualDisplay( nodeName, doc );
nickjillings@1596 5512
nickjillings@1596 5513 // If the simple way fails, read from inside an iframe
nickjillings@1596 5514 if ( display === "none" || !display ) {
nickjillings@1596 5515
nickjillings@1596 5516 // Use the already-created iframe if possible
nickjillings@1596 5517 iframe = (iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" )).appendTo( doc.documentElement );
nickjillings@1596 5518
nickjillings@1596 5519 // Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
nickjillings@1596 5520 doc = iframe[ 0 ].contentDocument;
nickjillings@1596 5521
nickjillings@1596 5522 // Support: IE
nickjillings@1596 5523 doc.write();
nickjillings@1596 5524 doc.close();
nickjillings@1596 5525
nickjillings@1596 5526 display = actualDisplay( nodeName, doc );
nickjillings@1596 5527 iframe.detach();
nickjillings@1596 5528 }
nickjillings@1596 5529
nickjillings@1596 5530 // Store the correct default display
nickjillings@1596 5531 elemdisplay[ nodeName ] = display;
nickjillings@1596 5532 }
nickjillings@1596 5533
nickjillings@1596 5534 return display;
nickjillings@1596 5535 }
nickjillings@1596 5536 var rmargin = (/^margin/);
nickjillings@1596 5537
nickjillings@1596 5538 var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
nickjillings@1596 5539
nickjillings@1596 5540 var getStyles = function( elem ) {
nickjillings@1596 5541 // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
nickjillings@1596 5542 // IE throws on elements created in popups
nickjillings@1596 5543 // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
nickjillings@1596 5544 if ( elem.ownerDocument.defaultView.opener ) {
nickjillings@1596 5545 return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
nickjillings@1596 5546 }
nickjillings@1596 5547
nickjillings@1596 5548 return window.getComputedStyle( elem, null );
nickjillings@1596 5549 };
nickjillings@1596 5550
nickjillings@1596 5551
nickjillings@1596 5552
nickjillings@1596 5553 function curCSS( elem, name, computed ) {
nickjillings@1596 5554 var width, minWidth, maxWidth, ret,
nickjillings@1596 5555 style = elem.style;
nickjillings@1596 5556
nickjillings@1596 5557 computed = computed || getStyles( elem );
nickjillings@1596 5558
nickjillings@1596 5559 // Support: IE9
nickjillings@1596 5560 // getPropertyValue is only needed for .css('filter') (#12537)
nickjillings@1596 5561 if ( computed ) {
nickjillings@1596 5562 ret = computed.getPropertyValue( name ) || computed[ name ];
nickjillings@1596 5563 }
nickjillings@1596 5564
nickjillings@1596 5565 if ( computed ) {
nickjillings@1596 5566
nickjillings@1596 5567 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
nickjillings@1596 5568 ret = jQuery.style( elem, name );
nickjillings@1596 5569 }
nickjillings@1596 5570
nickjillings@1596 5571 // Support: iOS < 6
nickjillings@1596 5572 // A tribute to the "awesome hack by Dean Edwards"
nickjillings@1596 5573 // iOS < 6 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
nickjillings@1596 5574 // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
nickjillings@1596 5575 if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
nickjillings@1596 5576
nickjillings@1596 5577 // Remember the original values
nickjillings@1596 5578 width = style.width;
nickjillings@1596 5579 minWidth = style.minWidth;
nickjillings@1596 5580 maxWidth = style.maxWidth;
nickjillings@1596 5581
nickjillings@1596 5582 // Put in the new values to get a computed value out
nickjillings@1596 5583 style.minWidth = style.maxWidth = style.width = ret;
nickjillings@1596 5584 ret = computed.width;
nickjillings@1596 5585
nickjillings@1596 5586 // Revert the changed values
nickjillings@1596 5587 style.width = width;
nickjillings@1596 5588 style.minWidth = minWidth;
nickjillings@1596 5589 style.maxWidth = maxWidth;
nickjillings@1596 5590 }
nickjillings@1596 5591 }
nickjillings@1596 5592
nickjillings@1596 5593 return ret !== undefined ?
nickjillings@1596 5594 // Support: IE
nickjillings@1596 5595 // IE returns zIndex value as an integer.
nickjillings@1596 5596 ret + "" :
nickjillings@1596 5597 ret;
nickjillings@1596 5598 }
nickjillings@1596 5599
nickjillings@1596 5600
nickjillings@1596 5601 function addGetHookIf( conditionFn, hookFn ) {
nickjillings@1596 5602 // Define the hook, we'll check on the first run if it's really needed.
nickjillings@1596 5603 return {
nickjillings@1596 5604 get: function() {
nickjillings@1596 5605 if ( conditionFn() ) {
nickjillings@1596 5606 // Hook not needed (or it's not possible to use it due
nickjillings@1596 5607 // to missing dependency), remove it.
nickjillings@1596 5608 delete this.get;
nickjillings@1596 5609 return;
nickjillings@1596 5610 }
nickjillings@1596 5611
nickjillings@1596 5612 // Hook needed; redefine it so that the support test is not executed again.
nickjillings@1596 5613 return (this.get = hookFn).apply( this, arguments );
nickjillings@1596 5614 }
nickjillings@1596 5615 };
nickjillings@1596 5616 }
nickjillings@1596 5617
nickjillings@1596 5618
nickjillings@1596 5619 (function() {
nickjillings@1596 5620 var pixelPositionVal, boxSizingReliableVal,
nickjillings@1596 5621 docElem = document.documentElement,
nickjillings@1596 5622 container = document.createElement( "div" ),
nickjillings@1596 5623 div = document.createElement( "div" );
nickjillings@1596 5624
nickjillings@1596 5625 if ( !div.style ) {
nickjillings@1596 5626 return;
nickjillings@1596 5627 }
nickjillings@1596 5628
nickjillings@1596 5629 // Support: IE9-11+
nickjillings@1596 5630 // Style of cloned element affects source element cloned (#8908)
nickjillings@1596 5631 div.style.backgroundClip = "content-box";
nickjillings@1596 5632 div.cloneNode( true ).style.backgroundClip = "";
nickjillings@1596 5633 support.clearCloneStyle = div.style.backgroundClip === "content-box";
nickjillings@1596 5634
nickjillings@1596 5635 container.style.cssText = "border:0;width:0;height:0;top:0;left:-9999px;margin-top:1px;" +
nickjillings@1596 5636 "position:absolute";
nickjillings@1596 5637 container.appendChild( div );
nickjillings@1596 5638
nickjillings@1596 5639 // Executing both pixelPosition & boxSizingReliable tests require only one layout
nickjillings@1596 5640 // so they're executed at the same time to save the second computation.
nickjillings@1596 5641 function computePixelPositionAndBoxSizingReliable() {
nickjillings@1596 5642 div.style.cssText =
nickjillings@1596 5643 // Support: Firefox<29, Android 2.3
nickjillings@1596 5644 // Vendor-prefix box-sizing
nickjillings@1596 5645 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" +
nickjillings@1596 5646 "box-sizing:border-box;display:block;margin-top:1%;top:1%;" +
nickjillings@1596 5647 "border:1px;padding:1px;width:4px;position:absolute";
nickjillings@1596 5648 div.innerHTML = "";
nickjillings@1596 5649 docElem.appendChild( container );
nickjillings@1596 5650
nickjillings@1596 5651 var divStyle = window.getComputedStyle( div, null );
nickjillings@1596 5652 pixelPositionVal = divStyle.top !== "1%";
nickjillings@1596 5653 boxSizingReliableVal = divStyle.width === "4px";
nickjillings@1596 5654
nickjillings@1596 5655 docElem.removeChild( container );
nickjillings@1596 5656 }
nickjillings@1596 5657
nickjillings@1596 5658 // Support: node.js jsdom
nickjillings@1596 5659 // Don't assume that getComputedStyle is a property of the global object
nickjillings@1596 5660 if ( window.getComputedStyle ) {
nickjillings@1596 5661 jQuery.extend( support, {
nickjillings@1596 5662 pixelPosition: function() {
nickjillings@1596 5663
nickjillings@1596 5664 // This test is executed only once but we still do memoizing
nickjillings@1596 5665 // since we can use the boxSizingReliable pre-computing.
nickjillings@1596 5666 // No need to check if the test was already performed, though.
nickjillings@1596 5667 computePixelPositionAndBoxSizingReliable();
nickjillings@1596 5668 return pixelPositionVal;
nickjillings@1596 5669 },
nickjillings@1596 5670 boxSizingReliable: function() {
nickjillings@1596 5671 if ( boxSizingReliableVal == null ) {
nickjillings@1596 5672 computePixelPositionAndBoxSizingReliable();
nickjillings@1596 5673 }
nickjillings@1596 5674 return boxSizingReliableVal;
nickjillings@1596 5675 },
nickjillings@1596 5676 reliableMarginRight: function() {
nickjillings@1596 5677
nickjillings@1596 5678 // Support: Android 2.3
nickjillings@1596 5679 // Check if div with explicit width and no margin-right incorrectly
nickjillings@1596 5680 // gets computed margin-right based on width of container. (#3333)
nickjillings@1596 5681 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
nickjillings@1596 5682 // This support function is only executed once so no memoizing is needed.
nickjillings@1596 5683 var ret,
nickjillings@1596 5684 marginDiv = div.appendChild( document.createElement( "div" ) );
nickjillings@1596 5685
nickjillings@1596 5686 // Reset CSS: box-sizing; display; margin; border; padding
nickjillings@1596 5687 marginDiv.style.cssText = div.style.cssText =
nickjillings@1596 5688 // Support: Firefox<29, Android 2.3
nickjillings@1596 5689 // Vendor-prefix box-sizing
nickjillings@1596 5690 "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;" +
nickjillings@1596 5691 "box-sizing:content-box;display:block;margin:0;border:0;padding:0";
nickjillings@1596 5692 marginDiv.style.marginRight = marginDiv.style.width = "0";
nickjillings@1596 5693 div.style.width = "1px";
nickjillings@1596 5694 docElem.appendChild( container );
nickjillings@1596 5695
nickjillings@1596 5696 ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight );
nickjillings@1596 5697
nickjillings@1596 5698 docElem.removeChild( container );
nickjillings@1596 5699 div.removeChild( marginDiv );
nickjillings@1596 5700
nickjillings@1596 5701 return ret;
nickjillings@1596 5702 }
nickjillings@1596 5703 });
nickjillings@1596 5704 }
nickjillings@1596 5705 })();
nickjillings@1596 5706
nickjillings@1596 5707
nickjillings@1596 5708 // A method for quickly swapping in/out CSS properties to get correct calculations.
nickjillings@1596 5709 jQuery.swap = function( elem, options, callback, args ) {
nickjillings@1596 5710 var ret, name,
nickjillings@1596 5711 old = {};
nickjillings@1596 5712
nickjillings@1596 5713 // Remember the old values, and insert the new ones
nickjillings@1596 5714 for ( name in options ) {
nickjillings@1596 5715 old[ name ] = elem.style[ name ];
nickjillings@1596 5716 elem.style[ name ] = options[ name ];
nickjillings@1596 5717 }
nickjillings@1596 5718
nickjillings@1596 5719 ret = callback.apply( elem, args || [] );
nickjillings@1596 5720
nickjillings@1596 5721 // Revert the old values
nickjillings@1596 5722 for ( name in options ) {
nickjillings@1596 5723 elem.style[ name ] = old[ name ];
nickjillings@1596 5724 }
nickjillings@1596 5725
nickjillings@1596 5726 return ret;
nickjillings@1596 5727 };
nickjillings@1596 5728
nickjillings@1596 5729
nickjillings@1596 5730 var
nickjillings@1596 5731 // Swappable if display is none or starts with table except "table", "table-cell", or "table-caption"
nickjillings@1596 5732 // See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
nickjillings@1596 5733 rdisplayswap = /^(none|table(?!-c[ea]).+)/,
nickjillings@1596 5734 rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ),
nickjillings@1596 5735 rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ),
nickjillings@1596 5736
nickjillings@1596 5737 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
nickjillings@1596 5738 cssNormalTransform = {
nickjillings@1596 5739 letterSpacing: "0",
nickjillings@1596 5740 fontWeight: "400"
nickjillings@1596 5741 },
nickjillings@1596 5742
nickjillings@1596 5743 cssPrefixes = [ "Webkit", "O", "Moz", "ms" ];
nickjillings@1596 5744
nickjillings@1596 5745 // Return a css property mapped to a potentially vendor prefixed property
nickjillings@1596 5746 function vendorPropName( style, name ) {
nickjillings@1596 5747
nickjillings@1596 5748 // Shortcut for names that are not vendor prefixed
nickjillings@1596 5749 if ( name in style ) {
nickjillings@1596 5750 return name;
nickjillings@1596 5751 }
nickjillings@1596 5752
nickjillings@1596 5753 // Check for vendor prefixed names
nickjillings@1596 5754 var capName = name[0].toUpperCase() + name.slice(1),
nickjillings@1596 5755 origName = name,
nickjillings@1596 5756 i = cssPrefixes.length;
nickjillings@1596 5757
nickjillings@1596 5758 while ( i-- ) {
nickjillings@1596 5759 name = cssPrefixes[ i ] + capName;
nickjillings@1596 5760 if ( name in style ) {
nickjillings@1596 5761 return name;
nickjillings@1596 5762 }
nickjillings@1596 5763 }
nickjillings@1596 5764
nickjillings@1596 5765 return origName;
nickjillings@1596 5766 }
nickjillings@1596 5767
nickjillings@1596 5768 function setPositiveNumber( elem, value, subtract ) {
nickjillings@1596 5769 var matches = rnumsplit.exec( value );
nickjillings@1596 5770 return matches ?
nickjillings@1596 5771 // Guard against undefined "subtract", e.g., when used as in cssHooks
nickjillings@1596 5772 Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
nickjillings@1596 5773 value;
nickjillings@1596 5774 }
nickjillings@1596 5775
nickjillings@1596 5776 function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
nickjillings@1596 5777 var i = extra === ( isBorderBox ? "border" : "content" ) ?
nickjillings@1596 5778 // If we already have the right measurement, avoid augmentation
nickjillings@1596 5779 4 :
nickjillings@1596 5780 // Otherwise initialize for horizontal or vertical properties
nickjillings@1596 5781 name === "width" ? 1 : 0,
nickjillings@1596 5782
nickjillings@1596 5783 val = 0;
nickjillings@1596 5784
nickjillings@1596 5785 for ( ; i < 4; i += 2 ) {
nickjillings@1596 5786 // Both box models exclude margin, so add it if we want it
nickjillings@1596 5787 if ( extra === "margin" ) {
nickjillings@1596 5788 val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
nickjillings@1596 5789 }
nickjillings@1596 5790
nickjillings@1596 5791 if ( isBorderBox ) {
nickjillings@1596 5792 // border-box includes padding, so remove it if we want content
nickjillings@1596 5793 if ( extra === "content" ) {
nickjillings@1596 5794 val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1596 5795 }
nickjillings@1596 5796
nickjillings@1596 5797 // At this point, extra isn't border nor margin, so remove border
nickjillings@1596 5798 if ( extra !== "margin" ) {
nickjillings@1596 5799 val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1596 5800 }
nickjillings@1596 5801 } else {
nickjillings@1596 5802 // At this point, extra isn't content, so add padding
nickjillings@1596 5803 val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
nickjillings@1596 5804
nickjillings@1596 5805 // At this point, extra isn't content nor padding, so add border
nickjillings@1596 5806 if ( extra !== "padding" ) {
nickjillings@1596 5807 val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
nickjillings@1596 5808 }
nickjillings@1596 5809 }
nickjillings@1596 5810 }
nickjillings@1596 5811
nickjillings@1596 5812 return val;
nickjillings@1596 5813 }
nickjillings@1596 5814
nickjillings@1596 5815 function getWidthOrHeight( elem, name, extra ) {
nickjillings@1596 5816
nickjillings@1596 5817 // Start with offset property, which is equivalent to the border-box value
nickjillings@1596 5818 var valueIsBorderBox = true,
nickjillings@1596 5819 val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
nickjillings@1596 5820 styles = getStyles( elem ),
nickjillings@1596 5821 isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
nickjillings@1596 5822
nickjillings@1596 5823 // Some non-html elements return undefined for offsetWidth, so check for null/undefined
nickjillings@1596 5824 // svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
nickjillings@1596 5825 // MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
nickjillings@1596 5826 if ( val <= 0 || val == null ) {
nickjillings@1596 5827 // Fall back to computed then uncomputed css if necessary
nickjillings@1596 5828 val = curCSS( elem, name, styles );
nickjillings@1596 5829 if ( val < 0 || val == null ) {
nickjillings@1596 5830 val = elem.style[ name ];
nickjillings@1596 5831 }
nickjillings@1596 5832
nickjillings@1596 5833 // Computed unit is not pixels. Stop here and return.
nickjillings@1596 5834 if ( rnumnonpx.test(val) ) {
nickjillings@1596 5835 return val;
nickjillings@1596 5836 }
nickjillings@1596 5837
nickjillings@1596 5838 // Check for style in case a browser which returns unreliable values
nickjillings@1596 5839 // for getComputedStyle silently falls back to the reliable elem.style
nickjillings@1596 5840 valueIsBorderBox = isBorderBox &&
nickjillings@1596 5841 ( support.boxSizingReliable() || val === elem.style[ name ] );
nickjillings@1596 5842
nickjillings@1596 5843 // Normalize "", auto, and prepare for extra
nickjillings@1596 5844 val = parseFloat( val ) || 0;
nickjillings@1596 5845 }
nickjillings@1596 5846
nickjillings@1596 5847 // Use the active box-sizing model to add/subtract irrelevant styles
nickjillings@1596 5848 return ( val +
nickjillings@1596 5849 augmentWidthOrHeight(
nickjillings@1596 5850 elem,
nickjillings@1596 5851 name,
nickjillings@1596 5852 extra || ( isBorderBox ? "border" : "content" ),
nickjillings@1596 5853 valueIsBorderBox,
nickjillings@1596 5854 styles
nickjillings@1596 5855 )
nickjillings@1596 5856 ) + "px";
nickjillings@1596 5857 }
nickjillings@1596 5858
nickjillings@1596 5859 function showHide( elements, show ) {
nickjillings@1596 5860 var display, elem, hidden,
nickjillings@1596 5861 values = [],
nickjillings@1596 5862 index = 0,
nickjillings@1596 5863 length = elements.length;
nickjillings@1596 5864
nickjillings@1596 5865 for ( ; index < length; index++ ) {
nickjillings@1596 5866 elem = elements[ index ];
nickjillings@1596 5867 if ( !elem.style ) {
nickjillings@1596 5868 continue;
nickjillings@1596 5869 }
nickjillings@1596 5870
nickjillings@1596 5871 values[ index ] = data_priv.get( elem, "olddisplay" );
nickjillings@1596 5872 display = elem.style.display;
nickjillings@1596 5873 if ( show ) {
nickjillings@1596 5874 // Reset the inline display of this element to learn if it is
nickjillings@1596 5875 // being hidden by cascaded rules or not
nickjillings@1596 5876 if ( !values[ index ] && display === "none" ) {
nickjillings@1596 5877 elem.style.display = "";
nickjillings@1596 5878 }
nickjillings@1596 5879
nickjillings@1596 5880 // Set elements which have been overridden with display: none
nickjillings@1596 5881 // in a stylesheet to whatever the default browser style is
nickjillings@1596 5882 // for such an element
nickjillings@1596 5883 if ( elem.style.display === "" && isHidden( elem ) ) {
nickjillings@1596 5884 values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) );
nickjillings@1596 5885 }
nickjillings@1596 5886 } else {
nickjillings@1596 5887 hidden = isHidden( elem );
nickjillings@1596 5888
nickjillings@1596 5889 if ( display !== "none" || !hidden ) {
nickjillings@1596 5890 data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) );
nickjillings@1596 5891 }
nickjillings@1596 5892 }
nickjillings@1596 5893 }
nickjillings@1596 5894
nickjillings@1596 5895 // Set the display of most of the elements in a second loop
nickjillings@1596 5896 // to avoid the constant reflow
nickjillings@1596 5897 for ( index = 0; index < length; index++ ) {
nickjillings@1596 5898 elem = elements[ index ];
nickjillings@1596 5899 if ( !elem.style ) {
nickjillings@1596 5900 continue;
nickjillings@1596 5901 }
nickjillings@1596 5902 if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
nickjillings@1596 5903 elem.style.display = show ? values[ index ] || "" : "none";
nickjillings@1596 5904 }
nickjillings@1596 5905 }
nickjillings@1596 5906
nickjillings@1596 5907 return elements;
nickjillings@1596 5908 }
nickjillings@1596 5909
nickjillings@1596 5910 jQuery.extend({
nickjillings@1596 5911
nickjillings@1596 5912 // Add in style property hooks for overriding the default
nickjillings@1596 5913 // behavior of getting and setting a style property
nickjillings@1596 5914 cssHooks: {
nickjillings@1596 5915 opacity: {
nickjillings@1596 5916 get: function( elem, computed ) {
nickjillings@1596 5917 if ( computed ) {
nickjillings@1596 5918
nickjillings@1596 5919 // We should always get a number back from opacity
nickjillings@1596 5920 var ret = curCSS( elem, "opacity" );
nickjillings@1596 5921 return ret === "" ? "1" : ret;
nickjillings@1596 5922 }
nickjillings@1596 5923 }
nickjillings@1596 5924 }
nickjillings@1596 5925 },
nickjillings@1596 5926
nickjillings@1596 5927 // Don't automatically add "px" to these possibly-unitless properties
nickjillings@1596 5928 cssNumber: {
nickjillings@1596 5929 "columnCount": true,
nickjillings@1596 5930 "fillOpacity": true,
nickjillings@1596 5931 "flexGrow": true,
nickjillings@1596 5932 "flexShrink": true,
nickjillings@1596 5933 "fontWeight": true,
nickjillings@1596 5934 "lineHeight": true,
nickjillings@1596 5935 "opacity": true,
nickjillings@1596 5936 "order": true,
nickjillings@1596 5937 "orphans": true,
nickjillings@1596 5938 "widows": true,
nickjillings@1596 5939 "zIndex": true,
nickjillings@1596 5940 "zoom": true
nickjillings@1596 5941 },
nickjillings@1596 5942
nickjillings@1596 5943 // Add in properties whose names you wish to fix before
nickjillings@1596 5944 // setting or getting the value
nickjillings@1596 5945 cssProps: {
nickjillings@1596 5946 "float": "cssFloat"
nickjillings@1596 5947 },
nickjillings@1596 5948
nickjillings@1596 5949 // Get and set the style property on a DOM Node
nickjillings@1596 5950 style: function( elem, name, value, extra ) {
nickjillings@1596 5951
nickjillings@1596 5952 // Don't set styles on text and comment nodes
nickjillings@1596 5953 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
nickjillings@1596 5954 return;
nickjillings@1596 5955 }
nickjillings@1596 5956
nickjillings@1596 5957 // Make sure that we're working with the right name
nickjillings@1596 5958 var ret, type, hooks,
nickjillings@1596 5959 origName = jQuery.camelCase( name ),
nickjillings@1596 5960 style = elem.style;
nickjillings@1596 5961
nickjillings@1596 5962 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) );
nickjillings@1596 5963
nickjillings@1596 5964 // Gets hook for the prefixed version, then unprefixed version
nickjillings@1596 5965 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1596 5966
nickjillings@1596 5967 // Check if we're setting a value
nickjillings@1596 5968 if ( value !== undefined ) {
nickjillings@1596 5969 type = typeof value;
nickjillings@1596 5970
nickjillings@1596 5971 // Convert "+=" or "-=" to relative numbers (#7345)
nickjillings@1596 5972 if ( type === "string" && (ret = rrelNum.exec( value )) ) {
nickjillings@1596 5973 value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) );
nickjillings@1596 5974 // Fixes bug #9237
nickjillings@1596 5975 type = "number";
nickjillings@1596 5976 }
nickjillings@1596 5977
nickjillings@1596 5978 // Make sure that null and NaN values aren't set (#7116)
nickjillings@1596 5979 if ( value == null || value !== value ) {
nickjillings@1596 5980 return;
nickjillings@1596 5981 }
nickjillings@1596 5982
nickjillings@1596 5983 // If a number, add 'px' to the (except for certain CSS properties)
nickjillings@1596 5984 if ( type === "number" && !jQuery.cssNumber[ origName ] ) {
nickjillings@1596 5985 value += "px";
nickjillings@1596 5986 }
nickjillings@1596 5987
nickjillings@1596 5988 // Support: IE9-11+
nickjillings@1596 5989 // background-* props affect original clone's values
nickjillings@1596 5990 if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
nickjillings@1596 5991 style[ name ] = "inherit";
nickjillings@1596 5992 }
nickjillings@1596 5993
nickjillings@1596 5994 // If a hook was provided, use that value, otherwise just set the specified value
nickjillings@1596 5995 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
nickjillings@1596 5996 style[ name ] = value;
nickjillings@1596 5997 }
nickjillings@1596 5998
nickjillings@1596 5999 } else {
nickjillings@1596 6000 // If a hook was provided get the non-computed value from there
nickjillings@1596 6001 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
nickjillings@1596 6002 return ret;
nickjillings@1596 6003 }
nickjillings@1596 6004
nickjillings@1596 6005 // Otherwise just get the value from the style object
nickjillings@1596 6006 return style[ name ];
nickjillings@1596 6007 }
nickjillings@1596 6008 },
nickjillings@1596 6009
nickjillings@1596 6010 css: function( elem, name, extra, styles ) {
nickjillings@1596 6011 var val, num, hooks,
nickjillings@1596 6012 origName = jQuery.camelCase( name );
nickjillings@1596 6013
nickjillings@1596 6014 // Make sure that we're working with the right name
nickjillings@1596 6015 name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) );
nickjillings@1596 6016
nickjillings@1596 6017 // Try prefixed name followed by the unprefixed name
nickjillings@1596 6018 hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
nickjillings@1596 6019
nickjillings@1596 6020 // If a hook was provided get the computed value from there
nickjillings@1596 6021 if ( hooks && "get" in hooks ) {
nickjillings@1596 6022 val = hooks.get( elem, true, extra );
nickjillings@1596 6023 }
nickjillings@1596 6024
nickjillings@1596 6025 // Otherwise, if a way to get the computed value exists, use that
nickjillings@1596 6026 if ( val === undefined ) {
nickjillings@1596 6027 val = curCSS( elem, name, styles );
nickjillings@1596 6028 }
nickjillings@1596 6029
nickjillings@1596 6030 // Convert "normal" to computed value
nickjillings@1596 6031 if ( val === "normal" && name in cssNormalTransform ) {
nickjillings@1596 6032 val = cssNormalTransform[ name ];
nickjillings@1596 6033 }
nickjillings@1596 6034
nickjillings@1596 6035 // Make numeric if forced or a qualifier was provided and val looks numeric
nickjillings@1596 6036 if ( extra === "" || extra ) {
nickjillings@1596 6037 num = parseFloat( val );
nickjillings@1596 6038 return extra === true || jQuery.isNumeric( num ) ? num || 0 : val;
nickjillings@1596 6039 }
nickjillings@1596 6040 return val;
nickjillings@1596 6041 }
nickjillings@1596 6042 });
nickjillings@1596 6043
nickjillings@1596 6044 jQuery.each([ "height", "width" ], function( i, name ) {
nickjillings@1596 6045 jQuery.cssHooks[ name ] = {
nickjillings@1596 6046 get: function( elem, computed, extra ) {
nickjillings@1596 6047 if ( computed ) {
nickjillings@1596 6048
nickjillings@1596 6049 // Certain elements can have dimension info if we invisibly show them
nickjillings@1596 6050 // but it must have a current display style that would benefit
nickjillings@1596 6051 return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ?
nickjillings@1596 6052 jQuery.swap( elem, cssShow, function() {
nickjillings@1596 6053 return getWidthOrHeight( elem, name, extra );
nickjillings@1596 6054 }) :
nickjillings@1596 6055 getWidthOrHeight( elem, name, extra );
nickjillings@1596 6056 }
nickjillings@1596 6057 },
nickjillings@1596 6058
nickjillings@1596 6059 set: function( elem, value, extra ) {
nickjillings@1596 6060 var styles = extra && getStyles( elem );
nickjillings@1596 6061 return setPositiveNumber( elem, value, extra ?
nickjillings@1596 6062 augmentWidthOrHeight(
nickjillings@1596 6063 elem,
nickjillings@1596 6064 name,
nickjillings@1596 6065 extra,
nickjillings@1596 6066 jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
nickjillings@1596 6067 styles
nickjillings@1596 6068 ) : 0
nickjillings@1596 6069 );
nickjillings@1596 6070 }
nickjillings@1596 6071 };
nickjillings@1596 6072 });
nickjillings@1596 6073
nickjillings@1596 6074 // Support: Android 2.3
nickjillings@1596 6075 jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
nickjillings@1596 6076 function( elem, computed ) {
nickjillings@1596 6077 if ( computed ) {
nickjillings@1596 6078 return jQuery.swap( elem, { "display": "inline-block" },
nickjillings@1596 6079 curCSS, [ elem, "marginRight" ] );
nickjillings@1596 6080 }
nickjillings@1596 6081 }
nickjillings@1596 6082 );
nickjillings@1596 6083
nickjillings@1596 6084 // These hooks are used by animate to expand properties
nickjillings@1596 6085 jQuery.each({
nickjillings@1596 6086 margin: "",
nickjillings@1596 6087 padding: "",
nickjillings@1596 6088 border: "Width"
nickjillings@1596 6089 }, function( prefix, suffix ) {
nickjillings@1596 6090 jQuery.cssHooks[ prefix + suffix ] = {
nickjillings@1596 6091 expand: function( value ) {
nickjillings@1596 6092 var i = 0,
nickjillings@1596 6093 expanded = {},
nickjillings@1596 6094
nickjillings@1596 6095 // Assumes a single number if not a string
nickjillings@1596 6096 parts = typeof value === "string" ? value.split(" ") : [ value ];
nickjillings@1596 6097
nickjillings@1596 6098 for ( ; i < 4; i++ ) {
nickjillings@1596 6099 expanded[ prefix + cssExpand[ i ] + suffix ] =
nickjillings@1596 6100 parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
nickjillings@1596 6101 }
nickjillings@1596 6102
nickjillings@1596 6103 return expanded;
nickjillings@1596 6104 }
nickjillings@1596 6105 };
nickjillings@1596 6106
nickjillings@1596 6107 if ( !rmargin.test( prefix ) ) {
nickjillings@1596 6108 jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
nickjillings@1596 6109 }
nickjillings@1596 6110 });
nickjillings@1596 6111
nickjillings@1596 6112 jQuery.fn.extend({
nickjillings@1596 6113 css: function( name, value ) {
nickjillings@1596 6114 return access( this, function( elem, name, value ) {
nickjillings@1596 6115 var styles, len,
nickjillings@1596 6116 map = {},
nickjillings@1596 6117 i = 0;
nickjillings@1596 6118
nickjillings@1596 6119 if ( jQuery.isArray( name ) ) {
nickjillings@1596 6120 styles = getStyles( elem );
nickjillings@1596 6121 len = name.length;
nickjillings@1596 6122
nickjillings@1596 6123 for ( ; i < len; i++ ) {
nickjillings@1596 6124 map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
nickjillings@1596 6125 }
nickjillings@1596 6126
nickjillings@1596 6127 return map;
nickjillings@1596 6128 }
nickjillings@1596 6129
nickjillings@1596 6130 return value !== undefined ?
nickjillings@1596 6131 jQuery.style( elem, name, value ) :
nickjillings@1596 6132 jQuery.css( elem, name );
nickjillings@1596 6133 }, name, value, arguments.length > 1 );
nickjillings@1596 6134 },
nickjillings@1596 6135 show: function() {
nickjillings@1596 6136 return showHide( this, true );
nickjillings@1596 6137 },
nickjillings@1596 6138 hide: function() {
nickjillings@1596 6139 return showHide( this );
nickjillings@1596 6140 },
nickjillings@1596 6141 toggle: function( state ) {
nickjillings@1596 6142 if ( typeof state === "boolean" ) {
nickjillings@1596 6143 return state ? this.show() : this.hide();
nickjillings@1596 6144 }
nickjillings@1596 6145
nickjillings@1596 6146 return this.each(function() {
nickjillings@1596 6147 if ( isHidden( this ) ) {
nickjillings@1596 6148 jQuery( this ).show();
nickjillings@1596 6149 } else {
nickjillings@1596 6150 jQuery( this ).hide();
nickjillings@1596 6151 }
nickjillings@1596 6152 });
nickjillings@1596 6153 }
nickjillings@1596 6154 });
nickjillings@1596 6155
nickjillings@1596 6156
nickjillings@1596 6157 function Tween( elem, options, prop, end, easing ) {
nickjillings@1596 6158 return new Tween.prototype.init( elem, options, prop, end, easing );
nickjillings@1596 6159 }
nickjillings@1596 6160 jQuery.Tween = Tween;
nickjillings@1596 6161
nickjillings@1596 6162 Tween.prototype = {
nickjillings@1596 6163 constructor: Tween,
nickjillings@1596 6164 init: function( elem, options, prop, end, easing, unit ) {
nickjillings@1596 6165 this.elem = elem;
nickjillings@1596 6166 this.prop = prop;
nickjillings@1596 6167 this.easing = easing || "swing";
nickjillings@1596 6168 this.options = options;
nickjillings@1596 6169 this.start = this.now = this.cur();
nickjillings@1596 6170 this.end = end;
nickjillings@1596 6171 this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
nickjillings@1596 6172 },
nickjillings@1596 6173 cur: function() {
nickjillings@1596 6174 var hooks = Tween.propHooks[ this.prop ];
nickjillings@1596 6175
nickjillings@1596 6176 return hooks && hooks.get ?
nickjillings@1596 6177 hooks.get( this ) :
nickjillings@1596 6178 Tween.propHooks._default.get( this );
nickjillings@1596 6179 },
nickjillings@1596 6180 run: function( percent ) {
nickjillings@1596 6181 var eased,
nickjillings@1596 6182 hooks = Tween.propHooks[ this.prop ];
nickjillings@1596 6183
nickjillings@1596 6184 if ( this.options.duration ) {
nickjillings@1596 6185 this.pos = eased = jQuery.easing[ this.easing ](
nickjillings@1596 6186 percent, this.options.duration * percent, 0, 1, this.options.duration
nickjillings@1596 6187 );
nickjillings@1596 6188 } else {
nickjillings@1596 6189 this.pos = eased = percent;
nickjillings@1596 6190 }
nickjillings@1596 6191 this.now = ( this.end - this.start ) * eased + this.start;
nickjillings@1596 6192
nickjillings@1596 6193 if ( this.options.step ) {
nickjillings@1596 6194 this.options.step.call( this.elem, this.now, this );
nickjillings@1596 6195 }
nickjillings@1596 6196
nickjillings@1596 6197 if ( hooks && hooks.set ) {
nickjillings@1596 6198 hooks.set( this );
nickjillings@1596 6199 } else {
nickjillings@1596 6200 Tween.propHooks._default.set( this );
nickjillings@1596 6201 }
nickjillings@1596 6202 return this;
nickjillings@1596 6203 }
nickjillings@1596 6204 };
nickjillings@1596 6205
nickjillings@1596 6206 Tween.prototype.init.prototype = Tween.prototype;
nickjillings@1596 6207
nickjillings@1596 6208 Tween.propHooks = {
nickjillings@1596 6209 _default: {
nickjillings@1596 6210 get: function( tween ) {
nickjillings@1596 6211 var result;
nickjillings@1596 6212
nickjillings@1596 6213 if ( tween.elem[ tween.prop ] != null &&
nickjillings@1596 6214 (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
nickjillings@1596 6215 return tween.elem[ tween.prop ];
nickjillings@1596 6216 }
nickjillings@1596 6217
nickjillings@1596 6218 // Passing an empty string as a 3rd parameter to .css will automatically
nickjillings@1596 6219 // attempt a parseFloat and fallback to a string if the parse fails.
nickjillings@1596 6220 // Simple values such as "10px" are parsed to Float;
nickjillings@1596 6221 // complex values such as "rotate(1rad)" are returned as-is.
nickjillings@1596 6222 result = jQuery.css( tween.elem, tween.prop, "" );
nickjillings@1596 6223 // Empty strings, null, undefined and "auto" are converted to 0.
nickjillings@1596 6224 return !result || result === "auto" ? 0 : result;
nickjillings@1596 6225 },
nickjillings@1596 6226 set: function( tween ) {
nickjillings@1596 6227 // Use step hook for back compat.
nickjillings@1596 6228 // Use cssHook if its there.
nickjillings@1596 6229 // Use .style if available and use plain properties where available.
nickjillings@1596 6230 if ( jQuery.fx.step[ tween.prop ] ) {
nickjillings@1596 6231 jQuery.fx.step[ tween.prop ]( tween );
nickjillings@1596 6232 } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
nickjillings@1596 6233 jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
nickjillings@1596 6234 } else {
nickjillings@1596 6235 tween.elem[ tween.prop ] = tween.now;
nickjillings@1596 6236 }
nickjillings@1596 6237 }
nickjillings@1596 6238 }
nickjillings@1596 6239 };
nickjillings@1596 6240
nickjillings@1596 6241 // Support: IE9
nickjillings@1596 6242 // Panic based approach to setting things on disconnected nodes
nickjillings@1596 6243 Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
nickjillings@1596 6244 set: function( tween ) {
nickjillings@1596 6245 if ( tween.elem.nodeType && tween.elem.parentNode ) {
nickjillings@1596 6246 tween.elem[ tween.prop ] = tween.now;
nickjillings@1596 6247 }
nickjillings@1596 6248 }
nickjillings@1596 6249 };
nickjillings@1596 6250
nickjillings@1596 6251 jQuery.easing = {
nickjillings@1596 6252 linear: function( p ) {
nickjillings@1596 6253 return p;
nickjillings@1596 6254 },
nickjillings@1596 6255 swing: function( p ) {
nickjillings@1596 6256 return 0.5 - Math.cos( p * Math.PI ) / 2;
nickjillings@1596 6257 }
nickjillings@1596 6258 };
nickjillings@1596 6259
nickjillings@1596 6260 jQuery.fx = Tween.prototype.init;
nickjillings@1596 6261
nickjillings@1596 6262 // Back Compat <1.8 extension point
nickjillings@1596 6263 jQuery.fx.step = {};
nickjillings@1596 6264
nickjillings@1596 6265
nickjillings@1596 6266
nickjillings@1596 6267
nickjillings@1596 6268 var
nickjillings@1596 6269 fxNow, timerId,
nickjillings@1596 6270 rfxtypes = /^(?:toggle|show|hide)$/,
nickjillings@1596 6271 rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
nickjillings@1596 6272 rrun = /queueHooks$/,
nickjillings@1596 6273 animationPrefilters = [ defaultPrefilter ],
nickjillings@1596 6274 tweeners = {
nickjillings@1596 6275 "*": [ function( prop, value ) {
nickjillings@1596 6276 var tween = this.createTween( prop, value ),
nickjillings@1596 6277 target = tween.cur(),
nickjillings@1596 6278 parts = rfxnum.exec( value ),
nickjillings@1596 6279 unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
nickjillings@1596 6280
nickjillings@1596 6281 // Starting value computation is required for potential unit mismatches
nickjillings@1596 6282 start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) &&
nickjillings@1596 6283 rfxnum.exec( jQuery.css( tween.elem, prop ) ),
nickjillings@1596 6284 scale = 1,
nickjillings@1596 6285 maxIterations = 20;
nickjillings@1596 6286
nickjillings@1596 6287 if ( start && start[ 3 ] !== unit ) {
nickjillings@1596 6288 // Trust units reported by jQuery.css
nickjillings@1596 6289 unit = unit || start[ 3 ];
nickjillings@1596 6290
nickjillings@1596 6291 // Make sure we update the tween properties later on
nickjillings@1596 6292 parts = parts || [];
nickjillings@1596 6293
nickjillings@1596 6294 // Iteratively approximate from a nonzero starting point
nickjillings@1596 6295 start = +target || 1;
nickjillings@1596 6296
nickjillings@1596 6297 do {
nickjillings@1596 6298 // If previous iteration zeroed out, double until we get *something*.
nickjillings@1596 6299 // Use string for doubling so we don't accidentally see scale as unchanged below
nickjillings@1596 6300 scale = scale || ".5";
nickjillings@1596 6301
nickjillings@1596 6302 // Adjust and apply
nickjillings@1596 6303 start = start / scale;
nickjillings@1596 6304 jQuery.style( tween.elem, prop, start + unit );
nickjillings@1596 6305
nickjillings@1596 6306 // Update scale, tolerating zero or NaN from tween.cur(),
nickjillings@1596 6307 // break the loop if scale is unchanged or perfect, or if we've just had enough
nickjillings@1596 6308 } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations );
nickjillings@1596 6309 }
nickjillings@1596 6310
nickjillings@1596 6311 // Update tween properties
nickjillings@1596 6312 if ( parts ) {
nickjillings@1596 6313 start = tween.start = +start || +target || 0;
nickjillings@1596 6314 tween.unit = unit;
nickjillings@1596 6315 // If a +=/-= token was provided, we're doing a relative animation
nickjillings@1596 6316 tween.end = parts[ 1 ] ?
nickjillings@1596 6317 start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
nickjillings@1596 6318 +parts[ 2 ];
nickjillings@1596 6319 }
nickjillings@1596 6320
nickjillings@1596 6321 return tween;
nickjillings@1596 6322 } ]
nickjillings@1596 6323 };
nickjillings@1596 6324
nickjillings@1596 6325 // Animations created synchronously will run synchronously
nickjillings@1596 6326 function createFxNow() {
nickjillings@1596 6327 setTimeout(function() {
nickjillings@1596 6328 fxNow = undefined;
nickjillings@1596 6329 });
nickjillings@1596 6330 return ( fxNow = jQuery.now() );
nickjillings@1596 6331 }
nickjillings@1596 6332
nickjillings@1596 6333 // Generate parameters to create a standard animation
nickjillings@1596 6334 function genFx( type, includeWidth ) {
nickjillings@1596 6335 var which,
nickjillings@1596 6336 i = 0,
nickjillings@1596 6337 attrs = { height: type };
nickjillings@1596 6338
nickjillings@1596 6339 // If we include width, step value is 1 to do all cssExpand values,
nickjillings@1596 6340 // otherwise step value is 2 to skip over Left and Right
nickjillings@1596 6341 includeWidth = includeWidth ? 1 : 0;
nickjillings@1596 6342 for ( ; i < 4 ; i += 2 - includeWidth ) {
nickjillings@1596 6343 which = cssExpand[ i ];
nickjillings@1596 6344 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
nickjillings@1596 6345 }
nickjillings@1596 6346
nickjillings@1596 6347 if ( includeWidth ) {
nickjillings@1596 6348 attrs.opacity = attrs.width = type;
nickjillings@1596 6349 }
nickjillings@1596 6350
nickjillings@1596 6351 return attrs;
nickjillings@1596 6352 }
nickjillings@1596 6353
nickjillings@1596 6354 function createTween( value, prop, animation ) {
nickjillings@1596 6355 var tween,
nickjillings@1596 6356 collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
nickjillings@1596 6357 index = 0,
nickjillings@1596 6358 length = collection.length;
nickjillings@1596 6359 for ( ; index < length; index++ ) {
nickjillings@1596 6360 if ( (tween = collection[ index ].call( animation, prop, value )) ) {
nickjillings@1596 6361
nickjillings@1596 6362 // We're done with this property
nickjillings@1596 6363 return tween;
nickjillings@1596 6364 }
nickjillings@1596 6365 }
nickjillings@1596 6366 }
nickjillings@1596 6367
nickjillings@1596 6368 function defaultPrefilter( elem, props, opts ) {
nickjillings@1596 6369 /* jshint validthis: true */
nickjillings@1596 6370 var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
nickjillings@1596 6371 anim = this,
nickjillings@1596 6372 orig = {},
nickjillings@1596 6373 style = elem.style,
nickjillings@1596 6374 hidden = elem.nodeType && isHidden( elem ),
nickjillings@1596 6375 dataShow = data_priv.get( elem, "fxshow" );
nickjillings@1596 6376
nickjillings@1596 6377 // Handle queue: false promises
nickjillings@1596 6378 if ( !opts.queue ) {
nickjillings@1596 6379 hooks = jQuery._queueHooks( elem, "fx" );
nickjillings@1596 6380 if ( hooks.unqueued == null ) {
nickjillings@1596 6381 hooks.unqueued = 0;
nickjillings@1596 6382 oldfire = hooks.empty.fire;
nickjillings@1596 6383 hooks.empty.fire = function() {
nickjillings@1596 6384 if ( !hooks.unqueued ) {
nickjillings@1596 6385 oldfire();
nickjillings@1596 6386 }
nickjillings@1596 6387 };
nickjillings@1596 6388 }
nickjillings@1596 6389 hooks.unqueued++;
nickjillings@1596 6390
nickjillings@1596 6391 anim.always(function() {
nickjillings@1596 6392 // Ensure the complete handler is called before this completes
nickjillings@1596 6393 anim.always(function() {
nickjillings@1596 6394 hooks.unqueued--;
nickjillings@1596 6395 if ( !jQuery.queue( elem, "fx" ).length ) {
nickjillings@1596 6396 hooks.empty.fire();
nickjillings@1596 6397 }
nickjillings@1596 6398 });
nickjillings@1596 6399 });
nickjillings@1596 6400 }
nickjillings@1596 6401
nickjillings@1596 6402 // Height/width overflow pass
nickjillings@1596 6403 if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
nickjillings@1596 6404 // Make sure that nothing sneaks out
nickjillings@1596 6405 // Record all 3 overflow attributes because IE9-10 do not
nickjillings@1596 6406 // change the overflow attribute when overflowX and
nickjillings@1596 6407 // overflowY are set to the same value
nickjillings@1596 6408 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
nickjillings@1596 6409
nickjillings@1596 6410 // Set display property to inline-block for height/width
nickjillings@1596 6411 // animations on inline elements that are having width/height animated
nickjillings@1596 6412 display = jQuery.css( elem, "display" );
nickjillings@1596 6413
nickjillings@1596 6414 // Test default display if display is currently "none"
nickjillings@1596 6415 checkDisplay = display === "none" ?
nickjillings@1596 6416 data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
nickjillings@1596 6417
nickjillings@1596 6418 if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
nickjillings@1596 6419 style.display = "inline-block";
nickjillings@1596 6420 }
nickjillings@1596 6421 }
nickjillings@1596 6422
nickjillings@1596 6423 if ( opts.overflow ) {
nickjillings@1596 6424 style.overflow = "hidden";
nickjillings@1596 6425 anim.always(function() {
nickjillings@1596 6426 style.overflow = opts.overflow[ 0 ];
nickjillings@1596 6427 style.overflowX = opts.overflow[ 1 ];
nickjillings@1596 6428 style.overflowY = opts.overflow[ 2 ];
nickjillings@1596 6429 });
nickjillings@1596 6430 }
nickjillings@1596 6431
nickjillings@1596 6432 // show/hide pass
nickjillings@1596 6433 for ( prop in props ) {
nickjillings@1596 6434 value = props[ prop ];
nickjillings@1596 6435 if ( rfxtypes.exec( value ) ) {
nickjillings@1596 6436 delete props[ prop ];
nickjillings@1596 6437 toggle = toggle || value === "toggle";
nickjillings@1596 6438 if ( value === ( hidden ? "hide" : "show" ) ) {
nickjillings@1596 6439
nickjillings@1596 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@1596 6441 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
nickjillings@1596 6442 hidden = true;
nickjillings@1596 6443 } else {
nickjillings@1596 6444 continue;
nickjillings@1596 6445 }
nickjillings@1596 6446 }
nickjillings@1596 6447 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
nickjillings@1596 6448
nickjillings@1596 6449 // Any non-fx value stops us from restoring the original display value
nickjillings@1596 6450 } else {
nickjillings@1596 6451 display = undefined;
nickjillings@1596 6452 }
nickjillings@1596 6453 }
nickjillings@1596 6454
nickjillings@1596 6455 if ( !jQuery.isEmptyObject( orig ) ) {
nickjillings@1596 6456 if ( dataShow ) {
nickjillings@1596 6457 if ( "hidden" in dataShow ) {
nickjillings@1596 6458 hidden = dataShow.hidden;
nickjillings@1596 6459 }
nickjillings@1596 6460 } else {
nickjillings@1596 6461 dataShow = data_priv.access( elem, "fxshow", {} );
nickjillings@1596 6462 }
nickjillings@1596 6463
nickjillings@1596 6464 // Store state if its toggle - enables .stop().toggle() to "reverse"
nickjillings@1596 6465 if ( toggle ) {
nickjillings@1596 6466 dataShow.hidden = !hidden;
nickjillings@1596 6467 }
nickjillings@1596 6468 if ( hidden ) {
nickjillings@1596 6469 jQuery( elem ).show();
nickjillings@1596 6470 } else {
nickjillings@1596 6471 anim.done(function() {
nickjillings@1596 6472 jQuery( elem ).hide();
nickjillings@1596 6473 });
nickjillings@1596 6474 }
nickjillings@1596 6475 anim.done(function() {
nickjillings@1596 6476 var prop;
nickjillings@1596 6477
nickjillings@1596 6478 data_priv.remove( elem, "fxshow" );
nickjillings@1596 6479 for ( prop in orig ) {
nickjillings@1596 6480 jQuery.style( elem, prop, orig[ prop ] );
nickjillings@1596 6481 }
nickjillings@1596 6482 });
nickjillings@1596 6483 for ( prop in orig ) {
nickjillings@1596 6484 tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
nickjillings@1596 6485
nickjillings@1596 6486 if ( !( prop in dataShow ) ) {
nickjillings@1596 6487 dataShow[ prop ] = tween.start;
nickjillings@1596 6488 if ( hidden ) {
nickjillings@1596 6489 tween.end = tween.start;
nickjillings@1596 6490 tween.start = prop === "width" || prop === "height" ? 1 : 0;
nickjillings@1596 6491 }
nickjillings@1596 6492 }
nickjillings@1596 6493 }
nickjillings@1596 6494
nickjillings@1596 6495 // If this is a noop like .hide().hide(), restore an overwritten display value
nickjillings@1596 6496 } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) {
nickjillings@1596 6497 style.display = display;
nickjillings@1596 6498 }
nickjillings@1596 6499 }
nickjillings@1596 6500
nickjillings@1596 6501 function propFilter( props, specialEasing ) {
nickjillings@1596 6502 var index, name, easing, value, hooks;
nickjillings@1596 6503
nickjillings@1596 6504 // camelCase, specialEasing and expand cssHook pass
nickjillings@1596 6505 for ( index in props ) {
nickjillings@1596 6506 name = jQuery.camelCase( index );
nickjillings@1596 6507 easing = specialEasing[ name ];
nickjillings@1596 6508 value = props[ index ];
nickjillings@1596 6509 if ( jQuery.isArray( value ) ) {
nickjillings@1596 6510 easing = value[ 1 ];
nickjillings@1596 6511 value = props[ index ] = value[ 0 ];
nickjillings@1596 6512 }
nickjillings@1596 6513
nickjillings@1596 6514 if ( index !== name ) {
nickjillings@1596 6515 props[ name ] = value;
nickjillings@1596 6516 delete props[ index ];
nickjillings@1596 6517 }
nickjillings@1596 6518
nickjillings@1596 6519 hooks = jQuery.cssHooks[ name ];
nickjillings@1596 6520 if ( hooks && "expand" in hooks ) {
nickjillings@1596 6521 value = hooks.expand( value );
nickjillings@1596 6522 delete props[ name ];
nickjillings@1596 6523
nickjillings@1596 6524 // Not quite $.extend, this won't overwrite existing keys.
nickjillings@1596 6525 // Reusing 'index' because we have the correct "name"
nickjillings@1596 6526 for ( index in value ) {
nickjillings@1596 6527 if ( !( index in props ) ) {
nickjillings@1596 6528 props[ index ] = value[ index ];
nickjillings@1596 6529 specialEasing[ index ] = easing;
nickjillings@1596 6530 }
nickjillings@1596 6531 }
nickjillings@1596 6532 } else {
nickjillings@1596 6533 specialEasing[ name ] = easing;
nickjillings@1596 6534 }
nickjillings@1596 6535 }
nickjillings@1596 6536 }
nickjillings@1596 6537
nickjillings@1596 6538 function Animation( elem, properties, options ) {
nickjillings@1596 6539 var result,
nickjillings@1596 6540 stopped,
nickjillings@1596 6541 index = 0,
nickjillings@1596 6542 length = animationPrefilters.length,
nickjillings@1596 6543 deferred = jQuery.Deferred().always( function() {
nickjillings@1596 6544 // Don't match elem in the :animated selector
nickjillings@1596 6545 delete tick.elem;
nickjillings@1596 6546 }),
nickjillings@1596 6547 tick = function() {
nickjillings@1596 6548 if ( stopped ) {
nickjillings@1596 6549 return false;
nickjillings@1596 6550 }
nickjillings@1596 6551 var currentTime = fxNow || createFxNow(),
nickjillings@1596 6552 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
nickjillings@1596 6553 // Support: Android 2.3
nickjillings@1596 6554 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
nickjillings@1596 6555 temp = remaining / animation.duration || 0,
nickjillings@1596 6556 percent = 1 - temp,
nickjillings@1596 6557 index = 0,
nickjillings@1596 6558 length = animation.tweens.length;
nickjillings@1596 6559
nickjillings@1596 6560 for ( ; index < length ; index++ ) {
nickjillings@1596 6561 animation.tweens[ index ].run( percent );
nickjillings@1596 6562 }
nickjillings@1596 6563
nickjillings@1596 6564 deferred.notifyWith( elem, [ animation, percent, remaining ]);
nickjillings@1596 6565
nickjillings@1596 6566 if ( percent < 1 && length ) {
nickjillings@1596 6567 return remaining;
nickjillings@1596 6568 } else {
nickjillings@1596 6569 deferred.resolveWith( elem, [ animation ] );
nickjillings@1596 6570 return false;
nickjillings@1596 6571 }
nickjillings@1596 6572 },
nickjillings@1596 6573 animation = deferred.promise({
nickjillings@1596 6574 elem: elem,
nickjillings@1596 6575 props: jQuery.extend( {}, properties ),
nickjillings@1596 6576 opts: jQuery.extend( true, { specialEasing: {} }, options ),
nickjillings@1596 6577 originalProperties: properties,
nickjillings@1596 6578 originalOptions: options,
nickjillings@1596 6579 startTime: fxNow || createFxNow(),
nickjillings@1596 6580 duration: options.duration,
nickjillings@1596 6581 tweens: [],
nickjillings@1596 6582 createTween: function( prop, end ) {
nickjillings@1596 6583 var tween = jQuery.Tween( elem, animation.opts, prop, end,
nickjillings@1596 6584 animation.opts.specialEasing[ prop ] || animation.opts.easing );
nickjillings@1596 6585 animation.tweens.push( tween );
nickjillings@1596 6586 return tween;
nickjillings@1596 6587 },
nickjillings@1596 6588 stop: function( gotoEnd ) {
nickjillings@1596 6589 var index = 0,
nickjillings@1596 6590 // If we are going to the end, we want to run all the tweens
nickjillings@1596 6591 // otherwise we skip this part
nickjillings@1596 6592 length = gotoEnd ? animation.tweens.length : 0;
nickjillings@1596 6593 if ( stopped ) {
nickjillings@1596 6594 return this;
nickjillings@1596 6595 }
nickjillings@1596 6596 stopped = true;
nickjillings@1596 6597 for ( ; index < length ; index++ ) {
nickjillings@1596 6598 animation.tweens[ index ].run( 1 );
nickjillings@1596 6599 }
nickjillings@1596 6600
nickjillings@1596 6601 // Resolve when we played the last frame; otherwise, reject
nickjillings@1596 6602 if ( gotoEnd ) {
nickjillings@1596 6603 deferred.resolveWith( elem, [ animation, gotoEnd ] );
nickjillings@1596 6604 } else {
nickjillings@1596 6605 deferred.rejectWith( elem, [ animation, gotoEnd ] );
nickjillings@1596 6606 }
nickjillings@1596 6607 return this;
nickjillings@1596 6608 }
nickjillings@1596 6609 }),
nickjillings@1596 6610 props = animation.props;
nickjillings@1596 6611
nickjillings@1596 6612 propFilter( props, animation.opts.specialEasing );
nickjillings@1596 6613
nickjillings@1596 6614 for ( ; index < length ; index++ ) {
nickjillings@1596 6615 result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
nickjillings@1596 6616 if ( result ) {
nickjillings@1596 6617 return result;
nickjillings@1596 6618 }
nickjillings@1596 6619 }
nickjillings@1596 6620
nickjillings@1596 6621 jQuery.map( props, createTween, animation );
nickjillings@1596 6622
nickjillings@1596 6623 if ( jQuery.isFunction( animation.opts.start ) ) {
nickjillings@1596 6624 animation.opts.start.call( elem, animation );
nickjillings@1596 6625 }
nickjillings@1596 6626
nickjillings@1596 6627 jQuery.fx.timer(
nickjillings@1596 6628 jQuery.extend( tick, {
nickjillings@1596 6629 elem: elem,
nickjillings@1596 6630 anim: animation,
nickjillings@1596 6631 queue: animation.opts.queue
nickjillings@1596 6632 })
nickjillings@1596 6633 );
nickjillings@1596 6634
nickjillings@1596 6635 // attach callbacks from options
nickjillings@1596 6636 return animation.progress( animation.opts.progress )
nickjillings@1596 6637 .done( animation.opts.done, animation.opts.complete )
nickjillings@1596 6638 .fail( animation.opts.fail )
nickjillings@1596 6639 .always( animation.opts.always );
nickjillings@1596 6640 }
nickjillings@1596 6641
nickjillings@1596 6642 jQuery.Animation = jQuery.extend( Animation, {
nickjillings@1596 6643
nickjillings@1596 6644 tweener: function( props, callback ) {
nickjillings@1596 6645 if ( jQuery.isFunction( props ) ) {
nickjillings@1596 6646 callback = props;
nickjillings@1596 6647 props = [ "*" ];
nickjillings@1596 6648 } else {
nickjillings@1596 6649 props = props.split(" ");
nickjillings@1596 6650 }
nickjillings@1596 6651
nickjillings@1596 6652 var prop,
nickjillings@1596 6653 index = 0,
nickjillings@1596 6654 length = props.length;
nickjillings@1596 6655
nickjillings@1596 6656 for ( ; index < length ; index++ ) {
nickjillings@1596 6657 prop = props[ index ];
nickjillings@1596 6658 tweeners[ prop ] = tweeners[ prop ] || [];
nickjillings@1596 6659 tweeners[ prop ].unshift( callback );
nickjillings@1596 6660 }
nickjillings@1596 6661 },
nickjillings@1596 6662
nickjillings@1596 6663 prefilter: function( callback, prepend ) {
nickjillings@1596 6664 if ( prepend ) {
nickjillings@1596 6665 animationPrefilters.unshift( callback );
nickjillings@1596 6666 } else {
nickjillings@1596 6667 animationPrefilters.push( callback );
nickjillings@1596 6668 }
nickjillings@1596 6669 }
nickjillings@1596 6670 });
nickjillings@1596 6671
nickjillings@1596 6672 jQuery.speed = function( speed, easing, fn ) {
nickjillings@1596 6673 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
nickjillings@1596 6674 complete: fn || !fn && easing ||
nickjillings@1596 6675 jQuery.isFunction( speed ) && speed,
nickjillings@1596 6676 duration: speed,
nickjillings@1596 6677 easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
nickjillings@1596 6678 };
nickjillings@1596 6679
nickjillings@1596 6680 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
nickjillings@1596 6681 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
nickjillings@1596 6682
nickjillings@1596 6683 // Normalize opt.queue - true/undefined/null -> "fx"
nickjillings@1596 6684 if ( opt.queue == null || opt.queue === true ) {
nickjillings@1596 6685 opt.queue = "fx";
nickjillings@1596 6686 }
nickjillings@1596 6687
nickjillings@1596 6688 // Queueing
nickjillings@1596 6689 opt.old = opt.complete;
nickjillings@1596 6690
nickjillings@1596 6691 opt.complete = function() {
nickjillings@1596 6692 if ( jQuery.isFunction( opt.old ) ) {
nickjillings@1596 6693 opt.old.call( this );
nickjillings@1596 6694 }
nickjillings@1596 6695
nickjillings@1596 6696 if ( opt.queue ) {
nickjillings@1596 6697 jQuery.dequeue( this, opt.queue );
nickjillings@1596 6698 }
nickjillings@1596 6699 };
nickjillings@1596 6700
nickjillings@1596 6701 return opt;
nickjillings@1596 6702 };
nickjillings@1596 6703
nickjillings@1596 6704 jQuery.fn.extend({
nickjillings@1596 6705 fadeTo: function( speed, to, easing, callback ) {
nickjillings@1596 6706
nickjillings@1596 6707 // Show any hidden elements after setting opacity to 0
nickjillings@1596 6708 return this.filter( isHidden ).css( "opacity", 0 ).show()
nickjillings@1596 6709
nickjillings@1596 6710 // Animate to the value specified
nickjillings@1596 6711 .end().animate({ opacity: to }, speed, easing, callback );
nickjillings@1596 6712 },
nickjillings@1596 6713 animate: function( prop, speed, easing, callback ) {
nickjillings@1596 6714 var empty = jQuery.isEmptyObject( prop ),
nickjillings@1596 6715 optall = jQuery.speed( speed, easing, callback ),
nickjillings@1596 6716 doAnimation = function() {
nickjillings@1596 6717 // Operate on a copy of prop so per-property easing won't be lost
nickjillings@1596 6718 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
nickjillings@1596 6719
nickjillings@1596 6720 // Empty animations, or finishing resolves immediately
nickjillings@1596 6721 if ( empty || data_priv.get( this, "finish" ) ) {
nickjillings@1596 6722 anim.stop( true );
nickjillings@1596 6723 }
nickjillings@1596 6724 };
nickjillings@1596 6725 doAnimation.finish = doAnimation;
nickjillings@1596 6726
nickjillings@1596 6727 return empty || optall.queue === false ?
nickjillings@1596 6728 this.each( doAnimation ) :
nickjillings@1596 6729 this.queue( optall.queue, doAnimation );
nickjillings@1596 6730 },
nickjillings@1596 6731 stop: function( type, clearQueue, gotoEnd ) {
nickjillings@1596 6732 var stopQueue = function( hooks ) {
nickjillings@1596 6733 var stop = hooks.stop;
nickjillings@1596 6734 delete hooks.stop;
nickjillings@1596 6735 stop( gotoEnd );
nickjillings@1596 6736 };
nickjillings@1596 6737
nickjillings@1596 6738 if ( typeof type !== "string" ) {
nickjillings@1596 6739 gotoEnd = clearQueue;
nickjillings@1596 6740 clearQueue = type;
nickjillings@1596 6741 type = undefined;
nickjillings@1596 6742 }
nickjillings@1596 6743 if ( clearQueue && type !== false ) {
nickjillings@1596 6744 this.queue( type || "fx", [] );
nickjillings@1596 6745 }
nickjillings@1596 6746
nickjillings@1596 6747 return this.each(function() {
nickjillings@1596 6748 var dequeue = true,
nickjillings@1596 6749 index = type != null && type + "queueHooks",
nickjillings@1596 6750 timers = jQuery.timers,
nickjillings@1596 6751 data = data_priv.get( this );
nickjillings@1596 6752
nickjillings@1596 6753 if ( index ) {
nickjillings@1596 6754 if ( data[ index ] && data[ index ].stop ) {
nickjillings@1596 6755 stopQueue( data[ index ] );
nickjillings@1596 6756 }
nickjillings@1596 6757 } else {
nickjillings@1596 6758 for ( index in data ) {
nickjillings@1596 6759 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
nickjillings@1596 6760 stopQueue( data[ index ] );
nickjillings@1596 6761 }
nickjillings@1596 6762 }
nickjillings@1596 6763 }
nickjillings@1596 6764
nickjillings@1596 6765 for ( index = timers.length; index--; ) {
nickjillings@1596 6766 if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
nickjillings@1596 6767 timers[ index ].anim.stop( gotoEnd );
nickjillings@1596 6768 dequeue = false;
nickjillings@1596 6769 timers.splice( index, 1 );
nickjillings@1596 6770 }
nickjillings@1596 6771 }
nickjillings@1596 6772
nickjillings@1596 6773 // Start the next in the queue if the last step wasn't forced.
nickjillings@1596 6774 // Timers currently will call their complete callbacks, which
nickjillings@1596 6775 // will dequeue but only if they were gotoEnd.
nickjillings@1596 6776 if ( dequeue || !gotoEnd ) {
nickjillings@1596 6777 jQuery.dequeue( this, type );
nickjillings@1596 6778 }
nickjillings@1596 6779 });
nickjillings@1596 6780 },
nickjillings@1596 6781 finish: function( type ) {
nickjillings@1596 6782 if ( type !== false ) {
nickjillings@1596 6783 type = type || "fx";
nickjillings@1596 6784 }
nickjillings@1596 6785 return this.each(function() {
nickjillings@1596 6786 var index,
nickjillings@1596 6787 data = data_priv.get( this ),
nickjillings@1596 6788 queue = data[ type + "queue" ],
nickjillings@1596 6789 hooks = data[ type + "queueHooks" ],
nickjillings@1596 6790 timers = jQuery.timers,
nickjillings@1596 6791 length = queue ? queue.length : 0;
nickjillings@1596 6792
nickjillings@1596 6793 // Enable finishing flag on private data
nickjillings@1596 6794 data.finish = true;
nickjillings@1596 6795
nickjillings@1596 6796 // Empty the queue first
nickjillings@1596 6797 jQuery.queue( this, type, [] );
nickjillings@1596 6798
nickjillings@1596 6799 if ( hooks && hooks.stop ) {
nickjillings@1596 6800 hooks.stop.call( this, true );
nickjillings@1596 6801 }
nickjillings@1596 6802
nickjillings@1596 6803 // Look for any active animations, and finish them
nickjillings@1596 6804 for ( index = timers.length; index--; ) {
nickjillings@1596 6805 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
nickjillings@1596 6806 timers[ index ].anim.stop( true );
nickjillings@1596 6807 timers.splice( index, 1 );
nickjillings@1596 6808 }
nickjillings@1596 6809 }
nickjillings@1596 6810
nickjillings@1596 6811 // Look for any animations in the old queue and finish them
nickjillings@1596 6812 for ( index = 0; index < length; index++ ) {
nickjillings@1596 6813 if ( queue[ index ] && queue[ index ].finish ) {
nickjillings@1596 6814 queue[ index ].finish.call( this );
nickjillings@1596 6815 }
nickjillings@1596 6816 }
nickjillings@1596 6817
nickjillings@1596 6818 // Turn off finishing flag
nickjillings@1596 6819 delete data.finish;
nickjillings@1596 6820 });
nickjillings@1596 6821 }
nickjillings@1596 6822 });
nickjillings@1596 6823
nickjillings@1596 6824 jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
nickjillings@1596 6825 var cssFn = jQuery.fn[ name ];
nickjillings@1596 6826 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1596 6827 return speed == null || typeof speed === "boolean" ?
nickjillings@1596 6828 cssFn.apply( this, arguments ) :
nickjillings@1596 6829 this.animate( genFx( name, true ), speed, easing, callback );
nickjillings@1596 6830 };
nickjillings@1596 6831 });
nickjillings@1596 6832
nickjillings@1596 6833 // Generate shortcuts for custom animations
nickjillings@1596 6834 jQuery.each({
nickjillings@1596 6835 slideDown: genFx("show"),
nickjillings@1596 6836 slideUp: genFx("hide"),
nickjillings@1596 6837 slideToggle: genFx("toggle"),
nickjillings@1596 6838 fadeIn: { opacity: "show" },
nickjillings@1596 6839 fadeOut: { opacity: "hide" },
nickjillings@1596 6840 fadeToggle: { opacity: "toggle" }
nickjillings@1596 6841 }, function( name, props ) {
nickjillings@1596 6842 jQuery.fn[ name ] = function( speed, easing, callback ) {
nickjillings@1596 6843 return this.animate( props, speed, easing, callback );
nickjillings@1596 6844 };
nickjillings@1596 6845 });
nickjillings@1596 6846
nickjillings@1596 6847 jQuery.timers = [];
nickjillings@1596 6848 jQuery.fx.tick = function() {
nickjillings@1596 6849 var timer,
nickjillings@1596 6850 i = 0,
nickjillings@1596 6851 timers = jQuery.timers;
nickjillings@1596 6852
nickjillings@1596 6853 fxNow = jQuery.now();
nickjillings@1596 6854
nickjillings@1596 6855 for ( ; i < timers.length; i++ ) {
nickjillings@1596 6856 timer = timers[ i ];
nickjillings@1596 6857 // Checks the timer has not already been removed
nickjillings@1596 6858 if ( !timer() && timers[ i ] === timer ) {
nickjillings@1596 6859 timers.splice( i--, 1 );
nickjillings@1596 6860 }
nickjillings@1596 6861 }
nickjillings@1596 6862
nickjillings@1596 6863 if ( !timers.length ) {
nickjillings@1596 6864 jQuery.fx.stop();
nickjillings@1596 6865 }
nickjillings@1596 6866 fxNow = undefined;
nickjillings@1596 6867 };
nickjillings@1596 6868
nickjillings@1596 6869 jQuery.fx.timer = function( timer ) {
nickjillings@1596 6870 jQuery.timers.push( timer );
nickjillings@1596 6871 if ( timer() ) {
nickjillings@1596 6872 jQuery.fx.start();
nickjillings@1596 6873 } else {
nickjillings@1596 6874 jQuery.timers.pop();
nickjillings@1596 6875 }
nickjillings@1596 6876 };
nickjillings@1596 6877
nickjillings@1596 6878 jQuery.fx.interval = 13;
nickjillings@1596 6879
nickjillings@1596 6880 jQuery.fx.start = function() {
nickjillings@1596 6881 if ( !timerId ) {
nickjillings@1596 6882 timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
nickjillings@1596 6883 }
nickjillings@1596 6884 };
nickjillings@1596 6885
nickjillings@1596 6886 jQuery.fx.stop = function() {
nickjillings@1596 6887 clearInterval( timerId );
nickjillings@1596 6888 timerId = null;
nickjillings@1596 6889 };
nickjillings@1596 6890
nickjillings@1596 6891 jQuery.fx.speeds = {
nickjillings@1596 6892 slow: 600,
nickjillings@1596 6893 fast: 200,
nickjillings@1596 6894 // Default speed
nickjillings@1596 6895 _default: 400
nickjillings@1596 6896 };
nickjillings@1596 6897
nickjillings@1596 6898
nickjillings@1596 6899 // Based off of the plugin by Clint Helfers, with permission.
nickjillings@1596 6900 // http://blindsignals.com/index.php/2009/07/jquery-delay/
nickjillings@1596 6901 jQuery.fn.delay = function( time, type ) {
nickjillings@1596 6902 time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
nickjillings@1596 6903 type = type || "fx";
nickjillings@1596 6904
nickjillings@1596 6905 return this.queue( type, function( next, hooks ) {
nickjillings@1596 6906 var timeout = setTimeout( next, time );
nickjillings@1596 6907 hooks.stop = function() {
nickjillings@1596 6908 clearTimeout( timeout );
nickjillings@1596 6909 };
nickjillings@1596 6910 });
nickjillings@1596 6911 };
nickjillings@1596 6912
nickjillings@1596 6913
nickjillings@1596 6914 (function() {
nickjillings@1596 6915 var input = document.createElement( "input" ),
nickjillings@1596 6916 select = document.createElement( "select" ),
nickjillings@1596 6917 opt = select.appendChild( document.createElement( "option" ) );
nickjillings@1596 6918
nickjillings@1596 6919 input.type = "checkbox";
nickjillings@1596 6920
nickjillings@1596 6921 // Support: iOS<=5.1, Android<=4.2+
nickjillings@1596 6922 // Default value for a checkbox should be "on"
nickjillings@1596 6923 support.checkOn = input.value !== "";
nickjillings@1596 6924
nickjillings@1596 6925 // Support: IE<=11+
nickjillings@1596 6926 // Must access selectedIndex to make default options select
nickjillings@1596 6927 support.optSelected = opt.selected;
nickjillings@1596 6928
nickjillings@1596 6929 // Support: Android<=2.3
nickjillings@1596 6930 // Options inside disabled selects are incorrectly marked as disabled
nickjillings@1596 6931 select.disabled = true;
nickjillings@1596 6932 support.optDisabled = !opt.disabled;
nickjillings@1596 6933
nickjillings@1596 6934 // Support: IE<=11+
nickjillings@1596 6935 // An input loses its value after becoming a radio
nickjillings@1596 6936 input = document.createElement( "input" );
nickjillings@1596 6937 input.value = "t";
nickjillings@1596 6938 input.type = "radio";
nickjillings@1596 6939 support.radioValue = input.value === "t";
nickjillings@1596 6940 })();
nickjillings@1596 6941
nickjillings@1596 6942
nickjillings@1596 6943 var nodeHook, boolHook,
nickjillings@1596 6944 attrHandle = jQuery.expr.attrHandle;
nickjillings@1596 6945
nickjillings@1596 6946 jQuery.fn.extend({
nickjillings@1596 6947 attr: function( name, value ) {
nickjillings@1596 6948 return access( this, jQuery.attr, name, value, arguments.length > 1 );
nickjillings@1596 6949 },
nickjillings@1596 6950
nickjillings@1596 6951 removeAttr: function( name ) {
nickjillings@1596 6952 return this.each(function() {
nickjillings@1596 6953 jQuery.removeAttr( this, name );
nickjillings@1596 6954 });
nickjillings@1596 6955 }
nickjillings@1596 6956 });
nickjillings@1596 6957
nickjillings@1596 6958 jQuery.extend({
nickjillings@1596 6959 attr: function( elem, name, value ) {
nickjillings@1596 6960 var hooks, ret,
nickjillings@1596 6961 nType = elem.nodeType;
nickjillings@1596 6962
nickjillings@1596 6963 // don't get/set attributes on text, comment and attribute nodes
nickjillings@1596 6964 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1596 6965 return;
nickjillings@1596 6966 }
nickjillings@1596 6967
nickjillings@1596 6968 // Fallback to prop when attributes are not supported
nickjillings@1596 6969 if ( typeof elem.getAttribute === strundefined ) {
nickjillings@1596 6970 return jQuery.prop( elem, name, value );
nickjillings@1596 6971 }
nickjillings@1596 6972
nickjillings@1596 6973 // All attributes are lowercase
nickjillings@1596 6974 // Grab necessary hook if one is defined
nickjillings@1596 6975 if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
nickjillings@1596 6976 name = name.toLowerCase();
nickjillings@1596 6977 hooks = jQuery.attrHooks[ name ] ||
nickjillings@1596 6978 ( jQuery.expr.match.bool.test( name ) ? boolHook : nodeHook );
nickjillings@1596 6979 }
nickjillings@1596 6980
nickjillings@1596 6981 if ( value !== undefined ) {
nickjillings@1596 6982
nickjillings@1596 6983 if ( value === null ) {
nickjillings@1596 6984 jQuery.removeAttr( elem, name );
nickjillings@1596 6985
nickjillings@1596 6986 } else if ( hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ) {
nickjillings@1596 6987 return ret;
nickjillings@1596 6988
nickjillings@1596 6989 } else {
nickjillings@1596 6990 elem.setAttribute( name, value + "" );
nickjillings@1596 6991 return value;
nickjillings@1596 6992 }
nickjillings@1596 6993
nickjillings@1596 6994 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ) {
nickjillings@1596 6995 return ret;
nickjillings@1596 6996
nickjillings@1596 6997 } else {
nickjillings@1596 6998 ret = jQuery.find.attr( elem, name );
nickjillings@1596 6999
nickjillings@1596 7000 // Non-existent attributes return null, we normalize to undefined
nickjillings@1596 7001 return ret == null ?
nickjillings@1596 7002 undefined :
nickjillings@1596 7003 ret;
nickjillings@1596 7004 }
nickjillings@1596 7005 },
nickjillings@1596 7006
nickjillings@1596 7007 removeAttr: function( elem, value ) {
nickjillings@1596 7008 var name, propName,
nickjillings@1596 7009 i = 0,
nickjillings@1596 7010 attrNames = value && value.match( rnotwhite );
nickjillings@1596 7011
nickjillings@1596 7012 if ( attrNames && elem.nodeType === 1 ) {
nickjillings@1596 7013 while ( (name = attrNames[i++]) ) {
nickjillings@1596 7014 propName = jQuery.propFix[ name ] || name;
nickjillings@1596 7015
nickjillings@1596 7016 // Boolean attributes get special treatment (#10870)
nickjillings@1596 7017 if ( jQuery.expr.match.bool.test( name ) ) {
nickjillings@1596 7018 // Set corresponding property to false
nickjillings@1596 7019 elem[ propName ] = false;
nickjillings@1596 7020 }
nickjillings@1596 7021
nickjillings@1596 7022 elem.removeAttribute( name );
nickjillings@1596 7023 }
nickjillings@1596 7024 }
nickjillings@1596 7025 },
nickjillings@1596 7026
nickjillings@1596 7027 attrHooks: {
nickjillings@1596 7028 type: {
nickjillings@1596 7029 set: function( elem, value ) {
nickjillings@1596 7030 if ( !support.radioValue && value === "radio" &&
nickjillings@1596 7031 jQuery.nodeName( elem, "input" ) ) {
nickjillings@1596 7032 var val = elem.value;
nickjillings@1596 7033 elem.setAttribute( "type", value );
nickjillings@1596 7034 if ( val ) {
nickjillings@1596 7035 elem.value = val;
nickjillings@1596 7036 }
nickjillings@1596 7037 return value;
nickjillings@1596 7038 }
nickjillings@1596 7039 }
nickjillings@1596 7040 }
nickjillings@1596 7041 }
nickjillings@1596 7042 });
nickjillings@1596 7043
nickjillings@1596 7044 // Hooks for boolean attributes
nickjillings@1596 7045 boolHook = {
nickjillings@1596 7046 set: function( elem, value, name ) {
nickjillings@1596 7047 if ( value === false ) {
nickjillings@1596 7048 // Remove boolean attributes when set to false
nickjillings@1596 7049 jQuery.removeAttr( elem, name );
nickjillings@1596 7050 } else {
nickjillings@1596 7051 elem.setAttribute( name, name );
nickjillings@1596 7052 }
nickjillings@1596 7053 return name;
nickjillings@1596 7054 }
nickjillings@1596 7055 };
nickjillings@1596 7056 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
nickjillings@1596 7057 var getter = attrHandle[ name ] || jQuery.find.attr;
nickjillings@1596 7058
nickjillings@1596 7059 attrHandle[ name ] = function( elem, name, isXML ) {
nickjillings@1596 7060 var ret, handle;
nickjillings@1596 7061 if ( !isXML ) {
nickjillings@1596 7062 // Avoid an infinite loop by temporarily removing this function from the getter
nickjillings@1596 7063 handle = attrHandle[ name ];
nickjillings@1596 7064 attrHandle[ name ] = ret;
nickjillings@1596 7065 ret = getter( elem, name, isXML ) != null ?
nickjillings@1596 7066 name.toLowerCase() :
nickjillings@1596 7067 null;
nickjillings@1596 7068 attrHandle[ name ] = handle;
nickjillings@1596 7069 }
nickjillings@1596 7070 return ret;
nickjillings@1596 7071 };
nickjillings@1596 7072 });
nickjillings@1596 7073
nickjillings@1596 7074
nickjillings@1596 7075
nickjillings@1596 7076
nickjillings@1596 7077 var rfocusable = /^(?:input|select|textarea|button)$/i;
nickjillings@1596 7078
nickjillings@1596 7079 jQuery.fn.extend({
nickjillings@1596 7080 prop: function( name, value ) {
nickjillings@1596 7081 return access( this, jQuery.prop, name, value, arguments.length > 1 );
nickjillings@1596 7082 },
nickjillings@1596 7083
nickjillings@1596 7084 removeProp: function( name ) {
nickjillings@1596 7085 return this.each(function() {
nickjillings@1596 7086 delete this[ jQuery.propFix[ name ] || name ];
nickjillings@1596 7087 });
nickjillings@1596 7088 }
nickjillings@1596 7089 });
nickjillings@1596 7090
nickjillings@1596 7091 jQuery.extend({
nickjillings@1596 7092 propFix: {
nickjillings@1596 7093 "for": "htmlFor",
nickjillings@1596 7094 "class": "className"
nickjillings@1596 7095 },
nickjillings@1596 7096
nickjillings@1596 7097 prop: function( elem, name, value ) {
nickjillings@1596 7098 var ret, hooks, notxml,
nickjillings@1596 7099 nType = elem.nodeType;
nickjillings@1596 7100
nickjillings@1596 7101 // Don't get/set properties on text, comment and attribute nodes
nickjillings@1596 7102 if ( !elem || nType === 3 || nType === 8 || nType === 2 ) {
nickjillings@1596 7103 return;
nickjillings@1596 7104 }
nickjillings@1596 7105
nickjillings@1596 7106 notxml = nType !== 1 || !jQuery.isXMLDoc( elem );
nickjillings@1596 7107
nickjillings@1596 7108 if ( notxml ) {
nickjillings@1596 7109 // Fix name and attach hooks
nickjillings@1596 7110 name = jQuery.propFix[ name ] || name;
nickjillings@1596 7111 hooks = jQuery.propHooks[ name ];
nickjillings@1596 7112 }
nickjillings@1596 7113
nickjillings@1596 7114 if ( value !== undefined ) {
nickjillings@1596 7115 return hooks && "set" in hooks && (ret = hooks.set( elem, value, name )) !== undefined ?
nickjillings@1596 7116 ret :
nickjillings@1596 7117 ( elem[ name ] = value );
nickjillings@1596 7118
nickjillings@1596 7119 } else {
nickjillings@1596 7120 return hooks && "get" in hooks && (ret = hooks.get( elem, name )) !== null ?
nickjillings@1596 7121 ret :
nickjillings@1596 7122 elem[ name ];
nickjillings@1596 7123 }
nickjillings@1596 7124 },
nickjillings@1596 7125
nickjillings@1596 7126 propHooks: {
nickjillings@1596 7127 tabIndex: {
nickjillings@1596 7128 get: function( elem ) {
nickjillings@1596 7129 return elem.hasAttribute( "tabindex" ) || rfocusable.test( elem.nodeName ) || elem.href ?
nickjillings@1596 7130 elem.tabIndex :
nickjillings@1596 7131 -1;
nickjillings@1596 7132 }
nickjillings@1596 7133 }
nickjillings@1596 7134 }
nickjillings@1596 7135 });
nickjillings@1596 7136
nickjillings@1596 7137 if ( !support.optSelected ) {
nickjillings@1596 7138 jQuery.propHooks.selected = {
nickjillings@1596 7139 get: function( elem ) {
nickjillings@1596 7140 var parent = elem.parentNode;
nickjillings@1596 7141 if ( parent && parent.parentNode ) {
nickjillings@1596 7142 parent.parentNode.selectedIndex;
nickjillings@1596 7143 }
nickjillings@1596 7144 return null;
nickjillings@1596 7145 }
nickjillings@1596 7146 };
nickjillings@1596 7147 }
nickjillings@1596 7148
nickjillings@1596 7149 jQuery.each([
nickjillings@1596 7150 "tabIndex",
nickjillings@1596 7151 "readOnly",
nickjillings@1596 7152 "maxLength",
nickjillings@1596 7153 "cellSpacing",
nickjillings@1596 7154 "cellPadding",
nickjillings@1596 7155 "rowSpan",
nickjillings@1596 7156 "colSpan",
nickjillings@1596 7157 "useMap",
nickjillings@1596 7158 "frameBorder",
nickjillings@1596 7159 "contentEditable"
nickjillings@1596 7160 ], function() {
nickjillings@1596 7161 jQuery.propFix[ this.toLowerCase() ] = this;
nickjillings@1596 7162 });
nickjillings@1596 7163
nickjillings@1596 7164
nickjillings@1596 7165
nickjillings@1596 7166
nickjillings@1596 7167 var rclass = /[\t\r\n\f]/g;
nickjillings@1596 7168
nickjillings@1596 7169 jQuery.fn.extend({
nickjillings@1596 7170 addClass: function( value ) {
nickjillings@1596 7171 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1596 7172 proceed = typeof value === "string" && value,
nickjillings@1596 7173 i = 0,
nickjillings@1596 7174 len = this.length;
nickjillings@1596 7175
nickjillings@1596 7176 if ( jQuery.isFunction( value ) ) {
nickjillings@1596 7177 return this.each(function( j ) {
nickjillings@1596 7178 jQuery( this ).addClass( value.call( this, j, this.className ) );
nickjillings@1596 7179 });
nickjillings@1596 7180 }
nickjillings@1596 7181
nickjillings@1596 7182 if ( proceed ) {
nickjillings@1596 7183 // The disjunction here is for better compressibility (see removeClass)
nickjillings@1596 7184 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1596 7185
nickjillings@1596 7186 for ( ; i < len; i++ ) {
nickjillings@1596 7187 elem = this[ i ];
nickjillings@1596 7188 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1596 7189 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1596 7190 " "
nickjillings@1596 7191 );
nickjillings@1596 7192
nickjillings@1596 7193 if ( cur ) {
nickjillings@1596 7194 j = 0;
nickjillings@1596 7195 while ( (clazz = classes[j++]) ) {
nickjillings@1596 7196 if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
nickjillings@1596 7197 cur += clazz + " ";
nickjillings@1596 7198 }
nickjillings@1596 7199 }
nickjillings@1596 7200
nickjillings@1596 7201 // only assign if different to avoid unneeded rendering.
nickjillings@1596 7202 finalValue = jQuery.trim( cur );
nickjillings@1596 7203 if ( elem.className !== finalValue ) {
nickjillings@1596 7204 elem.className = finalValue;
nickjillings@1596 7205 }
nickjillings@1596 7206 }
nickjillings@1596 7207 }
nickjillings@1596 7208 }
nickjillings@1596 7209
nickjillings@1596 7210 return this;
nickjillings@1596 7211 },
nickjillings@1596 7212
nickjillings@1596 7213 removeClass: function( value ) {
nickjillings@1596 7214 var classes, elem, cur, clazz, j, finalValue,
nickjillings@1596 7215 proceed = arguments.length === 0 || typeof value === "string" && value,
nickjillings@1596 7216 i = 0,
nickjillings@1596 7217 len = this.length;
nickjillings@1596 7218
nickjillings@1596 7219 if ( jQuery.isFunction( value ) ) {
nickjillings@1596 7220 return this.each(function( j ) {
nickjillings@1596 7221 jQuery( this ).removeClass( value.call( this, j, this.className ) );
nickjillings@1596 7222 });
nickjillings@1596 7223 }
nickjillings@1596 7224 if ( proceed ) {
nickjillings@1596 7225 classes = ( value || "" ).match( rnotwhite ) || [];
nickjillings@1596 7226
nickjillings@1596 7227 for ( ; i < len; i++ ) {
nickjillings@1596 7228 elem = this[ i ];
nickjillings@1596 7229 // This expression is here for better compressibility (see addClass)
nickjillings@1596 7230 cur = elem.nodeType === 1 && ( elem.className ?
nickjillings@1596 7231 ( " " + elem.className + " " ).replace( rclass, " " ) :
nickjillings@1596 7232 ""
nickjillings@1596 7233 );
nickjillings@1596 7234
nickjillings@1596 7235 if ( cur ) {
nickjillings@1596 7236 j = 0;
nickjillings@1596 7237 while ( (clazz = classes[j++]) ) {
nickjillings@1596 7238 // Remove *all* instances
nickjillings@1596 7239 while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
nickjillings@1596 7240 cur = cur.replace( " " + clazz + " ", " " );
nickjillings@1596 7241 }
nickjillings@1596 7242 }
nickjillings@1596 7243
nickjillings@1596 7244 // Only assign if different to avoid unneeded rendering.
nickjillings@1596 7245 finalValue = value ? jQuery.trim( cur ) : "";
nickjillings@1596 7246 if ( elem.className !== finalValue ) {
nickjillings@1596 7247 elem.className = finalValue;
nickjillings@1596 7248 }
nickjillings@1596 7249 }
nickjillings@1596 7250 }
nickjillings@1596 7251 }
nickjillings@1596 7252
nickjillings@1596 7253 return this;
nickjillings@1596 7254 },
nickjillings@1596 7255
nickjillings@1596 7256 toggleClass: function( value, stateVal ) {
nickjillings@1596 7257 var type = typeof value;
nickjillings@1596 7258
nickjillings@1596 7259 if ( typeof stateVal === "boolean" && type === "string" ) {
nickjillings@1596 7260 return stateVal ? this.addClass( value ) : this.removeClass( value );
nickjillings@1596 7261 }
nickjillings@1596 7262
nickjillings@1596 7263 if ( jQuery.isFunction( value ) ) {
nickjillings@1596 7264 return this.each(function( i ) {
nickjillings@1596 7265 jQuery( this ).toggleClass( value.call(this, i, this.className, stateVal), stateVal );
nickjillings@1596 7266 });
nickjillings@1596 7267 }
nickjillings@1596 7268
nickjillings@1596 7269 return this.each(function() {
nickjillings@1596 7270 if ( type === "string" ) {
nickjillings@1596 7271 // Toggle individual class names
nickjillings@1596 7272 var className,
nickjillings@1596 7273 i = 0,
nickjillings@1596 7274 self = jQuery( this ),
nickjillings@1596 7275 classNames = value.match( rnotwhite ) || [];
nickjillings@1596 7276
nickjillings@1596 7277 while ( (className = classNames[ i++ ]) ) {
nickjillings@1596 7278 // Check each className given, space separated list
nickjillings@1596 7279 if ( self.hasClass( className ) ) {
nickjillings@1596 7280 self.removeClass( className );
nickjillings@1596 7281 } else {
nickjillings@1596 7282 self.addClass( className );
nickjillings@1596 7283 }
nickjillings@1596 7284 }
nickjillings@1596 7285
nickjillings@1596 7286 // Toggle whole class name
nickjillings@1596 7287 } else if ( type === strundefined || type === "boolean" ) {
nickjillings@1596 7288 if ( this.className ) {
nickjillings@1596 7289 // store className if set
nickjillings@1596 7290 data_priv.set( this, "__className__", this.className );
nickjillings@1596 7291 }
nickjillings@1596 7292
nickjillings@1596 7293 // If the element has a class name or if we're passed `false`,
nickjillings@1596 7294 // then remove the whole classname (if there was one, the above saved it).
nickjillings@1596 7295 // Otherwise bring back whatever was previously saved (if anything),
nickjillings@1596 7296 // falling back to the empty string if nothing was stored.
nickjillings@1596 7297 this.className = this.className || value === false ? "" : data_priv.get( this, "__className__" ) || "";
nickjillings@1596 7298 }
nickjillings@1596 7299 });
nickjillings@1596 7300 },
nickjillings@1596 7301
nickjillings@1596 7302 hasClass: function( selector ) {
nickjillings@1596 7303 var className = " " + selector + " ",
nickjillings@1596 7304 i = 0,
nickjillings@1596 7305 l = this.length;
nickjillings@1596 7306 for ( ; i < l; i++ ) {
nickjillings@1596 7307 if ( this[i].nodeType === 1 && (" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
nickjillings@1596 7308 return true;
nickjillings@1596 7309 }
nickjillings@1596 7310 }
nickjillings@1596 7311
nickjillings@1596 7312 return false;
nickjillings@1596 7313 }
nickjillings@1596 7314 });
nickjillings@1596 7315
nickjillings@1596 7316
nickjillings@1596 7317
nickjillings@1596 7318
nickjillings@1596 7319 var rreturn = /\r/g;
nickjillings@1596 7320
nickjillings@1596 7321 jQuery.fn.extend({
nickjillings@1596 7322 val: function( value ) {
nickjillings@1596 7323 var hooks, ret, isFunction,
nickjillings@1596 7324 elem = this[0];
nickjillings@1596 7325
nickjillings@1596 7326 if ( !arguments.length ) {
nickjillings@1596 7327 if ( elem ) {
nickjillings@1596 7328 hooks = jQuery.valHooks[ elem.type ] || jQuery.valHooks[ elem.nodeName.toLowerCase() ];
nickjillings@1596 7329
nickjillings@1596 7330 if ( hooks && "get" in hooks && (ret = hooks.get( elem, "value" )) !== undefined ) {
nickjillings@1596 7331 return ret;
nickjillings@1596 7332 }
nickjillings@1596 7333
nickjillings@1596 7334 ret = elem.value;
nickjillings@1596 7335
nickjillings@1596 7336 return typeof ret === "string" ?
nickjillings@1596 7337 // Handle most common string cases
nickjillings@1596 7338 ret.replace(rreturn, "") :
nickjillings@1596 7339 // Handle cases where value is null/undef or number
nickjillings@1596 7340 ret == null ? "" : ret;
nickjillings@1596 7341 }
nickjillings@1596 7342
nickjillings@1596 7343 return;
nickjillings@1596 7344 }
nickjillings@1596 7345
nickjillings@1596 7346 isFunction = jQuery.isFunction( value );
nickjillings@1596 7347
nickjillings@1596 7348 return this.each(function( i ) {
nickjillings@1596 7349 var val;
nickjillings@1596 7350
nickjillings@1596 7351 if ( this.nodeType !== 1 ) {
nickjillings@1596 7352 return;
nickjillings@1596 7353 }
nickjillings@1596 7354
nickjillings@1596 7355 if ( isFunction ) {
nickjillings@1596 7356 val = value.call( this, i, jQuery( this ).val() );
nickjillings@1596 7357 } else {
nickjillings@1596 7358 val = value;
nickjillings@1596 7359 }
nickjillings@1596 7360
nickjillings@1596 7361 // Treat null/undefined as ""; convert numbers to string
nickjillings@1596 7362 if ( val == null ) {
nickjillings@1596 7363 val = "";
nickjillings@1596 7364
nickjillings@1596 7365 } else if ( typeof val === "number" ) {
nickjillings@1596 7366 val += "";
nickjillings@1596 7367
nickjillings@1596 7368 } else if ( jQuery.isArray( val ) ) {
nickjillings@1596 7369 val = jQuery.map( val, function( value ) {
nickjillings@1596 7370 return value == null ? "" : value + "";
nickjillings@1596 7371 });
nickjillings@1596 7372 }
nickjillings@1596 7373
nickjillings@1596 7374 hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
nickjillings@1596 7375
nickjillings@1596 7376 // If set returns undefined, fall back to normal setting
nickjillings@1596 7377 if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
nickjillings@1596 7378 this.value = val;
nickjillings@1596 7379 }
nickjillings@1596 7380 });
nickjillings@1596 7381 }
nickjillings@1596 7382 });
nickjillings@1596 7383
nickjillings@1596 7384 jQuery.extend({
nickjillings@1596 7385 valHooks: {
nickjillings@1596 7386 option: {
nickjillings@1596 7387 get: function( elem ) {
nickjillings@1596 7388 var val = jQuery.find.attr( elem, "value" );
nickjillings@1596 7389 return val != null ?
nickjillings@1596 7390 val :
nickjillings@1596 7391 // Support: IE10-11+
nickjillings@1596 7392 // option.text throws exceptions (#14686, #14858)
nickjillings@1596 7393 jQuery.trim( jQuery.text( elem ) );
nickjillings@1596 7394 }
nickjillings@1596 7395 },
nickjillings@1596 7396 select: {
nickjillings@1596 7397 get: function( elem ) {
nickjillings@1596 7398 var value, option,
nickjillings@1596 7399 options = elem.options,
nickjillings@1596 7400 index = elem.selectedIndex,
nickjillings@1596 7401 one = elem.type === "select-one" || index < 0,
nickjillings@1596 7402 values = one ? null : [],
nickjillings@1596 7403 max = one ? index + 1 : options.length,
nickjillings@1596 7404 i = index < 0 ?
nickjillings@1596 7405 max :
nickjillings@1596 7406 one ? index : 0;
nickjillings@1596 7407
nickjillings@1596 7408 // Loop through all the selected options
nickjillings@1596 7409 for ( ; i < max; i++ ) {
nickjillings@1596 7410 option = options[ i ];
nickjillings@1596 7411
nickjillings@1596 7412 // IE6-9 doesn't update selected after form reset (#2551)
nickjillings@1596 7413 if ( ( option.selected || i === index ) &&
nickjillings@1596 7414 // Don't return options that are disabled or in a disabled optgroup
nickjillings@1596 7415 ( support.optDisabled ? !option.disabled : option.getAttribute( "disabled" ) === null ) &&
nickjillings@1596 7416 ( !option.parentNode.disabled || !jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
nickjillings@1596 7417
nickjillings@1596 7418 // Get the specific value for the option
nickjillings@1596 7419 value = jQuery( option ).val();
nickjillings@1596 7420
nickjillings@1596 7421 // We don't need an array for one selects
nickjillings@1596 7422 if ( one ) {
nickjillings@1596 7423 return value;
nickjillings@1596 7424 }
nickjillings@1596 7425
nickjillings@1596 7426 // Multi-Selects return an array
nickjillings@1596 7427 values.push( value );
nickjillings@1596 7428 }
nickjillings@1596 7429 }
nickjillings@1596 7430
nickjillings@1596 7431 return values;
nickjillings@1596 7432 },
nickjillings@1596 7433
nickjillings@1596 7434 set: function( elem, value ) {
nickjillings@1596 7435 var optionSet, option,
nickjillings@1596 7436 options = elem.options,
nickjillings@1596 7437 values = jQuery.makeArray( value ),
nickjillings@1596 7438 i = options.length;
nickjillings@1596 7439
nickjillings@1596 7440 while ( i-- ) {
nickjillings@1596 7441 option = options[ i ];
nickjillings@1596 7442 if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
nickjillings@1596 7443 optionSet = true;
nickjillings@1596 7444 }
nickjillings@1596 7445 }
nickjillings@1596 7446
nickjillings@1596 7447 // Force browsers to behave consistently when non-matching value is set
nickjillings@1596 7448 if ( !optionSet ) {
nickjillings@1596 7449 elem.selectedIndex = -1;
nickjillings@1596 7450 }
nickjillings@1596 7451 return values;
nickjillings@1596 7452 }
nickjillings@1596 7453 }
nickjillings@1596 7454 }
nickjillings@1596 7455 });
nickjillings@1596 7456
nickjillings@1596 7457 // Radios and checkboxes getter/setter
nickjillings@1596 7458 jQuery.each([ "radio", "checkbox" ], function() {
nickjillings@1596 7459 jQuery.valHooks[ this ] = {
nickjillings@1596 7460 set: function( elem, value ) {
nickjillings@1596 7461 if ( jQuery.isArray( value ) ) {
nickjillings@1596 7462 return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
nickjillings@1596 7463 }
nickjillings@1596 7464 }
nickjillings@1596 7465 };
nickjillings@1596 7466 if ( !support.checkOn ) {
nickjillings@1596 7467 jQuery.valHooks[ this ].get = function( elem ) {
nickjillings@1596 7468 return elem.getAttribute("value") === null ? "on" : elem.value;
nickjillings@1596 7469 };
nickjillings@1596 7470 }
nickjillings@1596 7471 });
nickjillings@1596 7472
nickjillings@1596 7473
nickjillings@1596 7474
nickjillings@1596 7475
nickjillings@1596 7476 // Return jQuery for attributes-only inclusion
nickjillings@1596 7477
nickjillings@1596 7478
nickjillings@1596 7479 jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
nickjillings@1596 7480 "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
nickjillings@1596 7481 "change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {
nickjillings@1596 7482
nickjillings@1596 7483 // Handle event binding
nickjillings@1596 7484 jQuery.fn[ name ] = function( data, fn ) {
nickjillings@1596 7485 return arguments.length > 0 ?
nickjillings@1596 7486 this.on( name, null, data, fn ) :
nickjillings@1596 7487 this.trigger( name );
nickjillings@1596 7488 };
nickjillings@1596 7489 });
nickjillings@1596 7490
nickjillings@1596 7491 jQuery.fn.extend({
nickjillings@1596 7492 hover: function( fnOver, fnOut ) {
nickjillings@1596 7493 return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
nickjillings@1596 7494 },
nickjillings@1596 7495
nickjillings@1596 7496 bind: function( types, data, fn ) {
nickjillings@1596 7497 return this.on( types, null, data, fn );
nickjillings@1596 7498 },
nickjillings@1596 7499 unbind: function( types, fn ) {
nickjillings@1596 7500 return this.off( types, null, fn );
nickjillings@1596 7501 },
nickjillings@1596 7502
nickjillings@1596 7503 delegate: function( selector, types, data, fn ) {
nickjillings@1596 7504 return this.on( types, selector, data, fn );
nickjillings@1596 7505 },
nickjillings@1596 7506 undelegate: function( selector, types, fn ) {
nickjillings@1596 7507 // ( namespace ) or ( selector, types [, fn] )
nickjillings@1596 7508 return arguments.length === 1 ? this.off( selector, "**" ) : this.off( types, selector || "**", fn );
nickjillings@1596 7509 }
nickjillings@1596 7510 });
nickjillings@1596 7511
nickjillings@1596 7512
nickjillings@1596 7513 var nonce = jQuery.now();
nickjillings@1596 7514
nickjillings@1596 7515 var rquery = (/\?/);
nickjillings@1596 7516
nickjillings@1596 7517
nickjillings@1596 7518
nickjillings@1596 7519 // Support: Android 2.3
nickjillings@1596 7520 // Workaround failure to string-cast null input
nickjillings@1596 7521 jQuery.parseJSON = function( data ) {
nickjillings@1596 7522 return JSON.parse( data + "" );
nickjillings@1596 7523 };
nickjillings@1596 7524
nickjillings@1596 7525
nickjillings@1596 7526 // Cross-browser xml parsing
nickjillings@1596 7527 jQuery.parseXML = function( data ) {
nickjillings@1596 7528 var xml, tmp;
nickjillings@1596 7529 if ( !data || typeof data !== "string" ) {
nickjillings@1596 7530 return null;
nickjillings@1596 7531 }
nickjillings@1596 7532
nickjillings@1596 7533 // Support: IE9
nickjillings@1596 7534 try {
nickjillings@1596 7535 tmp = new DOMParser();
nickjillings@1596 7536 xml = tmp.parseFromString( data, "text/xml" );
nickjillings@1596 7537 } catch ( e ) {
nickjillings@1596 7538 xml = undefined;
nickjillings@1596 7539 }
nickjillings@1596 7540
nickjillings@1596 7541 if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
nickjillings@1596 7542 jQuery.error( "Invalid XML: " + data );
nickjillings@1596 7543 }
nickjillings@1596 7544 return xml;
nickjillings@1596 7545 };
nickjillings@1596 7546
nickjillings@1596 7547
nickjillings@1596 7548 var
nickjillings@1596 7549 rhash = /#.*$/,
nickjillings@1596 7550 rts = /([?&])_=[^&]*/,
nickjillings@1596 7551 rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
nickjillings@1596 7552 // #7653, #8125, #8152: local protocol detection
nickjillings@1596 7553 rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
nickjillings@1596 7554 rnoContent = /^(?:GET|HEAD)$/,
nickjillings@1596 7555 rprotocol = /^\/\//,
nickjillings@1596 7556 rurl = /^([\w.+-]+:)(?:\/\/(?:[^\/?#]*@|)([^\/?#:]*)(?::(\d+)|)|)/,
nickjillings@1596 7557
nickjillings@1596 7558 /* Prefilters
nickjillings@1596 7559 * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
nickjillings@1596 7560 * 2) These are called:
nickjillings@1596 7561 * - BEFORE asking for a transport
nickjillings@1596 7562 * - AFTER param serialization (s.data is a string if s.processData is true)
nickjillings@1596 7563 * 3) key is the dataType
nickjillings@1596 7564 * 4) the catchall symbol "*" can be used
nickjillings@1596 7565 * 5) execution will start with transport dataType and THEN continue down to "*" if needed
nickjillings@1596 7566 */
nickjillings@1596 7567 prefilters = {},
nickjillings@1596 7568
nickjillings@1596 7569 /* Transports bindings
nickjillings@1596 7570 * 1) key is the dataType
nickjillings@1596 7571 * 2) the catchall symbol "*" can be used
nickjillings@1596 7572 * 3) selection will start with transport dataType and THEN go to "*" if needed
nickjillings@1596 7573 */
nickjillings@1596 7574 transports = {},
nickjillings@1596 7575
nickjillings@1596 7576 // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
nickjillings@1596 7577 allTypes = "*/".concat( "*" ),
nickjillings@1596 7578
nickjillings@1596 7579 // Document location
nickjillings@1596 7580 ajaxLocation = window.location.href,
nickjillings@1596 7581
nickjillings@1596 7582 // Segment location into parts
nickjillings@1596 7583 ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [];
nickjillings@1596 7584
nickjillings@1596 7585 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
nickjillings@1596 7586 function addToPrefiltersOrTransports( structure ) {
nickjillings@1596 7587
nickjillings@1596 7588 // dataTypeExpression is optional and defaults to "*"
nickjillings@1596 7589 return function( dataTypeExpression, func ) {
nickjillings@1596 7590
nickjillings@1596 7591 if ( typeof dataTypeExpression !== "string" ) {
nickjillings@1596 7592 func = dataTypeExpression;
nickjillings@1596 7593 dataTypeExpression = "*";
nickjillings@1596 7594 }
nickjillings@1596 7595
nickjillings@1596 7596 var dataType,
nickjillings@1596 7597 i = 0,
nickjillings@1596 7598 dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
nickjillings@1596 7599
nickjillings@1596 7600 if ( jQuery.isFunction( func ) ) {
nickjillings@1596 7601 // For each dataType in the dataTypeExpression
nickjillings@1596 7602 while ( (dataType = dataTypes[i++]) ) {
nickjillings@1596 7603 // Prepend if requested
nickjillings@1596 7604 if ( dataType[0] === "+" ) {
nickjillings@1596 7605 dataType = dataType.slice( 1 ) || "*";
nickjillings@1596 7606 (structure[ dataType ] = structure[ dataType ] || []).unshift( func );
nickjillings@1596 7607
nickjillings@1596 7608 // Otherwise append
nickjillings@1596 7609 } else {
nickjillings@1596 7610 (structure[ dataType ] = structure[ dataType ] || []).push( func );
nickjillings@1596 7611 }
nickjillings@1596 7612 }
nickjillings@1596 7613 }
nickjillings@1596 7614 };
nickjillings@1596 7615 }
nickjillings@1596 7616
nickjillings@1596 7617 // Base inspection function for prefilters and transports
nickjillings@1596 7618 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
nickjillings@1596 7619
nickjillings@1596 7620 var inspected = {},
nickjillings@1596 7621 seekingTransport = ( structure === transports );
nickjillings@1596 7622
nickjillings@1596 7623 function inspect( dataType ) {
nickjillings@1596 7624 var selected;
nickjillings@1596 7625 inspected[ dataType ] = true;
nickjillings@1596 7626 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
nickjillings@1596 7627 var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
nickjillings@1596 7628 if ( typeof dataTypeOrTransport === "string" && !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
nickjillings@1596 7629 options.dataTypes.unshift( dataTypeOrTransport );
nickjillings@1596 7630 inspect( dataTypeOrTransport );
nickjillings@1596 7631 return false;
nickjillings@1596 7632 } else if ( seekingTransport ) {
nickjillings@1596 7633 return !( selected = dataTypeOrTransport );
nickjillings@1596 7634 }
nickjillings@1596 7635 });
nickjillings@1596 7636 return selected;
nickjillings@1596 7637 }
nickjillings@1596 7638
nickjillings@1596 7639 return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
nickjillings@1596 7640 }
nickjillings@1596 7641
nickjillings@1596 7642 // A special extend for ajax options
nickjillings@1596 7643 // that takes "flat" options (not to be deep extended)
nickjillings@1596 7644 // Fixes #9887
nickjillings@1596 7645 function ajaxExtend( target, src ) {
nickjillings@1596 7646 var key, deep,
nickjillings@1596 7647 flatOptions = jQuery.ajaxSettings.flatOptions || {};
nickjillings@1596 7648
nickjillings@1596 7649 for ( key in src ) {
nickjillings@1596 7650 if ( src[ key ] !== undefined ) {
nickjillings@1596 7651 ( flatOptions[ key ] ? target : ( deep || (deep = {}) ) )[ key ] = src[ key ];
nickjillings@1596 7652 }
nickjillings@1596 7653 }
nickjillings@1596 7654 if ( deep ) {
nickjillings@1596 7655 jQuery.extend( true, target, deep );
nickjillings@1596 7656 }
nickjillings@1596 7657
nickjillings@1596 7658 return target;
nickjillings@1596 7659 }
nickjillings@1596 7660
nickjillings@1596 7661 /* Handles responses to an ajax request:
nickjillings@1596 7662 * - finds the right dataType (mediates between content-type and expected dataType)
nickjillings@1596 7663 * - returns the corresponding response
nickjillings@1596 7664 */
nickjillings@1596 7665 function ajaxHandleResponses( s, jqXHR, responses ) {
nickjillings@1596 7666
nickjillings@1596 7667 var ct, type, finalDataType, firstDataType,
nickjillings@1596 7668 contents = s.contents,
nickjillings@1596 7669 dataTypes = s.dataTypes;
nickjillings@1596 7670
nickjillings@1596 7671 // Remove auto dataType and get content-type in the process
nickjillings@1596 7672 while ( dataTypes[ 0 ] === "*" ) {
nickjillings@1596 7673 dataTypes.shift();
nickjillings@1596 7674 if ( ct === undefined ) {
nickjillings@1596 7675 ct = s.mimeType || jqXHR.getResponseHeader("Content-Type");
nickjillings@1596 7676 }
nickjillings@1596 7677 }
nickjillings@1596 7678
nickjillings@1596 7679 // Check if we're dealing with a known content-type
nickjillings@1596 7680 if ( ct ) {
nickjillings@1596 7681 for ( type in contents ) {
nickjillings@1596 7682 if ( contents[ type ] && contents[ type ].test( ct ) ) {
nickjillings@1596 7683 dataTypes.unshift( type );
nickjillings@1596 7684 break;
nickjillings@1596 7685 }
nickjillings@1596 7686 }
nickjillings@1596 7687 }
nickjillings@1596 7688
nickjillings@1596 7689 // Check to see if we have a response for the expected dataType
nickjillings@1596 7690 if ( dataTypes[ 0 ] in responses ) {
nickjillings@1596 7691 finalDataType = dataTypes[ 0 ];
nickjillings@1596 7692 } else {
nickjillings@1596 7693 // Try convertible dataTypes
nickjillings@1596 7694 for ( type in responses ) {
nickjillings@1596 7695 if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[0] ] ) {
nickjillings@1596 7696 finalDataType = type;
nickjillings@1596 7697 break;
nickjillings@1596 7698 }
nickjillings@1596 7699 if ( !firstDataType ) {
nickjillings@1596 7700 firstDataType = type;
nickjillings@1596 7701 }
nickjillings@1596 7702 }
nickjillings@1596 7703 // Or just use first one
nickjillings@1596 7704 finalDataType = finalDataType || firstDataType;
nickjillings@1596 7705 }
nickjillings@1596 7706
nickjillings@1596 7707 // If we found a dataType
nickjillings@1596 7708 // We add the dataType to the list if needed
nickjillings@1596 7709 // and return the corresponding response
nickjillings@1596 7710 if ( finalDataType ) {
nickjillings@1596 7711 if ( finalDataType !== dataTypes[ 0 ] ) {
nickjillings@1596 7712 dataTypes.unshift( finalDataType );
nickjillings@1596 7713 }
nickjillings@1596 7714 return responses[ finalDataType ];
nickjillings@1596 7715 }
nickjillings@1596 7716 }
nickjillings@1596 7717
nickjillings@1596 7718 /* Chain conversions given the request and the original response
nickjillings@1596 7719 * Also sets the responseXXX fields on the jqXHR instance
nickjillings@1596 7720 */
nickjillings@1596 7721 function ajaxConvert( s, response, jqXHR, isSuccess ) {
nickjillings@1596 7722 var conv2, current, conv, tmp, prev,
nickjillings@1596 7723 converters = {},
nickjillings@1596 7724 // Work with a copy of dataTypes in case we need to modify it for conversion
nickjillings@1596 7725 dataTypes = s.dataTypes.slice();
nickjillings@1596 7726
nickjillings@1596 7727 // Create converters map with lowercased keys
nickjillings@1596 7728 if ( dataTypes[ 1 ] ) {
nickjillings@1596 7729 for ( conv in s.converters ) {
nickjillings@1596 7730 converters[ conv.toLowerCase() ] = s.converters[ conv ];
nickjillings@1596 7731 }
nickjillings@1596 7732 }
nickjillings@1596 7733
nickjillings@1596 7734 current = dataTypes.shift();
nickjillings@1596 7735
nickjillings@1596 7736 // Convert to each sequential dataType
nickjillings@1596 7737 while ( current ) {
nickjillings@1596 7738
nickjillings@1596 7739 if ( s.responseFields[ current ] ) {
nickjillings@1596 7740 jqXHR[ s.responseFields[ current ] ] = response;
nickjillings@1596 7741 }
nickjillings@1596 7742
nickjillings@1596 7743 // Apply the dataFilter if provided
nickjillings@1596 7744 if ( !prev && isSuccess && s.dataFilter ) {
nickjillings@1596 7745 response = s.dataFilter( response, s.dataType );
nickjillings@1596 7746 }
nickjillings@1596 7747
nickjillings@1596 7748 prev = current;
nickjillings@1596 7749 current = dataTypes.shift();
nickjillings@1596 7750
nickjillings@1596 7751 if ( current ) {
nickjillings@1596 7752
nickjillings@1596 7753 // There's only work to do if current dataType is non-auto
nickjillings@1596 7754 if ( current === "*" ) {
nickjillings@1596 7755
nickjillings@1596 7756 current = prev;
nickjillings@1596 7757
nickjillings@1596 7758 // Convert response if prev dataType is non-auto and differs from current
nickjillings@1596 7759 } else if ( prev !== "*" && prev !== current ) {
nickjillings@1596 7760
nickjillings@1596 7761 // Seek a direct converter
nickjillings@1596 7762 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
nickjillings@1596 7763
nickjillings@1596 7764 // If none found, seek a pair
nickjillings@1596 7765 if ( !conv ) {
nickjillings@1596 7766 for ( conv2 in converters ) {
nickjillings@1596 7767
nickjillings@1596 7768 // If conv2 outputs current
nickjillings@1596 7769 tmp = conv2.split( " " );
nickjillings@1596 7770 if ( tmp[ 1 ] === current ) {
nickjillings@1596 7771
nickjillings@1596 7772 // If prev can be converted to accepted input
nickjillings@1596 7773 conv = converters[ prev + " " + tmp[ 0 ] ] ||
nickjillings@1596 7774 converters[ "* " + tmp[ 0 ] ];
nickjillings@1596 7775 if ( conv ) {
nickjillings@1596 7776 // Condense equivalence converters
nickjillings@1596 7777 if ( conv === true ) {
nickjillings@1596 7778 conv = converters[ conv2 ];
nickjillings@1596 7779
nickjillings@1596 7780 // Otherwise, insert the intermediate dataType
nickjillings@1596 7781 } else if ( converters[ conv2 ] !== true ) {
nickjillings@1596 7782 current = tmp[ 0 ];
nickjillings@1596 7783 dataTypes.unshift( tmp[ 1 ] );
nickjillings@1596 7784 }
nickjillings@1596 7785 break;
nickjillings@1596 7786 }
nickjillings@1596 7787 }
nickjillings@1596 7788 }
nickjillings@1596 7789 }
nickjillings@1596 7790
nickjillings@1596 7791 // Apply converter (if not an equivalence)
nickjillings@1596 7792 if ( conv !== true ) {
nickjillings@1596 7793
nickjillings@1596 7794 // Unless errors are allowed to bubble, catch and return them
nickjillings@1596 7795 if ( conv && s[ "throws" ] ) {
nickjillings@1596 7796 response = conv( response );
nickjillings@1596 7797 } else {
nickjillings@1596 7798 try {
nickjillings@1596 7799 response = conv( response );
nickjillings@1596 7800 } catch ( e ) {
nickjillings@1596 7801 return { state: "parsererror", error: conv ? e : "No conversion from " + prev + " to " + current };
nickjillings@1596 7802 }
nickjillings@1596 7803 }
nickjillings@1596 7804 }
nickjillings@1596 7805 }
nickjillings@1596 7806 }
nickjillings@1596 7807 }
nickjillings@1596 7808
nickjillings@1596 7809 return { state: "success", data: response };
nickjillings@1596 7810 }
nickjillings@1596 7811
nickjillings@1596 7812 jQuery.extend({
nickjillings@1596 7813
nickjillings@1596 7814 // Counter for holding the number of active queries
nickjillings@1596 7815 active: 0,
nickjillings@1596 7816
nickjillings@1596 7817 // Last-Modified header cache for next request
nickjillings@1596 7818 lastModified: {},
nickjillings@1596 7819 etag: {},
nickjillings@1596 7820
nickjillings@1596 7821 ajaxSettings: {
nickjillings@1596 7822 url: ajaxLocation,
nickjillings@1596 7823 type: "GET",
nickjillings@1596 7824 isLocal: rlocalProtocol.test( ajaxLocParts[ 1 ] ),
nickjillings@1596 7825 global: true,
nickjillings@1596 7826 processData: true,
nickjillings@1596 7827 async: true,
nickjillings@1596 7828 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
nickjillings@1596 7829 /*
nickjillings@1596 7830 timeout: 0,
nickjillings@1596 7831 data: null,
nickjillings@1596 7832 dataType: null,
nickjillings@1596 7833 username: null,
nickjillings@1596 7834 password: null,
nickjillings@1596 7835 cache: null,
nickjillings@1596 7836 throws: false,
nickjillings@1596 7837 traditional: false,
nickjillings@1596 7838 headers: {},
nickjillings@1596 7839 */
nickjillings@1596 7840
nickjillings@1596 7841 accepts: {
nickjillings@1596 7842 "*": allTypes,
nickjillings@1596 7843 text: "text/plain",
nickjillings@1596 7844 html: "text/html",
nickjillings@1596 7845 xml: "application/xml, text/xml",
nickjillings@1596 7846 json: "application/json, text/javascript"
nickjillings@1596 7847 },
nickjillings@1596 7848
nickjillings@1596 7849 contents: {
nickjillings@1596 7850 xml: /xml/,
nickjillings@1596 7851 html: /html/,
nickjillings@1596 7852 json: /json/
nickjillings@1596 7853 },
nickjillings@1596 7854
nickjillings@1596 7855 responseFields: {
nickjillings@1596 7856 xml: "responseXML",
nickjillings@1596 7857 text: "responseText",
nickjillings@1596 7858 json: "responseJSON"
nickjillings@1596 7859 },
nickjillings@1596 7860
nickjillings@1596 7861 // Data converters
nickjillings@1596 7862 // Keys separate source (or catchall "*") and destination types with a single space
nickjillings@1596 7863 converters: {
nickjillings@1596 7864
nickjillings@1596 7865 // Convert anything to text
nickjillings@1596 7866 "* text": String,
nickjillings@1596 7867
nickjillings@1596 7868 // Text to html (true = no transformation)
nickjillings@1596 7869 "text html": true,
nickjillings@1596 7870
nickjillings@1596 7871 // Evaluate text as a json expression
nickjillings@1596 7872 "text json": jQuery.parseJSON,
nickjillings@1596 7873
nickjillings@1596 7874 // Parse text as xml
nickjillings@1596 7875 "text xml": jQuery.parseXML
nickjillings@1596 7876 },
nickjillings@1596 7877
nickjillings@1596 7878 // For options that shouldn't be deep extended:
nickjillings@1596 7879 // you can add your own custom options here if
nickjillings@1596 7880 // and when you create one that shouldn't be
nickjillings@1596 7881 // deep extended (see ajaxExtend)
nickjillings@1596 7882 flatOptions: {
nickjillings@1596 7883 url: true,
nickjillings@1596 7884 context: true
nickjillings@1596 7885 }
nickjillings@1596 7886 },
nickjillings@1596 7887
nickjillings@1596 7888 // Creates a full fledged settings object into target
nickjillings@1596 7889 // with both ajaxSettings and settings fields.
nickjillings@1596 7890 // If target is omitted, writes into ajaxSettings.
nickjillings@1596 7891 ajaxSetup: function( target, settings ) {
nickjillings@1596 7892 return settings ?
nickjillings@1596 7893
nickjillings@1596 7894 // Building a settings object
nickjillings@1596 7895 ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
nickjillings@1596 7896
nickjillings@1596 7897 // Extending ajaxSettings
nickjillings@1596 7898 ajaxExtend( jQuery.ajaxSettings, target );
nickjillings@1596 7899 },
nickjillings@1596 7900
nickjillings@1596 7901 ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
nickjillings@1596 7902 ajaxTransport: addToPrefiltersOrTransports( transports ),
nickjillings@1596 7903
nickjillings@1596 7904 // Main method
nickjillings@1596 7905 ajax: function( url, options ) {
nickjillings@1596 7906
nickjillings@1596 7907 // If url is an object, simulate pre-1.5 signature
nickjillings@1596 7908 if ( typeof url === "object" ) {
nickjillings@1596 7909 options = url;
nickjillings@1596 7910 url = undefined;
nickjillings@1596 7911 }
nickjillings@1596 7912
nickjillings@1596 7913 // Force options to be an object
nickjillings@1596 7914 options = options || {};
nickjillings@1596 7915
nickjillings@1596 7916 var transport,
nickjillings@1596 7917 // URL without anti-cache param
nickjillings@1596 7918 cacheURL,
nickjillings@1596 7919 // Response headers
nickjillings@1596 7920 responseHeadersString,
nickjillings@1596 7921 responseHeaders,
nickjillings@1596 7922 // timeout handle
nickjillings@1596 7923 timeoutTimer,
nickjillings@1596 7924 // Cross-domain detection vars
nickjillings@1596 7925 parts,
nickjillings@1596 7926 // To know if global events are to be dispatched
nickjillings@1596 7927 fireGlobals,
nickjillings@1596 7928 // Loop variable
nickjillings@1596 7929 i,
nickjillings@1596 7930 // Create the final options object
nickjillings@1596 7931 s = jQuery.ajaxSetup( {}, options ),
nickjillings@1596 7932 // Callbacks context
nickjillings@1596 7933 callbackContext = s.context || s,
nickjillings@1596 7934 // Context for global events is callbackContext if it is a DOM node or jQuery collection
nickjillings@1596 7935 globalEventContext = s.context && ( callbackContext.nodeType || callbackContext.jquery ) ?
nickjillings@1596 7936 jQuery( callbackContext ) :
nickjillings@1596 7937 jQuery.event,
nickjillings@1596 7938 // Deferreds
nickjillings@1596 7939 deferred = jQuery.Deferred(),
nickjillings@1596 7940 completeDeferred = jQuery.Callbacks("once memory"),
nickjillings@1596 7941 // Status-dependent callbacks
nickjillings@1596 7942 statusCode = s.statusCode || {},
nickjillings@1596 7943 // Headers (they are sent all at once)
nickjillings@1596 7944 requestHeaders = {},
nickjillings@1596 7945 requestHeadersNames = {},
nickjillings@1596 7946 // The jqXHR state
nickjillings@1596 7947 state = 0,
nickjillings@1596 7948 // Default abort message
nickjillings@1596 7949 strAbort = "canceled",
nickjillings@1596 7950 // Fake xhr
nickjillings@1596 7951 jqXHR = {
nickjillings@1596 7952 readyState: 0,
nickjillings@1596 7953
nickjillings@1596 7954 // Builds headers hashtable if needed
nickjillings@1596 7955 getResponseHeader: function( key ) {
nickjillings@1596 7956 var match;
nickjillings@1596 7957 if ( state === 2 ) {
nickjillings@1596 7958 if ( !responseHeaders ) {
nickjillings@1596 7959 responseHeaders = {};
nickjillings@1596 7960 while ( (match = rheaders.exec( responseHeadersString )) ) {
nickjillings@1596 7961 responseHeaders[ match[1].toLowerCase() ] = match[ 2 ];
nickjillings@1596 7962 }
nickjillings@1596 7963 }
nickjillings@1596 7964 match = responseHeaders[ key.toLowerCase() ];
nickjillings@1596 7965 }
nickjillings@1596 7966 return match == null ? null : match;
nickjillings@1596 7967 },
nickjillings@1596 7968
nickjillings@1596 7969 // Raw string
nickjillings@1596 7970 getAllResponseHeaders: function() {
nickjillings@1596 7971 return state === 2 ? responseHeadersString : null;
nickjillings@1596 7972 },
nickjillings@1596 7973
nickjillings@1596 7974 // Caches the header
nickjillings@1596 7975 setRequestHeader: function( name, value ) {
nickjillings@1596 7976 var lname = name.toLowerCase();
nickjillings@1596 7977 if ( !state ) {
nickjillings@1596 7978 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
nickjillings@1596 7979 requestHeaders[ name ] = value;
nickjillings@1596 7980 }
nickjillings@1596 7981 return this;
nickjillings@1596 7982 },
nickjillings@1596 7983
nickjillings@1596 7984 // Overrides response content-type header
nickjillings@1596 7985 overrideMimeType: function( type ) {
nickjillings@1596 7986 if ( !state ) {
nickjillings@1596 7987 s.mimeType = type;
nickjillings@1596 7988 }
nickjillings@1596 7989 return this;
nickjillings@1596 7990 },
nickjillings@1596 7991
nickjillings@1596 7992 // Status-dependent callbacks
nickjillings@1596 7993 statusCode: function( map ) {
nickjillings@1596 7994 var code;
nickjillings@1596 7995 if ( map ) {
nickjillings@1596 7996 if ( state < 2 ) {
nickjillings@1596 7997 for ( code in map ) {
nickjillings@1596 7998 // Lazy-add the new callback in a way that preserves old ones
nickjillings@1596 7999 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
nickjillings@1596 8000 }
nickjillings@1596 8001 } else {
nickjillings@1596 8002 // Execute the appropriate callbacks
nickjillings@1596 8003 jqXHR.always( map[ jqXHR.status ] );
nickjillings@1596 8004 }
nickjillings@1596 8005 }
nickjillings@1596 8006 return this;
nickjillings@1596 8007 },
nickjillings@1596 8008
nickjillings@1596 8009 // Cancel the request
nickjillings@1596 8010 abort: function( statusText ) {
nickjillings@1596 8011 var finalText = statusText || strAbort;
nickjillings@1596 8012 if ( transport ) {
nickjillings@1596 8013 transport.abort( finalText );
nickjillings@1596 8014 }
nickjillings@1596 8015 done( 0, finalText );
nickjillings@1596 8016 return this;
nickjillings@1596 8017 }
nickjillings@1596 8018 };
nickjillings@1596 8019
nickjillings@1596 8020 // Attach deferreds
nickjillings@1596 8021 deferred.promise( jqXHR ).complete = completeDeferred.add;
nickjillings@1596 8022 jqXHR.success = jqXHR.done;
nickjillings@1596 8023 jqXHR.error = jqXHR.fail;
nickjillings@1596 8024
nickjillings@1596 8025 // Remove hash character (#7531: and string promotion)
nickjillings@1596 8026 // Add protocol if not provided (prefilters might expect it)
nickjillings@1596 8027 // Handle falsy url in the settings object (#10093: consistency with old signature)
nickjillings@1596 8028 // We also use the url parameter if available
nickjillings@1596 8029 s.url = ( ( url || s.url || ajaxLocation ) + "" ).replace( rhash, "" )
nickjillings@1596 8030 .replace( rprotocol, ajaxLocParts[ 1 ] + "//" );
nickjillings@1596 8031
nickjillings@1596 8032 // Alias method option to type as per ticket #12004
nickjillings@1596 8033 s.type = options.method || options.type || s.method || s.type;
nickjillings@1596 8034
nickjillings@1596 8035 // Extract dataTypes list
nickjillings@1596 8036 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
nickjillings@1596 8037
nickjillings@1596 8038 // A cross-domain request is in order when we have a protocol:host:port mismatch
nickjillings@1596 8039 if ( s.crossDomain == null ) {
nickjillings@1596 8040 parts = rurl.exec( s.url.toLowerCase() );
nickjillings@1596 8041 s.crossDomain = !!( parts &&
nickjillings@1596 8042 ( parts[ 1 ] !== ajaxLocParts[ 1 ] || parts[ 2 ] !== ajaxLocParts[ 2 ] ||
nickjillings@1596 8043 ( parts[ 3 ] || ( parts[ 1 ] === "http:" ? "80" : "443" ) ) !==
nickjillings@1596 8044 ( ajaxLocParts[ 3 ] || ( ajaxLocParts[ 1 ] === "http:" ? "80" : "443" ) ) )
nickjillings@1596 8045 );
nickjillings@1596 8046 }
nickjillings@1596 8047
nickjillings@1596 8048 // Convert data if not already a string
nickjillings@1596 8049 if ( s.data && s.processData && typeof s.data !== "string" ) {
nickjillings@1596 8050 s.data = jQuery.param( s.data, s.traditional );
nickjillings@1596 8051 }
nickjillings@1596 8052
nickjillings@1596 8053 // Apply prefilters
nickjillings@1596 8054 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
nickjillings@1596 8055
nickjillings@1596 8056 // If request was aborted inside a prefilter, stop there
nickjillings@1596 8057 if ( state === 2 ) {
nickjillings@1596 8058 return jqXHR;
nickjillings@1596 8059 }
nickjillings@1596 8060
nickjillings@1596 8061 // We can fire global events as of now if asked to
nickjillings@1596 8062 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
nickjillings@1596 8063 fireGlobals = jQuery.event && s.global;
nickjillings@1596 8064
nickjillings@1596 8065 // Watch for a new set of requests
nickjillings@1596 8066 if ( fireGlobals && jQuery.active++ === 0 ) {
nickjillings@1596 8067 jQuery.event.trigger("ajaxStart");
nickjillings@1596 8068 }
nickjillings@1596 8069
nickjillings@1596 8070 // Uppercase the type
nickjillings@1596 8071 s.type = s.type.toUpperCase();
nickjillings@1596 8072
nickjillings@1596 8073 // Determine if request has content
nickjillings@1596 8074 s.hasContent = !rnoContent.test( s.type );
nickjillings@1596 8075
nickjillings@1596 8076 // Save the URL in case we're toying with the If-Modified-Since
nickjillings@1596 8077 // and/or If-None-Match header later on
nickjillings@1596 8078 cacheURL = s.url;
nickjillings@1596 8079
nickjillings@1596 8080 // More options handling for requests with no content
nickjillings@1596 8081 if ( !s.hasContent ) {
nickjillings@1596 8082
nickjillings@1596 8083 // If data is available, append data to url
nickjillings@1596 8084 if ( s.data ) {
nickjillings@1596 8085 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
nickjillings@1596 8086 // #9682: remove data so that it's not used in an eventual retry
nickjillings@1596 8087 delete s.data;
nickjillings@1596 8088 }
nickjillings@1596 8089
nickjillings@1596 8090 // Add anti-cache in url if needed
nickjillings@1596 8091 if ( s.cache === false ) {
nickjillings@1596 8092 s.url = rts.test( cacheURL ) ?
nickjillings@1596 8093
nickjillings@1596 8094 // If there is already a '_' parameter, set its value
nickjillings@1596 8095 cacheURL.replace( rts, "$1_=" + nonce++ ) :
nickjillings@1596 8096
nickjillings@1596 8097 // Otherwise add one to the end
nickjillings@1596 8098 cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
nickjillings@1596 8099 }
nickjillings@1596 8100 }
nickjillings@1596 8101
nickjillings@1596 8102 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1596 8103 if ( s.ifModified ) {
nickjillings@1596 8104 if ( jQuery.lastModified[ cacheURL ] ) {
nickjillings@1596 8105 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
nickjillings@1596 8106 }
nickjillings@1596 8107 if ( jQuery.etag[ cacheURL ] ) {
nickjillings@1596 8108 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
nickjillings@1596 8109 }
nickjillings@1596 8110 }
nickjillings@1596 8111
nickjillings@1596 8112 // Set the correct header, if data is being sent
nickjillings@1596 8113 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
nickjillings@1596 8114 jqXHR.setRequestHeader( "Content-Type", s.contentType );
nickjillings@1596 8115 }
nickjillings@1596 8116
nickjillings@1596 8117 // Set the Accepts header for the server, depending on the dataType
nickjillings@1596 8118 jqXHR.setRequestHeader(
nickjillings@1596 8119 "Accept",
nickjillings@1596 8120 s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[0] ] ?
nickjillings@1596 8121 s.accepts[ s.dataTypes[0] ] + ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
nickjillings@1596 8122 s.accepts[ "*" ]
nickjillings@1596 8123 );
nickjillings@1596 8124
nickjillings@1596 8125 // Check for headers option
nickjillings@1596 8126 for ( i in s.headers ) {
nickjillings@1596 8127 jqXHR.setRequestHeader( i, s.headers[ i ] );
nickjillings@1596 8128 }
nickjillings@1596 8129
nickjillings@1596 8130 // Allow custom headers/mimetypes and early abort
nickjillings@1596 8131 if ( s.beforeSend && ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
nickjillings@1596 8132 // Abort if not done already and return
nickjillings@1596 8133 return jqXHR.abort();
nickjillings@1596 8134 }
nickjillings@1596 8135
nickjillings@1596 8136 // Aborting is no longer a cancellation
nickjillings@1596 8137 strAbort = "abort";
nickjillings@1596 8138
nickjillings@1596 8139 // Install callbacks on deferreds
nickjillings@1596 8140 for ( i in { success: 1, error: 1, complete: 1 } ) {
nickjillings@1596 8141 jqXHR[ i ]( s[ i ] );
nickjillings@1596 8142 }
nickjillings@1596 8143
nickjillings@1596 8144 // Get transport
nickjillings@1596 8145 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
nickjillings@1596 8146
nickjillings@1596 8147 // If no transport, we auto-abort
nickjillings@1596 8148 if ( !transport ) {
nickjillings@1596 8149 done( -1, "No Transport" );
nickjillings@1596 8150 } else {
nickjillings@1596 8151 jqXHR.readyState = 1;
nickjillings@1596 8152
nickjillings@1596 8153 // Send global event
nickjillings@1596 8154 if ( fireGlobals ) {
nickjillings@1596 8155 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
nickjillings@1596 8156 }
nickjillings@1596 8157 // Timeout
nickjillings@1596 8158 if ( s.async && s.timeout > 0 ) {
nickjillings@1596 8159 timeoutTimer = setTimeout(function() {
nickjillings@1596 8160 jqXHR.abort("timeout");
nickjillings@1596 8161 }, s.timeout );
nickjillings@1596 8162 }
nickjillings@1596 8163
nickjillings@1596 8164 try {
nickjillings@1596 8165 state = 1;
nickjillings@1596 8166 transport.send( requestHeaders, done );
nickjillings@1596 8167 } catch ( e ) {
nickjillings@1596 8168 // Propagate exception as error if not done
nickjillings@1596 8169 if ( state < 2 ) {
nickjillings@1596 8170 done( -1, e );
nickjillings@1596 8171 // Simply rethrow otherwise
nickjillings@1596 8172 } else {
nickjillings@1596 8173 throw e;
nickjillings@1596 8174 }
nickjillings@1596 8175 }
nickjillings@1596 8176 }
nickjillings@1596 8177
nickjillings@1596 8178 // Callback for when everything is done
nickjillings@1596 8179 function done( status, nativeStatusText, responses, headers ) {
nickjillings@1596 8180 var isSuccess, success, error, response, modified,
nickjillings@1596 8181 statusText = nativeStatusText;
nickjillings@1596 8182
nickjillings@1596 8183 // Called once
nickjillings@1596 8184 if ( state === 2 ) {
nickjillings@1596 8185 return;
nickjillings@1596 8186 }
nickjillings@1596 8187
nickjillings@1596 8188 // State is "done" now
nickjillings@1596 8189 state = 2;
nickjillings@1596 8190
nickjillings@1596 8191 // Clear timeout if it exists
nickjillings@1596 8192 if ( timeoutTimer ) {
nickjillings@1596 8193 clearTimeout( timeoutTimer );
nickjillings@1596 8194 }
nickjillings@1596 8195
nickjillings@1596 8196 // Dereference transport for early garbage collection
nickjillings@1596 8197 // (no matter how long the jqXHR object will be used)
nickjillings@1596 8198 transport = undefined;
nickjillings@1596 8199
nickjillings@1596 8200 // Cache response headers
nickjillings@1596 8201 responseHeadersString = headers || "";
nickjillings@1596 8202
nickjillings@1596 8203 // Set readyState
nickjillings@1596 8204 jqXHR.readyState = status > 0 ? 4 : 0;
nickjillings@1596 8205
nickjillings@1596 8206 // Determine if successful
nickjillings@1596 8207 isSuccess = status >= 200 && status < 300 || status === 304;
nickjillings@1596 8208
nickjillings@1596 8209 // Get response data
nickjillings@1596 8210 if ( responses ) {
nickjillings@1596 8211 response = ajaxHandleResponses( s, jqXHR, responses );
nickjillings@1596 8212 }
nickjillings@1596 8213
nickjillings@1596 8214 // Convert no matter what (that way responseXXX fields are always set)
nickjillings@1596 8215 response = ajaxConvert( s, response, jqXHR, isSuccess );
nickjillings@1596 8216
nickjillings@1596 8217 // If successful, handle type chaining
nickjillings@1596 8218 if ( isSuccess ) {
nickjillings@1596 8219
nickjillings@1596 8220 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
nickjillings@1596 8221 if ( s.ifModified ) {
nickjillings@1596 8222 modified = jqXHR.getResponseHeader("Last-Modified");
nickjillings@1596 8223 if ( modified ) {
nickjillings@1596 8224 jQuery.lastModified[ cacheURL ] = modified;
nickjillings@1596 8225 }
nickjillings@1596 8226 modified = jqXHR.getResponseHeader("etag");
nickjillings@1596 8227 if ( modified ) {
nickjillings@1596 8228 jQuery.etag[ cacheURL ] = modified;
nickjillings@1596 8229 }
nickjillings@1596 8230 }
nickjillings@1596 8231
nickjillings@1596 8232 // if no content
nickjillings@1596 8233 if ( status === 204 || s.type === "HEAD" ) {
nickjillings@1596 8234 statusText = "nocontent";
nickjillings@1596 8235
nickjillings@1596 8236 // if not modified
nickjillings@1596 8237 } else if ( status === 304 ) {
nickjillings@1596 8238 statusText = "notmodified";
nickjillings@1596 8239
nickjillings@1596 8240 // If we have data, let's convert it
nickjillings@1596 8241 } else {
nickjillings@1596 8242 statusText = response.state;
nickjillings@1596 8243 success = response.data;
nickjillings@1596 8244 error = response.error;
nickjillings@1596 8245 isSuccess = !error;
nickjillings@1596 8246 }
nickjillings@1596 8247 } else {
nickjillings@1596 8248 // Extract error from statusText and normalize for non-aborts
nickjillings@1596 8249 error = statusText;
nickjillings@1596 8250 if ( status || !statusText ) {
nickjillings@1596 8251 statusText = "error";
nickjillings@1596 8252 if ( status < 0 ) {
nickjillings@1596 8253 status = 0;
nickjillings@1596 8254 }
nickjillings@1596 8255 }
nickjillings@1596 8256 }
nickjillings@1596 8257
nickjillings@1596 8258 // Set data for the fake xhr object
nickjillings@1596 8259 jqXHR.status = status;
nickjillings@1596 8260 jqXHR.statusText = ( nativeStatusText || statusText ) + "";
nickjillings@1596 8261
nickjillings@1596 8262 // Success/Error
nickjillings@1596 8263 if ( isSuccess ) {
nickjillings@1596 8264 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
nickjillings@1596 8265 } else {
nickjillings@1596 8266 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
nickjillings@1596 8267 }
nickjillings@1596 8268
nickjillings@1596 8269 // Status-dependent callbacks
nickjillings@1596 8270 jqXHR.statusCode( statusCode );
nickjillings@1596 8271 statusCode = undefined;
nickjillings@1596 8272
nickjillings@1596 8273 if ( fireGlobals ) {
nickjillings@1596 8274 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
nickjillings@1596 8275 [ jqXHR, s, isSuccess ? success : error ] );
nickjillings@1596 8276 }
nickjillings@1596 8277
nickjillings@1596 8278 // Complete
nickjillings@1596 8279 completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
nickjillings@1596 8280
nickjillings@1596 8281 if ( fireGlobals ) {
nickjillings@1596 8282 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
nickjillings@1596 8283 // Handle the global AJAX counter
nickjillings@1596 8284 if ( !( --jQuery.active ) ) {
nickjillings@1596 8285 jQuery.event.trigger("ajaxStop");
nickjillings@1596 8286 }
nickjillings@1596 8287 }
nickjillings@1596 8288 }
nickjillings@1596 8289
nickjillings@1596 8290 return jqXHR;
nickjillings@1596 8291 },
nickjillings@1596 8292
nickjillings@1596 8293 getJSON: function( url, data, callback ) {
nickjillings@1596 8294 return jQuery.get( url, data, callback, "json" );
nickjillings@1596 8295 },
nickjillings@1596 8296
nickjillings@1596 8297 getScript: function( url, callback ) {
nickjillings@1596 8298 return jQuery.get( url, undefined, callback, "script" );
nickjillings@1596 8299 }
nickjillings@1596 8300 });
nickjillings@1596 8301
nickjillings@1596 8302 jQuery.each( [ "get", "post" ], function( i, method ) {
nickjillings@1596 8303 jQuery[ method ] = function( url, data, callback, type ) {
nickjillings@1596 8304 // Shift arguments if data argument was omitted
nickjillings@1596 8305 if ( jQuery.isFunction( data ) ) {
nickjillings@1596 8306 type = type || callback;
nickjillings@1596 8307 callback = data;
nickjillings@1596 8308 data = undefined;
nickjillings@1596 8309 }
nickjillings@1596 8310
nickjillings@1596 8311 return jQuery.ajax({
nickjillings@1596 8312 url: url,
nickjillings@1596 8313 type: method,
nickjillings@1596 8314 dataType: type,
nickjillings@1596 8315 data: data,
nickjillings@1596 8316 success: callback
nickjillings@1596 8317 });
nickjillings@1596 8318 };
nickjillings@1596 8319 });
nickjillings@1596 8320
nickjillings@1596 8321
nickjillings@1596 8322 jQuery._evalUrl = function( url ) {
nickjillings@1596 8323 return jQuery.ajax({
nickjillings@1596 8324 url: url,
nickjillings@1596 8325 type: "GET",
nickjillings@1596 8326 dataType: "script",
nickjillings@1596 8327 async: false,
nickjillings@1596 8328 global: false,
nickjillings@1596 8329 "throws": true
nickjillings@1596 8330 });
nickjillings@1596 8331 };
nickjillings@1596 8332
nickjillings@1596 8333
nickjillings@1596 8334 jQuery.fn.extend({
nickjillings@1596 8335 wrapAll: function( html ) {
nickjillings@1596 8336 var wrap;
nickjillings@1596 8337
nickjillings@1596 8338 if ( jQuery.isFunction( html ) ) {
nickjillings@1596 8339 return this.each(function( i ) {
nickjillings@1596 8340 jQuery( this ).wrapAll( html.call(this, i) );
nickjillings@1596 8341 });
nickjillings@1596 8342 }
nickjillings@1596 8343
nickjillings@1596 8344 if ( this[ 0 ] ) {
nickjillings@1596 8345
nickjillings@1596 8346 // The elements to wrap the target around
nickjillings@1596 8347 wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
nickjillings@1596 8348
nickjillings@1596 8349 if ( this[ 0 ].parentNode ) {
nickjillings@1596 8350 wrap.insertBefore( this[ 0 ] );
nickjillings@1596 8351 }
nickjillings@1596 8352
nickjillings@1596 8353 wrap.map(function() {
nickjillings@1596 8354 var elem = this;
nickjillings@1596 8355
nickjillings@1596 8356 while ( elem.firstElementChild ) {
nickjillings@1596 8357 elem = elem.firstElementChild;
nickjillings@1596 8358 }
nickjillings@1596 8359
nickjillings@1596 8360 return elem;
nickjillings@1596 8361 }).append( this );
nickjillings@1596 8362 }
nickjillings@1596 8363
nickjillings@1596 8364 return this;
nickjillings@1596 8365 },
nickjillings@1596 8366
nickjillings@1596 8367 wrapInner: function( html ) {
nickjillings@1596 8368 if ( jQuery.isFunction( html ) ) {
nickjillings@1596 8369 return this.each(function( i ) {
nickjillings@1596 8370 jQuery( this ).wrapInner( html.call(this, i) );
nickjillings@1596 8371 });
nickjillings@1596 8372 }
nickjillings@1596 8373
nickjillings@1596 8374 return this.each(function() {
nickjillings@1596 8375 var self = jQuery( this ),
nickjillings@1596 8376 contents = self.contents();
nickjillings@1596 8377
nickjillings@1596 8378 if ( contents.length ) {
nickjillings@1596 8379 contents.wrapAll( html );
nickjillings@1596 8380
nickjillings@1596 8381 } else {
nickjillings@1596 8382 self.append( html );
nickjillings@1596 8383 }
nickjillings@1596 8384 });
nickjillings@1596 8385 },
nickjillings@1596 8386
nickjillings@1596 8387 wrap: function( html ) {
nickjillings@1596 8388 var isFunction = jQuery.isFunction( html );
nickjillings@1596 8389
nickjillings@1596 8390 return this.each(function( i ) {
nickjillings@1596 8391 jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
nickjillings@1596 8392 });
nickjillings@1596 8393 },
nickjillings@1596 8394
nickjillings@1596 8395 unwrap: function() {
nickjillings@1596 8396 return this.parent().each(function() {
nickjillings@1596 8397 if ( !jQuery.nodeName( this, "body" ) ) {
nickjillings@1596 8398 jQuery( this ).replaceWith( this.childNodes );
nickjillings@1596 8399 }
nickjillings@1596 8400 }).end();
nickjillings@1596 8401 }
nickjillings@1596 8402 });
nickjillings@1596 8403
nickjillings@1596 8404
nickjillings@1596 8405 jQuery.expr.filters.hidden = function( elem ) {
nickjillings@1596 8406 // Support: Opera <= 12.12
nickjillings@1596 8407 // Opera reports offsetWidths and offsetHeights less than zero on some elements
nickjillings@1596 8408 return elem.offsetWidth <= 0 && elem.offsetHeight <= 0;
nickjillings@1596 8409 };
nickjillings@1596 8410 jQuery.expr.filters.visible = function( elem ) {
nickjillings@1596 8411 return !jQuery.expr.filters.hidden( elem );
nickjillings@1596 8412 };
nickjillings@1596 8413
nickjillings@1596 8414
nickjillings@1596 8415
nickjillings@1596 8416
nickjillings@1596 8417 var r20 = /%20/g,
nickjillings@1596 8418 rbracket = /\[\]$/,
nickjillings@1596 8419 rCRLF = /\r?\n/g,
nickjillings@1596 8420 rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
nickjillings@1596 8421 rsubmittable = /^(?:input|select|textarea|keygen)/i;
nickjillings@1596 8422
nickjillings@1596 8423 function buildParams( prefix, obj, traditional, add ) {
nickjillings@1596 8424 var name;
nickjillings@1596 8425
nickjillings@1596 8426 if ( jQuery.isArray( obj ) ) {
nickjillings@1596 8427 // Serialize array item.
nickjillings@1596 8428 jQuery.each( obj, function( i, v ) {
nickjillings@1596 8429 if ( traditional || rbracket.test( prefix ) ) {
nickjillings@1596 8430 // Treat each array item as a scalar.
nickjillings@1596 8431 add( prefix, v );
nickjillings@1596 8432
nickjillings@1596 8433 } else {
nickjillings@1596 8434 // Item is non-scalar (array or object), encode its numeric index.
nickjillings@1596 8435 buildParams( prefix + "[" + ( typeof v === "object" ? i : "" ) + "]", v, traditional, add );
nickjillings@1596 8436 }
nickjillings@1596 8437 });
nickjillings@1596 8438
nickjillings@1596 8439 } else if ( !traditional && jQuery.type( obj ) === "object" ) {
nickjillings@1596 8440 // Serialize object item.
nickjillings@1596 8441 for ( name in obj ) {
nickjillings@1596 8442 buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
nickjillings@1596 8443 }
nickjillings@1596 8444
nickjillings@1596 8445 } else {
nickjillings@1596 8446 // Serialize scalar item.
nickjillings@1596 8447 add( prefix, obj );
nickjillings@1596 8448 }
nickjillings@1596 8449 }
nickjillings@1596 8450
nickjillings@1596 8451 // Serialize an array of form elements or a set of
nickjillings@1596 8452 // key/values into a query string
nickjillings@1596 8453 jQuery.param = function( a, traditional ) {
nickjillings@1596 8454 var prefix,
nickjillings@1596 8455 s = [],
nickjillings@1596 8456 add = function( key, value ) {
nickjillings@1596 8457 // If value is a function, invoke it and return its value
nickjillings@1596 8458 value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
nickjillings@1596 8459 s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
nickjillings@1596 8460 };
nickjillings@1596 8461
nickjillings@1596 8462 // Set traditional to true for jQuery <= 1.3.2 behavior.
nickjillings@1596 8463 if ( traditional === undefined ) {
nickjillings@1596 8464 traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
nickjillings@1596 8465 }
nickjillings@1596 8466
nickjillings@1596 8467 // If an array was passed in, assume that it is an array of form elements.
nickjillings@1596 8468 if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
nickjillings@1596 8469 // Serialize the form elements
nickjillings@1596 8470 jQuery.each( a, function() {
nickjillings@1596 8471 add( this.name, this.value );
nickjillings@1596 8472 });
nickjillings@1596 8473
nickjillings@1596 8474 } else {
nickjillings@1596 8475 // If traditional, encode the "old" way (the way 1.3.2 or older
nickjillings@1596 8476 // did it), otherwise encode params recursively.
nickjillings@1596 8477 for ( prefix in a ) {
nickjillings@1596 8478 buildParams( prefix, a[ prefix ], traditional, add );
nickjillings@1596 8479 }
nickjillings@1596 8480 }
nickjillings@1596 8481
nickjillings@1596 8482 // Return the resulting serialization
nickjillings@1596 8483 return s.join( "&" ).replace( r20, "+" );
nickjillings@1596 8484 };
nickjillings@1596 8485
nickjillings@1596 8486 jQuery.fn.extend({
nickjillings@1596 8487 serialize: function() {
nickjillings@1596 8488 return jQuery.param( this.serializeArray() );
nickjillings@1596 8489 },
nickjillings@1596 8490 serializeArray: function() {
nickjillings@1596 8491 return this.map(function() {
nickjillings@1596 8492 // Can add propHook for "elements" to filter or add form elements
nickjillings@1596 8493 var elements = jQuery.prop( this, "elements" );
nickjillings@1596 8494 return elements ? jQuery.makeArray( elements ) : this;
nickjillings@1596 8495 })
nickjillings@1596 8496 .filter(function() {
nickjillings@1596 8497 var type = this.type;
nickjillings@1596 8498
nickjillings@1596 8499 // Use .is( ":disabled" ) so that fieldset[disabled] works
nickjillings@1596 8500 return this.name && !jQuery( this ).is( ":disabled" ) &&
nickjillings@1596 8501 rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
nickjillings@1596 8502 ( this.checked || !rcheckableType.test( type ) );
nickjillings@1596 8503 })
nickjillings@1596 8504 .map(function( i, elem ) {
nickjillings@1596 8505 var val = jQuery( this ).val();
nickjillings@1596 8506
nickjillings@1596 8507 return val == null ?
nickjillings@1596 8508 null :
nickjillings@1596 8509 jQuery.isArray( val ) ?
nickjillings@1596 8510 jQuery.map( val, function( val ) {
nickjillings@1596 8511 return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1596 8512 }) :
nickjillings@1596 8513 { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
nickjillings@1596 8514 }).get();
nickjillings@1596 8515 }
nickjillings@1596 8516 });
nickjillings@1596 8517
nickjillings@1596 8518
nickjillings@1596 8519 jQuery.ajaxSettings.xhr = function() {
nickjillings@1596 8520 try {
nickjillings@1596 8521 return new XMLHttpRequest();
nickjillings@1596 8522 } catch( e ) {}
nickjillings@1596 8523 };
nickjillings@1596 8524
nickjillings@1596 8525 var xhrId = 0,
nickjillings@1596 8526 xhrCallbacks = {},
nickjillings@1596 8527 xhrSuccessStatus = {
nickjillings@1596 8528 // file protocol always yields status code 0, assume 200
nickjillings@1596 8529 0: 200,
nickjillings@1596 8530 // Support: IE9
nickjillings@1596 8531 // #1450: sometimes IE returns 1223 when it should be 204
nickjillings@1596 8532 1223: 204
nickjillings@1596 8533 },
nickjillings@1596 8534 xhrSupported = jQuery.ajaxSettings.xhr();
nickjillings@1596 8535
nickjillings@1596 8536 // Support: IE9
nickjillings@1596 8537 // Open requests must be manually aborted on unload (#5280)
nickjillings@1596 8538 // See https://support.microsoft.com/kb/2856746 for more info
nickjillings@1596 8539 if ( window.attachEvent ) {
nickjillings@1596 8540 window.attachEvent( "onunload", function() {
nickjillings@1596 8541 for ( var key in xhrCallbacks ) {
nickjillings@1596 8542 xhrCallbacks[ key ]();
nickjillings@1596 8543 }
nickjillings@1596 8544 });
nickjillings@1596 8545 }
nickjillings@1596 8546
nickjillings@1596 8547 support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
nickjillings@1596 8548 support.ajax = xhrSupported = !!xhrSupported;
nickjillings@1596 8549
nickjillings@1596 8550 jQuery.ajaxTransport(function( options ) {
nickjillings@1596 8551 var callback;
nickjillings@1596 8552
nickjillings@1596 8553 // Cross domain only allowed if supported through XMLHttpRequest
nickjillings@1596 8554 if ( support.cors || xhrSupported && !options.crossDomain ) {
nickjillings@1596 8555 return {
nickjillings@1596 8556 send: function( headers, complete ) {
nickjillings@1596 8557 var i,
nickjillings@1596 8558 xhr = options.xhr(),
nickjillings@1596 8559 id = ++xhrId;
nickjillings@1596 8560
nickjillings@1596 8561 xhr.open( options.type, options.url, options.async, options.username, options.password );
nickjillings@1596 8562
nickjillings@1596 8563 // Apply custom fields if provided
nickjillings@1596 8564 if ( options.xhrFields ) {
nickjillings@1596 8565 for ( i in options.xhrFields ) {
nickjillings@1596 8566 xhr[ i ] = options.xhrFields[ i ];
nickjillings@1596 8567 }
nickjillings@1596 8568 }
nickjillings@1596 8569
nickjillings@1596 8570 // Override mime type if needed
nickjillings@1596 8571 if ( options.mimeType && xhr.overrideMimeType ) {
nickjillings@1596 8572 xhr.overrideMimeType( options.mimeType );
nickjillings@1596 8573 }
nickjillings@1596 8574
nickjillings@1596 8575 // X-Requested-With header
nickjillings@1596 8576 // For cross-domain requests, seeing as conditions for a preflight are
nickjillings@1596 8577 // akin to a jigsaw puzzle, we simply never set it to be sure.
nickjillings@1596 8578 // (it can always be set on a per-request basis or even using ajaxSetup)
nickjillings@1596 8579 // For same-domain requests, won't change header if already provided.
nickjillings@1596 8580 if ( !options.crossDomain && !headers["X-Requested-With"] ) {
nickjillings@1596 8581 headers["X-Requested-With"] = "XMLHttpRequest";
nickjillings@1596 8582 }
nickjillings@1596 8583
nickjillings@1596 8584 // Set headers
nickjillings@1596 8585 for ( i in headers ) {
nickjillings@1596 8586 xhr.setRequestHeader( i, headers[ i ] );
nickjillings@1596 8587 }
nickjillings@1596 8588
nickjillings@1596 8589 // Callback
nickjillings@1596 8590 callback = function( type ) {
nickjillings@1596 8591 return function() {
nickjillings@1596 8592 if ( callback ) {
nickjillings@1596 8593 delete xhrCallbacks[ id ];
nickjillings@1596 8594 callback = xhr.onload = xhr.onerror = null;
nickjillings@1596 8595
nickjillings@1596 8596 if ( type === "abort" ) {
nickjillings@1596 8597 xhr.abort();
nickjillings@1596 8598 } else if ( type === "error" ) {
nickjillings@1596 8599 complete(
nickjillings@1596 8600 // file: protocol always yields status 0; see #8605, #14207
nickjillings@1596 8601 xhr.status,
nickjillings@1596 8602 xhr.statusText
nickjillings@1596 8603 );
nickjillings@1596 8604 } else {
nickjillings@1596 8605 complete(
nickjillings@1596 8606 xhrSuccessStatus[ xhr.status ] || xhr.status,
nickjillings@1596 8607 xhr.statusText,
nickjillings@1596 8608 // Support: IE9
nickjillings@1596 8609 // Accessing binary-data responseText throws an exception
nickjillings@1596 8610 // (#11426)
nickjillings@1596 8611 typeof xhr.responseText === "string" ? {
nickjillings@1596 8612 text: xhr.responseText
nickjillings@1596 8613 } : undefined,
nickjillings@1596 8614 xhr.getAllResponseHeaders()
nickjillings@1596 8615 );
nickjillings@1596 8616 }
nickjillings@1596 8617 }
nickjillings@1596 8618 };
nickjillings@1596 8619 };
nickjillings@1596 8620
nickjillings@1596 8621 // Listen to events
nickjillings@1596 8622 xhr.onload = callback();
nickjillings@1596 8623 xhr.onerror = callback("error");
nickjillings@1596 8624
nickjillings@1596 8625 // Create the abort callback
nickjillings@1596 8626 callback = xhrCallbacks[ id ] = callback("abort");
nickjillings@1596 8627
nickjillings@1596 8628 try {
nickjillings@1596 8629 // Do send the request (this may raise an exception)
nickjillings@1596 8630 xhr.send( options.hasContent && options.data || null );
nickjillings@1596 8631 } catch ( e ) {
nickjillings@1596 8632 // #14683: Only rethrow if this hasn't been notified as an error yet
nickjillings@1596 8633 if ( callback ) {
nickjillings@1596 8634 throw e;
nickjillings@1596 8635 }
nickjillings@1596 8636 }
nickjillings@1596 8637 },
nickjillings@1596 8638
nickjillings@1596 8639 abort: function() {
nickjillings@1596 8640 if ( callback ) {
nickjillings@1596 8641 callback();
nickjillings@1596 8642 }
nickjillings@1596 8643 }
nickjillings@1596 8644 };
nickjillings@1596 8645 }
nickjillings@1596 8646 });
nickjillings@1596 8647
nickjillings@1596 8648
nickjillings@1596 8649
nickjillings@1596 8650
nickjillings@1596 8651 // Install script dataType
nickjillings@1596 8652 jQuery.ajaxSetup({
nickjillings@1596 8653 accepts: {
nickjillings@1596 8654 script: "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
nickjillings@1596 8655 },
nickjillings@1596 8656 contents: {
nickjillings@1596 8657 script: /(?:java|ecma)script/
nickjillings@1596 8658 },
nickjillings@1596 8659 converters: {
nickjillings@1596 8660 "text script": function( text ) {
nickjillings@1596 8661 jQuery.globalEval( text );
nickjillings@1596 8662 return text;
nickjillings@1596 8663 }
nickjillings@1596 8664 }
nickjillings@1596 8665 });
nickjillings@1596 8666
nickjillings@1596 8667 // Handle cache's special case and crossDomain
nickjillings@1596 8668 jQuery.ajaxPrefilter( "script", function( s ) {
nickjillings@1596 8669 if ( s.cache === undefined ) {
nickjillings@1596 8670 s.cache = false;
nickjillings@1596 8671 }
nickjillings@1596 8672 if ( s.crossDomain ) {
nickjillings@1596 8673 s.type = "GET";
nickjillings@1596 8674 }
nickjillings@1596 8675 });
nickjillings@1596 8676
nickjillings@1596 8677 // Bind script tag hack transport
nickjillings@1596 8678 jQuery.ajaxTransport( "script", function( s ) {
nickjillings@1596 8679 // This transport only deals with cross domain requests
nickjillings@1596 8680 if ( s.crossDomain ) {
nickjillings@1596 8681 var script, callback;
nickjillings@1596 8682 return {
nickjillings@1596 8683 send: function( _, complete ) {
nickjillings@1596 8684 script = jQuery("<script>").prop({
nickjillings@1596 8685 async: true,
nickjillings@1596 8686 charset: s.scriptCharset,
nickjillings@1596 8687 src: s.url
nickjillings@1596 8688 }).on(
nickjillings@1596 8689 "load error",
nickjillings@1596 8690 callback = function( evt ) {
nickjillings@1596 8691 script.remove();
nickjillings@1596 8692 callback = null;
nickjillings@1596 8693 if ( evt ) {
nickjillings@1596 8694 complete( evt.type === "error" ? 404 : 200, evt.type );
nickjillings@1596 8695 }
nickjillings@1596 8696 }
nickjillings@1596 8697 );
nickjillings@1596 8698 document.head.appendChild( script[ 0 ] );
nickjillings@1596 8699 },
nickjillings@1596 8700 abort: function() {
nickjillings@1596 8701 if ( callback ) {
nickjillings@1596 8702 callback();
nickjillings@1596 8703 }
nickjillings@1596 8704 }
nickjillings@1596 8705 };
nickjillings@1596 8706 }
nickjillings@1596 8707 });
nickjillings@1596 8708
nickjillings@1596 8709
nickjillings@1596 8710
nickjillings@1596 8711
nickjillings@1596 8712 var oldCallbacks = [],
nickjillings@1596 8713 rjsonp = /(=)\?(?=&|$)|\?\?/;
nickjillings@1596 8714
nickjillings@1596 8715 // Default jsonp settings
nickjillings@1596 8716 jQuery.ajaxSetup({
nickjillings@1596 8717 jsonp: "callback",
nickjillings@1596 8718 jsonpCallback: function() {
nickjillings@1596 8719 var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
nickjillings@1596 8720 this[ callback ] = true;
nickjillings@1596 8721 return callback;
nickjillings@1596 8722 }
nickjillings@1596 8723 });
nickjillings@1596 8724
nickjillings@1596 8725 // Detect, normalize options and install callbacks for jsonp requests
nickjillings@1596 8726 jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
nickjillings@1596 8727
nickjillings@1596 8728 var callbackName, overwritten, responseContainer,
nickjillings@1596 8729 jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
nickjillings@1596 8730 "url" :
nickjillings@1596 8731 typeof s.data === "string" && !( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") && rjsonp.test( s.data ) && "data"
nickjillings@1596 8732 );
nickjillings@1596 8733
nickjillings@1596 8734 // Handle iff the expected data type is "jsonp" or we have a parameter to set
nickjillings@1596 8735 if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
nickjillings@1596 8736
nickjillings@1596 8737 // Get callback name, remembering preexisting value associated with it
nickjillings@1596 8738 callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
nickjillings@1596 8739 s.jsonpCallback() :
nickjillings@1596 8740 s.jsonpCallback;
nickjillings@1596 8741
nickjillings@1596 8742 // Insert callback into url or form data
nickjillings@1596 8743 if ( jsonProp ) {
nickjillings@1596 8744 s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
nickjillings@1596 8745 } else if ( s.jsonp !== false ) {
nickjillings@1596 8746 s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
nickjillings@1596 8747 }
nickjillings@1596 8748
nickjillings@1596 8749 // Use data converter to retrieve json after script execution
nickjillings@1596 8750 s.converters["script json"] = function() {
nickjillings@1596 8751 if ( !responseContainer ) {
nickjillings@1596 8752 jQuery.error( callbackName + " was not called" );
nickjillings@1596 8753 }
nickjillings@1596 8754 return responseContainer[ 0 ];
nickjillings@1596 8755 };
nickjillings@1596 8756
nickjillings@1596 8757 // force json dataType
nickjillings@1596 8758 s.dataTypes[ 0 ] = "json";
nickjillings@1596 8759
nickjillings@1596 8760 // Install callback
nickjillings@1596 8761 overwritten = window[ callbackName ];
nickjillings@1596 8762 window[ callbackName ] = function() {
nickjillings@1596 8763 responseContainer = arguments;
nickjillings@1596 8764 };
nickjillings@1596 8765
nickjillings@1596 8766 // Clean-up function (fires after converters)
nickjillings@1596 8767 jqXHR.always(function() {
nickjillings@1596 8768 // Restore preexisting value
nickjillings@1596 8769 window[ callbackName ] = overwritten;
nickjillings@1596 8770
nickjillings@1596 8771 // Save back as free
nickjillings@1596 8772 if ( s[ callbackName ] ) {
nickjillings@1596 8773 // make sure that re-using the options doesn't screw things around
nickjillings@1596 8774 s.jsonpCallback = originalSettings.jsonpCallback;
nickjillings@1596 8775
nickjillings@1596 8776 // save the callback name for future use
nickjillings@1596 8777 oldCallbacks.push( callbackName );
nickjillings@1596 8778 }
nickjillings@1596 8779
nickjillings@1596 8780 // Call if it was a function and we have a response
nickjillings@1596 8781 if ( responseContainer && jQuery.isFunction( overwritten ) ) {
nickjillings@1596 8782 overwritten( responseContainer[ 0 ] );
nickjillings@1596 8783 }
nickjillings@1596 8784
nickjillings@1596 8785 responseContainer = overwritten = undefined;
nickjillings@1596 8786 });
nickjillings@1596 8787
nickjillings@1596 8788 // Delegate to script
nickjillings@1596 8789 return "script";
nickjillings@1596 8790 }
nickjillings@1596 8791 });
nickjillings@1596 8792
nickjillings@1596 8793
nickjillings@1596 8794
nickjillings@1596 8795
nickjillings@1596 8796 // data: string of html
nickjillings@1596 8797 // context (optional): If specified, the fragment will be created in this context, defaults to document
nickjillings@1596 8798 // keepScripts (optional): If true, will include scripts passed in the html string
nickjillings@1596 8799 jQuery.parseHTML = function( data, context, keepScripts ) {
nickjillings@1596 8800 if ( !data || typeof data !== "string" ) {
nickjillings@1596 8801 return null;
nickjillings@1596 8802 }
nickjillings@1596 8803 if ( typeof context === "boolean" ) {
nickjillings@1596 8804 keepScripts = context;
nickjillings@1596 8805 context = false;
nickjillings@1596 8806 }
nickjillings@1596 8807 context = context || document;
nickjillings@1596 8808
nickjillings@1596 8809 var parsed = rsingleTag.exec( data ),
nickjillings@1596 8810 scripts = !keepScripts && [];
nickjillings@1596 8811
nickjillings@1596 8812 // Single tag
nickjillings@1596 8813 if ( parsed ) {
nickjillings@1596 8814 return [ context.createElement( parsed[1] ) ];
nickjillings@1596 8815 }
nickjillings@1596 8816
nickjillings@1596 8817 parsed = jQuery.buildFragment( [ data ], context, scripts );
nickjillings@1596 8818
nickjillings@1596 8819 if ( scripts && scripts.length ) {
nickjillings@1596 8820 jQuery( scripts ).remove();
nickjillings@1596 8821 }
nickjillings@1596 8822
nickjillings@1596 8823 return jQuery.merge( [], parsed.childNodes );
nickjillings@1596 8824 };
nickjillings@1596 8825
nickjillings@1596 8826
nickjillings@1596 8827 // Keep a copy of the old load method
nickjillings@1596 8828 var _load = jQuery.fn.load;
nickjillings@1596 8829
nickjillings@1596 8830 /**
nickjillings@1596 8831 * Load a url into a page
nickjillings@1596 8832 */
nickjillings@1596 8833 jQuery.fn.load = function( url, params, callback ) {
nickjillings@1596 8834 if ( typeof url !== "string" && _load ) {
nickjillings@1596 8835 return _load.apply( this, arguments );
nickjillings@1596 8836 }
nickjillings@1596 8837
nickjillings@1596 8838 var selector, type, response,
nickjillings@1596 8839 self = this,
nickjillings@1596 8840 off = url.indexOf(" ");
nickjillings@1596 8841
nickjillings@1596 8842 if ( off >= 0 ) {
nickjillings@1596 8843 selector = jQuery.trim( url.slice( off ) );
nickjillings@1596 8844 url = url.slice( 0, off );
nickjillings@1596 8845 }
nickjillings@1596 8846
nickjillings@1596 8847 // If it's a function
nickjillings@1596 8848 if ( jQuery.isFunction( params ) ) {
nickjillings@1596 8849
nickjillings@1596 8850 // We assume that it's the callback
nickjillings@1596 8851 callback = params;
nickjillings@1596 8852 params = undefined;
nickjillings@1596 8853
nickjillings@1596 8854 // Otherwise, build a param string
nickjillings@1596 8855 } else if ( params && typeof params === "object" ) {
nickjillings@1596 8856 type = "POST";
nickjillings@1596 8857 }
nickjillings@1596 8858
nickjillings@1596 8859 // If we have elements to modify, make the request
nickjillings@1596 8860 if ( self.length > 0 ) {
nickjillings@1596 8861 jQuery.ajax({
nickjillings@1596 8862 url: url,
nickjillings@1596 8863
nickjillings@1596 8864 // if "type" variable is undefined, then "GET" method will be used
nickjillings@1596 8865 type: type,
nickjillings@1596 8866 dataType: "html",
nickjillings@1596 8867 data: params
nickjillings@1596 8868 }).done(function( responseText ) {
nickjillings@1596 8869
nickjillings@1596 8870 // Save response for use in complete callback
nickjillings@1596 8871 response = arguments;
nickjillings@1596 8872
nickjillings@1596 8873 self.html( selector ?
nickjillings@1596 8874
nickjillings@1596 8875 // If a selector was specified, locate the right elements in a dummy div
nickjillings@1596 8876 // Exclude scripts to avoid IE 'Permission Denied' errors
nickjillings@1596 8877 jQuery("<div>").append( jQuery.parseHTML( responseText ) ).find( selector ) :
nickjillings@1596 8878
nickjillings@1596 8879 // Otherwise use the full result
nickjillings@1596 8880 responseText );
nickjillings@1596 8881
nickjillings@1596 8882 }).complete( callback && function( jqXHR, status ) {
nickjillings@1596 8883 self.each( callback, response || [ jqXHR.responseText, status, jqXHR ] );
nickjillings@1596 8884 });
nickjillings@1596 8885 }
nickjillings@1596 8886
nickjillings@1596 8887 return this;
nickjillings@1596 8888 };
nickjillings@1596 8889
nickjillings@1596 8890
nickjillings@1596 8891
nickjillings@1596 8892
nickjillings@1596 8893 // Attach a bunch of functions for handling common AJAX events
nickjillings@1596 8894 jQuery.each( [ "ajaxStart", "ajaxStop", "ajaxComplete", "ajaxError", "ajaxSuccess", "ajaxSend" ], function( i, type ) {
nickjillings@1596 8895 jQuery.fn[ type ] = function( fn ) {
nickjillings@1596 8896 return this.on( type, fn );
nickjillings@1596 8897 };
nickjillings@1596 8898 });
nickjillings@1596 8899
nickjillings@1596 8900
nickjillings@1596 8901
nickjillings@1596 8902
nickjillings@1596 8903 jQuery.expr.filters.animated = function( elem ) {
nickjillings@1596 8904 return jQuery.grep(jQuery.timers, function( fn ) {
nickjillings@1596 8905 return elem === fn.elem;
nickjillings@1596 8906 }).length;
nickjillings@1596 8907 };
nickjillings@1596 8908
nickjillings@1596 8909
nickjillings@1596 8910
nickjillings@1596 8911
nickjillings@1596 8912 var docElem = window.document.documentElement;
nickjillings@1596 8913
nickjillings@1596 8914 /**
nickjillings@1596 8915 * Gets a window from an element
nickjillings@1596 8916 */
nickjillings@1596 8917 function getWindow( elem ) {
nickjillings@1596 8918 return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
nickjillings@1596 8919 }
nickjillings@1596 8920
nickjillings@1596 8921 jQuery.offset = {
nickjillings@1596 8922 setOffset: function( elem, options, i ) {
nickjillings@1596 8923 var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
nickjillings@1596 8924 position = jQuery.css( elem, "position" ),
nickjillings@1596 8925 curElem = jQuery( elem ),
nickjillings@1596 8926 props = {};
nickjillings@1596 8927
nickjillings@1596 8928 // Set position first, in-case top/left are set even on static elem
nickjillings@1596 8929 if ( position === "static" ) {
nickjillings@1596 8930 elem.style.position = "relative";
nickjillings@1596 8931 }
nickjillings@1596 8932
nickjillings@1596 8933 curOffset = curElem.offset();
nickjillings@1596 8934 curCSSTop = jQuery.css( elem, "top" );
nickjillings@1596 8935 curCSSLeft = jQuery.css( elem, "left" );
nickjillings@1596 8936 calculatePosition = ( position === "absolute" || position === "fixed" ) &&
nickjillings@1596 8937 ( curCSSTop + curCSSLeft ).indexOf("auto") > -1;
nickjillings@1596 8938
nickjillings@1596 8939 // Need to be able to calculate position if either
nickjillings@1596 8940 // top or left is auto and position is either absolute or fixed
nickjillings@1596 8941 if ( calculatePosition ) {
nickjillings@1596 8942 curPosition = curElem.position();
nickjillings@1596 8943 curTop = curPosition.top;
nickjillings@1596 8944 curLeft = curPosition.left;
nickjillings@1596 8945
nickjillings@1596 8946 } else {
nickjillings@1596 8947 curTop = parseFloat( curCSSTop ) || 0;
nickjillings@1596 8948 curLeft = parseFloat( curCSSLeft ) || 0;
nickjillings@1596 8949 }
nickjillings@1596 8950
nickjillings@1596 8951 if ( jQuery.isFunction( options ) ) {
nickjillings@1596 8952 options = options.call( elem, i, curOffset );
nickjillings@1596 8953 }
nickjillings@1596 8954
nickjillings@1596 8955 if ( options.top != null ) {
nickjillings@1596 8956 props.top = ( options.top - curOffset.top ) + curTop;
nickjillings@1596 8957 }
nickjillings@1596 8958 if ( options.left != null ) {
nickjillings@1596 8959 props.left = ( options.left - curOffset.left ) + curLeft;
nickjillings@1596 8960 }
nickjillings@1596 8961
nickjillings@1596 8962 if ( "using" in options ) {
nickjillings@1596 8963 options.using.call( elem, props );
nickjillings@1596 8964
nickjillings@1596 8965 } else {
nickjillings@1596 8966 curElem.css( props );
nickjillings@1596 8967 }
nickjillings@1596 8968 }
nickjillings@1596 8969 };
nickjillings@1596 8970
nickjillings@1596 8971 jQuery.fn.extend({
nickjillings@1596 8972 offset: function( options ) {
nickjillings@1596 8973 if ( arguments.length ) {
nickjillings@1596 8974 return options === undefined ?
nickjillings@1596 8975 this :
nickjillings@1596 8976 this.each(function( i ) {
nickjillings@1596 8977 jQuery.offset.setOffset( this, options, i );
nickjillings@1596 8978 });
nickjillings@1596 8979 }
nickjillings@1596 8980
nickjillings@1596 8981 var docElem, win,
nickjillings@1596 8982 elem = this[ 0 ],
nickjillings@1596 8983 box = { top: 0, left: 0 },
nickjillings@1596 8984 doc = elem && elem.ownerDocument;
nickjillings@1596 8985
nickjillings@1596 8986 if ( !doc ) {
nickjillings@1596 8987 return;
nickjillings@1596 8988 }
nickjillings@1596 8989
nickjillings@1596 8990 docElem = doc.documentElement;
nickjillings@1596 8991
nickjillings@1596 8992 // Make sure it's not a disconnected DOM node
nickjillings@1596 8993 if ( !jQuery.contains( docElem, elem ) ) {
nickjillings@1596 8994 return box;
nickjillings@1596 8995 }
nickjillings@1596 8996
nickjillings@1596 8997 // Support: BlackBerry 5, iOS 3 (original iPhone)
nickjillings@1596 8998 // If we don't have gBCR, just use 0,0 rather than error
nickjillings@1596 8999 if ( typeof elem.getBoundingClientRect !== strundefined ) {
nickjillings@1596 9000 box = elem.getBoundingClientRect();
nickjillings@1596 9001 }
nickjillings@1596 9002 win = getWindow( doc );
nickjillings@1596 9003 return {
nickjillings@1596 9004 top: box.top + win.pageYOffset - docElem.clientTop,
nickjillings@1596 9005 left: box.left + win.pageXOffset - docElem.clientLeft
nickjillings@1596 9006 };
nickjillings@1596 9007 },
nickjillings@1596 9008
nickjillings@1596 9009 position: function() {
nickjillings@1596 9010 if ( !this[ 0 ] ) {
nickjillings@1596 9011 return;
nickjillings@1596 9012 }
nickjillings@1596 9013
nickjillings@1596 9014 var offsetParent, offset,
nickjillings@1596 9015 elem = this[ 0 ],
nickjillings@1596 9016 parentOffset = { top: 0, left: 0 };
nickjillings@1596 9017
nickjillings@1596 9018 // Fixed elements are offset from window (parentOffset = {top:0, left: 0}, because it is its only offset parent
nickjillings@1596 9019 if ( jQuery.css( elem, "position" ) === "fixed" ) {
nickjillings@1596 9020 // Assume getBoundingClientRect is there when computed position is fixed
nickjillings@1596 9021 offset = elem.getBoundingClientRect();
nickjillings@1596 9022
nickjillings@1596 9023 } else {
nickjillings@1596 9024 // Get *real* offsetParent
nickjillings@1596 9025 offsetParent = this.offsetParent();
nickjillings@1596 9026
nickjillings@1596 9027 // Get correct offsets
nickjillings@1596 9028 offset = this.offset();
nickjillings@1596 9029 if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
nickjillings@1596 9030 parentOffset = offsetParent.offset();
nickjillings@1596 9031 }
nickjillings@1596 9032
nickjillings@1596 9033 // Add offsetParent borders
nickjillings@1596 9034 parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
nickjillings@1596 9035 parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
nickjillings@1596 9036 }
nickjillings@1596 9037
nickjillings@1596 9038 // Subtract parent offsets and element margins
nickjillings@1596 9039 return {
nickjillings@1596 9040 top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
nickjillings@1596 9041 left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
nickjillings@1596 9042 };
nickjillings@1596 9043 },
nickjillings@1596 9044
nickjillings@1596 9045 offsetParent: function() {
nickjillings@1596 9046 return this.map(function() {
nickjillings@1596 9047 var offsetParent = this.offsetParent || docElem;
nickjillings@1596 9048
nickjillings@1596 9049 while ( offsetParent && ( !jQuery.nodeName( offsetParent, "html" ) && jQuery.css( offsetParent, "position" ) === "static" ) ) {
nickjillings@1596 9050 offsetParent = offsetParent.offsetParent;
nickjillings@1596 9051 }
nickjillings@1596 9052
nickjillings@1596 9053 return offsetParent || docElem;
nickjillings@1596 9054 });
nickjillings@1596 9055 }
nickjillings@1596 9056 });
nickjillings@1596 9057
nickjillings@1596 9058 // Create scrollLeft and scrollTop methods
nickjillings@1596 9059 jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
nickjillings@1596 9060 var top = "pageYOffset" === prop;
nickjillings@1596 9061
nickjillings@1596 9062 jQuery.fn[ method ] = function( val ) {
nickjillings@1596 9063 return access( this, function( elem, method, val ) {
nickjillings@1596 9064 var win = getWindow( elem );
nickjillings@1596 9065
nickjillings@1596 9066 if ( val === undefined ) {
nickjillings@1596 9067 return win ? win[ prop ] : elem[ method ];
nickjillings@1596 9068 }
nickjillings@1596 9069
nickjillings@1596 9070 if ( win ) {
nickjillings@1596 9071 win.scrollTo(
nickjillings@1596 9072 !top ? val : window.pageXOffset,
nickjillings@1596 9073 top ? val : window.pageYOffset
nickjillings@1596 9074 );
nickjillings@1596 9075
nickjillings@1596 9076 } else {
nickjillings@1596 9077 elem[ method ] = val;
nickjillings@1596 9078 }
nickjillings@1596 9079 }, method, val, arguments.length, null );
nickjillings@1596 9080 };
nickjillings@1596 9081 });
nickjillings@1596 9082
nickjillings@1596 9083 // Support: Safari<7+, Chrome<37+
nickjillings@1596 9084 // Add the top/left cssHooks using jQuery.fn.position
nickjillings@1596 9085 // Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
nickjillings@1596 9086 // Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
nickjillings@1596 9087 // getComputedStyle returns percent when specified for top/left/bottom/right;
nickjillings@1596 9088 // rather than make the css module depend on the offset module, just check for it here
nickjillings@1596 9089 jQuery.each( [ "top", "left" ], function( i, prop ) {
nickjillings@1596 9090 jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
nickjillings@1596 9091 function( elem, computed ) {
nickjillings@1596 9092 if ( computed ) {
nickjillings@1596 9093 computed = curCSS( elem, prop );
nickjillings@1596 9094 // If curCSS returns percentage, fallback to offset
nickjillings@1596 9095 return rnumnonpx.test( computed ) ?
nickjillings@1596 9096 jQuery( elem ).position()[ prop ] + "px" :
nickjillings@1596 9097 computed;
nickjillings@1596 9098 }
nickjillings@1596 9099 }
nickjillings@1596 9100 );
nickjillings@1596 9101 });
nickjillings@1596 9102
nickjillings@1596 9103
nickjillings@1596 9104 // Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
nickjillings@1596 9105 jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
nickjillings@1596 9106 jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name }, function( defaultExtra, funcName ) {
nickjillings@1596 9107 // Margin is only for outerHeight, outerWidth
nickjillings@1596 9108 jQuery.fn[ funcName ] = function( margin, value ) {
nickjillings@1596 9109 var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
nickjillings@1596 9110 extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
nickjillings@1596 9111
nickjillings@1596 9112 return access( this, function( elem, type, value ) {
nickjillings@1596 9113 var doc;
nickjillings@1596 9114
nickjillings@1596 9115 if ( jQuery.isWindow( elem ) ) {
nickjillings@1596 9116 // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
nickjillings@1596 9117 // isn't a whole lot we can do. See pull request at this URL for discussion:
nickjillings@1596 9118 // https://github.com/jquery/jquery/pull/764
nickjillings@1596 9119 return elem.document.documentElement[ "client" + name ];
nickjillings@1596 9120 }
nickjillings@1596 9121
nickjillings@1596 9122 // Get document width or height
nickjillings@1596 9123 if ( elem.nodeType === 9 ) {
nickjillings@1596 9124 doc = elem.documentElement;
nickjillings@1596 9125
nickjillings@1596 9126 // Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
nickjillings@1596 9127 // whichever is greatest
nickjillings@1596 9128 return Math.max(
nickjillings@1596 9129 elem.body[ "scroll" + name ], doc[ "scroll" + name ],
nickjillings@1596 9130 elem.body[ "offset" + name ], doc[ "offset" + name ],
nickjillings@1596 9131 doc[ "client" + name ]
nickjillings@1596 9132 );
nickjillings@1596 9133 }
nickjillings@1596 9134
nickjillings@1596 9135 return value === undefined ?
nickjillings@1596 9136 // Get width or height on the element, requesting but not forcing parseFloat
nickjillings@1596 9137 jQuery.css( elem, type, extra ) :
nickjillings@1596 9138
nickjillings@1596 9139 // Set width or height on the element
nickjillings@1596 9140 jQuery.style( elem, type, value, extra );
nickjillings@1596 9141 }, type, chainable ? margin : undefined, chainable, null );
nickjillings@1596 9142 };
nickjillings@1596 9143 });
nickjillings@1596 9144 });
nickjillings@1596 9145
nickjillings@1596 9146
nickjillings@1596 9147 // The number of elements contained in the matched element set
nickjillings@1596 9148 jQuery.fn.size = function() {
nickjillings@1596 9149 return this.length;
nickjillings@1596 9150 };
nickjillings@1596 9151
nickjillings@1596 9152 jQuery.fn.andSelf = jQuery.fn.addBack;
nickjillings@1596 9153
nickjillings@1596 9154
nickjillings@1596 9155
nickjillings@1596 9156
nickjillings@1596 9157 // Register as a named AMD module, since jQuery can be concatenated with other
nickjillings@1596 9158 // files that may use define, but not via a proper concatenation script that
nickjillings@1596 9159 // understands anonymous AMD modules. A named AMD is safest and most robust
nickjillings@1596 9160 // way to register. Lowercase jquery is used because AMD module names are
nickjillings@1596 9161 // derived from file names, and jQuery is normally delivered in a lowercase
nickjillings@1596 9162 // file name. Do this after creating the global so that if an AMD module wants
nickjillings@1596 9163 // to call noConflict to hide this version of jQuery, it will work.
nickjillings@1596 9164
nickjillings@1596 9165 // Note that for maximum portability, libraries that are not jQuery should
nickjillings@1596 9166 // declare themselves as anonymous modules, and avoid setting a global if an
nickjillings@1596 9167 // AMD loader is present. jQuery is a special case. For more information, see
nickjillings@1596 9168 // https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
nickjillings@1596 9169
nickjillings@1596 9170 if ( typeof define === "function" && define.amd ) {
nickjillings@1596 9171 define( "jquery", [], function() {
nickjillings@1596 9172 return jQuery;
nickjillings@1596 9173 });
nickjillings@1596 9174 }
nickjillings@1596 9175
nickjillings@1596 9176
nickjillings@1596 9177
nickjillings@1596 9178
nickjillings@1596 9179 var
nickjillings@1596 9180 // Map over jQuery in case of overwrite
nickjillings@1596 9181 _jQuery = window.jQuery,
nickjillings@1596 9182
nickjillings@1596 9183 // Map over the $ in case of overwrite
nickjillings@1596 9184 _$ = window.$;
nickjillings@1596 9185
nickjillings@1596 9186 jQuery.noConflict = function( deep ) {
nickjillings@1596 9187 if ( window.$ === jQuery ) {
nickjillings@1596 9188 window.$ = _$;
nickjillings@1596 9189 }
nickjillings@1596 9190
nickjillings@1596 9191 if ( deep && window.jQuery === jQuery ) {
nickjillings@1596 9192 window.jQuery = _jQuery;
nickjillings@1596 9193 }
nickjillings@1596 9194
nickjillings@1596 9195 return jQuery;
nickjillings@1596 9196 };
nickjillings@1596 9197
nickjillings@1596 9198 // Expose jQuery and $ identifiers, even in AMD
nickjillings@1596 9199 // (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
nickjillings@1596 9200 // and CommonJS for browser emulators (#13566)
nickjillings@1596 9201 if ( typeof noGlobal === strundefined ) {
nickjillings@1596 9202 window.jQuery = window.$ = jQuery;
nickjillings@1596 9203 }
nickjillings@1596 9204
nickjillings@1596 9205
nickjillings@1596 9206
nickjillings@1596 9207
nickjillings@1596 9208 return jQuery;
nickjillings@1596 9209
nickjillings@1596 9210 }));