(function (window, document, GPTConfig) { var GPT = GPT || {}; GPTConfig.callbacksTemplate = function () { return { before: [], response: { success: [], error: [] }, ajax: { done: [], fail: [], always: [] } } }; GPT.Callbacks = { Chat: { addComment: GPTConfig.callbacksTemplate(), loadHistory: GPTConfig.callbacksTemplate(), } } GPT.Callbacks.add = function (path, name, func) { if (typeof func != 'function') { return false; } path = path.split('.'); var obj = GPT.Callbacks; for (var i = 0; i < path.length; i++) { if (obj[path[i]] == undefined) { return false; } obj = obj[path[i]]; } if (typeof obj != 'object') { obj = [obj]; } if (name != undefined) { obj[name] = func; } else { obj.push(func); } return true; } GPT.setup = function () { $ = jQuery; this.btn; this.$doc = $(document); this.$body = this.$doc.find('body'); this.ajaxProgress = false; this.response; this.container = '#gpt_container'; this.sendData = { $form: null, action: null, formData: null }; }; GPT.load = { config: {}, script: function (url, callback) { var script = document.createElement('script'); if (typeof callback !== 'undefined'){ if (script.readyState){ //IE script.onreadystatechange = function(){ if (script.readyState == 'loaded' || script.readyState == 'complete'){ script.onreadystatechange = null; callback(); } }; } else { //Others script.onload = function(){ callback(); }; } } script.src = url + '?v=' + GPT.Utils.uniqueid(); document.body.appendChild(script); }, style: function (url) { var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css' link.href = url + '?v=' + GPT.Utils.uniqueid(); document.getElementsByTagName('head')[0].appendChild(link); }, scripts: function () { this.isLoad = true; for (let library in this.config.scripts){ let libdata = this.config.scripts[library]; if (libdata.depend && typeof window[libdata.depend] === 'undefined') continue; let check = typeof (libdata.depend === 'jQuery' ? jQuery.fn[library] : window[library]); if (check === 'undefined'){ this.isLoad = false; if (libdata.loading !== true) { libdata.loading = true; if (libdata.style) this.style(libdata.style); this.script(libdata.url); } } } if (this.isLoad){ GPT.Initialize.config(); } else { setTimeout(function() { GPT.load.scripts(); }, 50); } }, styles: function () { for (let library in this.config.styles){ this.style(this.config.styles[library]); } }, svg: function (url, event) { GPT.Loader.create(); var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status !== 200) console.error(xhr.statusText); GPT.loadData = xhr.responseXML.querySelector('svg').outerHTML; if (event) event(); GPT.Loader.destroy(); } }; xhr.onerror = function (e) { GPT.Message.log(xhr.statusText); }; xhr.send(null); }, } GPT.Event = { list: {}, on: function (event, func) { this.list[event] = func; }, start: function (name) { if (this.list[name] && typeof this.list[name] === 'function') this.list[name](); }, } GPT.Initialize = { events: {}, load: function () { GPT.load.scripts(); GPT.load.styles(); }, config: function () { GPT.setup(); var callbacks = GPTConfig.callbacksTemplate(); callbacks.response.success = function (response) { if (response.data.timeout) GPT.Push.config.timeout = response.data.timeout; if (response.data.message) GPT.Push.config.message = response.data.message; if (response.data.push_type) GPT.Push.config.type = response.data.push_type; if (response.data.tooltips) GPT.Chat.config.tooltips = response.data.tooltips; GPT.Initialize.start(); } GPT.Request.toSystem({ url: document.URL, action: 'getConfig', }, callbacks); if (GPT.Chat.reaction) { for (let i in GPT.Chat.reaction){ var item = GPT.Chat.reaction[i]; if (!item.src) continue; GPT.Utils.preLoadVideo(item); } } }, start: function () { GPT.Chat.initialize(); GPT.Push.initialize(); }, } GPT.Chat = { config: { moduleId: 'gpt', limitChars: 2000, timeLimit: 30, action: '', type: 'popup', resize: true, }, initialize: function () { if (this.module) return; this.setSession(); if (GPTConfig.container && $(GPTConfig.container).length) { this.module = $(GPTConfig.container); this.config.type = 'inline'; this.config.resize = false; } else { this.module = $('
').html(t.text) .on('click', (e) => this.addTooltip(t.text, e.target, t.file)) .appendTo(this.tplWrap); }); } this.form = $('