| | 56 | var shrinkTextarea = window._.throttle( function() { |
| | 57 | var x = window.scrollX || document.documentElement.scrollLeft; |
| | 58 | var y = window.scrollY || document.documentElement.scrollTop; |
| | 59 | var height = parseInt( textEditor.style.height, 10 ); |
| | 60 | |
| | 61 | textEditor.style.height = autoresizeMinHeight + 'px'; |
| | 62 | |
| | 63 | if ( textEditor.scrollHeight > autoresizeMinHeight ) { |
| | 64 | textEditor.style.height = textEditor.scrollHeight + 'px'; |
| | 65 | } |
| | 66 | |
| | 67 | if ( typeof x !== 'undefined' ) { |
| | 68 | window.scrollTo( x, y ); |
| | 69 | } |
| | 70 | |
| | 71 | if ( textEditor.scrollHeight < height ) { |
| | 72 | adjust(); |
| | 73 | } |
| | 74 | }, 300 ); |
| | 75 | |
| | 76 | function textEditorResize() { |
| | 77 | var length = textEditor.value.length; |
| | 78 | |
| | 79 | if ( mceEditor && ! mceEditor.isHidden() ) { |
| | 80 | return; |
| | 81 | } |
| | 82 | |
| | 83 | if ( ! mceEditor && initialMode === 'tinymce' ) { |
| | 84 | return; |
| | 85 | } |
| | 86 | |
| | 87 | if ( length < oldTextLength ) { |
| | 88 | shrinkTextarea(); |
| | 89 | } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) { |
| | 90 | textEditor.style.height = Math.ceil( textEditor.scrollHeight ) + 'px'; |
| | 91 | adjust(); |
| | 92 | } |
| | 93 | |
| | 94 | oldTextLength = length; |
| | 95 | } |
| | 96 | |
| 78 | | function textEditorResize() { |
| 79 | | if ( mceEditor && ! mceEditor.isHidden() ) { |
| 80 | | return; |
| 81 | | } |
| 82 | | |
| 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 | | |