Skip to main content

Library Config

To embed any UI component on a page, you must include the library in the header section of the page.

caution

Choose the right library URL based on the environment that you are integrating with.

<!-- For the Sandbox environment -->
<script
src="https://js.weavr.io/sandbox/weavr-client-v2.js"
charset="utf-8"
></script>
<!-- For the Live environment -->
<script
src="https://js.weavr.io/secure/weavr-client-v2.js"
charset="utf-8"
></script>

Initialise

Upon loading the library your window object will be appended with a weavr property. Next, initialise the library by providing your UI key with some other optional parameters.

init(uiKey, options);
ParameterTypeRequired?Description
uiKeystringRequiredThe UI Key retrieved from the Embedder Portal > API Credentials screen.
optionsobjectOptionalDescribes the fonts that are to be injected in the iframe DOM and consumed by other components

Parameter Definitions

The below defines the options object

PropertyTypeRequired?Description
fontsobject arrayRequiredDefines the fonts to be loaded. The array can be populate with only two types of objects. Types defined below. Type 1 and Type 2.
// Remember to change the UI key when moving your application to the Live environment

const weavrComponents = window.weavr.init(`{{uiKey}}`);

Property Definitions

fonts

You can specify the font(s) to be loaded and utilised from components when initialising the Weavr UI Components library by passing in the options parameter. Fonts can be injected in the components via 3 different manners (URI, Base64 & Custom Font URI )


Type 1 - The below defines the object.

PropertyTypeRequired?Description
familystringRequiredThe font family name.
srcstringRequiredThe src of the font.
stylestringOptionalThe style of the font.
unicodeRangestringOptionalThe Unicode range for the font.
weightstringOptionalThe weight of the font.
variantstringOptionalThe variant of the font.
stretchstringOptionalThe stretch of the font.
displaystringOptionalThe display style of the font.

Type 2 - The below defines the object.

PropertyTypeRequired?Description
cssSrcstringRequiredDefines the font and all font properties to be loaded.

const weavrComponents = window.weavr.init("{{ui_key}}", {
fonts: [
{
family: "{{Font Family Name}}",
src: "url('{{Font URL to be imported}}')",
/** Below are optional **/
style: "",
unicodeRange: "",
weight: "",
variant: "",
stretch: "",
display: "",
},
{
family: "{{Font Family Name}}",
src: "data:font/opentype;base64,{{base64 data format of font}}",
},
{
cssSrc: "{{Font URL content to be retrieved}}",
},
],
});



Examples

1. Initialisation with Fonts

The following example demonstrates the initialisation of the library, including the essential parameters for loading the fonts.

<!--index.html-->
<head>
...
<script
src="https://js.weavr.io/sandbox/weavr-client-v2.js"
charset="utf-8"
></script>
...
</head>
// secure-init.js

// Keys found in example are for demonstrations only and should always be changed.
const weavrComponents = window.weavr.init("HdKUGUBAW1", {
fonts: [
{
cssSrc:
"https://fonts.googleapis.com/css2?family=Fuggles:wght@100;400;900&display=swap",
},
],
});