Extend Custom Events To Run Default Event Handler From Custom Attributes
Reported by David Fenster | July 3rd, 2008 @ 06: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 July 3rd, 2008 @ 07: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 July 3rd, 2008 @ 07: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 July 3rd, 2008 @ 09: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 July 3rd, 2008 @ 09:50 PM
Thanks for explaining it to me.
Is there any purpose to requiring a colon character in custom events?
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
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.
