jquery.zmd.hierarchical-display.min.js 3.2 KB

1
  1. (function(i){"use strict";function t(t){return this.each(function(){var a=i(this),e=a.data("zmd.hierarchicalDisplay"),o=i.extend({},n.DEFAULTS,a.data(),"object"==typeof t&&t);return e||a.data("zmd.hierarchicalDisplay",e=new n(this,o)),"string"==typeof t?e[t]():o.action in e?e[o.action]():void 0})}var n=function(t,a){this.$element=i(t),this.$children=this.$element.children(),this.options=i.extend({},n.DEFAULTS,a),this._time=n.TRANSITION_DURATION*this.options.speed,this.init(),!0===this.options.debug&&this._debug()};n.VERSION="1.0.1",n.TRANSITION_DURATION=300,n.DEFAULTS={action:"show",speed:5,animationIn:"zoomedIn",animationOut:"zoomedOut",debug:!1},n.prototype.init=function(){var t,n,a,e=this,o=this.$element,s=this.$children,h=this.options,l=this._time;o.addClass("zmd-hierarchical-display"),s.each(function(){t=i(this).position(),n=.8*t.left+t.top,a=parseFloat(n/l).toFixed(2),i(this).css("-webkit-animation-delay",a+"s").css("animation-delay",a+"s")}),this._delay=a,s.last().on("webkitAnimationEnd animationend",function(){i(this).hasClass(h.animationOut)&&e._complete("hidden"),i(this).hasClass(h.animationIn)&&e._complete("shown")})},n.prototype.show=function(){var t=this.$element,n=(this.$children,this.options);t.hasClass("in")||t.hasClass("zmd-hierarchical-displaying")||(this._removeAnimations(),t.trigger(i.Event("show.zmd.hierarchicalDisplay")),this._addAnimation(n.animationIn))},n.prototype.hide=function(){var t=this.$element,n=(this.$children,this.options);"hidden"===t.css("visibility")||t.hasClass("zmd-hierarchical-displaying")||(this._removeAnimations(),t.trigger(i.Event("hide.zmd.hierarchicalDisplay")),this._addAnimation(n.animationOut))},n.prototype.toggle=function(){return this.$element.hasClass("in")?this.hide():this.show()},n.prototype._removeAnimations=function(){var t=this.options;this.$children.each(function(){i(this).removeClass(t.animationIn).removeClass(t.animationOut)})},n.prototype._addAnimation=function(t){this.$element.addClass("zmd-hierarchical-displaying"),this.$children.each(function(){i(this).addClass(t).addClass("animation")})},n.prototype._complete=function(t){this.$element.removeClass("zmd-hierarchical-displaying").toggleClass("in").trigger(i.Event(t+".zmd.hierarchicalDisplay"))},n.prototype._debug=function(){i(document).on("show.zmd.hierarchicalDisplay",function(i){console.log('Event "show.zmd.hierarchicalDisplay". For more information see:'),console.log(i)}).on("shown.zmd.hierarchicalDisplay",function(i){console.log('Event "shown.zmd.hierarchicalDisplay". For more information see:'),console.log(i)}).on("hide.zmd.hierarchicalDisplay",function(i){console.log('Event "hide.zmd.hierarchicalDisplay". For more information see:'),console.log(i)}).on("hidden.zmd.hierarchicalDisplay",function(i){console.log('Event "hidden.zmd.hierarchicalDisplay". For more information see:'),console.log(i)})},i.fn.hierarchicalDisplay=t,i.fn.hierarchicalDisplay.Constructor=n,i(document).on("ready",function(){i('[data-animation="hierarchical-display"]').each(function(){t.call(i(this))})}),i(document).on("click",'[data-toggle="hierarchical-display"]',function(n){var a=i(this),e=i(a.attr("data-target")||a.attr("href"));a.is("a")&&n.preventDefault(),t.call(e,"toggle")})})(jQuery);