6 var display_tags = false;
10 var active_title_text = "";
12 var current_subtitle = "";
15 /*@if (@_jscript_version >= 5)
16 // JScript gives us Conditional compilation, we can cope with old IE versions.
17 // and security blocked creation of the objects.
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
29 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
30 xmlhttp = new XMLHttpRequest();
33 function toggleTags() {
34 display_tags = !display_tags;
36 var p = document.getElementById("dispSwitchPrompt");
39 p.innerHTML = "display feeds";
41 p.innerHTML = "display tags";
47 function dlg_frefresh_callback() {
48 if (xmlhttp.readyState == 4) {
49 updateFeedList(false, false);
54 function dialog_refresh_callback() {
55 if (xmlhttp.readyState == 4) {
56 var dlg = document.getElementById("userDlg");
57 var dlg_s = document.getElementById("userDlgShadow");
59 dlg.innerHTML = xmlhttp.responseText;
60 dlg_s.style.display = "block";
64 function refetch_callback() {
65 if (xmlhttp.readyState == 4) {
68 if (!xmlhttp.responseXML) {
69 notify("refetch_callback: backend did not return valid XML");
73 var reply = xmlhttp.responseXML.firstChild;
76 notify("refetch_callback: backend did not return expected XML object");
80 var error_code = reply.getAttribute("error-code");
82 if (error_code && error_code != 0) {
83 return fatalError(error_code);
86 var f_document = window.frames["feeds-frame"].document;
88 for (var l = 0; l < reply.childNodes.length; l++) {
89 var id = reply.childNodes[l].getAttribute("id");
90 var ctr = reply.childNodes[l].getAttribute("counter");
92 var feedctr = f_document.getElementById("FEEDCTR-" + id);
93 var feedu = f_document.getElementById("FEEDU-" + id);
94 var feedr = f_document.getElementById("FEEDR-" + id);
96 /* TODO figure out how to update this from viewfeed.js->view()
99 if (id == "global-unread") {
103 if (feedctr && feedu && feedr) {
105 feedu.innerHTML = ctr;
108 feedctr.className = "odd";
109 if (!feedr.className.match("Unread")) {
110 feedr.className = feedr.className + "Unread";
113 feedctr.className = "invisible";
114 feedr.className = feedr.className.replace("Unread", "");
120 notify("All feeds updated.");
122 exception_error("refetch_callback", e);
127 function backend_sanity_check_callback() {
129 if (xmlhttp.readyState == 4) {
133 if (!xmlhttp.responseXML) {
138 var reply = xmlhttp.responseXML.firstChild;
145 var error_code = reply.getAttribute("error-code");
147 if (error_code && error_code != 0) {
148 return fatalError(error_code);
154 exception_error("backend_sanity_check_callback", e);
159 function scheduleFeedUpdate(force) {
161 notify("Updating feeds in background...");
163 // document.title = "Tiny Tiny RSS - Updating...";
165 updateTitle("Updating");
167 var query_str = "backend.php?op=rpc&subop=";
170 query_str = query_str + "forceUpdateAllFeeds";
172 query_str = query_str + "updateAllFeeds";
183 query_str = query_str + "&omode=" + omode;
185 if (xmlhttp_ready(xmlhttp)) {
186 xmlhttp.open("GET", query_str, true);
187 xmlhttp.onreadystatechange=refetch_callback;
194 function updateFeedList(silent, fetch) {
196 // if (silent != true) {
197 // notify("Loading feed list...");
200 var query_str = "backend.php?op=feeds";
203 query_str = query_str + "&tags=1";
206 if (getActiveFeedId()) {
207 query_str = query_str + "&actid=" + getActiveFeedId();
210 if (fetch) query_str = query_str + "&fetch=yes";
212 var feeds_frame = document.getElementById("feeds-frame");
214 feeds_frame.src = query_str;
217 function catchupAllFeeds() {
219 var query_str = "backend.php?op=feeds&subop=catchupAll";
221 notify("Marking all feeds as read...");
223 var feeds_frame = document.getElementById("feeds-frame");
225 feeds_frame.src = query_str;
232 function viewCurrentFeed(skip, subop) {
234 if (getActiveFeedId()) {
235 viewfeed(getActiveFeedId(), skip, subop);
237 disableContainerChildren("headlinesToolbar", false, document);
238 viewfeed(-1, skip, subop); // FIXME
242 function viewfeed(feed, skip, subop) {
243 var f = window.frames["feeds-frame"];
244 f.viewfeed(feed, skip, subop);
248 scheduleFeedUpdate(false);
249 setTimeout("timeout()", 1800*1000);
252 function resetSearch() {
253 var searchbox = document.getElementById("searchbox")
255 if (searchbox.value != "" && getActiveFeedId()) {
256 searchbox.value = "";
257 viewfeed(getActiveFeedId(), 0, "");
262 viewCurrentFeed(0, "");
265 function localPiggieFunction(enable) {
267 var query_str = "backend.php?op=feeds&subop=piggie";
269 if (xmlhttp_ready(xmlhttp)) {
271 xmlhttp.open("GET", query_str, true);
272 xmlhttp.onreadystatechange=feedlist_callback;
278 function localHotkeyHandler(keycode) {
280 /* if (keycode == 78) {
281 return moveToPost('next');
285 return moveToPost('prev');
288 if (keycode == 82) { // r
289 return scheduleFeedUpdate(true);
292 if (keycode == 85) { // u
293 if (getActiveFeedId()) {
294 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
298 if (keycode == 65) { // a
299 return toggleDispRead();
302 var f_doc = window.frames["feeds-frame"].document;
303 var feedlist = f_doc.getElementById('feedList');
305 if (keycode == 74) { // j
306 var feed = getActiveFeedId();
307 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
308 if (new_feed) viewfeed(new_feed, 0, '');
311 if (keycode == 75) { // k
312 var feed = getActiveFeedId();
313 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
314 if (new_feed) viewfeed(new_feed, 0, '');
317 // notify("KC: " + keycode);
321 function updateTitle(s) {
322 var tmp = "Tiny Tiny RSS";
324 if (s && s.length > 0) {
325 current_subtitle = s;
328 if (global_unread > 0) {
329 tmp = tmp + " (" + global_unread + ")";
333 tmp = tmp + " - " + current_subtitle;
336 if (active_title_text.length > 0) {
337 tmp = tmp + " > " + active_title_text;
340 document.title = tmp;
343 function genericSanityCheck() {
345 if (!xmlhttp) fatalError(1);
347 setCookie("ttrss_vf_test", "TEST");
349 if (getCookie("ttrss_vf_test") != "TEST") {
360 disableContainerChildren("headlinesToolbar", true);
362 if (!genericSanityCheck())
365 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
366 xmlhttp.onreadystatechange=backend_sanity_check_callback;
370 exception_error("init", e);
374 function init_second_stage() {
378 setCookie("ttrss_vf_actfeed", "");
380 updateFeedList(false, false);
381 document.onkeydown = hotkey_handler;
383 var content = document.getElementById("content");
385 if (getCookie("ttrss_vf_vmode")) {
386 var viewbox = document.getElementById("viewbox");
387 viewbox.value = getCookie("ttrss_vf_vmode");
390 if (getCookie("ttrss_vf_limit")) {
391 var limitbox = document.getElementById("limitbox");
392 limitbox.value = getCookie("ttrss_vf_limit");
395 // if (getCookie("ttrss_vf_actfeed")) {
396 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
399 // setTimeout("timeout()", 2*1000);
400 // scheduleFeedUpdate(true);
403 exception_error("init_second_stage", e);
407 function quickMenuGo() {
409 var chooser = document.getElementById("quickMenuChooser");
410 var opid = chooser[chooser.selectedIndex].id;
412 if (opid == "qmcPrefs") {
416 if (opid == "qmcAdvSearch") {
417 displayDlg("search");
421 if (opid == "qmcAddFeed") {
422 displayDlg("quickAddFeed");
426 if (opid == "qmcRemoveFeed") {
427 var actid = getActiveFeedId();
430 notify("Please select some feed first.");
434 displayDlg("quickDelFeed", actid);
438 if (opid == "qmcUpdateFeeds") {
439 scheduleFeedUpdate(true);
443 if (opid == "qmcCatchupAll") {
448 if (opid == "qmcShowOnlyUnread") {
457 if (!xmlhttp_ready(xmlhttp)) {
462 var link = document.getElementById("qafInput");
464 if (link.value.length == 0) {
465 notify("Missing feed URL.");
467 notify("Adding feed...");
469 var feeds_doc = window.frames["feeds-frame"].document;
471 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
473 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
474 param_escape(link.value), true);
475 xmlhttp.onreadystatechange=dlg_frefresh_callback;
483 function displayDlg(id, param) {
487 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
488 param_escape(id) + "¶m=" + param_escape(param), true);
489 xmlhttp.onreadystatechange=dialog_refresh_callback;
494 function closeDlg() {
495 var dlg = document.getElementById("userDlgShadow");
496 dlg.style.display = "none";
499 function qfdDelete(feed_id) {
501 notify("Removing feed...");
503 var feeds_doc = window.frames["feeds-frame"].document;
504 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
506 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
507 xmlhttp.onreadystatechange=dlg_frefresh_callback;
512 function allFeedsMenuGo() {
513 var chooser = document.getElementById("allFeedsChooser");
515 var opname = chooser[chooser.selectedIndex].text;
517 if (opname == "Update") {
518 scheduleFeedUpdate(true);
522 if (opname == "Mark as read") {
527 if (opname == "Show only unread") {
534 function updateFeedTitle(t) {
535 active_title_text = t;
539 function toggleDispRead() {
540 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
542 hide_read_feeds = !hide_read_feeds;
544 var feeds_doc = window.frames["feeds-frame"].document;
546 hideOrShowFeeds(feeds_doc, hide_read_feeds);
548 if (hide_read_feeds) {
549 setCookie("ttrss_vf_hreadf", 1);
551 setCookie("ttrss_vf_hreadf", 0);