infinite scrolling

This commit is contained in:
Andrew Dolgov 2007-08-09 08:36:04 +01:00
parent e4914b6275
commit ac54143200
3 changed files with 92 additions and 24 deletions

View File

@ -1,5 +1,7 @@
//var xmlhttp = Ajax.getTransport();
var feed_cur_page = 0;
function viewCategory(cat) {
active_feed_is_cat = true;
viewfeed(cat, '', true);
@ -35,13 +37,35 @@ function viewFeedGoPage(i) {
}
}
function viewNextFeedPage() {
try {
if (!getActiveFeedId()) return;
feed_cur_page++;
viewfeed(getActiveFeedId(), undefined, undefined, undefined,
undefined, feed_cur_page);
} catch (e) {
exception_error(e, "viewFeedGoPage");
}
}
function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
try {
//if (!offset) page_offset = 0;
// if (!offset) page_offset = 0;
if (offset != undefined) {
if (offset > 0) {
page_offset = offset;
} else {
page_offset = 0;
feed_cur_page = 0;
}
if (getActiveFeedId() != feed) {
feed_cur_page = 0;
}
enableHotkeys();

View File

@ -3693,7 +3693,9 @@
$topmost_article_ids = array();
if (!$offset) $offset = 0;
if (!$offset) {
$offset = 0;
}
if ($subop == "undefined") $subop = "";
@ -3777,24 +3779,26 @@
/// STOP //////////////////////////////////////////////////////////////////////////////////
print "<div id=\"headlinesContainer\" $rtl_tag>";
if (!$offset) {
print "<div id=\"headlinesContainer\" $rtl_tag>";
if (!$result) {
print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
return;
if (!$result) {
print "<div align='center'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
return;
}
print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
$rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
$offset, $limit);
print "<div id=\"headlinesInnerContainer\" onscroll=\"headlines_scroll_handler()\">";
}
print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
$rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
$offset, $limit);
print "<div id=\"headlinesInnerContainer\">";
if (db_num_rows($result) > 0) {
# print "\{$offset}";
if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
print "<table class=\"headlinesList\" id=\"headlinesList\"
cellspacing=\"0\">";
}
@ -3975,7 +3979,7 @@
++$lnum;
}
if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
if (!get_pref($link, 'COMBINED_DISPLAY_MODE') && !$offset) {
print "</table>";
}
@ -3984,12 +3988,13 @@
} else {
print "<div class='whiteBox'>".__('No articles found.')."</div>";
if (!$offset) print "<div class='whiteBox'>".__('No articles found.')."</div>";
}
print "</div>";
print "</div>";
if (!$offset) {
print "</div>";
print "</div>";
}
return $topmost_article_ids;
}

View File

@ -38,7 +38,10 @@ function headlines_callback() {
debug("headlines_callback");
var f = document.getElementById("headlines-frame");
try {
f.scrollTop = 0;
if (feed_cur_page == 0) {
debug("resetting headlines scrollTop");
f.scrollTop = 0;
}
} catch (e) { };
if (xmlhttp.responseXML) {
@ -47,11 +50,29 @@ function headlines_callback() {
var articles = xmlhttp.responseXML.getElementsByTagName("article");
var runtime_info = xmlhttp.responseXML.getElementsByTagName("runtime-info");
if (headlines) {
f.innerHTML = headlines.firstChild.nodeValue;
if (feed_cur_page == 0) {
if (headlines) {
f.innerHTML = headlines.firstChild.nodeValue;
} else {
debug("headlines_callback: returned no data");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
}
} else {
debug("headlines_callback: returned no data");
f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
if (headlines) {
debug("adding some more headlines...");
var c = document.getElementById("headlinesList");
if (!c) {
c = document.getElementById("headlinesInnerContainer");
}
c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
} else {
debug("headlines_callback: returned no data");
notify_error("Error while trying to load more headlines");
}
}
@ -103,6 +124,8 @@ function headlines_callback() {
try {
document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
_tag_cdm_scroll = false;
debug("resetting headlinesInner scrollTop");
} catch (e) { }
}
@ -937,3 +960,19 @@ function cdmMouseIn(elem) {
function cdmMouseOut(elem) {
active_post_id = false;
}
function headlines_scroll_handler() {
try {
var e = document.getElementById("headlinesInnerContainer");
if (e.scrollTop + e.offsetHeight == e.scrollHeight) {
debug("more cowbell!");
viewNextFeedPage();
}
} catch (e) {
exception_error("headlines_scroll_handler", e);
}
}