bookwyrm/bookwyrm/static/js/localstorage.js
Fabien Basmaison 70c652d565 [assets] Add rules to ESLint:
- Fix long line.
- Enforce a few stylistic habits:

    - Avoid some potential dangerous constructs.
    - `arrow-spacing`: Use at least one space around arrows.
    - `keyword-spacing`: Use at least one space around keywords (if, else, for…).
    - `no-multiple-empty-lines`: Only use one empty line between code.
	- `no-var`: Use `let` or `const` instead of `var`:
    - `padded-blocks`: Do not pad blocks.
    - `padding-line-between-statements`: Use empty lines between some statements.
    - `space-before-blocks`: Use at least one space before the opening brace of a block.
2021-04-06 10:42:52 +02:00

35 lines
1,004 B
JavaScript

/* exported LocalStorageTools */
/* globals BookWyrm */
let LocalStorageTools = new class {
constructor() {
// display based on localstorage vars
document.querySelectorAll('[data-hide]')
.forEach(t => this.setDisplay(t));
// update localstorage
document.querySelectorAll('.set-display')
.forEach(t => t.onclick = this.updateDisplay.bind(this));
}
// set javascript listeners
updateDisplay(e) {
// used in set reading goal
let key = e.target.getAttribute('data-id');
let value = e.target.getAttribute('data-value');
window.localStorage.setItem(key, value);
document.querySelectorAll('[data-hide="' + key + '"]')
.forEach(t => this.setDisplay(t));
}
setDisplay(el) {
// used in set reading goal
let key = el.getAttribute('data-hide');
let value = window.localStorage.getItem(key);
BookWyrm.addRemoveClass(el, 'hidden', value);
}
}