forked from LeaVerou/stretchy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stretchy.min.js
4 lines (4 loc) · 2.7 KB
/
stretchy.min.js
1
2
3
4
!function(){function e(e,t){return e instanceof Node||e instanceof Window?[e]:[].slice.call("string"==typeof e?(t||document).querySelectorAll(e):e||[])}if(self.Element&&(Element.prototype.matches||(Element.prototype.matches=Element.prototype.webkitMatchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||null),Element.prototype.matches)){var t=self.Stretchy={selectors:{base:'textarea, select:not([size]), input:not([type]), input[type="'+"text url email tel".split(" ").join('"], input[type="')+'"]',filter:"*"},script:document.currentScript||e("script").pop(),resize:function(e){if(t.resizes(e)){var i=getComputedStyle(e),n=0;if(!e.value&&e.placeholder){var o=!0;e.value=e.placeholder}var l=e.nodeName.toLowerCase();if("textarea"==l)e.style.height="0","border-box"==i.boxSizing?n=e.offsetHeight:"content-box"==i.boxSizing&&(n=-e.clientHeight+parseFloat(i.minHeight)),e.style.height=e.scrollHeight+n+"px";else if("input"==l)if(e.style.width="1000px",
e.offsetWidth){e.style.width="0","border-box"==i.boxSizing?n=e.offsetWidth:"padding-box"==i.boxSizing?n=e.clientWidth:"content-box"==i.boxSizing&&(n=parseFloat(i.minWidth)),e.scrollLeft=1e10;var r=Math.max(e.scrollLeft+n,e.scrollWidth-e.clientWidth);e.style.width=r+"px"}else e.style.width=e.value.length+1+"ch";else if("select"==l){var s=e.selectedIndex>0?e.selectedIndex:0,c=document.createElement("_");c.textContent=e.options[s].textContent,e.parentNode.insertBefore(c,e.nextSibling);var a;for(var d in i){var h=i[d];/^(width|webkitLogicalWidth|length)$/.test(d)||"string"!=typeof h||(c.style[d]=h,/appearance$/i.test(d)&&(a=d))}c.style.width="",c.offsetWidth>0&&(e.style.width=c.offsetWidth+"px",i[a]&&"none"===i[a]||(e.style.width="calc("+e.style.width+" + 2em)")),c.parentNode.removeChild(c),c=null}o&&(e.value="")}},resizeAll:function(i){e(i||t.selectors.base).forEach(function(e){t.resize(e)})},active:!0,resizes:function(e){return e&&e.parentNode&&e.matches&&e.matches(t.selectors.base)&&e.matches(t.selectors.filter);
},init:function(){t.selectors.filter=t.script.getAttribute("data-filter")||(e("[data-stretchy-filter]").pop()||document.body).getAttribute("data-stretchy-filter")||Stretchy.selectors.filter||"*",t.resizeAll()},$$:e};"loading"!==document.readyState?t.init():document.addEventListener("DOMContentLoaded",t.init);var i=function(e){t.active&&t.resize(e.target)};document.documentElement.addEventListener("input",i),document.documentElement.addEventListener("change",i),self.MutationObserver&&new MutationObserver(function(e){t.active&&e.forEach(function(e){"childList"==e.type&&Stretchy.resizeAll(e.addedNodes)})}).observe(document.documentElement,{childList:!0,subtree:!0})}}();
//# sourceMappingURL=stretchy.min.js.map