mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Replace link has button role with button tag
# Change HTML tag to button Replace the link tag with an HTML button to prevent some screen readers from having confusing announcements. By using the HTML button, users can use the Enter and Space keys to activate actions by default, instead of implementing them in JavaScript. # Differentiate links and buttons visually When activating the link element, the user may expect the web page to navigate to the URL and the page will refresh; when activating the button element, the user may expect the web page to still be on the same page, so that their current state, such as: input value, won't disappear. Links and buttons should have different styles visually, so that users can't expect what will happen when they activate a link or a button. I added the underline to the links, because that is the common pattern. Buttons have border and background color in a common pattern. But I think that will change the current layout drastically. So I added the focus, hover and active classes to the buttons instead.
This commit is contained in:
parent
0f85c0511a
commit
ea58bac548
15 changed files with 186 additions and 124 deletions
|
@ -135,7 +135,7 @@ function markPageAsRead() {
|
|||
updateEntriesStatus(entryIDs, "read", () => {
|
||||
// Make sure the Ajax request reach the server before we reload the page.
|
||||
|
||||
let element = document.querySelector("a[data-action=markPageAsRead]");
|
||||
let element = document.querySelector(":is(a, button)[data-action=markPageAsRead]");
|
||||
let showOnlyUnread = false;
|
||||
if (element) {
|
||||
showOnlyUnread = element.dataset.showOnlyUnread || false;
|
||||
|
@ -161,7 +161,7 @@ function handleEntryStatus(item, element, setToRead) {
|
|||
let toasting = !element;
|
||||
let currentEntry = findEntry(element);
|
||||
if (currentEntry) {
|
||||
if (!setToRead || currentEntry.querySelector("a[data-toggle-status]").dataset.value == "unread") {
|
||||
if (!setToRead || currentEntry.querySelector(":is(a, button)[data-toggle-status]").dataset.value == "unread") {
|
||||
toggleEntryStatus(currentEntry, toasting);
|
||||
}
|
||||
if (isListView() && currentEntry.classList.contains('current-item')) {
|
||||
|
@ -180,7 +180,7 @@ function handleEntryStatus(item, element, setToRead) {
|
|||
// Change the entry status to the opposite value.
|
||||
function toggleEntryStatus(element, toasting) {
|
||||
let entryID = parseInt(element.dataset.id, 10);
|
||||
let link = element.querySelector("a[data-toggle-status]");
|
||||
let link = element.querySelector(":is(a, button)[data-toggle-status]");
|
||||
|
||||
let currentStatus = link.dataset.value;
|
||||
let newStatus = currentStatus === "read" ? "unread" : "read";
|
||||
|
@ -259,7 +259,7 @@ function handleSaveEntry(element) {
|
|||
let toasting = !element;
|
||||
let currentEntry = findEntry(element);
|
||||
if (currentEntry) {
|
||||
saveEntry(currentEntry.querySelector("a[data-save-entry]"), toasting);
|
||||
saveEntry(currentEntry.querySelector(":is(a, button)[data-save-entry]"), toasting);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ function handleBookmark(element) {
|
|||
|
||||
// Send the Ajax request and change the icon when bookmarking an entry.
|
||||
function toggleBookmark(parentElement, toasting) {
|
||||
let element = parentElement.querySelector("a[data-toggle-bookmark]");
|
||||
let element = parentElement.querySelector(":is(a, button)[data-toggle-bookmark]");
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ function handleFetchOriginalContent() {
|
|||
return;
|
||||
}
|
||||
|
||||
let element = document.querySelector("a[data-fetch-content-entry]");
|
||||
let element = document.querySelector(":is(a, button)[data-fetch-content-entry]");
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
|
@ -376,13 +376,13 @@ function openOriginalLink(openLinkInCurrentTab) {
|
|||
return;
|
||||
}
|
||||
|
||||
let currentItemOriginalLink = document.querySelector(".current-item a[data-original-link]");
|
||||
let currentItemOriginalLink = document.querySelector(".current-item :is(a, button)[data-original-link]");
|
||||
if (currentItemOriginalLink !== null) {
|
||||
DomHelper.openNewTab(currentItemOriginalLink.getAttribute("href"));
|
||||
|
||||
let currentItem = document.querySelector(".current-item");
|
||||
// If we are not on the list of starred items, move to the next item
|
||||
if (document.location.href != document.querySelector('a[data-page=starred]').href) {
|
||||
if (document.location.href != document.querySelector(':is(a, button)[data-page=starred]').href) {
|
||||
goToListItem(1);
|
||||
}
|
||||
markEntryAsRead(currentItem);
|
||||
|
@ -391,7 +391,7 @@ function openOriginalLink(openLinkInCurrentTab) {
|
|||
|
||||
function openCommentLink(openLinkInCurrentTab) {
|
||||
if (!isListView()) {
|
||||
let entryLink = document.querySelector("a[data-comments-link]");
|
||||
let entryLink = document.querySelector(":is(a, button)[data-comments-link]");
|
||||
if (entryLink !== null) {
|
||||
if (openLinkInCurrentTab) {
|
||||
window.location.href = entryLink.getAttribute("href");
|
||||
|
@ -401,7 +401,7 @@ function openCommentLink(openLinkInCurrentTab) {
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
let currentItemCommentsLink = document.querySelector(".current-item a[data-comments-link]");
|
||||
let currentItemCommentsLink = document.querySelector(".current-item :is(a, button)[data-comments-link]");
|
||||
if (currentItemCommentsLink !== null) {
|
||||
DomHelper.openNewTab(currentItemCommentsLink.getAttribute("href"));
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ function unsubscribeFromFeed() {
|
|||
* @param {boolean} fallbackSelf Refresh actual page if the page is not found.
|
||||
*/
|
||||
function goToPage(page, fallbackSelf) {
|
||||
let element = document.querySelector("a[data-page=" + page + "]");
|
||||
let element = document.querySelector(":is(a, button)[data-page=" + page + "]");
|
||||
|
||||
if (element) {
|
||||
document.location.href = element.href;
|
||||
|
@ -477,7 +477,7 @@ function goToFeed() {
|
|||
window.location.href = feedAnchor.href;
|
||||
}
|
||||
} else {
|
||||
let currentItemFeed = document.querySelector(".current-item a[data-feed-link]");
|
||||
let currentItemFeed = document.querySelector(".current-item :is(a, button)[data-feed-link]");
|
||||
if (currentItemFeed !== null) {
|
||||
window.location.href = currentItemFeed.getAttribute("href");
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ function findEntry(element) {
|
|||
}
|
||||
|
||||
function handleConfirmationMessage(linkElement, callback) {
|
||||
if (linkElement.tagName != 'A') {
|
||||
if (linkElement.tagName != 'A' && linkElement.tagName != "BUTTON") {
|
||||
linkElement = linkElement.parentNode;
|
||||
}
|
||||
|
||||
|
@ -592,8 +592,7 @@ function handleConfirmationMessage(linkElement, callback) {
|
|||
containerElement.appendChild(loadingElement);
|
||||
}
|
||||
|
||||
let yesElement = document.createElement("a");
|
||||
yesElement.href = "#";
|
||||
let yesElement = document.createElement("button");
|
||||
yesElement.appendChild(document.createTextNode(linkElement.dataset.labelYes));
|
||||
yesElement.onclick = (event) => {
|
||||
event.preventDefault();
|
||||
|
@ -603,8 +602,7 @@ function handleConfirmationMessage(linkElement, callback) {
|
|||
callback(linkElement.dataset.url, linkElement.dataset.redirectUrl);
|
||||
};
|
||||
|
||||
let noElement = document.createElement("a");
|
||||
noElement.href = "#";
|
||||
let noElement = document.createElement("button");
|
||||
noElement.appendChild(document.createTextNode(linkElement.dataset.labelNo));
|
||||
noElement.onclick = (event) => {
|
||||
event.preventDefault();
|
||||
|
@ -677,7 +675,7 @@ function handlePlayerProgressionSave(playerElement) {
|
|||
* handle new share entires and already shared entries
|
||||
*/
|
||||
function handleShare() {
|
||||
let link = document.querySelector('a[data-share-status]');
|
||||
let link = document.querySelector(':is(a, button)[data-share-status]');
|
||||
let title = document.querySelector("body > main > section > header > h1 > a");
|
||||
if (link.dataset.shareStatus === "shared") {
|
||||
checkShareAPI(title, link.href);
|
||||
|
|
14
internal/ui/static/js/bootstrap.js
vendored
14
internal/ui/static/js/bootstrap.js
vendored
|
@ -79,14 +79,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
}
|
||||
}
|
||||
|
||||
onClick("a[data-save-entry]", (event) => handleSaveEntry(event.target));
|
||||
onClick("a[data-toggle-bookmark]", (event) => handleBookmark(event.target));
|
||||
onClick("a[data-fetch-content-entry]", () => handleFetchOriginalContent());
|
||||
onClick("a[data-share-status]", () => handleShare());
|
||||
onClick("a[data-action=markPageAsRead]", (event) => handleConfirmationMessage(event.target, () => markPageAsRead()));
|
||||
onClick("a[data-toggle-status]", (event) => handleEntryStatus("next", event.target));
|
||||
onClick(":is(a, button)[data-save-entry]", (event) => handleSaveEntry(event.target));
|
||||
onClick(":is(a, button)[data-toggle-bookmark]", (event) => handleBookmark(event.target));
|
||||
onClick(":is(a, button)[data-fetch-content-entry]", () => handleFetchOriginalContent());
|
||||
onClick(":is(a, button)[data-share-status]", () => handleShare());
|
||||
onClick(":is(a, button)[data-action=markPageAsRead]", (event) => handleConfirmationMessage(event.target, () => markPageAsRead()));
|
||||
onClick(":is(a, button)[data-toggle-status]", (event) => handleEntryStatus("next", event.target));
|
||||
|
||||
onClick("a[data-confirm]", (event) => handleConfirmationMessage(event.target, (url, redirectURL) => {
|
||||
onClick(":is(a, button)[data-confirm]", (event) => handleConfirmationMessage(event.target, (url, redirectURL) => {
|
||||
let request = new RequestBuilder(url);
|
||||
|
||||
request.withCallback((response) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue