Scope stream scrolled events to new elements

This commit is contained in:
Raphael Sofaer 2011-08-03 12:08:24 -07:00
parent 67123a277c
commit 0b1ef41838
6 changed files with 48 additions and 31 deletions

View file

@ -18,8 +18,12 @@ var Stream = {
Stream.setUpAudioLinks(); Stream.setUpAudioLinks();
//Stream.setUpImageLinks(); //Stream.setUpImageLinks();
Diaspora.widgets.subscribe("stream/scrolled", Stream.collapseText);
},
collapseText: function(){
elements = $(Array.prototype.slice.call(arguments,1));
// collapse long posts // collapse long posts
$(".content p", this.selector).expander({ $(".content p", elements).expander({
slicePoint: 400, slicePoint: 400,
widow: 12, widow: 12,
expandText: Diaspora.widgets.i18n.t("show_more"), expandText: Diaspora.widgets.i18n.t("show_more"),
@ -27,14 +31,13 @@ var Stream = {
}); });
// collapse long comments // collapse long comments
$(".comment .content span", this.selector).expander({ $(".comment .content span", elements).expander({
slicePoint: 200, slicePoint: 200,
widow: 400, widow: 400,
expandText: Diaspora.widgets.i18n.t("show_more"), expandText: Diaspora.widgets.i18n.t("show_more"),
userCollapse: false userCollapse: false
}); });
}, },
initializeLives: function(){ initializeLives: function(){
// reshare button action // reshare button action
$(".reshare_button", this.selector).live("click", function(evt) { $(".reshare_button", this.selector).live("click", function(evt) {
@ -152,7 +155,7 @@ var Stream = {
toggle.html(Diaspora.widgets.i18n.t("comments.hide")); toggle.html(Diaspora.widgets.i18n.t("comments.hide"));
commentList.html(data) commentList.html(data)
.addClass('loaded'); .addClass('loaded');
Diaspora.widgets.publish("stream/scrolled") Diaspora.widgets.publish("stream/scrolled", commentList);
} }
}); });
} }

View file

@ -17,7 +17,8 @@ var View = {
}); });
Diaspora.widgets.subscribe("stream/scrolled", function() { Diaspora.widgets.subscribe("stream/scrolled", function() {
$('#main_stream label').inFieldLabels(); new_elements = Array.prototype.slice.call(arguments,1)
$(new_elements).find('label').inFieldLabels();
}); });
Diaspora.widgets.subscribe("stream/reloaded", function() { Diaspora.widgets.subscribe("stream/reloaded", function() {
@ -56,11 +57,15 @@ var View = {
/* Autoexpand textareas */ /* Autoexpand textareas */
var startAutoResize = function() { var startAutoResize = function() {
$('textarea') if (arguments.length > 1){
.autoResize({ target = $(Array.prototype.slice.call(arguments,1)).find('textarea');
'animate': false, }else{
'extraSpace': 5 target = $('textarea')
}); }
target.autoResize({
'animate': false,
'extraSpace': 5
});
} }
Diaspora.widgets.subscribe("stream/scrolled", startAutoResize) Diaspora.widgets.subscribe("stream/scrolled", startAutoResize)
Diaspora.widgets.subscribe("stream/reloaded", startAutoResize) Diaspora.widgets.subscribe("stream/reloaded", startAutoResize)

View file

@ -3,7 +3,7 @@
* the COPYRIGHT file. * the COPYRIGHT file.
*/ */
/* Modified version of https://gitorious.org/statusnet/mainline/blobs/master/plugins/DirectionDetector/jquery.DirectionDetector.js */ /* Modified version of https://gitorious.org/statusnet/mainline/blobs/master/plugins/DirectionDetector/jquery.DirectionDetector.js */
(function() { (function() {
var DirectionDetector = function() { var DirectionDetector = function() {
var self = this; var self = this;
this.binds = []; this.binds = [];
@ -11,8 +11,8 @@
this.subscribe("widget/ready", function() { this.subscribe("widget/ready", function() {
self.updateBinds(); self.updateBinds();
Diaspora.widgets.subscribe("stream/scrolled", function() { Diaspora.widgets.subscribe("stream/scrolled", function(eventID, new_elements) {
self.updateBinds(); self.updateBinds();
}); });
}); });
@ -21,35 +21,35 @@
if(typeof str !== "string" || str.length < 1) { if(typeof str !== "string" || str.length < 1) {
return false; return false;
} }
var charCode = str.charCodeAt(0); var charCode = str.charCodeAt(0);
if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ... if(charCode >= 1536 && charCode <= 1791) // Sarabic, Persian, ...
return true; return true;
else if(charCode >= 65136 && charCode <= 65279) // Arabic present 1 else if(charCode >= 65136 && charCode <= 65279) // Arabic present 1
return true; return true;
else if(charCode >= 64336 && charCode <= 65023) // Arabic present 2 else if(charCode >= 64336 && charCode <= 65023) // Arabic present 2
return true; return true;
else if(charCode>=1424 && charCode<=1535) // Hebrew else if(charCode>=1424 && charCode<=1535) // Hebrew
return true; return true;
else if(charCode>=64256 && charCode<=64335) // Hebrew present else if(charCode>=64256 && charCode<=64335) // Hebrew present
return true; return true;
else if(charCode>=1792 && charCode<=1871) // Syriac else if(charCode>=1792 && charCode<=1871) // Syriac
return true; return true;
else if(charCode>=1920 && charCode<=1983) // Thaana else if(charCode>=1920 && charCode<=1983) // Thaana
return true; return true;
else if(charCode>=1984 && charCode<=2047) // NKo else if(charCode>=1984 && charCode<=2047) // NKo
return true; return true;
else if(charCode>=11568 && charCode<=11647) // Tifinagh else if(charCode>=11568 && charCode<=11647) // Tifinagh
return true; return true;
return false; return false;
}; };
@ -72,7 +72,7 @@
this.updateDirection = function() { this.updateDirection = function() {
var textArea = $(this), var textArea = $(this),
cleaned = textArea.val().replace(self.cleaner, "").replace(/^[ ]+/, ""); cleaned = textArea.val().replace(self.cleaner, "").replace(/^[ ]+/, "");
if(self.isRTL(cleaned)) { if(self.isRTL(cleaned)) {
textArea.css("direction", "rtl"); textArea.css("direction", "rtl");
} }

View file

@ -34,8 +34,8 @@
this.initialize = function() { this.initialize = function() {
if($('#main_stream').length !== 0){ if($('#main_stream').length !== 0){
$('#main_stream').infinitescroll(this.options, function() { $('#main_stream').infinitescroll(this.options, function(new_elements) {
Diaspora.widgets.publish("stream/scrolled"); Diaspora.widgets.publish("stream/scrolled", new_elements);
}); });
} else if($('#people_stream').length !== 0){ } else if($('#people_stream').length !== 0){
$("#people_stream").infinitescroll($.extend(self.options, { $("#people_stream").infinitescroll($.extend(self.options, {
@ -44,8 +44,8 @@
pathParse : function( pathStr, nextPage){ pathParse : function( pathStr, nextPage){
return pathStr.replace("page=2", "page=" + nextPage); return pathStr.replace("page=2", "page=" + nextPage);
} }
}), function() { }), function(new_elements) {
Diaspora.widgets.publish("stream/scrolled"); Diaspora.widgets.publish("stream/scrolled", new_elements);
}); });
} }
}; };

View file

@ -23,7 +23,12 @@
}; };
this.updateTimeAgo = function() { this.updateTimeAgo = function() {
self.timeAgoElement().timeago(); if (arguments.length > 1){
new_elements = Array.prototype.slice.call(arguments,1);
$(new_elements).find(self.selector).timeago();
}else{
self.timeAgoElement().timeago();
}
}; };
}; };
Diaspora.widgets.add("timeago", TimeAgo); Diaspora.widgets.add("timeago", TimeAgo);

View file

@ -20,17 +20,21 @@ describe("Stream", function() {
}); });
}); });
describe("initialize", function() { describe("collapseText", function() {
it("adds a 'show more' links to long posts", function() { it("adds a 'show more' links to long posts", function() {
Diaspora.widgets.i18n.loadLocale( Diaspora.widgets.i18n.loadLocale(
{show_more: 'Placeholder'}, 'en'); {show_more: 'Placeholder'}, 'en');
Stream.initialize();
stream_element = $('#main_stream .stream_element:first'); 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("p .details").css('display')).toEqual('none');
expect(stream_element.find(".read-more a").css('display')).toEqual('inline'); expect(stream_element.find(".read-more a").css('display')).toEqual('inline');
stream_element.find(".read-more a").click(); stream_element.find(".read-more a").click();
jasmine.Clock.tick(200); jasmine.Clock.tick(200);
expect(stream_element.find(".read-more").css('display')).toEqual('none'); expect(stream_element.find(".read-more").css('display')).toEqual('none');
expect(stream_element.find(".details").css('display')).toEqual('inline'); expect(stream_element.find(".details").css('display')).toEqual('inline');
}); });