diff --git a/themes/twentyfifteen/js/functions.js b/themes/twentyfifteen/js/functions.js index be6515f..848c102 100644 --- a/themes/twentyfifteen/js/functions.js +++ b/themes/twentyfifteen/js/functions.js @@ -75,62 +75,7 @@ } } ); } )(); - - /** - * Add or remove ARIA attributes. - * - * Uses jQuery's width() function to determine the size of the window and add - * the default ARIA attributes for the menu toggle if it's visible. - * - * @since Twenty Fifteen 1.1 - */ - function onResizeARIA() { - if ( 955 > $window.width() ) { - button.attr( 'aria-expanded', 'false' ); - secondary.attr( 'aria-expanded', 'false' ); - button.attr( 'aria-controls', 'secondary' ); - } else { - button.removeAttr( 'aria-expanded' ); - secondary.removeAttr( 'aria-expanded' ); - button.removeAttr( 'aria-controls' ); - } - } - - // Sidebar scrolling. - function resizeAndScroll() { - var windowPos = $window.scrollTop(), - windowHeight = $window.height(), - sidebarHeight = $sidebar.height(), - pageHeight = $( '#page' ).height(); - - if ( 955 < $window.width() && pageHeight > sidebarHeight && ( windowPos + windowHeight ) >= sidebarHeight ) { - $sidebar.css({ - position: 'fixed', - bottom: sidebarHeight > windowHeight ? 0 : 'auto' - }); - } else { - $sidebar.css('position', 'relative'); - } - } - - $( function() { - $body = $( document.body ); - $window = $( window ); - $sidebar = $( '#sidebar' ).first(); - - $window - .on( 'scroll.twentyfifteen', resizeAndScroll ) - .on( 'load.twentyfifteen', onResizeARIA ) - .on( 'resize.twentyfifteen', function() { - clearTimeout( resizeTimer ); - resizeTimer = setTimeout( resizeAndScroll, 500 ); - onResizeARIA(); - } ); - $sidebar.on( 'click.twentyfifteen keydown.twentyfifteen', 'button', resizeAndScroll ); - - for ( var i = 0; i < 6; i++ ) { - setTimeout( resizeAndScroll, 100 * i ); - } - } ); + + $('#sidebar, #content').theiaStickySidebar(); } )( jQuery ); diff --git a/themes/twentyfifteen/js/theia-sticky-sidebar.min.js b/themes/twentyfifteen/js/theia-sticky-sidebar.min.js new file mode 100644 index 0000000..7bcdd11 --- /dev/null +++ b/themes/twentyfifteen/js/theia-sticky-sidebar.min.js @@ -0,0 +1 @@ +!function(i){i.fn.theiaStickySidebar=function(t){function e(t,e){var a=o(t,e);a||(console.log("TSS: Body width smaller than options.minWidth. Init is delayed."),i(document).on("scroll."+t.namespace,function(t,e){return function(a){var n=o(t,e);n&&i(this).unbind(a)}}(t,e)),i(window).on("resize."+t.namespace,function(t,e){return function(a){var n=o(t,e);n&&i(this).unbind(a)}}(t,e)))}function o(t,e){return t.initialized===!0||!(i("body").width().theiaStickySidebar:after {content: ""; display: table; clear: both;}')),e.each(function(){function e(){a.fixedScrollTop=0,a.sidebar.css({"min-height":"1px"}),a.stickySidebar.css({position:"static",width:"",transform:"none"})}function o(t){var e=t.height();return t.children().each(function(){e=Math.max(e,i(this).height())}),e}var a={};if(a.sidebar=i(this),a.options=t||{},a.container=i(a.options.containerSelector),0==a.container.length&&(a.container=a.sidebar.parent()),a.sidebar.parents().css("-webkit-transform","none"),a.sidebar.css({position:a.options.defaultPosition,overflow:"visible","-webkit-box-sizing":"border-box","-moz-box-sizing":"border-box","box-sizing":"border-box"}),a.stickySidebar=a.sidebar.find(".theiaStickySidebar"),0==a.stickySidebar.length){var s=/(?:text|application)\/(?:x-)?(?:javascript|ecmascript)/i;a.sidebar.find("script").filter(function(i,t){return 0===t.type.length||t.type.match(s)}).remove(),a.stickySidebar=i("
").addClass("theiaStickySidebar").append(a.sidebar.children()),a.sidebar.append(a.stickySidebar)}a.marginBottom=parseInt(a.sidebar.css("margin-bottom")),a.paddingTop=parseInt(a.sidebar.css("padding-top")),a.paddingBottom=parseInt(a.sidebar.css("padding-bottom"));var r=a.stickySidebar.offset().top,d=a.stickySidebar.outerHeight();a.stickySidebar.css("padding-top",1),a.stickySidebar.css("padding-bottom",1),r-=a.stickySidebar.offset().top,d=a.stickySidebar.outerHeight()-d-r,0==r?(a.stickySidebar.css("padding-top",0),a.stickySidebarPaddingTop=0):a.stickySidebarPaddingTop=1,0==d?(a.stickySidebar.css("padding-bottom",0),a.stickySidebarPaddingBottom=0):a.stickySidebarPaddingBottom=1,a.previousScrollTop=null,a.fixedScrollTop=0,e(),a.onScroll=function(a){if(a.stickySidebar.is(":visible")){if(i("body").width()a.container.width())return void e()}var r=i(document).scrollTop(),d="static";if(r>=a.sidebar.offset().top+(a.paddingTop-a.options.additionalMarginTop)){var c,p=a.paddingTop+t.additionalMarginTop,b=a.paddingBottom+a.marginBottom+t.additionalMarginBottom,l=a.sidebar.offset().top,f=a.sidebar.offset().top+o(a.container),h=0+t.additionalMarginTop,g=a.stickySidebar.outerHeight()+p+b0?Math.min(y,h):Math.max(y,c-a.stickySidebar.outerHeight()),y=Math.max(y,u),y=Math.min(y,S-a.stickySidebar.outerHeight());var k=a.container.height()==a.stickySidebar.outerHeight();d=(k||y!=h)&&(k||y!=c-a.stickySidebar.outerHeight())?r+y-a.sidebar.offset().top-a.paddingTop<=t.additionalMarginTop?"static":"absolute":"fixed"}if("fixed"==d){var v=i(document).scrollLeft();a.stickySidebar.css({position:"fixed",width:n(a.stickySidebar)+"px",transform:"translateY("+y+"px)",left:a.sidebar.offset().left+parseInt(a.sidebar.css("padding-left"))-v+"px",top:"0px"})}else if("absolute"==d){var x={};"absolute"!=a.stickySidebar.css("position")&&(x.position="absolute",x.transform="translateY("+(r+y-a.sidebar.offset().top-a.stickySidebarPaddingTop-a.stickySidebarPaddingBottom)+"px)",x.top="0px"),x.width=n(a.stickySidebar)+"px",x.left="",a.stickySidebar.css(x)}else"static"==d&&e();"static"!=d&&1==a.options.updateSidebarHeight&&a.sidebar.css({"min-height":a.stickySidebar.outerHeight()+a.stickySidebar.offset().top-a.sidebar.offset().top+a.paddingBottom}),a.previousScrollTop=r}},a.onScroll(a),i(document).on("scroll."+a.options.namespace,function(i){return function(){i.onScroll(i)}}(a)),i(window).on("resize."+a.options.namespace,function(i){return function(){i.stickySidebar.css({position:"static"}),i.onScroll(i)}}(a)),"undefined"!=typeof ResizeSensor&&new ResizeSensor(a.stickySidebar[0],function(i){return function(){i.onScroll(i)}}(a))})}function n(i){var t;try{t=i[0].getBoundingClientRect().width}catch(i){}return"undefined"==typeof t&&(t=i.width()),t}var s={containerSelector:"",additionalMarginTop:0,additionalMarginBottom:0,updateSidebarHeight:!0,minWidth:0,disableOnResponsiveLayouts:!0,sidebarBehavior:"modern",defaultPosition:"relative",namespace:"TSS"};return t=i.extend(s,t),t.additionalMarginTop=parseInt(t.additionalMarginTop)||0,t.additionalMarginBottom=parseInt(t.additionalMarginBottom)||0,e(t,this),this}}(jQuery); diff --git a/themes/twentyfifteen/layout.html.php b/themes/twentyfifteen/layout.html.php index 6cecdb5..d4bc82c 100644 --- a/themes/twentyfifteen/layout.html.php +++ b/themes/twentyfifteen/layout.html.php @@ -106,9 +106,9 @@ - + + -