mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
Run cleanDOM
even when swapping out models
This commit is contained in:
parent
513d755d08
commit
42f2cd83db
@ -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();
|
||||
|
||||
|
@ -17,18 +17,62 @@ 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);
|
||||
_refreshTitleOnce: function() {
|
||||
this.send('_collectTitleTokens', []);
|
||||
},
|
||||
|
||||
_cleanDOM() {
|
||||
actions: {
|
||||
|
||||
_collectTitleTokens: function(tokens) {
|
||||
// If there's a title token method, call it and get the token
|
||||
if (this.titleToken) {
|
||||
const t = this.titleToken();
|
||||
if (t && t.length) {
|
||||
if (t instanceof Array) {
|
||||
t.forEach(function(ti) {
|
||||
tokens.push(ti);
|
||||
});
|
||||
} else {
|
||||
tokens.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
refreshTitle: function() {
|
||||
Ember.run.once(this, this._refreshTitleOnce);
|
||||
}
|
||||
},
|
||||
|
||||
redirectIfLoginRequired: function() {
|
||||
const app = this.controllerFor('application');
|
||||
if (app.get('loginRequired')) {
|
||||
this.replaceWith('login');
|
||||
}
|
||||
},
|
||||
|
||||
openTopicDraft: function(model){
|
||||
// If there's a draft, open the create topic composer
|
||||
if (model.draft) {
|
||||
const composer = this.controllerFor('composer');
|
||||
if (!composer.get('model.viewOpen')) {
|
||||
composer.open({
|
||||
action: Discourse.Composer.CREATE_TOPIC,
|
||||
draft: model.draft,
|
||||
draftKey: model.draft_key,
|
||||
draftSequence: model.draft_sequence
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
isPoppedState: function(transition) {
|
||||
return (!transition._discourse_intercepted) && (!!transition.intent.url);
|
||||
}
|
||||
});
|
||||
|
||||
export function cleanDOM() {
|
||||
// Close mini profiler
|
||||
$('.profiler-results .profiler-result').remove();
|
||||
|
||||
@ -49,67 +93,12 @@ const DiscourseRoute = Ember.Route.extend({
|
||||
|
||||
Discourse.set('notifyCount',0);
|
||||
$('#discourse-modal').modal('hide');
|
||||
var hideDropDownFunction = $('html').data('hide-dropdown');
|
||||
const hideDropDownFunction = $('html').data('hide-dropdown');
|
||||
if (hideDropDownFunction) { hideDropDownFunction(); }
|
||||
|
||||
// TODO: Avoid container lookup here
|
||||
var appEvents = Discourse.__container__.lookup('app-events:main');
|
||||
const appEvents = Discourse.__container__.lookup('app-events:main');
|
||||
appEvents.trigger('dom:clean');
|
||||
},
|
||||
|
||||
_refreshTitleOnce: function() {
|
||||
this.send('_collectTitleTokens', []);
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
||||
_collectTitleTokens: function(tokens) {
|
||||
// If there's a title token method, call it and get the token
|
||||
if (this.titleToken) {
|
||||
var t = this.titleToken();
|
||||
if (t && t.length) {
|
||||
if (t instanceof Array) {
|
||||
t.forEach(function(ti) {
|
||||
tokens.push(ti);
|
||||
});
|
||||
} else {
|
||||
tokens.push(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
refreshTitle: function() {
|
||||
Ember.run.once(this, this._refreshTitleOnce);
|
||||
}
|
||||
},
|
||||
|
||||
redirectIfLoginRequired: function() {
|
||||
var app = this.controllerFor('application');
|
||||
if (app.get('loginRequired')) {
|
||||
this.replaceWith('login');
|
||||
}
|
||||
},
|
||||
|
||||
openTopicDraft: function(model){
|
||||
// If there's a draft, open the create topic composer
|
||||
if (model.draft) {
|
||||
var composer = this.controllerFor('composer');
|
||||
if (!composer.get('model.viewOpen')) {
|
||||
composer.open({
|
||||
action: Discourse.Composer.CREATE_TOPIC,
|
||||
draft: model.draft,
|
||||
draftKey: model.draft_key,
|
||||
draftSequence: model.draft_sequence
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
isPoppedState: function(transition) {
|
||||
return (!transition._discourse_intercepted) && (!!transition.intent.url);
|
||||
}
|
||||
});
|
||||
|
||||
export default DiscourseRoute;
|
||||
|
Loading…
Reference in New Issue
Block a user