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