Make WordPress Core

Ticket #26053: 26053.2.diff

File 26053.2.diff, 2.7 KB (added by lessbloat, 10 years ago)
  • wp-admin/js/dashboard.js

     
    120120                        $('#description-wrap, p.submit').slideDown(200);
    121121                        wpActiveEditor = 'content';
    122122                });
     123               
     124                autoResizeTextarea();
    123125        };
    124126        quickPressLoad();
    125127
     
    131133                e.preventDefault();
    132134        });
    133135
     136        function autoResizeTextarea () {
     137                // Add a hidden div. We'll copy over the text from the textarea to measure it's height
     138                $('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
     139 
     140                var clone = $('.quick-draft-textarea-clone'),
     141                        editor = $('#content'),
     142                        editorCurrentHeight = editor.height(),
     143                        // 100px ensures that the editor isn't the exact same height as the window
     144                        // It allows the save draft button to be shown at max-height
     145                        editorMaxHeight = $(window).height() - 100;
     146                        editorOriginalHeight = editorCurrentHeight;
     147
     148                // Match up textarea and clone div as much as possible
     149                // Firefox is necessitates declaring each padding setting individually
     150                clone.css({ 'font-family': editor.css('font-family'),
     151                                        'font-size':   editor.css('font-size'),
     152                                        'line-height': editor.css('line-height'),
     153                                        'padding-bottom': editor.css('paddingBottom'),
     154                                        'padding-left': editor.css('paddingLeft'),
     155                                        'padding-right': editor.css('paddingRight'),
     156                                        'padding-top': editor.css('paddingTop') });
     157
     158                // Hide overflow on textarea
     159                editor.css('overflow', 'hidden');
     160
     161                editor.on('keyup paste', function (e) {
     162                        var $this = $(this),
     163                                textareaContent = $this.val().replace(/\n/g, '<br>'),
     164                                cloneHeight = clone.css('width', $this.css('width')).html(textareaContent).height();
     165
     166                        if (cloneHeight !== editorCurrentHeight) {
     167                               
     168                                // 2px is for border-top & border-bottom
     169                                var editorNewHeight = clone.outerHeight() + 2;
     170                               
     171                                // Don't allow editor to exceed height of window
     172                                if ( clone.outerHeight() > editorMaxHeight ) {
     173                                        editorNewHeight = editorMaxHeight;
     174                                        // re-enable scrollbar
     175                                        $this.css('overflow', 'auto');
     176                                } else {
     177                                        $this.css('overflow', 'hidden');
     178                                }
     179
     180                                $this.css('height', editorNewHeight + 'px');
     181                                editorCurrentHeight = cloneHeight;
     182                        }
     183                });
     184        }
     185
    134186} );
  • wp-admin/css/wp-admin.css

     
    30983098        padding: 6px 7px;
    30993099}
    31003100
     3101#quick-press textarea#content {
     3102        min-height: 90px;
     3103        max-height: 1300px;
     3104}
     3105
    31013106/* Dashboard Quick Draft - Drafts list */
    31023107
    31033108#dashboard_quick_press .drafts {