miniflux-legacy/assets/js/event.js

346 lines
13 KiB
JavaScript
Raw Normal View History

2013-10-15 04:38:07 +02:00
Miniflux.Event = (function() {
var queue = [];
function isEventIgnored(e)
{
if (e.keyCode !== 63 && e.which !== 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;
2016-07-31 00:21:01 +02:00
return !!(target.tagName === 'INPUT' || target.tagName === 'TEXTAREA');
}
2013-10-15 04:38:07 +02:00
return {
lastEventType: "",
2013-10-15 04:38:07 +02:00
ListenMouseEvents: function() {
document.onclick = function(e) {
if (e.target.hasAttribute("data-action") && e.target.className !== 'original') {
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
// Auto-select input content
if (e.target.nodeName === "INPUT" && e.target.className === "auto-select") {
e.target.select();
return;
}
// Application actions
2013-10-15 04:38:07 +02:00
var action = e.target.getAttribute("data-action");
if (action) {
Miniflux.Event.lastEventType = "mouse";
var currentItem = function () {
2016-07-31 00:21:01 +02:00
var element = e.target;
while (element && element.parentNode) {
element = element.parentNode;
if (element.tagName && element.tagName.toLowerCase() === 'article') {
return element;
}
}
}();
2013-10-15 04:38:07 +02:00
switch (action) {
case 'refresh-all':
Miniflux.Feed.UpdateAll(e.target.getAttribute("data-concurrent-requests"));
2013-10-15 04:38:07 +02:00
break;
case 'refresh-feed':
currentItem && Miniflux.Feed.Update(currentItem);
2013-10-15 04:38:07 +02:00
break;
case 'mark-read':
currentItem && Miniflux.Item.MarkAsRead(currentItem);
2013-10-15 04:38:07 +02:00
break;
case 'mark-unread':
currentItem && Miniflux.Item.MarkAsUnread(currentItem);
2013-10-15 04:38:07 +02:00
break;
case 'mark-removed':
currentItem && Miniflux.Item.MarkAsRemoved(currentItem);
break;
2013-10-15 04:38:07 +02:00
case 'bookmark':
currentItem && Miniflux.Item.SwitchBookmark(currentItem);
2013-10-15 04:38:07 +02:00
break;
case 'download-item':
currentItem && Miniflux.Item.DownloadContent(currentItem);
2013-10-15 04:38:07 +02:00
break;
case 'mark-feed-read':
2015-04-29 11:16:36 +02:00
var feed_id = document.getElementById('listing').getAttribute('data-feed-id');
Miniflux.Item.MarkFeedAsRead(feed_id);
2013-10-15 04:38:07 +02:00
break;
2016-03-06 16:23:19 +01:00
case 'close-help':
Miniflux.Nav.CloseHelp();
break;
2016-05-04 02:15:20 +02:00
case 'show-search':
Miniflux.Nav.ShowSearch();
break;
2013-10-15 04:38:07 +02:00
}
}
};
},
ListenKeyboardEvents: function() {
document.onkeypress = function(e) {
if (isEventIgnored(e)) {
return;
}
Miniflux.Event.lastEventType = "keyboard";
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
queue.push(e.key || e.which);
2013-10-15 04:38:07 +02:00
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
if (queue[0] === 'g' || queue[0] === 103) {
2013-10-15 04:38:07 +02:00
switch (queue[1]) {
case undefined:
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'u':
case 117:
2013-10-15 04:38:07 +02:00
window.location.href = "?action=unread";
queue = [];
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'b':
case 98:
2013-10-15 04:38:07 +02:00
window.location.href = "?action=bookmarks";
queue = [];
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'h':
case 104:
2013-10-15 04:38:07 +02:00
window.location.href = "?action=history";
queue = [];
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 's':
case 115:
2013-10-15 04:38:07 +02:00
window.location.href = "?action=feeds";
queue = [];
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'p':
case 112:
2013-10-15 04:38:07 +02:00
window.location.href = "?action=config";
queue = [];
break;
default:
queue = [];
break;
}
}
else {
queue = [];
var currentItem = function () {
return document.getElementById("current-item");
}();
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
switch (e.key || e.which) {
case 'd':
case 100:
currentItem && Miniflux.Item.DownloadContent(currentItem);
2013-10-15 04:38:07 +02:00
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'p':
case 112:
case 'k':
case 107:
2013-10-15 04:38:07 +02:00
Miniflux.Nav.SelectPreviousItem();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'n':
case 110:
case 'j':
case 106:
2013-10-15 04:38:07 +02:00
Miniflux.Nav.SelectNextItem();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'v':
case 118:
currentItem && Miniflux.Item.OpenOriginal(currentItem);
2013-10-15 04:38:07 +02:00
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'o':
case 111:
currentItem && Miniflux.Item.Show(currentItem);
2013-10-15 04:38:07 +02:00
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'm':
case 109:
currentItem && Miniflux.Item.SwitchStatus(currentItem);
2013-10-15 04:38:07 +02:00
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'f':
case 102:
currentItem && Miniflux.Item.SwitchBookmark(currentItem);
2013-10-15 04:38:07 +02:00
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'h':
case 104:
2013-10-15 04:38:07 +02:00
Miniflux.Nav.OpenPreviousPage();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'l':
case 108:
2013-10-15 04:38:07 +02:00
Miniflux.Nav.OpenNextPage();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'r':
case 114:
Miniflux.Feed.UpdateAll();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case '?':
case 63:
2013-10-15 04:38:07 +02:00
Miniflux.Nav.ShowHelp();
break;
2016-03-06 16:23:19 +01:00
case 'Q':
case 81: // Q
case 'q':
case 113: // q
Miniflux.Nav.CloseHelp();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case 'z':
case 122:
Miniflux.Item.ToggleRTLMode();
break;
2013-10-15 04:38:07 +02:00
}
}
};
document.onkeydown = function(e) {
if (isEventIgnored(e)) {
return;
}
Miniflux.Event.lastEventType = "keyboard";
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
switch (e.key || e.which) {
case "ArrowLeft":
case "Left":
case 37:
Miniflux.Nav.SelectPreviousItem();
break;
use keyboardevent.key if implemented Beside other stuff the main reason for this change is the circumstance that Firefox triggers the "Toggle RTL mode" shortcut if the user press F11 to switch Firefox into the fullscreen mode. Each browser sends keycodes that are used by different other keys on the keyboard for the function keys. Firefox is the only browser which sends the onkeypress event for the function keys. The used keyboard event properties event.keyCode and event.which are already marked as deprecated and has been removed from the Web standards. The "DOM Level 3 Events" standard specifies event.key as their successor. Right now event.key is only available for Firefox 29+ and Internet Explorer 9+. Webkit based browser have support for the former specified event.keyIdentifier. The implementation of event.keyIdentifier isn't the same across different webkit based browsers and buggy: - the value for the z key is F11 (Chrome - Windows, Linux) - the value for the F11 key is F11 as well on (Chrome - Windows, Linux) - the value for latin keys is always the value of the capital letter (Chrome) - the value for cyrillic keys depends on the shift modifier (Chrome) - the value for the keypress event is always an empty string (Safari - Mac OS) - the value for the keydown event matches the keyboard layout dependent character (Safari - Mac OS) - the value for the keydown event does NOT matches the keyboard layout dependent character (Chrome - Windows, Linux) Instead of workaround the problems, the event.which is used for every browser that doesn't support event.key.
2015-03-07 18:23:36 +01:00
case "ArrowRight":
case "Right":
case 39:
Miniflux.Nav.SelectNextItem();
break;
}
implement frontend autoupdate Only the unread counter is updated right know. The AutoUpdate Feature is designed on the premise of don't wasting resources. A distinction is made between updates when Miniflux is visible or hidden. To determine the visibility status, the Page Visibility API is used. The API is available starting with Chrome 33, Firefox 18 and IE10. [https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API] As IE9 returns an undefined, it doesn't break the compatibility at least. If Miniflux is visible, the unread counter on the web page is updated as soon as a mismatch between the counter and the number of unread articles in the database is found. If Miniflux is hidden, the timestamp of the most recent article from each feed is compared with the value from the last run. We have an update If the timestamp of the latest article is greater than the stored one and the latest article is unread. The web page title is updated with a ? symbol to notify the user and the update check pauses till Miniflux gets visible again. If Miniflux gets visible again, the number of unread articles is queried from the database, the unread counter on the web page is updated and finally the ? symbol is removed from the web page title. This way I can use my fever API client to read new articles (or at least the latest article) while Miniflux is hidden and as I've seen the new articles already a new articles notification is prevented. It's intentionally that the page does not reload automatically as long as articles are visible. If I'm in hurry, I only scroll through the articles to spot something interesting. Most of the time I don't reach the last article. If the page is reloaded while I'm away, I would have to scan from the top again. If we're on a nothing_to_read page and have unread articles in the database, a redirect to the unread page will be done. The default update check interval is 10 minutes and can be changed on the settings page. A zero value disables the update check entirely. fixes #213
2014-11-27 22:36:04 +01:00
};
},
ListenVisibilityEvents: function() {
document.addEventListener('visibilitychange', function() {
Miniflux.App.Log('document.visibilityState: ' + document.visibilityState);
if (!document.hidden && Miniflux.Item.hasNewUnread()) {
Miniflux.App.Log('Need to update the unread counter with fresh values from the database');
Miniflux.Item.CheckForUpdates();
}
});
},
ListenTouchEvents: function() {
var touches = null;
var resetTouch = function () {
touches && touches.element && (touches.element.style.opacity = 1);
touches && touches.element && (touches.element.style.transform = "");
touches = {
"touchstart": {"x":-1, "y":-1},
"touchmove" : {"x":-1, "y":-1},
"touchend" : false,
"direction" : "undetermined",
"swipestarted" : false,
2016-07-31 00:21:01 +02:00
"element" : null
};
};
var horizontalSwipe = function () {
if((touches.touchstart.x > -1 && touches.touchmove.x > -1 &&
((touches.touchmove.x - touches.touchstart.x) > 30 | touches.swipestarted) &&
Math.abs(touches.touchmove.y - touches.touchstart.y) < 75)) {
touches.swipestarted = true;
return touches.touchmove.x - touches.touchstart.x;
}
return 0;
};
var closest = function(el, fn) {
return el && (fn(el) ? el : closest(el.parentNode, fn));
};
var getTouchElement = function() {
return touches.element ? touches.element :
closest(document.elementFromPoint(touches.touchstart.x, touches.touchstart.y),
function(el) {
return el.tagName === 'ARTICLE';
});
};
var drawElement = function(){
if(touches &&
(touches.touchend === true || touches.touchstart.x == -1)) {
return;
}
if(touches.element === null) {
touches.element = getTouchElement();
}
2016-07-31 00:21:01 +02:00
var swipedistance = horizontalSwipe();
if(swipedistance > 0) {
var element = getTouchElement();
if(!element) {resetTouch(); return;}
touches.element.style.opacity = 1 -
((swipedistance > 75) ? 0.9 : swipedistance/75 *0.9);
touches.element.style.transform = "translateX("+
(swipedistance > 75 ? 75 : swipedistance)+"px)";
touches.element = element;
}
window.requestAnimationFrame(drawElement);
};
var touchHandler = function (e) {
if (typeof e.touches != 'undefined' && e.touches.length <= 1) {
var touch = e.touches[0];
var swipedistance = null;
var element = null;
switch (e.type) {
case 'touchstart':
resetTouch();
touches[e.type].x = touch.clientX;
touches[e.type].y = touch.clientY;
drawElement();
break;
case 'touchmove':
touches[e.type].x = touch.clientX;
touches[e.type].y = touch.clientY;
break;
case 'touchend':
touches[e.type] = true;
element = getTouchElement();
swipedistance = horizontalSwipe();
if(swipedistance > 75) {
element && Miniflux.Item.MarkAsRead(element);
if(!element.getAttribute("data-hide")){
resetTouch();
}
} else {
resetTouch();
}
break;
case 'touchcancel':
resetTouch();
break;
default:
break;
}
} else {
resetTouch();
}
};
resetTouch();
document.addEventListener('touchstart', touchHandler, false);
document.addEventListener('touchmove', touchHandler, false);
document.addEventListener('touchend', touchHandler, false);
document.addEventListener('touchcancel', touchHandler, false);
2013-10-15 04:38:07 +02:00
}
};
})();