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