1/*! 2 Autosize 3.0.5 3 license: MIT 4 http://www.jacklmoore.com/autosize 5*/ 6(function (global, factory) { 7 if (typeof define === 'function' && define.amd) { 8 define(['exports', 'module'], factory); 9 } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') { 10 factory(exports, module); 11 } else { 12 var mod = { 13 exports: {} 14 }; 15 factory(mod.exports, mod); 16 global.autosize = mod.exports; 17 } 18})(this, function (exports, module) { 19 'use strict'; 20 21 function assign(ta) { 22 var _ref = arguments[1] === undefined ? {} : arguments[1]; 23 24 var _ref$setOverflowX = _ref.setOverflowX; 25 var setOverflowX = _ref$setOverflowX === undefined ? true : _ref$setOverflowX; 26 var _ref$setOverflowY = _ref.setOverflowY; 27 var setOverflowY = _ref$setOverflowY === undefined ? true : _ref$setOverflowY; 28 29 if (!ta || !ta.nodeName || ta.nodeName !== 'TEXTAREA' || ta.hasAttribute('data-autosize-on')) return; 30 31 var heightOffset = null; 32 var overflowY = 'hidden'; 33 34 function init() { 35 var style = window.getComputedStyle(ta, null); 36 37 if (style.resize === 'vertical') { 38 ta.style.resize = 'none'; 39 } else if (style.resize === 'both') { 40 ta.style.resize = 'horizontal'; 41 } 42 43 if (style.boxSizing === 'content-box') { 44 heightOffset = -(parseFloat(style.paddingTop) + parseFloat(style.paddingBottom)); 45 } else { 46 heightOffset = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth); 47 } 48 49 update(); 50 } 51 52 function changeOverflow(value) { 53 { 54 // Chrome/Safari-specific fix: 55 // When the textarea y-overflow is hidden, Chrome/Safari do not reflow the text to account for the space 56 // made available by removing the scrollbar. The following forces the necessary text reflow. 57 var width = ta.style.width; 58 ta.style.width = '0px'; 59 // Force reflow: 60 /* jshint ignore:start */ 61 ta.offsetWidth; 62 /* jshint ignore:end */ 63 ta.style.width = width; 64 } 65 66 overflowY = value; 67 68 if (setOverflowY) { 69 ta.style.overflowY = value; 70 } 71 72 update(); 73 } 74 75 function update() { 76 var startHeight = ta.style.height; 77 var htmlTop = document.documentElement.scrollTop; 78 var bodyTop = document.body.scrollTop; 79 var originalHeight = ta.style.height; 80 81 ta.style.height = 'auto'; 82 83 var endHeight = ta.scrollHeight + heightOffset; 84 85 if (ta.scrollHeight === 0) { 86 // If the scrollHeight is 0, then the element probably has display:none or is detached from the DOM. 87 ta.style.height = originalHeight; 88 return; 89 } 90 91 ta.style.height = endHeight + 'px'; 92 93 // prevents scroll-position jumping 94 document.documentElement.scrollTop = htmlTop; 95 document.body.scrollTop = bodyTop; 96 97 var style = window.getComputedStyle(ta, null); 98 99 if (style.height !== ta.style.height) { 100 if (overflowY !== 'visible') { 101 changeOverflow('visible'); 102 return; 103 } 104 } else { 105 if (overflowY !== 'hidden') { 106 changeOverflow('hidden'); 107 return; 108 } 109 } 110 111 if (startHeight !== ta.style.height) { 112 var evt = document.createEvent('Event'); 113 evt.initEvent('autosize:resized', true, false); 114 ta.dispatchEvent(evt); 115 } 116 } 117 118 var destroy = (function (style) { 119 window.removeEventListener('resize', update); 120 ta.removeEventListener('input', update); 121 ta.removeEventListener('keyup', update); 122 ta.removeAttribute('data-autosize-on'); 123 ta.removeEventListener('autosize:destroy', destroy); 124 125 Object.keys(style).forEach(function (key) { 126 ta.style[key] = style[key]; 127 }); 128 }).bind(ta, { 129 height: ta.style.height, 130 resize: ta.style.resize, 131 overflowY: ta.style.overflowY, 132 overflowX: ta.style.overflowX, 133 wordWrap: ta.style.wordWrap }); 134 135 ta.addEventListener('autosize:destroy', destroy); 136 137 // IE9 does not fire onpropertychange or oninput for deletions, 138 // so binding to onkeyup to catch most of those events. 139 // There is no way that I know of to detect something like 'cut' in IE9. 140 if ('onpropertychange' in ta && 'oninput' in ta) { 141 ta.addEventListener('keyup', update); 142 } 143 144 window.addEventListener('resize', update); 145 ta.addEventListener('input', update); 146 ta.addEventListener('autosize:update', update); 147 ta.setAttribute('data-autosize-on', true); 148 149 if (setOverflowY) { 150 ta.style.overflowY = 'hidden'; 151 } 152 if (setOverflowX) { 153 ta.style.overflowX = 'hidden'; 154 ta.style.wordWrap = 'break-word'; 155 } 156 157 init(); 158 } 159 160 function destroy(ta) { 161 if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; 162 var evt = document.createEvent('Event'); 163 evt.initEvent('autosize:destroy', true, false); 164 ta.dispatchEvent(evt); 165 } 166 167 function update(ta) { 168 if (!(ta && ta.nodeName && ta.nodeName === 'TEXTAREA')) return; 169 var evt = document.createEvent('Event'); 170 evt.initEvent('autosize:update', true, false); 171 ta.dispatchEvent(evt); 172 } 173 174 var autosize = null; 175 176 // Do nothing in Node.js environment and IE8 (or lower) 177 if (typeof window === 'undefined' || typeof window.getComputedStyle !== 'function') { 178 autosize = function (el) { 179 return el; 180 }; 181 autosize.destroy = function (el) { 182 return el; 183 }; 184 autosize.update = function (el) { 185 return el; 186 }; 187 } else { 188 autosize = function (el, options) { 189 if (el) { 190 Array.prototype.forEach.call(el.length ? el : [el], function (x) { 191 return assign(x, options); 192 }); 193 } 194 return el; 195 }; 196 autosize.destroy = function (el) { 197 if (el) { 198 Array.prototype.forEach.call(el.length ? el : [el], destroy); 199 } 200 return el; 201 }; 202 autosize.update = function (el) { 203 if (el) { 204 Array.prototype.forEach.call(el.length ? el : [el], update); 205 } 206 return el; 207 }; 208 } 209 210 module.exports = autosize; 211});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.