mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
Merge remote-tracking branch 'origin/master' into webserver.js-refactor
Conflicts: public/templates/admin/themes.tpl src/meta.js src/routes/api.js
This commit is contained in:
@@ -1,43 +1,53 @@
|
|||||||
define(['forum/admin/settings'], function(Settings) {
|
define(['forum/admin/settings'], function(Settings) {
|
||||||
var Themes = {};
|
var Themes = {};
|
||||||
|
|
||||||
|
function highlightSelectedTheme(themeId) {
|
||||||
|
$('#themes li[data-theme]').removeClass('btn-warning');
|
||||||
|
$('#themes li[data-theme="' + themeId + '"]').addClass('btn-warning');
|
||||||
|
}
|
||||||
|
|
||||||
Themes.init = function() {
|
Themes.init = function() {
|
||||||
var scriptEl = $('<script />');
|
var scriptEl = $('<script />');
|
||||||
scriptEl.attr('src', 'http://api.bootswatch.com/3/?callback=bootswatchListener');
|
scriptEl.attr('src', 'http://api.bootswatch.com/3/?callback=bootswatchListener');
|
||||||
$('body').append(scriptEl);
|
$('body').append(scriptEl);
|
||||||
|
|
||||||
var bootstrapThemeContainer = $('#bootstrap_themes'),
|
var bootstrapThemeContainer = $('#bootstrap_themes'),
|
||||||
installedThemeContainer = $('#installed_themes'),
|
installedThemeContainer = $('#installed_themes');
|
||||||
|
|
||||||
themeEvent = function(e) {
|
function themeEvent(e) {
|
||||||
var target = $(e.target),
|
var target = $(e.target),
|
||||||
action = target.attr('data-action');
|
action = target.attr('data-action');
|
||||||
|
|
||||||
if (action) {
|
if (action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'use':
|
case 'use':
|
||||||
var parentEl = target.parents('li'),
|
var parentEl = target.parents('li'),
|
||||||
themeType = parentEl.attr('data-type'),
|
themeType = parentEl.attr('data-type'),
|
||||||
cssSrc = parentEl.attr('data-css'),
|
cssSrc = parentEl.attr('data-css'),
|
||||||
themeId = parentEl.attr('data-theme');
|
themeId = parentEl.attr('data-theme');
|
||||||
|
|
||||||
socket.emit('admin.themes.set', {
|
socket.emit('admin.themes.set', {
|
||||||
type: themeType,
|
type: themeType,
|
||||||
id: themeId,
|
id: themeId,
|
||||||
src: cssSrc
|
src: cssSrc
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
app.alert({
|
if (err) {
|
||||||
alert_id: 'admin:theme',
|
return app.alertError(err.message);
|
||||||
type: 'success',
|
}
|
||||||
title: 'Theme Changed',
|
highlightSelectedTheme(themeId);
|
||||||
message: 'Restarting your NodeBB <i class="fa fa-refresh fa-spin"></i>',
|
|
||||||
timeout: 3500
|
app.alert({
|
||||||
});
|
alert_id: 'admin:theme',
|
||||||
|
type: 'success',
|
||||||
|
title: 'Theme Changed',
|
||||||
|
message: 'Restarting your NodeBB <i class="fa fa-refresh fa-spin"></i>',
|
||||||
|
timeout: 3500
|
||||||
});
|
});
|
||||||
break;
|
});
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bootstrapThemeContainer.on('click', themeEvent);
|
bootstrapThemeContainer.on('click', themeEvent);
|
||||||
installedThemeContainer.on('click', themeEvent);
|
installedThemeContainer.on('click', themeEvent);
|
||||||
@@ -49,6 +59,10 @@ define(['forum/admin/settings'], function(Settings) {
|
|||||||
type: 'local',
|
type: 'local',
|
||||||
id: 'nodebb-theme-cerulean'
|
id: 'nodebb-theme-cerulean'
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
highlightSelectedTheme('nodebb-theme-cerulean');
|
||||||
app.alert({
|
app.alert({
|
||||||
alert_id: 'admin:theme',
|
alert_id: 'admin:theme',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
@@ -59,7 +73,7 @@ define(['forum/admin/settings'], function(Settings) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, false);
|
});
|
||||||
|
|
||||||
// Installed Themes
|
// Installed Themes
|
||||||
socket.emit('admin.themes.getInstalled', function(err, themes) {
|
socket.emit('admin.themes.getInstalled', function(err, themes) {
|
||||||
@@ -69,30 +83,32 @@ define(['forum/admin/settings'], function(Settings) {
|
|||||||
|
|
||||||
var instListEl = $('#installed_themes').empty(), liEl;
|
var instListEl = $('#installed_themes').empty(), liEl;
|
||||||
|
|
||||||
if (themes.length > 0) {
|
if (!themes.length) {
|
||||||
for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
|
|
||||||
liEl = $('<li/ >').attr({
|
|
||||||
'data-type': 'local',
|
|
||||||
'data-theme': themes[x].id
|
|
||||||
}).html('<img src="' + (themes[x].screenshot ? '/css/previews/' + themes[x].id : RELATIVE_PATH + '/images/themes/default.png') + '" />' +
|
|
||||||
'<div>' +
|
|
||||||
'<div class="pull-right">' +
|
|
||||||
'<button class="btn btn-primary" data-action="use">Use</button> ' +
|
|
||||||
'</div>' +
|
|
||||||
'<h4>' + themes[x].name + '</h4>' +
|
|
||||||
'<p>' +
|
|
||||||
themes[x].description +
|
|
||||||
(themes[x].url ? ' (<a href="' + themes[x].url + '">Homepage</a>)' : '') +
|
|
||||||
'</p>' +
|
|
||||||
'</div>' +
|
|
||||||
'<div class="clear">');
|
|
||||||
|
|
||||||
instListEl.append(liEl);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No themes found
|
|
||||||
instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found'));
|
instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found'));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
|
||||||
|
liEl = $('<li/ >').attr({
|
||||||
|
'data-type': 'local',
|
||||||
|
'data-theme': themes[x].id
|
||||||
|
}).html('<img src="' + (themes[x].screenshot ? '/css/previews/' + themes[x].id : RELATIVE_PATH + '/images/themes/default.png') + '" />' +
|
||||||
|
'<div>' +
|
||||||
|
'<div class="pull-right">' +
|
||||||
|
'<button class="btn btn-primary" data-action="use">Use</button> ' +
|
||||||
|
'</div>' +
|
||||||
|
'<h4>' + themes[x].name + '</h4>' +
|
||||||
|
'<p>' +
|
||||||
|
themes[x].description +
|
||||||
|
(themes[x].url ? ' (<a href="' + themes[x].url + '">Homepage</a>)' : '') +
|
||||||
|
'</p>' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="clear">');
|
||||||
|
|
||||||
|
instListEl.append(liEl);
|
||||||
|
}
|
||||||
|
|
||||||
|
highlightSelectedTheme(config['theme:id']);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Proper tabbing for "Custom CSS" field
|
// Proper tabbing for "Custom CSS" field
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
|
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
|
||||||
if (window.location.hash) {
|
if (window.location.hash) {
|
||||||
Topic.scrollToPost(window.location.hash.substr(1), true);
|
Topic.scrollToPost(window.location.hash.substr(1), true);
|
||||||
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1))) {
|
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && Topic.postCount > 1) {
|
||||||
app.alert({
|
app.alert({
|
||||||
alert_id: 'bookmark',
|
alert_id: 'bookmark',
|
||||||
message: '[[topic:bookmark_instructions]]',
|
message: '[[topic:bookmark_instructions]]',
|
||||||
@@ -1042,8 +1042,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
$('.progress-bar').width((index / Topic.postCount * 100) + '%');
|
$('.progress-bar').width((index / Topic.postCount * 100) + '%');
|
||||||
|
|
||||||
var currentBookmark = localStorage.getItem('topic:' + templates.get('topic_id') + ':bookmark');
|
var currentBookmark = localStorage.getItem('topic:' + templates.get('topic_id') + ':bookmark');
|
||||||
if (!currentBookmark || parseInt(el.attr('data-pid'), 10) > parseInt(currentBookmark, 10)) {
|
if (!currentBookmark || parseInt(el.attr('data-pid'), 10) >= parseInt(currentBookmark, 10)) {
|
||||||
localStorage.setItem('topic:' + templates.get('topic_id') + ':bookmark', el.attr('data-pid'));
|
localStorage.setItem('topic:' + templates.get('topic_id') + ':bookmark', el.attr('data-pid'));
|
||||||
|
app.removeAlert('bookmark');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!scrollingToPost) {
|
if (!scrollingToPost) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ apiController.getConfig = function(req, res, next) {
|
|||||||
config.topicsPerPage = meta.config.topicsPerPage || 20;
|
config.topicsPerPage = meta.config.topicsPerPage || 20;
|
||||||
config.postsPerPage = meta.config.postsPerPage || 20;
|
config.postsPerPage = meta.config.postsPerPage || 20;
|
||||||
config.maximumFileSize = meta.config.maximumFileSize;
|
config.maximumFileSize = meta.config.maximumFileSize;
|
||||||
|
config['theme:id'] = meta.config['theme:id'];
|
||||||
config.defaultLang = meta.config.defaultLang || 'en_GB';
|
config.defaultLang = meta.config.defaultLang || 'en_GB';
|
||||||
config.environment = process.env.NODE_ENV;
|
config.environment = process.env.NODE_ENV;
|
||||||
|
|
||||||
|
|||||||
@@ -207,9 +207,7 @@
|
|||||||
multi.hgetall(keys[x]);
|
multi.hgetall(keys[x]);
|
||||||
}
|
}
|
||||||
|
|
||||||
multi.exec(function (err, replies) {
|
multi.exec(callback);
|
||||||
callback(err, replies);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.getObjectField = function(key, field, callback) {
|
module.getObjectField = function(key, field, callback) {
|
||||||
|
|||||||
16
src/meta.js
16
src/meta.js
@@ -128,12 +128,12 @@ var fs = require('fs'),
|
|||||||
},
|
},
|
||||||
set: function(data, callback) {
|
set: function(data, callback) {
|
||||||
var themeData = {
|
var themeData = {
|
||||||
'theme:type': data.type,
|
'theme:type': data.type,
|
||||||
'theme:id': data.id,
|
'theme:id': data.id,
|
||||||
'theme:staticDir': '',
|
'theme:staticDir': '',
|
||||||
'theme:templates': '',
|
'theme:templates': '',
|
||||||
'theme:src': ''
|
'theme:src': ''
|
||||||
};
|
};
|
||||||
|
|
||||||
switch(data.type) {
|
switch(data.type) {
|
||||||
case 'local':
|
case 'local':
|
||||||
@@ -155,9 +155,7 @@ var fs = require('fs'),
|
|||||||
|
|
||||||
db.setObject('config', themeData, next);
|
db.setObject('config', themeData, next);
|
||||||
}
|
}
|
||||||
], function(err) {
|
], callback);
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'bootswatch':
|
case 'bootswatch':
|
||||||
|
|||||||
Reference in New Issue
Block a user