Skip to content

Commit

Permalink
Forgot to commit some files
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Aug 5, 2019
1 parent 15da0be commit 819efe4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
52 changes: 52 additions & 0 deletions assets/js/hamburger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'

;(function () {
// Preamble: this code is very specific, and clearly made for then
// main nav.
// Currently, this functionality is not need elsewhere, so we didn't
// bother to generalized this.
// No guards too.

// To disable this feature, just remove the script tag.

window.addEventListener('DOMContentLoaded', function () {
var container = document.querySelector('#hamburger')
var button = document.querySelector('#hamburger-toggle')
var target = document.querySelector('#hamburger-target')

// Show hamburger (hidden by default if no js or hamburger disabled).
container.style.display = 'block'

// Get target height.
var baseHeight = getElementHeight(target)

// Do that after the height calculation!
target.className += ' nav__list--slider'

button.addEventListener('click', function (e) {
e.preventDefault()
e.stopPropagation()

var currentMaxHeight = parseInt(target.style.maxHeight, 10)

// If not set or 0, toggle to full height.
// Otherwise, hide.
if (!currentMaxHeight || currentMaxHeight === 0) {
target.style.cssText = 'max-height: ' + baseHeight + 'px'
} else {
target.style.cssText = 'max-height: 0px'
}
})
})

// Clone an element outside the screen to safely get its height, then destroy it.
function getElementHeight (element) {
var clone = element.cloneNode(true)
clone.style.cssText = 'visibility: hidden; display: block; margin: -999px 0'

var height = (element.parentNode.appendChild(clone)).clientHeight
element.parentNode.removeChild(clone)

return height
}
})()
7 changes: 7 additions & 0 deletions assets/js/imagesloaded.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 819efe4

Please sign in to comment.