Make WordPress Core

Ticket #37690: 37690.1.patch

File 37690.1.patch, 3.7 KB (added by azaozz, 9 years ago)
  • src/wp-admin/js/editor-expand.js

     
    1616                        $textTop = $( '#ed_toolbar' ),
    1717                        $textEditor = $( '#content' ),
    1818                        textEditor = $textEditor[0],
     19                        $textEditorClone = $textEditor.clone().attr({ id: 'content-clone', name: null }),
     20                        textEditorClone = $textEditorClone[0],
    1921                        oldTextLength = 0,
    2022                        $bottom = $( '#post-status-info' ),
    2123                        $menuBar = $(),
     
    5355                                sideSortablesHeight: 0
    5456                        };
    5557
     58                var shrinkTextarea = window._.throttle( function() {
     59                        var top = window.scrollTop;
     60                        var height = parseInt( textEditor.style.height, 10 );
     61
     62                        textEditorClone.value = textEditor.value;
     63
     64                        if ( textEditorClone.scrollHeight > autoresizeMinHeight ) {
     65                                textEditor.style.height = textEditorClone.scrollHeight + 'px';
     66                        } else if ( textEditorClone.scrollHeight < height ) {
     67                                textEditor.style.height = autoresizeMinHeight + 'px';
     68                        }
     69
     70                        // Prevent scroll-jumping in Firefox and IE.
     71                        window.scrollTop = top;
     72
     73                        if ( textEditor.scrollHeight < height ) {
     74                                adjust();
     75                        }
     76                }, 500 );
     77
     78                function textEditorResize() {
     79                        var length = textEditor.value.length;
     80
     81                        if ( mceEditor && ! mceEditor.isHidden() ) {
     82                                return;
     83                        }
     84
     85                        if ( ! mceEditor && initialMode === 'tinymce' ) {
     86                                return;
     87                        }
     88
     89                        if ( length < oldTextLength ) {
     90                                shrinkTextarea();
     91                        } else if ( parseInt( textEditor.style.height, 10 ) < textEditor.scrollHeight ) {
     92                                textEditor.style.height = Math.ceil( textEditor.scrollHeight ) + 'px';
     93                                adjust();
     94                        }
     95
     96                        oldTextLength = length;
     97                }
     98
    5699                function getHeights() {
    57100                        var windowWidth = $window.width();
    58101
     
    75118                        }
    76119                }
    77120
    78                 function textEditorResize() {
    79                         if ( mceEditor && ! mceEditor.isHidden() ) {
    80                                 return;
    81                         }
     121                // Append the cloned textarea after the "real" one and move it off screen.
     122                $textEditor.after( $textEditorClone.css({ position: 'absolute', left: '-10000em' }) );
    82123
    83                         if ( ! mceEditor && initialMode === 'tinymce' ) {
    84                                 return;
    85                         }
    86 
    87                         var length = textEditor.value.length;
    88                         var height = parseInt( textEditor.style.height, 10 );
    89                         var top = window.scrollTop;
    90 
    91                         if ( length < oldTextLength ) {
    92                                 // textEditor.scrollHeight is not adjusted until the next line.
    93                                 textEditor.style.height = 'auto';
    94 
    95                                 if ( textEditor.scrollHeight > autoresizeMinHeight ) {
    96                                         textEditor.style.height = textEditor.scrollHeight + 'px';
    97                                 } else {
    98                                         textEditor.style.height = autoresizeMinHeight + 'px';
    99                                 }
    100 
    101                                 // Prevent scroll-jumping in Firefox and IE.
    102                                 window.scrollTop = top;
    103 
    104                                 if ( textEditor.scrollHeight < height ) {
    105                                         adjust();
    106                                 }
    107                         } else if ( height < textEditor.scrollHeight ) {
    108                                 textEditor.style.height = textEditor.scrollHeight + 'px';
    109                                 adjust();
    110                         }
    111 
    112                         oldTextLength = length;
    113                 }
    114 
    115124                // We need to wait for TinyMCE to initialize.
    116125                $document.on( 'tinymce-editor-init.editor-expand', function( event, editor ) {
    117126                        var VK = window.tinymce.util.VK,
  • src/wp-includes/script-loader.php

     
    563563                        'suggestedImgAlt' => __( 'Suggested image #%d' ),
    564564                ) );
    565565
    566                 $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery' ), false, 1 );
     566                $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 );
    567567
    568568                $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
    569569