-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimg2x.js
42 lines (32 loc) · 814 Bytes
/
img2x.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* img2x v1.00
* img2x is a jQuery plugin designed to replace
* standard resolution images with their @2x
* counterpart.
*/
(function($) {
$.fn.img2x = function(settingsOptions) {
var settings = {},
settingsDefault = {
className: 'img2x',
fileTypes: ['.png', '.gif', '.jpg']
};
settings = jQuery.extend(settings, settingsDefault, settingsOptions);
var elements = this.filter('.' + settings.className),
is2x = false;
if (elements.css('font-size') == '1px') {
is2x = true;
}
return (
elements.each(function(index) {
if (is2x) {
var img = $(this),
src = img.attr('src'),
re = new RegExp('(' + settings.fileTypes.join('|') + ')', 'ig');
src = src.replace(re, '@2x$1');
img.attr('src', src);
}
})
);
};
})(jQuery);