replace self links client side

v1.18.x
barisusakli 11 years ago
parent c8efeb7d7c
commit 63d88957a8

@ -90,6 +90,7 @@ var socket,
socket.on('event:connect', function (data) { socket.on('event:connect', function (data) {
app.username = data.username; app.username = data.username;
app.userslug = data.userslug;
app.uid = data.uid; app.uid = data.uid;
app.isAdmin = data.isAdmin; app.isAdmin = data.isAdmin;
@ -285,6 +286,16 @@ var socket,
}); });
}; };
app.replaceSelfLinks = function(selector) {
selector = selector || $('a');
selector.each(function() {
var href = $(this).attr('href')
if (href && app.userslug) {
$(this).attr('href', href.replace(/\[self\]/g, app.userslug));
}
});
};
app.processPage = function () { app.processPage = function () {
app.populateOnlineUsers(); app.populateOnlineUsers();
@ -299,6 +310,8 @@ var socket,
app.createStatusTooltips(); app.createStatusTooltips();
app.replaceSelfLinks();
setTimeout(function () { setTimeout(function () {
window.scrollTo(0, 1); // rehide address bar on mobile after page load completes. window.scrollTo(0, 1); // rehide address bar on mobile after page load completes.
}, 100); }, 100);

@ -52,20 +52,6 @@ middleware.redirectToAccountIfLoggedIn = function(req, res, next) {
} }
}; };
middleware.redirectToSelf = function(req, res, next) {
if (req.user && req.params.userslug === '[self]') {
user.getUserField(req.user.uid, 'userslug', function (err, userslug) {
if(res.locals.isAPI) {
res.json(302, '/user/' + userslug + (req.params.section ? '/' + req.params.section : ''));
} else {
res.redirect('/user/' + userslug + (req.params.section ? '/' + req.params.section : ''));
}
});
} else {
next();
}
};
middleware.addSlug = function(req, res, next) { middleware.addSlug = function(req, res, next) {
function redirect(method, id, name) { function redirect(method, id, name) {
method(id, 'slug', function(err, slug) { method(id, 'slug', function(err, slug) {

@ -73,8 +73,6 @@ function categoryRoutes(app, middleware, controllers) {
} }
function accountRoutes(app, middleware, controllers) { function accountRoutes(app, middleware, controllers) {
app.get('/user/:userslug/:section?', middleware.redirectToSelf);
app.get('/api/user/:userslug/:section?', middleware.redirectToSelf);
app.get('/user/:userslug', middleware.buildHeader, middleware.checkGlobalPrivacySettings, controllers.accounts.getAccount); app.get('/user/:userslug', middleware.buildHeader, middleware.checkGlobalPrivacySettings, controllers.accounts.getAccount);
app.get('/api/user/:userslug', middleware.checkGlobalPrivacySettings, controllers.accounts.getAccount); app.get('/api/user/:userslug', middleware.checkGlobalPrivacySettings, controllers.accounts.getAccount);

@ -79,8 +79,8 @@ Sockets.init = function(server) {
socket.join('uid_' + uid); socket.join('uid_' + uid);
async.parallel({ async.parallel({
username: function(next) { user: function(next) {
user.getUserField(uid, 'username', next); user.getUserFields(uid, ['username', 'userslug'], next);
}, },
isAdmin: function(next) { isAdmin: function(next) {
user.isAdministrator(uid, next); user.isAdministrator(uid, next);
@ -88,7 +88,8 @@ Sockets.init = function(server) {
}, function(err, userData) { }, function(err, userData) {
socket.emit('event:connect', { socket.emit('event:connect', {
status: 1, status: 1,
username: userData.username, username: userData.user.username,
userslug: userData.user.userslug,
isAdmin: userData.isAdmin, isAdmin: userData.isAdmin,
uid: uid uid: uid
}); });

Loading…
Cancel
Save