FIX: `cleanDOM` couldn't be called from `url`

This commit is contained in:
Robin Ward 2016-10-26 13:27:47 -04:00
parent eeee5f4c08
commit 3bb4e22692
4 changed files with 34 additions and 37 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -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;