Show More
@@ -0,0 +1,37 b'' | |||
|
1 | var THREAD_UPDATE_DELAY = 10000; | |
|
2 | ||
|
3 | var loading = false; | |
|
4 | ||
|
5 | function updateThread() { | |
|
6 | if (loading) { | |
|
7 | return; | |
|
8 | } | |
|
9 | ||
|
10 | loading = true; | |
|
11 | ||
|
12 | var threadPosts = $('div.thread').children('.post'); | |
|
13 | ||
|
14 | var lastPost = threadPosts.last(); | |
|
15 | var threadId = threadPosts.first().attr('id'); | |
|
16 | var lastPostId = lastPost.attr('id'); | |
|
17 | ||
|
18 | var diffUrl = '/api/diff_thread/' + threadId + '/' + lastPostId + '/'; | |
|
19 | $.getJSON(diffUrl) | |
|
20 | .success(function(data) { | |
|
21 | var addedPosts = data.added; | |
|
22 | ||
|
23 | for (var i = 0; i < addedPosts.length; i++) { | |
|
24 | var postText = addedPosts[i]; | |
|
25 | ||
|
26 | var post = $(postText).hide(); | |
|
27 | post.appendTo(lastPost.parent()).show('slow'); | |
|
28 | addRefLinkPreview(post[0]); | |
|
29 | ||
|
30 | lastPost = post; | |
|
31 | } | |
|
32 | ||
|
33 | loading = false; | |
|
34 | }); | |
|
35 | } | |
|
36 | ||
|
37 | setInterval(updateThread, THREAD_UPDATE_DELAY); |
@@ -28,7 +28,7 b' function showPostPreview(e) {' | |||
|
28 | 28 | var pNum = $(this).text().match(/\d+/); |
|
29 | 29 | |
|
30 | 30 | if (pNum.length == 0) { |
|
31 |
|
|
|
31 | return; | |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | //position |
@@ -72,19 +72,19 b' function showPostPreview(e) {' | |||
|
72 | 72 | //ajax api |
|
73 | 73 | else { |
|
74 | 74 | $.ajax({ |
|
75 |
|
|
|
76 | }) | |
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
75 | url: '/api/post/' + pNum + '/' | |
|
76 | }) | |
|
77 | .success(function(data) { | |
|
78 | // TODO get a json, not post itself | |
|
79 | var postdata = $(data).wrap("<div/>").parent().html(); | |
|
80 | 80 | |
|
81 |
|
|
|
82 |
|
|
|
81 | //make preview | |
|
82 | mkPreview(cln, postdata); | |
|
83 | 83 | |
|
84 | }) | |
|
85 |
|
|
|
86 |
|
|
|
87 | }); | |
|
84 | }) | |
|
85 | .error(function() { | |
|
86 | cln.innerHTML = gettext('Post not found'); | |
|
87 | }); | |
|
88 | 88 | } |
|
89 | 89 | |
|
90 | 90 | $del(doc.getElementById(cln.id)); |
@@ -1,14 +1,19 b'' | |||
|
1 | 1 | {% load i18n %} |
|
2 | 2 | {% load board %} |
|
3 | 3 | |
|
4 | <div class="post" id="{{ post.id }}"> | |
|
4 | {% if can_bump %} | |
|
5 | <div class="post" id="{{ post.id }}"> | |
|
6 | {% else %} | |
|
7 | <div class="post dead_post" id="{{ post.id }}"> | |
|
8 | {% endif %} | |
|
9 | ||
|
5 | 10 | {% if post.image %} |
|
6 | 11 | <div class="image"> |
|
7 | 12 | <a |
|
8 | 13 | class="thumb" |
|
9 | 14 | href="{{ post.image.url }}"><img |
|
10 | 15 | src="{{ post.image.url_200x150 }}" |
|
11 |
alt="{% trans 'Post image' %}" |
|
|
16 | alt="{% trans 'Post image' %}" | |
|
12 | 17 | data-width="{{ post.image_width }}" |
|
13 | 18 | data-height="{{ post.image_height }}"/> |
|
14 | 19 | </a> |
@@ -18,8 +23,10 b'' | |||
|
18 | 23 | <div class="post-info"> |
|
19 | 24 | <span class="title">{{ post.title }}</span> |
|
20 | 25 | <a class="post_id" href="#{{ post.id }}"> |
|
21 |
( |
|
|
26 | ({{ post.id }})</a> | |
|
22 | 27 | [{{ post.pub_time }}] |
|
28 | [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}') | |
|
29 | ; return false;">>></a>] | |
|
23 | 30 | |
|
24 | 31 | {% if moderator %} |
|
25 | 32 | <span class="moderator_info"> |
@@ -34,22 +41,24 b'' | |||
|
34 | 41 | {% autoescape off %} |
|
35 | 42 | {{ post.text.rendered }} |
|
36 | 43 | {% endautoescape %} |
|
37 | <div class="refmap"> | |
|
38 | {% trans "Replies" %}: | |
|
39 | {% for ref_post in post.get_sorted_referenced_posts %} | |
|
40 | <a href="{% post_url ref_post.id %}">>>{{ ref_post.id }}</a | |
|
41 | >{% if not forloop.last %},{% endif %} | |
|
42 | {% endfor %} | |
|
43 | </div> | |
|
44 | {% if post.is_referenced %} | |
|
45 | <div class="refmap"> | |
|
46 | {% trans "Replies" %}: | |
|
47 | {% for ref_post in post.get_sorted_referenced_posts %} | |
|
48 | <a href="{% post_url ref_post.id %}">>>{{ ref_post.id }}</a | |
|
49 | >{% if not forloop.last %},{% endif %} | |
|
50 | {% endfor %} | |
|
51 | </div> | |
|
52 | {% endif %} | |
|
44 | 53 | </div> |
|
45 | 54 | {% if post.tags.exists %} |
|
46 | 55 | <div class="metadata"> |
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
56 | <span class="tags">{% trans 'Tags' %}: | |
|
57 | {% for tag in post.tags.all %} | |
|
58 | <a class="tag" href="{% url 'tag' tag.name %}"> | |
|
59 | {{ tag.name }}</a> | |
|
60 | {% endfor %} | |
|
61 | </span> | |
|
53 | 62 | </div> |
|
54 | 63 | {% endif %} |
|
55 | 64 | </div> No newline at end of file |
@@ -13,9 +13,10 b'' | |||
|
13 | 13 | {% block content %} |
|
14 | 14 | {% get_current_language as LANGUAGE_CODE %} |
|
15 | 15 | |
|
16 | <script src="{% static 'js/thread_update.js' %}"></script> | |
|
16 | 17 | <script src="{% static 'js/thread.js' %}"></script> |
|
17 | 18 | |
|
18 |
|
|
|
19 | {% if posts %} | |
|
19 | 20 | {% cache 600 thread_view posts.0.last_edit_time moderator LANGUAGE_CODE %} |
|
20 | 21 | {% if bumpable %} |
|
21 | 22 | <div class="bar-bg"> |
@@ -27,7 +28,7 b'' | |||
|
27 | 28 | </div> |
|
28 | 29 | {% endif %} |
|
29 | 30 | <div class="thread"> |
|
30 |
|
|
|
31 | {% for post in posts %} | |
|
31 | 32 | {% if bumpable %} |
|
32 | 33 | <div class="post" id="{{ post.id }}"> |
|
33 | 34 | {% else %} |
@@ -67,7 +68,7 b'' | |||
|
67 | 68 | {% autoescape off %} |
|
68 | 69 | {{ post.text.rendered }} |
|
69 | 70 | {% endautoescape %} |
|
70 |
|
|
|
71 | {% if post.is_referenced %} | |
|
71 | 72 | <div class="refmap"> |
|
72 | 73 | {% trans "Replies" %}: |
|
73 | 74 | {% for ref_post in post.get_sorted_referenced_posts %} |
@@ -89,15 +90,15 b'' | |||
|
89 | 90 | </div> |
|
90 | 91 | {% endif %} |
|
91 | 92 | </div> |
|
92 |
|
|
|
93 | {% endfor %} | |
|
93 | 94 | </div> |
|
94 | 95 | {% endcache %} |
|
95 |
|
|
|
96 | {% endif %} | |
|
96 | 97 | |
|
97 | 98 | <form id="form" enctype="multipart/form-data" method="post" |
|
98 | 99 | >{% csrf_token %} |
|
99 | 100 | <div class="post-form-w"> |
|
100 |
|
|
|
101 | <div class="form-title">{% trans "Reply to thread" %} #{{ posts.0.id }}</div> | |
|
101 | 102 | <div class="post-form"> |
|
102 | 103 | <div class="form-row"> |
|
103 | 104 | <div class="form-label">{% trans 'Title' %}</div> |
@@ -53,4 +53,6 b" urlpatterns = patterns(''," | |||
|
53 | 53 | |
|
54 | 54 | # API |
|
55 | 55 | url(r'^api/post/(?P<post_id>\w+)/$', views.get_post, name="get_post"), |
|
56 | url(r'^api/diff_thread/(?P<thread_id>\w+)/(?P<last_post_id>\w+)/$', | |
|
57 | views.api_get_threaddiff, name="get_thread_diff"), | |
|
56 | 58 | ) |
@@ -1,4 +1,5 b'' | |||
|
1 | 1 | import hashlib |
|
2 | import json | |
|
2 | 3 | import string |
|
3 | 4 | from django.core import serializers |
|
4 | 5 | from django.core.urlresolvers import reverse |
@@ -408,13 +409,28 b' def api_get_post(request, post_id):' | |||
|
408 | 409 | return HttpResponse(content=json) |
|
409 | 410 | |
|
410 | 411 | |
|
412 | def api_get_threaddiff(request, thread_id, last_post_id): | |
|
413 | thread = get_object_or_404(Post, id=thread_id) | |
|
414 | posts = Post.objects.filter(thread=thread, id__gt=last_post_id) | |
|
415 | ||
|
416 | json_data = { | |
|
417 | 'added': [] | |
|
418 | } | |
|
419 | for post in posts: | |
|
420 | json_data['added'].append(get_post(request, post.id).content.strip()) | |
|
421 | ||
|
422 | return HttpResponse(content=json.dumps(json_data)) | |
|
423 | ||
|
424 | ||
|
411 | 425 | def get_post(request, post_id): |
|
412 | 426 | """Get the html of a post. Used for popups.""" |
|
413 | 427 | |
|
414 | 428 | post = get_object_or_404(Post, id=post_id) |
|
429 | thread = post.thread | |
|
415 | 430 | |
|
416 | 431 | context = RequestContext(request) |
|
417 | 432 | context["post"] = post |
|
433 | context["can_bump"] = thread.can_bump() | |
|
418 | 434 | |
|
419 | 435 | return render(request, 'boards/post.html', context) |
|
420 | 436 |
General Comments 0
You need to be logged in to leave comments.
Login now