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