]> git.wh0rd.org - tt-rss.git/blame - prefs.js
MSIE5 compatibility workarounds
[tt-rss.git] / prefs.js
CommitLineData
007bda35
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
007bda35
AD
27
28function feedlist_callback() {
29 var container = document.getElementById('feeds');
30 if (xmlhttp.readyState == 4) {
31 container.innerHTML=xmlhttp.responseText;
32 }
33}
34
0e091d38
AD
35function notify_callback() {
36 var container = document.getElementById('notify');
37 if (xmlhttp.readyState == 4) {
38 container.innerHTML=xmlhttp.responseText;
39 }
40}
41
175847de 42
0e091d38 43function updateFeedList() {
007bda35 44
c0e5a40e 45 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
46 printLockingError();
47 return
48 }
49
007bda35
AD
50 document.getElementById("feeds").innerHTML = "Loading feeds, please wait...";
51
52 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
53 xmlhttp.onreadystatechange=feedlist_callback;
54 xmlhttp.send(null);
55
56}
57
58function toggleSelectRow(sender) {
59 var parent_row = sender.parentNode.parentNode;
60
61 if (sender.checked) {
62 if (!parent_row.className.match("Selected")) {
63 parent_row.className = parent_row.className + "Selected";
64 }
65 } else {
66 if (parent_row.className.match("Selected")) {
67 parent_row.className = parent_row.className.replace("Selected", "");
68 }
69 }
70}
71
71ad3959
AD
72function addFeed() {
73
c0e5a40e 74 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
75 printLockingError();
76 return
77 }
78
331900c6
AD
79 var link = document.getElementById("fadd_link");
80
83fe4d6d 81 if (link.value.length == 0) {
c753cd32 82 notify("Missing feed URL.");
331900c6
AD
83 } else {
84 notify("Adding feed...");
85
86 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
87 param_escape(link.value), true);
88 xmlhttp.onreadystatechange=feedlist_callback;
89 xmlhttp.send(null);
90
91 link.value = "";
92
93 }
94
95}
96
97function editFeed(feed) {
98
508a81e1
AD
99// notify("Editing feed...");
100
c0e5a40e 101 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
102 printLockingError();
103 return
104 }
331900c6
AD
105
106 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=edit&id=" +
107 param_escape(feed), true);
108 xmlhttp.onreadystatechange=feedlist_callback;
109 xmlhttp.send(null);
110
111}
112
83fe4d6d 113function getSelectedFeeds() {
331900c6
AD
114
115 var content = document.getElementById("prefFeedList");
116
117 var sel_rows = new Array();
118
119 for (i = 0; i < content.rows.length; i++) {
120 if (content.rows[i].className.match("Selected")) {
121 var row_id = content.rows[i].id.replace("FEEDR-", "");
122 sel_rows.push(row_id);
123 }
124 }
125
83fe4d6d
AD
126 return sel_rows;
127}
128
129function readSelectedFeeds() {
130
c0e5a40e 131 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
132 printLockingError();
133 return
134 }
135
83fe4d6d
AD
136 var sel_rows = getSelectedFeeds();
137
138 if (sel_rows.length > 0) {
139
140 notify("Marking selected feeds as read...");
141
0e091d38 142 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 143 param_escape(sel_rows.toString()), true);
0e091d38 144 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
145 xmlhttp.send(null);
146
147 } else {
148
c753cd32 149 notify("Please select some feeds first.");
83fe4d6d
AD
150
151 }
152}
153
154function unreadSelectedFeeds() {
155
c0e5a40e 156 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
157 printLockingError();
158 return
159 }
160
83fe4d6d
AD
161 var sel_rows = getSelectedFeeds();
162
163 if (sel_rows.length > 0) {
164
165 notify("Marking selected feeds as unread...");
166
0e091d38 167 xmlhttp.open("GET", "backend.php?op=pref-rpc&subop=unread&ids="+
83fe4d6d 168 param_escape(sel_rows.toString()), true);
0e091d38 169 xmlhttp.onreadystatechange=notify_callback;
83fe4d6d
AD
170 xmlhttp.send(null);
171
172 } else {
173
c753cd32 174 notify("Please select some feeds first.");
83fe4d6d
AD
175
176 }
177}
178
179function removeSelectedFeeds() {
180
c0e5a40e 181 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
182 printLockingError();
183 return
184 }
185
83fe4d6d
AD
186 var sel_rows = getSelectedFeeds();
187
331900c6
AD
188 if (sel_rows.length > 0) {
189
190 notify("Removing selected feeds...");
191
192 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids="+
193 param_escape(sel_rows.toString()), true);
194 xmlhttp.onreadystatechange=feedlist_callback;
195 xmlhttp.send(null);
71ad3959 196
71ad3959 197 } else {
331900c6 198
c753cd32 199 notify("Please select some feeds first.");
331900c6 200
71ad3959
AD
201 }
202
203}
007bda35 204
508a81e1
AD
205function feedEditCancel() {
206
c0e5a40e 207 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
208 printLockingError();
209 return
210 }
211
212 notify("Operation cancelled.");
213
214 xmlhttp.open("GET", "backend.php?op=pref-feeds", true);
215 xmlhttp.onreadystatechange=feedlist_callback;
216 xmlhttp.send(null);
217
218}
219
220function feedEditSave(feed) {
221
c0e5a40e 222 if (!xmlhttp_ready(xmlhttp)) {
508a81e1
AD
223 printLockingError();
224 return
225 }
226
227 notify("Saving feed.");
228
229 var link = document.getElementById("fedit_link").value;
230 var title = document.getElementById("fedit_title").value;
231
232 if (link.length == 0) {
233 notify("Feed link cannot be blank.");
234 return;
235 }
236
237 if (title.length == 0) {
238 notify("Feed title cannot be blank.");
239 return;
240 }
241
242 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editSave&id=" +
243 feed + "&l=" + param_escape(link) + "&t=" + param_escape(title) ,true);
244 xmlhttp.onreadystatechange=feedlist_callback;
245 xmlhttp.send(null);
246
247}
248
249function editSelectedFeed() {
250 var rows = getSelectedFeeds();
251
252 if (rows.length == 0) {
253 notify("No feeds are selected.");
254 return;
255 }
256
257 if (rows.length > 1) {
258 notify("Please select one feed.");
259 return;
260 }
261
262 editFeed(rows[0]);
263
264}
265
13ad9102
AD
266function localPiggieFunction(enable) {
267 if (enable) {
508a81e1
AD
268 piggie.style.display = "block";
269 seq = "";
270 notify("I loveded it!!!");
271 } else {
272 piggie.style.display = "none";
273 notify("");
274 }
508a81e1
AD
275}
276
007bda35 277function init() {
857a9270 278
0e091d38 279 updateFeedList();
508a81e1 280 document.onkeydown = hotkey_handler;
857a9270
AD
281 notify("");
282
007bda35 283}