diff --git a/js/expand.js b/js/expand.js
index 0256aebe..0fa8de05 100644
--- a/js/expand.js
+++ b/js/expand.js
@@ -20,8 +20,8 @@ $(document).ready(function(){
var do_expand = function() {
$(this)
.html($(this).text().replace(_("Click reply to view."), ''+_("Click to expand")+'.'))
- .find('a').click(function() {
- var thread = $(this).parent().parent().parent();
+ .find('a').click(window.expand_fun = function() {
+ var thread = $(this).parents('[id^="thread_"]');
var id = thread.attr('id').replace(/^thread_/, '');
$.ajax({
url: thread.find('p.intro a.post_no:first').attr('href'),
@@ -43,12 +43,16 @@ $(document).ready(function(){
last_expanded = post_in_doc;
}
});
- $('' + _('Hide expanded replies') + '.')
- .insertAfter(thread.find('span.omitted').css('display', 'none'))
+
+
+ thread.find("span.omitted").css('display', 'none');
+
+ $('' + _('Hide expanded replies') + '.')
+ .insertAfter(thread.find('.op div.body, .op span.omitted').last())
.click(function() {
thread.find('.expanded').remove();
- $(this).prev().css('display', '');
- $(this).remove();
+ $(this).parent().find(".omitted:not(.hide-expanded)").css('display', '');
+ $(this).parent().find(".hide-expanded").remove();
});
}
});
diff --git a/js/live-index.js b/js/live-index.js
new file mode 100644
index 00000000..dabb34fc
--- /dev/null
+++ b/js/live-index.js
@@ -0,0 +1,84 @@
+/*
+ * live-index.js
+ * https://github.com/vichan-devel/Tinyboard/blob/master/js/live-index.js
+ *
+ * Released under the MIT license
+ * Copyright (c) 2014 Marcin Ćabanowski
+ *
+ * Usage:
+ * $config['api']['enabled'] = true;
+ * $config['additional_javascript'][] = 'js/jquery.min.js';
+ * $config['additional_javascript'][] = 'js/expand.js';
+ * $config['additional_javascript'][] = 'js/live-index.js';
+ *
+ */
+
+if (active_page == 'index' && (""+document.location).match(/\/(index\.html)?(\?|$)/))
++function() {
+ var board_name = (""+document.location).match(/\/([^\/])\/[^/]*$/)[1];
+
+ var handle_one_thread = function() {
+ $(this).find("br.clear").before(""+_("No new posts.")+"
")
+ };
+
+ $(function() {
+ $("hr:first").before("
"+_("No new threads.")+"
");
+
+ $('div[id^="thread_"]').each(handle_one_thread);
+ });
+
+ $(document).on("new_post", function(e, post) {
+ if (!$(post).hasClass("reply")) {
+ handle_one_thread.bind(post);
+ }
+ });
+
+ var update_new_threads = function(i) {
+ var msg = i ?
+ fmt(_("There are {0} new threads."), [i]) :
+ _("No new threads.");
+
+ if ($(".new-threads").html() != msg)
+ $(".new-threads").html(msg);
+ };
+
+ var update_new_posts = function(i, th) {
+ var msg = (i>0) ?
+ (fmt(_("There are {0} new posts in this thread."), [i])+" "+_("Click to expand")+".") :
+ _("No new posts.");
+
+ if ($(th).find(".new-posts").html() != msg) {
+ $(th).find(".new-posts").html(msg);
+ $(th).find(".new-posts a").click(window.expand_fun);
+ }
+ };
+
+ setInterval(function() {
+ $.getJSON(configRoot+board_name+"/0.json", function(j, x, r) {
+ var new_threads = 0;
+
+ j.threads.forEach(function(t) {
+ var s_thread = $("#thread_"+t.posts[0].no);
+
+ if (s_thread.length) {
+ var my_posts = s_thread.find(".post.reply").length;
+
+ var omitted_posts = s_thread.find(".omitted");
+ if (omitted_posts.length) {
+ omitted_posts = omitted_posts.html().match("^[^0-9]*([0-9]+)")[1]|0;
+ my_posts += omitted_posts;
+ }
+
+ my_posts -= t.posts[0].replies|0;
+ my_posts *= -1;
+ update_new_posts(my_posts, s_thread);
+ }
+ else {
+ new_threads++;
+ }
+ });
+
+ update_new_threads(new_threads);
+ });
+ }, 500);
+}();
diff --git a/stylesheets/style.css b/stylesheets/style.css
index 4d6ee5ab..3688b939 100644
--- a/stylesheets/style.css
+++ b/stylesheets/style.css
@@ -627,3 +627,12 @@ form.ban-appeal textarea {
padding: 0;
margin: 5px 25px 5px 5px;
}
+
+/* live-index.js */
+.new-posts {
+ opacity: 0.6;
+ margin-top: 1em;
+}
+.new-threads {
+ text-align: center;
+}