| 145 | var clone = $('.quick-draft-textarea-clone'), |
| 146 | editor = $('#content'), |
| 147 | editorCurrentHeight = editor.height(), |
| 148 | editorOriginalHeight = editorCurrentHeight; |
| 149 | |
| 150 | // Match up textarea and clone div as much as possible |
| 151 | // Firefox is necessitates declaring each padding setting individually |
| 152 | clone.css({ 'font-family': editor.css('font-family'), |
| 153 | 'font-size': editor.css('font-size'), |
| 154 | 'line-height': editor.css('line-height'), |
| 155 | 'padding-bottom': editor.css('paddingBottom'), |
| 156 | 'padding-left': editor.css('paddingLeft'), |
| 157 | 'padding-right': editor.css('paddingRight'), |
| 158 | 'padding-top': editor.css('paddingTop') }); |
| 159 | |
| 160 | // Hide overflow on textarea |
| 161 | editor.css('overflow', 'hidden'); |
| 162 | |
| 163 | editor.on('keyup paste', function (e) { |
| 164 | var $this = $(this), |
| 165 | textareaContent = $this.val().replace(/\n/g, '<br>'), |
| 166 | cloneHeight = clone.css('width', $this.css('width')).html(textareaContent).height(); |
| 167 | |
| 168 | if (cloneHeight !== editorCurrentHeight) { |
| 169 | $this.css('height', clone.outerHeight() + 2 + 'px'); |
| 170 | $this.css('min-height', clone.outerHeight() + 59 + 'px'); |
| 171 | editorCurrentHeight = cloneHeight; |
| 172 | } |
| 173 | }); |
| 174 | } |
| 175 | |