-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed broken retina_part setting. Wrapped in self executing function …
…(closure)
- Loading branch information
Showing
1 changed file
with
23 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
|