govuk_publishing_components 32.1.0 → 35.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (496) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/assets/config/govuk_publishing_components_manifest.js +75 -1
  4. data/app/assets/images/govuk_publishing_components/icon-search.svg +3 -0
  5. data/app/assets/images/govuk_publishing_components/youtube-play-icon.png +0 -0
  6. data/app/assets/images/govuk_publishing_components/youtube-play-icon.svg +4 -0
  7. data/app/assets/javascripts/component_guide/accessibility-test.js +0 -1
  8. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +2 -1
  9. data/app/assets/javascripts/govuk_publishing_components/analytics/linked-domains.js +135 -0
  10. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-auto-tracker.js +49 -0
  11. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +341 -27
  12. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-ecommerce-tracker.js +17 -92
  13. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js +11 -23
  14. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-form-tracker.js +121 -0
  15. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +86 -305
  16. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +13 -6
  17. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-schemas.js +31 -1
  18. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-smart-answer-results-tracker.js +57 -0
  19. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-specialist-link-tracker.js +131 -0
  20. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +9 -4
  21. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js +4 -2
  22. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +4 -0
  23. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +12 -1
  24. data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +2 -2
  25. data/app/assets/javascripts/govuk_publishing_components/components/image-card.js +19 -0
  26. data/app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js +2 -81
  27. data/app/assets/javascripts/govuk_publishing_components/components/single-page-notification-button.js +24 -8
  28. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +23 -1
  29. data/app/assets/javascripts/govuk_publishing_components/dependencies.js +13 -0
  30. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +3 -2
  31. data/app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js +1 -0
  32. data/app/assets/javascripts/govuk_publishing_components/load-analytics.js +116 -0
  33. data/app/assets/javascripts/govuk_publishing_components/modules.js +7 -2
  34. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +140 -191
  35. data/app/assets/stylesheets/govuk_publishing_components/_individual_component_support.scss +10 -0
  36. data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +29 -0
  37. data/app/assets/stylesheets/govuk_publishing_components/components/_action-link.scss +2 -0
  38. data/app/assets/stylesheets/govuk_publishing_components/components/_attachment.scss +2 -0
  39. data/app/assets/stylesheets/govuk_publishing_components/components/_back-link.scss +1 -0
  40. data/app/assets/stylesheets/govuk_publishing_components/components/_big-number.scss +4 -5
  41. data/app/assets/stylesheets/govuk_publishing_components/components/_breadcrumbs.scss +1 -0
  42. data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +12 -0
  43. data/app/assets/stylesheets/govuk_publishing_components/components/_cards.scss +20 -0
  44. data/app/assets/stylesheets/govuk_publishing_components/components/_character-count.scss +1 -0
  45. data/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss +1 -0
  46. data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +21 -0
  47. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-guidance.scss +2 -0
  48. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +2 -0
  49. data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +7 -0
  50. data/app/assets/stylesheets/govuk_publishing_components/components/_date-input.scss +1 -0
  51. data/app/assets/stylesheets/govuk_publishing_components/components/_details.scss +1 -0
  52. data/app/assets/stylesheets/govuk_publishing_components/components/_devolved-nations.scss +2 -0
  53. data/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss +8 -0
  54. data/app/assets/stylesheets/govuk_publishing_components/components/_emergency-banner.scss +8 -0
  55. data/app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss +2 -0
  56. data/app/assets/stylesheets/govuk_publishing_components/components/_error-message.scss +1 -0
  57. data/app/assets/stylesheets/govuk_publishing_components/components/_error-summary.scss +1 -0
  58. data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +17 -19
  59. data/app/assets/stylesheets/govuk_publishing_components/components/_fieldset.scss +1 -0
  60. data/app/assets/stylesheets/govuk_publishing_components/components/_file-upload.scss +1 -0
  61. data/app/assets/stylesheets/govuk_publishing_components/components/_govspeak-html-publication.scss +10 -0
  62. data/app/assets/stylesheets/govuk_publishing_components/components/_govspeak.scss +85 -0
  63. data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +2 -0
  64. data/app/assets/stylesheets/govuk_publishing_components/components/_hint.scss +1 -0
  65. data/app/assets/stylesheets/govuk_publishing_components/components/_image-card.scss +85 -6
  66. data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +6 -6
  67. data/app/assets/stylesheets/govuk_publishing_components/components/_inset-text.scss +1 -0
  68. data/app/assets/stylesheets/govuk_publishing_components/components/_intervention.scss +2 -0
  69. data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +2 -0
  70. data/app/assets/stylesheets/govuk_publishing_components/components/_label.scss +1 -0
  71. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-footer.scss +1 -0
  72. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-for-public.scss +2 -0
  73. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +253 -483
  74. data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +2 -0
  75. data/app/assets/stylesheets/govuk_publishing_components/components/_metadata.scss +2 -0
  76. data/app/assets/stylesheets/govuk_publishing_components/components/_modal-dialogue.scss +2 -0
  77. data/app/assets/stylesheets/govuk_publishing_components/components/_notice.scss +1 -0
  78. data/app/assets/stylesheets/govuk_publishing_components/components/_organisation-logo.scss +2 -0
  79. data/app/assets/stylesheets/govuk_publishing_components/components/_panel.scss +1 -0
  80. data/app/assets/stylesheets/govuk_publishing_components/components/_phase-banner.scss +1 -0
  81. data/app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss +1 -0
  82. data/app/assets/stylesheets/govuk_publishing_components/components/_print-link.scss +2 -0
  83. data/app/assets/stylesheets/govuk_publishing_components/components/_radio.scss +1 -0
  84. data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +2 -0
  85. data/app/assets/stylesheets/govuk_publishing_components/components/_reorderable-list.scss +2 -0
  86. data/app/assets/stylesheets/govuk_publishing_components/components/_search.scss +2 -7
  87. data/app/assets/stylesheets/govuk_publishing_components/components/_select.scss +1 -0
  88. data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +2 -0
  89. data/app/assets/stylesheets/govuk_publishing_components/components/_show-password.scss +2 -0
  90. data/app/assets/stylesheets/govuk_publishing_components/components/_signup-link.scss +2 -0
  91. data/app/assets/stylesheets/govuk_publishing_components/components/_single-page-notification-button.scss +2 -0
  92. data/app/assets/stylesheets/govuk_publishing_components/components/_skip-link.scss +1 -0
  93. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +17 -0
  94. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +2 -0
  95. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +8 -0
  96. data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +2 -1
  97. data/app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss +1 -0
  98. data/app/assets/stylesheets/govuk_publishing_components/components/_summary-list.scss +1 -0
  99. data/app/assets/stylesheets/govuk_publishing_components/components/_table.scss +1 -0
  100. data/app/assets/stylesheets/govuk_publishing_components/components/_tabs.scss +1 -0
  101. data/app/assets/stylesheets/govuk_publishing_components/components/_textarea.scss +17 -0
  102. data/app/assets/stylesheets/govuk_publishing_components/components/_title.scss +12 -0
  103. data/app/assets/stylesheets/govuk_publishing_components/components/_translation-nav.scss +2 -0
  104. data/app/assets/stylesheets/govuk_publishing_components/components/_warning-text.scss +1 -0
  105. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_steps.scss +26 -9
  106. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_tables.scss +12 -0
  107. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_brand-colours.scss +2 -2
  108. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_contents-list-helper.scss +0 -1
  109. data/app/controllers/govuk_publishing_components/application_controller.rb +0 -13
  110. data/app/controllers/govuk_publishing_components/audit_controller.rb +1 -1
  111. data/app/controllers/govuk_publishing_components/component_guide_controller.rb +6 -9
  112. data/app/models/govuk_publishing_components/audit_applications.rb +10 -19
  113. data/app/models/govuk_publishing_components/audit_comparer.rb +29 -24
  114. data/app/models/govuk_publishing_components/audit_components.rb +157 -82
  115. data/app/models/govuk_publishing_components/component_doc.rb +14 -0
  116. data/app/models/govuk_publishing_components/component_wrapper_helper_options.rb +15 -0
  117. data/app/views/govuk_publishing_components/audit/_applications.html.erb +3 -3
  118. data/app/views/govuk_publishing_components/audit/_component_contents.html.erb +47 -39
  119. data/app/views/govuk_publishing_components/audit/_components.html.erb +47 -2
  120. data/app/views/govuk_publishing_components/component_guide/_application_stylesheet.html.erb +0 -3
  121. data/app/views/govuk_publishing_components/component_guide/index.html.erb +0 -7
  122. data/app/views/govuk_publishing_components/component_guide/show.html.erb +21 -6
  123. data/app/views/govuk_publishing_components/components/_accordion.html.erb +30 -36
  124. data/app/views/govuk_publishing_components/components/_action_link.html.erb +7 -2
  125. data/app/views/govuk_publishing_components/components/_attachment.html.erb +2 -0
  126. data/app/views/govuk_publishing_components/components/_attachment_link.html.erb +2 -0
  127. data/app/views/govuk_publishing_components/components/_back_link.html.erb +2 -0
  128. data/app/views/govuk_publishing_components/components/_big_number.html.erb +3 -1
  129. data/app/views/govuk_publishing_components/components/_breadcrumbs.html.erb +8 -2
  130. data/app/views/govuk_publishing_components/components/_button.html.erb +2 -0
  131. data/app/views/govuk_publishing_components/components/_cards.html.erb +6 -4
  132. data/app/views/govuk_publishing_components/components/_character_count.html.erb +2 -0
  133. data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +6 -2
  134. data/app/views/govuk_publishing_components/components/_contents_list.html.erb +11 -15
  135. data/app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb +7 -4
  136. data/app/views/govuk_publishing_components/components/_contextual_footer.html.erb +2 -0
  137. data/app/views/govuk_publishing_components/components/_contextual_guidance.html.erb +2 -0
  138. data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +13 -6
  139. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +12 -6
  140. data/app/views/govuk_publishing_components/components/_date_input.html.erb +2 -0
  141. data/app/views/govuk_publishing_components/components/_details.html.erb +5 -1
  142. data/app/views/govuk_publishing_components/components/_devolved_nations.html.erb +2 -0
  143. data/app/views/govuk_publishing_components/components/_document_list.html.erb +3 -0
  144. data/app/views/govuk_publishing_components/components/_emergency_banner.html.erb +2 -0
  145. data/app/views/govuk_publishing_components/components/_error_alert.html.erb +2 -0
  146. data/app/views/govuk_publishing_components/components/_error_message.html.erb +4 -1
  147. data/app/views/govuk_publishing_components/components/_error_summary.html.erb +29 -26
  148. data/app/views/govuk_publishing_components/components/_feedback.html.erb +2 -0
  149. data/app/views/govuk_publishing_components/components/_fieldset.html.erb +2 -0
  150. data/app/views/govuk_publishing_components/components/_file_upload.html.erb +2 -0
  151. data/app/views/govuk_publishing_components/components/_google_tag_manager_script.html.erb +2 -2
  152. data/app/views/govuk_publishing_components/components/_govspeak.html.erb +1 -0
  153. data/app/views/govuk_publishing_components/components/_govspeak_html_publication.html.erb +2 -0
  154. data/app/views/govuk_publishing_components/components/_heading.html.erb +2 -0
  155. data/app/views/govuk_publishing_components/components/_hint.html.erb +4 -1
  156. data/app/views/govuk_publishing_components/components/_image_card.html.erb +17 -12
  157. data/app/views/govuk_publishing_components/components/_input.html.erb +10 -2
  158. data/app/views/govuk_publishing_components/components/_inset_text.html.erb +2 -0
  159. data/app/views/govuk_publishing_components/components/_intervention.html.erb +2 -0
  160. data/app/views/govuk_publishing_components/components/_inverse_header.html.erb +2 -0
  161. data/app/views/govuk_publishing_components/components/_label.html.erb +7 -3
  162. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +2 -0
  163. data/app/views/govuk_publishing_components/components/_layout_for_admin.html.erb +8 -5
  164. data/app/views/govuk_publishing_components/components/_layout_for_public.html.erb +8 -3
  165. data/app/views/govuk_publishing_components/components/_layout_header.html.erb +2 -0
  166. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +238 -267
  167. data/app/views/govuk_publishing_components/components/_lead_paragraph.html.erb +2 -0
  168. data/app/views/govuk_publishing_components/components/_metadata.html.erb +2 -0
  169. data/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb +2 -0
  170. data/app/views/govuk_publishing_components/components/_notice.html.erb +2 -0
  171. data/app/views/govuk_publishing_components/components/_organisation_logo.html.erb +2 -0
  172. data/app/views/govuk_publishing_components/components/_panel.html.erb +2 -0
  173. data/app/views/govuk_publishing_components/components/_phase_banner.html.erb +3 -1
  174. data/app/views/govuk_publishing_components/components/_previous_and_next_navigation.html.erb +6 -1
  175. data/app/views/govuk_publishing_components/components/_print_link.html.erb +2 -0
  176. data/app/views/govuk_publishing_components/components/_radio.html.erb +2 -0
  177. data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +16 -6
  178. data/app/views/govuk_publishing_components/components/_reorderable_list.html.erb +2 -0
  179. data/app/views/govuk_publishing_components/components/_search.html.erb +2 -0
  180. data/app/views/govuk_publishing_components/components/_select.html.erb +2 -0
  181. data/app/views/govuk_publishing_components/components/_share_links.html.erb +13 -13
  182. data/app/views/govuk_publishing_components/components/_show_password.html.erb +2 -0
  183. data/app/views/govuk_publishing_components/components/_signup_link.html.erb +2 -0
  184. data/app/views/govuk_publishing_components/components/_single_page_notification_button.html.erb +8 -2
  185. data/app/views/govuk_publishing_components/components/_skip_link.html.erb +2 -0
  186. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +8 -1
  187. data/app/views/govuk_publishing_components/components/_step_by_step_nav_header.html.erb +12 -2
  188. data/app/views/govuk_publishing_components/components/_step_by_step_nav_related.html.erb +21 -8
  189. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +3 -1
  190. data/app/views/govuk_publishing_components/components/_success_alert.html.erb +2 -0
  191. data/app/views/govuk_publishing_components/components/_summary_list.html.erb +2 -0
  192. data/app/views/govuk_publishing_components/components/_table.html.erb +3 -1
  193. data/app/views/govuk_publishing_components/components/_tabs.html.erb +22 -2
  194. data/app/views/govuk_publishing_components/components/_textarea.html.erb +12 -2
  195. data/app/views/govuk_publishing_components/components/_title.html.erb +2 -0
  196. data/app/views/govuk_publishing_components/components/_translation_nav.html.erb +2 -0
  197. data/app/views/govuk_publishing_components/components/_warning_text.html.erb +2 -0
  198. data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +16 -6
  199. data/app/views/govuk_publishing_components/components/docs/accordion.yml +16 -3
  200. data/app/views/govuk_publishing_components/components/docs/action_link.yml +1 -0
  201. data/app/views/govuk_publishing_components/components/docs/breadcrumbs.yml +2 -1
  202. data/app/views/govuk_publishing_components/components/docs/button.yml +10 -0
  203. data/app/views/govuk_publishing_components/components/docs/cards.yml +1 -0
  204. data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +1 -0
  205. data/app/views/govuk_publishing_components/components/docs/contents_list.yml +1 -12
  206. data/app/views/govuk_publishing_components/components/docs/contextual_breadcrumbs.yml +13 -0
  207. data/app/views/govuk_publishing_components/components/docs/contextual_footer.yml +43 -0
  208. data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +65 -0
  209. data/app/views/govuk_publishing_components/components/docs/details.yml +17 -0
  210. data/app/views/govuk_publishing_components/components/docs/document_list.yml +18 -1
  211. data/app/views/govuk_publishing_components/components/docs/emergency_banner.yml +3 -1
  212. data/app/views/govuk_publishing_components/components/docs/error_message.yml +13 -0
  213. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +22 -1
  214. data/app/views/govuk_publishing_components/components/docs/hint.yml +6 -0
  215. data/app/views/govuk_publishing_components/components/docs/image_card.yml +24 -1
  216. data/app/views/govuk_publishing_components/components/docs/input.yml +32 -0
  217. data/app/views/govuk_publishing_components/components/docs/intervention.yml +2 -1
  218. data/app/views/govuk_publishing_components/components/docs/label.yml +17 -0
  219. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +1 -0
  220. data/app/views/govuk_publishing_components/components/docs/previous_and_next_navigation.yml +2 -0
  221. data/app/views/govuk_publishing_components/components/docs/related_navigation.yml +47 -0
  222. data/app/views/govuk_publishing_components/components/docs/share_links.yml +59 -30
  223. data/app/views/govuk_publishing_components/components/docs/single_page_notification_button.yml +16 -1
  224. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +54 -0
  225. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_header.yml +6 -0
  226. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav_related.yml +10 -0
  227. data/app/views/govuk_publishing_components/components/docs/tabs.yml +15 -0
  228. data/app/views/govuk_publishing_components/components/docs/textarea.yml +31 -0
  229. data/app/views/govuk_publishing_components/components/docs/translation_nav.yml +2 -0
  230. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +3 -3
  231. data/app/views/govuk_publishing_components/components/feedback/_survey_signup_form.html.erb +1 -1
  232. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +4 -5
  233. data/app/views/govuk_publishing_components/components/metadata/_sentence.html.erb +4 -2
  234. data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +36 -16
  235. data/app/views/layouts/govuk_publishing_components/application.html.erb +3 -4
  236. data/config/locales/ar.yml +14 -14
  237. data/config/locales/az.yml +15 -14
  238. data/config/locales/be.yml +14 -14
  239. data/config/locales/bg.yml +14 -14
  240. data/config/locales/bn.yml +14 -14
  241. data/config/locales/cs.yml +14 -14
  242. data/config/locales/cy.yml +14 -14
  243. data/config/locales/da.yml +14 -14
  244. data/config/locales/de.yml +14 -14
  245. data/config/locales/dr.yml +14 -14
  246. data/config/locales/el.yml +14 -14
  247. data/config/locales/en.yml +21 -28
  248. data/config/locales/es-419.yml +14 -14
  249. data/config/locales/es.yml +14 -14
  250. data/config/locales/et.yml +14 -14
  251. data/config/locales/fa.yml +15 -14
  252. data/config/locales/fi.yml +14 -14
  253. data/config/locales/fr.yml +14 -14
  254. data/config/locales/gd.yml +14 -14
  255. data/config/locales/gu.yml +14 -14
  256. data/config/locales/he.yml +14 -14
  257. data/config/locales/hi.yml +14 -14
  258. data/config/locales/hr.yml +14 -14
  259. data/config/locales/hu.yml +14 -14
  260. data/config/locales/hy.yml +14 -14
  261. data/config/locales/id.yml +14 -14
  262. data/config/locales/is.yml +14 -14
  263. data/config/locales/it.yml +14 -14
  264. data/config/locales/ja.yml +14 -14
  265. data/config/locales/ka.yml +14 -14
  266. data/config/locales/kk.yml +14 -14
  267. data/config/locales/ko.yml +14 -14
  268. data/config/locales/lt.yml +14 -14
  269. data/config/locales/lv.yml +14 -14
  270. data/config/locales/ms.yml +14 -14
  271. data/config/locales/mt.yml +14 -14
  272. data/config/locales/nl.yml +14 -14
  273. data/config/locales/no.yml +14 -14
  274. data/config/locales/pa-pk.yml +14 -14
  275. data/config/locales/pa.yml +14 -14
  276. data/config/locales/pl.yml +14 -14
  277. data/config/locales/ps.yml +14 -14
  278. data/config/locales/pt.yml +14 -14
  279. data/config/locales/ro.yml +14 -14
  280. data/config/locales/ru.yml +14 -14
  281. data/config/locales/si.yml +14 -14
  282. data/config/locales/sk.yml +14 -14
  283. data/config/locales/sl.yml +14 -14
  284. data/config/locales/so.yml +14 -14
  285. data/config/locales/sq.yml +14 -14
  286. data/config/locales/sr.yml +14 -14
  287. data/config/locales/sv.yml +14 -14
  288. data/config/locales/sw.yml +14 -14
  289. data/config/locales/ta.yml +14 -14
  290. data/config/locales/th.yml +14 -14
  291. data/config/locales/tk.yml +14 -14
  292. data/config/locales/tr.yml +14 -14
  293. data/config/locales/uk.yml +14 -14
  294. data/config/locales/ur.yml +14 -14
  295. data/config/locales/uz.yml +14 -14
  296. data/config/locales/vi.yml +14 -14
  297. data/config/locales/zh-hk.yml +14 -14
  298. data/config/locales/zh-tw.yml +14 -14
  299. data/config/locales/zh.yml +14 -14
  300. data/lib/govuk_publishing_components/app_helpers/asset_helper.rb +86 -0
  301. data/lib/govuk_publishing_components/config.rb +3 -3
  302. data/lib/govuk_publishing_components/presenters/accordion_helper.rb +38 -0
  303. data/lib/govuk_publishing_components/presenters/breadcrumb_selector.rb +3 -2
  304. data/lib/govuk_publishing_components/presenters/{breadcrumbs.rb → breadcrumbs_helper.rb} +8 -0
  305. data/lib/govuk_publishing_components/presenters/button_helper.rb +9 -2
  306. data/lib/govuk_publishing_components/presenters/component_wrapper_helper.rb +95 -0
  307. data/lib/govuk_publishing_components/presenters/image_card_helper.rb +65 -2
  308. data/lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb +3 -2
  309. data/lib/govuk_publishing_components/presenters/related_navigation_helper.rb +16 -7
  310. data/lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb +43 -2
  311. data/lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb +16 -0
  312. data/lib/govuk_publishing_components/railtie.rb +7 -0
  313. data/lib/govuk_publishing_components/version.rb +1 -1
  314. data/lib/govuk_publishing_components.rb +6 -1
  315. data/node_modules/axe-core/README.md +1 -1
  316. data/node_modules/axe-core/axe.d.ts +76 -24
  317. data/node_modules/axe-core/axe.js +9200 -9059
  318. data/node_modules/axe-core/axe.min.js +3 -3
  319. data/node_modules/axe-core/package.json +29 -29
  320. data/node_modules/axe-core/sri-history.json +20 -0
  321. data/node_modules/govuk-frontend/README.md +1 -2
  322. data/node_modules/govuk-frontend/govuk/all.js +4035 -2673
  323. data/node_modules/govuk-frontend/govuk/all.js.map +1 -0
  324. data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js +71 -0
  325. data/node_modules/govuk-frontend/govuk/common/closest-attribute-value.js.map +1 -0
  326. data/node_modules/govuk-frontend/govuk/common/index.js +180 -0
  327. data/node_modules/govuk-frontend/govuk/common/index.js.map +1 -0
  328. data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js +376 -0
  329. data/node_modules/govuk-frontend/govuk/common/normalise-dataset.js.map +1 -0
  330. data/node_modules/govuk-frontend/govuk/common.js +173 -30
  331. data/node_modules/govuk-frontend/govuk/common.js.map +1 -0
  332. data/node_modules/govuk-frontend/govuk/components/_all.scss +1 -1
  333. data/node_modules/govuk-frontend/govuk/components/accordion/_index.scss +23 -4
  334. data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +2116 -983
  335. data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js.map +1 -0
  336. data/node_modules/govuk-frontend/govuk/components/accordion/fixtures.json +54 -22
  337. data/node_modules/govuk-frontend/govuk/components/accordion/macro-options.json +36 -0
  338. data/node_modules/govuk-frontend/govuk/components/accordion/template.njk +8 -2
  339. data/node_modules/govuk-frontend/govuk/components/back-link/_index.scss +19 -19
  340. data/node_modules/govuk-frontend/govuk/components/back-link/fixtures.json +12 -12
  341. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/_index.scss +21 -10
  342. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/fixtures.json +22 -22
  343. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +23 -5
  344. data/node_modules/govuk-frontend/govuk/components/button/button.js +958 -690
  345. data/node_modules/govuk-frontend/govuk/components/button/button.js.map +1 -0
  346. data/node_modules/govuk-frontend/govuk/components/button/fixtures.json +85 -66
  347. data/node_modules/govuk-frontend/govuk/components/button/template.njk +1 -1
  348. data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +9 -0
  349. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +2083 -1161
  350. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js.map +1 -0
  351. data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +112 -36
  352. data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +42 -0
  353. data/node_modules/govuk-frontend/govuk/components/character-count/template.njk +27 -3
  354. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +1155 -1119
  355. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js.map +1 -0
  356. data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +96 -93
  357. data/node_modules/govuk-frontend/govuk/components/cookie-banner/fixtures.json +46 -46
  358. data/node_modules/govuk-frontend/govuk/components/cookie-banner/template.njk +1 -1
  359. data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +50 -50
  360. data/node_modules/govuk-frontend/govuk/components/details/details.js +797 -766
  361. data/node_modules/govuk-frontend/govuk/components/details/details.js.map +1 -0
  362. data/node_modules/govuk-frontend/govuk/components/details/fixtures.json +20 -20
  363. data/node_modules/govuk-frontend/govuk/components/error-message/fixtures.json +20 -20
  364. data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js +1089 -814
  365. data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js.map +1 -0
  366. data/node_modules/govuk-frontend/govuk/components/error-summary/fixtures.json +44 -35
  367. data/node_modules/govuk-frontend/govuk/components/error-summary/template.njk +25 -21
  368. data/node_modules/govuk-frontend/govuk/components/fieldset/fixtures.json +51 -39
  369. data/node_modules/govuk-frontend/govuk/components/file-upload/fixtures.json +26 -26
  370. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +1 -1
  371. data/node_modules/govuk-frontend/govuk/components/footer/fixtures.json +46 -46
  372. data/node_modules/govuk-frontend/govuk/components/footer/macro-options.json +2 -2
  373. data/node_modules/govuk-frontend/govuk/components/header/_index.scss +6 -0
  374. data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +93 -38
  375. data/node_modules/govuk-frontend/govuk/components/header/header.js +646 -992
  376. data/node_modules/govuk-frontend/govuk/components/header/header.js.map +1 -0
  377. data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +8 -2
  378. data/node_modules/govuk-frontend/govuk/components/header/template.njk +4 -2
  379. data/node_modules/govuk-frontend/govuk/components/hint/fixtures.json +12 -12
  380. data/node_modules/govuk-frontend/govuk/components/input/fixtures.json +80 -80
  381. data/node_modules/govuk-frontend/govuk/components/inset-text/fixtures.json +12 -12
  382. data/node_modules/govuk-frontend/govuk/components/label/fixtures.json +34 -34
  383. data/node_modules/govuk-frontend/govuk/components/notification-banner/fixtures.json +56 -46
  384. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +790 -532
  385. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js.map +1 -0
  386. data/node_modules/govuk-frontend/govuk/components/notification-banner/template.njk +1 -1
  387. data/node_modules/govuk-frontend/govuk/components/pagination/_index.scss +10 -7
  388. data/node_modules/govuk-frontend/govuk/components/pagination/fixtures.json +94 -26
  389. data/node_modules/govuk-frontend/govuk/components/pagination/template.njk +1 -1
  390. data/node_modules/govuk-frontend/govuk/components/panel/fixtures.json +18 -18
  391. data/node_modules/govuk-frontend/govuk/components/phase-banner/fixtures.json +14 -14
  392. data/node_modules/govuk-frontend/govuk/components/phase-banner/macro-options.json +1 -1
  393. data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +94 -91
  394. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +1110 -1079
  395. data/node_modules/govuk-frontend/govuk/components/radios/radios.js.map +1 -0
  396. data/node_modules/govuk-frontend/govuk/components/select/fixtures.json +32 -32
  397. data/node_modules/govuk-frontend/govuk/components/skip-link/fixtures.json +22 -20
  398. data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js +1017 -1008
  399. data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js.map +1 -0
  400. data/node_modules/govuk-frontend/govuk/components/summary-list/_index.scss +107 -0
  401. data/node_modules/govuk-frontend/govuk/components/summary-list/fixtures.json +345 -50
  402. data/node_modules/govuk-frontend/govuk/components/summary-list/macro-options.json +110 -0
  403. data/node_modules/govuk-frontend/govuk/components/summary-list/template.njk +72 -28
  404. data/node_modules/govuk-frontend/govuk/components/table/_index.scss +1 -1
  405. data/node_modules/govuk-frontend/govuk/components/table/fixtures.json +40 -40
  406. data/node_modules/govuk-frontend/govuk/components/tabs/fixtures.json +29 -29
  407. data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js +1389 -1233
  408. data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js.map +1 -0
  409. data/node_modules/govuk-frontend/govuk/components/tag/fixtures.json +28 -28
  410. data/node_modules/govuk-frontend/govuk/components/textarea/fixtures.json +34 -34
  411. data/node_modules/govuk-frontend/govuk/components/warning-text/fixtures.json +14 -14
  412. data/node_modules/govuk-frontend/govuk/core/_section-break.scss +1 -1
  413. data/node_modules/govuk-frontend/govuk/helpers/_colour.scss +2 -2
  414. data/node_modules/govuk-frontend/govuk/helpers/_focused.scss +5 -0
  415. data/node_modules/govuk-frontend/govuk/helpers/_links.scss +6 -6
  416. data/node_modules/govuk-frontend/govuk/i18n.js +389 -0
  417. data/node_modules/govuk-frontend/govuk/i18n.js.map +1 -0
  418. data/node_modules/govuk-frontend/govuk/macros/i18n.njk +15 -0
  419. data/node_modules/govuk-frontend/govuk/settings/_all.scss +1 -0
  420. data/node_modules/govuk-frontend/govuk/settings/_colours-palette.scss +12 -0
  421. data/node_modules/govuk-frontend/govuk/settings/_compatibility.scss +26 -0
  422. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +5 -5
  423. data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +23 -0
  424. data/node_modules/govuk-frontend/govuk/settings/_typography-responsive.scss +12 -0
  425. data/node_modules/govuk-frontend/govuk/settings/_warnings.scss +53 -0
  426. data/node_modules/govuk-frontend/govuk/tools/_compatibility.scss +20 -6
  427. data/node_modules/govuk-frontend/govuk/vendor/polyfills/DOMTokenList.js +242 -241
  428. data/node_modules/govuk-frontend/govuk/vendor/polyfills/DOMTokenList.js.map +1 -0
  429. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js +22 -0
  430. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Date/now.js.map +1 -0
  431. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Document.js +17 -16
  432. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Document.js.map +1 -0
  433. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList.js +547 -546
  434. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/classList.js.map +1 -0
  435. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/closest.js +37 -36
  436. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/closest.js.map +1 -0
  437. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js +301 -0
  438. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/dataset.js.map +1 -0
  439. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/matches.js +21 -20
  440. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/matches.js.map +1 -0
  441. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/nextElementSibling.js +198 -197
  442. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/nextElementSibling.js.map +1 -0
  443. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/previousElementSibling.js +198 -197
  444. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element/prototype/previousElementSibling.js.map +1 -0
  445. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element.js +106 -105
  446. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Element.js.map +1 -0
  447. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Event.js +400 -399
  448. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Event.js.map +1 -0
  449. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind.js +239 -238
  450. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Function/prototype/bind.js.map +1 -0
  451. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Object/defineProperty.js +72 -71
  452. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Object/defineProperty.js.map +1 -0
  453. data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js +22 -0
  454. data/node_modules/govuk-frontend/govuk/vendor/polyfills/String/prototype/trim.js.map +1 -0
  455. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js +17 -16
  456. data/node_modules/govuk-frontend/govuk/vendor/polyfills/Window.js.map +1 -0
  457. data/node_modules/govuk-frontend/govuk-esm/all.mjs +52 -29
  458. data/node_modules/govuk-frontend/govuk-esm/common/closest-attribute-value.mjs +15 -0
  459. data/node_modules/govuk-frontend/govuk-esm/common/index.mjs +166 -0
  460. data/node_modules/govuk-frontend/govuk-esm/common/normalise-dataset.mjs +60 -0
  461. data/node_modules/govuk-frontend/govuk-esm/common.mjs +6 -28
  462. data/node_modules/govuk-frontend/govuk-esm/components/accordion/accordion.mjs +238 -85
  463. data/node_modules/govuk-frontend/govuk-esm/components/button/button.mjs +73 -34
  464. data/node_modules/govuk-frontend/govuk-esm/components/character-count/character-count.mjs +329 -124
  465. data/node_modules/govuk-frontend/govuk-esm/components/checkboxes/checkboxes.mjs +32 -20
  466. data/node_modules/govuk-frontend/govuk-esm/components/details/details.mjs +41 -20
  467. data/node_modules/govuk-frontend/govuk-esm/components/error-summary/error-summary.mjs +60 -14
  468. data/node_modules/govuk-frontend/govuk-esm/components/header/header.mjs +9 -2
  469. data/node_modules/govuk-frontend/govuk-esm/components/notification-banner/notification-banner.mjs +33 -4
  470. data/node_modules/govuk-frontend/govuk-esm/components/radios/radios.mjs +18 -11
  471. data/node_modules/govuk-frontend/govuk-esm/components/skip-link/skip-link.mjs +15 -7
  472. data/node_modules/govuk-frontend/govuk-esm/components/tabs/tabs.mjs +171 -38
  473. data/node_modules/govuk-frontend/govuk-esm/i18n.mjs +378 -0
  474. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Date/now.mjs +13 -0
  475. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/Element/prototype/dataset.mjs +68 -0
  476. data/node_modules/govuk-frontend/govuk-esm/vendor/polyfills/String/prototype/trim.mjs +13 -0
  477. data/node_modules/govuk-frontend/govuk-prototype-kit/init.js +7 -0
  478. data/node_modules/govuk-frontend/govuk-prototype-kit/init.scss +12 -0
  479. data/node_modules/govuk-frontend/govuk-prototype-kit.config.json +138 -7
  480. data/node_modules/govuk-frontend/package.json +1 -1
  481. metadata +70 -19
  482. data/app/assets/stylesheets/component_guide/print.scss +0 -1
  483. data/app/assets/stylesheets/govuk_publishing_components/_all_components_print.scss +0 -18
  484. data/app/assets/stylesheets/govuk_publishing_components/components/print/_accordion.scss +0 -28
  485. data/app/assets/stylesheets/govuk_publishing_components/components/print/_button.scss +0 -8
  486. data/app/assets/stylesheets/govuk_publishing_components/components/print/_cards.scss +0 -4
  487. data/app/assets/stylesheets/govuk_publishing_components/components/print/_contents-list.scss +0 -19
  488. data/app/assets/stylesheets/govuk_publishing_components/components/print/_emergency-banner.scss +0 -3
  489. data/app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak-html-publication.scss +0 -5
  490. data/app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak.scss +0 -80
  491. data/app/assets/stylesheets/govuk_publishing_components/components/print/_layout-super-navigation-header.scss +0 -3
  492. data/app/assets/stylesheets/govuk_publishing_components/components/print/_organisation-logo.scss +0 -7
  493. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav-header.scss +0 -7
  494. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav.scss +0 -116
  495. data/app/assets/stylesheets/govuk_publishing_components/components/print/_textarea.scss +0 -13
  496. data/app/assets/stylesheets/govuk_publishing_components/components/print/_title.scss +0 -7
@@ -1,1105 +1,2238 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define('GOVUKFrontend.Accordion', factory) :
4
- (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Accordion = factory());
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define('GOVUKFrontend.Accordion', factory) :
4
+ (global.GOVUKFrontend = global.GOVUKFrontend || {}, global.GOVUKFrontend.Accordion = factory());
5
5
  }(this, (function () { 'use strict';
6
6
 
7
- /**
8
- * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
9
- * This seems to fail in IE8, requires more investigation.
10
- * See: https://github.com/imagitama/nodelist-foreach-polyfill
11
- */
12
- function nodeListForEach (nodes, callback) {
13
- if (window.NodeList.prototype.forEach) {
14
- return nodes.forEach(callback)
7
+ /**
8
+ * Common helpers which do not require polyfill.
9
+ *
10
+ * IMPORTANT: If a helper require a polyfill, please isolate it in its own module
11
+ * so that the polyfill can be properly tree-shaken and does not burden
12
+ * the components that do not need that helper
13
+ *
14
+ * @module common/index
15
+ */
16
+
17
+ /**
18
+ * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
19
+ * This seems to fail in IE8, requires more investigation.
20
+ * See: https://github.com/imagitama/nodelist-foreach-polyfill
21
+ *
22
+ * @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
23
+ * @param {nodeListIterator} callback - Callback function to run for each node
24
+ * @returns {void}
25
+ */
26
+ function nodeListForEach (nodes, callback) {
27
+ if (window.NodeList.prototype.forEach) {
28
+ return nodes.forEach(callback)
29
+ }
30
+ for (var i = 0; i < nodes.length; i++) {
31
+ callback.call(window, nodes[i], i, nodes);
32
+ }
15
33
  }
16
- for (var i = 0; i < nodes.length; i++) {
17
- callback.call(window, nodes[i], i, nodes);
34
+
35
+ /**
36
+ * Config flattening function
37
+ *
38
+ * Takes any number of objects, flattens them into namespaced key-value pairs,
39
+ * (e.g. {'i18n.showSection': 'Show section'}) and combines them together, with
40
+ * greatest priority on the LAST item passed in.
41
+ *
42
+ * @returns {Object<string, unknown>} A flattened object of key-value pairs.
43
+ */
44
+ function mergeConfigs (/* configObject1, configObject2, ...configObjects */) {
45
+ /**
46
+ * Function to take nested objects and flatten them to a dot-separated keyed
47
+ * object. Doing this means we don't need to do any deep/recursive merging of
48
+ * each of our objects, nor transform our dataset from a flat list into a
49
+ * nested object.
50
+ *
51
+ * @param {Object<string, unknown>} configObject - Deeply nested object
52
+ * @returns {Object<string, unknown>} Flattened object with dot-separated keys
53
+ */
54
+ var flattenObject = function (configObject) {
55
+ // Prepare an empty return object
56
+ var flattenedObject = {};
57
+
58
+ /**
59
+ * Our flattening function, this is called recursively for each level of
60
+ * depth in the object. At each level we prepend the previous level names to
61
+ * the key using `prefix`.
62
+ *
63
+ * @param {Partial<Object<string, unknown>>} obj - Object to flatten
64
+ * @param {string} [prefix] - Optional dot-separated prefix
65
+ */
66
+ var flattenLoop = function (obj, prefix) {
67
+ // Loop through keys...
68
+ for (var key in obj) {
69
+ // Check to see if this is a prototypical key/value,
70
+ // if it is, skip it.
71
+ if (!Object.prototype.hasOwnProperty.call(obj, key)) {
72
+ continue
73
+ }
74
+ var value = obj[key];
75
+ var prefixedKey = prefix ? prefix + '.' + key : key;
76
+ if (typeof value === 'object') {
77
+ // If the value is a nested object, recurse over that too
78
+ flattenLoop(value, prefixedKey);
79
+ } else {
80
+ // Otherwise, add this value to our return object
81
+ flattenedObject[prefixedKey] = value;
82
+ }
83
+ }
84
+ };
85
+
86
+ // Kick off the recursive loop
87
+ flattenLoop(configObject);
88
+ return flattenedObject
89
+ };
90
+
91
+ // Start with an empty object as our base
92
+ var formattedConfigObject = {};
93
+
94
+ // Loop through each of the remaining passed objects and push their keys
95
+ // one-by-one into configObject. Any duplicate keys will override the existing
96
+ // key with the new value.
97
+ for (var i = 0; i < arguments.length; i++) {
98
+ var obj = flattenObject(arguments[i]);
99
+ for (var key in obj) {
100
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
101
+ formattedConfigObject[key] = obj[key];
102
+ }
103
+ }
104
+ }
105
+
106
+ return formattedConfigObject
18
107
  }
19
- }
20
-
21
- (function(undefined) {
22
-
23
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
24
- var detect = (
25
- // In IE8, defineProperty could only act on DOM elements, so full support
26
- // for the feature requires the ability to set a property on an arbitrary object
27
- 'defineProperty' in Object && (function() {
28
- try {
29
- var a = {};
30
- Object.defineProperty(a, 'test', {value:42});
31
- return true;
32
- } catch(e) {
33
- return false
108
+
109
+ /**
110
+ * Extracts keys starting with a particular namespace from a flattened config
111
+ * object, removing the namespace in the process.
112
+ *
113
+ * @param {Object<string, unknown>} configObject - The object to extract key-value pairs from.
114
+ * @param {string} namespace - The namespace to filter keys with.
115
+ * @returns {Object<string, unknown>} Flattened object with dot-separated key namespace removed
116
+ * @throws {Error} Config object required
117
+ * @throws {Error} Namespace string required
118
+ */
119
+ function extractConfigByNamespace (configObject, namespace) {
120
+ // Check we have what we need
121
+ if (!configObject || typeof configObject !== 'object') {
122
+ throw new Error('Provide a `configObject` of type "object".')
123
+ }
124
+ if (!namespace || typeof namespace !== 'string') {
125
+ throw new Error('Provide a `namespace` of type "string" to filter the `configObject` by.')
126
+ }
127
+ var newObject = {};
128
+ for (var key in configObject) {
129
+ // Split the key into parts, using . as our namespace separator
130
+ var keyParts = key.split('.');
131
+ // Check if the first namespace matches the configured namespace
132
+ if (Object.prototype.hasOwnProperty.call(configObject, key) && keyParts[0] === namespace) {
133
+ // Remove the first item (the namespace) from the parts array,
134
+ // but only if there is more than one part (we don't want blank keys!)
135
+ if (keyParts.length > 1) {
136
+ keyParts.shift();
137
+ }
138
+ // Join the remaining parts back together
139
+ var newKey = keyParts.join('.');
140
+ // Add them to our new object
141
+ newObject[newKey] = configObject[key];
142
+ }
143
+ }
144
+ return newObject
145
+ }
146
+
147
+ /**
148
+ * @callback nodeListIterator
149
+ * @param {Element} value - The current node being iterated on
150
+ * @param {number} index - The current index in the iteration
151
+ * @param {NodeListOf<Element>} nodes - NodeList from querySelectorAll()
152
+ * @returns {void}
153
+ */
154
+
155
+ (function(undefined) {
156
+
157
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
158
+ var detect = (
159
+ // In IE8, defineProperty could only act on DOM elements, so full support
160
+ // for the feature requires the ability to set a property on an arbitrary object
161
+ 'defineProperty' in Object && (function() {
162
+ try {
163
+ var a = {};
164
+ Object.defineProperty(a, 'test', {value:42});
165
+ return true;
166
+ } catch(e) {
167
+ return false
168
+ }
169
+ }())
170
+ );
171
+
172
+ if (detect) return
173
+
174
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
175
+ (function (nativeDefineProperty) {
176
+
177
+ var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
178
+ var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
179
+ var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
180
+
181
+ Object.defineProperty = function defineProperty(object, property, descriptor) {
182
+
183
+ // Where native support exists, assume it
184
+ if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
185
+ return nativeDefineProperty(object, property, descriptor);
186
+ }
187
+
188
+ if (object === null || !(object instanceof Object || typeof object === 'object')) {
189
+ throw new TypeError('Object.defineProperty called on non-object');
190
+ }
191
+
192
+ if (!(descriptor instanceof Object)) {
193
+ throw new TypeError('Property description must be an object');
194
+ }
195
+
196
+ var propertyString = String(property);
197
+ var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
198
+ var getterType = 'get' in descriptor && typeof descriptor.get;
199
+ var setterType = 'set' in descriptor && typeof descriptor.set;
200
+
201
+ // handle descriptor.get
202
+ if (getterType) {
203
+ if (getterType !== 'function') {
204
+ throw new TypeError('Getter must be a function');
205
+ }
206
+ if (!supportsAccessors) {
207
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
208
+ }
209
+ if (hasValueOrWritable) {
210
+ throw new TypeError(ERR_VALUE_ACCESSORS);
211
+ }
212
+ Object.__defineGetter__.call(object, propertyString, descriptor.get);
213
+ } else {
214
+ object[propertyString] = descriptor.value;
215
+ }
216
+
217
+ // handle descriptor.set
218
+ if (setterType) {
219
+ if (setterType !== 'function') {
220
+ throw new TypeError('Setter must be a function');
221
+ }
222
+ if (!supportsAccessors) {
223
+ throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
224
+ }
225
+ if (hasValueOrWritable) {
226
+ throw new TypeError(ERR_VALUE_ACCESSORS);
227
+ }
228
+ Object.__defineSetter__.call(object, propertyString, descriptor.set);
229
+ }
230
+
231
+ // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
232
+ if ('value' in descriptor) {
233
+ object[propertyString] = descriptor.value;
234
+ }
235
+
236
+ return object;
237
+ };
238
+ }(Object.defineProperty));
239
+ })
240
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
241
+
242
+ (function(undefined) {
243
+
244
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
245
+ var detect = ("Document" in this);
246
+
247
+ if (detect) return
248
+
249
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
250
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
251
+
252
+ if (this.HTMLDocument) { // IE8
253
+
254
+ // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
255
+ this.Document = this.HTMLDocument;
256
+
257
+ } else {
258
+
259
+ // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made.
260
+ this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
261
+ this.Document.prototype = document;
34
262
  }
35
- }())
36
- );
37
-
38
- if (detect) return
39
-
40
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
41
- (function (nativeDefineProperty) {
42
-
43
- var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
44
- var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
45
- var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
46
-
47
- Object.defineProperty = function defineProperty(object, property, descriptor) {
48
-
49
- // Where native support exists, assume it
50
- if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
51
- return nativeDefineProperty(object, property, descriptor);
52
- }
53
-
54
- if (object === null || !(object instanceof Object || typeof object === 'object')) {
55
- throw new TypeError('Object.defineProperty called on non-object');
56
- }
57
-
58
- if (!(descriptor instanceof Object)) {
59
- throw new TypeError('Property description must be an object');
60
- }
61
-
62
- var propertyString = String(property);
63
- var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
64
- var getterType = 'get' in descriptor && typeof descriptor.get;
65
- var setterType = 'set' in descriptor && typeof descriptor.set;
66
-
67
- // handle descriptor.get
68
- if (getterType) {
69
- if (getterType !== 'function') {
70
- throw new TypeError('Getter must be a function');
71
- }
72
- if (!supportsAccessors) {
73
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
74
- }
75
- if (hasValueOrWritable) {
76
- throw new TypeError(ERR_VALUE_ACCESSORS);
77
- }
78
- Object.__defineGetter__.call(object, propertyString, descriptor.get);
79
- } else {
80
- object[propertyString] = descriptor.value;
81
- }
82
-
83
- // handle descriptor.set
84
- if (setterType) {
85
- if (setterType !== 'function') {
86
- throw new TypeError('Setter must be a function');
87
- }
88
- if (!supportsAccessors) {
89
- throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
90
- }
91
- if (hasValueOrWritable) {
92
- throw new TypeError(ERR_VALUE_ACCESSORS);
93
- }
94
- Object.__defineSetter__.call(object, propertyString, descriptor.set);
95
- }
96
-
97
- // OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
98
- if ('value' in descriptor) {
99
- object[propertyString] = descriptor.value;
100
- }
101
-
102
- return object;
103
- };
104
- }(Object.defineProperty));
105
- })
106
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
107
-
108
- (function(undefined) {
109
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
110
- var detect = 'bind' in Function.prototype;
263
+ }
264
+
265
+
266
+ })
267
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
268
+
269
+ (function(undefined) {
270
+
271
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
272
+ var detect = ('Element' in this && 'HTMLElement' in this);
111
273
 
112
274
  if (detect) return
113
275
 
114
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
115
- Object.defineProperty(Function.prototype, 'bind', {
116
- value: function bind(that) { // .length is 1
117
- // add necessary es5-shim utilities
118
- var $Array = Array;
119
- var $Object = Object;
120
- var ObjectPrototype = $Object.prototype;
121
- var ArrayPrototype = $Array.prototype;
122
- var Empty = function Empty() {};
123
- var to_string = ObjectPrototype.toString;
124
- var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
125
- var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
126
- var array_slice = ArrayPrototype.slice;
127
- var array_concat = ArrayPrototype.concat;
128
- var array_push = ArrayPrototype.push;
129
- var max = Math.max;
130
- // /add necessary es5-shim utilities
131
-
132
- // 1. Let Target be the this value.
133
- var target = this;
134
- // 2. If IsCallable(Target) is false, throw a TypeError exception.
135
- if (!isCallable(target)) {
136
- throw new TypeError('Function.prototype.bind called on incompatible ' + target);
137
- }
138
- // 3. Let A be a new (possibly empty) internal list of all of the
139
- // argument values provided after thisArg (arg1, arg2 etc), in order.
140
- // XXX slicedArgs will stand in for "A" if used
141
- var args = array_slice.call(arguments, 1); // for normal call
142
- // 4. Let F be a new native ECMAScript object.
143
- // 11. Set the [[Prototype]] internal property of F to the standard
144
- // built-in Function prototype object as specified in 15.3.3.1.
145
- // 12. Set the [[Call]] internal property of F as described in
146
- // 15.3.4.5.1.
147
- // 13. Set the [[Construct]] internal property of F as described in
148
- // 15.3.4.5.2.
149
- // 14. Set the [[HasInstance]] internal property of F as described in
150
- // 15.3.4.5.3.
151
- var bound;
152
- var binder = function () {
153
-
154
- if (this instanceof bound) {
155
- // 15.3.4.5.2 [[Construct]]
156
- // When the [[Construct]] internal method of a function object,
157
- // F that was created using the bind function is called with a
158
- // list of arguments ExtraArgs, the following steps are taken:
159
- // 1. Let target be the value of F's [[TargetFunction]]
160
- // internal property.
161
- // 2. If target has no [[Construct]] internal method, a
162
- // TypeError exception is thrown.
163
- // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
164
- // property.
165
- // 4. Let args be a new list containing the same values as the
166
- // list boundArgs in the same order followed by the same
167
- // values as the list ExtraArgs in the same order.
168
- // 5. Return the result of calling the [[Construct]] internal
169
- // method of target providing args as the arguments.
170
-
171
- var result = target.apply(
172
- this,
173
- array_concat.call(args, array_slice.call(arguments))
174
- );
175
- if ($Object(result) === result) {
176
- return result;
177
- }
178
- return this;
179
-
180
- } else {
181
- // 15.3.4.5.1 [[Call]]
182
- // When the [[Call]] internal method of a function object, F,
183
- // which was created using the bind function is called with a
184
- // this value and a list of arguments ExtraArgs, the following
185
- // steps are taken:
186
- // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
187
- // property.
188
- // 2. Let boundThis be the value of F's [[BoundThis]] internal
189
- // property.
190
- // 3. Let target be the value of F's [[TargetFunction]] internal
191
- // property.
192
- // 4. Let args be a new list containing the same values as the
193
- // list boundArgs in the same order followed by the same
194
- // values as the list ExtraArgs in the same order.
195
- // 5. Return the result of calling the [[Call]] internal method
196
- // of target providing boundThis as the this value and
197
- // providing args as the arguments.
198
-
199
- // equiv: target.call(this, ...boundArgs, ...args)
200
- return target.apply(
201
- that,
202
- array_concat.call(args, array_slice.call(arguments))
203
- );
204
-
205
- }
276
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
277
+ (function () {
206
278
 
207
- };
279
+ // IE8
280
+ if (window.Element && !window.HTMLElement) {
281
+ window.HTMLElement = window.Element;
282
+ return;
283
+ }
208
284
 
209
- // 15. If the [[Class]] internal property of Target is "Function", then
210
- // a. Let L be the length property of Target minus the length of A.
211
- // b. Set the length own property of F to either 0 or L, whichever is
212
- // larger.
213
- // 16. Else set the length own property of F to 0.
285
+ // create Element constructor
286
+ window.Element = window.HTMLElement = new Function('return function Element() {}')();
287
+
288
+ // generate sandboxed iframe
289
+ var vbody = document.appendChild(document.createElement('body'));
290
+ var frame = vbody.appendChild(document.createElement('iframe'));
291
+
292
+ // use sandboxed iframe to replicate Element functionality
293
+ var frameDocument = frame.contentWindow.document;
294
+ var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
295
+ var cache = {};
296
+
297
+ // polyfill Element.prototype on an element
298
+ var shiv = function (element, deep) {
299
+ var
300
+ childNodes = element.childNodes || [],
301
+ index = -1,
302
+ key, value, childNode;
303
+
304
+ if (element.nodeType === 1 && element.constructor !== Element) {
305
+ element.constructor = Element;
306
+
307
+ for (key in cache) {
308
+ value = cache[key];
309
+ element[key] = value;
310
+ }
311
+ }
312
+
313
+ while (childNode = deep && childNodes[++index]) {
314
+ shiv(childNode, deep);
315
+ }
316
+
317
+ return element;
318
+ };
319
+
320
+ var elements = document.getElementsByTagName('*');
321
+ var nativeCreateElement = document.createElement;
322
+ var interval;
323
+ var loopLimit = 100;
324
+
325
+ prototype.attachEvent('onpropertychange', function (event) {
326
+ var
327
+ propertyName = event.propertyName,
328
+ nonValue = !cache.hasOwnProperty(propertyName),
329
+ newValue = prototype[propertyName],
330
+ oldValue = cache[propertyName],
331
+ index = -1,
332
+ element;
333
+
334
+ while (element = elements[++index]) {
335
+ if (element.nodeType === 1) {
336
+ if (nonValue || element[propertyName] === oldValue) {
337
+ element[propertyName] = newValue;
338
+ }
339
+ }
340
+ }
341
+
342
+ cache[propertyName] = newValue;
343
+ });
344
+
345
+ prototype.constructor = Element;
346
+
347
+ if (!prototype.hasAttribute) {
348
+ // <Element>.hasAttribute
349
+ prototype.hasAttribute = function hasAttribute(name) {
350
+ return this.getAttribute(name) !== null;
351
+ };
352
+ }
214
353
 
215
- var boundLength = max(0, target.length - args.length);
354
+ // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
355
+ function bodyCheck() {
356
+ if (!(loopLimit--)) clearTimeout(interval);
357
+ if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
358
+ shiv(document, true);
359
+ if (interval && document.body.prototype) clearTimeout(interval);
360
+ return (!!document.body.prototype);
361
+ }
362
+ return false;
363
+ }
364
+ if (!bodyCheck()) {
365
+ document.onreadystatechange = bodyCheck;
366
+ interval = setInterval(bodyCheck, 25);
367
+ }
216
368
 
217
- // 17. Set the attributes of the length own property of F to the values
218
- // specified in 15.3.5.1.
219
- var boundArgs = [];
220
- for (var i = 0; i < boundLength; i++) {
221
- array_push.call(boundArgs, '$' + i);
222
- }
369
+ // Apply to any new elements created after load
370
+ document.createElement = function createElement(nodeName) {
371
+ var element = nativeCreateElement(String(nodeName).toLowerCase());
372
+ return shiv(element);
373
+ };
223
374
 
224
- // XXX Build a dynamic function with desired amount of arguments is the only
225
- // way to set the length property of a function.
226
- // In environments where Content Security Policies enabled (Chrome extensions,
227
- // for ex.) all use of eval or Function costructor throws an exception.
228
- // However in all of these environments Function.prototype.bind exists
229
- // and so this code will never be executed.
230
- bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
231
-
232
- if (target.prototype) {
233
- Empty.prototype = target.prototype;
234
- bound.prototype = new Empty();
235
- // Clean up dangling references.
236
- Empty.prototype = null;
237
- }
375
+ // remove sandboxed iframe
376
+ document.removeChild(vbody);
377
+ }());
238
378
 
239
- // TODO
240
- // 18. Set the [[Extensible]] internal property of F to true.
241
-
242
- // TODO
243
- // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
244
- // 20. Call the [[DefineOwnProperty]] internal method of F with
245
- // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
246
- // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
247
- // false.
248
- // 21. Call the [[DefineOwnProperty]] internal method of F with
249
- // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
250
- // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
251
- // and false.
252
-
253
- // TODO
254
- // NOTE Function objects created using Function.prototype.bind do not
255
- // have a prototype property or the [[Code]], [[FormalParameters]], and
256
- // [[Scope]] internal properties.
257
- // XXX can't delete prototype in pure-js.
258
-
259
- // 22. Return F.
260
- return bound;
261
- }
262
- });
263
- })
264
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
379
+ })
380
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
265
381
 
266
- (function(undefined) {
382
+ (function(undefined) {
267
383
 
268
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
269
- var detect = (
270
- 'DOMTokenList' in this && (function (x) {
271
- return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
272
- })(document.createElement('x'))
273
- );
384
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/13cf7c340974d128d557580b5e2dafcd1b1192d1/polyfills/Element/prototype/dataset/detect.js
385
+ var detect = (function(){
386
+ if (!document.documentElement.dataset) {
387
+ return false;
388
+ }
389
+ var el = document.createElement('div');
390
+ el.setAttribute("data-a-b", "c");
391
+ return el.dataset && el.dataset.aB == "c";
392
+ }());
274
393
 
275
394
  if (detect) return
276
395
 
277
- // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
278
- (function (global) {
279
- var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
280
-
281
- if (
282
- !nativeImpl ||
283
- (
284
- !!document.createElementNS &&
285
- !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
286
- !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
287
- )
288
- ) {
289
- global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
290
- var dpSupport = true;
291
- var defineGetter = function (object, name, fn, configurable) {
292
- if (Object.defineProperty)
293
- Object.defineProperty(object, name, {
294
- configurable: false === dpSupport ? true : !!configurable,
295
- get: fn
396
+ // Polyfill derived from https://raw.githubusercontent.com/Financial-Times/polyfill-library/13cf7c340974d128d557580b5e2dafcd1b1192d1/polyfills/Element/prototype/dataset/polyfill.js
397
+ Object.defineProperty(Element.prototype, 'dataset', {
398
+ get: function() {
399
+ var element = this;
400
+ var attributes = this.attributes;
401
+ var map = {};
402
+
403
+ for (var i = 0; i < attributes.length; i++) {
404
+ var attribute = attributes[i];
405
+
406
+ // This regex has been edited from the original polyfill, to add
407
+ // support for period (.) separators in data-* attribute names. These
408
+ // are allowed in the HTML spec, but were not covered by the original
409
+ // polyfill's regex. We use periods in our i18n implementation.
410
+ if (attribute && attribute.name && (/^data-\w[.\w-]*$/).test(attribute.name)) {
411
+ var name = attribute.name;
412
+ var value = attribute.value;
413
+
414
+ var propName = name.substr(5).replace(/-./g, function (prop) {
415
+ return prop.charAt(1).toUpperCase();
416
+ });
417
+
418
+ // If this browser supports __defineGetter__ and __defineSetter__,
419
+ // continue using defineProperty. If not (like IE 8 and below), we use
420
+ // a hacky fallback which at least gives an object in the right format
421
+ if ('__defineGetter__' in Object.prototype && '__defineSetter__' in Object.prototype) {
422
+ Object.defineProperty(map, propName, {
423
+ enumerable: true,
424
+ get: function() {
425
+ return this.value;
426
+ }.bind({value: value || ''}),
427
+ set: function setter(name, value) {
428
+ if (typeof value !== 'undefined') {
429
+ this.setAttribute(name, value);
430
+ } else {
431
+ this.removeAttribute(name);
432
+ }
433
+ }.bind(element, name)
296
434
  });
435
+ } else {
436
+ map[propName] = value;
437
+ }
297
438
 
298
- else object.__defineGetter__(name, fn);
299
- };
300
-
301
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
302
- try {
303
- defineGetter({}, "support");
304
- }
305
- catch (e) {
306
- dpSupport = false;
307
439
  }
440
+ }
441
+
442
+ return map;
443
+ }
444
+ });
308
445
 
446
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
309
447
 
310
- var _DOMTokenList = function (el, prop) {
311
- var that = this;
312
- var tokens = [];
313
- var tokenMap = {};
314
- var length = 0;
315
- var maxLength = 0;
316
- var addIndexGetter = function (i) {
317
- defineGetter(that, i, function () {
318
- preop();
319
- return tokens[i];
320
- }, false);
448
+ (function(undefined) {
321
449
 
322
- };
323
- var reindex = function () {
450
+ // Detection from https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill
451
+ var detect = ('trim' in String.prototype);
452
+
453
+ if (detect) return
324
454
 
325
- /** Define getter functions for array-like access to the tokenList's contents. */
326
- if (length >= maxLength)
327
- for (; maxLength < length; ++maxLength) {
328
- addIndexGetter(maxLength);
329
- }
330
- };
455
+ // Polyfill from https://github.com/mdn/content/blob/cf607d68522cd35ee7670782d3ee3a361eaef2e4/files/en-us/web/javascript/reference/global_objects/string/trim/index.md#polyfill
456
+ String.prototype.trim = function () {
457
+ return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
458
+ };
331
459
 
332
- /** Helper function called at the start of each class method. Internal use only. */
333
- var preop = function () {
334
- var error;
335
- var i;
336
- var args = arguments;
337
- var rSpace = /\s+/;
338
-
339
- /** Validate the token/s passed to an instance method, if any. */
340
- if (args.length)
341
- for (i = 0; i < args.length; ++i)
342
- if (rSpace.test(args[i])) {
343
- error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
344
- error.code = 5;
345
- error.name = "InvalidCharacterError";
346
- throw error;
347
- }
460
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
461
+
462
+ /* eslint-disable es-x/no-string-prototype-trim -- Polyfill imported */
463
+
464
+ /**
465
+ * Normalise string
466
+ *
467
+ * 'If it looks like a duck, and it quacks like a duck…' 🦆
468
+ *
469
+ * If the passed value looks like a boolean or a number, convert it to a boolean
470
+ * or number.
471
+ *
472
+ * Designed to be used to convert config passed via data attributes (which are
473
+ * always strings) into something sensible.
474
+ *
475
+ * @param {string} value - The value to normalise
476
+ * @returns {string | boolean | number | undefined} Normalised data
477
+ */
478
+ function normaliseString (value) {
479
+ if (typeof value !== 'string') {
480
+ return value
481
+ }
482
+
483
+ var trimmedValue = value.trim();
484
+
485
+ if (trimmedValue === 'true') {
486
+ return true
487
+ }
488
+
489
+ if (trimmedValue === 'false') {
490
+ return false
491
+ }
492
+
493
+ // Empty / whitespace-only strings are considered finite so we need to check
494
+ // the length of the trimmed string as well
495
+ if (trimmedValue.length > 0 && isFinite(trimmedValue)) {
496
+ return Number(trimmedValue)
497
+ }
498
+
499
+ return value
500
+ }
501
+
502
+ /**
503
+ * Normalise dataset
504
+ *
505
+ * Loop over an object and normalise each value using normaliseData function
506
+ *
507
+ * @param {DOMStringMap} dataset - HTML element dataset
508
+ * @returns {Object<string, unknown>} Normalised dataset
509
+ */
510
+ function normaliseDataset (dataset) {
511
+ var out = {};
512
+
513
+ for (var key in dataset) {
514
+ out[key] = normaliseString(dataset[key]);
515
+ }
516
+
517
+ return out
518
+ }
519
+
520
+ /**
521
+ * Internal support for selecting messages to render, with placeholder
522
+ * interpolation and locale-aware number formatting and pluralisation
523
+ *
524
+ * @class
525
+ * @private
526
+ * @param {Object<string, unknown>} translations - Key-value pairs of the translation strings to use.
527
+ * @param {object} [config] - Configuration options for the function.
528
+ * @param {string} [config.locale] - An overriding locale for the PluralRules functionality.
529
+ */
530
+ function I18n (translations, config) {
531
+ // Make list of translations available throughout function
532
+ this.translations = translations || {};
533
+
534
+ // The locale to use for PluralRules and NumberFormat
535
+ this.locale = (config && config.locale) || document.documentElement.lang || 'en';
536
+ }
537
+
538
+ /**
539
+ * The most used function - takes the key for a given piece of UI text and
540
+ * returns the appropriate string.
541
+ *
542
+ * @param {string} lookupKey - The lookup key of the string to use.
543
+ * @param {Object<string, unknown>} [options] - Any options passed with the translation string, e.g: for string interpolation.
544
+ * @returns {string} The appropriate translation string.
545
+ * @throws {Error} Lookup key required
546
+ * @throws {Error} Options required for `${}` placeholders
547
+ */
548
+ I18n.prototype.t = function (lookupKey, options) {
549
+ if (!lookupKey) {
550
+ // Print a console error if no lookup key has been provided
551
+ throw new Error('i18n: lookup key missing')
552
+ }
553
+
554
+ // If the `count` option is set, determine which plural suffix is needed and
555
+ // change the lookupKey to match. We check to see if it's undefined instead of
556
+ // falsy, as this could legitimately be 0.
557
+ if (options && typeof options.count !== 'undefined') {
558
+ // Get the plural suffix
559
+ lookupKey = lookupKey + '.' + this.getPluralSuffix(lookupKey, options.count);
560
+ }
561
+
562
+ if (lookupKey in this.translations) {
563
+ // Fetch the translation string for that lookup key
564
+ var translationString = this.translations[lookupKey];
565
+
566
+ // Check for ${} placeholders in the translation string
567
+ if (translationString.match(/%{(.\S+)}/)) {
568
+ if (!options) {
569
+ throw new Error('i18n: cannot replace placeholders in string if no option data provided')
570
+ }
571
+
572
+ return this.replacePlaceholders(translationString, options)
573
+ } else {
574
+ return translationString
575
+ }
576
+ } else {
577
+ // If the key wasn't found in our translations object,
578
+ // return the lookup key itself as the fallback
579
+ return lookupKey
580
+ }
581
+ };
582
+
583
+ /**
584
+ * Takes a translation string with placeholders, and replaces the placeholders
585
+ * with the provided data
586
+ *
587
+ * @param {string} translationString - The translation string
588
+ * @param {Object<string, unknown>} options - Any options passed with the translation string, e.g: for string interpolation.
589
+ * @returns {string} The translation string to output, with ${} placeholders replaced
590
+ */
591
+ I18n.prototype.replacePlaceholders = function (translationString, options) {
592
+ var formatter;
593
+
594
+ if (this.hasIntlNumberFormatSupport()) {
595
+ formatter = new Intl.NumberFormat(this.locale);
596
+ }
597
+
598
+ return translationString.replace(/%{(.\S+)}/g, function (placeholderWithBraces, placeholderKey) {
599
+ if (Object.prototype.hasOwnProperty.call(options, placeholderKey)) {
600
+ var placeholderValue = options[placeholderKey];
348
601
 
602
+ // If a user has passed `false` as the value for the placeholder
603
+ // treat it as though the value should not be displayed
604
+ if (placeholderValue === false) {
605
+ return ''
606
+ }
349
607
 
350
- /** Split the new value apart by whitespace*/
351
- if (typeof el[prop] === "object") {
352
- tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
353
- } else {
354
- tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
355
- }
608
+ // If the placeholder's value is a number, localise the number formatting
609
+ if (typeof placeholderValue === 'number' && formatter) {
610
+ return formatter.format(placeholderValue)
611
+ }
356
612
 
357
- /** Avoid treating blank strings as single-item token lists */
358
- if ("" === tokens[0]) tokens = [];
613
+ return placeholderValue
614
+ } else {
615
+ throw new Error('i18n: no data found to replace ' + placeholderWithBraces + ' placeholder in string')
616
+ }
617
+ })
618
+ };
619
+
620
+ /**
621
+ * Check to see if the browser supports Intl and Intl.PluralRules.
622
+ *
623
+ * It requires all conditions to be met in order to be supported:
624
+ * - The browser supports the Intl class (true in IE11)
625
+ * - The implementation of Intl supports PluralRules (NOT true in IE11)
626
+ * - The browser/OS has plural rules for the current locale (browser dependent)
627
+ *
628
+ * @returns {boolean} Returns true if all conditions are met. Returns false otherwise.
629
+ */
630
+ I18n.prototype.hasIntlPluralRulesSupport = function () {
631
+ return Boolean(window.Intl && ('PluralRules' in window.Intl && Intl.PluralRules.supportedLocalesOf(this.locale).length))
632
+ };
633
+
634
+ /**
635
+ * Check to see if the browser supports Intl and Intl.NumberFormat.
636
+ *
637
+ * It requires all conditions to be met in order to be supported:
638
+ * - The browser supports the Intl class (true in IE11)
639
+ * - The implementation of Intl supports NumberFormat (also true in IE11)
640
+ * - The browser/OS has number formatting rules for the current locale (browser dependent)
641
+ *
642
+ * @returns {boolean} Returns true if all conditions are met. Returns false otherwise.
643
+ */
644
+ I18n.prototype.hasIntlNumberFormatSupport = function () {
645
+ return Boolean(window.Intl && ('NumberFormat' in window.Intl && Intl.NumberFormat.supportedLocalesOf(this.locale).length))
646
+ };
647
+
648
+ /**
649
+ * Get the appropriate suffix for the plural form.
650
+ *
651
+ * Uses Intl.PluralRules (or our own fallback implementation) to get the
652
+ * 'preferred' form to use for the given count.
653
+ *
654
+ * Checks that a translation has been provided for that plural form – if it
655
+ * hasn't, it'll fall back to the 'other' plural form (unless that doesn't exist
656
+ * either, in which case an error will be thrown)
657
+ *
658
+ * @param {string} lookupKey - The lookup key of the string to use.
659
+ * @param {number} count - Number used to determine which pluralisation to use.
660
+ * @returns {PluralRule} The suffix associated with the correct pluralisation for this locale.
661
+ * @throws {Error} Plural form `.other` required when preferred plural form is missing
662
+ */
663
+ I18n.prototype.getPluralSuffix = function (lookupKey, count) {
664
+ // Validate that the number is actually a number.
665
+ //
666
+ // Number(count) will turn anything that can't be converted to a Number type
667
+ // into 'NaN'. isFinite filters out NaN, as it isn't a finite number.
668
+ count = Number(count);
669
+ if (!isFinite(count)) { return 'other' }
670
+
671
+ var preferredForm;
672
+
673
+ // Check to verify that all the requirements for Intl.PluralRules are met.
674
+ // If so, we can use that instead of our custom implementation. Otherwise,
675
+ // use the hardcoded fallback.
676
+ if (this.hasIntlPluralRulesSupport()) {
677
+ preferredForm = new Intl.PluralRules(this.locale).select(count);
678
+ } else {
679
+ preferredForm = this.selectPluralFormUsingFallbackRules(count);
680
+ }
681
+
682
+ // Use the correct plural form if provided
683
+ if (lookupKey + '.' + preferredForm in this.translations) {
684
+ return preferredForm
685
+ // Fall back to `other` if the plural form is missing, but log a warning
686
+ // to the console
687
+ } else if (lookupKey + '.other' in this.translations) {
688
+ if (console && 'warn' in console) {
689
+ console.warn('i18n: Missing plural form ".' + preferredForm + '" for "' +
690
+ this.locale + '" locale. Falling back to ".other".');
691
+ }
692
+
693
+ return 'other'
694
+ // If the required `other` plural form is missing, all we can do is error
695
+ } else {
696
+ throw new Error(
697
+ 'i18n: Plural form ".other" is required for "' + this.locale + '" locale'
698
+ )
699
+ }
700
+ };
701
+
702
+ /**
703
+ * Get the plural form using our fallback implementation
704
+ *
705
+ * This is split out into a separate function to make it easier to test the
706
+ * fallback behaviour in an environment where Intl.PluralRules exists.
707
+ *
708
+ * @param {number} count - Number used to determine which pluralisation to use.
709
+ * @returns {PluralRule} The pluralisation form for count in this locale.
710
+ */
711
+ I18n.prototype.selectPluralFormUsingFallbackRules = function (count) {
712
+ // Currently our custom code can only handle positive integers, so let's
713
+ // make sure our number is one of those.
714
+ count = Math.abs(Math.floor(count));
715
+
716
+ var ruleset = this.getPluralRulesForLocale();
717
+
718
+ if (ruleset) {
719
+ return I18n.pluralRules[ruleset](count)
720
+ }
359
721
 
360
- /** Repopulate the internal token lists */
361
- tokenMap = {};
362
- for (i = 0; i < tokens.length; ++i)
363
- tokenMap[tokens[i]] = true;
364
- length = tokens.length;
365
- reindex();
722
+ return 'other'
723
+ };
724
+
725
+ /**
726
+ * Work out which pluralisation rules to use for the current locale
727
+ *
728
+ * The locale may include a regional indicator (such as en-GB), but we don't
729
+ * usually care about this part, as pluralisation rules are usually the same
730
+ * regardless of region. There are exceptions, however, (e.g. Portuguese) so
731
+ * this searches by both the full and shortened locale codes, just to be sure.
732
+ *
733
+ * @returns {PluralRuleName | undefined} The name of the pluralisation rule to use (a key for one
734
+ * of the functions in this.pluralRules)
735
+ */
736
+ I18n.prototype.getPluralRulesForLocale = function () {
737
+ var locale = this.locale;
738
+ var localeShort = locale.split('-')[0];
739
+
740
+ // Look through the plural rules map to find which `pluralRule` is
741
+ // appropriate for our current `locale`.
742
+ for (var pluralRule in I18n.pluralRulesMap) {
743
+ if (Object.prototype.hasOwnProperty.call(I18n.pluralRulesMap, pluralRule)) {
744
+ var languages = I18n.pluralRulesMap[pluralRule];
745
+ for (var i = 0; i < languages.length; i++) {
746
+ if (languages[i] === locale || languages[i] === localeShort) {
747
+ return pluralRule
748
+ }
749
+ }
750
+ }
751
+ }
752
+ };
753
+
754
+ /**
755
+ * Map of plural rules to languages where those rules apply.
756
+ *
757
+ * Note: These groups are named for the most dominant or recognisable language
758
+ * that uses each system. The groupings do not imply that the languages are
759
+ * related to one another. Many languages have evolved the same systems
760
+ * independently of one another.
761
+ *
762
+ * Code to support more languages can be found in the i18n spike:
763
+ * {@link https://github.com/alphagov/govuk-frontend/blob/spike-i18n-support/src/govuk/i18n.mjs}
764
+ *
765
+ * Languages currently supported:
766
+ *
767
+ * Arabic: Arabic (ar)
768
+ * Chinese: Burmese (my), Chinese (zh), Indonesian (id), Japanese (ja),
769
+ * Javanese (jv), Korean (ko), Malay (ms), Thai (th), Vietnamese (vi)
770
+ * French: Armenian (hy), Bangla (bn), French (fr), Gujarati (gu), Hindi (hi),
771
+ * Persian Farsi (fa), Punjabi (pa), Zulu (zu)
772
+ * German: Afrikaans (af), Albanian (sq), Azerbaijani (az), Basque (eu),
773
+ * Bulgarian (bg), Catalan (ca), Danish (da), Dutch (nl), English (en),
774
+ * Estonian (et), Finnish (fi), Georgian (ka), German (de), Greek (el),
775
+ * Hungarian (hu), Luxembourgish (lb), Norwegian (no), Somali (so),
776
+ * Swahili (sw), Swedish (sv), Tamil (ta), Telugu (te), Turkish (tr),
777
+ * Urdu (ur)
778
+ * Irish: Irish Gaelic (ga)
779
+ * Russian: Russian (ru), Ukrainian (uk)
780
+ * Scottish: Scottish Gaelic (gd)
781
+ * Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es)
782
+ * Welsh: Welsh (cy)
783
+ *
784
+ * @type {Object<PluralRuleName, string[]>}
785
+ */
786
+ I18n.pluralRulesMap = {
787
+ arabic: ['ar'],
788
+ chinese: ['my', 'zh', 'id', 'ja', 'jv', 'ko', 'ms', 'th', 'vi'],
789
+ french: ['hy', 'bn', 'fr', 'gu', 'hi', 'fa', 'pa', 'zu'],
790
+ german: [
791
+ 'af', 'sq', 'az', 'eu', 'bg', 'ca', 'da', 'nl', 'en', 'et', 'fi', 'ka',
792
+ 'de', 'el', 'hu', 'lb', 'no', 'so', 'sw', 'sv', 'ta', 'te', 'tr', 'ur'
793
+ ],
794
+ irish: ['ga'],
795
+ russian: ['ru', 'uk'],
796
+ scottish: ['gd'],
797
+ spanish: ['pt-PT', 'it', 'es'],
798
+ welsh: ['cy']
799
+ };
800
+
801
+ /**
802
+ * Different pluralisation rule sets
803
+ *
804
+ * Returns the appropriate suffix for the plural form associated with `n`.
805
+ * Possible suffixes: 'zero', 'one', 'two', 'few', 'many', 'other' (the actual
806
+ * meaning of each differs per locale). 'other' should always exist, even in
807
+ * languages without plurals, such as Chinese.
808
+ * {@link https://cldr.unicode.org/index/cldr-spec/plural-rules}
809
+ *
810
+ * The count must be a positive integer. Negative numbers and decimals aren't accounted for
811
+ *
812
+ * @type {Object<string, function(number): PluralRule>}
813
+ */
814
+ I18n.pluralRules = {
815
+ /* eslint-disable jsdoc/require-jsdoc */
816
+ arabic: function (n) {
817
+ if (n === 0) { return 'zero' }
818
+ if (n === 1) { return 'one' }
819
+ if (n === 2) { return 'two' }
820
+ if (n % 100 >= 3 && n % 100 <= 10) { return 'few' }
821
+ if (n % 100 >= 11 && n % 100 <= 99) { return 'many' }
822
+ return 'other'
823
+ },
824
+ chinese: function () {
825
+ return 'other'
826
+ },
827
+ french: function (n) {
828
+ return n === 0 || n === 1 ? 'one' : 'other'
829
+ },
830
+ german: function (n) {
831
+ return n === 1 ? 'one' : 'other'
832
+ },
833
+ irish: function (n) {
834
+ if (n === 1) { return 'one' }
835
+ if (n === 2) { return 'two' }
836
+ if (n >= 3 && n <= 6) { return 'few' }
837
+ if (n >= 7 && n <= 10) { return 'many' }
838
+ return 'other'
839
+ },
840
+ russian: function (n) {
841
+ var lastTwo = n % 100;
842
+ var last = lastTwo % 10;
843
+ if (last === 1 && lastTwo !== 11) { return 'one' }
844
+ if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) { return 'few' }
845
+ if (last === 0 || (last >= 5 && last <= 9) || (lastTwo >= 11 && lastTwo <= 14)) { return 'many' }
846
+ // Note: The 'other' suffix is only used by decimal numbers in Russian.
847
+ // We don't anticipate it being used, but it's here for consistency.
848
+ return 'other'
849
+ },
850
+ scottish: function (n) {
851
+ if (n === 1 || n === 11) { return 'one' }
852
+ if (n === 2 || n === 12) { return 'two' }
853
+ if ((n >= 3 && n <= 10) || (n >= 13 && n <= 19)) { return 'few' }
854
+ return 'other'
855
+ },
856
+ spanish: function (n) {
857
+ if (n === 1) { return 'one' }
858
+ if (n % 1000000 === 0 && n !== 0) { return 'many' }
859
+ return 'other'
860
+ },
861
+ welsh: function (n) {
862
+ if (n === 0) { return 'zero' }
863
+ if (n === 1) { return 'one' }
864
+ if (n === 2) { return 'two' }
865
+ if (n === 3) { return 'few' }
866
+ if (n === 6) { return 'many' }
867
+ return 'other'
868
+ }
869
+ /* eslint-enable jsdoc/require-jsdoc */
870
+ };
871
+
872
+ /**
873
+ * Supported languages for plural rules
874
+ *
875
+ * @typedef {'arabic' | 'chinese' | 'french' | 'german' | 'irish' | 'russian' | 'scottish' | 'spanish' | 'welsh'} PluralRuleName
876
+ */
877
+
878
+ /**
879
+ * Plural rule category mnemonic tags
880
+ *
881
+ * @typedef {'zero' | 'one' | 'two' | 'few' | 'many' | 'other'} PluralRule
882
+ */
883
+
884
+ /**
885
+ * Translated message by plural rule they correspond to.
886
+ *
887
+ * Allows to group pluralised messages under a single key when passing
888
+ * translations to a component's constructor
889
+ *
890
+ * @typedef {object} TranslationPluralForms
891
+ * @property {string} [other] - General plural form
892
+ * @property {string} [zero] - Plural form used with 0
893
+ * @property {string} [one] - Plural form used with 1
894
+ * @property {string} [two] - Plural form used with 2
895
+ * @property {string} [few] - Plural form used for a few
896
+ * @property {string} [many] - Plural form used for many
897
+ */
898
+
899
+ (function(undefined) {
900
+
901
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
902
+ var detect = (
903
+ 'DOMTokenList' in this && (function (x) {
904
+ return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
905
+ })(document.createElement('x'))
906
+ );
907
+
908
+ if (detect) return
909
+
910
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
911
+ (function (global) {
912
+ var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
913
+
914
+ if (
915
+ !nativeImpl ||
916
+ (
917
+ !!document.createElementNS &&
918
+ !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
919
+ !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
920
+ )
921
+ ) {
922
+ global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
923
+ var dpSupport = true;
924
+ var defineGetter = function (object, name, fn, configurable) {
925
+ if (Object.defineProperty)
926
+ Object.defineProperty(object, name, {
927
+ configurable: false === dpSupport ? true : !!configurable,
928
+ get: fn
929
+ });
930
+
931
+ else object.__defineGetter__(name, fn);
366
932
  };
367
933
 
368
- /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
369
- preop();
934
+ /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
935
+ try {
936
+ defineGetter({}, "support");
937
+ }
938
+ catch (e) {
939
+ dpSupport = false;
940
+ }
941
+
942
+
943
+ var _DOMTokenList = function (el, prop) {
944
+ var that = this;
945
+ var tokens = [];
946
+ var tokenMap = {};
947
+ var length = 0;
948
+ var maxLength = 0;
949
+ var addIndexGetter = function (i) {
950
+ defineGetter(that, i, function () {
951
+ preop();
952
+ return tokens[i];
953
+ }, false);
954
+
955
+ };
956
+ var reindex = function () {
957
+
958
+ /** Define getter functions for array-like access to the tokenList's contents. */
959
+ if (length >= maxLength)
960
+ for (; maxLength < length; ++maxLength) {
961
+ addIndexGetter(maxLength);
962
+ }
963
+ };
964
+
965
+ /** Helper function called at the start of each class method. Internal use only. */
966
+ var preop = function () {
967
+ var error;
968
+ var i;
969
+ var args = arguments;
970
+ var rSpace = /\s+/;
971
+
972
+ /** Validate the token/s passed to an instance method, if any. */
973
+ if (args.length)
974
+ for (i = 0; i < args.length; ++i)
975
+ if (rSpace.test(args[i])) {
976
+ error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
977
+ error.code = 5;
978
+ error.name = "InvalidCharacterError";
979
+ throw error;
980
+ }
981
+
982
+
983
+ /** Split the new value apart by whitespace*/
984
+ if (typeof el[prop] === "object") {
985
+ tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
986
+ } else {
987
+ tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
988
+ }
989
+
990
+ /** Avoid treating blank strings as single-item token lists */
991
+ if ("" === tokens[0]) tokens = [];
370
992
 
371
- /** Return the number of tokens in the underlying string. Read-only. */
372
- defineGetter(that, "length", function () {
993
+ /** Repopulate the internal token lists */
994
+ tokenMap = {};
995
+ for (i = 0; i < tokens.length; ++i)
996
+ tokenMap[tokens[i]] = true;
997
+ length = tokens.length;
998
+ reindex();
999
+ };
1000
+
1001
+ /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
373
1002
  preop();
374
- return length;
375
- });
376
1003
 
377
- /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
378
- that.toLocaleString =
379
- that.toString = function () {
1004
+ /** Return the number of tokens in the underlying string. Read-only. */
1005
+ defineGetter(that, "length", function () {
1006
+ preop();
1007
+ return length;
1008
+ });
1009
+
1010
+ /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
1011
+ that.toLocaleString =
1012
+ that.toString = function () {
1013
+ preop();
1014
+ return tokens.join(" ");
1015
+ };
1016
+
1017
+ that.item = function (idx) {
380
1018
  preop();
381
- return tokens.join(" ");
1019
+ return tokens[idx];
382
1020
  };
383
1021
 
384
- that.item = function (idx) {
385
- preop();
386
- return tokens[idx];
387
- };
1022
+ that.contains = function (token) {
1023
+ preop();
1024
+ return !!tokenMap[token];
1025
+ };
388
1026
 
389
- that.contains = function (token) {
390
- preop();
391
- return !!tokenMap[token];
392
- };
1027
+ that.add = function () {
1028
+ preop.apply(that, args = arguments);
393
1029
 
394
- that.add = function () {
395
- preop.apply(that, args = arguments);
1030
+ for (var args, token, i = 0, l = args.length; i < l; ++i) {
1031
+ token = args[i];
1032
+ if (!tokenMap[token]) {
1033
+ tokens.push(token);
1034
+ tokenMap[token] = true;
1035
+ }
1036
+ }
396
1037
 
397
- for (var args, token, i = 0, l = args.length; i < l; ++i) {
398
- token = args[i];
399
- if (!tokenMap[token]) {
400
- tokens.push(token);
401
- tokenMap[token] = true;
1038
+ /** Update the targeted attribute of the attached element if the token list's changed. */
1039
+ if (length !== tokens.length) {
1040
+ length = tokens.length >>> 0;
1041
+ if (typeof el[prop] === "object") {
1042
+ el[prop].baseVal = tokens.join(" ");
1043
+ } else {
1044
+ el[prop] = tokens.join(" ");
1045
+ }
1046
+ reindex();
402
1047
  }
403
- }
1048
+ };
1049
+
1050
+ that.remove = function () {
1051
+ preop.apply(that, args = arguments);
1052
+
1053
+ /** Build a hash of token names to compare against when recollecting our token list. */
1054
+ for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
1055
+ ignore[args[i]] = true;
1056
+ delete tokenMap[args[i]];
1057
+ }
1058
+
1059
+ /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
1060
+ for (i = 0; i < tokens.length; ++i)
1061
+ if (!ignore[tokens[i]]) t.push(tokens[i]);
404
1062
 
405
- /** Update the targeted attribute of the attached element if the token list's changed. */
406
- if (length !== tokens.length) {
407
- length = tokens.length >>> 0;
1063
+ tokens = t;
1064
+ length = t.length >>> 0;
1065
+
1066
+ /** Update the targeted attribute of the attached element. */
408
1067
  if (typeof el[prop] === "object") {
409
1068
  el[prop].baseVal = tokens.join(" ");
410
1069
  } else {
411
1070
  el[prop] = tokens.join(" ");
412
1071
  }
413
1072
  reindex();
414
- }
415
- };
416
-
417
- that.remove = function () {
418
- preop.apply(that, args = arguments);
419
-
420
- /** Build a hash of token names to compare against when recollecting our token list. */
421
- for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
422
- ignore[args[i]] = true;
423
- delete tokenMap[args[i]];
424
- }
425
-
426
- /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
427
- for (i = 0; i < tokens.length; ++i)
428
- if (!ignore[tokens[i]]) t.push(tokens[i]);
429
-
430
- tokens = t;
431
- length = t.length >>> 0;
432
-
433
- /** Update the targeted attribute of the attached element. */
434
- if (typeof el[prop] === "object") {
435
- el[prop].baseVal = tokens.join(" ");
436
- } else {
437
- el[prop] = tokens.join(" ");
438
- }
439
- reindex();
440
- };
1073
+ };
441
1074
 
442
- that.toggle = function (token, force) {
443
- preop.apply(that, [token]);
1075
+ that.toggle = function (token, force) {
1076
+ preop.apply(that, [token]);
1077
+
1078
+ /** Token state's being forced. */
1079
+ if (undefined !== force) {
1080
+ if (force) {
1081
+ that.add(token);
1082
+ return true;
1083
+ } else {
1084
+ that.remove(token);
1085
+ return false;
1086
+ }
1087
+ }
444
1088
 
445
- /** Token state's being forced. */
446
- if (undefined !== force) {
447
- if (force) {
448
- that.add(token);
449
- return true;
450
- } else {
1089
+ /** Token already exists in tokenList. Remove it, and return FALSE. */
1090
+ if (tokenMap[token]) {
451
1091
  that.remove(token);
452
1092
  return false;
453
1093
  }
454
- }
455
1094
 
456
- /** Token already exists in tokenList. Remove it, and return FALSE. */
457
- if (tokenMap[token]) {
458
- that.remove(token);
459
- return false;
460
- }
1095
+ /** Otherwise, add the token and return TRUE. */
1096
+ that.add(token);
1097
+ return true;
1098
+ };
461
1099
 
462
- /** Otherwise, add the token and return TRUE. */
463
- that.add(token);
464
- return true;
1100
+ return that;
465
1101
  };
466
1102
 
467
- return that;
1103
+ return _DOMTokenList;
1104
+ }());
1105
+ }
1106
+
1107
+ // Add second argument to native DOMTokenList.toggle() if necessary
1108
+ (function () {
1109
+ var e = document.createElement('span');
1110
+ if (!('classList' in e)) return;
1111
+ e.classList.toggle('x', false);
1112
+ if (!e.classList.contains('x')) return;
1113
+ e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
1114
+ var force = arguments[1];
1115
+ if (force === undefined) {
1116
+ var add = !this.contains(token);
1117
+ this[add ? 'add' : 'remove'](token);
1118
+ return add;
1119
+ }
1120
+ force = !!force;
1121
+ this[force ? 'add' : 'remove'](token);
1122
+ return force;
468
1123
  };
1124
+ }());
469
1125
 
470
- return _DOMTokenList;
1126
+ // Add multiple arguments to native DOMTokenList.add() if necessary
1127
+ (function () {
1128
+ var e = document.createElement('span');
1129
+ if (!('classList' in e)) return;
1130
+ e.classList.add('a', 'b');
1131
+ if (e.classList.contains('b')) return;
1132
+ var native = e.classList.constructor.prototype.add;
1133
+ e.classList.constructor.prototype.add = function () {
1134
+ var args = arguments;
1135
+ var l = arguments.length;
1136
+ for (var i = 0; i < l; i++) {
1137
+ native.call(this, args[i]);
1138
+ }
1139
+ };
471
1140
  }());
472
- }
473
1141
 
474
- // Add second argument to native DOMTokenList.toggle() if necessary
475
- (function () {
476
- var e = document.createElement('span');
477
- if (!('classList' in e)) return;
478
- e.classList.toggle('x', false);
479
- if (!e.classList.contains('x')) return;
480
- e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
481
- var force = arguments[1];
482
- if (force === undefined) {
483
- var add = !this.contains(token);
484
- this[add ? 'add' : 'remove'](token);
485
- return add;
486
- }
487
- force = !!force;
488
- this[force ? 'add' : 'remove'](token);
489
- return force;
490
- };
491
- }());
492
-
493
- // Add multiple arguments to native DOMTokenList.add() if necessary
494
- (function () {
495
- var e = document.createElement('span');
496
- if (!('classList' in e)) return;
497
- e.classList.add('a', 'b');
498
- if (e.classList.contains('b')) return;
499
- var native = e.classList.constructor.prototype.add;
500
- e.classList.constructor.prototype.add = function () {
501
- var args = arguments;
502
- var l = arguments.length;
503
- for (var i = 0; i < l; i++) {
504
- native.call(this, args[i]);
505
- }
1142
+ // Add multiple arguments to native DOMTokenList.remove() if necessary
1143
+ (function () {
1144
+ var e = document.createElement('span');
1145
+ if (!('classList' in e)) return;
1146
+ e.classList.add('a');
1147
+ e.classList.add('b');
1148
+ e.classList.remove('a', 'b');
1149
+ if (!e.classList.contains('b')) return;
1150
+ var native = e.classList.constructor.prototype.remove;
1151
+ e.classList.constructor.prototype.remove = function () {
1152
+ var args = arguments;
1153
+ var l = arguments.length;
1154
+ for (var i = 0; i < l; i++) {
1155
+ native.call(this, args[i]);
1156
+ }
1157
+ };
1158
+ }());
1159
+
1160
+ }(this));
1161
+
1162
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1163
+
1164
+ (function(undefined) {
1165
+
1166
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
1167
+ var detect = (
1168
+ 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
1169
+ var e = document.createElement('span');
1170
+ e.classList.add('a', 'b');
1171
+ return e.classList.contains('b');
1172
+ }())
1173
+ );
1174
+
1175
+ if (detect) return
1176
+
1177
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
1178
+ (function (global) {
1179
+ var dpSupport = true;
1180
+ var defineGetter = function (object, name, fn, configurable) {
1181
+ if (Object.defineProperty)
1182
+ Object.defineProperty(object, name, {
1183
+ configurable: false === dpSupport ? true : !!configurable,
1184
+ get: fn
1185
+ });
1186
+
1187
+ else object.__defineGetter__(name, fn);
506
1188
  };
507
- }());
508
-
509
- // Add multiple arguments to native DOMTokenList.remove() if necessary
510
- (function () {
511
- var e = document.createElement('span');
512
- if (!('classList' in e)) return;
513
- e.classList.add('a');
514
- e.classList.add('b');
515
- e.classList.remove('a', 'b');
516
- if (!e.classList.contains('b')) return;
517
- var native = e.classList.constructor.prototype.remove;
518
- e.classList.constructor.prototype.remove = function () {
519
- var args = arguments;
520
- var l = arguments.length;
521
- for (var i = 0; i < l; i++) {
522
- native.call(this, args[i]);
523
- }
1189
+ /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
1190
+ try {
1191
+ defineGetter({}, "support");
1192
+ }
1193
+ catch (e) {
1194
+ dpSupport = false;
1195
+ }
1196
+ /** Polyfills a property with a DOMTokenList */
1197
+ var addProp = function (o, name, attr) {
1198
+
1199
+ defineGetter(o.prototype, name, function () {
1200
+ var tokenList;
1201
+
1202
+ var THIS = this,
1203
+
1204
+ /** Prevent this from firing twice for some reason. What the hell, IE. */
1205
+ gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
1206
+ if(THIS[gibberishProperty]) return tokenList;
1207
+ THIS[gibberishProperty] = true;
1208
+
1209
+ /**
1210
+ * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
1211
+ *
1212
+ * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
1213
+ * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
1214
+ * element instead, this would conflict with element types which use indexed properties (such as forms and
1215
+ * select lists).
1216
+ */
1217
+ if (false === dpSupport) {
1218
+
1219
+ var visage;
1220
+ var mirror = addProp.mirror || document.createElement("div");
1221
+ var reflections = mirror.childNodes;
1222
+ var l = reflections.length;
1223
+
1224
+ for (var i = 0; i < l; ++i)
1225
+ if (reflections[i]._R === THIS) {
1226
+ visage = reflections[i];
1227
+ break;
1228
+ }
1229
+
1230
+ /** Couldn't find an element's reflection inside the mirror. Materialise one. */
1231
+ visage || (visage = mirror.appendChild(document.createElement("div")));
1232
+
1233
+ tokenList = DOMTokenList.call(visage, THIS, attr);
1234
+ } else tokenList = new DOMTokenList(THIS, attr);
1235
+
1236
+ defineGetter(THIS, name, function () {
1237
+ return tokenList;
1238
+ });
1239
+ delete THIS[gibberishProperty];
1240
+
1241
+ return tokenList;
1242
+ }, true);
524
1243
  };
525
- }());
526
1244
 
527
- }(this));
1245
+ addProp(global.Element, "classList", "className");
1246
+ addProp(global.HTMLElement, "classList", "className");
1247
+ addProp(global.HTMLLinkElement, "relList", "rel");
1248
+ addProp(global.HTMLAnchorElement, "relList", "rel");
1249
+ addProp(global.HTMLAreaElement, "relList", "rel");
1250
+ }(this));
528
1251
 
529
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1252
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
530
1253
 
531
- (function(undefined) {
1254
+ (function(undefined) {
532
1255
 
533
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
534
- var detect = ("Document" in this);
1256
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js
1257
+ var detect = (
1258
+ 'document' in this && "matches" in document.documentElement
1259
+ );
535
1260
 
536
- if (detect) return
1261
+ if (detect) return
537
1262
 
538
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
539
- if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
1263
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js
1264
+ Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
1265
+ var element = this;
1266
+ var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
1267
+ var index = 0;
540
1268
 
541
- if (this.HTMLDocument) { // IE8
1269
+ while (elements[index] && elements[index] !== element) {
1270
+ ++index;
1271
+ }
542
1272
 
543
- // HTMLDocument is an extension of Document. If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
544
- this.Document = this.HTMLDocument;
1273
+ return !!elements[index];
1274
+ };
545
1275
 
546
- } else {
1276
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
547
1277
 
548
- // Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype. The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made.
549
- this.Document = this.HTMLDocument = document.constructor = (new Function('return function Document() {}')());
550
- this.Document.prototype = document;
551
- }
552
- }
1278
+ (function(undefined) {
553
1279
 
1280
+ // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/detect.js
1281
+ var detect = (
1282
+ 'document' in this && "closest" in document.documentElement
1283
+ );
554
1284
 
555
- })
556
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1285
+ if (detect) return
557
1286
 
558
- (function(undefined) {
1287
+ // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/polyfill.js
1288
+ Element.prototype.closest = function closest(selector) {
1289
+ var node = this;
559
1290
 
560
- // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
561
- var detect = ('Element' in this && 'HTMLElement' in this);
562
-
563
- if (detect) return
564
-
565
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
566
- (function () {
1291
+ while (node) {
1292
+ if (node.matches(selector)) return node;
1293
+ else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
1294
+ }
567
1295
 
568
- // IE8
569
- if (window.Element && !window.HTMLElement) {
570
- window.HTMLElement = window.Element;
571
- return;
572
- }
1296
+ return null;
1297
+ };
573
1298
 
574
- // create Element constructor
575
- window.Element = window.HTMLElement = new Function('return function Element() {}')();
1299
+ }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
576
1300
 
577
- // generate sandboxed iframe
578
- var vbody = document.appendChild(document.createElement('body'));
579
- var frame = vbody.appendChild(document.createElement('iframe'));
1301
+ (function(undefined) {
580
1302
 
581
- // use sandboxed iframe to replicate Element functionality
582
- var frameDocument = frame.contentWindow.document;
583
- var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
584
- var cache = {};
1303
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
1304
+ var detect = ('Window' in this);
585
1305
 
586
- // polyfill Element.prototype on an element
587
- var shiv = function (element, deep) {
588
- var
589
- childNodes = element.childNodes || [],
590
- index = -1,
591
- key, value, childNode;
1306
+ if (detect) return
592
1307
 
593
- if (element.nodeType === 1 && element.constructor !== Element) {
594
- element.constructor = Element;
1308
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
1309
+ if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
1310
+ (function (global) {
1311
+ if (global.constructor) {
1312
+ global.Window = global.constructor;
1313
+ } else {
1314
+ (global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
1315
+ }
1316
+ }(this));
1317
+ }
595
1318
 
596
- for (key in cache) {
597
- value = cache[key];
598
- element[key] = value;
599
- }
600
- }
1319
+ })
1320
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
601
1321
 
602
- while (childNode = deep && childNodes[++index]) {
603
- shiv(childNode, deep);
604
- }
1322
+ (function(undefined) {
605
1323
 
606
- return element;
607
- };
1324
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
1325
+ var detect = (
1326
+ (function(global) {
608
1327
 
609
- var elements = document.getElementsByTagName('*');
610
- var nativeCreateElement = document.createElement;
611
- var interval;
612
- var loopLimit = 100;
1328
+ if (!('Event' in global)) return false;
1329
+ if (typeof global.Event === 'function') return true;
613
1330
 
614
- prototype.attachEvent('onpropertychange', function (event) {
615
- var
616
- propertyName = event.propertyName,
617
- nonValue = !cache.hasOwnProperty(propertyName),
618
- newValue = prototype[propertyName],
619
- oldValue = cache[propertyName],
620
- index = -1,
621
- element;
1331
+ try {
622
1332
 
623
- while (element = elements[++index]) {
624
- if (element.nodeType === 1) {
625
- if (nonValue || element[propertyName] === oldValue) {
626
- element[propertyName] = newValue;
627
- }
628
- }
629
- }
630
-
631
- cache[propertyName] = newValue;
632
- });
633
-
634
- prototype.constructor = Element;
635
-
636
- if (!prototype.hasAttribute) {
637
- // <Element>.hasAttribute
638
- prototype.hasAttribute = function hasAttribute(name) {
639
- return this.getAttribute(name) !== null;
640
- };
641
- }
642
-
643
- // Apply Element prototype to the pre-existing DOM as soon as the body element appears.
644
- function bodyCheck() {
645
- if (!(loopLimit--)) clearTimeout(interval);
646
- if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
647
- shiv(document, true);
648
- if (interval && document.body.prototype) clearTimeout(interval);
649
- return (!!document.body.prototype);
650
- }
651
- return false;
652
- }
653
- if (!bodyCheck()) {
654
- document.onreadystatechange = bodyCheck;
655
- interval = setInterval(bodyCheck, 25);
656
- }
657
-
658
- // Apply to any new elements created after load
659
- document.createElement = function createElement(nodeName) {
660
- var element = nativeCreateElement(String(nodeName).toLowerCase());
661
- return shiv(element);
662
- };
663
-
664
- // remove sandboxed iframe
665
- document.removeChild(vbody);
666
- }());
667
-
668
- })
669
- .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
670
-
671
- (function(undefined) {
672
-
673
- // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
674
- var detect = (
675
- 'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
676
- var e = document.createElement('span');
677
- e.classList.add('a', 'b');
678
- return e.classList.contains('b');
679
- }())
680
- );
1333
+ // In IE 9-11, the Event object exists but cannot be instantiated
1334
+ new Event('click');
1335
+ return true;
1336
+ } catch(e) {
1337
+ return false;
1338
+ }
1339
+ }(this))
1340
+ );
1341
+
1342
+ if (detect) return
1343
+
1344
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
1345
+ (function () {
1346
+ var unlistenableWindowEvents = {
1347
+ click: 1,
1348
+ dblclick: 1,
1349
+ keyup: 1,
1350
+ keypress: 1,
1351
+ keydown: 1,
1352
+ mousedown: 1,
1353
+ mouseup: 1,
1354
+ mousemove: 1,
1355
+ mouseover: 1,
1356
+ mouseenter: 1,
1357
+ mouseleave: 1,
1358
+ mouseout: 1,
1359
+ storage: 1,
1360
+ storagecommit: 1,
1361
+ textinput: 1
1362
+ };
1363
+
1364
+ // This polyfill depends on availability of `document` so will not run in a worker
1365
+ // However, we asssume there are no browsers with worker support that lack proper
1366
+ // support for `Event` within the worker
1367
+ if (typeof document === 'undefined' || typeof window === 'undefined') return;
1368
+
1369
+ function indexOf(array, element) {
1370
+ var
1371
+ index = -1,
1372
+ length = array.length;
1373
+
1374
+ while (++index < length) {
1375
+ if (index in array && array[index] === element) {
1376
+ return index;
1377
+ }
1378
+ }
1379
+
1380
+ return -1;
1381
+ }
1382
+
1383
+ var existingProto = (window.Event && window.Event.prototype) || null;
1384
+ window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
1385
+ if (!type) {
1386
+ throw new Error('Not enough arguments');
1387
+ }
1388
+
1389
+ var event;
1390
+ // Shortcut if browser supports createEvent
1391
+ if ('createEvent' in document) {
1392
+ event = document.createEvent('Event');
1393
+ var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
1394
+ var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
1395
+
1396
+ event.initEvent(type, bubbles, cancelable);
1397
+
1398
+ return event;
1399
+ }
1400
+
1401
+ event = document.createEventObject();
1402
+
1403
+ event.type = type;
1404
+ event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
1405
+ event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
1406
+
1407
+ return event;
1408
+ };
1409
+ if (existingProto) {
1410
+ Object.defineProperty(window.Event, 'prototype', {
1411
+ configurable: false,
1412
+ enumerable: false,
1413
+ writable: true,
1414
+ value: existingProto
1415
+ });
1416
+ }
1417
+
1418
+ if (!('createEvent' in document)) {
1419
+ window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
1420
+ var
1421
+ element = this,
1422
+ type = arguments[0],
1423
+ listener = arguments[1];
1424
+
1425
+ if (element === window && type in unlistenableWindowEvents) {
1426
+ throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
1427
+ }
1428
+
1429
+ if (!element._events) {
1430
+ element._events = {};
1431
+ }
1432
+
1433
+ if (!element._events[type]) {
1434
+ element._events[type] = function (event) {
1435
+ var
1436
+ list = element._events[event.type].list,
1437
+ events = list.slice(),
1438
+ index = -1,
1439
+ length = events.length,
1440
+ eventElement;
1441
+
1442
+ event.preventDefault = function preventDefault() {
1443
+ if (event.cancelable !== false) {
1444
+ event.returnValue = false;
1445
+ }
1446
+ };
1447
+
1448
+ event.stopPropagation = function stopPropagation() {
1449
+ event.cancelBubble = true;
1450
+ };
1451
+
1452
+ event.stopImmediatePropagation = function stopImmediatePropagation() {
1453
+ event.cancelBubble = true;
1454
+ event.cancelImmediate = true;
1455
+ };
1456
+
1457
+ event.currentTarget = element;
1458
+ event.relatedTarget = event.fromElement || null;
1459
+ event.target = event.target || event.srcElement || element;
1460
+ event.timeStamp = new Date().getTime();
1461
+
1462
+ if (event.clientX) {
1463
+ event.pageX = event.clientX + document.documentElement.scrollLeft;
1464
+ event.pageY = event.clientY + document.documentElement.scrollTop;
1465
+ }
1466
+
1467
+ while (++index < length && !event.cancelImmediate) {
1468
+ if (index in events) {
1469
+ eventElement = events[index];
1470
+
1471
+ if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
1472
+ eventElement.call(element, event);
1473
+ }
1474
+ }
1475
+ }
1476
+ };
1477
+
1478
+ element._events[type].list = [];
1479
+
1480
+ if (element.attachEvent) {
1481
+ element.attachEvent('on' + type, element._events[type]);
1482
+ }
1483
+ }
1484
+
1485
+ element._events[type].list.push(listener);
1486
+ };
1487
+
1488
+ window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
1489
+ var
1490
+ element = this,
1491
+ type = arguments[0],
1492
+ listener = arguments[1],
1493
+ index;
1494
+
1495
+ if (element._events && element._events[type] && element._events[type].list) {
1496
+ index = indexOf(element._events[type].list, listener);
1497
+
1498
+ if (index !== -1) {
1499
+ element._events[type].list.splice(index, 1);
1500
+
1501
+ if (!element._events[type].list.length) {
1502
+ if (element.detachEvent) {
1503
+ element.detachEvent('on' + type, element._events[type]);
1504
+ }
1505
+ delete element._events[type];
1506
+ }
1507
+ }
1508
+ }
1509
+ };
1510
+
1511
+ window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
1512
+ if (!arguments.length) {
1513
+ throw new Error('Not enough arguments');
1514
+ }
1515
+
1516
+ if (!event || typeof event.type !== 'string') {
1517
+ throw new Error('DOM Events Exception 0');
1518
+ }
1519
+
1520
+ var element = this, type = event.type;
1521
+
1522
+ try {
1523
+ if (!event.bubbles) {
1524
+ event.cancelBubble = true;
1525
+
1526
+ var cancelBubbleEvent = function (event) {
1527
+ event.cancelBubble = true;
1528
+
1529
+ (element || window).detachEvent('on' + type, cancelBubbleEvent);
1530
+ };
1531
+
1532
+ this.attachEvent('on' + type, cancelBubbleEvent);
1533
+ }
1534
+
1535
+ this.fireEvent('on' + type, event);
1536
+ } catch (error) {
1537
+ event.target = element;
1538
+
1539
+ do {
1540
+ event.currentTarget = element;
1541
+
1542
+ if ('_events' in element && typeof element._events[type] === 'function') {
1543
+ element._events[type].call(element, event);
1544
+ }
1545
+
1546
+ if (typeof element['on' + type] === 'function') {
1547
+ element['on' + type].call(element, event);
1548
+ }
1549
+
1550
+ element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
1551
+ } while (element && !event.cancelBubble);
1552
+ }
1553
+
1554
+ return true;
1555
+ };
1556
+
1557
+ // Add the DOMContentLoaded Event
1558
+ document.attachEvent('onreadystatechange', function() {
1559
+ if (document.readyState === 'complete') {
1560
+ document.dispatchEvent(new Event('DOMContentLoaded', {
1561
+ bubbles: true
1562
+ }));
1563
+ }
1564
+ });
1565
+ }
1566
+ }());
1567
+
1568
+ })
1569
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1570
+
1571
+ (function(undefined) {
1572
+ // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
1573
+ var detect = 'bind' in Function.prototype;
681
1574
 
682
1575
  if (detect) return
683
1576
 
684
- // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
685
- (function (global) {
686
- var dpSupport = true;
687
- var defineGetter = function (object, name, fn, configurable) {
688
- if (Object.defineProperty)
689
- Object.defineProperty(object, name, {
690
- configurable: false === dpSupport ? true : !!configurable,
691
- get: fn
692
- });
693
-
694
- else object.__defineGetter__(name, fn);
695
- };
696
- /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
697
- try {
698
- defineGetter({}, "support");
699
- }
700
- catch (e) {
701
- dpSupport = false;
702
- }
703
- /** Polyfills a property with a DOMTokenList */
704
- var addProp = function (o, name, attr) {
705
-
706
- defineGetter(o.prototype, name, function () {
707
- var tokenList;
708
-
709
- var THIS = this,
710
-
711
- /** Prevent this from firing twice for some reason. What the hell, IE. */
712
- gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
713
- if(THIS[gibberishProperty]) return tokenList;
714
- THIS[gibberishProperty] = true;
715
-
716
- /**
717
- * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
718
- *
719
- * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
720
- * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
721
- * element instead, this would conflict with element types which use indexed properties (such as forms and
722
- * select lists).
723
- */
724
- if (false === dpSupport) {
725
-
726
- var visage;
727
- var mirror = addProp.mirror || document.createElement("div");
728
- var reflections = mirror.childNodes;
729
- var l = reflections.length;
730
-
731
- for (var i = 0; i < l; ++i)
732
- if (reflections[i]._R === THIS) {
733
- visage = reflections[i];
734
- break;
735
- }
736
-
737
- /** Couldn't find an element's reflection inside the mirror. Materialise one. */
738
- visage || (visage = mirror.appendChild(document.createElement("div")));
739
-
740
- tokenList = DOMTokenList.call(visage, THIS, attr);
741
- } else tokenList = new DOMTokenList(THIS, attr);
742
-
743
- defineGetter(THIS, name, function () {
744
- return tokenList;
745
- });
746
- delete THIS[gibberishProperty];
1577
+ // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
1578
+ Object.defineProperty(Function.prototype, 'bind', {
1579
+ value: function bind(that) { // .length is 1
1580
+ // add necessary es5-shim utilities
1581
+ var $Array = Array;
1582
+ var $Object = Object;
1583
+ var ObjectPrototype = $Object.prototype;
1584
+ var ArrayPrototype = $Array.prototype;
1585
+ var Empty = function Empty() {};
1586
+ var to_string = ObjectPrototype.toString;
1587
+ var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
1588
+ var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
1589
+ var array_slice = ArrayPrototype.slice;
1590
+ var array_concat = ArrayPrototype.concat;
1591
+ var array_push = ArrayPrototype.push;
1592
+ var max = Math.max;
1593
+ // /add necessary es5-shim utilities
1594
+
1595
+ // 1. Let Target be the this value.
1596
+ var target = this;
1597
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
1598
+ if (!isCallable(target)) {
1599
+ throw new TypeError('Function.prototype.bind called on incompatible ' + target);
1600
+ }
1601
+ // 3. Let A be a new (possibly empty) internal list of all of the
1602
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
1603
+ // XXX slicedArgs will stand in for "A" if used
1604
+ var args = array_slice.call(arguments, 1); // for normal call
1605
+ // 4. Let F be a new native ECMAScript object.
1606
+ // 11. Set the [[Prototype]] internal property of F to the standard
1607
+ // built-in Function prototype object as specified in 15.3.3.1.
1608
+ // 12. Set the [[Call]] internal property of F as described in
1609
+ // 15.3.4.5.1.
1610
+ // 13. Set the [[Construct]] internal property of F as described in
1611
+ // 15.3.4.5.2.
1612
+ // 14. Set the [[HasInstance]] internal property of F as described in
1613
+ // 15.3.4.5.3.
1614
+ var bound;
1615
+ var binder = function () {
1616
+
1617
+ if (this instanceof bound) {
1618
+ // 15.3.4.5.2 [[Construct]]
1619
+ // When the [[Construct]] internal method of a function object,
1620
+ // F that was created using the bind function is called with a
1621
+ // list of arguments ExtraArgs, the following steps are taken:
1622
+ // 1. Let target be the value of F's [[TargetFunction]]
1623
+ // internal property.
1624
+ // 2. If target has no [[Construct]] internal method, a
1625
+ // TypeError exception is thrown.
1626
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
1627
+ // property.
1628
+ // 4. Let args be a new list containing the same values as the
1629
+ // list boundArgs in the same order followed by the same
1630
+ // values as the list ExtraArgs in the same order.
1631
+ // 5. Return the result of calling the [[Construct]] internal
1632
+ // method of target providing args as the arguments.
1633
+
1634
+ var result = target.apply(
1635
+ this,
1636
+ array_concat.call(args, array_slice.call(arguments))
1637
+ );
1638
+ if ($Object(result) === result) {
1639
+ return result;
1640
+ }
1641
+ return this;
747
1642
 
748
- return tokenList;
749
- }, true);
750
- };
1643
+ } else {
1644
+ // 15.3.4.5.1 [[Call]]
1645
+ // When the [[Call]] internal method of a function object, F,
1646
+ // which was created using the bind function is called with a
1647
+ // this value and a list of arguments ExtraArgs, the following
1648
+ // steps are taken:
1649
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
1650
+ // property.
1651
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
1652
+ // property.
1653
+ // 3. Let target be the value of F's [[TargetFunction]] internal
1654
+ // property.
1655
+ // 4. Let args be a new list containing the same values as the
1656
+ // list boundArgs in the same order followed by the same
1657
+ // values as the list ExtraArgs in the same order.
1658
+ // 5. Return the result of calling the [[Call]] internal method
1659
+ // of target providing boundThis as the this value and
1660
+ // providing args as the arguments.
1661
+
1662
+ // equiv: target.call(this, ...boundArgs, ...args)
1663
+ return target.apply(
1664
+ that,
1665
+ array_concat.call(args, array_slice.call(arguments))
1666
+ );
751
1667
 
752
- addProp(global.Element, "classList", "className");
753
- addProp(global.HTMLElement, "classList", "className");
754
- addProp(global.HTMLLinkElement, "relList", "rel");
755
- addProp(global.HTMLAnchorElement, "relList", "rel");
756
- addProp(global.HTMLAreaElement, "relList", "rel");
757
- }(this));
758
-
759
- }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
760
-
761
- function Accordion ($module) {
762
- this.$module = $module;
763
- this.moduleId = $module.getAttribute('id');
764
- this.$sections = $module.querySelectorAll('.govuk-accordion__section');
765
- this.$showAllButton = '';
766
- this.browserSupportsSessionStorage = helper.checkForSessionStorage();
767
-
768
- this.controlsClass = 'govuk-accordion__controls';
769
- this.showAllClass = 'govuk-accordion__show-all';
770
- this.showAllTextClass = 'govuk-accordion__show-all-text';
771
-
772
- this.sectionExpandedClass = 'govuk-accordion__section--expanded';
773
- this.sectionButtonClass = 'govuk-accordion__section-button';
774
- this.sectionHeaderClass = 'govuk-accordion__section-header';
775
- this.sectionHeadingClass = 'govuk-accordion__section-heading';
776
- this.sectionHeadingTextClass = 'govuk-accordion__section-heading-text';
777
- this.sectionHeadingTextFocusClass = 'govuk-accordion__section-heading-text-focus';
778
-
779
- this.sectionShowHideToggleClass = 'govuk-accordion__section-toggle';
780
- this.sectionShowHideToggleFocusClass = 'govuk-accordion__section-toggle-focus';
781
- this.sectionShowHideTextClass = 'govuk-accordion__section-toggle-text';
782
- this.upChevronIconClass = 'govuk-accordion-nav__chevron';
783
- this.downChevronIconClass = 'govuk-accordion-nav__chevron--down';
784
-
785
- this.sectionSummaryClass = 'govuk-accordion__section-summary';
786
- this.sectionSummaryFocusClass = 'govuk-accordion__section-summary-focus';
787
- }
788
-
789
- // Initialize component
790
- Accordion.prototype.init = function () {
791
- // Check for module
792
- if (!this.$module) {
793
- return
794
- }
1668
+ }
795
1669
 
796
- this.initControls();
797
- this.initSectionHeaders();
798
-
799
- // See if "Show all sections" button text should be updated
800
- var areAllSectionsOpen = this.checkIfAllSectionsOpen();
801
- this.updateShowAllButton(areAllSectionsOpen);
802
- };
803
-
804
- // Initialise controls and set attributes
805
- Accordion.prototype.initControls = function () {
806
- // Create "Show all" button and set attributes
807
- this.$showAllButton = document.createElement('button');
808
- this.$showAllButton.setAttribute('type', 'button');
809
- this.$showAllButton.setAttribute('class', this.showAllClass);
810
- this.$showAllButton.setAttribute('aria-expanded', 'false');
811
-
812
- // Create icon, add to element
813
- var $icon = document.createElement('span');
814
- $icon.classList.add(this.upChevronIconClass);
815
- this.$showAllButton.appendChild($icon);
816
-
817
- // Create control wrapper and add controls to it
818
- var $accordionControls = document.createElement('div');
819
- $accordionControls.setAttribute('class', this.controlsClass);
820
- $accordionControls.appendChild(this.$showAllButton);
821
- this.$module.insertBefore($accordionControls, this.$module.firstChild);
822
-
823
- // Build additional wrapper for Show all toggle text and place after icon
824
- var $wrappershowAllText = document.createElement('span');
825
- $wrappershowAllText.classList.add(this.showAllTextClass);
826
- this.$showAllButton.appendChild($wrappershowAllText);
827
-
828
- // Handle click events on the show/hide all button
829
- this.$showAllButton.addEventListener('click', this.onShowOrHideAllToggle.bind(this));
830
- };
831
-
832
- // Initialise section headers
833
- Accordion.prototype.initSectionHeaders = function () {
834
- // Loop through section headers
835
- nodeListForEach(this.$sections, function ($section, i) {
836
- // Set header attributes
837
- var $header = $section.querySelector('.' + this.sectionHeaderClass);
838
- this.constructHeaderMarkup($header, i);
839
- this.setExpanded(this.isExpanded($section), $section);
840
-
841
- // Handle events
842
- $header.addEventListener('click', this.onSectionToggle.bind(this, $section));
843
-
844
- // See if there is any state stored in sessionStorage and set the sections to
845
- // open or closed.
846
- this.setInitialState($section);
847
- }.bind(this));
848
- };
849
-
850
- Accordion.prototype.constructHeaderMarkup = function ($headerWrapper, index) {
851
- var $span = $headerWrapper.querySelector('.' + this.sectionButtonClass);
852
- var $heading = $headerWrapper.querySelector('.' + this.sectionHeadingClass);
853
- var $summary = $headerWrapper.querySelector('.' + this.sectionSummaryClass);
854
-
855
- // Create a button element that will replace the '.govuk-accordion__section-button' span
856
- var $button = document.createElement('button');
857
- $button.setAttribute('type', 'button');
858
- $button.setAttribute('aria-controls', this.moduleId + '-content-' + (index + 1));
859
-
860
- // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from $span to $button
861
- for (var i = 0; i < $span.attributes.length; i++) {
862
- var attr = $span.attributes.item(i);
863
- // Add all attributes but not ID as this is being added to
864
- // the section heading ($headingText)
865
- if (attr.nodeName !== 'id') {
866
- $button.setAttribute(attr.nodeName, attr.nodeValue);
867
- }
1670
+ };
1671
+
1672
+ // 15. If the [[Class]] internal property of Target is "Function", then
1673
+ // a. Let L be the length property of Target minus the length of A.
1674
+ // b. Set the length own property of F to either 0 or L, whichever is
1675
+ // larger.
1676
+ // 16. Else set the length own property of F to 0.
1677
+
1678
+ var boundLength = max(0, target.length - args.length);
1679
+
1680
+ // 17. Set the attributes of the length own property of F to the values
1681
+ // specified in 15.3.5.1.
1682
+ var boundArgs = [];
1683
+ for (var i = 0; i < boundLength; i++) {
1684
+ array_push.call(boundArgs, '$' + i);
1685
+ }
1686
+
1687
+ // XXX Build a dynamic function with desired amount of arguments is the only
1688
+ // way to set the length property of a function.
1689
+ // In environments where Content Security Policies enabled (Chrome extensions,
1690
+ // for ex.) all use of eval or Function costructor throws an exception.
1691
+ // However in all of these environments Function.prototype.bind exists
1692
+ // and so this code will never be executed.
1693
+ bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
1694
+
1695
+ if (target.prototype) {
1696
+ Empty.prototype = target.prototype;
1697
+ bound.prototype = new Empty();
1698
+ // Clean up dangling references.
1699
+ Empty.prototype = null;
1700
+ }
1701
+
1702
+ // TODO
1703
+ // 18. Set the [[Extensible]] internal property of F to true.
1704
+
1705
+ // TODO
1706
+ // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
1707
+ // 20. Call the [[DefineOwnProperty]] internal method of F with
1708
+ // arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
1709
+ // thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
1710
+ // false.
1711
+ // 21. Call the [[DefineOwnProperty]] internal method of F with
1712
+ // arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
1713
+ // [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
1714
+ // and false.
1715
+
1716
+ // TODO
1717
+ // NOTE Function objects created using Function.prototype.bind do not
1718
+ // have a prototype property or the [[Code]], [[FormalParameters]], and
1719
+ // [[Scope]] internal properties.
1720
+ // XXX can't delete prototype in pure-js.
1721
+
1722
+ // 22. Return F.
1723
+ return bound;
1724
+ }
1725
+ });
1726
+ })
1727
+ .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
1728
+
1729
+ /* eslint-disable es-x/no-function-prototype-bind -- Polyfill imported */
1730
+
1731
+ /**
1732
+ * @constant
1733
+ * @type {AccordionTranslations}
1734
+ * @see Default value for {@link AccordionConfig.i18n}
1735
+ * @default
1736
+ */
1737
+ var ACCORDION_TRANSLATIONS = {
1738
+ hideAllSections: 'Hide all sections',
1739
+ hideSection: 'Hide',
1740
+ hideSectionAriaLabel: 'Hide this section',
1741
+ showAllSections: 'Show all sections',
1742
+ showSection: 'Show',
1743
+ showSectionAriaLabel: 'Show this section'
1744
+ };
1745
+
1746
+ /**
1747
+ * Accordion component
1748
+ *
1749
+ * This allows a collection of sections to be collapsed by default, showing only
1750
+ * their headers. Sections can be expanded or collapsed individually by clicking
1751
+ * their headers. A "Show all sections" button is also added to the top of the
1752
+ * accordion, which switches to "Hide all sections" when all the sections are
1753
+ * expanded.
1754
+ *
1755
+ * The state of each section is saved to the DOM via the `aria-expanded`
1756
+ * attribute, which also provides accessibility.
1757
+ *
1758
+ * @class
1759
+ * @param {HTMLElement} $module - HTML element to use for accordion
1760
+ * @param {AccordionConfig} [config] - Accordion config
1761
+ */
1762
+ function Accordion ($module, config) {
1763
+ this.$module = $module;
1764
+
1765
+ var defaultConfig = {
1766
+ i18n: ACCORDION_TRANSLATIONS
1767
+ };
1768
+
1769
+ this.config = mergeConfigs(
1770
+ defaultConfig,
1771
+ config || {},
1772
+ normaliseDataset($module.dataset)
1773
+ );
1774
+
1775
+ this.i18n = new I18n(extractConfigByNamespace(this.config, 'i18n'));
1776
+
1777
+ this.controlsClass = 'govuk-accordion__controls';
1778
+ this.showAllClass = 'govuk-accordion__show-all';
1779
+ this.showAllTextClass = 'govuk-accordion__show-all-text';
1780
+
1781
+ this.sectionClass = 'govuk-accordion__section';
1782
+ this.sectionExpandedClass = 'govuk-accordion__section--expanded';
1783
+ this.sectionButtonClass = 'govuk-accordion__section-button';
1784
+ this.sectionHeaderClass = 'govuk-accordion__section-header';
1785
+ this.sectionHeadingClass = 'govuk-accordion__section-heading';
1786
+ this.sectionHeadingDividerClass = 'govuk-accordion__section-heading-divider';
1787
+ this.sectionHeadingTextClass = 'govuk-accordion__section-heading-text';
1788
+ this.sectionHeadingTextFocusClass = 'govuk-accordion__section-heading-text-focus';
1789
+
1790
+ this.sectionShowHideToggleClass = 'govuk-accordion__section-toggle';
1791
+ this.sectionShowHideToggleFocusClass = 'govuk-accordion__section-toggle-focus';
1792
+ this.sectionShowHideTextClass = 'govuk-accordion__section-toggle-text';
1793
+ this.upChevronIconClass = 'govuk-accordion-nav__chevron';
1794
+ this.downChevronIconClass = 'govuk-accordion-nav__chevron--down';
1795
+
1796
+ this.sectionSummaryClass = 'govuk-accordion__section-summary';
1797
+ this.sectionSummaryFocusClass = 'govuk-accordion__section-summary-focus';
1798
+ this.sectionContentClass = 'govuk-accordion__section-content';
1799
+
1800
+ this.$sections = this.$module.querySelectorAll('.' + this.sectionClass);
1801
+ this.browserSupportsSessionStorage = helper.checkForSessionStorage();
868
1802
  }
869
1803
 
870
- // Create container for heading text so it can be styled
871
- var $headingText = document.createElement('span');
872
- $headingText.classList.add(this.sectionHeadingTextClass);
873
- // Copy the span ID to the heading text to allow it to be referenced by `aria-labelledby` on the
874
- // hidden content area without "Show this section"
875
- $headingText.id = $span.id;
876
-
877
- // Create an inner heading text container to limit the width of the focus state
878
- var $headingTextFocus = document.createElement('span');
879
- $headingTextFocus.classList.add(this.sectionHeadingTextFocusClass);
880
- $headingText.appendChild($headingTextFocus);
881
- // span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
882
- $headingTextFocus.innerHTML = $span.innerHTML;
883
-
884
- // Create container for show / hide icons and text.
885
- var $showToggle = document.createElement('span');
886
- $showToggle.classList.add(this.sectionShowHideToggleClass);
887
- // Tell Google not to index the 'show' text as part of the heading
888
- // For the snippet to work with JavaScript, it must be added before adding the page element to the
889
- // page's DOM. See https://developers.google.com/search/docs/advanced/robots/robots_meta_tag#data-nosnippet-attr
890
- $showToggle.setAttribute('data-nosnippet', '');
891
- // Create an inner container to limit the width of the focus state
892
- var $showToggleFocus = document.createElement('span');
893
- $showToggleFocus.classList.add(this.sectionShowHideToggleFocusClass);
894
- $showToggle.appendChild($showToggleFocus);
895
- // Create wrapper for the show / hide text. Append text after the show/hide icon
896
- var $showToggleText = document.createElement('span');
897
- var $icon = document.createElement('span');
898
- $icon.classList.add(this.upChevronIconClass);
899
- $showToggleFocus.appendChild($icon);
900
- $showToggleText.classList.add(this.sectionShowHideTextClass);
901
- $showToggleFocus.appendChild($showToggleText);
902
-
903
- // Append elements to the button:
904
- // 1. Heading text
905
- // 2. Punctuation
906
- // 3. (Optional: Summary line followed by punctuation)
907
- // 4. Show / hide toggle
908
- $button.appendChild($headingText);
909
- $button.appendChild(this.getButtonPunctuationEl());
910
-
911
- // If summary content exists add to DOM in correct order
912
- if (typeof ($summary) !== 'undefined' && $summary !== null) {
913
- // Create a new `span` element and copy the summary line content from the original `div` to the
914
- // new `span`
915
- // This is because the summary line text is now inside a button element, which can only contain
916
- // phrasing content
917
- var $summarySpan = document.createElement('span');
918
- // Create an inner summary container to limit the width of the summary focus state
919
- var $summarySpanFocus = document.createElement('span');
920
- $summarySpanFocus.classList.add(this.sectionSummaryFocusClass);
921
- $summarySpan.appendChild($summarySpanFocus);
922
-
923
- // Get original attributes, and pass them to the replacement
924
- for (var j = 0, l = $summary.attributes.length; j < l; ++j) {
925
- var nodeName = $summary.attributes.item(j).nodeName;
926
- var nodeValue = $summary.attributes.item(j).nodeValue;
927
- $summarySpan.setAttribute(nodeName, nodeValue);
1804
+ /**
1805
+ * Initialise component
1806
+ */
1807
+ Accordion.prototype.init = function () {
1808
+ // Check for module
1809
+ if (!this.$module) {
1810
+ return
928
1811
  }
929
1812
 
930
- // Copy original contents of summary to the new summary span
931
- $summarySpanFocus.innerHTML = $summary.innerHTML;
932
-
933
- // Replace the original summary `div` with the new summary `span`
934
- $summary.parentNode.replaceChild($summarySpan, $summary);
1813
+ this.initControls();
1814
+ this.initSectionHeaders();
1815
+
1816
+ // See if "Show all sections" button text should be updated
1817
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen();
1818
+ this.updateShowAllButton(areAllSectionsOpen);
1819
+ };
1820
+
1821
+ /**
1822
+ * Initialise controls and set attributes
1823
+ */
1824
+ Accordion.prototype.initControls = function () {
1825
+ // Create "Show all" button and set attributes
1826
+ this.$showAllButton = document.createElement('button');
1827
+ this.$showAllButton.setAttribute('type', 'button');
1828
+ this.$showAllButton.setAttribute('class', this.showAllClass);
1829
+ this.$showAllButton.setAttribute('aria-expanded', 'false');
1830
+
1831
+ // Create icon, add to element
1832
+ this.$showAllIcon = document.createElement('span');
1833
+ this.$showAllIcon.classList.add(this.upChevronIconClass);
1834
+ this.$showAllButton.appendChild(this.$showAllIcon);
1835
+
1836
+ // Create control wrapper and add controls to it
1837
+ var $accordionControls = document.createElement('div');
1838
+ $accordionControls.setAttribute('class', this.controlsClass);
1839
+ $accordionControls.appendChild(this.$showAllButton);
1840
+ this.$module.insertBefore($accordionControls, this.$module.firstChild);
1841
+
1842
+ // Build additional wrapper for Show all toggle text and place after icon
1843
+ this.$showAllText = document.createElement('span');
1844
+ this.$showAllText.classList.add(this.showAllTextClass);
1845
+ this.$showAllButton.appendChild(this.$showAllText);
1846
+
1847
+ // Handle click events on the show/hide all button
1848
+ this.$showAllButton.addEventListener('click', this.onShowOrHideAllToggle.bind(this));
1849
+
1850
+ // Handle 'beforematch' events, if the user agent supports them
1851
+ if ('onbeforematch' in document) {
1852
+ document.addEventListener('beforematch', this.onBeforeMatch.bind(this));
1853
+ }
1854
+ };
1855
+
1856
+ /**
1857
+ * Initialise section headers
1858
+ */
1859
+ Accordion.prototype.initSectionHeaders = function () {
1860
+ // Loop through section headers
1861
+ nodeListForEach(this.$sections, function ($section, i) {
1862
+ // Set header attributes
1863
+ var $header = $section.querySelector('.' + this.sectionHeaderClass);
1864
+ this.constructHeaderMarkup($header, i);
1865
+ this.setExpanded(this.isExpanded($section), $section);
1866
+
1867
+ // Handle events
1868
+ $header.addEventListener('click', this.onSectionToggle.bind(this, $section));
1869
+
1870
+ // See if there is any state stored in sessionStorage and set the sections to
1871
+ // open or closed.
1872
+ this.setInitialState($section);
1873
+ }.bind(this));
1874
+ };
1875
+
1876
+ /**
1877
+ * Construct section header
1878
+ *
1879
+ * @param {HTMLDivElement} $header - Section header
1880
+ * @param {number} index - Section index
1881
+ */
1882
+ Accordion.prototype.constructHeaderMarkup = function ($header, index) {
1883
+ var $span = $header.querySelector('.' + this.sectionButtonClass);
1884
+ var $heading = $header.querySelector('.' + this.sectionHeadingClass);
1885
+ var $summary = $header.querySelector('.' + this.sectionSummaryClass);
1886
+
1887
+ // Create a button element that will replace the '.govuk-accordion__section-button' span
1888
+ var $button = document.createElement('button');
1889
+ $button.setAttribute('type', 'button');
1890
+ $button.setAttribute('aria-controls', this.$module.id + '-content-' + (index + 1));
1891
+
1892
+ // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from $span to $button
1893
+ for (var i = 0; i < $span.attributes.length; i++) {
1894
+ var attr = $span.attributes.item(i);
1895
+ // Add all attributes but not ID as this is being added to
1896
+ // the section heading ($headingText)
1897
+ if (attr.nodeName !== 'id') {
1898
+ $button.setAttribute(attr.nodeName, attr.nodeValue);
1899
+ }
1900
+ }
935
1901
 
936
- $button.appendChild($summarySpan);
1902
+ // Create container for heading text so it can be styled
1903
+ var $headingText = document.createElement('span');
1904
+ $headingText.classList.add(this.sectionHeadingTextClass);
1905
+ // Copy the span ID to the heading text to allow it to be referenced by `aria-labelledby` on the
1906
+ // hidden content area without "Show this section"
1907
+ $headingText.id = $span.id;
1908
+
1909
+ // Create an inner heading text container to limit the width of the focus state
1910
+ var $headingTextFocus = document.createElement('span');
1911
+ $headingTextFocus.classList.add(this.sectionHeadingTextFocusClass);
1912
+ $headingText.appendChild($headingTextFocus);
1913
+ // span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
1914
+ $headingTextFocus.innerHTML = $span.innerHTML;
1915
+
1916
+ // Create container for show / hide icons and text.
1917
+ var $showHideToggle = document.createElement('span');
1918
+ $showHideToggle.classList.add(this.sectionShowHideToggleClass);
1919
+ // Tell Google not to index the 'show' text as part of the heading
1920
+ // For the snippet to work with JavaScript, it must be added before adding the page element to the
1921
+ // page's DOM. See https://developers.google.com/search/docs/advanced/robots/robots_meta_tag#data-nosnippet-attr
1922
+ $showHideToggle.setAttribute('data-nosnippet', '');
1923
+ // Create an inner container to limit the width of the focus state
1924
+ var $showHideToggleFocus = document.createElement('span');
1925
+ $showHideToggleFocus.classList.add(this.sectionShowHideToggleFocusClass);
1926
+ $showHideToggle.appendChild($showHideToggleFocus);
1927
+ // Create wrapper for the show / hide text. Append text after the show/hide icon
1928
+ var $showHideText = document.createElement('span');
1929
+ var $showHideIcon = document.createElement('span');
1930
+ $showHideIcon.classList.add(this.upChevronIconClass);
1931
+ $showHideToggleFocus.appendChild($showHideIcon);
1932
+ $showHideText.classList.add(this.sectionShowHideTextClass);
1933
+ $showHideToggleFocus.appendChild($showHideText);
1934
+
1935
+ // Append elements to the button:
1936
+ // 1. Heading text
1937
+ // 2. Punctuation
1938
+ // 3. (Optional: Summary line followed by punctuation)
1939
+ // 4. Show / hide toggle
1940
+ $button.appendChild($headingText);
937
1941
  $button.appendChild(this.getButtonPunctuationEl());
938
- }
939
1942
 
940
- $button.appendChild($showToggle);
1943
+ // If summary content exists add to DOM in correct order
1944
+ if (typeof ($summary) !== 'undefined' && $summary !== null) {
1945
+ // Create a new `span` element and copy the summary line content from the original `div` to the
1946
+ // new `span`
1947
+ // This is because the summary line text is now inside a button element, which can only contain
1948
+ // phrasing content
1949
+ var $summarySpan = document.createElement('span');
1950
+ // Create an inner summary container to limit the width of the summary focus state
1951
+ var $summarySpanFocus = document.createElement('span');
1952
+ $summarySpanFocus.classList.add(this.sectionSummaryFocusClass);
1953
+ $summarySpan.appendChild($summarySpanFocus);
1954
+
1955
+ // Get original attributes, and pass them to the replacement
1956
+ for (var j = 0, l = $summary.attributes.length; j < l; ++j) {
1957
+ var nodeName = $summary.attributes.item(j).nodeName;
1958
+ var nodeValue = $summary.attributes.item(j).nodeValue;
1959
+ $summarySpan.setAttribute(nodeName, nodeValue);
1960
+ }
1961
+
1962
+ // Copy original contents of summary to the new summary span
1963
+ $summarySpanFocus.innerHTML = $summary.innerHTML;
941
1964
 
942
- $heading.removeChild($span);
943
- $heading.appendChild($button);
944
- };
1965
+ // Replace the original summary `div` with the new summary `span`
1966
+ $summary.parentNode.replaceChild($summarySpan, $summary);
945
1967
 
946
- // When section toggled, set and store state
947
- Accordion.prototype.onSectionToggle = function ($section) {
948
- var expanded = this.isExpanded($section);
949
- this.setExpanded(!expanded, $section);
1968
+ $button.appendChild($summarySpan);
1969
+ $button.appendChild(this.getButtonPunctuationEl());
1970
+ }
950
1971
 
951
- // Store the state in sessionStorage when a change is triggered
952
- this.storeState($section);
953
- };
1972
+ $button.appendChild($showHideToggle);
1973
+
1974
+ $heading.removeChild($span);
1975
+ $heading.appendChild($button);
1976
+ };
1977
+
1978
+ /**
1979
+ * When a section is opened by the user agent via the 'beforematch' event
1980
+ *
1981
+ * @param {Event} event - Generic event
1982
+ */
1983
+ Accordion.prototype.onBeforeMatch = function (event) {
1984
+ var $section = event.target.closest('.' + this.sectionClass);
1985
+ if ($section) {
1986
+ this.setExpanded(true, $section);
1987
+ }
1988
+ };
954
1989
 
955
- // When Open/Close All toggled, set and store state
956
- Accordion.prototype.onShowOrHideAllToggle = function () {
957
- var $module = this;
958
- var $sections = this.$sections;
959
- var nowExpanded = !this.checkIfAllSectionsOpen();
1990
+ /**
1991
+ * When section toggled, set and store state
1992
+ *
1993
+ * @param {HTMLElement} $section - Section element
1994
+ */
1995
+ Accordion.prototype.onSectionToggle = function ($section) {
1996
+ var expanded = this.isExpanded($section);
1997
+ this.setExpanded(!expanded, $section);
960
1998
 
961
- nodeListForEach($sections, function ($section) {
962
- $module.setExpanded(nowExpanded, $section);
963
1999
  // Store the state in sessionStorage when a change is triggered
964
- $module.storeState($section);
965
- });
966
-
967
- $module.updateShowAllButton(nowExpanded);
968
- };
969
-
970
- // Set section attributes when opened/closed
971
- Accordion.prototype.setExpanded = function (expanded, $section) {
972
- var $icon = $section.querySelector('.' + this.upChevronIconClass);
973
- var $showHideText = $section.querySelector('.' + this.sectionShowHideTextClass);
974
- var $button = $section.querySelector('.' + this.sectionButtonClass);
975
- var newButtonText = expanded ? 'Hide' : 'Show';
976
-
977
- // Build additional copy of "this section" for assistive technology and place inside toggle link
978
- var $visuallyHiddenText = document.createElement('span');
979
- $visuallyHiddenText.classList.add('govuk-visually-hidden');
980
- $visuallyHiddenText.innerHTML = ' this section';
981
-
982
- $showHideText.innerHTML = newButtonText;
983
- $showHideText.appendChild($visuallyHiddenText);
984
- $button.setAttribute('aria-expanded', expanded);
985
-
986
- // Swap icon, change class
987
- if (expanded) {
988
- $section.classList.add(this.sectionExpandedClass);
989
- $icon.classList.remove(this.downChevronIconClass);
990
- } else {
991
- $section.classList.remove(this.sectionExpandedClass);
992
- $icon.classList.add(this.downChevronIconClass);
993
- }
994
-
995
- // See if "Show all sections" button text should be updated
996
- var areAllSectionsOpen = this.checkIfAllSectionsOpen();
997
- this.updateShowAllButton(areAllSectionsOpen);
998
- };
999
-
1000
- // Get state of section
1001
- Accordion.prototype.isExpanded = function ($section) {
1002
- return $section.classList.contains(this.sectionExpandedClass)
1003
- };
1004
-
1005
- // Check if all sections are open
1006
- Accordion.prototype.checkIfAllSectionsOpen = function () {
1007
- // Get a count of all the Accordion sections
1008
- var sectionsCount = this.$sections.length;
1009
- // Get a count of all Accordion sections that are expanded
1010
- var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length;
1011
- var areAllSectionsOpen = sectionsCount === expandedSectionCount;
1012
-
1013
- return areAllSectionsOpen
1014
- };
1015
-
1016
- // Update "Show all sections" button
1017
- Accordion.prototype.updateShowAllButton = function (expanded) {
1018
- var $showAllIcon = this.$showAllButton.querySelector('.' + this.upChevronIconClass);
1019
- var $showAllText = this.$showAllButton.querySelector('.' + this.showAllTextClass);
1020
- var newButtonText = expanded ? 'Hide all sections' : 'Show all sections';
1021
- this.$showAllButton.setAttribute('aria-expanded', expanded);
1022
- $showAllText.innerHTML = newButtonText;
1023
-
1024
- // Swap icon, toggle class
1025
- if (expanded) {
1026
- $showAllIcon.classList.remove(this.downChevronIconClass);
1027
- } else {
1028
- $showAllIcon.classList.add(this.downChevronIconClass);
1029
- }
1030
- };
1031
-
1032
- // Check for `window.sessionStorage`, and that it actually works.
1033
- var helper = {
1034
- checkForSessionStorage: function () {
1035
- var testString = 'this is the test string';
1036
- var result;
1037
- try {
1038
- window.sessionStorage.setItem(testString, testString);
1039
- result = window.sessionStorage.getItem(testString) === testString.toString();
1040
- window.sessionStorage.removeItem(testString);
1041
- return result
1042
- } catch (exception) {
1043
- return false
1044
- }
1045
- }
1046
- };
1047
-
1048
- // Set the state of the accordions in sessionStorage
1049
- Accordion.prototype.storeState = function ($section) {
1050
- if (this.browserSupportsSessionStorage) {
1051
- // We need a unique way of identifying each content in the Accordion. Since
1052
- // an `#id` should be unique and an `id` is required for `aria-` attributes
1053
- // `id` can be safely used.
2000
+ this.storeState($section);
2001
+ };
2002
+
2003
+ /**
2004
+ * When Open/Close All toggled, set and store state
2005
+ */
2006
+ Accordion.prototype.onShowOrHideAllToggle = function () {
2007
+ var $module = this;
2008
+ var $sections = this.$sections;
2009
+ var nowExpanded = !this.checkIfAllSectionsOpen();
2010
+
2011
+ nodeListForEach($sections, function ($section) {
2012
+ $module.setExpanded(nowExpanded, $section);
2013
+ // Store the state in sessionStorage when a change is triggered
2014
+ $module.storeState($section);
2015
+ });
2016
+
2017
+ $module.updateShowAllButton(nowExpanded);
2018
+ };
2019
+
2020
+ /**
2021
+ * Set section attributes when opened/closed
2022
+ *
2023
+ * @param {boolean} expanded - Section expanded
2024
+ * @param {HTMLElement} $section - Section element
2025
+ */
2026
+ Accordion.prototype.setExpanded = function (expanded, $section) {
2027
+ var $showHideIcon = $section.querySelector('.' + this.upChevronIconClass);
2028
+ var $showHideText = $section.querySelector('.' + this.sectionShowHideTextClass);
1054
2029
  var $button = $section.querySelector('.' + this.sectionButtonClass);
2030
+ var $content = $section.querySelector('.' + this.sectionContentClass);
1055
2031
 
1056
- if ($button) {
1057
- var contentId = $button.getAttribute('aria-controls');
1058
- var contentState = $button.getAttribute('aria-expanded');
2032
+ var newButtonText = expanded
2033
+ ? this.i18n.t('hideSection')
2034
+ : this.i18n.t('showSection');
1059
2035
 
1060
- // Only set the state when both `contentId` and `contentState` are taken from the DOM.
1061
- if (contentId && contentState) {
1062
- window.sessionStorage.setItem(contentId, contentState);
1063
- }
2036
+ $showHideText.innerText = newButtonText;
2037
+ $button.setAttribute('aria-expanded', expanded);
2038
+
2039
+ // Update aria-label combining
2040
+ var ariaLabelParts = [];
2041
+
2042
+ var $headingText = $section.querySelector('.' + this.sectionHeadingTextClass);
2043
+ if ($headingText) {
2044
+ ariaLabelParts.push($headingText.innerText.trim());
1064
2045
  }
1065
- }
1066
- };
1067
2046
 
1068
- // Read the state of the accordions from sessionStorage
1069
- Accordion.prototype.setInitialState = function ($section) {
1070
- if (this.browserSupportsSessionStorage) {
1071
- var $button = $section.querySelector('.' + this.sectionButtonClass);
2047
+ var $summary = $section.querySelector('.' + this.sectionSummaryClass);
2048
+ if ($summary) {
2049
+ ariaLabelParts.push($summary.innerText.trim());
2050
+ }
1072
2051
 
1073
- if ($button) {
1074
- var contentId = $button.getAttribute('aria-controls');
1075
- var contentState = contentId ? window.sessionStorage.getItem(contentId) : null;
2052
+ var ariaLabelMessage = expanded
2053
+ ? this.i18n.t('hideSectionAriaLabel')
2054
+ : this.i18n.t('showSectionAriaLabel');
2055
+ ariaLabelParts.push(ariaLabelMessage);
2056
+
2057
+ /*
2058
+ * Join with a comma to add pause for assistive technology.
2059
+ * Example: [heading]Section A ,[pause] Show this section.
2060
+ * https://accessibility.blog.gov.uk/2017/12/18/what-working-on-gov-uk-navigation-taught-us-about-accessibility/
2061
+ */
2062
+ $button.setAttribute('aria-label', ariaLabelParts.join(' , '));
2063
+
2064
+ // Swap icon, change class
2065
+ if (expanded) {
2066
+ $content.removeAttribute('hidden');
2067
+ $section.classList.add(this.sectionExpandedClass);
2068
+ $showHideIcon.classList.remove(this.downChevronIconClass);
2069
+ } else {
2070
+ $content.setAttribute('hidden', 'until-found');
2071
+ $section.classList.remove(this.sectionExpandedClass);
2072
+ $showHideIcon.classList.add(this.downChevronIconClass);
2073
+ }
1076
2074
 
1077
- if (contentState !== null) {
1078
- this.setExpanded(contentState === 'true', $section);
2075
+ // See if "Show all sections" button text should be updated
2076
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen();
2077
+ this.updateShowAllButton(areAllSectionsOpen);
2078
+ };
2079
+
2080
+ /**
2081
+ * Get state of section
2082
+ *
2083
+ * @param {HTMLElement} $section - Section element
2084
+ * @returns {boolean} True if expanded
2085
+ */
2086
+ Accordion.prototype.isExpanded = function ($section) {
2087
+ return $section.classList.contains(this.sectionExpandedClass)
2088
+ };
2089
+
2090
+ /**
2091
+ * Check if all sections are open
2092
+ *
2093
+ * @returns {boolean} True if all sections are open
2094
+ */
2095
+ Accordion.prototype.checkIfAllSectionsOpen = function () {
2096
+ // Get a count of all the Accordion sections
2097
+ var sectionsCount = this.$sections.length;
2098
+ // Get a count of all Accordion sections that are expanded
2099
+ var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length;
2100
+ var areAllSectionsOpen = sectionsCount === expandedSectionCount;
2101
+
2102
+ return areAllSectionsOpen
2103
+ };
2104
+
2105
+ /**
2106
+ * Update "Show all sections" button
2107
+ *
2108
+ * @param {boolean} expanded - Section expanded
2109
+ */
2110
+ Accordion.prototype.updateShowAllButton = function (expanded) {
2111
+ var newButtonText = expanded
2112
+ ? this.i18n.t('hideAllSections')
2113
+ : this.i18n.t('showAllSections');
2114
+
2115
+ this.$showAllButton.setAttribute('aria-expanded', expanded);
2116
+ this.$showAllText.innerText = newButtonText;
2117
+
2118
+ // Swap icon, toggle class
2119
+ if (expanded) {
2120
+ this.$showAllIcon.classList.remove(this.downChevronIconClass);
2121
+ } else {
2122
+ this.$showAllIcon.classList.add(this.downChevronIconClass);
2123
+ }
2124
+ };
2125
+
2126
+ var helper = {
2127
+ /**
2128
+ * Check for `window.sessionStorage`, and that it actually works.
2129
+ *
2130
+ * @returns {boolean} True if session storage is available
2131
+ */
2132
+ checkForSessionStorage: function () {
2133
+ var testString = 'this is the test string';
2134
+ var result;
2135
+ try {
2136
+ window.sessionStorage.setItem(testString, testString);
2137
+ result = window.sessionStorage.getItem(testString) === testString.toString();
2138
+ window.sessionStorage.removeItem(testString);
2139
+ return result
2140
+ } catch (exception) {
2141
+ return false
1079
2142
  }
1080
2143
  }
1081
- }
1082
- };
1083
-
1084
- /**
1085
- * Create an element to improve semantics of the section button with punctuation
1086
- * @return {object} DOM element
1087
- *
1088
- * Used to add pause (with a comma) for assistive technology.
1089
- * Example: [heading]Section A ,[pause] Show this section.
1090
- * https://accessibility.blog.gov.uk/2017/12/18/what-working-on-gov-uk-navigation-taught-us-about-accessibility/
1091
- *
1092
- * Adding punctuation to the button can also improve its general semantics by dividing its contents
1093
- * into thematic chunks.
1094
- * See https://github.com/alphagov/govuk-frontend/issues/2327#issuecomment-922957442
1095
- */
1096
- Accordion.prototype.getButtonPunctuationEl = function () {
1097
- var $punctuationEl = document.createElement('span');
1098
- $punctuationEl.classList.add('govuk-visually-hidden', 'govuk-accordion__section-heading-divider');
1099
- $punctuationEl.innerHTML = ', ';
1100
- return $punctuationEl
1101
- };
1102
-
1103
- return Accordion;
2144
+ };
2145
+
2146
+ /**
2147
+ * Set the state of the accordions in sessionStorage
2148
+ *
2149
+ * @param {HTMLElement} $section - Section element
2150
+ */
2151
+ Accordion.prototype.storeState = function ($section) {
2152
+ if (this.browserSupportsSessionStorage) {
2153
+ // We need a unique way of identifying each content in the Accordion. Since
2154
+ // an `#id` should be unique and an `id` is required for `aria-` attributes
2155
+ // `id` can be safely used.
2156
+ var $button = $section.querySelector('.' + this.sectionButtonClass);
2157
+
2158
+ if ($button) {
2159
+ var contentId = $button.getAttribute('aria-controls');
2160
+ var contentState = $button.getAttribute('aria-expanded');
2161
+
2162
+ // Only set the state when both `contentId` and `contentState` are taken from the DOM.
2163
+ if (contentId && contentState) {
2164
+ window.sessionStorage.setItem(contentId, contentState);
2165
+ }
2166
+ }
2167
+ }
2168
+ };
2169
+
2170
+ /**
2171
+ * Read the state of the accordions from sessionStorage
2172
+ *
2173
+ * @param {HTMLElement} $section - Section element
2174
+ */
2175
+ Accordion.prototype.setInitialState = function ($section) {
2176
+ if (this.browserSupportsSessionStorage) {
2177
+ var $button = $section.querySelector('.' + this.sectionButtonClass);
2178
+
2179
+ if ($button) {
2180
+ var contentId = $button.getAttribute('aria-controls');
2181
+ var contentState = contentId ? window.sessionStorage.getItem(contentId) : null;
2182
+
2183
+ if (contentState !== null) {
2184
+ this.setExpanded(contentState === 'true', $section);
2185
+ }
2186
+ }
2187
+ }
2188
+ };
2189
+
2190
+ /**
2191
+ * Create an element to improve semantics of the section button with punctuation
2192
+ *
2193
+ * Adding punctuation to the button can also improve its general semantics by dividing its contents
2194
+ * into thematic chunks.
2195
+ * See https://github.com/alphagov/govuk-frontend/issues/2327#issuecomment-922957442
2196
+ *
2197
+ * @returns {HTMLElement} DOM element
2198
+ */
2199
+ Accordion.prototype.getButtonPunctuationEl = function () {
2200
+ var $punctuationEl = document.createElement('span');
2201
+ $punctuationEl.classList.add('govuk-visually-hidden', this.sectionHeadingDividerClass);
2202
+ $punctuationEl.innerHTML = ', ';
2203
+ return $punctuationEl
2204
+ };
2205
+
2206
+ /**
2207
+ * Accordion config
2208
+ *
2209
+ * @typedef {object} AccordionConfig
2210
+ * @property {AccordionTranslations} [i18n = ACCORDION_TRANSLATIONS] - See constant {@link ACCORDION_TRANSLATIONS}
2211
+ */
2212
+
2213
+ /**
2214
+ * Accordion translations
2215
+ *
2216
+ * @typedef {object} AccordionTranslations
2217
+ *
2218
+ * Messages used by the component for the labels of its buttons. This includes
2219
+ * the visible text shown on screen, and text to help assistive technology users
2220
+ * for the buttons toggling each section.
2221
+ * @property {string} [hideAllSections] - The text content for the 'Hide all
2222
+ * sections' button, used when at least one section is expanded.
2223
+ * @property {string} [hideSection] - The text content for the 'Hide'
2224
+ * button, used when a section is expanded.
2225
+ * @property {string} [hideSectionAriaLabel] - The text content appended to the
2226
+ * 'Hide' button's accessible name when a section is expanded.
2227
+ * @property {string} [showAllSections] - The text content for the 'Show all
2228
+ * sections' button, used when all sections are collapsed.
2229
+ * @property {string} [showSection] - The text content for the 'Show'
2230
+ * button, used when a section is collapsed.
2231
+ * @property {string} [showSectionAriaLabel] - The text content appended to the
2232
+ * 'Show' button's accessible name when a section is expanded.
2233
+ */
2234
+
2235
+ return Accordion;
1104
2236
 
1105
2237
  })));
2238
+ //# sourceMappingURL=accordion.js.map