let gds = { settings: { enableTrace: true, enableDebug: true }, convertPage: function(pageTitle) { var listboxOptions = []; this.changePageTitle(pageTitle); this.changeFormTitle(); this.runMutationObserver(listboxOptions); this.styleErrors(); this.changeSecurityErrorText(); this.changeFieldLabels(); this.changeTextareas(); this.changeTextInputs(); this.changeEmailInput(); this.changePageToDotGovTemplate(); this.changeRadioInputs(); this.changeNextButton(); this.changeUpdateButton(); this.changeNavBarToRemoveSignIn(); this.changeBackground(); this.removeAdditionalCSSClasses(); this.removeConfilctingCSSClasses(); this.relocateAndRestyleBackButton(); this.errorHandling(); this.moveInstructions(); this.characterCounter(); this.removeEmptyTableRows(); this.clearErrorsOnNewInput(); this.validateContactDetails(); this.accordionUpdatesForJAWS(); this.removeXSNavBar(); listboxOptions = []; }, convertReviewPage: function(pageTitle) { this.changePageTitle(pageTitle); this.changeReviewFormTitle(); this.changeReviewFieldLabels(); this.changePageToDotGovTemplate(); this.changeNavBarToRemoveSignIn(); this.changeBackground(); this.hideBlankReviewRows(); this.replaceReviewAnswerDisplays(); this.addRowStyling(); this.removeAdditionalCSSClasses(); this.errorHandling(); this.runMutationObserverReviewPage(); this.removeConfilctingCSSClasses(); this.clearErrorsOnNewInput(); this.accordionUpdatesForJAWS(); this.removeXSNavBar(); }, changePageTitle: function(pageTitle) { // Change name in the header and hide additional text $(".headercontent1").text(pageTitle); $(".headercontent2").remove(); $('title').text(pageTitle - $('.tab-title').text()); console.log($('title').text(`${$('.tab-title').text()} - ${pageTitle}`)); }, changeFormTitle: function() { // Change the form title to match GDS and wrap in legend var title = $("h2.tab-title"); var locationName = sessionStorage.serviceName; if (title.length > 0) { if (title[0].innerHTML.contains("the service") && locationName != "") { title[0].innerHTML = title[0].innerText.replace("the service", locationName); } title.replaceWith(`

${title[0].innerHTML}

`); $("legend").next(`div`).addBack().wrapAll(`
`); } }, changeReviewFormTitle: function() { // Change the form title to match GDS and wrap in legend var title = $("h2.tab-title"); title.replaceWith(`

${title.text()}

`); $("legend").next(`div`).addBack().wrapAll(`
`); }, changeFieldLabels: function() { // Style field labels $('.field-label').addClass('govuk-label'); $('.field-label').removeClass('field-label'); }, changeReviewFieldLabels: function() { // Style field labels for review page $('.field-label').unwrap(); $('.field-label').wrap('
'); $('.field-label').addClass('govuk-summary-list govuk-summary-list__key'); $('.field-label').removeClass('field-label'); }, changeTextareas: function() { // Change textareas to match GDS var textArea = $('textarea.textarea'); if (textArea.length > 0) { textArea.addClass('govuk-textarea'); textArea.removeClass('textarea form-control'); //textArea.css('height', 'fit-content'); } }, changeTextInputs: function() { // Change text inputs to match GDS $('input[type="text"]').each(function() { $(this).attr('class', 'govuk-input govuk-border-important govuk-background-important'); var checkCaptcha = $(this).parent().parent().parent().parent(); if (checkCaptcha.hasClass("captcha-cell")) { $(this).addClass('gds-captcha'); $(this).parent().attr('class', 'd-flex flex-column-reverse'); $(this).parent().append('

This box contains 7 characters

'); $(this).parent().prepend(`
`); } }); }, changeEmailInput: function() { // Change email inputs to match GDS text input $('input[type="email"]').each(function() { $(this).attr('class', 'govuk-input govuk-border-important govuk-background-important'); }); }, changePageToDotGovTemplate: function() { // Convert page to Gov Template $('html').addClass('govuk-template'); }, changeRadioInputs: function() { // Change each Radio input to match GDS $("input").each(function (i) { var ths = $(this); var parent = ths.parent(); if (parent.hasClass('picklist')) { $('br').remove(); ths.addClass("govuk-radios__input"); ths.next('label').addClass("govuk-label govuk-radios__label"); $("span.sr-only").remove(); var active = ths.is(":checked") ? ' active' : ''; var divHtml = common.buildWrappingDiv(parent, '
'); ths.next('label').addBack().wrapAll(divHtml); } }); }, changeSecurityErrorText: function() { var securityErrorText = $('p.text-danger'); securityErrorText.addClass('govuk-error-message mb-0'); securityErrorText.removeClass('text-danger'); $('span.fa-exclamation-triangle').remove(); var errorMessagePanel = $('#MessagePanel'); errorMessagePanel.addClass('govuk-error-summary'); errorMessagePanel.removeClass('message alert error alert alert-danger'); }, changeNextButton: function() { // Change Next Button to match GDS var submissionButton = $('#NextButton'); submissionButton.removeClass('btn btn-primary button next submit-btn'); submissionButton.addClass('govuk-button mt-4'); submissionButton.val("Continue"); submissionButton.on("click", function() { var securityErrorText = $('p.text-danger'); securityErrorText.addClass('govuk-error-message'); securityErrorText.removeClass('text-danger'); $('span.fa-exclamation-triangle').remove(); }); }, changeUpdateButton: function() { // Change Update Button to match GDS var updateButton = $('#UpdateButton'); updateButton.removeClass('btn btn-primary button next submit-btn form-action-container-left'); updateButton.addClass('govuk-button'); updateButton.val("Update"); }, changeNavBarToRemoveSignIn: function() { // Remove Sign in $('.navbar-toggle').remove(); $('.navbar-collapse').remove(); }, changeBackground: function() { // Change form background to match GDS $('.crmEntityFormView').css({'background-color':'#fff !important;','padding':'0px'}); }, removeEmptyTableRows: function() { $('tr').each(function() { if ($(this).children().length == 0 || $(this.children[0]).children().length == 0) { $(this).remove(); } else { $(this).addClass("d-flex flex-column"); } }); var firstRow = $('tbody').children(); $(firstRow[0]).css("margin-top", "0px"); }, removeAdditionalCSSClasses: function() { // Remove needless additional classes on CTA buttons $('.col-sm-6').removeClass('col-sm-6 clearfix'); $('td.cell').removeClass('cell'); $('.validators').attr("hidden", "hidden"); $('.text-primary').parent().remove(); }, removeConfilctingCSSClasses: function() { // Remove conflicting CSS classes $('.control').css({"width":"auto", "margin": "0px"}); $('.zero-cell').remove(); $('.info').css('padding-bottom', '0px'); }, relocateAndRestyleBackButton: function() { // Take the previous button and move to top of he screen var previousButton = $('#PreviousButton'); $('#top-action-row').append(previousButton); previousButton.replaceWith(`Back`); }, errorHandling: function() { // Error handling (also see MutationObserver) var errorSummary = $('.validation-summary'); errorSummary.removeClass('validation-summary alert alert-error alert-danger alert-block'); errorSummary.addClass('govuk-error-summary'); }, changeCaptcha: function() { $('.captcha-cell').find('img').css('height', '67px'); $('.captcha-cell').find('img').css('width', '300px'); var captchaRefresh = $('a.rcRefreshImage'); captchaRefresh.parent().attr('class', 'd-flex'); captchaRefresh.next('a').addBack().wrapAll(`
`); captchaRefresh.replaceWith(``); var captchaAudio = $('a.rcCaptchaAudioLink'); captchaAudio.addClass(`captcha-symbol`); //captchaAudio.html('🕨'); // 🕨 captchaAudio.html('This is the read aloud button icon for the Captcha'); $('#NextButton').val("Start"); if ($('p.govuk-label').length == 0) { $('.captcha-cell').prepend('

To continue, please enter the characters below

'); } $('label').text("Type the characters here"); $('label').addClass('govuk-label mt-3'); }, styleErrors: function() { //$('.govuk-form-group--error').removeClass('govuk-form-group--error'); $('span.fa-info-circle').remove(); $('span.fa-exclamation-triangle').remove(); $('.validation-header').replaceWith('

There is a problem

'); var node = $('.govuk-error-summary').children(); for (var e = 0; e < node.length; e++) { if ($(node[e]).hasClass('text-danger')) { $(node[e]).addClass('govuk-error-message'); $(node[e]).removeClass('text-danger'); } if ($(node[e]).is('ul') && !$(node[e]).hasClass('govuk-error-summary__list')) { $(node[e]).addClass('govuk-list govuk-error-summary__list'); $(node[e]).wrapAll('
'); var newChildElems = $(node[e]).children(); for (var i = 0; i < newChildElems.length; i++) { var errorElem = $(newChildElems[i].children[0]); if ($('tbody').children().length > 1) { $(errorElem.attr("href")).closest("tr").addClass('govuk-form-group--error'); } else { if ($('div.govuk-form-group--error').length == 0) { $('.govuk-fieldset').children().wrapAll('
'); } } $(errorElem.attr("href")).addClass("govuk-input--error"); if ($(errorElem.attr("href")+'-input-error').length == 0) { $(errorElem.attr("href")).parent().prepend(`

${errorElem.text()}

`); } var errorText = this.customErrorMessages(newChildElems[i]); var href = $(newChildElems[i].children[0]).attr('href').replace('#', ''); errorElem[0].innerText = errorText; errorElem[0].id = `${href}-error`; if (!$(`#${href}-error`).text()) { errorElem.parent().prepend(`

${errorText}

`); } } } }; }, customErrorMessages: function(error) { var errorId = $(error.children[0]).attr('href'); switch(errorId) { default: error = error.innerText; break; case '#captcha': error = "The characters you enter must match the ones displayed"; break; } return error; }, characterCounter: function() { $('input[type="text"], textarea').each(function() { if ($(this).attr("maxlength") > 0 && $(this).attr("maxlength") != 7) { $(this).addClass("mb-0"); var charLimit = this.maxlength; $(this).parent().append(`

`); $(`#${this.id}-counter`).text(`You can enter up to ${$(this).attr("maxlength") - $(this).val().length} characters`); $(this).on("input", function() { if (($(this).attr("maxlength") - $(this).val().length) == 0) { $(`#${this.id}-counter`).text(`You have entered the maximum number of characters.\nIf you have pasted information into this field, please check if it has all been included.`); $(`#${this.id}-counter`).addClass('govuk-error-message'); $(`#${this.id}-counter`).removeClass('govuk-hint'); } else { $(`#${this.id}-counter`).text(`You can enter up to ${$(this).attr("maxlength") - $(this).val().length} characters`); $(`#${this.id}-counter`).removeClass('govuk-error-message'); $(`#${this.id}-counter`).addClass('govuk-hint'); } }); } }); }, runMutationObserver: function(listboxOptions) { // Select the target node to observe const targetNode = document.body; // Create a MutationObserver instance const observer = new MutationObserver((mutationsList) => { observer.disconnect(); for (const mutation of mutationsList) { if (mutation.type === 'childList') { this.styleErrors(); // Captcha symbols var captchaRefresh = $('a.rcRefreshImage'); if (captchaRefresh.length > 0) { this.changeCaptcha(captchaRefresh); } // Incomplete - generates checkboxes from multiselect elements if (listboxOptions.length == 0) { $('DIV.msos-label-text').each(function() { listboxOptions.push($(this).text()); }); if (listboxOptions.length > 0) { //this.generateCheckBoxes(listboxOptions); } } } } listboxOptions = []; observer.observe(targetNode, config); }); // Configuration for the observer const config = { childList: true, subtree: true }; // Start observing the target node observer.observe(targetNode, config); }, runMutationObserverReviewPage: function() { // Select the target node to observe const targetNode = document.body; // Create a MutationObserver instance const observer = new MutationObserver((mutationsList) => { observer.disconnect(); for (const mutation of mutationsList) { if (mutation.type === 'childList') { $('span.fa-info-circle').remove(); $('.validation-header').replaceWith('

There is a problem

'); mutation.addedNodes.forEach((node) => { if ($(node).is('ul') && !$(node).hasClass('govuk-error-summary__list')) { $(node).addClass('govuk-list govuk-error-summary__list'); $(node).wrapAll('
'); var newChildElems = $(node).children(); for (var i = 0; i < newChildElems.length; i++) { var errorElem = $(newChildElems[i]); errorElem = $(errorElem.children()[0]).attr("href"); errorElem = $(errorElem); errorElem.parent().addClass('govuk-form-group--error'); if (!$(`#${newChildElems[i].referencecontrolid}-error`).text()) { errorElem.parent().prepend(`

${newChildElems[i].textContent}

`); } } } }); } } observer.observe(targetNode, config); }); // Configuration for the observer const config = { childList: true, subtree: true }; // Start observing the target node observer.observe(targetNode, config); }, generateCheckBoxes: function(options) { options.shift(); var optionsHTML = []; options.forEach((option) => { optionsHTML.push(`
`); }); var checkboxComponent = `
${optionsHTML.join('')}
`; $('.flexbox').parent().append(checkboxComponent); $('.flexbox').hide(); }, checkboxSelect: function(input) { var targetCheckbox = $(`input[aria-label="${input.id}"]`); targetCheckbox.click(); targetCheckbox.focus(); }, moveInstructions: function() { var instructions = $('.instructions'); var newInstructions = instructions; instructions.remove(); $('tbody').prepend(instructions); }, replaceReviewAnswerDisplays: function() { $('input:not([type="hidden"]),select:not([type="hidden"]),textarea:not([type="hidden"])').each(function(){ var id = $(this).attr('id'); var component = $('#' + id); var value = component.val(); var text = component.find('option:selected').text(); if (text == "") { text = value; } //if (text == "") { // text = "Not provided"; //} component.unwrap(); if ($(this).parent().hasClass('cqc-form-start') || $(this).parent().hasClass('control')) { component.unwrap(); } component.replaceWith(`

${text}

`); if(value == "" || value == " " || value == null) { $(this).closest("tr").hide(); } }); }, hideBlankReviewRows: function() { // Loop through all rows that have a field inside (.control > select|input|textarea) $('tr').each(function () { const $row = $(this); const field = $row.find('.control select, .control input, .control textarea').first(); const fieldId = field.attr('id'); if (!fieldId) return; // use the fieldId directly as the key in window.sitemarkerLinks const url = window.sitemarkerLinks[fieldId]; if (!url) return; // build the full href const recordId = window.id; const href = `${url}?id=${recordId}`; const linkHtml = `
`; $row.find('td').append(linkHtml); }); }, addRowStyling: function() { $('td').addClass('d-md-flex pb-0 govuk-summary-list__row'); $('td').removeClass('clearfix lookup form-control-cell picklist-cell'); }, clearErrorsOnNewInput: function() { $('input[type="text"], input[type="email"], textarea').each(function() { $(this).on("input", function() { $(this).closest(".govuk-form-group--error").removeClass("govuk-form-group--error"); var errorLabelId = `#${this.id}_label-input-error`; if ($(errorLabelId).length == 0) { errorLabelId = `#${this.id}-input-error`; } $('.govuk-input--error').removeClass('govuk-input--error'); $(errorLabelId).remove(); }); }); }, validateContactDetails: function() { var self = this; if ($('#cqc_fullname').length > 0 && $('#cqc_emailaddress').length > 0 && $('#cqc_uktelephonenumber').length > 0) { $('#NextButton').hide(); $('#NextButton').parent().prepend(''); $('#UpdateButton').hide(); $('#UpdateButton').parent().prepend(''); } $('#NextButton_Contact, #UpdateButton_Contact').on("click", function(event) { var errorLog = []; var errorsDetected = false; if ($('#cqc_fullname').val() == "") { errorLog.push({"component":"cqc_fullname", "error":"Enter your name"}); errorsDetected = true; } var regex = /^(?=.*[A-Za-z])[A-Za-z' -]+$/gs; if (!$('#cqc_fullname').val() == "" && !regex.test($('#cqc_fullname').val())) { errorLog.push({"component":"cqc_fullname", "error":"Name must include at least one letter, and may only contain spaces, hyphens, or apostrophes"}); errorsDetected = true; } if ($('#cqc_emailaddress').val() == "" && $('#cqc_uktelephonenumber').val() == "") { errorLog.push({"component":"cqc_emailaddress", "error":"Enter either an email address or phone number"}); errorsDetected = true; } regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/; if (!$('#cqc_emailaddress').val() == "" && !regex.test($('#cqc_emailaddress').val())) { errorLog.push({"component":"cqc_emailaddress", "error":"You must enter a valid email address"}); errorsDetected = true; } regex = /^(?=(?:\D*\d){11}\D*$)[0-9()\-\—\s]{10,20}$/; if (!$('#cqc_uktelephonenumber').val() == "" && !regex.test($('#cqc_uktelephonenumber').val())) { errorLog.push({"component":"cqc_uktelephonenumber", "error":"Enter a phone number with 11 numerical characters. It can include spaces, brackets or hyphens but must be no more than 20 characters in total"}); errorsDetected = true; } if (!errorsDetected) { var numberToStrip = $('#cqc_uktelephonenumber').val(); numberToStrip = numberToStrip.replaceAll(" ", ""); numberToStrip = numberToStrip.replaceAll("-", ""); numberToStrip = numberToStrip.replaceAll("(", ""); numberToStrip = numberToStrip.replaceAll(")", ""); numberToStrip = numberToStrip.replaceAll("—", ""); $('#cqc_uktelephonenumber').val(numberToStrip); $('#NextButton, #UpdateButton').click(); } else { var allErrors; for (var i = 0; i < errorLog.length; i++) { if (allErrors != null) { allErrors += `
  • ${errorLog[i].error}
  • `; } else { allErrors = `
  • ${errorLog[i].error}
  • `; } self.generateInputErrors(errorLog[i]); } $('#ValidationSummaryEntityFormView').remove(); $('fieldset.govuk-fieldset').before(` `); } }); }, generateInputErrors: function(error) { $(`#${error.component}`).closest('tr').addClass('govuk-form-group--error'); if ($(`#${error.component}_label-input-error`).length == 0) { $(`#${error.component}`).parent().prepend(`

    ${error.error}

    `); } }, accordionUpdatesForJAWS: function() { $('.govuk-details').on("toggle", function() { var expandable = $(this).find(".govuk-details__text"); if ($(expandable).attr("aria-hidden") == "false") { $(expandable).attr("aria-hidden", "true"); $(expandable).attr("aria-live", "off"); $('.govuk-details__summary').attr("aria-expanded", "false"); } else { $(expandable).attr("aria-hidden", "false"); $(expandable).attr("aria-live", "polite"); $('.govuk-details__summary').attr("aria-expanded", "true"); } }); }, focusRadioGroup: function (fieldId) { setTimeout(function () { const container = $('#' + fieldId); if (!container.length) return; // Prefer checked radio, otherwise first visible radio let radioToFocus = container.find('input[type="radio"]:checked').first(); if (!radioToFocus.length) { radioToFocus = container.find('input[type="radio"]:visible').first(); } if (radioToFocus.length) { radioToFocus.focus(); } }, 250); // delay ensures Power Pages rendering is complete }, syncRadioFocus: function (selector) { $(document).on('change', selector, function () { if (this.checked) { this.focus(); } }); }, removeXSNavBar: function () { $('.visible-xs-block').find('.navbar-brand').replaceWith('

    Give Feedback On Care

    '); } }