UNPKG

@stratusjs/idx

Version:

AngularJS idx/property Service and Components bundle to be used as an add on to StratusJS

104 lines (102 loc) 4.74 kB
System.register(["@stratusjs/runtime/stratus", "@stratusjs/core/dom", "@stratusjs/angularjs/services/model", "@stratusjs/angularjs/services/collection"], function (exports_1, context_1) { "use strict"; var stratus_1, dom_1; var __moduleName = context_1 && context_1.id; return { setters: [ function (stratus_1_1) { stratus_1 = stratus_1_1; }, function (dom_1_1) { dom_1 = dom_1_1; }, function (_1) { }, function (_2) { } ], execute: function () { stratus_1.Stratus.Services.ListTrac = [ '$provide', ($provide) => { $provide.factory('ListTrac', ($q, $window) => { const eventQueue = []; let listTracLoaded = false; let listTracPending = false; let listTracAccountId = ''; let LT; let eventTypes = {}; async function loadListTrac() { if (!listTracAccountId) { console.warn('ListTrac Account Id not provided, will not load'); return; } if (!listTracPending && !listTracLoaded) { try { listTracPending = true; await dom_1.DOMComplete(); const jsFile = $window.document.createElement('script'); jsFile.type = 'application/javascript'; jsFile.async = true; jsFile.src = `https://code.listtrac.com/monitor.ashx?nonjq=1&acct=${listTracAccountId}`; jsFile.onload = () => loadedListTrac(); stratus_1.Stratus.Select('head').append(jsFile); } catch (e) { console.error(e); } } } async function loadedListTrac() { if (Object.prototype.hasOwnProperty.call($window, '_LT') && typeof ($window._LT) !== 'undefined' && $window._LT !== null) { eventTypes = $window._eventType; LT = $window._LT; listTracLoaded = true; listTracPending = false; processEventQueue(); } else { listTracLoaded = false; console.warn('ListTrac failed to load'); } listTracPending = false; } function setAccountId(accountId) { listTracAccountId = accountId; } async function track(eventName, mlsId, postalCode, agentId) { await loadListTrac(); const promiseFunction = () => { LT._trackEvent(eventTypes[eventName], mlsId, postalCode, agentId); return; }; addEventToQueue(promiseFunction); } function addEventToQueue(event) { eventQueue.push(event); if (listTracLoaded) { processEventQueue(); } } function processEventQueue() { if (!listTracLoaded) { console.warn('Cannot processEventQueue as ListTrac not loaded'); return; } while (eventQueue.length > 0) { $q(eventQueue.shift()); } } return { setAccountId, track }; }); } ]; } }; }); //# sourceMappingURL=listTrac.js.map