logo       

Re: [jQuery] Is there a way to "endAll()"?: msg#01219

lang.javascript.jquery

Subject: Re: [jQuery] Is there a way to "endAll()"?

Hi,

> I like the idea of endAll(), but it won't help plugin developers:
>
> To savely restore the state, you could do something like this (untested):
> jQuery.fn.plugin = function() {
> var oldStack = $.merge( [], this.stack );
> // do other stuff
> this.stack = oldStack;
> return this;
> };

I just had the idea of savepoints:

jQuery.fn.savepoint = function() {
if( ! this.savePoints )
this.savePoints = [];
this.savepoints.push(this.stack.length);
return this;
}
jQuery.fn.savepointReturn = function() {
if( ! this.savepoints || this.savepoints.length == 0 )
return this;
return this.get(this.stack[this.savepoints.pop()]);
}

then you can do:

jQuery.fn.plugin = function() {
  this.savepoint();
  // do other stuff
  return this.savepointReturn();
};

Christof


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise