Skip to content

Commit

Permalink
hide spinner once liquid is rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
MattBudz committed Jun 4, 2024
1 parent 3401968 commit 499c2ac
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions app/assets/javascripts/tylium/modules/liquid_async.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
document.addEventListener('turbolinks:load', function () {
$('[data-behavior~=liquid-async]').each(function() {
var that = this,
data = { text: $(that).attr('data-content') };
$('[data-behavior~=liquid-async]').each(function () {
const that = this,
data = { text: $(that).attr('data-content') },
$spinner = $(that).prev().find('[data-behavior~=liquid-spinner');

fetch($(that).attr('data-path'), {
method: 'POST',
headers: {
"Accept": "text/html",
"Content-Type": "application/json",
"X-CSRF-Token": $('meta[name="csrf-token"]').attr('content')
Accept: 'text/html',
'Content-Type': 'application/json',
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'),
},
body: JSON.stringify(data)
}).
then(response => response.text()).
then(function(html) {
$(that).html(html);
});
body: JSON.stringify(data),
})
.then((response) => response.text())
.then(function (html) {
$(that).html(html);
$spinner.addClass('d-none');
});
});
});

0 comments on commit 499c2ac

Please sign in to comment.