1/*! 2 * WebChat v3 Javascript Library 3 */ 4(function(win, doc) { 5 var defaultSettings = { 6 id: 'sdkWebchat', 7 width: 400, 8 height: 600, 9 bottom: 0, 10 right: 0, 11 zIndex: 999, 12 background: 'transparent', 13 show_main: 0, 14 drag: false 15 }; 16 17 //instantiation livechat 18 function WebChat(options) { 19 var self = this; 20 21 //checkt customer id 22 if (!options.customer.id) { 23 if (localStorage.getItem("webchat:customerid:localstorage")) { 24 options.customer.id = localStorage.getItem( 25 "webchat:customerid:localstorage" 26 ); 27 } else { 28 var customerid = self._guid(); 29 options.customer.id = customerid; 30 localStorage.setItem("webchat:customerid:localstorage", customerid); 31 } 32 } 33 34 //check option 35 if (!options) { 36 throw new Error("Configuration Information Can Not Be Null!"); 37 } else if (!options.app_key) { 38 throw new Error("Configuration Information App Key Can Not Be Null!"); 39 } else if (!options.app_secret) { 40 throw new Error( 41 "Configuration Information App Secret Can Not Be Null!" 42 ); 43 } else if (!options.lang) { 44 throw new Error("Configuration Information Lang Can Not Be Null!"); 45 } else if (!options.system) { 46 throw new Error("Configuration Information System Can Not Be Null!"); 47 } else if (!options.customer) { 48 throw new Error("Configuration Information Customer Can Not Be Null!"); 49 } else if (!options.url) { 50 throw new Error("Configuration Information Url Can Not Be Null!"); 51 } 52 self = Object.assign(self, defaultSettings, options); 53 self.container = 54 doc.querySelector(self.container) || 55 doc.querySelectorAll(self.container); 56 57 //init post message event 58 this._initPostMessageEvent() 59 60 return self._init(); 61 } 62 63 WebChat.prototype = { 64 _init: function () { 65 var self = this; 66 var iframe = null; 67 68 //create iframe 69 if (!doc.getElementById(self.id)) { 70 iframe = doc.createElement("iframe"); 71 iframe.style.border = 0; 72 iframe.setAttribute("id", self.id); 73 iframe.setAttribute("name", self.id); 74 iframe.setAttribute("title", self.id); 75 76 //check view size 77 var win_w = window.innerWidth; 78 if(win_w < 500){ 79 iframe.style.width = '100%'; 80 iframe.style.height = '100%'; 81 } else { 82 iframe.style.width = (this.show_main ? self.width : 100) + 'px'; 83 iframe.style.height = (this.show_main ? self.height : 100) + 'px'; 84 } 85 86 iframe.style.position = "fixed"; 87 iframe.style.bottom = self.bottom; 88 iframe.style.right = self.right; 89 iframe.style.zIndex = self.zIndex; 90 iframe.style.background = self.background; 91 doc.body.appendChild(iframe); 92 } else { 93 iframe = doc.getElementById(self.id); 94 } 95 96 //form data 97 var webchatForm = doc.createElement("form"); 98 webchatForm.style = "display:none;"; 99 webchatForm.method = "post"; 100 webchatForm.action = self.url + "chat/index"; 101 webchatForm.target = self.id; 102 103 var appKeyInput = document.createElement("input"); 104 appKeyInput.type = "hidden"; 105 appKeyInput.name = "app_key"; 106 appKeyInput.value = self.app_key; 107 webchatForm.appendChild(appKeyInput); 108 109 var appSecretInput = document.createElement("input"); 110 appSecretInput.type = "hidden"; 111 appSecretInput.name = "app_secret"; 112 appSecretInput.value = self.app_secret; 113 webchatForm.appendChild(appSecretInput); 114 115 var langInput = document.createElement("input"); 116 langInput.type = "hidden"; 117 langInput.name = "lang"; 118 langInput.value = self.lang; 119 webchatForm.appendChild(langInput); 120 121 var systemInput = document.createElement("input"); 122 systemInput.type = "hidden"; 123 systemInput.name = "system"; 124 systemInput.value = self.system; 125 webchatForm.appendChild(systemInput); 126 127 var customerIdInput = document.createElement("input"); 128 customerIdInput.type = "hidden"; 129 customerIdInput.name = "customerId"; 130 customerIdInput.value = self.customer.id; 131 webchatForm.appendChild(customerIdInput); 132 133 var customerNameInput = document.createElement("input"); 134 customerNameInput.type = "hidden"; 135 customerNameInput.name = "customerName"; 136 customerNameInput.value = self.customer.name; 137 webchatForm.appendChild(customerNameInput); 138 139 var showMainInput = document.createElement("input"); 140 showMainInput.type = "hidden"; 141 showMainInput.name = "showMain"; 142 showMainInput.value = self.show_main; 143 webchatForm.appendChild(showMainInput); 144 145 var navigatorInput = document.createElement("input"); 146 navigatorInput.type = "hidden"; 147 navigatorInput.name = "navigator"; 148 navigatorInput.value = navigator.userAgent; 149 webchatForm.appendChild(navigatorInput); 150 151 var currPageInput = document.createElement("input"); 152 currPageInput.type = "hidden"; 153 currPageInput.name = "currPage"; 154 currPageInput.value = window.location.href; 155 webchatForm.appendChild(currPageInput); 156 157 var prevPageInput = document.createElement("input"); 158 prevPageInput.type = "hidden"; 159 prevPageInput.name = "prevPage"; 160 prevPageInput.value = document.referrer; 161 webchatForm.appendChild(prevPageInput); 162 163 if (self.customer.device) { 164 var deviceInput = document.createElement("input"); 165 deviceInput.type = "hidden"; 166 deviceInput.name = "device"; 167 deviceInput.value = self.customer.device; 168 webchatForm.appendChild(deviceInput); 169 } 170 171 doc.body.appendChild(webchatForm); 172 webchatForm.submit(); 173 doc.body.removeChild(webchatForm); 174 175 return iframe; 176 }, 177 178 _guid: function () { 179 return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace( 180 /[xy]/g, 181 function (c) { 182 var r = (Math.random() * 16) | 0, 183 v = c == "x" ? r : (r & 0x3) | 0x8; 184 return v.toString(16); 185 } 186 ); 187 }, 188 _initPostMessageEvent: function () { 189 var self = this; 190 window.addEventListener( 191 "message", 192 function (e) { 193 let data = e.data; 194 195 // if (!data.id) return 196 // let iframe = doc.getElementById(data.id.slice(1)); 197 let iframe = doc.getElementById(self.id); 198 199 if (data.event == "chat view change") { 200 201 if (data.value == 1) { 202 //open 203 //check view size 204 var win_w = window.innerWidth; 205 206 if(win_w < 500){ 207 iframe.style.width = '100%'; 208 iframe.style.height = '100%'; 209 } else { 210 iframe.style.width = self.width + 'px'; 211 iframe.style.height = self.height + 'px'; 212 } 213 } else if (data.value == 2) { 214 //close 215 // self.width = iframe.getBoundingClientRect().width; 216 // self.height = iframe.getBoundingClientRect().height; 217 218 iframe.style.width = data.width + "px"; 219 iframe.style.height = data.height + "px"; 220 } else if (data.value == 3) { 221 //init size 222 iframe.style.width = data.width + "px"; 223 iframe.style.height = data.height + "px"; 224 } 225 } 226 227 if (data.event == "chat box size") { 228 if (e.data.type == "bigger") { 229 self.width = iframe.getBoundingClientRect().width; 230 self.height = iframe.getBoundingClientRect().height; 231 232 width = self.width + 100; 233 width = width > window.innerWidth ? window.innerWidth : width; 234 235 iframe.style.width = width + 'px'; 236 iframe.style.height = "80vh"; 237 } else { 238 iframe.style.width = self.width + "px"; 239 iframe.style.height = self.height + "px"; 240 } 241 } 242 }, 243 false 244 ); 245 } 246 }; 247 248 WebChat.drag = function (selector) { 249 let el = document.querySelector(selector || "#" + this.id) 250 251 if (!el) { 252 console.warn("WebChat: element not found") 253 return 254 } 255 256 el.onload = function() { 257 el.contentWindow.postMessage({ 258 event: 'send-id', 259 data: selector || this.id 260 }, '*') 261 } 262 263 window.addEventListener("message", function (e) { 264 if (!e.data.event) return 265 266 if (e.data.event === "chat-drag-move") { 267 if (!e.data.data.id) return 268 let { x, y, id } = e.data.data 269 let el = document.querySelector(id) 270 let _x = +el.style.getPropertyValue("--x") 271 let _y = +el.style.getPropertyValue("--y") 272 273 el.style.transform = `translate(${_x + x}px, ${_y + y}px)` 274 } else if (e.data.event === "chat-drag-start") { 275 if (!e.data.data.id) return 276 let el = document.querySelector(e.data.data.id) 277 let transform = el.style.transform.match(/translate\((.+)\)/) 278 279 if (transform) { 280 let [x, y] = transform[1].split(",").map(parseFloat) 281 el.style.setProperty("--x", x) 282 el.style.setProperty("--y", y) 283 } else { 284 el.style.setProperty("--x", 0) 285 el.style.setProperty("--y", 0) 286 } 287 } 288 }); 289 }; 290 291 win.WebChat = WebChat 292})(window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.