阜外心血管项目前端

mui.js 252KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304
  1. /*!
  2. * =====================================================
  3. * Mui v3.7.0 (http://dev.dcloud.net.cn/mui)
  4. * =====================================================
  5. */
  6. /**
  7. * MUI核心JS
  8. * @type _L4.$|Function
  9. */
  10. var mui = (function(document, undefined) {
  11. var readyRE = /complete|loaded|interactive/;
  12. var idSelectorRE = /^#([\w-]+)$/;
  13. var classSelectorRE = /^\.([\w-]+)$/;
  14. var tagSelectorRE = /^[\w-]+$/;
  15. var translateRE = /translate(?:3d)?\((.+?)\)/;
  16. var translateMatrixRE = /matrix(3d)?\((.+?)\)/;
  17. var $ = function(selector, context) {
  18. context = context || document;
  19. if (!selector)
  20. return wrap();
  21. if (typeof selector === 'object')
  22. if ($.isArrayLike(selector)) {
  23. return wrap($.slice.call(selector), null);
  24. } else {
  25. return wrap([selector], null);
  26. }
  27. if (typeof selector === 'function')
  28. return $.ready(selector);
  29. if (typeof selector === 'string') {
  30. try {
  31. selector = selector.trim();
  32. if (idSelectorRE.test(selector)) {
  33. var found = document.getElementById(RegExp.$1);
  34. return wrap(found ? [found] : []);
  35. }
  36. return wrap($.qsa(selector, context), selector);
  37. } catch (e) {}
  38. }
  39. return wrap();
  40. };
  41. var wrap = function(dom, selector) {
  42. dom = dom || [];
  43. Object.setPrototypeOf(dom, $.fn);
  44. dom.selector = selector || '';
  45. return dom;
  46. };
  47. $.uuid = 0;
  48. $.data = {};
  49. /**
  50. * extend(simple)
  51. * @param {type} target
  52. * @param {type} source
  53. * @param {type} deep
  54. * @returns {unresolved}
  55. */
  56. $.extend = function() { //from jquery2
  57. var options, name, src, copy, copyIsArray, clone,
  58. target = arguments[0] || {},
  59. i = 1,
  60. length = arguments.length,
  61. deep = false;
  62. if (typeof target === "boolean") {
  63. deep = target;
  64. target = arguments[i] || {};
  65. i++;
  66. }
  67. if (typeof target !== "object" && !$.isFunction(target)) {
  68. target = {};
  69. }
  70. if (i === length) {
  71. target = this;
  72. i--;
  73. }
  74. for (; i < length; i++) {
  75. if ((options = arguments[i]) != null) {
  76. for (name in options) {
  77. src = target[name];
  78. copy = options[name];
  79. if (target === copy) {
  80. continue;
  81. }
  82. if (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy)))) {
  83. if (copyIsArray) {
  84. copyIsArray = false;
  85. clone = src && $.isArray(src) ? src : [];
  86. } else {
  87. clone = src && $.isPlainObject(src) ? src : {};
  88. }
  89. target[name] = $.extend(deep, clone, copy);
  90. } else if (copy !== undefined) {
  91. target[name] = copy;
  92. }
  93. }
  94. }
  95. }
  96. return target;
  97. };
  98. /**
  99. * mui noop(function)
  100. */
  101. $.noop = function() {};
  102. /**
  103. * mui slice(array)
  104. */
  105. $.slice = [].slice;
  106. /**
  107. * mui filter(array)
  108. */
  109. $.filter = [].filter;
  110. $.type = function(obj) {
  111. return obj == null ? String(obj) : class2type[{}.toString.call(obj)] || "object";
  112. };
  113. /**
  114. * mui isArray
  115. */
  116. $.isArray = Array.isArray ||
  117. function(object) {
  118. return object instanceof Array;
  119. };
  120. /**
  121. * mui isArrayLike
  122. * @param {Object} obj
  123. */
  124. $.isArrayLike = function(obj) {
  125. var length = !!obj && "length" in obj && obj.length;
  126. var type = $.type(obj);
  127. if (type === "function" || $.isWindow(obj)) {
  128. return false;
  129. }
  130. return type === "array" || length === 0 ||
  131. typeof length === "number" && length > 0 && (length - 1) in obj;
  132. };
  133. /**
  134. * mui isWindow(需考虑obj为undefined的情况)
  135. */
  136. $.isWindow = function(obj) {
  137. return obj != null && obj === obj.window;
  138. };
  139. /**
  140. * mui isObject
  141. */
  142. $.isObject = function(obj) {
  143. return $.type(obj) === "object";
  144. };
  145. /**
  146. * mui isPlainObject
  147. */
  148. $.isPlainObject = function(obj) {
  149. return $.isObject(obj) && !$.isWindow(obj) && Object.getPrototypeOf(obj) === Object.prototype;
  150. };
  151. /**
  152. * mui isEmptyObject
  153. * @param {Object} o
  154. */
  155. $.isEmptyObject = function(o) {
  156. for (var p in o) {
  157. if (p !== undefined) {
  158. return false;
  159. }
  160. }
  161. return true;
  162. };
  163. /**
  164. * mui isFunction
  165. */
  166. $.isFunction = function(value) {
  167. return $.type(value) === "function";
  168. };
  169. /**
  170. * mui querySelectorAll
  171. * @param {type} selector
  172. * @param {type} context
  173. * @returns {Array}
  174. */
  175. $.qsa = function(selector, context) {
  176. context = context || document;
  177. return $.slice.call(classSelectorRE.test(selector) ? context.getElementsByClassName(RegExp.$1) : tagSelectorRE.test(selector) ? context.getElementsByTagName(selector) : context.querySelectorAll(selector));
  178. };
  179. /**
  180. * ready(DOMContentLoaded)
  181. * @param {type} callback
  182. * @returns {_L6.$}
  183. */
  184. $.ready = function(callback) {
  185. if (readyRE.test(document.readyState)) {
  186. callback($);
  187. } else {
  188. document.addEventListener('DOMContentLoaded', function() {
  189. callback($);
  190. }, false);
  191. }
  192. return this;
  193. };
  194. /**
  195. * 将 fn 缓存一段时间后, 再被调用执行
  196. * 此方法为了避免在 ms 段时间内, 执行 fn 多次. 常用于 resize , scroll , mousemove 等连续性事件中;
  197. * 当 ms 设置为 -1, 表示立即执行 fn, 即和直接调用 fn 一样;
  198. * 调用返回函数的 stop 停止最后一次的 buffer 效果
  199. * @param {Object} fn
  200. * @param {Object} ms
  201. * @param {Object} context
  202. */
  203. $.buffer = function(fn, ms, context) {
  204. var timer;
  205. var lastStart = 0;
  206. var lastEnd = 0;
  207. var ms = ms || 150;
  208. function run() {
  209. if (timer) {
  210. timer.cancel();
  211. timer = 0;
  212. }
  213. lastStart = $.now();
  214. fn.apply(context || this, arguments);
  215. lastEnd = $.now();
  216. }
  217. return $.extend(function() {
  218. if (
  219. (!lastStart) || // 从未运行过
  220. (lastEnd >= lastStart && $.now() - lastEnd > ms) || // 上次运行成功后已经超过ms毫秒
  221. (lastEnd < lastStart && $.now() - lastStart > ms * 8) // 上次运行或未完成,后8*ms毫秒
  222. ) {
  223. run.apply(this, arguments);
  224. } else {
  225. if (timer) {
  226. timer.cancel();
  227. }
  228. timer = $.later(run, ms, null, $.slice.call(arguments));
  229. }
  230. }, {
  231. stop: function() {
  232. if (timer) {
  233. timer.cancel();
  234. timer = 0;
  235. }
  236. }
  237. });
  238. };
  239. /**
  240. * each
  241. * @param {type} elements
  242. * @param {type} callback
  243. * @returns {_L8.$}
  244. */
  245. $.each = function(elements, callback, hasOwnProperty) {
  246. if (!elements) {
  247. return this;
  248. }
  249. if (typeof elements.length === 'number') {
  250. [].every.call(elements, function(el, idx) {
  251. return callback.call(el, idx, el) !== false;
  252. });
  253. } else {
  254. for (var key in elements) {
  255. if (hasOwnProperty) {
  256. if (elements.hasOwnProperty(key)) {
  257. if (callback.call(elements[key], key, elements[key]) === false) return elements;
  258. }
  259. } else {
  260. if (callback.call(elements[key], key, elements[key]) === false) return elements;
  261. }
  262. }
  263. }
  264. return this;
  265. };
  266. $.focus = function(element) {
  267. if ($.os.ios) {
  268. setTimeout(function() {
  269. element.focus();
  270. }, 10);
  271. } else {
  272. element.focus();
  273. }
  274. };
  275. /**
  276. * trigger event
  277. * @param {type} element
  278. * @param {type} eventType
  279. * @param {type} eventData
  280. * @returns {_L8.$}
  281. */
  282. $.trigger = function(element, eventType, eventData) {
  283. element.dispatchEvent(new CustomEvent(eventType, {
  284. detail: eventData,
  285. bubbles: true,
  286. cancelable: true
  287. }));
  288. return this;
  289. };
  290. /**
  291. * getStyles
  292. * @param {type} element
  293. * @param {type} property
  294. * @returns {styles}
  295. */
  296. $.getStyles = function(element, property) {
  297. var styles = element.ownerDocument.defaultView.getComputedStyle(element, null);
  298. if (property) {
  299. return styles.getPropertyValue(property) || styles[property];
  300. }
  301. return styles;
  302. };
  303. /**
  304. * parseTranslate
  305. * @param {type} translateString
  306. * @param {type} position
  307. * @returns {Object}
  308. */
  309. $.parseTranslate = function(translateString, position) {
  310. var result = translateString.match(translateRE || '');
  311. if (!result || !result[1]) {
  312. result = ['', '0,0,0'];
  313. }
  314. result = result[1].split(",");
  315. result = {
  316. x: parseFloat(result[0]),
  317. y: parseFloat(result[1]),
  318. z: parseFloat(result[2])
  319. };
  320. if (position && result.hasOwnProperty(position)) {
  321. return result[position];
  322. }
  323. return result;
  324. };
  325. /**
  326. * parseTranslateMatrix
  327. * @param {type} translateString
  328. * @param {type} position
  329. * @returns {Object}
  330. */
  331. $.parseTranslateMatrix = function(translateString, position) {
  332. var matrix = translateString.match(translateMatrixRE);
  333. var is3D = matrix && matrix[1];
  334. if (matrix) {
  335. matrix = matrix[2].split(",");
  336. if (is3D === "3d")
  337. matrix = matrix.slice(12, 15);
  338. else {
  339. matrix.push(0);
  340. matrix = matrix.slice(4, 7);
  341. }
  342. } else {
  343. matrix = [0, 0, 0];
  344. }
  345. var result = {
  346. x: parseFloat(matrix[0]),
  347. y: parseFloat(matrix[1]),
  348. z: parseFloat(matrix[2])
  349. };
  350. if (position && result.hasOwnProperty(position)) {
  351. return result[position];
  352. }
  353. return result;
  354. };
  355. $.hooks = {};
  356. $.addAction = function(type, hook) {
  357. var hooks = $.hooks[type];
  358. if (!hooks) {
  359. hooks = [];
  360. }
  361. hook.index = hook.index || 1000;
  362. hooks.push(hook);
  363. hooks.sort(function(a, b) {
  364. return a.index - b.index;
  365. });
  366. $.hooks[type] = hooks;
  367. return $.hooks[type];
  368. };
  369. $.doAction = function(type, callback) {
  370. if ($.isFunction(callback)) { //指定了callback
  371. $.each($.hooks[type], callback);
  372. } else { //未指定callback,直接执行
  373. $.each($.hooks[type], function(index, hook) {
  374. return !hook.handle();
  375. });
  376. }
  377. };
  378. /**
  379. * setTimeout封装
  380. * @param {Object} fn
  381. * @param {Object} when
  382. * @param {Object} context
  383. * @param {Object} data
  384. */
  385. $.later = function(fn, when, context, data) {
  386. when = when || 0;
  387. var m = fn;
  388. var d = data;
  389. var f;
  390. var r;
  391. if (typeof fn === 'string') {
  392. m = context[fn];
  393. }
  394. f = function() {
  395. m.apply(context, $.isArray(d) ? d : [d]);
  396. };
  397. r = setTimeout(f, when);
  398. return {
  399. id: r,
  400. cancel: function() {
  401. clearTimeout(r);
  402. }
  403. };
  404. };
  405. $.now = Date.now || function() {
  406. return +new Date();
  407. };
  408. var class2type = {};
  409. $.each(['Boolean', 'Number', 'String', 'Function', 'Array', 'Date', 'RegExp', 'Object', 'Error'], function(i, name) {
  410. class2type["[object " + name + "]"] = name.toLowerCase();
  411. });
  412. if (window.JSON) {
  413. $.parseJSON = JSON.parse;
  414. }
  415. /**
  416. * $.fn
  417. */
  418. $.fn = {
  419. each: function(callback) {
  420. [].every.call(this, function(el, idx) {
  421. return callback.call(el, idx, el) !== false;
  422. });
  423. return this;
  424. }
  425. };
  426. /**
  427. * 兼容 AMD 模块
  428. **/
  429. if (typeof define === 'function' && define.amd) {
  430. define('mui', [], function() {
  431. return $;
  432. });
  433. }
  434. return $;
  435. })(document);
  436. //window.mui = mui;
  437. //'$' in window || (window.$ = mui);
  438. /**
  439. * $.os
  440. * @param {type} $
  441. * @returns {undefined}
  442. */
  443. (function($, window) {
  444. function detect(ua) {
  445. this.os = {};
  446. var funcs = [
  447. function() { //wechat
  448. var wechat = ua.match(/(MicroMessenger)\/([\d\.]+)/i);
  449. if (wechat) { //wechat
  450. this.os.wechat = {
  451. version: wechat[2].replace(/_/g, '.')
  452. };
  453. }
  454. return false;
  455. },
  456. function() { //android
  457. var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  458. if (android) {
  459. this.os.android = true;
  460. this.os.version = android[2];
  461. this.os.isBadAndroid = !(/Chrome\/\d/.test(window.navigator.appVersion));
  462. }
  463. return this.os.android === true;
  464. },
  465. function() { //ios
  466. var iphone = ua.match(/(iPhone\sOS)\s([\d_]+)/);
  467. if (iphone) { //iphone
  468. this.os.ios = this.os.iphone = true;
  469. this.os.version = iphone[2].replace(/_/g, '.');
  470. } else {
  471. var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  472. if (ipad) { //ipad
  473. this.os.ios = this.os.ipad = true;
  474. this.os.version = ipad[2].replace(/_/g, '.');
  475. }
  476. }
  477. return this.os.ios === true;
  478. }
  479. ];
  480. [].every.call(funcs, function(func) {
  481. return !func.call($);
  482. });
  483. }
  484. detect.call($, navigator.userAgent);
  485. })(mui, window);
  486. /**
  487. * $.os.plus
  488. * @param {type} $
  489. * @returns {undefined}
  490. */
  491. (function($, document) {
  492. function detect(ua) {
  493. this.os = this.os || {};
  494. var plus = ua.match(/Html5Plus/i); //TODO 5\+Browser?
  495. if (plus) {
  496. this.os.plus = true;
  497. $(function() {
  498. document.body.classList.add('mui-plus');
  499. });
  500. if (ua.match(/StreamApp/i)) { //TODO 最好有流应用自己的标识
  501. this.os.stream = true;
  502. $(function() {
  503. document.body.classList.add('mui-plus-stream');
  504. });
  505. }
  506. }
  507. }
  508. detect.call($, navigator.userAgent);
  509. })(mui, document);
  510. /**
  511. * 仅提供简单的on,off(仅支持事件委托,不支持当前元素绑定,当前元素绑定请直接使用addEventListener,removeEventListener)
  512. * @param {Object} $
  513. */
  514. (function($) {
  515. if ('ontouchstart' in window) {
  516. $.isTouchable = true;
  517. $.EVENT_START = 'touchstart';
  518. $.EVENT_MOVE = 'touchmove';
  519. $.EVENT_END = 'touchend';
  520. } else {
  521. $.isTouchable = false;
  522. $.EVENT_START = 'mousedown';
  523. $.EVENT_MOVE = 'mousemove';
  524. $.EVENT_END = 'mouseup';
  525. }
  526. $.EVENT_CANCEL = 'touchcancel';
  527. $.EVENT_CLICK = 'click';
  528. var _mid = 1;
  529. var delegates = {};
  530. //需要wrap的函数
  531. var eventMethods = {
  532. preventDefault: 'isDefaultPrevented',
  533. stopImmediatePropagation: 'isImmediatePropagationStopped',
  534. stopPropagation: 'isPropagationStopped'
  535. };
  536. //默认true返回函数
  537. var returnTrue = function() {
  538. return true
  539. };
  540. //默认false返回函数
  541. var returnFalse = function() {
  542. return false
  543. };
  544. //wrap浏览器事件
  545. var compatible = function(event, target) {
  546. if (!event.detail) {
  547. event.detail = {
  548. currentTarget: target
  549. };
  550. } else {
  551. event.detail.currentTarget = target;
  552. }
  553. $.each(eventMethods, function(name, predicate) {
  554. var sourceMethod = event[name];
  555. event[name] = function() {
  556. this[predicate] = returnTrue;
  557. return sourceMethod && sourceMethod.apply(event, arguments)
  558. }
  559. event[predicate] = returnFalse;
  560. }, true);
  561. return event;
  562. };
  563. //简单的wrap对象_mid
  564. var mid = function(obj) {
  565. return obj && (obj._mid || (obj._mid = _mid++));
  566. };
  567. //事件委托对象绑定的事件回调列表
  568. var delegateFns = {};
  569. //返回事件委托的wrap事件回调
  570. var delegateFn = function(element, event, selector, callback) {
  571. return function(e) {
  572. //same event
  573. var callbackObjs = delegates[element._mid][event];
  574. var handlerQueue = [];
  575. var target = e.target;
  576. var selectorAlls = {};
  577. for (; target && target !== document; target = target.parentNode) {
  578. if (target === element) {
  579. break;
  580. }
  581. if (~['click', 'tap', 'doubletap', 'longtap', 'hold'].indexOf(event) && (target.disabled || target.classList.contains('mui-disabled'))) {
  582. break;
  583. }
  584. var matches = {};
  585. $.each(callbackObjs, function(selector, callbacks) { //same selector
  586. selectorAlls[selector] || (selectorAlls[selector] = $.qsa(selector, element));
  587. if (selectorAlls[selector] && ~(selectorAlls[selector]).indexOf(target)) {
  588. if (!matches[selector]) {
  589. matches[selector] = callbacks;
  590. }
  591. }
  592. }, true);
  593. if (!$.isEmptyObject(matches)) {
  594. handlerQueue.push({
  595. element: target,
  596. handlers: matches
  597. });
  598. }
  599. }
  600. selectorAlls = null;
  601. e = compatible(e); //compatible event
  602. $.each(handlerQueue, function(index, handler) {
  603. target = handler.element;
  604. var tagName = target.tagName;
  605. if (event === 'tap' && (tagName !== 'INPUT' && tagName !== 'TEXTAREA' && tagName !== 'SELECT')) {
  606. e.preventDefault();
  607. e.detail && e.detail.gesture && e.detail.gesture.preventDefault();
  608. }
  609. $.each(handler.handlers, function(index, handler) {
  610. $.each(handler, function(index, callback) {
  611. if (callback.call(target, e) === false) {
  612. e.preventDefault();
  613. e.stopPropagation();
  614. }
  615. }, true);
  616. }, true)
  617. if (e.isPropagationStopped()) {
  618. return false;
  619. }
  620. }, true);
  621. };
  622. };
  623. var findDelegateFn = function(element, event) {
  624. var delegateCallbacks = delegateFns[mid(element)];
  625. var result = [];
  626. if (delegateCallbacks) {
  627. result = [];
  628. if (event) {
  629. var filterFn = function(fn) {
  630. return fn.type === event;
  631. }
  632. return delegateCallbacks.filter(filterFn);
  633. } else {
  634. result = delegateCallbacks;
  635. }
  636. }
  637. return result;
  638. };
  639. var preventDefaultException = /^(INPUT|TEXTAREA|BUTTON|SELECT)$/;
  640. /**
  641. * mui delegate events
  642. * @param {type} event
  643. * @param {type} selector
  644. * @param {type} callback
  645. * @returns {undefined}
  646. */
  647. $.fn.on = function(event, selector, callback) { //仅支持简单的事件委托,主要是tap事件使用,类似mouse,focus之类暂不封装支持
  648. return this.each(function() {
  649. var element = this;
  650. mid(element);
  651. mid(callback);
  652. var isAddEventListener = false;
  653. var delegateEvents = delegates[element._mid] || (delegates[element._mid] = {});
  654. var delegateCallbackObjs = delegateEvents[event] || ((delegateEvents[event] = {}));
  655. if ($.isEmptyObject(delegateCallbackObjs)) {
  656. isAddEventListener = true;
  657. }
  658. var delegateCallbacks = delegateCallbackObjs[selector] || (delegateCallbackObjs[selector] = []);
  659. delegateCallbacks.push(callback);
  660. if (isAddEventListener) {
  661. var delegateFnArray = delegateFns[mid(element)];
  662. if (!delegateFnArray) {
  663. delegateFnArray = [];
  664. }
  665. var delegateCallback = delegateFn(element, event, selector, callback);
  666. delegateFnArray.push(delegateCallback);
  667. delegateCallback.i = delegateFnArray.length - 1;
  668. delegateCallback.type = event;
  669. delegateFns[mid(element)] = delegateFnArray;
  670. element.addEventListener(event, delegateCallback);
  671. if (event === 'tap') { //TODO 需要找个更好的解决方案
  672. element.addEventListener('click', function(e) {
  673. if (e.target) {
  674. var tagName = e.target.tagName;
  675. if (!preventDefaultException.test(tagName)) {
  676. if (tagName === 'A') {
  677. var href = e.target.href;
  678. if (!(href && ~href.indexOf('tel:'))) {
  679. e.preventDefault();
  680. }
  681. } else {
  682. e.preventDefault();
  683. }
  684. }
  685. }
  686. });
  687. }
  688. }
  689. });
  690. };
  691. $.fn.off = function(event, selector, callback) {
  692. return this.each(function() {
  693. var _mid = mid(this);
  694. if (!event) { //mui(selector).off();
  695. delegates[_mid] && delete delegates[_mid];
  696. } else if (!selector) { //mui(selector).off(event);
  697. delegates[_mid] && delete delegates[_mid][event];
  698. } else if (!callback) { //mui(selector).off(event,selector);
  699. delegates[_mid] && delegates[_mid][event] && delete delegates[_mid][event][selector];
  700. } else { //mui(selector).off(event,selector,callback);
  701. var delegateCallbacks = delegates[_mid] && delegates[_mid][event] && delegates[_mid][event][selector];
  702. $.each(delegateCallbacks, function(index, delegateCallback) {
  703. if (mid(delegateCallback) === mid(callback)) {
  704. delegateCallbacks.splice(index, 1);
  705. return false;
  706. }
  707. }, true);
  708. }
  709. if (delegates[_mid]) {
  710. //如果off掉了所有当前element的指定的event事件,则remove掉当前element的delegate回调
  711. if ((!delegates[_mid][event] || $.isEmptyObject(delegates[_mid][event]))) {
  712. findDelegateFn(this, event).forEach(function(fn) {
  713. this.removeEventListener(fn.type, fn);
  714. delete delegateFns[_mid][fn.i];
  715. }.bind(this));
  716. }
  717. } else {
  718. //如果delegates[_mid]已不存在,删除所有
  719. findDelegateFn(this).forEach(function(fn) {
  720. this.removeEventListener(fn.type, fn);
  721. delete delegateFns[_mid][fn.i];
  722. }.bind(this));
  723. }
  724. });
  725. };
  726. })(mui);
  727. /**
  728. * mui target(action>popover>modal>tab>toggle)
  729. */
  730. (function($, window, document) {
  731. /**
  732. * targets
  733. */
  734. $.targets = {};
  735. /**
  736. * target handles
  737. */
  738. $.targetHandles = [];
  739. /**
  740. * register target
  741. * @param {type} target
  742. * @returns {$.targets}
  743. */
  744. $.registerTarget = function(target) {
  745. target.index = target.index || 1000;
  746. $.targetHandles.push(target);
  747. $.targetHandles.sort(function(a, b) {
  748. return a.index - b.index;
  749. });
  750. return $.targetHandles;
  751. };
  752. window.addEventListener($.EVENT_START, function(event) {
  753. var target = event.target;
  754. var founds = {};
  755. for (; target && target !== document; target = target.parentNode) {
  756. var isFound = false;
  757. $.each($.targetHandles, function(index, targetHandle) {
  758. var name = targetHandle.name;
  759. if (!isFound && !founds[name] && targetHandle.hasOwnProperty('handle')) {
  760. $.targets[name] = targetHandle.handle(event, target);
  761. if ($.targets[name]) {
  762. founds[name] = true;
  763. if (targetHandle.isContinue !== true) {
  764. isFound = true;
  765. }
  766. }
  767. } else {
  768. if (!founds[name]) {
  769. if (targetHandle.isReset !== false)
  770. $.targets[name] = false;
  771. }
  772. }
  773. });
  774. if (isFound) {
  775. break;
  776. }
  777. }
  778. });
  779. window.addEventListener('click', function(event) { //解决touch与click的target不一致的问题(比如链接边缘点击时,touch的target为html,而click的target为A)
  780. var target = event.target;
  781. var isFound = false;
  782. for (; target && target !== document; target = target.parentNode) {
  783. if (target.tagName === 'A') {
  784. $.each($.targetHandles, function(index, targetHandle) {
  785. var name = targetHandle.name;
  786. if (targetHandle.hasOwnProperty('handle')) {
  787. if (targetHandle.handle(event, target)) {
  788. isFound = true;
  789. event.preventDefault();
  790. return false;
  791. }
  792. }
  793. });
  794. if (isFound) {
  795. break;
  796. }
  797. }
  798. }
  799. });
  800. })(mui, window, document);
  801. /**
  802. * fixed trim
  803. * @param {type} undefined
  804. * @returns {undefined}
  805. */
  806. (function(undefined) {
  807. if (String.prototype.trim === undefined) { // fix for iOS 3.2
  808. String.prototype.trim = function() {
  809. return this.replace(/^\s+|\s+$/g, '');
  810. };
  811. }
  812. Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
  813. obj['__proto__'] = proto;
  814. return obj;
  815. };
  816. })();
  817. /**
  818. * fixed CustomEvent
  819. */
  820. (function() {
  821. if (typeof window.CustomEvent === 'undefined') {
  822. function CustomEvent(event, params) {
  823. params = params || {
  824. bubbles: false,
  825. cancelable: false,
  826. detail: undefined
  827. };
  828. var evt = document.createEvent('Events');
  829. var bubbles = true;
  830. for (var name in params) {
  831. (name === 'bubbles') ? (bubbles = !!params[name]) : (evt[name] = params[name]);
  832. }
  833. evt.initEvent(event, bubbles, true);
  834. return evt;
  835. };
  836. CustomEvent.prototype = window.Event.prototype;
  837. window.CustomEvent = CustomEvent;
  838. }
  839. })();
  840. /*
  841. A shim for non ES5 supporting browsers.
  842. Adds function bind to Function prototype, so that you can do partial application.
  843. Works even with the nasty thing, where the first word is the opposite of extranet, the second one is the profession of Columbus, and the version number is 9, flipped 180 degrees.
  844. */
  845. Function.prototype.bind = Function.prototype.bind || function(to) {
  846. // Make an array of our arguments, starting from second argument
  847. var partial = Array.prototype.splice.call(arguments, 1),
  848. // We'll need the original function.
  849. fn = this;
  850. var bound = function() {
  851. // Join the already applied arguments to the now called ones (after converting to an array again).
  852. var args = partial.concat(Array.prototype.splice.call(arguments, 0));
  853. // If not being called as a constructor
  854. if (!(this instanceof bound)) {
  855. // return the result of the function called bound to target and partially applied.
  856. return fn.apply(to, args);
  857. }
  858. // If being called as a constructor, apply the function bound to self.
  859. fn.apply(this, args);
  860. }
  861. // Attach the prototype of the function to our newly created function.
  862. bound.prototype = fn.prototype;
  863. return bound;
  864. };
  865. /**
  866. * mui fixed classList
  867. * @param {type} document
  868. * @returns {undefined}
  869. */
  870. (function(document) {
  871. if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
  872. Object.defineProperty(HTMLElement.prototype, 'classList', {
  873. get: function() {
  874. var self = this;
  875. function update(fn) {
  876. return function(value) {
  877. var classes = self.className.split(/\s+/),
  878. index = classes.indexOf(value);
  879. fn(classes, index, value);
  880. self.className = classes.join(" ");
  881. };
  882. }
  883. var ret = {
  884. add: update(function(classes, index, value) {
  885. ~index || classes.push(value);
  886. }),
  887. remove: update(function(classes, index) {
  888. ~index && classes.splice(index, 1);
  889. }),
  890. toggle: update(function(classes, index, value) {
  891. ~index ? classes.splice(index, 1) : classes.push(value);
  892. }),
  893. contains: function(value) {
  894. return !!~self.className.split(/\s+/).indexOf(value);
  895. },
  896. item: function(i) {
  897. return self.className.split(/\s+/)[i] || null;
  898. }
  899. };
  900. Object.defineProperty(ret, 'length', {
  901. get: function() {
  902. return self.className.split(/\s+/).length;
  903. }
  904. });
  905. return ret;
  906. }
  907. });
  908. }
  909. })(document);
  910. /**
  911. * mui fixed requestAnimationFrame
  912. * @param {type} window
  913. * @returns {undefined}
  914. */
  915. (function(window) {
  916. if (!window.requestAnimationFrame) {
  917. var lastTime = 0;
  918. window.requestAnimationFrame = window.webkitRequestAnimationFrame || function(callback, element) {
  919. var currTime = new Date().getTime();
  920. var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
  921. var id = window.setTimeout(function() {
  922. callback(currTime + timeToCall);
  923. }, timeToCall);
  924. lastTime = currTime + timeToCall;
  925. return id;
  926. };
  927. window.cancelAnimationFrame = window.webkitCancelAnimationFrame || window.webkitCancelRequestAnimationFrame || function(id) {
  928. clearTimeout(id);
  929. };
  930. };
  931. }(window));
  932. /**
  933. * fastclick(only for radio,checkbox)
  934. */
  935. (function($, window, name) {
  936. if (!$.os.android && !$.os.ios) { //目前仅识别android和ios
  937. return;
  938. }
  939. if (window.FastClick) {
  940. return;
  941. }
  942. var handle = function(event, target) {
  943. if (target.tagName === 'LABEL') {
  944. if (target.parentNode) {
  945. target = target.parentNode.querySelector('input');
  946. }
  947. }
  948. if (target && (target.type === 'radio' || target.type === 'checkbox')) {
  949. if (!target.disabled) { //disabled
  950. return target;
  951. }
  952. }
  953. return false;
  954. };
  955. $.registerTarget({
  956. name: name,
  957. index: 40,
  958. handle: handle,
  959. target: false
  960. });
  961. var dispatchEvent = function(event) {
  962. var targetElement = $.targets.click;
  963. if (targetElement) {
  964. var clickEvent, touch;
  965. // On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect
  966. if (document.activeElement && document.activeElement !== targetElement) {
  967. document.activeElement.blur();
  968. }
  969. touch = event.detail.gesture.changedTouches[0];
  970. // Synthesise a click event, with an extra attribute so it can be tracked
  971. clickEvent = document.createEvent('MouseEvents');
  972. clickEvent.initMouseEvent('click', true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
  973. clickEvent.forwardedTouchEvent = true;
  974. targetElement.dispatchEvent(clickEvent);
  975. event.detail && event.detail.gesture.preventDefault();
  976. }
  977. };
  978. window.addEventListener('tap', dispatchEvent);
  979. window.addEventListener('doubletap', dispatchEvent);
  980. //捕获
  981. window.addEventListener('click', function(event) {
  982. if ($.targets.click) {
  983. if (!event.forwardedTouchEvent) { //stop click
  984. if (event.stopImmediatePropagation) {
  985. event.stopImmediatePropagation();
  986. } else {
  987. // Part of the hack for browsers that don't support Event#stopImmediatePropagation
  988. event.propagationStopped = true;
  989. }
  990. event.stopPropagation();
  991. event.preventDefault();
  992. return false;
  993. }
  994. }
  995. }, true);
  996. })(mui, window, 'click');
  997. (function($, document) {
  998. $(function() {
  999. if (!$.os.ios) {
  1000. return;
  1001. }
  1002. var CLASS_FOCUSIN = 'mui-focusin';
  1003. var CLASS_BAR_TAB = 'mui-bar-tab';
  1004. var CLASS_BAR_FOOTER = 'mui-bar-footer';
  1005. var CLASS_BAR_FOOTER_SECONDARY = 'mui-bar-footer-secondary';
  1006. var CLASS_BAR_FOOTER_SECONDARY_TAB = 'mui-bar-footer-secondary-tab';
  1007. // var content = document.querySelector('.' + CLASS_CONTENT);
  1008. // if (content) {
  1009. // document.body.insertBefore(content, document.body.firstElementChild);
  1010. // }
  1011. document.addEventListener('focusin', function(e) {
  1012. if ($.os.plus) { //在父webview里边不fix
  1013. if (window.plus) {
  1014. if (plus.webview.currentWebview().children().length > 0) {
  1015. return;
  1016. }
  1017. }
  1018. }
  1019. var target = e.target;
  1020. //TODO 需考虑所有键盘弹起的情况
  1021. if (target.tagName && (target.tagName === 'TEXTAREA' || (target.tagName === 'INPUT' && (target.type === 'text' || target.type === 'search' || target.type === 'number')))) {
  1022. if (target.disabled || target.readOnly) {
  1023. return;
  1024. }
  1025. document.body.classList.add(CLASS_FOCUSIN);
  1026. var isFooter = false;
  1027. for (; target && target !== document; target = target.parentNode) {
  1028. var classList = target.classList;
  1029. if (classList && classList.contains(CLASS_BAR_TAB) || classList.contains(CLASS_BAR_FOOTER) || classList.contains(CLASS_BAR_FOOTER_SECONDARY) || classList.contains(CLASS_BAR_FOOTER_SECONDARY_TAB)) {
  1030. isFooter = true;
  1031. break;
  1032. }
  1033. }
  1034. if (isFooter) {
  1035. var scrollTop = document.body.scrollHeight;
  1036. var scrollLeft = document.body.scrollLeft;
  1037. setTimeout(function() {
  1038. window.scrollTo(scrollLeft, scrollTop);
  1039. }, 20);
  1040. }
  1041. }
  1042. });
  1043. document.addEventListener('focusout', function(e) {
  1044. var classList = document.body.classList;
  1045. if (classList.contains(CLASS_FOCUSIN)) {
  1046. classList.remove(CLASS_FOCUSIN);
  1047. setTimeout(function() {
  1048. window.scrollTo(document.body.scrollLeft, document.body.scrollTop);
  1049. }, 20);
  1050. }
  1051. });
  1052. });
  1053. })(mui, document);
  1054. /**
  1055. * mui namespace(optimization)
  1056. * @param {type} $
  1057. * @returns {undefined}
  1058. */
  1059. (function($) {
  1060. $.namespace = 'mui';
  1061. $.classNamePrefix = $.namespace + '-';
  1062. $.classSelectorPrefix = '.' + $.classNamePrefix;
  1063. /**
  1064. * 返回正确的className
  1065. * @param {type} className
  1066. * @returns {String}
  1067. */
  1068. $.className = function(className) {
  1069. return $.classNamePrefix + className;
  1070. };
  1071. /**
  1072. * 返回正确的classSelector
  1073. * @param {type} classSelector
  1074. * @returns {String}
  1075. */
  1076. $.classSelector = function(classSelector) {
  1077. return classSelector.replace(/\./g, $.classSelectorPrefix);
  1078. };
  1079. /**
  1080. * 返回正确的eventName
  1081. * @param {type} event
  1082. * @param {type} module
  1083. * @returns {String}
  1084. */
  1085. $.eventName = function(event, module) {
  1086. return event + ($.namespace ? ('.' + $.namespace) : '') + ( module ? ('.' + module) : '');
  1087. };
  1088. })(mui);
  1089. /**
  1090. * mui gestures
  1091. * @param {type} $
  1092. * @param {type} window
  1093. * @returns {undefined}
  1094. */
  1095. (function($, window) {
  1096. $.gestures = {
  1097. session: {}
  1098. };
  1099. /**
  1100. * Gesture preventDefault
  1101. * @param {type} e
  1102. * @returns {undefined}
  1103. */
  1104. $.preventDefault = function(e) {
  1105. e.preventDefault();
  1106. };
  1107. /**
  1108. * Gesture stopPropagation
  1109. * @param {type} e
  1110. * @returns {undefined}
  1111. */
  1112. $.stopPropagation = function(e) {
  1113. e.stopPropagation();
  1114. };
  1115. /**
  1116. * register gesture
  1117. * @param {type} gesture
  1118. * @returns {$.gestures}
  1119. */
  1120. $.addGesture = function(gesture) {
  1121. return $.addAction('gestures', gesture);
  1122. };
  1123. var round = Math.round;
  1124. var abs = Math.abs;
  1125. var sqrt = Math.sqrt;
  1126. var atan = Math.atan;
  1127. var atan2 = Math.atan2;
  1128. /**
  1129. * distance
  1130. * @param {type} p1
  1131. * @param {type} p2
  1132. * @returns {Number}
  1133. */
  1134. var getDistance = function(p1, p2, props) {
  1135. if (!props) {
  1136. props = ['x', 'y'];
  1137. }
  1138. var x = p2[props[0]] - p1[props[0]];
  1139. var y = p2[props[1]] - p1[props[1]];
  1140. return sqrt((x * x) + (y * y));
  1141. };
  1142. /**
  1143. * scale
  1144. * @param {Object} starts
  1145. * @param {Object} moves
  1146. */
  1147. var getScale = function(starts, moves) {
  1148. if (starts.length >= 2 && moves.length >= 2) {
  1149. var props = ['pageX', 'pageY'];
  1150. return getDistance(moves[1], moves[0], props) / getDistance(starts[1], starts[0], props);
  1151. }
  1152. return 1;
  1153. };
  1154. /**
  1155. * angle
  1156. * @param {type} p1
  1157. * @param {type} p2
  1158. * @returns {Number}
  1159. */
  1160. var getAngle = function(p1, p2, props) {
  1161. if (!props) {
  1162. props = ['x', 'y'];
  1163. }
  1164. var x = p2[props[0]] - p1[props[0]];
  1165. var y = p2[props[1]] - p1[props[1]];
  1166. return atan2(y, x) * 180 / Math.PI;
  1167. };
  1168. /**
  1169. * direction
  1170. * @param {Object} x
  1171. * @param {Object} y
  1172. */
  1173. var getDirection = function(x, y) {
  1174. if (x === y) {
  1175. return '';
  1176. }
  1177. if (abs(x) >= abs(y)) {
  1178. return x > 0 ? 'left' : 'right';
  1179. }
  1180. return y > 0 ? 'up' : 'down';
  1181. };
  1182. /**
  1183. * rotation
  1184. * @param {Object} start
  1185. * @param {Object} end
  1186. */
  1187. var getRotation = function(start, end) {
  1188. var props = ['pageX', 'pageY'];
  1189. return getAngle(end[1], end[0], props) - getAngle(start[1], start[0], props);
  1190. };
  1191. /**
  1192. * px per ms
  1193. * @param {Object} deltaTime
  1194. * @param {Object} x
  1195. * @param {Object} y
  1196. */
  1197. var getVelocity = function(deltaTime, x, y) {
  1198. return {
  1199. x: x / deltaTime || 0,
  1200. y: y / deltaTime || 0
  1201. };
  1202. };
  1203. /**
  1204. * detect gestures
  1205. * @param {type} event
  1206. * @param {type} touch
  1207. * @returns {undefined}
  1208. */
  1209. var detect = function(event, touch) {
  1210. if ($.gestures.stoped) {
  1211. return;
  1212. }
  1213. $.doAction('gestures', function(index, gesture) {
  1214. if (!$.gestures.stoped) {
  1215. if ($.options.gestureConfig[gesture.name] !== false) {
  1216. gesture.handle(event, touch);
  1217. }
  1218. }
  1219. });
  1220. };
  1221. /**
  1222. * 暂时无用
  1223. * @param {Object} node
  1224. * @param {Object} parent
  1225. */
  1226. var hasParent = function(node, parent) {
  1227. while (node) {
  1228. if (node == parent) {
  1229. return true;
  1230. }
  1231. node = node.parentNode;
  1232. }
  1233. return false;
  1234. };
  1235. var uniqueArray = function(src, key, sort) {
  1236. var results = [];
  1237. var values = [];
  1238. var i = 0;
  1239. while (i < src.length) {
  1240. var val = key ? src[i][key] : src[i];
  1241. if (values.indexOf(val) < 0) {
  1242. results.push(src[i]);
  1243. }
  1244. values[i] = val;
  1245. i++;
  1246. }
  1247. if (sort) {
  1248. if (!key) {
  1249. results = results.sort();
  1250. } else {
  1251. results = results.sort(function sortUniqueArray(a, b) {
  1252. return a[key] > b[key];
  1253. });
  1254. }
  1255. }
  1256. return results;
  1257. };
  1258. var getMultiCenter = function(touches) {
  1259. var touchesLength = touches.length;
  1260. if (touchesLength === 1) {
  1261. return {
  1262. x: round(touches[0].pageX),
  1263. y: round(touches[0].pageY)
  1264. };
  1265. }
  1266. var x = 0;
  1267. var y = 0;
  1268. var i = 0;
  1269. while (i < touchesLength) {
  1270. x += touches[i].pageX;
  1271. y += touches[i].pageY;
  1272. i++;
  1273. }
  1274. return {
  1275. x: round(x / touchesLength),
  1276. y: round(y / touchesLength)
  1277. };
  1278. };
  1279. var multiTouch = function() {
  1280. return $.options.gestureConfig.pinch;
  1281. };
  1282. var copySimpleTouchData = function(touch) {
  1283. var touches = [];
  1284. var i = 0;
  1285. while (i < touch.touches.length) {
  1286. touches[i] = {
  1287. pageX: round(touch.touches[i].pageX),
  1288. pageY: round(touch.touches[i].pageY)
  1289. };
  1290. i++;
  1291. }
  1292. return {
  1293. timestamp: $.now(),
  1294. gesture: touch.gesture,
  1295. touches: touches,
  1296. center: getMultiCenter(touch.touches),
  1297. deltaX: touch.deltaX,
  1298. deltaY: touch.deltaY
  1299. };
  1300. };
  1301. var calDelta = function(touch) {
  1302. var session = $.gestures.session;
  1303. var center = touch.center;
  1304. var offset = session.offsetDelta || {};
  1305. var prevDelta = session.prevDelta || {};
  1306. var prevTouch = session.prevTouch || {};
  1307. if (touch.gesture.type === $.EVENT_START || touch.gesture.type === $.EVENT_END) {
  1308. prevDelta = session.prevDelta = {
  1309. x: prevTouch.deltaX || 0,
  1310. y: prevTouch.deltaY || 0
  1311. };
  1312. offset = session.offsetDelta = {
  1313. x: center.x,
  1314. y: center.y
  1315. };
  1316. }
  1317. touch.deltaX = prevDelta.x + (center.x - offset.x);
  1318. touch.deltaY = prevDelta.y + (center.y - offset.y);
  1319. };
  1320. var calTouchData = function(touch) {
  1321. var session = $.gestures.session;
  1322. var touches = touch.touches;
  1323. var touchesLength = touches.length;
  1324. if (!session.firstTouch) {
  1325. session.firstTouch = copySimpleTouchData(touch);
  1326. }
  1327. if (multiTouch() && touchesLength > 1 && !session.firstMultiTouch) {
  1328. session.firstMultiTouch = copySimpleTouchData(touch);
  1329. } else if (touchesLength === 1) {
  1330. session.firstMultiTouch = false;
  1331. }
  1332. var firstTouch = session.firstTouch;
  1333. var firstMultiTouch = session.firstMultiTouch;
  1334. var offsetCenter = firstMultiTouch ? firstMultiTouch.center : firstTouch.center;
  1335. var center = touch.center = getMultiCenter(touches);
  1336. touch.timestamp = $.now();
  1337. touch.deltaTime = touch.timestamp - firstTouch.timestamp;
  1338. touch.angle = getAngle(offsetCenter, center);
  1339. touch.distance = getDistance(offsetCenter, center);
  1340. calDelta(touch);
  1341. touch.offsetDirection = getDirection(touch.deltaX, touch.deltaY);
  1342. touch.scale = firstMultiTouch ? getScale(firstMultiTouch.touches, touches) : 1;
  1343. touch.rotation = firstMultiTouch ? getRotation(firstMultiTouch.touches, touches) : 0;
  1344. calIntervalTouchData(touch);
  1345. };
  1346. var CAL_INTERVAL = 25;
  1347. var calIntervalTouchData = function(touch) {
  1348. var session = $.gestures.session;
  1349. var last = session.lastInterval || touch;
  1350. var deltaTime = touch.timestamp - last.timestamp;
  1351. var velocity;
  1352. var velocityX;
  1353. var velocityY;
  1354. var direction;
  1355. if (touch.gesture.type != $.EVENT_CANCEL && (deltaTime > CAL_INTERVAL || last.velocity === undefined)) {
  1356. var deltaX = last.deltaX - touch.deltaX;
  1357. var deltaY = last.deltaY - touch.deltaY;
  1358. var v = getVelocity(deltaTime, deltaX, deltaY);
  1359. velocityX = v.x;
  1360. velocityY = v.y;
  1361. velocity = (abs(v.x) > abs(v.y)) ? v.x : v.y;
  1362. direction = getDirection(deltaX, deltaY) || last.direction;
  1363. session.lastInterval = touch;
  1364. } else {
  1365. velocity = last.velocity;
  1366. velocityX = last.velocityX;
  1367. velocityY = last.velocityY;
  1368. direction = last.direction;
  1369. }
  1370. touch.velocity = velocity;
  1371. touch.velocityX = velocityX;
  1372. touch.velocityY = velocityY;
  1373. touch.direction = direction;
  1374. };
  1375. var targetIds = {};
  1376. var convertTouches = function(touches) {
  1377. for (var i = 0; i < touches.length; i++) {
  1378. !touches['identifier'] && (touches['identifier'] = 0);
  1379. }
  1380. return touches;
  1381. };
  1382. var getTouches = function(event, touch) {
  1383. var allTouches = convertTouches($.slice.call(event.touches || [event]));
  1384. var type = event.type;
  1385. var targetTouches = [];
  1386. var changedTargetTouches = [];
  1387. //当touchstart或touchmove且touches长度为1,直接获得all和changed
  1388. if ((type === $.EVENT_START || type === $.EVENT_MOVE) && allTouches.length === 1) {
  1389. targetIds[allTouches[0].identifier] = true;
  1390. targetTouches = allTouches;
  1391. changedTargetTouches = allTouches;
  1392. touch.target = event.target;
  1393. } else {
  1394. var i = 0;
  1395. var targetTouches = [];
  1396. var changedTargetTouches = [];
  1397. var changedTouches = convertTouches($.slice.call(event.changedTouches || [event]));
  1398. touch.target = event.target;
  1399. var sessionTarget = $.gestures.session.target || event.target;
  1400. targetTouches = allTouches.filter(function(touch) {
  1401. return hasParent(touch.target, sessionTarget);
  1402. });
  1403. if (type === $.EVENT_START) {
  1404. i = 0;
  1405. while (i < targetTouches.length) {
  1406. targetIds[targetTouches[i].identifier] = true;
  1407. i++;
  1408. }
  1409. }
  1410. i = 0;
  1411. while (i < changedTouches.length) {
  1412. if (targetIds[changedTouches[i].identifier]) {
  1413. changedTargetTouches.push(changedTouches[i]);
  1414. }
  1415. if (type === $.EVENT_END || type === $.EVENT_CANCEL) {
  1416. delete targetIds[changedTouches[i].identifier];
  1417. }
  1418. i++;
  1419. }
  1420. if (!changedTargetTouches.length) {
  1421. return false;
  1422. }
  1423. }
  1424. targetTouches = uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true);
  1425. var touchesLength = targetTouches.length;
  1426. var changedTouchesLength = changedTargetTouches.length;
  1427. if (type === $.EVENT_START && touchesLength - changedTouchesLength === 0) { //first
  1428. touch.isFirst = true;
  1429. $.gestures.touch = $.gestures.session = {
  1430. target: event.target
  1431. };
  1432. }
  1433. touch.isFinal = ((type === $.EVENT_END || type === $.EVENT_CANCEL) && (touchesLength - changedTouchesLength === 0));
  1434. touch.touches = targetTouches;
  1435. touch.changedTouches = changedTargetTouches;
  1436. return true;
  1437. };
  1438. var handleTouchEvent = function(event) {
  1439. var touch = {
  1440. gesture: event
  1441. };
  1442. var touches = getTouches(event, touch);
  1443. if (!touches) {
  1444. return;
  1445. }
  1446. calTouchData(touch);
  1447. detect(event, touch);
  1448. $.gestures.session.prevTouch = touch;
  1449. if (event.type === $.EVENT_END && !$.isTouchable) {
  1450. $.gestures.touch = $.gestures.session = {};
  1451. }
  1452. };
  1453. window.addEventListener($.EVENT_START, handleTouchEvent);
  1454. window.addEventListener($.EVENT_MOVE, handleTouchEvent);
  1455. window.addEventListener($.EVENT_END, handleTouchEvent);
  1456. window.addEventListener($.EVENT_CANCEL, handleTouchEvent);
  1457. //fixed hashchange(android)
  1458. window.addEventListener($.EVENT_CLICK, function(e) {
  1459. //TODO 应该判断当前target是不是在targets.popover内部,而不是非要相等
  1460. if (($.os.android || $.os.ios) && (($.targets.popover && e.target === $.targets.popover) || ($.targets.tab) || $.targets.offcanvas || $.targets.modal)) {
  1461. e.preventDefault();
  1462. }
  1463. }, true);
  1464. //增加原生滚动识别
  1465. $.isScrolling = false;
  1466. var scrollingTimeout = null;
  1467. window.addEventListener('scroll', function() {
  1468. $.isScrolling = true;
  1469. scrollingTimeout && clearTimeout(scrollingTimeout);
  1470. scrollingTimeout = setTimeout(function() {
  1471. $.isScrolling = false;
  1472. }, 250);
  1473. });
  1474. })(mui, window);
  1475. /**
  1476. * mui gesture flick[left|right|up|down]
  1477. * @param {type} $
  1478. * @param {type} name
  1479. * @returns {undefined}
  1480. */
  1481. (function($, name) {
  1482. var flickStartTime = 0;
  1483. var handle = function(event, touch) {
  1484. var session = $.gestures.session;
  1485. var options = this.options;
  1486. var now = $.now();
  1487. switch (event.type) {
  1488. case $.EVENT_MOVE:
  1489. if (now - flickStartTime > 300) {
  1490. flickStartTime = now;
  1491. session.flickStart = touch.center;
  1492. }
  1493. break;
  1494. case $.EVENT_END:
  1495. case $.EVENT_CANCEL:
  1496. touch.flick = false;
  1497. if (session.flickStart && options.flickMaxTime > (now - flickStartTime) && touch.distance > options.flickMinDistince) {
  1498. touch.flick = true;
  1499. touch.flickTime = now - flickStartTime;
  1500. touch.flickDistanceX = touch.center.x - session.flickStart.x;
  1501. touch.flickDistanceY = touch.center.y - session.flickStart.y;
  1502. $.trigger(session.target, name, touch);
  1503. $.trigger(session.target, name + touch.direction, touch);
  1504. }
  1505. break;
  1506. }
  1507. };
  1508. /**
  1509. * mui gesture flick
  1510. */
  1511. $.addGesture({
  1512. name: name,
  1513. index: 5,
  1514. handle: handle,
  1515. options: {
  1516. flickMaxTime: 200,
  1517. flickMinDistince: 10
  1518. }
  1519. });
  1520. })(mui, 'flick');
  1521. /**
  1522. * mui gesture swipe[left|right|up|down]
  1523. * @param {type} $
  1524. * @param {type} name
  1525. * @returns {undefined}
  1526. */
  1527. (function($, name) {
  1528. var handle = function(event, touch) {
  1529. var session = $.gestures.session;
  1530. if (event.type === $.EVENT_END || event.type === $.EVENT_CANCEL) {
  1531. var options = this.options;
  1532. touch.swipe = false;
  1533. //TODO 后续根据velocity计算
  1534. if (touch.direction && options.swipeMaxTime > touch.deltaTime && touch.distance > options.swipeMinDistince) {
  1535. touch.swipe = true;
  1536. $.trigger(session.target, name, touch);
  1537. $.trigger(session.target, name + touch.direction, touch);
  1538. }
  1539. }
  1540. };
  1541. /**
  1542. * mui gesture swipe
  1543. */
  1544. $.addGesture({
  1545. name: name,
  1546. index: 10,
  1547. handle: handle,
  1548. options: {
  1549. swipeMaxTime: 300,
  1550. swipeMinDistince: 18
  1551. }
  1552. });
  1553. })(mui, 'swipe');
  1554. /**
  1555. * mui gesture drag[start|left|right|up|down|end]
  1556. * @param {type} $
  1557. * @param {type} name
  1558. * @returns {undefined}
  1559. */
  1560. (function($, name) {
  1561. var handle = function(event, touch) {
  1562. var session = $.gestures.session;
  1563. switch (event.type) {
  1564. case $.EVENT_START:
  1565. break;
  1566. case $.EVENT_MOVE:
  1567. if (!touch.direction || !session.target) {
  1568. return;
  1569. }
  1570. //修正direction,可在session期间自行锁定拖拽方向,方便开发scroll类不同方向拖拽插件嵌套
  1571. if (session.lockDirection && session.startDirection) {
  1572. if (session.startDirection && session.startDirection !== touch.direction) {
  1573. if (session.startDirection === 'up' || session.startDirection === 'down') {
  1574. touch.direction = touch.deltaY < 0 ? 'up' : 'down';
  1575. } else {
  1576. touch.direction = touch.deltaX < 0 ? 'left' : 'right';
  1577. }
  1578. }
  1579. }
  1580. if (!session.drag) {
  1581. session.drag = true;
  1582. $.trigger(session.target, name + 'start', touch);
  1583. }
  1584. $.trigger(session.target, name, touch);
  1585. $.trigger(session.target, name + touch.direction, touch);
  1586. break;
  1587. case $.EVENT_END:
  1588. case $.EVENT_CANCEL:
  1589. if (session.drag && touch.isFinal) {
  1590. $.trigger(session.target, name + 'end', touch);
  1591. }
  1592. break;
  1593. }
  1594. };
  1595. /**
  1596. * mui gesture drag
  1597. */
  1598. $.addGesture({
  1599. name: name,
  1600. index: 20,
  1601. handle: handle,
  1602. options: {
  1603. fingers: 1
  1604. }
  1605. });
  1606. })(mui, 'drag');
  1607. /**
  1608. * mui gesture tap and doubleTap
  1609. * @param {type} $
  1610. * @param {type} name
  1611. * @returns {undefined}
  1612. */
  1613. (function($, name) {
  1614. var lastTarget;
  1615. var lastTapTime;
  1616. var handle = function(event, touch) {
  1617. var session = $.gestures.session;
  1618. var options = this.options;
  1619. switch (event.type) {
  1620. case $.EVENT_END:
  1621. if (!touch.isFinal) {
  1622. return;
  1623. }
  1624. var target = session.target;
  1625. if (!target || (target.disabled || (target.classList && target.classList.contains('mui-disabled')))) {
  1626. return;
  1627. }
  1628. if (touch.distance < options.tapMaxDistance && touch.deltaTime < options.tapMaxTime) {
  1629. if ($.options.gestureConfig.doubletap && lastTarget && (lastTarget === target)) { //same target
  1630. if (lastTapTime && (touch.timestamp - lastTapTime) < options.tapMaxInterval) {
  1631. $.trigger(target, 'doubletap', touch);
  1632. lastTapTime = $.now();
  1633. lastTarget = target;
  1634. return;
  1635. }
  1636. }
  1637. $.trigger(target, name, touch);
  1638. lastTapTime = $.now();
  1639. lastTarget = target;
  1640. }
  1641. break;
  1642. }
  1643. };
  1644. /**
  1645. * mui gesture tap
  1646. */
  1647. $.addGesture({
  1648. name: name,
  1649. index: 30,
  1650. handle: handle,
  1651. options: {
  1652. fingers: 1,
  1653. tapMaxInterval: 300,
  1654. tapMaxDistance: 5,
  1655. tapMaxTime: 250
  1656. }
  1657. });
  1658. })(mui, 'tap');
  1659. /**
  1660. * mui gesture longtap
  1661. * @param {type} $
  1662. * @param {type} name
  1663. * @returns {undefined}
  1664. */
  1665. (function($, name) {
  1666. var timer;
  1667. var handle = function(event, touch) {
  1668. var session = $.gestures.session;
  1669. var options = this.options;
  1670. switch (event.type) {
  1671. case $.EVENT_START:
  1672. clearTimeout(timer);
  1673. timer = setTimeout(function() {
  1674. $.trigger(session.target, name, touch);
  1675. }, options.holdTimeout);
  1676. break;
  1677. case $.EVENT_MOVE:
  1678. if (touch.distance > options.holdThreshold) {
  1679. clearTimeout(timer);
  1680. }
  1681. break;
  1682. case $.EVENT_END:
  1683. case $.EVENT_CANCEL:
  1684. clearTimeout(timer);
  1685. break;
  1686. }
  1687. };
  1688. /**
  1689. * mui gesture longtap
  1690. */
  1691. $.addGesture({
  1692. name: name,
  1693. index: 10,
  1694. handle: handle,
  1695. options: {
  1696. fingers: 1,
  1697. holdTimeout: 500,
  1698. holdThreshold: 2
  1699. }
  1700. });
  1701. })(mui, 'longtap');
  1702. /**
  1703. * mui gesture hold
  1704. * @param {type} $
  1705. * @param {type} name
  1706. * @returns {undefined}
  1707. */
  1708. (function($, name) {
  1709. var timer;
  1710. var handle = function(event, touch) {
  1711. var session = $.gestures.session;
  1712. var options = this.options;
  1713. switch (event.type) {
  1714. case $.EVENT_START:
  1715. if ($.options.gestureConfig.hold) {
  1716. timer && clearTimeout(timer);
  1717. timer = setTimeout(function() {
  1718. touch.hold = true;
  1719. $.trigger(session.target, name, touch);
  1720. }, options.holdTimeout);
  1721. }
  1722. break;
  1723. case $.EVENT_MOVE:
  1724. break;
  1725. case $.EVENT_END:
  1726. case $.EVENT_CANCEL:
  1727. if (timer) {
  1728. clearTimeout(timer) && (timer = null);
  1729. $.trigger(session.target, 'release', touch);
  1730. }
  1731. break;
  1732. }
  1733. };
  1734. /**
  1735. * mui gesture hold
  1736. */
  1737. $.addGesture({
  1738. name: name,
  1739. index: 10,
  1740. handle: handle,
  1741. options: {
  1742. fingers: 1,
  1743. holdTimeout: 0
  1744. }
  1745. });
  1746. })(mui, 'hold');
  1747. /**
  1748. * mui gesture pinch
  1749. * @param {type} $
  1750. * @param {type} name
  1751. * @returns {undefined}
  1752. */
  1753. (function($, name) {
  1754. var handle = function(event, touch) {
  1755. var options = this.options;
  1756. var session = $.gestures.session;
  1757. switch (event.type) {
  1758. case $.EVENT_START:
  1759. break;
  1760. case $.EVENT_MOVE:
  1761. if ($.options.gestureConfig.pinch) {
  1762. if (touch.touches.length < 2) {
  1763. return;
  1764. }
  1765. if (!session.pinch) { //start
  1766. session.pinch = true;
  1767. $.trigger(session.target, name + 'start', touch);
  1768. }
  1769. $.trigger(session.target, name, touch);
  1770. var scale = touch.scale;
  1771. var rotation = touch.rotation;
  1772. var lastScale = typeof touch.lastScale === 'undefined' ? 1 : touch.lastScale;
  1773. var scaleDiff = 0.000000000001; //防止scale与lastScale相等,不触发事件的情况。
  1774. if (scale > lastScale) { //out
  1775. lastScale = scale - scaleDiff;
  1776. $.trigger(session.target, name + 'out', touch);
  1777. } //in
  1778. else if (scale < lastScale) {
  1779. lastScale = scale + scaleDiff;
  1780. $.trigger(session.target, name + 'in', touch);
  1781. }
  1782. if (Math.abs(rotation) > options.minRotationAngle) {
  1783. $.trigger(session.target, 'rotate', touch);
  1784. }
  1785. }
  1786. break;
  1787. case $.EVENT_END:
  1788. case $.EVENT_CANCEL:
  1789. if ($.options.gestureConfig.pinch && session.pinch && touch.touches.length === 2) {
  1790. session.pinch = false;
  1791. $.trigger(session.target, name + 'end', touch);
  1792. }
  1793. break;
  1794. }
  1795. };
  1796. /**
  1797. * mui gesture pinch
  1798. */
  1799. $.addGesture({
  1800. name: name,
  1801. index: 10,
  1802. handle: handle,
  1803. options: {
  1804. minRotationAngle: 0
  1805. }
  1806. });
  1807. })(mui, 'pinch');
  1808. /**
  1809. * mui.init
  1810. * @param {type} $
  1811. * @returns {undefined}
  1812. */
  1813. (function($) {
  1814. $.global = $.options = {
  1815. gestureConfig: {
  1816. tap: true,
  1817. doubletap: false,
  1818. longtap: false,
  1819. hold: false,
  1820. flick: true,
  1821. swipe: true,
  1822. drag: true,
  1823. pinch: false
  1824. }
  1825. };
  1826. /**
  1827. *
  1828. * @param {type} options
  1829. * @returns {undefined}
  1830. */
  1831. $.initGlobal = function(options) {
  1832. $.options = $.extend(true, $.global, options);
  1833. return this;
  1834. };
  1835. var inits = {};
  1836. /**
  1837. * 单页配置 初始化
  1838. * @param {object} options
  1839. */
  1840. $.init = function(options) {
  1841. $.options = $.extend(true, $.global, options || {});
  1842. $.ready(function() {
  1843. $.doAction('inits', function(index, init) {
  1844. var isInit = !!(!inits[init.name] || init.repeat);
  1845. if (isInit) {
  1846. init.handle.call($);
  1847. inits[init.name] = true;
  1848. }
  1849. });
  1850. });
  1851. return this;
  1852. };
  1853. /**
  1854. * 增加初始化执行流程
  1855. * @param {function} init
  1856. */
  1857. $.addInit = function(init) {
  1858. return $.addAction('inits', init);
  1859. };
  1860. /**
  1861. * 处理html5版本subpages
  1862. */
  1863. $.addInit({
  1864. name: 'iframe',
  1865. index: 100,
  1866. handle: function() {
  1867. var options = $.options;
  1868. var subpages = options.subpages || [];
  1869. if (!$.os.plus && subpages.length) {
  1870. //暂时只处理单个subpage。后续可以考虑支持多个subpage
  1871. createIframe(subpages[0]);
  1872. }
  1873. }
  1874. });
  1875. var createIframe = function(options) {
  1876. var wrapper = document.createElement('div');
  1877. wrapper.className = 'mui-iframe-wrapper';
  1878. var styles = options.styles || {};
  1879. if (typeof styles.top !== 'string') {
  1880. styles.top = '0px';
  1881. }
  1882. if (typeof styles.bottom !== 'string') {
  1883. styles.bottom = '0px';
  1884. }
  1885. wrapper.style.top = styles.top;
  1886. wrapper.style.bottom = styles.bottom;
  1887. var iframe = document.createElement('iframe');
  1888. iframe.src = options.url;
  1889. iframe.id = options.id || options.url;
  1890. iframe.name = iframe.id;
  1891. wrapper.appendChild(iframe);
  1892. document.body.appendChild(wrapper);
  1893. //目前仅处理微信
  1894. $.os.wechat && handleScroll(wrapper, iframe);
  1895. };
  1896. function handleScroll(wrapper, iframe) {
  1897. var key = 'MUI_SCROLL_POSITION_' + document.location.href + '_' + iframe.src;
  1898. var scrollTop = (parseFloat(localStorage.getItem(key)) || 0);
  1899. if (scrollTop) {
  1900. (function(y) {
  1901. iframe.onload = function() {
  1902. window.scrollTo(0, y);
  1903. };
  1904. })(scrollTop);
  1905. }
  1906. setInterval(function() {
  1907. var _scrollTop = window.scrollY;
  1908. if (scrollTop !== _scrollTop) {
  1909. localStorage.setItem(key, _scrollTop + '');
  1910. scrollTop = _scrollTop;
  1911. }
  1912. }, 100);
  1913. };
  1914. $(function() {
  1915. var classList = document.body.classList;
  1916. var os = [];
  1917. if ($.os.ios) {
  1918. os.push({
  1919. os: 'ios',
  1920. version: $.os.version
  1921. });
  1922. classList.add('mui-ios');
  1923. } else if ($.os.android) {
  1924. os.push({
  1925. os: 'android',
  1926. version: $.os.version
  1927. });
  1928. classList.add('mui-android');
  1929. }
  1930. if ($.os.wechat) {
  1931. os.push({
  1932. os: 'wechat',
  1933. version: $.os.wechat.version
  1934. });
  1935. classList.add('mui-wechat');
  1936. }
  1937. if (os.length) {
  1938. $.each(os, function(index, osObj) {
  1939. var version = '';
  1940. var classArray = [];
  1941. if (osObj.version) {
  1942. $.each(osObj.version.split('.'), function(i, v) {
  1943. version = version + (version ? '-' : '') + v;
  1944. classList.add($.className(osObj.os + '-' + version));
  1945. });
  1946. }
  1947. });
  1948. }
  1949. });
  1950. })(mui);
  1951. /**
  1952. * mui.init 5+
  1953. * @param {type} $
  1954. * @returns {undefined}
  1955. */
  1956. (function($) {
  1957. var defaultOptions = {
  1958. swipeBack: false,
  1959. preloadPages: [], //5+ lazyLoad webview
  1960. preloadLimit: 10, //预加载窗口的数量限制(一旦超出,先进先出)
  1961. keyEventBind: {
  1962. backbutton: true,
  1963. menubutton: true
  1964. },
  1965. titleConfig: {
  1966. height: "44px",
  1967. backgroundColor: "#f7f7f7", //导航栏背景色
  1968. bottomBorderColor: "#cccccc", //底部边线颜色
  1969. title: { //标题配置
  1970. text: "", //标题文字
  1971. position: {
  1972. top: 0,
  1973. left: 0,
  1974. width: "100%",
  1975. height: "100%"
  1976. },
  1977. styles: {
  1978. color: "#000000",
  1979. align: "center",
  1980. family: "'Helvetica Neue',Helvetica,sans-serif",
  1981. size: "17px",
  1982. style: "normal",
  1983. weight: "normal",
  1984. fontSrc: ""
  1985. }
  1986. },
  1987. back: {
  1988. image: {
  1989. base64Data: '',
  1990. imgSrc: '',
  1991. sprite: {
  1992. top: '0px',
  1993. left: '0px',
  1994. width: '100%',
  1995. height: '100%'
  1996. },
  1997. position: {
  1998. top: "10px",
  1999. left: "10px",
  2000. width: "24px",
  2001. height: "24px"
  2002. }
  2003. }
  2004. }
  2005. }
  2006. };
  2007. //默认页面动画
  2008. var defaultShow = {
  2009. event:"titleUpdate",
  2010. autoShow: true,
  2011. duration: 300,
  2012. aniShow: 'slide-in-right',
  2013. extras:{}
  2014. };
  2015. //若执行了显示动画初始化操作,则要覆盖默认配置
  2016. if($.options.show) {
  2017. defaultShow = $.extend(true, defaultShow, $.options.show);
  2018. }
  2019. $.currentWebview = null;
  2020. $.extend(true, $.global, defaultOptions);
  2021. $.extend(true, $.options, defaultOptions);
  2022. /**
  2023. * 等待动画配置
  2024. * @param {type} options
  2025. * @returns {Object}
  2026. */
  2027. $.waitingOptions = function(options) {
  2028. return $.extend(true, {}, {
  2029. autoShow: true,
  2030. title: '',
  2031. modal: false
  2032. }, options);
  2033. };
  2034. /**
  2035. * 窗口显示配置
  2036. * @param {type} options
  2037. * @returns {Object}
  2038. */
  2039. $.showOptions = function(options) {
  2040. return $.extend(true, {}, defaultShow, options);
  2041. };
  2042. /**
  2043. * 窗口默认配置
  2044. * @param {type} options
  2045. * @returns {Object}
  2046. */
  2047. $.windowOptions = function(options) {
  2048. return $.extend({
  2049. scalable: false,
  2050. bounce: "" //vertical
  2051. }, options);
  2052. };
  2053. /**
  2054. * plusReady
  2055. * @param {type} callback
  2056. * @returns {_L6.$}
  2057. */
  2058. $.plusReady = function(callback) {
  2059. if(window.plus) {
  2060. setTimeout(function() { //解决callback与plusready事件的执行时机问题(典型案例:showWaiting,closeWaiting)
  2061. callback();
  2062. }, 0);
  2063. } else {
  2064. document.addEventListener("plusready", function() {
  2065. callback();
  2066. }, false);
  2067. }
  2068. return this;
  2069. };
  2070. /**
  2071. * 5+ event(5+没提供之前我自己实现)
  2072. * @param {type} webview
  2073. * @param {type} eventType
  2074. * @param {type} data
  2075. * @returns {undefined}
  2076. */
  2077. $.fire = function(webview, eventType, data) {
  2078. if(webview) {
  2079. if(typeof data === 'undefined') {
  2080. data = '';
  2081. } else if(typeof data === 'boolean' || typeof data === 'number') {
  2082. webview.evalJS("typeof mui!=='undefined'&&mui.receive('" + eventType + "'," + data + ")");
  2083. return;
  2084. } else if($.isPlainObject(data) || $.isArray(data)) {
  2085. data = JSON.stringify(data || {}).replace(/\'/g, "\\u0027").replace(/\\/g, "\\u005c");
  2086. }
  2087. webview.evalJS("typeof mui!=='undefined'&&mui.receive('" + eventType + "','" + data + "')");
  2088. }
  2089. };
  2090. /**
  2091. * 5+ event(5+没提供之前我自己实现)
  2092. * @param {type} eventType
  2093. * @param {type} data
  2094. * @returns {undefined}
  2095. */
  2096. $.receive = function(eventType, data) {
  2097. if(eventType) {
  2098. try {
  2099. if(data && typeof data === 'string') {
  2100. data = JSON.parse(data);
  2101. }
  2102. } catch(e) {}
  2103. $.trigger(document, eventType, data);
  2104. }
  2105. };
  2106. var triggerPreload = function(webview) {
  2107. if(!webview.preloaded) { //保证仅触发一次
  2108. $.fire(webview, 'preload');
  2109. var list = webview.children();
  2110. for(var i = 0; i < list.length; i++) {
  2111. $.fire(list[i], 'preload');
  2112. }
  2113. webview.preloaded = true;
  2114. }
  2115. };
  2116. var trigger = function(webview, eventType, timeChecked) {
  2117. if(timeChecked) {
  2118. if(!webview[eventType + 'ed']) {
  2119. $.fire(webview, eventType);
  2120. var list = webview.children();
  2121. for(var i = 0; i < list.length; i++) {
  2122. $.fire(list[i], eventType);
  2123. }
  2124. webview[eventType + 'ed'] = true;
  2125. }
  2126. } else {
  2127. $.fire(webview, eventType);
  2128. var list = webview.children();
  2129. for(var i = 0; i < list.length; i++) {
  2130. $.fire(list[i], eventType);
  2131. }
  2132. }
  2133. };
  2134. /**
  2135. * 打开新窗口
  2136. * @param {string} url 要打开的页面地址
  2137. * @param {string} id 指定页面ID
  2138. * @param {object} options 可选:参数,等待,窗口,显示配置{params:{},waiting:{},styles:{},show:{}}
  2139. */
  2140. $.openWindow = function(url, id, options) {
  2141. if(typeof url === 'object') {
  2142. options = url;
  2143. url = options.url;
  2144. id = options.id || url;
  2145. } else {
  2146. if(typeof id === 'object') {
  2147. options = id;
  2148. id = options.id || url;
  2149. } else {
  2150. id = id || url;
  2151. }
  2152. }
  2153. if(!$.os.plus) {
  2154. //TODO 先临时这么处理:手机上顶层跳,PC上parent跳
  2155. if($.os.ios || $.os.android) {
  2156. window.top.location.href = url;
  2157. } else {
  2158. window.parent.location.href = url;
  2159. }
  2160. return;
  2161. }
  2162. if(!window.plus) {
  2163. return;
  2164. }
  2165. options = options || {};
  2166. var params = options.params || {};
  2167. var webview = null,
  2168. webviewCache = null,
  2169. nShow, nWaiting;
  2170. if($.webviews[id]) {
  2171. webviewCache = $.webviews[id];
  2172. //webview真实存在,才能获取
  2173. if(plus.webview.getWebviewById(id)) {
  2174. webview = webviewCache.webview;
  2175. }
  2176. } else if(options.createNew !== true) {
  2177. webview = plus.webview.getWebviewById(id);
  2178. }
  2179. if(webview) { //已缓存
  2180. //每次show都需要传递动画参数;
  2181. //预加载的动画参数优先级:openWindow配置>preloadPages配置>mui默认配置;
  2182. nShow = webviewCache ? webviewCache.show : defaultShow;
  2183. nShow = options.show ? $.extend(nShow, options.show) : nShow;
  2184. nShow.autoShow && webview.show(nShow.aniShow, nShow.duration, function() {
  2185. triggerPreload(webview);
  2186. trigger(webview, 'pagebeforeshow', false);
  2187. });
  2188. if(webviewCache) {
  2189. webviewCache.afterShowMethodName && webview.evalJS(webviewCache.afterShowMethodName + '(\'' + JSON.stringify(params) + '\')');
  2190. }
  2191. return webview;
  2192. } else { //新窗口
  2193. if(!url) {
  2194. throw new Error('webview[' + id + '] does not exist');
  2195. }
  2196. //显示waiting
  2197. var waitingConfig = $.waitingOptions(options.waiting);
  2198. if(waitingConfig.autoShow) {
  2199. nWaiting = plus.nativeUI.showWaiting(waitingConfig.title, waitingConfig.options);
  2200. }
  2201. //创建页面
  2202. options = $.extend(options, {
  2203. id: id,
  2204. url: url
  2205. });
  2206. webview = $.createWindow(options);
  2207. //显示
  2208. nShow = $.showOptions(options.show);
  2209. if(nShow.autoShow) {
  2210. var showWebview = function() {
  2211. //关闭等待框
  2212. if(nWaiting) {
  2213. nWaiting.close();
  2214. }
  2215. //显示页面
  2216. webview.show(nShow.aniShow, nShow.duration, function() {},nShow.extras);
  2217. options.afterShowMethodName && webview.evalJS(options.afterShowMethodName + '(\'' + JSON.stringify(params) + '\')');
  2218. };
  2219. //titleUpdate触发时机早于loaded,更换为titleUpdate后,可以更早的显示webview
  2220. webview.addEventListener(nShow.event, showWebview, false);
  2221. //loaded事件发生后,触发预加载和pagebeforeshow事件
  2222. webview.addEventListener("loaded", function() {
  2223. triggerPreload(webview);
  2224. trigger(webview, 'pagebeforeshow', false);
  2225. }, false);
  2226. }
  2227. }
  2228. return webview;
  2229. };
  2230. $.openWindowWithTitle = function(options, titleConfig) {
  2231. options = options || {};
  2232. var url = options.url;
  2233. var id = options.id || url;
  2234. if(!$.os.plus) {
  2235. //TODO 先临时这么处理:手机上顶层跳,PC上parent跳
  2236. if($.os.ios || $.os.android) {
  2237. window.top.location.href = url;
  2238. } else {
  2239. window.parent.location.href = url;
  2240. }
  2241. return;
  2242. }
  2243. if(!window.plus) {
  2244. return;
  2245. }
  2246. var params = options.params || {};
  2247. var webview = null,
  2248. webviewCache = null,
  2249. nShow, nWaiting;
  2250. if($.webviews[id]) {
  2251. webviewCache = $.webviews[id];
  2252. //webview真实存在,才能获取
  2253. if(plus.webview.getWebviewById(id)) {
  2254. webview = webviewCache.webview;
  2255. }
  2256. } else if(options.createNew !== true) {
  2257. webview = plus.webview.getWebviewById(id);
  2258. }
  2259. if(webview) { //已缓存
  2260. //每次show都需要传递动画参数;
  2261. //预加载的动画参数优先级:openWindow配置>preloadPages配置>mui默认配置;
  2262. nShow = webviewCache ? webviewCache.show : defaultShow;
  2263. nShow = options.show ? $.extend(nShow, options.show) : nShow;
  2264. nShow.autoShow && webview.show(nShow.aniShow, nShow.duration, function() {
  2265. triggerPreload(webview);
  2266. trigger(webview, 'pagebeforeshow', false);
  2267. });
  2268. if(webviewCache) {
  2269. webviewCache.afterShowMethodName && webview.evalJS(webviewCache.afterShowMethodName + '(\'' + JSON.stringify(params) + '\')');
  2270. }
  2271. return webview;
  2272. } else { //新窗口
  2273. if(!url) {
  2274. throw new Error('webview[' + id + '] does not exist');
  2275. }
  2276. //显示waiting
  2277. var waitingConfig = $.waitingOptions(options.waiting);
  2278. if(waitingConfig.autoShow) {
  2279. nWaiting = plus.nativeUI.showWaiting(waitingConfig.title, waitingConfig.options);
  2280. }
  2281. //创建页面
  2282. options = $.extend(options, {
  2283. id: id,
  2284. url: url
  2285. });
  2286. webview = $.createWindow(options);
  2287. if(titleConfig) { //处理原生头
  2288. $.extend(true, $.options.titleConfig, titleConfig);
  2289. var tid = $.options.titleConfig.id ? $.options.titleConfig.id : id + "_title";
  2290. var view = new plus.nativeObj.View(tid, {
  2291. top: 0,
  2292. height: $.options.titleConfig.height,
  2293. width: "100%",
  2294. dock: "top",
  2295. position: "dock"
  2296. });
  2297. view.drawRect($.options.titleConfig.backgroundColor); //绘制背景色
  2298. var _b = parseInt($.options.titleConfig.height) - 1;
  2299. view.drawRect($.options.titleConfig.bottomBorderColor, {
  2300. top: _b + "px",
  2301. left: "0px"
  2302. }); //绘制底部边线
  2303. //绘制文字
  2304. if($.options.titleConfig.title.text){
  2305. var _title = $.options.titleConfig.title;
  2306. view.drawText(_title.text,_title.position , _title.styles);
  2307. }
  2308. //返回图标绘制
  2309. var _back = $.options.titleConfig.back;
  2310. var backClick = null;
  2311. //优先字体
  2312. //其次是图片
  2313. var _backImage = _back.image;
  2314. if(_backImage.base64Data || _backImage.imgSrc) {
  2315. //TODO 此处需要处理百分比的情况
  2316. backClick = {
  2317. left:parseInt(_backImage.position.left),
  2318. right:parseInt(_backImage.position.left) + parseInt(_backImage.position.width)
  2319. };
  2320. var bitmap = new plus.nativeObj.Bitmap(id + "_back");
  2321. if(_backImage.base64Data) { //优先base64编码字符串
  2322. bitmap.loadBase64Data(_backImage.base64Data);
  2323. } else { //其次加载图片文件
  2324. bitmap.load(_backImage.imgSrc);
  2325. }
  2326. view.drawBitmap(bitmap,_backImage.sprite , _backImage.position);
  2327. }
  2328. //处理点击事件
  2329. view.setTouchEventRect({
  2330. top: "0px",
  2331. left: "0px",
  2332. width: "100%",
  2333. height: "100%"
  2334. });
  2335. view.interceptTouchEvent(true);
  2336. view.addEventListener("click", function(e) {
  2337. var x = e.clientX;
  2338. //返回按钮点击
  2339. if(backClick&& x > backClick.left && x < backClick.right){
  2340. if( _back.click && $.isFunction(_back.click)){
  2341. _back.click();
  2342. }else{
  2343. webview.evalJS("window.mui&&mui.back();");
  2344. }
  2345. }
  2346. }, false);
  2347. webview.append(view);
  2348. }
  2349. //显示
  2350. nShow = $.showOptions(options.show);
  2351. if(nShow.autoShow) {
  2352. //titleUpdate触发时机早于loaded,更换为titleUpdate后,可以更早的显示webview
  2353. webview.addEventListener(nShow.event, function () {
  2354. //关闭等待框
  2355. if(nWaiting) {
  2356. nWaiting.close();
  2357. }
  2358. //显示页面
  2359. webview.show(nShow.aniShow, nShow.duration, function() {},nShow.extras);
  2360. }, false);
  2361. }
  2362. }
  2363. return webview;
  2364. };
  2365. /**
  2366. * 根据配置信息创建一个webview
  2367. * @param {type} options
  2368. * @param {type} isCreate
  2369. * @returns {webview}
  2370. */
  2371. $.createWindow = function(options, isCreate) {
  2372. if(!window.plus) {
  2373. return;
  2374. }
  2375. var id = options.id || options.url;
  2376. var webview;
  2377. if(options.preload) {
  2378. if($.webviews[id] && $.webviews[id].webview.getURL()) { //已经cache
  2379. webview = $.webviews[id].webview;
  2380. } else { //新增预加载窗口
  2381. //判断是否携带createNew参数,默认为false
  2382. if(options.createNew !== true) {
  2383. webview = plus.webview.getWebviewById(id);
  2384. }
  2385. //之前没有,那就新创建
  2386. if(!webview) {
  2387. webview = plus.webview.create(options.url, id, $.windowOptions(options.styles), $.extend({
  2388. preload: true
  2389. }, options.extras));
  2390. if(options.subpages) {
  2391. $.each(options.subpages, function(index, subpage) {
  2392. var subpageId = subpage.id || subpage.url;
  2393. if(subpageId) { //过滤空对象
  2394. var subWebview = plus.webview.getWebviewById(subpageId);
  2395. if(!subWebview) { //如果该webview不存在,则创建
  2396. subWebview = plus.webview.create(subpage.url, subpageId, $.windowOptions(subpage.styles), $.extend({
  2397. preload: true
  2398. }, subpage.extras));
  2399. }
  2400. webview.append(subWebview);
  2401. }
  2402. });
  2403. }
  2404. }
  2405. }
  2406. //TODO 理论上,子webview也应该计算到预加载队列中,但这样就麻烦了,要退必须退整体,否则可能出现问题;
  2407. $.webviews[id] = {
  2408. webview: webview, //目前仅preload的缓存webview
  2409. preload: true,
  2410. show: $.showOptions(options.show),
  2411. afterShowMethodName: options.afterShowMethodName //就不应该用evalJS。应该是通过事件消息通讯
  2412. };
  2413. //索引该预加载窗口
  2414. var preloads = $.data.preloads;
  2415. var index = preloads.indexOf(id);
  2416. if(~index) { //删除已存在的(变相调整插入位置)
  2417. preloads.splice(index, 1);
  2418. }
  2419. preloads.push(id);
  2420. if(preloads.length > $.options.preloadLimit) {
  2421. //先进先出
  2422. var first = $.data.preloads.shift();
  2423. var webviewCache = $.webviews[first];
  2424. if(webviewCache && webviewCache.webview) {
  2425. //需要将自己打开的所有页面,全部close;
  2426. //关闭该预加载webview
  2427. $.closeAll(webviewCache.webview);
  2428. }
  2429. //删除缓存
  2430. delete $.webviews[first];
  2431. }
  2432. } else {
  2433. if(isCreate !== false) { //直接创建非预加载窗口
  2434. webview = plus.webview.create(options.url, id, $.windowOptions(options.styles), options.extras);
  2435. if(options.subpages) {
  2436. $.each(options.subpages, function(index, subpage) {
  2437. var subpageId = subpage.id || subpage.url;
  2438. var subWebview = plus.webview.getWebviewById(subpageId);
  2439. if(!subWebview) {
  2440. subWebview = plus.webview.create(subpage.url, subpageId, $.windowOptions(subpage.styles), subpage.extras);
  2441. }
  2442. webview.append(subWebview);
  2443. });
  2444. }
  2445. }
  2446. }
  2447. return webview;
  2448. };
  2449. /**
  2450. * 预加载
  2451. */
  2452. $.preload = function(options) {
  2453. //调用预加载函数,不管是否传递preload参数,强制变为true
  2454. if(!options.preload) {
  2455. options.preload = true;
  2456. }
  2457. return $.createWindow(options);
  2458. };
  2459. /**
  2460. *关闭当前webview打开的所有webview;
  2461. */
  2462. $.closeOpened = function(webview) {
  2463. var opened = webview.opened();
  2464. if(opened) {
  2465. for(var i = 0, len = opened.length; i < len; i++) {
  2466. var openedWebview = opened[i];
  2467. var open_open = openedWebview.opened();
  2468. if(open_open && open_open.length > 0) {
  2469. //关闭打开的webview
  2470. $.closeOpened(openedWebview);
  2471. //关闭自己
  2472. openedWebview.close("none");
  2473. } else {
  2474. //如果直接孩子节点,就不用关闭了,因为父关闭的时候,会自动关闭子;
  2475. if(openedWebview.parent() !== webview) {
  2476. openedWebview.close('none');
  2477. }
  2478. }
  2479. }
  2480. }
  2481. };
  2482. $.closeAll = function(webview, aniShow) {
  2483. $.closeOpened(webview);
  2484. if(aniShow) {
  2485. webview.close(aniShow);
  2486. } else {
  2487. webview.close();
  2488. }
  2489. };
  2490. /**
  2491. * 批量创建webview
  2492. * @param {type} options
  2493. * @returns {undefined}
  2494. */
  2495. $.createWindows = function(options) {
  2496. $.each(options, function(index, option) {
  2497. //初始化预加载窗口(创建)和非预加载窗口(仅配置,不创建)
  2498. $.createWindow(option, false);
  2499. });
  2500. };
  2501. /**
  2502. * 创建当前页面的子webview
  2503. * @param {type} options
  2504. * @returns {webview}
  2505. */
  2506. $.appendWebview = function(options) {
  2507. if(!window.plus) {
  2508. return;
  2509. }
  2510. var id = options.id || options.url;
  2511. var webview;
  2512. if(!$.webviews[id]) { //保证执行一遍
  2513. //TODO 这里也有隐患,比如某个webview不是作为subpage创建的,而是作为target webview的话;
  2514. if(!plus.webview.getWebviewById(id)) {
  2515. webview = plus.webview.create(options.url, id, options.styles, options.extras);
  2516. }
  2517. //之前的实现方案:子窗口loaded之后再append到父窗口中;
  2518. //问题:部分子窗口loaded事件发生较晚,此时执行父窗口的children方法会返回空,导致父子通讯失败;
  2519. // 比如父页面执行完preload事件后,需触发子页面的preload事件,此时未append的话,就无法触发;
  2520. //修改方式:不再监控loaded事件,直接append
  2521. //by chb@20150521
  2522. // webview.addEventListener('loaded', function() {
  2523. plus.webview.currentWebview().append(webview);
  2524. // });
  2525. $.webviews[id] = options;
  2526. }
  2527. return webview;
  2528. };
  2529. //全局webviews
  2530. $.webviews = {};
  2531. //预加载窗口索引
  2532. $.data.preloads = [];
  2533. //$.currentWebview
  2534. $.plusReady(function() {
  2535. $.currentWebview = plus.webview.currentWebview();
  2536. });
  2537. $.addInit({
  2538. name: '5+',
  2539. index: 100,
  2540. handle: function() {
  2541. var options = $.options;
  2542. var subpages = options.subpages || [];
  2543. if($.os.plus) {
  2544. $.plusReady(function() {
  2545. //TODO 这里需要判断一下,最好等子窗口加载完毕后,再调用主窗口的show方法;
  2546. //或者:在openwindow方法中,监听实现;
  2547. $.each(subpages, function(index, subpage) {
  2548. $.appendWebview(subpage);
  2549. });
  2550. //判断是否首页
  2551. if(plus.webview.currentWebview() === plus.webview.getWebviewById(plus.runtime.appid)) {
  2552. //首页需要自己激活预加载;
  2553. //timeout因为子页面loaded之后才append的,防止子页面尚未append、从而导致其preload未触发的问题;
  2554. setTimeout(function() {
  2555. triggerPreload(plus.webview.currentWebview());
  2556. }, 300);
  2557. }
  2558. //设置ios顶部状态栏颜色;
  2559. if($.os.ios && $.options.statusBarBackground) {
  2560. plus.navigator.setStatusBarBackground($.options.statusBarBackground);
  2561. }
  2562. if($.os.android && parseFloat($.os.version) < 4.4) {
  2563. //解决Android平台4.4版本以下,resume后,父窗体标题延迟渲染的问题;
  2564. if(plus.webview.currentWebview().parent() == null) {
  2565. document.addEventListener("resume", function() {
  2566. var body = document.body;
  2567. body.style.display = 'none';
  2568. setTimeout(function() {
  2569. body.style.display = '';
  2570. }, 10);
  2571. });
  2572. }
  2573. }
  2574. });
  2575. } else {
  2576. //已支持iframe嵌入
  2577. // if (subpages.length > 0) {
  2578. // var err = document.createElement('div');
  2579. // err.className = 'mui-error';
  2580. // //文字描述
  2581. // var span = document.createElement('span');
  2582. // span.innerHTML = '在该浏览器下,不支持创建子页面,具体参考';
  2583. // err.appendChild(span);
  2584. // var a = document.createElement('a');
  2585. // a.innerHTML = '"mui框架适用场景"';
  2586. // a.href = 'http://ask.dcloud.net.cn/article/113';
  2587. // err.appendChild(a);
  2588. // document.body.appendChild(err);
  2589. // console.log('在该浏览器下,不支持创建子页面');
  2590. // }
  2591. }
  2592. }
  2593. });
  2594. window.addEventListener('preload', function() {
  2595. //处理预加载部分
  2596. var webviews = $.options.preloadPages || [];
  2597. $.plusReady(function() {
  2598. $.each(webviews, function(index, webview) {
  2599. $.createWindow($.extend(webview, {
  2600. preload: true
  2601. }));
  2602. });
  2603. });
  2604. });
  2605. $.supportStatusbarOffset = function() {
  2606. return $.os.plus && $.os.ios && parseFloat($.os.version) >= 7;
  2607. };
  2608. $.ready(function() {
  2609. //标识当前环境支持statusbar
  2610. if($.supportStatusbarOffset()) {
  2611. document.body.classList.add('mui-statusbar');
  2612. }
  2613. });
  2614. })(mui);
  2615. /**
  2616. * mui back
  2617. * @param {type} $
  2618. * @param {type} window
  2619. * @returns {undefined}
  2620. */
  2621. (function($, window) {
  2622. /**
  2623. * register back
  2624. * @param {type} back
  2625. * @returns {$.gestures}
  2626. */
  2627. $.addBack = function(back) {
  2628. return $.addAction('backs', back);
  2629. };
  2630. /**
  2631. * default
  2632. */
  2633. $.addBack({
  2634. name: 'browser',
  2635. index: 100,
  2636. handle: function() {
  2637. if (window.history.length > 1) {
  2638. window.history.back();
  2639. return true;
  2640. }
  2641. return false;
  2642. }
  2643. });
  2644. /**
  2645. * 后退
  2646. */
  2647. $.back = function() {
  2648. if (typeof $.options.beforeback === 'function') {
  2649. if ($.options.beforeback() === false) {
  2650. return;
  2651. }
  2652. }
  2653. $.doAction('backs');
  2654. };
  2655. window.addEventListener('tap', function(e) {
  2656. var action = $.targets.action;
  2657. if (action && action.classList.contains('mui-action-back')) {
  2658. $.back();
  2659. $.targets.action = false;
  2660. }
  2661. });
  2662. window.addEventListener('swiperight', function(e) {
  2663. var detail = e.detail;
  2664. if ($.options.swipeBack === true && Math.abs(detail.angle) < 3) {
  2665. $.back();
  2666. }
  2667. });
  2668. })(mui, window);
  2669. /**
  2670. * mui back 5+
  2671. * @param {type} $
  2672. * @param {type} window
  2673. * @returns {undefined}
  2674. */
  2675. (function($, window) {
  2676. if ($.os.plus && $.os.android) {
  2677. $.addBack({
  2678. name: 'mui',
  2679. index: 5,
  2680. handle: function() {
  2681. //后续重新设计此处,将back放到各个空间内部实现
  2682. //popover
  2683. if ($.targets._popover && $.targets._popover.classList.contains('mui-active')) {
  2684. $($.targets._popover).popover('hide');
  2685. return true;
  2686. }
  2687. //offcanvas
  2688. var offCanvas = document.querySelector('.mui-off-canvas-wrap.mui-active');
  2689. if (offCanvas) {
  2690. $(offCanvas).offCanvas('close');
  2691. return true;
  2692. }
  2693. var previewImage = $.isFunction($.getPreviewImage) && $.getPreviewImage();
  2694. if (previewImage && previewImage.isShown()) {
  2695. previewImage.close();
  2696. return true;
  2697. }
  2698. //popup
  2699. return $.closePopup();
  2700. }
  2701. });
  2702. }
  2703. //首次按下back按键的时间
  2704. $.__back__first = null;
  2705. /**
  2706. * 5+ back
  2707. */
  2708. $.addBack({
  2709. name: '5+',
  2710. index: 10,
  2711. handle: function() {
  2712. if (!window.plus) {
  2713. return false;
  2714. }
  2715. var wobj = plus.webview.currentWebview();
  2716. var parent = wobj.parent();
  2717. if (parent) {
  2718. parent.evalJS('mui&&mui.back();');
  2719. } else {
  2720. wobj.canBack(function(e) {
  2721. //by chb 暂时注释,在碰到类似popover之类的锚点的时候,需多次点击才能返回;
  2722. if (e.canBack) { //webview history back
  2723. window.history.back();
  2724. } else { //webview close or hide
  2725. //fixed by fxy 此处不应该用opener判断,因为用户有可能自己close掉当前窗口的opener。这样的话。opener就为空了,导致不能执行close
  2726. if (wobj.id === plus.runtime.appid) { //首页
  2727. //首页不存在opener的情况下,后退实际上应该是退出应用;
  2728. //首次按键,提示‘再按一次退出应用’
  2729. if (!$.__back__first) {
  2730. $.__back__first = new Date().getTime();
  2731. mui.toast('再按一次退出应用');
  2732. setTimeout(function() {
  2733. $.__back__first = null;
  2734. }, 2000);
  2735. } else {
  2736. if (new Date().getTime() - $.__back__first < 2000) {
  2737. plus.runtime.quit();
  2738. }
  2739. }
  2740. } else { //其他页面,
  2741. if (wobj.preload) {
  2742. wobj.hide("auto");
  2743. } else {
  2744. //关闭页面时,需要将其打开的所有子页面全部关闭;
  2745. $.closeAll(wobj);
  2746. }
  2747. }
  2748. }
  2749. });
  2750. }
  2751. return true;
  2752. }
  2753. });
  2754. $.menu = function() {
  2755. var menu = document.querySelector('.mui-action-menu');
  2756. if (menu) {
  2757. $.trigger(menu, $.EVENT_START); //临时处理menu无touchstart的话,找不到当前targets的问题
  2758. $.trigger(menu, 'tap');
  2759. } else { //执行父窗口的menu
  2760. if (window.plus) {
  2761. var wobj = $.currentWebview;
  2762. var parent = wobj.parent();
  2763. if (parent) { //又得evalJS
  2764. parent.evalJS('mui&&mui.menu();');
  2765. }
  2766. }
  2767. }
  2768. };
  2769. var __back = function() {
  2770. $.back();
  2771. };
  2772. var __menu = function() {
  2773. $.menu();
  2774. };
  2775. //默认监听
  2776. $.plusReady(function() {
  2777. if ($.options.keyEventBind.backbutton) {
  2778. plus.key.addEventListener('backbutton', __back, false);
  2779. }
  2780. if ($.options.keyEventBind.menubutton) {
  2781. plus.key.addEventListener('menubutton', __menu, false);
  2782. }
  2783. });
  2784. //处理按键监听事件
  2785. $.addInit({
  2786. name: 'keyEventBind',
  2787. index: 1000,
  2788. handle: function() {
  2789. $.plusReady(function() {
  2790. //如果不为true,则移除默认监听
  2791. if (!$.options.keyEventBind.backbutton) {
  2792. plus.key.removeEventListener('backbutton', __back);
  2793. }
  2794. if (!$.options.keyEventBind.menubutton) {
  2795. plus.key.removeEventListener('menubutton', __menu);
  2796. }
  2797. });
  2798. }
  2799. });
  2800. })(mui, window);
  2801. /**
  2802. * mui.init pulldownRefresh
  2803. * @param {type} $
  2804. * @returns {undefined}
  2805. */
  2806. (function($) {
  2807. $.addInit({
  2808. name: 'pullrefresh',
  2809. index: 1000,
  2810. handle: function() {
  2811. var options = $.options;
  2812. var pullRefreshOptions = options.pullRefresh || {};
  2813. var hasPulldown = pullRefreshOptions.down && pullRefreshOptions.down.hasOwnProperty('callback');
  2814. var hasPullup = pullRefreshOptions.up && pullRefreshOptions.up.hasOwnProperty('callback');
  2815. if(hasPulldown || hasPullup) {
  2816. var container = pullRefreshOptions.container;
  2817. if(container) {
  2818. var $container = $(container);
  2819. if($container.length === 1) {
  2820. if($.os.plus) { //5+环境
  2821. if(hasPulldown && pullRefreshOptions.down.style == "circle") { //原生转圈
  2822. $.plusReady(function() {
  2823. //这里改写$.fn.pullRefresh
  2824. $.fn.pullRefresh = $.fn.pullRefresh_native;
  2825. $container.pullRefresh(pullRefreshOptions);
  2826. });
  2827. } else if($.os.android) { //非原生转圈,但是Android环境
  2828. $.plusReady(function() {
  2829. //这里改写$.fn.pullRefresh
  2830. $.fn.pullRefresh = $.fn.pullRefresh_native
  2831. var webview = plus.webview.currentWebview();
  2832. if(window.__NWin_Enable__ === false) { //不支持多webview
  2833. $container.pullRefresh(pullRefreshOptions);
  2834. } else {
  2835. if(hasPullup) {
  2836. //当前页面初始化pullup
  2837. var upOptions = {};
  2838. upOptions.up = pullRefreshOptions.up;
  2839. upOptions.webviewId = webview.id || webview.getURL();
  2840. $container.pullRefresh(upOptions);
  2841. }
  2842. if(hasPulldown) {
  2843. var parent = webview.parent();
  2844. var id = webview.id || webview.getURL();
  2845. if(parent) {
  2846. if(!hasPullup) { //如果没有上拉加载,需要手动初始化一个默认的pullRefresh,以便当前页面容器可以调用endPulldownToRefresh等方法
  2847. $container.pullRefresh({
  2848. webviewId: id
  2849. });
  2850. }
  2851. var downOptions = {
  2852. webviewId: id//子页面id
  2853. };
  2854. downOptions.down = $.extend({}, pullRefreshOptions.down);
  2855. downOptions.down.callback = '_CALLBACK';
  2856. //改写父页面的$.fn.pullRefresh
  2857. parent.evalJS("mui.fn.pullRefresh=mui.fn.pullRefresh_native");
  2858. //父页面初始化pulldown
  2859. parent.evalJS("mui&&mui(document.querySelector('.mui-content')).pullRefresh('" + JSON.stringify(downOptions) + "')");
  2860. }
  2861. }
  2862. }
  2863. });
  2864. } else { //非原生转圈,iOS环境
  2865. $container.pullRefresh(pullRefreshOptions);
  2866. }
  2867. } else {
  2868. $container.pullRefresh(pullRefreshOptions);
  2869. }
  2870. }
  2871. }
  2872. }
  2873. }
  2874. });
  2875. })(mui);
  2876. /**
  2877. * mui ajax
  2878. * @param {type} $
  2879. * @returns {undefined}
  2880. */
  2881. (function($, window, undefined) {
  2882. var jsonType = 'application/json';
  2883. var htmlType = 'text/html';
  2884. var rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
  2885. var scriptTypeRE = /^(?:text|application)\/javascript/i;
  2886. var xmlTypeRE = /^(?:text|application)\/xml/i;
  2887. var blankRE = /^\s*$/;
  2888. $.ajaxSettings = {
  2889. type: 'GET',
  2890. beforeSend: $.noop,
  2891. success: $.noop,
  2892. error: $.noop,
  2893. complete: $.noop,
  2894. context: null,
  2895. xhr: function(protocol) {
  2896. return new window.XMLHttpRequest();
  2897. },
  2898. accepts: {
  2899. script: 'text/javascript, application/javascript, application/x-javascript',
  2900. json: jsonType,
  2901. xml: 'application/xml, text/xml',
  2902. html: htmlType,
  2903. text: 'text/plain'
  2904. },
  2905. timeout: 0,
  2906. processData: true,
  2907. cache: true
  2908. };
  2909. var ajaxBeforeSend = function(xhr, settings) {
  2910. var context = settings.context
  2911. if(settings.beforeSend.call(context, xhr, settings) === false) {
  2912. return false;
  2913. }
  2914. };
  2915. var ajaxSuccess = function(data, xhr, settings) {
  2916. settings.success.call(settings.context, data, 'success', xhr);
  2917. ajaxComplete('success', xhr, settings);
  2918. };
  2919. // type: "timeout", "error", "abort", "parsererror"
  2920. var ajaxError = function(error, type, xhr, settings) {
  2921. settings.error.call(settings.context, xhr, type, error);
  2922. ajaxComplete(type, xhr, settings);
  2923. };
  2924. // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
  2925. var ajaxComplete = function(status, xhr, settings) {
  2926. settings.complete.call(settings.context, xhr, status);
  2927. };
  2928. var serialize = function(params, obj, traditional, scope) {
  2929. var type, array = $.isArray(obj),
  2930. hash = $.isPlainObject(obj);
  2931. $.each(obj, function(key, value) {
  2932. type = $.type(value);
  2933. if(scope) {
  2934. key = traditional ? scope :
  2935. scope + '[' + (hash || type === 'object' || type === 'array' ? key : '') + ']';
  2936. }
  2937. // handle data in serializeArray() format
  2938. if(!scope && array) {
  2939. params.add(value.name, value.value);
  2940. }
  2941. // recurse into nested objects
  2942. else if(type === "array" || (!traditional && type === "object")) {
  2943. serialize(params, value, traditional, key);
  2944. } else {
  2945. params.add(key, value);
  2946. }
  2947. });
  2948. };
  2949. var serializeData = function(options) {
  2950. if(options.processData && options.data && typeof options.data !== "string") {
  2951. var contentType = options.contentType;
  2952. if(!contentType && options.headers) {
  2953. contentType = options.headers['Content-Type'];
  2954. }
  2955. if(contentType && ~contentType.indexOf(jsonType)) { //application/json
  2956. options.data = JSON.stringify(options.data);
  2957. } else {
  2958. options.data = $.param(options.data, options.traditional);
  2959. }
  2960. }
  2961. if(options.data && (!options.type || options.type.toUpperCase() === 'GET')) {
  2962. options.url = appendQuery(options.url, options.data);
  2963. options.data = undefined;
  2964. }
  2965. };
  2966. var appendQuery = function(url, query) {
  2967. if(query === '') {
  2968. return url;
  2969. }
  2970. return(url + '&' + query).replace(/[&?]{1,2}/, '?');
  2971. };
  2972. var mimeToDataType = function(mime) {
  2973. if(mime) {
  2974. mime = mime.split(';', 2)[0];
  2975. }
  2976. return mime && (mime === htmlType ? 'html' :
  2977. mime === jsonType ? 'json' :
  2978. scriptTypeRE.test(mime) ? 'script' :
  2979. xmlTypeRE.test(mime) && 'xml') || 'text';
  2980. };
  2981. var parseArguments = function(url, data, success, dataType) {
  2982. if($.isFunction(data)) {
  2983. dataType = success, success = data, data = undefined;
  2984. }
  2985. if(!$.isFunction(success)) {
  2986. dataType = success, success = undefined;
  2987. }
  2988. return {
  2989. url: url,
  2990. data: data,
  2991. success: success,
  2992. dataType: dataType
  2993. };
  2994. };
  2995. $.ajax = function(url, options) {
  2996. if(typeof url === "object") {
  2997. options = url;
  2998. url = undefined;
  2999. }
  3000. var settings = options || {};
  3001. settings.url = url || settings.url;
  3002. for(var key in $.ajaxSettings) {
  3003. if(settings[key] === undefined) {
  3004. settings[key] = $.ajaxSettings[key];
  3005. }
  3006. }
  3007. serializeData(settings);
  3008. var dataType = settings.dataType;
  3009. if(settings.cache === false || ((!options || options.cache !== true) && ('script' === dataType))) {
  3010. settings.url = appendQuery(settings.url, '_=' + $.now());
  3011. }
  3012. var mime = settings.accepts[dataType && dataType.toLowerCase()];
  3013. var headers = {};
  3014. var setHeader = function(name, value) {
  3015. headers[name.toLowerCase()] = [name, value];
  3016. };
  3017. var protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol;
  3018. var xhr = settings.xhr(settings);
  3019. var nativeSetHeader = xhr.setRequestHeader;
  3020. var abortTimeout;
  3021. setHeader('X-Requested-With', 'XMLHttpRequest');
  3022. setHeader('Accept', mime || '*/*');
  3023. if(!!(mime = settings.mimeType || mime)) {
  3024. if(mime.indexOf(',') > -1) {
  3025. mime = mime.split(',', 2)[0];
  3026. }
  3027. xhr.overrideMimeType && xhr.overrideMimeType(mime);
  3028. }
  3029. if(settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() !== 'GET')) {
  3030. setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded');
  3031. }
  3032. if(settings.headers) {
  3033. for(var name in settings.headers)
  3034. setHeader(name, settings.headers[name]);
  3035. }
  3036. xhr.setRequestHeader = setHeader;
  3037. xhr.onreadystatechange = function() {
  3038. if(xhr.readyState === 4) {
  3039. xhr.onreadystatechange = $.noop;
  3040. clearTimeout(abortTimeout);
  3041. var result, error = false;
  3042. var isLocal = protocol === 'file:';
  3043. if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || (xhr.status === 0 && isLocal && xhr.responseText)) {
  3044. dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'));
  3045. result = xhr.responseText;
  3046. try {
  3047. // http://perfectionkills.com/global-eval-what-are-the-options/
  3048. if(dataType === 'script') {
  3049. (1, eval)(result);
  3050. } else if(dataType === 'xml') {
  3051. result = xhr.responseXML;
  3052. } else if(dataType === 'json') {
  3053. result = blankRE.test(result) ? null : $.parseJSON(result);
  3054. }
  3055. } catch(e) {
  3056. error = e;
  3057. }
  3058. if(error) {
  3059. ajaxError(error, 'parsererror', xhr, settings);
  3060. } else {
  3061. ajaxSuccess(result, xhr, settings);
  3062. }
  3063. } else {
  3064. var status = xhr.status ? 'error' : 'abort';
  3065. var statusText = xhr.statusText || null;
  3066. if(isLocal) {
  3067. status = 'error';
  3068. statusText = '404';
  3069. }
  3070. ajaxError(statusText, status, xhr, settings);
  3071. }
  3072. }
  3073. };
  3074. if(ajaxBeforeSend(xhr, settings) === false) {
  3075. xhr.abort();
  3076. ajaxError(null, 'abort', xhr, settings);
  3077. return xhr;
  3078. }
  3079. if(settings.xhrFields) {
  3080. for(var name in settings.xhrFields) {
  3081. xhr[name] = settings.xhrFields[name];
  3082. }
  3083. }
  3084. var async = 'async' in settings ? settings.async : true;
  3085. xhr.open(settings.type.toUpperCase(), settings.url, async, settings.username, settings.password);
  3086. for(var name in headers) {
  3087. if(headers.hasOwnProperty(name)) {
  3088. nativeSetHeader.apply(xhr, headers[name]);
  3089. }
  3090. }
  3091. if(settings.timeout > 0) {
  3092. abortTimeout = setTimeout(function() {
  3093. xhr.onreadystatechange = $.noop;
  3094. xhr.abort();
  3095. ajaxError(null, 'timeout', xhr, settings);
  3096. }, settings.timeout);
  3097. }
  3098. xhr.send(settings.data ? settings.data : null);
  3099. return xhr;
  3100. };
  3101. $.param = function(obj, traditional) {
  3102. var params = [];
  3103. params.add = function(k, v) {
  3104. this.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
  3105. };
  3106. serialize(params, obj, traditional);
  3107. return params.join('&').replace(/%20/g, '+');
  3108. };
  3109. $.get = function( /* url, data, success, dataType */ ) {
  3110. return $.ajax(parseArguments.apply(null, arguments));
  3111. };
  3112. $.post = function( /* url, data, success, dataType */ ) {
  3113. var options = parseArguments.apply(null, arguments);
  3114. options.type = 'POST';
  3115. return $.ajax(options);
  3116. };
  3117. $.getJSON = function( /* url, data, success */ ) {
  3118. var options = parseArguments.apply(null, arguments);
  3119. options.dataType = 'json';
  3120. return $.ajax(options);
  3121. };
  3122. $.fn.load = function(url, data, success) {
  3123. if(!this.length)
  3124. return this;
  3125. var self = this,
  3126. parts = url.split(/\s/),
  3127. selector,
  3128. options = parseArguments(url, data, success),
  3129. callback = options.success;
  3130. if(parts.length > 1)
  3131. options.url = parts[0], selector = parts[1];
  3132. options.success = function(response) {
  3133. if(selector) {
  3134. var div = document.createElement('div');
  3135. div.innerHTML = response.replace(rscript, "");
  3136. var selectorDiv = document.createElement('div');
  3137. var childs = div.querySelectorAll(selector);
  3138. if(childs && childs.length > 0) {
  3139. for(var i = 0, len = childs.length; i < len; i++) {
  3140. selectorDiv.appendChild(childs[i]);
  3141. }
  3142. }
  3143. self[0].innerHTML = selectorDiv.innerHTML;
  3144. } else {
  3145. self[0].innerHTML = response;
  3146. }
  3147. callback && callback.apply(self, arguments);
  3148. };
  3149. $.ajax(options);
  3150. return this;
  3151. };
  3152. })(mui, window);
  3153. /**
  3154. * 5+ ajax
  3155. */
  3156. (function($) {
  3157. var originAnchor = document.createElement('a');
  3158. originAnchor.href = window.location.href;
  3159. $.plusReady(function() {
  3160. $.ajaxSettings = $.extend($.ajaxSettings, {
  3161. xhr: function(settings) {
  3162. if (settings.crossDomain) { //强制使用plus跨域
  3163. return new plus.net.XMLHttpRequest();
  3164. }
  3165. //仅在webview的url为远程文件,且ajax请求的资源不同源下使用plus.net.XMLHttpRequest
  3166. if (originAnchor.protocol !== 'file:') {
  3167. var urlAnchor = document.createElement('a');
  3168. urlAnchor.href = settings.url;
  3169. urlAnchor.href = urlAnchor.href;
  3170. settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host);
  3171. if (settings.crossDomain) {
  3172. return new plus.net.XMLHttpRequest();
  3173. }
  3174. }
  3175. if ($.os.ios && window.webkit && window.webkit.messageHandlers) { //wkwebview下同样使用5+ xhr
  3176. return new plus.net.XMLHttpRequest();
  3177. }
  3178. return new window.XMLHttpRequest();
  3179. }
  3180. });
  3181. });
  3182. })(mui);
  3183. /**
  3184. * mui layout(offset[,position,width,height...])
  3185. * @param {type} $
  3186. * @param {type} window
  3187. * @param {type} undefined
  3188. * @returns {undefined}
  3189. */
  3190. (function($, window, undefined) {
  3191. $.offset = function(element) {
  3192. var box = {
  3193. top : 0,
  3194. left : 0
  3195. };
  3196. if ( typeof element.getBoundingClientRect !== undefined) {
  3197. box = element.getBoundingClientRect();
  3198. }
  3199. return {
  3200. top : box.top + window.pageYOffset - element.clientTop,
  3201. left : box.left + window.pageXOffset - element.clientLeft
  3202. };
  3203. };
  3204. })(mui, window);
  3205. /**
  3206. * mui animation
  3207. */
  3208. (function($, window) {
  3209. /**
  3210. * scrollTo
  3211. */
  3212. $.scrollTo = function(scrollTop, duration, callback) {
  3213. duration = duration || 1000;
  3214. var scroll = function(duration) {
  3215. if (duration <= 0) {
  3216. window.scrollTo(0, scrollTop);
  3217. callback && callback();
  3218. return;
  3219. }
  3220. var distaince = scrollTop - window.scrollY;
  3221. setTimeout(function() {
  3222. window.scrollTo(0, window.scrollY + distaince / duration * 10);
  3223. scroll(duration - 10);
  3224. }, 16.7);
  3225. };
  3226. scroll(duration);
  3227. };
  3228. $.animationFrame = function(cb) {
  3229. var args, isQueued, context;
  3230. return function() {
  3231. args = arguments;
  3232. context = this;
  3233. if (!isQueued) {
  3234. isQueued = true;
  3235. requestAnimationFrame(function() {
  3236. cb.apply(context, args);
  3237. isQueued = false;
  3238. });
  3239. }
  3240. };
  3241. };
  3242. })(mui, window);
  3243. (function($) {
  3244. var initializing = false,
  3245. fnTest = /xyz/.test(function() {
  3246. xyz;
  3247. }) ? /\b_super\b/ : /.*/;
  3248. var Class = function() {};
  3249. Class.extend = function(prop) {
  3250. var _super = this.prototype;
  3251. initializing = true;
  3252. var prototype = new this();
  3253. initializing = false;
  3254. for (var name in prop) {
  3255. prototype[name] = typeof prop[name] == "function" &&
  3256. typeof _super[name] == "function" && fnTest.test(prop[name]) ?
  3257. (function(name, fn) {
  3258. return function() {
  3259. var tmp = this._super;
  3260. this._super = _super[name];
  3261. var ret = fn.apply(this, arguments);
  3262. this._super = tmp;
  3263. return ret;
  3264. };
  3265. })(name, prop[name]) :
  3266. prop[name];
  3267. }
  3268. function Class() {
  3269. if (!initializing && this.init)
  3270. this.init.apply(this, arguments);
  3271. }
  3272. Class.prototype = prototype;
  3273. Class.prototype.constructor = Class;
  3274. Class.extend = arguments.callee;
  3275. return Class;
  3276. };
  3277. $.Class = Class;
  3278. })(mui);
  3279. (function($, document, undefined) {
  3280. var CLASS_PULL_TOP_POCKET = 'mui-pull-top-pocket';
  3281. var CLASS_PULL_BOTTOM_POCKET = 'mui-pull-bottom-pocket';
  3282. var CLASS_PULL = 'mui-pull';
  3283. var CLASS_PULL_LOADING = 'mui-pull-loading';
  3284. var CLASS_PULL_CAPTION = 'mui-pull-caption';
  3285. var CLASS_PULL_CAPTION_DOWN = 'mui-pull-caption-down';
  3286. var CLASS_PULL_CAPTION_REFRESH = 'mui-pull-caption-refresh';
  3287. var CLASS_PULL_CAPTION_NOMORE = 'mui-pull-caption-nomore';
  3288. var CLASS_ICON = 'mui-icon';
  3289. var CLASS_SPINNER = 'mui-spinner';
  3290. var CLASS_ICON_PULLDOWN = 'mui-icon-pulldown';
  3291. var CLASS_BLOCK = 'mui-block';
  3292. var CLASS_HIDDEN = 'mui-hidden';
  3293. var CLASS_VISIBILITY = 'mui-visibility';
  3294. var CLASS_LOADING_UP = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_ICON_PULLDOWN;
  3295. var CLASS_LOADING_DOWN = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_ICON_PULLDOWN;
  3296. var CLASS_LOADING = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_SPINNER;
  3297. var pocketHtml = ['<div class="' + CLASS_PULL + '">', '<div class="{icon}"></div>', '<div class="' + CLASS_PULL_CAPTION + '">{contentrefresh}</div>', '</div>'].join('');
  3298. var PullRefresh = {
  3299. init: function(element, options) {
  3300. this._super(element, $.extend(true, {
  3301. scrollY: true,
  3302. scrollX: false,
  3303. indicators: true,
  3304. deceleration: 0.003,
  3305. down: {
  3306. height: 50,
  3307. contentinit: '下拉可以刷新',
  3308. contentdown: '下拉可以刷新',
  3309. contentover: '释放立即刷新',
  3310. contentrefresh: '正在刷新...'
  3311. },
  3312. up: {
  3313. height: 50,
  3314. auto: false,
  3315. contentinit: '上拉显示更多',
  3316. contentdown: '上拉显示更多',
  3317. contentrefresh: '正在加载...',
  3318. contentnomore: '没有更多数据了',
  3319. duration: 300
  3320. }
  3321. }, options));
  3322. },
  3323. _init: function() {
  3324. this._super();
  3325. this._initPocket();
  3326. },
  3327. _initPulldownRefresh: function() {
  3328. this.pulldown = true;
  3329. if (this.topPocket) {
  3330. this.pullPocket = this.topPocket;
  3331. this.pullPocket.classList.add(CLASS_BLOCK);
  3332. this.pullPocket.classList.add(CLASS_VISIBILITY);
  3333. this.pullCaption = this.topCaption;
  3334. this.pullLoading = this.topLoading;
  3335. }
  3336. },
  3337. _initPullupRefresh: function() {
  3338. this.pulldown = false;
  3339. if (this.bottomPocket) {
  3340. this.pullPocket = this.bottomPocket;
  3341. this.pullPocket.classList.add(CLASS_BLOCK);
  3342. this.pullPocket.classList.add(CLASS_VISIBILITY);
  3343. this.pullCaption = this.bottomCaption;
  3344. this.pullLoading = this.bottomLoading;
  3345. }
  3346. },
  3347. _initPocket: function() {
  3348. var options = this.options;
  3349. if (options.down && options.down.hasOwnProperty('callback')) {
  3350. this.topPocket = this.scroller.querySelector('.' + CLASS_PULL_TOP_POCKET);
  3351. if (!this.topPocket) {
  3352. this.topPocket = this._createPocket(CLASS_PULL_TOP_POCKET, options.down, CLASS_LOADING_DOWN);
  3353. this.wrapper.insertBefore(this.topPocket, this.wrapper.firstChild);
  3354. }
  3355. this.topLoading = this.topPocket.querySelector('.' + CLASS_PULL_LOADING);
  3356. this.topCaption = this.topPocket.querySelector('.' + CLASS_PULL_CAPTION);
  3357. }
  3358. if (options.up && options.up.hasOwnProperty('callback')) {
  3359. this.bottomPocket = this.scroller.querySelector('.' + CLASS_PULL_BOTTOM_POCKET);
  3360. if (!this.bottomPocket) {
  3361. this.bottomPocket = this._createPocket(CLASS_PULL_BOTTOM_POCKET, options.up, CLASS_LOADING);
  3362. this.scroller.appendChild(this.bottomPocket);
  3363. }
  3364. this.bottomLoading = this.bottomPocket.querySelector('.' + CLASS_PULL_LOADING);
  3365. this.bottomCaption = this.bottomPocket.querySelector('.' + CLASS_PULL_CAPTION);
  3366. //TODO only for h5
  3367. this.wrapper.addEventListener('scrollbottom', this);
  3368. }
  3369. },
  3370. _createPocket: function(clazz, options, iconClass) {
  3371. var pocket = document.createElement('div');
  3372. pocket.className = clazz;
  3373. pocket.innerHTML = pocketHtml.replace('{contentrefresh}', options.contentinit).replace('{icon}', iconClass);
  3374. return pocket;
  3375. },
  3376. _resetPullDownLoading: function() {
  3377. var loading = this.pullLoading;
  3378. if (loading) {
  3379. this.pullCaption.innerHTML = this.options.down.contentdown;
  3380. loading.style.webkitTransition = "";
  3381. loading.style.webkitTransform = "";
  3382. loading.style.webkitAnimation = "";
  3383. loading.className = CLASS_LOADING_DOWN;
  3384. }
  3385. },
  3386. _setCaptionClass: function(isPulldown, caption, title) {
  3387. if (!isPulldown) {
  3388. switch (title) {
  3389. case this.options.up.contentdown:
  3390. caption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_DOWN;
  3391. break;
  3392. case this.options.up.contentrefresh:
  3393. caption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_REFRESH
  3394. break;
  3395. case this.options.up.contentnomore:
  3396. caption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_NOMORE;
  3397. break;
  3398. }
  3399. }
  3400. },
  3401. _setCaption: function(title, reset) {
  3402. if (this.loading) {
  3403. return;
  3404. }
  3405. var options = this.options;
  3406. var pocket = this.pullPocket;
  3407. var caption = this.pullCaption;
  3408. var loading = this.pullLoading;
  3409. var isPulldown = this.pulldown;
  3410. var self = this;
  3411. if (pocket) {
  3412. if (reset) {
  3413. setTimeout(function() {
  3414. caption.innerHTML = self.lastTitle = title;
  3415. if (isPulldown) {
  3416. loading.className = CLASS_LOADING_DOWN;
  3417. } else {
  3418. self._setCaptionClass(false, caption, title);
  3419. loading.className = CLASS_LOADING;
  3420. }
  3421. loading.style.webkitAnimation = "";
  3422. loading.style.webkitTransition = "";
  3423. loading.style.webkitTransform = "";
  3424. }, 100);
  3425. } else {
  3426. if (title !== this.lastTitle) {
  3427. caption.innerHTML = title;
  3428. if (isPulldown) {
  3429. if (title === options.down.contentrefresh) {
  3430. loading.className = CLASS_LOADING;
  3431. loading.style.webkitAnimation = "spinner-spin 1s step-end infinite";
  3432. } else if (title === options.down.contentover) {
  3433. loading.className = CLASS_LOADING_UP;
  3434. loading.style.webkitTransition = "-webkit-transform 0.3s ease-in";
  3435. loading.style.webkitTransform = "rotate(180deg)";
  3436. } else if (title === options.down.contentdown) {
  3437. loading.className = CLASS_LOADING_DOWN;
  3438. loading.style.webkitTransition = "-webkit-transform 0.3s ease-in";
  3439. loading.style.webkitTransform = "rotate(0deg)";
  3440. }
  3441. } else {
  3442. if (title === options.up.contentrefresh) {
  3443. loading.className = CLASS_LOADING + ' ' + CLASS_VISIBILITY;
  3444. } else {
  3445. loading.className = CLASS_LOADING + ' ' + CLASS_HIDDEN;
  3446. }
  3447. self._setCaptionClass(false, caption, title);
  3448. }
  3449. this.lastTitle = title;
  3450. }
  3451. }
  3452. }
  3453. }
  3454. };
  3455. $.PullRefresh = PullRefresh;
  3456. })(mui, document);
  3457. (function($, window, document, undefined) {
  3458. var CLASS_SCROLL = 'mui-scroll';
  3459. var CLASS_SCROLLBAR = 'mui-scrollbar';
  3460. var CLASS_INDICATOR = 'mui-scrollbar-indicator';
  3461. var CLASS_SCROLLBAR_VERTICAL = CLASS_SCROLLBAR + '-vertical';
  3462. var CLASS_SCROLLBAR_HORIZONTAL = CLASS_SCROLLBAR + '-horizontal';
  3463. var CLASS_ACTIVE = 'mui-active';
  3464. var ease = {
  3465. quadratic: {
  3466. style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  3467. fn: function(k) {
  3468. return k * (2 - k);
  3469. }
  3470. },
  3471. circular: {
  3472. style: 'cubic-bezier(0.1, 0.57, 0.1, 1)',
  3473. fn: function(k) {
  3474. return Math.sqrt(1 - (--k * k));
  3475. }
  3476. },
  3477. outCirc: {
  3478. style: 'cubic-bezier(0.075, 0.82, 0.165, 1)'
  3479. },
  3480. outCubic: {
  3481. style: 'cubic-bezier(0.165, 0.84, 0.44, 1)'
  3482. }
  3483. }
  3484. var Scroll = $.Class.extend({
  3485. init: function(element, options) {
  3486. this.wrapper = this.element = element;
  3487. this.scroller = this.wrapper.children[0];
  3488. this.scrollerStyle = this.scroller && this.scroller.style;
  3489. this.stopped = false;
  3490. this.options = $.extend(true, {
  3491. scrollY: true, //是否竖向滚动
  3492. scrollX: false, //是否横向滚动
  3493. startX: 0, //初始化时滚动至x
  3494. startY: 0, //初始化时滚动至y
  3495. indicators: true, //是否显示滚动条
  3496. stopPropagation: false,
  3497. hardwareAccelerated: true,
  3498. fixedBadAndorid: false,
  3499. preventDefaultException: {
  3500. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|VIDEO)$/
  3501. },
  3502. momentum: true,
  3503. snapX: 0.5, //横向切换距离(以当前容器宽度为基准)
  3504. snap: false, //图片轮播,拖拽式选项卡
  3505. bounce: true, //是否启用回弹
  3506. bounceTime: 500, //回弹动画时间
  3507. bounceEasing: ease.outCirc, //回弹动画曲线
  3508. scrollTime: 500,
  3509. scrollEasing: ease.outCubic, //轮播动画曲线
  3510. directionLockThreshold: 5,
  3511. parallaxElement: false, //视差元素
  3512. parallaxRatio: 0.5
  3513. }, options);
  3514. this.x = 0;
  3515. this.y = 0;
  3516. this.translateZ = this.options.hardwareAccelerated ? ' translateZ(0)' : '';
  3517. this._init();
  3518. if (this.scroller) {
  3519. this.refresh();
  3520. // if (this.options.startX !== 0 || this.options.startY !== 0) { //需要判断吗?后续根据实际情况再看看
  3521. this.scrollTo(this.options.startX, this.options.startY);
  3522. // }
  3523. }
  3524. },
  3525. _init: function() {
  3526. this._initParallax();
  3527. this._initIndicators();
  3528. this._initEvent();
  3529. },
  3530. _initParallax: function() {
  3531. if (this.options.parallaxElement) {
  3532. this.parallaxElement = document.querySelector(this.options.parallaxElement);
  3533. this.parallaxStyle = this.parallaxElement.style;
  3534. this.parallaxHeight = this.parallaxElement.offsetHeight;
  3535. this.parallaxImgStyle = this.parallaxElement.querySelector('img').style;
  3536. }
  3537. },
  3538. _initIndicators: function() {
  3539. var self = this;
  3540. self.indicators = [];
  3541. if (!this.options.indicators) {
  3542. return;
  3543. }
  3544. var indicators = [],
  3545. indicator;
  3546. // Vertical scrollbar
  3547. if (self.options.scrollY) {
  3548. indicator = {
  3549. el: this._createScrollBar(CLASS_SCROLLBAR_VERTICAL),
  3550. listenX: false
  3551. };
  3552. this.wrapper.appendChild(indicator.el);
  3553. indicators.push(indicator);
  3554. }
  3555. // Horizontal scrollbar
  3556. if (this.options.scrollX) {
  3557. indicator = {
  3558. el: this._createScrollBar(CLASS_SCROLLBAR_HORIZONTAL),
  3559. listenY: false
  3560. };
  3561. this.wrapper.appendChild(indicator.el);
  3562. indicators.push(indicator);
  3563. }
  3564. for (var i = indicators.length; i--;) {
  3565. this.indicators.push(new Indicator(this, indicators[i]));
  3566. }
  3567. },
  3568. _initSnap: function() {
  3569. this.currentPage = {};
  3570. this.pages = [];
  3571. var snaps = this.snaps;
  3572. var length = snaps.length;
  3573. var m = 0;
  3574. var n = -1;
  3575. var x = 0;
  3576. var leftX = 0;
  3577. var rightX = 0;
  3578. var snapX = 0;
  3579. for (var i = 0; i < length; i++) {
  3580. var snap = snaps[i];
  3581. var offsetLeft = snap.offsetLeft;
  3582. var offsetWidth = snap.offsetWidth;
  3583. if (i === 0 || offsetLeft <= snaps[i - 1].offsetLeft) {
  3584. m = 0;
  3585. n++;
  3586. }
  3587. if (!this.pages[m]) {
  3588. this.pages[m] = [];
  3589. }
  3590. x = this._getSnapX(offsetLeft);
  3591. snapX = Math.round((offsetWidth) * this.options.snapX);
  3592. leftX = x - snapX;
  3593. rightX = x - offsetWidth + snapX;
  3594. this.pages[m][n] = {
  3595. x: x,
  3596. leftX: leftX,
  3597. rightX: rightX,
  3598. pageX: m,
  3599. element: snap
  3600. }
  3601. if (snap.classList.contains(CLASS_ACTIVE)) {
  3602. this.currentPage = this.pages[m][0];
  3603. }
  3604. if (x >= this.maxScrollX) {
  3605. m++;
  3606. }
  3607. }
  3608. this.options.startX = this.currentPage.x || 0;
  3609. },
  3610. _getSnapX: function(offsetLeft) {
  3611. return Math.max(Math.min(0, -offsetLeft + (this.wrapperWidth / 2)), this.maxScrollX);
  3612. },
  3613. _gotoPage: function(index) {
  3614. this.currentPage = this.pages[Math.min(index, this.pages.length - 1)][0];
  3615. for (var i = 0, len = this.snaps.length; i < len; i++) {
  3616. if (i === index) {
  3617. this.snaps[i].classList.add(CLASS_ACTIVE);
  3618. } else {
  3619. this.snaps[i].classList.remove(CLASS_ACTIVE);
  3620. }
  3621. }
  3622. this.scrollTo(this.currentPage.x, 0, this.options.scrollTime);
  3623. },
  3624. _nearestSnap: function(x) {
  3625. if (!this.pages.length) {
  3626. return {
  3627. x: 0,
  3628. pageX: 0
  3629. };
  3630. }
  3631. var i = 0;
  3632. var length = this.pages.length;
  3633. if (x > 0) {
  3634. x = 0;
  3635. } else if (x < this.maxScrollX) {
  3636. x = this.maxScrollX;
  3637. }
  3638. for (; i < length; i++) {
  3639. var nearestX = this.direction === 'left' ? this.pages[i][0].leftX : this.pages[i][0].rightX;
  3640. if (x >= nearestX) {
  3641. return this.pages[i][0];
  3642. }
  3643. }
  3644. return {
  3645. x: 0,
  3646. pageX: 0
  3647. };
  3648. },
  3649. _initEvent: function(detach) {
  3650. var action = detach ? 'removeEventListener' : 'addEventListener';
  3651. window[action]('orientationchange', this);
  3652. window[action]('resize', this);
  3653. this.scroller[action]('webkitTransitionEnd', this);
  3654. this.wrapper[action]($.EVENT_START, this);
  3655. this.wrapper[action]($.EVENT_CANCEL, this);
  3656. this.wrapper[action]($.EVENT_END, this);
  3657. this.wrapper[action]('drag', this);
  3658. this.wrapper[action]('dragend', this);
  3659. this.wrapper[action]('flick', this);
  3660. this.wrapper[action]('scrollend', this);
  3661. if (this.options.scrollX) {
  3662. this.wrapper[action]('swiperight', this);
  3663. }
  3664. var segmentedControl = this.wrapper.querySelector('.mui-segmented-control');
  3665. if (segmentedControl) { //靠,这个bug排查了一下午,阻止hash跳转,一旦hash跳转会导致可拖拽选项卡的tab不见
  3666. mui(segmentedControl)[detach ? 'off' : 'on']('click', 'a', $.preventDefault);
  3667. }
  3668. this.wrapper[action]('scrollstart', this);
  3669. this.wrapper[action]('refresh', this);
  3670. },
  3671. _handleIndicatorScrollend: function() {
  3672. this.indicators.map(function(indicator) {
  3673. indicator.fade();
  3674. });
  3675. },
  3676. _handleIndicatorScrollstart: function() {
  3677. this.indicators.map(function(indicator) {
  3678. indicator.fade(1);
  3679. });
  3680. },
  3681. _handleIndicatorRefresh: function() {
  3682. this.indicators.map(function(indicator) {
  3683. indicator.refresh();
  3684. });
  3685. },
  3686. handleEvent: function(e) {
  3687. if (this.stopped) {
  3688. this.resetPosition();
  3689. return;
  3690. }
  3691. switch (e.type) {
  3692. case $.EVENT_START:
  3693. this._start(e);
  3694. break;
  3695. case 'drag':
  3696. this.options.stopPropagation && e.stopPropagation();
  3697. this._drag(e);
  3698. break;
  3699. case 'dragend':
  3700. case 'flick':
  3701. this.options.stopPropagation && e.stopPropagation();
  3702. this._flick(e);
  3703. break;
  3704. case $.EVENT_CANCEL:
  3705. case $.EVENT_END:
  3706. this._end(e);
  3707. break;
  3708. case 'webkitTransitionEnd':
  3709. this.transitionTimer && this.transitionTimer.cancel();
  3710. this._transitionEnd(e);
  3711. break;
  3712. case 'scrollstart':
  3713. this._handleIndicatorScrollstart(e);
  3714. break;
  3715. case 'scrollend':
  3716. this._handleIndicatorScrollend(e);
  3717. this._scrollend(e);
  3718. e.stopPropagation();
  3719. break;
  3720. case 'orientationchange':
  3721. case 'resize':
  3722. this._resize();
  3723. break;
  3724. case 'swiperight':
  3725. e.stopPropagation();
  3726. break;
  3727. case 'refresh':
  3728. this._handleIndicatorRefresh(e);
  3729. break;
  3730. }
  3731. },
  3732. _start: function(e) {
  3733. this.moved = this.needReset = false;
  3734. this._transitionTime();
  3735. if (this.isInTransition) {
  3736. this.needReset = true;
  3737. this.isInTransition = false;
  3738. var pos = $.parseTranslateMatrix($.getStyles(this.scroller, 'webkitTransform'));
  3739. this.setTranslate(Math.round(pos.x), Math.round(pos.y));
  3740. // this.resetPosition(); //reset
  3741. $.trigger(this.scroller, 'scrollend', this);
  3742. // e.stopPropagation();
  3743. e.preventDefault();
  3744. }
  3745. this.reLayout();
  3746. $.trigger(this.scroller, 'beforescrollstart', this);
  3747. },
  3748. _getDirectionByAngle: function(angle) {
  3749. if (angle < -80 && angle > -100) {
  3750. return 'up';
  3751. } else if (angle >= 80 && angle < 100) {
  3752. return 'down';
  3753. } else if (angle >= 170 || angle <= -170) {
  3754. return 'left';
  3755. } else if (angle >= -35 && angle <= 10) {
  3756. return 'right';
  3757. }
  3758. return null;
  3759. },
  3760. _drag: function(e) {
  3761. // if (this.needReset) {
  3762. // e.stopPropagation(); //disable parent drag(nested scroller)
  3763. // return;
  3764. // }
  3765. var detail = e.detail;
  3766. if (this.options.scrollY || detail.direction === 'up' || detail.direction === 'down') { //如果是竖向滚动或手势方向是上或下
  3767. //ios8 hack
  3768. if ($.os.ios && parseFloat($.os.version) >= 8) { //多webview时,离开当前webview会导致后续touch事件不触发
  3769. var clientY = detail.gesture.touches[0].clientY;
  3770. //下拉刷新 or 上拉加载
  3771. if ((clientY + 10) > window.innerHeight || clientY < 10) {
  3772. this.resetPosition(this.options.bounceTime);
  3773. return;
  3774. }
  3775. }
  3776. }
  3777. var isPreventDefault = isReturn = false;
  3778. var direction = this._getDirectionByAngle(detail.angle);
  3779. if (detail.direction === 'left' || detail.direction === 'right') {
  3780. if (this.options.scrollX) {
  3781. isPreventDefault = true;
  3782. if (!this.moved) { //识别角度(该角度导致轮播不灵敏)
  3783. // if (direction !== 'left' && direction !== 'right') {
  3784. // isReturn = true;
  3785. // } else {
  3786. $.gestures.session.lockDirection = true; //锁定方向
  3787. $.gestures.session.startDirection = detail.direction;
  3788. // }
  3789. }
  3790. } else if (this.options.scrollY && !this.moved) {
  3791. isReturn = true;
  3792. }
  3793. } else if (detail.direction === 'up' || detail.direction === 'down') {
  3794. if (this.options.scrollY) {
  3795. isPreventDefault = true;
  3796. // if (!this.moved) { //识别角度,竖向滚动似乎没必要进行小角度验证
  3797. // if (direction !== 'up' && direction !== 'down') {
  3798. // isReturn = true;
  3799. // }
  3800. // }
  3801. if (!this.moved) {
  3802. $.gestures.session.lockDirection = true; //锁定方向
  3803. $.gestures.session.startDirection = detail.direction;
  3804. }
  3805. } else if (this.options.scrollX && !this.moved) {
  3806. isReturn = true;
  3807. }
  3808. } else {
  3809. isReturn = true;
  3810. }
  3811. if (this.moved || isPreventDefault) {
  3812. e.stopPropagation(); //阻止冒泡(scroll类嵌套)
  3813. detail.gesture && detail.gesture.preventDefault();
  3814. }
  3815. if (isReturn) { //禁止非法方向滚动
  3816. return;
  3817. }
  3818. if (!this.moved) {
  3819. $.trigger(this.scroller, 'scrollstart', this);
  3820. } else {
  3821. e.stopPropagation(); //move期间阻止冒泡(scroll嵌套)
  3822. }
  3823. var deltaX = 0;
  3824. var deltaY = 0;
  3825. if (!this.moved) { //start
  3826. deltaX = detail.deltaX;
  3827. deltaY = detail.deltaY;
  3828. } else { //move
  3829. deltaX = detail.deltaX - $.gestures.session.prevTouch.deltaX;
  3830. deltaY = detail.deltaY - $.gestures.session.prevTouch.deltaY;
  3831. }
  3832. var absDeltaX = Math.abs(detail.deltaX);
  3833. var absDeltaY = Math.abs(detail.deltaY);
  3834. if (absDeltaX > absDeltaY + this.options.directionLockThreshold) {
  3835. deltaY = 0;
  3836. } else if (absDeltaY >= absDeltaX + this.options.directionLockThreshold) {
  3837. deltaX = 0;
  3838. }
  3839. deltaX = this.hasHorizontalScroll ? deltaX : 0;
  3840. deltaY = this.hasVerticalScroll ? deltaY : 0;
  3841. var newX = this.x + deltaX;
  3842. var newY = this.y + deltaY;
  3843. // Slow down if outside of the boundaries
  3844. if (newX > 0 || newX < this.maxScrollX) {
  3845. newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX;
  3846. }
  3847. if (newY > 0 || newY < this.maxScrollY) {
  3848. newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY;
  3849. }
  3850. if (!this.requestAnimationFrame) {
  3851. this._updateTranslate();
  3852. }
  3853. this.direction = detail.deltaX > 0 ? 'right' : 'left';
  3854. this.moved = true;
  3855. this.x = newX;
  3856. this.y = newY;
  3857. $.trigger(this.scroller, 'scroll', this);
  3858. },
  3859. _flick: function(e) {
  3860. // if (!this.moved || this.needReset) {
  3861. // return;
  3862. // }
  3863. if (!this.moved) {
  3864. return;
  3865. }
  3866. e.stopPropagation();
  3867. var detail = e.detail;
  3868. this._clearRequestAnimationFrame();
  3869. if (e.type === 'dragend' && detail.flick) { //dragend
  3870. return;
  3871. }
  3872. var newX = Math.round(this.x);
  3873. var newY = Math.round(this.y);
  3874. this.isInTransition = false;
  3875. // reset if we are outside of the boundaries
  3876. if (this.resetPosition(this.options.bounceTime)) {
  3877. return;
  3878. }
  3879. this.scrollTo(newX, newY); // ensures that the last position is rounded
  3880. if (e.type === 'dragend') { //dragend
  3881. $.trigger(this.scroller, 'scrollend', this);
  3882. return;
  3883. }
  3884. var time = 0;
  3885. var easing = '';
  3886. // start momentum animation if needed
  3887. if (this.options.momentum && detail.flickTime < 300) {
  3888. momentumX = this.hasHorizontalScroll ? this._momentum(this.x, detail.flickDistanceX, detail.flickTime, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : {
  3889. destination: newX,
  3890. duration: 0
  3891. };
  3892. momentumY = this.hasVerticalScroll ? this._momentum(this.y, detail.flickDistanceY, detail.flickTime, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : {
  3893. destination: newY,
  3894. duration: 0
  3895. };
  3896. newX = momentumX.destination;
  3897. newY = momentumY.destination;
  3898. time = Math.max(momentumX.duration, momentumY.duration);
  3899. this.isInTransition = true;
  3900. }
  3901. if (newX != this.x || newY != this.y) {
  3902. if (newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY) {
  3903. easing = ease.quadratic;
  3904. }
  3905. this.scrollTo(newX, newY, time, easing);
  3906. return;
  3907. }
  3908. $.trigger(this.scroller, 'scrollend', this);
  3909. // e.stopPropagation();
  3910. },
  3911. _end: function(e) {
  3912. this.needReset = false;
  3913. if ((!this.moved && this.needReset) || e.type === $.EVENT_CANCEL) {
  3914. this.resetPosition();
  3915. }
  3916. },
  3917. _transitionEnd: function(e) {
  3918. if (e.target != this.scroller || !this.isInTransition) {
  3919. return;
  3920. }
  3921. this._transitionTime();
  3922. if (!this.resetPosition(this.options.bounceTime)) {
  3923. this.isInTransition = false;
  3924. $.trigger(this.scroller, 'scrollend', this);
  3925. }
  3926. },
  3927. _scrollend: function(e) {
  3928. if ((this.y === 0 && this.maxScrollY === 0) || (Math.abs(this.y) > 0 && this.y <= this.maxScrollY)) {
  3929. $.trigger(this.scroller, 'scrollbottom', this);
  3930. }
  3931. },
  3932. _resize: function() {
  3933. var that = this;
  3934. clearTimeout(that.resizeTimeout);
  3935. that.resizeTimeout = setTimeout(function() {
  3936. that.refresh();
  3937. }, that.options.resizePolling);
  3938. },
  3939. _transitionTime: function(time) {
  3940. time = time || 0;
  3941. this.scrollerStyle['webkitTransitionDuration'] = time + 'ms';
  3942. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  3943. this.parallaxStyle['webkitTransitionDuration'] = time + 'ms';
  3944. }
  3945. if (this.options.fixedBadAndorid && !time && $.os.isBadAndroid) {
  3946. this.scrollerStyle['webkitTransitionDuration'] = '0.001s';
  3947. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  3948. this.parallaxStyle['webkitTransitionDuration'] = '0.001s';
  3949. }
  3950. }
  3951. if (this.indicators) {
  3952. for (var i = this.indicators.length; i--;) {
  3953. this.indicators[i].transitionTime(time);
  3954. }
  3955. }
  3956. if (time) { //自定义timer,保证webkitTransitionEnd始终触发
  3957. this.transitionTimer && this.transitionTimer.cancel();
  3958. this.transitionTimer = $.later(function() {
  3959. $.trigger(this.scroller, 'webkitTransitionEnd');
  3960. }, time + 100, this);
  3961. }
  3962. },
  3963. _transitionTimingFunction: function(easing) {
  3964. this.scrollerStyle['webkitTransitionTimingFunction'] = easing;
  3965. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  3966. this.parallaxStyle['webkitTransitionDuration'] = easing;
  3967. }
  3968. if (this.indicators) {
  3969. for (var i = this.indicators.length; i--;) {
  3970. this.indicators[i].transitionTimingFunction(easing);
  3971. }
  3972. }
  3973. },
  3974. _translate: function(x, y) {
  3975. this.x = x;
  3976. this.y = y;
  3977. },
  3978. _clearRequestAnimationFrame: function() {
  3979. if (this.requestAnimationFrame) {
  3980. cancelAnimationFrame(this.requestAnimationFrame);
  3981. this.requestAnimationFrame = null;
  3982. }
  3983. },
  3984. _updateTranslate: function() {
  3985. var self = this;
  3986. if (self.x !== self.lastX || self.y !== self.lastY) {
  3987. self.setTranslate(self.x, self.y);
  3988. }
  3989. self.requestAnimationFrame = requestAnimationFrame(function() {
  3990. self._updateTranslate();
  3991. });
  3992. },
  3993. _createScrollBar: function(clazz) {
  3994. var scrollbar = document.createElement('div');
  3995. var indicator = document.createElement('div');
  3996. scrollbar.className = CLASS_SCROLLBAR + ' ' + clazz;
  3997. indicator.className = CLASS_INDICATOR;
  3998. scrollbar.appendChild(indicator);
  3999. if (clazz === CLASS_SCROLLBAR_VERTICAL) {
  4000. this.scrollbarY = scrollbar;
  4001. this.scrollbarIndicatorY = indicator;
  4002. } else if (clazz === CLASS_SCROLLBAR_HORIZONTAL) {
  4003. this.scrollbarX = scrollbar;
  4004. this.scrollbarIndicatorX = indicator;
  4005. }
  4006. this.wrapper.appendChild(scrollbar);
  4007. return scrollbar;
  4008. },
  4009. _preventDefaultException: function(el, exceptions) {
  4010. for (var i in exceptions) {
  4011. if (exceptions[i].test(el[i])) {
  4012. return true;
  4013. }
  4014. }
  4015. return false;
  4016. },
  4017. _reLayout: function() {
  4018. if (!this.hasHorizontalScroll) {
  4019. this.maxScrollX = 0;
  4020. this.scrollerWidth = this.wrapperWidth;
  4021. }
  4022. if (!this.hasVerticalScroll) {
  4023. this.maxScrollY = 0;
  4024. this.scrollerHeight = this.wrapperHeight;
  4025. }
  4026. this.indicators.map(function(indicator) {
  4027. indicator.refresh();
  4028. });
  4029. //以防slider类嵌套使用
  4030. if (this.options.snap && typeof this.options.snap === 'string') {
  4031. var items = this.scroller.querySelectorAll(this.options.snap);
  4032. this.itemLength = 0;
  4033. this.snaps = [];
  4034. for (var i = 0, len = items.length; i < len; i++) {
  4035. var item = items[i];
  4036. if (item.parentNode === this.scroller) {
  4037. this.itemLength++;
  4038. this.snaps.push(item);
  4039. }
  4040. }
  4041. this._initSnap(); //需要每次都_initSnap么。其实init的时候执行一次,后续resize的时候执行一次就行了吧.先这么做吧,如果影响性能,再调整
  4042. }
  4043. },
  4044. _momentum: function(current, distance, time, lowerMargin, wrapperSize, deceleration) {
  4045. var speed = parseFloat(Math.abs(distance) / time),
  4046. destination,
  4047. duration;
  4048. deceleration = deceleration === undefined ? 0.0006 : deceleration;
  4049. destination = current + (speed * speed) / (2 * deceleration) * (distance < 0 ? -1 : 1);
  4050. duration = speed / deceleration;
  4051. if (destination < lowerMargin) {
  4052. destination = wrapperSize ? lowerMargin - (wrapperSize / 2.5 * (speed / 8)) : lowerMargin;
  4053. distance = Math.abs(destination - current);
  4054. duration = distance / speed;
  4055. } else if (destination > 0) {
  4056. destination = wrapperSize ? wrapperSize / 2.5 * (speed / 8) : 0;
  4057. distance = Math.abs(current) + destination;
  4058. duration = distance / speed;
  4059. }
  4060. return {
  4061. destination: Math.round(destination),
  4062. duration: duration
  4063. };
  4064. },
  4065. _getTranslateStr: function(x, y) {
  4066. if (this.options.hardwareAccelerated) {
  4067. return 'translate3d(' + x + 'px,' + y + 'px,0px) ' + this.translateZ;
  4068. }
  4069. return 'translate(' + x + 'px,' + y + 'px) ';
  4070. },
  4071. //API
  4072. setStopped: function(stopped) {
  4073. this.stopped = !!stopped;
  4074. },
  4075. setTranslate: function(x, y) {
  4076. this.x = x;
  4077. this.y = y;
  4078. this.scrollerStyle['webkitTransform'] = this._getTranslateStr(x, y);
  4079. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  4080. var parallaxY = y * this.options.parallaxRatio;
  4081. var scale = 1 + parallaxY / ((this.parallaxHeight - parallaxY) / 2);
  4082. if (scale > 1) {
  4083. this.parallaxImgStyle['opacity'] = 1 - parallaxY / 100 * this.options.parallaxRatio;
  4084. this.parallaxStyle['webkitTransform'] = this._getTranslateStr(0, -parallaxY) + ' scale(' + scale + ',' + scale + ')';
  4085. } else {
  4086. this.parallaxImgStyle['opacity'] = 1;
  4087. this.parallaxStyle['webkitTransform'] = this._getTranslateStr(0, -1) + ' scale(1,1)';
  4088. }
  4089. }
  4090. if (this.indicators) {
  4091. for (var i = this.indicators.length; i--;) {
  4092. this.indicators[i].updatePosition();
  4093. }
  4094. }
  4095. this.lastX = this.x;
  4096. this.lastY = this.y;
  4097. $.trigger(this.scroller, 'scroll', this);
  4098. },
  4099. reLayout: function() {
  4100. this.wrapper.offsetHeight;
  4101. var paddingLeft = parseFloat($.getStyles(this.wrapper, 'padding-left')) || 0;
  4102. var paddingRight = parseFloat($.getStyles(this.wrapper, 'padding-right')) || 0;
  4103. var paddingTop = parseFloat($.getStyles(this.wrapper, 'padding-top')) || 0;
  4104. var paddingBottom = parseFloat($.getStyles(this.wrapper, 'padding-bottom')) || 0;
  4105. var clientWidth = this.wrapper.clientWidth;
  4106. var clientHeight = this.wrapper.clientHeight;
  4107. this.scrollerWidth = this.scroller.offsetWidth;
  4108. this.scrollerHeight = this.scroller.offsetHeight;
  4109. this.wrapperWidth = clientWidth - paddingLeft - paddingRight;
  4110. this.wrapperHeight = clientHeight - paddingTop - paddingBottom;
  4111. this.maxScrollX = Math.min(this.wrapperWidth - this.scrollerWidth, 0);
  4112. this.maxScrollY = Math.min(this.wrapperHeight - this.scrollerHeight, 0);
  4113. this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0;
  4114. this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0;
  4115. this._reLayout();
  4116. },
  4117. resetPosition: function(time) {
  4118. var x = this.x,
  4119. y = this.y;
  4120. time = time || 0;
  4121. if (!this.hasHorizontalScroll || this.x > 0) {
  4122. x = 0;
  4123. } else if (this.x < this.maxScrollX) {
  4124. x = this.maxScrollX;
  4125. }
  4126. if (!this.hasVerticalScroll || this.y > 0) {
  4127. y = 0;
  4128. } else if (this.y < this.maxScrollY) {
  4129. y = this.maxScrollY;
  4130. }
  4131. if (x == this.x && y == this.y) {
  4132. return false;
  4133. }
  4134. this.scrollTo(x, y, time, this.options.scrollEasing);
  4135. return true;
  4136. },
  4137. _reInit: function() {
  4138. var groups = this.wrapper.querySelectorAll('.' + CLASS_SCROLL);
  4139. for (var i = 0, len = groups.length; i < len; i++) {
  4140. if (groups[i].parentNode === this.wrapper) {
  4141. this.scroller = groups[i];
  4142. break;
  4143. }
  4144. }
  4145. this.scrollerStyle = this.scroller && this.scroller.style;
  4146. },
  4147. refresh: function() {
  4148. this._reInit();
  4149. this.reLayout();
  4150. $.trigger(this.scroller, 'refresh', this);
  4151. this.resetPosition();
  4152. },
  4153. scrollTo: function(x, y, time, easing) {
  4154. var easing = easing || ease.circular;
  4155. // this.isInTransition = time > 0 && (this.lastX != x || this.lastY != y);
  4156. //暂不严格判断x,y,否则会导致部分版本上不正常触发轮播
  4157. this.isInTransition = time > 0;
  4158. if (this.isInTransition) {
  4159. this._clearRequestAnimationFrame();
  4160. this._transitionTimingFunction(easing.style);
  4161. this._transitionTime(time);
  4162. this.setTranslate(x, y);
  4163. } else {
  4164. this.setTranslate(x, y);
  4165. }
  4166. },
  4167. scrollToBottom: function(time, easing) {
  4168. time = time || this.options.scrollTime;
  4169. this.scrollTo(0, this.maxScrollY, time, easing);
  4170. },
  4171. gotoPage: function(index) {
  4172. this._gotoPage(index);
  4173. },
  4174. destroy: function() {
  4175. this._initEvent(true); //detach
  4176. delete $.data[this.wrapper.getAttribute('data-scroll')];
  4177. this.wrapper.setAttribute('data-scroll', '');
  4178. }
  4179. });
  4180. //Indicator
  4181. var Indicator = function(scroller, options) {
  4182. this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el;
  4183. this.wrapperStyle = this.wrapper.style;
  4184. this.indicator = this.wrapper.children[0];
  4185. this.indicatorStyle = this.indicator.style;
  4186. this.scroller = scroller;
  4187. this.options = $.extend({
  4188. listenX: true,
  4189. listenY: true,
  4190. fade: false,
  4191. speedRatioX: 0,
  4192. speedRatioY: 0
  4193. }, options);
  4194. this.sizeRatioX = 1;
  4195. this.sizeRatioY = 1;
  4196. this.maxPosX = 0;
  4197. this.maxPosY = 0;
  4198. if (this.options.fade) {
  4199. this.wrapperStyle['webkitTransform'] = this.scroller.translateZ;
  4200. this.wrapperStyle['webkitTransitionDuration'] = this.options.fixedBadAndorid && $.os.isBadAndroid ? '0.001s' : '0ms';
  4201. this.wrapperStyle.opacity = '0';
  4202. }
  4203. }
  4204. Indicator.prototype = {
  4205. handleEvent: function(e) {
  4206. },
  4207. transitionTime: function(time) {
  4208. time = time || 0;
  4209. this.indicatorStyle['webkitTransitionDuration'] = time + 'ms';
  4210. if (this.scroller.options.fixedBadAndorid && !time && $.os.isBadAndroid) {
  4211. this.indicatorStyle['webkitTransitionDuration'] = '0.001s';
  4212. }
  4213. },
  4214. transitionTimingFunction: function(easing) {
  4215. this.indicatorStyle['webkitTransitionTimingFunction'] = easing;
  4216. },
  4217. refresh: function() {
  4218. this.transitionTime();
  4219. if (this.options.listenX && !this.options.listenY) {
  4220. this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none';
  4221. } else if (this.options.listenY && !this.options.listenX) {
  4222. this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none';
  4223. } else {
  4224. this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none';
  4225. }
  4226. this.wrapper.offsetHeight; // force refresh
  4227. if (this.options.listenX) {
  4228. this.wrapperWidth = this.wrapper.clientWidth;
  4229. this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
  4230. this.indicatorStyle.width = this.indicatorWidth + 'px';
  4231. this.maxPosX = this.wrapperWidth - this.indicatorWidth;
  4232. this.minBoundaryX = 0;
  4233. this.maxBoundaryX = this.maxPosX;
  4234. this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX));
  4235. }
  4236. if (this.options.listenY) {
  4237. this.wrapperHeight = this.wrapper.clientHeight;
  4238. this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8);
  4239. this.indicatorStyle.height = this.indicatorHeight + 'px';
  4240. this.maxPosY = this.wrapperHeight - this.indicatorHeight;
  4241. this.minBoundaryY = 0;
  4242. this.maxBoundaryY = this.maxPosY;
  4243. this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY));
  4244. }
  4245. this.updatePosition();
  4246. },
  4247. updatePosition: function() {
  4248. var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0,
  4249. y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0;
  4250. if (x < this.minBoundaryX) {
  4251. this.width = Math.max(this.indicatorWidth + x, 8);
  4252. this.indicatorStyle.width = this.width + 'px';
  4253. x = this.minBoundaryX;
  4254. } else if (x > this.maxBoundaryX) {
  4255. this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8);
  4256. this.indicatorStyle.width = this.width + 'px';
  4257. x = this.maxPosX + this.indicatorWidth - this.width;
  4258. } else if (this.width != this.indicatorWidth) {
  4259. this.width = this.indicatorWidth;
  4260. this.indicatorStyle.width = this.width + 'px';
  4261. }
  4262. if (y < this.minBoundaryY) {
  4263. this.height = Math.max(this.indicatorHeight + y * 3, 8);
  4264. this.indicatorStyle.height = this.height + 'px';
  4265. y = this.minBoundaryY;
  4266. } else if (y > this.maxBoundaryY) {
  4267. this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8);
  4268. this.indicatorStyle.height = this.height + 'px';
  4269. y = this.maxPosY + this.indicatorHeight - this.height;
  4270. } else if (this.height != this.indicatorHeight) {
  4271. this.height = this.indicatorHeight;
  4272. this.indicatorStyle.height = this.height + 'px';
  4273. }
  4274. this.x = x;
  4275. this.y = y;
  4276. this.indicatorStyle['webkitTransform'] = this.scroller._getTranslateStr(x, y);
  4277. },
  4278. fade: function(val, hold) {
  4279. if (hold && !this.visible) {
  4280. return;
  4281. }
  4282. clearTimeout(this.fadeTimeout);
  4283. this.fadeTimeout = null;
  4284. var time = val ? 250 : 500,
  4285. delay = val ? 0 : 300;
  4286. val = val ? '1' : '0';
  4287. this.wrapperStyle['webkitTransitionDuration'] = time + 'ms';
  4288. this.fadeTimeout = setTimeout((function(val) {
  4289. this.wrapperStyle.opacity = val;
  4290. this.visible = +val;
  4291. }).bind(this, val), delay);
  4292. }
  4293. };
  4294. $.Scroll = Scroll;
  4295. $.fn.scroll = function(options) {
  4296. var scrollApis = [];
  4297. this.each(function() {
  4298. var scrollApi = null;
  4299. var self = this;
  4300. var id = self.getAttribute('data-scroll');
  4301. if (!id) {
  4302. id = ++$.uuid;
  4303. var _options = $.extend({}, options);
  4304. if (self.classList.contains('mui-segmented-control')) {
  4305. _options = $.extend(_options, {
  4306. scrollY: false,
  4307. scrollX: true,
  4308. indicators: false,
  4309. snap: '.mui-control-item'
  4310. });
  4311. }
  4312. $.data[id] = scrollApi = new Scroll(self, _options);
  4313. self.setAttribute('data-scroll', id);
  4314. } else {
  4315. scrollApi = $.data[id];
  4316. }
  4317. scrollApis.push(scrollApi);
  4318. });
  4319. return scrollApis.length === 1 ? scrollApis[0] : scrollApis;
  4320. };
  4321. })(mui, window, document);
  4322. (function($, window, document, undefined) {
  4323. var CLASS_VISIBILITY = 'mui-visibility';
  4324. var CLASS_HIDDEN = 'mui-hidden';
  4325. var PullRefresh = $.Scroll.extend($.extend({
  4326. handleEvent: function(e) {
  4327. this._super(e);
  4328. if (e.type === 'scrollbottom') {
  4329. if (e.target === this.scroller) {
  4330. this._scrollbottom();
  4331. }
  4332. }
  4333. },
  4334. _scrollbottom: function() {
  4335. if (!this.pulldown && !this.loading) {
  4336. this.pulldown = false;
  4337. this._initPullupRefresh();
  4338. this.pullupLoading();
  4339. }
  4340. },
  4341. _start: function(e) {
  4342. //仅下拉刷新在start阻止默认事件
  4343. if (e.touches && e.touches.length && e.touches[0].clientX > 30) {
  4344. e.target && !this._preventDefaultException(e.target, this.options.preventDefaultException) && e.preventDefault();
  4345. }
  4346. if (!this.loading) {
  4347. this.pulldown = this.pullPocket = this.pullCaption = this.pullLoading = false
  4348. }
  4349. this._super(e);
  4350. },
  4351. _drag: function(e) {
  4352. this._super(e);
  4353. if (!this.pulldown && !this.loading && this.topPocket && e.detail.direction === 'down' && this.y >= 0) {
  4354. this._initPulldownRefresh();
  4355. }
  4356. if (this.pulldown) {
  4357. this._setCaption(this.y > this.options.down.height ? this.options.down.contentover : this.options.down.contentdown);
  4358. }
  4359. },
  4360. _reLayout: function() {
  4361. this.hasVerticalScroll = true;
  4362. this._super();
  4363. },
  4364. //API
  4365. resetPosition: function(time) {
  4366. if (this.pulldown) {
  4367. if (this.y >= this.options.down.height) {
  4368. this.pulldownLoading(undefined, time || 0);
  4369. return true;
  4370. } else {
  4371. !this.loading && this.topPocket.classList.remove(CLASS_VISIBILITY);
  4372. }
  4373. }
  4374. return this._super(time);
  4375. },
  4376. pulldownLoading: function(y, time) {
  4377. typeof y === 'undefined' && (y = this.options.down.height); //默认高度
  4378. this.scrollTo(0, y, time, this.options.bounceEasing);
  4379. if (this.loading) {
  4380. return;
  4381. }
  4382. // if (!this.pulldown) {
  4383. this._initPulldownRefresh();
  4384. // }
  4385. this._setCaption(this.options.down.contentrefresh);
  4386. this.loading = true;
  4387. this.indicators.map(function(indicator) {
  4388. indicator.fade(0);
  4389. });
  4390. var callback = this.options.down.callback;
  4391. callback && callback.call(this);
  4392. },
  4393. endPulldownToRefresh: function() {
  4394. var self = this;
  4395. if (self.topPocket && self.loading && this.pulldown) {
  4396. self.scrollTo(0, 0, self.options.bounceTime, self.options.bounceEasing);
  4397. self.loading = false;
  4398. self._setCaption(self.options.down.contentdown, true);
  4399. setTimeout(function() {
  4400. self.loading || self.topPocket.classList.remove(CLASS_VISIBILITY);
  4401. }, 350);
  4402. }
  4403. },
  4404. pullupLoading: function(callback, x, time) {
  4405. x = x || 0;
  4406. this.scrollTo(x, this.maxScrollY, time, this.options.bounceEasing);
  4407. if (this.loading) {
  4408. return;
  4409. }
  4410. this._initPullupRefresh();
  4411. this._setCaption(this.options.up.contentrefresh);
  4412. this.indicators.map(function(indicator) {
  4413. indicator.fade(0);
  4414. });
  4415. this.loading = true;
  4416. callback = callback || this.options.up.callback;
  4417. callback && callback.call(this);
  4418. },
  4419. endPullupToRefresh: function(finished) {
  4420. var self = this;
  4421. if (self.bottomPocket) { // && self.loading && !this.pulldown
  4422. self.loading = false;
  4423. if (finished) {
  4424. this.finished = true;
  4425. self._setCaption(self.options.up.contentnomore);
  4426. // self.bottomPocket.classList.remove(CLASS_VISIBILITY);
  4427. // self.bottomPocket.classList.add(CLASS_HIDDEN);
  4428. self.wrapper.removeEventListener('scrollbottom', self);
  4429. } else {
  4430. self._setCaption(self.options.up.contentdown);
  4431. // setTimeout(function() {
  4432. self.loading || self.bottomPocket.classList.remove(CLASS_VISIBILITY);
  4433. // }, 300);
  4434. }
  4435. }
  4436. },
  4437. disablePullupToRefresh: function() {
  4438. this._initPullupRefresh();
  4439. this.bottomPocket.className = 'mui-pull-bottom-pocket' + ' ' + CLASS_HIDDEN;
  4440. this.wrapper.removeEventListener('scrollbottom', this);
  4441. },
  4442. enablePullupToRefresh: function() {
  4443. this._initPullupRefresh();
  4444. this.bottomPocket.classList.remove(CLASS_HIDDEN);
  4445. this._setCaption(this.options.up.contentdown);
  4446. this.wrapper.addEventListener('scrollbottom', this);
  4447. },
  4448. refresh: function(isReset) {
  4449. if (isReset && this.finished) {
  4450. this.enablePullupToRefresh();
  4451. this.finished = false;
  4452. }
  4453. this._super();
  4454. },
  4455. }, $.PullRefresh));
  4456. $.fn.pullRefresh = function(options) {
  4457. if (this.length === 1) {
  4458. var self = this[0];
  4459. var pullRefreshApi = null;
  4460. var id = self.getAttribute('data-pullrefresh');
  4461. if (!id && typeof options === 'undefined') {
  4462. return false;
  4463. }
  4464. options = options || {};
  4465. if (!id) {
  4466. id = ++$.uuid;
  4467. $.data[id] = pullRefreshApi = new PullRefresh(self, options);
  4468. self.setAttribute('data-pullrefresh', id);
  4469. } else {
  4470. pullRefreshApi = $.data[id];
  4471. }
  4472. if (options.down && options.down.auto) { //如果设置了auto,则自动下拉一次
  4473. pullRefreshApi.pulldownLoading(options.down.autoY);
  4474. } else if (options.up && options.up.auto) { //如果设置了auto,则自动上拉一次
  4475. pullRefreshApi.pullupLoading();
  4476. }
  4477. //暂不提供这种调用方式吧
  4478. // if (typeof options === 'string') {
  4479. // var methodValue = pullRefreshApi[options].apply(pullRefreshApi, $.slice.call(arguments, 1));
  4480. // if (methodValue !== undefined) {
  4481. // return methodValue;
  4482. // }
  4483. // }
  4484. return pullRefreshApi;
  4485. }
  4486. };
  4487. })(mui, window, document);
  4488. /**
  4489. * snap 重构
  4490. * @param {Object} $
  4491. * @param {Object} window
  4492. */
  4493. (function($, window) {
  4494. var CLASS_SLIDER = 'mui-slider';
  4495. var CLASS_SLIDER_GROUP = 'mui-slider-group';
  4496. var CLASS_SLIDER_LOOP = 'mui-slider-loop';
  4497. var CLASS_SLIDER_INDICATOR = 'mui-slider-indicator';
  4498. var CLASS_ACTION_PREVIOUS = 'mui-action-previous';
  4499. var CLASS_ACTION_NEXT = 'mui-action-next';
  4500. var CLASS_SLIDER_ITEM = 'mui-slider-item';
  4501. var CLASS_ACTIVE = 'mui-active';
  4502. var SELECTOR_SLIDER_ITEM = '.' + CLASS_SLIDER_ITEM;
  4503. var SELECTOR_SLIDER_INDICATOR = '.' + CLASS_SLIDER_INDICATOR;
  4504. var SELECTOR_SLIDER_PROGRESS_BAR = '.mui-slider-progress-bar';
  4505. var Slider = $.Slider = $.Scroll.extend({
  4506. init: function(element, options) {
  4507. this._super(element, $.extend(true, {
  4508. fingers: 1,
  4509. interval: 0, //设置为0,则不定时轮播
  4510. scrollY: false,
  4511. scrollX: true,
  4512. indicators: false,
  4513. scrollTime: 1000,
  4514. startX: false,
  4515. slideTime: 0, //滑动动画时间
  4516. snap: SELECTOR_SLIDER_ITEM
  4517. }, options));
  4518. if (this.options.startX) {
  4519. // $.trigger(this.wrapper, 'scrollend', this);
  4520. }
  4521. },
  4522. _init: function() {
  4523. this._reInit();
  4524. if (this.scroller) {
  4525. this.scrollerStyle = this.scroller.style;
  4526. this.progressBar = this.wrapper.querySelector(SELECTOR_SLIDER_PROGRESS_BAR);
  4527. if (this.progressBar) {
  4528. this.progressBarWidth = this.progressBar.offsetWidth;
  4529. this.progressBarStyle = this.progressBar.style;
  4530. }
  4531. //忘记这个代码是干什么的了?
  4532. // this.x = this._getScroll();
  4533. // if (this.options.startX === false) {
  4534. // this.options.startX = this.x;
  4535. // }
  4536. //根据active修正startX
  4537. this._super();
  4538. this._initTimer();
  4539. }
  4540. },
  4541. _triggerSlide: function() {
  4542. var self = this;
  4543. self.isInTransition = false;
  4544. var page = self.currentPage;
  4545. self.slideNumber = self._fixedSlideNumber();
  4546. if (self.loop) {
  4547. if (self.slideNumber === 0) {
  4548. self.setTranslate(self.pages[1][0].x, 0);
  4549. } else if (self.slideNumber === self.itemLength - 3) {
  4550. self.setTranslate(self.pages[self.itemLength - 2][0].x, 0);
  4551. }
  4552. }
  4553. if (self.lastSlideNumber != self.slideNumber) {
  4554. self.lastSlideNumber = self.slideNumber;
  4555. self.lastPage = self.currentPage;
  4556. $.trigger(self.wrapper, 'slide', {
  4557. slideNumber: self.slideNumber
  4558. });
  4559. }
  4560. self._initTimer();
  4561. },
  4562. _handleSlide: function(e) {
  4563. var self = this;
  4564. if (e.target !== self.wrapper) {
  4565. return;
  4566. }
  4567. var detail = e.detail;
  4568. detail.slideNumber = detail.slideNumber || 0;
  4569. var temps = self.scroller.querySelectorAll(SELECTOR_SLIDER_ITEM);
  4570. var items = [];
  4571. for (var i = 0, len = temps.length; i < len; i++) {
  4572. var item = temps[i];
  4573. if (item.parentNode === self.scroller) {
  4574. items.push(item);
  4575. }
  4576. }
  4577. var _slideNumber = detail.slideNumber;
  4578. if (self.loop) {
  4579. _slideNumber += 1;
  4580. }
  4581. if (!self.wrapper.classList.contains('mui-segmented-control')) {
  4582. for (var i = 0, len = items.length; i < len; i++) {
  4583. var item = items[i];
  4584. if (item.parentNode === self.scroller) {
  4585. if (i === _slideNumber) {
  4586. item.classList.add(CLASS_ACTIVE);
  4587. } else {
  4588. item.classList.remove(CLASS_ACTIVE);
  4589. }
  4590. }
  4591. }
  4592. }
  4593. var indicatorWrap = self.wrapper.querySelector('.mui-slider-indicator');
  4594. if (indicatorWrap) {
  4595. if (indicatorWrap.getAttribute('data-scroll')) { //scroll
  4596. $(indicatorWrap).scroll().gotoPage(detail.slideNumber);
  4597. }
  4598. var indicators = indicatorWrap.querySelectorAll('.mui-indicator');
  4599. if (indicators.length > 0) { //图片轮播
  4600. for (var i = 0, len = indicators.length; i < len; i++) {
  4601. indicators[i].classList[i === detail.slideNumber ? 'add' : 'remove'](CLASS_ACTIVE);
  4602. }
  4603. } else {
  4604. var number = indicatorWrap.querySelector('.mui-number span');
  4605. if (number) { //图文表格
  4606. number.innerText = (detail.slideNumber + 1);
  4607. } else { //segmented controls
  4608. var controlItems = indicatorWrap.querySelectorAll('.mui-control-item');
  4609. for (var i = 0, len = controlItems.length; i < len; i++) {
  4610. controlItems[i].classList[i === detail.slideNumber ? 'add' : 'remove'](CLASS_ACTIVE);
  4611. }
  4612. }
  4613. }
  4614. }
  4615. e.stopPropagation();
  4616. },
  4617. _handleTabShow: function(e) {
  4618. var self = this;
  4619. self.gotoItem((e.detail.tabNumber || 0), self.options.slideTime);
  4620. },
  4621. _handleIndicatorTap: function(event) {
  4622. var self = this;
  4623. var target = event.target;
  4624. if (target.classList.contains(CLASS_ACTION_PREVIOUS) || target.classList.contains(CLASS_ACTION_NEXT)) {
  4625. self[target.classList.contains(CLASS_ACTION_PREVIOUS) ? 'prevItem' : 'nextItem']();
  4626. event.stopPropagation();
  4627. }
  4628. },
  4629. _initEvent: function(detach) {
  4630. var self = this;
  4631. self._super(detach);
  4632. var action = detach ? 'removeEventListener' : 'addEventListener';
  4633. self.wrapper[action]('slide', this);
  4634. self.wrapper[action]($.eventName('shown', 'tab'), this);
  4635. },
  4636. handleEvent: function(e) {
  4637. this._super(e);
  4638. switch (e.type) {
  4639. case 'slide':
  4640. this._handleSlide(e);
  4641. break;
  4642. case $.eventName('shown', 'tab'):
  4643. if (~this.snaps.indexOf(e.target)) { //避免嵌套监听错误的tab show
  4644. this._handleTabShow(e);
  4645. }
  4646. break;
  4647. }
  4648. },
  4649. _scrollend: function(e) {
  4650. this._super(e);
  4651. this._triggerSlide(e);
  4652. },
  4653. _drag: function(e) {
  4654. this._super(e);
  4655. var direction = e.detail.direction;
  4656. if (direction === 'left' || direction === 'right') {
  4657. //拖拽期间取消定时
  4658. var slidershowTimer = this.wrapper.getAttribute('data-slidershowTimer');
  4659. slidershowTimer && window.clearTimeout(slidershowTimer);
  4660. e.stopPropagation();
  4661. }
  4662. },
  4663. _initTimer: function() {
  4664. var self = this;
  4665. var slider = self.wrapper;
  4666. var interval = self.options.interval;
  4667. var slidershowTimer = slider.getAttribute('data-slidershowTimer');
  4668. slidershowTimer && window.clearTimeout(slidershowTimer);
  4669. if (interval) {
  4670. slidershowTimer = window.setTimeout(function() {
  4671. if (!slider) {
  4672. return;
  4673. }
  4674. //仅slider显示状态进行自动轮播
  4675. if (!!(slider.offsetWidth || slider.offsetHeight)) {
  4676. self.nextItem(true);
  4677. //下一个
  4678. }
  4679. self._initTimer();
  4680. }, interval);
  4681. slider.setAttribute('data-slidershowTimer', slidershowTimer);
  4682. }
  4683. },
  4684. _fixedSlideNumber: function(page) {
  4685. page = page || this.currentPage;
  4686. var slideNumber = page.pageX;
  4687. if (this.loop) {
  4688. if (page.pageX === 0) {
  4689. slideNumber = this.itemLength - 3;
  4690. } else if (page.pageX === (this.itemLength - 1)) {
  4691. slideNumber = 0;
  4692. } else {
  4693. slideNumber = page.pageX - 1;
  4694. }
  4695. }
  4696. return slideNumber;
  4697. },
  4698. _reLayout: function() {
  4699. this.hasHorizontalScroll = true;
  4700. this.loop = this.scroller.classList.contains(CLASS_SLIDER_LOOP);
  4701. this._super();
  4702. },
  4703. _getScroll: function() {
  4704. var result = $.parseTranslateMatrix($.getStyles(this.scroller, 'webkitTransform'));
  4705. return result ? result.x : 0;
  4706. },
  4707. _transitionEnd: function(e) {
  4708. if (e.target !== this.scroller || !this.isInTransition) {
  4709. return;
  4710. }
  4711. this._transitionTime();
  4712. this.isInTransition = false;
  4713. $.trigger(this.wrapper, 'scrollend', this);
  4714. },
  4715. _flick: function(e) {
  4716. if (!this.moved) { //无moved
  4717. return;
  4718. }
  4719. var detail = e.detail;
  4720. var direction = detail.direction;
  4721. this._clearRequestAnimationFrame();
  4722. this.isInTransition = true;
  4723. // if (direction === 'up' || direction === 'down') {
  4724. // this.resetPosition(this.options.bounceTime);
  4725. // return;
  4726. // }
  4727. if (e.type === 'flick') {
  4728. if (detail.deltaTime < 200) { //flick,太容易触发,额外校验一下deltaTime
  4729. this.x = this._getPage((this.slideNumber + (direction === 'right' ? -1 : 1)), true).x;
  4730. }
  4731. this.resetPosition(this.options.bounceTime);
  4732. } else if (e.type === 'dragend' && !detail.flick) {
  4733. this.resetPosition(this.options.bounceTime);
  4734. }
  4735. e.stopPropagation();
  4736. },
  4737. _initSnap: function() {
  4738. this.scrollerWidth = this.itemLength * this.scrollerWidth;
  4739. this.maxScrollX = Math.min(this.wrapperWidth - this.scrollerWidth, 0);
  4740. this._super();
  4741. if (!this.currentPage.x) {
  4742. //当slider处于隐藏状态时,导致snap计算是错误的,临时先这么判断一下,后续要考虑解决所有scroll在隐藏状态下初始化属性不正确的问题
  4743. var currentPage = this.pages[this.loop ? 1 : 0];
  4744. currentPage = currentPage || this.pages[0];
  4745. if (!currentPage) {
  4746. return;
  4747. }
  4748. this.currentPage = currentPage[0];
  4749. this.slideNumber = 0;
  4750. this.lastSlideNumber = typeof this.lastSlideNumber === 'undefined' ? 0 : this.lastSlideNumber;
  4751. } else {
  4752. this.slideNumber = this._fixedSlideNumber();
  4753. this.lastSlideNumber = typeof this.lastSlideNumber === 'undefined' ? this.slideNumber : this.lastSlideNumber;
  4754. }
  4755. this.options.startX = this.currentPage.x || 0;
  4756. },
  4757. _getSnapX: function(offsetLeft) {
  4758. return Math.max(-offsetLeft, this.maxScrollX);
  4759. },
  4760. _getPage: function(slideNumber, isFlick) {
  4761. if (this.loop) {
  4762. if (slideNumber > (this.itemLength - (isFlick ? 2 : 3))) {
  4763. slideNumber = 1;
  4764. time = 0;
  4765. } else if (slideNumber < (isFlick ? -1 : 0)) {
  4766. slideNumber = this.itemLength - 2;
  4767. time = 0;
  4768. } else {
  4769. slideNumber += 1;
  4770. }
  4771. } else {
  4772. if (!isFlick) {
  4773. if (slideNumber > (this.itemLength - 1)) {
  4774. slideNumber = 0;
  4775. time = 0;
  4776. } else if (slideNumber < 0) {
  4777. slideNumber = this.itemLength - 1;
  4778. time = 0;
  4779. }
  4780. }
  4781. slideNumber = Math.min(Math.max(0, slideNumber), this.itemLength - 1);
  4782. }
  4783. return this.pages[slideNumber][0];
  4784. },
  4785. _gotoItem: function(slideNumber, time) {
  4786. this.currentPage = this._getPage(slideNumber, true); //此处传true。可保证程序切换时,动画与人手操作一致(第一张,最后一张的切换动画)
  4787. this.scrollTo(this.currentPage.x, 0, time, this.options.scrollEasing);
  4788. if (time === 0) {
  4789. $.trigger(this.wrapper, 'scrollend', this);
  4790. }
  4791. },
  4792. //API
  4793. setTranslate: function(x, y) {
  4794. this._super(x, y);
  4795. var progressBar = this.progressBar;
  4796. if (progressBar) {
  4797. this.progressBarStyle.webkitTransform = this._getTranslateStr((-x * (this.progressBarWidth / this.wrapperWidth)), 0);
  4798. }
  4799. },
  4800. resetPosition: function(time) {
  4801. time = time || 0;
  4802. if (this.x > 0) {
  4803. this.x = 0;
  4804. } else if (this.x < this.maxScrollX) {
  4805. this.x = this.maxScrollX;
  4806. }
  4807. this.currentPage = this._nearestSnap(this.x);
  4808. this.scrollTo(this.currentPage.x, 0, time, this.options.scrollEasing);
  4809. return true;
  4810. },
  4811. gotoItem: function(slideNumber, time) {
  4812. this._gotoItem(slideNumber, typeof time === 'undefined' ? this.options.scrollTime : time);
  4813. },
  4814. nextItem: function() {
  4815. this._gotoItem(this.slideNumber + 1, this.options.scrollTime);
  4816. },
  4817. prevItem: function() {
  4818. this._gotoItem(this.slideNumber - 1, this.options.scrollTime);
  4819. },
  4820. getSlideNumber: function() {
  4821. return this.slideNumber || 0;
  4822. },
  4823. _reInit: function() {
  4824. var groups = this.wrapper.querySelectorAll('.' + CLASS_SLIDER_GROUP);
  4825. for (var i = 0, len = groups.length; i < len; i++) {
  4826. if (groups[i].parentNode === this.wrapper) {
  4827. this.scroller = groups[i];
  4828. break;
  4829. }
  4830. }
  4831. this.scrollerStyle = this.scroller && this.scroller.style;
  4832. if (this.progressBar) {
  4833. this.progressBarWidth = this.progressBar.offsetWidth;
  4834. this.progressBarStyle = this.progressBar.style;
  4835. }
  4836. },
  4837. refresh: function(options) {
  4838. if (options) {
  4839. $.extend(this.options, options);
  4840. this._super();
  4841. this._initTimer();
  4842. } else {
  4843. this._super();
  4844. }
  4845. },
  4846. destroy: function() {
  4847. this._initEvent(true); //detach
  4848. delete $.data[this.wrapper.getAttribute('data-slider')];
  4849. this.wrapper.setAttribute('data-slider', '');
  4850. }
  4851. });
  4852. $.fn.slider = function(options) {
  4853. var slider = null;
  4854. this.each(function() {
  4855. var sliderElement = this;
  4856. if (!this.classList.contains(CLASS_SLIDER)) {
  4857. sliderElement = this.querySelector('.' + CLASS_SLIDER);
  4858. }
  4859. if (sliderElement && sliderElement.querySelector(SELECTOR_SLIDER_ITEM)) {
  4860. var id = sliderElement.getAttribute('data-slider');
  4861. if (!id) {
  4862. id = ++$.uuid;
  4863. $.data[id] = slider = new Slider(sliderElement, options);
  4864. sliderElement.setAttribute('data-slider', id);
  4865. } else {
  4866. slider = $.data[id];
  4867. if (slider && options) {
  4868. slider.refresh(options);
  4869. }
  4870. }
  4871. }
  4872. });
  4873. return slider;
  4874. };
  4875. $.ready(function() {
  4876. // setTimeout(function() {
  4877. $('.mui-slider').slider();
  4878. $('.mui-scroll-wrapper.mui-slider-indicator.mui-segmented-control').scroll({
  4879. scrollY: false,
  4880. scrollX: true,
  4881. indicators: false,
  4882. snap: '.mui-control-item'
  4883. });
  4884. // }, 500); //临时处理slider宽度计算不正确的问题(初步确认是scrollbar导致的)
  4885. });
  4886. })(mui, window);
  4887. /**
  4888. * pullRefresh 5+
  4889. * @param {type} $
  4890. * @returns {undefined}
  4891. */
  4892. (function($, document) {
  4893. if (!($.os.plus)) { //仅在5+android支持多webview的使用
  4894. return;
  4895. }
  4896. $.plusReady(function() {
  4897. if (window.__NWin_Enable__ === false) { //不支持多webview,则不用5+下拉刷新
  4898. return;
  4899. }
  4900. var CLASS_PLUS_PULLREFRESH = 'mui-plus-pullrefresh';
  4901. var CLASS_VISIBILITY = 'mui-visibility';
  4902. var CLASS_HIDDEN = 'mui-hidden';
  4903. var CLASS_BLOCK = 'mui-block';
  4904. var CLASS_PULL_CAPTION = 'mui-pull-caption';
  4905. var CLASS_PULL_CAPTION_DOWN = 'mui-pull-caption-down';
  4906. var CLASS_PULL_CAPTION_REFRESH = 'mui-pull-caption-refresh';
  4907. var CLASS_PULL_CAPTION_NOMORE = 'mui-pull-caption-nomore';
  4908. var PlusPullRefresh = $.Class.extend({
  4909. init: function(element, options) {
  4910. this.element = element;
  4911. this.options = options;
  4912. this.wrapper = this.scroller = element;
  4913. this._init();
  4914. this._initPulldownRefreshEvent();
  4915. },
  4916. _init: function() {
  4917. var self = this;
  4918. //document.addEventListener('plusscrollbottom', this);
  4919. window.addEventListener('dragup', self);
  4920. document.addEventListener("plusscrollbottom", self);
  4921. self.scrollInterval = window.setInterval(function() {
  4922. if (self.isScroll && !self.loading) {
  4923. if (window.pageYOffset + window.innerHeight + 10 >= document.documentElement.scrollHeight) {
  4924. self.isScroll = false; //放在这里是因为快速滚动的话,有可能检测时,还没到底,所以只要有滚动,没到底之前一直检测高度变化
  4925. if (self.bottomPocket) {
  4926. self.pullupLoading();
  4927. }
  4928. }
  4929. }
  4930. }, 100);
  4931. },
  4932. _initPulldownRefreshEvent: function() {
  4933. var self = this;
  4934. $.plusReady(function() {
  4935. if(self.options.down.style == "circle"){
  4936. //单webview、原生转圈
  4937. self.options.webview = plus.webview.currentWebview();
  4938. self.options.webview.setPullToRefresh({
  4939. support: true,
  4940. color:self.options.down.color || '#2BD009',
  4941. height: self.options.down.height || '50px',
  4942. range: self.options.down.range || '100px',
  4943. style: 'circle',
  4944. offset: self.options.down.offset || '0px'
  4945. }, function() {
  4946. self.options.down.callback();
  4947. });
  4948. }else if (self.topPocket && self.options.webviewId) {
  4949. var webview = plus.webview.getWebviewById(self.options.webviewId);//子窗口
  4950. if (!webview) {
  4951. return;
  4952. }
  4953. self.options.webview = webview;
  4954. var downOptions = self.options.down;
  4955. var height = downOptions.height;
  4956. webview.addEventListener('close', function() {
  4957. var attrWebviewId = self.options.webviewId && self.options.webviewId.replace(/\//g, "_"); //替换所有"/"
  4958. self.element.removeAttribute('data-pullrefresh-plus-' + attrWebviewId);
  4959. });
  4960. webview.addEventListener("dragBounce", function(e) {
  4961. if (!self.pulldown) {
  4962. self._initPulldownRefresh();
  4963. } else {
  4964. self.pullPocket.classList.add(CLASS_BLOCK);
  4965. }
  4966. switch (e.status) {
  4967. case "beforeChangeOffset": //下拉可刷新状态
  4968. self._setCaption(downOptions.contentdown);
  4969. break;
  4970. case "afterChangeOffset": //松开可刷新状态
  4971. self._setCaption(downOptions.contentover);
  4972. break;
  4973. case "dragEndAfterChangeOffset": //正在刷新状态
  4974. //执行下拉刷新所在webview的回调函数
  4975. webview.evalJS("window.mui&&mui.options.pullRefresh.down.callback()");
  4976. self._setCaption(downOptions.contentrefresh);
  4977. break;
  4978. default:
  4979. break;
  4980. }
  4981. }, false);
  4982. webview.setBounce({
  4983. position: {
  4984. top: height * 2 + 'px'
  4985. },
  4986. changeoffset: {
  4987. top: height + 'px'
  4988. }
  4989. });
  4990. }
  4991. });
  4992. },
  4993. handleEvent: function(e) {
  4994. var self = this;
  4995. if (self.stopped) {
  4996. return;
  4997. }
  4998. self.isScroll = false;
  4999. if (e.type === 'dragup' || e.type === 'plusscrollbottom') {
  5000. self.isScroll = true;
  5001. setTimeout(function() {
  5002. self.isScroll = false;
  5003. }, 1000);
  5004. }
  5005. }
  5006. }).extend($.extend({
  5007. setStopped: function(stopped) { //该方法是子页面调用的
  5008. this.stopped = !!stopped;
  5009. //TODO 此处需要设置当前webview的bounce为none,目前5+有BUG
  5010. var webview = plus.webview.currentWebview();
  5011. if (this.stopped) {
  5012. webview.setStyle({
  5013. bounce: 'none'
  5014. });
  5015. webview.setBounce({
  5016. position: {
  5017. top: 'none'
  5018. }
  5019. });
  5020. } else {
  5021. var height = this.options.down.height;
  5022. webview.setStyle({
  5023. bounce: 'vertical'
  5024. });
  5025. webview.setBounce({
  5026. position: {
  5027. top: height * 2 + 'px'
  5028. },
  5029. changeoffset: {
  5030. top: height + 'px'
  5031. }
  5032. });
  5033. }
  5034. },
  5035. beginPulldown:function() {
  5036. $.plusReady(function() {
  5037. var _wv = plus.webview.currentWebview();
  5038. var self = this;
  5039. //这里延时的目的是为了保证下拉刷新组件初始化完成,后续应该做成有状态的
  5040. setTimeout(function () {
  5041. if(self.options.down.style == "circle"){
  5042. _wv.beginPullToRefresh();
  5043. }else{
  5044. _wv.setBounce({
  5045. offset: {
  5046. top: this.options.down.height + "px"
  5047. }
  5048. });
  5049. }
  5050. },15);
  5051. }.bind(this));
  5052. },
  5053. pulldownLoading: function () {//该方法是子页面调用的,兼容老的历史API
  5054. this.beginPulldown();
  5055. },
  5056. _pulldownLoading: function() { //该方法是父页面调用的
  5057. var self = this;
  5058. $.plusReady(function() {
  5059. var childWebview = plus.webview.getWebviewById(self.options.webviewId);
  5060. childWebview && childWebview.setBounce({
  5061. offset: {
  5062. top: self.options.down.height + "px"
  5063. }
  5064. });
  5065. });
  5066. },
  5067. endPulldown:function(){
  5068. var _wv = plus.webview.currentWebview();
  5069. //双webview的下拉刷新,需要修改父窗口提示信息
  5070. if(_wv.parent() && this.options.down.style !== "circle"){
  5071. _wv.parent().evalJS("mui&&mui(document.querySelector('.mui-content')).pullRefresh('" + JSON.stringify({
  5072. webviewId: _wv.id
  5073. }) + "')._endPulldownToRefresh()");
  5074. }else{
  5075. _wv.endPullToRefresh();
  5076. }
  5077. },
  5078. endPulldownToRefresh: function () {//该方法是子页面调用的,兼容老的历史API
  5079. this.endPulldown();
  5080. },
  5081. _endPulldownToRefresh: function() { //该方法是父页面调用的
  5082. var self = this;
  5083. if (self.topPocket && self.options.webview) {
  5084. self.options.webview.endPullToRefresh(); //下拉刷新所在webview回弹
  5085. self.loading = false;
  5086. self._setCaption(self.options.down.contentdown, true);
  5087. setTimeout(function() {
  5088. self.loading || self.topPocket.classList.remove(CLASS_BLOCK);
  5089. }, 350);
  5090. }
  5091. },
  5092. beginPullup:function(callback) {//开始上拉加载
  5093. var self = this;
  5094. if (self.isLoading) return;
  5095. self.isLoading = true;
  5096. if (self.pulldown !== false) {
  5097. self._initPullupRefresh();
  5098. } else {
  5099. this.pullPocket.classList.add(CLASS_BLOCK);
  5100. }
  5101. setTimeout(function() {
  5102. self.pullLoading.classList.add(CLASS_VISIBILITY);
  5103. self.pullLoading.classList.remove(CLASS_HIDDEN);
  5104. self.pullCaption.innerHTML = ''; //修正5+里边第一次加载时,文字显示的bug(还会显示出来个“多”,猜测应该是渲染问题导致的)
  5105. self.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_REFRESH;
  5106. self.pullCaption.innerHTML = self.options.up.contentrefresh;
  5107. callback = callback || self.options.up.callback;
  5108. callback && callback.call(self);
  5109. }, 300);
  5110. },
  5111. pullupLoading:function (callback) {//兼容老的API
  5112. this.beginPullup(callback);
  5113. },
  5114. endPullup:function(finished) {//上拉加载结束
  5115. var self = this;
  5116. if (self.pullLoading) {
  5117. self.pullLoading.classList.remove(CLASS_VISIBILITY);
  5118. self.pullLoading.classList.add(CLASS_HIDDEN);
  5119. self.isLoading = false;
  5120. if (finished) {
  5121. self.finished = true;
  5122. self.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_NOMORE;
  5123. self.pullCaption.innerHTML = self.options.up.contentnomore;
  5124. //取消5+的plusscrollbottom事件
  5125. document.removeEventListener('plusscrollbottom', self);
  5126. window.removeEventListener('dragup', self);
  5127. } else { //初始化时隐藏,后续不再隐藏
  5128. self.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_DOWN;
  5129. self.pullCaption.innerHTML = self.options.up.contentdown;
  5130. }
  5131. }
  5132. },
  5133. endPullupToRefresh: function (finished) {//上拉加载结束,兼容老的API
  5134. this.endPullup(finished);
  5135. },
  5136. disablePullupToRefresh: function() {
  5137. this._initPullupRefresh();
  5138. this.bottomPocket.className = 'mui-pull-bottom-pocket' + ' ' + CLASS_HIDDEN;
  5139. window.removeEventListener('dragup', this);
  5140. },
  5141. enablePullupToRefresh: function() {
  5142. this._initPullupRefresh();
  5143. this.bottomPocket.classList.remove(CLASS_HIDDEN);
  5144. this.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_DOWN;
  5145. this.pullCaption.innerHTML = this.options.up.contentdown;
  5146. document.addEventListener("plusscrollbottom", this);
  5147. window.addEventListener('dragup', this);
  5148. },
  5149. scrollTo: function(x, y, time) {
  5150. $.scrollTo(y, time);
  5151. },
  5152. scrollToBottom: function(time) {
  5153. $.scrollTo(document.documentElement.scrollHeight, time);
  5154. },
  5155. refresh: function(isReset) {
  5156. if (isReset && this.finished) {
  5157. this.enablePullupToRefresh();
  5158. this.finished = false;
  5159. }
  5160. }
  5161. }, $.PullRefresh));
  5162. //override h5 pullRefresh
  5163. $.fn.pullRefresh_native = function(options) {
  5164. var self;
  5165. if (this.length === 0) {
  5166. self = document.createElement('div');
  5167. self.className = 'mui-content';
  5168. document.body.appendChild(self);
  5169. } else {
  5170. self = this[0];
  5171. }
  5172. var args = options;
  5173. //一个父需要支持多个子下拉刷新
  5174. options = options || {}
  5175. if (typeof options === 'string') {
  5176. options = $.parseJSON(options);
  5177. };
  5178. !options.webviewId && (options.webviewId = (plus.webview.currentWebview().id || plus.webview.currentWebview().getURL()));
  5179. var pullRefreshApi = null;
  5180. var attrWebviewId = options.webviewId && options.webviewId.replace(/\//g, "_"); //替换所有"/"
  5181. var id = self.getAttribute('data-pullrefresh-plus-' + attrWebviewId);
  5182. if (!id && typeof args === 'undefined') {
  5183. return false;
  5184. }
  5185. if (!id) { //避免重复初始化5+ pullrefresh
  5186. id = ++$.uuid;
  5187. self.setAttribute('data-pullrefresh-plus-' + attrWebviewId, id);
  5188. document.body.classList.add(CLASS_PLUS_PULLREFRESH);
  5189. $.data[id] = pullRefreshApi = new PlusPullRefresh(self, options);
  5190. } else {
  5191. pullRefreshApi = $.data[id];
  5192. }
  5193. if (options.down && options.down.auto) { //如果设置了auto,则自动下拉一次
  5194. //pullRefreshApi._pulldownLoading(); //parent webview
  5195. pullRefreshApi.beginPulldown();
  5196. } else if (options.up && options.up.auto) { //如果设置了auto,则自动上拉一次
  5197. pullRefreshApi.beginPullup();
  5198. }
  5199. return pullRefreshApi;
  5200. };
  5201. });
  5202. })(mui, document);
  5203. /**
  5204. * off-canvas
  5205. * @param {type} $
  5206. * @param {type} window
  5207. * @param {type} document
  5208. * @param {type} action
  5209. * @returns {undefined}
  5210. */
  5211. (function($, window, document, name) {
  5212. var CLASS_OFF_CANVAS_LEFT = 'mui-off-canvas-left';
  5213. var CLASS_OFF_CANVAS_RIGHT = 'mui-off-canvas-right';
  5214. var CLASS_ACTION_BACKDROP = 'mui-off-canvas-backdrop';
  5215. var CLASS_OFF_CANVAS_WRAP = 'mui-off-canvas-wrap';
  5216. var CLASS_SLIDE_IN = 'mui-slide-in';
  5217. var CLASS_ACTIVE = 'mui-active';
  5218. var CLASS_TRANSITIONING = 'mui-transitioning';
  5219. var SELECTOR_INNER_WRAP = '.mui-inner-wrap';
  5220. var OffCanvas = $.Class.extend({
  5221. init: function(element, options) {
  5222. this.wrapper = this.element = element;
  5223. this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
  5224. this.classList = this.wrapper.classList;
  5225. if (this.scroller) {
  5226. this.options = $.extend(true, {
  5227. dragThresholdX: 10,
  5228. scale: 0.8,
  5229. opacity: 0.1,
  5230. preventDefaultException: {
  5231. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|VIDEO)$/
  5232. },
  5233. }, options);
  5234. document.body.classList.add('mui-fullscreen'); //fullscreen
  5235. this.refresh();
  5236. this.initEvent();
  5237. }
  5238. },
  5239. _preventDefaultException: function(el, exceptions) {
  5240. for (var i in exceptions) {
  5241. if (exceptions[i].test(el[i])) {
  5242. return true;
  5243. }
  5244. }
  5245. return false;
  5246. },
  5247. refresh: function(offCanvas) {
  5248. // offCanvas && !offCanvas.classList.contains(CLASS_ACTIVE) && this.classList.remove(CLASS_ACTIVE);
  5249. this.slideIn = this.classList.contains(CLASS_SLIDE_IN);
  5250. this.scalable = this.classList.contains('mui-scalable') && !this.slideIn;
  5251. this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
  5252. // !offCanvas && this.scroller.classList.remove(CLASS_TRANSITIONING);
  5253. // !offCanvas && this.scroller.setAttribute('style', '');
  5254. this.offCanvasLefts = this.wrapper.querySelectorAll('.' + CLASS_OFF_CANVAS_LEFT);
  5255. this.offCanvasRights = this.wrapper.querySelectorAll('.' + CLASS_OFF_CANVAS_RIGHT);
  5256. if (offCanvas) {
  5257. if (offCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT)) {
  5258. this.offCanvasLeft = offCanvas;
  5259. } else if (offCanvas.classList.contains(CLASS_OFF_CANVAS_RIGHT)) {
  5260. this.offCanvasRight = offCanvas;
  5261. }
  5262. } else {
  5263. this.offCanvasRight = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT);
  5264. this.offCanvasLeft = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT);
  5265. }
  5266. this.offCanvasRightWidth = this.offCanvasLeftWidth = 0;
  5267. this.offCanvasLeftSlideIn = this.offCanvasRightSlideIn = false;
  5268. if (this.offCanvasRight) {
  5269. this.offCanvasRightWidth = this.offCanvasRight.offsetWidth;
  5270. this.offCanvasRightSlideIn = this.slideIn && (this.offCanvasRight.parentNode === this.wrapper);
  5271. // this.offCanvasRight.classList.remove(CLASS_TRANSITIONING);
  5272. // this.offCanvasRight.classList.remove(CLASS_ACTIVE);
  5273. // this.offCanvasRight.setAttribute('style', '');
  5274. }
  5275. if (this.offCanvasLeft) {
  5276. this.offCanvasLeftWidth = this.offCanvasLeft.offsetWidth;
  5277. this.offCanvasLeftSlideIn = this.slideIn && (this.offCanvasLeft.parentNode === this.wrapper);
  5278. // this.offCanvasLeft.classList.remove(CLASS_TRANSITIONING);
  5279. // this.offCanvasLeft.classList.remove(CLASS_ACTIVE);
  5280. // this.offCanvasLeft.setAttribute('style', '');
  5281. }
  5282. this.backdrop = this.scroller.querySelector('.' + CLASS_ACTION_BACKDROP);
  5283. this.options.dragThresholdX = this.options.dragThresholdX || 10;
  5284. this.visible = false;
  5285. this.startX = null;
  5286. this.lastX = null;
  5287. this.offsetX = null;
  5288. this.lastTranslateX = null;
  5289. },
  5290. handleEvent: function(e) {
  5291. switch (e.type) {
  5292. case $.EVENT_START:
  5293. e.target && !this._preventDefaultException(e.target, this.options.preventDefaultException) && e.preventDefault();
  5294. break;
  5295. case 'webkitTransitionEnd': //有个bug需要处理,需要考虑假设没有触发webkitTransitionEnd的情况
  5296. if (e.target === this.scroller) {
  5297. this._dispatchEvent();
  5298. }
  5299. break;
  5300. case 'drag':
  5301. var detail = e.detail;
  5302. if (!this.startX) {
  5303. this.startX = detail.center.x;
  5304. this.lastX = this.startX;
  5305. } else {
  5306. this.lastX = detail.center.x;
  5307. }
  5308. if (!this.isDragging && Math.abs(this.lastX - this.startX) > this.options.dragThresholdX && (detail.direction === 'left' || (detail.direction === 'right'))) {
  5309. if (this.slideIn) {
  5310. this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
  5311. if (this.classList.contains(CLASS_ACTIVE)) {
  5312. if (this.offCanvasRight && this.offCanvasRight.classList.contains(CLASS_ACTIVE)) {
  5313. this.offCanvas = this.offCanvasRight;
  5314. this.offCanvasWidth = this.offCanvasRightWidth;
  5315. } else {
  5316. this.offCanvas = this.offCanvasLeft;
  5317. this.offCanvasWidth = this.offCanvasLeftWidth;
  5318. }
  5319. } else {
  5320. if (detail.direction === 'left' && this.offCanvasRight) {
  5321. this.offCanvas = this.offCanvasRight;
  5322. this.offCanvasWidth = this.offCanvasRightWidth;
  5323. } else if (detail.direction === 'right' && this.offCanvasLeft) {
  5324. this.offCanvas = this.offCanvasLeft;
  5325. this.offCanvasWidth = this.offCanvasLeftWidth;
  5326. } else {
  5327. this.scroller = null;
  5328. }
  5329. }
  5330. } else {
  5331. if (this.classList.contains(CLASS_ACTIVE)) {
  5332. if (detail.direction === 'left') {
  5333. this.offCanvas = this.offCanvasLeft;
  5334. this.offCanvasWidth = this.offCanvasLeftWidth;
  5335. } else {
  5336. this.offCanvas = this.offCanvasRight;
  5337. this.offCanvasWidth = this.offCanvasRightWidth;
  5338. }
  5339. } else {
  5340. if (detail.direction === 'right') {
  5341. this.offCanvas = this.offCanvasLeft;
  5342. this.offCanvasWidth = this.offCanvasLeftWidth;
  5343. } else {
  5344. this.offCanvas = this.offCanvasRight;
  5345. this.offCanvasWidth = this.offCanvasRightWidth;
  5346. }
  5347. }
  5348. }
  5349. if (this.offCanvas && this.scroller) {
  5350. this.startX = this.lastX;
  5351. this.isDragging = true;
  5352. $.gestures.session.lockDirection = true; //锁定方向
  5353. $.gestures.session.startDirection = detail.direction;
  5354. this.offCanvas.classList.remove(CLASS_TRANSITIONING);
  5355. this.scroller.classList.remove(CLASS_TRANSITIONING);
  5356. this.offsetX = this.getTranslateX();
  5357. this._initOffCanvasVisible();
  5358. }
  5359. }
  5360. if (this.isDragging) {
  5361. this.updateTranslate(this.offsetX + (this.lastX - this.startX));
  5362. detail.gesture.preventDefault();
  5363. e.stopPropagation();
  5364. }
  5365. break;
  5366. case 'dragend':
  5367. if (this.isDragging) {
  5368. var detail = e.detail;
  5369. var direction = detail.direction;
  5370. this.isDragging = false;
  5371. this.offCanvas.classList.add(CLASS_TRANSITIONING);
  5372. this.scroller.classList.add(CLASS_TRANSITIONING);
  5373. var ratio = 0;
  5374. var x = this.getTranslateX();
  5375. if (!this.slideIn) {
  5376. if (x >= 0) {
  5377. ratio = (this.offCanvasLeftWidth && (x / this.offCanvasLeftWidth)) || 0;
  5378. } else {
  5379. ratio = (this.offCanvasRightWidth && (x / this.offCanvasRightWidth)) || 0;
  5380. }
  5381. if (ratio === 0) {
  5382. this.openPercentage(0);
  5383. this._dispatchEvent(); //此处不触发webkitTransitionEnd,所以手动dispatch
  5384. return;
  5385. }
  5386. if (direction === 'right' && ratio >= 0 && (ratio >= 0.5 || detail.swipe)) { //右滑打开
  5387. this.openPercentage(100);
  5388. } else if (direction === 'right' && ratio < 0 && (ratio > -0.5 || detail.swipe)) { //右滑关闭
  5389. this.openPercentage(0);
  5390. } else if (direction === 'right' && ratio > 0 && ratio < 0.5) { //右滑还原关闭
  5391. this.openPercentage(0);
  5392. } else if (direction === 'right' && ratio < 0.5) { //右滑还原打开
  5393. this.openPercentage(-100);
  5394. } else if (direction === 'left' && ratio <= 0 && (ratio <= -0.5 || detail.swipe)) { //左滑打开
  5395. this.openPercentage(-100);
  5396. } else if (direction === 'left' && ratio > 0 && (ratio <= 0.5 || detail.swipe)) { //左滑关闭
  5397. this.openPercentage(0);
  5398. } else if (direction === 'left' && ratio < 0 && ratio >= -0.5) { //左滑还原关闭
  5399. this.openPercentage(0);
  5400. } else if (direction === 'left' && ratio > 0.5) { //左滑还原打开
  5401. this.openPercentage(100);
  5402. } else { //默认关闭
  5403. this.openPercentage(0);
  5404. }
  5405. if (ratio === 1 || ratio === -1) { //此处不触发webkitTransitionEnd,所以手动dispatch
  5406. this._dispatchEvent();
  5407. }
  5408. } else {
  5409. if (x >= 0) {
  5410. ratio = (this.offCanvasRightWidth && (x / this.offCanvasRightWidth)) || 0;
  5411. } else {
  5412. ratio = (this.offCanvasLeftWidth && (x / this.offCanvasLeftWidth)) || 0;
  5413. }
  5414. if (direction === 'right' && ratio <= 0 && (ratio >= -0.5 || detail.swipe)) { //右滑打开
  5415. this.openPercentage(100);
  5416. } else if (direction === 'right' && ratio > 0 && (ratio >= 0.5 || detail.swipe)) { //右滑关闭
  5417. this.openPercentage(0);
  5418. } else if (direction === 'right' && ratio <= -0.5) { //右滑还原关闭
  5419. this.openPercentage(0);
  5420. } else if (direction === 'right' && ratio > 0 && ratio <= 0.5) { //右滑还原打开
  5421. this.openPercentage(-100);
  5422. } else if (direction === 'left' && ratio >= 0 && (ratio <= 0.5 || detail.swipe)) { //左滑打开
  5423. this.openPercentage(-100);
  5424. } else if (direction === 'left' && ratio < 0 && (ratio <= -0.5 || detail.swipe)) { //左滑关闭
  5425. this.openPercentage(0);
  5426. } else if (direction === 'left' && ratio >= 0.5) { //左滑还原关闭
  5427. this.openPercentage(0);
  5428. } else if (direction === 'left' && ratio >= -0.5 && ratio < 0) { //左滑还原打开
  5429. this.openPercentage(100);
  5430. } else {
  5431. this.openPercentage(0);
  5432. }
  5433. if (ratio === 1 || ratio === -1 || ratio === 0) {
  5434. this._dispatchEvent();
  5435. return;
  5436. }
  5437. }
  5438. }
  5439. break;
  5440. }
  5441. },
  5442. _dispatchEvent: function() {
  5443. if (this.classList.contains(CLASS_ACTIVE)) {
  5444. $.trigger(this.wrapper, 'shown', this);
  5445. } else {
  5446. $.trigger(this.wrapper, 'hidden', this);
  5447. }
  5448. },
  5449. _initOffCanvasVisible: function() {
  5450. if (!this.visible) {
  5451. this.visible = true;
  5452. if (this.offCanvasLeft) {
  5453. this.offCanvasLeft.style.visibility = 'visible';
  5454. }
  5455. if (this.offCanvasRight) {
  5456. this.offCanvasRight.style.visibility = 'visible';
  5457. }
  5458. }
  5459. },
  5460. initEvent: function() {
  5461. var self = this;
  5462. if (self.backdrop) {
  5463. self.backdrop.addEventListener('tap', function(e) {
  5464. self.close();
  5465. e.detail.gesture.preventDefault();
  5466. });
  5467. }
  5468. if (this.classList.contains('mui-draggable')) {
  5469. this.wrapper.addEventListener($.EVENT_START, this); //临时处理
  5470. this.wrapper.addEventListener('drag', this);
  5471. this.wrapper.addEventListener('dragend', this);
  5472. }
  5473. this.wrapper.addEventListener('webkitTransitionEnd', this);
  5474. },
  5475. openPercentage: function(percentage) {
  5476. var p = percentage / 100;
  5477. if (!this.slideIn) {
  5478. if (this.offCanvasLeft && percentage >= 0) {
  5479. this.updateTranslate(this.offCanvasLeftWidth * p);
  5480. this.offCanvasLeft.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5481. } else if (this.offCanvasRight && percentage <= 0) {
  5482. this.updateTranslate(this.offCanvasRightWidth * p);
  5483. this.offCanvasRight.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5484. }
  5485. this.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5486. } else {
  5487. if (this.offCanvasLeft && percentage >= 0) {
  5488. p = p === 0 ? -1 : 0;
  5489. this.updateTranslate(this.offCanvasLeftWidth * p);
  5490. this.offCanvasLeft.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5491. } else if (this.offCanvasRight && percentage <= 0) {
  5492. p = p === 0 ? 1 : 0;
  5493. this.updateTranslate(this.offCanvasRightWidth * p);
  5494. this.offCanvasRight.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5495. }
  5496. this.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5497. }
  5498. },
  5499. updateTranslate: function(x) {
  5500. if (x !== this.lastTranslateX) {
  5501. if (!this.slideIn) {
  5502. if ((!this.offCanvasLeft && x > 0) || (!this.offCanvasRight && x < 0)) {
  5503. this.setTranslateX(0);
  5504. return;
  5505. }
  5506. if (this.leftShowing && x > this.offCanvasLeftWidth) {
  5507. this.setTranslateX(this.offCanvasLeftWidth);
  5508. return;
  5509. }
  5510. if (this.rightShowing && x < -this.offCanvasRightWidth) {
  5511. this.setTranslateX(-this.offCanvasRightWidth);
  5512. return;
  5513. }
  5514. this.setTranslateX(x);
  5515. if (x >= 0) {
  5516. this.leftShowing = true;
  5517. this.rightShowing = false;
  5518. if (x > 0) {
  5519. if (this.offCanvasLeft) {
  5520. $.each(this.offCanvasLefts, function(index, offCanvas) {
  5521. if (offCanvas === this.offCanvasLeft) {
  5522. this.offCanvasLeft.style.zIndex = 0;
  5523. } else {
  5524. offCanvas.style.zIndex = -1;
  5525. }
  5526. }.bind(this));
  5527. }
  5528. if (this.offCanvasRight) {
  5529. this.offCanvasRight.style.zIndex = -1;
  5530. }
  5531. }
  5532. } else {
  5533. this.rightShowing = true;
  5534. this.leftShowing = false;
  5535. if (this.offCanvasRight) {
  5536. $.each(this.offCanvasRights, function(index, offCanvas) {
  5537. if (offCanvas === this.offCanvasRight) {
  5538. offCanvas.style.zIndex = 0;
  5539. } else {
  5540. offCanvas.style.zIndex = -1;
  5541. }
  5542. }.bind(this));
  5543. }
  5544. if (this.offCanvasLeft) {
  5545. this.offCanvasLeft.style.zIndex = -1;
  5546. }
  5547. }
  5548. } else {
  5549. if (this.offCanvas.classList.contains(CLASS_OFF_CANVAS_RIGHT)) {
  5550. if (x < 0) {
  5551. this.setTranslateX(0);
  5552. return;
  5553. }
  5554. if (x > this.offCanvasRightWidth) {
  5555. this.setTranslateX(this.offCanvasRightWidth);
  5556. return;
  5557. }
  5558. } else {
  5559. if (x > 0) {
  5560. this.setTranslateX(0);
  5561. return;
  5562. }
  5563. if (x < -this.offCanvasLeftWidth) {
  5564. this.setTranslateX(-this.offCanvasLeftWidth);
  5565. return;
  5566. }
  5567. }
  5568. this.setTranslateX(x);
  5569. }
  5570. this.lastTranslateX = x;
  5571. }
  5572. },
  5573. setTranslateX: $.animationFrame(function(x) {
  5574. if (this.scroller) {
  5575. if (this.scalable && this.offCanvas.parentNode === this.wrapper) {
  5576. var percent = Math.abs(x) / this.offCanvasWidth;
  5577. var zoomOutScale = 1 - (1 - this.options.scale) * percent;
  5578. var zoomInScale = this.options.scale + (1 - this.options.scale) * percent;
  5579. var zoomOutOpacity = 1 - (1 - this.options.opacity) * percent;
  5580. var zoomInOpacity = this.options.opacity + (1 - this.options.opacity) * percent;
  5581. if (this.offCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT)) {
  5582. this.offCanvas.style.webkitTransformOrigin = '-100%';
  5583. this.scroller.style.webkitTransformOrigin = 'left';
  5584. } else {
  5585. this.offCanvas.style.webkitTransformOrigin = '200%';
  5586. this.scroller.style.webkitTransformOrigin = 'right';
  5587. }
  5588. this.offCanvas.style.opacity = zoomInOpacity;
  5589. this.offCanvas.style.webkitTransform = 'translate3d(0,0,0) scale(' + zoomInScale + ')';
  5590. this.scroller.style.webkitTransform = 'translate3d(' + x + 'px,0,0) scale(' + zoomOutScale + ')';
  5591. } else {
  5592. if (this.slideIn) {
  5593. this.offCanvas.style.webkitTransform = 'translate3d(' + x + 'px,0,0)';
  5594. } else {
  5595. this.scroller.style.webkitTransform = 'translate3d(' + x + 'px,0,0)';
  5596. }
  5597. }
  5598. }
  5599. }),
  5600. getTranslateX: function() {
  5601. if (this.offCanvas) {
  5602. var scroller = this.slideIn ? this.offCanvas : this.scroller;
  5603. var result = $.parseTranslateMatrix($.getStyles(scroller, 'webkitTransform'));
  5604. return (result && result.x) || 0;
  5605. }
  5606. return 0;
  5607. },
  5608. isShown: function(direction) {
  5609. var shown = false;
  5610. if (!this.slideIn) {
  5611. var x = this.getTranslateX();
  5612. if (direction === 'right') {
  5613. shown = this.classList.contains(CLASS_ACTIVE) && x < 0;
  5614. } else if (direction === 'left') {
  5615. shown = this.classList.contains(CLASS_ACTIVE) && x > 0;
  5616. } else {
  5617. shown = this.classList.contains(CLASS_ACTIVE) && x !== 0;
  5618. }
  5619. } else {
  5620. if (direction === 'left') {
  5621. shown = this.classList.contains(CLASS_ACTIVE) && this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE);
  5622. } else if (direction === 'right') {
  5623. shown = this.classList.contains(CLASS_ACTIVE) && this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE);
  5624. } else {
  5625. shown = this.classList.contains(CLASS_ACTIVE) && (this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE) || this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE));
  5626. }
  5627. }
  5628. return shown;
  5629. },
  5630. close: function() {
  5631. this._initOffCanvasVisible();
  5632. this.offCanvas = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE) || this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE);
  5633. this.offCanvasWidth = this.offCanvas.offsetWidth;
  5634. if (this.scroller) {
  5635. this.offCanvas.offsetHeight;
  5636. this.offCanvas.classList.add(CLASS_TRANSITIONING);
  5637. this.scroller.classList.add(CLASS_TRANSITIONING);
  5638. this.openPercentage(0);
  5639. }
  5640. },
  5641. show: function(direction) {
  5642. this._initOffCanvasVisible();
  5643. if (this.isShown(direction)) {
  5644. return false;
  5645. }
  5646. if (!direction) {
  5647. direction = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT) ? 'right' : 'left';
  5648. }
  5649. if (direction === 'right') {
  5650. this.offCanvas = this.offCanvasRight;
  5651. this.offCanvasWidth = this.offCanvasRightWidth;
  5652. } else {
  5653. this.offCanvas = this.offCanvasLeft;
  5654. this.offCanvasWidth = this.offCanvasLeftWidth;
  5655. }
  5656. if (this.scroller) {
  5657. this.offCanvas.offsetHeight;
  5658. this.offCanvas.classList.add(CLASS_TRANSITIONING);
  5659. this.scroller.classList.add(CLASS_TRANSITIONING);
  5660. this.openPercentage(direction === 'left' ? 100 : -100);
  5661. }
  5662. return true;
  5663. },
  5664. toggle: function(directionOrOffCanvas) {
  5665. var direction = directionOrOffCanvas;
  5666. if (directionOrOffCanvas && directionOrOffCanvas.classList) {
  5667. direction = directionOrOffCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT) ? 'left' : 'right';
  5668. this.refresh(directionOrOffCanvas);
  5669. }
  5670. if (!this.show(direction)) {
  5671. this.close();
  5672. }
  5673. }
  5674. });
  5675. //hash to offcanvas
  5676. var findOffCanvasContainer = function(target) {
  5677. parentNode = target.parentNode;
  5678. if (parentNode) {
  5679. if (parentNode.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
  5680. return parentNode;
  5681. } else {
  5682. parentNode = parentNode.parentNode;
  5683. if (parentNode.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
  5684. return parentNode;
  5685. }
  5686. }
  5687. }
  5688. };
  5689. var handle = function(event, target) {
  5690. if (target.tagName === 'A' && target.hash) {
  5691. var offcanvas = document.getElementById(target.hash.replace('#', ''));
  5692. if (offcanvas) {
  5693. var container = findOffCanvasContainer(offcanvas);
  5694. if (container) {
  5695. $.targets._container = container;
  5696. return offcanvas;
  5697. }
  5698. }
  5699. }
  5700. return false;
  5701. };
  5702. $.registerTarget({
  5703. name: name,
  5704. index: 60,
  5705. handle: handle,
  5706. target: false,
  5707. isReset: false,
  5708. isContinue: true
  5709. });
  5710. window.addEventListener('tap', function(e) {
  5711. if (!$.targets.offcanvas) {
  5712. return;
  5713. }
  5714. //TODO 此处类型的代码后续考虑统一优化(target机制),现在的实现费力不讨好
  5715. var target = e.target;
  5716. for (; target && target !== document; target = target.parentNode) {
  5717. if (target.tagName === 'A' && target.hash && target.hash === ('#' + $.targets.offcanvas.id)) {
  5718. e.detail && e.detail.gesture && e.detail.gesture.preventDefault(); //fixed hashchange
  5719. $($.targets._container).offCanvas().toggle($.targets.offcanvas);
  5720. $.targets.offcanvas = $.targets._container = null;
  5721. break;
  5722. }
  5723. }
  5724. });
  5725. $.fn.offCanvas = function(options) {
  5726. var offCanvasApis = [];
  5727. this.each(function() {
  5728. var offCanvasApi = null;
  5729. var self = this;
  5730. //hack old version
  5731. if (!self.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
  5732. self = findOffCanvasContainer(self);
  5733. }
  5734. var id = self.getAttribute('data-offCanvas');
  5735. if (!id) {
  5736. id = ++$.uuid;
  5737. $.data[id] = offCanvasApi = new OffCanvas(self, options);
  5738. self.setAttribute('data-offCanvas', id);
  5739. } else {
  5740. offCanvasApi = $.data[id];
  5741. }
  5742. if (options === 'show' || options === 'close' || options === 'toggle') {
  5743. offCanvasApi.toggle();
  5744. }
  5745. offCanvasApis.push(offCanvasApi);
  5746. });
  5747. return offCanvasApis.length === 1 ? offCanvasApis[0] : offCanvasApis;
  5748. };
  5749. $.ready(function() {
  5750. $('.mui-off-canvas-wrap').offCanvas();
  5751. });
  5752. })(mui, window, document, 'offcanvas');
  5753. /**
  5754. * actions
  5755. * @param {type} $
  5756. * @param {type} name
  5757. * @returns {undefined}
  5758. */
  5759. (function($, name) {
  5760. var CLASS_ACTION = 'mui-action';
  5761. var handle = function(event, target) {
  5762. var className = target.className || '';
  5763. if (typeof className !== 'string') { //svg className(SVGAnimatedString)
  5764. className = '';
  5765. }
  5766. if (className && ~className.indexOf(CLASS_ACTION)) {
  5767. if (target.classList.contains('mui-action-back')) {
  5768. event.preventDefault();
  5769. }
  5770. return target;
  5771. }
  5772. return false;
  5773. };
  5774. $.registerTarget({
  5775. name: name,
  5776. index: 50,
  5777. handle: handle,
  5778. target: false,
  5779. isContinue: true
  5780. });
  5781. })(mui, 'action');
  5782. /**
  5783. * Modals
  5784. * @param {type} $
  5785. * @param {type} window
  5786. * @param {type} document
  5787. * @param {type} name
  5788. * @returns {undefined}
  5789. */
  5790. (function($, window, document, name) {
  5791. var CLASS_MODAL = 'mui-modal';
  5792. var handle = function(event, target) {
  5793. if (target.tagName === 'A' && target.hash) {
  5794. var modal = document.getElementById(target.hash.replace('#', ''));
  5795. if (modal && modal.classList.contains(CLASS_MODAL)) {
  5796. return modal;
  5797. }
  5798. }
  5799. return false;
  5800. };
  5801. $.registerTarget({
  5802. name: name,
  5803. index: 50,
  5804. handle: handle,
  5805. target: false,
  5806. isReset: false,
  5807. isContinue: true
  5808. });
  5809. window.addEventListener('tap', function(event) {
  5810. if ($.targets.modal) {
  5811. event.detail.gesture.preventDefault(); //fixed hashchange
  5812. $.targets.modal.classList.toggle('mui-active');
  5813. }
  5814. });
  5815. })(mui, window, document, 'modal');
  5816. /**
  5817. * Popovers
  5818. * @param {type} $
  5819. * @param {type} window
  5820. * @param {type} document
  5821. * @param {type} name
  5822. * @param {type} undefined
  5823. * @returns {undefined}
  5824. */
  5825. (function($, window, document, name) {
  5826. var CLASS_POPOVER = 'mui-popover';
  5827. var CLASS_POPOVER_ARROW = 'mui-popover-arrow';
  5828. var CLASS_ACTION_POPOVER = 'mui-popover-action';
  5829. var CLASS_BACKDROP = 'mui-backdrop';
  5830. var CLASS_BAR_POPOVER = 'mui-bar-popover';
  5831. var CLASS_BAR_BACKDROP = 'mui-bar-backdrop';
  5832. var CLASS_ACTION_BACKDROP = 'mui-backdrop-action';
  5833. var CLASS_ACTIVE = 'mui-active';
  5834. var CLASS_BOTTOM = 'mui-bottom';
  5835. var handle = function(event, target) {
  5836. if (target.tagName === 'A' && target.hash) {
  5837. $.targets._popover = document.getElementById(target.hash.replace('#', ''));
  5838. if ($.targets._popover && $.targets._popover.classList.contains(CLASS_POPOVER)) {
  5839. return target;
  5840. } else {
  5841. $.targets._popover = null;
  5842. }
  5843. }
  5844. return false;
  5845. };
  5846. $.registerTarget({
  5847. name: name,
  5848. index: 60,
  5849. handle: handle,
  5850. target: false,
  5851. isReset: false,
  5852. isContinue: true
  5853. });
  5854. var onPopoverShown = function(e) {
  5855. this.removeEventListener('webkitTransitionEnd', onPopoverShown);
  5856. this.addEventListener($.EVENT_MOVE, $.preventDefault);
  5857. $.trigger(this, 'shown', this);
  5858. }
  5859. var onPopoverHidden = function(e) {
  5860. setStyle(this, 'none');
  5861. this.removeEventListener('webkitTransitionEnd', onPopoverHidden);
  5862. this.removeEventListener($.EVENT_MOVE, $.preventDefault);
  5863. $.trigger(this, 'hidden', this);
  5864. };
  5865. var backdrop = (function() {
  5866. var element = document.createElement('div');
  5867. element.classList.add(CLASS_BACKDROP);
  5868. element.addEventListener($.EVENT_MOVE, $.preventDefault);
  5869. element.addEventListener('tap', function(e) {
  5870. var popover = $.targets._popover;
  5871. if (popover) {
  5872. popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
  5873. popover.classList.remove(CLASS_ACTIVE);
  5874. removeBackdrop(popover);
  5875. }
  5876. });
  5877. return element;
  5878. }());
  5879. var removeBackdropTimer;
  5880. var removeBackdrop = function(popover) {
  5881. backdrop.setAttribute('style', 'opacity:0');
  5882. $.targets.popover = $.targets._popover = null; //reset
  5883. removeBackdropTimer = $.later(function() {
  5884. if (!popover.classList.contains(CLASS_ACTIVE) && backdrop.parentNode && backdrop.parentNode === document.body) {
  5885. document.body.removeChild(backdrop);
  5886. }
  5887. }, 350);
  5888. };
  5889. window.addEventListener('tap', function(e) {
  5890. if (!$.targets.popover) {
  5891. return;
  5892. }
  5893. var toggle = false;
  5894. var target = e.target;
  5895. for (; target && target !== document; target = target.parentNode) {
  5896. if (target === $.targets.popover) {
  5897. toggle = true;
  5898. }
  5899. }
  5900. if (toggle) {
  5901. e.detail.gesture.preventDefault(); //fixed hashchange
  5902. togglePopover($.targets._popover, $.targets.popover);
  5903. }
  5904. });
  5905. var togglePopover = function(popover, anchor, state) {
  5906. if ((state === 'show' && popover.classList.contains(CLASS_ACTIVE)) || (state === 'hide' && !popover.classList.contains(CLASS_ACTIVE))) {
  5907. return;
  5908. }
  5909. removeBackdropTimer && removeBackdropTimer.cancel(); //取消remove的timer
  5910. //remove一遍,以免来回快速切换,导致webkitTransitionEnd不触发,无法remove
  5911. popover.removeEventListener('webkitTransitionEnd', onPopoverShown);
  5912. popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
  5913. backdrop.classList.remove(CLASS_BAR_BACKDROP);
  5914. backdrop.classList.remove(CLASS_ACTION_BACKDROP);
  5915. var _popover = document.querySelector('.mui-popover.mui-active');
  5916. if (_popover) {
  5917. // _popover.setAttribute('style', '');
  5918. _popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
  5919. _popover.classList.remove(CLASS_ACTIVE);
  5920. // _popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
  5921. //同一个弹出则直接返回,解决同一个popover的toggle
  5922. if (popover === _popover) {
  5923. removeBackdrop(_popover);
  5924. return;
  5925. }
  5926. }
  5927. var isActionSheet = false;
  5928. if (popover.classList.contains(CLASS_BAR_POPOVER) || popover.classList.contains(CLASS_ACTION_POPOVER)) { //navBar
  5929. if (popover.classList.contains(CLASS_ACTION_POPOVER)) { //action sheet popover
  5930. isActionSheet = true;
  5931. backdrop.classList.add(CLASS_ACTION_BACKDROP);
  5932. } else { //bar popover
  5933. backdrop.classList.add(CLASS_BAR_BACKDROP);
  5934. // if (anchor) {
  5935. // if (anchor.parentNode) {
  5936. // var offsetWidth = anchor.offsetWidth;
  5937. // var offsetLeft = anchor.offsetLeft;
  5938. // var innerWidth = window.innerWidth;
  5939. // popover.style.left = (Math.min(Math.max(offsetLeft, defaultPadding), innerWidth - offsetWidth - defaultPadding)) + "px";
  5940. // } else {
  5941. // //TODO anchor is position:{left,top,bottom,right}
  5942. // }
  5943. // }
  5944. }
  5945. }
  5946. setStyle(popover, 'block'); //actionsheet transform
  5947. popover.offsetHeight;
  5948. popover.classList.add(CLASS_ACTIVE);
  5949. backdrop.setAttribute('style', '');
  5950. document.body.appendChild(backdrop);
  5951. calPosition(popover, anchor, isActionSheet); //position
  5952. backdrop.classList.add(CLASS_ACTIVE);
  5953. popover.addEventListener('webkitTransitionEnd', onPopoverShown);
  5954. };
  5955. var setStyle = function(popover, display, top, left) {
  5956. var style = popover.style;
  5957. if (typeof display !== 'undefined')
  5958. style.display = display;
  5959. if (typeof top !== 'undefined')
  5960. style.top = top + 'px';
  5961. if (typeof left !== 'undefined')
  5962. style.left = left + 'px';
  5963. };
  5964. var calPosition = function(popover, anchor, isActionSheet) {
  5965. if (!popover || !anchor) {
  5966. return;
  5967. }
  5968. if (isActionSheet) { //actionsheet
  5969. setStyle(popover, 'block')
  5970. return;
  5971. }
  5972. var wWidth = window.innerWidth;
  5973. var wHeight = window.innerHeight;
  5974. var pWidth = popover.offsetWidth;
  5975. var pHeight = popover.offsetHeight;
  5976. var aWidth = anchor.offsetWidth;
  5977. var aHeight = anchor.offsetHeight;
  5978. var offset = $.offset(anchor);
  5979. var arrow = popover.querySelector('.' + CLASS_POPOVER_ARROW);
  5980. if (!arrow) {
  5981. arrow = document.createElement('div');
  5982. arrow.className = CLASS_POPOVER_ARROW;
  5983. popover.appendChild(arrow);
  5984. }
  5985. var arrowSize = arrow && arrow.offsetWidth / 2 || 0;
  5986. var pTop = 0;
  5987. var pLeft = 0;
  5988. var diff = 0;
  5989. var arrowLeft = 0;
  5990. var defaultPadding = popover.classList.contains(CLASS_ACTION_POPOVER) ? 0 : 5;
  5991. var position = 'top';
  5992. if ((pHeight + arrowSize) < (offset.top - window.pageYOffset)) { //top
  5993. pTop = offset.top - pHeight - arrowSize;
  5994. } else if ((pHeight + arrowSize) < (wHeight - (offset.top - window.pageYOffset) - aHeight)) { //bottom
  5995. position = 'bottom';
  5996. pTop = offset.top + aHeight + arrowSize;
  5997. } else { //middle
  5998. position = 'middle';
  5999. pTop = Math.max((wHeight - pHeight) / 2 + window.pageYOffset, 0);
  6000. pLeft = Math.max((wWidth - pWidth) / 2 + window.pageXOffset, 0);
  6001. }
  6002. if (position === 'top' || position === 'bottom') {
  6003. pLeft = aWidth / 2 + offset.left - pWidth / 2;
  6004. diff = pLeft;
  6005. if (pLeft < defaultPadding) pLeft = defaultPadding;
  6006. if (pLeft + pWidth > wWidth) pLeft = wWidth - pWidth - defaultPadding;
  6007. if (arrow) {
  6008. if (position === 'top') {
  6009. arrow.classList.add(CLASS_BOTTOM);
  6010. } else {
  6011. arrow.classList.remove(CLASS_BOTTOM);
  6012. }
  6013. diff = diff - pLeft;
  6014. arrowLeft = (pWidth / 2 - arrowSize / 2 + diff);
  6015. arrowLeft = Math.max(Math.min(arrowLeft, pWidth - arrowSize * 2 - 6), 6);
  6016. arrow.setAttribute('style', 'left:' + arrowLeft + 'px');
  6017. }
  6018. } else if (position === 'middle') {
  6019. arrow.setAttribute('style', 'display:none');
  6020. }
  6021. setStyle(popover, 'block', pTop, pLeft);
  6022. };
  6023. $.createMask = function(callback) {
  6024. var element = document.createElement('div');
  6025. element.classList.add(CLASS_BACKDROP);
  6026. element.addEventListener($.EVENT_MOVE, $.preventDefault);
  6027. element.addEventListener('tap', function() {
  6028. mask.close();
  6029. });
  6030. var mask = [element];
  6031. mask._show = false;
  6032. mask.show = function() {
  6033. mask._show = true;
  6034. element.setAttribute('style', 'opacity:1');
  6035. document.body.appendChild(element);
  6036. return mask;
  6037. };
  6038. mask._remove = function() {
  6039. if (mask._show) {
  6040. mask._show = false;
  6041. element.setAttribute('style', 'opacity:0');
  6042. $.later(function() {
  6043. var body = document.body;
  6044. element.parentNode === body && body.removeChild(element);
  6045. }, 350);
  6046. }
  6047. return mask;
  6048. };
  6049. mask.close = function() {
  6050. if (callback) {
  6051. if (callback() !== false) {
  6052. mask._remove();
  6053. }
  6054. } else {
  6055. mask._remove();
  6056. }
  6057. };
  6058. return mask;
  6059. };
  6060. $.fn.popover = function() {
  6061. var args = arguments;
  6062. this.each(function() {
  6063. $.targets._popover = this;
  6064. if (args[0] === 'show' || args[0] === 'hide' || args[0] === 'toggle') {
  6065. togglePopover(this, args[1], args[0]);
  6066. }
  6067. });
  6068. };
  6069. })(mui, window, document, 'popover');
  6070. /**
  6071. * segmented-controllers
  6072. * @param {type} $
  6073. * @param {type} window
  6074. * @param {type} document
  6075. * @param {type} undefined
  6076. * @returns {undefined}
  6077. */
  6078. (function($, window, document, name, undefined) {
  6079. var CLASS_CONTROL_ITEM = 'mui-control-item';
  6080. var CLASS_SEGMENTED_CONTROL = 'mui-segmented-control';
  6081. var CLASS_SEGMENTED_CONTROL_VERTICAL = 'mui-segmented-control-vertical';
  6082. var CLASS_CONTROL_CONTENT = 'mui-control-content';
  6083. var CLASS_TAB_BAR = 'mui-bar-tab';
  6084. var CLASS_TAB_ITEM = 'mui-tab-item';
  6085. var CLASS_SLIDER_ITEM = 'mui-slider-item';
  6086. var handle = function(event, target) {
  6087. if (target.classList && (target.classList.contains(CLASS_CONTROL_ITEM) || target.classList.contains(CLASS_TAB_ITEM))) {
  6088. if (target.parentNode && target.parentNode.classList && target.parentNode.classList.contains(CLASS_SEGMENTED_CONTROL_VERTICAL)) {
  6089. //vertical 如果preventDefault会导致无法滚动
  6090. } else {
  6091. event.preventDefault(); //stop hash change
  6092. }
  6093. // if (target.hash) {
  6094. return target;
  6095. // }
  6096. }
  6097. return false;
  6098. };
  6099. $.registerTarget({
  6100. name: name,
  6101. index: 80,
  6102. handle: handle,
  6103. target: false
  6104. });
  6105. window.addEventListener('tap', function(e) {
  6106. var targetTab = $.targets.tab;
  6107. if (!targetTab) {
  6108. return;
  6109. }
  6110. var activeTab;
  6111. var activeBodies;
  6112. var targetBody;
  6113. var className = 'mui-active';
  6114. var classSelector = '.' + className;
  6115. var segmentedControl = targetTab.parentNode;
  6116. for (; segmentedControl && segmentedControl !== document; segmentedControl = segmentedControl.parentNode) {
  6117. if (segmentedControl.classList.contains(CLASS_SEGMENTED_CONTROL)) {
  6118. activeTab = segmentedControl.querySelector(classSelector + '.' + CLASS_CONTROL_ITEM);
  6119. break;
  6120. } else if (segmentedControl.classList.contains(CLASS_TAB_BAR)) {
  6121. activeTab = segmentedControl.querySelector(classSelector + '.' + CLASS_TAB_ITEM);
  6122. }
  6123. }
  6124. if (activeTab) {
  6125. activeTab.classList.remove(className);
  6126. }
  6127. var isLastActive = targetTab === activeTab;
  6128. if (targetTab) {
  6129. targetTab.classList.add(className);
  6130. }
  6131. if (!targetTab.hash) {
  6132. return;
  6133. }
  6134. targetBody = document.getElementById(targetTab.hash.replace('#', ''));
  6135. if (!targetBody) {
  6136. return;
  6137. }
  6138. if (!targetBody.classList.contains(CLASS_CONTROL_CONTENT)) { //tab bar popover
  6139. targetTab.classList[isLastActive ? 'remove' : 'add'](className);
  6140. return;
  6141. }
  6142. if (isLastActive) { //same
  6143. return;
  6144. }
  6145. var parentNode = targetBody.parentNode;
  6146. activeBodies = parentNode.querySelectorAll('.' + CLASS_CONTROL_CONTENT + classSelector);
  6147. for (var i = 0; i < activeBodies.length; i++) {
  6148. var activeBody = activeBodies[i];
  6149. activeBody.parentNode === parentNode && activeBody.classList.remove(className);
  6150. }
  6151. targetBody.classList.add(className);
  6152. var contents = [];
  6153. var _contents = parentNode.querySelectorAll('.' + CLASS_CONTROL_CONTENT);
  6154. for (var i = 0; i < _contents.length; i++) { //查找直属子节点
  6155. _contents[i].parentNode === parentNode && (contents.push(_contents[i]));
  6156. }
  6157. $.trigger(targetBody, $.eventName('shown', name), {
  6158. tabNumber: Array.prototype.indexOf.call(contents, targetBody)
  6159. });
  6160. e.detail && e.detail.gesture.preventDefault(); //fixed hashchange
  6161. });
  6162. })(mui, window, document, 'tab');
  6163. /**
  6164. * Toggles switch
  6165. * @param {type} $
  6166. * @param {type} window
  6167. * @param {type} name
  6168. * @returns {undefined}
  6169. */
  6170. (function($, window, name) {
  6171. var CLASS_SWITCH = 'mui-switch';
  6172. var CLASS_SWITCH_HANDLE = 'mui-switch-handle';
  6173. var CLASS_ACTIVE = 'mui-active';
  6174. var CLASS_DRAGGING = 'mui-dragging';
  6175. var CLASS_DISABLED = 'mui-disabled';
  6176. var SELECTOR_SWITCH_HANDLE = '.' + CLASS_SWITCH_HANDLE;
  6177. var handle = function(event, target) {
  6178. if (target.classList && target.classList.contains(CLASS_SWITCH)) {
  6179. return target;
  6180. }
  6181. return false;
  6182. };
  6183. $.registerTarget({
  6184. name: name,
  6185. index: 100,
  6186. handle: handle,
  6187. target: false
  6188. });
  6189. var Toggle = function(element) {
  6190. this.element = element;
  6191. this.classList = this.element.classList;
  6192. this.handle = this.element.querySelector(SELECTOR_SWITCH_HANDLE);
  6193. this.init();
  6194. this.initEvent();
  6195. };
  6196. Toggle.prototype.init = function() {
  6197. this.toggleWidth = this.element.offsetWidth;
  6198. this.handleWidth = this.handle.offsetWidth;
  6199. this.handleX = this.toggleWidth - this.handleWidth - 3;
  6200. };
  6201. Toggle.prototype.initEvent = function() {
  6202. this.element.addEventListener($.EVENT_START, this);
  6203. this.element.addEventListener('drag', this);
  6204. this.element.addEventListener('swiperight', this);
  6205. this.element.addEventListener($.EVENT_END, this);
  6206. this.element.addEventListener($.EVENT_CANCEL, this);
  6207. };
  6208. Toggle.prototype.handleEvent = function(e) {
  6209. if (this.classList.contains(CLASS_DISABLED)) {
  6210. return;
  6211. }
  6212. switch (e.type) {
  6213. case $.EVENT_START:
  6214. this.start(e);
  6215. break;
  6216. case 'drag':
  6217. this.drag(e);
  6218. break;
  6219. case 'swiperight':
  6220. this.swiperight();
  6221. break;
  6222. case $.EVENT_END:
  6223. case $.EVENT_CANCEL:
  6224. this.end(e);
  6225. break;
  6226. }
  6227. };
  6228. Toggle.prototype.start = function(e) {
  6229. this.handle.style.webkitTransitionDuration = this.element.style.webkitTransitionDuration = '.2s';
  6230. this.classList.add(CLASS_DRAGGING);
  6231. if (this.toggleWidth === 0 || this.handleWidth === 0) { //当switch处于隐藏状态时,width为0,需要重新初始化
  6232. this.init();
  6233. }
  6234. };
  6235. Toggle.prototype.drag = function(e) {
  6236. var detail = e.detail;
  6237. if (!this.isDragging) {
  6238. if (detail.direction === 'left' || detail.direction === 'right') {
  6239. this.isDragging = true;
  6240. this.lastChanged = undefined;
  6241. this.initialState = this.classList.contains(CLASS_ACTIVE);
  6242. }
  6243. }
  6244. if (this.isDragging) {
  6245. this.setTranslateX(detail.deltaX);
  6246. e.stopPropagation();
  6247. detail.gesture.preventDefault();
  6248. }
  6249. };
  6250. Toggle.prototype.swiperight = function(e) {
  6251. if (this.isDragging) {
  6252. e.stopPropagation();
  6253. }
  6254. };
  6255. Toggle.prototype.end = function(e) {
  6256. this.classList.remove(CLASS_DRAGGING);
  6257. if (this.isDragging) {
  6258. this.isDragging = false;
  6259. e.stopPropagation();
  6260. $.trigger(this.element, 'toggle', {
  6261. isActive: this.classList.contains(CLASS_ACTIVE)
  6262. });
  6263. } else {
  6264. this.toggle();
  6265. }
  6266. };
  6267. Toggle.prototype.toggle = function(animate) {
  6268. var classList = this.classList;
  6269. if (animate === false) {
  6270. this.handle.style.webkitTransitionDuration = this.element.style.webkitTransitionDuration = '0s';
  6271. } else {
  6272. this.handle.style.webkitTransitionDuration = this.element.style.webkitTransitionDuration = '.2s';
  6273. }
  6274. if (classList.contains(CLASS_ACTIVE)) {
  6275. classList.remove(CLASS_ACTIVE);
  6276. this.handle.style.webkitTransform = 'translate(0,0)';
  6277. } else {
  6278. classList.add(CLASS_ACTIVE);
  6279. this.handle.style.webkitTransform = 'translate(' + this.handleX + 'px,0)';
  6280. }
  6281. $.trigger(this.element, 'toggle', {
  6282. isActive: this.classList.contains(CLASS_ACTIVE)
  6283. });
  6284. };
  6285. Toggle.prototype.setTranslateX = $.animationFrame(function(x) {
  6286. if (!this.isDragging) {
  6287. return;
  6288. }
  6289. var isChanged = false;
  6290. if ((this.initialState && -x > (this.handleX / 2)) || (!this.initialState && x > (this.handleX / 2))) {
  6291. isChanged = true;
  6292. }
  6293. if (this.lastChanged !== isChanged) {
  6294. if (isChanged) {
  6295. this.handle.style.webkitTransform = 'translate(' + (this.initialState ? 0 : this.handleX) + 'px,0)';
  6296. this.classList[this.initialState ? 'remove' : 'add'](CLASS_ACTIVE);
  6297. } else {
  6298. this.handle.style.webkitTransform = 'translate(' + (this.initialState ? this.handleX : 0) + 'px,0)';
  6299. this.classList[this.initialState ? 'add' : 'remove'](CLASS_ACTIVE);
  6300. }
  6301. this.lastChanged = isChanged;
  6302. }
  6303. });
  6304. $.fn['switch'] = function(options) {
  6305. var switchApis = [];
  6306. this.each(function() {
  6307. var switchApi = null;
  6308. var id = this.getAttribute('data-switch');
  6309. if (!id) {
  6310. id = ++$.uuid;
  6311. $.data[id] = new Toggle(this);
  6312. this.setAttribute('data-switch', id);
  6313. } else {
  6314. switchApi = $.data[id];
  6315. }
  6316. switchApis.push(switchApi);
  6317. });
  6318. return switchApis.length > 1 ? switchApis : switchApis[0];
  6319. };
  6320. $.ready(function() {
  6321. $('.' + CLASS_SWITCH)['switch']();
  6322. });
  6323. })(mui, window, 'toggle');
  6324. /**
  6325. * Tableviews
  6326. * @param {type} $
  6327. * @param {type} window
  6328. * @param {type} document
  6329. * @returns {undefined}
  6330. */
  6331. (function($, window, document) {
  6332. var CLASS_ACTIVE = 'mui-active';
  6333. var CLASS_SELECTED = 'mui-selected';
  6334. var CLASS_GRID_VIEW = 'mui-grid-view';
  6335. var CLASS_RADIO_VIEW = 'mui-table-view-radio';
  6336. var CLASS_TABLE_VIEW_CELL = 'mui-table-view-cell';
  6337. var CLASS_COLLAPSE_CONTENT = 'mui-collapse-content';
  6338. var CLASS_DISABLED = 'mui-disabled';
  6339. var CLASS_TOGGLE = 'mui-switch';
  6340. var CLASS_BTN = 'mui-btn';
  6341. var CLASS_SLIDER_HANDLE = 'mui-slider-handle';
  6342. var CLASS_SLIDER_LEFT = 'mui-slider-left';
  6343. var CLASS_SLIDER_RIGHT = 'mui-slider-right';
  6344. var CLASS_TRANSITIONING = 'mui-transitioning';
  6345. var SELECTOR_SLIDER_HANDLE = '.' + CLASS_SLIDER_HANDLE;
  6346. var SELECTOR_SLIDER_LEFT = '.' + CLASS_SLIDER_LEFT;
  6347. var SELECTOR_SLIDER_RIGHT = '.' + CLASS_SLIDER_RIGHT;
  6348. var SELECTOR_SELECTED = '.' + CLASS_SELECTED;
  6349. var SELECTOR_BUTTON = '.' + CLASS_BTN;
  6350. var overFactor = 0.8;
  6351. var cell, a;
  6352. var isMoved = isOpened = openedActions = progress = false;
  6353. var sliderHandle = sliderActionLeft = sliderActionRight = buttonsLeft = buttonsRight = sliderDirection = sliderRequestAnimationFrame = false;
  6354. var timer = translateX = lastTranslateX = sliderActionLeftWidth = sliderActionRightWidth = 0;
  6355. var toggleActive = function(isActive) {
  6356. if (isActive) {
  6357. if (a) {
  6358. a.classList.add(CLASS_ACTIVE);
  6359. } else if (cell) {
  6360. cell.classList.add(CLASS_ACTIVE);
  6361. }
  6362. } else {
  6363. timer && timer.cancel();
  6364. if (a) {
  6365. a.classList.remove(CLASS_ACTIVE);
  6366. } else if (cell) {
  6367. cell.classList.remove(CLASS_ACTIVE);
  6368. }
  6369. }
  6370. };
  6371. var updateTranslate = function() {
  6372. if (translateX !== lastTranslateX) {
  6373. if (buttonsRight && buttonsRight.length > 0) {
  6374. progress = translateX / sliderActionRightWidth;
  6375. if (translateX < -sliderActionRightWidth) {
  6376. translateX = -sliderActionRightWidth - Math.pow(-translateX - sliderActionRightWidth, overFactor);
  6377. }
  6378. for (var i = 0, len = buttonsRight.length; i < len; i++) {
  6379. var buttonRight = buttonsRight[i];
  6380. if (typeof buttonRight._buttonOffset === 'undefined') {
  6381. buttonRight._buttonOffset = buttonRight.offsetLeft;
  6382. }
  6383. buttonOffset = buttonRight._buttonOffset;
  6384. setTranslate(buttonRight, (translateX - buttonOffset * (1 + Math.max(progress, -1))));
  6385. }
  6386. }
  6387. if (buttonsLeft && buttonsLeft.length > 0) {
  6388. progress = translateX / sliderActionLeftWidth;
  6389. if (translateX > sliderActionLeftWidth) {
  6390. translateX = sliderActionLeftWidth + Math.pow(translateX - sliderActionLeftWidth, overFactor);
  6391. }
  6392. for (var i = 0, len = buttonsLeft.length; i < len; i++) {
  6393. var buttonLeft = buttonsLeft[i];
  6394. if (typeof buttonLeft._buttonOffset === 'undefined') {
  6395. buttonLeft._buttonOffset = sliderActionLeftWidth - buttonLeft.offsetLeft - buttonLeft.offsetWidth;
  6396. }
  6397. buttonOffset = buttonLeft._buttonOffset;
  6398. if (buttonsLeft.length > 1) {
  6399. buttonLeft.style.zIndex = buttonsLeft.length - i;
  6400. }
  6401. setTranslate(buttonLeft, (translateX + buttonOffset * (1 - Math.min(progress, 1))));
  6402. }
  6403. }
  6404. setTranslate(sliderHandle, translateX);
  6405. lastTranslateX = translateX;
  6406. }
  6407. sliderRequestAnimationFrame = requestAnimationFrame(function() {
  6408. updateTranslate();
  6409. });
  6410. };
  6411. var setTranslate = function(element, x) {
  6412. if (element) {
  6413. element.style.webkitTransform = 'translate(' + x + 'px,0)';
  6414. }
  6415. };
  6416. window.addEventListener($.EVENT_START, function(event) {
  6417. if (cell) {
  6418. toggleActive(false);
  6419. }
  6420. cell = a = false;
  6421. isMoved = isOpened = openedActions = false;
  6422. var target = event.target;
  6423. var isDisabled = false;
  6424. for (; target && target !== document; target = target.parentNode) {
  6425. if (target.classList) {
  6426. var classList = target.classList;
  6427. if ((target.tagName === 'INPUT' && target.type !== 'radio' && target.type !== 'checkbox') || target.tagName === 'BUTTON' || classList.contains(CLASS_TOGGLE) || classList.contains(CLASS_BTN) || classList.contains(CLASS_DISABLED)) {
  6428. isDisabled = true;
  6429. }
  6430. if (classList.contains(CLASS_COLLAPSE_CONTENT)) { //collapse content
  6431. break;
  6432. }
  6433. if (classList.contains(CLASS_TABLE_VIEW_CELL)) {
  6434. cell = target;
  6435. //TODO swipe to delete close
  6436. var selected = cell.parentNode.querySelector(SELECTOR_SELECTED);
  6437. if (!cell.parentNode.classList.contains(CLASS_RADIO_VIEW) && selected && selected !== cell) {
  6438. $.swipeoutClose(selected);
  6439. cell = isDisabled = false;
  6440. return;
  6441. }
  6442. if (!cell.parentNode.classList.contains(CLASS_GRID_VIEW)) {
  6443. var link = cell.querySelector('a');
  6444. if (link && link.parentNode === cell) { //li>a
  6445. a = link;
  6446. }
  6447. }
  6448. var handle = cell.querySelector(SELECTOR_SLIDER_HANDLE);
  6449. if (handle) {
  6450. toggleEvents(cell);
  6451. event.stopPropagation();
  6452. }
  6453. if (!isDisabled) {
  6454. if (handle) {
  6455. if (timer) {
  6456. timer.cancel();
  6457. }
  6458. timer = $.later(function() {
  6459. toggleActive(true);
  6460. }, 100);
  6461. } else {
  6462. toggleActive(true);
  6463. }
  6464. }
  6465. break;
  6466. }
  6467. }
  6468. }
  6469. });
  6470. window.addEventListener($.EVENT_MOVE, function(event) {
  6471. toggleActive(false);
  6472. });
  6473. var handleEvent = {
  6474. handleEvent: function(event) {
  6475. switch (event.type) {
  6476. case 'drag':
  6477. this.drag(event);
  6478. break;
  6479. case 'dragend':
  6480. this.dragend(event);
  6481. break;
  6482. case 'flick':
  6483. this.flick(event);
  6484. break;
  6485. case 'swiperight':
  6486. this.swiperight(event);
  6487. break;
  6488. case 'swipeleft':
  6489. this.swipeleft(event);
  6490. break;
  6491. }
  6492. },
  6493. drag: function(event) {
  6494. if (!cell) {
  6495. return;
  6496. }
  6497. if (!isMoved) { //init
  6498. sliderHandle = sliderActionLeft = sliderActionRight = buttonsLeft = buttonsRight = sliderDirection = sliderRequestAnimationFrame = false;
  6499. sliderHandle = cell.querySelector(SELECTOR_SLIDER_HANDLE);
  6500. if (sliderHandle) {
  6501. sliderActionLeft = cell.querySelector(SELECTOR_SLIDER_LEFT);
  6502. sliderActionRight = cell.querySelector(SELECTOR_SLIDER_RIGHT);
  6503. if (sliderActionLeft) {
  6504. sliderActionLeftWidth = sliderActionLeft.offsetWidth;
  6505. buttonsLeft = sliderActionLeft.querySelectorAll(SELECTOR_BUTTON);
  6506. }
  6507. if (sliderActionRight) {
  6508. sliderActionRightWidth = sliderActionRight.offsetWidth;
  6509. buttonsRight = sliderActionRight.querySelectorAll(SELECTOR_BUTTON);
  6510. }
  6511. cell.classList.remove(CLASS_TRANSITIONING);
  6512. isOpened = cell.classList.contains(CLASS_SELECTED);
  6513. if (isOpened) {
  6514. openedActions = cell.querySelector(SELECTOR_SLIDER_LEFT + SELECTOR_SELECTED) ? 'left' : 'right';
  6515. }
  6516. }
  6517. }
  6518. var detail = event.detail;
  6519. var direction = detail.direction;
  6520. var angle = detail.angle;
  6521. if (direction === 'left' && (angle > 150 || angle < -150)) {
  6522. if (buttonsRight || (buttonsLeft && isOpened)) { //存在右侧按钮或存在左侧按钮且是已打开状态
  6523. isMoved = true;
  6524. }
  6525. } else if (direction === 'right' && (angle > -30 && angle < 30)) {
  6526. if (buttonsLeft || (buttonsRight && isOpened)) { //存在左侧按钮或存在右侧按钮且是已打开状态
  6527. isMoved = true;
  6528. }
  6529. }
  6530. if (isMoved) {
  6531. event.stopPropagation();
  6532. event.detail.gesture.preventDefault();
  6533. var translate = event.detail.deltaX;
  6534. if (isOpened) {
  6535. if (openedActions === 'right') {
  6536. translate = translate - sliderActionRightWidth;
  6537. } else {
  6538. translate = translate + sliderActionLeftWidth;
  6539. }
  6540. }
  6541. if ((translate > 0 && !buttonsLeft) || (translate < 0 && !buttonsRight)) {
  6542. if (!isOpened) {
  6543. return;
  6544. }
  6545. translate = 0;
  6546. }
  6547. if (translate < 0) {
  6548. sliderDirection = 'toLeft';
  6549. } else if (translate > 0) {
  6550. sliderDirection = 'toRight';
  6551. } else {
  6552. if (!sliderDirection) {
  6553. sliderDirection = 'toLeft';
  6554. }
  6555. }
  6556. if (!sliderRequestAnimationFrame) {
  6557. updateTranslate();
  6558. }
  6559. translateX = translate;
  6560. }
  6561. },
  6562. flick: function(event) {
  6563. if (isMoved) {
  6564. event.stopPropagation();
  6565. }
  6566. },
  6567. swipeleft: function(event) {
  6568. if (isMoved) {
  6569. event.stopPropagation();
  6570. }
  6571. },
  6572. swiperight: function(event) {
  6573. if (isMoved) {
  6574. event.stopPropagation();
  6575. }
  6576. },
  6577. dragend: function(event) {
  6578. if (!isMoved) {
  6579. return;
  6580. }
  6581. event.stopPropagation();
  6582. if (sliderRequestAnimationFrame) {
  6583. cancelAnimationFrame(sliderRequestAnimationFrame);
  6584. sliderRequestAnimationFrame = null;
  6585. }
  6586. var detail = event.detail;
  6587. isMoved = false;
  6588. var action = 'close';
  6589. var actionsWidth = sliderDirection === 'toLeft' ? sliderActionRightWidth : sliderActionLeftWidth;
  6590. var isToggle = detail.swipe || (Math.abs(translateX) > actionsWidth / 2);
  6591. if (isToggle) {
  6592. if (!isOpened) {
  6593. action = 'open';
  6594. } else if (detail.direction === 'left' && openedActions === 'right') {
  6595. action = 'open';
  6596. } else if (detail.direction === 'right' && openedActions === 'left') {
  6597. action = 'open';
  6598. }
  6599. }
  6600. cell.classList.add(CLASS_TRANSITIONING);
  6601. var buttons;
  6602. if (action === 'open') {
  6603. var newTranslate = sliderDirection === 'toLeft' ? -actionsWidth : actionsWidth;
  6604. setTranslate(sliderHandle, newTranslate);
  6605. buttons = sliderDirection === 'toLeft' ? buttonsRight : buttonsLeft;
  6606. if (typeof buttons !== 'undefined') {
  6607. var button = null;
  6608. for (var i = 0; i < buttons.length; i++) {
  6609. button = buttons[i];
  6610. setTranslate(button, newTranslate);
  6611. }
  6612. button.parentNode.classList.add(CLASS_SELECTED);
  6613. cell.classList.add(CLASS_SELECTED);
  6614. if (!isOpened) {
  6615. $.trigger(cell, sliderDirection === 'toLeft' ? 'slideleft' : 'slideright');
  6616. }
  6617. }
  6618. } else {
  6619. setTranslate(sliderHandle, 0);
  6620. sliderActionLeft && sliderActionLeft.classList.remove(CLASS_SELECTED);
  6621. sliderActionRight && sliderActionRight.classList.remove(CLASS_SELECTED);
  6622. cell.classList.remove(CLASS_SELECTED);
  6623. }
  6624. var buttonOffset;
  6625. if (buttonsLeft && buttonsLeft.length > 0 && buttonsLeft !== buttons) {
  6626. for (var i = 0, len = buttonsLeft.length; i < len; i++) {
  6627. var buttonLeft = buttonsLeft[i];
  6628. buttonOffset = buttonLeft._buttonOffset;
  6629. if (typeof buttonOffset === 'undefined') {
  6630. buttonLeft._buttonOffset = sliderActionLeftWidth - buttonLeft.offsetLeft - buttonLeft.offsetWidth;
  6631. }
  6632. setTranslate(buttonLeft, buttonOffset);
  6633. }
  6634. }
  6635. if (buttonsRight && buttonsRight.length > 0 && buttonsRight !== buttons) {
  6636. for (var i = 0, len = buttonsRight.length; i < len; i++) {
  6637. var buttonRight = buttonsRight[i];
  6638. buttonOffset = buttonRight._buttonOffset;
  6639. if (typeof buttonOffset === 'undefined') {
  6640. buttonRight._buttonOffset = buttonRight.offsetLeft;
  6641. }
  6642. setTranslate(buttonRight, -buttonOffset);
  6643. }
  6644. }
  6645. }
  6646. };
  6647. function toggleEvents(element, isRemove) {
  6648. var method = !!isRemove ? 'removeEventListener' : 'addEventListener';
  6649. element[method]('drag', handleEvent);
  6650. element[method]('dragend', handleEvent);
  6651. element[method]('swiperight', handleEvent);
  6652. element[method]('swipeleft', handleEvent);
  6653. element[method]('flick', handleEvent);
  6654. };
  6655. /**
  6656. * 打开滑动菜单
  6657. * @param {Object} el
  6658. * @param {Object} direction
  6659. */
  6660. $.swipeoutOpen = function(el, direction) {
  6661. if (!el) return;
  6662. var classList = el.classList;
  6663. if (classList.contains(CLASS_SELECTED)) return;
  6664. if (!direction) {
  6665. if (el.querySelector(SELECTOR_SLIDER_RIGHT)) {
  6666. direction = 'right';
  6667. } else {
  6668. direction = 'left';
  6669. }
  6670. }
  6671. var swipeoutAction = el.querySelector($.classSelector(".slider-" + direction));
  6672. if (!swipeoutAction) return;
  6673. swipeoutAction.classList.add(CLASS_SELECTED);
  6674. classList.add(CLASS_SELECTED);
  6675. classList.remove(CLASS_TRANSITIONING);
  6676. var buttons = swipeoutAction.querySelectorAll(SELECTOR_BUTTON);
  6677. var swipeoutWidth = swipeoutAction.offsetWidth;
  6678. var translate = (direction === 'right') ? -swipeoutWidth : swipeoutWidth;
  6679. var length = buttons.length;
  6680. var button;
  6681. for (var i = 0; i < length; i++) {
  6682. button = buttons[i];
  6683. if (direction === 'right') {
  6684. setTranslate(button, -button.offsetLeft);
  6685. } else {
  6686. setTranslate(button, (swipeoutWidth - button.offsetWidth - button.offsetLeft));
  6687. }
  6688. }
  6689. classList.add(CLASS_TRANSITIONING);
  6690. for (var i = 0; i < length; i++) {
  6691. setTranslate(buttons[i], translate);
  6692. }
  6693. setTranslate(el.querySelector(SELECTOR_SLIDER_HANDLE), translate);
  6694. };
  6695. /**
  6696. * 关闭滑动菜单
  6697. * @param {Object} el
  6698. */
  6699. $.swipeoutClose = function(el) {
  6700. if (!el) return;
  6701. var classList = el.classList;
  6702. if (!classList.contains(CLASS_SELECTED)) return;
  6703. var direction = el.querySelector(SELECTOR_SLIDER_RIGHT + SELECTOR_SELECTED) ? 'right' : 'left';
  6704. var swipeoutAction = el.querySelector($.classSelector(".slider-" + direction));
  6705. if (!swipeoutAction) return;
  6706. swipeoutAction.classList.remove(CLASS_SELECTED);
  6707. classList.remove(CLASS_SELECTED);
  6708. classList.add(CLASS_TRANSITIONING);
  6709. var buttons = swipeoutAction.querySelectorAll(SELECTOR_BUTTON);
  6710. var swipeoutWidth = swipeoutAction.offsetWidth;
  6711. var length = buttons.length;
  6712. var button;
  6713. setTranslate(el.querySelector(SELECTOR_SLIDER_HANDLE), 0);
  6714. for (var i = 0; i < length; i++) {
  6715. button = buttons[i];
  6716. if (direction === 'right') {
  6717. setTranslate(button, (-button.offsetLeft));
  6718. } else {
  6719. setTranslate(button, (swipeoutWidth - button.offsetWidth - button.offsetLeft));
  6720. }
  6721. }
  6722. };
  6723. window.addEventListener($.EVENT_END, function(event) { //使用touchend来取消高亮,避免一次点击既不触发tap,doubletap,longtap的事件
  6724. if (!cell) {
  6725. return;
  6726. }
  6727. toggleActive(false);
  6728. sliderHandle && toggleEvents(cell, true);
  6729. });
  6730. window.addEventListener($.EVENT_CANCEL, function(event) { //使用touchcancel来取消高亮,避免一次点击既不触发tap,doubletap,longtap的事件
  6731. if (!cell) {
  6732. return;
  6733. }
  6734. toggleActive(false);
  6735. sliderHandle && toggleEvents(cell, true);
  6736. });
  6737. var radioOrCheckboxClick = function(event) {
  6738. var type = event.target && event.target.type || '';
  6739. if (type === 'radio' || type === 'checkbox') {
  6740. return;
  6741. }
  6742. var classList = cell.classList;
  6743. if (classList.contains('mui-radio')) {
  6744. var input = cell.querySelector('input[type=radio]');
  6745. if (input) {
  6746. // input.click();
  6747. if (!input.disabled && !input.readOnly) {
  6748. input.checked = !input.checked;
  6749. $.trigger(input, 'change');
  6750. }
  6751. }
  6752. } else if (classList.contains('mui-checkbox')) {
  6753. var input = cell.querySelector('input[type=checkbox]');
  6754. if (input) {
  6755. // input.click();
  6756. if (!input.disabled && !input.readOnly) {
  6757. input.checked = !input.checked;
  6758. $.trigger(input, 'change');
  6759. }
  6760. }
  6761. }
  6762. };
  6763. //fixed hashchange(android)
  6764. window.addEventListener($.EVENT_CLICK, function(e) {
  6765. if (cell && cell.classList.contains('mui-collapse')) {
  6766. e.preventDefault();
  6767. }
  6768. });
  6769. window.addEventListener('doubletap', function(event) {
  6770. if (cell) {
  6771. radioOrCheckboxClick(event);
  6772. }
  6773. });
  6774. var preventDefaultException = /^(INPUT|TEXTAREA|BUTTON|SELECT)$/;
  6775. window.addEventListener('tap', function(event) {
  6776. if (!cell) {
  6777. return;
  6778. }
  6779. var isExpand = false;
  6780. var classList = cell.classList;
  6781. var ul = cell.parentNode;
  6782. if (ul && ul.classList.contains(CLASS_RADIO_VIEW)) {
  6783. if (classList.contains(CLASS_SELECTED)) {
  6784. return;
  6785. }
  6786. var selected = ul.querySelector('li' + SELECTOR_SELECTED);
  6787. if (selected) {
  6788. selected.classList.remove(CLASS_SELECTED);
  6789. }
  6790. classList.add(CLASS_SELECTED);
  6791. $.trigger(cell, 'selected', {
  6792. el: cell
  6793. });
  6794. return;
  6795. }
  6796. if (classList.contains('mui-collapse') && !cell.parentNode.classList.contains('mui-unfold')) {
  6797. if (!preventDefaultException.test(event.target.tagName)) {
  6798. event.detail.gesture.preventDefault();
  6799. }
  6800. if (!classList.contains(CLASS_ACTIVE)) { //展开时,需要收缩其他同类
  6801. var collapse = cell.parentNode.querySelector('.mui-collapse.mui-active');
  6802. if (collapse) {
  6803. collapse.classList.remove(CLASS_ACTIVE);
  6804. }
  6805. isExpand = true;
  6806. }
  6807. classList.toggle(CLASS_ACTIVE);
  6808. if (isExpand) {
  6809. //触发展开事件
  6810. $.trigger(cell, 'expand');
  6811. //scroll
  6812. //暂不滚动
  6813. // var offsetTop = $.offset(cell).top;
  6814. // var scrollTop = document.body.scrollTop;
  6815. // var height = window.innerHeight;
  6816. // var offsetHeight = cell.offsetHeight;
  6817. // var cellHeight = (offsetTop - scrollTop + offsetHeight);
  6818. // if (offsetHeight > height) {
  6819. // $.scrollTo(offsetTop, 300);
  6820. // } else if (cellHeight > height) {
  6821. // $.scrollTo(cellHeight - height + scrollTop, 300);
  6822. // }
  6823. }
  6824. } else {
  6825. radioOrCheckboxClick(event);
  6826. }
  6827. });
  6828. })(mui, window, document);
  6829. (function($, window) {
  6830. /**
  6831. * 警告消息框
  6832. */
  6833. $.alert = function(message, title, btnValue, callback) {
  6834. if ($.os.plus) {
  6835. if (typeof message === 'undefined') {
  6836. return;
  6837. } else {
  6838. if (typeof title === 'function') {
  6839. callback = title;
  6840. title = null;
  6841. btnValue = '确定';
  6842. } else if (typeof btnValue === 'function') {
  6843. callback = btnValue;
  6844. btnValue = null;
  6845. }
  6846. $.plusReady(function() {
  6847. plus.nativeUI.alert(message, callback, title, btnValue);
  6848. });
  6849. }
  6850. } else {
  6851. //TODO H5版本
  6852. window.alert(message);
  6853. }
  6854. };
  6855. })(mui, window);
  6856. (function($, window) {
  6857. /**
  6858. * 确认消息框
  6859. */
  6860. $.confirm = function(message, title, btnArray, callback) {
  6861. if ($.os.plus) {
  6862. if (typeof message === 'undefined') {
  6863. return;
  6864. } else {
  6865. if (typeof title === 'function') {
  6866. callback = title;
  6867. title = null;
  6868. btnArray = null;
  6869. } else if (typeof btnArray === 'function') {
  6870. callback = btnArray;
  6871. btnArray = null;
  6872. }
  6873. $.plusReady(function() {
  6874. plus.nativeUI.confirm(message, callback, title, btnArray);
  6875. });
  6876. }
  6877. } else {
  6878. //H5版本,0为确认,1为取消
  6879. if (window.confirm(message)) {
  6880. callback({
  6881. index: 0
  6882. });
  6883. } else {
  6884. callback({
  6885. index: 1
  6886. });
  6887. }
  6888. }
  6889. };
  6890. })(mui, window);
  6891. (function($, window) {
  6892. /**
  6893. * 输入对话框
  6894. */
  6895. $.prompt = function(text, defaultText, title, btnArray, callback) {
  6896. if ($.os.plus) {
  6897. if (typeof message === 'undefined') {
  6898. return;
  6899. } else {
  6900. if (typeof defaultText === 'function') {
  6901. callback = defaultText;
  6902. defaultText = null;
  6903. title = null;
  6904. btnArray = null;
  6905. } else if (typeof title === 'function') {
  6906. callback = title;
  6907. title = null;
  6908. btnArray = null;
  6909. } else if (typeof btnArray === 'function') {
  6910. callback = btnArray;
  6911. btnArray = null;
  6912. }
  6913. $.plusReady(function() {
  6914. plus.nativeUI.prompt(text, callback, title, defaultText, btnArray);
  6915. });
  6916. }
  6917. } else {
  6918. //H5版本(确认index为0,取消index为1)
  6919. var result = window.prompt(text);
  6920. if (result) {
  6921. callback({
  6922. index: 0,
  6923. value: result
  6924. });
  6925. } else {
  6926. callback({
  6927. index: 1,
  6928. value: ''
  6929. });
  6930. }
  6931. }
  6932. };
  6933. })(mui, window);
  6934. (function($, window) {
  6935. var CLASS_ACTIVE = 'mui-active';
  6936. /**
  6937. * 自动消失提示框
  6938. */
  6939. $.toast = function(message,options) {
  6940. var durations = {
  6941. 'long': 3500,
  6942. 'short': 2000
  6943. };
  6944. //计算显示时间
  6945. options = $.extend({
  6946. duration: 'short'
  6947. }, options || {});
  6948. if ($.os.plus && options.type !== 'div') {
  6949. //默认显示在底部;
  6950. $.plusReady(function() {
  6951. plus.nativeUI.toast(message, {
  6952. verticalAlign: 'bottom',
  6953. duration:options.duration
  6954. });
  6955. });
  6956. } else {
  6957. if (typeof options.duration === 'number') {
  6958. duration = options.duration>0 ? options.duration:durations['short'];
  6959. } else {
  6960. duration = durations[options.duration];
  6961. }
  6962. if (!duration) {
  6963. duration = durations['short'];
  6964. }
  6965. var toast = document.createElement('div');
  6966. toast.classList.add('mui-toast-container');
  6967. toast.innerHTML = '<div class="' + 'mui-toast-message' + '">' + message + '</div>';
  6968. toast.addEventListener('webkitTransitionEnd', function() {
  6969. if (!toast.classList.contains(CLASS_ACTIVE)) {
  6970. toast.parentNode.removeChild(toast);
  6971. toast = null;
  6972. }
  6973. });
  6974. //点击则自动消失
  6975. toast.addEventListener('click', function() {
  6976. toast.parentNode.removeChild(toast);
  6977. toast = null;
  6978. });
  6979. document.body.appendChild(toast);
  6980. toast.offsetHeight;
  6981. toast.classList.add(CLASS_ACTIVE);
  6982. setTimeout(function() {
  6983. toast && toast.classList.remove(CLASS_ACTIVE);
  6984. }, duration);
  6985. return {
  6986. isVisible: function() {return !!toast;}
  6987. }
  6988. }
  6989. };
  6990. })(mui, window);
  6991. /**
  6992. * Popup(alert,confirm,prompt)
  6993. * @param {Object} $
  6994. * @param {Object} window
  6995. * @param {Object} document
  6996. */
  6997. (function($, window, document) {
  6998. var CLASS_POPUP = 'mui-popup';
  6999. var CLASS_POPUP_BACKDROP = 'mui-popup-backdrop';
  7000. var CLASS_POPUP_IN = 'mui-popup-in';
  7001. var CLASS_POPUP_OUT = 'mui-popup-out';
  7002. var CLASS_POPUP_INNER = 'mui-popup-inner';
  7003. var CLASS_POPUP_TITLE = 'mui-popup-title';
  7004. var CLASS_POPUP_TEXT = 'mui-popup-text';
  7005. var CLASS_POPUP_INPUT = 'mui-popup-input';
  7006. var CLASS_POPUP_BUTTONS = 'mui-popup-buttons';
  7007. var CLASS_POPUP_BUTTON = 'mui-popup-button';
  7008. var CLASS_POPUP_BUTTON_BOLD = 'mui-popup-button-bold';
  7009. var CLASS_POPUP_BACKDROP = 'mui-popup-backdrop';
  7010. var CLASS_ACTIVE = 'mui-active';
  7011. var popupStack = [];
  7012. var backdrop = (function() {
  7013. var element = document.createElement('div');
  7014. element.classList.add(CLASS_POPUP_BACKDROP);
  7015. element.addEventListener($.EVENT_MOVE, $.preventDefault);
  7016. element.addEventListener('webkitTransitionEnd', function() {
  7017. if (!this.classList.contains(CLASS_ACTIVE)) {
  7018. element.parentNode && element.parentNode.removeChild(element);
  7019. }
  7020. });
  7021. return element;
  7022. }());
  7023. var createInput = function(placeholder) {
  7024. return '<div class="' + CLASS_POPUP_INPUT + '"><input type="text" autofocus placeholder="' + (placeholder || '') + '"/></div>';
  7025. };
  7026. var createInner = function(message, title, extra) {
  7027. return '<div class="' + CLASS_POPUP_INNER + '"><div class="' + CLASS_POPUP_TITLE + '">' + title + '</div><div class="' + CLASS_POPUP_TEXT + '">' + message.replace(/\r\n/g, "<br/>").replace(/\n/g, "<br/>") + '</div>' + (extra || '') + '</div>';
  7028. };
  7029. var createButtons = function(btnArray) {
  7030. var length = btnArray.length;
  7031. var btns = [];
  7032. for (var i = 0; i < length; i++) {
  7033. btns.push('<span class="' + CLASS_POPUP_BUTTON + (i === length - 1 ? (' ' + CLASS_POPUP_BUTTON_BOLD) : '') + '">' + btnArray[i] + '</span>');
  7034. }
  7035. return '<div class="' + CLASS_POPUP_BUTTONS + '">' + btns.join('') + '</div>';
  7036. };
  7037. var createPopup = function(html, callback) {
  7038. var popupElement = document.createElement('div');
  7039. popupElement.className = CLASS_POPUP;
  7040. popupElement.innerHTML = html;
  7041. var removePopupElement = function() {
  7042. popupElement.parentNode && popupElement.parentNode.removeChild(popupElement);
  7043. popupElement = null;
  7044. };
  7045. popupElement.addEventListener($.EVENT_MOVE, $.preventDefault);
  7046. popupElement.addEventListener('webkitTransitionEnd', function(e) {
  7047. if (popupElement && e.target === popupElement && popupElement.classList.contains(CLASS_POPUP_OUT)) {
  7048. removePopupElement();
  7049. }
  7050. });
  7051. popupElement.style.display = 'block';
  7052. document.body.appendChild(popupElement);
  7053. popupElement.offsetHeight;
  7054. popupElement.classList.add(CLASS_POPUP_IN);
  7055. if (!backdrop.classList.contains(CLASS_ACTIVE)) {
  7056. backdrop.style.display = 'block';
  7057. document.body.appendChild(backdrop);
  7058. backdrop.offsetHeight;
  7059. backdrop.classList.add(CLASS_ACTIVE);
  7060. }
  7061. var btns = $.qsa('.' + CLASS_POPUP_BUTTON, popupElement);
  7062. var input = popupElement.querySelector('.' + CLASS_POPUP_INPUT + ' input');
  7063. var popup = {
  7064. element: popupElement,
  7065. close: function(index, animate) {
  7066. if (popupElement) {
  7067. var result = callback && callback({
  7068. index: index || 0,
  7069. value: input && input.value || ''
  7070. });
  7071. if (result === false) { //返回false则不关闭当前popup
  7072. return;
  7073. }
  7074. if (animate !== false) {
  7075. popupElement.classList.remove(CLASS_POPUP_IN);
  7076. popupElement.classList.add(CLASS_POPUP_OUT);
  7077. } else {
  7078. removePopupElement();
  7079. }
  7080. popupStack.pop();
  7081. //如果还有其他popup,则不remove backdrop
  7082. if (popupStack.length) {
  7083. popupStack[popupStack.length - 1]['show'](animate);
  7084. } else {
  7085. backdrop.classList.remove(CLASS_ACTIVE);
  7086. }
  7087. }
  7088. }
  7089. };
  7090. var handleEvent = function(e) {
  7091. popup.close(btns.indexOf(e.target));
  7092. };
  7093. $(popupElement).on('tap', '.' + CLASS_POPUP_BUTTON, handleEvent);
  7094. if (popupStack.length) {
  7095. popupStack[popupStack.length - 1]['hide']();
  7096. }
  7097. popupStack.push({
  7098. close: popup.close,
  7099. show: function(animate) {
  7100. popupElement.style.display = 'block';
  7101. popupElement.offsetHeight;
  7102. popupElement.classList.add(CLASS_POPUP_IN);
  7103. },
  7104. hide: function() {
  7105. popupElement.style.display = 'none';
  7106. popupElement.classList.remove(CLASS_POPUP_IN);
  7107. }
  7108. });
  7109. return popup;
  7110. };
  7111. var createAlert = function(message, title, btnValue, callback, type) {
  7112. if (typeof message === 'undefined') {
  7113. return;
  7114. } else {
  7115. if (typeof title === 'function') {
  7116. callback = title;
  7117. type = btnValue;
  7118. title = null;
  7119. btnValue = null;
  7120. } else if (typeof btnValue === 'function') {
  7121. type = callback;
  7122. callback = btnValue;
  7123. btnValue = null;
  7124. }
  7125. }
  7126. if (!$.os.plus || type === 'div') {
  7127. return createPopup(createInner(message, title || '提示') + createButtons([btnValue || '确定']), callback);
  7128. }
  7129. return plus.nativeUI.alert(message, callback, title || '提示', btnValue || '确定');
  7130. };
  7131. var createConfirm = function(message, title, btnArray, callback, type) {
  7132. if (typeof message === 'undefined') {
  7133. return;
  7134. } else {
  7135. if (typeof title === 'function') {
  7136. callback = title;
  7137. type = btnArray;
  7138. title = null;
  7139. btnArray = null;
  7140. } else if (typeof btnArray === 'function') {
  7141. type = callback;
  7142. callback = btnArray;
  7143. btnArray = null;
  7144. }
  7145. }
  7146. if (!$.os.plus || type === 'div') {
  7147. return createPopup(createInner(message, title || '提示') + createButtons(btnArray || ['取消', '确认']), callback);
  7148. }
  7149. return plus.nativeUI.confirm(message, callback, title, btnArray || ['取消', '确认']);
  7150. };
  7151. var createPrompt = function(message, placeholder, title, btnArray, callback, type) {
  7152. if (typeof message === 'undefined') {
  7153. return;
  7154. } else {
  7155. if (typeof placeholder === 'function') {
  7156. callback = placeholder;
  7157. type = title;
  7158. placeholder = null;
  7159. title = null;
  7160. btnArray = null;
  7161. } else if (typeof title === 'function') {
  7162. callback = title;
  7163. type = btnArray;
  7164. title = null;
  7165. btnArray = null;
  7166. } else if (typeof btnArray === 'function') {
  7167. type = callback;
  7168. callback = btnArray;
  7169. btnArray = null;
  7170. }
  7171. }
  7172. if (!$.os.plus || type === 'div') {
  7173. return createPopup(createInner(message, title || '提示', createInput(placeholder)) + createButtons(btnArray || ['取消', '确认']), callback);
  7174. }
  7175. return plus.nativeUI.prompt(message, callback, title || '提示', placeholder, btnArray || ['取消', '确认']);
  7176. };
  7177. var closePopup = function() {
  7178. if (popupStack.length) {
  7179. popupStack[popupStack.length - 1]['close']();
  7180. return true;
  7181. } else {
  7182. return false;
  7183. }
  7184. };
  7185. var closePopups = function() {
  7186. while (popupStack.length) {
  7187. popupStack[popupStack.length - 1]['close']();
  7188. }
  7189. };
  7190. $.closePopup = closePopup;
  7191. $.closePopups = closePopups;
  7192. $.alert = createAlert;
  7193. $.confirm = createConfirm;
  7194. $.prompt = createPrompt;
  7195. })(mui, window, document);
  7196. (function($, document) {
  7197. var CLASS_PROGRESSBAR = 'mui-progressbar';
  7198. var CLASS_PROGRESSBAR_IN = 'mui-progressbar-in';
  7199. var CLASS_PROGRESSBAR_OUT = 'mui-progressbar-out';
  7200. var CLASS_PROGRESSBAR_INFINITE = 'mui-progressbar-infinite';
  7201. var SELECTOR_PROGRESSBAR = '.mui-progressbar';
  7202. var _findProgressbar = function(container) {
  7203. container = $(container || 'body');
  7204. if (container.length === 0) return;
  7205. container = container[0];
  7206. if (container.classList.contains(CLASS_PROGRESSBAR)) {
  7207. return container;
  7208. }
  7209. var progressbars = container.querySelectorAll(SELECTOR_PROGRESSBAR);
  7210. if (progressbars) {
  7211. for (var i = 0, len = progressbars.length; i < len; i++) {
  7212. var progressbar = progressbars[i];
  7213. if (progressbar.parentNode === container) {
  7214. return progressbar;
  7215. }
  7216. }
  7217. }
  7218. };
  7219. /**
  7220. * 创建并显示进度条
  7221. * @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
  7222. * @param {Object} progress 可选,undefined表示循环,数字表示具体进度
  7223. * @param {Object} color 可选,指定颜色样式(目前暂未提供实际样式,可暂时不暴露此参数)
  7224. */
  7225. var showProgressbar = function(container, progress, color) {
  7226. if (typeof container === 'number') {
  7227. color = progress;
  7228. progress = container;
  7229. container = 'body';
  7230. }
  7231. container = $(container || 'body');
  7232. if (container.length === 0) return;
  7233. container = container[0];
  7234. var progressbar;
  7235. if (container.classList.contains(CLASS_PROGRESSBAR)) {
  7236. progressbar = container;
  7237. } else {
  7238. var progressbars = container.querySelectorAll(SELECTOR_PROGRESSBAR + ':not(.' + CLASS_PROGRESSBAR_OUT + ')');
  7239. if (progressbars) {
  7240. for (var i = 0, len = progressbars.length; i < len; i++) {
  7241. var _progressbar = progressbars[i];
  7242. if (_progressbar.parentNode === container) {
  7243. progressbar = _progressbar;
  7244. break;
  7245. }
  7246. }
  7247. }
  7248. if (!progressbar) {
  7249. progressbar = document.createElement('span');
  7250. progressbar.className = CLASS_PROGRESSBAR + ' ' + CLASS_PROGRESSBAR_IN + (typeof progress !== 'undefined' ? '' : (' ' + CLASS_PROGRESSBAR_INFINITE)) + (color ? (' ' + CLASS_PROGRESSBAR + '-' + color) : '');
  7251. if (typeof progress !== 'undefined') {
  7252. progressbar.innerHTML = '<span></span>';
  7253. }
  7254. container.appendChild(progressbar);
  7255. } else {
  7256. progressbar.classList.add(CLASS_PROGRESSBAR_IN);
  7257. }
  7258. }
  7259. if (progress) setProgressbar(container, progress);
  7260. return progressbar;
  7261. };
  7262. /**
  7263. * 关闭进度条
  7264. * @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
  7265. */
  7266. var hideProgressbar = function(container) {
  7267. var progressbar = _findProgressbar(container);
  7268. if (!progressbar) {
  7269. return;
  7270. }
  7271. var classList = progressbar.classList;
  7272. if (!classList.contains(CLASS_PROGRESSBAR_IN) || classList.contains(CLASS_PROGRESSBAR_OUT)) {
  7273. return;
  7274. }
  7275. classList.remove(CLASS_PROGRESSBAR_IN);
  7276. classList.add(CLASS_PROGRESSBAR_OUT);
  7277. progressbar.addEventListener('webkitAnimationEnd', function() {
  7278. progressbar.parentNode && progressbar.parentNode.removeChild(progressbar);
  7279. progressbar = null;
  7280. });
  7281. return;
  7282. };
  7283. /**
  7284. * 设置指定进度条进度
  7285. * @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
  7286. * @param {Object} progress 可选,默认0 取值范围[0-100]
  7287. * @param {Object} speed 进度条动画时间
  7288. */
  7289. var setProgressbar = function(container, progress, speed) {
  7290. if (typeof container === 'number') {
  7291. speed = progress;
  7292. progress = container;
  7293. container = false;
  7294. }
  7295. var progressbar = _findProgressbar(container);
  7296. if (!progressbar || progressbar.classList.contains(CLASS_PROGRESSBAR_INFINITE)) {
  7297. return;
  7298. }
  7299. if (progress) progress = Math.min(Math.max(progress, 0), 100);
  7300. progressbar.offsetHeight;
  7301. var span = progressbar.querySelector('span');
  7302. if (span) {
  7303. var style = span.style;
  7304. style.webkitTransform = 'translate3d(' + (-100 + progress) + '%,0,0)';
  7305. if (typeof speed !== 'undefined') {
  7306. style.webkitTransitionDuration = speed + 'ms';
  7307. } else {
  7308. style.webkitTransitionDuration = '';
  7309. }
  7310. }
  7311. return progressbar;
  7312. };
  7313. $.fn.progressbar = function(options) {
  7314. var progressbarApis = [];
  7315. options = options || {};
  7316. this.each(function() {
  7317. var self = this;
  7318. var progressbarApi = self.mui_plugin_progressbar;
  7319. if (!progressbarApi) {
  7320. self.mui_plugin_progressbar = progressbarApi = {
  7321. options: options,
  7322. setOptions: function(options) {
  7323. this.options = options;
  7324. },
  7325. show: function() {
  7326. return showProgressbar(self, this.options.progress, this.options.color);
  7327. },
  7328. setProgress: function(progress) {
  7329. return setProgressbar(self, progress);
  7330. },
  7331. hide: function() {
  7332. return hideProgressbar(self);
  7333. }
  7334. };
  7335. } else if (options) {
  7336. progressbarApi.setOptions(options);
  7337. }
  7338. progressbarApis.push(progressbarApi);
  7339. });
  7340. return progressbarApis.length === 1 ? progressbarApis[0] : progressbarApis;
  7341. };
  7342. // $.setProgressbar = setProgressbar;
  7343. // $.showProgressbar = showProgressbar;
  7344. // $.hideProgressbar = hideProgressbar;
  7345. })(mui, document);
  7346. /**
  7347. * Input(TODO resize)
  7348. * @param {type} $
  7349. * @param {type} window
  7350. * @param {type} document
  7351. * @returns {undefined}
  7352. */
  7353. (function($, window, document) {
  7354. var CLASS_ICON = 'mui-icon';
  7355. var CLASS_ICON_CLEAR = 'mui-icon-clear';
  7356. var CLASS_ICON_SPEECH = 'mui-icon-speech';
  7357. var CLASS_ICON_SEARCH = 'mui-icon-search';
  7358. var CLASS_ICON_PASSWORD = 'mui-icon-eye';
  7359. var CLASS_INPUT_ROW = 'mui-input-row';
  7360. var CLASS_PLACEHOLDER = 'mui-placeholder';
  7361. var CLASS_TOOLTIP = 'mui-tooltip';
  7362. var CLASS_HIDDEN = 'mui-hidden';
  7363. var CLASS_FOCUSIN = 'mui-focusin';
  7364. var SELECTOR_ICON_CLOSE = '.' + CLASS_ICON_CLEAR;
  7365. var SELECTOR_ICON_SPEECH = '.' + CLASS_ICON_SPEECH;
  7366. var SELECTOR_ICON_PASSWORD = '.' + CLASS_ICON_PASSWORD;
  7367. var SELECTOR_PLACEHOLDER = '.' + CLASS_PLACEHOLDER;
  7368. var SELECTOR_TOOLTIP = '.' + CLASS_TOOLTIP;
  7369. var findRow = function(target) {
  7370. for (; target && target !== document; target = target.parentNode) {
  7371. if (target.classList && target.classList.contains(CLASS_INPUT_ROW)) {
  7372. return target;
  7373. }
  7374. }
  7375. return null;
  7376. };
  7377. var Input = function(element, options) {
  7378. this.element = element;
  7379. this.options = options || {
  7380. actions: 'clear'
  7381. };
  7382. if (~this.options.actions.indexOf('slider')) { //slider
  7383. this.sliderActionClass = CLASS_TOOLTIP + ' ' + CLASS_HIDDEN;
  7384. this.sliderActionSelector = SELECTOR_TOOLTIP;
  7385. } else { //clear,speech,search
  7386. if (~this.options.actions.indexOf('clear')) {
  7387. this.clearActionClass = CLASS_ICON + ' ' + CLASS_ICON_CLEAR + ' ' + CLASS_HIDDEN;
  7388. this.clearActionSelector = SELECTOR_ICON_CLOSE;
  7389. }
  7390. if (~this.options.actions.indexOf('speech')) { //only for 5+
  7391. this.speechActionClass = CLASS_ICON + ' ' + CLASS_ICON_SPEECH;
  7392. this.speechActionSelector = SELECTOR_ICON_SPEECH;
  7393. }
  7394. if (~this.options.actions.indexOf('search')) {
  7395. this.searchActionClass = CLASS_PLACEHOLDER;
  7396. this.searchActionSelector = SELECTOR_PLACEHOLDER;
  7397. }
  7398. if (~this.options.actions.indexOf('password')) {
  7399. this.passwordActionClass = CLASS_ICON + ' ' + CLASS_ICON_PASSWORD;
  7400. this.passwordActionSelector = SELECTOR_ICON_PASSWORD;
  7401. }
  7402. }
  7403. this.init();
  7404. };
  7405. Input.prototype.init = function() {
  7406. this.initAction();
  7407. this.initElementEvent();
  7408. };
  7409. Input.prototype.initAction = function() {
  7410. var self = this;
  7411. var row = self.element.parentNode;
  7412. if (row) {
  7413. if (self.sliderActionClass) {
  7414. self.sliderAction = self.createAction(row, self.sliderActionClass, self.sliderActionSelector);
  7415. } else {
  7416. if (self.searchActionClass) {
  7417. self.searchAction = self.createAction(row, self.searchActionClass, self.searchActionSelector);
  7418. self.searchAction.addEventListener('tap', function(e) {
  7419. $.focus(self.element);
  7420. e.stopPropagation();
  7421. });
  7422. }
  7423. if (self.speechActionClass) {
  7424. self.speechAction = self.createAction(row, self.speechActionClass, self.speechActionSelector);
  7425. self.speechAction.addEventListener('click', $.stopPropagation);
  7426. self.speechAction.addEventListener('tap', function(event) {
  7427. self.speechActionClick(event);
  7428. });
  7429. }
  7430. if (self.clearActionClass) {
  7431. self.clearAction = self.createAction(row, self.clearActionClass, self.clearActionSelector);
  7432. self.clearAction.addEventListener('tap', function(event) {
  7433. self.clearActionClick(event);
  7434. });
  7435. }
  7436. if (self.passwordActionClass) {
  7437. self.passwordAction = self.createAction(row, self.passwordActionClass, self.passwordActionSelector);
  7438. self.passwordAction.addEventListener('tap', function(event) {
  7439. self.passwordActionClick(event);
  7440. });
  7441. }
  7442. }
  7443. }
  7444. };
  7445. Input.prototype.createAction = function(row, actionClass, actionSelector) {
  7446. var action = row.querySelector(actionSelector);
  7447. if (!action) {
  7448. var action = document.createElement('span');
  7449. action.className = actionClass;
  7450. if (actionClass === this.searchActionClass) {
  7451. action.innerHTML = '<span class="' + CLASS_ICON + ' ' + CLASS_ICON_SEARCH + '"></span><span>' + this.element.getAttribute('placeholder') + '</span>';
  7452. this.element.setAttribute('placeholder', '');
  7453. if (this.element.value.trim()) {
  7454. row.classList.add('mui-active');
  7455. }
  7456. }
  7457. row.insertBefore(action, this.element.nextSibling);
  7458. }
  7459. return action;
  7460. };
  7461. Input.prototype.initElementEvent = function() {
  7462. var element = this.element;
  7463. if (this.sliderActionClass) {
  7464. var tooltip = this.sliderAction;
  7465. var timer = null;
  7466. var showTip = function() { //每次重新计算是因为控件可能被隐藏,初始化时计算是不正确的
  7467. tooltip.classList.remove(CLASS_HIDDEN);
  7468. var offsetLeft = element.offsetLeft;
  7469. var width = element.offsetWidth - 28;
  7470. var tooltipWidth = tooltip.offsetWidth;
  7471. var distince = Math.abs(element.max - element.min);
  7472. var scaleWidth = (width / distince) * Math.abs(element.value - element.min);
  7473. tooltip.style.left = (14 + offsetLeft + scaleWidth - tooltipWidth / 2) + 'px';
  7474. tooltip.innerText = element.value;
  7475. if (timer) {
  7476. clearTimeout(timer);
  7477. }
  7478. timer = setTimeout(function() {
  7479. tooltip.classList.add(CLASS_HIDDEN);
  7480. }, 1000);
  7481. };
  7482. element.addEventListener('input', showTip);
  7483. element.addEventListener('tap', showTip);
  7484. element.addEventListener($.EVENT_MOVE, function(e) {
  7485. e.stopPropagation();
  7486. });
  7487. } else {
  7488. if (this.clearActionClass) {
  7489. var action = this.clearAction;
  7490. if (!action) {
  7491. return;
  7492. }
  7493. $.each(['keyup', 'change', 'input', 'focus', 'cut', 'paste'], function(index, type) {
  7494. (function(type) {
  7495. element.addEventListener(type, function() {
  7496. action.classList[element.value.trim() ? 'remove' : 'add'](CLASS_HIDDEN);
  7497. });
  7498. })(type);
  7499. });
  7500. element.addEventListener('blur', function() {
  7501. action.classList.add(CLASS_HIDDEN);
  7502. });
  7503. }
  7504. if (this.searchActionClass) {
  7505. element.addEventListener('focus', function() {
  7506. element.parentNode.classList.add('mui-active');
  7507. });
  7508. element.addEventListener('blur', function() {
  7509. if (!element.value.trim()) {
  7510. element.parentNode.classList.remove('mui-active');
  7511. }
  7512. });
  7513. }
  7514. }
  7515. };
  7516. Input.prototype.setPlaceholder = function(text) {
  7517. if (this.searchActionClass) {
  7518. var placeholder = this.element.parentNode.querySelector(SELECTOR_PLACEHOLDER);
  7519. placeholder && (placeholder.getElementsByTagName('span')[1].innerText = text);
  7520. } else {
  7521. this.element.setAttribute('placeholder', text);
  7522. }
  7523. };
  7524. Input.prototype.passwordActionClick = function(event) {
  7525. if (this.element.type === 'text') {
  7526. this.element.type = 'password';
  7527. } else {
  7528. this.element.type = 'text';
  7529. }
  7530. this.passwordAction.classList.toggle('mui-active');
  7531. event.preventDefault();
  7532. };
  7533. Input.prototype.clearActionClick = function(event) {
  7534. var self = this;
  7535. self.element.value = '';
  7536. $.focus(self.element);
  7537. self.clearAction.classList.add(CLASS_HIDDEN);
  7538. event.preventDefault();
  7539. };
  7540. Input.prototype.speechActionClick = function(event) {
  7541. if (window.plus) {
  7542. var self = this;
  7543. var oldValue = self.element.value;
  7544. self.element.value = '';
  7545. document.body.classList.add(CLASS_FOCUSIN);
  7546. plus.speech.startRecognize({
  7547. engine: 'iFly'
  7548. }, function(s) {
  7549. self.element.value += s;
  7550. $.focus(self.element);
  7551. plus.speech.stopRecognize();
  7552. $.trigger(self.element, 'recognized', {
  7553. value: self.element.value
  7554. });
  7555. if (oldValue !== self.element.value) {
  7556. $.trigger(self.element, 'change');
  7557. $.trigger(self.element, 'input');
  7558. }
  7559. // document.body.classList.remove(CLASS_FOCUSIN);
  7560. }, function(e) {
  7561. document.body.classList.remove(CLASS_FOCUSIN);
  7562. });
  7563. } else {
  7564. alert('only for 5+');
  7565. }
  7566. event.preventDefault();
  7567. };
  7568. $.fn.input = function(options) {
  7569. var inputApis = [];
  7570. this.each(function() {
  7571. var inputApi = null;
  7572. var actions = [];
  7573. var row = findRow(this.parentNode);
  7574. if (this.type === 'range' && row.classList.contains('mui-input-range')) {
  7575. actions.push('slider');
  7576. } else {
  7577. var classList = this.classList;
  7578. if (classList.contains('mui-input-clear')) {
  7579. actions.push('clear');
  7580. }
  7581. if (!($.os.android && $.os.stream) && classList.contains('mui-input-speech')) {
  7582. actions.push('speech');
  7583. }
  7584. if (classList.contains('mui-input-password')) {
  7585. actions.push('password');
  7586. }
  7587. if (this.type === 'search' && row.classList.contains('mui-search')) {
  7588. actions.push('search');
  7589. }
  7590. }
  7591. var id = this.getAttribute('data-input-' + actions[0]);
  7592. if (!id) {
  7593. id = ++$.uuid;
  7594. inputApi = $.data[id] = new Input(this, {
  7595. actions: actions.join(',')
  7596. });
  7597. for (var i = 0, len = actions.length; i < len; i++) {
  7598. this.setAttribute('data-input-' + actions[i], id);
  7599. }
  7600. } else {
  7601. inputApi = $.data[id];
  7602. }
  7603. inputApis.push(inputApi);
  7604. });
  7605. return inputApis.length === 1 ? inputApis[0] : inputApis;
  7606. };
  7607. $.ready(function() {
  7608. $('.mui-input-row input').input();
  7609. });
  7610. })(mui, window, document);
  7611. (function($, window) {
  7612. var CLASS_ACTIVE = 'mui-active';
  7613. var rgbaRegex = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/;
  7614. var getColor = function(colorStr) {
  7615. var matches = colorStr.match(rgbaRegex);
  7616. if (matches && matches.length === 5) {
  7617. return [
  7618. matches[1],
  7619. matches[2],
  7620. matches[3],
  7621. matches[4]
  7622. ];
  7623. }
  7624. return [];
  7625. };
  7626. var Transparent = function(element, options) {
  7627. this.element = element;
  7628. this.options = $.extend({
  7629. top: 0, //距离顶部高度(到达该高度即触发)
  7630. offset: 150, //滚动透明距离
  7631. duration: 16, //过渡时间
  7632. scrollby: window//监听滚动距离容器
  7633. }, options || {});
  7634. this.scrollByElem = this.options.scrollby || window;
  7635. if (!this.scrollByElem) {
  7636. throw new Error("监听滚动的元素不存在");
  7637. }
  7638. this.isNativeScroll = false;
  7639. if (this.scrollByElem === window) {
  7640. this.isNativeScroll = true;
  7641. } else if (!~this.scrollByElem.className.indexOf('mui-scroll-wrapper')) {
  7642. this.isNativeScroll = true;
  7643. }
  7644. this._style = this.element.style;
  7645. this._bgColor = this._style.backgroundColor;
  7646. var color = getColor(mui.getStyles(this.element, 'backgroundColor'));
  7647. if (color.length) {
  7648. this._R = color[0];
  7649. this._G = color[1];
  7650. this._B = color[2];
  7651. this._A = parseFloat(color[3]);
  7652. this.lastOpacity = this._A;
  7653. this._bufferFn = $.buffer(this.handleScroll, this.options.duration, this);
  7654. this.initEvent();
  7655. } else {
  7656. throw new Error("元素背景颜色必须为RGBA");
  7657. }
  7658. };
  7659. Transparent.prototype.initEvent = function() {
  7660. this.scrollByElem.addEventListener('scroll', this._bufferFn);
  7661. if (this.isNativeScroll) { //原生scroll
  7662. this.scrollByElem.addEventListener($.EVENT_MOVE, this._bufferFn);
  7663. }
  7664. }
  7665. Transparent.prototype.handleScroll = function(e) {
  7666. var y = window.scrollY;
  7667. if (!this.isNativeScroll && e && e.detail) {
  7668. y = -e.detail.y;
  7669. }
  7670. var opacity = (y - this.options.top) / this.options.offset + this._A;
  7671. opacity = Math.min(Math.max(this._A, opacity), 1);
  7672. this._style.backgroundColor = 'rgba(' + this._R + ',' + this._G + ',' + this._B + ',' + opacity + ')';
  7673. if (opacity > this._A) {
  7674. this.element.classList.add(CLASS_ACTIVE);
  7675. } else {
  7676. this.element.classList.remove(CLASS_ACTIVE);
  7677. }
  7678. if (this.lastOpacity !== opacity) {
  7679. $.trigger(this.element, 'alpha', {
  7680. alpha: opacity
  7681. });
  7682. this.lastOpacity = opacity;
  7683. }
  7684. };
  7685. Transparent.prototype.destory = function() {
  7686. this.scrollByElem.removeEventListener('scroll', this._bufferFn);
  7687. this.scrollByElem.removeEventListener($.EVENT_MOVE, this._bufferFn);
  7688. this.element.style.backgroundColor = this._bgColor;
  7689. this.element.mui_plugin_transparent = null;
  7690. };
  7691. $.fn.transparent = function(options) {
  7692. options = options || {};
  7693. var transparentApis = [];
  7694. this.each(function() {
  7695. var transparentApi = this.mui_plugin_transparent;
  7696. if (!transparentApi) {
  7697. var top = this.getAttribute('data-top');
  7698. var offset = this.getAttribute('data-offset');
  7699. var duration = this.getAttribute('data-duration');
  7700. var scrollby = this.getAttribute('data-scrollby');
  7701. if (top !== null && typeof options.top === 'undefined') {
  7702. options.top = top;
  7703. }
  7704. if (offset !== null && typeof options.offset === 'undefined') {
  7705. options.offset = offset;
  7706. }
  7707. if (duration !== null && typeof options.duration === 'undefined') {
  7708. options.duration = duration;
  7709. }
  7710. if (scrollby !== null && typeof options.scrollby === 'undefined') {
  7711. options.scrollby = document.querySelector(scrollby) || window;
  7712. }
  7713. transparentApi = this.mui_plugin_transparent = new Transparent(this, options);
  7714. }
  7715. transparentApis.push(transparentApi);
  7716. });
  7717. return transparentApis.length === 1 ? transparentApis[0] : transparentApis;
  7718. };
  7719. $.ready(function() {
  7720. $('.mui-bar-transparent').transparent();
  7721. });
  7722. })(mui, window);
  7723. /**
  7724. * 数字输入框
  7725. * varstion 1.0.1
  7726. * by Houfeng
  7727. * Houfeng@DCloud.io
  7728. */
  7729. (function($) {
  7730. var touchSupport = ('ontouchstart' in document);
  7731. var tapEventName = touchSupport ? 'tap' : 'click';
  7732. var changeEventName = 'change';
  7733. var holderClassName = 'mui-numbox';
  7734. var plusClassSelector = '.mui-btn-numbox-plus,.mui-numbox-btn-plus';
  7735. var minusClassSelector = '.mui-btn-numbox-minus,.mui-numbox-btn-minus';
  7736. var inputClassSelector = '.mui-input-numbox,.mui-numbox-input';
  7737. var Numbox = $.Numbox = $.Class.extend({
  7738. /**
  7739. * 构造函数
  7740. **/
  7741. init: function(holder, options) {
  7742. var self = this;
  7743. if (!holder) {
  7744. throw "构造 numbox 时缺少容器元素";
  7745. }
  7746. self.holder = holder;
  7747. options = options || {};
  7748. options.step = parseInt(options.step || 1);
  7749. self.options = options;
  7750. self.input = $.qsa(inputClassSelector, self.holder)[0];
  7751. self.plus = $.qsa(plusClassSelector, self.holder)[0];
  7752. self.minus = $.qsa(minusClassSelector, self.holder)[0];
  7753. self.checkValue();
  7754. self.initEvent();
  7755. },
  7756. /**
  7757. * 初始化事件绑定
  7758. **/
  7759. initEvent: function() {
  7760. var self = this;
  7761. self.plus.addEventListener(tapEventName, function(event) {
  7762. var val = parseInt(self.input.value) + self.options.step;
  7763. self.input.value = val.toString();
  7764. $.trigger(self.input, changeEventName, null);
  7765. });
  7766. self.minus.addEventListener(tapEventName, function(event) {
  7767. var val = parseInt(self.input.value) - self.options.step;
  7768. self.input.value = val.toString();
  7769. $.trigger(self.input, changeEventName, null);
  7770. });
  7771. self.input.addEventListener(changeEventName, function(event) {
  7772. self.checkValue();
  7773. var val = parseInt(self.input.value);
  7774. //触发顶层容器
  7775. $.trigger(self.holder, changeEventName, {
  7776. value: val
  7777. });
  7778. });
  7779. },
  7780. /**
  7781. * 获取当前值
  7782. **/
  7783. getValue: function() {
  7784. var self = this;
  7785. return parseInt(self.input.value);
  7786. },
  7787. /**
  7788. * 验证当前值是法合法
  7789. **/
  7790. checkValue: function() {
  7791. var self = this;
  7792. var val = self.input.value;
  7793. if (val == null || val == '' || isNaN(val)) {
  7794. self.input.value = self.options.min || 0;
  7795. self.minus.disabled = self.options.min != null;
  7796. } else {
  7797. var val = parseInt(val);
  7798. if (self.options.max != null && !isNaN(self.options.max) && val >= parseInt(self.options.max)) {
  7799. val = self.options.max;
  7800. self.plus.disabled = true;
  7801. } else {
  7802. self.plus.disabled = false;
  7803. }
  7804. if (self.options.min != null && !isNaN(self.options.min) && val <= parseInt(self.options.min)) {
  7805. val = self.options.min;
  7806. self.minus.disabled = true;
  7807. } else {
  7808. self.minus.disabled = false;
  7809. }
  7810. self.input.value = val;
  7811. }
  7812. },
  7813. /**
  7814. * 更新选项
  7815. **/
  7816. setOption: function(name, value) {
  7817. var self = this;
  7818. self.options[name] = value;
  7819. },
  7820. /**
  7821. * 动态设置新值
  7822. **/
  7823. setValue: function(value) {
  7824. this.input.value = value;
  7825. this.checkValue();
  7826. }
  7827. });
  7828. $.fn.numbox = function(options) {
  7829. var instanceArray = [];
  7830. //遍历选择的元素
  7831. this.each(function(i, element) {
  7832. if (element.numbox) {
  7833. return;
  7834. }
  7835. if (options) {
  7836. element.numbox = new Numbox(element, options);
  7837. } else {
  7838. var optionsText = element.getAttribute('data-numbox-options');
  7839. var options = optionsText ? JSON.parse(optionsText) : {};
  7840. options.step = element.getAttribute('data-numbox-step') || options.step;
  7841. options.min = element.getAttribute('data-numbox-min') || options.min;
  7842. options.max = element.getAttribute('data-numbox-max') || options.max;
  7843. element.numbox = new Numbox(element, options);
  7844. }
  7845. });
  7846. return this[0] ? this[0].numbox : null;
  7847. }
  7848. //自动处理 class='mui-locker' 的 dom
  7849. $.ready(function() {
  7850. $('.' + holderClassName).numbox();
  7851. });
  7852. }(mui));
  7853. /**
  7854. * Button
  7855. * @param {type} $
  7856. * @param {type} window
  7857. * @param {type} document
  7858. * @returns {undefined}
  7859. */
  7860. (function($, window, document) {
  7861. var CLASS_ICON = 'mui-icon';
  7862. var CLASS_DISABLED = 'mui-disabled';
  7863. var STATE_RESET = 'reset';
  7864. var STATE_LOADING = 'loading';
  7865. var defaultOptions = {
  7866. loadingText: 'Loading...', //文案
  7867. loadingIcon: 'mui-spinner' + ' ' + 'mui-spinner-white', //图标,可为空
  7868. loadingIconPosition: 'left' //图标所处位置,仅支持left|right
  7869. };
  7870. var Button = function(element, options) {
  7871. this.element = element;
  7872. this.options = $.extend({}, defaultOptions, options);
  7873. if (!this.options.loadingText) {
  7874. this.options.loadingText = defaultOptions.loadingText;
  7875. }
  7876. if (this.options.loadingIcon === null) {
  7877. this.options.loadingIcon = 'mui-spinner';
  7878. if ($.getStyles(this.element, 'color') === 'rgb(255, 255, 255)') {
  7879. this.options.loadingIcon += ' ' + 'mui-spinner-white';
  7880. }
  7881. }
  7882. this.isInput = this.element.tagName === 'INPUT';
  7883. this.resetHTML = this.isInput ? this.element.value : this.element.innerHTML;
  7884. this.state = '';
  7885. };
  7886. Button.prototype.loading = function() {
  7887. this.setState(STATE_LOADING);
  7888. };
  7889. Button.prototype.reset = function() {
  7890. this.setState(STATE_RESET);
  7891. };
  7892. Button.prototype.setState = function(state) {
  7893. if (this.state === state) {
  7894. return false;
  7895. }
  7896. this.state = state;
  7897. if (state === STATE_RESET) {
  7898. this.element.disabled = false;
  7899. this.element.classList.remove(CLASS_DISABLED);
  7900. this.setHtml(this.resetHTML);
  7901. } else if (state === STATE_LOADING) {
  7902. this.element.disabled = true;
  7903. this.element.classList.add(CLASS_DISABLED);
  7904. var html = this.isInput ? this.options.loadingText : ('<span>' + this.options.loadingText + '</span>');
  7905. if (this.options.loadingIcon && !this.isInput) {
  7906. if (this.options.loadingIconPosition === 'right') {
  7907. html += '&nbsp;<span class="' + this.options.loadingIcon + '"></span>';
  7908. } else {
  7909. html = '<span class="' + this.options.loadingIcon + '"></span>&nbsp;' + html;
  7910. }
  7911. }
  7912. this.setHtml(html);
  7913. }
  7914. };
  7915. Button.prototype.setHtml = function(html) {
  7916. if (this.isInput) {
  7917. this.element.value = html;
  7918. } else {
  7919. this.element.innerHTML = html;
  7920. }
  7921. }
  7922. $.fn.button = function(state) {
  7923. var buttonApis = [];
  7924. this.each(function() {
  7925. var buttonApi = this.mui_plugin_button;
  7926. if (!buttonApi) {
  7927. var loadingText = this.getAttribute('data-loading-text');
  7928. var loadingIcon = this.getAttribute('data-loading-icon');
  7929. var loadingIconPosition = this.getAttribute('data-loading-icon-position');
  7930. this.mui_plugin_button = buttonApi = new Button(this, {
  7931. loadingText: loadingText,
  7932. loadingIcon: loadingIcon,
  7933. loadingIconPosition: loadingIconPosition
  7934. });
  7935. }
  7936. if (state === STATE_LOADING || state === STATE_RESET) {
  7937. buttonApi.setState(state);
  7938. }
  7939. buttonApis.push(buttonApi);
  7940. });
  7941. return buttonApis.length === 1 ? buttonApis[0] : buttonApis;
  7942. };
  7943. })(mui, window, document);