use popState in message inbox

This commit is contained in:
danielgrippi 2011-03-30 16:22:13 -07:00
parent 72d8b4a7e6
commit 5fa2a7a6f3
5 changed files with 41 additions and 38 deletions

View file

@ -1,7 +1,7 @@
class ConversationsController < ApplicationController class ConversationsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html, :json respond_to :html, :json, :js
def index def index
@conversations = Conversation.joins(:conversation_visibilities).where( @conversations = Conversation.joins(:conversation_visibilities).where(
@ -44,17 +44,12 @@ class ConversationsController < ApplicationController
def show def show
@conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id], @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
:conversation_visibilities => {:person_id => current_user.person.id}).first :conversation_visibilities => {:person_id => current_user.person.id}).first
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
@visibility.unread = 0 @visibility.unread = 0
@visibility.save @visibility.save
end end
if @conversation respond_with @conversation
render :layout => false
else
redirect_to conversations_path
end
end end
def new def new

View file

@ -2,8 +2,9 @@
-# licensed under the Affero General Public License version 3 or later. See -# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file. -# the COPYRIGHT file.
%a.conversation{:href => conversations_path(:conversation_id => conversation.id)}
.stream_element.conversation{:data=>{:guid=>conversation.id}, :class => ('unread' if unread_counts[conversation.id].to_i > 0)} .stream_element.conversation{:data=>{:guid=>conversation.id}, :class => ('unread' if unread_counts[conversation.id].to_i > 0)}
= person_image_tag(authors[conversation.id]) = person_image_tag(conversation.author)
.subject .subject
.message_count .message_count

View file

@ -0,0 +1,6 @@
$('#conversation_show').html("<%= escape_javascript(render('conversations/show', :conversation => @conversation)) %>");
$(".stream_element", "#conversation_inbox").removeClass('selected');
$(".stream_element[data-guid='<%= @conversation.id %>']", "#conversation_inbox").addClass('selected');
Diaspora.widgets.timeago.updateTimeAgo();

View file

@ -5,24 +5,15 @@
$(document).ready(function(){ $(document).ready(function(){
var bindIt = function(element){ $('a.conversation').live('click', function(){
var conversationSummary = element, $.getScript(this.href);
conversationGuid = conversationSummary.attr('data-guid'); history.pushState(null, "", this.href);
$.get("conversations/"+conversationGuid, function(data){ return false;
$('.conversation', '.stream').removeClass('selected');
conversationSummary.addClass('selected').removeClass('unread');
$('#conversation_show').html(data);
Diaspora.widgets.timeago.updateTimeAgo();
}); });
if (typeof(history.pushState) == 'function') { $(window).bind("popstate", function(){
history.pushState(null, document.title, '?conversation_id='+conversationGuid); $.getScript(location.href);
} return false;
}
$('.conversation', '.stream').bind('mousedown', function(){
bindIt($(this));
}); });
resize(); resize();

View file

@ -320,6 +320,11 @@ header
:margin 0 :margin 0
:padding 0 :padding 0
#conversation_inbox a
&:hover
:text
:decoration none
.stream_element .stream_element
:position relative :position relative
:word-wrap break-word :word-wrap break-word
@ -2621,7 +2626,12 @@ div.dislikes
&:hover:not(.selected) &:hover:not(.selected)
:background :background
:color #f0f0f0 :color #fafafa
&.selected:hover
:background
:color lighten($blue,5%)
&:hover &:hover
:cursor pointer :cursor pointer