cupper-hugo-theme/public/js/dom-scripts.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-06-26 17:21:58 +02:00
/* expandable sections */
(function () {
function toggle (button, target) {
2017-07-01 13:20:18 +02:00
var expanded = button.getAttribute('aria-expanded') === 'true'
2017-06-26 17:21:58 +02:00
button.setAttribute('aria-expanded', !expanded)
target.hidden = !target.hidden
}
var expanders = document.querySelectorAll('[data-expands]')
Array.prototype.forEach.call(expanders, function (expander) {
var target = document.getElementById(expander.getAttribute('data-expands'))
expander.addEventListener('click', function () {
toggle(expander, target)
})
})
2017-07-01 13:20:18 +02:00
}());
2017-06-26 17:21:58 +02:00
2017-07-01 13:20:18 +02:00
/* menu button */
(function () {
var button = document.getElementById('menu-button')
var menu = document.getElementById('patterns-list')
button.addEventListener('click', function() {
var expanded = this.getAttribute('aria-expanded') === 'true'
this.setAttribute('aria-expanded', !expanded)
})
}());
2017-07-01 12:48:01 +02:00
/* persist navigation scroll point */
2017-07-01 13:20:18 +02:00
(function () {
window.addEventListener('unload', function() {
var scrollPoint = document.getElementById('patterns-nav').scrollTop
localStorage.setItem('scrollPoint', scrollPoint)
})
2017-07-01 12:48:01 +02:00
2017-07-01 13:20:18 +02:00
window.addEventListener('load', function() {
document.getElementById('patterns-nav').scrollTop = parseInt(localStorage.getItem('scrollPoint'))
})
}());