Make WordPress Core

Ticket #29979: 29979.3.patch

File 29979.3.patch, 3.2 KB (added by iseulde, 10 years ago)
  • src/wp-content/themes/twentyfifteen/js/functions.js

     
    66 */
    77
    88( function( $ ) {
     9        'use strict';
     10
    911        $( 'html' ).removeClass( 'no-js' );
    1012
    1113        // Add dropdown toggle that display child menu items.
     
    4749                        $( this ).toggleClass( 'toggled-on' );
    4850                } );
    4951        } )();
    50 } )( jQuery );
    51  No newline at end of file
     52
     53        // Sidebar scrolling.
     54
     55        $( function() {
     56                var     $window = $( window ),
     57                        lastWindowPos = 0,
     58                        $document = $( document ),
     59                        $adminbar = $( '#wpadminbar' ),
     60                        $sidebar = $( '#sidebar' ),
     61                        top = false,
     62                        bottom = false,
     63                        windowWidth, windowHeight, documentHeight,
     64                        adminBarHeight, sidebarWidth, sidebarHeight,
     65                        resizeTimer;
     66
     67                function resize() {
     68                        windowWidth = $window.width();
     69                        windowHeight = $window.height();
     70                        documentHeight = $document.height();
     71                        adminBarHeight = $adminbar.height();
     72                        sidebarWidth = $sidebar.width();
     73                        sidebarHeight = $sidebar.height();
     74
     75                        if ( sidebarWidth === windowWidth ) {
     76                                top = bottom = false;
     77                                $sidebar.removeAttr( 'style' );
     78                        }
     79                }
     80
     81                function scroll() {
     82                        var windowPos = $window.scrollTop();
     83
     84                        if ( sidebarWidth < windowWidth && sidebarHeight + adminBarHeight < documentHeight ) {
     85                                if ( windowPos > lastWindowPos ) {
     86                                        if ( top ) {
     87                                                top = false;
     88                                                $sidebar.attr( 'style', 'top: ' + $sidebar.offset().top + 'px;' );
     89                                        } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top ) {
     90                                                bottom = true;
     91                                                $sidebar.attr( 'style', 'position: fixed;bottom: 0;' );
     92                                        }
     93                                } else if ( windowPos < lastWindowPos ) {
     94                                        if ( bottom ) {
     95                                                bottom = false;
     96                                                $sidebar.attr( 'style', 'top: ' + $sidebar.offset().top + 'px;' );
     97                                        } else if ( ! top && windowPos + adminBarHeight < $sidebar.offset().top ) {
     98                                                top = true;
     99                                                $sidebar.attr( 'style', 'position: fixed;' );
     100                                        }
     101                                } else {
     102                                        top = bottom = false;
     103                                        $sidebar.attr( 'style', 'top: ' + $sidebar.offset().top + 'px;' );
     104                                }
     105                        }
     106
     107                        lastWindowPos = windowPos;
     108                }
     109
     110                function resizeAndScroll() {
     111                        resize();
     112                        scroll();
     113                }
     114
     115                $window.on( 'scroll.pin-sidebar', scroll );
     116
     117                $window.resize( function() {
     118                        clearTimeout( resizeTimer );
     119
     120                        resizeTimer = setTimeout( resizeAndScroll, 200 );
     121                } );
     122
     123                resizeAndScroll();
     124
     125                for ( var i = 1; i < 6; i++ ) {
     126                        setTimeout( resizeAndScroll, 500 * i );
     127                }
     128        } );
     129} )( jQuery );
  • src/wp-content/themes/twentyfifteen/style.css

     
    38043804
    38053805        .sidebar {
    38063806                float: left;
    3807                 height: 100%;
    3808                 overflow-y: auto;
    38093807                margin-right: -100%;
    38103808                max-width: 413px;
    3811                 -webkit-overflow-scrolling: touch;
    3812                 position: fixed;
     3809                position: absolute;
    38133810                width: 29.4118%;
    38143811        }
    38153812
    3816         .admin-bar .sidebar {
    3817                 height: -webkit-calc(100% - 32px);
    3818                 height: calc(100% - 32px);
    3819         }
    3820 
    38213813        .secondary {
    38223814                background-color: transparent;
    38233815                display: block;