mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-05-07 10:34:06 +02:00
Fix various keyboard navigation issues
Signed-off-by: Rhys Tyers <mail@rhy.si>
This commit is contained in:
parent
cbcf87f4ea
commit
a50d0a427d
@ -34,6 +34,10 @@ app.config(function ($routeProvider, $provide, $httpProvider, $locationProvider)
|
|||||||
$provide.constant('MARK_READ_TIMEOUT', 0.5);
|
$provide.constant('MARK_READ_TIMEOUT', 0.5);
|
||||||
$provide.constant('SCROLL_TIMEOUT', 0.1);
|
$provide.constant('SCROLL_TIMEOUT', 0.1);
|
||||||
|
|
||||||
|
const majorVersion = parseInt($('#app-content').data('nc-major-version') || 0, 10);
|
||||||
|
$provide.constant('NC_MAJOR_VERSION', majorVersion);
|
||||||
|
window.NEWS_NC_MAJOR_VERSION = majorVersion;
|
||||||
|
|
||||||
// make sure that the CSRF header is only sent to the Nextcloud domain
|
// make sure that the CSRF header is only sent to the Nextcloud domain
|
||||||
$provide.factory('CSRFInterceptor', function ($q, BASE_URL, $window) {
|
$provide.factory('CSRFInterceptor', function ($q, BASE_URL, $window) {
|
||||||
return {
|
return {
|
||||||
|
@ -8,21 +8,17 @@
|
|||||||
* @copyright Bernhard Posselt 2014
|
* @copyright Bernhard Posselt 2014
|
||||||
*/
|
*/
|
||||||
app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE,
|
app.directive('newsScroll', function ($timeout, ITEM_AUTO_PAGE_SIZE,
|
||||||
MARK_READ_TIMEOUT, SCROLL_TIMEOUT) {
|
MARK_READ_TIMEOUT, SCROLL_TIMEOUT, NC_MAJOR_VERSION) {
|
||||||
'use strict';
|
'use strict';
|
||||||
var timer;
|
var timer;
|
||||||
|
|
||||||
|
|
||||||
var scrollElement = function() {
|
var scrollElement = function() {
|
||||||
const appContentElem = $('#app-content');
|
// This should be in sync with the same function in js/gui/KeyboardShortcuts.js
|
||||||
const majorVersion = parseInt($('#app-content').data('nc-major-version') || 0, 10);
|
if (NC_MAJOR_VERSION >= 25) {
|
||||||
if (majorVersion >= 25) {
|
return $('#app-content');
|
||||||
return appContentElem;
|
|
||||||
}
|
}
|
||||||
if (majorVersion === 24) {
|
return $(window);
|
||||||
return $(window);
|
|
||||||
}
|
|
||||||
return $('html');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// autopaging
|
// autopaging
|
||||||
|
@ -16,6 +16,14 @@
|
|||||||
(function (window, document, $) {
|
(function (window, document, $) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var scrollElement = function() {
|
||||||
|
// This should be in sync with the same function in js/directive/NewsScroll.js
|
||||||
|
if (window.NEWS_NC_MAJOR_VERSION >= 25) {
|
||||||
|
return $('#app-content');
|
||||||
|
}
|
||||||
|
return $(window);
|
||||||
|
};
|
||||||
|
|
||||||
var noInputFocused = function (element) {
|
var noInputFocused = function (element) {
|
||||||
return !(
|
return !(
|
||||||
element.is('input') ||
|
element.is('input') ||
|
||||||
@ -223,34 +231,34 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var getActiveElement = function (scrollArea) {
|
var getActiveElement = function () {
|
||||||
return scrollArea.find('.item.active:first');
|
return $('#app-content').find('.item.active:first');
|
||||||
};
|
};
|
||||||
|
|
||||||
var onActiveItem = function (scrollArea, callback) {
|
var onActiveItem = function (callback) {
|
||||||
callback(getActiveElement(scrollArea));
|
callback(getActiveElement());
|
||||||
};
|
};
|
||||||
|
|
||||||
var toggleUnread = function (scrollArea) {
|
var toggleUnread = function () {
|
||||||
onActiveItem(scrollArea, function (item) {
|
onActiveItem(function (item) {
|
||||||
item.find('.toggle-keep-unread').trigger('click');
|
item.find('.toggle-keep-unread').trigger('click');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var toggleStar = function (scrollArea) {
|
var toggleStar = function () {
|
||||||
onActiveItem(scrollArea, function (item) {
|
onActiveItem(function (item) {
|
||||||
item.find('.star').trigger('click');
|
item.find('.star').trigger('click');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var expandItem = function (scrollArea) {
|
var expandItem = function () {
|
||||||
onActiveItem(scrollArea, function (item) {
|
onActiveItem(function (item) {
|
||||||
item.find('.utils').trigger('click');
|
item.find('.utils').trigger('click');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
var openLink = function (scrollArea) {
|
var openLink = function () {
|
||||||
onActiveItem(scrollArea, function (item) {
|
onActiveItem(function (item) {
|
||||||
item.trigger('click'); // mark read
|
item.trigger('click'); // mark read
|
||||||
var url = item.find('.external:visible').attr('href');
|
var url = item.find('.external:visible').attr('href');
|
||||||
var newWindow = window.open(url, '_blank');
|
var newWindow = window.open(url, '_blank');
|
||||||
@ -265,9 +273,14 @@
|
|||||||
var scrollToItem = function (scrollArea, item, expandItemInCompact) {
|
var scrollToItem = function (scrollArea, item, expandItemInCompact) {
|
||||||
// if you go to the next article in compact view, it should
|
// if you go to the next article in compact view, it should
|
||||||
// expand the current one
|
// expand the current one
|
||||||
scrollArea.scrollTop(
|
|
||||||
item.offset().top - 50
|
if (window.NEWS_NC_MAJOR_VERSION >= 25) {
|
||||||
);
|
scrollArea.scrollTop(scrollArea.scrollTop() + item.offset().top - 50);
|
||||||
|
} else {
|
||||||
|
scrollArea.scrollTop(
|
||||||
|
item.offset().top - 50
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
setItemActive(item[0]);
|
setItemActive(item[0]);
|
||||||
|
|
||||||
@ -279,7 +292,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var scrollToNextItem = function (scrollArea, expandItemInCompact) {
|
var scrollToNextItem = function (scrollArea, expandItemInCompact) {
|
||||||
var activeElement = getActiveElement(scrollArea);
|
var activeElement = getActiveElement();
|
||||||
// in expand in compact mode, jumping to the next item should open
|
// in expand in compact mode, jumping to the next item should open
|
||||||
// the current one if it's not open yet
|
// the current one if it's not open yet
|
||||||
if (expandItemInCompact && !activeElement.hasClass('open')) {
|
if (expandItemInCompact && !activeElement.hasClass('open')) {
|
||||||
@ -300,7 +313,7 @@
|
|||||||
|
|
||||||
var scrollToPreviousItem = function (scrollArea,
|
var scrollToPreviousItem = function (scrollArea,
|
||||||
expandItemInCompact) {
|
expandItemInCompact) {
|
||||||
var activeElement = getActiveElement(scrollArea);
|
var activeElement = getActiveElement();
|
||||||
var previousElement = activeElement.prev();
|
var previousElement = activeElement.prev();
|
||||||
|
|
||||||
// if the active element has been scrolled, the previous element
|
// if the active element has been scrolled, the previous element
|
||||||
@ -321,18 +334,19 @@
|
|||||||
items.each(function (index, item) {
|
items.each(function (index, item) {
|
||||||
var $item = $(item);
|
var $item = $(item);
|
||||||
var bottom = $item.position().top + $item.outerHeight(true);
|
var bottom = $item.position().top + $item.outerHeight(true);
|
||||||
if ((bottom - 20) >= 0) {
|
var scrollBottom = scrollElement().scrollTop();
|
||||||
|
if (bottom - 20 >= scrollBottom) {
|
||||||
setItemActive(item);
|
setItemActive(item);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
$('#app-content').scroll(_.debounce(detectAndSetActiveItem, 250));
|
scrollElement().scroll(_.debounce(detectAndSetActiveItem, 250));
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).keyup(function (event) {
|
$(document).keyup(function (event) {
|
||||||
var keyCode = event.keyCode;
|
var keyCode = event.keyCode;
|
||||||
var scrollArea = $(document);
|
var scrollArea = scrollElement();
|
||||||
var navigationArea = $('#app-navigation');
|
var navigationArea = $('#app-navigation');
|
||||||
var isCompactView = $('#articles.compact').length > 0;
|
var isCompactView = $('#articles.compact').length > 0;
|
||||||
var isExpandItem = $('#articles')
|
var isExpandItem = $('#articles')
|
||||||
|
@ -86,6 +86,7 @@ class PageController extends Controller
|
|||||||
$this->appName,
|
$this->appName,
|
||||||
'index',
|
'index',
|
||||||
[
|
[
|
||||||
|
'nc_major_version' => \OCP\Util::getVersion()[0],
|
||||||
'warnings' => $status['warnings'],
|
'warnings' => $status['warnings'],
|
||||||
'url_generator' => $this->urlGenerator
|
'url_generator' => $this->urlGenerator
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user