javascript - Coffee Script not fire on page change, but works on page load. [Rails 5] -
i using coffee script in rails project, problem works when load(refresh) page instead when page renders, should work on page view change.
here script using:
facebook.js.coffee
jquery -> $('body').prepend('<div id="fb-root"></div>') $.ajax url: "#{window.location.protocol}//connect.facebook.net/en_us/all.js" datatype: 'script' cache: true window.fbasyncinit = -> fb.init(appid: env["app_id"], cookie: true) $('#sign_in').click (e) -> e.preventdefault() fb.login (response) -> window.location = '/auth/facebook/callback' if response.authresponse $('#sign_out').click (e) -> fb.getloginstatus (response) -> fb.logout() if response.authresponse true
you can try "turoblinks:load"
ready = -> $('body').prepend('<div id="fb-root"></div>') $.ajax url: "#{window.location.protocol}//connect.facebook.net/en_us/all.js" datatype: 'script' cache: true window.fbasyncinit = -> fb.init(appid: env["app_id"], cookie: true) $('#sign_in').click (e) -> e.preventdefault() fb.login (response) -> window.location = '/auth/facebook/callback' if response.authresponse $('#sign_out').click (e) -> fb.getloginstatus (response) -> fb.logout() if response.authresponse true $(document).on('turbolinks:load', ready)
Comments
Post a Comment