"use strict"; /*global define, socket, app, bootbox, tabIndent, config, RELATIVE_PATH*/ define(['forum/admin/settings'], function(Settings) { var Themes = {}; function highlightSelectedTheme(themeId) { $('#themes li[data-theme]').removeClass('btn-warning'); $('#themes li[data-theme="' + themeId + '"]').addClass('btn-warning'); } Themes.init = function() { var scriptEl = $(''); scriptEl.attr('src', 'http://api.bootswatch.com/3/?callback=bootswatchListener'); $('body').append(scriptEl); var bootstrapThemeContainer = $('#bootstrap_themes'), installedThemeContainer = $('#installed_themes'); function themeEvent(e) { var target = $(e.target), action = target.attr('data-action'); if (action) { switch (action) { case 'use': var parentEl = target.parents('li'), themeType = parentEl.attr('data-type'), cssSrc = parentEl.attr('data-css'), themeId = parentEl.attr('data-theme'); socket.emit('admin.themes.set', { type: themeType, id: themeId, src: cssSrc }, function(err) { if (err) { return app.alertError(err.message); } highlightSelectedTheme(themeId); app.alert({ alert_id: 'admin:theme', type: 'success', title: 'Theme Changed', message: 'Restarting your NodeBB ', timeout: 3500 }); }); break; } } } bootstrapThemeContainer.on('click', themeEvent); installedThemeContainer.on('click', themeEvent); $('#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', { type: 'local', id: 'nodebb-theme-cerulean' }, function(err) { if (err) { return app.alertError(err.message); } highlightSelectedTheme('nodebb-theme-cerulean'); app.alert({ alert_id: 'admin:theme', type: 'success', title: 'Theme Changed', message: 'You have successfully reverted your NodeBB back to it\'s default theme. Restarting your NodeBB ', timeout: 3500 }); }); } }); }); // Installed Themes socket.emit('admin.themes.getInstalled', function(err, themes) { if(err) { return app.alertError(err.message); } var instListEl = $('#installed_themes').empty(), liEl; if (!themes.length) { instListEl.append($('
' +
'' + themes[x].description + (themes[x].url ? ' (Homepage)' : '') + '
' + '' + theme.description + '
' + '