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 | //ajax api |
|
72 | //ajax api | |
73 | else { |
|
73 | else { | |
74 | $.ajax({ |
|
74 | $.ajax({ | |
75 |
|
|
75 | url: '/api/post/' + pNum + '/' | |
76 | }) |
|
76 | }) | |
77 |
|
|
77 | .success(function(data) { | |
78 |
|
|
78 | // TODO get a json, not post itself |
@@ -1,14 +1,19 b'' | |||||
1 | {% load i18n %} |
|
1 | {% load i18n %} | |
2 | {% load board %} |
|
2 | {% load board %} | |
3 |
|
3 | |||
|
4 | {% if can_bump %} | |||
4 | <div class="post" id="{{ post.id }}"> |
|
5 | <div class="post" id="{{ post.id }}"> | |
|
6 | {% else %} | |||
|
7 | <div class="post dead_post" id="{{ post.id }}"> | |||
|
8 | {% endif %} | |||
|
9 | ||||
5 | {% if post.image %} |
|
10 | {% if post.image %} | |
6 | <div class="image"> |
|
11 | <div class="image"> | |
7 | <a |
|
12 | <a | |
8 | class="thumb" |
|
13 | class="thumb" | |
9 | href="{{ post.image.url }}"><img |
|
14 | href="{{ post.image.url }}"><img | |
10 | src="{{ post.image.url_200x150 }}" |
|
15 | src="{{ post.image.url_200x150 }}" | |
11 |
alt="{% trans 'Post image' %}" |
|
16 | alt="{% trans 'Post image' %}" | |
12 | data-width="{{ post.image_width }}" |
|
17 | data-width="{{ post.image_width }}" | |
13 | data-height="{{ post.image_height }}"/> |
|
18 | data-height="{{ post.image_height }}"/> | |
14 | </a> |
|
19 | </a> | |
@@ -18,8 +23,10 b'' | |||||
18 | <div class="post-info"> |
|
23 | <div class="post-info"> | |
19 | <span class="title">{{ post.title }}</span> |
|
24 | <span class="title">{{ post.title }}</span> | |
20 | <a class="post_id" href="#{{ post.id }}"> |
|
25 | <a class="post_id" href="#{{ post.id }}"> | |
21 |
( |
|
26 | ({{ post.id }})</a> | |
22 | [{{ post.pub_time }}] |
|
27 | [{{ post.pub_time }}] | |
|
28 | [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}') | |||
|
29 | ; return false;">>></a>] | |||
23 |
|
30 | |||
24 | {% if moderator %} |
|
31 | {% if moderator %} | |
25 | <span class="moderator_info"> |
|
32 | <span class="moderator_info"> | |
@@ -34,6 +41,7 b'' | |||||
34 | {% autoescape off %} |
|
41 | {% autoescape off %} | |
35 | {{ post.text.rendered }} |
|
42 | {{ post.text.rendered }} | |
36 | {% endautoescape %} |
|
43 | {% endautoescape %} | |
|
44 | {% if post.is_referenced %} | |||
37 | <div class="refmap"> |
|
45 | <div class="refmap"> | |
38 | {% trans "Replies" %}: |
|
46 | {% trans "Replies" %}: | |
39 | {% for ref_post in post.get_sorted_referenced_posts %} |
|
47 | {% for ref_post in post.get_sorted_referenced_posts %} | |
@@ -41,6 +49,7 b'' | |||||
41 | >{% if not forloop.last %},{% endif %} |
|
49 | >{% if not forloop.last %},{% endif %} | |
42 | {% endfor %} |
|
50 | {% endfor %} | |
43 | </div> |
|
51 | </div> | |
|
52 | {% endif %} | |||
44 | </div> |
|
53 | </div> | |
45 | {% if post.tags.exists %} |
|
54 | {% if post.tags.exists %} | |
46 | <div class="metadata"> |
|
55 | <div class="metadata"> |
@@ -13,6 +13,7 b'' | |||||
13 | {% block content %} |
|
13 | {% block content %} | |
14 | {% get_current_language as LANGUAGE_CODE %} |
|
14 | {% get_current_language as LANGUAGE_CODE %} | |
15 |
|
15 | |||
|
16 | <script src="{% static 'js/thread_update.js' %}"></script> | |||
16 | <script src="{% static 'js/thread.js' %}"></script> |
|
17 | <script src="{% static 'js/thread.js' %}"></script> | |
17 |
|
18 | |||
18 |
|
|
19 | {% if posts %} |
@@ -53,4 +53,6 b" urlpatterns = patterns(''," | |||||
53 |
|
53 | |||
54 | # API |
|
54 | # API | |
55 | url(r'^api/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 | 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 | import hashlib |
|
1 | import hashlib | |
|
2 | import json | |||
2 | import string |
|
3 | import string | |
3 | from django.core import serializers |
|
4 | from django.core import serializers | |
4 | from django.core.urlresolvers import reverse |
|
5 | from django.core.urlresolvers import reverse | |
@@ -408,13 +409,28 b' def api_get_post(request, post_id):' | |||||
408 | return HttpResponse(content=json) |
|
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 | def get_post(request, post_id): |
|
425 | def get_post(request, post_id): | |
412 | """Get the html of a post. Used for popups.""" |
|
426 | """Get the html of a post. Used for popups.""" | |
413 |
|
427 | |||
414 | post = get_object_or_404(Post, id=post_id) |
|
428 | post = get_object_or_404(Post, id=post_id) | |
|
429 | thread = post.thread | |||
415 |
|
430 | |||
416 | context = RequestContext(request) |
|
431 | context = RequestContext(request) | |
417 | context["post"] = post |
|
432 | context["post"] = post | |
|
433 | context["can_bump"] = thread.can_bump() | |||
418 |
|
434 | |||
419 | return render(request, 'boards/post.html', context) |
|
435 | return render(request, 'boards/post.html', context) | |
420 |
|
436 |
General Comments 0
You need to be logged in to leave comments.
Login now