-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupyachka.jquery.js
57 lines (48 loc) · 1.13 KB
/
upyachka.jquery.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*!
upyachka.js 0.3.0 | https://github.com/artpolikarpov/upyachka.js
*/
(function() {
function cure($img) {
if ($img.width() && $img.height()) {
return;
}
var _this = this;
this.$img = $img;
this.style = $img.attr('style');
this.ratio = $img.attr('width') / $img.attr('height');
this.enable();
$img.on('load', function() {
_this.disable();
});
}
cure.prototype = {
fixHeight: function() {
this.$img.css('height', Math.round(this.$img.width() / this.ratio));
},
enable: function() {
this.$img.addClass('upyachka');
this.fixHeight();
$(window).on('resize.upyachka', this.fixHeight);
},
disable: function() {
if (this.style) {
this.$img.attr('style', this.style);
}
else {
this.$img.removeAttr('style');
}
this.enabled = false;
this.$img.removeClass('upyachka');
$(window).off('resize.upyachka');
}
};
$.fn.upyachka = function() {
this.each(function() {
new cure($(this));
});
return this;
};
$(function() {
$('img[width][height][src]').upyachka();
});
})();