Make WordPress Core

Changeset 30918


Ignore:
Timestamp:
12/16/2014 07:42:09 PM (12 years ago)
Author:
johnbillion
Message:

Improve the fix for menu shakiness when over-scrolling. Recalculate heights on editor auto-resize.

Merges [30852] to the 4.1 branch.

See #30692.

Location:
branches/4.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

  • branches/4.1/src/wp-admin/js/common.js

    r30917 r30918  
    194194                pinnedMenuTop = false,
    195195                pinnedMenuBottom = false,
    196                 isScrolling = false,
    197                 scrollTimer,
    198196                menuTop = 0,
     197                menuIsPinned = false,
    199198                height = {
    200                         document: $document.height(),
    201199                        window: $window.height(),
    202200                        wpwrap: $wpwrap.height(),
    … …  
    545543        })();
    546544
    547         function pinMenu() {
    548                 var windowPos = $window.scrollTop();
     545        function pinMenu( event ) {
     546                var windowPos = $window.scrollTop(),
     547                        resizing = ! event || event.type !== 'scroll';
    549548
    550549                if ( isIOS || isIE8 || $adminmenu.data( 'wp-responsive' ) ) {
    … …  
    552551                }
    553552
    554                 if ( height.menu + height.adminbar + 20 > height.wpwrap ) { // 20px "buffer"
     553                if ( height.menu + height.adminbar < height.window ||
     554                        height.menu + height.adminbar + 20 > height.wpwrap ) {
    555555                        unpinMenu();
    556556                        return;
    557557                }
     558
     559                menuIsPinned = true;
    558560
    559561                if ( height.menu + height.adminbar > height.window ) {
    … …  
    572574
    573575                                return;
    574                         } else if ( windowPos + height.window > height.document - 1 ) {
     576                        } else if ( windowPos + height.window > $document.height() - 1 ) {
    575577                                if ( ! pinnedMenuBottom ) {
    576578                                        pinnedMenuBottom = true;
    … …  
    639641                                        });
    640642                                }
    641                         } else {
     643                        } else if ( resizing ) {
    642644                                // Resizing
    643645                                pinnedMenuTop = pinnedMenuBottom = false;
    … …  
    661663        function resetHeights() {
    662664                height = {
    663                         document: $document.height(),
    664665                        window: $window.height(),
    665666                        wpwrap: $wpwrap.height(),
    … …  
    670671
    671672        function unpinMenu() {
    672                 if ( isIOS ) {
     673                if ( isIOS || ! menuIsPinned ) {
    673674                        return;
    674675                }
    675676
    676                 pinnedMenuTop = pinnedMenuBottom = false;
     677                pinnedMenuTop = pinnedMenuBottom = menuIsPinned = false;
    677678                $adminMenuWrap.css({
    678679                        position: '',
    … …  
    697698        }
    698699
    699         function scrollStart() {
    700                 if ( isScrolling ) {
    701                         window.clearTimeout( scrollTimer );
    702 
    703                         scrollTimer = window.setTimeout( function() {
    704                                 isScrolling = false;
    705                         }, 200 );
    706                 } else {
    707                         isScrolling = true;
    708                         $document.triggerHandler( 'wp-scroll-start' );
    709                 }
    710         }
    711 
    712700        if ( ! isIOS ) {
    713                 $window.on( 'scroll.pin-menu', function() {
    714                         scrollStart();
    715                         pinMenu();
     701                $window.on( 'scroll.pin-menu', pinMenu );
     702                $document.on( 'tinymce-editor-init.pin-menu', function( event, editor ) {
     703                        editor.on( 'wp-autoresize', resetHeights );
    716704                });
    717705        }
Note: See TracChangeset for help on using the changeset viewer.