From 720dd9e960b7d402acdedf07537d4f0b0feda566 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Thu, 1 Aug 2013 16:11:00 -0400 Subject: [PATCH] scroll to posts --- public/src/ajaxify.js | 10 ++++-- public/src/app.js | 68 ++++++++++++++++++++++++++++++++++++++ public/src/forum/topic.js | 41 ++++------------------- public/templates/topic.tpl | 6 ++-- src/posts.js | 4 +-- src/topics.js | 9 ++--- src/websockets.js | 11 +++--- 7 files changed, 97 insertions(+), 52 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 98e9f0914e..aa63a1d3fa 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -29,9 +29,10 @@ var ajaxify = {}; // leave room and join global app.enter_room('global'); - var url = url.replace(/\/$/, ""); + var hash = window.location.hash; + if(url.indexOf(RELATIVE_PATH.slice(1)) !== -1) { url = url.slice(RELATIVE_PATH.length); } @@ -67,7 +68,12 @@ var ajaxify = {}; } app.process_page(); - jQuery('#content, #footer').stop(true, true).fadeIn(200); + + jQuery('#content, #footer').stop(true, true).fadeIn(200, function() { + console.log('done loading'); + app.scrollToPost(hash.substr(1)); + }); + }, url, template); return true; diff --git a/public/src/app.js b/public/src/app.js index d5e65818a7..91df13efa2 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -295,6 +295,74 @@ var socket, } } + app.addCommasToNumbers = function() { + $('.formatted-number').each(function(index, element) { + $(element).html(app.addCommas($(element).html())); + }); + } + + app.createNewPosts = function(data) { + data.posts[0].display_moderator_tools = 'none'; + var html = templates.prepare(templates['topic'].blocks['posts']).parse(data), + uniqueid = new Date().getTime(), + tempContainer = jQuery('
') + .appendTo("#post-container") + .hide() + .append(html) + .fadeIn('slow'); + + for(var x=0,numPosts=data.posts.length;x half && !infiniteLoaderActive) { - infiniteLoaderActive = true; - socket.emit('api:topic.loadMore', { - tid: tid, - after: document.querySelectorAll('#post-container li[data-pid]').length - }); + if (document.body.scrollTop > half && !app.infiniteLoaderActive) { + app.loadMorePosts(tid); } }); }); @@ -331,26 +321,7 @@ adjust_rep(-1, data.pid, data.uid); }); - socket.on('event:new_post', function(data) { - data.posts[0].display_moderator_tools = 'none'; - var html = templates.prepare(templates['topic'].blocks['posts']).parse(data), - uniqueid = new Date().getTime(), - tempContainer = jQuery('
') - .appendTo("#post-container") - .hide() - .append(html) - .fadeIn('slow'); - - for(var x=0,numPosts=data.posts.length;x -
    +
      - +
    • @@ -78,7 +78,7 @@ - +
    • diff --git a/src/posts.js b/src/posts.js index 6ebd499197..192c9d536d 100644 --- a/src/posts.js +++ b/src/posts.js @@ -24,9 +24,7 @@ var RDB = require('./redis.js'), callback(posts); }); } else { - callback({ - error: 'no-posts' - }); + callback([]); } }); } diff --git a/src/topics.js b/src/topics.js index b4796d557f..d1105180e5 100644 --- a/src/topics.js +++ b/src/topics.js @@ -41,7 +41,9 @@ marked.setOptions({ Topics.getTopicPosts = function(tid, start, end, current_user, callback) { posts.getPostsByTid(tid, start, end, function(postData) { - + if(Array.isArray(postData) && !postData.length) + return callback([]); + function getFavouritesData(next) { var pids = []; for(var i=0; i