]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
early title work
[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 }
42
43 function viewfeed_callback() {
44 var container = document.getElementById('headlines');
45 if (xmlhttp.readyState == 4) {
46 container.innerHTML = xmlhttp.responseText;
47
48 var factive = document.getElementById("FACTIVE");
49 var funread = document.getElementById("FUNREAD");
50 var ftotal = document.getElementById("FTOTAL");
51
52 if (ftotal && factive && funread) {
53 var feed_id = factive.innerHTML;
54
55 var feedr = document.getElementById("FEEDR-" + feed_id);
56 var feedt = document.getElementById("FEEDT-" + feed_id);
57 var feedu = document.getElementById("FEEDU-" + feed_id);
58
59 feedt.innerHTML = ftotal.innerHTML;
60 feedu.innerHTML = funread.innerHTML;
61
62 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
63 feedr.className = feedr.className + "Unread";
64 } else if (feedu.innerHTML <= 0) {
65 feedr.className = feedr.className.replace("Unread", "");
66 }
67
68 }
69 }
70 }
71
72 function view_callback() {
73 var container = document.getElementById('content');
74 if (xmlhttp.readyState == 4) {
75 container.innerHTML=xmlhttp.responseText;
76 }
77 }
78
79
80 function update_feed_list(called_from_timer, fetch) {
81
82 if (called_from_timer != true) {
83 document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
84 }
85
86 var query_str = "backend.php?op=feeds";
87
88 if (fetch) query_str = query_str + "&fetch=yes";
89
90 xmlhttp.open("GET", query_str, true);
91 xmlhttp.onreadystatechange=feedlist_callback;
92 xmlhttp.send(null);
93
94
95 }
96
97 function viewfeed(feed, skip, ext) {
98
99 // notify("view-feed: " + feed);
100
101 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
102 document.getElementById('content').innerHTML='&nbsp;';
103
104 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
105 "&skip=" + param_escape(skip) + "&ext=" + param_escape(ext) , true);
106 xmlhttp.onreadystatechange=viewfeed_callback;
107 xmlhttp.send(null);
108
109 }
110
111 function view(id,feed_id) {
112
113 var crow = document.getElementById("RROW-" + id);
114
115 if (crow.className.match("Unread")) {
116 var umark = document.getElementById("FEEDU-" + feed_id);
117 umark.innerHTML = umark.innerHTML - 1;
118 crow.className = crow.className.replace("Unread", "");
119
120 if (umark.innerHTML == "0") {
121 var feedr = document.getElementById("FEEDR-" + feed_id);
122 feedr.className = feedr.className.replace("Unread", "");
123 }
124
125 total_unread--;
126
127 update_title();
128 }
129
130 document.getElementById('content').innerHTML='Loading, please wait...';
131
132 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
133 xmlhttp.onreadystatechange=view_callback;
134 xmlhttp.send(null);
135
136 }
137
138 function timeout() {
139
140 update_feed_list(true);
141
142 setTimeout("timeout()", 1800*1000);
143
144 }
145
146 function search(feed, sender) {
147
148 notify("Search: " + feed + ", " + sender.value)
149
150 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
151 document.getElementById('content').innerHTML='&nbsp;';
152
153 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
154 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
155 xmlhttp.onreadystatechange=viewfeed_callback;
156 xmlhttp.send(null);
157
158 }
159
160 function update_title() {
161 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
162 }
163
164 function init() {
165 update_feed_list(false, false);
166 setTimeout("timeout()", 1800*1000);
167 }