fixed problems with scroll to load more

This commit is contained in:
jeena 2013-04-14 13:36:53 +02:00
parent 624dd9a1b9
commit be8a0c63e3
10 changed files with 101 additions and 45 deletions

View file

@ -8,9 +8,11 @@ define([
function(HostApp, Core, Paths, URI) {
function Conversation() {
function Conversation(standalone) {
Core.call(this);
this.standalone = standalone;
this.action = "conversation";
@ -20,7 +22,7 @@ function(HostApp, Core, Paths, URI) {
this.container.appendChild(this.body)
document.getElementById("content").appendChild(this.container);
this.hide();
if(!this.standalone) this.hide();
}
Conversation.prototype = Object.create(Core.prototype);
@ -43,6 +45,8 @@ function(HostApp, Core, Paths, URI) {
Conversation.prototype.showStatus = function(id, entity) {
this.body.innerHTML = "";
this.current_post_id = id;
this.current_entity = entity;
this.append(id, entity);
}

View file

@ -417,11 +417,10 @@ function(HostApp, Core, Paths, URI) {
if(statuses != null && statuses.length > 0) {
var last_status = statuses[statuses.length -1];
this.before.id = last_status.id
this.before.entity = last_status.entity;
this.before.loading = false;
if (append) statuses = statuses.reverse();
for(var i = statuses.length-1, c=0; i>=c; --i) {
var status = statuses[i];
@ -460,11 +459,11 @@ function(HostApp, Core, Paths, URI) {
}
Profile.prototype.getMoreStatusPosts = function() {
if (!this.before.loading && this.before.id) {
if (!this.before.loading) {
this.before.loading = true;
var add_search = {
"before_id": this.before.id,
"before_id_entity": this.before.entity
"before_id": this.body.lastChild.status.id,
"before_id_entity": this.body.lastChild.status.entity
}
this.getStatuses(this.server, add_search, true);
}

View file

@ -20,8 +20,7 @@ function(HostApp, Paths, Cache) {
this.menu.user = this.createItem("User", function() { _this.onEntity(); return false; }, "img/sidebar/user.png", "img/sidebar/user.png");
this.menu.timeline = this.createItem("Timeline", function() { _this.onTimeline(); return false; }, "img/sidebar/timeline.png", "img/sidebar/timeline_active.png", true);
this.menu.mentions = this.createItem("Mentions", function() { _this.onMentions(); return false; }, "img/sidebar/mentions.png", "img/sidebar/mentions_active.png");
this.menu.mentions = this.createItem("Mentions", function() { _this.onMentions(); return false; }, "img/sidebar/mentions.png", "img/sidebar/mentions_active.png");
this.menu.conversation = this.createItem("Conversation", function() { _this.onConversation(); return false; }, "img/sidebar/conversation.png", "img/sidebar/conversation_active.png");
this.menu.entityProfile = this.createItem("Profile", function() { _this.onEntityProfile(); return false; }, "img/sidebar/profile.png", "img/sidebar/profile_active.png");
this.menu.search = this.createItem("Search", function() { _this.onSearch(); return false; }, "img/sidebar/search.png", "img/sidebar/search_active.png")
@ -35,13 +34,22 @@ function(HostApp, Paths, Cache) {
this.unreadMentionsSpan = document.createElement("span");
this.unreadMentionsSpan.className = "unread_mentions";
this.menu.mentions.appendChild(this.unreadMentionsSpan);
this.menu.mentions.getElementsByTagName("a")[0].appendChild(this.unreadMentionsSpan);
this.setUnreadMentions(0);
this.menu.conversation.getElementsByTagName("a")[0].ondblclick = function() {
var postId = bungloo.conversation.current_post_id;
var entity = bungloo.conversation.current_entity;
if (postId && entity) {
HostApp.showConversationViewForPostIdandEntity(postId, entity);
}
}
document.getElementById("sidebar").appendChild(this.body);
// initial seting of the <body> class
document.body.className = "body-timeline";
document.body.id = "with-sidebar";
this.setEntityAvatar();
this.setOnScroll();

View file

@ -14,7 +14,7 @@ function(Core, Paths, HostApp, URI) {
this.action = "timeline";
this.reload_blocked = false;
this.max_length = 20;
this.max_length = 25;
this.timeout = 10 * 1000; // every 10 seconds
this.since_id = null;
this.since_id_entity = null;
@ -49,11 +49,10 @@ function(Core, Paths, HostApp, URI) {
if(statuses != null && statuses.length > 0) {
var last_status = statuses[statuses.length -1];
this.before.id = last_status.id
this.before.entity = last_status.entity;
this.before.loading = false;
if (append) statuses = statuses.reverse();
for(var i = statuses.length-1, c=0; i>=c; --i) {
var status = statuses[i];
@ -66,18 +65,20 @@ function(Core, Paths, HostApp, URI) {
var new_node = this.getStatusDOMElement(status);
if(!append && this.body.childNodes.length > 0) {
if (!document.getElementById(new_node.id)) {
if(!append && this.body.childNodes.length > 0) {
if(this.body.childNodes.length > this.max_length) {
if(this.body.childNodes.length > this.max_length) {
this.body.removeChild(this.body.lastChild);
this.body.removeChild(this.body.lastChild);
}
this.body.insertBefore(new_node, this.body.firstChild);
} else {
this.body.appendChild(new_node);
}
this.body.insertBefore(new_node, this.body.firstChild);
} else {
this.body.appendChild(new_node);
}
} else if (status.type == "https://tent.io/types/post/delete/v0.1.0") {
@ -107,7 +108,7 @@ function(Core, Paths, HostApp, URI) {
"https://tent.io/types/post/photo/v0.1.0"
];
url.addSearch("post_types", post_types.join(","));
//url.addSearch("sort_by", "published_at");
url.addSearch("limit", this.max_length);
if(this.since_id && !append) {
@ -147,12 +148,13 @@ function(Core, Paths, HostApp, URI) {
}
Timeline.prototype.getMoreStatusPosts = function() {
if (!this.before.loading && this.before.id) {
if (!this.before.loading) {
this.before.loading = true;
var add_search = {
"before_id": this.before.id,
"before_id_entity": this.before.entity
"before_id": this.body.lastChild.status.id,
"before_id_entity": this.body.lastChild.status.entity
}
this.getNewData(add_search, true);
}
}

View file

@ -4,7 +4,8 @@ define([
"lib/URI",
"helper/HostApp",
"helper/Cache",
"lib/Timeago"
"lib/Timeago",
"lib/SingleDoubleClick"
],
function(jQuery, Paths, URI, HostApp, Cache) {
@ -336,10 +337,12 @@ function(jQuery, Paths, URI, HostApp, Cache) {
template.ago.appendChild(time);
template.ago.href = "#"
template.ago.onclick = function() {
$(template.ago).single_double_click(function () {
HostApp.showConversation(status.id, status.entity);
return false;
}
}, function () {
HostApp.showConversationViewForPostIdandEntity(status.id, status.entity);
});
// {"type":"Point","coordinates":[57.10803113,12.25854746]}
if (status.content && status.content.location && (typeof status.content.location.type == "undefined" || status.content.location.type == "Point")) {
@ -370,7 +373,7 @@ function(jQuery, Paths, URI, HostApp, Cache) {
}
Core.prototype.getRepost = function(repost, before_node) {
Core.prototype.getRepost = function(repost, before_node, append) {
var post = document.getElementById("post-" + repost.content.id + "-" + this.action);
@ -450,7 +453,7 @@ function(jQuery, Paths, URI, HostApp, Cache) {
var status = JSON.parse(resp.responseText);
status.__repost = repost;
var li = _this.getStatusDOMElement(status);
before_node.parentNode.insertBefore(li, before_node);
if(!document.getElementById(li.id)) before_node.parentNode.insertBefore(li, before_node);
_this.getRepost(repost, before_node); // call this recursive because we now have the repost
}
}
@ -994,7 +997,8 @@ function(jQuery, Paths, URI, HostApp, Cache) {
Core.prototype.afterChangingTextinMessageHTML = function(message_node) {
// adding show search on click hash
$(message_node).find("a.hash").click(function(e) {
bungloo.search.searchFor(e.target.innerHTML);
if(bungloo.search) bungloo.search.searchFor(e.target.innerHTML);
return false;
});

View file

@ -95,6 +95,14 @@ define(function() {
}
}
HostApp.showConversationViewForPostIdandEntity = function(id, entity) {
if (OS_TYPE == "mac") {
controller.showConversationViewForPostId_andEntity_(id, entity);
} else {
controller.showConversationViewForPostIdandEntity(id, entity);
}
}
HostApp.showProfileForEntity = function(entity) {
if (OS_TYPE == "mac") {

View file

@ -14,7 +14,7 @@ requirejs.config({
baseUrl: 'scripts'
});
function start(view) {
function start(view, callback) {
if (view == "oauth") {
@ -24,6 +24,15 @@ function start(view) {
});
} else if (view == "conversation-standalone") {
require(["controller/Conversation"], function(Conversation) {
bungloo.conversation = new Conversation(true);
if(callback) callback();
});
} else {
@ -141,7 +150,7 @@ function loadCssPlugin(css_url) {
function debug(string) {
if (typeof string != "string") {
string = JSON.stringify(string);
string = JSON.stringify(string);
}
console.debug(string);