// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
- return new jQuery.fn.init( selector, context );
+ return new jQuery.fn.init( selector, context, rootjQuery );
},
// Map over jQuery in case of overwrite
// (both of which we optimize for)
quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]+)$)/,
- // Is it a simple selector
- isSimple = /^.[^:#\[\.,]*$/,
-
// Check if a string has a non-whitespace character in it
rnotwhite = /\S/,
- rwhite = /\s/,
// Used for trimming whitespace
trimLeft = /^\s+/,
trimRight = /\s+$/,
- // Check for non-word characters
- rnonword = /\W/,
-
// Check for digits
rdigit = /\d/,
// For matching the engine and version of the browser
browserMatch,
-
- // Has the ready events already been bound?
- readyBound = false,
-
+
// The deferred used on DOM ready
readyList,
slice = Array.prototype.slice,
trim = String.prototype.trim,
indexOf = Array.prototype.indexOf,
-
+
// [[Class]] -> type pairs
- class2type = {},
-
- // Marker for deferred
- deferredMarker = [];
+ class2type = {};
jQuery.fn = jQuery.prototype = {
- init: function( selector, context ) {
+ constructor: jQuery,
+ init: function( selector, context, rootjQuery ) {
var match, elem, ret, doc;
// Handle $(""), $(null), or $(undefined)
this.length = 1;
return this;
}
-
+
// The body element only exists once, optimize finding it
if ( selector === "body" && !context && document.body ) {
this.context = document;
// HANDLE: $(html) -> $(array)
if ( match[1] ) {
+ context = context instanceof jQuery ? context[0] : context;
doc = (context ? context.ownerDocument || context : document);
// If a single string is passed in and it's a single tag
} else {
ret = jQuery.buildFragment( [ match[1] ], [ doc ] );
- selector = (ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
+ selector = (ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes;
}
-
+
return jQuery.merge( this, selector );
-
+
// HANDLE: $("#id")
} else {
elem = document.getElementById( match[2] );
return this;
}
- // HANDLE: $("TAG")
- } else if ( !context && !rnonword.test( selector ) ) {
- this.selector = selector;
- this.context = document;
- selector = document.getElementsByTagName( selector );
- return jQuery.merge( this, selector );
-
// HANDLE: $(expr, $(...))
} else if ( !context || context.jquery ) {
return (context || rootjQuery).find( selector );
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
} else {
- return jQuery( context ).find( selector );
+ return this.constructor( context ).find( selector );
}
// HANDLE: $(function)
// (returning the new matched element set)
pushStack: function( elems, name, selector ) {
// Build a new jQuery matched element set
- var ret = jQuery();
+ var ret = this.constructor();
if ( jQuery.isArray( elems ) ) {
push.apply( ret, elems );
-
+
} else {
jQuery.merge( ret, elems );
}
each: function( callback, args ) {
return jQuery.each( this, callback, args );
},
-
- ready: function() {
+
+ ready: function( fn ) {
// Attach the listeners
jQuery.bindReady();
-
- // Change ready & apply
- return ( jQuery.fn.ready = readyList.then ).apply( this , arguments );
+
+ // Add the callback
+ readyList.done( fn );
+
+ return this;
},
-
+
eq: function( i ) {
return i === -1 ?
this.slice( i ) :
return callback.call( elem, i, elem );
}));
},
-
+
end: function() {
- return this.prevObject || jQuery(null);
+ return this.prevObject || this.constructor(null);
},
// For internal use only.
jQuery.fn.init.prototype = jQuery.fn;
jQuery.extend = jQuery.fn.extend = function() {
- var options, name, src, copy, copyIsArray, clone,
+ var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
return jQuery;
},
-
+
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
// A counter to track how many items to wait for before
// the ready event fires. See #6781
readyWait: 1,
-
+
// Handle when the DOM is ready
ready: function( wait ) {
// A third-party is pushing the ready event forwards
}
// If there are functions bound, to execute
- readyList.fire( document , [ jQuery ] );
-
+ readyList.resolveWith( document, [ jQuery ] );
+
// Trigger any bound ready events
if ( jQuery.fn.trigger ) {
jQuery( document ).trigger( "ready" ).unbind( "ready" );
}
}
},
-
+
bindReady: function() {
- if ( readyBound ) {
+ if ( readyList ) {
return;
}
- readyBound = true;
+ readyList = jQuery._Deferred();
// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
-
+
// A fallback to window.onload, that will always work
window.addEventListener( "load", jQuery.ready, false );
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent("onreadystatechange", DOMContentLoaded);
-
+
// A fallback to window.onload, that will always work
window.attachEvent( "onload", jQuery.ready );
if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
return false;
}
-
+
// Not own constructor property must be Object
if ( obj.constructor &&
!hasOwn.call(obj, "constructor") &&
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
return false;
}
-
+
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
-
+
var key;
for ( key in obj ) {}
-
+
return key === undefined || hasOwn.call( obj, key );
},
}
return true;
},
-
+
error: function( msg ) {
throw msg;
},
-
+
parseJSON: function( data ) {
if ( typeof data !== "string" || !data ) {
return null;
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim( data );
-
+
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if ( rvalidchars.test(data.replace(rvalidescape, "@")
}
},
+ // Cross-browser xml parsing
+ // (xml & tmp used internally)
+ parseXML: function( data , xml , tmp ) {
+
+ if ( window.DOMParser ) { // Standard
+ tmp = new DOMParser();
+ xml = tmp.parseFromString( data , "text/xml" );
+ } else { // IE
+ xml = new ActiveXObject( "Microsoft.XMLDOM" );
+ xml.async = "false";
+ xml.loadXML( data );
+ }
+
+ tmp = xml.documentElement;
+
+ if ( ! tmp || ! tmp.nodeName || tmp.nodeName === "parsererror" ) {
+ jQuery.error( "Invalid XML: " + data );
+ }
+
+ return xml;
+ },
+
noop: function() {},
// Evalulates a script in a global context
if ( data && rnotwhite.test(data) ) {
// Inspired by code by Andrea Giammarchi
// http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
- var head = document.getElementsByTagName("head")[0] || document.documentElement,
- script = document.createElement("script");
+ var head = document.head || document.getElementsByTagName( "head" )[0] || document.documentElement,
+ script = document.createElement( "script" );
- script.type = "text/javascript";
-
- if ( jQuery.support.scriptEval ) {
+ if ( jQuery.support.scriptEval() ) {
script.appendChild( document.createTextNode( data ) );
} else {
script.text = data;
for ( var l = second.length; j < l; j++ ) {
first[ i++ ] = second[ j ];
}
-
+
} else {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
// The value/s can be optionally by executed if its a function
access: function( elems, key, value, exec, fn, pass ) {
var length = elems.length;
-
+
// Setting many attributes
if ( typeof key === "object" ) {
for ( var k in key ) {
}
return elems;
}
-
+
// Setting one attribute
if ( value !== undefined ) {
// Optionally, function values get executed if exec is true
exec = !pass && exec && jQuery.isFunction(value);
-
+
for ( var i = 0; i < length; i++ ) {
fn( elems[i], key, exec ? value.call( elems[i], i, fn( elems[i], key ) ) : value, pass );
}
-
+
return elems;
}
-
+
// Getting an attribute
return length ? fn( elems[0], key ) : undefined;
},
now: function() {
return (new Date()).getTime();
},
-
- // Create a simple deferred (one callbacks list)
- _deferred: function( cancellable ) {
-
- // cancellable by default
- cancellable = cancellable !== false;
-
- var // callbacks list
- callbacks = [],
- // stored [ context , args ]
- fired,
- // to avoid firing when already doing so
- firing,
- // flag to know if the deferred has been cancelled
- cancelled,
- // the deferred itself
- deferred = {
-
- // then( f1, f2, ...)
- then: function() {
-
- if ( ! cancelled ) {
-
- var args = arguments,
- i,
- type,
- _fired;
-
- if ( fired ) {
- _fired = fired;
- fired = 0;
- }
-
- for ( i in args ) {
- i = args[ i ];
- type = jQuery.type( i );
- if ( type === "array" ) {
- this.then.apply( this , i );
- } else if ( type === "function" ) {
- callbacks.push( i );
- }
- }
-
- if ( _fired ) {
- deferred.fire( _fired[ 0 ] , _fired[ 1 ] );
- }
- }
- return this;
- },
-
- // resolve with given context and args
- // (i is used internally)
- fire: function( context , args , i ) {
- if ( ! cancelled && ! fired && ! firing ) {
- firing = 1;
- try {
- for( i = 0 ; ! cancelled && callbacks[ i ] ; i++ ) {
- cancelled = ( callbacks[ i ].apply( context , args ) === false ) && cancellable;
- }
- } catch( e ) {
- cancelled = cancellable;
- jQuery.error( e );
- } finally {
- fired = [ context , args ];
- callbacks = cancelled ? [] : callbacks.slice( i + 1 );
- firing = 0;
- }
- }
- return this;
- },
-
- // resolve with this as context and given arguments
- resolve: function() {
- deferred.fire( this , arguments );
- return this;
- },
-
- // cancelling further callbacks
- cancel: function() {
- if ( cancellable ) {
- callbacks = [];
- cancelled = 1;
- }
- return this;
- }
-
- };
-
- // Add the deferred marker
- deferred.then._ = deferredMarker;
-
- return deferred;
- },
-
- // Full fledged deferred (two callbacks list)
- // Typical success/error system
- deferred: function( func , cancellable ) {
-
- // Handle varargs
- if ( arguments.length === 1 ) {
-
- if ( typeof func === "boolean" ) {
- cancellable = func;
- func = 0;
- }
- }
-
- var errorDeferred = jQuery._deferred( cancellable ),
- deferred = jQuery._deferred( cancellable ),
- // Keep reference of the cancel method since we'll redefine it
- cancelThen = deferred.cancel;
-
- // Add errorDeferred methods and redefine cancel
- jQuery.extend( deferred , {
-
- fail: errorDeferred.then,
- fireReject: errorDeferred.fire,
- reject: errorDeferred.resolve,
- cancel: function() {
- cancelThen();
- errorDeferred.cancel();
- return this;
- }
-
- } );
-
- // Make sure only one callback list will be used
- deferred.then( errorDeferred.cancel ).fail( cancelThen );
-
- // Call given func if any
- if ( func ) {
- func.call( deferred , deferred );
- }
-
- return deferred;
- },
-
- // Check if an object is a deferred
- isDeferred: function( object , method ) {
- method = method || "then";
- return !!( object && object[ method ] && object[ method ]._ === deferredMarker );
- },
-
- // Deferred helper
- when: function( object , method ) {
- method = method || "then";
- object = jQuery.isDeferred( object , method ) ?
- object :
- jQuery.deferred().resolve( object );
- object.fail = object.fail || function() { return this; };
- object[ method ] = object[ method ] || object.then;
- object.then = object.then || object[ method ];
- return object;
- },
// Use of jQuery.browser is frowned upon.
// More details: http://docs.jquery.com/Utilities/jQuery.browser
return { browser: match[1] || "", version: match[2] || "0" };
},
+ sub: function() {
+ function jQuerySubclass( selector, context ) {
+ return new jQuerySubclass.fn.init( selector, context );
+ }
+ jQuery.extend( true, jQuerySubclass, this );
+ jQuerySubclass.superclass = this;
+ jQuerySubclass.fn = jQuerySubclass.prototype = this();
+ jQuerySubclass.fn.constructor = jQuerySubclass;
+ jQuerySubclass.subclass = this.subclass;
+ jQuerySubclass.fn.init = function init( selector, context ) {
+ if ( context && context instanceof jQuery && !(context instanceof jQuerySubclass) ) {
+ context = jQuerySubclass(context);
+ }
+
+ return jQuery.fn.init.call( this, selector, context, rootjQuerySubclass );
+ };
+ jQuerySubclass.fn.init.prototype = jQuerySubclass.fn;
+ var rootjQuerySubclass = jQuerySubclass(document);
+ return jQuerySubclass;
+ },
+
browser: {}
});
-// Create readyList deferred
-// also force $.fn.ready to be recognized as a defer
-readyList = jQuery._deferred( false );
-jQuery.fn.ready._ = deferredMarker;
-
// Populate the class2type map
jQuery.each("Boolean Number String Function Array Date RegExp Object".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
};
}
-// Verify that \s matches non-breaking spaces
-// (IE fails on this test)
-if ( !rwhite.test( "\xA0" ) ) {
+// IE doesn't match non-breaking spaces with \s
+if ( rnotwhite.test( "\xA0" ) ) {
trimLeft = /^[\s\xA0]+/;
trimRight = /[\s\xA0]+$/;
}
}
// Expose jQuery to the global object
-return (window.jQuery = window.$ = jQuery);
+return jQuery;
})();