FEATURE: maintain preview theme, while previewing
This means you can browse around in preview mode without losing the theme. At any point you can refresh page and maintain the preview theme.
This commit is contained in:
parent
2097f5330c
commit
ba15273d3f
|
@ -7,6 +7,28 @@ export default {
|
|||
initialize(container) {
|
||||
const messageBus = container.lookup('message-bus:main');
|
||||
|
||||
if (window.history && window.location.search.indexOf("?preview_theme_key=") === 0) {
|
||||
// force preview theme key to always be carried along
|
||||
const themeKey = window.location.search.slice(19).split('&')[0];
|
||||
if (themeKey.match(/^[a-z0-9-]+$/i)) {
|
||||
const patchState = function(f) {
|
||||
const patched = window.history[f];
|
||||
|
||||
window.history[f] = function(stateObj, name, url) {
|
||||
if (url.indexOf("preview_theme_key=") === -1) {
|
||||
const joiner = url.indexOf("?") === -1 ? "?" : "&";
|
||||
url = `${url}${joiner}preview_theme_key=${themeKey}`;
|
||||
}
|
||||
|
||||
return patched.call(window.history, stateObj, name, url);
|
||||
};
|
||||
};
|
||||
patchState("replaceState");
|
||||
patchState("pushState");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Custom header changes
|
||||
$('header.custom').each(function() {
|
||||
const header = $(this);
|
||||
|
|
|
@ -7,8 +7,7 @@ class Admin::ThemesController < Admin::AdminController
|
|||
|
||||
def preview
|
||||
@theme = Theme.find(params[:id])
|
||||
|
||||
redirect_to path("/"), flash: { preview_theme_key: @theme.key }
|
||||
redirect_to path("/?preview_theme_key=#{@theme.key}")
|
||||
end
|
||||
|
||||
def upload_asset
|
||||
|
|
|
@ -315,7 +315,7 @@ class ApplicationController < ActionController::Base
|
|||
resolve_safe_mode
|
||||
return if request.env[NO_CUSTOM]
|
||||
|
||||
theme_key = flash[:preview_theme_key]
|
||||
theme_key = request[:preview_theme_key]
|
||||
|
||||
user_option = current_user&.user_option
|
||||
|
||||
|
|
Loading…
Reference in New Issue