-
Notifications
You must be signed in to change notification settings - Fork 0
/
tigerDOM.min.js
8 lines (8 loc) · 4.88 KB
/
tigerDOM.min.js
1
2
3
4
5
6
7
8
/**
* TigerDOM Plugin
* TigerDOM is a multi-function jQuery plugin that allows you to do a multitude of things elegantly in the DOM.
* Author: Beau Beauchamp, WebTIGERS
* License: MIT
* Version 2.0.0
*/
!function(t){let e={init:function(){t(document).ready(function(){})},animateCount:function(e){let i={count:e.begin},n={count:e.end};t(i).animate(n,{duration:400,step:function(){e.callback(Math.round(this.count))},complete:function(){e.callback(e.end)}})},count:function(t){let e,i=0;for(e in t)t.hasOwnProperty(e)&&i++;return i},equalHeights:function(){let e=0;t(this).each(function(){let i=t(this).height();i>e&&(e=i)}),t(this).height(e)},initScrollTo:function(){t("[data-tiger-scrollto]").each(function(){let e=t(this),i=t(e.attr("data-tiger-scrollto"));e.on("click",function(){t("html, body").animate({scrollTop:i.offset().top},1e3)})})},initTigerControls:function(){t("[data-tiger-control]").each(function(){let e=t(this),i=e.find("i"),n=t(e.attr("data-tiger-control")),o=function(t,i){t.addClass(e.attr("data-tiger-class-close")),t.removeClass(e.attr("data-tiger-class-open")),i.tigerDOM("close")};n.is(":visible")||(n.css("overflow","hidden").css("height","0").css("opacity","0").css("display","").removeClass("hide"),o(i,n)),t(this).on("click",{target:n},function(t){t.preventDefault(),n.is(":visible")?o(i,n):function(t,i){t.addClass(e.attr("data-tiger-class-open")),t.removeClass(e.attr("data-tiger-class-close")),i.tigerDOM("open")}(i,n)})})},show:function(e){return this.each(function(){t(this).css("opacity",0).removeClass("hide").animate({opacity:1},400,e(this))})},hide:function(e){return this.each(function(){t(this).animate({opacity:0},400,e(this))})},open:function(e){return this.each(function(){let e=t(this);e.removeClass("hide");let i=parseInt(e.prop("scrollHeight"),10);e.css("opacity",0).css("height",0).css("overflow","hidden"),e.animate({height:i},400,function(){e.animate({opacity:1},400,function(){e.css("height","").css("overflow","").css("opacity","")})})})},close:function(e){return e="function"==typeof e?e:null,this.each(function(){let e=t(this);return e.css("overflow","hidden").animate({opacity:0},400,function(){e.animate({height:0},400,function(){e.addClass("hide"),e.css("opacity","").css("height","").css("display","")})})})},insert:function(e){let i="function"==typeof e.callback?e.callback:function(){return!1};return this.each(function(){let n=t(this);n.css("position","relative").css("overflow","auto");let o=n.prop("scrollHeight");n.css("height",o);let s=t(e.content).css("opacity",0).appendTo(n);n.css("height","auto");let c=n.innerHeight();n.css("overflow","hidden").css("height",o),c=""!==e.content?c:0,n.animate({height:c},400,function(){s.animate({opacity:1},400,i(n[0]))}),e.removeClick&&!0===e.removeClick&&s.addClass("pointer").on("click",function(){(n=t(this)).tigerDOM("remove")}),e.removeTimeout&&e.removeTimeout>0&&setTimeout(function(){s.tigerDOM("remove")},e.removeTimeout)})},remove:function(e){return e="function"==typeof e?e:null,this.each(function(){let i=t(this),n=i.outerHeight(!0),o=i.parent();o.css("position","relative").css("overflow","auto");let s=o.innerHeight(),c=parseInt(s-n,10),a=o.children().length>0?c:1,r=parseInt(o.css("min-height"),10);return a=r>0?r:a,o.css("height",s),i.animate({opacity:0},400,function(){let t=i[0].currentStyle||window.getComputedStyle(i[0]),n=parseInt(t.height,10)+parseInt(t.marginTop,10)+parseInt(t.marginBottom,10);i.css("margin-top",0).css("margin-bottom",0).css("height",n).css("overflow","hidden").css("padding-top",0).css("padding-bottom",0),i.animate({height:0},400,function(){return 0===a&&o.css("margin-bottom","1px"),i.remove(),o.animate({height:a},400,e)})})})},change:function(e){return this.each(function(){let i=t(this);i.css("position","relative").css("overflow","auto"),i.children().length>0?(i.css("height",i.innerHeight()),i.queue("change",function(e){i.children().each(function(){t(this).fadeOut(400,function(){e()})})}),i.queue("change",function(e){i.children().each(function(){t(this).remove()}),e()}),i.queue("change",function(t){i.tigerDOM("insert",e),t()}),i.dequeue("change")):i.tigerDOM("insert",e)})},switch:function(e){"function"==typeof e.callback&&e.callback;return this.each(function(){let i=t(this),n=t(e.out),o=t(e.in);i.css("height",i.innerHeight()).css("overflow","hidden"),i.queue("switch",function(t){o.css("opacity",0),n.fadeOut(200,function(){n.addClass("hide"),t()})}),i.queue("switch",function(){o.removeClass("hide");let t=parseInt(o.css("min-height"),10),e=o.outerHeight()+parseInt(o.css("margin-top"),10)+parseInt(o.css("margin-bottom"),10);e=t>0&&t>e?t:e,i.animate({height:e},200,function(){o.css("display","").animate({opacity:1},200,function(){i.css("height","").css("overflow","")})})}),i.dequeue("switch")})}};t.fn.tigerDOM=function(i){return e[i]?e[i].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof i&&i?void t.error("Method "+i+" does not exist on jQuery.tigerDOM"):e.init.apply(this,arguments)},t().tigerDOM()}(jQuery);