/[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 7 by dpavlin, Tue Aug 15 23:13:20 2006 UTC revision 11 by dpavlin, Wed Aug 16 14:20:18 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
5    
6            2006-08-16 Dobrica Pavlinusic <dpavlin@rot13.org>
7  */  */
8    
9  function favorite( image, feedID ){  var preloadDistance = 1000;
10          var makeFavorite;  var isUpdating = false;
11          if (image.src.indexOf("fav_off.gif") != -1){  var id;
12                  image.src = "static/images/fav_on.gif";  var checker;
                 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})  
           
 }  
13    
14  function getMoreHistory(){  /*
15          var indexVal = getElement("history_index").value;          function to log debugging information into debug div
16          var xmlDoc = doSimpleXMLHttpRequest("index.cgi/snippet", {index: indexVal, q: document.getElementById('q').value });  */
         xmlDoc.addCallbacks(addMoreHistory, failure);  
 }  
17    
18  function failure(){  function logDebug( m1, m2 ) {
19          var message = P( null, "" );          var m = m1;
20          message.innerHTML  = "<strong>Could not contact the Humanized server.</strong> <br />";          if (m2) m += m2;
21          message.innerHTML += "Please wait awhile and try again. <br /><br />";          if (m) $('#debug').append( '<small>'+m+'</small><br/>' );
22          message.innerHTML += "We apologize for the inconvenience.";  }
         var el = getElement("more_history");  
23    
24    function log( m1, m2 ) {
25            var m = m1;
26            if (m2) m += m2;
27            m += '</br>'
28            if (m) $('#debug').append( m );
29  }  }
30    
31  function addMoreHistory( xmlDoc ){  function load_page() {
32          var response = xmlDoc.responseText;          setCookie(id+"_height", getScrollHeight() );
33            setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );
34    
35          var index_el = getElement("history_index");          if ( isUpdating == true
36          var indexVal = parseInt(index_el.value);                  || getPageHeight() - getScrollHeight() > preloadDistance
37            ) return;
38    
39            var history_index = parseInt( $('#history_index').val() );
40            var q = $('#q').val();
41    
42            if (! q || q == '') return;
43    
44            log("Getting segment: " + history_index + " for: "+q);
45    
46            setCookie( id, history_index );
47            isUpdating = true;
48    
49            $('#status').html(
50                    'Loading page '+ ( history_index + 1 ) + '...'
51            );
52    
53            $.get(
54                    "index.cgi/snippet",
55                    {
56                            index: history_index,
57                            q: q
58                    },
59                    function ( response ) {
60                            
61                            if (response.length < 500) {
62                                    $('#footer').show();
63                                    if ( history_index > 0 ) {
64                                            $('#more_history').html('<h2 style="text-align: center; font-style:italic; padding: 2em;">No more results.</h2>');
65                                    } else {
66                                            $('#more_history').html('<h2 style="text-align: center; font-style:italic; padding: 2em;">No results matched your search.</h2>');
67                                    }
68                                    $('#status').html( 'All results shown.' );
69                                    return;
70                            }
71    
72                            response += "<div id='more_history'>";
73                            response += "  <strong>More posts are being loaded...</strong> <br />";
74                            response += "  If you are using the scroll bar, release the mouse to see more posts.";
75                            response += "</div>"
76                            $('#more_history').html( response );
77                            $('#history_index').val( history_index + 1 );
78                            isUpdating = false;
79                            $('#status').html( $('#status_update').html() );
80                    }
81            );
82    
 // minimum response length?  
         if (response.length < 300){  
                   
            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 posts matched your search."  
                                            );  
            }  
            replaceChildNodes( "more_history", out )  
            return;  
         }  
83    
         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;  
84  }  }
85    
86  function updatePage(){  /*
87          if ( isUpdating == false          bind events and init no_pager
88                          && 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);  
 }  
   
   
 function onMouseDown(e ){  
         mouseState = "down";  
         setCookie(id+"_height", getScrollHeight() );  
         setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );  
 }  
89    
90  function onMouseUp(){  $(document).ready( function() {
         mouseState = "up";  
 }  
91    
92  var checker;          logDebug( 'no_page binding events' );
 var checkInterval = .2;  
 var preloadDistance = 1000;  
 var isUpdating = false;  
 var mouseState = "up";  
 var id;  
93    
94  function init( ){          checker = setInterval(function () {
95          document.onmousedown = onMouseDown;                  load_page();
96          document.onmouseup   = onMouseUp;          }, 100);
97    
98          //createLoggingPane(true);          id = $('#page_id').val();
         id = $("page_id").value;  
99          logDebug("Page ID:", id);          logDebug("Page ID:", id);
100          logDebug("Page Cookie:", getCookie(id));          logDebug("Page Cookie:", getCookie(id));
101            
102          var fromBackButton = false;          var fromBackButton = false;
103          if( getCookie(id) ){ fromBackButton = true; }          if ( getCookie(id) ) {
104          else{ setCookie(id, "1") }                  fromBackButton = true;
105            } else {
106                    setCookie(id, "1");
107            }
108    
109          logDebug("From Back Button?:", fromBackButton);          logDebug("From Back Button?:", fromBackButton);
110          if( fromBackButton ){          if( fromBackButton ){
111                  logDebug( "Number of segments loaded: ", getCookie(id) );                  logDebug( "Number of segments loaded: ", getCookie(id) );
112                  logDebug( "Should scroll to: ", getCookie(id+"_scroll") );                  logDebug( "Should scroll to: ", getCookie(id+"_scroll") );
113                  $("spacer").style.height=getCookie(id+"_height")+"px";                  $('#spacer').height( getCookie(id+"_height")+"px" );
114                  scroll( 0, getCookie(id+"_scroll") );                                    scroll( 0, getCookie(id+"_scroll") );
115          }          }
116    
117          getElement("history_index").value = 0;          $('#history_index').val( 0 );
118          checker = callLater(0, updatePage);          load_page();
119  }  });
   
 addLoadEvent(init);  
120    

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

  ViewVC Help
Powered by ViewVC 1.1.26