Skip to content
This repository has been archived by the owner on Dec 5, 2017. It is now read-only.

Commit

Permalink
Generated files and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cheeaun committed Oct 18, 2015
1 parent 468f9c4 commit d3435a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 58 deletions.
3 changes: 1 addition & 2 deletions bus-arrival/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ <h1>Bus arrival times for <b id="bus-stop-name">&nbsp;</b></h1>
</tfoot>
</table>
</main>
<script src="https://busrouter-sg.s3-ap-southeast-1.amazonaws.com/js/gzip-enabled.js"></script>
<script>
!function(n,e){"function"==typeof define&&define.amd?define([],e):"undefined"!=typeof module&&module.exports?module.exports=e():n.lscache=e()}(this,function(){function n(){var n="__lscachetest__",t=n;if(void 0!==h)return h;try{u(n,t),a(n),h=!0}catch(r){h=e(r)?!0:!1}return h}function e(n){return n&&"QUOTA_EXCEEDED_ERR"===n.name||"NS_ERROR_DOM_QUOTA_REACHED"===n.name||"QuotaExceededError"===n.name?!0:!1}function t(){return void 0===p&&(p=null!=window.JSON),p}function r(n){return n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function o(n){return n+m}function i(){return Math.floor((new Date).getTime()/w)}function c(n){return localStorage.getItem(g+E+n)}function u(n,e){localStorage.removeItem(g+E+n),localStorage.setItem(g+E+n,e)}function a(n){localStorage.removeItem(g+E+n)}function f(n){for(var e=new RegExp("^"+g+r(E)+"(.*)"),t=localStorage.length-1;t>=0;--t){var i=localStorage.key(t);i=i&&i.match(e),i=i&&i[1],i&&i.indexOf(m)<0&&n(i,o(i))}}function l(n){var e=o(n);a(n),a(e)}function s(n){var e=o(n),t=c(e);if(t){var r=parseInt(t,v);if(i()>=r)return a(n),a(e),!0}}function d(n,e){S&&"console"in window&&"function"==typeof window.console.warn&&(window.console.warn("lscache - "+n),e&&window.console.warn("lscache - The error was: "+e.message))}var h,p,g="lscache-",m="-cacheexpiration",v=10,w=6e4,y=Math.floor(864e13/w),E="",S=!1,x={set:function(r,s,h){if(n()){if("string"!=typeof s){if(!t())return;try{s=JSON.stringify(s)}catch(p){return}}try{u(r,s)}catch(p){if(!e(p))return d("Could not add item with key '"+r+"'",p),void 0;var g,m=[];f(function(n,e){var t=c(e);t=t?parseInt(t,v):y,m.push({key:n,size:(c(n)||"").length,expiration:t})}),m.sort(function(n,e){return e.expiration-n.expiration});for(var w=(s||"").length;m.length&&w>0;)g=m.pop(),d("Cache is full, removing item with key '"+r+"'"),l(g.key),w-=g.size;try{u(r,s)}catch(p){return d("Could not add item with key '"+r+"', perhaps it's too big?",p),void 0}}h?u(o(r),(i()+h).toString(v)):a(o(r))}},get:function(e){if(!n())return null;if(s(e))return null;var r=c(e);if(!r||!t())return r;try{return JSON.parse(r)}catch(o){return r}},remove:function(e){n()&&l(e)},supported:function(){return n()},flush:function(){n()&&f(function(n){l(n)})},flushExpired:function(){n()&&f(function(n){s(n)})},setBucket:function(n){E=n},resetBucket:function(){E=""},enableWarnings:function(n){S=n}};return x});
</script>
<script>
var $arrivals=document.getElementById("arrivals"),arrivalsTimeout,xhr=new XMLHttpRequest,showArrivals=function(t){return document.hidden||"hidden"==document.visibilityState?(arrivalsTimeout=setTimeout(function(){showArrivals(t)},2500),void 0):(xhr.open("get","https://arrivelah.herokuapp.com/?id="+t,!0),xhr.onload=function(){$arrivals.classList.remove("fading");var e=JSON.parse(this.responseText);e&&!e.error&&($arrivals.innerHTML=e.services.sort(function(t,e){return null==t.next.duration_ms?1:null==e.next.duration_ms?-1:t.next.duration_ms-e.next.duration_ms}).map(function(t){return"<tr><th>"+t.no+"</th><td>"+timeDisplay(t.next.duration_ms)+"</td><td>"+timeDisplay(t.subsequent.duration_ms)+"</td></tr>"}).join(""),arrivalsTimeout=setTimeout(function(){showArrivals(t)},15e3))},xhr.onerror=function(){arrivalsTimeout=setTimeout(function(){showArrivals(t)},5e3)},xhr.send(),$arrivals.classList.add("fading"),void 0)},timeDisplay=function(t){if(null==t)return'<span class="insignificant">Unavailable</span>';var e=Math.ceil(t/1e3/60);return 0>=e?"Now":1==e?e+" min":e+" mins"},rootEndPoints={github:"../data/2/",s3:"https://busrouter-sg.s3-ap-southeast-1.amazonaws.com/v2/"},dataEndPoints={busStops:"bus-stops.json",busServices:"bus-services.json",busService:"bus-services/{{no}}.json",busStopsServices:"bus-stops-services.json"},getData=function(t,e,s){2==arguments.length&&(s=e,e={});var n=lscache.get(t);if(n)s(null,n);else{var a=new XMLHttpRequest,i="withCredentials"in a&&"undefined"!=typeof GZIP_ENABLED&&GZIP_ENABLED,r=rootEndPoints[i?"s3":"github"]+dataEndPoints[t.split("-")[0]];for(p in e)r=r.replace("{{"+p+"}}",e[p]);i&&(r+="?"+ +new Date),a.onload=function(){try{var e=JSON.parse(this.responseText);s(null,e),lscache.set(t,e,1440)}catch(n){s(n)}},a.onerror=a.onabort=s,a.open("get",r,!0),a.send()}};getData("busStops",function(t,e){var s=e.reduce(function(t,e){return t[e.no]=e,t},{});window.onhashchange=function(){var t=location.hash.slice(1),e=s[t];if(clearTimeout(arrivalsTimeout),t&&e){var n=e.lat+","+e.lng,a=t+" - "+e.name;document.title="Bus arrival times for "+a,document.getElementById("bus-stop-name").innerHTML=a,document.getElementById("bus-stop-heading").style.backgroundImage="url(https://maps.googleapis.com/maps/api/staticmap?"+["key=AIzaSyDJii3LssFIl3cw4XzTxtWqSls57rayV5I","center="+n,"zoom=16","scale=2","size=480x240","maptype=roadmap","format=png"].join("&")+")",showArrivals(t)}else alert("Invalid bus stop code.")},window.onhashchange()});
var $arrivals=document.getElementById("arrivals"),arrivalsTimeout,xhr=new XMLHttpRequest,showArrivals=function(e){return document.hidden||"hidden"==document.visibilityState?(arrivalsTimeout=setTimeout(function(){showArrivals(e)},2500),void 0):(xhr.open("get","https://arrivelah.herokuapp.com/?id="+e,!0),xhr.onload=function(){$arrivals.classList.remove("fading");var t=JSON.parse(this.responseText);t&&!t.error&&($arrivals.innerHTML=t.services.sort(function(e,t){return null==e.next.duration_ms?1:null==t.next.duration_ms?-1:e.next.duration_ms-t.next.duration_ms}).map(function(e){return"<tr><th>"+e.no+"</th><td>"+timeDisplay(e.next.duration_ms)+"</td><td>"+timeDisplay(e.subsequent.duration_ms)+"</td></tr>"}).join(""),arrivalsTimeout=setTimeout(function(){showArrivals(e)},15e3))},xhr.onerror=function(){arrivalsTimeout=setTimeout(function(){showArrivals(e)},5e3)},xhr.send(),$arrivals.classList.add("fading"),void 0)},timeDisplay=function(e){if(null==e)return'<span class="insignificant">Unavailable</span>';var t=Math.ceil(e/1e3/60);return 0>=t?"Now":1==t?t+" min":t+" mins"},dataEndPoints={busStops:"bus-stops.json",busServices:"bus-services.json",busService:"bus-services/{{no}}.json",busStopsServices:"bus-stops-services.json"},getData=function(e,t,s){2==arguments.length&&(s=t,t={});var n=lscache.get(e);if(n)s(null,n);else{var a=new XMLHttpRequest,r="../data/2/"+dataEndPoints[e.split("-")[0]];for(p in t)r=r.replace("{{"+p+"}}",t[p]);a.onload=function(){try{var t=JSON.parse(this.responseText);s(null,t),lscache.set(e,t,1440)}catch(n){s(n)}},a.onerror=a.onabort=s,a.open("get",r,!0),a.send()}};getData("busStops",function(e,t){var s=t.reduce(function(e,t){return e[t.no]=t,e},{});window.onhashchange=function(){var e=location.hash.slice(1),t=s[e];if(clearTimeout(arrivalsTimeout),e&&t){var n=t.lat+","+t.lng,a=e+" - "+t.name;document.title="Bus arrival times for "+a,document.getElementById("bus-stop-name").innerHTML=a,document.getElementById("bus-stop-heading").style.backgroundImage="url(https://maps.googleapis.com/maps/api/staticmap?"+["key=AIzaSyDJii3LssFIl3cw4XzTxtWqSls57rayV5I","center="+n,"zoom=16","scale=2","size=480x240","maptype=roadmap","format=png"].join("&")+")",showArrivals(e)}else alert("Invalid bus stop code.")},window.onhashchange()});
</script>
<script>
WebFontConfig = {
Expand Down
Loading

0 comments on commit d3435a0

Please sign in to comment.