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