summaryrefslogtreecommitdiff
path: root/templates/themes
diff options
context:
space:
mode:
authorczaks <marcin@6irc.net>2013-08-02 03:16:34 -0400
committerczaks <marcin@6irc.net>2013-08-02 03:16:34 -0400
commit6f6a20af8eb779f4b8dd703e3d87e72ad9b67908 (patch)
tree737206497fe93ac43fcb7629d3132c616cb932da /templates/themes
parentc9b9b450df92b3f50c9e9919d90bfa905ed0c2b0 (diff)
ukko: javascript major refactor
Diffstat (limited to 'templates/themes')
-rw-r--r--templates/themes/ukko/ukko.js37
1 files changed, 27 insertions, 10 deletions
diff --git a/templates/themes/ukko/ukko.js b/templates/themes/ukko/ukko.js
index 6566335e..99c737d6 100644
--- a/templates/themes/ukko/ukko.js
+++ b/templates/themes/ukko/ukko.js
@@ -1,20 +1,30 @@
+(function(){
+
var cache = new Array(),
thread = false,
loading = false;
$(document).ready(function() {
+ $('.pages').hide();
$(window).on('scroll', function() {
- if($(window).scrollTop() + $(window).height() + 100 > $(document).height() && !loading && overflow.length > 0) {
+ if (overflow.length == 0) {
+ $('.pages').show().html(_("No more threads to display"));
+ }
+ while($(window).scrollTop() + $(window).height() + 500 > $(document).height() && !loading && overflow.length > 0) {
var page = '../' + overflow[0].board + '/' + overflow[0].page;
- 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'));
- $(document).trigger('new_post', thread);
- overflow.shift();
- }
+ thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
+ if (thread.length > 0 && thread.css('display') != 'none') { // already present
+ overflow.shift();
+ continue;
+ }
+
+ if($.inArray(page, cache) != -1 && 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'));
+ $(document).trigger('new_post', thread);
+ overflow.shift();
} else {
loading = true;
+ $('.pages').show().html(_("Loading..."));
$.get(page, function(data) {
cache.push(page);
@@ -23,16 +33,23 @@ $(document).ready(function() {
});
thread = $('div#thread_' + overflow[0].id + '[data-board="' + overflow[0].board + '"]');
- if(thread.length > 0) {
+ if(thread.length > 0 && thread.css('display') != 'none') {
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'));
$(document).trigger('new_post', thread);
overflow.shift();
}
+ else {
+ overflow.shift(); // We missed it? Or already present...
+ }
loading = false;
+ $('.pages').hide().html("");
});
+ break;
}
}
});
});
+
+})();