/[jquery]/no_pager/no_pager.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /no_pager/no_pager.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 11 by dpavlin, Wed Aug 16 14:20:18 2006 UTC revision 15 by dpavlin, Wed Aug 16 21:34:37 2006 UTC
# Line 8  Line 8 
8    
9  var preloadDistance = 1000;  var preloadDistance = 1000;
10  var isUpdating = false;  var isUpdating = false;
 var id;  
11  var checker;  var checker;
12    var v;
13    var cookie = 'no_pager';
14    
15  /*  /*
16          function to log debugging information into debug div          function to log debugging information into debug div
# Line 29  function log( m1, m2 ) { Line 30  function log( m1, m2 ) {
30  }  }
31    
32  function load_page() {  function load_page() {
33          setCookie(id+"_height", getScrollHeight() );          setCookie(cookie+"_height", getScrollHeight() );
34          setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );          setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() );
35    
36          if ( isUpdating == true          if ( isUpdating == true
37                  || getPageHeight() - getScrollHeight() > preloadDistance                  || getPageHeight() - getScrollHeight() > preloadDistance
38                    || v.page >= v.max_page
39          ) return;          ) return;
40    
41          var history_index = parseInt( $('#history_index').val() );          v.page++;
         var q = $('#q').val();  
42    
43          if (! q || q == '') return;          log(
44                    'Get page:' + v.page + '<br/>search: ' + v.search +
45          log("Getting segment: " + history_index + " for: "+q);                  ' PageHeight:' + getPageHeight() + ' ScrollHeight:' + getScrollHeight()
46            );
47    
48          setCookie( id, history_index );          setCookie( cookie+'_page', v.page );
49          isUpdating = true;          isUpdating = true;
50    
51          $('#status').html(          $('#status').html(
52                  'Loading page '+ ( history_index + 1 ) + '...'                  'Loading page '+ v.page + '...'
53          );          );
54    
55          $.get(          $.get(
56                  "index.cgi/snippet",                  "index.cgi/snippet",
57                  {                  {
58                          index: history_index,                          page: v.page,
59                          q: q                          search: v.search,
60                  },                  },
61                  function ( response ) {                  function ( response ) {
62                                                    
63                          if (response.length < 500) {                          if (response.length < 500) {
64                                  $('#footer').show();                                  $('#footer').show();
65                                  if ( history_index > 0 ) {                                  if ( v.page > 0 ) {
66                                          $('#more_history').html('<h2 style="text-align: center; font-style:italic; padding: 2em;">No more results.</h2>');                                          $('#more_history').html('<h2 style="text-align: center; font-style:italic; padding: 2em;">No more results.</h2>');
67                                  } else {                                  } else {
68                                          $('#more_history').html('<h2 style="text-align: center; font-style:italic; padding: 2em;">No results matched your search.</h2>');                                          $('#more_history').html('<h2 style="text-align: center; font-style:italic; padding: 2em;">No results matched your search.</h2>');
# Line 74  function load_page() { Line 76  function load_page() {
76                          response += "  If you are using the scroll bar, release the mouse to see more posts.";                          response += "  If you are using the scroll bar, release the mouse to see more posts.";
77                          response += "</div>"                          response += "</div>"
78                          $('#more_history').html( response );                          $('#more_history').html( response );
79                          $('#history_index').val( history_index + 1 );  
80                            eval( 'v=' + $('#json').val() );
81    
82                          isUpdating = false;                          isUpdating = false;
83                          $('#status').html( $('#status_update').html() );                          $('#status').html( v.status );
84                  }                  }
85          );          );
86    
# Line 91  $(document).ready( function() { Line 95  $(document).ready( function() {
95    
96          logDebug( 'no_page binding events' );          logDebug( 'no_page binding events' );
97    
98          checker = setInterval(function () {          eval( 'v=' + $('#json').val() );
                 load_page();  
         }, 100);  
99    
100          id = $('#page_id').val();          var cookie_id = getCookie(cookie+'_id') || 0;
101          logDebug("Page ID:", id);  
102          logDebug("Page Cookie:", getCookie(id));          logDebug("Page ID:", v.id);
103            logDebug("Page Cookie:", cookie_id);
104    
105          var fromBackButton = false;          var fromBackButton = false;
106          if ( getCookie(id) ) {          if ( cookie_id == v.id ) {
107                  fromBackButton = true;                  fromBackButton = true;
108          } else {          } else {
109                  setCookie(id, "1");                  setCookie(cookie+'_id', v.id);
110          }          }
111    
112          logDebug("From Back Button?:", fromBackButton);          logDebug("From Back Button?:", fromBackButton);
113          if( fromBackButton ){          if ( fromBackButton ) {
114                  logDebug( "Number of segments loaded: ", getCookie(id) );                  logDebug( 'Load ' + getCookie(cookie+'_page') + ' pages');
115                  logDebug( "Should scroll to: ", getCookie(id+"_scroll") );                  logDebug( 'Scroll to:' + getCookie(cookie+'_scroll') );
116                  $('#spacer').height( getCookie(id+"_height")+"px" );                  $('#spacer').height( getCookie(cookie+'_height')+"px" );
117                  scroll( 0, getCookie(id+"_scroll") );                  scroll( 0, getCookie(cookie+'_scroll') );
118          }          }
119    
120          $('#history_index').val( 0 );  
121          load_page();          checker = setInterval(function () {
122                    load_page();
123            }, 100);
124    
125    
126  });  });
127    

Legend:
Removed from v.11  
changed lines
  Added in v.15

  ViewVC Help
Powered by ViewVC 1.1.26