-
-
Save termi/3743724 to your computer and use it in GitHub Desktop.
RadioNodeList polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
demo :- http://jsfiddle.net/termi/pyFXW/ | |
Implements RadioNodeList :- http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#radionodelist | |
Implementation just adds `.value` as a property to `NodeList`. | |
Requires ES5 shim and ES5 shimmable browser. (Modern and IE8) | |
*/ | |
;(function () { | |
var form = document.createElement("form") | |
, _NodeList_prototype_ | |
; | |
form.innerHTML = "<input type=radio name=t value=1><input type=radio checked name=t value=2>"; | |
if(form["t"] && form["t"]["value"] === 2)return; | |
_NodeList_prototype_ = | |
(_NodeList_prototype_ = form["t"]) && (_NodeList_prototype_ = _NodeList_prototype_.constructor) && _NodeList_prototype_.prototype | |
|| (_NodeList_prototype_ = NodeList) && _NodeList_prototype_.prototype | |
; | |
Object.defineProperty(_NodeList_prototype_, "value", { | |
get: function() { | |
if(!this[0] || !("form" in this[0]))return; | |
var k = this.length | |
, el | |
; | |
while(el = this[--k]) { | |
if (el.checked) { | |
return el.value; | |
} | |
} | |
}, | |
set: function(value) { | |
if(!this[0] || !("form" in this[0]))return; | |
var k = this.length | |
, el | |
; | |
while(el = this[--k]) { | |
if (el.checked) { | |
el.value = value; | |
return el.value; | |
} | |
} | |
}, | |
configurable: true | |
}); | |
_NodeList_prototype_ = form = void 0; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment