Show More
@@ -31,6 +31,8 var IMAGE_VIEWERS = [ | |||
|
31 | 31 | |
|
32 | 32 | var FULL_IMG_CLASS = 'post-image-full'; |
|
33 | 33 | |
|
34 | var ATTR_SCALE = 'scale'; | |
|
35 | ||
|
34 | 36 | |
|
35 | 37 | function ImageViewer() {} |
|
36 | 38 | ImageViewer.prototype.view = function (post) {}; |
@@ -76,8 +78,8 PopupImageViewer.prototype.view = functi | |||
|
76 | 78 | if (!existingPopups.length) { |
|
77 | 79 | var imgElement= el.find('img'); |
|
78 | 80 | |
|
79 | var img_w = imgElement.attr('data-width'); | |
|
80 | var img_h = imgElement.attr('data-height'); | |
|
81 | var full_img_w = imgElement.attr('data-width'); | |
|
82 | var full_img_h = imgElement.attr('data-height'); | |
|
81 | 83 | |
|
82 | 84 | var win = $(window); |
|
83 | 85 | |
@@ -87,16 +89,16 PopupImageViewer.prototype.view = functi | |||
|
87 | 89 | // New image size |
|
88 | 90 | var w_scale = 1; |
|
89 | 91 | var h_scale = 1; |
|
90 | if (img_w > win_w) { | |
|
91 | w_scale = img_w / (win_w - margin); | |
|
92 | if (full_img_w > win_w) { | |
|
93 | w_scale = full_img_w / (win_w - margin); | |
|
92 | 94 | } |
|
93 | if (img_h > win_h) { | |
|
94 | h_scale = img_h / (win_h - margin); | |
|
95 | if (full_img_h > win_h) { | |
|
96 | h_scale = full_img_h / (win_h - margin); | |
|
95 | 97 | } |
|
96 | 98 | |
|
97 | 99 | var scale = Math.max(w_scale, h_scale) |
|
98 | img_w = img_w / scale; | |
|
99 | img_h = img_h / scale; | |
|
100 | var img_w = full_img_w / scale; | |
|
101 | var img_h = full_img_h / scale; | |
|
100 | 102 | |
|
101 | 103 | var postNode = $(el); |
|
102 | 104 | |
@@ -105,6 +107,7 PopupImageViewer.prototype.view = functi | |||
|
105 | 107 | newImage.addClass('img-full') |
|
106 | 108 | .attr('id', thumb_id) |
|
107 | 109 | .attr('src', postNode.attr('href')) |
|
110 | .attr(ATTR_SCALE, scale) | |
|
108 | 111 | .appendTo(postNode) |
|
109 | 112 | .css({ |
|
110 | 113 | 'width': img_w, |
@@ -117,19 +120,23 PopupImageViewer.prototype.view = functi | |||
|
117 | 120 | var cx = event.originalEvent.clientX; |
|
118 | 121 | var cy = event.originalEvent.clientY; |
|
119 | 122 | |
|
120 | var i_w = parseFloat(newImage.width()); | |
|
121 | var i_h = parseFloat(newImage.height()); | |
|
123 | var scale = newImage.attr(ATTR_SCALE) / (delta > 0 ? 1.25 : 0.8); | |
|
122 | 124 | |
|
123 | var newIW = i_w * (delta > 0 ? 1.25 : 0.8); | |
|
124 | var newIH = i_h * (delta > 0 ? 1.25 : 0.8); | |
|
125 | var oldWidth = newImage.width(); | |
|
126 | var oldHeight = newImage.height(); | |
|
127 | ||
|
128 | var newIW = full_img_w / scale; | |
|
129 | var newIH = full_img_h / scale; | |
|
125 | 130 | |
|
126 | 131 | newImage.width(newIW); |
|
127 | 132 | newImage.height(newIH); |
|
133 | newImage.attr(ATTR_SCALE, scale); | |
|
134 | ||
|
128 | 135 | // Set position |
|
129 | 136 | var oldPosition = newImage.position(); |
|
130 | 137 | newImage.css({ |
|
131 |
left: parseInt(cx - (newIW/ |
|
|
132 |
top: parseInt(cy - (newIH/ |
|
|
138 | left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10), | |
|
139 | top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10) | |
|
133 | 140 | }); |
|
134 | 141 | |
|
135 | 142 | return false; |
General Comments 0
You need to be logged in to leave comments.
Login now