silvrgit/app/live/js/app.js

1 line
9.1 KiB
JavaScript
Raw Normal View History

2017-04-06 09:56:11 +00:00
"use strict";var FxModel,FxView,_typeof,TrainModel,TrainView,popitout,popitoutSmall,BitcoinModel=Backbone.Model.extend({initialize:function(){this.set("url","/btc");var t={lastGBP:0,lastUSD:0,lows:{gbp:0,usd:0},highs:{gbp:0,usd:0},eclass:""};this.set("btcdata",t),this.update()},update:function(){var t,e,i;this.getBTC(),t=new Date,e=6e4-t.getTime()%6e4,i=function(){this.update()},setTimeout(i.bind(this),e+10)},recalc:function(){var t=this.get("btcdata"),e=t.lastGBP,i=void 0,n=t.gbp,o=t.usd,s=t.lows,a=t.highs,r=t.eclass;0!==t.lastGBP?r=n>e?"up":"down":(s.gbp=n,s.usd=o,a.gbp=n,a.usd=o),e=n,i=o,n<s.gbp&&(s.gbp=n),o<s.usd&&(s.usd=o),a.gbp<n&&(a.gbp=n),a.usd<o&&(a.usd=o),t={lastGBP:e,lastUSD:i,lows:s,highs:a,eclass:r},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,n=e.bpi.USD.rate_float,o=t.get("btcdata");o.gbp=i,o.usd=n,t.set("btcdata",o),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="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))),this.$btc.prop("title",e)}});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.GBP,n=i*t.rates.SEK,o={usd:1,gbp:t.rates.GBP,sek:t.rates.SEK,gpbe:i,sekex:n};e.set("fxdata",o)},error:function(t,e){}})}}),FxView=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$fx=$("#fx")},render:function(){var t=this.model.get("fxdata");this.$fx.html("&pound;1 = &#36;"+parseFloat(t.gpbe.toFixed(2))+" = "+parseFloat(t.sekex.toFixed(2))+" SEK")}}),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},TrainModel=Backbone.Model.extend({initialize:function(){var t=this.get("from"),e=this.get("to"),i="/getnexttraintimes?from="+t+"&to="+e,n="/gettrains?from="+t+"&to="+e,o=t+e;this.set("url",i),this.set("routeUrl",n),this.set("target",o),this.set("visible",!1),this.update()},update:function(){var t,e,i;this.getTrain(),t=new Date,e=6e4-t.getTime()%6e4,i=function(){this.update()},setTimeout(i.bind(this),e+10)},getTrain: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){e.set("trainData",t)},error:function(t,e){}})},getRoute:function(){var t=this.get("routeUrl"),e=this;this.get("visible")===!0?this.set("visible",!1):$.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){e.set("route",t),e.set("visible",!0)},error:function(t,e){}})}}),TrainView=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",t