Files
SDL/data/software-Dateien/vera.js
2024-10-01 16:32:40 +02:00

324 lines
18 KiB
JavaScript

var Vera = (function(window, undefined) {
dataLayer = window.dataLayer || [];
var baseUrl = 'https://vera.wkooe.at';
var isFirstRequest = true;
var params = {};
var Vera = {};
Vera.isMobileOrTablet = function() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4))) check = true;})(navigator.userAgent||navigator.vendor||window.opera);
return check;
}
Vera.showMessage = function(text, isUserMessage, responseId) {
if (text === undefined || text == '') {
return false;
}
if (isUserMessage) {
text = '<p>' + text + '</p>';
}
var $messageElem = Vera.$('<div class="vera-chat-history-entry ' + (isUserMessage ? 'vera-chat-history-user-entry' : 'vera-chat-history-bot-entry') + '"><div class="vera-chat-history-entry-message">' + text + '</div></div>');
Vera.$('#vera-chat-history').append($messageElem);
var $chatBody = Vera.$('.vera-chat-body');
$chatBody.animate({ scrollTop: $chatBody.prop("scrollHeight") }, 700);
}
Vera.ask = function(message, displayMessage) {
Vera.showMessage((displayMessage === undefined ? message : displayMessage), true);
Vera.$.post(
baseUrl + '/api/talk',
{
message: message,
sessionId: sessionStorage.getItem('vera_session_id'),
channel: ('channel' in params ? params.channel : 0)
},
function(data) {
if (data.success != -1) {
var answer = '';
if (data.type == 'farewell' && data.farewell != undefined && data.farewell != '') {
answer = data.farewell;
} else {
answer += data.answers.join('<hr>');
}
if (data.sessionId != undefined && data.sessionId != '') {
sessionStorage.setItem('vera_session_id', data.sessionId);
}
setTimeout(function() {Vera.showMessage(answer, false, data.responseId);}, 500);
isFirstRequest = false;
if (data.auto != 'undefined' && data.auto != '') {
setTimeout(function() {Vera.ask(data.auto, '');}, 3000);
}
if (displayMessage !== '') {
dataLayer.push({
event: 'vera-search',
searchTerm: (displayMessage === undefined ? message : displayMessage),
searchResults: (data.type == 'no-answer' ? 0 : 1)
});
}
}
}
);
};
function loadScript(url, callback) {
var script = document.createElement('script');
script.async = true;
script.src = url;
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(script, entry);
script.onload = script.onreadystatechange = function() {
var rdyState = script.readyState;
if (!rdyState || /complete|loaded/.test(script.readyState)) {
callback();
script.onload = null;
script.onreadystatechange = null;
}
}
}
/**
* function to load stylesheets
* @param url
*/
function loadStylesheet(url) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = url;
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(link, entry);
}
/**
* function to check if css is already loaded
* @param callback
*/
function isCssReady(callback) {
var testElem = document.createElement('div');
testElem.id = 'vera-css-ready';
testElem.style = 'color: #ffffff';
var entry = document.getElementsByTagName('script')[0];
entry.parentNode.insertBefore(testElem, entry);
(function poll() {
var node = document.getElementById('vera-css-ready');
var value;
if (window.getComputedStyle) {
value = document.defaultView.getComputedStyle(testElem, null).getPropertyValue('color');
} else if (node.currentStyle) {
value = node.currentStyle.color;
}
if (value && value === 'rgb(186, 218, 85)' || value.toLocaleLowerCase() === '#bada55') {
callback();
node.parentNode.removeChild(node);
} else {
setTimeout(poll, 500);
}
})();
}
/**
* get src-URL of script, to extract paramter from URL
* @returns {string|null}
*/
function getScriptUrl() {
var scripts = document.getElementsByTagName('script');
var element;
var src;
for (var i=0; i<scripts.length; i++) {
element = scripts[i];
src = element.src;
if (src && /vera\.wkooe\.at\/embed\/js\/vera\.js/.test(src)) {
return src;
}
}
return null;
}
/**
* Extract parameters from url-query-path
* @param query
*/
function getQueryParams(query) {
var args = query.split('&');
var params = {};
var pair;
var key;
var value;
function decode(string) {
return decodeURIComponent(string || "").replace('+', ' ');
}
for (var i=0; i<args.length; i++) {
pair = args[i].split('=');
key = decode(pair[0]);
value = decode(pair[1]);
params[key] = value;
}
return params;
}
function loadSupportingFiles(callback) {
callback();
}
function getWidgetParams() {
var url = getScriptUrl();
var params = getQueryParams(url.replace(/^.*\?/, ''));
return params;
}
function getRatingData(params, callback) {
callback();
}
function initChat() {
Vera.$('#vera-launch-btn').click(function(e) {
e.preventDefault();
e.stopPropagation();
Vera.$(this).fadeOut(400, function() {
Vera.$('#vera-container').animate({"right":"0px"}, "slow", function(e) {
var chatStart = Vera.$('#vera-chat').data('chat-start');
if (isFirstRequest && typeof chatStart !== "undefined") {
Vera.ask('start:' + chatStart, '');
}
});
});
dataLayer.push({
event: 'vera-display'
});
});
Vera.$(document).on('click','#vera-container .select-topic', function(e) {
e.preventDefault();
e.stopPropagation();
var $btn = Vera.$(this);
var text = $btn.text();
var messageText = $btn.data('query');
Vera.ask(messageText, text);
});
Vera.$('#vera-chat-big-screen-btn').click(function(e) {
e.preventDefault();
e.stopPropagation();
Vera.$('#vera-container').addClass('vera-mode-fullscreen');
Vera.$('body').addClass('vera-overflow-hidden');
});
Vera.$('#vera-chat-small-screen-btn').click(function(e) {
e.preventDefault();
e.stopPropagation();
Vera.$('#vera-container').removeClass('vera-mode-fullscreen');
Vera.$('body').removeClass('vera-overflow-hidden');
});
Vera.$('#vera-chat-print-btn').click(function(e) {
e.preventDefault();
e.stopPropagation();
var veraChatContent = Vera.$('#vera-chat').html();
var iframePattern = '<iframe.+</iframe>';
var re = new RegExp(iframePattern, "g");
var veraChatContent = veraChatContent.replace(re, '');
var veraPrintWindow = window.open('', 'vera_print', 'height=400,width=600');
veraPrintWindow.document.write('<html><head><title>Vera - Fragen rund um den Coronavirus</title>');
veraPrintWindow.document.write('<style>body,html{font-family:Arial,sans-serif;font-size:10pt;margin:0}#vera-chat .vera-chat-controls{display:none}#vera-chat .vera-chat-header{background-color:#304c59;box-sizing:border-box;color:#fff;display:flex;position:relative}#vera-chat .vera-chat-header .vera-chat-title{font-weight:700;line-height:42px;margin-left:10px}#vera-chat .vera-chat-body{color:#777;padding:10px 0}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry{margin-top:10px;margin-bottom:10px;padding-bottom:10px}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message{border-radius:5px;font-size:10pt;line-height:1.5em;position:relative;padding:10px 0}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message p{margin:0}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message p a{color:#e20613}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message img{max-width:100%;height:auto}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message hr{margin:10px 0}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.hint,#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.warning{border-radius:5px;color:#777;display:block;padding:10px 10px 10px 45px;margin-bottom:10px}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.hint strong,#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.warning strong{font-weight:700!important}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.hint a,#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.warning a{color:#777;text-decoration:underline}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.hint{background:url(../img/icons/hint_icon.png) no-repeat 5px center #f8d534}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message span.warning{background:url(../img/icons/warning_icon.png) no-repeat 5px center #f8d534}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message .btn-primary{background:#fff;border:1px solid #e20613;border-radius:10px;box-shadow:none;color:#e20613;display:inline-block;font-weight:400;font-size:1em;line-height:1.2em;margin:5px 5px 0 0;outline:0;padding:4px;text-align:left;text-decoration:none;white-space:inherit}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message .btn-primary:hover{background:#e20613;color:#fff;cursor:pointer;text-decoration:none}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry .vera-chat-history-entry-message:after{content:"";position:absolute;top:50%;width:0;height:0;border:10px solid transparent;margin-top:-10px}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry.vera-chat-history-bot-entry .vera-chat-history-entry-message{background-color:#fff;color:#304c59;width:90%}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry.vera-chat-history-bot-entry .vera-chat-history-entry-message .vera-answer-list .btn.btn-primary{background-color:#fff;border:none;border-radius:0;color:#e20613;display:block;padding:5px 0 5px 18px;position:relative}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry.vera-chat-history-bot-entry .vera-chat-history-entry-message .vera-answer-list .btn.btn-primary:before{border:solid #e20613;border-width:0 3px 3px 0;content:"";display:inline-block;padding:3px;transform:rotate(-45deg);-webkit-transform:rotate(-45deg);position:absolute;left:0;top:8px}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry.vera-chat-history-bot-entry .vera-chat-history-entry-message .vera-answer-list :last-child{border:none!important}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry.vera-chat-history-user-entry{margin-left:10%}#vera-chat .vera-chat-body .vera-chat-history .vera-chat-history-entry.vera-chat-history-user-entry .vera-chat-history-entry-message{font-weight:700;color:#000;text-align:right}#vera-chat .vera-chat-footer{display:none}</style>');
veraPrintWindow.document.write('</head><body >');
veraPrintWindow.document.write('<div id="vera-chat">' + veraChatContent + '</div>');
veraPrintWindow.document.write('<hr><p>Alle Rechtsauskünfte werden von der WKO nach bestem Wissen und Gewissen erteilt und basieren auf den zum jeweiligen Zeitpunkt gesicherten Informationen. Die WKO übernimmt für die Richtigkeit der Auskünfte keine Haftung.</p>');
veraPrintWindow.document.write('</body></html>');
veraPrintWindow.document.close(); // necessary for IE >= 10
veraPrintWindow.focus(); // necessary for IE >= 10*/
if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
veraPrintWindow.print();
setTimeout(function(){veraPrintWindow.close();}, 1000);
} else {
veraPrintWindow.print();
veraPrintWindow.close();
}
})
Vera.$('#vera-chat-close-btn').click(function(e) {
e.preventDefault();
e.stopPropagation();
localStorage.setItem('vera_hide', 1);
var rightPosition = (-1 * (Vera.$('#vera-container').width())) + 'px';
if (Vera.$(window).width() >= 992) {
rightPosition = (-1 * (Vera.$('#vera-container').width() + 10)) + 'px';
}
Vera.$('#vera-container').removeClass('vera-mode-fullscreen');
Vera.$('body').removeClass('vera-overflow-hidden');
Vera.$('#vera-container').animate({"right":rightPosition}, "slow", function() {
Vera.$('#vera-launch-btn').fadeIn();
});
});
Vera.$('#vera-chat-form').submit(function(e) {
e.preventDefault();
e.stopPropagation();
var $message = Vera.$('#vera-chat-message');
Vera.ask($message.val());
$message.val('').focus();
});
if (Vera.$('#vera-chat').data('show-on-load') && localStorage.getItem('vera_hide') != 1 && !Vera.isMobileOrTablet()) {
Vera.$('#vera-launch-btn').trigger('click');
}
}
function drawWidget() {
var urlParams = Object.keys(params).map(function(k) {
return encodeURIComponent(k) + '=' + encodeURIComponent(params[k])
}).join('&');
// jQuery cross domain ajax
Vera.$.get(baseUrl + "/embed/?" + urlParams).done(function (data) {
Vera.$('body').append(Vera.$(data));
initChat();
});
}
loadSupportingFiles(function() {
params = getWidgetParams();
loadStylesheet(baseUrl + '/embed/css/fa.all.min.css');
loadStylesheet(baseUrl + '/embed/css/vera.css?d=4');
isCssReady(function() {
loadScript(baseUrl + '/embed/js/jquery-3.4.1.min.js', function() {
drawWidget(params);
});
});
});
return Vera;
})(window);