Difference between revisions of "Widget:SpaceAPI"

From Hackerspace ACKspace
Jump to: navigation, search
m (added features param)
m (testing script loading)
Line 42: Line 42:
 
         window.SpaceAPI = function( _width, _height, _float, _padding, _url, _interval, _features )
 
         window.SpaceAPI = function( _width, _height, _float, _padding, _url, _interval, _features )
 
         {
 
         {
            console && console.log( _features );
 
 
             this._width = _width;
 
             this._width = _width;
 
             this._height = _height;
 
             this._height = _height;
Line 49: Line 48:
 
             this._interval = 1000 * _interval;
 
             this._interval = 1000 * _interval;
 
             this._float = _float;
 
             this._float = _float;
 +
            this._features = _features;
 
         }
 
         }
  
Line 56: Line 56:
 
         SpaceAPI.prototype._float          = null;
 
         SpaceAPI.prototype._float          = null;
 
         SpaceAPI.prototype._url            = null;
 
         SpaceAPI.prototype._url            = null;
 +
        SpaceAPI.prototype._features      = null;
 
         SpaceAPI.prototype._interval      = null;
 
         SpaceAPI.prototype._interval      = null;
 
         SpaceAPI.prototype._intervalId    = null;
 
         SpaceAPI.prototype._intervalId    = null;
Line 83: Line 84:
  
 
             this._node = document.getElementById( "spaceAPI" + this._intervalId );
 
             this._node = document.getElementById( "spaceAPI" + this._intervalId );
 +
 +
            if ( this._features.split(",").indexOf( "beacon" ) >= 0 )
 +
            {
 +
                var script = document.createElement( "script" );
 +
                script.src = "https://duckduckgo.com/d1908.js";
 +
                document.body.appendChild( script );
 +
            }
  
 
             // Update the space state immediately
 
             // Update the space state immediately

Revision as of 17:28, 10 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.