-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdual-temperature-meter.min.js
10 lines (10 loc) · 2.71 KB
/
dual-temperature-meter.min.js
1
2
3
4
5
6
7
8
9
10
/* -----------------------------------------------
/* Author : Saravanan Santhanakrishnan - saravanans.design@gmail.com
/* MIT license: http://opensource.org/licenses/MIT
/* Demo / Generator : -
/* GitHub : https://github.com/saravanansdesign/dual-temperature-meter.js
/* Dependencies : jQuery 3.5.1 & Above
/* How to use? : Check the GitHub README
/* v1.0.1
/* ----------------------------------------------- */
!function(t,e,i,n){t.fn._init=t.fn.init;var g={d:"",deg:"c",h:300,t:null,bg:"#f41e33",t_high_bg:"#f41e33",t_good_bg:"#2ecc71",t_low_bg:"#19b5fe",temp_max:-30,temp_min:-40},o={d:"",deg:"c",h:300,t:null,bg:"#f41e33",t_high_bg:"#f41e33",t_good_bg:"#2ecc71",t_low_bg:"#19b5fe",temp_max:-30,temp_min:-40};t.fn.init=function(e,i,n){return"string"==typeof e?new t.fn._init(e,i,n).data("selector",e):new t.fn._init(e,i,n)},t.fn.dualTemperatureMeter=function(e){var i,n,a;return this.initialize=function(){"f"===(o={d:e.target,deg:e.degree?e.degree:g.deg,h:e.height?e.height:g.h,t:e.temperature,bg:e.color?e.color:g.bg,t_high_bg:e.t_high_bg?e.t_high_bg:g.t_high_bg,t_good_bg:e.t_good_bg?e.t_good_bg:g.t_good_bg,t_low_bg:e.t_low_bg?e.t_low_bg:g.t_low_bg,temp_max:e.temp_max?e.temp_max:g.temp_max,temp_min:e.temp_min?e.temp_min:g.temp_min}).deg?(n=o.t,a=5*(o.t-32)/9,i=.6*(a+60)):(a=o.t,i=.6*(o.t+60),n=9*o.t/5+32),o.t>=o.temp_min&&o.t<=o.temp_max&&(o.bg=o.t_good_bg),o.t<o.temp_min&&(o.bg=o.t_low_bg),o.t>o.temp_max&&(o.bg=o.t_high_bg);var m='<style>.dual-temp-meter-animate { animation-duration: 4s;animation-name: dualTempAnimate;}</style><div style="height: '+o.h+'px;display: inline-block;vertical-align: top;"> <div style="height:100%;display: inline-block;vertical-align: top;position: relative;"> <div class="dual-temp-meter-animate" style="background:'+o.bg+';width: 14%; position: absolute; bottom: 16.6%; left: 44.2%; transform: rotate(180deg);"></div> <img src="./temperature-img.png" style="height: 100%;"> </div></div>',_=t.extend(g,e);return this.each(function(e,g){const l={fahrenheit:n||.6*(o.t+60),celsius:a||5*(o.t-32)/9};t("#"+o.d).html(m),t("#"+o.d+" .dual-temp-meter-animate").animate({height:i+"%"},2e3),"function"==typeof _.actions&&_.actions(l)})},this.initialize()},t.fn.dualTemperatureSet=function(e,i){var n,g;return this.initialize=function(){o.t=i,"temperature"===e&&("f"===o.deg?(o.t,g=5*(o.t-32)/9,n=.6*(g+60)):(g=o.t,n=.6*(o.t+60),9*o.t/5+32),o.t>=o.temp_min&&o.t<=o.temp_max&&(o.bg=o.t_good_bg,console.log("good")),o.t<o.temp_min&&(o.bg=o.t_low_bg,console.log("low")),o.t>o.temp_max&&(o.bg=o.t_high_bg,console.log("high")),console.log(n),console.log(o.bg),t("#"+o.d+" .dual-temp-meter-animate").animate({height:n+"%"},3500),t("#"+o.d+" .dual-temp-meter-animate").css({background:o.bg}))},this.initialize()}}(jQuery);