/[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

Annotation of /no_pager/no_pager.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Wed Aug 16 14:20:18 2006 UTC (17 years, 8 months ago) by dpavlin
File MIME type: application/javascript
File size: 2724 byte(s)
big refactoring: use jquery istead of Mochikit
1 dpavlin 2 /*
2     no pager, as seen at
3     http://www.humanized.com/weblog/2006/04/28/reading_humanized/
4 dpavlin 11 but using jquery
5    
6     2006-08-16 Dobrica Pavlinusic <dpavlin@rot13.org>
7 dpavlin 2 */
8    
9 dpavlin 11 var preloadDistance = 1000;
10     var isUpdating = false;
11     var id;
12     var checker;
13    
14     /*
15     function to log debugging information into debug div
16     */
17    
18     function logDebug( m1, m2 ) {
19     var m = m1;
20     if (m2) m += m2;
21     if (m) $('#debug').append( '<small>'+m+'</small><br/>' );
22 dpavlin 2 }
23    
24 dpavlin 11 function log( m1, m2 ) {
25     var m = m1;
26     if (m2) m += m2;
27     m += '</br>'
28     if (m) $('#debug').append( m );
29 dpavlin 2 }
30    
31 dpavlin 11 function load_page() {
32     setCookie(id+"_height", getScrollHeight() );
33     setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() );
34 dpavlin 2
35 dpavlin 11 if ( isUpdating == true
36     || getPageHeight() - getScrollHeight() > preloadDistance
37     ) return;
38 dpavlin 2
39 dpavlin 11 var history_index = parseInt( $('#history_index').val() );
40     var q = $('#q').val();
41 dpavlin 2
42 dpavlin 11 if (! q || q == '') return;
43 dpavlin 2
44 dpavlin 11 log("Getting segment: " + history_index + " for: "+q);
45 dpavlin 2
46 dpavlin 11 setCookie( id, history_index );
47     isUpdating = true;
48 dpavlin 2
49 dpavlin 11 $('#status').html(
50     'Loading page '+ ( history_index + 1 ) + '...'
51     );
52 dpavlin 2
53 dpavlin 11 $.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 dpavlin 9
72 dpavlin 11 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 dpavlin 9
83 dpavlin 2
84     }
85    
86 dpavlin 11 /*
87     bind events and init no_pager
88     */
89 dpavlin 2
90 dpavlin 11 $(document).ready( function() {
91 dpavlin 2
92 dpavlin 11 logDebug( 'no_page binding events' );
93 dpavlin 2
94 dpavlin 11 checker = setInterval(function () {
95     load_page();
96     }, 100);
97 dpavlin 2
98 dpavlin 11 id = $('#page_id').val();
99 dpavlin 2 logDebug("Page ID:", id);
100     logDebug("Page Cookie:", getCookie(id));
101 dpavlin 11
102 dpavlin 2 var fromBackButton = false;
103 dpavlin 11 if ( getCookie(id) ) {
104     fromBackButton = true;
105     } else {
106     setCookie(id, "1");
107     }
108 dpavlin 2
109     logDebug("From Back Button?:", fromBackButton);
110     if( fromBackButton ){
111     logDebug( "Number of segments loaded: ", getCookie(id) );
112     logDebug( "Should scroll to: ", getCookie(id+"_scroll") );
113 dpavlin 11 $('#spacer').height( getCookie(id+"_height")+"px" );
114     scroll( 0, getCookie(id+"_scroll") );
115 dpavlin 2 }
116    
117 dpavlin 11 $('#history_index').val( 0 );
118     load_page();
119     });
120 dpavlin 2

  ViewVC Help
Powered by ViewVC 1.1.26