/[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 30 by dpavlin, Fri Aug 18 11:54:32 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  function favorite( image, feedID ){          2006-08-16 Dobrica Pavlinusic <dpavlin@rot13.org>
7          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 xmlDoc = doSimpleXMLHttpRequest("index.cgi/snippet", {index: indexVal, q: document.getElementById('q').value });  
         xmlDoc.addCallbacks(addMoreHistory, failure);  
 }  
8    
9  function failure(){  var preloadDistance = 1000;
10          var message = P( null, "" );  var isUpdating = false;
11          message.innerHTML  = "<strong>Could not contact the Humanized server.</strong> <br />";  var isMouseDown = false;
12          message.innerHTML += "Please wait awhile and try again. <br /><br />";  var checker;
13          message.innerHTML += "We apologize for the inconvenience.";  var v;
14          var el = getElement("more_history");  var cookie = 'no_pager';
15    
16  }  function load_page() {
17            setCookie(cookie+"_height", getScrollHeight() );
18            setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() );
19    
20            if ( isUpdating == true
21                    || isMouseDown == true
22                    || getPageHeight() - getScrollHeight() > preloadDistance
23                    || v.page >= v.max_page
24            ) return;
25    
26            v.page++;
27    
28            $.log.info(
29                    'get page: ' + v.page,
30                    'search: ' + v.search,
31                    'PageHeight:' + getPageHeight(),
32                    'ScrollHeight:' + getScrollHeight()
33            );
34    
35  function addMoreHistory( xmlDoc ){          setCookie( cookie+'_page', v.page );
36          var response = xmlDoc.responseText;          isUpdating = true;
37    
38          var index_el = getElement("history_index");          $('#status').html(
39          var indexVal = parseInt(index_el.value);                  'Loading page '+ v.page + '...'
40            );
41    
42            $.get(
43                    "index.cgi/snippet",
44                    {
45                            page: v.page,
46                            search: v.search
47                    },
48                    function ( response ) {
49                            
50                            $('#next_page').html( response );
51    
52                            eval( 'v=' + $('#json').val() );
53    
54                            isUpdating = false;
55                            $('#status').html( v.status );
56                    }
57            );
58    
 // 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;  
         }  
59    
         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;  
60  }  }
61    
62  function updatePage(){  /*
63          if ( isUpdating == false          bind events and init no_pager
64                     && 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);  
 }  
65    
66    $(document).ready( function() {
67    
68  function onMouseDown(e ){          $.log.info('no_page binding events');
         mouseState = "down";  
         setCookie(id+"_height", getScrollHeight() );  
         setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );  
 }  
69    
70  function onMouseUp(){          eval( 'v=' + $('#json').val() );
         mouseState = "up";  
 }  
71    
72  var checker;          var cookie_id = getCookie(cookie+'_id') || 0;
73  var checkInterval = .2;  
74  var preloadDistance = 1000;          $.log.debug("Page ID:" + v.id);
75  var isUpdating = false;          $.log.debug("Page Cookie:" + cookie_id);
 var mouseState = "up";  
 var id;  
76    
 function init( ){  
         document.onmousedown = onMouseDown;  
         document.onmouseup   = onMouseUp;  
   
         //createLoggingPane(true);  
         id = $("page_id").value;  
         logDebug("Page ID:", id);  
         logDebug("Page Cookie:", getCookie(id));  
           
77          var fromBackButton = false;          var fromBackButton = false;
78          if( getCookie(id) ){ fromBackButton = true; }          if ( cookie_id == v.id ) {
79          else{ setCookie(id, "1") }                  fromBackButton = true;
80            } else {
81                    setCookie(cookie+'_id', v.id);
82            }
83    
84          logDebug("From Back Button?:", fromBackButton);          $.log.debug("from Back button? " + fromBackButton);
85          if( fromBackButton ){          if ( fromBackButton ) {
86                  logDebug( "Number of segments loaded: ", getCookie(id) );                  $.log.info( 'Load ' + getCookie(cookie+'_page') + ' pages');
87                  logDebug( "Should scroll to: ", getCookie(id+"_scroll") );                  $.log.debug( 'Scroll to:' + getCookie(cookie+'_scroll') );
88                  $("spacer").style.height=getCookie(id+"_height")+"px";                  $('#spacer').height( getCookie(cookie+'_height')+"px" );
89                  scroll( 0, getCookie(id+"_scroll") );                                    scroll( 0, getCookie(cookie+'_scroll') );
90          }          }
91    
92          getElement("history_index").value = 0;          $(window).mousedown( function () {
93          checker = callLater(0, updatePage);                  isMouseDown = true;
94  }          });
95            $(window).mouseup( function () {
96                    isMouseDown = false;
97            });
98    
99            checker = setInterval(function () {
100                    load_page();
101            }, 100);
102    
103    
104  addLoadEvent(init);  });
105    

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

  ViewVC Help
Powered by ViewVC 1.1.26