From 741cbb31bd0092be0633277c6edaca89187ba29e Mon Sep 17 00:00:00 2001 From: Jens Soegaard Date: Mon, 19 Nov 2018 20:10:20 -0500 Subject: [PATCH] Added preventSubmitOnEnter option. Fixes #270 --- dist/conversational-form.js | 156 ++++++--- dist/conversational-form.min.js | 8 +- ...ment-disable-submit-on-enter-keypress.html | 331 ++++++++++++++++++ src/scripts/cf/ConversationalForm.ts | 8 + src/scripts/cf/ui/inputs/UserTextInput.ts | 6 + 5 files changed, 457 insertions(+), 52 deletions(-) create mode 100644 src/development-disable-submit-on-enter-keypress.html diff --git a/dist/conversational-form.js b/dist/conversational-form.js index a90db9e3e..08f50f03b 100644 --- a/dist/conversational-form.js +++ b/dist/conversational-form.js @@ -515,9 +515,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -1799,6 +1802,13 @@ var cf; enumerable: true, configurable: true }); + Object.defineProperty(Tag.prototype, "rows", { + get: function () { + return this.domElement.hasAttribute("rows") ? parseInt(this.domElement.getAttribute("rows")) : 0; + }, + enumerable: true, + configurable: true + }); Object.defineProperty(Tag.prototype, "disabled", { get: function () { // a tag is disabled if its conditions are not meet, also if it contains the disabled attribute @@ -2467,9 +2477,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2531,9 +2544,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2653,9 +2669,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2686,9 +2705,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2754,9 +2776,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2785,9 +2810,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2869,9 +2897,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2931,9 +2962,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -2991,9 +3025,12 @@ var cf; /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -3155,9 +3192,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -3814,9 +3854,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -3985,9 +4028,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -4280,6 +4326,10 @@ var cf; else { this.el.classList.remove("hide-input"); } + // Set rows attribute if present + if (this._currentTag.rows && this._currentTag.rows > 1) { + this.inputElement.setAttribute('rows', this._currentTag.rows.toString()); + } if (cf.UserInputElement.hideUserInputOnNoneTextInput) { // toggle userinput hide if (this.controlElements.active) { @@ -4493,6 +4543,8 @@ var cf; }; UserTextInput.prototype.resetValue = function () { this.inputElement.value = ""; + if (this.inputElement.hasAttribute('rows')) + this.inputElement.setAttribute('rows', '1'); this.onInputChange(); }; UserTextInput.prototype.dealloc = function () { @@ -4527,9 +4579,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -4866,9 +4921,12 @@ var cf; /// /// var __extends = (this && this.__extends) || (function () { - var extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } @@ -4958,6 +5016,8 @@ var cf; this.onInputElementChanged(); }; ChatList.prototype.onInputElementChanged = function () { + if (!this.cfReference || !this.cfReference.el) + return; var cfHeight = this.cfReference.el.offsetHeight; var inputHeight = this.input.height; var listHeight = cfHeight - inputHeight; @@ -5575,7 +5635,7 @@ var cf; var tag = indexesToRemove[i]; this.tags.splice(this.tags.indexOf(tag), 1); } - if (!this.tags || this.tags.length == 0) { + if (!ConversationalForm.suppressLog && (!this.tags || this.tags.length == 0)) { console.warn("Conversational Form: No tags found or registered."); } //let's start the conversation @@ -5675,7 +5735,7 @@ var cf; // remove the tags as they are now apart of a group for (var i = 0; i < groups[group].length; i++) { var tagToBeRemoved = groups[group][i]; - if (i == 0) + if (i == 0) // add the group at same index as the the first tag to be removed tags.splice(tags.indexOf(tagToBeRemoved), 1, tagGroup); else tags.splice(tags.indexOf(tagToBeRemoved), 1); @@ -5819,7 +5879,7 @@ var cf; // doing classic .submit wont trigger onsubmit if that is present on form element // as described here: http://wayback.archive.org/web/20090323062817/http://blogs.vertigosoftware.com/snyholm/archive/2006/09/27/3788.aspx // so we mimic a click. - var button = this.formEl.ownerDocument.createElement('input'); + var button = this.formEl.ownerDocument.createElement('button'); button.style.display = 'none'; button.type = 'submit'; this.formEl.appendChild(button); diff --git a/dist/conversational-form.min.js b/dist/conversational-form.min.js index 950716c72..2c27bc20a 100644 --- a/dist/conversational-form.min.js +++ b/dist/conversational-form.min.js @@ -1,4 +1,4 @@ -!function(t){function e(){}function n(t,e){return function(){t.apply(e,arguments)}}function i(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],c(t,this)}function o(t,e){for(;3===t._state;)t=t._value;if(0===t._state)return void t._deferreds.push(e);t._handled=!0,i._immediateFn(function(){var n=1===t._state?e.onFulfilled:e.onRejected;if(null===n)return void(1===t._state?s:r)(e.promise,t._value);var i;try{i=n(t._value)}catch(t){return void r(e.promise,t)}s(e.promise,i)})}function s(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var o=e.then;if(e instanceof i)return t._state=3,t._value=e,void a(t);if("function"==typeof o)return void c(n(o,e),t)}t._state=1,t._value=e,a(t)}catch(e){r(t,e)}}function r(t,e){t._state=2,t._value=e,a(t)}function a(t){2===t._state&&0===t._deferreds.length&&i._immediateFn(function(){t._handled||i._unhandledRejectionFn(t._value)});for(var e=0,n=t._deferreds.length;e0||!!navigator.userAgent.match(/Trident.*rv\:11\./)},t.getValuesOfBars=function(t){var e=t.split("||");return e.length<=1&&(e=t.split("|")),e},t.setTransform=function(t,e){t.style["-webkit-transform"]=e,t.style["-moz-transform"]=e,t.style["-ms-transform"]=e,t.style.transform=e},t.extendObject=function(t,e){for(var n in e)e[n]&&e[n].constructor&&e[n].constructor===Object?(t[n]=t[n]||{},arguments.callee(t[n],e[n])):t[n]=e[n];return t},t.caniuse={fileReader:function(){return!!(window.File&&window.FileReader&&window.FileList&&window.Blob)}},t}();t.Helpers=e}(cf||(cf={}));var cf;!function(t){var e=function(){function t(t){void 0===t&&(t=null),this._cf=t,this.target=document.createDocumentFragment()}return Object.defineProperty(t.prototype,"cf",{get:function(){return this._cf},set:function(t){this._cf=t},enumerable:!0,configurable:!0}),t.prototype.addEventListener=function(t,e,n){return this.target.addEventListener(t,e,n)},t.prototype.dispatchEvent=function(t){return this.target.dispatchEvent(t)},t.prototype.removeEventListener=function(t,e,n){this.target.removeEventListener(t,e,n)},t}();t.EventDispatcher=e}(cf||(cf={}));var cf;!function(t){var e=function(){function t(){}return t.parseTag=function(t){var e=document.createElement(t.tag);e.setAttribute("cf-formless","");for(var n in t)"tag"!==n&&"children"!==n&&e.setAttribute(n,t[n]);return e},t.parseGroupTag=function(e){for(var n=t.parseTag(e),i=e.children,o=0;o0)for(var r=0;r':"")+t.Helpers.getInnerTextOfElement(this.el)}else e=t.Helpers.getInnerTextOfElement(this.el);return e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"positionVector",{get:function(){return this._positionVector},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"tabIndex",{set:function(t){this.el.tabIndex=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"highlight",{get:function(){return this.el.classList.contains("highlight")},set:function(t){t?this.el.classList.add("highlight"):this.el.classList.remove("highlight")},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"focus",{get:function(){return this._focus},set:function(t){this._focus=t,this._focus?this.el.focus():this.el.blur()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"visible",{get:function(){return!this.el.classList.contains("hide")},set:function(t){t?this.el.classList.remove("hide"):(this.el.classList.add("hide"),this.tabIndex=-1,this.highlight=!1)},enumerable:!0,configurable:!0}),n.prototype.onBlur=function(t){this._focus=!1},n.prototype.onFocus=function(e){this._focus=!0,t.ConversationalForm.illustrateFlow(this,"dispatch",t.ControlElementEvents.ON_FOCUS,this.referenceTag),this.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.ON_FOCUS,{detail:this.positionVector}))},n.prototype.hasImage=function(){return!1},n.prototype.calcPosition=function(){var t=parseInt(window.getComputedStyle(this.el).getPropertyValue("margin-right"),10);this._positionVector={height:this.el.offsetHeight,width:this.el.offsetWidth+t,x:this.el.offsetLeft,y:this.el.offsetTop,el:this},this._positionVector.centerX=this._positionVector.x+.5*this._positionVector.width,this._positionVector.centerY=this._positionVector.y+.5*this._positionVector.height},n.prototype.setData=function(t){this.referenceTag=t.referenceTag,e.prototype.setData.call(this,t)},n.prototype.animateIn=function(){clearTimeout(this.animateInTimer),this.el.classList.add("animate-in")},n.prototype.animateOut=function(){this.el.classList.add("animate-out")},n.prototype.onChoose=function(){t.ConversationalForm.illustrateFlow(this,"dispatch",t.ControlElementEvents.SUBMIT_VALUE,this.referenceTag),this.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.SUBMIT_VALUE,{detail:this}))},n.prototype.dealloc=function(){this.el.removeEventListener("blur",this.onBlurCallback,!1),this.onBlurCallback=null,this.el.removeEventListener("focus",this.onFocusCallback,!1),this.onFocusCallback=null,e.prototype.dealloc.call(this)},n}(t.BasicElement);t.ControlElement=e}(cf||(cf={}));var cf;!function(t){t.ControlElementsEvents={ON_RESIZE:"cf-on-control-elements-resize",CHANGED:"cf-on-control-elements-changed"};var e=function(){function e(e){this.animateInFromReponseTimer=0,this.ignoreKeyboardInput=!1,this.rowIndex=-1,this.columnIndex=0,this.elementWidth=0,this.filterListNumberOfVisible=0,this.listWidth=0,this.el=e.el,this.eventTarget=e.eventTarget,this.cfReference=e.cfReference,this.list=this.el.getElementsByTagName("cf-list")[0],this.infoElement=e.infoEl,this.onScrollCallback=this.onScroll.bind(this),this.el.addEventListener("scroll",this.onScrollCallback,!1),this.onResizeCallback=this.onResize.bind(this),window.addEventListener("resize",this.onResizeCallback,!1),this.onElementFocusCallback=this.onElementFocus.bind(this),this.eventTarget.addEventListener(t.ControlElementEvents.ON_FOCUS,this.onElementFocusCallback,!1),this.onElementLoadedCallback=this.onElementLoaded.bind(this),this.eventTarget.addEventListener(t.ControlElementEvents.ON_LOADED,this.onElementLoadedCallback,!1),this.onChatReponsesUpdatedCallback=this.onChatReponsesUpdated.bind(this),this.eventTarget.addEventListener(t.ChatListEvents.CHATLIST_UPDATED,this.onChatReponsesUpdatedCallback,!1),this.onUserInputKeyChangeCallback=this.onUserInputKeyChange.bind(this),this.eventTarget.addEventListener(t.UserInputEvents.KEY_CHANGE,this.onUserInputKeyChangeCallback,!1),this.userInputUpdateCallback=this.onUserInputUpdate.bind(this),this.eventTarget.addEventListener(t.FlowEvents.USER_INPUT_UPDATE,this.userInputUpdateCallback,!1),this.listScrollController=new t.ScrollController({interactionListener:this.el,listToScroll:this.list,eventTarget:this.eventTarget,listNavButtons:this.el.getElementsByTagName("cf-list-button")})}return Object.defineProperty(e.prototype,"active",{get:function(){return this.elements&&this.elements.length>0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"focus",{get:function(){if(!this.elements)return!1;for(var t=this.getElements(),e=0;ethis.tableableRows[this.rowIndex].length-1&&(this.columnIndex=0),!0):(this.resetTabList(),!1)},e.prototype.updateRowIndex=function(t){var e=this.rowIndex;if(this.rowIndex+=t,this.tableableRows[this.rowIndex])for(var n=this.tableableRows[e]?this.tableableRows[e][this.columnIndex].positionVector.centerX:0,i=this.tableableRows[this.rowIndex],o=1e13,s=0;sMath.abs(n-r.positionVector.centerX)&&(o=Math.abs(n-r.positionVector.centerX),this.columnIndex=s)}},e.prototype.resetTabList=function(){this.rowIndex=-1,this.columnIndex=-1},e.prototype.onUserInputUpdate=function(t){if(this.el.classList.remove("animate-in"),this.infoElement.classList.remove("show"),this.elements)for(var e=this.getElements(),n=0;n1){for(var o=[],s=0;s0&&(o[0].highlight=!0)}},e.prototype.clickOnHighlighted=function(){for(var t=this.getElements(),e=0;e0){this.el.classList.contains("animate-in")||this.el.classList.add("animate-in");for(var e=0;e0&&"OptionsList"==this.elements[0].type?this.elements[0].elements:this.elements},e.prototype.buildTabableRows=function(){this.tableableRows=[],this.resetTabList();var t=this.getElements();if(this.el.classList.contains("two-row")){this.tableableRows[0]=[],this.tableableRows[1]=[];for(var e=0;e0)switch(this.elements[0].type){case"CheckboxButton":for(var n=0,i=[],o=0;o1)break}for(var o=0;o1&&(s.partOfSeveralChoices=!0),i.push(s.value)),e.controlElements.push(s)}e.text=t.Dictionary.parseAndGetMultiValueString(i);break;case"RadioButton":for(var o=0;o0;)this.elements.pop().dealloc();this.list.innerHTML="",this.onListChanged()},e.prototype.buildTags=function(e){var n=this;this.disabled=!1;this.el.parentNode.getElementsByTagName("ul")[0],this.el.parentNode.getElementsByTagName("ul")[1];this.clearTagsAndReset(),this.elements=[];for(var i=0;i0){var s=this.elements[this.elements.length-1];this.list.appendChild(s.el)}}var r=this.elements[0]&&"OptionsList"==this.elements[0].type;this.filterListNumberOfVisible=r?this.elements[0].elements.length:e.length,new Promise(function(t,e){return n.resize(t,e)}).then(function(){var e=n.list.offsetHeight,i={height:e};n.onListChanged(),t.ConversationalForm.illustrateFlow(n,"dispatch",t.UserInputEvents.CONTROL_ELEMENTS_ADDED,i),n.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.CONTROL_ELEMENTS_ADDED,{detail:i}))})},e.prototype.onResize=function(t){this.resize()},e.prototype.resize=function(e,n){this.list.style.width="100%",this.el.classList.remove("resized"),this.el.classList.remove("one-row"),this.el.classList.remove("two-row"),this.elementWidth=0,this.listWidth=0;var i=this.getElements();if(i&&i.length>0){for(var o=[],s=[],r=!1,a=0;ac;u&&!r?(this.el.classList.add("two-row"),this.listWidth=Math.max(c,Math.round(o[Math.floor(o.length/2)]+50)),this.list.style.width=this.listWidth+"px"):this.el.classList.add("one-row");for(var a=0;ac;for(var h=i.slice(),p=h.sort(function(t,e){var n=t.positionVector.y>e.positionVector.y;return t.positionVector.x==e.positionVector.x?n?1:-1:t.positionVector.x0&&(this.xTarget+=(0-this.xTarget)*t.Helpers.lerp(e.accerlation,.3,.8)),this.xTargetthis.max&&(this.nextButton.classList.contains("active")||this.nextButton.classList.add("active"),this.nextButton.classList.contains("cf-gradient")||this.nextButton.classList.add("cf-gradient")),i<=this.max&&(this.nextButton.classList.contains("active")&&this.nextButton.classList.remove("active"),this.nextButton.classList.contains("cf-gradient")&&this.nextButton.classList.remove("cf-gradient"));var o=this.x;t.Helpers.setTransform(this.listToScroll,"translateX("+o+"px)"),(this.interacting||Math.abs(this.x-this.xTarget)>.02&&!this.interacting)&&(this.rAF=window.requestAnimationFrame(function(){return n.render()}))},e.prototype.setScroll=function(t,e){this.xTarget=this.visibleAreaWidth==this.listWidth?0:t,this.render()},e.prototype.pushDirection=function(t){this.inputAccerlationTarget+=5e3*t,this.render()},e.prototype.dealloc=function(){this.prevButton.removeEventListener("click",this.onListNavButtonsClickCallback,!1),this.nextButton.removeEventListener("click",this.onListNavButtonsClickCallback,!1),this.onListNavButtonsClickCallback=null,this.prevButton=null,this.nextButton=null,document.removeEventListener("mouseleave",this.documentLeaveCallback,!1),document.removeEventListener(t.Helpers.getMouseEvent("mouseup"),this.documentLeaveCallback,!1),this.interactionListener.removeEventListener(t.Helpers.getMouseEvent("mousedown"),this.onInteractStartCallback,!1),this.interactionListener.removeEventListener(t.Helpers.getMouseEvent("mouseup"),this.onInteractEndCallback,!1),this.interactionListener.removeEventListener(t.Helpers.getMouseEvent("mousemove"),this.onInteractMoveCallback,!1),this.documentLeaveCallback=null,this.onInteractStartCallback=null,this.onInteractEndCallback=null,this.onInteractMoveCallback=null},e.prototype.reset=function(){this.interacting=!1,this.startX=0,this.startXTarget=this.startX,this.inputAccerlation=0,this.x=0,this.xTarget=0,t.Helpers.setTransform(this.listToScroll,"translateX(0px)"),this.render(),this.prevButton.classList.remove("active"),this.nextButton.classList.remove("active")},e.prototype.resize=function(t,e){this.reset(),this.visibleAreaWidth=e,this.listWidth=Math.max(e,t),this.max=-1*(this.listWidth-this.visibleAreaWidth),this.render()},e.accerlation=.1,e}();t.ScrollController=e}(cf||(cf={}));var cf;!function(t){var e=function(){function e(t){this.data={"user-image":"https://cf-4053.kxcdn.com/conversational-form/human.png","entry-not-found":"Dictionary item not found.","awaiting-mic-permission":"Awaiting mic permission","user-audio-reponse-invalid":"I didn't get that, try again.","microphone-terminal-error":"Audio input not supported","input-placeholder":"Type your answer here ...","group-placeholder":"Type to filter list ...","input-placeholder-error":"Your input is not correct ...","input-placeholder-required":"Input is required ...","input-placeholder-file-error":"File upload failed ...","input-placeholder-file-size-error":"File size too big ...","input-no-filter":"No results found for {input-value}","user-reponse-and":" and ","user-reponse-missing":"Missing input ...","user-reponse-missing-group":"Nothing selected ...",general:"General type1||General type2","icon-type-file":""},this.robotData={"robot-image":"https://cf-4053.kxcdn.com/conversational-form/robot.png",input:"Please write some text.",text:"Please write some text.",checkbox:"Select as many as you want.",name:"What's your name?", -email:"Need your e-mail.",password:"Please provide password",tel:"What's your phone number?",radio:"I need you to select one of these.",select:"Choose any of these options.",file:"Select a file to upload.",general:"General1||General2||General3.."},e.instance=this,t&&t.data&&(this.data=this.validateAndSetNewData(t.data,this.data)),t.userImage&&(this.data["user-image"]=t.userImage),t.robotImage&&(this.robotData["robot-image"]=t.robotImage),t&&t.robotData&&(this.robotData=this.validateAndSetNewData(t.robotData,this.robotData))}return e.get=function(n){var i=e.instance,o=i.data[n];if(o){var s=t.Helpers.getValuesOfBars(o);o=s[Math.floor(Math.random()*s.length)]}else o=i.data["entry-not-found"];return o},e.set=function(t,n,i){var o=e.instance,s="robot"==n?o.robotData:o.data;return s[t]=i,s[t]},e.getRobotResponse=function(n){var i=e.instance,o=i.robotData[n];if(o){var s=t.Helpers.getValuesOfBars(o);o=s[Math.floor(Math.random()*s.length)]}else{var r=t.Helpers.getValuesOfBars(i.robotData.general);o=r[Math.floor(Math.random()*r.length)]}return o},e.parseAndGetMultiValueString=function(t){for(var n="",i=0;i1&&i==t.length-2?e.get("user-reponse-and"):", ";n+=o+(i Tag registered:",this.type,this)),this.refresh()}return Object.defineProperty(Tag.prototype,"type",{get:function(){return this.domElement.getAttribute("type")||this.domElement.tagName.toLowerCase()},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"name",{get:function(){return this.domElement.getAttribute("name")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"id",{get:function(){return this.domElement.getAttribute("id")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"inputPlaceholder",{get:function(){return this._inputPlaceholder},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"formless",{get:function(){return cf.TagsParser.isElementFormless(this.domElement)},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"label",{get:function(){return this.getLabel()},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"value",{get:function(){return this.domElement.value||this.initialDefaultValue},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"hasImage",{get:function(){return this.domElement.hasAttribute("cf-image")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"disabled",{get:function(){return!this.checkConditionalAndIsValid()||void 0!=this.domElement.getAttribute("disabled")&&null!=this.domElement.getAttribute("disabled")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"required",{get:function(){return!!this.domElement.getAttribute("required")||""==this.domElement.getAttribute("required")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"question",{get:function(){return this.questions&&0!=this.questions.length?this.questions[Math.floor(Math.random()*this.questions.length)]:cf.Dictionary.getRobotResponse(this.type)},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"eventTarget",{set:function(t){this._eventTarget=t},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"errorMessage",{get:function(){return this.errorMessages||(this.domElement.getAttribute("cf-error")?this.errorMessages=cf.Helpers.getValuesOfBars(this.domElement.getAttribute("cf-error")):this.domElement.parentNode&&this.domElement.parentNode.getAttribute("cf-error")?this.errorMessages=cf.Helpers.getValuesOfBars(this.domElement.parentNode.getAttribute("cf-error")):this.required?this.errorMessages=[cf.Dictionary.get("input-placeholder-required")]:"file"==this.type?this.errorMessages=[cf.Dictionary.get("input-placeholder-file-error")]:this.errorMessages=[cf.Dictionary.get("input-placeholder-error")]),this.errorMessages[Math.floor(Math.random()*this.errorMessages.length)]},enumerable:!0,configurable:!0}),Tag.prototype.dealloc=function(){this.domElement.removeEventListener("change",this.changeCallback,!1),this.changeCallback=null,this.domElement=null,this.defaultValue=null,this.errorMessages=null,this.pattern=null,this._label=null,this.validationCallback=null,this.questions=null},Tag.testConditions=function(t,e){var n=function(e,n){return"object"==typeof n?n.test(e):t===n};if("string"==typeof t){for(var i=t,o=!1,s=0;s0},Tag.prototype.checkConditionalAndIsValid=function(){return!this.hasConditions()||this.flowManager.areConditionsInFlowFullfilled(this,this.conditionalTags)},Tag.prototype.setTagValueAndIsValid=function(t){var e=!0,n=t.text;this.pattern&&(e=this.pattern.test(n)),""==n&&this.required&&(e=!1);var i=parseInt(this.domElement.getAttribute("minlength"),10)||-1,o=parseInt(this.domElement.getAttribute("maxlength"),10)||-1;return-1!=i&&n.lengtho&&(e=!1),e&&"file"!=this.type&&(this.domElement.value=n),e},Tag.prototype.getLabel=function(){return this._label||this.findAndSetLabel(),this._label?this._label:cf.Dictionary.getRobotResponse(this.type)},Tag.prototype.findConditionalAttributes=function(){var t=this.domElement.attributes;if(t.length>0){this.conditionalTags=[];for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];if(n&&n.name&&-1!==n.name.indexOf("cf-conditional")){for(var i=[],o=-1!==n.value.indexOf("||")?n.value.split("||"):n.value.split("&&"),s=0;s0&&(e=[t])}else if(e.length>0)for(var i=0;i TagGroup registered:",this.elements[0].type,this)),this.skipUserInput=!1}return Object.defineProperty(e.prototype,"required",{get:function(){for(var t=0;t0)return this.questions[Math.floor(Math.random()*this.questions.length)];if(this.elements[0]&&this.elements[0].question){return this.elements[0].question}return t.Dictionary.getRobotResponse(this.getGroupTagType())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activeElements",{get:function(){return this._activeElements},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._values?this._values:[""]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){for(var t=0,e=0;e\n\t\t\t\t'+this.referenceTag.label+"\n\t\t\t\n\t\t\t"},n}(t.ControlElement);t.Button=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"RadioButton"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"checked",{get:function(){return this.el.hasAttribute("checked")&&"checked"==this.el.getAttribute("checked")},set:function(t){t?(this.el.setAttribute("checked","checked"),this.referenceTag.domElement.setAttribute("checked","checked"),this.referenceTag.domElement.checked=!0):(this.el.removeAttribute("checked"),this.referenceTag.domElement.removeAttribute("checked"),this.referenceTag.domElement.checked=!1)},enumerable:!0,configurable:!0}),e.prototype.onClick=function(e){this.checked=!0,t.prototype.onClick.call(this,e)},e.prototype.getTemplate=function(){return'\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t"+this.referenceTag.label+"\n\t\t\t\t
\n\t\t\t
\n\t\t\t"},e}(t.Button);t.RadioButton=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"CheckboxButton"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"checked",{get:function(){return"checked"==this.el.getAttribute("checked")},set:function(t){t?(this.el.setAttribute("checked","checked"),this.referenceTag.domElement.setAttribute("checked","checked"),this.referenceTag.domElement.checked=!0):(this.el.removeAttribute("checked"),this.referenceTag.domElement.removeAttribute("checked"),this.referenceTag.domElement.checked=!1)},enumerable:!0,configurable:!0}),e.prototype.onClick=function(t){this.checked=!this.checked},e.prototype.getTemplate=function(){var t=this.referenceTag.domElement.checked&&this.referenceTag.domElement.hasAttribute("checked");return'";return t+="
",this.isMultiChoice&&(t+=""),t+=this.referenceTag.label,t+="
",t+="
"},n}(t.Button);t.OptionButton=e}(cf||(cf={}));var cf;!function(t){var e=function(){function e(e){this.context=e.context,this.eventTarget=e.eventTarget,this.referenceTag=e.referenceTag,this.multiChoice=this.referenceTag.domElement.hasAttribute("multiple"),this.onOptionButtonClickCallback=this.onOptionButtonClick.bind(this),this.eventTarget.addEventListener(t.OptionButtonEvents.CLICK,this.onOptionButtonClickCallback,!1),this.createElements()}return Object.defineProperty(e.prototype,"type",{get:function(){return"OptionsList"},enumerable:!0,configurable:!0}),e.prototype.getValue=function(){for(var t=[],e=0;e0;)this.elements.pop().dealloc();this.elements=null},e}();t.OptionsList=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;if(i.maxFileSize=1e11,i.loading=!1,i.submitTimer=0,i._fileName="",i._readerResult="",!t.Helpers.caniuse.fileReader())throw new Error("Conversational Form Error: No FileReader available for client.");var o=i.referenceTag.domElement.getAttribute("cf-max-size")||i.referenceTag.domElement.getAttribute("max-size");if(o){var s=parseInt(o,10);i.maxFileSize=s}return i.progressBar=i.el.getElementsByTagName("cf-upload-file-progress-bar")[0],i.onDomElementChangeCallback=i.onDomElementChange.bind(i),i.referenceTag.domElement.addEventListener("change",i.onDomElementChangeCallback,!1),i}return __extends(n,e),Object.defineProperty(n.prototype,"value",{get:function(){return this.referenceTag.domElement.value},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"readerResult",{get:function(){return this._readerResult},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"files",{get:function(){return this._files},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"fileName",{get:function(){return this._fileName},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"type",{get:function(){return"UploadFileUI"},enumerable:!0,configurable:!0}),n.prototype.getFilesAsString=function(){var e=document.createElement("span");return e.innerHTML=t.Dictionary.get("icon-type-file")+this.fileName,e.outerHTML},n.prototype.onDomElementChange=function(e){var n=this;t.ConversationalForm.suppressLog||console.log("...onDomElementChange");var i=new FileReader;this._files=this.referenceTag.domElement.files,i.onerror=function(e){t.ConversationalForm.suppressLog||console.log("onerror",e)},i.onprogress=function(e){t.ConversationalForm.suppressLog||console.log("onprogress",e),n.progressBar.style.width=e.loaded/e.total*100+"%"},i.onabort=function(e){t.ConversationalForm.suppressLog||console.log("onabort",e)},i.onloadstart=function(e){var o=n.files[0],s=o?o.size:n.maxFileSize+1;if(s>n.maxFileSize){i.abort();var r={errorText:t.Dictionary.get("input-placeholder-file-size-error")};t.ConversationalForm.illustrateFlow(n,"dispatch",t.FlowEvents.USER_INPUT_INVALID,r),n.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:r}))}else{n._fileName=o.name,n.loading=!0,n.animateIn();var a=Math.floor(Math.log(s)/Math.log(1024)),l=["b","kb","mb","gb"];a=Math.min(l.length-1,a);var c=1*Number((s/Math.pow(1024,a)).toFixed(2))+" "+l[a],u=o.name+" ("+c+")";n.el.getElementsByTagName("cf-upload-file-text")[0].innerHTML=u,n.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.PROGRESS_CHANGE,{detail:t.ControlElementProgressStates.BUSY}))}},i.onload=function(e){n._readerResult=e.target.result,n.progressBar.classList.add("loaded"),n.submitTimer=setTimeout(function(){n.el.classList.remove("animate-in"),n.onChoose(), -n.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.PROGRESS_CHANGE,{detail:t.ControlElementProgressStates.READY}))},0)},i.readAsDataURL(this.files[0])},n.prototype.animateIn=function(){this.loading&&e.prototype.animateIn.call(this)},n.prototype.onClick=function(t){},n.prototype.triggerFileSelect=function(){this.referenceTag.domElement.click()},n.prototype.dealloc=function(){clearTimeout(this.submitTimer),this.progressBar=null,this.onDomElementChangeCallback&&(this.referenceTag.domElement.removeEventListener("change",this.onDomElementChangeCallback,!1),this.onDomElementChangeCallback=null),e.prototype.dealloc.call(this)},n.prototype.getTemplate=function(){"1"==this.referenceTag.value||this.referenceTag.domElement.hasAttribute("checked");return"\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t"},n}(t.Button);t.UploadFileUI=e}(cf||(cf={}));var cf;!function(t){t.MicrophoneBridgeEvent={ERROR:"cf-microphone-bridge-error",TERMNIAL_ERROR:"cf-microphone-bridge-terminal-error"};var e=function(){function e(e){this.currentTextResponse="",this._hasUserMedia=!1,this.inputErrorCount=0,this.inputCurrentError="",this.el=e.el,this.button=e.button,this.eventTarget=e.eventTarget,this.microphoneObj=e.microphoneObj,this.flowUpdateCallback=this.onFlowUpdate.bind(this),this.eventTarget.addEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1)}return Object.defineProperty(e.prototype,"hasUserMedia",{set:function(t){this._hasUserMedia=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"active",{set:function(t){this.equalizer&&(this.equalizer.disabled=!t)},enumerable:!0,configurable:!0}),e.prototype.cancel=function(){this.button.loading=!1,this.microphoneObj.cancelInput&&this.microphoneObj.cancelInput()},e.prototype.onFlowUpdate=function(){var t=this;if(this.currentTextResponse=null,this._hasUserMedia)this.microphoneObj.awaitingCallback||this.callInput();else{var e=!1;window.navigator.mediaDevices&&window.navigator.mediaDevices.enumerateDevices().then(function(n){n.forEach(function(t){e||""===t.label||(e=!0)}),e&&t.getUserMedia()})}},e.prototype.getUserMedia=function(){var e=this;try{void 0===navigator.mediaDevices&&(navigator.mediaDevices={}),void 0===navigator.mediaDevices.getUserMedia&&(navigator.mediaDevices.getUserMedia=function(t){var e=navigator.getUserMedia||window.navigator.webkitGetUserMedia||window.navigator.mozGetUserMedia;return e?new Promise(function(n,i){e.call(navigator,t,n,i)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}),navigator.mediaDevices.getUserMedia({audio:!0}).then(function(t){e.currentStream=t,t.getAudioTracks().length>0?(e.hasUserMedia=!0,e.setupEqualizer(),e.microphoneObj.awaitingCallback||e.callInput()):e.hasUserMedia=!1}).catch(function(n){e.hasUserMedia=!1,e.eventTarget.dispatchEvent(new Event(t.MicrophoneBridgeEvent.TERMNIAL_ERROR))})}catch(e){this.hasUserMedia=!1,this.eventTarget.dispatchEvent(new Event(t.MicrophoneBridgeEvent.TERMNIAL_ERROR))}},e.prototype.dealloc=function(){this.cancel(),this.promise=null,this.currentStream=null,this.equalizer&&this.equalizer.dealloc(),this.equalizer=null,this.eventTarget.removeEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1),this.flowUpdateCallback=null},e.prototype.callInput=function(e){var n=this;void 0===e&&(e=0),this.button.loading=!0,this.equalizer&&(this.equalizer.disabled=!1),this.promise=new Promise(function(t,e){return n.microphoneObj.input(t,e,n.currentStream)}).then(function(e){if(n.promise=null,n.currentTextResponse=e.toString(),!n.currentTextResponse||""==n.currentTextResponse)return n.showError(t.Dictionary.get("user-audio-reponse-invalid")),void n.callInput();n.inputErrorCount=0,n.inputCurrentError="",n.button.loading=!1;var i={text:n.currentTextResponse};t.ConversationalForm.illustrateFlow(n,"dispatch",t.UserInputEvents.SUBMIT,i),n.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.SUBMIT,{detail:i}))}).catch(function(e){n.isErrorTerminal(e)?(n.eventTarget.dispatchEvent(new CustomEvent(t.MicrophoneBridgeEvent.TERMNIAL_ERROR,{detail:t.Dictionary.get("microphone-terminal-error")})),t.ConversationalForm.suppressLog||console.log("Conversational Form: Terminal error: ",e)):(n.inputCurrentError!=e&&(n.inputErrorCount=0,n.inputCurrentError=e),n.inputErrorCount++,n.inputErrorCount>2?n.showError(e):(n.eventTarget.dispatchEvent(new CustomEvent(t.MicrophoneBridgeEvent.TERMNIAL_ERROR,{detail:t.Dictionary.get("microphone-terminal-error")})),t.ConversationalForm.suppressLog||console.log("Conversational Form: Terminal error: ",e)))})},e.prototype.isErrorTerminal=function(t){return-1!==["network"].indexOf(t)},e.prototype.showError=function(e){var n={errorText:e};t.ConversationalForm.illustrateFlow(this,"dispatch",t.FlowEvents.USER_INPUT_INVALID,n),this.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:n})),this.callInput()},e.prototype.setupEqualizer=function(){var t=this.el.getElementsByTagName("cf-icon-audio-eq")[0];n.supported&&t&&(this.equalizer=new n({stream:this.currentStream,elementToScale:t}))},e}();t.MicrophoneBridge=e;var n=function(){function t(t){var e=this;this.maxBorderWidth=0,this._disabled=!1,this.elementToScale=t.elementToScale,this.context=new AudioContext,this.analyser=this.context.createAnalyser(),this.mic=this.context.createMediaStreamSource(t.stream),this.javascriptNode=this.context.createScriptProcessor(2048,1,1),this.analyser.smoothingTimeConstant=.3,this.analyser.fftSize=1024,this.mic.connect(this.analyser),this.analyser.connect(this.javascriptNode),this.javascriptNode.connect(this.context.destination),this.javascriptNode.onaudioprocess=function(){e.onAudioProcess()}}return Object.defineProperty(t.prototype,"disabled",{set:function(t){this._disabled=t,this.elementToScale.style.borderWidth="0px"},enumerable:!0,configurable:!0}),t.prototype.onAudioProcess=function(){if(!this._disabled){var t=new Uint8Array(this.analyser.frequencyBinCount);this.analyser.getByteFrequencyData(t);for(var e=0,n=t.length,i=0;i\n\t\t\t\t
\n\t\t\t\t\n\t\t\t';var i=n.firstChild||n.content.firstChild;this.mic=new t.MicrophoneBridge({el:i,button:this,eventTarget:this.eventTarget,microphoneObj:e}),this.el.appendChild(i)},e.prototype.reset=function(){this.mic&&!this.typing&&this.mic.callInput()},e.prototype.getTemplate=function(){return'\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
'},e.prototype.onMicrophoneTerminalError=function(e){this.mic&&(this.mic.dealloc(),this.mic=null,this.el.removeChild(this.el.getElementsByClassName("cf-microphone")[0]),this.el.classList.remove("microphone-interface"),this.loading=!1,this.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:{errorText:e.detail}})))},e.prototype.onClick=function(e){this.mic&&!this.typing?this.mic.callInput():this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputSubmitButtonEvents.CHANGE))},e.prototype.click=function(){this.el.click()},e.prototype.dealloc=function(){this.eventTarget.removeEventListener(t.MicrophoneBridgeEvent.TERMNIAL_ERROR,this.onMicrophoneTerminalErrorCallback,!1),this.onMicrophoneTerminalErrorCallback=null,this.mic&&this.mic.dealloc(),this.mic=null,this.el.removeEventListener("click",this.onClickCallback,!1),this.onClickCallback=null,this.el=null,this.eventTarget=null},e}();t.UserInputSubmitButton=e}(cf||(cf={}));var cf;!function(t){t.UserInputTypes={VOICE:"voice",VR_GESTURE:"vr-gesture",TEXT:"text"}}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;return i._disabled=!1,i._visible=!1,i.onChatReponsesUpdatedCallback=i.onChatReponsesUpdated.bind(i),i.eventTarget.addEventListener(t.ChatListEvents.CHATLIST_UPDATED,i.onChatReponsesUpdatedCallback,!1),i.windowFocusCallback=i.windowFocus.bind(i),window.addEventListener("focus",i.windowFocusCallback,!1),i.inputInvalidCallback=i.inputInvalid.bind(i),i.eventTarget.addEventListener(t.FlowEvents.USER_INPUT_INVALID,i.inputInvalidCallback,!1),i.flowUpdateCallback=i.onFlowUpdate.bind(i),i.eventTarget.addEventListener(t.FlowEvents.FLOW_UPDATE,i.flowUpdateCallback,!1),i}return __extends(n,e),Object.defineProperty(n.prototype,"currentTag",{get:function(){return this._currentTag},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"visible",{set:function(t){var e=this;this._visible=t,!this.el.classList.contains("animate-in")&&t?setTimeout(function(){e.el.classList.add("animate-in")},0):this.el.classList.contains("animate-in")&&!t&&this.el.classList.remove("animate-in")},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this._disabled},set:function(t){this._disabled!=t&&(this._disabled=t,t?this.el.setAttribute("disabled","disabled"):(this.setFocusOnInput(),this.el.removeAttribute("disabled")))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){var e=0,n=0,i=this.el;return t.Helpers.isInternetExlorer()?(e=i.offsetHeight,n=parseInt(i.currentStyle.marginTop,10)+parseInt(i.currentStyle.marginBottom,10),n*=2):(e=parseInt(document.defaultView.getComputedStyle(i,"").getPropertyValue("height"),10),n=parseInt(document.defaultView.getComputedStyle(i,"").getPropertyValue("margin-top"))+parseInt(document.defaultView.getComputedStyle(i,"").getPropertyValue("margin-bottom"))),e+n},enumerable:!0,configurable:!0}),n.prototype.onEnterOrSubmitButtonSubmit=function(t){void 0===t&&(t=null)},n.prototype.inputInvalid=function(t){},n.prototype.deactivate=function(){this.disabled=!0},n.prototype.reactivate=function(){this.disabled=!1},n.prototype.getFlowDTO=function(){},n.prototype.setFocusOnInput=function(){},n.prototype.onFlowStopped=function(){},n.prototype.reset=function(){},n.prototype.dealloc=function(){this.eventTarget.removeEventListener(t.ChatListEvents.CHATLIST_UPDATED,this.onChatReponsesUpdatedCallback,!1),this.onChatReponsesUpdatedCallback=null,this.eventTarget.removeEventListener(t.FlowEvents.USER_INPUT_INVALID,this.inputInvalidCallback,!1),this.inputInvalidCallback=null,window.removeEventListener("focus",this.windowFocusCallback,!1),this.windowFocusCallback=null,this.eventTarget.removeEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1),this.flowUpdateCallback=null,e.prototype.dealloc.call(this)},n.prototype.onFlowUpdate=function(e){t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail),this._currentTag=e.detail.tag},n.prototype.windowFocus=function(t){},n.prototype.onChatReponsesUpdated=function(t){t.detail.currentResponse.isRobotResponse||(this.visible=!0,this.disabled=!1,this.setFocusOnInput())},n.ERROR_TIME=2e3,n.preventAutoFocus=!1,n.hideUserInputOnNoneTextInput=!1,n}(t.BasicElement);t.UserInputElement=e,t.UserInputEvents={SUBMIT:"cf-input-user-input-submit",KEY_CHANGE:"cf-input-key-change",CONTROL_ELEMENTS_ADDED:"cf-input-control-elements-added",HEIGHT_CHANGE:"cf-input-height-change",FOCUS:"cf-input-focus",BLUR:"cf-input-blur"}}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;return i.errorTimer=0,i.initialInputHeight=0,i.shiftIsDown=!1,i._active=!1,i.cfReference=n.cfReference,i.eventTarget=n.eventTarget,i.inputElement=i.el.getElementsByTagName("textarea")[0],i.onInputFocusCallback=i.onInputFocus.bind(i),i.onInputBlurCallback=i.onInputBlur.bind(i),i.inputElement.addEventListener("focus",i.onInputFocusCallback,!1),i.inputElement.addEventListener("blur",i.onInputBlurCallback,!1),i.controlElements=new t.ControlElements({el:i.el.getElementsByTagName("cf-input-control-elements")[0],cfReference:i.cfReference,infoEl:i.el.getElementsByTagName("cf-info")[0],eventTarget:i.eventTarget}),i.keyUpCallback=i.onKeyUp.bind(i),document.addEventListener("keyup",i.keyUpCallback,!1),i.keyDownCallback=i.onKeyDown.bind(i),document.addEventListener("keydown",i.keyDownCallback,!1),i.onOriginalTagChangedCallback=i.onOriginalTagChanged.bind(i),i.eventTarget.addEventListener(t.TagEvents.ORIGINAL_ELEMENT_CHANGED,i.onOriginalTagChangedCallback,!1),i.onControlElementSubmitCallback=i.onControlElementSubmit.bind(i),i.eventTarget.addEventListener(t.ControlElementEvents.SUBMIT_VALUE,i.onControlElementSubmitCallback,!1),i.onControlElementProgressChangeCallback=i.onControlElementProgressChange.bind(i),i.eventTarget.addEventListener(t.ControlElementEvents.PROGRESS_CHANGE,i.onControlElementProgressChangeCallback,!1),i.onSubmitButtonChangeStateCallback=i.onSubmitButtonChangeState.bind(i),i.eventTarget.addEventListener(t.UserInputSubmitButtonEvents.CHANGE,i.onSubmitButtonChangeStateCallback,!1),i.submitButton=new t.UserInputSubmitButton({eventTarget:i.eventTarget}),i.el.appendChild(i.submitButton.el),n.microphoneInputObj&&(i.microphoneObj=n.microphoneInputObj,i.microphoneObj&&i.microphoneObj.init&&i.microphoneObj.init(),i.submitButton.addMicrophone(i.microphoneObj)),i}return __extends(n,e),Object.defineProperty(n.prototype,"active",{get:function(){return this.inputElement===document.activeElement||this._active},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{set:function(e){var n=this._disabled!=e;t.ConversationalForm.suppressLog||console.log("option hasChanged",e),n&&(this._disabled=e,e?(this.el.setAttribute("disabled","disabled"),this.inputElement.blur()):(this.setFocusOnInput(),this.el.removeAttribute("disabled")))},enumerable:!0,configurable:!0}),n.prototype.getInputValue=function(){var t=this.inputElement.value,e=document.createElement("div");return e.appendChild(document.createTextNode(t)),e.innerHTML},n.prototype.getFlowDTO=function(){var t;return t=this.controlElements&&this.controlElements.active?this.controlElements.getDTO():{text:this.getInputValue()},t.tag||(t.tag=this.currentTag),t.input=this,t.tag=this.currentTag,t},n.prototype.reset=function(){this.controlElements&&this.controlElements.clearTagsAndReset()},n.prototype.deactivate=function(){e.prototype.deactivate.call(this),this.microphoneObj&&(this.submitButton.active=!1)},n.prototype.reactivate=function(){e.prototype.reactivate.call(this),this.microphoneObj&&!this.submitButton.typing&&(this.submitButton.loading=!0,this.submitButton.typing=!1,this.submitButton.active=!0)},n.prototype.onFlowStopped=function(){this.submitButton.loading=!1,this.submitButton.typing&&(this.submitButton.typing=!1),this.controlElements&&this.controlElements.clearTagsAndReset(),this.disabled=!0},n.prototype.onOriginalTagChanged=function(t){this.currentTag==t.detail.tag&&this.onInputChange(),this.controlElements&&this.controlElements.active&&this.controlElements.updateStateOnElementsFromTag(t.detail.tag)},n.prototype.onInputChange=function(){if(this.active||this.controlElements.active){var e=Math.max(this.initialInputHeight,parseInt(this.inputElement.style.height,10));this.inputElement.style.height="0px",this.inputElement.style.height=(0===this.inputElement.scrollHeight?e:this.inputElement.scrollHeight)+"px",t.ConversationalForm.illustrateFlow(this,"dispatch",t.UserInputEvents.HEIGHT_CHANGE),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.HEIGHT_CHANGE,{detail:this.inputElement.scrollHeight}))}},n.prototype.inputInvalid=function(e){var n=this;t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var i=e.detail;this.inputElement.setAttribute("data-value",this.inputElement.value),this.inputElement.value="",this.el.setAttribute("error",""),this.disabled=!0,this.inputElement.setAttribute("placeholder",i.errorText||(this._currentTag?this._currentTag.errorMessage:"")),clearTimeout(this.errorTimer),this.submitButton.loading=!1,this.errorTimer=setTimeout(function(){n.disabled=!1,t.ConversationalForm.suppressLog||console.log("option, disabled 1"),n.el.removeAttribute("error"),n.inputElement.value=n.inputElement.getAttribute("data-value"),n.inputElement.setAttribute("data-value",""),n.setPlaceholder(),n.setFocusOnInput(),n.submitButton.reset(),n.controlElements&&n.controlElements.resetAfterErrorMessage()},t.UserInputElement.ERROR_TIME)},n.prototype.setPlaceholder=function(){this._currentTag?this._currentTag.inputPlaceholder?this.inputElement.setAttribute("placeholder",this._currentTag.inputPlaceholder):this.inputElement.setAttribute("placeholder","group"==this._currentTag.type?t.Dictionary.get("group-placeholder"):t.Dictionary.get("input-placeholder")):this.inputElement.setAttribute("placeholder",t.Dictionary.get("group-placeholder"))},n.prototype.checkForCorrectInputTag=function(){var t=this.inputElement.getAttribute("type"),e="password"==this._currentTag.type&&"password"!=t,n="password"!=this._currentTag.type&&"password"==t,i="email"==this._currentTag.type&&"email"!=t||"number"==this._currentTag.type&&"number"!=t;if(this.inputElement&&(e||n)&&(this.inputElement.removeEventListener("focus",this.onInputFocusCallback,!1),this.inputElement.removeEventListener("blur",this.onInputBlurCallback,!1)),e||i){var o=document.createElement("input");Array.prototype.slice.call(this.inputElement.attributes).forEach(function(t){o.setAttribute(t.name,t.value)}),o.setAttribute("autocomplete","new-password"),this.inputElement.parentNode.replaceChild(o,this.inputElement),this.inputElement=o,"number"!==this._currentTag.type&&"email"!==this._currentTag.type||(this.inputElement.type=this._currentTag.type,o.setAttribute("type",this._currentTag.type))}else if(n){var s=document.createElement("textarea");Array.prototype.slice.call(this.inputElement.attributes).forEach(function(t){s.setAttribute(t.name,t.value)}),this.inputElement.parentNode.replaceChild(s,this.inputElement),this.inputElement=s}this.inputElement&&(e||n)&&(this.inputElement.addEventListener("focus",this.onInputFocusCallback,!1),this.inputElement.addEventListener("blur",this.onInputBlurCallback,!1)),0==this.initialInputHeight&&(this.initialInputHeight=this.inputElement.offsetHeight),this.setFocusOnInput()},n.prototype.onFlowUpdate=function(n){var i=this;e.prototype.onFlowUpdate.call(this,n),this.submitButton.loading=!1,this.submitButton.typing&&(this.submitButton.typing=!1),this.el.setAttribute("tag-type",this._currentTag.type),this.checkForCorrectInputTag();var o=-1!==["password","number","email"].indexOf(this._currentTag.type);this.inputElement.setAttribute("type",o?this._currentTag.type:"input"),clearTimeout(this.errorTimer),this.el.removeAttribute("error"),this.inputElement.setAttribute("data-value",""),this.inputElement.value="",this.submitButton.loading=!1,this.setPlaceholder(),this.resetValue(),this.setFocusOnInput(),this.controlElements.reset(),"group"==this._currentTag.type?this.buildControlElements(this._currentTag.elements):this.buildControlElements([this._currentTag]),"text"!=this._currentTag.type&&"email"!=this._currentTag.type||(this.inputElement.value=this._currentTag.defaultValue.toString()),!0===this._currentTag.skipUserInput?this.el.classList.add("hide-input"):this.el.classList.remove("hide-input"),t.UserInputElement.hideUserInputOnNoneTextInput&&(this.controlElements.active?(this.el.classList.add("hide-input"),this.controlElements.focusFrom("bottom")):this.el.classList.remove("hide-input")),setTimeout(function(){i.onInputChange()},150)},n.prototype.onControlElementProgressChange=function(e){var n=e.detail;this.disabled=n==t.ControlElementProgressStates.BUSY,t.ConversationalForm.suppressLog||console.log("option, disabled 2")},n.prototype.buildControlElements=function(t){this.controlElements.buildTags(t)},n.prototype.onControlElementSubmit=function(e){t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var n=e.detail;this.controlElements.updateStateOnElements(n),this.doSubmit()},n.prototype.onSubmitButtonChangeState=function(t){this.onEnterOrSubmitButtonSubmit(t)},n.prototype.isMetaKeyPressed=function(t){t.metaKey||[91,93].indexOf(t.keyCode)},n.prototype.onKeyDown=function(e){(this.active||this.controlElements.focus)&&(this.isControlElementsActiveAndUserInputHidden()||this.isMetaKeyPressed(e)||(e.keyCode==t.Dictionary.keyCodes.shift&&(this.shiftIsDown=!0),e.keyCode!=t.Dictionary.keyCodes.enter||e.shiftKey||e.preventDefault()))},n.prototype.isControlElementsActiveAndUserInputHidden=function(){return this.controlElements&&this.controlElements.active&&t.UserInputElement.hideUserInputOnNoneTextInput},n.prototype.onKeyUp=function(e){if((this.active||this.isControlElementsActiveAndUserInputHidden()||this.controlElements.focus)&&!this.isMetaKeyPressed(e)){if(e.keyCode==t.Dictionary.keyCodes.shift)this.shiftIsDown=!1;else if(e.keyCode==t.Dictionary.keyCodes.up)e.preventDefault(),this.active&&!this.controlElements.focus&&this.controlElements.focusFrom("bottom");else if(e.keyCode==t.Dictionary.keyCodes.down)e.preventDefault(),this.active&&!this.controlElements.focus&&this.controlElements.focusFrom("top");else if(e.keyCode==t.Dictionary.keyCodes.tab){for(var n=!1,i=e.target.parentNode;null!=i;){if(i===this.cfReference.el){n=!0;break}i=i.parentNode}n||(e.preventDefault(),this.controlElements.active||this.setFocusOnInput())}if(!this.el.hasAttribute("disabled")){var o=this.getFlowDTO();if(e.keyCode==t.Dictionary.keyCodes.enter&&!e.shiftKey||e.keyCode==t.Dictionary.keyCodes.space)if(e.keyCode==t.Dictionary.keyCodes.enter&&this.active)e.preventDefault(),this.onEnterOrSubmitButtonSubmit();else if(e.keyCode==t.Dictionary.keyCodes.enter||e.keyCode==t.Dictionary.keyCodes.space){e.preventDefault();var s="group"==this._currentTag.type?this._currentTag.getGroupTagType():this._currentTag.type;if("select"==s||"checkbox"==s){var r=this._currentTag;"checkbox"==s||r.multipleChoice?(this.active||this.isControlElementsActiveAndUserInputHidden())&&e.keyCode==t.Dictionary.keyCodes.enter?this.submitButton.click():(this.active||this.controlElements.active||this.isControlElementsActiveAndUserInputHidden()||(this.resetValue(),this.setFocusOnInput()),this.dispatchKeyChange(o,e.keyCode)):this.dispatchKeyChange(o,e.keyCode)}else"group"==this._currentTag.type&&this.dispatchKeyChange(o,e.keyCode)}else e.keyCode==t.Dictionary.keyCodes.space&&document.activeElement&&this.dispatchKeyChange(o,e.keyCode);else e.keyCode!=t.Dictionary.keyCodes.shift&&e.keyCode!=t.Dictionary.keyCodes.tab&&this.dispatchKeyChange(o,e.keyCode);this.onInputChange()}}},n.prototype.dispatchKeyChange=function(e,n){this.submitButton.typing=e.text&&e.text.length>0,t.ConversationalForm.illustrateFlow(this,"dispatch",t.UserInputEvents.KEY_CHANGE,e),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.KEY_CHANGE,{detail:{dto:e,keyCode:n,inputFieldActive:this.active}}))},n.prototype.windowFocus=function(t){e.prototype.windowFocus.call(this,t),this.setFocusOnInput()},n.prototype.onInputBlur=function(e){this._active=!1,this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.BLUR))},n.prototype.onInputFocus=function(e){this._active=!0,this.onInputChange(),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.FOCUS))},n.prototype.setFocusOnInput=function(){t.UserInputElement.preventAutoFocus||this.el.classList.contains("hide-input")||this.inputElement.focus()},n.prototype.onEnterOrSubmitButtonSubmit=function(e){void 0===e&&(e=null);var n=this.controlElements.active&&t.UserInputElement.hideUserInputOnNoneTextInput;(this.active||n)&&this.controlElements.highlighted?this.controlElements.clickOnHighlighted():this._currentTag?"file"==this._currentTag.type&&e?this.controlElements.getElement(0).triggerFileSelect():this.doSubmit():this.eventTarget.cf.addUserChatResponse(this.inputElement.value)},n.prototype.doSubmit=function(){var e=this.getFlowDTO();this.submitButton.loading=!0,this.disabled=!0,this.el.removeAttribute("error"),this.inputElement.setAttribute("data-value",""),t.ConversationalForm.illustrateFlow(this,"dispatch",t.UserInputEvents.SUBMIT,e),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.SUBMIT,{detail:e}))},n.prototype.resetValue=function(){this.inputElement.value="",this.onInputChange()},n.prototype.dealloc=function(){this.inputElement.removeEventListener("blur",this.onInputBlurCallback,!1),this.onInputBlurCallback=null,this.inputElement.removeEventListener("focus",this.onInputFocusCallback,!1),this.onInputFocusCallback=null,document.removeEventListener("keydown",this.keyDownCallback,!1),this.keyDownCallback=null,document.removeEventListener("keyup",this.keyUpCallback,!1),this.keyUpCallback=null,this.eventTarget.removeEventListener(t.ControlElementEvents.SUBMIT_VALUE,this.onControlElementSubmitCallback,!1),this.onControlElementSubmitCallback=null,this.submitButton.el.removeEventListener(t.UserInputSubmitButtonEvents.CHANGE,this.onSubmitButtonChangeStateCallback,!1),this.onSubmitButtonChangeStateCallback=null,this.submitButton.dealloc(),this.submitButton=null,e.prototype.dealloc.call(this)},n.prototype.getTemplate=function(){return this.customTemplate||'\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\n\t\t\t\t\n\n\t\t\t\n\t\t\t'},n}(t.UserInputElement);t.UserTextInput=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){t.ChatResponseEvents={USER_ANSWER_CLICKED:"cf-on-user-answer-clicked"};var e=function(e){function n(t){var n=e.call(this,t)||this;return n.readyTimer=0,n.container=t.container,n.uiOptions=t.cfReference.uiOptions,n._tag=t.tag,n}return __extends(n,e),Object.defineProperty(n.prototype,"tag",{get:function(){return this._tag},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"added",{get:function(){return!!this.el.parentNode.parentNode},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this.el.classList.contains("disabled")},set:function(t){t?this.el.classList.add("disabled"):this.el.classList.remove("disabled")},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"visible",{set:function(t){var e=this;this.el.offsetWidth,setTimeout(function(){return t?e.el.classList.add("show"):e.el.classList.remove("show")},100)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"strippedSesponse",{get:function(){var t=this.response,e=document.createElement("div");return e.innerHTML=t,e.textContent||e.innerText||""},enumerable:!0,configurable:!0}),n.prototype.whenReady=function(t){this.onReadyCallback=t},n.prototype.setValue=function(e){void 0===e&&(e=null),this.visible||(this.visible=!0);this.el.hasAttribute("thinking");if(e){if(this.response=this.originalResponse=e.text,this.processResponseAndSetText(),this.responseLink&&!this.isRobotResponse&&this.responseLink.processResponseAndSetText(),e&&e.controlElements&&e.controlElements[0])switch(e.controlElements[0].type){case"UploadFileUI":this.textEl.classList.add("file-icon")}this.isRobotResponse||this.onClickCallback||(this.onClickCallback=this.onClick.bind(this),this.el.addEventListener(t.Helpers.getMouseEvent("click"),this.onClickCallback,!1))}else this.setToThinking()},n.prototype.show=function(){this.visible=!0,this.disabled=!1,this.response?this.checkForEditMode():this.setToThinking()},n.prototype.updateThumbnail=function(t){var e=this.el.getElementsByTagName("thumb")[0];if(0===t.indexOf("text:")){var n=e.getElementsByTagName("span")[0];n.innerHTML=t.split("text:")[1],n.setAttribute("length",t.length.toString())}else this.image=t,e.style.backgroundImage='url("'+this.image+'")'},n.prototype.setLinkToOtherReponse=function(t){this.responseLink=t},n.prototype.processResponseAndSetText=function(){var t=this;if(this.originalResponse){var e=this.originalResponse;if(this._tag&&"password"==this._tag.type&&!this.isRobotResponse){for(var i="",o=0;o"+n+"

";var e=t.textEl.getElementsByTagName("p");e[e.length-1].offsetWidth,e[e.length-1].classList.add("show"),t.scrollTo() -},l+(e+1)*u.uiOptions.robot.chainedResponseTime)}(h);this.readyTimer=setTimeout(function(){t.onReadyCallback&&t.onReadyCallback(),t.onReadyCallback=null,t._tag&&!0===t._tag.skipUserInput&&setTimeout(function(){t._tag.flowManager.nextStep(),t._tag.skipUserInput=!1},t.uiOptions.robot.chainedResponseTime)},l+c.length*this.uiOptions.robot.chainedResponseTime)}else{this.tryClearThinking(),this.textEl.innerHTML="

"+e+"

";var p=this.textEl.getElementsByTagName("p");p[p.length-1].offsetWidth,p[p.length-1].classList.add("show"),this.scrollTo()}this.parsedResponse=e,this.addSelf(),this.textEl.removeAttribute("value-added"),setTimeout(function(){t.textEl.setAttribute("value-added",""),t.el.classList.add("peak-thumb")},0),this.checkForEditMode(),this.response=e.split("&&").join(" ")}},n.prototype.scrollTo=function(){var t=this.el.offsetTop,e=this.el.offsetHeight;!this.container&&this.el&&(this.container=this.el),this.container.scrollTop=t+e+this.container.scrollTop},n.prototype.checkForEditMode=function(){this.isRobotResponse||this.el.hasAttribute("thinking")||(this.el.classList.add("can-edit"),this.disabled=!1)},n.prototype.tryClearThinking=function(){this.el.hasAttribute("thinking")&&(this.textEl.innerHTML="",this.el.removeAttribute("thinking"))},n.prototype.setToThinking=function(){(this.isRobotResponse&&0!==this.uiOptions.robot.robotResponseTime||!this.isRobotResponse&&this.cfReference.uiOptions.user.showThinking&&!this._tag.skipUserInput)&&(this.textEl.innerHTML=n.THINKING_MARKUP,this.el.classList.remove("can-edit"),this.el.setAttribute("thinking","")),(this.cfReference.uiOptions.user.showThinking||this.cfReference.uiOptions.user.showThumb)&&this.addSelf()},n.prototype.addSelf=function(){this.el.parentNode!=this.container&&this.container.appendChild(this.el)},n.prototype.onClick=function(e){this.setToThinking(),t.ConversationalForm.illustrateFlow(this,"dispatch",t.ChatResponseEvents.USER_ANSWER_CLICKED,e),this.eventTarget.dispatchEvent(new CustomEvent(t.ChatResponseEvents.USER_ANSWER_CLICKED,{detail:this._tag}))},n.prototype.setData=function(t){this.image=t.image,this.response=this.originalResponse=t.response,this.isRobotResponse=t.isRobotResponse,e.prototype.setData.call(this,t)},n.prototype.onElementCreated=function(){var t=this;this.textEl=this.el.getElementsByTagName("text")[0],this.updateThumbnail(this.image),this.isRobotResponse||null!=this.response?setTimeout(function(){t.setValue({text:t.response})},0):this.cfReference.uiOptions.user.showThumb&&this.el.classList.add("peak-thumb")},n.prototype.dealloc=function(){clearTimeout(this.readyTimer),this.container=null,this.uiOptions=null,this.onReadyCallback=null,this.onClickCallback&&(this.el.removeEventListener(t.Helpers.getMouseEvent("click"),this.onClickCallback,!1),this.onClickCallback=null),e.prototype.dealloc.call(this)},n.prototype.getTemplate=function(){return'\n\t\t\t\t\n\t\t\t\t\n\t\t\t'},n.THINKING_MARKUP="

...

",n}(t.BasicElement);t.ChatResponse=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){t.ChatListEvents={CHATLIST_UPDATED:"cf-chatlist-updated"};var e=function(e){function n(n){var i=e.call(this,n)||this;return i.updateTimer=0,t.ChatResponse.list=i,i.responses=[],i.flowUpdateCallback=i.onFlowUpdate.bind(i),i.eventTarget.addEventListener(t.FlowEvents.FLOW_UPDATE,i.flowUpdateCallback,!1),i.userInputUpdateCallback=i.onUserInputUpdate.bind(i),i.eventTarget.addEventListener(t.FlowEvents.USER_INPUT_UPDATE,i.userInputUpdateCallback,!1),i.onInputKeyChangeCallback=i.onInputKeyChange.bind(i),i.eventTarget.addEventListener(t.UserInputEvents.KEY_CHANGE,i.onInputKeyChangeCallback,!1),i.onInputHeightChangeCallback=i.onInputHeightChange.bind(i),i.eventTarget.addEventListener(t.UserInputEvents.HEIGHT_CHANGE,i.onInputHeightChangeCallback,!1),i.onControlElementsResizedCallback=i.onControlElementsResized.bind(i),i.eventTarget.addEventListener(t.ControlElementsEvents.ON_RESIZE,i.onControlElementsResizedCallback,!1),i.onControlElementsChangedCallback=i.onControlElementsChanged.bind(i),i.eventTarget.addEventListener(t.ControlElementsEvents.CHANGED,i.onControlElementsChangedCallback,!1),i}return __extends(n,e),n.prototype.onInputHeightChange=function(e){var n=e.detail.dto;t.ConversationalForm.illustrateFlow(this,"receive",e.type,n),this.onInputElementChanged()},n.prototype.onInputKeyChange=function(e){var n=e.detail.dto;t.ConversationalForm.illustrateFlow(this,"receive",e.type,n)},n.prototype.onUserInputUpdate=function(e){if(t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail),this.currentUserResponse){var n=e.detail;this.setCurrentUserResponse(n)}},n.prototype.addInput=function(t){this.input=t},n.prototype.onControlElementsChanged=function(t){this.onInputElementChanged()},n.prototype.onControlElementsResized=function(e){t.ConversationalForm.illustrateFlow(this,"receive",t.ControlElementsEvents.ON_RESIZE);var n=this.currentResponse;if(n){if(!n.added)for(var i=this.responses.indexOf(n);i>=0;i--){var o=this.responses[i];if(o.added){n=o;break}}n.scrollTo()}this.onInputElementChanged()},n.prototype.onInputElementChanged=function(){var t=this.cfReference.el.offsetHeight,e=this.input.height,n=t-e;this.el.style.height=n+"px"},n.prototype.onFlowUpdate=function(e){var n=this;t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var i=e.detail.tag;this.currentResponse&&(this.currentResponse.disabled=!1),this.containsTagResponse(i)&&!e.detail.ignoreExistingTag?this.onUserWantsToEditTag(i):setTimeout(function(){var t=n.createResponse(!0,i,i.question);t.whenReady(function(){n.currentUserResponse=n.createResponse(!1,i),t.scrollTo()}),n.currentUserResponse&&(n.currentUserResponse.setLinkToOtherReponse(t),t.setLinkToOtherReponse(n.currentUserResponse))},0===this.responses.length?500:0)},n.prototype.containsTagResponse=function(t){for(var e=0;e2&&(this.responses[this.responses.length-1].isRobotResponse||this.responses.pop().dealloc(),this.responses.pop().dealloc()),this.currentUserResponse=e,this.currentResponse=this.responses[this.responses.length-1],this.onListUpdate(this.currentUserResponse))},n.prototype.onListUpdate=function(e){var n=this;clearTimeout(this.updateTimer),this.updateTimer=setTimeout(function(){n.eventTarget.dispatchEvent(new CustomEvent(t.ChatListEvents.CHATLIST_UPDATED,{detail:n})),e.show()},0)},n.prototype.clearFrom=function(t){for(t*=2,t+=t%2;this.responses.length>t;)this.responses.pop().dealloc()},n.prototype.setCurrentUserResponse=function(e){this.flowDTOFromUserInputUpdate=e,!this.flowDTOFromUserInputUpdate.text&&e.tag&&("group"==e.tag.type?this.flowDTOFromUserInputUpdate.text=t.Dictionary.get("user-reponse-missing-group"):"password"!=e.tag.type&&(this.flowDTOFromUserInputUpdate.text=t.Dictionary.get("user-reponse-missing"))),this.currentUserResponse.setValue(this.flowDTOFromUserInputUpdate)},n.prototype.getResponses=function(){return this.responses},n.prototype.updateThumbnail=function(e,n){t.Dictionary.set(e?"robot-image":"user-image",e?"robot":"human",n);for(var i=e?t.Dictionary.getRobotResponse("robot-image"):t.Dictionary.get("user-image"),o=0;o\n\t\t\t\t\t\t\n\t\t\t\t\t"},n.prototype.dealloc=function(){this.eventTarget.removeEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1),this.flowUpdateCallback=null,this.eventTarget.removeEventListener(t.FlowEvents.USER_INPUT_UPDATE,this.userInputUpdateCallback,!1),this.userInputUpdateCallback=null,this.eventTarget.removeEventListener(t.UserInputEvents.KEY_CHANGE,this.onInputKeyChangeCallback,!1),this.onInputKeyChangeCallback=null,e.prototype.dealloc.call(this)},n}(t.BasicElement);t.ChatList=e}(cf||(cf={}));var cf;!function(t){t.FlowEvents={USER_INPUT_UPDATE:"cf-flow-user-input-update",USER_INPUT_INVALID:"cf-flow-user-input-invalid",FLOW_UPDATE:"cf-flow-update"};var e=function(){function e(e){this.stopped=!1,this.maxSteps=0,this.step=0,this.savedStep=-1,this.stepTimer=0,this.ignoreExistingTags=!1,this.cfReference=e.cfReference,this.eventTarget=e.eventTarget,this.flowStepCallback=e.flowStepCallback,this.setTags(e.tags),this.userInputSubmitCallback=this.userInputSubmit.bind(this),this.eventTarget.addEventListener(t.UserInputEvents.SUBMIT,this.userInputSubmitCallback,!1)}return Object.defineProperty(e.prototype,"currentTag",{get:function(){return this.tags[this.step]},enumerable:!0,configurable:!0}),e.prototype.userInputSubmit=function(e){var n=this;t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var i=e.detail;i.tag||(i.tag=this.currentTag);var o=this.currentTag.setTagValueAndIsValid(i),s=!1,r=!1,a=function(){return n.currentTag.validationCallback&&"function"==typeof n.currentTag.validationCallback&&!s&&o?(s=!0,void n.currentTag.validationCallback(i,function(){o=!0,a()},function(t){o=!1,t&&(i.errorText=t),a()})):n.flowStepCallback&&"function"==typeof n.flowStepCallback&&!r&&o?(r=!0,void n.flowStepCallback(i,function(){o=!0,a()},function(t){o=!1,t&&(i.errorText=t),a()})):void(o?(t.ConversationalForm.illustrateFlow(n,"dispatch",t.FlowEvents.USER_INPUT_UPDATE,i),i.input&&(i=i.input.getFlowDTO()),n.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_UPDATE,{detail:i})),setTimeout(function(){return n.nextStep()},t.ConversationalForm.animationsEnabled?250:0)):(t.ConversationalForm.illustrateFlow(n,"dispatch",t.FlowEvents.USER_INPUT_INVALID,i),n.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:i}))))};a()},e.prototype.startFrom=function(t,e){void 0===e&&(e=!1),this.step="number"==typeof t?t:this.tags.indexOf(t),this.ignoreExistingTags=e,this.ignoreExistingTags?this.showStep():this.editTag(this.tags[this.step])},e.prototype.areConditionsInFlowFullfilled=function(e,n){this.activeConditions||(this.activeConditions=[]);for(var i=0,o=0;o0){this.savedStep=-1,this.cfReference.chatList.clearFrom(this.step+1);for(var e=this.tags.indexOf(t),n=e+1;n0&&(this.step==this.maxSteps?this.cfReference.doSubmitForm():(this.step%=this.maxSteps,this.currentTag.disabled?this.skipStep():this.showStep()))},e.prototype.showStep=function(){var e=this;this.stopped||(t.ConversationalForm.illustrateFlow(this,"dispatch",t.FlowEvents.FLOW_UPDATE,this.currentTag),this.currentTag.refresh(),setTimeout(function(){e.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.FLOW_UPDATE,{detail:{tag:e.currentTag,ignoreExistingTag:e.ignoreExistingTags}}))},0))},e.STEP_TIME=1e3,e}();t.FlowManager=e}(cf||(cf={}));var cf;!function(cf_1){var ConversationalForm=function(){function ConversationalForm(options){if(this.version="0.9.81",this.cdnPath="https://cdn.jsdelivr.net/gh/space10-community/conversational-form@{version}/dist/",this.isDevelopment=!1,this.loadExternalStyleSheet=!0,this.preventAutoAppend=!1,this.preventAutoStart=!1,window.ConversationalForm=this,this.cdnPath=this.cdnPath.split("{version}").join(this.version),"boolean"==typeof options.suppressLog&&(ConversationalForm.suppressLog=options.suppressLog),ConversationalForm.suppressLog||console.log("Conversational Form > version:",this.version),ConversationalForm.suppressLog||console.log("Conversational Form > options:",options),window.ConversationalForm[this.createId]=this,options.eventDispatcher&&(this._eventTarget=options.eventDispatcher),this.eventTarget.cf||(this.eventTarget.cf=this),options.flowStepCallback&&(this.flowStepCallback=options.flowStepCallback),this.isDevelopment=ConversationalForm.illustrateAppFlow=!!document.getElementById("conversational-form-development"),(this.isDevelopment||0==options.loadExternalStyleSheet)&&(this.loadExternalStyleSheet=!1),isNaN(options.scrollAccerlation)||(cf_1.ScrollController.accerlation=options.scrollAccerlation),this.preventAutoStart=options.preventAutoStart,this.preventAutoAppend=options.preventAutoAppend,!options.formEl)throw new Error("Conversational Form error, the formEl needs to be defined.");this.formEl=options.formEl,this.formEl.setAttribute("cf-create-id",this.createId),!0===options.hideUserInputOnNoneTextInput&&(cf_1.UserInputElement.hideUserInputOnNoneTextInput=!0),this.submitCallback=options.submitCallback,this.submitCallback&&"string"==typeof this.submitCallback&&(this.submitCallback=eval(this.submitCallback)),""==this.formEl.getAttribute("cf-no-animation")&&(ConversationalForm.animationsEnabled=!1),(options.preventAutoFocus||""==this.formEl.getAttribute("cf-prevent-autofocus"))&&(cf_1.UserInputElement.preventAutoFocus=!0),this.dictionary=new cf_1.Dictionary({data:options.dictionaryData,robotData:options.dictionaryRobot,userImage:options.userImage,robotImage:options.robotImage}),this.context=options.context?options.context:document.body,this.tags=options.tags,options.microphoneInput&&(options.microphoneInput.init&&options.microphoneInput.input||(console.warn("Conversational Form: microphoneInput is not correctly setup",options.microphoneInput),options.microphoneInput=null)),this.microphoneInputObj=options.microphoneInput,this.uiOptions=cf_1.Helpers.extendObject(cf_1.UserInterfaceDefaultOptions,options.userInterfaceOptions||{}),this.init()}return Object.defineProperty(ConversationalForm.prototype,"createId",{get:function(){return this._createId||(this._createId=(new Date).getTime().toString()),this._createId},enumerable:!0,configurable:!0}),Object.defineProperty(ConversationalForm.prototype,"eventTarget",{get:function(){return this._eventTarget||(this._eventTarget=new cf_1.EventDispatcher(this)),this._eventTarget},enumerable:!0,configurable:!0}),ConversationalForm.prototype.init=function(){if(this.loadExternalStyleSheet){var t=document.head||document.getElementsByTagName("head")[0],e=document.createElement("link"),n=this.cdnPath+"conversational-form.min.css";e.type="text/css",e.media="all",e.setAttribute("rel","stylesheet"),e.setAttribute("href",n),t.appendChild(e)}else this.isDevelopment=!0;if(-1==["fixed","absolute","relative"].indexOf(window.getComputedStyle(this.context).getPropertyValue("position").toLowerCase())&&(this.context.style.position="relative"),!this.tags||0==this.tags.length){this.tags=[];for(var i=[].slice.call(this.formEl.querySelectorAll("input, select, button, textarea, cf-robot-message"),0),o=0;o0)for(var o in e)if(e[o].length>0){var s=e[o][0].domElement.parentNode;s&&"fieldset"!==s.tagName.toLowerCase()&&(s=s.parentNode,function(t){return t&&"fieldset"!==t.tagName.toLowerCase()&&!t.hasAttribute("cf-questions")}(s)&&(s=null));for(var r=new cf_1.TagGroup({fieldset:s,elements:e[o]}),n=0;n0){for(var n=0;n0||!!navigator.userAgent.match(/Trident.*rv\:11\./)},t.getValuesOfBars=function(t){var e=t.split("||");return e.length<=1&&(e=t.split("|")),e},t.setTransform=function(t,e){t.style["-webkit-transform"]=e,t.style["-moz-transform"]=e,t.style["-ms-transform"]=e,t.style.transform=e},t.extendObject=function(t,e){for(var n in e)e[n]&&e[n].constructor&&e[n].constructor===Object?(t[n]=t[n]||{},arguments.callee(t[n],e[n])):t[n]=e[n];return t},t.caniuse={fileReader:function(){return!!(window.File&&window.FileReader&&window.FileList&&window.Blob)}},t}();t.Helpers=e}(cf||(cf={}));var cf;!function(t){var e=function(){function t(t){void 0===t&&(t=null),this._cf=t,this.target=document.createDocumentFragment()}return Object.defineProperty(t.prototype,"cf",{get:function(){return this._cf},set:function(t){this._cf=t},enumerable:!0,configurable:!0}),t.prototype.addEventListener=function(t,e,n){return this.target.addEventListener(t,e,n)},t.prototype.dispatchEvent=function(t){return this.target.dispatchEvent(t)},t.prototype.removeEventListener=function(t,e,n){this.target.removeEventListener(t,e,n)},t}();t.EventDispatcher=e}(cf||(cf={}));var cf;!function(t){var e=function(){function t(){}return t.parseTag=function(t){var e=document.createElement(t.tag);e.setAttribute("cf-formless","");for(var n in t)"tag"!==n&&"children"!==n&&e.setAttribute(n,t[n]);return e},t.parseGroupTag=function(e){for(var n=t.parseTag(e),i=e.children,o=0;o0)for(var r=0;r':"")+t.Helpers.getInnerTextOfElement(this.el)}else e=t.Helpers.getInnerTextOfElement(this.el);return e},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"positionVector",{get:function(){return this._positionVector},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"tabIndex",{set:function(t){this.el.tabIndex=t},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"highlight",{get:function(){return this.el.classList.contains("highlight")},set:function(t){t?this.el.classList.add("highlight"):this.el.classList.remove("highlight")},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"focus",{get:function(){return this._focus},set:function(t){this._focus=t,this._focus?this.el.focus():this.el.blur()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"visible",{get:function(){return!this.el.classList.contains("hide")},set:function(t){t?this.el.classList.remove("hide"):(this.el.classList.add("hide"),this.tabIndex=-1,this.highlight=!1)},enumerable:!0,configurable:!0}),n.prototype.onBlur=function(t){this._focus=!1},n.prototype.onFocus=function(e){this._focus=!0,t.ConversationalForm.illustrateFlow(this,"dispatch",t.ControlElementEvents.ON_FOCUS,this.referenceTag),this.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.ON_FOCUS,{detail:this.positionVector}))},n.prototype.hasImage=function(){return!1},n.prototype.calcPosition=function(){var t=parseInt(window.getComputedStyle(this.el).getPropertyValue("margin-right"),10);this._positionVector={height:this.el.offsetHeight,width:this.el.offsetWidth+t,x:this.el.offsetLeft,y:this.el.offsetTop,el:this},this._positionVector.centerX=this._positionVector.x+.5*this._positionVector.width,this._positionVector.centerY=this._positionVector.y+.5*this._positionVector.height},n.prototype.setData=function(t){this.referenceTag=t.referenceTag,e.prototype.setData.call(this,t)},n.prototype.animateIn=function(){clearTimeout(this.animateInTimer),this.el.classList.add("animate-in")},n.prototype.animateOut=function(){this.el.classList.add("animate-out")},n.prototype.onChoose=function(){t.ConversationalForm.illustrateFlow(this,"dispatch",t.ControlElementEvents.SUBMIT_VALUE,this.referenceTag),this.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.SUBMIT_VALUE,{detail:this}))},n.prototype.dealloc=function(){this.el.removeEventListener("blur",this.onBlurCallback,!1),this.onBlurCallback=null,this.el.removeEventListener("focus",this.onFocusCallback,!1),this.onFocusCallback=null,e.prototype.dealloc.call(this)},n}(t.BasicElement);t.ControlElement=e}(cf||(cf={}));var cf;!function(t){t.ControlElementsEvents={ON_RESIZE:"cf-on-control-elements-resize",CHANGED:"cf-on-control-elements-changed"};var e=function(){function e(e){this.animateInFromReponseTimer=0,this.ignoreKeyboardInput=!1,this.rowIndex=-1,this.columnIndex=0,this.elementWidth=0,this.filterListNumberOfVisible=0,this.listWidth=0,this.el=e.el,this.eventTarget=e.eventTarget,this.cfReference=e.cfReference,this.list=this.el.getElementsByTagName("cf-list")[0],this.infoElement=e.infoEl,this.onScrollCallback=this.onScroll.bind(this),this.el.addEventListener("scroll",this.onScrollCallback,!1),this.onResizeCallback=this.onResize.bind(this),window.addEventListener("resize",this.onResizeCallback,!1),this.onElementFocusCallback=this.onElementFocus.bind(this),this.eventTarget.addEventListener(t.ControlElementEvents.ON_FOCUS,this.onElementFocusCallback,!1),this.onElementLoadedCallback=this.onElementLoaded.bind(this),this.eventTarget.addEventListener(t.ControlElementEvents.ON_LOADED,this.onElementLoadedCallback,!1),this.onChatReponsesUpdatedCallback=this.onChatReponsesUpdated.bind(this),this.eventTarget.addEventListener(t.ChatListEvents.CHATLIST_UPDATED,this.onChatReponsesUpdatedCallback,!1),this.onUserInputKeyChangeCallback=this.onUserInputKeyChange.bind(this),this.eventTarget.addEventListener(t.UserInputEvents.KEY_CHANGE,this.onUserInputKeyChangeCallback,!1),this.userInputUpdateCallback=this.onUserInputUpdate.bind(this),this.eventTarget.addEventListener(t.FlowEvents.USER_INPUT_UPDATE,this.userInputUpdateCallback,!1),this.listScrollController=new t.ScrollController({interactionListener:this.el,listToScroll:this.list,eventTarget:this.eventTarget,listNavButtons:this.el.getElementsByTagName("cf-list-button")})}return Object.defineProperty(e.prototype,"active",{get:function(){return this.elements&&this.elements.length>0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"focus",{get:function(){if(!this.elements)return!1;for(var t=this.getElements(),e=0;ethis.tableableRows[this.rowIndex].length-1&&(this.columnIndex=0),!0):(this.resetTabList(),!1)},e.prototype.updateRowIndex=function(t){var e=this.rowIndex;if(this.rowIndex+=t,this.tableableRows[this.rowIndex])for(var n=this.tableableRows[e]?this.tableableRows[e][this.columnIndex].positionVector.centerX:0,i=this.tableableRows[this.rowIndex],o=1e13,s=0;sMath.abs(n-r.positionVector.centerX)&&(o=Math.abs(n-r.positionVector.centerX),this.columnIndex=s)}},e.prototype.resetTabList=function(){this.rowIndex=-1,this.columnIndex=-1},e.prototype.onUserInputUpdate=function(t){if(this.el.classList.remove("animate-in"),this.infoElement.classList.remove("show"),this.elements)for(var e=this.getElements(),n=0;n1){for(var o=[],s=0;s0&&(o[0].highlight=!0)}},e.prototype.clickOnHighlighted=function(){for(var t=this.getElements(),e=0;e0){this.el.classList.contains("animate-in")||this.el.classList.add("animate-in");for(var e=0;e0&&"OptionsList"==this.elements[0].type?this.elements[0].elements:this.elements},e.prototype.buildTabableRows=function(){this.tableableRows=[],this.resetTabList();var t=this.getElements();if(this.el.classList.contains("two-row")){this.tableableRows[0]=[],this.tableableRows[1]=[];for(var e=0;e0)switch(this.elements[0].type){case"CheckboxButton":for(var n=0,i=[],o=0;o1)break}for(var o=0;o1&&(s.partOfSeveralChoices=!0),i.push(s.value)),e.controlElements.push(s)}e.text=t.Dictionary.parseAndGetMultiValueString(i);break;case"RadioButton":for(var o=0;o0;)this.elements.pop().dealloc();this.list.innerHTML="",this.onListChanged()},e.prototype.buildTags=function(e){var n=this;this.disabled=!1;this.el.parentNode.getElementsByTagName("ul")[0],this.el.parentNode.getElementsByTagName("ul")[1];this.clearTagsAndReset(),this.elements=[];for(var i=0;i0){var s=this.elements[this.elements.length-1];this.list.appendChild(s.el)}}var r=this.elements[0]&&"OptionsList"==this.elements[0].type;this.filterListNumberOfVisible=r?this.elements[0].elements.length:e.length,new Promise(function(t,e){return n.resize(t,e)}).then(function(){var e=n.list.offsetHeight,i={height:e};n.onListChanged(),t.ConversationalForm.illustrateFlow(n,"dispatch",t.UserInputEvents.CONTROL_ELEMENTS_ADDED,i),n.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.CONTROL_ELEMENTS_ADDED,{detail:i}))})},e.prototype.onResize=function(t){this.resize()},e.prototype.resize=function(e,n){this.list.style.width="100%",this.el.classList.remove("resized"),this.el.classList.remove("one-row"),this.el.classList.remove("two-row"),this.elementWidth=0,this.listWidth=0;var i=this.getElements();if(i&&i.length>0){for(var o=[],s=[],r=!1,a=0;ac;u&&!r?(this.el.classList.add("two-row"),this.listWidth=Math.max(c,Math.round(o[Math.floor(o.length/2)]+50)),this.list.style.width=this.listWidth+"px"):this.el.classList.add("one-row");for(var a=0;ac;for(var h=i.slice(),p=h.sort(function(t,e){var n=t.positionVector.y>e.positionVector.y;return t.positionVector.x==e.positionVector.x?n?1:-1:t.positionVector.x0&&(this.xTarget+=(0-this.xTarget)*t.Helpers.lerp(e.accerlation,.3,.8)),this.xTargetthis.max&&(this.nextButton.classList.contains("active")||this.nextButton.classList.add("active"),this.nextButton.classList.contains("cf-gradient")||this.nextButton.classList.add("cf-gradient")),i<=this.max&&(this.nextButton.classList.contains("active")&&this.nextButton.classList.remove("active"),this.nextButton.classList.contains("cf-gradient")&&this.nextButton.classList.remove("cf-gradient"));var o=this.x;t.Helpers.setTransform(this.listToScroll,"translateX("+o+"px)"),(this.interacting||Math.abs(this.x-this.xTarget)>.02&&!this.interacting)&&(this.rAF=window.requestAnimationFrame(function(){return n.render()}))},e.prototype.setScroll=function(t,e){this.xTarget=this.visibleAreaWidth==this.listWidth?0:t,this.render()},e.prototype.pushDirection=function(t){this.inputAccerlationTarget+=5e3*t,this.render()},e.prototype.dealloc=function(){this.prevButton.removeEventListener("click",this.onListNavButtonsClickCallback,!1),this.nextButton.removeEventListener("click",this.onListNavButtonsClickCallback,!1),this.onListNavButtonsClickCallback=null,this.prevButton=null,this.nextButton=null,document.removeEventListener("mouseleave",this.documentLeaveCallback,!1),document.removeEventListener(t.Helpers.getMouseEvent("mouseup"),this.documentLeaveCallback,!1),this.interactionListener.removeEventListener(t.Helpers.getMouseEvent("mousedown"),this.onInteractStartCallback,!1),this.interactionListener.removeEventListener(t.Helpers.getMouseEvent("mouseup"),this.onInteractEndCallback,!1),this.interactionListener.removeEventListener(t.Helpers.getMouseEvent("mousemove"),this.onInteractMoveCallback,!1),this.documentLeaveCallback=null,this.onInteractStartCallback=null,this.onInteractEndCallback=null,this.onInteractMoveCallback=null},e.prototype.reset=function(){this.interacting=!1,this.startX=0,this.startXTarget=this.startX,this.inputAccerlation=0,this.x=0,this.xTarget=0,t.Helpers.setTransform(this.listToScroll,"translateX(0px)"),this.render(),this.prevButton.classList.remove("active"),this.nextButton.classList.remove("active")},e.prototype.resize=function(t,e){this.reset(),this.visibleAreaWidth=e,this.listWidth=Math.max(e,t),this.max=-1*(this.listWidth-this.visibleAreaWidth),this.render()},e.accerlation=.1,e}();t.ScrollController=e}(cf||(cf={}));var cf;!function(t){var e=function(){function e(t){this.data={"user-image":"https://cf-4053.kxcdn.com/conversational-form/human.png","entry-not-found":"Dictionary item not found.","awaiting-mic-permission":"Awaiting mic permission","user-audio-reponse-invalid":"I didn't get that, try again.","microphone-terminal-error":"Audio input not supported","input-placeholder":"Type your answer here ...","group-placeholder":"Type to filter list ...","input-placeholder-error":"Your input is not correct ...","input-placeholder-required":"Input is required ...","input-placeholder-file-error":"File upload failed ...","input-placeholder-file-size-error":"File size too big ...","input-no-filter":"No results found for {input-value}","user-reponse-and":" and ","user-reponse-missing":"Missing input ...","user-reponse-missing-group":"Nothing selected ...",general:"General type1||General type2","icon-type-file":""},this.robotData={"robot-image":"https://cf-4053.kxcdn.com/conversational-form/robot.png",input:"Please write some text.",text:"Please write some text.",checkbox:"Select as many as you want.", +name:"What's your name?",email:"Need your e-mail.",password:"Please provide password",tel:"What's your phone number?",radio:"I need you to select one of these.",select:"Choose any of these options.",file:"Select a file to upload.",general:"General1||General2||General3.."},e.instance=this,t&&t.data&&(this.data=this.validateAndSetNewData(t.data,this.data)),t.userImage&&(this.data["user-image"]=t.userImage),t.robotImage&&(this.robotData["robot-image"]=t.robotImage),t&&t.robotData&&(this.robotData=this.validateAndSetNewData(t.robotData,this.robotData))}return e.get=function(n){var i=e.instance,o=i.data[n];if(o){var s=t.Helpers.getValuesOfBars(o);o=s[Math.floor(Math.random()*s.length)]}else o=i.data["entry-not-found"];return o},e.set=function(t,n,i){var o=e.instance,s="robot"==n?o.robotData:o.data;return s[t]=i,s[t]},e.getRobotResponse=function(n){var i=e.instance,o=i.robotData[n];if(o){var s=t.Helpers.getValuesOfBars(o);o=s[Math.floor(Math.random()*s.length)]}else{var r=t.Helpers.getValuesOfBars(i.robotData.general);o=r[Math.floor(Math.random()*r.length)]}return o},e.parseAndGetMultiValueString=function(t){for(var n="",i=0;i1&&i==t.length-2?e.get("user-reponse-and"):", ";n+=o+(i Tag registered:",this.type,this)),this.refresh()}return Object.defineProperty(Tag.prototype,"type",{get:function(){return this.domElement.getAttribute("type")||this.domElement.tagName.toLowerCase()},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"name",{get:function(){return this.domElement.getAttribute("name")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"id",{get:function(){return this.domElement.getAttribute("id")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"inputPlaceholder",{get:function(){return this._inputPlaceholder},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"formless",{get:function(){return cf.TagsParser.isElementFormless(this.domElement)},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"label",{get:function(){return this.getLabel()},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"value",{get:function(){return this.domElement.value||this.initialDefaultValue},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"hasImage",{get:function(){return this.domElement.hasAttribute("cf-image")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"rows",{get:function(){return this.domElement.hasAttribute("rows")?parseInt(this.domElement.getAttribute("rows")):0},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"disabled",{get:function(){return!this.checkConditionalAndIsValid()||void 0!=this.domElement.getAttribute("disabled")&&null!=this.domElement.getAttribute("disabled")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"required",{get:function(){return!!this.domElement.getAttribute("required")||""==this.domElement.getAttribute("required")},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"question",{get:function(){return this.questions&&0!=this.questions.length?this.questions[Math.floor(Math.random()*this.questions.length)]:cf.Dictionary.getRobotResponse(this.type)},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"eventTarget",{set:function(t){this._eventTarget=t},enumerable:!0,configurable:!0}),Object.defineProperty(Tag.prototype,"errorMessage",{get:function(){return this.errorMessages||(this.domElement.getAttribute("cf-error")?this.errorMessages=cf.Helpers.getValuesOfBars(this.domElement.getAttribute("cf-error")):this.domElement.parentNode&&this.domElement.parentNode.getAttribute("cf-error")?this.errorMessages=cf.Helpers.getValuesOfBars(this.domElement.parentNode.getAttribute("cf-error")):this.required?this.errorMessages=[cf.Dictionary.get("input-placeholder-required")]:"file"==this.type?this.errorMessages=[cf.Dictionary.get("input-placeholder-file-error")]:this.errorMessages=[cf.Dictionary.get("input-placeholder-error")]),this.errorMessages[Math.floor(Math.random()*this.errorMessages.length)]},enumerable:!0,configurable:!0}),Tag.prototype.dealloc=function(){this.domElement.removeEventListener("change",this.changeCallback,!1),this.changeCallback=null,this.domElement=null,this.defaultValue=null,this.errorMessages=null,this.pattern=null,this._label=null,this.validationCallback=null,this.questions=null},Tag.testConditions=function(t,e){var n=function(e,n){return"object"==typeof n?n.test(e):t===n};if("string"==typeof t){for(var i=t,o=!1,s=0;s0},Tag.prototype.checkConditionalAndIsValid=function(){return!this.hasConditions()||this.flowManager.areConditionsInFlowFullfilled(this,this.conditionalTags)},Tag.prototype.setTagValueAndIsValid=function(t){var e=!0,n=t.text;this.pattern&&(e=this.pattern.test(n)),""==n&&this.required&&(e=!1);var i=parseInt(this.domElement.getAttribute("minlength"),10)||-1,o=parseInt(this.domElement.getAttribute("maxlength"),10)||-1;return-1!=i&&n.lengtho&&(e=!1),e&&"file"!=this.type&&(this.domElement.value=n),e},Tag.prototype.getLabel=function(){return this._label||this.findAndSetLabel(),this._label?this._label:cf.Dictionary.getRobotResponse(this.type)},Tag.prototype.findConditionalAttributes=function(){var t=this.domElement.attributes;if(t.length>0){this.conditionalTags=[];for(var e in t)if(t.hasOwnProperty(e)){var n=t[e];if(n&&n.name&&-1!==n.name.indexOf("cf-conditional")){for(var i=[],o=-1!==n.value.indexOf("||")?n.value.split("||"):n.value.split("&&"),s=0;s0&&(e=[t])}else if(e.length>0)for(var i=0;i TagGroup registered:",this.elements[0].type,this)),this.skipUserInput=!1}return Object.defineProperty(e.prototype,"required",{get:function(){for(var t=0;t0)return this.questions[Math.floor(Math.random()*this.questions.length)];if(this.elements[0]&&this.elements[0].question){return this.elements[0].question}return t.Dictionary.getRobotResponse(this.getGroupTagType())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"activeElements",{get:function(){return this._activeElements},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this._values?this._values:[""]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"disabled",{get:function(){for(var t=0,e=0;e\n\t\t\t\t'+this.referenceTag.label+"\n\t\t\t\n\t\t\t"},n}(t.ControlElement);t.Button=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"RadioButton"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"checked",{get:function(){return this.el.hasAttribute("checked")&&"checked"==this.el.getAttribute("checked")},set:function(t){t?(this.el.setAttribute("checked","checked"),this.referenceTag.domElement.setAttribute("checked","checked"),this.referenceTag.domElement.checked=!0):(this.el.removeAttribute("checked"),this.referenceTag.domElement.removeAttribute("checked"),this.referenceTag.domElement.checked=!1)},enumerable:!0,configurable:!0}),e.prototype.onClick=function(e){this.checked=!0,t.prototype.onClick.call(this,e)},e.prototype.getTemplate=function(){return'\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t"+this.referenceTag.label+"\n\t\t\t\t
\n\t\t\t
\n\t\t\t"},e}(t.Button);t.RadioButton=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"type",{get:function(){return"CheckboxButton"},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"checked",{get:function(){return"checked"==this.el.getAttribute("checked")},set:function(t){t?(this.el.setAttribute("checked","checked"),this.referenceTag.domElement.setAttribute("checked","checked"),this.referenceTag.domElement.checked=!0):(this.el.removeAttribute("checked"),this.referenceTag.domElement.removeAttribute("checked"),this.referenceTag.domElement.checked=!1)},enumerable:!0,configurable:!0}),e.prototype.onClick=function(t){this.checked=!this.checked},e.prototype.getTemplate=function(){var t=this.referenceTag.domElement.checked&&this.referenceTag.domElement.hasAttribute("checked");return'";return t+="
",this.isMultiChoice&&(t+=""),t+=this.referenceTag.label,t+="
",t+="
"},n}(t.Button);t.OptionButton=e}(cf||(cf={}));var cf;!function(t){var e=function(){function e(e){this.context=e.context,this.eventTarget=e.eventTarget,this.referenceTag=e.referenceTag,this.multiChoice=this.referenceTag.domElement.hasAttribute("multiple"),this.onOptionButtonClickCallback=this.onOptionButtonClick.bind(this),this.eventTarget.addEventListener(t.OptionButtonEvents.CLICK,this.onOptionButtonClickCallback,!1),this.createElements()}return Object.defineProperty(e.prototype,"type",{get:function(){return"OptionsList"},enumerable:!0,configurable:!0}),e.prototype.getValue=function(){for(var t=[],e=0;e0;)this.elements.pop().dealloc();this.elements=null},e}();t.OptionsList=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;if(i.maxFileSize=1e11,i.loading=!1,i.submitTimer=0,i._fileName="",i._readerResult="",!t.Helpers.caniuse.fileReader())throw new Error("Conversational Form Error: No FileReader available for client.");var o=i.referenceTag.domElement.getAttribute("cf-max-size")||i.referenceTag.domElement.getAttribute("max-size");if(o){var s=parseInt(o,10);i.maxFileSize=s}return i.progressBar=i.el.getElementsByTagName("cf-upload-file-progress-bar")[0],i.onDomElementChangeCallback=i.onDomElementChange.bind(i),i.referenceTag.domElement.addEventListener("change",i.onDomElementChangeCallback,!1),i}return __extends(n,e),Object.defineProperty(n.prototype,"value",{get:function(){return this.referenceTag.domElement.value},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"readerResult",{get:function(){return this._readerResult},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"files",{get:function(){return this._files},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"fileName",{get:function(){return this._fileName},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"type",{get:function(){return"UploadFileUI"},enumerable:!0,configurable:!0}),n.prototype.getFilesAsString=function(){var e=document.createElement("span");return e.innerHTML=t.Dictionary.get("icon-type-file")+this.fileName,e.outerHTML},n.prototype.onDomElementChange=function(e){var n=this;t.ConversationalForm.suppressLog||console.log("...onDomElementChange");var i=new FileReader;this._files=this.referenceTag.domElement.files,i.onerror=function(e){t.ConversationalForm.suppressLog||console.log("onerror",e)},i.onprogress=function(e){t.ConversationalForm.suppressLog||console.log("onprogress",e),n.progressBar.style.width=e.loaded/e.total*100+"%"},i.onabort=function(e){t.ConversationalForm.suppressLog||console.log("onabort",e)},i.onloadstart=function(e){var o=n.files[0],s=o?o.size:n.maxFileSize+1;if(s>n.maxFileSize){i.abort();var r={errorText:t.Dictionary.get("input-placeholder-file-size-error")};t.ConversationalForm.illustrateFlow(n,"dispatch",t.FlowEvents.USER_INPUT_INVALID,r),n.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:r}))}else{n._fileName=o.name,n.loading=!0,n.animateIn();var a=Math.floor(Math.log(s)/Math.log(1024)),l=["b","kb","mb","gb"];a=Math.min(l.length-1,a) +;var c=1*Number((s/Math.pow(1024,a)).toFixed(2))+" "+l[a],u=o.name+" ("+c+")";n.el.getElementsByTagName("cf-upload-file-text")[0].innerHTML=u,n.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.PROGRESS_CHANGE,{detail:t.ControlElementProgressStates.BUSY}))}},i.onload=function(e){n._readerResult=e.target.result,n.progressBar.classList.add("loaded"),n.submitTimer=setTimeout(function(){n.el.classList.remove("animate-in"),n.onChoose(),n.eventTarget.dispatchEvent(new CustomEvent(t.ControlElementEvents.PROGRESS_CHANGE,{detail:t.ControlElementProgressStates.READY}))},0)},i.readAsDataURL(this.files[0])},n.prototype.animateIn=function(){this.loading&&e.prototype.animateIn.call(this)},n.prototype.onClick=function(t){},n.prototype.triggerFileSelect=function(){this.referenceTag.domElement.click()},n.prototype.dealloc=function(){clearTimeout(this.submitTimer),this.progressBar=null,this.onDomElementChangeCallback&&(this.referenceTag.domElement.removeEventListener("change",this.onDomElementChangeCallback,!1),this.onDomElementChangeCallback=null),e.prototype.dealloc.call(this)},n.prototype.getTemplate=function(){"1"==this.referenceTag.value||this.referenceTag.domElement.hasAttribute("checked");return"\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t"},n}(t.Button);t.UploadFileUI=e}(cf||(cf={}));var cf;!function(t){t.MicrophoneBridgeEvent={ERROR:"cf-microphone-bridge-error",TERMNIAL_ERROR:"cf-microphone-bridge-terminal-error"};var e=function(){function e(e){this.currentTextResponse="",this._hasUserMedia=!1,this.inputErrorCount=0,this.inputCurrentError="",this.el=e.el,this.button=e.button,this.eventTarget=e.eventTarget,this.microphoneObj=e.microphoneObj,this.flowUpdateCallback=this.onFlowUpdate.bind(this),this.eventTarget.addEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1)}return Object.defineProperty(e.prototype,"hasUserMedia",{set:function(t){this._hasUserMedia=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"active",{set:function(t){this.equalizer&&(this.equalizer.disabled=!t)},enumerable:!0,configurable:!0}),e.prototype.cancel=function(){this.button.loading=!1,this.microphoneObj.cancelInput&&this.microphoneObj.cancelInput()},e.prototype.onFlowUpdate=function(){var t=this;if(this.currentTextResponse=null,this._hasUserMedia)this.microphoneObj.awaitingCallback||this.callInput();else{var e=!1;window.navigator.mediaDevices&&window.navigator.mediaDevices.enumerateDevices().then(function(n){n.forEach(function(t){e||""===t.label||(e=!0)}),e&&t.getUserMedia()})}},e.prototype.getUserMedia=function(){var e=this;try{void 0===navigator.mediaDevices&&(navigator.mediaDevices={}),void 0===navigator.mediaDevices.getUserMedia&&(navigator.mediaDevices.getUserMedia=function(t){var e=navigator.getUserMedia||window.navigator.webkitGetUserMedia||window.navigator.mozGetUserMedia;return e?new Promise(function(n,i){e.call(navigator,t,n,i)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}),navigator.mediaDevices.getUserMedia({audio:!0}).then(function(t){e.currentStream=t,t.getAudioTracks().length>0?(e.hasUserMedia=!0,e.setupEqualizer(),e.microphoneObj.awaitingCallback||e.callInput()):e.hasUserMedia=!1}).catch(function(n){e.hasUserMedia=!1,e.eventTarget.dispatchEvent(new Event(t.MicrophoneBridgeEvent.TERMNIAL_ERROR))})}catch(e){this.hasUserMedia=!1,this.eventTarget.dispatchEvent(new Event(t.MicrophoneBridgeEvent.TERMNIAL_ERROR))}},e.prototype.dealloc=function(){this.cancel(),this.promise=null,this.currentStream=null,this.equalizer&&this.equalizer.dealloc(),this.equalizer=null,this.eventTarget.removeEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1),this.flowUpdateCallback=null},e.prototype.callInput=function(e){var n=this;void 0===e&&(e=0),this.button.loading=!0,this.equalizer&&(this.equalizer.disabled=!1),this.promise=new Promise(function(t,e){return n.microphoneObj.input(t,e,n.currentStream)}).then(function(e){if(n.promise=null,n.currentTextResponse=e.toString(),!n.currentTextResponse||""==n.currentTextResponse)return n.showError(t.Dictionary.get("user-audio-reponse-invalid")),void n.callInput();n.inputErrorCount=0,n.inputCurrentError="",n.button.loading=!1;var i={text:n.currentTextResponse};t.ConversationalForm.illustrateFlow(n,"dispatch",t.UserInputEvents.SUBMIT,i),n.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.SUBMIT,{detail:i}))}).catch(function(e){n.isErrorTerminal(e)?(n.eventTarget.dispatchEvent(new CustomEvent(t.MicrophoneBridgeEvent.TERMNIAL_ERROR,{detail:t.Dictionary.get("microphone-terminal-error")})),t.ConversationalForm.suppressLog||console.log("Conversational Form: Terminal error: ",e)):(n.inputCurrentError!=e&&(n.inputErrorCount=0,n.inputCurrentError=e),n.inputErrorCount++,n.inputErrorCount>2?n.showError(e):(n.eventTarget.dispatchEvent(new CustomEvent(t.MicrophoneBridgeEvent.TERMNIAL_ERROR,{detail:t.Dictionary.get("microphone-terminal-error")})),t.ConversationalForm.suppressLog||console.log("Conversational Form: Terminal error: ",e)))})},e.prototype.isErrorTerminal=function(t){return-1!==["network"].indexOf(t)},e.prototype.showError=function(e){var n={errorText:e};t.ConversationalForm.illustrateFlow(this,"dispatch",t.FlowEvents.USER_INPUT_INVALID,n),this.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:n})),this.callInput()},e.prototype.setupEqualizer=function(){var t=this.el.getElementsByTagName("cf-icon-audio-eq")[0];n.supported&&t&&(this.equalizer=new n({stream:this.currentStream,elementToScale:t}))},e}();t.MicrophoneBridge=e;var n=function(){function t(t){var e=this;this.maxBorderWidth=0,this._disabled=!1,this.elementToScale=t.elementToScale,this.context=new AudioContext,this.analyser=this.context.createAnalyser(),this.mic=this.context.createMediaStreamSource(t.stream),this.javascriptNode=this.context.createScriptProcessor(2048,1,1),this.analyser.smoothingTimeConstant=.3,this.analyser.fftSize=1024,this.mic.connect(this.analyser),this.analyser.connect(this.javascriptNode),this.javascriptNode.connect(this.context.destination),this.javascriptNode.onaudioprocess=function(){e.onAudioProcess()}}return Object.defineProperty(t.prototype,"disabled",{set:function(t){this._disabled=t,this.elementToScale.style.borderWidth="0px"},enumerable:!0,configurable:!0}),t.prototype.onAudioProcess=function(){if(!this._disabled){var t=new Uint8Array(this.analyser.frequencyBinCount);this.analyser.getByteFrequencyData(t);for(var e=0,n=t.length,i=0;i\n\t\t\t\t
\n\t\t\t\t\n\t\t\t';var i=n.firstChild||n.content.firstChild;this.mic=new t.MicrophoneBridge({el:i,button:this,eventTarget:this.eventTarget,microphoneObj:e}),this.el.appendChild(i)},e.prototype.reset=function(){this.mic&&!this.typing&&this.mic.callInput()},e.prototype.getTemplate=function(){return'\n\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
'},e.prototype.onMicrophoneTerminalError=function(e){this.mic&&(this.mic.dealloc(),this.mic=null,this.el.removeChild(this.el.getElementsByClassName("cf-microphone")[0]),this.el.classList.remove("microphone-interface"),this.loading=!1,this.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:{errorText:e.detail}})))},e.prototype.onClick=function(e){this.mic&&!this.typing?this.mic.callInput():this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputSubmitButtonEvents.CHANGE))},e.prototype.click=function(){this.el.click()},e.prototype.dealloc=function(){this.eventTarget.removeEventListener(t.MicrophoneBridgeEvent.TERMNIAL_ERROR,this.onMicrophoneTerminalErrorCallback,!1),this.onMicrophoneTerminalErrorCallback=null,this.mic&&this.mic.dealloc(),this.mic=null,this.el.removeEventListener("click",this.onClickCallback,!1),this.onClickCallback=null,this.el=null,this.eventTarget=null},e}();t.UserInputSubmitButton=e}(cf||(cf={}));var cf;!function(t){t.UserInputTypes={VOICE:"voice",VR_GESTURE:"vr-gesture",TEXT:"text"}}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;return i._disabled=!1,i._visible=!1,i.onChatReponsesUpdatedCallback=i.onChatReponsesUpdated.bind(i),i.eventTarget.addEventListener(t.ChatListEvents.CHATLIST_UPDATED,i.onChatReponsesUpdatedCallback,!1),i.windowFocusCallback=i.windowFocus.bind(i),window.addEventListener("focus",i.windowFocusCallback,!1),i.inputInvalidCallback=i.inputInvalid.bind(i),i.eventTarget.addEventListener(t.FlowEvents.USER_INPUT_INVALID,i.inputInvalidCallback,!1),i.flowUpdateCallback=i.onFlowUpdate.bind(i),i.eventTarget.addEventListener(t.FlowEvents.FLOW_UPDATE,i.flowUpdateCallback,!1),i}return __extends(n,e),Object.defineProperty(n.prototype,"currentTag",{get:function(){return this._currentTag},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"visible",{set:function(t){var e=this;this._visible=t,!this.el.classList.contains("animate-in")&&t?setTimeout(function(){e.el.classList.add("animate-in")},0):this.el.classList.contains("animate-in")&&!t&&this.el.classList.remove("animate-in")},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this._disabled},set:function(t){this._disabled!=t&&(this._disabled=t,t?this.el.setAttribute("disabled","disabled"):(this.setFocusOnInput(),this.el.removeAttribute("disabled")))},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"height",{get:function(){var e=0,n=0,i=this.el;return t.Helpers.isInternetExlorer()?(e=i.offsetHeight,n=parseInt(i.currentStyle.marginTop,10)+parseInt(i.currentStyle.marginBottom,10),n*=2):(e=parseInt(document.defaultView.getComputedStyle(i,"").getPropertyValue("height"),10),n=parseInt(document.defaultView.getComputedStyle(i,"").getPropertyValue("margin-top"))+parseInt(document.defaultView.getComputedStyle(i,"").getPropertyValue("margin-bottom"))),e+n},enumerable:!0,configurable:!0}),n.prototype.onEnterOrSubmitButtonSubmit=function(t){void 0===t&&(t=null)},n.prototype.inputInvalid=function(t){},n.prototype.deactivate=function(){this.disabled=!0},n.prototype.reactivate=function(){this.disabled=!1},n.prototype.getFlowDTO=function(){},n.prototype.setFocusOnInput=function(){},n.prototype.onFlowStopped=function(){},n.prototype.reset=function(){},n.prototype.dealloc=function(){this.eventTarget.removeEventListener(t.ChatListEvents.CHATLIST_UPDATED,this.onChatReponsesUpdatedCallback,!1),this.onChatReponsesUpdatedCallback=null,this.eventTarget.removeEventListener(t.FlowEvents.USER_INPUT_INVALID,this.inputInvalidCallback,!1),this.inputInvalidCallback=null,window.removeEventListener("focus",this.windowFocusCallback,!1),this.windowFocusCallback=null,this.eventTarget.removeEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1),this.flowUpdateCallback=null,e.prototype.dealloc.call(this)},n.prototype.onFlowUpdate=function(e){t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail),this._currentTag=e.detail.tag},n.prototype.windowFocus=function(t){},n.prototype.onChatReponsesUpdated=function(t){t.detail.currentResponse.isRobotResponse||(this.visible=!0,this.disabled=!1,this.setFocusOnInput())},n.ERROR_TIME=2e3,n.preventAutoFocus=!1,n.hideUserInputOnNoneTextInput=!1,n}(t.BasicElement);t.UserInputElement=e,t.UserInputEvents={SUBMIT:"cf-input-user-input-submit",KEY_CHANGE:"cf-input-key-change",CONTROL_ELEMENTS_ADDED:"cf-input-control-elements-added",HEIGHT_CHANGE:"cf-input-height-change",FOCUS:"cf-input-focus",BLUR:"cf-input-blur"}}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){var e=function(e){function n(n){var i=e.call(this,n)||this;return i.errorTimer=0,i.initialInputHeight=0,i.shiftIsDown=!1,i._active=!1,i.cfReference=n.cfReference,i.eventTarget=n.eventTarget,i.inputElement=i.el.getElementsByTagName("textarea")[0],i.onInputFocusCallback=i.onInputFocus.bind(i),i.onInputBlurCallback=i.onInputBlur.bind(i),i.inputElement.addEventListener("focus",i.onInputFocusCallback,!1),i.inputElement.addEventListener("blur",i.onInputBlurCallback,!1),i.controlElements=new t.ControlElements({el:i.el.getElementsByTagName("cf-input-control-elements")[0],cfReference:i.cfReference,infoEl:i.el.getElementsByTagName("cf-info")[0],eventTarget:i.eventTarget}),i.keyUpCallback=i.onKeyUp.bind(i),document.addEventListener("keyup",i.keyUpCallback,!1),i.keyDownCallback=i.onKeyDown.bind(i),document.addEventListener("keydown",i.keyDownCallback,!1),i.onOriginalTagChangedCallback=i.onOriginalTagChanged.bind(i),i.eventTarget.addEventListener(t.TagEvents.ORIGINAL_ELEMENT_CHANGED,i.onOriginalTagChangedCallback,!1),i.onControlElementSubmitCallback=i.onControlElementSubmit.bind(i),i.eventTarget.addEventListener(t.ControlElementEvents.SUBMIT_VALUE,i.onControlElementSubmitCallback,!1),i.onControlElementProgressChangeCallback=i.onControlElementProgressChange.bind(i),i.eventTarget.addEventListener(t.ControlElementEvents.PROGRESS_CHANGE,i.onControlElementProgressChangeCallback,!1),i.onSubmitButtonChangeStateCallback=i.onSubmitButtonChangeState.bind(i),i.eventTarget.addEventListener(t.UserInputSubmitButtonEvents.CHANGE,i.onSubmitButtonChangeStateCallback,!1),i.submitButton=new t.UserInputSubmitButton({eventTarget:i.eventTarget}),i.el.appendChild(i.submitButton.el),n.microphoneInputObj&&(i.microphoneObj=n.microphoneInputObj,i.microphoneObj&&i.microphoneObj.init&&i.microphoneObj.init(),i.submitButton.addMicrophone(i.microphoneObj)),i}return __extends(n,e),Object.defineProperty(n.prototype,"active",{get:function(){return this.inputElement===document.activeElement||this._active},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{set:function(e){var n=this._disabled!=e;t.ConversationalForm.suppressLog||console.log("option hasChanged",e),n&&(this._disabled=e,e?(this.el.setAttribute("disabled","disabled"),this.inputElement.blur()):(this.setFocusOnInput(),this.el.removeAttribute("disabled")))},enumerable:!0,configurable:!0}),n.prototype.getInputValue=function(){var t=this.inputElement.value,e=document.createElement("div");return e.appendChild(document.createTextNode(t)),e.innerHTML},n.prototype.getFlowDTO=function(){var t;return t=this.controlElements&&this.controlElements.active?this.controlElements.getDTO():{text:this.getInputValue()},t.tag||(t.tag=this.currentTag),t.input=this,t.tag=this.currentTag,t},n.prototype.reset=function(){this.controlElements&&this.controlElements.clearTagsAndReset()},n.prototype.deactivate=function(){e.prototype.deactivate.call(this),this.microphoneObj&&(this.submitButton.active=!1)},n.prototype.reactivate=function(){e.prototype.reactivate.call(this),this.microphoneObj&&!this.submitButton.typing&&(this.submitButton.loading=!0,this.submitButton.typing=!1,this.submitButton.active=!0)},n.prototype.onFlowStopped=function(){this.submitButton.loading=!1,this.submitButton.typing&&(this.submitButton.typing=!1),this.controlElements&&this.controlElements.clearTagsAndReset(),this.disabled=!0},n.prototype.onOriginalTagChanged=function(t){this.currentTag==t.detail.tag&&this.onInputChange(),this.controlElements&&this.controlElements.active&&this.controlElements.updateStateOnElementsFromTag(t.detail.tag)},n.prototype.onInputChange=function(){if(this.active||this.controlElements.active){var e=Math.max(this.initialInputHeight,parseInt(this.inputElement.style.height,10));this.inputElement.style.height="0px",this.inputElement.style.height=(0===this.inputElement.scrollHeight?e:this.inputElement.scrollHeight)+"px",t.ConversationalForm.illustrateFlow(this,"dispatch",t.UserInputEvents.HEIGHT_CHANGE),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.HEIGHT_CHANGE,{detail:this.inputElement.scrollHeight}))}},n.prototype.inputInvalid=function(e){var n=this;t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var i=e.detail;this.inputElement.setAttribute("data-value",this.inputElement.value),this.inputElement.value="",this.el.setAttribute("error",""),this.disabled=!0,this.inputElement.setAttribute("placeholder",i.errorText||(this._currentTag?this._currentTag.errorMessage:"")),clearTimeout(this.errorTimer),this.submitButton.loading=!1,this.errorTimer=setTimeout(function(){n.disabled=!1,t.ConversationalForm.suppressLog||console.log("option, disabled 1"),n.el.removeAttribute("error"),n.inputElement.value=n.inputElement.getAttribute("data-value"),n.inputElement.setAttribute("data-value",""),n.setPlaceholder(),n.setFocusOnInput(),n.submitButton.reset(),n.controlElements&&n.controlElements.resetAfterErrorMessage()},t.UserInputElement.ERROR_TIME)},n.prototype.setPlaceholder=function(){this._currentTag?this._currentTag.inputPlaceholder?this.inputElement.setAttribute("placeholder",this._currentTag.inputPlaceholder):this.inputElement.setAttribute("placeholder","group"==this._currentTag.type?t.Dictionary.get("group-placeholder"):t.Dictionary.get("input-placeholder")):this.inputElement.setAttribute("placeholder",t.Dictionary.get("group-placeholder"))},n.prototype.checkForCorrectInputTag=function(){var t=this.inputElement.getAttribute("type"),e="password"==this._currentTag.type&&"password"!=t,n="password"!=this._currentTag.type&&"password"==t,i="email"==this._currentTag.type&&"email"!=t||"number"==this._currentTag.type&&"number"!=t;if(this.inputElement&&(e||n)&&(this.inputElement.removeEventListener("focus",this.onInputFocusCallback,!1),this.inputElement.removeEventListener("blur",this.onInputBlurCallback,!1)),e||i){var o=document.createElement("input");Array.prototype.slice.call(this.inputElement.attributes).forEach(function(t){o.setAttribute(t.name,t.value)}),o.setAttribute("autocomplete","new-password"),this.inputElement.parentNode.replaceChild(o,this.inputElement),this.inputElement=o,"number"!==this._currentTag.type&&"email"!==this._currentTag.type||(this.inputElement.type=this._currentTag.type,o.setAttribute("type",this._currentTag.type))}else if(n){var s=document.createElement("textarea");Array.prototype.slice.call(this.inputElement.attributes).forEach(function(t){s.setAttribute(t.name,t.value)}),this.inputElement.parentNode.replaceChild(s,this.inputElement),this.inputElement=s}this.inputElement&&(e||n)&&(this.inputElement.addEventListener("focus",this.onInputFocusCallback,!1),this.inputElement.addEventListener("blur",this.onInputBlurCallback,!1)),0==this.initialInputHeight&&(this.initialInputHeight=this.inputElement.offsetHeight),this.setFocusOnInput()},n.prototype.onFlowUpdate=function(n){var i=this;e.prototype.onFlowUpdate.call(this,n),this.submitButton.loading=!1,this.submitButton.typing&&(this.submitButton.typing=!1),this.el.setAttribute("tag-type",this._currentTag.type),this.checkForCorrectInputTag();var o=-1!==["password","number","email"].indexOf(this._currentTag.type);this.inputElement.setAttribute("type",o?this._currentTag.type:"input"),clearTimeout(this.errorTimer),this.el.removeAttribute("error"),this.inputElement.setAttribute("data-value",""),this.inputElement.value="",this.submitButton.loading=!1,this.setPlaceholder(),this.resetValue(),this.setFocusOnInput(),this.controlElements.reset(),"group"==this._currentTag.type?this.buildControlElements(this._currentTag.elements):this.buildControlElements([this._currentTag]),"text"!=this._currentTag.type&&"email"!=this._currentTag.type||(this.inputElement.value=this._currentTag.defaultValue.toString()),!0===this._currentTag.skipUserInput?this.el.classList.add("hide-input"):this.el.classList.remove("hide-input"),this._currentTag.rows&&this._currentTag.rows>1&&this.inputElement.setAttribute("rows",this._currentTag.rows.toString()),t.UserInputElement.hideUserInputOnNoneTextInput&&(this.controlElements.active?(this.el.classList.add("hide-input"),this.controlElements.focusFrom("bottom")):this.el.classList.remove("hide-input")),setTimeout(function(){i.onInputChange()},150)},n.prototype.onControlElementProgressChange=function(e){var n=e.detail;this.disabled=n==t.ControlElementProgressStates.BUSY,t.ConversationalForm.suppressLog||console.log("option, disabled 2")},n.prototype.buildControlElements=function(t){this.controlElements.buildTags(t)},n.prototype.onControlElementSubmit=function(e){t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var n=e.detail;this.controlElements.updateStateOnElements(n),this.doSubmit()},n.prototype.onSubmitButtonChangeState=function(t){this.onEnterOrSubmitButtonSubmit(t)},n.prototype.isMetaKeyPressed=function(t){t.metaKey||[91,93].indexOf(t.keyCode)},n.prototype.onKeyDown=function(e){(this.active||this.controlElements.focus)&&(this.isControlElementsActiveAndUserInputHidden()||this.isMetaKeyPressed(e)||(e.keyCode==t.Dictionary.keyCodes.shift&&(this.shiftIsDown=!0),e.keyCode!=t.Dictionary.keyCodes.enter||e.shiftKey||e.preventDefault()))},n.prototype.isControlElementsActiveAndUserInputHidden=function(){return this.controlElements&&this.controlElements.active&&t.UserInputElement.hideUserInputOnNoneTextInput},n.prototype.onKeyUp=function(e){if((this.active||this.isControlElementsActiveAndUserInputHidden()||this.controlElements.focus)&&!this.isMetaKeyPressed(e)){if(e.keyCode==t.Dictionary.keyCodes.shift)this.shiftIsDown=!1;else if(e.keyCode==t.Dictionary.keyCodes.up)e.preventDefault(),this.active&&!this.controlElements.focus&&this.controlElements.focusFrom("bottom");else if(e.keyCode==t.Dictionary.keyCodes.down)e.preventDefault(),this.active&&!this.controlElements.focus&&this.controlElements.focusFrom("top");else if(e.keyCode==t.Dictionary.keyCodes.tab){for(var n=!1,i=e.target.parentNode;null!=i;){if(i===this.cfReference.el){n=!0;break}i=i.parentNode}n||(e.preventDefault(),this.controlElements.active||this.setFocusOnInput())}if(!this.el.hasAttribute("disabled")){var o=this.getFlowDTO();if(e.keyCode==t.Dictionary.keyCodes.enter&&!e.shiftKey||e.keyCode==t.Dictionary.keyCodes.space)if(e.keyCode==t.Dictionary.keyCodes.enter&&this.active)e.preventDefault(),this.onEnterOrSubmitButtonSubmit();else if(e.keyCode==t.Dictionary.keyCodes.enter||e.keyCode==t.Dictionary.keyCodes.space){e.preventDefault();var s="group"==this._currentTag.type?this._currentTag.getGroupTagType():this._currentTag.type;if("select"==s||"checkbox"==s){var r=this._currentTag;"checkbox"==s||r.multipleChoice?(this.active||this.isControlElementsActiveAndUserInputHidden())&&e.keyCode==t.Dictionary.keyCodes.enter?this.submitButton.click():(this.active||this.controlElements.active||this.isControlElementsActiveAndUserInputHidden()||(this.resetValue(),this.setFocusOnInput()),this.dispatchKeyChange(o,e.keyCode)):this.dispatchKeyChange(o,e.keyCode)}else"group"==this._currentTag.type&&this.dispatchKeyChange(o,e.keyCode)}else e.keyCode==t.Dictionary.keyCodes.space&&document.activeElement&&this.dispatchKeyChange(o,e.keyCode);else e.keyCode!=t.Dictionary.keyCodes.shift&&e.keyCode!=t.Dictionary.keyCodes.tab&&this.dispatchKeyChange(o,e.keyCode);this.onInputChange()}}},n.prototype.dispatchKeyChange=function(e,n){this.submitButton.typing=e.text&&e.text.length>0,t.ConversationalForm.illustrateFlow(this,"dispatch",t.UserInputEvents.KEY_CHANGE,e),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.KEY_CHANGE,{detail:{dto:e,keyCode:n,inputFieldActive:this.active}}))},n.prototype.windowFocus=function(t){e.prototype.windowFocus.call(this,t),this.setFocusOnInput()},n.prototype.onInputBlur=function(e){this._active=!1,this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.BLUR))},n.prototype.onInputFocus=function(e){this._active=!0,this.onInputChange(),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.FOCUS))},n.prototype.setFocusOnInput=function(){t.UserInputElement.preventAutoFocus||this.el.classList.contains("hide-input")||this.inputElement.focus()},n.prototype.onEnterOrSubmitButtonSubmit=function(e){void 0===e&&(e=null);var n=this.controlElements.active&&t.UserInputElement.hideUserInputOnNoneTextInput;(this.active||n)&&this.controlElements.highlighted?this.controlElements.clickOnHighlighted():this._currentTag?"file"==this._currentTag.type&&e?this.controlElements.getElement(0).triggerFileSelect():this.doSubmit():this.eventTarget.cf.addUserChatResponse(this.inputElement.value)},n.prototype.doSubmit=function(){var e=this.getFlowDTO();this.submitButton.loading=!0,this.disabled=!0,this.el.removeAttribute("error"),this.inputElement.setAttribute("data-value",""),t.ConversationalForm.illustrateFlow(this,"dispatch",t.UserInputEvents.SUBMIT,e),this.eventTarget.dispatchEvent(new CustomEvent(t.UserInputEvents.SUBMIT,{detail:e}))},n.prototype.resetValue=function(){this.inputElement.value="",this.inputElement.hasAttribute("rows")&&this.inputElement.setAttribute("rows","1"),this.onInputChange()},n.prototype.dealloc=function(){this.inputElement.removeEventListener("blur",this.onInputBlurCallback,!1),this.onInputBlurCallback=null,this.inputElement.removeEventListener("focus",this.onInputFocusCallback,!1),this.onInputFocusCallback=null,document.removeEventListener("keydown",this.keyDownCallback,!1),this.keyDownCallback=null,document.removeEventListener("keyup",this.keyUpCallback,!1),this.keyUpCallback=null,this.eventTarget.removeEventListener(t.ControlElementEvents.SUBMIT_VALUE,this.onControlElementSubmitCallback,!1),this.onControlElementSubmitCallback=null,this.submitButton.el.removeEventListener(t.UserInputSubmitButtonEvents.CHANGE,this.onSubmitButtonChangeStateCallback,!1),this.onSubmitButtonChangeStateCallback=null,this.submitButton.dealloc(),this.submitButton=null,e.prototype.dealloc.call(this)},n.prototype.getTemplate=function(){return this.customTemplate||'\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\n\t\t\t\t\n\n\t\t\t\n\t\t\t'},n}(t.UserInputElement);t.UserTextInput=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){t.ChatResponseEvents={USER_ANSWER_CLICKED:"cf-on-user-answer-clicked"};var e=function(e){function n(t){var n=e.call(this,t)||this;return n.readyTimer=0,n.container=t.container,n.uiOptions=t.cfReference.uiOptions,n._tag=t.tag,n}return __extends(n,e),Object.defineProperty(n.prototype,"tag",{get:function(){return this._tag},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"added",{get:function(){return!!this.el.parentNode.parentNode},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"disabled",{get:function(){return this.el.classList.contains("disabled")},set:function(t){t?this.el.classList.add("disabled"):this.el.classList.remove("disabled")},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"visible",{set:function(t){var e=this;this.el.offsetWidth,setTimeout(function(){return t?e.el.classList.add("show"):e.el.classList.remove("show")},100)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"strippedSesponse",{get:function(){var t=this.response,e=document.createElement("div");return e.innerHTML=t,e.textContent||e.innerText||""},enumerable:!0,configurable:!0}),n.prototype.whenReady=function(t){this.onReadyCallback=t},n.prototype.setValue=function(e){void 0===e&&(e=null),this.visible||(this.visible=!0);this.el.hasAttribute("thinking");if(e){if(this.response=this.originalResponse=e.text,this.processResponseAndSetText(),this.responseLink&&!this.isRobotResponse&&this.responseLink.processResponseAndSetText(),e&&e.controlElements&&e.controlElements[0])switch(e.controlElements[0].type){case"UploadFileUI":this.textEl.classList.add("file-icon")}this.isRobotResponse||this.onClickCallback||(this.onClickCallback=this.onClick.bind(this),this.el.addEventListener(t.Helpers.getMouseEvent("click"),this.onClickCallback,!1))}else this.setToThinking()},n.prototype.show=function(){this.visible=!0,this.disabled=!1,this.response?this.checkForEditMode():this.setToThinking()},n.prototype.updateThumbnail=function(t){var e=this.el.getElementsByTagName("thumb")[0];if(0===t.indexOf("text:")){var n=e.getElementsByTagName("span")[0];n.innerHTML=t.split("text:")[1],n.setAttribute("length",t.length.toString())}else this.image=t,e.style.backgroundImage='url("'+this.image+'")'},n.prototype.setLinkToOtherReponse=function(t){this.responseLink=t},n.prototype.processResponseAndSetText=function(){var t=this;if(this.originalResponse){var e=this.originalResponse;if(this._tag&&"password"==this._tag.type&&!this.isRobotResponse){for(var i="",o=0;o"+n+"

";var e=t.textEl.getElementsByTagName("p");e[e.length-1].offsetWidth,e[e.length-1].classList.add("show"),t.scrollTo()},l+(e+1)*u.uiOptions.robot.chainedResponseTime)}(h);this.readyTimer=setTimeout(function(){t.onReadyCallback&&t.onReadyCallback(),t.onReadyCallback=null,t._tag&&!0===t._tag.skipUserInput&&setTimeout(function(){t._tag.flowManager.nextStep(),t._tag.skipUserInput=!1},t.uiOptions.robot.chainedResponseTime)},l+c.length*this.uiOptions.robot.chainedResponseTime)}else{this.tryClearThinking(),this.textEl.innerHTML="

"+e+"

";var p=this.textEl.getElementsByTagName("p");p[p.length-1].offsetWidth,p[p.length-1].classList.add("show"),this.scrollTo()}this.parsedResponse=e,this.addSelf(),this.textEl.removeAttribute("value-added"),setTimeout(function(){t.textEl.setAttribute("value-added",""),t.el.classList.add("peak-thumb")},0),this.checkForEditMode(),this.response=e.split("&&").join(" ")}},n.prototype.scrollTo=function(){var t=this.el.offsetTop,e=this.el.offsetHeight;!this.container&&this.el&&(this.container=this.el),this.container.scrollTop=t+e+this.container.scrollTop},n.prototype.checkForEditMode=function(){this.isRobotResponse||this.el.hasAttribute("thinking")||(this.el.classList.add("can-edit"),this.disabled=!1)},n.prototype.tryClearThinking=function(){this.el.hasAttribute("thinking")&&(this.textEl.innerHTML="",this.el.removeAttribute("thinking"))},n.prototype.setToThinking=function(){(this.isRobotResponse&&0!==this.uiOptions.robot.robotResponseTime||!this.isRobotResponse&&this.cfReference.uiOptions.user.showThinking&&!this._tag.skipUserInput)&&(this.textEl.innerHTML=n.THINKING_MARKUP,this.el.classList.remove("can-edit"),this.el.setAttribute("thinking","")),(this.cfReference.uiOptions.user.showThinking||this.cfReference.uiOptions.user.showThumb)&&this.addSelf()},n.prototype.addSelf=function(){this.el.parentNode!=this.container&&this.container.appendChild(this.el)},n.prototype.onClick=function(e){this.setToThinking(),t.ConversationalForm.illustrateFlow(this,"dispatch",t.ChatResponseEvents.USER_ANSWER_CLICKED,e),this.eventTarget.dispatchEvent(new CustomEvent(t.ChatResponseEvents.USER_ANSWER_CLICKED,{detail:this._tag}))},n.prototype.setData=function(t){this.image=t.image,this.response=this.originalResponse=t.response,this.isRobotResponse=t.isRobotResponse,e.prototype.setData.call(this,t)},n.prototype.onElementCreated=function(){var t=this;this.textEl=this.el.getElementsByTagName("text")[0],this.updateThumbnail(this.image),this.isRobotResponse||null!=this.response?setTimeout(function(){t.setValue({text:t.response})},0):this.cfReference.uiOptions.user.showThumb&&this.el.classList.add("peak-thumb")},n.prototype.dealloc=function(){clearTimeout(this.readyTimer),this.container=null,this.uiOptions=null,this.onReadyCallback=null,this.onClickCallback&&(this.el.removeEventListener(t.Helpers.getMouseEvent("click"),this.onClickCallback,!1),this.onClickCallback=null),e.prototype.dealloc.call(this)},n.prototype.getTemplate=function(){return'\n\t\t\t\t\n\t\t\t\t\n\t\t\t'},n.THINKING_MARKUP="

...

",n}(t.BasicElement);t.ChatResponse=e}(cf||(cf={}));var __extends=this&&this.__extends||function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}(),cf;!function(t){t.ChatListEvents={CHATLIST_UPDATED:"cf-chatlist-updated"};var e=function(e){function n(n){var i=e.call(this,n)||this;return i.updateTimer=0,t.ChatResponse.list=i,i.responses=[],i.flowUpdateCallback=i.onFlowUpdate.bind(i),i.eventTarget.addEventListener(t.FlowEvents.FLOW_UPDATE,i.flowUpdateCallback,!1),i.userInputUpdateCallback=i.onUserInputUpdate.bind(i),i.eventTarget.addEventListener(t.FlowEvents.USER_INPUT_UPDATE,i.userInputUpdateCallback,!1),i.onInputKeyChangeCallback=i.onInputKeyChange.bind(i),i.eventTarget.addEventListener(t.UserInputEvents.KEY_CHANGE,i.onInputKeyChangeCallback,!1),i.onInputHeightChangeCallback=i.onInputHeightChange.bind(i),i.eventTarget.addEventListener(t.UserInputEvents.HEIGHT_CHANGE,i.onInputHeightChangeCallback,!1),i.onControlElementsResizedCallback=i.onControlElementsResized.bind(i),i.eventTarget.addEventListener(t.ControlElementsEvents.ON_RESIZE,i.onControlElementsResizedCallback,!1),i.onControlElementsChangedCallback=i.onControlElementsChanged.bind(i),i.eventTarget.addEventListener(t.ControlElementsEvents.CHANGED,i.onControlElementsChangedCallback,!1),i}return __extends(n,e),n.prototype.onInputHeightChange=function(e){var n=e.detail.dto;t.ConversationalForm.illustrateFlow(this,"receive",e.type,n),this.onInputElementChanged()},n.prototype.onInputKeyChange=function(e){var n=e.detail.dto;t.ConversationalForm.illustrateFlow(this,"receive",e.type,n)},n.prototype.onUserInputUpdate=function(e){if(t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail),this.currentUserResponse){var n=e.detail;this.setCurrentUserResponse(n)}},n.prototype.addInput=function(t){this.input=t},n.prototype.onControlElementsChanged=function(t){this.onInputElementChanged()},n.prototype.onControlElementsResized=function(e){t.ConversationalForm.illustrateFlow(this,"receive",t.ControlElementsEvents.ON_RESIZE);var n=this.currentResponse;if(n){if(!n.added)for(var i=this.responses.indexOf(n);i>=0;i--){var o=this.responses[i];if(o.added){n=o;break}}n.scrollTo()}this.onInputElementChanged()},n.prototype.onInputElementChanged=function(){if(this.cfReference&&this.cfReference.el){var t=this.cfReference.el.offsetHeight,e=this.input.height,n=t-e;this.el.style.height=n+"px"}},n.prototype.onFlowUpdate=function(e){var n=this;t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var i=e.detail.tag;this.currentResponse&&(this.currentResponse.disabled=!1),this.containsTagResponse(i)&&!e.detail.ignoreExistingTag?this.onUserWantsToEditTag(i):setTimeout(function(){var t=n.createResponse(!0,i,i.question);t.whenReady(function(){n.currentUserResponse=n.createResponse(!1,i),t.scrollTo()}),n.currentUserResponse&&(n.currentUserResponse.setLinkToOtherReponse(t),t.setLinkToOtherReponse(n.currentUserResponse))},0===this.responses.length?500:0)},n.prototype.containsTagResponse=function(t){for(var e=0;e2&&(this.responses[this.responses.length-1].isRobotResponse||this.responses.pop().dealloc(),this.responses.pop().dealloc()),this.currentUserResponse=e,this.currentResponse=this.responses[this.responses.length-1],this.onListUpdate(this.currentUserResponse))},n.prototype.onListUpdate=function(e){var n=this;clearTimeout(this.updateTimer),this.updateTimer=setTimeout(function(){n.eventTarget.dispatchEvent(new CustomEvent(t.ChatListEvents.CHATLIST_UPDATED,{detail:n})),e.show()},0)},n.prototype.clearFrom=function(t){for(t*=2,t+=t%2;this.responses.length>t;)this.responses.pop().dealloc()},n.prototype.setCurrentUserResponse=function(e){this.flowDTOFromUserInputUpdate=e,!this.flowDTOFromUserInputUpdate.text&&e.tag&&("group"==e.tag.type?this.flowDTOFromUserInputUpdate.text=t.Dictionary.get("user-reponse-missing-group"):"password"!=e.tag.type&&(this.flowDTOFromUserInputUpdate.text=t.Dictionary.get("user-reponse-missing"))),this.currentUserResponse.setValue(this.flowDTOFromUserInputUpdate)},n.prototype.getResponses=function(){return this.responses},n.prototype.updateThumbnail=function(e,n){t.Dictionary.set(e?"robot-image":"user-image",e?"robot":"human",n);for(var i=e?t.Dictionary.getRobotResponse("robot-image"):t.Dictionary.get("user-image"),o=0;o\n\t\t\t\t\t\t\n\t\t\t\t\t"},n.prototype.dealloc=function(){this.eventTarget.removeEventListener(t.FlowEvents.FLOW_UPDATE,this.flowUpdateCallback,!1),this.flowUpdateCallback=null,this.eventTarget.removeEventListener(t.FlowEvents.USER_INPUT_UPDATE,this.userInputUpdateCallback,!1),this.userInputUpdateCallback=null,this.eventTarget.removeEventListener(t.UserInputEvents.KEY_CHANGE,this.onInputKeyChangeCallback,!1),this.onInputKeyChangeCallback=null,e.prototype.dealloc.call(this)},n}(t.BasicElement);t.ChatList=e}(cf||(cf={}));var cf;!function(t){t.FlowEvents={USER_INPUT_UPDATE:"cf-flow-user-input-update",USER_INPUT_INVALID:"cf-flow-user-input-invalid",FLOW_UPDATE:"cf-flow-update"};var e=function(){function e(e){this.stopped=!1,this.maxSteps=0,this.step=0,this.savedStep=-1,this.stepTimer=0,this.ignoreExistingTags=!1,this.cfReference=e.cfReference,this.eventTarget=e.eventTarget,this.flowStepCallback=e.flowStepCallback,this.setTags(e.tags),this.userInputSubmitCallback=this.userInputSubmit.bind(this),this.eventTarget.addEventListener(t.UserInputEvents.SUBMIT,this.userInputSubmitCallback,!1)}return Object.defineProperty(e.prototype,"currentTag",{get:function(){return this.tags[this.step]},enumerable:!0,configurable:!0}),e.prototype.userInputSubmit=function(e){var n=this;t.ConversationalForm.illustrateFlow(this,"receive",e.type,e.detail);var i=e.detail;i.tag||(i.tag=this.currentTag);var o=this.currentTag.setTagValueAndIsValid(i),s=!1,r=!1,a=function(){return n.currentTag.validationCallback&&"function"==typeof n.currentTag.validationCallback&&!s&&o?(s=!0,void n.currentTag.validationCallback(i,function(){o=!0,a()},function(t){o=!1,t&&(i.errorText=t),a()})):n.flowStepCallback&&"function"==typeof n.flowStepCallback&&!r&&o?(r=!0,void n.flowStepCallback(i,function(){o=!0,a()},function(t){o=!1,t&&(i.errorText=t),a()})):void(o?(t.ConversationalForm.illustrateFlow(n,"dispatch",t.FlowEvents.USER_INPUT_UPDATE,i),i.input&&(i=i.input.getFlowDTO()),n.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_UPDATE,{detail:i})),setTimeout(function(){return n.nextStep()},t.ConversationalForm.animationsEnabled?250:0)):(t.ConversationalForm.illustrateFlow(n,"dispatch",t.FlowEvents.USER_INPUT_INVALID,i),n.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.USER_INPUT_INVALID,{detail:i}))))};a()},e.prototype.startFrom=function(t,e){void 0===e&&(e=!1),this.step="number"==typeof t?t:this.tags.indexOf(t),this.ignoreExistingTags=e,this.ignoreExistingTags?this.showStep():this.editTag(this.tags[this.step])},e.prototype.areConditionsInFlowFullfilled=function(e,n){this.activeConditions||(this.activeConditions=[]);for(var i=0,o=0;o0){this.savedStep=-1,this.cfReference.chatList.clearFrom(this.step+1);for(var e=this.tags.indexOf(t),n=e+1;n0&&(this.step==this.maxSteps?this.cfReference.doSubmitForm():(this.step%=this.maxSteps,this.currentTag.disabled?this.skipStep():this.showStep()))},e.prototype.showStep=function(){var e=this;this.stopped||(t.ConversationalForm.illustrateFlow(this,"dispatch",t.FlowEvents.FLOW_UPDATE,this.currentTag),this.currentTag.refresh(),setTimeout(function(){e.eventTarget.dispatchEvent(new CustomEvent(t.FlowEvents.FLOW_UPDATE,{detail:{tag:e.currentTag,ignoreExistingTag:e.ignoreExistingTags}}))},0))},e.STEP_TIME=1e3,e}();t.FlowManager=e}(cf||(cf={}));var cf;!function(cf_1){var ConversationalForm=function(){function ConversationalForm(options){if(this.version="0.9.81",this.cdnPath="https://cdn.jsdelivr.net/gh/space10-community/conversational-form@{version}/dist/",this.isDevelopment=!1,this.loadExternalStyleSheet=!0,this.preventAutoAppend=!1,this.preventAutoStart=!1,window.ConversationalForm=this,this.cdnPath=this.cdnPath.split("{version}").join(this.version),"boolean"==typeof options.suppressLog&&(ConversationalForm.suppressLog=options.suppressLog),ConversationalForm.suppressLog||console.log("Conversational Form > version:",this.version),ConversationalForm.suppressLog||console.log("Conversational Form > options:",options),window.ConversationalForm[this.createId]=this,options.eventDispatcher&&(this._eventTarget=options.eventDispatcher),this.eventTarget.cf||(this.eventTarget.cf=this),options.flowStepCallback&&(this.flowStepCallback=options.flowStepCallback),this.isDevelopment=ConversationalForm.illustrateAppFlow=!!document.getElementById("conversational-form-development"),(this.isDevelopment||0==options.loadExternalStyleSheet)&&(this.loadExternalStyleSheet=!1),isNaN(options.scrollAccerlation)||(cf_1.ScrollController.accerlation=options.scrollAccerlation),this.preventAutoStart=options.preventAutoStart,this.preventAutoAppend=options.preventAutoAppend,!options.formEl)throw new Error("Conversational Form error, the formEl needs to be defined.");this.formEl=options.formEl,this.formEl.setAttribute("cf-create-id",this.createId),!0===options.hideUserInputOnNoneTextInput&&(cf_1.UserInputElement.hideUserInputOnNoneTextInput=!0),this.submitCallback=options.submitCallback,this.submitCallback&&"string"==typeof this.submitCallback&&(this.submitCallback=eval(this.submitCallback)),""==this.formEl.getAttribute("cf-no-animation")&&(ConversationalForm.animationsEnabled=!1),(options.preventAutoFocus||""==this.formEl.getAttribute("cf-prevent-autofocus"))&&(cf_1.UserInputElement.preventAutoFocus=!0),this.dictionary=new cf_1.Dictionary({data:options.dictionaryData,robotData:options.dictionaryRobot,userImage:options.userImage,robotImage:options.robotImage}),this.context=options.context?options.context:document.body,this.tags=options.tags,options.microphoneInput&&(options.microphoneInput.init&&options.microphoneInput.input||(console.warn("Conversational Form: microphoneInput is not correctly setup",options.microphoneInput),options.microphoneInput=null)),this.microphoneInputObj=options.microphoneInput,this.uiOptions=cf_1.Helpers.extendObject(cf_1.UserInterfaceDefaultOptions,options.userInterfaceOptions||{}),this.init()}return Object.defineProperty(ConversationalForm.prototype,"createId",{get:function(){return this._createId||(this._createId=(new Date).getTime().toString()),this._createId},enumerable:!0,configurable:!0}),Object.defineProperty(ConversationalForm.prototype,"eventTarget",{get:function(){return this._eventTarget||(this._eventTarget=new cf_1.EventDispatcher(this)),this._eventTarget},enumerable:!0,configurable:!0}),ConversationalForm.prototype.init=function(){if(this.loadExternalStyleSheet){var t=document.head||document.getElementsByTagName("head")[0],e=document.createElement("link"),n=this.cdnPath+"conversational-form.min.css";e.type="text/css",e.media="all",e.setAttribute("rel","stylesheet"),e.setAttribute("href",n),t.appendChild(e)}else this.isDevelopment=!0;if(-1==["fixed","absolute","relative"].indexOf(window.getComputedStyle(this.context).getPropertyValue("position").toLowerCase())&&(this.context.style.position="relative"),!this.tags||0==this.tags.length){this.tags=[];for(var i=[].slice.call(this.formEl.querySelectorAll("input, select, button, textarea, cf-robot-message"),0),o=0;o0)for(var o in e)if(e[o].length>0){var s=e[o][0].domElement.parentNode;s&&"fieldset"!==s.tagName.toLowerCase()&&(s=s.parentNode,function(t){return t&&"fieldset"!==t.tagName.toLowerCase()&&!t.hasAttribute("cf-questions")}(s)&&(s=null));for(var r=new cf_1.TagGroup({fieldset:s,elements:e[o]}),n=0;n0){for(var n=0;n + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+ + +
+ +
+ + +
+ + + +
+ + + + +
+ +
+ + + + +
+ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/src/scripts/cf/ConversationalForm.ts b/src/scripts/cf/ConversationalForm.ts index f8008cc48..8902c0b29 100644 --- a/src/scripts/cf/ConversationalForm.ts +++ b/src/scripts/cf/ConversationalForm.ts @@ -75,6 +75,9 @@ namespace cf { // optional, Whenther to suppress console.log, default true suppressLog?:boolean; + + // Prevent submit on Enter keypress: https://github.com/space10-community/conversational-form/issues/270 + preventSubmitOnEnter?:boolean; } // CUI formless options @@ -89,6 +92,7 @@ namespace cf { public static animationsEnabled: boolean = true; public static illustrateAppFlow: boolean = true; public static suppressLog: boolean = true; + public static preventSubmitOnEnter: boolean = false; private cdnPath: string = "https://cdn.jsdelivr.net/gh/space10-community/conversational-form@{version}/dist/"; /** @@ -118,6 +122,7 @@ namespace cf { public el: HTMLElement; public chatList: ChatList; public uiOptions: IUserInterfaceOptions; + public preventSubmitOnEnter: boolean; private context: HTMLElement; private formEl: HTMLFormElement; @@ -142,6 +147,9 @@ namespace cf { if(typeof options.suppressLog === 'boolean') ConversationalForm.suppressLog = options.suppressLog; + if(typeof options.preventSubmitOnEnter === 'boolean') + this.preventSubmitOnEnter = options.preventSubmitOnEnter; + if(!ConversationalForm.suppressLog) console.log('Conversational Form > version:', this.version); if(!ConversationalForm.suppressLog) console.log('Conversational Form > options:', options); diff --git a/src/scripts/cf/ui/inputs/UserTextInput.ts b/src/scripts/cf/ui/inputs/UserTextInput.ts index 6d6445445..b9c43fc7e 100644 --- a/src/scripts/cf/ui/inputs/UserTextInput.ts +++ b/src/scripts/cf/ui/inputs/UserTextInput.ts @@ -429,6 +429,11 @@ namespace cf { if(event.keyCode == Dictionary.keyCodes["shift"]) this.shiftIsDown = true; + // If submit is prevented by option 'preventSubmitOnEnter' + if (this.cfReference.preventSubmitOnEnter === true && this.inputElement.hasAttribute('rows') && parseInt(this.inputElement.getAttribute('rows')) > 1) { + return; + } + // prevent textarea line breaks if(event.keyCode == Dictionary.keyCodes["enter"] && !event.shiftKey){ event.preventDefault(); @@ -487,6 +492,7 @@ namespace cf { if((event.keyCode == Dictionary.keyCodes["enter"] && !event.shiftKey) || event.keyCode == Dictionary.keyCodes["space"]){ if(event.keyCode == Dictionary.keyCodes["enter"] && this.active){ + if (this.cfReference.preventSubmitOnEnter === true) return; event.preventDefault(); this.onEnterOrSubmitButtonSubmit(); }else{