+*/
-function addMoreHistory( xmlDoc ){
- var response = xmlDoc.responseText;
+var preloadDistance = 1000;
+var isUpdating = false;
+var isMouseDown = false;
+var checker;
+var v;
+var cookie = 'no_pager';
- var index_el = getElement("history_index");
- var indexVal = parseInt(index_el.value);
+/*
+ function to log debugging information into debug div
+*/
- // minimum response length?
- if (response.length < 500){
-
- showElement("footer")
- if( indexVal > 0 ){
- var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'},
- "No more results."
- );
- }else{
- var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'},
- "No results matched your search."
- );
- }
- replaceChildNodes( "more_history", out )
- getElement("status").innerHTML = '';
- return;
- }
+function logDebug( m1, m2 ) {
+ var m = m1;
+ if (m2) m += m2;
+ if (m) $('#debug').append( ''+m+'
' );
+}
+
+function log( m1, m2 ) {
+ var m = m1;
+ if (m2) m += m2;
+ m += ''
+ if (m) $('#debug').append( m );
+}
+
+function load_page() {
+ setCookie(cookie+"_height", getScrollHeight() );
+ setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() );
+
+ if ( isUpdating == true
+ || isMouseDown == true
+ || getPageHeight() - getScrollHeight() > preloadDistance
+ || v.page >= v.max_page
+ ) return;
+
+ v.page++;
+
+ log(
+ 'Get page:' + v.page + '
search: ' + v.search +
+ ' PageHeight:' + getPageHeight() + ' ScrollHeight:' + getScrollHeight()
+ );
+
+ setCookie( cookie+'_page', v.page );
+ isUpdating = true;
+
+ $('#status').html(
+ 'Loading page '+ v.page + '...'
+ );
+
+ $.get(
+ "index.cgi/snippet",
+ {
+ page: v.page,
+ search: v.search
+ },
+ function ( response ) {
+
+ $('#next_page').html( response );
+
+ eval( 'v=' + $('#json').val() );
+
+ isUpdating = false;
+ $('#status').html( v.status );
+ }
+ );
- response += "";
- response += " More posts are being loaded...
";
- response += " If you are using the scroll bar, release the mouse to see more posts.";
- response += "
"
-
- index_el.value = indexVal + 1;
-
- var new_history = DIV(null,"");
- new_history.innerHTML = response;
- swapDOM( "more_history", new_history );
-
- isUpdating = false;
-
- var status_update = getElement("status_update");
- var status = getElement("status");
- if (status_update && status) {
- status.innerHTML = status_update.innerHTML;
- log("status updated");
- }
}
-function updatePage(){
- if ( isUpdating == false
- && mouseState == "up"
- && getPageHeight() - getScrollHeight() < preloadDistance){
- log("Getting segment: ", $("history_index").value);
- setCookie(id, $("history_index").value );
- isUpdating = true;
- getMoreHistory();
- }
- checker.cancel();
- checker = callLater(checkInterval, updatePage);
-}
+/*
+ bind events and init no_pager
+*/
+$(document).ready( function() {
-function onMouseDown(e ){
- mouseState = "down";
- setCookie(id+"_height", getScrollHeight() );
- setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );
-}
+ logDebug( 'no_page binding events' );
-function onMouseUp(){
- mouseState = "up";
-}
+ eval( 'v=' + $('#json').val() );
-var checker;
-var checkInterval = .2;
-var preloadDistance = 1000;
-var isUpdating = false;
-var mouseState = "up";
-var id;
+ var cookie_id = getCookie(cookie+'_id') || 0;
+
+ logDebug("Page ID:", v.id);
+ logDebug("Page Cookie:", cookie_id);
-function init( ){
- document.onmousedown = onMouseDown;
- document.onmouseup = onMouseUp;
-
- //createLoggingPane(true);
- id = $("page_id").value;
- logDebug("Page ID:", id);
- logDebug("Page Cookie:", getCookie(id));
-
var fromBackButton = false;
- if( getCookie(id) ){ fromBackButton = true; }
- else{ setCookie(id, "1") }
+ if ( cookie_id == v.id ) {
+ fromBackButton = true;
+ } else {
+ 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").style.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') );
+ }
+
+ $(window).mousedown( function () {
+ isMouseDown = true;
+ });
+ $(window).mouseup( function () {
+ isMouseDown = false;
+ });
+
+ checker = setInterval(function () {
+ load_page();
+ }, 100);
- getElement("history_index").value = 0;
- checker = callLater(0, updatePage);
-}
-addLoadEvent(init);
+});