Re: [Proto-Scripty] Re: element.observ on classname+id *

2010-02-23 Thread green
Hi T.J.

I like your idea of the efficient version of bindage function. I have a
similar case but this time i got to use "new Field.observer". There is a
list of options which people can select to enter some number. I have hooked
a new Field.observer with each "input" element to validate the number user
has entered. As you said it could be very inefficient to create an new
observer to each input field. Do you have any suggestion here?

TIA,
Green

On Sun, Feb 21, 2010 at 2:31 PM, T.J. Crowder wrote:

>  T.J. Crowder (prototype-scriptaculous@googlegroups.com) is on your Guest
> List  | Delete this 
> guest
>
> Hi Jinsa,
>
> Your `bindage` method nearly works, you just have to change `$
> ('menu').down('li').each` to `$('menu').select('li').each`.
> Element#down (with no index argument) finds the first matching
> descendant element and returns it; Element#select finds all matching
> descendant elements and returns them as an array. My use of
> Element#select here assumes that you *know* there won't be any nested
> lists, as it will match all descendant LIs, even those in nested lists
> within the list you're searching.
>
> But `bindage` can be improved. You're creating a new function for each
> LI, which is inefficient and unnecessary. You could do this:
>
> function bindage()
> {
>$('menu').select('li').invoke('observe', 'click', function(event)
> {
>event.stop();
>alert('hellow bro');
>});
> }
>
> or this, which has the advantage of using a named function (which
> makes it possible for your tools to help you -- showing function names
> in stack traces, etc.):
>
> function bindage()
> {
>$('menu').select('li').invoke('observe', 'click',
> bindage_liClick);
>
>function bindage_liClick(event)
>{
>event.stop();
>alert('hellow bro');
>}
> }
>
> Both of those use a single function to watch all of LIs.
>
> But wait, there's more: Why watch the individual LIs at all? The click
> event bubbles up the DOM, so you could just watch the UL -- unnamed
> example:
>
> function bindage()
> {
>$('menu').observe('click', function(event) {
>var li;
>
>li = event.findElement('li');
>if (li)
>{
>event.stop();
>alert('hellow bro');
>}
>});
> }
>
> or (named):
>
> function bindage()
> {
>$('menu').observe('click', bindage_ulClick);
>
>function bindage_ulClick(event)
>{
>var li;
>
>li = event.findElement('li');
>if (li)
>{
>event.stop();
>alert('hellow bro');
>}
>}
> }
>
> HTH,
> --
> T.J. Crowder
> Independent Software Consultant
> tj / crowder software / com
> www.crowdersoftware.com
>
>
> On Feb 20, 1:58 pm, Jinsa  wrote:
> > Hi everybody!
> >
> > I'm actually working on a script acting on a UL menu with different LI
> > classname. The goal is to react onMouseOver and onClick on each LI
> > click or mouseover differently. The fact is the class is unknown so my
> > script have to check the UL and then observe each LI as elements.
> >
> > Here is the html:
> >
> > 
> >   First
> >   Second
> >   Third
> >   Vador
> >   What the!
> >   Hahum!
> > 
> >
> > and then the script:
> >
> > function bindage()
> > {
> > $('menu').down('li').each(function (el)
> > {
> > return $(el).observe('click', function(event)
> > {
> > event.stop();
> > alert('hellow bro');
> > });
> > });
> >
> > }
> >
> > Event.observe(window, 'load', bindage);
> >
> > But that obviously doesn't work... I really don't have any idea to
> > make it work... I've tried so far but without any success... maybe you
> > could help me?
> >
> > Thanks,
> >
> > JF.
>
> --
> 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-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>
>

-- 
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-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] Re: element.observ on classname+id

2010-02-20 Thread agnese camellini
Hi jinsa, i'm not a professional but for what i've been reading yesterday i
can say you where is the problem.
I mean where to begin.
The approach can be pretty different if you are using a framework (Mootools
scriptaculous jQuery) or you are writing javascript by yourself (which i
think in order to have a solution need much more time to be elaborated.

Here is the link to elaborate the problem:

http://www.quirksmode.org/js/events_order.html
http://www.quirksmode.org/js/introevents.html

I'm actually having a problem like yours in writing down the scheme for a
gallery, BUT, i will try a first (temporary) solution with jQuery (which is
largely compatible), in the meanwhile i'll elaborate a more robust one with
the help of the site manual i showed to you.
don't know how much it will take but however i have time.

So if you find some better link. let me know.

;)


2010/2/20 Jinsa 

> The Html given is not good, the one I use is:
>
> 
>  Accueil
>  Programmes
>  A l'affiche
>  Débats
>  Intervenants
>  Infos-Pratiques
> 
>
> but it doesn't change the fact that's not wroking ^^.
>
> If someone can help :)
>
> Thanks :)
>
> --
> 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-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>

-- 
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-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.