From 71b06d8126ebce6e48d6189c755b2092bda41bee Mon Sep 17 00:00:00 2001 From: Mark Conroy Date: Mon, 20 Oct 2025 14:19:26 +0100 Subject: [PATCH 1/2] fix eslint issues --- js/step-by-step-nav.js | 215 +++++++++++++++++++++++++---------------- 1 file changed, 132 insertions(+), 83 deletions(-) diff --git a/js/step-by-step-nav.js b/js/step-by-step-nav.js index 860a438..bf5b74b 100644 --- a/js/step-by-step-nav.js +++ b/js/step-by-step-nav.js @@ -3,94 +3,143 @@ * Additional behaviour for the Step by step navigation. */ -(function($, Drupal, drupalSettings) { +(function lgdStepByStepScript($, Drupal) { + Drupal.behaviors.lgdStepByStepNav = { + attach(context) { + const stepByStep = {}; + stepByStep.showAllText = 'Show summaries'; + stepByStep.hideAllText = 'Hide summaries'; + stepByStep.showStepText = 'Show step summary'; + stepByStep.hideStepText = 'Hide step summary'; - const stepByStep = {}; - stepByStep.showAllText = 'Show summaries'; - stepByStep.hideAllText = 'Hide summaries'; - stepByStep.showStepText = 'Show step summary'; - stepByStep.hideStepText = 'Hide step summary'; + // Set visibility based on specified button.step-show elements. + function summaryVisiblity(elements, cmd) { + switch (cmd) { + case 'show': + elements.each(() => { + const stepTitle = $(this) + .parents('.step__title') + .find('a') + .text(); + $(this) + .parents('.step') + .find('.step__summary') + .addClass('step-show-summary'); + $(this).text(stepByStep.hideStepText); + $(this).attr('aria-expanded', 'true'); + $(this).attr( + 'aria-label', + Drupal.t('Hide step summary - !summary_message', { + '!summary_message': stepTitle, + }), + ); + }); + // 'Hide all' control displayed if all steps are shown. + if ($('.step__summary').length === $('.step-show-summary').length) { + $('.step-master').text(stepByStep.hideAllText); + $('.summaries-control i') + .addClass('fa-eye-slash') + .removeClass('fa-eye'); + } + break; - // Set visibility based on specified button.step-show elements. - function summaryVisiblity(elements, cmd) { - switch(cmd) { - case 'show': - elements.each(function() { - var stepTitle = $(this).parents('.step__title').find('a').text(); - $(this).parents('.step').find('.step__summary').addClass('step-show-summary'); - $(this).text(stepByStep.hideStepText); - $(this).attr("aria-expanded", "true"); - $(this).attr('aria-label', Drupal.t("Hide step summary - !summary_message", {"!summary_message": stepTitle})); - }); - // 'Hide all' control displayed if all steps are shown. - if ($('.step__summary').length === $('.step-show-summary').length) { - $('.step-master').text(stepByStep.hideAllText); - $('.summaries-control i').addClass('fa-eye-slash').removeClass('fa-eye'); + case 'hide': + elements.each(() => { + const stepTitle = $(this) + .parents('.step__title') + .find('a') + .text(); + $(this) + .parents('.step') + .find('.step__summary') + .removeClass('step-show-summary'); + $(this).attr('aria-expanded', 'false'); + $(this).text(stepByStep.showStepText); + $(this).attr( + 'aria-label', + Drupal.t('Show step summary - !summary_message', { + '!summary_message': stepTitle, + }), + ); + }); + // 'Show all' control displayed if any steps are hidden. + $('.step-master').text(stepByStep.showAllText); + $('.summaries-control i') + .addClass('fa-eye') + .removeClass('fa-eye-slash'); + break; + default: + break; } - break; + } - case 'hide': - elements.each(function() { - var stepTitle = $(this).parents('.step__title').find('a').text(); - $(this).parents('.step').find('.step__summary').removeClass('step-show-summary'); - $(this).attr("aria-expanded", "false"); - $(this).text(stepByStep.showStepText); - $(this).attr('aria-label', Drupal.t("Show step summary - !summary_message", {"!summary_message": stepTitle})); - }); - // 'Show all' control displayed if any steps are hidden. - $('.step-master').text(stepByStep.showAllText); - $('.summaries-control i').addClass('fa-eye').removeClass('fa-eye-slash'); - break; - } - } + // Insert show all button. + $( + `
`, + ).insertBefore('ol.step-list'); - // Insert show all button. - $("
").insertBefore("ol.step-list"); - - // Insert hide/show button for each step. - function stepSummaryButton(isVisible, stepTitle) { - var $container = $(""); - var $button = $("`, + `
`, ).insertBefore('ol.step-list'); // Insert hide/show button for each step. @@ -105,7 +108,7 @@ return $container; } - $('ol.step-list .step').each(() => { + $('ol.step-list .step').each(function initializeStep() { const isVisible = $(this).hasClass('step--active'); const stepTitle = $(this).find('.step__title').text(); if (isVisible) { @@ -117,7 +120,7 @@ }); // Show / hide all. - $('.step-master').on('click', () => { + $('.step-master').on('click', function toggleAllSteps() { $('.summaries-control i').toggleClass('fa-eye fa-eye-slash'); if ($(this).text() === stepByStep.showAllText) { $(this).text(stepByStep.hideAllText).attr('aria-expanded', true); @@ -129,7 +132,7 @@ }); // Show / hide single step. - $('.step-show').on('click', () => { + $('.step-show').on('click', function toggleSingleStep() { $(this) .parents('.step') .find('.step__summary') @@ -142,4 +145,4 @@ }); }, }; -})(jQuery, Drupal); +})(jQuery, Drupal, drupalSettings);