Make WordPress Core

Changeset 23302


Ignore:
Timestamp:
01/16/2013 07:10:38 PM (12 years ago)
Author:
azaozz
Message:

Main editor: when setting or saving the height, look only at elements that have style="height:..." set. Reset a previously saved erroneous "ed_size" value (over 5000px) to the default height of 360px. Fixes #23042 for trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/post.js

    r23278 r23302  
    688688        var textarea = $('textarea#content'), offset = null, el;
    689689        // No point for touch devices
    690         if ( 'ontouchstart' in window )
     690        if ( !textarea.length || 'ontouchstart' in window )
    691691            return;
    692692
     
    697697
    698698        function endDrag(e) {
    699             var height = $('#wp-content-editor-container').height();
     699            var height;
    700700
    701701            textarea.focus();
    702702            $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag);
    703703
    704             height -= 33; // compensate for toolbars, padding...
     704            height = parseInt( textarea.css('height'), 10 );
     705
    705706            // sanity check
    706             if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) )
     707            if ( height && height > 50 && height < 5000 )
    707708                setUserSetting( 'ed_size', height );
    708709        }
     
    725726                return;
    726727
     728            function getHeight() {
     729                var height, node = document.getElementById('content_ifr'),
     730                    ifr_height = node ? parseInt( node.style.height, 10 ) : 0,
     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 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 ),
    730                     tb_height = $('#content_tbl tr.mceFirst').height();
    731 
    732                 if ( height && !isNaN(height) && tb_height ) {
    733                     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                     }
     746                var ifr_height, node = document.getElementById('content'),
     747                    height = node ? parseInt( node.style.height, 10 ) : 0,
     748                    tb_height = $('#content_tbl tr.mceFirst').height() || 33;
     749
     750                // height cannot be under 50 or over 5000
     751                if ( !height || height < 50 || height > 5000 )
     752                    height = 360; // default height for the main editor
     753
     754                if ( getUserSetting( 'ed_size' ) > 5000  )
     755                    setUserSetting( 'ed_size', 360 );
     756
     757                // compensate for padding and toolbars
     758                ifr_height = ( height - tb_height ) + 12;
     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            });
     
    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();
    745 
    746                 if ( height && height > 83 && height < 5000 ) {
    747                     height -= 33;
    748 
    749                     $('#content').css( 'height', height + 'px' );
    750                 }
     769                var height = getHeight();
     770
     771                if ( !height || height < 50 || height > 5000 )
     772                    return;
     773
     774                $('textarea#content').css( 'height', height + 'px' );
    751775            });
    752776
     
    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();
    758 
    759                         height -= 33;
     781                        var height;
     782
     783                        $(document).off('mouseup.wp-mce-resize');
     784
     785                        height = getHeight();
    760786                        // sanity check
    761                         if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) )
     787                        if ( height && height > 50 && height < 5000 )
    762788                            setUserSetting( 'ed_size', height );
    763 
    764                         $(document).off('mouseup.wp-mce-resize');
    765789                    });
    766790                });
Note: See TracChangeset for help on using the changeset viewer.