fixed ajax for likes

This commit is contained in:
danielgrippi 2011-09-25 16:39:53 -07:00
parent 6deb924c32
commit f2f14c2894
7 changed files with 87 additions and 21 deletions

View file

@ -45,8 +45,9 @@
%body %body
%header %header
= link_to(image_tag('icons/compose_mobile2.png', :height => 28, :width => 28), new_status_message_path, :class => 'compose_icon')
= link_to(image_tag('white@2x.png', :height => 20, :width => 127, :id => 'header_title'), aspects_path) = link_to(image_tag('white@2x.png', :height => 20, :width => 127, :id => 'header_title'), aspects_path)
- if user_signed_in?
= link_to(image_tag('icons/compose_mobile2.png', :height => 28, :width => 28), new_status_message_path, :class => 'compose_icon')
- if flash.present? - if flash.present?
%p %p

View file

@ -7,16 +7,11 @@
- if post - if post
.content .content
.from .from
= person_link(post.author, :class => "hovercardable") = person_link(post.author)
- if post.activity_streams? - if post.activity_streams?
= link_to image_tag(post.image_url, 'data-small-photo' => post.image_url, 'data-full-photo' => post.image_url, :class => 'stream-photo'), post.object_url, :class => "stream-photo-link" = link_to image_tag(post.image_url, 'data-small-photo' => post.image_url, 'data-full-photo' => post.image_url, :class => 'stream-photo'), post.object_url, :class => "stream-photo-link"
- else - else
= render 'status_messages/status_message', :post => post, :photos => post.photos = render 'status_messages/status_message', :post => post, :photos => post.photos
- if defined?(current_user) && current_user && (post.author_id != current_user.person.id) && (post.public?) && !reshare?(post)
.reshare_action
= reshare_link(post)
= link_to t(".show_original"), post_path(post)
- else - else
= t('.deleted') = t('.deleted')

View file

@ -2,7 +2,7 @@
-# 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.
= form_for StatusMessage.new, {:data => {:ajax => false}} do |status| = form_for StatusMessage.new, {:data => {:ajax => false}} do |status|
= status.text_area :text, :placeholder => t('.whats_on_your_mind'), :style => "width:300px", :rows => 4 = status.text_area :text, :placeholder => t('.whats_on_your_mind'), :style => "width:300px", :rows => 4
- for aspect_id in aspect_ids - for aspect_id in aspect_ids

View file

@ -49,8 +49,9 @@ javascripts:
#- public/javascripts/diaspora.js #- public/javascripts/diaspora.js
#- public/javascripts/helpers/i18n.js #- public/javascripts/helpers/i18n.js
#- public/javascripts/widgets/infinite-scroll.js #- public/javascripts/widgets/infinite-scroll.js
#- public/javascripts/rails.js - public/javascripts/rails.js
- public/javascripts/vendor/mbp-helper.js - public/javascripts/vendor/mbp-helper.js
- public/javascripts/mobile.js
mailchimp: mailchimp:
- public/javascripts/vendor/mailchimp/jquery.form.js - public/javascripts/vendor/mailchimp/jquery.form.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -0,0 +1,46 @@
$(document).ready(function(){
$(".like_action.inactive").live('tap click', function(evt){
evt.preventDefault();
var target = $(this),
postId = target.data('post-id');
$.ajax({
url: '/posts/'+postId+'/likes.json',
type: 'POST',
beforeSend: function(){
target.removeClass('inactive')
.addClass('loading');
},
complete: function(data){
target.removeClass('loading')
.removeClass('inactive')
.addClass('active')
.data('post-id', postId);
}
});
});
$(".like_action.active").live('tap click', function(evt){
evt.preventDefault();
var target = $(this),
postId = $(this).data('post-id'),
likeId = $(this).data('like-id');
$.ajax({
url: '/posts/'+postId+'/likes/'+likeId+'.json',
type: 'DELETE',
beforeSend: function(){
target.removeClass('active')
.addClass('loading')
.fadeIn(50);
},
complete: function(data){
target.removeClass('loading')
.removeClass('active')
.addClass('inactive')
.data('like-id', '');
}
});
});
});

View file

@ -40,6 +40,16 @@ body {
left: 2px; }; left: 2px; };
} }
#main {
text-align: center;
}
.stream {
text-align: left;
max-width: 700px;
}
.stream_element, .stream_element,
.comments { .comments {
overflow: auto; overflow: auto;
@ -106,12 +116,9 @@ body {
@include border-radius(3px); @include border-radius(3px);
@include box-shadow(0, 1px, 5px, rgba(0, 0, 0, 1)); @include box-shadow(0, 1px, 5px, rgba(0, 0, 0, 1));
background: { background: {
color: white; }; color: #fff; };
border: { border: {
top: 1px solid black;
bottom: 1px solid black; }; bottom: 1px solid black; };
max-width: 700px;
} }
.photo_attachments { .photo_attachments {
@ -129,12 +136,8 @@ body {
padding: { padding: {
left: 15px; left: 15px;
top: 10px; }; top: 10px; };
.from { }
font: { }
style: italic; }; } }
.reshare_action {
font: {
size: 0.8em; }; } }
#main_stream { #main_stream {
font: { font: {
@ -310,9 +313,17 @@ footer {
left: 5px; }; } left: 5px; }; }
.like_action { .like_action {
background-image: url("/images/icons/heart_mobile_grey.png"); &.inactive{
background-image: url("/images/icons/heart_mobile_grey.png");
}
&.active { &.active {
background-image: url("/images/icons/heart_mobile_red.png"); } } background-image: url("/images/icons/heart_mobile_red.png");
}
&.loading {
background-image: url("/images/mobile-spinner.gif");
}
}
.comment_action { .comment_action {
background-image: url("/images/icons/pencil_mobile_grey.png"); } background-image: url("/images/icons/pencil_mobile_grey.png"); }
@ -329,3 +340,15 @@ form {
top: 6px; top: 6px;
right: 15px; right: 15px;
} }
#new_status_message {
position: absolute;
left: 0;
top: 45px;
width:100%;
textarea {
@include border-radius(0);
left: 0;
}
}