##// END OF EJS Templates
Don't run time conversion if Intl not available in browser. Also convert...
neko259 -
r1023:0040ea34 default
parent child Browse files
Show More
@@ -1,93 +1,99 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 LOCALE = window.navigator.language;
26 if (window.Intl) {
27 var FORMATTER = new Intl.DateTimeFormat(
27 var LOCALE = window.navigator.language;
28 LOCALE,
28 var FORMATTER = new Intl.DateTimeFormat(
29 {
29 LOCALE,
30 weekday: 'short', year: 'numeric', month: 'short', day: 'numeric',
30 {
31 hour: 'numeric', minute: '2-digit', second: '2-digit'
31 weekday: 'short', year: 'numeric', month: 'short', day: 'numeric',
32 }
32 hour: 'numeric', minute: '2-digit', second: '2-digit'
33 );
33 }
34 );
35 }
34
36
35 /**
37 /**
36 * An email is a hidden file to prevent spam bots from posting. It has to be
38 * An email is a hidden file to prevent spam bots from posting. It has to be
37 * hidden.
39 * hidden.
38 */
40 */
39 function hideEmailFromForm() {
41 function hideEmailFromForm() {
40 $('.form-email').parent().parent().hide();
42 $('.form-email').parent().parent().hide();
41 }
43 }
42
44
43 /**
45 /**
44 * Highlight code blocks with code highlighter
46 * Highlight code blocks with code highlighter
45 */
47 */
46 function highlightCode(node) {
48 function highlightCode(node) {
47 node.find('pre code').each(function(i, e) {
49 node.find('pre code').each(function(i, e) {
48 hljs.highlightBlock(e);
50 hljs.highlightBlock(e);
49 });
51 });
50 }
52 }
51
53
52 /**
54 /**
53 * Translate timestamps to local ones for all <time> tags inside node.
55 * Translate timestamps to local ones for all <time> tags inside node.
54 */
56 */
55 function translate_time(node) {
57 function translate_time(node) {
58 if (window.Intl === null) {
59 return;
60 }
61
56 var elements;
62 var elements;
57
63
58 if (node === null) {
64 if (node === null) {
59 elements = $('time');
65 elements = $('time');
60 } else {
66 } else {
61 elements = node.find('time');
67 elements = node.find('time');
62 }
68 }
63
69
64 if (!elements.length) {
70 if (!elements.length) {
65 return;
71 return;
66 }
72 }
67
73
68 elements.each(function() {
74 elements.each(function() {
69 var element = $(this);
75 var element = $(this);
70 var dateAttr = element.attr('datetime');
76 var dateAttr = element.attr('datetime');
71 if (dateAttr) {
77 if (dateAttr) {
72 var date = new Date(dateAttr);
78 var date = new Date(dateAttr);
73 element.text(FORMATTER.format(date));
79 element.text(FORMATTER.format(date));
74 }
80 }
75 });
81 });
76 }
82 }
77
83
78 $( document ).ready(function() {
84 $( document ).ready(function() {
79 hideEmailFromForm();
85 hideEmailFromForm();
80
86
81 $("a[href='#top']").click(function() {
87 $("a[href='#top']").click(function() {
82 $("html, body").animate({ scrollTop: 0 }, "slow");
88 $("html, body").animate({ scrollTop: 0 }, "slow");
83 return false;
89 return false;
84 });
90 });
85
91
86 addImgPreview();
92 addImgPreview();
87
93
88 addRefLinkPreview();
94 addRefLinkPreview();
89
95
90 highlightCode($(document));
96 highlightCode($(document));
91
97
92 translate_time(null);
98 translate_time(null);
93 });
99 });
@@ -1,97 +1,97 b''
1 {% load i18n %}
1 {% load i18n %}
2 {% load board %}
2 {% load board %}
3 {% load cache %}
3 {% load cache %}
4
4
5 {% get_current_language as LANGUAGE_CODE %}
5 {% get_current_language as LANGUAGE_CODE %}
6
6
7 {% if thread.archived %}
7 {% if thread.archived %}
8 <div class="post archive_post" id="{{ post.id }}">
8 <div class="post archive_post" id="{{ post.id }}">
9 {% elif bumpable %}
9 {% elif bumpable %}
10 <div class="post" id="{{ post.id }}">
10 <div class="post" id="{{ post.id }}">
11 {% else %}
11 {% else %}
12 <div class="post dead_post" id="{{ post.id }}">
12 <div class="post dead_post" id="{{ post.id }}">
13 {% endif %}
13 {% endif %}
14
14
15 <div class="post-info">
15 <div class="post-info">
16 <a class="post_id" href="{{ post.get_url }}"
16 <a class="post_id" href="{{ post.get_url }}"
17 {% if not truncated and not thread.archived %}
17 {% if not truncated and not thread.archived %}
18 onclick="javascript:addQuickReply('{{ post.id }}'); return false;"
18 onclick="javascript:addQuickReply('{{ post.id }}'); return false;"
19 title="{% trans 'Quote' %}" {% endif %}>({{ post.get_absolute_id }})</a>
19 title="{% trans 'Quote' %}" {% endif %}>({{ post.get_absolute_id }})</a>
20 <span class="title">{{ post.title }}</span>
20 <span class="title">{{ post.title }}</span>
21 <span class="pub_time"><time datetime="{{ post.pub_time|date:'c' }}">{{ post.pub_time|date:'r' }}</time></span>
21 <span class="pub_time"><time datetime="{{ post.pub_time|date:'c' }}">{{ post.pub_time|date:'r' }}</time></span>
22 {% comment %}
22 {% comment %}
23 Thread death time needs to be shown only if the thread is alredy archived
23 Thread death time needs to be shown only if the thread is alredy archived
24 and this is an opening post (thread death time) or a post for popup
24 and this is an opening post (thread death time) or a post for popup
25 (we don't see OP here so we show the death time in the post itself).
25 (we don't see OP here so we show the death time in the post itself).
26 {% endcomment %}
26 {% endcomment %}
27 {% if thread.archived %}
27 {% if thread.archived %}
28 {% if is_opening %}
28 {% if is_opening %}
29 β€” {{ thread.bump_time }}
29 β€” <time datetime="{{ thread.bump_time|date:'c' }}">{{ thread.bump_time|date:'r' }}</time>
30 {% endif %}
30 {% endif %}
31 {% endif %}
31 {% endif %}
32 {% if is_opening and need_open_link %}
32 {% if is_opening and need_open_link %}
33 {% if thread.archived %}
33 {% if thread.archived %}
34 [<a class="link" href="{% url 'thread' post.id %}">{% trans "Open" %}</a>]
34 [<a class="link" href="{% url 'thread' post.id %}">{% trans "Open" %}</a>]
35 {% else %}
35 {% else %}
36 [<a class="link" href="{% url 'thread' post.id %}#form">{% trans "Reply" %}</a>]
36 [<a class="link" href="{% url 'thread' post.id %}#form">{% trans "Reply" %}</a>]
37 {% endif %}
37 {% endif %}
38 {% endif %}
38 {% endif %}
39
39
40 {% if moderator %}
40 {% if moderator %}
41 <span class="moderator_info">
41 <span class="moderator_info">
42 [<a href="{% url 'admin:boards_post_change' post.id %}">{% trans 'Edit' %}</a>]
42 [<a href="{% url 'admin:boards_post_change' post.id %}">{% trans 'Edit' %}</a>]
43 {% if is_opening %}
43 {% if is_opening %}
44 [<a href="{% url 'admin:boards_thread_change' thread.id %}">{% trans 'Edit thread' %}</a>]
44 [<a href="{% url 'admin:boards_thread_change' thread.id %}">{% trans 'Edit thread' %}</a>]
45 {% endif %}
45 {% endif %}
46 </span>
46 </span>
47 {% endif %}
47 {% endif %}
48 </div>
48 </div>
49 {% comment %}
49 {% comment %}
50 Post images. Currently only 1 image can be posted and shown, but post model
50 Post images. Currently only 1 image can be posted and shown, but post model
51 supports multiple.
51 supports multiple.
52 {% endcomment %}
52 {% endcomment %}
53 {% if post.images.exists %}
53 {% if post.images.exists %}
54 {% with post.images.all.0 as image %}
54 {% with post.images.all.0 as image %}
55 {% autoescape off %}
55 {% autoescape off %}
56 {{ image.get_view }}
56 {{ image.get_view }}
57 {% endautoescape %}
57 {% endautoescape %}
58 {% endwith %}
58 {% endwith %}
59 {% endif %}
59 {% endif %}
60 {% comment %}
60 {% comment %}
61 Post message (text)
61 Post message (text)
62 {% endcomment %}
62 {% endcomment %}
63 <div class="message">
63 <div class="message">
64 {% autoescape off %}
64 {% autoescape off %}
65 {% if truncated %}
65 {% if truncated %}
66 {{ post.get_text|truncatewords_html:50 }}
66 {{ post.get_text|truncatewords_html:50 }}
67 {% else %}
67 {% else %}
68 {{ post.get_text }}
68 {{ post.get_text }}
69 {% endif %}
69 {% endif %}
70 {% endautoescape %}
70 {% endautoescape %}
71 {% if post.is_referenced %}
71 {% if post.is_referenced %}
72 <div class="refmap">
72 <div class="refmap">
73 {% autoescape off %}
73 {% autoescape off %}
74 {% trans "Replies" %}: {{ post.refmap }}
74 {% trans "Replies" %}: {{ post.refmap }}
75 {% endautoescape %}
75 {% endautoescape %}
76 </div>
76 </div>
77 {% endif %}
77 {% endif %}
78 </div>
78 </div>
79 {% comment %}
79 {% comment %}
80 Thread metadata: counters, tags etc
80 Thread metadata: counters, tags etc
81 {% endcomment %}
81 {% endcomment %}
82 {% if is_opening %}
82 {% if is_opening %}
83 <div class="metadata">
83 <div class="metadata">
84 {% if is_opening and need_open_link %}
84 {% if is_opening and need_open_link %}
85 {{ thread.get_reply_count }} {% trans 'messages' %},
85 {{ thread.get_reply_count }} {% trans 'messages' %},
86 {{ thread.get_images_count }} {% trans 'images' %}.
86 {{ thread.get_images_count }} {% trans 'images' %}.
87 {% endif %}
87 {% endif %}
88 <span class="tags">
88 <span class="tags">
89 {% autoescape off %}
89 {% autoescape off %}
90 {% for tag in thread.get_tags %}
90 {% for tag in thread.get_tags %}
91 {{ tag.get_view }}{% if not forloop.last %},{% endif %}
91 {{ tag.get_view }}{% if not forloop.last %},{% endif %}
92 {% endfor %}
92 {% endfor %}
93 {% endautoescape %}
93 {% endautoescape %}
94 </span>
94 </span>
95 </div>
95 </div>
96 {% endif %}
96 {% endif %}
97 </div>
97 </div>
General Comments 0
You need to be logged in to leave comments. Login now