-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggleTransition.min.js
More file actions
2 lines (2 loc) · 4.07 KB
/
toggleTransition.min.js
File metadata and controls
2 lines (2 loc) · 4.07 KB
1
2
/*! toggleTransition v0.9.0 - MIT license - Copyright 2007-2022 Denis Alemán */
!function(t,i){"function"==typeof define&&define.amd?define([],i):"object"==typeof module&&module.exports?module.exports=i():t.ToggleTransition=i()}("undefined"!=typeof global?global:this.window||this.global,function(){"use strict";function t(t,i){this.init(t,i)}function n(t,i,n=null){return"visibility"===this.settings.manageVisibilityWith?n?t.style.visibility="hidden":t.style.removeProperty("visibility"):"display"===this.settings.manageVisibilityWith&&(n?t.style.display="none":t.style.removeProperty("display")),"function"==typeof i?setTimeout(i.bind(this),0):this}function s(){var t=t||function(){var t,i=document.createElement("fakeelement"),n={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(t in n)if(void 0!==i.style[t])return n[t];throw"TransitionEnd event is not supported in this browser."}();return t}function e(t=function(){}){if(this.settings.hideTransitionClassname&&this.settings.hideTransitionClassname)return t.call(this);throw new Error("`hideTransitionClassname` and `showTransitionClassname` are not defined.")}function o(t,i){return"string"==typeof t?t=document.querySelectorAll(t):"function"==typeof t&&(t=t.call(this,this.$element)),"hide"===i||"show"===i||"toggle"===i?i=this[i].bind(this):"function"==typeof i&&(i=i.bind(this)),[t,i]}var a;return t.prototype=(a={manageVisibilityWith:"display"},{constructor:t,init:function(t,i){this.settings=function(t,i){var n,s={};for(n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=t[n]);for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(s[n]=i[n]);return s}(a,i),this.root=this.settings.root||document,this.$element=t,function(){this.isHidden=function(){return"boolean"==typeof this.settings.isHidden?this.settings.isHidden:e.call(this,function(){var t=this.$element.classList.contains(this.settings.hideTransitionClassname),i=this.$element.classList.contains(this.settings.showTransitionClassname);if(!t&&!i)throw new Error("Element must have one of the classes ['"+this.settings.hideTransitionClassname+"' or '"+this.settings.showTransitionClassname+"'].");if(t&&i)throw new Error("Element must have one class ['"+this.settings.hideTransitionClassname+"' or '"+this.settings.showTransitionClassname+"'], both given.");return!!t})}.call(this),n.call(this,this.$element,null,this.isHidden)}.call(this),this.$element.dispatchEvent(function(t,i){i=i||{bubbles:!0,cancelable:!0,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(t,i.bubbles,i.cancelable,i.detail),n}("toggle-transition-initialized"))},transition:function(t,i,n){return this.onTransitionEnd&&this.$element.removeEventListener(s(),this.onTransitionEnd),this.onTransitionEnd=function(){n(),this.onTransitionEnd=void 0}.bind(this),this.$element.classList.add(t),"function"==typeof n&&this.$element.addEventListener(s(),this.onTransitionEnd,{once:!0}),"function"==typeof i?i.call(this):this},show:function(t){return e.call(this,function(){this.$element.classList.remove(this.settings.hideTransitionClassname),n.call(this,this.$element,function(){this.transition(this.settings.showTransitionClassname,function(){this.isHidden=!1}.bind(this),function(){"function"==typeof this.settings.onHideTransitionEnd&&this.settings.onShowTransitionEnd.call(this,event)}.bind(this))}.bind(this),!1)}),"function"==typeof t?t.call(this):this},hide:function(t){return e.call(this,function(){this.$element.classList.remove(this.settings.showTransitionClassname),this.transition(this.settings.hideTransitionClassname,function(){this.isHidden=!0}.bind(this),function(t,i){n.call(this,this.$element,null,!0),"function"==typeof this.settings.onHideTransitionEnd&&this.settings.onHideTransitionEnd.call(this,t,i)}.bind(this))}),"function"==typeof t?t.call(this):this},toggle:function(t){var i=this.isHidden?this.show():this.hide();return"function"==typeof t?t.call(this)||i:this},on:function(t,i,n){n=o.call(this,i,n);return n[0].addEventListener(t,n[1]),this},off:function(t,i,n){n=o.call(this,i,n);return n[0].removeEventListener(t,n[1]),this}}),t});