mirror of
https://github.com/discourse/discourse.git
synced 2025-02-28 19:26:25 +08:00
FIX: theme preview from preferences wasn't working
This commit is contained in:
parent
b193ae2d15
commit
bb82e0a041
@ -1,45 +1,5 @@
|
|||||||
import DiscourseURL from 'discourse/lib/url';
|
import DiscourseURL from 'discourse/lib/url';
|
||||||
import { currentThemeKey } from 'discourse/lib/theme-selector';
|
import { currentThemeKey, refreshCSS } from 'discourse/lib/theme-selector';
|
||||||
|
|
||||||
export function refreshCSS(node, hash, newHref, options) {
|
|
||||||
|
|
||||||
let $orig = $(node);
|
|
||||||
|
|
||||||
if ($orig.data('reloading')) {
|
|
||||||
|
|
||||||
if (options && options.force) {
|
|
||||||
clearTimeout($orig.data('timeout'));
|
|
||||||
$orig.data("copy").remove();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$orig.data('orig')) {
|
|
||||||
$orig.data('orig', node.href);
|
|
||||||
}
|
|
||||||
|
|
||||||
$orig.data('reloading', true);
|
|
||||||
|
|
||||||
const orig = $(node).data('orig');
|
|
||||||
|
|
||||||
let reloaded = $orig.clone(true);
|
|
||||||
if (hash) {
|
|
||||||
reloaded[0].href = orig + (orig.indexOf('?') >= 0 ? "&hash=" : "?hash=") + hash;
|
|
||||||
} else {
|
|
||||||
reloaded[0].href = newHref;
|
|
||||||
}
|
|
||||||
|
|
||||||
$orig.after(reloaded);
|
|
||||||
|
|
||||||
let timeout = setTimeout(()=>{
|
|
||||||
$orig.remove();
|
|
||||||
reloaded.data('reloading', false);
|
|
||||||
}, 2000);
|
|
||||||
|
|
||||||
$orig.data("timeout", timeout);
|
|
||||||
$orig.data("copy", reloaded);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the message bus for live reloading of components for faster development.
|
// Use the message bus for live reloading of components for faster development.
|
||||||
export default {
|
export default {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
import { refreshCSS } from 'discourse/initializers/live-development';
|
|
||||||
const keySelector = 'meta[name=discourse_theme_key]';
|
const keySelector = 'meta[name=discourse_theme_key]';
|
||||||
|
|
||||||
export function currentThemeKey() {
|
export function currentThemeKey() {
|
||||||
@ -22,6 +21,46 @@ export function selectDefaultTheme(key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function refreshCSS(node, hash, newHref, options) {
|
||||||
|
|
||||||
|
let $orig = $(node);
|
||||||
|
|
||||||
|
if ($orig.data('reloading')) {
|
||||||
|
|
||||||
|
if (options && options.force) {
|
||||||
|
clearTimeout($orig.data('timeout'));
|
||||||
|
$orig.data("copy").remove();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$orig.data('orig')) {
|
||||||
|
$orig.data('orig', node.href);
|
||||||
|
}
|
||||||
|
|
||||||
|
$orig.data('reloading', true);
|
||||||
|
|
||||||
|
const orig = $(node).data('orig');
|
||||||
|
|
||||||
|
let reloaded = $orig.clone(true);
|
||||||
|
if (hash) {
|
||||||
|
reloaded[0].href = orig + (orig.indexOf('?') >= 0 ? "&hash=" : "?hash=") + hash;
|
||||||
|
} else {
|
||||||
|
reloaded[0].href = newHref;
|
||||||
|
}
|
||||||
|
|
||||||
|
$orig.after(reloaded);
|
||||||
|
|
||||||
|
let timeout = setTimeout(()=>{
|
||||||
|
$orig.remove();
|
||||||
|
reloaded.data('reloading', false);
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
$orig.data("timeout", timeout);
|
||||||
|
$orig.data("copy", reloaded);
|
||||||
|
}
|
||||||
|
|
||||||
export function previewTheme(key) {
|
export function previewTheme(key) {
|
||||||
if (currentThemeKey() !== key) {
|
if (currentThemeKey() !== key) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user