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