-
Notifications
You must be signed in to change notification settings - Fork 4
/
jquery.auto-text-rotating.min.js
8 lines (8 loc) · 8.46 KB
/
jquery.auto-text-rotating.min.js
1
2
3
4
5
6
7
8
/*!
* jQuery plugin to change/rotation of text or html, single or group, automatically with a separator.
* https://github.com/Arttse/jquery.auto-text-rotating
* Copyright (c) 2015-2016 Nikita «Arttse» Bystrov
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
* Version: 1.3.2
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports={}:a(jQuery)}(function(a){var b={init:function(b){function c(a,b){return b?"html"===e.type?a.html(b):a.text(b):"html"===e.type?a.html():a.text()}var d,e=a.extend({type:"text",method:"single",animation:"fade",animationSpeed:300,animationEasing:"swing",animationType:"full",animationScale:[1,0],animationRotateDeg:720,animateCssClass:"animated",animateCssAnimation:["bounceIn","bounceOut"],delay:2e3,delayStart:2e3,delayGroup:2e3,animateOne:!1,separator:"|",reverse:!1,trim:!0,css:void 0},b),f="webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",g=e.delay,h="object"==typeof e.animationSpeed?e.animationSpeed:[e.animationSpeed,e.animationSpeed],i="object"==typeof e.animationEasing?e.animationEasing:[e.animationEasing,e.animationEasing],j="object"==typeof e.animationRotateDeg?e.animationRotateDeg:[0,e.animationRotateDeg],k="object"==typeof e.animateCssAnimation?e.animateCssAnimation:[e.animateCssAnimation,e.animateCssAnimation];if("group"===e.method){var l=[];this.each(function(){l.push(this)}),g=e.delay*l.length+e.delayGroup}var m=function(b){function l(a){return e.reverse?a-1===-1?o.length-1:a-1:a+1===o.length?0:a+1}var m=a(this),n=m.css("display"),o=[],p={no:function(){c(m,o[d])},fade:function(){"full"===e.animationType?m.fadeOut(h[1],i[1],function(){c(m,o[d]).fadeIn(h[0],i[0])}):"in"===e.animationType?(m.css("display","none"),c(m,o[d]),m.fadeIn(h[0],i[0])):"out"===e.animationType&&m.fadeOut(h[1],i[1],function(){c(m,o[d]),m.css("display",n)})},scale:function(){function b(b){a(b.elem).css({"-webkit-transform":"scale("+b.now+")","-ms-transform":"scale("+b.now+")",transform:"scale("+b.now+")"})}a.fx.step.transformScaleIn=function(a){a.start=e.animationScale[1],b(a)},a.fx.step.transformScaleOut=function(a){a.start=e.animationScale[0],0!==a.pos&&b(a)},"full"===e.animationType?m.animate({transformScaleOut:e.animationScale[1]},h[1],i[1],function(){c(m,o[d]).animate({transformScaleIn:e.animationScale[0]},h[0],i[0])}):"in"===e.animationType?(m.css({"-webkit-transform":"scale("+e.animationScale[1]+")","-ms-transform":"scale("+e.animationScale[1]+")",transform:"scale("+e.animationScale[1]+")"}),c(m,o[d]).animate({transformScaleIn:e.animationScale[0]},h[0],i[0])):"out"===e.animationType&&m.animate({transformScaleOut:e.animationScale[1]},h[1],i[1],function(){c(m,o[d]).css({"-webkit-transform":"scale("+e.animationScale[0]+")","-ms-transform":"scale("+e.animationScale[0]+")",transform:"scale("+e.animationScale[0]+")"})})},spin:function(){function b(b,c){a(b.elem).css({"-webkit-transform":"translateZ(0) rotate("+c+"deg) scale("+b.now+")","-ms-transform":"translate(0, 0) rotate("+c+"deg) scale("+b.now+")",transform:"translateZ(0) rotate("+c+"deg) scale("+b.now+")"})}var f=null;a.fx.step.transformSpinIn=function(a){a.start=e.animationScale[1],f=j[1]/100*(100/e.animationScale[0]*a.now),b(a,f)},a.fx.step.transformSpinOut=function(a){a.start=e.animationScale[0],f=j[1]/100*(100/e.animationScale[0]*a.now),0!==a.pos&&b(a,f)},"full"===e.animationType?m.css({"-webkit-transform":"rotate(0deg) scale("+e.animationScale[0]+")","-ms-transform":"rotate(0deg) scale("+e.animationScale[0]+")",transform:"rotate(0deg) scale("+e.animationScale[0]+")"}).animate({transformSpinOut:e.animationScale[1]},h[1],i[1],function(){c(m,o[d]).animate({transformSpinIn:e.animationScale[0]},h[0],i[0])}):"in"===e.animationType?(m.css({"-webkit-transform":"rotate("+j[1]+"deg) scale("+e.animationScale[1]+")","-ms-transform":"rotate("+j[1]+"deg) scale("+e.animationScale[1]+")",transform:"rotate("+j[1]+"deg) scale("+e.animationScale[1]+")"}),c(m,o[d]).animate({transformSpinIn:e.animationScale[0]},h[0],i[0])):"out"===e.animationType&&m.animate({transformSpinOut:e.animationScale[1]},h[1],i[1],function(){c(m,o[d]).css({"-webkit-transform":"rotate(0deg) scale("+e.animationScale[0]+")","-ms-transform":"rotate(0deg) scale("+e.animationScale[0]+")",transform:"rotate(0deg) scale("+e.animationScale[0]+")"})})},flipY:function(){function b(b){a(b.elem).css({"-webkit-transform":"rotateY("+b.now+"deg)",transform:"rotateY("+b.now+"deg)"})}a.fx.step.transformFlipYIn=function(a){a.start=j[1],b(a)},a.fx.step.transformFlipYOut=function(a){a.start=j[0],0!==a.pos&&b(a)},"full"===e.animationType?m.animate({transformFlipYOut:j[1]},h[1],i[1],function(){c(m,o[d]).animate({transformFlipYIn:j[0]},h[0],i[0])}):"in"===e.animationType?(m.css({"-webkit-transform":"rotateY("+j[0]+"deg)",transform:"rotateY("+j[0]+"deg)"}),c(m,o[d]).animate({transformFlipYIn:j[0]},h[0],i[0])):"out"===e.animationType&&m.animate({transformFlipYOut:j[1]},h[1],i[1],function(){c(m,o[d]).css({"-webkit-transform":"rotateY("+j[0]+"deg)",transform:"rotateY("+j[0]+"deg)"})})},flipX:function(){function b(b){a(b.elem).css({"-webkit-transform":"rotateX("+b.now+"deg)",transform:"rotateX("+b.now+"deg)"})}a.fx.step.transformFlipXIn=function(a){a.start=j[1],b(a)},a.fx.step.transformFlipXOut=function(a){a.start=j[0],0!==a.pos&&b(a)},"full"===e.animationType?m.animate({transformFlipXOut:j[1]},h[1],i[1],function(){c(m,o[d]).animate({transformFlipXIn:j[0]},h[0],i[0])}):"in"===e.animationType?(m.css({"-webkit-transform":"rotateX("+j[0]+"deg)",transform:"rotateX("+j[0]+"deg)"}),c(m,o[d]).animate({transformFlipXIn:j[0]},h[0],i[0])):"out"===e.animationType&&m.animate({transformFlipXOut:j[1]},h[1],i[1],function(){c(m,o[d]).css({"-webkit-transform":"rotateX("+j[0]+"deg)",transform:"rotateX("+j[0]+"deg)"})})},animateCss:function(){function a(a,b){a.css({"-webkit-animation-duration":b+"ms","-moz-animation-duration":b+"ms","-o-animation-duration":b+"ms","animation-duration":b+"ms"})}function b(){a(m,e.animationSpeed[0]),c(m,o[d]).addClass(k[0]).one(f,function(){m.removeClass(k[0])})}"full"===e.animationType?k[0]===k[1]?b():(a(m,e.animationSpeed[1]),m.addClass(k[1]).one(f,function(){a(m,e.animationSpeed[0]),c(m,o[d]).removeClass(k[1]).addClass(k[0]).one(f,function(){m.removeClass(k[0])})})):"in"===e.animationType?b():"out"===e.animationType&&(a(m,e.animationSpeed[1]),m.addClass(k[1]).one(f,function(){c(m,o[d]).removeClass(k[1])}))}};if(m.data().atrContentOriginal?m.html(m.data().atrContentOriginal):m.data("atrContentOriginal",m.html()),"animateCss"===e.animation&&(m.addClass(e.animateCssClass),m.data("atrAnimateCssClass",e.animateCssClass)),m.data({atrInit:!0,atrSeparator:e.separator,atrTrim:e.trim}),e.css&&"object"==typeof e.css&&m.css(e.css),a.each(c(m).split(e.separator),function(b,c){e.trim?o.push(a.trim(c)):o.push(c)}),d=e.reverse?o.length-1:0,c(m,o[d]),m.data("atrIndexParts",d),e.animateOne||o.length>1){var q=function(){var f=function(){d=l(a.inArray(c(m),o)),m.data("atrIndexParts",d),p.hasOwnProperty(e.animation)?p[e.animation].call():p.fade()};if("single"===e.method)f();else if("group"===e.method){var g=setTimeout(f,e.delay*b);m.data("atrTimeoutGroup",g)}},r=setTimeout(function(){m.removeData("atrTimeoutStart"),q();var a=setInterval(q,g);m.data("atrIntervalMain",a)},e.delayStart);m.data("atrTimeoutStart",r)}};return this.each(m)},stop:function(b){function c(b,c){var e=c.split(d.separator);switch(d.content){case"original":b.html(c);break;case"firstPart":b.html(d.trim?a.trim(e[0]):e[0]);break;case"lastPart":b.html(d.trim?a.trim(e[e.length-1]):e[e.length-1]);break;case"currentPart":b.html(d.trim?a.trim(e[b.data().atrIndexParts]):e[b.data().atrIndexParts])}}var d=a.extend({content:"currentPart",separator:a(this).data().atrSeparator,trim:a(this).data().atrTrim},b),e=function(){var b=a(this),d=b.data();d.atrInit&&(d.atrAnimateCssClass&&(b.removeClass(d.atrAnimateCssClass),b.removeData("atrAnimateCssClass")),d.atrTimeoutStart&&(clearTimeout(d.atrTimeoutStart),b.removeData("atrTimeoutStart")),d.atrTimeoutGroup&&(clearTimeout(d.atrTimeoutGroup),b.removeData("atrTimeoutGroup")),d.atrIntervalMain&&(clearInterval(d.atrIntervalMain),b.removeData("atrIntervalMain")),d.atrContentOriginal&&(b.stop().removeAttr("style").removeData("atrInit"),c(b,d.atrContentOriginal)))};return this.each(e)},reinit:function(c){var d=a(this);return b.stop.apply(d),b.init.call(d,c),this.each(a.noop)}};a.fn.atrotating=function(c){return b[c]?b[c].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof c&&c?void a.error('A method named "'+c+'" does not exist for jQuery.atrotating'):b.init.apply(this,arguments)}});