##// END OF EJS Templates
Load reflink previews of posts that are not present on the current page
neko259 -
r354:34225dd7 default
parent child Browse files
Show More
@@ -1,111 +1,104 b''
1 1 function $X(path, root) {
2 2 return document.evaluate(path, root || document, null, 6, null);
3 3 }
4 4 function $x(path, root) {
5 5 return document.evaluate(path, root || document, null, 8, null).singleNodeValue;
6 6 }
7 7
8 8 function $del(el) {
9 9 if(el) el.parentNode.removeChild(el);
10 10 }
11 11
12 12 function $each(list, fn) {
13 13 if(!list) return;
14 14 var i = list.snapshotLength;
15 15 if(i > 0) while(i--) fn(list.snapshotItem(i), i);
16 16 }
17 17
18 18 function addRefLinkPreview(node) {
19 19 $each($X('.//a[starts-with(text(),">>")]', node || document), function(link) {
20 20 link.addEventListener('mouseover', showPostPreview, false);
21 21 link.addEventListener('mouseout', delPostPreview, false);
22 22 });
23 23 }
24 24
25 25 function showPostPreview(e) {
26 26 var doc = document;
27 27 //ref id
28 28 var pNum = $(this).text().match(/\d+/);
29 29
30 30 //position
31 31 //var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) - doc.documentElement.clientLeft + 1;
32 32 //var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop) - doc.documentElement.clientTop;
33 33
34 34 var x = e.clientX + (doc.documentElement.scrollLeft || doc.body.scrollLeft) + 2;
35 35 var y = e.clientY + (doc.documentElement.scrollTop || doc.body.scrollTop);
36 36
37 37 var cln = doc.createElement('div');
38 38 cln.id = 'pstprev_' + pNum;
39 39 cln.className = 'post_preview post';
40 40
41 41 cln.style.cssText = 'top:' + y + 'px;' + (x < doc.body.clientWidth/2 ? 'left:' + x + 'px' : 'right:' + parseInt(doc.body.clientWidth - x + 1) + 'px');
42 42
43 43 cln.addEventListener('mouseout', delPostPreview, false);
44 44
45 45
46 46 var mkPreview = function(cln, html) {
47 47
48 48 cln.innerHTML = html;
49 49
50 50 addRefLinkPreview(cln);
51 51
52 52 //if(!$x('.//small', cln)) showRefMap(post, p_num, refMap)
53 53 };
54 54
55 55
56 56 cln.innerHTML = 'Π—Π°Π³Ρ€ΡƒΠ·ΠΊΠ°...';
57 57
58 var found = false;
59
60 58 //Ссли пост Π½Π°ΠΉΠ΄Π΅Π½ Π² Π΄Π΅Ρ€Π΅Π²Π΅.
61 59 if($('div[id='+pNum+']').length > 0) {
62 60 var postdata = $('div[id='+pNum+']').html();
63 61
64 62 //TODO: Π²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎ
65 63 //funcInit(postdata);
66 64
67 65 //make preview
68 66 mkPreview(cln, postdata);
69
70 found = true;
71 67 }
72 68 //ajax api
73 // else {
74 // $.getJSON(mayuri_cfg['board_url']+'api/single/'+pNum)
75 // .success(function(data) {
76 // //post templates
77 // var postdata = makeAjaxPost(data).html();
78 //
79 // //TODO: Π²Ρ€Π΅ΠΌΠ΅Π½Π½ΠΎ
80 // //funcInit(postdata);
81 //
82 // //make preview
83 // mkPreview(cln, postdata);
84 //
85 // })//if error
86 // .error(function() {
87 // cln.innerHTML = 'ΠŸΠΎΡΡ‚ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½.';
88 // });
89 // }
69 else {
70 $.ajax({
71 url: '/api/post/' + pNum
72 })
73 .success(function(data) {
74 // TODO get a json, not post itself
75 var postdata = $(data).html();
76
77 //make preview
78 mkPreview(cln, postdata);
79
80 })
81 .error(function() {
82 cln.innerHTML = 'ΠŸΠΎΡΡ‚ Π½Π΅ Π½Π°ΠΉΠ΄Π΅Π½.';
83 });
84 }
90 85
91 86 $del(doc.getElementById(cln.id));
92 87
93 if (found) {
94 //add preview
95 $('body').append(cln);
96 }
88 //add preview
89 $('body').append(cln);
97 90 }
98 91
99 92 function delPostPreview(e) {
100 93 var el = $x('ancestor-or-self::*[starts-with(@id,"pstprev")]', e.relatedTarget);
101 94 if(!el) $each($X('.//div[starts-with(@id,"pstprev")]'), function(clone) {
102 95 $del(clone)
103 96 });
104 97 else while(el.nextSibling) $del(el.nextSibling);
105 98 }
106 99
107 100 function addPreview() {
108 101 $('.post').find('a').each(function() {
109 102 showPostPreview($(this));
110 103 });
111 104 }
@@ -1,56 +1,56 b''
1 1 from django.conf.urls import patterns, url, include
2 2 from boards import views
3 3 from boards.rss import AllThreadsFeed, TagThreadsFeed, ThreadPostsFeed
4 4
5 5 js_info_dict = {
6 6 'packages': ('boards',),
7 7 }
8 8
9 9 urlpatterns = patterns('',
10 10
11 11 # /boards/
12 12 url(r'^$', views.index, name='index'),
13 13 # /boards/page/
14 14 url(r'^page/(?P<page>\w+)/$', views.index, name='index'),
15 15
16 16 # login page
17 17 url(r'^login/$', views.login, name='login'),
18 18
19 19 # /boards/tag/tag_name/
20 20 url(r'^tag/(?P<tag_name>\w+)/$', views.tag, name='tag'),
21 21 # /boards/tag/tag_id/page/
22 22 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/$', views.tag, name='tag'),
23 23
24 24 # /boards/tag/tag_name/unsubscribe/
25 25 url(r'^tag/(?P<tag_name>\w+)/subscribe/$', views.tag_subscribe,
26 26 name='tag_subscribe'),
27 27 # /boards/tag/tag_name/unsubscribe/
28 28 url(r'^tag/(?P<tag_name>\w+)/unsubscribe/$', views.tag_unsubscribe,
29 29 name='tag_unsubscribe'),
30 30
31 31 # /boards/thread/
32 32 url(r'^thread/(?P<post_id>\w+)/$', views.thread, name='thread'),
33 33 url(r'^settings/$', views.settings, name='settings'),
34 34 url(r'^tags/$', views.all_tags, name='tags'),
35 35 url(r'^captcha/', include('captcha.urls')),
36 36 url(r'^jump/(?P<post_id>\w+)/$', views.jump_to_post, name='jumper'),
37 37 url(r'^authors/$', views.authors, name='authors'),
38 38 url(r'^delete/(?P<post_id>\w+)/$', views.delete, name='delete'),
39 39 url(r'^ban/(?P<post_id>\w+)/$', views.ban, name='ban'),
40 40
41 41 url(r'^banned/$', views.you_are_banned, name='banned'),
42 42 url(r'^staticpage/(?P<name>\w+)/$', views.static_page, name='staticpage'),
43 43
44 44 # RSS feeds
45 45 url(r'^rss/$', AllThreadsFeed()),
46 46 url(r'^page/(?P<page>\w+)/rss/$', AllThreadsFeed()),
47 47 url(r'^tag/(?P<tag_name>\w+)/rss/$', TagThreadsFeed()),
48 48 url(r'^tag/(?P<tag_name>\w+)/page/(?P<page>\w+)/rss/$', TagThreadsFeed()),
49 49 url(r'^thread/(?P<post_id>\w+)/rss/$', ThreadPostsFeed()),
50 50
51 51 # i18n
52 52 url(r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),
53 53
54 54 # API
55 url(r'^get_post/(?P<post_id>\w+)/$', views.get_post, name="get_post"),
55 url(r'^api/post/(?P<post_id>\w+)/$', views.get_post, name="get_post"),
56 56 )
General Comments 0
You need to be logged in to leave comments. Login now