mcilvena/jQuery-Retina-Display-Plugin — pull request #2 by mattbilson (2011-10-29 06:09:05+00:00)
Title: Phonegap support and ajax request optimisation

First up - great jquery plugin! Thank you.

However, I began having issues when using with PhoneGap (http://phonegap.com/) and when adding extra images to the page after having called retina().

After having called retina(), added content to the page, I called the retina() function again.
I didn't specify a custom selector for the new elements - partly for simplicity, but also because there was some old content being removed from the DOM and added back in alongside the brand new elements, meaning I was unable to use the parent selector - I would have to have added a new class to the new elements and then repeated this, adding extra classes, every time the content on the page changed.

I can see that ordinarily on calling the retina() function multiple times, the ajax call is made, the image isn't found and the image isn't replaced.
However with PhoneGap, it seems the ajax request is handled differently (maybe due to the request being made from within a mobile app), and seems to succeed - the image becomes suffixed with -2x-2x.jpg, -2x-2x-2x.jpg etc etc.

This commit fixes this issue, and also reduces the number of ajax requests which are made to check if the image exists for any situtation where retina() is called numerous times.
It does mean that a normal, non-retina image (which needs switching), can't be named with -2x as the new if statement will catch it, and it will not be switched. However this seems rare (not to mention extremely confusing if you have non-retina images named with -2x.jpg and want to use this plugin :) ), and if needed in this case, retina_part can be changed accordingly.

Let me know what you think,
Matt