import { AppConfigType } from '../../entities/AppConfig'; export function LiveChatDirectiveFactory() { return new LiveChatDirective(); } class LiveChatDirective implements angular.IDirective { retrict = 'E'; template = require('./LiveChat.html'); transclude = true; bindToController = true; controller = LiveChatController; controllerAs = 'ctrl'; } class LiveChatController { constructor(private appConfig: AppConfigType, private $window: LiveChatWindow) { if ($window.liveagent) { $window.liveagent.init('https://d.la1-c1-lon.salesforceliveagent.com/chat', this.appConfig.liveChat.deploymentId, this.appConfig.liveChat.salesforceId); $window.liveagent.setChatWindowWidth(600); $window.liveagent.setChatWindowHeight(600); $.each(document.getElementsByClassName('live-chat'), (_, element: Element) => { $window.liveagent.showWhenOnline(this.appConfig.liveChat.chatId, element); }); } } startChat() { this.$window.liveagent.startChat(this.appConfig.liveChat.chatId); } } interface LiveAgent { init(url: string, deploymentId: string, salesforceId: string); setChatWindowWidth(width: number); setChatWindowHeight(height: number); showWhenOnline(buttonId: string, element: Element): void; showWhenOffline(buttonId: string, element: Element): void; startChat(buttonId: string); } interface LiveChatWindow extends angular.IWindowService { liveagent: LiveAgent; }