| | |
| | | /** Script allowing to use the Web SDK from a WebView */ |
| | | |
| | | // Check if SDK is still initializing and should not display the notice yet |
| | | var initializationInProgress = true; |
| | | // Check if notice was initially displayed |
| | | var noticeReady = false; |
| | | var noticeDisplayed = false; |
| | | |
| | | /** |
| | | * Initialize the SDK with the specified configuration |
| | |
| | | // Set the global window configuration to the config object |
| | | window.didomiConfig = prepareConfigFromMobile(config, languageCode, isUnderage); |
| | | |
| | | // Set the location properties |
| | | window.didomiCountry = extractCountryFromMobileConfig(config); |
| | | window.didomiRegion = extractRegionFromMobileConfig(config); |
| | | |
| | | // If app, vendors, and iab exist, set the vendorList property |
| | | if ( |
| | | window.didomiConfig.app && |
| | |
| | | * Open the notice screen |
| | | */ |
| | | function openNotice(userStatus, options) { |
| | | var hasDeepLink = options != null && options.deepLinkView != null |
| | | if (!hasDeepLink) { |
| | | initializationInProgress = false |
| | | } |
| | | handleWebSDKEvents(); |
| | | window.didomiOnReady = window.didomiOnReady || []; |
| | | window.didomiOnReady.push(function (Didomi) { |
| | | Didomi.setUserStatus(userStatus); |
| | | if (options != null && options.deepLinkView != null) { |
| | | if (hasDeepLink) { |
| | | initializationInProgress = false; |
| | | Didomi.preferences.show( |
| | | options.deepLinkView == 0 ? "purposes" : "vendors" |
| | | ); |
| | | } else { |
| | | Didomi.notice.show(); |
| | | } |
| | | noticeReady = true; |
| | | noticeDisplayed = true; |
| | | }); |
| | | } |
| | | |
| | |
| | | { |
| | | event: 'notice.hidden', |
| | | listener: function () { |
| | | if (noticeReady && !Didomi.preferences.isVisible()) { |
| | | if (noticeDisplayed && !Didomi.preferences.isVisible()) { |
| | | if (isIOS()) { |
| | | window.webkit.messageHandlers.noticeHidden.postMessage(""); |
| | | } else { |
| | |
| | | { |
| | | event: 'notice.shown', |
| | | listener: function () { |
| | | if (isIOS()) { |
| | | if (initializationInProgress) { |
| | | // Make sure the notice is not displayed if initialization is still in progress |
| | | Didomi.notice.hide(); |
| | | } else if (isIOS()) { |
| | | window.webkit.messageHandlers.noticeShown.postMessage(""); |
| | | } else { |
| | | androidInterface.onNoticeShown(); |
| | |
| | | |
| | | /** |
| | | * Fix unescaped quotes. |
| | | * Note: lookbehinds (`(?<=...)` or `(?<!...)`) are only supported from safari 17+ |
| | | * @param {string} text |
| | | * @returns the sanitized text |
| | | */ |
| | | function sanitizeText(text) { |
| | | return text |
| | | // Escape unescaped quotes |
| | | .replace(/(?<!\\)(['"])/g, '\$1'); |
| | | return text.replace(/(^|[^\\])(['"])/g, '$1\$2'); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Extract the country from the mobile config. |
| | | * @param {*} configFromMobile |
| | | * @returns the country or null if not defined. |
| | | */ |
| | | function extractCountryFromMobileConfig(configFromMobile) { |
| | | return configFromMobile.user ? configFromMobile.user.country : null; |
| | | } |
| | | |
| | | /** |
| | | * Extract the region from the mobile config. |
| | | * @param {*} configFromMobile |
| | | * @returns the region or null if not defined. |
| | | */ |
| | | function extractRegionFromMobileConfig(configFromMobile) { |
| | | return configFromMobile.user ? configFromMobile.user.region : null; |
| | | } |
| | | |
| | | /** |
| | | * Prepare config file to be consumed by the Web SDK, by disabling the features already handled by Mobile SDKs. |
| | | * @param {*} configFromMobile Config provided by mobile. |
| | | * @param {string} languageCode language code to be set in the Config. |