]>
Commit | Line | Data |
---|---|---|
1cd17194 AD |
1 | /* |
2 | This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com> | |
3 | Licensed under GPL v.2 or (at your preference) any later version. | |
4 | */ | |
5 | ||
6 | var xmlhttp = false; | |
525116d4 | 7 | var xmlhttp_rpc = false; |
c3a8d71a | 8 | var xmlhttp_view = false; |
1cd17194 | 9 | |
76798ff3 | 10 | var total_unread = 0; |
525116d4 | 11 | var first_run = true; |
76798ff3 | 12 | |
9cfc649a | 13 | var active_feed_id = false; |
c3a8d71a | 14 | |
c374a3fe AD |
15 | var search_query = ""; |
16 | ||
1cd17194 AD |
17 | /*@cc_on @*/ |
18 | /*@if (@_jscript_version >= 5) | |
19 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
20 | // and security blocked creation of the objects. | |
21 | try { | |
22 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
23 | } catch (e) { | |
24 | try { | |
25 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
508a81e1 | 26 | xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); |
c3a8d71a | 27 | xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP"); |
1cd17194 AD |
28 | } catch (E) { |
29 | xmlhttp = false; | |
508a81e1 | 30 | xmlhttp_rpc = false; |
c3a8d71a | 31 | xmlhttp_view = false; |
1cd17194 AD |
32 | } |
33 | } | |
34 | @end @*/ | |
35 | ||
36 | if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
37 | xmlhttp = new XMLHttpRequest(); | |
525116d4 | 38 | xmlhttp_rpc = new XMLHttpRequest(); |
c3a8d71a | 39 | xmlhttp_view = new XMLHttpRequest(); |
1cd17194 AD |
40 | } |
41 | ||
1a66d16e | 42 | /* |
1cd17194 | 43 | function feedlist_callback() { |
d76a3b03 | 44 | var container = document.getElementById('feeds'); |
1cd17194 | 45 | if (xmlhttp.readyState == 4) { |
d76a3b03 | 46 | container.innerHTML=xmlhttp.responseText; |
76798ff3 | 47 | |
525116d4 | 48 | if (first_run) { |
cb246176 | 49 | scheduleFeedUpdate(false); |
13c280e7 AD |
50 | if (getCookie("ttrss_vf_actfeed")) { |
51 | viewfeed(getCookie("ttrss_vf_actfeed"), 0, ""); | |
52 | } | |
525116d4 AD |
53 | first_run = false; |
54 | } else { | |
55 | notify(""); | |
c0e5a40e AD |
56 | } |
57 | } | |
1cd17194 | 58 | } |
1a66d16e AD |
59 | */ |
60 | ||
8158c57a | 61 | function checkActiveFeedId() { |
1cd17194 | 62 | |
8158c57a | 63 | var actfeedid = frames["feeds-frame"].document.getElementById("ACTFEEDID"); |
c0e5a40e | 64 | |
8158c57a AD |
65 | if (actfeedid) { |
66 | active_feed_id = actfeedid.innerHTML; | |
67 | } | |
68 | } | |
13c280e7 | 69 | |
8158c57a | 70 | function refetch_callback() { |
310da49d | 71 | |
8158c57a | 72 | if (xmlhttp_rpc.readyState == 4) { |
310da49d | 73 | |
1a66d16e | 74 | document.title = "Tiny Tiny RSS"; |
310da49d AD |
75 | notify("All feeds updated."); |
76 | ||
1a66d16e | 77 | updateFeedList(); |
13c280e7 | 78 | |
c0e5a40e | 79 | } |
525116d4 AD |
80 | } |
81 | ||
1a66d16e | 82 | |
caa4e57f AD |
83 | function updateFeed(feed_id) { |
84 | ||
85 | var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id; | |
86 | ||
87 | if (xmlhttp_ready(xmlhttp_rpc)) { | |
88 | xmlhttp_rpc.open("GET", query_str, true); | |
89 | xmlhttp_rpc.onreadystatechange=feed_update_callback; | |
90 | xmlhttp_rpc.send(null); | |
91 | } else { | |
92 | printLockingError(); | |
93 | } | |
94 | ||
95 | } | |
96 | ||
cb246176 | 97 | function scheduleFeedUpdate(force) { |
525116d4 AD |
98 | |
99 | notify("Updating feeds in background..."); | |
100 | ||
55193822 AD |
101 | document.title = "Tiny Tiny RSS - Updating..."; |
102 | ||
cb246176 AD |
103 | var query_str = "backend.php?op=rpc&subop="; |
104 | ||
105 | if (force) { | |
c3b81db0 | 106 | query_str = query_str + "forceUpdateAllFeeds"; |
cb246176 | 107 | } else { |
c3b81db0 | 108 | query_str = query_str + "updateAllFeeds"; |
cb246176 | 109 | } |
525116d4 | 110 | |
c0e5a40e | 111 | if (xmlhttp_ready(xmlhttp_rpc)) { |
525116d4 AD |
112 | xmlhttp_rpc.open("GET", query_str, true); |
113 | xmlhttp_rpc.onreadystatechange=refetch_callback; | |
114 | xmlhttp_rpc.send(null); | |
115 | } else { | |
116 | printLockingError(); | |
c0e5a40e | 117 | } |
525116d4 | 118 | } |
1cd17194 | 119 | |
525116d4 | 120 | function updateFeedList(silent, fetch) { |
c0e5a40e | 121 | |
1a66d16e AD |
122 | // if (silent != true) { |
123 | // notify("Loading feed list..."); | |
124 | // } | |
82baad4a | 125 | |
331900c6 AD |
126 | var query_str = "backend.php?op=feeds"; |
127 | ||
1a66d16e AD |
128 | if (active_feed_id) { |
129 | query_str = query_str + "&actid=" + active_feed_id; | |
175847de AD |
130 | } |
131 | ||
1a66d16e | 132 | if (fetch) query_str = query_str + "&fetch=yes"; |
e1123aee | 133 | |
1a66d16e | 134 | var feeds_frame = document.getElementById("feeds-frame"); |
e1123aee | 135 | |
1a66d16e AD |
136 | feeds_frame.src = query_str; |
137 | } | |
175847de | 138 | |
476cac42 | 139 | function catchupAllFeeds() { |
076682aa | 140 | |
476cac42 AD |
141 | var query_str = "backend.php?op=feeds&subop=catchupAll"; |
142 | ||
143 | notify("Marking all feeds as read..."); | |
144 | ||
1a66d16e AD |
145 | var feeds_frame = document.getElementById("feeds-frame"); |
146 | ||
147 | feeds_frame.src = query_str; | |
476cac42 AD |
148 | |
149 | } | |
1cd17194 | 150 | |
f0601b87 | 151 | function viewCurrentFeed(skip, subop) { |
1a66d16e AD |
152 | |
153 | active_feed_id = frames["feeds-frame"].document.getElementById("ACTFEEDID").innerHTML; | |
154 | ||
155 | if (active_feed_id) { | |
f0601b87 AD |
156 | viewfeed(active_feed_id, skip, subop); |
157 | } | |
158 | } | |
159 | ||
476cac42 | 160 | function viewfeed(feed, skip, subop) { |
1cd17194 | 161 | |
caa486f8 | 162 | // notify("Loading headlines..."); |
c05608c2 | 163 | |
36bf7496 AD |
164 | enableHotkeys(); |
165 | ||
c374a3fe AD |
166 | var searchbox = document.getElementById("searchbox"); |
167 | ||
168 | if (searchbox) { | |
169 | search_query = searchbox.value; | |
170 | } else { | |
171 | search_query = ""; | |
172 | } | |
173 | ||
f175937c AD |
174 | var viewbox = document.getElementById("viewbox"); |
175 | ||
176 | var view_mode; | |
177 | ||
178 | if (viewbox) { | |
179 | view_mode = viewbox.value; | |
180 | } else { | |
181 | view_mode = "All Posts"; | |
182 | } | |
183 | ||
ac43eba1 AD |
184 | setCookie("ttrss_vf_vmode", view_mode); |
185 | ||
cb1083a1 AD |
186 | var limitbox = document.getElementById("limitbox"); |
187 | ||
188 | var limit; | |
189 | ||
190 | if (limitbox) { | |
191 | limit = limitbox.value; | |
ac43eba1 | 192 | setCookie("ttrss_vf_limit", limit); |
cb1083a1 AD |
193 | } else { |
194 | limit = "All"; | |
195 | } | |
196 | ||
9cfc649a | 197 | active_feed_id = feed; |
1a66d16e AD |
198 | |
199 | var f_doc = frames["feeds-frame"].document; | |
200 | ||
201 | f_doc.getElementById("ACTFEEDID").innerHTML = feed; | |
076682aa | 202 | |
ac43eba1 | 203 | setCookie("ttrss_vf_actfeed", feed); |
caa486f8 | 204 | |
f0601b87 AD |
205 | if (subop == "MarkAllRead") { |
206 | ||
1a66d16e | 207 | var feedr = f_doc.getElementById("FEEDR-" + feed); |
deaaa02c | 208 | var feedctr = f_doc.getElementById("FEEDCTR-" + feed); |
1a66d16e | 209 | |
deaaa02c | 210 | feedctr.className = "invisible"; |
f0601b87 AD |
211 | |
212 | if (feedr.className.match("Unread")) { | |
213 | feedr.className = feedr.className.replace("Unread", ""); | |
214 | } | |
215 | } | |
216 | ||
c374a3fe | 217 | var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) + |
f175937c | 218 | "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) + |
cb1083a1 | 219 | "&view=" + param_escape(view_mode) + "&limit=" + limit; |
c374a3fe AD |
220 | |
221 | if (search_query != "") { | |
222 | query = query + "&search=" + param_escape(search_query); | |
223 | } | |
224 | ||
1a66d16e AD |
225 | var headlines_frame = parent.frames["headlines-frame"]; |
226 | ||
227 | headlines_frame.location.href = query + "&addheader=true"; | |
caa4e57f | 228 | |
f0601b87 | 229 | cleanSelected("feedsList"); |
13c280e7 AD |
230 | var feedr = document.getElementById("FEEDR-" + feed); |
231 | if (feedr) { | |
232 | feedr.className = feedr.className + "Selected"; | |
233 | } | |
f0601b87 | 234 | |
1a66d16e | 235 | disableContainerChildren("headlinesToolbar", false, doc); |
ac43eba1 | 236 | |
c05608c2 | 237 | // notify(""); |
9cfc649a AD |
238 | |
239 | } | |
240 | ||
1a66d16e | 241 | |
40d13c28 | 242 | function timeout() { |
cb246176 | 243 | scheduleFeedUpdate(true); |
ac53063a | 244 | setTimeout("timeout()", 1800*1000); |
ac53063a AD |
245 | } |
246 | ||
c374a3fe | 247 | function resetSearch() { |
64c620ce AD |
248 | var searchbox = document.getElementById("searchbox") |
249 | ||
250 | if (searchbox.value != "" && active_feed_id) { | |
251 | searchbox.value = ""; | |
ac43eba1 AD |
252 | viewfeed(active_feed_id, 0, ""); |
253 | } | |
c374a3fe | 254 | } |
ac53063a | 255 | |
f0601b87 | 256 | function search() { |
8158c57a | 257 | checkActiveFeedId(); |
f0601b87 AD |
258 | if (active_feed_id) { |
259 | viewfeed(active_feed_id, 0, ""); | |
260 | } else { | |
261 | notify("Please select some feed first."); | |
262 | } | |
76798ff3 | 263 | } |
1cd17194 | 264 | |
13ad9102 AD |
265 | function localPiggieFunction(enable) { |
266 | if (enable) { | |
267 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
268 | ||
c0e5a40e | 269 | if (xmlhttp_ready(xmlhttp)) { |
13ad9102 AD |
270 | |
271 | xmlhttp.open("GET", query_str, true); | |
272 | xmlhttp.onreadystatechange=feedlist_callback; | |
273 | xmlhttp.send(null); | |
274 | } | |
275 | } | |
276 | } | |
277 | ||
9cfc649a AD |
278 | function localHotkeyHandler(keycode) { |
279 | ||
f0601b87 | 280 | /* if (keycode == 78) { |
c3a8d71a | 281 | return moveToPost('next'); |
9cfc649a AD |
282 | } |
283 | ||
284 | if (keycode == 80) { | |
c3a8d71a | 285 | return moveToPost('prev'); |
f0601b87 | 286 | } */ |
c3a8d71a AD |
287 | |
288 | if (keycode == 82) { | |
289 | return scheduleFeedUpdate(true); | |
290 | } | |
291 | ||
292 | if (keycode == 85) { | |
293 | return viewfeed(active_feed_id, active_offset, "ForceUpdate"); | |
294 | } | |
295 | ||
296 | // notify("KC: " + keycode); | |
297 | ||
9cfc649a AD |
298 | } |
299 | ||
76798ff3 | 300 | function init() { |
c0e5a40e | 301 | |
ac43eba1 AD |
302 | disableContainerChildren("headlinesToolbar", true); |
303 | ||
c0e5a40e AD |
304 | // IE kludge |
305 | ||
306 | if (xmlhttp && !xmlhttp_rpc) { | |
307 | xmlhttp_rpc = xmlhttp; | |
308 | xmlhttp_view = xmlhttp; | |
309 | } | |
310 | ||
311 | if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) { | |
c3a8d71a AD |
312 | document.getElementById("headlines").innerHTML = |
313 | "<b>Fatal error:</b> This program needs XmlHttpRequest " + | |
314 | "to function properly. Your browser doesn't seem to support it."; | |
315 | return; | |
316 | } | |
317 | ||
476cac42 | 318 | updateFeedList(false, false); |
13ad9102 | 319 | document.onkeydown = hotkey_handler; |
70830c87 | 320 | |
77a1bf8b AD |
321 | setTimeout("timeout()", 1800*1000); |
322 | scheduleFeedUpdate(true); | |
1a66d16e | 323 | |
70830c87 | 324 | var content = document.getElementById("content"); |
ac43eba1 | 325 | |
ac43eba1 AD |
326 | if (getCookie("ttrss_vf_vmode")) { |
327 | var viewbox = document.getElementById("viewbox"); | |
328 | viewbox.value = getCookie("ttrss_vf_vmode"); | |
329 | } | |
47179952 | 330 | |
a8d28f48 AD |
331 | if (getCookie("ttrss_vf_limit")) { |
332 | var limitbox = document.getElementById("limitbox"); | |
333 | limitbox.value = getCookie("ttrss_vf_limit"); | |
334 | } | |
1cd17194 | 335 | } |
ac43eba1 AD |
336 | |
337 |