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