katalyst-govuk-formbuilder 1.2.2 → 1.3.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/assets/builds/katalyst/govuk/formbuilder.css +25 -21
- data/app/assets/{javascripts → builds}/katalyst/govuk/formbuilder.js +606 -203
- data/app/assets/builds/katalyst/govuk/formbuilder.min.js +1 -0
- data/app/assets/config/katalyst-govuk-formbuilder.js +2 -0
- data/app/assets/stylesheets/katalyst/govuk/components/richtextarea/_index.scss +48 -0
- data/app/assets/stylesheets/katalyst/govuk/components/richtextarea/_richtextarea.scss +2 -0
- data/app/assets/stylesheets/katalyst/govuk/formbuilder.scss +26 -0
- data/config/importmap.rb +5 -0
- data/lib/govuk_design_system_formbuilder/elements/check_box_field.rb +5 -5
- data/lib/govuk_design_system_formbuilder/elements/rich_text_area.rb +2 -1
- data/lib/katalyst/govuk/formbuilder/engine.rb +3 -8
- data/lib/katalyst/govuk/formbuilder/frontend.rb +2 -0
- data/lib/katalyst/govuk/formbuilder/version.rb +3 -1
- data/lib/katalyst/govuk/formbuilder.rb +2 -0
- metadata +8 -4
- data/app/assets/javascripts/katalyst/govuk/formbuilder.min.js +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
function t(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 e(){for(var t=function(t){var e={},n=function(t,o){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var r=t[i],a=o?o+"."+i:i;"object"==typeof r?n(r,a):e[a]=r}};return n(t),e},e={},n=0;n<arguments.length;n++){var o=t(arguments[n]);for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(e[i]=o[i])}return e}function n(t){if("string"!=typeof t)return t;var e=t.trim();return"true"===e||"false"!==e&&(e.length>0&&isFinite(e)?Number(e):t)}function o(t){var e={};for(var o in t)e[o]=n(t[o]);return e}(function(t){var e,n,o,i;"defineProperty"in Object&&function(){try{return Object.defineProperty({},"test",{value:42}),!0}catch(t){return!1}}()||(e=Object.defineProperty,n=Object.prototype.hasOwnProperty("__defineGetter__"),o="Getters & setters cannot be defined on this javascript engine",i="A property cannot both have accessors and be writable or have a value",Object.defineProperty=function(t,r,a){if(e&&(t===window||t===document||t===Element.prototype||t instanceof Element))return e(t,r,a);if(null===t||!(t instanceof Object||"object"==typeof t))throw new TypeError("Object.defineProperty called on non-object");if(!(a instanceof Object))throw new TypeError("Property description must be an object");var s=String(r),c="value"in a||"writable"in a,l="get"in a&&typeof a.get,u="set"in a&&typeof a.set;if(l){if("function"!==l)throw new TypeError("Getter must be a function");if(!n)throw new TypeError(o);if(c)throw new TypeError(i);Object.__defineGetter__.call(t,s,a.get)}else t[s]=a.value;if(u){if("function"!==u)throw new TypeError("Setter must be a function");if(!n)throw new TypeError(o);if(c)throw new TypeError(i);Object.__defineSetter__.call(t,s,a.set)}return"value"in a&&(t[s]=a.value),t})}).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,o=Element.prototype=n.appendChild(n.createElement("*")),i={},r=function(t,e){var n,o,a,s=t.childNodes||[],c=-1;if(1===t.nodeType&&t.constructor!==Element)for(n in t.constructor=Element,i)o=i[n],t[n]=o;for(;a=e&&s[++c];)r(a,e);return t},a=document.getElementsByTagName("*"),s=document.createElement,c=100;o.attachEvent("onpropertychange",(function(t){for(var e,n=t.propertyName,r=!i.hasOwnProperty(n),s=o[n],c=i[n],l=-1;e=a[++l];)1===e.nodeType&&(r||e[n]===c)&&(e[n]=s);i[n]=s})),o.constructor=Element,o.hasAttribute||(o.hasAttribute=function(t){return null!==this.getAttribute(t)}),l()||(document.onreadystatechange=l,t=setInterval(l,25)),document.createElement=function(t){var e=s(String(t).toLowerCase());return r(e)},document.removeChild(e)}else window.HTMLElement=window.Element;function l(){return c--||clearTimeout(t),!(!document.body||document.body.prototype||!/(complete|interactive)/.test(document.readyState))&&(r(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){(function(){if(!document.documentElement.dataset)return!1;var t=document.createElement("div");return t.setAttribute("data-a-b","c"),t.dataset&&"c"==t.dataset.aB})()||Object.defineProperty(Element.prototype,"dataset",{get:function(){for(var t=this.attributes,e={},n=0;n<t.length;n++){var o=t[n];if(o&&o.name&&/^data-\w[.\w-]*$/.test(o.name)){var i=o.name,r=o.value,a=i.substr(5).replace(/-./g,(function(t){return t.charAt(1).toUpperCase()}));"__defineGetter__"in Object.prototype&&"__defineSetter__"in Object.prototype?Object.defineProperty(e,a,{enumerable:!0,get:function(){return this.value}.bind({value:r||""}),set:function(t,e){void 0!==e?this.setAttribute(t,e):this.removeAttribute(t)}.bind(this,i)}):e[a]=r}}return e}})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){"trim"in String.prototype||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),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(t){(function(t){if(!("Event"in t))return!1;if("function"==typeof t.Event)return!0;try{return new Event("click"),!0}catch(t){return!1}})(this)||function(){var e={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 n=window.Event&&window.Event.prototype||null;window.Event=Window.prototype.Event=function(e,n){if(!e)throw new Error("Not enough arguments");var o;if("createEvent"in document){o=document.createEvent("Event");var i=!(!n||n.bubbles===t)&&n.bubbles,r=!(!n||n.cancelable===t)&&n.cancelable;return o.initEvent(e,i,r),o}return(o=document.createEventObject()).type=e,o.bubbles=!(!n||n.bubbles===t)&&n.bubbles,o.cancelable=!(!n||n.cancelable===t)&&n.cancelable,o},n&&Object.defineProperty(window.Event,"prototype",{configurable:!1,enumerable:!1,writable:!0,value:n}),"createEvent"in document||(window.addEventListener=Window.prototype.addEventListener=Document.prototype.addEventListener=Element.prototype.addEventListener=function(){var t=this,n=arguments[0],i=arguments[1];if(t===window&&n in e)throw new Error("In IE8 the event: "+n+" is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.");t._events||(t._events={}),t._events[n]||(t._events[n]=function(e){var n,i=t._events[e.type].list,r=i.slice(),a=-1,s=r.length;for(e.preventDefault=function(){!1!==e.cancelable&&(e.returnValue=!1)},e.stopPropagation=function(){e.cancelBubble=!0},e.stopImmediatePropagation=function(){e.cancelBubble=!0,e.cancelImmediate=!0},e.currentTarget=t,e.relatedTarget=e.fromElement||null,e.target=e.target||e.srcElement||t,e.timeStamp=(new Date).getTime(),e.clientX&&(e.pageX=e.clientX+document.documentElement.scrollLeft,e.pageY=e.clientY+document.documentElement.scrollTop);++a<s&&!e.cancelImmediate;)a in r&&-1!==o(i,n=r[a])&&"function"==typeof n&&n.call(t,e)},t._events[n].list=[],t.attachEvent&&t.attachEvent("on"+n,t._events[n])),t._events[n].list.push(i)},window.removeEventListener=Window.prototype.removeEventListener=Document.prototype.removeEventListener=Element.prototype.removeEventListener=function(){var t,e=this,n=arguments[0],i=arguments[1];e._events&&e._events[n]&&e._events[n].list&&-1!==(t=o(e._events[n].list,i))&&(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(o){t.target=e;do{t.currentTarget=e,"_events"in 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}while(e&&!t.cancelBubble)}return!0},document.attachEvent("onreadystatechange",(function(){"complete"===document.readyState&&document.dispatchEvent(new Event("DOMContentLoaded",{bubbles:!0}))})))}function o(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(t){"bind"in Function.prototype||Object.defineProperty(Function.prototype,"bind",{value:function(t){var e,n=Array,o=Object,i=o.prototype,r=n.prototype,a=function(){},s=i.toString,c="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,l=Function.prototype.toString;e=function(t){if("function"!=typeof t)return!1;if(c)return function(t){try{return l.call(t),!0}catch(t){return!1}}(t);var e=s.call(t);return"[object Function]"===e||"[object GeneratorFunction]"===e};var u=r.slice,d=r.concat,p=r.push,h=Math.max,f=this;if(!e(f))throw new TypeError("Function.prototype.bind called on incompatible "+f);for(var m,v=u.call(arguments,1),b=h(0,f.length-v.length),y=[],g=0;g<b;g++)p.call(y,"$"+g);return m=Function("binder","return function ("+y.join(",")+"){ return binder.apply(this, arguments); }")((function(){if(this instanceof m){var e=f.apply(this,d.call(v,u.call(arguments)));return o(e)===e?e:this}return f.apply(t,d.call(v,u.call(arguments)))})),f.prototype&&(a.prototype=f.prototype,m.prototype=new a,a.prototype=null),m}})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{});function i(t,n){if(!t)return this;this.$module=t,this.debounceFormSubmitTimer=null;this.config=e({preventDoubleClick:!1},n||{},o(t.dataset))}function r(t,e){var n=t.closest("["+e+"]");if(n)return n.getAttribute(e)}function a(t,e){this.translations=t||{},this.locale=e&&e.locale||document.documentElement.lang||"en"}i.prototype.init=function(){this.$module&&(this.$module.addEventListener("keydown",this.handleKeyDown),this.$module.addEventListener("click",this.debounce.bind(this)))},i.prototype.handleKeyDown=function(t){var e=t.target;"button"===e.getAttribute("role")&&32===t.keyCode&&(t.preventDefault(),e.click())},i.prototype.debounce=function(t){if(this.config.preventDoubleClick)return this.debounceFormSubmitTimer?(t.preventDefault(),!1):void(this.debounceFormSubmitTimer=setTimeout(function(){this.debounceFormSubmitTimer=null}.bind(this),1e3))},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,n=(e.document||e.ownerDocument).querySelectorAll(t),o=0;n[o]&&n[o]!==e;)++o;return!!n[o]})}.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||{}),a.prototype.t=function(t,e){if(!t)throw new Error("i18n: lookup key missing");if(e&&void 0!==e.count&&(t=t+"."+this.getPluralSuffix(t,e.count)),t in this.translations){var n=this.translations[t];if(n.match(/%{(.\S+)}/)){if(!e)throw new Error("i18n: cannot replace placeholders in string if no option data provided");return this.replacePlaceholders(n,e)}return n}return t},a.prototype.replacePlaceholders=function(t,e){var n;return this.hasIntlNumberFormatSupport()&&(n=new Intl.NumberFormat(this.locale)),t.replace(/%{(.\S+)}/g,(function(t,o){if(Object.prototype.hasOwnProperty.call(e,o)){var i=e[o];return!1===i?"":"number"==typeof i&&n?n.format(i):i}throw new Error("i18n: no data found to replace "+t+" placeholder in string")}))},a.prototype.hasIntlPluralRulesSupport=function(){return Boolean(window.Intl&&"PluralRules"in window.Intl&&Intl.PluralRules.supportedLocalesOf(this.locale).length)},a.prototype.hasIntlNumberFormatSupport=function(){return Boolean(window.Intl&&"NumberFormat"in window.Intl&&Intl.NumberFormat.supportedLocalesOf(this.locale).length)},a.prototype.getPluralSuffix=function(t,e){if(e=Number(e),!isFinite(e))return"other";var n;if(t+"."+(n=this.hasIntlPluralRulesSupport()?new Intl.PluralRules(this.locale).select(e):this.selectPluralFormUsingFallbackRules(e))in this.translations)return n;if(t+".other"in this.translations)return console&&"warn"in console&&console.warn('i18n: Missing plural form ".'+n+'" for "'+this.locale+'" locale. Falling back to ".other".'),"other";throw new Error('i18n: Plural form ".other" is required for "'+this.locale+'" locale')},a.prototype.selectPluralFormUsingFallbackRules=function(t){t=Math.abs(Math.floor(t));var e=this.getPluralRulesForLocale();return e?a.pluralRules[e](t):"other"},a.prototype.getPluralRulesForLocale=function(){var t=this.locale,e=t.split("-")[0];for(var n in a.pluralRulesMap)if(Object.prototype.hasOwnProperty.call(a.pluralRulesMap,n))for(var o=a.pluralRulesMap[n],i=0;i<o.length;i++)if(o[i]===t||o[i]===e)return n},a.pluralRulesMap={arabic:["ar"],chinese:["my","zh","id","ja","jv","ko","ms","th","vi"],french:["hy","bn","fr","gu","hi","fa","pa","zu"],german:["af","sq","az","eu","bg","ca","da","nl","en","et","fi","ka","de","el","hu","lb","no","so","sw","sv","ta","te","tr","ur"],irish:["ga"],russian:["ru","uk"],scottish:["gd"],spanish:["pt-PT","it","es"],welsh:["cy"]},a.pluralRules={arabic:function(t){return 0===t?"zero":1===t?"one":2===t?"two":t%100>=3&&t%100<=10?"few":t%100>=11&&t%100<=99?"many":"other"},chinese:function(){return"other"},french:function(t){return 0===t||1===t?"one":"other"},german:function(t){return 1===t?"one":"other"},irish:function(t){return 1===t?"one":2===t?"two":t>=3&&t<=6?"few":t>=7&&t<=10?"many":"other"},russian:function(t){var e=t%100,n=e%10;return 1===n&&11!==e?"one":n>=2&&n<=4&&!(e>=12&&e<=14)?"few":0===n||n>=5&&n<=9||e>=11&&e<=14?"many":"other"},scottish:function(t){return 1===t||11===t?"one":2===t||12===t?"two":t>=3&&t<=10||t>=13&&t<=19?"few":"other"},spanish:function(t){return 1===t?"one":t%1e6==0&&0!==t?"many":"other"},welsh:function(t){return 0===t?"zero":1===t?"one":2===t?"two":3===t?"few":6===t?"many":"other"}},function(t){"Date"in self&&"now"in self.Date&&"getTime"in self.Date.prototype||(Date.now=function(){return(new Date).getTime()})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){var e;"DOMTokenList"in this&&(!("classList"in(e=document.createElement("x")))||!e.classList.toggle("x",!1)&&!e.className)||function(e){var n;"DOMTokenList"in e&&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 e=!0,n=function(t,n,o,i){Object.defineProperty?Object.defineProperty(t,n,{configurable:!1===e||!!i,get:o}):t.__defineGetter__(n,o)};try{n({},"support")}catch(t){e=!1}return function(e,o){var i=this,r=[],a={},s=0,c=0,l=function(t){n(i,t,(function(){return d(),r[t]}),!1)},u=function(){if(s>=c)for(;c<s;++c)l(c)},d=function(){var t,n,i=arguments,c=/\s+/;if(i.length)for(n=0;n<i.length;++n)if(c.test(i[n]))throw(t=new SyntaxError('String "'+i[n]+'" contains an invalid character')).code=5,t.name="InvalidCharacterError",t;for(""===(r="object"==typeof e[o]?(""+e[o].baseVal).replace(/^\s+|\s+$/g,"").split(c):(""+e[o]).replace(/^\s+|\s+$/g,"").split(c))[0]&&(r=[]),a={},n=0;n<r.length;++n)a[r[n]]=!0;s=r.length,u()};return d(),n(i,"length",(function(){return d(),s})),i.toLocaleString=i.toString=function(){return d(),r.join(" ")},i.item=function(t){return d(),r[t]},i.contains=function(t){return d(),!!a[t]},i.add=function(){d.apply(i,t=arguments);for(var t,n,c=0,l=t.length;c<l;++c)a[n=t[c]]||(r.push(n),a[n]=!0);s!==r.length&&(s=r.length>>>0,"object"==typeof e[o]?e[o].baseVal=r.join(" "):e[o]=r.join(" "),u())},i.remove=function(){d.apply(i,t=arguments);for(var t,n={},c=0,l=[];c<t.length;++c)n[t[c]]=!0,delete a[t[c]];for(c=0;c<r.length;++c)n[r[c]]||l.push(r[c]);r=l,s=l.length>>>0,"object"==typeof e[o]?e[o].baseVal=r.join(" "):e[o]=r.join(" "),u()},i.toggle=function(e,n){return d.apply(i,[e]),t!==n?n?(i.add(e),!0):(i.remove(e),!1):a[e]?(i.remove(e),!1):(i.add(e),!0)},i}}()),"classList"in(n=document.createElement("span"))&&(n.classList.toggle("x",!1),n.classList.contains("x")&&(n.classList.constructor.prototype.toggle=function(e){var n=arguments[1];if(n===t){var o=!this.contains(e);return this[o?"add":"remove"](e),o}return this[(n=!!n)?"add":"remove"](e),n})),function(){var t=document.createElement("span");if("classList"in t&&(t.classList.add("a","b"),!t.classList.contains("b"))){var e=t.classList.constructor.prototype.add;t.classList.constructor.prototype.add=function(){for(var t=arguments,n=arguments.length,o=0;o<n;o++)e.call(this,t[o])}}}(),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 e=t.classList.constructor.prototype.remove;t.classList.constructor.prototype.remove=function(){for(var t=arguments,n=arguments.length,o=0;o<n;o++)e.call(this,t[o])}}}()}(this)}.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 e=!0,n=function(t,n,o,i){Object.defineProperty?Object.defineProperty(t,n,{configurable:!1===e||!!i,get:o}):t.__defineGetter__(n,o)};try{n({},"support")}catch(t){e=!1}var o=function(t,i,r){n(t.prototype,i,(function(){var t,a=this,s="__defineGetter__DEFINE_PROPERTY"+i;if(a[s])return t;if(a[s]=!0,!1===e){for(var c,l=o.mirror||document.createElement("div"),u=l.childNodes,d=u.length,p=0;p<d;++p)if(u[p]._R===a){c=u[p];break}c||(c=l.appendChild(document.createElement("div"))),t=DOMTokenList.call(c,a,r)}else t=new DOMTokenList(a,r);return n(a,i,(function(){return t})),delete a[s],t}),!0)};o(t.Element,"classList","className"),o(t.HTMLElement,"classList","className"),o(t.HTMLLinkElement,"relList","rel"),o(t.HTMLAnchorElement,"relList","rel"),o(t.HTMLAreaElement,"relList","rel")}(this)}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{});var s={charactersUnderLimit:{one:"You have %{count} character remaining",other:"You have %{count} characters remaining"},charactersAtLimit:"You have 0 characters remaining",charactersOverLimit:{one:"You have %{count} character too many",other:"You have %{count} characters too many"},wordsUnderLimit:{one:"You have %{count} word remaining",other:"You have %{count} words remaining"},wordsAtLimit:"You have 0 words remaining",wordsOverLimit:{one:"You have %{count} word too many",other:"You have %{count} words too many"},textareaDescription:{other:""}};function c(t,n){if(!t)return this;var i={threshold:0,i18n:s},c=o(t.dataset),l={};if(("maxwords"in c||"maxlength"in c)&&(l={maxlength:!1,maxwords:!1}),this.config=e(i,n||{},l,c),this.i18n=new a(function(t,e){if(!t||"object"!=typeof t)throw new Error('Provide a `configObject` of type "object".');if(!e||"string"!=typeof e)throw new Error('Provide a `namespace` of type "string" to filter the `configObject` by.');var n={};for(var o in t){var i=o.split(".");Object.prototype.hasOwnProperty.call(t,o)&&i[0]===e&&(i.length>1&&i.shift(),n[i.join(".")]=t[o])}return n}(this.config,"i18n"),{locale:r(t,"lang")}),this.config.maxwords)this.maxLength=this.config.maxwords;else{if(!this.config.maxlength)return;this.maxLength=this.config.maxlength}this.$module=t,this.$textarea=t.querySelector(".govuk-js-character-count"),this.$visibleCountMessage=null,this.$screenReaderCountMessage=null,this.lastInputTimestamp=null}function l(t){this.$module=t,this.$inputs=t.querySelectorAll('input[type="checkbox"]')}function u(t,n){if(!t)return this;this.$module=t;this.config=e({disableAutoFocus:!1},n||{},o(t.dataset))}function d(t){this.$module=t,this.$inputs=t.querySelectorAll('input[type="radio"]')}function p(e){const n=void 0!==(e=void 0!==e?e:{}).scope?e.scope:document;t(n.querySelectorAll('[data-module="govuk-button"]'),(function(t){new i(t).init()}));t(n.querySelectorAll('[data-module="govuk-character-count"]'),(function(t){new c(t).init()}));t(n.querySelectorAll('[data-module="govuk-checkboxes"]'),(function(t){new l(t).init()}));new u(n.querySelector('[data-module="govuk-error-summary"]')).init();t(n.querySelectorAll('[data-module="govuk-radios"]'),(function(t){new d(t).init()}))}c.prototype.init=function(){if(this.$textarea){var t=this.$textarea,e=document.getElementById(t.id+"-info");e.innerText.match(/^\s*$/)&&(e.innerText=this.i18n.t("textareaDescription",{count:this.maxLength})),t.insertAdjacentElement("afterend",e);var n=document.createElement("div");n.className="govuk-character-count__sr-status govuk-visually-hidden",n.setAttribute("aria-live","polite"),this.$screenReaderCountMessage=n,e.insertAdjacentElement("afterend",n);var o=document.createElement("div");o.className=e.className,o.classList.add("govuk-character-count__status"),o.setAttribute("aria-hidden","true"),this.$visibleCountMessage=o,e.insertAdjacentElement("afterend",o),e.classList.add("govuk-visually-hidden"),t.removeAttribute("maxlength"),this.bindChangeEvents(),"onpageshow"in window?window.addEventListener("pageshow",this.updateCountMessage.bind(this)):window.addEventListener("DOMContentLoaded",this.updateCountMessage.bind(this)),this.updateCountMessage()}},c.prototype.bindChangeEvents=function(){var t=this.$textarea;t.addEventListener("keyup",this.handleKeyUp.bind(this)),t.addEventListener("focus",this.handleFocus.bind(this)),t.addEventListener("blur",this.handleBlur.bind(this))},c.prototype.handleKeyUp=function(){this.updateVisibleCountMessage(),this.lastInputTimestamp=Date.now()},c.prototype.handleFocus=function(){this.valueChecker=setInterval(function(){(!this.lastInputTimestamp||Date.now()-500>=this.lastInputTimestamp)&&this.updateIfValueChanged()}.bind(this),1e3)},c.prototype.handleBlur=function(){clearInterval(this.valueChecker)},c.prototype.updateIfValueChanged=function(){this.$textarea.oldValue||(this.$textarea.oldValue=""),this.$textarea.value!==this.$textarea.oldValue&&(this.$textarea.oldValue=this.$textarea.value,this.updateCountMessage())},c.prototype.updateCountMessage=function(){this.updateVisibleCountMessage(),this.updateScreenReaderCountMessage()},c.prototype.updateVisibleCountMessage=function(){var t=this.$textarea,e=this.$visibleCountMessage,n=this.maxLength-this.count(t.value);this.isOverThreshold()?e.classList.remove("govuk-character-count__message--disabled"):e.classList.add("govuk-character-count__message--disabled"),n<0?(t.classList.add("govuk-textarea--error"),e.classList.remove("govuk-hint"),e.classList.add("govuk-error-message")):(t.classList.remove("govuk-textarea--error"),e.classList.remove("govuk-error-message"),e.classList.add("govuk-hint")),e.innerText=this.getCountMessage()},c.prototype.updateScreenReaderCountMessage=function(){var t=this.$screenReaderCountMessage;this.isOverThreshold()?t.removeAttribute("aria-hidden"):t.setAttribute("aria-hidden",!0),t.innerText=this.getCountMessage()},c.prototype.count=function(t){return this.config.maxwords?(t.match(/\S+/g)||[]).length:t.length},c.prototype.getCountMessage=function(){var t=this.maxLength-this.count(this.$textarea.value),e=this.config.maxwords?"words":"characters";return this.formatCountMessage(t,e)},c.prototype.formatCountMessage=function(t,e){if(0===t)return this.i18n.t(e+"AtLimit");var n=t<0?"OverLimit":"UnderLimit";return this.i18n.t(e+n,{count:Math.abs(t)})},c.prototype.isOverThreshold=function(){if(!this.config.threshold)return!0;var t=this.$textarea,e=this.count(t.value);return this.maxLength*this.config.threshold/100<=e},l.prototype.init=function(){var e=this.$module;t(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(),e.addEventListener("click",this.handleClick.bind(this))},l.prototype.syncAllConditionalReveals=function(){t(this.$inputs,this.syncConditionalRevealWithInputState.bind(this))},l.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)}},l.prototype.unCheckAllInputsExcept=function(e){t(document.querySelectorAll('input[type="checkbox"][name="'+e.name+'"]'),function(t){e.form===t.form&&t!==e&&(t.checked=!1,this.syncConditionalRevealWithInputState(t))}.bind(this))},l.prototype.unCheckExclusiveInputs=function(e){t(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))},l.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)))},u.prototype.init=function(){var t=this.$module;t&&(this.setFocus(),t.addEventListener("click",this.handleClick.bind(this)))},u.prototype.setFocus=function(){var t=this.$module;this.config.disableAutoFocus||(t.setAttribute("tabindex","-1"),t.addEventListener("blur",(function(){t.removeAttribute("tabindex")})),t.focus())},u.prototype.handleClick=function(t){var e=t.target;this.focusTarget(e)&&t.preventDefault()},u.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)},u.prototype.getFragmentFromUrl=function(t){return-1!==t.indexOf("#")&&t.split("#").pop()},u.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,r=t.getBoundingClientRect();if(r.height&&window.innerHeight)if(r.top+r.height-i<window.innerHeight/2)return o}}return document.querySelector("label[for='"+t.getAttribute("id")+"']")||t.closest("label")},d.prototype.init=function(){var e=this.$module;t(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(),e.addEventListener("click",this.handleClick.bind(this))},d.prototype.syncAllConditionalReveals=function(){t(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(e){var n=e.target;"radio"===n.type&&t(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))};export{i as Button,c as CharacterCount,l as Checkboxes,u as ErrorSummary,d as Radios,p as initAll};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
@import "govuk-frontend/govuk/components/error-message/index";
|
2
|
+
@import "govuk-frontend/govuk/components/hint/index";
|
3
|
+
@import "govuk-frontend/govuk/components/label/index";
|
4
|
+
|
5
|
+
// Based on components/textarea
|
6
|
+
@include govuk-exports("govuk/component/richtextarea") {
|
7
|
+
.govuk-richtextarea {
|
8
|
+
@include govuk-font($size: 19, $line-height: 1.25);
|
9
|
+
|
10
|
+
box-sizing: border-box; // should this be global?
|
11
|
+
display: block;
|
12
|
+
width: 100%;
|
13
|
+
// min-height inherited from trix-editor styles
|
14
|
+
@include govuk-responsive-margin(6, "bottom");
|
15
|
+
padding: govuk-spacing(1);
|
16
|
+
|
17
|
+
resize: vertical;
|
18
|
+
|
19
|
+
border: $govuk-border-width-form-element solid $govuk-input-border-colour;
|
20
|
+
border-radius: 0;
|
21
|
+
|
22
|
+
-webkit-appearance: none;
|
23
|
+
|
24
|
+
&:focus {
|
25
|
+
outline: $govuk-focus-width solid $govuk-focus-colour;
|
26
|
+
// Ensure outline appears outside of the element
|
27
|
+
outline-offset: 0;
|
28
|
+
// Double the border by adding its width again. Use `box-shadow` to do
|
29
|
+
// this instead of changing `border-width` (which changes element size) and
|
30
|
+
// since `outline` is already used for the yellow focus state.
|
31
|
+
box-shadow: inset 0 0 0 $govuk-border-width-form-element;
|
32
|
+
|
33
|
+
@include govuk-if-ie8 {
|
34
|
+
// IE8 doesn't support `box-shadow` so double the border with
|
35
|
+
// `border-width`.
|
36
|
+
border-width: $govuk-border-width-form-element * 2;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
.govuk-richtextarea--error {
|
42
|
+
border-color: $govuk-error-colour;
|
43
|
+
|
44
|
+
&:focus {
|
45
|
+
border-color: $govuk-input-border-colour;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$govuk-include-default-font-face: false;
|
2
|
+
$govuk-font-family: "Open Sans", sans-serif;
|
3
|
+
|
4
|
+
@import "govuk-frontend/govuk/base";
|
5
|
+
|
6
|
+
@import "govuk-frontend/govuk/core/all";
|
7
|
+
@import "govuk-frontend/govuk/objects/all";
|
8
|
+
|
9
|
+
@import "govuk-frontend/govuk/components/button";
|
10
|
+
@import "govuk-frontend/govuk/components/checkboxes";
|
11
|
+
@import "govuk-frontend/govuk/components/date-input";
|
12
|
+
@import "govuk-frontend/govuk/components/error-message";
|
13
|
+
@import "govuk-frontend/govuk/components/error-summary";
|
14
|
+
@import "govuk-frontend/govuk/components/fieldset";
|
15
|
+
@import "govuk-frontend/govuk/components/file-upload";
|
16
|
+
@import "govuk-frontend/govuk/components/hint";
|
17
|
+
@import "govuk-frontend/govuk/components/input";
|
18
|
+
@import "govuk-frontend/govuk/components/label";
|
19
|
+
@import "govuk-frontend/govuk/components/radios";
|
20
|
+
@import "govuk-frontend/govuk/components/select";
|
21
|
+
@import "govuk-frontend/govuk/components/textarea";
|
22
|
+
|
23
|
+
@import "govuk-frontend/govuk/utilities/all";
|
24
|
+
@import "govuk-frontend/govuk/overrides/all";
|
25
|
+
|
26
|
+
@import "components/richtextarea";
|
data/config/importmap.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
|
3
4
|
pin "@katalyst/govuk-formbuilder", to: "katalyst/govuk/formbuilder.js"
|
5
|
+
|
6
|
+
pin_all_from Katalyst::GOVUK::Formbuilder::Engine.root.join("app/assets/javascripts"),
|
7
|
+
# preload in tests so that we don't start clicking before controllers load
|
8
|
+
preload: Rails.env.test?
|
@@ -17,7 +17,7 @@ module GOVUKDesignSystemFormBuilder
|
|
17
17
|
# @option label text [String] the label text
|
18
18
|
# @option label size [String] the size of the label font, can be +xl+, +l+, +m+, +s+ or nil
|
19
19
|
# @option label tag [Symbol,String] the label's wrapper tag, intended to allow labels to act as page headings
|
20
|
-
# @option label hidden [Boolean] control the visibility of the label. Hidden labels will
|
20
|
+
# @option label hidden [Boolean] control the visibility of the label. Hidden labels will be read by screenreaders
|
21
21
|
# @option label kwargs [Hash] additional arguments are applied as attributes on the +label+ element
|
22
22
|
# @option kwargs [Hash] kwargs additional arguments are applied as attributes to the +input+ element
|
23
23
|
# @param block [Block] any HTML passed in will form the contents of the fieldset
|
@@ -31,11 +31,11 @@ module GOVUKDesignSystemFormBuilder
|
|
31
31
|
#
|
32
32
|
def govuk_check_box_field(attribute_name, value = 1, unchecked_value = 0,
|
33
33
|
small: false, hint: {}, label: {}, link_errors: false, **kwargs, &block)
|
34
|
-
govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small:
|
34
|
+
govuk_check_boxes_fieldset(attribute_name, legend: nil, multiple: false, small:) do
|
35
35
|
govuk_check_box(attribute_name, value, unchecked_value,
|
36
|
-
hint
|
37
|
-
label
|
38
|
-
link_errors
|
36
|
+
hint:,
|
37
|
+
label:,
|
38
|
+
link_errors:,
|
39
39
|
multiple: false,
|
40
40
|
exclusive: false,
|
41
41
|
**kwargs, &block)
|
@@ -100,7 +100,8 @@ module GOVUKDesignSystemFormBuilder
|
|
100
100
|
# }
|
101
101
|
#
|
102
102
|
def govuk_rich_text_area(attribute_name, hint: {}, label: {}, caption: {}, form_group: {}, **kwargs, &block)
|
103
|
-
Elements::RichTextArea.new(self, object_name, attribute_name,
|
103
|
+
Elements::RichTextArea.new(self, object_name, attribute_name,
|
104
|
+
hint:, label:, caption:, form_group:, **kwargs, &block).html
|
104
105
|
end
|
105
106
|
end
|
106
107
|
end
|
@@ -1,19 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Katalyst
|
2
4
|
module GOVUK
|
3
5
|
module Formbuilder
|
4
6
|
# Engine is responsible for adding assets to load path
|
5
7
|
class Engine < ::Rails::Engine
|
6
|
-
PRECOMPILE_ASSETS = %w(
|
7
|
-
katalyst/govuk/formbuilder.js
|
8
|
-
katalyst/govuk/formbuilder.min.js
|
9
|
-
katalyst/govuk/formbuilder.min.css
|
10
|
-
katalyst/govuk/formbuilder.css
|
11
|
-
)
|
12
|
-
|
13
8
|
initializer "katalyst-govuk-formbuilder.assets" do
|
14
9
|
config.after_initialize do |app|
|
15
10
|
if app.config.respond_to?(:assets)
|
16
|
-
app.config.assets.precompile +=
|
11
|
+
app.config.assets.precompile += %w(katalyst-govuk-formbuilder.js)
|
17
12
|
end
|
18
13
|
end
|
19
14
|
end
|
@@ -4,6 +4,7 @@ module Katalyst
|
|
4
4
|
module GOVUK
|
5
5
|
module Formbuilder
|
6
6
|
module Frontend
|
7
|
+
# rubocop:disable Rails/OutputSafety
|
7
8
|
def govuk_formbuilder_init
|
8
9
|
tag.script type: "module", nonce: request.content_security_policy_nonce do
|
9
10
|
<<~JS.html_safe
|
@@ -13,6 +14,7 @@ module Katalyst
|
|
13
14
|
JS
|
14
15
|
end
|
15
16
|
end
|
17
|
+
# rubocop:enable Rails/OutputSafety
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-govuk-formbuilder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_design_system_formbuilder
|
@@ -34,9 +34,13 @@ files:
|
|
34
34
|
- LICENSE.txt
|
35
35
|
- README.md
|
36
36
|
- app/assets/builds/katalyst/govuk/formbuilder.css
|
37
|
+
- app/assets/builds/katalyst/govuk/formbuilder.js
|
37
38
|
- app/assets/builds/katalyst/govuk/formbuilder.min.css
|
38
|
-
- app/assets/
|
39
|
-
- app/assets/
|
39
|
+
- app/assets/builds/katalyst/govuk/formbuilder.min.js
|
40
|
+
- app/assets/config/katalyst-govuk-formbuilder.js
|
41
|
+
- app/assets/stylesheets/katalyst/govuk/components/richtextarea/_index.scss
|
42
|
+
- app/assets/stylesheets/katalyst/govuk/components/richtextarea/_richtextarea.scss
|
43
|
+
- app/assets/stylesheets/katalyst/govuk/formbuilder.scss
|
40
44
|
- config/importmap.rb
|
41
45
|
- lib/govuk_design_system_formbuilder/elements/check_box_field.rb
|
42
46
|
- lib/govuk_design_system_formbuilder/elements/rich_text_area.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
function t(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(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(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,o=Element.prototype=n.appendChild(n.createElement("*")),i={},r=function(t,e){var n,o,a,s=t.childNodes||[],c=-1;if(1===t.nodeType&&t.constructor!==Element)for(n in t.constructor=Element,i)o=i[n],t[n]=o;for(;a=e&&s[++c];)r(a,e);return t},a=document.getElementsByTagName("*"),s=document.createElement,c=100;o.attachEvent("onpropertychange",(function(t){for(var e,n=t.propertyName,r=!i.hasOwnProperty(n),s=o[n],c=i[n],l=-1;e=a[++l];)1===e.nodeType&&(r||e[n]===c)&&(e[n]=s);i[n]=s})),o.constructor=Element,o.hasAttribute||(o.hasAttribute=function(t){return null!==this.getAttribute(t)}),l()||(document.onreadystatechange=l,t=setInterval(l,25)),document.createElement=function(t){var e=s(String(t).toLowerCase());return r(e)},document.removeChild(e)}else window.HTMLElement=window.Element;function l(){return c--||clearTimeout(t),!(!document.body||document.body.prototype||!/(complete|interactive)/.test(document.readyState))&&(r(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,n,o,i;"defineProperty"in Object&&function(){try{return Object.defineProperty({},"test",{value:42}),!0}catch(t){return!1}}()||(e=Object.defineProperty,n=Object.prototype.hasOwnProperty("__defineGetter__"),o="Getters & setters cannot be defined on this javascript engine",i="A property cannot both have accessors and be writable or have a value",Object.defineProperty=function(t,r,a){if(e&&(t===window||t===document||t===Element.prototype||t instanceof Element))return e(t,r,a);if(null===t||!(t instanceof Object||"object"==typeof t))throw new TypeError("Object.defineProperty called on non-object");if(!(a instanceof Object))throw new TypeError("Property description must be an object");var s=String(r),c="value"in a||"writable"in a,l="get"in a&&typeof a.get,u="set"in a&&typeof a.set;if(l){if("function"!==l)throw new TypeError("Getter must be a function");if(!n)throw new TypeError(o);if(c)throw new TypeError(i);Object.__defineGetter__.call(t,s,a.get)}else t[s]=a.value;if(u){if("function"!==u)throw new TypeError("Setter must be a function");if(!n)throw new TypeError(o);if(c)throw new TypeError(i);Object.__defineSetter__.call(t,s,a.set)}return"value"in a&&(t[s]=a.value),t})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),function(t){(function(t){if(!("Event"in t))return!1;if("function"==typeof t.Event)return!0;try{return new Event("click"),!0}catch(t){return!1}})(this)||function(){var e={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 n=window.Event&&window.Event.prototype||null;window.Event=Window.prototype.Event=function(e,n){if(!e)throw new Error("Not enough arguments");var o;if("createEvent"in document){o=document.createEvent("Event");var i=!(!n||n.bubbles===t)&&n.bubbles,r=!(!n||n.cancelable===t)&&n.cancelable;return o.initEvent(e,i,r),o}return(o=document.createEventObject()).type=e,o.bubbles=!(!n||n.bubbles===t)&&n.bubbles,o.cancelable=!(!n||n.cancelable===t)&&n.cancelable,o},n&&Object.defineProperty(window.Event,"prototype",{configurable:!1,enumerable:!1,writable:!0,value:n}),"createEvent"in document||(window.addEventListener=Window.prototype.addEventListener=Document.prototype.addEventListener=Element.prototype.addEventListener=function(){var t=this,n=arguments[0],i=arguments[1];if(t===window&&n in e)throw new Error("In IE8 the event: "+n+" is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.");t._events||(t._events={}),t._events[n]||(t._events[n]=function(e){var n,i=t._events[e.type].list,r=i.slice(),a=-1,s=r.length;for(e.preventDefault=function(){!1!==e.cancelable&&(e.returnValue=!1)},e.stopPropagation=function(){e.cancelBubble=!0},e.stopImmediatePropagation=function(){e.cancelBubble=!0,e.cancelImmediate=!0},e.currentTarget=t,e.relatedTarget=e.fromElement||null,e.target=e.target||e.srcElement||t,e.timeStamp=(new Date).getTime(),e.clientX&&(e.pageX=e.clientX+document.documentElement.scrollLeft,e.pageY=e.clientY+document.documentElement.scrollTop);++a<s&&!e.cancelImmediate;)a in r&&-1!==o(i,n=r[a])&&"function"==typeof n&&n.call(t,e)},t._events[n].list=[],t.attachEvent&&t.attachEvent("on"+n,t._events[n])),t._events[n].list.push(i)},window.removeEventListener=Window.prototype.removeEventListener=Document.prototype.removeEventListener=Element.prototype.removeEventListener=function(){var t,e=this,n=arguments[0],i=arguments[1];e._events&&e._events[n]&&e._events[n].list&&-1!==(t=o(e._events[n].list,i))&&(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(o){t.target=e;do{t.currentTarget=e,"_events"in 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}while(e&&!t.cancelBubble)}return!0},document.attachEvent("onreadystatechange",(function(){"complete"===document.readyState&&document.dispatchEvent(new Event("DOMContentLoaded",{bubbles:!0}))})))}function o(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(t){"bind"in Function.prototype||Object.defineProperty(Function.prototype,"bind",{value:function(t){var e,n=Array,o=Object,i=o.prototype,r=n.prototype,a=function(){},s=i.toString,c="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,l=Function.prototype.toString,u=function(t){try{return l.call(t),!0}catch(t){return!1}},d="[object Function]",p="[object GeneratorFunction]";e=function(t){if("function"!=typeof t)return!1;if(c)return u(t);var e=s.call(t);return e===d||e===p};var h=r.slice,f=r.concat,m=r.push,v=Math.max,b=this;if(!e(b))throw new TypeError("Function.prototype.bind called on incompatible "+b);for(var y,g=h.call(arguments,1),w=function(){if(this instanceof y){var e=b.apply(this,f.call(g,h.call(arguments)));return o(e)===e?e:this}return b.apply(t,f.call(g,h.call(arguments)))},E=v(0,b.length-g.length),L=[],k=0;k<E;k++)m.call(L,"$"+k);return y=Function("binder","return function ("+L.join(",")+"){ return binder.apply(this, arguments); }")(w),b.prototype&&(a.prototype=b.prototype,y.prototype=new a,a.prototype=null),y}})}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{});function e(t){this.$module=t,this.debounceFormSubmitTimer=null}function n(t){this.$module=t,this.$textarea=t.querySelector(".govuk-js-character-count"),this.$visibleCountMessage=null,this.$screenReaderCountMessage=null,this.lastInputTimestamp=null}function o(t){this.$module=t,this.$inputs=t.querySelectorAll('input[type="checkbox"]')}function i(t){this.$module=t}function r(t){this.$module=t,this.$inputs=t.querySelectorAll('input[type="radio"]')}function a(a){const s=void 0!==(a=void 0!==a?a:{}).scope?a.scope:document;t(s.querySelectorAll('[data-module="govuk-button"]'),(function(t){new e(t).init()}));t(s.querySelectorAll('[data-module="govuk-character-count"]'),(function(t){new n(t).init()}));t(s.querySelectorAll('[data-module="govuk-checkboxes"]'),(function(t){new o(t).init()}));new i(s.querySelector('[data-module="govuk-error-summary"]')).init();t(s.querySelectorAll('[data-module="govuk-radios"]'),(function(t){new r(t).init()}))}e.prototype.handleKeyDown=function(t){var e=t.target;"button"===e.getAttribute("role")&&32===t.keyCode&&(t.preventDefault(),e.click())},e.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))},e.prototype.init=function(){this.$module.addEventListener("keydown",this.handleKeyDown),this.$module.addEventListener("click",this.debounce)},function(t){var e;"DOMTokenList"in this&&(!("classList"in(e=document.createElement("x")))||!e.classList.toggle("x",!1)&&!e.className)||function(e){var n;"DOMTokenList"in e&&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 e=!0,n=function(t,n,o,i){Object.defineProperty?Object.defineProperty(t,n,{configurable:!1===e||!!i,get:o}):t.__defineGetter__(n,o)};try{n({},"support")}catch(t){e=!1}return function(e,o){var i=this,r=[],a={},s=0,c=0,l=function(t){n(i,t,(function(){return d(),r[t]}),!1)},u=function(){if(s>=c)for(;c<s;++c)l(c)},d=function(){var t,n,i=arguments,c=/\s+/;if(i.length)for(n=0;n<i.length;++n)if(c.test(i[n]))throw(t=new SyntaxError('String "'+i[n]+'" contains an invalid character')).code=5,t.name="InvalidCharacterError",t;for(""===(r="object"==typeof e[o]?(""+e[o].baseVal).replace(/^\s+|\s+$/g,"").split(c):(""+e[o]).replace(/^\s+|\s+$/g,"").split(c))[0]&&(r=[]),a={},n=0;n<r.length;++n)a[r[n]]=!0;s=r.length,u()};return d(),n(i,"length",(function(){return d(),s})),i.toLocaleString=i.toString=function(){return d(),r.join(" ")},i.item=function(t){return d(),r[t]},i.contains=function(t){return d(),!!a[t]},i.add=function(){d.apply(i,t=arguments);for(var t,n,c=0,l=t.length;c<l;++c)n=t[c],a[n]||(r.push(n),a[n]=!0);s!==r.length&&(s=r.length>>>0,"object"==typeof e[o]?e[o].baseVal=r.join(" "):e[o]=r.join(" "),u())},i.remove=function(){d.apply(i,t=arguments);for(var t,n={},c=0,l=[];c<t.length;++c)n[t[c]]=!0,delete a[t[c]];for(c=0;c<r.length;++c)n[r[c]]||l.push(r[c]);r=l,s=l.length>>>0,"object"==typeof e[o]?e[o].baseVal=r.join(" "):e[o]=r.join(" "),u()},i.toggle=function(e,n){return d.apply(i,[e]),t!==n?n?(i.add(e),!0):(i.remove(e),!1):a[e]?(i.remove(e),!1):(i.add(e),!0)},i}}()),"classList"in(n=document.createElement("span"))&&(n.classList.toggle("x",!1),n.classList.contains("x")&&(n.classList.constructor.prototype.toggle=function(e){var n=arguments[1];if(n===t){var o=!this.contains(e);return this[o?"add":"remove"](e),o}return this[(n=!!n)?"add":"remove"](e),n})),function(){var t=document.createElement("span");if("classList"in t&&(t.classList.add("a","b"),!t.classList.contains("b"))){var e=t.classList.constructor.prototype.add;t.classList.constructor.prototype.add=function(){for(var t=arguments,n=arguments.length,o=0;o<n;o++)e.call(this,t[o])}}}(),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 e=t.classList.constructor.prototype.remove;t.classList.constructor.prototype.remove=function(){for(var t=arguments,n=arguments.length,o=0;o<n;o++)e.call(this,t[o])}}}()}(this)}.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 e=!0,n=function(t,n,o,i){Object.defineProperty?Object.defineProperty(t,n,{configurable:!1===e||!!i,get:o}):t.__defineGetter__(n,o)};try{n({},"support")}catch(t){e=!1}var o=function(t,i,r){n(t.prototype,i,(function(){var t,a=this,s="__defineGetter__DEFINE_PROPERTY"+i;if(a[s])return t;if(a[s]=!0,!1===e){for(var c,l=o.mirror||document.createElement("div"),u=l.childNodes,d=u.length,p=0;p<d;++p)if(u[p]._R===a){c=u[p];break}c||(c=l.appendChild(document.createElement("div"))),t=DOMTokenList.call(c,a,r)}else t=new DOMTokenList(a,r);return n(a,i,(function(){return t})),delete a[s],t}),!0)};o(t.Element,"classList","className"),o(t.HTMLElement,"classList","className"),o(t.HTMLLinkElement,"relList","rel"),o(t.HTMLAnchorElement,"relList","rel"),o(t.HTMLAreaElement,"relList","rel")}(this)}.call("object"==typeof window&&window||"object"==typeof self&&self||"object"==typeof global&&global||{}),n.prototype.defaults={characterCountAttribute:"data-maxlength",wordCountAttribute:"data-maxwords"},n.prototype.init=function(){if(this.$textarea){var t=this.$module,e=this.$textarea,n=document.getElementById(e.id+"-info");e.insertAdjacentElement("afterend",n);var o=document.createElement("div");o.className="govuk-character-count__sr-status govuk-visually-hidden",o.setAttribute("aria-live","polite"),this.$screenReaderCountMessage=o,n.insertAdjacentElement("afterend",o);var i=document.createElement("div");i.className=n.className,i.classList.add("govuk-character-count__status"),i.setAttribute("aria-hidden","true"),this.$visibleCountMessage=i,n.insertAdjacentElement("afterend",i),n.classList.add("govuk-visually-hidden"),this.options=this.getDataset(t);var r=this.defaults.characterCountAttribute;this.options.maxwords&&(r=this.defaults.wordCountAttribute),this.maxLength=t.getAttribute(r),this.maxLength&&(e.removeAttribute("maxlength"),this.bindChangeEvents(),"onpageshow"in window?window.addEventListener("pageshow",this.updateCountMessage.bind(this)):window.addEventListener("DOMContentLoaded",this.updateCountMessage.bind(this)),this.updateCountMessage())}},n.prototype.getDataset=function(t){var e={},n=t.attributes;if(n)for(var o=0;o<n.length;o++){var i=n[o],r=i.name.match(/^data-(.+)/);r&&(e[r[1]]=i.value)}return e},n.prototype.count=function(t){var e;this.options.maxwords?e=(t.match(/\S+/g)||[]).length:e=t.length;return e},n.prototype.bindChangeEvents=function(){var t=this.$textarea;t.addEventListener("keyup",this.handleKeyUp.bind(this)),t.addEventListener("focus",this.handleFocus.bind(this)),t.addEventListener("blur",this.handleBlur.bind(this))},n.prototype.checkIfValueChanged=function(){this.$textarea.oldValue||(this.$textarea.oldValue=""),this.$textarea.value!==this.$textarea.oldValue&&(this.$textarea.oldValue=this.$textarea.value,this.updateCountMessage())},n.prototype.updateCountMessage=function(){this.updateVisibleCountMessage(),this.updateScreenReaderCountMessage()},n.prototype.updateVisibleCountMessage=function(){var t=this.$textarea,e=this.$visibleCountMessage,n=this.maxLength-this.count(t.value);this.isOverThreshold()?e.classList.remove("govuk-character-count__message--disabled"):e.classList.add("govuk-character-count__message--disabled"),n<0?(t.classList.add("govuk-textarea--error"),e.classList.remove("govuk-hint"),e.classList.add("govuk-error-message")):(t.classList.remove("govuk-textarea--error"),e.classList.remove("govuk-error-message"),e.classList.add("govuk-hint")),e.innerHTML=this.formattedUpdateMessage()},n.prototype.updateScreenReaderCountMessage=function(){var t=this.$screenReaderCountMessage;this.isOverThreshold()?t.removeAttribute("aria-hidden"):t.setAttribute("aria-hidden",!0),t.innerHTML=this.formattedUpdateMessage()},n.prototype.formattedUpdateMessage=function(){var t,e=this.$textarea,n=this.options,o=this.maxLength-this.count(e.value),i="character";return n.maxwords&&(i="word"),i+=-1===o||1===o?"":"s",t=o<0?"too many":"remaining","You have "+Math.abs(o)+" "+i+" "+t},n.prototype.isOverThreshold=function(){var t=this.$textarea,e=this.options,n=this.count(t.value);return this.maxLength*(e.threshold?e.threshold:0)/100<=n},n.prototype.handleKeyUp=function(){this.updateVisibleCountMessage(),this.lastInputTimestamp=Date.now()},n.prototype.handleFocus=function(){this.valueChecker=setInterval(function(){(!this.lastInputTimestamp||Date.now()-500>=this.lastInputTimestamp)&&this.checkIfValueChanged()}.bind(this),1e3)},n.prototype.handleBlur=function(){clearInterval(this.valueChecker)},o.prototype.init=function(){var e=this.$module;t(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(),e.addEventListener("click",this.handleClick.bind(this))},o.prototype.syncAllConditionalReveals=function(){t(this.$inputs,this.syncConditionalRevealWithInputState.bind(this))},o.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)}},o.prototype.unCheckAllInputsExcept=function(e){t(document.querySelectorAll('input[type="checkbox"][name="'+e.name+'"]'),function(t){e.form===t.form&&t!==e&&(t.checked=!1,this.syncConditionalRevealWithInputState(t))}.bind(this))},o.prototype.unCheckExclusiveInputs=function(e){t(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))},o.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,n=(e.document||e.ownerDocument).querySelectorAll(t),o=0;n[o]&&n[o]!==e;)++o;return!!n[o]})}.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||{}),i.prototype.init=function(){var t=this.$module;t&&(this.setFocus(),t.addEventListener("click",this.handleClick.bind(this)))},i.prototype.setFocus=function(){var t=this.$module;"true"!==t.getAttribute("data-disable-auto-focus")&&(t.setAttribute("tabindex","-1"),t.addEventListener("blur",(function(){t.removeAttribute("tabindex")})),t.focus())},i.prototype.handleClick=function(t){var e=t.target;this.focusTarget(e)&&t.preventDefault()},i.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)},i.prototype.getFragmentFromUrl=function(t){return-1!==t.indexOf("#")&&t.split("#").pop()},i.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,r=t.getBoundingClientRect();if(r.height&&window.innerHeight)if(r.top+r.height-i<window.innerHeight/2)return o}}return document.querySelector("label[for='"+t.getAttribute("id")+"']")||t.closest("label")},r.prototype.init=function(){var e=this.$module;t(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(),e.addEventListener("click",this.handleClick.bind(this))},r.prototype.syncAllConditionalReveals=function(){t(this.$inputs,this.syncConditionalRevealWithInputState.bind(this))},r.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)}},r.prototype.handleClick=function(e){var n=e.target;"radio"===n.type&&t(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))};export{e as Button,n as CharacterCount,o as Checkboxes,i as ErrorSummary,r as Radios,a as initAll};
|