Make WordPress Core

Ticket #32706: 32706.1.patch

File 32706.1.patch, 7.0 KB (added by azaozz, 10 years ago)
  • src/wp-admin/css/press-this.css

     
    20382038        top: -1px;
    20392039        margin-left: 11px;
    20402040}
     2041
     2042/* Text editor */
     2043#pressthis {
     2044        color: #404040;
     2045        resize: none;
     2046}
     2047
     2048.wp-editor-wrap .quicktags-toolbar {
     2049        background: transparent;
     2050        border: none;
     2051}
  • src/wp-admin/includes/class-wp-press-this.php

     
    13761376                                                'toolbar1'              => 'bold,italic,bullist,numlist,blockquote,link,unlink',
    13771377                                                'toolbar2'              => 'undo,redo',
    13781378                                        ),
    1379                                         'quicktags' => false,
     1379                                        'quicktags' => true,
     1380                                        'default_editor' => 'tinymce',
    13801381                                ) );
    13811382
    13821383                                ?>
  • src/wp-admin/js/press-this.js

     
    55( function( $, window ) {
    66        var PressThis = function() {
    77                var editor, $mediaList, $mediaThumbWrap,
     8                        $window               = $( window ),
     9                        $document             = $( document ),
    810                        saveAlert             = false,
    911                        editLinkVisible       = false,
    1012                        textarea              = document.createElement( 'textarea' ),
     
    1719                        isOffScreen           = 'is-off-screen',
    1820                        isHidden              = 'is-hidden',
    1921                        offscreenHidden       = isOffScreen + ' ' + isHidden,
     22                        $textEditor           = $( '#pressthis' ),
     23                        textEditor            = $textEditor[0],
     24                        textLength            = 0,
    2025                        transitionEndEvent    = ( function() {
    2126                                var style = document.documentElement.style;
    2227
     
    114119                        $( '.post-actions button' ).removeAttr( 'disabled' );
    115120                }
    116121
     122                function textEditorResize( reset ) {
     123                        var pageYOffset, height;
     124
     125                        if ( editor && ! editor.isHidden() ) {
     126                                return;
     127                        }
     128
     129                        reset = ( reset === 'reset' ) || ( textLength && textLength > textEditor.value.length );
     130                        height = textEditor.style.height;
     131
     132                        if ( reset ) {
     133                                pageYOffset = window.pageYOffset;
     134
     135                                textEditor.style.height = 'auto';
     136                                textEditor.style.height = textEditor.scrollHeight + 'px';
     137                                window.scrollTo( window.pageXOffset, pageYOffset );
     138                        } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) {
     139                                textEditor.style.height = textEditor.scrollHeight + 'px';
     140                        }
     141
     142                        textLength = textEditor.value.length;
     143                }
     144
     145                function mceGetCursorOffset() {
     146                        if ( ! editor ) {
     147                                return false;
     148                        }
     149
     150                        var node = editor.selection.getNode(),
     151                                range, view, offset;
     152
     153                        if ( editor.wp && editor.wp.getView && ( view = editor.wp.getView( node ) ) ) {
     154                                offset = view.getBoundingClientRect();
     155                        } else {
     156                                range = editor.selection.getRng();
     157
     158                                try {
     159                                        offset = range.getClientRects()[0];
     160                                } catch( er ) {}
     161
     162                                if ( ! offset ) {
     163                                        offset = node.getBoundingClientRect();
     164                                }
     165                        }
     166
     167                        return offset.height ? offset : false;
     168                }
     169
     170                // Make sure the caret is always visible.
     171                function mceKeyup( event ) {
     172                        var VK = window.tinymce.util.VK,
     173                                key = event.keyCode;
     174
     175                        // Bail on special keys.
     176                        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 ) ) {
     177                                return;
     178                        // OS keys, function keys, num lock, scroll lock
     179                        } else if ( ( key >= 91 && key <= 93 ) || ( key >= 112 && key <= 123 ) || key === 144 || key === 145 ) {
     180                                return;
     181                        }
     182
     183                        mceScroll( key );
     184                }
     185
     186                function mceScroll( key ) {
     187                        var cursorTop, cursorBottom, editorTop, editorBottom,
     188                                offset = mceGetCursorOffset(),
     189                                bufferTop = 50,
     190                                bufferBottom = 65,
     191                                VK = window.tinymce.util.VK;
     192
     193                        if ( ! offset ) {
     194                                return;
     195                        }
     196
     197                        cursorTop = offset.top + editor.iframeElement.getBoundingClientRect().top;
     198                        cursorBottom = cursorTop + offset.height;
     199                        cursorTop = cursorTop - bufferTop;
     200                        cursorBottom = cursorBottom + bufferBottom;
     201                        editorBottom = $window.height();
     202
     203                        // Don't scroll if the node is taller than the visible part of the editor
     204                        if ( editorBottom < offset.height ) {
     205                                return;
     206                        }
     207
     208                        if ( cursorTop < 0 && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) {
     209                                window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset );
     210                        } else if ( cursorBottom > editorBottom ) {
     211                                window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );
     212                        }
     213                }
     214
    117215                /**
    118216                 * Replace emoji images with chars and sanitize the text content.
    119217                 */
     
    256354                                newContent = '[embed]' + src + '[/embed]';
    257355                        }
    258356
    259                         if ( ! hasSetFocus ) {
    260                                 editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() );
    261                         } else {
    262                                 editor.execCommand( 'mceInsertContent', false, newContent );
     357                        if ( ! editor.isHidden() ) {
     358                                if ( ! hasSetFocus ) {
     359                                        editor.setContent( '<p>' + newContent + '</p>' + editor.getContent() );
     360                                } else {
     361                                        editor.execCommand( 'mceInsertContent', false, newContent );
     362                                }
     363                        } else if ( window.QTags ) {
     364                                window.QTags.insertContent( newContent );
    263365                        }
    264366                }
    265367
     
    648750                 * Set app events and other state monitoring related code.
    649751                 */
    650752                function monitor() {
    651                         $( document ).on( 'tinymce-editor-init', function( event, ed ) {
     753                        $document.on( 'tinymce-editor-init', function( event, ed ) {
    652754                                editor = ed;
    653755
    654756                                editor.on( 'nodechange', function() {
     
    655757                                        hasSetFocus = true;
    656758                                        resetDraftButton();
    657759                                } );
     760
     761                                editor.on( 'show', function() {
     762                                        setTimeout( function() {
     763                                                editor.execCommand( 'wpAutoResize' );
     764                                        }, 300 );
     765                                });
     766
     767                                editor.on( 'hide', function() {
     768                                        setTimeout( function() {
     769                                                textEditorResize( 'reset' );
     770                                        }, 100 );
     771                                });
     772
     773                                editor.on( 'keyup', mceKeyup );
     774                                editor.on( 'undo redo', mceScroll );
     775
    658776                        }).on( 'click.press-this keypress.press-this', '.suggested-media-thumbnail', function( event ) {
    659777                                if ( event.type === 'click' || event.keyCode === 13 ) {
    660778                                        insertSelectedMedia( $( this ) );
     
    722840                                }
    723841                        } );
    724842
    725                         $( window ).on( 'beforeunload.press-this', function() {
     843                        $window.on( 'beforeunload.press-this', function() {
    726844                                if ( saveAlert || ( editor && editor.isDirty() ) ) {
    727845                                        return __( 'saveAlert' );
    728846                                }
    729                         } );
     847                        } ).on( 'resize.press-this', function() {
     848                                textEditorResize( 'reset' );
     849                        });
    730850
    731851                        $( 'button.add-cat-toggle' ).on( 'click.press-this', function() {
    732852                                var $this = $( this );
     
    761881                                }
    762882                        } );
    763883
     884                        $textEditor.on( 'focus.press-this input.press-this propertychange.press-this', textEditorResize );
     885
    764886                        return true;
    765887                }
    766888
     
    777899                }
    778900
    779901                // Let's go!
    780                 $( document ).ready( function() {
     902                $document.ready( function() {
    781903                        render();
    782904                        monitor();
    783905                        refreshCatsCache();