| | |
| | | /** Script allowing to use the Web SDK from a WebView */ |
| | | |
| | | // Check if notice was initially displayed |
| | | var noticeReady = false; |
| | | |
| | | /** |
| | | * Initialize the SDK with the specified configuration |
| | | */ |
| | | function initSdk(config, gvl, sdkURL, languageCode) { |
| | | function initSdk(config, gvl, sdkURL, languageCode, isUnderage) { |
| | | if (config) { |
| | | // Set the global window configuration to the config object |
| | | window.didomiConfig = prepareConfigFromMobile(config, languageCode); |
| | | window.didomiConfig = prepareConfigFromMobile(config, languageCode, isUnderage); |
| | | |
| | | // If app, vendors, and iab exist, set the vendorList property |
| | | if ( |
| | |
| | | /** |
| | | * Open the notice screen |
| | | */ |
| | | function openNotice(options) { |
| | | function openNotice(userStatus, options) { |
| | | handleWebSDKEvents(); |
| | | window.didomiOnReady = window.didomiOnReady || []; |
| | | window.didomiOnReady.push(function (Didomi) { |
| | | Didomi.setUserStatus(userStatus); |
| | | if (options != null && options.deepLinkView != null) { |
| | | Didomi.preferences.show( |
| | | options.deepLinkView == 0 ? "purposes" : "vendors" |
| | |
| | | } else { |
| | | Didomi.notice.show(); |
| | | } |
| | | noticeReady = true; |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * Listen to SDK events |
| | | */ |
| | | function handleWebSDKEvents() { |
| | | window.didomiEventListeners = window.didomiEventListeners || []; |
| | | // TODO: Handle all iOS events |
| | | window.didomiEventListeners.push( |
| | |
| | | { |
| | | event: 'notice.hidden', |
| | | listener: function () { |
| | | if (noticeReady && !Didomi.preferences.isVisible()) { |
| | | if (isIOS()) { |
| | | if (Didomi.notice.isVisible()) { |
| | | window.webkit.messageHandlers.noticeHidden.postMessage(); |
| | | } |
| | | window.webkit.messageHandlers.noticeHidden.postMessage(""); |
| | | } else { |
| | | androidInterface.onNoticeHidden(); |
| | | } |
| | | } |
| | | } |
| | | }, |
| | |
| | | } |
| | | |
| | | /** |
| | | * Fix unescaped quotes and html tags. |
| | | * Fix unescaped quotes. |
| | | * @param {string} text |
| | | * @returns the sanitized text |
| | | */ |
| | | function sanitizeText(text) { |
| | | return text |
| | | // Escape unescaped quotes |
| | | .replace(/(?<!\\)(['"])/g, '\$1') |
| | | // Remove html tags |
| | | .replace(/[<>]/g, ''); |
| | | .replace(/(?<!\\)(['"])/g, '\$1'); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 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. |
| | | * @param {boolean} isUnderage whether the notice should be underage or not. |
| | | * @returns Config with unneeded features disabled |
| | | */ |
| | | function prepareConfigFromMobile(configFromMobile, languageCode) { |
| | | function prepareConfigFromMobile(configFromMobile, languageCode, isUnderage) { |
| | | if (configFromMobile == null) { |
| | | return null; |
| | | } |
| | |
| | | configFromMobile.app.consentString.signatureEnabled = false; |
| | | } |
| | | |
| | | // Ignore daysBeforeShowingAgain as this is already handled by the mobile SDKs. |
| | | if (configFromMobile.notice) { |
| | | delete configFromMobile.notice.daysBeforeShowingAgain; |
| | | } |
| | | |
| | | if (languageCode) { |
| | | if (languageCode == "pt-PT") { |
| | | // Temporary workaround for https://didomi.atlassian.net/browse/CMP-5552 |
| | | languageCode = "pt"; |
| | | } |
| | | configFromMobile.languages = { enabled: [languageCode], default: languageCode }; |
| | | } |
| | | |
| | | if (isUnderage) { |
| | | configFromMobile.user = configFromMobile.user || {}; |
| | | configFromMobile.user.isUnderage = isUnderage; |
| | | } |
| | | |
| | | return configFromMobile; |
| | | } |
| | | |