Attribute names starting on 'on' don't work
Attribute names starting on 'on' don't work. Example (@on is not readable):
<div on="XXX"></div>
In normal HTML documents they work.
Do you mean you cannot set/get attributes starting "on" ? What are the use cases for such feature?
The use case is simple - natural attribute names. I wanted to have attributes "on", "off" but I can't. I can't have attributes online, one, onion, onyx etc or any other starting from these words.
Ok, suppose you create an attribute onyyy, do you expect the value of this attribute to be treated as event handler and be evaluated if an event with name "yyy" propagates through the element with such attribute?
Why not to copy browsers behavior? "Standard" events can be handled via inline handlers but not custom events.
<div onmousemove="console.log(888)" onxxx="console.log(999)"></div>
@onmousemove handles 'mousemove' events but @onxxx does not handle 'xxx' event. And both @onmousemove and @onxxx are accessible via .getAttribute() method.
In Ample SDK we have generic support for multiple XML technologies and also let creating custom ones. The list of "Standard" events does not cover all languages, and building specific language technology into the core of the framework doesn't sound as viable solution.
I see this behaviour as a nice generic approach to inline handlers in attributes working consistently across all XML languages? Suggested by you list of attributes: online, one, onion, onyx and on, sounds like a list of values for attributes with other names, except for maybe one - "online", but even here an attribute "state" with values online/offline could be of a good alternative.
What do you think?
You don't realize that an attribute name can't even start from any of this words. I wanted to create attributes 'onLabel', 'offLabel' but I can't. Ok, let's skip "standard" events. But why I can't read/set attributes via .getAttribute()/.setAttribute() ? It's possible in browser to read value like
element.getAttribute('onmousemove')
Yes, this is correct: by design all attribute names starting "on" have been reserved for "inline event handlers". As for suggested names, it is better to name them "labelOn" and "labelOff". The reason for hiding on-attributes from setAttribute/getAttribute was problem with ordering/finding handlers on the node. This can now be changed, however any attribute starting "on" would still throw handler compilation error if its content is not valid JavaScript.
Can't you use lazy evaluation? Until event fires event handler is not created? That's how it works in FF/Chrome.
Good idea for optimization. I will look if this is possible. Still, suppose it is lazy evaluated, and event passes through with matching name, should the attribute be then treated as handler? Isn't this going to be source of unexpected problems?
Ed, can you open separate request for lazy evaluation?
All attributes including inline handlers should be treated as attributes. But some of them may have additional meaning.
Ok, who and how should make sense of 'some with additional meaning'? Suggestions?
At this moment attributes starting 'on-' can be treated in 2 ways. But I agree - without lazy evaluating it will be hard to solve the issue.
Question is still open. Suppose we have lazy evaluation in place. Now there is an attribute "once" specified on an element, and an event passes this node with name "ce". Shall the handler be instantiated now and invoked? If not, who and where would have to have provided instructions otherwise.
When @once attribute is created and special meaning is detected null event handler is created to handle 'ce' events. When 'ce' event is fired null event handler is replaced by actual event handler and invoked. At this moment syntax error exception can be thrown if attribute value is invalid JS. When @once attribute is removed related event handler also is removed.
Who and where do you think should provide "special meaning" to attributes?