FIX: theme preview from preferences wasn't working

This commit is contained in:
Neil Lalonde 2017-04-28 14:01:57 -04:00
parent b193ae2d15
commit bb82e0a041
2 changed files with 41 additions and 42 deletions

View File

@ -1,45 +1,5 @@
import DiscourseURL from 'discourse/lib/url';
import { currentThemeKey } 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);
}
import { currentThemeKey, refreshCSS } from 'discourse/lib/theme-selector';
// Use the message bus for live reloading of components for faster development.
export default {

View File

@ -1,5 +1,4 @@
import { ajax } from 'discourse/lib/ajax';
import { refreshCSS } from 'discourse/initializers/live-development';
const keySelector = 'meta[name=discourse_theme_key]';
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) {
if (currentThemeKey() !== key) {