diff --git a/controllers/public/community_hub_plugin_public_controller.rb b/controllers/public/community_hub_plugin_public_controller.rb index 8815b3c..604b333 100644 --- a/controllers/public/community_hub_plugin_public_controller.rb +++ b/controllers/public/community_hub_plugin_public_controller.rb @@ -81,20 +81,35 @@ class CommunityHubPluginPublicController < PublicController def newer_comments latest_post = params[:latest_post] hub = Article.find(params[:hub]) - posts = Comment.find(:all, :order => "id desc", :conditions => ["id > :id and source_id = :hub", { :id => latest_post, :hub => hub }]) + posts = Comment.find(:all, :order => "id desc", :conditions => ["id > :id and source_id = :hub", { :id => latest_post, :hub => hub }], :limit => 20) if !posts.empty? oldest_post = posts.last.id latest_post = posts.first.id + size = posts.size else oldest_post = 0 latest_post = 0 end - render :partial => "post", :collection => posts, :locals => { :latest_post => latest_post, :oldest_post => oldest_post, :hub => hub } + render :partial => "post", :collection => posts, :locals => { :latest_id => latest_post, :oldest_id => oldest_post, :hub => hub } end + def older_comments + oldest_id = params[:oldest_id] + hub = Article.find(params[:hub]) + posts = Comment.find(:all, :order => "id desc", :conditions => ["id < :id and source_id = :hub", { :id => oldest_id, :hub => hub }], :limit => 20) + + if !posts.empty? + oldest_id = posts.last.id + latest_id = posts.first.id + end + + render :partial => "post", :collection => posts, :locals => { :latest_id => latest_id, :oldest_id => oldest_id, :hub => hub } + end + + def newer_articles latest_post = params[:latest_post] hub = Article.find(params[:hub]) diff --git a/public/javascripts/community_hub.js b/public/javascripts/community_hub.js index 416752e..422ad71 100644 --- a/public/javascripts/community_hub.js +++ b/public/javascripts/community_hub.js @@ -3,24 +3,30 @@ var oldest_post_id = 0; live_scroll_position = 0; var mediations = []; -function validate_textarea(txt) { - return (txt.search(/[^\n\s]/)!=-1); +function load_more_messages() { + + var hub_id = jQuery(".hub").attr('id'); + var oldest_id = jQuery("#live-posts li.post").last().attr("id"); + + jQuery.ajax({ + url: '/plugin/community_hub/public/older_comments', + type: 'get', + data: { oldest_id: oldest_id, hub: hub_id }, + success: function(data) { + if (data.trim().length > 0) { + jQuery("#live-posts").append(data); + } + }, + error: function(ajax, stat, errorThrown) { + } + }); } -function clearLoadingMediationCommentSignal(mediation) { - jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-error"); - jQuery(".loading-mediation-comment").filter("#" + mediation).removeClass("loading-signal-done"); -} -function clearLoadingMessageSignal() { - jQuery("#loading-message").removeClass("loading-signal-error"); - jQuery("#loading-message").removeClass("loading-signal-done"); +function validate_textarea(txt) { + return (txt.search(/[^\n\s]/)!=-1); } -function clearLoadingMediationSignal() { - jQuery("#loading-mediation").removeClass("loading-signal-error"); - jQuery("#loading-mediation").removeClass("loading-signal-done"); -} function toogle_mediation_comments(mediation) { jQuery("#mediation-comment-list-" + mediation ).toggle(); @@ -58,16 +64,10 @@ function new_mediation_comment(button, mediation) { jQuery("#mediation-comment-form-" + mediation + " textarea").val(''); jQuery("#mediation-comment-form-" + mediation + " .submit").attr("disabled", false); update_mediation_comments(mediation, false); - setTimeout(function(){ - clearLoadingMediationCommentSignal(mediation); - }, 3000); mediations.push( [ mediation, setInterval(function() { update_mediation_comments(mediation, false)}, 5000) ] ); } else { jQuery("#mediation-comment-form-" + mediation + " .submit").attr("disabled", false); - setTimeout(function(){ - clearLoadingMediationCommentSignal(mediation); - }, 3000); mediations.push( [ mediation, setInterval(function() { update_mediation_comments(mediation, false)}, 5000) ] ); } }, 'json'); @@ -93,12 +93,9 @@ function new_message(button) { jQuery(".hub .form-message #message_body").val(''); jQuery(".hub .form-message .submit").attr("disabled", false); update_live_stream(false); - setTimeout(clearLoadingMessageSignal, 3000); - } else { jQuery(".hub .form-message .submit").attr("disabled", false); - setTimeout(clearLoadingMessageSignal, 3000); } }, 'json'); @@ -124,11 +121,9 @@ function new_mediation(button) { jQuery(".hub .form-mediation .submit").attr("disabled", false); tinymce.get('article_body').setContent(''); update_mediations(); - setTimeout(clearLoadingMediationSignal, 3000); } else { jQuery(".hub .form-mediation .submit").attr("disabled", false); - setTimeout(clearLoadingMediationSignal, 3000); } }, 'json'); @@ -317,6 +312,14 @@ function hub_right_tab_click() { first_hub_load = true; +jQuery(".hub .live .envelope").scroll(function() { + jQuery("#auto_scrolling").attr('checked', false); + if (jQuery(".hub .live .envelope").scrollTop() == (jQuery(".hub ul#live-posts").height() - jQuery(".hub .live .envelope").height() + 23)) { + load_more_messages(); + } +}); + + jQuery(document).ready(function() { jQuery("#live-posts").scroll(function() { @@ -329,4 +332,5 @@ jQuery(document).ready(function() { update_live_stream(true); update_mediations(); + }); diff --git a/public/style.css b/public/style.css index af2c5a2..d6b2572 100644 --- a/public/style.css +++ b/public/style.css @@ -7,7 +7,7 @@ height: 350px; padding-top: 10px; height: 350px; - display: inline-block; + display: inline-block; } #hub-loading { @@ -174,11 +174,14 @@ margin-bottom: 2em; } +.hub .envelope { + height: 500px; + overflow-x: hidden; + overflow-y: scroll; +} + .hub ul#live-posts, .hub ul#mediation-posts{ - height: 500px; - overflow-x: hidden; - overflow-y: scroll; - border-width: 1px; + border-width: 0 1px 1px; border-style: solid; border-color: lightGray; padding-top: 10px; @@ -257,7 +260,6 @@ text-align: center; margin-top: 9px; line-height: 27px; - } #content .main-block .hub .live h1.mediation {} diff --git a/views/community_hub_plugin_public/_mediation.rhtml b/views/community_hub_plugin_public/_mediation.rhtml index 5e21606..c798ff4 100644 --- a/views/community_hub_plugin_public/_mediation.rhtml +++ b/views/community_hub_plugin_public/_mediation.rhtml @@ -1,6 +1,6 @@ <% extend CommunityHubPlugin::HubHelper %> -