From 081ddc03aef7becc3b084a9079a2574fd3e3b49b Mon Sep 17 00:00:00 2001 From: Choom Date: Sat, 28 Jan 2023 00:52:56 -0300 Subject: userconf --- static/js/userconf.js | 116 ++++++++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 50 deletions(-) (limited to 'static/js/userconf.js') diff --git a/static/js/userconf.js b/static/js/userconf.js index 0118e88..399878e 100644 --- a/static/js/userconf.js +++ b/static/js/userconf.js @@ -1,35 +1,3 @@ -var request = new XMLHttpRequest(); - -function cargarEstilos() { - var api = '/cgi/api/styles'; - request.open("GET", api, true); - request.send(); -} - -function listarEstilos(id, estilos, def) { - var select = document.getElementById(id); - - for (var i=0; i < estilos.length; i++) { - var opt = document.createElement('option'); - opt.value = estilos[i]; - opt.textContent = estilos[i]; - if (i == def) { - opt.selected = true; - } - select.appendChild(opt); - } -} - -request.onreadystatechange = function() { - if (request.readyState == 4) { - var json = JSON.parse(request.responseText); - if (json.state == "success") { - listarEstilos('stylebbs', json.bbs_styles, json.bbs_styles_default); - listarEstilos('styleib', json.ib_styles, json.ib_styles_default); - } - } -}; - function cambiarModo(e) { var iframe = document.getElementById('examplebbs'); var estilo = document.getElementById('stylebbs').value; @@ -63,7 +31,7 @@ function mostrarEstilo(e) { loc += 'txt/'; } - css.href = loc + estilo.toLowerCase() + ".css"; + css.href = loc + estilo.trim().toLowerCase() + ".css"; var key = 'weabot_style_' + tipo; var estilo = document.getElementById(('style'+tipo)).value; @@ -74,32 +42,41 @@ function cargariframe(tipo) { var iframe = document.createElement('iframe'); iframe.id = 'example' + tipo; iframe.dataset.type = tipo; - iframe.addEventListener('load', cargarDatos); + iframe.addEventListener('load', cargarEstilo); iframe.src = '/static/example/' + tipo + '1.html'; var div = document.getElementById("desc" + tipo); div.appendChild(iframe); } -function cargarDatos(e) { +function cargarEstilo(e) { var tipo = this.dataset.type; var key = 'weabot_style_' + tipo; + if (localStorage.hasOwnProperty(key)) { - var estilo = localStorage.getItem(key); - document.getElementById(('style'+tipo)).value = estilo; + var estilo = localStorage.getItem(key).trim(); + + if (estilo != '') { + document.getElementById(('style'+tipo)).value = estilo; + } else { + localStorage.removeItem(key); + return; + } + mostrarEstilo(e); this.tabIndex = -1; } - this.removeEventListener('load', cargarDatos); + + this.removeEventListener('load', cargarEstilo); } function init(tipo) { - cargariframe(tipo); document.getElementById('style'+tipo).addEventListener('change', mostrarEstilo); + cargariframe(tipo); } function checkboxes() { var chk = document.getElementsByClassName("weabot-obj"); - for (var i=0; i < chk.length; i++) { + for (var i=0; i < chk.length; i++) { chk[i].addEventListener("change", saveInput); } } @@ -151,19 +128,19 @@ function nuevoFiltro(usar, patron, tipo) { var lista = document.getElementById("filterlist"); var fila = document.createElement("tr"); - var selected = ['', '', '', '']; - selected[tipo] = ' selected="selected"'; + var selected = ['', '', '', '']; + selected[tipo] = ' selected="selected"'; var html = '