Add left/right arrow as keyboard shortcuts

This commit is contained in:
Frederic Guillot 2015-01-12 19:46:21 -05:00
parent 6a1515c0cc
commit 84078bb2a5
3 changed files with 55 additions and 27 deletions

37
assets/js/all.min.js vendored
View File

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

View File

@ -2,6 +2,21 @@ Miniflux.Event = (function() {
var queue = [];
function isEventIgnored(e)
{
if (e.keyCode !== 63 && (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
return true;
}
// Do not handle events when there is a focus in form fields
var target = e.target || e.srcElement;
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
return true;
}
return false;
}
return {
lastEventType: "",
ListenMouseEvents: function() {
@ -88,13 +103,7 @@ Miniflux.Event = (function() {
document.onkeypress = function(e) {
if (e.keyCode !== 63 && (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
return;
}
// Do not handle events when there is a focus in form fields
var target = e.target || e.srcElement;
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
if (isEventIgnored(e)) {
return;
}
@ -182,6 +191,24 @@ Miniflux.Event = (function() {
}
}
};
document.onkeydown = function(e) {
if (isEventIgnored(e)) {
return;
}
Miniflux.Event.lastEventType = "keyboard";
switch (e.keyCode || e.which) {
case 37: // left arrow
Miniflux.Nav.SelectPreviousItem();
break;
case 39: // right arrow
Miniflux.Nav.SelectNextItem();
break;
}
}
}
};

View File

@ -8,8 +8,8 @@
<li><?= t('Go to preferences') ?> = <strong>gp</strong></li>
<li><?= t('Update all subscriptions') ?> = <strong>r</strong></li>
<li><?= t('Download content') ?> = <strong>d</strong></li>
<li><?= t('Previous item') ?> = <strong>p</strong> <?= t('or') ?> <strong>j</strong></li>
<li><?= t('Next item') ?> = <strong>n</strong> <?= t('or') ?> <strong>k</strong></li>
<li><?= t('Previous item') ?> = <strong>p</strong> <?= t('or') ?> <strong>j</strong> <?= t('or') ?> <strong>&#9668;</strong></li>
<li><?= t('Next item') ?> = <strong>n</strong> <?= t('or') ?> <strong>k</strong> <?= t('or') ?> <strong>&#9658;</strong></li>
<li><?= t('Mark as read or unread') ?> = <strong>m</strong></li>
<li><?= t('Open original link') ?> = <strong>v</strong></li>
<li><?= t('Open item') ?> = <strong>o</strong></li>