mui.js 247 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243
  1. /*!
  2. * =====================================================
  3. * Mui v3.6.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();
  224. } else {
  225. if (timer) {
  226. timer.cancel();
  227. }
  228. timer = $.later(run, ms, null, 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)) {
  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("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 && $.os.android) { //android 5+
  2821. $.plusReady(function() {
  2822. var webview = plus.webview.currentWebview();
  2823. if (hasPullup) {
  2824. //当前页面初始化pullup
  2825. var upOptions = {};
  2826. upOptions.up = pullRefreshOptions.up;
  2827. upOptions.webviewId = webview.id || webview.getURL();
  2828. $container.pullRefresh(upOptions);
  2829. }
  2830. if (hasPulldown) {
  2831. var parent = webview.parent();
  2832. var id = webview.id || webview.getURL();
  2833. if (parent) {
  2834. if (!hasPullup) { //如果没有上拉加载,需要手动初始化一个默认的pullRefresh,以便当前页面容器可以调用endPulldownToRefresh等方法
  2835. $container.pullRefresh({
  2836. webviewId: id
  2837. });
  2838. }
  2839. var downOptions = {
  2840. webviewId: id
  2841. };
  2842. downOptions.down = $.extend({}, pullRefreshOptions.down);
  2843. downOptions.down.callback = '_CALLBACK';
  2844. //父页面初始化pulldown
  2845. parent.evalJS("mui&&mui(document.querySelector('.mui-content')).pullRefresh('" + JSON.stringify(downOptions) + "')");
  2846. }
  2847. }
  2848. });
  2849. } else {
  2850. $container.pullRefresh(pullRefreshOptions);
  2851. }
  2852. }
  2853. }
  2854. }
  2855. }
  2856. });
  2857. })(mui);
  2858. /**
  2859. * mui ajax
  2860. * @param {type} $
  2861. * @returns {undefined}
  2862. */
  2863. (function($, window, undefined) {
  2864. var jsonType = 'application/json';
  2865. var htmlType = 'text/html';
  2866. var rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;
  2867. var scriptTypeRE = /^(?:text|application)\/javascript/i;
  2868. var xmlTypeRE = /^(?:text|application)\/xml/i;
  2869. var blankRE = /^\s*$/;
  2870. $.ajaxSettings = {
  2871. type: 'GET',
  2872. beforeSend: $.noop,
  2873. success: $.noop,
  2874. error: $.noop,
  2875. complete: $.noop,
  2876. context: null,
  2877. xhr: function(protocol) {
  2878. return new window.XMLHttpRequest();
  2879. },
  2880. accepts: {
  2881. script: 'text/javascript, application/javascript, application/x-javascript',
  2882. json: jsonType,
  2883. xml: 'application/xml, text/xml',
  2884. html: htmlType,
  2885. text: 'text/plain'
  2886. },
  2887. timeout: 0,
  2888. processData: true,
  2889. cache: true
  2890. };
  2891. var ajaxBeforeSend = function(xhr, settings) {
  2892. var context = settings.context
  2893. if(settings.beforeSend.call(context, xhr, settings) === false) {
  2894. return false;
  2895. }
  2896. };
  2897. var ajaxSuccess = function(data, xhr, settings) {
  2898. settings.success.call(settings.context, data, 'success', xhr);
  2899. ajaxComplete('success', xhr, settings);
  2900. };
  2901. // type: "timeout", "error", "abort", "parsererror"
  2902. var ajaxError = function(error, type, xhr, settings) {
  2903. settings.error.call(settings.context, xhr, type, error);
  2904. ajaxComplete(type, xhr, settings);
  2905. };
  2906. // status: "success", "notmodified", "error", "timeout", "abort", "parsererror"
  2907. var ajaxComplete = function(status, xhr, settings) {
  2908. settings.complete.call(settings.context, xhr, status);
  2909. };
  2910. var serialize = function(params, obj, traditional, scope) {
  2911. var type, array = $.isArray(obj),
  2912. hash = $.isPlainObject(obj);
  2913. $.each(obj, function(key, value) {
  2914. type = $.type(value);
  2915. if(scope) {
  2916. key = traditional ? scope :
  2917. scope + '[' + (hash || type === 'object' || type === 'array' ? key : '') + ']';
  2918. }
  2919. // handle data in serializeArray() format
  2920. if(!scope && array) {
  2921. params.add(value.name, value.value);
  2922. }
  2923. // recurse into nested objects
  2924. else if(type === "array" || (!traditional && type === "object")) {
  2925. serialize(params, value, traditional, key);
  2926. } else {
  2927. params.add(key, value);
  2928. }
  2929. });
  2930. };
  2931. var serializeData = function(options) {
  2932. if(options.processData && options.data && typeof options.data !== "string") {
  2933. var contentType = options.contentType;
  2934. if(!contentType && options.headers) {
  2935. contentType = options.headers['Content-Type'];
  2936. }
  2937. if(contentType && ~contentType.indexOf(jsonType)) { //application/json
  2938. options.data = JSON.stringify(options.data);
  2939. } else {
  2940. options.data = $.param(options.data, options.traditional);
  2941. }
  2942. }
  2943. if(options.data && (!options.type || options.type.toUpperCase() === 'GET')) {
  2944. options.url = appendQuery(options.url, options.data);
  2945. options.data = undefined;
  2946. }
  2947. };
  2948. var appendQuery = function(url, query) {
  2949. if(query === '') {
  2950. return url;
  2951. }
  2952. return(url + '&' + query).replace(/[&?]{1,2}/, '?');
  2953. };
  2954. var mimeToDataType = function(mime) {
  2955. if(mime) {
  2956. mime = mime.split(';', 2)[0];
  2957. }
  2958. return mime && (mime === htmlType ? 'html' :
  2959. mime === jsonType ? 'json' :
  2960. scriptTypeRE.test(mime) ? 'script' :
  2961. xmlTypeRE.test(mime) && 'xml') || 'text';
  2962. };
  2963. var parseArguments = function(url, data, success, dataType) {
  2964. if($.isFunction(data)) {
  2965. dataType = success, success = data, data = undefined;
  2966. }
  2967. if(!$.isFunction(success)) {
  2968. dataType = success, success = undefined;
  2969. }
  2970. return {
  2971. url: url,
  2972. data: data,
  2973. success: success,
  2974. dataType: dataType
  2975. };
  2976. };
  2977. $.ajax = function(url, options) {
  2978. if(typeof url === "object") {
  2979. options = url;
  2980. url = undefined;
  2981. }
  2982. var settings = options || {};
  2983. settings.url = url || settings.url;
  2984. for(var key in $.ajaxSettings) {
  2985. if(settings[key] === undefined) {
  2986. settings[key] = $.ajaxSettings[key];
  2987. }
  2988. }
  2989. serializeData(settings);
  2990. var dataType = settings.dataType;
  2991. if(settings.cache === false || ((!options || options.cache !== true) && ('script' === dataType))) {
  2992. settings.url = appendQuery(settings.url, '_=' + $.now());
  2993. }
  2994. var mime = settings.accepts[dataType && dataType.toLowerCase()];
  2995. var headers = {};
  2996. var setHeader = function(name, value) {
  2997. headers[name.toLowerCase()] = [name, value];
  2998. };
  2999. var protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol;
  3000. var xhr = settings.xhr(settings);
  3001. var nativeSetHeader = xhr.setRequestHeader;
  3002. var abortTimeout;
  3003. setHeader('X-Requested-With', 'XMLHttpRequest');
  3004. setHeader('Accept', mime || '*/*');
  3005. if(!!(mime = settings.mimeType || mime)) {
  3006. if(mime.indexOf(',') > -1) {
  3007. mime = mime.split(',', 2)[0];
  3008. }
  3009. xhr.overrideMimeType && xhr.overrideMimeType(mime);
  3010. }
  3011. if(settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() !== 'GET')) {
  3012. setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded');
  3013. }
  3014. if(settings.headers) {
  3015. for(var name in settings.headers)
  3016. setHeader(name, settings.headers[name]);
  3017. }
  3018. xhr.setRequestHeader = setHeader;
  3019. xhr.onreadystatechange = function() {
  3020. if(xhr.readyState === 4) {
  3021. xhr.onreadystatechange = $.noop;
  3022. clearTimeout(abortTimeout);
  3023. var result, error = false;
  3024. var isLocal = protocol === 'file:';
  3025. if((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || (xhr.status === 0 && isLocal && xhr.responseText)) {
  3026. dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type'));
  3027. result = xhr.responseText;
  3028. try {
  3029. // http://perfectionkills.com/global-eval-what-are-the-options/
  3030. if(dataType === 'script') {
  3031. (1, eval)(result);
  3032. } else if(dataType === 'xml') {
  3033. result = xhr.responseXML;
  3034. } else if(dataType === 'json') {
  3035. result = blankRE.test(result) ? null : $.parseJSON(result);
  3036. }
  3037. } catch(e) {
  3038. error = e;
  3039. }
  3040. if(error) {
  3041. ajaxError(error, 'parsererror', xhr, settings);
  3042. } else {
  3043. ajaxSuccess(result, xhr, settings);
  3044. }
  3045. } else {
  3046. var status = xhr.status ? 'error' : 'abort';
  3047. var statusText = xhr.statusText || null;
  3048. if(isLocal) {
  3049. status = 'error';
  3050. statusText = '404';
  3051. }
  3052. ajaxError(statusText, status, xhr, settings);
  3053. }
  3054. }
  3055. };
  3056. if(ajaxBeforeSend(xhr, settings) === false) {
  3057. xhr.abort();
  3058. ajaxError(null, 'abort', xhr, settings);
  3059. return xhr;
  3060. }
  3061. if(settings.xhrFields) {
  3062. for(var name in settings.xhrFields) {
  3063. xhr[name] = settings.xhrFields[name];
  3064. }
  3065. }
  3066. var async = 'async' in settings ? settings.async : true;
  3067. xhr.open(settings.type.toUpperCase(), settings.url, async, settings.username, settings.password);
  3068. for(var name in headers) {
  3069. if(headers.hasOwnProperty(name)) {
  3070. nativeSetHeader.apply(xhr, headers[name]);
  3071. }
  3072. }
  3073. if(settings.timeout > 0) {
  3074. abortTimeout = setTimeout(function() {
  3075. xhr.onreadystatechange = $.noop;
  3076. xhr.abort();
  3077. ajaxError(null, 'timeout', xhr, settings);
  3078. }, settings.timeout);
  3079. }
  3080. xhr.send(settings.data ? settings.data : null);
  3081. return xhr;
  3082. };
  3083. $.param = function(obj, traditional) {
  3084. var params = [];
  3085. params.add = function(k, v) {
  3086. this.push(encodeURIComponent(k) + '=' + encodeURIComponent(v));
  3087. };
  3088. serialize(params, obj, traditional);
  3089. return params.join('&').replace(/%20/g, '+');
  3090. };
  3091. $.get = function( /* url, data, success, dataType */ ) {
  3092. return $.ajax(parseArguments.apply(null, arguments));
  3093. };
  3094. $.post = function( /* url, data, success, dataType */ ) {
  3095. var options = parseArguments.apply(null, arguments);
  3096. options.type = 'POST';
  3097. return $.ajax(options);
  3098. };
  3099. $.getJSON = function( /* url, data, success */ ) {
  3100. var options = parseArguments.apply(null, arguments);
  3101. options.dataType = 'json';
  3102. return $.ajax(options);
  3103. };
  3104. $.fn.load = function(url, data, success) {
  3105. if(!this.length)
  3106. return this;
  3107. var self = this,
  3108. parts = url.split(/\s/),
  3109. selector,
  3110. options = parseArguments(url, data, success),
  3111. callback = options.success;
  3112. if(parts.length > 1)
  3113. options.url = parts[0], selector = parts[1];
  3114. options.success = function(response) {
  3115. if(selector) {
  3116. var div = document.createElement('div');
  3117. div.innerHTML = response.replace(rscript, "");
  3118. var selectorDiv = document.createElement('div');
  3119. var childs = div.querySelectorAll(selector);
  3120. if(childs && childs.length > 0) {
  3121. for(var i = 0, len = childs.length; i < len; i++) {
  3122. selectorDiv.appendChild(childs[i]);
  3123. }
  3124. }
  3125. self[0].innerHTML = selectorDiv.innerHTML;
  3126. } else {
  3127. self[0].innerHTML = response;
  3128. }
  3129. callback && callback.apply(self, arguments);
  3130. };
  3131. $.ajax(options);
  3132. return this;
  3133. };
  3134. })(mui, window);
  3135. /**
  3136. * 5+ ajax
  3137. */
  3138. (function($) {
  3139. var originAnchor = document.createElement('a');
  3140. originAnchor.href = window.location.href;
  3141. $.plusReady(function() {
  3142. $.ajaxSettings = $.extend($.ajaxSettings, {
  3143. xhr: function(settings) {
  3144. if (settings.crossDomain) { //强制使用plus跨域
  3145. return new plus.net.XMLHttpRequest();
  3146. }
  3147. //仅在webview的url为远程文件,且ajax请求的资源不同源下使用plus.net.XMLHttpRequest
  3148. if (originAnchor.protocol !== 'file:') {
  3149. var urlAnchor = document.createElement('a');
  3150. urlAnchor.href = settings.url;
  3151. urlAnchor.href = urlAnchor.href;
  3152. settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host);
  3153. if (settings.crossDomain) {
  3154. return new plus.net.XMLHttpRequest();
  3155. }
  3156. }
  3157. return new window.XMLHttpRequest();
  3158. }
  3159. });
  3160. });
  3161. })(mui);
  3162. /**
  3163. * mui layout(offset[,position,width,height...])
  3164. * @param {type} $
  3165. * @param {type} window
  3166. * @param {type} undefined
  3167. * @returns {undefined}
  3168. */
  3169. (function($, window, undefined) {
  3170. $.offset = function(element) {
  3171. var box = {
  3172. top : 0,
  3173. left : 0
  3174. };
  3175. if ( typeof element.getBoundingClientRect !== undefined) {
  3176. box = element.getBoundingClientRect();
  3177. }
  3178. return {
  3179. top : box.top + window.pageYOffset - element.clientTop,
  3180. left : box.left + window.pageXOffset - element.clientLeft
  3181. };
  3182. };
  3183. })(mui, window);
  3184. /**
  3185. * mui animation
  3186. */
  3187. (function($, window) {
  3188. /**
  3189. * scrollTo
  3190. */
  3191. $.scrollTo = function(scrollTop, duration, callback) {
  3192. duration = duration || 1000;
  3193. var scroll = function(duration) {
  3194. if (duration <= 0) {
  3195. window.scrollTo(0, scrollTop);
  3196. callback && callback();
  3197. return;
  3198. }
  3199. var distaince = scrollTop - window.scrollY;
  3200. setTimeout(function() {
  3201. window.scrollTo(0, window.scrollY + distaince / duration * 10);
  3202. scroll(duration - 10);
  3203. }, 16.7);
  3204. };
  3205. scroll(duration);
  3206. };
  3207. $.animationFrame = function(cb) {
  3208. var args, isQueued, context;
  3209. return function() {
  3210. args = arguments;
  3211. context = this;
  3212. if (!isQueued) {
  3213. isQueued = true;
  3214. requestAnimationFrame(function() {
  3215. cb.apply(context, args);
  3216. isQueued = false;
  3217. });
  3218. }
  3219. };
  3220. };
  3221. })(mui, window);
  3222. (function($) {
  3223. var initializing = false,
  3224. fnTest = /xyz/.test(function() {
  3225. xyz;
  3226. }) ? /\b_super\b/ : /.*/;
  3227. var Class = function() {};
  3228. Class.extend = function(prop) {
  3229. var _super = this.prototype;
  3230. initializing = true;
  3231. var prototype = new this();
  3232. initializing = false;
  3233. for (var name in prop) {
  3234. prototype[name] = typeof prop[name] == "function" &&
  3235. typeof _super[name] == "function" && fnTest.test(prop[name]) ?
  3236. (function(name, fn) {
  3237. return function() {
  3238. var tmp = this._super;
  3239. this._super = _super[name];
  3240. var ret = fn.apply(this, arguments);
  3241. this._super = tmp;
  3242. return ret;
  3243. };
  3244. })(name, prop[name]) :
  3245. prop[name];
  3246. }
  3247. function Class() {
  3248. if (!initializing && this.init)
  3249. this.init.apply(this, arguments);
  3250. }
  3251. Class.prototype = prototype;
  3252. Class.prototype.constructor = Class;
  3253. Class.extend = arguments.callee;
  3254. return Class;
  3255. };
  3256. $.Class = Class;
  3257. })(mui);
  3258. (function($, document, undefined) {
  3259. var CLASS_PULL_TOP_POCKET = 'mui-pull-top-pocket';
  3260. var CLASS_PULL_BOTTOM_POCKET = 'mui-pull-bottom-pocket';
  3261. var CLASS_PULL = 'mui-pull';
  3262. var CLASS_PULL_LOADING = 'mui-pull-loading';
  3263. var CLASS_PULL_CAPTION = 'mui-pull-caption';
  3264. var CLASS_PULL_CAPTION_DOWN = 'mui-pull-caption-down';
  3265. var CLASS_PULL_CAPTION_REFRESH = 'mui-pull-caption-refresh';
  3266. var CLASS_PULL_CAPTION_NOMORE = 'mui-pull-caption-nomore';
  3267. var CLASS_ICON = 'mui-icon';
  3268. var CLASS_SPINNER = 'mui-spinner';
  3269. var CLASS_ICON_PULLDOWN = 'mui-icon-pulldown';
  3270. var CLASS_BLOCK = 'mui-block';
  3271. var CLASS_HIDDEN = 'mui-hidden';
  3272. var CLASS_VISIBILITY = 'mui-visibility';
  3273. var CLASS_LOADING_UP = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_ICON_PULLDOWN;
  3274. var CLASS_LOADING_DOWN = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_ICON_PULLDOWN;
  3275. var CLASS_LOADING = CLASS_PULL_LOADING + ' ' + CLASS_ICON + ' ' + CLASS_SPINNER;
  3276. var pocketHtml = ['<div class="' + CLASS_PULL + '">', '<div class="{icon}"></div>', '<div class="' + CLASS_PULL_CAPTION + '">{contentrefresh}</div>', '</div>'].join('');
  3277. var PullRefresh = {
  3278. init: function(element, options) {
  3279. this._super(element, $.extend(true, {
  3280. scrollY: true,
  3281. scrollX: false,
  3282. indicators: true,
  3283. deceleration: 0.003,
  3284. down: {
  3285. height: 50,
  3286. contentinit: '下拉可以刷新',
  3287. contentdown: '下拉可以刷新',
  3288. contentover: '释放立即刷新',
  3289. contentrefresh: '正在刷新...'
  3290. },
  3291. up: {
  3292. height: 50,
  3293. auto: false,
  3294. contentinit: '上拉显示更多',
  3295. contentdown: '上拉显示更多',
  3296. contentrefresh: '正在加载...',
  3297. contentnomore: '没有更多数据了',
  3298. duration: 300
  3299. }
  3300. }, options));
  3301. },
  3302. _init: function() {
  3303. this._super();
  3304. this._initPocket();
  3305. },
  3306. _initPulldownRefresh: function() {
  3307. this.pulldown = true;
  3308. this.pullPocket = this.topPocket;
  3309. this.pullPocket.classList.add(CLASS_BLOCK);
  3310. this.pullPocket.classList.add(CLASS_VISIBILITY);
  3311. this.pullCaption = this.topCaption;
  3312. this.pullLoading = this.topLoading;
  3313. },
  3314. _initPullupRefresh: function() {
  3315. this.pulldown = false;
  3316. this.pullPocket = this.bottomPocket;
  3317. this.pullPocket.classList.add(CLASS_BLOCK);
  3318. this.pullPocket.classList.add(CLASS_VISIBILITY);
  3319. this.pullCaption = this.bottomCaption;
  3320. this.pullLoading = this.bottomLoading;
  3321. },
  3322. _initPocket: function() {
  3323. var options = this.options;
  3324. if (options.down && options.down.hasOwnProperty('callback')) {
  3325. this.topPocket = this.scroller.querySelector('.' + CLASS_PULL_TOP_POCKET);
  3326. if (!this.topPocket) {
  3327. this.topPocket = this._createPocket(CLASS_PULL_TOP_POCKET, options.down, CLASS_LOADING_DOWN);
  3328. this.wrapper.insertBefore(this.topPocket, this.wrapper.firstChild);
  3329. }
  3330. this.topLoading = this.topPocket.querySelector('.' + CLASS_PULL_LOADING);
  3331. this.topCaption = this.topPocket.querySelector('.' + CLASS_PULL_CAPTION);
  3332. }
  3333. if (options.up && options.up.hasOwnProperty('callback')) {
  3334. this.bottomPocket = this.scroller.querySelector('.' + CLASS_PULL_BOTTOM_POCKET);
  3335. if (!this.bottomPocket) {
  3336. this.bottomPocket = this._createPocket(CLASS_PULL_BOTTOM_POCKET, options.up, CLASS_LOADING);
  3337. this.scroller.appendChild(this.bottomPocket);
  3338. }
  3339. this.bottomLoading = this.bottomPocket.querySelector('.' + CLASS_PULL_LOADING);
  3340. this.bottomCaption = this.bottomPocket.querySelector('.' + CLASS_PULL_CAPTION);
  3341. //TODO only for h5
  3342. this.wrapper.addEventListener('scrollbottom', this);
  3343. }
  3344. },
  3345. _createPocket: function(clazz, options, iconClass) {
  3346. var pocket = document.createElement('div');
  3347. pocket.className = clazz;
  3348. pocket.innerHTML = pocketHtml.replace('{contentrefresh}', options.contentinit).replace('{icon}', iconClass);
  3349. return pocket;
  3350. },
  3351. _resetPullDownLoading: function() {
  3352. var loading = this.pullLoading;
  3353. if (loading) {
  3354. this.pullCaption.innerHTML = this.options.down.contentdown;
  3355. loading.style.webkitTransition = "";
  3356. loading.style.webkitTransform = "";
  3357. loading.style.webkitAnimation = "";
  3358. loading.className = CLASS_LOADING_DOWN;
  3359. }
  3360. },
  3361. _setCaptionClass: function(isPulldown, caption, title) {
  3362. if (!isPulldown) {
  3363. switch (title) {
  3364. case this.options.up.contentdown:
  3365. caption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_DOWN;
  3366. break;
  3367. case this.options.up.contentrefresh:
  3368. caption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_REFRESH
  3369. break;
  3370. case this.options.up.contentnomore:
  3371. caption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_NOMORE;
  3372. break;
  3373. }
  3374. }
  3375. },
  3376. _setCaption: function(title, reset) {
  3377. if (this.loading) {
  3378. return;
  3379. }
  3380. var options = this.options;
  3381. var pocket = this.pullPocket;
  3382. var caption = this.pullCaption;
  3383. var loading = this.pullLoading;
  3384. var isPulldown = this.pulldown;
  3385. var self = this;
  3386. if (pocket) {
  3387. if (reset) {
  3388. setTimeout(function() {
  3389. caption.innerHTML = self.lastTitle = title;
  3390. if (isPulldown) {
  3391. loading.className = CLASS_LOADING_DOWN;
  3392. } else {
  3393. self._setCaptionClass(false, caption, title);
  3394. loading.className = CLASS_LOADING;
  3395. }
  3396. loading.style.webkitAnimation = "";
  3397. loading.style.webkitTransition = "";
  3398. loading.style.webkitTransform = "";
  3399. }, 100);
  3400. } else {
  3401. if (title !== this.lastTitle) {
  3402. caption.innerHTML = title;
  3403. if (isPulldown) {
  3404. if (title === options.down.contentrefresh) {
  3405. loading.className = CLASS_LOADING;
  3406. loading.style.webkitAnimation = "spinner-spin 1s step-end infinite";
  3407. } else if (title === options.down.contentover) {
  3408. loading.className = CLASS_LOADING_UP;
  3409. loading.style.webkitTransition = "-webkit-transform 0.3s ease-in";
  3410. loading.style.webkitTransform = "rotate(180deg)";
  3411. } else if (title === options.down.contentdown) {
  3412. loading.className = CLASS_LOADING_DOWN;
  3413. loading.style.webkitTransition = "-webkit-transform 0.3s ease-in";
  3414. loading.style.webkitTransform = "rotate(0deg)";
  3415. }
  3416. } else {
  3417. if (title === options.up.contentrefresh) {
  3418. loading.className = CLASS_LOADING + ' ' + CLASS_VISIBILITY;
  3419. } else {
  3420. loading.className = CLASS_LOADING + ' ' + CLASS_HIDDEN;
  3421. }
  3422. self._setCaptionClass(false, caption, title);
  3423. }
  3424. this.lastTitle = title;
  3425. }
  3426. }
  3427. }
  3428. }
  3429. };
  3430. $.PullRefresh = PullRefresh;
  3431. })(mui, document);
  3432. (function($, window, document, undefined) {
  3433. var CLASS_SCROLL = 'mui-scroll';
  3434. var CLASS_SCROLLBAR = 'mui-scrollbar';
  3435. var CLASS_INDICATOR = 'mui-scrollbar-indicator';
  3436. var CLASS_SCROLLBAR_VERTICAL = CLASS_SCROLLBAR + '-vertical';
  3437. var CLASS_SCROLLBAR_HORIZONTAL = CLASS_SCROLLBAR + '-horizontal';
  3438. var CLASS_ACTIVE = 'mui-active';
  3439. var ease = {
  3440. quadratic: {
  3441. style: 'cubic-bezier(0.25, 0.46, 0.45, 0.94)',
  3442. fn: function(k) {
  3443. return k * (2 - k);
  3444. }
  3445. },
  3446. circular: {
  3447. style: 'cubic-bezier(0.1, 0.57, 0.1, 1)',
  3448. fn: function(k) {
  3449. return Math.sqrt(1 - (--k * k));
  3450. }
  3451. },
  3452. outCirc: {
  3453. style: 'cubic-bezier(0.075, 0.82, 0.165, 1)'
  3454. },
  3455. outCubic: {
  3456. style: 'cubic-bezier(0.165, 0.84, 0.44, 1)'
  3457. }
  3458. }
  3459. var Scroll = $.Class.extend({
  3460. init: function(element, options) {
  3461. this.wrapper = this.element = element;
  3462. this.scroller = this.wrapper.children[0];
  3463. this.scrollerStyle = this.scroller && this.scroller.style;
  3464. this.stopped = false;
  3465. this.options = $.extend(true, {
  3466. scrollY: true, //是否竖向滚动
  3467. scrollX: false, //是否横向滚动
  3468. startX: 0, //初始化时滚动至x
  3469. startY: 0, //初始化时滚动至y
  3470. indicators: true, //是否显示滚动条
  3471. stopPropagation: false,
  3472. hardwareAccelerated: true,
  3473. fixedBadAndorid: false,
  3474. preventDefaultException: {
  3475. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|VIDEO)$/
  3476. },
  3477. momentum: true,
  3478. snapX: 0.5, //横向切换距离(以当前容器宽度为基准)
  3479. snap: false, //图片轮播,拖拽式选项卡
  3480. bounce: true, //是否启用回弹
  3481. bounceTime: 500, //回弹动画时间
  3482. bounceEasing: ease.outCirc, //回弹动画曲线
  3483. scrollTime: 500,
  3484. scrollEasing: ease.outCubic, //轮播动画曲线
  3485. directionLockThreshold: 5,
  3486. parallaxElement: false, //视差元素
  3487. parallaxRatio: 0.5
  3488. }, options);
  3489. this.x = 0;
  3490. this.y = 0;
  3491. this.translateZ = this.options.hardwareAccelerated ? ' translateZ(0)' : '';
  3492. this._init();
  3493. if (this.scroller) {
  3494. this.refresh();
  3495. // if (this.options.startX !== 0 || this.options.startY !== 0) { //需要判断吗?后续根据实际情况再看看
  3496. this.scrollTo(this.options.startX, this.options.startY);
  3497. // }
  3498. }
  3499. },
  3500. _init: function() {
  3501. this._initParallax();
  3502. this._initIndicators();
  3503. this._initEvent();
  3504. },
  3505. _initParallax: function() {
  3506. if (this.options.parallaxElement) {
  3507. this.parallaxElement = document.querySelector(this.options.parallaxElement);
  3508. this.parallaxStyle = this.parallaxElement.style;
  3509. this.parallaxHeight = this.parallaxElement.offsetHeight;
  3510. this.parallaxImgStyle = this.parallaxElement.querySelector('img').style;
  3511. }
  3512. },
  3513. _initIndicators: function() {
  3514. var self = this;
  3515. self.indicators = [];
  3516. if (!this.options.indicators) {
  3517. return;
  3518. }
  3519. var indicators = [],
  3520. indicator;
  3521. // Vertical scrollbar
  3522. if (self.options.scrollY) {
  3523. indicator = {
  3524. el: this._createScrollBar(CLASS_SCROLLBAR_VERTICAL),
  3525. listenX: false
  3526. };
  3527. this.wrapper.appendChild(indicator.el);
  3528. indicators.push(indicator);
  3529. }
  3530. // Horizontal scrollbar
  3531. if (this.options.scrollX) {
  3532. indicator = {
  3533. el: this._createScrollBar(CLASS_SCROLLBAR_HORIZONTAL),
  3534. listenY: false
  3535. };
  3536. this.wrapper.appendChild(indicator.el);
  3537. indicators.push(indicator);
  3538. }
  3539. for (var i = indicators.length; i--;) {
  3540. this.indicators.push(new Indicator(this, indicators[i]));
  3541. }
  3542. },
  3543. _initSnap: function() {
  3544. this.currentPage = {};
  3545. this.pages = [];
  3546. var snaps = this.snaps;
  3547. var length = snaps.length;
  3548. var m = 0;
  3549. var n = -1;
  3550. var x = 0;
  3551. var leftX = 0;
  3552. var rightX = 0;
  3553. var snapX = 0;
  3554. for (var i = 0; i < length; i++) {
  3555. var snap = snaps[i];
  3556. var offsetLeft = snap.offsetLeft;
  3557. var offsetWidth = snap.offsetWidth;
  3558. if (i === 0 || offsetLeft <= snaps[i - 1].offsetLeft) {
  3559. m = 0;
  3560. n++;
  3561. }
  3562. if (!this.pages[m]) {
  3563. this.pages[m] = [];
  3564. }
  3565. x = this._getSnapX(offsetLeft);
  3566. snapX = Math.round((offsetWidth) * this.options.snapX);
  3567. leftX = x - snapX;
  3568. rightX = x - offsetWidth + snapX;
  3569. this.pages[m][n] = {
  3570. x: x,
  3571. leftX: leftX,
  3572. rightX: rightX,
  3573. pageX: m,
  3574. element: snap
  3575. }
  3576. if (snap.classList.contains(CLASS_ACTIVE)) {
  3577. this.currentPage = this.pages[m][0];
  3578. }
  3579. if (x >= this.maxScrollX) {
  3580. m++;
  3581. }
  3582. }
  3583. this.options.startX = this.currentPage.x || 0;
  3584. },
  3585. _getSnapX: function(offsetLeft) {
  3586. return Math.max(Math.min(0, -offsetLeft + (this.wrapperWidth / 2)), this.maxScrollX);
  3587. },
  3588. _gotoPage: function(index) {
  3589. this.currentPage = this.pages[Math.min(index, this.pages.length - 1)][0];
  3590. for (var i = 0, len = this.snaps.length; i < len; i++) {
  3591. if (i === index) {
  3592. this.snaps[i].classList.add(CLASS_ACTIVE);
  3593. } else {
  3594. this.snaps[i].classList.remove(CLASS_ACTIVE);
  3595. }
  3596. }
  3597. this.scrollTo(this.currentPage.x, 0, this.options.scrollTime);
  3598. },
  3599. _nearestSnap: function(x) {
  3600. if (!this.pages.length) {
  3601. return {
  3602. x: 0,
  3603. pageX: 0
  3604. };
  3605. }
  3606. var i = 0;
  3607. var length = this.pages.length;
  3608. if (x > 0) {
  3609. x = 0;
  3610. } else if (x < this.maxScrollX) {
  3611. x = this.maxScrollX;
  3612. }
  3613. for (; i < length; i++) {
  3614. var nearestX = this.direction === 'left' ? this.pages[i][0].leftX : this.pages[i][0].rightX;
  3615. if (x >= nearestX) {
  3616. return this.pages[i][0];
  3617. }
  3618. }
  3619. return {
  3620. x: 0,
  3621. pageX: 0
  3622. };
  3623. },
  3624. _initEvent: function(detach) {
  3625. var action = detach ? 'removeEventListener' : 'addEventListener';
  3626. window[action]('orientationchange', this);
  3627. window[action]('resize', this);
  3628. this.scroller[action]('webkitTransitionEnd', this);
  3629. this.wrapper[action]($.EVENT_START, this);
  3630. this.wrapper[action]($.EVENT_CANCEL, this);
  3631. this.wrapper[action]($.EVENT_END, this);
  3632. this.wrapper[action]('drag', this);
  3633. this.wrapper[action]('dragend', this);
  3634. this.wrapper[action]('flick', this);
  3635. this.wrapper[action]('scrollend', this);
  3636. if (this.options.scrollX) {
  3637. this.wrapper[action]('swiperight', this);
  3638. }
  3639. var segmentedControl = this.wrapper.querySelector('.mui-segmented-control');
  3640. if (segmentedControl) { //靠,这个bug排查了一下午,阻止hash跳转,一旦hash跳转会导致可拖拽选项卡的tab不见
  3641. mui(segmentedControl)[detach ? 'off' : 'on']('click', 'a', $.preventDefault);
  3642. }
  3643. this.wrapper[action]('scrollstart', this);
  3644. this.wrapper[action]('refresh', this);
  3645. },
  3646. _handleIndicatorScrollend: function() {
  3647. this.indicators.map(function(indicator) {
  3648. indicator.fade();
  3649. });
  3650. },
  3651. _handleIndicatorScrollstart: function() {
  3652. this.indicators.map(function(indicator) {
  3653. indicator.fade(1);
  3654. });
  3655. },
  3656. _handleIndicatorRefresh: function() {
  3657. this.indicators.map(function(indicator) {
  3658. indicator.refresh();
  3659. });
  3660. },
  3661. handleEvent: function(e) {
  3662. if (this.stopped) {
  3663. this.resetPosition();
  3664. return;
  3665. }
  3666. switch (e.type) {
  3667. case $.EVENT_START:
  3668. this._start(e);
  3669. break;
  3670. case 'drag':
  3671. this.options.stopPropagation && e.stopPropagation();
  3672. this._drag(e);
  3673. break;
  3674. case 'dragend':
  3675. case 'flick':
  3676. this.options.stopPropagation && e.stopPropagation();
  3677. this._flick(e);
  3678. break;
  3679. case $.EVENT_CANCEL:
  3680. case $.EVENT_END:
  3681. this._end(e);
  3682. break;
  3683. case 'webkitTransitionEnd':
  3684. this.transitionTimer && this.transitionTimer.cancel();
  3685. this._transitionEnd(e);
  3686. break;
  3687. case 'scrollstart':
  3688. this._handleIndicatorScrollstart(e);
  3689. break;
  3690. case 'scrollend':
  3691. this._handleIndicatorScrollend(e);
  3692. this._scrollend(e);
  3693. e.stopPropagation();
  3694. break;
  3695. case 'orientationchange':
  3696. case 'resize':
  3697. this._resize();
  3698. break;
  3699. case 'swiperight':
  3700. e.stopPropagation();
  3701. break;
  3702. case 'refresh':
  3703. this._handleIndicatorRefresh(e);
  3704. break;
  3705. }
  3706. },
  3707. _start: function(e) {
  3708. this.moved = this.needReset = false;
  3709. this._transitionTime();
  3710. if (this.isInTransition) {
  3711. this.needReset = true;
  3712. this.isInTransition = false;
  3713. var pos = $.parseTranslateMatrix($.getStyles(this.scroller, 'webkitTransform'));
  3714. this.setTranslate(Math.round(pos.x), Math.round(pos.y));
  3715. // this.resetPosition(); //reset
  3716. $.trigger(this.scroller, 'scrollend', this);
  3717. // e.stopPropagation();
  3718. e.preventDefault();
  3719. }
  3720. this.reLayout();
  3721. $.trigger(this.scroller, 'beforescrollstart', this);
  3722. },
  3723. _getDirectionByAngle: function(angle) {
  3724. if (angle < -80 && angle > -100) {
  3725. return 'up';
  3726. } else if (angle >= 80 && angle < 100) {
  3727. return 'down';
  3728. } else if (angle >= 170 || angle <= -170) {
  3729. return 'left';
  3730. } else if (angle >= -35 && angle <= 10) {
  3731. return 'right';
  3732. }
  3733. return null;
  3734. },
  3735. _drag: function(e) {
  3736. // if (this.needReset) {
  3737. // e.stopPropagation(); //disable parent drag(nested scroller)
  3738. // return;
  3739. // }
  3740. var detail = e.detail;
  3741. if (this.options.scrollY || detail.direction === 'up' || detail.direction === 'down') { //如果是竖向滚动或手势方向是上或下
  3742. //ios8 hack
  3743. if ($.os.ios && parseFloat($.os.version) >= 8) { //多webview时,离开当前webview会导致后续touch事件不触发
  3744. var clientY = detail.gesture.touches[0].clientY;
  3745. //下拉刷新 or 上拉加载
  3746. if ((clientY + 10) > window.innerHeight || clientY < 10) {
  3747. this.resetPosition(this.options.bounceTime);
  3748. return;
  3749. }
  3750. }
  3751. }
  3752. var isPreventDefault = isReturn = false;
  3753. var direction = this._getDirectionByAngle(detail.angle);
  3754. if (detail.direction === 'left' || detail.direction === 'right') {
  3755. if (this.options.scrollX) {
  3756. isPreventDefault = true;
  3757. if (!this.moved) { //识别角度(该角度导致轮播不灵敏)
  3758. // if (direction !== 'left' && direction !== 'right') {
  3759. // isReturn = true;
  3760. // } else {
  3761. $.gestures.session.lockDirection = true; //锁定方向
  3762. $.gestures.session.startDirection = detail.direction;
  3763. // }
  3764. }
  3765. } else if (this.options.scrollY && !this.moved) {
  3766. isReturn = true;
  3767. }
  3768. } else if (detail.direction === 'up' || detail.direction === 'down') {
  3769. if (this.options.scrollY) {
  3770. isPreventDefault = true;
  3771. // if (!this.moved) { //识别角度,竖向滚动似乎没必要进行小角度验证
  3772. // if (direction !== 'up' && direction !== 'down') {
  3773. // isReturn = true;
  3774. // }
  3775. // }
  3776. if (!this.moved) {
  3777. $.gestures.session.lockDirection = true; //锁定方向
  3778. $.gestures.session.startDirection = detail.direction;
  3779. }
  3780. } else if (this.options.scrollX && !this.moved) {
  3781. isReturn = true;
  3782. }
  3783. } else {
  3784. isReturn = true;
  3785. }
  3786. if (this.moved || isPreventDefault) {
  3787. e.stopPropagation(); //阻止冒泡(scroll类嵌套)
  3788. detail.gesture && detail.gesture.preventDefault();
  3789. }
  3790. if (isReturn) { //禁止非法方向滚动
  3791. return;
  3792. }
  3793. if (!this.moved) {
  3794. $.trigger(this.scroller, 'scrollstart', this);
  3795. } else {
  3796. e.stopPropagation(); //move期间阻止冒泡(scroll嵌套)
  3797. }
  3798. var deltaX = 0;
  3799. var deltaY = 0;
  3800. if (!this.moved) { //start
  3801. deltaX = detail.deltaX;
  3802. deltaY = detail.deltaY;
  3803. } else { //move
  3804. deltaX = detail.deltaX - $.gestures.session.prevTouch.deltaX;
  3805. deltaY = detail.deltaY - $.gestures.session.prevTouch.deltaY;
  3806. }
  3807. var absDeltaX = Math.abs(detail.deltaX);
  3808. var absDeltaY = Math.abs(detail.deltaY);
  3809. if (absDeltaX > absDeltaY + this.options.directionLockThreshold) {
  3810. deltaY = 0;
  3811. } else if (absDeltaY >= absDeltaX + this.options.directionLockThreshold) {
  3812. deltaX = 0;
  3813. }
  3814. deltaX = this.hasHorizontalScroll ? deltaX : 0;
  3815. deltaY = this.hasVerticalScroll ? deltaY : 0;
  3816. var newX = this.x + deltaX;
  3817. var newY = this.y + deltaY;
  3818. // Slow down if outside of the boundaries
  3819. if (newX > 0 || newX < this.maxScrollX) {
  3820. newX = this.options.bounce ? this.x + deltaX / 3 : newX > 0 ? 0 : this.maxScrollX;
  3821. }
  3822. if (newY > 0 || newY < this.maxScrollY) {
  3823. newY = this.options.bounce ? this.y + deltaY / 3 : newY > 0 ? 0 : this.maxScrollY;
  3824. }
  3825. if (!this.requestAnimationFrame) {
  3826. this._updateTranslate();
  3827. }
  3828. this.direction = detail.deltaX > 0 ? 'right' : 'left';
  3829. this.moved = true;
  3830. this.x = newX;
  3831. this.y = newY;
  3832. $.trigger(this.scroller, 'scroll', this);
  3833. },
  3834. _flick: function(e) {
  3835. // if (!this.moved || this.needReset) {
  3836. // return;
  3837. // }
  3838. if (!this.moved) {
  3839. return;
  3840. }
  3841. e.stopPropagation();
  3842. var detail = e.detail;
  3843. this._clearRequestAnimationFrame();
  3844. if (e.type === 'dragend' && detail.flick) { //dragend
  3845. return;
  3846. }
  3847. var newX = Math.round(this.x);
  3848. var newY = Math.round(this.y);
  3849. this.isInTransition = false;
  3850. // reset if we are outside of the boundaries
  3851. if (this.resetPosition(this.options.bounceTime)) {
  3852. return;
  3853. }
  3854. this.scrollTo(newX, newY); // ensures that the last position is rounded
  3855. if (e.type === 'dragend') { //dragend
  3856. $.trigger(this.scroller, 'scrollend', this);
  3857. return;
  3858. }
  3859. var time = 0;
  3860. var easing = '';
  3861. // start momentum animation if needed
  3862. if (this.options.momentum && detail.flickTime < 300) {
  3863. momentumX = this.hasHorizontalScroll ? this._momentum(this.x, detail.flickDistanceX, detail.flickTime, this.maxScrollX, this.options.bounce ? this.wrapperWidth : 0, this.options.deceleration) : {
  3864. destination: newX,
  3865. duration: 0
  3866. };
  3867. momentumY = this.hasVerticalScroll ? this._momentum(this.y, detail.flickDistanceY, detail.flickTime, this.maxScrollY, this.options.bounce ? this.wrapperHeight : 0, this.options.deceleration) : {
  3868. destination: newY,
  3869. duration: 0
  3870. };
  3871. newX = momentumX.destination;
  3872. newY = momentumY.destination;
  3873. time = Math.max(momentumX.duration, momentumY.duration);
  3874. this.isInTransition = true;
  3875. }
  3876. if (newX != this.x || newY != this.y) {
  3877. if (newX > 0 || newX < this.maxScrollX || newY > 0 || newY < this.maxScrollY) {
  3878. easing = ease.quadratic;
  3879. }
  3880. this.scrollTo(newX, newY, time, easing);
  3881. return;
  3882. }
  3883. $.trigger(this.scroller, 'scrollend', this);
  3884. // e.stopPropagation();
  3885. },
  3886. _end: function(e) {
  3887. this.needReset = false;
  3888. if ((!this.moved && this.needReset) || e.type === $.EVENT_CANCEL) {
  3889. this.resetPosition();
  3890. }
  3891. },
  3892. _transitionEnd: function(e) {
  3893. if (e.target != this.scroller || !this.isInTransition) {
  3894. return;
  3895. }
  3896. this._transitionTime();
  3897. if (!this.resetPosition(this.options.bounceTime)) {
  3898. this.isInTransition = false;
  3899. $.trigger(this.scroller, 'scrollend', this);
  3900. }
  3901. },
  3902. _scrollend: function(e) {
  3903. if ((this.y === 0 && this.maxScrollY === 0) || (Math.abs(this.y) > 0 && this.y <= this.maxScrollY)) {
  3904. $.trigger(this.scroller, 'scrollbottom', this);
  3905. }
  3906. },
  3907. _resize: function() {
  3908. var that = this;
  3909. clearTimeout(that.resizeTimeout);
  3910. that.resizeTimeout = setTimeout(function() {
  3911. that.refresh();
  3912. }, that.options.resizePolling);
  3913. },
  3914. _transitionTime: function(time) {
  3915. time = time || 0;
  3916. this.scrollerStyle['webkitTransitionDuration'] = time + 'ms';
  3917. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  3918. this.parallaxStyle['webkitTransitionDuration'] = time + 'ms';
  3919. }
  3920. if (this.options.fixedBadAndorid && !time && $.os.isBadAndroid) {
  3921. this.scrollerStyle['webkitTransitionDuration'] = '0.001s';
  3922. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  3923. this.parallaxStyle['webkitTransitionDuration'] = '0.001s';
  3924. }
  3925. }
  3926. if (this.indicators) {
  3927. for (var i = this.indicators.length; i--;) {
  3928. this.indicators[i].transitionTime(time);
  3929. }
  3930. }
  3931. if (time) { //自定义timer,保证webkitTransitionEnd始终触发
  3932. this.transitionTimer && this.transitionTimer.cancel();
  3933. this.transitionTimer = $.later(function() {
  3934. $.trigger(this.scroller, 'webkitTransitionEnd');
  3935. }, time + 100, this);
  3936. }
  3937. },
  3938. _transitionTimingFunction: function(easing) {
  3939. this.scrollerStyle['webkitTransitionTimingFunction'] = easing;
  3940. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  3941. this.parallaxStyle['webkitTransitionDuration'] = easing;
  3942. }
  3943. if (this.indicators) {
  3944. for (var i = this.indicators.length; i--;) {
  3945. this.indicators[i].transitionTimingFunction(easing);
  3946. }
  3947. }
  3948. },
  3949. _translate: function(x, y) {
  3950. this.x = x;
  3951. this.y = y;
  3952. },
  3953. _clearRequestAnimationFrame: function() {
  3954. if (this.requestAnimationFrame) {
  3955. cancelAnimationFrame(this.requestAnimationFrame);
  3956. this.requestAnimationFrame = null;
  3957. }
  3958. },
  3959. _updateTranslate: function() {
  3960. var self = this;
  3961. if (self.x !== self.lastX || self.y !== self.lastY) {
  3962. self.setTranslate(self.x, self.y);
  3963. }
  3964. self.requestAnimationFrame = requestAnimationFrame(function() {
  3965. self._updateTranslate();
  3966. });
  3967. },
  3968. _createScrollBar: function(clazz) {
  3969. var scrollbar = document.createElement('div');
  3970. var indicator = document.createElement('div');
  3971. scrollbar.className = CLASS_SCROLLBAR + ' ' + clazz;
  3972. indicator.className = CLASS_INDICATOR;
  3973. scrollbar.appendChild(indicator);
  3974. if (clazz === CLASS_SCROLLBAR_VERTICAL) {
  3975. this.scrollbarY = scrollbar;
  3976. this.scrollbarIndicatorY = indicator;
  3977. } else if (clazz === CLASS_SCROLLBAR_HORIZONTAL) {
  3978. this.scrollbarX = scrollbar;
  3979. this.scrollbarIndicatorX = indicator;
  3980. }
  3981. this.wrapper.appendChild(scrollbar);
  3982. return scrollbar;
  3983. },
  3984. _preventDefaultException: function(el, exceptions) {
  3985. for (var i in exceptions) {
  3986. if (exceptions[i].test(el[i])) {
  3987. return true;
  3988. }
  3989. }
  3990. return false;
  3991. },
  3992. _reLayout: function() {
  3993. if (!this.hasHorizontalScroll) {
  3994. this.maxScrollX = 0;
  3995. this.scrollerWidth = this.wrapperWidth;
  3996. }
  3997. if (!this.hasVerticalScroll) {
  3998. this.maxScrollY = 0;
  3999. this.scrollerHeight = this.wrapperHeight;
  4000. }
  4001. this.indicators.map(function(indicator) {
  4002. indicator.refresh();
  4003. });
  4004. //以防slider类嵌套使用
  4005. if (this.options.snap && typeof this.options.snap === 'string') {
  4006. var items = this.scroller.querySelectorAll(this.options.snap);
  4007. this.itemLength = 0;
  4008. this.snaps = [];
  4009. for (var i = 0, len = items.length; i < len; i++) {
  4010. var item = items[i];
  4011. if (item.parentNode === this.scroller) {
  4012. this.itemLength++;
  4013. this.snaps.push(item);
  4014. }
  4015. }
  4016. this._initSnap(); //需要每次都_initSnap么。其实init的时候执行一次,后续resize的时候执行一次就行了吧.先这么做吧,如果影响性能,再调整
  4017. }
  4018. },
  4019. _momentum: function(current, distance, time, lowerMargin, wrapperSize, deceleration) {
  4020. var speed = parseFloat(Math.abs(distance) / time),
  4021. destination,
  4022. duration;
  4023. deceleration = deceleration === undefined ? 0.0006 : deceleration;
  4024. destination = current + (speed * speed) / (2 * deceleration) * (distance < 0 ? -1 : 1);
  4025. duration = speed / deceleration;
  4026. if (destination < lowerMargin) {
  4027. destination = wrapperSize ? lowerMargin - (wrapperSize / 2.5 * (speed / 8)) : lowerMargin;
  4028. distance = Math.abs(destination - current);
  4029. duration = distance / speed;
  4030. } else if (destination > 0) {
  4031. destination = wrapperSize ? wrapperSize / 2.5 * (speed / 8) : 0;
  4032. distance = Math.abs(current) + destination;
  4033. duration = distance / speed;
  4034. }
  4035. return {
  4036. destination: Math.round(destination),
  4037. duration: duration
  4038. };
  4039. },
  4040. _getTranslateStr: function(x, y) {
  4041. if (this.options.hardwareAccelerated) {
  4042. return 'translate3d(' + x + 'px,' + y + 'px,0px) ' + this.translateZ;
  4043. }
  4044. return 'translate(' + x + 'px,' + y + 'px) ';
  4045. },
  4046. //API
  4047. setStopped: function(stopped) {
  4048. this.stopped = !!stopped;
  4049. },
  4050. setTranslate: function(x, y) {
  4051. this.x = x;
  4052. this.y = y;
  4053. this.scrollerStyle['webkitTransform'] = this._getTranslateStr(x, y);
  4054. if (this.parallaxElement && this.options.scrollY) { //目前仅支持竖向视差效果
  4055. var parallaxY = y * this.options.parallaxRatio;
  4056. var scale = 1 + parallaxY / ((this.parallaxHeight - parallaxY) / 2);
  4057. if (scale > 1) {
  4058. this.parallaxImgStyle['opacity'] = 1 - parallaxY / 100 * this.options.parallaxRatio;
  4059. this.parallaxStyle['webkitTransform'] = this._getTranslateStr(0, -parallaxY) + ' scale(' + scale + ',' + scale + ')';
  4060. } else {
  4061. this.parallaxImgStyle['opacity'] = 1;
  4062. this.parallaxStyle['webkitTransform'] = this._getTranslateStr(0, -1) + ' scale(1,1)';
  4063. }
  4064. }
  4065. if (this.indicators) {
  4066. for (var i = this.indicators.length; i--;) {
  4067. this.indicators[i].updatePosition();
  4068. }
  4069. }
  4070. this.lastX = this.x;
  4071. this.lastY = this.y;
  4072. $.trigger(this.scroller, 'scroll', this);
  4073. },
  4074. reLayout: function() {
  4075. this.wrapper.offsetHeight;
  4076. var paddingLeft = parseFloat($.getStyles(this.wrapper, 'padding-left')) || 0;
  4077. var paddingRight = parseFloat($.getStyles(this.wrapper, 'padding-right')) || 0;
  4078. var paddingTop = parseFloat($.getStyles(this.wrapper, 'padding-top')) || 0;
  4079. var paddingBottom = parseFloat($.getStyles(this.wrapper, 'padding-bottom')) || 0;
  4080. var clientWidth = this.wrapper.clientWidth;
  4081. var clientHeight = this.wrapper.clientHeight;
  4082. this.scrollerWidth = this.scroller.offsetWidth;
  4083. this.scrollerHeight = this.scroller.offsetHeight;
  4084. this.wrapperWidth = clientWidth - paddingLeft - paddingRight;
  4085. this.wrapperHeight = clientHeight - paddingTop - paddingBottom;
  4086. this.maxScrollX = Math.min(this.wrapperWidth - this.scrollerWidth, 0);
  4087. this.maxScrollY = Math.min(this.wrapperHeight - this.scrollerHeight, 0);
  4088. this.hasHorizontalScroll = this.options.scrollX && this.maxScrollX < 0;
  4089. this.hasVerticalScroll = this.options.scrollY && this.maxScrollY < 0;
  4090. this._reLayout();
  4091. },
  4092. resetPosition: function(time) {
  4093. var x = this.x,
  4094. y = this.y;
  4095. time = time || 0;
  4096. if (!this.hasHorizontalScroll || this.x > 0) {
  4097. x = 0;
  4098. } else if (this.x < this.maxScrollX) {
  4099. x = this.maxScrollX;
  4100. }
  4101. if (!this.hasVerticalScroll || this.y > 0) {
  4102. y = 0;
  4103. } else if (this.y < this.maxScrollY) {
  4104. y = this.maxScrollY;
  4105. }
  4106. if (x == this.x && y == this.y) {
  4107. return false;
  4108. }
  4109. this.scrollTo(x, y, time, this.options.scrollEasing);
  4110. return true;
  4111. },
  4112. _reInit: function() {
  4113. var groups = this.wrapper.querySelectorAll('.' + CLASS_SCROLL);
  4114. for (var i = 0, len = groups.length; i < len; i++) {
  4115. if (groups[i].parentNode === this.wrapper) {
  4116. this.scroller = groups[i];
  4117. break;
  4118. }
  4119. }
  4120. this.scrollerStyle = this.scroller && this.scroller.style;
  4121. },
  4122. refresh: function() {
  4123. this._reInit();
  4124. this.reLayout();
  4125. $.trigger(this.scroller, 'refresh', this);
  4126. this.resetPosition();
  4127. },
  4128. scrollTo: function(x, y, time, easing) {
  4129. var easing = easing || ease.circular;
  4130. // this.isInTransition = time > 0 && (this.lastX != x || this.lastY != y);
  4131. //暂不严格判断x,y,否则会导致部分版本上不正常触发轮播
  4132. this.isInTransition = time > 0;
  4133. if (this.isInTransition) {
  4134. this._clearRequestAnimationFrame();
  4135. this._transitionTimingFunction(easing.style);
  4136. this._transitionTime(time);
  4137. this.setTranslate(x, y);
  4138. } else {
  4139. this.setTranslate(x, y);
  4140. }
  4141. },
  4142. scrollToBottom: function(time, easing) {
  4143. time = time || this.options.scrollTime;
  4144. this.scrollTo(0, this.maxScrollY, time, easing);
  4145. },
  4146. gotoPage: function(index) {
  4147. this._gotoPage(index);
  4148. },
  4149. destroy: function() {
  4150. this._initEvent(true); //detach
  4151. delete $.data[this.wrapper.getAttribute('data-scroll')];
  4152. this.wrapper.setAttribute('data-scroll', '');
  4153. }
  4154. });
  4155. //Indicator
  4156. var Indicator = function(scroller, options) {
  4157. this.wrapper = typeof options.el == 'string' ? document.querySelector(options.el) : options.el;
  4158. this.wrapperStyle = this.wrapper.style;
  4159. this.indicator = this.wrapper.children[0];
  4160. this.indicatorStyle = this.indicator.style;
  4161. this.scroller = scroller;
  4162. this.options = $.extend({
  4163. listenX: true,
  4164. listenY: true,
  4165. fade: false,
  4166. speedRatioX: 0,
  4167. speedRatioY: 0
  4168. }, options);
  4169. this.sizeRatioX = 1;
  4170. this.sizeRatioY = 1;
  4171. this.maxPosX = 0;
  4172. this.maxPosY = 0;
  4173. if (this.options.fade) {
  4174. this.wrapperStyle['webkitTransform'] = this.scroller.translateZ;
  4175. this.wrapperStyle['webkitTransitionDuration'] = this.options.fixedBadAndorid && $.os.isBadAndroid ? '0.001s' : '0ms';
  4176. this.wrapperStyle.opacity = '0';
  4177. }
  4178. }
  4179. Indicator.prototype = {
  4180. handleEvent: function(e) {
  4181. },
  4182. transitionTime: function(time) {
  4183. time = time || 0;
  4184. this.indicatorStyle['webkitTransitionDuration'] = time + 'ms';
  4185. if (this.scroller.options.fixedBadAndorid && !time && $.os.isBadAndroid) {
  4186. this.indicatorStyle['webkitTransitionDuration'] = '0.001s';
  4187. }
  4188. },
  4189. transitionTimingFunction: function(easing) {
  4190. this.indicatorStyle['webkitTransitionTimingFunction'] = easing;
  4191. },
  4192. refresh: function() {
  4193. this.transitionTime();
  4194. if (this.options.listenX && !this.options.listenY) {
  4195. this.indicatorStyle.display = this.scroller.hasHorizontalScroll ? 'block' : 'none';
  4196. } else if (this.options.listenY && !this.options.listenX) {
  4197. this.indicatorStyle.display = this.scroller.hasVerticalScroll ? 'block' : 'none';
  4198. } else {
  4199. this.indicatorStyle.display = this.scroller.hasHorizontalScroll || this.scroller.hasVerticalScroll ? 'block' : 'none';
  4200. }
  4201. this.wrapper.offsetHeight; // force refresh
  4202. if (this.options.listenX) {
  4203. this.wrapperWidth = this.wrapper.clientWidth;
  4204. this.indicatorWidth = Math.max(Math.round(this.wrapperWidth * this.wrapperWidth / (this.scroller.scrollerWidth || this.wrapperWidth || 1)), 8);
  4205. this.indicatorStyle.width = this.indicatorWidth + 'px';
  4206. this.maxPosX = this.wrapperWidth - this.indicatorWidth;
  4207. this.minBoundaryX = 0;
  4208. this.maxBoundaryX = this.maxPosX;
  4209. this.sizeRatioX = this.options.speedRatioX || (this.scroller.maxScrollX && (this.maxPosX / this.scroller.maxScrollX));
  4210. }
  4211. if (this.options.listenY) {
  4212. this.wrapperHeight = this.wrapper.clientHeight;
  4213. this.indicatorHeight = Math.max(Math.round(this.wrapperHeight * this.wrapperHeight / (this.scroller.scrollerHeight || this.wrapperHeight || 1)), 8);
  4214. this.indicatorStyle.height = this.indicatorHeight + 'px';
  4215. this.maxPosY = this.wrapperHeight - this.indicatorHeight;
  4216. this.minBoundaryY = 0;
  4217. this.maxBoundaryY = this.maxPosY;
  4218. this.sizeRatioY = this.options.speedRatioY || (this.scroller.maxScrollY && (this.maxPosY / this.scroller.maxScrollY));
  4219. }
  4220. this.updatePosition();
  4221. },
  4222. updatePosition: function() {
  4223. var x = this.options.listenX && Math.round(this.sizeRatioX * this.scroller.x) || 0,
  4224. y = this.options.listenY && Math.round(this.sizeRatioY * this.scroller.y) || 0;
  4225. if (x < this.minBoundaryX) {
  4226. this.width = Math.max(this.indicatorWidth + x, 8);
  4227. this.indicatorStyle.width = this.width + 'px';
  4228. x = this.minBoundaryX;
  4229. } else if (x > this.maxBoundaryX) {
  4230. this.width = Math.max(this.indicatorWidth - (x - this.maxPosX), 8);
  4231. this.indicatorStyle.width = this.width + 'px';
  4232. x = this.maxPosX + this.indicatorWidth - this.width;
  4233. } else if (this.width != this.indicatorWidth) {
  4234. this.width = this.indicatorWidth;
  4235. this.indicatorStyle.width = this.width + 'px';
  4236. }
  4237. if (y < this.minBoundaryY) {
  4238. this.height = Math.max(this.indicatorHeight + y * 3, 8);
  4239. this.indicatorStyle.height = this.height + 'px';
  4240. y = this.minBoundaryY;
  4241. } else if (y > this.maxBoundaryY) {
  4242. this.height = Math.max(this.indicatorHeight - (y - this.maxPosY) * 3, 8);
  4243. this.indicatorStyle.height = this.height + 'px';
  4244. y = this.maxPosY + this.indicatorHeight - this.height;
  4245. } else if (this.height != this.indicatorHeight) {
  4246. this.height = this.indicatorHeight;
  4247. this.indicatorStyle.height = this.height + 'px';
  4248. }
  4249. this.x = x;
  4250. this.y = y;
  4251. this.indicatorStyle['webkitTransform'] = this.scroller._getTranslateStr(x, y);
  4252. },
  4253. fade: function(val, hold) {
  4254. if (hold && !this.visible) {
  4255. return;
  4256. }
  4257. clearTimeout(this.fadeTimeout);
  4258. this.fadeTimeout = null;
  4259. var time = val ? 250 : 500,
  4260. delay = val ? 0 : 300;
  4261. val = val ? '1' : '0';
  4262. this.wrapperStyle['webkitTransitionDuration'] = time + 'ms';
  4263. this.fadeTimeout = setTimeout((function(val) {
  4264. this.wrapperStyle.opacity = val;
  4265. this.visible = +val;
  4266. }).bind(this, val), delay);
  4267. }
  4268. };
  4269. $.Scroll = Scroll;
  4270. $.fn.scroll = function(options) {
  4271. var scrollApis = [];
  4272. this.each(function() {
  4273. var scrollApi = null;
  4274. var self = this;
  4275. var id = self.getAttribute('data-scroll');
  4276. if (!id) {
  4277. id = ++$.uuid;
  4278. var _options = $.extend({}, options);
  4279. if (self.classList.contains('mui-segmented-control')) {
  4280. _options = $.extend(_options, {
  4281. scrollY: false,
  4282. scrollX: true,
  4283. indicators: false,
  4284. snap: '.mui-control-item'
  4285. });
  4286. }
  4287. $.data[id] = scrollApi = new Scroll(self, _options);
  4288. self.setAttribute('data-scroll', id);
  4289. } else {
  4290. scrollApi = $.data[id];
  4291. }
  4292. scrollApis.push(scrollApi);
  4293. });
  4294. return scrollApis.length === 1 ? scrollApis[0] : scrollApis;
  4295. };
  4296. })(mui, window, document);
  4297. (function($, window, document, undefined) {
  4298. var CLASS_VISIBILITY = 'mui-visibility';
  4299. var CLASS_HIDDEN = 'mui-hidden';
  4300. var PullRefresh = $.Scroll.extend($.extend({
  4301. handleEvent: function(e) {
  4302. this._super(e);
  4303. if (e.type === 'scrollbottom') {
  4304. if (e.target === this.scroller) {
  4305. this._scrollbottom();
  4306. }
  4307. }
  4308. },
  4309. _scrollbottom: function() {
  4310. if (!this.pulldown && !this.loading) {
  4311. this.pulldown = false;
  4312. this._initPullupRefresh();
  4313. this.pullupLoading();
  4314. }
  4315. },
  4316. _start: function(e) {
  4317. //仅下拉刷新在start阻止默认事件
  4318. if (e.touches && e.touches.length && e.touches[0].clientX > 30) {
  4319. e.target && !this._preventDefaultException(e.target, this.options.preventDefaultException) && e.preventDefault();
  4320. }
  4321. if (!this.loading) {
  4322. this.pulldown = this.pullPocket = this.pullCaption = this.pullLoading = false
  4323. }
  4324. this._super(e);
  4325. },
  4326. _drag: function(e) {
  4327. this._super(e);
  4328. if (!this.pulldown && !this.loading && this.topPocket && e.detail.direction === 'down' && this.y >= 0) {
  4329. this._initPulldownRefresh();
  4330. }
  4331. if (this.pulldown) {
  4332. this._setCaption(this.y > this.options.down.height ? this.options.down.contentover : this.options.down.contentdown);
  4333. }
  4334. },
  4335. _reLayout: function() {
  4336. this.hasVerticalScroll = true;
  4337. this._super();
  4338. },
  4339. //API
  4340. resetPosition: function(time) {
  4341. if (this.pulldown) {
  4342. if (this.y >= this.options.down.height) {
  4343. this.pulldownLoading(undefined, time || 0);
  4344. return true;
  4345. } else {
  4346. !this.loading && this.topPocket.classList.remove(CLASS_VISIBILITY);
  4347. }
  4348. }
  4349. return this._super(time);
  4350. },
  4351. pulldownLoading: function(y, time) {
  4352. typeof y === 'undefined' && (y = this.options.down.height); //默认高度
  4353. this.scrollTo(0, y, time, this.options.bounceEasing);
  4354. if (this.loading) {
  4355. return;
  4356. }
  4357. // if (!this.pulldown) {
  4358. this._initPulldownRefresh();
  4359. // }
  4360. this._setCaption(this.options.down.contentrefresh);
  4361. this.loading = true;
  4362. this.indicators.map(function(indicator) {
  4363. indicator.fade(0);
  4364. });
  4365. var callback = this.options.down.callback;
  4366. callback && callback.call(this);
  4367. },
  4368. endPulldownToRefresh: function() {
  4369. var self = this;
  4370. if (self.topPocket && self.loading && this.pulldown) {
  4371. self.scrollTo(0, 0, self.options.bounceTime, self.options.bounceEasing);
  4372. self.loading = false;
  4373. self._setCaption(self.options.down.contentdown, true);
  4374. setTimeout(function() {
  4375. self.loading || self.topPocket.classList.remove(CLASS_VISIBILITY);
  4376. }, 350);
  4377. }
  4378. },
  4379. pullupLoading: function(callback, x, time) {
  4380. x = x || 0;
  4381. this.scrollTo(x, this.maxScrollY, time, this.options.bounceEasing);
  4382. if (this.loading) {
  4383. return;
  4384. }
  4385. this._initPullupRefresh();
  4386. this._setCaption(this.options.up.contentrefresh);
  4387. this.indicators.map(function(indicator) {
  4388. indicator.fade(0);
  4389. });
  4390. this.loading = true;
  4391. callback = callback || this.options.up.callback;
  4392. callback && callback.call(this);
  4393. },
  4394. endPullupToRefresh: function(finished) {
  4395. var self = this;
  4396. if (self.bottomPocket) { // && self.loading && !this.pulldown
  4397. self.loading = false;
  4398. if (finished) {
  4399. this.finished = true;
  4400. self._setCaption(self.options.up.contentnomore);
  4401. // self.bottomPocket.classList.remove(CLASS_VISIBILITY);
  4402. // self.bottomPocket.classList.add(CLASS_HIDDEN);
  4403. self.wrapper.removeEventListener('scrollbottom', self);
  4404. } else {
  4405. self._setCaption(self.options.up.contentdown);
  4406. // setTimeout(function() {
  4407. self.loading || self.bottomPocket.classList.remove(CLASS_VISIBILITY);
  4408. // }, 300);
  4409. }
  4410. }
  4411. },
  4412. disablePullupToRefresh: function() {
  4413. this._initPullupRefresh();
  4414. this.bottomPocket.className = 'mui-pull-bottom-pocket' + ' ' + CLASS_HIDDEN;
  4415. this.wrapper.removeEventListener('scrollbottom', this);
  4416. },
  4417. enablePullupToRefresh: function() {
  4418. this._initPullupRefresh();
  4419. this.bottomPocket.classList.remove(CLASS_HIDDEN);
  4420. this._setCaption(this.options.up.contentdown);
  4421. this.wrapper.addEventListener('scrollbottom', this);
  4422. },
  4423. refresh: function(isReset) {
  4424. if (isReset && this.finished) {
  4425. this.enablePullupToRefresh();
  4426. this.finished = false;
  4427. }
  4428. this._super();
  4429. },
  4430. }, $.PullRefresh));
  4431. $.fn.pullRefresh = function(options) {
  4432. if (this.length === 1) {
  4433. var self = this[0];
  4434. var pullRefreshApi = null;
  4435. options = options || {};
  4436. var id = self.getAttribute('data-pullrefresh');
  4437. if (!id) {
  4438. id = ++$.uuid;
  4439. $.data[id] = pullRefreshApi = new PullRefresh(self, options);
  4440. self.setAttribute('data-pullrefresh', id);
  4441. } else {
  4442. pullRefreshApi = $.data[id];
  4443. }
  4444. if (options.down && options.down.auto) { //如果设置了auto,则自动下拉一次
  4445. pullRefreshApi.pulldownLoading(options.down.autoY);
  4446. } else if (options.up && options.up.auto) { //如果设置了auto,则自动上拉一次
  4447. pullRefreshApi.pullupLoading();
  4448. }
  4449. //暂不提供这种调用方式吧
  4450. // if (typeof options === 'string') {
  4451. // var methodValue = pullRefreshApi[options].apply(pullRefreshApi, $.slice.call(arguments, 1));
  4452. // if (methodValue !== undefined) {
  4453. // return methodValue;
  4454. // }
  4455. // }
  4456. return pullRefreshApi;
  4457. }
  4458. };
  4459. })(mui, window, document);
  4460. /**
  4461. * snap 重构
  4462. * @param {Object} $
  4463. * @param {Object} window
  4464. */
  4465. (function($, window) {
  4466. var CLASS_SLIDER = 'mui-slider';
  4467. var CLASS_SLIDER_GROUP = 'mui-slider-group';
  4468. var CLASS_SLIDER_LOOP = 'mui-slider-loop';
  4469. var CLASS_SLIDER_INDICATOR = 'mui-slider-indicator';
  4470. var CLASS_ACTION_PREVIOUS = 'mui-action-previous';
  4471. var CLASS_ACTION_NEXT = 'mui-action-next';
  4472. var CLASS_SLIDER_ITEM = 'mui-slider-item';
  4473. var CLASS_ACTIVE = 'mui-active';
  4474. var SELECTOR_SLIDER_ITEM = '.' + CLASS_SLIDER_ITEM;
  4475. var SELECTOR_SLIDER_INDICATOR = '.' + CLASS_SLIDER_INDICATOR;
  4476. var SELECTOR_SLIDER_PROGRESS_BAR = '.mui-slider-progress-bar';
  4477. var Slider = $.Slider = $.Scroll.extend({
  4478. init: function(element, options) {
  4479. this._super(element, $.extend(true, {
  4480. fingers: 1,
  4481. interval: 0, //设置为0,则不定时轮播
  4482. scrollY: false,
  4483. scrollX: true,
  4484. indicators: false,
  4485. scrollTime: 1000,
  4486. startX: false,
  4487. slideTime: 0, //滑动动画时间
  4488. snap: SELECTOR_SLIDER_ITEM
  4489. }, options));
  4490. if (this.options.startX) {
  4491. // $.trigger(this.wrapper, 'scrollend', this);
  4492. }
  4493. },
  4494. _init: function() {
  4495. this._reInit();
  4496. if (this.scroller) {
  4497. this.scrollerStyle = this.scroller.style;
  4498. this.progressBar = this.wrapper.querySelector(SELECTOR_SLIDER_PROGRESS_BAR);
  4499. if (this.progressBar) {
  4500. this.progressBarWidth = this.progressBar.offsetWidth;
  4501. this.progressBarStyle = this.progressBar.style;
  4502. }
  4503. //忘记这个代码是干什么的了?
  4504. // this.x = this._getScroll();
  4505. // if (this.options.startX === false) {
  4506. // this.options.startX = this.x;
  4507. // }
  4508. //根据active修正startX
  4509. this._super();
  4510. this._initTimer();
  4511. }
  4512. },
  4513. _triggerSlide: function() {
  4514. var self = this;
  4515. self.isInTransition = false;
  4516. var page = self.currentPage;
  4517. self.slideNumber = self._fixedSlideNumber();
  4518. if (self.loop) {
  4519. if (self.slideNumber === 0) {
  4520. self.setTranslate(self.pages[1][0].x, 0);
  4521. } else if (self.slideNumber === self.itemLength - 3) {
  4522. self.setTranslate(self.pages[self.itemLength - 2][0].x, 0);
  4523. }
  4524. }
  4525. if (self.lastSlideNumber != self.slideNumber) {
  4526. self.lastSlideNumber = self.slideNumber;
  4527. self.lastPage = self.currentPage;
  4528. $.trigger(self.wrapper, 'slide', {
  4529. slideNumber: self.slideNumber
  4530. });
  4531. }
  4532. self._initTimer();
  4533. },
  4534. _handleSlide: function(e) {
  4535. var self = this;
  4536. if (e.target !== self.wrapper) {
  4537. return;
  4538. }
  4539. var detail = e.detail;
  4540. detail.slideNumber = detail.slideNumber || 0;
  4541. var temps = self.scroller.querySelectorAll(SELECTOR_SLIDER_ITEM);
  4542. var items = [];
  4543. for (var i = 0, len = temps.length; i < len; i++) {
  4544. var item = temps[i];
  4545. if (item.parentNode === self.scroller) {
  4546. items.push(item);
  4547. }
  4548. }
  4549. var _slideNumber = detail.slideNumber;
  4550. if (self.loop) {
  4551. _slideNumber += 1;
  4552. }
  4553. if (!self.wrapper.classList.contains('mui-segmented-control')) {
  4554. for (var i = 0, len = items.length; i < len; i++) {
  4555. var item = items[i];
  4556. if (item.parentNode === self.scroller) {
  4557. if (i === _slideNumber) {
  4558. item.classList.add(CLASS_ACTIVE);
  4559. } else {
  4560. item.classList.remove(CLASS_ACTIVE);
  4561. }
  4562. }
  4563. }
  4564. }
  4565. var indicatorWrap = self.wrapper.querySelector('.mui-slider-indicator');
  4566. if (indicatorWrap) {
  4567. if (indicatorWrap.getAttribute('data-scroll')) { //scroll
  4568. $(indicatorWrap).scroll().gotoPage(detail.slideNumber);
  4569. }
  4570. var indicators = indicatorWrap.querySelectorAll('.mui-indicator');
  4571. if (indicators.length > 0) { //图片轮播
  4572. for (var i = 0, len = indicators.length; i < len; i++) {
  4573. indicators[i].classList[i === detail.slideNumber ? 'add' : 'remove'](CLASS_ACTIVE);
  4574. }
  4575. } else {
  4576. var number = indicatorWrap.querySelector('.mui-number span');
  4577. if (number) { //图文表格
  4578. number.innerText = (detail.slideNumber + 1);
  4579. } else { //segmented controls
  4580. var controlItems = indicatorWrap.querySelectorAll('.mui-control-item');
  4581. for (var i = 0, len = controlItems.length; i < len; i++) {
  4582. controlItems[i].classList[i === detail.slideNumber ? 'add' : 'remove'](CLASS_ACTIVE);
  4583. }
  4584. }
  4585. }
  4586. }
  4587. e.stopPropagation();
  4588. },
  4589. _handleTabShow: function(e) {
  4590. var self = this;
  4591. self.gotoItem((e.detail.tabNumber || 0), self.options.slideTime);
  4592. },
  4593. _handleIndicatorTap: function(event) {
  4594. var self = this;
  4595. var target = event.target;
  4596. if (target.classList.contains(CLASS_ACTION_PREVIOUS) || target.classList.contains(CLASS_ACTION_NEXT)) {
  4597. self[target.classList.contains(CLASS_ACTION_PREVIOUS) ? 'prevItem' : 'nextItem']();
  4598. event.stopPropagation();
  4599. }
  4600. },
  4601. _initEvent: function(detach) {
  4602. var self = this;
  4603. self._super(detach);
  4604. var action = detach ? 'removeEventListener' : 'addEventListener';
  4605. self.wrapper[action]('slide', this);
  4606. self.wrapper[action]($.eventName('shown', 'tab'), this);
  4607. },
  4608. handleEvent: function(e) {
  4609. this._super(e);
  4610. switch (e.type) {
  4611. case 'slide':
  4612. this._handleSlide(e);
  4613. break;
  4614. case $.eventName('shown', 'tab'):
  4615. if (~this.snaps.indexOf(e.target)) { //避免嵌套监听错误的tab show
  4616. this._handleTabShow(e);
  4617. }
  4618. break;
  4619. }
  4620. },
  4621. _scrollend: function(e) {
  4622. this._super(e);
  4623. this._triggerSlide(e);
  4624. },
  4625. _drag: function(e) {
  4626. this._super(e);
  4627. var direction = e.detail.direction;
  4628. if (direction === 'left' || direction === 'right') {
  4629. //拖拽期间取消定时
  4630. var slidershowTimer = this.wrapper.getAttribute('data-slidershowTimer');
  4631. slidershowTimer && window.clearTimeout(slidershowTimer);
  4632. e.stopPropagation();
  4633. }
  4634. },
  4635. _initTimer: function() {
  4636. var self = this;
  4637. var slider = self.wrapper;
  4638. var interval = self.options.interval;
  4639. var slidershowTimer = slider.getAttribute('data-slidershowTimer');
  4640. slidershowTimer && window.clearTimeout(slidershowTimer);
  4641. if (interval) {
  4642. slidershowTimer = window.setTimeout(function() {
  4643. if (!slider) {
  4644. return;
  4645. }
  4646. //仅slider显示状态进行自动轮播
  4647. if (!!(slider.offsetWidth || slider.offsetHeight)) {
  4648. self.nextItem(true);
  4649. //下一个
  4650. }
  4651. self._initTimer();
  4652. }, interval);
  4653. slider.setAttribute('data-slidershowTimer', slidershowTimer);
  4654. }
  4655. },
  4656. _fixedSlideNumber: function(page) {
  4657. page = page || this.currentPage;
  4658. var slideNumber = page.pageX;
  4659. if (this.loop) {
  4660. if (page.pageX === 0) {
  4661. slideNumber = this.itemLength - 3;
  4662. } else if (page.pageX === (this.itemLength - 1)) {
  4663. slideNumber = 0;
  4664. } else {
  4665. slideNumber = page.pageX - 1;
  4666. }
  4667. }
  4668. return slideNumber;
  4669. },
  4670. _reLayout: function() {
  4671. this.hasHorizontalScroll = true;
  4672. this.loop = this.scroller.classList.contains(CLASS_SLIDER_LOOP);
  4673. this._super();
  4674. },
  4675. _getScroll: function() {
  4676. var result = $.parseTranslateMatrix($.getStyles(this.scroller, 'webkitTransform'));
  4677. return result ? result.x : 0;
  4678. },
  4679. _transitionEnd: function(e) {
  4680. if (e.target !== this.scroller || !this.isInTransition) {
  4681. return;
  4682. }
  4683. this._transitionTime();
  4684. this.isInTransition = false;
  4685. $.trigger(this.wrapper, 'scrollend', this);
  4686. },
  4687. _flick: function(e) {
  4688. if (!this.moved) { //无moved
  4689. return;
  4690. }
  4691. var detail = e.detail;
  4692. var direction = detail.direction;
  4693. this._clearRequestAnimationFrame();
  4694. this.isInTransition = true;
  4695. // if (direction === 'up' || direction === 'down') {
  4696. // this.resetPosition(this.options.bounceTime);
  4697. // return;
  4698. // }
  4699. if (e.type === 'flick') {
  4700. if (detail.deltaTime < 200) { //flick,太容易触发,额外校验一下deltaTime
  4701. this.x = this._getPage((this.slideNumber + (direction === 'right' ? -1 : 1)), true).x;
  4702. }
  4703. this.resetPosition(this.options.bounceTime);
  4704. } else if (e.type === 'dragend' && !detail.flick) {
  4705. this.resetPosition(this.options.bounceTime);
  4706. }
  4707. e.stopPropagation();
  4708. },
  4709. _initSnap: function() {
  4710. this.scrollerWidth = this.itemLength * this.scrollerWidth;
  4711. this.maxScrollX = Math.min(this.wrapperWidth - this.scrollerWidth, 0);
  4712. this._super();
  4713. if (!this.currentPage.x) {
  4714. //当slider处于隐藏状态时,导致snap计算是错误的,临时先这么判断一下,后续要考虑解决所有scroll在隐藏状态下初始化属性不正确的问题
  4715. var currentPage = this.pages[this.loop ? 1 : 0];
  4716. currentPage = currentPage || this.pages[0];
  4717. if (!currentPage) {
  4718. return;
  4719. }
  4720. this.currentPage = currentPage[0];
  4721. this.slideNumber = 0;
  4722. this.lastSlideNumber = typeof this.lastSlideNumber === 'undefined' ? 0 : this.lastSlideNumber;
  4723. } else {
  4724. this.slideNumber = this._fixedSlideNumber();
  4725. this.lastSlideNumber = typeof this.lastSlideNumber === 'undefined' ? this.slideNumber : this.lastSlideNumber;
  4726. }
  4727. this.options.startX = this.currentPage.x || 0;
  4728. },
  4729. _getSnapX: function(offsetLeft) {
  4730. return Math.max(-offsetLeft, this.maxScrollX);
  4731. },
  4732. _getPage: function(slideNumber, isFlick) {
  4733. if (this.loop) {
  4734. if (slideNumber > (this.itemLength - (isFlick ? 2 : 3))) {
  4735. slideNumber = 1;
  4736. time = 0;
  4737. } else if (slideNumber < (isFlick ? -1 : 0)) {
  4738. slideNumber = this.itemLength - 2;
  4739. time = 0;
  4740. } else {
  4741. slideNumber += 1;
  4742. }
  4743. } else {
  4744. if (!isFlick) {
  4745. if (slideNumber > (this.itemLength - 1)) {
  4746. slideNumber = 0;
  4747. time = 0;
  4748. } else if (slideNumber < 0) {
  4749. slideNumber = this.itemLength - 1;
  4750. time = 0;
  4751. }
  4752. }
  4753. slideNumber = Math.min(Math.max(0, slideNumber), this.itemLength - 1);
  4754. }
  4755. return this.pages[slideNumber][0];
  4756. },
  4757. _gotoItem: function(slideNumber, time) {
  4758. this.currentPage = this._getPage(slideNumber, true); //此处传true。可保证程序切换时,动画与人手操作一致(第一张,最后一张的切换动画)
  4759. this.scrollTo(this.currentPage.x, 0, time, this.options.scrollEasing);
  4760. if (time === 0) {
  4761. $.trigger(this.wrapper, 'scrollend', this);
  4762. }
  4763. },
  4764. //API
  4765. setTranslate: function(x, y) {
  4766. this._super(x, y);
  4767. var progressBar = this.progressBar;
  4768. if (progressBar) {
  4769. this.progressBarStyle.webkitTransform = this._getTranslateStr((-x * (this.progressBarWidth / this.wrapperWidth)), 0);
  4770. }
  4771. },
  4772. resetPosition: function(time) {
  4773. time = time || 0;
  4774. if (this.x > 0) {
  4775. this.x = 0;
  4776. } else if (this.x < this.maxScrollX) {
  4777. this.x = this.maxScrollX;
  4778. }
  4779. this.currentPage = this._nearestSnap(this.x);
  4780. this.scrollTo(this.currentPage.x, 0, time, this.options.scrollEasing);
  4781. return true;
  4782. },
  4783. gotoItem: function(slideNumber, time) {
  4784. this._gotoItem(slideNumber, typeof time === 'undefined' ? this.options.scrollTime : time);
  4785. },
  4786. nextItem: function() {
  4787. this._gotoItem(this.slideNumber + 1, this.options.scrollTime);
  4788. },
  4789. prevItem: function() {
  4790. this._gotoItem(this.slideNumber - 1, this.options.scrollTime);
  4791. },
  4792. getSlideNumber: function() {
  4793. return this.slideNumber || 0;
  4794. },
  4795. _reInit: function() {
  4796. var groups = this.wrapper.querySelectorAll('.' + CLASS_SLIDER_GROUP);
  4797. for (var i = 0, len = groups.length; i < len; i++) {
  4798. if (groups[i].parentNode === this.wrapper) {
  4799. this.scroller = groups[i];
  4800. break;
  4801. }
  4802. }
  4803. this.scrollerStyle = this.scroller && this.scroller.style;
  4804. if (this.progressBar) {
  4805. this.progressBarWidth = this.progressBar.offsetWidth;
  4806. this.progressBarStyle = this.progressBar.style;
  4807. }
  4808. },
  4809. refresh: function(options) {
  4810. if (options) {
  4811. $.extend(this.options, options);
  4812. this._super();
  4813. this._initTimer();
  4814. } else {
  4815. this._super();
  4816. }
  4817. },
  4818. destroy: function() {
  4819. this._initEvent(true); //detach
  4820. delete $.data[this.wrapper.getAttribute('data-slider')];
  4821. this.wrapper.setAttribute('data-slider', '');
  4822. }
  4823. });
  4824. $.fn.slider = function(options) {
  4825. var slider = null;
  4826. this.each(function() {
  4827. var sliderElement = this;
  4828. if (!this.classList.contains(CLASS_SLIDER)) {
  4829. sliderElement = this.querySelector('.' + CLASS_SLIDER);
  4830. }
  4831. if (sliderElement && sliderElement.querySelector(SELECTOR_SLIDER_ITEM)) {
  4832. var id = sliderElement.getAttribute('data-slider');
  4833. if (!id) {
  4834. id = ++$.uuid;
  4835. $.data[id] = slider = new Slider(sliderElement, options);
  4836. sliderElement.setAttribute('data-slider', id);
  4837. } else {
  4838. slider = $.data[id];
  4839. if (slider && options) {
  4840. slider.refresh(options);
  4841. }
  4842. }
  4843. }
  4844. });
  4845. return slider;
  4846. };
  4847. $.ready(function() {
  4848. // setTimeout(function() {
  4849. $('.mui-slider').slider();
  4850. $('.mui-scroll-wrapper.mui-slider-indicator.mui-segmented-control').scroll({
  4851. scrollY: false,
  4852. scrollX: true,
  4853. indicators: false,
  4854. snap: '.mui-control-item'
  4855. });
  4856. // }, 500); //临时处理slider宽度计算不正确的问题(初步确认是scrollbar导致的)
  4857. });
  4858. })(mui, window);
  4859. /**
  4860. * pullRefresh 5+
  4861. * @param {type} $
  4862. * @returns {undefined}
  4863. */
  4864. (function($, document) {
  4865. if (!($.os.plus && $.os.android)) { //仅在5+android支持多webview的使用
  4866. return;
  4867. }
  4868. $.plusReady(function() {
  4869. if (window.__NWin_Enable__ === false) { //不支持多webview,则不用5+下拉刷新
  4870. return;
  4871. }
  4872. var CLASS_PLUS_PULLREFRESH = 'mui-plus-pullrefresh';
  4873. var CLASS_VISIBILITY = 'mui-visibility';
  4874. var CLASS_HIDDEN = 'mui-hidden';
  4875. var CLASS_BLOCK = 'mui-block';
  4876. var CLASS_PULL_CAPTION = 'mui-pull-caption';
  4877. var CLASS_PULL_CAPTION_DOWN = 'mui-pull-caption-down';
  4878. var CLASS_PULL_CAPTION_REFRESH = 'mui-pull-caption-refresh';
  4879. var CLASS_PULL_CAPTION_NOMORE = 'mui-pull-caption-nomore';
  4880. var PlusPullRefresh = $.Class.extend({
  4881. init: function(element, options) {
  4882. this.element = element;
  4883. this.options = options;
  4884. this.wrapper = this.scroller = element;
  4885. this._init();
  4886. this._initPulldownRefreshEvent();
  4887. },
  4888. _init: function() {
  4889. var self = this;
  4890. //document.addEventListener('plusscrollbottom', this);
  4891. window.addEventListener('dragup', self);
  4892. document.addEventListener("plusscrollbottom", self);
  4893. self.scrollInterval = window.setInterval(function() {
  4894. if (self.isScroll && !self.loading) {
  4895. if (window.pageYOffset + window.innerHeight + 10 >= document.documentElement.scrollHeight) {
  4896. self.isScroll = false; //放在这里是因为快速滚动的话,有可能检测时,还没到底,所以只要有滚动,没到底之前一直检测高度变化
  4897. if (self.bottomPocket) {
  4898. self.pullupLoading();
  4899. }
  4900. }
  4901. }
  4902. }, 100);
  4903. },
  4904. _initPulldownRefreshEvent: function() {
  4905. var self = this;
  4906. if (self.topPocket && self.options.webviewId) {
  4907. $.plusReady(function() {
  4908. var webview = plus.webview.getWebviewById(self.options.webviewId);
  4909. if (!webview) {
  4910. return;
  4911. }
  4912. self.options.webview = webview;
  4913. var downOptions = self.options.down;
  4914. var height = downOptions.height;
  4915. webview.addEventListener('close', function() {
  4916. var attrWebviewId = self.options.webviewId && self.options.webviewId.replace(/\//g, "_"); //替换所有"/"
  4917. self.element.removeAttribute('data-pullrefresh-plus-' + attrWebviewId);
  4918. });
  4919. webview.addEventListener("dragBounce", function(e) {
  4920. if (!self.pulldown) {
  4921. self._initPulldownRefresh();
  4922. } else {
  4923. self.pullPocket.classList.add(CLASS_BLOCK);
  4924. }
  4925. switch (e.status) {
  4926. case "beforeChangeOffset": //下拉可刷新状态
  4927. self._setCaption(downOptions.contentdown);
  4928. break;
  4929. case "afterChangeOffset": //松开可刷新状态
  4930. self._setCaption(downOptions.contentover);
  4931. break;
  4932. case "dragEndAfterChangeOffset": //正在刷新状态
  4933. //执行下拉刷新所在webview的回调函数
  4934. webview.evalJS("mui&&mui.options.pullRefresh.down.callback()");
  4935. self._setCaption(downOptions.contentrefresh);
  4936. break;
  4937. default:
  4938. break;
  4939. }
  4940. }, false);
  4941. webview.setBounce({
  4942. position: {
  4943. top: height * 2 + 'px'
  4944. },
  4945. changeoffset: {
  4946. top: height + 'px'
  4947. }
  4948. });
  4949. });
  4950. }
  4951. },
  4952. handleEvent: function(e) {
  4953. var self = this;
  4954. if (self.stopped) {
  4955. return;
  4956. }
  4957. //5+的plusscrollbottom当页面内容较少时,不触发
  4958. // if (e.type === 'plusscrollbottom') {
  4959. // if (this.bottomPocket) {
  4960. // this.pullupLoading();
  4961. // }
  4962. // }
  4963. self.isScroll = false;
  4964. if (e.type === 'dragup' || e.type === 'plusscrollbottom') {
  4965. self.isScroll = true;
  4966. setTimeout(function() {
  4967. self.isScroll = false;
  4968. }, 1000);
  4969. }
  4970. }
  4971. }).extend($.extend({
  4972. setStopped: function(stopped) { //该方法是子页面调用的
  4973. this.stopped = !!stopped;
  4974. //TODO 此处需要设置当前webview的bounce为none,目前5+有BUG
  4975. var webview = plus.webview.currentWebview();
  4976. if (this.stopped) {
  4977. webview.setStyle({
  4978. bounce: 'none'
  4979. });
  4980. webview.setBounce({
  4981. position: {
  4982. top: 'none'
  4983. }
  4984. });
  4985. } else {
  4986. var height = this.options.down.height;
  4987. webview.setStyle({
  4988. bounce: 'vertical'
  4989. });
  4990. webview.setBounce({
  4991. position: {
  4992. top: height * 2 + 'px'
  4993. },
  4994. changeoffset: {
  4995. top: height + 'px'
  4996. }
  4997. });
  4998. }
  4999. },
  5000. pulldownLoading: function() { //该方法是子页面调用的
  5001. $.plusReady(function() {
  5002. plus.webview.currentWebview().setBounce({
  5003. offset: {
  5004. top: this.options.down.height + "px"
  5005. }
  5006. });
  5007. }.bind(this));
  5008. },
  5009. _pulldownLoading: function() { //该方法是父页面调用的
  5010. var self = this;
  5011. $.plusReady(function() {
  5012. var childWebview = plus.webview.getWebviewById(self.options.webviewId);
  5013. childWebview.setBounce({
  5014. offset: {
  5015. top: self.options.down.height + "px"
  5016. }
  5017. });
  5018. });
  5019. },
  5020. endPulldownToRefresh: function() { //该方法是子页面调用的
  5021. var webview = plus.webview.currentWebview();
  5022. webview.parent().evalJS("mui&&mui(document.querySelector('.mui-content')).pullRefresh('" + JSON.stringify({
  5023. webviewId: webview.id
  5024. }) + "')._endPulldownToRefresh()");
  5025. },
  5026. _endPulldownToRefresh: function() { //该方法是父页面调用的
  5027. var self = this;
  5028. if (self.topPocket && self.options.webview) {
  5029. self.options.webview.endPullToRefresh(); //下拉刷新所在webview回弹
  5030. self.loading = false;
  5031. self._setCaption(self.options.down.contentdown, true);
  5032. setTimeout(function() {
  5033. self.loading || self.topPocket.classList.remove(CLASS_BLOCK);
  5034. }, 350);
  5035. }
  5036. },
  5037. pullupLoading: function(callback) {
  5038. var self = this;
  5039. if (self.isLoading) return;
  5040. self.isLoading = true;
  5041. if (self.pulldown !== false) {
  5042. self._initPullupRefresh();
  5043. } else {
  5044. this.pullPocket.classList.add(CLASS_BLOCK);
  5045. }
  5046. setTimeout(function() {
  5047. self.pullLoading.classList.add(CLASS_VISIBILITY);
  5048. self.pullLoading.classList.remove(CLASS_HIDDEN);
  5049. self.pullCaption.innerHTML = ''; //修正5+里边第一次加载时,文字显示的bug(还会显示出来个“多”,猜测应该是渲染问题导致的)
  5050. self.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_REFRESH;
  5051. self.pullCaption.innerHTML = self.options.up.contentrefresh;
  5052. callback = callback || self.options.up.callback;
  5053. callback && callback.call(self);
  5054. }, 300);
  5055. },
  5056. endPullupToRefresh: function(finished) {
  5057. var self = this;
  5058. if (self.pullLoading) {
  5059. self.pullLoading.classList.remove(CLASS_VISIBILITY);
  5060. self.pullLoading.classList.add(CLASS_HIDDEN);
  5061. self.isLoading = false;
  5062. if (finished) {
  5063. self.finished = true;
  5064. self.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_NOMORE;
  5065. self.pullCaption.innerHTML = self.options.up.contentnomore;
  5066. // self.bottomPocket.classList.remove(CLASS_BLOCK);
  5067. // self.bottomPocket.classList.add(CLASS_HIDDEN);
  5068. //取消5+的plusscrollbottom事件
  5069. document.removeEventListener('plusscrollbottom', self);
  5070. window.removeEventListener('dragup', self);
  5071. } else { //初始化时隐藏,后续不再隐藏
  5072. self.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_DOWN;
  5073. self.pullCaption.innerHTML = self.options.up.contentdown;
  5074. // setTimeout(function() {
  5075. // self.loading || self.bottomPocket.classList.remove(CLASS_BLOCK);
  5076. // }, 350);
  5077. }
  5078. }
  5079. },
  5080. disablePullupToRefresh: function() {
  5081. this._initPullupRefresh();
  5082. this.bottomPocket.className = 'mui-pull-bottom-pocket' + ' ' + CLASS_HIDDEN;
  5083. window.removeEventListener('dragup', this);
  5084. },
  5085. enablePullupToRefresh: function() {
  5086. this._initPullupRefresh();
  5087. this.bottomPocket.classList.remove(CLASS_HIDDEN);
  5088. this.pullCaption.className = CLASS_PULL_CAPTION + ' ' + CLASS_PULL_CAPTION_DOWN;
  5089. this.pullCaption.innerHTML = this.options.up.contentdown;
  5090. document.addEventListener("plusscrollbottom", this);
  5091. window.addEventListener('dragup', this);
  5092. },
  5093. scrollTo: function(x, y, time) {
  5094. $.scrollTo(y, time);
  5095. },
  5096. scrollToBottom: function(time) {
  5097. $.scrollTo(document.documentElement.scrollHeight, time);
  5098. },
  5099. refresh: function(isReset) {
  5100. if (isReset && this.finished) {
  5101. this.enablePullupToRefresh();
  5102. this.finished = false;
  5103. }
  5104. }
  5105. }, $.PullRefresh));
  5106. //override h5 pullRefresh
  5107. $.fn.pullRefresh = function(options) {
  5108. var self;
  5109. if (this.length === 0) {
  5110. self = document.createElement('div');
  5111. self.className = 'mui-content';
  5112. document.body.appendChild(self);
  5113. } else {
  5114. self = this[0];
  5115. }
  5116. var args = options;
  5117. //一个父需要支持多个子下拉刷新
  5118. options = options || {}
  5119. if (typeof options === 'string') {
  5120. options = $.parseJSON(options);
  5121. };
  5122. !options.webviewId && (options.webviewId = (plus.webview.currentWebview().id || plus.webview.currentWebview().getURL()));
  5123. var pullRefreshApi = null;
  5124. var attrWebviewId = options.webviewId && options.webviewId.replace(/\//g, "_"); //替换所有"/"
  5125. var id = self.getAttribute('data-pullrefresh-plus-' + attrWebviewId);
  5126. if (!id && typeof args === 'undefined') {
  5127. return false;
  5128. }
  5129. if (!id) { //避免重复初始化5+ pullrefresh
  5130. id = ++$.uuid;
  5131. self.setAttribute('data-pullrefresh-plus-' + attrWebviewId, id);
  5132. document.body.classList.add(CLASS_PLUS_PULLREFRESH);
  5133. $.data[id] = pullRefreshApi = new PlusPullRefresh(self, options);
  5134. } else {
  5135. pullRefreshApi = $.data[id];
  5136. }
  5137. if (options.down && options.down.auto) { //如果设置了auto,则自动下拉一次
  5138. pullRefreshApi._pulldownLoading(); //parent webview
  5139. } else if (options.up && options.up.auto) { //如果设置了auto,则自动上拉一次
  5140. pullRefreshApi.pullupLoading();
  5141. }
  5142. return pullRefreshApi;
  5143. };
  5144. });
  5145. })(mui, document);
  5146. /**
  5147. * off-canvas
  5148. * @param {type} $
  5149. * @param {type} window
  5150. * @param {type} document
  5151. * @param {type} action
  5152. * @returns {undefined}
  5153. */
  5154. (function($, window, document, name) {
  5155. var CLASS_OFF_CANVAS_LEFT = 'mui-off-canvas-left';
  5156. var CLASS_OFF_CANVAS_RIGHT = 'mui-off-canvas-right';
  5157. var CLASS_ACTION_BACKDROP = 'mui-off-canvas-backdrop';
  5158. var CLASS_OFF_CANVAS_WRAP = 'mui-off-canvas-wrap';
  5159. var CLASS_SLIDE_IN = 'mui-slide-in';
  5160. var CLASS_ACTIVE = 'mui-active';
  5161. var CLASS_TRANSITIONING = 'mui-transitioning';
  5162. var SELECTOR_INNER_WRAP = '.mui-inner-wrap';
  5163. var OffCanvas = $.Class.extend({
  5164. init: function(element, options) {
  5165. this.wrapper = this.element = element;
  5166. this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
  5167. this.classList = this.wrapper.classList;
  5168. if (this.scroller) {
  5169. this.options = $.extend(true, {
  5170. dragThresholdX: 10,
  5171. scale: 0.8,
  5172. opacity: 0.1,
  5173. preventDefaultException: {
  5174. tagName: /^(INPUT|TEXTAREA|BUTTON|SELECT|VIDEO)$/
  5175. },
  5176. }, options);
  5177. document.body.classList.add('mui-fullscreen'); //fullscreen
  5178. this.refresh();
  5179. this.initEvent();
  5180. }
  5181. },
  5182. _preventDefaultException: function(el, exceptions) {
  5183. for (var i in exceptions) {
  5184. if (exceptions[i].test(el[i])) {
  5185. return true;
  5186. }
  5187. }
  5188. return false;
  5189. },
  5190. refresh: function(offCanvas) {
  5191. // offCanvas && !offCanvas.classList.contains(CLASS_ACTIVE) && this.classList.remove(CLASS_ACTIVE);
  5192. this.slideIn = this.classList.contains(CLASS_SLIDE_IN);
  5193. this.scalable = this.classList.contains('mui-scalable') && !this.slideIn;
  5194. this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
  5195. // !offCanvas && this.scroller.classList.remove(CLASS_TRANSITIONING);
  5196. // !offCanvas && this.scroller.setAttribute('style', '');
  5197. this.offCanvasLefts = this.wrapper.querySelectorAll('.' + CLASS_OFF_CANVAS_LEFT);
  5198. this.offCanvasRights = this.wrapper.querySelectorAll('.' + CLASS_OFF_CANVAS_RIGHT);
  5199. if (offCanvas) {
  5200. if (offCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT)) {
  5201. this.offCanvasLeft = offCanvas;
  5202. } else if (offCanvas.classList.contains(CLASS_OFF_CANVAS_RIGHT)) {
  5203. this.offCanvasRight = offCanvas;
  5204. }
  5205. } else {
  5206. this.offCanvasRight = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT);
  5207. this.offCanvasLeft = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT);
  5208. }
  5209. this.offCanvasRightWidth = this.offCanvasLeftWidth = 0;
  5210. this.offCanvasLeftSlideIn = this.offCanvasRightSlideIn = false;
  5211. if (this.offCanvasRight) {
  5212. this.offCanvasRightWidth = this.offCanvasRight.offsetWidth;
  5213. this.offCanvasRightSlideIn = this.slideIn && (this.offCanvasRight.parentNode === this.wrapper);
  5214. // this.offCanvasRight.classList.remove(CLASS_TRANSITIONING);
  5215. // this.offCanvasRight.classList.remove(CLASS_ACTIVE);
  5216. // this.offCanvasRight.setAttribute('style', '');
  5217. }
  5218. if (this.offCanvasLeft) {
  5219. this.offCanvasLeftWidth = this.offCanvasLeft.offsetWidth;
  5220. this.offCanvasLeftSlideIn = this.slideIn && (this.offCanvasLeft.parentNode === this.wrapper);
  5221. // this.offCanvasLeft.classList.remove(CLASS_TRANSITIONING);
  5222. // this.offCanvasLeft.classList.remove(CLASS_ACTIVE);
  5223. // this.offCanvasLeft.setAttribute('style', '');
  5224. }
  5225. this.backdrop = this.scroller.querySelector('.' + CLASS_ACTION_BACKDROP);
  5226. this.options.dragThresholdX = this.options.dragThresholdX || 10;
  5227. this.visible = false;
  5228. this.startX = null;
  5229. this.lastX = null;
  5230. this.offsetX = null;
  5231. this.lastTranslateX = null;
  5232. },
  5233. handleEvent: function(e) {
  5234. switch (e.type) {
  5235. case $.EVENT_START:
  5236. e.target && !this._preventDefaultException(e.target, this.options.preventDefaultException) && e.preventDefault();
  5237. break;
  5238. case 'webkitTransitionEnd': //有个bug需要处理,需要考虑假设没有触发webkitTransitionEnd的情况
  5239. if (e.target === this.scroller) {
  5240. this._dispatchEvent();
  5241. }
  5242. break;
  5243. case 'drag':
  5244. var detail = e.detail;
  5245. if (!this.startX) {
  5246. this.startX = detail.center.x;
  5247. this.lastX = this.startX;
  5248. } else {
  5249. this.lastX = detail.center.x;
  5250. }
  5251. if (!this.isDragging && Math.abs(this.lastX - this.startX) > this.options.dragThresholdX && (detail.direction === 'left' || (detail.direction === 'right'))) {
  5252. if (this.slideIn) {
  5253. this.scroller = this.wrapper.querySelector(SELECTOR_INNER_WRAP);
  5254. if (this.classList.contains(CLASS_ACTIVE)) {
  5255. if (this.offCanvasRight && this.offCanvasRight.classList.contains(CLASS_ACTIVE)) {
  5256. this.offCanvas = this.offCanvasRight;
  5257. this.offCanvasWidth = this.offCanvasRightWidth;
  5258. } else {
  5259. this.offCanvas = this.offCanvasLeft;
  5260. this.offCanvasWidth = this.offCanvasLeftWidth;
  5261. }
  5262. } else {
  5263. if (detail.direction === 'left' && this.offCanvasRight) {
  5264. this.offCanvas = this.offCanvasRight;
  5265. this.offCanvasWidth = this.offCanvasRightWidth;
  5266. } else if (detail.direction === 'right' && this.offCanvasLeft) {
  5267. this.offCanvas = this.offCanvasLeft;
  5268. this.offCanvasWidth = this.offCanvasLeftWidth;
  5269. } else {
  5270. this.scroller = null;
  5271. }
  5272. }
  5273. } else {
  5274. if (this.classList.contains(CLASS_ACTIVE)) {
  5275. if (detail.direction === 'left') {
  5276. this.offCanvas = this.offCanvasLeft;
  5277. this.offCanvasWidth = this.offCanvasLeftWidth;
  5278. } else {
  5279. this.offCanvas = this.offCanvasRight;
  5280. this.offCanvasWidth = this.offCanvasRightWidth;
  5281. }
  5282. } else {
  5283. if (detail.direction === 'right') {
  5284. this.offCanvas = this.offCanvasLeft;
  5285. this.offCanvasWidth = this.offCanvasLeftWidth;
  5286. } else {
  5287. this.offCanvas = this.offCanvasRight;
  5288. this.offCanvasWidth = this.offCanvasRightWidth;
  5289. }
  5290. }
  5291. }
  5292. if (this.offCanvas && this.scroller) {
  5293. this.startX = this.lastX;
  5294. this.isDragging = true;
  5295. $.gestures.session.lockDirection = true; //锁定方向
  5296. $.gestures.session.startDirection = detail.direction;
  5297. this.offCanvas.classList.remove(CLASS_TRANSITIONING);
  5298. this.scroller.classList.remove(CLASS_TRANSITIONING);
  5299. this.offsetX = this.getTranslateX();
  5300. this._initOffCanvasVisible();
  5301. }
  5302. }
  5303. if (this.isDragging) {
  5304. this.updateTranslate(this.offsetX + (this.lastX - this.startX));
  5305. detail.gesture.preventDefault();
  5306. e.stopPropagation();
  5307. }
  5308. break;
  5309. case 'dragend':
  5310. if (this.isDragging) {
  5311. var detail = e.detail;
  5312. var direction = detail.direction;
  5313. this.isDragging = false;
  5314. this.offCanvas.classList.add(CLASS_TRANSITIONING);
  5315. this.scroller.classList.add(CLASS_TRANSITIONING);
  5316. var ratio = 0;
  5317. var x = this.getTranslateX();
  5318. if (!this.slideIn) {
  5319. if (x >= 0) {
  5320. ratio = (this.offCanvasLeftWidth && (x / this.offCanvasLeftWidth)) || 0;
  5321. } else {
  5322. ratio = (this.offCanvasRightWidth && (x / this.offCanvasRightWidth)) || 0;
  5323. }
  5324. if (ratio === 0) {
  5325. this.openPercentage(0);
  5326. this._dispatchEvent(); //此处不触发webkitTransitionEnd,所以手动dispatch
  5327. return;
  5328. }
  5329. if (direction === 'right' && ratio >= 0 && (ratio >= 0.5 || detail.swipe)) { //右滑打开
  5330. this.openPercentage(100);
  5331. } else if (direction === 'right' && ratio < 0 && (ratio > -0.5 || detail.swipe)) { //右滑关闭
  5332. this.openPercentage(0);
  5333. } else if (direction === 'right' && ratio > 0 && ratio < 0.5) { //右滑还原关闭
  5334. this.openPercentage(0);
  5335. } else if (direction === 'right' && ratio < 0.5) { //右滑还原打开
  5336. this.openPercentage(-100);
  5337. } else if (direction === 'left' && ratio <= 0 && (ratio <= -0.5 || detail.swipe)) { //左滑打开
  5338. this.openPercentage(-100);
  5339. } else if (direction === 'left' && ratio > 0 && (ratio <= 0.5 || detail.swipe)) { //左滑关闭
  5340. this.openPercentage(0);
  5341. } else if (direction === 'left' && ratio < 0 && ratio >= -0.5) { //左滑还原关闭
  5342. this.openPercentage(0);
  5343. } else if (direction === 'left' && ratio > 0.5) { //左滑还原打开
  5344. this.openPercentage(100);
  5345. } else { //默认关闭
  5346. this.openPercentage(0);
  5347. }
  5348. if (ratio === 1 || ratio === -1) { //此处不触发webkitTransitionEnd,所以手动dispatch
  5349. this._dispatchEvent();
  5350. }
  5351. } else {
  5352. if (x >= 0) {
  5353. ratio = (this.offCanvasRightWidth && (x / this.offCanvasRightWidth)) || 0;
  5354. } else {
  5355. ratio = (this.offCanvasLeftWidth && (x / this.offCanvasLeftWidth)) || 0;
  5356. }
  5357. if (direction === 'right' && ratio <= 0 && (ratio >= -0.5 || detail.swipe)) { //右滑打开
  5358. this.openPercentage(100);
  5359. } else if (direction === 'right' && ratio > 0 && (ratio >= 0.5 || detail.swipe)) { //右滑关闭
  5360. this.openPercentage(0);
  5361. } else if (direction === 'right' && ratio <= -0.5) { //右滑还原关闭
  5362. this.openPercentage(0);
  5363. } else if (direction === 'right' && ratio > 0 && ratio <= 0.5) { //右滑还原打开
  5364. this.openPercentage(-100);
  5365. } else if (direction === 'left' && ratio >= 0 && (ratio <= 0.5 || detail.swipe)) { //左滑打开
  5366. this.openPercentage(-100);
  5367. } else if (direction === 'left' && ratio < 0 && (ratio <= -0.5 || detail.swipe)) { //左滑关闭
  5368. this.openPercentage(0);
  5369. } else if (direction === 'left' && ratio >= 0.5) { //左滑还原关闭
  5370. this.openPercentage(0);
  5371. } else if (direction === 'left' && ratio >= -0.5 && ratio < 0) { //左滑还原打开
  5372. this.openPercentage(100);
  5373. } else {
  5374. this.openPercentage(0);
  5375. }
  5376. if (ratio === 1 || ratio === -1 || ratio === 0) {
  5377. this._dispatchEvent();
  5378. return;
  5379. }
  5380. }
  5381. }
  5382. break;
  5383. }
  5384. },
  5385. _dispatchEvent: function() {
  5386. if (this.classList.contains(CLASS_ACTIVE)) {
  5387. $.trigger(this.wrapper, 'shown', this);
  5388. } else {
  5389. $.trigger(this.wrapper, 'hidden', this);
  5390. }
  5391. },
  5392. _initOffCanvasVisible: function() {
  5393. if (!this.visible) {
  5394. this.visible = true;
  5395. if (this.offCanvasLeft) {
  5396. this.offCanvasLeft.style.visibility = 'visible';
  5397. }
  5398. if (this.offCanvasRight) {
  5399. this.offCanvasRight.style.visibility = 'visible';
  5400. }
  5401. }
  5402. },
  5403. initEvent: function() {
  5404. var self = this;
  5405. if (self.backdrop) {
  5406. self.backdrop.addEventListener('tap', function(e) {
  5407. self.close();
  5408. e.detail.gesture.preventDefault();
  5409. });
  5410. }
  5411. if (this.classList.contains('mui-draggable')) {
  5412. this.wrapper.addEventListener($.EVENT_START, this); //临时处理
  5413. this.wrapper.addEventListener('drag', this);
  5414. this.wrapper.addEventListener('dragend', this);
  5415. }
  5416. this.wrapper.addEventListener('webkitTransitionEnd', this);
  5417. },
  5418. openPercentage: function(percentage) {
  5419. var p = percentage / 100;
  5420. if (!this.slideIn) {
  5421. if (this.offCanvasLeft && percentage >= 0) {
  5422. this.updateTranslate(this.offCanvasLeftWidth * p);
  5423. this.offCanvasLeft.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5424. } else if (this.offCanvasRight && percentage <= 0) {
  5425. this.updateTranslate(this.offCanvasRightWidth * p);
  5426. this.offCanvasRight.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5427. }
  5428. this.classList[p !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5429. } else {
  5430. if (this.offCanvasLeft && percentage >= 0) {
  5431. p = p === 0 ? -1 : 0;
  5432. this.updateTranslate(this.offCanvasLeftWidth * p);
  5433. this.offCanvasLeft.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5434. } else if (this.offCanvasRight && percentage <= 0) {
  5435. p = p === 0 ? 1 : 0;
  5436. this.updateTranslate(this.offCanvasRightWidth * p);
  5437. this.offCanvasRight.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5438. }
  5439. this.classList[percentage !== 0 ? 'add' : 'remove'](CLASS_ACTIVE);
  5440. }
  5441. },
  5442. updateTranslate: function(x) {
  5443. if (x !== this.lastTranslateX) {
  5444. if (!this.slideIn) {
  5445. if ((!this.offCanvasLeft && x > 0) || (!this.offCanvasRight && x < 0)) {
  5446. this.setTranslateX(0);
  5447. return;
  5448. }
  5449. if (this.leftShowing && x > this.offCanvasLeftWidth) {
  5450. this.setTranslateX(this.offCanvasLeftWidth);
  5451. return;
  5452. }
  5453. if (this.rightShowing && x < -this.offCanvasRightWidth) {
  5454. this.setTranslateX(-this.offCanvasRightWidth);
  5455. return;
  5456. }
  5457. this.setTranslateX(x);
  5458. if (x >= 0) {
  5459. this.leftShowing = true;
  5460. this.rightShowing = false;
  5461. if (x > 0) {
  5462. if (this.offCanvasLeft) {
  5463. $.each(this.offCanvasLefts, function(index, offCanvas) {
  5464. if (offCanvas === this.offCanvasLeft) {
  5465. this.offCanvasLeft.style.zIndex = 0;
  5466. } else {
  5467. offCanvas.style.zIndex = -1;
  5468. }
  5469. }.bind(this));
  5470. }
  5471. if (this.offCanvasRight) {
  5472. this.offCanvasRight.style.zIndex = -1;
  5473. }
  5474. }
  5475. } else {
  5476. this.rightShowing = true;
  5477. this.leftShowing = false;
  5478. if (this.offCanvasRight) {
  5479. $.each(this.offCanvasRights, function(index, offCanvas) {
  5480. if (offCanvas === this.offCanvasRight) {
  5481. offCanvas.style.zIndex = 0;
  5482. } else {
  5483. offCanvas.style.zIndex = -1;
  5484. }
  5485. }.bind(this));
  5486. }
  5487. if (this.offCanvasLeft) {
  5488. this.offCanvasLeft.style.zIndex = -1;
  5489. }
  5490. }
  5491. } else {
  5492. if (this.offCanvas.classList.contains(CLASS_OFF_CANVAS_RIGHT)) {
  5493. if (x < 0) {
  5494. this.setTranslateX(0);
  5495. return;
  5496. }
  5497. if (x > this.offCanvasRightWidth) {
  5498. this.setTranslateX(this.offCanvasRightWidth);
  5499. return;
  5500. }
  5501. } else {
  5502. if (x > 0) {
  5503. this.setTranslateX(0);
  5504. return;
  5505. }
  5506. if (x < -this.offCanvasLeftWidth) {
  5507. this.setTranslateX(-this.offCanvasLeftWidth);
  5508. return;
  5509. }
  5510. }
  5511. this.setTranslateX(x);
  5512. }
  5513. this.lastTranslateX = x;
  5514. }
  5515. },
  5516. setTranslateX: $.animationFrame(function(x) {
  5517. if (this.scroller) {
  5518. if (this.scalable && this.offCanvas.parentNode === this.wrapper) {
  5519. var percent = Math.abs(x) / this.offCanvasWidth;
  5520. var zoomOutScale = 1 - (1 - this.options.scale) * percent;
  5521. var zoomInScale = this.options.scale + (1 - this.options.scale) * percent;
  5522. var zoomOutOpacity = 1 - (1 - this.options.opacity) * percent;
  5523. var zoomInOpacity = this.options.opacity + (1 - this.options.opacity) * percent;
  5524. if (this.offCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT)) {
  5525. this.offCanvas.style.webkitTransformOrigin = '-100%';
  5526. this.scroller.style.webkitTransformOrigin = 'left';
  5527. } else {
  5528. this.offCanvas.style.webkitTransformOrigin = '200%';
  5529. this.scroller.style.webkitTransformOrigin = 'right';
  5530. }
  5531. this.offCanvas.style.opacity = zoomInOpacity;
  5532. this.offCanvas.style.webkitTransform = 'translate3d(0,0,0) scale(' + zoomInScale + ')';
  5533. this.scroller.style.webkitTransform = 'translate3d(' + x + 'px,0,0) scale(' + zoomOutScale + ')';
  5534. } else {
  5535. if (this.slideIn) {
  5536. this.offCanvas.style.webkitTransform = 'translate3d(' + x + 'px,0,0)';
  5537. } else {
  5538. this.scroller.style.webkitTransform = 'translate3d(' + x + 'px,0,0)';
  5539. }
  5540. }
  5541. }
  5542. }),
  5543. getTranslateX: function() {
  5544. if (this.offCanvas) {
  5545. var scroller = this.slideIn ? this.offCanvas : this.scroller;
  5546. var result = $.parseTranslateMatrix($.getStyles(scroller, 'webkitTransform'));
  5547. return (result && result.x) || 0;
  5548. }
  5549. return 0;
  5550. },
  5551. isShown: function(direction) {
  5552. var shown = false;
  5553. if (!this.slideIn) {
  5554. var x = this.getTranslateX();
  5555. if (direction === 'right') {
  5556. shown = this.classList.contains(CLASS_ACTIVE) && x < 0;
  5557. } else if (direction === 'left') {
  5558. shown = this.classList.contains(CLASS_ACTIVE) && x > 0;
  5559. } else {
  5560. shown = this.classList.contains(CLASS_ACTIVE) && x !== 0;
  5561. }
  5562. } else {
  5563. if (direction === 'left') {
  5564. shown = this.classList.contains(CLASS_ACTIVE) && this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE);
  5565. } else if (direction === 'right') {
  5566. shown = this.classList.contains(CLASS_ACTIVE) && this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE);
  5567. } else {
  5568. shown = this.classList.contains(CLASS_ACTIVE) && (this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE) || this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE));
  5569. }
  5570. }
  5571. return shown;
  5572. },
  5573. close: function() {
  5574. this._initOffCanvasVisible();
  5575. this.offCanvas = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT + '.' + CLASS_ACTIVE) || this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_LEFT + '.' + CLASS_ACTIVE);
  5576. this.offCanvasWidth = this.offCanvas.offsetWidth;
  5577. if (this.scroller) {
  5578. this.offCanvas.offsetHeight;
  5579. this.offCanvas.classList.add(CLASS_TRANSITIONING);
  5580. this.scroller.classList.add(CLASS_TRANSITIONING);
  5581. this.openPercentage(0);
  5582. }
  5583. },
  5584. show: function(direction) {
  5585. this._initOffCanvasVisible();
  5586. if (this.isShown(direction)) {
  5587. return false;
  5588. }
  5589. if (!direction) {
  5590. direction = this.wrapper.querySelector('.' + CLASS_OFF_CANVAS_RIGHT) ? 'right' : 'left';
  5591. }
  5592. if (direction === 'right') {
  5593. this.offCanvas = this.offCanvasRight;
  5594. this.offCanvasWidth = this.offCanvasRightWidth;
  5595. } else {
  5596. this.offCanvas = this.offCanvasLeft;
  5597. this.offCanvasWidth = this.offCanvasLeftWidth;
  5598. }
  5599. if (this.scroller) {
  5600. this.offCanvas.offsetHeight;
  5601. this.offCanvas.classList.add(CLASS_TRANSITIONING);
  5602. this.scroller.classList.add(CLASS_TRANSITIONING);
  5603. this.openPercentage(direction === 'left' ? 100 : -100);
  5604. }
  5605. return true;
  5606. },
  5607. toggle: function(directionOrOffCanvas) {
  5608. var direction = directionOrOffCanvas;
  5609. if (directionOrOffCanvas && directionOrOffCanvas.classList) {
  5610. direction = directionOrOffCanvas.classList.contains(CLASS_OFF_CANVAS_LEFT) ? 'left' : 'right';
  5611. this.refresh(directionOrOffCanvas);
  5612. }
  5613. if (!this.show(direction)) {
  5614. this.close();
  5615. }
  5616. }
  5617. });
  5618. //hash to offcanvas
  5619. var findOffCanvasContainer = function(target) {
  5620. parentNode = target.parentNode;
  5621. if (parentNode) {
  5622. if (parentNode.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
  5623. return parentNode;
  5624. } else {
  5625. parentNode = parentNode.parentNode;
  5626. if (parentNode.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
  5627. return parentNode;
  5628. }
  5629. }
  5630. }
  5631. };
  5632. var handle = function(event, target) {
  5633. if (target.tagName === 'A' && target.hash) {
  5634. var offcanvas = document.getElementById(target.hash.replace('#', ''));
  5635. if (offcanvas) {
  5636. var container = findOffCanvasContainer(offcanvas);
  5637. if (container) {
  5638. $.targets._container = container;
  5639. return offcanvas;
  5640. }
  5641. }
  5642. }
  5643. return false;
  5644. };
  5645. $.registerTarget({
  5646. name: name,
  5647. index: 60,
  5648. handle: handle,
  5649. target: false,
  5650. isReset: false,
  5651. isContinue: true
  5652. });
  5653. window.addEventListener('tap', function(e) {
  5654. if (!$.targets.offcanvas) {
  5655. return;
  5656. }
  5657. //TODO 此处类型的代码后续考虑统一优化(target机制),现在的实现费力不讨好
  5658. var target = e.target;
  5659. for (; target && target !== document; target = target.parentNode) {
  5660. if (target.tagName === 'A' && target.hash && target.hash === ('#' + $.targets.offcanvas.id)) {
  5661. e.detail && e.detail.gesture && e.detail.gesture.preventDefault(); //fixed hashchange
  5662. $($.targets._container).offCanvas().toggle($.targets.offcanvas);
  5663. $.targets.offcanvas = $.targets._container = null;
  5664. break;
  5665. }
  5666. }
  5667. });
  5668. $.fn.offCanvas = function(options) {
  5669. var offCanvasApis = [];
  5670. this.each(function() {
  5671. var offCanvasApi = null;
  5672. var self = this;
  5673. //hack old version
  5674. if (!self.classList.contains(CLASS_OFF_CANVAS_WRAP)) {
  5675. self = findOffCanvasContainer(self);
  5676. }
  5677. var id = self.getAttribute('data-offCanvas');
  5678. if (!id) {
  5679. id = ++$.uuid;
  5680. $.data[id] = offCanvasApi = new OffCanvas(self, options);
  5681. self.setAttribute('data-offCanvas', id);
  5682. } else {
  5683. offCanvasApi = $.data[id];
  5684. }
  5685. if (options === 'show' || options === 'close' || options === 'toggle') {
  5686. offCanvasApi.toggle();
  5687. }
  5688. offCanvasApis.push(offCanvasApi);
  5689. });
  5690. return offCanvasApis.length === 1 ? offCanvasApis[0] : offCanvasApis;
  5691. };
  5692. $.ready(function() {
  5693. $('.mui-off-canvas-wrap').offCanvas();
  5694. });
  5695. })(mui, window, document, 'offcanvas');
  5696. /**
  5697. * actions
  5698. * @param {type} $
  5699. * @param {type} name
  5700. * @returns {undefined}
  5701. */
  5702. (function($, name) {
  5703. var CLASS_ACTION = 'mui-action';
  5704. var handle = function(event, target) {
  5705. var className = target.className || '';
  5706. if (typeof className !== 'string') { //svg className(SVGAnimatedString)
  5707. className = '';
  5708. }
  5709. if (className && ~className.indexOf(CLASS_ACTION)) {
  5710. if (target.classList.contains('mui-action-back')) {
  5711. event.preventDefault();
  5712. }
  5713. return target;
  5714. }
  5715. return false;
  5716. };
  5717. $.registerTarget({
  5718. name: name,
  5719. index: 50,
  5720. handle: handle,
  5721. target: false,
  5722. isContinue: true
  5723. });
  5724. })(mui, 'action');
  5725. /**
  5726. * Modals
  5727. * @param {type} $
  5728. * @param {type} window
  5729. * @param {type} document
  5730. * @param {type} name
  5731. * @returns {undefined}
  5732. */
  5733. (function($, window, document, name) {
  5734. var CLASS_MODAL = 'mui-modal';
  5735. var handle = function(event, target) {
  5736. if (target.tagName === 'A' && target.hash) {
  5737. var modal = document.getElementById(target.hash.replace('#', ''));
  5738. if (modal && modal.classList.contains(CLASS_MODAL)) {
  5739. return modal;
  5740. }
  5741. }
  5742. return false;
  5743. };
  5744. $.registerTarget({
  5745. name: name,
  5746. index: 50,
  5747. handle: handle,
  5748. target: false,
  5749. isReset: false,
  5750. isContinue: true
  5751. });
  5752. window.addEventListener('tap', function(event) {
  5753. if ($.targets.modal) {
  5754. event.detail.gesture.preventDefault(); //fixed hashchange
  5755. $.targets.modal.classList.toggle('mui-active');
  5756. }
  5757. });
  5758. })(mui, window, document, 'modal');
  5759. /**
  5760. * Popovers
  5761. * @param {type} $
  5762. * @param {type} window
  5763. * @param {type} document
  5764. * @param {type} name
  5765. * @param {type} undefined
  5766. * @returns {undefined}
  5767. */
  5768. (function($, window, document, name) {
  5769. var CLASS_POPOVER = 'mui-popover';
  5770. var CLASS_POPOVER_ARROW = 'mui-popover-arrow';
  5771. var CLASS_ACTION_POPOVER = 'mui-popover-action';
  5772. var CLASS_BACKDROP = 'mui-backdrop';
  5773. var CLASS_BAR_POPOVER = 'mui-bar-popover';
  5774. var CLASS_BAR_BACKDROP = 'mui-bar-backdrop';
  5775. var CLASS_ACTION_BACKDROP = 'mui-backdrop-action';
  5776. var CLASS_ACTIVE = 'mui-active';
  5777. var CLASS_BOTTOM = 'mui-bottom';
  5778. var handle = function(event, target) {
  5779. if (target.tagName === 'A' && target.hash) {
  5780. $.targets._popover = document.getElementById(target.hash.replace('#', ''));
  5781. if ($.targets._popover && $.targets._popover.classList.contains(CLASS_POPOVER)) {
  5782. return target;
  5783. } else {
  5784. $.targets._popover = null;
  5785. }
  5786. }
  5787. return false;
  5788. };
  5789. $.registerTarget({
  5790. name: name,
  5791. index: 60,
  5792. handle: handle,
  5793. target: false,
  5794. isReset: false,
  5795. isContinue: true
  5796. });
  5797. var onPopoverShown = function(e) {
  5798. this.removeEventListener('webkitTransitionEnd', onPopoverShown);
  5799. this.addEventListener($.EVENT_MOVE, $.preventDefault);
  5800. $.trigger(this, 'shown', this);
  5801. }
  5802. var onPopoverHidden = function(e) {
  5803. setStyle(this, 'none');
  5804. this.removeEventListener('webkitTransitionEnd', onPopoverHidden);
  5805. this.removeEventListener($.EVENT_MOVE, $.preventDefault);
  5806. $.trigger(this, 'hidden', this);
  5807. };
  5808. var backdrop = (function() {
  5809. var element = document.createElement('div');
  5810. element.classList.add(CLASS_BACKDROP);
  5811. element.addEventListener($.EVENT_MOVE, $.preventDefault);
  5812. element.addEventListener('tap', function(e) {
  5813. var popover = $.targets._popover;
  5814. if (popover) {
  5815. popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
  5816. popover.classList.remove(CLASS_ACTIVE);
  5817. removeBackdrop(popover);
  5818. }
  5819. });
  5820. return element;
  5821. }());
  5822. var removeBackdropTimer;
  5823. var removeBackdrop = function(popover) {
  5824. backdrop.setAttribute('style', 'opacity:0');
  5825. $.targets.popover = $.targets._popover = null; //reset
  5826. removeBackdropTimer = $.later(function() {
  5827. if (!popover.classList.contains(CLASS_ACTIVE) && backdrop.parentNode && backdrop.parentNode === document.body) {
  5828. document.body.removeChild(backdrop);
  5829. }
  5830. }, 350);
  5831. };
  5832. window.addEventListener('tap', function(e) {
  5833. if (!$.targets.popover) {
  5834. return;
  5835. }
  5836. var toggle = false;
  5837. var target = e.target;
  5838. for (; target && target !== document; target = target.parentNode) {
  5839. if (target === $.targets.popover) {
  5840. toggle = true;
  5841. }
  5842. }
  5843. if (toggle) {
  5844. e.detail.gesture.preventDefault(); //fixed hashchange
  5845. togglePopover($.targets._popover, $.targets.popover);
  5846. }
  5847. });
  5848. var togglePopover = function(popover, anchor, state) {
  5849. if ((state === 'show' && popover.classList.contains(CLASS_ACTIVE)) || (state === 'hide' && !popover.classList.contains(CLASS_ACTIVE))) {
  5850. return;
  5851. }
  5852. removeBackdropTimer && removeBackdropTimer.cancel(); //取消remove的timer
  5853. //remove一遍,以免来回快速切换,导致webkitTransitionEnd不触发,无法remove
  5854. popover.removeEventListener('webkitTransitionEnd', onPopoverShown);
  5855. popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
  5856. backdrop.classList.remove(CLASS_BAR_BACKDROP);
  5857. backdrop.classList.remove(CLASS_ACTION_BACKDROP);
  5858. var _popover = document.querySelector('.mui-popover.mui-active');
  5859. if (_popover) {
  5860. // _popover.setAttribute('style', '');
  5861. _popover.addEventListener('webkitTransitionEnd', onPopoverHidden);
  5862. _popover.classList.remove(CLASS_ACTIVE);
  5863. // _popover.removeEventListener('webkitTransitionEnd', onPopoverHidden);
  5864. //同一个弹出则直接返回,解决同一个popover的toggle
  5865. if (popover === _popover) {
  5866. removeBackdrop(_popover);
  5867. return;
  5868. }
  5869. }
  5870. var isActionSheet = false;
  5871. if (popover.classList.contains(CLASS_BAR_POPOVER) || popover.classList.contains(CLASS_ACTION_POPOVER)) { //navBar
  5872. if (popover.classList.contains(CLASS_ACTION_POPOVER)) { //action sheet popover
  5873. isActionSheet = true;
  5874. backdrop.classList.add(CLASS_ACTION_BACKDROP);
  5875. } else { //bar popover
  5876. backdrop.classList.add(CLASS_BAR_BACKDROP);
  5877. // if (anchor) {
  5878. // if (anchor.parentNode) {
  5879. // var offsetWidth = anchor.offsetWidth;
  5880. // var offsetLeft = anchor.offsetLeft;
  5881. // var innerWidth = window.innerWidth;
  5882. // popover.style.left = (Math.min(Math.max(offsetLeft, defaultPadding), innerWidth - offsetWidth - defaultPadding)) + "px";
  5883. // } else {
  5884. // //TODO anchor is position:{left,top,bottom,right}
  5885. // }
  5886. // }
  5887. }
  5888. }
  5889. setStyle(popover, 'block'); //actionsheet transform
  5890. popover.offsetHeight;
  5891. popover.classList.add(CLASS_ACTIVE);
  5892. backdrop.setAttribute('style', '');
  5893. document.body.appendChild(backdrop);
  5894. calPosition(popover, anchor, isActionSheet); //position
  5895. backdrop.classList.add(CLASS_ACTIVE);
  5896. popover.addEventListener('webkitTransitionEnd', onPopoverShown);
  5897. };
  5898. var setStyle = function(popover, display, top, left) {
  5899. var style = popover.style;
  5900. if (typeof display !== 'undefined')
  5901. style.display = display;
  5902. if (typeof top !== 'undefined')
  5903. style.top = top + 'px';
  5904. if (typeof left !== 'undefined')
  5905. style.left = left + 'px';
  5906. };
  5907. var calPosition = function(popover, anchor, isActionSheet) {
  5908. if (!popover || !anchor) {
  5909. return;
  5910. }
  5911. if (isActionSheet) { //actionsheet
  5912. setStyle(popover, 'block')
  5913. return;
  5914. }
  5915. var wWidth = window.innerWidth;
  5916. var wHeight = window.innerHeight;
  5917. var pWidth = popover.offsetWidth;
  5918. var pHeight = popover.offsetHeight;
  5919. var aWidth = anchor.offsetWidth;
  5920. var aHeight = anchor.offsetHeight;
  5921. var offset = $.offset(anchor);
  5922. var arrow = popover.querySelector('.' + CLASS_POPOVER_ARROW);
  5923. if (!arrow) {
  5924. arrow = document.createElement('div');
  5925. arrow.className = CLASS_POPOVER_ARROW;
  5926. popover.appendChild(arrow);
  5927. }
  5928. var arrowSize = arrow && arrow.offsetWidth / 2 || 0;
  5929. var pTop = 0;
  5930. var pLeft = 0;
  5931. var diff = 0;
  5932. var arrowLeft = 0;
  5933. var defaultPadding = popover.classList.contains(CLASS_ACTION_POPOVER) ? 0 : 5;
  5934. var position = 'top';
  5935. if ((pHeight + arrowSize) < (offset.top - window.pageYOffset)) { //top
  5936. pTop = offset.top - pHeight - arrowSize;
  5937. } else if ((pHeight + arrowSize) < (wHeight - (offset.top - window.pageYOffset) - aHeight)) { //bottom
  5938. position = 'bottom';
  5939. pTop = offset.top + aHeight + arrowSize;
  5940. } else { //middle
  5941. position = 'middle';
  5942. pTop = Math.max((wHeight - pHeight) / 2 + window.pageYOffset, 0);
  5943. pLeft = Math.max((wWidth - pWidth) / 2 + window.pageXOffset, 0);
  5944. }
  5945. if (position === 'top' || position === 'bottom') {
  5946. pLeft = aWidth / 2 + offset.left - pWidth / 2;
  5947. diff = pLeft;
  5948. if (pLeft < defaultPadding) pLeft = defaultPadding;
  5949. if (pLeft + pWidth > wWidth) pLeft = wWidth - pWidth - defaultPadding;
  5950. if (arrow) {
  5951. if (position === 'top') {
  5952. arrow.classList.add(CLASS_BOTTOM);
  5953. } else {
  5954. arrow.classList.remove(CLASS_BOTTOM);
  5955. }
  5956. diff = diff - pLeft;
  5957. arrowLeft = (pWidth / 2 - arrowSize / 2 + diff);
  5958. arrowLeft = Math.max(Math.min(arrowLeft, pWidth - arrowSize * 2 - 6), 6);
  5959. arrow.setAttribute('style', 'left:' + arrowLeft + 'px');
  5960. }
  5961. } else if (position === 'middle') {
  5962. arrow.setAttribute('style', 'display:none');
  5963. }
  5964. setStyle(popover, 'block', pTop, pLeft);
  5965. };
  5966. $.createMask = function(callback) {
  5967. var element = document.createElement('div');
  5968. element.classList.add(CLASS_BACKDROP);
  5969. element.addEventListener($.EVENT_MOVE, $.preventDefault);
  5970. element.addEventListener('tap', function() {
  5971. mask.close();
  5972. });
  5973. var mask = [element];
  5974. mask._show = false;
  5975. mask.show = function() {
  5976. mask._show = true;
  5977. element.setAttribute('style', 'opacity:1');
  5978. document.body.appendChild(element);
  5979. return mask;
  5980. };
  5981. mask._remove = function() {
  5982. if (mask._show) {
  5983. mask._show = false;
  5984. element.setAttribute('style', 'opacity:0');
  5985. $.later(function() {
  5986. var body = document.body;
  5987. element.parentNode === body && body.removeChild(element);
  5988. }, 350);
  5989. }
  5990. return mask;
  5991. };
  5992. mask.close = function() {
  5993. if (callback) {
  5994. if (callback() !== false) {
  5995. mask._remove();
  5996. }
  5997. } else {
  5998. mask._remove();
  5999. }
  6000. };
  6001. return mask;
  6002. };
  6003. $.fn.popover = function() {
  6004. var args = arguments;
  6005. this.each(function() {
  6006. $.targets._popover = this;
  6007. if (args[0] === 'show' || args[0] === 'hide' || args[0] === 'toggle') {
  6008. togglePopover(this, args[1], args[0]);
  6009. }
  6010. });
  6011. };
  6012. })(mui, window, document, 'popover');
  6013. /**
  6014. * segmented-controllers
  6015. * @param {type} $
  6016. * @param {type} window
  6017. * @param {type} document
  6018. * @param {type} undefined
  6019. * @returns {undefined}
  6020. */
  6021. (function($, window, document, name, undefined) {
  6022. var CLASS_CONTROL_ITEM = 'mui-control-item';
  6023. var CLASS_SEGMENTED_CONTROL = 'mui-segmented-control';
  6024. var CLASS_SEGMENTED_CONTROL_VERTICAL = 'mui-segmented-control-vertical';
  6025. var CLASS_CONTROL_CONTENT = 'mui-control-content';
  6026. var CLASS_TAB_BAR = 'mui-bar-tab';
  6027. var CLASS_TAB_ITEM = 'mui-tab-item';
  6028. var CLASS_SLIDER_ITEM = 'mui-slider-item';
  6029. var handle = function(event, target) {
  6030. if (target.classList && (target.classList.contains(CLASS_CONTROL_ITEM) || target.classList.contains(CLASS_TAB_ITEM))) {
  6031. if (target.parentNode && target.parentNode.classList && target.parentNode.classList.contains(CLASS_SEGMENTED_CONTROL_VERTICAL)) {
  6032. //vertical 如果preventDefault会导致无法滚动
  6033. } else {
  6034. event.preventDefault(); //stop hash change
  6035. }
  6036. // if (target.hash) {
  6037. return target;
  6038. // }
  6039. }
  6040. return false;
  6041. };
  6042. $.registerTarget({
  6043. name: name,
  6044. index: 80,
  6045. handle: handle,
  6046. target: false
  6047. });
  6048. window.addEventListener('tap', function(e) {
  6049. var targetTab = $.targets.tab;
  6050. if (!targetTab) {
  6051. return;
  6052. }
  6053. var activeTab;
  6054. var activeBodies;
  6055. var targetBody;
  6056. var className = 'mui-active';
  6057. var classSelector = '.' + className;
  6058. var segmentedControl = targetTab.parentNode;
  6059. for (; segmentedControl && segmentedControl !== document; segmentedControl = segmentedControl.parentNode) {
  6060. if (segmentedControl.classList.contains(CLASS_SEGMENTED_CONTROL)) {
  6061. activeTab = segmentedControl.querySelector(classSelector + '.' + CLASS_CONTROL_ITEM);
  6062. break;
  6063. } else if (segmentedControl.classList.contains(CLASS_TAB_BAR)) {
  6064. activeTab = segmentedControl.querySelector(classSelector + '.' + CLASS_TAB_ITEM);
  6065. }
  6066. }
  6067. if (activeTab) {
  6068. activeTab.classList.remove(className);
  6069. }
  6070. var isLastActive = targetTab === activeTab;
  6071. if (targetTab) {
  6072. targetTab.classList.add(className);
  6073. }
  6074. if (!targetTab.hash) {
  6075. return;
  6076. }
  6077. targetBody = document.getElementById(targetTab.hash.replace('#', ''));
  6078. if (!targetBody) {
  6079. return;
  6080. }
  6081. if (!targetBody.classList.contains(CLASS_CONTROL_CONTENT)) { //tab bar popover
  6082. targetTab.classList[isLastActive ? 'remove' : 'add'](className);
  6083. return;
  6084. }
  6085. if (isLastActive) { //same
  6086. return;
  6087. }
  6088. var parentNode = targetBody.parentNode;
  6089. activeBodies = parentNode.querySelectorAll('.' + CLASS_CONTROL_CONTENT + classSelector);
  6090. for (var i = 0; i < activeBodies.length; i++) {
  6091. var activeBody = activeBodies[i];
  6092. activeBody.parentNode === parentNode && activeBody.classList.remove(className);
  6093. }
  6094. targetBody.classList.add(className);
  6095. var contents = [];
  6096. var _contents = parentNode.querySelectorAll('.' + CLASS_CONTROL_CONTENT);
  6097. for (var i = 0; i < _contents.length; i++) { //查找直属子节点
  6098. _contents[i].parentNode === parentNode && (contents.push(_contents[i]));
  6099. }
  6100. $.trigger(targetBody, $.eventName('shown', name), {
  6101. tabNumber: Array.prototype.indexOf.call(contents, targetBody)
  6102. });
  6103. e.detail && e.detail.gesture.preventDefault(); //fixed hashchange
  6104. });
  6105. })(mui, window, document, 'tab');
  6106. /**
  6107. * Toggles switch
  6108. * @param {type} $
  6109. * @param {type} window
  6110. * @param {type} name
  6111. * @returns {undefined}
  6112. */
  6113. (function($, window, name) {
  6114. var CLASS_SWITCH = 'mui-switch';
  6115. var CLASS_SWITCH_HANDLE = 'mui-switch-handle';
  6116. var CLASS_ACTIVE = 'mui-active';
  6117. var CLASS_DRAGGING = 'mui-dragging';
  6118. var CLASS_DISABLED = 'mui-disabled';
  6119. var SELECTOR_SWITCH_HANDLE = '.' + CLASS_SWITCH_HANDLE;
  6120. var handle = function(event, target) {
  6121. if (target.classList && target.classList.contains(CLASS_SWITCH)) {
  6122. return target;
  6123. }
  6124. return false;
  6125. };
  6126. $.registerTarget({
  6127. name: name,
  6128. index: 100,
  6129. handle: handle,
  6130. target: false
  6131. });
  6132. var Toggle = function(element) {
  6133. this.element = element;
  6134. this.classList = this.element.classList;
  6135. this.handle = this.element.querySelector(SELECTOR_SWITCH_HANDLE);
  6136. this.init();
  6137. this.initEvent();
  6138. };
  6139. Toggle.prototype.init = function() {
  6140. this.toggleWidth = this.element.offsetWidth;
  6141. this.handleWidth = this.handle.offsetWidth;
  6142. this.handleX = this.toggleWidth - this.handleWidth - 3;
  6143. };
  6144. Toggle.prototype.initEvent = function() {
  6145. this.element.addEventListener($.EVENT_START, this);
  6146. this.element.addEventListener('drag', this);
  6147. this.element.addEventListener('swiperight', this);
  6148. this.element.addEventListener($.EVENT_END, this);
  6149. this.element.addEventListener($.EVENT_CANCEL, this);
  6150. };
  6151. Toggle.prototype.handleEvent = function(e) {
  6152. if (this.classList.contains(CLASS_DISABLED)) {
  6153. return;
  6154. }
  6155. switch (e.type) {
  6156. case $.EVENT_START:
  6157. this.start(e);
  6158. break;
  6159. case 'drag':
  6160. this.drag(e);
  6161. break;
  6162. case 'swiperight':
  6163. this.swiperight();
  6164. break;
  6165. case $.EVENT_END:
  6166. case $.EVENT_CANCEL:
  6167. this.end(e);
  6168. break;
  6169. }
  6170. };
  6171. Toggle.prototype.start = function(e) {
  6172. this.handle.style.webkitTransitionDuration = this.element.style.webkitTransitionDuration = '.2s';
  6173. this.classList.add(CLASS_DRAGGING);
  6174. if (this.toggleWidth === 0 || this.handleWidth === 0) { //当switch处于隐藏状态时,width为0,需要重新初始化
  6175. this.init();
  6176. }
  6177. };
  6178. Toggle.prototype.drag = function(e) {
  6179. var detail = e.detail;
  6180. if (!this.isDragging) {
  6181. if (detail.direction === 'left' || detail.direction === 'right') {
  6182. this.isDragging = true;
  6183. this.lastChanged = undefined;
  6184. this.initialState = this.classList.contains(CLASS_ACTIVE);
  6185. }
  6186. }
  6187. if (this.isDragging) {
  6188. this.setTranslateX(detail.deltaX);
  6189. e.stopPropagation();
  6190. detail.gesture.preventDefault();
  6191. }
  6192. };
  6193. Toggle.prototype.swiperight = function(e) {
  6194. if (this.isDragging) {
  6195. e.stopPropagation();
  6196. }
  6197. };
  6198. Toggle.prototype.end = function(e) {
  6199. this.classList.remove(CLASS_DRAGGING);
  6200. if (this.isDragging) {
  6201. this.isDragging = false;
  6202. e.stopPropagation();
  6203. $.trigger(this.element, 'toggle', {
  6204. isActive: this.classList.contains(CLASS_ACTIVE)
  6205. });
  6206. } else {
  6207. this.toggle();
  6208. }
  6209. };
  6210. Toggle.prototype.toggle = function(animate) {
  6211. var classList = this.classList;
  6212. if (animate === false) {
  6213. this.handle.style.webkitTransitionDuration = this.element.style.webkitTransitionDuration = '0s';
  6214. } else {
  6215. this.handle.style.webkitTransitionDuration = this.element.style.webkitTransitionDuration = '.2s';
  6216. }
  6217. if (classList.contains(CLASS_ACTIVE)) {
  6218. classList.remove(CLASS_ACTIVE);
  6219. this.handle.style.webkitTransform = 'translate(0,0)';
  6220. } else {
  6221. classList.add(CLASS_ACTIVE);
  6222. this.handle.style.webkitTransform = 'translate(' + this.handleX + 'px,0)';
  6223. }
  6224. $.trigger(this.element, 'toggle', {
  6225. isActive: this.classList.contains(CLASS_ACTIVE)
  6226. });
  6227. };
  6228. Toggle.prototype.setTranslateX = $.animationFrame(function(x) {
  6229. if (!this.isDragging) {
  6230. return;
  6231. }
  6232. var isChanged = false;
  6233. if ((this.initialState && -x > (this.handleX / 2)) || (!this.initialState && x > (this.handleX / 2))) {
  6234. isChanged = true;
  6235. }
  6236. if (this.lastChanged !== isChanged) {
  6237. if (isChanged) {
  6238. this.handle.style.webkitTransform = 'translate(' + (this.initialState ? 0 : this.handleX) + 'px,0)';
  6239. this.classList[this.initialState ? 'remove' : 'add'](CLASS_ACTIVE);
  6240. } else {
  6241. this.handle.style.webkitTransform = 'translate(' + (this.initialState ? this.handleX : 0) + 'px,0)';
  6242. this.classList[this.initialState ? 'add' : 'remove'](CLASS_ACTIVE);
  6243. }
  6244. this.lastChanged = isChanged;
  6245. }
  6246. });
  6247. $.fn['switch'] = function(options) {
  6248. var switchApis = [];
  6249. this.each(function() {
  6250. var switchApi = null;
  6251. var id = this.getAttribute('data-switch');
  6252. if (!id) {
  6253. id = ++$.uuid;
  6254. $.data[id] = new Toggle(this);
  6255. this.setAttribute('data-switch', id);
  6256. } else {
  6257. switchApi = $.data[id];
  6258. }
  6259. switchApis.push(switchApi);
  6260. });
  6261. return switchApis.length > 1 ? switchApis : switchApis[0];
  6262. };
  6263. $.ready(function() {
  6264. $('.' + CLASS_SWITCH)['switch']();
  6265. });
  6266. })(mui, window, 'toggle');
  6267. /**
  6268. * Tableviews
  6269. * @param {type} $
  6270. * @param {type} window
  6271. * @param {type} document
  6272. * @returns {undefined}
  6273. */
  6274. (function($, window, document) {
  6275. var CLASS_ACTIVE = 'mui-active';
  6276. var CLASS_SELECTED = 'mui-selected';
  6277. var CLASS_GRID_VIEW = 'mui-grid-view';
  6278. var CLASS_RADIO_VIEW = 'mui-table-view-radio';
  6279. var CLASS_TABLE_VIEW_CELL = 'mui-table-view-cell';
  6280. var CLASS_COLLAPSE_CONTENT = 'mui-collapse-content';
  6281. var CLASS_DISABLED = 'mui-disabled';
  6282. var CLASS_TOGGLE = 'mui-switch';
  6283. var CLASS_BTN = 'mui-btn';
  6284. var CLASS_SLIDER_HANDLE = 'mui-slider-handle';
  6285. var CLASS_SLIDER_LEFT = 'mui-slider-left';
  6286. var CLASS_SLIDER_RIGHT = 'mui-slider-right';
  6287. var CLASS_TRANSITIONING = 'mui-transitioning';
  6288. var SELECTOR_SLIDER_HANDLE = '.' + CLASS_SLIDER_HANDLE;
  6289. var SELECTOR_SLIDER_LEFT = '.' + CLASS_SLIDER_LEFT;
  6290. var SELECTOR_SLIDER_RIGHT = '.' + CLASS_SLIDER_RIGHT;
  6291. var SELECTOR_SELECTED = '.' + CLASS_SELECTED;
  6292. var SELECTOR_BUTTON = '.' + CLASS_BTN;
  6293. var overFactor = 0.8;
  6294. var cell, a;
  6295. var isMoved = isOpened = openedActions = progress = false;
  6296. var sliderHandle = sliderActionLeft = sliderActionRight = buttonsLeft = buttonsRight = sliderDirection = sliderRequestAnimationFrame = false;
  6297. var timer = translateX = lastTranslateX = sliderActionLeftWidth = sliderActionRightWidth = 0;
  6298. var toggleActive = function(isActive) {
  6299. if (isActive) {
  6300. if (a) {
  6301. a.classList.add(CLASS_ACTIVE);
  6302. } else if (cell) {
  6303. cell.classList.add(CLASS_ACTIVE);
  6304. }
  6305. } else {
  6306. timer && timer.cancel();
  6307. if (a) {
  6308. a.classList.remove(CLASS_ACTIVE);
  6309. } else if (cell) {
  6310. cell.classList.remove(CLASS_ACTIVE);
  6311. }
  6312. }
  6313. };
  6314. var updateTranslate = function() {
  6315. if (translateX !== lastTranslateX) {
  6316. if (buttonsRight && buttonsRight.length > 0) {
  6317. progress = translateX / sliderActionRightWidth;
  6318. if (translateX < -sliderActionRightWidth) {
  6319. translateX = -sliderActionRightWidth - Math.pow(-translateX - sliderActionRightWidth, overFactor);
  6320. }
  6321. for (var i = 0, len = buttonsRight.length; i < len; i++) {
  6322. var buttonRight = buttonsRight[i];
  6323. if (typeof buttonRight._buttonOffset === 'undefined') {
  6324. buttonRight._buttonOffset = buttonRight.offsetLeft;
  6325. }
  6326. buttonOffset = buttonRight._buttonOffset;
  6327. setTranslate(buttonRight, (translateX - buttonOffset * (1 + Math.max(progress, -1))));
  6328. }
  6329. }
  6330. if (buttonsLeft && buttonsLeft.length > 0) {
  6331. progress = translateX / sliderActionLeftWidth;
  6332. if (translateX > sliderActionLeftWidth) {
  6333. translateX = sliderActionLeftWidth + Math.pow(translateX - sliderActionLeftWidth, overFactor);
  6334. }
  6335. for (var i = 0, len = buttonsLeft.length; i < len; i++) {
  6336. var buttonLeft = buttonsLeft[i];
  6337. if (typeof buttonLeft._buttonOffset === 'undefined') {
  6338. buttonLeft._buttonOffset = sliderActionLeftWidth - buttonLeft.offsetLeft - buttonLeft.offsetWidth;
  6339. }
  6340. buttonOffset = buttonLeft._buttonOffset;
  6341. if (buttonsLeft.length > 1) {
  6342. buttonLeft.style.zIndex = buttonsLeft.length - i;
  6343. }
  6344. setTranslate(buttonLeft, (translateX + buttonOffset * (1 - Math.min(progress, 1))));
  6345. }
  6346. }
  6347. setTranslate(sliderHandle, translateX);
  6348. lastTranslateX = translateX;
  6349. }
  6350. sliderRequestAnimationFrame = requestAnimationFrame(function() {
  6351. updateTranslate();
  6352. });
  6353. };
  6354. var setTranslate = function(element, x) {
  6355. if (element) {
  6356. element.style.webkitTransform = 'translate(' + x + 'px,0)';
  6357. }
  6358. };
  6359. window.addEventListener($.EVENT_START, function(event) {
  6360. if (cell) {
  6361. toggleActive(false);
  6362. }
  6363. cell = a = false;
  6364. isMoved = isOpened = openedActions = false;
  6365. var target = event.target;
  6366. var isDisabled = false;
  6367. for (; target && target !== document; target = target.parentNode) {
  6368. if (target.classList) {
  6369. var classList = target.classList;
  6370. 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)) {
  6371. isDisabled = true;
  6372. }
  6373. if (classList.contains(CLASS_COLLAPSE_CONTENT)) { //collapse content
  6374. break;
  6375. }
  6376. if (classList.contains(CLASS_TABLE_VIEW_CELL)) {
  6377. cell = target;
  6378. //TODO swipe to delete close
  6379. var selected = cell.parentNode.querySelector(SELECTOR_SELECTED);
  6380. if (!cell.parentNode.classList.contains(CLASS_RADIO_VIEW) && selected && selected !== cell) {
  6381. $.swipeoutClose(selected);
  6382. cell = isDisabled = false;
  6383. return;
  6384. }
  6385. if (!cell.parentNode.classList.contains(CLASS_GRID_VIEW)) {
  6386. var link = cell.querySelector('a');
  6387. if (link && link.parentNode === cell) { //li>a
  6388. a = link;
  6389. }
  6390. }
  6391. var handle = cell.querySelector(SELECTOR_SLIDER_HANDLE);
  6392. if (handle) {
  6393. toggleEvents(cell);
  6394. event.stopPropagation();
  6395. }
  6396. if (!isDisabled) {
  6397. if (handle) {
  6398. if (timer) {
  6399. timer.cancel();
  6400. }
  6401. timer = $.later(function() {
  6402. toggleActive(true);
  6403. }, 100);
  6404. } else {
  6405. toggleActive(true);
  6406. }
  6407. }
  6408. break;
  6409. }
  6410. }
  6411. }
  6412. });
  6413. window.addEventListener($.EVENT_MOVE, function(event) {
  6414. toggleActive(false);
  6415. });
  6416. var handleEvent = {
  6417. handleEvent: function(event) {
  6418. switch (event.type) {
  6419. case 'drag':
  6420. this.drag(event);
  6421. break;
  6422. case 'dragend':
  6423. this.dragend(event);
  6424. break;
  6425. case 'flick':
  6426. this.flick(event);
  6427. break;
  6428. case 'swiperight':
  6429. this.swiperight(event);
  6430. break;
  6431. case 'swipeleft':
  6432. this.swipeleft(event);
  6433. break;
  6434. }
  6435. },
  6436. drag: function(event) {
  6437. if (!cell) {
  6438. return;
  6439. }
  6440. if (!isMoved) { //init
  6441. sliderHandle = sliderActionLeft = sliderActionRight = buttonsLeft = buttonsRight = sliderDirection = sliderRequestAnimationFrame = false;
  6442. sliderHandle = cell.querySelector(SELECTOR_SLIDER_HANDLE);
  6443. if (sliderHandle) {
  6444. sliderActionLeft = cell.querySelector(SELECTOR_SLIDER_LEFT);
  6445. sliderActionRight = cell.querySelector(SELECTOR_SLIDER_RIGHT);
  6446. if (sliderActionLeft) {
  6447. sliderActionLeftWidth = sliderActionLeft.offsetWidth;
  6448. buttonsLeft = sliderActionLeft.querySelectorAll(SELECTOR_BUTTON);
  6449. }
  6450. if (sliderActionRight) {
  6451. sliderActionRightWidth = sliderActionRight.offsetWidth;
  6452. buttonsRight = sliderActionRight.querySelectorAll(SELECTOR_BUTTON);
  6453. }
  6454. cell.classList.remove(CLASS_TRANSITIONING);
  6455. isOpened = cell.classList.contains(CLASS_SELECTED);
  6456. if (isOpened) {
  6457. openedActions = cell.querySelector(SELECTOR_SLIDER_LEFT + SELECTOR_SELECTED) ? 'left' : 'right';
  6458. }
  6459. }
  6460. }
  6461. var detail = event.detail;
  6462. var direction = detail.direction;
  6463. var angle = detail.angle;
  6464. if (direction === 'left' && (angle > 150 || angle < -150)) {
  6465. if (buttonsRight || (buttonsLeft && isOpened)) { //存在右侧按钮或存在左侧按钮且是已打开状态
  6466. isMoved = true;
  6467. }
  6468. } else if (direction === 'right' && (angle > -30 && angle < 30)) {
  6469. if (buttonsLeft || (buttonsRight && isOpened)) { //存在左侧按钮或存在右侧按钮且是已打开状态
  6470. isMoved = true;
  6471. }
  6472. }
  6473. if (isMoved) {
  6474. event.stopPropagation();
  6475. event.detail.gesture.preventDefault();
  6476. var translate = event.detail.deltaX;
  6477. if (isOpened) {
  6478. if (openedActions === 'right') {
  6479. translate = translate - sliderActionRightWidth;
  6480. } else {
  6481. translate = translate + sliderActionLeftWidth;
  6482. }
  6483. }
  6484. if ((translate > 0 && !buttonsLeft) || (translate < 0 && !buttonsRight)) {
  6485. if (!isOpened) {
  6486. return;
  6487. }
  6488. translate = 0;
  6489. }
  6490. if (translate < 0) {
  6491. sliderDirection = 'toLeft';
  6492. } else if (translate > 0) {
  6493. sliderDirection = 'toRight';
  6494. } else {
  6495. if (!sliderDirection) {
  6496. sliderDirection = 'toLeft';
  6497. }
  6498. }
  6499. if (!sliderRequestAnimationFrame) {
  6500. updateTranslate();
  6501. }
  6502. translateX = translate;
  6503. }
  6504. },
  6505. flick: function(event) {
  6506. if (isMoved) {
  6507. event.stopPropagation();
  6508. }
  6509. },
  6510. swipeleft: function(event) {
  6511. if (isMoved) {
  6512. event.stopPropagation();
  6513. }
  6514. },
  6515. swiperight: function(event) {
  6516. if (isMoved) {
  6517. event.stopPropagation();
  6518. }
  6519. },
  6520. dragend: function(event) {
  6521. if (!isMoved) {
  6522. return;
  6523. }
  6524. event.stopPropagation();
  6525. if (sliderRequestAnimationFrame) {
  6526. cancelAnimationFrame(sliderRequestAnimationFrame);
  6527. sliderRequestAnimationFrame = null;
  6528. }
  6529. var detail = event.detail;
  6530. isMoved = false;
  6531. var action = 'close';
  6532. var actionsWidth = sliderDirection === 'toLeft' ? sliderActionRightWidth : sliderActionLeftWidth;
  6533. var isToggle = detail.swipe || (Math.abs(translateX) > actionsWidth / 2);
  6534. if (isToggle) {
  6535. if (!isOpened) {
  6536. action = 'open';
  6537. } else if (detail.direction === 'left' && openedActions === 'right') {
  6538. action = 'open';
  6539. } else if (detail.direction === 'right' && openedActions === 'left') {
  6540. action = 'open';
  6541. }
  6542. }
  6543. cell.classList.add(CLASS_TRANSITIONING);
  6544. var buttons;
  6545. if (action === 'open') {
  6546. var newTranslate = sliderDirection === 'toLeft' ? -actionsWidth : actionsWidth;
  6547. setTranslate(sliderHandle, newTranslate);
  6548. buttons = sliderDirection === 'toLeft' ? buttonsRight : buttonsLeft;
  6549. if (typeof buttons !== 'undefined') {
  6550. var button = null;
  6551. for (var i = 0; i < buttons.length; i++) {
  6552. button = buttons[i];
  6553. setTranslate(button, newTranslate);
  6554. }
  6555. button.parentNode.classList.add(CLASS_SELECTED);
  6556. cell.classList.add(CLASS_SELECTED);
  6557. if (!isOpened) {
  6558. $.trigger(cell, sliderDirection === 'toLeft' ? 'slideleft' : 'slideright');
  6559. }
  6560. }
  6561. } else {
  6562. setTranslate(sliderHandle, 0);
  6563. sliderActionLeft && sliderActionLeft.classList.remove(CLASS_SELECTED);
  6564. sliderActionRight && sliderActionRight.classList.remove(CLASS_SELECTED);
  6565. cell.classList.remove(CLASS_SELECTED);
  6566. }
  6567. var buttonOffset;
  6568. if (buttonsLeft && buttonsLeft.length > 0 && buttonsLeft !== buttons) {
  6569. for (var i = 0, len = buttonsLeft.length; i < len; i++) {
  6570. var buttonLeft = buttonsLeft[i];
  6571. buttonOffset = buttonLeft._buttonOffset;
  6572. if (typeof buttonOffset === 'undefined') {
  6573. buttonLeft._buttonOffset = sliderActionLeftWidth - buttonLeft.offsetLeft - buttonLeft.offsetWidth;
  6574. }
  6575. setTranslate(buttonLeft, buttonOffset);
  6576. }
  6577. }
  6578. if (buttonsRight && buttonsRight.length > 0 && buttonsRight !== buttons) {
  6579. for (var i = 0, len = buttonsRight.length; i < len; i++) {
  6580. var buttonRight = buttonsRight[i];
  6581. buttonOffset = buttonRight._buttonOffset;
  6582. if (typeof buttonOffset === 'undefined') {
  6583. buttonRight._buttonOffset = buttonRight.offsetLeft;
  6584. }
  6585. setTranslate(buttonRight, -buttonOffset);
  6586. }
  6587. }
  6588. }
  6589. };
  6590. function toggleEvents(element, isRemove) {
  6591. var method = !!isRemove ? 'removeEventListener' : 'addEventListener';
  6592. element[method]('drag', handleEvent);
  6593. element[method]('dragend', handleEvent);
  6594. element[method]('swiperight', handleEvent);
  6595. element[method]('swipeleft', handleEvent);
  6596. element[method]('flick', handleEvent);
  6597. };
  6598. /**
  6599. * 打开滑动菜单
  6600. * @param {Object} el
  6601. * @param {Object} direction
  6602. */
  6603. $.swipeoutOpen = function(el, direction) {
  6604. if (!el) return;
  6605. var classList = el.classList;
  6606. if (classList.contains(CLASS_SELECTED)) return;
  6607. if (!direction) {
  6608. if (el.querySelector(SELECTOR_SLIDER_RIGHT)) {
  6609. direction = 'right';
  6610. } else {
  6611. direction = 'left';
  6612. }
  6613. }
  6614. var swipeoutAction = el.querySelector($.classSelector(".slider-" + direction));
  6615. if (!swipeoutAction) return;
  6616. swipeoutAction.classList.add(CLASS_SELECTED);
  6617. classList.add(CLASS_SELECTED);
  6618. classList.remove(CLASS_TRANSITIONING);
  6619. var buttons = swipeoutAction.querySelectorAll(SELECTOR_BUTTON);
  6620. var swipeoutWidth = swipeoutAction.offsetWidth;
  6621. var translate = (direction === 'right') ? -swipeoutWidth : swipeoutWidth;
  6622. var length = buttons.length;
  6623. var button;
  6624. for (var i = 0; i < length; i++) {
  6625. button = buttons[i];
  6626. if (direction === 'right') {
  6627. setTranslate(button, -button.offsetLeft);
  6628. } else {
  6629. setTranslate(button, (swipeoutWidth - button.offsetWidth - button.offsetLeft));
  6630. }
  6631. }
  6632. classList.add(CLASS_TRANSITIONING);
  6633. for (var i = 0; i < length; i++) {
  6634. setTranslate(buttons[i], translate);
  6635. }
  6636. setTranslate(el.querySelector(SELECTOR_SLIDER_HANDLE), translate);
  6637. };
  6638. /**
  6639. * 关闭滑动菜单
  6640. * @param {Object} el
  6641. */
  6642. $.swipeoutClose = function(el) {
  6643. if (!el) return;
  6644. var classList = el.classList;
  6645. if (!classList.contains(CLASS_SELECTED)) return;
  6646. var direction = el.querySelector(SELECTOR_SLIDER_RIGHT + SELECTOR_SELECTED) ? 'right' : 'left';
  6647. var swipeoutAction = el.querySelector($.classSelector(".slider-" + direction));
  6648. if (!swipeoutAction) return;
  6649. swipeoutAction.classList.remove(CLASS_SELECTED);
  6650. classList.remove(CLASS_SELECTED);
  6651. classList.add(CLASS_TRANSITIONING);
  6652. var buttons = swipeoutAction.querySelectorAll(SELECTOR_BUTTON);
  6653. var swipeoutWidth = swipeoutAction.offsetWidth;
  6654. var length = buttons.length;
  6655. var button;
  6656. setTranslate(el.querySelector(SELECTOR_SLIDER_HANDLE), 0);
  6657. for (var i = 0; i < length; i++) {
  6658. button = buttons[i];
  6659. if (direction === 'right') {
  6660. setTranslate(button, (-button.offsetLeft));
  6661. } else {
  6662. setTranslate(button, (swipeoutWidth - button.offsetWidth - button.offsetLeft));
  6663. }
  6664. }
  6665. };
  6666. window.addEventListener($.EVENT_END, function(event) { //使用touchend来取消高亮,避免一次点击既不触发tap,doubletap,longtap的事件
  6667. if (!cell) {
  6668. return;
  6669. }
  6670. toggleActive(false);
  6671. sliderHandle && toggleEvents(cell, true);
  6672. });
  6673. window.addEventListener($.EVENT_CANCEL, function(event) { //使用touchcancel来取消高亮,避免一次点击既不触发tap,doubletap,longtap的事件
  6674. if (!cell) {
  6675. return;
  6676. }
  6677. toggleActive(false);
  6678. sliderHandle && toggleEvents(cell, true);
  6679. });
  6680. var radioOrCheckboxClick = function(event) {
  6681. var type = event.target && event.target.type || '';
  6682. if (type === 'radio' || type === 'checkbox') {
  6683. return;
  6684. }
  6685. var classList = cell.classList;
  6686. if (classList.contains('mui-radio')) {
  6687. var input = cell.querySelector('input[type=radio]');
  6688. if (input) {
  6689. // input.click();
  6690. if (!input.disabled && !input.readOnly) {
  6691. input.checked = !input.checked;
  6692. $.trigger(input, 'change');
  6693. }
  6694. }
  6695. } else if (classList.contains('mui-checkbox')) {
  6696. var input = cell.querySelector('input[type=checkbox]');
  6697. if (input) {
  6698. // input.click();
  6699. if (!input.disabled && !input.readOnly) {
  6700. input.checked = !input.checked;
  6701. $.trigger(input, 'change');
  6702. }
  6703. }
  6704. }
  6705. };
  6706. //fixed hashchange(android)
  6707. window.addEventListener($.EVENT_CLICK, function(e) {
  6708. if (cell && cell.classList.contains('mui-collapse')) {
  6709. e.preventDefault();
  6710. }
  6711. });
  6712. window.addEventListener('doubletap', function(event) {
  6713. if (cell) {
  6714. radioOrCheckboxClick(event);
  6715. }
  6716. });
  6717. var preventDefaultException = /^(INPUT|TEXTAREA|BUTTON|SELECT)$/;
  6718. window.addEventListener('tap', function(event) {
  6719. if (!cell) {
  6720. return;
  6721. }
  6722. var isExpand = false;
  6723. var classList = cell.classList;
  6724. var ul = cell.parentNode;
  6725. if (ul && ul.classList.contains(CLASS_RADIO_VIEW)) {
  6726. if (classList.contains(CLASS_SELECTED)) {
  6727. return;
  6728. }
  6729. var selected = ul.querySelector('li' + SELECTOR_SELECTED);
  6730. if (selected) {
  6731. selected.classList.remove(CLASS_SELECTED);
  6732. }
  6733. classList.add(CLASS_SELECTED);
  6734. $.trigger(cell, 'selected', {
  6735. el: cell
  6736. });
  6737. return;
  6738. }
  6739. if (classList.contains('mui-collapse') && !cell.parentNode.classList.contains('mui-unfold')) {
  6740. if (!preventDefaultException.test(event.target.tagName)) {
  6741. event.detail.gesture.preventDefault();
  6742. }
  6743. if (!classList.contains(CLASS_ACTIVE)) { //展开时,需要收缩其他同类
  6744. var collapse = cell.parentNode.querySelector('.mui-collapse.mui-active');
  6745. if (collapse) {
  6746. collapse.classList.remove(CLASS_ACTIVE);
  6747. }
  6748. isExpand = true;
  6749. }
  6750. classList.toggle(CLASS_ACTIVE);
  6751. if (isExpand) {
  6752. //触发展开事件
  6753. $.trigger(cell, 'expand');
  6754. //scroll
  6755. //暂不滚动
  6756. // var offsetTop = $.offset(cell).top;
  6757. // var scrollTop = document.body.scrollTop;
  6758. // var height = window.innerHeight;
  6759. // var offsetHeight = cell.offsetHeight;
  6760. // var cellHeight = (offsetTop - scrollTop + offsetHeight);
  6761. // if (offsetHeight > height) {
  6762. // $.scrollTo(offsetTop, 300);
  6763. // } else if (cellHeight > height) {
  6764. // $.scrollTo(cellHeight - height + scrollTop, 300);
  6765. // }
  6766. }
  6767. } else {
  6768. radioOrCheckboxClick(event);
  6769. }
  6770. });
  6771. })(mui, window, document);
  6772. (function($, window) {
  6773. /**
  6774. * 警告消息框
  6775. */
  6776. $.alert = function(message, title, btnValue, callback) {
  6777. if ($.os.plus) {
  6778. if (typeof message === 'undefined') {
  6779. return;
  6780. } else {
  6781. if (typeof title === 'function') {
  6782. callback = title;
  6783. title = null;
  6784. btnValue = '确定';
  6785. } else if (typeof btnValue === 'function') {
  6786. callback = btnValue;
  6787. btnValue = null;
  6788. }
  6789. $.plusReady(function() {
  6790. plus.nativeUI.alert(message, callback, title, btnValue);
  6791. });
  6792. }
  6793. } else {
  6794. //TODO H5版本
  6795. window.alert(message);
  6796. }
  6797. };
  6798. })(mui, window);
  6799. (function($, window) {
  6800. /**
  6801. * 确认消息框
  6802. */
  6803. $.confirm = function(message, title, btnArray, callback) {
  6804. if ($.os.plus) {
  6805. if (typeof message === 'undefined') {
  6806. return;
  6807. } else {
  6808. if (typeof title === 'function') {
  6809. callback = title;
  6810. title = null;
  6811. btnArray = null;
  6812. } else if (typeof btnArray === 'function') {
  6813. callback = btnArray;
  6814. btnArray = null;
  6815. }
  6816. $.plusReady(function() {
  6817. plus.nativeUI.confirm(message, callback, title, btnArray);
  6818. });
  6819. }
  6820. } else {
  6821. //H5版本,0为确认,1为取消
  6822. if (window.confirm(message)) {
  6823. callback({
  6824. index: 0
  6825. });
  6826. } else {
  6827. callback({
  6828. index: 1
  6829. });
  6830. }
  6831. }
  6832. };
  6833. })(mui, window);
  6834. (function($, window) {
  6835. /**
  6836. * 输入对话框
  6837. */
  6838. $.prompt = function(text, defaultText, title, btnArray, callback) {
  6839. if ($.os.plus) {
  6840. if (typeof message === 'undefined') {
  6841. return;
  6842. } else {
  6843. if (typeof defaultText === 'function') {
  6844. callback = defaultText;
  6845. defaultText = null;
  6846. title = null;
  6847. btnArray = null;
  6848. } else if (typeof title === 'function') {
  6849. callback = title;
  6850. title = null;
  6851. btnArray = null;
  6852. } else if (typeof btnArray === 'function') {
  6853. callback = btnArray;
  6854. btnArray = null;
  6855. }
  6856. $.plusReady(function() {
  6857. plus.nativeUI.prompt(text, callback, title, defaultText, btnArray);
  6858. });
  6859. }
  6860. } else {
  6861. //H5版本(确认index为0,取消index为1)
  6862. var result = window.prompt(text);
  6863. if (result) {
  6864. callback({
  6865. index: 0,
  6866. value: result
  6867. });
  6868. } else {
  6869. callback({
  6870. index: 1,
  6871. value: ''
  6872. });
  6873. }
  6874. }
  6875. };
  6876. })(mui, window);
  6877. (function($, window) {
  6878. var CLASS_ACTIVE = 'mui-active';
  6879. /**
  6880. * 自动消失提示框
  6881. */
  6882. $.toast = function(message,options) {
  6883. var durations = {
  6884. 'long': 3500,
  6885. 'short': 2000
  6886. };
  6887. //计算显示时间
  6888. options = $.extend({
  6889. duration: 'short'
  6890. }, options || {});
  6891. if ($.os.plus && options.type !== 'div') {
  6892. //默认显示在底部;
  6893. $.plusReady(function() {
  6894. plus.nativeUI.toast(message, {
  6895. verticalAlign: 'bottom',
  6896. duration:options.duration
  6897. });
  6898. });
  6899. } else {
  6900. if (typeof options.duration === 'number') {
  6901. duration = options.duration>0 ? options.duration:durations['short'];
  6902. } else {
  6903. duration = durations[options.duration];
  6904. }
  6905. if (!duration) {
  6906. duration = durations['short'];
  6907. }
  6908. var toast = document.createElement('div');
  6909. toast.classList.add('mui-toast-container');
  6910. toast.innerHTML = '<div class="' + 'mui-toast-message' + '">' + message + '</div>';
  6911. toast.addEventListener('webkitTransitionEnd', function() {
  6912. if (!toast.classList.contains(CLASS_ACTIVE)) {
  6913. toast.parentNode.removeChild(toast);
  6914. toast = null;
  6915. }
  6916. });
  6917. //点击则自动消失
  6918. toast.addEventListener('click', function() {
  6919. toast.parentNode.removeChild(toast);
  6920. toast = null;
  6921. });
  6922. document.body.appendChild(toast);
  6923. toast.offsetHeight;
  6924. toast.classList.add(CLASS_ACTIVE);
  6925. setTimeout(function() {
  6926. toast && toast.classList.remove(CLASS_ACTIVE);
  6927. }, duration);
  6928. return {
  6929. isVisible: function() {return !!toast;}
  6930. }
  6931. }
  6932. };
  6933. })(mui, window);
  6934. /**
  6935. * Popup(alert,confirm,prompt)
  6936. * @param {Object} $
  6937. * @param {Object} window
  6938. * @param {Object} document
  6939. */
  6940. (function($, window, document) {
  6941. var CLASS_POPUP = 'mui-popup';
  6942. var CLASS_POPUP_BACKDROP = 'mui-popup-backdrop';
  6943. var CLASS_POPUP_IN = 'mui-popup-in';
  6944. var CLASS_POPUP_OUT = 'mui-popup-out';
  6945. var CLASS_POPUP_INNER = 'mui-popup-inner';
  6946. var CLASS_POPUP_TITLE = 'mui-popup-title';
  6947. var CLASS_POPUP_TEXT = 'mui-popup-text';
  6948. var CLASS_POPUP_INPUT = 'mui-popup-input';
  6949. var CLASS_POPUP_BUTTONS = 'mui-popup-buttons';
  6950. var CLASS_POPUP_BUTTON = 'mui-popup-button';
  6951. var CLASS_POPUP_BUTTON_BOLD = 'mui-popup-button-bold';
  6952. var CLASS_POPUP_BACKDROP = 'mui-popup-backdrop';
  6953. var CLASS_ACTIVE = 'mui-active';
  6954. var popupStack = [];
  6955. var backdrop = (function() {
  6956. var element = document.createElement('div');
  6957. element.classList.add(CLASS_POPUP_BACKDROP);
  6958. element.addEventListener($.EVENT_MOVE, $.preventDefault);
  6959. element.addEventListener('webkitTransitionEnd', function() {
  6960. if (!this.classList.contains(CLASS_ACTIVE)) {
  6961. element.parentNode && element.parentNode.removeChild(element);
  6962. }
  6963. });
  6964. return element;
  6965. }());
  6966. var createInput = function(placeholder) {
  6967. return '<div class="' + CLASS_POPUP_INPUT + '"><input type="text" autofocus placeholder="' + (placeholder || '') + '"/></div>';
  6968. };
  6969. var createInner = function(message, title, extra) {
  6970. 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>';
  6971. };
  6972. var createButtons = function(btnArray) {
  6973. var length = btnArray.length;
  6974. var btns = [];
  6975. for (var i = 0; i < length; i++) {
  6976. btns.push('<span class="' + CLASS_POPUP_BUTTON + (i === length - 1 ? (' ' + CLASS_POPUP_BUTTON_BOLD) : '') + '">' + btnArray[i] + '</span>');
  6977. }
  6978. return '<div class="' + CLASS_POPUP_BUTTONS + '">' + btns.join('') + '</div>';
  6979. };
  6980. var createPopup = function(html, callback) {
  6981. var popupElement = document.createElement('div');
  6982. popupElement.className = CLASS_POPUP;
  6983. popupElement.innerHTML = html;
  6984. var removePopupElement = function() {
  6985. popupElement.parentNode && popupElement.parentNode.removeChild(popupElement);
  6986. popupElement = null;
  6987. };
  6988. popupElement.addEventListener($.EVENT_MOVE, $.preventDefault);
  6989. popupElement.addEventListener('webkitTransitionEnd', function(e) {
  6990. if (popupElement && e.target === popupElement && popupElement.classList.contains(CLASS_POPUP_OUT)) {
  6991. removePopupElement();
  6992. }
  6993. });
  6994. popupElement.style.display = 'block';
  6995. document.body.appendChild(popupElement);
  6996. popupElement.offsetHeight;
  6997. popupElement.classList.add(CLASS_POPUP_IN);
  6998. if (!backdrop.classList.contains(CLASS_ACTIVE)) {
  6999. backdrop.style.display = 'block';
  7000. document.body.appendChild(backdrop);
  7001. backdrop.offsetHeight;
  7002. backdrop.classList.add(CLASS_ACTIVE);
  7003. }
  7004. var btns = $.qsa('.' + CLASS_POPUP_BUTTON, popupElement);
  7005. var input = popupElement.querySelector('.' + CLASS_POPUP_INPUT + ' input');
  7006. var popup = {
  7007. element: popupElement,
  7008. close: function(index, animate) {
  7009. if (popupElement) {
  7010. var result = callback && callback({
  7011. index: index || 0,
  7012. value: input && input.value || ''
  7013. });
  7014. if (result === false) { //返回false则不关闭当前popup
  7015. return;
  7016. }
  7017. if (animate !== false) {
  7018. popupElement.classList.remove(CLASS_POPUP_IN);
  7019. popupElement.classList.add(CLASS_POPUP_OUT);
  7020. } else {
  7021. removePopupElement();
  7022. }
  7023. popupStack.pop();
  7024. //如果还有其他popup,则不remove backdrop
  7025. if (popupStack.length) {
  7026. popupStack[popupStack.length - 1]['show'](animate);
  7027. } else {
  7028. backdrop.classList.remove(CLASS_ACTIVE);
  7029. }
  7030. }
  7031. }
  7032. };
  7033. var handleEvent = function(e) {
  7034. popup.close(btns.indexOf(e.target));
  7035. };
  7036. $(popupElement).on('tap', '.' + CLASS_POPUP_BUTTON, handleEvent);
  7037. if (popupStack.length) {
  7038. popupStack[popupStack.length - 1]['hide']();
  7039. }
  7040. popupStack.push({
  7041. close: popup.close,
  7042. show: function(animate) {
  7043. popupElement.style.display = 'block';
  7044. popupElement.offsetHeight;
  7045. popupElement.classList.add(CLASS_POPUP_IN);
  7046. },
  7047. hide: function() {
  7048. popupElement.style.display = 'none';
  7049. popupElement.classList.remove(CLASS_POPUP_IN);
  7050. }
  7051. });
  7052. return popup;
  7053. };
  7054. var createAlert = function(message, title, btnValue, callback, type) {
  7055. if (typeof message === 'undefined') {
  7056. return;
  7057. } else {
  7058. if (typeof title === 'function') {
  7059. callback = title;
  7060. type = btnValue;
  7061. title = null;
  7062. btnValue = null;
  7063. } else if (typeof btnValue === 'function') {
  7064. type = callback;
  7065. callback = btnValue;
  7066. btnValue = null;
  7067. }
  7068. }
  7069. if (!$.os.plus || type === 'div') {
  7070. return createPopup(createInner(message, title || '提示') + createButtons([btnValue || '确定']), callback);
  7071. }
  7072. return plus.nativeUI.alert(message, callback, title || '提示', btnValue || '确定');
  7073. };
  7074. var createConfirm = function(message, title, btnArray, callback, type) {
  7075. if (typeof message === 'undefined') {
  7076. return;
  7077. } else {
  7078. if (typeof title === 'function') {
  7079. callback = title;
  7080. type = btnArray;
  7081. title = null;
  7082. btnArray = null;
  7083. } else if (typeof btnArray === 'function') {
  7084. type = callback;
  7085. callback = btnArray;
  7086. btnArray = null;
  7087. }
  7088. }
  7089. if (!$.os.plus || type === 'div') {
  7090. return createPopup(createInner(message, title || '提示') + createButtons(btnArray || ['取消', '确认']), callback);
  7091. }
  7092. return plus.nativeUI.confirm(message, callback, title, btnArray || ['取消', '确认']);
  7093. };
  7094. var createPrompt = function(message, placeholder, title, btnArray, callback, type) {
  7095. if (typeof message === 'undefined') {
  7096. return;
  7097. } else {
  7098. if (typeof placeholder === 'function') {
  7099. callback = placeholder;
  7100. type = title;
  7101. placeholder = null;
  7102. title = null;
  7103. btnArray = null;
  7104. } else if (typeof title === 'function') {
  7105. callback = title;
  7106. type = btnArray;
  7107. title = null;
  7108. btnArray = null;
  7109. } else if (typeof btnArray === 'function') {
  7110. type = callback;
  7111. callback = btnArray;
  7112. btnArray = null;
  7113. }
  7114. }
  7115. if (!$.os.plus || type === 'div') {
  7116. return createPopup(createInner(message, title || '提示', createInput(placeholder)) + createButtons(btnArray || ['取消', '确认']), callback);
  7117. }
  7118. return plus.nativeUI.prompt(message, callback, title || '提示', placeholder, btnArray || ['取消', '确认']);
  7119. };
  7120. var closePopup = function() {
  7121. if (popupStack.length) {
  7122. popupStack[popupStack.length - 1]['close']();
  7123. return true;
  7124. } else {
  7125. return false;
  7126. }
  7127. };
  7128. var closePopups = function() {
  7129. while (popupStack.length) {
  7130. popupStack[popupStack.length - 1]['close']();
  7131. }
  7132. };
  7133. $.closePopup = closePopup;
  7134. $.closePopups = closePopups;
  7135. $.alert = createAlert;
  7136. $.confirm = createConfirm;
  7137. $.prompt = createPrompt;
  7138. })(mui, window, document);
  7139. (function($, document) {
  7140. var CLASS_PROGRESSBAR = 'mui-progressbar';
  7141. var CLASS_PROGRESSBAR_IN = 'mui-progressbar-in';
  7142. var CLASS_PROGRESSBAR_OUT = 'mui-progressbar-out';
  7143. var CLASS_PROGRESSBAR_INFINITE = 'mui-progressbar-infinite';
  7144. var SELECTOR_PROGRESSBAR = '.mui-progressbar';
  7145. var _findProgressbar = function(container) {
  7146. container = $(container || 'body');
  7147. if (container.length === 0) return;
  7148. container = container[0];
  7149. if (container.classList.contains(CLASS_PROGRESSBAR)) {
  7150. return container;
  7151. }
  7152. var progressbars = container.querySelectorAll(SELECTOR_PROGRESSBAR);
  7153. if (progressbars) {
  7154. for (var i = 0, len = progressbars.length; i < len; i++) {
  7155. var progressbar = progressbars[i];
  7156. if (progressbar.parentNode === container) {
  7157. return progressbar;
  7158. }
  7159. }
  7160. }
  7161. };
  7162. /**
  7163. * 创建并显示进度条
  7164. * @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
  7165. * @param {Object} progress 可选,undefined表示循环,数字表示具体进度
  7166. * @param {Object} color 可选,指定颜色样式(目前暂未提供实际样式,可暂时不暴露此参数)
  7167. */
  7168. var showProgressbar = function(container, progress, color) {
  7169. if (typeof container === 'number') {
  7170. color = progress;
  7171. progress = container;
  7172. container = 'body';
  7173. }
  7174. container = $(container || 'body');
  7175. if (container.length === 0) return;
  7176. container = container[0];
  7177. var progressbar;
  7178. if (container.classList.contains(CLASS_PROGRESSBAR)) {
  7179. progressbar = container;
  7180. } else {
  7181. var progressbars = container.querySelectorAll(SELECTOR_PROGRESSBAR + ':not(.' + CLASS_PROGRESSBAR_OUT + ')');
  7182. if (progressbars) {
  7183. for (var i = 0, len = progressbars.length; i < len; i++) {
  7184. var _progressbar = progressbars[i];
  7185. if (_progressbar.parentNode === container) {
  7186. progressbar = _progressbar;
  7187. break;
  7188. }
  7189. }
  7190. }
  7191. if (!progressbar) {
  7192. progressbar = document.createElement('span');
  7193. progressbar.className = CLASS_PROGRESSBAR + ' ' + CLASS_PROGRESSBAR_IN + (typeof progress !== 'undefined' ? '' : (' ' + CLASS_PROGRESSBAR_INFINITE)) + (color ? (' ' + CLASS_PROGRESSBAR + '-' + color) : '');
  7194. if (typeof progress !== 'undefined') {
  7195. progressbar.innerHTML = '<span></span>';
  7196. }
  7197. container.appendChild(progressbar);
  7198. } else {
  7199. progressbar.classList.add(CLASS_PROGRESSBAR_IN);
  7200. }
  7201. }
  7202. if (progress) setProgressbar(container, progress);
  7203. return progressbar;
  7204. };
  7205. /**
  7206. * 关闭进度条
  7207. * @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
  7208. */
  7209. var hideProgressbar = function(container) {
  7210. var progressbar = _findProgressbar(container);
  7211. if (!progressbar) {
  7212. return;
  7213. }
  7214. var classList = progressbar.classList;
  7215. if (!classList.contains(CLASS_PROGRESSBAR_IN) || classList.contains(CLASS_PROGRESSBAR_OUT)) {
  7216. return;
  7217. }
  7218. classList.remove(CLASS_PROGRESSBAR_IN);
  7219. classList.add(CLASS_PROGRESSBAR_OUT);
  7220. progressbar.addEventListener('webkitAnimationEnd', function() {
  7221. progressbar.parentNode && progressbar.parentNode.removeChild(progressbar);
  7222. progressbar = null;
  7223. });
  7224. return;
  7225. };
  7226. /**
  7227. * 设置指定进度条进度
  7228. * @param {Object} container 可选,默认body,支持selector,DOM Node,mui wrapper
  7229. * @param {Object} progress 可选,默认0 取值范围[0-100]
  7230. * @param {Object} speed 进度条动画时间
  7231. */
  7232. var setProgressbar = function(container, progress, speed) {
  7233. if (typeof container === 'number') {
  7234. speed = progress;
  7235. progress = container;
  7236. container = false;
  7237. }
  7238. var progressbar = _findProgressbar(container);
  7239. if (!progressbar || progressbar.classList.contains(CLASS_PROGRESSBAR_INFINITE)) {
  7240. return;
  7241. }
  7242. if (progress) progress = Math.min(Math.max(progress, 0), 100);
  7243. progressbar.offsetHeight;
  7244. var span = progressbar.querySelector('span');
  7245. if (span) {
  7246. var style = span.style;
  7247. style.webkitTransform = 'translate3d(' + (-100 + progress) + '%,0,0)';
  7248. if (typeof speed !== 'undefined') {
  7249. style.webkitTransitionDuration = speed + 'ms';
  7250. } else {
  7251. style.webkitTransitionDuration = '';
  7252. }
  7253. }
  7254. return progressbar;
  7255. };
  7256. $.fn.progressbar = function(options) {
  7257. var progressbarApis = [];
  7258. options = options || {};
  7259. this.each(function() {
  7260. var self = this;
  7261. var progressbarApi = self.mui_plugin_progressbar;
  7262. if (!progressbarApi) {
  7263. self.mui_plugin_progressbar = progressbarApi = {
  7264. options: options,
  7265. setOptions: function(options) {
  7266. this.options = options;
  7267. },
  7268. show: function() {
  7269. return showProgressbar(self, this.options.progress, this.options.color);
  7270. },
  7271. setProgress: function(progress) {
  7272. return setProgressbar(self, progress);
  7273. },
  7274. hide: function() {
  7275. return hideProgressbar(self);
  7276. }
  7277. };
  7278. } else if (options) {
  7279. progressbarApi.setOptions(options);
  7280. }
  7281. progressbarApis.push(progressbarApi);
  7282. });
  7283. return progressbarApis.length === 1 ? progressbarApis[0] : progressbarApis;
  7284. };
  7285. // $.setProgressbar = setProgressbar;
  7286. // $.showProgressbar = showProgressbar;
  7287. // $.hideProgressbar = hideProgressbar;
  7288. })(mui, document);
  7289. /**
  7290. * Input(TODO resize)
  7291. * @param {type} $
  7292. * @param {type} window
  7293. * @param {type} document
  7294. * @returns {undefined}
  7295. */
  7296. (function($, window, document) {
  7297. var CLASS_ICON = 'mui-icon';
  7298. var CLASS_ICON_CLEAR = 'mui-icon-clear';
  7299. var CLASS_ICON_SPEECH = 'mui-icon-speech';
  7300. var CLASS_ICON_SEARCH = 'mui-icon-search';
  7301. var CLASS_ICON_PASSWORD = 'mui-icon-eye';
  7302. var CLASS_INPUT_ROW = 'mui-input-row';
  7303. var CLASS_PLACEHOLDER = 'mui-placeholder';
  7304. var CLASS_TOOLTIP = 'mui-tooltip';
  7305. var CLASS_HIDDEN = 'mui-hidden';
  7306. var CLASS_FOCUSIN = 'mui-focusin';
  7307. var SELECTOR_ICON_CLOSE = '.' + CLASS_ICON_CLEAR;
  7308. var SELECTOR_ICON_SPEECH = '.' + CLASS_ICON_SPEECH;
  7309. var SELECTOR_ICON_PASSWORD = '.' + CLASS_ICON_PASSWORD;
  7310. var SELECTOR_PLACEHOLDER = '.' + CLASS_PLACEHOLDER;
  7311. var SELECTOR_TOOLTIP = '.' + CLASS_TOOLTIP;
  7312. var findRow = function(target) {
  7313. for (; target && target !== document; target = target.parentNode) {
  7314. if (target.classList && target.classList.contains(CLASS_INPUT_ROW)) {
  7315. return target;
  7316. }
  7317. }
  7318. return null;
  7319. };
  7320. var Input = function(element, options) {
  7321. this.element = element;
  7322. this.options = options || {
  7323. actions: 'clear'
  7324. };
  7325. if (~this.options.actions.indexOf('slider')) { //slider
  7326. this.sliderActionClass = CLASS_TOOLTIP + ' ' + CLASS_HIDDEN;
  7327. this.sliderActionSelector = SELECTOR_TOOLTIP;
  7328. } else { //clear,speech,search
  7329. if (~this.options.actions.indexOf('clear')) {
  7330. this.clearActionClass = CLASS_ICON + ' ' + CLASS_ICON_CLEAR + ' ' + CLASS_HIDDEN;
  7331. this.clearActionSelector = SELECTOR_ICON_CLOSE;
  7332. }
  7333. if (~this.options.actions.indexOf('speech')) { //only for 5+
  7334. this.speechActionClass = CLASS_ICON + ' ' + CLASS_ICON_SPEECH;
  7335. this.speechActionSelector = SELECTOR_ICON_SPEECH;
  7336. }
  7337. if (~this.options.actions.indexOf('search')) {
  7338. this.searchActionClass = CLASS_PLACEHOLDER;
  7339. this.searchActionSelector = SELECTOR_PLACEHOLDER;
  7340. }
  7341. if (~this.options.actions.indexOf('password')) {
  7342. this.passwordActionClass = CLASS_ICON + ' ' + CLASS_ICON_PASSWORD;
  7343. this.passwordActionSelector = SELECTOR_ICON_PASSWORD;
  7344. }
  7345. }
  7346. this.init();
  7347. };
  7348. Input.prototype.init = function() {
  7349. this.initAction();
  7350. this.initElementEvent();
  7351. };
  7352. Input.prototype.initAction = function() {
  7353. var self = this;
  7354. var row = self.element.parentNode;
  7355. if (row) {
  7356. if (self.sliderActionClass) {
  7357. self.sliderAction = self.createAction(row, self.sliderActionClass, self.sliderActionSelector);
  7358. } else {
  7359. if (self.searchActionClass) {
  7360. self.searchAction = self.createAction(row, self.searchActionClass, self.searchActionSelector);
  7361. self.searchAction.addEventListener('tap', function(e) {
  7362. $.focus(self.element);
  7363. e.stopPropagation();
  7364. });
  7365. }
  7366. if (self.speechActionClass) {
  7367. self.speechAction = self.createAction(row, self.speechActionClass, self.speechActionSelector);
  7368. self.speechAction.addEventListener('click', $.stopPropagation);
  7369. self.speechAction.addEventListener('tap', function(event) {
  7370. self.speechActionClick(event);
  7371. });
  7372. }
  7373. if (self.clearActionClass) {
  7374. self.clearAction = self.createAction(row, self.clearActionClass, self.clearActionSelector);
  7375. self.clearAction.addEventListener('tap', function(event) {
  7376. self.clearActionClick(event);
  7377. });
  7378. }
  7379. if (self.passwordActionClass) {
  7380. self.passwordAction = self.createAction(row, self.passwordActionClass, self.passwordActionSelector);
  7381. self.passwordAction.addEventListener('tap', function(event) {
  7382. self.passwordActionClick(event);
  7383. });
  7384. }
  7385. }
  7386. }
  7387. };
  7388. Input.prototype.createAction = function(row, actionClass, actionSelector) {
  7389. var action = row.querySelector(actionSelector);
  7390. if (!action) {
  7391. var action = document.createElement('span');
  7392. action.className = actionClass;
  7393. if (actionClass === this.searchActionClass) {
  7394. action.innerHTML = '<span class="' + CLASS_ICON + ' ' + CLASS_ICON_SEARCH + '"></span><span>' + this.element.getAttribute('placeholder') + '</span>';
  7395. this.element.setAttribute('placeholder', '');
  7396. if (this.element.value.trim()) {
  7397. row.classList.add('mui-active');
  7398. }
  7399. }
  7400. row.insertBefore(action, this.element.nextSibling);
  7401. }
  7402. return action;
  7403. };
  7404. Input.prototype.initElementEvent = function() {
  7405. var element = this.element;
  7406. if (this.sliderActionClass) {
  7407. var tooltip = this.sliderAction;
  7408. var timer = null;
  7409. var showTip = function() { //每次重新计算是因为控件可能被隐藏,初始化时计算是不正确的
  7410. tooltip.classList.remove(CLASS_HIDDEN);
  7411. var offsetLeft = element.offsetLeft;
  7412. var width = element.offsetWidth - 28;
  7413. var tooltipWidth = tooltip.offsetWidth;
  7414. var distince = Math.abs(element.max - element.min);
  7415. var scaleWidth = (width / distince) * Math.abs(element.value - element.min);
  7416. tooltip.style.left = (14 + offsetLeft + scaleWidth - tooltipWidth / 2) + 'px';
  7417. tooltip.innerText = element.value;
  7418. if (timer) {
  7419. clearTimeout(timer);
  7420. }
  7421. timer = setTimeout(function() {
  7422. tooltip.classList.add(CLASS_HIDDEN);
  7423. }, 1000);
  7424. };
  7425. element.addEventListener('input', showTip);
  7426. element.addEventListener('tap', showTip);
  7427. element.addEventListener($.EVENT_MOVE, function(e) {
  7428. e.stopPropagation();
  7429. });
  7430. } else {
  7431. if (this.clearActionClass) {
  7432. var action = this.clearAction;
  7433. if (!action) {
  7434. return;
  7435. }
  7436. $.each(['keyup', 'change', 'input', 'focus', 'cut', 'paste'], function(index, type) {
  7437. (function(type) {
  7438. element.addEventListener(type, function() {
  7439. action.classList[element.value.trim() ? 'remove' : 'add'](CLASS_HIDDEN);
  7440. });
  7441. })(type);
  7442. });
  7443. element.addEventListener('blur', function() {
  7444. action.classList.add(CLASS_HIDDEN);
  7445. });
  7446. }
  7447. if (this.searchActionClass) {
  7448. element.addEventListener('focus', function() {
  7449. element.parentNode.classList.add('mui-active');
  7450. });
  7451. element.addEventListener('blur', function() {
  7452. if (!element.value.trim()) {
  7453. element.parentNode.classList.remove('mui-active');
  7454. }
  7455. });
  7456. }
  7457. }
  7458. };
  7459. Input.prototype.setPlaceholder = function(text) {
  7460. if (this.searchActionClass) {
  7461. var placeholder = this.element.parentNode.querySelector(SELECTOR_PLACEHOLDER);
  7462. placeholder && (placeholder.getElementsByTagName('span')[1].innerText = text);
  7463. } else {
  7464. this.element.setAttribute('placeholder', text);
  7465. }
  7466. };
  7467. Input.prototype.passwordActionClick = function(event) {
  7468. if (this.element.type === 'text') {
  7469. this.element.type = 'password';
  7470. } else {
  7471. this.element.type = 'text';
  7472. }
  7473. this.passwordAction.classList.toggle('mui-active');
  7474. event.preventDefault();
  7475. };
  7476. Input.prototype.clearActionClick = function(event) {
  7477. var self = this;
  7478. self.element.value = '';
  7479. $.focus(self.element);
  7480. self.clearAction.classList.add(CLASS_HIDDEN);
  7481. event.preventDefault();
  7482. };
  7483. Input.prototype.speechActionClick = function(event) {
  7484. if (window.plus) {
  7485. var self = this;
  7486. var oldValue = self.element.value;
  7487. self.element.value = '';
  7488. document.body.classList.add(CLASS_FOCUSIN);
  7489. plus.speech.startRecognize({
  7490. engine: 'iFly'
  7491. }, function(s) {
  7492. self.element.value += s;
  7493. $.focus(self.element);
  7494. plus.speech.stopRecognize();
  7495. $.trigger(self.element, 'recognized', {
  7496. value: self.element.value
  7497. });
  7498. if (oldValue !== self.element.value) {
  7499. $.trigger(self.element, 'change');
  7500. $.trigger(self.element, 'input');
  7501. }
  7502. // document.body.classList.remove(CLASS_FOCUSIN);
  7503. }, function(e) {
  7504. document.body.classList.remove(CLASS_FOCUSIN);
  7505. });
  7506. } else {
  7507. alert('only for 5+');
  7508. }
  7509. event.preventDefault();
  7510. };
  7511. $.fn.input = function(options) {
  7512. var inputApis = [];
  7513. this.each(function() {
  7514. var inputApi = null;
  7515. var actions = [];
  7516. var row = findRow(this.parentNode);
  7517. if (this.type === 'range' && row.classList.contains('mui-input-range')) {
  7518. actions.push('slider');
  7519. } else {
  7520. var classList = this.classList;
  7521. if (classList.contains('mui-input-clear')) {
  7522. actions.push('clear');
  7523. }
  7524. if (!($.os.android && $.os.stream) && classList.contains('mui-input-speech')) {
  7525. actions.push('speech');
  7526. }
  7527. if (classList.contains('mui-input-password')) {
  7528. actions.push('password');
  7529. }
  7530. if (this.type === 'search' && row.classList.contains('mui-search')) {
  7531. actions.push('search');
  7532. }
  7533. }
  7534. var id = this.getAttribute('data-input-' + actions[0]);
  7535. if (!id) {
  7536. id = ++$.uuid;
  7537. inputApi = $.data[id] = new Input(this, {
  7538. actions: actions.join(',')
  7539. });
  7540. for (var i = 0, len = actions.length; i < len; i++) {
  7541. this.setAttribute('data-input-' + actions[i], id);
  7542. }
  7543. } else {
  7544. inputApi = $.data[id];
  7545. }
  7546. inputApis.push(inputApi);
  7547. });
  7548. return inputApis.length === 1 ? inputApis[0] : inputApis;
  7549. };
  7550. $.ready(function() {
  7551. $('.mui-input-row input').input();
  7552. });
  7553. })(mui, window, document);
  7554. (function($, window) {
  7555. var CLASS_ACTIVE = 'mui-active';
  7556. var rgbaRegex = /^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/;
  7557. var getColor = function(colorStr) {
  7558. var matches = colorStr.match(rgbaRegex);
  7559. if (matches && matches.length === 5) {
  7560. return [
  7561. matches[1],
  7562. matches[2],
  7563. matches[3],
  7564. matches[4]
  7565. ];
  7566. }
  7567. return [];
  7568. };
  7569. var Transparent = function(element, options) {
  7570. this.element = element;
  7571. this.options = $.extend({
  7572. top: 0, //距离顶部高度(到达该高度即触发)
  7573. offset: 150, //滚动透明距离档设定top值后offset也会随着top向下延伸
  7574. duration: 16, //过渡时间
  7575. scrollby: window
  7576. }, options || {});
  7577. this.scrollByElem = this.options.scrollby || window;
  7578. if (!this.scrollByElem) {
  7579. throw new Error("监听滚动的元素不存在");
  7580. }
  7581. this.isNativeScroll = false;
  7582. if (this.scrollByElem === window) {
  7583. this.isNativeScroll = true;
  7584. } else if (!~this.scrollByElem.className.indexOf('mui-scroll-wrapper')) {
  7585. this.isNativeScroll = true;
  7586. }
  7587. this._style = this.element.style;
  7588. this._bgColor = this._style.backgroundColor;
  7589. var color = getColor(mui.getStyles(this.element, 'backgroundColor'));
  7590. if (color.length) {
  7591. this._R = color[0];
  7592. this._G = color[1];
  7593. this._B = color[2];
  7594. this._A = parseFloat(color[3]);
  7595. this.lastOpacity = this._A;
  7596. this._bufferFn = $.buffer(this.handleScroll, this.options.duration, this);
  7597. this.initEvent();
  7598. } else {
  7599. throw new Error("元素背景颜色必须为RGBA");
  7600. }
  7601. };
  7602. Transparent.prototype.initEvent = function() {
  7603. this.scrollByElem.addEventListener('scroll', this._bufferFn);
  7604. if (this.isNativeScroll) { //原生scroll
  7605. this.scrollByElem.addEventListener($.EVENT_MOVE, this._bufferFn);
  7606. }
  7607. }
  7608. Transparent.prototype.handleScroll = function(e) {
  7609. var y = window.scrollY;
  7610. if (!this.isNativeScroll && e && e.detail) {
  7611. y = -e.detail.y;
  7612. }
  7613. var opacity = (y - this.options.top) / this.options.offset + this._A;
  7614. opacity = Math.min(Math.max(this._A, opacity), 1);
  7615. this._style.backgroundColor = 'rgba(' + this._R + ',' + this._G + ',' + this._B + ',' + opacity + ')';
  7616. if (opacity > this._A) {
  7617. this.element.classList.add(CLASS_ACTIVE);
  7618. } else {
  7619. this.element.classList.remove(CLASS_ACTIVE);
  7620. }
  7621. if (this.lastOpacity !== opacity) {
  7622. $.trigger(this.element, 'alpha', {
  7623. alpha: opacity
  7624. });
  7625. this.lastOpacity = opacity;
  7626. }
  7627. };
  7628. Transparent.prototype.destory = function() {
  7629. this.scrollByElem.removeEventListener('scroll', this._bufferFn);
  7630. this.scrollByElem.removeEventListener($.EVENT_MOVE, this._bufferFn);
  7631. this.element.style.backgroundColor = this._bgColor;
  7632. this.element.mui_plugin_transparent = null;
  7633. };
  7634. $.fn.transparent = function(options) {
  7635. options = options || {};
  7636. var transparentApis = [];
  7637. this.each(function() {
  7638. var transparentApi = this.mui_plugin_transparent;
  7639. if (!transparentApi) {
  7640. var top = this.getAttribute('data-top');
  7641. var offset = this.getAttribute('data-offset');
  7642. var duration = this.getAttribute('data-duration');
  7643. var scrollby = this.getAttribute('data-scrollby');
  7644. if (top !== null && typeof options.top === 'undefined') {
  7645. options.top = top;
  7646. }
  7647. if (offset !== null && typeof options.offset === 'undefined') {
  7648. options.offset = offset;
  7649. }
  7650. if (duration !== null && typeof options.duration === 'undefined') {
  7651. options.duration = duration;
  7652. }
  7653. if (scrollby !== null && typeof options.scrollby === 'undefined') {
  7654. options.scrollby = document.querySelector(scrollby) || window;
  7655. }
  7656. transparentApi = this.mui_plugin_transparent = new Transparent(this, options);
  7657. }
  7658. transparentApis.push(transparentApi);
  7659. });
  7660. return transparentApis.length === 1 ? transparentApis[0] : transparentApis;
  7661. };
  7662. $.ready(function() {
  7663. $('.mui-bar-transparent').transparent();
  7664. });
  7665. })(mui, window);
  7666. /**
  7667. * 数字输入框
  7668. * varstion 1.0.1
  7669. * by Houfeng
  7670. * Houfeng@DCloud.io
  7671. */
  7672. (function($) {
  7673. var touchSupport = ('ontouchstart' in document);
  7674. var tapEventName = touchSupport ? 'tap' : 'click';
  7675. var changeEventName = 'change';
  7676. var holderClassName = 'mui-numbox';
  7677. var plusClassSelector = '.mui-btn-numbox-plus,.mui-numbox-btn-plus';
  7678. var minusClassSelector = '.mui-btn-numbox-minus,.mui-numbox-btn-minus';
  7679. var inputClassSelector = '.mui-input-numbox,.mui-numbox-input';
  7680. var Numbox = $.Numbox = $.Class.extend({
  7681. /**
  7682. * 构造函数
  7683. **/
  7684. init: function(holder, options) {
  7685. var self = this;
  7686. if (!holder) {
  7687. throw "构造 numbox 时缺少容器元素";
  7688. }
  7689. self.holder = holder;
  7690. options = options || {};
  7691. options.step = parseInt(options.step || 1);
  7692. self.options = options;
  7693. self.input = $.qsa(inputClassSelector, self.holder)[0];
  7694. self.plus = $.qsa(plusClassSelector, self.holder)[0];
  7695. self.minus = $.qsa(minusClassSelector, self.holder)[0];
  7696. self.checkValue();
  7697. self.initEvent();
  7698. },
  7699. /**
  7700. * 初始化事件绑定
  7701. **/
  7702. initEvent: function() {
  7703. var self = this;
  7704. self.plus.addEventListener(tapEventName, function(event) {
  7705. var val = parseInt(self.input.value) + self.options.step;
  7706. self.input.value = val.toString();
  7707. $.trigger(self.input, changeEventName, null);
  7708. });
  7709. self.minus.addEventListener(tapEventName, function(event) {
  7710. var val = parseInt(self.input.value) - self.options.step;
  7711. self.input.value = val.toString();
  7712. $.trigger(self.input, changeEventName, null);
  7713. });
  7714. self.input.addEventListener(changeEventName, function(event) {
  7715. self.checkValue();
  7716. var val = parseInt(self.input.value);
  7717. //触发顶层容器
  7718. $.trigger(self.holder, changeEventName, {
  7719. value: val
  7720. });
  7721. });
  7722. },
  7723. /**
  7724. * 获取当前值
  7725. **/
  7726. getValue: function() {
  7727. var self = this;
  7728. return parseInt(self.input.value);
  7729. },
  7730. /**
  7731. * 验证当前值是法合法
  7732. **/
  7733. checkValue: function() {
  7734. var self = this;
  7735. var val = self.input.value;
  7736. if (val == null || val == '' || isNaN(val)) {
  7737. self.input.value = self.options.min || 0;
  7738. self.minus.disabled = self.options.min != null;
  7739. } else {
  7740. var val = parseInt(val);
  7741. if (self.options.max != null && !isNaN(self.options.max) && val >= parseInt(self.options.max)) {
  7742. val = self.options.max;
  7743. self.plus.disabled = true;
  7744. } else {
  7745. self.plus.disabled = false;
  7746. }
  7747. if (self.options.min != null && !isNaN(self.options.min) && val <= parseInt(self.options.min)) {
  7748. val = self.options.min;
  7749. self.minus.disabled = true;
  7750. } else {
  7751. self.minus.disabled = false;
  7752. }
  7753. self.input.value = val;
  7754. }
  7755. },
  7756. /**
  7757. * 更新选项
  7758. **/
  7759. setOption: function(name, value) {
  7760. var self = this;
  7761. self.options[name] = value;
  7762. },
  7763. /**
  7764. * 动态设置新值
  7765. **/
  7766. setValue: function(value) {
  7767. this.input.value = value;
  7768. this.checkValue();
  7769. }
  7770. });
  7771. $.fn.numbox = function(options) {
  7772. var instanceArray = [];
  7773. //遍历选择的元素
  7774. this.each(function(i, element) {
  7775. if (element.numbox) {
  7776. return;
  7777. }
  7778. if (options) {
  7779. element.numbox = new Numbox(element, options);
  7780. } else {
  7781. var optionsText = element.getAttribute('data-numbox-options');
  7782. var options = optionsText ? JSON.parse(optionsText) : {};
  7783. options.step = element.getAttribute('data-numbox-step') || options.step;
  7784. options.min = element.getAttribute('data-numbox-min') || options.min;
  7785. options.max = element.getAttribute('data-numbox-max') || options.max;
  7786. element.numbox = new Numbox(element, options);
  7787. }
  7788. });
  7789. return this[0] ? this[0].numbox : null;
  7790. }
  7791. //自动处理 class='mui-locker' 的 dom
  7792. $.ready(function() {
  7793. $('.' + holderClassName).numbox();
  7794. });
  7795. }(mui));
  7796. /**
  7797. * Button
  7798. * @param {type} $
  7799. * @param {type} window
  7800. * @param {type} document
  7801. * @returns {undefined}
  7802. */
  7803. (function($, window, document) {
  7804. var CLASS_ICON = 'mui-icon';
  7805. var CLASS_DISABLED = 'mui-disabled';
  7806. var STATE_RESET = 'reset';
  7807. var STATE_LOADING = 'loading';
  7808. var defaultOptions = {
  7809. loadingText: 'Loading...', //文案
  7810. loadingIcon: 'mui-spinner' + ' ' + 'mui-spinner-white', //图标,可为空
  7811. loadingIconPosition: 'left' //图标所处位置,仅支持left|right
  7812. };
  7813. var Button = function(element, options) {
  7814. this.element = element;
  7815. this.options = $.extend({}, defaultOptions, options);
  7816. if (!this.options.loadingText) {
  7817. this.options.loadingText = defaultOptions.loadingText;
  7818. }
  7819. if (this.options.loadingIcon === null) {
  7820. this.options.loadingIcon = 'mui-spinner';
  7821. if ($.getStyles(this.element, 'color') === 'rgb(255, 255, 255)') {
  7822. this.options.loadingIcon += ' ' + 'mui-spinner-white';
  7823. }
  7824. }
  7825. this.isInput = this.element.tagName === 'INPUT';
  7826. this.resetHTML = this.isInput ? this.element.value : this.element.innerHTML;
  7827. this.state = '';
  7828. };
  7829. Button.prototype.loading = function() {
  7830. this.setState(STATE_LOADING);
  7831. };
  7832. Button.prototype.reset = function() {
  7833. this.setState(STATE_RESET);
  7834. };
  7835. Button.prototype.setState = function(state) {
  7836. if (this.state === state) {
  7837. return false;
  7838. }
  7839. this.state = state;
  7840. if (state === STATE_RESET) {
  7841. this.element.disabled = false;
  7842. this.element.classList.remove(CLASS_DISABLED);
  7843. this.setHtml(this.resetHTML);
  7844. } else if (state === STATE_LOADING) {
  7845. this.element.disabled = true;
  7846. this.element.classList.add(CLASS_DISABLED);
  7847. var html = this.isInput ? this.options.loadingText : ('<span>' + this.options.loadingText + '</span>');
  7848. if (this.options.loadingIcon && !this.isInput) {
  7849. if (this.options.loadingIconPosition === 'right') {
  7850. html += '&nbsp;<span class="' + this.options.loadingIcon + '"></span>';
  7851. } else {
  7852. html = '<span class="' + this.options.loadingIcon + '"></span>&nbsp;' + html;
  7853. }
  7854. }
  7855. this.setHtml(html);
  7856. }
  7857. };
  7858. Button.prototype.setHtml = function(html) {
  7859. if (this.isInput) {
  7860. this.element.value = html;
  7861. } else {
  7862. this.element.innerHTML = html;
  7863. }
  7864. }
  7865. $.fn.button = function(state) {
  7866. var buttonApis = [];
  7867. this.each(function() {
  7868. var buttonApi = this.mui_plugin_button;
  7869. if (!buttonApi) {
  7870. var loadingText = this.getAttribute('data-loading-text');
  7871. var loadingIcon = this.getAttribute('data-loading-icon');
  7872. var loadingIconPosition = this.getAttribute('data-loading-icon-position');
  7873. this.mui_plugin_button = buttonApi = new Button(this, {
  7874. loadingText: loadingText,
  7875. loadingIcon: loadingIcon,
  7876. loadingIconPosition: loadingIconPosition
  7877. });
  7878. }
  7879. if (state === STATE_LOADING || state === STATE_RESET) {
  7880. buttonApi.setState(state);
  7881. }
  7882. buttonApis.push(buttonApi);
  7883. });
  7884. return buttonApis.length === 1 ? buttonApis[0] : buttonApis;
  7885. };
  7886. })(mui, window, document);