]> git.wh0rd.org Git - tt-rss.git/blob - mobile/mobile.js
daemon2: properly abort stuck children
[tt-rss.git] / mobile / mobile.js
1 var backend = "backend.php";
2
3 function toggleMarked(id, elem) {
4
5         var toggled = false;
6
7         if (elem.getAttribute("toggled") == "true") {
8                 toggled = 1;
9         } else {
10                 toggled = 0;
11         }
12
13         var query = "?op=toggleMarked&id=" + id + "&mark=" + toggled;
14
15         new Ajax.Request(backend, {
16                 parameters: query,
17                 onComplete: function (transport) {
18                         //
19                 } });
20 }
21
22 function togglePublished(id, elem) {
23
24         var toggled = false;
25
26         if (elem.getAttribute("toggled") == "true") {
27                 toggled = 1;
28         } else {
29                 toggled = 0;
30         }
31
32         var query = "?op=togglePublished&id=" + id + "&mark=" + toggled;
33
34         new Ajax.Request(backend, {
35                 parameters: query,
36                 onComplete: function (transport) {
37                         //
38                 } });
39
40 }
41
42 function setPref(elem) {
43         var toggled = false;
44         var id = elem.id;
45
46         if (elem.getAttribute("toggled") == "true") {
47                 toggled = 1;
48         } else {
49                 toggled = 0;
50         }
51
52         var query = "?op=setPref&id=" + id + "&to=" + toggled;
53
54         new Ajax.Request(backend, {
55                 parameters: query,
56                 onComplete: function (transport) {
57                         //
58                 } });
59
60 }
61
62 // Go directly to another item in the same feed
63 function goToSibling(article_id, feed_id, link, step) {
64     var links = linksInFeed(feed_id);
65     for (var i=0 ; i<links.length ; i++) {
66         var re = new RegExp(".*article\\.php\\?id="+article_id+"&.*");
67         if (!re.test(links[i].href)) continue;
68         // here, we've found the current article
69         var index = i + step;
70         if (index < 0) {
71             markAsRead(feed_id);
72             iui.showPage($("feed-"+feed_id), true);
73             return false;
74         }
75         if (index >= links.length) {
76             showRestOfFeed(feed_id);
77             return false;
78         }
79         console.log(links[index]);
80         var match = links[index].href.match(/.*article\.php\?(.*)/);
81         var qs = match[1];
82         var backwards = false;
83         if (step < 0) backwards = true;
84         link.setAttribute("selected", "progress");
85         function unselect() { link.removeAttribute("selected"); }
86         iui.showPageByHref("article.php?"+qs, null, null, null, unselect, backwards);
87         return false;
88     }
89     return false;
90 }
91 function goPrev(article_id, feed_id, link) {
92     return goToSibling(article_id, feed_id, link, -1);
93 }
94 function goNext(article_id, feed_id, link) {
95     return goToSibling(article_id, feed_id, link, 1);
96 }
97
98 // Get all the links in the feed. The all_links variable includes the "get more article" link
99 function linksInFeed(feed_id, all_links) {
100     var feed_content = $("feed-"+feed_id);
101     var links_raw = feed_content.getElementsByTagName("a");
102     if (all_links) return links_raw;
103     var links = [];
104     // filter the array to remove the "get more articles" link
105     // and the "search" link (which is always first)
106     for (var i=1 ; i<links_raw.length ; i++) {
107         if (links_raw[i].href.match(/.*article\.php\?id=.*/)) {
108             links.push(links_raw[i]);
109         }
110     }
111     return links;
112 }
113
114 // Adds the "read" class to all read links in the feed
115 function markAsRead(feed_id) {
116     var links = linksInFeed(feed_id);
117     for (var j=0 ; j<links.length ; j++) {
118         var match = links[j].href.match(/.*article\.php\?id=(\d+)&.*/);
119         if ($("article-"+match[1])) {
120             links[j].className = "read";
121         }
122     }
123 }
124
125 // Go the the articles list and expand the "get more articles" link
126 function showRestOfFeed(feed_id) {
127     var links_raw = linksInFeed(feed_id, true);
128     var lastlink = links_raw[links_raw.length - 1];
129     if (lastlink.target == "_replace") {
130         // It's a "get more articles" link
131         iui.showPage($("feed-"+feed_id), true);
132         // Mark old items a "read"
133         markAsRead(feed_id);
134         // Simulate click on the "get more articles" link
135         lastlink.setAttribute("selected", "progress");
136         function unselect() { lastlink.removeAttribute("selected"); }
137         setTimeout(window.scrollTo, 0, 0, 1000);
138         iui.showPageByHref(lastlink.href, null, null, lastlink, unselect);
139     } else {
140         iui.showPage($("home"), true);
141     }
142 }