text: (function (global, factory) {
  	typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  	typeof define === 'function' && define.amd ? define('GOVUKFrontend', ['exports'], factory) :
  	(factory((global.GOVUKFrontend = {})));
  }(this, (function (exports) { 'use strict';
  
  /**
   * TODO: Ideally this would be a NodeList.prototype.forEach polyfill
   * This seems to fail in IE8, requires more investigation.
   * See: https://github.com/imagitama/nodelist-foreach-polyfill
   */
  function nodeListForEach (nodes, callback) {
    if (window.NodeList.prototype.forEach) {
      return nodes.forEach(callback)
    }
    for (var i = 0; i < nodes.length; i++) {
      callback.call(window, nodes[i], i, nodes);
    }
  }
  
  // Used to generate a unique string, allows multiple instances of the component without
  // Them conflicting with each other.
  // https://stackoverflow.com/a/8809472
  function generateUniqueID () {
    var d = new Date().getTime();
    if (typeof window.performance !== 'undefined' && typeof window.performance.now === 'function') {
      d += window.performance.now(); // use high-precision timer if available
    }
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
      var r = (d + Math.random() * 16) % 16 | 0;
      d = Math.floor(d / 16);
      return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16)
    })
  }
  
  (function(undefined) {
  
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Object/defineProperty/detect.js
  var detect = (
    // In IE8, defineProperty could only act on DOM elements, so full support
    // for the feature requires the ability to set a property on an arbitrary object
    'defineProperty' in Object && (function() {
    	try {
    		var a = {};
    		Object.defineProperty(a, 'test', {value:42});
    		return true;
    	} catch(e) {
    		return false
    	}
    }())
  );
  
  if (detect) return
  
  // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Object.defineProperty&flags=always
  (function (nativeDefineProperty) {
  
  	var supportsAccessors = Object.prototype.hasOwnProperty('__defineGetter__');
  	var ERR_ACCESSORS_NOT_SUPPORTED = 'Getters & setters cannot be defined on this javascript engine';
  	var ERR_VALUE_ACCESSORS = 'A property cannot both have accessors and be writable or have a value';
  
  	Object.defineProperty = function defineProperty(object, property, descriptor) {
  
  		// Where native support exists, assume it
  		if (nativeDefineProperty && (object === window || object === document || object === Element.prototype || object instanceof Element)) {
  			return nativeDefineProperty(object, property, descriptor);
  		}
  
  		if (object === null || !(object instanceof Object || typeof object === 'object')) {
  			throw new TypeError('Object.defineProperty called on non-object');
  		}
  
  		if (!(descriptor instanceof Object)) {
  			throw new TypeError('Property description must be an object');
  		}
  
  		var propertyString = String(property);
  		var hasValueOrWritable = 'value' in descriptor || 'writable' in descriptor;
  		var getterType = 'get' in descriptor && typeof descriptor.get;
  		var setterType = 'set' in descriptor && typeof descriptor.set;
  
  		// handle descriptor.get
  		if (getterType) {
  			if (getterType !== 'function') {
  				throw new TypeError('Getter must be a function');
  			}
  			if (!supportsAccessors) {
  				throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  			}
  			if (hasValueOrWritable) {
  				throw new TypeError(ERR_VALUE_ACCESSORS);
  			}
  			Object.__defineGetter__.call(object, propertyString, descriptor.get);
  		} else {
  			object[propertyString] = descriptor.value;
  		}
  
  		// handle descriptor.set
  		if (setterType) {
  			if (setterType !== 'function') {
  				throw new TypeError('Setter must be a function');
  			}
  			if (!supportsAccessors) {
  				throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  			}
  			if (hasValueOrWritable) {
  				throw new TypeError(ERR_VALUE_ACCESSORS);
  			}
  			Object.__defineSetter__.call(object, propertyString, descriptor.set);
  		}
  
  		// OK to define value unconditionally - if a getter has been specified as well, an error would be thrown above
  		if ('value' in descriptor) {
  			object[propertyString] = descriptor.value;
  		}
  
  		return object;
  	};
  }(Object.defineProperty));
  })
  .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
    // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Function/prototype/bind/detect.js
    var detect = 'bind' in Function.prototype;
  
    if (detect) return
  
    // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Function.prototype.bind&flags=always
    Object.defineProperty(Function.prototype, 'bind', {
        value: function bind(that) { // .length is 1
            // add necessary es5-shim utilities
            var $Array = Array;
            var $Object = Object;
            var ObjectPrototype = $Object.prototype;
            var ArrayPrototype = $Array.prototype;
            var Empty = function Empty() {};
            var to_string = ObjectPrototype.toString;
            var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
            var isCallable; /* inlined from https://npmjs.com/is-callable */ var fnToStr = Function.prototype.toString, tryFunctionObject = function tryFunctionObject(value) { try { fnToStr.call(value); return true; } catch (e) { return false; } }, fnClass = '[object Function]', genClass = '[object GeneratorFunction]'; isCallable = function isCallable(value) { if (typeof value !== 'function') { return false; } if (hasToStringTag) { return tryFunctionObject(value); } var strClass = to_string.call(value); return strClass === fnClass || strClass === genClass; };
            var array_slice = ArrayPrototype.slice;
            var array_concat = ArrayPrototype.concat;
            var array_push = ArrayPrototype.push;
            var max = Math.max;
            // /add necessary es5-shim utilities
  
            // 1. Let Target be the this value.
            var target = this;
            // 2. If IsCallable(Target) is false, throw a TypeError exception.
            if (!isCallable(target)) {
                throw new TypeError('Function.prototype.bind called on incompatible ' + target);
            }
            // 3. Let A be a new (possibly empty) internal list of all of the
            //   argument values provided after thisArg (arg1, arg2 etc), in order.
            // XXX slicedArgs will stand in for "A" if used
            var args = array_slice.call(arguments, 1); // for normal call
            // 4. Let F be a new native ECMAScript object.
            // 11. Set the [[Prototype]] internal property of F to the standard
            //   built-in Function prototype object as specified in 15.3.3.1.
            // 12. Set the [[Call]] internal property of F as described in
            //   15.3.4.5.1.
            // 13. Set the [[Construct]] internal property of F as described in
            //   15.3.4.5.2.
            // 14. Set the [[HasInstance]] internal property of F as described in
            //   15.3.4.5.3.
            var bound;
            var binder = function () {
  
                if (this instanceof bound) {
                    // 15.3.4.5.2 [[Construct]]
                    // When the [[Construct]] internal method of a function object,
                    // F that was created using the bind function is called with a
                    // list of arguments ExtraArgs, the following steps are taken:
                    // 1. Let target be the value of F's [[TargetFunction]]
                    //   internal property.
                    // 2. If target has no [[Construct]] internal method, a
                    //   TypeError exception is thrown.
                    // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
                    //   property.
                    // 4. Let args be a new list containing the same values as the
                    //   list boundArgs in the same order followed by the same
                    //   values as the list ExtraArgs in the same order.
                    // 5. Return the result of calling the [[Construct]] internal
                    //   method of target providing args as the arguments.
  
                    var result = target.apply(
                        this,
                        array_concat.call(args, array_slice.call(arguments))
                    );
                    if ($Object(result) === result) {
                        return result;
                    }
                    return this;
  
                } else {
                    // 15.3.4.5.1 [[Call]]
                    // When the [[Call]] internal method of a function object, F,
                    // which was created using the bind function is called with a
                    // this value and a list of arguments ExtraArgs, the following
                    // steps are taken:
                    // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
                    //   property.
                    // 2. Let boundThis be the value of F's [[BoundThis]] internal
                    //   property.
                    // 3. Let target be the value of F's [[TargetFunction]] internal
                    //   property.
                    // 4. Let args be a new list containing the same values as the
                    //   list boundArgs in the same order followed by the same
                    //   values as the list ExtraArgs in the same order.
                    // 5. Return the result of calling the [[Call]] internal method
                    //   of target providing boundThis as the this value and
                    //   providing args as the arguments.
  
                    // equiv: target.call(this, ...boundArgs, ...args)
                    return target.apply(
                        that,
                        array_concat.call(args, array_slice.call(arguments))
                    );
  
                }
  
            };
  
            // 15. If the [[Class]] internal property of Target is "Function", then
            //     a. Let L be the length property of Target minus the length of A.
            //     b. Set the length own property of F to either 0 or L, whichever is
            //       larger.
            // 16. Else set the length own property of F to 0.
  
            var boundLength = max(0, target.length - args.length);
  
            // 17. Set the attributes of the length own property of F to the values
            //   specified in 15.3.5.1.
            var boundArgs = [];
            for (var i = 0; i < boundLength; i++) {
                array_push.call(boundArgs, '$' + i);
            }
  
            // XXX Build a dynamic function with desired amount of arguments is the only
            // way to set the length property of a function.
            // In environments where Content Security Policies enabled (Chrome extensions,
            // for ex.) all use of eval or Function costructor throws an exception.
            // However in all of these environments Function.prototype.bind exists
            // and so this code will never be executed.
            bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
  
            if (target.prototype) {
                Empty.prototype = target.prototype;
                bound.prototype = new Empty();
                // Clean up dangling references.
                Empty.prototype = null;
            }
  
            // TODO
            // 18. Set the [[Extensible]] internal property of F to true.
  
            // TODO
            // 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
            // 20. Call the [[DefineOwnProperty]] internal method of F with
            //   arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
            //   thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
            //   false.
            // 21. Call the [[DefineOwnProperty]] internal method of F with
            //   arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
            //   [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
            //   and false.
  
            // TODO
            // NOTE Function objects created using Function.prototype.bind do not
            // have a prototype property or the [[Code]], [[FormalParameters]], and
            // [[Scope]] internal properties.
            // XXX can't delete prototype in pure-js.
  
            // 22. Return F.
            return bound;
        }
    });
  })
  .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
  
      // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
      var detect = (
        'DOMTokenList' in this && (function (x) {
          return 'classList' in x ? !x.classList.toggle('x', false) && !x.className : true;
        })(document.createElement('x'))
      );
  
      if (detect) return
  
      // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/polyfill.js
      (function (global) {
        var nativeImpl = "DOMTokenList" in global && global.DOMTokenList;
  
        if (
            !nativeImpl ||
            (
              !!document.createElementNS &&
              !!document.createElementNS('http://www.w3.org/2000/svg', 'svg') &&
              !(document.createElementNS("http://www.w3.org/2000/svg", "svg").classList instanceof DOMTokenList)
            )
          ) {
          global.DOMTokenList = (function() { // eslint-disable-line no-unused-vars
            var dpSupport = true;
            var defineGetter = function (object, name, fn, configurable) {
              if (Object.defineProperty)
                Object.defineProperty(object, name, {
                  configurable: false === dpSupport ? true : !!configurable,
                  get: fn
                });
  
              else object.__defineGetter__(name, fn);
            };
  
            /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
            try {
              defineGetter({}, "support");
            }
            catch (e) {
              dpSupport = false;
            }
  
  
            var _DOMTokenList = function (el, prop) {
              var that = this;
              var tokens = [];
              var tokenMap = {};
              var length = 0;
              var maxLength = 0;
              var addIndexGetter = function (i) {
                defineGetter(that, i, function () {
                  preop();
                  return tokens[i];
                }, false);
  
              };
              var reindex = function () {
  
                /** Define getter functions for array-like access to the tokenList's contents. */
                if (length >= maxLength)
                  for (; maxLength < length; ++maxLength) {
                    addIndexGetter(maxLength);
                  }
              };
  
              /** Helper function called at the start of each class method. Internal use only. */
              var preop = function () {
                var error;
                var i;
                var args = arguments;
                var rSpace = /\s+/;
  
                /** Validate the token/s passed to an instance method, if any. */
                if (args.length)
                  for (i = 0; i < args.length; ++i)
                    if (rSpace.test(args[i])) {
                      error = new SyntaxError('String "' + args[i] + '" ' + "contains" + ' an invalid character');
                      error.code = 5;
                      error.name = "InvalidCharacterError";
                      throw error;
                    }
  
  
                /** Split the new value apart by whitespace*/
                if (typeof el[prop] === "object") {
                  tokens = ("" + el[prop].baseVal).replace(/^\s+|\s+$/g, "").split(rSpace);
                } else {
                  tokens = ("" + el[prop]).replace(/^\s+|\s+$/g, "").split(rSpace);
                }
  
                /** Avoid treating blank strings as single-item token lists */
                if ("" === tokens[0]) tokens = [];
  
                /** Repopulate the internal token lists */
                tokenMap = {};
                for (i = 0; i < tokens.length; ++i)
                  tokenMap[tokens[i]] = true;
                length = tokens.length;
                reindex();
              };
  
              /** Populate our internal token list if the targeted attribute of the subject element isn't empty. */
              preop();
  
              /** Return the number of tokens in the underlying string. Read-only. */
              defineGetter(that, "length", function () {
                preop();
                return length;
              });
  
              /** Override the default toString/toLocaleString methods to return a space-delimited list of tokens when typecast. */
              that.toLocaleString =
                that.toString = function () {
                  preop();
                  return tokens.join(" ");
                };
  
              that.item = function (idx) {
                preop();
                return tokens[idx];
              };
  
              that.contains = function (token) {
                preop();
                return !!tokenMap[token];
              };
  
              that.add = function () {
                preop.apply(that, args = arguments);
  
                for (var args, token, i = 0, l = args.length; i < l; ++i) {
                  token = args[i];
                  if (!tokenMap[token]) {
                    tokens.push(token);
                    tokenMap[token] = true;
                  }
                }
  
                /** Update the targeted attribute of the attached element if the token list's changed. */
                if (length !== tokens.length) {
                  length = tokens.length >>> 0;
                  if (typeof el[prop] === "object") {
                    el[prop].baseVal = tokens.join(" ");
                  } else {
                    el[prop] = tokens.join(" ");
                  }
                  reindex();
                }
              };
  
              that.remove = function () {
                preop.apply(that, args = arguments);
  
                /** Build a hash of token names to compare against when recollecting our token list. */
                for (var args, ignore = {}, i = 0, t = []; i < args.length; ++i) {
                  ignore[args[i]] = true;
                  delete tokenMap[args[i]];
                }
  
                /** Run through our tokens list and reassign only those that aren't defined in the hash declared above. */
                for (i = 0; i < tokens.length; ++i)
                  if (!ignore[tokens[i]]) t.push(tokens[i]);
  
                tokens = t;
                length = t.length >>> 0;
  
                /** Update the targeted attribute of the attached element. */
                if (typeof el[prop] === "object") {
                  el[prop].baseVal = tokens.join(" ");
                } else {
                  el[prop] = tokens.join(" ");
                }
                reindex();
              };
  
              that.toggle = function (token, force) {
                preop.apply(that, [token]);
  
                /** Token state's being forced. */
                if (undefined !== force) {
                  if (force) {
                    that.add(token);
                    return true;
                  } else {
                    that.remove(token);
                    return false;
                  }
                }
  
                /** Token already exists in tokenList. Remove it, and return FALSE. */
                if (tokenMap[token]) {
                  that.remove(token);
                  return false;
                }
  
                /** Otherwise, add the token and return TRUE. */
                that.add(token);
                return true;
              };
  
              return that;
            };
  
            return _DOMTokenList;
          }());
        }
  
        // Add second argument to native DOMTokenList.toggle() if necessary
        (function () {
          var e = document.createElement('span');
          if (!('classList' in e)) return;
          e.classList.toggle('x', false);
          if (!e.classList.contains('x')) return;
          e.classList.constructor.prototype.toggle = function toggle(token /*, force*/) {
            var force = arguments[1];
            if (force === undefined) {
              var add = !this.contains(token);
              this[add ? 'add' : 'remove'](token);
              return add;
            }
            force = !!force;
            this[force ? 'add' : 'remove'](token);
            return force;
          };
        }());
  
        // Add multiple arguments to native DOMTokenList.add() if necessary
        (function () {
          var e = document.createElement('span');
          if (!('classList' in e)) return;
          e.classList.add('a', 'b');
          if (e.classList.contains('b')) return;
          var native = e.classList.constructor.prototype.add;
          e.classList.constructor.prototype.add = function () {
            var args = arguments;
            var l = arguments.length;
            for (var i = 0; i < l; i++) {
              native.call(this, args[i]);
            }
          };
        }());
  
        // Add multiple arguments to native DOMTokenList.remove() if necessary
        (function () {
          var e = document.createElement('span');
          if (!('classList' in e)) return;
          e.classList.add('a');
          e.classList.add('b');
          e.classList.remove('a', 'b');
          if (!e.classList.contains('b')) return;
          var native = e.classList.constructor.prototype.remove;
          e.classList.constructor.prototype.remove = function () {
            var args = arguments;
            var l = arguments.length;
            for (var i = 0; i < l; i++) {
              native.call(this, args[i]);
            }
          };
        }());
  
      }(this));
  
  }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
  
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Document/detect.js
  var detect = ("Document" in this);
  
  if (detect) return
  
  // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Document&flags=always
  if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
  
  	if (this.HTMLDocument) { // IE8
  
  		// HTMLDocument is an extension of Document.  If the browser has HTMLDocument but not Document, the former will suffice as an alias for the latter.
  		this.Document = this.HTMLDocument;
  
  	} else {
  
  		// Create an empty function to act as the missing constructor for the document object, attach the document object as its prototype.  The function needs to be anonymous else it is hoisted and causes the feature detect to prematurely pass, preventing the assignments below being made.
  		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(undefined) {
  
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Element/detect.js
  var detect = ('Element' in this && 'HTMLElement' in this);
  
  if (detect) return
  
  // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element&flags=always
  (function () {
  
  	// IE8
  	if (window.Element && !window.HTMLElement) {
  		window.HTMLElement = window.Element;
  		return;
  	}
  
  	// create Element constructor
  	window.Element = window.HTMLElement = new Function('return function Element() {}')();
  
  	// generate sandboxed iframe
  	var vbody = document.appendChild(document.createElement('body'));
  	var frame = vbody.appendChild(document.createElement('iframe'));
  
  	// use sandboxed iframe to replicate Element functionality
  	var frameDocument = frame.contentWindow.document;
  	var prototype = Element.prototype = frameDocument.appendChild(frameDocument.createElement('*'));
  	var cache = {};
  
  	// polyfill Element.prototype on an element
  	var shiv = function (element, deep) {
  		var
  		childNodes = element.childNodes || [],
  		index = -1,
  		key, value, childNode;
  
  		if (element.nodeType === 1 && element.constructor !== Element) {
  			element.constructor = Element;
  
  			for (key in cache) {
  				value = cache[key];
  				element[key] = value;
  			}
  		}
  
  		while (childNode = deep && childNodes[++index]) {
  			shiv(childNode, deep);
  		}
  
  		return element;
  	};
  
  	var elements = document.getElementsByTagName('*');
  	var nativeCreateElement = document.createElement;
  	var interval;
  	var loopLimit = 100;
  
  	prototype.attachEvent('onpropertychange', function (event) {
  		var
  		propertyName = event.propertyName,
  		nonValue = !cache.hasOwnProperty(propertyName),
  		newValue = prototype[propertyName],
  		oldValue = cache[propertyName],
  		index = -1,
  		element;
  
  		while (element = elements[++index]) {
  			if (element.nodeType === 1) {
  				if (nonValue || element[propertyName] === oldValue) {
  					element[propertyName] = newValue;
  				}
  			}
  		}
  
  		cache[propertyName] = newValue;
  	});
  
  	prototype.constructor = Element;
  
  	if (!prototype.hasAttribute) {
  		// <Element>.hasAttribute
  		prototype.hasAttribute = function hasAttribute(name) {
  			return this.getAttribute(name) !== null;
  		};
  	}
  
  	// Apply Element prototype to the pre-existing DOM as soon as the body element appears.
  	function bodyCheck() {
  		if (!(loopLimit--)) clearTimeout(interval);
  		if (document.body && !document.body.prototype && /(complete|interactive)/.test(document.readyState)) {
  			shiv(document, true);
  			if (interval && document.body.prototype) clearTimeout(interval);
  			return (!!document.body.prototype);
  		}
  		return false;
  	}
  	if (!bodyCheck()) {
  		document.onreadystatechange = bodyCheck;
  		interval = setInterval(bodyCheck, 25);
  	}
  
  	// Apply to any new elements created after load
  	document.createElement = function createElement(nodeName) {
  		var element = nativeCreateElement(String(nodeName).toLowerCase());
  		return shiv(element);
  	};
  
  	// remove sandboxed iframe
  	document.removeChild(vbody);
  }());
  
  })
  .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
  
      // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/8717a9e04ac7aff99b4980fbedead98036b0929a/packages/polyfill-library/polyfills/Element/prototype/classList/detect.js
      var detect = (
        'document' in this && "classList" in document.documentElement && 'Element' in this && 'classList' in Element.prototype && (function () {
          var e = document.createElement('span');
          e.classList.add('a', 'b');
          return e.classList.contains('b');
        }())
      );
  
      if (detect) return
  
      // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Element.prototype.classList&flags=always
      (function (global) {
        var dpSupport = true;
        var defineGetter = function (object, name, fn, configurable) {
          if (Object.defineProperty)
            Object.defineProperty(object, name, {
              configurable: false === dpSupport ? true : !!configurable,
              get: fn
            });
  
          else object.__defineGetter__(name, fn);
        };
        /** Ensure the browser allows Object.defineProperty to be used on native JavaScript objects. */
        try {
          defineGetter({}, "support");
        }
        catch (e) {
          dpSupport = false;
        }
        /** Polyfills a property with a DOMTokenList */
        var addProp = function (o, name, attr) {
  
          defineGetter(o.prototype, name, function () {
            var tokenList;
  
            var THIS = this,
  
            /** Prevent this from firing twice for some reason. What the hell, IE. */
            gibberishProperty = "__defineGetter__" + "DEFINE_PROPERTY" + name;
            if(THIS[gibberishProperty]) return tokenList;
            THIS[gibberishProperty] = true;
  
            /**
             * IE8 can't define properties on native JavaScript objects, so we'll use a dumb hack instead.
             *
             * What this is doing is creating a dummy element ("reflection") inside a detached phantom node ("mirror")
             * that serves as the target of Object.defineProperty instead. While we could simply use the subject HTML
             * element instead, this would conflict with element types which use indexed properties (such as forms and
             * select lists).
             */
            if (false === dpSupport) {
  
              var visage;
              var mirror = addProp.mirror || document.createElement("div");
              var reflections = mirror.childNodes;
              var l = reflections.length;
  
              for (var i = 0; i < l; ++i)
                if (reflections[i]._R === THIS) {
                  visage = reflections[i];
                  break;
                }
  
              /** Couldn't find an element's reflection inside the mirror. Materialise one. */
              visage || (visage = mirror.appendChild(document.createElement("div")));
  
              tokenList = DOMTokenList.call(visage, THIS, attr);
            } else tokenList = new DOMTokenList(THIS, attr);
  
            defineGetter(THIS, name, function () {
              return tokenList;
            });
            delete THIS[gibberishProperty];
  
            return tokenList;
          }, true);
        };
  
        addProp(global.Element, "classList", "className");
        addProp(global.HTMLElement, "classList", "className");
        addProp(global.HTMLLinkElement, "relList", "rel");
        addProp(global.HTMLAnchorElement, "relList", "rel");
        addProp(global.HTMLAreaElement, "relList", "rel");
      }(this));
  
  }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  function Accordion ($module) {
    this.$module = $module;
    this.moduleId = $module.getAttribute('id');
    this.$sections = $module.querySelectorAll('.govuk-accordion__section');
    this.$openAllButton = '';
    this.browserSupportsSessionStorage = helper.checkForSessionStorage();
  
    this.controlsClass = 'govuk-accordion__controls';
    this.openAllClass = 'govuk-accordion__open-all';
    this.iconClass = 'govuk-accordion__icon';
  
    this.sectionHeaderClass = 'govuk-accordion__section-header';
    this.sectionHeaderFocusedClass = 'govuk-accordion__section-header--focused';
    this.sectionHeadingClass = 'govuk-accordion__section-heading';
    this.sectionSummaryClass = 'govuk-accordion__section-summary';
    this.sectionButtonClass = 'govuk-accordion__section-button';
    this.sectionExpandedClass = 'govuk-accordion__section--expanded';
  }
  
  // Initialize component
  Accordion.prototype.init = function () {
    // Check for module
    if (!this.$module) {
      return
    }
  
    this.initControls();
  
    this.initSectionHeaders();
  
    // See if "Open all" button text should be updated
    var areAllSectionsOpen = this.checkIfAllSectionsOpen();
    this.updateOpenAllButton(areAllSectionsOpen);
  };
  
  // Initialise controls and set attributes
  Accordion.prototype.initControls = function () {
    // Create "Open all" button and set attributes
    this.$openAllButton = document.createElement('button');
    this.$openAllButton.setAttribute('type', 'button');
    this.$openAllButton.innerHTML = 'Open all <span class="govuk-visually-hidden">sections</span>';
    this.$openAllButton.setAttribute('class', this.openAllClass);
    this.$openAllButton.setAttribute('aria-expanded', 'false');
    this.$openAllButton.setAttribute('type', 'button');
  
    // Create control wrapper and add controls to it
    var accordionControls = document.createElement('div');
    accordionControls.setAttribute('class', this.controlsClass);
    accordionControls.appendChild(this.$openAllButton);
    this.$module.insertBefore(accordionControls, this.$module.firstChild);
  
    // Handle events for the controls
    this.$openAllButton.addEventListener('click', this.onOpenOrCloseAllToggle.bind(this));
  };
  
  // Initialise section headers
  Accordion.prototype.initSectionHeaders = function () {
    // Loop through section headers
    nodeListForEach(this.$sections, function ($section, i) {
      // Set header attributes
      var header = $section.querySelector('.' + this.sectionHeaderClass);
      this.initHeaderAttributes(header, i);
  
      this.setExpanded(this.isExpanded($section), $section);
  
      // Handle events
      header.addEventListener('click', this.onSectionToggle.bind(this, $section));
  
      // See if there is any state stored in sessionStorage and set the sections to
      // open or closed.
      this.setInitialState($section);
    }.bind(this));
  };
  
  // Set individual header attributes
  Accordion.prototype.initHeaderAttributes = function ($headerWrapper, index) {
    var $module = this;
    var $span = $headerWrapper.querySelector('.' + this.sectionButtonClass);
    var $heading = $headerWrapper.querySelector('.' + this.sectionHeadingClass);
    var $summary = $headerWrapper.querySelector('.' + this.sectionSummaryClass);
  
    // Copy existing span element to an actual button element, for improved accessibility.
    var $button = document.createElement('button');
    $button.setAttribute('type', 'button');
    $button.setAttribute('id', this.moduleId + '-heading-' + (index + 1));
    $button.setAttribute('aria-controls', this.moduleId + '-content-' + (index + 1));
  
    // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from $span to $button
    for (var i = 0; i < $span.attributes.length; i++) {
      var attr = $span.attributes.item(i);
      $button.setAttribute(attr.nodeName, attr.nodeValue);
    }
  
    $button.addEventListener('focusin', function (e) {
      if (!$headerWrapper.classList.contains($module.sectionHeaderFocusedClass)) {
        $headerWrapper.className += ' ' + $module.sectionHeaderFocusedClass;
      }
    });
  
    $button.addEventListener('blur', function (e) {
      $headerWrapper.classList.remove($module.sectionHeaderFocusedClass);
    });
  
    if (typeof ($summary) !== 'undefined' && $summary !== null) {
      $button.setAttribute('aria-describedby', this.moduleId + '-summary-' + (index + 1));
    }
  
    // $span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
    $button.innerHTML = $span.innerHTML;
  
    $heading.removeChild($span);
    $heading.appendChild($button);
  
    // Add "+/-" icon
    var icon = document.createElement('span');
    icon.className = this.iconClass;
    icon.setAttribute('aria-hidden', 'true');
  
    $button.appendChild(icon);
  };
  
  // When section toggled, set and store state
  Accordion.prototype.onSectionToggle = function ($section) {
    var expanded = this.isExpanded($section);
    this.setExpanded(!expanded, $section);
  
    // Store the state in sessionStorage when a change is triggered
    this.storeState($section);
  };
  
  // When Open/Close All toggled, set and store state
  Accordion.prototype.onOpenOrCloseAllToggle = function () {
    var $module = this;
    var $sections = this.$sections;
  
    var nowExpanded = !this.checkIfAllSectionsOpen();
  
    nodeListForEach($sections, function ($section) {
      $module.setExpanded(nowExpanded, $section);
      // Store the state in sessionStorage when a change is triggered
      $module.storeState($section);
    });
  
    $module.updateOpenAllButton(nowExpanded);
  };
  
  // Set section attributes when opened/closed
  Accordion.prototype.setExpanded = function (expanded, $section) {
    var $button = $section.querySelector('.' + this.sectionButtonClass);
    $button.setAttribute('aria-expanded', expanded);
  
    if (expanded) {
      $section.classList.add(this.sectionExpandedClass);
    } else {
      $section.classList.remove(this.sectionExpandedClass);
    }
  
    // See if "Open all" button text should be updated
    var areAllSectionsOpen = this.checkIfAllSectionsOpen();
    this.updateOpenAllButton(areAllSectionsOpen);
  };
  
  // Get state of section
  Accordion.prototype.isExpanded = function ($section) {
    return $section.classList.contains(this.sectionExpandedClass)
  };
  
  // Check if all sections are open
  Accordion.prototype.checkIfAllSectionsOpen = function () {
    // Get a count of all the Accordion sections
    var sectionsCount = this.$sections.length;
    // Get a count of all Accordion sections that are expanded
    var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length;
    var areAllSectionsOpen = sectionsCount === expandedSectionCount;
  
    return areAllSectionsOpen
  };
  
  // Update "Open all" button
  Accordion.prototype.updateOpenAllButton = function (expanded) {
    var newButtonText = expanded ? 'Close all' : 'Open all';
    newButtonText += '<span class="govuk-visually-hidden"> sections</span>';
    this.$openAllButton.setAttribute('aria-expanded', expanded);
    this.$openAllButton.innerHTML = newButtonText;
  };
  
  // Check for `window.sessionStorage`, and that it actually works.
  var helper = {
    checkForSessionStorage: function () {
      var testString = 'this is the test string';
      var result;
      try {
        window.sessionStorage.setItem(testString, testString);
        result = window.sessionStorage.getItem(testString) === testString.toString();
        window.sessionStorage.removeItem(testString);
        return result
      } catch (exception) {
        if ((typeof console === 'undefined' || typeof console.log === 'undefined')) {
          console.log('Notice: sessionStorage not available.');
        }
      }
    }
  };
  
  // Set the state of the accordions in sessionStorage
  Accordion.prototype.storeState = function ($section) {
    if (this.browserSupportsSessionStorage) {
      // We need a unique way of identifying each content in the accordion. Since
      // an `#id` should be unique and an `id` is required for `aria-` attributes
      // `id` can be safely used.
      var $button = $section.querySelector('.' + this.sectionButtonClass);
  
      if ($button) {
        var contentId = $button.getAttribute('aria-controls');
        var contentState = $button.getAttribute('aria-expanded');
  
        if (typeof contentId === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
          console.error(new Error('No aria controls present in accordion section heading.'));
        }
  
        if (typeof contentState === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
          console.error(new Error('No aria expanded present in accordion section heading.'));
        }
  
        // Only set the state when both `contentId` and `contentState` are taken from the DOM.
        if (contentId && contentState) {
          window.sessionStorage.setItem(contentId, contentState);
        }
      }
    }
  };
  
  // Read the state of the accordions from sessionStorage
  Accordion.prototype.setInitialState = function ($section) {
    if (this.browserSupportsSessionStorage) {
      var $button = $section.querySelector('.' + this.sectionButtonClass);
  
      if ($button) {
        var contentId = $button.getAttribute('aria-controls');
        var contentState = contentId ? window.sessionStorage.getItem(contentId) : null;
  
        if (contentState !== null) {
          this.setExpanded(contentState === 'true', $section);
        }
      }
    }
  };
  
  (function(undefined) {
  
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Window/detect.js
  var detect = ('Window' in this);
  
  if (detect) return
  
  // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Window&flags=always
  if ((typeof WorkerGlobalScope === "undefined") && (typeof importScripts !== "function")) {
  	(function (global) {
  		if (global.constructor) {
  			global.Window = global.constructor;
  		} else {
  			(global.Window = global.constructor = new Function('return function Window() {}')()).prototype = this;
  		}
  	}(this));
  }
  
  })
  .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
  
  // Detection from https://github.com/Financial-Times/polyfill-service/blob/master/packages/polyfill-library/polyfills/Event/detect.js
  var detect = (
    (function(global) {
  
    	if (!('Event' in global)) return false;
    	if (typeof global.Event === 'function') return true;
  
    	try {
  
    		// In IE 9-11, the Event object exists but cannot be instantiated
    		new Event('click');
    		return true;
    	} catch(e) {
    		return false;
    	}
    }(this))
  );
  
  if (detect) return
  
  // Polyfill from https://cdn.polyfill.io/v2/polyfill.js?features=Event&flags=always
  (function () {
  	var unlistenableWindowEvents = {
  		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
  	};
  
  	// This polyfill depends on availability of `document` so will not run in a worker
  	// However, we asssume there are no browsers with worker support that lack proper
  	// support for `Event` within the worker
  	if (typeof document === 'undefined' || typeof window === 'undefined') return;
  
  	function indexOf(array, element) {
  		var
  		index = -1,
  		length = array.length;
  
  		while (++index < length) {
  			if (index in array && array[index] === element) {
  				return index;
  			}
  		}
  
  		return -1;
  	}
  
  	var existingProto = (window.Event && window.Event.prototype) || null;
  	window.Event = Window.prototype.Event = function Event(type, eventInitDict) {
  		if (!type) {
  			throw new Error('Not enough arguments');
  		}
  
  		var event;
  		// Shortcut if browser supports createEvent
  		if ('createEvent' in document) {
  			event = document.createEvent('Event');
  			var bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
  			var cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
  
  			event.initEvent(type, bubbles, cancelable);
  
  			return event;
  		}
  
  		event = document.createEventObject();
  
  		event.type = type;
  		event.bubbles = eventInitDict && eventInitDict.bubbles !== undefined ? eventInitDict.bubbles : false;
  		event.cancelable = eventInitDict && eventInitDict.cancelable !== undefined ? eventInitDict.cancelable : false;
  
  		return event;
  	};
  	if (existingProto) {
  		Object.defineProperty(window.Event, 'prototype', {
  			configurable: false,
  			enumerable: false,
  			writable: true,
  			value: existingProto
  		});
  	}
  
  	if (!('createEvent' in document)) {
  		window.addEventListener = Window.prototype.addEventListener = Document.prototype.addEventListener = Element.prototype.addEventListener = function addEventListener() {
  			var
  			element = this,
  			type = arguments[0],
  			listener = arguments[1];
  
  			if (element === window && type in unlistenableWindowEvents) {
  				throw new Error('In IE8 the event: ' + type + ' is not available on the window object. Please see https://github.com/Financial-Times/polyfill-service/issues/317 for more information.');
  			}
  
  			if (!element._events) {
  				element._events = {};
  			}
  
  			if (!element._events[type]) {
  				element._events[type] = function (event) {
  					var
  					list = element._events[event.type].list,
  					events = list.slice(),
  					index = -1,
  					length = events.length,
  					eventElement;
  
  					event.preventDefault = function preventDefault() {
  						if (event.cancelable !== false) {
  							event.returnValue = false;
  						}
  					};
  
  					event.stopPropagation = function stopPropagation() {
  						event.cancelBubble = true;
  					};
  
  					event.stopImmediatePropagation = function stopImmediatePropagation() {
  						event.cancelBubble = true;
  						event.cancelImmediate = true;
  					};
  
  					event.currentTarget = element;
  					event.relatedTarget = event.fromElement || null;
  					event.target = event.target || event.srcElement || element;
  					event.timeStamp = new Date().getTime();
  
  					if (event.clientX) {
  						event.pageX = event.clientX + document.documentElement.scrollLeft;
  						event.pageY = event.clientY + document.documentElement.scrollTop;
  					}
  
  					while (++index < length && !event.cancelImmediate) {
  						if (index in events) {
  							eventElement = events[index];
  
  							if (indexOf(list, eventElement) !== -1 && typeof eventElement === 'function') {
  								eventElement.call(element, event);
  							}
  						}
  					}
  				};
  
  				element._events[type].list = [];
  
  				if (element.attachEvent) {
  					element.attachEvent('on' + type, element._events[type]);
  				}
  			}
  
  			element._events[type].list.push(listener);
  		};
  
  		window.removeEventListener = Window.prototype.removeEventListener = Document.prototype.removeEventListener = Element.prototype.removeEventListener = function removeEventListener() {
  			var
  			element = this,
  			type = arguments[0],
  			listener = arguments[1],
  			index;
  
  			if (element._events && element._events[type] && element._events[type].list) {
  				index = indexOf(element._events[type].list, listener);
  
  				if (index !== -1) {
  					element._events[type].list.splice(index, 1);
  
  					if (!element._events[type].list.length) {
  						if (element.detachEvent) {
  							element.detachEvent('on' + type, element._events[type]);
  						}
  						delete element._events[type];
  					}
  				}
  			}
  		};
  
  		window.dispatchEvent = Window.prototype.dispatchEvent = Document.prototype.dispatchEvent = Element.prototype.dispatchEvent = function dispatchEvent(event) {
  			if (!arguments.length) {
  				throw new Error('Not enough arguments');
  			}
  
  			if (!event || typeof event.type !== 'string') {
  				throw new Error('DOM Events Exception 0');
  			}
  
  			var element = this, type = event.type;
  
  			try {
  				if (!event.bubbles) {
  					event.cancelBubble = true;
  
  					var cancelBubbleEvent = function (event) {
  						event.cancelBubble = true;
  
  						(element || window).detachEvent('on' + type, cancelBubbleEvent);
  					};
  
  					this.attachEvent('on' + type, cancelBubbleEvent);
  				}
  
  				this.fireEvent('on' + type, event);
  			} catch (error) {
  				event.target = element;
  
  				do {
  					event.currentTarget = element;
  
  					if ('_events' in element && typeof element._events[type] === 'function') {
  						element._events[type].call(element, event);
  					}
  
  					if (typeof element['on' + type] === 'function') {
  						element['on' + type].call(element, event);
  					}
  
  					element = element.nodeType === 9 ? element.parentWindow : element.parentNode;
  				} while (element && !event.cancelBubble);
  			}
  
  			return true;
  		};
  
  		// Add the DOMContentLoaded Event
  		document.attachEvent('onreadystatechange', function() {
  			if (document.readyState === 'complete') {
  				document.dispatchEvent(new Event('DOMContentLoaded', {
  					bubbles: true
  				}));
  			}
  		});
  	}
  }());
  
  })
  .call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  var KEY_SPACE = 32;
  var DEBOUNCE_TIMEOUT_IN_SECONDS = 1;
  
  function Button ($module) {
    this.$module = $module;
    this.debounceFormSubmitTimer = null;
  }
  
  /**
  * JavaScript 'shim' to trigger the click event of element(s) when the space key is pressed.
  *
  * Created since some Assistive Technologies (for example some Screenreaders)
  * will tell a user to press space on a 'button', so this functionality needs to be shimmed
  * See https://github.com/alphagov/govuk_elements/pull/272#issuecomment-233028270
  *
  * @param {object} event event
  */
  Button.prototype.handleKeyDown = function (event) {
    // get the target element
    var target = event.target;
    // if the element has a role='button' and the pressed key is a space, we'll simulate a click
    if (target.getAttribute('role') === 'button' && event.keyCode === KEY_SPACE) {
      event.preventDefault();
      // trigger the target's click event
      target.click();
    }
  };
  
  /**
  * If the click quickly succeeds a previous click then nothing will happen.
  * This stops people accidentally causing multiple form submissions by
  * double clicking buttons.
  */
  Button.prototype.debounce = function (event) {
    var target = event.target;
    // Check the button that is clicked on has the preventDoubleClick feature enabled
    if (target.getAttribute('data-prevent-double-click') !== 'true') {
      return
    }
  
    // If the timer is still running then we want to prevent the click from submitting the form
    if (this.debounceFormSubmitTimer) {
      event.preventDefault();
      return false
    }
  
    this.debounceFormSubmitTimer = setTimeout(function () {
      this.debounceFormSubmitTimer = null;
    }.bind(this), DEBOUNCE_TIMEOUT_IN_SECONDS * 1000);
  };
  
  /**
  * Initialise an event listener for keydown at document level
  * this will help listening for later inserted elements with a role="button"
  */
  Button.prototype.init = function () {
    this.$module.addEventListener('keydown', this.handleKeyDown);
    this.$module.addEventListener('click', this.debounce);
  };
  
  /**
   * JavaScript 'polyfill' for HTML5's <details> and <summary> elements
   * and 'shim' to add accessiblity enhancements for all browsers
   *
   * http://caniuse.com/#feat=details
   */
  
  var KEY_ENTER = 13;
  var KEY_SPACE$1 = 32;
  
  function Details ($module) {
    this.$module = $module;
  }
  
  Details.prototype.init = function () {
    if (!this.$module) {
      return
    }
  
    // If there is native details support, we want to avoid running code to polyfill native behaviour.
    var hasNativeDetails = typeof this.$module.open === 'boolean';
  
    if (hasNativeDetails) {
      return
    }
  
    this.polyfillDetails();
  };
  
  Details.prototype.polyfillDetails = function () {
    var $module = this.$module;
  
    // Save shortcuts to the inner summary and content elements
    var $summary = this.$summary = $module.getElementsByTagName('summary').item(0);
    var $content = this.$content = $module.getElementsByTagName('div').item(0);
  
    // If <details> doesn't have a <summary> and a <div> representing the content
    // it means the required HTML structure is not met so the script will stop
    if (!$summary || !$content) {
      return
    }
  
    // If the content doesn't have an ID, assign it one now
    // which we'll need for the summary's aria-controls assignment
    if (!$content.id) {
      $content.id = 'details-content-' + generateUniqueID();
    }
  
    // Add ARIA role="group" to details
    $module.setAttribute('role', 'group');
  
    // Add role=button to summary
    $summary.setAttribute('role', 'button');
  
    // Add aria-controls
    $summary.setAttribute('aria-controls', $content.id);
  
    // Set tabIndex so the summary is keyboard accessible for non-native elements
    //
    // We have to use the camelcase `tabIndex` property as there is a bug in IE6/IE7 when we set the correct attribute lowercase:
    // See http://web.archive.org/web/20170120194036/http://www.saliences.com/browserBugs/tabIndex.html for more information.
    $summary.tabIndex = 0;
  
    // Detect initial open state
    var openAttr = $module.getAttribute('open') !== null;
    if (openAttr === true) {
      $summary.setAttribute('aria-expanded', 'true');
      $content.setAttribute('aria-hidden', 'false');
    } else {
      $summary.setAttribute('aria-expanded', 'false');
      $content.setAttribute('aria-hidden', 'true');
      $content.style.display = 'none';
    }
  
    // Bind an event to handle summary elements
    this.polyfillHandleInputs($summary, this.polyfillSetAttributes.bind(this));
  };
  
  /**
  * Define a statechange function that updates aria-expanded and style.display
  * @param {object} summary element
  */
  Details.prototype.polyfillSetAttributes = function () {
    var $module = this.$module;
    var $summary = this.$summary;
    var $content = this.$content;
  
    var expanded = $summary.getAttribute('aria-expanded') === 'true';
    var hidden = $content.getAttribute('aria-hidden') === 'true';
  
    $summary.setAttribute('aria-expanded', (expanded ? 'false' : 'true'));
    $content.setAttribute('aria-hidden', (hidden ? 'false' : 'true'));
  
    $content.style.display = (expanded ? 'none' : '');
  
    var hasOpenAttr = $module.getAttribute('open') !== null;
    if (!hasOpenAttr) {
      $module.setAttribute('open', 'open');
    } else {
      $module.removeAttribute('open');
    }
  
    return true
  };
  
  /**
  * Handle cross-modal click events
  * @param {object} node element
  * @param {function} callback function
  */
  Details.prototype.polyfillHandleInputs = function (node, callback) {
    node.addEventListener('keypress', function (event) {
      var target = event.target;
      // When the key gets pressed - check if it is enter or space
      if (event.keyCode === KEY_ENTER || event.keyCode === KEY_SPACE$1) {
        if (target.nodeName.toLowerCase() === 'summary') {
          // Prevent space from scrolling the page
          // and enter from submitting a form
          event.preventDefault();
          // Click to let the click event do all the necessary action
          if (target.click) {
            target.click();
          } else {
            // except Safari 5.1 and under don't support .click() here
            callback(event);
          }
        }
      }
    });
  
    // Prevent keyup to prevent clicking twice in Firefox when using space key
    node.addEventListener('keyup', function (event) {
      var target = event.target;
      if (event.keyCode === KEY_SPACE$1) {
        if (target.nodeName.toLowerCase() === 'summary') {
          event.preventDefault();
        }
      }
    });
  
    node.addEventListener('click', callback);
  };
  
  function CharacterCount ($module) {
    this.$module = $module;
    this.$textarea = $module.querySelector('.govuk-js-character-count');
    if (this.$textarea) {
      this.$countMessage = $module.querySelector('[id=' + this.$textarea.id + '-info]');
    }
  }
  
  CharacterCount.prototype.defaults = {
    characterCountAttribute: 'data-maxlength',
    wordCountAttribute: 'data-maxwords'
  };
  
  // Initialize component
  CharacterCount.prototype.init = function () {
    // Check for module
    var $module = this.$module;
    var $textarea = this.$textarea;
    var $countMessage = this.$countMessage;
  
    if (!$textarea || !$countMessage) {
      return
    }
  
    // We move count message right after the field
    // Kept for backwards compatibility
    $textarea.insertAdjacentElement('afterend', $countMessage);
  
    // Read options set using dataset ('data-' values)
    this.options = this.getDataset($module);
  
    // Determine the limit attribute (characters or words)
    var countAttribute = this.defaults.characterCountAttribute;
    if (this.options.maxwords) {
      countAttribute = this.defaults.wordCountAttribute;
    }
  
    // Save the element limit
    this.maxLength = $module.getAttribute(countAttribute);
  
    // Check for limit
    if (!this.maxLength) {
      return
    }
  
    // Remove hard limit if set
    $module.removeAttribute('maxlength');
  
    // When the page is restored after navigating 'back' in some browsers the
    // state of the character count is not restored until *after* the DOMContentLoaded
    // event is fired, so we need to sync after the pageshow event in browsers
    // that support it.
    if ('onpageshow' in window) {
      window.addEventListener('pageshow', this.sync.bind(this));
    } else {
      window.addEventListener('DOMContentLoaded', this.sync.bind(this));
    }
  
    this.sync();
  };
  
  CharacterCount.prototype.sync = function () {
    this.bindChangeEvents();
    this.updateCountMessage();
  };
  
  // Read data attributes
  CharacterCount.prototype.getDataset = function (element) {
    var dataset = {};
    var attributes = element.attributes;
    if (attributes) {
      for (var i = 0; i < attributes.length; i++) {
        var attribute = attributes[i];
        var match = attribute.name.match(/^data-(.+)/);
        if (match) {
          dataset[match[1]] = attribute.value;
        }
      }
    }
    return dataset
  };
  
  // Counts characters or words in text
  CharacterCount.prototype.count = function (text) {
    var length;
    if (this.options.maxwords) {
      var tokens = text.match(/\S+/g) || []; // Matches consecutive non-whitespace chars
      length = tokens.length;
    } else {
      length = text.length;
    }
    return length
  };
  
  // Bind input propertychange to the elements and update based on the change
  CharacterCount.prototype.bindChangeEvents = function () {
    var $textarea = this.$textarea;
    $textarea.addEventListener('keyup', this.checkIfValueChanged.bind(this));
  
    // Bind focus/blur events to start/stop polling
    $textarea.addEventListener('focus', this.handleFocus.bind(this));
    $textarea.addEventListener('blur', this.handleBlur.bind(this));
  };
  
  // Speech recognition software such as Dragon NaturallySpeaking will modify the
  // fields by directly changing its `value`. These changes don't trigger events
  // in JavaScript, so we need to poll to handle when and if they occur.
  CharacterCount.prototype.checkIfValueChanged = function () {
    if (!this.$textarea.oldValue) this.$textarea.oldValue = '';
    if (this.$textarea.value !== this.$textarea.oldValue) {
      this.$textarea.oldValue = this.$textarea.value;
      this.updateCountMessage();
    }
  };
  
  // Update message box
  CharacterCount.prototype.updateCountMessage = function () {
    var countElement = this.$textarea;
    var options = this.options;
    var countMessage = this.$countMessage;
  
    // Determine the remaining number of characters/words
    var currentLength = this.count(countElement.value);
    var maxLength = this.maxLength;
    var remainingNumber = maxLength - currentLength;
  
    // Set threshold if presented in options
    var thresholdPercent = options.threshold ? options.threshold : 0;
    var thresholdValue = maxLength * thresholdPercent / 100;
    if (thresholdValue > currentLength) {
      countMessage.classList.add('govuk-character-count__message--disabled');
      // Ensure threshold is hidden for users of assistive technologies
      countMessage.setAttribute('aria-hidden', true);
    } else {
      countMessage.classList.remove('govuk-character-count__message--disabled');
      // Ensure threshold is visible for users of assistive technologies
      countMessage.removeAttribute('aria-hidden');
    }
  
    // Update styles
    if (remainingNumber < 0) {
      countElement.classList.add('govuk-textarea--error');
      countMessage.classList.remove('govuk-hint');
      countMessage.classList.add('govuk-error-message');
    } else {
      countElement.classList.remove('govuk-textarea--error');
      countMessage.classList.remove('govuk-error-message');
      countMessage.classList.add('govuk-hint');
    }
  
    // Update message
    var charVerb = 'remaining';
    var charNoun = 'character';
    var displayNumber = remainingNumber;
    if (options.maxwords) {
      charNoun = 'word';
    }
    charNoun = charNoun + ((remainingNumber === -1 || remainingNumber === 1) ? '' : 's');
  
    charVerb = (remainingNumber < 0) ? 'too many' : 'remaining';
    displayNumber = Math.abs(remainingNumber);
  
    countMessage.innerHTML = 'You have ' + displayNumber + ' ' + charNoun + ' ' + charVerb;
  };
  
  CharacterCount.prototype.handleFocus = function () {
    // Check if value changed on focus
    this.valueChecker = setInterval(this.checkIfValueChanged.bind(this), 1000);
  };
  
  CharacterCount.prototype.handleBlur = function () {
    // Cancel value checking on blur
    clearInterval(this.valueChecker);
  };
  
  function Checkboxes ($module) {
    this.$module = $module;
    this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
  }
  
  /**
   * Initialise Checkboxes
   *
   * Checkboxes can be associated with a 'conditionally revealed' content block –
   * for example, a checkbox for 'Phone' could reveal an additional form field for
   * the user to enter their phone number.
   *
   * These associations are made using a `data-aria-controls` attribute, which is
   * promoted to an aria-controls attribute during initialisation.
   *
   * We also need to restore the state of any conditional reveals on the page (for
   * example if the user has navigated back), and set up event handlers to keep
   * the reveal in sync with the checkbox state.
   */
  Checkboxes.prototype.init = function () {
    var $module = this.$module;
    var $inputs = this.$inputs;
  
    nodeListForEach($inputs, function ($input) {
      var target = $input.getAttribute('data-aria-controls');
  
      // Skip checkboxes without data-aria-controls attributes, or where the
      // target element does not exist.
      if (!target || !$module.querySelector('#' + target)) {
        return
      }
  
      // Promote the data-aria-controls attribute to a aria-controls attribute
      // so that the relationship is exposed in the AOM
      $input.setAttribute('aria-controls', target);
      $input.removeAttribute('data-aria-controls');
    });
  
    // When the page is restored after navigating 'back' in some browsers the
    // state of form controls is not restored until *after* the DOMContentLoaded
    // event is fired, so we need to sync after the pageshow event in browsers
    // that support it.
    if ('onpageshow' in window) {
      window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
    } else {
      window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
    }
  
    // Although we've set up handlers to sync state on the pageshow or
    // DOMContentLoaded event, init could be called after those events have fired,
    // for example if they are added to the page dynamically, so sync now too.
    this.syncAllConditionalReveals();
  
    $module.addEventListener('click', this.handleClick.bind(this));
  };
  
  /**
   * Sync the conditional reveal states for all inputs in this $module.
   */
  Checkboxes.prototype.syncAllConditionalReveals = function () {
    nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
  };
  
  /**
   * Sync conditional reveal with the input state
   *
   * Synchronise the visibility of the conditional reveal, and its accessible
   * state, with the input's checked state.
   *
   * @param {HTMLInputElement} $input Checkbox input
   */
  Checkboxes.prototype.syncConditionalRevealWithInputState = function ($input) {
    var $target = this.$module.querySelector('#' + $input.getAttribute('aria-controls'));
  
    if ($target && $target.classList.contains('govuk-checkboxes__conditional')) {
      var inputIsChecked = $input.checked;
  
      $input.setAttribute('aria-expanded', inputIsChecked);
      $target.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
    }
  };
  
  /**
   * Click event handler
   *
   * Handle a click within the $module – if the click occurred on a checkbox, sync
   * the state of any associated conditional reveal with the checkbox state.
   *
   * @param {MouseEvent} event Click event
   */
  Checkboxes.prototype.handleClick = function (event) {
    var $target = event.target;
  
    // If a checkbox with aria-controls, handle click
    var isCheckbox = $target.getAttribute('type') === 'checkbox';
    var hasAriaControls = $target.getAttribute('aria-controls');
    if (isCheckbox && hasAriaControls) {
      this.syncConditionalRevealWithInputState($target);
    }
  };
  
  (function(undefined) {
  
    // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/detect.js
    var detect = (
      'document' in this && "matches" in document.documentElement
    );
  
    if (detect) return
  
    // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/matches/polyfill.js
    Element.prototype.matches = Element.prototype.webkitMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.mozMatchesSelector || function matches(selector) {
      var element = this;
      var elements = (element.document || element.ownerDocument).querySelectorAll(selector);
      var index = 0;
  
      while (elements[index] && elements[index] !== element) {
        ++index;
      }
  
      return !!elements[index];
    };
  
  }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
  
    // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/detect.js
    var detect = (
      'document' in this && "closest" in document.documentElement
    );
  
    if (detect) return
  
    // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-service/1f3c09b402f65bf6e393f933a15ba63f1b86ef1f/packages/polyfill-library/polyfills/Element/prototype/closest/polyfill.js
    Element.prototype.closest = function closest(selector) {
      var node = this;
  
      while (node) {
        if (node.matches(selector)) return node;
        else node = 'SVGElement' in window && node instanceof SVGElement ? node.parentNode : node.parentElement;
      }
  
      return null;
    };
  
  }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  function ErrorSummary ($module) {
    this.$module = $module;
  }
  
  ErrorSummary.prototype.init = function () {
    var $module = this.$module;
    if (!$module) {
      return
    }
    $module.focus();
  
    $module.addEventListener('click', this.handleClick.bind(this));
  };
  
  /**
  * Click event handler
  *
  * @param {MouseEvent} event - Click event
  */
  ErrorSummary.prototype.handleClick = function (event) {
    var target = event.target;
    if (this.focusTarget(target)) {
      event.preventDefault();
    }
  };
  
  /**
   * Focus the target element
   *
   * By default, the browser will scroll the target into view. Because our labels
   * or legends appear above the input, this means the user will be presented with
   * an input without any context, as the label or legend will be off the top of
   * the screen.
   *
   * Manually handling the click event, scrolling the question into view and then
   * focussing the element solves this.
   *
   * This also results in the label and/or legend being announced correctly in
   * NVDA (as tested in 2018.3.2) - without this only the field type is announced
   * (e.g. "Edit, has autocomplete").
   *
   * @param {HTMLElement} $target - Event target
   * @returns {boolean} True if the target was able to be focussed
   */
  ErrorSummary.prototype.focusTarget = function ($target) {
    // If the element that was clicked was not a link, return early
    if ($target.tagName !== 'A' || $target.href === false) {
      return false
    }
  
    var inputId = this.getFragmentFromUrl($target.href);
    var $input = document.getElementById(inputId);
    if (!$input) {
      return false
    }
  
    var $legendOrLabel = this.getAssociatedLegendOrLabel($input);
    if (!$legendOrLabel) {
      return false
    }
  
    // Scroll the legend or label into view *before* calling focus on the input to
    // avoid extra scrolling in browsers that don't support `preventScroll` (which
    // at time of writing is most of them...)
    $legendOrLabel.scrollIntoView();
    $input.focus({ preventScroll: true });
  
    return true
  };
  
  /**
   * Get fragment from URL
   *
   * Extract the fragment (everything after the hash) from a URL, but not including
   * the hash.
   *
   * @param {string} url - URL
   * @returns {string} Fragment from URL, without the hash
   */
  ErrorSummary.prototype.getFragmentFromUrl = function (url) {
    if (url.indexOf('#') === -1) {
      return false
    }
  
    return url.split('#').pop()
  };
  
  /**
   * Get associated legend or label
   *
   * Returns the first element that exists from this list:
   *
   * - The `<legend>` associated with the closest `<fieldset>` ancestor, as long
   *   as the top of it is no more than half a viewport height away from the
   *   bottom of the input
   * - The first `<label>` that is associated with the input using for="inputId"
   * - The closest parent `<label>`
   *
   * @param {HTMLElement} $input - The input
   * @returns {HTMLElement} Associated legend or label, or null if no associated
   *                        legend or label can be found
   */
  ErrorSummary.prototype.getAssociatedLegendOrLabel = function ($input) {
    var $fieldset = $input.closest('fieldset');
  
    if ($fieldset) {
      var legends = $fieldset.getElementsByTagName('legend');
  
      if (legends.length) {
        var $candidateLegend = legends[0];
  
        // If the input type is radio or checkbox, always use the legend if there
        // is one.
        if ($input.type === 'checkbox' || $input.type === 'radio') {
          return $candidateLegend
        }
  
        // For other input types, only scroll to the fieldset’s legend (instead of
        // the label associated with the input) if the input would end up in the
        // top half of the screen.
        //
        // This should avoid situations where the input either ends up off the
        // screen, or obscured by a software keyboard.
        var legendTop = $candidateLegend.getBoundingClientRect().top;
        var inputRect = $input.getBoundingClientRect();
  
        // If the browser doesn't support Element.getBoundingClientRect().height
        // or window.innerHeight (like IE8), bail and just link to the label.
        if (inputRect.height && window.innerHeight) {
          var inputBottom = inputRect.top + inputRect.height;
  
          if (inputBottom - legendTop < window.innerHeight / 2) {
            return $candidateLegend
          }
        }
      }
    }
  
    return document.querySelector("label[for='" + $input.getAttribute('id') + "']") ||
      $input.closest('label')
  };
  
  function Header ($module) {
    this.$module = $module;
    this.$menuButton = $module && $module.querySelector('.govuk-js-header-toggle');
    this.$menu = this.$menuButton && $module.querySelector(
      '#' + this.$menuButton.getAttribute('aria-controls')
    );
  }
  
  /**
   * Initialise header
   *
   * Check for the presence of the header, menu and menu button – if any are
   * missing then there's nothing to do so return early.
   */
  Header.prototype.init = function () {
    if (!this.$module || !this.$menuButton || !this.$menu) {
      return
    }
  
    this.syncState(this.$menu.classList.contains('govuk-header__navigation--open'));
    this.$menuButton.addEventListener('click', this.handleMenuButtonClick.bind(this));
  };
  
  /**
   * Sync menu state
   *
   * Sync the menu button class and the accessible state of the menu and the menu
   * button with the visible state of the menu
   *
   * @param {boolean} isVisible Whether the menu is currently visible
   */
  Header.prototype.syncState = function (isVisible) {
    this.$menuButton.classList.toggle('govuk-header__menu-button--open', isVisible);
    this.$menuButton.setAttribute('aria-expanded', isVisible);
  };
  
  /**
   * Handle menu button click
   *
   * When the menu button is clicked, change the visibility of the menu and then
   * sync the accessibility state and menu button state
   */
  Header.prototype.handleMenuButtonClick = function () {
    var isVisible = this.$menu.classList.toggle('govuk-header__navigation--open');
    this.syncState(isVisible);
  };
  
  function Radios ($module) {
    this.$module = $module;
    this.$inputs = $module.querySelectorAll('input[type="radio"]');
  }
  
  /**
   * Initialise Radios
   *
   * Radios can be associated with a 'conditionally revealed' content block – for
   * example, a radio for 'Phone' could reveal an additional form field for the
   * user to enter their phone number.
   *
   * These associations are made using a `data-aria-controls` attribute, which is
   * promoted to an aria-controls attribute during initialisation.
   *
   * We also need to restore the state of any conditional reveals on the page (for
   * example if the user has navigated back), and set up event handlers to keep
   * the reveal in sync with the radio state.
   */
  Radios.prototype.init = function () {
    var $module = this.$module;
    var $inputs = this.$inputs;
  
    nodeListForEach($inputs, function ($input) {
      var target = $input.getAttribute('data-aria-controls');
  
      // Skip radios without data-aria-controls attributes, or where the
      // target element does not exist.
      if (!target || !$module.querySelector('#' + target)) {
        return
      }
  
      // Promote the data-aria-controls attribute to a aria-controls attribute
      // so that the relationship is exposed in the AOM
      $input.setAttribute('aria-controls', target);
      $input.removeAttribute('data-aria-controls');
    });
  
    // When the page is restored after navigating 'back' in some browsers the
    // state of form controls is not restored until *after* the DOMContentLoaded
    // event is fired, so we need to sync after the pageshow event in browsers
    // that support it.
    if ('onpageshow' in window) {
      window.addEventListener('pageshow', this.syncAllConditionalReveals.bind(this));
    } else {
      window.addEventListener('DOMContentLoaded', this.syncAllConditionalReveals.bind(this));
    }
  
    // Although we've set up handlers to sync state on the pageshow or
    // DOMContentLoaded event, init could be called after those events have fired,
    // for example if they are added to the page dynamically, so sync now too.
    this.syncAllConditionalReveals();
  
    // Handle events
    $module.addEventListener('click', this.handleClick.bind(this));
  };
  
  /**
   * Sync the conditional reveal states for all inputs in this $module.
   */
  Radios.prototype.syncAllConditionalReveals = function () {
    nodeListForEach(this.$inputs, this.syncConditionalRevealWithInputState.bind(this));
  };
  
  /**
   * Sync conditional reveal with the input state
   *
   * Synchronise the visibility of the conditional reveal, and its accessible
   * state, with the input's checked state.
   *
   * @param {HTMLInputElement} $input Radio input
   */
  Radios.prototype.syncConditionalRevealWithInputState = function ($input) {
    var $target = document.querySelector('#' + $input.getAttribute('aria-controls'));
  
    if ($target && $target.classList.contains('govuk-radios__conditional')) {
      var inputIsChecked = $input.checked;
  
      $input.setAttribute('aria-expanded', inputIsChecked);
      $target.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
    }
  };
  
  /**
   * Click event handler
   *
   * Handle a click within the $module – if the click occurred on a radio, sync
   * the state of the conditional reveal for all radio buttons in the same form
   * with the same name (because checking one radio could have un-checked a radio
   * in another $module)
   *
   * @param {MouseEvent} event Click event
   */
  Radios.prototype.handleClick = function (event) {
    var $clickedInput = event.target;
  
    // Ignore clicks on things that aren't radio buttons
    if ($clickedInput.type !== 'radio') {
      return
    }
  
    // We only need to consider radios with conditional reveals, which will have
    // aria-controls attributes.
    var $allInputs = document.querySelectorAll('input[type="radio"][aria-controls]');
  
    nodeListForEach($allInputs, function ($input) {
      var hasSameFormOwner = ($input.form === $clickedInput.form);
      var hasSameName = ($input.name === $clickedInput.name);
  
      if (hasSameName && hasSameFormOwner) {
        this.syncConditionalRevealWithInputState($input);
      }
    }.bind(this));
  };
  
  (function(undefined) {
  
      // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/detect.js
      var detect = (
        'document' in this && "nextElementSibling" in document.documentElement
      );
  
      if (detect) return
  
      // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/nextElementSibling/polyfill.js
      Object.defineProperty(Element.prototype, "nextElementSibling", {
        get: function(){
          var el = this.nextSibling;
          while (el && el.nodeType !== 1) { el = el.nextSibling; }
          return el;
        }
      });
  
  }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  (function(undefined) {
  
      // Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/detect.js
      var detect = (
        'document' in this && "previousElementSibling" in document.documentElement
      );
  
      if (detect) return
  
      // Polyfill from https://raw.githubusercontent.com/Financial-Times/polyfill-library/master/polyfills/Element/prototype/previousElementSibling/polyfill.js
      Object.defineProperty(Element.prototype, 'previousElementSibling', {
        get: function(){
          var el = this.previousSibling;
          while (el && el.nodeType !== 1) { el = el.previousSibling; }
          return el;
        }
      });
  
  }).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
  
  function Tabs ($module) {
    this.$module = $module;
    this.$tabs = $module.querySelectorAll('.govuk-tabs__tab');
  
    this.keys = { left: 37, right: 39, up: 38, down: 40 };
    this.jsHiddenClass = 'govuk-tabs__panel--hidden';
  }
  
  Tabs.prototype.init = function () {
    if (typeof window.matchMedia === 'function') {
      this.setupResponsiveChecks();
    } else {
      this.setup();
    }
  };
  
  Tabs.prototype.setupResponsiveChecks = function () {
    this.mql = window.matchMedia('(min-width: 40.0625em)');
    this.mql.addListener(this.checkMode.bind(this));
    this.checkMode();
  };
  
  Tabs.prototype.checkMode = function () {
    if (this.mql.matches) {
      this.setup();
    } else {
      this.teardown();
    }
  };
  
  Tabs.prototype.setup = function () {
    var $module = this.$module;
    var $tabs = this.$tabs;
    var $tabList = $module.querySelector('.govuk-tabs__list');
    var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
  
    if (!$tabs || !$tabList || !$tabListItems) {
      return
    }
  
    $tabList.setAttribute('role', 'tablist');
  
    nodeListForEach($tabListItems, function ($item) {
      $item.setAttribute('role', 'presentation');
    });
  
    nodeListForEach($tabs, function ($tab) {
      // Set HTML attributes
      this.setAttributes($tab);
  
      // Save bounded functions to use when removing event listeners during teardown
      $tab.boundTabClick = this.onTabClick.bind(this);
      $tab.boundTabKeydown = this.onTabKeydown.bind(this);
  
      // Handle events
      $tab.addEventListener('click', $tab.boundTabClick, true);
      $tab.addEventListener('keydown', $tab.boundTabKeydown, true);
  
      // Remove old active panels
      this.hideTab($tab);
    }.bind(this));
  
    // Show either the active tab according to the URL's hash or the first tab
    var $activeTab = this.getTab(window.location.hash) || this.$tabs[0];
    this.showTab($activeTab);
  
    // Handle hashchange events
    $module.boundOnHashChange = this.onHashChange.bind(this);
    window.addEventListener('hashchange', $module.boundOnHashChange, true);
  };
  
  Tabs.prototype.teardown = function () {
    var $module = this.$module;
    var $tabs = this.$tabs;
    var $tabList = $module.querySelector('.govuk-tabs__list');
    var $tabListItems = $module.querySelectorAll('.govuk-tabs__list-item');
  
    if (!$tabs || !$tabList || !$tabListItems) {
      return
    }
  
    $tabList.removeAttribute('role');
  
    nodeListForEach($tabListItems, function ($item) {
      $item.removeAttribute('role', 'presentation');
    });
  
    nodeListForEach($tabs, function ($tab) {
      // Remove events
      $tab.removeEventListener('click', $tab.boundTabClick, true);
      $tab.removeEventListener('keydown', $tab.boundTabKeydown, true);
  
      // Unset HTML attributes
      this.unsetAttributes($tab);
    }.bind(this));
  
    // Remove hashchange event handler
    window.removeEventListener('hashchange', $module.boundOnHashChange, true);
  };
  
  Tabs.prototype.onHashChange = function (e) {
    var hash = window.location.hash;
    var $tabWithHash = this.getTab(hash);
    if (!$tabWithHash) {
      return
    }
  
    // Prevent changing the hash
    if (this.changingHash) {
      this.changingHash = false;
      return
    }
  
    // Show either the active tab according to the URL's hash or the first tab
    var $previousTab = this.getCurrentTab();
  
    this.hideTab($previousTab);
    this.showTab($tabWithHash);
    $tabWithHash.focus();
  };
  
  Tabs.prototype.hideTab = function ($tab) {
    this.unhighlightTab($tab);
    this.hidePanel($tab);
  };
  
  Tabs.prototype.showTab = function ($tab) {
    this.highlightTab($tab);
    this.showPanel($tab);
  };
  
  Tabs.prototype.getTab = function (hash) {
    return this.$module.querySelector('.govuk-tabs__tab[href="' + hash + '"]')
  };
  
  Tabs.prototype.setAttributes = function ($tab) {
    // set tab attributes
    var panelId = this.getHref($tab).slice(1);
    $tab.setAttribute('id', 'tab_' + panelId);
    $tab.setAttribute('role', 'tab');
    $tab.setAttribute('aria-controls', panelId);
    $tab.setAttribute('aria-selected', 'false');
    $tab.setAttribute('tabindex', '-1');
  
    // set panel attributes
    var $panel = this.getPanel($tab);
    $panel.setAttribute('role', 'tabpanel');
    $panel.setAttribute('aria-labelledby', $tab.id);
    $panel.classList.add(this.jsHiddenClass);
  };
  
  Tabs.prototype.unsetAttributes = function ($tab) {
    // unset tab attributes
    $tab.removeAttribute('id');
    $tab.removeAttribute('role');
    $tab.removeAttribute('aria-controls');
    $tab.removeAttribute('aria-selected');
    $tab.removeAttribute('tabindex');
  
    // unset panel attributes
    var $panel = this.getPanel($tab);
    $panel.removeAttribute('role');
    $panel.removeAttribute('aria-labelledby');
    $panel.classList.remove(this.jsHiddenClass);
  };
  
  Tabs.prototype.onTabClick = function (e) {
    if (!e.target.classList.contains('govuk-tabs__tab')) {
    // Allow events on child DOM elements to bubble up to tab parent
      return false
    }
    e.preventDefault();
    var $newTab = e.target;
    var $currentTab = this.getCurrentTab();
    this.hideTab($currentTab);
    this.showTab($newTab);
    this.createHistoryEntry($newTab);
  };
  
  Tabs.prototype.createHistoryEntry = function ($tab) {
    var $panel = this.getPanel($tab);
  
    // Save and restore the id
    // so the page doesn't jump when a user clicks a tab (which changes the hash)
    var id = $panel.id;
    $panel.id = '';
    this.changingHash = true;
    window.location.hash = this.getHref($tab).slice(1);
    $panel.id = id;
  };
  
  Tabs.prototype.onTabKeydown = function (e) {
    switch (e.keyCode) {
      case this.keys.left:
      case this.keys.up:
        this.activatePreviousTab();
        e.preventDefault();
        break
      case this.keys.right:
      case this.keys.down:
        this.activateNextTab();
        e.preventDefault();
        break
    }
  };
  
  Tabs.prototype.activateNextTab = function () {
    var currentTab = this.getCurrentTab();
    var nextTabListItem = currentTab.parentNode.nextElementSibling;
    if (nextTabListItem) {
      var nextTab = nextTabListItem.querySelector('.govuk-tabs__tab');
    }
    if (nextTab) {
      this.hideTab(currentTab);
      this.showTab(nextTab);
      nextTab.focus();
      this.createHistoryEntry(nextTab);
    }
  };
  
  Tabs.prototype.activatePreviousTab = function () {
    var currentTab = this.getCurrentTab();
    var previousTabListItem = currentTab.parentNode.previousElementSibling;
    if (previousTabListItem) {
      var previousTab = previousTabListItem.querySelector('.govuk-tabs__tab');
    }
    if (previousTab) {
      this.hideTab(currentTab);
      this.showTab(previousTab);
      previousTab.focus();
      this.createHistoryEntry(previousTab);
    }
  };
  
  Tabs.prototype.getPanel = function ($tab) {
    var $panel = this.$module.querySelector(this.getHref($tab));
    return $panel
  };
  
  Tabs.prototype.showPanel = function ($tab) {
    var $panel = this.getPanel($tab);
    $panel.classList.remove(this.jsHiddenClass);
  };
  
  Tabs.prototype.hidePanel = function (tab) {
    var $panel = this.getPanel(tab);
    $panel.classList.add(this.jsHiddenClass);
  };
  
  Tabs.prototype.unhighlightTab = function ($tab) {
    $tab.setAttribute('aria-selected', 'false');
    $tab.parentNode.classList.remove('govuk-tabs__list-item--selected');
    $tab.setAttribute('tabindex', '-1');
  };
  
  Tabs.prototype.highlightTab = function ($tab) {
    $tab.setAttribute('aria-selected', 'true');
    $tab.parentNode.classList.add('govuk-tabs__list-item--selected');
    $tab.setAttribute('tabindex', '0');
  };
  
  Tabs.prototype.getCurrentTab = function () {
    return this.$module.querySelector('.govuk-tabs__list-item--selected .govuk-tabs__tab')
  };
  
  // this is because IE doesn't always return the actual value but a relative full path
  // should be a utility function most prob
  // http://labs.thesedays.com/blog/2010/01/08/getting-the-href-value-with-jquery-in-ie/
  Tabs.prototype.getHref = function ($tab) {
    var href = $tab.getAttribute('href');
    var hash = href.slice(href.indexOf('#'), href.length);
    return hash
  };
  
  function initAll (options) {
    // Set the options to an empty object by default if no options are passed.
    options = typeof options !== 'undefined' ? options : {};
  
    // Allow the user to initialise GOV.UK Frontend in only certain sections of the page
    // Defaults to the entire document if nothing is set.
    var scope = typeof options.scope !== 'undefined' ? options.scope : document;
  
    var $buttons = scope.querySelectorAll('[data-module="govuk-button"]');
    nodeListForEach($buttons, function ($button) {
      new Button($button).init();
    });
  
    var $accordions = scope.querySelectorAll('[data-module="govuk-accordion"]');
    nodeListForEach($accordions, function ($accordion) {
      new Accordion($accordion).init();
    });
  
    var $details = scope.querySelectorAll('[data-module="govuk-details"]');
    nodeListForEach($details, function ($detail) {
      new Details($detail).init();
    });
  
    var $characterCounts = scope.querySelectorAll('[data-module="govuk-character-count"]');
    nodeListForEach($characterCounts, function ($characterCount) {
      new CharacterCount($characterCount).init();
    });
  
    var $checkboxes = scope.querySelectorAll('[data-module="govuk-checkboxes"]');
    nodeListForEach($checkboxes, function ($checkbox) {
      new Checkboxes($checkbox).init();
    });
  
    // Find first error summary module to enhance.
    var $errorSummary = scope.querySelector('[data-module="govuk-error-summary"]');
    new ErrorSummary($errorSummary).init();
  
    // Find first header module to enhance.
    var $toggleButton = scope.querySelector('[data-module="govuk-header"]');
    new Header($toggleButton).init();
  
    var $radios = scope.querySelectorAll('[data-module="govuk-radios"]');
    nodeListForEach($radios, function ($radio) {
      new Radios($radio).init();
    });
  
    var $tabs = scope.querySelectorAll('[data-module="govuk-tabs"]');
    nodeListForEach($tabs, function ($tabs) {
      new Tabs($tabs).init();
    });
  }
  
  exports.initAll = initAll;
  exports.Accordion = Accordion;
  exports.Button = Button;
  exports.Details = Details;
  exports.CharacterCount = CharacterCount;
  exports.Checkboxes = Checkboxes;
  exports.ErrorSummary = ErrorSummary;
  exports.Header = Header;
  exports.Radios = Radios;
  exports.Tabs = Tabs;
  
  })));
  