-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.bartimer.min.js
1 lines (1 loc) · 2.27 KB
/
jquery.bartimer.min.js
1
function colorIntensity(t,r){var i=!1;"#"==t[0]&&(t=t.slice(1),i=!0);var e=parseInt(t,16),a=(e>>16)+r;a>255?a=255:0>a&&(a=0);var o=(255&e)+r;o>255?o=255:0>o&&(o=0);var s=(e>>8&255)+r;return s>255?s=255:0>s&&(s=0),(i?"#":"")+(o|s<<8|a<<16).toString(16)}!function(t){var r={init:function(r){var i={timer:null,refreshRateMs:10,timerSeconds:10,color:"#ff0000",bgColor:"#900000",opacityPercent:75,height:10,orientation:"top",shadow:!1,callback:function(){}};return i=t.extend(i,r),this.each(function(){var r=t(this),e=r.data("bartimer");if(!e){if("bottom"!=i.orientation&&"top"!=i.orientation&&(i.orientation="top"),"bottom"==i.orientation?(r.css("position","absolute"),r.css("bottom","0"),r.parent()&&r.parent().css("position","relative")):r.css("position","relative"),i.shadow){var a="bottom"==i.orientation?"-":"",o="0px "+a+"0px 20px 6px "+colorIntensity(i.bgColor,50);r.css("box-shadow",o),r.css("-moz-box-shadow",o),r.css("-webkit-box-shadow",o)}r.css("width","100%"),r.css("background-color",i.bgColor),r.css("opacity",i.opacityPercent/100),r.css("height",i.height+"px"),r.html('<div id="barTimerProgress"></div>'),t("#barTimerProgress").css("position","absolute"),t("#barTimerProgress").css("width","1%"),t("#barTimerProgress").css("height","100%"),t("#barTimerProgress").css("background-color",i.color),t("#barTimerProgress").css("opacity",i.opacityPercent/100),r.data("bartimer",i),r.bartimer("start")}})},stopWatch:function(){var r=t(this).data("bartimer");if(r){var i=(r.timerFinish-(new Date).getTime())/1e3;if(0<i){var e=100-i/r.timerSeconds*100;t(this).bartimer("drawTimer",e)}else clearInterval(r.timer),t(this).bartimer("drawTimer",100),r.callback()}},drawTimer:function(r){$this=t(this);var i=$this.data("bartimer");i&&t("#barTimerProgress").css("width",Math.ceil(r)+"%")},start:function(){var r=t(this).data("bartimer");r&&(r.timerFinish=(new Date).getTime()+1e3*r.timerSeconds,t(this).bartimer("drawTimer",0),r.timer=setInterval("$this.bartimer('stopWatch')",r.refreshRateMs))},reset:function(){var r=t(this).data("bartimer");r&&(clearInterval(r.timer),t(this).bartimer("drawTimer",0))}};t.fn.bartimer=function(i){return r[i]?r[i].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof i&&i?void t.error("Method "+i+" does not exist on jQuery.bartimer"):r.init.apply(this,arguments)}}(jQuery);