yelda-webchat 1.1.6 → 1.1.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yelda-webchat",
3
- "version": "1.1.6",
3
+ "version": "1.1.10",
4
4
  "description": "Website Chat Plugin",
5
5
  "main": "./dist/js/yeldaWebchatInjector.min.js",
6
6
  "license": "MIT",
@@ -27,7 +27,8 @@ module.exports = {
27
27
  LISTEN_LEAVE_VIEWPORT: 'listenLeaveViewport',
28
28
  LISTEN_URL_UPDATE: 'listenUrlUpdate',
29
29
  ABSTAIN_URL_UPDATE: 'abstainUrlUpdate',
30
- ADD_BUBBLE_TEXT: 'addBubbleText'
30
+ ADD_BUBBLE_TEXT: 'addBubbleText',
31
+ ADD_MINIMAL_NOTIFICATION_TEXT: 'addMinimalNotificationText'
31
32
  }
32
33
  }
33
34
  }
@@ -2,8 +2,29 @@
2
2
 
3
3
 
4
4
  .yelda_assistant_img {
5
- opacity: 0.93;
6
5
  cursor: pointer;
6
+ height: auto;
7
+ transition: opacity 0.6s ease-in-out 1.2s, height 1ms linear 1.2s;
8
+ animation-name: appear;
9
+ animation-duration: 0.8s;
10
+ animation-delay: 1s;
11
+ animation-timing-function: cubic-bezier(0.230, 1.000, 0.320, 1.000);
12
+ animation-iteration-count: 1;
13
+ animation-fill-mode: both;
14
+ opacity: 0;
15
+ overflow: hidden;
16
+ }
17
+
18
+ .yelda_container.y_active .yelda_assistant_img{
19
+ opacity:0 ;
20
+ height: 0 !important;
21
+ width: 0 !important;
22
+ transition: opacity 1ms linear 0s, height 1ms linear 0s;
23
+ animation: none;
24
+ }
25
+
26
+ .yelda_assistant_img.activated{
27
+ transition: opacity 0.6s ease-in-out 0.6s, height 1ms linear 0.6s;
7
28
  }
8
29
 
9
30
  .yelda_assistant_img.default {
@@ -33,32 +54,30 @@
33
54
  }
34
55
 
35
56
  .yelda_assistant_img.default i{
36
- font-size: 32px !important;
37
- }
38
-
39
- .yelda_assistant_img:hover{
40
- animation-name: fonta;
41
- animation-duration: 300ms;
42
- opacity: 1;
43
- }
44
- .yelda_assistant_img.default:hover i{
45
57
  height: 60px;
46
58
  width: 60px;
47
59
  line-height: 65px;
48
60
  font-size: 35px !important;
49
61
  }
50
62
 
63
+
64
+
65
+
66
+ .yelda_container {
67
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,
68
+ 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
69
+ font-weight: normal;
70
+ display: flex;
71
+ flex-direction: column-reverse;
72
+ align-items: flex-end;
73
+ }
74
+
51
75
  .yelda_container.inner {
52
76
  position: absolute !important;
53
77
  left: 45px;
54
78
  top: 80px;
55
79
  }
56
80
 
57
- @keyframes fonta {
58
- from {font-size:32px;}
59
- to {font-size:35px;}
60
- }
61
-
62
81
  #web_chat_frame{
63
82
  height: 100% !important;
64
83
  width: 100% !important;
@@ -72,13 +91,14 @@
72
91
  }
73
92
 
74
93
  .yelda_iframe_container {
75
- width: 430px;
76
- height: calc(100vh - 170px);
94
+ width: 0;
95
+ height: 0;
77
96
  max-height: 600px;
78
- transition-duration: 1s;
79
- margin: 0px 20px 0 0px;
97
+ margin: 0;
80
98
  overflow: hidden;
99
+ transition: opacity 0.6s linear 0s, transform 0.6s ease-in-out 0s, height 1ms linear 0.6s, width 1ms linear 0.6s;
81
100
  opacity: 0;
101
+ transform: translateY(20px);
82
102
  }
83
103
 
84
104
  .yelda_iframe_container:not(.voiceFirstUI) {
@@ -86,9 +106,12 @@
86
106
  border-radius: 6px;
87
107
  }
88
108
 
89
- .yelda_iframe_container.y_active{
109
+ .y_active .yelda_iframe_container{
110
+ width: 430px;
111
+ height: calc(100vh - 170px);
112
+ transition: opacity 0.6s linear 0s, transform 0.6s ease-in-out 0s, height 1ms linear 0s, width 1ms linear 0s;
90
113
  opacity: 1 !important;
91
- margin-bottom: 20px !important;
114
+ transform: translateY(0);
92
115
  }
93
116
 
94
117
  .lg-backdrop {
@@ -126,70 +149,110 @@
126
149
  border-radius: 0;
127
150
  margin: 0 !important;
128
151
  padding: 0;
129
- transition-duration: 0s;
130
152
  }
131
153
 
132
154
  .yelda_iframe_container.inner {
133
155
  width: 100%;
134
156
  box-shadow: 0 5px 32px rgba(0,0,0,.16);
135
157
  border-radius: 6px;
136
- transition-duration: 1s;
137
158
  margin: 0px 20px 0 0px;
138
159
  overflow: hidden;
139
160
  }
140
161
  }
141
162
  /** CSS for assistant bubble text */
142
163
  #yelda_assistant_bubble_text {
143
- position: absolute;
144
- white-space: nowrap;
145
- text-align: center;
146
- transform: translate(-104%, -140%);
147
- padding: 5px;
148
- border: 1px solid #000000;
149
- border-radius: 3px;
150
- box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.5);
164
+ animation-name: fadeAndSlideInFromRight;
165
+ animation-duration: 1s;
166
+ animation-delay: 2s;
167
+ animation-timing-function: cubic-bezier(0.230, 1.000, 0.320, 1.000);
168
+ animation-iteration-count: 1;
169
+ animation-fill-mode: both;
170
+ padding: 7px 10px 6px;
171
+ border-radius: 8px;
172
+ box-shadow: #00000030 0 2px 8px 0;
151
173
  background-color: white;
152
174
  cursor: pointer;
153
- animation: 1s ease-out 0s 1 fadeAndSlideInFromRight;
175
+ right: 0;
176
+ bottom: 76px;
177
+ max-width: 300px;
178
+ text-align: left;
179
+ font-size: 14px;
180
+ font-weight: normal;
181
+ display: inline-block;
182
+ margin-bottom: 10px;
183
+ }
184
+ #yelda_assistant_bubble_text.y_notification{
185
+ animation-delay: 0s;
154
186
  }
155
187
 
156
188
  #yelda_assistant_bubble_text.hidden {
157
189
  display: none;
158
190
  }
159
191
 
160
- /** css for adding tooltip like triangle to the assistant bubble text */
161
- #yelda_assistant_bubble_text::before,
162
- #yelda_assistant_bubble_text::after {
163
- content: "";
192
+ .y_active #yelda_assistant_bubble_text{
193
+ display: none;
194
+ }
195
+
196
+ /* Close button for bubble text */
197
+ .bubbleCloseButton {
164
198
  position: absolute;
165
- border-top: 5px solid transparent;
166
- border-bottom: 5px solid transparent;
167
- top: 50%;
168
- left: 100%;
199
+ color: white;
200
+ background: grey;
201
+ border-radius: 68%;
202
+ padding: 0;
203
+ font-size: 20px;
204
+ width: 27px;
205
+ height: 27px;
206
+ line-height: 22px;
207
+ text-align: center;
208
+ right: -14px;
209
+ top: -17px;
210
+ text-decoration: none !important;
211
+ transition: all 0.15s ease-in;
212
+ transform: scale(0.7);
213
+ opacity:0; /* Don't show the close button by default */
169
214
  }
170
215
 
171
- /* The border of the triangle */
172
- #yelda_assistant_bubble_text::before {
173
- border-left: 10px solid #000;
174
- margin-top: -5px;
175
- margin-left: 1px;
216
+ a.bubbleCloseButton:hover {
217
+ color: white;
218
+ background: #5a5a5a;
176
219
  }
177
220
 
178
- /* The white fill of the triangle */
179
- #yelda_assistant_bubble_text::after {
180
- border-left: 10px solid white;
181
- margin-top: -5px;
182
- z-index: 1;
221
+ /* Show the close button on mouse hover */
222
+ #yelda_assistant_bubble_text:hover .bubbleCloseButton {
223
+ opacity:1;
224
+ transform: scale(1);
225
+ }
226
+
227
+ /* Show the close button always on mobile screen */
228
+ @media only screen and (max-width: 768px) {
229
+ .bubbleCloseButton {
230
+ opacity: 1;
231
+ transform: none;
232
+ }
183
233
  }
184
234
 
185
235
  /** Animation for assistant bubble text */
186
236
  @keyframes fadeAndSlideInFromRight {
187
237
  0% {
188
- transform: translateX(0%) translateY(-140%);
238
+ transform: translateY(10%);
189
239
  opacity: 0;
190
240
  }
191
241
  100% {
192
- transform: translateX(-104%) translateY(-140%);
242
+ transform: translateY(0%);
243
+ opacity: 1;
244
+ }
245
+ }
246
+
247
+
248
+ @keyframes appear {
249
+ from {
250
+ transform: scale(0.5);
251
+ opacity: 0;
252
+ }
253
+ to {
254
+ transform: scale(1);
193
255
  opacity: 1;
194
256
  }
195
257
  }
258
+
@@ -82,16 +82,23 @@ class YeldaChat {
82
82
 
83
83
  /**
84
84
  * Create an assistantBubbleText component and add it to webChatContainer element
85
+ * @param {String} text - default null
86
+ * @param {String} cssClass - default ''
85
87
  */
86
- addAssistantBubbleText() {
87
- if (!this.webChatContainer || !this.webchatSettings || !this.webchatSettings.bubbleText) {
88
+ addAssistantBubbleText(text = null, cssClass = '') {
89
+ text = text || this.webchatSettings && this.webchatSettings.bubbleText
90
+ if (!this.webChatContainer || !text) {
88
91
  return
89
92
  }
90
93
 
94
+ // Remove the assistant bubble text element before adding a new one
95
+ this.removeElement('yelda_assistant_bubble_text')
91
96
  // create assistantBubbleText element and set the text
92
97
  this.assistantBubbleText = document.createElement('span')
93
98
  this.assistantBubbleText.setAttribute('id', 'yelda_assistant_bubble_text')
94
- this.assistantBubbleText.innerText = this.webchatSettings.bubbleText
99
+ this.assistantBubbleText.setAttribute('class', cssClass)
100
+ this.assistantBubbleText.innerText = text
101
+ this.addCloseButtonForBubbleText()
95
102
 
96
103
  // Add click event to assistant text
97
104
  this.assistantBubbleText.addEventListener('click', this.openChat.bind(this))
@@ -100,6 +107,31 @@ class YeldaChat {
100
107
  this.webChatContainer.appendChild(this.assistantBubbleText)
101
108
  }
102
109
 
110
+ /**
111
+ * Add close button for bubble text
112
+ */
113
+ addCloseButtonForBubbleText() {
114
+ // Create close button and add it to the bubble text container
115
+ const closeButton = document.createElement('a')
116
+ closeButton.setAttribute('class', 'bubbleCloseButton')
117
+ closeButton.setAttribute('id', 'yelda_assistant_bubble_text_close')
118
+ closeButton.setAttribute('href', '#')
119
+ closeButton.innerHTML = '×'
120
+ closeButton.onclick = this.closeBubbleText.bind(this)
121
+ this.assistantBubbleText.prepend(closeButton)
122
+ }
123
+
124
+ /**
125
+ * Callback function for bubble text close button
126
+ * @param {Event} event
127
+ */
128
+ closeBubbleText(event) {
129
+ event.preventDefault()
130
+ event.stopPropagation()
131
+ this.removeElement('yelda_assistant_bubble_text')
132
+ this.assistantBubbleText = null
133
+ }
134
+
103
135
  /**
104
136
  * Create assistantImage element and add it to webChatContainer element
105
137
  */
@@ -247,6 +279,43 @@ class YeldaChat {
247
279
  return url
248
280
  }
249
281
 
282
+ /**
283
+ * Add 'y_active' class to the webChatContainer if required
284
+ *
285
+ * To control the opacity of the iframe container (.yelda_iframe_container) and the assistant image (.yelda_assistant_img),
286
+ * We add and remove the "y_active" CSS class to the webChatContainer (.yelda_container) which is always visible
287
+ * By default
288
+ * - yelda_iframe_container is hidden (opacity: 0;)
289
+ * - assistant image is visible (opacity: 1 for yelda_assistant_img)
290
+ *
291
+ * When we add the class "y_active" to (webChatContainer)
292
+ * - yelda_iframe_container is now visible (.y_active .yelda_iframe_container => opacity: 1)
293
+ * - the assistant image is hidden (.yelda_container.y_active .yelda_assistant_img => opacity: 0
294
+ *
295
+ * @param {Boolean} data.shouldBeOpened
296
+ * @param {Boolean} data.isStartBtn
297
+ * @param {Boolean} data.canBeClosed
298
+ */
299
+ initWebChatContainerYActiveClass(data) {
300
+ // should be opened on load OR has a start button
301
+ const shoulBeOpened = data.shouldBeOpened || data.isStartBtn
302
+
303
+ // cannot be closed (canBeClosed explicitly set to false)
304
+ const cantBeClosed = data.hasOwnProperty('canBeClosed') && !data.canBeClosed
305
+
306
+ /**
307
+ * If we are sure that the webchat should be opened from the creation and displayed all the time
308
+ * we add the y_active class to webChatContainer at the creation
309
+ *
310
+ * Otherwise yelda_assistant_img click event management will take care of showing and hiding the webchat
311
+ * - closeChat() remove "y_active" from the yelda container
312
+ * - openChat() add y_active" to the yelda container
313
+ */
314
+ if (shoulBeOpened && cantBeClosed) {
315
+ this.webChatContainer.classList.add('y_active')
316
+ }
317
+ }
318
+
250
319
  /**
251
320
  * Create iframeContainer and it's child webchat iframe, and add it to webChatContainer
252
321
  * @param {String} url webchat url
@@ -273,24 +342,7 @@ class YeldaChat {
273
342
  classList += ' inner'
274
343
  }
275
344
 
276
- /**
277
- * add CSS class which controls the opacity of the frame container if the iframe:
278
- * - should be opened on load OR has a start button
279
- * - cannot be closed (canBeClosed explicitly set to false)
280
- *
281
- * If we are sure that the webchat should be opened and displayed all the time, we can add the y_active class right away
282
- * Otherwise,
283
- */
284
- if ((data.shouldBeOpened || data.isStartBtn) && data.hasOwnProperty('canBeClosed') && !data.canBeClosed) {
285
- classList += ' y_active'
286
- } else {
287
- /**
288
- * If the iframe can be closed, hide it by default
289
- * yelda_assistant_img click event management will take care of showing and hiding the webchat
290
- * And if it should be opened, the webchat will trigger the 'openChat' event on its own
291
- */
292
- this.iframeContainer.style.cssText = 'display: none;'
293
- }
345
+ this.initWebChatContainerYActiveClass(data)
294
346
 
295
347
  this.iframeContainer.setAttribute('class', classList)
296
348
  this.webChatContainer.appendChild(this.iframeContainer)
@@ -437,6 +489,11 @@ class YeldaChat {
437
489
  window.dispatchEvent(new CustomEvent('isSendingMessage', { detail: eventData.data }))
438
490
  }
439
491
  break
492
+ case config.FRAME_EVENT_TYPES.RECEIVED.ADD_MINIMAL_NOTIFICATION_TEXT:
493
+ if (!this.configurationData.hasOwnProperty('canBeClosed') || this.configurationData.canBeClosed) {
494
+ this.addAssistantBubbleText(eventData.text, 'y_notification')
495
+ }
496
+ break;
440
497
  }
441
498
  }
442
499
 
@@ -493,15 +550,11 @@ class YeldaChat {
493
550
  * Close the webchat window
494
551
  */
495
552
  closeChat() {
496
- const assistantImgElement = document.getElementById('yelda_assistant_img')
497
- if (assistantImgElement !== null) {
498
- assistantImgElement.style.display = 'inline-block'
499
- }
500
-
501
- const yeldaIframeContainerElement = document.getElementById('yelda_iframe_container')
502
- if (yeldaIframeContainerElement !== null) {
503
- yeldaIframeContainerElement.classList.remove('y_active')
504
- yeldaIframeContainerElement.style.display = 'none'
553
+ // Closing the webchat = remove the y_active class on #yelda_container
554
+ // Hiding the iframe + showing back the bubble + animation => All is done in CSS
555
+ const yeldaContainerElement = document.getElementById('yelda_container')
556
+ if (yeldaContainerElement !== null) {
557
+ yeldaContainerElement.classList.remove('y_active')
505
558
  }
506
559
  }
507
560
 
@@ -509,22 +562,28 @@ class YeldaChat {
509
562
  * Open the webchat window
510
563
  */
511
564
  openChat() {
565
+ // Adding the class "activated" allows the CSS to change the transition/animation after the first opening
512
566
  const assistantImgElement = document.getElementById('yelda_assistant_img')
513
567
  if (assistantImgElement !== null) {
514
- assistantImgElement.style.display = 'none'
568
+ assistantImgElement.classList.add('activated')
515
569
  }
516
570
 
517
- const yeldaIframeContainerElement = document.getElementById('yelda_iframe_container')
518
- if (yeldaIframeContainerElement !== null) {
519
- yeldaIframeContainerElement.style.display = 'block'
520
- yeldaIframeContainerElement.classList.add('y_active')
571
+ // Opening the webchat = adding the y_active class on #yelda_container
572
+ // Showing the iframe + hiding bubble + hiding minimal notification + animation => All is done in CSS
573
+ const yeldaContainerElement = document.getElementById('yelda_container')
574
+ if (yeldaContainerElement !== null) {
575
+ yeldaContainerElement.classList.add('y_active')
521
576
  }
522
577
 
523
- // hide the assistant bubble text while opening the webchat window
578
+ // Hide the assistant bubble text while opening the webchat window
579
+ // Note : bubble text container is also hidden in CSS
524
580
  if (this.assistantBubbleText) {
525
- this.assistantBubbleText.classList.add('hidden')
581
+ this.assistantBubbleText = null
526
582
  }
527
583
 
584
+ // Remove assistant bubble text while opening the webchat window
585
+ this.removeElement('yelda_assistant_bubble_text')
586
+
528
587
  // Propagate the event to the webchat
529
588
  document.getElementById('web_chat_frame').contentWindow.postMessage(config.FRAME_EVENT_TYPES.SENT.OPEN_CHAT, '*')
530
589
  }