silvrgit/app/live/js/app.js

1 line
14 KiB
JavaScript
Raw Normal View History

2017-08-08 00:25:41 +00:00
"use strict";var BitcoinModel,Bitcoin,FxModel,FxView,_typeof,TrainModel,TrainView,WeatherModel,Weather,WeatherSlim,PasswordView,popitout,popitoutSmall,EventModel=Backbone.Model.extend({initialize:function(){this.update()},getDays:function(t,e){var i=void 0,a=void 0;return i=t.getTime(),a=e.getTime(),(a-i)/864e5},update:function(){var t,e=new Date,i=36e5-e.getTime()%36e5,a={};a.days=Math.ceil(this.getDays(e,this.get("event"))),a.weeks=Math.ceil(this.getDays(e,this.get("event"))/7),this.set("data",a),t=function(){this.update()},setTimeout(t.bind(this),i+10)}}),EventView=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.id="e_"+Math.random().toString(36).substr(2,9),this.$events=$("#events"),this.$myEvent=null,this.$el=this.$events,this.initView(),this.render()},render:function(){var t=this.model.get("label"),e=this.model.get("data"),i=t+" "+e.days+" days / "+e.weeks+" weeks";this.$myEvent.empty().append(i)},initView:function(){var t="<div class='mui-col-xs-12 mui-col-md-3' id=\""+this.id+'"></div>';this.$html=$(t),this.$events.append(this.$html),this.$myEvent=$("#"+this.id)}});BitcoinModel=Backbone.Model.extend({initialize:function(){this.set("url","/btc"),this.set("balanceUrl","/balance");var t={lastGBP:0,lastUSD:0,lows:{gbp:0,usd:0},highs:{gbp:0,usd:0},eclass:"",balance:0};this.set("btcdata",t),this.set("balance",0),this.update(),this.updateHourly()},update:function(){var t,e,i;this.getBTC(),t=new Date,e=3e5-t.getTime()%3e5,i=function(){this.update()},setTimeout(i.bind(this),e+10)},updateHourly:function(){var t,e,i;this.getBalance(),t=new Date,e=36e5-t.getTime()%36e5,i=function(){this.update()},setTimeout(i.bind(this),e+10)},recalc:function(){var t=this.get("btcdata"),e=t.lastGBP,i=void 0,a=t.gbp,n=t.usd,s=t.lows,o=t.highs,r=t.eclass,l=t.balance;void 0!==a&&(0!==t.lastGBP?r=a>e?"up":"down":(s.gbp=a,s.usd=n,o.gbp=a,o.usd=n),e=a,i=n,a<s.gbp&&(s.gbp=a),n<s.usd&&(s.usd=n),o.gbp<a&&(o.gbp=a),o.usd<n&&(o.usd=n),t={lastGBP:e,lastUSD:i,lows:s,highs:o,eclass:r,balance:l}),t.stub=Math.random(Number.MAX_SAFE_INTEGER).toString(32),this.set("btcdata",t)},getBTC:function(){var t=this,e=this.get("url");$.ajax({type:"GET",url:e,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){var i=e.bpi.GBP.rate_float,a=e.bpi.USD.rate_float,n=t.get("btcdata");n.gbp=i,n.usd=a,t.set("btcdata",n),t.recalc()},error:function(t,e){}})},getBalance:function(){var t=this,e=this.get("balanceUrl");$.ajax({type:"GET",url:e,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(e){var i=e.balance;t.set("balance",i),t.recalc()},error:function(t,e){}})}}),Bitcoin=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$btc=$("#btc")},render:function(){var t=this.model.get("btcdata"),e=this.model.get("balance"),i=parseFloat(t.lastGBP)*parseFloat(e),a="High: $"+parseFloat(t.highs.usd.toFixed(2))+" / Low $"+parseFloat(t.lows.usd.toFixed(2));this.$btc.removeClass(),this.$btc.addClass(t.eclass),this.$btc.html("&#36;"+parseFloat(t.lastUSD.toFixed(2))+" / &pound;"+parseFloat(t.lastGBP.toFixed(2))+" <div>&#8383;"+e+" &pound;"+parseFloat(i.toFixed(2))+"</div>"),this.$btc.prop("title",a)}}),FxModel=Backbone.Model.extend({initialize:function(){this.set("url","/fx"),this.set("fxdata",{}),this.update()},update:function(){var t,e,i;this.getFX(),t=new Date,e=9e5-t.getTime()%9e5,i=function(){this.update()},setTimeout(i.bind(this),e+10)},getFX:function(){var t=this.get("url"),e=this;$.ajax({type:"GET",url:t,data:"",dataType:"json",timeout:1e4,headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(t){var i=1/t.rates.