Make WordPress Core

Changeset 30852 for trunk


Ignore:
Timestamp:
12/15/2014 12:10:18 AM (11 years ago)
Author:
azaozz
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/common.js

    r30844 r30852  
    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.