[Moo] Re: remove CSS all classes from element except one

2010-02-24 Thread rasmusfl0e
The way you've used RegExp will also match partial matches; you look for "rump" and get a match on "scrump"... not good. False positives. @Yann: The contains method you listed is the Array method - not String one which looks like this: contains: function(string, separator){ return (separa

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Yann Leretaille
On Wed, Feb 24, 2010 at 04:35, Sanford Whiteman wrote: > It isn't shocking that running hasClass()»contains()»indexOf() and > set() is marginally slower than running only exec() (on a preexisting > regex)»direct property set. Not that it isn't mildly interesting, just > not anything actionab

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Sanford Whiteman
It isn't shocking that running hasClass()»contains()»indexOf() and set() is marginally slower than running only exec() (on a preexisting regex)»direct property set. Not that it isn't mildly interesting, just not anything actionable IMO. It would be shocking if just indexOf()»direct property s

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Yann Leretaille
> > But your benchmark still isn't balanced. For example, fn [1b] is using > more pure JS/DOM functions and is implemented on Array, while fn [4] > is using Moo overhead and is implemented on Element. > Really? [4] used className, so i wanted to see how big the change was when using className in

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Sanford Whiteman
But your benchmark still isn't balanced. For example, fn [1b] is using more pure JS/DOM functions and is implemented on Array, while fn [4] is using Moo overhead and is implemented on Element. The most apt competitor to your className.RegExp is className.indexOf. I adjusted fn [4] accordingly. I

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Yann Leretaille
> anyways... if you want performance avoid extra function calls when > they aren't needed. all of the above could be done much simpler - the > following example uses only 1 hasClass call: > > Element.implement({ >removeAllClassExcept: function(klass) { >this.className = this.hasClass(kl

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Thierry bela nanga
10 items time1::: 0.6685 *time1a: 0.3263* time2::: 0.6325 time3::: 0.52434 100 items time1::: 0.4923 *time1a: 0.2901*4 time2::: 0.4503 time3::: 0.38425 1000 items t

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Thierry bela nanga
from the mooshell, Win Vista64 FF3.6 time1::: 0.49606 time1a: 0.284 time2::: 0.44395 time3::: 0.348 On Tue, Feb 23, 2010 at 4:08 PM, Yann Leretaille wrote: > could somebody test this one with 100,100 & 10 Elements? > > My results: > n > FF 3.6, Linux, 64

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread אריה גלזר
FF 3.6 Windows 764bit: 1000: time1::: 0.394 *time1a: 0.24195* - fastets time2::: 0.338 time3::: 0.24803 100: time1::: 0.5443 *time1a: 0.3122* time2::: 0.49825 time3::: 0.3963 10: time1::: 0.000

[Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread rasmusfl0e
Avoid unnecessary function calls. The following uses only 1 extra call to hasClass: Element.implement({ removeAllClassExcept: function(klass) { this.className = this.hasClass(klass) ? klass : ''; return this; } }); Performance is better ("time4"): http://mootools.net/shel

[Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread rasmusfl0e
dude - would you like to borrow the "var" keyword? :P anyways... if you want performance avoid extra function calls when they aren't needed. all of the above could be done much simpler - the following example uses only 1 hasClass call: Element.implement({ removeAllClassExcept: function(klass)

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-23 Thread Yann Leretaille
could somebody test this one with 100,100 & 10 Elements? My results: n FF 3.6, Linux, 64Bit FF 2.5.8,WinXP, 32Bit 1000 time1::: 0.33 *time1a: 0.20* time2::: 0.30 time3::: 0.24time1::: 0.55 *time1a: 0.36* time2::: 0.48 time3::: 0.38 100 time1::: 0.45 *time1a: 0.0

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-22 Thread Sanford Whiteman
> This might be to do with TraceMonkey being en-/disabled on one of the > testing machines... As far as I know, it's disabled by default in 64bit > Linux, and perhaps in some other builds. A promising idea, but I just tested on 3.5.7 with TM off and TM on and the non-regex fn cleanly beats ou

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-22 Thread Barry van Oudtshoorn
This might be to do with TraceMonkey being en-/disabled on one of the testing machines... As far as I know, it's disabled by default in 64bit Linux, and perhaps in some other builds. Barry On 22/02/10 23:20, Dimitar Christoff wrote: even through your benchmark: time1: 0.000329 time2: 0.00022

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-22 Thread Yann Leretaille
I understand your point. Actually, benchmarking seems particualry difficult for this one. I created a mooshell wich creates a list with 1000 Elements, wich have 0-3 classes, with or without base_class. The list ist cloned for each benchmark and i ran each methos is runned 10 times. Here are the res

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-22 Thread Dimitar Christoff
even through your benchmark: time1: 0.000329 time2: 0.00022602 time3: 0.0001933 i am using FF 3.5.8(?) even with advances in regex performance for webkit, hasClass uses contains which uses indexOf... indexOf > regex, at least for now. -- Dimitar Christoff - http://fragg

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-21 Thread Sanford Whiteman
>- Method1: 0.000265s >- Method2: 0.000297s >- Method3: 0.000279s > Looks like if my method is slightly faster... Mmm, something is wrong with your benchmark. Comparing your regex [f1] t.set('class',new RegExp('base_class').exec(t.get('class'))); with the straightforward [f2]t

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-21 Thread Yann Leretaille
On Mon, Feb 22, 2010 at 00:28, Dimitar Christoff wrote: > > Why not use RegExp? > > > speed. this will be slower. > I'm not sure about this. hasClass require string-operation anyway and with RegExp, you can directly set the correct class without further comparing. I made a small benchmark compari

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-21 Thread Dimitar Christoff
> Why not use RegExp? > speed. this will be slower. -- Dimitar Christoff - http://fragged.org/

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-20 Thread Yann Leretaille
Why not use RegExp? Element.implement({ removeClassesExcept: function(klass) { return this.set("class",new RegExp(klass).exec(this.get("class"))); } }); If the RegExp /klass/ matches class, class is "klass", otherwise it's null. Yann On Sun, Feb 14, 2010 at 23:32, Dimitar Christ

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-20 Thread Sanford Whiteman
OK, how often are you going to be running the function that strips the classes from a collection of els? How large is the usual collection? -- Sandy Sanford Whiteman, Chief Technologist Broadleaf Systems, a division of Cypress Integrated Systems, Inc. e-mail:

[Moo] Re: remove CSS all classes from element except one

2010-02-20 Thread cbolson
Hi, The reason is that the classes are added via javascript (mootools) according to user actions. In basic terms this is used on a large list of (delegation is used ;) ) some of which can be clicked and others not (they are dates). The "clickable" dates always need to remain clickable but, as the

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-19 Thread Sanford Whiteman
Hey Chris, I was just looking at this thread again and wondered what the particulars were that necessitated a JS solution for this. Depending on the environment, could the "clever" solution have been CSS-only? http://mootools.net/shell/XdL9T/6/ Not saying this would apply, but I'm w

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-15 Thread Roman Land
Or with my version: Element.Implement({ 'removeClassesExcept': function(baseClass){ this.set('class', this.get('class').split(' ').filter(function(c){return c == this },baseClass)[0]); } }) On Mon, Feb 15, 2010 at 8:55 PM, Sanford Whiteman < sa...@cypressintegrated.com> wro

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-15 Thread Sanford Whiteman
> Yes, But the question was from an array of controls: When you implement on Element, you automatically implement on Elements arrays. There is no need to implement on the generic Array. Element.implement({ removeClassesExcept: function(klass) { ... } }); $('remove').addEvent('cli

[Moo] Re: remove CSS all classes from element except one

2010-02-15 Thread hazlema
Yes, But the question was from an array of controls: http://mootools.net/shell/hv3Yv/ Array.implement({ removeClassesExcept: function(klass) { this.map(function(ele, ndx) { return ele.hasClass(klass) ? ele.set("class", klass) : ele.erase("class"); }); } }); On

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-14 Thread Roman Land
(mooshell is down) how about this over engineered solution: var leaveOnlyThisClass = function(el, cl){ el.set('class', el.get('class').split(' ').filter(function(c){return c == this },cl)[0]); }; usage: leaveOnlyThisClass($('divid'),'leave-only-me'); On Mon, Feb 15, 2010 at 12:32 AM, Dimi

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-14 Thread Dimitar Christoff
> Anyway, this way is just a function around the same basic logic... not > really reaching the "cleverer" mark. :) the 'clever' i could think of without involving garden gnomes was this: Element.implement({ removeClassesExcept: function(klass) { return this.hasClass(klass) ? this.set

Re: [Moo] Re: remove CSS all classes from element except one

2010-02-14 Thread Sanford Whiteman
> the mootools way You forgot the "don't add base_class if it wasn't originally there" part of the spec. Anyway, this way is just a function around the same basic logic... not really reaching the "cleverer" mark. :) -- S.

[Moo] Re: remove CSS all classes from element except one

2010-02-13 Thread ken
the mootools way http://mootools.net/shell/TV5MM/ On Feb 14, 1:27 am, cbolson wrote: > Thanks for that :) > I am actually using something along those lines I was just hoping that > there might be a "cleverer" way to do it (ie not remove then add > again) :) > > Chris > > On 13 feb, 18:10, Sanfor

[Moo] Re: remove CSS all classes from element except one

2010-02-13 Thread cbolson
Thanks for that :) I am actually using something along those lines I was just hoping that there might be a "cleverer" way to do it (ie not remove then add again) :) Chris On 13 feb, 18:10, Sanford Whiteman wrote: > http://mootools.net/shell/w4fc5/1/ > > -- S.