Index: src/wp-admin/css/press-this.css =================================================================== --- src/wp-admin/css/press-this.css (revision 32900) +++ src/wp-admin/css/press-this.css (working copy) @@ -2038,3 +2038,14 @@ top: -1px; margin-left: 11px; } + +/* Text editor */ +#pressthis { + color: #404040; + resize: none; +} + +.wp-editor-wrap .quicktags-toolbar { + background: transparent; + border: none; +} Index: src/wp-admin/includes/class-wp-press-this.php =================================================================== --- src/wp-admin/includes/class-wp-press-this.php (revision 32900) +++ src/wp-admin/includes/class-wp-press-this.php (working copy) @@ -1376,7 +1376,8 @@ 'toolbar1' => 'bold,italic,bullist,numlist,blockquote,link,unlink', 'toolbar2' => 'undo,redo', ), - 'quicktags' => false, + 'quicktags' => true, + 'default_editor' => 'tinymce', ) ); ?> Index: src/wp-admin/js/press-this.js =================================================================== --- src/wp-admin/js/press-this.js (revision 32900) +++ src/wp-admin/js/press-this.js (working copy) @@ -5,6 +5,8 @@ ( function( $, window ) { var PressThis = function() { var editor, $mediaList, $mediaThumbWrap, + $window = $( window ), + $document = $( document ), saveAlert = false, editLinkVisible = false, textarea = document.createElement( 'textarea' ), @@ -17,6 +19,9 @@ isOffScreen = 'is-off-screen', isHidden = 'is-hidden', offscreenHidden = isOffScreen + ' ' + isHidden, + $textEditor = $( '#pressthis' ), + textEditor = $textEditor[0], + textLength = 0, transitionEndEvent = ( function() { var style = document.documentElement.style; @@ -114,6 +119,99 @@ $( '.post-actions button' ).removeAttr( 'disabled' ); } + 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 = textEditor.scrollHeight + '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, editorTop, 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 ); + } + } + /** * Replace emoji images with chars and sanitize the text content. */ @@ -256,10 +354,14 @@ newContent = '[embed]' + src + '[/embed]'; } - if ( ! hasSetFocus ) { - editor.setContent( '
' + newContent + '
' + editor.getContent() ); - } else { - editor.execCommand( 'mceInsertContent', false, newContent ); + if ( ! editor.isHidden() ) { + if ( ! hasSetFocus ) { + editor.setContent( '' + newContent + '
' + editor.getContent() ); + } else { + editor.execCommand( 'mceInsertContent', false, newContent ); + } + } else if ( window.QTags ) { + window.QTags.insertContent( newContent ); } } @@ -648,7 +750,7 @@ * Set app events and other state monitoring related code. */ function monitor() { - $( document ).on( 'tinymce-editor-init', function( event, ed ) { + $document.on( 'tinymce-editor-init', function( event, ed ) { editor = ed; editor.on( 'nodechange', function() { @@ -655,6 +757,22 @@ hasSetFocus = true; resetDraftButton(); } ); + + editor.on( 'show', function() { + setTimeout( function() { + editor.execCommand( 'wpAutoResize' ); + }, 300 ); + }); + + editor.on( 'hide', function() { + setTimeout( function() { + textEditorResize( 'reset' ); + }, 100 ); + }); + + editor.on( 'keyup', mceKeyup ); + editor.on( 'undo redo', mceScroll ); + }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) { if ( event.type === 'click' || event.keyCode === 13 ) { insertSelectedMedia( $( this ) ); @@ -722,11 +840,13 @@ } } ); - $( window ).on( 'beforeunload.press-this', function() { + $window.on( 'beforeunload.press-this', function() { if ( saveAlert || ( editor && editor.isDirty() ) ) { return __( 'saveAlert' ); } - } ); + } ).on( 'resize.press-this', function() { + textEditorResize( 'reset' ); + }); $( 'button.add-cat-toggle' ).on( 'click.press-this', function() { var $this = $( this ); @@ -761,6 +881,8 @@ } } ); + $textEditor.on( 'focus.press-this input.press-this propertychange.press-this', textEditorResize ); + return true; } @@ -777,7 +899,7 @@ } // Let's go! - $( document ).ready( function() { + $document.ready( function() { render(); monitor(); refreshCatsCache();