forked from LeaVerou/stretchy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stretchy.min.js.map
1 lines (1 loc) · 9.26 KB
/
stretchy.min.js.map
1
{"version":3,"sources":["stretchy.js"],"names":["$$","expr","con","Node","Window","slice","call","document","querySelectorAll","self","Element","prototype","matches","webkitMatchesSelector","mozMatchesSelector","msMatchesSelector","oMatchesSelector","_","Stretchy","selectors","base","split","join","filter","script","currentScript","pop","resize","element","resizes","cs","getComputedStyle","offset","value","placeholder","empty","type","nodeName","toLowerCase","style","height","boxSizing","offsetHeight","clientHeight","parseFloat","minHeight","scrollHeight","width","offsetWidth","clientWidth","minWidth","scrollLeft","Math","max","scrollWidth","length","selectedIndex","option","createElement","textContent","options","parentNode","insertBefore","nextSibling","appearance","property","test","removeChild","resizeAll","elements","forEach","active","init","getAttribute","body","readyState","addEventListener","listener","evt","target","documentElement","MutationObserver","mutations","mutation","addedNodes","observe","childList","subtree"],"mappings":"CAKA,WAcA,QAASA,GAAGC,EAAMC,GACjB,MAAOD,aAAgBE,OAAQF,YAAgBG,SAASH,MAC9CI,MAAMC,KAAoB,gBAARL,IAAmBC,GAAOK,UAAUC,iBAAiBP,GAAQA,OAd1F,GAAKQ,KAAKC,UAILA,QAAQC,UAAUC,UACtBF,QAAQC,UAAUC,QAAUF,QAAQC,UAAUE,uBAAyBH,QAAQC,UAAUG,oBAAsBJ,QAAQC,UAAUI,mBAAqBL,QAAQC,UAAUK,kBAAoB,MAGxLN,QAAQC,UAAUC,SAAvB,CASA,GAAIK,GAAIR,KAAKS,UACZC,WACCC,KAAM,gEAAkE,qBAAqBC,MAAM,KAAKC,KAAK,oBAAsB,KACnIC,OAAQ,KAITC,OAAQjB,SAASkB,eAAiBzB,EAAG,UAAU0B,MAG/CC,OAAQ,SAASC,GAChB,GAAKX,EAAEY,QAAQD,GAAf,CAIA,GAAIE,GAAKC,iBAAiBH,GACtBI,EAAS,CAEb,KAAKJ,EAAQK,OAASL,EAAQM,YAAa,CAC1C,GAAIC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AAOT,YAAc,KAEtClB,EAAGkC,IAAkC,SAAnBlC,EAAGkC,KAEzBpC,EAAQW,MAAMQ,MAAQ,QAAUnB,EAAQW,MAAMQ,MAAQ,YAIxDU,EAAOI,WAAWM,YAAYV,GAC9BA,EAAS,KAGNtB,IACHP,EAAQK,MAAQ,MAKlBmC,UAAW,SAASC,GACnBrE,EAAGqE,GAAYpD,EAAEE,UAAUC,MAAMkD,QAAQ,SAAU1C,GAClDX,EAAEU,OAAOC,MAIX2C,QAAQ,EAGR1C,QAAS,SAASD,GACjB,MAAOA,IACAA,EAAQiC,YACRjC,EAAQhB,SACRgB,EAAQhB,QAAQK,EAAEE,UAAUC,OAC5BQ,EAAQhB,QAAQK,EAAEE,UAAUI;EAGpCiD,KAAM,WACLvD,EAAEE,UAAUI,OAASN,EAAEO,OAAOiD,aAAa,iBACrBzE,EAAG,0BAA0B0B,OAASnB,SAASmE,MAAMD,aAAa,yBAA2BvD,SAASC,UAAUI,QAAU,IAEhJN,EAAEmD,aAGHpE,GAAIA,EAMuB,aAAxBO,SAASoE,WACZ1D,EAAEuD,OAIFjE,SAASqE,iBAAiB,mBAAoB3D,EAAEuD,KAIjD,IAAIK,GAAW,SAASC,GACnB7D,EAAEsD,QACLtD,EAAEU,OAAOmD,EAAIC,QAIfxE,UAASyE,gBAAgBJ,iBAAiB,QAASC,GAGnDtE,SAASyE,gBAAgBJ,iBAAiB,SAAUC,GAGhDpE,KAAKwE,kBACR,GAAKA,kBAAiB,SAASC,GAC1BjE,EAAEsD,QACLW,EAAUZ,QAAQ,SAASa,GACL,aAAjBA,EAAS/C,MACZlB,SAASkD,UAAUe,EAASC,gBAI5BC,QAAQ9E,SAASyE,iBACpBM,WAAW,EACXC,SAAS","file":"stretchy.min.js","sourcesContent":["/*\n * Stretchy: Form element autosizing, the way it should be.\n * by Lea Verou http://lea.verou.me\n * MIT license\n */\n(function() {\n\nif (!self.Element) {\n\treturn; // super old browser\n}\n\nif (!Element.prototype.matches) {\n\tElement.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || null;\n}\n\nif (!Element.prototype.matches) {\n\treturn;\n}\n\nfunction $$(expr, con) {\n\treturn expr instanceof Node || expr instanceof Window? [expr] :\n\t [].slice.call(typeof expr == \"string\"? (con || document).querySelectorAll(expr) : expr || []);\n}\n\nvar _ = self.Stretchy = {\n\tselectors: {\n\t\tbase: 'textarea, select:not([size]), input:not([type]), input[type=\"' + \"text url email tel\".split(\" \").join('\"], input[type=\"') + '\"]',\n\t\tfilter: \"*\"\n\t},\n\n\t// Script element this was included with, if any\n\tscript: document.currentScript || $$(\"script\").pop(),\n\n\t// Autosize one element. The core of Stretchy.\n\tresize: function(element) {\n\t\tif (!_.resizes(element)) {\n\t\t\treturn;\n\t\t}\n\n\t\tvar cs = getComputedStyle(element);\n\t\tvar offset = 0;\n\n\t\tif (!element.value && element.placeholder) {\n\t\t\tvar empty = true;\n\t\t\telement.value = element.placeholder;\n\t\t}\n\n\t\tvar type = element.nodeName.toLowerCase();\n\n\t\tif (type == \"textarea\") {\n\t\t\telement.style.height = \"0\";\n\n\t\t\tif (cs.boxSizing == \"border-box\") {\n\t\t\t\toffset = element.offsetHeight;\n\t\t\t}\n\t\t\telse if (cs.boxSizing == \"content-box\") {\n\t\t\t\toffset = -element.clientHeight + parseFloat(cs.minHeight);\n\t\t\t}\n\n\t\t\telement.style.height = element.scrollHeight + offset + \"px\";\n\t\t}\n\t\telse if(type == \"input\") {\n\t\t\t// First test that it is actually visible, otherwise all measurements are off\n\t\t\telement.style.width = \"1000px\";\n\n\t\t\tif (element.offsetWidth) {\n\t\t\t\telement.style.width = \"0\";\n\n\t\t\t\tif (cs.boxSizing == \"border-box\") {\n\t\t\t\t\toffset = element.offsetWidth;\n\t\t\t\t}\n\t\t\t\telse if (cs.boxSizing == \"padding-box\") {\n\t\t\t\t\toffset = element.clientWidth;\n\t\t\t\t}\n\t\t\t\telse if (cs.boxSizing == \"content-box\") {\n\t\t\t\t\toffset = parseFloat(cs.minWidth);\n\t\t\t\t}\n\n\t\t\t\t// Safari misreports scrollWidth, so we will instead set scrollLeft to a\n\t\t\t\t// huge number, and read that back to see what it was clipped to\n\t\t\t\telement.scrollLeft = 1e+10;\n\n\t\t\t\tvar width = Math.max(element.scrollLeft + offset, element.scrollWidth - element.clientWidth);\n\n\t\t\t\telement.style.width = width + \"px\";\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// Element is invisible, just set to something reasonable\n\t\t\t\telement.style.width = element.value.length + 1 + \"ch\";\n\t\t\t}\n\t\t}\n\t\telse if (type == \"select\") {\n\t\t\tvar selectedIndex = element.selectedIndex > 0? element.selectedIndex : 0;\n\n\t\t\t// Need to use dummy element to measure :(\n\t\t\tvar option = document.createElement(\"_\");\n\t\t\toption.textContent = element.options[selectedIndex].textContent;\n\t\t\telement.parentNode.insertBefore(option, element.nextSibling);\n\n\t\t\t// The name of the appearance property, as it might be prefixed\n\t\t\tvar appearance;\n\n\t\t\tfor (var property in cs) {\n\t\t\t\tvar value = cs[property];\n\t\t\t\tif (!/^(width|webkitLogicalWidth|length)$/.test(property) && typeof value == \"string\") {\n\t\t\t\t\t//console.log(property, option.offsetWidth, cs[property]);\n\t\t\t\t\toption.style[property] = value;\n\n\t\t\t\t\tif (/appearance$/i.test(property)) {\n\t\t\t\t\t\tappearance = property;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\toption.style.width = \"\";\n\n\t\t\tif (option.offsetWidth > 0) {\n\t\t\t\telement.style.width = option.offsetWidth + \"px\";\n\n\t\t\t\tif (!cs[appearance] || cs[appearance] !== \"none\") {\n\t\t\t\t\t// Account for arrow\n\t\t\t\t\telement.style.width = \"calc(\" + element.style.width + \" + 2em)\";\n\t\t\t\t}\n\t\t\t}\n\n\t\t\toption.parentNode.removeChild(option);\n\t\t\toption = null;\n\t\t}\n\n\t\tif (empty) {\n\t\t\telement.value = \"\";\n\t\t}\n\t},\n\n\t// Autosize multiple elements\n\tresizeAll: function(elements) {\n\t\t$$(elements || _.selectors.base).forEach(function (element) {\n\t\t\t_.resize(element);\n\t\t});\n\t},\n\n\tactive: true,\n\n\t// Will stretchy do anything for this element?\n\tresizes: function(element) {\n\t\treturn element &&\n\t\t element.parentNode &&\n\t\t element.matches &&\n\t\t element.matches(_.selectors.base) &&\n\t\t element.matches(_.selectors.filter);\n\t},\n\n\tinit: function(){\n\t\t_.selectors.filter = _.script.getAttribute(\"data-filter\") ||\n\t\t ($$(\"[data-stretchy-filter]\").pop() || document.body).getAttribute(\"data-stretchy-filter\") || Stretchy.selectors.filter || \"*\";\n\n\t\t_.resizeAll();\n\t},\n\n\t$$: $$\n};\n\n// Autosize all elements once the DOM is loaded\n\n// DOM already loaded?\nif (document.readyState !== \"loading\") {\n\t_.init();\n}\nelse {\n\t// Wait for it\n\tdocument.addEventListener(\"DOMContentLoaded\", _.init);\n}\n\n// Listen for changes\nvar listener = function(evt) {\n\tif (_.active) {\n\t\t_.resize(evt.target);\n\t}\n};\n\ndocument.documentElement.addEventListener(\"input\", listener);\n\n// Firefox fires a change event instead of an input event\ndocument.documentElement.addEventListener(\"change\", listener);\n\n// Listen for new elements\nif (self.MutationObserver) {\n\t(new MutationObserver(function(mutations) {\n\t\tif (_.active) {\n\t\t\tmutations.forEach(function(mutation) {\n\t\t\t\tif (mutation.type == \"childList\") {\n\t\t\t\t\tStretchy.resizeAll(mutation.addedNodes);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t})).observe(document.documentElement, {\n\t\tchildList: true,\n\t\tsubtree: true\n\t});\n}\n\n})();\n"]}