##// END OF EJS Templates
Speed up reflink popup animation
neko259 -
r422:4120940a default
parent child Browse files
Show More
@@ -1,99 +1,99 b''
1 function $X(path, root) {
1 function $X(path, root) {
2 return document.evaluate(path, root || document, null, 6, null);
2 return document.evaluate(path, root || document, null, 6, null);
3 }
3 }
4 function $x(path, root) {
4 function $x(path, root) {
5 return document.evaluate(path, root || document, null, 8, null).singleNodeValue;
5 return document.evaluate(path, root || document, null, 8, null).singleNodeValue;
6 }
6 }
7
7
8 function $del(el) {
8 function $del(el) {
9 if(el) el.parentNode.removeChild(el);
9 if(el) el.parentNode.removeChild(el);
10 }
10 }
11
11
12 function $each(list, fn) {
12 function $each(list, fn) {
13 if(!list) return;
13 if(!list) return;
14 var i = list.snapshotLength;
14 var i = list.snapshotLength;
15 if(i > 0) while(i--) fn(list.snapshotItem(i), i);
15 if(i > 0) while(i--) fn(list.snapshotItem(i), i);
16 }
16 }
17
17
18 function addRefLinkPreview(node) {
18 function addRefLinkPreview(node) {
19 $each($X('.//a[starts-with(text(),">>")]', node || document), function(link) {
19 $each($X('.//a[starts-with(text(),">>")]', node || document), function(link) {
20 link.addEventListener('mouseover', showPostPreview, false);
20 link.addEventListener('mouseover', showPostPreview, false);
21 link.addEventListener('mouseout', delPostPreview, false);
21 link.addEventListener('mouseout', delPostPreview, false);
22 });
22 });
23 }
23 }
24
24
25 function showPostPreview(e) {
25 function showPostPreview(e) {
26 var doc = document;
26 var doc = document;
27 //ref id
27 //ref id
28 var pNum = $(this).text().match(/\d+/);
28 var pNum = $(this).text().match(/\d+/);
29
29
30 if (pNum == null || pNum.length == 0) {
30 if (pNum == null || pNum.length == 0) {
31 return;
31 return;
32 }
32 }
33
33
34 //position
34 //position
35 //var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) - doc.documentElement.clientLeft + 1;
35 //var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) - doc.documentElement.clientLeft + 1;
36 //var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop) - doc.documentElement.clientTop;
36 //var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop) - doc.documentElement.clientTop;
37
37
38 var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2;
38 var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2;
39 var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop);
39 var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop);
40
40
41 var cln = doc.createElement('div');
41 var cln = doc.createElement('div');
42 cln.id = 'pstprev_' + pNum;
42 cln.id = 'pstprev_' + pNum;
43 cln.className = 'post_preview';
43 cln.className = 'post_preview';
44
44
45 cln.style.cssText = 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) + 'px');
45 cln.style.cssText = 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) + 'px');
46
46
47 cln.addEventListener('mouseout', delPostPreview, false);
47 cln.addEventListener('mouseout', delPostPreview, false);
48
48
49
49
50 var mkPreview = function(cln, html) {
50 var mkPreview = function(cln, html) {
51 cln.innerHTML = html;
51 cln.innerHTML = html;
52
52
53 addRefLinkPreview(cln);
53 addRefLinkPreview(cln);
54 };
54 };
55
55
56
56
57 cln.innerHTML = "<div class=\"post\">" + gettext('Loading...') + "</div>";
57 cln.innerHTML = "<div class=\"post\">" + gettext('Loading...') + "</div>";
58
58
59 if($('div[id='+pNum+']').length > 0) {
59 if($('div[id='+pNum+']').length > 0) {
60 var postdata = $('div[id='+pNum+']').wrap("<div/>").parent().html();
60 var postdata = $('div[id='+pNum+']').wrap("<div/>").parent().html();
61
61
62 mkPreview(cln, postdata);
62 mkPreview(cln, postdata);
63 } else {
63 } else {
64 $.ajax({
64 $.ajax({
65 url: '/api/post/' + pNum + '/?truncated'
65 url: '/api/post/' + pNum + '/?truncated'
66 })
66 })
67 .success(function(data) {
67 .success(function(data) {
68 var postdata = $(data).wrap("<div/>").parent().html();
68 var postdata = $(data).wrap("<div/>").parent().html();
69
69
70 //make preview
70 //make preview
71 mkPreview(cln, postdata);
71 mkPreview(cln, postdata);
72
72
73 })
73 })
74 .error(function() {
74 .error(function() {
75 cln.innerHTML = "<div class=\"post\">"
75 cln.innerHTML = "<div class=\"post\">"
76 + gettext('Post not found') + "</div>";
76 + gettext('Post not found') + "</div>";
77 });
77 });
78 }
78 }
79
79
80 $del(doc.getElementById(cln.id));
80 $del(doc.getElementById(cln.id));
81
81
82 //add preview
82 //add preview
83 $(cln).fadeIn();
83 $(cln).fadeIn(200);
84 $('body').append(cln);
84 $('body').append(cln);
85 }
85 }
86
86
87 function delPostPreview(e) {
87 function delPostPreview(e) {
88 var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
88 var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
89 if(!el) $each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
89 if(!el) $each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
90 $del(clone)
90 $del(clone)
91 });
91 });
92 else while(el.nextSibling) $del(el.nextSibling);
92 else while(el.nextSibling) $del(el.nextSibling);
93 }
93 }
94
94
95 function addPreview() {
95 function addPreview() {
96 $('.post').find('a').each(function() {
96 $('.post').find('a').each(function() {
97 showPostPreview($(this));
97 showPostPreview($(this));
98 });
98 });
99 }
99 }
General Comments 0
You need to be logged in to leave comments. Login now