using two less delegates in mobilejs; made some partials for mobile stream elements for sanity's sake

This commit is contained in:
danielgrippi 2011-10-02 12:26:56 -07:00
parent 164b395f06
commit 9672c27232
7 changed files with 90 additions and 103 deletions

View file

@ -21,7 +21,7 @@ class LikesController < ApplicationController
format.js { render 'likes/update', :status => 201 }
format.html { render :nothing => true, :status => 201 }
format.mobile { redirect_to post_path(@like.post_id) }
format.json { render :nothing => true, :status => 201 }
format.json { render :json => {"id" => @like.id}, :status => 201 }
end
else
render :nothing => true, :status => 422

View file

@ -4,33 +4,10 @@
.reshare
- if post
.photo_area
- if post.is_a?(StatusMessage)
-if post.photos.size > 0
.photo_attachments
- if post.photos.size > 1
.additional_photo_count
= "+ #{post.photos.size-1}"
= image_tag post.photos.first.url(:thumb_large), :class => "stream-photo big-stream-photo"
- elsif post.activity_streams?
= image_tag post.image_url
= render 'shared/photo_area', :post => post
.content
.from
= person_image_link(post.author, :size => :thumb_small)
= person_link(post.author)
.info
%span.time{:integer => post.created_at.to_i}
= t('ago', :time => time_ago_in_words(post.created_at))
%span.via
- if post.activity_streams?
= t('shared.stream_element.via', :link => link_to("#{post.provider_display_name}", post.actor_url)).html_safe
&ndash;
%span.scope_scope
- if post.public?
= t('public')
- else
= t('limited')
= render 'shared/post_info', :post => post
- if !post.activity_streams?
= render 'status_messages/status_message', :post => post, :photos => post.photos

View file

@ -0,0 +1,15 @@
-# Copyright (c) 2010-2011, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.photo_area
- if post.is_a?(StatusMessage)
-if post.photos.size > 0
.photo_attachments
- if post.photos.size > 1
.additional_photo_count
= "+ #{post.photos.size-1}"
= image_tag post.photos.first.url(:thumb_large), :class => "stream-photo big-stream-photo"
- elsif post.activity_streams?
= image_tag post.image_url

View file

@ -0,0 +1,23 @@
-# Copyright (c) 2010-2011, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.from
= person_image_link(post.author, :size => :thumb_small)
= person_link(post.author)
.info
%span.time{:integer => post.created_at.to_i}
= t('ago', :time => time_ago_in_words(post.created_at))
%span.via
- if post.activity_streams?
= t('shared.stream_element.via', :link => link_to("#{post.provider_display_name}", post.actor_url)).html_safe
- elsif post.provider_display_name == 'mobile'
= t('shared.stream_element.via', :link => nil)
mobile
&ndash;
%span.scope_scope
- if post.public?
= t('public')
- else
= t('limited')

View file

@ -7,38 +7,10 @@
- if post.is_a?(Reshare)
= render 'reshares/reshare', :reshare => post, :post => post.root
.photo_area
- if post.is_a?(StatusMessage)
-if post.photos.size > 0
.photo_attachments
- if post.photos.size > 1
.additional_photo_count
= "+ #{post.photos.size-1}"
= image_tag post.photos.first.url(:thumb_large), :class => "stream-photo big-stream-photo"
- elsif post.activity_streams?
= image_tag post.image_url
= render 'shared/photo_area', :post => post
.content
.from
= person_image_link(post.author, :size => :thumb_small)
= person_link(post.author)
.info
%span.time{:integer => post.created_at.to_i}
= t('ago', :time => time_ago_in_words(post.created_at))
%span.via
- if post.activity_streams?
= t('.via', :link => link_to("#{post.provider_display_name}", post.actor_url)).html_safe
- elsif post.provider_display_name == 'mobile'
= t('.via', :link => nil)
mobile
&ndash;
%span.scope_scope
- if post.public?
= t('public')
- else
= t('limited')
= render 'shared/post_info', :post => post
- if post.is_a?(StatusMessage)
= render 'status_messages/status_message', :post => post, :photos => post.photos

View file

@ -1,58 +1,59 @@
$(document).ready(function(){
$(".stream").delegate(".like_action.inactive", "tap click", function(evt){
/* Heart toggle */
$(".like_action", ".stream").bind("tap click", function(evt){
evt.preventDefault();
var link = $(this),
likeCounter = $(this).closest(".stream_element").find("like_count"),
postId = link.closest(".stream_element").data("post-guid");
href = link.attr("href");
$.ajax({
url: link.attr("href"),
dataType: 'json',
type: 'POST',
beforeSend: function(){
link.removeClass('inactive')
.addClass('loading');
},
complete: function(data){
link.removeClass('loading')
.removeClass('inactive')
.addClass('active')
.data('post-id', postId);
var showLoader = function(link){
link.addClass('loading');
};
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) + 1);
var removeLoader = function(link){
link.removeClass('loading')
.toggleClass('active')
.toggleClass('inactive');
};
if(!link.hasClass("loading") && link.hasClass('inactive')) {
$.ajax({
url: href,
dataType: 'json',
type: 'POST',
beforeSend: showLoader(link),
success: function(data){
removeLoader(link);
link.attr("href", href + "/" + data["id"]);
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) + 1);
}
}
}
});
});
}
else if(!link.hasClass("loading") && link.hasClass("active")){
$.ajax({
url: link.attr("href"),
dataType: 'json',
type: 'DELETE',
beforeSend: showLoader(link),
complete: function(data){
removeLoader(link);
link.attr("href", href.replace(/\/\d+$/, ''));
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) - 1);
}
}
});
}
});
$(".stream").delegate(".like_action.active", "tap click", function(evt){
evt.preventDefault();
var link = $(this);
likeCounter = $(this).closest(".stream_element").find("like_count");
$.ajax({
url: link.attr("href"),
dataType: 'json',
type: 'DELETE',
beforeSend: function(){
link.removeClass('active')
.addClass('loading');
},
complete: function(data){
link.removeClass('loading')
.removeClass('active')
.addClass('inactive')
.data('like-id', '');
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) - 1);
}
}
});
});
$(".stream").delegate(".show_comments", "tap click", function(evt){
/* Show comments */
$(".show_comments", ".stream").bind("tap click", function(evt){
evt.preventDefault();
var link = $(this),
parent = link.closest(".bottom_bar").first(),

View file

@ -630,7 +630,6 @@ footer {
.comment_action.image_link {
background-image: url("/images/icons/pencil_mobile_grey_active.png");
&.inactive {
background-image: url("/images/icons/pencil_mobile_grey.png");
}