Repository URL to install this package:
|
Version:
3.0.0-rc.1 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isSSR = isSSR;
exports.installIntercom = installIntercom;
exports.uninstallIntercom = uninstallIntercom;
function isSSR() {
return typeof window === 'undefined';
}
function isLoaded() {
return typeof window.Intercom !== 'undefined';
}
function installIntercom(intercomAppId) {
if (isSSR()) {
return;
}
if (!intercomAppId) {
console.warn('Cannot install Intercom, app ID is missing.');
return;
} // Check if Intercom is already loaded/present (via GTM for example)
if (!isLoaded()) {
/* eslint-disable */
window.intercomSettings = {
app_id: intercomAppId
};
(function () {
var w = window;
var ic = w.Intercom;
if (typeof ic === "function") {
ic('reattach_activator');
ic('update', w.intercomSettings);
} else {
var d = document;
var i = function i() {
i.c(arguments);
};
i.q = [];
i.c = function (args) {
i.q.push(args);
};
w.Intercom = i;
var l = function l() {
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://widget.intercom.io/widget/' + intercomAppId;
var x = d.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
};
if (document.readyState === 'complete') {
l();
} else if (w.attachEvent) {
w.attachEvent('onload', l);
} else {
w.addEventListener('load', l, false);
}
}
})();
/* eslint-enable */
}
}
function uninstallIntercom() {
if (isSSR()) {
return;
} // Don't need to do anything if intercom is not loaded/present
if (!isLoaded()) {
return;
} // Shut it down: this causes the connections to Intercom servers to be terminated
window.Intercom('shutdown'); // Force remove the left-over Intercom iframe from DOM
var iframe = document.getElementById('intercom-frame');
if (iframe) {
iframe.parentNode.removeChild(iframe);
} // Also clean up the Intercom API
window.Intercom = undefined;
}