diff --git a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 index caa1290e0e1..1899879943f 100644 --- a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 +++ b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 @@ -1,6 +1,5 @@ -/** - Sets up the PageTracking hook. -**/ +import { cleanDOM } from 'discourse/routes/discourse'; + export default { name: "page-tracking", after: 'register-discourse-location', @@ -13,6 +12,10 @@ export default { Discourse.viewTrackingRequired(); }); + router.on('didTransition', function() { + Em.run.scheduleOnce('afterRender', Ember.Route, cleanDOM); + }); + var pageTracker = Discourse.PageTracker.current(); pageTracker.start(); diff --git a/app/assets/javascripts/discourse/routes/discourse.js.es6 b/app/assets/javascripts/discourse/routes/discourse.js.es6 index 62c7b652dc9..bc7d283d03a 100644 --- a/app/assets/javascripts/discourse/routes/discourse.js.es6 +++ b/app/assets/javascripts/discourse/routes/discourse.js.es6 @@ -17,46 +17,6 @@ const DiscourseRoute = Ember.Route.extend({ } }, - /** - NOT called every time we enter a route on Discourse. - Only called the FIRST time we enter a route. - So, when going from one topic to another, activate will only be called on the - TopicRoute for the first topic. - **/ - activate: function() { - this._super(); - Em.run.scheduleOnce('afterRender', Ember.Route, this._cleanDOM); - }, - - _cleanDOM() { - // Close mini profiler - $('.profiler-results .profiler-result').remove(); - - // Close some elements that may be open - $('.d-dropdown').hide(); - $('header ul.icons li').removeClass('active'); - $('[data-toggle="dropdown"]').parent().removeClass('open'); - // close the lightbox - if ($.magnificPopup && $.magnificPopup.instance) { - $.magnificPopup.instance.close(); - $('body').removeClass('mfp-zoom-out-cur'); - } - - // Remove any link focus - // NOTE: the '.not("body")' is here to prevent a bug in IE10 on Win7 - // cf. https://stackoverflow.com/questions/5657371/ie9-window-loses-focus-due-to-jquery-mobile - $(document.activeElement).not("body").blur(); - - Discourse.set('notifyCount',0); - $('#discourse-modal').modal('hide'); - var hideDropDownFunction = $('html').data('hide-dropdown'); - if (hideDropDownFunction) { hideDropDownFunction(); } - - // TODO: Avoid container lookup here - var appEvents = Discourse.__container__.lookup('app-events:main'); - appEvents.trigger('dom:clean'); - }, - _refreshTitleOnce: function() { this.send('_collectTitleTokens', []); }, @@ -66,7 +26,7 @@ const DiscourseRoute = Ember.Route.extend({ _collectTitleTokens: function(tokens) { // If there's a title token method, call it and get the token if (this.titleToken) { - var t = this.titleToken(); + const t = this.titleToken(); if (t && t.length) { if (t instanceof Array) { t.forEach(function(ti) { @@ -86,7 +46,7 @@ const DiscourseRoute = Ember.Route.extend({ }, redirectIfLoginRequired: function() { - var app = this.controllerFor('application'); + const app = this.controllerFor('application'); if (app.get('loginRequired')) { this.replaceWith('login'); } @@ -95,7 +55,7 @@ const DiscourseRoute = Ember.Route.extend({ openTopicDraft: function(model){ // If there's a draft, open the create topic composer if (model.draft) { - var composer = this.controllerFor('composer'); + const composer = this.controllerFor('composer'); if (!composer.get('model.viewOpen')) { composer.open({ action: Discourse.Composer.CREATE_TOPIC, @@ -112,4 +72,33 @@ const DiscourseRoute = Ember.Route.extend({ } }); +export function cleanDOM() { + // Close mini profiler + $('.profiler-results .profiler-result').remove(); + + // Close some elements that may be open + $('.d-dropdown').hide(); + $('header ul.icons li').removeClass('active'); + $('[data-toggle="dropdown"]').parent().removeClass('open'); + // close the lightbox + if ($.magnificPopup && $.magnificPopup.instance) { + $.magnificPopup.instance.close(); + $('body').removeClass('mfp-zoom-out-cur'); + } + + // Remove any link focus + // NOTE: the '.not("body")' is here to prevent a bug in IE10 on Win7 + // cf. https://stackoverflow.com/questions/5657371/ie9-window-loses-focus-due-to-jquery-mobile + $(document.activeElement).not("body").blur(); + + Discourse.set('notifyCount',0); + $('#discourse-modal').modal('hide'); + const hideDropDownFunction = $('html').data('hide-dropdown'); + if (hideDropDownFunction) { hideDropDownFunction(); } + + // TODO: Avoid container lookup here + const appEvents = Discourse.__container__.lookup('app-events:main'); + appEvents.trigger('dom:clean'); +} + export default DiscourseRoute;