mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
closed #2583
This commit is contained in:
@@ -566,8 +566,11 @@ app.uid = null;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
require(['taskbar'], function(taskbar) {
|
require(['taskbar', 'helpers'], function(taskbar, helpers) {
|
||||||
taskbar.init();
|
taskbar.init();
|
||||||
|
|
||||||
|
// templates.js helpers
|
||||||
|
helpers.register();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
/*global templates*/
|
|
||||||
|
|
||||||
|
|
||||||
(function(module) {
|
|
||||||
var helpers = {};
|
|
||||||
|
|
||||||
helpers.displayUsersLink = function(config) {
|
|
||||||
return (config.loggedIn || !config.privateUserInfo);
|
|
||||||
};
|
|
||||||
|
|
||||||
helpers.buildMetaTag = function(tag) {
|
|
||||||
var name = tag.name ? 'name="' + tag.name + '" ' : '',
|
|
||||||
property = tag.property ? 'property="' + tag.property + '" ' : '',
|
|
||||||
content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : '';
|
|
||||||
|
|
||||||
return '<meta ' + name + property + content + '/>';
|
|
||||||
};
|
|
||||||
|
|
||||||
if ('undefined' !== typeof window) {
|
|
||||||
$(document).ready(module.exports);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function() {
|
|
||||||
var templates = templates || require('templates.js');
|
|
||||||
|
|
||||||
templates.registerHelper('displayUsersLink', helpers.displayUsersLink);
|
|
||||||
templates.registerHelper('buildMetaTag', helpers.buildMetaTag);
|
|
||||||
};
|
|
||||||
|
|
||||||
})('undefined' === typeof module ? {
|
|
||||||
module: {
|
|
||||||
exports: {}
|
|
||||||
}
|
|
||||||
} : module);
|
|
||||||
59
public/src/modules/helpers.js
Normal file
59
public/src/modules/helpers.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
;(function(exports) {
|
||||||
|
"use strict";
|
||||||
|
/* globals define */
|
||||||
|
|
||||||
|
// export the class if we are in a Node-like system.
|
||||||
|
if (typeof module === 'object' && module.exports === exports) {
|
||||||
|
exports = module.exports/* = SemVer*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
var helpers = {};
|
||||||
|
|
||||||
|
helpers.displayUsersLink = function(config) {
|
||||||
|
return (config.loggedIn || !config.privateUserInfo);
|
||||||
|
};
|
||||||
|
|
||||||
|
helpers.buildMetaTag = function(tag) {
|
||||||
|
var name = tag.name ? 'name="' + tag.name + '" ' : '',
|
||||||
|
property = tag.property ? 'property="' + tag.property + '" ' : '',
|
||||||
|
content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : '';
|
||||||
|
|
||||||
|
return '<meta ' + name + property + content + '/>';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Groups helpers
|
||||||
|
helpers.membershipBtn = function(groupObj) {
|
||||||
|
if (groupObj.isMember) {
|
||||||
|
return '<button class="btn btn-danger" data-action="leave" data-group="' + groupObj.name + '"><i class="fa fa-times"></i> Leave Group</button>';
|
||||||
|
} else {
|
||||||
|
if (groupObj.pending) {
|
||||||
|
return '<button class="btn btn-warning disabled"><i class="fa fa-clock-o"></i> Invitation Pending</button>';
|
||||||
|
} else {
|
||||||
|
return '<button class="btn btn-success" data-action="join" data-group="' + groupObj.name + '"><i class="fa fa-plus"></i> Join Group</button>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.register = function() {
|
||||||
|
var templates;
|
||||||
|
|
||||||
|
if (typeof module === 'object') {
|
||||||
|
templates = require('templates.js');
|
||||||
|
} else {
|
||||||
|
templates = window.templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
templates.registerHelper('displayUsersLink', helpers.displayUsersLink);
|
||||||
|
templates.registerHelper('buildMetaTag', helpers.buildMetaTag);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use the define() function if we're in AMD land
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
define('helpers', exports);
|
||||||
|
}
|
||||||
|
|
||||||
|
})(
|
||||||
|
typeof exports === 'object' ? exports :
|
||||||
|
typeof define === 'function' && define.amd ? {} :
|
||||||
|
helpers = {}
|
||||||
|
);
|
||||||
@@ -45,7 +45,6 @@ module.exports = function(Meta) {
|
|||||||
'public/src/variables.js',
|
'public/src/variables.js',
|
||||||
'public/src/widgets.js',
|
'public/src/widgets.js',
|
||||||
'public/src/translator.js',
|
'public/src/translator.js',
|
||||||
'public/src/helpers.js',
|
|
||||||
'public/src/overrides.js'
|
'public/src/overrides.js'
|
||||||
],
|
],
|
||||||
rjs: []
|
rjs: []
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ var path = require('path'),
|
|||||||
routes = require('./routes'),
|
routes = require('./routes'),
|
||||||
emitter = require('./emitter'),
|
emitter = require('./emitter'),
|
||||||
|
|
||||||
helpers = require('./../public/src/helpers')(),
|
helpers = require('./../public/src/modules/helpers'),
|
||||||
net;
|
net;
|
||||||
|
|
||||||
if(nconf.get('ssl')) {
|
if(nconf.get('ssl')) {
|
||||||
@@ -48,6 +48,9 @@ if(nconf.get('ssl')) {
|
|||||||
middleware = middleware(app);
|
middleware = middleware(app);
|
||||||
routes(app, middleware);
|
routes(app, middleware);
|
||||||
|
|
||||||
|
// Load server-side template helpers
|
||||||
|
helpers.register();
|
||||||
|
|
||||||
// Cache static files on production
|
// Cache static files on production
|
||||||
if (global.env !== 'development') {
|
if (global.env !== 'development') {
|
||||||
app.enable('cache');
|
app.enable('cache');
|
||||||
|
|||||||
Reference in New Issue
Block a user