Project

General

Profile

1 2 Manuela
!function(t){"undefined"!=typeof module&&"object"==typeof exports?"undefined"!=typeof window?module.exports=t():module.exports=t:window.Collapse=t()}(function(){var t=function(t,e){e=e||{},this.isIE=null!=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})").exec(navigator.userAgent)?parseFloat(RegExp.$1):!1,this.btn="object"==typeof t?t:document.querySelector(t),this.accordion=null,this.collapse=null,this.duration=300,this.options={},this.options.duration=this.isIE&&this.isIE<10?0:e.duration||this.duration,this.init()};t.prototype={init:function(){this.actions(),this.addEvent()},actions:function(){var t=this,e=function(t){var e=t&&t.currentStyle||window.getComputedStyle(t),n=e.borderTopWidth||0,o=/px/.test(e.marginTop)?Math.round(e.marginTop.replace("px","")):0,s=/px/.test(e.marginBottom)?Math.round(e.marginBottom.replace("px","")):0,a=/em/.test(e.marginTop)?Math.round(e.marginTop.replace("em","")*parseInt(e.fontSize)):0,i=/em/.test(e.marginBottom)?Math.round(e.marginBottom.replace("em","")*parseInt(e.fontSize)):0;return t.clientHeight+parseInt(n)+parseInt(o)+parseInt(s)+parseInt(a)+parseInt(i)};this.toggle=function(e){t.btn=t.getTarget(e).btn,t.collapse=t.getTarget(e).collapse,/in/.test(t.collapse.className)?t.close(e):t.open(e)},this.close=function(e){e.preventDefault(),t.btn=t.getTarget(e).btn,t.collapse=t.getTarget(e).collapse,t._close(t.collapse),t.removeClass(t.btn,"collapsed")},this.open=function(e){if(e.preventDefault(),t.btn=t.getTarget(e).btn,t.collapse=t.getTarget(e).collapse,t.accordion=t.btn.getAttribute("data-parent")&&t.getClosest(t.btn,t.btn.getAttribute("data-parent")),t._open(t.collapse),t.addClass(t.btn,"collapsed"),null!==t.accordion){var n=t.accordion.querySelectorAll(".collapse.in"),o=n.length,s=0;for(s;o>s;s++)n[s]!==t.collapse&&t._close(n[s])}},this._open=function(e){t.removeEvent(),t.addClass(e,"in"),e.setAttribute("aria-expanded","true"),t.addClass(e,"collapsing"),setTimeout(function(){var n=t.getMaxHeight(e);e.style.height=n+"px",e.style.overflowY="hidden"},0),setTimeout(function(){e.style.height="",e.style.overflowY="",t.removeClass(e,"collapsing"),t.addEvent()},t.options.duration)},this._close=function(e){t.removeEvent(),e.setAttribute("aria-expanded","false"),e.style.height=t.getMaxHeight(e)+"px",setTimeout(function(){e.style.height="0px",e.style.overflowY="hidden",t.addClass(e,"collapsing")},0),setTimeout(function(){t.removeClass(e,"collapsing"),t.removeClass(e,"in"),e.style.overflowY="",e.style.height="",t.addEvent()},t.options.duration)},this.getMaxHeight=function(t){for(var n=0,o=0,s=t.children.length;s>o;o++)n+=e(t.children[o]);return n},this.removeEvent=function(){this.btn.removeEventListener("click",this.toggle,!1)},this.addEvent=function(){this.btn.addEventListener("click",this.toggle,!1)},this.getTarget=function(t){var e=t.currentTarget||t.srcElement,n=e.href&&e.getAttribute("href").replace("#",""),o=e.getAttribute("data-target")&&e.getAttribute("data-target"),s=n||o&&/#/.test(o)&&o.replace("#",""),a=o&&"."===o.charAt(0)&&o,i=s&&document.getElementById(s)||a&&document.querySelector(a);return{btn:e,collapse:i}},this.getClosest=function(t,e){for(var n=e.charAt(0);t&&t!==document;t=t.parentNode){if("."===n&&void 0!==document.querySelector(e))return t;if("#"===n&&t.id===e.substr(1))return t}return!1},this.addClass=function(t,e){t.classList?t.classList.add(e):t.className+=" "+e},this.removeClass=function(t,e){t.classList?t.classList.remove(e):t.className=t.className.replace(e,"").replace(/^\s+|\s+$/g,"")}}};var e=document.querySelectorAll('[data-toggle="collapse"]'),n=0,o=e.length;for(n;o>n;n++){var s=e[n],a={};a.duration=s.getAttribute("data-duration"),new t(s,a)}return t});