trabajo-afectivo/public/assets/chat/chat.js

1793 lines
56 KiB
JavaScript
Raw Normal View History

if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["agent"] = function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
if (this.agent.avatar) {
__out.push('\n<img class="zammad-chat-agent-avatar" src="');
__out.push(__sanitize(this.agent.avatar));
__out.push('">\n');
}
__out.push('\n<span class="zammad-chat-agent-sentence">\n <span class="zammad-chat-agent-name">');
__out.push(__sanitize(this.agent.name));
__out.push('</span>\n</span>');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
/*!
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <jevin9@gmail.com> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Jevin O. Sewaruth
* ----------------------------------------------------------------------------
*
* Autogrow Textarea Plugin Version v3.0
* http://www.technoreply.com/autogrow-textarea-plugin-3-0
*
* THIS PLUGIN IS DELIVERD ON A PAY WHAT YOU WHANT BASIS. IF THE PLUGIN WAS USEFUL TO YOU, PLEASE CONSIDER BUYING THE PLUGIN HERE :
* https://sites.fastspring.com/technoreply/instant/autogrowtextareaplugin
*
* Date: October 15, 2012
*
* Zammad modification: remove overflow:hidden when maximum height is reached
*
*/
jQuery.fn.autoGrow = function(options) {
return this.each(function() {
var settings = jQuery.extend({
extraLine: true,
}, options);
var createMirror = function(textarea) {
jQuery(textarea).after('<div class="autogrow-textarea-mirror"></div>');
return jQuery(textarea).next('.autogrow-textarea-mirror')[0];
}
var sendContentToMirror = function (textarea) {
mirror.innerHTML = String(textarea.value)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/ /g, '&nbsp;')
.replace(/\n/g, '<br />') +
(settings.extraLine? '.<br/>.' : '')
;
if (jQuery(textarea).height() != jQuery(mirror).height()) {
jQuery(textarea).height(jQuery(mirror).height());
var maxHeight = parseInt(jQuery(textarea).css('max-height'), 10);
var overflow = jQuery(mirror).height() > maxHeight ? '' : 'hidden'
jQuery(textarea).css('overflow', overflow);
}
}
var growTextarea = function () {
sendContentToMirror(this);
}
// Create a mirror
var mirror = createMirror(this);
// Style the mirror
mirror.style.display = 'none';
mirror.style.wordWrap = 'break-word';
mirror.style.whiteSpace = 'normal';
mirror.style.padding = jQuery(this).css('paddingTop') + ' ' +
jQuery(this).css('paddingRight') + ' ' +
jQuery(this).css('paddingBottom') + ' ' +
jQuery(this).css('paddingLeft');
mirror.style.width = jQuery(this).css('width');
mirror.style.fontFamily = jQuery(this).css('font-family');
mirror.style.fontSize = jQuery(this).css('font-size');
mirror.style.lineHeight = jQuery(this).css('line-height');
console.log(mirror.style.lineHeight);
// Style the textarea
this.style.overflow = "hidden";
this.style.minHeight = this.rows+"em";
// Bind the textarea's event
this.onkeyup = growTextarea;
// Fire the event for text already present
sendContentToMirror(this);
});
};
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
2015-12-05 19:41:14 +00:00
slice = [].slice,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
2015-10-15 09:26:56 +00:00
(function($, window) {
2015-12-05 19:41:14 +00:00
var Base, Io, Log, Timeout, ZammadChat, myScript, scriptHost, scripts;
scripts = document.getElementsByTagName('script');
myScript = scripts[scripts.length - 1];
2015-11-25 10:06:26 +00:00
scriptHost = myScript.src.match('.*://([^:/]*).*')[1];
2015-12-05 19:41:14 +00:00
Base = (function() {
Base.prototype.defaults = {
debug: false
};
function Base(options) {
this.options = $.extend({}, this.defaults, options);
this.log = new Log({
debug: this.options.debug,
logPrefix: this.options.logPrefix || this.logPrefix
});
}
return Base;
})();
Log = (function() {
Log.prototype.defaults = {
debug: false
};
function Log(options) {
this.log = bind(this.log, this);
this.error = bind(this.error, this);
this.notice = bind(this.notice, this);
this.debug = bind(this.debug, this);
this.options = $.extend({}, this.defaults, options);
}
Log.prototype.debug = function() {
var items;
items = 1 <= arguments.length ? slice.call(arguments, 0) : [];
2015-12-06 15:40:47 +00:00
if (!this.options.debug) {
2015-12-05 19:41:14 +00:00
return;
}
return this.log('debug', items);
};
Log.prototype.notice = function() {
var items;
items = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return this.log('notice', items);
};
Log.prototype.error = function() {
var items;
items = 1 <= arguments.length ? slice.call(arguments, 0) : [];
2015-12-06 15:40:47 +00:00
return this.log('error', items);
2015-12-05 19:41:14 +00:00
};
Log.prototype.log = function(level, items) {
var i, item, len, logString;
items.unshift('||');
items.unshift(level);
items.unshift(this.options.logPrefix);
console.log.apply(console, items);
if (!this.options.debug) {
return;
}
logString = '';
for (i = 0, len = items.length; i < len; i++) {
item = items[i];
logString += ' ';
if (typeof item === 'object') {
logString += JSON.stringify(item);
} else if (item && item.toString) {
logString += item.toString();
} else {
logString += item;
}
}
return $('.js-chatLogDisplay').prepend('<div>' + logString + '</div>');
};
return Log;
})();
Timeout = (function(superClass) {
extend(Timeout, superClass);
Timeout.prototype.timeoutStartedAt = null;
Timeout.prototype.logPrefix = 'timeout';
Timeout.prototype.defaults = {
debug: false,
timeout: 4,
timeoutIntervallCheck: 0.5
};
function Timeout(options) {
this.stop = bind(this.stop, this);
this.start = bind(this.start, this);
Timeout.__super__.constructor.call(this, options);
}
Timeout.prototype.start = function() {
var check, timeoutStartedAt;
this.stop();
timeoutStartedAt = new Date;
check = (function(_this) {
return function() {
var timeLeft;
timeLeft = new Date - new Date(timeoutStartedAt.getTime() + _this.options.timeout * 1000 * 60);
_this.log.debug("Timeout check for " + _this.options.timeout + " minutes (left " + (timeLeft / 1000) + " sec.)");
if (timeLeft < 0) {
return;
}
_this.stop();
return _this.options.callback();
};
})(this);
this.log.debug("Start timeout in " + this.options.timeout + " minutes");
return this.intervallId = setInterval(check, this.options.timeoutIntervallCheck * 1000 * 60);
};
Timeout.prototype.stop = function() {
if (!this.intervallId) {
return;
}
2015-12-08 11:32:19 +00:00
this.log.debug("Stop timeout of " + this.options.timeout + " minutes");
2015-12-05 19:41:14 +00:00
return clearInterval(this.intervallId);
};
return Timeout;
})(Base);
Io = (function(superClass) {
extend(Io, superClass);
Io.prototype.logPrefix = 'io';
function Io(options) {
this.ping = bind(this.ping, this);
2015-12-05 19:41:14 +00:00
this.send = bind(this.send, this);
this.reconnect = bind(this.reconnect, this);
this.close = bind(this.close, this);
this.connect = bind(this.connect, this);
this.set = bind(this.set, this);
Io.__super__.constructor.call(this, options);
}
Io.prototype.set = function(params) {
var key, results, value;
results = [];
for (key in params) {
value = params[key];
results.push(this.options[key] = value);
}
return results;
};
Io.prototype.connect = function() {
this.log.debug("Connecting to " + this.options.host);
this.ws = new window.WebSocket("" + this.options.host);
this.ws.onopen = (function(_this) {
return function(e) {
2015-12-08 11:32:19 +00:00
_this.log.debug('onOpen', e);
_this.options.onOpen(e);
return _this.ping();
2015-12-05 19:41:14 +00:00
};
})(this);
this.ws.onmessage = (function(_this) {
return function(e) {
var i, len, pipe, pipes;
2015-12-05 19:41:14 +00:00
pipes = JSON.parse(e.data);
2015-12-08 11:32:19 +00:00
_this.log.debug('onMessage', e.data);
for (i = 0, len = pipes.length; i < len; i++) {
pipe = pipes[i];
if (pipe.event === 'pong') {
_this.ping();
}
}
2015-12-05 19:41:14 +00:00
if (_this.options.onMessage) {
return _this.options.onMessage(pipes);
}
};
})(this);
this.ws.onclose = (function(_this) {
return function(e) {
2015-12-08 11:32:19 +00:00
_this.log.debug('close websocket connection', e);
if (_this.pingDelayId) {
clearTimeout(_this.pingDelayId);
}
2015-12-08 11:32:19 +00:00
if (_this.manualClose) {
_this.log.debug('manual close, onClose callback');
_this.manualClose = false;
if (_this.options.onClose) {
return _this.options.onClose(e);
}
} else {
_this.log.debug('error close, onError callback');
if (_this.options.onError) {
return _this.options.onError('Connection lost...');
}
2015-12-05 19:41:14 +00:00
}
};
})(this);
return this.ws.onerror = (function(_this) {
return function(e) {
2015-12-08 11:32:19 +00:00
_this.log.debug('onError', e);
2015-12-05 19:41:14 +00:00
if (_this.options.onError) {
return _this.options.onError(e);
}
};
})(this);
};
Io.prototype.close = function() {
2015-12-08 11:32:19 +00:00
this.log.debug('close websocket manually');
this.manualClose = true;
2015-12-05 19:41:14 +00:00
return this.ws.close();
};
Io.prototype.reconnect = function() {
2015-12-08 11:32:19 +00:00
this.log.debug('reconnect');
this.close();
2015-12-05 19:41:14 +00:00
return this.connect();
};
Io.prototype.send = function(event, data) {
var msg;
if (data == null) {
data = {};
}
this.log.debug('send', event, data);
msg = JSON.stringify({
event: event,
data: data
});
return this.ws.send(msg);
};
Io.prototype.ping = function() {
var localPing;
localPing = (function(_this) {
return function() {
return _this.send('ping');
};
})(this);
return this.pingDelayId = setTimeout(localPing, 29000);
};
2015-12-05 19:41:14 +00:00
return Io;
})(Base);
ZammadChat = (function(superClass) {
extend(ZammadChat, superClass);
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.defaults = {
chatId: void 0,
show: true,
target: $('body'),
host: '',
debug: false,
flat: false,
lang: void 0,
cssAutoload: true,
cssUrl: void 0,
2015-11-16 10:46:42 +00:00
fontSize: void 0,
buttonClass: 'open-zammad-chat',
inactiveClass: 'is-inactive',
2015-11-25 23:40:52 +00:00
title: '<strong>Chat</strong> with us!',
2015-12-08 11:32:19 +00:00
idleTimeout: 6,
2015-12-05 19:41:14 +00:00
idleTimeoutIntervallCheck: 0.5,
inactiveTimeout: 8,
inactiveTimeoutIntervallCheck: 0.5,
waitingListTimeout: 4,
waitingListTimeoutIntervallCheck: 0.5
2015-10-15 09:26:56 +00:00
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.logPrefix = 'chat';
ZammadChat.prototype._messageCount = 0;
2015-12-08 11:32:19 +00:00
ZammadChat.prototype.isOpen = false;
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.blinkOnlineInterval = null;
ZammadChat.prototype.stopBlinOnlineStateTimeout = null;
2016-01-05 12:46:43 +00:00
ZammadChat.prototype.showTimeEveryXMinutes = 2;
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.lastTimestamp = null;
ZammadChat.prototype.lastAddedType = null;
ZammadChat.prototype.inputTimeout = null;
ZammadChat.prototype.isTyping = false;
ZammadChat.prototype.state = 'offline';
2015-10-15 09:26:56 +00:00
2015-11-12 14:05:43 +00:00
ZammadChat.prototype.initialQueueDelay = 10000;
ZammadChat.prototype.translations = {
de: {
'<strong>Chat</strong> with us!': '<strong>Chatte</strong> mit uns!',
'Online': 'Online',
'Online': 'Online',
'Offline': 'Offline',
'Connecting': 'Verbinden',
'Connection re-established': 'Verbindung wiederhergestellt',
'Today': 'Heute',
'Send': 'Senden',
'Compose your message...': 'Ihre Nachricht...',
2016-01-05 12:46:43 +00:00
'All colleagues are busy.': 'Alle Kollegen sind belegt.',
'You are on waiting list position <strong>%s</strong>.': 'Sie sind in der Warteliste an der Position <strong>%s</strong>.',
'Start new conversation': 'Neue Konversation starten',
2015-11-25 23:40:52 +00:00
'Since you didn\'t respond in the last %s minutes your conversation with <strong>%s</strong> got closed.': 'Da Sie in den letzten %s Minuten nichts geschrieben haben wurde Ihre Konversation mit <strong>%s</strong> geschlossen.',
'Since you didn\'t respond in the last %s minutes your conversation got closed.': 'Da Sie in den letzten %s Minuten nichts geschrieben haben wurde Ihre Konversation geschlossen.'
}
};
2015-11-12 10:44:37 +00:00
ZammadChat.prototype.sessionId = void 0;
ZammadChat.prototype.T = function() {
var i, item, items, len, string, translations;
string = arguments[0], items = 2 <= arguments.length ? slice.call(arguments, 1) : [];
if (this.options.lang && this.options.lang !== 'en') {
if (!this.translations[this.options.lang]) {
2015-12-05 19:41:14 +00:00
this.log.notice("Translation '" + this.options.lang + "' needed!");
} else {
translations = this.translations[this.options.lang];
if (!translations[string]) {
2015-12-05 19:41:14 +00:00
this.log.notice("Translation needed for '" + string + "'");
}
string = translations[string] || string;
}
}
if (items) {
for (i = 0, len = items.length; i < len; i++) {
item = items[i];
string = string.replace(/%s/, item);
}
}
return string;
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.view = function(name) {
return (function(_this) {
return function(options) {
if (!options) {
options = {};
}
options.T = _this.T;
options.background = _this.options.background;
options.flat = _this.options.flat;
2015-11-16 10:46:42 +00:00
options.fontSize = _this.options.fontSize;
return window.zammadChatTemplates[name](options);
};
})(this);
2015-10-15 09:26:56 +00:00
};
function ZammadChat(options) {
2015-12-05 19:41:14 +00:00
this.startTimeoutObservers = bind(this.startTimeoutObservers, this);
2015-10-15 09:26:56 +00:00
this.setAgentOnlineState = bind(this.setAgentOnlineState, this);
this.onConnectionEstablished = bind(this.onConnectionEstablished, this);
2015-11-12 14:05:43 +00:00
this.setSessionId = bind(this.setSessionId, this);
2015-10-15 09:26:56 +00:00
this.onConnectionReestablished = bind(this.onConnectionReestablished, this);
this.reconnect = bind(this.reconnect, this);
2015-12-05 19:41:14 +00:00
this.destroy = bind(this.destroy, this);
this.onLeaveTemporary = bind(this.onLeaveTemporary, this);
2015-10-15 09:26:56 +00:00
this.onAgentTypingEnd = bind(this.onAgentTypingEnd, this);
this.onAgentTypingStart = bind(this.onAgentTypingStart, this);
this.onQueue = bind(this.onQueue, this);
2015-11-12 14:05:43 +00:00
this.onQueueScreen = bind(this.onQueueScreen, this);
2015-12-08 11:32:19 +00:00
this.onWebSocketClose = bind(this.onWebSocketClose, this);
2015-10-15 09:26:56 +00:00
this.onCloseAnimationEnd = bind(this.onCloseAnimationEnd, this);
2015-11-11 10:44:10 +00:00
this.close = bind(this.close, this);
2015-12-08 11:32:19 +00:00
this.sessionClose = bind(this.sessionClose, this);
2015-11-25 23:40:52 +00:00
this.onOpenAnimationEnd = bind(this.onOpenAnimationEnd, this);
2015-11-11 10:44:10 +00:00
this.open = bind(this.open, this);
2015-11-12 14:05:43 +00:00
this.renderMessage = bind(this.renderMessage, this);
2015-10-15 09:26:56 +00:00
this.receiveMessage = bind(this.receiveMessage, this);
this.onSubmit = bind(this.onSubmit, this);
this.onInput = bind(this.onInput, this);
2015-12-08 11:32:19 +00:00
this.onReopenSession = bind(this.onReopenSession, this);
this.onError = bind(this.onError, this);
this.onWebSocketMessage = bind(this.onWebSocketMessage, this);
this.send = bind(this.send, this);
2015-10-15 09:26:56 +00:00
this.checkForEnter = bind(this.checkForEnter, this);
2015-12-05 19:41:14 +00:00
this.render = bind(this.render, this);
this.view = bind(this.view, this);
this.T = bind(this.T, this);
this.options = $.extend({}, this.defaults, options);
2015-12-05 19:41:14 +00:00
ZammadChat.__super__.constructor.call(this, this.options);
2015-11-25 23:40:52 +00:00
if (!$) {
this.state = 'unsupported';
2015-12-05 19:41:14 +00:00
this.log.notice('Chat: no jquery found!');
2015-11-25 23:40:52 +00:00
return;
}
if (!window.WebSocket || !sessionStorage) {
this.state = 'unsupported';
2015-12-05 19:41:14 +00:00
this.log.notice('Chat: Browser not supported!');
return;
}
if (!this.options.chatId) {
2015-11-25 10:06:26 +00:00
this.state = 'unsupported';
2015-12-05 19:41:14 +00:00
this.log.error('Chat: need chatId as option!');
2015-11-25 10:06:26 +00:00
return;
}
if (!this.options.lang) {
this.options.lang = $('html').attr('lang');
}
if (this.options.lang) {
this.options.lang = this.options.lang.replace(/-.+?$/, '');
2015-12-05 19:41:14 +00:00
this.log.debug("lang: " + this.options.lang);
}
if (!this.options.host) {
this.detectHost();
}
2015-12-05 19:41:14 +00:00
this.loadCss();
this.io = new Io(this.options);
this.io.set({
onOpen: this.render,
2015-12-08 11:32:19 +00:00
onClose: this.onWebSocketClose,
onMessage: this.onWebSocketMessage,
onError: this.onError
2015-12-05 19:41:14 +00:00
});
this.io.connect();
}
ZammadChat.prototype.render = function() {
2015-12-08 11:32:19 +00:00
if (!this.el || !$('.zammad-chat').get(0)) {
this.el = $(this.view('chat')({
title: this.options.title
}));
this.options.target.append(this.el);
this.input = this.el.find('.zammad-chat-input');
this.el.find('.js-chat-open').click(this.open);
this.el.find('.js-chat-close').click(this.close);
this.el.find('.zammad-chat-controls').on('submit', this.onSubmit);
this.input.on({
keydown: this.checkForEnter,
input: this.onInput
});
$(window).on('beforeunload', (function(_this) {
return function() {
return _this.onLeaveTemporary();
};
})(this));
$(window).bind('hashchange', (function(_this) {
return function() {
if (_this.isOpen) {
return;
}
return _this.idleTimeout.start();
};
})(this));
}
$("." + this.options.buttonClass).addClass(this.inactiveClass);
2015-12-05 19:41:14 +00:00
this.setAgentOnlineState('online');
this.log.debug('widget rendered');
this.startTimeoutObservers();
this.idleTimeout.start();
this.sessionId = sessionStorage.getItem('sessionId');
return this.send('chat_status_customer', {
session_id: this.sessionId
});
};
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.checkForEnter = function(event) {
if (!event.shiftKey && event.keyCode === 13) {
event.preventDefault();
return this.sendMessage();
}
};
2015-11-10 14:01:04 +00:00
ZammadChat.prototype.send = function(event, data) {
2015-11-25 10:06:26 +00:00
if (data == null) {
data = {};
}
data.chat_id = this.options.chatId;
2015-12-05 19:41:14 +00:00
return this.io.send(event, data);
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.onWebSocketMessage = function(pipes) {
var i, len, pipe;
2015-11-10 14:01:04 +00:00
for (i = 0, len = pipes.length; i < len; i++) {
pipe = pipes[i];
2015-12-05 19:41:14 +00:00
this.log.debug('ws:onmessage', pipe);
2015-11-10 14:01:04 +00:00
switch (pipe.event) {
2015-11-25 10:06:26 +00:00
case 'chat_error':
2015-12-05 19:41:14 +00:00
this.log.notice(pipe.data);
2015-11-25 23:40:52 +00:00
if (pipe.data && pipe.data.state === 'chat_disabled') {
2015-12-05 19:41:14 +00:00
this.destroy({
2015-12-08 11:32:19 +00:00
remove: true
2015-12-05 19:41:14 +00:00
});
2015-11-25 23:40:52 +00:00
}
2015-11-25 10:06:26 +00:00
break;
2015-11-10 14:01:04 +00:00
case 'chat_session_message':
if (pipe.data.self_written) {
return;
}
this.receiveMessage(pipe.data);
break;
case 'chat_session_typing':
if (pipe.data.self_written) {
return;
}
this.onAgentTypingStart();
break;
case 'chat_session_start':
2015-11-12 14:05:43 +00:00
this.onConnectionEstablished(pipe.data);
2015-11-10 14:01:04 +00:00
break;
2015-11-12 10:44:37 +00:00
case 'chat_session_queue':
this.onQueueScreen(pipe.data);
2015-11-10 14:01:04 +00:00
break;
case 'chat_session_closed':
this.onSessionClosed(pipe.data);
break;
case 'chat_session_left':
this.onSessionClosed(pipe.data);
break;
case 'chat_status_customer':
2015-11-10 14:01:04 +00:00
switch (pipe.data.state) {
case 'online':
this.sessionId = void 0;
2015-11-10 14:01:04 +00:00
this.onReady();
break;
case 'offline':
this.onError('Zammad Chat: No agent online');
2015-11-10 14:01:04 +00:00
break;
case 'chat_disabled':
this.onError('Zammad Chat: Chat is disabled');
2015-11-10 14:01:04 +00:00
break;
case 'no_seats_available':
2015-11-25 10:06:26 +00:00
this.onError("Zammad Chat: Too many clients in queue. Clients in queue: " + pipe.data.queue);
break;
case 'reconnect':
2015-12-08 11:32:19 +00:00
this.onReopenSession(pipe.data);
2015-11-10 14:01:04 +00:00
}
}
}
};
ZammadChat.prototype.onReady = function() {
2015-12-05 19:41:14 +00:00
this.log.debug('widget ready for use');
$("." + this.options.buttonClass).click(this.open).removeClass(this.inactiveClass);
if (this.options.show) {
2015-11-12 14:05:43 +00:00
return this.show();
}
};
ZammadChat.prototype.onError = function(message) {
2015-12-05 19:41:14 +00:00
this.log.debug(message);
2015-12-08 11:32:19 +00:00
this.addStatus(message);
$("." + this.options.buttonClass).hide();
if (this.isOpen) {
this.disableInput();
return this.destroy({
remove: false
});
} else {
return this.destroy({
remove: true
});
}
};
2015-12-08 11:32:19 +00:00
ZammadChat.prototype.onReopenSession = function(data) {
var i, len, message, ref, unfinishedMessage;
2015-12-08 11:32:19 +00:00
this.log.debug('old messages', data.session);
2015-12-05 19:41:14 +00:00
this.inactiveTimeout.start();
2015-11-12 14:05:43 +00:00
unfinishedMessage = sessionStorage.getItem('unfinished_message');
if (data.agent) {
this.onConnectionEstablished(data);
ref = data.session;
for (i = 0, len = ref.length; i < len; i++) {
message = ref[i];
this.renderMessage({
message: message.content,
id: message.id,
from: message.created_by_id ? 'agent' : 'customer'
});
}
if (unfinishedMessage) {
this.input.val(unfinishedMessage);
}
}
if (data.position) {
this.onQueue(data);
2015-11-12 14:05:43 +00:00
}
this.show();
this.open();
this.scrollToBottom();
2015-11-12 14:05:43 +00:00
if (unfinishedMessage) {
return this.input.focus();
}
};
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.onInput = function() {
this.el.find('.zammad-chat-message--unread').removeClass('zammad-chat-message--unread');
2015-11-12 14:05:43 +00:00
sessionStorage.setItem('unfinished_message', this.input.val());
2015-11-25 15:15:59 +00:00
return this.onTyping();
2015-10-15 09:26:56 +00:00
};
2015-11-25 15:15:59 +00:00
ZammadChat.prototype.onTyping = function() {
if (this.isTyping && this.isTyping > new Date(new Date().getTime() - 1500)) {
return;
2015-11-10 14:01:04 +00:00
}
2015-11-25 15:15:59 +00:00
this.isTyping = new Date();
2015-11-25 23:40:52 +00:00
this.send('chat_session_typing', {
2015-11-25 15:15:59 +00:00
session_id: this.sessionId
});
2015-12-05 19:41:14 +00:00
return this.inactiveTimeout.start();
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.onSubmit = function(event) {
event.preventDefault();
return this.sendMessage();
};
ZammadChat.prototype.sendMessage = function() {
var message, messageElement;
2015-11-12 14:05:43 +00:00
message = this.input.val();
if (!message) {
return;
}
2015-12-05 19:41:14 +00:00
this.inactiveTimeout.start();
2015-11-12 14:05:43 +00:00
sessionStorage.removeItem('unfinished_message');
messageElement = this.view('message')({
message: message,
from: 'customer',
2015-11-26 09:52:10 +00:00
id: this._messageCount++,
unreadClass: ''
});
this.maybeAddTimestamp();
if (this.el.find('.zammad-chat-message--typing').size()) {
this.lastAddedType = 'typing-placeholder';
this.el.find('.zammad-chat-message--typing').before(messageElement);
} else {
this.lastAddedType = 'message--customer';
this.el.find('.zammad-chat-body').append(messageElement);
2015-10-15 09:26:56 +00:00
}
2015-11-12 14:05:43 +00:00
this.input.val('');
this.scrollToBottom();
2015-11-10 14:01:04 +00:00
return this.send('chat_session_message', {
content: message,
id: this._messageCount,
2015-11-12 10:44:37 +00:00
session_id: this.sessionId
});
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.receiveMessage = function(data) {
2015-12-05 19:41:14 +00:00
this.inactiveTimeout.start();
2015-10-15 09:26:56 +00:00
this.onAgentTypingEnd();
this.maybeAddTimestamp();
2015-11-12 14:05:43 +00:00
return this.renderMessage({
2015-11-10 14:01:04 +00:00
message: data.message.content,
id: data.id,
2015-10-15 09:26:56 +00:00
from: 'agent'
2015-11-12 14:05:43 +00:00
});
};
ZammadChat.prototype.renderMessage = function(data) {
this.lastAddedType = "message--" + data.from;
2015-11-26 09:52:10 +00:00
data.unreadClass = document.hidden ? ' zammad-chat-message--unread' : '';
2015-11-12 14:05:43 +00:00
this.el.find('.zammad-chat-body').append(this.view('message')(data));
2015-10-15 09:26:56 +00:00
return this.scrollToBottom();
};
ZammadChat.prototype.open = function() {
2015-10-15 09:26:56 +00:00
if (this.isOpen) {
2015-12-08 11:32:19 +00:00
this.log.debug('widget already open, block');
return;
2015-10-15 09:26:56 +00:00
}
2015-12-08 11:32:19 +00:00
this.isOpen = true;
this.log.debug('open widget');
if (!this.sessionId) {
2015-11-12 14:05:43 +00:00
this.showLoader();
}
2015-11-25 13:47:02 +00:00
this.el.addClass('zammad-chat-is-open');
if (!this.sessionId) {
2015-11-12 14:05:43 +00:00
this.el.animate({
bottom: 0
}, 500, this.onOpenAnimationEnd);
2015-12-08 11:32:19 +00:00
return this.send('chat_session_init');
2015-11-12 14:05:43 +00:00
} else {
this.el.css('bottom', 0);
2015-12-08 11:32:19 +00:00
return this.onOpenAnimationEnd();
}
2015-10-15 09:26:56 +00:00
};
2015-11-25 23:40:52 +00:00
ZammadChat.prototype.onOpenAnimationEnd = function() {
2015-12-05 19:41:14 +00:00
return this.idleTimeout.stop();
2015-11-25 23:40:52 +00:00
};
2015-12-08 11:32:19 +00:00
ZammadChat.prototype.sessionClose = function() {
2015-11-25 23:40:52 +00:00
this.send('chat_session_close', {
session_id: this.sessionId
});
2015-12-05 19:41:14 +00:00
this.inactiveTimeout.stop();
this.waitingListTimeout.stop();
2015-11-25 23:40:52 +00:00
sessionStorage.removeItem('unfinished_message');
if (this.onInitialQueueDelayId) {
clearTimeout(this.onInitialQueueDelayId);
}
2015-11-25 23:40:52 +00:00
return this.setSessionId(void 0);
2015-11-12 14:05:43 +00:00
};
2015-12-08 11:32:19 +00:00
ZammadChat.prototype.close = function(event) {
2015-11-12 14:05:43 +00:00
var remainerHeight;
2015-12-08 11:32:19 +00:00
if (!this.isOpen) {
this.log.debug('can\'t close widget, it\'s not open');
return;
}
if (!this.sessionId) {
this.log.debug('can\'t close widget without sessionId');
return;
}
this.log.debug('close widget');
if (event) {
event.stopPropagation();
}
this.sessionClose();
2015-11-25 13:47:02 +00:00
this.el.removeClass('zammad-chat-is-open');
2015-10-15 09:26:56 +00:00
remainerHeight = this.el.height() - this.el.find('.zammad-chat-header').outerHeight();
return this.el.animate({
bottom: -remainerHeight
2015-10-15 13:28:30 +00:00
}, 500, this.onCloseAnimationEnd);
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.onCloseAnimationEnd = function() {
this.el.removeClass('zammad-chat-is-visible');
2015-12-05 19:41:14 +00:00
this.showLoader();
this.el.find('.zammad-chat-welcome').removeClass('zammad-chat-is-hidden');
this.el.find('.zammad-chat-agent').addClass('zammad-chat-is-hidden');
this.el.find('.zammad-chat-agent-status').addClass('zammad-chat-is-hidden');
this.isOpen = false;
2015-12-05 19:41:14 +00:00
return this.io.reconnect();
2015-10-15 09:26:56 +00:00
};
2015-12-08 11:32:19 +00:00
ZammadChat.prototype.onWebSocketClose = function() {
if (this.isOpen) {
return;
}
2015-12-05 19:41:14 +00:00
if (this.el) {
return this.el.removeClass('zammad-chat-is-shown');
}
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.show = function() {
var remainerHeight;
2015-12-08 11:32:19 +00:00
if (this.state === 'offline') {
return;
}
2015-11-25 13:47:02 +00:00
this.el.addClass('zammad-chat-is-shown');
if (!this.inputInitialized) {
this.inputInitialized = true;
this.input.autoGrow({
extraLine: false
});
}
remainerHeight = this.el.height() - this.el.find('.zammad-chat-header').outerHeight();
return this.el.css('bottom', -remainerHeight);
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.disableInput = function() {
2015-11-12 14:05:43 +00:00
this.input.prop('disabled', true);
return this.el.find('.zammad-chat-send').prop('disabled', true);
};
ZammadChat.prototype.enableInput = function() {
2015-11-12 14:05:43 +00:00
this.input.prop('disabled', false);
return this.el.find('.zammad-chat-send').prop('disabled', false);
};
2015-11-12 14:05:43 +00:00
ZammadChat.prototype.onQueueScreen = function(data) {
var show;
this.setSessionId(data.session_id);
2015-11-12 14:05:43 +00:00
show = (function(_this) {
return function() {
2015-12-05 19:41:14 +00:00
_this.onQueue(data);
return _this.waitingListTimeout.start();
2015-11-12 14:05:43 +00:00
};
})(this);
if (this.initialQueueDelay && !this.onInitialQueueDelayId) {
this.onInitialQueueDelayId = setTimeout(show, this.initialQueueDelay);
return;
}
if (this.onInitialQueueDelayId) {
clearTimeout(this.onInitialQueueDelayId);
}
return show();
};
ZammadChat.prototype.onQueue = function(data) {
2015-12-05 19:41:14 +00:00
this.log.notice('onQueue', data.position);
this.inQueue = true;
return this.el.find('.zammad-chat-body').html(this.view('waiting')({
2015-11-12 14:05:43 +00:00
position: data.position
}));
};
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.onAgentTypingStart = function() {
if (this.stopTypingId) {
clearTimeout(this.stopTypingId);
}
this.stopTypingId = setTimeout(this.onAgentTypingEnd, 3000);
2015-10-15 09:26:56 +00:00
if (this.el.find('.zammad-chat-message--typing').size()) {
return;
}
this.maybeAddTimestamp();
this.el.find('.zammad-chat-body').append(this.view('typingIndicator')());
return this.scrollToBottom();
};
ZammadChat.prototype.onAgentTypingEnd = function() {
return this.el.find('.zammad-chat-message--typing').remove();
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.onLeaveTemporary = function() {
if (!this.sessionId) {
return;
}
return this.send('chat_session_leave_temporary', {
session_id: this.sessionId
});
};
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.maybeAddTimestamp = function() {
var label, time, timestamp;
timestamp = Date.now();
if (!this.lastTimestamp || (timestamp - this.lastTimestamp) > this.showTimeEveryXMinutes * 60000) {
label = this.T('Today');
time = new Date().toTimeString().substr(0, 5);
if (this.lastAddedType === 'timestamp') {
this.updateLastTimestamp(label, time);
return this.lastTimestamp = timestamp;
} else {
this.el.find('.zammad-chat-body').append(this.view('timestamp')({
label: label,
time: time
}));
2015-10-15 09:26:56 +00:00
this.lastTimestamp = timestamp;
this.lastAddedType = 'timestamp';
return this.scrollToBottom();
2015-10-15 09:26:56 +00:00
}
}
};
ZammadChat.prototype.updateLastTimestamp = function(label, time) {
2015-12-08 11:32:19 +00:00
if (!this.el) {
return;
}
return this.el.find('.zammad-chat-body').find('.zammad-chat-timestamp').last().replaceWith(this.view('timestamp')({
2015-10-15 09:26:56 +00:00
label: label,
time: time
}));
};
ZammadChat.prototype.addStatus = function(status) {
2015-12-08 11:32:19 +00:00
if (!this.el) {
return;
}
this.maybeAddTimestamp();
this.el.find('.zammad-chat-body').append(this.view('status')({
status: status
2015-10-15 09:26:56 +00:00
}));
return this.scrollToBottom();
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.scrollToBottom = function() {
return this.el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'));
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.destroy = function(params) {
if (params == null) {
params = {};
}
2015-12-08 11:32:19 +00:00
this.log.debug('destroy widget', params);
this.setAgentOnlineState('offline');
if (params.remove && this.el) {
this.el.remove();
2015-12-05 19:41:14 +00:00
}
2015-12-08 11:32:19 +00:00
if (this.waitingListTimeout) {
this.waitingListTimeout.stop();
}
2015-12-08 11:32:19 +00:00
if (this.inactiveTimeout) {
this.inactiveTimeout.stop();
2015-12-05 19:41:14 +00:00
}
2015-12-08 11:32:19 +00:00
if (this.idleTimeout) {
this.idleTimeout.stop();
}
return this.io.close();
2015-11-12 14:05:43 +00:00
};
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.reconnect = function() {
2015-12-05 19:41:14 +00:00
this.log.notice('reconnecting');
this.disableInput();
2015-10-15 09:26:56 +00:00
this.lastAddedType = 'status';
this.setAgentOnlineState('connecting');
2015-12-05 19:41:14 +00:00
return this.addStatus(this.T('Connection lost'));
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.onConnectionReestablished = function() {
this.lastAddedType = 'status';
this.setAgentOnlineState('online');
2015-10-15 09:26:56 +00:00
return this.addStatus(this.T('Connection re-established'));
};
ZammadChat.prototype.onSessionClosed = function(data) {
this.addStatus(this.T('Chat closed by %s', data.realname));
2015-11-25 10:06:26 +00:00
this.disableInput();
2015-11-25 23:40:52 +00:00
this.setAgentOnlineState('offline');
2015-12-05 19:41:14 +00:00
return this.inactiveTimeout.stop();
2015-10-15 09:26:56 +00:00
};
2015-11-12 14:05:43 +00:00
ZammadChat.prototype.setSessionId = function(id) {
this.sessionId = id;
if (id === void 0) {
return sessionStorage.removeItem('sessionId');
} else {
return sessionStorage.setItem('sessionId', id);
}
2015-11-12 14:05:43 +00:00
};
ZammadChat.prototype.onConnectionEstablished = function(data) {
if (this.onInitialQueueDelayId) {
clearTimeout(this.onInitialQueueDelayId);
}
this.inQueue = false;
if (data.agent) {
this.agent = data.agent;
}
if (data.session_id) {
this.setSessionId(data.session_id);
}
this.el.find('.zammad-chat-agent').html(this.view('agent')({
2015-11-12 14:05:43 +00:00
agent: this.agent
}));
this.enableInput();
this.el.find('.zammad-chat-body').empty();
2015-10-15 09:26:56 +00:00
this.el.find('.zammad-chat-welcome').addClass('zammad-chat-is-hidden');
this.el.find('.zammad-chat-agent').removeClass('zammad-chat-is-hidden');
this.el.find('.zammad-chat-agent-status').removeClass('zammad-chat-is-hidden');
2015-11-25 10:06:26 +00:00
this.input.focus();
2015-12-05 19:41:14 +00:00
this.setAgentOnlineState('online');
this.waitingListTimeout.stop();
this.idleTimeout.stop();
return this.inactiveTimeout.start();
2015-10-15 09:26:56 +00:00
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.showCustomerTimeout = function() {
2015-11-25 23:40:52 +00:00
var reload;
2015-12-05 19:41:14 +00:00
this.el.find('.zammad-chat-body').html(this.view('customer_timeout')({
agent: this.agent.name,
2015-11-25 23:40:52 +00:00
delay: this.options.inactiveTimeout
}));
2015-11-25 23:40:52 +00:00
reload = function() {
return location.reload();
};
2015-12-08 11:32:19 +00:00
this.el.find('.js-restart').click(reload);
return this.sessionClose();
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.showWaitingListTimeout = function() {
var reload;
this.el.find('.zammad-chat-body').html(this.view('waiting_list_timeout')({
delay: this.options.watingListTimeout
}));
reload = function() {
return location.reload();
};
2015-12-08 11:32:19 +00:00
this.el.find('.js-restart').click(reload);
return this.sessionClose();
2015-12-05 19:41:14 +00:00
};
ZammadChat.prototype.showLoader = function() {
return this.el.find('.zammad-chat-body').html(this.view('loader')());
};
2015-10-15 09:26:56 +00:00
ZammadChat.prototype.setAgentOnlineState = function(state) {
var capitalizedState;
this.state = state;
2015-12-08 11:32:19 +00:00
if (!this.el) {
return;
}
capitalizedState = state.charAt(0).toUpperCase() + state.slice(1);
return this.el.find('.zammad-chat-agent-status').attr('data-status', state).text(this.T(capitalizedState));
2015-10-15 09:26:56 +00:00
};
ZammadChat.prototype.detectHost = function() {
var protocol;
protocol = 'ws://';
if (window.location.protocol === 'https:') {
protocol = 'wss://';
}
return this.options.host = "" + protocol + scriptHost + "/ws";
};
ZammadChat.prototype.loadCss = function() {
var newSS, styles, url;
if (!this.options.cssAutoload) {
return;
}
url = this.options.cssUrl;
if (!url) {
url = this.options.host.replace(/^wss/i, 'https').replace(/^ws/i, 'http').replace(/\/ws/i, '');
url += '/assets/chat/chat.css';
}
2015-12-05 19:41:14 +00:00
this.log.debug("load css from '" + url + "'");
styles = "@import url('" + url + "');";
newSS = document.createElement('link');
newSS.rel = 'stylesheet';
newSS.href = 'data:text/css,' + escape(styles);
return document.getElementsByTagName('head')[0].appendChild(newSS);
};
2015-12-05 19:41:14 +00:00
ZammadChat.prototype.startTimeoutObservers = function() {
this.idleTimeout = new Timeout({
logPrefix: 'idleTimeout',
debug: this.options.debug,
timeout: this.options.idleTimeout,
timeoutIntervallCheck: this.options.idleTimeoutIntervallCheck,
callback: (function(_this) {
return function() {
_this.log.debug('Idle timeout reached, hide widget', new Date);
return _this.destroy({
2015-12-08 11:32:19 +00:00
remove: true
2015-12-05 19:41:14 +00:00
});
};
})(this)
});
this.inactiveTimeout = new Timeout({
logPrefix: 'inactiveTimeout',
debug: this.options.debug,
timeout: this.options.inactiveTimeout,
timeoutIntervallCheck: this.options.inactiveTimeoutIntervallCheck,
callback: (function(_this) {
return function() {
_this.log.debug('Inactive timeout reached, show timeout screen.', new Date);
_this.showCustomerTimeout();
return _this.destroy({
2015-12-08 11:32:19 +00:00
remove: false
2015-12-05 19:41:14 +00:00
});
};
})(this)
});
return this.waitingListTimeout = new Timeout({
logPrefix: 'waitingListTimeout',
debug: this.options.debug,
timeout: this.options.waitingListTimeout,
timeoutIntervallCheck: this.options.waitingListTimeoutIntervallCheck,
callback: (function(_this) {
return function() {
_this.log.debug('Waiting list timeout reached, show timeout screen.', new Date);
_this.showWaitingListTimeout();
return _this.destroy({
2015-12-08 11:32:19 +00:00
remove: false
2015-12-05 19:41:14 +00:00
});
};
})(this)
});
2015-11-25 23:40:52 +00:00
};
2015-10-15 09:26:56 +00:00
return ZammadChat;
2015-12-05 19:41:14 +00:00
})(Base);
return window.ZammadChat = ZammadChat;
2015-10-15 09:26:56 +00:00
})(window.jQuery, window);
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["chat"] = function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
__out.push('<div class="zammad-chat');
if (this.flat) {
__out.push(__sanitize(' zammad-chat--flat'));
}
2015-11-16 10:46:42 +00:00
__out.push('"');
2015-11-16 10:46:42 +00:00
if (this.fontSize) {
2015-11-16 13:39:39 +00:00
__out.push(__sanitize(" style='font-size: " + this.fontSize + "'"));
2015-11-16 10:46:42 +00:00
}
2015-11-16 10:46:42 +00:00
__out.push('>\n <div class="zammad-chat-header js-chat-open"');
if (this.background) {
__out.push(__sanitize(" style='background: " + this.background + "'"));
}
__out.push('>\n <div class="zammad-chat-header-controls">\n <span class="zammad-chat-agent-status zammad-chat-is-hidden" data-status="online"></span>\n <span class="zammad-chat-header-icon">\n <svg class="zammad-chat-header-icon-open" viewBox="0 0 13 7"><path d="M10.807 7l1.4-1.428-5-4.9L6.5-.02l-.7.7-4.9 4.9 1.414 1.413L6.5 2.886 10.807 7z" fill-rule="evenodd"/></svg>\n <svg class="zammad-chat-header-icon-close js-chat-close" viewBox="0 0 13 13"><path d="m2.241.12l-2.121 2.121 4.243 4.243-4.243 4.243 2.121 2.121 4.243-4.243 4.243 4.243 2.121-2.121-4.243-4.243 4.243-4.243-2.121-2.121-4.243 4.243-4.243-4.243" fill-rule="evenodd"/></svg>\n </span>\n </div>\n <div class="zammad-chat-agent zammad-chat-is-hidden">\n </div>\n <div class="zammad-chat-welcome">\n <svg class="zammad-chat-icon" viewBox="0 0 24 24"><path d="M2 5C2 4 3 3 4 3h16c1 0 2 1 2 2v10C22 16 21 17 20 17H4C3 17 2 16 2 15V5zM12 17l6 4v-4h-6z" fill-rule="evenodd"/></svg>\n <span class="zammad-chat-welcome-text">');
__out.push(this.T(this.title));
__out.push('</span>\n </div>\n </div>\n <div class="zammad-chat-body"></div>\n <form class="zammad-chat-controls">\n <textarea class="zammad-chat-input" rows="1" placeholder="');
__out.push(this.T('Compose your message...'));
__out.push('"></textarea>\n <button type="submit" class="zammad-chat-button zammad-chat-send"');
if (this.background) {
__out.push(__sanitize(" style='background: " + this.background + "'"));
}
__out.push('>');
__out.push(this.T('Send'));
__out.push('</button>\n </form>\n</div>');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
2015-12-05 19:41:14 +00:00
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["customer_timeout"] = function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
__out.push('<div class="zammad-chat-modal">\n <div class="zammad-chat-modal-text">\n ');
2015-12-05 19:41:14 +00:00
if (this.agent) {
__out.push('\n ');
__out.push(this.T('Since you didn\'t respond in the last %s minutes your conversation with <strong>%s</strong> got closed.', this.delay, this.agent));
__out.push('\n ');
} else {
__out.push('\n ');
__out.push(this.T('Since you didn\'t respond in the last %s minutes your conversation got closed.', this.delay));
__out.push('\n ');
}
2015-12-05 19:41:14 +00:00
__out.push('\n <br>\n <div class="zammad-chat-button js-restart"');
2015-12-05 19:41:14 +00:00
if (this.background) {
__out.push(__sanitize(" style='background: " + this.background + "'"));
}
2015-12-05 19:41:14 +00:00
__out.push('>');
2015-12-05 19:41:14 +00:00
__out.push(this.T('Start new conversation'));
2015-12-05 19:41:14 +00:00
__out.push('</div>\n </div>\n</div>');
2015-12-05 19:41:14 +00:00
}).call(this);
2015-12-05 19:41:14 +00:00
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
2015-11-11 10:44:10 +00:00
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["loader"] = function (__obj) {
2015-11-11 10:44:10 +00:00
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
__out.push('<div class="zammad-chat-modal">\n <span class="zammad-chat-loading-animation">\n <span class="zammad-chat-loading-circle"></span>\n <span class="zammad-chat-loading-circle"></span>\n <span class="zammad-chat-loading-circle"></span>\n </span>\n <span class="zammad-chat-modal-text">');
__out.push(this.T('Connecting'));
__out.push('</span>\n</div>');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["message"] = function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
__out.push('<div class="zammad-chat-message zammad-chat-message--');
__out.push(__sanitize(this.from));
2015-11-26 09:52:10 +00:00
__out.push(__sanitize(this.unreadClass));
__out.push('">\n <span class="zammad-chat-message-body"');
if (this.background && this.from === 'customer') {
__out.push(__sanitize(" style='background: " + this.background + "'"));
}
__out.push('>');
__out.push(this.message);
__out.push('</span>\n</div>');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
2015-10-15 09:14:19 +00:00
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["status"] = function (__obj) {
2015-10-15 09:14:19 +00:00
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
__out.push('<div class="zammad-chat-status">\n <div class="zammad-chat-status-inner">\n ');
__out.push(this.status);
__out.push('\n </div>\n</div>');
2015-10-15 09:14:19 +00:00
}).call(this);
2015-10-15 09:14:19 +00:00
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
2015-12-05 19:41:14 +00:00
window.zammadChatTemplates["timestamp"] = function (__obj) {
2015-10-15 09:14:19 +00:00
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
2015-12-05 19:41:14 +00:00
__out.push('<div class="zammad-chat-timestamp"><strong>');
2015-12-05 19:41:14 +00:00
__out.push(__sanitize(this.label));
2015-12-05 19:41:14 +00:00
__out.push('</strong> ');
2015-12-05 19:41:14 +00:00
__out.push(__sanitize(this.time));
2015-12-05 19:41:14 +00:00
__out.push('</div>');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
2015-12-05 19:41:14 +00:00
window.zammadChatTemplates["typingIndicator"] = function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
2015-12-05 19:41:14 +00:00
__out.push('<div class="zammad-chat-message zammad-chat-message--typing zammad-chat-message--agent">\n <span class="zammad-chat-message-body">\n <span class="zammad-chat-loading-animation">\n <span class="zammad-chat-loading-circle"></span>\n <span class="zammad-chat-loading-circle"></span>\n <span class="zammad-chat-loading-circle"></span>\n </span>\n </span>\n</div>');
2015-10-15 09:14:19 +00:00
}).call(this);
2015-10-15 09:14:19 +00:00
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
2015-12-05 19:41:14 +00:00
window.zammadChatTemplates["waiting"] = function (__obj) {
2015-10-15 09:14:19 +00:00
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
2015-12-05 19:41:14 +00:00
__out.push('<div class="zammad-chat-modal">\n <div class="zammad-chat-modal-text">\n <span class="zammad-chat-loading-animation">\n <span class="zammad-chat-loading-circle"></span>\n <span class="zammad-chat-loading-circle"></span>\n <span class="zammad-chat-loading-circle"></span>\n </span>\n ');
2016-01-05 12:46:43 +00:00
__out.push(this.T('All colleagues are busy.'));
2015-12-05 19:41:14 +00:00
__out.push('<br>\n ');
2015-12-05 19:41:14 +00:00
__out.push(this.T('You are on waiting list position <strong>%s</strong>.', this.position));
2015-12-05 19:41:14 +00:00
__out.push('\n </div>\n</div>');
2015-10-15 09:14:19 +00:00
}).call(this);
2015-10-15 09:14:19 +00:00
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
2015-12-05 19:41:14 +00:00
window.zammadChatTemplates["waiting_list_timeout"] = function (__obj) {
if (!__obj) __obj = {};
var __out = [], __capture = function(callback) {
var out = __out, result;
__out = [];
callback.call(this);
result = __out.join('');
__out = out;
return __safe(result);
}, __sanitize = function(value) {
if (value && value.ecoSafe) {
return value;
} else if (typeof value !== 'undefined' && value != null) {
return __escape(value);
} else {
return '';
}
}, __safe, __objSafe = __obj.safe, __escape = __obj.escape;
__safe = __obj.safe = function(value) {
if (value && value.ecoSafe) {
return value;
} else {
if (!(typeof value !== 'undefined' && value != null)) value = '';
var result = new String(value);
result.ecoSafe = true;
return result;
}
};
if (!__escape) {
__escape = __obj.escape = function(value) {
return ('' + value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};
}
(function() {
(function() {
2015-12-05 19:41:14 +00:00
__out.push('<div class="zammad-chat-modal">\n <div class="zammad-chat-modal-text">\n ');
2015-12-05 19:41:14 +00:00
__out.push(this.T('We are sorry, it takes longer as expected to get an empty slot. Please try again later or send us an email. Thank you!'));
2015-12-05 19:41:14 +00:00
__out.push('\n <br>\n <div class="zammad-chat-button js-restart"');
2015-12-05 19:41:14 +00:00
if (this.background) {
__out.push(__sanitize(" style='background: " + this.background + "'"));
}
2015-12-05 19:41:14 +00:00
__out.push('>');
2015-12-05 19:41:14 +00:00
__out.push(this.T('Start new conversation'));
2015-12-05 19:41:14 +00:00
__out.push('</div>\n </div>\n</div>');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};