Fix the thing that I broke in the build, fix syntax error in the build that disabled stream-spec
This commit is contained in:
parent
5676fdc73e
commit
cfd077a90d
3 changed files with 39 additions and 51 deletions
26
public/javascripts/vendor/jquery.expander.js
vendored
26
public/javascripts/vendor/jquery.expander.js
vendored
|
|
@ -19,21 +19,21 @@
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
|
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
|
||||||
var cleanedTag, startTags, endTags;
|
var cleanedTag, startTags, endTags;
|
||||||
var allText = $this.html();
|
var allText = $this.html();
|
||||||
var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,'');
|
var startText = allText.slice(0, o.slicePoint).replace(/\w+$/,'');
|
||||||
startTags = startText.match(/<\w[^>]*>/g);
|
startTags = startText.match(/<\w[^>]*>/g);
|
||||||
if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}
|
if (startTags) {startText = allText.slice(0,o.slicePoint + startTags.join('').length).replace(/\w+$/,'');}
|
||||||
|
|
||||||
if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {
|
if (startText.lastIndexOf('<') > startText.lastIndexOf('>') ) {
|
||||||
startText = startText.slice(0,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
|
// create necessary expand/collapse elements if they don't already exist
|
||||||
if (!$('span.details', this).length) {
|
if (!$('span.details', this).length) {
|
||||||
// end script if text length isn't long enough.
|
// end script if text length isn't long enough.
|
||||||
if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; }
|
if ( endText.replace(/\s+$/,'').split(' ').length < o.widow ) { return; }
|
||||||
// otherwise, continue...
|
// otherwise, continue...
|
||||||
if (endText.indexOf('</') > -1) {
|
if (endText.indexOf('</') > -1) {
|
||||||
endTags = endText.match(/<(\/)?[^>]*>/g);
|
endTags = endText.match(/<(\/)?[^>]*>/g);
|
||||||
for (var i=0; i < endTags.length; i++) {
|
for (var i=0; i < endTags.length; i++) {
|
||||||
|
|
@ -45,12 +45,12 @@
|
||||||
if (startTag == rSlash(endTags[i])) {
|
if (startTag == rSlash(endTags[i])) {
|
||||||
startTagExists = true;
|
startTagExists = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!startTagExists) {
|
if (!startTagExists) {
|
||||||
startText = startText + endTags[i];
|
startText = startText + endTags[i];
|
||||||
var matched = false;
|
var matched = false;
|
||||||
for (var s=startTags.length - 1; s >= 0; s--) {
|
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) {
|
&& matched == false) {
|
||||||
cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];
|
cleanedTag = cleanedTag ? startTags[s] + cleanedTag : startTags[s];
|
||||||
matched = true;
|
matched = true;
|
||||||
|
|
@ -116,7 +116,7 @@
|
||||||
}
|
}
|
||||||
function delayCollapse(option, $collapseEl) {
|
function delayCollapse(option, $collapseEl) {
|
||||||
if (option.collapseTimer) {
|
if (option.collapseTimer) {
|
||||||
delayedCollapse = setTimeout(function() {
|
delayedCollapse = setTimeout(function() {
|
||||||
reCollapse($collapseEl);
|
reCollapse($collapseEl);
|
||||||
option.onCollapse($collapseEl.parent(), false);
|
option.onCollapse($collapseEl.parent(), false);
|
||||||
},
|
},
|
||||||
|
|
@ -126,17 +126,17 @@
|
||||||
}
|
}
|
||||||
function rSlash(rString) {
|
function rSlash(rString) {
|
||||||
return rString.replace(/\//,'');
|
return rString.replace(/\//,'');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// plugin defaults
|
// plugin defaults
|
||||||
$.fn.expander.defaults = {
|
$.fn.expander.defaults = {
|
||||||
slicePoint: 100, // the number of characters at which the contents will be sliced into two parts.
|
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
|
// Note: any tag names in the HTML that appear inside the sliced element before
|
||||||
// the slicePoint will be counted along with the text characters.
|
// 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.
|
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
|
// 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.
|
// 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
|
// clicking this will expand/show the hidden/collapsed text
|
||||||
expandPrefix: '… ',
|
expandPrefix: '… ',
|
||||||
collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again
|
collapseTimer: 0, // number of milliseconds after text has been expanded at which to collapse the text again
|
||||||
|
|
|
||||||
|
|
@ -64,11 +64,11 @@ describe AspectsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'generates a jasmine fixture with posts', :fixture => 'jasmine' do
|
it 'generates a jasmine fixture with posts', :fixture => 'jasmine' do
|
||||||
message = alice.post(:status_message, :text => "hello", :to => @alices_aspect_2.id)
|
message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id)
|
||||||
bob.comment("what", :on => message)
|
4.times { bob.comment("what", :on => message) }
|
||||||
get :index
|
get :index
|
||||||
save_fixture(html_for("body"), "aspects_index_with_posts")
|
save_fixture(html_for("body"), "aspects_index_with_posts")
|
||||||
|
|
||||||
save_fixture(html_for(".stream_element:first"), "status_message_in_stream")
|
save_fixture(html_for(".stream_element:first"), "status_message_in_stream")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,12 @@
|
||||||
* licensed under the Affero General Public License version 3 or later. See
|
* licensed under the Affero General Public License version 3 or later. See
|
||||||
* the COPYRIGHT file.
|
* the COPYRIGHT file.
|
||||||
*/
|
*/
|
||||||
function randomString(string_length) {
|
|
||||||
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz ";
|
|
||||||
var randomstring = '';
|
|
||||||
for (var i=0; i<string_length; i++) {
|
|
||||||
var rnum = Math.floor(Math.random() * chars.length);
|
|
||||||
randomstring += chars.substring(rnum,rnum+1);
|
|
||||||
}
|
|
||||||
return randomstring;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("Stream", function() {
|
describe("Stream", function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
jasmine.Clock.useMock();
|
jasmine.Clock.useMock();
|
||||||
spec.loadFixture('aspects_index_with_posts');
|
spec.loadFixture('aspects_index_with_posts');
|
||||||
|
Diaspora.widgets.i18n.locale = { };
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("initialize", function() {
|
describe("initialize", function() {
|
||||||
|
|
@ -27,44 +19,40 @@ describe("Stream", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds a 'show more' links to long posts", function() {
|
it("adds a 'show more' links to long posts", function() {
|
||||||
$("#jasmine_content").html(
|
Diaspora.widgets.i18n.loadLocale(
|
||||||
'<li class="stream_element">' +
|
{show_more: 'Placeholder'}, 'en');
|
||||||
'<div class="content">' +
|
|
||||||
'<p id="text">' +
|
|
||||||
randomString(1000) +
|
|
||||||
'</p>' +
|
|
||||||
'</div>' +
|
|
||||||
'</li>'
|
|
||||||
);
|
|
||||||
Stream.initialize();
|
Stream.initialize();
|
||||||
expect($(".details").css('display')).toEqual('none');
|
stream_element = $('#main_stream .stream_element:first');
|
||||||
expect($(".read-more a").css('display').toEqual('inline');
|
expect(stream_element.find(".details").css('display')).toEqual('none');
|
||||||
expect($(".re-collapse a").css('display')).toEqual('none');
|
expect(stream_element.find(".read-more a").css('display')).toEqual('inline');
|
||||||
$(".read-more a").click();
|
stream_element.find(".read-more a").click();
|
||||||
jasmine.Clock.tick(200);
|
jasmine.Clock.tick(200);
|
||||||
expect($(".read-more a").css('display').toEqual('none');
|
expect(stream_element.find(".read-more").css('display')).toEqual('none');
|
||||||
expect($(".re-collapse a").css('display')).toEqual('inline');
|
expect(stream_element.find(".details").css('display')).toEqual('inline');
|
||||||
expect($(".details").css('display')).toEqual('inline');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("toggleComments", function() {
|
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 () {
|
it("toggles class hidden on the comment block", function () {
|
||||||
expect(jQuery('ul.comments')).not.toHaveClass("hidden");
|
link = $("a.show_post_comments");
|
||||||
$("a.show_post_comments").click();
|
expect(jQuery('ul.comments .older_comments')).toHaveClass("hidden");
|
||||||
|
Stream.toggleComments.call(
|
||||||
|
link, {preventDefault: function(){} }
|
||||||
|
);
|
||||||
jasmine.Clock.tick(200);
|
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() {
|
it("changes the text on the show comments link", function() {
|
||||||
expect($("a.show_post_comments").text()).toEqual("hide comments (1)");
|
link = $("a.show_post_comments");
|
||||||
$("a.show_post_comments").click();
|
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);
|
jasmine.Clock.tick(200);
|
||||||
expect($("a.show_post_comments").text()).toEqual("show comments (1)");
|
expect(link.text()).toEqual("comments.hide pl");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue