walter/app/views/application/_shepherd.html.erb
2021-10-01 21:30:35 +02:00

79 lines
3.2 KiB
Plaintext

<script>
Walter.tours["<%= tour_name %>"] = new Shepherd.Tour(<%= Rails.configuration.walter.tour_options.html_safe unless Rails.configuration.walter.tour_options.nil? %>);
<% if trigger != 'manual' %>
Walter.tours["<%= tour_name %>"].on("complete", function() {
// Make AJAX call to save history of tour completion
return fetch("/walter_histories/", {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
authenticity_token: '<%= form_authenticity_token %>',
controller_name: '<%= controller_path %>',
action_name: '<%= action_name %>',
tour_name: '<%= tour_name %>'
})
});
});
Walter.tours["<%= tour_name %>"].on("cancel", function() {
Cookies.set('<%= walter_cookie_prefix %>-<%= tour_name %>', 'later', { domain: '<%= walter_domain %>' });
});
<% end %>
<% steps.each_with_index do |(key, step), index| %>
Walter.tours["<%= tour_name %>"].addStep({
id: 'step-<%= key %>',
<% if step.key?('title') %>
title: "<%== step['title'] %>",
<% end %>
text: "<%== step['text'] %>",
<% if step.key?('attachTo') %>
attachTo: { element: "<%= step['attachTo']['element'] %>", on: "<%= step['attachTo']['placement'] %>" },
showOn: function() {
// Only display this step if its selector is present
return document.querySelector("<%= step['attachTo']['element'] %>") ? true : false
},
<% end %>
buttons: [
{ text: '<%= t('walter.exit') %>', action: Walter.tours["<%= tour_name %>"].cancel, classes: 'shepherd-button-secondary' },
<% if index == steps.size - 1 %>
<% if steps.size > 1 %>
{ text: '<%= t('walter.back') %>', action: Walter.tours["<%= tour_name %>"].back, classes: 'shepherd-button-secondary' },
<% end %>
{ text: '<%= t('walter.done') %>', action: Walter.tours["<%= tour_name %>"].complete },
<% else %>
<% if index == 0 %>
{ text: '<%= t('walter.later') %>', action: Walter.tours["<%= tour_name %>"].cancel, classes: 'shepherd-button-secondary' },
<% else %>
{ text: '<%= t('walter.back') %>', action: Walter.tours["<%= tour_name %>"].back, classes: 'shepherd-button-secondary' },
<% end %>
{ text: '<%= t('walter.continue') %>', action: Walter.tours["<%= tour_name %>"].next },
<% end %>
]
});
<% end %>
<% if trigger != "manual" %>
Walter.tours["<%= tour_name %>"].checkAndStart = function (start) {
return function () {
// Don't start the tour if the user dismissed it once this session
var tourMayStart = !Cookies.get('<%= walter_cookie_prefix %>-<%= tour_name %>', {domain: '<%= walter_domain %>'});
<% if steps.first[1]['attachTo'] %>
// Don't start the tour if the first step's element is missing
tourMayStart = tourMayStart && document.querySelector("<%= steps.first[1]['attachTo']['element'] %>");
<% end %>
if (tourMayStart) {
setTimeout(function(){start();}, <%= tour_delay %>); // need to delay this
}
}
}(Walter.tours["<%= tour_name %>"].start)
<% if !tour_completed %>
Walter.incompleteTours.push("<%= tour_name %>");
<% end %>
<% end %>
</script>