Make WordPress Core

Changeset 21963


Ignore:
Timestamp:
09/24/2012 03:08:31 AM (14 years ago)
Author:
azaozz
Message:

DFW: add scroll locking to prevent scrolling to top in WebKit on paste, add auto-resize throttling to 0.5 sec, only compare scrollHeight values (works well in all supported browsers), fixes #21979

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js

    r21266 r21963  
    77(function() {
    88        tinymce.create('tinymce.plugins.wpFullscreenPlugin', {
     9                resize_timeout: false,
    910
    1011                init : function(ed, url) {
    … …  
    120121                         * This method gets executed each time the editor needs to resize.
    121122                         */
    122                         function resize() {
    123                                 var d = ed.getDoc(), DOM = tinymce.DOM, resizeHeight, myHeight;
     123                        function resize(editor, e) {
     124                                var DOM = tinymce.DOM, body = ed.getBody(), ifr = DOM.get(ed.id + '_ifr'), height, y = ed.dom.win.scrollY;
    124125
    125                                 // Get height differently depending on the browser used
    126                                 if ( tinymce.isWebKit )
    127                                         myHeight = d.body.offsetHeight;
    128                                 else
    129                                         myHeight = d.body.scrollHeight;
     126                                if ( t.resize_timeout )
     127                                        return;
    130128
    131                                 // Don't make it smaller than 300px
    132                                 resizeHeight = (myHeight > 300) ? myHeight : 300;
     129                                // sometimes several events are fired few ms apart, trottle down resizing a little
     130                                t.resize_timeout = true;
     131                                setTimeout(function(){
     132                                        t.resize_timeout = false;
     133                                }, 500);
    133134
    134                                 // Resize content element
    135                                 if ( oldHeight != resizeHeight ) {
    136                                         DOM.setStyle(DOM.get(ed.id + '_ifr'), 'height', resizeHeight + 'px');
    137                                         oldHeight = resizeHeight;
    138                                         ed.getWin().scrollTo(0,0);
     135                                height = body.scrollHeight > 300 ? body.scrollHeight : 300;
     136
     137                                if ( height != ifr.scrollHeight ) {
     138                                        DOM.setStyle(ifr, 'height', height + 'px');
     139                                        ed.getWin().scrollTo(0, 0); // iframe window object, make sure there's no scrolling
     140                                }
     141
     142                                // WebKit scrolls to top on paste...
     143                                if ( e && e.type == 'paste' && tinymce.isWebKit ) {
     144                                        setTimeout(function(){
     145                                                ed.dom.win.scrollTo(0, y);
     146                                        }, 40);
    139147                                }
    140148                        };
    … …  
    151159                        });
    152160
    153                         if (ed.getParam('autoresize_on_init', true)) {
     161                        if ( ed.getParam('autoresize_on_init', true) ) {
    154162                                ed.onLoadContent.add(function(ed, l) {
    155163                                        // Because the content area resizes when its content CSS loads,
Note: See TracChangeset for help on using the changeset viewer.