Ticket #37536: 37536.2.2.diff
File 37536.2.2.diff, 3.6 KB (added by , 9 years ago) |
---|
-
wp-content/themes/twentyfifteen/js/functions.js
6 6 */ 7 7 8 8 ( function( $ ) { 9 var $body, $window, $sidebar, adminbarOffset, top = false, 10 bottom = false, windowWidth, windowHeight, lastWindowPos = 0, 11 topOffset = 0, bodyHeight, sidebarHeight, resizeTimer, 12 secondary, button; 9 var $body, $window, $sidebar, resizeTimer, 10 secondary, button; 13 11 14 12 function initMainNavigation( container ) { 15 13 // Add dropdown toggle that display child menu items. … … 95 93 } 96 94 97 95 // Sidebar scrolling. 98 function resize() { 99 windowWidth = $window.width(); 96 function resizeAndScroll() { 97 var windowPos = $window.scrollTop(), 98 windowHeight = $window.height(), 99 sidebarHeight = $sidebar.height(), 100 bodyHeight = $body.height(); 100 101 101 if ( 955 > windowWidth ) { 102 top = bottom = false; 103 $sidebar.removeAttr( 'style' ); 104 } 105 } 102 if( 955 < $window.width() 103 && bodyHeight > sidebarHeight 104 && ( windowPos + windowHeight ) >= sidebarHeight ) { 106 105 107 function scroll() { 108 var windowPos = $window.scrollTop(); 109 110 if ( 955 > windowWidth ) { 111 return; 106 $sidebar.css({ 107 position: "fixed", 108 bottom: sidebarHeight > windowHeight ? 0 : 'auto' 109 }); 110 } else { 111 $sidebar.css('position', 'relative') 112 112 } 113 114 sidebarHeight = $sidebar.height();115 windowHeight = $window.height();116 bodyHeight = $body.height();117 118 if ( sidebarHeight + adminbarOffset > windowHeight ) {119 if ( windowPos > lastWindowPos ) {120 if ( top ) {121 top = false;122 topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;123 $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );124 } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) {125 bottom = true;126 $sidebar.attr( 'style', 'position: fixed; bottom: 0;' );127 }128 } else if ( windowPos < lastWindowPos ) {129 if ( bottom ) {130 bottom = false;131 topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;132 $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );133 } else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) {134 top = true;135 $sidebar.attr( 'style', 'position: fixed;' );136 }137 } else {138 top = bottom = false;139 topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;140 $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );141 }142 } else if ( ! top ) {143 top = true;144 $sidebar.attr( 'style', 'position: fixed;' );145 }146 147 lastWindowPos = windowPos;148 113 } 149 114 150 function resizeAndScroll() {151 resize();152 scroll();153 }154 155 115 $( document ).ready( function() { 156 116 $body = $( document.body ); 157 117 $window = $( window ); 158 118 $sidebar = $( '#sidebar' ).first(); 159 adminbarOffset = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;160 119 161 120 $window 162 .on( 'scroll.twentyfifteen', scroll )121 .on( 'scroll.twentyfifteen', resizeAndScroll ) 163 122 .on( 'load.twentyfifteen', onResizeARIA ) 164 123 .on( 'resize.twentyfifteen', function() { 165 124 clearTimeout( resizeTimer ); … … 168 127 } ); 169 128 $sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll ); 170 129 171 resizeAndScroll(); 172 173 for ( var i = 1; i < 6; i++ ) { 130 for ( var i = 0; i < 6; i++ ) { 174 131 setTimeout( resizeAndScroll, 100 * i ); 175 132 } 176 133 } );