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

Add aria labels to toggle expand metadata (fixes issue 1081) #1156

Closed
wants to merge 16 commits into from
Closed
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
44 changes: 28 additions & 16 deletions src/content-handlers/iiif/JQueryPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Strings } from "@edsilv/utils";

export default function jqueryPlugins($) {
$.fn.checkboxButton = function(onClick: (checked: boolean) => void) {
return this.each(function() {
Expand Down Expand Up @@ -441,11 +443,17 @@ export default function jqueryPlugins($) {
lines: number,
lessText: string,
moreText: string,
cb: () => void
cb: () => void,
lessAriaLabelTemplate: string = 'Less information: Hide {0}',
moreAriaLabelTemplate: string = 'More information: Reveal {0}'
) {
return this.each(function() {

const $self: JQuery = $(this);
const expandedText: string = $self.html();
const $label: JQuery = $self.find('.label');
const $value: JQuery = $self.find('.value');
const expandedText: string = $value.html();
const labelText: string = $label.html();
// add 'pad' to account for the right margin in the sidebar
const $buttonPad: JQuery = $(
'<span>&hellip; <a href="#" class="toggle more">morepad</a></span>'
Expand All @@ -454,21 +462,21 @@ export default function jqueryPlugins($) {
const stringsByLine: string[] = [expandedText];
let lastHeight: number = $self.height();
// Until empty
while ($self.text().length > 0) {
$self.removeLastWord();
const html: string = $self.html();
$self.append($buttonPad);
while ($value.text().length > 0) {
$value.removeLastWord();
const html: string = $value.html();
$value.append($buttonPad);

if (lastHeight > $self.height()) {
if (lastHeight > $value.height()) {
stringsByLine.unshift(html);
lastHeight = $self.height();
lastHeight = $value.height();
}

$buttonPad.remove();
}

if (stringsByLine.length <= lines) {
$self.html(expandedText);
$value.html(expandedText);
return;
}

Expand All @@ -477,27 +485,31 @@ export default function jqueryPlugins($) {
// Toggle function
let expanded: boolean = false;

(<any>$self).toggle = function() {
$self.empty();
(<any>$value).toggle = function() {
$value.empty();
const $toggleButton: JQuery = $('<a href="#" class="toggle"></a>');
if (expanded) {
$self.html(expandedText + " ");
const lessAriaLabel: string = Strings.format(lessAriaLabelTemplate, labelText);
$value.html(expandedText + " ");
$toggleButton.text(lessText);
$toggleButton.switchClass("less", "more");
$toggleButton.attr('aria-label', lessAriaLabel);
} else {
$self.html(collapsedText + "&hellip; ");
const moreAriaLabel: string = Strings.format(moreAriaLabelTemplate, labelText);
$value.html(collapsedText + "&hellip; ");
$toggleButton.text(moreText);
$toggleButton.switchClass("more", "less");
$toggleButton.attr('aria-label', moreAriaLabel);
}
$toggleButton.one("click", function(e) {
e.preventDefault();
$self.toggle();
$value.toggle();
});
expanded = !expanded;
$self.append($toggleButton);
$value.append($toggleButton);
if (cb) cb();
};
$self.toggle();
$value.toggle();
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@
"expandFull": "$expandGallery",
"holdingText": "$moduleGoesHere",
"less": "$less",
"lessAriaLabelTemplate": "$lessAriaLabelTemplate",
"license": "$license",
"logo": "$logo",
"manifestHeader": "$aboutTheItem",
"more": "$more",
"moreAriaLabelTemplate": "$moreAriaLabelTemplate",
"noData": "$noDataToDisplay",
"page": "$page",
"rangeHeader": "$aboutThisSection",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/cy-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"$expandInformation": "Ehangu'r Wybodaeth",
"$moduleGoesHere": "Eich modiwl fan hyn!",
"$less": "llai",
"$lessAriaLabelTemplate": "Llai o wybodaeth: Cuddio {0}",
"$license": "Trwydded",
"$logo": "Logo",
"$aboutTheItem": "Am yr eitem",
"$more": "mwy",
"$moreAriaLabelTemplate": "Mwy o wybodaeth: Gweld {0}",
"$noDataToDisplay": "Nid oes data i'w arddangos",
"$page": "Tudalen",
"$aboutThisSection": "Am yr adran hon",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en-GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"$expandInformation": "Expand Information",
"$moduleGoesHere": "Your module goes here!",
"$less": "less",
"$lessAriaLabelTemplate": "Less information: Hide {0}",
"$license": "License",
"$logo": "Logo",
"$aboutTheItem": "About the item",
"$more": "more",
"$moreAriaLabelTemplate": "More information: Reveal {0}",
"$noDataToDisplay": "No data to display",
"$page": "Page",
"$aboutThisSection": "About this section",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"$expandInformation": "Afficher les informations",
"$moduleGoesHere": "Votre module vient ici !",
"$less": "moins",
"$lessAriaLabelTemplate": "Moins d'informations: cacher {0}",
"$license": "Licence",
"$logo": "Logo",
"$aboutTheItem": "A propos du contenu",
"$more": "suite",
"$moreAriaLabelTemplate": "Plus d'informations: afficher {0}",
"$noDataToDisplay": "Aucune donnée à afficher",
"$page": "Page",
"$aboutThisSection": "À propos de cette rubrique",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"$expandInformation": "Rozwiń informacje",
"$moduleGoesHere": "Miejsce na twój moduł!",
"$less": "mniej",
"$lessAriaLabelTemplate": "Więcej informacji: pokaż {0}",
"$license": "Licencja",
"$logo": "Logo",
"$aboutTheItem": "O obiekcie",
"$more": "więcej",
"$moreAriaLabelTemplate": "Mniej informacji: ukryj {0}",
"$noDataToDisplay": "Brak danych do wyświetlenia",
"$page": "Strona",
"$aboutThisSection": "O tej sekcji",
Expand Down
2 changes: 2 additions & 0 deletions src/locales/sv-SE.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"$expandInformation": "Expandera information",
"$moduleGoesHere": "Plats för din modul!",
"$less": "mindre",
"$lessAriaLabelTemplate": "Mindre information: göm {0}",
"$license": "Licensvillkor",
"$logo": "Logotyp",
"$aboutTheItem": "Om objektet",
"$more": "mer",
"$moreAriaLabelTemplate": "Mer information: visa {0}",
"$noDataToDisplay": "Ingen information att vis",
"$page": "Sida",
"$aboutThisSection": "Om detta avsnitt",
Expand Down