diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index 41b11fa13..86ca99f05 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -7,33 +7,13 @@ var Stream = { selector: "#main_stream", initialize: function() { - Diaspora.page.timeAgo.updateTimeAgo(); + //Diaspora.page.timeAgo.updateTimeAgo(); // this is not needed because + // we do this in both streamelement + // and comment widgets Diaspora.page.directionDetector.updateBinds(); //audio links Stream.setUpAudioLinks(); - //Stream.setUpImageLinks(); - - Diaspora.page.subscribe("stream/scrolled", Stream.collapseText); - Stream.collapseText('eventID', $(Stream.selector)[0]); - }, - collapseText: function(){ - elements = $(Array.prototype.slice.call(arguments,1)); - // collapse long posts - $(".content p", elements).expander({ - slicePoint: 400, - widow: 12, - expandText: Diaspora.I18n.t("show_more"), - userCollapse: false - }); - - // collapse long comments - $(".comment .content span", elements).expander({ - slicePoint: 200, - widow: 18, - expandText: Diaspora.I18n.t("show_more"), - userCollapse: false - }); }, initializeLives: function(){ @@ -101,19 +81,6 @@ var Stream = { }); }, - setUpImageLinks: function() { - $(".stream a[target='_blank']").each(function() { - var link = $(this); - if(this.href.match(/\.gif$|\.jpg$|\.png$|\.jpeg$/)) { - $("", { - src: this.href - }).appendTo(link.parent()); - - link.remove(); - } - }); - }, - focusNewComment: function(toggle, evt) { evt.preventDefault(); var post = toggle.closest(".stream_element"); diff --git a/public/javascripts/widgets/comment.js b/public/javascripts/widgets/comment.js index 75bef11eb..78cc78f2a 100644 --- a/public/javascripts/widgets/comment.js +++ b/public/javascripts/widgets/comment.js @@ -6,11 +6,21 @@ $.extend(self, { comment: comment, deleteCommentLink: comment.find("a.comment_delete"), - timeAgo: self.instantiate("TimeAgo", comment) + timeAgo: self.instantiate("TimeAgo", comment), + content: comment.find(".content span") }); self.deleteCommentLink.click(self.removeComment); self.deleteCommentLink.tipsy({ trigger: "hover" }); + + // collapse long comments + self.content.expander({ + slicePoint: 200, + widow: 18, + expandText: Diaspora.I18n.t("show_more"), + userCollapse: false + }); + }); this.removeComment = function(evt) { diff --git a/public/javascripts/widgets/stream-element.js b/public/javascripts/widgets/stream-element.js index 7e1bcd0bd..3bfd82ed9 100644 --- a/public/javascripts/widgets/stream-element.js +++ b/public/javascripts/widgets/stream-element.js @@ -12,12 +12,22 @@ likes: self.instantiate("Likes", element.find("div.likes_container")), lightBox: self.instantiate("Lightbox", element), deletePostLink: element.find("a.stream_element_delete"), - postScope: element.find("span.post_scope") + postScope: element.find("span.post_scope"), + content: element.find(".content p") }); + // tipsy tooltips self.deletePostLink.tipsy({ trigger: "hover" }); self.postScope.tipsy({ trigger: "hover" }); + // collapse long posts + self.content.expander({ + slicePoint: 400, + widow: 12, + expandText: Diaspora.I18n.t("show_more"), + userCollapse: false + }); + self.globalSubscribe("post/" + self.postGuid + "/comment/added", function(evt, comment) { self.commentStream.publish("comment/added", comment); }); diff --git a/spec/javascripts/stream-spec.js b/spec/javascripts/stream-spec.js index 55230dac0..47044327d 100644 --- a/spec/javascripts/stream-spec.js +++ b/spec/javascripts/stream-spec.js @@ -10,24 +10,6 @@ describe("Stream", function() { Diaspora.I18n.locale = { }; }); - describe("collapseText", function() { - it("adds a 'show more' links to long posts", function() { - Diaspora.I18n.loadLocale({show_more: 'Placeholder'}, 'en'); - - var stream_element = $('#main_stream .stream_element:first'); - Stream.collapseText('eventID', stream_element[0]); - - expect(stream_element.find("p .details").css('display')).toEqual('none'); - expect(stream_element.find(".read-more a").css('display')).toEqual('inline'); - - stream_element.find(".read-more a").click(); - jasmine.Clock.tick(200); - - expect(stream_element.find(".read-more").css('display')).toEqual('none'); - expect(stream_element.find(".details").css('display')).toEqual('inline'); - }); - }); - describe("streamElement", function() { it("makes sure that ajax spinner appears when hiding a post", function() { Stream.initializeLives(); @@ -42,13 +24,4 @@ describe("Stream", function() { expect(spinner).not.toHaveClass("hidden"); }); }); - - describe("initialize", function() { - it("calls collapseText",function(){ - spyOn(Stream, "collapseText"); - Stream.initialize(); - expect(Stream.collapseText).toHaveBeenCalled(); - }) - }); - });