/* global CONFIG, Velocity */ document.addEventListener('DOMContentLoaded', () => { const isRight = CONFIG.sidebar.position === 'right'; const mousePos = {}; const sidebarToggleMotion = { lines: document.querySelector('.sidebar-toggle'), init : function() { window.addEventListener('mousedown', this.mousedownHandler); window.addEventListener('mouseup', this.mouseupHandler.bind(this)); document.querySelector('#sidebar-dimmer').addEventListener('click', this.clickHandler.bind(this)); document.querySelector('.sidebar-toggle').addEventListener('click', this.clickHandler.bind(this)); window.addEventListener('sidebar:show', this.showSidebar); window.addEventListener('sidebar:hide', this.hideSidebar); }, mousedownHandler: function(event) { mousePos.X = event.pageX; mousePos.Y = event.pageY; }, mouseupHandler: function(event) { const deltaX = event.pageX - mousePos.X; const deltaY = event.pageY - mousePos.Y; const clickingBlankPart = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY)) < 20 && event.target.matches('.main'); // Fancybox has z-index property, but medium-zoom does not, so the sidebar will overlay the zoomed image. if (clickingBlankPart || event.target.matches('img.medium-zoom-image')) { this.hideSidebar(); } }, clickHandler: function() { document.body.classList.contains('sidebar-active') ? this.hideSidebar() : this.showSidebar(); }, showSidebar: function() { document.body.classList.add('sidebar-active'); if (typeof Velocity === 'function') { Velocity(document.querySelectorAll('.sidebar .motion-element'), isRight ? 'transition.slideRightIn' : 'transition.slideLeftIn', { stagger: 50, drag : true }); } }, hideSidebar: function() { document.body.classList.remove('sidebar-active'); } }; sidebarToggleMotion.init(); function updateFooterPosition() { const footer = document.querySelector('.footer'); const containerHeight = document.querySelector('.header').offsetHeight + document.querySelector('.main').offsetHeight + footer.offsetHeight; footer.classList.toggle('footer-fixed', containerHeight <= window.innerHeight); } updateFooterPosition(); window.addEventListener('resize', updateFooterPosition); window.addEventListener('scroll', updateFooterPosition); });