2013-10-15 04:38:07 +02:00
|
|
|
Miniflux.Event = (function() {
|
|
|
|
|
|
|
|
var queue = [];
|
|
|
|
|
2015-01-13 01:46:21 +01:00
|
|
|
function isEventIgnored(e)
|
|
|
|
{
|
2015-01-15 02:00:17 +01:00
|
|
|
if (e.keyCode !== 63 && e.which !== 63 && (e.ctrlKey || e.shiftKey || e.altKey || e.metaKey)) {
|
2015-01-13 01:46:21 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
return {
|
2014-02-15 03:37:07 +01:00
|
|
|
lastEventType: "",
|
2013-10-15 04:38:07 +02:00
|
|
|
ListenMouseEvents: function() {
|
|
|
|
|
|
|
|
document.onclick = function(e) {
|
2015-01-03 00:49:29 +01:00
|
|
|
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;
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
|
2015-01-02 18:43:17 +01:00
|
|
|
// Auto-select input content
|
|
|
|
|
2015-01-03 00:49:29 +01:00
|
|
|
if (e.target.nodeName === "INPUT" && e.target.className === "auto-select") {
|
2015-01-02 18:43:17 +01:00
|
|
|
e.target.select();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Application actions
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
var action = e.target.getAttribute("data-action");
|
|
|
|
|
|
|
|
if (action) {
|
|
|
|
|
2014-02-15 03:37:07 +01:00
|
|
|
Miniflux.Event.lastEventType = "mouse";
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
var currentItem = function () {
|
|
|
|
element = e.target;
|
|
|
|
|
|
|
|
while (element && element.parentNode) {
|
|
|
|
element = element.parentNode;
|
|
|
|
if (element.tagName && element.tagName.toLowerCase() === 'article') {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-15 02:00:17 +01:00
|
|
|
return;
|
2014-09-16 20:42:15 +02:00
|
|
|
}();
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
switch (action) {
|
|
|
|
case 'refresh-all':
|
|
|
|
Miniflux.Feed.UpdateAll();
|
|
|
|
break;
|
|
|
|
case 'refresh-feed':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Feed.Update(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 'mark-read':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.MarkAsRead(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 'mark-unread':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.MarkAsUnread(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
2014-07-26 14:01:25 +02:00
|
|
|
case 'mark-removed':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.MarkAsRemoved(currentItem);
|
2014-07-26 14:01:25 +02:00
|
|
|
break;
|
2013-10-15 04:38:07 +02:00
|
|
|
case 'bookmark':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.SwitchBookmark(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 'download-item':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.DownloadContent(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 'original-link':
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.OpenOriginal(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 'mark-all-read':
|
|
|
|
Miniflux.Item.MarkListingAsRead("?action=unread");
|
|
|
|
break;
|
|
|
|
case 'mark-feed-read':
|
|
|
|
Miniflux.Item.MarkListingAsRead("?action=feed-items&feed_id=" + e.target.getAttribute("data-feed-id"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
ListenKeyboardEvents: function() {
|
|
|
|
|
|
|
|
document.onkeypress = function(e) {
|
|
|
|
|
2015-01-13 01:46:21 +01:00
|
|
|
if (isEventIgnored(e)) {
|
2014-10-26 15:27:27 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-09-05 11:30:40 +02:00
|
|
|
|
2014-02-15 03:37:07 +01:00
|
|
|
Miniflux.Event.lastEventType = "keyboard";
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
queue.push(e.keyCode || e.which);
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
if (queue[0] === 103) { // g
|
2013-10-15 04:38:07 +02:00
|
|
|
|
|
|
|
switch (queue[1]) {
|
|
|
|
case undefined:
|
|
|
|
break;
|
|
|
|
case 117: // u
|
|
|
|
window.location.href = "?action=unread";
|
|
|
|
queue = [];
|
|
|
|
break;
|
|
|
|
case 98: // b
|
|
|
|
window.location.href = "?action=bookmarks";
|
|
|
|
queue = [];
|
|
|
|
break;
|
|
|
|
case 104: // h
|
|
|
|
window.location.href = "?action=history";
|
|
|
|
queue = [];
|
|
|
|
break;
|
|
|
|
case 115: // s
|
|
|
|
window.location.href = "?action=feeds";
|
|
|
|
queue = [];
|
|
|
|
break;
|
|
|
|
case 112: // p
|
|
|
|
window.location.href = "?action=config";
|
|
|
|
queue = [];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
queue = [];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
queue = [];
|
|
|
|
|
2014-09-16 20:42:15 +02:00
|
|
|
var currentItem = function () {
|
|
|
|
return document.getElementById("current-item");
|
|
|
|
}();
|
|
|
|
|
2013-10-15 04:38:07 +02:00
|
|
|
switch (e.keyCode || e.which) {
|
|
|
|
case 100: // d
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.DownloadContent(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 112: // p
|
|
|
|
case 107: // k
|
|
|
|
Miniflux.Nav.SelectPreviousItem();
|
|
|
|
break;
|
|
|
|
case 110: // n
|
|
|
|
case 106: // j
|
|
|
|
Miniflux.Nav.SelectNextItem();
|
|
|
|
break;
|
|
|
|
case 118: // v
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.OpenOriginal(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 111: // o
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.Show(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 109: // m
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.SwitchStatus(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 102: // f
|
2015-01-15 02:00:17 +01:00
|
|
|
currentItem && Miniflux.Item.SwitchBookmark(currentItem);
|
2013-10-15 04:38:07 +02:00
|
|
|
break;
|
|
|
|
case 104: // h
|
|
|
|
Miniflux.Nav.OpenPreviousPage();
|
|
|
|
break
|
|
|
|
case 108: // l
|
|
|
|
Miniflux.Nav.OpenNextPage();
|
|
|
|
break;
|
2013-10-31 20:27:33 +01:00
|
|
|
case 114: // r
|
2014-09-16 20:42:15 +02:00
|
|
|
Miniflux.Feed.UpdateAll();
|
|
|
|
break;
|
2013-10-15 04:38:07 +02:00
|
|
|
case 63: // ?
|
|
|
|
Miniflux.Nav.ShowHelp();
|
|
|
|
break;
|
2014-12-24 04:13:23 +01:00
|
|
|
case 122: // z
|
|
|
|
Miniflux.Item.ToggleRTLMode();
|
|
|
|
break;
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 00:49:29 +01:00
|
|
|
};
|
2015-01-13 01:46:21 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2013-10-15 04:38:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-31 20:27:33 +01:00
|
|
|
})();
|