Make WordPress Core

Changeset 30917 for branches/4.1


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

Fix menu shakiness when over-scrolling in Chrome and Safari on MacOS.

Merges [30844] 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

    r30738 r30917  
    194194                pinnedMenuTop = false,
    195195                pinnedMenuBottom = false,
     196                isScrolling = false,
     197                scrollTimer,
    196198                menuTop = 0,
    197199                height = {
     200                        document: $document.height(),
    198201                        window: $window.height(),
    199202                        wpwrap: $wpwrap.height(),
     
    555558
    556559                if ( height.menu + height.adminbar > height.window ) {
     560                        // Check for overscrolling
     561                        if ( windowPos < 0 ) {
     562                                if ( ! pinnedMenuTop ) {
     563                                        pinnedMenuTop = true;
     564                                        pinnedMenuBottom = false;
     565
     566                                        $adminMenuWrap.css({
     567                                                position: 'fixed',
     568                                                top: '',
     569                                                bottom: ''
     570                                        });
     571                                }
     572
     573                                return;
     574                        } else if ( windowPos + height.window > height.document - 1 ) {
     575                                if ( ! pinnedMenuBottom ) {
     576                                        pinnedMenuBottom = true;
     577                                        pinnedMenuTop = false;
     578
     579                                        $adminMenuWrap.css({
     580                                                position: 'fixed',
     581                                                top: '',
     582                                                bottom: 0
     583                                        });
     584                                }
     585
     586                                return;
     587                        }
     588
    557589                        if ( windowPos > lastScrollPosition ) {
    558590                                // Scrolling down
     
    627659        }
    628660
     661        function resetHeights() {
     662                height = {
     663                        document: $document.height(),
     664                        window: $window.height(),
     665                        wpwrap: $wpwrap.height(),
     666                        adminbar: $adminbar.height(),
     667                        menu: $adminMenuWrap.height()
     668                };
     669        }
     670
    629671        function unpinMenu() {
    630672                if ( isIOS ) {
     
    641683
    642684        function setPinMenu() {
     685                resetHeights();
     686
    643687                if ( $adminmenu.data('wp-responsive') ) {
    644688                        $body.removeClass( 'sticky-menu' );
     
    653697        }
    654698
     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
    655712        if ( ! isIOS ) {
    656                 $window.on( 'scroll.pin-menu', pinMenu );
     713                $window.on( 'scroll.pin-menu', function() {
     714                        scrollStart();
     715                        pinMenu();
     716                });
    657717        }
    658718
     
    793853        setPinMenu();
    794854
    795         $document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu', function() {
    796                 height.wpwrap = $wpwrap.height();
    797                 height.window = $window.height();
    798                 height.adminbar = $adminbar.height();
    799                 setPinMenu();
    800         }).on( 'wp-collapse-menu.pin-menu', function() {
    801                 height.wpwrap = $wpwrap.height();
    802                 height.menu = $adminMenuWrap.height();
    803                 setPinMenu();
    804         });
    805 
     855        $document.on( 'wp-window-resized.pin-menu postboxes-columnchange.pin-menu postbox-toggled.pin-menu wp-collapse-menu.pin-menu wp-scroll-start.pin-menu', setPinMenu );
    806856});
    807857
Note: See TracChangeset for help on using the changeset viewer.