2014-03-12 18:30:13 -04:00
|
|
|
"use strict";
|
2014-12-19 17:19:29 -05:00
|
|
|
/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH, config*/
|
2014-03-12 18:30:13 -04:00
|
|
|
|
2014-12-19 17:19:29 -05:00
|
|
|
var socket,
|
2014-12-19 18:31:39 -05:00
|
|
|
app = app || {};
|
|
|
|
|
|
|
|
|
|
app.isFocused = true;
|
|
|
|
|
app.isConnected = false;
|
|
|
|
|
app.currentRoom = null;
|
|
|
|
|
app.widgets = {};
|
|
|
|
|
app.cacheBuster = null;
|
|
|
|
|
|
|
|
|
|
// TODO: deprecate in 0.7.0, use app.user
|
|
|
|
|
app.username = null;
|
|
|
|
|
app.uid = null;
|
2013-04-22 19:13:39 +00:00
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
(function () {
|
2013-08-13 12:58:07 -04:00
|
|
|
var showWelcomeMessage = false;
|
2014-04-09 13:26:24 +01:00
|
|
|
var reconnecting = false;
|
|
|
|
|
|
2014-12-19 17:19:29 -05:00
|
|
|
function socketIOConnect() {
|
|
|
|
|
var ioParams = {
|
|
|
|
|
reconnectionAttempts: config.maxReconnectionAttempts,
|
|
|
|
|
reconnectionDelay : config.reconnectionDelay,
|
|
|
|
|
transports: config.socketioTransports,
|
|
|
|
|
path: config.relative_path + '/socket.io'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
socket = io.connect(config.websocketAddress, ioParams);
|
|
|
|
|
reconnecting = false;
|
|
|
|
|
|
|
|
|
|
socket.on('event:connect', function (data) {
|
|
|
|
|
// TODO : deprecate in 0.7.0, use app.user
|
|
|
|
|
app.username = data.username;
|
|
|
|
|
app.userslug = data.userslug;
|
|
|
|
|
app.picture = data.picture;
|
|
|
|
|
app.uid = data.uid;
|
|
|
|
|
app.isAdmin = data.isAdmin;
|
|
|
|
|
|
|
|
|
|
app.showLoginMessage();
|
|
|
|
|
app.replaceSelfLinks();
|
|
|
|
|
$(window).trigger('action:connected');
|
|
|
|
|
app.isConnected = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.on('connect', onSocketConnect);
|
|
|
|
|
|
|
|
|
|
socket.on('event:disconnect', function() {
|
|
|
|
|
$(window).trigger('action:disconnected');
|
|
|
|
|
app.isConnected = false;
|
2014-12-19 18:49:56 -05:00
|
|
|
socket.connect();
|
2014-12-19 17:19:29 -05:00
|
|
|
});
|
|
|
|
|
|
2014-12-19 18:49:56 -05:00
|
|
|
socket.on('reconnecting', function (attempt) {
|
2014-12-19 17:19:29 -05:00
|
|
|
if(attempt === parseInt(config.maxReconnectionAttempts, 10)) {
|
2014-12-19 18:49:56 -05:00
|
|
|
socket.io.attempts = 0;
|
2014-12-19 17:19:29 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reconnecting = true;
|
|
|
|
|
var reconnectEl = $('#reconnect');
|
|
|
|
|
|
|
|
|
|
if (!reconnectEl.hasClass('active')) {
|
|
|
|
|
reconnectEl.html('<i class="fa fa-spinner fa-spin"></i>');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reconnectEl.addClass('active').removeClass("hide").tooltip({
|
|
|
|
|
placement: 'bottom'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
socket.on('event:banned', function() {
|
|
|
|
|
app.alert({
|
|
|
|
|
title: '[[global:alert.banned]]',
|
|
|
|
|
message: '[[global:alert.banned.message]]',
|
|
|
|
|
type: 'danger',
|
|
|
|
|
timeout: 1000
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
window.location.href = config.relative_path + '/';
|
|
|
|
|
}, 1000);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-09 13:26:24 +01:00
|
|
|
function onSocketConnect(data) {
|
|
|
|
|
if (reconnecting) {
|
|
|
|
|
var reconnectEl = $('#reconnect');
|
|
|
|
|
|
|
|
|
|
reconnectEl.tooltip('destroy');
|
|
|
|
|
reconnectEl.html('<i class="fa fa-check"></i>');
|
|
|
|
|
reconnecting = false;
|
|
|
|
|
|
|
|
|
|
// Rejoin room that was left when we disconnected
|
2014-05-16 09:39:46 -04:00
|
|
|
var url_parts = window.location.pathname.slice(RELATIVE_PATH.length).split('/').slice(1);
|
2014-04-09 13:26:24 +01:00
|
|
|
var room;
|
|
|
|
|
|
|
|
|
|
switch(url_parts[0]) {
|
|
|
|
|
case 'user':
|
|
|
|
|
room = 'user/' + ajaxify.variables.get('theirid');
|
|
|
|
|
break;
|
|
|
|
|
case 'topic':
|
|
|
|
|
room = 'topic_' + url_parts[1];
|
|
|
|
|
break;
|
|
|
|
|
case 'category':
|
|
|
|
|
room = 'category_' + url_parts[1];
|
|
|
|
|
break;
|
|
|
|
|
case 'recent': // intentional fall-through
|
|
|
|
|
case 'unread':
|
|
|
|
|
room = 'recent_posts';
|
|
|
|
|
break;
|
|
|
|
|
case 'admin':
|
|
|
|
|
room = 'admin';
|
|
|
|
|
break;
|
2014-09-05 22:11:21 -04:00
|
|
|
case 'home':
|
|
|
|
|
room = 'home';
|
2014-04-09 13:26:24 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2014-09-05 22:11:21 -04:00
|
|
|
app.currentRoom = '';
|
|
|
|
|
app.enterRoom(room);
|
2014-02-20 13:23:29 -05:00
|
|
|
|
2014-07-20 18:44:08 -04:00
|
|
|
socket.emit('meta.reconnected');
|
|
|
|
|
|
2014-10-02 18:32:36 -04:00
|
|
|
app.isConnected = true;
|
2014-04-09 13:26:24 +01:00
|
|
|
$(window).trigger('action:reconnected');
|
2014-02-20 13:23:29 -05:00
|
|
|
|
2014-04-09 13:26:24 +01:00
|
|
|
setTimeout(function() {
|
2014-12-05 13:15:51 -05:00
|
|
|
reconnectEl.removeClass('active').addClass('hide');
|
2014-04-09 13:26:24 +01:00
|
|
|
}, 3000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-08 17:35:23 -04:00
|
|
|
|
2013-10-28 14:36:31 -04:00
|
|
|
app.logout = function() {
|
2014-11-18 14:54:54 -05:00
|
|
|
require(['csrf'], function(csrf) {
|
|
|
|
|
$.ajax(RELATIVE_PATH + '/logout', {
|
|
|
|
|
type: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'x-csrf-token': csrf.get()
|
|
|
|
|
},
|
|
|
|
|
success: function() {
|
|
|
|
|
window.location.href = RELATIVE_PATH + '/';
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-10-28 14:36:31 -04:00
|
|
|
});
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-10-28 14:36:31 -04:00
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
app.alert = function (params) {
|
2014-03-31 14:49:48 -04:00
|
|
|
require(['alerts'], function(alerts) {
|
|
|
|
|
alerts.alert(params);
|
|
|
|
|
});
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-04-23 19:38:48 +00:00
|
|
|
|
2014-02-26 21:58:04 -05:00
|
|
|
app.removeAlert = function(id) {
|
2014-03-31 14:49:48 -04:00
|
|
|
require(['alerts'], function(alerts) {
|
|
|
|
|
alerts.remove(id);
|
|
|
|
|
});
|
2014-03-12 18:30:13 -04:00
|
|
|
};
|
2014-02-26 21:58:04 -05:00
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
app.alertSuccess = function (message, timeout) {
|
2013-07-30 18:30:43 -04:00
|
|
|
app.alert({
|
2014-01-30 13:30:49 -05:00
|
|
|
title: '[[global:alert.success]]',
|
2013-07-30 18:30:43 -04:00
|
|
|
message: message,
|
|
|
|
|
type: 'success',
|
2014-03-31 14:49:48 -04:00
|
|
|
timeout: timeout ? timeout : 2000
|
2013-07-30 18:30:43 -04:00
|
|
|
});
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-07-30 18:30:43 -04:00
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
app.alertError = function (message, timeout) {
|
2013-07-30 18:30:43 -04:00
|
|
|
app.alert({
|
2014-01-30 13:30:49 -05:00
|
|
|
title: '[[global:alert.error]]',
|
2013-07-30 18:30:43 -04:00
|
|
|
message: message,
|
2013-08-24 03:36:44 +08:00
|
|
|
type: 'danger',
|
2014-12-21 14:14:46 -05:00
|
|
|
timeout: timeout ? timeout : 5000
|
2013-07-30 18:30:43 -04:00
|
|
|
});
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-06-21 17:48:12 -04:00
|
|
|
|
2014-09-05 22:11:21 -04:00
|
|
|
app.enterRoom = function (room) {
|
2013-09-17 13:03:53 -04:00
|
|
|
if (socket) {
|
2014-09-05 22:11:21 -04:00
|
|
|
if (app.currentRoom === room) {
|
2013-07-14 21:58:11 -04:00
|
|
|
return;
|
2013-11-23 17:07:31 -05:00
|
|
|
}
|
2013-08-20 12:31:08 -04:00
|
|
|
|
2014-01-16 15:10:37 -05:00
|
|
|
socket.emit('meta.rooms.enter', {
|
2014-09-06 00:19:46 -04:00
|
|
|
enter: room,
|
|
|
|
|
username: app.username,
|
|
|
|
|
userslug: app.userslug,
|
|
|
|
|
picture: app.picture
|
2013-07-14 21:58:11 -04:00
|
|
|
});
|
2013-08-20 12:31:08 -04:00
|
|
|
|
2013-11-23 17:07:31 -05:00
|
|
|
app.currentRoom = room;
|
2013-07-14 21:58:11 -04:00
|
|
|
}
|
2013-05-05 20:10:26 +00:00
|
|
|
};
|
|
|
|
|
|
2013-11-23 17:07:31 -05:00
|
|
|
function highlightNavigationLink() {
|
2013-11-11 14:06:26 -05:00
|
|
|
var path = window.location.pathname,
|
|
|
|
|
parts = path.split('/'),
|
2013-09-17 13:03:53 -04:00
|
|
|
active = parts[parts.length - 1];
|
2013-08-20 12:31:08 -04:00
|
|
|
|
2014-02-26 21:55:29 -05:00
|
|
|
$('#main-nav li').removeClass('active');
|
2013-09-17 13:03:53 -04:00
|
|
|
if (active) {
|
2014-02-26 21:55:29 -05:00
|
|
|
$('#main-nav li a').each(function () {
|
|
|
|
|
var href = $(this).attr('href');
|
2014-03-12 18:30:13 -04:00
|
|
|
if (active === "sort-posts" || active === "sort-reputation" || active === "search" || active === "latest" || active === "online") {
|
2013-07-22 18:29:09 -04:00
|
|
|
active = 'users';
|
2014-03-12 18:30:13 -04:00
|
|
|
}
|
|
|
|
|
|
2013-07-24 12:33:37 -04:00
|
|
|
if (href && href.match(active)) {
|
2014-02-26 21:55:29 -05:00
|
|
|
$(this.parentNode).addClass('active');
|
2013-07-22 18:29:09 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2014-02-26 21:55:29 -05:00
|
|
|
}
|
2013-11-23 17:07:31 -05:00
|
|
|
|
2013-11-24 22:48:58 -05:00
|
|
|
app.createUserTooltips = function() {
|
|
|
|
|
$('img[title].teaser-pic,img[title].user-img').each(function() {
|
|
|
|
|
$(this).tooltip({
|
|
|
|
|
placement: 'top',
|
|
|
|
|
title: $(this).attr('title')
|
|
|
|
|
});
|
|
|
|
|
});
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-11-24 22:48:58 -05:00
|
|
|
|
2014-02-23 21:50:02 -05:00
|
|
|
app.createStatusTooltips = function() {
|
|
|
|
|
$('body').tooltip({
|
|
|
|
|
selector:'.fa-circle.status',
|
|
|
|
|
placement: 'top'
|
|
|
|
|
});
|
2014-02-26 21:55:29 -05:00
|
|
|
};
|
2014-02-23 21:50:02 -05:00
|
|
|
|
2014-04-30 17:42:50 -04:00
|
|
|
app.replaceSelfLinks = function(selector) {
|
|
|
|
|
selector = selector || $('a');
|
|
|
|
|
selector.each(function() {
|
2014-05-06 18:42:38 -04:00
|
|
|
var href = $(this).attr('href');
|
2014-11-21 11:44:06 -05:00
|
|
|
if (href && app.userslug && href.indexOf('user/_self_') !== -1) {
|
|
|
|
|
$(this).attr('href', href.replace(/user\/_self_/g, 'user/' + app.userslug));
|
2014-04-30 17:42:50 -04:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-23 17:07:31 -05:00
|
|
|
app.processPage = function () {
|
|
|
|
|
highlightNavigationLink();
|
2013-07-22 18:29:09 -04:00
|
|
|
|
2013-09-19 15:02:35 -04:00
|
|
|
$('span.timeago').timeago();
|
2013-11-28 11:16:52 -05:00
|
|
|
|
2014-03-31 14:43:44 -04:00
|
|
|
utils.makeNumbersHumanReadable($('.human-readable-number'));
|
2013-09-23 14:40:31 -04:00
|
|
|
|
2014-05-08 19:17:31 -04:00
|
|
|
utils.addCommasToNumbers($('.formatted-number'));
|
|
|
|
|
|
2013-11-24 22:48:58 -05:00
|
|
|
app.createUserTooltips();
|
|
|
|
|
|
2014-02-23 21:50:02 -05:00
|
|
|
app.createStatusTooltips();
|
|
|
|
|
|
2014-04-30 17:42:50 -04:00
|
|
|
app.replaceSelfLinks();
|
|
|
|
|
|
2015-01-26 21:35:14 -05:00
|
|
|
// Scroll back to top of page
|
|
|
|
|
window.scrollTo(0, 0);
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-05-21 17:02:04 -04:00
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
app.showLoginMessage = function () {
|
2013-07-30 18:30:43 -04:00
|
|
|
function showAlert() {
|
2013-07-25 16:20:18 -04:00
|
|
|
app.alert({
|
|
|
|
|
type: 'success',
|
2014-02-16 11:36:11 -05:00
|
|
|
title: '[[global:welcome_back]] ' + app.username + '!',
|
|
|
|
|
message: '[[global:you_have_successfully_logged_in]]',
|
2013-07-25 16:20:18 -04:00
|
|
|
timeout: 5000
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-08-20 12:31:08 -04:00
|
|
|
|
2013-09-17 13:03:53 -04:00
|
|
|
if (showWelcomeMessage) {
|
2013-08-13 12:58:07 -04:00
|
|
|
showWelcomeMessage = false;
|
2013-09-17 13:03:53 -04:00
|
|
|
if (document.readyState !== 'complete') {
|
2013-07-30 18:30:43 -04:00
|
|
|
$(document).ready(showAlert);
|
|
|
|
|
} else {
|
|
|
|
|
showAlert();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-07-25 16:20:18 -04:00
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
app.openChat = function (username, touid) {
|
2013-11-21 17:00:20 -05:00
|
|
|
if (username === app.username) {
|
2014-04-10 12:47:48 -04:00
|
|
|
return app.alertError('[[error:cant-chat-with-yourself]]');
|
2013-11-21 17:00:20 -05:00
|
|
|
}
|
2013-11-21 20:11:06 -05:00
|
|
|
|
2014-02-28 15:36:57 -05:00
|
|
|
if (!app.uid) {
|
2014-04-10 12:47:48 -04:00
|
|
|
return app.alertError('[[error:not-logged-in]]');
|
2013-11-21 17:00:20 -05:00
|
|
|
}
|
|
|
|
|
|
2013-09-24 11:02:06 -04:00
|
|
|
require(['chat'], function (chat) {
|
2014-11-04 17:23:39 -05:00
|
|
|
function loadAndCenter(chatModal) {
|
|
|
|
|
chat.load(chatModal.attr('UUID'));
|
|
|
|
|
chat.center(chatModal);
|
2014-12-21 00:08:01 -05:00
|
|
|
chat.focusInput(chatModal);
|
2014-11-04 17:23:39 -05:00
|
|
|
}
|
2014-11-04 16:49:02 -05:00
|
|
|
|
2014-11-04 17:23:39 -05:00
|
|
|
if (!chat.modalExists(touid)) {
|
|
|
|
|
chat.createModal(username, touid, loadAndCenter);
|
|
|
|
|
} else {
|
|
|
|
|
loadAndCenter(chat.getModal(touid));
|
|
|
|
|
}
|
2013-08-30 14:25:59 -04:00
|
|
|
});
|
2013-12-08 10:38:09 -05:00
|
|
|
};
|
2013-11-26 14:25:46 -05:00
|
|
|
|
2013-12-05 23:24:47 -05:00
|
|
|
var titleObj = {
|
|
|
|
|
active: false,
|
|
|
|
|
interval: undefined,
|
|
|
|
|
titles: []
|
|
|
|
|
};
|
2014-01-16 17:11:27 -05:00
|
|
|
|
2013-12-05 23:24:47 -05:00
|
|
|
app.alternatingTitle = function (title) {
|
2014-01-14 10:31:21 -05:00
|
|
|
if (typeof title !== 'string') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-12-05 23:24:47 -05:00
|
|
|
|
2014-01-19 22:38:44 +01:00
|
|
|
if (title.length > 0 && !app.isFocused) {
|
2014-05-09 17:46:10 -04:00
|
|
|
if (!titleObj.titles[0]) {
|
|
|
|
|
titleObj.titles[0] = window.document.title;
|
|
|
|
|
}
|
2014-05-09 17:57:39 -04:00
|
|
|
|
|
|
|
|
translator.translate(title, function(translated) {
|
|
|
|
|
titleObj.titles[1] = translated;
|
|
|
|
|
if (titleObj.interval) {
|
|
|
|
|
clearInterval(titleObj.interval);
|
2014-02-10 14:05:09 -05:00
|
|
|
}
|
2014-05-09 17:57:39 -04:00
|
|
|
|
|
|
|
|
titleObj.interval = setInterval(function() {
|
|
|
|
|
var title = titleObj.titles[titleObj.titles.indexOf(window.document.title) ^ 1];
|
|
|
|
|
if (title) {
|
2014-11-01 15:08:12 -04:00
|
|
|
window.document.title = $('<div/>').html(title).text();
|
2014-05-09 17:57:39 -04:00
|
|
|
}
|
|
|
|
|
}, 2000);
|
|
|
|
|
});
|
2013-12-05 23:24:47 -05:00
|
|
|
} else {
|
|
|
|
|
if (titleObj.interval) {
|
|
|
|
|
clearInterval(titleObj.interval);
|
|
|
|
|
}
|
2014-01-14 10:31:21 -05:00
|
|
|
if (titleObj.titles[0]) {
|
2014-11-01 15:08:12 -04:00
|
|
|
window.document.title = $('<div/>').html(titleObj.titles[0]).text();
|
2014-01-14 10:31:21 -05:00
|
|
|
}
|
2013-12-05 23:24:47 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
app.refreshTitle = function(url) {
|
|
|
|
|
if (!url) {
|
|
|
|
|
var a = document.createElement('a');
|
|
|
|
|
a.href = document.location;
|
|
|
|
|
url = a.pathname.slice(1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 17:11:27 -05:00
|
|
|
socket.emit('meta.buildTitle', url, function(err, title, numNotifications) {
|
2014-11-01 15:08:12 -04:00
|
|
|
if (err) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-12-05 23:24:47 -05:00
|
|
|
titleObj.titles[0] = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
|
|
|
|
|
app.alternatingTitle('');
|
|
|
|
|
});
|
|
|
|
|
};
|
2013-09-04 04:50:45 +08:00
|
|
|
|
2014-09-19 14:39:27 -04:00
|
|
|
app.toggleNavbar = function(state) {
|
|
|
|
|
var navbarEl = $('.navbar');
|
|
|
|
|
if (navbarEl) {
|
|
|
|
|
navbarEl.toggleClass('hidden', !!!state);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-19 16:38:45 -05:00
|
|
|
app.exposeConfigToTemplates = function() {
|
2014-05-06 18:42:38 -04:00
|
|
|
$(document).ready(function() {
|
2014-12-19 17:19:29 -05:00
|
|
|
templates.setGlobal('loggedIn', config.loggedIn);
|
2014-05-06 18:42:38 -04:00
|
|
|
templates.setGlobal('relative_path', RELATIVE_PATH);
|
|
|
|
|
for(var key in config) {
|
|
|
|
|
if (config.hasOwnProperty(key)) {
|
|
|
|
|
templates.setGlobal('config.' + key, config[key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createHeaderTooltips() {
|
2014-07-18 20:43:47 -04:00
|
|
|
if (utils.findBootstrapEnvironment() === 'xs') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-20 14:21:23 -04:00
|
|
|
$('#header-menu li [title]').each(function() {
|
|
|
|
|
$(this).tooltip({
|
2014-05-06 18:42:38 -04:00
|
|
|
placement: 'bottom',
|
|
|
|
|
title: $(this).attr('title')
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#search-form').parent().tooltip({
|
|
|
|
|
placement: 'bottom',
|
|
|
|
|
title: $('#search-button i').attr('title')
|
|
|
|
|
});
|
2014-01-31 16:21:41 -05:00
|
|
|
|
2014-05-06 18:42:38 -04:00
|
|
|
$('#user_dropdown').tooltip({
|
|
|
|
|
placement: 'bottom',
|
|
|
|
|
title: $('#user_dropdown').attr('title')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function handleSearch() {
|
2014-04-09 13:25:02 +01:00
|
|
|
var searchButton = $("#search-button"),
|
|
|
|
|
searchFields = $("#search-fields"),
|
|
|
|
|
searchInput = $('#search-fields input');
|
|
|
|
|
|
2014-08-29 11:48:30 -04:00
|
|
|
$('#search-form').on('submit', dismissSearch);
|
|
|
|
|
searchInput.on('blur', dismissSearch);
|
|
|
|
|
|
2014-04-09 13:25:02 +01:00
|
|
|
function dismissSearch(){
|
|
|
|
|
searchFields.hide();
|
|
|
|
|
searchButton.show();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 11:48:30 -04:00
|
|
|
function prepareSearch() {
|
|
|
|
|
searchFields.removeClass('hide').show();
|
|
|
|
|
searchButton.hide();
|
|
|
|
|
searchInput.focus();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-11 12:16:01 -04:00
|
|
|
searchButton.on('click', function(e) {
|
2014-07-24 21:11:46 -04:00
|
|
|
if (!config.loggedIn && !config.allowGuestSearching) {
|
2014-06-19 18:46:01 -04:00
|
|
|
app.alert({
|
|
|
|
|
message:'[[error:search-requires-login]]',
|
|
|
|
|
timeout: 3000
|
|
|
|
|
});
|
|
|
|
|
ajaxify.go('login');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2014-01-14 10:31:21 -05:00
|
|
|
e.stopPropagation();
|
2014-04-09 13:25:02 +01:00
|
|
|
|
2014-08-29 11:48:30 -04:00
|
|
|
prepareSearch();
|
2014-01-20 21:41:04 -05:00
|
|
|
return false;
|
2014-01-09 22:46:51 -05:00
|
|
|
});
|
|
|
|
|
|
2014-08-29 11:48:30 -04:00
|
|
|
require(['search', 'mousetrap'], function(search, Mousetrap) {
|
2014-08-29 11:18:02 -04:00
|
|
|
$('#search-form').on('submit', function (e) {
|
|
|
|
|
e.preventDefault();
|
2015-01-07 16:10:11 -05:00
|
|
|
var input = $(this).find('input');
|
2014-08-29 11:18:02 -04:00
|
|
|
|
2015-01-07 17:27:09 -05:00
|
|
|
search.query({term: input.val(), in: 'posts'}, function() {
|
2014-08-27 15:25:02 -04:00
|
|
|
input.val('');
|
|
|
|
|
});
|
|
|
|
|
});
|
2014-08-29 11:18:02 -04:00
|
|
|
|
|
|
|
|
$('.topic-search')
|
|
|
|
|
.on('click', '.prev', function() {
|
|
|
|
|
search.topicDOM.prev();
|
|
|
|
|
})
|
|
|
|
|
.on('click', '.next', function() {
|
|
|
|
|
search.topicDOM.next();
|
|
|
|
|
});
|
2014-08-29 11:48:30 -04:00
|
|
|
|
|
|
|
|
Mousetrap.bind('ctrl+f', function(e) {
|
2014-11-24 12:48:21 -05:00
|
|
|
if (config.topicSearchEnabled) {
|
|
|
|
|
// If in topic, open search window and populate, otherwise regular behaviour
|
|
|
|
|
var match = ajaxify.currentPage.match(/^topic\/([\d]+)/),
|
|
|
|
|
tid;
|
|
|
|
|
if (match) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
tid = match[1];
|
|
|
|
|
searchInput.val('in:topic-' + tid + ' ');
|
|
|
|
|
prepareSearch();
|
|
|
|
|
}
|
2014-08-29 11:48:30 -04:00
|
|
|
}
|
|
|
|
|
});
|
2014-05-06 18:42:38 -04:00
|
|
|
});
|
|
|
|
|
}
|
2014-01-09 22:46:51 -05:00
|
|
|
|
2014-05-06 18:42:38 -04:00
|
|
|
function collapseNavigationOnClick() {
|
2014-04-09 13:26:40 +01:00
|
|
|
$('#main-nav a, #user-control-list a, #logged-out-menu li a, #logged-in-menu .visible-xs').off('click').on('click', function() {
|
2014-01-14 10:31:21 -05:00
|
|
|
if($('.navbar .navbar-collapse').hasClass('in')) {
|
2014-01-09 22:46:51 -05:00
|
|
|
$('.navbar-header button').click();
|
2014-01-14 10:31:21 -05:00
|
|
|
}
|
2014-01-09 22:46:51 -05:00
|
|
|
});
|
2014-05-06 18:42:38 -04:00
|
|
|
}
|
2014-01-31 15:13:52 -05:00
|
|
|
|
2014-05-06 18:42:38 -04:00
|
|
|
function handleStatusChange() {
|
2014-01-31 16:21:41 -05:00
|
|
|
$('#user-control-list .user-status').off('click').on('click', function(e) {
|
2014-09-02 05:04:39 -04:00
|
|
|
var status = $(this).attr('data-status');
|
|
|
|
|
socket.emit('user.setStatus', status, function(err, data) {
|
2014-01-31 15:13:52 -05:00
|
|
|
if(err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
2014-09-02 05:04:39 -04:00
|
|
|
$('#logged-in-menu #user_label #user-profile-link>i').attr('class', 'fa fa-circle status ' + status);
|
2014-01-31 15:13:52 -05:00
|
|
|
});
|
2014-01-31 16:21:41 -05:00
|
|
|
e.preventDefault();
|
2014-01-31 15:13:52 -05:00
|
|
|
});
|
2014-01-27 01:48:43 -05:00
|
|
|
}
|
|
|
|
|
|
2014-03-11 14:41:32 -04:00
|
|
|
app.load = function() {
|
|
|
|
|
$('document').ready(function () {
|
2014-06-16 10:28:57 +07:00
|
|
|
var url = ajaxify.removeRelativePath(window.location.pathname.slice(1).replace(/\/$/, "")),
|
2014-06-15 23:30:40 -04:00
|
|
|
tpl_url = ajaxify.getTemplateMapping(url),
|
2014-05-16 01:38:20 -04:00
|
|
|
search = window.location.search,
|
2014-05-16 09:39:46 -04:00
|
|
|
hash = window.location.hash,
|
|
|
|
|
$window = $(window);
|
2014-02-28 16:08:13 -05:00
|
|
|
|
2014-05-30 15:29:17 -04:00
|
|
|
|
2014-05-16 09:39:46 -04:00
|
|
|
$window.trigger('action:ajaxify.start', {
|
2015-01-12 17:54:07 -05:00
|
|
|
url: url,
|
|
|
|
|
tpl_url: tpl_url
|
2014-03-11 14:41:32 -04:00
|
|
|
});
|
2014-02-28 16:08:13 -05:00
|
|
|
|
2014-05-06 18:42:38 -04:00
|
|
|
collapseNavigationOnClick();
|
|
|
|
|
|
|
|
|
|
handleStatusChange();
|
|
|
|
|
|
2014-11-24 12:38:44 -05:00
|
|
|
if (config.searchEnabled) {
|
|
|
|
|
handleSearch();
|
|
|
|
|
}
|
2014-05-06 18:42:38 -04:00
|
|
|
|
|
|
|
|
$('#logout-link').on('click', app.logout);
|
2014-02-28 16:08:13 -05:00
|
|
|
|
2014-10-02 18:29:40 -04:00
|
|
|
Visibility.change(function(e, state){
|
|
|
|
|
if (state === 'visible') {
|
|
|
|
|
app.isFocused = true;
|
|
|
|
|
app.alternatingTitle('');
|
|
|
|
|
} else if (state === 'hidden') {
|
|
|
|
|
app.isFocused = false;
|
|
|
|
|
}
|
2014-03-11 14:41:32 -04:00
|
|
|
});
|
2014-02-28 16:08:13 -05:00
|
|
|
|
2014-03-11 14:41:32 -04:00
|
|
|
createHeaderTooltips();
|
2014-12-21 14:36:22 -05:00
|
|
|
showEmailConfirmWarning();
|
|
|
|
|
|
2014-03-28 13:02:36 -04:00
|
|
|
ajaxify.variables.parse();
|
2014-04-18 13:20:50 -04:00
|
|
|
ajaxify.currentPage = url;
|
2014-03-02 22:51:40 -05:00
|
|
|
|
2014-07-17 15:48:21 -04:00
|
|
|
$window.trigger('action:ajaxify.contentLoaded', {
|
|
|
|
|
url: url
|
|
|
|
|
});
|
|
|
|
|
|
2014-04-07 14:32:17 -04:00
|
|
|
if (window.history && window.history.replaceState) {
|
|
|
|
|
window.history.replaceState({
|
2014-05-16 01:38:20 -04:00
|
|
|
url: url + search + hash
|
2014-05-16 01:55:13 -04:00
|
|
|
}, url, RELATIVE_PATH + '/' + url + search + hash);
|
2014-04-07 14:32:17 -04:00
|
|
|
}
|
|
|
|
|
|
2014-03-11 14:41:32 -04:00
|
|
|
ajaxify.loadScript(tpl_url, function() {
|
2014-07-13 15:38:17 -04:00
|
|
|
ajaxify.widgets.render(tpl_url, url, function() {
|
|
|
|
|
app.processPage();
|
|
|
|
|
$window.trigger('action:ajaxify.end', {
|
2015-01-12 16:57:18 -05:00
|
|
|
url: url,
|
|
|
|
|
tpl_url: tpl_url
|
2014-07-13 15:38:17 -04:00
|
|
|
});
|
2014-03-11 18:46:16 -04:00
|
|
|
});
|
2014-03-11 14:41:32 -04:00
|
|
|
});
|
2014-08-26 11:09:54 -04:00
|
|
|
|
|
|
|
|
socket.removeAllListeners('event:nodebb.ready');
|
|
|
|
|
socket.on('event:nodebb.ready', function(cacheBusters) {
|
|
|
|
|
if (
|
|
|
|
|
!app.cacheBusters ||
|
|
|
|
|
app.cacheBusters.general !== cacheBusters.general ||
|
|
|
|
|
app.cacheBusters.css !== cacheBusters.css ||
|
|
|
|
|
app.cacheBusters.js !== cacheBusters.js
|
|
|
|
|
) {
|
|
|
|
|
app.cacheBusters = cacheBusters;
|
|
|
|
|
|
|
|
|
|
app.alert({
|
|
|
|
|
alert_id: 'forum_updated',
|
|
|
|
|
title: '[[global:updated.title]]',
|
|
|
|
|
message: '[[global:updated.message]]',
|
|
|
|
|
clickfn: function() {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
},
|
|
|
|
|
type: 'warning'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-11-15 14:47:22 -05:00
|
|
|
|
2015-01-07 16:18:38 -05:00
|
|
|
require(['taskbar', 'helpers'], function(taskbar, helpers) {
|
2014-11-15 14:47:22 -05:00
|
|
|
taskbar.init();
|
2015-01-07 16:18:38 -05:00
|
|
|
|
|
|
|
|
// templates.js helpers
|
|
|
|
|
helpers.register();
|
2014-11-15 14:47:22 -05:00
|
|
|
});
|
2014-02-28 16:08:13 -05:00
|
|
|
});
|
2014-03-11 14:41:32 -04:00
|
|
|
};
|
2014-02-28 16:08:13 -05:00
|
|
|
|
2014-12-21 14:36:22 -05:00
|
|
|
function showEmailConfirmWarning() {
|
|
|
|
|
if (config.requireEmailConfirmation && app.user.uid && !app.user['email:confirmed']) {
|
|
|
|
|
app.alert({
|
|
|
|
|
alert_id: 'email_confirm',
|
|
|
|
|
message: '[[error:email-not-confirmed]]',
|
|
|
|
|
type: 'warning',
|
|
|
|
|
timeout: 0,
|
|
|
|
|
clickfn: function() {
|
|
|
|
|
app.removeAlert('email_confirm');
|
|
|
|
|
socket.emit('user.emailConfirm', {}, function(err) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
app.alertSuccess('[[notifications:email-confirm-sent]]');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 09:39:46 -04:00
|
|
|
showWelcomeMessage = window.location.href.indexOf('loggedin') !== -1;
|
2013-08-13 12:58:07 -04:00
|
|
|
|
2015-01-19 16:38:45 -05:00
|
|
|
app.exposeConfigToTemplates();
|
2014-12-19 17:19:29 -05:00
|
|
|
|
|
|
|
|
socketIOConnect();
|
|
|
|
|
|
|
|
|
|
app.cacheBuster = config['cache-buster'];
|
|
|
|
|
|
|
|
|
|
require(['csrf'], function(csrf) {
|
|
|
|
|
csrf.set(config.csrf_token);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bootbox.setDefaults({
|
|
|
|
|
locale: config.userLang
|
|
|
|
|
});
|
|
|
|
|
|
2013-12-05 23:24:47 -05:00
|
|
|
app.alternatingTitle('');
|
2014-06-23 19:45:45 -04:00
|
|
|
|
2014-04-09 13:26:24 +01:00
|
|
|
}());
|