Make WordPress Core

Ticket #26053: 26053.diff

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

     
    114114                        $("#description-wrap, p.submit").slideDown(200);
    115115                        wpActiveEditor = 'content';
    116116                });
     117               
     118                autoResizeTextarea();
    117119        };
    118120        quickPressLoad();
    119121
     
    132134        jQuery(window).resize( _.debounce( function(){
    133135                updateColumnCount();
    134136        }, 30) );
     137       
     138        function autoResizeTextarea () {
     139                // Add a hidden div. We'll copy over the text from the textarea to measure it's height
     140                $('body').append( '<div class="quick-draft-textarea-clone" style="display: none;"></div>' );
    135141
     142                var clone = $('.quick-draft-textarea-clone'),
     143                        editor = $('#content'),
     144                        editorCurrentHeight = editor.height(),
     145                        editorOriginalHeight = editorCurrentHeight;
     146                       
     147                // Match up textarea and clone div as much as possible
     148                // Firefox is necessitates declaring each padding setting individually
     149                clone.css({ 'font-family': editor.css('font-family'),
     150                                        'font-size':   editor.css('font-size'),
     151                                        'line-height': editor.css('line-height'),
     152                                        'padding-bottom': editor.css('paddingBottom'),
     153                                        'padding-left': editor.css('paddingLeft'),
     154                                        'padding-right': editor.css('paddingRight'),
     155                                        'padding-top': editor.css('paddingTop'), });
     156                                       
     157                // Hide overflow on textarea
     158                editor.css('overflow', 'hidden');
     159               
     160                editor.on('keyup paste', function (e) {
     161                        var $this = $(this),
     162                                textareaContent = $this.val().replace(/\n/g, '<br>'),
     163                                cloneHeight = clone.css('width', $this.css('width')).html(textareaContent).height();
     164
     165                        if (cloneHeight !== editorCurrentHeight) {
     166                                $this.css('height', clone.outerHeight() + 2 + 'px');
     167                                editorCurrentHeight = cloneHeight;
     168                        }
     169                });
     170        }
     171
    136172        function updateColumnCount() {
    137173                var cols = 1,
    138174                        windowWidth = parseInt(jQuery(window).width());