diff --git a/build/criteo-mraid.js b/build/criteo-mraid.js index 737e28d..0f3e04f 100644 --- a/build/criteo-mraid.js +++ b/build/criteo-mraid.js @@ -1 +1 @@ -!function(){"use strict";function isFunction(any){return"function"==typeof any}!function(LogLevel){LogLevel.Debug="Debug",LogLevel.Info="Info",LogLevel.Warning="Warning",LogLevel.Error="Error"}(LogLevel=LogLevel||{}),function(MraidEvent){MraidEvent.Ready="ready",MraidEvent.Error="error",MraidEvent.StateChange="stateChange",MraidEvent.ViewableChange="viewableChange"}(MraidEvent=MraidEvent||{});var LogLevel,MraidEvent,MraidState,MraidPlacementType,EventsCoordinator=function(){function EventsCoordinator(){this.eventListeners=new Map(Object.values(MraidEvent).map(function(e){return[e,new Set]}))}return EventsCoordinator.prototype.addEventListener=function(event,listener,logger){var _a;event&&this.isCorrectEvent(event)?listener?isFunction(listener)?null!=(_a=this.eventListeners.get(event))&&_a.add(listener):logger(LogLevel.Error,"addEventListener","Incorrect listener when addEventListener. \n Listener is not a function. Actual type = ".concat(typeof listener)):logger(LogLevel.Error,"addEventListener","Incorrect listener when addEventListener. It is null or undefined"):logger(LogLevel.Error,"addEventListener","Incorrect event when addEventListener.Type = ".concat(typeof event,", value = ").concat(event))},EventsCoordinator.prototype.removeEventListener=function(event,listener,logger){var listeners;event&&this.isCorrectEvent(event)?listener&&!isFunction(listener)?logger(LogLevel.Error,"removeEventListener","Incorrect listener when removeEventListener. \n Listener is not a function. Actual type = ".concat(typeof listener)):(listeners=this.eventListeners.get(event),listener?null!=listeners&&listeners.delete(listener):null!=listeners&&listeners.clear()):logger(LogLevel.Error,"removeEventListener","Incorrect event when removeEventListener.Type = ".concat(typeof event,", value = ").concat(event))},EventsCoordinator.prototype.fireReadyEvent=function(){var _a;null!=(_a=this.eventListeners.get(MraidEvent.Ready))&&_a.forEach(function(value){null!=value&&value()})},EventsCoordinator.prototype.fireErrorEvent=function(message,action){var _a;null!=(_a=this.eventListeners.get(MraidEvent.Error))&&_a.forEach(function(value){null!=value&&value(message,action)})},EventsCoordinator.prototype.fireStateChangeEvent=function(newState){var _a;null!=(_a=this.eventListeners.get(MraidEvent.StateChange))&&_a.forEach(function(value){null!=value&&value(newState)})},EventsCoordinator.prototype.fireViewableChangeEvent=function(isViewable){var _a;null!=(_a=this.eventListeners.get(MraidEvent.ViewableChange))&&_a.forEach(function(value){null!=value&&value(isViewable)})},EventsCoordinator.prototype.isCorrectEvent=function(event){return event&&this.eventListeners.has(event)},EventsCoordinator}(),ExpandProperties=(!function(MraidState){MraidState.Loading="loading",MraidState.Default="default",MraidState.Expanded="expanded",MraidState.Hidden="hidden"}(MraidState=MraidState||{}),!function(MraidPlacementType){MraidPlacementType.Unknown="",MraidPlacementType.Inline="inline",MraidPlacementType.Interstitial="interstitial"}(MraidPlacementType=MraidPlacementType||{}),function(width,height){this.useCustomClose=!1,this.isModal=!0,this.width=width,this.height=height});var SdkFeature,Size=function(){function Size(width,height){this.width=width,this.height=height}return Size.prototype.clone=function(){return new Size(this.width,this.height)},Size}();!function(SdkFeature){SdkFeature.Sms="sms",SdkFeature.Tel="tel",SdkFeature.Calendar="calendar",SdkFeature.StorePicture="storePicture",SdkFeature.InlineVideo="inlineVideo"}(SdkFeature=SdkFeature||{});var defaultSupportedSdkFeatures=new function(sms,tel,inlineVideo){this.calendar=!1,this.storePicture=!1,this.sms=sms,this.tel=tel,this.inlineVideo=inlineVideo}(!1,!1,!1),Position=function(){function Position(x,y,width,height){this.x=x,this.y=y,this.width=width,this.height=height}return Position.prototype.clone=function(){return new Position(this.x,this.y,this.width,this.height)},Position}(),initialPosition=new Position(0,0,0,0),MRAIDImplementation=function(){function MRAIDImplementation(eventsCoordinator,sdkInteractor,logger){this.currentState=MraidState.Loading,this.placementType=MraidPlacementType.Unknown,this.isCurrentlyViewable=!1,this.currentExpandProperties=new ExpandProperties(-1,-1),this.currentMaxSize=new Size(0,0),this.currentScreenSize=new Size(0,0),this.pixelMultiplier=1,this.supportedSdkFeatures=defaultSupportedSdkFeatures,this.defaultPosition=initialPosition.clone(),this.currentPosition=initialPosition.clone(),this.eventsCoordinator=eventsCoordinator,this.sdkInteractor=sdkInteractor,this.logger=logger,this.spreadMraidInstance()}return MRAIDImplementation.prototype.getVersion=function(){return"2.0"},MRAIDImplementation.prototype.addEventListener=function(event,listener){try{this.eventsCoordinator.addEventListener(event,listener,this.logger.log)}catch(e){this.logger.log(LogLevel.Error,"addEventListener","error when addEventListener, event = ".concat(event,", listenerType = ").concat(typeof listener))}},MRAIDImplementation.prototype.removeEventListener=function(event,listener){try{this.eventsCoordinator.removeEventListener(event,listener,this.logger.log)}catch(e){this.logger.log(LogLevel.Error,"removeEventListener","error when removeEventListener, event = ".concat(event,", listenerType = ").concat(typeof listener))}},MRAIDImplementation.prototype.getState=function(){return this.currentState},MRAIDImplementation.prototype.getPlacementType=function(){return this.placementType},MRAIDImplementation.prototype.isViewable=function(){return this.isCurrentlyViewable},MRAIDImplementation.prototype.expand=function(url){this.canPerformActions()?this.placementType===MraidPlacementType.Interstitial?this.logger.log(LogLevel.Error,"expand","can't expand interstitial ad"):null!=url?this.logger.log(LogLevel.Error,"expand","two-part expandable ads are not supported"):this.sdkInteractor.expand(this.currentExpandProperties.width,this.currentExpandProperties.height):this.logger.log(LogLevel.Error,"expand","can't expand in ".concat(this.currentState," state"))},MRAIDImplementation.prototype.getExpandProperties=function(){var width=-1===this.currentExpandProperties.width?this.currentMaxSize.width*this.pixelMultiplier:this.currentExpandProperties.width,height=-1===this.currentExpandProperties.height?this.currentMaxSize.height*this.pixelMultiplier:this.currentExpandProperties.height;return new ExpandProperties(width,height)},MRAIDImplementation.prototype.setExpandProperties=function(properties){var _a;this.isCorrectProperties(properties)&&(this.currentExpandProperties.width=null!=(_a=properties.width)?_a:-1,this.currentExpandProperties.height=null!=(_a=properties.height)?_a:-1)},MRAIDImplementation.prototype.close=function(){this.sdkInteractor.close()},MRAIDImplementation.prototype.useCustomClose=function(useCustomClose){this.logger.log(LogLevel.Error,"useCustomClose","useCustomClose() is not supported")},MRAIDImplementation.prototype.open=function(url){url?"string"==typeof url?this.sdkInteractor.open(url):url instanceof URL?this.sdkInteractor.open(url.toString()):this.logger.log(LogLevel.Error,"open","Error when open(), url is not a string"):this.logger.log(LogLevel.Error,"open","Error when open(), url is null, empty or undefined")},MRAIDImplementation.prototype.createCalendarEvent=function(parameters){this.logger.log(LogLevel.Error,"createCalendarEvent","createCalendarEvent() is not supported")},MRAIDImplementation.prototype.storePicture=function(uri){this.logger.log(LogLevel.Error,"storePicture","storePicture() is not supported")},MRAIDImplementation.prototype.getMaxSize=function(){return this.currentMaxSize.clone()},MRAIDImplementation.prototype.getScreenSize=function(){return this.currentScreenSize.clone()},MRAIDImplementation.prototype.supports=function(feature){var value;return(value=feature)&&Object.values(SdkFeature).includes(value)?this.supportedSdkFeatures[feature]:(this.logger.log(LogLevel.Error,"supports","Feature param is not one of ".concat("[".concat(Object.values(SdkFeature).join(", "),"]"))),!1)},MRAIDImplementation.prototype.getCurrentPosition=function(){return this.currentPosition.clone()},MRAIDImplementation.prototype.getDefaultPosition=function(){return this.defaultPosition.clone()},MRAIDImplementation.prototype.playVideo=function(url){url?"string"==typeof url?this.sdkInteractor.playVideo(url):url instanceof URL?this.sdkInteractor.playVideo(url.toString()):this.logger.log(LogLevel.Error,"playVideo","Error when playVideo(), url is not a string"):this.logger.log(LogLevel.Error,"playVideo","Error when playVideo(), url is null, empty or undefined")},MRAIDImplementation.prototype.notifyReady=function(placementType){this.logger.log(LogLevel.Debug,"notifyReady","placementType=".concat(placementType)),this.placementType=placementType,this.setReady()},MRAIDImplementation.prototype.notifyError=function(message,action){this.eventsCoordinator.fireErrorEvent(message,action)},MRAIDImplementation.prototype.setIsViewable=function(isViewable){this.logger.log(LogLevel.Debug,"setIsViewable","isViewable=".concat(isViewable)),this.isCurrentlyViewable!==isViewable&&(this.isCurrentlyViewable=isViewable,this.eventsCoordinator.fireViewableChangeEvent(isViewable))},MRAIDImplementation.prototype.setMaxSize=function(width,height,pixelMultiplier){this.currentMaxSize.width=width,this.currentMaxSize.height=height,this.pixelMultiplier=pixelMultiplier},MRAIDImplementation.prototype.setScreenSize=function(width,height){this.currentScreenSize.width=width,this.currentScreenSize.height=height},MRAIDImplementation.prototype.notifyClosed=function(){this.canPerformActions()?this.currentState===MraidState.Expanded?this.updateState(MraidState.Default):this.currentState===MraidState.Default&&this.updateState(MraidState.Hidden):this.logger.log(LogLevel.Warning,"notifyClosed","can't close in ".concat(this.currentState," state"))},MRAIDImplementation.prototype.notifyExpanded=function(){switch(this.currentState){case MraidState.Default:this.updateState(MraidState.Expanded);break;case MraidState.Expanded:this.logger.log(LogLevel.Warning,"notifyExpanded","ad is already expanded");break;case MraidState.Loading:case MraidState.Hidden:this.logger.log(LogLevel.Warning,"notifyExpanded","can't expand from ".concat(this.currentState))}},MRAIDImplementation.prototype.setSupports=function(supportedSdkFeatures){var _a;this.supportedSdkFeatures.sms=null!=(_a=supportedSdkFeatures.sms)?_a:this.supportedSdkFeatures.sms,this.supportedSdkFeatures.tel=null!=(_a=supportedSdkFeatures.tel)?_a:this.supportedSdkFeatures.tel,this.supportedSdkFeatures.inlineVideo=null!=(_a=supportedSdkFeatures.inlineVideo)?_a:this.supportedSdkFeatures.inlineVideo},MRAIDImplementation.prototype.setCurrentPosition=function(x,y,width,height){x=new Position(x,y,width,height);JSON.stringify(this.defaultPosition)===JSON.stringify(initialPosition)&&(this.defaultPosition=x),this.currentPosition=x},MRAIDImplementation.prototype.updateState=function(newState){this.currentState=newState,this.eventsCoordinator.fireStateChangeEvent(newState)},MRAIDImplementation.prototype.setReady=function(){this.currentState===MraidState.Loading&&(this.updateState(MraidState.Default),this.eventsCoordinator.fireReadyEvent())},MRAIDImplementation.prototype.canPerformActions=function(){return this.currentState!==MraidState.Loading&&this.currentState!==MraidState.Hidden},MRAIDImplementation.prototype.isCorrectProperties=function(properties){var width,height,useCustomClose,isModal;return function(properties){var hasAnyProperty;if(null!=properties&&"object"==typeof properties)return hasAnyProperty=!1,Object.keys(new ExpandProperties(0,0)).forEach(function(property){Object.prototype.hasOwnProperty.call(properties,property)&&(hasAnyProperty=!0)}),0===Object.keys(properties).length||hasAnyProperty}(properties)?(width=properties.width,height=properties.height,useCustomClose=properties.useCustomClose,isModal=properties.isModal,!!this.isCorrectDimension(width)&&!!this.isCorrectDimension(height)&&(useCustomClose&&this.logger.log(LogLevel.Warning,"setExpandProperties","useCustomClose is not supported"),null==isModal||isModal||this.logger.log(LogLevel.Warning,"setExpandProperties","isModal property is readonly and always equals to true"),!0)):(this.logger.log(LogLevel.Error,"setExpandProperties","properties is ".concat(properties)),!1)},MRAIDImplementation.prototype.isCorrectDimension=function(dimension){return!(dimension&&("number"!=typeof dimension?(this.logger.log(LogLevel.Error,"setExpandProperties","width is not a number, width is ".concat(typeof dimension)),1):!this.isInAcceptedBounds(dimension)&&(this.logger.log(LogLevel.Error,"setExpandProperties","width is ".concat(dimension)),1)))},MRAIDImplementation.prototype.isInAcceptedBounds=function(number){return Number.isFinite(number)&&0<=number},MRAIDImplementation.prototype.spreadMraidInstance=function(){for(var _a,_b,iframes=document.getElementsByTagName("iframe"),i=0;i { mraid.setSupports({ sms: true, tel: true, - inlineVideo: true, }); expect(mraid.supports("sms")).toBe(true);