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}) |
|
|
|
|
|
} |
|
8 |
|
|
9 |
function getMoreHistory(){ |
var preloadDistance = 1000; |
10 |
var indexVal = getElement("history_index").value; |
var isUpdating = false; |
11 |
var q = getElement('q').value; |
var id; |
12 |
getElement('status').innerHTML = 'Loading page '+ ( parseInt(indexVal) + 1 ) + '...'; |
var checker; |
|
var xmlDoc = doSimpleXMLHttpRequest("index.cgi/snippet", {index: indexVal, q: q}); |
|
|
xmlDoc.addCallbacks(addMoreHistory, failure); |
|
|
} |
|
13 |
|
|
14 |
function failure(){ |
/* |
15 |
var message = P( null, "" ); |
function to log debugging information into debug div |
16 |
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"); |
|
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 addMoreHistory( xmlDoc ){ |
function log( m1, m2 ) { |
25 |
var response = xmlDoc.responseText; |
var m = m1; |
26 |
|
if (m2) m += m2; |
27 |
|
m += '</br>' |
28 |
|
if (m) $('#debug').append( m ); |
29 |
|
} |
30 |
|
|
31 |
var index_el = getElement("history_index"); |
function load_page() { |
32 |
var indexVal = parseInt(index_el.value); |
setCookie(id+"_height", getScrollHeight() ); |
33 |
|
setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() ); |
34 |
|
|
35 |
// minimum response length? |
if ( isUpdating == true |
36 |
if (response.length < 500){ |
|| getPageHeight() - getScrollHeight() > preloadDistance |
37 |
|
) return; |
38 |
showElement("footer") |
|
39 |
if( indexVal > 0 ){ |
var history_index = parseInt( $('#history_index').val() ); |
40 |
var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'}, |
var q = $('#q').val(); |
41 |
"No more results." |
|
42 |
); |
if (! q || q == '') return; |
43 |
}else{ |
|
44 |
var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'}, |
log("Getting segment: " + history_index + " for: "+q); |
45 |
"No results matched your search." |
|
46 |
); |
setCookie( id, history_index ); |
47 |
} |
isUpdating = true; |
48 |
replaceChildNodes( "more_history", out ) |
|
49 |
getElement("status").innerHTML = ''; |
$('#status').html( |
50 |
return; |
'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 |
|
|
|
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; |
|
|
|
|
|
var status_update = getElement("status_update"); |
|
|
var status = getElement("status"); |
|
|
if (status_update && status) { |
|
|
status.innerHTML = status_update.innerHTML; |
|
|
log("status updated"); |
|
|
} |
|
83 |
|
|
84 |
} |
} |
85 |
|
|
86 |
function updatePage(){ |
/* |
87 |
if ( isUpdating == false |
bind events and init no_pager |
88 |
&& 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); |
|
|
} |
|
89 |
|
|
90 |
|
$(document).ready( function() { |
91 |
|
|
92 |
function onMouseDown(e ){ |
logDebug( 'no_page binding events' ); |
|
mouseState = "down"; |
|
|
setCookie(id+"_height", getScrollHeight() ); |
|
|
setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() ); |
|
|
} |
|
93 |
|
|
94 |
function onMouseUp(){ |
checker = setInterval(function () { |
95 |
mouseState = "up"; |
load_page(); |
96 |
} |
}, 100); |
97 |
|
|
98 |
var checker; |
id = $('#page_id').val(); |
|
var checkInterval = .2; |
|
|
var preloadDistance = 1000; |
|
|
var isUpdating = false; |
|
|
var mouseState = "up"; |
|
|
var id; |
|
|
|
|
|
function init( ){ |
|
|
document.onmousedown = onMouseDown; |
|
|
document.onmouseup = onMouseUp; |
|
|
|
|
|
//createLoggingPane(true); |
|
|
id = $("page_id").value; |
|
99 |
logDebug("Page ID:", id); |
logDebug("Page ID:", id); |
100 |
logDebug("Page Cookie:", getCookie(id)); |
logDebug("Page Cookie:", getCookie(id)); |
101 |
|
|
102 |
var fromBackButton = false; |
var fromBackButton = false; |
103 |
if( getCookie(id) ){ fromBackButton = true; } |
if ( getCookie(id) ) { |
104 |
else{ setCookie(id, "1") } |
fromBackButton = true; |
105 |
|
} else { |
106 |
|
setCookie(id, "1"); |
107 |
|
} |
108 |
|
|
109 |
logDebug("From Back Button?:", fromBackButton); |
logDebug("From Back Button?:", fromBackButton); |
110 |
if( fromBackButton ){ |
if( fromBackButton ){ |
111 |
logDebug( "Number of segments loaded: ", getCookie(id) ); |
logDebug( "Number of segments loaded: ", getCookie(id) ); |
112 |
logDebug( "Should scroll to: ", getCookie(id+"_scroll") ); |
logDebug( "Should scroll to: ", getCookie(id+"_scroll") ); |
113 |
$("spacer").style.height=getCookie(id+"_height")+"px"; |
$('#spacer').height( getCookie(id+"_height")+"px" ); |
114 |
scroll( 0, getCookie(id+"_scroll") ); |
scroll( 0, getCookie(id+"_scroll") ); |
115 |
} |
} |
116 |
|
|
117 |
getElement("history_index").value = 0; |
$('#history_index').val( 0 ); |
118 |
checker = callLater(0, updatePage); |
load_page(); |
119 |
} |
}); |
|
|
|
|
addLoadEvent(init); |
|
120 |
|
|