V
V
Vyacheslav Soldatov2016-03-09 22:32:54
JavaScript
Vyacheslav Soldatov, 2016-03-09 22:32:54

What is the correct way to use turbolinks in rails?

Good afternoon. Rails 4.2.5. I'm struggling with turbolink. Tell me how to correctly connect third-party JS scripts or call a function in application.js so that it runs once, when the page is fully loaded.
For example, in the footer, I throw a dialer service that runs twice:

<script type="text/javascript" src="//cdn.dozvonзкшьук.com/widget/js/dzv.js?przv_code=8355e"></script>

Or in application.js I want to call a function only on page reload.
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require turbolinks
//= require_tree .

$(document).on('page:change', function() {
    console.log('Выполняется один раз при полной загрузке страницы, а не два как сейчас при работе турболинка');
});

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
TyzhSysAdmin, 2016-03-10
@POS_troi

A great idea for solving turbolink problems is to demolish it immediately when creating a project.
Well, this is my IMHO;)
PS https://github.com/turbolinks/turbolinks-classic#events

D
Dmitry, 2016-07-26
@svetozar

I make a function and pass it to $(document).ready(...) and $(document).on('page:load', ...)
ready_service = function() {
return $('#start_registration_link'). on('click', function(event) {
return $('#registration-block').addClass('fullscreen');
});
};
$(document).ready(ready_service);
$(document).on('page:load', ready_service);
here is more details - https://habrahabr.ru/post/167161/

D
drtrem, 2017-04-20
@drtrem

$(document).on('turbolinks:load', function() {
function body
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question