common

Playtech.API. common

Methods

# (static) getScript(url, optionsopt) → {Promise.<{Event}>}

Load script.
Parameters:
Name Type Attributes Description
url string URL to JS file to load.
options Object <optional>
options for loading JS file.
Properties
Name Type Attributes Default Description
parent string <optional>
'head' Tag in witch script should be mounted, usage: document.getElementsByTagName(parent)[0].appendChild(script).
id string <optional>
HTML id attribute of created script.
type string <optional>
'text/javascript' HTML type attribute of created script.
Returns:
'load' type event
Type
Promise.<{Event}>
Example
Playtech.API.common.getScript('https://www.example.com', { parent: 'head', id: 'container', type: 'module' }).then((event) => { ... });

# (static) getStylesheet(url) → {Promise.<{Event}>}

Load styles.
Parameters:
Name Type Description
url string URL to CSS file to load.
Returns:
'load' type event
Type
Promise.<{Event}>
Example
Playtech.API.common.getStylesheet('https://www.example.com').then((event) => { ... });

# (static) isAllowedToRedirect(path) → {boolean}

Return whether the Portal can be redirected to page according to allowedRedirectHostNames.
Parameters:
Name Type Description
path string Relative path or full link of the existing page to redirect to.
Returns:
Type
boolean
Example
Playtech.API.common.isAllowedToRedirect('/deposit');
Playtech.API.common.isAllowedToRedirect('https://google.com');

# (static) navigate(path, stateopt, optionsopt)

Navigates to another page.
Parameters:
Name Type Attributes Description
path string Relative path of the existing page to redirect to.
state Object <optional>
State object to store with the new navigate.
Properties
Name Type Attributes Description
fromPopup boolean <optional>
options Object <optional>
Properties
Name Type Attributes Default Description
removeParams Array.<string> <optional>
[] List of query string parameters to remove upon navigation.
preserveSearchParams boolean <optional>
true Preserve existing query string parameters.
Example
Playtech.API.common.navigate(
       'test-page',
       { fromPopup: false },
       { removeParams: ['test'], preserveSearchParams: true }
);

# (static) redirect(path, stateopt, optionsopt)

Redirects to another page (full reload).
Parameters:
Name Type Attributes Description
path string Relative path of the existing page to redirect to.
state Object <optional>
State object to store with the new navigate.
options Object <optional>
Properties
Name Type Attributes Default Description
removeParams Array.<string> <optional>
[] List of query string parameters to remove upon navigation.
preserveSearchParams boolean <optional>
true Preserve existing query string parameters.
preserveHash boolean <optional>
false Preserve existing query string parameters.
Example
Playtech.API.common.redirect(
       'test-page',
      { fromPopup: false },
      {
           removeParams: ['test'],
           preserveSearchParams: true
       }
);

# (static) replace(path, stateopt, optionsopt)

Navigates to another page but replaces current history frame.
Parameters:
Name Type Attributes Description
path string Relative path of the existing page to redirect to.
state Object <optional>
State object to store with the new navigate.
options Object <optional>
Properties
Name Type Attributes Default Description
removeParams Array.<string> <optional>
[] List of query string parameters to remove upon navigation.
preserveSearchParams boolean <optional>
true Preserve existing query string parameters.
preserveHash boolean <optional>
false Preserve existing query string parameters.
Example
Playtech.API.common.replace(
       'test-page',
       { fromPopup: false },
       { removeParams: ['test'], preserveSearchParams: true }
);

# (static) sanitize(html) → {string}

Sanitize HTML string.
Parameters:
Name Type Description
html string HTML string to sanitize.
Returns:
Sanitized HTML string.
Type
string
Example
Playtech.API.common.sanitize('<script>alert("XSS")</script>');

# (static) setNotificationsOptions(options)

Sets global toast notifications options
Parameters:
Name Type Description
options Object Global Notistack toast messages options to override default Portal options. See docs
Properties
Name Type Attributes Description
autoHideDuration number <optional>
Toast display duration in seconds. Default value '5' if custom value is not set in 'Toast Message Preferences' component.
Example
Playtech.API.common.setNotificationsOptions({ hideIconVariant: false, disableWindowBlurListener: true, autoHideDuration: 5 });

# (static) showNotification(messageOrTKey, toastOptionsopt)

Display toast notification
Parameters:
Name Type Attributes Description
messageOrTKey string Translation Key or message to be shown in toast notification, message can be HTML text.
toastOptions Object <optional>
Notistack toast message options. See docs
Properties
Name Type Attributes Default Description
variant 'default' | 'info' | 'success' | 'warning' | 'error' <optional>
'default'
autoHideDuration number <optional>
Toast display duration in seconds. Default value '5' if custom value is not set in 'Toast Message Preferences' component.
Example
Playtech.API.common.showNotification('playtech.mobile.system.error.default');
Playtech.API.common.showNotification('playtech.mobile.system.error.default', { variant: 'error' });
Playtech.API.common.showNotification('Success!!!', { autoHideDuration: 5, variant: 'success' });
Playtech.API.common.showNotification('This is <b>NOT</b> allowed!', { variant: 'warning' });         *
Playtech.API.common.showNotification('playtech.mobile.system.error.default', {
    SnackbarProps: {'aria-label': 'text'},
    className: 'className',
    onClose: () => console.log('snack was closed')
});