From 3bb4e226921ae21bed12847db585c6d3486400a4 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 26 Oct 2016 13:27:47 -0400 Subject: [PATCH] FIX: `cleanDOM` couldn't be called from `url` --- .../initializers/page-tracking.js.es6 | 7 ++-- .../discourse/lib/clean-dom.js.es6 | 32 +++++++++++++++++++ .../javascripts/discourse/lib/url.js.es6 | 3 -- .../discourse/routes/discourse.js.es6 | 29 ----------------- 4 files changed, 34 insertions(+), 37 deletions(-) create mode 100644 app/assets/javascripts/discourse/lib/clean-dom.js.es6 diff --git a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 index 7e744a7de96..cf978f43006 100644 --- a/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 +++ b/app/assets/javascripts/discourse/initializers/page-tracking.js.es6 @@ -1,4 +1,4 @@ -import { cleanDOM } from 'discourse/routes/discourse'; +import { cleanDOM } from 'discourse/lib/clean-dom'; import { startPageTracking, onPageChange } from 'discourse/lib/page-tracker'; import { viewTrackingRequired } from 'discourse/lib/ajax'; @@ -10,10 +10,7 @@ export default { // Tell our AJAX system to track a page transition const router = container.lookup('router:main'); router.on('willTransition', viewTrackingRequired); - - router.on('didTransition', function() { - Em.run.scheduleOnce('afterRender', Ember.Route, cleanDOM); - }); + router.on('didTransition', cleanDOM); startPageTracking(router); diff --git a/app/assets/javascripts/discourse/lib/clean-dom.js.es6 b/app/assets/javascripts/discourse/lib/clean-dom.js.es6 new file mode 100644 index 00000000000..8f86e6a6fd7 --- /dev/null +++ b/app/assets/javascripts/discourse/lib/clean-dom.js.es6 @@ -0,0 +1,32 @@ +function _clean() { + if (window.MiniProfiler) { + window.MiniProfiler.pageTransition(); + } + + // Close some elements that may be open + $('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 + $(document.activeElement).not("body").not(".no-blur").blur(); + + Discourse.set('notifyCount',0); + Discourse.__container__.lookup('route:application').send('closeModal'); + 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 function cleanDOM() { + Ember.run.scheduleOnce('afterRender', _clean); +} diff --git a/app/assets/javascripts/discourse/lib/url.js.es6 b/app/assets/javascripts/discourse/lib/url.js.es6 index 8101a2a7d33..7621ae4ce98 100644 --- a/app/assets/javascripts/discourse/lib/url.js.es6 +++ b/app/assets/javascripts/discourse/lib/url.js.es6 @@ -168,9 +168,6 @@ const DiscourseURL = Ember.Object.extend({ if (this.navigatedToPost(oldPath, path, opts)) { return; } - // Schedule a DOM cleanup event - Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM'); - if (oldPath === path) { // If navigating to the same path send an app event. Views can watch it // and tell their controllers to refresh diff --git a/app/assets/javascripts/discourse/routes/discourse.js.es6 b/app/assets/javascripts/discourse/routes/discourse.js.es6 index 8b4c7b8465d..8b3d3bbc310 100644 --- a/app/assets/javascripts/discourse/routes/discourse.js.es6 +++ b/app/assets/javascripts/discourse/routes/discourse.js.es6 @@ -74,33 +74,4 @@ const DiscourseRoute = Ember.Route.extend({ } }); -export function cleanDOM() { - if (window.MiniProfiler) { - window.MiniProfiler.pageTransition(); - } - - // Close some elements that may be open - $('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 - $(document.activeElement).not("body").not(".no-blur").blur(); - - Discourse.set('notifyCount',0); - Discourse.__container__.lookup('route:application').send('closeModal'); - 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;