0

I'm using this snippet to show a spinner once a link is clicked. Some times the link .ln-edit-task is loaded via Ajax, and the snippet breaks. How do I make it work on Ajax loaded content?

jQuery(document).on("ready page:change", function() {
  return $(".ln-destroy-task").on("confirm:complete", function(e, response) {
    if (response) {
      return showSpinner($(this));
    }
  });
});
showSpinner = function(el) {
  return el.find(".fa").removeClass().addClass("fa fa-spinner fa-spin");
};

Note that page:change is required by Turbolinks in Rails.

Jumbalaya Wanton
  • 1,601
  • 1
  • 25
  • 47

1 Answers1

3

Try

$(document).on("confirm:complete", ".ln-destroy-task", function (e, response) {
    if (response) {
        return showSpinner($(this));
    }
});
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531