';
if (htype == "1")
str = '
';
str += '';
str += '
';
for (var i in contents) {
str+= '';
}
str += '
';
if (footers.length > 0) {
str += '';
}
str += '
';
item = str;
}
var reload = false;
if (item.indexOf("[Payment Form]") >= 0) {
jQuery('.allioc-container .cell.example.example2').remove();
template = jQuery('#hidden-template').html();
item = item.replace("[Payment Form]", template);
//reload = true;
}
var innerHTML = "

" + item + "
";
if (allioc_script_vars.show_time) {
innerHTML += "
" + date.toLocaleTimeString() + "
";
}
innerHTML += "
";
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").append(innerHTML);
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").scrollTop(100000);
/*if (reload) {
resetForm();
reload = false;
}*////////////
});
} else {
text = allioc_script_vars.messages.internal_error;
var innerHTML = "

" + text + "
";
if (allioc_script_vars.show_time) {
innerHTML += "
" + date.toLocaleTimeString() + "
";
}
innerHTML += "
";
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").append(innerHTML);
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").scrollTop(100000);
}
}
/**
* Displays a image response
*
* @param imageUrl
* @param sequence
* @returns
*/
function imageResponse(imageUrl, sequence) {
if (imageUrl === "") {
textResponse(allioc_script_vars.messages.internal_error, sequence)
} else {
// FIXME wait for image to load by creating HTML first
var date = new Date();
var innerHTML = "
";
if (allioc_script_vars.show_time) {
innerHTML += "
" + date.toLocaleTimeString() + "
";
}
innerHTML += "
";
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").append(innerHTML);
}
}
/**
* Card response
*
* @param title
* @param subtitle
* @param buttons
* @param text
* @param postback
* @param sequence
*/
function cardResponse(title, subtitle, buttons, text, postback, sequence) {
var html = "
" + title + "
";
html += "
" + subtitle + "
";
// TODO
}
/**
* Quick replies response
*
* @param title
* @param replies
* @param sequence
*/
function quickRepliesResponse(title, replies, sequence) {
var html = "
" + title + "
";
var index = 0;
for (index; index
";
}
var date = new Date();
var innerHTML = "
" + html + "
";
if (allioc_script_vars.show_time) {
innerHTML += "
" + date.toLocaleTimeString() + "
";
}
innerHTML += "
";
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").append(innerHTML);
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area .allioc-is-active .allioc-quick-reply").click(function(event) {
event.preventDefault();
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area .allioc-conversation-request").removeClass("allioc-is-active");
var text = jQuery(this).val()
var date = new Date();
var innerHTML = "
" + escapeTextInput(text) + "
";
if (allioc_script_vars.show_time) {
innerHTML += "
" + date.toLocaleTimeString() + "
";
}
if (allioc_script_vars.show_loading) {
innerHTML += "
";
}
innerHTML += "
";
jQuery("#allioc-container-" + sequence + " .allioc-conversation-area").append(innerHTML);
textQuery(text, sequence);
});
}
/**
* Custom payload
*
* @param payload
*/
function customPayload(payload, sequence) {
}
var entityMap = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
'/': '/',
'`': '`',
'=': '='
};
/**
* Escapes HTML in text input
*/
function escapeTextInput(text) {
return String(text).replace(/[&<>"'`=\/]/g, function (s) {
return entityMap[s];
});
}
/*
var worker = new Worker(allioc_script_vars.worker_url);
//worker.start();
worker.addEventListener('message', function(e) {
var message = e.data;
if (message == "reload") {
window.location.reload();
}
});*/
jQuery(window).load(function(e) {
//jQuery('input.allioc-text').focus();
});
function chatreload() {
var container = jQuery(".allioc-content-overlay-container .allioc-container");
jQuery(container).find('.allioc-conversation-area').html('');
var containerId = jQuery(container).attr('id');
var parts = containerId.split("-");
var sequence = parts[2];
welcomeIntent(sequence);
//jQuery('input.allioc-text').focus();
}
var stripe;
function resetForm() {
stripe = Stripe(allioc_script_vars.stripe_pk);
var elements = stripe.elements({
fonts: [
{
cssSrc: 'https://fonts.googleapis.com/css?family=Source+Code+Pro',
},
],
// Stripe's examples are localized to specific languages, but if
// you wish to have Elements automatically detect your user's locale,
// use `locale: 'auto'` instead.
});
// Floating labels
var inputs = document.querySelectorAll('.cell.example.example2 .input');
Array.prototype.forEach.call(inputs, function(input) {
input.addEventListener('focus', function() {
input.classList.add('focused');
});
input.addEventListener('blur', function() {
input.classList.remove('focused');
});
input.addEventListener('keyup', function() {
if (input.value.length === 0) {
input.classList.add('empty');
} else {
input.classList.remove('empty');
}
});
});
var elementStyles = {
base: {
color: '#32325D',
fontWeight: 500,
fontFamily: 'Source Code Pro, Consolas, Menlo, monospace',
fontSize: '16px',
fontSmoothing: 'antialiased',
'::placeholder': {
color: '#CFD7DF',
},
':-webkit-autofill': {
color: '#e39f48',
},
},
invalid: {
color: '#E25950',
'::placeholder': {
color: '#FFCCA5',
},
},
};
var elementClasses = {
focus: 'focused',
empty: 'empty',
invalid: 'invalid',
};
var cardNumber = elements.create('cardNumber', {
style: elementStyles,
classes: elementClasses,
});
cardNumber.mount('#example2-card-number');
var cardExpiry = elements.create('cardExpiry', {
style: elementStyles,
classes: elementClasses,
});
cardExpiry.mount('#example2-card-expiry');
var cardCvc = elements.create('cardCvc', {
style: elementStyles,
classes: elementClasses,
});
cardCvc.mount('#example2-card-cvc');
registerElements([cardNumber, cardExpiry, cardCvc], 'example2');
}
function registerElements(elements, exampleName) {
var formClass = '.' + exampleName;
var example = document.querySelector(formClass);
var form = example.querySelector('form');
var error = form.querySelector('.error');
var errorMessage = error.querySelector('.message');
function enableInputs() {
Array.prototype.forEach.call(
form.querySelectorAll(
"input[type='text'], input[type='email'], input[type='tel']"
),
function(input) {
input.removeAttribute('disabled');
}
);
}
function disableInputs() {
Array.prototype.forEach.call(
form.querySelectorAll(
"input[type='text'], input[type='email'], input[type='tel']"
),
function(input) {
input.setAttribute('disabled', 'true');
}
);
}
function triggerBrowserValidation() {
// The only way to trigger HTML5 form validation UI is to fake a user submit
// event.
var submit = document.createElement('input');
submit.type = 'submit';
submit.style.display = 'none';
form.appendChild(submit);
submit.click();
submit.remove();
}
// Listen for errors from each Element, and show error messages in the UI.
var savedErrors = {};
elements.forEach(function(element, idx) {
element.on('change', function(event) {
if (event.error) {
error.classList.add('visible');
savedErrors[idx] = event.error.message;
errorMessage.innerText = event.error.message;
} else {
savedErrors[idx] = null;
// Loop over the saved errors and find the first one, if any.
var nextError = Object.keys(savedErrors)
.sort()
.reduce(function(maybeFoundError, key) {
return maybeFoundError || savedErrors[key];
}, null);
if (nextError) {
// Now that they've fixed the current error, show another one.
errorMessage.innerText = nextError;
} else {
// The user fixed the last error; no more errors.
error.classList.remove('visible');
}
}
});
});
// Listen on the form's 'submit' handler...
jQuery('.cell.example.example2').parent().parent().find('.card-el a').off('click').on('click', function(e) {
e.preventDefault();
var self = this;
// Trigger HTML5 validation UI on the form if any of the inputs fail
// validation.
var plainInputsValid = true;
Array.prototype.forEach.call(form.querySelectorAll('input'), function(
input
) {
if (input.checkValidity && !input.checkValidity()) {
plainInputsValid = false;
return;
}
});
if (!plainInputsValid) {
triggerBrowserValidation();
return;
}
// Show a loading screen...
example.classList.add('submitting');
// Disable all inputs.
disableInputs();
var zip = form.querySelector('#' + exampleName + '-zip');
var additionalData = {
address_zip: zip ? zip.value : undefined,
};
// Use Stripe.js to create a token. We only need to pass in one Element
// from the Element group in order to create a token. We can also pass
// in the additional customer data we collected in our form.
stripe.createToken(elements[0], additionalData).then(function(result) {
// Stop loading!
example.classList.remove('submitting');
if (result.token) {
// If we received a token, show the token ID.
gtoken = result.token.id;
var title = jQuery(self).attr('title');
if (title !== "") {
jQuery("input.allioc-text").val(title);
jQuery("#allioc-input-area .allioc-send-button").trigger('click');
}
} else {
// Otherwise, un-disable inputs.
enableInputs();
}
});
});
}