thdoan / magnify

A lightweight jQuery magnifying glass zoom plugin.
https://thdoan.github.io/magnify/
MIT License
243 stars 63 forks source link

Problem when image is not found #29

Closed gpetrioli closed 7 years ago

gpetrioli commented 7 years ago

When the image is not found the code that wraps the image in the <div class="magnify"></div> is not run (since that code is executed on the load event of the image).

But on resize the destroy is executed which unwraps the image. The code uses .unwrap('.magnify'), but using a selector is only introduced in jQuery v3.0 (https://api.jquery.com/unwrap/#unwrap-selector)

gpetrioli commented 7 years ago

Perhaps a solution would be to use replaceWith on the parent element if it is .magnify

thdoan commented 7 years ago

Thanks, good catch. I don't use v3 myself, which still works in most cases since jQuery probably just ignores the unwrap() selector for v1 and v2, until we encounter the scenario you mentioned.

I will also add logic to skip destroying the zoom if the image has no zoom to begin with.