diff --git a/boards/static/js/image.js b/boards/static/js/image.js
--- a/boards/static/js/image.js
+++ b/boards/static/js/image.js
@@ -149,38 +149,37 @@ PopupImageViewer.prototype.view = functi
'left': (win_w - img_w) / 2,
'top': ((win_h - img_h) / 2)
})
- .appendTo(postNode)
- //scaling preview
- .mousewheel(function(event, delta) {
- var cx = event.originalEvent.clientX;
- var cy = event.originalEvent.clientY;
+ //scaling preview
+ .mousewheel(function(event, delta) {
+ var cx = event.originalEvent.clientX;
+ var cy = event.originalEvent.clientY;
- var scale = newImage.attr(ATTR_SCALE) / (delta > 0 ? 1.25 : 0.8);
+ var scale = newImage.attr(ATTR_SCALE) / (delta > 0 ? 1.25 : 0.8);
- var oldWidth = newImage.width();
- var oldHeight = newImage.height();
+ var oldWidth = newImage.width();
+ var oldHeight = newImage.height();
- var newIW = full_img_w / scale;
- var newIH = full_img_h / scale;
+ var newIW = full_img_w / scale;
+ var newIH = full_img_h / scale;
- newImage.width(newIW);
- newImage.height(newIH);
- newImage.attr(ATTR_SCALE, scale);
+ newImage.width(newIW);
+ newImage.height(newIH);
+ newImage.attr(ATTR_SCALE, scale);
- // Set position
- var oldPosition = newImage.position();
- newImage.css({
- left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10),
- top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10)
- });
+ // Set position
+ var oldPosition = newImage.position();
+ newImage.css({
+ left: parseInt(cx - (newIW/oldWidth) * (cx - parseInt(oldPosition.left, 10)), 10),
+ top: parseInt(cy - (newIH/oldHeight) * (cy - parseInt(oldPosition.top, 10)), 10)
+ });
- return false;
- }
- )
+ return false;
+ })
.draggable({
addClasses: false,
stack: '.img-full'
- });
+ })
+ .appendTo($('body'));
} else {
existingPopups.remove();
}
diff --git a/boards/static/js/refpopup.js b/boards/static/js/refpopup.js
--- a/boards/static/js/refpopup.js
+++ b/boards/static/js/refpopup.js
@@ -1,3 +1,5 @@
+var LOADING_MSG = "
" + gettext('Loading...') + "
";
+
function $X(path, root) {
return document.evaluate(path, root || document, null, 6, null);
}
@@ -56,6 +58,7 @@ function showPostPreview(e) {
var post = $('#' + pNum);
if (post.length > 0 && isElementInViewport(post)) {
+ // If post is on the same page and visible, just highlight it
post.addClass('highlight');
} else {
var x = reflink.offset().left;
@@ -65,33 +68,34 @@ function showPostPreview(e) {
cln.id = 'pstprev_' + pNum;
cln.className = 'post_preview';
-// var newX = x < doc.body.clientWidth/2 ? 'left:' + x : 'right:' + parseInt(doc.body.clientWidth - x - reflink.width());
-// var newY = y < doc.body.clientHeight/2 ? 'top:' + y : 'bottom:' + parseInt(doc.body.clientHeight - y - reflink.height());
cln.style.cssText = 'left:' + x + 'px; top:' + y + 'px';
cln.addEventListener('mouseout', delPostPreview, false);
- cln.innerHTML = "" + gettext('Loading...') + "
";
+ cln.innerHTML = LOADING_MSG;
- if(post.length > 0) {
- var postdata = post.clone().wrap("").parent().html();
+ if (post.length > 0) {
+ // If post is on the same page but not visible, generate preview from it
+ var postClone = post.clone();
+ postClone.removeAttr('style');
+ var postdata = postClone.wrap("").parent().html();
mkPreview(cln, postdata);
} else {
+ // If post is from other page, load it
$.ajax({
url: '/api/post/' + pNum + '/?truncated'
})
- .success(function(data) {
- var postdata = $(data).wrap("").parent().html();
-
- //make preview
- mkPreview(cln, postdata);
+ .success(function(data) {
+ var postdata = $(data).wrap("").parent().html();
- })
- .error(function() {
- cln.innerHTML = ""
- + gettext('Post not found') + "
";
- });
+ //make preview
+ mkPreview(cln, postdata);
+ })
+ .error(function() {
+ cln.innerHTML = ""
+ + gettext('Post not found') + "
";
+ });
}
$del(doc.getElementById(cln.id));
@@ -109,7 +113,13 @@ function delPostPreview(e) {
$del(clone)
});
} else {
- while(el.nextSibling) $del(el.nextSibling);
+ while (el.nextSibling) {
+ if (el.nextSibling.className.startsWith('pstprev')) {
+ $del(el.nextSibling);
+ } else {
+ break;
+ }
+ }
}
$('.highlight').removeClass('highlight');