@@ -52,6 +52,7 @@ var Polyglot = require('node-polyglot'),
5252 ServerConnectModal = require ( './views/serverConnectModal' ) ,
5353 OnboardingModal = require ( './views/onboardingModal' ) ,
5454 PageConnectModal = require ( './views/pageConnectModal' ) ,
55+ Dialog = require ( './views/dialog.js' ) ,
5556 loadProfileNeeded = true ,
5657 startUpConnectMaxRetries = 2 ,
5758 startUpConnectRetryDelay = 2 * 1000 ,
@@ -107,6 +108,11 @@ updatePolyglot = function(lang){
107108} ;
108109
109110user . on ( 'change:language' , function ( md , lang ) {
111+ // Re-starting the app on lang change. For now leaving in the code in various global views
112+ // that deals with lang change.
113+ // TODO: Once it looks like the restart on lang change approach is fine, go into the different
114+ // views and cleanup any code dealing with lang change.
115+
110116 updatePolyglot ( lang ) ;
111117} ) ;
112118
@@ -341,9 +347,16 @@ $(window).bind('keydown', function(e) {
341347
342348 if ( route !== null ) {
343349 e . preventDefault ( ) ;
344- Backbone . history . navigate ( route , {
345- trigger : true
346- } ) ;
350+
351+ if ( location . hash . startsWith ( '#' + route ) ) {
352+ // Hard refresh if we're already on the page we're trying to route to
353+ // so a cached page is not served.
354+ app . router . refresh ( ) ;
355+ } else {
356+ Backbone . history . navigate ( route , {
357+ trigger : true
358+ } ) ;
359+ }
347360 }
348361 }
349362} ) ;
@@ -444,7 +457,40 @@ var loadProfile = function(landingRoute, onboarded) {
444457 app . simpleMessageModal . remove = ( ) => {
445458 throw new Error ( 'This instance of the simpleMessageModal is globally shared ' +
446459 'and should not be removed. When you are done with it, please close it.' ) ;
447- } ;
460+ } ;
461+
462+ // any lang changes after our app has loaded will need an app re-start to fully take effect
463+ user . on ( 'change:language' , function ( md , lang ) {
464+ var restartWarning ;
465+
466+ restartWarning = new Dialog ( {
467+ title : window . polyglot . t ( 'langChangeRestartTitle' ) ,
468+ message : window . polyglot . t ( 'langChangeRestartMessage' ) ,
469+ buttons : [ {
470+ text : 'Restart Later' ,
471+ fragment : 'restart-later'
472+ } , {
473+ text : 'Restart Now' ,
474+ fragment : 'restart-now'
475+ } ]
476+ } ) . on ( 'click-restart-later' , ( ) => {
477+ restartWarning . close ( ) ;
478+ } ) . on ( 'click-restart-now' , ( ) => {
479+ location . reload ( ) ;
480+ } ) . render ( ) . open ( ) ;
481+ } ) ;
482+
483+ // If navigating to a page you're already on, we'll hard refresh so
484+ // a cached page is not served, which avoids the issue of it looking
485+ // like nothing happened.
486+ $ ( document ) . on ( 'click' , '[href^="#"]' , ( e ) => {
487+ var href = $ ( e . target ) . attr ( 'href' ) ;
488+
489+ if ( location . hash . startsWith ( href ) ) {
490+ app . router . refresh ( ) ;
491+ e . preventDefault ( ) ;
492+ }
493+ } ) ;
448494
449495 app . router = new router ( { userModel : user , userProfile : userProfile , socketView : newSocketView } ) ;
450496
0 commit comments