To integrate the Mockup Request Widget into your website, you need to include the widget script, initialize it, and then open it when necessary (e.g., on a button click).
Add the following script snippet to your HTML document (in the <head> or right before </body>). Ensure you replace [YOUR_BACKEND_URL] with the appropriate environment URL (e.g., https://demo.pdb.graphxserver.io).
<script>
(function (i, s, o, g, r, a, m, c) {
i['MockupRequestWidget'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.addEventListener('load', c);
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', `[YOUR_BACKEND_URL]/public/mockup-request-widget/main.js`, 'gsx_widget_mockup', undefined, undefined, () => {
console.log('Widget script is loaded and ready');
});
</script>
Once the script is loaded, the MockupRequestWidget object becomes available globally on the window object. First, initialize the widget by calling .init(). Then, open the widget by calling .open() with the required properties and callbacks.
const Widget = MockupRequestWidget.init();
Widget.open({
authToken: 'YOUR_AUTH_TOKEN',
createCustomView: true,
onSave: (result) => {
console.log('Saved data:', result.data);
},
onGenerate: (blob) => {
const objectURL = URL.createObjectURL(blob);
window.open(objectURL, '_blank');
}
});
Below are the properties that the open method accepts:
Authentication token used for API interactions.
(result: { data: SavePayload }) => void
Callback function executed when the user completes and saves their mockups.
Callback function executed when the user clicks 'Generate'. The widget processes the current active view layer layout and requests a high-resolution preview from the backend API, returning it as a Blob.
Allows the user to create custom views.
The widget is packed as a UMD module. When the script executes, it automatically assigns its exports to window.MockupRequestWidget. The inline async script snippet provided above safely bootstraps this process with a load callback.