diff --git a/src/content-handlers/iiif/JQueryPlugins.ts b/src/content-handlers/iiif/JQueryPlugins.ts index 245314ea6..39142c319 100644 --- a/src/content-handlers/iiif/JQueryPlugins.ts +++ b/src/content-handlers/iiif/JQueryPlugins.ts @@ -1,3 +1,5 @@ +import { Strings } from "@edsilv/utils"; + export default function jqueryPlugins($) { $.fn.checkboxButton = function (onClick: (checked: boolean) => void) { return this.each(function () { @@ -432,11 +434,16 @@ 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 = $( 'morepad' @@ -445,21 +452,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; } @@ -468,27 +475,37 @@ export default function jqueryPlugins($) { // Toggle function let expanded: boolean = false; - ($self).toggle = function () { - $self.empty(); + ($value).toggle = function () { + $value.empty(); const $toggleButton: JQuery = $(''); 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 + "… "); + const moreAriaLabel: string = Strings.format( + moreAriaLabelTemplate, + labelText + ); + $value.html(collapsedText + "… "); $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(); }); }; diff --git a/src/content-handlers/iiif/extensions/uv-aleph-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-aleph-extension/config/config.json index f53a7097f..30bb028fe 100644 --- a/src/content-handlers/iiif/extensions/uv-aleph-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-aleph-extension/config/config.json @@ -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", diff --git a/src/content-handlers/iiif/extensions/uv-av-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-av-extension/config/config.json index ab32b2ed9..d9f3cb40d 100644 --- a/src/content-handlers/iiif/extensions/uv-av-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-av-extension/config/config.json @@ -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", diff --git a/src/content-handlers/iiif/extensions/uv-default-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-default-extension/config/config.json index 4c01ff653..4435595d7 100644 --- a/src/content-handlers/iiif/extensions/uv-default-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-default-extension/config/config.json @@ -212,10 +212,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", diff --git a/src/content-handlers/iiif/extensions/uv-ebook-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-ebook-extension/config/config.json index 1df06c3ff..38cd8fcd2 100644 --- a/src/content-handlers/iiif/extensions/uv-ebook-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-ebook-extension/config/config.json @@ -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", diff --git a/src/content-handlers/iiif/extensions/uv-mediaelement-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-mediaelement-extension/config/config.json index 54928498c..54e1a30fb 100644 --- a/src/content-handlers/iiif/extensions/uv-mediaelement-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-mediaelement-extension/config/config.json @@ -248,10 +248,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", diff --git a/src/content-handlers/iiif/extensions/uv-model-viewer-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-model-viewer-extension/config/config.json index 13479234c..84e8a0d05 100644 --- a/src/content-handlers/iiif/extensions/uv-model-viewer-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-model-viewer-extension/config/config.json @@ -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", diff --git a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/config/config.json index 6fa3d2127..90d0216ed 100644 --- a/src/content-handlers/iiif/extensions/uv-openseadragon-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-openseadragon-extension/config/config.json @@ -257,10 +257,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", diff --git a/src/content-handlers/iiif/extensions/uv-pdf-extension/config/config.json b/src/content-handlers/iiif/extensions/uv-pdf-extension/config/config.json index 7aafa2bed..1b91e3f27 100644 --- a/src/content-handlers/iiif/extensions/uv-pdf-extension/config/config.json +++ b/src/content-handlers/iiif/extensions/uv-pdf-extension/config/config.json @@ -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", diff --git a/src/locales/cy-GB.json b/src/locales/cy-GB.json index 4111dd7bb..bcb9460ad 100644 --- a/src/locales/cy-GB.json +++ b/src/locales/cy-GB.json @@ -62,10 +62,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", diff --git a/src/locales/en-GB.json b/src/locales/en-GB.json index 6870aa1ba..472fa8859 100644 --- a/src/locales/en-GB.json +++ b/src/locales/en-GB.json @@ -62,10 +62,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", diff --git a/src/locales/fr-FR.json b/src/locales/fr-FR.json index cd4f82e12..8ce0edebb 100644 --- a/src/locales/fr-FR.json +++ b/src/locales/fr-FR.json @@ -62,10 +62,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", diff --git a/src/locales/pl-PL.json b/src/locales/pl-PL.json index 5da9c288b..7c25f3fb7 100644 --- a/src/locales/pl-PL.json +++ b/src/locales/pl-PL.json @@ -62,10 +62,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", diff --git a/src/locales/sv-SE.json b/src/locales/sv-SE.json index 7c98233da..8d4350c80 100644 --- a/src/locales/sv-SE.json +++ b/src/locales/sv-SE.json @@ -62,10 +62,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",