summaryrefslogtreecommitdiff
path: root/templates/themes/ukko
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-08-05 06:03:40 -0400
committerczaks <marcin@6irc.net>2013-08-05 06:03:40 -0400
commita84c4510fccfdc0cfb6f187633daea10dc70f326 (patch)
tree6077f5211196ae40cac0184bb7cc67b81d320b0b /templates/themes/ukko
parent33c7abf11f3a9b5c0964a2d7a25533c2849dbc78 (diff)
parenta8327c3a37fd22d2aa5d63061c9d3eaa30ae425a (diff)
Merge branch 'master' of github.com:vichan-devel/Tinyboard
Conflicts: js/post-hider.js
Diffstat (limited to 'templates/themes/ukko')
-rw-r--r--templates/themes/ukko/theme.php6
-rw-r--r--templates/themes/ukko/ukko.js108
2 files changed, 96 insertions, 18 deletions
diff --git a/templates/themes/ukko/theme.php b/templates/themes/ukko/theme.php
index 6fa5fa7e..1682b4ec 100644
--- a/templates/themes/ukko/theme.php
+++ b/templates/themes/ukko/theme.php
@@ -25,7 +25,7 @@
foreach($boards as &$_board) {
if(in_array($_board['uri'], explode(' ', $this->settings['exclude'])))
continue;
- $query .= sprintf("SELECT *, '%s' AS `board` FROM `posts_%s` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
+ $query .= sprintf("SELECT *, '%s' AS `board` FROM ``posts_%s`` WHERE `thread` IS NULL UNION ALL ", $_board['uri'], $_board['uri']);
}
$query = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $query);
$query = query($query) or error(db_error());
@@ -48,7 +48,7 @@
$post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['sage'], $post['embed'], $mod ? '?/' : $config['root'], $mod
);
- $posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
+ $posts = prepare(sprintf("SELECT * FROM ``posts_%s`` WHERE `thread` = :id ORDER BY `id` DESC LIMIT :limit", $post['board']));
$posts->bindValue(':id', $post['id']);
$posts->bindValue(':limit', ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT);
$posts->execute() or error(db_error($posts));
@@ -66,7 +66,7 @@
}
if ($posts->rowCount() == ($post['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) {
- $ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM `posts_%s` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
+ $ct = prepare(sprintf("SELECT COUNT(`id`) as `num` FROM ``posts_%s`` WHERE `thread` = :thread UNION ALL SELECT COUNT(`id`) FROM `posts_%s` WHERE `file` IS NOT NULL AND `thread` = :thread", $post['board'], $post['board']));
$ct->bindValue(':thread', $post['id'], PDO::PARAM_INT);
$ct->execute() or error(db_error($count));
diff --git a/templates/themes/ukko/ukko.js b/templates/themes/ukko/ukko.js
index baf0f78d..4a36b394 100644
--- a/templates/themes/ukko/ukko.js
+++ b/templates/themes/ukko/ukko.js
@@ -1,37 +1,115 @@
+(function(){
+
var cache = new Array(),
thread = false,
- loading = false;
+ loading = false,
+ ukkotimer = false;
+if (localStorage.hiddenboards !== null) {
+ localStorage.hiddenboards = "{}";
+}
+
+// Load data from HTML5 localStorage
+var hiddenboards = JSON.parse(localStorage.hiddenboards);
+
+var storeboards = function() {
+ localStorage.hiddenboards = JSON.stringify(hiddenboards);
+};
+
$(document).ready(function() {
- $(window).on('scroll', function() {
- if($(window).scrollTop() + $(window).height() + 100 > $(document).height() && !loading && overflow.length > 0) {
+ var addukkohide = function() {
+ var ukkohide = $('<a href="javascript:void(0);" class="unimportant ukkohide"></a>');
+ var board = $(this).next().data("board");
+ var hr = $("<hr />");
+
+ $(this).append(ukkohide);
+ $(this).append(hr);
+
+ if (hiddenboards[board] !== true) {
+ ukkohide.html(_("(hide threads from this board)"));
+ hr.hide();
+ }
+ else {
+ ukkohide.html(_("(show threads from this board)"));
+ $(this).next().hide();
+ }
+ ukkohide.click(function() {
+ hiddenboards[board] = (hiddenboards[board] !== true);
+ if (hiddenboards[board] !== true) {
+ $('[data-board="'+board+'"]:not([data-cached="yes"])').show().prev().
+ find('.ukkohide').html(_("(hide threads from this board)")).
+ parent().find('hr').hide();
+ }
+ else {
+ $('[data-board="'+board+'"]:not([data-cached="yes"])').hide().prev().
+ find('.ukkohide').html(_("(show threads from this board)"))
+ .parent().find('hr').show();
+ }
+ storeboards();
+ return false;
+ });
+
+ };
+ $("h2").each(addukkohide);
+
+ $('.pages').hide();
+ var loadnext = function() {
+ if (overflow.length == 0) {
+ $('.pages').show().html(_("No more threads to display"));
+ }
+ while($(window).scrollTop() + $(window).height() + 1000 > $(document).height() && !loading && overflow.length > 0) {
var page = '../' + overflow[0].board + '/' + overflow[0].page;
+ thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
+ if (thread.length > 0 && thread.attr("data-cached") !== 'yes') { // already present
+ overflow.shift();
+ continue;
+ }
+
+ var boardheader = $('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a> </h2>');
+
if($.inArray(page, cache) != -1) {
- thread = $('div#thread_' + overflow[0].id);
- if(thread.length > 0) {
- thread.prepend('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a></h2>');
- $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).css('display', 'block'));
- overflow.shift();
+ if (thread.length > 0) {
+ $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
+ boardheader.insertBefore(thread);
+ addukkohide.call(boardheader);
+ $(document).trigger('new_post', thread);
}
+ overflow.shift();
} else {
loading = true;
+ $('.pages').show().html(_("Loading..."));
$.get(page, function(data) {
cache.push(page);
$(data).find('div[id*="thread_"]').each(function() {
- $('body').prepend($(this).css('display', 'none').attr('data-board', overflow[0].board));
+ var checkout = $(this).attr('id').replace('thread_', '');
+ if ($('div#thread_' + checkout + '[data-board="' + overflow[0].board + '"]').length == 0) {
+ $('form[name="postcontrols"]').prepend($(this).css('display', 'none').attr("data-cached", "yes").attr('data-board', overflow[0].board));
+ }
});
- thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
+ thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"][data-cached="yes"]');
+
if(thread.length > 0) {
- thread.prepend('<h2><a href="/' + overflow[0].board + '/">/' + overflow[0].board + '/</a></h2>');
- $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).css('display', 'block'));
- overflow.shift();
+ $('div[id*="thread_"]').last().after(thread.attr('data-board', overflow[0].board).attr("data-cached", "no").css('display', 'block'));
+ boardheader.insertBefore(thread);
+ addukkohide.call(boardheader);
+ $(document).trigger('new_post', thread);
}
+ overflow.shift();
loading = false;
+ $('.pages').hide().html("");
});
+ break;
}
}
- });
+ clearTimeout(ukkotimer);
+ ukkotimer = setTimeout(loadnext, 1000);
+ };
+
+ $(window).on('scroll', loadnext);
+
+ ukkotimer = setTimeout(loadnext, 1000);
+});
-}); \ No newline at end of file
+})();