diff options
-rw-r--r-- | res.js | 4 |
1 files changed, 0 insertions, 4 deletions
@@ -1,4 +0,0 @@ -var itemEntries=nodeListToArray(document.querySelectorAll(".g-Recipe ul > li")).map(function(a){return{tag:"li",node:a}}),h1=document.querySelector(".g-Recipe h1");null!==h1&&itemEntries.push({tag:"h1",node:h1});var inputs=setInputs(itemEntries);inputs.map(function(a){a.node.oninput=function(c){if(null!==c.target&&(c=parseNumber(c.target.value),void 0!==c&&""===c.before&&""===c.after)){var b=parseFloat(c.number)/a.number;inputs.map(function(a){a.node.value=(a.number*b).toString()})}}}); -function setInputs(a){for(var c=[],b=0;b<a.length;b++){var d=parseNumber(a[b].node.innerText);if(void 0!==d){var e=parsedNumberNode(a[b].tag,d),f=a[b].node.parentNode;f&&(f.replaceChild(e.all,a[b].node),c.push({number:parseFloat(d.number),node:e.number}))}}return c} -function parsedNumberNode(a,c){a=document.createElement(a);a.appendChild(document.createTextNode(c.before));var b=document.createElement("input");b.className="g-Number";b.value=c.number;a.appendChild(b);a.appendChild(document.createTextNode(c.after));return{all:a,number:b}} -function parseNumber(a){for(var c=0;c<a.length&&!isDigit(a.charAt(c));c++);if(c!==a.length){for(var b=c+1;b<a.length&&isDigit(a.charAt(b));b++);for(b<a.length&&("."===a.charAt(b)||","===a.charAt(b))&&b++;b<a.length&&isDigit(a.charAt(b));b++);return{before:a.substring(0,c),number:a.substring(c,b),after:a.substring(b,a.length)}}}function isDigit(a){return"0"<=a&&"9">=a}function nodeListToArray(a){var c=[];a.forEach(function(a){c.push(a)});return c}; |