(function ($) {
'use strict';
$.fn.czmChatSupport = function (options) {
var defaults = {
button: {
position: "right",
style: 1,
src: '',
backgroundColor: "#26c281",
effect: 1,
notificationNumber: "1",
speechBubble: "How can we help you?",
pulseEffect: true,
text: {
title: "Need help? Chat with us",
description: "Customer Support",
online: "I'm Online",
offline: "I will be back soon"
},
link: {
desktop: false,
mobile: false
},
onlineDay: {
sunday: false,
monday: false,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
saturday: false
},
delay: true
},
popup: {
automaticOpen: false,
outsideClickClosePopup: true,
effect: 1,
header: {
backgroundColor: "#26c281",
title: "Need help? Chat with us",
description: "Click one of our representatives below"
},
persons: [],
personsSettings: {
avatar: {
src: '',
backgroundColor: "#26c281",
onlineCircle: true
},
text: {
title: "Need Help?",
description: "Customer Support",
online: "I'm Online",
offline: "I will be back soon",
message: false,
textbox: false,
button: "Start Chat"
},
link: {
desktop: false,
mobile: false
},
onlineDay: {
sunday: false,
monday: false,
tuesday: false,
wednesday: false,
thursday: false,
friday: false,
saturday: false
}
}
},
sound: true,
changeBrowserTitle: "New Message!",
cookie: false,
timezone: false,
onLoad: function () {},
onClick: function () {},
onPopupOpen: function () {},
onPopupClose: function () {}
};
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
var settings = $.extend(true, {}, defaults, options);
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** TIMEZONE **********/
var mtimezone;
if (window.moment) {
if (settings.timezone !== false) {
mtimezone = moment().tz(settings.timezone);
} else {
mtimezone = moment().tz(moment.tz.guess());
}
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
return this.each(function () {
//console.log(settings);
var czmID = this;
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** COOKIE **********/
if (getCookie('czmChatSupport') == 'true') {
settings.button.pulseEffect = false;
settings.button.notificationNumber = false;
settings.button.speechBubble = false;
settings.button.delay = false;
settings.popup.automaticOpen = false;
settings.sound = false;
settings.changeBrowserTitle = false;
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
if (settings.onLoad && typeof settings.onLoad === 'function') {
settings.onLoad.call(this);
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
if ((settings.button.position !== 'right') && (settings.button.position !== 'left')) {
settings.button.speechBubble = false;
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** BUTTON **********/
$(czmID).addClass('czm-chat-support czm-chat-support-' + settings.button.style).prepend('
');
if ((settings.button.position == 'right') || (settings.button.position == 'left')) {
$(czmID).addClass('czm-fixed');
if (settings.button.position == 'right') {
$(czmID).addClass('czm-right');
} else if (settings.button.position == 'left') {
$(czmID).addClass('czm-left');
}
if (settings.button.delay !== false) {
if ((settings.button.effect == 2) || (settings.button.effect == 4) || (settings.button.effect == 5) || (settings.button.effect == 7)) {
if (settings.button.position == 'right') {
settings.button.effect = settings.button.effect + '__1';
} else if (settings.button.position == 'left') {
settings.button.effect = settings.button.effect + '__2';
}
}
$(czmID).addClass('czm-chat-support-show');
$('.czm-button', czmID).addClass('animate__animated animate__' + settings.button.effect);
setInterval(function () {
$('.czm-button', czmID).removeClass('animate__animated animate__' + settings.button.effect);
}, 1000);
} else {
$(czmID).addClass('czm-chat-support-show');
}
} else {
$(czmID).addClass('czm-chat-support-show');
}
var buttonOnline = true;
var buttonLink;
if ((settings.button.link.desktop !== false) || (settings.button.link.mobile !== false)) {
if (window.moment) {
if ((settings.button.onlineDay[mtimezone.format('dddd').toLowerCase()] == false) || (settings.button.onlineDay[mtimezone.format('dddd').toLowerCase()] == undefined)) {
buttonOnline = false;
} else if (moment(mtimezone.format('HH:mm:ss'), 'HH:mm:ss').isBetween(moment(settings.button.onlineDay[mtimezone.format('dddd').toLowerCase()].split('-')[0] + ':00', 'HH:mm:ss'), moment(settings.button.onlineDay[mtimezone.format('dddd').toLowerCase()].split('-')[1] + ':59', 'HH:mm:ss')) == false) {
buttonOnline = false;
}
}
} else if (settings.popup.persons.length == 0) {
buttonOnline = false;
}
$('.czm-button', czmID).css('background', settings.button.backgroundColor);
$('.czm-button', czmID).append('');
$('.czm-button-person-avatar', czmID).append(settings.button.src);
if ((settings.button.style == 6) || (settings.button.style == 7)) {
$('.czm-button-person-avatar', czmID).css('background', settings.button.backgroundColor);
}
if ((settings.button.style == 3) || (settings.button.style == 5)) {
$('.czm-button', czmID).append('' + settings.button.text.title + '
');
} else if ((settings.button.style == 2) || (settings.button.style == 4) || (settings.button.style == 6) || (settings.button.style == 7)) {
$('.czm-button', czmID).append('' + settings.button.text.title + '
');
if (((settings.button.text.description !== false) && (settings.button.text.description !== '') && (settings.button.text.description !== undefined)) || ((settings.button.text.online !== false) && (settings.button.text.online !== '') && (settings.button.text.online !== undefined)) || (settings.button.text.offline !== false) && (settings.button.text.offline !== '') && (settings.button.text.offline !== undefined)) {
if ((settings.button.text.description !== false) && (settings.button.text.description !== '') && (settings.button.text.description !== undefined)) {
$('.czm-button-content', czmID).append('' + settings.button.text.description + '
');
}
if (buttonOnline == true) {
if ((settings.button.text.online !== false) && (settings.button.text.online !== '') && (settings.button.text.online !== undefined)) {
$('.czm-button-content', czmID).append('' + settings.button.text.online + '
');
}
} else {
if ((settings.button.text.offline !== false) && (settings.button.text.offline !== '') && (settings.button.text.offline !== undefined)) {
$('.czm-button-content', czmID).append('' + settings.button.text.offline + '
');
}
}
}
}
if (settings.button.src.search('img') !== -1) {
$('.czm-button', czmID).addClass('czm-button-image');
}
if (buttonOnline == false) {
$('.czm-button', czmID).addClass('czm-button-offline');
}
if (((settings.button.link.desktop !== false) || (settings.button.link.mobile !== false)) && (buttonOnline == true)) {
$('.czm-button', czmID).click(function () {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if (settings.button.link.mobile !== false) {
buttonLink = settings.button.link.mobile;
} else {
buttonLink = settings.button.link.desktop;
}
} else {
buttonLink = settings.button.link.desktop;
}
window.open(buttonLink, '_blank');
if (settings.onClick && typeof settings.onClick === 'function') {
settings.onClick.call(this);
}
});
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** POPUP **********/
if ((settings.button.link.desktop == false) && (settings.button.link.mobile == false) && (settings.popup.persons.length > 0) && ((settings.button.position == 'right') || (settings.button.position == 'left'))) {
if (settings.popup.outsideClickClosePopup == true) {
$(document).click(function () {
if ($(czmID).hasClass('czm-popup-show')) {
czmHide();
if (settings.onPopupClose && typeof settings.onPopupClose === 'function') {
settings.onPopupClose.call(this);
}
}
});
$(czmID).click(function (e) {
e.stopPropagation();
return false;
});
}
$('.czm-button', czmID).click(function () {
czmHide();
if ($(czmID).hasClass('czm-popup-show')) {
if (settings.onPopupOpen && typeof settings.onPopupOpen === 'function') {
settings.onPopupOpen.call(this);
}
} else {
if (settings.onPopupClose && typeof settings.onPopupClose === 'function') {
settings.onPopupClose.call(this);
}
}
});
if ((settings.popup.effect == 2) || (settings.popup.effect == 10) || (settings.popup.effect == 12)) {
if (settings.button.position == 'right') {
settings.popup.effect = settings.popup.effect + '__1';
} else if (settings.button.position == 'left') {
settings.popup.effect = settings.popup.effect + '__2';
}
}
$(czmID).prepend('');
if (settings.popup.automaticOpen == true) {
var automaticOpenTime;
if (settings.button.delay == true) {
automaticOpenTime = 900;
} else {
automaticOpenTime = 200;
}
setTimeout(function () {
czmHide();
if (settings.onPopupOpen && typeof settings.onPopupOpen === 'function') {
settings.onPopupOpen.call(this);
}
}, automaticOpenTime);
}
$('.czm-popup', czmID).prepend('');
$('.czm-popup-close', czmID).click(function () {
czmHide();
if (settings.onPopupClose && typeof settings.onPopupClose === 'function') {
settings.onPopupClose.call(this);
}
});
$('.czm-popup-header', czmID).css('background', settings.popup.header.backgroundColor);
if ((settings.popup.header.title == false) || (settings.popup.header.title == '') || (settings.popup.header.title == undefined)) {
$('.czm-popup-header', czmID).append('');
} else {
$('.czm-popup-header', czmID).append('');
}
if ((settings.popup.header.description !== false) && (settings.popup.header.description !== '') && (settings.popup.header.description !== undefined)) {
$('.czm-popup-header', czmID).append('');
}
$('.czm-popup', czmID).append('');
if (settings.popup.persons.length > 5) {
$('.czm-popup', czmID).addClass('czm-popup-small');
}
var pn = 0;
for (var p = 0; p < settings.popup.persons.length; p++) {
pn = p + 1;
var personLink;
var personOnline = true;
if (settings.popup.persons[p].link == undefined) {
settings.popup.persons[p].link = settings.popup.personsSettings.link;
} else {
if (settings.popup.persons[p].link.desktop == undefined) {
settings.popup.persons[p].link.desktop = settings.popup.personsSettings.link.desktop;
}
if (settings.popup.persons[p].link.mobile == undefined) {
settings.popup.persons[p].link.mobile = settings.popup.personsSettings.link.mobile;
}
}
if (settings.popup.persons[p].avatar == undefined) {
settings.popup.persons[p].avatar = settings.popup.personsSettings.avatar;
} else {
if (settings.popup.persons[p].avatar.src == undefined) {
settings.popup.persons[p].avatar.src = settings.popup.personsSettings.avatar.src;
}
if (settings.popup.persons[p].avatar.backgroundColor == undefined) {
settings.popup.persons[p].avatar.backgroundColor = settings.popup.personsSettings.avatar.backgroundColor;
}
if (settings.popup.persons[p].avatar.onlineCircle == undefined) {
settings.popup.persons[p].avatar.onlineCircle = settings.popup.personsSettings.avatar.onlineCircle;
}
}
if (settings.popup.persons[p].text == undefined) {
settings.popup.persons[p].text = settings.popup.personsSettings.text;
} else {
if (settings.popup.persons[p].text.title == undefined) {
settings.popup.persons[p].text.title = settings.popup.personsSettings.text.title;
}
if (settings.popup.persons[p].text.description == undefined) {
settings.popup.persons[p].text.description = settings.popup.personsSettings.text.description;
}
if (settings.popup.persons[p].text.online == undefined) {
settings.popup.persons[p].text.online = settings.popup.personsSettings.text.online;
}
if (settings.popup.persons[p].text.offline == undefined) {
settings.popup.persons[p].text.offline = settings.popup.personsSettings.text.offline;
}
if (settings.popup.persons[p].text.message == undefined) {
settings.popup.persons[p].text.message = settings.popup.personsSettings.text.message;
}
if (settings.popup.persons[p].text.textbox == undefined) {
settings.popup.persons[p].text.textbox = settings.popup.personsSettings.text.textbox;
}
if (settings.popup.persons[p].text.button == undefined) {
settings.popup.persons[p].text.button = settings.popup.personsSettings.text.button;
}
}
if (settings.popup.persons[p].onlineDay == undefined) {
settings.popup.persons[p].onlineDay = settings.popup.personsSettings.onlineDay;
} else {
if (settings.popup.persons[p].onlineDay.sunday == undefined) {
settings.popup.persons[p].onlineDay.sunday = settings.popup.personsSettings.onlineDay.sunday;
}
if (settings.popup.persons[p].onlineDay.monday == undefined) {
settings.popup.persons[p].onlineDay.monday = settings.popup.personsSettings.onlineDay.monday;
}
if (settings.popup.persons[p].onlineDay.tuesday == undefined) {
settings.popup.persons[p].onlineDay.tuesday = settings.popup.personsSettings.onlineDay.tuesday;
}
if (settings.popup.persons[p].onlineDay.wednesday == undefined) {
settings.popup.persons[p].onlineDay.wednesday = settings.popup.personsSettings.onlineDay.wednesday;
}
if (settings.popup.persons[p].onlineDay.thursday == undefined) {
settings.popup.persons[p].onlineDay.thursday = settings.popup.personsSettings.onlineDay.thursday;
}
if (settings.popup.persons[p].onlineDay.friday == undefined) {
settings.popup.persons[p].onlineDay.friday = settings.popup.personsSettings.onlineDay.friday;
}
if (settings.popup.persons[p].onlineDay.saturday == undefined) {
settings.popup.persons[p].onlineDay.saturday = settings.popup.personsSettings.onlineDay.saturday;
}
}
if (window.moment) {
if (settings.popup.persons[p].onlineDay[mtimezone.format('dddd').toLowerCase()] == false) {
personOnline = false;
} else if (moment(mtimezone.format('HH:mm:ss'), 'HH:mm:ss').isBetween(moment(settings.popup.persons[p].onlineDay[mtimezone.format('dddd').toLowerCase()].split('-')[0] + ':00', 'HH:mm:ss'), moment(settings.popup.persons[p].onlineDay[mtimezone.format('dddd').toLowerCase()].split('-')[1] + ':59', 'HH:mm:ss')) == false) {
personOnline = false;
}
}
$('.czm-popup-persons', czmID).append('');
var personChild = $('.czm-popup-person:nth-child(' + pn + ')', czmID);
personChild.prepend('');
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-avatar', czmID).prepend(settings.popup.persons[p].avatar.src).css('background', settings.popup.persons[p].avatar.backgroundColor);
if ((settings.popup.persons[p].text.title == false) || (settings.popup.persons[p].text.title == '') || (settings.popup.persons[p].text.title == undefined)) {
settings.popup.persons[p].text.title = 'Need Help?';
}
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-content', czmID).append('');
if ((settings.popup.persons[p].text.description !== false) && (settings.popup.persons[p].text.description !== '') && (settings.popup.persons[p].text.description !== undefined)) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-content', czmID).append('');
}
if (personOnline == true) {
if (settings.popup.persons[p].avatar.onlineCircle == true) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-avatar', czmID).append('');
}
if ((settings.popup.persons[p].text.online !== false) && (settings.popup.persons[p].text.online !== '') && (settings.popup.persons[p].text.online !== undefined)) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-content', czmID).append('');
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-online-offline-text', czmID).css('background', settings.popup.header.backgroundColor);
}
} else {
personChild.addClass('czm-popup-person-offline');
if ((settings.popup.persons[p].text.offline !== false) && (settings.popup.persons[p].text.offline !== '') && (settings.popup.persons[p].text.offline !== undefined)) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-content', czmID).append('');
}
}
if (settings.popup.persons.length == 1) {
$('.czm-popup', czmID).addClass('czm-popup-single');
$('.czm-popup-header', czmID).css('background', settings.popup.header.backgroundColor);
$('.czm-popup-header-title', czmID).remove();
$('.czm-popup-header-description', czmID).remove();
$('.czm-popup-person:nth-child(' + pn + ')', czmID).css('background', settings.popup.header.backgroundColor);
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-avatar', czmID).css('background', '#ffffff');
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-avatar i', czmID).css('color', settings.popup.header.backgroundColor);
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-person-online-offline-text', czmID).remove();
$('.czm-popup-person:nth-child(' + pn + ')', czmID).append('');
// Musbu branding
// $('.czm-popup-persons:nth-child(' + pn + ')', czmID).append('Powered by Musbu');
// Musbu branding
if (settings.popup.persons[p].text.message !== false) {
$('.czm-popup-person:nth-child(' + pn + ')', czmID).addClass('czm-popup-person-message');
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat', czmID).append('');
}
if (settings.popup.persons[p].text.textbox !== false) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat', czmID).append('');
if ((settings.popup.persons[p].link.desktop !== false) || (settings.popup.persons[p].link.mobile !== false)) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat-textbox i', czmID).click(function () {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if (settings.popup.persons[0].link.mobile !== false) {
personLink = settings.popup.persons[0].link.mobile;
} else {
personLink = settings.popup.persons[0].link.desktop;
}
} else {
personLink = settings.popup.persons[0].link.desktop;
}
if (settings.popup.persons[0].text.textbox !== false) {
if (personLink.search(/text/) != -1) {
personLink = personLink.split('text')[0];
}
personLink = personLink + 'text=' + $('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat-textbox input[type="text"]', czmID).val();
}
window.open(personLink, '_blank');
});
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat-textbox input[type="text"]', czmID).keyup(function (e) {
if (e.keyCode == 13) {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if (settings.popup.persons[0].link.mobile !== false) {
personLink = settings.popup.persons[0].link.mobile;
} else {
personLink = settings.popup.persons[0].link.desktop;
}
} else {
personLink = settings.popup.persons[0].link.desktop;
}
if (settings.popup.persons[0].text.textbox !== false) {
if (personLink.search(/text/) != -1) {
personLink = personLink.split('text')[0];
}
personLink = personLink + 'text=' + $('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat-textbox input[type="text"]', czmID).val();
}
window.open(personLink, '_blank');
}
});
}
} else {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat', czmID).append('');
$('.czm-popup-start-chat-button', czmID).css('background', settings.popup.header.backgroundColor);
if ((settings.popup.persons[p].link.desktop !== false) || (settings.popup.persons[p].link.mobile !== false)) {
$('.czm-popup-person:nth-child(' + pn + ') .czm-popup-start-chat-button', czmID).click(function () {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if (settings.popup.persons[0].link.mobile !== false) {
personLink = settings.popup.persons[0].link.mobile;
} else {
personLink = settings.popup.persons[0].link.desktop;
}
} else {
personLink = settings.popup.persons[0].link.desktop;
}
window.open(personLink, '_blank');
});
}
}
if (personOnline == false) {
$('.czm-popup', czmID).remove();
$('.czm-button', czmID).addClass('czm-button-offline');
if ((settings.button.text.offline !== false) && (settings.button.text.offline !== '') && (settings.button.text.offline !== undefined)) {
$('.czm-button-content-online-offline-text', czmID).html(settings.button.text.offline);
} else {
$('.czm-button-content-online-offline-text', czmID).remove();
}
buttonOnline = false;
}
} else {
if ((settings.popup.persons[p].link.desktop !== false) || (settings.popup.persons[p].link.mobile !== false)) {
personChild.click(function (e) {
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if (settings.popup.persons[e.currentTarget.dataset.id].link.mobile !== false) {
personLink = settings.popup.persons[e.currentTarget.dataset.id].link.mobile;
} else {
personLink = settings.popup.persons[e.currentTarget.dataset.id].link.desktop;
}
} else {
personLink = settings.popup.persons[e.currentTarget.dataset.id].link.desktop;
}
window.open(personLink, '_blank');
});
}
}
}
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** PULSE EFFECT **********/
if ((settings.button.pulseEffect == true) && (buttonOnline == true)) {
if (settings.button.style == 1) {
$('.czm-button', czmID).append('');
$('.czm-pulse', czmID).css('background', settings.button.backgroundColor);
}
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** NOTIFY **********/
if ((settings.button.notificationNumber !== false) && (buttonOnline == true)) {
$('.czm-button', czmID).append('');
setTimeout(function () {
$('.czm-notify-circle', czmID).addClass('czm-notify-circle-show czm-bounce').html(settings.button.notificationNumber);
setInterval(function () {
$('.czm-notify-circle', czmID).toggleClass('czm-bounce');
}, 2000);
}, 4000);
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** SPEECH BUBBLE **********/
if ((settings.button.speechBubble !== false) && (buttonOnline == true)) {
$(czmID).prepend('');
setTimeout(function () {
setTimeout(function () {
$('.czm-speech-bubble', czmID).addClass('czm-speech-bubble-show');
}, 1);
$('.czm-speech-bubble-text', czmID).html('');
setTimeout(function () {
$('.czm-speech-bubble-close', czmID).addClass('czm-speech-bubble-close-show');
$('.czm-speech-bubble-text', czmID).html(settings.button.speechBubble);
}, 3000);
}, 1000);
$('.czm-speech-bubble-close', czmID).click(function () {
$('.czm-speech-bubble', czmID).removeClass('czm-speech-bubble-show');
});
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** BU DOSYANIN TAM YOLU **********/
window.getRunningScript = () => {
return () => {
return new Error().stack.match(/([^ \n])*([a-z]*:\/\/\/?)*?[a-z0-9\/\\]*\.js/ig)[0]
}
}
var getCurrentScriptPath = function () {
var script = getRunningScript()();
var path = script.substring(0, script.lastIndexOf('/'));
return path + '/';
};
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** SOUND **********/
if ((settings.sound !== false) && (buttonOnline == true)) {
if ($('#czmSound').length > 0) {
$('#czmSound').remove();
}
setTimeout(function () {
if (settings.sound === true) {
settings.sound = getCurrentScriptPath() + 'assets/sound/notification.mp3';
}
$(czmID).append('');
if ($('#czmSound').length > 0) {
var czmSound = document.getElementById('czmSound');
if (czmSound !== undefined) {
czmSound.play();
czmSound.muted = false;
}
}
}, 4000);
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** CHANGE BROWSER TITLE **********/
if ((settings.changeBrowserTitle !== false) && (buttonOnline == true)) {
var faviconSelect = false;
if (document.querySelector('link[rel="shortcut icon"]') !== null) {
faviconSelect = 'shortcut icon';
} else if (document.querySelector('link[rel="icon"]') !== null) {
faviconSelect = 'icon';
}
var isOldTitle = true;
var changeTitle;
var oldTitle = $('title').text();
if (faviconSelect !== false) {
var oldFavicon = $('link[rel="' + faviconSelect + '"]').attr('href');
}
var newTitle = settings.changeBrowserTitle;
var newFavicon = getCurrentScriptPath() + 'assets/img/browser-title-number.png';
$(window).blur(function (e) {
$('title').text(newTitle);
if (faviconSelect !== false) {
$('link[rel="' + faviconSelect + '"]').attr('href', newFavicon);
}
changeTitle = setInterval(function () {
document.title = isOldTitle ? oldTitle : newTitle;
if (faviconSelect !== false) {
document.querySelector('link[rel="' + faviconSelect + '"]').href = isOldTitle ? oldFavicon : newFavicon;
}
isOldTitle = !isOldTitle;
}, 1000);
});
$(window).focus(function (e) {
clearInterval(changeTitle);
if (faviconSelect !== false) {
$('link[rel="' + faviconSelect + '"]').attr('href', oldFavicon);
}
$('title').text(oldTitle);
});
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** COOKIE **********/
if ((settings.cookie !== false) && (buttonOnline == true)) {
if (getCookie('czmChatSupport') !== 'true') {
setCookie('czmChatSupport', true, new Date(new Date().getTime() + (settings.cookie * 60) * 60 * 1000));
}
}
/**************************************************************************************************/
/**************************************************************************************************/
/**************************************************************************************************/
/********** FUNCTION **********/
function czmHide() {
$(czmID).toggleClass('czm-popup-show');
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
});
};
}(jQuery));