Difference between revisions of "Widget:SpaceAPI"
| m (added last update timestamp popup) | m (fixed timestamp, testing animation classname) | ||
| Line 227: | Line 227: | ||
|                      this._beacon.point = L.latLng( this.data.sensors.beacon[0].location.lat, this.data.sensors.beacon[0].location.lon ); |                      this._beacon.point = L.latLng( this.data.sensors.beacon[0].location.lat, this.data.sensors.beacon[0].location.lon ); | ||
|                      this._beacon.circle.setRadius( this.data.sensors.beacon[0].location.accuracy ); |                      this._beacon.circle.setRadius( this.data.sensors.beacon[0].location.accuracy ); | ||
| + | |||
| + |                     var delta = (Date.now() - new Date( this.data.sensors.beacon[0].ext_lastchange * 1000 )) / 1000; | ||
| + |                     var postfix = "s"; | ||
| + |                     if ( this._beacon.icons[ this.data.sensors.beacon[0].name ] ) | ||
| + |                         this._beacon.icons[ this.data.sensors.beacon[0].name ].options.className = delta > 60 ? "disconnected" : ""; | ||
| + | |||
| + |                     // s->m | ||
| + |                     if ( delta / 60 > 1 ) | ||
| + |                     { | ||
| + |                         delta =/ 60; | ||
| + |                         postfix = "m"; | ||
| + |                     } | ||
| + |                     // m->h (starting @ 90m) | ||
| + |                     if ( delta / 90 > 1 ) | ||
| + |                     { | ||
| + |                         delta =/ 60; | ||
| + |                         postfix = "h"; | ||
| + |                     } | ||
| + |                     // h->d | ||
| + |                     if ( delta / 24 > 1 ) | ||
| + |                     { | ||
| + |                         delta =/ 24; | ||
| + |                         postfix = "d"; | ||
| + |                     } | ||
| + |                     // d->w | ||
| + |                     if ( delta / 7 > 1 ) | ||
| + |                     { | ||
| + |                         delta =/ 7; | ||
| + |                         postfix = "W"; | ||
| + |                     } | ||
| + |                     // w->m (@8) | ||
| + |                     if ( delta / 8 > 1 ) | ||
| + |                     { | ||
| + |                         delta = ( delta * 7 / 30.436875 ); | ||
| + |                         postfix = "M"; | ||
| + |                     } | ||
| + |                     // m->y | ||
| + |                     if ( delta / 12 > 1 ) | ||
| + |                     { | ||
| + |                         delta /= 12; | ||
| + |                         postfix = "Y"; | ||
| + |                     } | ||
| + |                     this._beacon.marker.bindPopup( "Hackers on a Bike<br/>Last update: " + Math.round( delta ) + postfix + " ago" ); | ||
|                      this._beacon.marker.setIcon( this._beacon.icons[ this.data.sensors.beacon[0].name ] || new L.Icon.Default() ); |                      this._beacon.marker.setIcon( this._beacon.icons[ this.data.sensors.beacon[0].name ] || new L.Icon.Default() ); | ||
| − | |||
| − | |||
|                  } |                  } | ||
|                  else |                  else | ||
Revision as of 08:37, 12 May 2016
This widget allows you to display the Space API data (provided as JSON)
Created by Xopr
Using this widget
To insert this widget, use the following code:
{{#widget:SpaceAPI
|url=/spaceAPI/
|width=260px
|height=20px
|padding=8px
|interval=20
|float=right
}}
This will give the following result:
Notes
- url is mandatory, the rest is optional (leave out interval to make the data static).
- it also must be written without protocol since colon (:) is not allowed, and may be relative, for example: //ackspace.nl/spaceAPI/ or /spaceAPI/
 
- You must provide a unit for the sizes (i.e. px, %, etc.)
Copy to your site
To use this widget on your site, just install MediaWiki Widgets extension and copy full source code of this page to your wiki as Widget:SpaceAPI article.
