<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[32999] trunk/src/wp-admin: Press This:</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/32999">32999</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/32999","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-06-30 03:57:42 +0000 (Tue, 30 Jun 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Press This:
- Add support for the Text editor.
- Add auto-scrolling when the caret moves out of the viewport while the user is typing (similarly to editor-expand).
- Add auto-resize for the textarea.
See <a href="https://core.trac.wordpress.org/ticket/32706">#32706</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsspressthiscss">trunk/src/wp-admin/css/press-this.css</a></li>
<li><a href="#trunksrcwpadminincludesclasswppressthisphp">trunk/src/wp-admin/includes/class-wp-press-this.php</a></li>
<li><a href="#trunksrcwpadminjspressthisjs">trunk/src/wp-admin/js/press-this.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincsspressthiscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/press-this.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/press-this.css     2015-06-29 21:31:21 UTC (rev 32998)
+++ trunk/src/wp-admin/css/press-this.css       2015-06-30 03:57:42 UTC (rev 32999)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2172,3 +2172,44 @@
</span><span class="cx" style="display: block; padding: 0 10px">        top: -1px;
</span><span class="cx" style="display: block; padding: 0 10px">        margin-left: 11px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/* Text editor */
+#pressthis {
+       color: #404040;
+       resize: none;
+       padding-top: 30px;
+}
+
+.wp-editor-wrap .quicktags-toolbar {
+       background: transparent;
+       border: none;
+}
+
+/* Switch editor buttons */
+.wp-editor-wrap .wp-editor-tools {
+       z-index: 0;
+}
+
+.wp-editor-wrap .wp-editor-tabs {
+       padding: 2px;
+}
+
+.wp-editor-wrap .wp-switch-editor {
+       top: 0;
+       margin: 3px 0 0 5px;
+       background: #f5f5f5;
+       color: #555;
+       border-color: #ccc;
+}
+
+.wp-editor-wrap .wp-switch-editor:hover {
+       background: #fafafa;
+       border-color: #999;
+       color: #23282d;
+}
+
+.wp-editor-wrap.tmce-active .switch-tmce,
+.wp-editor-wrap.html-active .switch-html {
+       background: #fff;
+       border-color: #d8d8d8;
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludesclasswppressthisphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/class-wp-press-this.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/class-wp-press-this.php       2015-06-29 21:31:21 UTC (rev 32998)
+++ trunk/src/wp-admin/includes/class-wp-press-this.php 2015-06-30 03:57:42 UTC (rev 32999)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1387,7 +1387,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                'toolbar1'              => 'bold,italic,bullist,numlist,blockquote,link,unlink',
</span><span class="cx" style="display: block; padding: 0 10px">                                                'toolbar2'              => 'undo,redo',
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'quicktags' => false,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 'quicktags' => array(
+                                               'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,more',
+                                       ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                ?>
</span></span></pre></div>
<a id="trunksrcwpadminjspressthisjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/press-this.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/press-this.js       2015-06-29 21:31:21 UTC (rev 32998)
+++ trunk/src/wp-admin/js/press-this.js 2015-06-30 03:57:42 UTC (rev 32999)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,6 +5,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ( function( $, window ) {
</span><span class="cx" style="display: block; padding: 0 10px">        var PressThis = function() {
</span><span class="cx" style="display: block; padding: 0 10px">                var editor, $mediaList, $mediaThumbWrap,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $window               = $( window ),
+                       $document             = $( document ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         saveAlert             = false,
</span><span class="cx" style="display: block; padding: 0 10px">                        textarea              = document.createElement( 'textarea' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        sidebarIsOpen         = false,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,6 +19,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        isHidden              = 'is-hidden',
</span><span class="cx" style="display: block; padding: 0 10px">                        offscreenHidden       = isOffScreen + ' ' + isHidden,
</span><span class="cx" style="display: block; padding: 0 10px">                        iOS                   = /iPad|iPod|iPhone/.test( window.navigator.userAgent ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $textEditor           = $( '#pressthis' ),
+                       textEditor            = $textEditor[0],
+                       textEditorMinHeight   = 600,
+                       textLength            = 0,
</ins><span class="cx" style="display: block; padding: 0 10px">                         transitionEndEvent    = ( function() {
</span><span class="cx" style="display: block; padding: 0 10px">                                var style = document.documentElement.style;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -114,6 +120,99 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $( '.post-actions button' ).removeAttr( 'disabled' );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                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 );
+                       }
+               }
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><span class="cx" style="display: block; padding: 0 10px">                 * Replace emoji images with chars and sanitize the text content.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -216,10 +315,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                function insertSelectedMedia( $element ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        var src, link, newContent = '';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! editor ) {
-                               return;
-                       }
-
</del><span class="cx" style="display: block; padding: 0 10px">                         src = checkUrl( $element.attr( 'data-wp-src' ) || '' );
</span><span class="cx" style="display: block; padding: 0 10px">                        link = checkUrl( data.u );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -233,10 +328,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                newContent = '[embed]' + src + '[/embed]';
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! hasSetFocus ) {
-                               editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() );
-                       } else {
-                               editor.execCommand( 'mceInsertContent', false, newContent );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( editor && ! editor.isHidden() ) {
+                               if ( ! hasSetFocus ) {
+                                       editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() );
+                               } else {
+                                       editor.execCommand( 'mceInsertContent', false, newContent );
+                               }
+                       } else if ( window.QTags ) {
+                               window.QTags.insertContent( newContent );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -636,7 +735,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                function monitor() {
</span><span class="cx" style="display: block; padding: 0 10px">                        var $splitButton = $( '.split-button' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $( document ).on( 'tinymce-editor-init', function( event, ed ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $document.on( 'tinymce-editor-init', function( event, ed ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 editor = ed;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                editor.on( 'nodechange', function() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -646,6 +745,22 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                editor.on( 'focus', function() {
</span><span class="cx" style="display: block; padding: 0 10px">                                        splitButtonClose();
</span><span class="cx" style="display: block; padding: 0 10px">                                });
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               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 );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                if ( event.type === 'click' || event.keyCode === 13 ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        insertSelectedMedia( $( this ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -727,11 +842,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $( window ).on( 'beforeunload.press-this', function() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $window.on( 'beforeunload.press-this', function() {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( saveAlert || ( editor && editor.isDirty() ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                        return __( 'saveAlert' );
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } ).on( 'resize.press-this', function() {
+                               if ( ! editor || editor.isHidden() ) {
+                                       textEditorResize( 'reset' );
+                               }
+                       });
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        $( 'button.add-cat-toggle' ).on( 'click.press-this', function() {
</span><span class="cx" style="display: block; padding: 0 10px">                                var $this = $( this );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -766,6 +885,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        } );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $textEditor.on( 'focus.press-this input.press-this propertychange.press-this', textEditorResize );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         return true;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -782,7 +903,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Let's go!
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $( document ).ready( function() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $document.ready( function() {
</ins><span class="cx" style="display: block; padding: 0 10px">                         render();
</span><span class="cx" style="display: block; padding: 0 10px">                        monitor();
</span><span class="cx" style="display: block; padding: 0 10px">                        refreshCatsCache();
</span></span></pre>
</div>
</div>

</body>
</html>