mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 23:15:48 +01:00
IE8 support, general cleanups, from native to $ objects ...
This commit is contained in:
@@ -2,17 +2,21 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
var Themes = {};
|
||||
|
||||
Themes.init = function() {
|
||||
var scriptEl = document.createElement('script');
|
||||
scriptEl.src = 'http://api.bootswatch.com/3/?callback=bootswatchListener';
|
||||
document.body.appendChild(scriptEl);
|
||||
var scriptEl = $('<script />');
|
||||
scriptEl.attr('src', 'http://api.bootswatch.com/3/?callback=bootswatchListener');
|
||||
$('body').append(scriptEl);
|
||||
|
||||
var bootstrapThemeContainer = $('#bootstrap_themes'),
|
||||
installedThemeContainer = $('#installed_themes'),
|
||||
|
||||
var bootstrapThemeContainer = document.querySelector('#bootstrap_themes'),
|
||||
installedThemeContainer = document.querySelector('#installed_themes'),
|
||||
themeEvent = function(e) {
|
||||
if (e.target.hasAttribute('data-action')) {
|
||||
switch (e.target.getAttribute('data-action')) {
|
||||
var target = $(e.target),
|
||||
action = target.attr('data-action');
|
||||
|
||||
if (action) {
|
||||
switch (action) {
|
||||
case 'use':
|
||||
var parentEl = $(e.target).parents('li'),
|
||||
var parentEl = target.parents('li'),
|
||||
themeType = parentEl.attr('data-type'),
|
||||
cssSrc = parentEl.attr('data-css'),
|
||||
themeId = parentEl.attr('data-theme');
|
||||
@@ -30,16 +34,15 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
timeout: 3500
|
||||
});
|
||||
});
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bootstrapThemeContainer.addEventListener('click', themeEvent);
|
||||
installedThemeContainer.addEventListener('click', themeEvent);
|
||||
bootstrapThemeContainer.on('click', themeEvent);
|
||||
installedThemeContainer.on('click', themeEvent);
|
||||
|
||||
var revertEl = document.getElementById('revert_theme');
|
||||
revertEl.addEventListener('click', function() {
|
||||
$('#revert_theme').on('click', function() {
|
||||
bootbox.confirm('Are you sure you wish to remove the custom theme and restore the NodeBB default theme?', function(confirm) {
|
||||
if (confirm) {
|
||||
socket.emit('admin.themes.set', {
|
||||
@@ -64,37 +67,32 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
var instListEl = document.getElementById('installed_themes'),
|
||||
themeFrag = document.createDocumentFragment(),
|
||||
liEl = document.createElement('li');
|
||||
liEl.setAttribute('data-type', 'local');
|
||||
var instListEl = $('#installed_themes').empty(), liEl;
|
||||
|
||||
if (themes.length > 0) {
|
||||
for (var x = 0, numThemes = themes.length; x < numThemes; x++) {
|
||||
liEl.setAttribute('data-theme', themes[x].id);
|
||||
liEl.innerHTML = '<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">';
|
||||
themeFrag.appendChild(liEl.cloneNode(true));
|
||||
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
|
||||
liEl.className = 'no-themes';
|
||||
liEl.innerHTML = 'No installed themes found';
|
||||
themeFrag.appendChild(liEl);
|
||||
instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found'));
|
||||
}
|
||||
|
||||
instListEl.innerHTML = '';
|
||||
instListEl.appendChild(themeFrag);
|
||||
});
|
||||
|
||||
// Proper tabbing for "Custom CSS" field
|
||||
@@ -105,34 +103,30 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
Themes.prepareWidgets();
|
||||
|
||||
Settings.prepare();
|
||||
}
|
||||
};
|
||||
|
||||
Themes.render = function(bootswatch) {
|
||||
var themeFrag = document.createDocumentFragment(),
|
||||
themeEl = document.createElement('li'),
|
||||
themeContainer = document.querySelector('#bootstrap_themes'),
|
||||
numThemes = bootswatch.themes.length;
|
||||
|
||||
themeEl.setAttribute('data-type', 'bootswatch');
|
||||
var themeContainer = $('#bootstrap_themes').empty(),
|
||||
numThemes = bootswatch.themes.length, themeEl, theme;
|
||||
|
||||
for (var x = 0; x < numThemes; x++) {
|
||||
var theme = bootswatch.themes[x];
|
||||
themeEl.setAttribute('data-css', theme.cssCdn);
|
||||
themeEl.setAttribute('data-theme', theme.name);
|
||||
themeEl.innerHTML = '<img src="' + theme.thumbnail + '" />' +
|
||||
'<div>' +
|
||||
'<div class="pull-right">' +
|
||||
'<button class="btn btn-primary" data-action="use">Use</button> ' +
|
||||
'</div>' +
|
||||
'<h4>' + theme.name + '</h4>' +
|
||||
'<p>' + theme.description + '</p>' +
|
||||
'</div>' +
|
||||
'<div class="clear">';
|
||||
themeFrag.appendChild(themeEl.cloneNode(true));
|
||||
theme = bootswatch.themes[x];
|
||||
themeEl = $('<li />').attr({
|
||||
'data-type': 'bootswatch',
|
||||
'data-css': theme.cssCdn,
|
||||
'data-theme': theme.name
|
||||
}).html('<img src="' + theme.thumbnail + '" />' +
|
||||
'<div>' +
|
||||
'<div class="pull-right">' +
|
||||
'<button class="btn btn-primary" data-action="use">Use</button> ' +
|
||||
'</div>' +
|
||||
'<h4>' + theme.name + '</h4>' +
|
||||
'<p>' + theme.description + '</p>' +
|
||||
'</div>' +
|
||||
'<div class="clear">');
|
||||
themeContainer.append(themeEl);
|
||||
}
|
||||
themeContainer.innerHTML = '';
|
||||
themeContainer.appendChild(themeFrag);
|
||||
}
|
||||
};
|
||||
|
||||
Themes.prepareWidgets = function() {
|
||||
$('#widgets .available-widgets .panel').draggable({
|
||||
@@ -167,8 +161,8 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
hoverClass: "panel-info"
|
||||
})
|
||||
.children('.panel-heading')
|
||||
.append('<div class="pull-right pointer"><span class="delete-widget"><i class="fa fa-times-circle"></i></span></div><div class="pull-left pointer"><span class="toggle-widget"><i class="fa fa-chevron-circle-down"></i></span> </div>')
|
||||
.children('small').html('');
|
||||
.append('<div class="pull-right pointer"><span class="delete-widget"><i class="fa fa-times-circle"></i></span></div><div class="pull-left pointer"><span class="toggle-widget"><i class="fa fa-chevron-circle-down"></i></span> </div>')
|
||||
.children('small').html('');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,18 +172,18 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
},
|
||||
connectWith: "div"
|
||||
}).on('click', '.toggle-widget', function() {
|
||||
$(this).parents('.panel').children('.panel-body').toggleClass('hidden');
|
||||
}).on('click', '.delete-widget', function() {
|
||||
var panel = $(this).parents('.panel');
|
||||
$(this).parents('.panel').children('.panel-body').toggleClass('hidden');
|
||||
}).on('click', '.delete-widget', function() {
|
||||
var panel = $(this).parents('.panel');
|
||||
|
||||
bootbox.confirm('Are you sure you wish to delete this widget?', function(confirm) {
|
||||
if (confirm) {
|
||||
panel.remove();
|
||||
}
|
||||
bootbox.confirm('Are you sure you wish to delete this widget?', function(confirm) {
|
||||
if (confirm) {
|
||||
panel.remove();
|
||||
}
|
||||
});
|
||||
}).on('dblclick', '.panel-heading', function() {
|
||||
$(this).parents('.panel').children('.panel-body').toggleClass('hidden');
|
||||
});
|
||||
}).on('dblclick', '.panel-heading', function() {
|
||||
$(this).parents('.panel').children('.panel-body').toggleClass('hidden');
|
||||
});
|
||||
|
||||
$('#widgets .btn[data-template]').on('click', function() {
|
||||
var btn = $(this),
|
||||
@@ -205,13 +199,13 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
for (var d in data) {
|
||||
if (data.hasOwnProperty(d)) {
|
||||
if (data[d].name) {
|
||||
widgetData[data[d].name] = data[d].value;
|
||||
widgetData[data[d].name] = data[d].value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
widgets.push({
|
||||
widget: this.getAttribute('data-widget'),
|
||||
widget: $(this).attr('data-widget'),
|
||||
data: widgetData
|
||||
});
|
||||
});
|
||||
@@ -245,7 +239,7 @@ define(['forum/admin/settings'], function(Settings) {
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
||||
$.get(RELATIVE_PATH + '/api/admin/themes', function(data) {
|
||||
var areas = data.areas;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user