JavaScript API
Available as window.Paintbase once the script has loaded. Optional.
| Method | |
|---|---|
Paintbase.open() | Open the popup |
Paintbase.close() | Close the popup |
Paintbase.on("result", fn) | Call fn after every successful lookup |
Paintbase.mount() | Mount any data-paintbase-inline elements added after the script loaded |
result
Fires for the popup and the inline lookup.
Paintbase.on("result", (result) => {
// { code: "KKN", name: "Elixir red", make: "Citroën", model: "C3", year: "2020", plate: "ABC123" }
});| Field | Type | |
|---|---|---|
code | string | null | Paint code. null when only a color name is known. |
name | string | null | Color name |
make | string | null | |
model | string | null | |
year | string | null | |
plate | string | Plate or VIN that was searched |
Example: show matching products
Use the paint code to filter your own catalogue on the same page.
Paintbase.on("result", (result) => {
showProducts(result.code); // your own function, e.g. "KKN"
});Example: go to the product
<script
src="https://embed.paintbase.app/v1/embed.js"
data-partner="YOUR_ID"
async
></script>
<script>
window.addEventListener("load", () => {
Paintbase.on("result", ({ code }) => {
if (code) location.href = "/search?q=" + encodeURIComponent(code);
});
});
</script>Open from your own code
document.querySelector("#paint-help").addEventListener("click", () => Paintbase.open());Single-page apps
The script mounts inline lookups once, when it loads. If your site adds the data-paintbase-inline element later (a route change, a tab, a modal), call Paintbase.mount() after it is on the page.
Paintbase.mount();Last updated on