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, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
if (this.agent.avatar) {
__out.push('\n\n');
}
__out.push('\n\n ');
__out.push(__sanitize(this.agent.name));
__out.push('\n');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
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;
(function($, window) {
var Base, Io, Log, Timeout, ZammadChat, myScript, scriptHost, scriptProtocol, scripts;
scripts = document.getElementsByTagName('script');
myScript = scripts[scripts.length - 1];
scriptHost = myScript.src.match('.*://([^:/]*).*')[1];
scriptProtocol = myScript.src.match('(.*)://[^:/]*.*')[1];
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) : [];
if (!this.options.debug) {
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) : [];
return this.log('error', items);
};
Log.prototype.log = function(level, items) {
var item, j, len, logString;
items.unshift('||');
items.unshift(level);
items.unshift(this.options.logPrefix);
console.log.apply(console, items);
if (!this.options.debug) {
return;
}
logString = '';
for (j = 0, len = items.length; j < len; j++) {
item = items[j];
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>/g, '
');
}
console.log('p', docType, text);
if (docType === 'html') {
html = $("
" + text + "
");
match = false;
htmlTmp = text;
regex = new RegExp('<(/w|w)\:[A-Za-z]');
if (htmlTmp.match(regex)) {
match = true;
htmlTmp = htmlTmp.replace(regex, '');
}
regex = new RegExp('<(/o|o)\:[A-Za-z]');
if (htmlTmp.match(regex)) {
match = true;
htmlTmp = htmlTmp.replace(regex, '');
}
if (match) {
html = _this.wordFilter(html);
}
html = $(html);
html.contents().each(function() {
if (this.nodeType === 8) {
return $(this).remove();
}
});
html.find('a, font, small, time, form, label').replaceWith(function() {
return $(this).contents();
});
replacementTag = 'div';
html.find('textarea').each(function() {
var newTag, outer;
outer = this.outerHTML;
regex = new RegExp('<' + this.tagName, 'i');
newTag = outer.replace(regex, '<' + replacementTag);
regex = new RegExp('' + this.tagName, 'i');
newTag = newTag.replace(regex, '' + replacementTag);
return $(this).replaceWith(newTag);
});
html.find('font, img, svg, input, select, button, style, applet, embed, noframes, canvas, script, frame, iframe, meta, link, title, head, fieldset').remove();
_this.removeAttributes(html);
text = html.html();
}
if (docType === 'text3') {
_this.pasteHtmlAtCaret(text);
} else {
document.execCommand('insertHTML', false, text);
}
return true;
};
})(this));
this.input.on('drop', (function(_this) {
return function(e) {
var dataTransfer, file, reader, x, y;
e.stopPropagation();
e.preventDefault();
dataTransfer;
if (window.dataTransfer) {
dataTransfer = window.dataTransfer;
} else if (e.originalEvent.dataTransfer) {
dataTransfer = e.originalEvent.dataTransfer;
} else {
throw 'No clipboardData support';
}
x = e.clientX;
y = e.clientY;
file = dataTransfer.files[0];
if (file.type.match('image.*')) {
reader = new FileReader();
reader.onload = function(e) {
var img, insert, result;
result = e.target.result;
img = document.createElement('img');
img.src = result;
insert = function(dataUrl, width, height, isRetina) {
var pos, range;
if (_this.isRetina()) {
width = width / 2;
height = height / 2;
}
result = dataUrl;
img = $("
");
img = img.get(0);
if (document.caretPositionFromPoint) {
pos = document.caretPositionFromPoint(x, y);
range = document.createRange();
range.setStart(pos.offsetNode, pos.offset);
range.collapse();
return range.insertNode(img);
} else if (document.caretRangeFromPoint) {
range = document.caretRangeFromPoint(x, y);
return range.insertNode(img);
} else {
return console.log('could not find carat');
}
};
return _this.resizeImage(img.src, 460, 'auto', 2, 'image/jpeg', 'auto', insert);
};
return reader.readAsDataURL(file);
}
};
})(this));
$(window).on('beforeunload', (function(_this) {
return function() {
return _this.onLeaveTemporary();
};
})(this));
$(window).bind('hashchange', (function(_this) {
return function() {
if (_this.isOpen) {
if (_this.sessionId) {
_this.send('chat_session_notice', {
session_id: _this.sessionId,
message: window.location.href
});
}
return;
}
return _this.idleTimeout.start();
};
})(this));
if (this.isFullscreen) {
return this.input.on({
focus: this.onFocus,
focusout: this.onFocusOut
});
}
};
ZammadChat.prototype.checkForEnter = function(event) {
if (!event.shiftKey && event.keyCode === 13) {
event.preventDefault();
return this.sendMessage();
}
};
ZammadChat.prototype.send = function(event, data) {
if (data == null) {
data = {};
}
data.chat_id = this.options.chatId;
return this.io.send(event, data);
};
ZammadChat.prototype.onWebSocketMessage = function(pipes) {
var j, len, pipe;
for (j = 0, len = pipes.length; j < len; j++) {
pipe = pipes[j];
this.log.debug('ws:onmessage', pipe);
switch (pipe.event) {
case 'chat_error':
this.log.notice(pipe.data);
if (pipe.data && pipe.data.state === 'chat_disabled') {
this.destroy({
remove: true
});
}
break;
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':
this.onConnectionEstablished(pipe.data);
break;
case 'chat_session_queue':
this.onQueueScreen(pipe.data);
break;
case 'chat_session_closed':
this.onSessionClosed(pipe.data);
break;
case 'chat_session_left':
this.onSessionClosed(pipe.data);
break;
case 'chat_status_customer':
switch (pipe.data.state) {
case 'online':
this.sessionId = void 0;
if (!this.options.cssAutoload || this.cssLoaded) {
this.onReady();
} else {
this.socketReady = true;
}
break;
case 'offline':
this.onError('Zammad Chat: No agent online');
break;
case 'chat_disabled':
this.onError('Zammad Chat: Chat is disabled');
break;
case 'no_seats_available':
this.onError("Zammad Chat: Too many clients in queue. Clients in queue: " + pipe.data.queue);
break;
case 'reconnect':
this.onReopenSession(pipe.data);
}
}
}
};
ZammadChat.prototype.onReady = function() {
this.log.debug('widget ready for use');
$("." + this.options.buttonClass).click(this.open).removeClass(this.inactiveClass);
if (this.options.show) {
return this.show();
}
};
ZammadChat.prototype.onError = function(message) {
this.log.debug(message);
this.addStatus(message);
$("." + this.options.buttonClass).hide();
if (this.isOpen) {
this.disableInput();
return this.destroy({
remove: false
});
} else {
return this.destroy({
remove: true
});
}
};
ZammadChat.prototype.onReopenSession = function(data) {
var j, len, message, ref, unfinishedMessage;
this.log.debug('old messages', data.session);
this.inactiveTimeout.start();
unfinishedMessage = sessionStorage.getItem('unfinished_message');
if (data.agent) {
this.onConnectionEstablished(data);
ref = data.session;
for (j = 0, len = ref.length; j < len; j++) {
message = ref[j];
this.renderMessage({
message: message.content,
id: message.id,
from: message.created_by_id ? 'agent' : 'customer'
});
}
if (unfinishedMessage) {
this.input.html(unfinishedMessage);
}
}
if (data.position) {
this.onQueue(data);
}
this.show();
this.open();
this.scrollToBottom();
if (unfinishedMessage) {
return this.input.focus();
}
};
ZammadChat.prototype.onInput = function() {
this.el.find('.zammad-chat-message--unread').removeClass('zammad-chat-message--unread');
sessionStorage.setItem('unfinished_message', this.input.html());
return this.onTyping();
};
ZammadChat.prototype.onFocus = function() {
var keyboardShown;
$(window).scrollTop(10);
keyboardShown = $(window).scrollTop() > 0;
$(window).scrollTop(0);
if (keyboardShown) {
return this.log.notice('virtual keyboard shown');
}
};
ZammadChat.prototype.onFocusOut = function() {};
ZammadChat.prototype.onTyping = function() {
if (this.isTyping && this.isTyping > new Date(new Date().getTime() - 1500)) {
return;
}
this.isTyping = new Date();
this.send('chat_session_typing', {
session_id: this.sessionId
});
return this.inactiveTimeout.start();
};
ZammadChat.prototype.onSubmit = function(event) {
event.preventDefault();
return this.sendMessage();
};
ZammadChat.prototype.sendMessage = function() {
var message, messageElement;
message = this.input.html();
if (!message) {
return;
}
this.inactiveTimeout.start();
sessionStorage.removeItem('unfinished_message');
messageElement = this.view('message')({
message: message,
from: 'customer',
id: this._messageCount++,
unreadClass: ''
});
this.maybeAddTimestamp();
if (this.el.find('.zammad-chat-message--typing').get(0)) {
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);
}
this.input.html('');
this.scrollToBottom();
return this.send('chat_session_message', {
content: message,
id: this._messageCount,
session_id: this.sessionId
});
};
ZammadChat.prototype.receiveMessage = function(data) {
this.inactiveTimeout.start();
this.onAgentTypingEnd();
this.maybeAddTimestamp();
this.renderMessage({
message: data.message.content,
id: data.id,
from: 'agent'
});
return this.scrollToBottom({
showHint: true
});
};
ZammadChat.prototype.renderMessage = function(data) {
this.lastAddedType = "message--" + data.from;
data.unreadClass = document.hidden ? ' zammad-chat-message--unread' : '';
return this.el.find('.zammad-chat-body').append(this.view('message')(data));
};
ZammadChat.prototype.open = function() {
var remainerHeight;
if (this.isOpen) {
this.log.debug('widget already open, block');
return;
}
this.isOpen = true;
this.log.debug('open widget');
if (!this.sessionId) {
this.showLoader();
}
this.el.addClass('zammad-chat-is-open');
remainerHeight = this.el.height() - this.el.find('.zammad-chat-header').outerHeight();
this.el.css('bottom', -remainerHeight);
if (!this.sessionId) {
this.el.animate({
bottom: 0
}, 500, this.onOpenAnimationEnd);
return this.send('chat_session_init', {
url: window.location.href
});
} else {
this.el.css('bottom', 0);
return this.onOpenAnimationEnd();
}
};
ZammadChat.prototype.onOpenAnimationEnd = function() {
this.idleTimeout.stop();
if (this.isFullscreen) {
return this.disableScrollOnRoot();
}
};
ZammadChat.prototype.sessionClose = function() {
this.send('chat_session_close', {
session_id: this.sessionId
});
this.inactiveTimeout.stop();
this.waitingListTimeout.stop();
sessionStorage.removeItem('unfinished_message');
if (this.onInitialQueueDelayId) {
clearTimeout(this.onInitialQueueDelayId);
}
return this.setSessionId(void 0);
};
ZammadChat.prototype.toggle = function(event) {
if (this.isOpen) {
return this.close(event);
} else {
return this.open(event);
}
};
ZammadChat.prototype.close = function(event) {
var remainerHeight;
if (!this.isOpen) {
this.log.debug('can\'t close widget, it\'s not open');
return;
}
if (this.initDelayId) {
clearTimeout(this.initDelayId);
}
if (!this.sessionId) {
this.log.debug('can\'t close widget without sessionId');
return;
}
this.log.debug('close widget');
if (event) {
event.stopPropagation();
}
this.sessionClose();
if (this.isFullscreen) {
this.enableScrollOnRoot();
}
remainerHeight = this.el.height() - this.el.find('.zammad-chat-header').outerHeight();
return this.el.animate({
bottom: -remainerHeight
}, 500, this.onCloseAnimationEnd);
};
ZammadChat.prototype.onCloseAnimationEnd = function() {
this.el.css('bottom', '');
this.el.removeClass('zammad-chat-is-open');
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;
return this.io.reconnect();
};
ZammadChat.prototype.onWebSocketClose = function() {
if (this.isOpen) {
return;
}
if (this.el) {
this.el.removeClass('zammad-chat-is-shown');
return this.el.removeClass('zammad-chat-is-loaded');
}
};
ZammadChat.prototype.show = function() {
if (this.state === 'offline') {
return;
}
this.el.addClass('zammad-chat-is-loaded');
return this.el.addClass('zammad-chat-is-shown');
};
ZammadChat.prototype.disableInput = function() {
this.input.prop('disabled', true);
return this.el.find('.zammad-chat-send').prop('disabled', true);
};
ZammadChat.prototype.enableInput = function() {
this.input.prop('disabled', false);
return this.el.find('.zammad-chat-send').prop('disabled', false);
};
ZammadChat.prototype.hideModal = function() {
return this.el.find('.zammad-chat-modal').html('');
};
ZammadChat.prototype.onQueueScreen = function(data) {
var show;
this.setSessionId(data.session_id);
show = (function(_this) {
return function() {
_this.onQueue(data);
return _this.waitingListTimeout.start();
};
})(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) {
this.log.notice('onQueue', data.position);
this.inQueue = true;
return this.el.find('.zammad-chat-modal').html(this.view('waiting')({
position: data.position
}));
};
ZammadChat.prototype.onAgentTypingStart = function() {
if (this.stopTypingId) {
clearTimeout(this.stopTypingId);
}
this.stopTypingId = setTimeout(this.onAgentTypingEnd, 3000);
if (this.el.find('.zammad-chat-message--typing').get(0)) {
return;
}
this.maybeAddTimestamp();
this.el.find('.zammad-chat-body').append(this.view('typingIndicator')());
if (!this.isVisible(this.el.find('.zammad-chat-message--typing'), true)) {
return;
}
return this.scrollToBottom();
};
ZammadChat.prototype.onAgentTypingEnd = function() {
return this.el.find('.zammad-chat-message--typing').remove();
};
ZammadChat.prototype.onLeaveTemporary = function() {
if (!this.sessionId) {
return;
}
return this.send('chat_session_leave_temporary', {
session_id: this.sessionId
});
};
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
}));
this.lastTimestamp = timestamp;
this.lastAddedType = 'timestamp';
return this.scrollToBottom();
}
}
};
ZammadChat.prototype.updateLastTimestamp = function(label, time) {
if (!this.el) {
return;
}
return this.el.find('.zammad-chat-body').find('.zammad-chat-timestamp').last().replaceWith(this.view('timestamp')({
label: label,
time: time
}));
};
ZammadChat.prototype.addStatus = function(status) {
if (!this.el) {
return;
}
this.maybeAddTimestamp();
this.el.find('.zammad-chat-body').append(this.view('status')({
status: status
}));
return this.scrollToBottom();
};
ZammadChat.prototype.detectScrolledtoBottom = function() {
var scrollBottom;
scrollBottom = this.el.find('.zammad-chat-body').scrollTop() + this.el.find('.zammad-chat-body').outerHeight();
this.scrolledToBottom = Math.abs(scrollBottom - this.el.find('.zammad-chat-body').prop('scrollHeight')) <= this.scrollSnapTolerance;
if (this.scrolledToBottom) {
return this.el.find('.zammad-scroll-hint').addClass('is-hidden');
}
};
ZammadChat.prototype.showScrollHint = function() {
this.el.find('.zammad-scroll-hint').removeClass('is-hidden');
return this.el.find('.zammad-chat-body').scrollTop(this.el.find('.zammad-chat-body').scrollTop() + this.el.find('.zammad-scroll-hint').outerHeight());
};
ZammadChat.prototype.onScrollHintClick = function() {
return this.el.find('.zammad-chat-body').animate({
scrollTop: this.el.find('.zammad-chat-body').prop('scrollHeight')
}, 300);
};
ZammadChat.prototype.scrollToBottom = function(arg) {
var showHint;
showHint = (arg != null ? arg : {
showHint: false
}).showHint;
if (this.scrolledToBottom) {
return this.el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'));
} else if (showHint) {
return this.showScrollHint();
}
};
ZammadChat.prototype.destroy = function(params) {
if (params == null) {
params = {};
}
this.log.debug('destroy widget', params);
this.setAgentOnlineState('offline');
if (params.remove && this.el) {
this.el.remove();
}
if (this.waitingListTimeout) {
this.waitingListTimeout.stop();
}
if (this.inactiveTimeout) {
this.inactiveTimeout.stop();
}
if (this.idleTimeout) {
this.idleTimeout.stop();
}
return this.io.close();
};
ZammadChat.prototype.reconnect = function() {
this.log.notice('reconnecting');
this.disableInput();
this.lastAddedType = 'status';
this.setAgentOnlineState('connecting');
return this.addStatus(this.T('Connection lost'));
};
ZammadChat.prototype.onConnectionReestablished = function() {
this.lastAddedType = 'status';
this.setAgentOnlineState('online');
return this.addStatus(this.T('Connection re-established'));
};
ZammadChat.prototype.onSessionClosed = function(data) {
this.addStatus(this.T('Chat closed by %s', data.realname));
this.disableInput();
this.setAgentOnlineState('offline');
return this.inactiveTimeout.stop();
};
ZammadChat.prototype.setSessionId = function(id) {
this.sessionId = id;
if (id === void 0) {
return sessionStorage.removeItem('sessionId');
} else {
return sessionStorage.setItem('sessionId', id);
}
};
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-body').html('');
this.el.find('.zammad-chat-agent').html(this.view('agent')({
agent: this.agent
}));
this.enableInput();
this.hideModal();
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');
if (!this.isFullscreen) {
this.input.focus();
}
this.setAgentOnlineState('online');
this.waitingListTimeout.stop();
this.idleTimeout.stop();
return this.inactiveTimeout.start();
};
ZammadChat.prototype.showCustomerTimeout = function() {
var reload;
this.el.find('.zammad-chat-modal').html(this.view('customer_timeout')({
agent: this.agent.name,
delay: this.options.inactiveTimeout
}));
reload = function() {
return location.reload();
};
this.el.find('.js-restart').click(reload);
return this.sessionClose();
};
ZammadChat.prototype.showWaitingListTimeout = function() {
var reload;
this.el.find('.zammad-chat-modal').html(this.view('waiting_list_timeout')({
delay: this.options.watingListTimeout
}));
reload = function() {
return location.reload();
};
this.el.find('.js-restart').click(reload);
return this.sessionClose();
};
ZammadChat.prototype.showLoader = function() {
return this.el.find('.zammad-chat-modal').html(this.view('loader')());
};
ZammadChat.prototype.setAgentOnlineState = function(state) {
var capitalizedState;
this.state = state;
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));
};
ZammadChat.prototype.detectHost = function() {
var protocol;
protocol = 'ws://';
if (scriptProtocol === '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';
}
this.log.debug("load css from '" + url + "'");
styles = "@import url('" + url + "');";
newSS = document.createElement('link');
newSS.onload = this.onCssLoaded;
newSS.rel = 'stylesheet';
newSS.href = 'data:text/css,' + escape(styles);
return document.getElementsByTagName('head')[0].appendChild(newSS);
};
ZammadChat.prototype.onCssLoaded = function() {
if (this.socketReady) {
return this.onReady();
} else {
return this.cssLoaded = true;
}
};
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({
remove: true
});
};
})(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({
remove: false
});
};
})(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({
remove: false
});
};
})(this)
});
};
ZammadChat.prototype.disableScrollOnRoot = function() {
this.rootScrollOffset = this.scrollRoot.scrollTop();
return this.scrollRoot.css({
overflow: 'hidden',
position: 'fixed'
});
};
ZammadChat.prototype.enableScrollOnRoot = function() {
this.scrollRoot.scrollTop(this.rootScrollOffset);
return this.scrollRoot.css({
overflow: '',
position: ''
});
};
ZammadChat.prototype.isVisible = function(el, partial, hidden, direction) {
var $t, $w, _bottom, _left, _right, _top, bViz, clientSize, compareBottom, compareLeft, compareRight, compareTop, hVisible, lViz, offset, rViz, rec, t, tViz, vVisible, viewBottom, viewLeft, viewRight, viewTop, vpHeight, vpWidth;
if (el.length < 1) {
return;
}
$w = $(window);
$t = el.length > 1 ? el.eq(0) : el;
t = $t.get(0);
vpWidth = $w.width();
vpHeight = $w.height();
direction = direction ? direction : 'both';
clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true;
if (typeof t.getBoundingClientRect === 'function') {
rec = t.getBoundingClientRect();
tViz = rec.top >= 0 && rec.top < vpHeight;
bViz = rec.bottom > 0 && rec.bottom <= vpHeight;
lViz = rec.left >= 0 && rec.left < vpWidth;
rViz = rec.right > 0 && rec.right <= vpWidth;
vVisible = partial ? tViz || bViz : tViz && bViz;
hVisible = partial ? lViz || rViz : lViz && rViz;
if (direction === 'both') {
return clientSize && vVisible && hVisible;
} else if (direction === 'vertical') {
return clientSize && vVisible;
} else if (direction === 'horizontal') {
return clientSize && hVisible;
}
} else {
viewTop = $w.scrollTop();
viewBottom = viewTop + vpHeight;
viewLeft = $w.scrollLeft();
viewRight = viewLeft + vpWidth;
offset = $t.offset();
_top = offset.top;
_bottom = _top + $t.height();
_left = offset.left;
_right = _left + $t.width();
compareTop = partial === true ? _bottom : _top;
compareBottom = partial === true ? _top : _bottom;
compareLeft = partial === true ? _right : _left;
compareRight = partial === true ? _left : _right;
if (direction === 'both') {
return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)) && ((compareRight <= viewRight) && (compareLeft >= viewLeft));
} else if (direction === 'vertical') {
return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop));
} else if (direction === 'horizontal') {
return !!clientSize && ((compareRight <= viewRight) && (compareLeft >= viewLeft));
}
}
};
ZammadChat.prototype.isRetina = function() {
var mq;
if (window.matchMedia) {
mq = window.matchMedia('only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3), only screen and (min-resolution: 1.3dppx)');
return mq && mq.matches || (window.devicePixelRatio > 1);
}
return false;
};
ZammadChat.prototype.resizeImage = function(dataURL, x, y, sizeFactor, type, quallity, callback, force) {
var imageObject;
if (x == null) {
x = 'auto';
}
if (y == null) {
y = 'auto';
}
if (sizeFactor == null) {
sizeFactor = 1;
}
if (force == null) {
force = true;
}
imageObject = new Image();
imageObject.onload = function() {
var canvas, context, factor, imageHeight, imageWidth, newDataUrl, resize;
imageWidth = imageObject.width;
imageHeight = imageObject.height;
console.log('ImageService', 'current size', imageWidth, imageHeight);
if (y === 'auto' && x === 'auto') {
x = imageWidth;
y = imageHeight;
}
if (y === 'auto') {
factor = imageWidth / x;
y = imageHeight / factor;
}
if (x === 'auto') {
factor = imageWidth / y;
x = imageHeight / factor;
}
resize = false;
if (x < imageWidth || y < imageHeight) {
resize = true;
x = x * sizeFactor;
y = y * sizeFactor;
} else {
x = imageWidth;
y = imageHeight;
}
canvas = document.createElement('canvas');
canvas.width = x;
canvas.height = y;
context = canvas.getContext('2d');
context.drawImage(imageObject, 0, 0, x, y);
if (quallity === 'auto') {
if (x < 200 && y < 200) {
quallity = 1;
} else if (x < 400 && y < 400) {
quallity = 0.9;
} else if (x < 600 && y < 600) {
quallity = 0.8;
} else if (x < 900 && y < 900) {
quallity = 0.7;
} else {
quallity = 0.6;
}
}
newDataUrl = canvas.toDataURL(type, quallity);
if (resize) {
console.log('ImageService', 'resize', x / sizeFactor, y / sizeFactor, quallity, (newDataUrl.length * 0.75) / 1024 / 1024, 'in mb');
callback(newDataUrl, x / sizeFactor, y / sizeFactor, true);
return;
}
console.log('ImageService', 'no resize', x, y, quallity, (newDataUrl.length * 0.75) / 1024 / 1024, 'in mb');
return callback(newDataUrl, x, y, false);
};
return imageObject.src = dataURL;
};
ZammadChat.prototype.pasteHtmlAtCaret = function(html) {
var el, frag, lastNode, node, range, sel;
sel = void 0;
range = void 0;
if (window.getSelection) {
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
el = document.createElement('div');
el.innerHTML = html;
frag = document.createDocumentFragment(node, lastNode);
while (node = el.firstChild) {
lastNode = frag.appendChild(node);
}
range.insertNode(frag);
if (lastNode) {
range = range.cloneRange();
range.setStartAfter(lastNode);
range.collapse(true);
sel.removeAllRanges();
return sel.addRange(range);
}
}
} else if (document.selection && document.selection.type !== 'Control') {
return document.selection.createRange().pasteHTML(html);
}
};
ZammadChat.prototype.wordFilter = function(editor) {
var content, last_level, pnt;
content = editor.html();
content = content.replace(//gi, '');
content = content.replace(/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi, '');
content = content.replace(/<(\/?)s>/gi, '<$1strike>');
content = content.replace(/ /gi, ' ');
editor.html(content);
$('p', editor).each(function() {
var matches, str;
str = $(this).attr('style');
matches = /mso-list:\w+ \w+([0-9]+)/.exec(str);
if (matches) {
return $(this).data('_listLevel', parseInt(matches[1], 10));
}
});
last_level = 0;
pnt = null;
$('p', editor).each(function() {
var cur_level, i, j, list_tag, matches, ref, ref1, ref2, start, txt;
cur_level = $(this).data('_listLevel');
if (cur_level !== void 0) {
txt = $(this).text();
list_tag = '
';
if (/^\s*\w+\./.test(txt)) {
matches = /([0-9])\./.exec(txt);
if (matches) {
start = parseInt(matches[1], 10);
list_tag = (ref = start > 1) != null ? ref : '
': '
'
};
} else {
list_tag = '
';
}
}
if (cur_level > last_level) {
if (last_level === 0) {
$(this).before(list_tag);
pnt = $(this).prev();
} else {
pnt = $(list_tag).appendTo(pnt);
}
}
if (cur_level < last_level) {
for (i = j = ref1 = i, ref2 = last_level - cur_level; ref1 <= ref2 ? j <= ref2 : j >= ref2; i = ref1 <= ref2 ? ++j : --j) {
pnt = pnt.parent();
}
}
$('span:first', this).remove();
pnt.append('
' + $(this).html() + '');
$(this).remove();
return last_level = cur_level;
} else {
return last_level = 0;
}
});
$('[style]', editor).removeAttr('style');
$('[align]', editor).removeAttr('align');
$('span', editor).replaceWith(function() {
return $(this).contents();
});
$('span:empty', editor).remove();
$("[class^='Mso']", editor).removeAttr('class');
$('p:empty', editor).remove();
return editor;
};
ZammadChat.prototype.removeAttribute = function(element) {
var $element, att, j, len, ref;
if (!element) {
return;
}
$element = $(element);
ref = element.attributes;
for (j = 0, len = ref.length; j < len; j++) {
att = ref[j];
if (att && att.name) {
element.removeAttribute(att.name);
}
}
return $element.removeAttr('style').removeAttr('class').removeAttr('lang').removeAttr('type').removeAttr('align').removeAttr('id').removeAttr('wrap').removeAttr('title');
};
ZammadChat.prototype.removeAttributes = function(html, parent) {
if (parent == null) {
parent = true;
}
if (parent) {
html.each((function(_this) {
return function(index, element) {
return _this.removeAttribute(element);
};
})(this));
}
html.find('*').each((function(_this) {
return function(index, element) {
return _this.removeAttribute(element);
};
})(this));
return html;
};
return ZammadChat;
})(Base);
return window.ZammadChat = ZammadChat;
})(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, '&')
.replace(//g, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
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, '&')
.replace(//g, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n ');
if (this.agent) {
__out.push('\n ');
__out.push(this.T('Since you didn\'t respond in the last %s minutes your conversation with
%s 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 ');
}
__out.push('\n
\n
');
__out.push(this.T('Start new conversation'));
__out.push('
\n
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["loader"] = 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, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n \n \n \n\n
');
__out.push(this.T('Connecting'));
__out.push('');
}).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, '&')
.replace(//g, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n ');
__out.push(this.message);
__out.push('\n
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["status"] = 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, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n
\n ');
__out.push(this.status);
__out.push('\n
\n
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["timestamp"] = 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, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
');
__out.push(__sanitize(this.label));
__out.push(' ');
__out.push(__sanitize(this.time));
__out.push('
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
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, '&')
.replace(//g, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n \n \n \n \n \n \n \n
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
window.zammadChatTemplates["waiting"] = 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, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n \n \n \n \n \n ');
__out.push(this.T('All colleagues are busy.'));
__out.push('
\n ');
__out.push(this.T('You are on waiting list position %s.', this.position));
__out.push('\n
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};
if (!window.zammadChatTemplates) {
window.zammadChatTemplates = {};
}
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, '&')
.replace(//g, '>')
.replace(/"/g, '"');
};
}
(function() {
(function() {
__out.push('
\n ');
__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!'));
__out.push('\n
\n
');
__out.push(this.T('Start new conversation'));
__out.push('
\n
');
}).call(this);
}).call(__obj);
__obj.safe = __objSafe, __obj.escape = __escape;
return __out.join('');
};