@ministryofjustice/frontend 3.5.0 → 3.6.1
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.
- package/moj/all.jquery.min.js +1 -81
- package/moj/all.js +2577 -2853
- package/moj/all.mjs +126 -0
- package/moj/all.scss +1 -1
- package/moj/components/add-another/add-another.js +111 -132
- package/moj/components/add-another/add-another.mjs +106 -0
- package/moj/components/alert/alert.js +352 -479
- package/moj/components/alert/alert.mjs +251 -0
- package/moj/components/alert/alert.spec.helper.js +6 -24
- package/moj/components/alert/alert.spec.helper.mjs +66 -0
- package/moj/components/button-menu/button-menu.js +326 -343
- package/moj/components/button-menu/button-menu.mjs +329 -0
- package/moj/components/cookie-banner/_cookie-banner.scss +1 -1
- package/moj/components/date-picker/date-picker.js +905 -922
- package/moj/components/date-picker/date-picker.mjs +961 -0
- package/moj/components/filter-toggle-button/filter-toggle-button.js +98 -119
- package/moj/components/filter-toggle-button/filter-toggle-button.mjs +93 -0
- package/moj/components/form-validator/form-validator.js +201 -396
- package/moj/components/form-validator/form-validator.mjs +168 -0
- package/moj/components/multi-file-upload/multi-file-upload.js +227 -441
- package/moj/components/multi-file-upload/multi-file-upload.mjs +219 -0
- package/moj/components/multi-select/multi-select.js +82 -103
- package/moj/components/multi-select/multi-select.mjs +77 -0
- package/moj/components/password-reveal/password-reveal.js +40 -61
- package/moj/components/password-reveal/password-reveal.mjs +35 -0
- package/moj/components/rich-text-editor/rich-text-editor.js +162 -183
- package/moj/components/rich-text-editor/rich-text-editor.mjs +157 -0
- package/moj/components/search-toggle/search-toggle.js +52 -73
- package/moj/components/search-toggle/search-toggle.mjs +54 -0
- package/moj/components/sortable-table/sortable-table.js +143 -164
- package/moj/components/sortable-table/sortable-table.mjs +138 -0
- package/moj/helpers.js +196 -215
- package/moj/helpers.mjs +123 -0
- package/moj/moj-frontend.min.js +1 -81
- package/moj/version.js +6 -23
- package/moj/version.mjs +3 -0
- package/package.json +24 -6
package/moj/moj-frontend.min.js
CHANGED
|
@@ -1,81 +1 @@
|
|
|
1
|
-
((t,e)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MOJFrontend=e()})(this,function(){function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var b,y,e,o,v,k,D,x,j,_,w,C,B,$,L,M,T,S,A,E,F,H,I,O,q,R,P,N,z=window.jQuery;function Z(){return o||(o=1,e={removeAttributeValue:function(t,e,o){var i;t.getAttribute(e)&&(t.getAttribute(e)===o?t.removeAttribute(e):(o=new RegExp(`(^|\\s)${o}(\\s|$)`),(i=t.getAttribute(e).match(o))&&3===i.length&&t.setAttribute(e,t.getAttribute(e).replace(o,i[1]&&i[2]?" ":""))))},addAttributeValue:function(t,e,o){t.getAttribute(e)?new RegExp(`(^|\\s)${o}(\\s|$)`).test(t.getAttribute(e))||t.setAttribute(e,t.getAttribute(e)+" "+o):t.setAttribute(e,o)},dragAndDropSupported:function(){return void 0!==document.createElement("div").ondrop},formDataSupported:function(){return"function"==typeof FormData},fileApiSupported:function(){var t=document.createElement("input");return t.type="file",void 0!==t.files},nodeListForEach:function(e,o){if(window.NodeList.prototype.forEach)return e.forEach(o);for(let t=0;t<e.length;t++)o.call(window,e[t],t,e)},getNextSibling:function(e,o){if(e){let t=e.nextElementSibling;if(!o)return t;for(;t;){if(t.matches(o))return t;t=t.nextElementSibling}}},getPreviousSibling:function(e,o){if(e){let t=e.previousElementSibling;if(!o)return t;for(;t;){if(t.matches(o))return t;t=t.previousElementSibling}}},findNearestMatchingElement:function(t,o){if(t&&o){let e=t;for(;e;){if(e.matches(o))return e;let t=e.previousElementSibling;for(;t;){if(t.matches(o))return t;t=t.previousElementSibling}e=e.parentElement}}},setFocus:function(t,e={}){let o=t.getAttribute("tabindex");function i(){e.onBlur&&e.onBlur.call(t),o||t.removeAttribute("tabindex")}o||t.setAttribute("tabindex","-1"),t.addEventListener("focus",function(){t.addEventListener("blur",i,{once:!0})},{once:!0}),e.onBeforeFocus&&e.onBeforeFocus.call(t),t.focus()}}),e}return t((()=>{if(!N){N=1;let n=z,o=(()=>{if(!y){y=1;let s=z;function t(t){this.container=s(t),this.container.data("moj-add-another-initialised")||(this.container.data("moj-add-another-initialised",!0),this.container.on("click",".moj-add-another__remove-button",s.proxy(this,"onRemoveButtonClick")),this.container.on("click",".moj-add-another__add-button",s.proxy(this,"onAddButtonClick")),this.container.find(".moj-add-another__add-button, moj-add-another__remove-button").prop("type","button"))}t.prototype.onAddButtonClick=function(t){var e=this.getNewItem(),o=(this.updateAttributes(this.getItems().length,e),this.resetItem(e),this.getItems().first());this.hasRemoveButton(o)||this.createRemoveButton(o),this.getItems().last().after(e),e.find("input, textarea, select").first().focus()},t.prototype.hasRemoveButton=function(t){return t.find(".moj-add-another__remove-button").length},t.prototype.getItems=function(){return this.container.find(".moj-add-another__item")},t.prototype.getNewItem=function(){var t=this.getItems().first().clone();return this.hasRemoveButton(t)||this.createRemoveButton(t),t},t.prototype.updateAttributes=function(i,n){n.find("[data-name]").each(function(t,e){var o=e.id;e.name=s(e).attr("data-name").replace(/%index%/,i),e.id=s(e).attr("data-id").replace(/%index%/,i),(s(e).siblings("label")[0]||s(e).parents("label")[0]||n.find(`[for="${o}"]`)[0]).htmlFor=e.id})},t.prototype.createRemoveButton=function(t){t.append('<button type="button" class="govuk-button govuk-button--secondary moj-add-another__remove-button">Remove</button>')},t.prototype.resetItem=function(t){t.find("[data-name], [data-id]").each(function(t,e){"checkbox"===e.type||"radio"===e.type?e.checked=!1:e.value=""})},t.prototype.onRemoveButtonClick=function(t){s(t.currentTarget).parents(".moj-add-another__item").remove();t=this.getItems();1===t.length&&t.find(".moj-add-another__remove-button").remove(),t.each(s.proxy(function(t,e){this.updateAttributes(t,s(e))},this)),this.focusHeading()},t.prototype.focusHeading=function(){this.container.find(".moj-add-another__heading").get(0).focus()},b={AddAnother:t}}return b})().AddAnother,i=(()=>{if(!k){k=1;let{findNearestMatchingElement:o,getPreviousSibling:i,setFocus:n}=Z();function t(t,e={}){if(!t)return this;var o=Object.freeze({properties:{dismissible:{type:"boolean"},dismissText:{type:"string"},disableAutoFocus:{type:"boolean"},focusOnDismissSelector:{type:"string"}}});this.config=this.mergeConfigs({dismissible:!1,dismissText:"Dismiss",disableAutoFocus:!1},e,this.parseDataset(o,t.dataset)),this.$module=t}t.prototype.init=function(){"alert"!==this.$module.getAttribute("role")||this.config.disableAutoFocus||n(this.$module),this.$dismissButton=this.$module.querySelector(".moj-alert__dismiss"),this.config.dismissible&&this.$dismissButton&&(this.$dismissButton.innerHTML=this.config.dismissText,this.$dismissButton.removeAttribute("hidden"),this.$module.addEventListener("click",t=>{this.$dismissButton.contains(t.target)&&this.dimiss()}))},t.prototype.dimiss=function(){let t;var e;(t=this.config.focusOnDismissSelector?document.querySelector(this.config.focusOnDismissSelector):t)||(e=this.$module.nextElementSibling)&&e.matches(".moj-alert")&&(t=e),(t=(t=t||i(this.$module,".moj-alert, h1, h2, h3, h4, h5, h6"))||o(this.$module,"h1, h2, h3, h4, h5, h6, main, body"))&&n(t),this.$module.remove()},t.prototype.normaliseString=function(t,e){var o=t?t.trim():"";let i,n;switch((n=e&&e.type?e.type:n)||(["true","false"].includes(o)&&(n="boolean"),0<o.length&&isFinite(Number(o))&&(n="number")),n){case"boolean":i="true"===o;break;case"number":i=Number(o);break;default:i=t}return i},t.prototype.parseDataset=function(t,e){var o,i,n={};for([o,i]of Object.entries(t.properties))o in e&&e[o]&&(n[o]=this.normaliseString(e[o],i));return n},t.prototype.mergeConfigs=function(...t){var e,o={};for(e of t)for(var i of Object.keys(e)){var n=o[i],s=e[i];o[i]="object"==typeof n&&"object"==typeof s?this.mergeConfigs(n,s):s}return o},v={Alert:t}}return v})().Alert,s=(x||(x=1,f.prototype.init=function(){if(1===this.$module.children.length){let e=this.$module.children[0];e.classList.forEach(t=>{t.startsWith("govuk-button-")&&e.classList.remove(t),e.classList.remove("moj-button-menu__item")}),this.config.buttonClasses&&e.classList.add(...this.config.buttonClasses.split(" "))}1<this.$module.children.length&&this.initMenu()},f.prototype.initMenu=function(){this.$menu=this.createMenu(),this.$module.insertAdjacentHTML("afterbegin",this.toggleTemplate()),this.setupMenuItems(),this.$menuToggle=this.$module.querySelector(":scope > button"),this.items=this.$menu.querySelectorAll("a, button"),this.$menuToggle.addEventListener("click",t=>{this.toggleMenu(t)}),this.$module.addEventListener("keydown",t=>{this.handleKeyDown(t)}),document.addEventListener("click",t=>{this.$module.contains(t.target)||this.closeMenu(!1)})},f.prototype.createMenu=function(){var t=document.createElement("ul");for(t.setAttribute("role","list"),t.hidden=!0,t.classList.add("moj-button-menu__wrapper"),"right"===this.config.alignMenu&&t.classList.add("moj-button-menu__wrapper--right"),this.$module.appendChild(t);this.$module.firstChild!==t;)t.appendChild(this.$module.firstChild);return t},f.prototype.setupMenuItems=function(){Array.from(this.$menu.children).forEach(e=>{var t=document.createElement("li");this.$menu.insertBefore(t,e),t.appendChild(e),e.setAttribute("tabindex",-1),"BUTTON"===e.tagName&&e.setAttribute("type","button"),e.classList.forEach(t=>{t.startsWith("govuk-button")&&e.classList.remove(t)}),e.addEventListener("click",t=>{setTimeout(()=>{this.closeMenu(!1)},50)})})},f.prototype.toggleTemplate=function(){return`
|
|
2
|
-
<button type="button" class="govuk-button moj-button-menu__toggle-button ${this.config.buttonClasses||""}" aria-haspopup="true" aria-expanded="false">
|
|
3
|
-
<span>
|
|
4
|
-
${this.config.buttonText}
|
|
5
|
-
<svg width="11" height="5" viewBox="0 0 11 5" xmlns="http://www.w3.org/2000/svg">
|
|
6
|
-
<path d="M5.5 0L11 5L0 5L5.5 0Z" fill="currentColor"/>
|
|
7
|
-
</svg>
|
|
8
|
-
</span>
|
|
9
|
-
</button>`},f.prototype.isOpen=function(){return"true"===this.$menuToggle.getAttribute("aria-expanded")},f.prototype.toggleMenu=function(t){t.preventDefault();t=0===t.detail?0:-1;this.isOpen()?this.closeMenu():this.openMenu(t)},f.prototype.openMenu=function(t=0){this.$menu.hidden=!1,this.$menuToggle.setAttribute("aria-expanded","true"),-1!==t&&this.focusItem(t)},f.prototype.closeMenu=function(t=!0){this.$menu.hidden=!0,this.$menuToggle.setAttribute("aria-expanded","false"),t&&this.$menuToggle.focus()},f.prototype.focusItem=function(t){(t=t>=this.items.length?0:t)<0&&(t=this.items.length-1);t=this.items.item(t);t&&t.focus()},f.prototype.currentFocusIndex=function(){var t=document.activeElement;return Array.from(this.items).indexOf(t)},f.prototype.handleKeyDown=function(t){if(t.target===this.$menuToggle)switch(t.key){case"ArrowDown":t.preventDefault(),this.openMenu();break;case"ArrowUp":t.preventDefault(),this.openMenu(this.items.length-1)}if(this.$menu.contains(t.target)&&this.isOpen())switch(t.key){case"ArrowDown":t.preventDefault(),-1!==this.currentFocusIndex()&&this.focusItem(this.currentFocusIndex()+1);break;case"ArrowUp":t.preventDefault(),-1!==this.currentFocusIndex()&&this.focusItem(this.currentFocusIndex()-1);break;case"Home":t.preventDefault(),this.focusItem(0);break;case"End":t.preventDefault(),this.focusItem(this.items.length-1)}"Escape"===t.key&&this.isOpen()&&this.closeMenu(),"Tab"===t.key&&this.isOpen()&&this.closeMenu(!1)},f.prototype.parseDataset=function(t,e){var o,i={};for([o,,]of Object.entries(t.properties))o in e&&e[o]&&(i[o]=e[o]);return i},f.prototype.mergeConfigs=function(...t){var e,o={};for(e of t)for(var i of Object.keys(e)){var n=o[i],s=e[i];o[i]="object"==typeof n&&"object"==typeof s?this.mergeConfigs(n,s):s}return o},D={ButtonMenu:f}),D).ButtonMenu,a=(_||(_=1,g.prototype.init=function(){!this.$input||this.$module.dataset.initialized||(this.setOptions(),this.initControls(),this.$module.setAttribute("data-initialized","true"))},g.prototype.initControls=function(){this.id="datepicker-"+this.$input.id,this.$dialog=this.createDialog(),this.createCalendarHeaders();var t=document.createElement("div"),e=document.createElement("div"),e=(t.classList.add("moj-datepicker__wrapper"),e.classList.add("govuk-input__wrapper"),this.$input.parentNode.insertBefore(t,this.$input),t.appendChild(e),e.appendChild(this.$input),e.insertAdjacentHTML("beforeend",this.toggleTemplate()),t.insertAdjacentElement("beforeend",this.$dialog),this.$calendarButton=this.$module.querySelector(".moj-js-datepicker-toggle"),this.$dialogTitle=this.$dialog.querySelector(".moj-js-datepicker-month-year"),this.createCalendar(),this.$prevMonthButton=this.$dialog.querySelector(".moj-js-datepicker-prev-month"),this.$prevYearButton=this.$dialog.querySelector(".moj-js-datepicker-prev-year"),this.$nextMonthButton=this.$dialog.querySelector(".moj-js-datepicker-next-month"),this.$nextYearButton=this.$dialog.querySelector(".moj-js-datepicker-next-year"),this.$cancelButton=this.$dialog.querySelector(".moj-js-datepicker-cancel"),this.$okButton=this.$dialog.querySelector(".moj-js-datepicker-ok"),this.$prevMonthButton.addEventListener("click",t=>this.focusPreviousMonth(t,!1)),this.$prevYearButton.addEventListener("click",t=>this.focusPreviousYear(t,!1)),this.$nextMonthButton.addEventListener("click",t=>this.focusNextMonth(t,!1)),this.$nextYearButton.addEventListener("click",t=>this.focusNextYear(t,!1)),this.$cancelButton.addEventListener("click",t=>{t.preventDefault(),this.closeDialog(t)}),this.$okButton.addEventListener("click",()=>{this.selectDate(this.currentDate)}),this.$dialog.querySelectorAll('button:not([disabled="true"])'));this.$firstButtonInDialog=e[0],this.$lastButtonInDialog=e[e.length-1],this.$firstButtonInDialog.addEventListener("keydown",t=>this.firstButtonKeydown(t)),this.$lastButtonInDialog.addEventListener("keydown",t=>this.lastButtonKeydown(t)),this.$calendarButton.addEventListener("click",t=>this.toggleDialog(t)),this.$dialog.addEventListener("keydown",t=>{"Escape"===t.key&&(this.closeDialog(),t.preventDefault(),t.stopPropagation())}),document.body.addEventListener("mouseup",t=>this.backgroundClick(t)),this.updateCalendar()},g.prototype.createDialog=function(){var t="datepicker-title-"+this.$input.id,e=document.createElement("div");return e.id=this.id,e.setAttribute("class","moj-datepicker__dialog"),e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-labelledby",t),e.innerHTML=this.dialogTemplate(t),e.hidden=!0,e},g.prototype.createCalendar=function(){var t=this.$dialog.querySelector("tbody");let o=0;for(let e=0;e<6;e++){var i=t.insertRow(e);for(let t=0;t<7;t++){var n=document.createElement("td"),s=document.createElement("button"),n=(n.appendChild(s),i.appendChild(n),new m(s,o,e,t,this));n.init(),this.calendarDays.push(n),o++}}},g.prototype.toggleTemplate=function(){return`<button class="moj-datepicker__toggle moj-js-datepicker-toggle" type="button" aria-haspopup="dialog" aria-controls="${this.id}" aria-expanded="false">
|
|
10
|
-
<span class="govuk-visually-hidden">Choose date</span>
|
|
11
|
-
<svg width="32" height="24" focusable="false" class="moj-datepicker-icon" aria-hidden="true" role="img" viewBox="0 0 22 22">
|
|
12
|
-
<path
|
|
13
|
-
fill="currentColor"
|
|
14
|
-
fill-rule="evenodd"
|
|
15
|
-
clip-rule="evenodd"
|
|
16
|
-
d="M16.1333 2.93333H5.86668V4.4C5.86668 5.21002 5.21003 5.86667 4.40002 5.86667C3.59 5.86667 2.93335 5.21002 2.93335 4.4V2.93333H2C0.895431 2.93333 0 3.82877 0 4.93334V19.2667C0 20.3712 0.89543 21.2667 2 21.2667H20C21.1046 21.2667 22 20.3712 22 19.2667V4.93333C22 3.82876 21.1046 2.93333 20 2.93333H19.0667V4.4C19.0667 5.21002 18.41 5.86667 17.6 5.86667C16.79 5.86667 16.1333 5.21002 16.1333 4.4V2.93333ZM20.5333 8.06667H1.46665V18.8C1.46665 19.3523 1.91436 19.8 2.46665 19.8H19.5333C20.0856 19.8 20.5333 19.3523 20.5333 18.8V8.06667Z"
|
|
17
|
-
></path>
|
|
18
|
-
<rect x="3.66669" width="1.46667" height="5.13333" rx="0.733333" fill="currentColor"></rect>
|
|
19
|
-
<rect x="16.8667" width="1.46667" height="5.13333" rx="0.733333" fill="currentColor"></rect>
|
|
20
|
-
</svg>
|
|
21
|
-
</button>`},g.prototype.dialogTemplate=function(t){return`<div class="moj-datepicker__dialog-header">
|
|
22
|
-
<div class="moj-datepicker__dialog-navbuttons">
|
|
23
|
-
<button class="moj-datepicker__button moj-js-datepicker-prev-year">
|
|
24
|
-
<span class="govuk-visually-hidden">Previous year</span>
|
|
25
|
-
<svg width="44" height="40" viewBox="0 0 44 40" fill="none" fill="none" focusable="false" aria-hidden="true" role="img">
|
|
26
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M23.1643 20L28.9572 14.2071L27.5429 12.7929L20.3358 20L27.5429 27.2071L28.9572 25.7929L23.1643 20Z" fill="currentColor"/>
|
|
27
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.1643 20L22.9572 14.2071L21.5429 12.7929L14.3358 20L21.5429 27.2071L22.9572 25.7929L17.1643 20Z" fill="currentColor"/>
|
|
28
|
-
</svg>
|
|
29
|
-
</button>
|
|
30
|
-
|
|
31
|
-
<button class="moj-datepicker__button moj-js-datepicker-prev-month">
|
|
32
|
-
<span class="govuk-visually-hidden">Previous month</span>
|
|
33
|
-
<svg width="44" height="40" viewBox="0 0 44 40" fill="none" focusable="false" aria-hidden="true" role="img">
|
|
34
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.5729 20L25.7865 14.2071L24.5137 12.7929L18.0273 20L24.5137 27.2071L25.7865 25.7929L20.5729 20Z" fill="currentColor"/>
|
|
35
|
-
</svg>
|
|
36
|
-
</button>
|
|
37
|
-
</div>
|
|
38
|
-
|
|
39
|
-
<h2 id="${t}" class="moj-datepicker__dialog-title moj-js-datepicker-month-year" aria-live="polite">June 2020</h2>
|
|
40
|
-
|
|
41
|
-
<div class="moj-datepicker__dialog-navbuttons">
|
|
42
|
-
<button class="moj-datepicker__button moj-js-datepicker-next-month">
|
|
43
|
-
<span class="govuk-visually-hidden">Next month</span>
|
|
44
|
-
<svg width="44" height="40" viewBox="0 0 44 40" fill="none" focusable="false" aria-hidden="true" role="img">
|
|
45
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M23.4271 20L18.2135 14.2071L19.4863 12.7929L25.9727 20L19.4863 27.2071L18.2135 25.7929L23.4271 20Z" fill="currentColor"/>
|
|
46
|
-
</svg>
|
|
47
|
-
</button>
|
|
48
|
-
|
|
49
|
-
<button class="moj-datepicker__button moj-js-datepicker-next-year">
|
|
50
|
-
<span class="govuk-visually-hidden">Next year</span>
|
|
51
|
-
<svg width="44" height="40" viewBox="0 0 44 40" fill="none" fill="none" focusable="false" aria-hidden="true" role="img">
|
|
52
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M20.8357 20L15.0428 14.2071L16.4571 12.7929L23.6642 20L16.4571 27.2071L15.0428 25.7929L20.8357 20Z" fill="currentColor"/>
|
|
53
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M26.8357 20L21.0428 14.2071L22.4571 12.7929L29.6642 20L22.4571 27.2071L21.0428 25.7929L26.8357 20Z" fill="currentColor"/>
|
|
54
|
-
</svg>
|
|
55
|
-
</button>
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
|
|
59
|
-
<table class="moj-datepicker__calendar moj-js-datepicker-grid" role="grid" aria-labelledby="${t}">
|
|
60
|
-
<thead>
|
|
61
|
-
<tr></tr>
|
|
62
|
-
</thead>
|
|
63
|
-
|
|
64
|
-
<tbody></tbody>
|
|
65
|
-
</table>
|
|
66
|
-
|
|
67
|
-
<div class="govuk-button-group">
|
|
68
|
-
<button type="button" class="govuk-button moj-js-datepicker-ok">Select</button>
|
|
69
|
-
<button type="button" class="govuk-button govuk-button--secondary moj-js-datepicker-cancel">Close</button>
|
|
70
|
-
</div>`},g.prototype.createCalendarHeaders=function(){this.dayLabels.forEach(t=>{t=`<th scope="col"><span aria-hidden="true">${t.substring(0,3)}</span><span class="govuk-visually-hidden">${t}</span></th>`;this.$dialog.querySelector("thead > tr").insertAdjacentHTML("beforeend",t)})},g.prototype.leadingZeros=function(t,e=2){let o=t.toString();for(;o.length<e;)o="0"+o;return o},g.prototype.setOptions=function(){this.setMinAndMaxDatesOnCalendar(),this.setExcludedDates(),this.setExcludedDays(),this.setLeadingZeros(),this.setWeekStartDay()},g.prototype.setMinAndMaxDatesOnCalendar=function(){this.config.minDate&&(this.minDate=this.formattedDateFromString(this.config.minDate,null),this.minDate)&&this.currentDate<this.minDate&&(this.currentDate=this.minDate),this.config.maxDate&&(this.maxDate=this.formattedDateFromString(this.config.maxDate,null),this.maxDate)&&this.currentDate>this.maxDate&&(this.currentDate=this.maxDate)},g.prototype.setExcludedDates=function(){this.config.excludedDates&&(this.excludedDates=this.config.excludedDates.replace(/\s+/," ").split(" ").map(t=>t.includes("-")?this.parseDateRangeString(t):this.formattedDateFromString(t)).flat().filter(t=>t))},g.prototype.parseDateRangeString=function(t){var e=[],[t,o]=t.split("-").map(t=>this.formattedDateFromString(t,null));if(t&&o)for(var i=new Date(t.getTime());i<=o;)e.push(new Date(i)),i.setDate(i.getDate()+1);return e},g.prototype.setExcludedDays=function(){if(this.config.excludedDays){let e=this.dayLabels.map(t=>t.toLowerCase());"monday"===this.config.weekStartDay&&e.unshift(e.pop()),this.excludedDays=this.config.excludedDays.replace(/\s+/," ").toLowerCase().split(" ").map(t=>e.indexOf(t)).filter(t=>-1!==t)}},g.prototype.setLeadingZeros=function(){"boolean"!=typeof this.config.leadingZeros&&("true"===this.config.leadingZeros.toLowerCase()?this.config.leadingZeros=!0:"false"===this.config.leadingZeros.toLowerCase()&&(this.config.leadingZeros=!1))},g.prototype.setWeekStartDay=function(){var t=this.config.weekStartDay;t&&"sunday"===t.toLowerCase()?(this.config.weekStartDay="sunday",this.dayLabels.unshift(this.dayLabels.pop())):this.config.weekStartDay="monday"},g.prototype.isExcludedDate=function(t){if(this.minDate&&this.minDate>t)return!0;if(this.maxDate&&this.maxDate<t)return!0;for(var e of this.excludedDates)if(t.toDateString()===e.toDateString())return!0;return!!this.excludedDays.includes(t.getDay())},g.prototype.formattedDateFromString=function(t,e=new Date){var o=/(\d{1,2})([-/,. ])(\d{1,2})\2(\d{4})/;return o.test(t)&&(o=(t=t.match(o))[1],(t=new Date(t[4]+`-${t[3]}-`+o))instanceof Date)&&!isNaN(t)?t:e},g.prototype.formattedDateFromDate=function(t){return this.config.leadingZeros?`${this.leadingZeros(t.getDate())}/${this.leadingZeros(t.getMonth()+1)}/`+t.getFullYear():`${t.getDate()}/${t.getMonth()+1}/`+t.getFullYear()},g.prototype.formattedDateHuman=function(t){return`${this.dayLabels[(t.getDay()+6)%7]} ${t.getDate()} ${this.monthLabels[t.getMonth()]} `+t.getFullYear()},g.prototype.backgroundClick=function(t){!this.isOpen()||this.$dialog.contains(t.target)||this.$input.contains(t.target)||this.$calendarButton.contains(t.target)||(t.preventDefault(),this.closeDialog())},g.prototype.firstButtonKeydown=function(t){"Tab"===t.key&&t.shiftKey&&(this.$lastButtonInDialog.focus(),t.preventDefault())},g.prototype.lastButtonKeydown=function(t){"Tab"!==t.key||t.shiftKey||(this.$firstButtonInDialog.focus(),t.preventDefault())},g.prototype.updateCalendar=function(){this.$dialogTitle.innerHTML=this.monthLabels[this.currentDate.getMonth()]+" "+this.currentDate.getFullYear();var e=this.currentDate,t=new Date(e.getFullYear(),e.getMonth(),1);let o;o="monday"===this.config.weekStartDay?0===t.getDay()?6:t.getDay()-1:t.getDay(),t.setDate(t.getDate()-o);var i=new Date(t);for(let t=0;t<this.calendarDays.length;t++){var n=i.getMonth()!==e.getMonth(),s=this.isExcludedDate(i);this.calendarDays[t].update(i,n,s),i.setDate(i.getDate()+1)}},g.prototype.setCurrentDate=function(i=!0){let n=this.currentDate;var t;this.calendarDays.forEach(t=>{t.button.classList.add("moj-datepicker__button"),t.button.classList.add("moj-datepicker__calendar-day"),t.button.setAttribute("tabindex",-1),t.button.classList.remove(this.selectedDayButtonClass);var e=t.date,o=(e.setHours(0,0,0,0),new Date);o.setHours(0,0,0,0),e.getTime()===n.getTime()&&i&&(t.button.setAttribute("tabindex",0),t.button.focus(),t.button.classList.add(this.selectedDayButtonClass)),this.inputDate&&e.getTime()===this.inputDate.getTime()?(t.button.classList.add(this.currentDayButtonClass),t.button.setAttribute("aria-current","date")):(t.button.classList.remove(this.currentDayButtonClass),t.button.removeAttribute("aria-current")),e.getTime()===o.getTime()?t.button.classList.add(this.todayButtonClass):t.button.classList.remove(this.todayButtonClass)}),i||((t=this.calendarDays.filter(t=>"block"===window.getComputedStyle(t.button).display&&!t.button.disabled))[0].button.setAttribute("tabindex",0),this.currentDate=t[0].date)},g.prototype.selectDate=function(t){this.isExcludedDate(t)||(this.$calendarButton.querySelector("span").innerText="Choose date. Selected date is "+this.formattedDateHuman(t),this.$input.value=this.formattedDateFromDate(t),t=new Event("change",{bubbles:!0,cancelable:!0}),this.$input.dispatchEvent(t),this.closeDialog())},g.prototype.isOpen=function(){return this.$dialog.classList.contains("moj-datepicker__dialog--open")},g.prototype.toggleDialog=function(t){t.preventDefault(),this.isOpen()?this.closeDialog():(this.setMinAndMaxDatesOnCalendar(),this.openDialog())},g.prototype.openDialog=function(){this.$dialog.hidden=!1,this.$dialog.classList.add("moj-datepicker__dialog--open"),this.$calendarButton.setAttribute("aria-expanded","true"),this.$input.offsetWidth>this.$dialog.offsetWidth&&(this.$dialog.style.right="0px"),this.$dialog.style.top=this.$input.offsetHeight+3+"px",this.inputDate=this.formattedDateFromString(this.$input.value),this.currentDate=this.inputDate,this.currentDate.setHours(0,0,0,0),this.updateCalendar(),this.setCurrentDate()},g.prototype.closeDialog=function(){this.$dialog.hidden=!0,this.$dialog.classList.remove("moj-datepicker__dialog--open"),this.$calendarButton.setAttribute("aria-expanded","false"),this.$calendarButton.focus()},g.prototype.goToDate=function(t,e){var o=this.currentDate;this.currentDate=t,o.getMonth()===this.currentDate.getMonth()&&o.getFullYear()===this.currentDate.getFullYear()||this.updateCalendar(),this.setCurrentDate(e)},g.prototype.focusNextDay=function(){var t=new Date(this.currentDate);t.setDate(t.getDate()+1),this.goToDate(t)},g.prototype.focusPreviousDay=function(){var t=new Date(this.currentDate);t.setDate(t.getDate()-1),this.goToDate(t)},g.prototype.focusNextWeek=function(){var t=new Date(this.currentDate);t.setDate(t.getDate()+7),this.goToDate(t)},g.prototype.focusPreviousWeek=function(){var t=new Date(this.currentDate);t.setDate(t.getDate()-7),this.goToDate(t)},g.prototype.focusFirstDayOfWeek=function(){var t=new Date(this.currentDate),e="sunday"===this.config.weekStartDay?0:1,o=t.getDay(),e=e<=o?o-e:6-o;t.setDate(t.getDate()-e),t.setHours(0,0,0,0),this.goToDate(t)},g.prototype.focusLastDayOfWeek=function(){var t=new Date(this.currentDate),e="sunday"===this.config.weekStartDay?6:0,o=t.getDay(),e=o<=e?e-o:7-o;t.setDate(t.getDate()+e),t.setHours(0,0,0,0),this.goToDate(t)},g.prototype.focusNextMonth=function(t,e=!0){t.preventDefault();t=new Date(this.currentDate);t.setMonth(t.getMonth()+1,1),this.goToDate(t,e)},g.prototype.focusPreviousMonth=function(t,e=!0){t.preventDefault();t=new Date(this.currentDate);t.setMonth(t.getMonth()-1,1),this.goToDate(t,e)},g.prototype.focusNextYear=function(t,e=!0){t.preventDefault();t=new Date(this.currentDate);t.setFullYear(t.getFullYear()+1,t.getMonth(),1),this.goToDate(t,e)},g.prototype.focusPreviousYear=function(t,e=!0){t.preventDefault();t=new Date(this.currentDate);t.setFullYear(t.getFullYear()-1,t.getMonth(),1),this.goToDate(t,e)},g.prototype.parseDataset=function(t,e){var o,i={};for([o,,]of Object.entries(t.properties))o in e&&(i[o]=e[o]);return i},g.prototype.mergeConfigs=function(...t){var e,o={};for(e of t)for(var i of Object.keys(e)){var n=o[i],s=e[i];o[i]="object"==typeof n&&"object"==typeof s?this.mergeConfigs(n,s):s}return o},m.prototype.init=function(){this.button.addEventListener("keydown",this.keyPress.bind(this)),this.button.addEventListener("click",this.click.bind(this))},m.prototype.update=function(t,e,o){var i=t.getDate();let n=this.picker.formattedDateHuman(t);o?(this.button.setAttribute("aria-disabled",!0),n="Excluded date, "+n):this.button.removeAttribute("aria-disabled"),this.button.style.display=e?"none":"block",this.button.setAttribute("data-testid",this.picker.formattedDateFromDate(t)),this.button.innerHTML=`<span class="govuk-visually-hidden">${n}</span><span aria-hidden="true">${i}</span>`,this.date=new Date(t)},m.prototype.click=function(t){this.picker.goToDate(this.date),this.picker.selectDate(this.date),t.stopPropagation(),t.preventDefault()},m.prototype.keyPress=function(t){let e=!0;switch(t.key){case"ArrowLeft":this.picker.focusPreviousDay();break;case"ArrowRight":this.picker.focusNextDay();break;case"ArrowUp":this.picker.focusPreviousWeek();break;case"ArrowDown":this.picker.focusNextWeek();break;case"Home":this.picker.focusFirstDayOfWeek();break;case"End":this.picker.focusLastDayOfWeek();break;case"PageUp":t.shiftKey?this.picker.focusPreviousYear(t):this.picker.focusPreviousMonth(t);break;case"PageDown":t.shiftKey?this.picker.focusNextYear(t):this.picker.focusNextMonth(t);break;default:e=!1}e&&(t.preventDefault(),t.stopPropagation())},j={DatePicker:g}),j).DatePicker;var t=(()=>{if(!C){C=1;let e=z;function t(t){this.options=t,this.container=e(this.options.toggleButton.container),this.filterContainer=e(this.options.filter.container),this.createToggleButton(),this.setupResponsiveChecks(),this.filterContainer.attr("tabindex","-1"),this.options.startHidden&&this.hideMenu()}t.prototype.setupResponsiveChecks=function(){this.mq=window.matchMedia(this.options.bigModeMediaQuery),this.mq.addListener(e.proxy(this,"checkMode")),this.checkMode(this.mq)},t.prototype.createToggleButton=function(){this.menuButton=e(`<button class="govuk-button ${this.options.toggleButton.classes}" type="button" aria-haspopup="true" aria-expanded="false">${this.options.toggleButton.showText}</button>`),this.menuButton.on("click",e.proxy(this,"onMenuButtonClick")),this.container.append(this.menuButton)},t.prototype.checkMode=function(t){t.matches?this.enableBigMode():this.enableSmallMode()},t.prototype.enableBigMode=function(){this.showMenu(),this.removeCloseButton()},t.prototype.enableSmallMode=function(){this.hideMenu(),this.addCloseButton()},t.prototype.addCloseButton=function(){this.options.closeButton&&(this.closeButton=e(`<button class="moj-filter__close" type="button">${this.options.closeButton.text}</button>`),this.closeButton.on("click",e.proxy(this,"onCloseClick")),e(this.options.closeButton.container).append(this.closeButton))},t.prototype.onCloseClick=function(){this.hideMenu(),this.menuButton.focus()},t.prototype.removeCloseButton=function(){this.closeButton&&(this.closeButton.remove(),this.closeButton=null)},t.prototype.hideMenu=function(){this.menuButton.attr("aria-expanded","false"),this.filterContainer.addClass("moj-js-hidden"),this.menuButton.text(this.options.toggleButton.showText)},t.prototype.showMenu=function(){this.menuButton.attr("aria-expanded","true"),this.filterContainer.removeClass("moj-js-hidden"),this.menuButton.text(this.options.toggleButton.hideText)},t.prototype.onMenuButtonClick=function(){this.toggle()},t.prototype.toggle=function(){"false"===this.menuButton.attr("aria-expanded")?(this.showMenu(),this.filterContainer.get(0).focus()):this.hideMenu()},w={FilterToggleButton:t}}return w})().FilterToggleButton,e=(()=>{if(!$){$=1;let o=z,{dragAndDropSupported:e,fileApiSupported:i,formDataSupported:n}=Z();function t(t){e()&&n()&&i()&&(this.defaultParams={uploadFileEntryHook:o.noop,uploadFileExitHook:o.noop,uploadFileErrorHook:o.noop,fileDeleteHook:o.noop,uploadStatusText:"Uploading files, please wait",dropzoneHintText:"Drag and drop files here or",dropzoneButtonText:"Choose files"},this.params=o.extend({},this.defaultParams,t),this.container=o(this.params.container),this.container.addClass("moj-multi-file-upload--enhanced"),this.feedbackContainer=this.container.find(".moj-multi-file__uploaded-files"),this.setupFileInput(),this.setupDropzone(),this.setupLabel(),this.setupStatusBox(),this.container.on("click",".moj-multi-file-upload__delete",o.proxy(this,"onFileDeleteClick")))}t.prototype.setupDropzone=function(){this.fileInput.wrap('<div class="moj-multi-file-upload__dropzone" />'),this.dropzone=this.container.find(".moj-multi-file-upload__dropzone"),this.dropzone.on("dragover",o.proxy(this,"onDragOver")),this.dropzone.on("dragleave",o.proxy(this,"onDragLeave")),this.dropzone.on("drop",o.proxy(this,"onDrop"))},t.prototype.setupLabel=function(){this.label=o(`<label for="${this.fileInput[0].id}" class="govuk-button govuk-button--secondary">${this.params.dropzoneButtonText}</label>`),this.dropzone.append(`<p class="govuk-body">${this.params.dropzoneHintText}</p>`),this.dropzone.append(this.label)},t.prototype.setupFileInput=function(){this.fileInput=this.container.find(".moj-multi-file-upload__input"),this.fileInput.on("change",o.proxy(this,"onFileChange")),this.fileInput.on("focus",o.proxy(this,"onFileFocus")),this.fileInput.on("blur",o.proxy(this,"onFileBlur"))},t.prototype.setupStatusBox=function(){this.status=o('<div aria-live="polite" role="status" class="govuk-visually-hidden" />'),this.dropzone.append(this.status)},t.prototype.onDragOver=function(t){t.preventDefault(),this.dropzone.addClass("moj-multi-file-upload--dragover")},t.prototype.onDragLeave=function(){this.dropzone.removeClass("moj-multi-file-upload--dragover")},t.prototype.onDrop=function(t){t.preventDefault(),this.dropzone.removeClass("moj-multi-file-upload--dragover"),this.feedbackContainer.removeClass("moj-hidden"),this.status.html(this.params.uploadStatusText),this.uploadFiles(t.originalEvent.dataTransfer.files)},t.prototype.uploadFiles=function(e){for(let t=0;t<e.length;t++)this.uploadFile(e[t])},t.prototype.onFileChange=function(t){this.feedbackContainer.removeClass("moj-hidden"),this.status.html(this.params.uploadStatusText),this.uploadFiles(t.currentTarget.files),this.fileInput.replaceWith(o(t.currentTarget).val("").clone(!0)),this.setupFileInput(),this.fileInput.get(0).focus()},t.prototype.onFileFocus=function(t){this.label.addClass("moj-multi-file-upload--focused")},t.prototype.onFileBlur=function(t){this.label.removeClass("moj-multi-file-upload--focused")},t.prototype.getSuccessHtml=function(t){return`<span class="moj-multi-file-upload__success"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"/></svg>${t.messageHtml}</span>`},t.prototype.getErrorHtml=function(t){return`<span class="moj-multi-file-upload__error"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M13.6,15.4h-2.3v-4.5h2.3V15.4z M13.6,19.8h-2.3v-2.2h2.3V19.8z M0,23.2h25L12.5,2L0,23.2z"/></svg>${t.message}</span>`},t.prototype.getFileRowHtml=function(t){return`
|
|
71
|
-
<div class="govuk-summary-list__row moj-multi-file-upload__row">;
|
|
72
|
-
<div class="govuk-summary-list__value moj-multi-file-upload__message">;
|
|
73
|
-
<span class="moj-multi-file-upload__filename">${t.name}</span>;
|
|
74
|
-
<span class="moj-multi-file-upload__progress">0%</span>;
|
|
75
|
-
</div>';
|
|
76
|
-
<div class="govuk-summary-list__actions moj-multi-file-upload__actions"></div>;
|
|
77
|
-
</div>`},t.prototype.getDeleteButtonHtml=function(t){return`<button class="moj-multi-file-upload__delete govuk-button govuk-button--secondary govuk-!-margin-bottom-0" type="button" name="delete" value="${t.filename}">
|
|
78
|
-
Delete <span class="govuk-visually-hidden">${t.originalname}</span>
|
|
79
|
-
</button>`},t.prototype.uploadFile=function(i){this.params.uploadFileEntryHook(this,i);let e=o(this.getFileRowHtml(i));var t=new FormData;t.append("documents",i),this.feedbackContainer.find(".moj-multi-file-upload__list").append(e),o.ajax({url:this.params.uploadUrl,type:"post",data:t,processData:!1,contentType:!1,success:o.proxy(function(t){t.error?(e.find(".moj-multi-file-upload__message").html(this.getErrorHtml(t.error)),this.status.html(t.error.message)):(e.find(".moj-multi-file-upload__message").html(this.getSuccessHtml(t.success)),this.status.html(t.success.messageText)),e.find(".moj-multi-file-upload__actions").append(this.getDeleteButtonHtml(t.file)),this.params.uploadFileExitHook(this,i,t)},this),error:o.proxy(function(t,e,o){this.params.uploadFileErrorHook(this,i,t,e,o)},this),xhr:function(){var t=new XMLHttpRequest;return t.upload.addEventListener("progress",function(t){t.lengthComputable&&(t=t.loaded/t.total,t=parseInt(100*t,10),e.find(".moj-multi-file-upload__progress").text(` ${t}%`))},!1),t}})},t.prototype.onFileDeleteClick=function(t){t.preventDefault();let e=o(t.currentTarget);t={};t[e[0].name]=e[0].value,o.ajax({url:this.params.deleteUrl,type:"post",dataType:"json",data:t,success:o.proxy(function(t){t.error||(e.parents(".moj-multi-file-upload__row").remove(),0===this.feedbackContainer.find(".moj-multi-file-upload__row").length&&this.feedbackContainer.addClass("moj-hidden")),this.params.fileDeleteHook(this,t)},this)})},B={MultiFileUpload:t}}return B})().MultiFileUpload;let r=(()=>{if(!M){M=1;let i=z;function t(e){if(this.container=i(e.container),!this.container.data("moj-multi-select-initialised")){this.container.data("moj-multi-select-initialised",!0);var o=e.id_prefix;let t=void 0!==o?o+"checkboxes-all":"checkboxes-all";this.toggle=i(this.getToggleHtml(t)),this.toggleButton=this.toggle.find("input"),this.toggleButton.on("click",i.proxy(this,"onButtonClick")),this.container.append(this.toggle),this.checkboxes=i(e.checkboxes),this.checkboxes.on("click",i.proxy(this,"onCheckboxClick")),this.checked=e.checked||!1}}t.prototype.getToggleHtml=function(t){var e="";return e+'<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">'+` <input type="checkbox" class="govuk-checkboxes__input" id="${t}">`+` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${t}">`+' <span class="govuk-visually-hidden">Select all</span>'+" </label>"+"</div>"},t.prototype.onButtonClick=function(t){this.checked?(this.uncheckAll(),this.toggleButton[0].checked=!1):(this.checkAll(),this.toggleButton[0].checked=!0)},t.prototype.checkAll=function(){this.checkboxes.each(i.proxy(function(t,e){e.checked=!0},this)),this.checked=!0},t.prototype.uncheckAll=function(){this.checkboxes.each(i.proxy(function(t,e){e.checked=!1},this)),this.checked=!1},t.prototype.onCheckboxClick=function(t){t.target.checked?this.checkboxes.filter(":checked").length===this.checkboxes.length&&(this.toggleButton[0].checked=!0,this.checked=!0):(this.toggleButton[0].checked=!1,this.checked=!1)},L={MultiSelect:t}}return L})().MultiSelect,l=(()=>{if(!S){S=1;let e=z;function t(t){this.el=t;t=e(this.el);t.data("moj-password-reveal-initialised")||(t.data("moj-password-reveal-initialised",!0),t.attr("spellcheck","false"),t.wrap('<div class="moj-password-reveal"></div>'),this.container=e(this.el).parent(),this.createButton())}t.prototype.createButton=function(){this.button=e('<button type="button" class="govuk-button govuk-button--secondary moj-password-reveal__button">Show <span class="govuk-visually-hidden">password</span></button>'),this.container.append(this.button),this.button.on("click",e.proxy(this,"onButtonClick"))},t.prototype.onButtonClick=function(){"password"===this.el.type?(this.el.type="text",this.button.html('Hide <span class="govuk-visually-hidden">password</span>')):(this.el.type="password",this.button.html('Show <span class="govuk-visually-hidden">password</span>'))},T={PasswordReveal:t}}return T})().PasswordReveal,u=(()=>{if(!E){E=1;let e=z;function t(t){"contentEditable"in document.documentElement&&(this.options=t,this.options.toolbar=this.options.toolbar||{bold:!1,italic:!1,underline:!1,bullets:!0,numbers:!0},this.textarea=this.options.textarea,this.container=e(this.textarea).parent(),this.container.data("moj-rich-text-editor-initialised")||(this.container.data("moj-rich-text-editor-initialised",!0),this.createToolbar(),this.hideDefault(),this.configureToolbar(),this.keys={left:37,right:39,up:38,down:40},this.container.on("click",".moj-rich-text-editor__toolbar-button",e.proxy(this,"onButtonClick")),this.container.find(".moj-rich-text-editor__content").on("input",e.proxy(this,"onEditorInput")),this.container.find("label").on("click",e.proxy(this,"onLabelClick")),this.toolbar.on("keydown",e.proxy(this,"onToolbarKeydown"))))}t.prototype.onToolbarKeydown=function(t){let e;switch(t.keyCode){case this.keys.right:case this.keys.down:var o=(e=this.toolbar.find("button[tabindex=0]")).next("button");o[0]&&(o.focus(),e.attr("tabindex","-1"),o.attr("tabindex","0"));break;case this.keys.left:case this.keys.up:o=(e=this.toolbar.find("button[tabindex=0]")).prev("button");o[0]&&(o.focus(),e.attr("tabindex","-1"),o.attr("tabindex","0"))}},t.prototype.getToolbarHtml=function(){let t="";return t+='<div class="moj-rich-text-editor__toolbar" role="toolbar">',this.options.toolbar.bold&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--bold" type="button" data-command="bold"><span class="govuk-visually-hidden">Bold</span></button>'),this.options.toolbar.italic&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--italic" type="button" data-command="italic"><span class="govuk-visually-hidden">Italic</span></button>'),this.options.toolbar.underline&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--underline" type="button" data-command="underline"><span class="govuk-visually-hidden">Underline</span></button>'),this.options.toolbar.bullets&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--unordered-list" type="button" data-command="insertUnorderedList"><span class="govuk-visually-hidden">Unordered list</span></button>'),this.options.toolbar.numbers&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--ordered-list" type="button" data-command="insertOrderedList"><span class="govuk-visually-hidden">Ordered list</span></button>'),t+="</div>"},t.prototype.getEnhancedHtml=function(t){return this.getToolbarHtml()+'<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>'},t.prototype.hideDefault=function(){this.textarea=this.container.find("textarea"),this.textarea.addClass("govuk-visually-hidden"),this.textarea.attr("aria-hidden",!0),this.textarea.attr("tabindex","-1")},t.prototype.createToolbar=function(){this.toolbar=document.createElement("div"),this.toolbar.className="moj-rich-text-editor",this.toolbar.innerHTML=this.getEnhancedHtml(),this.container.append(this.toolbar),this.toolbar=this.container.find(".moj-rich-text-editor__toolbar"),this.container.find(".moj-rich-text-editor__content").html(this.textarea.val())},t.prototype.configureToolbar=function(){this.buttons=this.container.find(".moj-rich-text-editor__toolbar-button"),this.buttons.prop("tabindex","-1"),this.buttons.first().prop("tabindex","0")},t.prototype.onButtonClick=function(t){document.execCommand(e(t.currentTarget).data("command"),!1,null)},t.prototype.getContent=function(){return this.container.find(".moj-rich-text-editor__content").html()},t.prototype.onEditorInput=function(t){this.updateTextarea()},t.prototype.updateTextarea=function(){document.execCommand("defaultParagraphSeparator",!1,"p"),this.textarea.val(this.getContent())},t.prototype.onLabelClick=function(t){t.preventDefault(),this.container.find(".moj-rich-text-editor__content").focus()},A={RichTextEditor:t}}return A})().RichTextEditor,d=(()=>{if(!H){H=1;let e=z;function t(t){this.options=t,this.container=e(this.options.search.container),this.toggleButtonContainer=e(this.options.toggleButton.container),this.container.data("moj-search-toggle-initialised")||(this.container.data("moj-search-toggle-initialised",!0),this.toggleButton=e(`<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">
|
|
80
|
-
${this.options.toggleButton.text} <svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>
|
|
81
|
-
</button>`),this.toggleButton.on("click",e.proxy(this,"onToggleButtonClick")),this.toggleButtonContainer.append(this.toggleButton),e(document).on("click",this.onDocumentClick.bind(this)),e(document).on("focusin",this.onDocumentClick.bind(this)))}t.prototype.showMenu=function(){this.toggleButton.attr("aria-expanded","true"),this.container.removeClass("moj-js-hidden"),this.container.find("input").first().get(0).focus()},t.prototype.hideMenu=function(){this.container.addClass("moj-js-hidden"),this.toggleButton.attr("aria-expanded","false")},t.prototype.onToggleButtonClick=function(){"false"===this.toggleButton.attr("aria-expanded")?this.showMenu():this.hideMenu()},t.prototype.onDocumentClick=function(t){e.contains(this.toggleButtonContainer[0],t.target)||e.contains(this.container[0],t.target)||this.hideMenu()},F={SearchToggle:t}}return F})().SearchToggle,c=(()=>{if(!O){O=1;let s=z;function t(t){this.table=s(t.table),this.table.data("moj-search-toggle-initialised")||(this.table.data("moj-search-toggle-initialised",!0),this.setupOptions(t),this.body=this.table.find("tbody"),this.createHeadingButtons(),this.createStatusBox(),this.initialiseSortedColumn(),this.table.on("click","th button",s.proxy(this,"onSortButtonClick")))}t.prototype.setupOptions=function(t){this.statusMessage=(t=t||{}).statusMessage||"Sort by %heading% (%direction%)",this.ascendingText=t.ascendingText||"ascending",this.descendingText=t.descendingText||"descending"},t.prototype.createHeadingButtons=function(){var e,o=this.table.find("thead th");for(let t=0;t<o.length;t++)(e=s(o[t])).attr("aria-sort")&&this.createHeadingButton(e,t)},t.prototype.createHeadingButton=function(t,e){var o=t.text(),e=s(`<button type="button" data-index="${e}">${o}</button>`);t.text(""),t.append(e)},t.prototype.createStatusBox=function(){this.status=s('<div aria-live="polite" role="status" aria-atomic="true" class="govuk-visually-hidden" />'),this.table.parent().append(this.status)},t.prototype.initialiseSortedColumn=function(){let i=this.getTableRowsArray();this.table.find("th").filter('[aria-sort="ascending"], [aria-sort="descending"]').first().each((t,e)=>{var o=s(e).attr("aria-sort"),e=s(e).find("button").attr("data-index"),e=this.sort(i,e,o);this.addRows(e)})},t.prototype.onSortButtonClick=function(t){var e=t.currentTarget.getAttribute("data-index"),o=s(t.currentTarget).parent().attr("aria-sort");let i;i="none"===o||"descending"===o?"ascending":"descending";o=this.getTableRowsArray(),o=this.sort(o,e,i);this.addRows(o),this.removeButtonStates(),this.updateButtonState(s(t.currentTarget),i)},t.prototype.updateButtonState=function(t,e){t.parent().attr("aria-sort",e);let o=this.statusMessage;o=(o=o.replace(/%heading%/,t.text())).replace(/%direction%/,this[e+"Text"]),this.status.text(o)},t.prototype.removeButtonStates=function(){this.table.find("thead th").attr("aria-sort","none")},t.prototype.addRows=function(e){for(let t=0;t<e.length;t++)this.body.append(e[t])},t.prototype.getTableRowsArray=function(){var e=[],o=this.body.find("tr");for(let t=0;t<o.length;t++)e.push(o[t]);return e},t.prototype.sort=function(t,i,n){return t.sort(function(t,e){var t=s(t).find("td,th").eq(i),e=s(e).find("td,th").eq(i),o="ascending"===n?this.getCellValue(t):this.getCellValue(e),e="ascending"===n?this.getCellValue(e):this.getCellValue(t);return"string"==typeof o||"string"==typeof e?o.toString().localeCompare(e.toString()):o-e}.bind(this))},t.prototype.getCellValue=function(t){var t=t.attr("data-sort-value")||t.html(),e=Number(t);return isNaN(e)?t:e},I={SortableTable:t}}return I})().SortableTable,h=Z().nodeListForEach;var p=(R||(R=1,q={version:"0.0.0-development"}),q).version;function f(t,e={}){if(!t)return this;var o=Object.freeze({properties:{buttonText:{type:"string"},buttonClasses:{type:"string"},alignMenu:{type:"string"}}});this.config=this.mergeConfigs({buttonText:"Actions",alignMenu:"left",buttonClasses:""},e,this.parseDataset(o,t.dataset)),this.$module=t}function g(t,e={}){if(!t)return this;var o=Object.freeze({properties:{excludedDates:{type:"string"},excludedDays:{type:"string"},leadingZeros:{type:"string"},maxDate:{type:"string"},minDate:{type:"string"},weekStartDay:{type:"string"}}});this.config=this.mergeConfigs({leadingZeros:!1,weekStartDay:"monday"},e,this.parseDataset(o,t.dataset)),this.dayLabels=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],this.monthLabels=["January","February","March","April","May","June","July","August","September","October","November","December"],this.currentDate=new Date,this.currentDate.setHours(0,0,0,0),this.calendarDays=[],this.excludedDates=[],this.excludedDays=[],this.buttonClass="moj-datepicker__button",this.selectedDayButtonClass="moj-datepicker__button--selected",this.currentDayButtonClass="moj-datepicker__button--current",this.todayButtonClass="moj-datepicker__button--today",this.$module=t,this.$input=t.querySelector(".moj-js-datepicker-input")}function m(t,e,o,i,n){this.index=e,this.row=o,this.column=i,this.button=t,this.picker=n,this.date=new Date}P={initAll:function(t){var e=(t=void 0!==(t=void 0!==t?t:{}).scope?t.scope:document).querySelectorAll('[data-module="moj-add-another"]'),e=(h(e,function(t){new o(t)}),t.querySelectorAll('[data-module="moj-multi-select"]')),e=(h(e,function(t){new r({container:t.querySelector(t.getAttribute("data-multi-select-checkbox")),checkboxes:t.querySelectorAll("tbody .govuk-checkboxes__input"),id_prefix:t.getAttribute("data-multi-select-idprefix")})}),t.querySelectorAll('[data-module="moj-password-reveal"]')),e=(h(e,function(t){new l(t)}),t.querySelectorAll('[data-module="moj-rich-text-editor"]')),e=(h(e,function(t){var e={textarea:n(t)},t=t.getAttribute("data-moj-rich-text-editor-toolbar");if(t){var o,i=t.split(",");for(o in e.toolbar={},i)e.toolbar[i[o]]=!0}new u(e)}),t.querySelectorAll('[data-module="moj-search-toggle"]')),e=(h(e,function(t){new d({toggleButton:{container:n(t.querySelector(".moj-search-toggle__toggle")),text:t.getAttribute("data-moj-search-toggle-text")},search:{container:n(t.querySelector(".moj-search"))}})}),t.querySelectorAll('[data-module="moj-sortable-table"]')),e=(h(e,function(t){new c({table:t})}),t.querySelectorAll('[data-module="moj-date-picker"]')),e=(h(e,function(t){new a(t,{}).init()}),t.querySelectorAll('[data-module="moj-button-menu"]')),e=(h(e,function(t){new s(t,{}).init()}),t.querySelectorAll('[data-module="moj-alert"]'));h(e,function(t){new i(t,{}).init()})},version:p,AddAnother:o,Alert:i,ButtonMenu:s,DatePicker:a,FilterToggleButton:t,MultiFileUpload:e,MultiSelect:r,PasswordReveal:l,RichTextEditor:u,SearchToggle:d,SortableTable:c}}return P})())});
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MOJFrontend=t.MOJFrontend||{})}(this,(function(t){"use strict";function e(t){this.container=window.jQuery(t),this.container.data("moj-add-another-initialised")||(this.container.data("moj-add-another-initialised",!0),this.container.on("click",".moj-add-another__remove-button",window.jQuery.proxy(this,"onRemoveButtonClick")),this.container.on("click",".moj-add-another__add-button",window.jQuery.proxy(this,"onAddButtonClick")),this.container.find(".moj-add-another__add-button, moj-add-another__remove-button").prop("type","button"))}function o(t,e){if(window.NodeList.prototype.forEach)return t.forEach(e);for(let o=0;o<t.length;o++)e.call(window,t[o],o,t)}function n(t,e={}){const o=t.getAttribute("tabindex");function n(){e.onBlur&&e.onBlur.call(t),o||t.removeAttribute("tabindex")}o||t.setAttribute("tabindex","-1"),t.addEventListener("focus",(function(){t.addEventListener("blur",n,{once:!0})}),{once:!0}),e.onBeforeFocus&&e.onBeforeFocus.call(t),t.focus()}function i(t,e={}){if(!t)return this;const o=Object.freeze({properties:{dismissible:{type:"boolean"},dismissText:{type:"string"},disableAutoFocus:{type:"boolean"},focusOnDismissSelector:{type:"string"}}});this.config=this.mergeConfigs({dismissible:!1,dismissText:"Dismiss",disableAutoFocus:!1},e,this.parseDataset(o,t.dataset)),this.$module=t}function s(t,e={}){if(!t)return this;const o=Object.freeze({properties:{buttonText:{type:"string"},buttonClasses:{type:"string"},alignMenu:{type:"string"}}});this.config=this.mergeConfigs({buttonText:"Actions",alignMenu:"left",buttonClasses:""},e,this.parseDataset(o,t.dataset)),this.$module=t}function a(t,e={}){if(!t)return this;const o=Object.freeze({properties:{excludedDates:{type:"string"},excludedDays:{type:"string"},leadingZeros:{type:"string"},maxDate:{type:"string"},minDate:{type:"string"},weekStartDay:{type:"string"}}});this.config=this.mergeConfigs({leadingZeros:!1,weekStartDay:"monday"},e,this.parseDataset(o,t.dataset)),this.dayLabels=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],this.monthLabels=["January","February","March","April","May","June","July","August","September","October","November","December"],this.currentDate=new Date,this.currentDate.setHours(0,0,0,0),this.calendarDays=[],this.excludedDates=[],this.excludedDays=[],this.buttonClass="moj-datepicker__button",this.selectedDayButtonClass="moj-datepicker__button--selected",this.currentDayButtonClass="moj-datepicker__button--current",this.todayButtonClass="moj-datepicker__button--today",this.$module=t,this.$input=t.querySelector(".moj-js-datepicker-input")}function r(t,e,o,n,i){this.index=e,this.row=o,this.column=n,this.button=t,this.picker=i,this.date=new Date}function u(t){this.options=t,this.container=window.jQuery(this.options.toggleButton.container),this.filterContainer=window.jQuery(this.options.filter.container),this.createToggleButton(),this.setupResponsiveChecks(),this.filterContainer.attr("tabindex","-1"),this.options.startHidden&&this.hideMenu()}function l(t){void 0!==document.createElement("div").ondrop&&"function"==typeof FormData&&function(){const t=document.createElement("input");return t.type="file",void 0!==t.files}()&&(this.defaultParams={uploadFileEntryHook:window.jQuery.noop,uploadFileExitHook:window.jQuery.noop,uploadFileErrorHook:window.jQuery.noop,fileDeleteHook:window.jQuery.noop,uploadStatusText:"Uploading files, please wait",dropzoneHintText:"Drag and drop files here or",dropzoneButtonText:"Choose files"},this.params=window.jQuery.extend({},this.defaultParams,t),this.container=window.jQuery(this.params.container),this.container.addClass("moj-multi-file-upload--enhanced"),this.feedbackContainer=this.container.find(".moj-multi-file__uploaded-files"),this.setupFileInput(),this.setupDropzone(),this.setupLabel(),this.setupStatusBox(),this.container.on("click",".moj-multi-file-upload__delete",window.jQuery.proxy(this,"onFileDeleteClick")))}function c(t){if(this.container=window.jQuery(t.container),this.container.data("moj-multi-select-initialised"))return;this.container.data("moj-multi-select-initialised",!0);const e=t.id_prefix;let o="checkboxes-all";void 0!==e&&(o=`${e}checkboxes-all`),this.toggle=window.jQuery(this.getToggleHtml(o)),this.toggleButton=this.toggle.find("input"),this.toggleButton.on("click",window.jQuery.proxy(this,"onButtonClick")),this.container.append(this.toggle),this.checkboxes=window.jQuery(t.checkboxes),this.checkboxes.on("click",window.jQuery.proxy(this,"onCheckboxClick")),this.checked=t.checked||!1}function d(t){this.el=t;const e=window.jQuery(this.el);e.data("moj-password-reveal-initialised")||(e.data("moj-password-reveal-initialised",!0),e.attr("spellcheck","false"),e.wrap('<div class="moj-password-reveal"></div>'),this.container=window.jQuery(this.el).parent(),this.createButton())}function h(t){"contentEditable"in document.documentElement&&(this.options=t,this.options.toolbar=this.options.toolbar||{bold:!1,italic:!1,underline:!1,bullets:!0,numbers:!0},this.textarea=this.options.textarea,this.container=window.jQuery(this.textarea).parent(),this.container.data("moj-rich-text-editor-initialised")||(this.container.data("moj-rich-text-editor-initialised",!0),this.createToolbar(),this.hideDefault(),this.configureToolbar(),this.keys={left:37,right:39,up:38,down:40},this.container.on("click",".moj-rich-text-editor__toolbar-button",window.jQuery.proxy(this,"onButtonClick")),this.container.find(".moj-rich-text-editor__content").on("input",window.jQuery.proxy(this,"onEditorInput")),this.container.find("label").on("click",window.jQuery.proxy(this,"onLabelClick")),this.toolbar.on("keydown",window.jQuery.proxy(this,"onToolbarKeydown"))))}function p(t){if(this.options=t,this.container=window.jQuery(this.options.search.container),this.toggleButtonContainer=window.jQuery(this.options.toggleButton.container),this.container.data("moj-search-toggle-initialised"))return;this.container.data("moj-search-toggle-initialised",!0);this.toggleButton=window.jQuery(`<button class="moj-search-toggle__button" type="button" aria-haspopup="true" aria-expanded="false">\n ${this.options.toggleButton.text} <svg viewBox="0 0 20 20" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="moj-search-toggle__button__icon"><path d="M7.433,12.5790048 C6.06762625,12.5808611 4.75763941,12.0392925 3.79217348,11.0738265 C2.82670755,10.1083606 2.28513891,8.79837375 2.28699522,7.433 C2.28513891,6.06762625 2.82670755,4.75763941 3.79217348,3.79217348 C4.75763941,2.82670755 6.06762625,2.28513891 7.433,2.28699522 C8.79837375,2.28513891 10.1083606,2.82670755 11.0738265,3.79217348 C12.0392925,4.75763941 12.5808611,6.06762625 12.5790048,7.433 C12.5808611,8.79837375 12.0392925,10.1083606 11.0738265,11.0738265 C10.1083606,12.0392925 8.79837375,12.5808611 7.433,12.5790048 L7.433,12.5790048 Z M14.293,12.579 L13.391,12.579 L13.071,12.269 C14.2300759,10.9245158 14.8671539,9.20813198 14.866,7.433 C14.866,3.32786745 11.5381325,-1.65045755e-15 7.433,-1.65045755e-15 C3.32786745,-1.65045755e-15 -1.65045755e-15,3.32786745 -1.65045755e-15,7.433 C-1.65045755e-15,11.5381325 3.32786745,14.866 7.433,14.866 C9.208604,14.8671159 10.9253982,14.2296624 12.27,13.07 L12.579,13.39 L12.579,14.294 L18.296,20 L20,18.296 L14.294,12.579 L14.293,12.579 Z"></path></svg>\n </button>`),this.toggleButton.on("click",window.jQuery.proxy(this,"onToggleButtonClick")),this.toggleButtonContainer.append(this.toggleButton),window.jQuery(document).on("click",this.onDocumentClick.bind(this)),window.jQuery(document).on("focusin",this.onDocumentClick.bind(this))}function f(t){this.table=window.jQuery(t.table),this.table.data("moj-search-toggle-initialised")||(this.table.data("moj-search-toggle-initialised",!0),this.setupOptions(t),this.body=this.table.find("tbody"),this.createHeadingButtons(),this.createStatusBox(),this.initialiseSortedColumn(),this.table.on("click","th button",window.jQuery.proxy(this,"onSortButtonClick")))}e.prototype.onAddButtonClick=function(t){const e=this.getNewItem();this.updateAttributes(this.getItems().length,e),this.resetItem(e);const o=this.getItems().first();this.hasRemoveButton(o)||this.createRemoveButton(o),this.getItems().last().after(e),e.find("input, textarea, select").first().focus()},e.prototype.hasRemoveButton=function(t){return t.find(".moj-add-another__remove-button").length},e.prototype.getItems=function(){return this.container.find(".moj-add-another__item")},e.prototype.getNewItem=function(){const t=this.getItems().first().clone();return this.hasRemoveButton(t)||this.createRemoveButton(t),t},e.prototype.updateAttributes=function(t,e){e.find("[data-name]").each((function(o,n){const i=n.id;n.name=window.jQuery(n).attr("data-name").replace(/%index%/,t),n.id=window.jQuery(n).attr("data-id").replace(/%index%/,t);(window.jQuery(n).siblings("label")[0]||window.jQuery(n).parents("label")[0]||e.find(`[for="${i}"]`)[0]).htmlFor=n.id}))},e.prototype.createRemoveButton=function(t){t.append('<button type="button" class="govuk-button govuk-button--secondary moj-add-another__remove-button">Remove</button>')},e.prototype.resetItem=function(t){t.find("[data-name], [data-id]").each((function(t,e){"checkbox"===e.type||"radio"===e.type?e.checked=!1:e.value=""}))},e.prototype.onRemoveButtonClick=function(t){window.jQuery(t.currentTarget).parents(".moj-add-another__item").remove();const e=this.getItems();1===e.length&&e.find(".moj-add-another__remove-button").remove(),e.each(window.jQuery.proxy((function(t,e){this.updateAttributes(t,window.jQuery(e))}),this)),this.focusHeading()},e.prototype.focusHeading=function(){this.container.find(".moj-add-another__heading").get(0).focus()},i.prototype.init=function(){"alert"!==this.$module.getAttribute("role")||this.config.disableAutoFocus||n(this.$module),this.$dismissButton=this.$module.querySelector(".moj-alert__dismiss"),this.config.dismissible&&this.$dismissButton&&(this.$dismissButton.innerHTML=this.config.dismissText,this.$dismissButton.removeAttribute("hidden"),this.$module.addEventListener("click",(t=>{this.$dismissButton.contains(t.target)&&this.dimiss()})))},i.prototype.dimiss=function(){let t;if(this.config.focusOnDismissSelector&&(t=document.querySelector(this.config.focusOnDismissSelector)),!t){const e=this.$module.nextElementSibling;e&&e.matches(".moj-alert")&&(t=e)}t||(t=function(t,e){if(!t)return;let o=t.previousElementSibling;for(;o;){if(o.matches(e))return o;o=o.previousElementSibling}}(this.$module,".moj-alert, h1, h2, h3, h4, h5, h6")),t||(t=function(t,e){if(!t)return;let o=t;for(;o;){if(o.matches(e))return o;let t=o.previousElementSibling;for(;t;){if(t.matches(e))return t;t=t.previousElementSibling}o=o.parentElement}}(this.$module,"h1, h2, h3, h4, h5, h6, main, body")),t&&n(t),this.$module.remove()},i.prototype.normaliseString=function(t,e){const o=t?t.trim():"";let n,i;switch(e&&e.type&&(i=e.type),i||(["true","false"].includes(o)&&(i="boolean"),o.length>0&&isFinite(Number(o))&&(i="number")),i){case"boolean":n="true"===o;break;case"number":n=Number(o);break;default:n=t}return n},i.prototype.parseDataset=function(t,e){const o={};for(const[n,i]of Object.entries(t.properties))n in e&&e[n]&&(o[n]=this.normaliseString(e[n],i));return o},i.prototype.mergeConfigs=function(...t){const e={};for(const o of t)for(const t of Object.keys(o)){const n=e[t],i=o[t];e[t]="object"==typeof n&&"object"==typeof i?this.mergeConfigs(n,i):i}return e},s.prototype.init=function(){if(1===this.$module.children.length){const t=this.$module.children[0];t.classList.forEach((e=>{e.startsWith("govuk-button-")&&t.classList.remove(e),t.classList.remove("moj-button-menu__item")})),this.config.buttonClasses&&t.classList.add(...this.config.buttonClasses.split(" "))}this.$module.children.length>1&&this.initMenu()},s.prototype.initMenu=function(){this.$menu=this.createMenu(),this.$module.insertAdjacentHTML("afterbegin",this.toggleTemplate()),this.setupMenuItems(),this.$menuToggle=this.$module.querySelector(":scope > button"),this.items=this.$menu.querySelectorAll("a, button"),this.$menuToggle.addEventListener("click",(t=>{this.toggleMenu(t)})),this.$module.addEventListener("keydown",(t=>{this.handleKeyDown(t)})),document.addEventListener("click",(t=>{this.$module.contains(t.target)||this.closeMenu(!1)}))},s.prototype.createMenu=function(){const t=document.createElement("ul");for(t.setAttribute("role","list"),t.hidden=!0,t.classList.add("moj-button-menu__wrapper"),"right"===this.config.alignMenu&&t.classList.add("moj-button-menu__wrapper--right"),this.$module.appendChild(t);this.$module.firstChild!==t;)t.appendChild(this.$module.firstChild);return t},s.prototype.setupMenuItems=function(){Array.from(this.$menu.children).forEach((t=>{const e=document.createElement("li");this.$menu.insertBefore(e,t),e.appendChild(t),t.setAttribute("tabindex",-1),"BUTTON"===t.tagName&&t.setAttribute("type","button"),t.classList.forEach((e=>{e.startsWith("govuk-button")&&t.classList.remove(e)})),t.addEventListener("click",(t=>{setTimeout((()=>{this.closeMenu(!1)}),50)}))}))},s.prototype.toggleTemplate=function(){return`\n <button type="button" class="govuk-button moj-button-menu__toggle-button ${this.config.buttonClasses||""}" aria-haspopup="true" aria-expanded="false">\n <span>\n ${this.config.buttonText}\n <svg width="11" height="5" viewBox="0 0 11 5" xmlns="http://www.w3.org/2000/svg">\n <path d="M5.5 0L11 5L0 5L5.5 0Z" fill="currentColor"/>\n </svg>\n </span>\n </button>`},s.prototype.isOpen=function(){return"true"===this.$menuToggle.getAttribute("aria-expanded")},s.prototype.toggleMenu=function(t){t.preventDefault();const e=0===t.detail?0:-1;this.isOpen()?this.closeMenu():this.openMenu(e)},s.prototype.openMenu=function(t=0){this.$menu.hidden=!1,this.$menuToggle.setAttribute("aria-expanded","true"),-1!==t&&this.focusItem(t)},s.prototype.closeMenu=function(t=!0){this.$menu.hidden=!0,this.$menuToggle.setAttribute("aria-expanded","false"),t&&this.$menuToggle.focus()},s.prototype.focusItem=function(t){t>=this.items.length&&(t=0),t<0&&(t=this.items.length-1);const e=this.items.item(t);e&&e.focus()},s.prototype.currentFocusIndex=function(){const t=document.activeElement;return Array.from(this.items).indexOf(t)},s.prototype.handleKeyDown=function(t){if(t.target===this.$menuToggle)switch(t.key){case"ArrowDown":t.preventDefault(),this.openMenu();break;case"ArrowUp":t.preventDefault(),this.openMenu(this.items.length-1)}if(this.$menu.contains(t.target)&&this.isOpen())switch(t.key){case"ArrowDown":t.preventDefault(),-1!==this.currentFocusIndex()&&this.focusItem(this.currentFocusIndex()+1);break;case"ArrowUp":t.preventDefault(),-1!==this.currentFocusIndex()&&this.focusItem(this.currentFocusIndex()-1);break;case"Home":t.preventDefault(),this.focusItem(0);break;case"End":t.preventDefault(),this.focusItem(this.items.length-1)}"Escape"===t.key&&this.isOpen()&&this.closeMenu(),"Tab"===t.key&&this.isOpen()&&this.closeMenu(!1)},s.prototype.parseDataset=function(t,e){const o={};for(const[n,,]of Object.entries(t.properties))n in e&&e[n]&&(o[n]=e[n]);return o},s.prototype.mergeConfigs=function(...t){const e={};for(const o of t)for(const t of Object.keys(o)){const n=e[t],i=o[t];e[t]="object"==typeof n&&"object"==typeof i?this.mergeConfigs(n,i):i}return e},a.prototype.init=function(){this.$input&&(this.$module.dataset.initialized||(this.setOptions(),this.initControls(),this.$module.setAttribute("data-initialized","true")))},a.prototype.initControls=function(){this.id=`datepicker-${this.$input.id}`,this.$dialog=this.createDialog(),this.createCalendarHeaders();const t=document.createElement("div"),e=document.createElement("div");t.classList.add("moj-datepicker__wrapper"),e.classList.add("govuk-input__wrapper"),this.$input.parentNode.insertBefore(t,this.$input),t.appendChild(e),e.appendChild(this.$input),e.insertAdjacentHTML("beforeend",this.toggleTemplate()),t.insertAdjacentElement("beforeend",this.$dialog),this.$calendarButton=this.$module.querySelector(".moj-js-datepicker-toggle"),this.$dialogTitle=this.$dialog.querySelector(".moj-js-datepicker-month-year"),this.createCalendar(),this.$prevMonthButton=this.$dialog.querySelector(".moj-js-datepicker-prev-month"),this.$prevYearButton=this.$dialog.querySelector(".moj-js-datepicker-prev-year"),this.$nextMonthButton=this.$dialog.querySelector(".moj-js-datepicker-next-month"),this.$nextYearButton=this.$dialog.querySelector(".moj-js-datepicker-next-year"),this.$cancelButton=this.$dialog.querySelector(".moj-js-datepicker-cancel"),this.$okButton=this.$dialog.querySelector(".moj-js-datepicker-ok"),this.$prevMonthButton.addEventListener("click",(t=>this.focusPreviousMonth(t,!1))),this.$prevYearButton.addEventListener("click",(t=>this.focusPreviousYear(t,!1))),this.$nextMonthButton.addEventListener("click",(t=>this.focusNextMonth(t,!1))),this.$nextYearButton.addEventListener("click",(t=>this.focusNextYear(t,!1))),this.$cancelButton.addEventListener("click",(t=>{t.preventDefault(),this.closeDialog(t)})),this.$okButton.addEventListener("click",(()=>{this.selectDate(this.currentDate)}));const o=this.$dialog.querySelectorAll('button:not([disabled="true"])');this.$firstButtonInDialog=o[0],this.$lastButtonInDialog=o[o.length-1],this.$firstButtonInDialog.addEventListener("keydown",(t=>this.firstButtonKeydown(t))),this.$lastButtonInDialog.addEventListener("keydown",(t=>this.lastButtonKeydown(t))),this.$calendarButton.addEventListener("click",(t=>this.toggleDialog(t))),this.$dialog.addEventListener("keydown",(t=>{"Escape"===t.key&&(this.closeDialog(),t.preventDefault(),t.stopPropagation())})),document.body.addEventListener("mouseup",(t=>this.backgroundClick(t))),this.updateCalendar()},a.prototype.createDialog=function(){const t=`datepicker-title-${this.$input.id}`,e=document.createElement("div");return e.id=this.id,e.setAttribute("class","moj-datepicker__dialog"),e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e.setAttribute("aria-labelledby",t),e.innerHTML=this.dialogTemplate(t),e.hidden=!0,e},a.prototype.createCalendar=function(){const t=this.$dialog.querySelector("tbody");let e=0;for(let o=0;o<6;o++){const n=t.insertRow(o);for(let t=0;t<7;t++){const i=document.createElement("td"),s=document.createElement("button");i.appendChild(s),n.appendChild(i);const a=new r(s,e,o,t,this);a.init(),this.calendarDays.push(a),e++}}},a.prototype.toggleTemplate=function(){return`<button class="moj-datepicker__toggle moj-js-datepicker-toggle" type="button" aria-haspopup="dialog" aria-controls="${this.id}" aria-expanded="false">\n <span class="govuk-visually-hidden">Choose date</span>\n <svg width="32" height="24" focusable="false" class="moj-datepicker-icon" aria-hidden="true" role="img" viewBox="0 0 22 22">\n <path\n fill="currentColor"\n fill-rule="evenodd"\n clip-rule="evenodd"\n d="M16.1333 2.93333H5.86668V4.4C5.86668 5.21002 5.21003 5.86667 4.40002 5.86667C3.59 5.86667 2.93335 5.21002 2.93335 4.4V2.93333H2C0.895431 2.93333 0 3.82877 0 4.93334V19.2667C0 20.3712 0.89543 21.2667 2 21.2667H20C21.1046 21.2667 22 20.3712 22 19.2667V4.93333C22 3.82876 21.1046 2.93333 20 2.93333H19.0667V4.4C19.0667 5.21002 18.41 5.86667 17.6 5.86667C16.79 5.86667 16.1333 5.21002 16.1333 4.4V2.93333ZM20.5333 8.06667H1.46665V18.8C1.46665 19.3523 1.91436 19.8 2.46665 19.8H19.5333C20.0856 19.8 20.5333 19.3523 20.5333 18.8V8.06667Z"\n ></path>\n <rect x="3.66669" width="1.46667" height="5.13333" rx="0.733333" fill="currentColor"></rect>\n <rect x="16.8667" width="1.46667" height="5.13333" rx="0.733333" fill="currentColor"></rect>\n </svg>\n </button>`},a.prototype.dialogTemplate=function(t){return`<div class="moj-datepicker__dialog-header">\n <div class="moj-datepicker__dialog-navbuttons">\n <button class="moj-datepicker__button moj-js-datepicker-prev-year">\n <span class="govuk-visually-hidden">Previous year</span>\n <svg width="44" height="40" viewBox="0 0 44 40" fill="none" fill="none" focusable="false" aria-hidden="true" role="img">\n <path fill-rule="evenodd" clip-rule="evenodd" d="M23.1643 20L28.9572 14.2071L27.5429 12.7929L20.3358 20L27.5429 27.2071L28.9572 25.7929L23.1643 20Z" fill="currentColor"/>\n <path fill-rule="evenodd" clip-rule="evenodd" d="M17.1643 20L22.9572 14.2071L21.5429 12.7929L14.3358 20L21.5429 27.2071L22.9572 25.7929L17.1643 20Z" fill="currentColor"/>\n </svg>\n </button>\n\n <button class="moj-datepicker__button moj-js-datepicker-prev-month">\n <span class="govuk-visually-hidden">Previous month</span>\n <svg width="44" height="40" viewBox="0 0 44 40" fill="none" focusable="false" aria-hidden="true" role="img">\n <path fill-rule="evenodd" clip-rule="evenodd" d="M20.5729 20L25.7865 14.2071L24.5137 12.7929L18.0273 20L24.5137 27.2071L25.7865 25.7929L20.5729 20Z" fill="currentColor"/>\n </svg>\n </button>\n </div>\n\n <h2 id="${t}" class="moj-datepicker__dialog-title moj-js-datepicker-month-year" aria-live="polite">June 2020</h2>\n\n <div class="moj-datepicker__dialog-navbuttons">\n <button class="moj-datepicker__button moj-js-datepicker-next-month">\n <span class="govuk-visually-hidden">Next month</span>\n <svg width="44" height="40" viewBox="0 0 44 40" fill="none" focusable="false" aria-hidden="true" role="img">\n <path fill-rule="evenodd" clip-rule="evenodd" d="M23.4271 20L18.2135 14.2071L19.4863 12.7929L25.9727 20L19.4863 27.2071L18.2135 25.7929L23.4271 20Z" fill="currentColor"/>\n </svg>\n </button>\n\n <button class="moj-datepicker__button moj-js-datepicker-next-year">\n <span class="govuk-visually-hidden">Next year</span>\n <svg width="44" height="40" viewBox="0 0 44 40" fill="none" fill="none" focusable="false" aria-hidden="true" role="img">\n <path fill-rule="evenodd" clip-rule="evenodd" d="M20.8357 20L15.0428 14.2071L16.4571 12.7929L23.6642 20L16.4571 27.2071L15.0428 25.7929L20.8357 20Z" fill="currentColor"/>\n <path fill-rule="evenodd" clip-rule="evenodd" d="M26.8357 20L21.0428 14.2071L22.4571 12.7929L29.6642 20L22.4571 27.2071L21.0428 25.7929L26.8357 20Z" fill="currentColor"/>\n </svg>\n </button>\n </div>\n </div>\n\n <table class="moj-datepicker__calendar moj-js-datepicker-grid" role="grid" aria-labelledby="${t}">\n <thead>\n <tr></tr>\n </thead>\n\n <tbody></tbody>\n </table>\n\n <div class="govuk-button-group">\n <button type="button" class="govuk-button moj-js-datepicker-ok">Select</button>\n <button type="button" class="govuk-button govuk-button--secondary moj-js-datepicker-cancel">Close</button>\n </div>`},a.prototype.createCalendarHeaders=function(){this.dayLabels.forEach((t=>{const e=`<th scope="col"><span aria-hidden="true">${t.substring(0,3)}</span><span class="govuk-visually-hidden">${t}</span></th>`;this.$dialog.querySelector("thead > tr").insertAdjacentHTML("beforeend",e)}))},a.prototype.leadingZeros=function(t,e=2){let o=t.toString();for(;o.length<e;)o=`0${o}`;return o},a.prototype.setOptions=function(){this.setMinAndMaxDatesOnCalendar(),this.setExcludedDates(),this.setExcludedDays(),this.setLeadingZeros(),this.setWeekStartDay()},a.prototype.setMinAndMaxDatesOnCalendar=function(){this.config.minDate&&(this.minDate=this.formattedDateFromString(this.config.minDate,null),this.minDate&&this.currentDate<this.minDate&&(this.currentDate=this.minDate)),this.config.maxDate&&(this.maxDate=this.formattedDateFromString(this.config.maxDate,null),this.maxDate&&this.currentDate>this.maxDate&&(this.currentDate=this.maxDate))},a.prototype.setExcludedDates=function(){this.config.excludedDates&&(this.excludedDates=this.config.excludedDates.replace(/\s+/," ").split(" ").map((t=>t.includes("-")?this.parseDateRangeString(t):this.formattedDateFromString(t))).flat().filter((t=>t)))},a.prototype.parseDateRangeString=function(t){const e=[],[o,n]=t.split("-").map((t=>this.formattedDateFromString(t,null)));if(o&&n){const t=new Date(o.getTime());for(;t<=n;)e.push(new Date(t)),t.setDate(t.getDate()+1)}return e},a.prototype.setExcludedDays=function(){if(this.config.excludedDays){const t=this.dayLabels.map((t=>t.toLowerCase()));"monday"===this.config.weekStartDay&&t.unshift(t.pop()),this.excludedDays=this.config.excludedDays.replace(/\s+/," ").toLowerCase().split(" ").map((e=>t.indexOf(e))).filter((t=>-1!==t))}},a.prototype.setLeadingZeros=function(){if("boolean"!=typeof this.config.leadingZeros){if("true"===this.config.leadingZeros.toLowerCase())return void(this.config.leadingZeros=!0);"false"===this.config.leadingZeros.toLowerCase()&&(this.config.leadingZeros=!1)}},a.prototype.setWeekStartDay=function(){const t=this.config.weekStartDay;t&&"sunday"===t.toLowerCase()?(this.config.weekStartDay="sunday",this.dayLabels.unshift(this.dayLabels.pop())):this.config.weekStartDay="monday"},a.prototype.isExcludedDate=function(t){if(this.minDate&&this.minDate>t)return!0;if(this.maxDate&&this.maxDate<t)return!0;for(const e of this.excludedDates)if(t.toDateString()===e.toDateString())return!0;return!!this.excludedDays.includes(t.getDay())},a.prototype.formattedDateFromString=function(t,e=new Date){let o=null;const n=/(\d{1,2})([-/,. ])(\d{1,2})\2(\d{4})/;if(!n.test(t))return e;const i=t.match(n),s=i[1],a=i[3],r=i[4];return o=new Date(`${r}-${a}-${s}`),o instanceof Date&&!isNaN(o)?o:e},a.prototype.formattedDateFromDate=function(t){return this.config.leadingZeros?`${this.leadingZeros(t.getDate())}/${this.leadingZeros(t.getMonth()+1)}/${t.getFullYear()}`:`${t.getDate()}/${t.getMonth()+1}/${t.getFullYear()}`},a.prototype.formattedDateHuman=function(t){return`${this.dayLabels[(t.getDay()+6)%7]} ${t.getDate()} ${this.monthLabels[t.getMonth()]} ${t.getFullYear()}`},a.prototype.backgroundClick=function(t){!this.isOpen()||this.$dialog.contains(t.target)||this.$input.contains(t.target)||this.$calendarButton.contains(t.target)||(t.preventDefault(),this.closeDialog())},a.prototype.firstButtonKeydown=function(t){"Tab"===t.key&&t.shiftKey&&(this.$lastButtonInDialog.focus(),t.preventDefault())},a.prototype.lastButtonKeydown=function(t){"Tab"!==t.key||t.shiftKey||(this.$firstButtonInDialog.focus(),t.preventDefault())},a.prototype.updateCalendar=function(){this.$dialogTitle.innerHTML=`${this.monthLabels[this.currentDate.getMonth()]} ${this.currentDate.getFullYear()}`;const t=this.currentDate,e=new Date(t.getFullYear(),t.getMonth(),1);let o;o="monday"===this.config.weekStartDay?0===e.getDay()?6:e.getDay()-1:e.getDay(),e.setDate(e.getDate()-o);const n=new Date(e);for(let i=0;i<this.calendarDays.length;i++){const e=n.getMonth()!==t.getMonth(),o=this.isExcludedDate(n);this.calendarDays[i].update(n,e,o),n.setDate(n.getDate()+1)}},a.prototype.setCurrentDate=function(t=!0){const{currentDate:e}=this;if(this.calendarDays.forEach((o=>{o.button.classList.add("moj-datepicker__button"),o.button.classList.add("moj-datepicker__calendar-day"),o.button.setAttribute("tabindex",-1),o.button.classList.remove(this.selectedDayButtonClass);const n=o.date;n.setHours(0,0,0,0);const i=new Date;i.setHours(0,0,0,0),n.getTime()===e.getTime()&&t&&(o.button.setAttribute("tabindex",0),o.button.focus(),o.button.classList.add(this.selectedDayButtonClass)),this.inputDate&&n.getTime()===this.inputDate.getTime()?(o.button.classList.add(this.currentDayButtonClass),o.button.setAttribute("aria-current","date")):(o.button.classList.remove(this.currentDayButtonClass),o.button.removeAttribute("aria-current")),n.getTime()===i.getTime()?o.button.classList.add(this.todayButtonClass):o.button.classList.remove(this.todayButtonClass)})),!t){const t=this.calendarDays.filter((t=>"block"===window.getComputedStyle(t.button).display&&!t.button.disabled));t[0].button.setAttribute("tabindex",0),this.currentDate=t[0].date}},a.prototype.selectDate=function(t){if(this.isExcludedDate(t))return;this.$calendarButton.querySelector("span").innerText=`Choose date. Selected date is ${this.formattedDateHuman(t)}`,this.$input.value=this.formattedDateFromDate(t);const e=new Event("change",{bubbles:!0,cancelable:!0});this.$input.dispatchEvent(e),this.closeDialog()},a.prototype.isOpen=function(){return this.$dialog.classList.contains("moj-datepicker__dialog--open")},a.prototype.toggleDialog=function(t){t.preventDefault(),this.isOpen()?this.closeDialog():(this.setMinAndMaxDatesOnCalendar(),this.openDialog())},a.prototype.openDialog=function(){this.$dialog.hidden=!1,this.$dialog.classList.add("moj-datepicker__dialog--open"),this.$calendarButton.setAttribute("aria-expanded","true"),this.$input.offsetWidth>this.$dialog.offsetWidth&&(this.$dialog.style.right="0px"),this.$dialog.style.top=`${this.$input.offsetHeight+3}px`,this.inputDate=this.formattedDateFromString(this.$input.value),this.currentDate=this.inputDate,this.currentDate.setHours(0,0,0,0),this.updateCalendar(),this.setCurrentDate()},a.prototype.closeDialog=function(){this.$dialog.hidden=!0,this.$dialog.classList.remove("moj-datepicker__dialog--open"),this.$calendarButton.setAttribute("aria-expanded","false"),this.$calendarButton.focus()},a.prototype.goToDate=function(t,e){const o=this.currentDate;this.currentDate=t,o.getMonth()===this.currentDate.getMonth()&&o.getFullYear()===this.currentDate.getFullYear()||this.updateCalendar(),this.setCurrentDate(e)},a.prototype.focusNextDay=function(){const t=new Date(this.currentDate);t.setDate(t.getDate()+1),this.goToDate(t)},a.prototype.focusPreviousDay=function(){const t=new Date(this.currentDate);t.setDate(t.getDate()-1),this.goToDate(t)},a.prototype.focusNextWeek=function(){const t=new Date(this.currentDate);t.setDate(t.getDate()+7),this.goToDate(t)},a.prototype.focusPreviousWeek=function(){const t=new Date(this.currentDate);t.setDate(t.getDate()-7),this.goToDate(t)},a.prototype.focusFirstDayOfWeek=function(){const t=new Date(this.currentDate),e="sunday"===this.config.weekStartDay?0:1,o=t.getDay(),n=o>=e?o-e:6-o;t.setDate(t.getDate()-n),t.setHours(0,0,0,0),this.goToDate(t)},a.prototype.focusLastDayOfWeek=function(){const t=new Date(this.currentDate),e="sunday"===this.config.weekStartDay?6:0,o=t.getDay(),n=o<=e?e-o:7-o;t.setDate(t.getDate()+n),t.setHours(0,0,0,0),this.goToDate(t)},a.prototype.focusNextMonth=function(t,e=!0){t.preventDefault();const o=new Date(this.currentDate);o.setMonth(o.getMonth()+1,1),this.goToDate(o,e)},a.prototype.focusPreviousMonth=function(t,e=!0){t.preventDefault();const o=new Date(this.currentDate);o.setMonth(o.getMonth()-1,1),this.goToDate(o,e)},a.prototype.focusNextYear=function(t,e=!0){t.preventDefault();const o=new Date(this.currentDate);o.setFullYear(o.getFullYear()+1,o.getMonth(),1),this.goToDate(o,e)},a.prototype.focusPreviousYear=function(t,e=!0){t.preventDefault();const o=new Date(this.currentDate);o.setFullYear(o.getFullYear()-1,o.getMonth(),1),this.goToDate(o,e)},a.prototype.parseDataset=function(t,e){const o={};for(const[n,,]of Object.entries(t.properties))n in e&&(o[n]=e[n]);return o},a.prototype.mergeConfigs=function(...t){const e={};for(const o of t)for(const t of Object.keys(o)){const n=e[t],i=o[t];e[t]="object"==typeof n&&"object"==typeof i?this.mergeConfigs(n,i):i}return e},r.prototype.init=function(){this.button.addEventListener("keydown",this.keyPress.bind(this)),this.button.addEventListener("click",this.click.bind(this))},r.prototype.update=function(t,e,o){const n=t.getDate();let i=this.picker.formattedDateHuman(t);o?(this.button.setAttribute("aria-disabled",!0),i=`Excluded date, ${i}`):this.button.removeAttribute("aria-disabled"),this.button.style.display=e?"none":"block",this.button.setAttribute("data-testid",this.picker.formattedDateFromDate(t)),this.button.innerHTML=`<span class="govuk-visually-hidden">${i}</span><span aria-hidden="true">${n}</span>`,this.date=new Date(t)},r.prototype.click=function(t){this.picker.goToDate(this.date),this.picker.selectDate(this.date),t.stopPropagation(),t.preventDefault()},r.prototype.keyPress=function(t){let e=!0;switch(t.key){case"ArrowLeft":this.picker.focusPreviousDay();break;case"ArrowRight":this.picker.focusNextDay();break;case"ArrowUp":this.picker.focusPreviousWeek();break;case"ArrowDown":this.picker.focusNextWeek();break;case"Home":this.picker.focusFirstDayOfWeek();break;case"End":this.picker.focusLastDayOfWeek();break;case"PageUp":t.shiftKey?this.picker.focusPreviousYear(t):this.picker.focusPreviousMonth(t);break;case"PageDown":t.shiftKey?this.picker.focusNextYear(t):this.picker.focusNextMonth(t);break;default:e=!1}e&&(t.preventDefault(),t.stopPropagation())},u.prototype.setupResponsiveChecks=function(){this.mq=window.matchMedia(this.options.bigModeMediaQuery),this.mq.addListener(window.jQuery.proxy(this,"checkMode")),this.checkMode(this.mq)},u.prototype.createToggleButton=function(){this.menuButton=window.jQuery(`<button class="govuk-button ${this.options.toggleButton.classes}" type="button" aria-haspopup="true" aria-expanded="false">${this.options.toggleButton.showText}</button>`),this.menuButton.on("click",window.jQuery.proxy(this,"onMenuButtonClick")),this.container.append(this.menuButton)},u.prototype.checkMode=function(t){t.matches?this.enableBigMode():this.enableSmallMode()},u.prototype.enableBigMode=function(){this.showMenu(),this.removeCloseButton()},u.prototype.enableSmallMode=function(){this.hideMenu(),this.addCloseButton()},u.prototype.addCloseButton=function(){this.options.closeButton&&(this.closeButton=window.jQuery(`<button class="moj-filter__close" type="button">${this.options.closeButton.text}</button>`),this.closeButton.on("click",window.jQuery.proxy(this,"onCloseClick")),window.jQuery(this.options.closeButton.container).append(this.closeButton))},u.prototype.onCloseClick=function(){this.hideMenu(),this.menuButton.focus()},u.prototype.removeCloseButton=function(){this.closeButton&&(this.closeButton.remove(),this.closeButton=null)},u.prototype.hideMenu=function(){this.menuButton.attr("aria-expanded","false"),this.filterContainer.addClass("moj-js-hidden"),this.menuButton.text(this.options.toggleButton.showText)},u.prototype.showMenu=function(){this.menuButton.attr("aria-expanded","true"),this.filterContainer.removeClass("moj-js-hidden"),this.menuButton.text(this.options.toggleButton.hideText)},u.prototype.onMenuButtonClick=function(){this.toggle()},u.prototype.toggle=function(){"false"===this.menuButton.attr("aria-expanded")?(this.showMenu(),this.filterContainer.get(0).focus()):this.hideMenu()},l.prototype.setupDropzone=function(){this.fileInput.wrap('<div class="moj-multi-file-upload__dropzone" />'),this.dropzone=this.container.find(".moj-multi-file-upload__dropzone"),this.dropzone.on("dragover",window.jQuery.proxy(this,"onDragOver")),this.dropzone.on("dragleave",window.jQuery.proxy(this,"onDragLeave")),this.dropzone.on("drop",window.jQuery.proxy(this,"onDrop"))},l.prototype.setupLabel=function(){this.label=window.jQuery(`<label for="${this.fileInput[0].id}" class="govuk-button govuk-button--secondary">${this.params.dropzoneButtonText}</label>`),this.dropzone.append(`<p class="govuk-body">${this.params.dropzoneHintText}</p>`),this.dropzone.append(this.label)},l.prototype.setupFileInput=function(){this.fileInput=this.container.find(".moj-multi-file-upload__input"),this.fileInput.on("change",window.jQuery.proxy(this,"onFileChange")),this.fileInput.on("focus",window.jQuery.proxy(this,"onFileFocus")),this.fileInput.on("blur",window.jQuery.proxy(this,"onFileBlur"))},l.prototype.setupStatusBox=function(){this.status=window.jQuery('<div aria-live="polite" role="status" class="govuk-visually-hidden" />'),this.dropzone.append(this.status)},l.prototype.onDragOver=function(t){t.preventDefault(),this.dropzone.addClass("moj-multi-file-upload--dragover")},l.prototype.onDragLeave=function(){this.dropzone.removeClass("moj-multi-file-upload--dragover")},l.prototype.onDrop=function(t){t.preventDefault(),this.dropzone.removeClass("moj-multi-file-upload--dragover"),this.feedbackContainer.removeClass("moj-hidden"),this.status.html(this.params.uploadStatusText),this.uploadFiles(t.originalEvent.dataTransfer.files)},l.prototype.uploadFiles=function(t){for(let e=0;e<t.length;e++)this.uploadFile(t[e])},l.prototype.onFileChange=function(t){this.feedbackContainer.removeClass("moj-hidden"),this.status.html(this.params.uploadStatusText),this.uploadFiles(t.currentTarget.files),this.fileInput.replaceWith(window.jQuery(t.currentTarget).val("").clone(!0)),this.setupFileInput(),this.fileInput.get(0).focus()},l.prototype.onFileFocus=function(t){this.label.addClass("moj-multi-file-upload--focused")},l.prototype.onFileBlur=function(t){this.label.removeClass("moj-multi-file-upload--focused")},l.prototype.getSuccessHtml=function(t){return`<span class="moj-multi-file-upload__success"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M25,6.2L8.7,23.2L0,14.1l4-4.2l4.7,4.9L21,2L25,6.2z"/></svg>${t.messageHtml}</span>`},l.prototype.getErrorHtml=function(t){return`<span class="moj-multi-file-upload__error"> <svg class="moj-banner__icon" fill="currentColor" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 25 25" height="25" width="25"><path d="M13.6,15.4h-2.3v-4.5h2.3V15.4z M13.6,19.8h-2.3v-2.2h2.3V19.8z M0,23.2h25L12.5,2L0,23.2z"/></svg>${t.message}</span>`},l.prototype.getFileRowHtml=function(t){return`\n <div class="govuk-summary-list__row moj-multi-file-upload__row">;\n <div class="govuk-summary-list__value moj-multi-file-upload__message">;\n <span class="moj-multi-file-upload__filename">${t.name}</span>;\n <span class="moj-multi-file-upload__progress">0%</span>;\n </div>';\n <div class="govuk-summary-list__actions moj-multi-file-upload__actions"></div>;\n </div>`},l.prototype.getDeleteButtonHtml=function(t){return`<button class="moj-multi-file-upload__delete govuk-button govuk-button--secondary govuk-!-margin-bottom-0" type="button" name="delete" value="${t.filename}">\n Delete <span class="govuk-visually-hidden">${t.originalname}</span>\n </button>`},l.prototype.uploadFile=function(t){this.params.uploadFileEntryHook(this,t);const e=window.jQuery(this.getFileRowHtml(t)),o=new FormData;o.append("documents",t),this.feedbackContainer.find(".moj-multi-file-upload__list").append(e),window.jQuery.ajax({url:this.params.uploadUrl,type:"post",data:o,processData:!1,contentType:!1,success:window.jQuery.proxy((function(o){o.error?(e.find(".moj-multi-file-upload__message").html(this.getErrorHtml(o.error)),this.status.html(o.error.message)):(e.find(".moj-multi-file-upload__message").html(this.getSuccessHtml(o.success)),this.status.html(o.success.messageText)),e.find(".moj-multi-file-upload__actions").append(this.getDeleteButtonHtml(o.file)),this.params.uploadFileExitHook(this,t,o)}),this),error:window.jQuery.proxy((function(e,o,n){this.params.uploadFileErrorHook(this,t,e,o,n)}),this),xhr:function(){const t=new XMLHttpRequest;return t.upload.addEventListener("progress",(function(t){if(t.lengthComputable){let o=t.loaded/t.total;o=parseInt(100*o,10),e.find(".moj-multi-file-upload__progress").text(` ${o}%`)}}),!1),t}})},l.prototype.onFileDeleteClick=function(t){t.preventDefault();const e=window.jQuery(t.currentTarget),o={};o[e[0].name]=e[0].value,window.jQuery.ajax({url:this.params.deleteUrl,type:"post",dataType:"json",data:o,success:window.jQuery.proxy((function(t){t.error||(e.parents(".moj-multi-file-upload__row").remove(),0===this.feedbackContainer.find(".moj-multi-file-upload__row").length&&this.feedbackContainer.addClass("moj-hidden")),this.params.fileDeleteHook(this,t)}),this)})},c.prototype.getToggleHtml=function(t){let e="";return e+='<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">',e+=` <input type="checkbox" class="govuk-checkboxes__input" id="${t}">`,e+=` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${t}">`,e+=' <span class="govuk-visually-hidden">Select all</span>',e+=" </label>",e+="</div>",e},c.prototype.onButtonClick=function(t){this.checked?(this.uncheckAll(),this.toggleButton[0].checked=!1):(this.checkAll(),this.toggleButton[0].checked=!0)},c.prototype.checkAll=function(){this.checkboxes.each(window.jQuery.proxy((function(t,e){e.checked=!0}),this)),this.checked=!0},c.prototype.uncheckAll=function(){this.checkboxes.each(window.jQuery.proxy((function(t,e){e.checked=!1}),this)),this.checked=!1},c.prototype.onCheckboxClick=function(t){t.target.checked?this.checkboxes.filter(":checked").length===this.checkboxes.length&&(this.toggleButton[0].checked=!0,this.checked=!0):(this.toggleButton[0].checked=!1,this.checked=!1)},d.prototype.createButton=function(){this.button=window.jQuery('<button type="button" class="govuk-button govuk-button--secondary moj-password-reveal__button">Show <span class="govuk-visually-hidden">password</span></button>'),this.container.append(this.button),this.button.on("click",window.jQuery.proxy(this,"onButtonClick"))},d.prototype.onButtonClick=function(){"password"===this.el.type?(this.el.type="text",this.button.html('Hide <span class="govuk-visually-hidden">password</span>')):(this.el.type="password",this.button.html('Show <span class="govuk-visually-hidden">password</span>'))},h.prototype.onToolbarKeydown=function(t){let e;switch(t.keyCode){case this.keys.right:case this.keys.down:{e=this.toolbar.find("button[tabindex=0]");const t=e.next("button");t[0]&&(t.focus(),e.attr("tabindex","-1"),t.attr("tabindex","0"));break}case this.keys.left:case this.keys.up:{e=this.toolbar.find("button[tabindex=0]");const t=e.prev("button");t[0]&&(t.focus(),e.attr("tabindex","-1"),t.attr("tabindex","0"));break}}},h.prototype.getToolbarHtml=function(){let t="";return t+='<div class="moj-rich-text-editor__toolbar" role="toolbar">',this.options.toolbar.bold&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--bold" type="button" data-command="bold"><span class="govuk-visually-hidden">Bold</span></button>'),this.options.toolbar.italic&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--italic" type="button" data-command="italic"><span class="govuk-visually-hidden">Italic</span></button>'),this.options.toolbar.underline&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--underline" type="button" data-command="underline"><span class="govuk-visually-hidden">Underline</span></button>'),this.options.toolbar.bullets&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--unordered-list" type="button" data-command="insertUnorderedList"><span class="govuk-visually-hidden">Unordered list</span></button>'),this.options.toolbar.numbers&&(t+='<button class="moj-rich-text-editor__toolbar-button moj-rich-text-editor__toolbar-button--ordered-list" type="button" data-command="insertOrderedList"><span class="govuk-visually-hidden">Ordered list</span></button>'),t+="</div>",t},h.prototype.getEnhancedHtml=function(t){return`${this.getToolbarHtml()}<div class="govuk-textarea moj-rich-text-editor__content" contenteditable="true" spellcheck="false"></div>`},h.prototype.hideDefault=function(){this.textarea=this.container.find("textarea"),this.textarea.addClass("govuk-visually-hidden"),this.textarea.attr("aria-hidden",!0),this.textarea.attr("tabindex","-1")},h.prototype.createToolbar=function(){this.toolbar=document.createElement("div"),this.toolbar.className="moj-rich-text-editor",this.toolbar.innerHTML=this.getEnhancedHtml(),this.container.append(this.toolbar),this.toolbar=this.container.find(".moj-rich-text-editor__toolbar"),this.container.find(".moj-rich-text-editor__content").html(this.textarea.val())},h.prototype.configureToolbar=function(){this.buttons=this.container.find(".moj-rich-text-editor__toolbar-button"),this.buttons.prop("tabindex","-1");this.buttons.first().prop("tabindex","0")},h.prototype.onButtonClick=function(t){document.execCommand(window.jQuery(t.currentTarget).data("command"),!1,null)},h.prototype.getContent=function(){return this.container.find(".moj-rich-text-editor__content").html()},h.prototype.onEditorInput=function(t){this.updateTextarea()},h.prototype.updateTextarea=function(){document.execCommand("defaultParagraphSeparator",!1,"p"),this.textarea.val(this.getContent())},h.prototype.onLabelClick=function(t){t.preventDefault(),this.container.find(".moj-rich-text-editor__content").focus()},p.prototype.showMenu=function(){this.toggleButton.attr("aria-expanded","true"),this.container.removeClass("moj-js-hidden"),this.container.find("input").first().get(0).focus()},p.prototype.hideMenu=function(){this.container.addClass("moj-js-hidden"),this.toggleButton.attr("aria-expanded","false")},p.prototype.onToggleButtonClick=function(){"false"===this.toggleButton.attr("aria-expanded")?this.showMenu():this.hideMenu()},p.prototype.onDocumentClick=function(t){window.jQuery.contains(this.toggleButtonContainer[0],t.target)||window.jQuery.contains(this.container[0],t.target)||this.hideMenu()},f.prototype.setupOptions=function(t){t=t||{},this.statusMessage=t.statusMessage||"Sort by %heading% (%direction%)",this.ascendingText=t.ascendingText||"ascending",this.descendingText=t.descendingText||"descending"},f.prototype.createHeadingButtons=function(){const t=this.table.find("thead th");let e;for(let o=0;o<t.length;o++)e=window.jQuery(t[o]),e.attr("aria-sort")&&this.createHeadingButton(e,o)},f.prototype.createHeadingButton=function(t,e){const o=t.text(),n=window.jQuery(`<button type="button" data-index="${e}">${o}</button>`);t.text(""),t.append(n)},f.prototype.createStatusBox=function(){this.status=window.jQuery('<div aria-live="polite" role="status" aria-atomic="true" class="govuk-visually-hidden" />'),this.table.parent().append(this.status)},f.prototype.initialiseSortedColumn=function(){const t=this.getTableRowsArray();this.table.find("th").filter('[aria-sort="ascending"], [aria-sort="descending"]').first().each(((e,o)=>{const n=window.jQuery(o).attr("aria-sort"),i=window.jQuery(o).find("button").attr("data-index"),s=this.sort(t,i,n);this.addRows(s)}))},f.prototype.onSortButtonClick=function(t){const e=t.currentTarget.getAttribute("data-index"),o=window.jQuery(t.currentTarget).parent().attr("aria-sort");let n;n="none"===o||"descending"===o?"ascending":"descending";const i=this.getTableRowsArray(),s=this.sort(i,e,n);this.addRows(s),this.removeButtonStates(),this.updateButtonState(window.jQuery(t.currentTarget),n)},f.prototype.updateButtonState=function(t,e){t.parent().attr("aria-sort",e);let o=this.statusMessage;o=o.replace(/%heading%/,t.text()),o=o.replace(/%direction%/,this[`${e}Text`]),this.status.text(o)},f.prototype.removeButtonStates=function(){this.table.find("thead th").attr("aria-sort","none")},f.prototype.addRows=function(t){for(let e=0;e<t.length;e++)this.body.append(t[e])},f.prototype.getTableRowsArray=function(){const t=[],e=this.body.find("tr");for(let o=0;o<e.length;o++)t.push(e[o]);return t},f.prototype.sort=function(t,e,o){return t.sort(function(t,n){const i=window.jQuery(t).find("td,th").eq(e),s=window.jQuery(n).find("td,th").eq(e),a="ascending"===o?this.getCellValue(i):this.getCellValue(s),r="ascending"===o?this.getCellValue(s):this.getCellValue(i);return"string"==typeof a||"string"==typeof r?a.toString().localeCompare(r.toString()):a-r}.bind(this))},f.prototype.getCellValue=function(t){const e=t.attr("data-sort-value")||t.html(),o=Number(e);return isNaN(o)?e:o};t.AddAnother=e,t.Alert=i,t.ButtonMenu=s,t.DatePicker=a,t.FilterToggleButton=u,t.MultiFileUpload=l,t.MultiSelect=c,t.PasswordReveal=d,t.RichTextEditor=h,t.SearchToggle=p,t.SortableTable=f,t.initAll=function(t){const n=void 0!==(t=void 0!==t?t:{}).scope?t.scope:document;o(n.querySelectorAll('[data-module="moj-add-another"]'),(function(t){new e(t)})),o(n.querySelectorAll('[data-module="moj-multi-select"]'),(function(t){new c({container:t.querySelector(t.getAttribute("data-multi-select-checkbox")),checkboxes:t.querySelectorAll("tbody .govuk-checkboxes__input"),id_prefix:t.getAttribute("data-multi-select-idprefix")})})),o(n.querySelectorAll('[data-module="moj-password-reveal"]'),(function(t){new d(t)})),o(n.querySelectorAll('[data-module="moj-rich-text-editor"]'),(function(t){const e={textarea:window.jQuery(t)},o=t.getAttribute("data-moj-rich-text-editor-toolbar");if(o){const t=o.split(",");e.toolbar={};for(const o in t)e.toolbar[t[o]]=!0}new h(e)})),o(n.querySelectorAll('[data-module="moj-search-toggle"]'),(function(t){new p({toggleButton:{container:window.jQuery(t.querySelector(".moj-search-toggle__toggle")),text:t.getAttribute("data-moj-search-toggle-text")},search:{container:window.jQuery(t.querySelector(".moj-search"))}})})),o(n.querySelectorAll('[data-module="moj-sortable-table"]'),(function(t){new f({table:t})})),o(n.querySelectorAll('[data-module="moj-date-picker"]'),(function(t){new a(t,{}).init()})),o(n.querySelectorAll('[data-module="moj-button-menu"]'),(function(t){new s(t,{}).init()})),o(n.querySelectorAll('[data-module="moj-alert"]'),(function(t){new i(t,{}).init()}))},t.version="0.0.0-development"}));
|
package/moj/version.js
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ?
|
|
3
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MOJFrontend =
|
|
5
|
-
})(this, (function () { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.MOJFrontend = global.MOJFrontend || {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
9
|
-
}
|
|
7
|
+
const version = '0.0.0-development';
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
var hasRequiredVersion;
|
|
13
|
-
|
|
14
|
-
function requireVersion () {
|
|
15
|
-
if (hasRequiredVersion) return version_1;
|
|
16
|
-
hasRequiredVersion = 1;
|
|
17
|
-
const version = '0.0.0-development';
|
|
18
|
-
|
|
19
|
-
version_1 = { version };
|
|
20
|
-
return version_1;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var versionExports = requireVersion();
|
|
24
|
-
var version = /*@__PURE__*/getDefaultExportFromCjs(versionExports);
|
|
25
|
-
|
|
26
|
-
return version;
|
|
9
|
+
exports.version = version;
|
|
27
10
|
|
|
28
11
|
}));
|
package/moj/version.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/frontend",
|
|
3
3
|
"description": "The MOJ Frontend contains the code you need to start building user interfaces for UK Ministry of Justice government services.",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.6.1",
|
|
5
5
|
"main": "moj/all.js",
|
|
6
|
+
"module": "moj/all.mjs",
|
|
6
7
|
"sass": "moj/all.scss",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"sass": "./moj/all.scss",
|
|
11
|
+
"import": "./moj/all.mjs",
|
|
12
|
+
"require": "./moj/all.js",
|
|
13
|
+
"default": "./moj/all.js"
|
|
14
|
+
},
|
|
15
|
+
"./*": "./*",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": false,
|
|
7
19
|
"engines": {
|
|
8
20
|
"node": ">= 4.2.0"
|
|
9
21
|
},
|
|
@@ -26,11 +38,17 @@
|
|
|
26
38
|
"publishConfig": {
|
|
27
39
|
"access": "public"
|
|
28
40
|
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"govuk-frontend": "^5.0.0",
|
|
31
|
-
"moment": "^2.27.0"
|
|
32
|
-
},
|
|
33
41
|
"peerDependencies": {
|
|
34
|
-
"
|
|
42
|
+
"govuk-frontend": "5.x",
|
|
43
|
+
"jquery": "3.x",
|
|
44
|
+
"moment": "2.x"
|
|
45
|
+
},
|
|
46
|
+
"peerDependenciesMeta": {
|
|
47
|
+
"jquery": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"moment": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
35
53
|
}
|
|
36
54
|
}
|