diff --git a/public/src/app.js b/public/src/app.js index 5221974efb..720fb01d8c 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -58,10 +58,6 @@ var socket, reconnectEl.removeClass('active').addClass("hide"); }, 3000); } - - socket.emit('meta.updateHeader', { - fields: ['username', 'picture', 'userslug'] - }, app.updateHeader); } function onConfigLoad(data) { @@ -98,10 +94,6 @@ var socket, app.showLoginMessage(); - socket.emit('meta.updateHeader', { - fields: ['username', 'picture', 'userslug'] - }, app.updateHeader); - $(window).trigger('action:connected'); }); @@ -146,8 +138,6 @@ var socket, setTimeout(app.logout, 1000); }); - socket.on('meta.updateHeader', app.updateHeader); - app.enterRoom('global'); if (config.environment === 'development' && console && console.log) { @@ -289,7 +279,7 @@ var socket, app.replaceSelfLinks = function(selector) { selector = selector || $('a'); selector.each(function() { - var href = $(this).attr('href') + var href = $(this).attr('href'); if (href && app.userslug) { $(this).attr('href', href.replace(/\[self\]/g, app.userslug)); } @@ -430,8 +420,37 @@ var socket, }); } + function exposeConfigToTemplates() { + $(document).ready(function() { + templates.setGlobal('relative_path', RELATIVE_PATH); + for(var key in config) { + if (config.hasOwnProperty(key)) { + templates.setGlobal('config.' + key, config[key]); + } + } + }); + } + + function createHeaderTooltips() { + $('#header-menu li i[title]').each(function() { + $(this).parents('a').tooltip({ + placement: 'bottom', + title: $(this).attr('title') + }); + }); + + $('#search-form').parent().tooltip({ + placement: 'bottom', + title: $('#search-button i').attr('title') + }); - app.updateHeader = function(err, data) { + $('#user_dropdown').tooltip({ + placement: 'bottom', + title: $('#user_dropdown').attr('title') + }); + } + + function handleSearch() { var searchButton = $("#search-button"), searchFields = $("#search-fields"), searchInput = $('#search-fields input'); @@ -454,51 +473,23 @@ var socket, return false; }); - var loggedInMenu = $('#logged-in-menu'), - isLoggedIn = data.uid > 0, - allowGuestSearching = (data.config || {}).allowGuestSearching === '1'; - - if (isLoggedIn) { - $('#logged-out-menu').addClass('hide'); - $('#logged-in-menu').removeClass('hide'); - - searchButton.removeClass("hide").show(); - - var userLabel = loggedInMenu.find('#user_label'); - - if (data.userslug) { - userLabel.find('#user-profile-link').attr('href', RELATIVE_PATH + '/user/' + data.userslug); - } - if (data.picture) { - userLabel.find('img').attr('src', data.picture); - } - if (data.username) { - userLabel.find('#user-profile-link>span').html(' ' + data.username); - } - - $('#logout-link').on('click', app.logout); - - updateOnlineStatus(data.uid); - - } else { - if (allowGuestSearching) { - searchButton.removeClass("hide").show(); - $('#mobile-search-button').removeClass("hide").show(); - } else { - searchButton.addClass("hide").hide(); - $('#mobile-search-button').addClass("hide").hide(); - } - - $('#logged-out-menu').removeClass('hide'); - $('#logged-in-menu').addClass('hide'); - } + $('#search-form').on('submit', function () { + var input = $(this).find('input'); + ajaxify.go('search/' + input.val().replace(/^[ ?#]*/, '')); + input.val(''); + return false; + }); + } + function collapseNavigationOnClick() { $('#main-nav a, #user-control-list a, #logged-out-menu li a, #logged-in-menu .visible-xs').off('click').on('click', function() { if($('.navbar .navbar-collapse').hasClass('in')) { $('.navbar-header button').click(); } }); + } + function handleStatusChange() { $('#user-control-list .user-status').off('click').on('click', function(e) { socket.emit('user.setStatus', $(this).attr('data-status'), function(err, data) { if(err) { @@ -508,39 +499,8 @@ var socket, }); e.preventDefault(); }); - }; - - function exposeConfigToTemplates() { - $(document).ready(function() { - templates.setGlobal('relative_path', RELATIVE_PATH); - for(var key in config) { - if (config.hasOwnProperty(key)) { - templates.setGlobal('config.' + key, config[key]); - } - } - }); - } - - function createHeaderTooltips() { - $('#header-menu li i[title]').each(function() { - $(this).parents('a').tooltip({ - placement: 'bottom', - title: $(this).attr('title') - }); - }); - - $('#search-form').parent().tooltip({ - placement: 'bottom', - title: $('#search-button i').attr('title') - }); - - $('#user_dropdown').tooltip({ - placement: 'bottom', - title: $('#user_dropdown').attr('title') - }); } - app.load = function() { $('document').ready(function () { var url = window.location.pathname.slice(1), @@ -556,12 +516,13 @@ var socket, url: url }); - $('#search-form').on('submit', function () { - var input = $(this).find('input'); - ajaxify.go("search/" + input.val().replace(/^[ ?#]*/, '')); - input.val(''); - return false; - }); + collapseNavigationOnClick(); + + handleStatusChange(); + + handleSearch(); + + $('#logout-link').on('click', app.logout); $(window).blur(function(){ app.isFocused = false; diff --git a/public/src/forum/account/edit.js b/public/src/forum/account/edit.js index c1120432bc..acbe3275a6 100644 --- a/public/src/forum/account/edit.js +++ b/public/src/forum/account/edit.js @@ -26,6 +26,7 @@ define(['forum/account/header', 'uploader'], function(header, uploader) { handleImageUpload(); handlePasswordChange(); updateSignature(); + updateImages(); }; function updateProfile() { @@ -66,7 +67,7 @@ define(['forum/account/header', 'uploader'], function(header, uploader) { $('.account-username-box').attr('data-userslug', data.userslug); $('#user-profile-link').attr('href', config.relative_path + '/user/' + data.userslug); - $('#user-profile-link span').html(' ' + userData.username); + $('#user-header-name').text(userData.username); } }); @@ -106,8 +107,10 @@ define(['forum/account/header', 'uploader'], function(header, uploader) { if (selectedImageType === 'gravatar') { $('#user-current-picture').attr('src', gravatarPicture); + $('#user-header-picture').attr('src', gravatarPicture); } else if (selectedImageType === 'uploaded') { $('#user-current-picture').attr('src', uploadedPicture); + $('#user-header-picture').attr('src', uploadedPicture); } } }); @@ -126,12 +129,9 @@ define(['forum/account/header', 'uploader'], function(header, uploader) { $('#user-current-picture').attr('src', imageUrlOnServer); $('#user-uploaded-picture').attr('src', imageUrlOnServer); + $('#user-header-picture').attr('src', imageUrlOnServer); uploadedPicture = imageUrlOnServer; - - socket.emit('meta.updateHeader', { - fields: ['username', 'picture', 'userslug'] - }, app.updateHeader); }); return false; @@ -223,7 +223,7 @@ define(['forum/account/header', 'uploader'], function(header, uploader) { $('#gravatar-box').toggle(!!gravatarPicture); $('#uploaded-box').toggle(!!uploadedPicture); - $('#gravatar-box .fa-check').toggle(currentPicture === gravatarPicture); + $('#gravatar-box .fa-check').toggle(currentPicture !== uploadedPicture); $('#uploaded-box .fa-check').toggle(currentPicture === uploadedPicture); } diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index 585b9722c9..de0a25e81f 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -1,9 +1,5 @@ define(['notifications', 'chat'], function(Notifications, Chat) { - socket.emit('meta.updateHeader', { - fields: ['username', 'picture', 'userslug'] - }, app.updateHeader); - Notifications.prepareDOM(); Chat.prepareDOM(); translator.prepareDOM(); diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 98b616a54e..29b836035e 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -207,7 +207,7 @@ middleware.renderHeader = function(req, res, callback) { csrf: res.locals.csrf_token, navigation: custom_header.navigation, allowRegistration: meta.config.allowRegistration === undefined || parseInt(meta.config.allowRegistration, 10) === 1, - searchEnabled: plugins.hasListeners('filter:search.query') ? true : false + searchEnabled: plugins.hasListeners('filter:search.query') && (uid || parseInt(meta.config.allowGuestSearching, 10) === 1) }, escapeList = { '&': '&', @@ -264,13 +264,22 @@ middleware.renderHeader = function(req, res, callback) { }, isAdmin: function(next) { user.isAdministrator(uid, next); + }, + user: function(next) { + if (uid) { + user.getUserFields(uid, ['username', 'userslug', 'picture', 'status'], next); + } else { + next(); + } } }, function(err, results) { if (err) { return next(err); } + templateValues.browserTitle = results.title; templateValues.isAdmin = results.isAdmin || false; + templateValues.user = results.user; app.render('header', templateValues, callback); }); diff --git a/src/plugins.js b/src/plugins.js index 9be76bafe8..c72420def7 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -291,7 +291,7 @@ var fs = require('fs'), }; Plugins.hasListeners = function(hook) { - return (Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0); + return !!(Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0); }; Plugins.fireHook = function(hook) { diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index 35039a9dd4..5ce1004971 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -44,37 +44,6 @@ SocketMeta.buildTitle = function(socket, text, callback) { } }; -SocketMeta.updateHeader = function(socket, data, callback) { - if(!data) { - return callback(new Error('[[error:invalid-data]]')); - } - - if (socket.uid) { - user.getUserFields(socket.uid, data.fields, function(err, fields) { - if(err) { - return callback(err); - } - - if (fields) { - fields.uid = socket.uid; - callback(null, fields); - } else { - callback(null, []); - } - }); - } else { - callback(null, { - uid: 0, - username: '[[global:guest]]', - email: '', - picture: user.createGravatarURLFromEmail(''), - config: { - allowGuestSearching: meta.config.allowGuestSearching - } - }); - } -}; - SocketMeta.getUsageStats = function(socket, data, callback) { module.parent.exports.emitTopicPostStats(callback); }; diff --git a/src/socket.io/user.js b/src/socket.io/user.js index 4c564c18c9..c03b4cef13 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -87,21 +87,6 @@ SocketUser.changePicture = function(socket, data, callback) { var type = data.type; - function updateHeader(callback) { - user.getUserFields(socket.uid, ['picture'], function(err, fields) { - if(err) { - return callback(err); - } - - if (fields) { - fields.uid = socket.uid; - socket.emit('meta.updateHeader', null, fields); - } - - callback(); - }); - } - function changePicture(uid, callback) { user.getUserField(uid, type, function(err, picture) { if(err) { @@ -125,7 +110,7 @@ SocketUser.changePicture = function(socket, data, callback) { if(err) { return callback(err); } - updateHeader(callback); + }); return; }