Skip to content

Commit

Permalink
Fix: Nondestructive replaceWith for imageReady (fixes #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster committed Sep 5, 2023
1 parent a7540e2 commit df56e15
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/adapt-graphicLottie.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ class GraphicLottie extends Backbone.Controller {
const $img = $(img);
const div = document.createElement('div');
const $div = $(div);
$img.replaceWith($div);

// Do replaceWith using detach instead of remove to preserve
// imageready event listeners
const $parent = $img.parent();
const previousSibling = $img[0].previousSibling;
$img.detach();
if (!previousSibling) $parent.prepend($div);
else $div.insertAfter(previousSibling);

const lottieView = div.lottieView = new LottieView({
el: div,
replacedEl: img
Expand Down

0 comments on commit df56e15

Please sign in to comment.