// HANDLE: $(function)
// Shortcut for document ready
} else if ( jQuery.isFunction( selector ) )
- return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
+ return jQuery( document ).ready( selector );
return this.setArray(jQuery.makeArray(selector));
},
// Determine the position of an element within
// the matched set of elements
index: function( elem ) {
- var ret = -1;
-
// Locate the position of the desired element
return jQuery.inArray(
// If it receives a jQuery object, the first element is used
}) ), "filter", selector );
},
+ closest: function( selector ) {
+ return this.map(function(){
+ var cur = this;
+ while ( cur && cur.ownerDocument ) {
+ if ( jQuery(cur).is(selector) )
+ return cur;
+ cur = cur.parentNode;
+ }
+ });
+ },
+
not: function( selector ) {
if ( typeof selector === "string" )
// test special case where just one selector is passed in
},
clean: function( elems, context, fragment ) {
- var ret = [], scripts = [];
context = context || document;
// !context.createElement fails in IE with an error but returns typeof 'object'
if ( typeof context.createElement === "undefined" )
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
+ var ret = [], scripts = [], div = context.createElement("div");
+
jQuery.each(elems, function(i, elem){
if ( typeof elem === "number" )
elem += '';
});
// Trim whitespace, otherwise indexOf won't work as expected
- var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
+ var tags = jQuery.trim( elem ).toLowerCase();
var wrap =
// option or optgroup
ret = jQuery.merge( ret, elem );
});
+
+ // Clean up
+ div.innerHTML = "";
if ( fragment ) {
for ( var i = 0; ret[i]; i++ ) {
- if ( jQuery.nodeName( ret[i], "script" ) ) {
- ret[i].parentNode.removeChild( ret[i] );
+ var node = ret[i];
+ if ( jQuery.nodeName( node, "script" ) ) {
+ if( node.parentNode )
+ node.parentNode.removeChild( node );
} else {
- if ( ret[i].nodeType === 1 )
- ret = jQuery.merge( ret, ret[i].getElementsByTagName("script"));
- fragment.appendChild( ret[i] );
+ if ( node.nodeType === 1 )
+ ret = jQuery.merge( ret, node.getElementsByTagName("script"));
+ fragment.appendChild( node );
}
}
// Also, we need to make sure that the correct elements are being returned
// (IE returns comment nodes in a '*' query)
if ( !jQuery.support.getAll ) {
- while ( (elem = second[ i++ ]) )
+ while ( (elem = second[ i++ ]) != null )
if ( elem.nodeType != 8 )
first[ pos++ ] = elem;
} else
- while ( (elem = second[ i++ ]) )
+ while ( (elem = second[ i++ ]) != null )
first[ pos++ ] = elem;
return first;
jQuery.className.remove( this, classNames );
},
- toggleClass: function( classNames ) {
- jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
+ toggleClass: function( classNames, state ) {
+ if( typeof state !== "boolean" )
+ state = !jQuery.className.has( this, classNames );
+ jQuery.className[ state ? "add" : "remove" ]( this, classNames );
},
remove: function( selector ) {