/[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 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            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 isMouseDown = false;
12                  image.src = "static/images/fav_on.gif";  var checker;
13                  makeFavorite = "True";  var v;
14          }  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})  
           
 }  
15    
16  function getMoreHistory(){  function load_page() {
17          var indexVal = getElement("history_index").value;          setCookie(cookie+"_height", getScrollHeight() );
18          var xmlDoc = doSimpleXMLHttpRequest("index.cgi/snippet", {index: indexVal, q: document.getElementById('q').value });          setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() );
19          xmlDoc.addCallbacks(addMoreHistory, failure);  
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            setCookie( cookie+'_page', v.page );
36            isUpdating = true;
37    
38            $('#status').html(
39                    '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    
 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");  
59    
60  }  }
61    
62  function addMoreHistory( xmlDoc ){  /*
63          var response = xmlDoc.responseText;          bind events and init no_pager
64    */
         var index_el = getElement("history_index");  
         var indexVal = parseInt(index_el.value);  
   
 // 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;  
         }  
   
         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;  
 }  
65    
66  function updatePage(){  $(document).ready( function() {
         if ( isUpdating == false  
                         && 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);  
 }  
67    
68            $.log.info('no_page binding events');
69    
70  function onMouseDown(e ){          eval( 'v=' + $('#json').val() );
         mouseState = "down";  
         setCookie(id+"_height", getScrollHeight() );  
         setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );  
 }  
71    
72  function onMouseUp(){          var cookie_id = getCookie(cookie+'_id') || 0;
         mouseState = "up";  
 }  
73    
74  var checker;          $.log.debug("Page ID:" + v.id);
75  var checkInterval = .2;          $.log.debug("Page Cookie:" + cookie_id);
 var preloadDistance = 1000;  
 var isUpdating = false;  
 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.7  
changed lines
  Added in v.30

  ViewVC Help
Powered by ViewVC 1.1.26