Plugin: performing DOM manipulation on pages

I would like to run jQuery operations on Disourse topic pages from my plugin, but I cannot find a hook that fires after a topic page is displayed.

I’ve tried route:didTransition, route:setupController, component:didInsertElement, adding nested Ember.run.schedule('afterRender') and Ember.run.next(), but they all fire before the display occurs.

(to be more precise, they fire after display when refreshing the browser, but before display when changing route thereafter).

I could go with setTimeout(1000), but I’m sure there’s a clean way… Anybody on this?

1 Like

It’s a little tricky depending on what you are trying to do. For example, scrolling a topic will change its DOM, as will interacting with it via various buttons.

If you only want to apply some jQuery to a topic after it’s been rendered and that will work for you, you could try reopening the discourse-topic component and adding a lifecycle callbackwillRender should work.

4 Likes

Thanks a million, willRender and didRender seem to work!

1 Like