Skip to content

Commit

Permalink
Fixed broken retina_part setting. Wrapped in self executing function …
Browse files Browse the repository at this point in the history
…(closure)
  • Loading branch information
mcilvena committed Nov 10, 2010
1 parent 709c39a commit a602b7f
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions jquery.retina.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
/*
Author: Troy Mcilvena (http://troymcilvena.com)
Twitter: @mcilvena
Date: 27 August 2010
Version: 1.1
Date: 10 November 2010
Version: 1.2
Revision History:
1.0 (23/08/2010) - Initial release.
1.1 (27/08/2010) - Made plugin chainable
1.2 (10/11/2010) - Fixed broken retina_part setting. Wrapped in self executing function (closure)
*/

jQuery.fn.retina = function(retina_part) {
// Set default retina file part to '-2x'
// Eg. some_image.jpg will become some_image-2x.jpg
var settings = {'retina_part': '-2x'};
if(retina_part) jQuery.extend(config, settings);

if(window.devicePixelRatio >= 2) {
this.each(function(index, element) {
if(!$(element).attr('src')) return;

var new_image_src = $(element).attr('src').replace(/(.+)(\.\w{3,4})$/, "$1"+ settings['retina_part'] +"$2");
$.ajax({url: new_image_src, type: "HEAD", success: function() {
$(element).attr('src', new_image_src);
}});
});
(function( $ ){
$.fn.retina = function(retina_part) {
// Set default retina file part to '-2x'
// Eg. some_image.jpg will become some_image-2x.jpg
var settings = {'retina_part': '-2x'};
if(retina_part) jQuery.extend(settings, { 'retina_part': retina_part });

if(window.devicePixelRatio >= 2) {
this.each(function(index, element) {
if(!$(element).attr('src')) return;

var new_image_src = $(element).attr('src').replace(/(.+)(\.\w{3,4})$/, "$1"+ settings['retina_part'] +"$2");
$.ajax({url: new_image_src, type: "HEAD", success: function() {
$(element).attr('src', new_image_src);
}});
});
}
return this;
}
return this;
}
})( jQuery );

0 comments on commit a602b7f

Please sign in to comment.