1
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define("GOVUKFrontend",["exports"],e):e(t.GOVUKFrontend={})}(this,function(t){"use strict";function s(t,e){if(window.NodeList.prototype.forEach)return t.forEach(e);for(var n=0;n<t.length;n++)e.call(window,t[n],n,t)}function n(t){this.$module=t,this.moduleId=t.getAttribute("id"),this.$sections=t.querySelectorAll(".govuk-accordion__section"),this.$showAllButton="",this.browserSupportsSessionStorage=e.checkForSessionStorage(),this.controlsClass="govuk-accordion__controls",this.showAllClass="govuk-accordion__show-all",this.showAllTextClass="govuk-accordion__show-all-text",this.sectionExpandedClass="govuk-accordion__section--expanded",this.sectionButtonClass="govuk-accordion__section-button",this.sectionHeaderClass="govuk-accordion__section-header",this.sectionHeadingClass="govuk-accordion__section-heading",this.sectionHeadingTextClass="govuk-accordion__section-heading-text",this.sectionHeadingTextFocusClass="govuk-accordion__section-heading-text-focus",this.sectionShowHideToggleClass="govuk-accordion__section-toggle",this.sectionShowHideToggleFocusClass="govuk-accordion__section-toggle-focus",this.sectionShowHideTextClass="govuk-accordion__section-toggle-text",this.upChevronIconClass="govuk-accordion-nav__chevron",this.downChevronIconClass="govuk-accordion-nav__chevron--down",this.sectionSummaryClass="govuk-accordion__section-summary",this.sectionSummaryFocusClass="govuk-accordion__section-summary-focus"}(function(t){var a,l,c,u;"defineProperty"in Object&&function(){try{return Object.defineProperty({},"test",{value:42}),!0}catch(t){return!1}}()||(a=Object.defineProperty,l=Object.prototype.hasOwnProperty("__defineGetter__"),c="Getters & setters cannot be defined on this javascript engine",u="A property cannot both have accessors and be writable or have a value",Object.defineProperty=function(t,e,n){if(a&&(t===window||t===document||t===Element.prototype||t instanceof Element))return a(t,e,n);if(null===t||!(t instanceof Object||"object"==typeof t))throw new TypeError("Object.defineProperty called on non-object");if(!(n instanceof Object))throw new TypeError("Property description must be an object");var o=String(e),i="value"in n||"writable"in n,s="get"in n&&typeof n.get,r="set"in n&&typeof n.set;if(s){if("function"!==s)throw new TypeError("Getter must be a function");if(!l)throw new TypeError(c);if(i)throw new TypeError(u);Object.__defineGetter__.call(t,o,n.get)}else t[o]=n.value;if(r){if("function"!==r)throw new TypeError("Setter must be a function");if(!l)throw new TypeError(c);if(i)throw new TypeError(u);Object.__defineSetter__.call(t,o,n.set)}return"value"in n&&(t[o]=n.value),t})}).call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){"bind"in Function.prototype||Object.defineProperty(Function.prototype,"bind",{value:function(e){var n,t=Array,o=Object,i=o.prototype,s=t.prototype,r=function r(){},a=i.toString,l="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,c=Function.prototype.toString,u=function u(t){try{return c.call(t),!0}catch(e){return!1}};n=function n(t){if("function"!=typeof t)return!1;if(l)return u(t);var e=a.call(t);return"[object Function]"===e||"[object GeneratorFunction]"===e};var d=s.slice,h=s.concat,p=s.push,f=Math.max,m=this;if(!n(m))throw new TypeError("Function.prototype.bind called on incompatible "+m);for(var b,v=d.call(arguments,1),y=f(0,m.length-v.length),g=[],w=0;w<y;w++)p.call(g,"$"+w);return b=Function("binder","return function ("+g.join(",")+"){ return binder.apply(this, arguments); }")(function(){if(this instanceof b){var t=m.apply(this,h.call(v,d.call(arguments)));return o(t)===t?t:this}return m.apply(e,h.call(v,d.call(arguments)))}),m.prototype&&(r.prototype=m.prototype,b.prototype=new r,r.prototype=null),b}})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(o){var t,e,n;"DOMTokenList"in this&&(!("classList"in(t=document.createElement("x")))||!t.classList.toggle("x",!1)&&!t.className)||("DOMTokenList"in(e=this)&&e.DOMTokenList&&(!document.createElementNS||!document.createElementNS("http://www.w3.org/2000/svg","svg")||document.createElementNS("http://www.w3.org/2000/svg","svg").classList instanceof DOMTokenList)||(e.DOMTokenList=function(){var i=!0,n=function(t,e,n,o){Object.defineProperty?Object.defineProperty(t,e,{configurable:!1===i||!!o,get:n}):t.__defineGetter__(e,n)};try{n({},"support")}catch(t){i=!1}return function(i,s){var r=this,a=[],l={},c=0,t=0,e=function(t){n(r,t,function(){return d(),a[t]},!1)},u=function(){if(t<=c)for(;t<c;++t)e(t)},d=function(){var t,e,n=arguments,o=/\s+/;if(n.length)for(e=0;e<n.length;++e)if(o.test(n[e]))throw(t=new SyntaxError('String "'+n[e]+'" contains an invalid character')).code=5,t.name="InvalidCharacterError",t;for(""===(a="object"==typeof i[s]?(""+i[s].baseVal).replace(/^\s+|\s+$/g,"").split(o):(""+i[s]).replace(/^\s+|\s+$/g,"").split(o))[0]&&(a=[]),l={},e=0;e<a.length;++e)l[a[e]]=!0;c=a.length,u()};return d(),n(r,"length",function(){return d(),c}),r.toLocaleString=r.toString=function(){return d(),a.join(" ")},r.item=function(t){return d(),a[t]},r.contains=function(t){return d(),!!l[t]},r.add=function(){d.apply(r,t=arguments);for(var t,e,n=0,o=t.length;n<o;++n)l[e=t[n]]||(a.push(e),l[e]=!0);c!==a.length&&(c=a.length>>>0,"object"==typeof i[s]?i[s].baseVal=a.join(" "):i[s]=a.join(" "),u())},r.remove=function(){d.apply(r,t=arguments);for(var t,e={},n=0,o=[];n<t.length;++n)e[t[n]]=!0,delete l[t[n]];for(n=0;n<a.length;++n)e[a[n]]||o.push(a[n]);c=(a=o).length>>>0,"object"==typeof i[s]?i[s].baseVal=a.join(" "):i[s]=a.join(" "),u()},r.toggle=function(t,e){return d.apply(r,[t]),o!==e?e?(r.add(t),!0):(r.remove(t),!1):l[t]?(r.remove(t),!1):(r.add(t),!0)},r}}()),"classList"in(n=document.createElement("span"))&&(n.classList.toggle("x",!1),n.classList.contains("x")&&(n.classList.constructor.prototype.toggle=function(t){var e=arguments[1];if(e!==o)return this[(e=!!e)?"add":"remove"](t),e;var n=!this.contains(t);return this[n?"add":"remove"](t),n})),function(){var t=document.createElement("span");if("classList"in t&&(t.classList.add("a","b"),!t.classList.contains("b"))){var o=t.classList.constructor.prototype.add;t.classList.constructor.prototype.add=function(){for(var t=arguments,e=arguments.length,n=0;n<e;n++)o.call(this,t[n])}}}(),function(){var t=document.createElement("span");if("classList"in t&&(t.classList.add("a"),t.classList.add("b"),t.classList.remove("a","b"),t.classList.contains("b"))){var o=t.classList.constructor.prototype.remove;t.classList.constructor.prototype.remove=function(){for(var t=arguments,e=arguments.length,n=0;n<e;n++)o.call(this,t[n])}}}())}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){"Document"in this||"undefined"==typeof WorkerGlobalScope&&"function"!=typeof importScripts&&(this.HTMLDocument?this.Document=this.HTMLDocument:(this.Document=this.HTMLDocument=document.constructor=new Function("return function Document() {}")(),this.Document.prototype=document))}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){"Element"in this&&"HTMLElement"in this||function(){if(!window.Element||window.HTMLElement){window.Element=window.HTMLElement=new Function("return function Element() {}")();var t,e=document.appendChild(document.createElement("body")),n=e.appendChild(document.createElement("iframe")).contentWindow.document,a=Element.prototype=n.appendChild(n.createElement("*")),l={},c=function(t,e){var n,o,i,s=t.childNodes||[],r=-1;if(1===t.nodeType&&t.constructor!==Element)for(n in t.constructor=Element,l)o=l[n],t[n]=o;for(;i=e&&s[++r];)c(i,e);return t},u=document.getElementsByTagName("*"),o=document.createElement,i=100;a.attachEvent("onpropertychange",function(t){for(var e,n=t.propertyName,o=!l.hasOwnProperty(n),i=a[n],s=l[n],r=-1;e=u[++r];)1===e.nodeType&&(!o&&e[n]!==s||(e[n]=i));l[n]=i}),a.constructor=Element,a.hasAttribute||(a.hasAttribute=function(t){return null!==this.getAttribute(t)}),s()||(document.onreadystatechange=s,t=setInterval(s,25)),document.createElement=function(t){var e=o(String(t).toLowerCase());return c(e)},document.removeChild(e)}else window.HTMLElement=window.Element;function s(){return i--||clearTimeout(t),!(!document.body||document.body.prototype||!/(complete|interactive)/.test(document.readyState))&&(c(document,!0),t&&document.body.prototype&&clearTimeout(t),!!document.body.prototype)}}()}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){var e;"document"in this&&"classList"in document.documentElement&&"Element"in this&&"classList"in Element.prototype&&((e=document.createElement("span")).classList.add("a","b"),e.classList.contains("b"))||function(t){var u=!0,d=function(t,e,n,o){Object.defineProperty?Object.defineProperty(t,e,{configurable:!1===u||!!o,get:n}):t.__defineGetter__(e,n)};try{d({},"support")}catch(e){u=!1}var h=function(t,l,c){d(t.prototype,l,function(){var t,e=this,n="__defineGetter__DEFINE_PROPERTY"+l;if(e[n])return t;if(!(e[n]=!0)===u){for(var o,i=h.mirror||document.createElement("div"),s=i.childNodes,r=s.length,a=0;a<r;++a)if(s[a]._R===e){o=s[a];break}o=o||i.appendChild(document.createElement("div")),t=DOMTokenList.call(o,e,c)}else t=new DOMTokenList(e,c);return d(e,l,function(){return t}),delete e[n],t},!0)};h(t.Element,"classList","className"),h(t.HTMLElement,"classList","className"),h(t.HTMLLinkElement,"relList","rel"),h(t.HTMLAnchorElement,"relList","rel"),h(t.HTMLAreaElement,"relList","rel")}(this)}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),n.prototype.init=function(){if(this.$module){this.initControls(),this.initSectionHeaders();var t=this.checkIfAllSectionsOpen();this.updateShowAllButton(t)}},n.prototype.initControls=function(){this.$showAllButton=document.createElement("button"),this.$showAllButton.setAttribute("type","button"),this.$showAllButton.setAttribute("class",this.showAllClass),this.$showAllButton.setAttribute("aria-expanded","false");var t=document.createElement("span");t.classList.add(this.upChevronIconClass),this.$showAllButton.appendChild(t);var e=document.createElement("div");e.setAttribute("class",this.controlsClass),e.appendChild(this.$showAllButton),this.$module.insertBefore(e,this.$module.firstChild);var n=document.createElement("span");n.classList.add(this.showAllTextClass),this.$showAllButton.appendChild(n),this.$showAllButton.addEventListener("click",this.onShowOrHideAllToggle.bind(this))},n.prototype.initSectionHeaders=function(){s(this.$sections,function(t,e){var n=t.querySelector("."+this.sectionHeaderClass);this.constructHeaderMarkup(n,e),this.setExpanded(this.isExpanded(t),t),n.addEventListener("click",this.onSectionToggle.bind(this,t)),this.setInitialState(t)}.bind(this))},n.prototype.constructHeaderMarkup=function(t,e){var n=t.querySelector("."+this.sectionButtonClass),o=t.querySelector("."+this.sectionHeadingClass),i=t.querySelector("."+this.sectionSummaryClass),s=document.createElement("button");s.setAttribute("type","button"),s.setAttribute("aria-controls",this.moduleId+"-content-"+(e+1));for(var r=0;r<n.attributes.length;r++){var a=n.attributes.item(r);"id"!==a.nodeName&&s.setAttribute(a.nodeName,a.nodeValue)}var l=document.createElement("span");l.classList.add(this.sectionHeadingTextClass),l.id=n.id;var c=document.createElement("span");c.classList.add(this.sectionHeadingTextFocusClass),l.appendChild(c),c.innerHTML=n.innerHTML;var u=document.createElement("span");u.classList.add(this.sectionShowHideToggleClass),u.setAttribute("data-nosnippet","");var d=document.createElement("span");d.classList.add(this.sectionShowHideToggleFocusClass),u.appendChild(d);var h=document.createElement("span"),p=document.createElement("span");if(p.classList.add(this.upChevronIconClass),d.appendChild(p),h.classList.add(this.sectionShowHideTextClass),d.appendChild(h),s.appendChild(l),s.appendChild(this.getButtonPunctuationEl()),null!=i){var f=document.createElement("span"),m=document.createElement("span");m.classList.add(this.sectionSummaryFocusClass),f.appendChild(m);for(var b=0,v=i.attributes.length;b<v;++b){var y=i.attributes.item(b).nodeName,g=i.attributes.item(b).nodeValue;f.setAttribute(y,g)}m.innerHTML=i.innerHTML,i.parentNode.replaceChild(f,i),s.appendChild(f),s.appendChild(this.getButtonPunctuationEl())}s.appendChild(u),o.removeChild(n),o.appendChild(s)},n.prototype.onSectionToggle=function(t){var e=this.isExpanded(t);this.setExpanded(!e,t),this.storeState(t)},n.prototype.onShowOrHideAllToggle=function(){var e=this,t=this.$sections,n=!this.checkIfAllSectionsOpen();s(t,function(t){e.setExpanded(n,t),e.storeState(t)}),e.updateShowAllButton(n)},n.prototype.setExpanded=function(t,e){var n=e.querySelector("."+this.upChevronIconClass),o=e.querySelector("."+this.sectionShowHideTextClass),i=e.querySelector("."+this.sectionButtonClass),s=t?"Hide":"Show",r=document.createElement("span");r.classList.add("govuk-visually-hidden"),r.innerHTML=" this section",o.innerHTML=s,o.appendChild(r),i.setAttribute("aria-expanded",t),t?(e.classList.add(this.sectionExpandedClass),n.classList.remove(this.downChevronIconClass)):(e.classList.remove(this.sectionExpandedClass),n.classList.add(this.downChevronIconClass));var a=this.checkIfAllSectionsOpen();this.updateShowAllButton(a)},n.prototype.isExpanded=function(t){return t.classList.contains(this.sectionExpandedClass)},n.prototype.checkIfAllSectionsOpen=function(){return this.$sections.length===this.$module.querySelectorAll("."+this.sectionExpandedClass).length},n.prototype.updateShowAllButton=function(t){var e=this.$showAllButton.querySelector("."+this.upChevronIconClass),n=this.$showAllButton.querySelector("."+this.showAllTextClass),o=t?"Hide all sections":"Show all sections";this.$showAllButton.setAttribute("aria-expanded",t),n.innerHTML=o,t?e.classList.remove(this.downChevronIconClass):e.classList.add(this.downChevronIconClass)};var e={checkForSessionStorage:function(){var t,e="this is the test string";try{return window.sessionStorage.setItem(e,e),t=window.sessionStorage.getItem(e)===e.toString(),window.sessionStorage.removeItem(e),t}catch(n){"undefined"!=typeof console&&"undefined"!=typeof console.log||console.log("Notice: sessionStorage not available.")}}};n.prototype.storeState=function(t){if(this.browserSupportsSessionStorage){var e=t.querySelector("."+this.sectionButtonClass);if(e){var n=e.getAttribute("aria-controls"),o=e.getAttribute("aria-expanded");void 0!==n||"undefined"!=typeof console&&"undefined"!=typeof console.log||console.error(new Error("No aria controls present in accordion section heading.")),void 0!==o||"undefined"!=typeof console&&"undefined"!=typeof console.log||console.error(new Error("No aria expanded present in accordion section heading.")),n&&o&&window.sessionStorage.setItem(n,o)}}},n.prototype.setInitialState=function(t){if(this.browserSupportsSessionStorage){var e=t.querySelector("."+this.sectionButtonClass);if(e){var n=e.getAttribute("aria-controls"),o=n?window.sessionStorage.getItem(n):null;null!==o&&this.setExpanded("true"===o,t)}}},n.prototype.getButtonPunctuationEl=function(){var t=document.createElement("span");return t.classList.add("govuk-visually-hidden","govuk-accordion__section-heading-divider"),t.innerHTML=", ",t},function(t){"Window"in this||"undefined"==typeof WorkerGlobalScope&&"function"!=typeof importScripts&&function(t){t.constructor?t.Window=t.constructor:(t.Window=t.constructor=new Function("return function Window() {}")()).prototype=this}(this)}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(s){!function(t){if(!("Event"in t))return!1;if("function"==typeof t.Event)return!0;try{return new Event("click"),!0}catch(e){return!1}}(this)&&function(){var n={click:1,dblclick:1,keyup:1,keypress:1,keydown:1,mousedown:1,mouseup:1,mousemove:1,mouseover:1,mouseenter:1,mouseleave:1,mouseout:1,storage:1,storagecommit:1,textinput:1};if("undefined"!=typeof document&&"undefined"!=typeof window){var t=window.Event&&window.Event.prototype||null;window.Event=Window.prototype.Event=function(t,e){if(!t)throw new Error("Not enough arguments");var n;if("createEvent"in document){n=document.createEvent("Event");var o=!(!e||e.bubbles===s)&&e.bubbles,i=!(!e||e.cancelable===s)&&e.cancelable;return n.initEvent(t,o,i),n}return(n=document.createEventObject()).type=t,n.bubbles=!(!e||e.bubbles===s)&&e.bubbles,n.cancelable=!(!e||e.cancelable===s)&&e.cancelable,n},t&&Object.defineProperty(window.Event,"prototype",{configurable:!1,enumerable:!1,writable:!0,value:t}),"createEvent"in document||(window.addEventListener=Window.prototype.addEventListener=Document.prototype.addEventListener=Element.prototype.addEventListener=function(){var r=this,t=arguments[0],e=arguments[1];if(r===window&&t in n)throw new Error("In IE8 the event: "+t+" is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.");r._events||(r._events={}),r._events[t]||(r._events[t]=function(t){var e,n=r._events[t.type].list,o=n.slice(),i=-1,s=o.length;for(t.preventDefault=function(){!1!==t.cancelable&&(t.returnValue=!1)},t.stopPropagation=function(){t.cancelBubble=!0},t.stopImmediatePropagation=function(){t.cancelBubble=!0,t.cancelImmediate=!0},t.currentTarget=r,t.relatedTarget=t.fromElement||null,t.target=t.target||t.srcElement||r,t.timeStamp=(new Date).getTime(),t.clientX&&(t.pageX=t.clientX+document.documentElement.scrollLeft,t.pageY=t.clientY+document.documentElement.scrollTop);++i<s&&!t.cancelImmediate;)i in o&&-1!==a(n,e=o[i])&&"function"==typeof e&&e.call(r,t)},r._events[t].list=[],r.attachEvent&&r.attachEvent("on"+t,r._events[t])),r._events[t].list.push(e)},window.removeEventListener=Window.prototype.removeEventListener=Document.prototype.removeEventListener=Element.prototype.removeEventListener=function(){var t,e=this,n=arguments[0],o=arguments[1];e._events&&e._events[n]&&e._events[n].list&&-1!==(t=a(e._events[n].list,o))&&(e._events[n].list.splice(t,1),e._events[n].list.length||(e.detachEvent&&e.detachEvent("on"+n,e._events[n]),delete e._events[n]))},window.dispatchEvent=Window.prototype.dispatchEvent=Document.prototype.dispatchEvent=Element.prototype.dispatchEvent=function(t){if(!arguments.length)throw new Error("Not enough arguments");if(!t||"string"!=typeof t.type)throw new Error("DOM Events Exception 0");var e=this,n=t.type;try{if(!t.bubbles){t.cancelBubble=!0;var o=function(t){t.cancelBubble=!0,(e||window).detachEvent("on"+n,o)};this.attachEvent("on"+n,o)}this.fireEvent("on"+n,t)}catch(i){for(t.target=e;"_events"in(t.currentTarget=e)&&"function"==typeof e._events[n]&&e._events[n].call(e,t),"function"==typeof e["on"+n]&&e["on"+n].call(e,t),(e=9===e.nodeType?e.parentWindow:e.parentNode)&&!t.cancelBubble;);}return!0},document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&document.dispatchEvent(new Event("DOMContentLoaded",{bubbles:!0}))}))}function a(t,e){for(var n=-1,o=t.length;++n<o;)if(n in t&&t[n]===e)return n;return-1}}()}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{});function o(t){this.$module=t,this.debounceFormSubmitTimer=null}o.prototype.handleKeyDown=function(t){var e=t.target;"button"===e.getAttribute("role")&&32===t.keyCode&&(t.preventDefault(),e.click())},o.prototype.debounce=function(t){if("true"===t.target.getAttribute("data-prevent-double-click"))return this.debounceFormSubmitTimer?(t.preventDefault(),!1):void(this.debounceFormSubmitTimer=setTimeout(function(){this.debounceFormSubmitTimer=null}.bind(this),1e3))},o.prototype.init=function(){this.$module.addEventListener("keydown",this.handleKeyDown),this.$module.addEventListener("click",this.debounce)};function i(t){this.$module=t}function r(t){this.$module=t,this.$textarea=t.querySelector(".govuk-js-character-count"),this.$textarea&&(this.$countMessage=document.getElementById(this.$textarea.id+"-info"))}function a(t){this.$module=t,this.$inputs=t.querySelectorAll('input[type="checkbox"]')}function l(t){this.$module=t}function c(t){this.$module=t}function u(t){this.$module=t,this.$menuButton=t&&t.querySelector(".govuk-js-header-toggle"),this.$menu=this.$menuButton&&t.querySelector("#"+this.$menuButton.getAttribute("aria-controls"))}function d(t){this.$module=t,this.$inputs=t.querySelectorAll('input[type="radio"]')}function h(t){this.$module=t,this.$linkedElement=null,this.linkedElementListener=!1}function p(t){this.$module=t,this.$tabs=t.querySelectorAll(".govuk-tabs__tab"),this.keys={left:37,right:39,up:38,down:40},this.jsHiddenClass="govuk-tabs__panel--hidden"}i.prototype.init=function(){this.$module&&("boolean"==typeof this.$module.open||this.polyfillDetails())},i.prototype.polyfillDetails=function(){var t=this.$module,e=this.$summary=t.getElementsByTagName("summary").item(0),n=this.$content=t.getElementsByTagName("div").item(0);e&&n&&(n.id||(n.id="details-content-"+function o(){var n=(new Date).getTime();return"undefined"!=typeof window.performance&&"function"==typeof window.performance.now&&(n+=window.performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"===t?e:3&e|8).toString(16)})}()),t.setAttribute("role","group"),e.setAttribute("role","button"),e.setAttribute("aria-controls",n.id),!(e.tabIndex=0)==(null!==t.getAttribute("open"))?(e.setAttribute("aria-expanded","true"),n.setAttribute("aria-hidden","false")):(e.setAttribute("aria-expanded","false"),n.setAttribute("aria-hidden","true"),n.style.display="none"),this.polyfillHandleInputs(e,this.polyfillSetAttributes.bind(this)))},i.prototype.polyfillSetAttributes=function(){var t=this.$module,e=this.$summary,n=this.$content,o="true"===e.getAttribute("aria-expanded"),i="true"===n.getAttribute("aria-hidden");return e.setAttribute("aria-expanded",o?"false":"true"),n.setAttribute("aria-hidden",i?"false":"true"),n.style.display=o?"none":"",null!==t.getAttribute("open")?t.removeAttribute("open"):t.setAttribute("open","open"),!0},i.prototype.polyfillHandleInputs=function(t,n){t.addEventListener("keypress",function(t){var e=t.target;13!==t.keyCode&&32!==t.keyCode||"summary"===e.nodeName.toLowerCase()&&(t.preventDefault(),e.click?e.click():n(t))}),t.addEventListener("keyup",function(t){var e=t.target;32===t.keyCode&&"summary"===e.nodeName.toLowerCase()&&t.preventDefault()}),t.addEventListener("click",n)},r.prototype.defaults={characterCountAttribute:"data-maxlength",wordCountAttribute:"data-maxwords"},r.prototype.init=function(){var t=this.$module,e=this.$textarea,n=this.$countMessage;if(e&&n){e.insertAdjacentElement("afterend",n),this.options=this.getDataset(t);var o=this.defaults.characterCountAttribute;this.options.maxwords&&(o=this.defaults.wordCountAttribute),this.maxLength=t.getAttribute(o),this.maxLength&&(t.removeAttribute("maxlength"),"onpageshow"in window?window.addEventListener("pageshow",this.sync.bind(this)):window.addEventListener("DOMContentLoaded",this.sync.bind(this)),this.sync())}},r.prototype.sync=function(){this.bindChangeEvents(),this.updateCountMessage()},r.prototype.getDataset=function(t){var e={},n=t.attributes;if(n)for(var o=0;o<n.length;o++){var i=n[o],s=i.name.match(/^data-(.+)/);s&&(e[s[1]]=i.value)}return e},r.prototype.count=function(t){var e;this.options.maxwords?e=(t.match(/\S+/g)||[]).length:e=t.length;return e},r.prototype.bindChangeEvents=function(){var t=this.$textarea;t.addEventListener("keyup",this.checkIfValueChanged.bind(this)),t.addEventListener("focus",this.handleFocus.bind(this)),t.addEventListener("blur",this.handleBlur.bind(this))},r.prototype.checkIfValueChanged=function(){this.$textarea.oldValue||(this.$textarea.oldValue=""),this.$textarea.value!==this.$textarea.oldValue&&(this.$textarea.oldValue=this.$textarea.value,this.updateCountMessage())},r.prototype.updateCountMessage=function(){var t=this.$textarea,e=this.options,n=this.$countMessage,o=this.count(t.value),i=this.maxLength,s=i-o;o<i*(e.threshold?e.threshold:0)/100?(n.classList.add("govuk-character-count__message--disabled"),n.setAttribute("aria-hidden",!0)):(n.classList.remove("govuk-character-count__message--disabled"),n.removeAttribute("aria-hidden")),s<0?(t.classList.add("govuk-textarea--error"),n.classList.remove("govuk-hint"),n.classList.add("govuk-error-message")):(t.classList.remove("govuk-textarea--error"),n.classList.remove("govuk-error-message"),n.classList.add("govuk-hint"));var r,a,l="character";e.maxwords&&(l="word"),l+=-1==s||1==s?"":"s",r=s<0?"too many":"remaining",a=Math.abs(s),n.innerHTML="You have "+a+" "+l+" "+r},r.prototype.handleFocus=function(){this.valueChecker=setInterval(this.checkIfValueChanged.bind(this),1e3)},r.prototype.handleBlur=function(){clearInterval(this.valueChecker)},a.prototype.init=function(){var t=this.$module;s(this.$inputs,function(t){var e=t.getAttribute("data-aria-controls");e&&document.getElementById(e)&&(t.setAttribute("aria-controls",e),t.removeAttribute("data-aria-controls"))}),"onpageshow"in window?window.addEventListener("pageshow",this.syncAllConditionalReveals.bind(this)):window.addEventListener("DOMContentLoaded",this.syncAllConditionalReveals.bind(this)),this.syncAllConditionalReveals(),t.addEventListener("click",this.handleClick.bind(this))},a.prototype.syncAllConditionalReveals=function(){s(this.$inputs,this.syncConditionalRevealWithInputState.bind(this))},a.prototype.syncConditionalRevealWithInputState=function(t){var e=document.getElementById(t.getAttribute("aria-controls"));if(e&&e.classList.contains("govuk-checkboxes__conditional")){var n=t.checked;t.setAttribute("aria-expanded",n),e.classList.toggle("govuk-checkboxes__conditional--hidden",!n)}},a.prototype.unCheckAllInputsExcept=function(e){s(document.querySelectorAll('input[type="checkbox"][name="'+e.name+'"]'),function(t){e.form===t.form&&t!==e&&(t.checked=!1,this.syncConditionalRevealWithInputState(t))}.bind(this))},a.prototype.unCheckExclusiveInputs=function(e){s(document.querySelectorAll('input[data-behaviour="exclusive"][type="checkbox"][name="'+e.name+'"]'),function(t){e.form===t.form&&(t.checked=!1,this.syncConditionalRevealWithInputState(t))}.bind(this))},a.prototype.handleClick=function(t){var e=t.target;"checkbox"===e.type&&(e.getAttribute("aria-controls")&&this.syncConditionalRevealWithInputState(e),e.checked&&("exclusive"===e.getAttribute("data-behaviour")?this.unCheckAllInputsExcept(e):this.unCheckExclusiveInputs(e)))},function(t){"document"in this&&"matches"in document.documentElement||(Element.prototype.matches=Element.prototype.webkitMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.mozMatchesSelector||function(t){for(var e=(this.document||this.ownerDocument).querySelectorAll(t),n=0;e[n]&&e[n]!==this;)++n;return!!e[n]})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){"document"in this&&"closest"in document.documentElement||(Element.prototype.closest=function(t){for(var e=this;e;){if(e.matches(t))return e;e="SVGElement"in window&&e instanceof SVGElement?e.parentNode:e.parentElement}return null})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),l.prototype.init=function(){var t=this.$module;t&&(t.focus(),t.addEventListener("click",this.handleClick.bind(this)))},l.prototype.handleClick=function(t){var e=t.target;this.focusTarget(e)&&t.preventDefault()},l.prototype.focusTarget=function(t){if("A"!==t.tagName||!1===t.href)return!1;var e=this.getFragmentFromUrl(t.href),n=document.getElementById(e);if(!n)return!1;var o=this.getAssociatedLegendOrLabel(n);return!!o&&(o.scrollIntoView(),n.focus({preventScroll:!0}),!0)},l.prototype.getFragmentFromUrl=function(t){return-1!==t.indexOf("#")&&t.split("#").pop()},l.prototype.getAssociatedLegendOrLabel=function(t){var e=t.closest("fieldset");if(e){var n=e.getElementsByTagName("legend");if(n.length){var o=n[0];if("checkbox"===t.type||"radio"===t.type)return o;var i=o.getBoundingClientRect().top,s=t.getBoundingClientRect();if(s.height&&window.innerHeight)if(s.top+s.height-i<window.innerHeight/2)return o}}return document.querySelector("label[for='"+t.getAttribute("id")+"']")||t.closest("label")},c.prototype.init=function(){this.$module&&this.setFocus()},c.prototype.setFocus=function(){var t=this.$module;"true"!==t.getAttribute("data-disable-auto-focus")&&"alert"===t.getAttribute("role")&&(t.getAttribute("tabindex")||(t.setAttribute("tabindex","-1"),t.addEventListener("blur",function(){t.removeAttribute("tabindex")})),t.focus())},u.prototype.init=function(){this.$module&&this.$menuButton&&this.$menu&&(this.syncState(this.$menu.classList.contains("govuk-header__navigation-list--open")),this.$menuButton.addEventListener("click",this.handleMenuButtonClick.bind(this)))},u.prototype.syncState=function(t){this.$menuButton.classList.toggle("govuk-header__menu-button--open",t),this.$menuButton.setAttribute("aria-expanded",t)},u.prototype.handleMenuButtonClick=function(){var t=this.$menu.classList.toggle("govuk-header__navigation-list--open");this.syncState(t)},d.prototype.init=function(){var t=this.$module;s(this.$inputs,function(t){var e=t.getAttribute("data-aria-controls");e&&document.getElementById(e)&&(t.setAttribute("aria-controls",e),t.removeAttribute("data-aria-controls"))}),"onpageshow"in window?window.addEventListener("pageshow",this.syncAllConditionalReveals.bind(this)):window.addEventListener("DOMContentLoaded",this.syncAllConditionalReveals.bind(this)),this.syncAllConditionalReveals(),t.addEventListener("click",this.handleClick.bind(this))},d.prototype.syncAllConditionalReveals=function(){s(this.$inputs,this.syncConditionalRevealWithInputState.bind(this))},d.prototype.syncConditionalRevealWithInputState=function(t){var e=document.getElementById(t.getAttribute("aria-controls"));if(e&&e.classList.contains("govuk-radios__conditional")){var n=t.checked;t.setAttribute("aria-expanded",n),e.classList.toggle("govuk-radios__conditional--hidden",!n)}},d.prototype.handleClick=function(t){var n=t.target;"radio"===n.type&&s(document.querySelectorAll('input[type="radio"][aria-controls]'),function(t){var e=t.form===n.form;t.name===n.name&&e&&this.syncConditionalRevealWithInputState(t)}.bind(this))},h.prototype.init=function(){this.$module&&(this.$linkedElement=this.getLinkedElement(),this.$linkedElement&&this.$module.addEventListener("click",this.focusLinkedElement.bind(this)))},h.prototype.getLinkedElement=function(){var t=this.getFragmentFromUrl();return!!t&&document.getElementById(t)},h.prototype.focusLinkedElement=function(){var t=this.$linkedElement;t.getAttribute("tabindex")||(t.setAttribute("tabindex","-1"),t.classList.add("govuk-skip-link-focused-element"),this.linkedElementListener||(this.$linkedElement.addEventListener("blur",this.removeFocusProperties.bind(this)),this.linkedElementListener=!0)),t.focus()},h.prototype.removeFocusProperties=function(){this.$linkedElement.removeAttribute("tabindex"),this.$linkedElement.classList.remove("govuk-skip-link-focused-element")},h.prototype.getFragmentFromUrl=function(){return!!this.$module.hash&&this.$module.hash.split("#").pop()},function(t){"document"in this&&"nextElementSibling"in document.documentElement||Object.defineProperty(Element.prototype,"nextElementSibling",{get:function(){for(var t=this.nextSibling;t&&1!==t.nodeType;)t=t.nextSibling;return t}})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){"document"in this&&"previousElementSibling"in document.documentElement||Object.defineProperty(Element.prototype,"previousElementSibling",{get:function(){for(var t=this.previousSibling;t&&1!==t.nodeType;)t=t.previousSibling;return t}})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),p.prototype.init=function(){"function"==typeof window.matchMedia?this.setupResponsiveChecks():this.setup()},p.prototype.setupResponsiveChecks=function(){this.mql=window.matchMedia("(min-width: 40.0625em)"),this.mql.addListener(this.checkMode.bind(this)),this.checkMode()},p.prototype.checkMode=function(){this.mql.matches?this.setup():this.teardown()},p.prototype.setup=function(){var t=this.$module,e=this.$tabs,n=t.querySelector(".govuk-tabs__list"),o=t.querySelectorAll(".govuk-tabs__list-item");if(e&&n&&o){n.setAttribute("role","tablist"),s(o,function(t){t.setAttribute("role","presentation")}),s(e,function(t){this.setAttributes(t),t.boundTabClick=this.onTabClick.bind(this),t.boundTabKeydown=this.onTabKeydown.bind(this),t.addEventListener("click",t.boundTabClick,!0),t.addEventListener("keydown",t.boundTabKeydown,!0),this.hideTab(t)}.bind(this));var i=this.getTab(window.location.hash)||this.$tabs[0];this.showTab(i),t.boundOnHashChange=this.onHashChange.bind(this),window.addEventListener("hashchange",t.boundOnHashChange,!0)}},p.prototype.teardown=function(){var t=this.$module,e=this.$tabs,n=t.querySelector(".govuk-tabs__list"),o=t.querySelectorAll(".govuk-tabs__list-item");e&&n&&o&&(n.removeAttribute("role"),s(o,function(t){t.removeAttribute("role","presentation")}),s(e,function(t){t.removeEventListener("click",t.boundTabClick,!0),t.removeEventListener("keydown",t.boundTabKeydown,!0),this.unsetAttributes(t)}.bind(this)),window.removeEventListener("hashchange",t.boundOnHashChange,!0))},p.prototype.onHashChange=function(t){var e=window.location.hash,n=this.getTab(e);if(n)if(this.changingHash)this.changingHash=!1;else{var o=this.getCurrentTab();this.hideTab(o),this.showTab(n),n.focus()}},p.prototype.hideTab=function(t){this.unhighlightTab(t),this.hidePanel(t)},p.prototype.showTab=function(t){this.highlightTab(t),this.showPanel(t)},p.prototype.getTab=function(t){return this.$module.querySelector('.govuk-tabs__tab[href="'+t+'"]')},p.prototype.setAttributes=function(t){var e=this.getHref(t).slice(1);t.setAttribute("id","tab_"+e),t.setAttribute("role","tab"),t.setAttribute("aria-controls",e),t.setAttribute("aria-selected","false"),t.setAttribute("tabindex","-1");var n=this.getPanel(t);n.setAttribute("role","tabpanel"),n.setAttribute("aria-labelledby",t.id),n.classList.add(this.jsHiddenClass)},p.prototype.unsetAttributes=function(t){t.removeAttribute("id"),t.removeAttribute("role"),t.removeAttribute("aria-controls"),t.removeAttribute("aria-selected"),t.removeAttribute("tabindex");var e=this.getPanel(t);e.removeAttribute("role"),e.removeAttribute("aria-labelledby"),e.classList.remove(this.jsHiddenClass)},p.prototype.onTabClick=function(t){if(!t.target.classList.contains("govuk-tabs__tab"))return!1;t.preventDefault();var e=t.target,n=this.getCurrentTab();this.hideTab(n),this.showTab(e),this.createHistoryEntry(e)},p.prototype.createHistoryEntry=function(t){var e=this.getPanel(t),n=e.id;e.id="",this.changingHash=!0,window.location.hash=this.getHref(t).slice(1),e.id=n},p.prototype.onTabKeydown=function(t){switch(t.keyCode){case this.keys.left:case this.keys.up:this.activatePreviousTab(),t.preventDefault();break;case this.keys.right:case this.keys.down:this.activateNextTab(),t.preventDefault()}},p.prototype.activateNextTab=function(){var t=this.getCurrentTab(),e=t.parentNode.nextElementSibling;if(e)var n=e.querySelector(".govuk-tabs__tab");n&&(this.hideTab(t),this.showTab(n),n.focus(),this.createHistoryEntry(n))},p.prototype.activatePreviousTab=function(){var t=this.getCurrentTab(),e=t.parentNode.previousElementSibling;if(e)var n=e.querySelector(".govuk-tabs__tab");n&&(this.hideTab(t),this.showTab(n),n.focus(),this.createHistoryEntry(n))},p.prototype.getPanel=function(t){return this.$module.querySelector(this.getHref(t))},p.prototype.showPanel=function(t){this.getPanel(t).classList.remove(this.jsHiddenClass)},p.prototype.hidePanel=function(t){this.getPanel(t).classList.add(this.jsHiddenClass)},p.prototype.unhighlightTab=function(t){t.setAttribute("aria-selected","false"),t.parentNode.classList.remove("govuk-tabs__list-item--selected"),t.setAttribute("tabindex","-1")},p.prototype.highlightTab=function(t){t.setAttribute("aria-selected","true"),t.parentNode.classList.add("govuk-tabs__list-item--selected"),t.setAttribute("tabindex","0")},p.prototype.getCurrentTab=function(){return this.$module.querySelector(".govuk-tabs__list-item--selected .govuk-tabs__tab")},p.prototype.getHref=function(t){var e=t.getAttribute("href");return e.slice(e.indexOf("#"),e.length)},t.initAll=function f(t){var e="undefined"!=typeof(t=void 0!==t?t:{}).scope?t.scope:document;s(e.querySelectorAll('[data-module="govuk-button"]'),function(t){new o(t).init()}),s(e.querySelectorAll('[data-module="govuk-accordion"]'),function(t){new n(t).init()}),s(e.querySelectorAll('[data-module="govuk-details"]'),function(t){new i(t).init()}),s(e.querySelectorAll('[data-module="govuk-character-count"]'),function(t){new r(t).init()}),s(e.querySelectorAll('[data-module="govuk-checkboxes"]'),function(t){new a(t).init()}),new l(e.querySelector('[data-module="govuk-error-summary"]')).init(),new u(e.querySelector('[data-module="govuk-header"]')).init(),s(e.querySelectorAll('[data-module="govuk-notification-banner"]'),function(t){new c(t).init()}),s(e.querySelectorAll('[data-module="govuk-radios"]'),function(t){new d(t).init()}),new h(e.querySelector('[data-module="govuk-skip-link"]')).init(),s(e.querySelectorAll('[data-module="govuk-tabs"]'),function(t){new p(t).init()})},t.Accordion=n,t.Button=o,t.Details=i,t.CharacterCount=r,t.Checkboxes=a,t.ErrorSummary=l,t.Header=u,t.NotificationBanner=c,t.Radios=d,t.SkipLink=h,t.Tabs=p});
|