Skip to content

Commit

Permalink
fix: #60
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jun 2, 2022
1 parent 522e149 commit e38d945
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
26 changes: 9 additions & 17 deletions lib/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ var meta = require.main.require('./src/meta');
var user = require.main.require('./src/user');
var db = require.main.require('./src/database');

var themeSlickSkin = '';

var theme = module.exports;

theme.init = function(params, callback) {
Expand All @@ -26,16 +24,15 @@ theme.addAdminNavigation = function(header, callback) {
callback(null, header);
};

theme.getThemeConfig = function(config, callback) {
meta.settings.get('slick', function(err, settings) {
if (err) {
return callback(err);
}
config.hideSubCategories = settings.hideSubCategories === 'on';
config.selectedSkin = themeSlickSkin || settings.skinOption || 'default';
config.bootswatchSkin = '';
callback(null, config);
});
theme.getThemeConfig = async function(config) {
const [settings, userSettings] = await Promise.all([
meta.settings.get('slick'),
user.getSettings(config.uid),
]);
config.hideSubCategories = settings.hideSubCategories === 'on';
config.themeSlickSkin = userSettings.themeSlickSkin || settings.skinOption || 'default';
config.bootswatchSkin = '';
return config;
};

theme.addUserToTopic = async function (hookData) {
Expand Down Expand Up @@ -86,11 +83,6 @@ theme.saveSettings = function(data, callback) {
db.setObjectField('user:' + data.uid + ':settings', 'themeSlickSkin', data.settings.themeSlickSkin, callback);
};

theme.getSettings = function(data, callback) {
themeSlickSkin = data.settings.themeSlickSkin;
callback(null, data);
};

theme.getLinkTags = function(data, callback) {
data.links.push({
rel: 'prefetch stylesheet',
Expand Down
3 changes: 0 additions & 3 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
{
"hook": "action:user.saveSettings", "method": "saveSettings"
},
{
"hook": "filter:user.getSettings", "method": "getSettings"
},
{
"hook": "filter:meta.getLinkTags", "method": "getLinkTags"
}
Expand Down
10 changes: 10 additions & 0 deletions public/slick.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ $(document).ready(function () {
});
}
});

$(window).on('action:ajaxify.start', function () {
if (ajaxify.data.template.name === 'account/settings' && $('[data-property="themeSlickSkin"]').val() !== config.themeSlickSkin) {
var newSkin = config.themeSlickSkin;
var classes = $('body').attr('class').split(/\s+/);
classes = classes.filter(c => !c.startsWith('skin-'));
classes.push('skin-' + newSkin);
$('body').attr('class', classes.join(' '));
}
});
}

function setupEditedByIcon() {
Expand Down
2 changes: 1 addition & 1 deletion templates/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!-- END -->
</head>

<body class="{bodyClass} skin-{{{if bootswatchSkin}}}{bootswatchSkin}{{{else}}}{config.selectedSkin}{{{end}}}">
<body class="{bodyClass} skin-{{{if bootswatchSkin}}}{bootswatchSkin}{{{else}}}{config.themeSlickSkin}{{{end}}}">
<nav id="menu" class="hidden">
<section class="menu-profile">
<!-- IF user.uid -->
Expand Down

0 comments on commit e38d945

Please sign in to comment.