silvrgit/app/live/js/app.js
2017-04-20 13:42:55 +01:00

1 line
13 KiB
JavaScript

"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,n=void 0;return i=t.getTime(),n=e.getTime(),(n-i)/864e5},update:function(){var t,e=new Date,i=36e5-e.getTime()%36e5,n={};n.days=Math.ceil(this.getDays(e,this.get("event"))),n.weeks=Math.ceil(this.getDays(e,this.get("event"))/7),this.set("data",n),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-3 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");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,a=t.usd,s=t.lows,o=t.highs,r=t.eclass;0!==t.lastGBP?r=n>e?"up":"down":(s.gbp=n,s.usd=a,o.gbp=n,o.usd=a),e=n,i=a,n<s.gbp&&(s.gbp=n),a<s.usd&&(s.usd=a),o.gbp<n&&(o.gbp=n),o.usd<a&&(o.usd=a),t={lastGBP:e,lastUSD:i,lows:s,highs:o,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,a=t.get("btcdata");a.gbp=i,a.usd=n,t.set("btcdata",a),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,a={usd:1,gbp:t.rates.GBP,sek:t.rates.SEK,gpbe:i,sekex:n};e.set("fxdata",a)},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,a=t+e;this.set("url",i),this.set("routeUrl",n),this.set("target",a),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,a,s,o,r,l,d,h,u,c,m,p,g,f,b,v,w,y,T,$,C=void 0,A=void 0,x=this.model.get("trainData"),S=this.model.get("visible"),k=this.model.get("route");if(C="on time"===x.eta.toLowerCase()?x.sta:x.eta,A="on time"===x.eta.toLowerCase()?"ontime":"delayed",this.$button.html(C),this.$button.removeClass("delayed").removeClass("ontime").addClass(A),S){if(t="<div>"+k.locationName+" TO "+k.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(k.trainServices)&&null!==k.trainServices){e=!0,i=!1,n=void 0;try{for(a=k.trainServices[Symbol.iterator]();!(e=(s=a.next()).done);e=!0)o=s.value,r=o.destination[0],l=null!==r.via?"<em>"+r.via+"</em>":"",d=null!==o.platform?o.platform:"💠",h=null!==o.sta?o.sta:"D "+o.std,u=null!==o.eta?o.eta:o.etd,t=o.isCancelled?t+"<tr>\n <td>"+r.locationName+" "+l+"</td>\n <td>"+h+'</td>\n <td colspan="2">❌ '+o.cancelReason+"</td>\n \n </tr>":t+"<tr>\n <td>"+r.locationName+" "+l+"</td>\n <td>"+h+"</td>\n <td>"+u+"</td>\n <td>"+d+"</td>\n </tr>"}catch(t){i=!0,n=t}finally{try{!e&&a.return&&a.return()}finally{if(i)throw n}}}if("object"===_typeof(k.busServices)&&null!==k.busServices){c=!0,m=!1,p=void 0;try{for(g=k.busServices[Symbol.iterator]();!(c=(f=g.next()).done);c=!0)b=f.value,v=b.destination[0],w=null!==v.via?"<em>"+v.via+"</em>":"",y=null!==b.platform?b.platform:"",T=null!==b.sta?b.sta:"D "+b.std,$=null!==b.eta?b.eta:b.etd,t=t+"<tr>\n <td>🚌 "+v.locationName+" "+w+"</td>\n <td>"+T+"</td>\n <td>"+$+"</td>\n <td>"+y+"</td>\n </tr>"}catch(t){m=!0,p=t}finally{try{!c&&g.return&&g.return()}finally{if(m)throw p}}}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(){}}),WeatherModel=Backbone.Model.extend({initialize:function(){var t=this.get("geo");this.set("url","https://api.darksky.net/forecast/9ad2a41d420f3cf4960571bb886f710c/"+t.coords.latitude.toString()+","+t.coords.longitude.toString()+"?units=uk2&exclude=minutely,hourly,alerts,flags"),this.update()},update:function(){var t,e,i;this.getWeather(),t=new Date,e=18e5-t.getTime()%18e5,i=function(){this.update()},setTimeout(i.bind(this),e+10)},getWeather:function(){var t=this;$.ajax({type:"GET",url:t.get("url"),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(e){var i={temperature:e.currently.temperature,icon:e.currently.icon,summary:e.currently.summary,daily:e.daily.summary};t.set(i)},error:function(t,e){}})}}),Weather=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$weatherText=$("#weatherDescription"),this.$weatherTemp=$("#temp"),this.$weatherIcon=$("#weatherIcon")},render:function(){var t='<i class="wi wi-forecast-io-'+this.model.get("icon")+'"></i>';this.$weatherTemp.empty().html(parseInt(this.model.get("temperature"))+"&deg;c&nbsp;"),this.$weatherText.empty().html(this.model.get("summary")),this.$weatherIcon.empty().html(t)}}),WeatherSlim=Backbone.View.extend({tagName:"div",initialize:function(){_.bindAll(this,"render"),this.model.bind("change",this.render),this.$weather=$("#weather"),this.render()},render:function(){var t=this.model.get("summary"),e=this.model.get("temperature"),i=this.model.get("daily"),n=t+" "+e+"&deg;&nbsp;<em>"+i+"</em>";this.$weather.empty().html(n)}}),Array.prototype.random=function(){return this[Math.floor(Math.random()*this.length)]},PasswordView=Backbone.View.extend({el:$("#passwords"),initialize:function(){this.alpha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0","1","2","3","4","5","6","7","8","9"],this.whitespace=[".","~","#","!","$","+","-","+"],this.numbers=["0","1","2","3","4","5","6","7","8","9"],this.left=["Alabama","Alaska","Arizona","Maryland","Nevada","Mexico","Texas","Utah","Glasgow","Inverness","Edinburgh","Dumbarton","Balloch","Renton","Cardross","Dundee","Paisley","Hamilton","Greenock","Falkirk","Irvine","Renfrew","Erskine","London","Hammersmith","Islington","Silver","Black","Yellow","Purple","White","Pink","Red","Orange","Brown","Green","Blue","Amber","Aqua","Azure","Bronze","Coral","Copper","Crimson","Cyan","Ginger","Gold","Indigo","Jade"],this.right=["Aganju","Cygni","Akeron","Antares","Aragoth","Ardus","Carpenter","Cooper","Dahin","Capella","Endriago","Gallina","Fenris","Freya","Glenn","Grissom","Jotunheim","Kailaasa","Lagarto","Muspelheim","Nifleheim","Primus","Vega","Ragnarok","Shepard","Slayton","Tarsis","Mercury","Venus","Mars","Earth","Terra","Jupiter","Saturn","Uranus","Neptune","Pluto","Europa","Ganymede","Callisto","Titan","Juno","Eridanus","Scorpius","Crux","Cancer","Taurus","Lyra","Andromeda","Virgo","Aquarius","Cygnus","Corvus","Taurus","Draco","Perseus","Pegasus","Gemini","Columbia","Bootes","Orion","Deneb","Merope","Agate","Amber","Beryl","Calcite","Citrine","Coral","Diamond","Emerald","Garnet","Jade","Lapis","Moonstone","Obsidian","Onyx","Opal","Pearl","Quartz","Ruby","Sapphire","Topaz","Iron","Lead","Nickel","Copper","Zinc","Tin","Manes","Argon","Neon","Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliett","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whisky","Xray","Yankee","Zulu"],_.bindAll(this,"newClick")},events:{"click #newPassword":"newClick"},numberCluster:function(){return this.numbers.random()+this.numbers.random()+this.numbers.random()},randomAmount:function(t){var e,i="";for(e=0;e<t;e++)i+=this.alpha.random();return i},newClick:function(){var t=$("#passwordOut"),e=(this.left.random()+" "+this.right.random()+" "+this.numberCluster()).split(" ").join(this.whitespace.random()),i=(this.randomAmount(5)+" "+this.randomAmount(5)).split(" ").join(this.whitespace.random()),n="<div>Long: "+e+"</div><div>Short: "+i+"</div>";t.empty().append(n).removeClass("mui--hide")}}),function(){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};