2014-03-12 18:30:13 -04:00
"use strict" ;
2015-02-25 19:15:02 -05:00
/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH, config, Visibility*/
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 ;
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 ,
2015-03-10 11:52:32 -04:00
reconnectionDelay : config . reconnectionDelay ,
2014-12-19 17:19:29 -05:00
transports : config . socketioTransports ,
path : config . relative _path + '/socket.io'
} ;
2015-03-10 11:52:32 -04:00
socket = io ( config . websocketAddress , ioParams ) ;
2014-12-19 17:19:29 -05:00
reconnecting = false ;
2015-02-11 12:54:54 -05:00
socket . on ( 'event:connect' , function ( ) {
2014-12-19 17:19:29 -05:00
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
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 ) ;
} ) ;
2015-02-20 15:07:43 -05:00
socket . on ( 'event:alert' , function ( data ) {
app . alert ( data ) ;
} ) ;
2015-03-10 11:52:32 -04:00
socket . on ( 'reconnect_failed' , function ( ) {
// Wait ten times the reconnection delay and then start over
setTimeout ( socket . connect . bind ( socket ) , parseInt ( config . reconnectionDelay , 10 ) * 10 ) ;
} ) ;
2014-12-19 17:19:29 -05:00
}
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 ,
2015-02-11 12:54:54 -05:00
username : app . user . username ,
userslug : app . user . userslug ,
picture : app . user . 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' ) ;
2015-02-11 12:54:54 -05:00
if ( href && app . user . userslug && href . indexOf ( 'user/_self_' ) !== - 1 ) {
$ ( this ) . attr ( 'href' , href . replace ( /user\/_self_/g , 'user/' + app . user . 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' ,
2015-02-11 12:54:54 -05:00
title : '[[global:welcome_back]] ' + app . user . username + '!' ,
2014-02-16 11:36:11 -05:00
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 ) {
2015-02-11 12:54:54 -05:00
if ( username === app . user . 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
2015-02-11 12:54:54 -05:00
if ( ! app . user . 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 ] ) ;
}
}
} ) ;
2015-02-25 19:15:02 -05:00
} ;
2014-05-06 18:42:38 -04:00
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-02-07 20:00:07 -05:00
search . query ( { term : input . val ( ) } , 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 ( ) {
2015-02-26 10:08:48 -05:00
$ ( '#nav-dropdown' ) . off ( 'click' ) . on ( 'click' , '#main-nav a, #user-control-list a, #logged-out-menu li a, #logged-in-menu .visible-xs, #chat-list a' , 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 ( ) {
2015-03-07 13:52:02 -05:00
var url = ajaxify . start ( window . location . pathname . slice ( 1 ) , true , window . location . search ) ;
2015-03-07 00:25:55 -05:00
ajaxify . end ( url , app . template ) ;
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-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
2015-03-11 13:32:28 -04:00
function showEmailConfirmWarning ( err ) {
2015-02-23 13:39:17 -05:00
if ( ! config . requireEmailConfirmation || ! app . user . uid ) {
return ;
}
if ( ! app . user . email ) {
app . alert ( {
alert _id : 'email_confirm' ,
message : '[[error:no-email-to-confirm]]' ,
type : 'warning' ,
timeout : 0 ,
clickfn : function ( ) {
app . removeAlert ( 'email_confirm' ) ;
ajaxify . go ( 'user/' + app . user . userslug + '/edit' ) ;
}
} ) ;
} else if ( ! app . user [ 'email:confirmed' ] ) {
2014-12-21 14:36:22 -05:00
app . alert ( {
alert _id : 'email_confirm' ,
2015-03-11 13:32:28 -04:00
message : err ? err . message : '[[error:email-not-confirmed]]' ,
2014-12-21 14:36:22 -05:00
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
} ( ) ) ;