@chat21/chat21-web-widget 5.0.53-rc.3 → 5.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/app/utils/globals.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class Globals {
|
|
|
24
24
|
obsIsOpen = new BehaviorSubject<boolean>(null);
|
|
25
25
|
|
|
26
26
|
BASE_LOCATION = 'https://widget.tiledesk.com/v2';
|
|
27
|
-
POWERED_BY ='<a tabindex="-1" target="_blank" href="http://www.tiledesk.com
|
|
27
|
+
POWERED_BY ='<a tabindex="-1" target="_blank" href="http://www.tiledesk.com/?utm_source=widget"><img src="https://support-pre.tiledesk.com/dashboard/assets/img/logos/tiledesk-logo_new_gray.svg"/></a>'
|
|
28
28
|
DEFAULT_LOGO_CHAT = '/assets/images/tiledesk_logo_white_small.svg';
|
|
29
29
|
WIDGET_TITLE = 'Tiledesk';
|
|
30
30
|
|
|
@@ -298,11 +298,6 @@
|
|
|
298
298
|
setTimeout(() => {
|
|
299
299
|
document.getElementById("preloader").style.display = "none";
|
|
300
300
|
if(event_data && event_data.detail && event_data.detail.appConfigs){
|
|
301
|
-
|
|
302
|
-
var enbedJs = event_data.detail.appConfigs.enbedJs? event_data.detail.appConfigs.enbedJs : false;
|
|
303
|
-
document.getElementById("enbed").style.display = enbedJs? "inline-block": "none";
|
|
304
|
-
document.getElementById("base_url").innerHTML = enbedJs ? baseUrl + '/launch.js': null;
|
|
305
|
-
|
|
306
301
|
baseUrlConsole = event_data.detail.appConfigs.dashboardUrl? event_data.detail.appConfigs.dashboardUrl : baseUrlConsole;
|
|
307
302
|
}
|
|
308
303
|
}, 1000);
|
|
@@ -437,7 +437,7 @@
|
|
|
437
437
|
|
|
438
438
|
var enbedJs = event_data.detail.appConfigs.enbedJs? event_data.detail.appConfigs.enbedJs : false;
|
|
439
439
|
document.getElementById("enbed").style.display = enbedJs? "inline-block": "none";
|
|
440
|
-
document.getElementById("base_url").innerHTML = enbedJs ?
|
|
440
|
+
document.getElementById("base_url").innerHTML = enbedJs ? window.tiledesk.getBaseLocation() + '/launch.js': null;
|
|
441
441
|
|
|
442
442
|
baseUrlConsole = event_data.detail.appConfigs.dashboardUrl? event_data.detail.appConfigs.dashboardUrl : baseUrlConsole;
|
|
443
443
|
}
|
|
@@ -282,7 +282,7 @@
|
|
|
282
282
|
|
|
283
283
|
var enbedJs = event_data.detail.appConfigs.enbedJs? event_data.detail.appConfigs.enbedJs : false;
|
|
284
284
|
document.getElementById("enbed").style.display = enbedJs? "inline-block": "none";
|
|
285
|
-
document.getElementById("base_url").innerHTML = enbedJs ?
|
|
285
|
+
document.getElementById("base_url").innerHTML = enbedJs ? window.tiledesk.getBaseLocation() + '/launch.js': null;
|
|
286
286
|
|
|
287
287
|
baseUrlConsole = event_data.detail.appConfigs.dashboardUrl? event_data.detail.appConfigs.dashboardUrl : baseUrlConsole;
|
|
288
288
|
}
|
package/src/launch_old.js
DELETED
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
/** */
|
|
2
|
-
ready(function() {
|
|
3
|
-
// console.log('DOM is ready, call initWidget');
|
|
4
|
-
if(!window.tileDeskAsyncInit){
|
|
5
|
-
initAysncEvents();
|
|
6
|
-
}
|
|
7
|
-
initWidget();
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
/** */
|
|
11
|
-
function ready(callbackFunction){
|
|
12
|
-
if(document.readyState != 'loading')
|
|
13
|
-
callbackFunction()
|
|
14
|
-
else
|
|
15
|
-
document.addEventListener("DOMContentLoaded", callbackFunction)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/** */
|
|
20
|
-
function loadIframe(tiledeskScriptBaseLocation) {
|
|
21
|
-
var dev = window.location.hostname.includes('localhost')? true: false;
|
|
22
|
-
|
|
23
|
-
var containerDiv = document.createElement('div');
|
|
24
|
-
containerDiv.setAttribute('id','tiledesk-container');
|
|
25
|
-
containerDiv.classList.add("closed");
|
|
26
|
-
document.body.appendChild(containerDiv);
|
|
27
|
-
|
|
28
|
-
var iDiv = document.createElement('div');
|
|
29
|
-
iDiv.setAttribute('id','tiledeskdiv');
|
|
30
|
-
containerDiv.appendChild(iDiv);
|
|
31
|
-
|
|
32
|
-
var ifrm = document.createElement("iframe");
|
|
33
|
-
ifrm.setAttribute("frameborder", "0");
|
|
34
|
-
ifrm.setAttribute("border", "0");
|
|
35
|
-
ifrm.setAttribute("title", "Tiledesk Widget")
|
|
36
|
-
|
|
37
|
-
var srcTileDesk = '<html lang="en">';
|
|
38
|
-
srcTileDesk += '<head>';
|
|
39
|
-
srcTileDesk += '<meta charset="utf-8">';
|
|
40
|
-
srcTileDesk += '<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />';
|
|
41
|
-
srcTileDesk += '<title>Tilechat Widget</title>';
|
|
42
|
-
srcTileDesk += '<base href="./">';
|
|
43
|
-
srcTileDesk += '<link rel="icon" type="image/x-icon" href="favicon.ico">';
|
|
44
|
-
srcTileDesk += '<link rel="stylesheet" type="text/css" href="' + tiledeskScriptBaseLocation +'/assets/styles/tiledesk_v1.scss" media="all">';
|
|
45
|
-
srcTileDesk += '</head>';
|
|
46
|
-
srcTileDesk += '<body>';
|
|
47
|
-
srcTileDesk += '<chat-root></chat-root>';
|
|
48
|
-
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/runtime.js"></script>';
|
|
49
|
-
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/polyfills.js"></script>';
|
|
50
|
-
srcTileDesk += '<link type="text/css" rel="stylesheet" href="'+tiledeskScriptBaseLocation+'/styles.css" media="all"></link>';
|
|
51
|
-
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/vendor.js"></script>';
|
|
52
|
-
srcTileDesk += '<script type="text/javascript" src="'+tiledeskScriptBaseLocation+'/main.js"></script>';
|
|
53
|
-
srcTileDesk += '</body>';
|
|
54
|
-
srcTileDesk += '</html>';
|
|
55
|
-
|
|
56
|
-
ifrm.setAttribute('id','tiledeskiframe');
|
|
57
|
-
ifrm.setAttribute('tiledesk_context','parent');
|
|
58
|
-
|
|
59
|
-
/** */
|
|
60
|
-
window.tiledesk.on('onInit', function(event_data) {
|
|
61
|
-
// console.log("launch onInit isopen", tiledeskScriptBaseLocation, window.tiledesk.angularcomponent.component.g.isOpen);
|
|
62
|
-
if (window.tiledesk.angularcomponent.component.g.isOpen) {
|
|
63
|
-
containerDiv.classList.add("open");
|
|
64
|
-
containerDiv.classList.remove("closed");
|
|
65
|
-
iDiv.classList.remove("callout");
|
|
66
|
-
} else {
|
|
67
|
-
containerDiv.classList.add("closed");
|
|
68
|
-
containerDiv.classList.remove("open");
|
|
69
|
-
iDiv.classList.remove("messagePreview");
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
/** */
|
|
73
|
-
window.tiledesk.on('onOpen', function(event_data) {
|
|
74
|
-
containerDiv.classList.add("open");
|
|
75
|
-
containerDiv.classList.remove("closed");
|
|
76
|
-
iDiv.classList.remove("callout");
|
|
77
|
-
iDiv.classList.remove("messagePreview");
|
|
78
|
-
});
|
|
79
|
-
/** */
|
|
80
|
-
window.tiledesk.on('onClose', function(event_data) {
|
|
81
|
-
containerDiv.classList.add("closed");
|
|
82
|
-
containerDiv.classList.remove("open");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
/** */
|
|
86
|
-
window.tiledesk.on('onOpenEyeCatcher', function(event_data) {
|
|
87
|
-
iDiv.classList.add("callout");
|
|
88
|
-
});
|
|
89
|
-
/** */
|
|
90
|
-
window.tiledesk.on('onClosedEyeCatcher', function(event_data) {
|
|
91
|
-
iDiv.classList.remove("callout");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
/** */
|
|
95
|
-
window.tiledesk.on('onConversationUpdated', function(event_data) {
|
|
96
|
-
const messagePreview = window.tiledesk.angularcomponent.component.g.isOpenNewMessage
|
|
97
|
-
const isOpen = window.tiledesk.angularcomponent.component.g.isOpen
|
|
98
|
-
try {
|
|
99
|
-
if (!isOpen && messagePreview) {
|
|
100
|
-
iDiv.classList.add("messagePreview");
|
|
101
|
-
iDiv.classList.remove("callout");
|
|
102
|
-
// ----------------------------//
|
|
103
|
-
}
|
|
104
|
-
} catch(er) {
|
|
105
|
-
console.error("onConversationUpdated > error: " + er);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
window.tiledesk.on('onCloseMessagePreview', function(event_data) {
|
|
110
|
-
try {
|
|
111
|
-
iDiv.classList.remove("messagePreview");
|
|
112
|
-
} catch(er) {
|
|
113
|
-
console.error("onCloseMessagePreview > error: " + er);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
/**** BEGIN EVENST ****/
|
|
119
|
-
/** */
|
|
120
|
-
window.tiledesk.on('onNewConversation', function(event_data) {
|
|
121
|
-
// console.log("test-custom-auth.html onNewConversation >>>",event_data);
|
|
122
|
-
const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
|
|
123
|
-
// console.log(">>>> tiledeskToken >>>> ",event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid);
|
|
124
|
-
if(tiledeskToken) {
|
|
125
|
-
var httpRequest = createCORSRequest('POST', event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid+'/events',true); //set async to false because loadParams must return when the get is complete
|
|
126
|
-
httpRequest.setRequestHeader('Content-type', 'application/json');
|
|
127
|
-
httpRequest.setRequestHeader('Authorization',tiledeskToken);
|
|
128
|
-
httpRequest.send(JSON.stringify({"name":"new_conversation","attributes": {"request_id":event_data.detail.newConvId, "department": event_data.detail.global.departmentSelected.id, "participants": event_data.detail.global.participants, "language": event_data.detail.global.lang, "subtype":"info", "fullname":event_data.detail.global.attributes.userFullname, "email":event_data.detail.global.attributes.userEmail, "attributes":event_data.detail.global.attributes}}));
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
/** @deprecated event */
|
|
133
|
-
window.tiledesk.on('onLoggedIn', function(event_data) {
|
|
134
|
-
// console.log("test-custom-auth.html onLoggedIn",event_data);
|
|
135
|
-
const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
|
|
136
|
-
// console.log("------------------->>>> tiledeskToken: ",window.tiledesk.angularcomponent.component.g);
|
|
137
|
-
if(tiledeskToken) {
|
|
138
|
-
var httpRequest = createCORSRequest('POST', event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid+'/events',true); //set async to false because loadParams must return when the get is complete
|
|
139
|
-
httpRequest.setRequestHeader('Content-type','application/json');
|
|
140
|
-
httpRequest.setRequestHeader('Authorization',tiledeskToken);
|
|
141
|
-
httpRequest.send(JSON.stringify({"name":"logged_in","attributes": {"fullname":event_data.detail.global.attributes.userFullname, "email":event_data.detail.global.attributes.userEmail, "language": event_data.detail.global.lang, "attributes":event_data.detail.global.attributes}}));
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
/** */
|
|
146
|
-
window.tiledesk.on('onAuthStateChanged', function(event_data) {
|
|
147
|
-
// console.log("test-custom-auth.html onAuthStateChanged",event_data);
|
|
148
|
-
const tiledeskToken = window.tiledesk.angularcomponent.component.g.tiledeskToken;
|
|
149
|
-
// console.log("------------------->>>> tiledeskToken: ",window.tiledesk.angularcomponent.component.g);
|
|
150
|
-
if(tiledeskToken) {
|
|
151
|
-
var httpRequest = createCORSRequest('POST', event_data.detail.appConfigs.apiUrl+event_data.detail.default_settings.projectid+'/events',true); //set async to false because loadParams must return when the get is complete
|
|
152
|
-
httpRequest.setRequestHeader('Content-type','application/json');
|
|
153
|
-
httpRequest.setRequestHeader('Authorization',tiledeskToken);
|
|
154
|
-
httpRequest.send(JSON.stringify({"name":"auth_state_changed","attributes": {"user_id":event_data.detail.global.senderId, "isLogged":event_data.detail.global.isLogged, "event":event_data.detail.event, "subtype":"info", "fullname":event_data.detail.global.attributes.userFullname, "email":event_data.detail.global.attributes.userEmail, "language":event_data.detail.global.lang, "attributes":event_data.detail.global.attributes}}));
|
|
155
|
-
httpRequest.onload = function(event) {
|
|
156
|
-
if(event.target && event.target.status === 401){
|
|
157
|
-
window.tiledesk.hide()
|
|
158
|
-
window.tiledesk.dispose()
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
/**** END EVENST ****/
|
|
164
|
-
|
|
165
|
-
iDiv.appendChild(ifrm);
|
|
166
|
-
|
|
167
|
-
if(tiledeskScriptBaseLocation.includes('localhost')){
|
|
168
|
-
// ifrm.src = tiledeskScriptBaseLocation + '/base_script.html'
|
|
169
|
-
// buildIframeDOM(ifrm, tiledeskScriptBaseLocation)
|
|
170
|
-
ifrm.contentWindow.document.open();
|
|
171
|
-
ifrm.contentWindow.document.write(srcTileDesk);
|
|
172
|
-
ifrm.contentWindow.document.close();
|
|
173
|
-
}else {
|
|
174
|
-
ifrm.srcdoc = srcTileDesk
|
|
175
|
-
}
|
|
176
|
-
// ifrm.onload = function(ev){
|
|
177
|
-
// const obj = {tiledeskSettings: window.tiledeskSettings}
|
|
178
|
-
// ifrm.contentWindow.postMessage(obj, "*")
|
|
179
|
-
// console.log('iframe contentwindowwww', ifrm.contentWindow)
|
|
180
|
-
// // ifrm.contentWindow.tiledesk = window.tiledesk
|
|
181
|
-
// }
|
|
182
|
-
// ifrm.innerHTML = srcTileDesk
|
|
183
|
-
// ifrm.contentWindow.document.open();
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function buildIframeDOM(iframe, tiledeskScriptBaseLocation){
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var Idocument = iframe.contentDocument
|
|
193
|
-
console.log('iframeeee', Idocument)
|
|
194
|
-
var meta = Idocument.createElement('meta');
|
|
195
|
-
meta.setAttribute('charset', 'utf-8')
|
|
196
|
-
var meta_2 = Idocument.createElement('meta')
|
|
197
|
-
meta_2.setAttribute('name', 'viewport')
|
|
198
|
-
meta_2.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0')
|
|
199
|
-
var title = Idocument.createElement('title')
|
|
200
|
-
title.title = 'Tilechat Widget'
|
|
201
|
-
var base = Idocument.createElement('base')
|
|
202
|
-
base.setAttribute('href', './')
|
|
203
|
-
var link_1 = Idocument.createElement('link')
|
|
204
|
-
link_1.setAttribute('rel', 'icon')
|
|
205
|
-
link_1.setAttribute('type', 'image/x-icon')
|
|
206
|
-
link_1.setAttribute('href', 'favicon.ico')
|
|
207
|
-
var link_2 = Idocument.createElement('link')
|
|
208
|
-
link_2.setAttribute('rel', 'stylesheet')
|
|
209
|
-
link_2.setAttribute('type', 'text/css')
|
|
210
|
-
link_2.setAttribute('href', tiledeskScriptBaseLocation + '/assets/styles/tiledesk_v1.scss')
|
|
211
|
-
link_2.setAttribute('media','all')
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
let head = Idocument.getElementsByTagName('head')[0]
|
|
215
|
-
head.appendChild(meta)
|
|
216
|
-
head.appendChild(meta_2)
|
|
217
|
-
head.appendChild(title)
|
|
218
|
-
head.appendChild(base)
|
|
219
|
-
head.appendChild(link_1)
|
|
220
|
-
head.appendChild(link_2)
|
|
221
|
-
|
|
222
|
-
var script_1 = Idocument.createElement('script')
|
|
223
|
-
script_1.setAttribute('type','text/javascript')
|
|
224
|
-
script_1.setAttribute('src',tiledeskScriptBaseLocation + '/runtime.js')
|
|
225
|
-
var script_2 = Idocument.createElement('script')
|
|
226
|
-
script_2.setAttribute('type','text/javascript')
|
|
227
|
-
script_2.setAttribute('src',tiledeskScriptBaseLocation + '/polyfills.js')
|
|
228
|
-
var link = Idocument.createElement('link')
|
|
229
|
-
link.setAttribute('type','text/css')
|
|
230
|
-
link.setAttribute('rel','stylesheet')
|
|
231
|
-
link.setAttribute('href',tiledeskScriptBaseLocation + '/styles.css')
|
|
232
|
-
link.setAttribute('media','all')
|
|
233
|
-
var script_4 = Idocument.createElement('script')
|
|
234
|
-
script_4.setAttribute('type','text/javascript')
|
|
235
|
-
script_4.setAttribute('src',tiledeskScriptBaseLocation + '/vendor.js')
|
|
236
|
-
var script_5 = Idocument.createElement('script')
|
|
237
|
-
script_5.setAttribute('type','text/javascript')
|
|
238
|
-
script_5.setAttribute('src',tiledeskScriptBaseLocation + '/main.js')
|
|
239
|
-
|
|
240
|
-
let body= Idocument.getElementsByTagName('body')[0]
|
|
241
|
-
body.appendChild(Idocument.createElement('chat-root'))
|
|
242
|
-
body.appendChild(script_1)
|
|
243
|
-
body.appendChild(script_2)
|
|
244
|
-
body.appendChild(link)
|
|
245
|
-
body.appendChild(script_4)
|
|
246
|
-
body.appendChild(script_5)
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
function initAysncEvents() {
|
|
251
|
-
console.log('INIT ASYNC EVENTS')
|
|
252
|
-
|
|
253
|
-
window.tileDeskAsyncInit = function() {
|
|
254
|
-
// console.log('launch tiledeskAsyncInit:::', window.Tiledesk.q)
|
|
255
|
-
window.tiledesk.on('onLoadParams', function(event_data) {
|
|
256
|
-
if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
|
|
257
|
-
window.Tiledesk.q.forEach(f => {
|
|
258
|
-
if (f.length>=1) {
|
|
259
|
-
var functionName = f[0];
|
|
260
|
-
if (functionName==="onLoadParams") {
|
|
261
|
-
//CALLING ONLY FUNCTION 'onLoadParams'
|
|
262
|
-
if (f.length==2) {
|
|
263
|
-
var functionCallback = f[1];
|
|
264
|
-
if(typeof functionCallback === "function") {
|
|
265
|
-
window.tiledesk.on(functionName, functionCallback);
|
|
266
|
-
functionCallback(event_data);
|
|
267
|
-
} else {
|
|
268
|
-
console.error("initAysncEvents --> functionCallback is not a function.");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}else if(functionName=='setParameter'){
|
|
272
|
-
//CALLING ONLY METHOD 'setParameter' AND CHECK IF IT HAS OBJECT ARG
|
|
273
|
-
if (f.length==2) {
|
|
274
|
-
var functionArgs = f[1];
|
|
275
|
-
if(typeof functionArgs === "object") {
|
|
276
|
-
window.tiledesk[functionName](functionArgs);
|
|
277
|
-
} else {
|
|
278
|
-
console.error("initAysncEvents --> functionArgs is not a object.");
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
window.tiledesk.on('onBeforeInit', function(event_data) {
|
|
288
|
-
if (window.Tiledesk && window.Tiledesk.q && window.Tiledesk.q.length>0) {
|
|
289
|
-
// console.log("w.q", window.Tiledesk.q);
|
|
290
|
-
window.Tiledesk.q.forEach(f => {
|
|
291
|
-
if (f.length>=1) {
|
|
292
|
-
var functionName = f[0];
|
|
293
|
-
if (functionName==="onLoadParams" || functionName==="setParameter") {
|
|
294
|
-
//SKIP FUNCTION WITH NAMES 'onLoadParams' AND METHOD 'setParameter'
|
|
295
|
-
} else if (functionName.startsWith("on")) {
|
|
296
|
-
// CALLING METHOD THAT STARTS WITH 'on'
|
|
297
|
-
if (f.length==2) {
|
|
298
|
-
var functionCallback = f[1];
|
|
299
|
-
if(typeof functionCallback === "function"){
|
|
300
|
-
window.tiledesk.on(functionName, functionCallback); //potrei usare window.Tiledesk ?!?
|
|
301
|
-
if (functionName==="onBeforeInit") {
|
|
302
|
-
functionCallback(event_data)
|
|
303
|
-
}
|
|
304
|
-
} else {
|
|
305
|
-
console.error("functionCallback is not a function.");
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
} else {
|
|
309
|
-
//CALLING REMAININGS METHOD and CHECK IF CONTAINS ARG TO PASS THROUGH THE METHOD
|
|
310
|
-
if (f.length==2) {
|
|
311
|
-
let args = f[1]
|
|
312
|
-
window.tiledesk[functionName](args);
|
|
313
|
-
} else {
|
|
314
|
-
window.tiledesk[functionName]();
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// RICHIAMATO DOPO L'INIT DEL WIDGET
|
|
324
|
-
window.Tiledesk = function() {
|
|
325
|
-
if (arguments.length>=1) {
|
|
326
|
-
var functionName = arguments[0];
|
|
327
|
-
if (arguments.length==2) {
|
|
328
|
-
var functionCallback = arguments[1];
|
|
329
|
-
}
|
|
330
|
-
var methodOrProperty = window.tiledesk[functionName];
|
|
331
|
-
if(typeof methodOrProperty==="function"){
|
|
332
|
-
return window.tiledesk[functionName](functionCallback);
|
|
333
|
-
}else { //property
|
|
334
|
-
return window.tiledesk[functionName];
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
*
|
|
346
|
-
*/
|
|
347
|
-
function initWidget() {
|
|
348
|
-
var tiledeskroot = document.createElement('chat-root');
|
|
349
|
-
var tiledeskScriptLocation = document.getElementById("tiledesk-jssdk").src;
|
|
350
|
-
//var currentScript = document.currentScript;
|
|
351
|
-
//var tiledeskScriptLocation = '';
|
|
352
|
-
//setInterval(function(){
|
|
353
|
-
//tiledeskScriptLocation = currentScript.src;
|
|
354
|
-
var tiledeskScriptBaseLocation = tiledeskScriptLocation.replace("/launch.js","");
|
|
355
|
-
window.tiledesk = new function() {
|
|
356
|
-
//this.type = "macintosh";
|
|
357
|
-
this.tiledeskroot = tiledeskroot;
|
|
358
|
-
this.on = function (event_name, handler) {
|
|
359
|
-
tiledeskroot.addEventListener(event_name, handler);
|
|
360
|
-
};
|
|
361
|
-
this.getBaseLocation = function() {
|
|
362
|
-
return tiledeskScriptBaseLocation;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
try {
|
|
367
|
-
window.tileDeskAsyncInit();
|
|
368
|
-
}catch(er) {
|
|
369
|
-
if (typeof window.tileDeskAsyncInit == "undefined") {
|
|
370
|
-
console.log("tileDeskAsyncInit() doesn't exists");
|
|
371
|
-
} else {
|
|
372
|
-
console.log(er);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
document.body.appendChild(tiledeskroot);
|
|
376
|
-
initCSSWidget(tiledeskScriptBaseLocation);
|
|
377
|
-
loadIframe(tiledeskScriptBaseLocation);
|
|
378
|
-
//},2000);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
function initCSSWidget(tiledeskScriptBaseLocation) {
|
|
386
|
-
var cssId = 'iframeCss'; // you could encode the css path itself to generate id..
|
|
387
|
-
// if (!document.getElementById(cssId))
|
|
388
|
-
// {
|
|
389
|
-
var head = document.getElementsByTagName('head')[0];
|
|
390
|
-
var link = document.createElement('link');
|
|
391
|
-
link.id = cssId;
|
|
392
|
-
link.rel = 'stylesheet';
|
|
393
|
-
link.type = 'text/css';
|
|
394
|
-
link.href = tiledeskScriptBaseLocation+'/iframe-style.css';
|
|
395
|
-
link.media = 'all';
|
|
396
|
-
head.appendChild(link);
|
|
397
|
-
// }
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
//DEPRECATED
|
|
402
|
-
function signInWithCustomToken() {
|
|
403
|
-
let json = JSON.stringify({
|
|
404
|
-
"id_project": "5b55e806c93dde00143163dd"
|
|
405
|
-
});
|
|
406
|
-
var httpRequest = createCORSRequest('POST', 'https://tiledesk-server-pre.herokuapp.com/auth/signinAnonymously',true);
|
|
407
|
-
if (!httpRequest) {
|
|
408
|
-
throw new Error('CORS not supported');
|
|
409
|
-
}
|
|
410
|
-
httpRequest.setRequestHeader('Content-type','application/json');
|
|
411
|
-
httpRequest.send(json);
|
|
412
|
-
httpRequest.onload = function() {
|
|
413
|
-
if (httpRequest.readyState === XMLHttpRequest.DONE) {
|
|
414
|
-
if (httpRequest.status === 200) {
|
|
415
|
-
try {
|
|
416
|
-
var response = JSON.parse(httpRequest.responseText);
|
|
417
|
-
window.tiledesk.signInWithCustomToken(response);
|
|
418
|
-
}
|
|
419
|
-
catch(err) {
|
|
420
|
-
console.error(err.message);
|
|
421
|
-
}
|
|
422
|
-
return true;
|
|
423
|
-
} else {
|
|
424
|
-
alert('There was a problem with the request.');
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
httpRequest.onerror = function() {
|
|
429
|
-
console.error('There was an error!');
|
|
430
|
-
return false;
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
function createCORSRequest(method, url, async) {
|
|
436
|
-
var xhr = new XMLHttpRequest();
|
|
437
|
-
if ("withCredentials" in xhr) {
|
|
438
|
-
xhr.open(method, url, async);
|
|
439
|
-
} else if (typeof XDomainRequest != "undefined") {
|
|
440
|
-
xhr = new XDomainRequest();
|
|
441
|
-
xhr.open(method, url);
|
|
442
|
-
} else {
|
|
443
|
-
xhr = null;
|
|
444
|
-
}
|
|
445
|
-
return xhr;
|
|
446
|
-
}
|