Select random theme for new articles client side
This commit is contained in:
parent
65ad262bd8
commit
7373af0417
2 changed files with 18 additions and 4 deletions
|
@ -259,6 +259,22 @@ function openEditor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initializeTheme() {
|
||||||
|
const form = document.getElementById('article-editor');
|
||||||
|
|
||||||
|
let preSelectedTheme = form.querySelector(`.theme-picker--option[checked]`);
|
||||||
|
if (preSelectedTheme) return;
|
||||||
|
|
||||||
|
let themes = form.querySelectorAll(`.theme-picker--option`);
|
||||||
|
let randomThemeId = (Math.random() * themes.length) | 0;
|
||||||
|
|
||||||
|
let theme = themes[randomThemeId];
|
||||||
|
theme.defaultChecked = theme.checked = true;
|
||||||
|
document.querySelector("body").className = `theme-${theme.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeTheme();
|
||||||
|
|
||||||
document
|
document
|
||||||
.getElementById("openEditor")
|
.getElementById("openEditor")
|
||||||
.addEventListener("click", function (ev) {
|
.addEventListener("click", function (ev) {
|
||||||
|
|
|
@ -87,15 +87,13 @@ impl Resource for NewArticleResource {
|
||||||
let title = self.slug.as_ref()
|
let title = self.slug.as_ref()
|
||||||
.map_or("".to_owned(), |x| title_from_slug(x));
|
.map_or("".to_owned(), |x| title_from_slug(x));
|
||||||
|
|
||||||
let theme = theme::theme_from_str_hash(&title);
|
|
||||||
|
|
||||||
Box::new(self.head()
|
Box::new(self.head()
|
||||||
.and_then(move |head| {
|
.and_then(move |head| {
|
||||||
Ok(head
|
Ok(head
|
||||||
.with_body(Layout {
|
.with_body(Layout {
|
||||||
base: None, // Hmm, should perhaps accept `base` as argument
|
base: None, // Hmm, should perhaps accept `base` as argument
|
||||||
title: &title,
|
title: &title,
|
||||||
theme,
|
theme: theme::Theme::Gray,
|
||||||
body: &Template {
|
body: &Template {
|
||||||
revision: NEW,
|
revision: NEW,
|
||||||
last_updated: None,
|
last_updated: None,
|
||||||
|
@ -106,7 +104,7 @@ impl Resource for NewArticleResource {
|
||||||
rendered: EMPTY_ARTICLE_MESSAGE,
|
rendered: EMPTY_ARTICLE_MESSAGE,
|
||||||
themes: &theme::THEMES.iter().map(|&x| SelectableTheme {
|
themes: &theme::THEMES.iter().map(|&x| SelectableTheme {
|
||||||
theme: x,
|
theme: x,
|
||||||
selected: x == theme,
|
selected: false,
|
||||||
}).collect::<Vec<_>>(),
|
}).collect::<Vec<_>>(),
|
||||||
},
|
},
|
||||||
}.to_string()))
|
}.to_string()))
|
||||||
|
|
Loading…
Reference in a new issue