in css/jetbrains-bundle/sales-chat.js [232:333]
function SalesChat(config) {
var chat = this;
// Configure
/**
* @type {SalesChatConfig}
*/
var cfg = mergeConfig(defaultConfig, config || {});
this.config = cfg;
// Check is chat should be shown on current URL path
var currentURLPath = window.location.pathname;
var isShouldBeShown = true;
if (!cfg.urls || cfg.urls.length > 0) {
isShouldBeShown = cfg.urls.filter(function (regexp) {
return regexp.test(currentURLPath)
}).length > 0;
if (!isShouldBeShown) {
console.log('Chat#urls does not match current location');
return this;
}
}
this._emitter = Emitter();
Promise.resolve()
.then(function () {
// If country code not provided detect it via GeoIP service
if (!cfg.countryCode) {
return geo.getCountryCode();
} else {
return cfg.countryCode;
}
})
.then(function (countryCode) {
var department = chat.getDepartmentByCountryCode(countryCode);
chat.department = department;
return department;
})
// Load Zopim chat JS API
.then(function (department) {
return utils.loadZopimChatJSAPI(department.instanceDomain);
})
// Fire onReady & onConnect events
.then(function () {
$zopim(function () {
chat._emitter.emit(SalesChat.EVENTS.READY);
$zopim.livechat.setOnConnected(function () {
chat._emitter.emit(SalesChat.EVENTS.CONNECTED);
});
});
});
chat.onReady(function () {
var currentDepartment = chat.department;
// Pre-select the department based on the country
chat.setDepartment(currentDepartment.name);
if (cfg.lang) {
chat.setLanguage(cfg.lang);
}
else if (cfg.useDepartmentLang) {
chat.setLanguage(currentDepartment.lang);
}
chat.customizeTheme();
});
chat.onConnect(function () {
var currentDepartment = chat.department;
// Leave only current department
$zopim.livechat.departments.filter(currentDepartment.name);
var currentDepartmentId;
for (var deptId in departmentsList) {
if (departmentsList[deptId] === currentDepartment) {
currentDepartmentId = deptId;
break;
}
}
var status = chat.getDepartmentStatus(currentDepartment.name);
status = status ? status : '';
// lang, department id and status, e.g. en_international_offline
var tag = [
currentDepartment.lang,
currentDepartmentId,
status
].join('_');
chat.addTags([tag]);
});
}