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

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

  ViewVC Help
Powered by ViewVC 1.1.26