]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
functions.js: add function cancelDialog()
[tt-rss.git] / tt-rss.js
CommitLineData
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
6var xmlhttp = false;
7
76798ff3 8var total_unread = 0;
525116d4 9var first_run = true;
76798ff3 10
c374a3fe 11var search_query = "";
52b51244 12var search_mode = "";
c374a3fe 13
8143ae1f
AD
14var display_tags = false;
15
fc69e641
AD
16var global_unread = 0;
17
1cd17194
AD
18/*@cc_on @*/
19/*@if (@_jscript_version >= 5)
20// JScript gives us Conditional compilation, we can cope with old IE versions.
21// and security blocked creation of the objects.
22try {
23 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
24} catch (e) {
25 try {
26 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
27 } catch (E) {
28 xmlhttp = false;
29 }
30}
31@end @*/
32
33if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
34 xmlhttp = new XMLHttpRequest();
35}
36
8143ae1f
AD
37function toggleTags() {
38 display_tags = !display_tags;
39
40 var p = document.getElementById("dispSwitchPrompt");
41
42 if (display_tags) {
43 p.innerHTML = "display feeds";
44 } else {
45 p.innerHTML = "display tags";
46 }
47
48 updateFeedList();
49}
50
1a66d16e 51/*
1cd17194 52function feedlist_callback() {
d76a3b03 53 var container = document.getElementById('feeds');
1cd17194 54 if (xmlhttp.readyState == 4) {
d76a3b03 55 container.innerHTML=xmlhttp.responseText;
76798ff3 56
525116d4 57 if (first_run) {
cb246176 58 scheduleFeedUpdate(false);
13c280e7
AD
59 if (getCookie("ttrss_vf_actfeed")) {
60 viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
61 }
525116d4
AD
62 first_run = false;
63 } else {
64 notify("");
c0e5a40e
AD
65 }
66 }
1cd17194 67}
1a66d16e
AD
68*/
69
8158c57a 70function refetch_callback() {
29fb8c70 71 if (xmlhttp.readyState == 4) {
310da49d 72
fc69e641 73// document.title = "Tiny Tiny RSS";
310da49d 74
bc18bcdd
AD
75 if (!xmlhttp.responseXML) {
76 notify("refetch_callback: backend did not return valid XML");
77 return;
78 }
79
090e250b
AD
80 var reply = xmlhttp.responseXML.firstChild;
81
bc18bcdd
AD
82 if (!reply) {
83 notify("refetch_callback: backend did not return expected XML object");
84 return;
9cab3250 85 }
bc18bcdd 86
090e250b
AD
87 var f_document = window.frames["feeds-frame"].document;
88
89 for (var l = 0; l < reply.childNodes.length; l++) {
90 var id = reply.childNodes[l].getAttribute("id");
91 var ctr = reply.childNodes[l].getAttribute("counter");
525116d4 92
090e250b
AD
93 var feedctr = f_document.getElementById("FEEDCTR-" + id);
94 var feedu = f_document.getElementById("FEEDU-" + id);
95 var feedr = f_document.getElementById("FEEDR-" + id);
96
fc69e641
AD
97/* TODO figure out how to update this from viewfeed.js->view()
98 disabled for now...
99
100 if (id == "global-unread") {
101 global_unread = ctr;
102 } */
103
8143ae1f
AD
104 if (feedctr && feedu && feedr) {
105
106 feedu.innerHTML = ctr;
107
108 if (ctr > 0) {
109 feedctr.className = "odd";
110 if (!feedr.className.match("Unread")) {
111 feedr.className = feedr.className + "Unread";
112 }
113 } else {
114 feedctr.className = "invisible";
115 feedr.className = feedr.className.replace("Unread", "");
090e250b 116 }
090e250b
AD
117 }
118 }
fc69e641
AD
119
120 updateTitle("");
121 notify("All feeds updated.");
122
090e250b
AD
123 }
124}
1a66d16e 125
caa4e57f
AD
126function updateFeed(feed_id) {
127
128 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
129
29fb8c70
AD
130 if (xmlhttp_ready(xmlhttp)) {
131 xmlhttp.open("GET", query_str, true);
132 xmlhttp.onreadystatechange=feed_update_callback;
133 xmlhttp.send(null);
caa4e57f
AD
134 } else {
135 printLockingError();
136 }
137
138}
139
cb246176 140function scheduleFeedUpdate(force) {
525116d4
AD
141
142 notify("Updating feeds in background...");
143
fc69e641
AD
144// document.title = "Tiny Tiny RSS - Updating...";
145
146 updateTitle("Updating...");
55193822 147
cb246176
AD
148 var query_str = "backend.php?op=rpc&subop=";
149
150 if (force) {
c3b81db0 151 query_str = query_str + "forceUpdateAllFeeds";
cb246176 152 } else {
c3b81db0 153 query_str = query_str + "updateAllFeeds";
cb246176 154 }
525116d4 155
29fb8c70
AD
156 if (xmlhttp_ready(xmlhttp)) {
157 xmlhttp.open("GET", query_str, true);
158 xmlhttp.onreadystatechange=refetch_callback;
159 xmlhttp.send(null);
525116d4
AD
160 } else {
161 printLockingError();
c0e5a40e 162 }
525116d4 163}
1cd17194 164
525116d4 165function updateFeedList(silent, fetch) {
c0e5a40e 166
1a66d16e
AD
167// if (silent != true) {
168// notify("Loading feed list...");
169// }
82baad4a 170
331900c6
AD
171 var query_str = "backend.php?op=feeds";
172
8143ae1f
AD
173 if (display_tags) {
174 query_str = query_str + "&tags=1";
175 }
176
86741347
AD
177 if (getActiveFeedId()) {
178 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
179 }
180
1a66d16e 181 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 182
1a66d16e 183 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 184
1a66d16e
AD
185 feeds_frame.src = query_str;
186}
175847de 187
476cac42 188function catchupAllFeeds() {
076682aa 189
476cac42
AD
190 var query_str = "backend.php?op=feeds&subop=catchupAll";
191
192 notify("Marking all feeds as read...");
193
1a66d16e
AD
194 var feeds_frame = document.getElementById("feeds-frame");
195
196 feeds_frame.src = query_str;
476cac42 197
fc69e641
AD
198 global_unread = 0;
199 updateTitle();
200
476cac42 201}
1cd17194 202
f0601b87 203function viewCurrentFeed(skip, subop) {
1a66d16e 204
86741347
AD
205 if (getActiveFeedId()) {
206 viewfeed(getActiveFeedId(), skip, subop);
f0601b87
AD
207 }
208}
209
476cac42 210function viewfeed(feed, skip, subop) {
1cd17194 211
caa486f8 212// notify("Loading headlines...");
c05608c2 213
36bf7496
AD
214 enableHotkeys();
215
c374a3fe
AD
216 var searchbox = document.getElementById("searchbox");
217
218 if (searchbox) {
219 search_query = searchbox.value;
220 } else {
221 search_query = "";
222 }
223
52b51244
AD
224 var searchmodebox = document.getElementById("searchmodebox");
225
226 if (searchmodebox) {
227 search_mode = searchmodebox.value;
228 } else {
229 search_mode = "";
230 }
231
232 setCookie("ttrss_vf_smode", search_mode);
233
f175937c
AD
234 var viewbox = document.getElementById("viewbox");
235
236 var view_mode;
237
238 if (viewbox) {
25cb5736 239 view_mode = viewbox[viewbox.selectedIndex].text;
f175937c
AD
240 } else {
241 view_mode = "All Posts";
242 }
243
ac43eba1
AD
244 setCookie("ttrss_vf_vmode", view_mode);
245
cb1083a1
AD
246 var limitbox = document.getElementById("limitbox");
247
248 var limit;
249
250 if (limitbox) {
25cb5736 251 limit = limitbox[limitbox.selectedIndex].text;
ac43eba1 252 setCookie("ttrss_vf_limit", limit);
cb1083a1
AD
253 } else {
254 limit = "All";
255 }
256
86741347 257 setActiveFeedId(feed);
1a66d16e
AD
258
259 var f_doc = frames["feeds-frame"].document;
260
86741347 261// f_doc.getElementById("ACTFEEDID").innerHTML = feed;
caa486f8 262
f0601b87
AD
263 if (subop == "MarkAllRead") {
264
1a66d16e 265 var feedr = f_doc.getElementById("FEEDR-" + feed);
deaaa02c 266 var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
1a66d16e 267
deaaa02c 268 feedctr.className = "invisible";
f0601b87
AD
269
270 if (feedr.className.match("Unread")) {
271 feedr.className = feedr.className.replace("Unread", "");
272 }
273 }
274
c374a3fe 275 var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
f175937c 276 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
52b51244
AD
277 "&view=" + param_escape(view_mode) + "&limit=" + limit +
278 "&smode=" + param_escape(search_mode);
c374a3fe
AD
279
280 if (search_query != "") {
281 query = query + "&search=" + param_escape(search_query);
282 }
283
1a66d16e
AD
284 var headlines_frame = parent.frames["headlines-frame"];
285
286 headlines_frame.location.href = query + "&addheader=true";
caa4e57f 287
f0601b87 288 cleanSelected("feedsList");
13c280e7
AD
289 var feedr = document.getElementById("FEEDR-" + feed);
290 if (feedr) {
291 feedr.className = feedr.className + "Selected";
292 }
f0601b87 293
1a66d16e 294 disableContainerChildren("headlinesToolbar", false, doc);
ac43eba1 295
a7de14fc
AD
296 var btnMarkAsRead = document.getElementById("btnMarkFeedAsRead");
297
919bb09c 298 if (btnMarkAsRead && !isNumeric(feed)) {
a7de14fc
AD
299 btnMarkAsRead.disabled = true;
300 btnMarkAsRead.className = "disabledButton";
301 }
302
c05608c2 303// notify("");
9cfc649a
AD
304
305}
306
1a66d16e 307
40d13c28 308function timeout() {
cb246176 309 scheduleFeedUpdate(true);
ac53063a 310 setTimeout("timeout()", 1800*1000);
ac53063a
AD
311}
312
c374a3fe 313function resetSearch() {
64c620ce
AD
314 var searchbox = document.getElementById("searchbox")
315
86741347 316 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 317 searchbox.value = "";
86741347 318 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 319 }
c374a3fe 320}
ac53063a 321
f0601b87 322function search() {
4ce19859 323 viewCurrentFeed(0, "");
76798ff3 324}
1cd17194 325
13ad9102
AD
326function localPiggieFunction(enable) {
327 if (enable) {
328 var query_str = "backend.php?op=feeds&subop=piggie";
329
c0e5a40e 330 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
331
332 xmlhttp.open("GET", query_str, true);
333 xmlhttp.onreadystatechange=feedlist_callback;
334 xmlhttp.send(null);
335 }
336 }
337}
338
9cfc649a
AD
339function localHotkeyHandler(keycode) {
340
f0601b87 341/* if (keycode == 78) {
c3a8d71a 342 return moveToPost('next');
9cfc649a
AD
343 }
344
345 if (keycode == 80) {
c3a8d71a 346 return moveToPost('prev');
f0601b87 347 } */
c3a8d71a
AD
348
349 if (keycode == 82) {
350 return scheduleFeedUpdate(true);
351 }
352
353 if (keycode == 85) {
86741347 354 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
c3a8d71a
AD
355 }
356
357// notify("KC: " + keycode);
358
9cfc649a
AD
359}
360
fc69e641
AD
361function updateTitle(s) {
362 var tmp = "Tiny Tiny RSS";
363
364 if (global_unread > 0) {
365 tmp = tmp + " (" + global_unread + ")";
366 }
367
368 if (s) {
369 tmp = tmp + " - " + s;
370 }
371 document.title = tmp;
372}
373
22a93ad8 374function genericSanityCheck() {
ac43eba1 375
29fb8c70 376 if (!xmlhttp) {
c3a8d71a 377 document.getElementById("headlines").innerHTML =
29fb8c70 378 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
c3a8d71a 379 "to function properly. Your browser doesn't seem to support it.";
22a93ad8
AD
380 return false;
381 }
382
383 setCookie("ttrss_vf_test", "TEST");
384 if (getCookie("ttrss_vf_test") != "TEST") {
385
386 document.getElementById("headlines").innerHTML =
387 "<b>Fatal error:</b> This program requires cookies " +
388 "to function properly. Your browser doesn't seem to support them.";
389
390 return false;
c3a8d71a
AD
391 }
392
22a93ad8
AD
393 return true;
394}
395
396function init() {
397
398 disableContainerChildren("headlinesToolbar", true);
399
400 if (!genericSanityCheck())
401 return;
402
fe2f1970
AD
403 setCookie("ttrss_vf_actfeed", "");
404
476cac42 405 updateFeedList(false, false);
13ad9102 406 document.onkeydown = hotkey_handler;
70830c87 407
77a1bf8b
AD
408 setTimeout("timeout()", 1800*1000);
409 scheduleFeedUpdate(true);
1a66d16e 410
70830c87 411 var content = document.getElementById("content");
ac43eba1 412
ac43eba1
AD
413 if (getCookie("ttrss_vf_vmode")) {
414 var viewbox = document.getElementById("viewbox");
415 viewbox.value = getCookie("ttrss_vf_vmode");
416 }
47179952 417
a8d28f48
AD
418 if (getCookie("ttrss_vf_limit")) {
419 var limitbox = document.getElementById("limitbox");
420 limitbox.value = getCookie("ttrss_vf_limit");
421 }
86741347
AD
422
423// if (getCookie("ttrss_vf_actfeed")) {
424// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
425// }
426
1cd17194 427}
ac43eba1
AD
428
429