Skip to content

Instantly share code, notes, and snippets.

@termi
Forked from Raynos/polyfill.js
Created September 18, 2012 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save termi/3743724 to your computer and use it in GitHub Desktop.
Save termi/3743724 to your computer and use it in GitHub Desktop.
RadioNodeList polyfill
/*
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