JavaScript API¶
Reference documentation for the OSGEO-Inject JavaScript API.
Global Object¶
The library exposes window.OSGeoInject:
Methods¶
init()¶
Manually initialize the badge. Called automatically on page load.
Properties¶
version¶
The library version string.
config¶
The configuration object:
{
baseUrl: "https://affiliate.osgeo.org",
matomoUrl: "https://affiliate.osgeo.org/matomo",
matomoSiteId: 1,
announcementEndpoint: "/content/announcement.json",
osgeoUrl: "https://www.osgeo.org",
osgeoProjectsUrl: "https://www.osgeo.org/projects/",
logoPath: "/images/osgeo-logo.svg",
cacheDuration: 3600000
}
Data Attributes¶
Configure via script tag attributes:
| Attribute | Type | Default | Description |
|---|---|---|---|
data-position |
string | "top-right" |
Badge position |
data-collapsed |
boolean | false |
Start collapsed |
data-theme |
string | "auto" |
Color theme |
Events¶
The badge doesn't emit custom events, but you can observe DOM changes:
const observer = new MutationObserver((mutations) => {
// Badge was modified
});
observer.observe(
document.getElementById('osgeo-inject-badge'),
{ attributes: true, childList: true }
);
CSS Classes¶
| Class | Description |
|---|---|
.osgeo-inject |
Main container |
.osgeo-inject--collapsed |
Collapsed state |
.osgeo-inject--light |
Light theme |
.osgeo-inject--dark |
Dark theme |
.osgeo-inject--top-right |
Position modifier |
LocalStorage¶
The library uses localStorage for caching:
| Key | Description |
|---|---|
osgeo-inject-announcement |
Cached announcement JSON |
osgeo-inject-announcement-time |
Cache timestamp |
Clear cache: