Skip to content

Commit

Permalink
return early instead of erroring out on nonstandard page
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahs committed Nov 17, 2020
1 parent 9143e5d commit 7848e3c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
2 changes: 2 additions & 0 deletions javascripts/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export default function initializeEvents () {
})
})

if (!document.querySelector('.sidebar-products')) return

// Navigate event
Array.from(
document.querySelectorAll('.sidebar-products details')
Expand Down
41 changes: 19 additions & 22 deletions javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@ import filterCodeExamples from './filter-code-examples'
import allArticles from './all-articles'
import devToc from './dev-toc'

if (location.pathname.endsWith('/dev-toc')) {
document.addEventListener('DOMContentLoaded', async () => {
displayPlatformSpecificContent()
explorer()
search()
nav()
browserDateFormatter()
deprecationBanner()
sidebar()
wrapCodeTerms()
print()
localization()
await fillCsrf() // this must complete before any POST calls
helpfulness()
experiment()
copyCode()
initializeEvents()
filterCodeExamples()
allArticles()
devToc()
} else {
document.addEventListener('DOMContentLoaded', async () => {
displayPlatformSpecificContent()
explorer()
search()
nav()
browserDateFormatter()
deprecationBanner()
sidebar()
wrapCodeTerms()
print()
localization()
await fillCsrf() // this must complete before any POST calls
helpfulness()
experiment()
copyCode()
initializeEvents()
filterCodeExamples()
allArticles()
})
}
})
2 changes: 2 additions & 0 deletions javascripts/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export default function () {
const hamburgerButton = document.querySelector('.nav-mobile-burgerIcon')
const mobileDropdown = document.querySelector('.nav-mobile-dropdown')

if (!(hamburgerButton && mobileDropdown)) return

hamburgerButton.addEventListener('click', (event) => {
event.preventDefault()
hamburgerButton.classList.toggle('js-open')
Expand Down
2 changes: 2 additions & 0 deletions javascripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const resultTemplate = (item) => {
}

export default function () {
if (!document.querySelector('#search-results-container')) return

window.initialPageLoad = true
const opts = {

Expand Down

0 comments on commit 7848e3c

Please sign in to comment.