Skip to content

Commit

Permalink
Fixed spinners in Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
tg666 committed Aug 11, 2022
1 parent 11c3f93 commit 6a49a4c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions assets/js/ajax-spinner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

(function () {
const showed = [];

const findSpinner = el => {
if ('self' === el.data('spinner-for')) {
return el;
Expand All @@ -18,11 +20,21 @@
};

const show = spinner => {
spinner && spinner.addClass('spinner');
spinner && spinner.addClass('spinner') && showed.push(spinner);
};

const hide = spinner => {
spinner && spinner.removeClass('spinner');
if (!spinner) {
return;
}

spinner.removeClass('spinner');

for (let i in showed) {
if (showed[i] === spinner) {
showed.splice(i, 1);
}
}
};

$.nette.ext('plugin-spinner', {
Expand Down Expand Up @@ -59,4 +71,12 @@
$(document).on('click', 'a:not(.ajax)', function () {
show(findSpinner($(this)));
});

window.addEventListener('pageshow', function (e) {
if (e.persisted) {
for (let i in showed) {
hide(showed[i]);
}
}
});
})();

0 comments on commit 6a49a4c

Please sign in to comment.