##// END OF EJS Templates
Fixed tree child positions
Fixed tree child positions

File last commit:

r1476:fdce35a2 default
r1487:e4a035cf default
Show More
refpopup.js
134 lines | 3.7 KiB | application/javascript | JavascriptLexer
neko259
Do not close images from refpopups when the popup is removed
r1474 var LOADING_MSG = "<div class=\"post\">" + gettext('Loading...') + "</div>";
neko259
Fixed mouseout on cascade previews
r1476 var CLS_PREVIEW = 'post_preview';
neko259
Added post preview popups
r352 function $X(path, root) {
return document.evaluate(path, root || document, null, 6, null);
}
function $x(path, root) {
return document.evaluate(path, root || document, null, 8, null).singleNodeValue;
}
function $del(el) {
if(el) el.parentNode.removeChild(el);
}
function $each(list, fn) {
if(!list) return;
var i = list.snapshotLength;
if(i > 0) while(i--) fn(list.snapshotItem(i), i);
}
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 function mkPreview(cln, html) {
cln.innerHTML = html;
neko259
Save video and audio volume level
r1432 addScriptsToPost($(cln));
neko259
Fixed SVG popup preview
r1405 }
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035
function isElementInViewport (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}
neko259
Added post preview popups
r352 function addRefLinkPreview(node) {
$each($X('.//a[starts-with(text(),">>")]', node || document), function(link) {
link.addEventListener('mouseover', showPostPreview, false);
link.addEventListener('mouseout', delPostPreview, false);
});
}
function showPostPreview(e) {
var doc = document;
neko259
Show notifications directly above the reflink unrelated to the cursor position
r1456
var reflink = $(this);
var pNum = reflink.text().match(/\d+/);
neko259
Added post preview popups
r352
neko259
Fixed NPE in reflink previews
r376 if (pNum == null || pNum.length == 0) {
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 return;
neko259
Fixed reply links on page that trigger ajax
r355 }
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 var post = $('#' + pNum);
if (post.length > 0 && isElementInViewport(post)) {
neko259
Do not close images from refpopups when the popup is removed
r1474 // If post is on the same page and visible, just highlight it
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 post.addClass('highlight');
} else {
neko259
Show notifications directly above the reflink unrelated to the cursor position
r1456 var x = reflink.offset().left;
var y = reflink.offset().top;
neko259
Added post preview popups
r352
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 var cln = doc.createElement('div');
cln.id = 'pstprev_' + pNum;
neko259
Fixed mouseout on cascade previews
r1476 cln.className = CLS_PREVIEW;
neko259
Added post preview popups
r352
neko259
Show reflink popups from left-top always. Don't insert spaces after comma in...
r1457 cln.style.cssText = 'left:' + x + 'px; top:' + y + 'px';
neko259
Added post preview popups
r352
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 cln.addEventListener('mouseout', delPostPreview, false);
neko259
Added post preview popups
r352
neko259
Do not close images from refpopups when the popup is removed
r1474 cln.innerHTML = LOADING_MSG;
neko259
Added post preview popups
r352
neko259
Do not close images from refpopups when the popup is removed
r1474 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("<div/>").parent().html();
neko259
Added post preview popups
r352
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 mkPreview(cln, postdata);
} else {
neko259
Do not close images from refpopups when the popup is removed
r1474 // If post is from other page, load it
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 $.ajax({
url: '/api/post/' + pNum + '/?truncated'
})
neko259
Do not close images from refpopups when the popup is removed
r1474 .success(function(data) {
var postdata = $(data).wrap("<div/>").parent().html();
neko259
Load reflink previews of posts that are not present on the current page
r354
neko259
Do not close images from refpopups when the popup is removed
r1474 //make preview
mkPreview(cln, postdata);
})
.error(function() {
cln.innerHTML = "<div class=\"post\">"
+ gettext('Post not found') + "</div>";
});
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 }
neko259
Load reflink previews of posts that are not present on the current page
r354
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 $del(doc.getElementById(cln.id));
//add preview
$(cln).fadeIn(200);
$('body').append(cln);
neko259
Load reflink previews of posts that are not present on the current page
r354 }
neko259
Added post preview popups
r352 }
function delPostPreview(e) {
var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 if(!el) {
$each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
$del(clone)
});
} else {
neko259
Do not close images from refpopups when the popup is removed
r1474 while (el.nextSibling) {
neko259
Fixed mouseout on cascade previews
r1476 if (el.nextSibling.className == CLS_PREVIEW) {
neko259
Do not close images from refpopups when the popup is removed
r1474 $del(el.nextSibling);
} else {
break;
}
}
neko259
Highlight post instead of showing popup if the post is visible on page....
r1035 }
$('.highlight').removeClass('highlight');
neko259
Added post preview popups
r352 }
function addPreview() {
$('.post').find('a').each(function() {
showPostPreview($(this));
});
}