Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ Implement HTML*Element.prototype.labels

  • Loading branch information...
commit 731f4db0cd8a9ecf4e1df2f2d6f0950abe8fe3df 1 parent 8a5dac4
@termi termi authored
Showing with 37 additions and 0 deletions.
  1. +37 −0 src/all/interfaces/HTMLElement.js
View
37 src/all/interfaces/HTMLElement.js
@@ -0,0 +1,37 @@
+module.exports = {
+ interface: window.HTMLElement || window.Element || window.Node,
+ labels: {
+ get: getLabels
+ }
+}
+
+/*
+https://developer.mozilla.org/en/DOM/HTMLInputElement
+http://www.w3.org/TR/html5/forms.html#dom-lfe-labels
+require: HTMLLabelElement.control
+*/
+function getLabels() {
+ //if(!~["INPUT", "BUTTON", "KEYGEN", "METER", "OUTPUT", "PROGRESS", "TEXTAREA", "SELECT"].indexOf(this.nodeName))
+ // return void 0;
+
+ var node = this,
+ /**
+ * represents the list of label elements, in [!]tree order[!]
+ * @type {Array}
+ */
+ result = this.id ?
+ Array.prototype.slice.apply(document.querySelectorAll("label[for='" + this.id + "']")) :
+ [],
+ _lastInTreeOrder_index = result.length - 1;
+
+ while((node = node.parentNode) && (!node.control || node.control === this))
+ if(node.nodeName === "LABEL") {
+
+ while(result[_lastInTreeOrder_index] &&
+ result[_lastInTreeOrder_index].compareDocumentPosition(node) & 2)//DOCUMENT_POSITION_PRECEDING
+ _lastInTreeOrder_index--;
+ result.splice(_lastInTreeOrder_index + 1, 0, node)
+ }
+
+ return result;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.