/** Version 1.1 Log: Remove jquery dependency for client loader */ if (!croWD) { var croWD; (function(exports) { 'use strict'; function croWDxClient() {}; exports.croWDxClient = croWDxClient; var document = window.document; var isLocal = (window.location.host.indexOf('localhost') > -1 && window.location.port === '9999'); var loaderNow = new Date().getTime(); //window.performance polyfill if ('performance' in window == false) { window.performance = {}; } Date.now = (Date.now || function() { // thanks IE8 return new Date().getTime(); }); if ('now' in window.performance == false) { var nowOffset = Date.now(); if (performance.timing && performance.timing.navigationStart) { nowOffset = performance.timing.navigationStart } window.performance.now = function now() { return Date.now() - nowOffset; } } croWDxClient.prototype = { croWDUtils: { //currentScriptSrc: document.currentScript ? document.currentScript.src : 'https://www.vodafone.com.au/content/crowd/agents/', currentScriptSrc: 'https://www.vodafone.com.au/content/crowd/agents/', ulPermCookieName: 'ulPermCookieTrain', ulTempCookieName: 'ulTempCookieTrain', setULCookie: function(type, key, value) { var cookie, cookieTrain, expires; var path = '/'; var domain = '.vodafone.com.au'; var cookieName = type === 'perm' ? croWDxClient.prototype.croWDUtils.ulPermCookieName : croWDxClient.prototype.croWDUtils.ulTempCookieName; // if(croWDxClient.prototype.croWDUtils.getULCookie(type)){ // cookieTrain = JSON.parse(croWDxClient.prototype.croWDUtils.getULCookie(type)); // } // else{ // cookieTrain = {}; // }; // cookieTrain = croWDxClient.prototype.croWDUtils.getULCookie(type); cookieTrain[key] = value; cookie = cookieName + '=' + JSON.stringify(cookieTrain) + ';'; if (type === 'perm') { expires = new Date(new Date().getTime() + 1000 * 1000 * 60 * 60 * 24); //set expires to 1000 DAYS cookie += 'expires=' + expires.toGMTString() + ';'; } cookie += 'path=' + path + ';'; cookie += 'domain=' + domain + ';'; document.cookie = cookie; }, getULCookie: function(type) { var name = type === 'perm' ? croWDxClient.prototype.croWDUtils.ulPermCookieName + '=' : croWDxClient.prototype.croWDUtils.ulTempCookieName + '='; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return JSON.parse(c.substring(name.length, c.length)); } } return {}; }, removeULCookie: function(type, key) { var cookie, cookieTrain, expires; var path = '/'; var domain = '.vodafone.com.au'; var cookieName = type === 'perm' ? croWDxClient.prototype.croWDUtils.ulPermCookieName : croWDxClient.prototype.croWDUtils.ulTempCookieName; // if(croWDxClient.prototype.croWDUtils.getULCookie(type)){ // cookieTrain = JSON.parse(croWDxClient.prototype.croWDUtils.getULCookie(type)); // } // else{ // cookieTrain = {}; // }; cookieTrain = croWDxClient.prototype.croWDUtils.getULCookie(type); if (cookieTrain[key]) { delete cookieTrain[key]; cookie = cookieName + '=' + JSON.stringify(cookieTrain) + ';'; if (type === 'perm') { expires = new Date(new Date().getTime() + 1000 * 1000 * 60 * 60 * 24); //set expires to 1000 DAYS cookie += 'expires=' + expires.toGMTString() + ';'; } cookie += 'path=' + path + ';' + 'domain=' + domain + ';'; document.cookie = cookie; } }, findAngular: function(dom) { // return angular controller return angular.element(dom).scope(); // once get angular controller, apply function // hackyCtrlr = angular.element(dom).scope(); // hackyCtrlr.$apply(function () { // hackyCtrlr.showOrCollapseContacts() // hackyCtrlr.viewParams.isContactsCollapsed = false; // }) }, findReact: function(dom) { for (var key in dom) { if (key.startsWith('__reactInternalInstance$')) { var compInternals = dom[key]._currentElement; var compWrapper = compInternals._owner; var comp = compWrapper._instance; return comp; } } return null; }, setReactState: function(el, key, value) { croWDxClient.prototype.croWDUtils.findReact(el).setState({ key: value }); }, getReactProps: function(el, key) { return croWDxClient.prototype.croWDUtils.findReact(el)[key]; }, geoLocation: {}, getGeo: function() { if (!navigator.geolocation) { console.log('%cWarning: navigator.geolocation is NOT supported!', 'color: #f6a11a; font-style: italic; background-color: #f4fff7; padding: 2px'); } else { navigator.geolocation.getCurrentPosition(function(pos) { croWDxClient.prototype.croWDUtils.geoLocation = pos; }, function(err) { croWDxClient.prototype.croWDUtils.geoLocation = err; }, { // timeout: 5000, // maximumAge: 0, enableHighAccuracy: true } ); } }, campaignPath: function(aid) { var path = ''; if (aid) { path = croWDxClient.prototype.croWDUtils.currentScriptSrc.replace('/utils/loader-client.js', '/'); } else { path = croWDxClient.prototype.croWDUtils.currentScriptSrc.replace(/\/DCP[\S]*\/loader.js[\S]*/g, '/'); } if (isLocal) { path = '//' + window.location.host + '/agents/'; } //TODO: planner needs modification !!!!! // if(croWDxClient.prototype.croWDUtils.campaignOpts.planner.time !== undefined){ // if(loaderNow > new Date(croWDxClient.prototype.croWDUtils.campaignOpts.planner.time).getTime()){ // path = croWDxClient.prototype.croWDUtils.campaignOpts.planner.path; // } // } return path; }, getCurrentScriptParameter: function(key) { return new URL(croWDxClient.prototype.croWDUtils.currentScriptSrc).searchParams.get(key); }, tracking: function() {}, isLocalAssetsExist: function(campaignOpts) { var hasLocalIndex = localStorage.getItem('__' + campaignOpts.agentId + '_html') !== null; var validTimeStamp = loaderNow <= parseInt(localStorage.getItem('__' + campaignOpts.agentId + '_timestamp')); if (hasLocalIndex && validTimeStamp && campaignOpts.saveToLocal) { return true; } else { localStorage.removeItem('__' + campaignOpts.agentId + '_html'); localStorage.removeItem('__' + campaignOpts.agentId + '_timestamp'); return false; } }, isCampaignLoaded: function(campaignID) { var myCampaignID = document.querySelector('.' + campaignID); if (myCampaignID) { return true } }, appendScript: function(location, script, inlineScript, isAsync, aid) { isAsync = (isAsync !== undefined ? isAsync : false); var js = document.createElement('script'); js.type = 'text/javascript'; js.defer = isAsync; js.async = isAsync; if (script !== null) { js.src = script[1].indexOf('//') > -1 ? script[1] : croWDxClient.prototype.croWDUtils.campaignPath(aid) + aid + '/' + script[1]; } if (inlineScript !== null) { js.appendChild(document.createTextNode(inlineScript[1])); } location.appendChild(js); }, appendStyle: function(location, style, aid) { var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = style.indexOf('//') > -1 ? style : croWDxClient.prototype.croWDUtils.campaignPath(aid) + aid + '/' + style; document.querySelector('head').appendChild(link); }, filterScriptStyle: function(location, response, aid, campaignOpts) { var re = //gm; var script; var htmlText = response; while ((script = re.exec(response))) { var srcRe = /src=["|']([\s\S]*?)["|']/gm; var src = srcRe.exec(script); var inlineSrc = /\>([\s\S]+)<\/script>/gm.exec(script); var asyncRe = /async=?(["|']([\s\S]*?)["|'])?/gm; var asy = asyncRe.exec(script); var isAsync = ((asy === null || asy[2] === 'false') ? false : true); croWDxClient.prototype.croWDUtils.appendScript(location, src, inlineSrc, isAsync, aid); } var reSty = //gm; var style; while ((style = reSty.exec(response))) { var styRe = /href=["|']([\s\S]*?)["|']/gm; var href = styRe.exec(style); if (href !== null) { croWDxClient.prototype.croWDUtils.appendStyle(location, href[1], aid); } // htmlText = htmlText.replace(style[0], ''); //remove