Node.js based forum software built for the modern web
refactored admin/themes.js
psychobunnyb468404506bd
diff --git a/public/src/forum/admin/appearance/customise.js b/public/src/forum/admin/appearance/customise.jsnew file mode 100644index 0000000000..536816b0f4--- /dev/null+++ b/public/src/forum/admin/appearance/customise.js@@ -0,0 +1,16 @@+"use strict";+/* global define, app, socket */++define('forum/admin/appearance/customise', ['forum/admin/settings'], function(Settings) {+ var Customise = {};++ Customise.init = function() {+ var customCSSEl = $('textarea[data-field]')[0];+ tabIndent.config.tab = ' ';+ tabIndent.render(customCSSEl);++ Settings.prepare();+ };++ return Customise;+});diff --git a/public/src/forum/admin/appearance/skins.js b/public/src/forum/admin/appearance/skins.jsnew file mode 100644index 0000000000..4353acb2a8--- /dev/null+++ b/public/src/forum/admin/appearance/skins.js@@ -0,0 +1,73 @@+"use strict";+/* global define, app, socket */++define('forum/admin/appearance/skins', function() {+ var Skins = {};++ Skins.init = function() {+ var scriptEl = $('<script />');+ scriptEl.attr('src', '//bootswatch.aws.af.cm/3/?callback=bootswatchListener');+ $('body').append(scriptEl);++ $('#bootstrap_themes').on('click', function(e){+ var target = $(e.target),+ action = target.attr('data-action');++ if (action && action === '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: 'info',+ title: 'Theme Changed',+ message: 'Please restart your NodeBB to fully activate this theme',+ timeout: 5000,+ clickfn: function() {+ socket.emit('admin.restart');+ }+ });+ });+ }+ });+ };++ Skins.render = function(bootswatch) {+ var themeContainer = $('#bootstrap_themes');++ templates.parse('partials/admin/theme_list', {+ themes: bootswatch.themes.map(function(theme) {+ return {+ type: 'bootswatch',+ id: theme.name,+ name: theme.name,+ description: theme.description,+ screenshot_url: theme.thumbnail,+ url: theme.preview,+ css: theme.cssCdn+ };+ })+ }, function(html) {+ themeContainer.html(html);+ });+ };++ function highlightSelectedTheme(themeId) {+ $('.themes li[data-theme]').removeClass('btn-warning');+ $('.themes li[data-theme="' + themeId + '"]').addClass('btn-warning');+ }++ return Skins;+});diff --git a/public/src/forum/admin/appearance/themes.js b/public/src/forum/admin/appearance/themes.jsnew file mode 100644index 0000000000..68f4c2ff65--- /dev/null+++ b/public/src/forum/admin/appearance/themes.js@@ -0,0 +1,93 @@+"use strict";+/* global define, app, socket */++define('forum/admin/appearance/themes', function() {+ var Themes = {};++ Themes.init = function() {+ $('#installed_themes').on('click', function(e){+ var target = $(e.target),+ action = target.attr('data-action');++ if (action && action === '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: 'info',+ title: 'Theme Changed',+ message: 'Please restart your NodeBB to fully activate this theme',+ timeout: 5000,+ clickfn: function() {+ socket.emit('admin.restart');+ }+ });+ });+ }+ });++ $('#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-vanilla'+ }, function(err) {+ if (err) {+ return app.alertError(err.message);+ }+ highlightSelectedTheme('nodebb-theme-vanilla');+ app.alert({+ alert_id: 'admin:theme',+ type: 'success',+ title: 'Theme Changed',+ message: 'You have successfully reverted your NodeBB back to it\'s default theme.',+ timeout: 3500+ });+ });+ }+ });+ });++ // Installed Themes+ socket.emit('admin.themes.getInstalled', function(err, themes) {+ if(err) {+ return app.alertError(err.message);+ }++ var instListEl = $('#installed_themes');++ if (!themes.length) {+ instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found'));+ return;+ } else {+ templates.parse('partials/admin/theme_list', {+ themes: themes+ }, function(html) {+ instListEl.html(html);+ highlightSelectedTheme(config['theme:id']);+ });+ }+ });+ };++ function highlightSelectedTheme(themeId) {+ $('.themes li[data-theme]').removeClass('btn-warning');+ $('.themes li[data-theme="' + themeId + '"]').addClass('btn-warning');+ }++ return Themes;+});diff --git a/public/src/forum/admin/themes.js b/public/src/forum/admin/appearance/widgets.jssimilarity index 56%rename from public/src/forum/admin/themes.jsrename to public/src/forum/admin/appearance/widgets.jsindex 4fe5f88838..2bafe5cdc7 100644--- a/public/src/forum/admin/themes.js+++ b/public/src/forum/admin/appearance/widgets.js@@ -1,146 +1,14 @@"use strict";-/*global define, socket, app, bootbox, tabIndent, config, RELATIVE_PATH, templates */+/* global define, app, socket */-define('forum/admin/themes', ['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 = $('<script />');- scriptEl.attr('src', '//bootswatch.aws.af.cm/3/?callback=bootswatchListener');- $('body').append(scriptEl);-- $('#widgets .nav-pills a').on('click', function(ev) {- var $this = $(this);- $('#widgets .nav-pills li').removeClass('active');- $this.parent().addClass('active');-- $('#widgets .tab-pane').removeClass('active');- $('#widgets .tab-pane[data-template="' + $this.attr('data-template') + '"]').addClass('active');-- ev.preventDefault();- return false;- });-- var bootstrapThemeContainer = $('#bootstrap_themes'),- installedThemeContainer = $('#installed_themes');-- function themeEvent(e) {- var target = $(e.target),- action = target.attr('data-action');-- if (action && action === '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: 'info',- title: 'Theme Changed',- message: 'Please restart your NodeBB to fully activate this theme',- timeout: 5000,- clickfn: function() {- socket.emit('admin.restart');- }- });- });- }- }-- 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-vanilla'- }, function(err) {- if (err) {- return app.alertError(err.message);- }- highlightSelectedTheme('nodebb-theme-vanilla');- app.alert({- alert_id: 'admin:theme',- type: 'success',- title: 'Theme Changed',- message: 'You have successfully reverted your NodeBB back to it\'s default theme.',- timeout: 3500- });- });- }- });- });-- // Installed Themes- socket.emit('admin.themes.getInstalled', function(err, themes) {- if(err) {- return app.alertError(err.message);- }-- var instListEl = $('#installed_themes');-- if (!themes.length) {- instListEl.append($('<li/ >').addClass('no-themes').html('No installed themes found'));- return;- } else {- templates.parse('partials/admin/theme_list', {- themes: themes- }, function(html) {- instListEl.html(html);- highlightSelectedTheme(config['theme:id']);- });- }- });-- // Proper tabbing for "Custom CSS" field- var customCSSEl = $('textarea[data-field]')[0];- tabIndent.config.tab = ' ';- tabIndent.render(customCSSEl);-- Themes.prepareWidgets();-- Settings.prepare();+define('forum/admin/appearance/widgets', function() {+ var Widgets = {};++ Widgets.init = function() {+ prepareWidgets();};- Themes.render = function(bootswatch) {- var themeContainer = $('#bootstrap_themes');-- templates.parse('partials/admin/theme_list', {- themes: bootswatch.themes.map(function(theme) {- return {- type: 'bootswatch',- id: theme.name,- name: theme.name,- description: theme.description,- screenshot_url: theme.thumbnail,- url: theme.preview,- css: theme.cssCdn- };- })- }, function(html) {- themeContainer.html(html);- });- };-- Themes.prepareWidgets = function() {+ function prepareWidgets() {$('[data-location="drafts"]').insertAfter($('[data-location="drafts"]').closest('.tab-content'));$('#widgets .available-widgets .panel').draggable({@@ -312,7 +180,7 @@ define('forum/admin/themes', ['forum/admin/settings'], function(Settings) {.replace(/class="[a-zA-Z0-9-\s]+"/, 'class="' + container[0].className.replace(' pointer ui-draggable', '') + '"'));});- };+ }- return Themes;+ return Widgets;});diff --git a/src/views/admin/appearance/footer.tpl b/src/views/admin/appearance/footer.tplindex 13eab70ff4..f199f3de74 100644--- a/src/views/admin/appearance/footer.tpl+++ b/src/views/admin/appearance/footer.tpl@@ -3,12 +3,8 @@<script>var bootswatchListener = function(data) {- require(['forum/admin/themes'], function(t) {+ require(['forum/admin/appearance/skins'], function(t) {t.render(data);});};-- require(['forum/admin/themes'], function(t) {- t.init();- });</script>\ No newline at end of file