var robin = (function () { return {}; })(); robin.constants = (function () { return { presence: { online: 'online', offline: 'offline', serviceHours: 'servicehours' }, url: { chatSendMessage: 'Chat/SendMessage', chatSendAttachment: 'Chat/SendAttachment', getMissingMessages: 'Chat/GetMissingMessages', setCartContents: 'ViewedProducts/SetCartContents', addViewedProducts: 'ViewedProducts/AddViewedProducts', relationIsTyping: 'Chat/RelationIsTyping', relationStopsTyping: 'Chat/RelationStopsTyping', getAttachment: 'Attachment', getAttachmentThumbnail: 'Attachment/Thumbnail' }, event: { init: 'init', setContext: 'setContext', setCustomCss: 'setCustomCss', resizeFrame: 'resizeFrame', navigateTo: 'navigateTo', inputFocus: 'inputFocus', hideConversation: 'hideConversation', maxIframeHeightReached: 'maxIframeHeightReached', maxIframeHeightNotReached: 'maxIframeHeightNotReached', setCartContents: 'setCartContents', addViewedProducts: 'addViewedProducts', resetViewedProducts: 'resetViewedProducts', initViewedProducts: 'initViewedProducts', tabClicked: 'tabClicked', activateConversationMode: 'activateConversationMode', showProActiveChatPopup: 'showProActiveChatPopup', hideProActiveChatPopup: 'hideProActiveChatPopup', stopProActiveChat: 'stopProActiveChat', conversationStarted: 'conversationStarted' }, topic: { init: 'topic.init', storeMessage: 'topic.storeMessage', textAreaHeightChanged: 'topic.textAreaHeightChanged', maxIframeHeightReached: 'topic.maxIframeHeightReached', repositionCloseButton: 'topic.repositionCloseButton', setCartContents: 'topic.setCartContents', addViewedProducts: 'topic.addViewedProducts', setFocus: 'topic.setFocus', resizeFrame: 'topic.resizeFrame', inputFocus: 'topic.inputFocus', attachmentThumbnailLoaded: 'topic.attachmentThumbnailLoaded', userIsTyping: 'userIsTyping', userStoppedTyping: 'userStoppedTyping', showUserTyping: 'showUserTyping', hideUserTyping: 'hideUserTyping', showChat: 'showChat', showProActiveChatPopup: 'showProActiveChatPopup', hideProActiveChatPopup: 'hideProActiveChatPopup', startProActiveChatChat: 'startProActiveChatChat' }, realtime: { messageAdded: 'realtimeMessageAdded' }, bubbleType: { agent: 1, shopper: 2, initial: 3 }, mode: { conversation: 1, proActiveChat: 2 }, classNames: { shopperBubbleClassName: 'shopper', agentBubbleClassName: 'agent', initialBubbleClassName: 'initial', fixedCloseButtonClassName: 'fixed', closeButtonClassName: 'normal', maxHeightClassName: 'max-height', focusClassName: 'focus', phoneClassName: 'phone', mobileClassName: 'mobile', proActiveChatYesClassName: 'yes', proActiveChatNoClassName: 'no' }, storage: { lastPopupTime: 'rbn_last_popup_time', // use same name as 'old' widget, so navigating between them handles this correctly numberOfPopups: 'rbn_number_of_popups', // use same name as 'old' widget, so navigating between them handles this correctly popupsShown: 'rbn_journey_popups', // use same name as 'old' widget, so navigating between them handles this correctly journeyStopped: 'rbn_journey_stopped', // use same name as 'old' widget, so navigating between them handles this correctly guid: 'conversationguid', widgetActive: 'rbn_widgetActive', conversationStarted: 'rbn_conversationStarted', cart: 'rbn_cart_api', viewedProducts: 'rbn_viewedProducts_api' }, viewedProductType: { product: 'product', time: 'time' }, proActiveChat: { popupTypeEngagement: 1, popupTypeExitGrabber: 2, popupLayoutText: 1, popupLayoutActions: 2, popupLayoutInput: 3, popupLayoutTextClass: 'text', popupLayoutActionsClass: 'actions', popupLayoutInputClass: 'input', buttonTypeChat: 1, buttonTypeClose: 2, buttonTypeUrl: 3, transitionDelayInMs: 2000 }, cosmetics: { initialTextAreaHeight: 40, brandingHeight: 18, initialConversationHeight: 95, additionalConversationBottom: 19, additionalConversationHeight: -10, additionalConversationBottomMobile: 9, additionalConversationHeightMobile: 17, additionalCloseButtonBottomMobile: -10, additionalBubblesHeight: 26, additionalBubbleHeight: 4, additionalProActiveChatBottom: 93, additionalProActiveChatBottomMobile: 81, closeButtonHeight: 21 }, proActivechatActionPositionLeft: 'left', proActivechatActionPositionRight: 'right' }; })(); robin.shared = (function () { var extend = function (destination, source) { for (var property in source) { if (destination[property] === undefined) { destination[property] = source[property]; } } }; var _removeEmptyArrayItems = function (array) { for (var i = array.length - 1; i >= 0; i--) { if (array[i] == '') { array.splice(i, 1); } } }; var _getUrlObject = function (url) { var parser = document.createElement('a'); parser.href = url; return parser; }; var urlFitsReferrer = function (url, referrer) { if (url.indexOf('@') >= 0) { return false; } if (url.indexOf('http://') != 0 && url.indexOf('https://') != 0) { url = 'http://' + url; } var urlLocation = _getUrlObject(url); var referrerLocation = _getUrlObject(referrer); var urlSegments = urlLocation.pathname.split('/'); var referrerSegments = referrerLocation.pathname.split('/'); if (urlLocation.search.length > 0) { urlSegments[urlSegments.length] = urlLocation.search; } if (referrerLocation.search.length > 0) { referrerSegments[referrerSegments.length] = referrerLocation.search; } if (referrerLocation.host.indexOf(urlLocation.host, referrerLocation.host.length - urlLocation.host.length) === -1) return false; if (referrerSegments.length < urlSegments.length) return false; _removeEmptyArrayItems(urlSegments); _removeEmptyArrayItems(referrerSegments); for (var i = 0; i < urlSegments.length; i++) { var referrerSegment = referrerSegments[i]; if (referrerSegment == undefined) return false; var segment = urlSegments[i]; if (referrerSegment.indexOf('/', referrerSegment.length - 1) === -1) referrerSegment += '/'; if (segment.indexOf('/', segment.length - 1) === -1) segment += '/'; if (segment !== referrerSegment) return false; } return true; }; var determineWebStoreBasedOnReferrer = function (referrer, webStores) { //First try to find an exact match for (var i = 0; i < webStores.length; i++) { for (var j = 0; j < webStores[i].referrers.length; j++) { if (referrer === webStores[i].referrers[j]) { return webStores[i]; } } } // Then try to find the longest (=best) domain match var webStore = null; var url = ''; for (var i = 0; i < webStores.length; i++) { for (var j = 0; j < webStores[i].referrers.length; j++) { if (urlFitsReferrer(webStores[i].referrers[j], referrer)) { if (webStores[i].referrers[j].length > url.length) { webStore = webStores[i]; url = webStores[i].referrers[j]; } } } } if (webStore != null) { return webStore; } // Then the default webstore for (var i = 0; i < webStores.length; i++) { webStore = webStores[i]; if (webStore.defaultStore) { return webStore; } } return { contactTabTemplate: { tabStyle: 'icon-tab', mobileTabStyle: null } }; }; var isInternetExplorer9OrLower = function (userAgent) { if (userAgent === undefined) { userAgent = navigator.userAgent; } if (/MSIE (\d+\.\d+);/.test(userAgent)) { var ieversion = new Number(RegExp.$1); if (ieversion <= 9) { return true; } } return false; }; var isPhoneBrowser = function (userAgent) { if (userAgent === undefined) { userAgent = navigator.userAgent; } if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(userAgent.substr(0, 4))) { return true; } else { return false; } }; var isMobileBrowser = function (userAgent) { if (userAgent === undefined) { userAgent = navigator.userAgent; } if (userAgent.match(/Android/i) || userAgent.match(/webOS/i) || userAgent.match(/iPhone/i) || userAgent.match(/iPad/i) || userAgent.match(/iPod/i) || userAgent.match(/BlackBerry/i) || userAgent.match(/Windows Phone/i) ) { return true; } else { // return true; return false; } }; var isIphoneBrowser = function (userAgent) { if (userAgent === undefined) { userAgent = navigator.userAgent; } if (/ip(hone|od)/i.test(userAgent) ) { return true; } else { return false; } }; var isIosBrowser = function (userAgent) { if (userAgent === undefined) { userAgent = navigator.userAgent; } if (/iPad|iPhone|iPod/.test(userAgent)) { return true; } else { return false; } }; var createGuid = function () { var S4 = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); }; return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase(); }; var getCurrentDateTimeSinceEpoch = function () { var d = new Date(); return d.getTime(); }; var getSessionData = function (name) { var value = window.sessionStorage.getItem(name); if (value == null) return ''; return value; }; var setSessionData = function (name, value) { window.sessionStorage.setItem(name, value); }; var navigateTo = function(url) { window.location.href = url; }; var getTime = function() { return new Date().getTime(); }; var getFormattedUrl = function(apikey, url) { return '/' + apikey + '/' + url; } return { determineWebStoreBasedOnReferrer: determineWebStoreBasedOnReferrer, isInternetExplorer9OrLower: isInternetExplorer9OrLower, isPhoneBrowser: isPhoneBrowser, isIphoneBrowser: isIphoneBrowser, isIosBrowser: isIosBrowser, isMobileBrowser: isMobileBrowser, extend: extend, urlFitsReferrer: urlFitsReferrer, createGuid: createGuid, getCurrentDateTimeSinceEpoch: getCurrentDateTimeSinceEpoch, getSessionData: getSessionData, setSessionData: setSessionData, navigateTo: navigateTo, getTime: getTime, getFormattedUrl: getFormattedUrl }; })(); robin.api = (function () { var setCartContents = function (cart) { if (cart === undefined) { cart = robin.shared.getSessionData(robin.constants.storage.cart); if (cart === '') { cart = []; } else { cart = JSON.parse(cart); } } else { robin.shared.setSessionData(robin.constants.storage.cart, JSON.stringify(cart)); } robin.tab.sendMessage(robin.constants.event.setCartContents, cart); }; var addViewedProduct = function (viewedProduct, conversationStarted) { var viewedProducts = robin.shared.getSessionData(robin.constants.storage.viewedProducts); if (viewedProducts === '') { viewedProducts = []; } else { viewedProducts = JSON.parse(viewedProducts); } var first = true; if (viewedProduct !== undefined) { first = false; viewedProducts.push({ type: robin.constants.viewedProductType.time, time: robin.shared.getTime() }); viewedProduct.type = robin.constants.viewedProductType.product; viewedProducts.push(viewedProduct); robin.shared.setSessionData(robin.constants.storage.viewedProducts, JSON.stringify(viewedProducts)); } else { first = !conversationStarted; } robin.tab.sendMessage(robin.constants.event.addViewedProducts, {viewedProducts: viewedProducts, first: first }); }; var _onMessage = function(e) { var event = e.data.event; var data = e.data.data; switch (event) { case robin.constants.event.resetViewedProducts: robin.shared.setSessionData(robin.constants.storage.viewedProducts, ''); break; case robin.constants.event.initViewedProducts: robin.api.setCartContents(); robin.api.addViewedProduct(undefined, data); break; } }; var init = function() { window.addEventListener('message', function (e) { _onMessage(e); }); }; return { addViewedProduct: addViewedProduct, setCartContents: setCartContents, init: init }; })(); window.__robin = robin.api; robin.api.init(); var script = document.createElement("script"); script.src = 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js'; script.type = 'text/javascript'; script.onload = function () { var robinJQuery = $.noConflict(true); (function ($, jQuery) { window._$ = window.$; window.$ = $; window._jQuery = window.jQuery; window.jQuery = jQuery; $.loadScript = function (src) { var def = $.Deferred(); var script = document.createElement('script'); script.src = src; script.onload = function () { def.resolve(); } script.onerror = function () { def.reject(); } document.body.appendChild(script); return def.promise(); }; $.getMultiScripts = function (arr) { var _arr = $.map(arr, function (src) { return $.loadScript(src); }); _arr.push($.Deferred(function (deferred) { $(deferred.resolve); })); return $.when.apply($, _arr); }; $.loadCSS = function (href) { var cssLink = $(""); $("head").append(cssLink); //IE hack: append before setting href cssLink.attr({ rel: "stylesheet", type: "text/css", href: href }); }; robin.tab = (function () { var baseUrl; var webStore; var agent; var frameSelector = '.'; var frameClassName = 'robin_frame'; var tabSelector = '.'; var tabClassName = 'robin_tab'; var hasProActiveChat = false; var init = function () { baseUrl = robin_settings.newWidgetBaseUrl; webStore = robin.shared.determineWebStoreBasedOnReferrer(window.location.href, robin_settings.webStores); $('body').append(_getTabContainerHtml()); if (webStore.conversationTemplate.customStylesheetUrl !== undefined && webStore.conversationTemplate.customStylesheetUrl !== null) { $.loadCSS(webStore.conversationTemplate.customStylesheetUrl); } window._$ = window.$; window.$ = $; window._jQuery = window.jQuery; window.jQuery = jQuery; var scripts = []; if (robin_settings.features.viewedProducts) { scripts.push(robin_settings.newWidgetBaseUrl + '/scripts/lib/robin.nosto.js'); } $.getMultiScripts(scripts).done(function () { window.$ = window._$; window.jQuery = window._jQuery; $(tabSelector + tabClassName).click(function () { robin.proActiveChat.cancel(true); robin.shared.setSessionData(robin.constants.storage.widgetActive, 'true'); _loadIframe(true, function() { sendMessage(robin.constants.event.activateConversationMode, true); sendMessage(robin.constants.event.tabClicked, {}); }); }); var conversationStarted = robin.shared.getSessionData(robin.constants.storage.conversationStarted); var widgetActive = false; var active = robin.shared.getSessionData(robin.constants.storage.widgetActive); if (active !== '') { widgetActive = JSON.parse(active); _loadIframe(widgetActive, function () { sendMessage(robin.constants.event.activateConversationMode, widgetActive); }); } if (conversationStarted === '') { _initProActiveChat(!widgetActive); } }).fail(function (jqxhr, textStatus, error) { var err = textStatus + ", " + error; console.error("Error loading script(s): " + err); }); }; _initProActiveChat = function(startEngine) { if (robin_settings.features.proActiveChat) { if (robin.presence.webStoreIsOnline(webStore) && webStore.proActiveChatTemplate !== null && webStore.proActiveChatTemplate !== undefined) { // TODO - Determine whether iframe can be loaded delayed, // what are the benefits of both strategies, // create unittest accordingly hasProActiveChat = true; _loadIframe(false); robin.proActiveChat.initialize(window.location.href, webStore.proActiveChatTemplate, _proActiveChatInitiator(), startEngine); } } }; _getTabContainerHtml = function () { var additionalClasses = ''; if (_usePhoneSettings()) { additionalClasses += 'phone'; } additionalClasses += ' ' + _getTabPosition(); additionalClasses += ' ' + _getOnlineClassName(); agent = null; if (_getTabPersonalAvatar()) { agent = robin.presence.getRandomOnlineUser(webStore); if (agent != null) { var personalAvatar = agent ? agent.avatar128 : '#'; additionalClasses += ' personal'; } } _loadThemeStyleSheet(_getTabTheme()); return '
' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '