You are on page 1of 4

/iphone|mac|ipad|ipod/i.test(window.navigator.userAgent.toLowerCase())&&(console={},console.

log=function(e){va
r t=document.createElement("iframe");t.setAttribute("src","ios-log:
"+e),document.documentElement.appendChild(t),t.parentNode.removeChild(t),t=null},console.debug=console.info=c
o n s o l e . w a r n = c o n s o l e . e r r o r = c o n s o l e . l o g ) , f u n c t i o n ( ) { v a r
e=window.mraid={},t=window.navigator.userAgent.toLowerCase(),n=/iphone|mac|ipad|ipod/i.test(t),r=/android/i.test(
t),i=window.mraidbridge={nativeSDKFiredReady:!1,nativeCallQueue:[],nativeCallInFlight:!1,lastSizeChangePropert
i e s : n u l l } ; f u n c t i o n o ( e ) { v a r t , i ; N ( s . I N F O , "
:"+e),n?(t=e,(i=document.createElement("iframe")).setAttribute("frameborder","0"),i.style.cssText="width:0;height:0;
border:0;display:none;",i.setAttribute("src",t),setTimeout(function(){document.body.appendChild(i)},5)):r&&window
.prompt(e,"mraid:")}i.fireChangeEvent=function(e){for(var t in
e){if(e.hasOwnProperty(t))(0,A[t])(e[t])}},i.nativeCallComplete=function(e){0!==this.nativeCallQueue.length?o(this.
nativeCallQueue.pop()):this.nativeCallInFlight=!1},i.executeNativeCall=function(e){var
t=e.shift();if(!this.nativeSDKFiredReady)return console.log("rejecting "+t+" because mraid is not ready"),void
i . n o t i f y E r r o r E v e n t ( " m r a i d i s n o t r e a d y " , t ) ; f o r ( v a r
n,r,a="mraid://"+t,s=!0,u=0;u<e.length;u+=2)n=e[u],null!==(r=e[u+1])&&(s?(a+="?",s=!1):a+="&",a+=encodeURIC
omponent(n)+"="+encodeURIComponent(r));this.nativeCallInFlight?this.nativeCallQueue.push(a):(this.nativeCallInF
light=!0,o(a))},i.setCurrentPosition=function(e,t,n,r){d={x:e,y:t,width:n,height:r},N(s.INFO,"Set current position to
"+I(d))},i.setDefaultPosition=function(e,t,n,r){g={x:e,y:t,width:n,height:r},N(s.INFO,"Set default position to
"+I(g))},i.setMaxSize=function(e,t){p={width:e,height:t},h.width=e,h.height=t,N(s.INFO,"Set max size to
"+I(p))},i.setPlacementType=function(e){O=e,N(s.INFO,"Set placement type to
"+I(O))},i.setScreenSize=function(e,t){m={width:e,height:t},N(s.INFO,"Set screen size to
"+I(m))},i.setState=function(e){R=e,N(s.INFO,"Set state to
"+I(R)),N(s.STATECHANGE,R)},i.setIsViewable=function(e){y=e,N(s.INFO,"Set isViewable to
"+I(y)),N(s.VIEWABLECHANGE,y)},i.setSupports=function(e,t,n,r,i){f={sms:e,tel:t,calendar:n,storePicture:r,inline
Video:i}},i.notifyReadyEvent=function(){this.nativeSDKFiredReady=!0,N(s.READY)},i.notifyErrorEvent=function(
e,t){N(s.ERROR,e,t)},i.fireReadyEvent=i.notifyReadyEvent,i.fireErrorEvent=i.notifyErrorEvent,i.notifySizeChangeE
vent=function(e,t){this.lastSizeChangeProperties&&e==this.lastSizeChangeProperties.width&&t==this.lastSizeChan
geProperties.height||(this.lastSizeChangeProperties={width:e,height:t},N(s.SIZECHANGE,e,t))},i.notifyStateChange
Event=function(){R===a.LOADING&&N(s.INFO,"Native SDK initialized."),N(s.INFO,"Set state to
"+I(R)),N(s.STATECHANGE,R)},i.notifyViewableChangeEvent=function(){N(s.INFO,"Set isViewable to
"+I(y)),N(s.VIEWABLECHANGE,y)},i.audioVolumeChange=function(e){w=e,N(s.INFO,"Set audioVolumeChange
to "+I(e)),N(s.AUDIOVOLUMECHANGE,w)};e.VERSION="3.0";var
a=e.STATES={LOADING:"loading",DEFAULT:"default",EXPANDED:"expanded",HIDDEN:"hidden",RESIZED:"
resized"},s=e.EVENTS={ERROR:"error",INFO:"info",READY:"ready",STATECHANGE:"stateChange",VIEWABL
ECHANGE:"viewableChange",SIZECHANGE:"sizeChange",AUDIOVOLUMECHANGE:"audioVolumeChange"},u
=e.PLACEMENT_TYPES={UNKNOWN:"unknown",INLINE:"inline",INTERSTITIAL:"interstitial"},h={width:!1,h
eight:!1,useCustomClose:!1,isModal:!0},l={width:!1,height:!1,offsetX:!1,offsetY:!1,customClosePosition:"top-
right",allowOffscreen:!0},c={allowOrientationChange:!0,forceOrientation:"none"},f={sms:!1,tel:!1,calendar:!1,storeP
icture:!1,inlineVideo:!1},p={},d={},g={},m={},v={},E={},w="",R=a.LOADING,y=!1,O=u.UNKNOWN,C={major:
0 , m i n o r : 0 , p a t c h : 0 } , N = f u n c t i o n ( ) { f o r ( v a r e = n e w
Array(arguments.length),t=arguments.length,n=0;n<t;n++)e[n]=arguments[n];var
r=e.shift();v[r]&&v[r].broadcast(e)},S=function(e,t){for(var n in
t)if(t[n]===e)return!0;return!1},I=function(e){if("object"==typeof e){var t=[];if(e.push){for(var n in
e)t.push(e[n]);return"["+t.join(",")+"]"}for(var n in e)t.push("'"+n+"': "+e[n]);return"{"+t.join(",")+"}"}return
String(e)},A={state:function(e){R===a.LOADING&&N(s.INFO,"Native SDK initialized."),R=e,N(s.INFO,"Set state
to "+I(e)),N(s.STATECHANGE,R)},viewable:function(e){y=e,N(s.INFO,"Set isViewable to
"+I(e)),N(s.VIEWABLECHANGE,y)},placementType:function(e){N(s.INFO,"Set placementType to
"+I(e)),O=e},sizeChange:function(e){for(var t in N(s.INFO,"Set screenSize to
"+I(e)),e)e.hasOwnProperty(t)&&(m[t]=e[t])},currentAppOrientation:function(e,t){E={orientation:e,locked:t},N(s.IN
FO,"Set app orientation to "+I(E))},supports:function(e){N(s.INFO,"Set supports to
"+I(e)),f=e},hostSDKVersion:function(e){var t=e.split(".").map(function(e){return
p a r s e I n t ( e , 1 0 ) } ) . f i l t e r ( f u n c t i o n ( e ) { r e t u r n
e>=0});t.length>=3&&(C.major=parseInt(t[0],10),C.minor=parseInt(t[1],10),C.patch=parseInt(t[2],10),N(s.INFO,"Set
hostSDKVersion to "+I(C)))}},P=function(e,t,n,r){if(!r){if(null===e)return N(s.ERROR,"Required object not
provided.",n),!1;for(var i in t)if(t.hasOwnProperty(i)&&void 0===e[i])return N(s.ERROR,"Object is missing required
property: "+i,n),!1}for(var o in e){var a=t[o],u=e[o];if(a&&!a(u))return N(s.ERROR,"Value of property "+o+" is
invalid: "+u,n),!1}return!0},b={useCustomClose:function(e){return"boolean"==typeof
e}};e.addEventListener=function(t,n){t&&n?S(t,s)?(v[t]||(v[t]=new function(t){this.event=t,this.count=0;var
n={};this.add=function(e){var t=String(e);n[t]||(n[t]=e,this.count++)},this.remove=function(e){var
t=String(e);return!!n[t]&&(n[t]=null,delete n[t],this.count--,!0)},this.removeAll=function(){for(var e in
n)n.hasOwnProperty(e)&&this.remove(n[e])},this.broadcast=function(t){for(var r in
n)n.hasOwnProperty(r)&&n[r].apply(e,t)},this.toString=function(){var e=[t,":"];for(var r in
n)n.hasOwnProperty(r)&&e.push("|",r,"|");return e.join("")}}(t)),v[t].add(n)):N(s.ERROR,"Unknown MRAID event:
"+t,"addEventListener"):N(s.ERROR,"Both event and listener are
required.","addEventListener")},e.close=function(){R===a.HIDDEN?N(s.ERROR,"Ad cannot be closed when it is
already hidden.","close"):i.executeNativeCall(["close"])},e.unload=function(){R===a.EXPANDED?N(s.ERROR,"Ad
c a n n o t b e u n l o a d w h e n i t i s a l r e a d y
EXPANDED.","close"):i.executeNativeCall(["unload"])},e.expand=function(e){if(this.getState()!==a.DEFAULT&&t
his.getState()!==a.RESIZED)N(s.ERROR,"Ad can only be expanded from the default or resized
s t a t e . " , " e x p a n d " ) ; e l s e { v a r
t=["expand","shouldUseCustomClose",!1];e&&(t=t.concat(["url",e])),i.executeNativeCall(t)}},e.getExpandProperties
=function(){return{width:h.width,height:h.height,useCustomClose:h.useCustomClose,isModal:h.isModal}},e.getCurr
entPosition=function(){return{x:d.x,y:d.y,width:d.width,height:d.height}},e.getDefaultPosition=function(){return{x:g
.x,y:g.y,width:g.width,height:g.height}},e.getMaxSize=function(){return{width:p.width||window.innerWidth,height:p.
height||window.innerHeight}},e.getPlacementType=function(){return
O},e.getScreenSize=function(){return{width:m.width||window.screen.width,height:m.height||window.screen.height}},
e.getState=function(){return R},e.isViewable=function(){return y},e.getVersion=function(){return
e.VERSION},e.getCurrentAppOrientation=function(){return{orientation:E.orientation,locked:E.locked}},e.getAudio
Volume=function(){return w},e.open=function(e){e?i.executeNativeCall(["open","url",e]):N(s.ERROR,"URL is
required.","open")},e.removeEventListener=function(e,t){if(e){if(t){var n=!1;if(v[e]&&(n=v[e].remove(t)),!n)return
void N(s.ERROR,"Listener not currently registered for
event.","removeEventListener")}else!t&&v[e]&&v[e].removeAll();v[e]&&0===v[e].count&&(v[e]=null,delete
v [ e ] ) } e l s e N ( s . E R R O R , " E v e n t i s
required.","removeEventListener")},e.setExpandProperties=function(e){P(e,b,"setExpandProperties",!0)&&e.hasOwn
Property("useCustomClose")&&(h.useCustomClose=!1)},e.useCustomClose=function(e){},e.createCalendarEvent=fu
nction(e){D.initialize(e),D.parse()?i.executeNativeCall(D.arguments):N(s.ERROR,D.errors[0],"createCalendarEvent"
) } , e . s u p p o r t s = f u n c t i o n ( e ) { r e t u r n
f[e]},e.playVideo=function(t){e.isViewable()?t?i.executeNativeCall(["playVideo","uri",t]):N(s.ERROR,"playVideo
must be called with a valid URI","playVideo"):N(s.ERROR,"playVideo cannot be called until the ad is
viewable","playVideo")},e.storePicture=function(t){e.isViewable()?t?i.executeNativeCall(["storePicture","uri",t]):N(s
.ERROR,"storePicture must be called with a valid URI","storePicture"):N(s.ERROR,"storePicture cannot be called
u n t i l t h e a d i s v i e w a b l e " , " s t o r e P i c t u r e " ) } ; v a r
V={width:function(e){return!isNaN(e)&&e>0},height:function(e){return!isNaN(e)&&e>0},offsetX:function(e){retur
n!isNaN(e)},offsetY:function(e){return!isNaN(e)},customClosePosition:function(e){return"string"==typeof
e&&["top-right","bottom-right","top-left","bottom-left","center","top-center","bottom-center"].indexOf(e)>-
1 } , a l l o w O f f s c r e e n : f u n c t i o n ( e ) { r e t u r n " b o o l e a n " = = t y p e o f
e}};e.setOrientationProperties=function(e){e.hasOwnProperty("allowOrientationChange")&&(c.allowOrientationCha
nge=e.allowOrientationChange),e.hasOwnProperty("forceOrientation")&&(c.forceOrientation=e.forceOrientation);va
r
t=["setOrientationProperties","allowOrientationChange",c.allowOrientationChange,"forceOrientation",c.forceOrientat
ion];i.executeNativeCall(t)},e.getOrientationProperties=function(){return{allowOrientationChange:c.allowOrientation
Change,forceOrientation:c.forceOrientation}},e.resize=function(){if(this.getState()!==a.DEFAULT&&this.getState()!
==a.RESIZED)N(s.ERROR,"Ad can only be resized from the default or resized state.","resize");else
i f ( l . w i d t h & & l . h e i g h t ) { v a r
e=["resize","width",l.width,"height",l.height,"offsetX",l.offsetX||0,"offsetY",l.offsetY||0,"customClosePosition",l.cust
omClosePosition,"allowOffscreen",!!l.allowOffscreen];i.executeNativeCall(e)}else N(s.ERROR,"Must set resize
p r o p e r t i e s b e f o r e c a l l i n g
resize()","resize")},e.getResizeProperties=function(){return{width:l.width,height:l.height,offsetX:l.offsetX,offsetY:l.o
ffsetY,customClosePosition:l.customClosePosition,allowOffscreen:l.allowOffscreen}},e.setResizeProperties=function
( e ) { i f ( P ( e , V , " s e t R e s i z e P r o p e r t i e s " , ! 0 ) ) f o r ( v a r
t=["width","height","offsetX","offsetY","customClosePosition","allowOffscreen"],n=t.length,r=0;r<n;r++){var
i=t[r];e.hasOwnProperty(i)&&(l[i]=e[i])}},e.getHostSDKVersion=function(){return C};var
D={initialize:function(e){this.parameters=e,this.errors=[],this.arguments=["createCalendarEvent"]},parse:function(){t
his.parameters?(this.parseDescription(),this.parseLocation(),this.parseSummary(),this.parseStartAndEndDates(),this.p
arseReminder(),this.parseRecurrence(),this.parseTransparency()):this.errors.push("The object passed to
createCalendarEvent cannot be null.");var e=this.errors.length;return
e&&(this.arguments.length=0),0===e},parseDescription:function(){this._processStringValue("description")},parseLo
cation:function(){this._processStringValue("location")},parseSummary:function(){this._processStringValue("summar
y")},parseStartAndEndDates:function(){this._processDateValue("start"),this._processDateValue("end")},parseRemin
d e r : f u n c t i o n ( ) { v a r
e=this._getParameter("reminder");e&&(e<0?(this.arguments.push("relativeReminder"),this.arguments.push(parseInt(e
)/1e3)):(this.arguments.push("absoluteReminder"),this.arguments.push(e)))},parseRecurrence:function(){var
e=this._getParameter("recurrence");e&&(this.parseRecurrenceInterval(e),this.parseRecurrenceFrequency(e),this.parse
RecurrenceEndDate(e),this.parseRecurrenceArrayValue(e,"daysInWeek"),this.parseRecurrenceArrayValue(e,"daysIn
Month"),this.parseRecurrenceArrayValue(e,"daysInYear"),this.parseRecurrenceArrayValue(e,"monthsInYear"))},pars
eTransparency:function(){if(this.parameters.hasOwnProperty("transparency")){var
e=this.parameters.transparency;S(e,["opaque","transparent"])?(this.arguments.push("transparency"),this.arguments.pu
sh(e)):this.errors.push("transparency must be opaque or
transparent")}},parseRecurrenceArrayValue:function(e,t){if(e.hasOwnProperty(t)){var n=e[t];if(n&&n instanceof
Array){var r=n.join(",");this.arguments.push(t),this.arguments.push(r)}else this.errors.push(t+" must be an
array.")}},parseRecurrenceInterval:function(e){if(e.hasOwnProperty("interval")){var
t=e.interval;t?(this.arguments.push("interval"),this.arguments.push(t)):this.errors.push("Recurrence interval cannot be
n u l l . " ) } e l s e
this.arguments.push("interval"),this.arguments.push(1)},parseRecurrenceFrequency:function(e){if(e.hasOwnProperty(
" f r e q u e n c y " ) ) { v a r
t=e.frequency;S(t,["daily","weekly","monthly","yearly"])?(this.arguments.push("frequency"),this.arguments.push(t)):t
his.errors.push('Recurrence frequency must be one of: "daily", "weekly", "monthly",
" y e a r l y " . ' ) } } , p a r s e R e c u r r e n c e E n d D a t e : f u n c t i o n ( e ) { v a r
t=e.expires;t&&(this.arguments.push("expires"),this.arguments.push(t))},_getParameter:function(e){return
this.parameters.hasOwnProperty(e)?this.parameters[e]:null},_processStringValue:function(e){if(this.parameters.hasO
w n P r o p e r t y ( e ) ) { v a r
t=this.parameters[e];this.arguments.push(e),this.arguments.push(t)}},_processDateValue:function(e){if(this.parameter
s.hasOwnProperty(e)){var t=this._getParameter(e);this.arguments.push(e),this.arguments.push(t)}}}}();

You might also like