]>
git.wh0rd.org - tt-rss.git/blob - mobile/mobile.js
1 var backend
= "backend.php";
3 function toggleMarked(id
, elem
) {
7 if (elem
.getAttribute("toggled") == "true") {
13 var query
= "?op=toggleMarked&id=" + id
+ "&mark=" + toggled
;
15 new Ajax
.Request(backend
, {
17 onComplete: function (transport
) {
22 function togglePublished(id
, elem
) {
26 if (elem
.getAttribute("toggled") == "true") {
32 var query
= "?op=togglePublished&id=" + id
+ "&mark=" + toggled
;
34 new Ajax
.Request(backend
, {
36 onComplete: function (transport
) {
42 function setPref(elem
) {
46 if (elem
.getAttribute("toggled") == "true") {
52 var query
= "?op=setPref&id=" + id
+ "&to=" + toggled
;
54 new Ajax
.Request(backend
, {
56 onComplete: function (transport
) {
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
72 iui
.showPage($("feed-"+feed_id
), true);
75 if (index
>= links
.length
) {
76 showRestOfFeed(feed_id
);
79 console
.log(links
[index
]);
80 var match
= links
[index
].href
.match(/.*article\.php\?(.*)/);
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
);
91 function goPrev(article_id
, feed_id
, link
) {
92 return goToSibling(article_id
, feed_id
, link
, -1);
94 function goNext(article_id
, feed_id
, link
) {
95 return goToSibling(article_id
, feed_id
, link
, 1);
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
;
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
]);
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";
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"
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
);
140 iui
.showPage($("home"), true);