miniflux-legacy/assets/js/all.min.js
Mathias Kresin 3dae99ac27 remove multiple definition of item id
The item id exists as data attribute or as element.id postfix on multiple
elements in an article.

The basic idea is to traverse the DOM tree - starting from the event firing
element - in reverse order till an article element is found.

This article element is passed to the JavaScript functions. These JavaScript
functions are getting the elements which they want to manipulate starting from
the article utilizing the JavaScript querySelector function.

The bootstrap themes had a conflicting and unused class style definied, which is
removed by now.
2014-11-20 10:43:29 +01:00

20 lines
8.6 KiB
JavaScript

var Miniflux={};Miniflux.App=function(){return{BlinkIcon:function(){var e=document.querySelectorAll(".loading-icon");[].forEach.call(e,function(c){c.classList.toggle("loading-icon-blink")})},Run:function(){Miniflux.Event.ListenKeyboardEvents();Miniflux.Event.ListenMouseEvents()}}}();
Miniflux.Feed=function(){function e(d){if(d=document.getElementById("loading-feed-"+d))d.appendChild(document.createTextNode("\u2600")),d.classList.add("loading-icon-blink");g||(g=setInterval(Miniflux.App.BlinkIcon,500))}function c(){for(var d=document.getElementsByTagName("a"),h=0,a=d.length;h<a;h++){var c=d[h].getAttribute("data-feed-id");c&&b.push(parseInt(c))}}var b=[],a=[],g;return{Update:function(d,b){e(d);var a=new XMLHttpRequest;a.onload=function(){var a=document.getElementById("loading-feed-"+
d);a&&(a.innerHTML="");if(a=document.getElementById("last-checked-feed-"+d))a.innerHTML=a.getAttribute("data-after-update");try{var c=JSON.parse(this.responseText);if(c.result){var f=c.items_count,e=document.getElementById("items-count-"+d);e&&(e.innerHTML="("+f.items_unread+"/"+f.items_total+")")}b&&b(c)}catch(g){}};a.open("POST","?action=refresh-feed&feed_id="+d,!0);a.send()},UpdateAll:function(){c();var d=setInterval(function(){for(;0<b.length&&5>a.length;){var h=b.shift();a.push(h);Miniflux.Feed.Update(h,
function(h){h=a.indexOf(h.feed_id);0<=h&&a.splice(h,1);0==b.length&&0==a.length&&(clearInterval(d),clearInterval(g),window.location.href="?action=unread")})}},100)}}}();
Miniflux.Item=function(){function e(d){return item_id=d.getAttribute("data-item-id")}function c(d){if(d&&d.hasAttribute("data-reverse-label")){var b=d.innerHTML;d.innerHTML=d.getAttribute("data-reverse-label");d.setAttribute("data-reverse-label",b)}}function b(d){"mouse"!==Miniflux.Event.lastEventType&&Miniflux.Nav.SelectNextItem();d.parentNode.removeChild(d);var b=document.getElementById("page-counter");if(b){d=d.getAttribute("data-item-page");var a=parseInt(b.textContent,10)-1,c=document.getElementsByTagName("article");
if(0===a||0===c.length)window.location=location.href;b.textContent=a;switch(d){case "unread":document.title="Miniflux ("+a+")";document.getElementById("nav-counter").textContent=a;break;case "feed-items":document.title="("+a+") "+b.parentNode.firstChild.nodeValue;break;default:document.title=b.parentNode.firstChild.nodeValue+" ("+a+")"}}}function a(d){var a=e(d),f=new XMLHttpRequest;f.onload=function(){if(Miniflux.Nav.IsListing())if(d.getAttribute("data-hide"))b(d);else{d.setAttribute("data-item-status",
"read");var a=d.querySelector("a.mark");c(a);(a=d.querySelector("a.mark"))&&a.setAttribute("data-action","mark-unread")}};f.open("POST","?action=mark-item-read&id="+a,!0);f.send()}function g(d){var a=e(d),f=new XMLHttpRequest;f.onload=function(){if(Miniflux.Nav.IsListing())if(d.getAttribute("data-hide"))b(d);else{d.setAttribute("data-item-status","unread");var a=d.querySelector("a.mark");c(a);(a=d.querySelector("a.mark"))&&a.setAttribute("data-action","mark-read")}};f.open("POST","?action=mark-item-unread&id="+
a,!0);f.send()}return{MarkAsRead:a,MarkAsUnread:g,MarkAsRemoved:function(a){var c=e(a),f=new XMLHttpRequest;f.onload=function(){Miniflux.Nav.IsListing()&&b(a)};f.open("POST","?action=mark-item-removed&id="+c,!0);f.send()},SwitchBookmark:function(a){var b=e(a),f="1"===a.getAttribute("data-item-bookmark")?"0":"1",k=new XMLHttpRequest;k.onload=function(){a.setAttribute("data-item-bookmark",f);if(Miniflux.Nav.IsListing()){var b=a.querySelector("a.bookmark");c(b)}};k.open("POST","?action=bookmark&id="+
b+"&value="+f,!0);k.send()},SwitchStatus:function(b){var c=b.getAttribute("data-item-status");"read"===c?g(b):"unread"===c&&a(b)},Show:function(a){(a=a.querySelector("a.show"))&&a.click()},OpenOriginal:function(b){var c=b.querySelector("a.original");c&&("unread"===b.getAttribute("data-item-status")&&a(b),c.removeAttribute("data-action"),c.click())},DownloadContent:function(a){var b=document.getElementById("download-item");if(b){a=e(a);var c=b.getAttribute("data-before-message"),k=document.createElement("span");
k.appendChild(document.createTextNode("\u2600"));k.className="loading-icon";b.innerHTML="";b.className="downloading";b.appendChild(k);b.appendChild(document.createTextNode(" "+c));var g=setInterval(Miniflux.App.BlinkIcon,250),l=new XMLHttpRequest;l.onload=function(){var a=JSON.parse(l.responseText);clearInterval(g);if(a.result){var c=document.getElementById("item-content");c&&(c.innerHTML=a.content);b&&(a=b.getAttribute("data-after-message"),b.innerHTML="",b.appendChild(document.createTextNode(" "+
a)))}else b&&(a=b.getAttribute("data-failure-message"),b.innerHTML="",b.appendChild(document.createTextNode(" "+a)))};l.open("POST","?action=download-item&id="+a,!0);l.send()}},MarkListingAsRead:function(b){for(var a=document.getElementsByTagName("article"),c=[],g=0,m=a.length;g<m;g++)c.push(e(a[g]));a=new XMLHttpRequest;a.onload=function(){window.location.href=b};a.open("POST","?action=mark-items-as-read",!0);a.send(JSON.stringify(c))}}}();
Miniflux.Event=function(){var e=[];return{lastEventType:"",ListenMouseEvents:function(){document.onclick=function(c){var b=c.target.getAttribute("data-action");if(b){Miniflux.Event.lastEventType="mouse";var a;a:{for(element=c.target;element&&element.parentNode;)if(element=element.parentNode,element.tagName&&"article"===element.tagName.toLowerCase()){a=element;break a}a=null}switch(b){case "refresh-all":c.preventDefault();Miniflux.Feed.UpdateAll();break;case "refresh-feed":c.preventDefault();Miniflux.Feed.Update(c.target.getAttribute("data-feed-id"));
break;case "mark-read":c.preventDefault();Miniflux.Item.MarkAsRead(a);break;case "mark-unread":c.preventDefault();Miniflux.Item.MarkAsUnread(a);break;case "mark-removed":c.preventDefault();Miniflux.Item.MarkAsRemoved(a);break;case "bookmark":c.preventDefault();Miniflux.Item.SwitchBookmark(a);break;case "download-item":c.preventDefault();Miniflux.Item.DownloadContent(a);break;case "original-link":c.preventDefault();Miniflux.Item.OpenOriginal(a);break;case "mark-all-read":c.preventDefault();Miniflux.Item.MarkListingAsRead("?action=unread");
break;case "mark-feed-read":c.preventDefault(),Miniflux.Item.MarkListingAsRead("?action=feed-items&feed_id="+c.target.getAttribute("data-feed-id"))}}}},ListenKeyboardEvents:function(){document.onkeypress=function(c){if(!(c.ctrlKey||c.shiftKey||c.altKey||c.metaKey)){var b=c.target||c.srcElement;if("INPUT"!=b.tagName&&"TEXTAREA"!=b.tagName)if(Miniflux.Event.lastEventType="keyboard",e.push(c.keyCode||c.which),103===e[0])switch(e[1]){case void 0:break;case 117:window.location.href="?action=unread";e=
[];break;case 98:window.location.href="?action=bookmarks";e=[];break;case 104:window.location.href="?action=history";e=[];break;case 115:window.location.href="?action=feeds";e=[];break;case 112:window.location.href="?action=config";e=[];break;default:e=[]}else switch(e=[],b=document.getElementById("current-item"),c.keyCode||c.which){case 100:Miniflux.Item.DownloadContent(b);break;case 112:case 107:Miniflux.Nav.SelectPreviousItem();break;case 110:case 106:Miniflux.Nav.SelectNextItem();break;case 118:Miniflux.Item.OpenOriginal(b);
break;case 111:Miniflux.Item.Show(b);break;case 109:Miniflux.Item.SwitchStatus(b);break;case 102:Miniflux.Item.SwitchBookmark(b);break;case 104:Miniflux.Nav.OpenPreviousPage();break;case 108:Miniflux.Nav.OpenNextPage();break;case 114:Miniflux.Feed.UpdateAll();break;case 63:Miniflux.Nav.ShowHelp()}}}}}}();
Miniflux.Nav=function(){function e(b){var a=pageYOffset+document.documentElement.clientHeight;(0>a-(b.offsetTop+b.offsetHeight)||a-b.offsetTop>document.documentElement.clientHeight)&&window.scrollTo(0,b.offsetTop-10)}function c(){return document.getElementById("listing")?!0:!1}return{OpenNextPage:function(){var b=document.getElementById("next-page");b&&b.click()},OpenPreviousPage:function(){var b=document.getElementById("previous-page");b&&b.click()},SelectNextItem:function(){var b=document.getElementById("next-item");
if(b)b.click();else if(c())if(b=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var a=0,g=b.length;a<g;a++){if("current-item"==b[a].id){b[a].id="item-"+b[a].getAttribute("data-item-id");a+1<g&&(b[a+1].id="current-item",e(b[a+1]));break}}else b[0].id="current-item",e(b[0])},SelectPreviousItem:function(){var b=document.getElementById("previous-item");if(b)b.click();else if(c())if(b=document.getElementsByTagName("article"),document.getElementById("current-item"))for(var a=
b.length-1;0<=a;a--){if("current-item"==b[a].id){b[a].id="item-"+b[a].getAttribute("data-item-id");0<=a-1&&(b[a-1].id="current-item",e(b[a-1]));break}}else b[b.length-1].id="current-item",e(b[b.length-1])},ShowHelp:function(){open("?action=show-help","Help","width=320,height=450,location=no,scrollbars=no,status=no,toolbar=no")},IsListing:c}}();Miniflux.App.Run();