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|
|
respond_to do |format|
|
||||||
format.any { }
|
format.any { }
|
||||||
format.js { render 'likes/update' }
|
format.js { render 'likes/update' }
|
||||||
format.json { render :nothing => true, :status => :ok}
|
format.json { render :nothing => true, :status => 204}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@
|
||||||
<div class="shield_wrapper">
|
<div class="shield_wrapper">
|
||||||
<div class="shield">
|
<div class="shield">
|
||||||
This post has been flagged as NSFW by its author.
|
This post has been flagged as NSFW by its author.
|
||||||
|
<a href="#">
|
||||||
|
show
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
|
@ -63,32 +66,28 @@
|
||||||
-
|
-
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="like_action">
|
|
||||||
<% if(user_like) { %>
|
<% if(user_like) { %>
|
||||||
<a href="/posts/<%= id %>/likes/<%= user_like.id %>" class="unlike" data-method='delete' data-remote='true' rel='nofollow'>
|
<a href="/posts/<%= id %>/likes/<%= user_like.id %>" class="like_action unlike" rel='nofollow'>
|
||||||
Unlike
|
Unlike
|
||||||
</a>
|
</a>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<a href="/posts/<%= id %>/likes?positive=true" class="like" data-method='post' data-remote='true' rel='nofollow'>
|
<a href="/posts/<%= id %>/likes?positive=true" class="like_action like" rel='nofollow'>
|
||||||
Like
|
Like
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
</span>
|
|
||||||
·
|
·
|
||||||
|
|
||||||
<% if(public && author.id != current_user.id) { %>
|
<% if(public && author.id != current_user.id) { %>
|
||||||
<span class="reshare_action">
|
|
||||||
<% if(root) {
|
<% if(root) {
|
||||||
var rootGuid = root.guid;
|
var rootGuid = root.guid;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var rootGuid = guid;
|
var rootGuid = guid;
|
||||||
} %>
|
} %>
|
||||||
<a href="/reshares?root_guid=<%= rootGuid %>" data-confirm="Reshare Bob Grimm's post?" data-method="post" data-remote="true" rel="nofollow">
|
<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
|
Reshare
|
||||||
</a>
|
</a>
|
||||||
·
|
·
|
||||||
</span>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
<a href="#" class="focus_comment_textarea">
|
<a href="#" class="focus_comment_textarea">
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ javascripts:
|
||||||
- public/javascripts/vendor/swfobject.js
|
- public/javascripts/vendor/swfobject.js
|
||||||
- public/javascripts/vendor/web_socket.js
|
- public/javascripts/vendor/web_socket.js
|
||||||
jquery:
|
jquery:
|
||||||
- public/javascripts/vendor/jquery162.min.js
|
- public/javascripts/vendor/jquery-1.7.1.min.js
|
||||||
|
|
||||||
main:
|
main:
|
||||||
- public/javascripts/vendor/underscore.js
|
- 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() {
|
initialize: function() {
|
||||||
this.comments = new App.Collections.Comments(this.get("last_three_comments"));
|
this.comments = new App.Collections.Comments(this.get("last_three_comments"));
|
||||||
|
this.likes = new App.Collections.Likes();
|
||||||
},
|
},
|
||||||
|
|
||||||
createdAt: function(){
|
createdAt: function(){
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ App.Views.Comment = App.Views.StreamObject.extend({
|
||||||
template_name: "#comment-template",
|
template_name: "#comment-template",
|
||||||
|
|
||||||
events : {
|
events : {
|
||||||
"click .delete:first": "destroyModel"
|
"click .comment_delete": "destroyModel"
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ App.Views.CommentStream = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
$(this.el).html(this.template($.extend(
|
$(this.el).html(this.template($.extend(
|
||||||
this.model.toJSON(),
|
this.model.toJSON(),
|
||||||
App.user()
|
App.user()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@ App.Views.Post = App.Views.StreamObject.extend({
|
||||||
events: {
|
events: {
|
||||||
"click .focus_comment_textarea": "focusCommentTextarea",
|
"click .focus_comment_textarea": "focusCommentTextarea",
|
||||||
"focus .comment_box": "commentTextareaFocused",
|
"focus .comment_box": "commentTextareaFocused",
|
||||||
"click .delete:first": "destroyModel"
|
"click .shield a": "removeNsfwShield",
|
||||||
|
"click .remove_post": "destroyModel",
|
||||||
|
"click .like_action": "toggleLike"
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
@ -42,6 +44,14 @@ App.Views.Post = App.Views.StreamObject.extend({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
removeNsfwShield: function(evt){
|
||||||
|
if(evt){ evt.preventDefault(); }
|
||||||
|
|
||||||
|
$(evt.target).parent(".shield").remove();
|
||||||
|
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
initializeTooltips: function(){
|
initializeTooltips: function(){
|
||||||
$([
|
$([
|
||||||
this.$(".delete"),
|
this.$(".delete"),
|
||||||
|
|
@ -52,6 +62,31 @@ App.Views.Post = App.Views.StreamObject.extend({
|
||||||
return this;
|
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){
|
focusCommentTextarea: function(evt){
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
this.$(".new_comment_form_wrapper").removeClass("hidden");
|
this.$(".new_comment_form_wrapper").removeClass("hidden");
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,17 @@ App.Views.StreamObject = Backbone.View.extend({
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.model = options.model;
|
this.model = options.model;
|
||||||
this.template = _.template($(this.template_name).html());
|
this.template = _.template($(this.template_name).html());
|
||||||
|
|
||||||
|
this.model.bind('destroy', this.remove, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
destroyModel: function(evt){
|
destroyModel: function(evt){
|
||||||
if(evt){ evt.preventDefault(); }
|
if(evt){ evt.preventDefault(); }
|
||||||
|
this.model.destroy();
|
||||||
|
},
|
||||||
|
|
||||||
var domElement = this.el;
|
remove: function() {
|
||||||
this.model.destroy({
|
$(this.el).remove();
|
||||||
success: function(){
|
|
||||||
$(domElement).remove();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ App.Views.Stream = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
_.bindAll(this, "render", "appendPost", "collectionFetched", "loadMore");
|
_.bindAll(this, "appendPost", "collectionFetched", "loadMore");
|
||||||
|
|
||||||
this.collection = this.collection || new App.Collections.Stream;
|
this.collection = this.collection || new App.Collections.Stream;
|
||||||
this.collection.bind("add", this.appendPost);
|
this.collection.bind("add", this.appendPost);
|
||||||
|
|
@ -12,7 +12,7 @@ App.Views.Stream = Backbone.View.extend({
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
_.each(this.collection.models, this.appendPost)
|
_.each(this.collection.models, this.appendPost)
|
||||||
return this
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
appendPost: function(post) {
|
appendPost: function(post) {
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,11 @@
|
||||||
Diaspora.page.publish("page/ready", [$(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;
|
window.Diaspora = Diaspora;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ var Stream = {
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
if( Diaspora.backboneEnabled() ){ return }
|
||||||
|
|
||||||
if( $(Stream.selector).length == 0 ) { return }
|
if( $(Stream.selector).length == 0 ) { return }
|
||||||
Stream.initializeLives();
|
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;
|
var self = this;
|
||||||
|
|
||||||
this.subscribe("widget/ready", function(evt, element) {
|
this.subscribe("widget/ready", function(evt, element) {
|
||||||
|
if( Diaspora.backboneEnabled() ){ return }
|
||||||
|
|
||||||
self.postGuid = element.attr("id");
|
self.postGuid = element.attr("id");
|
||||||
|
|
||||||
$.extend(self, {
|
$.extend(self, {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
this.streamElements = {};
|
this.streamElements = {};
|
||||||
|
|
||||||
this.subscribe("widget/ready", function(evt, stream) {
|
this.subscribe("widget/ready", function(evt, stream) {
|
||||||
|
if( Diaspora.backboneEnabled() ){ return }
|
||||||
|
|
||||||
$.extend(self, {
|
$.extend(self, {
|
||||||
stream: $(stream),
|
stream: $(stream),
|
||||||
mainStream: $(stream).find('#main_stream'),
|
mainStream: $(stream).find('#main_stream'),
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ describe("App.views.Stream", function(){
|
||||||
|
|
||||||
context("when rendering a Status Mesasage", function(){
|
context("when rendering a Status Mesasage", function(){
|
||||||
it("shows the status message in the content area", 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