-
Notifications
You must be signed in to change notification settings - Fork 14
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
Implement HTMLInputElement.prototype.labels & tests #35
Comments
eventually, won't be done for a while. We really should work on a single shim project together ;) much more efficient |
I would be glad to. Is this thread stable, or I need to Fork Dev version? |
This thread is stable, but I'm going to restructure the entire thing for increased modularity. One of the aims of the DOM-shim is to be able to just package Since the full CSSOM/DOM/DOMEvents/HTML/XHR shim will come into 50kb gzipped. I plan to have it refactored in a stable state end of next weekend. Of course any additions added to the current project can be ported by me to the new format. |
Here's some code from our project at work. Has a jQuery dependency and returns an array instead of a Remember that you need it for more than just if (!("labels" in document.createElement("input"))) {
Object.defineProperty(HTMLElement.prototype, "labels", {
enumerable: true,
get: function () {
var labelsFromId = this.id ?
Array.from(document.querySelectorAll("label[for='" + this.id + "']")) :
[];
// TODO: can we eliminate jQuery here?
var parentLabel = jQuery(this).closest("label");
if (parentLabel.length === 0) {
return labelsFromId;
} else {
return parentLabel.toArray().concat(labelsFromId);
}
}
});
} |
var parentLabel = this.parentNode
while (parentLabel && parentLabel.tagName !== "LABEL") parentLabel = parentLabel.parentNode
As an aside it's pretty cool to see you use the ES6 shim ( |
Strange behavior in different browsers in which is implemented this feature Try this https://github.com/termi1uc1/ES5-DOM-SHIM/blob/master/tests/new/HTMLInputElement.labels.html Spec say: "... NodeList object associated with them that represents the list of label elements, in tree order, whose labeled control is the element in question" I am confused Too early you closed this issue |
And one question: Or it will be not bad if implement it in HTMLElement.prototype ? |
You've got duplicate ids what do you expect? I think opera grabs the last element with id if you reference it as window and chrome grab the first element with said id. Also note duplicate ids is invalid HTML and thus undefined behaviour. |
I would personally implement them as
|
As for closing, I seemed to have cloased and commented by accident. |
Re: "You've got duplicate ids what do you expect?" |
I think the reason chrome and opera differ is that chrome says "return all labels for this element" and opera says "return all labels for the form that this element belongs to" It may be an issue with the lack of |
The same sh*t :( I think we need to chose wich implementation is right and bugfixing other implementation |
Details: |
I am asked https://twitter.com/#!/ODevRel_ru . He promised check it out |
Webkit do it right. There is a bug in Opera https://twitter.com/statuses/162234890039988224 |
Can't understand how to pull "labels" in your style guide.
How to do this using M8 ? |
In case your not aware you should not type m8 code seperately. You should use As for how this would be done, ideally you would create 8 new interface files "HTMLInputElement", "HTMLButtonElement", etc and add them to the interfaces folder. However I'm going to restructure everything shortly so I'm not sure what the ideal option is. For now just cheat and add it to HTMLElement and make a new interface file for HTMLElement. |
Ready to pull request "+ Implement HTML*Element.labels" as soon as you accept/reject my previous request |
http://www.w3.org/TR/html5/forms.html#dom-lfe-labels
The text was updated successfully, but these errors were encountered: