Ticket #23042: 23042-2.patch

File 23042-2.patch, 4.9 KB (added by azaozz, 5 months ago)
  • wp-admin/js/post.js

     
    685685 
    686686        // resizable textarea#content 
    687687        (function() { 
    688                 var textarea = $('textarea#content'), offset = null, el; 
     688                var textarea = $('textarea#content'), handle; 
    689689                // No point for touch devices 
    690                 if ( 'ontouchstart' in window ) 
     690                if ( !textarea.length || 'ontouchstart' in window ) 
    691691                        return; 
    692692 
    693                 function dragging(e) { 
    694                         textarea.height( Math.max(50, offset + e.pageY) + 'px' ); 
    695                         return false; 
    696                 } 
     693                textarea.css('resize', 'none'); 
     694                handle = $('<div id="content-resize-handle"><br></div>'); 
     695                $('#wp-content-wrap').append(handle); 
    697696 
    698                 function endDrag(e) { 
    699                         var height = $('#wp-content-editor-container').height(); 
     697                handle.on('mousedown', function(e) { 
     698                        var height, offset = textarea.height() - e.pageY; 
    700699 
    701                         textarea.focus(); 
    702                         $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag); 
     700                        textarea.blur(); 
    703701 
    704                         height -= 33; // compensate for toolbars, padding... 
    705                         // sanity check 
    706                         if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) ) 
    707                                 setUserSetting( 'ed_size', height ); 
    708                 } 
     702                        $(document).on( 'mousemove.wp-editor-resize', function(e) { 
     703                                height = Math.max(50, offset + e.pageY) 
     704                                textarea.height( height ); 
     705                                e.preventDefault(); 
     706                        }).on( 'mouseup.wp-editor-resize', function(e) { 
     707                                textarea.focus(); 
     708                                $(document).off( '.wp-editor-resize' ); 
    709709 
    710                 textarea.css('resize', 'none'); 
    711                 el = $('<div id="content-resize-handle"><br></div>'); 
    712                 $('#wp-content-wrap').append(el); 
    713                 el.on('mousedown', function(e) { 
    714                         offset = textarea.height() - e.pageY; 
    715                         textarea.blur(); 
    716                         $(document).mousemove(dragging).mouseup(endDrag); 
    717                         return false; 
     710                                // compensate for textarea padding, 'height' has been set while dragging 
     711                                height += 20; 
     712 
     713                                // sanity check 
     714                                if ( height > 50 && height < 5000 ) 
     715                                        setUserSetting( 'ed_size', height ); 
     716                        }); 
     717                        e.preventDefault(); // stop the browser selecting/highlighting elements 
    718718                }); 
    719719        })(); 
    720720 
    721721        if ( typeof(tinymce) != 'undefined' ) { 
    722722                tinymce.onAddEditor.add(function(mce, ed){ 
     723                        var get_textarea_height; 
     724 
    723725                        // iOS expands the iframe to full height and the user cannot adjust it. 
    724726                        if ( ed.id != 'content' || tinymce.isIOS5 ) 
    725727                                return; 
    726728 
     729                        get_textarea_height = function() { 
     730                                var height, ifr_height = $('#content_ifr').height(), 
     731                                        tb_height = $('#content_tbl tr.mceFirst').height(); 
     732 
     733                                if ( !ifr_height || !tb_height ) 
     734                                        return false; 
     735 
     736                                // total height including toolbar and statusbar 
     737                                height = ifr_height + tb_height + 21; 
     738                                // textarea height = total height - 33px Quicktags toolbar 
     739                                height -= 33; 
     740 
     741                                return height; 
     742                        } 
     743 
    727744                        // resize TinyMCE to match the textarea height when switching Text -> Visual 
    728745                        ed.onLoadContent.add( function(ed, o) { 
    729                                 var ifr_height, height = parseInt( $('#content').css('height'), 10 ), 
     746                                var ifr_height, node = document.getElementById('content'), 
     747                                        height = node ? parseInt( node.style.height, 10 ) : 360, 
    730748                                        tb_height = $('#content_tbl tr.mceFirst').height(); 
    731749 
    732                                 if ( height && !isNaN(height) && tb_height ) { 
     750                                if ( isNaN(height) || height < 50 || height > 5000 ) { 
     751                                        height = 360; // default height for the main editor 
     752                                        setUserSetting('ed_size', height); 
     753                                } 
     754 
     755                                if ( tb_height ) 
    733756                                        ifr_height = (height - tb_height) + 12; // compensate for padding in the textarea 
    734                                         // sanity check 
    735                                         if ( ifr_height > 50 && ifr_height < 5000 ) { 
    736                                                 $('#content_tbl').css('height', '' ); 
    737                                                 $('#content_ifr').css('height', ifr_height + 'px' ); 
    738                                         } 
     757                                else 
     758                                        ifr_height = 340; 
     759 
     760                                // sanity check 
     761                                if ( ifr_height > 50 && ifr_height < 5000 ) { 
     762                                        $('#content_tbl').css('height', '' ); 
     763                                        $('#content_ifr').css('height', ifr_height + 'px' ); 
    739764                                } 
    740765                        }); 
    741766 
    742767                        // resize the textarea to match TinyMCE's height when switching Visual -> Text 
    743768                        ed.onSaveContent.add( function(ed, o) { 
    744                                 var height = $('#content_tbl').height(); 
     769                                var height = get_textarea_height(); 
    745770 
    746                                 if ( height && height > 83 && height < 5000 ) { 
    747                                         height -= 33; 
     771                                if ( !height || height < 50 || height > 5000 ) 
     772                                        height = 360; 
    748773 
    749                                         $('#content').css( 'height', height + 'px' ); 
    750                                 } 
     774                                $('textarea#content').css( 'height', height + 'px' ); 
    751775                        }); 
    752776 
    753777                        // save on resizing TinyMCE 
    754778                        ed.onPostRender.add(function() { 
    755779                                $('#content_resize').on('mousedown.wp-mce-resize', function(e){ 
    756780                                        $(document).on('mouseup.wp-mce-resize', function(e){ 
    757                                                 var height = $('#wp-content-editor-container').height(); 
     781                                                var height = get_textarea_height(); 
    758782 
    759                                                 height -= 33; 
    760783                                                // sanity check 
    761                                                 if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) ) 
     784                                                if ( height && height > 50 && height < 5000 ) 
    762785                                                        setUserSetting( 'ed_size', height ); 
    763786 
    764787                                                $(document).off('mouseup.wp-mce-resize');