user3824647
user3824647

Reputation: 37

ember where to put jquery ready-function?

i have a problem getting Ember into an existing website-template.

Some visual effects of the website are javascript-based and have to be initialized. The static html-version of the web-design uses the a script-tag with the following code

jQuery(document).ready(function() {
    Main.init();
});

In case loading the website direct to a route (e.g. call localhost:9000/#/content/web) the visual-effects do not work. If i load the page to its root (where i don't have defined content to be shown by ember yet) everything is okay (even if i click on a link-to /content/web, the content is shown correctly).

Cause the init-script is placed at the pages end, i guess the content which is shown through ember-logic prevent its execution.

Does anyone know how to place such init-sequences the right way with ember?

Upvotes: 2

Views: 857

Answers (1)

blessanm86
blessanm86

Reputation: 31779

Like @CodeJack mentioned you should probably Create a view and override the 'didInsertElement' hook. Jquery pluging should be wrapped in views. It makes it easier to cleanup the plugin when the view is removed.

That said, ember js does have a ready event that is fired once the dom is ready. You can use it like

Ember.Application.create({
  ready: function() {
    //do ur initialization.
  }
});

Upvotes: 1

Related Questions