]>
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 | ||
1cd17194 | 61 | |
525116d4 | 62 | function refetch_callback() { |
c0e5a40e | 63 | |
525116d4 | 64 | if (xmlhttp_rpc.readyState == 4) { |
13c280e7 | 65 | |
310da49d AD |
66 | var actfeedid = frames["feeds-frame"].document.getElementById("ACTFEEDID"); |
67 | ||
68 | if (actfeedid) { | |
69 | active_feed_id = actfeedid.innerHTML; | |
70 | } | |
71 | ||
1a66d16e | 72 | document.title = "Tiny Tiny RSS"; |
310da49d AD |
73 | notify("All feeds updated."); |
74 | ||
1a66d16e | 75 | updateFeedList(); |
13c280e7 | 76 | |
c0e5a40e | 77 | } |
525116d4 AD |
78 | } |
79 | ||
1a66d16e | 80 | |
caa4e57f AD |
81 | function updateFeed(feed_id) { |
82 | ||
83 | var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id; | |
84 | ||
85 | if (xmlhttp_ready(xmlhttp_rpc)) { | |
86 | xmlhttp_rpc.open("GET", query_str, true); | |
87 | xmlhttp_rpc.onreadystatechange=feed_update_callback; | |
88 | xmlhttp_rpc.send(null); | |
89 | } else { | |
90 | printLockingError(); | |
91 | } | |
92 | ||
93 | } | |
94 | ||
cb246176 | 95 | function scheduleFeedUpdate(force) { |
525116d4 AD |
96 | |
97 | notify("Updating feeds in background..."); | |
98 | ||
55193822 AD |
99 | document.title = "Tiny Tiny RSS - Updating..."; |
100 | ||
cb246176 AD |
101 | var query_str = "backend.php?op=rpc&subop="; |
102 | ||
103 | if (force) { | |
c3b81db0 | 104 | query_str = query_str + "forceUpdateAllFeeds"; |
cb246176 | 105 | } else { |
c3b81db0 | 106 | query_str = query_str + "updateAllFeeds"; |
cb246176 | 107 | } |
525116d4 | 108 | |
c0e5a40e | 109 | if (xmlhttp_ready(xmlhttp_rpc)) { |
525116d4 AD |
110 | xmlhttp_rpc.open("GET", query_str, true); |
111 | xmlhttp_rpc.onreadystatechange=refetch_callback; | |
112 | xmlhttp_rpc.send(null); | |
113 | } else { | |
114 | printLockingError(); | |
c0e5a40e | 115 | } |
525116d4 | 116 | } |
1cd17194 | 117 | |
525116d4 | 118 | function updateFeedList(silent, fetch) { |
c0e5a40e | 119 | |
1a66d16e AD |
120 | // if (silent != true) { |
121 | // notify("Loading feed list..."); | |
122 | // } | |
82baad4a | 123 | |
331900c6 AD |
124 | var query_str = "backend.php?op=feeds"; |
125 | ||
1a66d16e AD |
126 | if (active_feed_id) { |
127 | query_str = query_str + "&actid=" + active_feed_id; | |
175847de AD |
128 | } |
129 | ||
1a66d16e | 130 | if (fetch) query_str = query_str + "&fetch=yes"; |
e1123aee | 131 | |
1a66d16e | 132 | var feeds_frame = document.getElementById("feeds-frame"); |
e1123aee | 133 | |
1a66d16e AD |
134 | feeds_frame.src = query_str; |
135 | } | |
175847de | 136 | |
476cac42 | 137 | function catchupAllFeeds() { |
076682aa | 138 | |
476cac42 AD |
139 | var query_str = "backend.php?op=feeds&subop=catchupAll"; |
140 | ||
141 | notify("Marking all feeds as read..."); | |
142 | ||
1a66d16e AD |
143 | var feeds_frame = document.getElementById("feeds-frame"); |
144 | ||
145 | feeds_frame.src = query_str; | |
476cac42 AD |
146 | |
147 | } | |
1cd17194 | 148 | |
f0601b87 | 149 | function viewCurrentFeed(skip, subop) { |
1a66d16e AD |
150 | |
151 | active_feed_id = frames["feeds-frame"].document.getElementById("ACTFEEDID").innerHTML; | |
152 | ||
153 | if (active_feed_id) { | |
f0601b87 AD |
154 | viewfeed(active_feed_id, skip, subop); |
155 | } | |
156 | } | |
157 | ||
476cac42 | 158 | function viewfeed(feed, skip, subop) { |
1cd17194 | 159 | |
90e395dc | 160 | // notify("Loading headlines..."); |
c05608c2 | 161 | |
36bf7496 AD |
162 | enableHotkeys(); |
163 | ||
c374a3fe AD |
164 | var searchbox = document.getElementById("searchbox"); |
165 | ||
166 | if (searchbox) { | |
167 | search_query = searchbox.value; | |
168 | } else { | |
169 | search_query = ""; | |
170 | } | |
171 | ||
f175937c AD |
172 | var viewbox = document.getElementById("viewbox"); |
173 | ||
174 | var view_mode; | |
175 | ||
176 | if (viewbox) { | |
177 | view_mode = viewbox.value; | |
178 | } else { | |
179 | view_mode = "All Posts"; | |
180 | } | |
181 | ||
ac43eba1 AD |
182 | setCookie("ttrss_vf_vmode", view_mode); |
183 | ||
cb1083a1 AD |
184 | var limitbox = document.getElementById("limitbox"); |
185 | ||
186 | var limit; | |
187 | ||
188 | if (limitbox) { | |
189 | limit = limitbox.value; | |
ac43eba1 | 190 | setCookie("ttrss_vf_limit", limit); |
cb1083a1 AD |
191 | } else { |
192 | limit = "All"; | |
193 | } | |
194 | ||
9cfc649a | 195 | active_feed_id = feed; |
1a66d16e AD |
196 | |
197 | var f_doc = frames["feeds-frame"].document; | |
198 | ||
199 | f_doc.getElementById("ACTFEEDID").innerHTML = feed; | |
076682aa | 200 | |
ac43eba1 AD |
201 | setCookie("ttrss_vf_actfeed", feed); |
202 | ||
f0601b87 AD |
203 | if (subop == "MarkAllRead") { |
204 | ||
1a66d16e AD |
205 | var feedr = f_doc.getElementById("FEEDR-" + feed); |
206 | var feedt = f_doc.getElementById("FEEDT-" + feed); | |
207 | var feedu = f_doc.getElementById("FEEDU-" + feed); | |
208 | ||
f0601b87 AD |
209 | feedu.innerHTML = "0"; |
210 | ||
211 | if (feedr.className.match("Unread")) { | |
212 | feedr.className = feedr.className.replace("Unread", ""); | |
213 | } | |
214 | } | |
215 | ||
c374a3fe | 216 | var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) + |
f175937c | 217 | "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) + |
cb1083a1 | 218 | "&view=" + param_escape(view_mode) + "&limit=" + limit; |
c374a3fe AD |
219 | |
220 | if (search_query != "") { | |
221 | query = query + "&search=" + param_escape(search_query); | |
222 | } | |
223 | ||
1a66d16e AD |
224 | var headlines_frame = parent.frames["headlines-frame"]; |
225 | ||
226 | headlines_frame.location.href = query + "&addheader=true"; | |
caa4e57f | 227 | |
f0601b87 | 228 | cleanSelected("feedsList"); |
13c280e7 AD |
229 | var feedr = document.getElementById("FEEDR-" + feed); |
230 | if (feedr) { | |
231 | feedr.className = feedr.className + "Selected"; | |
232 | } | |
f0601b87 | 233 | |
1a66d16e | 234 | disableContainerChildren("headlinesToolbar", false, doc); |
ac43eba1 | 235 | |
c05608c2 | 236 | // notify(""); |
9cfc649a AD |
237 | |
238 | } | |
239 | ||
1a66d16e | 240 | |
40d13c28 | 241 | function timeout() { |
cb246176 | 242 | scheduleFeedUpdate(true); |
ac53063a | 243 | setTimeout("timeout()", 1800*1000); |
ac53063a AD |
244 | } |
245 | ||
c374a3fe | 246 | function resetSearch() { |
64c620ce AD |
247 | var searchbox = document.getElementById("searchbox") |
248 | ||
249 | if (searchbox.value != "" && active_feed_id) { | |
250 | searchbox.value = ""; | |
ac43eba1 AD |
251 | viewfeed(active_feed_id, 0, ""); |
252 | } | |
c374a3fe | 253 | } |
ac53063a | 254 | |
f0601b87 AD |
255 | function search() { |
256 | if (active_feed_id) { | |
257 | viewfeed(active_feed_id, 0, ""); | |
258 | } else { | |
259 | notify("Please select some feed first."); | |
260 | } | |
76798ff3 | 261 | } |
1cd17194 | 262 | |
13ad9102 AD |
263 | function localPiggieFunction(enable) { |
264 | if (enable) { | |
265 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
266 | ||
c0e5a40e | 267 | if (xmlhttp_ready(xmlhttp)) { |
13ad9102 AD |
268 | |
269 | xmlhttp.open("GET", query_str, true); | |
270 | xmlhttp.onreadystatechange=feedlist_callback; | |
271 | xmlhttp.send(null); | |
272 | } | |
273 | } | |
274 | } | |
275 | ||
9cfc649a AD |
276 | function localHotkeyHandler(keycode) { |
277 | ||
f0601b87 | 278 | /* if (keycode == 78) { |
c3a8d71a | 279 | return moveToPost('next'); |
9cfc649a AD |
280 | } |
281 | ||
282 | if (keycode == 80) { | |
c3a8d71a | 283 | return moveToPost('prev'); |
f0601b87 | 284 | } */ |
c3a8d71a AD |
285 | |
286 | if (keycode == 82) { | |
287 | return scheduleFeedUpdate(true); | |
288 | } | |
289 | ||
290 | if (keycode == 85) { | |
291 | return viewfeed(active_feed_id, active_offset, "ForceUpdate"); | |
292 | } | |
293 | ||
294 | // notify("KC: " + keycode); | |
295 | ||
9cfc649a AD |
296 | } |
297 | ||
76798ff3 | 298 | function init() { |
c0e5a40e | 299 | |
ac43eba1 AD |
300 | disableContainerChildren("headlinesToolbar", true); |
301 | ||
c0e5a40e AD |
302 | // IE kludge |
303 | ||
304 | if (xmlhttp && !xmlhttp_rpc) { | |
305 | xmlhttp_rpc = xmlhttp; | |
306 | xmlhttp_view = xmlhttp; | |
307 | } | |
308 | ||
309 | if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) { | |
c3a8d71a AD |
310 | document.getElementById("headlines").innerHTML = |
311 | "<b>Fatal error:</b> This program needs XmlHttpRequest " + | |
312 | "to function properly. Your browser doesn't seem to support it."; | |
313 | return; | |
314 | } | |
315 | ||
476cac42 | 316 | updateFeedList(false, false); |
13ad9102 | 317 | document.onkeydown = hotkey_handler; |
ac53063a | 318 | setTimeout("timeout()", 1800*1000); |
70830c87 | 319 | |
1a66d16e AD |
320 | scheduleFeedUpdate(true); |
321 | ||
70830c87 | 322 | var content = document.getElementById("content"); |
ac43eba1 | 323 | |
ac43eba1 AD |
324 | if (getCookie("ttrss_vf_vmode")) { |
325 | var viewbox = document.getElementById("viewbox"); | |
326 | viewbox.value = getCookie("ttrss_vf_vmode"); | |
327 | } | |
47179952 | 328 | |
a8d28f48 AD |
329 | if (getCookie("ttrss_vf_limit")) { |
330 | var limitbox = document.getElementById("limitbox"); | |
331 | limitbox.value = getCookie("ttrss_vf_limit"); | |
332 | } | |
1cd17194 | 333 | } |
ac43eba1 AD |
334 | |
335 |