X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/b22765f41bf0b2021b9beb9120ee0ac91fa89292..f739362bc2205036998dacdccb4f07eda9048877:/wp-admin/js/editor-expand.js diff --git a/wp-admin/js/editor-expand.js b/wp-admin/js/editor-expand.js index bf67c64e..aaf34b0b 100644 --- a/wp-admin/js/editor-expand.js +++ b/wp-admin/js/editor-expand.js @@ -53,6 +53,47 @@ sideSortablesHeight: 0 }; + var shrinkTextarea = window._.throttle( function() { + var x = window.scrollX || document.documentElement.scrollLeft; + var y = window.scrollY || document.documentElement.scrollTop; + var height = parseInt( textEditor.style.height, 10 ); + + textEditor.style.height = autoresizeMinHeight + 'px'; + + if ( textEditor.scrollHeight > autoresizeMinHeight ) { + textEditor.style.height = textEditor.scrollHeight + 'px'; + } + + if ( typeof x !== 'undefined' ) { + window.scrollTo( x, y ); + } + + if ( textEditor.scrollHeight < height ) { + adjust(); + } + }, 300 ); + + function textEditorResize() { + var length = textEditor.value.length; + + if ( mceEditor && ! mceEditor.isHidden() ) { + return; + } + + if ( ! mceEditor && initialMode === 'tinymce' ) { + return; + } + + if ( length < oldTextLength ) { + shrinkTextarea(); + } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) { + textEditor.style.height = Math.ceil( textEditor.scrollHeight ) + 'px'; + adjust(); + } + + oldTextLength = length; + } + function getHeights() { var windowWidth = $window.width(); @@ -75,43 +116,6 @@ } } - function textEditorResize() { - if ( mceEditor && ! mceEditor.isHidden() ) { - return; - } - - if ( ! mceEditor && initialMode === 'tinymce' ) { - return; - } - - var length = textEditor.value.length; - var height = parseInt( textEditor.style.height, 10 ); - var top = window.scrollTop; - - if ( length < oldTextLength ) { - // textEditor.scrollHeight is not adjusted until the next line. - textEditor.style.height = 'auto'; - - if ( textEditor.scrollHeight > autoresizeMinHeight ) { - textEditor.style.height = textEditor.scrollHeight + 'px'; - } else { - textEditor.style.height = autoresizeMinHeight + 'px'; - } - - // Prevent scroll-jumping in Firefox and IE. - window.scrollTop = top; - - if ( textEditor.scrollHeight < height ) { - adjust(); - } - } else if ( height < textEditor.scrollHeight ) { - textEditor.style.height = textEditor.scrollHeight + 'px'; - adjust(); - } - - oldTextLength = length; - } - // We need to wait for TinyMCE to initialize. $document.on( 'tinymce-editor-init.editor-expand', function( event, editor ) { var VK = window.tinymce.util.VK,