Skip to content

Commit

Permalink
Fix: Non-destructive replaceWith for imageReady (fixes #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Sep 5, 2023
2 parents a7540e2 + df56e15 commit c0f5e4a
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 c0f5e4a

Please sign in to comment.