fix retractions, fix likes, backfill likes widget tests, remove typo from jasmine.yml, remove unneeded js files
require confirmation for comments in js, get rid of rails helper
This commit is contained in:
parent
2d45a4287f
commit
27d4fd8176
17 changed files with 131 additions and 135 deletions
|
|
@ -31,16 +31,16 @@ class LikesController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
|
||||
if target && @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
|
||||
current_user.retract(@like)
|
||||
respond_to do |format|
|
||||
format.all{}
|
||||
format.js{ render 'likes/update' }
|
||||
format.all { }
|
||||
format.js { render 'likes/update' }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.mobile {redirect_to :back}
|
||||
format.js {render :nothing => true, :status => 403}
|
||||
format.mobile { redirect_to :back }
|
||||
format.js { render :nothing => true, :status => 403 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
%li.comment.posted{:id => comment.guid, :class => ("hidden" if(defined? hidden))}
|
||||
- if current_user && (current_user.owns?(comment) || current_user.owns?(post))
|
||||
.right.controls
|
||||
= link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :class => "delete comment_delete", :title => t('delete'), :confirm => t('are_you_sure')
|
||||
= link_to image_tag('deletelabel.png'), post_comment_path(comment.post_id, comment), :class => "delete comment_delete", :title => t('delete')
|
||||
= person_image_link(comment.author, :size => :thumb_small)
|
||||
.content
|
||||
%span.from
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
$(".like_action", "#<%=@like.target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>");
|
||||
ContentUpdater.addLikesToPost("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes_count, :target_type => @like.target_type)) %>");
|
||||
$(".like_action", "#<%=@target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>");
|
||||
ContentUpdater.addLikesToPost("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @target.reload.likes_count, :target_type => @like.target_type)) %>");
|
||||
|
|
@ -8,18 +8,18 @@ javascripts:
|
|||
- public/javascripts/vendor/swfobject.js
|
||||
- public/javascripts/vendor/web_socket.js
|
||||
jquery:
|
||||
- public/javascripts/vendor/jquery152.min.js
|
||||
- public/javascripts/vendor/jquery162.min.js
|
||||
main:
|
||||
- public/javascripts/rails.js
|
||||
- public/javascripts/vendor/jquery.tipsy.js
|
||||
- public/javascripts/vendor/jquery.hotkeys.js
|
||||
- public/javascripts/vendor/jquery.autoresize.min.js
|
||||
- public/javascripts/vendor/jquery-ui-1.8.9.custom.min.js
|
||||
- public/javascripts/vendor/jquery.charcount.js
|
||||
- public/javascripts/vendor/jquery-debounce.js
|
||||
- public/javascripts/vendor/jquery.expander.js
|
||||
- public/javascripts/vendor/timeago.js
|
||||
- public/javascripts/vendor/Mustache.js
|
||||
- public/javascripts/vendor/charCount.js
|
||||
- public/javascripts/vendor/facebox.js
|
||||
- public/javascripts/jquery.infinitescroll-custom.js
|
||||
- public/javascripts/jquery.autocomplete-custom.js
|
||||
|
|
|
|||
|
|
@ -46,9 +46,12 @@ var ContentUpdater = {
|
|||
},
|
||||
|
||||
addLikesToPost: function(postGUID, html) {
|
||||
$(".likes_container", "#" + postGUID)
|
||||
var likesContainer = $(".likes_container", "#" + postGUID)
|
||||
.fadeOut("fast")
|
||||
.html(html)
|
||||
.fadeIn("fast");
|
||||
.html(html);
|
||||
|
||||
Diaspora.page.stream.streamElements[postGUID].likes.publish("widget/ready", [likesContainer]);
|
||||
|
||||
likesContainer.fadeIn("fast");
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -68,20 +68,22 @@
|
|||
});
|
||||
};
|
||||
|
||||
Diaspora.instantiatePage = function() {
|
||||
if (typeof Diaspora.Pages[Diaspora.Page] === "undefined") {
|
||||
Diaspora.page = Diaspora.EventBroker.extend(Diaspora.BaseWidget);
|
||||
} else {
|
||||
var Page = Diaspora.Pages[Diaspora.Page];
|
||||
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
|
||||
|
||||
Diaspora.page = new Page();
|
||||
}
|
||||
|
||||
$.extend(Diaspora.page, new Diaspora.BasePage($(document.body)));
|
||||
Diaspora.page.publish("page/ready", [$(document.body)])
|
||||
};
|
||||
|
||||
window.Diaspora = Diaspora;
|
||||
})();
|
||||
|
||||
|
||||
$(function() {
|
||||
if (typeof Diaspora.Pages[Diaspora.Page] === "undefined") {
|
||||
Diaspora.page = Diaspora.EventBroker.extend(Diaspora.BaseWidget);
|
||||
} else {
|
||||
var Page = Diaspora.Pages[Diaspora.Page];
|
||||
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
|
||||
|
||||
Diaspora.page = new Page();
|
||||
}
|
||||
|
||||
$.extend(Diaspora.page, new Diaspora.BasePage($(document.body)));
|
||||
Diaspora.page.publish("page/ready", [$(document.body)])
|
||||
});
|
||||
$(Diaspora.instantiatePage);
|
||||
|
|
@ -67,22 +67,6 @@ var Stream = {
|
|||
Stream.focusNewComment($(this), evt);
|
||||
});
|
||||
|
||||
|
||||
$(".comment .comment_delete", this.selector).live("ajax:success", function() {
|
||||
var element = $(this),
|
||||
target = element.parents(".comment"),
|
||||
post = element.closest(".stream_element"),
|
||||
toggler = post.find(".toggle_post_comments");
|
||||
|
||||
target.hide("blind", { direction: "vertical" }, 300, function() {
|
||||
$(this).remove();
|
||||
toggler.html(
|
||||
toggler.html().replace(/\d+/, $(".comments li", post).length - 1)
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$("textarea.comment_box", this.selector).live("focus", function(evt) {
|
||||
if (this.value === undefined || this.value === ''){
|
||||
var commentBox = $(this);
|
||||
|
|
@ -146,8 +130,7 @@ var Stream = {
|
|||
textarea.focus();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
|
|
|
|||
58
public/javascripts/vendor/charCount.js
vendored
58
public/javascripts/vendor/charCount.js
vendored
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Character Count Plugin - jQuery plugin
|
||||
* Dynamic character count for text areas and input fields
|
||||
* written by Alen Grakalic
|
||||
* http://cssglobe.com/post/7161/jquery-plugin-simplest-twitterlike-dynamic-character-count-for-textareas
|
||||
*
|
||||
* Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
|
||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||
* and GPL (GPL-LICENSE.txt) licenses.
|
||||
*
|
||||
* Built for jQuery library
|
||||
* http://jquery.com
|
||||
*
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
|
||||
$.fn.charCount = function(options){
|
||||
|
||||
// default configuration properties
|
||||
var defaults = {
|
||||
allowed: 140,
|
||||
warning: 25,
|
||||
css: 'counter',
|
||||
counterElement: 'span',
|
||||
cssWarning: 'warning',
|
||||
cssExceeded: 'exceeded',
|
||||
counterText: ''
|
||||
};
|
||||
|
||||
var options = $.extend(defaults, options);
|
||||
|
||||
function calculate(obj){
|
||||
var count = $(obj).val().length;
|
||||
var available = options.allowed - count;
|
||||
if(available <= options.warning && available >= 0){
|
||||
$(obj).next().addClass(options.cssWarning);
|
||||
} else {
|
||||
$(obj).next().removeClass(options.cssWarning);
|
||||
}
|
||||
if(available < 0){
|
||||
$(obj).next().addClass(options.cssExceeded);
|
||||
} else {
|
||||
$(obj).next().removeClass(options.cssExceeded);
|
||||
}
|
||||
$(obj).next().html(options.counterText + available);
|
||||
};
|
||||
|
||||
this.each(function() {
|
||||
$(this).after('<'+ options.counterElement +' class="' + options.css + '">'+ options.counterText +'</'+ options.counterElement +'>');
|
||||
calculate(this);
|
||||
$(this).keyup(function(){calculate(this)});
|
||||
$(this).change(function(){calculate(this)});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
17
public/javascripts/vendor/jquery152.min.js
vendored
17
public/javascripts/vendor/jquery152.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -17,7 +17,7 @@ var WSR = WebSocketReceiver = {
|
|||
else {
|
||||
switch(message["class"]) {
|
||||
case "retractions":
|
||||
ContentUpdater.removePostFromStream(message.post_guid);
|
||||
ContentUpdater.removePostFromStream(message.post_id);
|
||||
break;
|
||||
case "comments":
|
||||
ContentUpdater.addCommentToPost(message.post_guid, message.comment_guid, message.html);
|
||||
|
|
|
|||
|
|
@ -15,13 +15,15 @@
|
|||
this.removeComment = function(evt) {
|
||||
evt.preventDefault();
|
||||
|
||||
$.post(self.deleteCommentLink.attr("href"), {
|
||||
_method: "delete"
|
||||
}, function() {
|
||||
self.comment.hide("blind", { direction: "vertical" }, 300, function() {
|
||||
self.comment.remove();
|
||||
if(confirm(Diaspora.I18n.t("confirm_dialog"))) {
|
||||
$.post(self.deleteCommentLink.attr("href"), {
|
||||
_method: "delete"
|
||||
}, function() {
|
||||
self.comment.hide("blind", { direction: "vertical" }, 300, function() {
|
||||
self.comment.remove();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@
|
|||
|
||||
this.expandLikes = function(evt) {
|
||||
evt.preventDefault();
|
||||
var likesList = $(this).siblings(".likes_list");
|
||||
|
||||
var likesList = self.expander.siblings(".likes_list");
|
||||
if(likesList.children().length == 0) {
|
||||
self.loadingImage.appendTo(likesList.parent());
|
||||
$.get(this.href, function(data) {
|
||||
$.get(self.expander.href, function(data) {
|
||||
self.loadingImage.fadeOut(100, function() {
|
||||
likesList.html(data)
|
||||
.fadeToggle(100);
|
||||
|
|
|
|||
|
|
@ -89,6 +89,15 @@ describe AspectsController do
|
|||
save_fixture(html_for("body"), "aspects_index_with_video_post")
|
||||
end
|
||||
|
||||
it "generates a jasmine fixture with a post that has been liked", :fixture => true do
|
||||
message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id)
|
||||
alice.build_like(:positive => true, :target => message).save
|
||||
bob.build_like(:positive => true, :target => message).save
|
||||
|
||||
get :index
|
||||
save_fixture(html_for("body"), "aspects_index_with_a_post_with_likes")
|
||||
end
|
||||
|
||||
context 'with getting_started = true' do
|
||||
before do
|
||||
alice.getting_started = true
|
||||
|
|
|
|||
|
|
@ -69,12 +69,11 @@ describe("ContentUpdater", function() {
|
|||
it("adds a comment to a post only if it doesn't already exist", function() {
|
||||
var comments = post.find("ul.comments li");
|
||||
|
||||
expect(comments.length).toEqual(0);
|
||||
ContentUpdater.addCommentToPost(postGUID, "YEAH", "<li id='YEAH'>Comment</li>");
|
||||
expect(post.find("ul.comments li").length).toEqual(1);
|
||||
expect(post.find("ul.comments li").length).toEqual(comments.length + 1);
|
||||
|
||||
ContentUpdater.addCommentToPost(postGUID, "YEAH", "<li id='YEAH'>Comment</li>");
|
||||
expect(post.find("ul.comments li").length).toEqual(1);
|
||||
expect(post.find("ul.comments li").length).toEqual(comments.length + 1);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
@ -83,13 +82,29 @@ describe("ContentUpdater", function() {
|
|||
var post, postGUID;
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_with_posts");
|
||||
|
||||
Diaspora.Page = "AspectsIndex";
|
||||
Diaspora.instantiatePage();
|
||||
|
||||
console.log(Diaspora, $("#main_stream"), $("#jasmine_content"));
|
||||
|
||||
post = $(".stream_element:first"),
|
||||
postGUID = post.attr("id");
|
||||
|
||||
});
|
||||
|
||||
it("adds the given html to a post's likes container", function() {
|
||||
jasmine.Clock.useMock();
|
||||
|
||||
ContentUpdater.addLikesToPost(postGUID, "<p>1 like</p>");
|
||||
|
||||
jasmine.Clock.tick(250);
|
||||
|
||||
expect(post.find(".likes .likes_container").html()).toEqual("<p>1 like</p>");
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
$.fx.off = false;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ beforeEach(function() {
|
|||
self.directionDetector = self.instantiate("DirectionDetector");
|
||||
});
|
||||
};
|
||||
|
||||
var Page = Diaspora.Pages["TestPage"];
|
||||
$.extend(Page.prototype, Diaspora.EventBroker.extend(Diaspora.BaseWidget));
|
||||
|
||||
|
|
|
|||
|
|
@ -11,22 +11,24 @@
|
|||
# - dist/**/*.js
|
||||
#
|
||||
src_files:
|
||||
- public/javascripts/vendor/jquery152.min.js
|
||||
- public/javascripts/vendor/jquery162.min.js
|
||||
- public/javascripts/vendor/jquery-ui-1.8.9.custom.min.js
|
||||
- public/javascripts/vendor/jquery.tipsy.js
|
||||
- public/javascripts/jquery.infieldlabel-custom.js
|
||||
- public/javascripts/vendor/jquery.infinitescroll.min.js
|
||||
- public/javascripts/vendor/jquery.autoresize.min.js
|
||||
- public/javascripts/vendor/jquery.expander.js]
|
||||
- public/javascripts/vendor/jquery.expander.js
|
||||
- public/javascripts/vendor/jquery-debounce.js
|
||||
- public/javascripts/vendor/Mustache.js
|
||||
- public/javascripts/vendor/charCount.js
|
||||
- public/javascripts/vendor/jquery.charcount.js
|
||||
- public/javascripts/vendor/timeago.js
|
||||
- public/javascripts/vendor/facebox.js
|
||||
- public/javascripts/jquery.infieldlabel-custom.js
|
||||
- public/javascripts/fileuploader-custom.js
|
||||
- public/javascripts/jquery.autocomplete-custom.js
|
||||
- public/javascripts/diaspora.js
|
||||
- public/javascripts/keycodes.js
|
||||
|
||||
- public/javascripts/pages/*
|
||||
- public/javascripts/helpers/*
|
||||
- public/javascripts/widgets/*
|
||||
|
||||
|
|
|
|||
53
spec/javascripts/widgets/likes-spec.js
Normal file
53
spec/javascripts/widgets/likes-spec.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
describe("Diaspora.Widgets.Likes", function() {
|
||||
var likes;
|
||||
beforeEach(function() {
|
||||
spec.loadFixture("aspects_index_with_a_post_with_likes");
|
||||
likes = Diaspora.BaseWidget.instantiate("Likes", $(".stream_element .likes_container"));
|
||||
});
|
||||
|
||||
describe("integration", function() {
|
||||
beforeEach(function() {
|
||||
likes = new Diaspora.Widgets.Likes();
|
||||
|
||||
spyOn(likes, "expandLikes");
|
||||
|
||||
likes.publish("widget/ready", [$(".stream_element .likes_container")]);
|
||||
});
|
||||
|
||||
it("calls expandLikes when you click on the expand likes link", function() {
|
||||
$(".stream_element a.expand_likes").click();
|
||||
|
||||
expect(likes.expandLikes).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("expandLikes", function() {
|
||||
it("makes an ajax request if the list does not have children", function() {
|
||||
spyOn($, "ajax");
|
||||
|
||||
likes.expandLikes($.Event());
|
||||
|
||||
expect($.ajax).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not make an ajax request if the list has children", function() {
|
||||
spyOn($, "ajax");
|
||||
|
||||
$(".stream_element .likes_list").html("<span></span>");
|
||||
|
||||
likes.expandLikes($.Event());
|
||||
|
||||
expect($.ajax).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("makes the likes list's html the response of the request", function() {
|
||||
spyOn($, "ajax");
|
||||
|
||||
likes.expandLikes($.Event());
|
||||
|
||||
$.ajax.mostRecentCall.args[0].success("some html response");
|
||||
|
||||
expect($(".stream_element .likes_list").html()).toEqual("some html response");
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue