Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute names starting on 'on' don't work #190

Open
tedbeer opened this issue May 3, 2013 · 16 comments
Open

Attribute names starting on 'on' don't work #190

tedbeer opened this issue May 3, 2013 · 16 comments

Comments

@tedbeer
Copy link

tedbeer commented May 3, 2013

Attribute names starting on 'on' don't work.
Example (@on is not readable):

<div on="XXX"></div>

In normal HTML documents they work.

@ilinsky
Copy link
Member

ilinsky commented May 3, 2013

Do you mean you cannot set/get attributes starting "on" ? What are the use cases for such feature?

@tedbeer
Copy link
Author

tedbeer commented May 3, 2013

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.

@ilinsky
Copy link
Member

ilinsky commented May 4, 2013

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?

@tedbeer
Copy link
Author

tedbeer commented May 4, 2013

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.

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

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?

@tedbeer
Copy link
Author

tedbeer commented May 6, 2013

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')

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

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.

@tedbeer
Copy link
Author

tedbeer commented May 6, 2013

Can't you use lazy evaluation? Until event fires event handler is not created? That's how it works in FF/Chrome.

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

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?

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

Ed, can you open separate request for lazy evaluation?

@tedbeer
Copy link
Author

tedbeer commented May 6, 2013

All attributes including inline handlers should be treated as attributes. But some of them may have additional meaning.

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

Ok, who and how should make sense of 'some with additional meaning'? Suggestions?

@tedbeer
Copy link
Author

tedbeer commented May 6, 2013

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.

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

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.

@tedbeer
Copy link
Author

tedbeer commented May 6, 2013

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.

@ilinsky
Copy link
Member

ilinsky commented May 6, 2013

Who and where do you think should provide "special meaning" to attributes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants