/[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 9 by dpavlin, Wed Aug 16 00:29:08 2006 UTC revision 18 by dpavlin, Wed Aug 16 23:37:51 2006 UTC
# Line 1  Line 1 
1  /*  /*
2          no pager, as seen at          no pager, as seen at
3          http://www.humanized.com/weblog/2006/04/28/reading_humanized/          http://www.humanized.com/weblog/2006/04/28/reading_humanized/
4  */          but using jquery
   
 function favorite( image, feedID ){  
         var makeFavorite;  
         if (image.src.indexOf("fav_off.gif") != -1){  
                 image.src = "static/images/fav_on.gif";  
                 makeFavorite = "True";  
         }  
         else if (image.src.indexOf("fav_on.gif") != -1){  
                 image.src = "static/images/fav_off.gif";  
                 makeFavorite = "False";  
         }  
         doSimpleXMLHttpRequest("favorite", {id: feedID, makeFavorite: makeFavorite})  
           
 }  
   
 function getMoreHistory(){  
         var indexVal = getElement("history_index").value;  
         var q = getElement('q').value;  
         getElement('status').innerHTML = 'Loading page '+ ( parseInt(indexVal) + 1 ) + '...';  
         var xmlDoc = doSimpleXMLHttpRequest("index.cgi/snippet", {index: indexVal, q: q});  
         xmlDoc.addCallbacks(addMoreHistory, failure);  
 }  
   
 function failure(){  
         var message = P( null, "" );  
         message.innerHTML  = "<strong>Could not contact the Humanized server.</strong> <br />";  
         message.innerHTML += "Please wait awhile and try again. <br /><br />";  
         message.innerHTML += "We apologize for the inconvenience.";  
         var el = getElement("more_history");  
5    
6  }          2006-08-16 Dobrica Pavlinusic <dpavlin@rot13.org>
7    */
8    
9  function addMoreHistory( xmlDoc ){  var preloadDistance = 1000;
10          var response = xmlDoc.responseText;  var isUpdating = false;
11    var isMouseDown = false;
12    var checker;
13    var v;
14    var cookie = 'no_pager';
15    
16          var index_el = getElement("history_index");  /*
17          var indexVal = parseInt(index_el.value);          function to log debugging information into debug div
18    */
19    
20  // minimum response length?  function logDebug( m1, m2 ) {
21          if (response.length < 300){          var m = m1;
22                            if (m2) m += m2;
23             showElement("footer")          if (m) $('#debug').append( '<small>'+m+'</small><br/>' );
24             if( indexVal > 0 ){  }
25                     var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'},  
26                                                  "No more results."  function log( m1, m2 ) {
27                                             );          var m = m1;
28             }else{          if (m2) m += m2;
29                     var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'},          m += '</br>'
30                                                  "No posts matched your search."          if (m) $('#debug').append( m );
31                                             );  }
32             }  
33             replaceChildNodes( "more_history", out )  function load_page() {
34             return;          setCookie(cookie+"_height", getScrollHeight() );
35          }          setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() );
36    
37            if ( isUpdating == true
38                    || isMouseDown == true
39                    || getPageHeight() - getScrollHeight() > preloadDistance
40                    || v.page >= v.max_page
41            ) return;
42    
43            v.page++;
44    
45            log(
46                    'Get page:' + v.page + '<br/>search: ' + v.search +
47                    ' PageHeight:' + getPageHeight() + ' ScrollHeight:' + getScrollHeight()
48            );
49    
50            setCookie( cookie+'_page', v.page );
51            isUpdating = true;
52    
53            $('#status').html(
54                    'Loading page '+ v.page + '...'
55            );
56    
57            $.get(
58                    "index.cgi/snippet",
59                    {
60                            page: v.page,
61                            search: v.search
62                    },
63                    function ( response ) {
64                            
65                            $('#next_page').html( response );
66    
67                            eval( 'v=' + $('#json').val() );
68    
69                            isUpdating = false;
70                            $('#status').html( v.status );
71                    }
72            );
73    
         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>"  
   
         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");  
         }  
74    
75  }  }
76    
77  function updatePage(){  /*
78          if ( isUpdating == false          bind events and init no_pager
79                          && 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);  
 }  
80    
81    $(document).ready( function() {
82    
83  function onMouseDown(e ){          logDebug( 'no_page binding events' );
         mouseState = "down";  
         setCookie(id+"_height", getScrollHeight() );  
         setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );  
 }  
84    
85  function onMouseUp(){          eval( 'v=' + $('#json').val() );
         mouseState = "up";  
 }  
86    
87  var checker;          var cookie_id = getCookie(cookie+'_id') || 0;
88  var checkInterval = .2;  
89  var preloadDistance = 1000;          logDebug("Page ID:", v.id);
90  var isUpdating = false;          logDebug("Page Cookie:", cookie_id);
 var mouseState = "up";  
 var id;  
91    
 function init( ){  
         document.onmousedown = onMouseDown;  
         document.onmouseup   = onMouseUp;  
   
         //createLoggingPane(true);  
         id = $("page_id").value;  
         logDebug("Page ID:", id);  
         logDebug("Page Cookie:", getCookie(id));  
           
92          var fromBackButton = false;          var fromBackButton = false;
93          if( getCookie(id) ){ fromBackButton = true; }          if ( cookie_id == v.id ) {
94          else{ setCookie(id, "1") }                  fromBackButton = true;
95            } else {
96                    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").style.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            $(window).mousedown( function () {
108                    isMouseDown = true;
109            });
110            $(window).mouseup( function () {
111                    isMouseDown = false;
112            });
113    
114            checker = setInterval(function () {
115                    load_page();
116            }, 100);
117    
         getElement("history_index").value = 0;  
         checker = callLater(0, updatePage);  
 }  
118    
119  addLoadEvent(init);  });
120    

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

  ViewVC Help
Powered by ViewVC 1.1.26