From 50204e981b49c05981575c89515b3e57d8db9d5b Mon Sep 17 00:00:00 2001 From: owenatgov Date: Thu, 4 Mar 2021 13:37:54 +0000 Subject: [PATCH] Tidy up untranslated content and formatting on accordion docs --- .../components/accordion.js | 14 +- .../components/_accordion.html.erb | 5 + .../components/docs/accordion.yml | 144 +++++++++--------- config/locales/en.yml | 10 ++ 4 files changed, 98 insertions(+), 75 deletions(-) diff --git a/app/assets/javascripts/govuk_publishing_components/components/accordion.js b/app/assets/javascripts/govuk_publishing_components/components/accordion.js index 9aea61db46..4ef74314db 100644 --- a/app/assets/javascripts/govuk_publishing_components/components/accordion.js +++ b/app/assets/javascripts/govuk_publishing_components/components/accordion.js @@ -31,6 +31,14 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; this.upChevonIconClass = 'gem-c-accordion-nav__chevron' this.downChevonIconClass = 'gem-c-accordion-nav__chevron--down' + // component content pulled from translated data attributes + this.$module.actions = {} + this.$module.actions.showText = this.$module.getAttribute('data-show-text') + this.$module.actions.hideText = this.$module.getAttribute('data-hide-text') + this.$module.actions.showAllText = this.$module.getAttribute('data-show-all-text') + this.$module.actions.hideAllText = this.$module.getAttribute('data-hide-all-text') + this.$module.actions.thisSectionVisuallyHidden = this.$module.getAttribute('data-this-section-visually-hidden') + // Indicate that js has worked this.$module.classList.add('gem-c-accordion--active') @@ -117,7 +125,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; // Build additional copy for assistive technology var srAdditionalCopy = document.createElement('span') srAdditionalCopy.classList.add('govuk-visually-hidden') - srAdditionalCopy.innerHTML = ' this section' + srAdditionalCopy.innerHTML = this.$module.actions.thisSectionVisuallyHidden // Build additional wrapper for toggle text, place icon after wrapped text. var wrapperShowHideIcon = document.createElement('span') @@ -178,7 +186,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; var icon = section.querySelector('.' + this.upChevonIconClass) var showHideText = section.querySelector('.' + this.sectionShowHideTextClass) var button = section.querySelector('.' + this.sectionButtonClass) - var newButtonText = expanded ? 'Hide' : 'Show' + var newButtonText = expanded ? this.$module.actions.hideText : this.$module.actions.showText showHideText.innerHTML = newButtonText button.setAttribute('aria-expanded', expanded) @@ -218,7 +226,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; GemAccordion.prototype.updateOpenAllButton = function (expanded) { var icon = this.openAllButton.querySelector('.' + this.upChevonIconClass) var openAllCopy = this.openAllButton.querySelector('.' + this.openAllTextClass) - var newButtonText = expanded ? 'Hide all sections' : 'Show all sections' + var newButtonText = expanded ? this.$module.actions.hideAllText : this.$module.actions.showAllText this.openAllButton.setAttribute('aria-expanded', expanded) openAllCopy.innerHTML = newButtonText diff --git a/app/views/govuk_publishing_components/components/_accordion.html.erb b/app/views/govuk_publishing_components/components/_accordion.html.erb index 487572fc5a..183c224b31 100644 --- a/app/views/govuk_publishing_components/components/_accordion.html.erb +++ b/app/views/govuk_publishing_components/components/_accordion.html.erb @@ -14,6 +14,11 @@ data_attributes ||= {} data_attributes[:module] = 'gem-accordion' data_attributes[:anchor_navigation] = anchor_navigation + data_attributes[:show_text] = t("components.accordion.show") + data_attributes[:hide_text] = t("components.accordion.hide") + data_attributes[:show_all_text] = t("components.accordion.show_all") + data_attributes[:hide_all_text] = t("components.accordion.hide_all") + data_attributes[:this_section_visually_hidden] = t("components.accordion.this_section_visually_hidden") %> <% if items.any? %> <%= tag.div(class: accordion_classes, id: id, data: data_attributes) do %> diff --git a/app/views/govuk_publishing_components/components/docs/accordion.yml b/app/views/govuk_publishing_components/components/docs/accordion.yml index 6bfc9f641b..9164f11e44 100644 --- a/app/views/govuk_publishing_components/components/docs/accordion.yml +++ b/app/views/govuk_publishing_components/components/docs/accordion.yml @@ -40,21 +40,21 @@ examples: data: items: - heading: - text: "Writing well for the web" + text: Writing well for the web content: - html: "

This is the content for Writing well for the web.

" + html:

This is the content for Writing well for the web.

- heading: - text: "Writing well for specialists" + text: Writing well for specialists content: - html: "

This is the content for Writing well for specialists.

" + html:

This is the content for Writing well for specialists.

- heading: - text: "Know your audience" + text: Know your audience content: - html: "

This is the content for Know your audience.

" + html:

This is the content for Know your audience.

- heading: - text: "How people read" + text: How people read content: - html: "

This is the content for How people read.

" + html:

This is the content for How people read.

with_supplied_identification: description: | An `id` is optional as it's automatically generated, but it can be supplied if a specific `id` is required. @@ -66,29 +66,29 @@ examples: id: with-supplied-id-thats-unique-across-the-domain items: - heading: - text: "Writing well for the web" + text: Writing well for the web content: - html: "

This is the content for Writing well for the web.

" + html:

This is the content for Writing well for the web.

- heading: - text: "Writing well for specialists" + text: Writing well for specialists content: - html: "

This is the content for Writing well for specialists.

" + html:

This is the content for Writing well for specialists.

- heading: - text: "Know your audience" + text: Know your audience content: - html: "

This is the content for Know your audience.

" + html:

This is the content for Know your audience.

- heading: - text: "How people read" + text: How people read content: - html: "

This is the content for How people read.

" + html:

This is the content for How people read.

with_summary: description: Adds a subheading below each section heading. data: items: - heading: - text: "Understanding agile project management" + text: Understanding agile project management summary: - text: "Introductions, methods, core features." + text: Introductions, methods, core features. content: html: '' - heading: - text: "Working with agile methods" + text: Working with agile methods summary: - text: "Workspaces, tools and techniques, user stories, planning." + text: Workspaces, tools and techniques, user stories, planning. content: html: '' - heading: - text: "Governing agile services" + text: Governing agile services summary: - text: "Principles, measuring progress, spending money." + text: Principles, measuring progress, spending money. content: html: '' - heading: - text: "Phases of an agile project" + text: Phases of an agile project summary: - text: "Discovery, alpha, beta, live and retirement." + text: Discovery, alpha, beta, live and retirement. content: html: '