-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcircularprogress.jquery.min.js
2 lines (2 loc) · 3.54 KB
/
circularprogress.jquery.min.js
1
2
/* https://github.com/andysellick/circular-progress */
!function(t,s){var i=function(t,i){this.elem=t,this.$elem=s(t),this.options=i,this.init()};i.prototype={init:function(){this.settings=s.extend({rotateBy:1,initialPos:0,targetPos:0,scale:360,speed:5,includeInner:0,innerHTML:"",showProgress:0,progPreText:"",progPostText:"",delayAnimation:0,onFinishMoving:function(){}},this.defaults,this.options),this.rpanel,this.lpanel,this.overallpos=0,this.inner,this.innerhtml,this.innerprogress,this.timer,this.settings.rotateBy=Math.min(this.settings.rotateBy,360),this.settings.initialPos=Math.min(this.settings.initialPos,this.settings.scale),this.settings.targetPos=Math.min(this.settings.targetPos,this.settings.scale),this.settings.initialPos=this.calculateScale(this.settings.initialPos),this.settings.targetPos=this.calculateScale(this.settings.targetPos),this.rotateBy=this.settings.rotateBy;var t=s("<div/>").addClass("progressinner").appendTo(this.$elem),i=s("<div/>").addClass("lpane").appendTo(t),e=s("<div/>").addClass("rpane").appendTo(t);this.rpanel=s("<div/>").addClass("cover").appendTo(e),this.lpanel=s("<div/>").addClass("cover").appendTo(i),(this.settings.innerHTML.length||this.settings.showProgress||this.settings.includeInner)&&(this.inner=s("<div/>").addClass("display").appendTo(t)),this.settings.innerHTML.length&&(this.innerhtml=s("<div/>").addClass("extrahtml").html(this.settings.innerHTML).appendTo(this.inner)),this.settings.showProgress&&(this.innerprogress=s("<div/>").addClass("displayprogress").appendTo(this.inner));var n=this;this.settings.initialPos&&this.settings.initialPos!=this.settings.targetPos?(this.settings.initialPos>this.settings.targetPos&&(this.rotateBy=-this.rotateBy),this.setTargetPos(this.settings.initialPos),this.timer=setTimeout(function(){n.animateCircle(n.settings.initialPos,n.settings.targetPos)},this.settings.speed+this.settings.delayAnimation)):this.settings.initialPos!=this.settings.targetPos?this.timer=setTimeout(function(){n.animateCircle(n.settings.initialPos,n.settings.targetPos)},this.settings.speed+this.settings.delayAnimation):this.setTargetPos(this.settings.initialPos)},calculateScale:function(t){var s=360/this.settings.scale;return Math.ceil(t*s)},convertScale:function(t){var s=360/this.settings.scale;return Math.floor(t/s)},setTargetPos:function(t){this.overallpos=t,this.renderCircle()},animateCircle:function(t,s){var i=this.settings.rotateBy;t>s&&(i=-i);var e=t+i;e=s>t?Math.min(e,s):Math.max(e,s);var n=this;if(this.overallpos=e,e!=s)this.timer=setTimeout(function(){n.animateCircle(e,s)},this.settings.speed);else{var a=this.convertScale(this.overallpos);this.settings.onFinishMoving.call(this,a)}this.renderCircle()},renderCircle:function(){if(this.overallpos<180?(this.rotateElement(this.rpanel,this.overallpos),this.rotateElement(this.lpanel,0)):(this.rotateElement(this.rpanel,180),this.rotateElement(this.lpanel,this.overallpos-180)),this.settings.showProgress){var t=this.settings.progPreText+this.convertScale(this.overallpos)+this.settings.progPostText;this.innerprogress.html(t)}},rotateElement:function(t,s){t.css({transform:"rotate("+s+"deg)","-ms-transform":"rotate("+s+"deg)","-moz-tranform":"rotate("+s+"deg)","-webkit-transform":"rotate("+s+"deg)","-o-transform":"rotate("+s+"deg)"})},moveProgress:function(t){clearTimeout(this.timer),t=this.calculateScale(t),t=Math.max(Math.min(360,t),0),t!=this.overallpos&&this.animateCircle(this.overallpos,t)}},s.fn.circles=function(t){return void 0===t||"object"==typeof t?this.each(function(){s.data(this,"circles")||s.data(this,"circles",new i(this,t))}):void 0},t.Plugin=i}(window,jQuery);