remove old js files, specs; remove stream references in page js initializers

This commit is contained in:
danielgrippi 2011-12-31 23:25:44 -05:00 committed by Dennis Collinson
parent 85b5974fa9
commit 1e20ca0cf5
18 changed files with 15 additions and 388 deletions

View file

@ -1,8 +0,0 @@
Diaspora.Pages.CommentStreamIndex = function() {
var self = this;
this.subscribe("page/ready", function(evt, document) {
self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav"));
});
};

View file

@ -1,7 +0,0 @@
Diaspora.Pages.LikeStreamIndex = function() {
var self = this;
this.subscribe("page/ready", function(evt, document) {
self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav"));
});
};

View file

@ -3,6 +3,5 @@ Diaspora.Pages.MultisIndex = function() {
this.subscribe("page/ready", function(evt, document) {
self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav"));
self.stream = self.instantiate("Stream", document.find("#aspect_stream_container"));
});
};

View file

@ -1,3 +1,2 @@
Diaspora.Pages.PeopleShow = function() {
var self = this;
};

View file

@ -1,7 +1,2 @@
Diaspora.Pages.PostsIndex = function() {
var self = this;
this.subscribe("page/ready", function(evt, document) {
self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav"));
});
};

View file

@ -1,7 +1,2 @@
Diaspora.Pages.PostsShow = function() {
var self = this;
this.subscribe("page/ready", function(evt, body) {
self.stream = self.instantiate("Stream", body.find("#main_stream"));
});
};
};

View file

@ -3,7 +3,5 @@ Diaspora.Pages.TagFollowingsIndex = function() {
this.subscribe("page/ready", function(evt, document) {
self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav"));
self.stream = self.instantiate("Stream", document.find("#aspect_stream_container"));
});
};

View file

@ -8,36 +8,6 @@ var Stream = {
initialize: function() {
Diaspora.page.directionDetector.updateBinds();
Stream.setUpAudioLinks();
},
initializeLives: function(){
// reshare button action
$(".reshare_button", this.selector).live("click", function(evt) {
evt.preventDefault();
var button = $(this),
box = button.siblings(".reshare_box");
if (box.length > 0) {
button.toggleClass("active");
box.toggle();
}
});
},
setUpAudioLinks: function() {
$(".stream a[target='_blank']").each(function(r){
var link = $(this);
if(this.href.match(/\.mp3$|\.ogg$/)) {
$("<audio/>", {
preload: "none",
src: this.href,
controls: "controls"
}).appendTo(link.parent());
link.remove();
}
});
}
};

View file

@ -63,8 +63,6 @@ var View = {
'extraSpace': 5
});
}
// Diaspora.Page.subscribe("stream/scrolled", startAutoResize)
// Diaspora.Page.subscribe("stream/reloaded", startAutoResize)
/* photo exporting in the works */
$("#photo-export-button").bind("click", function(evt){

View file

@ -1,39 +0,0 @@
var WSR = WebSocketReceiver = {
initialize: function(url) {
WSR.socket = new WebSocket(url);
WSR.socket.onmessage = WSR.onMessage;
WSR.socket.onopen = function() {
WSR.socket.send(location.pathname);
};
},
onMessage: function(evt) {
var message = $.parseJSON(evt.data);
if(message["class"].match(/^notifications/)) {
Diaspora.page.header.notifications.showNotification(message);
}
else {
console.log("new content");
}
},
onPageForAspects: function(aspectIds) {
var streamIds = $("#main_stream").attr("data-guids"),
found = false;
$.each(aspectIds, function(index, value) {
if(WebSocketReceiver.onStreamForAspect(value, streamIds)) {
found = true;
return false;
}
});
return found;
},
onStreamForAspect: function(aspectId, streamIds) {
return (streamIds.search(aspectId) != -1);
}
};

View file

@ -1,22 +0,0 @@
(function() {
var CommentForm = function() {
var self = this;
this.subscribe("widget/ready", function(evt, commentFormElement) {
$.extend(self, {
commentFormElement: commentFormElement,
commentInput: commentFormElement.find("textarea")
});
self.commentInput.autoResize();
self.commentInput.focus(self.showCommentForm);
});
this.showCommentForm = function() {
self.commentFormElement.parent().removeClass("hidden");
self.commentFormElement.addClass("open");
};
};
Diaspora.Widgets.CommentForm = CommentForm;
})();

View file

@ -1,65 +0,0 @@
(function() {
var CommentStream = function() {
var self = this;
this.subscribe("widget/ready", function(evt, commentStream) {
$.extend(self, {
commentsList: commentStream.find("ul.comments"),
commentToggler: commentStream.find(".toggle_post_comments"),
comments: {}
});
self.commentsList.delegate(".new_comment", "ajax:failure", function() {
Diaspora.Alert.show(Diaspora.I18n.t("failed_to_post_message"));
});
self.commentToggler.toggle(self.showComments, self.hideComments);
self.instantiateCommentWidgets();
});
this.instantiateCommentWidgets = function() {
self.comments = {};
self.commentsList.find("li.comment").each(function() {
self.publish("comment/added", [$("#" + this.id)]);
});
};
this.showComments = function(evt) {
evt.preventDefault();
if(self.commentsList.hasClass("loaded")) {
self.commentToggler.html(Diaspora.I18n.t("comments.hide"));
self.commentsList.removeClass("hidden");
}
else {
$("<img/>", { alt: "loading", src: "/images/ajax-loader.gif"}).appendTo(self.commentToggler);
$.get(self.commentToggler.attr("href"), function(data) {
self.commentToggler.html(Diaspora.I18n.t("comments.hide"));
self.commentsList
.html(data)
.addClass("loaded")
.removeClass("hidden");
self.instantiateCommentWidgets();
});
}
};
this.hideComments = function(evt) {
evt.preventDefault();
self.commentToggler.html(Diaspora.I18n.t("comments.show"));
self.commentsList.addClass("hidden");
};
this.subscribe("comment/added", function(evt, comment) {
self.comments[comment.attr("id")] = self.instantiate("Comment", comment);
});
};
Diaspora.Widgets.CommentStream = CommentStream;
})();

View file

@ -5,40 +5,17 @@
this.subscribe("widget/ready", function(evt, comment) {
$.extend(self, {
comment: comment,
deleteCommentLink: comment.find("a.comment_delete"),
likes: self.instantiate("Likes", comment.find(".likes_container")),
timeAgo: self.instantiate("TimeAgo", comment.find("abbr.timeago")),
content: comment.find(".content span .collapsible")
});
self.deleteCommentLink.click(self.removeComment);
self.deleteCommentLink.twipsy({ trigger: "hover" });
self.content.expander({
slicePoint: 200,
widow: 18,
expandText: Diaspora.I18n.t("show_more"),
userCollapse: false
});
self.globalSubscribe("likes/" + self.comment.attr('id') + "/updated", function(){
self.likes = self.instantiate("Likes", self.comment.find(".likes_container"));
});
});
this.removeComment = function(evt) {
evt.preventDefault();
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();
});
});
}
};
};
Diaspora.Widgets.Comment = Comment;

View file

@ -5,19 +5,9 @@
this.subscribe("widget/ready", function(evt, element) {
if( Diaspora.backboneEnabled() ){ return }
self.postGuid = element.attr("id");
$.extend(self, {
commentForm: self.instantiate("CommentForm", element.find("form.new_comment")),
commentStream: self.instantiate("CommentStream", element.find(".comment_stream")),
likes: self.instantiate("Likes", element.find(".likes.on_post .likes_container:first")),
lightBox: self.instantiate("Lightbox", element),
timeAgo: self.instantiate("TimeAgo", element.find(".timeago a abbr.timeago")),
content: element.find(".content .collapsible"),
hidePostLoader: element.find("img.hide_loader"),
hidePostUndo: element.find("a.stream_element_hide_undo"),
post: element
});
// collapse long posts
@ -27,25 +17,6 @@
expandText: Diaspora.I18n.t("show_more"),
userCollapse: false
});
self.globalSubscribe("likes/" + self.postGuid + "/updated", function() {
self.likes = self.instantiate("Likes", self.post.find(".likes_container:first"));
});
self.deletePostLink.click(function(evt) {
evt.preventDefault();
self.hidePostLoader.ajaxStart( function() {
self.deletePostLink.addClass("hidden");
$(this).removeClass('hidden');
} );
});
self.hidePostUndo.click(function(evt) {
evt.preventDefault();
self.hidePostLoader.toggleClass("hidden");
});
});
};

View file

@ -11,14 +11,24 @@ describe MultisController do
end
it 'generates the multi_stream_json fixture', :fixture => true do
alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all')
post_to_be_liked = alice.post(:status_message, :text => "you're gonna love this.'", :to => alice.aspects.first.id)
posts = []
alice.like(1, :target => post_to_be_liked)
posts << alice.post(:status_message, :text => "hella infos yo!", :to => alice.aspects.first.id)
posts << alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all')
posts << alice.post(:status_message, :text => "you're gonna love this.'", :to => alice.aspects.first.id)
alice.like(1, :target => posts.last)
time = Time.now
posts.each do |p|
time += 1.day
p.stub(:created_at).and_return(time)
end
get :index, :format => :json
response.should be_success
pp response.body
save_fixture(response.body, "multi_stream_json")
end
end

View file

@ -1,21 +0,0 @@
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
describe("WebSocketReceiver", function() {
/* WSR should publish events that widgets hook into
* e.g. socket/message/CLASS
* WSR should pass the message's data as an argument to the event.
* downsides:
* - need to standardize notifications
*/
describe("onMessage", function() {
});
it("sets a shortcut", function() {
expect(WSR).toEqual(WebSocketReceiver);
});
});

View file

@ -1,95 +0,0 @@
describe("Diaspora.Widgets.CommentStream", function() {
var commentStream;
var ajaxCommentResponse;
beforeEach(function() {
ajaxCommentResponse = spec.readFixture("ajax_comments_on_post");
spec.loadFixture("aspects_index_post_with_comments");
jasmine.Clock.useMock();
jasmine.Ajax.useMock();
Diaspora.I18n.locale = { };
commentStream = Diaspora.BaseWidget.instantiate("CommentStream", $(".stream_element:first .comment_stream"));
});
describe("toggling comments", function() {
it("toggles class hidden on the comments ul", function () {
expect($("ul.comments:first")).not.toHaveClass("hidden");
commentStream.showComments($.Event());
mostRecentAjaxRequest().response({
responseHeaders: {
"Content-type": "text/html"
},
responseText: ajaxCommentResponse,
status: 200
});
jasmine.Clock.tick(200);
expect($("ul.comments:first")).not.toHaveClass("hidden");
commentStream.hideComments($.Event());
jasmine.Clock.tick(200);
expect($("ul.comments:first")).toHaveClass("hidden");
});
it("changes the text on the show comments link", function() {
Diaspora.I18n.loadLocale({'comments' : {
'show': 'show comments translation',
'hide': 'hide comments translation'
}}, 'en');
var link = $("a.toggle_post_comments:first");
commentStream.showComments($.Event());
mostRecentAjaxRequest().response({
responseHeaders: {
"Content-type": "text/html"
},
responseText: ajaxCommentResponse,
status: 200
});
jasmine.Clock.tick(200);
expect(link.text()).toEqual("hide comments translation");
commentStream.hideComments($.Event());
jasmine.Clock.tick(200);
expect(link.text()).toEqual("show comments translation");
});
it("only requests the comments when the loaded class is not present", function() {
spyOn($, "ajax").andCallThrough();
expect(commentStream.commentsList).not.toHaveClass("loaded");
commentStream.showComments($.Event());
mostRecentAjaxRequest().response({
responseHeaders: {
"Content-type": "text/html"
},
responseText: ajaxCommentResponse,
status: 200
});
expect($.ajax.callCount).toEqual(1);
expect(commentStream.commentsList).toHaveClass("loaded");
commentStream.showComments($.Event());
expect($.ajax.callCount).toEqual(1);
expect(commentStream.commentsList).toHaveClass("loaded");
});
});
});

View file

@ -1,28 +0,0 @@
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
describe("Diaspora.Widgets.StreamElement", function() {
var streamElement;
beforeEach(function() {
jasmine.Clock.useMock();
spec.loadFixture("aspects_index_only_posts");
streamElement = Diaspora.BaseWidget.instantiate("StreamElement", $(".stream_element").first());
});
describe("hidePost", function() {
it("makes sure that ajax spinner appears when hiding a post", function() {
expect(streamElement.deletePostLink).not.toHaveClass("hidden");
expect(streamElement.hidePostLoader).toHaveClass("hidden");
spyOn($, "ajax");
streamElement.deletePostLink.click();
streamElement.hidePostLoader.triggerHandler('ajaxStart');
jasmine.Clock.tick(200);
expect($.ajax).toHaveBeenCalled();
expect(streamElement.deletePostLink).toHaveClass("hidden");
expect(streamElement.hidePostLoader).not.toHaveClass("hidden");
});
});
});