-(function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.accordion=c.exports}})(this,function(a){"use strict";function b(a){for(var b=1;b<arguments.length;b++){var d=null==arguments[b]?{}:arguments[b],e=Object.keys(d);"function"==typeof Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(d).filter(function(a){return Object.getOwnPropertyDescriptor(d,a).enumerable}))),e.forEach(function(b){c(a,b,d[b])})}return a}function c(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function f(a,b,c){return b&&e(a.prototype,b),c&&e(a,c),a}Object.defineProperty(a,"__esModule",{value:!0}),a.default=void 0;var g=function(){function a(c){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return d(this,a),this.settings=b({headSelector:"[data-title]",bodySelector:"[data-content]",hiddenClass:"is--hidden",activeClass:"is--active"},e),this.el=c,this.head=this.el.querySelector(this.settings.headSelector),this.body=this.el.querySelector(this.settings.bodySelector),this.isOpen=!1,this.height=0,this.bind().close(),this}return f(a,[{key:"bind",value:function b(){var a=this;return this.head.addEventListener("click",this.toggle.bind(this)),this.body.addEventListener("transitionend",function(){a.isOpen||a.el.classList.add(a.settings.hiddenClass)}),this}},{key:"setHeight",value:function c(a){var b=this;return setTimeout(function(){b.body.style.maxHeight="".concat(a,"px")},1),this}},{key:"toggle",value:function a(){return this.height=this.body.scrollHeight,this.isOpen?this.close():this.open(),this}},{key:"close",value:function a(){return this.isOpen=!1,this.el.classList.remove(this.settings.activeClass),this.body.style.maxHeight="".concat(this.height,"px"),this.setHeight(0),this}},{key:"open",value:function a(){return this.isOpen=!0,this.el.classList.add(this.settings.activeClass),this.el.classList.remove(this.settings.hiddenClass),this.body.style.maxHeight="".concat(0,"px"),this.setHeight(this.height),this}}]),a}();a.default=g});
0 commit comments