function initMobileMenu () {
      var mobileBar = document.getElementById('mobile-bar')
      var sidebar = document.querySelector('.sidebar')
      var menuButton = mobileBar.querySelector('.menu-button')
  
      menuButton.addEventListener('click', function () {
        sidebar.classList.toggle('open')
      })
  
      document.body.addEventListener('click', function (e) {
        if (e.target !== menuButton && !sidebar.contains(e.target)) {
          sidebar.classList.remove('open')
        }
      })
  
      // Toggle sidebar on swipe
      var start = {}, end = {}
  
      document.body.addEventListener('touchstart', function (e) {
        start.x = e.changedTouches[0].clientX
        start.y = e.changedTouches[0].clientY
      })
  
      document.body.addEventListener('touchend', function (e) {
        end.y = e.changedTouches[0].clientY
        end.x = e.changedTouches[0].clientX
  
        var xDiff = end.x - start.x
        var yDiff = end.y - start.y
  
        if (Math.abs(xDiff) > Math.abs(yDiff)) {
          if (xDiff > 0 && start.x <= 80) sidebar.classList.add('open')
          else sidebar.classList.remove('open')
        }
      })
    }
/**
     * Mobile burger menu button and gesture for toggling sidebar
     */
Mobile burger menu button and gesture for toggling sidebar
Mobile burger menu button and gesture for toggling sidebar
function initMobileMenu () {
      var mobileBar = document.getElementById('mobile-bar')
      var sidebar = document.querySelector('.sidebar')
      var menuButton = mobileBar.querySelector('.menu-button')
      menuButton.addEventListener('click', function () {
        sidebar.classList.toggle('open')
      })
      document.body.addEventListener('click', function (e) {
        if (e.target !== menuButton && !sidebar.contains(e.target)) {
          sidebar.classList.remove('open')
        }
      })
      var start = {}, end = {}
      document.body.addEventListener('touchstart', function (e) {
        start.x = e.changedTouches[0].clientX
        start.y = e.changedTouches[0].clientY
      })
      document.body.addEventListener('touchend', function (e) {
        end.y = e.changedTouches[0].clientY
        end.x = e.changedTouches[0].clientX
        var xDiff = end.x - start.x
        var yDiff = end.y - start.y
        if (Math.abs(xDiff) > Math.abs(yDiff)) {
          if (xDiff > 0 && start.x <= 80) sidebar.classList.add('open')
          else sidebar.classList.remove('open')
        }
      })
    }
function initMobileMenu ( ) { var mobileBar = document . getElementById ( 'mobile-bar' ) var sidebar = document . querySelector ( '.sidebar' ) var menuButton = mobileBar . querySelector ( '.menu-button' ) menuButton . addEventListener ( 'click' , function ( ) { sidebar . classList . toggle ( 'open' ) } ) document . body . addEventListener ( 'click' , function ( e ) { if ( e . target !== menuButton && ! sidebar . contains ( e . target ) ) { sidebar . classList . remove ( 'open' ) } } ) var start = { } , end = { } document . body . addEventListener ( 'touchstart' , function ( e ) { start . x = e . changedTouches [ 0 ] . clientX start . y = e . changedTouches [ 0 ] . clientY } ) document . body . addEventListener ( 'touchend' , function ( e ) { end . y = e . changedTouches [ 0 ] . clientY end . x = e . changedTouches [ 0 ] . clientX var xDiff = end . x - start . x var yDiff = end . y - start . y if ( Math . abs ( xDiff ) > Math . abs ( yDiff ) ) { if ( xDiff > 0 && start . x <= 80 ) sidebar . classList . add ( 'open' ) else sidebar . classList . remove ( 'open' ) } } ) }
Mobile burger menu button and gesture for toggling sidebar
Mobile burger menu button and gesture for toggling sidebar
// Toggle sidebar on swipe