]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
bump version
[tt-rss.git] / tt-rss.js
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
6 var xmlhttp = false;
7
8 var total_unread = 0;
9
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.
14 try {
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
25 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
26 xmlhttp = new XMLHttpRequest();
27 }
28
29 function feedlist_callback() {
30 var container = document.getElementById('feeds');
31 if (xmlhttp.readyState == 4) {
32 container.innerHTML=xmlhttp.responseText;
33
34 var feedtu = document.getElementById("FEEDTU");
35
36 if (feedtu) {
37 total_unread = feedtu.innerHTML;
38 update_title();
39 }
40
41 notify("");
42 }
43 }
44
45 function viewfeed_callback() {
46 var container = document.getElementById('headlines');
47 if (xmlhttp.readyState == 4) {
48 container.innerHTML = xmlhttp.responseText;
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 }
71
72 notify("");
73
74 }
75 }
76
77 function view_callback() {
78 var container = document.getElementById('content');
79 if (xmlhttp.readyState == 4) {
80 container.innerHTML=xmlhttp.responseText;
81 }
82 }
83
84
85 function updateFeedList(called_from_timer, fetch) {
86
87 if (called_from_timer != true) {
88 //document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
89 notify("Updating feeds...");
90 }
91
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);
97 xmlhttp.onreadystatechange=feedlist_callback;
98 xmlhttp.send(null);
99
100 }
101
102 function 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 }
112
113 function viewfeed(feed, skip, subop) {
114
115 // document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
116 // document.getElementById('content').innerHTML='&nbsp;';
117
118 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
119 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
120 xmlhttp.onreadystatechange=viewfeed_callback;
121 xmlhttp.send(null);
122
123 notify("Loading headlines...");
124
125 }
126
127 function view(id,feed_id) {
128
129 var crow = document.getElementById("RROW-" + id);
130
131 if (crow.className.match("Unread")) {
132 var umark = document.getElementById("FEEDU-" + feed_id);
133 umark.innerHTML = umark.innerHTML - 1;
134 crow.className = crow.className.replace("Unread", "");
135
136 if (umark.innerHTML == "0") {
137 var feedr = document.getElementById("FEEDR-" + feed_id);
138 feedr.className = feedr.className.replace("Unread", "");
139 }
140
141 total_unread--;
142
143 update_title();
144 }
145
146 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
147
148 if (upd_img_pic) {
149 upd_img_pic.innerHTML = "";
150 }
151
152 document.getElementById('content').innerHTML='Loading, please wait...';
153
154 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
155 xmlhttp.onreadystatechange=view_callback;
156 xmlhttp.send(null);
157
158 }
159
160 function timeout() {
161
162 updateFeedList(true);
163
164 setTimeout("timeout()", 1800*1000);
165
166 }
167
168 function 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);
179
180 }
181
182 function update_title() {
183 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
184 }
185
186 function init() {
187 updateFeedList(false, false);
188 setTimeout("timeout()", 1800*1000);
189 }