forked from jc1arke/pietimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.pietimer.min.js
1 lines (1 loc) · 1.76 KB
/
jquery.pietimer.min.js
1
(function(a){"use strict";var b=360,c={seconds:10,color:"rgba(255, 255, 255, 0.8)",height:null,width:null},d=40,e="pie_timer",f="pie_timer",g=3*Math.PI/2,h=Math.PI/180,i=function(a,c,d){c.width===null&&(c.width=a.width()),c.height===null&&(c.height=a.height()),this.settings=c,this.jquery_object=a,this.interval_id=null,this.current_value=b,this.callback=d,this.is_paused=!0,this.jquery_object.html('<canvas class="'+e+'" width="'+c.width+'" height="'+c.height+'"></canvas>'),this.canvas=this.jquery_object.children("."+e)[0]};i.prototype={start:function(){this.is_paused&&(this.current_value<=0&&(this.current_value=b),this.interval_id=setInterval(a.proxy(this.run_timer,this),d),this.is_paused=!1)},pause:function(){this.is_paused||(clearInterval(this.interval_id),this.is_paused=!0)},run_timer:function(){if(this.canvas.getContext){this.current_value-=b/this.settings.seconds/24;if(this.current_value<=0)clearInterval(this.interval_id),this.canvas.width=this.settings.width,a.isFunction(this.callback)&&this.callback.call(),this.is_paused=!0;else{this.canvas.width=this.settings.width;var c=this.canvas.getContext("2d"),d=[this.canvas.width,this.canvas.height],e=Math.min(d[0],d[1])/2,f=[d[0]/2,d[1]/2];c.beginPath(),c.moveTo(f[0],f[1]);var i=g;c.arc(f[0],f[1],e,i-this.current_value*h,i,!1),c.closePath(),c.fillStyle=this.settings.color,c.fill()}}}};var j=function(b,d){var e=a.extend({},c,b);return this.each(function(){var b=a(this),c=new i(b,e,d);b.data(f,c)})},k=function(b){b in i.prototype||a.error("Method "+b+" does not exist on jQuery.pietimer");var c=Array.prototype.slice.call(arguments,1);return this.each(function(){var d=a(this),e=d.data(f);if(!e)return!0;e[b].apply(e,c)})};a.fn.pietimer=function(a){return typeof a=="object"||!a?j.apply(this,arguments):k.apply(this,arguments)}})(jQuery)