diff --git a/README.md b/README.md index e71976a..9ca83b2 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ Features: * Fork conversation based on answer * Access previous answers to use on questions * Messages that doesn't expect answer +* Dynamically create new questions (like using an API)! [Demo](https://eduardotkoller.github.io/convForm/api_example.html) - please see the example code inside the html to understand how it works -To build the chat, just wrap the form inside an element, and call .convform() on it's jquery selector. The function requires a placeholder for the user input. +To build the chat, just wrap the form inside an element, and call .convform() on it's jquery selector. Example: @@ -120,7 +121,7 @@ You can add an options object as a parameter to the convForm function, containin * ```typeInputUi```: 'input' or 'textarea', to choose the type of the html element to use as the user's input * ```timeOutFirstQuestion```: time in ms as the duration for the load-up animation before the first question * ```buttonClassStyle```: class for the user's submit answer button -* ```eventList```: an object with functions to be called at specific times, the only supported at the moment is ```onSubmitForm```, and the function is called with the convState as a parameter. +* ```eventList```: an object with functions to be called at specific times, the only supported at the moment are ```onSubmitForm``` (function is called with the convState as a parameter) and ```onInputSubmit``` (function called with the convState as the first parameter, and a ready callback function to print the next question as the second parameter) * ```formIdName```: html id for the form * ```inputIdName```: html id for the user's input * ```loadSpinnerVisible```: class for the loadSpinner diff --git a/api_example.html b/api_example.html new file mode 100644 index 0000000..8d9e896 --- /dev/null +++ b/api_example.html @@ -0,0 +1,66 @@ + + + + convForm - example + + + + + + + + +
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+ + + + + + + diff --git a/dist/jquery.convform.css b/dist/jquery.convform.css index 2466186..ad97838 100644 --- a/dist/jquery.convform.css +++ b/dist/jquery.convform.css @@ -119,26 +119,26 @@ form.convFormDynamic input.userInputDynamic { margin-right: 2.5%; } -div#chat.conv-form-wrapper div#messages { +div.conv-form-wrapper div#messages { max-height: 71vh; height: auto !important; overflow-y: scroll; } -div#chat.conv-form-wrapper div#messages:after { +div.conv-form-wrapper div#messages:after { content: ''; display: table; clear: both; } -div#chat.conv-form-wrapper { +div.conv-form-wrapper { position: relative; } -div#chat.conv-form-wrapper div.wrapper-messages { +div.conv-form-wrapper div.wrapper-messages { position: relative; height: 577px; max-height: 71vh; overflow-y: scroll; } -div#chat:before { +div.conv-form-wrapper:before { content: ''; position: absolute; width: 100%; @@ -150,12 +150,12 @@ div#chat:before { background: linear-gradient(#fff, transparent); } @media (max-width: 767px) { - div#chat.conv-form-wrapper div.wrapper-messages, div#chat.conv-form-wrapper div#messages { + div.conv-form-wrapper div.wrapper-messages, div.conv-form-wrapper div#messages { max-height: 71vh; } } -div#chat div.wrapper-messages::-webkit-scrollbar, div#feed ul::-webkit-scrollbar, div#chat div.options::-webkit-scrollbar { +div.conv-form-wrapper div.wrapper-messages::-webkit-scrollbar, div#feed ul::-webkit-scrollbar, div.conv-form-wrapper div.options::-webkit-scrollbar { width: 0px; height: 0px; /* remove scrollbar space */ @@ -179,7 +179,7 @@ textarea.userInputDynamic { margin: 7px 10px; } -div#chat.conv-form-wrapper div#messages { +div.conv-form-wrapper div#messages { transition: bottom 0.15s, padding-bottom 0.15s; position: absolute; bottom: 0; @@ -188,7 +188,7 @@ div#chat.conv-form-wrapper div#messages { padding-bottom: 20px; /*max-height: 71vh;*/ } -div#chat div.options { +div.conv-form-wrapper div.options { word-wrap: normal; white-space: nowrap; overflow-x: scroll; @@ -197,12 +197,12 @@ div#chat div.options { width: 100%; transform: translateY(-5px); } -div#chat div.options:after { +div.conv-form-wrapper div.options:after { content: ''; display: table; clear: both; } -div#chat div.options div.option { +div.conv-form-wrapper div.options div.option { padding: 7px 12px; border: 1px solid rgba(6,153,184,0.3); display: inline-block; @@ -213,19 +213,19 @@ div#chat div.options div.option { border-radius: 20px; font-size: 0.9rem; } -div#chat.conv-form-wrapper div.message { +div.conv-form-wrapper div.message { animation: slideTop 0.15s ease; } -div#chat.conv-form-wrapper div.message:after { +div.conv-form-wrapper div.message:after { content: ''; display: table; clear: both; } -div#chat.conv-form-wrapper div.message.ready { +div.conv-form-wrapper div.message.ready { animation: bounceIn 0.2s ease; transform-origin: 0 0 0; } -div#chat.conv-form-wrapper div#messages div.message { +div.conv-form-wrapper div#messages div.message { border-radius: 20px; padding: 12px 22px; font-size: 0.905rem; @@ -239,13 +239,13 @@ div#chat.conv-form-wrapper div#messages div.message { max-width: 65%; word-wrap: break-word; } -div#chat.conv-form-wrapper div#messages div.message.to { +div.conv-form-wrapper div#messages div.message.to { background: #efefef; color: #6f6f6f; float: left; border-top-left-radius: 0; } -div#chat.conv-form-wrapper div#messages div.message.from { +div.conv-form-wrapper div#messages div.message.from { background: #06b79a; color: #fff; border-top-right-radius: 0; @@ -270,14 +270,14 @@ div#chat.conv-form-wrapper div#messages div.message.from { transform: scale(1.0, 1.0); } } -div#chat div.options div.option:hover { +div.conv-form-wrapper div.options div.option:hover { background: #eeeeee; } -div#chat div.options div.option.selected { +div.conv-form-wrapper div.options div.option.selected { background: #06b79a; color: #fff; } -div#chat div.options div.option.selected:hover { +div.conv-form-wrapper div.options div.option.selected:hover { background: #069c7f; } @@ -312,7 +312,7 @@ button.submit.glow { .dragscroll { cursor: grab; } -div#chat div#messages::-webkit-scrollbar, div#feed ul::-webkit-scrollbar { +div.conv-form-wrapper div#messages::-webkit-scrollbar, div#feed ul::-webkit-scrollbar { width: 0px; /* remove scrollbar space */ background: transparent; diff --git a/dist/jquery.convform.js b/dist/jquery.convform.js index 8bcdf6c..e96a1d0 100644 --- a/dist/jquery.convform.js +++ b/dist/jquery.convform.js @@ -1,8 +1,9 @@ function SingleConvState(input){ this.input = input; + this.answer = ''; this.next = false; return this; -} +}; SingleConvState.prototype.hasNext = function(){ return this.next; }; @@ -15,7 +16,21 @@ function ConvState(wrapper, SingleConvState, form, params) { this.scrollDown = function() { $(this.wrapper).find('#messages').stop().animate({scrollTop: $(this.wrapper).find('#messages')[0].scrollHeight}, 600); }.bind(this); -} +}; +ConvState.prototype.newState = function(options) { + var input = $.extend(true, {}, { + name: '', + noAnswer: false, + required: true, + questions: ['You forgot the question!'], + type: 'text', + multiple: false, + selected: "", + answers: [] + }, options); + input.element = $(''); + return new SingleConvState(input); +}; ConvState.prototype.next = function(){ if(this.current.input.hasOwnProperty('callback')) { window[this.current.input.callback](this); @@ -60,11 +75,7 @@ ConvState.prototype.printQuestion = function(){ } } } - var messageObj = $('
'); - setTimeout(function(){ - $(this.wrapper).find('#messages').append(messageObj); - this.scrollDown(); - }.bind(this), 100); + var messageObj = $(this.wrapper).find('.message.typing'); setTimeout(function(){ messageObj.html(question); messageObj.removeClass('typing').addClass('ready'); @@ -72,9 +83,12 @@ ConvState.prototype.printQuestion = function(){ this.printAnswers(this.current.input.answers, this.current.input.multiple); } this.scrollDown(); - if(this.current.input.hasOwnProperty('noAnswer')) { + if(this.current.input.hasOwnProperty('noAnswer') && this.current.input.noAnswer===true) { if(this.next()){ setTimeout(function(){ + var messageObj = $('
'); + $(this.wrapper).find('#messages').append(messageObj); + this.scrollDown(); this.printQuestion(); }.bind(this),200); } else { @@ -141,9 +155,11 @@ ConvState.prototype.answerWith = function(answerText, answerObject) { if(this.current.input.type == 'tel') answerObject = answerObject.replace(/\s|\(|\)|-/g, ""); this.answers[this.current.input.name] = {text: answerText, value: answerObject}; + this.current.answer = {text: answerText, value: answerObject}; //console.log('previous answer: ', answerObject); } else { this.answers[this.current.input.name] = answerObject; + this.current.answer = answerObject; } if(this.current.input.type == 'select' && !this.current.input.multiple) { $(this.current.input.element).val(answerObject.value).change(); @@ -169,22 +185,31 @@ ConvState.prototype.answerWith = function(answerText, answerObject) { setTimeout(function(){ $(this.wrapper).find("#messages").append(message); this.scrollDown(); - }.bind(this), 300); + }.bind(this), 100); $(this.form).append(this.current.input.element); - //goes to next state and prints question - if(this.next()){ - setTimeout(function(){ - this.printQuestion(); - }.bind(this), 300); - } else { - this.parameters.eventList.onSubmitForm(this); - } + var messageObj = $('
'); + setTimeout(function(){ + $(this.wrapper).find('#messages').append(messageObj); + this.scrollDown(); + }.bind(this), 150); + + this.parameters.eventList.onInputSubmit(this, function(){ + //goes to next state and prints question + if(this.next()){ + setTimeout(function(){ + this.printQuestion(); + }.bind(this), 300); + } else { + this.parameters.eventList.onSubmitForm(this); + } + }.bind(this)); }; (function($){ $.fn.convform = function(options){ var wrapper = this; + $(this).addClass('conv-form-wrapper'); var parameters = $.extend(true, {}, { placeHolder : 'Type Here', @@ -196,7 +221,8 @@ ConvState.prototype.answerWith = function(answerText, answerObject) { console.log('completed'); convState.form.submit(); return true; - } + }, + onInputSubmit : function(convState, readyCallback) {readyCallback()} }, formIdName : 'convForm', inputIdName : 'userInput', @@ -288,6 +314,9 @@ ConvState.prototype.answerWith = function(answerText, answerObject) { //prints first question setTimeout(function() { $.when($('div.spinLoader').addClass('hidden')).done(function() { + var messageObj = $('
'); + $(state.wrapper).find('#messages').append(messageObj); + state.scrollDown(); state.printQuestion(); }); }, parameters.timeOutFirstQuestion); @@ -443,9 +472,3 @@ ConvState.prototype.answerWith = function(answerText, answerObject) { } } })( jQuery ); - -$(function(){ - //instantiate conversation form on .conv-form-wrapper (default class for plugin); - var convForm = $('.conv-form-wrapper').convform(); - console.log(convForm); -}); diff --git a/dist/jquery.convform.min.css b/dist/jquery.convform.min.css index 238c31c..fde225d 100644 --- a/dist/jquery.convform.min.css +++ b/dist/jquery.convform.min.css @@ -1 +1 @@ -.typing_loader,div#chat.conv-form-wrapper,form.convFormDynamic{position:relative}input[type=text].userInputDynamic.error,textarea.userInputDynamic.error{color:#ac0000!important}.typing_loader{width:6px;height:6px;border-radius:50%;-webkit-animation:typing 1s linear infinite alternate;-moz-animation:typing 1s linear infinite alternate;-ms-animation:typing 1s linear infinite alternate;animation:typing 1s linear infinite alternate;left:-12px;margin:7px 15px 6px}.to .typing_loader{animation:typing-black 1s linear infinite alternate}@-webkit-keyframes typing{0%{background-color:rgba(255,255,255,1);box-shadow:12px 0 0 0 rgba(255,255,255,.4),24px 0 0 0 rgba(255,255,255,.2)}50%{background-color:rgba(255,255,255,.4);box-shadow:12px 0 0 0 rgba(255,255,255,1),24px 0 0 0 rgba(255,255,255,.4)}100%{background-color:rgba(255,255,255,.2);box-shadow:12px 0 0 0 rgba(255,255,255,.4),24px 0 0 0 rgba(255,255,255,1)}}@-moz-keyframes typing{0%{background-color:rgba(255,255,255,1);box-shadow:12px 0 0 0 rgba(255,255,255,.4),24px 0 0 0 rgba(255,255,255,.2)}50%{background-color:rgba(255,255,255,.4);box-shadow:12px 0 0 0 rgba(255,255,255,1),24px 0 0 0 rgba(255,255,255,.4)}100%{background-color:rgba(255,255,255,.2);box-shadow:12px 0 0 0 rgba(255,255,255,.4),24px 0 0 0 rgba(255,255,255,1)}}@keyframes typing-black{0%{background-color:rgba(74,74,74,1);box-shadow:12px 0 0 0 rgba(74,74,74,.4),24px 0 0 0 rgba(74,74,74,.2)}50%{background-color:rgba(74,74,74,.4);box-shadow:12px 0 0 0 rgba(74,74,74,1),24px 0 0 0 rgba(74,74,74,.4)}100%{background-color:rgba(74,74,74,.2);box-shadow:12px 0 0 0 rgba(74,74,74,.4),24px 0 0 0 rgba(74,74,74,1)}}@keyframes typing{0%{background-color:rgba(255,255,255,1);box-shadow:12px 0 0 0 rgba(255,255,255,.4),24px 0 0 0 rgba(255,255,255,.2)}50%{background-color:rgba(255,255,255,.4);box-shadow:12px 0 0 0 rgba(255,255,255,1),24px 0 0 0 rgba(255,255,255,.4)}100%{background-color:rgba(255,255,255,.2);box-shadow:12px 0 0 0 rgba(255,255,255,.4),24px 0 0 0 rgba(255,255,255,1)}}form.convFormDynamic{width:calc(100% - 33px);margin:10px auto 15px;padding:0!important;box-shadow:0 0 5px 5px rgba(222,222,222,.4)}form.convFormDynamic input.userInputDynamic,form.convFormDynamic textarea.userInputDynamic{border:none;padding:7px 10px;outline:0;font-size:.905rem;float:left;width:calc(100% - 70px);line-height:1.3em;min-height:1.7em;max-height:10rem;display:block;max-width:88%;margin-right:2.5%}input[type=text].userInputDynamic,textarea.userInputDynamic{border-radius:3px;margin:7px 10px}div#chat.conv-form-wrapper div#messages:after{content:'';display:table;clear:both}div#chat.conv-form-wrapper div.wrapper-messages{position:relative;height:577px;max-height:71vh;overflow-y:scroll}div#chat:before{content:'';position:absolute;width:100%;display:block;height:30px;top:0;left:0;z-index:2;background:linear-gradient(#fff,transparent)}@media (max-width:767px){div#chat.conv-form-wrapper div#messages,div#chat.conv-form-wrapper div.wrapper-messages{max-height:71vh}}div#chat div.options::-webkit-scrollbar,div#chat div.wrapper-messages::-webkit-scrollbar,div#feed ul::-webkit-scrollbar{width:0;height:0;background:0 0}div#chat.conv-form-wrapper div#messages{max-height:71vh;overflow-y:scroll;transition:bottom .15s,padding-bottom .15s;position:absolute;bottom:0;height:auto!important;width:100%;padding-bottom:20px}div#chat div.options{word-wrap:normal;white-space:nowrap;overflow-x:scroll;position:absolute;bottom:100%;width:100%;transform:translateY(-5px)}div#chat div.options:after{content:'';display:table;clear:both}div#chat div.options div.option{padding:7px 12px;border:1px solid rgba(6,153,184,.3);display:inline-block;margin:5px;background:#fff;color:#06c5a6;cursor:pointer;border-radius:20px;font-size:.9rem}div#chat.conv-form-wrapper div.message{animation:slideTop .15s ease}div#chat.conv-form-wrapper div.message:after{content:'';display:table;clear:both}div#chat.conv-form-wrapper div.message.ready{animation:bounceIn .2s ease;transform-origin:0 0 0}div#chat.conv-form-wrapper div#messages div.message{font-size:.905rem;color:#333;display:inline-block;padding:10px 15px 8px;border-radius:20px;margin-bottom:5px;float:right;clear:both;max-width:65%;word-wrap:break-word}div#chat.conv-form-wrapper div#messages div.message.to{background:#efefef;color:#6f6f6f;float:left;border-top-left-radius:0}div#chat.conv-form-wrapper div#messages div.message.from{background:#06b79a;color:#fff;border-top-right-radius:0}.message.from+.message.to,.message.to+.message.from{margin-top:15px}@keyframes slideTop{0%{margin-bottom:-25px}100%{margin-bottom:0}}@keyframes bounceIn{0%{transform:scale(.75,.75)}100%{transform:scale(1,1)}}div#chat div.options div.option:hover{background:#eee}div#chat div.options div.option.selected{background:#06b79a;color:#fff}div#chat div.options div.option.selected:hover{background:#069c7f}form.convFormDynamic button.submit{padding:3px;border:none;float:left;margin:4px 5px 5px;color:#06c5a6;cursor:pointer;border-radius:8px;font-size:1.1rem;width:36px;height:35px;background:#fff;outline:0!important}form.convFormDynamic button.submit:hover{background:#06b79a;color:#fff}button.submit.glow{box-shadow:0 0 10px 5px rgba(6,197,166,.4)}.no-border{border:none!important}.dragscroll{cursor:grab}div#chat div#messages::-webkit-scrollbar,div#feed ul::-webkit-scrollbar{width:0;background:0 0}span.clear{display:block;clear:both}.spinLoader,.spinLoader:after,.spinLoader:before{background:#06c5a6!important;-webkit-animation:spinLoaderChat 1s infinite ease-in-out;animation:spinLoaderChat 1s infinite ease-in-out;width:1em;height:4em}.spinLoader{color:#06c5a6!important;text-indent:-9999em;margin:50% auto;position:relative;font-size:11px;-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);-webkit-animation-delay:-.16s;animation-delay:-.16s}.spinLoader:after,.spinLoader:before{position:absolute;top:0;content:''}.spinLoader:before{left:-1.5em;-webkit-animation-delay:-.32s;animation-delay:-.32s}.spinLoader:after{left:1.5em}@-webkit-keyframes spinLoaderChat{0%,100%,80%{box-shadow:0 0;height:4em}40%{box-shadow:0 -2em;height:5em}}@keyframes spinLoaderChat{0%,100%,80%{box-shadow:0 0;height:4em}40%{box-shadow:0 -2em;height:5em}} \ No newline at end of file +.typing_loader{width:6px;height:6px;border-radius:50%;-webkit-animation:typing 1s linear infinite alternate;-moz-animation:typing 1s linear infinite alternate;-ms-animation:typing 1s linear infinite alternate;animation:typing 1s linear infinite alternate;position:relative;left:-12px;margin:7px 15px 6px}.to .typing_loader{animation:typing-black 1s linear infinite alternate}@-webkit-keyframes typing{0%{background-color:rgba(255,255,255,1);box-shadow:12px 0 0 0 rgba(255,255,255,0.4),24px 0 0 0 rgba(255,255,255,0.2)}50%{background-color:rgba(255,255,255,0.4);box-shadow:12px 0 0 0 rgba(255,255,255,1),24px 0 0 0 rgba(255,255,255,0.4)}100%{background-color:rgba(255,255,255,0.2);box-shadow:12px 0 0 0 rgba(255,255,255,0.4),24px 0 0 0 rgba(255,255,255,1)}}@-moz-keyframes typing{0%{background-color:rgba(255,255,255,1);box-shadow:12px 0 0 0 rgba(255,255,255,0.4),24px 0 0 0 rgba(255,255,255,0.2)}50%{background-color:rgba(255,255,255,0.4);box-shadow:12px 0 0 0 rgba(255,255,255,1),24px 0 0 0 rgba(255,255,255,0.4)}100%{background-color:rgba(255,255,255,0.2);box-shadow:12px 0 0 0 rgba(255,255,255,0.4),24px 0 0 0 rgba(255,255,255,1)}}@keyframes typing-black{0%{background-color:rgba(74,74,74,1);box-shadow:12px 0 0 0 rgba(74,74,74,0.4),24px 0 0 0 rgba(74,74,74,0.2)}50%{background-color:rgba(74,74,74,0.4);box-shadow:12px 0 0 0 rgba(74,74,74,1),24px 0 0 0 rgba(74,74,74,0.4)}100%{background-color:rgba(74,74,74,0.2);box-shadow:12px 0 0 0 rgba(74,74,74,0.4),24px 0 0 0 rgba(74,74,74,1)}}@keyframes typing{0%{background-color:rgba(255,255,255,1);box-shadow:12px 0 0 0 rgba(255,255,255,0.4),24px 0 0 0 rgba(255,255,255,0.2)}50%{background-color:rgba(255,255,255,0.4);box-shadow:12px 0 0 0 rgba(255,255,255,1),24px 0 0 0 rgba(255,255,255,0.4)}100%{background-color:rgba(255,255,255,0.2);box-shadow:12px 0 0 0 rgba(255,255,255,0.4),24px 0 0 0 rgba(255,255,255,1)}}form.convFormDynamic{width:calc(100% - 33px);margin:10px auto 15px;padding:0!important;position:relative;box-shadow:0 0 5px 5px rgba(222,222,222,0.4)}form.convFormDynamic textarea.userInputDynamic{border:0;padding:7px 10px;outline:0;font-size:.905rem;float:left;width:calc(100% - 70px);line-height:1.3em;min-height:1.7em;max-height:10rem;display:block;max-width:88%;margin-right:2.5%}form.convFormDynamic input.userInputDynamic{border:0;padding:7px 10px;outline:0;font-size:.905rem;float:left;width:calc(100% - 70px);line-height:1.3em;min-height:1.7em;max-height:10rem;display:block;max-width:88%;margin-right:2.5%}div.conv-form-wrapper div#messages{max-height:71vh;height:auto!important;overflow-y:scroll}div.conv-form-wrapper div#messages:after{content:'';display:table;clear:both}div.conv-form-wrapper{position:relative}div.conv-form-wrapper div.wrapper-messages{position:relative;height:577px;max-height:71vh;overflow-y:scroll}div.conv-form-wrapper:before{content:'';position:absolute;width:100%;display:block;height:30px;top:0;left:0;z-index:2;background:linear-gradient(#fff,transparent)}@media(max-width:767px){div.conv-form-wrapper div.wrapper-messages,div.conv-form-wrapper div#messages{max-height:71vh}}div.conv-form-wrapper div.wrapper-messages::-webkit-scrollbar,div#feed ul::-webkit-scrollbar,div.conv-form-wrapper div.options::-webkit-scrollbar{width:0;height:0;background:transparent}input[type="text"].userInputDynamic.error{color:#ac0000!important}input[type="text"].userInputDynamic{border-radius:3px;margin:7px 10px}textarea.userInputDynamic.error{color:#ac0000!important}textarea.userInputDynamic{border-radius:3px;margin:7px 10px}div.conv-form-wrapper div#messages{transition:bottom .15s,padding-bottom .15s;position:absolute;bottom:0;height:auto!important;width:100%;padding-bottom:20px}div.conv-form-wrapper div.options{word-wrap:normal;white-space:nowrap;overflow-x:scroll;position:absolute;bottom:100%;width:100%;transform:translateY(-5px)}div.conv-form-wrapper div.options:after{content:'';display:table;clear:both}div.conv-form-wrapper div.options div.option{padding:7px 12px;border:1px solid rgba(6,153,184,0.3);display:inline-block;margin:5px;background:#fff;color:#06c5a6;cursor:pointer;border-radius:20px;font-size:.9rem}div.conv-form-wrapper div.message{animation:slideTop .15s ease}div.conv-form-wrapper div.message:after{content:'';display:table;clear:both}div.conv-form-wrapper div.message.ready{animation:bounceIn .2s ease;transform-origin:0 0}div.conv-form-wrapper div#messages div.message{border-radius:20px;padding:12px 22px;font-size:.905rem;color:#333;display:inline-block;padding:10px 15px 8px;border-radius:20px;margin-bottom:5px;float:right;clear:both;max-width:65%;word-wrap:break-word}div.conv-form-wrapper div#messages div.message.to{background:#efefef;color:#6f6f6f;float:left;border-top-left-radius:0}div.conv-form-wrapper div#messages div.message.from{background:#06b79a;color:#fff;border-top-right-radius:0}.message.to+.message.from,.message.from+.message.to{margin-top:15px}@keyframes slideTop{0%{margin-bottom:-25px}100%{margin-bottom:0}}@keyframes bounceIn{0%{transform:scale(0.75,0.75)}100%{transform:scale(1.0,1.0)}}div.conv-form-wrapper div.options div.option:hover{background:#eee}div.conv-form-wrapper div.options div.option.selected{background:#06b79a;color:#fff}div.conv-form-wrapper div.options div.option.selected:hover{background:#069c7f}form.convFormDynamic button.submit{padding:3px;border:0;float:left;margin:5px;color:#06c5a6;cursor:pointer;border-radius:8px;font-size:1.1rem;width:36px;height:35px;margin-top:4px;background:#fff;outline:none!important}form.convFormDynamic button.submit:hover{background:#06b79a;color:#fff}button.submit.glow{box-shadow:0 0 10px 5px rgba(6,197,166,0.4)}.no-border{border:none!important}.dragscroll{cursor:grab}div.conv-form-wrapper div#messages::-webkit-scrollbar,div#feed ul::-webkit-scrollbar{width:0;background:transparent}span.clear{display:block;clear:both}.spinLoader,.spinLoader:before,.spinLoader:after{background:#06c5a6!important;-webkit-animation:spinLoaderChat 1s infinite ease-in-out;animation:spinLoaderChat 1s infinite ease-in-out;width:1em;height:4em}.spinLoader{color:#06c5a6!important;text-indent:-9999em;margin:50% auto;position:relative;font-size:11px;-webkit-transform:translateZ(0);-ms-transform:translateZ(0);transform:translateZ(0);-webkit-animation-delay:-0.16s;animation-delay:-0.16s}.spinLoader:before,.spinLoader:after{position:absolute;top:0;content:''}.spinLoader:before{left:-1.5em;-webkit-animation-delay:-0.32s;animation-delay:-0.32s}.spinLoader:after{left:1.5em}@-webkit-keyframes spinLoaderChat{0%,80%,100%{box-shadow:0;height:4em}40%{box-shadow:0 -2em;height:5em}}@keyframes spinLoaderChat{0%,80%,100%{box-shadow:0;height:4em}40%{box-shadow:0 -2em;height:5em}} \ No newline at end of file diff --git a/dist/jquery.convform.min.js b/dist/jquery.convform.min.js index 33dc2fd..3fc5b04 100644 --- a/dist/jquery.convform.min.js +++ b/dist/jquery.convform.min.js @@ -1 +1 @@ -function SingleConvState(t){return this.input=t,this.next=!1,this}function ConvState(t,e,r,n){this.form=r,this.wrapper=t,this.current=e,this.answers={},this.parameters=n,this.scrollDown=function(){$(this.wrapper).find("#messages").stop().animate({scrollTop:$(this.wrapper).find("#messages")[0].scrollHeight},600)}.bind(this)}SingleConvState.prototype.hasNext=function(){return this.next},ConvState.prototype.next=function(){if(this.current.input.hasOwnProperty("callback")&&window[this.current.input.callback](this),this.current.hasNext()){if(this.current=this.current.next,this.current.input.hasOwnProperty("fork")&&this.current.input.hasOwnProperty("case")){if(this.answers.hasOwnProperty(this.current.input.fork)&&this.answers[this.current.input.fork].value!=this.current.input.case)return this.next();if(!this.answers.hasOwnProperty(this.current.input.fork))return this.next()}return!0}return!1},ConvState.prototype.printQuestion=function(){var t=this.current.input.questions,e=t[Math.floor(Math.random()*t.length)],r=e.match(/\{(.*?)\}(\:(\d)*)?/g);for(var n in r)if(r.hasOwnProperty(n)){var i=r[n].replace(/\{|\}/g,""),a=i,s=!1;if(-1!=i.indexOf(":")&&(a=a.split(":")[0],s=i.split(":")[1]),!1!==s){var p=this.answers[a].text.split(" ");e=p.length>=s?e.replace(r[n],p[s]):e.replace(r[n],this.answers[a].text)}else e=e.replace(r[n],this.answers[a].text)}var u=$('
');setTimeout(function(){$(this.wrapper).find("#messages").append(u),this.scrollDown()}.bind(this),100),setTimeout(function(){u.html(e),u.removeClass("typing").addClass("ready"),"select"==this.current.input.type&&this.printAnswers(this.current.input.answers,this.current.input.multiple),this.scrollDown(),this.current.input.hasOwnProperty("noAnswer")&&(this.next()?setTimeout(function(){this.printQuestion()}.bind(this),200):this.parameters.eventList.onSubmitForm(this)),$(this.wrapper).find(this.parameters.inputIdHashTagName).focus()}.bind(this),500)},ConvState.prototype.printAnswers=function(t,e){if(this.wrapper.find("div.options div.option").remove(),e){for(var r in t)if(t.hasOwnProperty(r)){var n=$('
'+t[r].text+"
").data("answer",t[r]).click(function(t){var e=this.current.input.selected.indexOf($(t.target).data("answer").value);-1==e?(this.current.input.selected.push($(t.target).data("answer").value),$(t.target).addClass("selected")):(this.current.input.selected.splice(e,1),$(t.target).removeClass("selected")),this.wrapper.find(this.parameters.inputIdHashTagName).removeClass("error"),this.wrapper.find(this.parameters.inputIdHashTagName).val(""),this.current.input.selected.length>0?this.wrapper.find("button.submit").addClass("glow"):this.wrapper.find("button.submit").removeClass("glow")}.bind(this));this.wrapper.find("div.options").append(n),$(window).trigger("dragreset")}}else for(var r in t)if(t.hasOwnProperty(r)){var n=$('
'+t[r].text+"
").data("answer",t[r]).click(function(t){this.current.input.selected=$(t.target).data("answer").value,this.wrapper.find(this.parameters.inputIdHashTagName).removeClass("error"),this.wrapper.find(this.parameters.inputIdHashTagName).val(""),this.answerWith($(t.target).data("answer").text,$(t.target).data("answer")),this.wrapper.find("div.options div.option").remove()}.bind(this));this.wrapper.find("div.options").append(n),$(window).trigger("dragreset")}var i=$(this.wrapper).find("div.options").height();$(this.wrapper).find("#messages").css({paddingBottom:i})},ConvState.prototype.answerWith=function(t,e){this.current.input.hasOwnProperty("name")&&("string"==typeof e?("tel"==this.current.input.type&&(e=e.replace(/\s|\(|\)|-/g,"")),this.answers[this.current.input.name]={text:t,value:e}):this.answers[this.current.input.name]=e,"select"!=this.current.input.type||this.current.input.multiple?$(this.current.input.element).val(e).change():$(this.current.input.element).val(e.value).change()),"password"==this.current.input.type&&(t=t.replace(/./g,"*"));var r=$('
'+t+"
");$(this.wrapper).find("div.options div.option").remove();var n=$(this.wrapper).find("div.options").height();$(this.wrapper).find("#messages").css({paddingBottom:n}),$(this.wrapper).find(this.parameters.inputIdHashTagName).focus(),e.hasOwnProperty("callback")&&window[e.callback](this),setTimeout(function(){$(this.wrapper).find("#messages").append(r),this.scrollDown()}.bind(this),300),$(this.form).append(this.current.input.element),this.next()?setTimeout(function(){this.printQuestion()}.bind(this),300):this.parameters.eventList.onSubmitForm(this)},function(t){t.fn.convform=function(e){var r=this,n=t.extend(!0,{},{placeHolder:"Type Here",typeInputUi:"textarea",timeOutFirstQuestion:1200,buttonClassStyle:"icon2-arrow",eventList:{onSubmitForm:function(t){return console.log("completed"),t.form.submit(),!0}},formIdName:"convForm",inputIdName:"userInput",loadSpinnerVisible:"",buttonText:"▶"},e),i=t(this).find("input, select, textarea").map(function(){var e={};return t(this).attr("name")&&(e.name=t(this).attr("name")),t(this).attr("data-no-answer")&&(e.noAnswer=!0),t(this).attr("required")&&(e.required=!0),t(this).attr("type")&&(e.type=t(this).attr("type")),e.questions=t(this).attr("data-conv-question").split("|"),t(this).attr("data-pattern")&&(e.pattern=t(this).attr("data-pattern")),t(this).attr("data-callback")&&(e.callback=t(this).attr("data-callback")),t(this).is("select")&&(e.type="select",e.answers=t(this).find("option").map(function(){var e={};return e.text=t(this).text(),e.value=t(this).val(),t(this).attr("data-callback")&&(e.callback=t(this).attr("data-callback")),e}).get(),t(this).prop("multiple")?(e.multiple=!0,e.selected=[]):(e.multiple=!1,e.selected="")),t(this).parent("div[data-conv-case]").length&&(e.case=t(this).parent("div[data-conv-case]").attr("data-conv-case"),e.fork=t(this).parent("div[data-conv-case]").parent("div[data-conv-fork]").attr("data-conv-fork")),e.element=this,t(this).detach(),e}).get();if(i.length){var a,s=t(r).find("form").hide();switch(n.inputIdHashTagName="#"+n.inputIdName,n.typeInputUi){case"input":a=t('
');break;case"textarea":a=t('
');break;default:return console.log("typeInputUi must be input or textarea"),!1}t(r).append('
'),t(r).append(a);var p=new SingleConvState(i[0]),u=new ConvState(r,p,s,n);for(var o in i)0!=o&&i.hasOwnProperty(o)&&(p.next=new SingleConvState(i[o]),p=p.next);return setTimeout(function(){t.when(t("div.spinLoader").addClass("hidden")).done(function(){u.printQuestion()})},n.timeOutFirstQuestion),t(a).find(n.inputIdHashTagName).keypress(function(e){if(13==e.which){var r=t(this).val();if(e.preventDefault(),"select"!=u.current.input.type||u.current.input.multiple)if("select"==u.current.input.type&&u.current.input.multiple)if(""!=r.trim()){var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?-1==u.current.input.selected.indexOf(i[0].value)?(u.current.input.selected.push(i[0].value),u.wrapper.find(n.inputIdHashTagName).val("")):u.wrapper.find(n.inputIdHashTagName).val(""):u.wrapper.find(n.inputIdHashTagName).addClass("error")}else u.current.input.selected.length&&t(this).parent("form").submit();else""==r.trim()||u.wrapper.find(n.inputIdHashTagName).hasClass("error")?t(u.wrapper).find(n.inputIdHashTagName).focus():t(this).parent("form").submit();else if(u.current.input.required)u.wrapper.find("#userInputBot").addClass("error");else{var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?(u.current.input.selected=i[0],t(this).parent("form").submit()):u.wrapper.find(n.inputIdHashTagName).addClass("error")}}autosize.update(t(u.wrapper).find(n.inputIdHashTagName))}).on("input",function(e){if("select"==u.current.input.type){var r=t(this).val(),i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?(u.wrapper.find(n.inputIdHashTagName).removeClass("error"),u.printAnswers(i,u.current.input.multiple)):u.wrapper.find(n.inputIdHashTagName).addClass("error")}else if(u.current.input.hasOwnProperty("pattern")){var a=new RegExp(u.current.input.pattern,"i");a.test(t(this).val())?u.wrapper.find(n.inputIdHashTagName).removeClass("error"):u.wrapper.find(n.inputIdHashTagName).addClass("error")}}),t(a).find("button.submit").click(function(e){var r=t(u.wrapper).find(n.inputIdHashTagName).val();if(e.preventDefault(),"select"!=u.current.input.type||u.current.input.multiple)if("select"==u.current.input.type&&u.current.input.multiple){if(u.current.input.required)return!1;if(""!=r.trim()&&r!=n.placeHolder){var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?-1==u.current.input.selected.indexOf(i[0].value)?(u.current.input.selected.push(i[0].value),u.wrapper.find(n.inputIdHashTagName).val("")):u.wrapper.find(n.inputIdHashTagName).val(""):u.wrapper.find(n.inputIdHashTagName).addClass("error")}else u.current.input.selected.length&&(t(this).removeClass("glow"),t(this).parent("form").submit())}else""==r.trim()||u.wrapper.find(n.inputIdHashTagName).hasClass("error")?t(u.wrapper).find(n.inputIdHashTagName).focus():t(this).parent("form").submit();else{if(u.current.input.required)return!1;r==n.placeHolder&&(r="");var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?(u.current.input.selected=i[0],t(this).parent("form").submit()):u.wrapper.find(n.inputIdHashTagName).addClass("error")}autosize.update(t(u.wrapper).find(n.inputIdHashTagName))}),t(a).submit(function(e){e.preventDefault();var r=t(this).find(n.inputIdHashTagName).val();t(this).find(n.inputIdHashTagName).val(""),"select"==u.current.input.type?u.current.input.multiple?u.answerWith(u.current.input.selected.join(", "),u.current.input.selected):u.answerWith(u.current.input.selected.text,u.current.input.selected):u.answerWith(r,r)}),"function"==typeof autosize&&($textarea=t(u.wrapper).find(n.inputIdHashTagName),autosize($textarea)),u}return!1}}(jQuery),$(function(){var t=$(".conv-form-wrapper").convform();console.log(t)}); \ No newline at end of file +function SingleConvState(t){return this.input=t,this.answer="",this.next=!1,this}function ConvState(t,e,r,n){this.form=r,this.wrapper=t,this.current=e,this.answers={},this.parameters=n,this.scrollDown=function(){$(this.wrapper).find("#messages").stop().animate({scrollTop:$(this.wrapper).find("#messages")[0].scrollHeight},600)}.bind(this)}SingleConvState.prototype.hasNext=function(){return this.next},ConvState.prototype.newState=function(t){var e=$.extend(!0,{},{name:"",noAnswer:!1,required:!0,questions:["You forgot the question!"],type:"text",multiple:!1,selected:"",answers:[]},t);return e.element=$(''),new SingleConvState(e)},ConvState.prototype.next=function(){if(this.current.input.hasOwnProperty("callback")&&window[this.current.input.callback](this),this.current.hasNext()){if(this.current=this.current.next,this.current.input.hasOwnProperty("fork")&&this.current.input.hasOwnProperty("case")){if(this.answers.hasOwnProperty(this.current.input.fork)&&this.answers[this.current.input.fork].value!=this.current.input.case)return this.next();if(!this.answers.hasOwnProperty(this.current.input.fork))return this.next()}return!0}return!1},ConvState.prototype.printQuestion=function(){var t=this.current.input.questions,e=t[Math.floor(Math.random()*t.length)],r=e.match(/\{(.*?)\}(\:(\d)*)?/g);for(var n in r)if(r.hasOwnProperty(n)){var i=r[n].replace(/\{|\}/g,""),a=i,s=!1;if(-1!=i.indexOf(":")&&(a=a.split(":")[0],s=i.split(":")[1]),!1!==s){var p=this.answers[a].text.split(" ");e=p.length>=s?e.replace(r[n],p[s]):e.replace(r[n],this.answers[a].text)}else e=e.replace(r[n],this.answers[a].text)}var u=$(this.wrapper).find(".message.typing");setTimeout(function(){u.html(e),u.removeClass("typing").addClass("ready"),"select"==this.current.input.type&&this.printAnswers(this.current.input.answers,this.current.input.multiple),this.scrollDown(),this.current.input.hasOwnProperty("noAnswer")&&!0===this.current.input.noAnswer&&(this.next()?setTimeout(function(){var t=$('
');$(this.wrapper).find("#messages").append(t),this.scrollDown(),this.printQuestion()}.bind(this),200):this.parameters.eventList.onSubmitForm(this)),$(this.wrapper).find(this.parameters.inputIdHashTagName).focus()}.bind(this),500)},ConvState.prototype.printAnswers=function(t,e){if(this.wrapper.find("div.options div.option").remove(),e){for(var r in t)if(t.hasOwnProperty(r)){var n=$('
'+t[r].text+"
").data("answer",t[r]).click(function(t){var e=this.current.input.selected.indexOf($(t.target).data("answer").value);-1==e?(this.current.input.selected.push($(t.target).data("answer").value),$(t.target).addClass("selected")):(this.current.input.selected.splice(e,1),$(t.target).removeClass("selected")),this.wrapper.find(this.parameters.inputIdHashTagName).removeClass("error"),this.wrapper.find(this.parameters.inputIdHashTagName).val(""),this.current.input.selected.length>0?this.wrapper.find("button.submit").addClass("glow"):this.wrapper.find("button.submit").removeClass("glow")}.bind(this));this.wrapper.find("div.options").append(n),$(window).trigger("dragreset")}}else for(var r in t)if(t.hasOwnProperty(r)){var n=$('
'+t[r].text+"
").data("answer",t[r]).click(function(t){this.current.input.selected=$(t.target).data("answer").value,this.wrapper.find(this.parameters.inputIdHashTagName).removeClass("error"),this.wrapper.find(this.parameters.inputIdHashTagName).val(""),this.answerWith($(t.target).data("answer").text,$(t.target).data("answer")),this.wrapper.find("div.options div.option").remove()}.bind(this));this.wrapper.find("div.options").append(n),$(window).trigger("dragreset")}var i=$(this.wrapper).find("div.options").height();$(this.wrapper).find("#messages").css({paddingBottom:i})},ConvState.prototype.answerWith=function(t,e){this.current.input.hasOwnProperty("name")&&("string"==typeof e?("tel"==this.current.input.type&&(e=e.replace(/\s|\(|\)|-/g,"")),this.answers[this.current.input.name]={text:t,value:e},this.current.answer={text:t,value:e}):(this.answers[this.current.input.name]=e,this.current.answer=e),"select"!=this.current.input.type||this.current.input.multiple?$(this.current.input.element).val(e).change():$(this.current.input.element).val(e.value).change()),"password"==this.current.input.type&&(t=t.replace(/./g,"*"));var r=$('
'+t+"
");$(this.wrapper).find("div.options div.option").remove();var n=$(this.wrapper).find("div.options").height();$(this.wrapper).find("#messages").css({paddingBottom:n}),$(this.wrapper).find(this.parameters.inputIdHashTagName).focus(),e.hasOwnProperty("callback")&&window[e.callback](this),setTimeout(function(){$(this.wrapper).find("#messages").append(r),this.scrollDown()}.bind(this),100),$(this.form).append(this.current.input.element);var i=$('
');setTimeout(function(){$(this.wrapper).find("#messages").append(i),this.scrollDown()}.bind(this),150),this.parameters.eventList.onInputSubmit(this,function(){this.next()?setTimeout(function(){this.printQuestion()}.bind(this),300):this.parameters.eventList.onSubmitForm(this)}.bind(this))},function(t){t.fn.convform=function(e){var r=this;t(this).addClass("conv-form-wrapper");var n=t.extend(!0,{},{placeHolder:"Type Here",typeInputUi:"textarea",timeOutFirstQuestion:1200,buttonClassStyle:"icon2-arrow",eventList:{onSubmitForm:function(t){return console.log("completed"),t.form.submit(),!0},onInputSubmit:function(t,e){e()}},formIdName:"convForm",inputIdName:"userInput",loadSpinnerVisible:"",buttonText:"▶"},e),i=t(this).find("input, select, textarea").map(function(){var e={};return t(this).attr("name")&&(e.name=t(this).attr("name")),t(this).attr("data-no-answer")&&(e.noAnswer=!0),t(this).attr("required")&&(e.required=!0),t(this).attr("type")&&(e.type=t(this).attr("type")),e.questions=t(this).attr("data-conv-question").split("|"),t(this).attr("data-pattern")&&(e.pattern=t(this).attr("data-pattern")),t(this).attr("data-callback")&&(e.callback=t(this).attr("data-callback")),t(this).is("select")&&(e.type="select",e.answers=t(this).find("option").map(function(){var e={};return e.text=t(this).text(),e.value=t(this).val(),t(this).attr("data-callback")&&(e.callback=t(this).attr("data-callback")),e}).get(),t(this).prop("multiple")?(e.multiple=!0,e.selected=[]):(e.multiple=!1,e.selected="")),t(this).parent("div[data-conv-case]").length&&(e.case=t(this).parent("div[data-conv-case]").attr("data-conv-case"),e.fork=t(this).parent("div[data-conv-case]").parent("div[data-conv-fork]").attr("data-conv-fork")),e.element=this,t(this).detach(),e}).get();if(i.length){var a,s=t(r).find("form").hide();switch(n.inputIdHashTagName="#"+n.inputIdName,n.typeInputUi){case"input":a=t('
');break;case"textarea":a=t('
');break;default:return console.log("typeInputUi must be input or textarea"),!1}t(r).append('
'),t(r).append(a);var p=new SingleConvState(i[0]),u=new ConvState(r,p,s,n);for(var o in i)0!=o&&i.hasOwnProperty(o)&&(p.next=new SingleConvState(i[o]),p=p.next);return setTimeout(function(){t.when(t("div.spinLoader").addClass("hidden")).done(function(){var e=t('
');t(u.wrapper).find("#messages").append(e),u.scrollDown(),u.printQuestion()})},n.timeOutFirstQuestion),t(a).find(n.inputIdHashTagName).keypress(function(e){if(13==e.which){var r=t(this).val();if(e.preventDefault(),"select"!=u.current.input.type||u.current.input.multiple)if("select"==u.current.input.type&&u.current.input.multiple)if(""!=r.trim()){var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?-1==u.current.input.selected.indexOf(i[0].value)?(u.current.input.selected.push(i[0].value),u.wrapper.find(n.inputIdHashTagName).val("")):u.wrapper.find(n.inputIdHashTagName).val(""):u.wrapper.find(n.inputIdHashTagName).addClass("error")}else u.current.input.selected.length&&t(this).parent("form").submit();else""==r.trim()||u.wrapper.find(n.inputIdHashTagName).hasClass("error")?t(u.wrapper).find(n.inputIdHashTagName).focus():t(this).parent("form").submit();else if(u.current.input.required)u.wrapper.find("#userInputBot").addClass("error");else{var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?(u.current.input.selected=i[0],t(this).parent("form").submit()):u.wrapper.find(n.inputIdHashTagName).addClass("error")}}autosize.update(t(u.wrapper).find(n.inputIdHashTagName))}).on("input",function(e){if("select"==u.current.input.type){var r=t(this).val(),i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?(u.wrapper.find(n.inputIdHashTagName).removeClass("error"),u.printAnswers(i,u.current.input.multiple)):u.wrapper.find(n.inputIdHashTagName).addClass("error")}else if(u.current.input.hasOwnProperty("pattern")){var a=new RegExp(u.current.input.pattern,"i");a.test(t(this).val())?u.wrapper.find(n.inputIdHashTagName).removeClass("error"):u.wrapper.find(n.inputIdHashTagName).addClass("error")}}),t(a).find("button.submit").click(function(e){var r=t(u.wrapper).find(n.inputIdHashTagName).val();if(e.preventDefault(),"select"!=u.current.input.type||u.current.input.multiple)if("select"==u.current.input.type&&u.current.input.multiple){if(u.current.input.required)return!1;if(""!=r.trim()&&r!=n.placeHolder){var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?-1==u.current.input.selected.indexOf(i[0].value)?(u.current.input.selected.push(i[0].value),u.wrapper.find(n.inputIdHashTagName).val("")):u.wrapper.find(n.inputIdHashTagName).val(""):u.wrapper.find(n.inputIdHashTagName).addClass("error")}else u.current.input.selected.length&&(t(this).removeClass("glow"),t(this).parent("form").submit())}else""==r.trim()||u.wrapper.find(n.inputIdHashTagName).hasClass("error")?t(u.wrapper).find(n.inputIdHashTagName).focus():t(this).parent("form").submit();else{if(u.current.input.required)return!1;r==n.placeHolder&&(r="");var i=u.current.input.answers.filter(function(t){return-1!=t.text.toLowerCase().indexOf(r.toLowerCase())});i.length?(u.current.input.selected=i[0],t(this).parent("form").submit()):u.wrapper.find(n.inputIdHashTagName).addClass("error")}autosize.update(t(u.wrapper).find(n.inputIdHashTagName))}),t(a).submit(function(e){e.preventDefault();var r=t(this).find(n.inputIdHashTagName).val();t(this).find(n.inputIdHashTagName).val(""),"select"==u.current.input.type?u.current.input.multiple?u.answerWith(u.current.input.selected.join(", "),u.current.input.selected):u.answerWith(u.current.input.selected.text,u.current.input.selected):u.answerWith(r,r)}),"function"==typeof autosize&&($textarea=t(u.wrapper).find(n.inputIdHashTagName),autosize($textarea)),u}return!1}}(jQuery); \ No newline at end of file diff --git a/index.html b/index.html index ae4150c..b03db6d 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@