]>
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 | |
90e395dc | 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 AD |
203 | setCookie("ttrss_vf_actfeed", feed); |
204 | ||
f0601b87 AD |
205 | if (subop == "MarkAllRead") { |
206 | ||
1a66d16e AD |
207 | var feedr = f_doc.getElementById("FEEDR-" + feed); |
208 | var feedt = f_doc.getElementById("FEEDT-" + feed); | |
209 | var feedu = f_doc.getElementById("FEEDU-" + feed); | |
210 | ||
f0601b87 AD |
211 | feedu.innerHTML = "0"; |
212 | ||
213 | if (feedr.className.match("Unread")) { | |
214 | feedr.className = feedr.className.replace("Unread", ""); | |
215 | } | |
216 | } | |
217 | ||
c374a3fe | 218 | var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) + |
f175937c | 219 | "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) + |
cb1083a1 | 220 | "&view=" + param_escape(view_mode) + "&limit=" + limit; |
c374a3fe AD |
221 | |
222 | if (search_query != "") { | |
223 | query = query + "&search=" + param_escape(search_query); | |
224 | } | |
225 | ||
1a66d16e AD |
226 | var headlines_frame = parent.frames["headlines-frame"]; |
227 | ||
228 | headlines_frame.location.href = query + "&addheader=true"; | |
caa4e57f | 229 | |
f0601b87 | 230 | cleanSelected("feedsList"); |
13c280e7 AD |
231 | var feedr = document.getElementById("FEEDR-" + feed); |
232 | if (feedr) { | |
233 | feedr.className = feedr.className + "Selected"; | |
234 | } | |
f0601b87 | 235 | |
1a66d16e | 236 | disableContainerChildren("headlinesToolbar", false, doc); |
ac43eba1 | 237 | |
c05608c2 | 238 | // notify(""); |
9cfc649a AD |
239 | |
240 | } | |
241 | ||
1a66d16e | 242 | |
40d13c28 | 243 | function timeout() { |
cb246176 | 244 | scheduleFeedUpdate(true); |
ac53063a | 245 | setTimeout("timeout()", 1800*1000); |
ac53063a AD |
246 | } |
247 | ||
c374a3fe | 248 | function resetSearch() { |
64c620ce AD |
249 | var searchbox = document.getElementById("searchbox") |
250 | ||
251 | if (searchbox.value != "" && active_feed_id) { | |
252 | searchbox.value = ""; | |
ac43eba1 AD |
253 | viewfeed(active_feed_id, 0, ""); |
254 | } | |
c374a3fe | 255 | } |
ac53063a | 256 | |
f0601b87 | 257 | function search() { |
8158c57a | 258 | checkActiveFeedId(); |
f0601b87 AD |
259 | if (active_feed_id) { |
260 | viewfeed(active_feed_id, 0, ""); | |
261 | } else { | |
262 | notify("Please select some feed first."); | |
263 | } | |
76798ff3 | 264 | } |
1cd17194 | 265 | |
13ad9102 AD |
266 | function localPiggieFunction(enable) { |
267 | if (enable) { | |
268 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
269 | ||
c0e5a40e | 270 | if (xmlhttp_ready(xmlhttp)) { |
13ad9102 AD |
271 | |
272 | xmlhttp.open("GET", query_str, true); | |
273 | xmlhttp.onreadystatechange=feedlist_callback; | |
274 | xmlhttp.send(null); | |
275 | } | |
276 | } | |
277 | } | |
278 | ||
9cfc649a AD |
279 | function localHotkeyHandler(keycode) { |
280 | ||
f0601b87 | 281 | /* if (keycode == 78) { |
c3a8d71a | 282 | return moveToPost('next'); |
9cfc649a AD |
283 | } |
284 | ||
285 | if (keycode == 80) { | |
c3a8d71a | 286 | return moveToPost('prev'); |
f0601b87 | 287 | } */ |
c3a8d71a AD |
288 | |
289 | if (keycode == 82) { | |
290 | return scheduleFeedUpdate(true); | |
291 | } | |
292 | ||
293 | if (keycode == 85) { | |
294 | return viewfeed(active_feed_id, active_offset, "ForceUpdate"); | |
295 | } | |
296 | ||
297 | // notify("KC: " + keycode); | |
298 | ||
9cfc649a AD |
299 | } |
300 | ||
76798ff3 | 301 | function init() { |
c0e5a40e | 302 | |
ac43eba1 AD |
303 | disableContainerChildren("headlinesToolbar", true); |
304 | ||
c0e5a40e AD |
305 | // IE kludge |
306 | ||
307 | if (xmlhttp && !xmlhttp_rpc) { | |
308 | xmlhttp_rpc = xmlhttp; | |
309 | xmlhttp_view = xmlhttp; | |
310 | } | |
311 | ||
312 | if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) { | |
c3a8d71a AD |
313 | document.getElementById("headlines").innerHTML = |
314 | "<b>Fatal error:</b> This program needs XmlHttpRequest " + | |
315 | "to function properly. Your browser doesn't seem to support it."; | |
316 | return; | |
317 | } | |
318 | ||
476cac42 | 319 | updateFeedList(false, false); |
13ad9102 | 320 | document.onkeydown = hotkey_handler; |
70830c87 | 321 | |
77a1bf8b AD |
322 | setTimeout("timeout()", 1800*1000); |
323 | scheduleFeedUpdate(true); | |
1a66d16e | 324 | |
70830c87 | 325 | var content = document.getElementById("content"); |
ac43eba1 | 326 | |
ac43eba1 AD |
327 | if (getCookie("ttrss_vf_vmode")) { |
328 | var viewbox = document.getElementById("viewbox"); | |
329 | viewbox.value = getCookie("ttrss_vf_vmode"); | |
330 | } | |
47179952 | 331 | |
a8d28f48 AD |
332 | if (getCookie("ttrss_vf_limit")) { |
333 | var limitbox = document.getElementById("limitbox"); | |
334 | limitbox.value = getCookie("ttrss_vf_limit"); | |
335 | } | |
1cd17194 | 336 | } |
ac43eba1 AD |
337 | |
338 |