mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Moves localstorage handlers into its own file
This commit is contained in:
parent
9a20b5dbd5
commit
baee0796cd
2 changed files with 27 additions and 26 deletions
27
bookwyrm/static/js/localstorage.js
Normal file
27
bookwyrm/static/js/localstorage.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// set javascript listeners
|
||||||
|
window.onload = function() {
|
||||||
|
// display based on localstorage vars
|
||||||
|
document.querySelectorAll('[data-hide]')
|
||||||
|
.forEach(t => setDisplay(t));
|
||||||
|
|
||||||
|
// update localstorage
|
||||||
|
Array.from(document.getElementsByClassName('set-display'))
|
||||||
|
.forEach(t => t.onclick = updateDisplay);
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateDisplay(e) {
|
||||||
|
// used in set reading goal
|
||||||
|
var key = e.target.getAttribute('data-id');
|
||||||
|
var value = e.target.getAttribute('data-value');
|
||||||
|
window.localStorage.setItem(key, value);
|
||||||
|
|
||||||
|
document.querySelectorAll('[data-hide="' + key + '"]')
|
||||||
|
.forEach(t => setDisplay(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDisplay(el) {
|
||||||
|
// used in set reading goal
|
||||||
|
var key = el.getAttribute('data-hide');
|
||||||
|
var value = window.localStorage.getItem(key);
|
||||||
|
addRemoveClass(el, 'hidden', value);
|
||||||
|
}
|
|
@ -23,14 +23,6 @@ window.onload = function() {
|
||||||
Array.from(document.getElementsByClassName('pulldown-menu'))
|
Array.from(document.getElementsByClassName('pulldown-menu'))
|
||||||
.forEach(t => t.onclick = toggleMenu);
|
.forEach(t => t.onclick = toggleMenu);
|
||||||
|
|
||||||
// display based on localstorage vars
|
|
||||||
document.querySelectorAll('[data-hide]')
|
|
||||||
.forEach(t => setDisplay(t));
|
|
||||||
|
|
||||||
// update localstorage
|
|
||||||
Array.from(document.getElementsByClassName('set-display'))
|
|
||||||
.forEach(t => t.onclick = updateDisplay);
|
|
||||||
|
|
||||||
// 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 = revealForm);
|
.forEach(t => t.onchange = revealForm);
|
||||||
|
@ -78,24 +70,6 @@ function revealForm(e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateDisplay(e) {
|
|
||||||
// used in set reading goal
|
|
||||||
var key = e.target.getAttribute('data-id');
|
|
||||||
var value = e.target.getAttribute('data-value');
|
|
||||||
window.localStorage.setItem(key, value);
|
|
||||||
|
|
||||||
document.querySelectorAll('[data-hide="' + key + '"]')
|
|
||||||
.forEach(t => setDisplay(t));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setDisplay(el) {
|
|
||||||
// used in set reading goal
|
|
||||||
var key = el.getAttribute('data-hide');
|
|
||||||
var value = window.localStorage.getItem(key);
|
|
||||||
addRemoveClass(el, 'hidden', value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function toggleAction(e) {
|
function toggleAction(e) {
|
||||||
var el = e.currentTarget;
|
var el = e.currentTarget;
|
||||||
var pressed = el.getAttribute('aria-pressed') == 'false';
|
var pressed = el.getAttribute('aria-pressed') == 'false';
|
||||||
|
|
Loading…
Reference in a new issue