Actually, I was thinking the same after I posted the code. Nodes could be wrapped everywhere and the remove call forcing to do not keep item could cause logical problems hard to explain/manage
I ended up with something more simple: inContext:(function(splice){ return function() { var length = this.length; while( length ){ if( !jQuery.contains( this.context, this[--length] ) ) splice.call( this, length, 1 ); }; return this; } })( Array.prototype.splice ), But the point is that you wrapped a function that could be useful for I don;t know how many plugins/extensions/improvements ... so, is there any chance you'll expose contains from selector.js ? On Tue, Aug 18, 2009 at 5:09 PM, Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > John, I have created and tested a patch. > > Please have a look when you have a second. It does not break anything, the > name could be obviously changed if you want ( something like > updateCollection or whatever ) > > It stays into manipulation file > > jQuery.fn.extend({ > > // updates precedent search removing nodes not in context anymore > garbage:(function(splice){ > return function() { > var length = this.length, > remove = [] > ; > while( length ){ > if( !jQuery.contains( this.context, this[--length] ) ) { > remove.push( splice.call( this, length, 1 ) ); > } > }; > remove.each = this.each; > this.remove.call(remove, false, false); > return this; > } > })( Array.prototype.splice ), > > text: function( text ) { > .... > > The only thing to avoid to mess up stuff is that it needs contains > exposures from selector file > > // EXPOSE > jQuery.find = Sizzle; > jQuery.expr = Sizzle.selectors; > jQuery.expr[":"] = jQuery.expr.filters; > jQuery.contains = contains; > > Please, let me know what you think. > > Cheers > > > On Tue, Aug 18, 2009 at 4:31 PM, Andrea Giammarchi < > andrea.giammar...@gmail.com> wrote: > >> Sorry, maybe this one will be better: >> >> garbage:(function(splice){ >> return function(){ >> var length = this.length; >> while(length){ >> if(!contains(this.context, this[--length])) >> jQuery.remove.call(splice.call(this, length, 1)); >> }; >> return this; >> }; >> })(Array.prototype.splice), >> >> Regards >> >> >> On Tue, Aug 18, 2009 at 4:21 PM, Andrea Giammarchi < >> andrea.giammar...@gmail.com> wrote: >> >>> What a bout a garbage collector prototype method? Is there any plugin >>> like this? >>> >>> garbage:(function(splice){ >>> return function(){ >>> var length = this.length; >>> while(length){ >>> if(!contains(this.context, this[--length])) >>> splice.call(this, length, 1); >>> }; >>> return this; >>> }; >>> })(Array.prototype.splice), >>> >>> The problem is that to use the jQuery contains function it requires to be >>> inside the library since if I am not wrong contains is not exposed. >>> >>> What do you think? >>> >>> >>> On Tue, Aug 18, 2009 at 4:00 PM, John Resig <jere...@gmail.com> wrote: >>> >>>> >>>> Not really, right? You can still modify and re-place nodes that have >>>>> been removed from the dom, but not on nodes that have been destroyed. >>>>> >>>>> <div id="bar"><p>hi</p><p>there</p></div> >>>>> >>>>> var ps = $("#bar p").remove(); >>>>> $("#bar").html("<p>hmm</p>"); >>>>> ps.appendTo("#bar") >>>>> >>>>> or some such. >>>>> >>>> >>>> Removed from the DOM via an innerHTML or removed from the DOM via a >>>> removeChild - the result is the same either way. A reference to the DOM >>>> element should be maintained so that further operations can be performed. >>>> >>>> --John >>>> >>>> >>>> >>>> >>>> >>> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---