Search code examples
javascriptruby-on-railsrubytemplatesturbolinks

I'm adding a free w3layout templates and javascript runs twice in rails 4.2 app


I'm adding a free w3layout template Link to template to my new rails 4.2 app and when I put all files in their places it seems that the javascript event runs twice. It is visible when you reload the page (F5).

I think the reason why - is this code below and also turbolinks. But without it the event runs once and immediately to all parts of template. The question is - How can I manage these .js files to only run once, but smoothly. I'm not very good at javascript.

<!--animate-->
    <script>
        new WOW().init();
    </script>
<!--//end-animate-->

All js files I put in app/assets/javascript

Here's the link to full github project. And this is application.html.erb where I think all the problems are. App runs locally.


Solution

  • I found the solution. The problem was not in the

    <!--animate--> <script> new WOW().init(); </script> <!--//end-animate-->

    The reason was in this code

    <!-- Placed at the end of the document so the pages load faster -->
    <script src="js/bootstrap.js"></script>
    

    It was at the end of the template so I don't seen it at once.