content update wip
This commit is contained in:
parent
fc25c9bedb
commit
50e67524c1
5 changed files with 62 additions and 19 deletions
26
public/javascripts/content-updates.js
Normal file
26
public/javascripts/content-updates.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
* licensed under the Affero General Public License version 3 or later. See
|
||||||
|
* the COPYRIGHT file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var ContentUpdates = {
|
||||||
|
addPostToStream: function(postId, html) {
|
||||||
|
if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) {
|
||||||
|
var streamElement = $(html);
|
||||||
|
|
||||||
|
if($("#no_posts").length) {
|
||||||
|
$("#no_posts").detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
streamElement.prependTo("#main_stream:not('.show')").fadeIn("fast", function() {
|
||||||
|
streamElement.find("label").inFieldLabels();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Diaspora.widgets.publish("stream/postAdded", [postId]);
|
||||||
|
|
||||||
|
Diaspora.widgets.timeago.updateTimeAgo();
|
||||||
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -133,25 +133,7 @@ var WebSocketReceiver = {
|
||||||
},
|
},
|
||||||
|
|
||||||
addPostToStream: function(postId, html) {
|
addPostToStream: function(postId, html) {
|
||||||
if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) {
|
|
||||||
var streamElement = $(html);
|
|
||||||
|
|
||||||
var showMessage = function() {
|
|
||||||
$("#main_stream:not('.show')").prepend(
|
|
||||||
streamElement.fadeIn("fast", function() {
|
|
||||||
streamElement.find("label").inFieldLabels();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
if( $("#no_posts").is(":visible") ) {
|
|
||||||
$("#no_posts").fadeOut(400, showMessage()).hide();
|
|
||||||
} else {
|
|
||||||
showMessage();
|
|
||||||
}
|
|
||||||
Diaspora.widgets.timeago.updateTimeAgo();
|
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onPageForClass: function(className) {
|
onPageForClass: function(className) {
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ describe AspectsController do
|
||||||
bob.comment("what", :on => message)
|
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")
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with getting_started = true' do
|
context 'with getting_started = true' do
|
||||||
|
|
|
||||||
32
spec/javascripts/content-updates-spec.js
Normal file
32
spec/javascripts/content-updates-spec.js
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
* licensed under the Affero General Public License version 3 or later. See
|
||||||
|
* the COPYRIGHT file.
|
||||||
|
*/
|
||||||
|
describe("ContentUpdates", function() {
|
||||||
|
describe("addPostToStream", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
$("#jasmine_content").empty();
|
||||||
|
spec.loadFixture("aspects_index_with_posts");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("adds a post to the stream", function() {
|
||||||
|
var originalPostCount = $(".stream_element").length;
|
||||||
|
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
||||||
|
expect($(".stream_element").length).toBeGreaterThan(originalPostCount);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not add duplicate posts", function() {
|
||||||
|
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
||||||
|
var originalPostCount = $(".stream_element").length;
|
||||||
|
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
||||||
|
expect($(".stream_element").length).toEqual(originalPostCount);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes the div that says you have no posts if it exists", function() {
|
||||||
|
spec.loadFixture("aspects_index");
|
||||||
|
expect($("#no_posts").length).toEqual(1);
|
||||||
|
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
||||||
|
expect($("#no_posts").length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -40,6 +40,7 @@ src_files:
|
||||||
- public/javascripts/validation.js
|
- public/javascripts/validation.js
|
||||||
- public/javascripts/rails.js
|
- public/javascripts/rails.js
|
||||||
- public/javascripts/aspect-filters.js
|
- public/javascripts/aspect-filters.js
|
||||||
|
- public/javascripts/content-updates.js
|
||||||
# stylesheets
|
# stylesheets
|
||||||
#
|
#
|
||||||
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue