Make WordPress Core

Ticket #26053: 26053.4.diff

File 26053.4.diff, 3.2 KB (added by helen, 10 years ago)
  • wp-admin/css/wp-admin.css

     
    31013101        padding: 6px 7px;
    31023102}
    31033103
     3104#quick-press textarea#content {
     3105        min-height: 90px;
     3106        max-height: 1300px;
     3107}
     3108
    31043109/* Dashboard Quick Draft - Drafts list */
    31053110
    31063111#dashboard_quick_press .drafts {
  • wp-admin/js/dashboard.js

     
    22var ajaxWidgets, ajaxPopulateWidgets, quickPressLoad;
    33
    44jQuery(document).ready( function($) {
    5         var $window = $( window ),
    6                 welcomePanel = $( '#welcome-panel' ),
     5        var welcomePanel = $( '#welcome-panel' ),
    76                welcomePanelHide = $('#wp_welcome_panel-hide'),
    8                 updateWelcomePanel,
    9                 metaboxHolder = $( '.metabox-holder' );
     7                updateWelcomePanel;
    108
    119        updateWelcomePanel = function( visible ) {
    1210                $.post( ajaxurl, {
     
    120118                        $('#description-wrap, p.submit').slideDown(200);
    121119                        wpActiveEditor = 'content';
    122120                });
     121
     122                autoResizeTextarea();
    123123        };
    124124        quickPressLoad();
    125125
     
    131131                e.preventDefault();
    132132        });
    133133
     134        function autoResizeTextarea() {
     135                // Add a hidden div. We'll copy over the text from the textarea to measure its height.
     136                $('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
     137
     138                var clone = $('.quick-draft-textarea-clone'),
     139                        editor = $('#content'),
     140                        editorHeight = editor.height(),
     141                        // 100px roughly accounts for browser chrome and allows the
     142                        // save draft button to show on-screen at the same time.
     143                        editorMaxHeight = $(window).height() - 100;
     144
     145                // Match up textarea and clone div as much as possible.
     146                // Padding cannot be reliably retrieved using shorthand in all browsers.
     147                clone.css({ 'font-family': editor.css('font-family'),
     148                                        'font-size':   editor.css('font-size'),
     149                                        'line-height': editor.css('line-height'),
     150                                        'padding-bottom': editor.css('paddingBottom'),
     151                                        'padding-left': editor.css('paddingLeft'),
     152                                        'padding-right': editor.css('paddingRight'),
     153                                        'padding-top': editor.css('paddingTop') });
     154
     155                // propertychange is for IE < 9
     156                editor.on('focus input propertychange', function() {
     157                        var $this = $(this),
     158                                // Add an extra new line to be ahead of the growth curve.
     159                                // &nbsp; is to ensure that the height of the final newline is included.
     160                                textareaContent = $this.val().replace(/\n/g, '<br>') + '<br>&nbsp;',
     161                                // 2px is for border-top & border-bottom
     162                                cloneHeight = clone.css('width', $this.css('width')).html(textareaContent).outerHeight() + 2;
     163
     164                        // Only change the height if it has indeed changed and both heights are below the max.
     165                        if ( cloneHeight === editorHeight || ( cloneHeight >= editorMaxHeight && editorHeight >= editorMaxHeight ) ) {
     166                                return;
     167                        }
     168
     169                        // Don't allow editor to exceed height of window.
     170                        // This is also bound in CSS to a max-height of 1300px to be extra safe.
     171                        if ( cloneHeight > editorMaxHeight ) {
     172                                editorHeight = editorMaxHeight;
     173                        } else {
     174                                editorHeight = cloneHeight;
     175                        }
     176
     177                        $this.animate({
     178                                height: editorHeight + 'px'
     179                        }, 50);
     180                });
     181        }
     182
    134183} );