Make WordPress Core

Ticket #26053: 26053.1.diff

File 26053.1.diff, 2.0 KB (added by seanchayes, 11 years ago)
  • wp-admin/js/dashboard.js

     
    117117                        $('#description-wrap, p.submit').slideDown(200);
    118118                        wpActiveEditor = 'content';
    119119                });
     120               
     121                autoResizeTextarea();
    120122        };
    121123        quickPressLoad();
    122124
     
    135137        jQuery(window).resize( _.debounce( function(){
    136138                updateColumnCount();
    137139        }, 30) );
     140       
     141        function autoResizeTextarea () {
     142                // Add a hidden div. We'll copy over the text from the textarea to measure it's height
     143                $('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
    138144
     145                var clone = $('.quick-draft-textarea-clone'),
     146                        editor = $('#content'),
     147                        editorCurrentHeight = editor.height(),
     148                        editorOriginalHeight = editorCurrentHeight;
     149                       
     150                // Match up textarea and clone div as much as possible
     151                // Firefox is necessitates declaring each padding setting individually
     152                clone.css({ 'font-family': editor.css('font-family'),
     153                                        'font-size':   editor.css('font-size'),
     154                                        'line-height': editor.css('line-height'),
     155                                        'padding-bottom': editor.css('paddingBottom'),
     156                                        'padding-left': editor.css('paddingLeft'),
     157                                        'padding-right': editor.css('paddingRight'),
     158                                        'padding-top': editor.css('paddingTop') });
     159                                       
     160                // Hide overflow on textarea
     161                editor.css('overflow', 'hidden');
     162               
     163                editor.on('keyup paste', function (e) {
     164                        var $this = $(this),
     165                                textareaContent = $this.val().replace(/\n/g, '<br>'),
     166                                cloneHeight = clone.css('width', $this.css('width')).html(textareaContent).height();
     167
     168                        if (cloneHeight !== editorCurrentHeight) {
     169                                $this.css('height', clone.outerHeight() + 2 + 'px');
     170                $this.css('min-height', clone.outerHeight() + 59 + 'px');
     171                                editorCurrentHeight = cloneHeight;
     172                        }
     173                });
     174        }
     175
    139176        function updateColumnCount() {
    140177                var cols = 1,
    141178                        windowWidth = parseInt(jQuery(window).width(), 10);