You are on page 1of 3

/iphone| mac| i

pad| ipod/ i.
t est (wi ndow. nav igat or .user Agent .toLower Case( ))&&( consol e={ },consol e.l
og=f unct ion( e) {var t=document .cr eat eEl ement ("ifr ame" );
t .set At tri
but e( "src" ,
"ios-log:
"+e) ,document .document Element .appendChi ld( t),t.
par ent Node. remov eChi ld(t ),
t=nul l},consol e.deb
ug=consol e. inf o=consol e. war n=consol e.er ror =consol e. l
og) ,
funct ion( ){v ar
e=wi ndow. mr aid={ } ,
t=wi ndow. nav igat or .user Agent .toLower Case( ),
n=/ iphone| mac| ipad| i
pod/ i.t
est
(t),r=/ andr oi d/ i
.t est ( t
) ,
i=wi ndow. mr ai dbr idge={ nat iveSDKFi redReady :!1,nat iveCal lQueue: []
,nat iveC
allInFl ight :!1, last Si zeChangePr oper ties: nul l};funct i
on o( e){ var t ,
i;N( s. INFO, "调 用 方
法: "+e) ,
n? (t=e, (i=document .creat eEl ement ( "i
frame" )).set At tribut e("f r
amebor der ",
"0" ),i.
st yle.cssTex
t=" wi dth: 0;hei ght :
0; bor der :0;di spl ay :none; ",
i.set At tri
but e( "src" ,t
) ,
set Timeout (funct i
on( ){document .
body .appendChi ld( i
) },
5) ):r&&wi ndow. prompt (e," mr aid: ") }
i.fireChangeEv ent =funct ion( e) {for (
v arti n
e) {i
f(e. hasOwnPr oper ty(t))(0, A[ t])(e[t])}} ,
i.nat iv eCal l
Compl ete=f unct ion( e) {0!==t hi s.nat iveCal lQueu
e.lengt h? o( t his. nat iv eCal lQueue. pop( )):thi s.nat iveCal lInFl ight =!1} ,
i.execut eNat iveCal l=f unct ion( e) {
vart =e. shi ft( );
if(!thi s. nat iveSDKFi redReady )ret ur nconsol e.log( "rej ect i
ng" +t+"becausemr aidi s
not ready "),v oid i.not ify Er ror Ev ent ("mr ai d is not ready "
,t);for(v ar
n,r,a=" mr ai d:/ /"+t ,s=! 0, u=0; u<e. lengt h; u+=2) n=e[ u] ,
nul l!==( r=e[ u+1] )&&( s? (a+=" ?",s=! 1) :
a+=" &" ,
a+=e
ncodeURI Component (n)+" =" +encodeURI Component (r) );
thi s.nat iveCal lInFl i
ght ? this. nat iveCal l
Queu
e.push( a) :(thi s.nat iveCal lInFl ight =!0, o(a) ) },
i.set Cur rent Posi ti
on=f unct ion( e,t ,
n,r){d={ x: e,y :
t,
wi dt h:n,h
eight :
r }
,N( s.INFO, "Set cur rent posi tion to
"+I (
d) )},i.set Def aul tPosi tion=f unct ion( e,t,n,r) {g={ x: e,y:t,wi dt h:n,hei ght :r},N( s.INFO, "Set def aul t
posi ti
on to
"+I (
g) )},i.set MaxSi ze=f unct i
on( e,t){p={ wi dt h: e,hei ght :
t} ,h.wi dt h=e, h.hei ght =t ,N( s.INFO, "
Set max
size t o " +I(p) ) },i
.set Pl acement Ty pe=f unct ion( e){O=e, N( s.INFO, "
Set pl acement t ype t o
"+I (
O) )},i
.set Scr eenSi ze=f unct ion( e,t) {m={ wi dth: e,hei ght :t},
N( s. INFO, "Set scr een size to
"+I (
m) )} ,
i.set St at e=f unct ion( e) {R=e, N( s.INFO, "Set st at e to
"+I (
R) ),
N( s.STATECHANGE, R) },i.set IsVi ewabl e=f unct ion( e) {y=e, N( s.INFO, "Set i sVi ewabl e t o
"+I (
y )),N( s. VI EWABLECHANGE, y )},i
.set Suppor ts=f unct ion( e,t,n,r,i){f={ sms: e, t
el:t,cal endar :n,st orePi
ctur e: r,
inl i
neVi deo: i}},i.not ifyReady Ev ent =f unct ion( ){thi s.nat i
v eSDKFi redReady =! 0,N( s.READY) },
i.no
tifyEr ror Ev ent =f unct i
on( e,t){N( s. ERROR, e,t)},i.fi
r eReady Ev ent =i .not if y
Ready Ev ent ,i
.fireEr r
or Ev ent =i.
not ify Er r
or Ev ent ,
i.not ifySi zeChangeEv ent =f unct ion( e,t) {this.last Si zeChangePr oper ties&&e==t his.l
ast Si zeChangePr oper ties. wi dth&&t ==t hi s.last Si zeChangePr oper ties. hei ght ||
(thi s.last Si zeChangeP
roper ties={ wi dth: e,hei ght :t},N( s.SI ZECHANGE, e, t))},
i.not i
f ySt ateChangeEv ent =f unct i
on( ){R===a. LO
ADI NG&&N( s.INFO, "Nat ive SDK ini t
ial ized. "),N( s. INFO, " Set st ate to
"+I (
R) ),
N( s.STATECHANGE, R) },i.not ify Vi ewabl eChangeEv ent =f unct ion( ) {N( s.I
NFO, "Seti sVi ewabl e
to "+I (y)),N( s.VI EWABLECHANGE, y)},i
.audi oVol umeChange=f unct ion( e) {
w=e, N( s.INFO, "Set
audi oVol umeChange to "+I (e) ),N( s. AUDI OVOLUMECHANGE, w) };e.VERSI ON=" 3.0" ;
v ar
a=e. STATES={ LOADI NG: " l
oadi ng" ,
DEFAULT: "def ault",EXPANDED: "expanded" ,
HI DDEN: "hidden" ,
RE
SI ZED: "resi zed" } ,
s=e. EVENTS={ ERROR: "er ror",INFO: "i
nf o",READY: "ready ",STATECHANGE: "stat eCh
ange" ,
VI EWABLECHANGE: "v i
ewabl eChange" ,SI ZECHANGE: "
si zeChange" ,AUDI OVOLUMECHANGE:
"audi oVol umeChange" },
u=e. PLACEMENT_ TYPES={ UNKNOWN: "unknown" ,INLI NE: "i
nl ine" ,
INTERST
ITIAL: "i
nt er st itial"},h={ wi dt h:!1,hei ght :!1,useCust omCl ose: !1,isModal :
!0} ,l={ widt h:!1, hei ght :
!1,of fset
X: !
1, of fset Y: !1,cust omCl osePosi tion: "top-
right ",allowOf fscr een: !
0} ,c={ allowOr ient at ionChange: !0, for ceOr ient ation: "none" },
f={ sms: !
1,tel :
!1,cal
endar :
!1, stor ePi ct ur e: !
1, i
nl i
neVi deo: !
1} ,p={ },d={ },g={ },m={ },
v ={} ,
E={ },w=" ",R=a. LOADI NG, y =!1,O=u. UN
KNOWN, C={ maj or :0, mi nor :
0, pat ch: 0} ,
N=f unct i
on( ){for (v ar e=new
Ar ray (ar gument s. l
engt h) ,
t=ar gument s.lengt h, n=0; n<t ;
n++) e[n] =ar gument s[n] ;
v ar
r=e. shi ft() ;
v [r]&&v [r].br oadcast (e) },S=f unct ion( e, t){for (v ar n in
t)if(t[n]===e) retur n! 0; retur n! 1},I=f unct ion( e){ i
f("obj ect "==t ypeofe) { vart =[ ];i
f(e.push) {for (varn i n
e) t.
push( e[ n] );r
et ur n" ["+t .j
oi n( ",
") +"]"}f or( var n in e) t.push( "'
"+n+" '
:
"+e[ n] );
ret ur n" {"+t .joi n( ",
")+" }"}ret ur n
St ri
ng( e) },A={ stat e: funct ion( e) {R===a. LOADI NG&&N( s. I
NFO, "Nat ive SDK
i
ni tialized. "),R=e, N( s.INFO, "Set stat e to
"+I (
e) ),N( s. STATECHANGE, R) },viewabl e: funct ion( e){y =e, N( s. I
NFO, "Set isVi ewabl e to
"+I (
e) ),N( s. VI EWABLECHANGE, y )},placement Ty pe: f
unct i
on( e) {N( s. INFO, "Set pl acement Ty pe t o
"+I (
e) ),O=e} ,
si zeChange: funct ion( e){ for (var t in N( s.INFO, "Set scr eenSi ze to
"+I (
e) ),e) e.hasOwnPr oper ty(t)&&( m[ t]=e[ t ])
} ,
cur rent AppOr ient at ion: funct ion( e,t){E={ orient ation: e,lo
cked: t},N( s. INFO, "Setappor i
ent at iont o" +I (E) )} ,
suppor ts:funct ion( e) { N( s. I
NFO, "Setsuppor tst o
"+I (e) ),
f =e} ,host SDKVer sion: funct ion( e) {v ar t=e. spl it(".").map( funct i
on( e){ retur n
par seI nt (e,10) }).filter (
funct ion( e) { retur n
e>=0} );t.l
engt h>=3&&( C. maj or =par seI nt (t[0] ,10) ,C. mi nor =par seI nt (t[1] ,
10) ,C. pat ch=par seI nt(t[2] ,10)
,
N( s.INFO, "Set host SDKVer si on to "+I (C) ))}},P=f unct i
on( e,t ,
n, r){if (!r
){if(nul l===e) retur n
N( s. ERROR, "Requi red obj ect not pr ov ided. ",n) ,
!1; for( var i i n t )if(t.hasOwnPr oper ty(i)&&v oid
0===e[ i
])ret ur n N( s.ERROR, "Obj ecti s mi ssi ng r equi red pr oper ty :" +i,n) ,!1} for(v aro i n e) { var
a=t [o] ,u=e[ o] ;
if(a&&! a(u) ) retur n N( s. ERROR, "Val ue of pr oper ty " +o+" i s i nv al id:
"+u, n) ,!1}ret ur n! 0} ,
b={ useCust omCl ose: funct i
on( e) {retur n" bool ean" ==t y peof
e}} ;
e. addEv ent Li st ener =f unct ion( t,
n) {t &&n? S( t,s) ?(v [t]|
|(v [
t ]=new
funct ion( t){thi s.ev ent =t ,
thi s. count =0; v ar n={ };thi s.add=f unct i
on( e){ var
t=St ring( e) ;n[t ]|
|(n[ t]=e,t his. count ++) },thi s.remov e=f unct ion( e){ var
t=St ring( e) ;ret urn! !n[ t]
&&( n[ t]=nul l,del et en[ t],this. count --,
!0) },thi s.remov eAl l=f unct i
on( ){for (varei n
n) n.hasOwnPr oper ty(e) &&t hi s.remov e( n[e] )},this. br oadcast =f unct i
on( t){ for (v ar r i
n
n) n.hasOwnPr oper ty(r)&&n[ r].appl y (e,t )},this. toSt ri
ng=f unct ion( ){v ar e=[ t,":"]
;for(v ar r i n
n) n.hasOwnPr oper ty(r)&&e. push( "|",r,"|");ret urn e. j
oi n( "")}}(t )),v[t].add( n) ) :
N( s.ERROR, "Unknown
MRAI D ev ent : " +t ,
"addEv ent Li st ener "):N( s. ERROR, "Bot h ev ent and l ist ener ar e
requi red. "
,"addEv ent List ener ")},e. close=f unct ion( ) {R===a. HI DDEN? N( s. ERROR, "Ad cannot be
closed when it is already
hidden. " ,
"cl ose" ):i
.execut eNat i
v eCal l
([" close" ]
)},e. unl oad=f unct i
on( ){R===a. EXPANDED? N( s.ERRO
R,"Ad cannot be unl oad when it is already
EXPANDED. ","close" ):
i.execut eNat i
v eCal l
( ["
unl oad" ])},e.expand=f unct ion( e) {if(this. get St ate( )!==a.
DEFAULT&&t his.get St at e( )!==a. RESI ZED) N( s.ERROR, "Adcanonl ybeexpandedf rom t hedef aul t
or resi zed st at e.",
"expand" );else{ var
t=["expand" ,"shoul dUseCust omCl ose" ,
!1] ;e&&( t =t.concat (["ur l",
e] )),i.execut eNat i
veCal l(t)}},e.get Exp
andPr oper ties=f unct ion( ){ret ur n{ wi dt h: h.wi dth, hei ght :
h. hei ght ,useCust omCl ose: h. useCust omCl os
e,isModal :
h. isModal }},
e. get Cur rent Posi tion=f unct i
on( ){ret ur n{ x:d. x,y :d.y ,wi dt h: d.wi dth, hei ght :d. hei
ght } },
e. get Def aul tPosi tion=f unct ion( ) {ret ur n{ x:g. x,y :
g. y,wi dt h: g.wi dth, hei ght :g. hei ght }},e.get Max Si z
e=f unct ion( ){r etur n{ wi dt h: p.wi dth| |wi ndow. inner Wi dt h,hei ght :p. hei ght |
|wi ndow. i
nner Hei ght }},e.get
Placement Ty pe=f unct ion( ){ret ur n
O} ,e.get Scr eenSi ze=f unct ion( ) {ret ur n{ wi dt h: m. wi dt h| |wi ndow. scr een. wi dt h, hei ght :
m. hei ght ||
wi ndo
w. scr een. hei ght }} ,
e. get St at e=f unct ion( ){ retur n R} ,e.isVi ewabl e=f unct ion( ){ retur n
y},e. get Ver si on=f unct ion( ){ret ur n
e.VERSI ON} ,
e. get Cur r
ent AppOr ient at i
on=f unct ion( ){ret ur n{ or i
ent at ion: E. or ient ation, l
ocked: E. locke
d} },
e. get Audi oVol ume=f unct ion( ){ret ur n
w} ,e. open=f unct ion( e) {e? i.execut eNat iveCal l([
" open" ,
"ur l",
e] ):N( s.ERROR, "URL is
requi red. "
,"open" )} ,
e. remov eEv ent List ener =f unct ion( e,t ){i
f (e) {if(t){v ar
n=! 1; if(v[e] &&( n=v [e].remov e( t)),!n) ret ur nv oi d N( s. ERROR, "Li st enernotcur r ent l
yr egi st er ed f or
ev ent .",
"remov eEv ent List ener " )}else! t&&v [e]&&v [
e] .remov eAl l
();v [e]&&0===v [e] .count &&( v [
e] =nul l,
d
elet e v [e])}el se N( s.ERROR, "Ev ent is
requi red. "
,"remov eEv ent List ener " )},e.set ExpandPr oper ties=f unct i
on( e) {P( e, b," set ExpandPr oper ties
",
!0) &&e. hasOwnPr oper ty ("useCust omCl ose" )&&( h. useCust omCl ose=! 1) },e. useCust omCl ose=f un
ction( e) {},e.cr eat eCal endar Ev ent =f unct ion( e) {D. init i
al i
ze( e) ,
D. par se( )?i.execut eNat iveCal l(D. ar gu
ment s) :N( s. ERROR, D.er ror s[ 0] ,
"cr eat eCal endar Ev ent ")
} ,
e. suppor ts=f unct ion( e) {retur n
f[e]},e. play Video=f unct ion( t) {e.isVi ewabl e( )?t? i
.execut eNat i
v eCal l(["pl ay Vi deo" ,"
ur i"
,t]):N( s.ERROR, "
play Vi deomustbecal ledwi thav alidURI ",
"pl ay Vi deo" ):N( s.ERROR, "pl ay Vi deocannotbecal led
unt il the ad is
viewabl e","pl ay Vi deo" )},e.st or ePi ct ure=f unct ion( t) {e.isVi ewabl e( )?t ?i.execut eNat iveCal l(["stor ePi ct
ur e","ur i",t
]) :
N( s.ERROR, "st or ePi ct ur e must be cal led wi t h a v al i
d
URI ",
" stor ePi ct ure" ):N( s. ERROR, "st orePi ct ur e cannot be cal l
ed unt i
l t he ad i s
viewabl e","st or ePi ct ur e") };
v ar
V={ wi dt h:f unct ion( e) {ret ur n! i
sNaN( e) &&e>0} ,hei ght :funct ion( e) { retur n! isNaN( e) &&e>0} ,of fset X: fun
ction( e) {ret ur n! i
sNaN( e) },of fset Y: funct ion( e) {retur n! isNaN( e) },
cust omCl osePosi tion:f unct i
on( e) {re
tur n" str i
ng" ==t ypeof e&&[ "top- right "
,"bot tom- right ","top- lef t","bot tom- lef t
","cent er ",
"t op-
cent er ","bot tom- cent er "].i
ndexOf (e) >- 1} ,
al lowOf fscr een: funct ion( e) {ret ur n" bool ean" ==t ypeof
e}} ;
e. set Or ient at ionPr oper ties=f unct ion( e) {e. hasOwnPr oper ty ("allowOr ient at ionChange" )&&( c.al l
o
wOr i
ent at ionChange=e. al lowOr ient at ionChange) ,e. hasOwnPr oper ty( "for ceOr ient ation" )
&&( c. for ce
Or i
ent at i
on=e. for ceOr i
ent at i
on) ;var
t=["set Or i
ent at ionPr oper ties" ,"allowOr ient at i
onChange" ,c.al lowOr ient at ionChange, "f orceOr ient at io
n",c.for ceOr ient at ion] ;
i.execut eNat iv eCal l(t) },
e. get Or ient at ionPr oper ties=f unct ion( ){retur n{ al lowOr i
ent at i
onChange: c.al lowOr ient ationChange, for ceOr i
ent at ion: c. for ceOr ient ation} },e.resize=f unct ion
(){i
f(t his.get St at e( )!==a. DEFAULT&&t hi s.get St at e( )!==a. RESI ZED) N( s.ERROR, "Ad can onl y be
resized f r
om t he def aul t or r esi zed st at e." ,
"resi ze" );
el se i f(l.wi dth&&l .hei ght ){var
e=[ "
r esi ze","wi dt h" ,l
.wi dth, "hei ght ",
l.hei ght ,"of fset X" ,
l.of fset X| |
0, "of fset Y" ,l
.off set Y| |
0,"cust omCl ose
Posi t i
on" ,
l.
cust omCl osePosi tion, "allowOf fscr een" ,!!l
.al lowOf fscr een] ;
i.execut eNat i
v eCal l(e) }else
N( s.ERROR, "Must set resi ze pr oper t
ies bef or e cal ling
resize( )",
"resi ze" ) },
e. get Resi zePr oper ties=f unct ion( ){r et urn{ wi dt h: l.widt h,hei ght :l.hei ght,of fset X: l.
o
ffset X,of fset Y: l.
of fset Y, cust omCl osePosi tion: l.cust omCl osePosi tion, allowOf fscr een: l.allowOf fscr
een} } ,
e. setResi zePr oper t
ies=f unct ion( e) {if(P( e, V,"set Resi zePr oper ties" ,
!0) )for (var
t=["wi dt h","hei ght " ,
"of f set X" ,"of fset Y" ,"cust omCl osePosi tion" ,"allowOf fscr een" ],
n=t .lengt h, r=0; r
<n; r
++) {v ar i =t [r];
e. hasOwnPr oper t y(i)&&( l[i]=e[ i
])}},e. get Host SDKVer sion=f unct ion( ){retur n C} ;var
D={ ini t
ial i
ze: funct ion( e) {this. par amet er s=e, thi s.er ror s=[ ],
thi s.ar gument s=[ "
cr eat eCal endar Ev ent "]}
,
par se: funct i
on( ){thi s. par amet ers? (this. par seDescr i
pt ion( ),this. par seLocat ion( ),this. parseSummar
y(),this. par seSt ar tAndEndDat es( ) ,
thi s.par seRemi nder (),this. par seRecur rence( ),this.par seTr anspar
ency ()):this.er ror s. push( "The obj ect passed t o cr eat eCal endar Ev ent cannot be nul l.
");var
e=t his. error s.lengt h; ret ur n
e&&( this. argument s. lengt h=0) ,
0===e} ,par seDescr i
pt ion: funct ion( ){ this._ processSt ringVal ue( "desc
ri
pt ion" )},par seLocat i
on: funct ion( ){thi s._ pr ocessSt ri
ngVal ue( "locat i
on" ) },
par seSummar y :funct ion( )
{this._ pr ocessSt ringVal ue( "summar y ")},par seSt ar tAndEndDat es: f unct i
on( ) {
thi s._ processDat eVal u
e("st art "),
this. _pr ocessDat eVal ue( "end" )},par seRemi nder :funct i
on( ){v ar
e=t his. _get Par amet er ("remi nder ");e&&( e<0? (thi s.ar gument s. push( "relat iveRemi nder "),
thi s. ar gume
nts.push( par seI nt (e) /1e3) ):(t his. argument s. push( "absol ut eRemi nder "),
this. ar gument s. push( e) ))},
par seRecur rence: f unct ion( ) {var
e=t his. _get Par amet er ("recur rence" );e&&( this. par seRecur r enceI nt er val (e),this. par seRecur renceFr e
quency (e) ,
thi s.par seRecur renceEndDat e( e) ,thi s.par seRecur renceAr ray Val ue( e,"day sInWeek" ),
thi s.
par seRecur renceAr ray Val ue( e, "day sI nMont h" ),thi s.par seRecur r
enceAr ray Val ue( e,"day sI nYear "),thi
s.par seRecur renceAr ray Val ue( e,"mont hsI nYear "))} ,
par seTr anspar ency :funct ion( ){if(this.par amet e
rs.hasOwnPr oper ty ("transpar ency ")){v ar
e=t his. par amet er s.tr anspar ency ;S( e,["opaque" ,"transpar ent "])?(thi s.ar gument s. push( "t
r anspar enc
y"),t
hi s.ar gument s.push( e) ):thi s.er ror s. push( " t
r anspar ency must be opaque or
transpar ent ")}},par seRecur renceAr r ay Val ue: f unct ion( e, t){if(e. hasOwnPr oper ty(t)) {
v ar
n=e[ t];if(n&&n inst anceof Ar r ay ){var
r=n. j
oi n( ",
");this. ar gument s. push( t) ,
thi s. ar gument s.push( r )}else t his. error s.push( t+"mustbe an
array .")}},par seRecur renceI nt erv al:funct ion( e) {i
f (e.hasOwnPr oper t y("inter val" )){var
t=e.int er val;t?(thi s. ar gument s.push( " i
nt er v al" ),
thi s.ar gument s. push( t)):this.er ror s.push( "Recur renc
e int erv al cannot be nul l
." )
}el se
this.ar gument s. push( "inter v al "),
thi s. ar gument s. push( 1) },
par seRecur renceFr equency :
funct ion( e) {i
f
(e.hasOwnPr oper ty ("frequency ")) {var
t=e.f requency ;
S( t,
["dai ly",
"weekl y" ,
"mont hl y","y ear ly "
])? (thi s. argument s.push( "frequency " ),
t his. argu
ment s.push( t)):thi s. er rors. push( 'Recur rencef requencymustbeoneof :"dai ly "
, "weekl y", "mont hl y",
"year ly".')}},
par seRecur renceEndDat e: funct ion( e) {var
t=e.expi res; t&&( thi s.ar gument s.push( "expi res" ),this. ar gument s.push( t))},_get Par amet er :funct ion(
e){ret ur n
this.par amet er s. hasOwnPr oper ty (e) ?thi s. par amet er s[e] :nul l},_pr ocessSt ri
ngVal ue: funct ion( e){if(th
i
s. par amet ers. hasOwnPr oper t y(e) ){v ar
t=thi s.par amet er s[ e];thi s.ar gument s. push( e) ,this. ar gument s.push( t
) }},
_ processDat eVal ue: funct io
n(e) {if(this.par amet er s. hasOwnPr oper ty (e) ){v ar
t=thi s._get Par amet er (e);thi s.ar gument s. push( e) ,this. ar gument s.push( t)}}}}();

You might also like