Make WordPress Core

Changeset 32711


Ignore:
Timestamp:
06/08/2015 09:31:39 PM (11 years ago)
Author:
iseulde
Message:

TinyMCE: wpviews: cache iframe heights

Cache iframe heights per instance so it can be reused. This will prevent to content from moving in the editor when undoing or redoing changes.

Fixes #32593.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/mce-view.js

    r32710 r32711  
    502502                                } );
    503503
     504                                if ( self.iframeHeight ) {
     505                                        dom.add( contentNode, 'div', { style: {
     506                                                width: '100%',
     507                                                height: self.iframeHeight
     508                                        } } );
     509                                }
     510
    504511                                // Seems the browsers need a bit of time to insert/set the view nodes,
    505512                                // or the iframe will fail especially when switching Text => Visual.
    506513                                setTimeout( function() {
    507                                         var iframe, iframeDoc, observer, i;
     514                                        var iframe, iframeDoc, observer, i, block;
    508515
    509516                                        contentNode.innerHTML = '';
    … …  
    519526                                                        width: '100%',
    520527                                                        display: 'block'
    521                                                 }
     528                                                },
     529                                                height: self.iframeHeight
    522530                                        } );
    523531
    … …  
    562570
    563571                                        function resize() {
    564                                                 var $iframe, iframeDocHeight;
     572                                                var $iframe;
     573
     574                                                if ( block ) {
     575                                                        return;
     576                                                }
    565577
    566578                                                // Make sure the iframe still exists.
    567579                                                if ( iframe.contentWindow ) {
    568580                                                        $iframe = $( iframe );
    569                                                         iframeDocHeight = $( iframeDoc.body ).height();
    570 
    571                                                         if ( $iframe.height() !== iframeDocHeight ) {
    572                                                                 $iframe.height( iframeDocHeight );
     581                                                        self.iframeHeight = $( iframeDoc.body ).height();
     582
     583                                                        if ( $iframe.height() !== self.iframeHeight ) {
     584                                                                $iframe.height( self.iframeHeight );
    573585                                                                editor.nodeChanged();
    574586                                                        }
    575587                                                }
     588                                        }
     589
     590                                        if ( self.iframeHeight ) {
     591                                                block = true;
     592
     593                                                setTimeout( function() {
     594                                                        block = false;
     595                                                        resize();
     596                                                }, 3000 );
    576597                                        }
    577598
Note: See TracChangeset for help on using the changeset viewer.