+ function textEditorResize( reset ) {
+ var pageYOffset, height;
+
+ if ( editor && ! editor.isHidden() ) {
+ return;
+ }
+
+ reset = ( reset === 'reset' ) || ( textLength && textLength > textEditor.value.length );
+ height = textEditor.style.height;
+
+ if ( reset ) {
+ pageYOffset = window.pageYOffset;
+
+ textEditor.style.height = 'auto';
+ textEditor.style.height = Math.max( textEditor.scrollHeight, textEditorMinHeight ) + 'px';
+ window.scrollTo( window.pageXOffset, pageYOffset );
+ } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) {
+ textEditor.style.height = textEditor.scrollHeight + 'px';
+ }
+
+ textLength = textEditor.value.length;
+ }
+
+ function mceGetCursorOffset() {
+ if ( ! editor ) {
+ return false;
+ }
+
+ var node = editor.selection.getNode(),
+ range, view, offset;
+
+ if ( editor.wp && editor.wp.getView && ( view = editor.wp.getView( node ) ) ) {
+ offset = view.getBoundingClientRect();
+ } else {
+ range = editor.selection.getRng();
+
+ try {
+ offset = range.getClientRects()[0];
+ } catch( er ) {}
+
+ if ( ! offset ) {
+ offset = node.getBoundingClientRect();
+ }
+ }
+
+ return offset.height ? offset : false;
+ }
+
+ // Make sure the caret is always visible.
+ function mceKeyup( event ) {
+ var VK = window.tinymce.util.VK,
+ key = event.keyCode;
+
+ // Bail on special keys.
+ if ( key <= 47 && ! ( key === VK.SPACEBAR || key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE || key === VK.UP || key === VK.LEFT || key === VK.DOWN || key === VK.UP ) ) {
+ return;
+ // OS keys, function keys, num lock, scroll lock
+ } else if ( ( key >= 91 && key <= 93 ) || ( key >= 112 && key <= 123 ) || key === 144 || key === 145 ) {
+ return;
+ }
+
+ mceScroll( key );
+ }
+
+ function mceScroll( key ) {
+ var cursorTop, cursorBottom, editorBottom,
+ offset = mceGetCursorOffset(),
+ bufferTop = 50,
+ bufferBottom = 65,
+ VK = window.tinymce.util.VK;
+
+ if ( ! offset ) {
+ return;
+ }
+
+ cursorTop = offset.top + editor.iframeElement.getBoundingClientRect().top;
+ cursorBottom = cursorTop + offset.height;
+ cursorTop = cursorTop - bufferTop;
+ cursorBottom = cursorBottom + bufferBottom;
+ editorBottom = $window.height();
+
+ // Don't scroll if the node is taller than the visible part of the editor
+ if ( editorBottom < offset.height ) {
+ return;
+ }
+
+ if ( cursorTop < 0 && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) {
+ window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset );
+ } else if ( cursorBottom > editorBottom ) {
+ window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );
+ }
+ }
+