12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952 |
- 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, scripts;
- scripts = document.getElementsByTagName('script');
- myScript = scripts[scripts.length - 1];
- scriptHost = 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 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;
- }
- this.log.debug("Stop timeout of " + this.options.timeout + " minutes");
- 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);
- 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) {
- _this.log.debug('onOpen', e);
- _this.options.onOpen(e);
- return _this.ping();
- };
- })(this);
- this.ws.onmessage = (function(_this) {
- return function(e) {
- var i, len, pipe, pipes;
- pipes = JSON.parse(e.data);
- _this.log.debug('onMessage', e.data);
- for (i = 0, len = pipes.length; i < len; i++) {
- pipe = pipes[i];
- if (pipe.event === 'pong') {
- _this.ping();
- }
- }
- if (_this.options.onMessage) {
- return _this.options.onMessage(pipes);
- }
- };
- })(this);
- this.ws.onclose = (function(_this) {
- return function(e) {
- _this.log.debug('close websocket connection', e);
- if (_this.pingDelayId) {
- clearTimeout(_this.pingDelayId);
- }
- 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...');
- }
- }
- };
- })(this);
- return this.ws.onerror = (function(_this) {
- return function(e) {
- _this.log.debug('onError', e);
- if (_this.options.onError) {
- return _this.options.onError(e);
- }
- };
- })(this);
- };
- Io.prototype.close = function() {
- this.log.debug('close websocket manually');
- this.manualClose = true;
- return this.ws.close();
- };
- Io.prototype.reconnect = function() {
- this.log.debug('reconnect');
- this.close();
- 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);
- };
- return Io;
- })(Base);
- ZammadChat = (function(superClass) {
- extend(ZammadChat, superClass);
- ZammadChat.prototype.defaults = {
- chatId: void 0,
- show: true,
- target: $('body'),
- host: '',
- debug: false,
- flat: false,
- lang: void 0,
- cssAutoload: true,
- cssUrl: void 0,
- fontSize: void 0,
- buttonClass: 'open-zammad-chat',
- inactiveClass: 'is-inactive',
- title: '<strong>Chat</strong> with us!',
- idleTimeout: 6,
- idleTimeoutIntervallCheck: 0.5,
- inactiveTimeout: 8,
- inactiveTimeoutIntervallCheck: 0.5,
- waitingListTimeout: 4,
- waitingListTimeoutIntervallCheck: 0.5
- };
- ZammadChat.prototype.logPrefix = 'chat';
- ZammadChat.prototype._messageCount = 0;
- ZammadChat.prototype.isOpen = false;
- ZammadChat.prototype.blinkOnlineInterval = null;
- ZammadChat.prototype.stopBlinOnlineStateTimeout = null;
- ZammadChat.prototype.showTimeEveryXMinutes = 2;
- ZammadChat.prototype.lastTimestamp = null;
- ZammadChat.prototype.lastAddedType = null;
- ZammadChat.prototype.inputTimeout = null;
- ZammadChat.prototype.isTyping = false;
- ZammadChat.prototype.state = 'offline';
- 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...',
- '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',
- '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.'
- }
- };
- 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]) {
- this.log.notice("Translation '" + this.options.lang + "' needed!");
- } else {
- translations = this.translations[this.options.lang];
- if (!translations[string]) {
- 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;
- };
- 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;
- options.fontSize = _this.options.fontSize;
- return window.zammadChatTemplates[name](options);
- };
- })(this);
- };
- function ZammadChat(options) {
- this.startTimeoutObservers = bind(this.startTimeoutObservers, this);
- this.onCssLoaded = bind(this.onCssLoaded, this);
- this.setAgentOnlineState = bind(this.setAgentOnlineState, this);
- this.onConnectionEstablished = bind(this.onConnectionEstablished, this);
- this.setSessionId = bind(this.setSessionId, this);
- this.onConnectionReestablished = bind(this.onConnectionReestablished, this);
- this.reconnect = bind(this.reconnect, this);
- this.destroy = bind(this.destroy, this);
- this.onLeaveTemporary = bind(this.onLeaveTemporary, this);
- this.onAgentTypingEnd = bind(this.onAgentTypingEnd, this);
- this.onAgentTypingStart = bind(this.onAgentTypingStart, this);
- this.onQueue = bind(this.onQueue, this);
- this.onQueueScreen = bind(this.onQueueScreen, this);
- this.onWebSocketClose = bind(this.onWebSocketClose, this);
- this.onCloseAnimationEnd = bind(this.onCloseAnimationEnd, this);
- this.close = bind(this.close, this);
- this.toggle = bind(this.toggle, this);
- this.sessionClose = bind(this.sessionClose, this);
- this.onOpenAnimationEnd = bind(this.onOpenAnimationEnd, this);
- this.open = bind(this.open, this);
- this.renderMessage = bind(this.renderMessage, this);
- this.receiveMessage = bind(this.receiveMessage, this);
- this.onSubmit = bind(this.onSubmit, this);
- this.onFocus = bind(this.onFocus, this);
- this.onInput = bind(this.onInput, this);
- this.onReopenSession = bind(this.onReopenSession, this);
- this.onError = bind(this.onError, this);
- this.onWebSocketMessage = bind(this.onWebSocketMessage, this);
- this.send = bind(this.send, this);
- this.checkForEnter = bind(this.checkForEnter, this);
- this.render = bind(this.render, this);
- this.view = bind(this.view, this);
- this.T = bind(this.T, this);
- this.options = $.extend({}, this.defaults, options);
- ZammadChat.__super__.constructor.call(this, this.options);
- this.isFullscreen = window.matchMedia && window.matchMedia('(max-width: 768px)').matches;
- this.scrollRoot = $(this.getScrollRoot());
- if (!$) {
- this.state = 'unsupported';
- this.log.notice('Chat: no jquery found!');
- return;
- }
- if (!window.WebSocket || !sessionStorage) {
- this.state = 'unsupported';
- this.log.notice('Chat: Browser not supported!');
- return;
- }
- if (!this.options.chatId) {
- this.state = 'unsupported';
- this.log.error('Chat: need chatId as option!');
- return;
- }
- if (!this.options.lang) {
- this.options.lang = $('html').attr('lang');
- }
- if (this.options.lang) {
- this.options.lang = this.options.lang.replace(/-.+?$/, '');
- this.log.debug("lang: " + this.options.lang);
- }
- if (!this.options.host) {
- this.detectHost();
- }
- this.loadCss();
- this.io = new Io(this.options);
- this.io.set({
- onOpen: this.render,
- onClose: this.onWebSocketClose,
- onMessage: this.onWebSocketMessage,
- onError: this.onError
- });
- this.io.connect();
- }
- ZammadChat.prototype.getScrollRoot = function() {
- var end, html, start;
- if ('scrollingElement' in document) {
- return document.scrollingElement;
- }
- html = document.documentElement;
- start = html.scrollTop;
- html.scrollTop = start + 1;
- end = html.scrollTop;
- html.scrollTop = start;
- if (end > start) {
- return html;
- } else {
- return document.body;
- }
- };
- ZammadChat.prototype.render = function() {
- if (!this.el || !$('.zammad-chat').get(0)) {
- this.renderBase();
- }
- $("." + this.options.buttonClass).addClass(this.inactiveClass);
- 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,
- url: window.location.href
- });
- };
- ZammadChat.prototype.renderBase = function() {
- 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-toggle').click(this.toggle);
- 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) {
- 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 i, len, pipe;
- for (i = 0, len = pipes.length; i < len; i++) {
- pipe = pipes[i];
- 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 i, 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 (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);
- }
- 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.val());
- 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.val();
- 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').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);
- }
- this.input.val('');
- 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();
- return this.renderMessage({
- message: data.message.content,
- id: data.id,
- from: 'agent'
- });
- };
- ZammadChat.prototype.renderMessage = function(data) {
- this.lastAddedType = "message--" + data.from;
- data.unreadClass = document.hidden ? ' zammad-chat-message--unread' : '';
- this.el.find('.zammad-chat-body').append(this.view('message')(data));
- return this.scrollToBottom();
- };
- 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');
- if (!this.inputInitialized) {
- this.inputInitialized = true;
- this.input.autoGrow({
- extraLine: false
- });
- }
- 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').size()) {
- 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.scrollToBottom = function() {
- return this.el.find('.zammad-chat-body').scrollTop($('.zammad-chat-body').prop('scrollHeight'));
- };
- 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 (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';
- }
- 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));
- }
- }
- };
- return ZammadChat;
- })(Base);
- return window.ZammadChat = ZammadChat;
- })(window.jQuery, window);
- 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, '>')
- .replace(/"/g, '"');
- };
- }
- (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, '&')
- .replace(/"/g, '"')
- .replace(/'/g, ''')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/ /g, ' ')
- .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');
- // 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);
- });
- };
- 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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<div class="zammad-chat');
-
- if (this.flat) {
- __out.push(__sanitize(' zammad-chat--flat'));
- }
-
- __out.push('"');
-
- if (this.fontSize) {
- __out.push(__sanitize(" style='font-size: " + this.fontSize + "'"));
- }
-
- __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 js-chat-toggle">\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" width="13" height="7" 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" width="13" height="13" 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" width="24" height="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"/></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-modal"></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('');
- };
- 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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<div class="zammad-chat-modal-text">\n ');
-
- 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 ');
- }
-
- __out.push('\n <br>\n <div class="zammad-chat-button js-restart"');
-
- if (this.background) {
- __out.push(__sanitize(" style='background: " + this.background + "'"));
- }
-
- __out.push('>');
-
- __out.push(this.T('Start new conversation'));
-
- __out.push('</div>\n</div>');
-
- }).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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<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>');
-
- }).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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<div class="zammad-chat-message zammad-chat-message--');
-
- __out.push(__sanitize(this.from));
-
- __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('');
- };
- 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, '>')
- .replace(/"/g, '"');
- };
- }
- (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>');
-
- }).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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<div class="zammad-chat-timestamp"><strong>');
-
- __out.push(__sanitize(this.label));
-
- __out.push('</strong> ');
-
- __out.push(__sanitize(this.time));
-
- __out.push('</div>');
-
- }).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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __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>');
-
- }).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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<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 ');
-
- __out.push(this.T('All colleagues are busy.'));
-
- __out.push('<br>\n ');
-
- __out.push(this.T('You are on waiting list position <strong>%s</strong>.', this.position));
-
- __out.push('\n</div>');
-
- }).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, '>')
- .replace(/"/g, '"');
- };
- }
- (function() {
- (function() {
- __out.push('<div class="zammad-chat-modal-text">\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 <br>\n <div class="zammad-chat-button js-restart"');
-
- if (this.background) {
- __out.push(__sanitize(" style='background: " + this.background + "'"));
- }
-
- __out.push('>');
-
- __out.push(this.T('Start new conversation'));
-
- __out.push('</div>\n</div>');
-
- }).call(this);
-
- }).call(__obj);
- __obj.safe = __objSafe, __obj.escape = __escape;
- return __out.join('');
- };
|