Skip to content

Node.js based forum software built for the modern web

moved js code in footer.tpl for admin into footer.js

Baris Soner Usaklif8518b1a9a12
diff --git a/public/src/forum/admin/footer.js b/public/src/forum/admin/footer.js
new file mode 100644
index 0000000000..2ed60171c4
--- /dev/null
+++ b/public/src/forum/admin/footer.js
@@ -0,0 +1,122 @@
+
+
+
+var nodebb_admin = (function(nodebb_admin) {
+
+ nodebb_admin.config = undefined;
+
+ nodebb_admin.prepare = function() {
+ // Come back in 500ms if the config isn't ready yet
+ if (nodebb_admin.config === undefined) {
+ setTimeout(function() {
+ nodebb_admin.prepare();
+ }, 500);
+ return;
+ }
+
+ // Populate the fields on the page from the config
+ var fields = document.querySelectorAll('#content [data-field]'),
+ numFields = fields.length,
+ saveBtn = document.getElementById('save'),
+ x, key, inputType;
+ for(x=0;x<numFields;x++) {
+ key = fields[x].getAttribute('data-field');
+ inputType = fields[x].getAttribute('type');
+ if (fields[x].nodeName === 'INPUT') {
+ if (nodebb_admin.config[key]) {
+ switch(inputType) {
+ case 'text':
+ case 'textarea':
+ case 'number':
+ fields[x].value = nodebb_admin.config[key];
+ break;
+
+ case 'checkbox':
+ fields[x].checked = nodebb_admin.config[key] === '1' ? true : false;
+ break;
+ }
+ }
+ } else if (fields[x].nodeName === 'TEXTAREA') {
+ if (nodebb_admin.config[key]) fields[x].value = nodebb_admin.config[key];
+ }
+ }
+
+ saveBtn.addEventListener('click', function(e) {
+ var key, value;
+ e.preventDefault();
+
+ for(x=0;x<numFields;x++) {
+ key = fields[x].getAttribute('data-field');
+ if (fields[x].nodeName === 'INPUT') {
+ inputType = fields[x].getAttribute('type');
+ switch(inputType) {
+ case 'text':
+ case 'number':
+ value = fields[x].value;
+ break;
+
+ case 'checkbox':
+ value = fields[x].checked ? '1' : '0';
+ break;
+ }
+ } else if (fields[x].nodeName === 'TEXTAREA') {
+ value = fields[x].value;
+ }
+
+ socket.emit('api:config.set', { key: key, value: value });
+ }
+ });
+ }
+
+ nodebb_admin.remove = function(key) {
+ socket.emit('api:config.remove', key);
+ }
+
+
+ jQuery('document').ready(function() {
+ // On menu click, change "active" state
+ var menuEl = document.querySelector('.sidebar-nav'),
+ liEls = menuEl.querySelectorAll('li')
+ parentEl = null;
+
+ menuEl.addEventListener('click', function(e) {
+ parentEl = e.target.parentNode;
+ if (parentEl.nodeName === 'LI') {
+ for(var x=0,numLis=liEls.length;x<numLis;x++) {
+ if (liEls[x] !== parentEl) jQuery(liEls[x]).removeClass('active');
+ else jQuery(parentEl).addClass('active');
+ }
+ }
+ }, false);
+ });
+
+ socket.once('api:config.get', function(config) {
+ nodebb_admin.config = config;
+ });
+
+ socket.emit('api:config.get');
+
+ socket.on('api:config.set', function(data) {
+ if (data.status === 'ok') {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Changes Saved',
+ message: 'Your changes to the NodeBB configuration have been saved. You may have to restart NodeBB to see the changes.',
+ type: 'success'
+ });
+ } else {
+ app.alert({
+ alert_id: 'config_status',
+ timeout: 2500,
+ title: 'Changes Not Saved',
+ message: 'NodeBB encountered a problem saving your changes',
+ type: 'error'
+ });
+ }
+ });
+
+ return nodebb_admin;
+
+}(nodebb_admin || {}));
+
diff --git a/public/src/forum/admin/themes.js b/public/src/forum/admin/themes.js
index 76c50c2900..1378237916 100644
--- a/public/src/forum/admin/themes.js
+++ b/public/src/forum/admin/themes.js
@@ -1,6 +1,11 @@
-nodebb_admin.themes = {
- render: function(bootswatch) {
- var themeFrag = document.createDocumentFragment(),
+
+
+var nodebb_admin = (function(nodebb_admin) {
+
+ var themes = {};
+
+ themes.render = function(bootswatch) {
+ var themeFrag = document.createDocumentFragment(),
themeEl = document.createElement('li'),
themeContainer = document.querySelector('#content .themes'),
numThemes = bootswatch.themes.length;
@@ -24,10 +29,16 @@ nodebb_admin.themes = {
themeContainer.innerHTML = '';
themeContainer.appendChild(themeFrag);
}
-};
+
+ nodebb_admin.themes = themes;
+
+ return nodebb_admin;
+
+}(nodebb_admin || {}));
+
(function() {
- var scriptEl = document.createElement('script');
+ var scriptEl = document.createElement('script');
scriptEl.src = 'http://api.bootswatch.com?callback=nodebb_admin.themes.render';
document.body.appendChild(scriptEl);
diff --git a/public/templates/admin/footer.tpl b/public/templates/admin/footer.tpl
index 3b10c74e8e..5721d11993 100644
--- a/public/templates/admin/footer.tpl
+++ b/public/templates/admin/footer.tpl
@@ -6,118 +6,7 @@
</div>
<script type="text/javascript">
- var nodebb_admin = {
- config: undefined,
- prepare: function() {
- // Come back in 500ms if the config isn't ready yet
- if (nodebb_admin.config === undefined) {
- setTimeout(function() {
- nodebb_admin.prepare();
- }, 500);
- return;
- }
-
- // Populate the fields on the page from the config
- var fields = document.querySelectorAll('#content [data-field]'),
- numFields = fields.length,
- saveBtn = document.getElementById('save'),
- x, key, inputType;
- for(x=0;x<numFields;x++) {
- key = fields[x].getAttribute('data-field');
- inputType = fields[x].getAttribute('type');
- if (fields[x].nodeName === 'INPUT') {
- if (nodebb_admin.config[key]) {
- switch(inputType) {
- case 'text':
- case 'textarea':
- case 'number':
- fields[x].value = nodebb_admin.config[key];
- break;
-
- case 'checkbox':
- fields[x].checked = nodebb_admin.config[key] === '1' ? true : false;
- break;
- }
- }
- } else if (fields[x].nodeName === 'TEXTAREA') {
- if (nodebb_admin.config[key]) fields[x].value = nodebb_admin.config[key];
- }
- }
-
- saveBtn.addEventListener('click', function(e) {
- var key, value;
- e.preventDefault();
-
- for(x=0;x<numFields;x++) {
- key = fields[x].getAttribute('data-field');
- if (fields[x].nodeName === 'INPUT') {
- inputType = fields[x].getAttribute('type');
- switch(inputType) {
- case 'text':
- case 'number':
- value = fields[x].value;
- break;
-
- case 'checkbox':
- value = fields[x].checked ? '1' : '0';
- break;
- }
- } else if (fields[x].nodeName === 'TEXTAREA') {
- value = fields[x].value;
- }
-
- socket.emit('api:config.set', { key: key, value: value });
- }
- });
- },
- remove: function(key) {
- socket.emit('api:config.remove', key);
- }
- };
-
- (function() {
- jQuery('document').ready(function() {
- // On menu click, change "active" state
- var menuEl = document.querySelector('.sidebar-nav'),
- liEls = menuEl.querySelectorAll('li')
- parentEl = null;
-
- menuEl.addEventListener('click', function(e) {
- parentEl = e.target.parentNode;
- if (parentEl.nodeName === 'LI') {
- for(var x=0,numLis=liEls.length;x<numLis;x++) {
- if (liEls[x] !== parentEl) jQuery(liEls[x]).removeClass('active');
- else jQuery(parentEl).addClass('active');
- }
- }
- }, false);
- });
-
- socket.once('api:config.get', function(config) {
- nodebb_admin.config = config;
- });
- socket.emit('api:config.get');
-
- socket.on('api:config.set', function(data) {
- if (data.status === 'ok') {
- app.alert({
- alert_id: 'config_status',
- timeout: 2500,
- title: 'Changes Saved',
- message: 'Your changes to the NodeBB configuration have been saved. You may have to restart NodeBB to see the changes.',
- type: 'success'
- });
- } else {
- app.alert({
- alert_id: 'config_status',
- timeout: 2500,
- title: 'Changes Not Saved',
- message: 'NodeBB encountered a problem saving your changes',
- type: 'error'
- });
- }
- });
- }())
+ $.getScript(RELATIVE_PATH + '/src/forum/admin/footer.js');
</script>
</body>