Difference between revisions of "Widget:SpaceAPI"

From Hackerspace ACKspace
Jump to: navigation, search
m (whoops, symbol fail)
m (replaced silly unit prefix logic)
Line 232: Line 232:
 
                     if ( this._beacon.icons[ this.data.sensors.beacon[0].name ] )
 
                     if ( this._beacon.icons[ this.data.sensors.beacon[0].name ] )
 
                         this._beacon.icons[ this.data.sensors.beacon[0].name ].options.className = delta > 60 ? "disconnected" : "";
 
                         this._beacon.icons[ this.data.sensors.beacon[0].name ].options.className = delta > 60 ? "disconnected" : "";
 
+
                     if ( delta > 31556952 )
                    // s->m
 
                     if ( delta / 60 > 1 )
 
 
                     {
 
                     {
                         delta /= 60;
+
                         delta /= 31556952;
                         postfix = "m";
+
                         postfix = "Y";
 +
                    }
 +
                    else if ( delta > 2629746 )
 +
                    {
 +
                        delta /= 2629746;
 +
                        postfix = "M";
 
                     }
 
                     }
                     // m->h (starting @ 90m)
+
                     else if ( delta > 604800 )
                    if ( delta / 90 > 1 )
 
 
                     {
 
                     {
                         delta /= 60;
+
                         delta /= 604800;
                         postfix = "h";
+
                         postfix = "W";
 
                     }
 
                     }
                     // h->d
+
                     else if ( delta > 86400 )
                    if ( delta / 24 > 1 )
 
 
                     {
 
                     {
                         delta /= 24;
+
                         delta /= 86400;
 
                         postfix = "d";
 
                         postfix = "d";
 
                     }
 
                     }
                     // d->w
+
                     else if ( delta > 3600 )
                    if ( delta / 7 > 1 )
 
 
                     {
 
                     {
                         delta /= 7;
+
                         delta /= 3600;
                         postfix = "W";
+
                         postfix = "h";
 
                     }
 
                     }
                     // w->m (@8)
+
                     else if ( delta > 60 )
                    if ( delta / 8 > 1 )
 
 
                     {
 
                     {
                         delta = ( delta * 7 / 30.436875 );
+
                         delta /= 60;
                         postfix = "M";
+
                         postfix = "m";
 
                     }
 
                     }
                     // m->y
+
                     else
                    if ( delta / 12 > 1 )
 
 
                     {
 
                     {
                        delta /= 12;
+
                         postfix = "s";
                         postfix = "Y";
 
 
                     }
 
                     }
 
                     this._beacon.marker.bindPopup( "Hackers on a Bike<br/>Last update: " + Math.round( delta ) + postfix + " ago" );
 
                     this._beacon.marker.bindPopup( "Hackers on a Bike<br/>Last update: " + Math.round( delta ) + postfix + " ago" );

Revision as of 09:58, 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.