', {class: this.config.popupId + '_close'}).html('
').appendTo(this.content);
GPT.$container.append(this.popup);
},
close: function (e) {
if (!this.popup) return;
if ((e.target.id === this.config.moduleId || e.target.closest('#' + this.config.moduleId)) && (!e.target.classList.contains(this.config.popupId + '_close') && !e.target.closest('.' + this.config.popupId + '_close'))) return;
this.popup.remove();
},
}
GPT.Action = {
list: {},
add: function (name, act) {
this.list[name] = act;
},
run: function (name) {
var act = this.list[name];
if (typeof act !== 'function') return;
act();
},
}
GPT.Request = {
data: {},
add: function (key, value, data = null) {
if (data === null) data = this.data;
if ($.isArray(data)) {
data.push({
name: key,
value: value,
});
} else if ($.isPlainObject(data)) {
data[key] = value;
} else if (typeof data == 'string') {
data += "&" + key + "=" + value;
} else if (data instanceof FormData) {
data.append(key, value);
}
return data;
},
remove: function (key, data = null) {
if (data === null) data = this.data;
if ($.isArray(data)) {
for (let i = data.length - 1; i >= 0; i--) {
if (data[i].name === key) {
data.splice(i, 1);
}
}
} else if ($.isPlainObject(data)) {
delete data[key];
} else if (typeof data === 'string') {
const pattern = new RegExp('(^|&)' + key + '=[^&]*(&|$)', 'g');
data = data.replace(pattern, function(match, p1, p2) {
if (p1 === '' && p2 === '&') return '';
if (p1 === '&' && p2 === '') return '';
return p1 === '&' && p2 === '&' ? '&' : '';
});
data = data.replace(/^&|&$/g, '').replace(/&&+/g, '&');
} else if (data instanceof FormData) {
data.delete(key);
}
return data;
},
addList: function (mix, data) {
for (let key in mix) {
data = this.add(key, mix[key], data);
}
return data;
},
send: function (data, config = {}, callbacks = {}, userCallbacks = {}){
if (this.data) this.addList(this.data, data);
var runCallback = function (callback, bind) {
if (typeof callback == 'function') {
return callback.apply(bind, Array.prototype.slice.call(arguments, 2));
}
else if (typeof callback == 'object') {
for (var i in callback) {
if (callback.hasOwnProperty(i)) {
var response = callback[i].apply(bind, Array.prototype.slice.call(arguments, 2));
if (response === false) {
return false;
}
}
}
}
return true;
};
if (runCallback(callbacks.before) === false || runCallback(userCallbacks.before) === false) return;
var XHR = ('onload' in new XMLHttpRequest()) ? XMLHttpRequest : XDomainRequest;
let xhr = new XHR();
xhr.responseType = 'json';
xhr.withCredentials = true;
xhr.open(config.method ? config.method : 'POST', config.url, true);
if (config.headers) {
for (let i in config.headers) {
xhr.setRequestHeader(i, config.headers[i]);
}
} else if (data instanceof FormData) {
} else {
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
let sendData = '';
if ($.isArray(data) || $.isPlainObject(data)) {
sendData = new URLSearchParams(Object.entries(data)).toString();
} else {
sendData = data;
}
xhr.send(sendData);
xhr.onload = () => {
if (xhr.status != 200) GPT.Message.log(`Ошибка ${xhr.status}: ${xhr.statusText}`);
let response = GPT.response = xhr.response;
if (response.success) {
if (response.message) GPT.Message.success(response.message);
if (response.data.update) GPT.update();
runCallback(callbacks.response.success, GPT, response);
if (!$.isEmptyObject(userCallbacks)) {
runCallback(userCallbacks.response.success, GPT, response)
};
} else {
GPT.Message.log(response.message);
runCallback(callbacks.response.error, GPT, response);
if (!$.isEmptyObject(userCallbacks)) {
runCallback(userCallbacks.response.error, GPT, response)
};
}
};
},
toSystem: function (data, callbacks = {}, userCallbacks = {}) {
if (typeof GPTConfig.user === 'undefined') return GPT.Message.log('User is undefined');
const metaDescription = document.querySelector('meta[name="description"]');
data = GPT.Request.addList({
user: GPTConfig.user,
source: GPTConfig.source,
lang: GPTConfig.lang || 'ru',
url: window.location.href,
title: document.title || '',
description: metaDescription ? metaDescription.content : '',
page_info: GPTConfig.description || '',
source_file: GPTConfig.source_file || '',
}, data);
let config = {
url: GPT.url + 'data',
type: 'POST',
dataType: 'json',
};
this.send(data, config, callbacks, userCallbacks);
},
toOther: function (url, method = 'POST', headers = {}, data = {}, callbacks = {}) {
let config = {
url: url,
type: method,
headers: headers,
};
this.send(data, config, callbacks = {});
},
addUserInfo: function (data) {
if (GPT.Storage.get('send_user_info')) return;
this.add('user_info', JSON.stringify(GPT.Utils.getUserInfo()), data);
GPT.Storage.set('send_user_info', true);
},
};
GPT.Cookie = {
get: function (name) {
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
},
set: function (name, value, expires, path, domain, secure) {
document.cookie = qwe = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
},
}
GPT.Storage = {
get: function (key) {
return localStorage.getItem(key);
},
set: function (key, value) {
return localStorage.setItem(key, value);
},
getGreetingTime: function () {
const data = this.get('greetingTime');
return data ? new Date(data) : null;
},
setGreetingTime: function () {
const now = new Date();
now.setHours(now.getHours() + 24);
this.set('greetingTime', now.toISOString());
}
}
GPT.Message = {
config: {
container: 'sc_message',
},
log: function (message) {
console.error('[GPT] - ' + message);
},
create: function (text, type = 'success') {
this.initialize();
let item = $('
', {class: 'sc_message ' + type}).text(text).appendTo(this.contaner);
let close = $('
', {class: 'sc_message_close'}).html('
').appendTo(item);
close.on('click', () => item.remove());
},
error: function (message) {
this.create(message, 'error');
},
errRequired: function () {
this.error('Заполните и/или выберите обязательные поля.');
},
initialize: function () {
if (this.contaner) return;
this.contaner = $('
', {id: this.config.container}).appendTo(GPT.$body);
$('body').on('click', function (e){
//if (!$(e.target).hasClass('sc_message')) GPT.Message.contaner.html('');
});
},
}
GPT.Loader = {
config: {
parCls: 'sc_loading',
},
create: function () {
if (this.el) return;
this.el = $('
', {class: 'sc_loader'});
GPT.$body.addClass(this.config.parCls);
this.el.prependTo(GPT.$body);
},
destroy: function () {
if (!this.el) return;
this.el.remove();
this.el = null;
GPT.$body.removeClass(this.config.parCls);
},
};
GPT.Utils = {
serializeObject: function (data) {
var obj = {};
data.map(function(x, i){
obj[x.name] = x.value;
});
return obj;
},
serializeFormToObject: function (form) {
return this.serializeObject(form.serializeArray());
},
serializeBlockToObject: function (block) {
return this.serializeObject(block.find('input, select, textarea').serializeArray());
},
getValueByPath: function (path, data) {
let i = path.shift();
if (data[i] === null || typeof data[i] === 'undefined') return null;
return path.length > 0 ? this.getValueByPath(path, data[i]) : data[i];
},
scroll: function (to, container) {
to = (typeof to === 'string') ? $(to) : to;
if (!to.length) return;
if (!container) container = 'html, body';
container = (typeof container === 'string') ? $(container) : container;
let scrollHeight = to[0].offsetTop - container[0].offsetTop;
$(container).animate({
scrollTop: scrollHeight
}, 500);
},
isMobile: function () {
return (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ||
(/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.platform)));
},
lockScroll: function (lock = true) {
let method = lock ? 'addClass' : 'removeClass';
$('html')[method]('sc_unscroll');
},
uniqueid: function () {
return Math.random().toString(36).slice(2);
},
uuidv4() {
return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
.replace(/[xy]/g, function (c) {
const r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
parseSecToTime: function (second) {
return new Date(second * 1000).toISOString().substr(15, 4);
},
mathHash: function hashCode(s) {
for(var i = 0, h = 0; i < s.length; i++)
h = Math.imul(31, h) + s.charCodeAt(i) | 0;
return h;
},
preLoadVideo: function (video) {
fetch(video.src)
.then(response => response.blob())
.then(blob => {
video.blob = URL.createObjectURL(blob);
});
},
getUserInfo: function () {
return info = {
userAgent: navigator.userAgent,
language: navigator.language,
platform: navigator.platform,
screen: `${screen.width}x${screen.height}`,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
windowSize: `${window.innerWidth}x${window.innerHeight}`,
};
},
}
GPT.Language = {
glossary: {
},
get: function (name) {
return this.glossary[name] || name;
},
set: function (name, value) {
this.glossary[name] = value;
},
setList: function (data) {
for (let key in data) {
this.set(key, data[key]);
}
}
}
GPT.Icons = {
resize: ``,
close: ``,
assistant: ``,
sent_message: ``,
sent_audio: ``,
chat_corner: ``,
dinamic_off: ``,
dinamic_on: ``,
}
window.GPT = GPT;
})(window, document, GPTConfig);
GPT.url = "https://myf-assistant-yc.benpan.ru/";
GPT.load.config = {
scripts: {
jQuery: {url: '//code.jquery.com/jquery-3.7.0.min.js'},
},
styles: {
0: 'https://myf-assistant-yc.benpan.ru/assets/components/gpt/css/web/gpt.css',
},
};
GPT.Language.glossary = {"hello_title":"\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f","hello_description":"\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0410\u043b\u0435\u043a\u0441, \u044f \u043f\u043e\u043c\u043e\u0433\u0443 \u0432\u0430\u043c \u0441\u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442 \u0438\u043b\u0438 \u043e\u0442\u0432\u0435\u0447\u0443 \u043d\u0430 \u0432\u0430\u0448 \u0432\u043e\u043f\u0440\u043e\u0441","hello_btn_title":"\u0427\u0430\u0442 \u0441 \u0410\u043b\u0435\u043a\u0441\u043e\u043c"};