From 50cbc498e7f178d3c16753dfc62bf11fe40aab2f Mon Sep 17 00:00:00 2001
From: Cinder
Date: Wed, 12 Feb 2025 07:01:41 -0800
Subject: [PATCH] [Themes] Add a toggle for WikiExcerpt in theme settings
(#914)
---
app/javascript/src/javascripts/post_search.js | 2 +-
app/javascript/src/javascripts/themes.js | 48 ++++++-------
.../src/javascripts/utility/storage.js | 2 +-
.../src/styles/views/posts/_posts.scss | 2 +-
app/views/layouts/_theme_include.html.erb | 2 +-
app/views/static/theme.html.erb | 67 ++++++++++---------
6 files changed, 65 insertions(+), 58 deletions(-)
diff --git a/app/javascript/src/javascripts/post_search.js b/app/javascript/src/javascripts/post_search.js
index 55421cfec..045d641d8 100644
--- a/app/javascript/src/javascripts/post_search.js
+++ b/app/javascript/src/javascripts/post_search.js
@@ -71,7 +71,7 @@ PostSearch.initialize_controls = function () {
let stickySearch = LStorage.Posts.StickySearch;
$("#search-sticky").on("click", () => {
stickySearch = !stickySearch;
- $("body").attr("data-st-stickysearch", stickySearch);
+ $("body").attr("data-st-ssearch", stickySearch);
LStorage.Posts.StickySearch = stickySearch;
});
};
diff --git a/app/javascript/src/javascripts/themes.js b/app/javascript/src/javascripts/themes.js
index a329e109e..ccff3abeb 100644
--- a/app/javascript/src/javascripts/themes.js
+++ b/app/javascript/src/javascripts/themes.js
@@ -3,17 +3,23 @@ import LStorage from "./utility/storage";
const Theme = {};
-Theme.Values = ["Main", "Extra", "StickyHeader", "ForumNotif", "Palette", "Navbar", "Gestures"];
+Theme.Values = {
+ "Theme": ["Main", "Extra", "Palette", "StickyHeader", "Navbar", "Gestures", "ForumNotif"],
+ "Posts": ["WikiExcerpt", "StickySearch"],
+};
-for (const one of Theme.Values) {
- Object.defineProperty(Theme, one, {
- get () { return LStorage.Theme[one]; },
- set (value) {
- // No value checking, we die like men
- LStorage.Theme[one] = value;
- $("body").attr("data-th-" + one.toLowerCase(), value);
- },
- });
+for (const [label, settings] of Object.entries(Theme.Values)) {
+ for (const one of settings) {
+ Object.defineProperty(Theme, one, {
+ get () { return LStorage.Theme[one]; },
+ set (value) {
+ // This has the unintended side effect of setting
+ // attribute values that don't exist on the body.
+ LStorage[label][one] = value;
+ $("body").attr("data-th-" + one.toLowerCase(), value);
+ },
+ });
+ }
}
Theme.initialize_selector = function () {
@@ -24,13 +30,15 @@ Theme.initialize_selector = function () {
return false;
}
- for (const one of Theme.Values) {
- $("#theme_" + one.toLowerCase())
- .val(LStorage.Theme[one] + "")
- .on("change", (event) => {
- const data = event.target.value;
- Theme[one] = data;
- });
+ for (const [label, settings] of Object.entries(Theme.Values)) {
+ for (const one of settings)
+ $(`#${label}_${one}`)
+ .val(LStorage[label][one] + "")
+ .on("change", (event) => {
+ const data = event.target.value;
+ console.log("change", one, data);
+ Theme[one] = data;
+ });
}
};
@@ -42,12 +50,6 @@ Theme.initialize_buttons = function () {
LStorage.Site.Mascot = 0;
$("#mascot-value").text(LStorage.Site.Mascot);
});
-
- $("#wiki-excerpt-value").text(LStorage.Posts.WikiExcerpt);
- $("#wiki-excerpt-reset").on("click", () => {
- LStorage.Posts.WikiExcerpt = 1;
- $("#wiki-excerpt-value").text(LStorage.Posts.WikiExcerpt);
- });
};
$(() => {
diff --git a/app/javascript/src/javascripts/utility/storage.js b/app/javascript/src/javascripts/utility/storage.js
index 55c65e4ab..d02ef5170 100644
--- a/app/javascript/src/javascripts/utility/storage.js
+++ b/app/javascript/src/javascripts/utility/storage.js
@@ -93,7 +93,7 @@ LStorage.Posts = {
Fullscreen: ["e6.posts.fusk", false],
/** @returns {boolean} True if the search should be displayed in fullscreen */
- StickySearch: ["e6.posts.stickysearch", false],
+ StickySearch: ["e6.posts.ssearch", false],
};
StorageUtils.bootstrapMany(LStorage.Posts);
diff --git a/app/javascript/src/styles/views/posts/_posts.scss b/app/javascript/src/styles/views/posts/_posts.scss
index 56c38dadb..f6dcef481 100644
--- a/app/javascript/src/styles/views/posts/_posts.scss
+++ b/app/javascript/src/styles/views/posts/_posts.scss
@@ -13,7 +13,7 @@
@include with-setting("fullscreen", "true") {
@import "index/partials/fullscreen";
}
- @include with-setting("stickysearch", "true") {
+ @include with-setting("ssearch", "true") {
@import "index/partials/sticky";
}
}
diff --git a/app/views/layouts/_theme_include.html.erb b/app/views/layouts/_theme_include.html.erb
index d6bcd97fa..4add60a81 100644
--- a/app/views/layouts/_theme_include.html.erb
+++ b/app/views/layouts/_theme_include.html.erb
@@ -12,7 +12,7 @@
// Settings
"st-fullscreen": localStorage.getItem("e6.posts.fusk") || false,
- "st-stickysearch": localStorage.getItem("e6.posts.stickysearch") || false,
+ "st-ssearch": localStorage.getItem("e6.posts.ssearch") || false,
};
var b = document.body;
diff --git a/app/views/static/theme.html.erb b/app/views/static/theme.html.erb
index 8344f356d..fd9087cf9 100644
--- a/app/views/static/theme.html.erb
+++ b/app/views/static/theme.html.erb
@@ -16,8 +16,8 @@
This means that they will not persist across multiple devices, or in incognito mode.
-
-