pass radix to parseInt function (to avoid unnecessary checks and unwanted side effects)
authorDan Allen <dan@opendevise.com>
Tue, 22 Dec 2020 09:25:04 +0000 (02:25 -0700)
committerDan Allen <dan@opendevise.com>
Tue, 22 Dec 2020 09:25:04 +0000 (02:25 -0700)
src/js/02-on-this-page.js
src/js/05-mobile-navbar.js

index 0bf7320..035bea4 100644 (file)
@@ -4,7 +4,7 @@
   var sidebar = document.querySelector('aside.toc.sidebar')
   if (!sidebar) return
   if (document.querySelector('body.-toc')) return sidebar.parentNode.removeChild(sidebar)
-  var levels = parseInt(sidebar.dataset.levels || 2)
+  var levels = parseInt(sidebar.dataset.levels || 2, 10)
   if (levels < 0) return
 
   var articleSelector = 'article.doc'
@@ -30,7 +30,7 @@
     link.textContent = heading.textContent
     links[(link.href = '#' + heading.id)] = link
     var listItem = document.createElement('li')
-    listItem.dataset.level = parseInt(heading.nodeName.slice(1)) - 1
+    listItem.dataset.level = parseInt(heading.nodeName.slice(1), 10) - 1
     listItem.appendChild(link)
     accum.appendChild(listItem)
     return accum
index b718738..892d0e7 100644 (file)
@@ -13,7 +13,7 @@
     if (menu.classList.toggle('is-active')) {
       menu.style.maxHeight = ''
       var expectedMaxHeight = window.innerHeight - Math.round(menu.getBoundingClientRect().top)
-      var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight)
+      var actualMaxHeight = parseInt(window.getComputedStyle(menu).maxHeight, 10)
       if (actualMaxHeight !== expectedMaxHeight) menu.style.maxHeight = expectedMaxHeight + 'px'
     }
   }