##// 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 'left': (win_w - img_w) / 2,
149 'left': (win_w - img_w) / 2,
150 'top': ((win_h - img_h) / 2)
150 'top': ((win_h - img_h) / 2)
151 })
151 })
152 .appendTo(postNode)
152 //scaling preview
153 //scaling preview
153 .mousewheel(function(event, delta) {
154 .mousewheel(function(event, delta) {
154 var cx = event.originalEvent.clientX;
155 var cx = event.originalEvent.clientX;
155 var cy = event.originalEvent.clientY;
156 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();
159 var oldWidth = newImage.width();
161 var oldHeight = newImage.height();
160 var oldHeight = newImage.height();
162
161
163 var newIW = full_img_w / scale;
162 var newIW = full_img_w / scale;
164 var newIH = full_img_h / scale;
163 var newIH = full_img_h / scale;
165
164
166 newImage.width(newIW);
165 newImage.width(newIW);
167 newImage.height(newIH);
166 newImage.height(newIH);
168 newImage.attr(ATTR_SCALE, scale);
167 newImage.attr(ATTR_SCALE, scale);
169
168
170 // Set position
169 // Set position
171 var oldPosition = newImage.position();
170 var oldPosition = newImage.position();
172 newImage.css({
171 newImage.css({
173 left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10),
172 left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10),
174 top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10)
173 top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10)
175 });
174 });
176
175
177 return false;
176 return false;
178 }
177 })
179 )
180 .draggable({
178 .draggable({
181 addClasses: false,
179 addClasses: false,
182 stack: '.img-full'
180 stack: '.img-full'
183 });
181 })
182 .appendTo($('body'));
184 } else {
183 } else {
185 existingPopups.remove();
184 existingPopups.remove();
186 }
185 }
@@ -1,3 +1,5 b''
1 var LOADING_MSG = "<div class=\"post\">" + gettext('Loading...') + "</div>";
2
1 function $X(path, root) {
3 function $X(path, root) {
2 return document.evaluate(path, root || document, null, 6, null);
4 return document.evaluate(path, root || document, null, 6, null);
3 }
5 }
@@ -56,6 +58,7 b' function showPostPreview(e) {'
56
58
57 var post = $('#' + pNum);
59 var post = $('#' + pNum);
58 if (post.length > 0 && isElementInViewport(post)) {
60 if (post.length > 0 && isElementInViewport(post)) {
61 // If post is on the same page and visible, just highlight it
59 post.addClass('highlight');
62 post.addClass('highlight');
60 } else {
63 } else {
61 var x = reflink.offset().left;
64 var x = reflink.offset().left;
@@ -65,33 +68,34 b' function showPostPreview(e) {'
65 cln.id = 'pstprev_' + pNum;
68 cln.id = 'pstprev_' + pNum;
66 cln.className = 'post_preview';
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 cln.style.cssText = 'left:' + x + 'px; top:' + y + 'px';
71 cln.style.cssText = 'left:' + x + 'px; top:' + y + 'px';
71
72
72 cln.addEventListener('mouseout', delPostPreview, false);
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 if (post.length > 0) {
77 var postdata = post.clone().wrap("<div/>").parent().html();
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 mkPreview(cln, postdata);
83 mkPreview(cln, postdata);
80 } else {
84 } else {
85 // If post is from other page, load it
81 $.ajax({
86 $.ajax({
82 url: '/api/post/' + pNum + '/?truncated'
87 url: '/api/post/' + pNum + '/?truncated'
83 })
88 })
84 .success(function(data) {
89 .success(function(data) {
85 var postdata = $(data).wrap("<div/>").parent().html();
90 var postdata = $(data).wrap("<div/>").parent().html();
86
87 //make preview
88 mkPreview(cln, postdata);
89
91
90 })
92 //make preview
91 .error(function() {
93 mkPreview(cln, postdata);
92 cln.innerHTML = "<div class=\"post\">"
94 })
93 + gettext('Post not found') + "</div>";
95 .error(function() {
94 });
96 cln.innerHTML = "<div class=\"post\">"
97 + gettext('Post not found') + "</div>";
98 });
95 }
99 }
96
100
97 $del(doc.getElementById(cln.id));
101 $del(doc.getElementById(cln.id));
@@ -109,7 +113,13 b' function delPostPreview(e) {'
109 $del(clone)
113 $del(clone)
110 });
114 });
111 } else {
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 $('.highlight').removeClass('highlight');
125 $('.highlight').removeClass('highlight');
General Comments 0
You need to be logged in to leave comments. Login now