nickjillings@1289: /*!
nickjillings@1289: * jQuery JavaScript Library v2.1.4
nickjillings@1289: * http://jquery.com/
nickjillings@1289: *
nickjillings@1289: * Includes Sizzle.js
nickjillings@1289: * http://sizzlejs.com/
nickjillings@1289: *
nickjillings@1289: * Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1289: * Released under the MIT license
nickjillings@1289: * http://jquery.org/license
nickjillings@1289: *
nickjillings@1289: * Date: 2015-04-28T16:01Z
nickjillings@1289: */
nickjillings@1289:
nickjillings@1289: (function( global, factory ) {
nickjillings@1289:
nickjillings@1289: if ( typeof module === "object" && typeof module.exports === "object" ) {
nickjillings@1289: // For CommonJS and CommonJS-like environments where a proper `window`
nickjillings@1289: // is present, execute the factory and get jQuery.
nickjillings@1289: // For environments that do not have a `window` with a `document`
nickjillings@1289: // (such as Node.js), expose a factory as module.exports.
nickjillings@1289: // This accentuates the need for the creation of a real `window`.
nickjillings@1289: // e.g. var jQuery = require("jquery")(window);
nickjillings@1289: // See ticket #14549 for more info.
nickjillings@1289: module.exports = global.document ?
nickjillings@1289: factory( global, true ) :
nickjillings@1289: function( w ) {
nickjillings@1289: if ( !w.document ) {
nickjillings@1289: throw new Error( "jQuery requires a window with a document" );
nickjillings@1289: }
nickjillings@1289: return factory( w );
nickjillings@1289: };
nickjillings@1289: } else {
nickjillings@1289: factory( global );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Pass this if window is not defined yet
nickjillings@1289: }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
nickjillings@1289:
nickjillings@1289: // Support: Firefox 18+
nickjillings@1289: // Can't be in strict mode, several libs including ASP.NET trace
nickjillings@1289: // the stack via arguments.caller.callee and Firefox dies if
nickjillings@1289: // you try to trace through "use strict" call chains. (#13335)
nickjillings@1289: //
nickjillings@1289:
nickjillings@1289: var arr = [];
nickjillings@1289:
nickjillings@1289: var slice = arr.slice;
nickjillings@1289:
nickjillings@1289: var concat = arr.concat;
nickjillings@1289:
nickjillings@1289: var push = arr.push;
nickjillings@1289:
nickjillings@1289: var indexOf = arr.indexOf;
nickjillings@1289:
nickjillings@1289: var class2type = {};
nickjillings@1289:
nickjillings@1289: var toString = class2type.toString;
nickjillings@1289:
nickjillings@1289: var hasOwn = class2type.hasOwnProperty;
nickjillings@1289:
nickjillings@1289: var support = {};
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: var
nickjillings@1289: // Use the correct document accordingly with window argument (sandbox)
nickjillings@1289: document = window.document,
nickjillings@1289:
nickjillings@1289: version = "2.1.4",
nickjillings@1289:
nickjillings@1289: // Define a local copy of jQuery
nickjillings@1289: jQuery = function( selector, context ) {
nickjillings@1289: // The jQuery object is actually just the init constructor 'enhanced'
nickjillings@1289: // Need init if jQuery is called (just allow error to be thrown if not included)
nickjillings@1289: return new jQuery.fn.init( selector, context );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Support: Android<4.1
nickjillings@1289: // Make sure we trim BOM and NBSP
nickjillings@1289: rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
nickjillings@1289:
nickjillings@1289: // Matches dashed string for camelizing
nickjillings@1289: rmsPrefix = /^-ms-/,
nickjillings@1289: rdashAlpha = /-([\da-z])/gi,
nickjillings@1289:
nickjillings@1289: // Used by jQuery.camelCase as callback to replace()
nickjillings@1289: fcamelCase = function( all, letter ) {
nickjillings@1289: return letter.toUpperCase();
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: jQuery.fn = jQuery.prototype = {
nickjillings@1289: // The current version of jQuery being used
nickjillings@1289: jquery: version,
nickjillings@1289:
nickjillings@1289: constructor: jQuery,
nickjillings@1289:
nickjillings@1289: // Start with an empty selector
nickjillings@1289: selector: "",
nickjillings@1289:
nickjillings@1289: // The default length of a jQuery object is 0
nickjillings@1289: length: 0,
nickjillings@1289:
nickjillings@1289: toArray: function() {
nickjillings@1289: return slice.call( this );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Get the Nth element in the matched element set OR
nickjillings@1289: // Get the whole matched element set as a clean array
nickjillings@1289: get: function( num ) {
nickjillings@1289: return num != null ?
nickjillings@1289:
nickjillings@1289: // Return just the one element from the set
nickjillings@1289: ( num < 0 ? this[ num + this.length ] : this[ num ] ) :
nickjillings@1289:
nickjillings@1289: // Return all the elements in a clean array
nickjillings@1289: slice.call( this );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Take an array of elements and push it onto the stack
nickjillings@1289: // (returning the new matched element set)
nickjillings@1289: pushStack: function( elems ) {
nickjillings@1289:
nickjillings@1289: // Build a new jQuery matched element set
nickjillings@1289: var ret = jQuery.merge( this.constructor(), elems );
nickjillings@1289:
nickjillings@1289: // Add the old object onto the stack (as a reference)
nickjillings@1289: ret.prevObject = this;
nickjillings@1289: ret.context = this.context;
nickjillings@1289:
nickjillings@1289: // Return the newly-formed element set
nickjillings@1289: return ret;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Execute a callback for every element in the matched set.
nickjillings@1289: // (You can seed the arguments with an array of args, but this is
nickjillings@1289: // only used internally.)
nickjillings@1289: each: function( callback, args ) {
nickjillings@1289: return jQuery.each( this, callback, args );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: map: function( callback ) {
nickjillings@1289: return this.pushStack( jQuery.map(this, function( elem, i ) {
nickjillings@1289: return callback.call( elem, i, elem );
nickjillings@1289: }));
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: slice: function() {
nickjillings@1289: return this.pushStack( slice.apply( this, arguments ) );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: first: function() {
nickjillings@1289: return this.eq( 0 );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: last: function() {
nickjillings@1289: return this.eq( -1 );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: eq: function( i ) {
nickjillings@1289: var len = this.length,
nickjillings@1289: j = +i + ( i < 0 ? len : 0 );
nickjillings@1289: return this.pushStack( j >= 0 && j < len ? [ this[j] ] : [] );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: end: function() {
nickjillings@1289: return this.prevObject || this.constructor(null);
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // For internal use only.
nickjillings@1289: // Behaves like an Array's method, not like a jQuery method.
nickjillings@1289: push: push,
nickjillings@1289: sort: arr.sort,
nickjillings@1289: splice: arr.splice
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: jQuery.extend = jQuery.fn.extend = function() {
nickjillings@1289: var options, name, src, copy, copyIsArray, clone,
nickjillings@1289: target = arguments[0] || {},
nickjillings@1289: i = 1,
nickjillings@1289: length = arguments.length,
nickjillings@1289: deep = false;
nickjillings@1289:
nickjillings@1289: // Handle a deep copy situation
nickjillings@1289: if ( typeof target === "boolean" ) {
nickjillings@1289: deep = target;
nickjillings@1289:
nickjillings@1289: // Skip the boolean and the target
nickjillings@1289: target = arguments[ i ] || {};
nickjillings@1289: i++;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Handle case when target is a string or something (possible in deep copy)
nickjillings@1289: if ( typeof target !== "object" && !jQuery.isFunction(target) ) {
nickjillings@1289: target = {};
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Extend jQuery itself if only one argument is passed
nickjillings@1289: if ( i === length ) {
nickjillings@1289: target = this;
nickjillings@1289: i--;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: for ( ; i < length; i++ ) {
nickjillings@1289: // Only deal with non-null/undefined values
nickjillings@1289: if ( (options = arguments[ i ]) != null ) {
nickjillings@1289: // Extend the base object
nickjillings@1289: for ( name in options ) {
nickjillings@1289: src = target[ name ];
nickjillings@1289: copy = options[ name ];
nickjillings@1289:
nickjillings@1289: // Prevent never-ending loop
nickjillings@1289: if ( target === copy ) {
nickjillings@1289: continue;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Recurse if we're merging plain objects or arrays
nickjillings@1289: if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) {
nickjillings@1289: if ( copyIsArray ) {
nickjillings@1289: copyIsArray = false;
nickjillings@1289: clone = src && jQuery.isArray(src) ? src : [];
nickjillings@1289:
nickjillings@1289: } else {
nickjillings@1289: clone = src && jQuery.isPlainObject(src) ? src : {};
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Never move original objects, clone them
nickjillings@1289: target[ name ] = jQuery.extend( deep, clone, copy );
nickjillings@1289:
nickjillings@1289: // Don't bring in undefined values
nickjillings@1289: } else if ( copy !== undefined ) {
nickjillings@1289: target[ name ] = copy;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Return the modified object
nickjillings@1289: return target;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: jQuery.extend({
nickjillings@1289: // Unique for each copy of jQuery on the page
nickjillings@1289: expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
nickjillings@1289:
nickjillings@1289: // Assume jQuery is ready without the ready module
nickjillings@1289: isReady: true,
nickjillings@1289:
nickjillings@1289: error: function( msg ) {
nickjillings@1289: throw new Error( msg );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: noop: function() {},
nickjillings@1289:
nickjillings@1289: isFunction: function( obj ) {
nickjillings@1289: return jQuery.type(obj) === "function";
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: isArray: Array.isArray,
nickjillings@1289:
nickjillings@1289: isWindow: function( obj ) {
nickjillings@1289: return obj != null && obj === obj.window;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: isNumeric: function( obj ) {
nickjillings@1289: // parseFloat NaNs numeric-cast false positives (null|true|false|"")
nickjillings@1289: // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
nickjillings@1289: // subtraction forces infinities to NaN
nickjillings@1289: // adding 1 corrects loss of precision from parseFloat (#15100)
nickjillings@1289: return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: isPlainObject: function( obj ) {
nickjillings@1289: // Not plain objects:
nickjillings@1289: // - Any object or value whose internal [[Class]] property is not "[object Object]"
nickjillings@1289: // - DOM nodes
nickjillings@1289: // - window
nickjillings@1289: if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( obj.constructor &&
nickjillings@1289: !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // If the function hasn't returned already, we're confident that
nickjillings@1289: // |obj| is a plain object, created by {} or constructed with new Object
nickjillings@1289: return true;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: isEmptyObject: function( obj ) {
nickjillings@1289: var name;
nickjillings@1289: for ( name in obj ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289: return true;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: type: function( obj ) {
nickjillings@1289: if ( obj == null ) {
nickjillings@1289: return obj + "";
nickjillings@1289: }
nickjillings@1289: // Support: Android<4.0, iOS<6 (functionish RegExp)
nickjillings@1289: return typeof obj === "object" || typeof obj === "function" ?
nickjillings@1289: class2type[ toString.call(obj) ] || "object" :
nickjillings@1289: typeof obj;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Evaluates a script in a global context
nickjillings@1289: globalEval: function( code ) {
nickjillings@1289: var script,
nickjillings@1289: indirect = eval;
nickjillings@1289:
nickjillings@1289: code = jQuery.trim( code );
nickjillings@1289:
nickjillings@1289: if ( code ) {
nickjillings@1289: // If the code includes a valid, prologue position
nickjillings@1289: // strict mode pragma, execute code by injecting a
nickjillings@1289: // script tag into the document.
nickjillings@1289: if ( code.indexOf("use strict") === 1 ) {
nickjillings@1289: script = document.createElement("script");
nickjillings@1289: script.text = code;
nickjillings@1289: document.head.appendChild( script ).parentNode.removeChild( script );
nickjillings@1289: } else {
nickjillings@1289: // Otherwise, avoid the DOM node creation, insertion
nickjillings@1289: // and removal by using an indirect global eval
nickjillings@1289: indirect( code );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Convert dashed to camelCase; used by the css and data modules
nickjillings@1289: // Support: IE9-11+
nickjillings@1289: // Microsoft forgot to hump their vendor prefix (#9572)
nickjillings@1289: camelCase: function( string ) {
nickjillings@1289: return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: nodeName: function( elem, name ) {
nickjillings@1289: return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // args is for internal usage only
nickjillings@1289: each: function( obj, callback, args ) {
nickjillings@1289: var value,
nickjillings@1289: i = 0,
nickjillings@1289: length = obj.length,
nickjillings@1289: isArray = isArraylike( obj );
nickjillings@1289:
nickjillings@1289: if ( args ) {
nickjillings@1289: if ( isArray ) {
nickjillings@1289: for ( ; i < length; i++ ) {
nickjillings@1289: value = callback.apply( obj[ i ], args );
nickjillings@1289:
nickjillings@1289: if ( value === false ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: } else {
nickjillings@1289: for ( i in obj ) {
nickjillings@1289: value = callback.apply( obj[ i ], args );
nickjillings@1289:
nickjillings@1289: if ( value === false ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // A special, fast, case for the most common use of each
nickjillings@1289: } else {
nickjillings@1289: if ( isArray ) {
nickjillings@1289: for ( ; i < length; i++ ) {
nickjillings@1289: value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1289:
nickjillings@1289: if ( value === false ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: } else {
nickjillings@1289: for ( i in obj ) {
nickjillings@1289: value = callback.call( obj[ i ], i, obj[ i ] );
nickjillings@1289:
nickjillings@1289: if ( value === false ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return obj;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Support: Android<4.1
nickjillings@1289: trim: function( text ) {
nickjillings@1289: return text == null ?
nickjillings@1289: "" :
nickjillings@1289: ( text + "" ).replace( rtrim, "" );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // results is for internal usage only
nickjillings@1289: makeArray: function( arr, results ) {
nickjillings@1289: var ret = results || [];
nickjillings@1289:
nickjillings@1289: if ( arr != null ) {
nickjillings@1289: if ( isArraylike( Object(arr) ) ) {
nickjillings@1289: jQuery.merge( ret,
nickjillings@1289: typeof arr === "string" ?
nickjillings@1289: [ arr ] : arr
nickjillings@1289: );
nickjillings@1289: } else {
nickjillings@1289: push.call( ret, arr );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return ret;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: inArray: function( elem, arr, i ) {
nickjillings@1289: return arr == null ? -1 : indexOf.call( arr, elem, i );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: merge: function( first, second ) {
nickjillings@1289: var len = +second.length,
nickjillings@1289: j = 0,
nickjillings@1289: i = first.length;
nickjillings@1289:
nickjillings@1289: for ( ; j < len; j++ ) {
nickjillings@1289: first[ i++ ] = second[ j ];
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: first.length = i;
nickjillings@1289:
nickjillings@1289: return first;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: grep: function( elems, callback, invert ) {
nickjillings@1289: var callbackInverse,
nickjillings@1289: matches = [],
nickjillings@1289: i = 0,
nickjillings@1289: length = elems.length,
nickjillings@1289: callbackExpect = !invert;
nickjillings@1289:
nickjillings@1289: // Go through the array, only saving the items
nickjillings@1289: // that pass the validator function
nickjillings@1289: for ( ; i < length; i++ ) {
nickjillings@1289: callbackInverse = !callback( elems[ i ], i );
nickjillings@1289: if ( callbackInverse !== callbackExpect ) {
nickjillings@1289: matches.push( elems[ i ] );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return matches;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // arg is for internal usage only
nickjillings@1289: map: function( elems, callback, arg ) {
nickjillings@1289: var value,
nickjillings@1289: i = 0,
nickjillings@1289: length = elems.length,
nickjillings@1289: isArray = isArraylike( elems ),
nickjillings@1289: ret = [];
nickjillings@1289:
nickjillings@1289: // Go through the array, translating each of the items to their new values
nickjillings@1289: if ( isArray ) {
nickjillings@1289: for ( ; i < length; i++ ) {
nickjillings@1289: value = callback( elems[ i ], i, arg );
nickjillings@1289:
nickjillings@1289: if ( value != null ) {
nickjillings@1289: ret.push( value );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Go through every key on the object,
nickjillings@1289: } else {
nickjillings@1289: for ( i in elems ) {
nickjillings@1289: value = callback( elems[ i ], i, arg );
nickjillings@1289:
nickjillings@1289: if ( value != null ) {
nickjillings@1289: ret.push( value );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Flatten any nested arrays
nickjillings@1289: return concat.apply( [], ret );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // A global GUID counter for objects
nickjillings@1289: guid: 1,
nickjillings@1289:
nickjillings@1289: // Bind a function to a context, optionally partially applying any
nickjillings@1289: // arguments.
nickjillings@1289: proxy: function( fn, context ) {
nickjillings@1289: var tmp, args, proxy;
nickjillings@1289:
nickjillings@1289: if ( typeof context === "string" ) {
nickjillings@1289: tmp = fn[ context ];
nickjillings@1289: context = fn;
nickjillings@1289: fn = tmp;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Quick check to determine if target is callable, in the spec
nickjillings@1289: // this throws a TypeError, but we will just return undefined.
nickjillings@1289: if ( !jQuery.isFunction( fn ) ) {
nickjillings@1289: return undefined;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Simulated bind
nickjillings@1289: args = slice.call( arguments, 2 );
nickjillings@1289: proxy = function() {
nickjillings@1289: return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // Set the guid of unique handler to the same of original handler, so it can be removed
nickjillings@1289: proxy.guid = fn.guid = fn.guid || jQuery.guid++;
nickjillings@1289:
nickjillings@1289: return proxy;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: now: Date.now,
nickjillings@1289:
nickjillings@1289: // jQuery.support is not used in Core but other projects attach their
nickjillings@1289: // properties to it so it needs to exist.
nickjillings@1289: support: support
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: // Populate the class2type map
nickjillings@1289: jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
nickjillings@1289: class2type[ "[object " + name + "]" ] = name.toLowerCase();
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: function isArraylike( obj ) {
nickjillings@1289:
nickjillings@1289: // Support: iOS 8.2 (not reproducible in simulator)
nickjillings@1289: // `in` check used to prevent JIT error (gh-2145)
nickjillings@1289: // hasOwn isn't used here due to false negatives
nickjillings@1289: // regarding Nodelist length in IE
nickjillings@1289: var length = "length" in obj && obj.length,
nickjillings@1289: type = jQuery.type( obj );
nickjillings@1289:
nickjillings@1289: if ( type === "function" || jQuery.isWindow( obj ) ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( obj.nodeType === 1 && length ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return type === "array" || length === 0 ||
nickjillings@1289: typeof length === "number" && length > 0 && ( length - 1 ) in obj;
nickjillings@1289: }
nickjillings@1289: var Sizzle =
nickjillings@1289: /*!
nickjillings@1289: * Sizzle CSS Selector Engine v2.2.0-pre
nickjillings@1289: * http://sizzlejs.com/
nickjillings@1289: *
nickjillings@1289: * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors
nickjillings@1289: * Released under the MIT license
nickjillings@1289: * http://jquery.org/license
nickjillings@1289: *
nickjillings@1289: * Date: 2014-12-16
nickjillings@1289: */
nickjillings@1289: (function( window ) {
nickjillings@1289:
nickjillings@1289: var i,
nickjillings@1289: support,
nickjillings@1289: Expr,
nickjillings@1289: getText,
nickjillings@1289: isXML,
nickjillings@1289: tokenize,
nickjillings@1289: compile,
nickjillings@1289: select,
nickjillings@1289: outermostContext,
nickjillings@1289: sortInput,
nickjillings@1289: hasDuplicate,
nickjillings@1289:
nickjillings@1289: // Local document vars
nickjillings@1289: setDocument,
nickjillings@1289: document,
nickjillings@1289: docElem,
nickjillings@1289: documentIsHTML,
nickjillings@1289: rbuggyQSA,
nickjillings@1289: rbuggyMatches,
nickjillings@1289: matches,
nickjillings@1289: contains,
nickjillings@1289:
nickjillings@1289: // Instance-specific data
nickjillings@1289: expando = "sizzle" + 1 * new Date(),
nickjillings@1289: preferredDoc = window.document,
nickjillings@1289: dirruns = 0,
nickjillings@1289: done = 0,
nickjillings@1289: classCache = createCache(),
nickjillings@1289: tokenCache = createCache(),
nickjillings@1289: compilerCache = createCache(),
nickjillings@1289: sortOrder = function( a, b ) {
nickjillings@1289: if ( a === b ) {
nickjillings@1289: hasDuplicate = true;
nickjillings@1289: }
nickjillings@1289: return 0;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // General-purpose constants
nickjillings@1289: MAX_NEGATIVE = 1 << 31,
nickjillings@1289:
nickjillings@1289: // Instance methods
nickjillings@1289: hasOwn = ({}).hasOwnProperty,
nickjillings@1289: arr = [],
nickjillings@1289: pop = arr.pop,
nickjillings@1289: push_native = arr.push,
nickjillings@1289: push = arr.push,
nickjillings@1289: slice = arr.slice,
nickjillings@1289: // Use a stripped-down indexOf as it's faster than native
nickjillings@1289: // http://jsperf.com/thor-indexof-vs-for/5
nickjillings@1289: indexOf = function( list, elem ) {
nickjillings@1289: var i = 0,
nickjillings@1289: len = list.length;
nickjillings@1289: for ( ; i < len; i++ ) {
nickjillings@1289: if ( list[i] === elem ) {
nickjillings@1289: return i;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return -1;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
nickjillings@1289:
nickjillings@1289: // Regular expressions
nickjillings@1289:
nickjillings@1289: // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
nickjillings@1289: whitespace = "[\\x20\\t\\r\\n\\f]",
nickjillings@1289: // http://www.w3.org/TR/css3-syntax/#characters
nickjillings@1289: characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
nickjillings@1289:
nickjillings@1289: // Loosely modeled on CSS identifier characters
nickjillings@1289: // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
nickjillings@1289: // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
nickjillings@1289: identifier = characterEncoding.replace( "w", "w#" ),
nickjillings@1289:
nickjillings@1289: // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
nickjillings@1289: attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace +
nickjillings@1289: // Operator (capture 2)
nickjillings@1289: "*([*^$|!~]?=)" + whitespace +
nickjillings@1289: // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
nickjillings@1289: "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
nickjillings@1289: "*\\]",
nickjillings@1289:
nickjillings@1289: pseudos = ":(" + characterEncoding + ")(?:\\((" +
nickjillings@1289: // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
nickjillings@1289: // 1. quoted (capture 3; capture 4 or capture 5)
nickjillings@1289: "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
nickjillings@1289: // 2. simple (capture 6)
nickjillings@1289: "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
nickjillings@1289: // 3. anything else (capture 2)
nickjillings@1289: ".*" +
nickjillings@1289: ")\\)|)",
nickjillings@1289:
nickjillings@1289: // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
nickjillings@1289: rwhitespace = new RegExp( whitespace + "+", "g" ),
nickjillings@1289: rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
nickjillings@1289:
nickjillings@1289: rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
nickjillings@1289: rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
nickjillings@1289:
nickjillings@1289: rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
nickjillings@1289:
nickjillings@1289: rpseudo = new RegExp( pseudos ),
nickjillings@1289: ridentifier = new RegExp( "^" + identifier + "$" ),
nickjillings@1289:
nickjillings@1289: matchExpr = {
nickjillings@1289: "ID": new RegExp( "^#(" + characterEncoding + ")" ),
nickjillings@1289: "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
nickjillings@1289: "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
nickjillings@1289: "ATTR": new RegExp( "^" + attributes ),
nickjillings@1289: "PSEUDO": new RegExp( "^" + pseudos ),
nickjillings@1289: "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
nickjillings@1289: "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
nickjillings@1289: "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
nickjillings@1289: "bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
nickjillings@1289: // For use in libraries implementing .is()
nickjillings@1289: // We use this for POS matching in `select`
nickjillings@1289: "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
nickjillings@1289: whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: rinputs = /^(?:input|select|textarea|button)$/i,
nickjillings@1289: rheader = /^h\d$/i,
nickjillings@1289:
nickjillings@1289: rnative = /^[^{]+\{\s*\[native \w/,
nickjillings@1289:
nickjillings@1289: // Easily-parseable/retrievable ID or TAG or CLASS selectors
nickjillings@1289: rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
nickjillings@1289:
nickjillings@1289: rsibling = /[+~]/,
nickjillings@1289: rescape = /'|\\/g,
nickjillings@1289:
nickjillings@1289: // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
nickjillings@1289: runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
nickjillings@1289: funescape = function( _, escaped, escapedWhitespace ) {
nickjillings@1289: var high = "0x" + escaped - 0x10000;
nickjillings@1289: // NaN means non-codepoint
nickjillings@1289: // Support: Firefox<24
nickjillings@1289: // Workaround erroneous numeric interpretation of +"0x"
nickjillings@1289: return high !== high || escapedWhitespace ?
nickjillings@1289: escaped :
nickjillings@1289: high < 0 ?
nickjillings@1289: // BMP codepoint
nickjillings@1289: String.fromCharCode( high + 0x10000 ) :
nickjillings@1289: // Supplemental Plane codepoint (surrogate pair)
nickjillings@1289: String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Used for iframes
nickjillings@1289: // See setDocument()
nickjillings@1289: // Removing the function wrapper causes a "Permission Denied"
nickjillings@1289: // error in IE
nickjillings@1289: unloadHandler = function() {
nickjillings@1289: setDocument();
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // Optimize for push.apply( _, NodeList )
nickjillings@1289: try {
nickjillings@1289: push.apply(
nickjillings@1289: (arr = slice.call( preferredDoc.childNodes )),
nickjillings@1289: preferredDoc.childNodes
nickjillings@1289: );
nickjillings@1289: // Support: Android<4.0
nickjillings@1289: // Detect silently failing push.apply
nickjillings@1289: arr[ preferredDoc.childNodes.length ].nodeType;
nickjillings@1289: } catch ( e ) {
nickjillings@1289: push = { apply: arr.length ?
nickjillings@1289:
nickjillings@1289: // Leverage slice if possible
nickjillings@1289: function( target, els ) {
nickjillings@1289: push_native.apply( target, slice.call(els) );
nickjillings@1289: } :
nickjillings@1289:
nickjillings@1289: // Support: IE<9
nickjillings@1289: // Otherwise append directly
nickjillings@1289: function( target, els ) {
nickjillings@1289: var j = target.length,
nickjillings@1289: i = 0;
nickjillings@1289: // Can't trust NodeList.length
nickjillings@1289: while ( (target[j++] = els[i++]) ) {}
nickjillings@1289: target.length = j - 1;
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function Sizzle( selector, context, results, seed ) {
nickjillings@1289: var match, elem, m, nodeType,
nickjillings@1289: // QSA vars
nickjillings@1289: i, groups, old, nid, newContext, newSelector;
nickjillings@1289:
nickjillings@1289: if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
nickjillings@1289: setDocument( context );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: context = context || document;
nickjillings@1289: results = results || [];
nickjillings@1289: nodeType = context.nodeType;
nickjillings@1289:
nickjillings@1289: if ( typeof selector !== "string" || !selector ||
nickjillings@1289: nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
nickjillings@1289:
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( !seed && documentIsHTML ) {
nickjillings@1289:
nickjillings@1289: // Try to shortcut find operations when possible (e.g., not under DocumentFragment)
nickjillings@1289: if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
nickjillings@1289: // Speed-up: Sizzle("#ID")
nickjillings@1289: if ( (m = match[1]) ) {
nickjillings@1289: if ( nodeType === 9 ) {
nickjillings@1289: elem = context.getElementById( m );
nickjillings@1289: // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1289: // nodes that are no longer in the document (jQuery #6963)
nickjillings@1289: if ( elem && elem.parentNode ) {
nickjillings@1289: // Handle the case where IE, Opera, and Webkit return items
nickjillings@1289: // by name instead of ID
nickjillings@1289: if ( elem.id === m ) {
nickjillings@1289: results.push( elem );
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289: } else {
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289: } else {
nickjillings@1289: // Context is not a document
nickjillings@1289: if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
nickjillings@1289: contains( context, elem ) && elem.id === m ) {
nickjillings@1289: results.push( elem );
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Speed-up: Sizzle("TAG")
nickjillings@1289: } else if ( match[2] ) {
nickjillings@1289: push.apply( results, context.getElementsByTagName( selector ) );
nickjillings@1289: return results;
nickjillings@1289:
nickjillings@1289: // Speed-up: Sizzle(".CLASS")
nickjillings@1289: } else if ( (m = match[3]) && support.getElementsByClassName ) {
nickjillings@1289: push.apply( results, context.getElementsByClassName( m ) );
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // QSA path
nickjillings@1289: if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
nickjillings@1289: nid = old = expando;
nickjillings@1289: newContext = context;
nickjillings@1289: newSelector = nodeType !== 1 && selector;
nickjillings@1289:
nickjillings@1289: // qSA works strangely on Element-rooted queries
nickjillings@1289: // We can work around this by specifying an extra ID on the root
nickjillings@1289: // and working up from there (Thanks to Andrew Dupont for the technique)
nickjillings@1289: // IE 8 doesn't work on object elements
nickjillings@1289: if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
nickjillings@1289: groups = tokenize( selector );
nickjillings@1289:
nickjillings@1289: if ( (old = context.getAttribute("id")) ) {
nickjillings@1289: nid = old.replace( rescape, "\\$&" );
nickjillings@1289: } else {
nickjillings@1289: context.setAttribute( "id", nid );
nickjillings@1289: }
nickjillings@1289: nid = "[id='" + nid + "'] ";
nickjillings@1289:
nickjillings@1289: i = groups.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: groups[i] = nid + toSelector( groups[i] );
nickjillings@1289: }
nickjillings@1289: newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context;
nickjillings@1289: newSelector = groups.join(",");
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( newSelector ) {
nickjillings@1289: try {
nickjillings@1289: push.apply( results,
nickjillings@1289: newContext.querySelectorAll( newSelector )
nickjillings@1289: );
nickjillings@1289: return results;
nickjillings@1289: } catch(qsaError) {
nickjillings@1289: } finally {
nickjillings@1289: if ( !old ) {
nickjillings@1289: context.removeAttribute("id");
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // All others
nickjillings@1289: return select( selector.replace( rtrim, "$1" ), context, results, seed );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Create key-value caches of limited size
nickjillings@1289: * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
nickjillings@1289: * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
nickjillings@1289: * deleting the oldest entry
nickjillings@1289: */
nickjillings@1289: function createCache() {
nickjillings@1289: var keys = [];
nickjillings@1289:
nickjillings@1289: function cache( key, value ) {
nickjillings@1289: // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
nickjillings@1289: if ( keys.push( key + " " ) > Expr.cacheLength ) {
nickjillings@1289: // Only keep the most recent entries
nickjillings@1289: delete cache[ keys.shift() ];
nickjillings@1289: }
nickjillings@1289: return (cache[ key + " " ] = value);
nickjillings@1289: }
nickjillings@1289: return cache;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Mark a function for special use by Sizzle
nickjillings@1289: * @param {Function} fn The function to mark
nickjillings@1289: */
nickjillings@1289: function markFunction( fn ) {
nickjillings@1289: fn[ expando ] = true;
nickjillings@1289: return fn;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Support testing using an element
nickjillings@1289: * @param {Function} fn Passed the created div and expects a boolean result
nickjillings@1289: */
nickjillings@1289: function assert( fn ) {
nickjillings@1289: var div = document.createElement("div");
nickjillings@1289:
nickjillings@1289: try {
nickjillings@1289: return !!fn( div );
nickjillings@1289: } catch (e) {
nickjillings@1289: return false;
nickjillings@1289: } finally {
nickjillings@1289: // Remove from its parent by default
nickjillings@1289: if ( div.parentNode ) {
nickjillings@1289: div.parentNode.removeChild( div );
nickjillings@1289: }
nickjillings@1289: // release memory in IE
nickjillings@1289: div = null;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Adds the same handler for all of the specified attrs
nickjillings@1289: * @param {String} attrs Pipe-separated list of attributes
nickjillings@1289: * @param {Function} handler The method that will be applied
nickjillings@1289: */
nickjillings@1289: function addHandle( attrs, handler ) {
nickjillings@1289: var arr = attrs.split("|"),
nickjillings@1289: i = attrs.length;
nickjillings@1289:
nickjillings@1289: while ( i-- ) {
nickjillings@1289: Expr.attrHandle[ arr[i] ] = handler;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Checks document order of two siblings
nickjillings@1289: * @param {Element} a
nickjillings@1289: * @param {Element} b
nickjillings@1289: * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
nickjillings@1289: */
nickjillings@1289: function siblingCheck( a, b ) {
nickjillings@1289: var cur = b && a,
nickjillings@1289: diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
nickjillings@1289: ( ~b.sourceIndex || MAX_NEGATIVE ) -
nickjillings@1289: ( ~a.sourceIndex || MAX_NEGATIVE );
nickjillings@1289:
nickjillings@1289: // Use IE sourceIndex if available on both nodes
nickjillings@1289: if ( diff ) {
nickjillings@1289: return diff;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Check if b follows a
nickjillings@1289: if ( cur ) {
nickjillings@1289: while ( (cur = cur.nextSibling) ) {
nickjillings@1289: if ( cur === b ) {
nickjillings@1289: return -1;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return a ? 1 : -1;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Returns a function to use in pseudos for input types
nickjillings@1289: * @param {String} type
nickjillings@1289: */
nickjillings@1289: function createInputPseudo( type ) {
nickjillings@1289: return function( elem ) {
nickjillings@1289: var name = elem.nodeName.toLowerCase();
nickjillings@1289: return name === "input" && elem.type === type;
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Returns a function to use in pseudos for buttons
nickjillings@1289: * @param {String} type
nickjillings@1289: */
nickjillings@1289: function createButtonPseudo( type ) {
nickjillings@1289: return function( elem ) {
nickjillings@1289: var name = elem.nodeName.toLowerCase();
nickjillings@1289: return (name === "input" || name === "button") && elem.type === type;
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Returns a function to use in pseudos for positionals
nickjillings@1289: * @param {Function} fn
nickjillings@1289: */
nickjillings@1289: function createPositionalPseudo( fn ) {
nickjillings@1289: return markFunction(function( argument ) {
nickjillings@1289: argument = +argument;
nickjillings@1289: return markFunction(function( seed, matches ) {
nickjillings@1289: var j,
nickjillings@1289: matchIndexes = fn( [], seed.length, argument ),
nickjillings@1289: i = matchIndexes.length;
nickjillings@1289:
nickjillings@1289: // Match elements found at the specified indexes
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( seed[ (j = matchIndexes[i]) ] ) {
nickjillings@1289: seed[j] = !(matches[j] = seed[j]);
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Checks a node for validity as a Sizzle context
nickjillings@1289: * @param {Element|Object=} context
nickjillings@1289: * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
nickjillings@1289: */
nickjillings@1289: function testContext( context ) {
nickjillings@1289: return context && typeof context.getElementsByTagName !== "undefined" && context;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Expose support vars for convenience
nickjillings@1289: support = Sizzle.support = {};
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Detects XML nodes
nickjillings@1289: * @param {Element|Object} elem An element or a document
nickjillings@1289: * @returns {Boolean} True iff elem is a non-HTML XML node
nickjillings@1289: */
nickjillings@1289: isXML = Sizzle.isXML = function( elem ) {
nickjillings@1289: // documentElement is verified for cases where it doesn't yet exist
nickjillings@1289: // (such as loading iframes in IE - #4833)
nickjillings@1289: var documentElement = elem && (elem.ownerDocument || elem).documentElement;
nickjillings@1289: return documentElement ? documentElement.nodeName !== "HTML" : false;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Sets document-related variables once based on the current document
nickjillings@1289: * @param {Element|Object} [doc] An element or document object to use to set the document
nickjillings@1289: * @returns {Object} Returns the current document
nickjillings@1289: */
nickjillings@1289: setDocument = Sizzle.setDocument = function( node ) {
nickjillings@1289: var hasCompare, parent,
nickjillings@1289: doc = node ? node.ownerDocument || node : preferredDoc;
nickjillings@1289:
nickjillings@1289: // If no document and documentElement is available, return
nickjillings@1289: if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
nickjillings@1289: return document;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Set our document
nickjillings@1289: document = doc;
nickjillings@1289: docElem = doc.documentElement;
nickjillings@1289: parent = doc.defaultView;
nickjillings@1289:
nickjillings@1289: // Support: IE>8
nickjillings@1289: // If iframe document is assigned to "document" variable and if iframe has been reloaded,
nickjillings@1289: // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
nickjillings@1289: // IE6-8 do not support the defaultView property so parent will be undefined
nickjillings@1289: if ( parent && parent !== parent.top ) {
nickjillings@1289: // IE11 does not have attachEvent, so all must suffer
nickjillings@1289: if ( parent.addEventListener ) {
nickjillings@1289: parent.addEventListener( "unload", unloadHandler, false );
nickjillings@1289: } else if ( parent.attachEvent ) {
nickjillings@1289: parent.attachEvent( "onunload", unloadHandler );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /* Support tests
nickjillings@1289: ---------------------------------------------------------------------- */
nickjillings@1289: documentIsHTML = !isXML( doc );
nickjillings@1289:
nickjillings@1289: /* Attributes
nickjillings@1289: ---------------------------------------------------------------------- */
nickjillings@1289:
nickjillings@1289: // Support: IE<8
nickjillings@1289: // Verify that getAttribute really returns attributes and not properties
nickjillings@1289: // (excepting IE8 booleans)
nickjillings@1289: support.attributes = assert(function( div ) {
nickjillings@1289: div.className = "i";
nickjillings@1289: return !div.getAttribute("className");
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: /* getElement(s)By*
nickjillings@1289: ---------------------------------------------------------------------- */
nickjillings@1289:
nickjillings@1289: // Check if getElementsByTagName("*") returns only elements
nickjillings@1289: support.getElementsByTagName = assert(function( div ) {
nickjillings@1289: div.appendChild( doc.createComment("") );
nickjillings@1289: return !div.getElementsByTagName("*").length;
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: // Support: IE<9
nickjillings@1289: support.getElementsByClassName = rnative.test( doc.getElementsByClassName );
nickjillings@1289:
nickjillings@1289: // Support: IE<10
nickjillings@1289: // Check if getElementById returns elements by name
nickjillings@1289: // The broken getElementById methods don't pick up programatically-set names,
nickjillings@1289: // so use a roundabout getElementsByName test
nickjillings@1289: support.getById = assert(function( div ) {
nickjillings@1289: docElem.appendChild( div ).id = expando;
nickjillings@1289: return !doc.getElementsByName || !doc.getElementsByName( expando ).length;
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: // ID find and filter
nickjillings@1289: if ( support.getById ) {
nickjillings@1289: Expr.find["ID"] = function( id, context ) {
nickjillings@1289: if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
nickjillings@1289: var m = context.getElementById( id );
nickjillings@1289: // Check parentNode to catch when Blackberry 4.6 returns
nickjillings@1289: // nodes that are no longer in the document #6963
nickjillings@1289: return m && m.parentNode ? [ m ] : [];
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289: Expr.filter["ID"] = function( id ) {
nickjillings@1289: var attrId = id.replace( runescape, funescape );
nickjillings@1289: return function( elem ) {
nickjillings@1289: return elem.getAttribute("id") === attrId;
nickjillings@1289: };
nickjillings@1289: };
nickjillings@1289: } else {
nickjillings@1289: // Support: IE6/7
nickjillings@1289: // getElementById is not reliable as a find shortcut
nickjillings@1289: delete Expr.find["ID"];
nickjillings@1289:
nickjillings@1289: Expr.filter["ID"] = function( id ) {
nickjillings@1289: var attrId = id.replace( runescape, funescape );
nickjillings@1289: return function( elem ) {
nickjillings@1289: var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
nickjillings@1289: return node && node.value === attrId;
nickjillings@1289: };
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Tag
nickjillings@1289: Expr.find["TAG"] = support.getElementsByTagName ?
nickjillings@1289: function( tag, context ) {
nickjillings@1289: if ( typeof context.getElementsByTagName !== "undefined" ) {
nickjillings@1289: return context.getElementsByTagName( tag );
nickjillings@1289:
nickjillings@1289: // DocumentFragment nodes don't have gEBTN
nickjillings@1289: } else if ( support.qsa ) {
nickjillings@1289: return context.querySelectorAll( tag );
nickjillings@1289: }
nickjillings@1289: } :
nickjillings@1289:
nickjillings@1289: function( tag, context ) {
nickjillings@1289: var elem,
nickjillings@1289: tmp = [],
nickjillings@1289: i = 0,
nickjillings@1289: // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
nickjillings@1289: results = context.getElementsByTagName( tag );
nickjillings@1289:
nickjillings@1289: // Filter out possible comments
nickjillings@1289: if ( tag === "*" ) {
nickjillings@1289: while ( (elem = results[i++]) ) {
nickjillings@1289: if ( elem.nodeType === 1 ) {
nickjillings@1289: tmp.push( elem );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return tmp;
nickjillings@1289: }
nickjillings@1289: return results;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // Class
nickjillings@1289: Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
nickjillings@1289: if ( documentIsHTML ) {
nickjillings@1289: return context.getElementsByClassName( className );
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: /* QSA/matchesSelector
nickjillings@1289: ---------------------------------------------------------------------- */
nickjillings@1289:
nickjillings@1289: // QSA and matchesSelector support
nickjillings@1289:
nickjillings@1289: // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
nickjillings@1289: rbuggyMatches = [];
nickjillings@1289:
nickjillings@1289: // qSa(:focus) reports false when true (Chrome 21)
nickjillings@1289: // We allow this because of a bug in IE8/9 that throws an error
nickjillings@1289: // whenever `document.activeElement` is accessed on an iframe
nickjillings@1289: // So, we allow :focus to pass through QSA all the time to avoid the IE error
nickjillings@1289: // See http://bugs.jquery.com/ticket/13378
nickjillings@1289: rbuggyQSA = [];
nickjillings@1289:
nickjillings@1289: if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) {
nickjillings@1289: // Build QSA regex
nickjillings@1289: // Regex strategy adopted from Diego Perini
nickjillings@1289: assert(function( div ) {
nickjillings@1289: // Select is set to empty string on purpose
nickjillings@1289: // This is to test IE's treatment of not explicitly
nickjillings@1289: // setting a boolean content attribute,
nickjillings@1289: // since its presence should be enough
nickjillings@1289: // http://bugs.jquery.com/ticket/12359
nickjillings@1289: docElem.appendChild( div ).innerHTML = "" +
nickjillings@1289: "";
nickjillings@1289:
nickjillings@1289: // Support: IE8, Opera 11-12.16
nickjillings@1289: // Nothing should be selected when empty strings follow ^= or $= or *=
nickjillings@1289: // The test attribute must be unknown in Opera but "safe" for WinRT
nickjillings@1289: // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
nickjillings@1289: if ( div.querySelectorAll("[msallowcapture^='']").length ) {
nickjillings@1289: rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Support: IE8
nickjillings@1289: // Boolean attributes and "value" are not treated correctly
nickjillings@1289: if ( !div.querySelectorAll("[selected]").length ) {
nickjillings@1289: rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+
nickjillings@1289: if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
nickjillings@1289: rbuggyQSA.push("~=");
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Webkit/Opera - :checked should return selected option elements
nickjillings@1289: // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1289: // IE8 throws error here and will not see later tests
nickjillings@1289: if ( !div.querySelectorAll(":checked").length ) {
nickjillings@1289: rbuggyQSA.push(":checked");
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Support: Safari 8+, iOS 8+
nickjillings@1289: // https://bugs.webkit.org/show_bug.cgi?id=136851
nickjillings@1289: // In-page `selector#id sibing-combinator selector` fails
nickjillings@1289: if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
nickjillings@1289: rbuggyQSA.push(".#.+[+~]");
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: assert(function( div ) {
nickjillings@1289: // Support: Windows 8 Native Apps
nickjillings@1289: // The type and name attributes are restricted during .innerHTML assignment
nickjillings@1289: var input = doc.createElement("input");
nickjillings@1289: input.setAttribute( "type", "hidden" );
nickjillings@1289: div.appendChild( input ).setAttribute( "name", "D" );
nickjillings@1289:
nickjillings@1289: // Support: IE8
nickjillings@1289: // Enforce case-sensitivity of name attribute
nickjillings@1289: if ( div.querySelectorAll("[name=d]").length ) {
nickjillings@1289: rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
nickjillings@1289: // IE8 throws error here and will not see later tests
nickjillings@1289: if ( !div.querySelectorAll(":enabled").length ) {
nickjillings@1289: rbuggyQSA.push( ":enabled", ":disabled" );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Opera 10-11 does not throw on post-comma invalid pseudos
nickjillings@1289: div.querySelectorAll("*,:x");
nickjillings@1289: rbuggyQSA.push(",.*:");
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
nickjillings@1289: docElem.webkitMatchesSelector ||
nickjillings@1289: docElem.mozMatchesSelector ||
nickjillings@1289: docElem.oMatchesSelector ||
nickjillings@1289: docElem.msMatchesSelector) )) ) {
nickjillings@1289:
nickjillings@1289: assert(function( div ) {
nickjillings@1289: // Check to see if it's possible to do matchesSelector
nickjillings@1289: // on a disconnected node (IE 9)
nickjillings@1289: support.disconnectedMatch = matches.call( div, "div" );
nickjillings@1289:
nickjillings@1289: // This should fail with an exception
nickjillings@1289: // Gecko does not error, returns false instead
nickjillings@1289: matches.call( div, "[s!='']:x" );
nickjillings@1289: rbuggyMatches.push( "!=", pseudos );
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
nickjillings@1289: rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
nickjillings@1289:
nickjillings@1289: /* Contains
nickjillings@1289: ---------------------------------------------------------------------- */
nickjillings@1289: hasCompare = rnative.test( docElem.compareDocumentPosition );
nickjillings@1289:
nickjillings@1289: // Element contains another
nickjillings@1289: // Purposefully does not implement inclusive descendent
nickjillings@1289: // As in, an element does not contain itself
nickjillings@1289: contains = hasCompare || rnative.test( docElem.contains ) ?
nickjillings@1289: function( a, b ) {
nickjillings@1289: var adown = a.nodeType === 9 ? a.documentElement : a,
nickjillings@1289: bup = b && b.parentNode;
nickjillings@1289: return a === bup || !!( bup && bup.nodeType === 1 && (
nickjillings@1289: adown.contains ?
nickjillings@1289: adown.contains( bup ) :
nickjillings@1289: a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
nickjillings@1289: ));
nickjillings@1289: } :
nickjillings@1289: function( a, b ) {
nickjillings@1289: if ( b ) {
nickjillings@1289: while ( (b = b.parentNode) ) {
nickjillings@1289: if ( b === a ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return false;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: /* Sorting
nickjillings@1289: ---------------------------------------------------------------------- */
nickjillings@1289:
nickjillings@1289: // Document order sorting
nickjillings@1289: sortOrder = hasCompare ?
nickjillings@1289: function( a, b ) {
nickjillings@1289:
nickjillings@1289: // Flag for duplicate removal
nickjillings@1289: if ( a === b ) {
nickjillings@1289: hasDuplicate = true;
nickjillings@1289: return 0;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Sort on method existence if only one input has compareDocumentPosition
nickjillings@1289: var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
nickjillings@1289: if ( compare ) {
nickjillings@1289: return compare;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Calculate position if both inputs belong to the same document
nickjillings@1289: compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
nickjillings@1289: a.compareDocumentPosition( b ) :
nickjillings@1289:
nickjillings@1289: // Otherwise we know they are disconnected
nickjillings@1289: 1;
nickjillings@1289:
nickjillings@1289: // Disconnected nodes
nickjillings@1289: if ( compare & 1 ||
nickjillings@1289: (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
nickjillings@1289:
nickjillings@1289: // Choose the first element that is related to our preferred document
nickjillings@1289: if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
nickjillings@1289: return -1;
nickjillings@1289: }
nickjillings@1289: if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
nickjillings@1289: return 1;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Maintain original order
nickjillings@1289: return sortInput ?
nickjillings@1289: ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1289: 0;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return compare & 4 ? -1 : 1;
nickjillings@1289: } :
nickjillings@1289: function( a, b ) {
nickjillings@1289: // Exit early if the nodes are identical
nickjillings@1289: if ( a === b ) {
nickjillings@1289: hasDuplicate = true;
nickjillings@1289: return 0;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: var cur,
nickjillings@1289: i = 0,
nickjillings@1289: aup = a.parentNode,
nickjillings@1289: bup = b.parentNode,
nickjillings@1289: ap = [ a ],
nickjillings@1289: bp = [ b ];
nickjillings@1289:
nickjillings@1289: // Parentless nodes are either documents or disconnected
nickjillings@1289: if ( !aup || !bup ) {
nickjillings@1289: return a === doc ? -1 :
nickjillings@1289: b === doc ? 1 :
nickjillings@1289: aup ? -1 :
nickjillings@1289: bup ? 1 :
nickjillings@1289: sortInput ?
nickjillings@1289: ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
nickjillings@1289: 0;
nickjillings@1289:
nickjillings@1289: // If the nodes are siblings, we can do a quick check
nickjillings@1289: } else if ( aup === bup ) {
nickjillings@1289: return siblingCheck( a, b );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Otherwise we need full lists of their ancestors for comparison
nickjillings@1289: cur = a;
nickjillings@1289: while ( (cur = cur.parentNode) ) {
nickjillings@1289: ap.unshift( cur );
nickjillings@1289: }
nickjillings@1289: cur = b;
nickjillings@1289: while ( (cur = cur.parentNode) ) {
nickjillings@1289: bp.unshift( cur );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Walk down the tree looking for a discrepancy
nickjillings@1289: while ( ap[i] === bp[i] ) {
nickjillings@1289: i++;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return i ?
nickjillings@1289: // Do a sibling check if the nodes have a common ancestor
nickjillings@1289: siblingCheck( ap[i], bp[i] ) :
nickjillings@1289:
nickjillings@1289: // Otherwise nodes in our document sort first
nickjillings@1289: ap[i] === preferredDoc ? -1 :
nickjillings@1289: bp[i] === preferredDoc ? 1 :
nickjillings@1289: 0;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: return doc;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Sizzle.matches = function( expr, elements ) {
nickjillings@1289: return Sizzle( expr, null, null, elements );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Sizzle.matchesSelector = function( elem, expr ) {
nickjillings@1289: // Set document vars if needed
nickjillings@1289: if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1289: setDocument( elem );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Make sure that attribute selectors are quoted
nickjillings@1289: expr = expr.replace( rattributeQuotes, "='$1']" );
nickjillings@1289:
nickjillings@1289: if ( support.matchesSelector && documentIsHTML &&
nickjillings@1289: ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
nickjillings@1289: ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
nickjillings@1289:
nickjillings@1289: try {
nickjillings@1289: var ret = matches.call( elem, expr );
nickjillings@1289:
nickjillings@1289: // IE 9's matchesSelector returns false on disconnected nodes
nickjillings@1289: if ( ret || support.disconnectedMatch ||
nickjillings@1289: // As well, disconnected nodes are said to be in a document
nickjillings@1289: // fragment in IE 9
nickjillings@1289: elem.document && elem.document.nodeType !== 11 ) {
nickjillings@1289: return ret;
nickjillings@1289: }
nickjillings@1289: } catch (e) {}
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return Sizzle( expr, document, null, [ elem ] ).length > 0;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Sizzle.contains = function( context, elem ) {
nickjillings@1289: // Set document vars if needed
nickjillings@1289: if ( ( context.ownerDocument || context ) !== document ) {
nickjillings@1289: setDocument( context );
nickjillings@1289: }
nickjillings@1289: return contains( context, elem );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Sizzle.attr = function( elem, name ) {
nickjillings@1289: // Set document vars if needed
nickjillings@1289: if ( ( elem.ownerDocument || elem ) !== document ) {
nickjillings@1289: setDocument( elem );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: var fn = Expr.attrHandle[ name.toLowerCase() ],
nickjillings@1289: // Don't get fooled by Object.prototype properties (jQuery #13807)
nickjillings@1289: val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
nickjillings@1289: fn( elem, name, !documentIsHTML ) :
nickjillings@1289: undefined;
nickjillings@1289:
nickjillings@1289: return val !== undefined ?
nickjillings@1289: val :
nickjillings@1289: support.attributes || !documentIsHTML ?
nickjillings@1289: elem.getAttribute( name ) :
nickjillings@1289: (val = elem.getAttributeNode(name)) && val.specified ?
nickjillings@1289: val.value :
nickjillings@1289: null;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Sizzle.error = function( msg ) {
nickjillings@1289: throw new Error( "Syntax error, unrecognized expression: " + msg );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Document sorting and removing duplicates
nickjillings@1289: * @param {ArrayLike} results
nickjillings@1289: */
nickjillings@1289: Sizzle.uniqueSort = function( results ) {
nickjillings@1289: var elem,
nickjillings@1289: duplicates = [],
nickjillings@1289: j = 0,
nickjillings@1289: i = 0;
nickjillings@1289:
nickjillings@1289: // Unless we *know* we can detect duplicates, assume their presence
nickjillings@1289: hasDuplicate = !support.detectDuplicates;
nickjillings@1289: sortInput = !support.sortStable && results.slice( 0 );
nickjillings@1289: results.sort( sortOrder );
nickjillings@1289:
nickjillings@1289: if ( hasDuplicate ) {
nickjillings@1289: while ( (elem = results[i++]) ) {
nickjillings@1289: if ( elem === results[ i ] ) {
nickjillings@1289: j = duplicates.push( i );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: while ( j-- ) {
nickjillings@1289: results.splice( duplicates[ j ], 1 );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Clear input after sorting to release objects
nickjillings@1289: // See https://github.com/jquery/sizzle/pull/225
nickjillings@1289: sortInput = null;
nickjillings@1289:
nickjillings@1289: return results;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Utility function for retrieving the text value of an array of DOM nodes
nickjillings@1289: * @param {Array|Element} elem
nickjillings@1289: */
nickjillings@1289: getText = Sizzle.getText = function( elem ) {
nickjillings@1289: var node,
nickjillings@1289: ret = "",
nickjillings@1289: i = 0,
nickjillings@1289: nodeType = elem.nodeType;
nickjillings@1289:
nickjillings@1289: if ( !nodeType ) {
nickjillings@1289: // If no nodeType, this is expected to be an array
nickjillings@1289: while ( (node = elem[i++]) ) {
nickjillings@1289: // Do not traverse comment nodes
nickjillings@1289: ret += getText( node );
nickjillings@1289: }
nickjillings@1289: } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
nickjillings@1289: // Use textContent for elements
nickjillings@1289: // innerText usage removed for consistency of new lines (jQuery #11153)
nickjillings@1289: if ( typeof elem.textContent === "string" ) {
nickjillings@1289: return elem.textContent;
nickjillings@1289: } else {
nickjillings@1289: // Traverse its children
nickjillings@1289: for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1289: ret += getText( elem );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: } else if ( nodeType === 3 || nodeType === 4 ) {
nickjillings@1289: return elem.nodeValue;
nickjillings@1289: }
nickjillings@1289: // Do not include comment or processing instruction nodes
nickjillings@1289:
nickjillings@1289: return ret;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Expr = Sizzle.selectors = {
nickjillings@1289:
nickjillings@1289: // Can be adjusted by the user
nickjillings@1289: cacheLength: 50,
nickjillings@1289:
nickjillings@1289: createPseudo: markFunction,
nickjillings@1289:
nickjillings@1289: match: matchExpr,
nickjillings@1289:
nickjillings@1289: attrHandle: {},
nickjillings@1289:
nickjillings@1289: find: {},
nickjillings@1289:
nickjillings@1289: relative: {
nickjillings@1289: ">": { dir: "parentNode", first: true },
nickjillings@1289: " ": { dir: "parentNode" },
nickjillings@1289: "+": { dir: "previousSibling", first: true },
nickjillings@1289: "~": { dir: "previousSibling" }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: preFilter: {
nickjillings@1289: "ATTR": function( match ) {
nickjillings@1289: match[1] = match[1].replace( runescape, funescape );
nickjillings@1289:
nickjillings@1289: // Move the given value to match[3] whether quoted or unquoted
nickjillings@1289: match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
nickjillings@1289:
nickjillings@1289: if ( match[2] === "~=" ) {
nickjillings@1289: match[3] = " " + match[3] + " ";
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return match.slice( 0, 4 );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "CHILD": function( match ) {
nickjillings@1289: /* matches from matchExpr["CHILD"]
nickjillings@1289: 1 type (only|nth|...)
nickjillings@1289: 2 what (child|of-type)
nickjillings@1289: 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
nickjillings@1289: 4 xn-component of xn+y argument ([+-]?\d*n|)
nickjillings@1289: 5 sign of xn-component
nickjillings@1289: 6 x of xn-component
nickjillings@1289: 7 sign of y-component
nickjillings@1289: 8 y of y-component
nickjillings@1289: */
nickjillings@1289: match[1] = match[1].toLowerCase();
nickjillings@1289:
nickjillings@1289: if ( match[1].slice( 0, 3 ) === "nth" ) {
nickjillings@1289: // nth-* requires argument
nickjillings@1289: if ( !match[3] ) {
nickjillings@1289: Sizzle.error( match[0] );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // numeric x and y parameters for Expr.filter.CHILD
nickjillings@1289: // remember that false/true cast respectively to 0/1
nickjillings@1289: match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
nickjillings@1289: match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
nickjillings@1289:
nickjillings@1289: // other types prohibit arguments
nickjillings@1289: } else if ( match[3] ) {
nickjillings@1289: Sizzle.error( match[0] );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return match;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "PSEUDO": function( match ) {
nickjillings@1289: var excess,
nickjillings@1289: unquoted = !match[6] && match[2];
nickjillings@1289:
nickjillings@1289: if ( matchExpr["CHILD"].test( match[0] ) ) {
nickjillings@1289: return null;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Accept quoted arguments as-is
nickjillings@1289: if ( match[3] ) {
nickjillings@1289: match[2] = match[4] || match[5] || "";
nickjillings@1289:
nickjillings@1289: // Strip excess characters from unquoted arguments
nickjillings@1289: } else if ( unquoted && rpseudo.test( unquoted ) &&
nickjillings@1289: // Get excess from tokenize (recursively)
nickjillings@1289: (excess = tokenize( unquoted, true )) &&
nickjillings@1289: // advance to the next closing parenthesis
nickjillings@1289: (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
nickjillings@1289:
nickjillings@1289: // excess is a negative index
nickjillings@1289: match[0] = match[0].slice( 0, excess );
nickjillings@1289: match[2] = unquoted.slice( 0, excess );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Return only captures needed by the pseudo filter method (type and argument)
nickjillings@1289: return match.slice( 0, 3 );
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: filter: {
nickjillings@1289:
nickjillings@1289: "TAG": function( nodeNameSelector ) {
nickjillings@1289: var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
nickjillings@1289: return nodeNameSelector === "*" ?
nickjillings@1289: function() { return true; } :
nickjillings@1289: function( elem ) {
nickjillings@1289: return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
nickjillings@1289: };
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "CLASS": function( className ) {
nickjillings@1289: var pattern = classCache[ className + " " ];
nickjillings@1289:
nickjillings@1289: return pattern ||
nickjillings@1289: (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
nickjillings@1289: classCache( className, function( elem ) {
nickjillings@1289: return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
nickjillings@1289: });
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "ATTR": function( name, operator, check ) {
nickjillings@1289: return function( elem ) {
nickjillings@1289: var result = Sizzle.attr( elem, name );
nickjillings@1289:
nickjillings@1289: if ( result == null ) {
nickjillings@1289: return operator === "!=";
nickjillings@1289: }
nickjillings@1289: if ( !operator ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: result += "";
nickjillings@1289:
nickjillings@1289: return operator === "=" ? result === check :
nickjillings@1289: operator === "!=" ? result !== check :
nickjillings@1289: operator === "^=" ? check && result.indexOf( check ) === 0 :
nickjillings@1289: operator === "*=" ? check && result.indexOf( check ) > -1 :
nickjillings@1289: operator === "$=" ? check && result.slice( -check.length ) === check :
nickjillings@1289: operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
nickjillings@1289: operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
nickjillings@1289: false;
nickjillings@1289: };
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "CHILD": function( type, what, argument, first, last ) {
nickjillings@1289: var simple = type.slice( 0, 3 ) !== "nth",
nickjillings@1289: forward = type.slice( -4 ) !== "last",
nickjillings@1289: ofType = what === "of-type";
nickjillings@1289:
nickjillings@1289: return first === 1 && last === 0 ?
nickjillings@1289:
nickjillings@1289: // Shortcut for :nth-*(n)
nickjillings@1289: function( elem ) {
nickjillings@1289: return !!elem.parentNode;
nickjillings@1289: } :
nickjillings@1289:
nickjillings@1289: function( elem, context, xml ) {
nickjillings@1289: var cache, outerCache, node, diff, nodeIndex, start,
nickjillings@1289: dir = simple !== forward ? "nextSibling" : "previousSibling",
nickjillings@1289: parent = elem.parentNode,
nickjillings@1289: name = ofType && elem.nodeName.toLowerCase(),
nickjillings@1289: useCache = !xml && !ofType;
nickjillings@1289:
nickjillings@1289: if ( parent ) {
nickjillings@1289:
nickjillings@1289: // :(first|last|only)-(child|of-type)
nickjillings@1289: if ( simple ) {
nickjillings@1289: while ( dir ) {
nickjillings@1289: node = elem;
nickjillings@1289: while ( (node = node[ dir ]) ) {
nickjillings@1289: if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: // Reverse direction for :only-* (if we haven't yet done so)
nickjillings@1289: start = dir = type === "only" && !start && "nextSibling";
nickjillings@1289: }
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: start = [ forward ? parent.firstChild : parent.lastChild ];
nickjillings@1289:
nickjillings@1289: // non-xml :nth-child(...) stores cache data on `parent`
nickjillings@1289: if ( forward && useCache ) {
nickjillings@1289: // Seek `elem` from a previously-cached index
nickjillings@1289: outerCache = parent[ expando ] || (parent[ expando ] = {});
nickjillings@1289: cache = outerCache[ type ] || [];
nickjillings@1289: nodeIndex = cache[0] === dirruns && cache[1];
nickjillings@1289: diff = cache[0] === dirruns && cache[2];
nickjillings@1289: node = nodeIndex && parent.childNodes[ nodeIndex ];
nickjillings@1289:
nickjillings@1289: while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1289:
nickjillings@1289: // Fallback to seeking `elem` from the start
nickjillings@1289: (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1289:
nickjillings@1289: // When found, cache indexes on `parent` and break
nickjillings@1289: if ( node.nodeType === 1 && ++diff && node === elem ) {
nickjillings@1289: outerCache[ type ] = [ dirruns, nodeIndex, diff ];
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Use previously-cached element index if available
nickjillings@1289: } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
nickjillings@1289: diff = cache[1];
nickjillings@1289:
nickjillings@1289: // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
nickjillings@1289: } else {
nickjillings@1289: // Use the same loop as above to seek `elem` from the start
nickjillings@1289: while ( (node = ++nodeIndex && node && node[ dir ] ||
nickjillings@1289: (diff = nodeIndex = 0) || start.pop()) ) {
nickjillings@1289:
nickjillings@1289: if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
nickjillings@1289: // Cache the index of each encountered element
nickjillings@1289: if ( useCache ) {
nickjillings@1289: (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( node === elem ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Incorporate the offset, then check against cycle size
nickjillings@1289: diff -= last;
nickjillings@1289: return diff === first || ( diff % first === 0 && diff / first >= 0 );
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "PSEUDO": function( pseudo, argument ) {
nickjillings@1289: // pseudo-class names are case-insensitive
nickjillings@1289: // http://www.w3.org/TR/selectors/#pseudo-classes
nickjillings@1289: // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
nickjillings@1289: // Remember that setFilters inherits from pseudos
nickjillings@1289: var args,
nickjillings@1289: fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
nickjillings@1289: Sizzle.error( "unsupported pseudo: " + pseudo );
nickjillings@1289:
nickjillings@1289: // The user may use createPseudo to indicate that
nickjillings@1289: // arguments are needed to create the filter function
nickjillings@1289: // just as Sizzle does
nickjillings@1289: if ( fn[ expando ] ) {
nickjillings@1289: return fn( argument );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // But maintain support for old signatures
nickjillings@1289: if ( fn.length > 1 ) {
nickjillings@1289: args = [ pseudo, pseudo, "", argument ];
nickjillings@1289: return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
nickjillings@1289: markFunction(function( seed, matches ) {
nickjillings@1289: var idx,
nickjillings@1289: matched = fn( seed, argument ),
nickjillings@1289: i = matched.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: idx = indexOf( seed, matched[i] );
nickjillings@1289: seed[ idx ] = !( matches[ idx ] = matched[i] );
nickjillings@1289: }
nickjillings@1289: }) :
nickjillings@1289: function( elem ) {
nickjillings@1289: return fn( elem, 0, args );
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return fn;
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: pseudos: {
nickjillings@1289: // Potentially complex pseudos
nickjillings@1289: "not": markFunction(function( selector ) {
nickjillings@1289: // Trim the selector passed to compile
nickjillings@1289: // to avoid treating leading and trailing
nickjillings@1289: // spaces as combinators
nickjillings@1289: var input = [],
nickjillings@1289: results = [],
nickjillings@1289: matcher = compile( selector.replace( rtrim, "$1" ) );
nickjillings@1289:
nickjillings@1289: return matcher[ expando ] ?
nickjillings@1289: markFunction(function( seed, matches, context, xml ) {
nickjillings@1289: var elem,
nickjillings@1289: unmatched = matcher( seed, null, xml, [] ),
nickjillings@1289: i = seed.length;
nickjillings@1289:
nickjillings@1289: // Match elements unmatched by `matcher`
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( (elem = unmatched[i]) ) {
nickjillings@1289: seed[i] = !(matches[i] = elem);
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }) :
nickjillings@1289: function( elem, context, xml ) {
nickjillings@1289: input[0] = elem;
nickjillings@1289: matcher( input, null, xml, results );
nickjillings@1289: // Don't keep the element (issue #299)
nickjillings@1289: input[0] = null;
nickjillings@1289: return !results.pop();
nickjillings@1289: };
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "has": markFunction(function( selector ) {
nickjillings@1289: return function( elem ) {
nickjillings@1289: return Sizzle( selector, elem ).length > 0;
nickjillings@1289: };
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "contains": markFunction(function( text ) {
nickjillings@1289: text = text.replace( runescape, funescape );
nickjillings@1289: return function( elem ) {
nickjillings@1289: return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
nickjillings@1289: };
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: // "Whether an element is represented by a :lang() selector
nickjillings@1289: // is based solely on the element's language value
nickjillings@1289: // being equal to the identifier C,
nickjillings@1289: // or beginning with the identifier C immediately followed by "-".
nickjillings@1289: // The matching of C against the element's language value is performed case-insensitively.
nickjillings@1289: // The identifier C does not have to be a valid language name."
nickjillings@1289: // http://www.w3.org/TR/selectors/#lang-pseudo
nickjillings@1289: "lang": markFunction( function( lang ) {
nickjillings@1289: // lang value must be a valid identifier
nickjillings@1289: if ( !ridentifier.test(lang || "") ) {
nickjillings@1289: Sizzle.error( "unsupported lang: " + lang );
nickjillings@1289: }
nickjillings@1289: lang = lang.replace( runescape, funescape ).toLowerCase();
nickjillings@1289: return function( elem ) {
nickjillings@1289: var elemLang;
nickjillings@1289: do {
nickjillings@1289: if ( (elemLang = documentIsHTML ?
nickjillings@1289: elem.lang :
nickjillings@1289: elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
nickjillings@1289:
nickjillings@1289: elemLang = elemLang.toLowerCase();
nickjillings@1289: return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
nickjillings@1289: }
nickjillings@1289: } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
nickjillings@1289: return false;
nickjillings@1289: };
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: // Miscellaneous
nickjillings@1289: "target": function( elem ) {
nickjillings@1289: var hash = window.location && window.location.hash;
nickjillings@1289: return hash && hash.slice( 1 ) === elem.id;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "root": function( elem ) {
nickjillings@1289: return elem === docElem;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "focus": function( elem ) {
nickjillings@1289: return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Boolean properties
nickjillings@1289: "enabled": function( elem ) {
nickjillings@1289: return elem.disabled === false;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "disabled": function( elem ) {
nickjillings@1289: return elem.disabled === true;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "checked": function( elem ) {
nickjillings@1289: // In CSS3, :checked should return both checked and selected elements
nickjillings@1289: // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
nickjillings@1289: var nodeName = elem.nodeName.toLowerCase();
nickjillings@1289: return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "selected": function( elem ) {
nickjillings@1289: // Accessing this property makes selected-by-default
nickjillings@1289: // options in Safari work properly
nickjillings@1289: if ( elem.parentNode ) {
nickjillings@1289: elem.parentNode.selectedIndex;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return elem.selected === true;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Contents
nickjillings@1289: "empty": function( elem ) {
nickjillings@1289: // http://www.w3.org/TR/selectors/#empty-pseudo
nickjillings@1289: // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
nickjillings@1289: // but not by others (comment: 8; processing instruction: 7; etc.)
nickjillings@1289: // nodeType < 6 works because attributes (2) do not appear as children
nickjillings@1289: for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
nickjillings@1289: if ( elem.nodeType < 6 ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return true;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "parent": function( elem ) {
nickjillings@1289: return !Expr.pseudos["empty"]( elem );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Element/input types
nickjillings@1289: "header": function( elem ) {
nickjillings@1289: return rheader.test( elem.nodeName );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "input": function( elem ) {
nickjillings@1289: return rinputs.test( elem.nodeName );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "button": function( elem ) {
nickjillings@1289: var name = elem.nodeName.toLowerCase();
nickjillings@1289: return name === "input" && elem.type === "button" || name === "button";
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: "text": function( elem ) {
nickjillings@1289: var attr;
nickjillings@1289: return elem.nodeName.toLowerCase() === "input" &&
nickjillings@1289: elem.type === "text" &&
nickjillings@1289:
nickjillings@1289: // Support: IE<8
nickjillings@1289: // New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
nickjillings@1289: ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Position-in-collection
nickjillings@1289: "first": createPositionalPseudo(function() {
nickjillings@1289: return [ 0 ];
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "last": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1289: return [ length - 1 ];
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1289: return [ argument < 0 ? argument + length : argument ];
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "even": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1289: var i = 0;
nickjillings@1289: for ( ; i < length; i += 2 ) {
nickjillings@1289: matchIndexes.push( i );
nickjillings@1289: }
nickjillings@1289: return matchIndexes;
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "odd": createPositionalPseudo(function( matchIndexes, length ) {
nickjillings@1289: var i = 1;
nickjillings@1289: for ( ; i < length; i += 2 ) {
nickjillings@1289: matchIndexes.push( i );
nickjillings@1289: }
nickjillings@1289: return matchIndexes;
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1289: var i = argument < 0 ? argument + length : argument;
nickjillings@1289: for ( ; --i >= 0; ) {
nickjillings@1289: matchIndexes.push( i );
nickjillings@1289: }
nickjillings@1289: return matchIndexes;
nickjillings@1289: }),
nickjillings@1289:
nickjillings@1289: "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
nickjillings@1289: var i = argument < 0 ? argument + length : argument;
nickjillings@1289: for ( ; ++i < length; ) {
nickjillings@1289: matchIndexes.push( i );
nickjillings@1289: }
nickjillings@1289: return matchIndexes;
nickjillings@1289: })
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: Expr.pseudos["nth"] = Expr.pseudos["eq"];
nickjillings@1289:
nickjillings@1289: // Add button/input type pseudos
nickjillings@1289: for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
nickjillings@1289: Expr.pseudos[ i ] = createInputPseudo( i );
nickjillings@1289: }
nickjillings@1289: for ( i in { submit: true, reset: true } ) {
nickjillings@1289: Expr.pseudos[ i ] = createButtonPseudo( i );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Easy API for creating new setFilters
nickjillings@1289: function setFilters() {}
nickjillings@1289: setFilters.prototype = Expr.filters = Expr.pseudos;
nickjillings@1289: Expr.setFilters = new setFilters();
nickjillings@1289:
nickjillings@1289: tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
nickjillings@1289: var matched, match, tokens, type,
nickjillings@1289: soFar, groups, preFilters,
nickjillings@1289: cached = tokenCache[ selector + " " ];
nickjillings@1289:
nickjillings@1289: if ( cached ) {
nickjillings@1289: return parseOnly ? 0 : cached.slice( 0 );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: soFar = selector;
nickjillings@1289: groups = [];
nickjillings@1289: preFilters = Expr.preFilter;
nickjillings@1289:
nickjillings@1289: while ( soFar ) {
nickjillings@1289:
nickjillings@1289: // Comma and first run
nickjillings@1289: if ( !matched || (match = rcomma.exec( soFar )) ) {
nickjillings@1289: if ( match ) {
nickjillings@1289: // Don't consume trailing commas as valid
nickjillings@1289: soFar = soFar.slice( match[0].length ) || soFar;
nickjillings@1289: }
nickjillings@1289: groups.push( (tokens = []) );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: matched = false;
nickjillings@1289:
nickjillings@1289: // Combinators
nickjillings@1289: if ( (match = rcombinators.exec( soFar )) ) {
nickjillings@1289: matched = match.shift();
nickjillings@1289: tokens.push({
nickjillings@1289: value: matched,
nickjillings@1289: // Cast descendant combinators to space
nickjillings@1289: type: match[0].replace( rtrim, " " )
nickjillings@1289: });
nickjillings@1289: soFar = soFar.slice( matched.length );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Filters
nickjillings@1289: for ( type in Expr.filter ) {
nickjillings@1289: if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
nickjillings@1289: (match = preFilters[ type ]( match ))) ) {
nickjillings@1289: matched = match.shift();
nickjillings@1289: tokens.push({
nickjillings@1289: value: matched,
nickjillings@1289: type: type,
nickjillings@1289: matches: match
nickjillings@1289: });
nickjillings@1289: soFar = soFar.slice( matched.length );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( !matched ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Return the length of the invalid excess
nickjillings@1289: // if we're just parsing
nickjillings@1289: // Otherwise, throw an error or return tokens
nickjillings@1289: return parseOnly ?
nickjillings@1289: soFar.length :
nickjillings@1289: soFar ?
nickjillings@1289: Sizzle.error( selector ) :
nickjillings@1289: // Cache the tokens
nickjillings@1289: tokenCache( selector, groups ).slice( 0 );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: function toSelector( tokens ) {
nickjillings@1289: var i = 0,
nickjillings@1289: len = tokens.length,
nickjillings@1289: selector = "";
nickjillings@1289: for ( ; i < len; i++ ) {
nickjillings@1289: selector += tokens[i].value;
nickjillings@1289: }
nickjillings@1289: return selector;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function addCombinator( matcher, combinator, base ) {
nickjillings@1289: var dir = combinator.dir,
nickjillings@1289: checkNonElements = base && dir === "parentNode",
nickjillings@1289: doneName = done++;
nickjillings@1289:
nickjillings@1289: return combinator.first ?
nickjillings@1289: // Check against closest ancestor/preceding element
nickjillings@1289: function( elem, context, xml ) {
nickjillings@1289: while ( (elem = elem[ dir ]) ) {
nickjillings@1289: if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1289: return matcher( elem, context, xml );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: } :
nickjillings@1289:
nickjillings@1289: // Check against all ancestor/preceding elements
nickjillings@1289: function( elem, context, xml ) {
nickjillings@1289: var oldCache, outerCache,
nickjillings@1289: newCache = [ dirruns, doneName ];
nickjillings@1289:
nickjillings@1289: // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
nickjillings@1289: if ( xml ) {
nickjillings@1289: while ( (elem = elem[ dir ]) ) {
nickjillings@1289: if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1289: if ( matcher( elem, context, xml ) ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: } else {
nickjillings@1289: while ( (elem = elem[ dir ]) ) {
nickjillings@1289: if ( elem.nodeType === 1 || checkNonElements ) {
nickjillings@1289: outerCache = elem[ expando ] || (elem[ expando ] = {});
nickjillings@1289: if ( (oldCache = outerCache[ dir ]) &&
nickjillings@1289: oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
nickjillings@1289:
nickjillings@1289: // Assign to newCache so results back-propagate to previous elements
nickjillings@1289: return (newCache[ 2 ] = oldCache[ 2 ]);
nickjillings@1289: } else {
nickjillings@1289: // Reuse newcache so results back-propagate to previous elements
nickjillings@1289: outerCache[ dir ] = newCache;
nickjillings@1289:
nickjillings@1289: // A match means we're done; a fail means we have to keep checking
nickjillings@1289: if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function elementMatcher( matchers ) {
nickjillings@1289: return matchers.length > 1 ?
nickjillings@1289: function( elem, context, xml ) {
nickjillings@1289: var i = matchers.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( !matchers[i]( elem, context, xml ) ) {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return true;
nickjillings@1289: } :
nickjillings@1289: matchers[0];
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function multipleContexts( selector, contexts, results ) {
nickjillings@1289: var i = 0,
nickjillings@1289: len = contexts.length;
nickjillings@1289: for ( ; i < len; i++ ) {
nickjillings@1289: Sizzle( selector, contexts[i], results );
nickjillings@1289: }
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function condense( unmatched, map, filter, context, xml ) {
nickjillings@1289: var elem,
nickjillings@1289: newUnmatched = [],
nickjillings@1289: i = 0,
nickjillings@1289: len = unmatched.length,
nickjillings@1289: mapped = map != null;
nickjillings@1289:
nickjillings@1289: for ( ; i < len; i++ ) {
nickjillings@1289: if ( (elem = unmatched[i]) ) {
nickjillings@1289: if ( !filter || filter( elem, context, xml ) ) {
nickjillings@1289: newUnmatched.push( elem );
nickjillings@1289: if ( mapped ) {
nickjillings@1289: map.push( i );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return newUnmatched;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
nickjillings@1289: if ( postFilter && !postFilter[ expando ] ) {
nickjillings@1289: postFilter = setMatcher( postFilter );
nickjillings@1289: }
nickjillings@1289: if ( postFinder && !postFinder[ expando ] ) {
nickjillings@1289: postFinder = setMatcher( postFinder, postSelector );
nickjillings@1289: }
nickjillings@1289: return markFunction(function( seed, results, context, xml ) {
nickjillings@1289: var temp, i, elem,
nickjillings@1289: preMap = [],
nickjillings@1289: postMap = [],
nickjillings@1289: preexisting = results.length,
nickjillings@1289:
nickjillings@1289: // Get initial elements from seed or context
nickjillings@1289: elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
nickjillings@1289:
nickjillings@1289: // Prefilter to get matcher input, preserving a map for seed-results synchronization
nickjillings@1289: matcherIn = preFilter && ( seed || !selector ) ?
nickjillings@1289: condense( elems, preMap, preFilter, context, xml ) :
nickjillings@1289: elems,
nickjillings@1289:
nickjillings@1289: matcherOut = matcher ?
nickjillings@1289: // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
nickjillings@1289: postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
nickjillings@1289:
nickjillings@1289: // ...intermediate processing is necessary
nickjillings@1289: [] :
nickjillings@1289:
nickjillings@1289: // ...otherwise use results directly
nickjillings@1289: results :
nickjillings@1289: matcherIn;
nickjillings@1289:
nickjillings@1289: // Find primary matches
nickjillings@1289: if ( matcher ) {
nickjillings@1289: matcher( matcherIn, matcherOut, context, xml );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Apply postFilter
nickjillings@1289: if ( postFilter ) {
nickjillings@1289: temp = condense( matcherOut, postMap );
nickjillings@1289: postFilter( temp, [], context, xml );
nickjillings@1289:
nickjillings@1289: // Un-match failing elements by moving them back to matcherIn
nickjillings@1289: i = temp.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( (elem = temp[i]) ) {
nickjillings@1289: matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( seed ) {
nickjillings@1289: if ( postFinder || preFilter ) {
nickjillings@1289: if ( postFinder ) {
nickjillings@1289: // Get the final matcherOut by condensing this intermediate into postFinder contexts
nickjillings@1289: temp = [];
nickjillings@1289: i = matcherOut.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( (elem = matcherOut[i]) ) {
nickjillings@1289: // Restore matcherIn since elem is not yet a final match
nickjillings@1289: temp.push( (matcherIn[i] = elem) );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: postFinder( null, (matcherOut = []), temp, xml );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Move matched elements from seed to results to keep them synchronized
nickjillings@1289: i = matcherOut.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( (elem = matcherOut[i]) &&
nickjillings@1289: (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
nickjillings@1289:
nickjillings@1289: seed[temp] = !(results[temp] = elem);
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Add elements to results, through postFinder if defined
nickjillings@1289: } else {
nickjillings@1289: matcherOut = condense(
nickjillings@1289: matcherOut === results ?
nickjillings@1289: matcherOut.splice( preexisting, matcherOut.length ) :
nickjillings@1289: matcherOut
nickjillings@1289: );
nickjillings@1289: if ( postFinder ) {
nickjillings@1289: postFinder( null, results, matcherOut, xml );
nickjillings@1289: } else {
nickjillings@1289: push.apply( results, matcherOut );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function matcherFromTokens( tokens ) {
nickjillings@1289: var checkContext, matcher, j,
nickjillings@1289: len = tokens.length,
nickjillings@1289: leadingRelative = Expr.relative[ tokens[0].type ],
nickjillings@1289: implicitRelative = leadingRelative || Expr.relative[" "],
nickjillings@1289: i = leadingRelative ? 1 : 0,
nickjillings@1289:
nickjillings@1289: // The foundational matcher ensures that elements are reachable from top-level context(s)
nickjillings@1289: matchContext = addCombinator( function( elem ) {
nickjillings@1289: return elem === checkContext;
nickjillings@1289: }, implicitRelative, true ),
nickjillings@1289: matchAnyContext = addCombinator( function( elem ) {
nickjillings@1289: return indexOf( checkContext, elem ) > -1;
nickjillings@1289: }, implicitRelative, true ),
nickjillings@1289: matchers = [ function( elem, context, xml ) {
nickjillings@1289: var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
nickjillings@1289: (checkContext = context).nodeType ?
nickjillings@1289: matchContext( elem, context, xml ) :
nickjillings@1289: matchAnyContext( elem, context, xml ) );
nickjillings@1289: // Avoid hanging onto element (issue #299)
nickjillings@1289: checkContext = null;
nickjillings@1289: return ret;
nickjillings@1289: } ];
nickjillings@1289:
nickjillings@1289: for ( ; i < len; i++ ) {
nickjillings@1289: if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
nickjillings@1289: matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
nickjillings@1289: } else {
nickjillings@1289: matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
nickjillings@1289:
nickjillings@1289: // Return special upon seeing a positional matcher
nickjillings@1289: if ( matcher[ expando ] ) {
nickjillings@1289: // Find the next relative operator (if any) for proper handling
nickjillings@1289: j = ++i;
nickjillings@1289: for ( ; j < len; j++ ) {
nickjillings@1289: if ( Expr.relative[ tokens[j].type ] ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return setMatcher(
nickjillings@1289: i > 1 && elementMatcher( matchers ),
nickjillings@1289: i > 1 && toSelector(
nickjillings@1289: // If the preceding token was a descendant combinator, insert an implicit any-element `*`
nickjillings@1289: tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
nickjillings@1289: ).replace( rtrim, "$1" ),
nickjillings@1289: matcher,
nickjillings@1289: i < j && matcherFromTokens( tokens.slice( i, j ) ),
nickjillings@1289: j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
nickjillings@1289: j < len && toSelector( tokens )
nickjillings@1289: );
nickjillings@1289: }
nickjillings@1289: matchers.push( matcher );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return elementMatcher( matchers );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
nickjillings@1289: var bySet = setMatchers.length > 0,
nickjillings@1289: byElement = elementMatchers.length > 0,
nickjillings@1289: superMatcher = function( seed, context, xml, results, outermost ) {
nickjillings@1289: var elem, j, matcher,
nickjillings@1289: matchedCount = 0,
nickjillings@1289: i = "0",
nickjillings@1289: unmatched = seed && [],
nickjillings@1289: setMatched = [],
nickjillings@1289: contextBackup = outermostContext,
nickjillings@1289: // We must always have either seed elements or outermost context
nickjillings@1289: elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
nickjillings@1289: // Use integer dirruns iff this is the outermost matcher
nickjillings@1289: dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
nickjillings@1289: len = elems.length;
nickjillings@1289:
nickjillings@1289: if ( outermost ) {
nickjillings@1289: outermostContext = context !== document && context;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Add elements passing elementMatchers directly to results
nickjillings@1289: // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
nickjillings@1289: // Support: IE<9, Safari
nickjillings@1289: // Tolerate NodeList properties (IE: "length"; Safari: ) matching elements by id
nickjillings@1289: for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
nickjillings@1289: if ( byElement && elem ) {
nickjillings@1289: j = 0;
nickjillings@1289: while ( (matcher = elementMatchers[j++]) ) {
nickjillings@1289: if ( matcher( elem, context, xml ) ) {
nickjillings@1289: results.push( elem );
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: if ( outermost ) {
nickjillings@1289: dirruns = dirrunsUnique;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Track unmatched elements for set filters
nickjillings@1289: if ( bySet ) {
nickjillings@1289: // They will have gone through all possible matchers
nickjillings@1289: if ( (elem = !matcher && elem) ) {
nickjillings@1289: matchedCount--;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Lengthen the array for every element, matched or not
nickjillings@1289: if ( seed ) {
nickjillings@1289: unmatched.push( elem );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Apply set filters to unmatched elements
nickjillings@1289: matchedCount += i;
nickjillings@1289: if ( bySet && i !== matchedCount ) {
nickjillings@1289: j = 0;
nickjillings@1289: while ( (matcher = setMatchers[j++]) ) {
nickjillings@1289: matcher( unmatched, setMatched, context, xml );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( seed ) {
nickjillings@1289: // Reintegrate element matches to eliminate the need for sorting
nickjillings@1289: if ( matchedCount > 0 ) {
nickjillings@1289: while ( i-- ) {
nickjillings@1289: if ( !(unmatched[i] || setMatched[i]) ) {
nickjillings@1289: setMatched[i] = pop.call( results );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Discard index placeholder values to get only actual matches
nickjillings@1289: setMatched = condense( setMatched );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Add matches to results
nickjillings@1289: push.apply( results, setMatched );
nickjillings@1289:
nickjillings@1289: // Seedless set matches succeeding multiple successful matchers stipulate sorting
nickjillings@1289: if ( outermost && !seed && setMatched.length > 0 &&
nickjillings@1289: ( matchedCount + setMatchers.length ) > 1 ) {
nickjillings@1289:
nickjillings@1289: Sizzle.uniqueSort( results );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Override manipulation of globals by nested matchers
nickjillings@1289: if ( outermost ) {
nickjillings@1289: dirruns = dirrunsUnique;
nickjillings@1289: outermostContext = contextBackup;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return unmatched;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: return bySet ?
nickjillings@1289: markFunction( superMatcher ) :
nickjillings@1289: superMatcher;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
nickjillings@1289: var i,
nickjillings@1289: setMatchers = [],
nickjillings@1289: elementMatchers = [],
nickjillings@1289: cached = compilerCache[ selector + " " ];
nickjillings@1289:
nickjillings@1289: if ( !cached ) {
nickjillings@1289: // Generate a function of recursive functions that can be used to check each element
nickjillings@1289: if ( !match ) {
nickjillings@1289: match = tokenize( selector );
nickjillings@1289: }
nickjillings@1289: i = match.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: cached = matcherFromTokens( match[i] );
nickjillings@1289: if ( cached[ expando ] ) {
nickjillings@1289: setMatchers.push( cached );
nickjillings@1289: } else {
nickjillings@1289: elementMatchers.push( cached );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Cache the compiled function
nickjillings@1289: cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
nickjillings@1289:
nickjillings@1289: // Save selector and tokenization
nickjillings@1289: cached.selector = selector;
nickjillings@1289: }
nickjillings@1289: return cached;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * A low-level selection function that works with Sizzle's compiled
nickjillings@1289: * selector functions
nickjillings@1289: * @param {String|Function} selector A selector or a pre-compiled
nickjillings@1289: * selector function built with Sizzle.compile
nickjillings@1289: * @param {Element} context
nickjillings@1289: * @param {Array} [results]
nickjillings@1289: * @param {Array} [seed] A set of elements to match against
nickjillings@1289: */
nickjillings@1289: select = Sizzle.select = function( selector, context, results, seed ) {
nickjillings@1289: var i, tokens, token, type, find,
nickjillings@1289: compiled = typeof selector === "function" && selector,
nickjillings@1289: match = !seed && tokenize( (selector = compiled.selector || selector) );
nickjillings@1289:
nickjillings@1289: results = results || [];
nickjillings@1289:
nickjillings@1289: // Try to minimize operations if there is no seed and only one group
nickjillings@1289: if ( match.length === 1 ) {
nickjillings@1289:
nickjillings@1289: // Take a shortcut and set the context if the root selector is an ID
nickjillings@1289: tokens = match[0] = match[0].slice( 0 );
nickjillings@1289: if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
nickjillings@1289: support.getById && context.nodeType === 9 && documentIsHTML &&
nickjillings@1289: Expr.relative[ tokens[1].type ] ) {
nickjillings@1289:
nickjillings@1289: context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
nickjillings@1289: if ( !context ) {
nickjillings@1289: return results;
nickjillings@1289:
nickjillings@1289: // Precompiled matchers will still verify ancestry, so step up a level
nickjillings@1289: } else if ( compiled ) {
nickjillings@1289: context = context.parentNode;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: selector = selector.slice( tokens.shift().value.length );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Fetch a seed set for right-to-left matching
nickjillings@1289: i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: token = tokens[i];
nickjillings@1289:
nickjillings@1289: // Abort if we hit a combinator
nickjillings@1289: if ( Expr.relative[ (type = token.type) ] ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: if ( (find = Expr.find[ type ]) ) {
nickjillings@1289: // Search, expanding context for leading sibling combinators
nickjillings@1289: if ( (seed = find(
nickjillings@1289: token.matches[0].replace( runescape, funescape ),
nickjillings@1289: rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
nickjillings@1289: )) ) {
nickjillings@1289:
nickjillings@1289: // If seed is empty or no tokens remain, we can return early
nickjillings@1289: tokens.splice( i, 1 );
nickjillings@1289: selector = seed.length && toSelector( tokens );
nickjillings@1289: if ( !selector ) {
nickjillings@1289: push.apply( results, seed );
nickjillings@1289: return results;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Compile and execute a filtering function if one is not provided
nickjillings@1289: // Provide `match` to avoid retokenization if we modified the selector above
nickjillings@1289: ( compiled || compile( selector, match ) )(
nickjillings@1289: seed,
nickjillings@1289: context,
nickjillings@1289: !documentIsHTML,
nickjillings@1289: results,
nickjillings@1289: rsibling.test( selector ) && testContext( context.parentNode ) || context
nickjillings@1289: );
nickjillings@1289: return results;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // One-time assignments
nickjillings@1289:
nickjillings@1289: // Sort stability
nickjillings@1289: support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
nickjillings@1289:
nickjillings@1289: // Support: Chrome 14-35+
nickjillings@1289: // Always assume duplicates if they aren't passed to the comparison function
nickjillings@1289: support.detectDuplicates = !!hasDuplicate;
nickjillings@1289:
nickjillings@1289: // Initialize against the default document
nickjillings@1289: setDocument();
nickjillings@1289:
nickjillings@1289: // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
nickjillings@1289: // Detached nodes confoundingly follow *each other*
nickjillings@1289: support.sortDetached = assert(function( div1 ) {
nickjillings@1289: // Should return 1, but returns 4 (following)
nickjillings@1289: return div1.compareDocumentPosition( document.createElement("div") ) & 1;
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: // Support: IE<8
nickjillings@1289: // Prevent attribute/property "interpolation"
nickjillings@1289: // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
nickjillings@1289: if ( !assert(function( div ) {
nickjillings@1289: div.innerHTML = "";
nickjillings@1289: return div.firstChild.getAttribute("href") === "#" ;
nickjillings@1289: }) ) {
nickjillings@1289: addHandle( "type|href|height|width", function( elem, name, isXML ) {
nickjillings@1289: if ( !isXML ) {
nickjillings@1289: return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Support: IE<9
nickjillings@1289: // Use defaultValue in place of getAttribute("value")
nickjillings@1289: if ( !support.attributes || !assert(function( div ) {
nickjillings@1289: div.innerHTML = "";
nickjillings@1289: div.firstChild.setAttribute( "value", "" );
nickjillings@1289: return div.firstChild.getAttribute( "value" ) === "";
nickjillings@1289: }) ) {
nickjillings@1289: addHandle( "value", function( elem, name, isXML ) {
nickjillings@1289: if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
nickjillings@1289: return elem.defaultValue;
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Support: IE<9
nickjillings@1289: // Use getAttributeNode to fetch booleans when getAttribute lies
nickjillings@1289: if ( !assert(function( div ) {
nickjillings@1289: return div.getAttribute("disabled") == null;
nickjillings@1289: }) ) {
nickjillings@1289: addHandle( booleans, function( elem, name, isXML ) {
nickjillings@1289: var val;
nickjillings@1289: if ( !isXML ) {
nickjillings@1289: return elem[ name ] === true ? name.toLowerCase() :
nickjillings@1289: (val = elem.getAttributeNode( name )) && val.specified ?
nickjillings@1289: val.value :
nickjillings@1289: null;
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return Sizzle;
nickjillings@1289:
nickjillings@1289: })( window );
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: jQuery.find = Sizzle;
nickjillings@1289: jQuery.expr = Sizzle.selectors;
nickjillings@1289: jQuery.expr[":"] = jQuery.expr.pseudos;
nickjillings@1289: jQuery.unique = Sizzle.uniqueSort;
nickjillings@1289: jQuery.text = Sizzle.getText;
nickjillings@1289: jQuery.isXMLDoc = Sizzle.isXML;
nickjillings@1289: jQuery.contains = Sizzle.contains;
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: var rneedsContext = jQuery.expr.match.needsContext;
nickjillings@1289:
nickjillings@1289: var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/);
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: var risSimple = /^.[^:#\[\.,]*$/;
nickjillings@1289:
nickjillings@1289: // Implement the identical functionality for filter and not
nickjillings@1289: function winnow( elements, qualifier, not ) {
nickjillings@1289: if ( jQuery.isFunction( qualifier ) ) {
nickjillings@1289: return jQuery.grep( elements, function( elem, i ) {
nickjillings@1289: /* jshint -W018 */
nickjillings@1289: return !!qualifier.call( elem, i, elem ) !== not;
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( qualifier.nodeType ) {
nickjillings@1289: return jQuery.grep( elements, function( elem ) {
nickjillings@1289: return ( elem === qualifier ) !== not;
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( typeof qualifier === "string" ) {
nickjillings@1289: if ( risSimple.test( qualifier ) ) {
nickjillings@1289: return jQuery.filter( qualifier, elements, not );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: qualifier = jQuery.filter( qualifier, elements );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return jQuery.grep( elements, function( elem ) {
nickjillings@1289: return ( indexOf.call( qualifier, elem ) >= 0 ) !== not;
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: jQuery.filter = function( expr, elems, not ) {
nickjillings@1289: var elem = elems[ 0 ];
nickjillings@1289:
nickjillings@1289: if ( not ) {
nickjillings@1289: expr = ":not(" + expr + ")";
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return elems.length === 1 && elem.nodeType === 1 ?
nickjillings@1289: jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
nickjillings@1289: jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
nickjillings@1289: return elem.nodeType === 1;
nickjillings@1289: }));
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: jQuery.fn.extend({
nickjillings@1289: find: function( selector ) {
nickjillings@1289: var i,
nickjillings@1289: len = this.length,
nickjillings@1289: ret = [],
nickjillings@1289: self = this;
nickjillings@1289:
nickjillings@1289: if ( typeof selector !== "string" ) {
nickjillings@1289: return this.pushStack( jQuery( selector ).filter(function() {
nickjillings@1289: for ( i = 0; i < len; i++ ) {
nickjillings@1289: if ( jQuery.contains( self[ i ], this ) ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }) );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: for ( i = 0; i < len; i++ ) {
nickjillings@1289: jQuery.find( selector, self[ i ], ret );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Needed because $( selector, context ) becomes $( context ).find( selector )
nickjillings@1289: ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
nickjillings@1289: ret.selector = this.selector ? this.selector + " " + selector : selector;
nickjillings@1289: return ret;
nickjillings@1289: },
nickjillings@1289: filter: function( selector ) {
nickjillings@1289: return this.pushStack( winnow(this, selector || [], false) );
nickjillings@1289: },
nickjillings@1289: not: function( selector ) {
nickjillings@1289: return this.pushStack( winnow(this, selector || [], true) );
nickjillings@1289: },
nickjillings@1289: is: function( selector ) {
nickjillings@1289: return !!winnow(
nickjillings@1289: this,
nickjillings@1289:
nickjillings@1289: // If this is a positional/relative selector, check membership in the returned set
nickjillings@1289: // so $("p:first").is("p:last") won't return true for a doc with two "p".
nickjillings@1289: typeof selector === "string" && rneedsContext.test( selector ) ?
nickjillings@1289: jQuery( selector ) :
nickjillings@1289: selector || [],
nickjillings@1289: false
nickjillings@1289: ).length;
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: // Initialize a jQuery object
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: // A central reference to the root jQuery(document)
nickjillings@1289: var rootjQuery,
nickjillings@1289:
nickjillings@1289: // A simple way to check for HTML strings
nickjillings@1289: // Prioritize #id over to avoid XSS via location.hash (#9521)
nickjillings@1289: // Strict HTML recognition (#11290: must start with <)
nickjillings@1289: rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
nickjillings@1289:
nickjillings@1289: init = jQuery.fn.init = function( selector, context ) {
nickjillings@1289: var match, elem;
nickjillings@1289:
nickjillings@1289: // HANDLE: $(""), $(null), $(undefined), $(false)
nickjillings@1289: if ( !selector ) {
nickjillings@1289: return this;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Handle HTML strings
nickjillings@1289: if ( typeof selector === "string" ) {
nickjillings@1289: if ( selector[0] === "<" && selector[ selector.length - 1 ] === ">" && selector.length >= 3 ) {
nickjillings@1289: // Assume that strings that start and end with <> are HTML and skip the regex check
nickjillings@1289: match = [ null, selector, null ];
nickjillings@1289:
nickjillings@1289: } else {
nickjillings@1289: match = rquickExpr.exec( selector );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Match html or make sure no context is specified for #id
nickjillings@1289: if ( match && (match[1] || !context) ) {
nickjillings@1289:
nickjillings@1289: // HANDLE: $(html) -> $(array)
nickjillings@1289: if ( match[1] ) {
nickjillings@1289: context = context instanceof jQuery ? context[0] : context;
nickjillings@1289:
nickjillings@1289: // Option to run scripts is true for back-compat
nickjillings@1289: // Intentionally let the error be thrown if parseHTML is not present
nickjillings@1289: jQuery.merge( this, jQuery.parseHTML(
nickjillings@1289: match[1],
nickjillings@1289: context && context.nodeType ? context.ownerDocument || context : document,
nickjillings@1289: true
nickjillings@1289: ) );
nickjillings@1289:
nickjillings@1289: // HANDLE: $(html, props)
nickjillings@1289: if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) {
nickjillings@1289: for ( match in context ) {
nickjillings@1289: // Properties of context are called as methods if possible
nickjillings@1289: if ( jQuery.isFunction( this[ match ] ) ) {
nickjillings@1289: this[ match ]( context[ match ] );
nickjillings@1289:
nickjillings@1289: // ...and otherwise set as attributes
nickjillings@1289: } else {
nickjillings@1289: this.attr( match, context[ match ] );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return this;
nickjillings@1289:
nickjillings@1289: // HANDLE: $(#id)
nickjillings@1289: } else {
nickjillings@1289: elem = document.getElementById( match[2] );
nickjillings@1289:
nickjillings@1289: // Support: Blackberry 4.6
nickjillings@1289: // gEBID returns nodes no longer in the document (#6963)
nickjillings@1289: if ( elem && elem.parentNode ) {
nickjillings@1289: // Inject the element directly into the jQuery object
nickjillings@1289: this.length = 1;
nickjillings@1289: this[0] = elem;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: this.context = document;
nickjillings@1289: this.selector = selector;
nickjillings@1289: return this;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // HANDLE: $(expr, $(...))
nickjillings@1289: } else if ( !context || context.jquery ) {
nickjillings@1289: return ( context || rootjQuery ).find( selector );
nickjillings@1289:
nickjillings@1289: // HANDLE: $(expr, context)
nickjillings@1289: // (which is just equivalent to: $(context).find(expr)
nickjillings@1289: } else {
nickjillings@1289: return this.constructor( context ).find( selector );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // HANDLE: $(DOMElement)
nickjillings@1289: } else if ( selector.nodeType ) {
nickjillings@1289: this.context = this[0] = selector;
nickjillings@1289: this.length = 1;
nickjillings@1289: return this;
nickjillings@1289:
nickjillings@1289: // HANDLE: $(function)
nickjillings@1289: // Shortcut for document ready
nickjillings@1289: } else if ( jQuery.isFunction( selector ) ) {
nickjillings@1289: return typeof rootjQuery.ready !== "undefined" ?
nickjillings@1289: rootjQuery.ready( selector ) :
nickjillings@1289: // Execute immediately if ready is not present
nickjillings@1289: selector( jQuery );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( selector.selector !== undefined ) {
nickjillings@1289: this.selector = selector.selector;
nickjillings@1289: this.context = selector.context;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return jQuery.makeArray( selector, this );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // Give the init function the jQuery prototype for later instantiation
nickjillings@1289: init.prototype = jQuery.fn;
nickjillings@1289:
nickjillings@1289: // Initialize central reference
nickjillings@1289: rootjQuery = jQuery( document );
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: var rparentsprev = /^(?:parents|prev(?:Until|All))/,
nickjillings@1289: // Methods guaranteed to produce a unique set when starting from a unique set
nickjillings@1289: guaranteedUnique = {
nickjillings@1289: children: true,
nickjillings@1289: contents: true,
nickjillings@1289: next: true,
nickjillings@1289: prev: true
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: jQuery.extend({
nickjillings@1289: dir: function( elem, dir, until ) {
nickjillings@1289: var matched = [],
nickjillings@1289: truncate = until !== undefined;
nickjillings@1289:
nickjillings@1289: while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
nickjillings@1289: if ( elem.nodeType === 1 ) {
nickjillings@1289: if ( truncate && jQuery( elem ).is( until ) ) {
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: matched.push( elem );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return matched;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: sibling: function( n, elem ) {
nickjillings@1289: var matched = [];
nickjillings@1289:
nickjillings@1289: for ( ; n; n = n.nextSibling ) {
nickjillings@1289: if ( n.nodeType === 1 && n !== elem ) {
nickjillings@1289: matched.push( n );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return matched;
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: jQuery.fn.extend({
nickjillings@1289: has: function( target ) {
nickjillings@1289: var targets = jQuery( target, this ),
nickjillings@1289: l = targets.length;
nickjillings@1289:
nickjillings@1289: return this.filter(function() {
nickjillings@1289: var i = 0;
nickjillings@1289: for ( ; i < l; i++ ) {
nickjillings@1289: if ( jQuery.contains( this, targets[i] ) ) {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: closest: function( selectors, context ) {
nickjillings@1289: var cur,
nickjillings@1289: i = 0,
nickjillings@1289: l = this.length,
nickjillings@1289: matched = [],
nickjillings@1289: pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
nickjillings@1289: jQuery( selectors, context || this.context ) :
nickjillings@1289: 0;
nickjillings@1289:
nickjillings@1289: for ( ; i < l; i++ ) {
nickjillings@1289: for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
nickjillings@1289: // Always skip document fragments
nickjillings@1289: if ( cur.nodeType < 11 && (pos ?
nickjillings@1289: pos.index(cur) > -1 :
nickjillings@1289:
nickjillings@1289: // Don't pass non-elements to Sizzle
nickjillings@1289: cur.nodeType === 1 &&
nickjillings@1289: jQuery.find.matchesSelector(cur, selectors)) ) {
nickjillings@1289:
nickjillings@1289: matched.push( cur );
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Determine the position of an element within the set
nickjillings@1289: index: function( elem ) {
nickjillings@1289:
nickjillings@1289: // No argument, return index in parent
nickjillings@1289: if ( !elem ) {
nickjillings@1289: return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Index in selector
nickjillings@1289: if ( typeof elem === "string" ) {
nickjillings@1289: return indexOf.call( jQuery( elem ), this[ 0 ] );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Locate the position of the desired element
nickjillings@1289: return indexOf.call( this,
nickjillings@1289:
nickjillings@1289: // If it receives a jQuery object, the first element is used
nickjillings@1289: elem.jquery ? elem[ 0 ] : elem
nickjillings@1289: );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: add: function( selector, context ) {
nickjillings@1289: return this.pushStack(
nickjillings@1289: jQuery.unique(
nickjillings@1289: jQuery.merge( this.get(), jQuery( selector, context ) )
nickjillings@1289: )
nickjillings@1289: );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: addBack: function( selector ) {
nickjillings@1289: return this.add( selector == null ?
nickjillings@1289: this.prevObject : this.prevObject.filter(selector)
nickjillings@1289: );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: function sibling( cur, dir ) {
nickjillings@1289: while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
nickjillings@1289: return cur;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: jQuery.each({
nickjillings@1289: parent: function( elem ) {
nickjillings@1289: var parent = elem.parentNode;
nickjillings@1289: return parent && parent.nodeType !== 11 ? parent : null;
nickjillings@1289: },
nickjillings@1289: parents: function( elem ) {
nickjillings@1289: return jQuery.dir( elem, "parentNode" );
nickjillings@1289: },
nickjillings@1289: parentsUntil: function( elem, i, until ) {
nickjillings@1289: return jQuery.dir( elem, "parentNode", until );
nickjillings@1289: },
nickjillings@1289: next: function( elem ) {
nickjillings@1289: return sibling( elem, "nextSibling" );
nickjillings@1289: },
nickjillings@1289: prev: function( elem ) {
nickjillings@1289: return sibling( elem, "previousSibling" );
nickjillings@1289: },
nickjillings@1289: nextAll: function( elem ) {
nickjillings@1289: return jQuery.dir( elem, "nextSibling" );
nickjillings@1289: },
nickjillings@1289: prevAll: function( elem ) {
nickjillings@1289: return jQuery.dir( elem, "previousSibling" );
nickjillings@1289: },
nickjillings@1289: nextUntil: function( elem, i, until ) {
nickjillings@1289: return jQuery.dir( elem, "nextSibling", until );
nickjillings@1289: },
nickjillings@1289: prevUntil: function( elem, i, until ) {
nickjillings@1289: return jQuery.dir( elem, "previousSibling", until );
nickjillings@1289: },
nickjillings@1289: siblings: function( elem ) {
nickjillings@1289: return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
nickjillings@1289: },
nickjillings@1289: children: function( elem ) {
nickjillings@1289: return jQuery.sibling( elem.firstChild );
nickjillings@1289: },
nickjillings@1289: contents: function( elem ) {
nickjillings@1289: return elem.contentDocument || jQuery.merge( [], elem.childNodes );
nickjillings@1289: }
nickjillings@1289: }, function( name, fn ) {
nickjillings@1289: jQuery.fn[ name ] = function( until, selector ) {
nickjillings@1289: var matched = jQuery.map( this, fn, until );
nickjillings@1289:
nickjillings@1289: if ( name.slice( -5 ) !== "Until" ) {
nickjillings@1289: selector = until;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( selector && typeof selector === "string" ) {
nickjillings@1289: matched = jQuery.filter( selector, matched );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( this.length > 1 ) {
nickjillings@1289: // Remove duplicates
nickjillings@1289: if ( !guaranteedUnique[ name ] ) {
nickjillings@1289: jQuery.unique( matched );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Reverse order for parents* and prev-derivatives
nickjillings@1289: if ( rparentsprev.test( name ) ) {
nickjillings@1289: matched.reverse();
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return this.pushStack( matched );
nickjillings@1289: };
nickjillings@1289: });
nickjillings@1289: var rnotwhite = (/\S+/g);
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: // String to Object options format cache
nickjillings@1289: var optionsCache = {};
nickjillings@1289:
nickjillings@1289: // Convert String-formatted options into Object-formatted ones and store in cache
nickjillings@1289: function createOptions( options ) {
nickjillings@1289: var object = optionsCache[ options ] = {};
nickjillings@1289: jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
nickjillings@1289: object[ flag ] = true;
nickjillings@1289: });
nickjillings@1289: return object;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /*
nickjillings@1289: * Create a callback list using the following parameters:
nickjillings@1289: *
nickjillings@1289: * options: an optional list of space-separated options that will change how
nickjillings@1289: * the callback list behaves or a more traditional option object
nickjillings@1289: *
nickjillings@1289: * By default a callback list will act like an event callback list and can be
nickjillings@1289: * "fired" multiple times.
nickjillings@1289: *
nickjillings@1289: * Possible options:
nickjillings@1289: *
nickjillings@1289: * once: will ensure the callback list can only be fired once (like a Deferred)
nickjillings@1289: *
nickjillings@1289: * memory: will keep track of previous values and will call any callback added
nickjillings@1289: * after the list has been fired right away with the latest "memorized"
nickjillings@1289: * values (like a Deferred)
nickjillings@1289: *
nickjillings@1289: * unique: will ensure a callback can only be added once (no duplicate in the list)
nickjillings@1289: *
nickjillings@1289: * stopOnFalse: interrupt callings when a callback returns false
nickjillings@1289: *
nickjillings@1289: */
nickjillings@1289: jQuery.Callbacks = function( options ) {
nickjillings@1289:
nickjillings@1289: // Convert options from String-formatted to Object-formatted if needed
nickjillings@1289: // (we check in cache first)
nickjillings@1289: options = typeof options === "string" ?
nickjillings@1289: ( optionsCache[ options ] || createOptions( options ) ) :
nickjillings@1289: jQuery.extend( {}, options );
nickjillings@1289:
nickjillings@1289: var // Last fire value (for non-forgettable lists)
nickjillings@1289: memory,
nickjillings@1289: // Flag to know if list was already fired
nickjillings@1289: fired,
nickjillings@1289: // Flag to know if list is currently firing
nickjillings@1289: firing,
nickjillings@1289: // First callback to fire (used internally by add and fireWith)
nickjillings@1289: firingStart,
nickjillings@1289: // End of the loop when firing
nickjillings@1289: firingLength,
nickjillings@1289: // Index of currently firing callback (modified by remove if needed)
nickjillings@1289: firingIndex,
nickjillings@1289: // Actual callback list
nickjillings@1289: list = [],
nickjillings@1289: // Stack of fire calls for repeatable lists
nickjillings@1289: stack = !options.once && [],
nickjillings@1289: // Fire callbacks
nickjillings@1289: fire = function( data ) {
nickjillings@1289: memory = options.memory && data;
nickjillings@1289: fired = true;
nickjillings@1289: firingIndex = firingStart || 0;
nickjillings@1289: firingStart = 0;
nickjillings@1289: firingLength = list.length;
nickjillings@1289: firing = true;
nickjillings@1289: for ( ; list && firingIndex < firingLength; firingIndex++ ) {
nickjillings@1289: if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) {
nickjillings@1289: memory = false; // To prevent further calls using add
nickjillings@1289: break;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: firing = false;
nickjillings@1289: if ( list ) {
nickjillings@1289: if ( stack ) {
nickjillings@1289: if ( stack.length ) {
nickjillings@1289: fire( stack.shift() );
nickjillings@1289: }
nickjillings@1289: } else if ( memory ) {
nickjillings@1289: list = [];
nickjillings@1289: } else {
nickjillings@1289: self.disable();
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289: // Actual Callbacks object
nickjillings@1289: self = {
nickjillings@1289: // Add a callback or a collection of callbacks to the list
nickjillings@1289: add: function() {
nickjillings@1289: if ( list ) {
nickjillings@1289: // First, we save the current length
nickjillings@1289: var start = list.length;
nickjillings@1289: (function add( args ) {
nickjillings@1289: jQuery.each( args, function( _, arg ) {
nickjillings@1289: var type = jQuery.type( arg );
nickjillings@1289: if ( type === "function" ) {
nickjillings@1289: if ( !options.unique || !self.has( arg ) ) {
nickjillings@1289: list.push( arg );
nickjillings@1289: }
nickjillings@1289: } else if ( arg && arg.length && type !== "string" ) {
nickjillings@1289: // Inspect recursively
nickjillings@1289: add( arg );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: })( arguments );
nickjillings@1289: // Do we need to add the callbacks to the
nickjillings@1289: // current firing batch?
nickjillings@1289: if ( firing ) {
nickjillings@1289: firingLength = list.length;
nickjillings@1289: // With memory, if we're not firing then
nickjillings@1289: // we should call right away
nickjillings@1289: } else if ( memory ) {
nickjillings@1289: firingStart = start;
nickjillings@1289: fire( memory );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // Remove a callback from the list
nickjillings@1289: remove: function() {
nickjillings@1289: if ( list ) {
nickjillings@1289: jQuery.each( arguments, function( _, arg ) {
nickjillings@1289: var index;
nickjillings@1289: while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
nickjillings@1289: list.splice( index, 1 );
nickjillings@1289: // Handle firing indexes
nickjillings@1289: if ( firing ) {
nickjillings@1289: if ( index <= firingLength ) {
nickjillings@1289: firingLength--;
nickjillings@1289: }
nickjillings@1289: if ( index <= firingIndex ) {
nickjillings@1289: firingIndex--;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // Check if a given callback is in the list.
nickjillings@1289: // If no argument is given, return whether or not list has callbacks attached.
nickjillings@1289: has: function( fn ) {
nickjillings@1289: return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length );
nickjillings@1289: },
nickjillings@1289: // Remove all callbacks from the list
nickjillings@1289: empty: function() {
nickjillings@1289: list = [];
nickjillings@1289: firingLength = 0;
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // Have the list do nothing anymore
nickjillings@1289: disable: function() {
nickjillings@1289: list = stack = memory = undefined;
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // Is it disabled?
nickjillings@1289: disabled: function() {
nickjillings@1289: return !list;
nickjillings@1289: },
nickjillings@1289: // Lock the list in its current state
nickjillings@1289: lock: function() {
nickjillings@1289: stack = undefined;
nickjillings@1289: if ( !memory ) {
nickjillings@1289: self.disable();
nickjillings@1289: }
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // Is it locked?
nickjillings@1289: locked: function() {
nickjillings@1289: return !stack;
nickjillings@1289: },
nickjillings@1289: // Call all callbacks with the given context and arguments
nickjillings@1289: fireWith: function( context, args ) {
nickjillings@1289: if ( list && ( !fired || stack ) ) {
nickjillings@1289: args = args || [];
nickjillings@1289: args = [ context, args.slice ? args.slice() : args ];
nickjillings@1289: if ( firing ) {
nickjillings@1289: stack.push( args );
nickjillings@1289: } else {
nickjillings@1289: fire( args );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // Call all the callbacks with the given arguments
nickjillings@1289: fire: function() {
nickjillings@1289: self.fireWith( this, arguments );
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: // To know if the callbacks have already been called at least once
nickjillings@1289: fired: function() {
nickjillings@1289: return !!fired;
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: return self;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: jQuery.extend({
nickjillings@1289:
nickjillings@1289: Deferred: function( func ) {
nickjillings@1289: var tuples = [
nickjillings@1289: // action, add listener, listener list, final state
nickjillings@1289: [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
nickjillings@1289: [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
nickjillings@1289: [ "notify", "progress", jQuery.Callbacks("memory") ]
nickjillings@1289: ],
nickjillings@1289: state = "pending",
nickjillings@1289: promise = {
nickjillings@1289: state: function() {
nickjillings@1289: return state;
nickjillings@1289: },
nickjillings@1289: always: function() {
nickjillings@1289: deferred.done( arguments ).fail( arguments );
nickjillings@1289: return this;
nickjillings@1289: },
nickjillings@1289: then: function( /* fnDone, fnFail, fnProgress */ ) {
nickjillings@1289: var fns = arguments;
nickjillings@1289: return jQuery.Deferred(function( newDefer ) {
nickjillings@1289: jQuery.each( tuples, function( i, tuple ) {
nickjillings@1289: var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
nickjillings@1289: // deferred[ done | fail | progress ] for forwarding actions to newDefer
nickjillings@1289: deferred[ tuple[1] ](function() {
nickjillings@1289: var returned = fn && fn.apply( this, arguments );
nickjillings@1289: if ( returned && jQuery.isFunction( returned.promise ) ) {
nickjillings@1289: returned.promise()
nickjillings@1289: .done( newDefer.resolve )
nickjillings@1289: .fail( newDefer.reject )
nickjillings@1289: .progress( newDefer.notify );
nickjillings@1289: } else {
nickjillings@1289: newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: });
nickjillings@1289: fns = null;
nickjillings@1289: }).promise();
nickjillings@1289: },
nickjillings@1289: // Get a promise for this deferred
nickjillings@1289: // If obj is provided, the promise aspect is added to the object
nickjillings@1289: promise: function( obj ) {
nickjillings@1289: return obj != null ? jQuery.extend( obj, promise ) : promise;
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289: deferred = {};
nickjillings@1289:
nickjillings@1289: // Keep pipe for back-compat
nickjillings@1289: promise.pipe = promise.then;
nickjillings@1289:
nickjillings@1289: // Add list-specific methods
nickjillings@1289: jQuery.each( tuples, function( i, tuple ) {
nickjillings@1289: var list = tuple[ 2 ],
nickjillings@1289: stateString = tuple[ 3 ];
nickjillings@1289:
nickjillings@1289: // promise[ done | fail | progress ] = list.add
nickjillings@1289: promise[ tuple[1] ] = list.add;
nickjillings@1289:
nickjillings@1289: // Handle state
nickjillings@1289: if ( stateString ) {
nickjillings@1289: list.add(function() {
nickjillings@1289: // state = [ resolved | rejected ]
nickjillings@1289: state = stateString;
nickjillings@1289:
nickjillings@1289: // [ reject_list | resolve_list ].disable; progress_list.lock
nickjillings@1289: }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // deferred[ resolve | reject | notify ]
nickjillings@1289: deferred[ tuple[0] ] = function() {
nickjillings@1289: deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments );
nickjillings@1289: return this;
nickjillings@1289: };
nickjillings@1289: deferred[ tuple[0] + "With" ] = list.fireWith;
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: // Make the deferred a promise
nickjillings@1289: promise.promise( deferred );
nickjillings@1289:
nickjillings@1289: // Call given func if any
nickjillings@1289: if ( func ) {
nickjillings@1289: func.call( deferred, deferred );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // All done!
nickjillings@1289: return deferred;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Deferred helper
nickjillings@1289: when: function( subordinate /* , ..., subordinateN */ ) {
nickjillings@1289: var i = 0,
nickjillings@1289: resolveValues = slice.call( arguments ),
nickjillings@1289: length = resolveValues.length,
nickjillings@1289:
nickjillings@1289: // the count of uncompleted subordinates
nickjillings@1289: remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
nickjillings@1289:
nickjillings@1289: // the master Deferred. If resolveValues consist of only a single Deferred, just use that.
nickjillings@1289: deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
nickjillings@1289:
nickjillings@1289: // Update function for both resolve and progress values
nickjillings@1289: updateFunc = function( i, contexts, values ) {
nickjillings@1289: return function( value ) {
nickjillings@1289: contexts[ i ] = this;
nickjillings@1289: values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
nickjillings@1289: if ( values === progressValues ) {
nickjillings@1289: deferred.notifyWith( contexts, values );
nickjillings@1289: } else if ( !( --remaining ) ) {
nickjillings@1289: deferred.resolveWith( contexts, values );
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: progressValues, progressContexts, resolveContexts;
nickjillings@1289:
nickjillings@1289: // Add listeners to Deferred subordinates; treat others as resolved
nickjillings@1289: if ( length > 1 ) {
nickjillings@1289: progressValues = new Array( length );
nickjillings@1289: progressContexts = new Array( length );
nickjillings@1289: resolveContexts = new Array( length );
nickjillings@1289: for ( ; i < length; i++ ) {
nickjillings@1289: if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
nickjillings@1289: resolveValues[ i ].promise()
nickjillings@1289: .done( updateFunc( i, resolveContexts, resolveValues ) )
nickjillings@1289: .fail( deferred.reject )
nickjillings@1289: .progress( updateFunc( i, progressContexts, progressValues ) );
nickjillings@1289: } else {
nickjillings@1289: --remaining;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // If we're not waiting on anything, resolve the master
nickjillings@1289: if ( !remaining ) {
nickjillings@1289: deferred.resolveWith( resolveContexts, resolveValues );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return deferred.promise();
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: // The deferred used on DOM ready
nickjillings@1289: var readyList;
nickjillings@1289:
nickjillings@1289: jQuery.fn.ready = function( fn ) {
nickjillings@1289: // Add the callback
nickjillings@1289: jQuery.ready.promise().done( fn );
nickjillings@1289:
nickjillings@1289: return this;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: jQuery.extend({
nickjillings@1289: // Is the DOM ready to be used? Set to true once it occurs.
nickjillings@1289: isReady: false,
nickjillings@1289:
nickjillings@1289: // A counter to track how many items to wait for before
nickjillings@1289: // the ready event fires. See #6781
nickjillings@1289: readyWait: 1,
nickjillings@1289:
nickjillings@1289: // Hold (or release) the ready event
nickjillings@1289: holdReady: function( hold ) {
nickjillings@1289: if ( hold ) {
nickjillings@1289: jQuery.readyWait++;
nickjillings@1289: } else {
nickjillings@1289: jQuery.ready( true );
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Handle when the DOM is ready
nickjillings@1289: ready: function( wait ) {
nickjillings@1289:
nickjillings@1289: // Abort if there are pending holds or we're already ready
nickjillings@1289: if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Remember that the DOM is ready
nickjillings@1289: jQuery.isReady = true;
nickjillings@1289:
nickjillings@1289: // If a normal DOM Ready event fired, decrement, and wait if need be
nickjillings@1289: if ( wait !== true && --jQuery.readyWait > 0 ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // If there are functions bound, to execute
nickjillings@1289: readyList.resolveWith( document, [ jQuery ] );
nickjillings@1289:
nickjillings@1289: // Trigger any bound ready events
nickjillings@1289: if ( jQuery.fn.triggerHandler ) {
nickjillings@1289: jQuery( document ).triggerHandler( "ready" );
nickjillings@1289: jQuery( document ).off( "ready" );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * The ready event handler and self cleanup method
nickjillings@1289: */
nickjillings@1289: function completed() {
nickjillings@1289: document.removeEventListener( "DOMContentLoaded", completed, false );
nickjillings@1289: window.removeEventListener( "load", completed, false );
nickjillings@1289: jQuery.ready();
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: jQuery.ready.promise = function( obj ) {
nickjillings@1289: if ( !readyList ) {
nickjillings@1289:
nickjillings@1289: readyList = jQuery.Deferred();
nickjillings@1289:
nickjillings@1289: // Catch cases where $(document).ready() is called after the browser event has already occurred.
nickjillings@1289: // We once tried to use readyState "interactive" here, but it caused issues like the one
nickjillings@1289: // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15
nickjillings@1289: if ( document.readyState === "complete" ) {
nickjillings@1289: // Handle it asynchronously to allow scripts the opportunity to delay ready
nickjillings@1289: setTimeout( jQuery.ready );
nickjillings@1289:
nickjillings@1289: } else {
nickjillings@1289:
nickjillings@1289: // Use the handy event callback
nickjillings@1289: document.addEventListener( "DOMContentLoaded", completed, false );
nickjillings@1289:
nickjillings@1289: // A fallback to window.onload, that will always work
nickjillings@1289: window.addEventListener( "load", completed, false );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return readyList.promise( obj );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // Kick off the DOM ready check even if the user does not
nickjillings@1289: jQuery.ready.promise();
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: // Multifunctional method to get and set values of a collection
nickjillings@1289: // The value/s can optionally be executed if it's a function
nickjillings@1289: var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
nickjillings@1289: var i = 0,
nickjillings@1289: len = elems.length,
nickjillings@1289: bulk = key == null;
nickjillings@1289:
nickjillings@1289: // Sets many values
nickjillings@1289: if ( jQuery.type( key ) === "object" ) {
nickjillings@1289: chainable = true;
nickjillings@1289: for ( i in key ) {
nickjillings@1289: jQuery.access( elems, fn, i, key[i], true, emptyGet, raw );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Sets one value
nickjillings@1289: } else if ( value !== undefined ) {
nickjillings@1289: chainable = true;
nickjillings@1289:
nickjillings@1289: if ( !jQuery.isFunction( value ) ) {
nickjillings@1289: raw = true;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( bulk ) {
nickjillings@1289: // Bulk operations run against the entire set
nickjillings@1289: if ( raw ) {
nickjillings@1289: fn.call( elems, value );
nickjillings@1289: fn = null;
nickjillings@1289:
nickjillings@1289: // ...except when executing function values
nickjillings@1289: } else {
nickjillings@1289: bulk = fn;
nickjillings@1289: fn = function( elem, key, value ) {
nickjillings@1289: return bulk.call( jQuery( elem ), value );
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( fn ) {
nickjillings@1289: for ( ; i < len; i++ ) {
nickjillings@1289: fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return chainable ?
nickjillings@1289: elems :
nickjillings@1289:
nickjillings@1289: // Gets
nickjillings@1289: bulk ?
nickjillings@1289: fn.call( elems ) :
nickjillings@1289: len ? fn( elems[0], key ) : emptyGet;
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: /**
nickjillings@1289: * Determines whether an object can have data
nickjillings@1289: */
nickjillings@1289: jQuery.acceptData = function( owner ) {
nickjillings@1289: // Accepts only:
nickjillings@1289: // - Node
nickjillings@1289: // - Node.ELEMENT_NODE
nickjillings@1289: // - Node.DOCUMENT_NODE
nickjillings@1289: // - Object
nickjillings@1289: // - Any
nickjillings@1289: /* jshint -W018 */
nickjillings@1289: return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: function Data() {
nickjillings@1289: // Support: Android<4,
nickjillings@1289: // Old WebKit does not have Object.preventExtensions/freeze method,
nickjillings@1289: // return new empty object instead with no [[set]] accessor
nickjillings@1289: Object.defineProperty( this.cache = {}, 0, {
nickjillings@1289: get: function() {
nickjillings@1289: return {};
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: this.expando = jQuery.expando + Data.uid++;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: Data.uid = 1;
nickjillings@1289: Data.accepts = jQuery.acceptData;
nickjillings@1289:
nickjillings@1289: Data.prototype = {
nickjillings@1289: key: function( owner ) {
nickjillings@1289: // We can accept data for non-element nodes in modern browsers,
nickjillings@1289: // but we should not, see #8335.
nickjillings@1289: // Always return the key for a frozen object.
nickjillings@1289: if ( !Data.accepts( owner ) ) {
nickjillings@1289: return 0;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: var descriptor = {},
nickjillings@1289: // Check if the owner object already has a cache key
nickjillings@1289: unlock = owner[ this.expando ];
nickjillings@1289:
nickjillings@1289: // If not, create one
nickjillings@1289: if ( !unlock ) {
nickjillings@1289: unlock = Data.uid++;
nickjillings@1289:
nickjillings@1289: // Secure it in a non-enumerable, non-writable property
nickjillings@1289: try {
nickjillings@1289: descriptor[ this.expando ] = { value: unlock };
nickjillings@1289: Object.defineProperties( owner, descriptor );
nickjillings@1289:
nickjillings@1289: // Support: Android<4
nickjillings@1289: // Fallback to a less secure definition
nickjillings@1289: } catch ( e ) {
nickjillings@1289: descriptor[ this.expando ] = unlock;
nickjillings@1289: jQuery.extend( owner, descriptor );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Ensure the cache object
nickjillings@1289: if ( !this.cache[ unlock ] ) {
nickjillings@1289: this.cache[ unlock ] = {};
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return unlock;
nickjillings@1289: },
nickjillings@1289: set: function( owner, data, value ) {
nickjillings@1289: var prop,
nickjillings@1289: // There may be an unlock assigned to this node,
nickjillings@1289: // if there is no entry for this "owner", create one inline
nickjillings@1289: // and set the unlock as though an owner entry had always existed
nickjillings@1289: unlock = this.key( owner ),
nickjillings@1289: cache = this.cache[ unlock ];
nickjillings@1289:
nickjillings@1289: // Handle: [ owner, key, value ] args
nickjillings@1289: if ( typeof data === "string" ) {
nickjillings@1289: cache[ data ] = value;
nickjillings@1289:
nickjillings@1289: // Handle: [ owner, { properties } ] args
nickjillings@1289: } else {
nickjillings@1289: // Fresh assignments by object are shallow copied
nickjillings@1289: if ( jQuery.isEmptyObject( cache ) ) {
nickjillings@1289: jQuery.extend( this.cache[ unlock ], data );
nickjillings@1289: // Otherwise, copy the properties one-by-one to the cache object
nickjillings@1289: } else {
nickjillings@1289: for ( prop in data ) {
nickjillings@1289: cache[ prop ] = data[ prop ];
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return cache;
nickjillings@1289: },
nickjillings@1289: get: function( owner, key ) {
nickjillings@1289: // Either a valid cache is found, or will be created.
nickjillings@1289: // New caches will be created and the unlock returned,
nickjillings@1289: // allowing direct access to the newly created
nickjillings@1289: // empty data object. A valid owner object must be provided.
nickjillings@1289: var cache = this.cache[ this.key( owner ) ];
nickjillings@1289:
nickjillings@1289: return key === undefined ?
nickjillings@1289: cache : cache[ key ];
nickjillings@1289: },
nickjillings@1289: access: function( owner, key, value ) {
nickjillings@1289: var stored;
nickjillings@1289: // In cases where either:
nickjillings@1289: //
nickjillings@1289: // 1. No key was specified
nickjillings@1289: // 2. A string key was specified, but no value provided
nickjillings@1289: //
nickjillings@1289: // Take the "read" path and allow the get method to determine
nickjillings@1289: // which value to return, respectively either:
nickjillings@1289: //
nickjillings@1289: // 1. The entire cache object
nickjillings@1289: // 2. The data stored at the key
nickjillings@1289: //
nickjillings@1289: if ( key === undefined ||
nickjillings@1289: ((key && typeof key === "string") && value === undefined) ) {
nickjillings@1289:
nickjillings@1289: stored = this.get( owner, key );
nickjillings@1289:
nickjillings@1289: return stored !== undefined ?
nickjillings@1289: stored : this.get( owner, jQuery.camelCase(key) );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // [*]When the key is not a string, or both a key and value
nickjillings@1289: // are specified, set or extend (existing objects) with either:
nickjillings@1289: //
nickjillings@1289: // 1. An object of properties
nickjillings@1289: // 2. A key and value
nickjillings@1289: //
nickjillings@1289: this.set( owner, key, value );
nickjillings@1289:
nickjillings@1289: // Since the "set" path can have two possible entry points
nickjillings@1289: // return the expected data based on which path was taken[*]
nickjillings@1289: return value !== undefined ? value : key;
nickjillings@1289: },
nickjillings@1289: remove: function( owner, key ) {
nickjillings@1289: var i, name, camel,
nickjillings@1289: unlock = this.key( owner ),
nickjillings@1289: cache = this.cache[ unlock ];
nickjillings@1289:
nickjillings@1289: if ( key === undefined ) {
nickjillings@1289: this.cache[ unlock ] = {};
nickjillings@1289:
nickjillings@1289: } else {
nickjillings@1289: // Support array or space separated string of keys
nickjillings@1289: if ( jQuery.isArray( key ) ) {
nickjillings@1289: // If "name" is an array of keys...
nickjillings@1289: // When data is initially created, via ("key", "val") signature,
nickjillings@1289: // keys will be converted to camelCase.
nickjillings@1289: // Since there is no way to tell _how_ a key was added, remove
nickjillings@1289: // both plain key and camelCase key. #12786
nickjillings@1289: // This will only penalize the array argument path.
nickjillings@1289: name = key.concat( key.map( jQuery.camelCase ) );
nickjillings@1289: } else {
nickjillings@1289: camel = jQuery.camelCase( key );
nickjillings@1289: // Try the string as a key before any manipulation
nickjillings@1289: if ( key in cache ) {
nickjillings@1289: name = [ key, camel ];
nickjillings@1289: } else {
nickjillings@1289: // If a key with the spaces exists, use it.
nickjillings@1289: // Otherwise, create an array by matching non-whitespace
nickjillings@1289: name = camel;
nickjillings@1289: name = name in cache ?
nickjillings@1289: [ name ] : ( name.match( rnotwhite ) || [] );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: i = name.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289: delete cache[ name[ i ] ];
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289: hasData: function( owner ) {
nickjillings@1289: return !jQuery.isEmptyObject(
nickjillings@1289: this.cache[ owner[ this.expando ] ] || {}
nickjillings@1289: );
nickjillings@1289: },
nickjillings@1289: discard: function( owner ) {
nickjillings@1289: if ( owner[ this.expando ] ) {
nickjillings@1289: delete this.cache[ owner[ this.expando ] ];
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289: var data_priv = new Data();
nickjillings@1289:
nickjillings@1289: var data_user = new Data();
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: // Implementation Summary
nickjillings@1289: //
nickjillings@1289: // 1. Enforce API surface and semantic compatibility with 1.9.x branch
nickjillings@1289: // 2. Improve the module's maintainability by reducing the storage
nickjillings@1289: // paths to a single mechanism.
nickjillings@1289: // 3. Use the same single mechanism to support "private" and "user" data.
nickjillings@1289: // 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
nickjillings@1289: // 5. Avoid exposing implementation details on user objects (eg. expando properties)
nickjillings@1289: // 6. Provide a clear path for implementation upgrade to WeakMap in 2014
nickjillings@1289:
nickjillings@1289: var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
nickjillings@1289: rmultiDash = /([A-Z])/g;
nickjillings@1289:
nickjillings@1289: function dataAttr( elem, key, data ) {
nickjillings@1289: var name;
nickjillings@1289:
nickjillings@1289: // If nothing was found internally, try to fetch any
nickjillings@1289: // data from the HTML5 data-* attribute
nickjillings@1289: if ( data === undefined && elem.nodeType === 1 ) {
nickjillings@1289: name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase();
nickjillings@1289: data = elem.getAttribute( name );
nickjillings@1289:
nickjillings@1289: if ( typeof data === "string" ) {
nickjillings@1289: try {
nickjillings@1289: data = data === "true" ? true :
nickjillings@1289: data === "false" ? false :
nickjillings@1289: data === "null" ? null :
nickjillings@1289: // Only convert to a number if it doesn't change the string
nickjillings@1289: +data + "" === data ? +data :
nickjillings@1289: rbrace.test( data ) ? jQuery.parseJSON( data ) :
nickjillings@1289: data;
nickjillings@1289: } catch( e ) {}
nickjillings@1289:
nickjillings@1289: // Make sure we set the data so it isn't changed later
nickjillings@1289: data_user.set( elem, key, data );
nickjillings@1289: } else {
nickjillings@1289: data = undefined;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return data;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: jQuery.extend({
nickjillings@1289: hasData: function( elem ) {
nickjillings@1289: return data_user.hasData( elem ) || data_priv.hasData( elem );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: data: function( elem, name, data ) {
nickjillings@1289: return data_user.access( elem, name, data );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: removeData: function( elem, name ) {
nickjillings@1289: data_user.remove( elem, name );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // TODO: Now that all calls to _data and _removeData have been replaced
nickjillings@1289: // with direct calls to data_priv methods, these can be deprecated.
nickjillings@1289: _data: function( elem, name, data ) {
nickjillings@1289: return data_priv.access( elem, name, data );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: _removeData: function( elem, name ) {
nickjillings@1289: data_priv.remove( elem, name );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: jQuery.fn.extend({
nickjillings@1289: data: function( key, value ) {
nickjillings@1289: var i, name, data,
nickjillings@1289: elem = this[ 0 ],
nickjillings@1289: attrs = elem && elem.attributes;
nickjillings@1289:
nickjillings@1289: // Gets all values
nickjillings@1289: if ( key === undefined ) {
nickjillings@1289: if ( this.length ) {
nickjillings@1289: data = data_user.get( elem );
nickjillings@1289:
nickjillings@1289: if ( elem.nodeType === 1 && !data_priv.get( elem, "hasDataAttrs" ) ) {
nickjillings@1289: i = attrs.length;
nickjillings@1289: while ( i-- ) {
nickjillings@1289:
nickjillings@1289: // Support: IE11+
nickjillings@1289: // The attrs elements can be null (#14894)
nickjillings@1289: if ( attrs[ i ] ) {
nickjillings@1289: name = attrs[ i ].name;
nickjillings@1289: if ( name.indexOf( "data-" ) === 0 ) {
nickjillings@1289: name = jQuery.camelCase( name.slice(5) );
nickjillings@1289: dataAttr( elem, name, data[ name ] );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: data_priv.set( elem, "hasDataAttrs", true );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return data;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Sets multiple values
nickjillings@1289: if ( typeof key === "object" ) {
nickjillings@1289: return this.each(function() {
nickjillings@1289: data_user.set( this, key );
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return access( this, function( value ) {
nickjillings@1289: var data,
nickjillings@1289: camelKey = jQuery.camelCase( key );
nickjillings@1289:
nickjillings@1289: // The calling jQuery object (element matches) is not empty
nickjillings@1289: // (and therefore has an element appears at this[ 0 ]) and the
nickjillings@1289: // `value` parameter was not undefined. An empty jQuery object
nickjillings@1289: // will result in `undefined` for elem = this[ 0 ] which will
nickjillings@1289: // throw an exception if an attempt to read a data cache is made.
nickjillings@1289: if ( elem && value === undefined ) {
nickjillings@1289: // Attempt to get data from the cache
nickjillings@1289: // with the key as-is
nickjillings@1289: data = data_user.get( elem, key );
nickjillings@1289: if ( data !== undefined ) {
nickjillings@1289: return data;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Attempt to get data from the cache
nickjillings@1289: // with the key camelized
nickjillings@1289: data = data_user.get( elem, camelKey );
nickjillings@1289: if ( data !== undefined ) {
nickjillings@1289: return data;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Attempt to "discover" the data in
nickjillings@1289: // HTML5 custom data-* attrs
nickjillings@1289: data = dataAttr( elem, camelKey, undefined );
nickjillings@1289: if ( data !== undefined ) {
nickjillings@1289: return data;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // We tried really hard, but the data doesn't exist.
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Set the data...
nickjillings@1289: this.each(function() {
nickjillings@1289: // First, attempt to store a copy or reference of any
nickjillings@1289: // data that might've been store with a camelCased key.
nickjillings@1289: var data = data_user.get( this, camelKey );
nickjillings@1289:
nickjillings@1289: // For HTML5 data-* attribute interop, we have to
nickjillings@1289: // store property names with dashes in a camelCase form.
nickjillings@1289: // This might not apply to all properties...*
nickjillings@1289: data_user.set( this, camelKey, value );
nickjillings@1289:
nickjillings@1289: // *... In the case of properties that might _actually_
nickjillings@1289: // have dashes, we need to also store a copy of that
nickjillings@1289: // unchanged property.
nickjillings@1289: if ( key.indexOf("-") !== -1 && data !== undefined ) {
nickjillings@1289: data_user.set( this, key, value );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: }, null, value, arguments.length > 1, null, true );
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: removeData: function( key ) {
nickjillings@1289: return this.each(function() {
nickjillings@1289: data_user.remove( this, key );
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: jQuery.extend({
nickjillings@1289: queue: function( elem, type, data ) {
nickjillings@1289: var queue;
nickjillings@1289:
nickjillings@1289: if ( elem ) {
nickjillings@1289: type = ( type || "fx" ) + "queue";
nickjillings@1289: queue = data_priv.get( elem, type );
nickjillings@1289:
nickjillings@1289: // Speed up dequeue by getting out quickly if this is just a lookup
nickjillings@1289: if ( data ) {
nickjillings@1289: if ( !queue || jQuery.isArray( data ) ) {
nickjillings@1289: queue = data_priv.access( elem, type, jQuery.makeArray(data) );
nickjillings@1289: } else {
nickjillings@1289: queue.push( data );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: return queue || [];
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: dequeue: function( elem, type ) {
nickjillings@1289: type = type || "fx";
nickjillings@1289:
nickjillings@1289: var queue = jQuery.queue( elem, type ),
nickjillings@1289: startLength = queue.length,
nickjillings@1289: fn = queue.shift(),
nickjillings@1289: hooks = jQuery._queueHooks( elem, type ),
nickjillings@1289: next = function() {
nickjillings@1289: jQuery.dequeue( elem, type );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: // If the fx queue is dequeued, always remove the progress sentinel
nickjillings@1289: if ( fn === "inprogress" ) {
nickjillings@1289: fn = queue.shift();
nickjillings@1289: startLength--;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( fn ) {
nickjillings@1289:
nickjillings@1289: // Add a progress sentinel to prevent the fx queue from being
nickjillings@1289: // automatically dequeued
nickjillings@1289: if ( type === "fx" ) {
nickjillings@1289: queue.unshift( "inprogress" );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Clear up the last queue stop function
nickjillings@1289: delete hooks.stop;
nickjillings@1289: fn.call( elem, next, hooks );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( !startLength && hooks ) {
nickjillings@1289: hooks.empty.fire();
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Not public - generate a queueHooks object, or return the current one
nickjillings@1289: _queueHooks: function( elem, type ) {
nickjillings@1289: var key = type + "queueHooks";
nickjillings@1289: return data_priv.get( elem, key ) || data_priv.access( elem, key, {
nickjillings@1289: empty: jQuery.Callbacks("once memory").add(function() {
nickjillings@1289: data_priv.remove( elem, [ type + "queue", key ] );
nickjillings@1289: })
nickjillings@1289: });
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289:
nickjillings@1289: jQuery.fn.extend({
nickjillings@1289: queue: function( type, data ) {
nickjillings@1289: var setter = 2;
nickjillings@1289:
nickjillings@1289: if ( typeof type !== "string" ) {
nickjillings@1289: data = type;
nickjillings@1289: type = "fx";
nickjillings@1289: setter--;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( arguments.length < setter ) {
nickjillings@1289: return jQuery.queue( this[0], type );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return data === undefined ?
nickjillings@1289: this :
nickjillings@1289: this.each(function() {
nickjillings@1289: var queue = jQuery.queue( this, type, data );
nickjillings@1289:
nickjillings@1289: // Ensure a hooks for this queue
nickjillings@1289: jQuery._queueHooks( this, type );
nickjillings@1289:
nickjillings@1289: if ( type === "fx" && queue[0] !== "inprogress" ) {
nickjillings@1289: jQuery.dequeue( this, type );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: },
nickjillings@1289: dequeue: function( type ) {
nickjillings@1289: return this.each(function() {
nickjillings@1289: jQuery.dequeue( this, type );
nickjillings@1289: });
nickjillings@1289: },
nickjillings@1289: clearQueue: function( type ) {
nickjillings@1289: return this.queue( type || "fx", [] );
nickjillings@1289: },
nickjillings@1289: // Get a promise resolved when queues of a certain type
nickjillings@1289: // are emptied (fx is the type by default)
nickjillings@1289: promise: function( type, obj ) {
nickjillings@1289: var tmp,
nickjillings@1289: count = 1,
nickjillings@1289: defer = jQuery.Deferred(),
nickjillings@1289: elements = this,
nickjillings@1289: i = this.length,
nickjillings@1289: resolve = function() {
nickjillings@1289: if ( !( --count ) ) {
nickjillings@1289: defer.resolveWith( elements, [ elements ] );
nickjillings@1289: }
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: if ( typeof type !== "string" ) {
nickjillings@1289: obj = type;
nickjillings@1289: type = undefined;
nickjillings@1289: }
nickjillings@1289: type = type || "fx";
nickjillings@1289:
nickjillings@1289: while ( i-- ) {
nickjillings@1289: tmp = data_priv.get( elements[ i ], type + "queueHooks" );
nickjillings@1289: if ( tmp && tmp.empty ) {
nickjillings@1289: count++;
nickjillings@1289: tmp.empty.add( resolve );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: resolve();
nickjillings@1289: return defer.promise( obj );
nickjillings@1289: }
nickjillings@1289: });
nickjillings@1289: var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source;
nickjillings@1289:
nickjillings@1289: var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
nickjillings@1289:
nickjillings@1289: var isHidden = function( elem, el ) {
nickjillings@1289: // isHidden might be called from jQuery#filter function;
nickjillings@1289: // in that case, element will be second argument
nickjillings@1289: elem = el || elem;
nickjillings@1289: return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem );
nickjillings@1289: };
nickjillings@1289:
nickjillings@1289: var rcheckableType = (/^(?:checkbox|radio)$/i);
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: (function() {
nickjillings@1289: var fragment = document.createDocumentFragment(),
nickjillings@1289: div = fragment.appendChild( document.createElement( "div" ) ),
nickjillings@1289: input = document.createElement( "input" );
nickjillings@1289:
nickjillings@1289: // Support: Safari<=5.1
nickjillings@1289: // Check state lost if the name is set (#11217)
nickjillings@1289: // Support: Windows Web Apps (WWA)
nickjillings@1289: // `name` and `type` must use .setAttribute for WWA (#14901)
nickjillings@1289: input.setAttribute( "type", "radio" );
nickjillings@1289: input.setAttribute( "checked", "checked" );
nickjillings@1289: input.setAttribute( "name", "t" );
nickjillings@1289:
nickjillings@1289: div.appendChild( input );
nickjillings@1289:
nickjillings@1289: // Support: Safari<=5.1, Android<4.2
nickjillings@1289: // Older WebKit doesn't clone checked state correctly in fragments
nickjillings@1289: support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
nickjillings@1289:
nickjillings@1289: // Support: IE<=11+
nickjillings@1289: // Make sure textarea (and checkbox) defaultValue is properly cloned
nickjillings@1289: div.innerHTML = "";
nickjillings@1289: support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
nickjillings@1289: })();
nickjillings@1289: var strundefined = typeof undefined;
nickjillings@1289:
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: support.focusinBubbles = "onfocusin" in window;
nickjillings@1289:
nickjillings@1289:
nickjillings@1289: var
nickjillings@1289: rkeyEvent = /^key/,
nickjillings@1289: rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/,
nickjillings@1289: rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
nickjillings@1289: rtypenamespace = /^([^.]*)(?:\.(.+)|)$/;
nickjillings@1289:
nickjillings@1289: function returnTrue() {
nickjillings@1289: return true;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function returnFalse() {
nickjillings@1289: return false;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: function safeActiveElement() {
nickjillings@1289: try {
nickjillings@1289: return document.activeElement;
nickjillings@1289: } catch ( err ) { }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: /*
nickjillings@1289: * Helper functions for managing events -- not part of the public interface.
nickjillings@1289: * Props to Dean Edwards' addEvent library for many of the ideas.
nickjillings@1289: */
nickjillings@1289: jQuery.event = {
nickjillings@1289:
nickjillings@1289: global: {},
nickjillings@1289:
nickjillings@1289: add: function( elem, types, handler, data, selector ) {
nickjillings@1289:
nickjillings@1289: var handleObjIn, eventHandle, tmp,
nickjillings@1289: events, t, handleObj,
nickjillings@1289: special, handlers, type, namespaces, origType,
nickjillings@1289: elemData = data_priv.get( elem );
nickjillings@1289:
nickjillings@1289: // Don't attach events to noData or text/comment nodes (but allow plain objects)
nickjillings@1289: if ( !elemData ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Caller can pass in an object of custom data in lieu of the handler
nickjillings@1289: if ( handler.handler ) {
nickjillings@1289: handleObjIn = handler;
nickjillings@1289: handler = handleObjIn.handler;
nickjillings@1289: selector = handleObjIn.selector;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Make sure that the handler has a unique ID, used to find/remove it later
nickjillings@1289: if ( !handler.guid ) {
nickjillings@1289: handler.guid = jQuery.guid++;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Init the element's event structure and main handler, if this is the first
nickjillings@1289: if ( !(events = elemData.events) ) {
nickjillings@1289: events = elemData.events = {};
nickjillings@1289: }
nickjillings@1289: if ( !(eventHandle = elemData.handle) ) {
nickjillings@1289: eventHandle = elemData.handle = function( e ) {
nickjillings@1289: // Discard the second event of a jQuery.event.trigger() and
nickjillings@1289: // when an event is called after a page has unloaded
nickjillings@1289: return typeof jQuery !== strundefined && jQuery.event.triggered !== e.type ?
nickjillings@1289: jQuery.event.dispatch.apply( elem, arguments ) : undefined;
nickjillings@1289: };
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Handle multiple events separated by a space
nickjillings@1289: types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1289: t = types.length;
nickjillings@1289: while ( t-- ) {
nickjillings@1289: tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1289: type = origType = tmp[1];
nickjillings@1289: namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1289:
nickjillings@1289: // There *must* be a type, no attaching namespace-only handlers
nickjillings@1289: if ( !type ) {
nickjillings@1289: continue;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // If event changes its type, use the special event handlers for the changed type
nickjillings@1289: special = jQuery.event.special[ type ] || {};
nickjillings@1289:
nickjillings@1289: // If selector defined, determine special event api type, otherwise given type
nickjillings@1289: type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1289:
nickjillings@1289: // Update special based on newly reset type
nickjillings@1289: special = jQuery.event.special[ type ] || {};
nickjillings@1289:
nickjillings@1289: // handleObj is passed to all event handlers
nickjillings@1289: handleObj = jQuery.extend({
nickjillings@1289: type: type,
nickjillings@1289: origType: origType,
nickjillings@1289: data: data,
nickjillings@1289: handler: handler,
nickjillings@1289: guid: handler.guid,
nickjillings@1289: selector: selector,
nickjillings@1289: needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
nickjillings@1289: namespace: namespaces.join(".")
nickjillings@1289: }, handleObjIn );
nickjillings@1289:
nickjillings@1289: // Init the event handler queue if we're the first
nickjillings@1289: if ( !(handlers = events[ type ]) ) {
nickjillings@1289: handlers = events[ type ] = [];
nickjillings@1289: handlers.delegateCount = 0;
nickjillings@1289:
nickjillings@1289: // Only use addEventListener if the special events handler returns false
nickjillings@1289: if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
nickjillings@1289: if ( elem.addEventListener ) {
nickjillings@1289: elem.addEventListener( type, eventHandle, false );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( special.add ) {
nickjillings@1289: special.add.call( elem, handleObj );
nickjillings@1289:
nickjillings@1289: if ( !handleObj.handler.guid ) {
nickjillings@1289: handleObj.handler.guid = handler.guid;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Add to the element's handler list, delegates in front
nickjillings@1289: if ( selector ) {
nickjillings@1289: handlers.splice( handlers.delegateCount++, 0, handleObj );
nickjillings@1289: } else {
nickjillings@1289: handlers.push( handleObj );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Keep track of which events have ever been used, for event optimization
nickjillings@1289: jQuery.event.global[ type ] = true;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: // Detach an event or set of events from an element
nickjillings@1289: remove: function( elem, types, handler, selector, mappedTypes ) {
nickjillings@1289:
nickjillings@1289: var j, origCount, tmp,
nickjillings@1289: events, t, handleObj,
nickjillings@1289: special, handlers, type, namespaces, origType,
nickjillings@1289: elemData = data_priv.hasData( elem ) && data_priv.get( elem );
nickjillings@1289:
nickjillings@1289: if ( !elemData || !(events = elemData.events) ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Once for each type.namespace in types; type may be omitted
nickjillings@1289: types = ( types || "" ).match( rnotwhite ) || [ "" ];
nickjillings@1289: t = types.length;
nickjillings@1289: while ( t-- ) {
nickjillings@1289: tmp = rtypenamespace.exec( types[t] ) || [];
nickjillings@1289: type = origType = tmp[1];
nickjillings@1289: namespaces = ( tmp[2] || "" ).split( "." ).sort();
nickjillings@1289:
nickjillings@1289: // Unbind all events (on this namespace, if provided) for the element
nickjillings@1289: if ( !type ) {
nickjillings@1289: for ( type in events ) {
nickjillings@1289: jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
nickjillings@1289: }
nickjillings@1289: continue;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: special = jQuery.event.special[ type ] || {};
nickjillings@1289: type = ( selector ? special.delegateType : special.bindType ) || type;
nickjillings@1289: handlers = events[ type ] || [];
nickjillings@1289: tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" );
nickjillings@1289:
nickjillings@1289: // Remove matching events
nickjillings@1289: origCount = j = handlers.length;
nickjillings@1289: while ( j-- ) {
nickjillings@1289: handleObj = handlers[ j ];
nickjillings@1289:
nickjillings@1289: if ( ( mappedTypes || origType === handleObj.origType ) &&
nickjillings@1289: ( !handler || handler.guid === handleObj.guid ) &&
nickjillings@1289: ( !tmp || tmp.test( handleObj.namespace ) ) &&
nickjillings@1289: ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) {
nickjillings@1289: handlers.splice( j, 1 );
nickjillings@1289:
nickjillings@1289: if ( handleObj.selector ) {
nickjillings@1289: handlers.delegateCount--;
nickjillings@1289: }
nickjillings@1289: if ( special.remove ) {
nickjillings@1289: special.remove.call( elem, handleObj );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Remove generic event handler if we removed something and no more handlers exist
nickjillings@1289: // (avoids potential for endless recursion during removal of special event handlers)
nickjillings@1289: if ( origCount && !handlers.length ) {
nickjillings@1289: if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
nickjillings@1289: jQuery.removeEvent( elem, type, elemData.handle );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: delete events[ type ];
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Remove the expando if it's no longer used
nickjillings@1289: if ( jQuery.isEmptyObject( events ) ) {
nickjillings@1289: delete elemData.handle;
nickjillings@1289: data_priv.remove( elem, "events" );
nickjillings@1289: }
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: trigger: function( event, data, elem, onlyHandlers ) {
nickjillings@1289:
nickjillings@1289: var i, cur, tmp, bubbleType, ontype, handle, special,
nickjillings@1289: eventPath = [ elem || document ],
nickjillings@1289: type = hasOwn.call( event, "type" ) ? event.type : event,
nickjillings@1289: namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : [];
nickjillings@1289:
nickjillings@1289: cur = tmp = elem = elem || document;
nickjillings@1289:
nickjillings@1289: // Don't do events on text and comment nodes
nickjillings@1289: if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // focus/blur morphs to focusin/out; ensure we're not firing them right now
nickjillings@1289: if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: if ( type.indexOf(".") >= 0 ) {
nickjillings@1289: // Namespaced trigger; create a regexp to match event type in handle()
nickjillings@1289: namespaces = type.split(".");
nickjillings@1289: type = namespaces.shift();
nickjillings@1289: namespaces.sort();
nickjillings@1289: }
nickjillings@1289: ontype = type.indexOf(":") < 0 && "on" + type;
nickjillings@1289:
nickjillings@1289: // Caller can pass in a jQuery.Event object, Object, or just an event type string
nickjillings@1289: event = event[ jQuery.expando ] ?
nickjillings@1289: event :
nickjillings@1289: new jQuery.Event( type, typeof event === "object" && event );
nickjillings@1289:
nickjillings@1289: // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
nickjillings@1289: event.isTrigger = onlyHandlers ? 2 : 3;
nickjillings@1289: event.namespace = namespaces.join(".");
nickjillings@1289: event.namespace_re = event.namespace ?
nickjillings@1289: new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) :
nickjillings@1289: null;
nickjillings@1289:
nickjillings@1289: // Clean up the event in case it is being reused
nickjillings@1289: event.result = undefined;
nickjillings@1289: if ( !event.target ) {
nickjillings@1289: event.target = elem;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Clone any incoming data and prepend the event, creating the handler arg list
nickjillings@1289: data = data == null ?
nickjillings@1289: [ event ] :
nickjillings@1289: jQuery.makeArray( data, [ event ] );
nickjillings@1289:
nickjillings@1289: // Allow special events to draw outside the lines
nickjillings@1289: special = jQuery.event.special[ type ] || {};
nickjillings@1289: if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Determine event propagation path in advance, per W3C events spec (#9951)
nickjillings@1289: // Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
nickjillings@1289: if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
nickjillings@1289:
nickjillings@1289: bubbleType = special.delegateType || type;
nickjillings@1289: if ( !rfocusMorph.test( bubbleType + type ) ) {
nickjillings@1289: cur = cur.parentNode;
nickjillings@1289: }
nickjillings@1289: for ( ; cur; cur = cur.parentNode ) {
nickjillings@1289: eventPath.push( cur );
nickjillings@1289: tmp = cur;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Only add window if we got to document (e.g., not plain obj or detached DOM)
nickjillings@1289: if ( tmp === (elem.ownerDocument || document) ) {
nickjillings@1289: eventPath.push( tmp.defaultView || tmp.parentWindow || window );
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Fire handlers on the event path
nickjillings@1289: i = 0;
nickjillings@1289: while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) {
nickjillings@1289:
nickjillings@1289: event.type = i > 1 ?
nickjillings@1289: bubbleType :
nickjillings@1289: special.bindType || type;
nickjillings@1289:
nickjillings@1289: // jQuery handler
nickjillings@1289: handle = ( data_priv.get( cur, "events" ) || {} )[ event.type ] && data_priv.get( cur, "handle" );
nickjillings@1289: if ( handle ) {
nickjillings@1289: handle.apply( cur, data );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Native handler
nickjillings@1289: handle = ontype && cur[ ontype ];
nickjillings@1289: if ( handle && handle.apply && jQuery.acceptData( cur ) ) {
nickjillings@1289: event.result = handle.apply( cur, data );
nickjillings@1289: if ( event.result === false ) {
nickjillings@1289: event.preventDefault();
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: event.type = type;
nickjillings@1289:
nickjillings@1289: // If nobody prevented the default action, do it now
nickjillings@1289: if ( !onlyHandlers && !event.isDefaultPrevented() ) {
nickjillings@1289:
nickjillings@1289: if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) &&
nickjillings@1289: jQuery.acceptData( elem ) ) {
nickjillings@1289:
nickjillings@1289: // Call a native DOM method on the target with the same name name as the event.
nickjillings@1289: // Don't do default actions on window, that's where global variables be (#6170)
nickjillings@1289: if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
nickjillings@1289:
nickjillings@1289: // Don't re-trigger an onFOO event when we call its FOO() method
nickjillings@1289: tmp = elem[ ontype ];
nickjillings@1289:
nickjillings@1289: if ( tmp ) {
nickjillings@1289: elem[ ontype ] = null;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Prevent re-triggering of the same event, since we already bubbled it above
nickjillings@1289: jQuery.event.triggered = type;
nickjillings@1289: elem[ type ]();
nickjillings@1289: jQuery.event.triggered = undefined;
nickjillings@1289:
nickjillings@1289: if ( tmp ) {
nickjillings@1289: elem[ ontype ] = tmp;
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return event.result;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: dispatch: function( event ) {
nickjillings@1289:
nickjillings@1289: // Make a writable jQuery.Event from the native event object
nickjillings@1289: event = jQuery.event.fix( event );
nickjillings@1289:
nickjillings@1289: var i, j, ret, matched, handleObj,
nickjillings@1289: handlerQueue = [],
nickjillings@1289: args = slice.call( arguments ),
nickjillings@1289: handlers = ( data_priv.get( this, "events" ) || {} )[ event.type ] || [],
nickjillings@1289: special = jQuery.event.special[ event.type ] || {};
nickjillings@1289:
nickjillings@1289: // Use the fix-ed jQuery.Event rather than the (read-only) native event
nickjillings@1289: args[0] = event;
nickjillings@1289: event.delegateTarget = this;
nickjillings@1289:
nickjillings@1289: // Call the preDispatch hook for the mapped type, and let it bail if desired
nickjillings@1289: if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
nickjillings@1289: return;
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Determine handlers
nickjillings@1289: handlerQueue = jQuery.event.handlers.call( this, event, handlers );
nickjillings@1289:
nickjillings@1289: // Run delegates first; they may want to stop propagation beneath us
nickjillings@1289: i = 0;
nickjillings@1289: while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) {
nickjillings@1289: event.currentTarget = matched.elem;
nickjillings@1289:
nickjillings@1289: j = 0;
nickjillings@1289: while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) {
nickjillings@1289:
nickjillings@1289: // Triggered event must either 1) have no namespace, or 2) have namespace(s)
nickjillings@1289: // a subset or equal to those in the bound event (both can have no namespace).
nickjillings@1289: if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) {
nickjillings@1289:
nickjillings@1289: event.handleObj = handleObj;
nickjillings@1289: event.data = handleObj.data;
nickjillings@1289:
nickjillings@1289: ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
nickjillings@1289: .apply( matched.elem, args );
nickjillings@1289:
nickjillings@1289: if ( ret !== undefined ) {
nickjillings@1289: if ( (event.result = ret) === false ) {
nickjillings@1289: event.preventDefault();
nickjillings@1289: event.stopPropagation();
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: // Call the postDispatch hook for the mapped type
nickjillings@1289: if ( special.postDispatch ) {
nickjillings@1289: special.postDispatch.call( this, event );
nickjillings@1289: }
nickjillings@1289:
nickjillings@1289: return event.result;
nickjillings@1289: },
nickjillings@1289:
nickjillings@1289: handlers: function( event, handlers ) {
nickjillings@1289: var i, matches, sel, handleObj,
nickjillings@1289: handlerQueue = [],
nickjillings@1289: delegateCount = handlers.delegateCount,
nickjillings@1289: cur = event.target;
nickjillings@1289:
nickjillings@1289: // Find delegate handlers
nickjillings@1289: // Black-hole SVG