[jquery-dev] Re: replaceClass

2009-03-26 Thread Julian Aubourg
So, I turned the code around a bit and managed to find a way to get more consistent timings:http://www.tfuture.org/julian/classname2.html Each solution is ran separately at user's request. Conclusions are: - For a single node: + .removeClass().addClass() have equivalent timing for the old & new

[jquery-dev] Re: replaceClass

2009-03-26 Thread Julian Aubourg
I don't doubt it... too bad we don't live in the future :P 2009/3/27 Daniel Friesen > > Just a future facing note, but HTML5 adds .classList which would likely > perform better than any possible trick we could use with strings, > arrays, or regexes. > > ~Daniel Friesen (Dantman, Nadir-Seen-Fire)

[jquery-dev] Re: replaceClass

2009-03-26 Thread Daniel Friesen
Just a future facing note, but HTML5 adds .classList which would likely perform better than any possible trick we could use with strings, arrays, or regexes. ~Daniel Friesen (Dantman, Nadir-Seen-Fire) Julian Aubourg wrote: > It may seem conter-intuitive but, in the end, the less you handle wit

[jquery-dev] Re: replaceClass

2009-03-26 Thread Julian Aubourg
It may seem conter-intuitive but, in the end, the less you handle within the VM the better. Since I want to support regexps, why make some special code with branching and javascript based handling just for "simple" strings. See, your code does apply a regexp on node.className. It should also split

[jquery-dev] Re: replaceClass

2009-03-26 Thread Daniel Friesen
Transforming every simple class check into a regex? That sounds like a horribly roundabout way to do something extremely simple. What happened to good old classic string testing? (" " + this.className + " ").indexOf(" foo "); A tiny bit of trickery, and that could be turned into a good possibili

[jquery-dev] Re: replaceClass

2009-03-26 Thread Julian Aubourg
And gmail borked the sample page link :/ http://www.tfuture.org/julian/classname.html 2009/3/27 Julian Aubourg > So, I talked about making a plugin I would be the only one to use, didn't > I? ;) > http://www.tfuture.org/julian/jquery.classname.js > > The test page is here: > http://www.tfuture.

[jquery-dev] Re: replaceClass

2009-03-26 Thread Julian Aubourg
So, I talked about making a plugin I would be the only one to use, didn't I? ;) http://www.tfuture.org/julian/jquery.classname.js The test page is here: http://www.tfuture.org/julian/classname.html (I borrowed a piece of internet from a friend)

[jquery-dev] Re: replaceClass

2009-03-26 Thread Gilles
If all your class have the same prefix you could also use CSS3 selectors like " class^=color-] " So $('class^=color-]').each(function() { $(this).removeClass(this.className); }); Haven't tried it and I am tried, but that "should" remove all classes starting with color-foo, not sure if it

[jquery-dev] Re: replaceClass

2009-03-26 Thread Julian Aubourg
> As for .replaceClass I still don't see a point. If > .removeClass(foo).addClass(bar); is doing bad performance things, then > those performance things should be fixed. I find the case to be trivial > in comparison to how much is already done in JS to do anything else. like I said, probably a bit

[jquery-dev] Re: replaceClass

2009-03-25 Thread Daniel Friesen
Your original example was confusing. If you just have buttons that change the background colors you don't even need to bother with the filter. $(node).removeClass('color-black color-white color-blue color-green').addClass('color-white'); I think multiple classes are supported in removeClass al

[jquery-dev] Re: replaceClass

2009-03-25 Thread Julian Aubourg
> $(node).filter('.color-black').removeClass('color-black').addClass('color-white').end() And you find that more readable than $(node).replaceClass('color-black','color-white') ? ;) The main issue here is that I dunno what the class will be in the first place. I just know it will be "color-XXX" bu

[jquery-dev] Re: replaceClass

2009-03-25 Thread Daniel Friesen
Having .hasClass / .removeClass support regex has been discussed before, there is a ticket open for one of them so it might be a possibility. I don't see much use for replaceClass, rather I think the semantics of reading it would be a little confusing. I can't even understand what the code you