#204 ✓not_for_core
David Fenster

Extend Custom Events To Run Default Event Handler From Custom Attributes

Reported by David Fenster | July 3rd, 2008 @ 08:45 PM

Could you enhance the library so that the event fire function will check for default event handlers in custom attributes?

The idea actually comes from some of the pre-existing events like onclick. If I had an attribute on my body element for onclick, it would automatically become an event handler. In the same way, I'd like a custom events (such as a made-up event called titlechanged) to look for attributes called titlechanged on elements as it bubbles up, and execute them as if they were assumed to be javascript event handlers.

Comments and changes to this ticket

  • Juriy Zaytsev

    Juriy Zaytsev July 3rd, 2008 @ 09:22 PM

    • State changed from “new” to “not_for_core”

    So what you're saying is:

    <h2 ontitlechanged="highlight()" id="foo">
      foo bar baz
    </h2>
    

    would translate into:

    $('foo').observe(':titlechanged', highlight);
    

    I'm not exactly sure how custom attributes would translate into appropriate event names. Is "ontitlechanged" becomes "title:changed" or "titlec:hanged" or "tit:lechanged" ?

    I'm closing this as "not-for-core". Please feel free to reopen with a working patch/tests.

  • David Fenster

    David Fenster July 3rd, 2008 @ 09:59 PM

    That is very close to what I mean. I'm not really sure what the significance of the colon ':' character is, so I would have said it translated into:

    $('foo').observe('titlechanged', function(){ highlight() });

    The reason I wouldn't even bother with the colon is because I already know something like this works:

    $('foo').observe('onclick', function(){ highlight() });

    What is the significance of the colon ':' character? I apologize for asking that here if this is not the correct venue.

  • Juriy Zaytsev

    Juriy Zaytsev July 3rd, 2008 @ 11:21 PM

    David,

    1) custom events are required to have colon anywhere in a string.

    2) #observe requires a W3C-compliant event name (i.e. "click" rather than "onclick"), so your example doesn't really work:

    $(foo).observe('onclick', function(){ ... } ) // fails
    $(foo).observe('click', function(){ ... } ) // works
    
  • David Fenster

    David Fenster July 3rd, 2008 @ 11:50 PM

    Thanks for explaining it to me.

    Is there any purpose to requiring a colon character in custom events?

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:55 AM

    • Tag changed from attributes, custom, events, fire, observe to section:dom

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

  • Tobie Langel

    Tobie Langel July 24th, 2009 @ 03:56 AM

    [not-tagged:"events" tagged:"section:dom" bulk edit command]

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages