| | 58 | var shrinkTextarea = window._.throttle( function() { |
| | 59 | var top = window.scrollTop; |
| | 60 | var height = parseInt( textEditor.style.height, 10 ); |
| | 61 | |
| | 62 | textEditorClone.value = textEditor.value; |
| | 63 | |
| | 64 | if ( textEditorClone.scrollHeight > autoresizeMinHeight ) { |
| | 65 | textEditor.style.height = textEditorClone.scrollHeight + 'px'; |
| | 66 | } else if ( textEditorClone.scrollHeight < height ) { |
| | 67 | textEditor.style.height = autoresizeMinHeight + 'px'; |
| | 68 | } |
| | 69 | |
| | 70 | // Prevent scroll-jumping in Firefox and IE. |
| | 71 | window.scrollTop = top; |
| | 72 | |
| | 73 | if ( textEditor.scrollHeight < height ) { |
| | 74 | adjust(); |
| | 75 | } |
| | 76 | }, 500 ); |
| | 77 | |
| | 78 | function textEditorResize() { |
| | 79 | var length = textEditor.value.length; |
| | 80 | |
| | 81 | if ( mceEditor && ! mceEditor.isHidden() ) { |
| | 82 | return; |
| | 83 | } |
| | 84 | |
| | 85 | if ( ! mceEditor && initialMode === 'tinymce' ) { |
| | 86 | return; |
| | 87 | } |
| | 88 | |
| | 89 | if ( length < oldTextLength ) { |
| | 90 | shrinkTextarea(); |
| | 91 | } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) { |
| | 92 | textEditor.style.height = Math.ceil( textEditor.scrollHeight ) + 'px'; |
| | 93 | adjust(); |
| | 94 | } |
| | 95 | |
| | 96 | oldTextLength = length; |
| | 97 | } |
| | 98 | |
| 83 | | if ( ! mceEditor && initialMode === 'tinymce' ) { |
| 84 | | return; |
| 85 | | } |
| 86 | | |
| 87 | | var length = textEditor.value.length; |
| 88 | | var height = parseInt( textEditor.style.height, 10 ); |
| 89 | | var top = window.scrollTop; |
| 90 | | |
| 91 | | if ( length < oldTextLength ) { |
| 92 | | // textEditor.scrollHeight is not adjusted until the next line. |
| 93 | | textEditor.style.height = 'auto'; |
| 94 | | |
| 95 | | if ( textEditor.scrollHeight > autoresizeMinHeight ) { |
| 96 | | textEditor.style.height = textEditor.scrollHeight + 'px'; |
| 97 | | } else { |
| 98 | | textEditor.style.height = autoresizeMinHeight + 'px'; |
| 99 | | } |
| 100 | | |
| 101 | | // Prevent scroll-jumping in Firefox and IE. |
| 102 | | window.scrollTop = top; |
| 103 | | |
| 104 | | if ( textEditor.scrollHeight < height ) { |
| 105 | | adjust(); |
| 106 | | } |
| 107 | | } else if ( height < textEditor.scrollHeight ) { |
| 108 | | textEditor.style.height = textEditor.scrollHeight + 'px'; |
| 109 | | adjust(); |
| 110 | | } |
| 111 | | |
| 112 | | oldTextLength = length; |
| 113 | | } |
| 114 | | |