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