Schedule a `blur` on links when the route changes. Also, convert DOM

cleanup tasks to only schedule once per render.
This commit is contained in:
Robin Ward 2014-02-13 15:35:19 -05:00
parent c0686a6dc6
commit 0b6bd5c187
2 changed files with 24 additions and 15 deletions

View File

@ -63,6 +63,9 @@ Discourse.URL = Em.Object.createWithMixins({
path = path.replace(rootURL, '');
}
// Schedule a DOM cleanup event
Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM');
// TODO: Extract into rules we can inject into the URL handler
if (this.navigatedToHome(oldPath, path)) { return; }
if (this.navigatedToListMore(oldPath, path)) { return; }

View File

@ -18,21 +18,7 @@ Discourse.Route = Em.Route.extend({
**/
activate: function() {
this._super();
// 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(); }
Discourse.set('notifyCount',0);
var hideDropDownFunction = $('html').data('hide-dropdown');
if (hideDropDownFunction) { hideDropDownFunction(); }
Em.run.scheduleOnce('afterRender', Discourse.Route, 'cleanDOM');
}
});
@ -48,6 +34,26 @@ Discourse.Route.reopenClass({
};
},
cleanDOM: function() {
// 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(); }
// Remove any link focus
$('a').blur();
Discourse.set('notifyCount',0);
var hideDropDownFunction = $('html').data('hide-dropdown');
if (hideDropDownFunction) { hideDropDownFunction(); }
},
/**
Shows a modal