2021-04-06 03:44:59 -04:00
|
|
|
/* exported LocalStorageTools */
|
|
|
|
/* globals BookWyrm */
|
2021-03-31 11:07:28 -04:00
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
let LocalStorageTools = new class {
|
|
|
|
constructor() {
|
|
|
|
// display based on localstorage vars
|
|
|
|
document.querySelectorAll('[data-hide]')
|
|
|
|
.forEach(t => this.setDisplay(t));
|
2021-03-18 12:02:07 -04:00
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
// update localstorage
|
|
|
|
document.querySelectorAll('.set-display')
|
2021-04-06 05:37:23 -04:00
|
|
|
.forEach(t => t.addEventListener('click', this.updateDisplay.bind(this)));
|
2021-04-06 03:44:59 -04:00
|
|
|
}
|
2021-03-18 12:02:07 -04:00
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
// set javascript listeners
|
|
|
|
updateDisplay(e) {
|
|
|
|
// used in set reading goal
|
2021-04-06 04:42:52 -04:00
|
|
|
let key = e.target.getAttribute('data-id');
|
|
|
|
let value = e.target.getAttribute('data-value');
|
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
window.localStorage.setItem(key, value);
|
2021-04-06 03:06:12 -04:00
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
document.querySelectorAll('[data-hide="' + key + '"]')
|
|
|
|
.forEach(t => this.setDisplay(t));
|
|
|
|
}
|
2021-04-06 03:06:12 -04:00
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
setDisplay(el) {
|
|
|
|
// used in set reading goal
|
2021-04-06 04:42:52 -04:00
|
|
|
let key = el.getAttribute('data-hide');
|
|
|
|
let value = window.localStorage.getItem(key);
|
|
|
|
|
2021-04-06 03:44:59 -04:00
|
|
|
BookWyrm.addRemoveClass(el, 'hidden', value);
|
|
|
|
}
|
|
|
|
}
|