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 |
|
|
|
|
function favorite( image, feedID ){ |
|
|
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); |
|
|
} |
|
5 |
|
|
6 |
function failure(){ |
2006-08-16 Dobrica Pavlinusic <dpavlin@rot13.org> |
7 |
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"); |
|
8 |
|
|
9 |
} |
var preloadDistance = 1000; |
10 |
|
var isUpdating = false; |
11 |
|
var checker; |
12 |
|
var v; |
13 |
|
var cookie = 'no_pager'; |
14 |
|
|
15 |
function addMoreHistory( xmlDoc ){ |
/* |
16 |
var response = xmlDoc.responseText; |
function to log debugging information into debug div |
17 |
|
*/ |
18 |
|
|
19 |
var index_el = getElement("history_index"); |
function logDebug( m1, m2 ) { |
20 |
var indexVal = parseInt(index_el.value); |
var m = m1; |
21 |
|
if (m2) m += m2; |
22 |
|
if (m) $('#debug').append( '<small>'+m+'</small><br/>' ); |
23 |
|
} |
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 load_page() { |
33 |
|
setCookie(cookie+"_height", getScrollHeight() ); |
34 |
|
setCookie(cookie+"_scroll", getScrollHeight() - _getWindowHeight() ); |
35 |
|
|
36 |
|
if ( isUpdating == true |
37 |
|
|| getPageHeight() - getScrollHeight() > preloadDistance |
38 |
|
|| v.page >= v.max_page |
39 |
|
) return; |
40 |
|
|
41 |
|
v.page++; |
42 |
|
|
43 |
|
log( |
44 |
|
'Get page:' + v.page + '<br/>search: ' + v.search + |
45 |
|
' PageHeight:' + getPageHeight() + ' ScrollHeight:' + getScrollHeight() |
46 |
|
); |
47 |
|
|
48 |
|
setCookie( cookie+'_page', v.page ); |
49 |
|
isUpdating = true; |
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 |
|
|
|
// 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; |
|
|
} |
|
87 |
|
|
|
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; |
|
88 |
} |
} |
89 |
|
|
90 |
function updatePage(){ |
/* |
91 |
if ( isUpdating == false |
bind events and init no_pager |
92 |
&& 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); |
|
|
} |
|
93 |
|
|
94 |
|
$(document).ready( function() { |
95 |
|
|
96 |
function onMouseDown(e ){ |
logDebug( 'no_page binding events' ); |
|
mouseState = "down"; |
|
|
setCookie(id+"_height", getScrollHeight() ); |
|
|
setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() ); |
|
|
} |
|
97 |
|
|
98 |
function onMouseUp(){ |
eval( 'v=' + $('#json').val() ); |
|
mouseState = "up"; |
|
|
} |
|
99 |
|
|
100 |
var checker; |
var cookie_id = getCookie(cookie+'_id') || 0; |
101 |
var checkInterval = .2; |
|
102 |
var preloadDistance = 1000; |
logDebug("Page ID:", v.id); |
103 |
var isUpdating = false; |
logDebug("Page Cookie:", cookie_id); |
|
var mouseState = "up"; |
|
|
var 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 |
|
|