##// END OF EJS Templates
Do not close images from refpopups when the popup is removed
neko259 -
r1474:378f92ac default
parent child Browse files
Show More
@@ -149,38 +149,37 b' PopupImageViewer.prototype.view = functi'
149 149 'left': (win_w - img_w) / 2,
150 150 'top': ((win_h - img_h) / 2)
151 151 })
152 .appendTo(postNode)
153 //scaling preview
154 .mousewheel(function(event, delta) {
155 var cx = event.originalEvent.clientX;
156 var cy = event.originalEvent.clientY;
152 //scaling preview
153 .mousewheel(function(event, delta) {
154 var cx = event.originalEvent.clientX;
155 var cy = event.originalEvent.clientY;
157 156
158 var scale = newImage.attr(ATTR_SCALE) / (delta > 0 ? 1.25 : 0.8);
157 var scale = newImage.attr(ATTR_SCALE) / (delta > 0 ? 1.25 : 0.8);
159 158
160 var oldWidth = newImage.width();
161 var oldHeight = newImage.height();
159 var oldWidth = newImage.width();
160 var oldHeight = newImage.height();
162 161
163 var newIW = full_img_w / scale;
164 var newIH = full_img_h / scale;
162 var newIW = full_img_w / scale;
163 var newIH = full_img_h / scale;
165 164
166 newImage.width(newIW);
167 newImage.height(newIH);
168 newImage.attr(ATTR_SCALE, scale);
165 newImage.width(newIW);
166 newImage.height(newIH);
167 newImage.attr(ATTR_SCALE, scale);
169 168
170 // Set position
171 var oldPosition = newImage.position();
172 newImage.css({
173 left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10),
174 top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10)
175 });
169 // Set position
170 var oldPosition = newImage.position();
171 newImage.css({
172 left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10),
173 top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10)
174 });
176 175
177 return false;
178 }
179 )
176 return false;
177 })
180 178 .draggable({
181 179 addClasses: false,
182 180 stack: '.img-full'
183 });
181 })
182 .appendTo($('body'));
184 183 } else {
185 184 existingPopups.remove();
186 185 }
@@ -1,3 +1,5 b''
1 var LOADING_MSG = "<div class=\"post\">" + gettext('Loading...') + "</div>";
2
1 3 function $X(path, root) {
2 4 return document.evaluate(path, root || document, null, 6, null);
3 5 }
@@ -56,6 +58,7 b' function showPostPreview(e) {'
56 58
57 59 var post = $('#' + pNum);
58 60 if (post.length > 0 && isElementInViewport(post)) {
61 // If post is on the same page and visible, just highlight it
59 62 post.addClass('highlight');
60 63 } else {
61 64 var x = reflink.offset().left;
@@ -65,33 +68,34 b' function showPostPreview(e) {'
65 68 cln.id = 'pstprev_' + pNum;
66 69 cln.className = 'post_preview';
67 70
68 // var newX = x < doc.body.clientWidth/2 ? 'left:' + x : 'right:' + parseInt(doc.body.clientWidth - x - reflink.width());
69 // var newY = y < doc.body.clientHeight/2 ? 'top:' + y : 'bottom:' + parseInt(doc.body.clientHeight - y - reflink.height());
70 71 cln.style.cssText = 'left:' + x + 'px; top:' + y + 'px';
71 72
72 73 cln.addEventListener('mouseout', delPostPreview, false);
73 74
74 cln.innerHTML = "<div class=\"post\">" + gettext('Loading...') + "</div>";
75 cln.innerHTML = LOADING_MSG;
75 76
76 if(post.length > 0) {
77 var postdata = post.clone().wrap("<div/>").parent().html();
77 if (post.length > 0) {
78 // If post is on the same page but not visible, generate preview from it
79 var postClone = post.clone();
80 postClone.removeAttr('style');
81 var postdata = postClone.wrap("<div/>").parent().html();
78 82
79 83 mkPreview(cln, postdata);
80 84 } else {
85 // If post is from other page, load it
81 86 $.ajax({
82 87 url: '/api/post/' + pNum + '/?truncated'
83 88 })
84 .success(function(data) {
85 var postdata = $(data).wrap("<div/>").parent().html();
86
87 //make preview
88 mkPreview(cln, postdata);
89 .success(function(data) {
90 var postdata = $(data).wrap("<div/>").parent().html();
89 91
90 })
91 .error(function() {
92 cln.innerHTML = "<div class=\"post\">"
93 + gettext('Post not found') + "</div>";
94 });
92 //make preview
93 mkPreview(cln, postdata);
94 })
95 .error(function() {
96 cln.innerHTML = "<div class=\"post\">"
97 + gettext('Post not found') + "</div>";
98 });
95 99 }
96 100
97 101 $del(doc.getElementById(cln.id));
@@ -109,7 +113,13 b' function delPostPreview(e) {'
109 113 $del(clone)
110 114 });
111 115 } else {
112 while(el.nextSibling) $del(el.nextSibling);
116 while (el.nextSibling) {
117 if (el.nextSibling.className.startsWith('pstprev')) {
118 $del(el.nextSibling);
119 } else {
120 break;
121 }
122 }
113 123 }
114 124
115 125 $('.highlight').removeClass('highlight');
General Comments 0
You need to be logged in to leave comments. Login now