diff --git a/public/javascripts/vendor/jquery.expander.js b/public/javascripts/vendor/jquery.expander.js index f56eef03c..13a8a2cb4 100644 --- a/public/javascripts/vendor/jquery.expander.js +++ b/public/javascripts/vendor/jquery.expander.js @@ -19,21 +19,21 @@ return this.each(function() { var $this = $(this); var o = $.meta ? $.extend({}, opts, $this.data()) : opts; - var cleanedTag, startTags, endTags; + var cleanedTag, startTags, endTags; var allText = $this.html(); var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,''); startTags = startText.match(/<\w[^>]*>/g); if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');} - + if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) { startText = startText.slice(0,startText.lastIndexOf('<')); } - var endText = allText.slice(startText.length); + var endText = allText.slice(startText.length); // create necessary expand/collapse elements if they don't already exist if (!$('span.details', this).length) { // end script if text length isn't long enough. if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; } - // otherwise, continue... + // otherwise, continue... if (endText.indexOf(' -1) { endTags = endText.match(/<(\/)?[^>]*>/g); for (var i=0; i < endTags.length; i++) { @@ -45,12 +45,12 @@ if (startTag == rSlash(endTags[i])) { startTagExists = true; } - } + } if (!startTagExists) { startText = startText + endTags[i]; var matched = false; for (var s=startTags.length - 1; s >= 0; s--) { - if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) + if (startTags[s].slice(0, startTags[s].indexOf(' ')).replace(/(\w)$/,'$1>') == rSlash(endTags[i]) && matched == false) { cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s]; matched = true; @@ -116,7 +116,7 @@ } function delayCollapse(option, $collapseEl) { if (option.collapseTimer) { - delayedCollapse = setTimeout(function() { + delayedCollapse = setTimeout(function() { reCollapse($collapseEl); option.onCollapse($collapseEl.parent(), false); }, @@ -126,17 +126,17 @@ } function rSlash(rString) { return rString.replace(/\//,''); - } + } }; // plugin defaults $.fn.expander.defaults = { - slicePoint: 100, // the number of characters at which the contents will be sliced into two parts. - // Note: any tag names in the HTML that appear inside the sliced element before + slicePoint: 100, // the number of characters at which the contents will be sliced into two parts. + // Note: any tag names in the HTML that appear inside the sliced element before // the slicePoint will be counted along with the text characters. - widow: 4, // a threshold of sorts for whether to initially hide/collapse part of the element's contents. - // If after slicing the contents in two there are fewer words in the second part than + widow: 4, // a threshold of sorts for whether to initially hide/collapse part of the element's contents. + // If after slicing the contents in two there are fewer words in the second part than // the value set by widow, we won't bother hiding/collapsing anything. - expandText: 'read more', // text displayed in a link instead of the hidden part of the element. + expandText: 'read more', // text displayed in a link instead of the hidden part of the element. // clicking this will expand/show the hidden/collapsed text expandPrefix: '… ', collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index f1e9d61be..a3f0fa9d6 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -64,11 +64,11 @@ describe AspectsController do end it 'generates a jasmine fixture with posts', :fixture => 'jasmine' do - message = alice.post(:status_message, :text => "hello", :to => @alices_aspect_2.id) - bob.comment("what", :on => message) + message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id) + 4.times { bob.comment("what", :on => message) } get :index save_fixture(html_for("body"), "aspects_index_with_posts") - + save_fixture(html_for(".stream_element:first"), "status_message_in_stream") end diff --git a/spec/javascripts/stream-spec.js b/spec/javascripts/stream-spec.js index c7ecd19c0..89dc7526c 100644 --- a/spec/javascripts/stream-spec.js +++ b/spec/javascripts/stream-spec.js @@ -2,20 +2,12 @@ * licensed under the Affero General Public License version 3 or later. See * the COPYRIGHT file. */ -function randomString(string_length) { - var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz "; - var randomstring = ''; - for (var i=0; i' + - '
' + - '

' + - randomString(1000) + - '

' + - '
' + - '' - ); + Diaspora.widgets.i18n.loadLocale( + {show_more: 'Placeholder'}, 'en'); Stream.initialize(); - expect($(".details").css('display')).toEqual('none'); - expect($(".read-more a").css('display').toEqual('inline'); - expect($(".re-collapse a").css('display')).toEqual('none'); - $(".read-more a").click(); + stream_element = $('#main_stream .stream_element:first'); + expect(stream_element.find(".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($(".read-more a").css('display').toEqual('none'); - expect($(".re-collapse a").css('display')).toEqual('inline'); - expect($(".details").css('display')).toEqual('inline'); + expect(stream_element.find(".read-more").css('display')).toEqual('none'); + expect(stream_element.find(".details").css('display')).toEqual('inline'); }); }); describe("toggleComments", function() { - beforeEach(function(){ - jQuery('#main_stream a.show_post_comments:not(.show)').die(); - Stream.initialize(); - }); it("toggles class hidden on the comment block", function () { - expect(jQuery('ul.comments')).not.toHaveClass("hidden"); - $("a.show_post_comments").click(); + link = $("a.show_post_comments"); + expect(jQuery('ul.comments .older_comments')).toHaveClass("hidden"); + Stream.toggleComments.call( + link, {preventDefault: function(){} } + ); jasmine.Clock.tick(200); - expect(jQuery('ul.comments')).toHaveClass("hidden"); + expect(jQuery('ul.comments .older_comments')).not.toHaveClass("hidden"); }); it("changes the text on the show comments link", function() { - expect($("a.show_post_comments").text()).toEqual("hide comments (1)"); - $("a.show_post_comments").click(); + link = $("a.show_post_comments"); + Diaspora.widgets.i18n.loadLocale( + {'comments.hide': 'comments.hide pl'}, 'en'); + expect(link.text()).toEqual("show all comments"); + Stream.toggleComments.call( + link, {preventDefault: function(){} } + ); jasmine.Clock.tick(200); - expect($("a.show_post_comments").text()).toEqual("show comments (1)"); + expect(link.text()).toEqual("comments.hide pl"); }); }); });