General Usage
For the first installation you can find the documentation here.
Using the API Widget you can register events that are dispatched by the widget.
The API Widget is included right after the body tag of your theme so please make sure to include any scripts that use the geolizr API below the following statement:
{% include 'geolizr-api' %}
You can register an event using the following function:
GeolizrAPI.addEventListener
Registers a callback function for a specific event.
GeolizrAPI.addEventListener([event], [callback]);
event The event you'd like to listen to.
callback The function that is called whenever the event is dispatched.
Events
Here is a list of currently available events.
geolizr.geoData
GeolizrAPI.addEventListener('geolizr.geoData', [callback]);
Callback parameters
geoData An object containing geo related informations:
{ status: [success|false], as: "<provider id ex: ASxxxx Telecom GmbH>", city: "<city ex: Cologne>", country: { code: "<country-code ex: DE>", country": "<country-name ex: Germany>" }, countryCode": "<country-iso-code ex: DE>", isp: "<Internet Service Provider ex: Telekom GmbH>", lat: <latitude ex: 50.9326>, lon: <longitude ex: 6.9342>, org: "<Organisation or Provider ex: Telekom GmbH>", query: "<ip adress ex: 87.78.185.249>", region: "<region-code ex: NW>", regionName: "<region-name: ex: North Rhine-Westphalia>", timezone: "<time-zone ex: Europe/Berlin>", zip: "<zip-code>", currencyCode: "<currency-code>", currency: { code: "<currency-code ex: EUR>" }, countryName: "<country-name ex: Germany>" }
Example
console.log(geoData);
});
Is dispatched whenever a notification is displayed.
GeolizrAPI.addEventListener('notification.show', [callback]);
Callback parameters
notification The notification:
{ id: [notification id], dismissible: [true|false], rememberCloseState: [true|false], linkText: [text of the link], linkUrl: [URL of the link], message: [notification message], font: [list of fonts], backgroundColor: [background color], textColor: [text color], linkColor: [link color] }
Example
console.log(notification);
});
GeolizrAPI.addEventListener('notification.resize', [callback]);
Callback parameters
notification The notification:
{ id: [notification id], dismissible: [true|false], rememberCloseState: [true|false], linkText: [text of the link], linkUrl: [URL of the link], message: [notification message], font: [list of fonts], backgroundColor: [background color], textColor: [text color], linkColor: [link color] }
notification.height The height of the notification.
Example
console.log(notification.notification);
console.log(notification.height);
});
notification.hide
Is dispatched whenever a notification is hidden.
Callback parameters
notification The notification:
{ id: [notification id], dismissible: [true|false], rememberCloseState: [true|false], linkText: [text of the link], linkUrl: [URL of the link], message: [notification message], font: [list of fonts], backgroundColor: [background color], textColor: [text color], linkColor: [link color] }
Example
console.log(notification);
});
Is dispatched whenever a popup is displayed.
GeolizrAPI.addEventListener('popup.show', [callback]);
Callback parameters
popup The popup:
{ id: [popup id], backgroundColor: [background color], pageBackgroundColor: [page background color], textColor: [text color], dismissible: [true|false], roundCorner: [true|false], rememberCloseState: [true|false], filterlistType: [none|blacklist|whitelist], filterlistUrls: [urls for the filter] }
Example
console.log(popup);
});
GeolizrAPI.addEventListener('popup.resize', [callback]);
Callback parameters
popup The popup:
{ id: [popup id], backgroundColor: [background color], pageBackgroundColor: [page background color], textColor: [text color], dismissible: [true|false], roundCorner: [true|false], rememberCloseState: [true|false], filterlistType: [none|blacklist|whitelist], filterlistUrls: [urls for the filter] }
Example
console.log(popup);
});
popup.hide
Is dispatched whenever a notification is hidden.
Callback parameters
popup The popup:
{ id: "[popup id]", backgroundColor: "[background color]", pageBackgroundColor: "[page background color]", textColor: "[text color]", dismissible: "[true|false]", roundCorner: "[true|false]", rememberCloseState: "[true|false]", filterlistType: "[none|blacklist|whitelist]", filterlistUrls: "[urls for the filter]" }
Example
console.log(popup);
});
Redirects
redirect.executed
Is dispatched whenever the redirects are configured but not executed.
Callback parameters
redirectResult The result of the redirect.
{ code: [rejected code], message: [rejected Message], redirect: { id: [redirect id], filterlistType: [none|blacklist|whitelist], filerlistUrls: [urls for the filter], redirectIgnoreReferrers: [urls for ignored referrers], redirectUrl: [target URL for the redirect] } }
Codes and Messages
Code | Message / Description |
---|---|
200 | <empty string> / No error - should not executed |
904 | "Filter blocks the Redirect" |
905 | "Referrer ... blocks the redirect" |
906 | "Destination and current URL are the same" |
Example
GeolizrAPI.addEventListener('redirect.notExecuted', function(result) { console.log(result); });
Currency Converter
currency.change
Is dispatched whenever the currency has changed.
Callback parameters
currency The currency code.
Example
console.log(currency);
});
currency.api
Is dispatched as soon as the currency api is available.
Callback parameters
api.switchCurrency A function that can be called to switch the currency.
api.getCurrency A function that returns the currently selected currency.
Example
api.switchCurrency('USD') // switches the currency to USD;
console.log(api.getCurrency());
});