vpat: 1 add role="link" to links components (#3952)

- added role="link" to "zotero-text-link" custom component,
using that instead of directly setting the class
wherever possible
- in all other cases, added role="link" directly to links
- added tooltiptext and "noClick" option to zotero-text-link
so that this component could be used in attachmentBox.js
- use "keyboard-clickable" class in zotero-text-link
instead of a separate listener to handle keypresses for brevity
This commit is contained in:
abaevbog 2024-04-11 23:02:53 -04:00 committed by GitHub
parent 5263c79ea8
commit 117197e11d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 23 deletions

View file

@ -27,7 +27,7 @@
</div> </div>
<hbox> <hbox>
<label id="version"/> <label id="version"/>
<label id="changelog" class="zotero-text-link" value="&zotero.whatsNew;"/> <label id="changelog" is="zotero-text-link" value="&zotero.whatsNew;"/>
</hbox> </hbox>
<script> <script>
var version = Zotero.version; var version = Zotero.version;
@ -44,8 +44,7 @@
<script><![CDATA[ <script><![CDATA[
Components.utils.import("resource://zotero/config.js"); Components.utils.import("resource://zotero/config.js");
document.getElementById('changelog').onclick = document.getElementById('changelog').href = ZOTERO_CONFIG.CHANGELOG_URL;
() => Zotero.launchURL(ZOTERO_CONFIG.CHANGELOG_URL);
// Replace [links] in localized strings with spans with onclick handlers // Replace [links] in localized strings with spans with onclick handlers
// //
@ -85,6 +84,7 @@
// Activate text links // Activate text links
for (let span of document.getElementById('about-text').getElementsByTagName('span')) { for (let span of document.getElementById('about-text').getElementsByTagName('span')) {
span.className = 'text-link'; span.className = 'text-link';
span.setAttribute('role', 'link');
span.onclick = function () { span.onclick = function () {
Zotero.launchURL(this.getAttribute('data-href')); Zotero.launchURL(this.getAttribute('data-href'));
}; };

View file

@ -34,7 +34,7 @@
<html:div class="body"> <html:div class="body">
<attachment-preview id="attachment-preview" tabindex="0"/> <attachment-preview id="attachment-preview" tabindex="0"/>
<html:div style="display: grid;"> <html:div style="display: grid;">
<label id="url" crop="end" tabindex="0" <label id="url" is="zotero-text-link" crop="end" tabindex="0"
ondragstart="let dt = event.dataTransfer; dt.setData('text/x-moz-url', this.value); dt.setData('text/uri-list', this.value); dt.setData('text/plain', this.value);"/> ondragstart="let dt = event.dataTransfer; dt.setData('text/x-moz-url', this.value); dt.setData('text/uri-list', this.value); dt.setData('text/plain', this.value);"/>
</html:div> </html:div>
<html:div class="metadata-table"> <html:div class="metadata-table">
@ -334,18 +334,9 @@
if (this.displayURL && (isImportedURL || isLinkedURL)) { if (this.displayURL && (isImportedURL || isLinkedURL)) {
let urlSpec = this.item.getField('url'); let urlSpec = this.item.getField('url');
urlField.setAttribute('value', urlSpec); urlField.setAttribute('value', urlSpec);
urlField.setAttribute('tooltiptext', urlSpec); urlField.href = urlSpec;
urlField.setAttribute('hidden', false); if (!this.clickableLink) {
if (this.clickableLink) { urlField.noClick = true;
urlField.onclick = function (event) {
if (event.button == 0) {
ZoteroPane_Local.loadURI(this.value, event);
}
};
urlField.className = 'zotero-text-link keyboard-clickable';
}
else {
urlField.className = '';
} }
urlField.hidden = false; urlField.hidden = false;
} }

View file

@ -5,20 +5,16 @@
constructor() { constructor() {
super(); super();
this.addEventListener('click', (event) => { this.addEventListener('click', (event) => {
if (event.button == 0) { if (event.button == 0 && !this.noClick) {
this.open(event); this.open(event);
} }
}, true); }, true);
this.addEventListener('keypress', (event) => {
if (event.key == 'Enter' || event.key == 'Return') {
event.preventDefault();
this.click();
}
});
} }
connectedCallback() { connectedCallback() {
this.classList.add('zotero-text-link'); this.classList.add('zotero-text-link');
this.classList.add('keyboard-clickable');
this.setAttribute('role', 'link');
} }
get href() { get href() {
@ -27,6 +23,15 @@
set href(href) { set href(href) {
this.setAttribute('href', href); this.setAttribute('href', href);
this.setAttribute('tooltiptext', href);
}
get noClick() {
return this.getAttribute('no-click');
}
set noClick(val) {
this.setAttribute('no-click', !!val);
} }
open(event) { open(event) {

View file

@ -3247,6 +3247,7 @@ var ItemTree = class ItemTree extends LibraryTree {
// Activate text links // Activate text links
for (let span of div.getElementsByTagName('span')) { for (let span of div.getElementsByTagName('span')) {
if (span.classList.contains('text-link')) { if (span.classList.contains('text-link')) {
span.setAttribute('role', 'link');
if (span.hasAttribute('data-href')) { if (span.hasAttribute('data-href')) {
span.onclick = function () { span.onclick = function () {
doc.defaultView.ZoteroPane.loadURI(this.getAttribute('data-href')); doc.defaultView.ZoteroPane.loadURI(this.getAttribute('data-href'));

View file

@ -215,6 +215,7 @@ Zotero.ProgressWindow = function(options = {}) {
var elem = _progressWindow.document.createXULElement('label'); var elem = _progressWindow.document.createXULElement('label');
elem.setAttribute('value', part.text); elem.setAttribute('value', part.text);
elem.setAttribute('class', 'zotero-text-link'); elem.setAttribute('class', 'zotero-text-link');
elem.setAttribute('role', 'link');
for (var i in part.attributes) { for (var i in part.attributes) {
elem.setAttribute(i, part.attributes[i]); elem.setAttribute(i, part.attributes[i]);
} }