Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.00 KB | None | 0 0
  1. "use strict";
  2. ! function() {
  3. function e(e) {
  4. return E[e]
  5. }
  6.  
  7. function t(t) {
  8. return t && t.length > 0 ? t.replace(b, e) : void 0
  9. }
  10. var a, s, n, i, o, r, l, c, m, h, d = ["https://w.chatlio.com/vendor/react-0.12.2.min.js", "//cdn.pubnub.com/pubnub-3.7.8.min.js"],
  11. p = "w.chatlio",
  12. u = !1,
  13. g = "https://w.chatlio.com/main.442f6971.css",
  14. f = 2e4,
  15. w = 20,
  16. v = 1728e5,
  17. y = new Audio("https://w.chatlio.com/media/water-drips-single16.a1857954.mp3");
  18. y.volume = .8;
  19. for (var E = {
  20. "&": "&",
  21. ">": ">",
  22. "<": "&lt;",
  23. '"': "&quot;",
  24. "'": "&#x27;",
  25. "`": "&#x27;"
  26. }, b = /[&><"'`]/g, N = document.getElementsByTagName("script"), C = "", S = 0; S < N.length; S++) {
  27. var D = N[S].src;
  28. if (D && D.indexOf(p) > 0) {
  29. C = N[S], l = document.createElement("div"), l.id = "chatlio-widget";
  30. var M = document.getElementById("chatlioWidgetPlaceholder");
  31. M ? document.getElementById("chatlioWidgetPlaceholder").appendChild(l) : document.body.appendChild(l), a = t(C.getAttribute("data-widget-id")), n = "chatlio_uuid--" + t(a), g = t(C.getAttribute("data-chatlio-css-src")) || g;
  32. try {
  33. i = JSON.parse(C.getAttribute("data-widget-options")) || {}
  34. } catch (T) {
  35. i = {}
  36. }
  37. }
  38. }
  39. var _ = function(e) {
  40. var t = Math.floor((new Date - e) / 1e3);
  41. if (60 > t) return "just now";
  42. var a = Math.floor(t / 31536e3);
  43. return a > 1 ? a + "y ago" : (a = Math.floor(t / 2592e3), a > 1 ? a + "m ago" : (a = Math.floor(t / 86400), a > 1 ? a + "d ago" : (a = Math.floor(t / 3600), a > 1 ? a + "h ago" : (a = Math.floor(t / 60), a > 1 ? a + "m ago" : 1 === a ? a + "m ago" : ""))))
  44. },
  45. k = function(e, t) {
  46. var a = document.createElement("script");
  47. a.setAttribute("type", "text/javascript"), a.setAttribute("src", e), a.onload = t, (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(a)
  48. },
  49. O = function() {
  50. if (U() && i.skipRequireLoad !== !0) require(d, function(e) {
  51. R(e)
  52. });
  53. else {
  54. var e = 0,
  55. t = function() {
  56. e++, e === d.length && R(React)
  57. };
  58. d.forEach(function(e) {
  59. k(e, t)
  60. })
  61. }
  62. },
  63. B = function(e) {
  64. var a = document.createElement("link");
  65. a.setAttribute("type", "text/css"), a.setAttribute("rel", "stylesheet"), a.setAttribute("href", t(e)), (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(a)
  66. },
  67. x = function(e, t, a) {
  68. var s = new Date;
  69. s.setTime(s.getTime() + 24 * a * 60 * 60 * 1e3);
  70. var n = "expires=" + s.toGMTString();
  71. document.cookie = e + "=" + t + "; " + n
  72. },
  73. A = function(e) {
  74. for (var t = e + "=", a = document.cookie.split(";"), s = 0; s < a.length; s++) {
  75. var n = a[s];
  76. if (-1 !== n.indexOf(t)) {
  77. for (;
  78. " " === n.charAt(0);) n = n.substring(1);
  79. return n.substring(t.length, n.length)
  80. }
  81. }
  82. return ""
  83. },
  84. I = function() {
  85. function e() {
  86. return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1)
  87. }
  88. return function() {
  89. return e() + e() + "-" + e() + "-" + e() + "-" + e() + "-" + e() + e() + e()
  90. }
  91. }(),
  92. P = function() {
  93. var e = A(n);
  94. return "" === e && (e = I(), x(n, e, 365)), e
  95. },
  96. U = function() {
  97. return "undefined" != typeof window.define && "undefined" !== window.require
  98. },
  99. W = function() {
  100. window._chatlio_pre_load = window._chatlio, window._chatlio = window._chatlio || [];
  101. var e = 5;
  102. window._chatlio.identify = function(t, n) {
  103. Object.keys(n).forEach(function(e) {
  104. n[e] = String(n[e])
  105. }), F("https://api.chatlio.com/v1/p/visitor/identify", {
  106. data: "vsUuid=" + s + "&ceUuid=" + a + "&userId=" + encodeURIComponent(t) + "&traits=" + encodeURIComponent(JSON.stringify(n)),
  107. onerror: function() {
  108. e > 0 ? (setTimeout(function() {
  109. window._chatlio.identify(t, n)
  110. }, f), e--) : console.warn("Oh noes! There was a problem identifying the current user to Chatlio. Please contact Chatlio support at support@chatlio.com. Status code: ", this.status)
  111. }
  112. })
  113. }
  114. },
  115. V = 5,
  116. R = function(e) {
  117. F("https://api.chatlio.com/v1/p/visitor/new", {
  118. timeout: 2999,
  119. onload: function() {
  120. G(e), u = !0
  121. },
  122. onerror: function() {
  123. J(), V > 0 ? (V--, setTimeout(R, 5003)) : (console.error("Oh noes! There was a problem registering the Chatlio widget '" + s + "'/'" + a + "'. Please contact Chatlio support! Status code: ", this.status), J())
  124. }
  125. })
  126. },
  127. J = function() {
  128. m && (m.unsubscribe({
  129. channel: s
  130. }), m = void 0), c && c.isMounted() && React.unmountComponentAtNode(l), h = void 0
  131. },
  132. q = function(e, t, a) {
  133. t = t || 1250;
  134. var s, n;
  135. return function() {
  136. var i = a || this,
  137. o = Date.now(),
  138. r = arguments;
  139. s && s + t > o ? (clearTimeout(n), n = setTimeout(function() {
  140. s = o, e.apply(i, r)
  141. }, t)) : (s = o, e.apply(i, r))
  142. }
  143. },
  144. j = function(e) {
  145. var t = new XMLHttpRequest;
  146. if ("withCredentials" in t) t.open("GET", e, !0);
  147. else {
  148. if ("undefined" == typeof XDomainRequest) throw new Error("Your browser does not support CORS. Please contact chatlio support at support@chatlio.com");
  149. t = new XDomainRequest, t.open("GET", e)
  150. }
  151. return t
  152. },
  153. F = function(e, t) {
  154. var n = t.data || "vsUuid=" + s + "&ceUuid=" + a,
  155. i = j(e + "?" + n);
  156. return i.onload = function() {
  157. if ("withCredentials" in i) 200 === i.status ? t.onload && t.onload.apply(i, arguments) : t.onerror.apply(i, arguments);
  158. else {
  159. var e;
  160. try {
  161. e = JSON.parse(this.responseText) || {}
  162. } catch (a) {
  163. e = {}
  164. }!e.status || "200" !== e.status && "online" !== e.status ? t.onerror.apply(i, arguments) : t.onload && t.onload.apply(i, arguments)
  165. }
  166. }, i.onerror = function() {
  167. t.onerror.apply(i, arguments)
  168. }, t.timeout > 0 && (i.timeout = t.timeout, i.ontimeout = t.ontimeout ? function() {
  169. t.ontimeout.apply(i, arguments)
  170. } : function() {
  171. t.onerror.apply(i, arguments)
  172. }), i.send(), i
  173. };
  174. s = P(), o = "chatlio-" + s + "-messages", r = "chatlio-" + s + "-isClosed", B(g), O();
  175. var G = function(e) {
  176. var n = 10,
  177. d = function() {
  178. setTimeout(d, f), F("https://api.chatlio.com/v1/p/widget", {
  179. onerror: function() {
  180. if (h) {
  181. var t = JSON.parse(h);
  182. t.connecting = !0, c = e.render(e.createElement(M, {
  183. meta: t
  184. }), l), h = JSON.stringify(t)
  185. }
  186. n > 0 ? n-- : (n = 10, J())
  187. },
  188. onload: function() {
  189. if (u && h !== this.responseText) {
  190. var t = JSON.parse(this.responseText);
  191. c = e.render(e.createElement(M, {
  192. meta: t
  193. }), l), h = this.responseText
  194. }
  195. }
  196. })
  197. },
  198. p = function() {
  199. m = window.PUBNUB.init({
  200. publish_key: "pub-c-0418c578-b424-498d-9b84-c40cc7221f21",
  201. subscribe_key: "sub-c-949c612e-a676-11e4-ae3a-02ee2ddab7fe",
  202. ssl: !0
  203. })
  204. },
  205. g = function(e) {
  206. void 0 === m && p(), m.subscribe({
  207. channel: s,
  208. message: e,
  209. error: function(e) {
  210. console.error("Cannot connect to Pubnub. Please try again in a while. Error: ", e), J()
  211. }
  212. })
  213. },
  214. E = function(e) {
  215. void 0 === m && p(), m.publish({
  216. channel: "widget_inbound",
  217. message: {
  218. ceUuid: a,
  219. fromVisitor: s,
  220. currentPage: window.location.href,
  221. message: e
  222. }
  223. })
  224. };
  225. W(), d();
  226. var b = /:simple_smile:/gim,
  227. N = /:smile:/gim,
  228. C = /:wink:/gim,
  229. S = /:disappointed:/gim,
  230. D = /:confused:/gim,
  231. M = e.createClass({
  232. displayName: "WidgetContainer",
  233. getInitialState: function() {
  234. var e, t = localStorage.getItem(o);
  235. e = JSON.parse(t) || [], e.length > 0 && g(this.onMessage);
  236. var a = JSON.parse(localStorage.getItem(r) || !0);
  237. return {
  238. isFirstMsg: !0,
  239. messages: e,
  240. widgetClosed: a,
  241. uuid: s
  242. }
  243. },
  244. widgetViewState: function() {
  245. return i.embedInline ? "" : this.state.widgetClosed ? "closed" : ""
  246. },
  247. toggleWidget: function(e) {
  248. this.setState({
  249. widgetClosed: !this.state.widgetClosed
  250. }), e.stopPropagation()
  251. },
  252. parseBody: function(e) {
  253. return e.replace(/(<(#C|@U|!).*?>)/gm, "").replace(b, ":)").replace(N, ":D").replace(C, ";)").replace(S, ":(").replace(D, ":/").replace(/<(.*?)>/gm, function(e, t) {
  254. var a = t.split("|"),
  255. s = '<a target="_blank" href="' + a[0] + '">' + (a[1] || a[0]) + "</a>";
  256. return s
  257. })
  258. },
  259. componentDidMount: function() {
  260. if (window._chatlio_pre_load) {
  261. for (var e = 0; e < _chatlio.length; e++) "identify" === _chatlio[e][0] ? window._chatlio.identify(_chatlio[e][1], _chatlio[e][2]) : "track" === _chatlio[e][0];
  262. delete window._chatlio_pre_load
  263. }
  264. },
  265. componentWillUnmount: function() {
  266. if (localStorage.setItem(r, JSON.stringify(this.state.widgetClosed)), this.state.messages.length > 0) {
  267. for (var e = Date.now() - v, t = this.state.messages.length, a = t - 1; a >= 0 && a >= t - w && !(this.state.messages[a].message.timestamp <= e); a--);
  268. var s = this.state.messages.slice(a + 1, t);
  269. localStorage.setItem(o, JSON.stringify(s))
  270. }
  271. },
  272. sendMessage: function(e) {
  273. if (13 === e.keyCode) {
  274. if (e.shiftKey) return !1;
  275. var a = e.currentTarget.value.trim();
  276. if ("" === a) return !1;
  277. this.state.isFirstMsg && (this.setState({
  278. isFirstMsg: !1
  279. }), g(this.onMessage)), e.currentTarget.value = "", E(a), this.state.messages.push({
  280. message: {
  281. Body: t(a),
  282. Author: "Me",
  283. timestamp: Date.now()
  284. },
  285. "class": "message from-me"
  286. }), this.setState({
  287. messages: this.state.messages
  288. }), this.clientAlive()
  289. }
  290. },
  291. clientAlive: q(function() {
  292. F("https://api.chatlio.com/v1/p/conversation/alive", {
  293. onerror: function() {
  294. console.warn("Alive check failed.")
  295. }
  296. })
  297. }, 2e3, this),
  298. onMessage: function(e) {
  299. e.Body.indexOf('{"system":') > -1 ? this.clientAlive() : (y.play(), e.Body = this.parseBody(e.Body), e.timestamp = Date.now(), this.setState({
  300. widgetClosed: !1,
  301. messages: this.state.messages.concat({
  302. message: e,
  303. "class": "message from-them"
  304. })
  305. }))
  306. },
  307. render: function() {
  308. return e.createElement(T, {
  309. metaData: this.props.meta,
  310. messages: this.state.messages,
  311. toggleWidget: this.toggleWidget,
  312. widgetViewState: this.widgetViewState(),
  313. keyup: this.sendMessage
  314. })
  315. }
  316. }),
  317. T = e.createClass({
  318. displayName: "ChatWidget",
  319. render: function() {
  320. if (!this.props.metaData) return null;
  321. var t = !1;
  322. if (this.props.metaData.off || "online" !== this.props.metaData.status) {
  323. if (this.props.metaData.hideWhenOffline) return null;
  324. t = !0
  325. }
  326. var a = {
  327. backgroundColor: this.props.metaData.titleColor
  328. },
  329. s = {
  330. color: this.props.metaData.titleFontColor
  331. },
  332. n = this.props.metaData.onlineTitle,
  333. o = "chatlio-widget " + this.props.widgetViewState;
  334. if (i.embedInline === !0) {
  335. o += " embed-inline", n = this.props.metaData.RoomName + " - " + n;
  336. var r = document.getElementById("chatlio-widget");
  337. r.className = r.className + " embed-inline-container"
  338. }
  339. return e.createElement("div", {
  340. className: o
  341. }, e.createElement("div", {
  342. className: "title-bar",
  343. style: a,
  344. onClick: this.props.toggleWidget
  345. }, e.createElement("span", {
  346. className: t ? "hide" : ""
  347. }, e.createElement("img", {
  348. src: "https://w.chatlio.com/images/live-chat-online.0c731865.png",
  349. className: "online-dot"
  350. })), e.createElement("span", {
  351. className: "title-text"
  352. }, e.createElement("a", {
  353. style: s,
  354. onClick: this.props.toggleWidget
  355. }, t ? this.props.metaData.offlineTitle : n)), e.createElement("span", {
  356. className: "controls " + this.props.widgetViewState
  357. })), t ? e.createElement(O, {
  358. keyup: this.props.keyup,
  359. messages: this.props.messages,
  360. widgetViewState: this.props.widgetViewState,
  361. metaData: this.props.metaData
  362. }) : e.createElement(k, {
  363. keyup: this.props.keyup,
  364. messages: this.props.messages,
  365. widgetViewState: this.props.widgetViewState,
  366. metaData: this.props.metaData
  367. }))
  368. }
  369. }),
  370. k = e.createClass({
  371. displayName: "ChatWidgetOnline",
  372. render: function() {
  373. var t = this.props.metaData.connecting;
  374. return e.createElement("div", {
  375. className: "chatlio-widget-body " + this.props.widgetViewState
  376. }, e.createElement(B, {
  377. messages: this.props.messages,
  378. metaData: this.props.metaData
  379. }), e.createElement("div", {
  380. className: "new-message-container"
  381. }, t ? e.createElement("textarea", {
  382. rows: "3",
  383. className: "new-message connecting",
  384. disabled: "true",
  385. placeholder: "Connecting to Chatlio. Please wait..."
  386. }) : e.createElement("textarea", {
  387. rows: "3",
  388. ref: "newMessage",
  389. onKeyUp: this.props.keyup,
  390. className: "new-message",
  391. placeholder: this.props.metaData.onlineMessagePlaceholder
  392. }), e.createElement("span", {
  393. className: "powered-by"
  394. }, e.createElement("a", {
  395. href: "https://chatlio.com"
  396. }, "live chat"), " powered by ", e.createElement("a", {
  397. href: "https://chatlio.com"
  398. }, "chatlio"))))
  399. }
  400. }),
  401. O = e.createClass({
  402. displayName: "ChatWidgetOffline",
  403. getInitialState: function() {
  404. return {
  405. email: "",
  406. message: ""
  407. }
  408. },
  409. handleChange: function(e) {
  410. var t = {};
  411. t[e.target.name] = e.target.value, this.state.email.length > 0 && this.setState({
  412. emailError: !1
  413. }), this.state.message.length > 0 && this.setState({
  414. messageError: !1
  415. }), this.setState(t)
  416. },
  417. sendOfflineMsg: function() {
  418. this.setState({
  419. emailError: !1,
  420. messageError: !1
  421. }), this.state.email.length < 1 && this.setState({
  422. emailError: !0
  423. }), this.state.message.length < 1 && this.setState({
  424. messageError: !0
  425. }), this.state.email.length < 1 || this.state.message.length < 1 || (this.setState({
  426. offlineMessageSent: !0
  427. }), E(["New Chatlio offline message:", this.state.name, this.state.email, this.state.message].join("\n")))
  428. },
  429. render: function() {
  430. return e.createElement("div", {
  431. className: "chatlio-widget-body " + this.props.widgetViewState
  432. }, e.createElement("div", null, this.state.offlineMessageSent ? e.createElement("div", {
  433. className: "offline-message-container-sent"
  434. }, e.createElement("div", null, this.props.metaData.offlineThankYouMessage)) : e.createElement("div", {
  435. className: "offline-message-container"
  436. }, e.createElement("p", {
  437. className: "missed-you-message"
  438. }, this.props.metaData.offlineGreeting), e.createElement("input", {
  439. type: "text",
  440. name: "email",
  441. onChange: this.handleChange,
  442. className: this.state.emailError ? "error" : "",
  443. placeholder: this.props.metaData.offlineEmailPlaceholder
  444. }), e.createElement("textarea", {
  445. name: "message",
  446. className: this.state.messageError ? "error" : "",
  447. rows: "6",
  448. onChange: this.handleChange,
  449. placeholder: this.props.metaData.offlineMessagePlaceholder
  450. }), e.createElement("input", {
  451. type: "text",
  452. name: "name",
  453. onChange: this.handleChange,
  454. className: "",
  455. placeholder: this.props.metaData.offlineNamePlaceholder
  456. }), e.createElement("button", {
  457. className: "btn",
  458. onClick: this.sendOfflineMsg
  459. }, this.props.metaData.offlineSendButton), e.createElement("span", {
  460. className: "powered-by"
  461. }, e.createElement("a", {
  462. href: "https://chatlio.com"
  463. }, "live chat"), " powered by ", e.createElement("a", {
  464. href: "https://chatlio.com"
  465. }, "chatlio")))))
  466. }
  467. }),
  468. B = e.createClass({
  469. displayName: "ChatMessages",
  470. scrollToBottom: function(e) {
  471. e.scrollTop = e.scrollHeight
  472. },
  473. componentDidMount: function() {
  474. this.scrollToBottom(this.getDOMNode())
  475. },
  476. componentDidUpdate: function() {
  477. this.scrollToBottom(this.getDOMNode())
  478. },
  479. render: function() {
  480. return e.createElement("div", {
  481. id: "chatlio-message-container",
  482. className: "message-container"
  483. }, e.createElement("span", null, e.createElement(x, {
  484. message: {
  485. message: {
  486. Body: this.props.metaData.autoResponseMessage,
  487. Author: this.props.metaData.agentLabel
  488. },
  489. "class": "message from-them"
  490. }
  491. }), e.createElement("div", {
  492. className: "clear"
  493. })), this.props.messages.map(function(t, a) {
  494. return e.createElement("span", {
  495. key: a
  496. }, e.createElement(x, {
  497. message: t
  498. }), e.createElement("div", {
  499. className: "clear"
  500. }))
  501. }))
  502. }
  503. }),
  504. x = e.createClass({
  505. displayName: "ChatMessage",
  506. render: function() {
  507. var t, a = this.props.message.message.Author; - 1 !== this.props.message["class"].indexOf("from-them") && (t = e.createElement("img", {
  508. height: "12",
  509. src: "https://s3-us-west-2.amazonaws.com/static.chatlio.com/avatar-black.png"
  510. }));
  511. var s = this.props.message.message.Body.replace(/\n/gm, "\n<br/>");
  512. return e.createElement("div", {
  513. key: this.props.key,
  514. className: this.props.message["class"]
  515. }, e.createElement("div", {
  516. className: "message-author"
  517. }, t, " ", a), e.createElement("div", {
  518. className: "message-timestamp"
  519. }, _(this.props.message.message.timestamp)), e.createElement("div", {
  520. className: "clear"
  521. }), e.createElement("span", {
  522. className: "message-body",
  523. dangerouslySetInnerHTML: {
  524. __html: s
  525. }
  526. }))
  527. }
  528. });
  529. window.onbeforeunload = J
  530. }
  531. }();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement