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