forked from mirrors/bookwyrm
[assets] Listen to events as soon as possible.
This commit is contained in:
parent
2f2f7db086
commit
991d897ac7
1 changed files with 23 additions and 15 deletions
|
@ -3,42 +3,50 @@
|
||||||
|
|
||||||
let BookWyrm = new class {
|
let BookWyrm = new class {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.initOnLoad();
|
this.initOnDOMLoaded();
|
||||||
|
this.initReccuringTasks();
|
||||||
this.initEventListeners();
|
this.initEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
initEventListeners() {
|
initEventListeners() {
|
||||||
// buttons that display or hide content
|
// buttons that display or hide content
|
||||||
document.querySelectorAll('[data-controls]')
|
document.querySelectorAll('[data-controls]')
|
||||||
.forEach(t => t.onclick = this.toggleAction.bind(this));
|
.forEach(button => button.onclick = this.toggleAction.bind(this));
|
||||||
|
|
||||||
// javascript interactions (boost/fav)
|
// javascript interactions (boost/fav)
|
||||||
document.querySelectorAll('.interaction')
|
document.querySelectorAll('.interaction')
|
||||||
.forEach(t => t.onsubmit = this.interact.bind(this));
|
.forEach(button => button.onsubmit = this.interact.bind(this));
|
||||||
|
|
||||||
// handle aria settings on menus
|
// handle aria settings on menus
|
||||||
document.querySelectorAll('.pulldown-menu')
|
document.querySelectorAll('.pulldown-menu')
|
||||||
.forEach(t => t.onclick = this.toggleMenu.bind(this));
|
.forEach(button => button.onclick = this.toggleMenu.bind(this));
|
||||||
|
|
||||||
// hidden submit button in a form
|
// hidden submit button in a form
|
||||||
document.querySelectorAll('.hidden-form input')
|
document.querySelectorAll('.hidden-form input')
|
||||||
.forEach(t => t.onchange = this.revealForm.bind(this));
|
.forEach(button => button.onchange = this.revealForm.bind(this));
|
||||||
|
|
||||||
// polling
|
|
||||||
document.querySelectorAll('[data-poll]')
|
|
||||||
.forEach(el => this.polling(el));
|
|
||||||
|
|
||||||
// browser back behavior
|
// browser back behavior
|
||||||
document.querySelectorAll('[data-back]')
|
document.querySelectorAll('[data-back]')
|
||||||
.forEach(t => t.onclick = this.back);
|
.forEach(button => button.onclick = this.back);
|
||||||
}
|
}
|
||||||
|
|
||||||
initOnLoad(){
|
/**
|
||||||
// set up javascript listeners
|
* Execute code once the DOM is loaded.
|
||||||
window.onload = function() {
|
*/
|
||||||
|
initOnDOMLoaded() {
|
||||||
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
document.querySelectorAll('.tab-group')
|
document.querySelectorAll('.tab-group')
|
||||||
.forEach(t => new TabGroup(t));
|
.forEach(tabs => new TabGroup(tabs));
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute recurring tasks.
|
||||||
|
*/
|
||||||
|
initReccuringTasks() {
|
||||||
|
// Polling
|
||||||
|
document.querySelectorAll('[data-poll]')
|
||||||
|
.forEach(liveArea => this.polling(liveArea));
|
||||||
}
|
}
|
||||||
|
|
||||||
back(e) {
|
back(e) {
|
||||||
|
|
Loading…
Reference in a new issue