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.
@@ -823,19 +823,29 @@ var YeldaChat = function () {
823
823
 
824
824
  /**
825
825
  * Create an assistantBubbleText component and add it to webChatContainer element
826
+ * @param {String} text - default null
827
+ * @param {String} cssClass - default ''
826
828
  */
827
829
 
828
830
  }, {
829
831
  key: 'addAssistantBubbleText',
830
832
  value: function addAssistantBubbleText() {
831
- if (!this.webChatContainer || !this.webchatSettings || !this.webchatSettings.bubbleText) {
833
+ var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
834
+ var cssClass = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
835
+
836
+ text = text || this.webchatSettings && this.webchatSettings.bubbleText;
837
+ if (!this.webChatContainer || !text) {
832
838
  return;
833
839
  }
834
840
 
841
+ // Remove the assistant bubble text element before adding a new one
842
+ this.removeElement('yelda_assistant_bubble_text');
835
843
  // create assistantBubbleText element and set the text
836
844
  this.assistantBubbleText = document.createElement('span');
837
845
  this.assistantBubbleText.setAttribute('id', 'yelda_assistant_bubble_text');
838
- this.assistantBubbleText.innerText = this.webchatSettings.bubbleText;
846
+ this.assistantBubbleText.setAttribute('class', cssClass);
847
+ this.assistantBubbleText.innerText = text;
848
+ this.addCloseButtonForBubbleText();
839
849
 
840
850
  // Add click event to assistant text
841
851
  this.assistantBubbleText.addEventListener('click', this.openChat.bind(this));
@@ -844,6 +854,37 @@ var YeldaChat = function () {
844
854
  this.webChatContainer.appendChild(this.assistantBubbleText);
845
855
  }
846
856
 
857
+ /**
858
+ * Add close button for bubble text
859
+ */
860
+
861
+ }, {
862
+ key: 'addCloseButtonForBubbleText',
863
+ value: function addCloseButtonForBubbleText() {
864
+ // Create close button and add it to the bubble text container
865
+ var closeButton = document.createElement('a');
866
+ closeButton.setAttribute('class', 'bubbleCloseButton');
867
+ closeButton.setAttribute('id', 'yelda_assistant_bubble_text_close');
868
+ closeButton.setAttribute('href', '#');
869
+ closeButton.innerHTML = '×';
870
+ closeButton.onclick = this.closeBubbleText.bind(this);
871
+ this.assistantBubbleText.prepend(closeButton);
872
+ }
873
+
874
+ /**
875
+ * Callback function for bubble text close button
876
+ * @param {Event} event
877
+ */
878
+
879
+ }, {
880
+ key: 'closeBubbleText',
881
+ value: function closeBubbleText(event) {
882
+ event.preventDefault();
883
+ event.stopPropagation();
884
+ this.removeElement('yelda_assistant_bubble_text');
885
+ this.assistantBubbleText = null;
886
+ }
887
+
847
888
  /**
848
889
  * Create assistantImage element and add it to webChatContainer element
849
890
  */
@@ -999,6 +1040,46 @@ var YeldaChat = function () {
999
1040
  return url;
1000
1041
  }
1001
1042
 
1043
+ /**
1044
+ * Add 'y_active' class to the webChatContainer if required
1045
+ *
1046
+ * To control the opacity of the iframe container (.yelda_iframe_container) and the assistant image (.yelda_assistant_img),
1047
+ * We add and remove the "y_active" CSS class to the webChatContainer (.yelda_container) which is always visible
1048
+ * By default
1049
+ * - yelda_iframe_container is hidden (opacity: 0;)
1050
+ * - assistant image is visible (opacity: 1 for yelda_assistant_img)
1051
+ *
1052
+ * When we add the class "y_active" to (webChatContainer)
1053
+ * - yelda_iframe_container is now visible (.y_active .yelda_iframe_container => opacity: 1)
1054
+ * - the assistant image is hidden (.yelda_container.y_active .yelda_assistant_img => opacity: 0
1055
+ *
1056
+ * @param {Boolean} data.shouldBeOpened
1057
+ * @param {Boolean} data.isStartBtn
1058
+ * @param {Boolean} data.canBeClosed
1059
+ */
1060
+
1061
+ }, {
1062
+ key: 'initWebChatContainerYActiveClass',
1063
+ value: function initWebChatContainerYActiveClass(data) {
1064
+ // should be opened on load OR has a start button
1065
+ var shoulBeOpened = data.shouldBeOpened || data.isStartBtn;
1066
+
1067
+ // cannot be closed (canBeClosed explicitly set to false)
1068
+ var cantBeClosed = data.hasOwnProperty('canBeClosed') && !data.canBeClosed;
1069
+
1070
+ /**
1071
+ * If we are sure that the webchat should be opened from the creation and displayed all the time
1072
+ * we add the y_active class to webChatContainer at the creation
1073
+ *
1074
+ * Otherwise yelda_assistant_img click event management will take care of showing and hiding the webchat
1075
+ * - closeChat() remove "y_active" from the yelda container
1076
+ * - openChat() add y_active" to the yelda container
1077
+ */
1078
+ if (shoulBeOpened && cantBeClosed) {
1079
+ this.webChatContainer.classList.add('y_active');
1080
+ }
1081
+ }
1082
+
1002
1083
  /**
1003
1084
  * Create iframeContainer and it's child webchat iframe, and add it to webChatContainer
1004
1085
  * @param {String} url webchat url
@@ -1028,24 +1109,7 @@ var YeldaChat = function () {
1028
1109
  classList += ' inner';
1029
1110
  }
1030
1111
 
1031
- /**
1032
- * add CSS class which controls the opacity of the frame container if the iframe:
1033
- * - should be opened on load OR has a start button
1034
- * - cannot be closed (canBeClosed explicitly set to false)
1035
- *
1036
- * If we are sure that the webchat should be opened and displayed all the time, we can add the y_active class right away
1037
- * Otherwise,
1038
- */
1039
- if ((data.shouldBeOpened || data.isStartBtn) && data.hasOwnProperty('canBeClosed') && !data.canBeClosed) {
1040
- classList += ' y_active';
1041
- } else {
1042
- /**
1043
- * If the iframe can be closed, hide it by default
1044
- * yelda_assistant_img click event management will take care of showing and hiding the webchat
1045
- * And if it should be opened, the webchat will trigger the 'openChat' event on its own
1046
- */
1047
- this.iframeContainer.style.cssText = 'display: none;';
1048
- }
1112
+ this.initWebChatContainerYActiveClass(data);
1049
1113
 
1050
1114
  this.iframeContainer.setAttribute('class', classList);
1051
1115
  this.webChatContainer.appendChild(this.iframeContainer);
@@ -1201,6 +1265,11 @@ var YeldaChat = function () {
1201
1265
  window.dispatchEvent(new CustomEvent('isSendingMessage', { detail: eventData.data }));
1202
1266
  }
1203
1267
  break;
1268
+ case _config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.RECEIVED.ADD_MINIMAL_NOTIFICATION_TEXT:
1269
+ if (!this.configurationData.hasOwnProperty('canBeClosed') || this.configurationData.canBeClosed) {
1270
+ this.addAssistantBubbleText(eventData.text, 'y_notification');
1271
+ }
1272
+ break;
1204
1273
  }
1205
1274
  }
1206
1275
 
@@ -1264,15 +1333,11 @@ var YeldaChat = function () {
1264
1333
  }, {
1265
1334
  key: 'closeChat',
1266
1335
  value: function closeChat() {
1267
- var assistantImgElement = document.getElementById('yelda_assistant_img');
1268
- if (assistantImgElement !== null) {
1269
- assistantImgElement.style.display = 'inline-block';
1270
- }
1271
-
1272
- var yeldaIframeContainerElement = document.getElementById('yelda_iframe_container');
1273
- if (yeldaIframeContainerElement !== null) {
1274
- yeldaIframeContainerElement.classList.remove('y_active');
1275
- yeldaIframeContainerElement.style.display = 'none';
1336
+ // Closing the webchat = remove the y_active class on #yelda_container
1337
+ // Hiding the iframe + showing back the bubble + animation => All is done in CSS
1338
+ var yeldaContainerElement = document.getElementById('yelda_container');
1339
+ if (yeldaContainerElement !== null) {
1340
+ yeldaContainerElement.classList.remove('y_active');
1276
1341
  }
1277
1342
  }
1278
1343
 
@@ -1283,22 +1348,28 @@ var YeldaChat = function () {
1283
1348
  }, {
1284
1349
  key: 'openChat',
1285
1350
  value: function openChat() {
1351
+ // Adding the class "activated" allows the CSS to change the transition/animation after the first opening
1286
1352
  var assistantImgElement = document.getElementById('yelda_assistant_img');
1287
1353
  if (assistantImgElement !== null) {
1288
- assistantImgElement.style.display = 'none';
1354
+ assistantImgElement.classList.add('activated');
1289
1355
  }
1290
1356
 
1291
- var yeldaIframeContainerElement = document.getElementById('yelda_iframe_container');
1292
- if (yeldaIframeContainerElement !== null) {
1293
- yeldaIframeContainerElement.style.display = 'block';
1294
- yeldaIframeContainerElement.classList.add('y_active');
1357
+ // Opening the webchat = adding the y_active class on #yelda_container
1358
+ // Showing the iframe + hiding bubble + hiding minimal notification + animation => All is done in CSS
1359
+ var yeldaContainerElement = document.getElementById('yelda_container');
1360
+ if (yeldaContainerElement !== null) {
1361
+ yeldaContainerElement.classList.add('y_active');
1295
1362
  }
1296
1363
 
1297
- // hide the assistant bubble text while opening the webchat window
1364
+ // Hide the assistant bubble text while opening the webchat window
1365
+ // Note : bubble text container is also hidden in CSS
1298
1366
  if (this.assistantBubbleText) {
1299
- this.assistantBubbleText.classList.add('hidden');
1367
+ this.assistantBubbleText = null;
1300
1368
  }
1301
1369
 
1370
+ // Remove assistant bubble text while opening the webchat window
1371
+ this.removeElement('yelda_assistant_bubble_text');
1372
+
1302
1373
  // Propagate the event to the webchat
1303
1374
  document.getElementById('web_chat_frame').contentWindow.postMessage(_config__WEBPACK_IMPORTED_MODULE_14___default.a.FRAME_EVENT_TYPES.SENT.OPEN_CHAT, '*');
1304
1375
  }
@@ -1397,7 +1468,7 @@ var YeldaChat = function () {
1397
1468
  }, _callee, _this2);
1398
1469
  }));
1399
1470
 
1400
- return function (_x4) {
1471
+ return function (_x6) {
1401
1472
  return _ref.apply(this, arguments);
1402
1473
  };
1403
1474
  }());
@@ -1675,7 +1746,7 @@ var YeldaChat = function () {
1675
1746
  }, _callee2, _this4, [[12, 19]]);
1676
1747
  }));
1677
1748
 
1678
- return function (_x5) {
1749
+ return function (_x7) {
1679
1750
  return _ref2.apply(this, arguments);
1680
1751
  };
1681
1752
  }());
@@ -1918,7 +1989,7 @@ var YeldaChat = function () {
1918
1989
  }, _callee4, _this5);
1919
1990
  }));
1920
1991
 
1921
- return function (_x6) {
1992
+ return function (_x8) {
1922
1993
  return _ref4.apply(this, arguments);
1923
1994
  };
1924
1995
  }());
@@ -2160,8 +2231,8 @@ if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
2160
2231
  var require;var require;/**!
2161
2232
  * lg-video.js | 1.2.0 | May 20th 2020
2162
2233
  * http://sachinchoolur.github.io/lg-video.js
2163
- * Copyright (c) 2016 Sachin N;
2164
- * @license GPLv3
2234
+ * Copyright (c) 2016 Sachin N;
2235
+ * @license GPLv3
2165
2236
  */(function(f){if(true){module.exports=f()}else { var g; }})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return require(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2166
2237
  (function (global, factory) {
2167
2238
  if (typeof define === "function" && define.amd) {
@@ -2429,11 +2500,12 @@ var require;var require;/**!
2429
2500
  videoTitle = this.core.s.dynamicEl[index].title;
2430
2501
  } else {
2431
2502
  videoTitle = this.core.items[index].getAttribute('title');
2432
- var firstImage = this.core.items[index].querySelector('img');
2503
+ }
2433
2504
 
2434
- if (firstImage) {
2435
- videoTitle = videoTitle || firstImage.getAttribute('alt');
2436
- }
2505
+ var firstImage = this.core.items[index].querySelector('img');
2506
+
2507
+ if (firstImage) {
2508
+ videoTitle = videoTitle || firstImage.getAttribute('alt');
2437
2509
  }
2438
2510
 
2439
2511
  videoTitle = videoTitle ? 'title="' + videoTitle + '"' : '';
@@ -2551,7 +2623,8 @@ module.exports = {
2551
2623
  LISTEN_LEAVE_VIEWPORT: 'listenLeaveViewport',
2552
2624
  LISTEN_URL_UPDATE: 'listenUrlUpdate',
2553
2625
  ABSTAIN_URL_UPDATE: 'abstainUrlUpdate',
2554
- ADD_BUBBLE_TEXT: 'addBubbleText'
2626
+ ADD_BUBBLE_TEXT: 'addBubbleText',
2627
+ ADD_MINIMAL_NOTIFICATION_TEXT: 'addMinimalNotificationText'
2555
2628
  }
2556
2629
  }
2557
2630
  };