##// END OF EJS Templates
Fixed thread OP id in thread view. Fixed reply count in thread view
neko259 -
r404:80f183eb 1.4 default
parent child Browse files
Show More
@@ -1,127 +1,127 b''
1 /*
1 /*
2 @licstart The following is the entire license notice for the
2 @licstart The following is the entire license notice for the
3 JavaScript code in this page.
3 JavaScript code in this page.
4
4
5
5
6 Copyright (C) 2013 neko259
6 Copyright (C) 2013 neko259
7
7
8 The JavaScript code in this page is free software: you can
8 The JavaScript code in this page is free software: you can
9 redistribute it and/or modify it under the terms of the GNU
9 redistribute it and/or modify it under the terms of the GNU
10 General Public License (GNU GPL) as published by the Free Software
10 General Public License (GNU GPL) as published by the Free Software
11 Foundation, either version 3 of the License, or (at your option)
11 Foundation, either version 3 of the License, or (at your option)
12 any later version. The code is distributed WITHOUT ANY WARRANTY;
12 any later version. The code is distributed WITHOUT ANY WARRANTY;
13 without even the implied warranty of MERCHANTABILITY or FITNESS
13 without even the implied warranty of MERCHANTABILITY or FITNESS
14 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
14 FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
15
15
16 As additional permission under GNU GPL version 3 section 7, you
16 As additional permission under GNU GPL version 3 section 7, you
17 may distribute non-source (e.g., minimized or compacted) forms of
17 may distribute non-source (e.g., minimized or compacted) forms of
18 that code without the copy of the GNU GPL normally required by
18 that code without the copy of the GNU GPL normally required by
19 section 4, provided you include this license notice and a URL
19 section 4, provided you include this license notice and a URL
20 through which recipients can access the Corresponding Source.
20 through which recipients can access the Corresponding Source.
21
21
22 @licend The above is the entire license notice
22 @licend The above is the entire license notice
23 for the JavaScript code in this page.
23 for the JavaScript code in this page.
24 */
24 */
25
25
26 var THREAD_UPDATE_DELAY = 10000;
26 var THREAD_UPDATE_DELAY = 10000;
27
27
28 var loading = false;
28 var loading = false;
29 var lastUpdateTime = null;
29 var lastUpdateTime = null;
30
30
31 function blink(node) {
31 function blink(node) {
32 var blinkCount = 2;
32 var blinkCount = 2;
33 var blinkDelay = 250;
33 var blinkDelay = 250;
34
34
35 var nodeToAnimate = node;
35 var nodeToAnimate = node;
36 for (var i = 0; i < blinkCount; i++) {
36 for (var i = 0; i < blinkCount; i++) {
37 nodeToAnimate = nodeToAnimate.fadeOut(blinkDelay).fadeIn(blinkDelay);
37 nodeToAnimate = nodeToAnimate.fadeOut(blinkDelay).fadeIn(blinkDelay);
38 }
38 }
39 }
39 }
40
40
41 function updateThread() {
41 function updateThread() {
42 if (loading) {
42 if (loading) {
43 return;
43 return;
44 }
44 }
45
45
46 loading = true;
46 loading = true;
47
47
48 var threadPosts = $('div.thread').children('.post');
48 var threadPosts = $('div.thread').children('.post');
49
49
50 var lastPost = threadPosts.last();
50 var lastPost = threadPosts.last();
51 var threadId = threadPosts.first().attr('id');
51 var threadId = threadPosts.first().attr('id');
52
52
53 var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/';
53 var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/';
54 $.getJSON(diffUrl)
54 $.getJSON(diffUrl)
55 .success(function(data) {
55 .success(function(data) {
56 var bottom = isPageBottom();
56 var bottom = isPageBottom();
57
57
58 var addedPosts = data.added;
58 var addedPosts = data.added;
59
59
60 for (var i = 0; i < addedPosts.length; i++) {
60 for (var i = 0; i < addedPosts.length; i++) {
61 var postText = addedPosts[i];
61 var postText = addedPosts[i];
62
62
63 var post = $(postText);
63 var post = $(postText);
64 post.appendTo(lastPost.parent());
64 post.appendTo(lastPost.parent());
65 addRefLinkPreview(post[0]);
65 addRefLinkPreview(post[0]);
66
66
67 lastPost = post;
67 lastPost = post;
68 blink(post);
68 blink(post);
69 }
69 }
70
70
71 var updatedPosts = data.updated;
71 var updatedPosts = data.updated;
72 for (var i = 0; i < updatedPosts.length; i++) {
72 for (var i = 0; i < updatedPosts.length; i++) {
73 var postText = updatedPosts[i];
73 var postText = updatedPosts[i];
74
74
75 var post = $(postText);
75 var post = $(postText);
76 var postId = post.attr('id');
76 var postId = post.attr('id');
77
77
78 var oldPost = $('div.thread').children('.post[id=' + postId + ']');
78 var oldPost = $('div.thread').children('.post[id=' + postId + ']');
79
79
80 oldPost.replaceWith(post);
80 oldPost.replaceWith(post);
81 addRefLinkPreview(post[0]);
81 addRefLinkPreview(post[0]);
82
82
83 blink(post);
83 blink(post);
84 }
84 }
85
85
86 // TODO Process deleted posts
86 // TODO Process deleted posts
87
87
88 lastUpdateTime = data.last_update;
88 lastUpdateTime = data.last_update;
89 loading = false;
89 loading = false;
90
90
91 if (bottom) {
91 if (bottom) {
92 var $target = $('html,body');
92 var $target = $('html,body');
93 $target.animate({scrollTop: $target.height()}, 1000);
93 $target.animate({scrollTop: $target.height()}, 1000);
94 }
94 }
95
95
96 $('#reply-count').text(getReplyCount());
96 $('#reply-count').text(getReplyCount());
97 $('#image-count').text(getImageCount());
97 $('#image-count').text(getImageCount());
98 })
98 })
99 .error(function(data) {
99 .error(function(data) {
100 // TODO Show error message that server is unavailable?
100 // TODO Show error message that server is unavailable?
101
101
102 loading = false;
102 loading = false;
103 });
103 });
104 }
104 }
105
105
106 function isPageBottom() {
106 function isPageBottom() {
107 var scroll = $(window).scrollTop() / ($(document).height()
107 var scroll = $(window).scrollTop() / ($(document).height()
108 - $(window).height())
108 - $(window).height())
109
109
110 return scroll == 1
110 return scroll == 1
111 }
111 }
112
112
113 function initAutoupdate() {
113 function initAutoupdate() {
114 loading = false;
114 loading = false;
115
115
116 lastUpdateTime = $('.metapanel').attr('data-last-update');
116 lastUpdateTime = $('.metapanel').attr('data-last-update');
117
117
118 setInterval(updateThread, THREAD_UPDATE_DELAY);
118 setInterval(updateThread, THREAD_UPDATE_DELAY);
119 }
119 }
120
120
121 function getReplyCount() {
121 function getReplyCount() {
122 return $('.thread').children('.post').length - 1
122 return $('.thread').children('.post').length
123 }
123 }
124
124
125 function getImageCount() {
125 function getImageCount() {
126 return $('.thread').find('img').length
126 return $('.thread').find('img').length
127 }
127 }
@@ -1,161 +1,161 b''
1 {% extends "boards/base.html" %}
1 {% extends "boards/base.html" %}
2
2
3 {% load i18n %}
3 {% load i18n %}
4 {% load cache %}
4 {% load cache %}
5 {% load static from staticfiles %}
5 {% load static from staticfiles %}
6 {% load board %}
6 {% load board %}
7
7
8 {% block head %}
8 {% block head %}
9 <title>Neboard - {{ thread.get_replies.0.get_title }}</title>
9 <title>Neboard - {{ thread.get_replies.0.get_title }}</title>
10 {% endblock %}
10 {% endblock %}
11
11
12 {% block content %}
12 {% block content %}
13 {% get_current_language as LANGUAGE_CODE %}
13 {% get_current_language as LANGUAGE_CODE %}
14
14
15 <script src="{% static 'js/thread_update.js' %}"></script>
15 <script src="{% static 'js/thread_update.js' %}"></script>
16 <script src="{% static 'js/thread.js' %}"></script>
16 <script src="{% static 'js/thread.js' %}"></script>
17
17
18 {% cache 600 thread_view thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
18 {% cache 600 thread_view thread.id thread.last_edit_time moderator LANGUAGE_CODE %}
19 {% if bumpable %}
19 {% if bumpable %}
20 <div class="bar-bg">
20 <div class="bar-bg">
21 <div class="bar-value" style="width:{{ bumplimit_progress }}%">
21 <div class="bar-value" style="width:{{ bumplimit_progress }}%">
22 </div>
22 </div>
23 <div class="bar-text">
23 <div class="bar-text">
24 {{ posts_left }} {% trans 'posts to bumplimit' %}
24 {{ posts_left }} {% trans 'posts to bumplimit' %}
25 </div>
25 </div>
26 </div>
26 </div>
27 {% endif %}
27 {% endif %}
28 <div class="thread">
28 <div class="thread">
29 {% for post in thread.get_replies %}
29 {% for post in thread.get_replies %}
30 {% if bumpable %}
30 {% if bumpable %}
31 <div class="post" id="{{ post.id }}">
31 <div class="post" id="{{ post.id }}">
32 {% else %}
32 {% else %}
33 <div class="post dead_post" id="{{ post.id }}">
33 <div class="post dead_post" id="{{ post.id }}">
34 {% endif %}
34 {% endif %}
35 {% if post.image %}
35 {% if post.image %}
36 <div class="image">
36 <div class="image">
37 <a
37 <a
38 class="thumb"
38 class="thumb"
39 href="{{ post.image.url }}"><img
39 href="{{ post.image.url }}"><img
40 src="{{ post.image.url_200x150 }}"
40 src="{{ post.image.url_200x150 }}"
41 alt="{{ post.id }}"
41 alt="{{ post.id }}"
42 data-width="{{ post.image_width }}"
42 data-width="{{ post.image_width }}"
43 data-height="{{ post.image_height }}"/>
43 data-height="{{ post.image_height }}"/>
44 </a>
44 </a>
45 </div>
45 </div>
46 {% endif %}
46 {% endif %}
47 <div class="message">
47 <div class="message">
48 <div class="post-info">
48 <div class="post-info">
49 <span class="title">{{ post.title }}</span>
49 <span class="title">{{ post.title }}</span>
50 <a class="post_id" href="#{{ post.id }}">
50 <a class="post_id" href="#{{ post.id }}">
51 ({{ post.id }})</a>
51 ({{ post.id }})</a>
52 [{{ post.pub_time }}]
52 [{{ post.pub_time }}]
53 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
53 [<a href="#" onclick="javascript:addQuickReply('{{ post.id }}')
54 ; return false;">&gt;&gt;</a>]
54 ; return false;">&gt;&gt;</a>]
55
55
56 {% if moderator %}
56 {% if moderator %}
57 <span class="moderator_info">
57 <span class="moderator_info">
58 [<a href="{% url 'delete' post_id=post.id %}"
58 [<a href="{% url 'delete' post_id=post.id %}"
59 >{% trans 'Delete' %}</a>]
59 >{% trans 'Delete' %}</a>]
60 ({{ post.poster_ip }})
60 ({{ post.poster_ip }})
61 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
61 [<a href="{% url 'ban' post_id=post.id %}?next={{ request.path }}"
62 >{% trans 'Ban IP' %}</a>]
62 >{% trans 'Ban IP' %}</a>]
63 </span>
63 </span>
64 {% endif %}
64 {% endif %}
65 </div>
65 </div>
66 {% autoescape off %}
66 {% autoescape off %}
67 {{ post.text.rendered }}
67 {{ post.text.rendered }}
68 {% endautoescape %}
68 {% endautoescape %}
69 {% if post.is_referenced %}
69 {% if post.is_referenced %}
70 <div class="refmap">
70 <div class="refmap">
71 {% trans "Replies" %}:
71 {% trans "Replies" %}:
72 {% for ref_post in post.get_sorted_referenced_posts %}
72 {% for ref_post in post.get_sorted_referenced_posts %}
73 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
73 <a href="{% post_url ref_post.id %}">&gt;&gt;{{ ref_post.id }}</a
74 >{% if not forloop.last %},{% endif %}
74 >{% if not forloop.last %},{% endif %}
75 {% endfor %}
75 {% endfor %}
76 </div>
76 </div>
77 {% endif %}
77 {% endif %}
78 </div>
78 </div>
79 {% if forloop.first %}
79 {% if forloop.first %}
80 <div class="metadata">
80 <div class="metadata">
81 <span class="tags">
81 <span class="tags">
82 {% for tag in thread.get_tags %}
82 {% for tag in thread.get_tags %}
83 <a class="tag" href="{% url 'tag' tag.name %}">
83 <a class="tag" href="{% url 'tag' tag.name %}">
84 #{{ tag.name }}</a
84 #{{ tag.name }}</a
85 >{% if not forloop.last %},{% endif %}
85 >{% if not forloop.last %},{% endif %}
86 {% endfor %}
86 {% endfor %}
87 </span>
87 </span>
88 </div>
88 </div>
89 {% endif %}
89 {% endif %}
90 </div>
90 </div>
91 {% endfor %}
91 {% endfor %}
92 </div>
92 </div>
93 {% endcache %}
93 {% endcache %}
94
94
95 <form id="form" enctype="multipart/form-data" method="post"
95 <form id="form" enctype="multipart/form-data" method="post"
96 >{% csrf_token %}
96 >{% csrf_token %}
97 <div class="post-form-w">
97 <div class="post-form-w">
98 <div class="form-title">{% trans "Reply to thread" %} #{{ posts.0.id }}</div>
98 <div class="form-title">{% trans "Reply to thread" %} #{{ thread.get_opening_post.id }}</div>
99 <div class="post-form">
99 <div class="post-form">
100 <div class="form-row">
100 <div class="form-row">
101 <div class="form-label">{% trans 'Title' %}</div>
101 <div class="form-label">{% trans 'Title' %}</div>
102 <div class="form-input">{{ form.title }}</div>
102 <div class="form-input">{{ form.title }}</div>
103 <div class="form-errors">{{ form.title.errors }}</div>
103 <div class="form-errors">{{ form.title.errors }}</div>
104 </div>
104 </div>
105 <div class="form-row">
105 <div class="form-row">
106 <div class="form-label">{% trans 'Formatting' %}</div>
106 <div class="form-label">{% trans 'Formatting' %}</div>
107 <div class="form-input" id="mark_panel">
107 <div class="form-input" id="mark_panel">
108 <span class="mark_btn" id="quote"><span class="quote">&gt;{% trans 'quote' %}</span></span>
108 <span class="mark_btn" id="quote"><span class="quote">&gt;{% trans 'quote' %}</span></span>
109 <span class="mark_btn" id="italic"><i>{% trans 'italic' %}</i></span>
109 <span class="mark_btn" id="italic"><i>{% trans 'italic' %}</i></span>
110 <span class="mark_btn" id="bold"><b>{% trans 'bold' %}</b></span>
110 <span class="mark_btn" id="bold"><b>{% trans 'bold' %}</b></span>
111 <span class="mark_btn" id="spoiler"><span class="spoiler">{% trans 'spoiler' %}</span></span>
111 <span class="mark_btn" id="spoiler"><span class="spoiler">{% trans 'spoiler' %}</span></span>
112 <span class="mark_btn" id="comment"><span class="comment">// {% trans 'comment' %}</span></span>
112 <span class="mark_btn" id="comment"><span class="comment">// {% trans 'comment' %}</span></span>
113 </div>
113 </div>
114 </div>
114 </div>
115 <div class="form-row">
115 <div class="form-row">
116 <div class="form-label">{% trans 'Text' %}</div>
116 <div class="form-label">{% trans 'Text' %}</div>
117 <div class="form-input">{{ form.text }}</div>
117 <div class="form-input">{{ form.text }}</div>
118 <div class="form-errors">{{ form.text.errors }}</div>
118 <div class="form-errors">{{ form.text.errors }}</div>
119 </div>
119 </div>
120 <div class="form-row">
120 <div class="form-row">
121 <div class="form-label">{% trans 'Image' %}</div>
121 <div class="form-label">{% trans 'Image' %}</div>
122 <div class="form-input">{{ form.image }}</div>
122 <div class="form-input">{{ form.image }}</div>
123 <div class="form-errors">{{ form.image.errors }}</div>
123 <div class="form-errors">{{ form.image.errors }}</div>
124 </div>
124 </div>
125 <div class="form-row form-email">
125 <div class="form-row form-email">
126 <div class="form-label">{% trans 'e-mail' %}</div>
126 <div class="form-label">{% trans 'e-mail' %}</div>
127 <div class="form-input">{{ form.email }}</div>
127 <div class="form-input">{{ form.email }}</div>
128 <div class="form-errors">{{ form.email.errors }}</div>
128 <div class="form-errors">{{ form.email.errors }}</div>
129 </div>
129 </div>
130 <div class="form-row">
130 <div class="form-row">
131 {{ form.captcha }}
131 {{ form.captcha }}
132 <div class="form-errors">{{ form.captcha.errors }}</div>
132 <div class="form-errors">{{ form.captcha.errors }}</div>
133 </div>
133 </div>
134 <div class="form-row">
134 <div class="form-row">
135 <div class="form-errors">{{ form.other.errors }}</div>
135 <div class="form-errors">{{ form.other.errors }}</div>
136 </div>
136 </div>
137 </div>
137 </div>
138
138
139 <div class="form-submit"><input type="submit"
139 <div class="form-submit"><input type="submit"
140 value="{% trans "Post" %}"/></div>
140 value="{% trans "Post" %}"/></div>
141 <div><a href="{% url "staticpage" name="help" %}">
141 <div><a href="{% url "staticpage" name="help" %}">
142 {% trans 'Text syntax' %}</a></div>
142 {% trans 'Text syntax' %}</a></div>
143 </div>
143 </div>
144 </form>
144 </form>
145
145
146 {% endblock %}
146 {% endblock %}
147
147
148 {% block metapanel %}
148 {% block metapanel %}
149
149
150 {% get_current_language as LANGUAGE_CODE %}
150 {% get_current_language as LANGUAGE_CODE %}
151
151
152 <span class="metapanel" data-last-update="{{ last_update }}">
152 <span class="metapanel" data-last-update="{{ last_update }}">
153 {% cache 600 thread_meta thread.last_edit_time moderator LANGUAGE_CODE %}
153 {% cache 600 thread_meta thread.last_edit_time moderator LANGUAGE_CODE %}
154 <span id="reply-count">{{ thread.get_reply_count }}</span> {% trans 'replies' %},
154 <span id="reply-count">{{ thread.get_reply_count }}</span> {% trans 'replies' %},
155 <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}.
155 <span id="image-count">{{ thread.get_images_count }}</span> {% trans 'images' %}.
156 {% trans 'Last update: ' %}{{ thread.last_edit_time }}
156 {% trans 'Last update: ' %}{{ thread.last_edit_time }}
157 [<a href="rss/">RSS</a>]
157 [<a href="rss/">RSS</a>]
158 {% endcache %}
158 {% endcache %}
159 </span>
159 </span>
160
160
161 {% endblock %}
161 {% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now