2013-10-15 04:38:07 +02:00
|
|
|
Miniflux.Item = (function() {
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function getItemID(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
item_id = item.getAttribute("data-item-id");
|
|
|
|
return item_id;
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
2014-08-11 00:03:48 +02:00
|
|
|
function changeLabel(link)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
if (link && link.hasAttribute("data-reverse-label")) {
|
2013-10-15 04:38:07 +02:00
|
|
|
var content = link.innerHTML;
|
|
|
|
link.innerHTML = link.getAttribute("data-reverse-label");
|
|
|
|
link.setAttribute("data-reverse-label", content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function changeBookmarkLabel(item)
|
2014-08-11 00:03:48 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var link = item.querySelector("a.bookmark");
|
2014-08-11 00:03:48 +02:00
|
|
|
changeLabel(link);
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function changeStatusLabel(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var link = item.querySelector("a.mark");
|
2014-08-11 00:03:48 +02:00
|
|
|
changeLabel(link);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function showItemAsRead(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
if (item.getAttribute("data-hide")) {
|
|
|
|
hideItem(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.setAttribute("data-item-status", "read");
|
|
|
|
changeStatusLabel(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
// Change action
|
|
|
|
var link = item.querySelector("a.mark");
|
|
|
|
if (link) link.setAttribute("data-action", "mark-unread");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function showItemAsUnread(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
if (item.getAttribute("data-hide")) {
|
|
|
|
hideItem(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.setAttribute("data-item-status", "unread");
|
|
|
|
changeStatusLabel(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
// Change action
|
|
|
|
var link = item.querySelector("a.mark");
|
|
|
|
if (link) link.setAttribute("data-action", "mark-read");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideItem(item)
|
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
if (Miniflux.Event.lastEventType !== "mouse") {
|
2014-02-15 03:37:07 +01:00
|
|
|
Miniflux.Nav.SelectNextItem();
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
item.parentNode.removeChild(item);
|
2014-07-26 14:01:25 +02:00
|
|
|
var pageCounter = document.getElementById("page-counter");
|
|
|
|
|
|
|
|
if (pageCounter) {
|
2014-12-04 12:08:17 +01:00
|
|
|
var sectionElement = document.querySelector("section.page");
|
2014-07-26 14:01:25 +02:00
|
|
|
var counter = parseInt(pageCounter.textContent, 10) - 1;
|
2014-08-11 00:03:48 +02:00
|
|
|
var articles = document.getElementsByTagName("article");
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-08-11 00:03:48 +02:00
|
|
|
if (counter === 0 || articles.length === 0) {
|
|
|
|
window.location = location.href;
|
2014-07-26 14:01:25 +02:00
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-07-26 14:01:25 +02:00
|
|
|
pageCounter.textContent = counter;
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-12-04 12:08:17 +01:00
|
|
|
switch (sectionElement.getAttribute("data-item-page")) {
|
2014-08-11 00:03:48 +02:00
|
|
|
case "unread":
|
|
|
|
document.title = "Miniflux (" + counter + ")";
|
2014-09-16 15:14:49 +02:00
|
|
|
document.getElementById("nav-counter").textContent = counter;
|
2014-08-11 00:03:48 +02:00
|
|
|
break;
|
|
|
|
case "feed-items":
|
|
|
|
document.title = "(" + counter + ") " + pageCounter.parentNode.firstChild.nodeValue;
|
|
|
|
break;
|
|
|
|
default:
|
2014-09-16 15:14:49 +02:00
|
|
|
document.title = pageCounter.parentNode.firstChild.nodeValue + " (" + counter + ")";
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function markAsRead(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
request.onload = function() {
|
2014-09-16 20:42:15 +02:00
|
|
|
if (Miniflux.Nav.IsListing()) showItemAsRead(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
};
|
|
|
|
request.open("POST", "?action=mark-item-read&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function markAsUnread(item)
|
2013-10-15 04:38:07 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
request.onload = function() {
|
2014-09-16 20:42:15 +02:00
|
|
|
if (Miniflux.Nav.IsListing()) showItemAsUnread(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
};
|
|
|
|
request.open("POST", "?action=mark-item-unread&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
function markAsRemoved(item)
|
2014-07-26 14:01:25 +02:00
|
|
|
{
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
2014-07-26 14:01:25 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-07-26 14:01:25 +02:00
|
|
|
request.onload = function() {
|
2014-09-16 20:42:15 +02:00
|
|
|
if (Miniflux.Nav.IsListing()) hideItem(item);
|
2014-07-26 14:01:25 +02:00
|
|
|
};
|
|
|
|
request.open("POST", "?action=mark-item-removed&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
}
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
return {
|
|
|
|
MarkAsRead: markAsRead,
|
|
|
|
MarkAsUnread: markAsUnread,
|
2014-07-26 14:01:25 +02:00
|
|
|
MarkAsRemoved: markAsRemoved,
|
2013-10-15 04:38:07 +02:00
|
|
|
SwitchBookmark: function(item) {
|
2014-09-16 20:42:15 +02:00
|
|
|
var item_id = getItemID(item);
|
|
|
|
var value = item.getAttribute("data-item-bookmark") === "1" ? "0" : "1";
|
|
|
|
var request = new XMLHttpRequest();
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
request.onload = function() {
|
2014-12-04 12:08:17 +01:00
|
|
|
var sectionElement = document.querySelector("section.page");
|
|
|
|
|
|
|
|
if (Miniflux.Nav.IsListing() && sectionElement.getAttribute("data-item-page") === "bookmarks") {
|
2014-11-10 18:36:15 +01:00
|
|
|
hideItem(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.setAttribute("data-item-bookmark", value);
|
|
|
|
|
|
|
|
if (Miniflux.Nav.IsListing()) {
|
|
|
|
changeBookmarkLabel(item);
|
|
|
|
}
|
2014-12-02 17:08:52 +01:00
|
|
|
else {
|
|
|
|
var link = item.querySelector("a.bookmark-icon");
|
|
|
|
if (link && link.hasAttribute("data-reverse-title")) {
|
|
|
|
var title = link.getAttribute("title");
|
2014-12-24 04:13:23 +01:00
|
|
|
|
2014-12-02 17:08:52 +01:00
|
|
|
link.setAttribute("title", link.getAttribute("data-reverse-title"));
|
|
|
|
link.setAttribute("data-reverse-title", title);
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 18:36:15 +01:00
|
|
|
}
|
2014-09-16 20:42:15 +02:00
|
|
|
};
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
request.open("POST", "?action=bookmark&id=" + item_id + "&value=" + value, true);
|
|
|
|
request.send();
|
2013-10-15 04:38:07 +02:00
|
|
|
},
|
|
|
|
SwitchStatus: function(item) {
|
|
|
|
var status = item.getAttribute("data-item-status");
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
if (status === "read") {
|
|
|
|
markAsUnread(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
2014-09-16 20:42:15 +02:00
|
|
|
else if (status === "unread") {
|
|
|
|
markAsRead(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
},
|
2014-09-16 20:42:15 +02:00
|
|
|
Show: function(item) {
|
|
|
|
var link = item.querySelector("a.show");
|
2013-10-15 04:38:07 +02:00
|
|
|
if (link) link.click();
|
|
|
|
},
|
2014-09-16 20:42:15 +02:00
|
|
|
OpenOriginal: function(item) {
|
|
|
|
var link = item.querySelector("a.original");
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
if (link) {
|
2014-09-16 20:42:15 +02:00
|
|
|
if (item.getAttribute("data-item-status") === "unread") markAsRead(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
link.removeAttribute("data-action");
|
|
|
|
link.click();
|
|
|
|
}
|
|
|
|
},
|
2014-09-16 20:42:15 +02:00
|
|
|
DownloadContent: function(item) {
|
2013-10-15 04:38:07 +02:00
|
|
|
var container = document.getElementById("download-item");
|
|
|
|
if (! container) return;
|
|
|
|
|
2014-12-02 16:29:00 +01:00
|
|
|
container.innerHTML = " " + container.getAttribute("data-before-message");
|
|
|
|
container.className = "loading-icon";
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.onload = function() {
|
|
|
|
|
|
|
|
var response = JSON.parse(request.responseText);
|
2014-12-02 16:29:00 +01:00
|
|
|
container.className = "";
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
if (response.result) {
|
|
|
|
var content = document.getElementById("item-content");
|
|
|
|
if (content) content.innerHTML = response.content;
|
2014-12-02 16:29:00 +01:00
|
|
|
|
|
|
|
container.innerHTML = container.getAttribute("data-after-message");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-12-02 16:29:00 +01:00
|
|
|
container.innerHTML = container.getAttribute("data-failure-message");
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
};
|
2014-12-02 16:29:00 +01:00
|
|
|
|
|
|
|
var item_id = getItemID(item);
|
2013-10-15 04:38:07 +02:00
|
|
|
request.open("POST", "?action=download-item&id=" + item_id, true);
|
|
|
|
request.send();
|
|
|
|
},
|
|
|
|
MarkListingAsRead: function(redirect) {
|
|
|
|
var articles = document.getElementsByTagName("article");
|
|
|
|
var listing = [];
|
|
|
|
|
|
|
|
for (var i = 0, ilen = articles.length; i < ilen; i++) {
|
2014-09-16 20:42:15 +02:00
|
|
|
listing.push(getItemID(articles[i]));
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
|
|
|
|
request.onload = function() {
|
|
|
|
window.location.href = redirect;
|
|
|
|
};
|
|
|
|
|
|
|
|
request.open("POST", "?action=mark-items-as-read", true);
|
|
|
|
request.send(JSON.stringify(listing));
|
2014-12-24 04:13:23 +01:00
|
|
|
},
|
|
|
|
ToggleRTLMode: function() {
|
|
|
|
var tags = [
|
|
|
|
"#current-item h1",
|
|
|
|
"#item-content",
|
2014-12-26 10:24:34 +01:00
|
|
|
"#listing #current-item h2",
|
|
|
|
"#listing #current-item .preview"
|
2014-12-24 04:13:23 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
for (var i = 0; i < tags.length; i++) {
|
|
|
|
var tag = document.querySelector(tags[i]);
|
|
|
|
|
|
|
|
if (tag) {
|
|
|
|
tag.dir = tag.dir == "" ? "rtl" : "";
|
|
|
|
}
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|