2009-01-04 22:25:46 +00:00
|
|
|
var
|
|
|
|
// Will speed up references to window, and allows munging its name.
|
|
|
|
window = this,
|
|
|
|
// Will speed up references to undefined, and allows munging its name.
|
|
|
|
undefined,
|
|
|
|
// Map over jQuery in case of overwrite
|
|
|
|
_jQuery = window.jQuery,
|
|
|
|
// Map over the $ in case of overwrite
|
|
|
|
_$ = window.$,
|
|
|
|
|
|
|
|
jQuery = window.jQuery = window.$ = function( selector, context ) {
|
|
|
|
// The jQuery object is actually just the init constructor 'enhanced'
|
2009-02-25 14:23:25 +00:00
|
|
|
return selector === undefined ?
|
|
|
|
rootjQuery :
|
|
|
|
new jQuery.fn.init( selector, context );
|
2009-01-04 22:25:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// A simple way to check for HTML strings or ID strings
|
|
|
|
// (both of which we optimize for)
|
|
|
|
quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
|
|
|
|
// Is it a simple selector
|
|
|
|
isSimple = /^.[^:#\[\.,]*$/;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
jQuery.fn = jQuery.prototype = {
|
|
|
|
init: function( selector, context ) {
|
2009-02-25 14:23:25 +00:00
|
|
|
// Handle $("") or $(null)
|
2009-02-25 04:57:00 +00:00
|
|
|
if ( !selector ) {
|
|
|
|
this.length = 0;
|
|
|
|
return this;
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Handle $(DOMElement)
|
|
|
|
if ( selector.nodeType ) {
|
|
|
|
this[0] = selector;
|
|
|
|
this.length = 1;
|
2008-12-19 04:37:10 +00:00
|
|
|
this.context = selector;
|
2008-01-14 22:30:48 +00:00
|
|
|
return this;
|
2008-05-06 22:36:30 +00:00
|
|
|
}
|
2009-02-25 04:57:00 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Handle HTML strings
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof selector === "string" ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
// Are we dealing with HTML string or an ID?
|
|
|
|
var match = quickExpr.exec( selector );
|
|
|
|
|
|
|
|
// Verify a match, and that no context was specified for #id
|
|
|
|
if ( match && (match[1] || !context) ) {
|
|
|
|
|
|
|
|
// HANDLE: $(html) -> $(array)
|
2009-02-25 04:57:00 +00:00
|
|
|
if ( match[1] ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
selector = jQuery.clean( [ match[1] ], context );
|
|
|
|
|
|
|
|
// HANDLE: $("#id")
|
2009-02-25 04:57:00 +00:00
|
|
|
} else {
|
2008-01-14 22:30:48 +00:00
|
|
|
var elem = document.getElementById( match[3] );
|
|
|
|
|
2009-01-20 16:00:48 +00:00
|
|
|
// Handle the case where IE and Opera return items
|
|
|
|
// by name instead of ID
|
2009-02-25 04:57:00 +00:00
|
|
|
if ( elem && elem.id != match[3] ) {
|
2009-02-25 14:23:25 +00:00
|
|
|
return rootjQuery.find( selector );
|
2009-02-25 04:57:00 +00:00
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2009-01-20 16:00:48 +00:00
|
|
|
// Otherwise, we inject the element directly into the jQuery object
|
2009-02-25 14:23:25 +00:00
|
|
|
var ret = jQuery( elem || null );
|
2009-01-20 16:00:48 +00:00
|
|
|
ret.context = document;
|
|
|
|
ret.selector = selector;
|
|
|
|
return ret;
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
|
2009-02-25 14:23:25 +00:00
|
|
|
// HANDLE: $(expr, $(...))
|
|
|
|
} else if ( !context || context.jquery ) {
|
|
|
|
return (context || rootjQuery).find( selector );
|
2009-02-25 04:57:00 +00:00
|
|
|
|
2009-02-25 14:23:25 +00:00
|
|
|
// HANDLE: $(expr, context)
|
2009-03-05 13:36:12 +00:00
|
|
|
// (which is just equivalent to: $(context).find(expr)
|
2009-02-25 04:57:00 +00:00
|
|
|
} else {
|
2009-02-25 14:23:25 +00:00
|
|
|
return jQuery( context ).find( selector );
|
2009-02-25 04:57:00 +00:00
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// HANDLE: $(function)
|
|
|
|
// Shortcut for document ready
|
2009-02-25 04:57:00 +00:00
|
|
|
} else if ( jQuery.isFunction( selector ) ) {
|
2009-02-25 14:23:25 +00:00
|
|
|
return rootjQuery.ready( selector );
|
2009-02-25 04:57:00 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-01-08 21:41:58 +00:00
|
|
|
// Make sure that old selector state is passed along
|
|
|
|
if ( selector.selector && selector.context ) {
|
|
|
|
this.selector = selector.selector;
|
|
|
|
this.context = selector.context;
|
|
|
|
}
|
|
|
|
|
2009-02-14 18:10:45 +00:00
|
|
|
return this.setArray(jQuery.isArray( selector ) ?
|
|
|
|
selector :
|
|
|
|
jQuery.makeArray(selector));
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-12-19 04:37:10 +00:00
|
|
|
// Start with an empty selector
|
|
|
|
selector: "",
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// The current version of jQuery being used
|
|
|
|
jquery: "@VERSION",
|
|
|
|
|
|
|
|
// The number of elements contained in the matched element set
|
|
|
|
size: function() {
|
|
|
|
return this.length;
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Get the Nth element in the matched element set OR
|
|
|
|
// Get the whole matched element set as a clean array
|
|
|
|
get: function( num ) {
|
2008-11-17 16:32:05 +00:00
|
|
|
return num === undefined ?
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Return a 'clean' array
|
2009-02-14 18:10:45 +00:00
|
|
|
Array.prototype.slice.call( this ) :
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Return just the object
|
|
|
|
this[ num ];
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Take an array of elements and push it onto the stack
|
|
|
|
// (returning the new matched element set)
|
2008-12-19 04:37:10 +00:00
|
|
|
pushStack: function( elems, name, selector ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
// Build a new jQuery matched element set
|
2009-02-25 14:23:25 +00:00
|
|
|
var ret = jQuery( elems || null );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Add the old object onto the stack (as a reference)
|
|
|
|
ret.prevObject = this;
|
|
|
|
|
2008-12-19 04:37:10 +00:00
|
|
|
ret.context = this.context;
|
|
|
|
|
|
|
|
if ( name === "find" )
|
|
|
|
ret.selector = this.selector + (this.selector ? " " : "") + selector;
|
|
|
|
else if ( name )
|
|
|
|
ret.selector = this.selector + "." + name + "(" + selector + ")";
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Return the newly-formed element set
|
|
|
|
return ret;
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Force the current matched set of elements to become
|
|
|
|
// the specified array of elements (destroying the stack in the process)
|
|
|
|
// You should use pushStack() in order to do this, but maintain the stack
|
|
|
|
setArray: function( elems ) {
|
|
|
|
// Resetting the length to 0, then using the native Array push
|
|
|
|
// is a super-fast way to populate an object with array-like properties
|
|
|
|
this.length = 0;
|
|
|
|
Array.prototype.push.apply( this, elems );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Execute a callback for every element in the matched set.
|
|
|
|
// (You can seed the arguments with an array of args, but this is
|
|
|
|
// only used internally.)
|
|
|
|
each: function( callback, args ) {
|
|
|
|
return jQuery.each( this, callback, args );
|
|
|
|
},
|
|
|
|
|
2008-05-13 01:45:58 +00:00
|
|
|
// Determine the position of an element within
|
2008-01-14 22:30:48 +00:00
|
|
|
// the matched set of elements
|
|
|
|
index: function( elem ) {
|
|
|
|
// Locate the position of the desired element
|
2008-05-13 01:45:58 +00:00
|
|
|
return jQuery.inArray(
|
2008-05-08 16:14:49 +00:00
|
|
|
// If it receives a jQuery object, the first element is used
|
|
|
|
elem && elem.jquery ? elem[0] : elem
|
|
|
|
, this );
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
attr: function( name, value, type ) {
|
2009-02-28 20:23:48 +00:00
|
|
|
var options = name, isFunction = jQuery.isFunction( value );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Look for the case where we're accessing a style value
|
2009-02-28 20:23:48 +00:00
|
|
|
if ( typeof name === "string" ) {
|
|
|
|
if ( value === undefined ) {
|
|
|
|
return this.length ?
|
|
|
|
jQuery[ type || "attr" ]( this[0], name ) :
|
|
|
|
null;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2009-02-28 20:23:48 +00:00
|
|
|
} else {
|
2008-01-14 22:30:48 +00:00
|
|
|
options = {};
|
|
|
|
options[ name ] = value;
|
|
|
|
}
|
2009-02-28 20:23:48 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Check to see if we're setting style values
|
2009-02-28 20:23:48 +00:00
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
var elem = this[i];
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Set all the styles
|
2009-02-28 20:23:48 +00:00
|
|
|
for ( var prop in options ) {
|
|
|
|
value = options[prop];
|
|
|
|
|
|
|
|
if ( isFunction ) {
|
|
|
|
value = value.call( elem, i );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( typeof value === "number" && type === "curCSS" && !exclude.test(prop) ) {
|
|
|
|
value = value + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.attr( type ? elem.style : elem, prop, value );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
css: function( key, value ) {
|
|
|
|
// ignore negative width and height values
|
|
|
|
if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
|
|
|
|
value = undefined;
|
|
|
|
return this.attr( key, value, "curCSS" );
|
|
|
|
},
|
|
|
|
|
|
|
|
text: function( text ) {
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof text !== "object" && text != null )
|
2008-01-14 22:30:48 +00:00
|
|
|
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
|
|
|
|
|
|
|
|
var ret = "";
|
|
|
|
|
|
|
|
jQuery.each( text || this, function(){
|
|
|
|
jQuery.each( this.childNodes, function(){
|
|
|
|
if ( this.nodeType != 8 )
|
|
|
|
ret += this.nodeType != 1 ?
|
|
|
|
this.nodeValue :
|
|
|
|
jQuery.fn.text( [ this ] );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
wrapAll: function( html ) {
|
2009-01-12 14:07:14 +00:00
|
|
|
if ( this[0] ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
// The elements to wrap the target around
|
2009-01-12 14:07:14 +00:00
|
|
|
var wrap = jQuery( html, this[0].ownerDocument ).clone();
|
|
|
|
|
|
|
|
if ( this[0].parentNode )
|
|
|
|
wrap.insertBefore( this[0] );
|
|
|
|
|
|
|
|
wrap.map(function(){
|
|
|
|
var elem = this;
|
|
|
|
|
|
|
|
while ( elem.firstChild )
|
|
|
|
elem = elem.firstChild;
|
|
|
|
|
|
|
|
return elem;
|
|
|
|
}).append(this);
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
wrapInner: function( html ) {
|
|
|
|
return this.each(function(){
|
|
|
|
jQuery( this ).contents().wrapAll( html );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
wrap: function( html ) {
|
|
|
|
return this.each(function(){
|
|
|
|
jQuery( this ).wrapAll( html );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
append: function() {
|
2008-12-19 04:37:54 +00:00
|
|
|
return this.domManip(arguments, true, function(elem){
|
2008-01-14 22:30:48 +00:00
|
|
|
if (this.nodeType == 1)
|
|
|
|
this.appendChild( elem );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
prepend: function() {
|
2008-12-19 04:37:54 +00:00
|
|
|
return this.domManip(arguments, true, function(elem){
|
2008-01-14 22:30:48 +00:00
|
|
|
if (this.nodeType == 1)
|
|
|
|
this.insertBefore( elem, this.firstChild );
|
|
|
|
});
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
before: function() {
|
2008-12-19 04:37:54 +00:00
|
|
|
return this.domManip(arguments, false, function(elem){
|
2008-01-14 22:30:48 +00:00
|
|
|
this.parentNode.insertBefore( elem, this );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
after: function() {
|
2008-12-19 04:37:54 +00:00
|
|
|
return this.domManip(arguments, false, function(elem){
|
2008-01-14 22:30:48 +00:00
|
|
|
this.parentNode.insertBefore( elem, this.nextSibling );
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
end: function() {
|
2009-02-25 14:23:25 +00:00
|
|
|
return this.prevObject || jQuery(null);
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
2009-03-17 20:39:29 +00:00
|
|
|
// For internal use only.
|
|
|
|
// Behaves like an Array's method, not like a jQuery method.
|
|
|
|
push: [].push,
|
|
|
|
sort: [].sort,
|
|
|
|
splice: [].splice,
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
find: function( selector ) {
|
2009-03-17 20:39:29 +00:00
|
|
|
var ret = this.pushStack( "", "find", selector ), length = 0;
|
2009-02-25 18:29:18 +00:00
|
|
|
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
length = ret.length;
|
|
|
|
jQuery.find( selector, this[i], ret );
|
|
|
|
|
|
|
|
if ( i > 0 ) {
|
|
|
|
// Make sure that the results are unique
|
|
|
|
for ( var n = length; n < ret.length; n++ ) {
|
|
|
|
for ( var r = 0; r < length; r++ ) {
|
|
|
|
if ( ret[r] === ret[n] ) {
|
2009-03-17 20:39:29 +00:00
|
|
|
ret.splice(n--, 1);
|
2009-02-25 18:29:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-25 15:37:09 +00:00
|
|
|
}
|
2009-01-06 16:17:50 +00:00
|
|
|
}
|
2009-02-25 18:29:18 +00:00
|
|
|
|
|
|
|
return ret;
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
clone: function( events ) {
|
|
|
|
// Do the clone
|
|
|
|
var ret = this.map(function(){
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
// IE copies events bound via attachEvent when
|
|
|
|
// using cloneNode. Calling detachEvent on the
|
|
|
|
// clone will also remove the events from the orignal
|
|
|
|
// In order to get around this, we use innerHTML.
|
2008-05-13 01:45:58 +00:00
|
|
|
// Unfortunately, this means some modifications to
|
|
|
|
// attributes in IE that are actually only stored
|
2008-01-14 22:30:48 +00:00
|
|
|
// as properties will not be copied (such as the
|
|
|
|
// the name attribute on an input).
|
2009-02-09 14:48:15 +00:00
|
|
|
var html = this.outerHTML;
|
|
|
|
if ( !html ) {
|
|
|
|
var div = this.ownerDocument.createElement("div");
|
|
|
|
div.appendChild( this.cloneNode(true) );
|
|
|
|
html = div.innerHTML;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")])[0];
|
2008-01-14 22:30:48 +00:00
|
|
|
} else
|
|
|
|
return this.cloneNode(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Copy the events from the original to the clone
|
2009-02-09 14:48:15 +00:00
|
|
|
if ( events === true ) {
|
|
|
|
var orig = this.find("*").andSelf(), i = 0;
|
|
|
|
|
|
|
|
ret.find("*").andSelf().each(function(){
|
|
|
|
if ( this.nodeName !== orig[i].nodeName )
|
2008-01-14 22:30:48 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-09 14:48:15 +00:00
|
|
|
var events = jQuery.data( orig[i], "events" );
|
|
|
|
|
|
|
|
for ( var type in events ) {
|
|
|
|
for ( var handler in events[ type ] ) {
|
|
|
|
jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
2008-01-14 22:30:48 +00:00
|
|
|
});
|
2009-02-09 14:48:15 +00:00
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Return the cloned set
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
filter: function( selector ) {
|
|
|
|
return this.pushStack(
|
|
|
|
jQuery.isFunction( selector ) &&
|
|
|
|
jQuery.grep(this, function(elem, i){
|
|
|
|
return selector.call( elem, i );
|
|
|
|
}) ||
|
|
|
|
|
2008-12-20 01:19:17 +00:00
|
|
|
jQuery.multiFilter( selector, jQuery.grep(this, function(elem){
|
|
|
|
return elem.nodeType === 1;
|
|
|
|
}) ), "filter", selector );
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
2008-12-22 00:52:53 +00:00
|
|
|
closest: function( selector ) {
|
2009-02-09 23:29:57 +00:00
|
|
|
var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
|
|
|
|
closer = 0;
|
2009-01-10 20:30:03 +00:00
|
|
|
|
2008-12-22 00:52:53 +00:00
|
|
|
return this.map(function(){
|
|
|
|
var cur = this;
|
|
|
|
while ( cur && cur.ownerDocument ) {
|
2009-02-09 23:29:57 +00:00
|
|
|
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
|
|
|
|
jQuery.data(cur, "closest", closer);
|
2008-12-22 00:52:53 +00:00
|
|
|
return cur;
|
2009-02-09 23:29:57 +00:00
|
|
|
}
|
2008-12-22 00:52:53 +00:00
|
|
|
cur = cur.parentNode;
|
2009-02-09 23:29:57 +00:00
|
|
|
closer++;
|
2008-12-22 00:52:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
not: function( selector ) {
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof selector === "string" )
|
2008-01-14 22:30:48 +00:00
|
|
|
// test special case where just one selector is passed in
|
|
|
|
if ( isSimple.test( selector ) )
|
2008-12-19 04:37:10 +00:00
|
|
|
return this.pushStack( jQuery.multiFilter( selector, this, true ), "not", selector );
|
2008-01-14 22:30:48 +00:00
|
|
|
else
|
|
|
|
selector = jQuery.multiFilter( selector, this );
|
|
|
|
|
|
|
|
var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;
|
|
|
|
return this.filter(function() {
|
|
|
|
return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
add: function( selector ) {
|
2008-05-13 01:45:58 +00:00
|
|
|
return this.pushStack( jQuery.unique( jQuery.merge(
|
2008-01-14 22:30:48 +00:00
|
|
|
this.get(),
|
2008-11-17 16:32:05 +00:00
|
|
|
typeof selector === "string" ?
|
2008-05-08 17:08:59 +00:00
|
|
|
jQuery( selector ) :
|
|
|
|
jQuery.makeArray( selector )
|
|
|
|
)));
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
is: function( selector ) {
|
2008-04-29 23:34:50 +00:00
|
|
|
return !!selector && jQuery.multiFilter( selector, this ).length > 0;
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hasClass: function( selector ) {
|
2008-12-16 00:02:17 +00:00
|
|
|
return !!selector && this.is( "." + selector );
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
val: function( value ) {
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( value === undefined ) {
|
2008-08-10 23:59:01 +00:00
|
|
|
var elem = this[0];
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2008-08-10 23:59:01 +00:00
|
|
|
if ( elem ) {
|
2008-07-23 17:00:32 +00:00
|
|
|
if( jQuery.nodeName( elem, 'option' ) )
|
|
|
|
return (elem.attributes.value || {}).specified ? elem.value : elem.text;
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// We need to handle select boxes special
|
|
|
|
if ( jQuery.nodeName( elem, "select" ) ) {
|
|
|
|
var index = elem.selectedIndex,
|
|
|
|
values = [],
|
|
|
|
options = elem.options,
|
|
|
|
one = elem.type == "select-one";
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Nothing was selected
|
|
|
|
if ( index < 0 )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
// Loop through all the selected options
|
|
|
|
for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {
|
|
|
|
var option = options[ i ];
|
|
|
|
|
|
|
|
if ( option.selected ) {
|
|
|
|
// Get the specifc value for the option
|
2008-07-23 17:00:32 +00:00
|
|
|
value = jQuery(option).val();
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// We don't need an array for one selects
|
|
|
|
if ( one )
|
|
|
|
return value;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Multi-Selects return an array
|
|
|
|
values.push( value );
|
|
|
|
}
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-08-10 23:59:01 +00:00
|
|
|
return values;
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Everything else, we just grab the value
|
2008-08-10 23:59:01 +00:00
|
|
|
return (elem.value || "").replace(/\r/g, "");
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof value === "number" )
|
2008-05-24 17:57:45 +00:00
|
|
|
value += '';
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
return this.each(function(){
|
|
|
|
if ( this.nodeType != 1 )
|
|
|
|
return;
|
|
|
|
|
2008-10-29 02:01:22 +00:00
|
|
|
if ( jQuery.isArray(value) && /radio|checkbox/.test( this.type ) )
|
2008-01-14 22:30:48 +00:00
|
|
|
this.checked = (jQuery.inArray(this.value, value) >= 0 ||
|
|
|
|
jQuery.inArray(this.name, value) >= 0);
|
|
|
|
|
|
|
|
else if ( jQuery.nodeName( this, "select" ) ) {
|
2008-05-16 18:32:03 +00:00
|
|
|
var values = jQuery.makeArray(value);
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
jQuery( "option", this ).each(function(){
|
|
|
|
this.selected = (jQuery.inArray( this.value, values ) >= 0 ||
|
|
|
|
jQuery.inArray( this.text, values ) >= 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( !values.length )
|
|
|
|
this.selectedIndex = -1;
|
|
|
|
|
|
|
|
} else
|
|
|
|
this.value = value;
|
|
|
|
});
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
html: function( value ) {
|
2008-11-17 16:32:05 +00:00
|
|
|
return value === undefined ?
|
2008-05-23 00:54:59 +00:00
|
|
|
(this[0] ?
|
2009-02-09 14:48:15 +00:00
|
|
|
this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
|
2008-01-14 22:30:48 +00:00
|
|
|
null) :
|
|
|
|
this.empty().append( value );
|
|
|
|
},
|
|
|
|
|
|
|
|
replaceWith: function( value ) {
|
|
|
|
return this.after( value ).remove();
|
|
|
|
},
|
|
|
|
|
|
|
|
eq: function( i ) {
|
2008-06-30 16:17:44 +00:00
|
|
|
return this.slice( i, +i + 1 );
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
slice: function() {
|
2008-12-19 04:37:10 +00:00
|
|
|
return this.pushStack( Array.prototype.slice.apply( this, arguments ),
|
|
|
|
"slice", Array.prototype.slice.call(arguments).join(",") );
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
map: function( callback ) {
|
|
|
|
return this.pushStack( jQuery.map(this, function(elem, i){
|
|
|
|
return callback.call( elem, i, elem );
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
andSelf: function() {
|
|
|
|
return this.add( this.prevObject );
|
|
|
|
},
|
2008-02-03 04:05:24 +00:00
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
domManip: function( args, table, callback ) {
|
|
|
|
if ( this[0] ) {
|
2009-01-05 19:22:25 +00:00
|
|
|
var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
|
|
|
|
scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
|
2009-02-18 16:29:43 +00:00
|
|
|
first = fragment.firstChild;
|
2009-01-05 19:22:25 +00:00
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
if ( first )
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ )
|
2009-02-18 16:29:43 +00:00
|
|
|
callback.call( root(this[i], first), this.length > 1 || i > 0 ?
|
|
|
|
fragment.cloneNode(true) : fragment );
|
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
if ( scripts )
|
|
|
|
jQuery.each( scripts, evalScript );
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
return this;
|
|
|
|
|
|
|
|
function root( elem, cur ) {
|
|
|
|
return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
|
|
|
|
(elem.getElementsByTagName("tbody")[0] ||
|
|
|
|
elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
|
|
|
|
elem;
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Give the init function the jQuery prototype for later instantiation
|
2008-04-29 23:34:50 +00:00
|
|
|
jQuery.fn.init.prototype = jQuery.fn;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
function evalScript( i, elem ) {
|
|
|
|
if ( elem.src )
|
|
|
|
jQuery.ajax({
|
|
|
|
url: elem.src,
|
|
|
|
async: false,
|
|
|
|
dataType: "script"
|
|
|
|
});
|
|
|
|
|
|
|
|
else
|
|
|
|
jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
|
|
|
|
|
|
|
|
if ( elem.parentNode )
|
|
|
|
elem.parentNode.removeChild( elem );
|
|
|
|
}
|
|
|
|
|
2008-04-29 23:34:50 +00:00
|
|
|
function now(){
|
|
|
|
return +new Date;
|
|
|
|
}
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
jQuery.extend = jQuery.fn.extend = function() {
|
|
|
|
// copy reference to target object
|
|
|
|
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;
|
|
|
|
|
|
|
|
// Handle a deep copy situation
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof target === "boolean" ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
deep = target;
|
|
|
|
target = arguments[1] || {};
|
|
|
|
// skip the boolean and the target
|
|
|
|
i = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle case when target is a string or something (possible in deep copy)
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof target !== "object" && !jQuery.isFunction(target) )
|
2008-01-14 22:30:48 +00:00
|
|
|
target = {};
|
|
|
|
|
|
|
|
// extend jQuery itself if only one argument is passed
|
2008-04-30 00:09:55 +00:00
|
|
|
if ( length == i ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
target = this;
|
2008-04-30 00:09:55 +00:00
|
|
|
--i;
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for ( ; i < length; i++ )
|
|
|
|
// Only deal with non-null/undefined values
|
|
|
|
if ( (options = arguments[ i ]) != null )
|
|
|
|
// Extend the base object
|
|
|
|
for ( var name in options ) {
|
2008-05-13 01:45:58 +00:00
|
|
|
var src = target[ name ], copy = options[ name ];
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Prevent never-ending loop
|
2008-04-30 00:09:55 +00:00
|
|
|
if ( target === copy )
|
2008-01-14 22:30:48 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Recurse if we're merging object values
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( deep && copy && typeof copy === "object" && !copy.nodeType )
|
2008-05-14 19:45:31 +00:00
|
|
|
target[ name ] = jQuery.extend( deep,
|
|
|
|
// Never move original objects, clone them
|
|
|
|
src || ( copy.length != null ? [ ] : { } )
|
|
|
|
, copy );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Don't bring in undefined values
|
2008-05-02 19:49:41 +00:00
|
|
|
else if ( copy !== undefined )
|
2008-04-30 00:09:55 +00:00
|
|
|
target[ name ] = copy;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the modified object
|
|
|
|
return target;
|
|
|
|
};
|
|
|
|
|
2008-12-30 02:31:26 +00:00
|
|
|
// exclude the following css properties to add px
|
|
|
|
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
|
2008-05-15 14:45:29 +00:00
|
|
|
// cache defaultView
|
2008-11-17 16:32:05 +00:00
|
|
|
defaultView = document.defaultView || {},
|
|
|
|
toString = Object.prototype.toString;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
jQuery.extend({
|
|
|
|
noConflict: function( deep ) {
|
|
|
|
window.$ = _$;
|
|
|
|
|
|
|
|
if ( deep )
|
|
|
|
window.jQuery = _jQuery;
|
|
|
|
|
|
|
|
return jQuery;
|
|
|
|
},
|
|
|
|
|
2008-11-17 16:32:05 +00:00
|
|
|
// See test/unit/core.js for details concerning isFunction.
|
2008-10-18 22:22:08 +00:00
|
|
|
// Since version 1.3, DOM methods and functions like alert
|
2008-07-23 16:18:05 +00:00
|
|
|
// aren't supported. They return false on IE (#2968).
|
2008-11-17 16:32:05 +00:00
|
|
|
isFunction: function( obj ) {
|
|
|
|
return toString.call(obj) === "[object Function]";
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
2008-11-17 16:32:05 +00:00
|
|
|
|
|
|
|
isArray: function( obj ) {
|
|
|
|
return toString.call(obj) === "[object Array]";
|
2008-10-29 02:01:22 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// check if an element is in a (or is an) XML document
|
|
|
|
isXMLDoc: function( elem ) {
|
2009-01-19 23:17:30 +00:00
|
|
|
return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" ||
|
2009-02-28 20:23:48 +00:00
|
|
|
!!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML";
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Evalulates a script in a global context
|
|
|
|
globalEval: function( data ) {
|
2009-02-09 15:35:33 +00:00
|
|
|
if ( data && /\S/.test(data) ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
// 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");
|
|
|
|
|
|
|
|
script.type = "text/javascript";
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( jQuery.support.scriptEval )
|
2008-01-14 22:30:48 +00:00
|
|
|
script.appendChild( document.createTextNode( data ) );
|
2008-12-21 21:22:44 +00:00
|
|
|
else
|
|
|
|
script.text = data;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2008-05-16 18:37:11 +00:00
|
|
|
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
|
|
|
|
// This arises when a base node is used (#2709).
|
|
|
|
head.insertBefore( script, head.firstChild );
|
2008-01-14 22:30:48 +00:00
|
|
|
head.removeChild( script );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
nodeName: function( elem, name ) {
|
|
|
|
return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// args is for internal usage only
|
|
|
|
each: function( object, callback, args ) {
|
2008-05-06 00:54:59 +00:00
|
|
|
var name, i = 0, length = object.length;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
if ( args ) {
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( length === undefined ) {
|
2008-05-06 00:54:59 +00:00
|
|
|
for ( name in object )
|
2008-01-14 22:30:48 +00:00
|
|
|
if ( callback.apply( object[ name ], args ) === false )
|
|
|
|
break;
|
|
|
|
} else
|
2008-05-06 00:54:59 +00:00
|
|
|
for ( ; i < length; )
|
|
|
|
if ( callback.apply( object[ i++ ], args ) === false )
|
2008-01-14 22:30:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
// A special, fast, case for the most common use of each
|
|
|
|
} else {
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( length === undefined ) {
|
2008-05-06 00:54:59 +00:00
|
|
|
for ( name in object )
|
2008-01-14 22:30:48 +00:00
|
|
|
if ( callback.call( object[ name ], name, object[ name ] ) === false )
|
|
|
|
break;
|
|
|
|
} else
|
2008-05-13 01:45:58 +00:00
|
|
|
for ( var value = object[0];
|
2008-01-14 22:30:48 +00:00
|
|
|
i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}
|
|
|
|
}
|
|
|
|
|
|
|
|
return object;
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
className: {
|
|
|
|
// internal only, use addClass("class")
|
|
|
|
add: function( elem, classNames ) {
|
|
|
|
jQuery.each((classNames || "").split(/\s+/), function(i, className){
|
|
|
|
if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )
|
|
|
|
elem.className += (elem.className ? " " : "") + className;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// internal only, use removeClass("class")
|
|
|
|
remove: function( elem, classNames ) {
|
|
|
|
if (elem.nodeType == 1)
|
2008-11-17 16:32:05 +00:00
|
|
|
elem.className = classNames !== undefined ?
|
2008-01-14 22:30:48 +00:00
|
|
|
jQuery.grep(elem.className.split(/\s+/), function(className){
|
2008-05-13 01:45:58 +00:00
|
|
|
return !jQuery.className.has( classNames, className );
|
2008-01-14 22:30:48 +00:00
|
|
|
}).join(" ") :
|
|
|
|
"";
|
|
|
|
},
|
|
|
|
|
2008-05-16 16:41:12 +00:00
|
|
|
// internal only, use hasClass("class")
|
2008-01-14 22:30:48 +00:00
|
|
|
has: function( elem, className ) {
|
2009-01-20 17:33:25 +00:00
|
|
|
return elem && jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// A method for quickly swapping in/out CSS properties to get correct calculations
|
|
|
|
swap: function( elem, options, callback ) {
|
|
|
|
var old = {};
|
|
|
|
// Remember the old values, and insert the new ones
|
|
|
|
for ( var name in options ) {
|
|
|
|
old[ name ] = elem.style[ name ];
|
|
|
|
elem.style[ name ] = options[ name ];
|
|
|
|
}
|
|
|
|
|
|
|
|
callback.call( elem );
|
|
|
|
|
|
|
|
// Revert the old values
|
|
|
|
for ( var name in options )
|
|
|
|
elem.style[ name ] = old[ name ];
|
|
|
|
},
|
|
|
|
|
2009-02-13 22:58:57 +00:00
|
|
|
css: function( elem, name, force, extra ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
if ( name == "width" || name == "height" ) {
|
|
|
|
var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
function getWH() {
|
|
|
|
val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
|
2009-02-13 22:58:57 +00:00
|
|
|
|
|
|
|
if ( extra === "border" )
|
|
|
|
return;
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
jQuery.each( which, function() {
|
2009-02-13 22:58:57 +00:00
|
|
|
if ( !extra )
|
|
|
|
val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
|
|
|
|
if ( extra === "margin" )
|
|
|
|
val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
|
|
|
|
else
|
|
|
|
val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
|
2008-01-14 22:30:48 +00:00
|
|
|
});
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-02-13 22:58:57 +00:00
|
|
|
if ( elem.offsetWidth !== 0 )
|
2008-01-14 22:30:48 +00:00
|
|
|
getWH();
|
|
|
|
else
|
|
|
|
jQuery.swap( elem, props, getWH );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2009-02-13 22:58:57 +00:00
|
|
|
return Math.max(0, Math.round(val));
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
return jQuery.curCSS( elem, name, force );
|
|
|
|
},
|
|
|
|
|
|
|
|
curCSS: function( elem, name, force ) {
|
2008-05-06 00:54:59 +00:00
|
|
|
var ret, style = elem.style;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// We need to handle opacity special in IE
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( name == "opacity" && !jQuery.support.opacity ) {
|
2008-05-06 00:54:59 +00:00
|
|
|
ret = jQuery.attr( style, "opacity" );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
return ret == "" ?
|
|
|
|
"1" :
|
|
|
|
ret;
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Make sure we're using the right name for getting the float value
|
|
|
|
if ( name.match( /float/i ) )
|
|
|
|
name = styleFloat;
|
|
|
|
|
2008-05-06 00:54:59 +00:00
|
|
|
if ( !force && style && style[ name ] )
|
|
|
|
ret = style[ name ];
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2008-05-15 14:45:29 +00:00
|
|
|
else if ( defaultView.getComputedStyle ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Only "float" is needed here
|
|
|
|
if ( name.match( /float/i ) )
|
|
|
|
name = "float";
|
|
|
|
|
|
|
|
name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
|
|
|
|
|
2008-05-15 14:45:29 +00:00
|
|
|
var computedStyle = defaultView.getComputedStyle( elem, null );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( computedStyle )
|
2008-04-21 22:54:25 +00:00
|
|
|
ret = computedStyle.getPropertyValue( name );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// We should always get a number back from opacity
|
|
|
|
if ( name == "opacity" && ret == "" )
|
|
|
|
ret = "1";
|
|
|
|
|
|
|
|
} else if ( elem.currentStyle ) {
|
|
|
|
var camelCase = name.replace(/\-(\w)/g, function(all, letter){
|
|
|
|
return letter.toUpperCase();
|
|
|
|
});
|
|
|
|
|
|
|
|
ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
|
|
|
|
|
|
|
|
// From the awesome hack by Dean Edwards
|
|
|
|
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
|
|
|
|
|
|
|
|
// If we're not dealing with a regular pixel number
|
|
|
|
// but a number that has a weird ending, we need to convert it to pixels
|
|
|
|
if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
|
|
|
|
// Remember the original values
|
2008-05-06 00:54:59 +00:00
|
|
|
var left = style.left, rsLeft = elem.runtimeStyle.left;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Put in the new values to get a computed value out
|
|
|
|
elem.runtimeStyle.left = elem.currentStyle.left;
|
2008-05-06 00:54:59 +00:00
|
|
|
style.left = ret || 0;
|
|
|
|
ret = style.pixelLeft + "px";
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
// Revert the changed values
|
2008-05-06 00:54:59 +00:00
|
|
|
style.left = left;
|
|
|
|
elem.runtimeStyle.left = rsLeft;
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
clean: function( elems, context, fragment ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
context = context || document;
|
2008-11-17 16:32:05 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// !context.createElement fails in IE with an error but returns typeof 'object'
|
2008-11-29 01:14:02 +00:00
|
|
|
if ( typeof context.createElement === "undefined" )
|
2008-01-14 22:30:48 +00:00
|
|
|
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
|
|
|
|
|
2009-01-03 00:51:07 +00:00
|
|
|
// If a single string is passed in and it's a single tag
|
|
|
|
// just do a createElement and skip the rest
|
|
|
|
if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
|
2009-01-04 21:09:03 +00:00
|
|
|
var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
|
2009-01-03 00:51:07 +00:00
|
|
|
if ( match )
|
|
|
|
return [ context.createElement( match[1] ) ];
|
|
|
|
}
|
|
|
|
|
2008-12-25 19:47:56 +00:00
|
|
|
var ret = [], scripts = [], div = context.createElement("div");
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
jQuery.each(elems, function(i, elem){
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof elem === "number" )
|
2008-06-17 19:57:42 +00:00
|
|
|
elem += '';
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
if ( !elem )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Convert html string into DOM nodes
|
2008-11-17 16:32:05 +00:00
|
|
|
if ( typeof elem === "string" ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
// Fix "XHTML"-style tags in all browsers
|
|
|
|
elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
|
|
|
|
return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
|
|
|
|
all :
|
|
|
|
front + "></" + tag + ">";
|
|
|
|
});
|
|
|
|
|
|
|
|
// Trim whitespace, otherwise indexOf won't work as expected
|
2009-02-09 15:41:50 +00:00
|
|
|
var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
var wrap =
|
|
|
|
// option or optgroup
|
|
|
|
!tags.indexOf("<opt") &&
|
|
|
|
[ 1, "<select multiple='multiple'>", "</select>" ] ||
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
!tags.indexOf("<leg") &&
|
|
|
|
[ 1, "<fieldset>", "</fieldset>" ] ||
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
|
|
|
|
[ 1, "<table>", "</table>" ] ||
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
!tags.indexOf("<tr") &&
|
|
|
|
[ 2, "<table><tbody>", "</tbody></table>" ] ||
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// <thead> matched above
|
|
|
|
(!tags.indexOf("<td") || !tags.indexOf("<th")) &&
|
|
|
|
[ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
!tags.indexOf("<col") &&
|
|
|
|
[ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
|
|
|
|
|
|
|
|
// IE can't serialize <link> and <script> tags normally
|
2008-12-21 21:22:44 +00:00
|
|
|
!jQuery.support.htmlSerialize &&
|
2008-01-14 22:30:48 +00:00
|
|
|
[ 1, "div<div>", "</div>" ] ||
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
[ 0, "", "" ];
|
|
|
|
|
|
|
|
// Go to html and back, then peel off extra wrappers
|
|
|
|
div.innerHTML = wrap[1] + elem + wrap[2];
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Move to the right depth
|
|
|
|
while ( wrap[0]-- )
|
|
|
|
div = div.lastChild;
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Remove IE's autoinserted <tbody> from table fragments
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( !jQuery.support.tbody ) {
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// String was a <table>, *may* have spurious <tbody>
|
2009-02-09 15:41:50 +00:00
|
|
|
var hasBody = /<tbody/i.test(elem),
|
|
|
|
tbody = !tags.indexOf("<table") && !hasBody ?
|
|
|
|
div.firstChild && div.firstChild.childNodes :
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// String was a bare <thead> or <tfoot>
|
2009-02-09 15:41:50 +00:00
|
|
|
wrap[1] == "<table>" && !hasBody ?
|
2008-01-14 22:30:48 +00:00
|
|
|
div.childNodes :
|
|
|
|
[];
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
for ( var j = tbody.length - 1; j >= 0 ; --j )
|
|
|
|
if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
|
|
|
|
tbody[ j ].parentNode.removeChild( tbody[ j ] );
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
// IE completely kills leading whitespace when innerHTML is used
|
|
|
|
if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
|
|
|
|
div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
|
2008-12-19 04:37:54 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
elem = jQuery.makeArray( div.childNodes );
|
|
|
|
}
|
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
if ( elem.nodeType )
|
2008-01-14 22:30:48 +00:00
|
|
|
ret.push( elem );
|
|
|
|
else
|
|
|
|
ret = jQuery.merge( ret, elem );
|
|
|
|
|
|
|
|
});
|
2008-12-25 19:47:56 +00:00
|
|
|
|
2008-12-19 04:37:54 +00:00
|
|
|
if ( fragment ) {
|
|
|
|
for ( var i = 0; ret[i]; i++ ) {
|
2009-01-11 21:22:37 +00:00
|
|
|
if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
|
2009-01-10 01:07:59 +00:00
|
|
|
scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
|
2008-12-19 04:37:54 +00:00
|
|
|
} else {
|
2009-01-05 22:58:02 +00:00
|
|
|
if ( ret[i].nodeType === 1 )
|
|
|
|
ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
|
|
|
|
fragment.appendChild( ret[i] );
|
2008-12-19 04:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return scripts;
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
attr: function( elem, name, value ) {
|
|
|
|
// don't set attributes on text and comment nodes
|
|
|
|
if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
|
|
|
|
return undefined;
|
|
|
|
|
2009-02-28 20:23:48 +00:00
|
|
|
var notxml = !elem.tagName || !jQuery.isXMLDoc( elem ),
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// Whether we are setting (or getting)
|
2008-12-21 21:22:44 +00:00
|
|
|
set = value !== undefined;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// Try to normalize/fix the name
|
|
|
|
name = notxml && jQuery.props[ name ] || name;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// Only do all the following if this is a node (faster for style)
|
|
|
|
// IE elem.getAttribute passes even for style
|
|
|
|
if ( elem.tagName ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// These attributes require special treatment
|
|
|
|
var special = /href|src|style/.test( name );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// Safari mis-reports the default selected property of a hidden option
|
|
|
|
// Accessing the parent's selectedIndex property fixes it
|
2009-01-12 14:00:35 +00:00
|
|
|
if ( name == "selected" && elem.parentNode )
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
elem.parentNode.selectedIndex;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// If applicable, access the attribute via the DOM 0 way
|
2008-05-24 18:09:21 +00:00
|
|
|
if ( name in elem && notxml && !special ) {
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
if ( set ){
|
|
|
|
// We can't allow the type property to be changed (since it causes problems in IE)
|
|
|
|
if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )
|
|
|
|
throw "type property can't be changed";
|
|
|
|
|
|
|
|
elem[ name ] = value;
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// browsers index elements by id/name on forms, give priority to attributes.
|
|
|
|
if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
|
|
|
|
return elem.getAttributeNode( name ).nodeValue;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2009-01-07 14:36:30 +00:00
|
|
|
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
|
2009-01-05 17:34:42 +00:00
|
|
|
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
2009-01-07 14:36:30 +00:00
|
|
|
if ( name == "tabIndex" ) {
|
|
|
|
var attributeNode = elem.getAttributeNode( "tabIndex" );
|
|
|
|
return attributeNode && attributeNode.specified
|
|
|
|
? attributeNode.value
|
2009-01-19 21:40:23 +00:00
|
|
|
: elem.nodeName.match(/(button|input|object|select|textarea)/i)
|
2009-01-07 14:36:30 +00:00
|
|
|
? 0
|
2009-01-19 21:40:23 +00:00
|
|
|
: elem.nodeName.match(/^(a|area)$/i) && elem.href
|
|
|
|
? 0
|
|
|
|
: undefined;
|
2009-01-05 17:34:42 +00:00
|
|
|
}
|
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
return elem[ name ];
|
|
|
|
}
|
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( !jQuery.support.style && notxml && name == "style" )
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
return jQuery.attr( elem.style, "cssText", value );
|
|
|
|
|
|
|
|
if ( set )
|
2008-01-14 22:30:48 +00:00
|
|
|
// convert the value to a string (all browsers do this but IE) see #1070
|
|
|
|
elem.setAttribute( name, "" + value );
|
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
var attr = !jQuery.support.hrefNormalized && notxml && special
|
2008-05-24 18:09:21 +00:00
|
|
|
// Some attributes require a special call on IE
|
|
|
|
? elem.getAttribute( name, 2 )
|
|
|
|
: elem.getAttribute( name );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2008-05-24 18:09:21 +00:00
|
|
|
// Non-existent attributes return null, we normalize to undefined
|
|
|
|
return attr === null ? undefined : attr;
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// elem is actually elem.style ... set the style
|
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// IE uses filters for opacity
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( !jQuery.support.opacity && name == "opacity" ) {
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
if ( set ) {
|
|
|
|
// IE has trouble with opacity if it does not have layout
|
|
|
|
// Force it by setting the zoom level
|
2008-05-13 01:45:58 +00:00
|
|
|
elem.zoom = 1;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
// Set the alpha filter to set the opacity
|
|
|
|
elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +
|
|
|
|
(parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
|
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?
|
|
|
|
(parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '':
|
|
|
|
"";
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
jquery core: #2548, #2170, #2188, #2099, #1170, #2558, #2521, #2119, #1271, #2453, #2537.
mass refactoring of $.attr (#2548)
* Changes
- undefined was returned for falsy values.
- expando attributes are used when possible.
- one $.isXmlDoc instead of 2.
- $.attr( style, ... ) goes thru less useless checks.
- reduced code size of recurrent accessed variables/checks.
- $.props doesn't need redundant sets of key value anymore.
- added cellSpacing to $.props (#2521)
2008-05-13 00:37:30 +00:00
|
|
|
|
|
|
|
name = name.replace(/-([a-z])/ig, function(all, letter){
|
|
|
|
return letter.toUpperCase();
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( set )
|
|
|
|
elem[ name ] = value;
|
|
|
|
|
|
|
|
return elem[ name ];
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
trim: function( text ) {
|
|
|
|
return (text || "").replace( /^\s+|\s+$/g, "" );
|
|
|
|
},
|
|
|
|
|
|
|
|
makeArray: function( array ) {
|
|
|
|
var ret = [];
|
|
|
|
|
2008-05-06 23:28:21 +00:00
|
|
|
if( array != null ){
|
2008-04-25 03:48:07 +00:00
|
|
|
var i = array.length;
|
2008-08-12 19:34:30 +00:00
|
|
|
// The window, strings (and functions) also have 'length'
|
2008-11-17 16:32:05 +00:00
|
|
|
if( i == null || typeof array === "string" || jQuery.isFunction(array) || array.setInterval )
|
2008-05-06 23:28:21 +00:00
|
|
|
ret[0] = array;
|
|
|
|
else
|
2008-04-25 03:48:07 +00:00
|
|
|
while( i )
|
2008-04-24 21:23:36 +00:00
|
|
|
ret[--i] = array[i];
|
2008-04-25 03:48:07 +00:00
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
inArray: function( elem, array ) {
|
|
|
|
for ( var i = 0, length = array.length; i < length; i++ )
|
2008-05-08 16:14:49 +00:00
|
|
|
// Use === because on IE, window == document
|
|
|
|
if ( array[ i ] === elem )
|
2008-01-14 22:30:48 +00:00
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
merge: function( first, second ) {
|
|
|
|
// We have to loop this way because IE & Opera overwrite the length
|
|
|
|
// expando of getElementsByTagName
|
2008-05-13 02:20:08 +00:00
|
|
|
var i = 0, elem, pos = first.length;
|
2008-01-14 22:30:48 +00:00
|
|
|
// Also, we need to make sure that the correct elements are being returned
|
|
|
|
// (IE returns comment nodes in a '*' query)
|
2008-12-21 21:22:44 +00:00
|
|
|
if ( !jQuery.support.getAll ) {
|
2008-12-25 19:25:30 +00:00
|
|
|
while ( (elem = second[ i++ ]) != null )
|
2008-05-13 02:20:08 +00:00
|
|
|
if ( elem.nodeType != 8 )
|
|
|
|
first[ pos++ ] = elem;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
} else
|
2008-12-25 19:25:30 +00:00
|
|
|
while ( (elem = second[ i++ ]) != null )
|
2008-05-13 02:20:08 +00:00
|
|
|
first[ pos++ ] = elem;
|
2008-01-14 22:30:48 +00:00
|
|
|
|
|
|
|
return first;
|
|
|
|
},
|
|
|
|
|
|
|
|
unique: function( array ) {
|
|
|
|
var ret = [], done = {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
for ( var i = 0, length = array.length; i < length; i++ ) {
|
|
|
|
var id = jQuery.data( array[ i ] );
|
|
|
|
|
|
|
|
if ( !done[ id ] ) {
|
|
|
|
done[ id ] = true;
|
|
|
|
ret.push( array[ i ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch( e ) {
|
|
|
|
ret = array;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
grep: function( elems, callback, inv ) {
|
|
|
|
var ret = [];
|
|
|
|
|
|
|
|
// Go through the array, only saving the items
|
|
|
|
// that pass the validator function
|
|
|
|
for ( var i = 0, length = elems.length; i < length; i++ )
|
2008-05-12 01:21:50 +00:00
|
|
|
if ( !inv != !callback( elems[ i ], i ) )
|
2008-01-14 22:30:48 +00:00
|
|
|
ret.push( elems[ i ] );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
map: function( elems, callback ) {
|
|
|
|
var ret = [];
|
|
|
|
|
|
|
|
// Go through the array, translating each of the items to their
|
|
|
|
// new value (or values).
|
|
|
|
for ( var i = 0, length = elems.length; i < length; i++ ) {
|
|
|
|
var value = callback( elems[ i ], i );
|
|
|
|
|
2008-05-06 14:54:53 +00:00
|
|
|
if ( value != null )
|
|
|
|
ret[ ret.length ] = value;
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 14:54:53 +00:00
|
|
|
return ret.concat.apply( [], ret );
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-02-25 14:23:25 +00:00
|
|
|
// All jQuery objects should point back to these
|
|
|
|
var rootjQuery = jQuery(document);
|
|
|
|
|
2008-12-21 21:22:44 +00:00
|
|
|
// Use of jQuery.browser is deprecated.
|
|
|
|
// It's included for backwards compatibility and plugins,
|
|
|
|
// although they should work to migrate away.
|
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
var userAgent = navigator.userAgent.toLowerCase();
|
|
|
|
|
|
|
|
// Figure out what browser is being used
|
|
|
|
jQuery.browser = {
|
2008-07-23 15:21:27 +00:00
|
|
|
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
|
2008-01-14 22:30:48 +00:00
|
|
|
safari: /webkit/.test( userAgent ),
|
|
|
|
opera: /opera/.test( userAgent ),
|
|
|
|
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
|
|
|
|
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
|
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.each({
|
2008-01-26 00:26:28 +00:00
|
|
|
parent: function(elem){return elem.parentNode;},
|
|
|
|
parents: function(elem){return jQuery.dir(elem,"parentNode");},
|
|
|
|
next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
|
|
|
|
prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
|
|
|
|
nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
|
|
|
|
prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
|
|
|
|
siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
|
|
|
|
children: function(elem){return jQuery.sibling(elem.firstChild);},
|
|
|
|
contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
|
2008-01-14 22:30:48 +00:00
|
|
|
}, function(name, fn){
|
|
|
|
jQuery.fn[ name ] = function( selector ) {
|
|
|
|
var ret = jQuery.map( this, fn );
|
|
|
|
|
|
|
|
if ( selector && typeof selector == "string" )
|
|
|
|
ret = jQuery.multiFilter( selector, ret );
|
|
|
|
|
2008-12-19 04:37:10 +00:00
|
|
|
return this.pushStack( jQuery.unique( ret ), name, selector );
|
2008-01-14 22:30:48 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.each({
|
|
|
|
appendTo: "append",
|
|
|
|
prependTo: "prepend",
|
|
|
|
insertBefore: "before",
|
|
|
|
insertAfter: "after",
|
|
|
|
replaceAll: "replaceWith"
|
|
|
|
}, function(name, original){
|
2009-02-18 16:29:43 +00:00
|
|
|
jQuery.fn[ name ] = function( selector ) {
|
|
|
|
var ret = [], insert = jQuery( selector );
|
2008-01-14 22:30:48 +00:00
|
|
|
|
2009-02-18 16:29:43 +00:00
|
|
|
for ( var i = 0, l = insert.length; i < l; i++ ) {
|
|
|
|
var elems = (i > 0 ? this.clone(true) : this).get();
|
|
|
|
jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
|
|
|
|
ret = ret.concat( elems );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.pushStack( ret, name, selector );
|
2008-01-14 22:30:48 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.each({
|
|
|
|
removeAttr: function( name ) {
|
|
|
|
jQuery.attr( this, name, "" );
|
2008-05-13 01:45:58 +00:00
|
|
|
if (this.nodeType == 1)
|
2008-01-14 22:30:48 +00:00
|
|
|
this.removeAttribute( name );
|
|
|
|
},
|
|
|
|
|
|
|
|
addClass: function( classNames ) {
|
|
|
|
jQuery.className.add( this, classNames );
|
|
|
|
},
|
|
|
|
|
|
|
|
removeClass: function( classNames ) {
|
|
|
|
jQuery.className.remove( this, classNames );
|
|
|
|
},
|
|
|
|
|
2008-12-25 20:12:18 +00:00
|
|
|
toggleClass: function( classNames, state ) {
|
|
|
|
if( typeof state !== "boolean" )
|
|
|
|
state = !jQuery.className.has( this, classNames );
|
|
|
|
jQuery.className[ state ? "add" : "remove" ]( this, classNames );
|
2008-01-14 22:30:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
remove: function( selector ) {
|
2009-02-20 19:45:29 +00:00
|
|
|
if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
|
2009-02-23 16:32:45 +00:00
|
|
|
if ( this.nodeType === 1 ) {
|
|
|
|
cleanData( this.getElementsByTagName("*") );
|
|
|
|
cleanData( [this] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.parentNode ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
this.parentNode.removeChild( this );
|
2009-02-23 16:32:45 +00:00
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
empty: function() {
|
|
|
|
// Remove element nodes and prevent memory leaks
|
2009-02-23 16:32:45 +00:00
|
|
|
if ( this.nodeType === 1 ) {
|
|
|
|
cleanData( this.getElementsByTagName("*") );
|
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-01-14 22:30:48 +00:00
|
|
|
// Remove any remaining nodes
|
2009-02-23 16:32:45 +00:00
|
|
|
while ( this.firstChild ) {
|
2008-01-14 22:30:48 +00:00
|
|
|
this.removeChild( this.firstChild );
|
2009-02-23 16:32:45 +00:00
|
|
|
}
|
2008-01-14 22:30:48 +00:00
|
|
|
}
|
|
|
|
}, function(name, fn){
|
|
|
|
jQuery.fn[ name ] = function(){
|
|
|
|
return this.each( fn, arguments );
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2009-02-23 16:32:45 +00:00
|
|
|
function cleanData( elems ) {
|
|
|
|
for ( var i = 0, l = elems.length; i < l; i++ ) {
|
|
|
|
var id = elems[i][expando];
|
|
|
|
if ( id ) {
|
|
|
|
delete jQuery.cache[ id ];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|