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); |
@@ -72,7 +72,7 b' function showPostPreview(e) {' | |||
|
72 | 72 | //ajax api |
|
73 | 73 | else { |
|
74 | 74 | $.ajax({ |
|
75 |
|
|
|
75 | url: '/api/post/' + pNum + '/' | |
|
76 | 76 | }) |
|
77 | 77 |
|
|
78 | 78 |
|
@@ -1,14 +1,19 b'' | |||
|
1 | 1 | {% load i18n %} |
|
2 | 2 | {% load board %} |
|
3 | 3 | |
|
4 | {% if can_bump %} | |
|
4 | 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,6 +41,7 b'' | |||
|
34 | 41 | {% autoescape off %} |
|
35 | 42 | {{ post.text.rendered }} |
|
36 | 43 | {% endautoescape %} |
|
44 | {% if post.is_referenced %} | |
|
37 | 45 | <div class="refmap"> |
|
38 | 46 | {% trans "Replies" %}: |
|
39 | 47 | {% for ref_post in post.get_sorted_referenced_posts %} |
@@ -41,6 +49,7 b'' | |||
|
41 | 49 | >{% if not forloop.last %},{% endif %} |
|
42 | 50 | {% endfor %} |
|
43 | 51 | </div> |
|
52 | {% endif %} | |
|
44 | 53 | </div> |
|
45 | 54 | {% if post.tags.exists %} |
|
46 | 55 | <div class="metadata"> |
@@ -13,6 +13,7 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 |
|
@@ -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