diff --git a/CHANGELOG.md b/CHANGELOG.md index dc28a37507..bb49c11c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Unreleased + +- Modify subscription links component (PR #294) + # 7.1.0 * Add subscription links component (PR #290) diff --git a/app/assets/javascripts/govuk_publishing_components/lib/toggle.js b/app/assets/javascripts/govuk_publishing_components/lib/toggle.js new file mode 100644 index 0000000000..466612f359 --- /dev/null +++ b/app/assets/javascripts/govuk_publishing_components/lib/toggle.js @@ -0,0 +1,69 @@ +/* + Toggle the display of elements + + This is a straight copy of the same file from static. + + Use `data-controls` and `data-expanded` to indicate the + starting state and the IDs of the elements that the toggle + controls. This is synonymous with ARIA attributes, which + get added when starting. +*/ + +window.GOVUK.Modules = window.GOVUK.Modules || {}; + +(function (Modules) { + 'use strict' + + Modules.GemToggle = function () { + this.start = function ($el) { + var toggleSelector = '[data-controls][data-expanded]' + + $el.on('click', toggleSelector, toggle) + $el.find(toggleSelector).each(addAriaAttrs) + + // Add the ARIA attributes with JavaScript + // If the JS fails and there's no interactive elements, having + // no aria attributes is an accurate representation. + function addAriaAttrs () { + var $toggle = $(this) + $toggle.attr('role', 'button') + $toggle.attr('aria-controls', $toggle.data('controls')) + $toggle.attr('aria-expanded', $toggle.data('expanded')) + + var $targets = getTargetElements($toggle) + $targets.attr('aria-live', 'polite') + $targets.attr('role', 'region') + $toggle.data('$targets', $targets) + } + + function toggle (event) { + var $toggle = $(event.target), + expanded = $toggle.attr('aria-expanded') === 'true', + $targets = $toggle.data('$targets') + + if (expanded) { + $toggle.attr('aria-expanded', false) + $targets.addClass('js-hidden') + } else { + $toggle.attr('aria-expanded', true) + $targets.removeClass('js-hidden') + } + + var toggledText = $toggle.data('toggled-text') + if (typeof toggledText === 'string') { + $toggle.data('toggled-text', $toggle.text()) + $toggle.text(toggledText) + } + + event.preventDefault() + } + + function getTargetElements ($toggle) { + var ids = $toggle.attr('aria-controls').split(' '), + selector = '#' + ids.join(', #') + + return $el.find(selector) + } + } + } +})(window.GOVUK.Modules) diff --git a/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss b/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss index 542a0f36e6..1350b938ca 100644 --- a/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +++ b/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss @@ -38,3 +38,9 @@ } } } + +.gem-c-subscription-links__feed-box { + padding: $gutter-half; + margin-top: $gutter-one-quarter; + background: $grey-3; +} diff --git a/app/views/govuk_publishing_components/components/_subscription-links.html.erb b/app/views/govuk_publishing_components/components/_subscription-links.html.erb index c319020d5c..62815c9ffc 100644 --- a/app/views/govuk_publishing_components/components/_subscription-links.html.erb +++ b/app/views/govuk_publishing_components/components/_subscription-links.html.erb @@ -1,19 +1,42 @@ <% email_signup_link ||= false + email_signup_link_text ||= "Get email alerts" feed_link ||= false + feed_link_text ||= "Subscribe to feed" + feed_link_box_value ||= false %> -<% if email_signup_link || feed_link %> +<% if email_signup_link || feed_link || feed_link_box_value %>