@ -1,5 +1,5 @@
"use strict" ;
"use strict" ;
/*global io, templates, translator, ajaxify, utils, bootbox, RELATIVE_PATH, config, Visibility*/
/*global io, templates, ajaxify, utils, bootbox, RELATIVE_PATH, config, Visibility*/
var socket ,
var socket ,
app = app || { } ;
app = app || { } ;
@ -310,18 +310,20 @@ app.cacheBuster = null;
titleObj . titles [ 0 ] = window . document . title ;
titleObj . titles [ 0 ] = window . document . title ;
}
}
translator . translate ( title , function ( translated ) {
require ( [ 'translator' ] , function ( translator ) {
titleObj . titles [ 1 ] = translated ;
translator . translate ( title , function ( translated ) {
if ( titleObj . interval ) {
titleObj . titles [ 1 ] = translated ;
clearInterval ( titleObj . interval ) ;
if ( titleObj . interval ) {
}
clearInterval ( titleObj . interval ) ;
titleObj . interval = setInterval ( function ( ) {
var title = titleObj . titles [ titleObj . titles . indexOf ( window . document . title ) ^ 1 ] ;
if ( title ) {
window . document . title = $ ( '<div/>' ) . html ( title ) . text ( ) ;
}
}
} , 2000 ) ;
titleObj . interval = setInterval ( function ( ) {
var title = titleObj . titles [ titleObj . titles . indexOf ( window . document . title ) ^ 1 ] ;
if ( title ) {
window . document . title = $ ( '<div/>' ) . html ( title ) . text ( ) ;
}
} , 2000 ) ;
} ) ;
} ) ;
} ) ;
} else {
} else {
if ( titleObj . interval ) {
if ( titleObj . interval ) {
@ -458,14 +460,6 @@ app.cacheBuster = null;
} ) ;
} ) ;
}
}
function collapseNavigationOnClick ( ) {
$ ( '#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 ( ) {
if ( $ ( '.navbar .navbar-collapse' ) . hasClass ( 'in' ) ) {
$ ( '.navbar-header button' ) . click ( ) ;
}
} ) ;
}
function handleStatusChange ( ) {
function handleStatusChange ( ) {
$ ( '#user-control-list .user-status' ) . off ( 'click' ) . on ( 'click' , function ( e ) {
$ ( '#user-control-list .user-status' ) . off ( 'click' ) . on ( 'click' , function ( e ) {
var status = $ ( this ) . attr ( 'data-status' ) ;
var status = $ ( this ) . attr ( 'data-status' ) ;
@ -479,19 +473,39 @@ app.cacheBuster = null;
} ) ;
} ) ;
}
}
function handleNewTopic ( ) {
$ ( '#content' ) . on ( 'click' , '#new_topic' , function ( ) {
require ( [ 'composer' ] , function ( composer ) {
var cid = ajaxify . variables . get ( 'category_id' ) ;
if ( cid ) {
composer . newTopic ( cid ) ;
} else {
socket . emit ( 'categories.getCategoriesByPrivilege' , 'topics:create' , function ( err , categories ) {
if ( err ) {
return app . alertError ( err . message ) ;
}
if ( categories . length ) {
composer . newTopic ( categories [ 0 ] . cid ) ;
}
} ) ;
}
} ) ;
} ) ;
}
app . load = function ( ) {
app . load = function ( ) {
$ ( 'document' ) . ready ( function ( ) {
$ ( 'document' ) . ready ( function ( ) {
var url = ajaxify . start ( window . location . pathname . slice ( 1 ) , true , window . location . search ) ;
var url = ajaxify . start ( window . location . pathname . slice ( 1 ) , true , window . location . search ) ;
ajaxify . end ( url , app . template ) ;
ajaxify . end ( url , app . template ) ;
collapseNavigationOnClick ( ) ;
handleStatusChange ( ) ;
handleStatusChange ( ) ;
if ( config . searchEnabled ) {
if ( config . searchEnabled ) {
handleSearch ( ) ;
handleSearch ( ) ;
}
}
handleNewTopic ( ) ;
$ ( '#logout-link' ) . on ( 'click' , app . logout ) ;
$ ( '#logout-link' ) . on ( 'click' , app . logout ) ;
Visibility . change ( function ( e , state ) {
Visibility . change ( function ( e , state ) {