mui.js 257 KB

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