1 |
dpavlin |
2 |
/* |
2 |
|
|
no pager, as seen at |
3 |
|
|
http://www.humanized.com/weblog/2006/04/28/reading_humanized/ |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
function favorite( image, feedID ){ |
7 |
|
|
var makeFavorite; |
8 |
|
|
if (image.src.indexOf("fav_off.gif") != -1){ |
9 |
|
|
image.src = "static/images/fav_on.gif"; |
10 |
|
|
makeFavorite = "True"; |
11 |
|
|
} |
12 |
|
|
else if (image.src.indexOf("fav_on.gif") != -1){ |
13 |
|
|
image.src = "static/images/fav_off.gif"; |
14 |
|
|
makeFavorite = "False"; |
15 |
|
|
} |
16 |
|
|
doSimpleXMLHttpRequest("favorite", {id: feedID, makeFavorite: makeFavorite}) |
17 |
|
|
|
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
function getMoreHistory(){ |
21 |
|
|
var indexVal = getElement("history_index").value; |
22 |
dpavlin |
9 |
var q = getElement('q').value; |
23 |
|
|
getElement('status').innerHTML = 'Loading page '+ ( parseInt(indexVal) + 1 ) + '...'; |
24 |
|
|
var xmlDoc = doSimpleXMLHttpRequest("index.cgi/snippet", {index: indexVal, q: q}); |
25 |
dpavlin |
2 |
xmlDoc.addCallbacks(addMoreHistory, failure); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
function failure(){ |
29 |
|
|
var message = P( null, "" ); |
30 |
|
|
message.innerHTML = "<strong>Could not contact the Humanized server.</strong> <br />"; |
31 |
|
|
message.innerHTML += "Please wait awhile and try again. <br /><br />"; |
32 |
|
|
message.innerHTML += "We apologize for the inconvenience."; |
33 |
|
|
var el = getElement("more_history"); |
34 |
|
|
|
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
function addMoreHistory( xmlDoc ){ |
38 |
|
|
var response = xmlDoc.responseText; |
39 |
|
|
|
40 |
|
|
var index_el = getElement("history_index"); |
41 |
|
|
var indexVal = parseInt(index_el.value); |
42 |
|
|
|
43 |
|
|
// minimum response length? |
44 |
|
|
if (response.length < 300){ |
45 |
|
|
|
46 |
|
|
showElement("footer") |
47 |
|
|
if( indexVal > 0 ){ |
48 |
|
|
var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'}, |
49 |
|
|
"No more results." |
50 |
|
|
); |
51 |
|
|
}else{ |
52 |
|
|
var out = H2({'style':'text-align:center; font-style:italic; padding: 2em;'}, |
53 |
|
|
"No posts matched your search." |
54 |
|
|
); |
55 |
|
|
} |
56 |
|
|
replaceChildNodes( "more_history", out ) |
57 |
|
|
return; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
response += "<div id='more_history'>"; |
61 |
|
|
response += " <strong>More posts are being loaded...</strong> <br />"; |
62 |
|
|
response += " If you are using the scroll bar, release the mouse to see more posts."; |
63 |
|
|
response += "</div>" |
64 |
|
|
|
65 |
|
|
index_el.value = indexVal + 1; |
66 |
|
|
|
67 |
|
|
var new_history = DIV(null,""); |
68 |
|
|
new_history.innerHTML = response; |
69 |
|
|
swapDOM( "more_history", new_history ); |
70 |
|
|
|
71 |
|
|
isUpdating = false; |
72 |
dpavlin |
9 |
|
73 |
|
|
var status_update = getElement("status_update"); |
74 |
|
|
var status = getElement("status"); |
75 |
|
|
if (status_update && status) { |
76 |
|
|
status.innerHTML = status_update.innerHTML; |
77 |
|
|
log("status updated"); |
78 |
|
|
} |
79 |
|
|
|
80 |
dpavlin |
2 |
} |
81 |
|
|
|
82 |
|
|
function updatePage(){ |
83 |
|
|
if ( isUpdating == false |
84 |
dpavlin |
7 |
&& mouseState == "up" |
85 |
|
|
&& getPageHeight() - getScrollHeight() < preloadDistance){ |
86 |
|
|
log("Getting segment: ", $("history_index").value); |
87 |
|
|
setCookie(id, $("history_index").value ); |
88 |
|
|
isUpdating = true; |
89 |
dpavlin |
2 |
getMoreHistory(); |
90 |
|
|
} |
91 |
|
|
checker.cancel(); |
92 |
|
|
checker = callLater(checkInterval, updatePage); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
function onMouseDown(e ){ |
97 |
|
|
mouseState = "down"; |
98 |
|
|
setCookie(id+"_height", getScrollHeight() ); |
99 |
|
|
setCookie(id+"_scroll", getScrollHeight() - _getWindowHeight() ); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
function onMouseUp(){ |
103 |
|
|
mouseState = "up"; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
var checker; |
107 |
|
|
var checkInterval = .2; |
108 |
|
|
var preloadDistance = 1000; |
109 |
|
|
var isUpdating = false; |
110 |
|
|
var mouseState = "up"; |
111 |
|
|
var id; |
112 |
|
|
|
113 |
|
|
function init( ){ |
114 |
|
|
document.onmousedown = onMouseDown; |
115 |
|
|
document.onmouseup = onMouseUp; |
116 |
|
|
|
117 |
|
|
//createLoggingPane(true); |
118 |
|
|
id = $("page_id").value; |
119 |
|
|
logDebug("Page ID:", id); |
120 |
|
|
logDebug("Page Cookie:", getCookie(id)); |
121 |
|
|
|
122 |
|
|
var fromBackButton = false; |
123 |
|
|
if( getCookie(id) ){ fromBackButton = true; } |
124 |
|
|
else{ setCookie(id, "1") } |
125 |
|
|
|
126 |
|
|
logDebug("From Back Button?:", fromBackButton); |
127 |
|
|
if( fromBackButton ){ |
128 |
|
|
logDebug( "Number of segments loaded: ", getCookie(id) ); |
129 |
|
|
logDebug( "Should scroll to: ", getCookie(id+"_scroll") ); |
130 |
|
|
$("spacer").style.height=getCookie(id+"_height")+"px"; |
131 |
|
|
scroll( 0, getCookie(id+"_scroll") ); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
getElement("history_index").value = 0; |
135 |
|
|
checker = callLater(0, updatePage); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
addLoadEvent(init); |
139 |
|
|
|