]> git.wh0rd.org Git - tt-rss.git/blob - feedlist.js
infinite scrolling
[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                 if (offset > 0) {
61                         page_offset = offset;
62                 } else {
63                         page_offset = 0;
64                         feed_cur_page = 0;
65                 }
66
67                 if (getActiveFeedId() != feed) {
68                         feed_cur_page = 0;
69                 }
70
71                 enableHotkeys();
72
73                 closeInfoBox();
74
75                 Form.enable("main_toolbar_form");
76
77                 var toolbar_form = document.forms["main_toolbar_form"];
78                 var toolbar_query = Form.serialize("main_toolbar_form");
79
80                 if (document.forms["main_toolbar_form"].query) {
81                         toolbar_form.query.value = "";
82                 }
83
84                 var query = "backend.php?op=viewfeed&feed=" + feed + "&" +
85                         toolbar_query + "&subop=" + param_escape(subop);
86
87                 if (document.getElementById("search_form")) {
88                         var search_query = Form.serialize("search_form");
89                         query = query + "&" + search_query;
90                         closeInfoBox(true);
91                 }
92
93                 debug("IS_CAT_STORED: " + activeFeedIsCat() + ", IS_CAT: " + is_cat);
94
95                 var fe = document.getElementById("FEEDR-" + getActiveFeedId());
96
97                 if (fe) {
98                         fe.className = fe.className.replace("Selected", "");
99                 }
100
101                 setActiveFeedId(feed);
102         
103                 if (is_cat != undefined) {
104                         active_feed_is_cat = is_cat;
105                 }
106
107                 if (subop == "MarkAllRead") {
108
109                         var feedlist = document.getElementById('feedList');
110                         
111                         var next_unread_feed = getRelativeFeedId(feedlist,
112                                         getActiveFeedId(), "next", true);
113
114                         if (!next_unread_feed) {
115                                 next_unread_feed = getRelativeFeedId(feedlist,
116                                         -1, "next", true);
117                         }
118
119                         var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
120
121                         if (next_unread_feed && show_next_feed && !activeFeedIsCat()) {
122                                 query = query + "&nuf=" + param_escape(next_unread_feed);
123                                 setActiveFeedId(next_unread_feed);
124                         }
125                 }
126
127                 if (activeFeedIsCat()) {
128                         query = query + "&cat=1";
129                 }
130
131                 if (page_offset != 0) {
132                         query = query + "&skip=" + page_offset;
133                 }
134
135                 var date = new Date();
136                 var timestamp = Math.round(date.getTime() / 1000);
137                 query = query + "&ts=" + timestamp
138
139                 if (!activeFeedIsCat()) {
140                         var feedr = document.getElementById("FEEDR-" + getActiveFeedId());
141                         if (feedr && !feedr.className.match("Selected")) {      
142                                 feedr.className = feedr.className + "Selected";
143                         } 
144                 }
145                 
146                 disableContainerChildren("headlinesToolbar", false);
147                 Form.enable("main_toolbar_form");
148
149                 debug(query);
150
151 /*              var container = document.getElementById("headlines-frame");
152
153                 container.innerHTML = "<div class=\"loadingPrompt\"><img src=\"images/indicator_white.gif\">&nbsp;" +
154                         "Loading, please wait...</div>"; */
155
156                 // for piggybacked counters
157
158                 if (tagsAreDisplayed()) {
159                         query = query + "&omode=lt";
160                 } else {
161                         query = query + "&omode=flc";
162                 }
163
164                 notify_progress("Loading, please wait...", true);
165
166 //              xmlhttp.abort();
167
168                 if (xmlhttp_ready(xmlhttp)) {
169                         xmlhttp.open("GET", query, true);
170                         xmlhttp.onreadystatechange=headlines_callback;
171                         xmlhttp.send(null);
172                 } else {
173                         debug("xmlhttp busy (@feeds)");
174                 }  
175
176         } catch (e) {
177                 exception_error("viewfeed", e);
178         }               
179 }
180
181 function toggleCollapseCat(cat) {
182         try {
183                 if (!xmlhttp_ready(xmlhttp)) {
184                         printLockingError();
185                         return;
186                 }
187         
188                 var cat_elem = document.getElementById("FCAT-" + cat);
189                 var cat_list = document.getElementById("FCATLIST-" + cat).parentNode;
190                 var caption = document.getElementById("FCAP-" + cat);
191                 
192                 if (cat_list.className.match("invisible")) {
193                         cat_list.className = "";
194                         caption.innerHTML = caption.innerHTML.replace("...", "");
195                         if (cat == 0) {
196                                 setCookie("ttrss_vf_uclps", "0");
197                         }
198                 } else {
199                         cat_list.className = "invisible";
200                         caption.innerHTML = caption.innerHTML + "...";
201                         if (cat == 0) {
202                                 setCookie("ttrss_vf_uclps", "1");
203                         }
204                 }
205
206                 new Ajax.Request("backend.php?op=feeds&subop=collapse&cid=" + 
207                         param_escape(cat));
208
209         } catch (e) {
210                 exception_error("toggleCollapseCat", e);
211         }
212 }
213
214 function feedlist_init() {
215         try {
216 //              if (arguments.callee.done) return;
217 //              arguments.callee.done = true;           
218                 
219                 debug("in feedlist init");
220                 
221                 hideOrShowFeeds(document, getInitParam("hide_read_feeds") == 1);
222                 document.onkeydown = hotkey_handler;
223                 setTimeout("timeout()", 0);
224
225                 debug("about to remove splash, OMG!");
226
227                 var o = document.getElementById("overlay");
228
229                 if (o) {
230                         o.style.display = "none";
231                         debug("removed splash!");
232                 }
233
234                 if (typeof correctPNG != 'undefined') {
235                         correctPNG();
236                 }
237
238                 if (getActiveFeedId()) {
239                         debug("some feed is open on feedlist refresh, reloading");
240                         setTimeout("viewCurrentFeed()", 100);
241                 } 
242
243         } catch (e) {
244                 exception_error("feedlist/init", e);
245         }
246 }