]> git.wh0rd.org Git - tt-rss.git/blob - feedlist.js
feed subscribe dialog: align fields
[tt-rss.git] / feedlist.js
1 //var xmlhttp = Ajax.getTransport();
2
3 var feed_cur_page = 0;
4
5 function viewCategory(cat) {
6         active_feed_is_cat = true;
7         viewfeed(cat, '', true);
8         return false;
9 }
10
11 function feedlist_callback() {
12         if (xmlhttp.readyState == 4) {
13                 debug("feedlist_callback");
14                 var f = document.getElementById("feeds-frame");
15                 f.innerHTML = xmlhttp.responseText;
16                 feedlist_init();
17         }
18 }
19
20 var page_offset = 0;
21
22 function viewFeedGoPage(i) {
23         try {
24                 if (!getActiveFeedId()) return;
25
26                 if (i != 0) {
27                         page_offset = page_offset + i;
28                 } else {
29                         page_offset = 0;
30                 }
31
32                 if (page_offset < 0) page_offset = 0;
33                 viewfeed(getActiveFeedId(), undefined, undefined, undefined,
34                         undefined, page_offset);
35         } catch (e) {
36                 exception_error(e, "viewFeedGoPage");
37         }
38 }
39
40
41 function viewNextFeedPage() {
42         try {
43                 if (!getActiveFeedId()) return;
44
45                 feed_cur_page++;
46
47                 viewfeed(getActiveFeedId(), undefined, undefined, undefined,
48                         undefined, feed_cur_page);
49
50         } catch (e) {
51                 exception_error(e, "viewFeedGoPage");
52         }
53 }
54
55 function viewfeed(feed, subop, is_cat, subop_param, skip_history, offset) {
56         try {
57
58 //              if (!offset) page_offset = 0;
59
60                 var page_offset = 0;
61
62                 if (offset > 0) {
63                         page_offset = offset;
64                 } else {
65                         page_offset = 0;
66                         feed_cur_page = 0;
67                 }
68
69                 if (getActiveFeedId() != feed) {
70                         feed_cur_page = 0;
71                 }
72
73                 enableHotkeys();
74
75                 closeInfoBox();
76
77                 Form.enable("main_toolbar_form");
78
79                 var toolbar_form = document.forms["main_toolbar_form"];
80                 var toolbar_query = Form.serialize("main_toolbar_form");
81
82                 if (document.forms["main_toolbar_form"].query) {
83                         toolbar_form.query.value = "";
84                 }
85
86                 var query = "backend.php?op=viewfeed&feed=" + feed + "&" +
87                         toolbar_query + "&subop=" + param_escape(subop);
88
89                 if (document.getElementById("search_form")) {
90                         var search_query = Form.serialize("search_form");
91                         query = query + "&" + search_query;
92                         closeInfoBox(true);
93                 }
94
95                 debug("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
96
97                 var fe = document.getElementById("FEEDR-" + getActiveFeedId());
98
99                 if (fe) {
100                         fe.className = fe.className.replace("Selected", "");
101                 }
102
103                 setActiveFeedId(feed);
104         
105                 if (is_cat != undefined) {
106                         active_feed_is_cat = is_cat;
107                 }
108
109                 if (subop == "MarkAllRead") {
110
111                         var feedlist = document.getElementById('feedList');
112                         
113                         var next_unread_feed = getRelativeFeedId(feedlist,
114                                         getActiveFeedId(), "next", true);
115
116                         if (!next_unread_feed) {
117                                 next_unread_feed = getRelativeFeedId(feedlist,
118                                         -1, "next", true);
119                         }
120
121                         var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
122
123                         if (next_unread_feed && show_next_feed && !activeFeedIsCat()) {
124                                 query = query + "&nuf=" + param_escape(next_unread_feed);
125                                 setActiveFeedId(next_unread_feed);
126                         }
127                 }
128
129                 if (activeFeedIsCat()) {
130                         query = query + "&cat=1";
131                 }
132
133                 if (page_offset != 0) {
134                         query = query + "&skip=" + page_offset;
135                 }
136
137                 var date = new Date();
138                 var timestamp = Math.round(date.getTime() / 1000);
139                 query = query + "&ts=" + timestamp
140
141                 if (!activeFeedIsCat()) {
142                         var feedr = document.getElementById("FEEDR-" + getActiveFeedId());
143                         if (feedr && !feedr.className.match("Selected")) {      
144                                 feedr.className = feedr.className + "Selected";
145                         } 
146                 }
147                 
148                 disableContainerChildren("headlinesToolbar", false);
149                 Form.enable("main_toolbar_form");
150
151                 debug(query);
152
153 /*              var container = document.getElementById("headlines-frame");
154
155                 container.innerHTML = "<div class=\"loadingPrompt\"><img src=\"images/indicator_white.gif\">&nbsp;" +
156                         "Loading, please wait...</div>"; */
157
158                 // for piggybacked counters
159
160                 if (tagsAreDisplayed()) {
161                         query = query + "&omode=lt";
162                 } else {
163                         query = query + "&omode=flc";
164                 }
165
166                 if (!page_offset) {
167                         notify_progress("Loading, please wait...", true);
168                 }
169
170 //              xmlhttp.abort();
171
172                 if (xmlhttp_ready(xmlhttp)) {
173                         xmlhttp.open("GET", query, true);
174                         xmlhttp.onreadystatechange=headlines_callback;
175                         xmlhttp.send(null);
176                 } else {
177                         debug("xmlhttp busy (@feeds)");
178                 }  
179
180         } catch (e) {
181                 exception_error("viewfeed", e);
182         }               
183 }
184
185 function toggleCollapseCat_af(effect) {
186         //var caption = elem.id.replace("FCATLIST-", "");
187
188         try {
189
190                 var elem = effect.element;
191                 var cat = elem.id.replace("FCATLIST-", "");
192                 var cap = document.getElementById("FCAP-" + cat);
193         
194                 if (Element.visible(elem)) {
195                         cap.innerHTML = cap.innerHTML.replace("...", "");
196                 } else {
197                         if (cap.innerHTML.lastIndexOf("...") != cap.innerHTML.length-3) {
198                                 cap.innerHTML = cap.innerHTML + "...";
199                         }
200                 }
201
202         } catch (e) {
203                 exception_error("toggleCollapseCat_af", e);
204         }
205 }
206
207 function toggleCollapseCat(cat) {
208         try {
209                 if (!xmlhttp_ready(xmlhttp)) {
210                         printLockingError();
211                         return;
212                 }
213         
214                 var cat_elem = document.getElementById("FCAT-" + cat);
215                 var cat_list = document.getElementById("FCATLIST-" + cat).parentNode;
216                 var caption = document.getElementById("FCAP-" + cat);
217                 
218 /*              if (cat_list.className.match("invisible")) {
219                         cat_list.className = "";
220                         caption.innerHTML = caption.innerHTML.replace("...", "");
221                         if (cat == 0) {
222                                 setCookie("ttrss_vf_uclps", "0");
223                         }
224                 } else {
225                         cat_list.className = "invisible";
226                         caption.innerHTML = caption.innerHTML + "...";
227                         if (cat == 0) {
228                                 setCookie("ttrss_vf_uclps", "1");
229                         } 
230
231                 } */
232
233                 if (cat == 0) {
234                         if (Element.visible("FCATLIST-" + cat)) {
235                                 setCookie("ttrss_vf_uclps", "1");
236                         } else {
237                                 setCookie("ttrss_vf_uclps", "0");
238                         }
239                 } 
240
241                 if (cat == -2) {
242                         if (Element.visible("FCATLIST-" + cat)) {
243                                 setCookie("ttrss_vf_lclps", "1");
244                         } else {
245                                 setCookie("ttrss_vf_lclps", "0");
246                         }
247                 } 
248
249                 if (cat == -1) {
250                         if (Element.visible("FCATLIST-" + cat)) {
251                                 setCookie("ttrss_vf_vclps", "1");
252                         } else {
253                                 setCookie("ttrss_vf_vclps", "0");
254                         }
255                 } 
256
257                 Effect.toggle('FCATLIST-' + cat, 'blind', { duration: 0.5,
258                         afterFinish: toggleCollapseCat_af });
259
260                 new Ajax.Request("backend.php?op=feeds&subop=collapse&cid=" + 
261                         param_escape(cat));
262
263         } catch (e) {
264                 exception_error("toggleCollapseCat", e);
265         }
266 }
267
268 function feedlist_init() {
269         try {
270 //              if (arguments.callee.done) return;
271 //              arguments.callee.done = true;           
272                 
273                 debug("in feedlist init");
274                 
275                 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
276                 document.onkeydown = hotkey_handler;
277                 setTimeout("timeout()", 0);
278
279                 debug("about to remove splash, OMG!");
280
281                 var o = document.getElementById("overlay");
282
283                 if (o) {
284                         o.style.display = "none";
285                         debug("removed splash!");
286                 }
287
288                 if (typeof correctPNG != 'undefined') {
289                         correctPNG();
290                 }
291
292                 if (getActiveFeedId()) {
293                         debug("some feed is open on feedlist refresh, reloading");
294                         setTimeout("viewCurrentFeed()", 100);
295                 } 
296
297         } catch (e) {
298                 exception_error("feedlist/init", e);
299         }
300 }