1 line
9.2 KiB
JavaScript
1 line
9.2 KiB
JavaScript
"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("$"+parseFloat(t.lastUSD.toFixed(2))+" / £"+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("£1 = $"+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",this.render),this.$trains=$("#trains"),this.$traininfo=$("#traininfo"),this.$traintext=$("#trainResults"),this.$el=this.$trains,this.initView()},events:{click:"showTrains"},render:function(){var t,e,i,n,o,s,a,r,l,d,c,u,h,f,m,p,b,g,T,w,v,y,$,x=void 0,C=void 0,A=this.model.get("trainData"),S=this.model.get("visible"),E=this.model.get("route");if(x="on time"===A.eta.toLowerCase()?A.sta:A.eta,C="on time"===A.eta.toLowerCase()?"ontime":"delayed",this.$button.html(x),this.$button.removeClass("delayed").removeClass("ontime").addClass(C),S){if(t="<div>"+E.locationName+" TO "+E.filterLocationName+'</div>\n <table class="mui-table mui-table-bordered">\n <tr><th>Destination</th>\n <th>Time</th>\n <th>Status</th>\n <th>Platform</th></tr>\n ',"object"===_typeof(E.trainServices)&&null!==E.trainServices){e=!0,i=!1,n=void 0;try{for(o=E.trainServices[Symbol.iterator]();!(e=(s=o.next()).done);e=!0)a=s.value,r=a.destination[0],l=null!==r.via?"<em>"+r.via+"</em>":"",d=null!==a.platform?a.platform:"💠",c=null!==a.sta?a.sta:"D "+a.std,u=null!==a.eta?a.eta:a.etd,t=a.isCancelled?t+"<tr>\n <td>"+r.locationName+" "+l+"</td>\n <td>"+c+'</td>\n <td colspan="2">❌ '+a.cancelReason+"</td>\n \n </tr>":t+"<tr>\n <td>"+r.locationName+" "+l+"</td>\n <td>"+c+"</td>\n <td>"+u+"</td>\n <td>"+d+"</td>\n </tr>"}catch(t){i=!0,n=t}finally{try{!e&&o.return&&o.return()}finally{if(i)throw n}}}if("object"===_typeof(E.busServices)&&null!==E.busServices){h=!0,f=!1,m=void 0;try{for(p=E.busServices[Symbol.iterator]();!(h=(b=p.next()).done);h=!0)g=b.value,T=g.destination[0],w=null!==T.via?"<em>"+T.via+"</em>":"",v=null!==g.platform?g.platform:"",y=null!==g.sta?g.sta:"D "+g.std,$=null!==g.eta?g.eta:g.etd,t=t+"<tr>\n <td>🚌 "+T.locationName+" "+w+"</td>\n <td>"+y+"</td>\n <td>"+$+"</td>\n <td>"+v+"</td>\n </tr>"}catch(t){f=!0,m=t}finally{try{!h&&p.return&&p.return()}finally{if(f)throw m}}}t+="</table>",this.$traintext.empty().html(t),this.$traintext.removeClass("mui--hide").addClass("mui--show")}else this.$traintext.removeClass("mui--show").addClass("mui--hide")},initView:function(){var t,e=this,i=this.model.get("target"),n="<div class='mui-col-xs-12 mui-col-md-6'>"+i.toUpperCase()+': <button class="mui-btn mui-btn--flat" id="'+i+'"></button></div>';this.$html=$(n),this.$html.on("click",function(){e.model.getRoute()}),this.$trains.append(this.$html),this.$button=$("#"+i),t="click #$(target)",this.events[t]="showTrains"},showTrains:function(){}}),function(){var t,e,i,n=this,o=function(t,e){return new Date(t.getTime()+24*e*60*60*1e3)},s=function(t,e){var i=void 0,n=void 0;return i=t.getTime(),n=e.getTime(),(n-i)/864e5},a=function(){var t=new Date,e=new Date,i=new Date,n=new Date;e.setFullYear(2013,9,24),o(e,1001),i.setFullYear(2017,6,5),n.setFullYear(2013,7,25),$("#one").hide(),$("#two").text("Ends: "+Math.ceil(s(t,i))+" days / "+Math.ceil(s(t,i)/7)+" weeks"),$("#three").hide()},r=function(){navigator.geolocation.getCurrentPosition(t)};this.bind("displayWeather",function(t){$("#weather").html(t.currently.summary+" "+t.currently.temperature+"°c <em>"+t.daily.summary+"</em>")}),t=function(t){var e=t.coords.latitude,i=t.coords.longitude;$.ajax({type:"GET",url:"https://api.forecast.io/forecast/9ad2a41d420f3cf4960571bb886f710c/"+e.toString()+","+i.toString()+"?units=uk2",data:"",dataType:"jsonp",timeout:1e4,context:$("body"),contentType:"application/json",headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"PUT, GET, POST, DELETE, OPTIONS","Access-Control-Allow-Headers":"Content-Type"},success:function(t){n.trigger("displayWeather",t)},error:function(t,e){}})},e=function(t){var e=$("#passwordOut"),i=new EJS({url:"/template/password.ejs"}).render(t);e.empty(),e.append(i),e.show()},i=function(t,i){$.ajax({type:"GET",url:"/generate",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(t)},error:function(t,e){}})},a(),r(),_fastTimer=setInterval(function(){},6e4),setInterval(function(){r()},9e5),$("#newPassword").on("click",function(){i()}),document.title="Slack"}(),popitout=function(t){var e=window.open(t,"name","height=600,width=570");return window.focus&&e.focus(),!1},popitoutSmall=function(t){var e=window.open(t,"name","height=400,width=520");return window.focus&&e.focus(),!1}; |