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

Legend:
Removed from v.2  
changed lines
  Added in v.16

  ViewVC Help
Powered by ViewVC 1.1.26