Fix for event listeners being duplicated on source change

This commit is contained in:
Sam
2016-01-17 01:25:11 +11:00
parent f18fb3f26d
commit f87a10ae0b
7 changed files with 62 additions and 40 deletions

View File

@ -33,6 +33,10 @@ shr.setup({
buttons[i].addEventListener('click', newSource);
}
window.addEventListener('popstate', function(event) {
console.log(event);
});
function toggleClass(element, className, state) {
if (element) {
if (element.classList) {
@ -113,6 +117,10 @@ shr.setup({
break;
}
if (window.history && window.history.pushState) {
history.pushState({ 'type': type }, '', '#' + type);
}
for (var x = buttons.length - 1; x >= 0; x--) {
toggleClass(buttons[x].parentElement, 'active', false);
}