Changeset 46308
- Timestamp:
- 09/25/2019 09:37:09 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyfifteen/js/functions.js
r42411 r46308 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 ) { … … 97 95 98 96 // Sidebar scrolling. 99 function resize() { 100 windowWidth = $window.width(); 97 function resizeAndScroll() { 98 var windowPos = $window.scrollTop(), 99 windowHeight = $window.height(), 100 sidebarHeight = $sidebar.height(), 101 bodyHeight = $body.height(); 101 102 102 if ( 955 > windowWidth ) { 103 top = bottom = false; 104 $sidebar.removeAttr( 'style' ); 103 if( 955 < $window.width() 104 && bodyHeight > sidebarHeight 105 && ( windowPos + windowHeight ) >= sidebarHeight ) { 106 107 $sidebar.css({ 108 position: "fixed", 109 bottom: sidebarHeight > windowHeight ? 0 : 'auto' 110 }); 111 } else { 112 $sidebar.css('position', 'relative') 105 113 } 106 }107 108 function scroll() {109 var windowPos = $window.scrollTop();110 111 if ( 955 > windowWidth ) {112 return;113 }114 115 sidebarHeight = $sidebar.height();116 windowHeight = $window.height();117 bodyHeight = $body.height();118 119 if ( sidebarHeight + adminbarOffset > windowHeight ) {120 if ( windowPos > lastWindowPos ) {121 if ( top ) {122 top = false;123 topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;124 $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );125 } else if ( ! bottom && windowPos + windowHeight > sidebarHeight + $sidebar.offset().top && sidebarHeight + adminbarOffset < bodyHeight ) {126 bottom = true;127 $sidebar.attr( 'style', 'position: fixed; bottom: 0;' );128 }129 } else if ( windowPos < lastWindowPos ) {130 if ( bottom ) {131 bottom = false;132 topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;133 $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );134 } else if ( ! top && windowPos + adminbarOffset < $sidebar.offset().top ) {135 top = true;136 $sidebar.attr( 'style', 'position: fixed;' );137 }138 } else {139 top = bottom = false;140 topOffset = ( $sidebar.offset().top > 0 ) ? $sidebar.offset().top - adminbarOffset : 0;141 $sidebar.attr( 'style', 'top: ' + topOffset + 'px;' );142 }143 } else if ( ! top ) {144 top = true;145 $sidebar.attr( 'style', 'position: fixed;' );146 }147 148 lastWindowPos = windowPos;149 }150 151 function resizeAndScroll() {152 resize();153 scroll();154 114 } 155 115 … … 158 118 $window = $( window ); 159 119 $sidebar = $( '#sidebar' ).first(); 160 adminbarOffset = $body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0;161 120 162 121 $window 163 .on( 'scroll.twentyfifteen', scroll )122 .on( 'scroll.twentyfifteen', resizeAndScroll ) 164 123 .on( 'load.twentyfifteen', onResizeARIA ) 165 124 .on( 'resize.twentyfifteen', function() { … … 170 129 $sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll ); 171 130 172 resizeAndScroll(); 173 174 for ( var i = 1; i < 6; i++ ) { 131 for ( var i = 0; i < 6; i++ ) { 175 132 setTimeout( resizeAndScroll, 100 * i ); 176 133 } -
trunk/tests/qunit/fixtures/wp-api-generated.js
r46252 r46308 7435 7435 "queryable": false, 7436 7436 "slug": "pending", 7437 "date_floating": false,7437 "date_floating": true, 7438 7438 "_links": { 7439 7439 "archives": [
Note: See TracChangeset
for help on using the changeset viewer.