Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a11y: entry stream pagination #1135

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"object-curly-newline": ["error", {"multiline": true, "consistent": true}],
"one-var-declaration-per-line": "error",
"quotes": ["error", "single", {"avoidEscape": true}],
"radix": "error",
"semi": "error",
"semi-spacing": "error",
"space-before-blocks": "error",
Expand Down
8 changes: 8 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,14 @@ input {
display:none;
}

#stream-pagination {
text-align: center;
}

#stream-pagination li {
display: inline;
}

#fullscreen-entry {
display:none;
}
Expand Down
4 changes: 2 additions & 2 deletions public/js/selfoss-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ var selfoss = {
if (ids.length === 0 && selfoss.filter.type == 'unread') {
$('.entry').remove();
if (selfoss.filter.type == 'unread' &&
parseInt($('.unread-count .count').html()) > 0) {
parseInt($('.unread-count .count').html(), 10) > 0) {
selfoss.db.reloadList();
} else {
selfoss.ui.refreshStreamButtons(true);
Expand All @@ -517,7 +517,7 @@ var selfoss = {

selfoss.ui.beforeReloadList(true);

var unreadstats = parseInt($('.nav-filter-unread span.count').html()) -
var unreadstats = parseInt($('.nav-filter-unread span.count').html(), 10) -
ids.length;
var displayed = false;
var displayNextUnread = function() {
Expand Down
22 changes: 15 additions & 7 deletions public/js/selfoss-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ selfoss.dbOnline = {
unreadCount = data.stats.unread;
} else {
unreadCount = parseInt($('.unread-count .count')
.html());
.html(), 10);
}
if (unreadCount > $('.entry.unread').length) {
$('.stream-more').show();
Expand Down Expand Up @@ -392,7 +392,7 @@ selfoss.dbOffline = {
.then(function() {
var offlineDays = window.localStorage.getItem('offlineDays');
if (offlineDays !== null) {
selfoss.dbOffline.offlineDays = parseInt(offlineDays);
selfoss.dbOffline.offlineDays = parseInt(offlineDays, 10);
}
// The newest garbage collected entry is either what's already
// in the offline db or if more recent the entry older than
Expand Down Expand Up @@ -559,19 +559,27 @@ selfoss.dbOffline = {
var isMore = false;
var alwaysInDb = selfoss.filter.type === 'starred'
|| selfoss.filter.type === 'unread';
var offset = selfoss.filter.offset;

entries.filter(function(entry) {
var keepEntry = false;

if (selfoss.filter.extraIds.indexOf(entry.id) > -1) {
return true;
}

if (selfoss.filter.type == 'starred') {
return entry.starred;
keepEntry = entry.starred;
} else if (selfoss.filter.type == 'unread') {
return entry.unread;
keepEntry = entry.unread;
}

if (keepEntry && offset > 0) {
offset = offset - 1;
return false;
}

return true;
return keepEntry;
}).until(function(entry) {
// stop iteration if enough entries have been shown
// go one further to assess if has more
Expand Down Expand Up @@ -679,7 +687,7 @@ selfoss.dbOffline = {
var d = new Date().toISOString();
statuses.forEach(function(newStatus) {
newQueuedStatuses.push({
entryId: parseInt(newStatus.entryId),
entryId: parseInt(newStatus.entryId, 10),
name: newStatus.name,
value: newStatus.value,
datetime: d
Expand Down Expand Up @@ -758,7 +766,7 @@ selfoss.dbOffline = {
}
});

var id = parseInt(itemStatus.id);
var id = parseInt(itemStatus.id, 10);
selfoss.db.storage.entries.get(id).then(function() {
selfoss.db.storage.entries.update(id, newStatus);
}, function() {
Expand Down
7 changes: 7 additions & 0 deletions public/js/selfoss-events-entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ selfoss.events.entries = function() {
});
}

// stream pagination buttons
$('#stream-pagination button').unbind('click').click(function() {
var pageNumber = parseInt($(this).html(), 10);
selfoss.filter.offset = (pageNumber - 1) * selfoss.filter.itemsPerPage;
selfoss.db.reloadList();
});

// click a tag
if (selfoss.isSmartphone() == false) {
$('.entry-tags-tag').unbind('click').click(function() {
Expand Down
4 changes: 2 additions & 2 deletions public/js/selfoss-events-entriestoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ selfoss.events.entriesToolbar = function(parent) {

// update statistics in main menue
var updateStats = function(starr) {
var starred = parseInt($('.nav-filter-starred span.count').html());
var starred = parseInt($('.nav-filter-starred span.count').html(), 10);
if (starr) {
starred++;
} else {
Expand Down Expand Up @@ -128,7 +128,7 @@ selfoss.events.entriesToolbar = function(parent) {
// update statistics in main menue and the currently active tag
var updateStats = function(unread) {
// update all unread counters
var unreadstats = parseInt($('.nav-filter-unread span.count').html());
var unreadstats = parseInt($('.nav-filter-unread span.count').html(), 10);
var diff = unread ? -1 : 1;

selfoss.refreshUnread(unreadstats + diff);
Expand Down
4 changes: 2 additions & 2 deletions public/js/selfoss-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ selfoss.events = {
+ '/' + selfoss.events.subsection;

var entryId = null;
if (hashPath.length > 2 && (entryId = parseInt(hashPath[2]))) {
if (hashPath.length > 2 && (entryId = parseInt(hashPath[2], 10))) {
selfoss.events.entryId = entryId;
} else {
selfoss.events.entryId = null;
Expand Down Expand Up @@ -168,7 +168,7 @@ selfoss.events = {
if (selfoss.events.subsection.substr(0, 4) == 'tag-') {
selfoss.filter.tag = selfoss.events.subsection.substr(4);
} else if (selfoss.events.subsection.substr(0, 7) == 'source-') {
var sourceId = parseInt(selfoss.events.subsection.substr(7));
var sourceId = parseInt(selfoss.events.subsection.substr(7), 10);
if (sourceId) {
selfoss.filter.source = sourceId;
selfoss.filter.sourcesNav = true;
Expand Down
50 changes: 44 additions & 6 deletions public/js/selfoss-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ selfoss.ui = {


refreshTitle: function(unread) {
unread = (typeof unread !== 'undefined') ? unread : parseInt($('.unread-count .count').html());
unread = (typeof unread !== 'undefined') ? unread : parseInt($('.unread-count .count').html(), 10);

if (unread > 0) {
$(document).attr('title', selfoss.htmlTitle + ' (' + unread + ')');
Expand Down Expand Up @@ -129,6 +129,7 @@ selfoss.ui = {
hasMore = (typeof hasMore !== 'undefined') ? hasMore : false;

$('.stream-button, .stream-empty').css('display', 'block').hide();
$('#stream-pagination').hide();
if (entries) {
if ($('.entry').not('.fullscreen').length > 0) {
$('.stream-empty').hide();
Expand All @@ -138,6 +139,10 @@ selfoss.ui = {
if (hasMore) {
$('.stream-more').show();
}

if ($('#config').data('auto_stream_more') == 0) {
selfoss.ui.refreshStreamPagination();
}
} else {
$('.stream-empty').show();
if (selfoss.isSmartphone()) {
Expand All @@ -148,6 +153,39 @@ selfoss.ui = {
},


refreshStreamPagination: function() {
var streamPagination = $('#stream-pagination').empty();

var pageButtonsAmount = 5;
var count = parseInt($('.nav-filter-' + selfoss.filter.type +
' span.count').html(), 10);
var currentPage = selfoss.filter.offset / selfoss.filter.itemsPerPage + 1;
var lastPage = count / selfoss.filter.itemsPerPage;
var maxPageDistance = pageButtonsAmount / 2;

for (var pageNumber = 1; pageNumber <= lastPage; pageNumber++) {
var currentPageDistance = Math.abs(pageNumber - currentPage);
if (pageNumber == 1 || pageNumber == lastPage ||
currentPageDistance < maxPageDistance) {

var currentAttr = '';
var current = '';
if (pageNumber == currentPage) {
currentAttr = ' aria-current="true"';
current = ' (' + selfoss.ui._('page_current') + ')';
}
streamPagination.append('<li><button aria-label="' + selfoss.ui._('page_goto', [pageNumber]) + current + '"' + currentAttr + '>' + pageNumber + current + '</button></li>');
} else if (pageNumber == 2) {
streamPagination.append('<li>...</li>');
} else if (pageNumber == lastPage - 1) {
streamPagination.append('<li>...</li>');
}
}

$('#stream-pagination').show();
},


beforeReloadList: function(clear) {
clear = (typeof clear !== 'undefined') ? clear : true;

Expand Down Expand Up @@ -226,7 +264,7 @@ selfoss.ui = {
case ',':
if (placeholder) {
if (state == 'index') {
placeholder.index = parseInt(buffer.trim());
placeholder.index = parseInt(buffer.trim(), 10);
placeholder.value = params[placeholder.index];
buffer = '';
} else if (state == 'type') {
Expand Down Expand Up @@ -398,7 +436,7 @@ selfoss.ui = {
var unreadCount = 0;
if (diff) {
if (tagsCountEl.html() != '') {
unreadCount = parseInt(tagsCountEl.html());
unreadCount = parseInt(tagsCountEl.html(), 10);
}
unreadCount = unreadCount + tagCount.count;
} else {
Expand All @@ -420,7 +458,7 @@ selfoss.ui = {
var unreadCount = 0;
if (diff) {
if (sourcesCountEl.html() != '') {
unreadCount = parseInt(sourcesCountEl.html());
unreadCount = parseInt(sourcesCountEl.html(), 10);
}
unreadCount = unreadCount + sourceCount.count;
} else {
Expand Down Expand Up @@ -450,12 +488,12 @@ selfoss.ui = {
var offlineWidget = $('span.offline-count', widget);

if (offlineCounts[ck] == 'keep') {
offlineCounts[ck] = parseInt(offlineWidget.html());
offlineCounts[ck] = parseInt(offlineWidget.html(), 10);
} else {
offlineWidget.html(offlineCounts[ck]);
}

if (parseInt($('span.count', widget).html()) !=
if (parseInt($('span.count', widget).html(), 10) !=
offlineCounts[ck]) {
offlineWidget.addClass('diff');
} else {
Expand Down
2 changes: 2 additions & 0 deletions public/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"lang_source_refresh": "Refresh this source",
"lang_no_entries": "No entries found",
"lang_more": "More",
"lang_page_current": "current",
"lang_page_goto": "Goto page {0}",
"lang_login": "Log in",
"lang_login_username": "Username",
"lang_login_password": "Password",
Expand Down
2 changes: 2 additions & 0 deletions public/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"lang_source_refresh": "Rafraîchir cette source",
"lang_no_entries": "Aucun article à consulter",
"lang_more": "Plus",
"lang_page_current": "celle-ci",
"lang_page_goto": "Aller à la page {0}",
"lang_login": "Connexion",
"lang_login_username": "Identifiant",
"lang_login_password": "Mot de passe",
Expand Down
7 changes: 6 additions & 1 deletion templates/home.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
data-error_invalid_subsection="<?= \F3::get('lang_error_invalid_subsection'); ?>"
data-seconds="<?= \F3::get('lang_seconds'); ?>"
data-minutes="<?= \F3::get('lang_minutes'); ?>"
data-hours="<?= \F3::get('lang_hours'); ?>"></span>
data-hours="<?= \F3::get('lang_hours'); ?>"
data-page_current="<?= \F3::get('lang_page_current'); ?>"
data-page_goto="<?= \F3::get('lang_page_goto'); ?>"></span>

<!-- other settings -->
<span id="config"
Expand Down Expand Up @@ -204,6 +206,9 @@
<button class="stream-button stream-more"><span><?= trim(\F3::get('lang_more')); ?></span></button>
<button class="stream-button mark-these-read"><span><?= trim(\F3::get('lang_markread')); ?></span></button>
<button class="stream-button stream-error"><?= trim(\F3::get('lang_streamerror')); ?></button>
<nav role="navigation" aria-label="Pagination Navigation">
<ul id="stream-pagination"></ul>
</nav>
</div>

<!-- fullscreen popup -->
Expand Down