]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
force refetching feeds on timeout update
[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
AD
8var total_unread = 0;
9
1cd17194
AD
10/*@cc_on @*/
11/*@if (@_jscript_version >= 5)
12// JScript gives us Conditional compilation, we can cope with old IE versions.
13// and security blocked creation of the objects.
14try {
15 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
16} catch (e) {
17 try {
18 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
19 } catch (E) {
20 xmlhttp = false;
21 }
22}
23@end @*/
24
25if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27}
28
1cd17194 29function feedlist_callback() {
d76a3b03 30 var container = document.getElementById('feeds');
1cd17194 31 if (xmlhttp.readyState == 4) {
d76a3b03 32 container.innerHTML=xmlhttp.responseText;
76798ff3
AD
33
34 var feedtu = document.getElementById("FEEDTU");
35
36 if (feedtu) {
37 total_unread = feedtu.innerHTML;
38 update_title();
39 }
476cac42
AD
40
41 notify("");
1cd17194
AD
42 }
43}
44
45function viewfeed_callback() {
d76a3b03 46 var container = document.getElementById('headlines');
1cd17194 47 if (xmlhttp.readyState == 4) {
d76a3b03 48 container.innerHTML = xmlhttp.responseText;
a1a8a2be
AD
49
50 var factive = document.getElementById("FACTIVE");
51 var funread = document.getElementById("FUNREAD");
52 var ftotal = document.getElementById("FTOTAL");
53
54 if (ftotal && factive && funread) {
55 var feed_id = factive.innerHTML;
56
57 var feedr = document.getElementById("FEEDR-" + feed_id);
58 var feedt = document.getElementById("FEEDT-" + feed_id);
59 var feedu = document.getElementById("FEEDU-" + feed_id);
60
61 feedt.innerHTML = ftotal.innerHTML;
62 feedu.innerHTML = funread.innerHTML;
63
64 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
65 feedr.className = feedr.className + "Unread";
66 } else if (feedu.innerHTML <= 0) {
67 feedr.className = feedr.className.replace("Unread", "");
68 }
69
70 }
1c37c607
AD
71
72 notify("");
73
74 }
1cd17194
AD
75}
76
77function view_callback() {
d76a3b03 78 var container = document.getElementById('content');
1cd17194 79 if (xmlhttp.readyState == 4) {
d76a3b03 80 container.innerHTML=xmlhttp.responseText;
1cd17194
AD
81 }
82}
83
84
476cac42 85function updateFeedList(called_from_timer, fetch) {
1cd17194 86
40d13c28 87 if (called_from_timer != true) {
476cac42
AD
88 //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
89 notify("Updating feeds...");
40d13c28 90 }
82baad4a 91
331900c6
AD
92 var query_str = "backend.php?op=feeds";
93
94 if (fetch) query_str = query_str + "&fetch=yes";
95
96 xmlhttp.open("GET", query_str, true);
1cd17194
AD
97 xmlhttp.onreadystatechange=feedlist_callback;
98 xmlhttp.send(null);
99
100}
101
476cac42
AD
102function catchupAllFeeds() {
103 var query_str = "backend.php?op=feeds&subop=catchupAll";
104
105 notify("Marking all feeds as read...");
106
107 xmlhttp.open("GET", query_str, true);
108 xmlhttp.onreadystatechange=feedlist_callback;
109 xmlhttp.send(null);
110
111}
1cd17194 112
476cac42 113function viewfeed(feed, skip, subop) {
1cd17194 114
1c37c607
AD
115// document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
116// document.getElementById('content').innerHTML='&nbsp;';
d76a3b03
AD
117
118 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
476cac42 119 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
1cd17194
AD
120 xmlhttp.onreadystatechange=viewfeed_callback;
121 xmlhttp.send(null);
122
1c37c607
AD
123 notify("Loading headlines...");
124
1cd17194
AD
125}
126
a1a8a2be 127function view(id,feed_id) {
d76a3b03
AD
128
129 var crow = document.getElementById("RROW-" + id);
130
a1a8a2be
AD
131 if (crow.className.match("Unread")) {
132 var umark = document.getElementById("FEEDU-" + feed_id);
133 umark.innerHTML = umark.innerHTML - 1;
d76a3b03 134 crow.className = crow.className.replace("Unread", "");
d76a3b03 135
a1a8a2be
AD
136 if (umark.innerHTML == "0") {
137 var feedr = document.getElementById("FEEDR-" + feed_id);
138 feedr.className = feedr.className.replace("Unread", "");
139 }
b197f117 140
76798ff3
AD
141 total_unread--;
142
b197f117 143 update_title();
76798ff3 144 }
1cd17194 145
b197f117
AD
146 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
147
148 if (upd_img_pic) {
149 upd_img_pic.innerHTML = "";
150 }
151
d76a3b03 152 document.getElementById('content').innerHTML='Loading, please wait...';
1cd17194 153
d76a3b03 154 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
1cd17194
AD
155 xmlhttp.onreadystatechange=view_callback;
156 xmlhttp.send(null);
157
158}
159
40d13c28
AD
160function timeout() {
161
5d348fee 162 updateFeedList(true, true);
40d13c28 163
ac53063a
AD
164 setTimeout("timeout()", 1800*1000);
165
166}
167
168function search(feed, sender) {
169
170 notify("Search: " + feed + ", " + sender.value)
171
172 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
173 document.getElementById('content').innerHTML='&nbsp;';
174
175 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
176 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
177 xmlhttp.onreadystatechange=viewfeed_callback;
178 xmlhttp.send(null);
40d13c28
AD
179
180}
181
76798ff3
AD
182function update_title() {
183 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
184}
1cd17194 185
76798ff3 186function init() {
476cac42 187 updateFeedList(false, false);
ac53063a 188 setTimeout("timeout()", 1800*1000);
1cd17194 189}