1 |
/* |
2 |
no pager, as seen at |
3 |
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 |
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 |
} |
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 load_page() { |
32 |
setCookie(id+"_height", getScrollHeight() ); |
33 |
setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() ); |
34 |
|
35 |
if ( isUpdating == true |
36 |
|| 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 |
|
83 |
|
84 |
} |
85 |
|
86 |
/* |
87 |
bind events and init no_pager |
88 |
*/ |
89 |
|
90 |
$(document).ready( function() { |
91 |
|
92 |
logDebug( 'no_page binding events' ); |
93 |
|
94 |
checker = setInterval(function () { |
95 |
load_page(); |
96 |
}, 100); |
97 |
|
98 |
id = $('#page_id').val(); |
99 |
logDebug("Page ID:", id); |
100 |
logDebug("Page Cookie:", getCookie(id)); |
101 |
|
102 |
var fromBackButton = false; |
103 |
if ( getCookie(id) ) { |
104 |
fromBackButton = true; |
105 |
} else { |
106 |
setCookie(id, "1"); |
107 |
} |
108 |
|
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 |
$('#spacer').height( getCookie(id+"_height")+"px" ); |
114 |
scroll( 0, getCookie(id+"_scroll") ); |
115 |
} |
116 |
|
117 |
$('#history_index').val( 0 ); |
118 |
load_page(); |
119 |
}); |
120 |
|