Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- ! function() {
- function e(e) {
- return E[e]
- }
- function t(t) {
- return t && t.length > 0 ? t.replace(b, e) : void 0
- }
- 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"],
- p = "w.chatlio",
- u = !1,
- g = "https://w.chatlio.com/main.442f6971.css",
- f = 2e4,
- w = 20,
- v = 1728e5,
- y = new Audio("https://w.chatlio.com/media/water-drips-single16.a1857954.mp3");
- y.volume = .8;
- for (var E = {
- "&": "&",
- ">": ">",
- "<": "<",
- '"': """,
- "'": "'",
- "`": "'"
- }, b = /[&><"'`]/g, N = document.getElementsByTagName("script"), C = "", S = 0; S < N.length; S++) {
- var D = N[S].src;
- if (D && D.indexOf(p) > 0) {
- C = N[S], l = document.createElement("div"), l.id = "chatlio-widget";
- var M = document.getElementById("chatlioWidgetPlaceholder");
- 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;
- try {
- i = JSON.parse(C.getAttribute("data-widget-options")) || {}
- } catch (T) {
- i = {}
- }
- }
- }
- var _ = function(e) {
- var t = Math.floor((new Date - e) / 1e3);
- if (60 > t) return "just now";
- var a = Math.floor(t / 31536e3);
- 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" : ""))))
- },
- k = function(e, t) {
- var a = document.createElement("script");
- a.setAttribute("type", "text/javascript"), a.setAttribute("src", e), a.onload = t, (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(a)
- },
- O = function() {
- if (U() && i.skipRequireLoad !== !0) require(d, function(e) {
- R(e)
- });
- else {
- var e = 0,
- t = function() {
- e++, e === d.length && R(React)
- };
- d.forEach(function(e) {
- k(e, t)
- })
- }
- },
- B = function(e) {
- var a = document.createElement("link");
- a.setAttribute("type", "text/css"), a.setAttribute("rel", "stylesheet"), a.setAttribute("href", t(e)), (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(a)
- },
- x = function(e, t, a) {
- var s = new Date;
- s.setTime(s.getTime() + 24 * a * 60 * 60 * 1e3);
- var n = "expires=" + s.toGMTString();
- document.cookie = e + "=" + t + "; " + n
- },
- A = function(e) {
- for (var t = e + "=", a = document.cookie.split(";"), s = 0; s < a.length; s++) {
- var n = a[s];
- if (-1 !== n.indexOf(t)) {
- for (;
- " " === n.charAt(0);) n = n.substring(1);
- return n.substring(t.length, n.length)
- }
- }
- return ""
- },
- I = function() {
- function e() {
- return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1)
- }
- return function() {
- return e() + e() + "-" + e() + "-" + e() + "-" + e() + "-" + e() + e() + e()
- }
- }(),
- P = function() {
- var e = A(n);
- return "" === e && (e = I(), x(n, e, 365)), e
- },
- U = function() {
- return "undefined" != typeof window.define && "undefined" !== window.require
- },
- W = function() {
- window._chatlio_pre_load = window._chatlio, window._chatlio = window._chatlio || [];
- var e = 5;
- window._chatlio.identify = function(t, n) {
- Object.keys(n).forEach(function(e) {
- n[e] = String(n[e])
- }), F("https://api.chatlio.com/v1/p/visitor/identify", {
- data: "vsUuid=" + s + "&ceUuid=" + a + "&userId=" + encodeURIComponent(t) + "&traits=" + encodeURIComponent(JSON.stringify(n)),
- onerror: function() {
- e > 0 ? (setTimeout(function() {
- window._chatlio.identify(t, n)
- }, 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)
- }
- })
- }
- },
- V = 5,
- R = function(e) {
- F("https://api.chatlio.com/v1/p/visitor/new", {
- timeout: 2999,
- onload: function() {
- G(e), u = !0
- },
- onerror: function() {
- 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())
- }
- })
- },
- J = function() {
- m && (m.unsubscribe({
- channel: s
- }), m = void 0), c && c.isMounted() && React.unmountComponentAtNode(l), h = void 0
- },
- q = function(e, t, a) {
- t = t || 1250;
- var s, n;
- return function() {
- var i = a || this,
- o = Date.now(),
- r = arguments;
- s && s + t > o ? (clearTimeout(n), n = setTimeout(function() {
- s = o, e.apply(i, r)
- }, t)) : (s = o, e.apply(i, r))
- }
- },
- j = function(e) {
- var t = new XMLHttpRequest;
- if ("withCredentials" in t) t.open("GET", e, !0);
- else {
- if ("undefined" == typeof XDomainRequest) throw new Error("Your browser does not support CORS. Please contact chatlio support at support@chatlio.com");
- t = new XDomainRequest, t.open("GET", e)
- }
- return t
- },
- F = function(e, t) {
- var n = t.data || "vsUuid=" + s + "&ceUuid=" + a,
- i = j(e + "?" + n);
- return i.onload = function() {
- if ("withCredentials" in i) 200 === i.status ? t.onload && t.onload.apply(i, arguments) : t.onerror.apply(i, arguments);
- else {
- var e;
- try {
- e = JSON.parse(this.responseText) || {}
- } catch (a) {
- e = {}
- }!e.status || "200" !== e.status && "online" !== e.status ? t.onerror.apply(i, arguments) : t.onload && t.onload.apply(i, arguments)
- }
- }, i.onerror = function() {
- t.onerror.apply(i, arguments)
- }, t.timeout > 0 && (i.timeout = t.timeout, i.ontimeout = t.ontimeout ? function() {
- t.ontimeout.apply(i, arguments)
- } : function() {
- t.onerror.apply(i, arguments)
- }), i.send(), i
- };
- s = P(), o = "chatlio-" + s + "-messages", r = "chatlio-" + s + "-isClosed", B(g), O();
- var G = function(e) {
- var n = 10,
- d = function() {
- setTimeout(d, f), F("https://api.chatlio.com/v1/p/widget", {
- onerror: function() {
- if (h) {
- var t = JSON.parse(h);
- t.connecting = !0, c = e.render(e.createElement(M, {
- meta: t
- }), l), h = JSON.stringify(t)
- }
- n > 0 ? n-- : (n = 10, J())
- },
- onload: function() {
- if (u && h !== this.responseText) {
- var t = JSON.parse(this.responseText);
- c = e.render(e.createElement(M, {
- meta: t
- }), l), h = this.responseText
- }
- }
- })
- },
- p = function() {
- m = window.PUBNUB.init({
- publish_key: "pub-c-0418c578-b424-498d-9b84-c40cc7221f21",
- subscribe_key: "sub-c-949c612e-a676-11e4-ae3a-02ee2ddab7fe",
- ssl: !0
- })
- },
- g = function(e) {
- void 0 === m && p(), m.subscribe({
- channel: s,
- message: e,
- error: function(e) {
- console.error("Cannot connect to Pubnub. Please try again in a while. Error: ", e), J()
- }
- })
- },
- E = function(e) {
- void 0 === m && p(), m.publish({
- channel: "widget_inbound",
- message: {
- ceUuid: a,
- fromVisitor: s,
- currentPage: window.location.href,
- message: e
- }
- })
- };
- W(), d();
- var b = /:simple_smile:/gim,
- N = /:smile:/gim,
- C = /:wink:/gim,
- S = /:disappointed:/gim,
- D = /:confused:/gim,
- M = e.createClass({
- displayName: "WidgetContainer",
- getInitialState: function() {
- var e, t = localStorage.getItem(o);
- e = JSON.parse(t) || [], e.length > 0 && g(this.onMessage);
- var a = JSON.parse(localStorage.getItem(r) || !0);
- return {
- isFirstMsg: !0,
- messages: e,
- widgetClosed: a,
- uuid: s
- }
- },
- widgetViewState: function() {
- return i.embedInline ? "" : this.state.widgetClosed ? "closed" : ""
- },
- toggleWidget: function(e) {
- this.setState({
- widgetClosed: !this.state.widgetClosed
- }), e.stopPropagation()
- },
- parseBody: function(e) {
- return e.replace(/(<(#C|@U|!).*?>)/gm, "").replace(b, ":)").replace(N, ":D").replace(C, ";)").replace(S, ":(").replace(D, ":/").replace(/<(.*?)>/gm, function(e, t) {
- var a = t.split("|"),
- s = '<a target="_blank" href="' + a[0] + '">' + (a[1] || a[0]) + "</a>";
- return s
- })
- },
- componentDidMount: function() {
- if (window._chatlio_pre_load) {
- 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];
- delete window._chatlio_pre_load
- }
- },
- componentWillUnmount: function() {
- if (localStorage.setItem(r, JSON.stringify(this.state.widgetClosed)), this.state.messages.length > 0) {
- 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--);
- var s = this.state.messages.slice(a + 1, t);
- localStorage.setItem(o, JSON.stringify(s))
- }
- },
- sendMessage: function(e) {
- if (13 === e.keyCode) {
- if (e.shiftKey) return !1;
- var a = e.currentTarget.value.trim();
- if ("" === a) return !1;
- this.state.isFirstMsg && (this.setState({
- isFirstMsg: !1
- }), g(this.onMessage)), e.currentTarget.value = "", E(a), this.state.messages.push({
- message: {
- Body: t(a),
- Author: "Me",
- timestamp: Date.now()
- },
- "class": "message from-me"
- }), this.setState({
- messages: this.state.messages
- }), this.clientAlive()
- }
- },
- clientAlive: q(function() {
- F("https://api.chatlio.com/v1/p/conversation/alive", {
- onerror: function() {
- console.warn("Alive check failed.")
- }
- })
- }, 2e3, this),
- onMessage: function(e) {
- e.Body.indexOf('{"system":') > -1 ? this.clientAlive() : (y.play(), e.Body = this.parseBody(e.Body), e.timestamp = Date.now(), this.setState({
- widgetClosed: !1,
- messages: this.state.messages.concat({
- message: e,
- "class": "message from-them"
- })
- }))
- },
- render: function() {
- return e.createElement(T, {
- metaData: this.props.meta,
- messages: this.state.messages,
- toggleWidget: this.toggleWidget,
- widgetViewState: this.widgetViewState(),
- keyup: this.sendMessage
- })
- }
- }),
- T = e.createClass({
- displayName: "ChatWidget",
- render: function() {
- if (!this.props.metaData) return null;
- var t = !1;
- if (this.props.metaData.off || "online" !== this.props.metaData.status) {
- if (this.props.metaData.hideWhenOffline) return null;
- t = !0
- }
- var a = {
- backgroundColor: this.props.metaData.titleColor
- },
- s = {
- color: this.props.metaData.titleFontColor
- },
- n = this.props.metaData.onlineTitle,
- o = "chatlio-widget " + this.props.widgetViewState;
- if (i.embedInline === !0) {
- o += " embed-inline", n = this.props.metaData.RoomName + " - " + n;
- var r = document.getElementById("chatlio-widget");
- r.className = r.className + " embed-inline-container"
- }
- return e.createElement("div", {
- className: o
- }, e.createElement("div", {
- className: "title-bar",
- style: a,
- onClick: this.props.toggleWidget
- }, e.createElement("span", {
- className: t ? "hide" : ""
- }, e.createElement("img", {
- src: "https://w.chatlio.com/images/live-chat-online.0c731865.png",
- className: "online-dot"
- })), e.createElement("span", {
- className: "title-text"
- }, e.createElement("a", {
- style: s,
- onClick: this.props.toggleWidget
- }, t ? this.props.metaData.offlineTitle : n)), e.createElement("span", {
- className: "controls " + this.props.widgetViewState
- })), t ? e.createElement(O, {
- keyup: this.props.keyup,
- messages: this.props.messages,
- widgetViewState: this.props.widgetViewState,
- metaData: this.props.metaData
- }) : e.createElement(k, {
- keyup: this.props.keyup,
- messages: this.props.messages,
- widgetViewState: this.props.widgetViewState,
- metaData: this.props.metaData
- }))
- }
- }),
- k = e.createClass({
- displayName: "ChatWidgetOnline",
- render: function() {
- var t = this.props.metaData.connecting;
- return e.createElement("div", {
- className: "chatlio-widget-body " + this.props.widgetViewState
- }, e.createElement(B, {
- messages: this.props.messages,
- metaData: this.props.metaData
- }), e.createElement("div", {
- className: "new-message-container"
- }, t ? e.createElement("textarea", {
- rows: "3",
- className: "new-message connecting",
- disabled: "true",
- placeholder: "Connecting to Chatlio. Please wait..."
- }) : e.createElement("textarea", {
- rows: "3",
- ref: "newMessage",
- onKeyUp: this.props.keyup,
- className: "new-message",
- placeholder: this.props.metaData.onlineMessagePlaceholder
- }), e.createElement("span", {
- className: "powered-by"
- }, e.createElement("a", {
- href: "https://chatlio.com"
- }, "live chat"), " powered by ", e.createElement("a", {
- href: "https://chatlio.com"
- }, "chatlio"))))
- }
- }),
- O = e.createClass({
- displayName: "ChatWidgetOffline",
- getInitialState: function() {
- return {
- email: "",
- message: ""
- }
- },
- handleChange: function(e) {
- var t = {};
- t[e.target.name] = e.target.value, this.state.email.length > 0 && this.setState({
- emailError: !1
- }), this.state.message.length > 0 && this.setState({
- messageError: !1
- }), this.setState(t)
- },
- sendOfflineMsg: function() {
- this.setState({
- emailError: !1,
- messageError: !1
- }), this.state.email.length < 1 && this.setState({
- emailError: !0
- }), this.state.message.length < 1 && this.setState({
- messageError: !0
- }), this.state.email.length < 1 || this.state.message.length < 1 || (this.setState({
- offlineMessageSent: !0
- }), E(["New Chatlio offline message:", this.state.name, this.state.email, this.state.message].join("\n")))
- },
- render: function() {
- return e.createElement("div", {
- className: "chatlio-widget-body " + this.props.widgetViewState
- }, e.createElement("div", null, this.state.offlineMessageSent ? e.createElement("div", {
- className: "offline-message-container-sent"
- }, e.createElement("div", null, this.props.metaData.offlineThankYouMessage)) : e.createElement("div", {
- className: "offline-message-container"
- }, e.createElement("p", {
- className: "missed-you-message"
- }, this.props.metaData.offlineGreeting), e.createElement("input", {
- type: "text",
- name: "email",
- onChange: this.handleChange,
- className: this.state.emailError ? "error" : "",
- placeholder: this.props.metaData.offlineEmailPlaceholder
- }), e.createElement("textarea", {
- name: "message",
- className: this.state.messageError ? "error" : "",
- rows: "6",
- onChange: this.handleChange,
- placeholder: this.props.metaData.offlineMessagePlaceholder
- }), e.createElement("input", {
- type: "text",
- name: "name",
- onChange: this.handleChange,
- className: "",
- placeholder: this.props.metaData.offlineNamePlaceholder
- }), e.createElement("button", {
- className: "btn",
- onClick: this.sendOfflineMsg
- }, this.props.metaData.offlineSendButton), e.createElement("span", {
- className: "powered-by"
- }, e.createElement("a", {
- href: "https://chatlio.com"
- }, "live chat"), " powered by ", e.createElement("a", {
- href: "https://chatlio.com"
- }, "chatlio")))))
- }
- }),
- B = e.createClass({
- displayName: "ChatMessages",
- scrollToBottom: function(e) {
- e.scrollTop = e.scrollHeight
- },
- componentDidMount: function() {
- this.scrollToBottom(this.getDOMNode())
- },
- componentDidUpdate: function() {
- this.scrollToBottom(this.getDOMNode())
- },
- render: function() {
- return e.createElement("div", {
- id: "chatlio-message-container",
- className: "message-container"
- }, e.createElement("span", null, e.createElement(x, {
- message: {
- message: {
- Body: this.props.metaData.autoResponseMessage,
- Author: this.props.metaData.agentLabel
- },
- "class": "message from-them"
- }
- }), e.createElement("div", {
- className: "clear"
- })), this.props.messages.map(function(t, a) {
- return e.createElement("span", {
- key: a
- }, e.createElement(x, {
- message: t
- }), e.createElement("div", {
- className: "clear"
- }))
- }))
- }
- }),
- x = e.createClass({
- displayName: "ChatMessage",
- render: function() {
- var t, a = this.props.message.message.Author; - 1 !== this.props.message["class"].indexOf("from-them") && (t = e.createElement("img", {
- height: "12",
- src: "https://s3-us-west-2.amazonaws.com/static.chatlio.com/avatar-black.png"
- }));
- var s = this.props.message.message.Body.replace(/\n/gm, "\n<br/>");
- return e.createElement("div", {
- key: this.props.key,
- className: this.props.message["class"]
- }, e.createElement("div", {
- className: "message-author"
- }, t, " ", a), e.createElement("div", {
- className: "message-timestamp"
- }, _(this.props.message.message.timestamp)), e.createElement("div", {
- className: "clear"
- }), e.createElement("span", {
- className: "message-body",
- dangerouslySetInnerHTML: {
- __html: s
- }
- }))
- }
- });
- window.onbeforeunload = J
- }
- }();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement