1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-03 11:46:22 -07:00

Update new/old browse element when settings are saved

This commit is contained in:
Eggbertx 2024-09-08 14:24:12 -07:00
parent 9eda27d38b
commit f03ea709f8
3 changed files with 23 additions and 9 deletions

View file

@ -1,6 +1,7 @@
import $ from "jquery"; import $ from "jquery";
import { alertLightbox } from "./lightbox"; import { alertLightbox } from "./lightbox";
import { getBooleanStorageVal } from "../storage";
export function updateUploadImage($elem: JQuery<HTMLElement>, onLoad?:()=>any) { export function updateUploadImage($elem: JQuery<HTMLElement>, onLoad?:()=>any) {
@ -76,9 +77,9 @@ function addFileUpload(file:File) {
uploadReader.readAsDataURL(file); uploadReader.readAsDataURL(file);
} }
export function replaceBrowseButton() { function replaceBrowseButton() {
const $browseBtn = $<HTMLInputElement>("input[name=imagefile]").hide(); const $browseBtn = $<HTMLInputElement>("input[name=imagefile]").hide();
if($browseBtn.length < 1) return; if($browseBtn.length < 1 || $("div#upload-box").length > 0) return;
$browseBtn.on("change", e => addFileUpload(e.target.files[0])); $browseBtn.on("change", e => addFileUpload(e.target.files[0]));
$("<div/>").attr("id", "upload-box").append( $("<div/>").attr("id", "upload-box").append(
@ -101,3 +102,13 @@ export function replaceBrowseButton() {
}); });
}); });
} }
export function updateBrowseButton() {
const useNewUploader = getBooleanStorageVal("newuploader", true);
if(useNewUploader) {
replaceBrowseButton();
} else {
$("div#upload-box").remove();
$("input[name=imagefile]").show();
}
}

View file

@ -13,7 +13,7 @@ import { addPostDropdown } from "./dom/postdropdown";
import { initFlags } from "./dom/flags"; import { initFlags } from "./dom/flags";
import { initQR } from "./dom/qr"; import { initQR } from "./dom/qr";
import { getBooleanStorageVal } from "./storage"; import { getBooleanStorageVal } from "./storage";
import { replaceBrowseButton } from "./dom/uploaddata"; import { updateBrowseButton } from "./dom/uploaddata";
import "./management/filters"; import "./management/filters";
export function toTop() { export function toTop() {
@ -45,7 +45,7 @@ $(() => {
if(getBooleanStorageVal("useqr", true)) if(getBooleanStorageVal("useqr", true))
initQR(); initQR();
initPostPreviews(); initPostPreviews();
replaceBrowseButton(); updateBrowseButton();
} }
$("div.post, div.reply").each((i, elem) => { $("div.post, div.reply").each((i, elem) => {
addPostDropdown($(elem)); addPostDropdown($(elem));

View file

@ -7,6 +7,7 @@ import { getBooleanStorageVal, getStorageVal, setStorageVal } from "./storage";
import { initPostPreviews } from "./postutil"; import { initPostPreviews } from "./postutil";
import { closeQR, initQR } from "./dom/qr"; import { closeQR, initQR } from "./dom/qr";
import { initWatcher } from "./watcher/watcher"; import { initWatcher } from "./watcher/watcher";
import { updateBrowseButton } from "./dom/uploaddata";
let $settingsButton: TopBarButton = null; let $settingsButton: TopBarButton = null;
@ -30,8 +31,7 @@ class Setting<T = any, E extends HTMLElement = HTMLElement> {
this.key = key; this.key = key;
this.title = title; this.title = title;
this.defaultVal = defaultVal; this.defaultVal = defaultVal;
if(onSave) this.onSave = onSave ?? (()=>true);
this.onSave = onSave;
this.element = null; this.element = null;
} }
getElementValue(): T { getElementValue(): T {
@ -47,6 +47,7 @@ class Setting<T = any, E extends HTMLElement = HTMLElement> {
} }
setStorageValue(newVal: T) { setStorageValue(newVal: T) {
setStorageVal(this.key, newVal); setStorageVal(this.key, newVal);
this.onSave();
} }
createElement(selector = "<input/>", props = {}) { createElement(selector = "<input/>", props = {}) {
return $<E>(selector).prop(props).prop({ return $<E>(selector).prop(props).prop({
@ -176,6 +177,9 @@ function createLightbox() {
const elType = $el.attr("type"); const elType = $el.attr("type");
const val: string|boolean = (elType === "checkbox")?$el.prop("checked"):$el.val(); const val: string|boolean = (elType === "checkbox")?$el.prop("checked"):$el.val();
setStorageVal($el.attr("id"), val); setStorageVal($el.attr("id"), val);
settings.get($el.attr("id"))?.onSave();
if(ev.target.id === "style") { if(ev.target.id === "style") {
setTheme(); setTheme();
} }
@ -255,12 +259,11 @@ $(() => {
min: 2 min: 2
}, initWatcher)); }, initWatcher));
settings.set("persistentqr", new BooleanSetting("persistentqr", "Persistent Quick Reply", false)); settings.set("persistentqr", new BooleanSetting("persistentqr", "Persistent Quick Reply", false));
settings.set("newuploader", new BooleanSetting("newuploader", "Use new upload element", true, updateBrowseButton));
settings.set("customjs", new TextSetting("customjs", "Custom JavaScript", "")); settings.set("customjs", new TextSetting("customjs", "Custom JavaScript", ""));
settings.set("customcss", new TextSetting("customcss", "Custom CSS", "", setCustomCSS)); settings.set("customcss", new TextSetting("customcss", "Custom CSS", "", setCustomCSS));
if($settingsButton === null) if($settingsButton === null)
$settingsButton = new TopBarButton("Settings", createLightbox, { $settingsButton = new TopBarButton("Settings", createLightbox, {before: "a#watcher"});
before: "a#watcher"
});
}); });