##// END OF EJS Templates
Highlight post instead of showing popup if the post is visible on page....
neko259 -
r1035:149028bb default
parent child Browse files
Show More
@@ -504,4 +504,8 b' ul {'
504 padding: .2ex;
504 padding: .2ex;
505 background: #152154;
505 background: #152154;
506 color: #fff;
506 color: #fff;
507 } No newline at end of file
507 }
508
509 .highlight {
510 background-color: #050052;
511 }
@@ -362,3 +362,7 b' input[type="submit"]:hover {'
362 border-color: #222;
362 border-color: #222;
363 font-size: 0.9em;
363 font-size: 0.9em;
364 }
364 }
365
366 .highlight {
367 background-color: #F9E8A5;
368 }
@@ -385,4 +385,8 b' li {'
385 color: #FFF;
385 color: #FFF;
386 display: inline-block;
386 display: inline-block;
387 text-decoration: none;
387 text-decoration: none;
388 } No newline at end of file
388 }
389
390 .highlight {
391 background-color: #D4F0F9;
392 }
@@ -15,6 +15,30 b' function $each(list, fn) {'
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 mkPreview(cln, html) {
19 cln.innerHTML = html;
20
21 highlightCode($(cln));
22 addRefLinkPreview(cln);
23 translate_time($(cln));
24 };
25
26 function isElementInViewport (el) {
27 //special bonus for those using jQuery
28 if (typeof jQuery === "function" && el instanceof jQuery) {
29 el = el[0];
30 }
31
32 var rect = el.getBoundingClientRect();
33
34 return (
35 rect.top >= 0 &&
36 rect.left >= 0 &&
37 rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
38 rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
39 );
40 }
41
18 function addRefLinkPreview(node) {
42 function addRefLinkPreview(node) {
19 $each($X('.//a[starts-with(text(),">>")]', node || document), function(link) {
43 $each($X('.//a[starts-with(text(),">>")]', node || document), function(link) {
20 link.addEventListener('mouseover', showPostPreview, false);
44 link.addEventListener('mouseover', showPostPreview, false);
@@ -31,67 +55,63 b' function showPostPreview(e) {'
31 return;
55 return;
32 }
56 }
33
57
34 //position
58 var post = $('#' + pNum);
35 //var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) - doc.documentElement.clientLeft + 1;
59 if (post.length > 0 && isElementInViewport(post)) {
36 //var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop) - doc.documentElement.clientTop;
60 post.addClass('highlight');
37
61 } else {
38 var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2;
62 var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2;
39 var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop);
63 var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop);
40
41 var cln = doc.createElement('div');
42 cln.id = 'pstprev_' + pNum;
43 cln.className = 'post_preview';
44
45 cln.style.cssText = 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) + 'px');
46
64
47 cln.addEventListener('mouseout', delPostPreview, false);
65 var cln = doc.createElement('div');
48
66 cln.id = 'pstprev_' + pNum;
67 cln.className = 'post_preview';
49
68
50 var mkPreview = function(cln, html) {
69 cln.style.cssText = 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) + 'px');
51 cln.innerHTML = html;
52
70
53 highlightCode($(cln));
71 cln.addEventListener('mouseout', delPostPreview, false);
54 addRefLinkPreview(cln);
55 translate_time($(cln));
56 };
57
72
73 cln.innerHTML = "<div class=\"post\">" + gettext('Loading...') + "</div>";
58
74
59 cln.innerHTML = "<div class=\"post\">" + gettext('Loading...') + "</div>";
75 if(post.length > 0) {
76 var postdata = post.clone().wrap("<div/>").parent().html();
60
77
61 if($('div[id='+pNum+']').length > 0) {
78 mkPreview(cln, postdata);
62 var postdata = $('div[id='+pNum+']').clone().wrap("<div/>").parent().html();
79 } else {
80 $.ajax({
81 url: '/api/post/' + pNum + '/?truncated'
82 })
83 .success(function(data) {
84 var postdata = $(data).wrap("<div/>").parent().html();
63
85
64 mkPreview(cln, postdata);
86 //make preview
65 } else {
87 mkPreview(cln, postdata);
66 $.ajax({
67 url: '/api/post/' + pNum + '/?truncated'
68 })
69 .success(function(data) {
70 var postdata = $(data).wrap("<div/>").parent().html();
71
88
72 //make preview
89 })
73 mkPreview(cln, postdata);
90 .error(function() {
91 cln.innerHTML = "<div class=\"post\">"
92 + gettext('Post not found') + "</div>";
93 });
94 }
74
95
75 })
96 $del(doc.getElementById(cln.id));
76 .error(function() {
97
77 cln.innerHTML = "<div class=\"post\">"
98 //add preview
78 + gettext('Post not found') + "</div>";
99 $(cln).fadeIn(200);
79 });
100 $('body').append(cln);
80 }
101 }
81
82 $del(doc.getElementById(cln.id));
83
84 //add preview
85 $(cln).fadeIn(200);
86 $('body').append(cln);
87 }
102 }
88
103
89 function delPostPreview(e) {
104 function delPostPreview(e) {
90 var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
105 var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
91 if(!el) $each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
106 if(!el) {
92 $del(clone)
107 $each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
93 });
108 $del(clone)
94 else while(el.nextSibling) $del(el.nextSibling);
109 });
110 } else {
111 while(el.nextSibling) $del(el.nextSibling);
112 }
113
114 $('.highlight').removeClass('highlight');
95 }
115 }
96
116
97 function addPreview() {
117 function addPreview() {
General Comments 0
You need to be logged in to leave comments. Login now