middle mouse button triggers event for all browser

This is a follow up to #1. The onclick event is triggered by different
mouse buttons across browsers:

Firefox
- all mouse buttons trigger document.onclick (https://bugzilla.mozilla.org/show_bug.cgi?id=430310)
- only left mouse button triggers document.body.onclick

Internet Explorer
- only left mouse button and without any modifier key triggers
  document.onclick

Chrome
- left & middle mouse button trigger document.onclick

Safari
- left mouse button triggers document.onclick
- middle click via mac os?

By switching to the onmouseup event this can be unified for all
mentioned browsers to:

- (CTRL+) left click triggers event
- middle click triggers event
- right click does nothing
This commit is contained in:
Mathias Kresin 2015-01-03 00:49:29 +01:00
parent 1e1e35e38c
commit 80952f29b0
2 changed files with 34 additions and 30 deletions

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

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

View File

@ -7,10 +7,23 @@ Miniflux.Event = (function() {
ListenMouseEvents: function() {
document.onclick = function(e) {
var action = e.target.getAttribute("data-action");
if (action && action !== 'original-link') {
e.preventDefault();
}
};
document.onmouseup = function(e) {
// ignore right mouse button (context menu)
if (e.button === 2) {
return;
}
// Auto-select input content
if (e.target.nodeName == "INPUT" && e.target.className == "auto-select") {
if (e.target.nodeName === "INPUT" && e.target.className === "auto-select") {
e.target.select();
return;
}
@ -38,42 +51,33 @@ Miniflux.Event = (function() {
switch (action) {
case 'refresh-all':
e.preventDefault();
Miniflux.Feed.UpdateAll();
break;
case 'refresh-feed':
e.preventDefault();
Miniflux.Feed.Update(currentItem);
break;
case 'mark-read':
e.preventDefault();
Miniflux.Item.MarkAsRead(currentItem);
break;
case 'mark-unread':
e.preventDefault();
Miniflux.Item.MarkAsUnread(currentItem);
break;
case 'mark-removed':
e.preventDefault();
Miniflux.Item.MarkAsRemoved(currentItem);
break;
case 'bookmark':
e.preventDefault();
Miniflux.Item.SwitchBookmark(currentItem);
break;
case 'download-item':
e.preventDefault();
Miniflux.Item.DownloadContent(currentItem);
break;
case 'original-link':
Miniflux.Item.OpenOriginal(currentItem);
break;
case 'mark-all-read':
e.preventDefault();
Miniflux.Item.MarkListingAsRead("?action=unread");
break;
case 'mark-feed-read':
e.preventDefault();
Miniflux.Item.MarkListingAsRead("?action=feed-items&feed_id=" + e.target.getAttribute("data-feed-id"));
break;
}
@ -84,13 +88,13 @@ Miniflux.Event = (function() {
document.onkeypress = function(e) {
if (e.keyCode != 63 && (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
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 (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') {
return;
}
@ -177,7 +181,7 @@ Miniflux.Event = (function() {
break;
}
}
}
};
}
};