don't use Diaspora widget system or stream.js when backbone is active;
migrating like actions over to backbone; some cleanup; bump jquery to 1.7.1
This commit is contained in:
parent
cd1d25dc30
commit
ae6fa5bebb
17 changed files with 102 additions and 40 deletions
|
|
@ -37,7 +37,7 @@ class LikesController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.any { }
|
||||
format.js { render 'likes/update' }
|
||||
format.json { render :nothing => true, :status => :ok}
|
||||
format.json { render :nothing => true, :status => 204}
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@
|
|||
<div class="shield_wrapper">
|
||||
<div class="shield">
|
||||
This post has been flagged as NSFW by its author.
|
||||
<a href="#">
|
||||
show
|
||||
</a>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
|
@ -63,32 +66,28 @@
|
|||
-
|
||||
</span>
|
||||
|
||||
<span class="like_action">
|
||||
<% if(user_like) { %>
|
||||
<a href="/posts/<%= id %>/likes/<%= user_like.id %>" class="unlike" data-method='delete' data-remote='true' rel='nofollow'>
|
||||
Unlike
|
||||
</a>
|
||||
<% } else { %>
|
||||
<a href="/posts/<%= id %>/likes?positive=true" class="like" data-method='post' data-remote='true' rel='nofollow'>
|
||||
Like
|
||||
</a>
|
||||
<% } %>
|
||||
</span>
|
||||
<% if(user_like) { %>
|
||||
<a href="/posts/<%= id %>/likes/<%= user_like.id %>" class="like_action unlike" rel='nofollow'>
|
||||
Unlike
|
||||
</a>
|
||||
<% } else { %>
|
||||
<a href="/posts/<%= id %>/likes?positive=true" class="like_action like" rel='nofollow'>
|
||||
Like
|
||||
</a>
|
||||
<% } %>
|
||||
·
|
||||
|
||||
<% if(public && author.id != current_user.id) { %>
|
||||
<span class="reshare_action">
|
||||
<% if(root) {
|
||||
var rootGuid = root.guid;
|
||||
}
|
||||
else {
|
||||
var rootGuid = guid;
|
||||
} %>
|
||||
<a href="/reshares?root_guid=<%= rootGuid %>" data-confirm="Reshare Bob Grimm's post?" data-method="post" data-remote="true" rel="nofollow">
|
||||
Reshare
|
||||
</a>
|
||||
·
|
||||
</span>
|
||||
<% if(root) {
|
||||
var rootGuid = root.guid;
|
||||
}
|
||||
else {
|
||||
var rootGuid = guid;
|
||||
} %>
|
||||
<a href="/reshares?root_guid=<%= rootGuid %>" class="reshare_action" data-confirm="Reshare Bob Grimm's post?" data-method="post" data-remote="true" rel="nofollow">
|
||||
Reshare
|
||||
</a>
|
||||
·
|
||||
<% } %>
|
||||
|
||||
<a href="#" class="focus_comment_textarea">
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ javascripts:
|
|||
- public/javascripts/vendor/swfobject.js
|
||||
- public/javascripts/vendor/web_socket.js
|
||||
jquery:
|
||||
- public/javascripts/vendor/jquery162.min.js
|
||||
- public/javascripts/vendor/jquery-1.7.1.min.js
|
||||
|
||||
main:
|
||||
- public/javascripts/vendor/underscore.js
|
||||
|
|
|
|||
3
public/javascripts/app/collections/likes.js
Normal file
3
public/javascripts/app/collections/likes.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
App.Collections.Likes = Backbone.Collection.extend({
|
||||
model: App.Models.Like
|
||||
});
|
||||
10
public/javascripts/app/models/like.js
Normal file
10
public/javascripts/app/models/like.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
App.Models.Like = Backbone.Model.extend({
|
||||
url: function(){
|
||||
if(this.get("id")) {
|
||||
return "/" + this.get("target_type") + "s/" + this.get("target_id") + "/likes/" + this.get("id");
|
||||
}
|
||||
else {
|
||||
return "/posts/" + this.get("target_id") + "/likes";
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -5,6 +5,7 @@ App.Models.Post = Backbone.Model.extend({
|
|||
|
||||
initialize: function() {
|
||||
this.comments = new App.Collections.Comments(this.get("last_three_comments"));
|
||||
this.likes = new App.Collections.Likes();
|
||||
},
|
||||
|
||||
createdAt: function(){
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ App.Views.Comment = App.Views.StreamObject.extend({
|
|||
template_name: "#comment-template",
|
||||
|
||||
events : {
|
||||
"click .delete:first": "destroyModel"
|
||||
"click .comment_delete": "destroyModel"
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ App.Views.CommentStream = Backbone.View.extend({
|
|||
},
|
||||
|
||||
render: function() {
|
||||
var self = this;
|
||||
|
||||
$(this.el).html(this.template($.extend(
|
||||
this.model.toJSON(),
|
||||
App.user()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ App.Views.Post = App.Views.StreamObject.extend({
|
|||
events: {
|
||||
"click .focus_comment_textarea": "focusCommentTextarea",
|
||||
"focus .comment_box": "commentTextareaFocused",
|
||||
"click .delete:first": "destroyModel"
|
||||
"click .shield a": "removeNsfwShield",
|
||||
"click .remove_post": "destroyModel",
|
||||
"click .like_action": "toggleLike"
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
|
@ -42,6 +44,14 @@ App.Views.Post = App.Views.StreamObject.extend({
|
|||
return this;
|
||||
},
|
||||
|
||||
removeNsfwShield: function(evt){
|
||||
if(evt){ evt.preventDefault(); }
|
||||
|
||||
$(evt.target).parent(".shield").remove();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
initializeTooltips: function(){
|
||||
$([
|
||||
this.$(".delete"),
|
||||
|
|
@ -52,6 +62,31 @@ App.Views.Post = App.Views.StreamObject.extend({
|
|||
return this;
|
||||
},
|
||||
|
||||
toggleLike: function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
|
||||
var link = $(evt.target);
|
||||
|
||||
if(link.hasClass('like')){
|
||||
this.model.likes.create({
|
||||
target_id: this.model.get("id"),
|
||||
target_type: "post",
|
||||
positive: "true"
|
||||
});
|
||||
}
|
||||
else {
|
||||
var like = new App.Models.Like({
|
||||
"id": this.model.get("user_like")["posts"]["id"],
|
||||
target_type: "post",
|
||||
target_id: this.model.get("id")
|
||||
});
|
||||
|
||||
like.destroy();
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
focusCommentTextarea: function(evt){
|
||||
evt.preventDefault();
|
||||
this.$(".new_comment_form_wrapper").removeClass("hidden");
|
||||
|
|
|
|||
|
|
@ -2,16 +2,17 @@ App.Views.StreamObject = Backbone.View.extend({
|
|||
initialize: function(options) {
|
||||
this.model = options.model;
|
||||
this.template = _.template($(this.template_name).html());
|
||||
|
||||
this.model.bind('destroy', this.remove, this);
|
||||
},
|
||||
|
||||
destroyModel: function(evt){
|
||||
if(evt){ evt.preventDefault(); }
|
||||
this.model.destroy();
|
||||
},
|
||||
|
||||
var domElement = this.el;
|
||||
this.model.destroy({
|
||||
success: function(){
|
||||
$(domElement).remove();
|
||||
}
|
||||
});
|
||||
remove: function() {
|
||||
$(this.el).remove();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ App.Views.Stream = Backbone.View.extend({
|
|||
},
|
||||
|
||||
initialize: function() {
|
||||
_.bindAll(this, "render", "appendPost", "collectionFetched", "loadMore");
|
||||
_.bindAll(this, "appendPost", "collectionFetched", "loadMore");
|
||||
|
||||
this.collection = this.collection || new App.Collections.Stream;
|
||||
this.collection.bind("add", this.appendPost);
|
||||
|
|
@ -12,7 +12,7 @@ App.Views.Stream = Backbone.View.extend({
|
|||
|
||||
render : function(){
|
||||
_.each(this.collection.models, this.appendPost)
|
||||
return this
|
||||
return this;
|
||||
},
|
||||
|
||||
appendPost: function(post) {
|
||||
|
|
|
|||
|
|
@ -77,12 +77,17 @@
|
|||
|
||||
Diaspora.page = new Page();
|
||||
}
|
||||
|
||||
|
||||
if(!$.mobile)//why does this need this?
|
||||
$.extend(Diaspora.page, new Diaspora.BasePage($(document.body)));
|
||||
Diaspora.page.publish("page/ready", [$(document.body)])
|
||||
};
|
||||
|
||||
// temp hack to check if backbone is enabled for the page
|
||||
Diaspora.backboneEnabled = function(){
|
||||
return window.App.router.routes[window.location.pathname.replace("/","")];
|
||||
}
|
||||
|
||||
window.Diaspora = Diaspora;
|
||||
})();
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ var Stream = {
|
|||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
if( Diaspora.backboneEnabled() ){ return }
|
||||
|
||||
if( $(Stream.selector).length == 0 ) { return }
|
||||
Stream.initializeLives();
|
||||
});
|
||||
|
|
|
|||
4
public/javascripts/vendor/jquery-1.7.1.min.js
vendored
Normal file
4
public/javascripts/vendor/jquery-1.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -3,6 +3,8 @@
|
|||
var self = this;
|
||||
|
||||
this.subscribe("widget/ready", function(evt, element) {
|
||||
if( Diaspora.backboneEnabled() ){ return }
|
||||
|
||||
self.postGuid = element.attr("id");
|
||||
|
||||
$.extend(self, {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
this.streamElements = {};
|
||||
|
||||
this.subscribe("widget/ready", function(evt, stream) {
|
||||
if( Diaspora.backboneEnabled() ){ return }
|
||||
|
||||
$.extend(self, {
|
||||
stream: $(stream),
|
||||
mainStream: $(stream).find('#main_stream'),
|
||||
|
|
@ -45,4 +47,4 @@
|
|||
};
|
||||
|
||||
Diaspora.Widgets.Stream = Stream;
|
||||
})();
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ describe("App.views.Stream", function(){
|
|||
|
||||
context("when rendering a Status Mesasage", function(){
|
||||
it("shows the status message in the content area", function(){
|
||||
expect(this.statusElement.find(".post-content p").text()).toContain("jimmy's 2 whales")
|
||||
expect(this.statusElement.find(".post-content p").text()).toContain("hella infos yo!")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue