From 28a1fa780adf509fabbb1cf86433611a7151fe7e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 4 Dec 2018 12:06:13 -0500 Subject: [PATCH] fix: skin not changing after login or logout, #7038 --- public/src/app.js | 18 ++++++++++++++++++ public/src/client/account/settings.js | 22 +++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index d87e3923cf..61077c4f82 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -139,6 +139,7 @@ app.cacheBuster = null; Notifications.prepareDOM(); Chat.prepareDOM(); + app.reskin(data.config.bootswatchSkin); callback(); }); }); @@ -734,4 +735,21 @@ app.cacheBuster = null; }); }); }; + + app.reskin = function (skinName) { + var clientEl = Array.prototype.filter.call(document.querySelectorAll('link[rel="stylesheet"]'), function (el) { + return el.href.indexOf(config.relative_path + '/assets/client') !== -1; + })[0] || null; + + // Update client.css link element to point to selected skin variant + clientEl.href = config.relative_path + '/assets/client' + (skinName ? '-' + skinName : '') + '.css'; + + var currentSkinClassName = $('body').attr('class').split(/\s+/).filter(function (className) { + return className.startsWith('skin-'); + }); + $('body').removeClass(currentSkinClassName.join(' ')); + if (skinName) { + $('body').addClass('skin-' + skinName); + } + }; }()); diff --git a/public/src/client/account/settings.js b/public/src/client/account/settings.js index 9613083940..032edad61a 100644 --- a/public/src/client/account/settings.js +++ b/public/src/client/account/settings.js @@ -4,9 +4,10 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds'], function (header, components, sounds) { var AccountSettings = {}; + // If page skin is changed but not saved, switch the skin back $(window).on('action:ajaxify.start', function () { if (ajaxify.data.template.name === 'account/settings' && $('#bootswatchSkin').val() !== config.bootswatchSkin) { - changePageSkin(config.bootswatchSkin); + app.reskin(config.bootswatchSkin); } }); @@ -30,7 +31,7 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' }); $('#bootswatchSkin').on('change', function () { - changePageSkin($(this).val()); + app.reskin($(this).val()); }); $('[data-property="homePageRoute"]').on('change', toggleCustomRoute); @@ -48,23 +49,6 @@ define('forum/account/settings', ['forum/account/header', 'components', 'sounds' components.get('user/sessions').find('.timeago').timeago(); }; - function changePageSkin(skinName) { - var clientEl = Array.prototype.filter.call(document.querySelectorAll('link[rel="stylesheet"]'), function (el) { - return el.href.indexOf(config.relative_path + '/assets/client') !== -1; - })[0] || null; - - // Update client.css link element to point to selected skin variant - clientEl.href = config.relative_path + '/assets/client' + (skinName ? '-' + skinName : '') + '.css'; - - var currentSkinClassName = $('body').attr('class').split(/\s+/).filter(function (className) { - return className.startsWith('skin-'); - }); - $('body').removeClass(currentSkinClassName.join(' ')); - if (skinName) { - $('body').addClass('skin-' + skinName); - } - } - function loadSettings() { var settings = {};