MattKetmo / darkroomjs

Extensible image editing tool in your browser
https://mattketmo.github.io/darkroomjs
MIT License
1.42k stars 405 forks source link

image.onload from selfDestroy() should be unbound after being called #51

Closed francislavoie closed 6 years ago

francislavoie commented 9 years ago

Currently, if the src of the image is changed again, the bound onload call will be called again, which results in an error because replaceChild won't work after already being destroyed.

This is the fix I implemented, not sure if there's a more ideal way.

image.onload = function() {
  container.parentNode.replaceChild(image, container);
  this.onload = null;
}
digz6666 commented 9 years ago

I called darkroom.selfDestroy() but the container.parentNode is not defined and it throws exception. I added null check and your fix works for me.

image.onload = function() {
  if (container.parentNode) {
    container.parentNode.replaceChild(image, container);
  }
  this.onload = null;
}