Thanks for all the helpful tips guys.

And don't worry this was not production code, I was just playing
around with some different options before actually working on the
finalized bit. This was sort of the proof of concept; I wanted to see
if I was tackling it in the right way.

thanks again!

On Sep 25, 12:43 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> > I was just curious if there were any tips or short cuts anyone had. In
> > particular, I was trying to condense some of the code down...
>
> Why?  It's already pretty dense, and as Justin pointed out earlier you
> may already be setting yourself up for maintenance hassles down the
> line.
>
> > ...This part:
>
> >         divs.invoke("hide");
> >         $(section_id).show();
>
> My issue with that code wouldn't be size, it'd be flicker if we're
> showing the div that's already showing (as it gets hidden and
> reshown).  This avoids invoke and flicker:
>
>     divs.each(function(div) {
>         if (div.id == section_id) {
>             div.show();
>         } else {
>             div.hide();
>         }
>     });
>
> or if you want to get *really* obscure:
>
>     divs.each(function(div) {
>         div[div.id == section_id ? 'show' : 'hide']();
>     });
>
> FWIW, though, I'd be looking at splitting that code up into several
> named functions, adding comments and whitespace, moving all the var
> declarations to the beginnings of functions (as that's where they take
> effect anyway), and then if you're worried about download size use a
> minifier and gzip.
> --
> T.J. Crowder
> tj / crowder software / com
>
> On Sep 25, 1:16 am, solidhex <[EMAIL PROTECTED]> wrote:
>
> > Yes the code does work :)
>
> > I was just curious if there were any tips or short cuts anyone had. In
> > particular, I was trying to condense some of the code down, but I
> > can't seem to figure out a way to chain hiding all the divs, and only
> > showing the current one, instead of splitting it into two lines. This
> > part:
>
> >         divs.invoke("hide");
> >         $(section_id).show();
>
> > I know there is a way to filter in jQuery and was wondering if there
> > was something similar in Prototype.
>
> > On Sep 24, 9:18 am, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
>
> > > I prefer not to nest my code like that, I feel like it is difficult to
> > > read and hard to extend/modify (read: fragile), but if that's how you
> > > like to read your code and you find it easier to read/write, then
> > > that's all that matters.
>
> > > I think if that code works for you now, then you should just be happy
> > > with it. Keep writing JavaScript and then revisit this code in a few
> > > months and you'll probably have an idea or two for improving it.
>
> > > -justin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to