##// END OF EJS Templates
Removed strange 'exists' method in post manager, fixed tests in which it was...
Removed strange 'exists' method in post manager, fixed tests in which it was used

File last commit:

r376:19cea728 default
r396:0d260248 default
Show More
refpopup.js
109 lines | 3.1 KiB | application/javascript | JavascriptLexer
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);
}
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;
//ref id
var pNum = $(this).text().match(/\d+/);
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
Added post preview popups
r352 //position
//var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) - doc.documentElement.clientLeft + 1;
//var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop) - doc.documentElement.clientTop;
var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2;
var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop);
var cln = doc.createElement('div');
cln.id = 'pstprev_' + pNum;
neko259
Fixed refmaps and bumplimited style in post previews
r359 cln.className = 'post_preview';
neko259
Added post preview popups
r352
cln.style.cssText = 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) + 'px');
cln.addEventListener('mouseout', delPostPreview, false);
var mkPreview = function(cln, html) {
cln.innerHTML = html;
addRefLinkPreview(cln);
//if(!$x('.//small', cln)) showRefMap(post, p_num, refMap)
};
neko259
Truncate posts in reflink popups
r368 cln.innerHTML = "<div class=\"post\">" + gettext('Loading...') + "</div>";
neko259
Added post preview popups
r352
//если пост найден в дереве.
if($('div[id='+pNum+']').length > 0) {
neko259
Fixed refmaps and bumplimited style in post previews
r359 var postdata = $('div[id='+pNum+']').wrap("<div/>").parent().html();
neko259
Added post preview popups
r352
//TODO: временно
//funcInit(postdata);
//make preview
mkPreview(cln, postdata);
}
//ajax api
neko259
Load reflink previews of posts that are not present on the current page
r354 else {
$.ajax({
neko259
Truncate posts in reflink popups
r368 url: '/api/post/' + pNum + '/?truncated'
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 })
.success(function(data) {
// TODO get a json, not post itself
var postdata = $(data).wrap("<div/>").parent().html();
neko259
Load reflink previews of posts that are not present on the current page
r354
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 //make preview
mkPreview(cln, postdata);
neko259
Load reflink previews of posts that are not present on the current page
r354
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 })
.error(function() {
neko259
Truncate posts in reflink popups
r368 cln.innerHTML = "<div class=\"post\">"
+ gettext('Post not found') + "</div>";
neko259
Added thread autoupdate. Currently has some bugs, not ready for merge with the main branch
r361 });
neko259
Load reflink previews of posts that are not present on the current page
r354 }
neko259
Added post preview popups
r352
$del(doc.getElementById(cln.id));
neko259
Load reflink previews of posts that are not present on the current page
r354 //add preview
$('body').append(cln);
neko259
Added post preview popups
r352 }
function delPostPreview(e) {
var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
if(!el) $each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
$del(clone)
});
else while(el.nextSibling) $del(el.nextSibling);
}
function addPreview() {
$('.post').find('a').each(function() {
showPostPreview($(this));
});
}