put global click listener on document element instead of window to ignore secondary...
authorDan Allen <dan@opendevise.com>
Fri, 19 Jul 2019 19:45:34 +0000 (13:45 -0600)
committerDan Allen <dan@opendevise.com>
Sun, 21 Jul 2019 07:21:05 +0000 (01:21 -0600)
src/js/01-nav.js
src/js/03-page-versions.js

index 65481b5..3001c0d 100644 (file)
 
   function showNav (e) {
     if (navToggle.classList.contains('is-active')) return hideNav(e)
-    document.documentElement.classList.add('is-clipped--nav')
+    var html = document.documentElement
+    html.classList.add('is-clipped--nav')
     navToggle.classList.add('is-active')
     navContainer.classList.add('is-active')
-    window.addEventListener('click', hideNav)
+    html.addEventListener('click', hideNav)
     concealEvent(e)
   }
 
   function hideNav (e) {
-    if (e.which === 3 || e.button === 2) return
-    document.documentElement.classList.remove('is-clipped--nav')
+    var html = document.documentElement
+    html.classList.remove('is-clipped--nav')
     navToggle.classList.remove('is-active')
     navContainer.classList.remove('is-active')
-    window.removeEventListener('click', hideNav)
+    html.removeEventListener('click', hideNav)
     concealEvent(e)
   }
 
index d1d4c2a..6b8678b 100644 (file)
@@ -12,7 +12,7 @@
     e.stopPropagation()
   })
 
-  window.addEventListener('click', function () {
+  document.documentElement.addEventListener('click', function () {
     selector.classList.remove('is-active')
   })
 })()