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