--- no_pager/no_pager.js 2006/08/16 14:20:18 11
+++ no_pager/no_pager.js 2006/08/16 21:34:37 15
@@ -8,8 +8,9 @@
var preloadDistance = 1000;
var isUpdating = false;
-var id;
var checker;
+var v;
+var cookie = 'no_pager';
/*
function to log debugging information into debug div
@@ -29,38 +30,39 @@
}
function load_page() {
- setCookie(id+"_height", getScrollHeight() );
- setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );
+ setCookie(cookie+"_height", getScrollHeight() );
+ setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() );
if ( isUpdating == true
|| getPageHeight() - getScrollHeight() > preloadDistance
+ || v.page >= v.max_page
) return;
- var history_index = parseInt( $('#history_index').val() );
- var q = $('#q').val();
+ v.page++;
- if (! q || q == '') return;
-
- log("Getting segment: " + history_index + " for: "+q);
+ log(
+ 'Get page:' + v.page + '
search: ' + v.search +
+ ' PageHeight:' + getPageHeight() + ' ScrollHeight:' + getScrollHeight()
+ );
- setCookie( id, history_index );
+ setCookie( cookie+'_page', v.page );
isUpdating = true;
$('#status').html(
- 'Loading page '+ ( history_index + 1 ) + '...'
+ 'Loading page '+ v.page + '...'
);
$.get(
"index.cgi/snippet",
{
- index: history_index,
- q: q
+ page: v.page,
+ search: v.search,
},
function ( response ) {
if (response.length < 500) {
$('#footer').show();
- if ( history_index > 0 ) {
+ if ( v.page > 0 ) {
$('#more_history').html('
No more results.
');
} else {
$('#more_history').html('No results matched your search.
');
@@ -74,9 +76,11 @@
response += " If you are using the scroll bar, release the mouse to see more posts.";
response += ""
$('#more_history').html( response );
- $('#history_index').val( history_index + 1 );
+
+ eval( 'v=' + $('#json').val() );
+
isUpdating = false;
- $('#status').html( $('#status_update').html() );
+ $('#status').html( v.status );
}
);
@@ -91,30 +95,33 @@
logDebug( 'no_page binding events' );
- checker = setInterval(function () {
- load_page();
- }, 100);
+ eval( 'v=' + $('#json').val() );
- id = $('#page_id').val();
- logDebug("Page ID:", id);
- logDebug("Page Cookie:", getCookie(id));
+ var cookie_id = getCookie(cookie+'_id') || 0;
+
+ logDebug("Page ID:", v.id);
+ logDebug("Page Cookie:", cookie_id);
var fromBackButton = false;
- if ( getCookie(id) ) {
+ if ( cookie_id == v.id ) {
fromBackButton = true;
} else {
- setCookie(id, "1");
+ setCookie(cookie+'_id', v.id);
}
logDebug("From Back Button?:", fromBackButton);
- if( fromBackButton ){
- logDebug( "Number of segments loaded: ", getCookie(id) );
- logDebug( "Should scroll to: ", getCookie(id+"_scroll") );
- $('#spacer').height( getCookie(id+"_height")+"px" );
- scroll( 0, getCookie(id+"_scroll") );
+ if ( fromBackButton ) {
+ logDebug( 'Load ' + getCookie(cookie+'_page') + ' pages');
+ logDebug( 'Scroll to:' + getCookie(cookie+'_scroll') );
+ $('#spacer').height( getCookie(cookie+'_height')+"px" );
+ scroll( 0, getCookie(cookie+'_scroll') );
}
- $('#history_index').val( 0 );
- load_page();
+
+ checker = setInterval(function () {
+ load_page();
+ }, 100);
+
+
});