@threespot/expand-toggle
Advanced tools
Comparing version 1.3.0 to 1.3.2
@@ -1,1 +0,1 @@ | ||
define("expand-toggleLink",[],function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=14)}([function(t,e,n){var i=n(1).Symbol;t.exports=i},function(t,e,n){var i=n(11),r="object"==typeof self&&self&&self.Object===Object&&self,o=i||r||Function("return this")();t.exports=o},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,n){var i,r;"undefined"!=typeof window&&window,void 0===(r="function"==typeof(i=function(){"use strict";function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var n=this._events=this._events||{},i=n[t]=n[t]||[];return-1==i.indexOf(e)&&i.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var n=this._onceEvents=this._onceEvents||{};return(n[t]=n[t]||{})[e]=!0,this}},e.off=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){var i=n.indexOf(e);return-1!=i&&n.splice(i,1),this}},e.emitEvent=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){n=n.slice(0),e=e||[];for(var i=this._onceEvents&&this._onceEvents[t],r=0;r<n.length;r++){var o=n[r];i&&i[o]&&(this.off(t,o),delete i[o]),o.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t})?i.call(e,n,e,t):i)||(t.exports=r)},function(t,e){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,e){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,e,n){var i=n(0),r=Object.prototype,o=r.hasOwnProperty,a=r.toString,s=i?i.toStringTag:void 0;t.exports=function(t){var e=o.call(t,s),n=t[s];try{t[s]=void 0;var i=!0}catch(t){}var r=a.call(t);return i&&(e?t[s]=n:delete t[s]),r}},function(t,e,n){var i=n(0),r=n(6),o=n(5),a=i?i.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?r(t):o(t)}},function(t,e,n){var i=n(7),r=n(4);t.exports=function(t){return"symbol"==typeof t||r(t)&&"[object Symbol]"==i(t)}},function(t,e,n){var i=n(2),r=n(8),o=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=s.test(t);return n||l.test(t)?u(t.slice(2),n?2:8):a.test(t)?NaN:+t}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(this,n(10))},function(t,e,n){var i=n(1);t.exports=function(){return i.Date.now()}},function(t,e,n){var i=n(2),r=n(12),o=n(9),a=Math.max,s=Math.min;t.exports=function(t,e,n){var l,u,d,c,h,f,p=0,v=!1,g=!1,x=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=l,i=u;return l=u=void 0,p=e,c=t.apply(i,n)}function b(t){var n=t-f;return void 0===f||n>=e||n<0||g&&t-p>=d}function m(){var t=r();if(b(t))return E(t);h=setTimeout(m,function(t){var n=e-(t-f);return g?s(n,d-(t-p)):n}(t))}function E(t){return h=void 0,x&&l?y(t):(l=u=void 0,c)}function T(){var t=r(),n=b(t);if(l=arguments,u=this,f=t,n){if(void 0===h)return function(t){return p=t,h=setTimeout(m,e),v?y(t):c}(f);if(g)return h=setTimeout(m,e),y(f)}return void 0===h&&(h=setTimeout(m,e)),c}return e=o(e)||0,i(n)&&(v=!!n.leading,d=(g="maxWait"in n)?a(o(n.maxWait)||0,e):d,x="trailing"in n?!!n.trailing:x),T.cancel=function(){void 0!==h&&clearTimeout(h),p=0,l=f=u=h=void 0},T.flush=function(){return void 0===h?c:E(r())},T}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=a(n(13)),o=a(n(3));function a(t){return t&&t.__esModule?t:{default:t}}function s(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.el=t,i.targetId=i.el.getAttribute("data-expands"),i.targetEl=document.getElementById(i.targetId),i.targetEl?(i.options=Object.assign({},{expandedClasses:"",shouldToggleHeight:!1,activeToggleText:"",onReady:null},n),i.expandedClasses=i.el.getAttribute("data-expands-class")||i.options.expandedClasses,i.expandedClasses.length&&(i.expandedClasses.indexOf(" ")>-1?i.expandedClasses=i.expandedClasses.split(" ").filter(function(t){return t.length}):i.expandedClasses=[i.expandedClasses]),i.shouldToggleHeight=i.el.hasAttribute("data-expands-height")||i.options.shouldToggleHeight,i.hasActiveText=!1,i.textEl=i.el.querySelector("[data-expands-text]"),i.textEl&&(i.defaultToggleText=i.textEl.textContent,i.activeToggleText=i.textEl.getAttribute("data-expands-text")||i.options.activeToggleText,i.hasActiveText=!!i.activeToggleText.length),i.init(),i):(console.warn("Can’t find expandable target with id “"+i.targetId+"”"),l(i,!1))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o.default),i(e,[{key:"init",value:function(){this.el.setAttribute("aria-haspopup",!0),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),"a"===this.el.tagName.toLowerCase()&&this.el.setAttribute("role","button"),this.shouldToggleHeight&&this.heightToggleSetup(),this.clickHandler=this.toggle.bind(this),this.el.addEventListener("click",this.clickHandler),this.keydownHandler=this.keyboardEvents.bind(this),this.el.addEventListener("keydown",this.keydownHandler),"function"==typeof this.options.onReady&&this.options.onReady()}},{key:"destroy",value:function(){var t,e;this.el.removeAttribute("aria-haspopup"),this.el.removeAttribute("aria-expanded"),this.targetEl.removeAttribute("aria-hidden"),this.targetEl.style.removeProperty("max-height"),"a"===this.el.tagName.toLowerCase()&&this.el.removeAttribute("role"),this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.removeEventListener("click",this.clickHandler),this.el.removeEventListener("keydown",this.keydownHandler),this.emitEvent("destroy")}},{key:"keyboardEvents",value:function(t){40==t.keyCode?this.expand():38!=t.keyCode&&27!=t.keyCode||this.collapse()}},{key:"heightToggleSetup",value:function(){var t=this;this.targetParentEl=this.targetEl.parentNode,this.updateExpandedHeight(),window.addEventListener("resize",(0,r.default)(function(e){t.updateExpandedHeight()},150))}},{key:"updateExpandedHeight",value:function(){var t=Math.round(parseFloat(this.targetEl.offsetWidth)),e=this.targetEl.cloneNode(!0);e.style.cssText="max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: "+t+"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important",e.setAttribute("aria-hidden",!1),e.removeAttribute("id");var n=this.targetParentEl.insertBefore(e,this.targetEl),i=Math.round(parseFloat(n.offsetHeight));this.targetParentEl.removeChild(n),this.targetEl.style.maxHeight=i+"px"}},{key:"expand",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.activeToggleText),this.expandedClasses.length&&((t=this.el.classList).add.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).add.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!0),this.targetEl.setAttribute("aria-hidden",!1),this.emitEvent("expand")}},{key:"collapse",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),this.emitEvent("collapse")}},{key:"toggle",value:function(t){"true"===this.el.getAttribute("aria-expanded")?this.collapse():this.expand()}}]),e}();e.default=u}])}); | ||
define("expand-toggleLink",[],function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=14)}([function(t,e,n){var i=n(1).Symbol;t.exports=i},function(t,e,n){var i=n(11),r="object"==typeof self&&self&&self.Object===Object&&self,o=i||r||Function("return this")();t.exports=o},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,n){var i,r;"undefined"!=typeof window&&window,void 0===(r="function"==typeof(i=function(){"use strict";function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var n=this._events=this._events||{},i=n[t]=n[t]||[];return-1==i.indexOf(e)&&i.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var n=this._onceEvents=this._onceEvents||{};return(n[t]=n[t]||{})[e]=!0,this}},e.off=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){var i=n.indexOf(e);return-1!=i&&n.splice(i,1),this}},e.emitEvent=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){n=n.slice(0),e=e||[];for(var i=this._onceEvents&&this._onceEvents[t],r=0;r<n.length;r++){var o=n[r];i&&i[o]&&(this.off(t,o),delete i[o]),o.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t})?i.call(e,n,e,t):i)||(t.exports=r)},function(t,e){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,e){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,e,n){var i=n(0),r=Object.prototype,o=r.hasOwnProperty,a=r.toString,s=i?i.toStringTag:void 0;t.exports=function(t){var e=o.call(t,s),n=t[s];try{t[s]=void 0;var i=!0}catch(t){}var r=a.call(t);return i&&(e?t[s]=n:delete t[s]),r}},function(t,e,n){var i=n(0),r=n(6),o=n(5),a=i?i.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?r(t):o(t)}},function(t,e,n){var i=n(7),r=n(4);t.exports=function(t){return"symbol"==typeof t||r(t)&&"[object Symbol]"==i(t)}},function(t,e,n){var i=n(2),r=n(8),o=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=s.test(t);return n||l.test(t)?u(t.slice(2),n?2:8):a.test(t)?NaN:+t}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(this,n(10))},function(t,e,n){var i=n(1);t.exports=function(){return i.Date.now()}},function(t,e,n){var i=n(2),r=n(12),o=n(9),a=Math.max,s=Math.min;t.exports=function(t,e,n){var l,u,d,c,h,f,p=0,v=!1,g=!1,x=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=l,i=u;return l=u=void 0,p=e,c=t.apply(i,n)}function b(t){var n=t-f;return void 0===f||n>=e||n<0||g&&t-p>=d}function m(){var t=r();if(b(t))return E(t);h=setTimeout(m,function(t){var n=e-(t-f);return g?s(n,d-(t-p)):n}(t))}function E(t){return h=void 0,x&&l?y(t):(l=u=void 0,c)}function T(){var t=r(),n=b(t);if(l=arguments,u=this,f=t,n){if(void 0===h)return function(t){return p=t,h=setTimeout(m,e),v?y(t):c}(f);if(g)return h=setTimeout(m,e),y(f)}return void 0===h&&(h=setTimeout(m,e)),c}return e=o(e)||0,i(n)&&(v=!!n.leading,d=(g="maxWait"in n)?a(o(n.maxWait)||0,e):d,x="trailing"in n?!!n.trailing:x),T.cancel=function(){void 0!==h&&clearTimeout(h),p=0,l=f=u=h=void 0},T.flush=function(){return void 0===h?c:E(r())},T}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=a(n(13)),o=a(n(3));function a(t){return t&&t.__esModule?t:{default:t}}function s(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.el=t,i.targetId=i.el.getAttribute("data-expands"),i.targetEl=document.getElementById(i.targetId),i.targetEl?(i.options=Object.assign({},{expandedClasses:"",shouldToggleHeight:!1,activeToggleText:"",onReady:null},n),i.expandedClasses=i.el.getAttribute("data-expands-class")||i.options.expandedClasses,i.expandedClasses.length&&(i.expandedClasses.indexOf(" ")>-1?i.expandedClasses=i.expandedClasses.split(" ").filter(function(t){return t.length}):i.expandedClasses=[i.expandedClasses]),i.shouldToggleHeight=i.el.hasAttribute("data-expands-height")||i.options.shouldToggleHeight,i.hasActiveText=!1,i.textEl=i.el.querySelector("[data-expands-text]"),i.textEl&&(i.defaultToggleText=i.textEl.textContent,i.activeToggleText=i.textEl.getAttribute("data-expands-text")||i.options.activeToggleText,i.hasActiveText=!!i.activeToggleText.length),i.init(),i):(console.warn("Can’t find expandable target with id “"+i.targetId+"”"),l(i,!1))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o.default),i(e,[{key:"init",value:function(){this.el.setAttribute("aria-haspopup",!0),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),"a"===this.el.tagName.toLowerCase()&&this.el.setAttribute("role","button"),this.shouldToggleHeight&&this.heightToggleSetup(),this.clickHandler=this.toggle.bind(this),this.el.addEventListener("click",this.clickHandler),this.keydownHandler=this.keyboardEvents.bind(this),this.el.addEventListener("keydown",this.keydownHandler),"function"==typeof this.options.onReady&&this.options.onReady()}},{key:"destroy",value:function(){var t,e;this.el.removeAttribute("aria-haspopup"),this.el.removeAttribute("aria-expanded"),this.targetEl.removeAttribute("aria-hidden"),this.targetEl.style.removeProperty("max-height"),"a"===this.el.tagName.toLowerCase()&&this.el.removeAttribute("role"),this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.removeEventListener("click",this.clickHandler),this.el.removeEventListener("keydown",this.keydownHandler),this.emitEvent("destroy")}},{key:"keyboardEvents",value:function(t){40==t.keyCode?this.expand():38!=t.keyCode&&27!=t.keyCode||this.collapse()}},{key:"heightToggleSetup",value:function(){var t=this;this.targetParentEl=this.targetEl.parentNode,this.updateExpandedHeight(),window.addEventListener("resize",(0,r.default)(function(e){t.updateExpandedHeight()},150))}},{key:"updateExpandedHeight",value:function(){var t=Math.round(parseFloat(this.targetEl.offsetWidth)),e=this.targetEl.cloneNode(!0);e.style.cssText="max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: "+t+"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important",e.setAttribute("aria-hidden",!1),e.removeAttribute("id");var n=this.targetParentEl.insertBefore(e,this.targetEl),i=Math.round(parseFloat(n.offsetHeight));this.targetParentEl.removeChild(n),this.targetEl.style.maxHeight=i+"px"}},{key:"expand",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.activeToggleText),this.expandedClasses.length&&((t=this.el.classList).add.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).add.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!0),this.targetEl.setAttribute("aria-hidden",!1),this.emitEvent("expand")}},{key:"collapse",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),this.emitEvent("collapse")}},{key:"toggle",value:function(t){t.preventDefault(),"true"===this.el.getAttribute("aria-expanded")?this.collapse():this.expand()}}]),e}();e.default=u}])}); |
@@ -1,1 +0,1 @@ | ||
module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=14)}([function(t,e,n){var i=n(1).Symbol;t.exports=i},function(t,e,n){var i=n(11),r="object"==typeof self&&self&&self.Object===Object&&self,o=i||r||Function("return this")();t.exports=o},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,n){var i,r;"undefined"!=typeof window&&window,void 0===(r="function"==typeof(i=function(){"use strict";function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var n=this._events=this._events||{},i=n[t]=n[t]||[];return-1==i.indexOf(e)&&i.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var n=this._onceEvents=this._onceEvents||{};return(n[t]=n[t]||{})[e]=!0,this}},e.off=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){var i=n.indexOf(e);return-1!=i&&n.splice(i,1),this}},e.emitEvent=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){n=n.slice(0),e=e||[];for(var i=this._onceEvents&&this._onceEvents[t],r=0;r<n.length;r++){var o=n[r];i&&i[o]&&(this.off(t,o),delete i[o]),o.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t})?i.call(e,n,e,t):i)||(t.exports=r)},function(t,e){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,e){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,e,n){var i=n(0),r=Object.prototype,o=r.hasOwnProperty,a=r.toString,s=i?i.toStringTag:void 0;t.exports=function(t){var e=o.call(t,s),n=t[s];try{t[s]=void 0;var i=!0}catch(t){}var r=a.call(t);return i&&(e?t[s]=n:delete t[s]),r}},function(t,e,n){var i=n(0),r=n(6),o=n(5),a=i?i.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?r(t):o(t)}},function(t,e,n){var i=n(7),r=n(4);t.exports=function(t){return"symbol"==typeof t||r(t)&&"[object Symbol]"==i(t)}},function(t,e,n){var i=n(2),r=n(8),o=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=s.test(t);return n||l.test(t)?u(t.slice(2),n?2:8):a.test(t)?NaN:+t}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(this,n(10))},function(t,e,n){var i=n(1);t.exports=function(){return i.Date.now()}},function(t,e,n){var i=n(2),r=n(12),o=n(9),a=Math.max,s=Math.min;t.exports=function(t,e,n){var l,u,d,c,h,f,p=0,v=!1,g=!1,x=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=l,i=u;return l=u=void 0,p=e,c=t.apply(i,n)}function b(t){var n=t-f;return void 0===f||n>=e||n<0||g&&t-p>=d}function m(){var t=r();if(b(t))return E(t);h=setTimeout(m,function(t){var n=e-(t-f);return g?s(n,d-(t-p)):n}(t))}function E(t){return h=void 0,x&&l?y(t):(l=u=void 0,c)}function T(){var t=r(),n=b(t);if(l=arguments,u=this,f=t,n){if(void 0===h)return function(t){return p=t,h=setTimeout(m,e),v?y(t):c}(f);if(g)return h=setTimeout(m,e),y(f)}return void 0===h&&(h=setTimeout(m,e)),c}return e=o(e)||0,i(n)&&(v=!!n.leading,d=(g="maxWait"in n)?a(o(n.maxWait)||0,e):d,x="trailing"in n?!!n.trailing:x),T.cancel=function(){void 0!==h&&clearTimeout(h),p=0,l=f=u=h=void 0},T.flush=function(){return void 0===h?c:E(r())},T}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=a(n(13)),o=a(n(3));function a(t){return t&&t.__esModule?t:{default:t}}function s(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.el=t,i.targetId=i.el.getAttribute("data-expands"),i.targetEl=document.getElementById(i.targetId),i.targetEl?(i.options=Object.assign({},{expandedClasses:"",shouldToggleHeight:!1,activeToggleText:"",onReady:null},n),i.expandedClasses=i.el.getAttribute("data-expands-class")||i.options.expandedClasses,i.expandedClasses.length&&(i.expandedClasses.indexOf(" ")>-1?i.expandedClasses=i.expandedClasses.split(" ").filter(function(t){return t.length}):i.expandedClasses=[i.expandedClasses]),i.shouldToggleHeight=i.el.hasAttribute("data-expands-height")||i.options.shouldToggleHeight,i.hasActiveText=!1,i.textEl=i.el.querySelector("[data-expands-text]"),i.textEl&&(i.defaultToggleText=i.textEl.textContent,i.activeToggleText=i.textEl.getAttribute("data-expands-text")||i.options.activeToggleText,i.hasActiveText=!!i.activeToggleText.length),i.init(),i):(console.warn("Can’t find expandable target with id “"+i.targetId+"”"),l(i,!1))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o.default),i(e,[{key:"init",value:function(){this.el.setAttribute("aria-haspopup",!0),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),"a"===this.el.tagName.toLowerCase()&&this.el.setAttribute("role","button"),this.shouldToggleHeight&&this.heightToggleSetup(),this.clickHandler=this.toggle.bind(this),this.el.addEventListener("click",this.clickHandler),this.keydownHandler=this.keyboardEvents.bind(this),this.el.addEventListener("keydown",this.keydownHandler),"function"==typeof this.options.onReady&&this.options.onReady()}},{key:"destroy",value:function(){var t,e;this.el.removeAttribute("aria-haspopup"),this.el.removeAttribute("aria-expanded"),this.targetEl.removeAttribute("aria-hidden"),this.targetEl.style.removeProperty("max-height"),"a"===this.el.tagName.toLowerCase()&&this.el.removeAttribute("role"),this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.removeEventListener("click",this.clickHandler),this.el.removeEventListener("keydown",this.keydownHandler),this.emitEvent("destroy")}},{key:"keyboardEvents",value:function(t){40==t.keyCode?this.expand():38!=t.keyCode&&27!=t.keyCode||this.collapse()}},{key:"heightToggleSetup",value:function(){var t=this;this.targetParentEl=this.targetEl.parentNode,this.updateExpandedHeight(),window.addEventListener("resize",(0,r.default)(function(e){t.updateExpandedHeight()},150))}},{key:"updateExpandedHeight",value:function(){var t=Math.round(parseFloat(this.targetEl.offsetWidth)),e=this.targetEl.cloneNode(!0);e.style.cssText="max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: "+t+"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important",e.setAttribute("aria-hidden",!1),e.removeAttribute("id");var n=this.targetParentEl.insertBefore(e,this.targetEl),i=Math.round(parseFloat(n.offsetHeight));this.targetParentEl.removeChild(n),this.targetEl.style.maxHeight=i+"px"}},{key:"expand",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.activeToggleText),this.expandedClasses.length&&((t=this.el.classList).add.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).add.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!0),this.targetEl.setAttribute("aria-hidden",!1),this.emitEvent("expand")}},{key:"collapse",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),this.emitEvent("collapse")}},{key:"toggle",value:function(t){"true"===this.el.getAttribute("aria-expanded")?this.collapse():this.expand()}}]),e}();e.default=u}]); | ||
module.exports=function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=14)}([function(t,e,n){var i=n(1).Symbol;t.exports=i},function(t,e,n){var i=n(11),r="object"==typeof self&&self&&self.Object===Object&&self,o=i||r||Function("return this")();t.exports=o},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,n){var i,r;"undefined"!=typeof window&&window,void 0===(r="function"==typeof(i=function(){"use strict";function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var n=this._events=this._events||{},i=n[t]=n[t]||[];return-1==i.indexOf(e)&&i.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var n=this._onceEvents=this._onceEvents||{};return(n[t]=n[t]||{})[e]=!0,this}},e.off=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){var i=n.indexOf(e);return-1!=i&&n.splice(i,1),this}},e.emitEvent=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){n=n.slice(0),e=e||[];for(var i=this._onceEvents&&this._onceEvents[t],r=0;r<n.length;r++){var o=n[r];i&&i[o]&&(this.off(t,o),delete i[o]),o.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t})?i.call(e,n,e,t):i)||(t.exports=r)},function(t,e){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,e){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,e,n){var i=n(0),r=Object.prototype,o=r.hasOwnProperty,a=r.toString,s=i?i.toStringTag:void 0;t.exports=function(t){var e=o.call(t,s),n=t[s];try{t[s]=void 0;var i=!0}catch(t){}var r=a.call(t);return i&&(e?t[s]=n:delete t[s]),r}},function(t,e,n){var i=n(0),r=n(6),o=n(5),a=i?i.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?r(t):o(t)}},function(t,e,n){var i=n(7),r=n(4);t.exports=function(t){return"symbol"==typeof t||r(t)&&"[object Symbol]"==i(t)}},function(t,e,n){var i=n(2),r=n(8),o=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=s.test(t);return n||l.test(t)?u(t.slice(2),n?2:8):a.test(t)?NaN:+t}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(this,n(10))},function(t,e,n){var i=n(1);t.exports=function(){return i.Date.now()}},function(t,e,n){var i=n(2),r=n(12),o=n(9),a=Math.max,s=Math.min;t.exports=function(t,e,n){var l,u,d,c,h,f,p=0,v=!1,g=!1,x=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=l,i=u;return l=u=void 0,p=e,c=t.apply(i,n)}function b(t){var n=t-f;return void 0===f||n>=e||n<0||g&&t-p>=d}function m(){var t=r();if(b(t))return E(t);h=setTimeout(m,function(t){var n=e-(t-f);return g?s(n,d-(t-p)):n}(t))}function E(t){return h=void 0,x&&l?y(t):(l=u=void 0,c)}function T(){var t=r(),n=b(t);if(l=arguments,u=this,f=t,n){if(void 0===h)return function(t){return p=t,h=setTimeout(m,e),v?y(t):c}(f);if(g)return h=setTimeout(m,e),y(f)}return void 0===h&&(h=setTimeout(m,e)),c}return e=o(e)||0,i(n)&&(v=!!n.leading,d=(g="maxWait"in n)?a(o(n.maxWait)||0,e):d,x="trailing"in n?!!n.trailing:x),T.cancel=function(){void 0!==h&&clearTimeout(h),p=0,l=f=u=h=void 0},T.flush=function(){return void 0===h?c:E(r())},T}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=a(n(13)),o=a(n(3));function a(t){return t&&t.__esModule?t:{default:t}}function s(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.el=t,i.targetId=i.el.getAttribute("data-expands"),i.targetEl=document.getElementById(i.targetId),i.targetEl?(i.options=Object.assign({},{expandedClasses:"",shouldToggleHeight:!1,activeToggleText:"",onReady:null},n),i.expandedClasses=i.el.getAttribute("data-expands-class")||i.options.expandedClasses,i.expandedClasses.length&&(i.expandedClasses.indexOf(" ")>-1?i.expandedClasses=i.expandedClasses.split(" ").filter(function(t){return t.length}):i.expandedClasses=[i.expandedClasses]),i.shouldToggleHeight=i.el.hasAttribute("data-expands-height")||i.options.shouldToggleHeight,i.hasActiveText=!1,i.textEl=i.el.querySelector("[data-expands-text]"),i.textEl&&(i.defaultToggleText=i.textEl.textContent,i.activeToggleText=i.textEl.getAttribute("data-expands-text")||i.options.activeToggleText,i.hasActiveText=!!i.activeToggleText.length),i.init(),i):(console.warn("Can’t find expandable target with id “"+i.targetId+"”"),l(i,!1))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o.default),i(e,[{key:"init",value:function(){this.el.setAttribute("aria-haspopup",!0),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),"a"===this.el.tagName.toLowerCase()&&this.el.setAttribute("role","button"),this.shouldToggleHeight&&this.heightToggleSetup(),this.clickHandler=this.toggle.bind(this),this.el.addEventListener("click",this.clickHandler),this.keydownHandler=this.keyboardEvents.bind(this),this.el.addEventListener("keydown",this.keydownHandler),"function"==typeof this.options.onReady&&this.options.onReady()}},{key:"destroy",value:function(){var t,e;this.el.removeAttribute("aria-haspopup"),this.el.removeAttribute("aria-expanded"),this.targetEl.removeAttribute("aria-hidden"),this.targetEl.style.removeProperty("max-height"),"a"===this.el.tagName.toLowerCase()&&this.el.removeAttribute("role"),this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.removeEventListener("click",this.clickHandler),this.el.removeEventListener("keydown",this.keydownHandler),this.emitEvent("destroy")}},{key:"keyboardEvents",value:function(t){40==t.keyCode?this.expand():38!=t.keyCode&&27!=t.keyCode||this.collapse()}},{key:"heightToggleSetup",value:function(){var t=this;this.targetParentEl=this.targetEl.parentNode,this.updateExpandedHeight(),window.addEventListener("resize",(0,r.default)(function(e){t.updateExpandedHeight()},150))}},{key:"updateExpandedHeight",value:function(){var t=Math.round(parseFloat(this.targetEl.offsetWidth)),e=this.targetEl.cloneNode(!0);e.style.cssText="max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: "+t+"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important",e.setAttribute("aria-hidden",!1),e.removeAttribute("id");var n=this.targetParentEl.insertBefore(e,this.targetEl),i=Math.round(parseFloat(n.offsetHeight));this.targetParentEl.removeChild(n),this.targetEl.style.maxHeight=i+"px"}},{key:"expand",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.activeToggleText),this.expandedClasses.length&&((t=this.el.classList).add.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).add.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!0),this.targetEl.setAttribute("aria-hidden",!1),this.emitEvent("expand")}},{key:"collapse",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),this.emitEvent("collapse")}},{key:"toggle",value:function(t){t.preventDefault(),"true"===this.el.getAttribute("aria-expanded")?this.collapse():this.expand()}}]),e}();e.default=u}]); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["expand-toggleLink"]=e():t["expand-toggleLink"]=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=14)}([function(t,e,n){var i=n(1).Symbol;t.exports=i},function(t,e,n){var i=n(11),r="object"==typeof self&&self&&self.Object===Object&&self,o=i||r||Function("return this")();t.exports=o},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,n){var i,r;"undefined"!=typeof window&&window,void 0===(r="function"==typeof(i=function(){"use strict";function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var n=this._events=this._events||{},i=n[t]=n[t]||[];return-1==i.indexOf(e)&&i.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var n=this._onceEvents=this._onceEvents||{};return(n[t]=n[t]||{})[e]=!0,this}},e.off=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){var i=n.indexOf(e);return-1!=i&&n.splice(i,1),this}},e.emitEvent=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){n=n.slice(0),e=e||[];for(var i=this._onceEvents&&this._onceEvents[t],r=0;r<n.length;r++){var o=n[r];i&&i[o]&&(this.off(t,o),delete i[o]),o.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t})?i.call(e,n,e,t):i)||(t.exports=r)},function(t,e){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,e){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,e,n){var i=n(0),r=Object.prototype,o=r.hasOwnProperty,a=r.toString,s=i?i.toStringTag:void 0;t.exports=function(t){var e=o.call(t,s),n=t[s];try{t[s]=void 0;var i=!0}catch(t){}var r=a.call(t);return i&&(e?t[s]=n:delete t[s]),r}},function(t,e,n){var i=n(0),r=n(6),o=n(5),a=i?i.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?r(t):o(t)}},function(t,e,n){var i=n(7),r=n(4);t.exports=function(t){return"symbol"==typeof t||r(t)&&"[object Symbol]"==i(t)}},function(t,e,n){var i=n(2),r=n(8),o=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=s.test(t);return n||l.test(t)?u(t.slice(2),n?2:8):a.test(t)?NaN:+t}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(this,n(10))},function(t,e,n){var i=n(1);t.exports=function(){return i.Date.now()}},function(t,e,n){var i=n(2),r=n(12),o=n(9),a=Math.max,s=Math.min;t.exports=function(t,e,n){var l,u,d,c,f,h,p=0,v=!1,g=!1,x=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=l,i=u;return l=u=void 0,p=e,c=t.apply(i,n)}function b(t){var n=t-h;return void 0===h||n>=e||n<0||g&&t-p>=d}function m(){var t=r();if(b(t))return E(t);f=setTimeout(m,function(t){var n=e-(t-h);return g?s(n,d-(t-p)):n}(t))}function E(t){return f=void 0,x&&l?y(t):(l=u=void 0,c)}function T(){var t=r(),n=b(t);if(l=arguments,u=this,h=t,n){if(void 0===f)return function(t){return p=t,f=setTimeout(m,e),v?y(t):c}(h);if(g)return f=setTimeout(m,e),y(h)}return void 0===f&&(f=setTimeout(m,e)),c}return e=o(e)||0,i(n)&&(v=!!n.leading,d=(g="maxWait"in n)?a(o(n.maxWait)||0,e):d,x="trailing"in n?!!n.trailing:x),T.cancel=function(){void 0!==f&&clearTimeout(f),p=0,l=h=u=f=void 0},T.flush=function(){return void 0===f?c:E(r())},T}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=a(n(13)),o=a(n(3));function a(t){return t&&t.__esModule?t:{default:t}}function s(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.el=t,i.targetId=i.el.getAttribute("data-expands"),i.targetEl=document.getElementById(i.targetId),i.targetEl?(i.options=Object.assign({},{expandedClasses:"",shouldToggleHeight:!1,activeToggleText:"",onReady:null},n),i.expandedClasses=i.el.getAttribute("data-expands-class")||i.options.expandedClasses,i.expandedClasses.length&&(i.expandedClasses.indexOf(" ")>-1?i.expandedClasses=i.expandedClasses.split(" ").filter(function(t){return t.length}):i.expandedClasses=[i.expandedClasses]),i.shouldToggleHeight=i.el.hasAttribute("data-expands-height")||i.options.shouldToggleHeight,i.hasActiveText=!1,i.textEl=i.el.querySelector("[data-expands-text]"),i.textEl&&(i.defaultToggleText=i.textEl.textContent,i.activeToggleText=i.textEl.getAttribute("data-expands-text")||i.options.activeToggleText,i.hasActiveText=!!i.activeToggleText.length),i.init(),i):(console.warn("Can’t find expandable target with id “"+i.targetId+"”"),l(i,!1))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o.default),i(e,[{key:"init",value:function(){this.el.setAttribute("aria-haspopup",!0),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),"a"===this.el.tagName.toLowerCase()&&this.el.setAttribute("role","button"),this.shouldToggleHeight&&this.heightToggleSetup(),this.clickHandler=this.toggle.bind(this),this.el.addEventListener("click",this.clickHandler),this.keydownHandler=this.keyboardEvents.bind(this),this.el.addEventListener("keydown",this.keydownHandler),"function"==typeof this.options.onReady&&this.options.onReady()}},{key:"destroy",value:function(){var t,e;this.el.removeAttribute("aria-haspopup"),this.el.removeAttribute("aria-expanded"),this.targetEl.removeAttribute("aria-hidden"),this.targetEl.style.removeProperty("max-height"),"a"===this.el.tagName.toLowerCase()&&this.el.removeAttribute("role"),this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.removeEventListener("click",this.clickHandler),this.el.removeEventListener("keydown",this.keydownHandler),this.emitEvent("destroy")}},{key:"keyboardEvents",value:function(t){40==t.keyCode?this.expand():38!=t.keyCode&&27!=t.keyCode||this.collapse()}},{key:"heightToggleSetup",value:function(){var t=this;this.targetParentEl=this.targetEl.parentNode,this.updateExpandedHeight(),window.addEventListener("resize",(0,r.default)(function(e){t.updateExpandedHeight()},150))}},{key:"updateExpandedHeight",value:function(){var t=Math.round(parseFloat(this.targetEl.offsetWidth)),e=this.targetEl.cloneNode(!0);e.style.cssText="max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: "+t+"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important",e.setAttribute("aria-hidden",!1),e.removeAttribute("id");var n=this.targetParentEl.insertBefore(e,this.targetEl),i=Math.round(parseFloat(n.offsetHeight));this.targetParentEl.removeChild(n),this.targetEl.style.maxHeight=i+"px"}},{key:"expand",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.activeToggleText),this.expandedClasses.length&&((t=this.el.classList).add.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).add.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!0),this.targetEl.setAttribute("aria-hidden",!1),this.emitEvent("expand")}},{key:"collapse",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),this.emitEvent("collapse")}},{key:"toggle",value:function(t){"true"===this.el.getAttribute("aria-expanded")?this.collapse():this.expand()}}]),e}();e.default=u}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["expand-toggleLink"]=e():t["expand-toggleLink"]=e()}(window,function(){return function(t){var e={};function n(i){if(e[i])return e[i].exports;var r=e[i]={i:i,l:!1,exports:{}};return t[i].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=14)}([function(t,e,n){var i=n(1).Symbol;t.exports=i},function(t,e,n){var i=n(11),r="object"==typeof self&&self&&self.Object===Object&&self,o=i||r||Function("return this")();t.exports=o},function(t,e){t.exports=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}},function(t,e,n){var i,r;"undefined"!=typeof window&&window,void 0===(r="function"==typeof(i=function(){"use strict";function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var n=this._events=this._events||{},i=n[t]=n[t]||[];return-1==i.indexOf(e)&&i.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var n=this._onceEvents=this._onceEvents||{};return(n[t]=n[t]||{})[e]=!0,this}},e.off=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){var i=n.indexOf(e);return-1!=i&&n.splice(i,1),this}},e.emitEvent=function(t,e){var n=this._events&&this._events[t];if(n&&n.length){n=n.slice(0),e=e||[];for(var i=this._onceEvents&&this._onceEvents[t],r=0;r<n.length;r++){var o=n[r];i&&i[o]&&(this.off(t,o),delete i[o]),o.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t})?i.call(e,n,e,t):i)||(t.exports=r)},function(t,e){t.exports=function(t){return null!=t&&"object"==typeof t}},function(t,e){var n=Object.prototype.toString;t.exports=function(t){return n.call(t)}},function(t,e,n){var i=n(0),r=Object.prototype,o=r.hasOwnProperty,a=r.toString,s=i?i.toStringTag:void 0;t.exports=function(t){var e=o.call(t,s),n=t[s];try{t[s]=void 0;var i=!0}catch(t){}var r=a.call(t);return i&&(e?t[s]=n:delete t[s]),r}},function(t,e,n){var i=n(0),r=n(6),o=n(5),a=i?i.toStringTag:void 0;t.exports=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":a&&a in Object(t)?r(t):o(t)}},function(t,e,n){var i=n(7),r=n(4);t.exports=function(t){return"symbol"==typeof t||r(t)&&"[object Symbol]"==i(t)}},function(t,e,n){var i=n(2),r=n(8),o=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,u=parseInt;t.exports=function(t){if("number"==typeof t)return t;if(r(t))return NaN;if(i(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=i(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(o,"");var n=s.test(t);return n||l.test(t)?u(t.slice(2),n?2:8):a.test(t)?NaN:+t}},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(this,n(10))},function(t,e,n){var i=n(1);t.exports=function(){return i.Date.now()}},function(t,e,n){var i=n(2),r=n(12),o=n(9),a=Math.max,s=Math.min;t.exports=function(t,e,n){var l,u,d,c,f,h,p=0,v=!1,g=!1,x=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function y(e){var n=l,i=u;return l=u=void 0,p=e,c=t.apply(i,n)}function b(t){var n=t-h;return void 0===h||n>=e||n<0||g&&t-p>=d}function m(){var t=r();if(b(t))return E(t);f=setTimeout(m,function(t){var n=e-(t-h);return g?s(n,d-(t-p)):n}(t))}function E(t){return f=void 0,x&&l?y(t):(l=u=void 0,c)}function T(){var t=r(),n=b(t);if(l=arguments,u=this,h=t,n){if(void 0===f)return function(t){return p=t,f=setTimeout(m,e),v?y(t):c}(h);if(g)return f=setTimeout(m,e),y(h)}return void 0===f&&(f=setTimeout(m,e)),c}return e=o(e)||0,i(n)&&(v=!!n.leading,d=(g="maxWait"in n)?a(o(n.maxWait)||0,e):d,x="trailing"in n?!!n.trailing:x),T.cancel=function(){void 0!==f&&clearTimeout(f),p=0,l=h=u=f=void 0},T.flush=function(){return void 0===f?c:E(r())},T}},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=a(n(13)),o=a(n(3));function a(t){return t&&t.__esModule?t:{default:t}}function s(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)}function l(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var u=function(t){function e(t,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var i=l(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return i.el=t,i.targetId=i.el.getAttribute("data-expands"),i.targetEl=document.getElementById(i.targetId),i.targetEl?(i.options=Object.assign({},{expandedClasses:"",shouldToggleHeight:!1,activeToggleText:"",onReady:null},n),i.expandedClasses=i.el.getAttribute("data-expands-class")||i.options.expandedClasses,i.expandedClasses.length&&(i.expandedClasses.indexOf(" ")>-1?i.expandedClasses=i.expandedClasses.split(" ").filter(function(t){return t.length}):i.expandedClasses=[i.expandedClasses]),i.shouldToggleHeight=i.el.hasAttribute("data-expands-height")||i.options.shouldToggleHeight,i.hasActiveText=!1,i.textEl=i.el.querySelector("[data-expands-text]"),i.textEl&&(i.defaultToggleText=i.textEl.textContent,i.activeToggleText=i.textEl.getAttribute("data-expands-text")||i.options.activeToggleText,i.hasActiveText=!!i.activeToggleText.length),i.init(),i):(console.warn("Can’t find expandable target with id “"+i.targetId+"”"),l(i,!1))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o.default),i(e,[{key:"init",value:function(){this.el.setAttribute("aria-haspopup",!0),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),"a"===this.el.tagName.toLowerCase()&&this.el.setAttribute("role","button"),this.shouldToggleHeight&&this.heightToggleSetup(),this.clickHandler=this.toggle.bind(this),this.el.addEventListener("click",this.clickHandler),this.keydownHandler=this.keyboardEvents.bind(this),this.el.addEventListener("keydown",this.keydownHandler),"function"==typeof this.options.onReady&&this.options.onReady()}},{key:"destroy",value:function(){var t,e;this.el.removeAttribute("aria-haspopup"),this.el.removeAttribute("aria-expanded"),this.targetEl.removeAttribute("aria-hidden"),this.targetEl.style.removeProperty("max-height"),"a"===this.el.tagName.toLowerCase()&&this.el.removeAttribute("role"),this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.removeEventListener("click",this.clickHandler),this.el.removeEventListener("keydown",this.keydownHandler),this.emitEvent("destroy")}},{key:"keyboardEvents",value:function(t){40==t.keyCode?this.expand():38!=t.keyCode&&27!=t.keyCode||this.collapse()}},{key:"heightToggleSetup",value:function(){var t=this;this.targetParentEl=this.targetEl.parentNode,this.updateExpandedHeight(),window.addEventListener("resize",(0,r.default)(function(e){t.updateExpandedHeight()},150))}},{key:"updateExpandedHeight",value:function(){var t=Math.round(parseFloat(this.targetEl.offsetWidth)),e=this.targetEl.cloneNode(!0);e.style.cssText="max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: "+t+"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important",e.setAttribute("aria-hidden",!1),e.removeAttribute("id");var n=this.targetParentEl.insertBefore(e,this.targetEl),i=Math.round(parseFloat(n.offsetHeight));this.targetParentEl.removeChild(n),this.targetEl.style.maxHeight=i+"px"}},{key:"expand",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.activeToggleText),this.expandedClasses.length&&((t=this.el.classList).add.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).add.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!0),this.targetEl.setAttribute("aria-hidden",!1),this.emitEvent("expand")}},{key:"collapse",value:function(){var t,e;this.hasActiveText&&(this.textEl.textContent=this.defaultToggleText),this.expandedClasses.length&&((t=this.el.classList).remove.apply(t,s(this.expandedClasses)),(e=this.targetEl.classList).remove.apply(e,s(this.expandedClasses))),this.el.setAttribute("aria-expanded",!1),this.targetEl.setAttribute("aria-hidden",!0),this.emitEvent("collapse")}},{key:"toggle",value:function(t){t.preventDefault(),"true"===this.el.getAttribute("aria-expanded")?this.collapse():this.expand()}}]),e}();e.default=u}])}); |
@@ -82,3 +82,3 @@ define("expand-toggleLink", [], function() { return /******/ (function(modules) { // webpackBootstrap | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debounce = __webpack_require__(/*! lodash/debounce */ \"./node_modules/lodash/debounce.js\");\n\nvar _debounce2 = _interopRequireDefault(_debounce);\n\nvar _evEmitter = __webpack_require__(/*! ev-emitter */ \"./node_modules/ev-emitter/ev-emitter.js\");\n\nvar _evEmitter2 = _interopRequireDefault(_evEmitter);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\n/**\n * Wrap the last X words in an HTML tag to prevent them from wrapping (i.e. orphans)\n * @param {HTMLElement} el - Toggle button DOM node\n * @param {Object} opts - Options\n * @param {string} [opts.expandedClasses=\"\"] - Class(es) to apply when expanded\n * @param {boolean} [opts.shouldToggleHeight=false] - Whether or not to animate height\n * @param {string} [opts.defaultToggleText=\"\"] - Expanded state toggle button text\n * @param {function} [opts.onReady=\"\"] - Ready callback function\n */\nvar ExpandToggle = function (_EventEmitter) {\n _inherits(ExpandToggle, _EventEmitter);\n\n function ExpandToggle(el, opts) {\n _classCallCheck(this, ExpandToggle);\n\n var _this = _possibleConstructorReturn(this, (ExpandToggle.__proto__ || Object.getPrototypeOf(ExpandToggle)).call(this));\n // Have to call super() first before referencing “this” since we’re extending EventEmitter\n // https://stackoverflow.com/a/43591507/673457\n\n\n _this.el = el;\n _this.targetId = _this.el.getAttribute(\"data-expands\");\n _this.targetEl = document.getElementById(_this.targetId);\n\n // Ensure target element exist before initializing\n if (!_this.targetEl) {\n var _ret;\n\n console.warn(\"Can\\u2019t find expandable target with id \\u201C\" + _this.targetId + \"\\u201D\");\n return _ret = false, _possibleConstructorReturn(_this, _ret);\n }\n\n // Use Object.assign() to merge “opts” object with default values in this.options\n _this.options = Object.assign({}, {\n expandedClasses: \"\", // string, accepts multiple space-separated classes\n shouldToggleHeight: false, // should target element’s height be animated using max-height\n activeToggleText: \"\", // expanded state toggle button text\n onReady: null // ready callback function\n }, opts);\n\n // Check for custom expanded class(es)\n _this.expandedClasses = _this.el.getAttribute(\"data-expands-class\") || _this.options.expandedClasses;\n\n if (_this.expandedClasses.length) {\n // Check if active class string contains multiple classes\n if (_this.expandedClasses.indexOf(\" \") > -1) {\n // Convert to array and remove any empty string values\n // caused by having multiple spaces in a row.\n _this.expandedClasses = _this.expandedClasses.split(\" \").filter(function (n) {\n return n.length;\n });\n } else {\n // We still need to convert a single active class to an array\n // so we can use the spread syntax later in classList.add()\n _this.expandedClasses = [_this.expandedClasses];\n }\n }\n\n // Check if height should be animated\n _this.shouldToggleHeight = _this.el.hasAttribute(\"data-expands-height\") || _this.options.shouldToggleHeight;\n\n // Check for custom toggle button text to use when expanded\n _this.hasActiveText = false;\n _this.textEl = _this.el.querySelector(\"[data-expands-text]\");\n\n if (_this.textEl) {\n _this.defaultToggleText = _this.textEl.textContent;\n _this.activeToggleText = _this.textEl.getAttribute(\"data-expands-text\") || _this.options.activeToggleText;\n _this.hasActiveText = !!_this.activeToggleText.length;\n }\n\n _this.init();\n return _this;\n }\n\n _createClass(ExpandToggle, [{\n key: \"init\",\n value: function init() {\n // Accessibility setup\n this.el.setAttribute(\"aria-haspopup\", true);\n this.el.setAttribute(\"aria-expanded\", false);\n // Omit “aria-controls” for now\n // See https://inclusive-components.design/menus-menu-buttons/#ariacontrols\n // this.el.setAttribute(\"aria-controls\", this.targetId);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.setAttribute(\"role\", \"button\");\n }\n\n if (this.shouldToggleHeight) {\n this.heightToggleSetup();\n }\n\n // Click event listener on toggle button\n // Note: Callback needs to be assigned to a var so we can remove it since we’re using bind()\n // https://stackoverflow.com/a/22870717/673457\n this.clickHandler = this.toggle.bind(this);\n this.el.addEventListener(\"click\", this.clickHandler);\n\n // Keyboard listeners on toggle button\n this.keydownHandler = this.keyboardEvents.bind(this);\n this.el.addEventListener(\"keydown\", this.keydownHandler);\n\n // Check for onReady callback\n if (typeof this.options.onReady === \"function\") {\n this.options.onReady();\n }\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n // Remove aria attributes\n this.el.removeAttribute(\"aria-haspopup\");\n this.el.removeAttribute(\"aria-expanded\");\n this.targetEl.removeAttribute(\"aria-hidden\");\n this.targetEl.style.removeProperty(\"max-height\");\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.removeAttribute(\"role\");\n }\n\n // Reset toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove custom classes\n if (this.expandedClasses.length) {\n var _el$classList, _targetEl$classList;\n\n (_el$classList = this.el.classList).remove.apply(_el$classList, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList = this.targetEl.classList).remove.apply(_targetEl$classList, _toConsumableArray(this.expandedClasses));\n }\n\n // Remove event listeners\n this.el.removeEventListener(\"click\", this.clickHandler);\n this.el.removeEventListener(\"keydown\", this.keydownHandler);\n\n this.emitEvent(\"destroy\");\n }\n }, {\n key: \"keyboardEvents\",\n value: function keyboardEvents(evt) {\n // Expand with down arrow\n if (evt.keyCode == 40) {\n this.expand();\n } else if (evt.keyCode == 38 || evt.keyCode == 27) {\n // Close with up arrow or escape key\n this.collapse();\n }\n }\n }, {\n key: \"heightToggleSetup\",\n value: function heightToggleSetup() {\n var self = this;\n this.targetParentEl = this.targetEl.parentNode;\n\n // Set max-height to the expanded height so we can animate it.\n this.updateExpandedHeight();\n\n // Update target element’s max-height on resize\n window.addEventListener(\"resize\", (0, _debounce2.default)(function (event) {\n self.updateExpandedHeight();\n }, 150));\n }\n\n // Set max-height of target element to its expanded height without triggering relayout.\n //\n // This technique works by creating an absolutely-positioned invisible clone of the target\n // element and calculating its height. This avoids any relayout that would otherwise occur\n // if the element was briefly expanded so we could measure it.\n //\n // Note: We’re using CSS to transition max-height instead jQuery’s slideToggle(),\n // or another 3rd-party lib like Velocity.js, to avoid loading a large lib.\n\n }, {\n key: \"updateExpandedHeight\",\n value: function updateExpandedHeight() {\n // Get width of original element so we can apply it to the clone\n var nodeWidth = Math.round(parseFloat(this.targetEl.offsetWidth));\n\n // Create clone of node\n var cloneEl = this.targetEl.cloneNode(true); // 'true' includes child nodes\n\n // Inline styles added to prevent reflow, ensure clone is same size as expanded element\n cloneEl.style.cssText = \"max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: \" + nodeWidth + \"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important\";\n\n // Update “aria-hidden” attribute\n cloneEl.setAttribute(\"aria-hidden\", false);\n\n // Remove id just to be safe\n cloneEl.removeAttribute(\"id\");\n\n // Append clone to document, save as new var so we can remove it later\n var newEl = this.targetParentEl.insertBefore(cloneEl, this.targetEl);\n\n // Calculate height\n var expandedHeight = Math.round(parseFloat(newEl.offsetHeight));\n\n // Remove cloned node to clean up after ourselves\n this.targetParentEl.removeChild(newEl);\n\n // Apply inline max-height to collapsed element\n // Note: CSS is overriding this when aria-hidden=\"true\"\n this.targetEl.style.maxHeight = expandedHeight + \"px\";\n }\n }, {\n key: \"expand\",\n value: function expand() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.activeToggleText;\n }\n\n // Add classes\n if (this.expandedClasses.length) {\n var _el$classList2, _targetEl$classList2;\n\n (_el$classList2 = this.el.classList).add.apply(_el$classList2, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList2 = this.targetEl.classList).add.apply(_targetEl$classList2, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", true);\n this.targetEl.setAttribute(\"aria-hidden\", false);\n\n this.emitEvent(\"expand\");\n }\n }, {\n key: \"collapse\",\n value: function collapse() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove classes\n if (this.expandedClasses.length) {\n var _el$classList3, _targetEl$classList3;\n\n (_el$classList3 = this.el.classList).remove.apply(_el$classList3, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList3 = this.targetEl.classList).remove.apply(_targetEl$classList3, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", false);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n this.emitEvent(\"collapse\");\n }\n }, {\n key: \"toggle\",\n value: function toggle(evt) {\n if (this.el.getAttribute(\"aria-expanded\") === \"true\") {\n this.collapse();\n } else {\n this.expand();\n }\n }\n }]);\n\n return ExpandToggle;\n}(_evEmitter2.default);\n\nexports.default = ExpandToggle;\n\n//# sourceURL=webpack://%5Bname%5DLink/./index.js?"); | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debounce = __webpack_require__(/*! lodash/debounce */ \"./node_modules/lodash/debounce.js\");\n\nvar _debounce2 = _interopRequireDefault(_debounce);\n\nvar _evEmitter = __webpack_require__(/*! ev-emitter */ \"./node_modules/ev-emitter/ev-emitter.js\");\n\nvar _evEmitter2 = _interopRequireDefault(_evEmitter);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\n/**\n * Wrap the last X words in an HTML tag to prevent them from wrapping (i.e. orphans)\n * @param {HTMLElement} el - Toggle button DOM node\n * @param {Object} opts - Options\n * @param {string} [opts.expandedClasses=\"\"] - Class(es) to apply when expanded\n * @param {boolean} [opts.shouldToggleHeight=false] - Whether or not to animate height\n * @param {string} [opts.defaultToggleText=\"\"] - Expanded state toggle button text\n * @param {function} [opts.onReady=\"\"] - Ready callback function\n */\nvar ExpandToggle = function (_EventEmitter) {\n _inherits(ExpandToggle, _EventEmitter);\n\n function ExpandToggle(el, opts) {\n _classCallCheck(this, ExpandToggle);\n\n var _this = _possibleConstructorReturn(this, (ExpandToggle.__proto__ || Object.getPrototypeOf(ExpandToggle)).call(this));\n // Have to call super() first before referencing “this” since we’re extending EventEmitter\n // https://stackoverflow.com/a/43591507/673457\n\n\n _this.el = el;\n _this.targetId = _this.el.getAttribute(\"data-expands\");\n _this.targetEl = document.getElementById(_this.targetId);\n\n // Ensure target element exist before initializing\n if (!_this.targetEl) {\n var _ret;\n\n console.warn(\"Can\\u2019t find expandable target with id \\u201C\" + _this.targetId + \"\\u201D\");\n return _ret = false, _possibleConstructorReturn(_this, _ret);\n }\n\n // Use Object.assign() to merge “opts” object with default values in this.options\n _this.options = Object.assign({}, {\n expandedClasses: \"\", // string, accepts multiple space-separated classes\n shouldToggleHeight: false, // should target element’s height be animated using max-height\n activeToggleText: \"\", // expanded state toggle button text\n onReady: null // ready callback function\n }, opts);\n\n // Check for custom expanded class(es)\n _this.expandedClasses = _this.el.getAttribute(\"data-expands-class\") || _this.options.expandedClasses;\n\n if (_this.expandedClasses.length) {\n // Check if active class string contains multiple classes\n if (_this.expandedClasses.indexOf(\" \") > -1) {\n // Convert to array and remove any empty string values\n // caused by having multiple spaces in a row.\n _this.expandedClasses = _this.expandedClasses.split(\" \").filter(function (n) {\n return n.length;\n });\n } else {\n // We still need to convert a single active class to an array\n // so we can use the spread syntax later in classList.add()\n _this.expandedClasses = [_this.expandedClasses];\n }\n }\n\n // Check if height should be animated\n _this.shouldToggleHeight = _this.el.hasAttribute(\"data-expands-height\") || _this.options.shouldToggleHeight;\n\n // Check for custom toggle button text to use when expanded\n _this.hasActiveText = false;\n _this.textEl = _this.el.querySelector(\"[data-expands-text]\");\n\n if (_this.textEl) {\n _this.defaultToggleText = _this.textEl.textContent;\n _this.activeToggleText = _this.textEl.getAttribute(\"data-expands-text\") || _this.options.activeToggleText;\n _this.hasActiveText = !!_this.activeToggleText.length;\n }\n\n _this.init();\n return _this;\n }\n\n _createClass(ExpandToggle, [{\n key: \"init\",\n value: function init() {\n // Accessibility setup\n this.el.setAttribute(\"aria-haspopup\", true);\n this.el.setAttribute(\"aria-expanded\", false);\n // Omit “aria-controls” for now\n // See https://inclusive-components.design/menus-menu-buttons/#ariacontrols\n // this.el.setAttribute(\"aria-controls\", this.targetId);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.setAttribute(\"role\", \"button\");\n }\n\n if (this.shouldToggleHeight) {\n this.heightToggleSetup();\n }\n\n // Click event listener on toggle button\n // Note: Callback needs to be assigned to a var so we can remove it since we’re using bind()\n // https://stackoverflow.com/a/22870717/673457\n this.clickHandler = this.toggle.bind(this);\n this.el.addEventListener(\"click\", this.clickHandler);\n\n // Keyboard listeners on toggle button\n this.keydownHandler = this.keyboardEvents.bind(this);\n this.el.addEventListener(\"keydown\", this.keydownHandler);\n\n // Check for onReady callback\n if (typeof this.options.onReady === \"function\") {\n this.options.onReady();\n }\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n // Remove aria attributes\n this.el.removeAttribute(\"aria-haspopup\");\n this.el.removeAttribute(\"aria-expanded\");\n this.targetEl.removeAttribute(\"aria-hidden\");\n this.targetEl.style.removeProperty(\"max-height\");\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.removeAttribute(\"role\");\n }\n\n // Reset toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove custom classes\n if (this.expandedClasses.length) {\n var _el$classList, _targetEl$classList;\n\n (_el$classList = this.el.classList).remove.apply(_el$classList, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList = this.targetEl.classList).remove.apply(_targetEl$classList, _toConsumableArray(this.expandedClasses));\n }\n\n // Remove event listeners\n this.el.removeEventListener(\"click\", this.clickHandler);\n this.el.removeEventListener(\"keydown\", this.keydownHandler);\n\n this.emitEvent(\"destroy\");\n }\n }, {\n key: \"keyboardEvents\",\n value: function keyboardEvents(evt) {\n // Expand with down arrow\n if (evt.keyCode == 40) {\n this.expand();\n } else if (evt.keyCode == 38 || evt.keyCode == 27) {\n // Close with up arrow or escape key\n this.collapse();\n }\n }\n }, {\n key: \"heightToggleSetup\",\n value: function heightToggleSetup() {\n var self = this;\n this.targetParentEl = this.targetEl.parentNode;\n\n // Set max-height to the expanded height so we can animate it.\n this.updateExpandedHeight();\n\n // Update target element’s max-height on resize\n window.addEventListener(\"resize\", (0, _debounce2.default)(function (event) {\n self.updateExpandedHeight();\n }, 150));\n }\n\n // Set max-height of target element to its expanded height without triggering relayout.\n //\n // This technique works by creating an absolutely-positioned invisible clone of the target\n // element and calculating its height. This avoids any relayout that would otherwise occur\n // if the element was briefly expanded so we could measure it.\n //\n // Note: We’re using CSS to transition max-height instead jQuery’s slideToggle(),\n // or another 3rd-party lib like Velocity.js, to avoid loading a large lib.\n\n }, {\n key: \"updateExpandedHeight\",\n value: function updateExpandedHeight() {\n // Get width of original element so we can apply it to the clone\n var nodeWidth = Math.round(parseFloat(this.targetEl.offsetWidth));\n\n // Create clone of node\n var cloneEl = this.targetEl.cloneNode(true); // 'true' includes child nodes\n\n // Inline styles added to prevent reflow, ensure clone is same size as expanded element\n cloneEl.style.cssText = \"max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: \" + nodeWidth + \"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important\";\n\n // Update “aria-hidden” attribute\n cloneEl.setAttribute(\"aria-hidden\", false);\n\n // Remove id just to be safe\n cloneEl.removeAttribute(\"id\");\n\n // Append clone to document, save as new var so we can remove it later\n var newEl = this.targetParentEl.insertBefore(cloneEl, this.targetEl);\n\n // Calculate height\n var expandedHeight = Math.round(parseFloat(newEl.offsetHeight));\n\n // Remove cloned node to clean up after ourselves\n this.targetParentEl.removeChild(newEl);\n\n // Apply inline max-height to collapsed element\n // Note: CSS is overriding this when aria-hidden=\"true\"\n this.targetEl.style.maxHeight = expandedHeight + \"px\";\n }\n }, {\n key: \"expand\",\n value: function expand() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.activeToggleText;\n }\n\n // Add classes\n if (this.expandedClasses.length) {\n var _el$classList2, _targetEl$classList2;\n\n (_el$classList2 = this.el.classList).add.apply(_el$classList2, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList2 = this.targetEl.classList).add.apply(_targetEl$classList2, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", true);\n this.targetEl.setAttribute(\"aria-hidden\", false);\n\n this.emitEvent(\"expand\");\n }\n }, {\n key: \"collapse\",\n value: function collapse() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove classes\n if (this.expandedClasses.length) {\n var _el$classList3, _targetEl$classList3;\n\n (_el$classList3 = this.el.classList).remove.apply(_el$classList3, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList3 = this.targetEl.classList).remove.apply(_targetEl$classList3, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", false);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n this.emitEvent(\"collapse\");\n }\n }, {\n key: \"toggle\",\n value: function toggle(evt) {\n // Prevent default in case toggle element is a link instead of a button\n evt.preventDefault();\n\n if (this.el.getAttribute(\"aria-expanded\") === \"true\") {\n this.collapse();\n } else {\n this.expand();\n }\n }\n }]);\n\n return ExpandToggle;\n}(_evEmitter2.default);\n\nexports.default = ExpandToggle;\n\n//# sourceURL=webpack://%5Bname%5DLink/./index.js?"); | ||
@@ -85,0 +85,0 @@ /***/ }), |
@@ -83,3 +83,3 @@ module.exports = | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debounce = __webpack_require__(/*! lodash/debounce */ \"./node_modules/lodash/debounce.js\");\n\nvar _debounce2 = _interopRequireDefault(_debounce);\n\nvar _evEmitter = __webpack_require__(/*! ev-emitter */ \"./node_modules/ev-emitter/ev-emitter.js\");\n\nvar _evEmitter2 = _interopRequireDefault(_evEmitter);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\n/**\n * Wrap the last X words in an HTML tag to prevent them from wrapping (i.e. orphans)\n * @param {HTMLElement} el - Toggle button DOM node\n * @param {Object} opts - Options\n * @param {string} [opts.expandedClasses=\"\"] - Class(es) to apply when expanded\n * @param {boolean} [opts.shouldToggleHeight=false] - Whether or not to animate height\n * @param {string} [opts.defaultToggleText=\"\"] - Expanded state toggle button text\n * @param {function} [opts.onReady=\"\"] - Ready callback function\n */\nvar ExpandToggle = function (_EventEmitter) {\n _inherits(ExpandToggle, _EventEmitter);\n\n function ExpandToggle(el, opts) {\n _classCallCheck(this, ExpandToggle);\n\n var _this = _possibleConstructorReturn(this, (ExpandToggle.__proto__ || Object.getPrototypeOf(ExpandToggle)).call(this));\n // Have to call super() first before referencing “this” since we’re extending EventEmitter\n // https://stackoverflow.com/a/43591507/673457\n\n\n _this.el = el;\n _this.targetId = _this.el.getAttribute(\"data-expands\");\n _this.targetEl = document.getElementById(_this.targetId);\n\n // Ensure target element exist before initializing\n if (!_this.targetEl) {\n var _ret;\n\n console.warn(\"Can\\u2019t find expandable target with id \\u201C\" + _this.targetId + \"\\u201D\");\n return _ret = false, _possibleConstructorReturn(_this, _ret);\n }\n\n // Use Object.assign() to merge “opts” object with default values in this.options\n _this.options = Object.assign({}, {\n expandedClasses: \"\", // string, accepts multiple space-separated classes\n shouldToggleHeight: false, // should target element’s height be animated using max-height\n activeToggleText: \"\", // expanded state toggle button text\n onReady: null // ready callback function\n }, opts);\n\n // Check for custom expanded class(es)\n _this.expandedClasses = _this.el.getAttribute(\"data-expands-class\") || _this.options.expandedClasses;\n\n if (_this.expandedClasses.length) {\n // Check if active class string contains multiple classes\n if (_this.expandedClasses.indexOf(\" \") > -1) {\n // Convert to array and remove any empty string values\n // caused by having multiple spaces in a row.\n _this.expandedClasses = _this.expandedClasses.split(\" \").filter(function (n) {\n return n.length;\n });\n } else {\n // We still need to convert a single active class to an array\n // so we can use the spread syntax later in classList.add()\n _this.expandedClasses = [_this.expandedClasses];\n }\n }\n\n // Check if height should be animated\n _this.shouldToggleHeight = _this.el.hasAttribute(\"data-expands-height\") || _this.options.shouldToggleHeight;\n\n // Check for custom toggle button text to use when expanded\n _this.hasActiveText = false;\n _this.textEl = _this.el.querySelector(\"[data-expands-text]\");\n\n if (_this.textEl) {\n _this.defaultToggleText = _this.textEl.textContent;\n _this.activeToggleText = _this.textEl.getAttribute(\"data-expands-text\") || _this.options.activeToggleText;\n _this.hasActiveText = !!_this.activeToggleText.length;\n }\n\n _this.init();\n return _this;\n }\n\n _createClass(ExpandToggle, [{\n key: \"init\",\n value: function init() {\n // Accessibility setup\n this.el.setAttribute(\"aria-haspopup\", true);\n this.el.setAttribute(\"aria-expanded\", false);\n // Omit “aria-controls” for now\n // See https://inclusive-components.design/menus-menu-buttons/#ariacontrols\n // this.el.setAttribute(\"aria-controls\", this.targetId);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.setAttribute(\"role\", \"button\");\n }\n\n if (this.shouldToggleHeight) {\n this.heightToggleSetup();\n }\n\n // Click event listener on toggle button\n // Note: Callback needs to be assigned to a var so we can remove it since we’re using bind()\n // https://stackoverflow.com/a/22870717/673457\n this.clickHandler = this.toggle.bind(this);\n this.el.addEventListener(\"click\", this.clickHandler);\n\n // Keyboard listeners on toggle button\n this.keydownHandler = this.keyboardEvents.bind(this);\n this.el.addEventListener(\"keydown\", this.keydownHandler);\n\n // Check for onReady callback\n if (typeof this.options.onReady === \"function\") {\n this.options.onReady();\n }\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n // Remove aria attributes\n this.el.removeAttribute(\"aria-haspopup\");\n this.el.removeAttribute(\"aria-expanded\");\n this.targetEl.removeAttribute(\"aria-hidden\");\n this.targetEl.style.removeProperty(\"max-height\");\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.removeAttribute(\"role\");\n }\n\n // Reset toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove custom classes\n if (this.expandedClasses.length) {\n var _el$classList, _targetEl$classList;\n\n (_el$classList = this.el.classList).remove.apply(_el$classList, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList = this.targetEl.classList).remove.apply(_targetEl$classList, _toConsumableArray(this.expandedClasses));\n }\n\n // Remove event listeners\n this.el.removeEventListener(\"click\", this.clickHandler);\n this.el.removeEventListener(\"keydown\", this.keydownHandler);\n\n this.emitEvent(\"destroy\");\n }\n }, {\n key: \"keyboardEvents\",\n value: function keyboardEvents(evt) {\n // Expand with down arrow\n if (evt.keyCode == 40) {\n this.expand();\n } else if (evt.keyCode == 38 || evt.keyCode == 27) {\n // Close with up arrow or escape key\n this.collapse();\n }\n }\n }, {\n key: \"heightToggleSetup\",\n value: function heightToggleSetup() {\n var self = this;\n this.targetParentEl = this.targetEl.parentNode;\n\n // Set max-height to the expanded height so we can animate it.\n this.updateExpandedHeight();\n\n // Update target element’s max-height on resize\n window.addEventListener(\"resize\", (0, _debounce2.default)(function (event) {\n self.updateExpandedHeight();\n }, 150));\n }\n\n // Set max-height of target element to its expanded height without triggering relayout.\n //\n // This technique works by creating an absolutely-positioned invisible clone of the target\n // element and calculating its height. This avoids any relayout that would otherwise occur\n // if the element was briefly expanded so we could measure it.\n //\n // Note: We’re using CSS to transition max-height instead jQuery’s slideToggle(),\n // or another 3rd-party lib like Velocity.js, to avoid loading a large lib.\n\n }, {\n key: \"updateExpandedHeight\",\n value: function updateExpandedHeight() {\n // Get width of original element so we can apply it to the clone\n var nodeWidth = Math.round(parseFloat(this.targetEl.offsetWidth));\n\n // Create clone of node\n var cloneEl = this.targetEl.cloneNode(true); // 'true' includes child nodes\n\n // Inline styles added to prevent reflow, ensure clone is same size as expanded element\n cloneEl.style.cssText = \"max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: \" + nodeWidth + \"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important\";\n\n // Update “aria-hidden” attribute\n cloneEl.setAttribute(\"aria-hidden\", false);\n\n // Remove id just to be safe\n cloneEl.removeAttribute(\"id\");\n\n // Append clone to document, save as new var so we can remove it later\n var newEl = this.targetParentEl.insertBefore(cloneEl, this.targetEl);\n\n // Calculate height\n var expandedHeight = Math.round(parseFloat(newEl.offsetHeight));\n\n // Remove cloned node to clean up after ourselves\n this.targetParentEl.removeChild(newEl);\n\n // Apply inline max-height to collapsed element\n // Note: CSS is overriding this when aria-hidden=\"true\"\n this.targetEl.style.maxHeight = expandedHeight + \"px\";\n }\n }, {\n key: \"expand\",\n value: function expand() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.activeToggleText;\n }\n\n // Add classes\n if (this.expandedClasses.length) {\n var _el$classList2, _targetEl$classList2;\n\n (_el$classList2 = this.el.classList).add.apply(_el$classList2, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList2 = this.targetEl.classList).add.apply(_targetEl$classList2, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", true);\n this.targetEl.setAttribute(\"aria-hidden\", false);\n\n this.emitEvent(\"expand\");\n }\n }, {\n key: \"collapse\",\n value: function collapse() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove classes\n if (this.expandedClasses.length) {\n var _el$classList3, _targetEl$classList3;\n\n (_el$classList3 = this.el.classList).remove.apply(_el$classList3, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList3 = this.targetEl.classList).remove.apply(_targetEl$classList3, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", false);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n this.emitEvent(\"collapse\");\n }\n }, {\n key: \"toggle\",\n value: function toggle(evt) {\n if (this.el.getAttribute(\"aria-expanded\") === \"true\") {\n this.collapse();\n } else {\n this.expand();\n }\n }\n }]);\n\n return ExpandToggle;\n}(_evEmitter2.default);\n\nexports.default = ExpandToggle;\n\n//# sourceURL=webpack://%5Bname%5DLink/./index.js?"); | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debounce = __webpack_require__(/*! lodash/debounce */ \"./node_modules/lodash/debounce.js\");\n\nvar _debounce2 = _interopRequireDefault(_debounce);\n\nvar _evEmitter = __webpack_require__(/*! ev-emitter */ \"./node_modules/ev-emitter/ev-emitter.js\");\n\nvar _evEmitter2 = _interopRequireDefault(_evEmitter);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\n/**\n * Wrap the last X words in an HTML tag to prevent them from wrapping (i.e. orphans)\n * @param {HTMLElement} el - Toggle button DOM node\n * @param {Object} opts - Options\n * @param {string} [opts.expandedClasses=\"\"] - Class(es) to apply when expanded\n * @param {boolean} [opts.shouldToggleHeight=false] - Whether or not to animate height\n * @param {string} [opts.defaultToggleText=\"\"] - Expanded state toggle button text\n * @param {function} [opts.onReady=\"\"] - Ready callback function\n */\nvar ExpandToggle = function (_EventEmitter) {\n _inherits(ExpandToggle, _EventEmitter);\n\n function ExpandToggle(el, opts) {\n _classCallCheck(this, ExpandToggle);\n\n var _this = _possibleConstructorReturn(this, (ExpandToggle.__proto__ || Object.getPrototypeOf(ExpandToggle)).call(this));\n // Have to call super() first before referencing “this” since we’re extending EventEmitter\n // https://stackoverflow.com/a/43591507/673457\n\n\n _this.el = el;\n _this.targetId = _this.el.getAttribute(\"data-expands\");\n _this.targetEl = document.getElementById(_this.targetId);\n\n // Ensure target element exist before initializing\n if (!_this.targetEl) {\n var _ret;\n\n console.warn(\"Can\\u2019t find expandable target with id \\u201C\" + _this.targetId + \"\\u201D\");\n return _ret = false, _possibleConstructorReturn(_this, _ret);\n }\n\n // Use Object.assign() to merge “opts” object with default values in this.options\n _this.options = Object.assign({}, {\n expandedClasses: \"\", // string, accepts multiple space-separated classes\n shouldToggleHeight: false, // should target element’s height be animated using max-height\n activeToggleText: \"\", // expanded state toggle button text\n onReady: null // ready callback function\n }, opts);\n\n // Check for custom expanded class(es)\n _this.expandedClasses = _this.el.getAttribute(\"data-expands-class\") || _this.options.expandedClasses;\n\n if (_this.expandedClasses.length) {\n // Check if active class string contains multiple classes\n if (_this.expandedClasses.indexOf(\" \") > -1) {\n // Convert to array and remove any empty string values\n // caused by having multiple spaces in a row.\n _this.expandedClasses = _this.expandedClasses.split(\" \").filter(function (n) {\n return n.length;\n });\n } else {\n // We still need to convert a single active class to an array\n // so we can use the spread syntax later in classList.add()\n _this.expandedClasses = [_this.expandedClasses];\n }\n }\n\n // Check if height should be animated\n _this.shouldToggleHeight = _this.el.hasAttribute(\"data-expands-height\") || _this.options.shouldToggleHeight;\n\n // Check for custom toggle button text to use when expanded\n _this.hasActiveText = false;\n _this.textEl = _this.el.querySelector(\"[data-expands-text]\");\n\n if (_this.textEl) {\n _this.defaultToggleText = _this.textEl.textContent;\n _this.activeToggleText = _this.textEl.getAttribute(\"data-expands-text\") || _this.options.activeToggleText;\n _this.hasActiveText = !!_this.activeToggleText.length;\n }\n\n _this.init();\n return _this;\n }\n\n _createClass(ExpandToggle, [{\n key: \"init\",\n value: function init() {\n // Accessibility setup\n this.el.setAttribute(\"aria-haspopup\", true);\n this.el.setAttribute(\"aria-expanded\", false);\n // Omit “aria-controls” for now\n // See https://inclusive-components.design/menus-menu-buttons/#ariacontrols\n // this.el.setAttribute(\"aria-controls\", this.targetId);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.setAttribute(\"role\", \"button\");\n }\n\n if (this.shouldToggleHeight) {\n this.heightToggleSetup();\n }\n\n // Click event listener on toggle button\n // Note: Callback needs to be assigned to a var so we can remove it since we’re using bind()\n // https://stackoverflow.com/a/22870717/673457\n this.clickHandler = this.toggle.bind(this);\n this.el.addEventListener(\"click\", this.clickHandler);\n\n // Keyboard listeners on toggle button\n this.keydownHandler = this.keyboardEvents.bind(this);\n this.el.addEventListener(\"keydown\", this.keydownHandler);\n\n // Check for onReady callback\n if (typeof this.options.onReady === \"function\") {\n this.options.onReady();\n }\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n // Remove aria attributes\n this.el.removeAttribute(\"aria-haspopup\");\n this.el.removeAttribute(\"aria-expanded\");\n this.targetEl.removeAttribute(\"aria-hidden\");\n this.targetEl.style.removeProperty(\"max-height\");\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.removeAttribute(\"role\");\n }\n\n // Reset toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove custom classes\n if (this.expandedClasses.length) {\n var _el$classList, _targetEl$classList;\n\n (_el$classList = this.el.classList).remove.apply(_el$classList, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList = this.targetEl.classList).remove.apply(_targetEl$classList, _toConsumableArray(this.expandedClasses));\n }\n\n // Remove event listeners\n this.el.removeEventListener(\"click\", this.clickHandler);\n this.el.removeEventListener(\"keydown\", this.keydownHandler);\n\n this.emitEvent(\"destroy\");\n }\n }, {\n key: \"keyboardEvents\",\n value: function keyboardEvents(evt) {\n // Expand with down arrow\n if (evt.keyCode == 40) {\n this.expand();\n } else if (evt.keyCode == 38 || evt.keyCode == 27) {\n // Close with up arrow or escape key\n this.collapse();\n }\n }\n }, {\n key: \"heightToggleSetup\",\n value: function heightToggleSetup() {\n var self = this;\n this.targetParentEl = this.targetEl.parentNode;\n\n // Set max-height to the expanded height so we can animate it.\n this.updateExpandedHeight();\n\n // Update target element’s max-height on resize\n window.addEventListener(\"resize\", (0, _debounce2.default)(function (event) {\n self.updateExpandedHeight();\n }, 150));\n }\n\n // Set max-height of target element to its expanded height without triggering relayout.\n //\n // This technique works by creating an absolutely-positioned invisible clone of the target\n // element and calculating its height. This avoids any relayout that would otherwise occur\n // if the element was briefly expanded so we could measure it.\n //\n // Note: We’re using CSS to transition max-height instead jQuery’s slideToggle(),\n // or another 3rd-party lib like Velocity.js, to avoid loading a large lib.\n\n }, {\n key: \"updateExpandedHeight\",\n value: function updateExpandedHeight() {\n // Get width of original element so we can apply it to the clone\n var nodeWidth = Math.round(parseFloat(this.targetEl.offsetWidth));\n\n // Create clone of node\n var cloneEl = this.targetEl.cloneNode(true); // 'true' includes child nodes\n\n // Inline styles added to prevent reflow, ensure clone is same size as expanded element\n cloneEl.style.cssText = \"max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: \" + nodeWidth + \"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important\";\n\n // Update “aria-hidden” attribute\n cloneEl.setAttribute(\"aria-hidden\", false);\n\n // Remove id just to be safe\n cloneEl.removeAttribute(\"id\");\n\n // Append clone to document, save as new var so we can remove it later\n var newEl = this.targetParentEl.insertBefore(cloneEl, this.targetEl);\n\n // Calculate height\n var expandedHeight = Math.round(parseFloat(newEl.offsetHeight));\n\n // Remove cloned node to clean up after ourselves\n this.targetParentEl.removeChild(newEl);\n\n // Apply inline max-height to collapsed element\n // Note: CSS is overriding this when aria-hidden=\"true\"\n this.targetEl.style.maxHeight = expandedHeight + \"px\";\n }\n }, {\n key: \"expand\",\n value: function expand() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.activeToggleText;\n }\n\n // Add classes\n if (this.expandedClasses.length) {\n var _el$classList2, _targetEl$classList2;\n\n (_el$classList2 = this.el.classList).add.apply(_el$classList2, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList2 = this.targetEl.classList).add.apply(_targetEl$classList2, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", true);\n this.targetEl.setAttribute(\"aria-hidden\", false);\n\n this.emitEvent(\"expand\");\n }\n }, {\n key: \"collapse\",\n value: function collapse() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove classes\n if (this.expandedClasses.length) {\n var _el$classList3, _targetEl$classList3;\n\n (_el$classList3 = this.el.classList).remove.apply(_el$classList3, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList3 = this.targetEl.classList).remove.apply(_targetEl$classList3, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", false);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n this.emitEvent(\"collapse\");\n }\n }, {\n key: \"toggle\",\n value: function toggle(evt) {\n // Prevent default in case toggle element is a link instead of a button\n evt.preventDefault();\n\n if (this.el.getAttribute(\"aria-expanded\") === \"true\") {\n this.collapse();\n } else {\n this.expand();\n }\n }\n }]);\n\n return ExpandToggle;\n}(_evEmitter2.default);\n\nexports.default = ExpandToggle;\n\n//# sourceURL=webpack://%5Bname%5DLink/./index.js?"); | ||
@@ -86,0 +86,0 @@ /***/ }), |
@@ -92,3 +92,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
"use strict"; | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debounce = __webpack_require__(/*! lodash/debounce */ \"./node_modules/lodash/debounce.js\");\n\nvar _debounce2 = _interopRequireDefault(_debounce);\n\nvar _evEmitter = __webpack_require__(/*! ev-emitter */ \"./node_modules/ev-emitter/ev-emitter.js\");\n\nvar _evEmitter2 = _interopRequireDefault(_evEmitter);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\n/**\n * Wrap the last X words in an HTML tag to prevent them from wrapping (i.e. orphans)\n * @param {HTMLElement} el - Toggle button DOM node\n * @param {Object} opts - Options\n * @param {string} [opts.expandedClasses=\"\"] - Class(es) to apply when expanded\n * @param {boolean} [opts.shouldToggleHeight=false] - Whether or not to animate height\n * @param {string} [opts.defaultToggleText=\"\"] - Expanded state toggle button text\n * @param {function} [opts.onReady=\"\"] - Ready callback function\n */\nvar ExpandToggle = function (_EventEmitter) {\n _inherits(ExpandToggle, _EventEmitter);\n\n function ExpandToggle(el, opts) {\n _classCallCheck(this, ExpandToggle);\n\n var _this = _possibleConstructorReturn(this, (ExpandToggle.__proto__ || Object.getPrototypeOf(ExpandToggle)).call(this));\n // Have to call super() first before referencing “this” since we’re extending EventEmitter\n // https://stackoverflow.com/a/43591507/673457\n\n\n _this.el = el;\n _this.targetId = _this.el.getAttribute(\"data-expands\");\n _this.targetEl = document.getElementById(_this.targetId);\n\n // Ensure target element exist before initializing\n if (!_this.targetEl) {\n var _ret;\n\n console.warn(\"Can\\u2019t find expandable target with id \\u201C\" + _this.targetId + \"\\u201D\");\n return _ret = false, _possibleConstructorReturn(_this, _ret);\n }\n\n // Use Object.assign() to merge “opts” object with default values in this.options\n _this.options = Object.assign({}, {\n expandedClasses: \"\", // string, accepts multiple space-separated classes\n shouldToggleHeight: false, // should target element’s height be animated using max-height\n activeToggleText: \"\", // expanded state toggle button text\n onReady: null // ready callback function\n }, opts);\n\n // Check for custom expanded class(es)\n _this.expandedClasses = _this.el.getAttribute(\"data-expands-class\") || _this.options.expandedClasses;\n\n if (_this.expandedClasses.length) {\n // Check if active class string contains multiple classes\n if (_this.expandedClasses.indexOf(\" \") > -1) {\n // Convert to array and remove any empty string values\n // caused by having multiple spaces in a row.\n _this.expandedClasses = _this.expandedClasses.split(\" \").filter(function (n) {\n return n.length;\n });\n } else {\n // We still need to convert a single active class to an array\n // so we can use the spread syntax later in classList.add()\n _this.expandedClasses = [_this.expandedClasses];\n }\n }\n\n // Check if height should be animated\n _this.shouldToggleHeight = _this.el.hasAttribute(\"data-expands-height\") || _this.options.shouldToggleHeight;\n\n // Check for custom toggle button text to use when expanded\n _this.hasActiveText = false;\n _this.textEl = _this.el.querySelector(\"[data-expands-text]\");\n\n if (_this.textEl) {\n _this.defaultToggleText = _this.textEl.textContent;\n _this.activeToggleText = _this.textEl.getAttribute(\"data-expands-text\") || _this.options.activeToggleText;\n _this.hasActiveText = !!_this.activeToggleText.length;\n }\n\n _this.init();\n return _this;\n }\n\n _createClass(ExpandToggle, [{\n key: \"init\",\n value: function init() {\n // Accessibility setup\n this.el.setAttribute(\"aria-haspopup\", true);\n this.el.setAttribute(\"aria-expanded\", false);\n // Omit “aria-controls” for now\n // See https://inclusive-components.design/menus-menu-buttons/#ariacontrols\n // this.el.setAttribute(\"aria-controls\", this.targetId);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.setAttribute(\"role\", \"button\");\n }\n\n if (this.shouldToggleHeight) {\n this.heightToggleSetup();\n }\n\n // Click event listener on toggle button\n // Note: Callback needs to be assigned to a var so we can remove it since we’re using bind()\n // https://stackoverflow.com/a/22870717/673457\n this.clickHandler = this.toggle.bind(this);\n this.el.addEventListener(\"click\", this.clickHandler);\n\n // Keyboard listeners on toggle button\n this.keydownHandler = this.keyboardEvents.bind(this);\n this.el.addEventListener(\"keydown\", this.keydownHandler);\n\n // Check for onReady callback\n if (typeof this.options.onReady === \"function\") {\n this.options.onReady();\n }\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n // Remove aria attributes\n this.el.removeAttribute(\"aria-haspopup\");\n this.el.removeAttribute(\"aria-expanded\");\n this.targetEl.removeAttribute(\"aria-hidden\");\n this.targetEl.style.removeProperty(\"max-height\");\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.removeAttribute(\"role\");\n }\n\n // Reset toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove custom classes\n if (this.expandedClasses.length) {\n var _el$classList, _targetEl$classList;\n\n (_el$classList = this.el.classList).remove.apply(_el$classList, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList = this.targetEl.classList).remove.apply(_targetEl$classList, _toConsumableArray(this.expandedClasses));\n }\n\n // Remove event listeners\n this.el.removeEventListener(\"click\", this.clickHandler);\n this.el.removeEventListener(\"keydown\", this.keydownHandler);\n\n this.emitEvent(\"destroy\");\n }\n }, {\n key: \"keyboardEvents\",\n value: function keyboardEvents(evt) {\n // Expand with down arrow\n if (evt.keyCode == 40) {\n this.expand();\n } else if (evt.keyCode == 38 || evt.keyCode == 27) {\n // Close with up arrow or escape key\n this.collapse();\n }\n }\n }, {\n key: \"heightToggleSetup\",\n value: function heightToggleSetup() {\n var self = this;\n this.targetParentEl = this.targetEl.parentNode;\n\n // Set max-height to the expanded height so we can animate it.\n this.updateExpandedHeight();\n\n // Update target element’s max-height on resize\n window.addEventListener(\"resize\", (0, _debounce2.default)(function (event) {\n self.updateExpandedHeight();\n }, 150));\n }\n\n // Set max-height of target element to its expanded height without triggering relayout.\n //\n // This technique works by creating an absolutely-positioned invisible clone of the target\n // element and calculating its height. This avoids any relayout that would otherwise occur\n // if the element was briefly expanded so we could measure it.\n //\n // Note: We’re using CSS to transition max-height instead jQuery’s slideToggle(),\n // or another 3rd-party lib like Velocity.js, to avoid loading a large lib.\n\n }, {\n key: \"updateExpandedHeight\",\n value: function updateExpandedHeight() {\n // Get width of original element so we can apply it to the clone\n var nodeWidth = Math.round(parseFloat(this.targetEl.offsetWidth));\n\n // Create clone of node\n var cloneEl = this.targetEl.cloneNode(true); // 'true' includes child nodes\n\n // Inline styles added to prevent reflow, ensure clone is same size as expanded element\n cloneEl.style.cssText = \"max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: \" + nodeWidth + \"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important\";\n\n // Update “aria-hidden” attribute\n cloneEl.setAttribute(\"aria-hidden\", false);\n\n // Remove id just to be safe\n cloneEl.removeAttribute(\"id\");\n\n // Append clone to document, save as new var so we can remove it later\n var newEl = this.targetParentEl.insertBefore(cloneEl, this.targetEl);\n\n // Calculate height\n var expandedHeight = Math.round(parseFloat(newEl.offsetHeight));\n\n // Remove cloned node to clean up after ourselves\n this.targetParentEl.removeChild(newEl);\n\n // Apply inline max-height to collapsed element\n // Note: CSS is overriding this when aria-hidden=\"true\"\n this.targetEl.style.maxHeight = expandedHeight + \"px\";\n }\n }, {\n key: \"expand\",\n value: function expand() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.activeToggleText;\n }\n\n // Add classes\n if (this.expandedClasses.length) {\n var _el$classList2, _targetEl$classList2;\n\n (_el$classList2 = this.el.classList).add.apply(_el$classList2, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList2 = this.targetEl.classList).add.apply(_targetEl$classList2, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", true);\n this.targetEl.setAttribute(\"aria-hidden\", false);\n\n this.emitEvent(\"expand\");\n }\n }, {\n key: \"collapse\",\n value: function collapse() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove classes\n if (this.expandedClasses.length) {\n var _el$classList3, _targetEl$classList3;\n\n (_el$classList3 = this.el.classList).remove.apply(_el$classList3, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList3 = this.targetEl.classList).remove.apply(_targetEl$classList3, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", false);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n this.emitEvent(\"collapse\");\n }\n }, {\n key: \"toggle\",\n value: function toggle(evt) {\n if (this.el.getAttribute(\"aria-expanded\") === \"true\") {\n this.collapse();\n } else {\n this.expand();\n }\n }\n }]);\n\n return ExpandToggle;\n}(_evEmitter2.default);\n\nexports.default = ExpandToggle;\n\n//# sourceURL=webpack://%5Bname%5DLink/./index.js?"); | ||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();\n\nvar _debounce = __webpack_require__(/*! lodash/debounce */ \"./node_modules/lodash/debounce.js\");\n\nvar _debounce2 = _interopRequireDefault(_debounce);\n\nvar _evEmitter = __webpack_require__(/*! ev-emitter */ \"./node_modules/ev-emitter/ev-emitter.js\");\n\nvar _evEmitter2 = _interopRequireDefault(_evEmitter);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\n/**\n * Wrap the last X words in an HTML tag to prevent them from wrapping (i.e. orphans)\n * @param {HTMLElement} el - Toggle button DOM node\n * @param {Object} opts - Options\n * @param {string} [opts.expandedClasses=\"\"] - Class(es) to apply when expanded\n * @param {boolean} [opts.shouldToggleHeight=false] - Whether or not to animate height\n * @param {string} [opts.defaultToggleText=\"\"] - Expanded state toggle button text\n * @param {function} [opts.onReady=\"\"] - Ready callback function\n */\nvar ExpandToggle = function (_EventEmitter) {\n _inherits(ExpandToggle, _EventEmitter);\n\n function ExpandToggle(el, opts) {\n _classCallCheck(this, ExpandToggle);\n\n var _this = _possibleConstructorReturn(this, (ExpandToggle.__proto__ || Object.getPrototypeOf(ExpandToggle)).call(this));\n // Have to call super() first before referencing “this” since we’re extending EventEmitter\n // https://stackoverflow.com/a/43591507/673457\n\n\n _this.el = el;\n _this.targetId = _this.el.getAttribute(\"data-expands\");\n _this.targetEl = document.getElementById(_this.targetId);\n\n // Ensure target element exist before initializing\n if (!_this.targetEl) {\n var _ret;\n\n console.warn(\"Can\\u2019t find expandable target with id \\u201C\" + _this.targetId + \"\\u201D\");\n return _ret = false, _possibleConstructorReturn(_this, _ret);\n }\n\n // Use Object.assign() to merge “opts” object with default values in this.options\n _this.options = Object.assign({}, {\n expandedClasses: \"\", // string, accepts multiple space-separated classes\n shouldToggleHeight: false, // should target element’s height be animated using max-height\n activeToggleText: \"\", // expanded state toggle button text\n onReady: null // ready callback function\n }, opts);\n\n // Check for custom expanded class(es)\n _this.expandedClasses = _this.el.getAttribute(\"data-expands-class\") || _this.options.expandedClasses;\n\n if (_this.expandedClasses.length) {\n // Check if active class string contains multiple classes\n if (_this.expandedClasses.indexOf(\" \") > -1) {\n // Convert to array and remove any empty string values\n // caused by having multiple spaces in a row.\n _this.expandedClasses = _this.expandedClasses.split(\" \").filter(function (n) {\n return n.length;\n });\n } else {\n // We still need to convert a single active class to an array\n // so we can use the spread syntax later in classList.add()\n _this.expandedClasses = [_this.expandedClasses];\n }\n }\n\n // Check if height should be animated\n _this.shouldToggleHeight = _this.el.hasAttribute(\"data-expands-height\") || _this.options.shouldToggleHeight;\n\n // Check for custom toggle button text to use when expanded\n _this.hasActiveText = false;\n _this.textEl = _this.el.querySelector(\"[data-expands-text]\");\n\n if (_this.textEl) {\n _this.defaultToggleText = _this.textEl.textContent;\n _this.activeToggleText = _this.textEl.getAttribute(\"data-expands-text\") || _this.options.activeToggleText;\n _this.hasActiveText = !!_this.activeToggleText.length;\n }\n\n _this.init();\n return _this;\n }\n\n _createClass(ExpandToggle, [{\n key: \"init\",\n value: function init() {\n // Accessibility setup\n this.el.setAttribute(\"aria-haspopup\", true);\n this.el.setAttribute(\"aria-expanded\", false);\n // Omit “aria-controls” for now\n // See https://inclusive-components.design/menus-menu-buttons/#ariacontrols\n // this.el.setAttribute(\"aria-controls\", this.targetId);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.setAttribute(\"role\", \"button\");\n }\n\n if (this.shouldToggleHeight) {\n this.heightToggleSetup();\n }\n\n // Click event listener on toggle button\n // Note: Callback needs to be assigned to a var so we can remove it since we’re using bind()\n // https://stackoverflow.com/a/22870717/673457\n this.clickHandler = this.toggle.bind(this);\n this.el.addEventListener(\"click\", this.clickHandler);\n\n // Keyboard listeners on toggle button\n this.keydownHandler = this.keyboardEvents.bind(this);\n this.el.addEventListener(\"keydown\", this.keydownHandler);\n\n // Check for onReady callback\n if (typeof this.options.onReady === \"function\") {\n this.options.onReady();\n }\n }\n }, {\n key: \"destroy\",\n value: function destroy() {\n // Remove aria attributes\n this.el.removeAttribute(\"aria-haspopup\");\n this.el.removeAttribute(\"aria-expanded\");\n this.targetEl.removeAttribute(\"aria-hidden\");\n this.targetEl.style.removeProperty(\"max-height\");\n\n if (this.el.tagName.toLowerCase() === \"a\") {\n this.el.removeAttribute(\"role\");\n }\n\n // Reset toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove custom classes\n if (this.expandedClasses.length) {\n var _el$classList, _targetEl$classList;\n\n (_el$classList = this.el.classList).remove.apply(_el$classList, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList = this.targetEl.classList).remove.apply(_targetEl$classList, _toConsumableArray(this.expandedClasses));\n }\n\n // Remove event listeners\n this.el.removeEventListener(\"click\", this.clickHandler);\n this.el.removeEventListener(\"keydown\", this.keydownHandler);\n\n this.emitEvent(\"destroy\");\n }\n }, {\n key: \"keyboardEvents\",\n value: function keyboardEvents(evt) {\n // Expand with down arrow\n if (evt.keyCode == 40) {\n this.expand();\n } else if (evt.keyCode == 38 || evt.keyCode == 27) {\n // Close with up arrow or escape key\n this.collapse();\n }\n }\n }, {\n key: \"heightToggleSetup\",\n value: function heightToggleSetup() {\n var self = this;\n this.targetParentEl = this.targetEl.parentNode;\n\n // Set max-height to the expanded height so we can animate it.\n this.updateExpandedHeight();\n\n // Update target element’s max-height on resize\n window.addEventListener(\"resize\", (0, _debounce2.default)(function (event) {\n self.updateExpandedHeight();\n }, 150));\n }\n\n // Set max-height of target element to its expanded height without triggering relayout.\n //\n // This technique works by creating an absolutely-positioned invisible clone of the target\n // element and calculating its height. This avoids any relayout that would otherwise occur\n // if the element was briefly expanded so we could measure it.\n //\n // Note: We’re using CSS to transition max-height instead jQuery’s slideToggle(),\n // or another 3rd-party lib like Velocity.js, to avoid loading a large lib.\n\n }, {\n key: \"updateExpandedHeight\",\n value: function updateExpandedHeight() {\n // Get width of original element so we can apply it to the clone\n var nodeWidth = Math.round(parseFloat(this.targetEl.offsetWidth));\n\n // Create clone of node\n var cloneEl = this.targetEl.cloneNode(true); // 'true' includes child nodes\n\n // Inline styles added to prevent reflow, ensure clone is same size as expanded element\n cloneEl.style.cssText = \"max-height: none !important; position: absolute !important; right: 100% !important; visibility: hidden !important; width: \" + nodeWidth + \"px !important; -webkit-transition: none !important; -moz-transition: none !important; transition: none !important\";\n\n // Update “aria-hidden” attribute\n cloneEl.setAttribute(\"aria-hidden\", false);\n\n // Remove id just to be safe\n cloneEl.removeAttribute(\"id\");\n\n // Append clone to document, save as new var so we can remove it later\n var newEl = this.targetParentEl.insertBefore(cloneEl, this.targetEl);\n\n // Calculate height\n var expandedHeight = Math.round(parseFloat(newEl.offsetHeight));\n\n // Remove cloned node to clean up after ourselves\n this.targetParentEl.removeChild(newEl);\n\n // Apply inline max-height to collapsed element\n // Note: CSS is overriding this when aria-hidden=\"true\"\n this.targetEl.style.maxHeight = expandedHeight + \"px\";\n }\n }, {\n key: \"expand\",\n value: function expand() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.activeToggleText;\n }\n\n // Add classes\n if (this.expandedClasses.length) {\n var _el$classList2, _targetEl$classList2;\n\n (_el$classList2 = this.el.classList).add.apply(_el$classList2, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList2 = this.targetEl.classList).add.apply(_targetEl$classList2, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", true);\n this.targetEl.setAttribute(\"aria-hidden\", false);\n\n this.emitEvent(\"expand\");\n }\n }, {\n key: \"collapse\",\n value: function collapse() {\n // Update toggle text\n if (this.hasActiveText) {\n this.textEl.textContent = this.defaultToggleText;\n }\n\n // Remove classes\n if (this.expandedClasses.length) {\n var _el$classList3, _targetEl$classList3;\n\n (_el$classList3 = this.el.classList).remove.apply(_el$classList3, _toConsumableArray(this.expandedClasses));\n (_targetEl$classList3 = this.targetEl.classList).remove.apply(_targetEl$classList3, _toConsumableArray(this.expandedClasses));\n }\n\n // Update aria attributes\n this.el.setAttribute(\"aria-expanded\", false);\n this.targetEl.setAttribute(\"aria-hidden\", true);\n\n this.emitEvent(\"collapse\");\n }\n }, {\n key: \"toggle\",\n value: function toggle(evt) {\n // Prevent default in case toggle element is a link instead of a button\n evt.preventDefault();\n\n if (this.el.getAttribute(\"aria-expanded\") === \"true\") {\n this.collapse();\n } else {\n this.expand();\n }\n }\n }]);\n\n return ExpandToggle;\n}(_evEmitter2.default);\n\nexports.default = ExpandToggle;\n\n//# sourceURL=webpack://%5Bname%5DLink/./index.js?"); | ||
@@ -95,0 +95,0 @@ /***/ }), |
@@ -251,2 +251,5 @@ "use strict"; | ||
toggle(evt) { | ||
// Prevent default in case toggle element is a link instead of a button | ||
evt.preventDefault(); | ||
if (this.el.getAttribute("aria-expanded") === "true") { | ||
@@ -253,0 +256,0 @@ this.collapse(); |
{ | ||
"name": "@threespot/expand-toggle", | ||
"version": "1.3.0", | ||
"version": "1.3.2", | ||
"description": "Simple and accessible expandable functionality, similar to jQuery’s `slideToggle()` method.", | ||
@@ -5,0 +5,0 @@ "main": "dist/expand-toggle.m.js", |
108
README.md
@@ -40,32 +40,32 @@ # Expand Toggle | ||
```scss | ||
// This class name is just an example | ||
.expandable { | ||
$transition-speed: 400ms; | ||
// This class name is just an example | ||
.expandable { | ||
$transition-speed: 400ms; | ||
// Expanded state | ||
&, | ||
.js &[aria-hidden="false"] { | ||
overflow: hidden; | ||
transition: max-height $transition-speed ease-in-out, | ||
visibility 0s linear 0s; | ||
visibility: visible; | ||
} | ||
// Expanded state | ||
&, | ||
.js &[aria-hidden="false"] { | ||
overflow: hidden; | ||
transition: max-height $transition-speed ease-in-out, | ||
visibility 0s linear 0s; | ||
visibility: visible; | ||
} | ||
// Collapsed state | ||
&[aria-hidden="true"], | ||
// Selector below prevents a flash of unstyled content (FOUC) | ||
.js &:not([aria-hidden]) { | ||
max-height: 0 !important;// !important required to override inline styles added by JS | ||
transition: max-height $transition-speed ease-in-out, | ||
visibility 0s linear $transition-speed; | ||
visibility: hidden; | ||
} | ||
// Collapsed state | ||
&[aria-hidden="true"], | ||
// Selector below prevents a flash of unstyled content (FOUC) | ||
.js &:not([aria-hidden]) { | ||
max-height: 0 !important;// !important required to override inline styles added by JS | ||
transition: max-height $transition-speed ease-in-out, | ||
visibility 0s linear $transition-speed; | ||
visibility: hidden; | ||
} | ||
} | ||
// We also suggest hiding the button when JS is disabled. | ||
// Note: Modernizr looks for a “no-js” class on the html tag and replaces it with “js” on load. | ||
// If not using Modernizr, see https://www.paulirish.com/2009/avoiding-the-fouc-v3/ | ||
.no-js [data-expands] { | ||
display: none; | ||
} | ||
// We also suggest hiding the button when JS is disabled. | ||
// Note: Modernizr looks for a “no-js” class on the html tag and replaces it with “js” on load. | ||
// If not using Modernizr, see https://www.paulirish.com/2009/avoiding-the-fouc-v3/ | ||
.no-js [data-expands] { | ||
display: none; | ||
} | ||
``` | ||
@@ -76,9 +76,9 @@ | ||
```html | ||
<button type="button" data-expands="demo" data-expands-class="is-expanded" data-expands-height> | ||
<span data-expands-text="Close">Open</span> | ||
</button> | ||
<button type="button" data-expands="demo" data-expands-class="is-expanded" data-expands-height> | ||
<span data-expands-text="Close">Open</span> | ||
</button> | ||
<div class="expandable" id="demo"> | ||
<p>This content will be hidden to start.</p> | ||
</div> | ||
<div class="expandable" id="demo"> | ||
<p>This content will be hidden to start.</p> | ||
</div> | ||
``` | ||
@@ -104,2 +104,46 @@ | ||
### Events | ||
#### ready | ||
Since the `ready` event may be trigger immediately, bind using the `onReady` option: | ||
```js | ||
const toggle = new ExpandToggle(el, { | ||
onReady: function() { | ||
console.log('ready'); | ||
} | ||
}); | ||
``` | ||
#### expand | ||
Triggered when component is expanded | ||
```js | ||
toggle.on('expand', function() { | ||
console.log('expand'); | ||
}); | ||
``` | ||
#### collapse | ||
Triggered when component is collapsed | ||
```js | ||
toggle.on('collapse', function() { | ||
console.log('collapse'); | ||
}); | ||
``` | ||
#### destroy | ||
Triggered when component is destroyed | ||
```js | ||
toggle.on('destroy', function() { | ||
console.log('destroy'); | ||
}); | ||
``` | ||
## License | ||
@@ -106,0 +150,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1862905
2372
155