Thanks Fábio. Yes, I had already added it to my version. Just thought
I'd make the suggestion in case others had seen a need for it.

Thanks for the quick replies. Good to see the community here is
alive! :)



On Apr 15, 10:48 pm, Fábio Costa <[email protected]> wrote:
> Anyway Mike, you know that you can create this function, right?
> I don't think that this function is something that will be used often to be
> inserted at the core.
>
> To add it:
>
> Element.implements({
>   enableClass: function(className, isEnabled) {
>     return (isEnabled) ? this.addClass(className) :
> this.removeClass(className);
>   }
>
> });
>
> The 'return' makes this function chainable.
>
> Fábio Miranda Costa
> Engenheiro de Computaçãohttp://meiocodigo.com
>
> On Wed, Apr 15, 2009 at 9:26 AM, Mike <[email protected]> wrote:
>
> > It's useful like this.
>
> > isCheckoutMode = $("cart").hasClass("checkout");
>
> > $("calculator").enable("checkout", isCheckoutMode);
> > $("catalog").enable("searching", !isCheckoutMode);
>
> > Without enable(), the code would need to look like this:
>
> > isCheckoutMode = $("cart").hasClass("checkout");
>
> > if (isCheckoutMode) {
> >  $("calculator").addClass("checkout");
> >  $("catalog").removeClass("searching");
> > } else {
> >  $("calculator").removeClass("checkout");
> >  $("catalog").addClass("searching");
> > }
>
> > It's not a toggle, because even if the class is currently applied, it
> > doesn't mean you will want to remove it. You are only enabling it
> > conditionally on some boolean value which may change dynamically as
> > the code is run.
>
> > On Apr 15, 9:28 pm, Fábio Costa <[email protected]> wrote:
> > > What is enabled in the context?
> > > I don't see where i'm going to use this.
> > > Do you have a code of your own that uses it and could you explain the
> > code?
>
> > > Have fun.
>
> > > Fábio Miranda Costa
> > > Engenheiro de Computaçãohttp://meiocodigo.com
>
> > > On Tue, Apr 14, 2009 at 10:31 PM, Mike <[email protected]> wrote:
>
> > > > Can I propose a new method of <Element> called enableClass? Makes
> > > > certain code much more compact.
>
> > > > ... <snip> ..
>
> > > > enableClass: function(className, isEnabled) {
> > > >   (isEnabled) ? this.addClass(className) : this.removeClass
> > > > (className);
> > > > },
>
> > > > ... <snip> ..

Reply via email to