-
Notifications
You must be signed in to change notification settings - Fork 0
/
optimizeReady.min.js
1 lines (1 loc) · 1.44 KB
/
optimizeReady.min.js
1
(function(root,optimizeReady){if(typeof define==="function"&&define.amd){define(optimizeReady)}else if(typeof exports==="object"){module.exports=optimizeReady()}else{root.returnExports=optimizeReady()}})(this,function(){"use strict";var customEventPolyfill=function(){if(typeof window.CustomEvent==="function"){return false}function CustomEvent(event,params){params=params||{bubbles:false,cancelable:false,detail:undefined};var evt=document.createEvent("CustomEvent");evt.initCustomEvent(event,params.bubbles,params.cancelable,params.detail);return evt}CustomEvent.prototype=window.Event.prototype;window.CustomEvent=CustomEvent};var optimizeReady=function(optimizeID,options){if(typeof optimizeID!=="object"){throw new Error("First parameter must be an object whose keys are Optimize container IDs")}options=typeof options==="object"?options:{};customEventPolyfill();var dataLayer=typeof options.dataLayer==="string"?options.dataLayer:"dataLayer",timeOut=typeof options.timeout==="number"?options.timeout:1500,optimizeReady=new CustomEvent("optimizeReady",{detail:{timeout:false}});if(options.timeout!==null){var timer=setTimeout(function(){optimizeReady.detail.timeout=true;window.dispatchEvent(optimizeReady);optimizeID.end=null},timeOut)}optimizeID.start=1*new Date;optimizeID.end=function(){if(timer){clearTimeout(timer)}window.dispatchEvent(optimizeReady)};(window[dataLayer]=window[dataLayer]||[]).hide=optimizeID;optimizeID.timeout=timeOut};return optimizeReady});